Ask Your Question
0

In SageMath 9.2 :"TypeError: unable to make sense of Maxima expression" .What does it mean ?

asked 2022-10-11 11:50:25 +0100

Periodic_1_6 gravatar image

updated 2023-01-09 23:59:56 +0100

tmonteil gravatar image

is there anyone who would help me with the output of this system?

import time
Start_Time = time.time()

var('N n k x h y X Y m K H s')


eq0 = N-187 == 0

eq1 = (-4-n^2+9*N+24*k*N-16*x-16*x^2+4*(h+2*h*x)^2+n*(2-4*y))/8 == 0
eq2 = -4*sqrt(-(N*(9+24*k)-3)/48) - h == 0
eq3 = (4*x+2)^2-(2*y-1)^2-N*(9+24*k) == 0

eq4 = x+h/4 == 0
eq5 = h^2-1-n == 0


eq6 = (-4-m^2+9*N+24*K*N-16*X-16*X^2+4*(H+2*H*X)^2+m*(2-4*Y))/8 == 0
eq7 = -4*sqrt(-(N*(9+24*K)-3)/48) - H == 0
eq8 = (4*X+2)^2-(2*Y-1)^2-N*(9+24*K) == 0

eq9 = X+H/4 == 0
eq10 = H^2-1-m == 0

eq11 = k+2*sqrt(-374*k-140)-374-K == 0



eq13 = (k-K)/2-(187-2*s) == 0

eq14 = 187*(9+24*k)-3+48*s^2 == 0



solutions = solve([eq0,eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq13,eq14],N,n,k,x,h,y,X,Y,m,K,H,s)
sol = solutions 
print(sol)
Execution_Time = time.time() - Start_Time
print (Execution_Time)
edit retag flag offensive close merge delete

Comments

A minimal command raising the same error seems to be:

sage: var('n k x h y')
sage: eq1 = (-4-n^2+9*187+24*k*187-16*x-16*x^2+4*(h+2*h*x)^2+n*(2-4*y))/8 == 0
sage: eq2 = -4*sqrt(-(187*(9+24*k)-3)/48) - h == 0
sage: eq4 = x+h/4 == 0
sage: solutions = solve([eq1,eq2,eq4],n,k,x,h,y)
Sébastien gravatar imageSébastien ( 2022-10-11 15:48:52 +0100 )edit

I created https://trac.sagemath.org/ticket/34659 for the simplified issue.

Sébastien gravatar imageSébastien ( 2022-10-14 08:57:32 +0100 )edit

Added confirmed_bugtag, see https://ask.sagemath.org/questions/sc...

