# Multivariable taylor series with relationship between variables

Let's consider a function f(x,y,z) and the following relationship between the variables:

f(x,y,z) = x+y+z
x << y << z     around 0


I would like the first order Taylor expansion of f around 0. And I would expect this result:

>> taylor(f, (x,0),(y,0),(z,0),1)
z


But I have :

>> taylor(f, (x,0),(y,0),(z,0),1)
x+y+z


How can I do it?

edit retag close merge delete

Sort by » oldest newest most voted

I have found a way to do it and I'll share the code here in case someone else wants to do it.

Hope it helps someone else.

def TaylorOrdered(func, vartup, order):
if (not isinstance(vartup,tuple)) or \
((not isinstance(vartup,tuple)) and (len(vartup)!=3)) or \
((isinstance(vartup,tuple)) and (len(vartup)!=3)):
show(vartup)
print( (not isinstance(vartup,tuple), not isinstance(vartup,tuple), len(vartup)!=3) )
raise NotImplementedError, "The second argument should be a tuple of 3-items tuples"
powrel = {}
taylist = []
if not isinstance(vartup,tuple):
powrel[vartup] = Integer(vartup)
taylist.append( (vartup, vartup) )
else:
for i in range(len(vartup)):
powrel[vartup[i]] = Integer(vartup[i])
taylist.append( (vartup[i], vartup[i]) )
taylist.append(order+1)
taytup = tuple(taylist)
# the added 1 solves the problem of single terms with iterator (numerator and denominator instead of monomials)
DLtmp = 1+(func.taylor(*taytup).expand())
if DLtmp.is_symbol() or DLtmp.is_constant() or DLtmp.is_numeric():
vo = DLtmp;
else:
vo = func*0
for t in DLtmp.iterator():
deg_t = 0
for v in func.variables():
if v in powrel.keys():
deg_t += powrel[v]*t.degree(v)
if  deg_t <= order :
vo += t;
vo = vo.expand()-1;
return vo


This is the description of the input:

TaylorOrdered(Func, (Var, Point, Rel), Order) # for monovariables
TaylorOrdered(Func, ( (Var1, Point1, Rel1), (Var2, Point2, Rel2), ...), Order) # for multivariables


Here are some examples:

show(TaylorOrdered(sqrt(1+X)+sqrt(1+Y)/h, (X,0,1), 2))
show(TaylorOrdered(sqrt(1+X)+sqrt(1+Y)/h, ((X,0,1),(h,Infinity,-1)), 2))

more