Ask Your Question

Revision history [back]

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)
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; 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()

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

Note that * is enough to compute the dot product of vectors, vectors can be obtained as u*v-- no need for .dot_product or for the function f that you defined for short.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 vcc instead of Circum2d
  • use vh instead of H_1 and just (vh*vh) for H_d
  • use an auxiliary function m functions mn and md (for numerator and denominator) 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, mn(x, y):
....:     return ((x*x)*(y*y) - (x*y)*(y*y))/(2*(x*x)*(y*y) - 2*(x*y)*(x*y))
(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 m(x, y)*x + m(y, x)*y
(mn(x, y)/md(x, y))*x + (mn(y, x)/md(x, y))*y
sage: def v(r, cc(r, s, t):
....:      return p((r - t), (s - t)) + t
sage: G = 1/4*(va + vb + vc + vd)
sage: H = vu + v(va, cc(va, vb, vd) + v(va, cc(va, vc, vd) + v(vb, 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; that is, apply simplifications in the functions m, p, v, 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?