Hi again,

It turned out that there was a specific point in the code where the
non-commutative terms were being added to the list of independent
expressions without actually being checked for the argument to
as_independent. I have fixed this, and the issue I observed no longer seems
to be there. I don't know if this is the most general solution for
non-commutative symbols, but it at least works for the incorrect output
cases that I observed.

I've submitted PR 481 for this (https://github.com/sympy/sympy/pull/481). I
would greatly appreciate any feedback! Thanks!

Tomo

On Wed, Jul 6, 2011 at 5:28 PM, Tomo Lazovich <[email protected]>wrote:

> I've opened an issue for this:
> http://code.google.com/p/sympy/issues/detail?id=2549
>
> I should note (as I do in the issue) that there are some cases where it
> does return the correct output for a non-commutative symbol. In fact, there
> are some tests already in the doctests for the non-commutative case. I think
> the issue is specifically for cases where the symbol we pass as an argument
> to as_independent is commutative, but is in an expression with a
> non-commutative symbol. In these cases, that expression always ends up as
> independent, even if it depends on the argument.
>
> I will play with this a bit and see what I can come up with. It might end
> up being a simple-ish fix, and if it gets more complicated I may need help
> from someone more experienced with this code.
>
> On Wed, Jul 6, 2011 at 4:50 PM, Aaron Meurer <[email protected]> wrote:
>
>> If as_independent (or any other function) does not work with
>> noncommutative symbols, it's a bug, and should be fixed.
>>
>> Unfortunately, quite a few functions in SymPy are not written with
>> noncommutative symbols taken into consideration.  This is because most
>> people and most code does not use them.  However, it should not be
>> this way.  Every function should either give the correct result for a
>> noncommutative expression, or raise NotImplementedError if it cannot
>> (for example, factor() does this).
>>
>> I recommend opening an issue for this.  Someone might come along and
>> fix it for you (Chris does a lot of work on making these methods of
>> Expr work with noncommutatives for example), but likely you will need
>> to fix it yourself.  You should look at the code to see which part of
>> it makes an assumption that is invalid in the noncommutative case, and
>> fix it.  You may need to rewrite the algorithm, or write a separate
>> algorithm for the noncommutative case, depending on how ingrained the
>> assumption of commutativity is in the code. Or, for example, if an
>> algorithm that takes noncommutatives into consideration would be
>> slower in the commutative case, you should separate the code.
>>
>> The code should be well tested (especially if it's being used by other
>> functions like integrate()), so don't worry about breaking things.
>> Just make sure that the tests pass, and you can be pretty sure that
>> things still work for the commutative case (you will of course need to
>> add your own tests for the noncommutative case).
>>
>> Aaron Meurer
>>
>> On Wed, Jul 6, 2011 at 12:57 PM, Tom Bachmann <[email protected]> wrote:
>> > I think as_independent only works with commutative terms (i.e. any
>> > implementation for non-commutative terms that ever existed is now
>> somehow
>> > broken). Indeed when I started my project some objects were
>> non-commutative
>> > [Tuple lacking correct assumptions turned out to be the cause] and I got
>> > similar behaviour.
>> >
>> > I guess this is not very helpful, since you cannot just make your
>> > non-commutative objects commutative ^^.
>> >
>> > --
>> > 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.
>> >
>> >
>>
>> --
>> 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.
>>
>>
>

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