ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 11 May 2011 06:35:18 -0500Making my own special type of variablehttp://ask.sagemath.org/question/8109/making-my-own-special-type-of-variable/I want to create an object that I can take formal products and sums of, and also that remembers some extra data. I'd like to use sage's symbolic tools to do it without reimplementing multiplication, etc. For example, I'd like to make a class `myVar` that behaves something like this:
sage: a = myVar("some data about a")
sage: b = myVar("other important stuff")
sage: p = ((a + b)^2).expand()
a^2 + 2*a*b + b^2
sage: p.operands()
[a^2, 2a*b, b^2]
sage: p.operands()[0].operands[0]
a
sage: p.operands()[0].operands[0].get_data()
"some data about a"
I've tried subclassing Expression, but it seems like whenever I try to do some sums or products it just turns my thing into an Expression and forgets that it was a myVar.
Is something like this possible in sage?paragonWed, 11 May 2011 06:35:18 -0500http://ask.sagemath.org/question/8109/