Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It might be better to do this computation in the symbolic ring instead in order to avoid expansions, i.e.

# from the question (for completeness)
def br(x):
    return 1-1/x

k = 3
gens = var(['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'])
K = 1 + q2 + q2^2 + q3 + q4
X = gens[:k]
rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.operands()]
rho.reverse()
chix = prod([ br(X[j]) for j in range(k)])
chim = prod([ br(X[j]/m) for j in range(k)])
chiup = prod([ prod([ br(q1*q2*X[i]/X[j])*br(q1*q3*X[i]/X[j])*br(q2*q3*X[i]/X[j])*(br(X[i]/X[j]))^2 for i in range(k) if i > j]) for j in range(k)])
chiups = prod([ prod([ br(X[i]/(X[j]*q1*q2))*br(X[i]/(X[j]*q1*q3))*br(X[i]/(X[j]*q2*q3)) for i in range(k) if i > j]) for j in range(k)])
chido = prod([ prod([ br(q1*X[i]/X[j])*br(q2*X[i]/X[j])*br(q3*X[i]/X[j])*br(q1*q2*q3*X[i]/X[j]) for i in range(k) if i > j]) for j in range (k)])
chidos = prod([ prod([ br(X[i]/(X[j]*q1))*br(X[i]/(X[j]*q2))*br(X[i]/(X[j]*q3))*br(X[i]/(X[j]*q1*q2*q3)) for i in range(k) if i > j]) for j in range (k)])
dx = prod([ X[j] for j in range(k)])
chinum = (chim*chiup*chiups)
chiden = (chix*chido*chidos*dx)
chi = (chinum/chiden)

Then carefully handle the products without calling factor on the entire fraction, but only on the individual factors that we already know.

for xi,rhoi in zip(X,rho):
    D = {xi: rhoi}
    chi = (chi*(xi-rhoi))
    g = prod([f.factor() for f in chi.operands()])  # this seems to have cancelled all fractions, but maybe add assertions for this
    dens = [(1/gi).subs(D) for gi in g.operands() if gi.numerator().is_constant()]
    nums = [gi.subs(D) for gi in g.operands() if not gi.numerator().is_constant()]
    chi = prod(nums) / prod(dens)

chi = prod([f.factor() for f in chi.operands()])

Here, g as well as the last line seem to end up being fractions of factors of actual polynomials (but I am not sure if this will work in every case). Result:

                          2         2                                      ⎛     2   3    ⎞ ⎛  2      3    ⎞ ⎛  2   2       ⎞
-(m - 1)⋅(m - q₃)⋅(q₁ - 1) ⋅(q₂ - 1) ⋅(q₃ - 1)⋅(q₁⋅q₂ - q₃)⋅(q₁⋅q₂⋅q₃ - 1)⋅⎝q₁⋅q₂ ⋅q₃  - 1⎠⋅⎝q₁ ⋅q₂⋅q₃  - 1⎠⋅⎝q₁ ⋅q₂ ⋅q₃ - 1⎠⋅(m⋅q₁⋅q₂⋅q₃ - 1)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                          2                         ⎛        3    ⎞ ⎛     2       ⎞ ⎛  2          ⎞ ⎛  2   2   3    ⎞
           (q₁ - q₃)⋅(q₂ - q₃)⋅(q₁⋅q₂ - 1) ⋅(q₁⋅q₃ - 1)⋅(q₂⋅q₃ - 1)⋅⎝q₁⋅q₂⋅q₃  - 1⎠⋅⎝q₁⋅q₂ ⋅q₃ - 1⎠⋅⎝q₁ ⋅q₂⋅q₃ - 1⎠⋅⎝q₁ ⋅q₂ ⋅q₃  - 1⎠

It might be better to do this computation in the symbolic ring instead in order to avoid expansions, i.e.

# from the question (for completeness)
def br(x):
    return 1-1/x

k = 3
gens = var(['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'])
K = 1 + q2 + q2^2 + q3 + q4
X = gens[:k]
rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.operands()]
rho.reverse()
chix = prod([ br(X[j]) for j in range(k)])
chim = prod([ br(X[j]/m) for j in range(k)])
chiup = prod([ prod([ br(q1*q2*X[i]/X[j])*br(q1*q3*X[i]/X[j])*br(q2*q3*X[i]/X[j])*(br(X[i]/X[j]))^2 for i in range(k) if i > j]) for j in range(k)])
chiups = prod([ prod([ br(X[i]/(X[j]*q1*q2))*br(X[i]/(X[j]*q1*q3))*br(X[i]/(X[j]*q2*q3)) for i in range(k) if i > j]) for j in range(k)])
chido = prod([ prod([ br(q1*X[i]/X[j])*br(q2*X[i]/X[j])*br(q3*X[i]/X[j])*br(q1*q2*q3*X[i]/X[j]) for i in range(k) if i > j]) for j in range (k)])
chidos = prod([ prod([ br(X[i]/(X[j]*q1))*br(X[i]/(X[j]*q2))*br(X[i]/(X[j]*q3))*br(X[i]/(X[j]*q1*q2*q3)) for i in range(k) if i > j]) for j in range (k)])
dx = prod([ X[j] for j in range(k)])
chinum = (chim*chiup*chiups)
chiden = (chix*chido*chidos*dx)
chi = (chinum/chiden)

Then carefully handle the products without calling factor on the entire fraction, but only on the individual factors that we already know.

for xi,rhoi in zip(X,rho):
    D = {xi: rhoi}
    chi = (chi*(xi-rhoi))
    g = prod([f.factor() for f in chi.operands()])  # this seems to have cancelled all fractions, but maybe add assertions for this
    dens = [(1/gi).subs(D) for gi in g.operands() if gi.numerator().is_constant()]
    nums = [gi.subs(D) for gi in g.operands() if not gi.numerator().is_constant()]
    chi = prod(nums) / prod(dens)

