Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can't solve your problem by subclassing Expression, this requires you to assign data to every expression. Whats the data associated to the Expression a+b?

Since you only want to associate something to variables, you can just use a dictionary:

sage: var('a, b')
(a, b)
mydata = { a:'foo', b:'bar' }
sage: p = ((a + b)^2).expand()
a^2 + 2*a*b + b^2
sage: p.operands()[0].operands()[0]
a
sage: mydata[_]
'foo'