# append a variable to a vector

I would like to define a new vector in Sage $\vec{u} = [O, P, \sigma]$ using a previously defined vecotor $\vec{x} = [O, P]$ and a new variable $\sigma$.

My code looks like:

var(O, P');

var('sigma');

x = vector([O,P]);

u = vector([x, sigma]);

Which gives an error:

TypeError: unable to find a common ring for all elements

Apparently this is because vector() requires the variables to be of the same ring. In my case

x.parent()

Vector space of dimension 2 over Symbolic Ring

and

sigma.parent() Symbolic Ring

There is any way how to connect this two objects ($\vec{x}$, $\sigma$) together to create one vector?

edit retag close merge delete

Sort by » oldest newest most voted

So an solution which work is to convert the vector to a list, append the new variable and convert to a vector again. The code for that would be as follows:

u = x.list()

u.append(sigma)

u = vector(u)

Do you see any potential problems with this solution? Why there is no method append in vector? Could I do better?

more

1

The short answer to your question about vector is that a vector in Sage is not the same as a "vector" in other languages. Python lists correspond to that notion. A vector in Sage is a *mathematical* object, and there is no one way to make a (say) 3-d vector a 4-d vector. One could indeed add a dimension, but where? It would be (mathematically) just as natural to do it 'in front' as 'in back'. Your solution is actually a good one, and has the advantage that if your original vectors live in two different spaces (say, over QQ and RR) then your new vector will still make sense.