ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 15 Sep 2016 06:22:11 -0500Polynomials with multiple variables and abstract coefficientshttp://ask.sagemath.org/question/34824/polynomials-with-multiple-variables-and-abstract-coefficients/ Hey there,
I need to create a polynomials (say P1, P2) that will have a number of variables (ca. 5) and abstract coefficients (ca. 9) (but I can assume that coefficients are variables carrying integer values). Then I would like to multiply P1, P2 and collect variables and extract coefficients standing next to them, e.g
from
` XA * XB + XA^2 + 2 * A * XA + 4*XB / XC + 5`
I should be able to get
`2*A*XA + XA^2 + XA*XB + 4*XB/XC + 5`
and from this a list of coefficients like
`[2A, 1, 1, 4, 5]` (with zeros in proper places eg. coefficient for XA*XB*XC)
Browsing the net I have found sth like:
`B.<x,y,z> = QQ[];
A.<x,y,z>=B[];
ex = (1-a^2)*x*y^2+(a-b^2+c)*x*y*z+(b^2-c^2-a)*x^2*z;
ex.coefficients();
ex.monomials()`
And my questions are:
(1.) how can I pass a list of variables to define a ring, I am interested in sth like
`B.list = QQ[];
A.list2 = B[]`
(2.) As you run the code above you can easily note that the output is:
`[-x*y^2, x^2*z - x*y*z, -x^2*z, -x^2*z + x*y*z, x*y*z, x*y^2];
[a^2, b^2, c^2, a, c, 1]`
As you can see the list from ex.coefficients() contains multiply entries for x*y^2 and -x*y^2 separately. And this is no go. Any ideas how can I fix it?
Thanks for any suggestions!
Bests
MichalmpzajacThu, 15 Sep 2016 06:22:11 -0500http://ask.sagemath.org/question/34824/Performing substitutions on powers of a variablehttp://ask.sagemath.org/question/32843/performing-substitutions-on-powers-of-a-variable/I have some polynomials of degree $d$ and I would like to obtain the monomial where all exponents greater than $1$ are reduced to $1$. For example $x_1^2 x_3^4 x_2 + x_1^7x_3^3 x_2^8 + \cdots$ would become $2x_1 x_3 x_2 + \cdots $
Naively, I thought an approach along the following lines would work:
sage: x = PolynomialRing(QQ, 1, 'x').objgens()[1][0]
sage: s = 2*x^2
sage: s.substitute({x^2:x})
2*x^2
Unfortunately, this does not give the proper result. Hence I am wondering
> What is the proper way to perform the described substitution on the powers of a given monomial?
Edit. It seems that I can do ss = symbolic_expression(s).substitute({x^2:x}) and then convert ss to a polynomial. However, this seems to be extremely inefficient.
JernejSun, 20 Mar 2016 15:03:35 -0500http://ask.sagemath.org/question/32843/Correct way to compute the modulus of a polynomialhttp://ask.sagemath.org/question/32838/correct-way-to-compute-the-modulus-of-a-polynomial/I am dealing with a large list of monomials of degree 1. One such (small) example would be
> x0*x2*x3*x4 + x1*x2*x3*x4 - x0*x2*x3 - x1*x2*x3 - x0*x3*x4 - x1*x3*x4 + x2*x3*x4 + x0*x3 + x1*x3 - x2*x3 - x3*x4 + x3
I need to create a dict that, encodes each of the above summands (recording the respective variable indices) and the respective value of the coefficient. So for the above expression I'd like to make the dictionary:
> {'0,2,3': -1, '0,2,3,4': 1, '0,3': 1,
> '0,3,4': -1, '1,2,3': -1, '1,2,3,4':
> 1, '1,3': 1, '1,3,4': -1, '2,3': -1,
> '2,3,4': 1, '3': 1, '3,4': -1}
I would like this to be as efficient as possible. As far as I understand it is not possible to use coefficients() to return this and the only way I see how to accomplish this is by converting the expression to a string and parse it. Given that this is quite inefficient and ugly I was wondering
> What would be an efficient way to extract the described dictionary from a given monomial expression?
JernejSun, 20 Mar 2016 08:47:17 -0500http://ask.sagemath.org/question/32838/Dimensions of modules in branchinghttp://ask.sagemath.org/question/27011/dimensions-of-modules-in-branching/ For example, consider the following branching:
G2=WeylCharacterRing("G2",style="coroots")
adj=G2(0,1)
A1 = WeylCharacterRing("A1", style="coroots")
adj.branch(A1,rule="levi")
How can I find the dimensions of all representations that occur?
In this example, we obtain:
3*A1(0) + A1(2) + 2*A1(3)
and I would like to get:
3*1 + 3 + 2*4
(Note: If I try A1(1).degree() I obtain 1 which is wrong.)vit.tucekWed, 03 Jun 2015 09:55:46 -0500http://ask.sagemath.org/question/27011/monomial orders in Laurent polynomialshttp://ask.sagemath.org/question/25411/monomial-orders-in-laurent-polynomials/ in Sage you can compare Laurent polynomials using a specified monomial order, one of the following standard ones: lex, grlex, invergrlex etc.
does anyone know how these monomial orders are defined for Laurent polynomials? are they well-orders too?marcin.szalskiTue, 06 Jan 2015 05:05:24 -0600http://ask.sagemath.org/question/25411/How to get a list of monomials of a given degreehttp://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/Is there a nice way to get all monomials of a given degree in a multivariable polynomial ring?
For example I want to input x,y,3 and get
x^3, x^2*y, x*y^2, y^3.
I think I could code it myself with not too much work, but it seems like something that might already have a nice method.paragonTue, 22 May 2012 16:43:08 -0500http://ask.sagemath.org/question/8994/How to reference algebra monomials?http://ask.sagemath.org/question/9130/how-to-reference-algebra-monomials/Hello. My questions are relatively easy to phrase, but first, some background.
If I have an algebra like
H = IwahoriHeckeAlgebraT("A3",1,prefix = "s")
and I ask for `H(H.basis().keys()[1])` I get s1, which is the correct ewaulr and the same result as `H.monomial(H.basis().keys()[1])`. However, with an algebra such as
A = CombinatorialFreeModule(QQ, ['a','b','c'])
`A(A.basis().keys()[1])` returns an error, whereas `A.monomial(A.basis().keys()[1])` returns B[b], which is the correct answer.
So, my question is, what is the difference between calling an Algebra Object (like A or H from above) versus calling that Algebra Object's monomial method? Furthermore, if they are different, (which they appear to be,) what method is A(x) or H(x) calling? Finally, is there any documentation on this A(x) method? Calling the documentation from the notebook interface gets me the docstring for the class.
Thank you for your help!ghseeliMon, 16 Jul 2012 10:25:26 -0500http://ask.sagemath.org/question/9130/