On Tue, 26 Jul 2011 00:03:41 -0700 Robert Bradshaw <rober...@math.washington.edu> wrote:
> On Thu, Jul 21, 2011 at 3:37 AM, Burcin Erocal <bur...@erocal.org> > wrote: > > > 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? Without the patch: sage: %timeit v = [-pi,-pi+1/100000..,pi] 5 loops, best of 3: 1.4 s per loop With the patch: sage: %timeit v = [-pi,-pi+1/100000..,pi] 5 loops, best of 3: 1.62 s per loop Cheers, Burcin -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org