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, 19 Dec 2019 20:18:18 +0100substitution of variable in the result of monomials()https://ask.sagemath.org/question/49089/substitution-of-variable-in-the-result-of-monomials/Given a polynomial in n variables, I'd like to extract the list of its monomials, and then manipulate that list by substituting certain variables for others.
Simple example: in $Z[x,y]$ consider the polynomial $1+x+y^2$; the list of its monomials (in some ordering) is $(1,x,y^2)$. My function should be able e.g. to take that list and substitute $y$ with $x$, namely return $[1,x,x^2]$.
At the moment, my code gives error, but I do not understand how to fix it.
N.<x1,x2> = PolynomialRing(ZZ, 2)
f = 1+x1+x2
g = f.monomials()
for i in range(3):
g[i] = g[i].substitute_expression(x2==x1)
Namely, how do I make a variable in the polynomial ring also have the substitute attribute? or is there a better way to achieve this?rue82Thu, 19 Dec 2019 20:18:18 +0100https://ask.sagemath.org/question/49089/generate a list of variables with two indiceshttps://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/Hi
I would like to make a list of variables with two consecutive indices, example rr_10, rr_21 .. etc
I tried :
n=3
rrL=list(var('rr_%d%d' %i %(i-1)) for i in [1..n])
without success:**not enough arguments for format string**
what is the missing arguments here ? ortolljTue, 16 Apr 2019 09:25:03 +0200https://ask.sagemath.org/question/46214/question about Python assignment of lists; meaning of equals sign; how to save a list?https://ask.sagemath.org/question/44324/question-about-python-assignment-of-lists-meaning-of-equals-sign-how-to-save-a-list/I have a list, then modify it, but want to save the old list to then modify in a different way.
I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign,
so the modification also changes the original. Why does this happen, and how do I deal with this?
Example:
sage: L1 = [1, 2]
sage: L2 = [3, 4]
sage: L3 = L1
sage: L1
[1, 2]
sage: L2
[3, 4]
sage: L3
[1, 2]
sage: L1.extend(L2)
sage: L1
[1, 2, 3, 4]
sage: L2
[3, 4]
sage: L3
[1, 2, 3, 4]
The same thing happens with "append".
Help please!!!
Note: this does not happen with variables with numerical (not list) values. For example:
sage: a = 4
sage: b = a
sage: a = 5
sage: a
5
sage: b
4
So it seems that the equals sign means two different things: for numbers it is an assignment;
for lists it is an identification. This is driving me crazy. I cannot find it explained anywhere (maybe because it is so "well-known"?)alSun, 18 Nov 2018 15:59:29 +0100https://ask.sagemath.org/question/44324/Please Append 'solve' Help Documentationhttps://ask.sagemath.org/question/32387/please-append-solve-help-documentation/ Hello,
I have been using SAGE for about 2 years, and only now have I finally figured out how to get the 'solve()' function to print out its solutions in plain form (so I can save the answers as variables, which is EXTREMELY important for me).
In order to do this: I had to sift through the help pages for 'solve', Programming -- Data Types (for both Lists and Dictionaries), and Python's official documentation on Lists and Dictionaries; until I finally figured out that you need to use the code:
print( 'listname' [ ' dict # ' ] [ 'var' ])
Now this may seem very elementary to those whom are fluent in Python, but for general users (like me): there is absolutely no clear indication on how to call one or several elements of several Dictionaries inside of a List.
PLEASE append your documentation so that people can actually use the 'solve' function without having to copy and paste the answers because it isn't shown how to properly use the output when 'solution_dict=true'.
(Note: if you're thinking about the 'for' loop example in the help documentation: it's completely useless for someone who needs to select one or more of those solutions & save them as variables).
Thank you.BLU7211Sat, 30 Jan 2016 21:46:43 +0100https://ask.sagemath.org/question/32387/Substitution of a list of variableshttps://ask.sagemath.org/question/10606/substitution-of-a-list-of-variables/I wish substituting a list of variables, without having to substitute them 1 by 1.
Here is an example with an attempt which doesn't work :
sage: V=[var('x_%d' % i) for i in range(10)]; V
[x_0, x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8, x_9]
sage: S=[sum(V),prod(V)]; S
[x_0 + x_1 + x_2 + x_3 + x_4 + x_5 + x_6 + x_7 + x_8 + x_9,
x_0*x_1*x_2*x_3*x_4*x_5*x_6*x_7*x_8*x_9]
sage: for i in range(10):
....: S.subs(V[i]=i)
....:
File "<ipython-input-99-7670392e3358>", line 2
SyntaxError: keyword can't be an expression
How can we do this ?
Sébastien PalcouxSun, 13 Oct 2013 19:44:43 +0200https://ask.sagemath.org/question/10606/