Alternative to changing the __add__ of Integers class (need 0Z+x=x, x belonging to custom class)
I have a class called phi defined on certain ring R, which morally should be Z-valued, ϕ:R→Z. From that I need only that adding 0Z to the phi-elements does nothing, and the next (pseudocode) works for adding 0 by the right to the phi elements:
class phi: ...
...
def __add__(self, other):
if other == 0:
return self
How can I define the addition to be trivial if the left argument is 0Z and the right in the phi class without changing the __add__ of the Integer class? (Or a workaround. Actually my target is not the integers but the sage symbolic ring, SR.)
You might want to have a look at the following entries in sagemath documentation
Thanks, I'm taking a look.