On Sun, Oct 7, 2012 at 12:32 AM, Matthew Rocklin <[email protected]> wrote:
>
>> I'll just raise an (open) question: how practically feasible would it
>> be to attempt to address this issue using the rewriting rule system
>> which is currently being developed?  I don't expect anyone to have
>> definite answers, but I'd definitely be glad to hear opinions (perhaps
>> in a separate thread).
>
> Most classes like Add, MatAdd, etc... do serve two purposes as you say. My
> names for these are as follows
> Container -- they act as a typed tuple and contain args
> Canonicalizer -- they take in different inputs like "x + y" and "y + x" and
> produce a normalized form

Yes, that's a nice way to put it.

> Rules do strip out a fair amount of canonicalization and leave the classes
> as mostly just containers. You could use rules for everything and make the
> classes just containers. This is a question of programming style though, I
> don't think that it's objectively better or worse. If you wanted to do this
> I think you would just make a new project. SymPy has its own thing going on
> and it works pretty well. I've made a project that was based on just rules
> for matrix expressions. It was neat, I had fun, but I don't expect the world
> to suddenly decide that rules are how we should do things. Balance is
> healthy.

Hm, I see your point.  In this case I wonder how far within SymPy you
envision the rewriting rule system to extend.

> Regarding "It's unfortunate that Expr can't support MatrixExpr."
> Actually, I disagree. Expr is effectively ScalarExpr. That's good. We should
> have different container classes for scalars and matrices. This makes
> writing a lot of code much more convenient. Example, it's really nice to
> assume that the additive identity is the number 0. We often type 0 when we
> actually mean "the additive identity". If we always had to use some object
> here that would be inconvenient. I think that having different classes for
> containers is good.

Hm, well, I get your point; however, shouldn't Expr be renamed to
ScalarExpr then?  It may be just me, but when I hear "expression" and
"matrix expression" I expect that all matrix expressions are
expressions.

> Of course, canonicalization is likely to be very similar. The process of
> removing identities from Adds and MatAdds is pretty similar so it's nice if
> our canonicalization system is general. Rules provide this pretty easily. I
> have a function remove identity (rmid) in sympy/sympy/rr/rl.py
>
> remove_zeros = rmid(lambda x : x == 0)
> remove_ZeroMatrices = rmid(lambda x: x.is_Matrix and x.is_ZeroMatrix)
>
> These two rules are now ready to be introduced into a set of rules for
> canonicalization.

Yes, it's precisely this similarity that I have in mind.

Sergiu

-- 
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