Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Human-readable form of operator() of an expression?

Consider the code below

sage: x,y=var('x y')                                                            
sage: (x+y).operator()                                                          
<function add_vararg at 0x7f9d56dbd430>

The output in the last line is a bit lengthy, and makes it hard for me to automatically test what kind of expression I have (e.g. determining if the expression is a sum or a product of operands). I would like to write code like this

if someExpression.operator() == plus:
    print("this is a sum")
elif someExpression.operator() == multiply:
    print("this is a product")
else:
    print("this is something else")

How should I modify the if-else loop above to make it actually work?

Human-readable form of operator() of an expression?

Consider the code below

sage: x,y=var('x y')                                                            
sage: (x+y).operator()                                                          
<function add_vararg at 0x7f9d56dbd430>

The output in the last line is a bit lengthy, and makes it hard for me to automatically test what kind of expression I have (e.g. determining if the expression is a sum or a product of operands). I would like to write code like this

if someExpression.operator() == plus:
    print("this is a sum")
elif someExpression.operator() == multiply:
    print("this is a product")
else:
    print("this is something else")

How should I modify the if-else loop statement above to make it actually work?