Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vbraun opened this issue Nov 28, 2012 · 4 comments
Open

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

vbraun opened this issue Nov 28, 2012 · 4 comments

Comments

@vbraun
Copy link
Member

vbraun commented Nov 28, 2012

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

@vbraun vbraun added this to the sage-5.11 milestone Nov 28, 2012
@kcrisman
Copy link
Member

comment:1

Just for the record, it's objecting to the "if". The "in Sage" is just what we append. Also, the "union" in the spot they're in will not get properly parsed, though we do handle that in certain easy circumstances. I feel like we may already have a ticket for this, even, but it's not going to be easy to fix unless we bring in our own "if", and I don't know that we want to do that.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@rwst
Copy link
Contributor

rwst commented Jul 29, 2015

comment:6

Related to #16653, i.e. maybe output a list of pairs (condition, result).

@rwst

This comment has been minimized.

@rwst rwst modified the milestones: sage-6.4, sage-8.2 Oct 10, 2017
@rwst rwst changed the title maxima solve output parser insufficient Translate maxima's if() function to Sage's cases() Oct 10, 2017
@kcrisman
Copy link
Member

kcrisman commented Mar 5, 2018

comment:9

Another example at #24800:

var('r2 si co r12 r22 r32 d32')
eq1 = r12==r2*d32*(1-si*(co+sqrt(3*(1-co*co)))/2)/2
eq2 = r22==r2*d32*(1-si*(co-sqrt(3*(1-co*co)))/2)/2
eq3 = r32==r2*d32*(1+si*co)/2
solve([eq1,eq2,eq3],r2,si,co)

HT to rws for noticing that was a dup.

@mkoeppe mkoeppe removed this from the sage-8.2 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants