On Wed, Jul 3, 2013 at 11:04 AM, Aaron Meurer <[email protected]> wrote:
> It's related, because currently all canonicalization happens in the
> class constructor, and it's impossible for classes to define their own
> canonicalization (i.e., what happens in the constructor) due to lack
> of dispatch.

That's right. So if we implement multiple dispatch, which btw can be
implemented really easily (though I don't know if this implementation
would be sufficient for our purposes), see e.g.:

http://www.artima.com/weblogs/viewpost.jsp?thread=101605
http://blog.ianbicking.org/more-on-multimethods.html


then
x = Symbol("x")
add(x, x)

would call our standard Add which would do the usual simplification
like x+x -> 2*x.
But then we could implement SymbolHold as a subclass of Symbol, and then

x = SymbolHold("x")
add(x, x)

would dispatch (based on the argument types, which now is SymboHold
instead of Symbol) to a new class AddHold which would keep x+x as x+x.

And we can register AddHold to be called even for argument
combinations like (Symbol, SymbolHold)
or (SymbolHold, Symbol), so if you do:

x = SymbolHold("x")
x2 = Symbol("x")
add(x, x2)

it would still keep it as x+x.

I think this could really work well.

Ondrej

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to