Manipulating expressions with vectors

67 views
Skip to first unread message

Alexander Lindsay

unread,
Jan 15, 2016, 11:04:20 AM1/15/16
to sympy
Hi all,

I'm pretty new to sympy. I'm wondering whether it's possible to manipulate expressions with vector dot products without sympy trying to actually evaluate the dot product. Let's say A and B are vectors; I want the expression A * B to simply be A * B, not a1*b1 + a2*b2 + a3*b3. I can't simply use:

A, B = symbols('A B')

and carry them around in expressions that way because I want to avoid simplifications like (C is another vector): A * B / (A * C) = B / C

My full expressions contain many scalars as well as dot products; I want to allow scalar simplification, e.g. I want x*y / x*z = y / z, while avoiding incorrect vector simplifications like the possibility above.

I hope that this is not too strange or stupid of a question!

Alex

Aaron Meurer

unread,
Jan 15, 2016, 11:09:14 AM1/15/16
to sy...@googlegroups.com
There is some work in progress to create a DotProduct for matrix
expressions, which should do what you want here
https://github.com/sympy/sympy/pull/10252.

Aaron Meurer
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> 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/7ab512af-b031-4b1f-bd09-f66b2e188b50%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Alex Lindsay

unread,
Jan 15, 2016, 11:25:06 AM1/15/16
to sy...@googlegroups.com
Neat. I'll be monitoring to see when the PR is merged!

brombo

unread,
Jan 16, 2016, 6:37:36 PM1/16/16
to sympy
You may want to look at my geometric algebra module that uses sympy (github.com/brombo/galgebra) and see if it does what you want it to.  I have attached the manual (galgebra.pdf) for you to look at.
galgebra.pdf

Francesco Bonazzi

unread,
Jan 18, 2016, 10:37:00 AM1/18/16
to sympy


On Friday, 15 January 2016 17:04:20 UTC+1, Alexander Lindsay wrote:

and carry them around in expressions that way because I want to avoid simplifications like (C is another vector): A * B / (A * C) = B / C


This is a trick: declare A, B, C as non commutative variables:

 
In [1]: A, B, C = symbols('A B C', commutative=False)

In [2]: A * B / (A * C)
Out[2]:
         
-1
A
*B*(A*C)  



Alex Lindsay

unread,
Jan 20, 2016, 6:51:54 PM1/20/16
to sy...@googlegroups.com
Looks neat. I will have to delve into it more. Thanks!
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

Alex Lindsay

unread,
Jan 20, 2016, 6:52:31 PM1/20/16
to sy...@googlegroups.com
I like that :-) That's probably actually all I need for this case
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
Reply all
Reply to author
Forward
0 new messages