chi = prod([f.factor() for f in chi.operands()])

Here, g as well as the last line seem to end up being fractions of factors of actual polynomials (but I am not sure if this will work in every case). Result:

                          2         2                                      ⎛     2   3    ⎞ ⎛  2      3    ⎞ ⎛  2   2       ⎞
-(m - 1)⋅(m - q₃)⋅(q₁ - 1) ⋅(q₂ - 1) ⋅(q₃ - 1)⋅(q₁⋅q₂ - q₃)⋅(q₁⋅q₂⋅q₃ - 1)⋅⎝q₁⋅q₂ ⋅q₃  - 1⎠⋅⎝q₁ ⋅q₂⋅q₃  - 1⎠⋅⎝q₁ ⋅q₂ ⋅q₃ - 1⎠⋅(m⋅q₁⋅q₂⋅q₃ - 1)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                          2                         ⎛        3    ⎞ ⎛     2       ⎞ ⎛  2          ⎞ ⎛  2   2   3    ⎞
           (q₁ - q₃)⋅(q₂ - q₃)⋅(q₁⋅q₂ - 1) ⋅(q₁⋅q₃ - 1)⋅(q₂⋅q₃ - 1)⋅⎝q₁⋅q₂⋅q₃  - 1⎠⋅⎝q₁⋅q₂ ⋅q₃ - 1⎠⋅⎝q₁ ⋅q₂⋅q₃ - 1⎠⋅⎝q₁ ⋅q₂ ⋅q₃  - 1⎠
-(q1^2*q2*q3^3 - 1)*(q1*q2^2*q3^3 - 1)*(q1^2*q2^2*q3 - 1)*(m*q1*q2*q3 - 1)*(q1*q2*q3 - 1)*(q1*q2 - q3)*(m - q3)*(m - 1)*(q1 - 1)^2*(q2 - 1)^2*(q3 - 1)/((q1^2*q

2^2q3^3 - 1)(q1q2q3^3 - 1)(q1^2q2q3 - 1)(q1q2^2q3 - 1)(q1q2 - 1)^2(q1q3 - 1)(q2q3 - 1)(q1 - q3)(q2 - q3))

It might be better to do this computation in the symbolic ring instead in order to avoid expansions, i.e.

# from the question (for completeness)
def br(x):
    return 1-1/x

k = 3
gens = var(['x%d' %p for p in range(k)]+['q1', 'q2', 'q3', 'q4', 'm'])
K = 1 + q2 + q2^2 + q3 + q4
X = gens[:k]
rho = [p.substitute({q4:(q1*q2*q3)^-1}) for p in K.operands()]
rho.reverse()
chix = prod([ br(X[j]) for j in range(k)])
chim = prod([ br(X[j]/m) for j in range(k)])
chiup = prod([ prod([ br(q1*q2*X[i]/X[j])*br(q1*q3*X[i]/X[j])*br(q2*q3*X[i]/X[j])*(br(X[i]/X[j]))^2 for i in range(k) if i > j]) for j in range(k)])
chiups = prod([ prod([ br(X[i]/(X[j]*q1*q2))*br(X[i]/(X[j]*q1*q3))*br(X[i]/(X[j]*q2*q3)) for i in range(k) if i > j]) for j in range(k)])
chido = prod([ prod([ br(q1*X[i]/X[j])*br(q2*X[i]/X[j])*br(q3*X[i]/X[j])*br(q1*q2*q3*X[i]/X[j]) for i in range(k) if i > j]) for j in range (k)])
chidos = prod([ prod([ br(X[i]/(X[j]*q1))*br(X[i]/(X[j]*q2))*br(X[i]/(X[j]*q3))*br(X[i]/(X[j]*q1*q2*q3)) for i in range(k) if i > j]) for j in range (k)])
dx = prod([ X[j] for j in range(k)])
chinum = (chim*chiup*chiups)
chiden = (chix*chido*chidos*dx)
chi = (chinum/chiden)

Then carefully handle the products without calling factor on the entire fraction, but only on the individual factors that we already know.

for xi,rhoi in zip(X,rho):
    D = {xi: rhoi}
    chi = (chi*(xi-rhoi))
    g = prod([f.factor() for f in chi.operands()])  # this seems to have cancelled all fractions, but maybe add assertions for this
    dens = [(1/gi).subs(D) for gi in g.operands() if gi.numerator().is_constant()]
    nums = [gi.subs(D) for gi in g.operands() if not gi.numerator().is_constant()]
    chi = prod(nums) / prod(dens)

chi = prod([f.factor() for f in chi.operands()])

Here, g as well as the last line seem to end up being fractions of factors of actual polynomials (but I am not sure if this will work in every case). Result:

-(q1^2*q2*q3^3 - 1)*(q1*q2^2*q3^3 - 1)*(q1^2*q2^2*q3 - 1)*(m*q1*q2*q3 - 1)*(q1*q2*q3 - 1)*(q1*q2 - q3)*(m - q3)*(m - 1)*(q1 - 1)^2*(q2 - 1)^2*(q3 - 1)/((q1^2*q
1)/((q1^2*q2^2*q3^3 - 1)*(q1*q2*q3^3 - 1)*(q1^2*q2*q3 - 1)*(q1*q2^2*q3 - 1)*(q1*q2 - 1)^2*(q1*q3 - 1)*(q2*q3 - 1)*(q1 - q3)*(q2 - q3))

2^2q3^3 - 1)(q1q2q3^3 - 1)(q1^2q2q3 - 1)(q1q2^2q3 - 1)(q1q2 - 1)^2(q1q3 - 1)(q2q3 - 1)(q1 - q3)(q2 - q3))