Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Defining new operators with specific rules

I would like to define new derivative operators dd1 and dd2. They should follow the following rules (dd being either dd1 or dd2 - They follow the same rules.):

dd(a+b)=dd(a)+dd(b);
dd(a*b)=b*dd(a)+a*dd(b);
dd(-a)=-dd(a);
dd(1/a)=-1/a^2*dd(a);
dd(c)=0;
dd(c*a)=c*dd(a);
dd(a**c)=c*a**(c-1)*dd(a);

where c is a symbolic variable or a number of any kind and, a and b are scalar field functions on a manifold.

If the code is something like the following:

# First operator
def dd1(x):
    ...

# Second operator
def dd2(x):
    ...

Man = Manifold(4, 'Man', r'\mathcal{Man}')
CO.<t,r,th,ph> = Man.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
a=Man.scalar_field(function('a')(*CO))
b=Man.scalar_field(function('b')(*CO))
c=var('c')

Then, it should produce these sample outputs for the following inputs:

Input> dd1(a)
Outpt> dd1(a)

Input> dd1(dd2(a))
Outpt> dd1(dd2(a))

Input> dd2(a*b)
Outpt> b*dd2(a)+a*dd2(b)

Input> dd1(c*a)
Outpt> c*dd1(a)

Input> dd2(dd1(c*a))
Outpt> c*dd2(dd1(a))

Input> dd1(-a)
Outpt> -dd1(a)

Input> dd2(c)
Outpt> 0

Input> dd1(7)
Outpt> 0