Question

I have some function which returns inequalies for example

s= solve(x^(2)<4,x) 
s
[[x>-2, 2<x]]

I would like to be able to convert this into a string "]-2,2[" to export into LaTeX.

How would I be able to check which comparison operator is used and then make a multiple case scenator based on that? For example

 if s[1].operatorused== "<" 
  then do stuff
 if s[1].operatorused== "<=" 
  then do stuff

and so on.

Was it helpful?

Solution

You can access the operator via .operator() and do your comparisons that way:

sage: s[0][0].operator()
<function operator.gt>
sage: s[0][1].operator()
<function operator.lt>
sage: s[0][0].operator() == operator.gt
True
sage: s[0][0].operator() == operator.lt
False

To be honest I've fallen back on doing string comparisons in the past when it seemed more convenient (although you have to remember to make sure that > doesn't trip before >=.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top