Ask Your Question

What is the average simplification time for Sage?

asked 2018-07-03 05:01:45 -0500

Trev gravatar image

I have a big chunk of expression that needs simplification, but it seems to take ages. I am not sure if Sage is not working while my computer rests for a while, or just that the simplification really takes that long time.

A range would be enough. I have roughly 30000 - 40000 digits long when not simplified.

edit retag flag offensive close merge delete


For a test, I have something around 500 digits long when not simplified, and that takes less than 1 minute to simplify

Trev gravatar imageTrev ( 2018-07-03 05:09:42 -0500 )edit

If you want us to give a try, you need to provide your code.

tmonteil gravatar imagetmonteil ( 2018-07-03 06:05:36 -0500 )edit

This is the code:

a = vector([a_1,sqrt(1-a_1^2-z^2),z])   
b = vector([b_1,sqrt(1-b_1^2-z^2),z])   
c = vector([c_1,sqrt(1-c_1^2-z^2),z])   
Circum = vector([0,0,z])   
H_1 = a+b+c-3*Circum   
def f(x,y):   
     return x.dot_product(y)   
H_d = f(H_1,H_1)   
d = H_1 - sqrt (1-H_d) * vector([0,0,1])   
def p(x,y):   
     return (f(x,x)*f(y,y)-f(x,y)*f(y,y))*x/(2*f(x,x)*f(y,y)-2*f(x,y)*f(x,y))+(f(x,x)*f(y,y)-f(x,y)*f(x,x))*y/(2*f(x,x)*f(y,y)-2*f(x,y)*f(x,y))   
def Circum2d(r,s,t):   
     return p((r-t),(s-t))+t   
G = 1/4*(a+b+c+d)   
H = Circum+Circum2d(a,b,d)+Circum(a,c,d)+Circum(b,c,d)   
Trev gravatar imageTrev ( 2018-07-03 06:39:45 -0500 )edit

Something is wrong with the line

H = Circum+Circum2d(a,b,d)+Circum(a,c,d)+Circum(b,c,d)
slelievre gravatar imageslelievre ( 2018-07-11 07:33:25 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2018-07-11 08:29:40 -0500

slelievre gravatar image

This is more of a comment, but posted as an answer since it is fairly long.

Note that * is enough to compute dot product of vectors, no need for .dot_product or the function f that you defined for short.

Below is an attempt to somewhat simplify the code in the question, to make it easier on the eye.

  • use a, b, c instead of a_1, b_1, c_1
  • use va, vb, vc instead of a, b, c
  • use vu instead of Circum and vinstead of Circum2d
  • use vh instead of H_1 and just (vh*vh) for H_d
  • use an auxiliary function m to help define p
  • name w the end result in the question

If I got things right, the computation can then be rewritten as:

sage: a, b, c, z = SR.var('a b c z')
sage: va = vector([a, sqrt(1 - a^2 - z^2), z])
sage: vb = vector([b, sqrt(1 - b^2 - z^2), z])
sage: vc = vector([c, sqrt(1 - c^2 - z^2), z])
sage: vu = vector([0, 0, z])
sage: vh = va + vb + vc - 3*vu
sage: vd = vh - sqrt(1 - (vh*vh)) * vector([0, 0, 1])
sage: def m(x, y):
....:     return ((x*x)*(y*y) - (x*y)*(y*y))/(2*(x*x)*(y*y) - 2*(x*y)*(x*y))
sage: def p(x, y):
....:      return m(x, y)*x + m(y, x)*y
sage: def v(r, s, t):
....:      return p((r - t), (s - t)) + t
sage: G = 1/4*(va + vb + vc + vd)
sage: H = vu + v(va, vb, vd) + v(va, vc, vd) + v(vb, vc, vd)
sage: w = (H*G)/sqrt((H*H)*(G*G))

and if I understand correctly, the question is how to simplify w, right?

(In the question, the method .simplify_rational is applied only to the denominator but I guess the intention was to simplify the whole thing.)

Note that the string representation of w is quite long: with ~ 50k characters.

sage: s = str(w)
sage: len(s)

(Note that with the original a_1, b_1, c_1 we would get 55539).

Now, how to go about that?

One could use .simplify_full instead of just .simplify_rational, or try .simplify_expwhich might work better with square roots.

One could try to simplify at each step, instead of only at the end; that is, apply simplifications in the functions m, p, v, and then in G and H before computing w.

One could compute the square of w rather than w itself, getting rid of the sqrt in the denominator:

sage: ww = (H*G)*(H*G)/(H*H)*(G*G)

or even

sage: hg = (H*G).simplify_full()
sage: hh = (H*H).simplify_full()
sage: gg = (G*G).simplify_full()
sage: wwnum = (hg^2).simplify_full()
sage: wwden = (hh*gg).simplify_full()
sage: ww = (wwnum/wwden).simplify_full()
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


Asked: 2018-07-03 04:41:43 -0500

Seen: 45 times

Last updated: Jul 11