Ask Your Question
0

vector division?

asked 2013-08-18 05:18:06 +0200

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
1

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

Comments

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 08:35:15 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-08-18 07:15:09 +0200

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])
1/2
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

Comments

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 08:09:01 +0200 )edit
0

answered 2013-08-18 06:35:58 +0200

ndomes gravatar image

updated 2013-08-18 16:38:51 +0200

It is funny.

1/sv

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:

sv.__div__(2)

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

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

(sv/2).parent()

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:

(sv/sv).parent()

Symbolic Ring
edit flag offensive delete link more

Comments

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 11:45:48 +0200 )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

Stats

Asked: 2013-08-18 05:18:06 +0200

Seen: 2,528 times

Last updated: Aug 18 '13