# 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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.75825393,"math_prob":0.9687174,"size":638,"snap":"2021-31-2021-39","text_gpt3_token_len":170,"char_repetition_ratio":0.1214511,"word_repetition_ratio":0.0,"special_character_ratio":0.28526646,"punctuation_ratio":0.14074074,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9969339,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-21T13:13:50Z\",\"WARC-Record-ID\":\"<urn:uuid:db129c05-415a-468a-a852-0d9a4508c4b3>\",\"Content-Length\":\"55752\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:71bb8c4f-152b-4b7e-b9a3-2cefe5a50b5c>\",\"WARC-Concurrent-To\":\"<urn:uuid:97c5e62e-d7f7-4bf7-8fb8-65089dd2f494>\",\"WARC-IP-Address\":\"194.254.163.53\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/10436/append-a-variable-to-a-vector/?sort=latest\",\"WARC-Payload-Digest\":\"sha1:EMT5OZZD4GYVHDDUORBHXSTQ45ER4UHQ\",\"WARC-Block-Digest\":\"sha1:XQRNOTPCK5GRJYNRYZKHMO4BKQWMIZRY\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057225.38_warc_CC-MAIN-20210921131252-20210921161252-00359.warc.gz\"}"}