Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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
True
sage: hash(XX)==hash(YY) #but this indicates something is amiss
False
sage: XX.operator().function(), YY.operator().function()
(T_e, T_e)
sage: XX.operator().function()==YY.operator().function()
False

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

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
True
sage: hash(XX)==hash(YY) #but this indicates something is amiss
False
sage: XX.operator().function(), YY.operator().function()
(T_e, T_e)
sage: XX.operator().function()==YY.operator().function()
False

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 http://trac.sagemath.org/ticket/14608 for a ticket about the underlying bug.