Ask Your Question

Weird c-values from solving system of equations

asked 2021-09-16 14:52:20 +0200

arneovi gravatar image

updated 2021-09-17 11:31:44 +0200

FrédéricC gravatar image

Here is the issue:

sage: a_1, a_2, b_1, b_2 = var('a_1 a_2 b_1 b_2')                               
sage: eq1 = a_1 * a_2^2 - a_2 * a_1^3 == 0                                      
sage: eq2 = 2*a_1*a_2*b_2 + b_2*a_2^2 - 3*a_2*a_1^2*b_1 - a_1*b_2               
sage: eq3 = a_2^3 - a_2^2*a_1^2                                                 
sage: eq4 = 3*a_2^2*b_2 - 2*a_2*a_1^2*b_2 - 2*a_2^2*b_1                         
sage: solve([eq1, eq2, eq3, eq4], a_1, a_2, b_1, b_2)                           
[[a_1 == 0, a_2 == 0, b_1 == c2439, b_2 == c2440], [a_1 == c2441, a_2 == 0, b_1 == c2442, b_2 == 0], [a_1 == c2443, a_2 == c2443^2, b_1 == 0, b_2 == 0]]

im getting these weird c2439 and c2440 solutions, are they just arbitrary complex numbers? Shouldn't they rather be prefixed with 'r' in that case? Can anyone tell me what these c-values are?

edit retag flag offensive close merge delete


Maxima can't solve this system (checked in Maxima itself) :

sage: maxima_calculus.solve(maxima_calculus(Sys),maxima_calculus(Unk))
RuntimeError                              Traceback (most recent call last)

[ Snip...]

TypeError: ECL says: Error executing code in Maxima: algsys: system too complicated; give up.

Sympy gives a bizarre (and incompletely solved) answer ; Giac's result can't be backtranslated to Sage. The result you got may well come from Fricas :

sage: solve(Sys, Unk, algorithm="fricas")
[[a_1 == 0, a_2 == 0, b_1 == c10757, b_2 == c10758], [a_1 == c10759, a_2 == 0, b_1 == c10760, b_2 == 0], [a_1 == c10761, a_2 == c10761^2, b_1 == 0, b_2 == 0]]

Do you have Fricas installed ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-09-17 10:53:17 +0200 )edit

Hello, @Emmanuel Charpentier! I deleted my previous comment that indicated that I couldn't reproduce the error message you obtained. The problem was that I accidentally solved the system with Sage's solve() function directly instead of using Maxima.

This made me wonder why Sage returns an answer when asked to solve with the algorithm='maxima' option instead of an error, so I took a look at the code. As it turns out, Sage's solve() function first tries to use Maxima's solve, and if that fails, it tries with to_poly_solve. Indeed, the following Maxima code should return the same solutions as Sage:

to_poly_solve(Sys, Unk);

In Sage you can write

m = maxima(Sys)

or the shorter version

