Ask Your Question
1

What is the average simplification time for Sage?

asked 2018-07-03 12:01:45 +0200

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

Comments

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 12:09:42 +0200 )edit

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

tmonteil gravatar imagetmonteil ( 2018-07-03 13:05:36 +0200 )edit

This is the code:

var('a_1')  
var('z')   
var('b_1')   
var('c_1')   
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)   
f(H,G)/sqrt(f(H,H)*f(G,G)).simplify_rational()
Trev gravatar imageTrev ( 2018-07-03 13:39:45 +0200 )edit

Something is wrong with the line

H = Circum+Circum2d(a,b,d)+Circum(a,c,d)+Circum(b,c,d)

probably you meant

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

The problem has a definite geometric flavour. It seems

  • $a$, $b$, $c$ are unit vectors located on a common horizontal plane at altitude $z$; from their $x$-coordinates and the chosen $z$, one picks the appropriate nonnegative value of $y$; this assumes that $a_1^2 + z^2 < 1$, and similarly for $b_1$ and $c_1$;
  • $H_1$ is the sum of $a$, $b$, $c$, projected to the horizontal plane
  • $d$ is the point on the unit sphere lying right below $H_1$; it exists under the extra assumption that $H_1$ is in the unit disc,
  • taking the average of $a$, $b$, $c$, rather than their sum, might seem more natural, in the absence of any context...
  • the function Circum2d computes the circumcenter of a triangle;
slelievre gravatar imageslelievre ( 2018-07-25 07:28:25 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-07-11 15:29:40 +0200

slelievre gravatar image

updated 2018-07-25 07:50:12 +0200

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

Note that the dot product of vectors can be obtained as u*v-- no need for .dot_product or for the function f in the question.

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 cc instead of Circum2d
  • use vh instead of H_1 and just (vh*vh) for H_d
  • use auxiliary functions mn and md (for numerator and denominator) to help define p

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 mn(x, y):
....:     return (x*x)*(y*y) - (x*y)*(y*y)
sage: def md(x, y):
....:     return 2*((x*x)*(y*y) - (x*y)*(x*y))
sage: def p(x, y):
....:     return (mn(x, y)/md(x, y))*x + (mn(y, x)/md(x, y))*y
sage: def cc(r, s, t):
....:     return p((r - t), (s - t)) + t
sage: G = 1/4*(va + vb + vc + vd)
sage: H = vu + cc(va, vb, vd) + cc(va, vc, vd) + cc(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)
49587

(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; e.g., when computing cc(va, vb, vd) and similar vectors; 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()

But nothing seems to particularly want to simplify, and before going into a whole lot of trouble, is there a particular reason to hope the expression should simplify to something nice?

What is the underlying geometric problem?

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

Stats

Asked: 2018-07-03 11:41:43 +0200

Seen: 340 times

Last updated: Jul 25 '18