ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 28 Feb 2017 03:03:25 -0600Issues with substitutionhttp://ask.sagemath.org/question/36748/issues-with-substitution/I have a list L = [a13 == a10, a14 == a11, a15 == a12, a16 == a7, a17 == a8, a18 == a9]
I then have a running through a loop giving it these values
a = 1
a = 2*a15*a16 + 2*a13*a17 + 2*a13*a18 +1849
etc
I have
print(a)
a.subs(L)
print(a)
and it indicates no change, but I would of thought/ expected substitution to of taken place. Maybe I am being idiot, but please tell me where. I also posted this on stack overflow, sorry if I am not meant to post on both.
Thanks.Mon, 27 Feb 2017 11:33:19 -0600http://ask.sagemath.org/question/36748/issues-with-substitution/Comment by kcrisman for <p>I have a list L = [a13 == a10, a14 == a11, a15 == a12, a16 == a7, a17 == a8, a18 == a9]</p>
<p>I then have a running through a loop giving it these values</p>
<p>a = 1 </p>
<p>a = 2<em>a15</em>a16 + 2<em>a13</em>a17 + 2<em>a13</em>a18 +1849 </p>
<p>etc</p>
<p>I have </p>
<p>print(a)</p>
<p>a.subs(L)</p>
<p>print(a)</p>
<p>and it indicates no change, but I would of thought/ expected substitution to of taken place. Maybe I am being idiot, but please tell me where. I also posted this on stack overflow, sorry if I am not meant to post on both.</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/36748/issues-with-substitution/?comment=36749#post-id-36749Cross-posted at http://stackoverflow.com/questions/42492080/issue-with-substitution (which is fine, by the way).Mon, 27 Feb 2017 13:10:37 -0600http://ask.sagemath.org/question/36748/issues-with-substitution/?comment=36749#post-id-36749Answer by ndomes for <p>I have a list L = [a13 == a10, a14 == a11, a15 == a12, a16 == a7, a17 == a8, a18 == a9]</p>
<p>I then have a running through a loop giving it these values</p>
<p>a = 1 </p>
<p>a = 2<em>a15</em>a16 + 2<em>a13</em>a17 + 2<em>a13</em>a18 +1849 </p>
<p>etc</p>
<p>I have </p>
<p>print(a)</p>
<p>a.subs(L)</p>
<p>print(a)</p>
<p>and it indicates no change, but I would of thought/ expected substitution to of taken place. Maybe I am being idiot, but please tell me where. I also posted this on stack overflow, sorry if I am not meant to post on both.</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/36748/issues-with-substitution/?answer=36757#post-id-36757This works as expected:
V = [var("a{}".format(k)) for k in [7..18]]
L = [a13 == a10, a14 == a11, a15 == a12, a16 == a7, a17 == a8, a18 == a9]
a = 2*a15*a16 + 2*a13*a17 + 2*a13*a18 + 1849
print a
b = a.subs(L)
print b
Please note: `a.subs(L)` does **not** change `a` in place.Tue, 28 Feb 2017 03:03:25 -0600http://ask.sagemath.org/question/36748/issues-with-substitution/?answer=36757#post-id-36757