In [1]:
from sympy import init_printing, latex
init_printing()
import sympy as sp
In [2]:
u,v = sp.symbols('u,v',positive = True)

Exploring inverse functions. If a function maps a domain to a range, then the inverse of that function maps the range back to the domain. $f(x) = y \Leftrightarrow g(y) = x$

These functions pass the test.

In [8]:
class S0(sp.Function):
    
    @classmethod
    def eval(cls, x):
        if x.is_Number:
            if x.is_zero:
                return sp.S.One
            elif x is sp.S.One:
                return sp.S.Zero
        if isinstance(x, S0_inv):
            return x.args[0]
class S0_inv(sp.Function):
    
    @classmethod
    def eval(cls, x):
        if isinstance(x,S0):
            return x.args[0]

S0(0)
S0(S0_inv(0))
Out[8]:
$\displaystyle 0$

An interesting example of defining a custom class to implement the differential operator D. https://stackoverflow.com/questions/15463412/differential-operator-usable-in-matrix-form-in-python-module-sympy