ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 27 Apr 2023 01:33:13 +0200Concatenation of list of variableshttps://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/Suppose I have three variables `x,y,z`. For pratical reasons, I want to define :
varx = var('x y')
varl = var('z')
A problem arrise immediately
type(varx)
returns `<class 'tuple'>`
when
type(varl)
returns `<class 'sage.symbolic.expression.Expression'>`. As they are not of the same (i can understand why but it seems a little weird) type, it's not possible to concatenate them. What is strange is that
[varl]
is a list, but
list(varl)
is not because `varl` is not enumerable. Finally,
list(varx)+[varl]
do what I was expecting (concatenation), but it was after a long time of essais and error. Could some one explain the logic behind this ?Wed, 26 Apr 2023 12:09:27 +0200https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/Answer by Max Alekseyev for <p>Suppose I have three variables <code>x,y,z</code>. For pratical reasons, I want to define :</p>
<pre><code>varx = var('x y')
varl = var('z')
</code></pre>
<p>A problem arrise immediately</p>
<pre><code>type(varx)
</code></pre>
<p>returns <code><class 'tuple'></code></p>
<p>when</p>
<pre><code>type(varl)
</code></pre>
<p>returns <code><class 'sage.symbolic.expression.Expression'></code>. As they are not of the same (i can understand why but it seems a little weird) type, it's not possible to concatenate them. What is strange is that </p>
<pre><code>[varl]
</code></pre>
<p>is a list, but</p>
<pre><code>list(varl)
</code></pre>
<p>is not because <code>varl</code> is not enumerable. Finally,</p>
<pre><code>list(varx)+[varl]
</code></pre>
<p>do what I was expecting (concatenation), but it was after a long time of essais and error. Could some one explain the logic behind this ?</p>
https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?answer=67911#post-id-67911`varx = var('x y')` defines a tuple of two variables, which can be accessed as `varx[0]` and `varx[1]`, which have names `x` and `y` respectively.
`list(varl)` is undefined as its requests conversion of a variable `varl` into a list. It's not the same as creating a list composed of a single variable, which would be `[varl]` as you noticed. And in general, `list(obj)` is not the same as `[obj]` where `obj` is any object.
`list(varx)` converts the tuple `varx` into a list (still composed of two variables), which enables further concatenations with other lists, like `list(varx)+[varl]`.Wed, 26 Apr 2023 15:25:56 +0200https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?answer=67911#post-id-67911Comment by Emmanuel Charpentier for <p><code>varx = var('x y')</code> defines a tuple of two variables, which can be accessed as <code>varx[0]</code> and <code>varx[1]</code>, which have names <code>x</code> and <code>y</code> respectively.</p>
<p><code>list(varl)</code> is undefined as its requests conversion of a variable <code>varl</code> into a list. It's not the same as creating a list composed of a single variable, which would be <code>[varl]</code> as you noticed. And in general, <code>list(obj)</code> is not the same as <code>[obj]</code> where <code>obj</code> is any object.</p>
<p><code>list(varx)</code> converts the tuple <code>varx</code> into a list (still composed of two variables), which enables further concatenations with other lists, like <code>list(varx)+[varl]</code>.</p>
https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?comment=67928#post-id-67928`var` behaves inconsistently, indeed.
Complain fiercely (or file an issue...).Thu, 27 Apr 2023 01:33:13 +0200https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?comment=67928#post-id-67928Comment by Max Alekseyev for <p><code>varx = var('x y')</code> defines a tuple of two variables, which can be accessed as <code>varx[0]</code> and <code>varx[1]</code>, which have names <code>x</code> and <code>y</code> respectively.</p>
<p><code>list(varl)</code> is undefined as its requests conversion of a variable <code>varl</code> into a list. It's not the same as creating a list composed of a single variable, which would be <code>[varl]</code> as you noticed. And in general, <code>list(obj)</code> is not the same as <code>[obj]</code> where <code>obj</code> is any object.</p>
<p><code>list(varx)</code> converts the tuple <code>varx</code> into a list (still composed of two variables), which enables further concatenations with other lists, like <code>list(varx)+[varl]</code>.</p>
https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?comment=67919#post-id-67919You don't have one-tuples in your question. If you mean `obj` and `(obj,)` - they are different objects for any `obj`.Wed, 26 Apr 2023 20:03:27 +0200https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?comment=67919#post-id-67919Comment by Cyrille for <p><code>varx = var('x y')</code> defines a tuple of two variables, which can be accessed as <code>varx[0]</code> and <code>varx[1]</code>, which have names <code>x</code> and <code>y</code> respectively.</p>
<p><code>list(varl)</code> is undefined as its requests conversion of a variable <code>varl</code> into a list. It's not the same as creating a list composed of a single variable, which would be <code>[varl]</code> as you noticed. And in general, <code>list(obj)</code> is not the same as <code>[obj]</code> where <code>obj</code> is any object.</p>
<p><code>list(varx)</code> converts the tuple <code>varx</code> into a list (still composed of two variables), which enables further concatenations with other lists, like <code>list(varx)+[varl]</code>.</p>
https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?comment=67917#post-id-67917But a one-tuple is a tuple. This was the origin of my question.Wed, 26 Apr 2023 19:11:11 +0200https://ask.sagemath.org/question/67903/concatenation-of-list-of-variables/?comment=67917#post-id-67917