New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancelling very long polynomial expression #9341

Closed
tschijnmo opened this Issue Apr 24, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@tschijnmo
Copy link
Contributor

tschijnmo commented Apr 24, 2015

Hello everyone,

In the simplification of polynomial expressions, it seems that on the lines 3706 of simplify/simplify.py,

    expr = bottom_up(expr, lambda w: w.normal())
    expr = Mul(*powsimp(expr).as_content_primitive())
    _e = cancel(expr)  # <== HERE, 3706 in 0.7.6
    expr1 = shorter(_e, _mexpand(_e).cancel())  # issue 6829
    expr2 = shorter(together(expr, deep=True), together(expr1, deep=True))

the expression will first be attempted to be manipulated to cancel the GCD of its numerator and denominator. In cases where the expression it just a plain polynomial without an explicit denominator, in the line 6220 of polys/polytools.py,

    if not isinstance(f, (tuple, Tuple)):
        if f.is_Number or isinstance(f, Relational) or not isinstance(f, Expr):
            return f
        f = factor_terms(f, radical=True)
        p, q = f.as_numer_denom()  # <=== HERE

it seems that the polynomial will still be taken to have a denominator of unity. This is mathematically fine, But the problem is that for polynomials of relatively large size, it seems that it takes quite a while to actually cancel the added 1 denominator out. In the line 6260 of the polytools.py,

 c, P, Q = F.cancel(G)

the cancel function takes quite a while to finish.

Since I am very new to sympy, could anyone help me if the problem could be straightforwardly fixed? Any pointers will be deeply appreciated. If it could be fixed, I guess I could submit a pull request for this. Thank you all!

PS

Here is a small code file where this problem can be apparently reproduced. The cancel function seems to take forever.

from sympy import symbols, Add, simplify
from sympy.tensor import IndexedBase

n = symbols('n')
t = IndexedBase('t', shape=(n, ) * 4)
u = IndexedBase('u', shape=(n, ) * 4)
a, b, c, d = symbols('a, b, c, d')
i, j, k, l = symbols('i, j, k, l')
a0 = symbols('a0')
i0 = symbols('i0')


terms = [
    -t[a0, b, j, k]*t[c, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, a0, j, k]*t[c, d, i, i0]*u[b, i0, a0, l]/4,
    t[a0, c, j, k]*t[b, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, d, i, i0]*t[a0, c, j, k]*u[b, i0, a0, l]/4,
    t[a, a0, j, k]*t[b, d, i, i0]*u[c, i0, a0, l]/4,
    t[a, d, i, i0]*t[a0, b, j, k]*u[c, i0, a0, l]/4,
    -t[a0, b, j, k]*t[c, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, a0, j, k]*t[c, d, i, i0]*u[b, i0, a0, l]/4,
    t[a0, c, j, k]*t[b, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, d, i, i0]*t[a0, c, j, k]*u[b, i0, a0, l]/4,
    t[a, a0, j, k]*t[b, d, i, i0]*u[c, i0, a0, l]/4,
    t[a, d, i, i0]*t[a0, b, j, k]*u[c, i0, a0, l]/4,
    -t[a0, d, j, k]*t[b, c, i, i0]*u[a, i0, a0, l]/4,
    t[a, c, i, i0]*t[a0, d, j, k]*u[b, i0, a0, l]/4,
    -t[a0, d, j, k]*t[b, c, i, i0]*u[a, i0, a0, l]/4,
    t[a, c, i, i0]*t[a0, d, j, k]*u[b, i0, a0, l]/4,
    -t[a, b, i, i0]*t[a0, d, j, k]*u[c, i0, a0, l]/4,
    -t[a, b, i, i0]*t[a0, d, j, k]*u[c, i0, a0, l]/4,
    -t[a, a0, j, k]*t[b, c, i, i0]*u[d, i0, a0, l]/4,
    -t[a, c, i, i0]*t[a0, b, j, k]*u[d, i0, a0, l]/4,
    -t[a, a0, j, k]*t[b, c, i, i0]*u[d, i0, a0, l]/4,
    -t[a, c, i, i0]*t[a0, b, j, k]*u[d, i0, a0, l]/4,
    t[a, b, i, i0]*t[a0, c, j, k]*u[d, i0, a0, l]/4,
    t[a, b, i, i0]*t[a0, c, j, k]*u[d, i0, a0, l]/4,
    t[a0, b, j, l]*t[c, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, a0, j, l]*t[c, d, i, i0]*u[b, i0, a0, k]/4,
    -t[a0, c, j, l]*t[b, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, d, i, i0]*t[a0, c, j, l]*u[b, i0, a0, k]/4,
    -t[a, a0, j, l]*t[b, d, i, i0]*u[c, i0, a0, k]/4,
    -t[a, d, i, i0]*t[a0, b, j, l]*u[c, i0, a0, k]/4,
    t[a0, b, j, l]*t[c, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, a0, j, l]*t[c, d, i, i0]*u[b, i0, a0, k]/4,
    -t[a0, c, j, l]*t[b, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, d, i, i0]*t[a0, c, j, l]*u[b, i0, a0, k]/4,
    -t[a, a0, j, l]*t[b, d, i, i0]*u[c, i0, a0, k]/4,
    -t[a, d, i, i0]*t[a0, b, j, l]*u[c, i0, a0, k]/4,
    t[a0, d, j, l]*t[b, c, i, i0]*u[a, i0, a0, k]/4,
    -t[a, c, i, i0]*t[a0, d, j, l]*u[b, i0, a0, k]/4,
    t[a0, d, j, l]*t[b, c, i, i0]*u[a, i0, a0, k]/4,
    -t[a, c, i, i0]*t[a0, d, j, l]*u[b, i0, a0, k]/4,
    t[a, b, i, i0]*t[a0, d, j, l]*u[c, i0, a0, k]/4,
    t[a, b, i, i0]*t[a0, d, j, l]*u[c, i0, a0, k]/4,
    t[a, a0, j, l]*t[b, c, i, i0]*u[d, i0, a0, k]/4,
    t[a, c, i, i0]*t[a0, b, j, l]*u[d, i0, a0, k]/4,
    t[a, a0, j, l]*t[b, c, i, i0]*u[d, i0, a0, k]/4,
    t[a, c, i, i0]*t[a0, b, j, l]*u[d, i0, a0, k]/4,
    -t[a, b, i, i0]*t[a0, c, j, l]*u[d, i0, a0, k]/4,
    -t[a, b, i, i0]*t[a0, c, j, l]*u[d, i0, a0, k]/4,
    -t[a0, b, j, k]*t[c, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, a0, j, k]*t[c, d, i, i0]*u[b, i0, a0, l]/4,
    t[a0, c, j, k]*t[b, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, d, i, i0]*t[a0, c, j, k]*u[b, i0, a0, l]/4,
    t[a, a0, j, k]*t[b, d, i, i0]*u[c, i0, a0, l]/4,
    t[a, d, i, i0]*t[a0, b, j, k]*u[c, i0, a0, l]/4,
    -t[a0, b, j, k]*t[c, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, a0, j, k]*t[c, d, i, i0]*u[b, i0, a0, l]/4,
    t[a0, c, j, k]*t[b, d, i, i0]*u[a, i0, a0, l]/4,
    -t[a, d, i, i0]*t[a0, c, j, k]*u[b, i0, a0, l]/4,
    t[a, a0, j, k]*t[b, d, i, i0]*u[c, i0, a0, l]/4,
    t[a, d, i, i0]*t[a0, b, j, k]*u[c, i0, a0, l]/4,
    -t[a0, d, j, k]*t[b, c, i, i0]*u[a, i0, a0, l]/4,
    t[a, c, i, i0]*t[a0, d, j, k]*u[b, i0, a0, l]/4,
    -t[a0, d, j, k]*t[b, c, i, i0]*u[a, i0, a0, l]/4,
    t[a, c, i, i0]*t[a0, d, j, k]*u[b, i0, a0, l]/4,
    -t[a, b, i, i0]*t[a0, d, j, k]*u[c, i0, a0, l]/4,
    -t[a, b, i, i0]*t[a0, d, j, k]*u[c, i0, a0, l]/4,
    -t[a, a0, j, k]*t[b, c, i, i0]*u[d, i0, a0, l]/4,
    -t[a, c, i, i0]*t[a0, b, j, k]*u[d, i0, a0, l]/4,
    -t[a, a0, j, k]*t[b, c, i, i0]*u[d, i0, a0, l]/4,
    -t[a, c, i, i0]*t[a0, b, j, k]*u[d, i0, a0, l]/4,
    t[a, b, i, i0]*t[a0, c, j, k]*u[d, i0, a0, l]/4,
    t[a, b, i, i0]*t[a0, c, j, k]*u[d, i0, a0, l]/4,
    t[a0, b, j, l]*t[c, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, a0, j, l]*t[c, d, i, i0]*u[b, i0, a0, k]/4,
    -t[a0, c, j, l]*t[b, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, d, i, i0]*t[a0, c, j, l]*u[b, i0, a0, k]/4,
    -t[a, a0, j, l]*t[b, d, i, i0]*u[c, i0, a0, k]/4,
    -t[a, d, i, i0]*t[a0, b, j, l]*u[c, i0, a0, k]/4,
    t[a0, b, j, l]*t[c, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, a0, j, l]*t[c, d, i, i0]*u[b, i0, a0, k]/4,
    -t[a0, c, j, l]*t[b, d, i, i0]*u[a, i0, a0, k]/4,
    t[a, d, i, i0]*t[a0, c, j, l]*u[b, i0, a0, k]/4,
    -t[a, a0, j, l]*t[b, d, i, i0]*u[c, i0, a0, k]/4,
    -t[a, d, i, i0]*t[a0, b, j, l]*u[c, i0, a0, k]/4,
    t[a0, d, j, l]*t[b, c, i, i0]*u[a, i0, a0, k]/4,
    -t[a, c, i, i0]*t[a0, d, j, l]*u[b, i0, a0, k]/4,
    t[a0, d, j, l]*t[b, c, i, i0]*u[a, i0, a0, k]/4,
    -t[a, c, i, i0]*t[a0, d, j, l]*u[b, i0, a0, k]/4,
    t[a, b, i, i0]*t[a0, d, j, l]*u[c, i0, a0, k]/4,
    t[a, b, i, i0]*t[a0, d, j, l]*u[c, i0, a0, k]/4,
    t[a, a0, j, l]*t[b, c, i, i0]*u[d, i0, a0, k]/4,
    t[a, c, i, i0]*t[a0, b, j, l]*u[d, i0, a0, k]/4,
    t[a, a0, j, l]*t[b, c, i, i0]*u[d, i0, a0, k]/4,
    t[a, c, i, i0]*t[a0, b, j, l]*u[d, i0, a0, k]/4,
    -t[a, b, i, i0]*t[a0, c, j, l]*u[d, i0, a0, k]/4,
    -t[a, b, i, i0]*t[a0, c, j, l]*u[d, i0, a0, k]/4,
    -t[a0, b, k, l]*t[c, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, a0, k, l]*t[c, d, i, i0]*u[b, i0, a0, j]/4,
    t[a0, c, k, l]*t[b, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, d, i, i0]*t[a0, c, k, l]*u[b, i0, a0, j]/4,
    t[a, a0, k, l]*t[b, d, i, i0]*u[c, i0, a0, j]/4,
    t[a, d, i, i0]*t[a0, b, k, l]*u[c, i0, a0, j]/4,
    -t[a0, b, k, l]*t[c, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, a0, k, l]*t[c, d, i, i0]*u[b, i0, a0, j]/4,
    t[a0, c, k, l]*t[b, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, d, i, i0]*t[a0, c, k, l]*u[b, i0, a0, j]/4,
    t[a, a0, k, l]*t[b, d, i, i0]*u[c, i0, a0, j]/4,
    t[a, d, i, i0]*t[a0, b, k, l]*u[c, i0, a0, j]/4,
    -t[a0, d, k, l]*t[b, c, i, i0]*u[a, i0, a0, j]/4,
    t[a, c, i, i0]*t[a0, d, k, l]*u[b, i0, a0, j]/4,
    -t[a0, d, k, l]*t[b, c, i, i0]*u[a, i0, a0, j]/4,
    t[a, c, i, i0]*t[a0, d, k, l]*u[b, i0, a0, j]/4,
    -t[a, b, i, i0]*t[a0, d, k, l]*u[c, i0, a0, j]/4,
    -t[a, b, i, i0]*t[a0, d, k, l]*u[c, i0, a0, j]/4,
    -t[a, a0, k, l]*t[b, c, i, i0]*u[d, i0, a0, j]/4,
    -t[a, c, i, i0]*t[a0, b, k, l]*u[d, i0, a0, j]/4,
    -t[a, a0, k, l]*t[b, c, i, i0]*u[d, i0, a0, j]/4,
    -t[a, c, i, i0]*t[a0, b, k, l]*u[d, i0, a0, j]/4,
    t[a, b, i, i0]*t[a0, c, k, l]*u[d, i0, a0, j]/4,
    t[a, b, i, i0]*t[a0, c, k, l]*u[d, i0, a0, j]/4,
    -t[a0, b, k, l]*t[c, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, a0, k, l]*t[c, d, i, i0]*u[b, i0, a0, j]/4,
    t[a0, c, k, l]*t[b, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, d, i, i0]*t[a0, c, k, l]*u[b, i0, a0, j]/4,
    t[a, a0, k, l]*t[b, d, i, i0]*u[c, i0, a0, j]/4,
    t[a, d, i, i0]*t[a0, b, k, l]*u[c, i0, a0, j]/4,
    -t[a0, b, k, l]*t[c, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, a0, k, l]*t[c, d, i, i0]*u[b, i0, a0, j]/4,
    t[a0, c, k, l]*t[b, d, i, i0]*u[a, i0, a0, j]/4,
    -t[a, d, i, i0]*t[a0, c, k, l]*u[b, i0, a0, j]/4,
    t[a, a0, k, l]*t[b, d, i, i0]*u[c, i0, a0, j]/4,
    t[a, d, i, i0]*t[a0, b, k, l]*u[c, i0, a0, j]/4,
    -t[a0, d, k, l]*t[b, c, i, i0]*u[a, i0, a0, j]/4,
    t[a, c, i, i0]*t[a0, d, k, l]*u[b, i0, a0, j]/4,
    -t[a0, d, k, l]*t[b, c, i, i0]*u[a, i0, a0, j]/4,
    t[a, c, i, i0]*t[a0, d, k, l]*u[b, i0, a0, j]/4,
    -t[a, b, i, i0]*t[a0, d, k, l]*u[c, i0, a0, j]/4,
    -t[a, b, i, i0]*t[a0, d, k, l]*u[c, i0, a0, j]/4,
    -t[a, a0, k, l]*t[b, c, i, i0]*u[d, i0, a0, j]/4,
    -t[a, c, i, i0]*t[a0, b, k, l]*u[d, i0, a0, j]/4,
    -t[a, a0, k, l]*t[b, c, i, i0]*u[d, i0, a0, j]/4,
    -t[a, c, i, i0]*t[a0, b, k, l]*u[d, i0, a0, j]/4,
    t[a, b, i, i0]*t[a0, c, k, l]*u[d, i0, a0, j]/4,
    t[a, b, i, i0]*t[a0, c, k, l]*u[d, i0, a0, j]/4,
    -t[a0, b, i, k]*t[c, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, a0, i, k]*t[c, d, i0, j]*u[b, i0, a0, l]/4,
    t[a0, c, i, k]*t[b, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, d, i0, j]*t[a0, c, i, k]*u[b, i0, a0, l]/4,
    t[a, a0, i, k]*t[b, d, i0, j]*u[c, i0, a0, l]/4,
    t[a, d, i0, j]*t[a0, b, i, k]*u[c, i0, a0, l]/4,
    -t[a0, b, i, k]*t[c, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, a0, i, k]*t[c, d, i0, j]*u[b, i0, a0, l]/4,
    t[a0, c, i, k]*t[b, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, d, i0, j]*t[a0, c, i, k]*u[b, i0, a0, l]/4,
    t[a, a0, i, k]*t[b, d, i0, j]*u[c, i0, a0, l]/4,
    t[a, d, i0, j]*t[a0, b, i, k]*u[c, i0, a0, l]/4,
    -t[a0, d, i, k]*t[b, c, i0, j]*u[a, i0, a0, l]/4,
    t[a, c, i0, j]*t[a0, d, i, k]*u[b, i0, a0, l]/4,
    -t[a0, d, i, k]*t[b, c, i0, j]*u[a, i0, a0, l]/4,
    t[a, c, i0, j]*t[a0, d, i, k]*u[b, i0, a0, l]/4,
    -t[a, b, i0, j]*t[a0, d, i, k]*u[c, i0, a0, l]/4,
    -t[a, b, i0, j]*t[a0, d, i, k]*u[c, i0, a0, l]/4,
    -t[a, a0, i, k]*t[b, c, i0, j]*u[d, i0, a0, l]/4,
    -t[a, c, i0, j]*t[a0, b, i, k]*u[d, i0, a0, l]/4,
    -t[a, a0, i, k]*t[b, c, i0, j]*u[d, i0, a0, l]/4,
    -t[a, c, i0, j]*t[a0, b, i, k]*u[d, i0, a0, l]/4,
    t[a, b, i0, j]*t[a0, c, i, k]*u[d, i0, a0, l]/4,
    t[a, b, i0, j]*t[a0, c, i, k]*u[d, i0, a0, l]/4,
    t[a0, b, i, l]*t[c, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, a0, i, l]*t[c, d, i0, j]*u[b, i0, a0, k]/4,
    -t[a0, c, i, l]*t[b, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, d, i0, j]*t[a0, c, i, l]*u[b, i0, a0, k]/4,
    -t[a, a0, i, l]*t[b, d, i0, j]*u[c, i0, a0, k]/4,
    -t[a, d, i0, j]*t[a0, b, i, l]*u[c, i0, a0, k]/4,
    t[a0, b, i, l]*t[c, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, a0, i, l]*t[c, d, i0, j]*u[b, i0, a0, k]/4,
    -t[a0, c, i, l]*t[b, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, d, i0, j]*t[a0, c, i, l]*u[b, i0, a0, k]/4,
    -t[a, a0, i, l]*t[b, d, i0, j]*u[c, i0, a0, k]/4,
    -t[a, d, i0, j]*t[a0, b, i, l]*u[c, i0, a0, k]/4,
    t[a0, d, i, l]*t[b, c, i0, j]*u[a, i0, a0, k]/4,
    -t[a, c, i0, j]*t[a0, d, i, l]*u[b, i0, a0, k]/4,
    t[a0, d, i, l]*t[b, c, i0, j]*u[a, i0, a0, k]/4,
    -t[a, c, i0, j]*t[a0, d, i, l]*u[b, i0, a0, k]/4,
    t[a, b, i0, j]*t[a0, d, i, l]*u[c, i0, a0, k]/4,
    t[a, b, i0, j]*t[a0, d, i, l]*u[c, i0, a0, k]/4,
    t[a, a0, i, l]*t[b, c, i0, j]*u[d, i0, a0, k]/4,
    t[a, c, i0, j]*t[a0, b, i, l]*u[d, i0, a0, k]/4,
    t[a, a0, i, l]*t[b, c, i0, j]*u[d, i0, a0, k]/4,
    t[a, c, i0, j]*t[a0, b, i, l]*u[d, i0, a0, k]/4,
    -t[a, b, i0, j]*t[a0, c, i, l]*u[d, i0, a0, k]/4,
    -t[a, b, i0, j]*t[a0, c, i, l]*u[d, i0, a0, k]/4,
    t[a0, b, i, j]*t[c, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, a0, i, j]*t[c, d, i0, k]*u[b, i0, a0, l]/4,
    -t[a0, c, i, j]*t[b, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, d, i0, k]*t[a0, c, i, j]*u[b, i0, a0, l]/4,
    -t[a, a0, i, j]*t[b, d, i0, k]*u[c, i0, a0, l]/4,
    -t[a, d, i0, k]*t[a0, b, i, j]*u[c, i0, a0, l]/4,
    t[a0, b, i, j]*t[c, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, a0, i, j]*t[c, d, i0, k]*u[b, i0, a0, l]/4,
    -t[a0, c, i, j]*t[b, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, d, i0, k]*t[a0, c, i, j]*u[b, i0, a0, l]/4,
    -t[a, a0, i, j]*t[b, d, i0, k]*u[c, i0, a0, l]/4,
    -t[a, d, i0, k]*t[a0, b, i, j]*u[c, i0, a0, l]/4,
    t[a0, d, i, j]*t[b, c, i0, k]*u[a, i0, a0, l]/4,
    -t[a, c, i0, k]*t[a0, d, i, j]*u[b, i0, a0, l]/4,
    t[a0, d, i, j]*t[b, c, i0, k]*u[a, i0, a0, l]/4,
    -t[a, c, i0, k]*t[a0, d, i, j]*u[b, i0, a0, l]/4,
    t[a, b, i0, k]*t[a0, d, i, j]*u[c, i0, a0, l]/4,
    t[a, b, i0, k]*t[a0, d, i, j]*u[c, i0, a0, l]/4,
    t[a, a0, i, j]*t[b, c, i0, k]*u[d, i0, a0, l]/4,
    t[a, c, i0, k]*t[a0, b, i, j]*u[d, i0, a0, l]/4,
    t[a, a0, i, j]*t[b, c, i0, k]*u[d, i0, a0, l]/4,
    t[a, c, i0, k]*t[a0, b, i, j]*u[d, i0, a0, l]/4,
    -t[a, b, i0, k]*t[a0, c, i, j]*u[d, i0, a0, l]/4,
    -t[a, b, i0, k]*t[a0, c, i, j]*u[d, i0, a0, l]/4,
    -t[a0, b, i, j]*t[c, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, a0, i, j]*t[c, d, i0, l]*u[b, i0, a0, k]/4,
    t[a0, c, i, j]*t[b, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, d, i0, l]*t[a0, c, i, j]*u[b, i0, a0, k]/4,
    t[a, a0, i, j]*t[b, d, i0, l]*u[c, i0, a0, k]/4,
    t[a, d, i0, l]*t[a0, b, i, j]*u[c, i0, a0, k]/4,
    -t[a0, b, i, j]*t[c, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, a0, i, j]*t[c, d, i0, l]*u[b, i0, a0, k]/4,
    t[a0, c, i, j]*t[b, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, d, i0, l]*t[a0, c, i, j]*u[b, i0, a0, k]/4,
    t[a, a0, i, j]*t[b, d, i0, l]*u[c, i0, a0, k]/4,
    t[a, d, i0, l]*t[a0, b, i, j]*u[c, i0, a0, k]/4,
    -t[a0, d, i, j]*t[b, c, i0, l]*u[a, i0, a0, k]/4,
    t[a, c, i0, l]*t[a0, d, i, j]*u[b, i0, a0, k]/4,
    -t[a0, d, i, j]*t[b, c, i0, l]*u[a, i0, a0, k]/4,
    t[a, c, i0, l]*t[a0, d, i, j]*u[b, i0, a0, k]/4,
    -t[a, b, i0, l]*t[a0, d, i, j]*u[c, i0, a0, k]/4,
    -t[a, b, i0, l]*t[a0, d, i, j]*u[c, i0, a0, k]/4,
    -t[a, a0, i, j]*t[b, c, i0, l]*u[d, i0, a0, k]/4,
    -t[a, c, i0, l]*t[a0, b, i, j]*u[d, i0, a0, k]/4,
    -t[a, a0, i, j]*t[b, c, i0, l]*u[d, i0, a0, k]/4,
    -t[a, c, i0, l]*t[a0, b, i, j]*u[d, i0, a0, k]/4,
    t[a, b, i0, l]*t[a0, c, i, j]*u[d, i0, a0, k]/4,
    t[a, b, i0, l]*t[a0, c, i, j]*u[d, i0, a0, k]/4,
    -t[a0, b, i, l]*t[c, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, a0, i, l]*t[c, d, i0, k]*u[b, i0, a0, j]/4,
    t[a0, c, i, l]*t[b, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, d, i0, k]*t[a0, c, i, l]*u[b, i0, a0, j]/4,
    t[a, a0, i, l]*t[b, d, i0, k]*u[c, i0, a0, j]/4,
    t[a, d, i0, k]*t[a0, b, i, l]*u[c, i0, a0, j]/4,
    -t[a0, b, i, l]*t[c, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, a0, i, l]*t[c, d, i0, k]*u[b, i0, a0, j]/4,
    t[a0, c, i, l]*t[b, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, d, i0, k]*t[a0, c, i, l]*u[b, i0, a0, j]/4,
    t[a, a0, i, l]*t[b, d, i0, k]*u[c, i0, a0, j]/4,
    t[a, d, i0, k]*t[a0, b, i, l]*u[c, i0, a0, j]/4,
    -t[a0, d, i, l]*t[b, c, i0, k]*u[a, i0, a0, j]/4,
    t[a, c, i0, k]*t[a0, d, i, l]*u[b, i0, a0, j]/4,
    -t[a0, d, i, l]*t[b, c, i0, k]*u[a, i0, a0, j]/4,
    t[a, c, i0, k]*t[a0, d, i, l]*u[b, i0, a0, j]/4,
    -t[a, b, i0, k]*t[a0, d, i, l]*u[c, i0, a0, j]/4,
    -t[a, b, i0, k]*t[a0, d, i, l]*u[c, i0, a0, j]/4,
    -t[a, a0, i, l]*t[b, c, i0, k]*u[d, i0, a0, j]/4,
    -t[a, c, i0, k]*t[a0, b, i, l]*u[d, i0, a0, j]/4,
    -t[a, a0, i, l]*t[b, c, i0, k]*u[d, i0, a0, j]/4,
    -t[a, c, i0, k]*t[a0, b, i, l]*u[d, i0, a0, j]/4,
    t[a, b, i0, k]*t[a0, c, i, l]*u[d, i0, a0, j]/4,
    t[a, b, i0, k]*t[a0, c, i, l]*u[d, i0, a0, j]/4,
    t[a0, b, i, k]*t[c, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, a0, i, k]*t[c, d, i0, l]*u[b, i0, a0, j]/4,
    -t[a0, c, i, k]*t[b, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, d, i0, l]*t[a0, c, i, k]*u[b, i0, a0, j]/4,
    -t[a, a0, i, k]*t[b, d, i0, l]*u[c, i0, a0, j]/4,
    -t[a, d, i0, l]*t[a0, b, i, k]*u[c, i0, a0, j]/4,
    t[a0, b, i, k]*t[c, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, a0, i, k]*t[c, d, i0, l]*u[b, i0, a0, j]/4,
    -t[a0, c, i, k]*t[b, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, d, i0, l]*t[a0, c, i, k]*u[b, i0, a0, j]/4,
    -t[a, a0, i, k]*t[b, d, i0, l]*u[c, i0, a0, j]/4,
    -t[a, d, i0, l]*t[a0, b, i, k]*u[c, i0, a0, j]/4,
    t[a0, d, i, k]*t[b, c, i0, l]*u[a, i0, a0, j]/4,
    -t[a, c, i0, l]*t[a0, d, i, k]*u[b, i0, a0, j]/4,
    t[a0, d, i, k]*t[b, c, i0, l]*u[a, i0, a0, j]/4,
    -t[a, c, i0, l]*t[a0, d, i, k]*u[b, i0, a0, j]/4,
    t[a, b, i0, l]*t[a0, d, i, k]*u[c, i0, a0, j]/4,
    t[a, b, i0, l]*t[a0, d, i, k]*u[c, i0, a0, j]/4,
    t[a, a0, i, k]*t[b, c, i0, l]*u[d, i0, a0, j]/4,
    t[a, c, i0, l]*t[a0, b, i, k]*u[d, i0, a0, j]/4,
    t[a, a0, i, k]*t[b, c, i0, l]*u[d, i0, a0, j]/4,
    t[a, c, i0, l]*t[a0, b, i, k]*u[d, i0, a0, j]/4,
    -t[a, b, i0, l]*t[a0, c, i, k]*u[d, i0, a0, j]/4,
    -t[a, b, i0, l]*t[a0, c, i, k]*u[d, i0, a0, j]/4,
    -t[a0, b, i, k]*t[c, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, a0, i, k]*t[c, d, i0, j]*u[b, i0, a0, l]/4,
    t[a0, c, i, k]*t[b, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, d, i0, j]*t[a0, c, i, k]*u[b, i0, a0, l]/4,
    t[a, a0, i, k]*t[b, d, i0, j]*u[c, i0, a0, l]/4,
    t[a, d, i0, j]*t[a0, b, i, k]*u[c, i0, a0, l]/4,
    -t[a0, b, i, k]*t[c, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, a0, i, k]*t[c, d, i0, j]*u[b, i0, a0, l]/4,
    t[a0, c, i, k]*t[b, d, i0, j]*u[a, i0, a0, l]/4,
    -t[a, d, i0, j]*t[a0, c, i, k]*u[b, i0, a0, l]/4,
    t[a, a0, i, k]*t[b, d, i0, j]*u[c, i0, a0, l]/4,
    t[a, d, i0, j]*t[a0, b, i, k]*u[c, i0, a0, l]/4,
    -t[a0, d, i, k]*t[b, c, i0, j]*u[a, i0, a0, l]/4,
    t[a, c, i0, j]*t[a0, d, i, k]*u[b, i0, a0, l]/4,
    -t[a0, d, i, k]*t[b, c, i0, j]*u[a, i0, a0, l]/4,
    t[a, c, i0, j]*t[a0, d, i, k]*u[b, i0, a0, l]/4,
    -t[a, b, i0, j]*t[a0, d, i, k]*u[c, i0, a0, l]/4,
    -t[a, b, i0, j]*t[a0, d, i, k]*u[c, i0, a0, l]/4,
    -t[a, a0, i, k]*t[b, c, i0, j]*u[d, i0, a0, l]/4,
    -t[a, c, i0, j]*t[a0, b, i, k]*u[d, i0, a0, l]/4,
    -t[a, a0, i, k]*t[b, c, i0, j]*u[d, i0, a0, l]/4,
    -t[a, c, i0, j]*t[a0, b, i, k]*u[d, i0, a0, l]/4,
    t[a, b, i0, j]*t[a0, c, i, k]*u[d, i0, a0, l]/4,
    t[a, b, i0, j]*t[a0, c, i, k]*u[d, i0, a0, l]/4,
    t[a0, b, i, l]*t[c, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, a0, i, l]*t[c, d, i0, j]*u[b, i0, a0, k]/4,
    -t[a0, c, i, l]*t[b, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, d, i0, j]*t[a0, c, i, l]*u[b, i0, a0, k]/4,
    -t[a, a0, i, l]*t[b, d, i0, j]*u[c, i0, a0, k]/4,
    -t[a, d, i0, j]*t[a0, b, i, l]*u[c, i0, a0, k]/4,
    t[a0, b, i, l]*t[c, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, a0, i, l]*t[c, d, i0, j]*u[b, i0, a0, k]/4,
    -t[a0, c, i, l]*t[b, d, i0, j]*u[a, i0, a0, k]/4,
    t[a, d, i0, j]*t[a0, c, i, l]*u[b, i0, a0, k]/4,
    -t[a, a0, i, l]*t[b, d, i0, j]*u[c, i0, a0, k]/4,
    -t[a, d, i0, j]*t[a0, b, i, l]*u[c, i0, a0, k]/4,
    t[a0, d, i, l]*t[b, c, i0, j]*u[a, i0, a0, k]/4,
    -t[a, c, i0, j]*t[a0, d, i, l]*u[b, i0, a0, k]/4,
    t[a0, d, i, l]*t[b, c, i0, j]*u[a, i0, a0, k]/4,
    -t[a, c, i0, j]*t[a0, d, i, l]*u[b, i0, a0, k]/4,
    t[a, b, i0, j]*t[a0, d, i, l]*u[c, i0, a0, k]/4,
    t[a, b, i0, j]*t[a0, d, i, l]*u[c, i0, a0, k]/4,
    t[a, a0, i, l]*t[b, c, i0, j]*u[d, i0, a0, k]/4,
    t[a, c, i0, j]*t[a0, b, i, l]*u[d, i0, a0, k]/4,
    t[a, a0, i, l]*t[b, c, i0, j]*u[d, i0, a0, k]/4,
    t[a, c, i0, j]*t[a0, b, i, l]*u[d, i0, a0, k]/4,
    -t[a, b, i0, j]*t[a0, c, i, l]*u[d, i0, a0, k]/4,
    -t[a, b, i0, j]*t[a0, c, i, l]*u[d, i0, a0, k]/4,
    t[a0, b, i, j]*t[c, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, a0, i, j]*t[c, d, i0, k]*u[b, i0, a0, l]/4,
    -t[a0, c, i, j]*t[b, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, d, i0, k]*t[a0, c, i, j]*u[b, i0, a0, l]/4,
    -t[a, a0, i, j]*t[b, d, i0, k]*u[c, i0, a0, l]/4,
    -t[a, d, i0, k]*t[a0, b, i, j]*u[c, i0, a0, l]/4,
    t[a0, b, i, j]*t[c, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, a0, i, j]*t[c, d, i0, k]*u[b, i0, a0, l]/4,
    -t[a0, c, i, j]*t[b, d, i0, k]*u[a, i0, a0, l]/4,
    t[a, d, i0, k]*t[a0, c, i, j]*u[b, i0, a0, l]/4,
    -t[a, a0, i, j]*t[b, d, i0, k]*u[c, i0, a0, l]/4,
    -t[a, d, i0, k]*t[a0, b, i, j]*u[c, i0, a0, l]/4,
    t[a0, d, i, j]*t[b, c, i0, k]*u[a, i0, a0, l]/4,
    -t[a, c, i0, k]*t[a0, d, i, j]*u[b, i0, a0, l]/4,
    t[a0, d, i, j]*t[b, c, i0, k]*u[a, i0, a0, l]/4,
    -t[a, c, i0, k]*t[a0, d, i, j]*u[b, i0, a0, l]/4,
    t[a, b, i0, k]*t[a0, d, i, j]*u[c, i0, a0, l]/4,
    t[a, b, i0, k]*t[a0, d, i, j]*u[c, i0, a0, l]/4,
    t[a, a0, i, j]*t[b, c, i0, k]*u[d, i0, a0, l]/4,
    t[a, c, i0, k]*t[a0, b, i, j]*u[d, i0, a0, l]/4,
    t[a, a0, i, j]*t[b, c, i0, k]*u[d, i0, a0, l]/4,
    t[a, c, i0, k]*t[a0, b, i, j]*u[d, i0, a0, l]/4,
    -t[a, b, i0, k]*t[a0, c, i, j]*u[d, i0, a0, l]/4,
    -t[a, b, i0, k]*t[a0, c, i, j]*u[d, i0, a0, l]/4,
    -t[a0, b, i, j]*t[c, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, a0, i, j]*t[c, d, i0, l]*u[b, i0, a0, k]/4,
    t[a0, c, i, j]*t[b, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, d, i0, l]*t[a0, c, i, j]*u[b, i0, a0, k]/4,
    t[a, a0, i, j]*t[b, d, i0, l]*u[c, i0, a0, k]/4,
    t[a, d, i0, l]*t[a0, b, i, j]*u[c, i0, a0, k]/4,
    -t[a0, b, i, j]*t[c, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, a0, i, j]*t[c, d, i0, l]*u[b, i0, a0, k]/4,
    t[a0, c, i, j]*t[b, d, i0, l]*u[a, i0, a0, k]/4,
    -t[a, d, i0, l]*t[a0, c, i, j]*u[b, i0, a0, k]/4,
    t[a, a0, i, j]*t[b, d, i0, l]*u[c, i0, a0, k]/4,
    t[a, d, i0, l]*t[a0, b, i, j]*u[c, i0, a0, k]/4,
    -t[a0, d, i, j]*t[b, c, i0, l]*u[a, i0, a0, k]/4,
    t[a, c, i0, l]*t[a0, d, i, j]*u[b, i0, a0, k]/4,
    -t[a0, d, i, j]*t[b, c, i0, l]*u[a, i0, a0, k]/4,
    t[a, c, i0, l]*t[a0, d, i, j]*u[b, i0, a0, k]/4,
    -t[a, b, i0, l]*t[a0, d, i, j]*u[c, i0, a0, k]/4,
    -t[a, b, i0, l]*t[a0, d, i, j]*u[c, i0, a0, k]/4,
    -t[a, a0, i, j]*t[b, c, i0, l]*u[d, i0, a0, k]/4,
    -t[a, c, i0, l]*t[a0, b, i, j]*u[d, i0, a0, k]/4,
    -t[a, a0, i, j]*t[b, c, i0, l]*u[d, i0, a0, k]/4,
    -t[a, c, i0, l]*t[a0, b, i, j]*u[d, i0, a0, k]/4,
    t[a, b, i0, l]*t[a0, c, i, j]*u[d, i0, a0, k]/4,
    t[a, b, i0, l]*t[a0, c, i, j]*u[d, i0, a0, k]/4,
    -t[a0, b, i, l]*t[c, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, a0, i, l]*t[c, d, i0, k]*u[b, i0, a0, j]/4,
    t[a0, c, i, l]*t[b, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, d, i0, k]*t[a0, c, i, l]*u[b, i0, a0, j]/4,
    t[a, a0, i, l]*t[b, d, i0, k]*u[c, i0, a0, j]/4,
    t[a, d, i0, k]*t[a0, b, i, l]*u[c, i0, a0, j]/4,
    -t[a0, b, i, l]*t[c, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, a0, i, l]*t[c, d, i0, k]*u[b, i0, a0, j]/4,
    t[a0, c, i, l]*t[b, d, i0, k]*u[a, i0, a0, j]/4,
    -t[a, d, i0, k]*t[a0, c, i, l]*u[b, i0, a0, j]/4,
    t[a, a0, i, l]*t[b, d, i0, k]*u[c, i0, a0, j]/4,
    t[a, d, i0, k]*t[a0, b, i, l]*u[c, i0, a0, j]/4,
    -t[a0, d, i, l]*t[b, c, i0, k]*u[a, i0, a0, j]/4,
    t[a, c, i0, k]*t[a0, d, i, l]*u[b, i0, a0, j]/4,
    -t[a0, d, i, l]*t[b, c, i0, k]*u[a, i0, a0, j]/4,
    t[a, c, i0, k]*t[a0, d, i, l]*u[b, i0, a0, j]/4,
    -t[a, b, i0, k]*t[a0, d, i, l]*u[c, i0, a0, j]/4,
    -t[a, b, i0, k]*t[a0, d, i, l]*u[c, i0, a0, j]/4,
    -t[a, a0, i, l]*t[b, c, i0, k]*u[d, i0, a0, j]/4,
    -t[a, c, i0, k]*t[a0, b, i, l]*u[d, i0, a0, j]/4,
    -t[a, a0, i, l]*t[b, c, i0, k]*u[d, i0, a0, j]/4,
    -t[a, c, i0, k]*t[a0, b, i, l]*u[d, i0, a0, j]/4,
    t[a, b, i0, k]*t[a0, c, i, l]*u[d, i0, a0, j]/4,
    t[a, b, i0, k]*t[a0, c, i, l]*u[d, i0, a0, j]/4,
    t[a0, b, i, k]*t[c, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, a0, i, k]*t[c, d, i0, l]*u[b, i0, a0, j]/4,
    -t[a0, c, i, k]*t[b, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, d, i0, l]*t[a0, c, i, k]*u[b, i0, a0, j]/4,
    -t[a, a0, i, k]*t[b, d, i0, l]*u[c, i0, a0, j]/4,
    -t[a, d, i0, l]*t[a0, b, i, k]*u[c, i0, a0, j]/4,
    t[a0, b, i, k]*t[c, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, a0, i, k]*t[c, d, i0, l]*u[b, i0, a0, j]/4,
    -t[a0, c, i, k]*t[b, d, i0, l]*u[a, i0, a0, j]/4,
    t[a, d, i0, l]*t[a0, c, i, k]*u[b, i0, a0, j]/4,
    -t[a, a0, i, k]*t[b, d, i0, l]*u[c, i0, a0, j]/4,
    -t[a, d, i0, l]*t[a0, b, i, k]*u[c, i0, a0, j]/4,
    t[a0, d, i, k]*t[b, c, i0, l]*u[a, i0, a0, j]/4,
    -t[a, c, i0, l]*t[a0, d, i, k]*u[b, i0, a0, j]/4,
    t[a0, d, i, k]*t[b, c, i0, l]*u[a, i0, a0, j]/4,
    -t[a, c, i0, l]*t[a0, d, i, k]*u[b, i0, a0, j]/4,
    t[a, b, i0, l]*t[a0, d, i, k]*u[c, i0, a0, j]/4,
    t[a, b, i0, l]*t[a0, d, i, k]*u[c, i0, a0, j]/4,
    t[a, a0, i, k]*t[b, c, i0, l]*u[d, i0, a0, j]/4,
    t[a, c, i0, l]*t[a0, b, i, k]*u[d, i0, a0, j]/4,
    t[a, a0, i, k]*t[b, c, i0, l]*u[d, i0, a0, j]/4,
    t[a, c, i0, l]*t[a0, b, i, k]*u[d, i0, a0, j]/4,
    -t[a, b, i0, l]*t[a0, c, i, k]*u[d, i0, a0, j]/4,
    -t[a, b, i0, l]*t[a0, c, i, k]*u[d, i0, a0, j]/4,
    -t[a0, b, k, l]*t[c, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, a0, k, l]*t[c, d, i0, j]*u[b, i0, a0, i]/4,
    t[a0, c, k, l]*t[b, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, d, i0, j]*t[a0, c, k, l]*u[b, i0, a0, i]/4,
    t[a, a0, k, l]*t[b, d, i0, j]*u[c, i0, a0, i]/4,
    t[a, d, i0, j]*t[a0, b, k, l]*u[c, i0, a0, i]/4,
    -t[a0, b, k, l]*t[c, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, a0, k, l]*t[c, d, i0, j]*u[b, i0, a0, i]/4,
    t[a0, c, k, l]*t[b, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, d, i0, j]*t[a0, c, k, l]*u[b, i0, a0, i]/4,
    t[a, a0, k, l]*t[b, d, i0, j]*u[c, i0, a0, i]/4,
    t[a, d, i0, j]*t[a0, b, k, l]*u[c, i0, a0, i]/4,
    -t[a0, d, k, l]*t[b, c, i0, j]*u[a, i0, a0, i]/4,
    t[a, c, i0, j]*t[a0, d, k, l]*u[b, i0, a0, i]/4,
    -t[a0, d, k, l]*t[b, c, i0, j]*u[a, i0, a0, i]/4,
    t[a, c, i0, j]*t[a0, d, k, l]*u[b, i0, a0, i]/4,
    -t[a, b, i0, j]*t[a0, d, k, l]*u[c, i0, a0, i]/4,
    -t[a, b, i0, j]*t[a0, d, k, l]*u[c, i0, a0, i]/4,
    -t[a, a0, k, l]*t[b, c, i0, j]*u[d, i0, a0, i]/4,
    -t[a, c, i0, j]*t[a0, b, k, l]*u[d, i0, a0, i]/4,
    -t[a, a0, k, l]*t[b, c, i0, j]*u[d, i0, a0, i]/4,
    -t[a, c, i0, j]*t[a0, b, k, l]*u[d, i0, a0, i]/4,
    t[a, b, i0, j]*t[a0, c, k, l]*u[d, i0, a0, i]/4,
    t[a, b, i0, j]*t[a0, c, k, l]*u[d, i0, a0, i]/4,
    -t[a0, b, k, l]*t[c, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, a0, k, l]*t[c, d, i0, j]*u[b, i0, a0, i]/4,
    t[a0, c, k, l]*t[b, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, d, i0, j]*t[a0, c, k, l]*u[b, i0, a0, i]/4,
    t[a, a0, k, l]*t[b, d, i0, j]*u[c, i0, a0, i]/4,
    t[a, d, i0, j]*t[a0, b, k, l]*u[c, i0, a0, i]/4,
    -t[a0, b, k, l]*t[c, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, a0, k, l]*t[c, d, i0, j]*u[b, i0, a0, i]/4,
    t[a0, c, k, l]*t[b, d, i0, j]*u[a, i0, a0, i]/4,
    -t[a, d, i0, j]*t[a0, c, k, l]*u[b, i0, a0, i]/4,
    t[a, a0, k, l]*t[b, d, i0, j]*u[c, i0, a0, i]/4,
    t[a, d, i0, j]*t[a0, b, k, l]*u[c, i0, a0, i]/4,
    -t[a0, d, k, l]*t[b, c, i0, j]*u[a, i0, a0, i]/4,
    t[a, c, i0, j]*t[a0, d, k, l]*u[b, i0, a0, i]/4,
    -t[a0, d, k, l]*t[b, c, i0, j]*u[a, i0, a0, i]/4,
    t[a, c, i0, j]*t[a0, d, k, l]*u[b, i0, a0, i]/4,
    -t[a, b, i0, j]*t[a0, d, k, l]*u[c, i0, a0, i]/4,
    -t[a, b, i0, j]*t[a0, d, k, l]*u[c, i0, a0, i]/4,
    -t[a, a0, k, l]*t[b, c, i0, j]*u[d, i0, a0, i]/4,
    -t[a, c, i0, j]*t[a0, b, k, l]*u[d, i0, a0, i]/4,
    -t[a, a0, k, l]*t[b, c, i0, j]*u[d, i0, a0, i]/4,
    -t[a, c, i0, j]*t[a0, b, k, l]*u[d, i0, a0, i]/4,
    t[a, b, i0, j]*t[a0, c, k, l]*u[d, i0, a0, i]/4,
    t[a, b, i0, j]*t[a0, c, k, l]*u[d, i0, a0, i]/4,
    t[a0, b, j, l]*t[c, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, a0, j, l]*t[c, d, i0, k]*u[b, i0, a0, i]/4,
    -t[a0, c, j, l]*t[b, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, d, i0, k]*t[a0, c, j, l]*u[b, i0, a0, i]/4,
    -t[a, a0, j, l]*t[b, d, i0, k]*u[c, i0, a0, i]/4,
    -t[a, d, i0, k]*t[a0, b, j, l]*u[c, i0, a0, i]/4,
    t[a0, b, j, l]*t[c, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, a0, j, l]*t[c, d, i0, k]*u[b, i0, a0, i]/4,
    -t[a0, c, j, l]*t[b, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, d, i0, k]*t[a0, c, j, l]*u[b, i0, a0, i]/4,
    -t[a, a0, j, l]*t[b, d, i0, k]*u[c, i0, a0, i]/4,
    -t[a, d, i0, k]*t[a0, b, j, l]*u[c, i0, a0, i]/4,
    t[a0, d, j, l]*t[b, c, i0, k]*u[a, i0, a0, i]/4,
    -t[a, c, i0, k]*t[a0, d, j, l]*u[b, i0, a0, i]/4,
    t[a0, d, j, l]*t[b, c, i0, k]*u[a, i0, a0, i]/4,
    -t[a, c, i0, k]*t[a0, d, j, l]*u[b, i0, a0, i]/4,
    t[a, b, i0, k]*t[a0, d, j, l]*u[c, i0, a0, i]/4,
    t[a, b, i0, k]*t[a0, d, j, l]*u[c, i0, a0, i]/4,
    t[a, a0, j, l]*t[b, c, i0, k]*u[d, i0, a0, i]/4,
    t[a, c, i0, k]*t[a0, b, j, l]*u[d, i0, a0, i]/4,
    t[a, a0, j, l]*t[b, c, i0, k]*u[d, i0, a0, i]/4,
    t[a, c, i0, k]*t[a0, b, j, l]*u[d, i0, a0, i]/4,
    -t[a, b, i0, k]*t[a0, c, j, l]*u[d, i0, a0, i]/4,
    -t[a, b, i0, k]*t[a0, c, j, l]*u[d, i0, a0, i]/4,
    -t[a0, b, j, k]*t[c, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, a0, j, k]*t[c, d, i0, l]*u[b, i0, a0, i]/4,
    t[a0, c, j, k]*t[b, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, d, i0, l]*t[a0, c, j, k]*u[b, i0, a0, i]/4,
    t[a, a0, j, k]*t[b, d, i0, l]*u[c, i0, a0, i]/4,
    t[a, d, i0, l]*t[a0, b, j, k]*u[c, i0, a0, i]/4,
    -t[a0, b, j, k]*t[c, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, a0, j, k]*t[c, d, i0, l]*u[b, i0, a0, i]/4,
    t[a0, c, j, k]*t[b, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, d, i0, l]*t[a0, c, j, k]*u[b, i0, a0, i]/4,
    t[a, a0, j, k]*t[b, d, i0, l]*u[c, i0, a0, i]/4,
    t[a, d, i0, l]*t[a0, b, j, k]*u[c, i0, a0, i]/4,
    -t[a0, d, j, k]*t[b, c, i0, l]*u[a, i0, a0, i]/4,
    t[a, c, i0, l]*t[a0, d, j, k]*u[b, i0, a0, i]/4,
    -t[a0, d, j, k]*t[b, c, i0, l]*u[a, i0, a0, i]/4,
    t[a, c, i0, l]*t[a0, d, j, k]*u[b, i0, a0, i]/4,
    -t[a, b, i0, l]*t[a0, d, j, k]*u[c, i0, a0, i]/4,
    -t[a, b, i0, l]*t[a0, d, j, k]*u[c, i0, a0, i]/4,
    -t[a, a0, j, k]*t[b, c, i0, l]*u[d, i0, a0, i]/4,
    -t[a, c, i0, l]*t[a0, b, j, k]*u[d, i0, a0, i]/4,
    -t[a, a0, j, k]*t[b, c, i0, l]*u[d, i0, a0, i]/4,
    -t[a, c, i0, l]*t[a0, b, j, k]*u[d, i0, a0, i]/4,
    t[a, b, i0, l]*t[a0, c, j, k]*u[d, i0, a0, i]/4,
    t[a, b, i0, l]*t[a0, c, j, k]*u[d, i0, a0, i]/4,
    t[a0, b, j, l]*t[c, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, a0, j, l]*t[c, d, i0, k]*u[b, i0, a0, i]/4,
    -t[a0, c, j, l]*t[b, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, d, i0, k]*t[a0, c, j, l]*u[b, i0, a0, i]/4,
    -t[a, a0, j, l]*t[b, d, i0, k]*u[c, i0, a0, i]/4,
    -t[a, d, i0, k]*t[a0, b, j, l]*u[c, i0, a0, i]/4,
    t[a0, b, j, l]*t[c, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, a0, j, l]*t[c, d, i0, k]*u[b, i0, a0, i]/4,
    -t[a0, c, j, l]*t[b, d, i0, k]*u[a, i0, a0, i]/4,
    t[a, d, i0, k]*t[a0, c, j, l]*u[b, i0, a0, i]/4,
    -t[a, a0, j, l]*t[b, d, i0, k]*u[c, i0, a0, i]/4,
    -t[a, d, i0, k]*t[a0, b, j, l]*u[c, i0, a0, i]/4,
    t[a0, d, j, l]*t[b, c, i0, k]*u[a, i0, a0, i]/4,
    -t[a, c, i0, k]*t[a0, d, j, l]*u[b, i0, a0, i]/4,
    t[a0, d, j, l]*t[b, c, i0, k]*u[a, i0, a0, i]/4,
    -t[a, c, i0, k]*t[a0, d, j, l]*u[b, i0, a0, i]/4,
    t[a, b, i0, k]*t[a0, d, j, l]*u[c, i0, a0, i]/4,
    t[a, b, i0, k]*t[a0, d, j, l]*u[c, i0, a0, i]/4,
    t[a, a0, j, l]*t[b, c, i0, k]*u[d, i0, a0, i]/4,
    t[a, c, i0, k]*t[a0, b, j, l]*u[d, i0, a0, i]/4,
    t[a, a0, j, l]*t[b, c, i0, k]*u[d, i0, a0, i]/4,
    t[a, c, i0, k]*t[a0, b, j, l]*u[d, i0, a0, i]/4,
    -t[a, b, i0, k]*t[a0, c, j, l]*u[d, i0, a0, i]/4,
    -t[a, b, i0, k]*t[a0, c, j, l]*u[d, i0, a0, i]/4,
    -t[a0, b, j, k]*t[c, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, a0, j, k]*t[c, d, i0, l]*u[b, i0, a0, i]/4,
    t[a0, c, j, k]*t[b, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, d, i0, l]*t[a0, c, j, k]*u[b, i0, a0, i]/4,
    t[a, a0, j, k]*t[b, d, i0, l]*u[c, i0, a0, i]/4,
    t[a, d, i0, l]*t[a0, b, j, k]*u[c, i0, a0, i]/4,
    -t[a0, b, j, k]*t[c, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, a0, j, k]*t[c, d, i0, l]*u[b, i0, a0, i]/4,
    t[a0, c, j, k]*t[b, d, i0, l]*u[a, i0, a0, i]/4,
    -t[a, d, i0, l]*t[a0, c, j, k]*u[b, i0, a0, i]/4,
    t[a, a0, j, k]*t[b, d, i0, l]*u[c, i0, a0, i]/4,
    t[a, d, i0, l]*t[a0, b, j, k]*u[c, i0, a0, i]/4,
    -t[a0, d, j, k]*t[b, c, i0, l]*u[a, i0, a0, i]/4,
    t[a, c, i0, l]*t[a0, d, j, k]*u[b, i0, a0, i]/4,
    -t[a0, d, j, k]*t[b, c, i0, l]*u[a, i0, a0, i]/4,
    t[a, c, i0, l]*t[a0, d, j, k]*u[b, i0, a0, i]/4,
    -t[a, b, i0, l]*t[a0, d, j, k]*u[c, i0, a0, i]/4,
    -t[a, b, i0, l]*t[a0, d, j, k]*u[c, i0, a0, i]/4,
    -t[a, a0, j, k]*t[b, c, i0, l]*u[d, i0, a0, i]/4,
    -t[a, c, i0, l]*t[a0, b, j, k]*u[d, i0, a0, i]/4,
    -t[a, a0, j, k]*t[b, c, i0, l]*u[d, i0, a0, i]/4,
    -t[a, c, i0, l]*t[a0, b, j, k]*u[d, i0, a0, i]/4,
    t[a, b, i0, l]*t[a0, c, j, k]*u[d, i0, a0, i]/4,
    t[a, b, i0, l]*t[a0, c, j, k]*u[d, i0, a0, i]/4
]

