Processing math: 100%
Ask Your Question
2

how to best simplify/factor symbolic expressions

asked 5 years ago

rue82 gravatar image

Define symbolic expressions T3 and T3s.

q1,q2,q3 = var('q1,q2,q3')
T3 = (q1^2*q2^2 + 1)*(q1^2*q3^2 + 1)*(q2^2*q3^2 + 1)*(q1*q2 + 1)*(q1*q2 - 1)*(q1*q3 + 1)*(q1*q3 - 1)*(q2*q3 + 1)*(q2*q3 - 1)/((q1^2*q2^2*q3^2 + 1)*(q1*q2*q3 + 1)*(q1*q2*q3 - 1)*(q1^2 + 1)*(q2^2 + 1)*(q3^2 + 1)*(q1 + 1)*(q1 - 1)*(q2 + 1)*(q2 - 1)*(q3 + 1)*(q3 - 1))

T3s = (q1^4*q2^4 - 1)*(q1^4*q3^4 - 1)*(q2^4*q3^4 - 1)/((q1^4*q2^4*q3^4 - 1)*(q1^4 - 1)*(q2^4 - 1)*(q3^4 - 1))

Is there any method to reduce T3 to its simpler (at least for a human) form T3s in Sage?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 5 years ago

rburing gravatar image

I prefer to work with polynomial rings and their fields of fractions:

R.<q1,q2,q3> = PolynomialRing(QQ)
T3 = (q1^2*q2^2 + 1)*(q1^2*q3^2 + 1)*(q2^2*q3^2 + 1)*(q1*q2 + 1)*(q1*q2 - 1)*(q1*q3 + 1)*(q1*q3 - 1)*(q2*q3 + 1)*(q2*q3 - 1)/((q1^2*q2^2*q3^2 + 1)*(q1*q2*q3 + 1)*(q1*q2*q3 - 1)*(q1^2 + 1)*(q2^2 + 1)*(q3^2 + 1)*(q1 + 1)*(q1 - 1)*(q2 + 1)*(q2 - 1)*(q3 + 1)*(q3 - 1))

Here T3 automatically belongs to the field of fractions of R.

One way to characterize the factorization you like is that all factors which contain exactly the same variables are multiplied out. We can make a function that returns such a factorization:

def my_factor(f):
    from collections import defaultdict
    factors = defaultdict(lambda: f.parent().one())
    for (g,e) in f.factor():
        factors[g.variables()] *= g^e
    return Factorization([(g,1) for g in factors.values()])

We can use it e.g. as follows:

show(LatexExpr('\\frac{' + latex(my_factor(T3.numerator())) + '}{' + latex(my_factor(T3.denominator())) + '}'))

(q42q431)(q41q431)(q41q421)(q431)(q421)(q411)(q41q42q431)

If you really prefer symbolic expressions, then you can do the conversions back and forth, or adapt the function.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 1,074 times

Last updated: Jan 21 '20