Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you only care about numerical values, you can use %:

sage: float(7.7) % float(2.2)
1.0999999999999996
sage: 7.7 % 2.2
1.10000000000000

but these won't work for symbolic expressions, unless you play subclassing games:

class ModExp(Expression):
    def __init__(self, value):
        Expression.__init__(self, SR, value)
    def __mod__(self, other):
        return self-floor(self/other)*other

sage: pi = ModExp(pi)
sage: pi % (pi*3/4)
1/4*pi
sage: pi.mod(pi*3/4)
1/4*pi

If you only care about numerical values, you can use %:

sage: float(7.7) % float(2.2)
1.0999999999999996
sage: 7.7 % 2.2
1.10000000000000

but these won't work for symbolic expressions, unless you play subclassing games:

class ModExp(Expression):
    def __init__(self, value):
        Expression.__init__(self, SR, value)
    def __mod__(self, other):
        return self-floor(self/other)*other
    def mod(self, other):
        return self.__mod__(other)

sage: pi = ModExp(pi)
sage: pi % (pi*3/4)
1/4*pi
sage: pi.mod(pi*3/4)
1/4*pi