import pdb; pdb.set_trace()
sum_ = simplify(
     Add(*terms)
     )
@jksuom

This comment has been minimized.

Copy link
Member

jksuom commented Apr 24, 2015

I have been wondering what kind of simplification of Add(*terms) you are expecting. It is hard to see that any substantial number of terms would cancel. (Probably simplify() is not what you would want to use.)

@tschijnmo

This comment has been minimized.

Copy link
Contributor

tschijnmo commented Apr 24, 2015

For this case, definitely I was not expecting any specific kind of simplification since there is no much that can be done. I put simplify there just for generality, in some cases the terms in the list might be able to be merged together or even annihilates to zero.

Fraction would normally not occur here, but it seems that expression will be cast to a fraction over unity internally and takes some time to attempt to cancel this fraction, which is impossible to cancel further. I mean, is it good to implement something to skip all the processing when one of the numerator or denominator is unity, or maybe something more general, like a small quick prime test. If any of them is tested to be a prime (integer or polynomial), then the GCD computation and cancelling can be skipped?

tschijnmo added a commit to tschijnmo/sympy that referenced this issue Nov 3, 2015

Shortcut cancelling fractions with integer one
Fractions with integer one in either the numerator or the denominator
would make it possible to cancelled out any common factor from the
numerator and the denominator.  However, in the current implementation,
there is no special treatment for this situation.  The computation of
the GCD with integer one would take a long time by using the Euclidean
algorithm, as in the issue sympy#9341.

