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.Sat, 05 Sep 2020 19:35:39 +0200Extracting terms of polynomial of certain powershttps://ask.sagemath.org/question/53323/extracting-terms-of-polynomial-of-certain-powers/Let's say I have a polynomial f. I want to extract the monomials where every power of variable is divisible by a number, say 5. I have two ideas on how to do this.
Method 1:
R.<x,y,z> = QQ[]
f=x^(5)*y^(2)+z^(2)*x^(2)+y^(5)*x^(10)
The end result should give me y^(5)x^(10) as the first term has a power 2 which is not divisible by 5 and obviously the 2nd term is not. I am stuck here as I want to somewhat say the following.
f.exponents()
gives
[(10, 5, 0), (5, 2, 0), (2, 0, 2)]
Then I want to say
f.exponents()[i] % (5,5,5) == (0,0,0) is False, remove the ith term
There are 2 problems with this. The first is when I do f.exponents(), you see the tuples they give me are rearranged so the "ith" term is no longer what I think it is. For example, (10,0,5) is the 3rd term of f, but they put it as the first tuple. The second thing is f.exponents()[i] % (5,5,5) is not valid (i.e. gives error) but hopefully you get what I want. I basically want to divide component-wise and get all remainder 0. What is the correct code for this and the coding language for "remove the ith term"?
Method 2: I can consider f(x^(1/5),y^(1/5),z^(1/5)) and then check whether f.exponents()[i] belongs to Z^(3)-cartesian product of integers. The issue is again I don't know how to code this and f(x^(1/5),y^(1/5),z^(1/5)) gives error as I lie in the polynomial ring. The polynomial ring doesn't allow fractional exponents. I looked online and maybe I am suppose to work with Puiseux polynomials?
https://stackoverflow.com/questions/51077537/what-is-the-best-way-to-implement-polynomials-with-fractional-exponents-with-sagwhatupmattSat, 05 Sep 2020 19:35:39 +0200https://ask.sagemath.org/question/53323/simplifying out negative signs in exponentshttps://ask.sagemath.org/question/43132/simplifying-out-negative-signs-in-exponents/Hello all!
I can't for the life of me find a way to force sage to return terms with only positive coefficient variable exponents. For example, if I enter something like
assume(n, 'integer', n>10)
c = 2^(-n)
I would like the output to be something like `1/(2^n)`, but instead I can only get something like `2^(-n)`. Is there a way to force the output to display only positive coefficients in front of the n?
In general I'd like some `magicFunc` function which I could feed some expression `g(x,n)` and have it return a rational expression with no negatives; eg.
var('x,n')
assume(x,'real')
assume(n,'integer',n>10)
g(x,n) = 2^(-n)*x^(-3*n)*3^n
magicFunc(g(x,n))
Would return `3^n/(2^n*x^(3n))`
Is this possible? This seems like it should be an existent simplification method, but nothing I've tried seems to work.
Thanks!Jason021Tue, 24 Jul 2018 23:19:26 +0200https://ask.sagemath.org/question/43132/Polynomials with symbolic exponentshttps://ask.sagemath.org/question/42704/polynomials-with-symbolic-exponents/Is there a structure available which would admit formulas like
$$(X^a + Y^b) * X^d * Y^e$$
where $X,Y,a,b,d,e$ are variables?
Obvious identities like
$$(X^a + Y^b) * X^d * Y^e = X^{(a+d)} * Y^e + X^d * Y^{(b+e)}$$
should hold.StepanHolubThu, 21 Jun 2018 11:41:41 +0200https://ask.sagemath.org/question/42704/How to extract exponents from a monomial in a FreeAlgebrahttps://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/I want something like this, or a way to get the equivalent information:
sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: m.my_exponents_function()
[(X,1),(Y,1),(X,2)]
or
sage: m.my_factor_function()
[X,Y,X,X]
would be as good or maybe better.
How can I get that information? I've looked over the available methods and can't seem to find anything. This is easy to do with Polynomial Rings.
I guess I could parse the string representation, but shouldn't there be a better way?paragonWed, 05 Apr 2017 01:34:43 +0200https://ask.sagemath.org/question/37170/TypeError: non-integral exponents not supportedhttps://ask.sagemath.org/question/26718/typeerror-non-integral-exponents-not-supported/Being new to Sage, I can't understand this error "TypeError: non-integral exponents not supported". This is raised by "find_root" in the following code snippet:
R.<x>=RR[]
n=1000
betas=[0.01,0.03,0.05,0.07,0.99,0.91]
#for beta in betas:
#for beta in srange(0.01,0.09,0.02):
for beta in srange(0.91,0.99,0.02):
f=x^n - 3*x^(n-1)+x^(n-2)+x^(n-3)-2*x^(n-beta*n-1)-3^(beta*n)
find_root(f, 1,4);
But what is strange for me is that if I replace the "for" line with one of the commented line, then it works well. So I think there must be some Sage concepts that I haven't been aware of.
Thanks for your help!LéoTue, 05 May 2015 11:47:27 +0200https://ask.sagemath.org/question/26718/Exponent overflow in PolynomialRing(): need a work aroundhttps://ask.sagemath.org/question/10102/exponent-overflow-in-polynomialring-need-a-work-around/PolynomialRing() gives an OverflowError for exponents larger than 32768.
For example
sage: R = GF(2**28, 'a')
sage: a = R.gen()
sage: x = PolynomialRing(R, 'x', 4).gens()
sage: f = x[0]**32768
sage: f = x[0]**32769
...
OverflowError: Exponent overflow (32769).
I need to make a function containing `x[0]**(2**28 - 2)`.
How can I get Sage to do that?
I am using Sage Version 5.3, Release Date: 2012-09-08.apeelWed, 08 May 2013 09:53:01 +0200https://ask.sagemath.org/question/10102/How to simplify expression with fractional exponents?https://ask.sagemath.org/question/10006/how-to-simplify-expression-with-fractional-exponents/Is there a way to have Sage recognize that e^(2/3) times e^(1/3) in the below will simplify to just the variable e. Is there a type that can handle this? Obviously using a PolynomialRing in the code below won't work.
R.<a,e> = PolynomialRing(QQ)
p1 = (a+e^(1/3))
p2 = e^(2/3)
p1*p2kevinfatTue, 09 Apr 2013 21:24:12 +0200https://ask.sagemath.org/question/10006/Solve an expression with fractional exponentshttps://ask.sagemath.org/question/9863/solve-an-expression-with-fractional-exponents/I have an expression which, effectively, looks like this:
expr = x == x^(1/3)*y
except y is a really large number of constants. If I wanted to solve this for x, I should get x=y^(3/2). But instead:
solve(expr,x)
yields
[x == x^(1/3)*y]
In the example I gave, it's obviously not a big deal. But for my actual code, y is a *very* large number of constant factors, and this means copying those factors out by hand, and then re-inputting them in the correct form ( x = (factors)^(3/2) ) which is error prone and time consuming.
I've tried using 0.333 instead of (1/3) in the exponent, that doesn't make a difference.
Any help here would be appreciated. Thank you ahead of time!adamhgWed, 27 Feb 2013 20:16:53 +0100https://ask.sagemath.org/question/9863/