Ask Your Question

vector division?

asked 2013-08-17 22:18:06 -0600

Mark gravatar image

given a vector in sage

sage: a,b=var('a,b')
sage: sv=vector(SR,[1,a,b^2])

then why is this a meaningful operation

sage: sv/sv

To my (utterly humble) understanding, I always thought, that if vector multiplication '*' is defined via the scalar product - as it seems to be in sage

sage: sv*sv
a^2 + b^4 + 1

then, division cannot be defined meaningfully?

[Just as a sideremark along that line: I have no problem with numpy's element wise array-arithmetic

In [1]: v=array([1.,2.,3.]) # vector
In [2]: e=array([1.,1.,1.]) # unity is a vector
In [3]: e*v == v # multiplication by unity
Out[4]: array([ True,  True,  True], dtype=bool)
In [5]: vi=v**(-1) # inverse is a vector
In [6]: e/v == vi # unity/vector == inverse
Out[7]: array([ True,  True,  True], dtype=bool)
In [8]: e == v*vi # vector * inverse == unity
Out[9]: array([ True,  True,  True], dtype=bool)

In my layman's world, this type of division makes perfect sense. (Moreover I'm curious why sage seems to not adopt this pythonic way of array arithmetic)]

edit retag flag offensive close merge delete


Note that `*` is not only inner product, but also multiplication by a scalar. Indeed `2*sv` returns the expected answer. I'd say that Sage strives to give an interface that is closer to the mathematical usage, rather than the "pythonic" way. Sometimes this can be surprising, as in `sv/sv`.

Luca gravatar imageLuca ( 2013-08-18 01:35:15 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2013-08-18 00:15:09 -0600

Volker Braun gravatar image

Division of two vectors is only allowed if they are a scalar multiple of each other, and the result is the ratio of their length. If not, you get an error:

sage: vector(QQ, [1,2,3]) / vector(QQ, [2,4,6])
sage: vector(QQ, [1,2,3]) / vector(QQ, [1,1,1])
Traceback (most recent call last)
ArithmeticError: vector is not in free module

The ratio is in the same base ring as the vectors, so if you have vectors over QQ then the ratio is rational, if you have vectors over SR then the ratio is again an element of the symbolic ring.

edit flag offensive delete link more


Ok., this makes (some) sense. Still, would you mind educating me on if this is just syntactic candy, or rather something absolutely standard that I should find in my high school linear algebra textbooks.

Mark gravatar imageMark ( 2013-08-18 01:09:01 -0600 )edit

answered 2013-08-17 23:35:58 -0600

ndomes gravatar image

updated 2013-08-18 09:38:51 -0600

It is funny.


gives the expected answer:

TypeError: unsupported operand parent(s) for '/': 'Integer Ring' and
'Vector space of dimension 3 over Symbolic Ring'

The vector sv has a division operator, which makes sense if interpreted as scalar multiplication:


(1/2, 1/2*a, 1/2*b^2)

The expression sv/2 is element of a vector space:


Vector space of dimension 3 over Symbolic Ring

As far nothing to complain.

I don't know why, but the expression sv/sv is astonishingly an element of the Symbolic Ring:


Symbolic Ring
edit flag offensive delete link more


this is because your vector sv belongs to the symbolic ring (try sv.parent()). It is coherent that the answer belongs to the ring or field of your module or vector space.

vdelecroix gravatar imagevdelecroix ( 2013-08-26 04:45:48 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-08-17 22:18:06 -0600

Seen: 868 times

Last updated: Aug 18 '13