As a result, in this commit, when called with expressions, the cancel
function will directly return the quotient when an integer unity is
found.  This could solve issue sympy#9314.  And when the function is called
with polynomials directly or called with tuples, this short-cut will not
be invoked to better preserve its original behaviour in internal use.
@tschijnmo

This comment has been minimized.

Copy link
Contributor

tschijnmo commented Nov 10, 2015

Solved by PR #10112.

@tschijnmo tschijnmo closed this Nov 10, 2015

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 16, 2016

Shortcut cancelling fractions with integer one
Fractions with integer one in either the numerator or the denominator
would make it possible to cancelled out any common factor from the
numerator and the denominator.  However, in the current implementation,
there is no special treatment for this situation.  The computation of
the GCD with integer one would take a long time by using the Euclidean
algorithm, as in the issue sympy/sympy#9341.

As a result, in this commit, when called with expressions, the cancel
function will directly return the quotient when an integer unity is
found.  This could solve issue #9314.  And when the function is called
with polynomials directly or called with tuples, this short-cut will not
be invoked to better preserve its original behaviour in internal use.

Add one as special case in computing GCD of DMP

In the GCD computation of dense multivariate polynomials, previously in
function `sympy.polys.euclidtools._dmp_rr_trivial_gcd`, only the special
cases with one of the polynomials being zero is specially treated as
trivial case.  However, the polynomial of constant unity is the unit of
the multiplication operation in the ring, so it cannot possibly have
other GCD with any polynomial.  So now one is being handled as a special
case as well to skip the later expensive operations.

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016