maxima.to_poly_solve([Sys, Unk])
dsejas gravatar imagedsejas ( 2021-09-19 04:00:47 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-09-17 20:56:38 +0200

dsejas gravatar image

updated 2021-09-26 05:07:35 +0200

Hello, @arneovi! The variables of the form cN, where N is a natural number, are parameters. For example, one of the solutions you obtained is

[a_1 == 0, a_2 == 0, b_1 == c2439, b_2 == c2440]

This can be rewritten as $a_1=0$, $a_2=0$, $b_1=s$ and $b_2=t$, where $s,t\in\mathbb{R}$. On the other hand, one of the other solutions you obtained is

[a_1 == c2443, a_2 == c2443^2, b_1 == 0, b_2 == 0]

In this case, you should notice that, unlike the previous example, the two occurrences of the variables of the from cN is the same one. Therefore, this can be rewritten as $a_1=t$, $a_2=t^2$, $b_1=0$ and $b_2=0$.

That should answer your question. However, I should also point out a potential problem that you might or might not find when using solve(). The solve() function accepts an algorithm parameter, which can take the values maxima (the default), sympy, giac and fricas. This indicates the Computer Algebra System that you want to use to solve the equation(s). In the case of maxima, giac and fricas, I obtained exactly the same results as you; however, sympy caused me some trouble. Indeed, when calling

solve([eq1, eq2, eq3, eq4], a_1, a_2, b_1, b_2, algorithm='sympy')

I obtained some results tat are consistent with the ones you obtained. For example, here is part of the output for this case:

[{a_1: 0, a_2: 0},
 {a_1: 0, a_2: 0},
 {a_2: 0, a_1: 0},
 {a_2: 0, b_2: 0},

On the other hand, Sympy also gave me this result:

{a_1: -1/6*2^(5/6)*sqrt(3*2^(2/3)*(3*I*sqrt(303) + 1499)^(1/3) + 48*2^(1/3) + 624/(3*I*sqrt(303) + 1499)^(1/3)),
 b_1: 1/2*b_2,
 a_2: 1/3*2^(1/3)*(3*I*sqrt(303) + 1499)^(1/3) + 104/3*2^(2/3)/(3*I*sqrt(303) + 1499)^(1/3) + 16/3}

After replacing in the original equations, it would seem that the whole system is satisfied, except for eq2. (Here is a SageCell using this exact solution, just in case you feel curious. However, be warned: I had to use polynomial rings in order to obtain numerical approximations, because the mathematical expressions are too complicated for full_simplify().)

My suggestion: Although very useful, the solve() function not always gives the right and/or complete answer. It is always a good idea to check with different algorithms. Even better, if you can solve the system by hand in a reasonable amount of time and with a reasonable amount of effort, it is best to do it so.

I hope this helps!

edit flag offensive delete link more


A couple remarks :

  • The solution {a_1: 0, b_1: 1/2*b_2, a_2: 0}is a special case of {a_1: 0, a_2: 0}

  • Both Sympy and Mathematica add to the general solutions given by Maxima and Fricas a triplet of solutions (a1 being in the roots of a a quadrinomial) ;

    • Mathematica presents the quadrinomial (and the derivative solutions can be checked),

    • Sympy presents the (supposed) roots, which do not check (one of them is in Matjematica's quadrinomioal roots (and checks), the other two being opposite to the other two Mathematica's quadrinomial's roots (and do not check)).

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-09-21 16:14:29 +0200 )edit

Thank you! I thought maybe it was parameters but was confused since I thought the "r" variables were parameters, like for example r23? Is there any difference between r and c parameters? Real and complex numbers maybe? I tried solving these by hand but this is just part of a bigger calculation so in the next step i will need to introduce more equations and variables so I would like to avoid doing it by hand. But I will use this method with caution. Thank you again for your help and suggestions.

arneovi gravatar imagearneovi ( 2021-09-23 14:24:24 +0200 )edit

Hello, @Emmanuel Charpentier! Concerning the solution {a_1: 0, b_1: 1/2*b_2, a_2: 0} being a particular case of {a_1:0, a_2: 0}, you are totally right. I just edited the answer in kind. (Perhaps I should stop answering questions at 2 o'clock in the morning, because I make these types of mistakes, but it is the only available time I have.) Thank you for your comment!

dsejas gravatar imagedsejas ( 2021-09-26 05:11:53 +0200 )edit

Hello, @arneovi! In my daily use of Sage I didn't find any instance where the parameters are expressed in the form rN, where N is a positive integer. Therefore, I cannot help with your doubt about r variables. Perhaps you could post this as a different question in the forum, giving an appropriate example.

dsejas gravatar imagedsejas ( 2021-09-26 05:15:25 +0200 )edit

@dsejas I thought the r-variable is the standard parameter? Running this :

a_1, a_2, b_1, b_2 = var('a_1, a_2, b_1, b_2')
eq1 = a_2^2 - a_2*a_1^2 == 0
eq2 = a_2*b_2 - 2*a_1*a_2*b_1 + a_2*b_2 - a_1^2*b_1 == 0
solve([eq1, eq2], a_1, a_2, b_1, b_2)

i get: [[a_1 == 0, a_2 == 0, b_1 == r4, b_2 == r5], [a_1 == r6, a_2 == 0, b_1 == 0, b_2 == r7], [a_1 == r8, a_2 == r8^2, b_1 == r9, b_2 == 1/2(2r8 + 1)*r9]]

arneovi gravatar imagearneovi ( 2021-09-27 14:34:15 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-09-16 14:52:20 +0200

Seen: 241 times

Last updated: Sep 26 '21