Ask Your Question

Substituting derivatives in Taylor expansions

asked 2015-11-09 14:48:26 +0200

bekalph gravatar image

Within Taylor expansions, as well as in results of 'Derivative'- operations, derivatives are marked by symbol "D[ ]" . I want to substitute them by other symbolic expressions/functions in order to get the usual presentation of derivative symbols via Latex. The following testprogram demonstrates that derivatives triggered by the "derivative"-operation can indeed be substituted by user-defined symbols, but not derivatives in Taylor expansions.

print 'a3(x):',a3(x)
print 'da3:', da3
print '### After a "derivative"-operation, substituting dt1 by dTedx works:'
print 'da4:',da4
print 'Taylor series ata:',ata
print '### After Taylor expansion, substituting dt2 by dTedx does not work:'
print 'Taylor series atb:',atb

I run this program within In a SAGE6.8 notebook-session. The output is:

dt1: D[0](T_e)(x)
dt2: D[0](T_e)(x_0)
a3(x): a_5*T_e(x) + a_4

After a "derivative"-operation, substituting dt1 by dTedx works:

da3: a_5*D[0](T_e)(x)
da4: a_5*dTedx

After Taylor expansion, substituting dt2 by dTedx does not work:

Taylor series ata: a_5*(x - x_0)*D[0](T_e)(x_0) + a_5*T_e(x_0) + a_4
Taylor series atb: a_5*(x - x_0)*D[0](T_e)(x_0) + a_5*T_e(x_0) + a_4

What is the reason for this difference? Maybe, I merely must access the derivative expression within a Taylor expansion in a different way. Thus: which is the correct way to do this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-11-09 18:36:03 +0200

nbruin gravatar image

updated 2015-11-09 22:30:56 +0200

Don't use the "nargs" argument in the function declaration. It doesn't do anything beyond confusing the Pynac <-> maxima symbol translator. The fact that it confuses the translator is a bug, but given that the "nargs" argument is a no-op in any other respect, the fix for the bug is probably removing the "nargs" argument anyway.

For posterity, the code below helped me diagnose the problem (in hindsight I did see this problem before and it's pretty fundamental: from maxima, one cannot see if T_e is supposed to have an "nargs" attribute).

sage: XX=T_e(x_0).derivative(x_0)
sage: YY=(ata.operands()[0].operands()[2]) #you may need different indices
sage: XX, YY
(D[0](T_e)(x_0), D[0](T_e)(x_0))
sage: bool(XX==YY) #this works because everything gets round-tripped to maxima
sage: hash(XX)==hash(YY) #but this indicates something is amiss
sage: XX.operator().function(), YY.operator().function()
(T_e, T_e)
sage: XX.operator().function()==YY.operator().function()

As you can see the T_e in the taylor expands isn't really the same T_e that you defined before. Simply testing equality of expressions doesn't seem to detect this, probably because the advanced equality tests involved: they would send things over to Maxima to do some simplifications and the translations used there would probably be oblivious to the differing internal representation of XX and YY.

With YY instead of XX, things seem to work:

sage: ata.subs(YY==dTedx)
a_5*dTedx*(x - x_0) + a_5*T_e(x_0) + a_4

See for a ticket about the underlying bug.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-11-09 14:48:26 +0200

Seen: 427 times

Last updated: Nov 09 '15