Add regression tests & mention closed issues
    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
    close sympy/sympy#9173 (test was added in 5a510ac)
    close sympy/sympy#9808 (fixed in 09e539b)
    close sympy/sympy#9341 (fixed in af98a00)
    close sympy/sympy#9908 (fixed in cc3fa8d)
    close sympy/sympy#6171 (test added in d278031)
    close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
    close sympy/sympy#10201 (fixed in 0d0fc5f)
    close sympy/sympy#9057 (test was added in 8290a0c)
    close sympy/sympy#11159 (test was added in ffb76cb)
    close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
    close sympy/sympy#11081 (see ed01e16 and bb92329)
    close sympy/sympy#10974 (see 73fc425)
    close sympy/sympy#10806 (test in 539929a)
    close sympy/sympy#10801 (test in 2fe3da5)
    close sympy/sympy#9549 (test in 88bdefa)
    close sympy/sympy#4231 (test was added in fb411d5)
    close sympy/sympy#8634 (see 2fcbb58)
    close sympy/sympy#8481 (see 1ef20d3)
    close sympy/sympy#9956 (fixed in a34735f)
    close sympy/sympy#9747 (see e117c60)
    close sympy/sympy#7853 (see 3e4fbed)
    close sympy/sympy#9634 (see 2be03f5)
    close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
    close sympy/sympy#9192 (see 9bf622f)
    close sympy/sympy#7130 (see e068fa3)
    close sympy/sympy#8514 (see b2d543b)
    close sympy/sympy#9334 (see 90de625)
    close sympy/sympy#8229 (see 9755b89)
    close sympy/sympy#8061 (see 7054f06)
    close sympy/sympy#7872 (tested in diofant#6)
    close sympy/sympy#3496 (tested in test_log_symbolic)
    close sympy/sympy#2929 (see da7db7a)
    close sympy/sympy#8203 (oo is not a real, see diofant#36)
    close sympy/sympy#7649 (0 is imaginary since diofant#8)
    close sympy/sympy#7256 (fixed in c0a4549)
    close sympy/sympy#6783 (see cb28d63)
    close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
    close sympy/sympy#5295 (fixed with diofant#354)
    close sympy/sympy#4856 (we now have flake/pep tests)
    close sympy/sympy#4555 (flake8 enabled after diofant#214)
    close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
    close sympy/sympy#5484 (see above)

    Added regression tests:
    from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw
    fixes sympy/sympy#8825 (probably via diofant#209)
    fixes sympy/sympy#8635
    fixes sympy/sympy#8157
    fixes sympy/sympy#7872
    fixes sympy/sympy#7599
    fixes sympy/sympy#6179
    fixes sympy/sympy#5415
    fixes sympy/sympy#2865
    fixes sympy/sympy#5907
    fixes sympy/sympy#11722

    Closes diofant#347

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016

