1 | initial version |
This means that Sage
's solve
by itself does not find an explicit solution to this equation. Indeed:
sage: Eq = 1/(a*(x - 1)) == 1/2*sqrt(x^2 + 1)/l
sage: solve(Eq, x)
[x == (sqrt(x^2 + 1)*a + 2*l)/(sqrt(x^2 + 1)*a)]
sage: solve(Eq, x, to_poly_solve=True)
[]
sage: solve(Eq, x, to_poly_solve="force")
[]
sage: solve(Eq, x, algorithm="giac")
[x == (sqrt(x^2 + 1)*a + 2*l)/(sqrt(x^2 + 1)*a)]
sage: solve(Eq, x, algorithm="fricas")
[x == (sqrt(x^2 + 1)*a + 2*l)/(sqrt(x^2 + 1)*a)]
However, eliminating the radical (thus getting an equation in rational fractions) is easily solved :
sage: foo=(Eq^2).expand().solve(x)
sage: foo
[x == -1/2*sqrt(-2*sqrt(3)*a/sqrt((2*a^2*(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(2/3) - a^2*(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(1/3) + 2*a^2 - 24*l^2)/(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(1/3)) + 2/3*(12*l^2/a^2 - 1)/(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(1/3) - 2/3*(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(1/3) - 2/3) - 1/6*sqrt(3)*sqrt((2*a^2*(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(2/3) - a^2*(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(1/3) + 2*a^2 - 24*l^2)/(9*l^2/a^2 + 9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4)*l/a^3 + 1)^(1/3) + 2*a^2 - 24*l^2)/(9*l^2/a^2 + 9*sqrt(2/3*a^4 - 13/3*a^2*l^2 + 64/3*l^4)*l/a^3 + 1)^(1/3))/a + 1/2]
However, by squaring the equation, we may have introduce spurious solutions ($a^2=b^2$ has ore solutions than $a=b$...). These solutions should therefore be checked before use ; my laziness leaves this as an exercise for the reader...
One can also get a solution via sympy
:
sage: bar=solve(Eq, x, algorithm="sympy")
However, this solution is a sympy
object (meaning that the"automatic" translation to sage
objects is not (yet) implemented) :
sage: type(bar)
<class 'sympy.sets.sets.Complement'>
This is the difference of two sets. The second is trivial:
sage: bar.args[1]
FiniteSet(1)
The first is a set :
sage: type(bar.args[0])
<class 'sympy.sets.sets.FiniteSet'>
sage: len(bar.args[0].args)
4
sage: [type(u) for u in bar.args[0].args]
Furthermore, each of these 4 solutins is a (value, condition)
pair :
[Piecewise, Piecewise, Piecewise, Piecewise]
Extracting the values of these solutions can be done by :
sage: [u.args[0][0]._sage_() for u in bar.args[0].args]
[-1/2*sqrt(2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 2/sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) - 2/3) - 1/2*sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) + 1/2,
1/2*sqrt(2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 2/sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) - 2/3) - 1/2*sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) + 1/2,
-1/2*sqrt(2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) + 2/sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) - 2/3) + 1/2*sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) + 1/2,
1/2*sqrt(2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) + 2/sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) - 2/3) + 1/2*sqrt(-2/3*(1/2)^(1/3)*(9*(a^2 - 4*l^2)/a^2 - 13)^(1/3) - 1/3) + 1/2]
Again, unscrewing and translating the conditions is left as an exercise to the reader.
"The competition" also gives us a set of 4 solutions :
sage: %time bar=mathematica.Solve(Eq,x)
CPU times: user 62 µs, sys: 4 ms, total: 4.06 ms
Wall time: 38.5 ms
sage: bar
{
{x -> 1/2 - Sqrt[-1/3 + (2*(a^4 - 12*a^2*l^2))/
(3*a^2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3)) +
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3))/(3*a^2)]/2 -
Sqrt[-2/3 - (2*(a^4 - 12*a^2*l^2))/
(3*a^2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3)) -
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3))/(3*a^2) -
2/Sqrt[-1/3 + (2*(a^4 - 12*a^2*l^2))/(3*a^2*
(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3)) +
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13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1/3)) -
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3))/(3*a^2) +
2/Sqrt[-1/3 + (2*(a^4 - 12*a^2*l^2))/(3*a^2*
(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3)) +
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3))/(3*a^2)]]/2},
{x -> 1/2 + Sqrt[-1/3 + (2*(a^4 - 12*a^2*l^2))/
(3*a^2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3)) +
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3))/(3*a^2)]/2 +
Sqrt[-2/3 - (2*(a^4 - 12*a^2*l^2))/
(3*a^2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3)) -
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3))/(3*a^2) +
2/Sqrt[-1/3 + (2*(a^4 - 12*a^2*l^2))/(3*a^2*
(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3)) +
(2*(a^6 + 9*a^4*l^2 + 3*Sqrt[3]*Sqrt[2*a^10*l^2 - 13*a^8*l^4 +
64*a^6*l^6])^(1/3))/(3*a^2)]]/2}}
This is not (yet) automatically transcriptible in Sage
, but can be manually translated :
sage: [{u[1][1].sage():u[1][2].sage()} for u in bar]
[{x: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/a^2 - 1/3) - 2/3*(a^4 - 12*a^2*l^2)/((a^6 + 9*a^4*l^2 + 3*sqrt(3)*sqrt(2*a^10*l^2 - 13*a^8*l^4 + 64*a^6*l^6))^(1/3)*a^2) - 2/3*(a^6 + 9*a^4*l^2 + 3*sqrt(3)*sqrt(2*a^10*l^2 - 13*a^8*l^4 + 64*a^6*l^6))^(1/3)/a^2 - 2/3) + 1/2*sqrt(2/3*(a^4 - 12*a^2*l^2)/((a^6 + 9*a^4*l^2 + 3*sqrt(3)*sqrt(2*a^10*l^2 - 13*a^8*l^4 + 64*a^6*l^6))^(1/3)*a^2) + 2/3*(a^6 + 9*a^4*l^2 + 3*sqrt(3)*sqrt(2*a^10*l^2 - 13*a^8*l^4 + 64*a^6*l^6))^(1/3)/a^2 - 1/3) + 1/2}]
Of course, checking that those solutions are equivalent is left as an exercise to the reader...