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_exp
which 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?
For a test, I have something around 500 digits long when not simplified, and that takes less than 1 minute to simplify
If you want us to give a try, you need to provide your code.
This is the code:
Something is wrong with the line
probably you meant
The problem has a definite geometric flavour. It seems
Circum2d
computes the circumcenter of a triangle;