Add regression tests & mention closed issues
    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
    close sympy/sympy#9173 (test was added in 5a510ac)
    close sympy/sympy#9808 (fixed in 09e539b)
    close sympy/sympy#9341 (fixed in af98a00)
    close sympy/sympy#9908 (fixed in cc3fa8d)
    close sympy/sympy#6171 (test added in d278031)
    close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
    close sympy/sympy#10201 (fixed in 0d0fc5f)
    close sympy/sympy#9057 (test was added in 8290a0c)
    close sympy/sympy#11159 (test was added in ffb76cb)
    close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
    close sympy/sympy#11081 (see ed01e16 and bb92329)
    close sympy/sympy#10974 (see 73fc425)
    close sympy/sympy#10806 (test in 539929a)
    close sympy/sympy#10801 (test in 2fe3da5)
    close sympy/sympy#9549 (test in 88bdefa)
    close sympy/sympy#4231 (test was added in fb411d5)
    close sympy/sympy#8634 (see 2fcbb58)
    close sympy/sympy#8481 (see 1ef20d3)
    close sympy/sympy#9956 (fixed in a34735f)
    close sympy/sympy#9747 (see e117c60)
    close sympy/sympy#7853 (see 3e4fbed)
    close sympy/sympy#9634 (see 2be03f5)
    close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
    close sympy/sympy#9192 (see 9bf622f)
    close sympy/sympy#7130 (see e068fa3)
    close sympy/sympy#8514 (see b2d543b)
    close sympy/sympy#9334 (see 90de625)
    close sympy/sympy#8229 (see 9755b89)
    close sympy/sympy#8061 (see 7054f06)
    close sympy/sympy#7872 (tested in diofant#6)
    close sympy/sympy#3496 (tested in test_log_symbolic)
    close sympy/sympy#2929 (see da7db7a)
    close sympy/sympy#8203 (oo is not a real, see diofant#36)
    close sympy/sympy#7649 (0 is imaginary since diofant#8)
    close sympy/sympy#7256 (fixed in c0a4549)
    close sympy/sympy#6783 (see cb28d63)
    close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
    close sympy/sympy#5295 (fixed with diofant#354)
    close sympy/sympy#4856 (we now have flake/pep tests)
    close sympy/sympy#4555 (flake8 enabled after diofant#214)
    close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
    close sympy/sympy#5484 (see above)

    Added regression tests:
    from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw
    fixes sympy/sympy#8825 (probably via diofant#209)
    fixes sympy/sympy#8635
    fixes sympy/sympy#8157
    fixes sympy/sympy#7872
    fixes sympy/sympy#7599
    fixes sympy/sympy#6179
    fixes sympy/sympy#5415
    fixes sympy/sympy#2865
    fixes sympy/sympy#5907
    fixes sympy/sympy#11722

    Closes diofant#347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment