Skip to content

Translate maxima's if() function to Sage's cases() #13773

@vbraun

Description

@vbraun

As reported in https://groups.google.com/d/topic/sage-support/gNPCG3Zbfjg/discussion

sage: var('r theta psi x y z') 
(r, theta, psi, x, y, z)
sage: (r,theta,psi,x,y,z) 
(r, theta, psi, x, y, z)
sage: e1 = r == +sqrt(x^2+y^2+z^2) 
sage: e2 = theta == arccos(z/sqrt(x^2+y^2+z^2)) 
sage: e3 = psi == arctan(y/x) 
sage: solve([e1,e2,e3],x,y,z) 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/vbraun/opt/sage-5.5.rc0/devel/sage-main/<ipython console> in <module>()

/home/vbraun/opt/sage-5.5.rc0/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in solve(f, *args, **kwds)
    751             s = []
    752 
--> 753     sol_list = string_to_list_of_solutions(repr(s))
    754 
    755     # Relaxed form suggested by Mike Hansen (#8553):

/home/vbraun/opt/sage-5.5.rc0/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in string_to_list_of_solutions(s)
    455     from sage.structure.sequence import Sequence
    456     from sage.calculus.calculus import symbolic_expression_from_maxima_string
--> 457     v = symbolic_expression_from_maxima_string(s, equals_sub=True)
    458     return Sequence(v, universe=Objects(), cr_str=True)
    459 

/home/vbraun/opt/sage-5.5.rc0/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in symbolic_expression_from_maxima_string(x, equals_sub, maxima)
   1789         return symbolic_expression_from_string(s, syms, accept_sequence=True)
   1790     except SyntaxError:
-> 1791         raise TypeError, "unable to make sense of Maxima expression '%s' in Sage"%s
   1792     finally:
   1793         is_simplified = False

TypeError: unable to make sense of Maxima expression '[If(and(-pi/2<parg(-r),-pi/2<parg(r),parg(-r)<==pi/2,parg(r)<==pi/2,-r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))!=0,sqrt(r^2*(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))+r^2*cos(theta)^2+tan(psi)^2*r^2*(1-cos(theta))*(cos(theta)+1)/(tan(psi)^2+1))!=0),[x==-r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1)),y==-tan(psi)*r*sqrt(1-cos(theta))*sqrt(cos(theta)+1)/sqrt(tan(psi)^2+1),z==-r*cos(theta)],union()),If(and(-pi/2<parg(-r),-pi/2<parg(r),parg(-r)<==pi/2,parg(r)<==pi/2,r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))!=0,sqrt(r^2*(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))+r^2*cos(theta)^2+tan(psi)^2*r^2*(1-cos(theta))*(cos(theta)+1)/(tan(psi)^2+1))!=0),[x==r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1)),y==tan(psi)*r*sqrt(1-cos(theta))*sqrt(cos(theta)+1)/sqrt(tan(psi)^2+1),z==-r*cos(theta)],union()),If(and(-pi/2<parg(r),parg(r)<==pi/2,-r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))!=0,sqrt(r^2*(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))+r^2*cos(theta)^2+tan(psi)^2*r^2*(1-cos(theta))*(cos(theta)+1)/(tan(psi)^2+1))!=0),[x==-r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1)),y==-tan(psi)*r*sqrt(1-cos(theta))*sqrt(cos(theta)+1)/sqrt(tan(psi)^2+1),z==r*cos(theta)],union()),If(and(-pi/2<parg(r),parg(r)<==pi/2,r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))!=0,sqrt(r^2*(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1))+r^2*cos(theta)^2+tan(psi)^2*r^2*(1-cos(theta))*(cos(theta)+1)/(tan(psi)^2+1))!=0),[x==r*sqrt(1/(tan(psi)^2+1)-cos(theta)^2/(tan(psi)^2+1)),y==tan(psi)*r*sqrt(1-cos(theta))*sqrt(cos(theta)+1)/sqrt(tan(psi)^2+1),z==r*cos(theta)],union())]' in Sage

See also https://groups.google.com/forum/?hl=en#!topic/sage-devel/3JhTyHooxQw

CC: @mforets

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/13773

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions