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.Sun, 25 Jun 2023 17:18:23 +0200Substitution of variable in polynomial not working as expected.https://ask.sagemath.org/question/69493/substitution-of-variable-in-polynomial-not-working-as-expected/The `subs` method behaves differently in two related settings:
- univariate polynomials over SR
- multivariate polynomials over SR
when trying to substitute a value for some variable involved as a coefficient.
In the univariate case:
R.<x> = SR[]
a = SR.var('a')
P = a*x
P.subs(a=1)
returns `x`, as expected.
But in the multivariate case:
R.<x, y> = SR[]
a = SR.var('a')
P = a*x
P.subs(a=1)
returns `a*x`.jllbSun, 25 Jun 2023 17:18:23 +0200https://ask.sagemath.org/question/69493/Computing singular locushttps://ask.sagemath.org/question/66654/computing-singular-locus/I have a bunch of homogeneous polynomials in 5 variables with specific arbitrary (symbolic) non-zero coefficients, i.e. some of them are zero and some of them are non-zero but I don't know the value. For instance:
$$F=a_0x_0f_3(x_1, x_2, x_3)+x_1^2f_2(x_0, \ldots, x_4)+x_0x_1g_3(x_0, x_1,x_2,x_3,x_4)$$
where $f_i, g_j$ are the polynomials with arbitrary non-zero coefficients of degree $i$, $j$, respectively, e.g. say that f_3 has all possible monomials of degree 3 in variables $x_1, x_2, x_3$ with arbitrary coefficients $a_1, a_2, \ldots$
I don't care much which field the coefficients belong to (but if you must know, let it be $\mathbb C$). I want to find the singular locus (i.e. the points $p\in \mathbb P^4$ where all partial derivatives $\frac{\partial F}{\partial x_i}(p)$ of $F$ simultaneously vanish) of one such $F$ in terms of symbolic coefficients and variables $x_i$. Is this something Sagemath can do? If so, can you give me a MWE? For the avoidance of doubt, I am happy to rewrite $F$ above to make the coefficients explicit (e.g. $F=a_0x_0x_1^3+a_1x_0x_1x_2^2+\cdots$).
Thank you.Jesus Martinez GarciaFri, 24 Feb 2023 14:43:02 +0100https://ask.sagemath.org/question/66654/polynomial variable rewritehttps://ask.sagemath.org/question/66057/polynomial-variable-rewrite/ Say I have a polynomial (over a ring) x^4+x^2+1. I want to change variables t=x^2 so it becomes t^2+t+1, and if possible rename back to x^2+x+1. How do I do that? ittaydMon, 23 Jan 2023 18:24:57 +0100https://ask.sagemath.org/question/66057/compute all degree d bivariate polynomials and evalute themhttps://ask.sagemath.org/question/65912/compute-all-degree-d-bivariate-polynomials-and-evalute-them/I want to compute all degree <=d polynomials, of form f1(x1)g1(x2)+f2(x1)g2(x2), from GF(2)[x1, x2] and then evaluate them at a certain polynomial input
eg degree d <= 1 and evaluation at (p^2, p^3 +1)
0 -> 0
1 -> 1
x1 -> p^2
x1 + 1 -> p^2 + 1
x2 -> p^3 + 1
x2 + 1 -> p^3
x1 + x2 -> p^2 + p^3 + 1
x1 + x2 + 1 -> p^2 + p^3hansserSat, 14 Jan 2023 10:32:58 +0100https://ask.sagemath.org/question/65912/checking whether the polynomial has a rational roothttps://ask.sagemath.org/question/65661/checking-whether-the-polynomial-has-a-rational-root/Hello there,
I have a polynomial $f$ which has all its roots purely imaginary, that is, if $f(z)=0$, then $z=ix$ for some real number $x$. I'm using the following command to check all the roots.
>f.roots(ring=CC)
Now I define $g(x) = f(ix)$. Then, all the roots of $g(x)$ are real. I want to print only the rational roots of $g$. So I tried:
> g.roots(ring=QQ)
But I'm getting the following error:
> Unable to coerce I to a rational
How to fix this?the1diotMon, 02 Jan 2023 12:09:14 +0100https://ask.sagemath.org/question/65661/Polynomial ring over self-defined coefficient ringhttps://ask.sagemath.org/question/65472/polynomial-ring-over-self-defined-coefficient-ring/Is it possible to define an Univariate Polynomial Ring over a user-defined ring in sagemath?
Here is sample code (only an example, not my real use case):
class Rationals:
def __init__(self,nom,denom):
if (denom==0):
print("Error")
print(quit)
quit()
else:
divisor=gcd(nom,denom)
if (divisor!=0):
self.nom=nom/divisor
self.denom=denom/divisor
else:
self.nom=nom
self.denom=denom
def __add__(self,element2):
denom=self.denom*element2.denom
nom=self.denom*element2.nom+self.nom*element2.denom
divisor=gcd(nom,denom)
nom=nom/divisor
denom=denom/divisor
return Rationals(nom,denom)
def __mul__(self,element2):
nom=self.nom*element2.nom
denom=self.denom*element2.denom
divisor=gcd(nom,denom)
nom=nom/divisor
denom=denom/divisor
return Rationals(nom,denom)
Now if I type in RR = PolynomialRing(Rationals,'y') I get an error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-112-6f1923f0a0bd> in <module>
----> 1 RR = PolynomialRing(Rationals,'y')
/usr/lib/python3/dist-packages/sage/rings/polynomial/polynomial_ring_constructor.py in PolynomialRing(base_ring, *args, **kwds)
553 """
554 if not ring.is_Ring(base_ring):
--> 555 raise TypeError("base_ring {!r} must be a ring".format(base_ring))
556
557 n = -1 # Unknown number of variables
TypeError: base_ring <class '__main__.Rationals'> must be a ring
**Note that this is only an example, not my real use case.** Of course, I could use QQ in sagemath, but I consider a more complex ring which does not exist in sagemath.
*How do I tell sage that I am confident that my domain is actually a ring?*awengFri, 23 Dec 2022 09:32:32 +0100https://ask.sagemath.org/question/65472/Why does elimination_ideal not work here?https://ask.sagemath.org/question/64565/why-does-elimination_ideal-not-work-here/ from sage.all import *
p = 1125899906842679
R = PolynomialRing(GF(p), 'x,y')
R.inject_variables()
I = Ideal(3*x**4 + 740736*x**2 + 4854540*x + 1125884665458743, -x**3 + y**2 + 1125899906719223*x + 1125899906438134)
J = I.elimination_ideal(y)
Here, elimination_ideal leads to an error. I have no clue why. For other examples, like other finite fields, it works. Has someone an idea, why?SiggiSat, 22 Oct 2022 15:50:06 +0200https://ask.sagemath.org/question/64565/How to compute such resultant?https://ask.sagemath.org/question/64188/how-to-compute-such-resultant/I need to compute such resultant:
<img src="https://latex.codecogs.com/svg.image?f(x)&space;=&space;{Res}_y&space;({A}_1&space;(y),&space;{C}_0&space;(x)&space;+&space;y{C}_1&space;(x))" title="https://latex.codecogs.com/svg.image?f(x) = {Res}_y ({A}_1 (y), {C}_0 (x) + y{C}_1 (x))" />
Where <img src="https://latex.codecogs.com/svg.image?{A}_1,&space;{C}_0,&space;{C}_1&space;" title="https://latex.codecogs.com/svg.image?{A}_1, {C}_0, {C}_1 " /> - polynomials over Z.
How can i do this in sage?DreDdMon, 26 Sep 2022 19:00:28 +0200https://ask.sagemath.org/question/64188/All the solutions of a polynomial system over a finite ringhttps://ask.sagemath.org/question/62787/all-the-solutions-of-a-polynomial-system-over-a-finite-ring/Let $E$ be a finite list of polynomial equations with variables $t_0, \dots, t_r$ over the finite ring of integers modulo $n$ (for some $n$). We can compute the Groebner basis as follows:
ZN=Integers(n)
R=PolynomialRing(ZN,r,"t")
R.inject_variables()
Id=R.ideal(E)
G=Id.groebner_basis()
Usually, over a field and if `Id.dimension()=0` then we can get all the solutions by `Id.variety()`. But here the dimension is not necessarily $0$ and moreover it is not over a field but a ring, the finite ring of integers modulo $n$. By finiteness of the ring, there still have finitely many solutions. How to get them all?
*Example*: $n=248832$, $r=10$ and:
sage: G
[t4*t7, t7*t8, t7*t9, t0, t1, t2, t3 + 248831*t4, 2*t4, t5 + 248783*t7, t6 + 11*t7, 9*t7, 4*t8 + 248828*t9, 16*t9]Sébastien PalcouxSat, 11 Jun 2022 12:47:46 +0200https://ask.sagemath.org/question/62787/How to make a list of polynomials callable?https://ask.sagemath.org/question/61951/how-to-make-a-list-of-polynomials-callable/A polynomial is callable:
sage: R=PolynomialRing(QQ,5,"x")
sage: R.gens()
(x0, x1, x2, x3, x4)
sage: f=x0*x1-x3
sage: f
x0*x1 - x3
sage: f(1,1,1)
0
but a list of polynomial is not:
sage: L=[x0*x1, x2, x3*x4]
sage: L(1,1,1,1,1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-7ed7fddd166b> in <module>
----> 1 L(Integer(1),Integer(1),Integer(1),Integer(1),Integer(1))
TypeError: 'list' object is not callable
**Question**: How to make a list of polynomials callable?
I would like a function `MakeCallable` as follows:
sage: def MakeCallable(L):
....: ....
....: return fL
where `fL` would be as follows (here `L=[x0*x1, x2, x3*x4]`):
sage: def fL(x0, x1, x2, x3, x4):
....: return [x0*x1, x2, x3*x4]Sébastien PalcouxWed, 13 Apr 2022 15:26:17 +0200https://ask.sagemath.org/question/61951/How do I truncate multivariate polynomials?https://ask.sagemath.org/question/61763/how-do-i-truncate-multivariate-polynomials/ Say that I have a polynomial ring
` R.<a,b,c>=PolynomialRing(QQ)`
How do a get the part of a polynomial P where the sum of degree in a,b, and c are less than a given number N? If P were a univariate polynomial, this could be done with P[:N].
Thank you in advance!
mcmugWed, 30 Mar 2022 04:42:32 +0200https://ask.sagemath.org/question/61763/Determinant and missing denominatorhttps://ask.sagemath.org/question/61686/determinant-and-missing-denominator/There is a problem in the following computation, some denominators are missing. It is computing the determinant of a matrix whose entries have some 1/x_i everywhere, but SageMath 9.2 provides a polynomial result (i.e. without denominators).
sage: M1=identity_matrix(2)
sage: M2=matrix([[1,1],[1,1]])
sage: M3=matrix([[1,1],[1,1]])
sage: M4=matrix([[1,1],[1,1]])
sage: M5=matrix([[2,1],[1,2]])
sage: M6=matrix([[0,3],[3,1]])
sage: M7=matrix([[3,1],[1,2]])
sage: L=[M1,M2,M3,M4,M5,M6,M7]
sage: var('x2,x3,x4,x5,x6,x7')
sage: dim=[1,x2,x3,x4,x5,x6,x7]
sage: M=sum((L[i].tensor_product(L[i])).tensor_product(L[i])/(dim[i]) for i in range(7))
sage: M.determinant().denominator()
1
sage: (M.determinant()).factor()
(216*x2*x5^3 + 216*x3*x5^3 + 216*x4*x5^3 + 729*x5^4 - 2583*x2*x5^2*x6 - 2583*x3*x5^2*x6 - 2583*x4*x5^2*x6 - 7560*x5^3*x6 - 19872*x2*x5*x6^2 - 19872*x3*x5*x6^2 - 19872*x4*x5*x6^2 - 81270*x5^2*x6^2 + 91125*x2*x6^3 + 91125*x3*x6^3 + 91125*x4*x6^3 + 204120*x5*x6^3 + 531441*x6^4 + 1833*x2*x5^2*x7 + 1833*x3*x5^2*x7 + 1833*x4*x5^2*x7 + 7344*x5^3*x7 - 12438*x2*x5*x6*x7 - 12438*x3*x5*x6*x7 - 12438*x4*x5*x6*x7 - 45363*x5^2*x6*x7 - 36963*x2*x6^2*x7 - 36963*x3*x6^2*x7 - 36963*x4*x6^2*x7 - 305424*x5*x6^2*x7 + 216513*x6^3*x7 + 4600*x2*x5*x7^2 + 4600*x3*x5*x7^2 + 4600*x4*x5*x7^2 + 24990*x5^2*x7^2 - 12115*x2*x6*x7^2 - 12115*x3*x6*x7^2 - 12115*x4*x6*x7^2 - 75320*x5*x6*x7^2 - 240570*x6^2*x7^2 + 3375*x2*x7^3 + 3375*x3*x7^3 + 3375*x4*x7^3 + 34000*x5*x7^3 - 37125*x6*x7^3 + 15625*x7^4 + 312*x2*x5^2 + 312*x3*x5^2 + 312*x4*x5^2 + 1080*x5^3 - 774*x2*x5*x6 - 774*x3*x5*x6 - 774*x4*x5*x6 - 1263*x5^2*x6 - 4572*x2*x6^2 - 4572*x3*x6^2 - 4572*x4*x6^2 - 22536*x5*x6^2 - 13851*x6^3 + 1658*x2*x5*x7 + 1658*x3*x5*x7 + 1658*x4*x5*x7 + 7497*x5^2*x7 - 3050*x2*x6*x7 - 3050*x3*x6*x7 - 3050*x4*x6*x7 - 6256*x5*x6*x7 - 45711*x6^2*x7 + 1900*x2*x7^2 + 1900*x3*x7^2 + 1900*x4*x7^2 + 15400*x5*x7^2 - 5275*x6*x7^2 + 9375*x7^3 + 104*x2*x5 + 104*x3*x5 + 104*x4*x5 + 390*x5^2 - 191*x2*x6 - 191*x3*x6 - 191*x4*x6 - 184*x5*x6 - 1710*x6^2 + 257*x2*x7 + 257*x3*x7 + 257*x4*x7 + 1632*x5*x7 + 193*x6*x7 + 1500*x7^2 + 8*x2 + 8*x3 + 8*x4 + 40*x5 + 19*x6 + 75*x7 + 1)*(27*x5^2 + 108*x5*x6 - 729*x6^2 + 120*x5*x7 + 135*x6*x7 + 125*x7^2 + 12*x5 - 9*x6 + 25*x7 + 1)^2
Below the entries of the matrix M:
sage: [[M[i][j] for j in range(8)] for i in range(8)]
[[1/x2 + 1/x3 + 1/x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4/x7],
[1/x2 + 1/x3 + 1/x4 + 1/x5 + 27/x6 + 1/x7,
1/x2 + 1/x3 + 1/x4 + 2/x5 + 9/x6 + 2/x7,
1/x2 + 1/x3 + 1/x4 + 2/x5 + 9/x6 + 2/x7,
1/x2 + 1/x3 + 1/x4 + 4/x5 + 3/x6 + 4/x7,
1/x2 + 1/x3 + 1/x4 + 2/x5 + 9/x6 + 2/x7,
1/x2 + 1/x3 + 1/x4 + 4/x5 + 3/x6 + 4/x7,
1/x2 + 1/x3 + 1/x4 + 4/x5 + 3/x6 + 4/x7,
1/x2 + 1/x3 + 1/x4 + 8/x5 + 1/x6 + 8/x7 + 1]]Sébastien PalcouxSun, 27 Mar 2022 06:37:35 +0200https://ask.sagemath.org/question/61686/Coefficients of symmetric polynomialshttps://ask.sagemath.org/question/61500/coefficients-of-symmetric-polynomials/Hi everyone,
I want to get the coefficients of symmetric polynomials, and then make them a vector. I tried the following code:
Sym = SymmetricFunctions(QQ)
e = Sym.elementary()
g = e[2, 1] - 3*e[3]
g.coefficients()
The output is `[1, -3]`, but my desired result is `[0, 1, -3]`, where the zero is the coefficient of `e[1, 1, 1]`.
I found this question [get the coefficients from the polynomial](https://ask.sagemath.org/question/26907/get-the-coefficients-from-the-polynomial/), but it seems `.coefficients(sparse=False)` and `.list()` only work for the univariate polynomial ring.
Thank you in advance for your answer and comments!
Edit:
I would like to make some clarification about the desired result. What I want is a vector of dimension `p(n)` where `p` is the partition function. And each of its components is the coefficient of `g` under the basis `e(part)`, where `part` ranges over all the partitions of `n`.timaeusMon, 14 Mar 2022 17:07:30 +0100https://ask.sagemath.org/question/61500/Partial evaluation of a MV Polynomial.https://ask.sagemath.org/question/61402/partial-evaluation-of-a-mv-polynomial/I have a polynomial defined as:
q = next_prime(2^128)
P.< x1, x2, x3, x4, x5> = GF(q)[]
p = (x1*x2) + (x3*x4)
I would like to obtain the resulting polynomial by partially evaluating by some variables.
Example partial polynomial p' generated by evaluating p at x2 = 2:
p' = (2*x1) + (x3*x4)
Is there a way to accomplish this?cryptoqsSat, 05 Mar 2022 15:29:56 +0100https://ask.sagemath.org/question/61402/Polynomial multiplication using the DFT?https://ask.sagemath.org/question/61356/polynomial-multiplication-using-the-dft/How to do [polynomial multiplication using the discrete Fourier transform](https://brilliant.org/wiki/discrete-fourier-transform/#convolution-and-polynomial-multiplication) in SageMath?rburingWed, 02 Mar 2022 14:47:10 +0100https://ask.sagemath.org/question/61356/Solve much slower than Mathematica for simple systemhttps://ask.sagemath.org/question/61202/solve-much-slower-than-mathematica-for-simple-system/Mathematica solves the following system of multivariate polynomials almost instantaneously while sagemath takes around 10 seconds. Is there any way to speed up solve?
vars('a15, x13_14, a4, a11, a0, x14_15, x11_13, x5_5, x9_12, a5, a12, x3_4, a1, x7_7, x11_14, x12_15, x5_6, x4_4, x9_9, a6, a13, x3_5, a2, x10_10, x7_8, x6_6, x5_7, x12_12, x8_8, a7, x3_6, x6_7, x14_14, a9, x15_15, x4_6, x11_11, x8_9, a8, x10_12, a14, x13_13, a3, a10, x4_7, x12_14, x11_12, x13_15, x10_13')
polys = [-x3_4*x9_12, -x10_12*x3_4, -x10_13*x3_4, -x11_12*x3_4, -x11_13*x3_4, -x11_14*x3_4, x3_4^2*x7_7, x7_8*x8_9, -x11_12^2*x8_8, -x12_12*x3_4 + x3_4*x4_4, -x12_14*x3_4 + x3_4*x4_6, -x12_15*x3_4 + x3_4*x4_7, -x13_13*x3_4 + x3_4*x5_5, -x13_14*x3_4 + x3_4*x5_6, -x13_15*x3_4 + x3_4*x5_7, -x14_14*x3_4 + x3_4*x6_6, -x14_15*x3_4 + x3_4*x6_7, -x15_15*x3_4*x7_8 + x3_4*x7_8, x3_4*x3_5*x7_7, x3_4*x3_6*x7_7, a0 - 1, a1 - 1, a2 - 1, a3 - 1, a4*x4_4 - 1, a5*x5_5 - 1, a6*x6_6 - 1, a7*x7_7 - 1, a8*x8_8 - 1, a9*x9_9 - 1, a10*x10_10 - 1, a11*x11_11 - 1, a12*x12_12 - 1, a13*x13_13 - 1, a14*x14_14 - 1, a15*x15_15 - 1]
vs = [a15, x13_14, a4, a11, a0, x14_15, x11_13, x5_5, x9_12, a5, a12, x3_4, a1, x7_7, x11_14, x12_15, x5_6, x4_4, x9_9, a6, a13, x3_5, a2, x10_10, x7_8, x6_6, x5_7, x12_12, x8_8, a7, x3_6, x6_7, x14_14, a9, x15_15, x4_6, x11_11, x8_9, a8, x10_12, a14, x13_13, a3, a10, x4_7, x12_14, x11_12, x13_15, x10_13]
%time solve(polys, *vs)
This takes about 10 seconds
dddFri, 18 Feb 2022 19:57:18 +0100https://ask.sagemath.org/question/61202/Using symmetric function package and multiplication in sagemathhttps://ask.sagemath.org/question/61077/using-symmetric-function-package-and-multiplication-in-sagemath/I am having a problem working in SageMath with the following series. In Maple, I could define
$$n(d):= \sum_{k=1}^{d} \operatorname{schur}((k,1^{d-k}))\prod_{\square \in (k,1^{d-k})} \, G(c(\square)h) \tag{*}$$
where
- $\operatorname{schur}$ is the usual schur function
I have created using the character formula,
- $G(h)$ is a series in $h$,
- the $c(\square)$ is the content of the Young tableaux.
For example for $d=3$ it can be read as follows
$$
\operatorname{schur}([1,1,1]) \, G(h) \, G(2h)
- \operatorname{schur}([2,1]) \, G(h) \, G(-h)
+ \operatorname{schur}([3]) \, G(2h) \, G(h)
$$
I wanted to do a similar thing in SageMath with Jack polynomials instead of Schur polynomials.
Hence I defined
Sym = SymmetricFunctions(QQ)
JJ = Sym.jack(t=1).J()
s = Sym.schur()
I can see that I have defined the symmetric function over the field of rationals.
Even when I define a new variable in Sage with `var('h')` I cannot
multiply `JJ[2,1]` and `h` -- it gives an error -- hence I cannot
compute $(*)$ with Jack polynomials in SageMath.
I am sure there is a way around. Please let me know.AnupamsageSun, 13 Feb 2022 04:12:01 +0100https://ask.sagemath.org/question/61077/How can I easily create and handle polynomials with symbolic coefficients?https://ask.sagemath.org/question/60439/how-can-i-easily-create-and-handle-polynomials-with-symbolic-coefficients/ I would like to create polynomial functions with symbolic (yet unknown) coefficients, like:
p(x)=a*x^5 + b*x^4 + c*x^3 + d*x^2+e*x+f
Then I would like to experiment with the degree and thus the number of coefficients, for example:
p(x)=a*x^7 + b*x^6 + c*x^5 + d*x^4+e*x^3+f*x^2+g*x+h
The problem is I always have to explicitely declare the coefficients, as variables, like:
var("a b c d e f g h")
So I should always have to enumerate them by hand.
Isn't exist some automatism to do this? For example:
Polynomial(x,degree=7)
and it would return
c0*x^7 + c1*x^6 + c2*x^5 + c3*x^4+c4*x^3+c5*x^2+c6*x+c7
Sometimes I also would like to query the coefficients, to solve an equation system, which contains those coefficients:
p(x)=a*x^7 + b*x^6 + c*x^5 + d*x^4+e*x^3+f*x^2+g*x+h
eq=[
derivative(p(x),x).subs(x=0)==0,
derivative(p(x),x,2).subs(x=0)==0,
p(x=0)==0,
p(x=x0)==1,
p(x=1)==1+z,
derivative(p(x),x).subs(x=1)==0,
derivative(p(x),x,2).subs(x=1)==0,
derivative(p(x),x).subs(x=x0)==1
]
s=solve(eq,a,b,c,d,e,f,g,h)
Again, when calling solve(), I have to explicitly enumerate the coefficients again, instead of some shortcut, like:
s=solve(eq,p(x).coefficients())
When I try to experiment with the degree of my polynomial p(x), to try out a higher or lower degree, and with more or less equations in the system, I always have to declare my coefficients as vars again and again, which is very annoying.
Furthermore when I tried to query coefficients by, eg.:
p.coefficient(x)
or
p.coefficient(x^3)
The first returns "g" as the coefficient, which is good. But how can I access or query the "free" coefficient, "h" which isn't multiplied by x?
p.coefficient(0)
Doesn't return anything. If it would return the free coeff, then I could get the coefficients by calling a map() with lambda function.
KonstantinSat, 25 Dec 2021 23:19:49 +0100https://ask.sagemath.org/question/60439/`is_homogeneous` ignoring orderhttps://ask.sagemath.org/question/59573/is_homogeneous-ignoring-order/It seems that for certain coefficient ring, `is_homogeneous` does not take into consideration the order. On the other hand, `homogeneous_components` does respect the order, which leads to inconsistent results...
sage: R.<x,y> = PolynomialRing(QQbar, order=TermOrder("wdeglex", [1,2]))
sage: (x^2+y).is_homogeneous()
False
sage: (x^2+y).homogeneous_components()
{2: x^2 + y}
8d1hTue, 02 Nov 2021 23:35:07 +0100https://ask.sagemath.org/question/59573/Polynomial Substitution for only higher termshttps://ask.sagemath.org/question/59133/polynomial-substitution-for-only-higher-terms/ I'm dealing with elliptic curves in SAGE. Say the elliptic curve I have is $y^2=x^3+x$ working over GF(43) and I have a polynomial expression in x and y:
$$y^2 + xy + 1.$$
I want to be able to substitute $y^2=x^3+x$ to get $(x^3+x)+xy+1$. How do I do this?RKnebelThu, 23 Sep 2021 20:41:09 +0200https://ask.sagemath.org/question/59133/I've got a big expression I need to dissect a certain wayhttps://ask.sagemath.org/question/57982/ive-got-a-big-expression-i-need-to-dissect-a-certain-way/ I've got a BIG polynomial (7 indeterminates, total degree 12), and I want to collect all the terms therein that contain only EVEN powers of all the indeterminates. Is there any reasonably simple way to do this? By "simple," I mean short of traversing the whole expression tree, testing each term to see if it contains only even powers, and collecting them one-by-one in a list (which, BTW, I also don't really know how to do)! If it makes any difference, I haven't been using the sage.rings.polynomial module, just generic Sage expressions.Tim02130Mon, 12 Jul 2021 22:11:18 +0200https://ask.sagemath.org/question/57982/why can't I compute the zeros of an integer polynomial using solve()?https://ask.sagemath.org/question/57833/why-cant-i-compute-the-zeros-of-an-integer-polynomial-using-solve/ This works fine, producing complex roots:
x=var('x')
f=x+x**2+x**3-100
z=solve(f==0,x)
this also works fine:
R.<x>=ZZ[]
f=x+x**2+x**3-100
f.roots()
but this seems to run forever without error message and I don't understand why:
x=var('x',domain=ZZ)
f=x+x**2+x**3-100
z=solve(f==0,x)
can anyone explain or tell me where to start reading to understand this behaviour?
dantetanteThu, 01 Jul 2021 08:12:48 +0200https://ask.sagemath.org/question/57833/way to subs var by matrix in polynomialhttps://ask.sagemath.org/question/57660/way-to-subs-var-by-matrix-in-polynomial/HI
What is the best way to substitute to the variables of a polynomial x, y with 2 matrices X, Y
R.<x,y> = QQ[]
p = x^2 + 5*y + 2*x*y + 3*x + y^2
show("p : ",p," \t degre : \t",p.degree(x))
for ex in range(1,p.degree(x)+1) :
coefx=p.coefficient(x^ex)
print(" ex : ",ex," \t coefx : ",coefx)
for ey in range(1,p.degree(x)+1) :
coefy=p.coefficient(y^ey)
print(" ey : ",ey," \t coefy : ",coefy)
#for ey in range(1,p.degree(y)+1) :
# coefy=p.coefficient(y^ex)
# for ex in range(0,coefy.degree(y)+1) :
# coefx=p.coefficient(x^ex)
# print(" ex : ",ex," \t coefx : ",coefx," \t ey : ",ey," \t coefy : ",coefy)
var('x_00,x_01,x_10,x_11',domain='integer')
var('y_00,y_01,y_10,y_11',domain='integer')
X=matrix(SR,[[x_00,x_01],[x_10,x_11]]); Y=matrix(SR,[[y_00,y_01],[y_10,y_11]])
show(X,Y)
#p.subs([x==X,y==Y])ortolljTue, 22 Jun 2021 08:34:49 +0200https://ask.sagemath.org/question/57660/Performance of PolynomialRing evaluationhttps://ask.sagemath.org/question/57281/performance-of-polynomialring-evaluation/ Hi,
I am having a performance issue with the evaluation of a PolynomialRing which I find suspicious. I would like to understand if I am doing things correctly here.
The polynomial is calculated as a function of a set of matrices, whose logic is not relevant here.
In particular, the polynomial I am benchmarking has 16 variables and is 15.000 terms long, which means it has (on average) 120.000 multiplications and 15.000 sums for a total of 135.000 operations.
On my laptop, a single evaluation takes 4 seconds, in other words a single operation every 30 us.
This seems weird, given the speed of modern computers and especially compared to the speed of calculating the polynomial - the *representativeSetPoly* in the code. Indeed I was expecting that part to be slower than the verification.
Is there a way I can evaluate the polynomial in a more efficient way (the verification part in the code)? I am attaching a code snippet to reproduce the issue
Thanks in advance!
import time
import numpy as np
from sage.all import *
from tqdm import tqdm
WORKLOAD_DIM = 16
PRIME_NUM = 109211909
workload = np.random.randint(2, size=(2, 50, WORKLOAD_DIM), dtype=np.int8)
variables = ["x" + str(counter) for counter in range(1, WORKLOAD_DIM + 1)]
P = PolynomialRing(GF(PRIME_NUM), variables, order='lex')
def calculateRowPoly(rowP):
poly = 1
for index, elem in enumerate(rowP):
rowMask = [0] * WORKLOAD_DIM
rowMask[index] = 1
poly = poly * (1 - P.monomial(*rowMask) * elem)
return poly
#=== Start finding solution (the polynomial)
representativeSetPoly = 0
t0solve = time.perf_counter()
for row in tqdm(workload[1]):
representativeSetPoly = representativeSetPoly + calculateRowPoly(row)
t1solve = time.perf_counter()
print(f"== It took {t1solve - t0solve} seconds to find a solution!")
#=== End finding solution
print(type(representativeSetPoly))
#=== Start verification
numOrthoVecVerifier = 0
t0verify = time.perf_counter()
for vec in tqdm(workload[0]):
numOrthoVecVerifier += representativeSetPoly(*vec)
t1verify = time.perf_counter()
print(f"== It took {t1verify - t0verify} seconds to verify the solution")
#=== End verification
27amWed, 26 May 2021 10:12:47 +0200https://ask.sagemath.org/question/57281/how do I compute a polynomial pseudo-remainder in sage?https://ask.sagemath.org/question/57266/how-do-i-compute-a-polynomial-pseudo-remainder-in-sage/ Most symbolic algebra systems provide a function, typically called "prem" or something like that, to compute the pseudo-remainder of two polynomials. Sage does provide other elementary functions for manipulating polynomials, e.g. "factor", but does not seem to provide this one. Perhaps something could be done by using the sage.rings.polynomial package, but that would be overkill for my immediate problem. Is there ANY way to do this simply?Tim02130Tue, 25 May 2021 18:21:41 +0200https://ask.sagemath.org/question/57266/What implementation does sage use for solve?https://ask.sagemath.org/question/56730/what-implementation-does-sage-use-for-solve/What algorithm does sage use when you solve polynomials with the solve() function? MathAllOverThePlaceMon, 19 Apr 2021 20:48:21 +0200https://ask.sagemath.org/question/56730/How to find the degree of a polynomialhttps://ask.sagemath.org/question/56440/how-to-find-the-degree-of-a-polynomial/ Is there a function that takes in a polynomial and returns its degree? For example: suppose we have the ring `R = PolynomialRing(ZZ, 'x')`, and the polynomial `p = (x-1)*(x-2)`. The degree function I'm looking for should return 2 when applied to `p`. Does such a function exist??Blob1234Tue, 30 Mar 2021 23:05:53 +0200https://ask.sagemath.org/question/56440/Referring to elements of a polynomial ring as integers.https://ask.sagemath.org/question/56295/referring-to-elements-of-a-polynomial-ring-as-integers/Suppose I create a polynomial ring:
F.<a> = GF(2^4)
R.<x> = PolynomialRing(F)
The syntax above is slightly incorrect, I couldn't figure out how to preserve the brackets around the 'a' and 'x'.
For the work I'm doing the references typically refer to elements of the ring in 4 different manners (within the same reference). An example of this is the BBC white paper, "Reed-Solomon Error Correction" by C. K. P. Clarke.
They use index form:
a^11
They use polynomial form:
a^3 + a^2 + a
They use binary form:
1110
They use decimal form:
14
I would like to map what they call decimal form to the polynomial form, because it's very convenient. For instance in the previously mentioned paper they encode a message: x^10 + 2*x^9 + 3*x^9 + ... 10*x + 11.
In sagemath this would be:
x^10 + a*x^9 + a^4*x^8 + ... a^9*x + a^7
The decimal form is very helpful for me. My eventual goal is to use sagemath to implement a Reed-Solomon encoder/decoder, and write code that parses that implementation and creates System Verilog code that gets implemented in an ASIC (application specific integrated circuit)jderyckSun, 21 Mar 2021 10:16:30 +0100https://ask.sagemath.org/question/56295/Converting multivariable polynomial with complex coefficients to a polynomial with integer coefficientshttps://ask.sagemath.org/question/55261/converting-multivariable-polynomial-with-complex-coefficients-to-a-polynomial-with-integer-coefficients/If we make a polynomial involving $\sqrt{-2}$ like this
X = PolynomialRing(CC, names='X').gen()
r0 = (X**2 + 2).roots()[0][0]
A,B = PolynomialRing(CC, 2, names='A,B').gens()
poly = (A + B + r0)*(A + B - r0)
we get $poly = A^2 + 2.00AB + B^2 + 2.00.$
How can this be changed into a polynomial with integer coefficients ?
If we had a univariate polynomial we could do this by mapping list(poly) to a list of integers and then defining a new polynomial with those. But this approach can't be translated directly to multivariable polynomials.david marquisWed, 13 Jan 2021 18:03:37 +0100https://ask.sagemath.org/question/55261/Indexing variables in a list comprehensionhttps://ask.sagemath.org/question/54503/indexing-variables-in-a-list-comprehension/ Suppose I create the polynomial ring R = PolynomialRing(QQ, ['lambda%s'%i for i in [1 .. g]] + ['psi%s'%i for i in [1 .. n]]).
If I want to create a list comprehension which creates a list of perhaps all the lambdas, what is the notation used at the beginning of the list comprehension?
i.e. [lambdai for i in [1 .. g]]. Laughematician760Tue, 01 Dec 2020 23:03:40 +0100https://ask.sagemath.org/question/54503/