Ask Your Question
2

how to best simplify/factor symbolic expressions

asked 2020-01-21 05:07:05 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2020-01-21 06:37:58 -0600

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())) + '}'))

$$\frac{ (q_{2}^{4} q_{3}^{4} - 1) \cdot (q_{1}^{4} q_{3}^{4} - 1) \cdot (q_{1}^{4} q_{2}^{4} - 1) }{ (q_{3}^{4} - 1) \cdot (q_{2}^{4} - 1) \cdot (q_{1}^{4} - 1) \cdot (q_{1}^{4} q_{2}^{4} q_{3}^{4} - 1) }$$

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

edit flag offensive delete link more

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: 2020-01-21 05:07:05 -0600

Seen: 32 times

Last updated: Jan 21