ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 13 Oct 2020 21:57:27 -0500substituting vars for a poly quotient in a list comprehension blows uphttps://ask.sagemath.org/question/53896/substituting-vars-for-a-poly-quotient-in-a-list-comprehension-blows-up/ If I run this but don't substitute the a and b for the polynomials:
a = 3*x^2 + 2*x + 1
b = 5*x^3 - 2*x^2 + 3
c = [((3*x^2 + 2*x + 1)/(5*x^3 - 2*x^2 + 3)).n() for x in [100..30000,step=100]]
for num in c:
print(num)
I get a numeric list, as expected.
If I use f = [(a/b) for x in [100..30000,step=100]] however,
I only get variables in x, all the same: (3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000)/(5.00000000000000*x^3 - 2.00000000000000*x^2 + 3.00000000000000)
And if I try (a/b).n(), I get an error: TypeError: unable to coerce to a ComplexNumber: <class 'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'>
What's going wrong?
cybervigilanteTue, 13 Oct 2020 21:57:27 -0500https://ask.sagemath.org/question/53896/Quotient group for matrix groups?https://ask.sagemath.org/question/53099/quotient-group-for-matrix-groups/Is there a way to create a quotient group for groups in the class MatrixGroup? The following use of .quotient(H) gives a NotImplementedError.
p=3
F=FiniteField(p)
t1=matrix(F,3,[1,0,1,0,1,0,0,0,1])
t2=matrix(F,3,[1,0,0,0,1,1,0,0,1])
t3=matrix(F,3,[1,0,0,0,1,0,0,1,1])
G=MatrixGroup([t1,t2,t3])
opts=[]
for a in G:
h=a*t1*a^-1
if h not in opts:
opts.append(h)
H=G.subgroup(opts)
print(H.order())
Q=G.quotient(H)
ndhanson3Wed, 19 Aug 2020 01:26:15 -0500https://ask.sagemath.org/question/53099/how to evaluate a polynomial in a quotient ring ?https://ask.sagemath.org/question/52596/how-to-evaluate-a-polynomial-in-a-quotient-ring/I define a polynomial ring and its quotient by an ideal:
sage: F = ZZ.quo(3*ZZ); F
Ring of integers modulo 3
sage: A.<X, Y, Z> = PolynomialRing(F); A
Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
sage: R.<x, y, z> = A.quotient(ideal(X^2 - 1, Y^2 - 1, Z^2 - 1)); R
Quotient of Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
by the ideal (X^2 + 2, Y^2 + 2, Z^2 + 2)
I define an element in this quotient ring:
sage: f = x*y*z; f
x*y*z
sage: f.parent()
Quotient of Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
by the ideal (X^2 + 2, Y^2 + 2, Z^2 + 2)
I want to evaluate this element at $(x, y, z) = (2, 3, 4)$.
I tried this, and got this error message:
sage: f(2, 3, 4)
Traceback (most recent call last)
...
TypeError: 'QuotientRing_generic_with_category.element_class' object is not callable
How can I calculate `f(2, 3, 4)` with Sage?andriamTue, 21 Jul 2020 05:22:20 -0500https://ask.sagemath.org/question/52596/Basis for such a quotient vector spacehttps://ask.sagemath.org/question/51550/basis-for-such-a-quotient-vector-space/Hi all,
Here is my code:
`A = matrix(QQ, 4, 3, [1, 2, 3, 5, 10, 15, 0, 0, 0, -2, -4, -6])`
`B = matrix(QQ, 5, 4, [0, 2, 7, 5, 0, 0, 0, 0, 0, -2, -7, -5, 0, 4, 14, 10, 0, 6, 21, 15])`
`W = A.transpose().image()`
`V = B.right_kernel()`
`V/W`
This way W is the range of the linear map
$$A:\mathbb{Q}^3\longrightarrow\mathbb{Q}^4,$$
V is the nullspace of
$$B:\mathbb{Q}^4\longrightarrow\mathbb{Q}^5,$$
Since BA=0, W is a subspace of V.
and the command V/W returns in particular the dimension of the quotient vector space V/W which is equal to 2.
What I want is a basis of V/W, i.e. 2 vectors of $\mathbb{Q}^4$ which are in V,
in the form of a 2x4 matrix
the same way V.basis_matrix() returns a basis for V.
How can I do this?
Thanks!BostonMon, 25 May 2020 12:26:58 -0500https://ask.sagemath.org/question/51550/How to base change from a PolynomialRing to that Ring with one variable evaluated, i.e., from Q[x,y] to Q[x,y]/(x=0) = Q[y]?https://ask.sagemath.org/question/50978/how-to-base-change-from-a-polynomialring-to-that-ring-with-one-variable-evaluated-ie-from-qxy-to-qxyx0-qy/I am trying to base change a Laurent series ring element from its base ring, Q[u1, u2, u3], to a quotient of its base ring, Q[u2, u3], but I am quite confused in forming this quotient. My setting is this:
S.<u1,u2,u3> = QQ[]
L.<z> = LaurentSeriesRing(S);
f = -4*z - 4/5*u1*z^5 + (-4/9*u1^2 - 8/9*u2)*z^9 + (-4/13*u1^3 - 24/13*u1*u2 - 12/13*u3)*z^13 + (-4/17*u1^4 - 48/17*u1^2*u2 - 24/17*u2^2 - 48/17*u1*u3 + 16/17*u1 + 16/17*u2 + 16/17*u3 + 16/17)*z^17 + O(z^20)
In other words, I wish to set u1 = 0, and look at f over that ring. I tried the following two things, which spit out f unchanged.
f.change_ring(S.quo(u1))
R = S.quotient(u1)
f.change_ring(R)
I also tried the following which gives an attribute error:
f.reduce(u1)
I am completely stuck and would deeply appreciate any help. I would also like to eventually set u2 = 0 and look at f over that ring, which I mention at the off chance that this changes the answer at all.masseygirlThu, 23 Apr 2020 20:00:38 -0500https://ask.sagemath.org/question/50978/center lift of a polynomial?https://ask.sagemath.org/question/49613/center-lift-of-a-polynomial/Hello! I am trying to code up the NTRU example in Hoffstein, Pipher and Silverman. Anyone know if the "center lift" of a polynomial is implemented in Sage? I am working the quotient ring:
Z_7[x] / x^5 - 1
I have a(x) = 5 + 3x - 6x^2 + 2x^3 + 4x^4
The center lift takes this a polynomial with coefficients in the range of - 7/2 < coeff <= 7/2.
Thus a(x) -> -2 + 3x + x^2 + 2x^3 - 3x^4
But what I get is:
N = 5
q = 7
P.<x> = GF(q)[]
Q = QuotientRing(P, x^N - 1)
a = 5 + 3*x - 6*x^2 + 2*x^3 + 4*x^4
aa = Q(a)
aa.lift()
4*x^4 + 2*x^3 + x^2 + 3*x + 5
Any thoughts? I guess I could write my own function to do the center lifting...
Thanks!
Susansusan_in_AnnapolisMon, 20 Jan 2020 18:55:52 -0600https://ask.sagemath.org/question/49613/subquotient of modulehttps://ask.sagemath.org/question/48198/subquotient-of-module/how can I take a quotient of a submodule? I was expecting the following to work:
<pre><code>sage: M = CombinatorialFreeModule(QQ, [1,2], prefix='x'); x = M.basis()
sage: A = M.submodule([x[2]])
sage: A.quotient_module(A)
Free module generated by {1} over Rational Field
</code></pre>
Which is clearly taking the quotient over the ambient space of `A` and not the image
<pre><code>sage: A.quotient_module(A) == M.quotient_module(A)
True</code></pre>
Replacing `A` with `A.lift.image()` is the same.
EDIT: well, reading now in `Modules.WithBasis.FiniteDimensional.ParentMethods.quotient_modules` this is simply a call to `QuotientModuleWithBasis(A,category)` which will infer the parent of `A`.
As a side observation, I find it disturbing that there is not even a check that `submodule` is indeed a submodule of `self` in that call.heluaniSat, 05 Oct 2019 20:02:20 -0500https://ask.sagemath.org/question/48198/Determinants of Matrices with Symmetric Functionshttps://ask.sagemath.org/question/47774/determinants-of-matrices-with-symmetric-functions/I'm interested in calculating the determinant of the matrix $ A = (a_{i+j})$ for $0\leq i,j\leq n$ in which $a_{k} = \frac{h_k}{e_k}$ where $h_k, e_k$ are the homogeneous (elementary, resp.) symmetric functions of degree $k$. I would like to express the numerator of $\det(A)$ in terms of monomial symmetric functions.
I have written some code that I think does the job, but it seems an incredibly hacky way of doing it in my opinion. Since I am quite new to sage I was wondering whether someone might be able to take a look at what I've done and suggest a more sage-like way to tackle this problem? My code is below.
I define a set of functions:
# set up two matrices containing symbolic functions hh(i+j), ee(i+j), which are later replaced with symmetric functions h and e
def heMatrices(N):
hh = function('hh')
ee = function('ee')
H = matrix(SR,N,N,lambda i,j:hh(i+j))
E = matrix(SR,N,N,lambda i,j:ee(i+j))
return H,E
# Pointwise divides two matrices (a bit like Hadamard division??)
def elementwiseDivision( M, N ):
assert( M.parent() == N.parent() )
nc, nr = M.ncols(), M.nrows()
A = copy( M.parent().zero() )
for r in range(nr):
for c in range(nc):
A[r,c] = M[r,c] / N[r,c]
return A
# extracts numerator of determinant
def extractNumerator(M):
return det(M).numerator()
# extracts denominator of determinant
def extractDenominator(M):
return det(M).denominator()
# This is dodgy - treates expression as a python string and replaces e(x) with e[x], h(x) with h[x]
def convertToSymmetricString(expr):
st = str(expr)
st = st.replace('(','[')
st = st.replace(')',']')
st = st.replace('ee','e')
st = st.replace('hh','h')
return st
# Puts together the above functions.
def evaluateDeterminant(N):
h,e = heMatrices(N)
A = elementwiseDivision(h,e)
srExpression = extractNumerator(A)
sageExpression = convertToSymmetricString(srExpression)
return sageExpression
Then I open sage in the command line and type the following:
sage: Sym = SymmetricFunctions(QQ)
sage: Sym.inject_shorthands(verbose=False)
sage: ee = evaluateDeterminant(2)
sage: ans = sage_eval(ee, locals=vars())
sage: ans = m(ans)
which returns
2*m[2, 1, 1] + 2*m[2, 2] + 2*m[3, 1] + m[4]
which I believe is what I'm after.WubbaLubbaDubDubFri, 06 Sep 2019 04:24:50 -0500https://ask.sagemath.org/question/47774/Unexpected result: quotient of algebra of free monoid by idealhttps://ask.sagemath.org/question/45824/unexpected-result-quotient-of-algebra-of-free-monoid-by-ideal/I'm hoping to use SAGE to calculate some asymptotic results in a larger problem. Along the way, I ran into some unexpected behavior. In the minimal example below, I am trying to create a simple FreeMonoid and expand it to an Algebra where the following constraint holds: a^2 - 1 == 0.
# Create monoid + corresponding algebra
M.<a,b> = FreeMonoid(2)
F = M.algebra(QQ)
# Create two sided ideal and quotient
I = F*[F(a)^2-F(1)]*F
A = F.quotient(I)
# Returns false
A(a^2) == A(1)
This returns False, and looks like it may be related to an older bug (trac ticket 24808; can't post link b/c new user with low karma). I'm using SageMath version 8.5.
It's quite possible I'm doing something bone-headed; I haven't thought about abstract algebra in over a decade. Any suggestions would be helpful!
Thanks,
Dustin
Dustin01Mon, 18 Mar 2019 13:52:28 -0500https://ask.sagemath.org/question/45824/Quotient of non-commutative ringhttps://ask.sagemath.org/question/45480/quotient-of-non-commutative-ring/ I'm trying to make a non-commutative ring, where X^2 = -1 ; XY = -YX and Y^2 = 0, something like this ;
R[X,Y] / (X^2 + 1 , XY + YX , Y^2)
To get the non-commutative part, I did :
A.<x,y> = FreeAlgebra(QQ,2)
P.<x,y> = A.g_algebra(relations={y*x:-x*y})
What is the next command to have the quotient by (X^2+1 , Y^2) ? Or maybe an other way to build the entire ring, if there exists a simpler method :) thanks !
franslagSat, 16 Feb 2019 14:54:16 -0600https://ask.sagemath.org/question/45480/weird behavior quotient operatorhttps://ask.sagemath.org/question/45099/weird-behavior-quotient-operator/Hello,
i am calculating the quotient of a really big number using the operator //
the fact is: if the big number is in a variable, let's say x, and i write x//2, it won't work (it'll return x/2).
But if i copy/paste the big number and write //2 at the end, it works.
I don't understand it.
I wanted to post a picture as example, but it seems that i need more karma to do it...
so instead i put a copy/paste of the problem at the end of this post. The variable's name is "test", so i first print it, then do the //2; as you can see it doesn't work, i got the same number with /2 at the end. Then i copy/paste the number and use //2 again and here it works. The point is: when i use it in a programm, i can't copy/paste the number, it'll be in a variable. And then it fails.
sage: test
837852367160941686882182203279810821534331590056292182065749220359229900094799322306853693706463088872767820405170018794451898101765853614283153521412505365960228304480760794688517092896652646155467604050167410281621256684893277033624912312765082826592417694451712096609637026970174504593832198908321736540951
sage: test//2
837852367160941686882182203279810821534331590056292182065749220359229900094799322306853693706463088872767820405170018794451898101765853614283153521412505365960228304480760794688517092896652646155467604050167410281621256684893277033624912312765082826592417694451712096609637026970174504593832198908321736540951/2
sage: 83785236716094168688218220327981082153433159005629218206574922035922990009479932230685369370646
....: 30888727678204051700187944518981017658536142831535214125053659602283044807607946885170928966526
....: 46155467604050167410281621256684893277033624912312765082826592417694451712096609637026970174504
....: 593832198908321736540951//2
418926183580470843441091101639905410767165795028146091032874610179614950047399661153426846853231544436383910202585009397225949050882926807141576760706252682980114152240380397344258546448326323077733802025083705140810628342446638516812456156382541413296208847225856048304818513485087252296916099454160868270475AbliaFri, 18 Jan 2019 10:26:41 -0600https://ask.sagemath.org/question/45099/Identity in a quotient Grouphttps://ask.sagemath.org/question/44965/identity-in-a-quotient-group/ Hello everyone, I have the following groups
F3.<a1,b1,a2,b2,a3,b3> = FreeGroup()
H3 = F3.quotient([a1*b1/a1/b1*a2*b2/a2/b2*a3*b3/a3/b3])
Then I inject the variables to $H3$
H3.inject_variables()
Now when every element that I write have parent $H3$, but when I write the word `a1*b1/a1/b1*a2*b2/a2/b2*a3*b3/a3/b3`
this does not return the identity of $H3$, although if I put
a1*b1/a1/b1*a2*b2/a2/b2*a3*b3/a3/b3 == H3.one()
this is true. Does anyone know why this happen and how can I get sage to reduce this word to identity of $H3$?
MarioMTue, 08 Jan 2019 18:03:52 -0600https://ask.sagemath.org/question/44965/Quotient Group constructionhttps://ask.sagemath.org/question/42747/quotient-group-construction/ I have created a group in the category - finite enumerated commutative subgroup. But it doesn't have an option of quotient group ( it has but shows Not Implemented Error)
I wanted to know why implementing a quotient group is not possible if quotient ring is done already?
Actually, I was thinking to implement it myself, but I thought it will be good to ask here first if people have tried that.
Also, does anyone know how I can track the current progress being done in sage.mathjainTue, 26 Jun 2018 19:49:42 -0500https://ask.sagemath.org/question/42747/Examining the quotients of a module $R\times R$ where $R$ is a finite ring.https://ask.sagemath.org/question/41421/examining-the-quotients-of-a-module-rtimes-r-where-r-is-a-finite-ring/I'm new to Sage, and I've been struggling to get started with (what I thought) should be a basic construction.
I have an $8$-element commutative ring $R$ which is constructed as a quotient of a polynomial ring in two variables. I need to examine all of the quotient of the right $R$ module $R\times R$.
I tried to use `M=R^2` and got something that looked promising, but when I tried to use the `quotient_module` method, I kept getting errors. I saw in the docs for that method that quotient_module isn't fully supported, so I started looking at the CombinatorialFreeModule class too.
> Can someone recommend an idiomatic way to accomplish the task?
I have been plagued by NotImplemented errors and a myriad of other error messages every step of the way, even when just attempting to find a method to list all elements of my $8$ element ring. All the examples I've seen really look like they stick to basic linear algebra, or free $\mathbb Z$ modules. I just want to do something similar for my small ring of $8$ elements.
Here's what I've been trying:
k # <- (finite field of size 2)
R.<x,y>=PolynomialRing(k)
S = R.quotient([x^2, x*y, y^3])
list(S) # <-- NotImplementedError("object does not support iteration") I noticed it worked for the univariate case though. What's a good way to recover the elements?
M = S^2
v = M.gens()
M.quotient_module([v[0]]) # <- ValueError("unable to compute the row reduced echelon form") TypeError("self must be an integral domain.")
Had the same problem with a univariate polynomial ring over $F_2$ mod $(x^3)$.
Obviously the messages are informative enough about what they think is wrong. But this seems like such an elementary task... is there some other class that can handle such a construction?rschwiebWed, 07 Mar 2018 08:28:00 -0600https://ask.sagemath.org/question/41421/How can you operate in a quotient of a group finitely presented?https://ask.sagemath.org/question/37511/how-can-you-operate-in-a-quotient-of-a-group-finitely-presented/Hello everyone, I have the following groups
G.<a,b> = FreeGroup()
H = G.quotient([a*b*a.inverse()*b.inverse()])
I would like SAGE to understand the product of to lateral clases in H? It is that possible?
Thanks in advance!NCAThu, 04 May 2017 12:56:13 -0500https://ask.sagemath.org/question/37511/Writing elements as a linear combination in a basis in a quotient ringhttps://ask.sagemath.org/question/33322/writing-elements-as-a-linear-combination-in-a-basis-in-a-quotient-ring/I have an explicit ideal in a multivariable polynomial ring R. I know a priori that the quotient
ring R/I is finite dimensional (as a vector space). In fact I have an explicit basis in R/I. I have all this programmed into sage. Is there a way to find the linear combination for a given element in R/I in the given basis?
example:
sage: R.<e1,e2>=PolynomialRing(QQ)
sage: I = ideal(e1^3 -2 * e2 * e1 +1, e2 * e1^2 - e2^2 - e1)
sage: I.vector_space_dimension()
6
sage: f22= e2^2 - e1; f21 = e2*e1 - 1; f11 = e1^2 - e2; f1= e1; f2 = e2; f0 = 1;
sage: I.reduce(f21*f21)
e1*e2
sage: I.reduce(f21*f21) == f21 + f0
True
I have an ideal I in R and I know that the quotient ring R/I is 6 dimensional over the field. I have the basis
f22,f21,f11,f2,f1,f0 of R/I as a vector space over QQ. I would like to find the structure constants of this finite dimensional algebra. For example compute f21^2 in the quotient ring, and write it in the basis, we get f21^2=f21+f0.
But I only get it by hand and would like to compute it with sage, so that I could get the whole set of structure constants. mathworkerThu, 05 May 2016 14:07:11 -0500https://ask.sagemath.org/question/33322/How to find a particular coset?https://ask.sagemath.org/question/33317/how-to-find-a-particular-coset/I am in the situation where I have groups $A,G$ with $G$ normal in $A$ such that $A/G$ is cyclic. I would like to find the coset of $G$ corresponding to a generator of $A/G$. AsvinWed, 04 May 2016 11:17:55 -0500https://ask.sagemath.org/question/33317/Rings, Ideals, Quotient Rings in Sagehttps://ask.sagemath.org/question/29990/rings-ideals-quotient-rings-in-sage/Hi everybody.
I am new to sage. I want to construct rings, ideals, and quotient rings.
I used Z.IntegerRing() to generate the ring of integers.
Question 1:
Then I used I = Z.ideal(2) to get the ideal generated by 2 (even numbers).
Question: How can I display the Elements. E.g. I(2) does not work in order to display the second element of the ideal.
Question 2:
To generate the quotientring Z/2Z i used S = Z.quotient_ring(I).
What if I want to generate the quotientring 2Z/6Z ? S = I.quotient_ring(J) does not work (I = Z.ideal(2), J = Z.ideal(6).
Thanks for any help
DesperateUserWed, 14 Oct 2015 02:38:47 -0500https://ask.sagemath.org/question/29990/Quotient of Polynomial rings reduction not workinghttps://ask.sagemath.org/question/27068/quotient-of-polynomial-rings-reduction-not-working/<code>
<br>R.<x>=PolynomialRing(QQ)
<br>R.ideal(x^4).reduce(x^8+1)
<br>R.<x>=PolynomialRing(ZZ)
<br>R.ideal(x^4).reduce(x^8+1)
1
x^8 + 1
</code>
Why am I not getting the result 1 in both cases?WizqTue, 09 Jun 2015 08:44:26 -0500https://ask.sagemath.org/question/27068/Mysterious behavior for quotient rings and cover()https://ask.sagemath.org/question/10944/mysterious-behavior-for-quotient-rings-and-cover/I don't understand this:
R.<T,U>=PolynomialRing(QQ)
Q=R.quo((T^2))
pi=Q.cover()
pi(T)
-- returns Tbar
However:
R.<T>=PolynomialRing(QQ)
Q=R.quo((T^2))
pi=Q.cover()
pi(T)
-- returns an error.jeremy9959Sat, 18 Jan 2014 01:49:36 -0600https://ask.sagemath.org/question/10944/preorders and posetshttps://ask.sagemath.org/question/10866/preorders-and-posets/I am looking for a module having to do with preorders (sets with reflexive and transitive relations, also called quasi-orders). I'd like to use a few of the poset methods on preorders, but this doesn't seem to work. That is, I get
Traceback (click to the left of this block for traceback)
...
ValueError: Hasse diagram contains cycles.
I figure that either there is a way to indirectly use the poset methods on preorders more generally, or else someone has implemented the quotient operation. (This turns a preorder (A,\leq) into a poset by taking the quotient under the equivalence relation \equiv on A by a \equiv b iff a \leq b and b \leq a.Larry MossSun, 29 Dec 2013 05:02:55 -0600https://ask.sagemath.org/question/10866/Power of a polynomial mod (n, X^r - 1)https://ask.sagemath.org/question/8742/power-of-a-polynomial-mod-n-xr-1/I need to calculate (X + a)^n mod (n, X^r - 1), where n can be very large.
I use the following code:
R.<x>=PolynomialRing(Integers(n))
pow(x + a, n, X^r - 1)
A better (i.e. faster) solution?
Thanks.mcl1962Mon, 27 Feb 2012 00:39:15 -0600https://ask.sagemath.org/question/8742/