On Feb 20, 2012, at 9:05 AM, ancienthart wrote:

> Guys, is there a method or function to flip an equation or inequality?
> 
> I'd like to turn 2*x + 3*y < 8 into 8 > 2*x + 3*y automatically.
> 
> Joal Heagney

If you just mean to reverse the order in which it is printed without changing 
the mathematical meaning then the function below should work (at least for 
simple cases).  If you want to actually reverse the meaning then it's actually 
easier since you can just use orig_op.

-Ivan

def reverse_inequality(eq):
    """
    Reverse the order of the inequality without changing it's meaning.
    """
    orig_op = eq.operator() # The "top-level" operator
    if orig_op == operator.lt:
        op = operator.gt
    elif orig_op == operator.le:
        op = operator.ge
    elif orig_op == operator.gt:
        op = operator.lt
    elif orig_op == operator.ge:
        op = operator.le
    elif orig_op == operator.eq:
        op = operator.eq
    elif orig_op == operator.ne:
        op = operator.ne
    else:
        raise TypeError, "this expression must be a relation"
   return op(eq.rhs(), eq.lhs())


-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to