What isn't clear is how expressions like

  2*x + 3*y + 4*z

get handled without creating intermediate classes.   Do the Add and
Mult classes combine subexpressions together within the __new__
method?

On Sep 10, 5:10 pm, Ondrej Certik <[email protected]> wrote:
> On Fri, Sep 10, 2010 at 3:40 PM, Bill Hart <[email protected]> wrote:
> > I recently viewed Ondrej's 2007 presentation on SymPy on the web:
> >http://www.google.com/url?sa=t&source=web&cd=6&ved=0CCoQFjAF&url=http....
> > ]
>
> > I'm curious about the details of the expression management in sympy,
> > which are discussed on slide 14.  Ondrej notes that the sympy strategy
> > avoids the creation of intermediate classes, which I think is a great
> > idea.  However, I don't quite see how this is done when I look at the
> > code.  Can you provide more details about how this is achieved?
>
> We use the __new__ method of Python classes, which is responsible for
> classes creation, and so if you do:
>
> a-a
>
> Add.__new__() get's called and inside that class it gets decided to
> create a class Integer(0) instead (without creating the intermediate
> Add class), in this case, "0" is also cached, but that's a detail.
>
>
>
> > I'm interested because I've run into performance bottlenecks in my
> > Coopr software (specifically in coopr.pyomo), where I'm building
> > algebraic expressions and I intermediate class construction is a major
> > bottleneck!
>
> Ondrej

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
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/sympy?hl=en.

Reply via email to