On Wed, Jul 18, 2012 at 2:29 PM, [email protected]
<[email protected]> wrote:
> I have questions about this:
>
>> In my branch where I'm fixing expand, I've moved the base _eval_expand
>> functions to Expr.  The result is that for expand to work on an
>> object, it must be rebuildable via obj.func(*obj.args).
>
> But how does then Symbol work? Are you just making a special case for
> it? And how will expressions like TensorProduct(a, b+c) work?

It uses is_Atom for the base case.

I'll have to look at what happens in TensorProduct.

>
> For the second case it may be argued that it is the constructor of
> TensorProduct that must do the expansion or that `expand` is and
> should be only defined for Mul objects, so just for the moment I will
> drop it.

expand() should work on any Expr object. In fact, the quantum module
already uses it and even defines its own methods, so I'm working to
make sure that it still works there, and so it should work with
TensorProduct too if it's Expr.

>
> However **if** (if not, it will be useful for me to know how you
> solved the problem) you are special-casing Symbol, why stop just
> there. It is not like Symbol is the only object that needs string for
> a name and hence has to do something special with the
> obj.func(*obj.args) stuff (as we permit only Basic in args for now).
>
> Is the new expand doing something like this type of tree traversal?
>
> def reconstruct():
> if hasattr(obj, 'args') and obj.args:
>     return obj.func(map(reconstruct, obj.func))
> else:
>     return obj

Yep, though it looks more like the way Add._eval_expand_multinomial
looks in master.  A consequence is that the .args elements don't have
to be Basic or Expr for it to work (expand() is only defined for Expr
anyway, not Basic).  However, only the top-level Expr no-op
_eval_expand_* methods do a hasattr check.  It would be simply
insanity to require that every _eval_expand_* on all subclasses do a
hasattr check on its args before recursing.

By the way, I'm *almost* ready to submit this as a PR.  What I have so
far is in my expand_refactor branch, but I've yet to push the actual
refactoring until I finish it completely and get all the tests
passing.

Aaron Meurer

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