The function that does the simplification you want is factor():

In [22]: var('a b c d')
Out[22]: (a, b, c, d)

In [23]: factor(a*c + b*d - a*d - b*c)
Out[23]: (a - b)⋅(c - d)

However, I'm not sure how to apply it here. You can't just convert
your dot products to multiplications because it isn't true that <a,
b>*<c, d> = <a, c>*<b, d>.

You might need to write a naive factor that recursively collects terms
with the same coefficient. For instance

<a, c> + <b,d> - <b,c> - <a, d>

-> <a, c - d> + <b, d - c>
-> <a - b, c - d>

This also needs to recognize that c - d = -(d - c).
could_extract_minus_sign is useful for this.

I don't recall if something like this is already written in SymPy.

Aaron Meurer


On Mon, Feb 27, 2017 at 12:44 PM, Nico Schlömer
<[email protected]> wrote:
> Thanks for the reply.
>
>>  I assume e0, e1, and e2 are arbitrary vectors.
>
> Indeed, they can be anything. (I'm looking at 3 dimensions here but given
> the fact that everything is a dot product I assume that doesn't play much of
> a role.)
>
> Cheers,
> Nico
>
>
>
> On Monday, February 27, 2017 at 6:37:59 PM UTC+1, brombo wrote:
>>
>> How the expression zeta obtained.  Do input the expression you show or is
>> it obtained by vector algebraic operations on vector expressions.  I assume
>> e0, e1, and e2 are arbitrary vectors.
>>
>> On Mon, Feb 27, 2017 at 12:04 PM, Nico Schlömer <[email protected]>
>> wrote:
>>>
>>> I have a somewhat large expression in inner products,
>>> ```
>>>           zeta = (
>>>               - <e0, e0> * <e1, e1> * <e2, e2>
>>>               + 4 * <e0, e1> * <e1, e2> * <e2, e0>
>>>               + (
>>>                   + <e0, e0> * <e1, e2>
>>>                   + <e1, e1> * <e2, e0>
>>>                   + <e2, e2> * <e0, e1>
>>>               ) * (
>>>                   + <e0, e0> + <e1, e1> + <e2, e2>
>>>                   - <e0, e1> - <e1, e2> - <e2, e0>
>>>                   )
>>>               - <e0, e0>**2 * <e1, e2>
>>>               - <e1, e1>**2 * <e2, e0>
>>>               - <e2, e2>**2 * <e0, e1>
>>>               )
>>> ```
>>> and the symmetry in the expression has me suspect that it can be further
>>> simplified. Is sympy capable of simplifying vector/dot product expressions?
>>> A small example that, for example, takes
>>> ```
>>> <a, c> + <b,d> - <b,c> - <a, d>
>>> ```
>>> and spits out
>>> ```
>>> <a-b, c-d>
>>> ```
>>> would be great.
>>>
>>> --
>>> 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 https://groups.google.com/group/sympy.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sympy/2cb85a5e-2b5f-402f-82cb-fd4e2f738d93%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
> --
> 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 https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/232c66f6-19a3-4672-8507-88631357e9c2%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2B72CZTPw_RsH0O0uasfZkt71zOZ-%3DpGNNdm2ZMw%3DBeFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to