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.Fri, 07 Apr 2017 10:11:15 +0200Mapping a list to some variables for a system of equationshttps://ask.sagemath.org/question/37192/mapping-a-list-to-some-variables-for-a-system-of-equations/ I have a list of integers $(a, b, c, d)$ and a system of equations, where each equation has two unknowns. My system looks like $(x0+x4, x1+x4, x2+x4, x3+x4).$ I am trying to evaluate the system in $(a,b,c,d)$. If I write $system(x0=1, x1=2, x3=1, x4=1)$, the system correctly outputs the result of each equation. Now, I would like to do something like $system(x0=a, x1=b, x3=c, x4=d)$ but without having to manually put the variables in. I have tried writing $system(list)$ but the number of variables and unknown doesn't match. Is there any way I can achieve this ?Thu, 06 Apr 2017 16:42:03 +0200https://ask.sagemath.org/question/37192/mapping-a-list-to-some-variables-for-a-system-of-equations/Answer by mforets for <p>I have a list of integers $(a, b, c, d)$ and a system of equations, where each equation has two unknowns. My system looks like $(x0+x4, x1+x4, x2+x4, x3+x4).$ I am trying to evaluate the system in $(a,b,c,d)$. If I write $system(x0=1, x1=2, x3=1, x4=1)$, the system correctly outputs the result of each equation. Now, I would like to do something like $system(x0=a, x1=b, x3=c, x4=d)$ but without having to manually put the variables in. I have tried writing $system(list)$ but the number of variables and unknown doesn't match. Is there any way I can achieve this ?</p>
https://ask.sagemath.org/question/37192/mapping-a-list-to-some-variables-for-a-system-of-equations/?answer=37217#post-id-37217maybe using [substitute](http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html#sage.symbolic.expression.Expression.substitute):
sage: var('a, b, c, d')
(a, b, c, d)
sage: assume([(a, 'integer'), (b, 'integer'), (c, 'integer'), (d, 'integer')])
sage: x = polygens(ZZ, ['x'+str(i) for i in range(5)]) # create x_0, ..., x_4
sage: system = [x[0]+x[4], x[1]+x[4], x[2]+x[4], x[3]+x[4]] # this is a Python list
sage: evaluation = {x[0]:a, x[1]:b, x[3]:c, x[4]:d} # this is a Python dictionary
sage: [si.subs(evaluation) for si in system] # subs is a shortcut for substitute
[a + d, b + d, d + x2, c + d]Fri, 07 Apr 2017 10:11:15 +0200https://ask.sagemath.org/question/37192/mapping-a-list-to-some-variables-for-a-system-of-equations/?answer=37217#post-id-37217