On Thu, Jul 21, 2011 at 3:37 AM, Burcin Erocal <[email protected]> wrote: > Hi, > > On Wed, 20 Jul 2011 17:02:49 -0700 (PDT) > Steven Pollack <[email protected]> wrote: > >> I noticed that a thread was developed for this sort of thing (http:// >> groups.google.com/group/sage-support/browse_thread/thread/ >> d50dc3bc2bdbeab0/34798c0585fc034f?lnk=gst&q=nicolas&fwc=1#), but I'm a >> newbie, and a lot of it went over my head. >> >> Is there a simple to create a subclass of >> sage.symbolic.expression.Expression?
Note that many of the low-level classes, such as Integers and perhaps Expressions, were not designed with sublcassing in mind. YMMV, but this is often a problem of OOP in general. > The main problem with subclassing Expression is that the result > returned from arithmetic is hardcoded to be an Expression again. > > I quickly did a search and replace in the sage/symbolics directory to > pass the new class as an argument to the fast expression constructor > new_Expression_from_GEx. Here is the patch: > > http://sage.math.washington.edu/home/burcin/subclass_expression.patch > > After applying the patch the following works: > > sage: class new_exp(Expression): > ....: pass > ....: > sage: t = new_exp(SR, x) > sage: t > x > sage: type(t) > <class '__main__.new_exp'> > sage: u = t*t > sage: type(u) > <class '__main__.new_exp'> > sage: u > x^2 Any performance cost? - Robert -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