tmonteil gravatar imagetmonteil ( 2022-10-14 11:28:28 +0100 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2022-10-11 16:04:58 +0100

Sébastien gravatar image

In the error traceback, it says there is a syntax error saying "Mismatched parentheses" when sage tries to parse the answer from Maxima.

For example, the simplified command:

sage: var('n k x h y')
sage: eq1 = (-4-n^2+9*187+24*k*187-16*x-16*x^2+4*(h+2*h*x)^2+n*(2-4*y))/8 == 0
sage: eq2 = -4*sqrt(-(187*(9+24*k)-3)/48) - h == 0
sage: eq4 = x+h/4 == 0
sage: solutions = solve([eq1,eq2,eq4],n,k,x,h,y)

outputs:

...
SyntaxError: Mismatched parentheses
...
TypeError: unable to make sense of Maxima expression '[if((-pi/2 < parg(c3812)) and (parg(c3812) <== pi/2),[_SAGE_VAR_h == -4*c3812,_SAGE_VAR_k == ((-2*c3812^2)-70)/187,_SAGE_VAR_n == 2*sqrt(c3814^2-c3814+64*c3812^4+64*c3812^3-4*c3812)-2*c3814+1,_SAGE_VAR_x == c3812,_SAGE_VAR_y == c3814],union()),if((-pi/2 < parg(c3815)) and (parg(c3815) <== pi/2),[_SAGE_VAR_h == -4*c3815,_SAGE_VAR_k == ((-2*c3815^2)-70)/187,_SAGE_VAR_n == (-2*sqrt(c3816^2-c3816+64*c3815^4+64*c3815^3-4*c3815))-2*c3816+1,_SAGE_VAR_x == c3815,_SAGE_VAR_y == c3816],union()),[_SAGE_VAR_h == -1,_SAGE_VAR_k == -3/8,_SAGE_VAR_n == (-2*sqrt(c3813^2-c3813+1/4))-2*c3813+1,_SAGE_VAR_x == 1/4,_SAGE_VAR_y == c3813],[_SAGE_VAR_h == -1,_SAGE_VAR_k == -3/8,_SAGE_VAR_n == 2*sqrt(c3819^2-c3819+1/4)-2*c3819+1,_SAGE_VAR_x == 1/4,_SAGE_VAR_y == c3819]]' in Sage

After editing the output result from Maxima, I don't see the "mismatches parenthesis", can you? :

[if((-pi/2 < parg(c3812)) and (parg(c3812) <== pi/2),
 [_SAGE_VAR_h == -4*c3812,
  _SAGE_VAR_k == ((-2*c3812^2)-70)/187,
  _SAGE_VAR_n == 2*sqrt(c3814^2-c3814+64*c3812^4+64*c3812^3-4*c3812)-2*c3814+1,
  _SAGE_VAR_x == c3812,
  _SAGE_VAR_y == c3814],
  union()),
 if((-pi/2 < parg(c3815)) and (parg(c3815) <== pi/2),
 [_SAGE_VAR_h == -4*c3815,
  _SAGE_VAR_k == ((-2*c3815^2)-70)/187,
  _SAGE_VAR_n == (-2*sqrt(c3816^2-c3816+64*c3815^4+64*c3815^3-4*c3815))-2*c3816+1,
  _SAGE_VAR_x == c3815,
  _SAGE_VAR_y == c3816],
  union()),
 [_SAGE_VAR_h == -1,
  _SAGE_VAR_k == -3/8,
  _SAGE_VAR_n == (-2*sqrt(c3813^2-c3813+1/4))-2*c3813+1,
  _SAGE_VAR_x == 1/4,
  _SAGE_VAR_y == c3813],
 [_SAGE_VAR_h == -1,
  _SAGE_VAR_k == -3/8,
  _SAGE_VAR_n == 2*sqrt(c3819^2-c3819+1/4)-2*c3819+1,
  _SAGE_VAR_x == 1/4,
  _SAGE_VAR_y == c3819]
]

If there are no mismatches parenthesis, it means sage needs to improve the way it parses the maxima output.

edit flag offensive delete link more

Comments

thank you !

Periodic_1_6 gravatar imagePeriodic_1_6 ( 2022-10-11 17:05:35 +0100 )edit
0

answered 2022-10-11 16:32:55 +0100

Emmanuel Charpentier gravatar image

updated 2022-10-11 16:37:14 +0100

Aaah ! A nice one...

Trying to solve :

Sol = solve(Sys, SVars)

Long error message : elided, seemingly false,... but another error message during the processing of the first :

TypeError: unable to make sense of Maxima expression '[if((-pi/2 < parg(374-2*c498417)) and (-pi/2 < parg(c498417-187)) and (-pi/2 < parg(c498417)) and (parg(374-2*c498417) <== pi/2) and (parg(c498417-187) <== pi/2) and (parg(c498417) <== pi/2),[_SAGE_VAR_H == -4*c498417,_SAGE_VAR_K == ((-2*c498417^2)-70)/187,_

... much elided again.

It seems that Maxima, duly piloted by Sage, is able to find a solution, but Sage is unable to translate it. The error message seems to point to the test of the argument of a quantity (possibly checking for the sign of a radicand).

This second error may indicate that the firs one has been derailed, hence a dubious meaning...

Further attempts with Mathematica (or the gratis Wolfram Engine, used through emacs' wolfram-mode) point to the same direction.

Your system has three equations involving square roots. We can try to eliminate those radicals, by replacing the equations by other ones whise roots are a superset of the original ones.

It happens that sympy has a nice tool for this : from sympy.solvers.solvers.unrad? :

   Remove radicals with symbolic arguments and return (eq, cov), None,
   or raise an error.

   None is returned if there are no radicals to remove.

   NotImplementedError is raised if there are radicals and they cannot
   be removed or if the relationship between the original symbols and
   the change of variable needed to rewrite the system as a polynomial
   cannot be solved.

   Otherwise the tuple, "(eq, cov)", is returned where:

   *eq*, "cov"
      *eq* is an equation without radicals (in the symbol(s) of
      interest) whose solutions are a superset of the solutions to the
      original expression. *eq* might be rewritten in terms of a new
      variable; the relationship to the original variables is given by
      "cov" which is a list containing "v" and "v**p - b" where "p" is
      the power needed to clear the radical and "b" is the radical now
      expressed as a polynomial in the symbols of interest. For
      example, for sqrt(2 - x) the tuple would be "(c, c**2 - 2 + x)".
      The solutions of *eq* will contain solutions to the original
      equation (if there are any).

[ Details elided but capital ! ]

So, let's build a system whose roots are a superset of the original ones :

import sympy
USys=[u[1][0]._sage_() if u[1] is not None else u[0]
         for u in list(zip(Sys,
                                map(lambda u:sympy.solvers.solvers.unrad(sympy.sympify(u)), Sys)))]

Use it to get a list of candidate solutions :

sage: %time USol=solve(USys, SVars)
CPU times: user 1.81 s, sys: 16 ms, total: 1.83 s
Wall time: 1.45 s

and keep the solutions that check the original system :

CUSol=[s for s in USol if all([bool(e.subs(s).simplify_full()) for e in Sys])]
sage: len(CUSol)
5

But all these solutions are not distinct :

sage: len(list(Set(set(u) for u in CUSol)))
4

FWIW :

  • Mathematica's Solve proposes these 4 solutions, but from a direct interface ; Sage's interface gets derailed by Mathematica's warning message, interpreted by the interface as an error message.

  • Mathematica's Reduce points at possible other solutions, which I have not (yet) checked.

Morality : equations system solving is not (yet) automatic. Sage and consorts may (seriously) compute for you, but won't think for you.

HTH,

edit flag offensive delete link more

Comments

sorry! thank you

Periodic_1_6 gravatar imagePeriodic_1_6 ( 2022-10-11 17:04:26 +0100 )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

Stats

Asked: 2022-10-11 11:50:25 +0100

Seen: 388 times

Last updated: Oct 11 '22