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.Fri, 09 Aug 2024 11:03:33 +0200Subgroups of $\mathbb{Z}^*_n$https://ask.sagemath.org/question/78631/subgroups-of-mathbbz_n/I am trying to write a code using SAGE to find all subgroups of $\mathbb{Z}^*_n$ where the elements of subgroups are elements of $\mathbb{Z}_n$.
To elaborate, when I am using the command .subgroups(), it returns the subgroups in generator-relator form and not as integers. Is there anyway to do it?sagelearnerFri, 09 Aug 2024 11:03:33 +0200https://ask.sagemath.org/question/78631/Is there any way to keep signs when converting from symmetric modular representation to integers?https://ask.sagemath.org/question/76595/is-there-any-way-to-keep-signs-when-converting-from-symmetric-modular-representation-to-integers/ I learned that you can get symmetric representation by using multivariate polynomials, but it seems kinda useless if it won't keep the sign after the change. Is there anyway to preserve the sign?
R = PolynomialRing(GF(5),('x','y'))
M = PolynomialRing(ZZ,('x','y'))
a = M(-2) + M(1)
M(R(-2))
3cjajciaoWed, 20 Mar 2024 19:33:53 +0100https://ask.sagemath.org/question/76595/How to dynamically pass multivariables while constructing a IntegerModRing?https://ask.sagemath.org/question/57562/how-to-dynamically-pass-multivariables-while-constructing-a-integermodring/I want to construct variables from an array of strings and then pass to IntegerModRing
Currently I am hardcoding the variables like below
R.<f1c1,f1c2,f2c1> = IntegerModRing(3^3)[]
R.<f1c1,f1c2,f1c3,f2c1,f3c1> = IntegerModRing(3^4)[]
R.<f1c1,f1c2,f1c3,f1c4,f2c1,f2c2,f3c1,f4c1>
= IntegerModRing(3^5)[]
so on.... 3^6 , 3^7...
I tried like below , but not working for me
xs = ['f1c1','f1c2','f1c3','f1c4','f1c5','f1c6','f2c1','f2c2','f2c3','f3c1','f3c2','f4c1','f5c1','f6c1']
R = IntegerModRing(3^7,names=xs)[]
I want to construct variables from an array of strings and then pass to IntegerModRingSenthilTue, 15 Jun 2021 17:53:20 +0200https://ask.sagemath.org/question/57562/Computing square root in IntegerModRing(2^n)https://ask.sagemath.org/question/50880/computing-square-root-in-integermodring2n/Hi, I'm trying to compute one square root in an IntegerModRing(2^n), but sage appears to fail to do so, am I doing something wrong?
PoC:
sage: n = 216
sage: FF = IntegerModRing(2^n)
sage: FF(1 + 2^(n - 1)).sqrt()
Thanks!apopoqMon, 20 Apr 2020 21:45:17 +0200https://ask.sagemath.org/question/50880/Error when calling the CRT functionhttps://ask.sagemath.org/question/39698/error-when-calling-the-crt-function/I have the following Magma code that I want to rewrite in Sage:
D := 1444451111007492249157225145240924628689936300289032719520989176681391983750\
5026233531541656521516385113467258658058158757413856041226225263754438069945819\
321862869928499936414339298248291015625;
N2tfac := [ 389017, 704969, 912673, 1030301, 1295029, 1442897, 2571353, 3307949,
3869893, 29929, 32761, 37249, 38809, 52441, 54289, 58081, 66049, 72361 ];
signs := [ 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1 ];
vecTau := [Integers()!(Sqrt(-IntegerRing(fac)!D)) : fac in N2tfac];
lst := [(-1)^(Integers()!signs[ind])*vecTau[ind] : ind in [1..#N2tfac]];
tau := CRT(lst, N2tfac);
"tau=",tau;
and when I run it I get the result of `tau= 13374843322841533370163824183368767068675387448700309211897565319967356307\
909512193392966464291429`. But when I rewrite it in Sage as this:
D = 1444451111007492249157225145240924628689936300289032719520989176681391983750\
5026233531541656521516385113467258658058158757413856041226225263754438069945819\
321862869928499936414339298248291015625
N2tfac = [ 389017, 704969, 912673, 1030301, 1295029, 1442897, 2571353, 3307949,
3869893, 29929, 32761, 37249, 38809, 52441, 54289, 58081, 66049, 72361 ]
signs = [ 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1 ]
vecTau = [Zmod(fac)(-D).square_root() for fac in N2tfac]
lst = [(-1)^(signs[ind])*vecTau[ind] for ind in [0..len(N2tfac)-1]]
tau = CRT(lst, N2tfac)
It gives me an error message of:
> TypeError: unsupported operand
> parent(s) for -: 'Ring of integers
> modulo 704969' and 'Ring of integers
> modulo 389017'
Any ideas what the problem might be, and how to solve it? For one thing I know that the `sqrt` function in Magma and Sage does not always return the same square root, can this be the problem? If yes, how to circumvent it, if no, what is causing the error here?whateverTue, 21 Nov 2017 15:11:18 +0100https://ask.sagemath.org/question/39698/Inconsistent result between Sage and Magma for sqrthttps://ask.sagemath.org/question/39670/inconsistent-result-between-sage-and-magma-for-sqrt/I have the following Magma code:
N2t := 625;
D := 84100;
tau:= Sqrt(-IntegerRing(N2t)!D);
tau
It basically creates a ring of integers modulo 625, evaluated it for the value of `D` with negation, and finally applies a square root calculation. Now, the result produced is `280`. When, I convert the code to Sage such as this:
N2t = 625
D = 84100
Z = Integers(N2t)
tau = sqrt(-Z(D))
tau
I get a result of `30`. Any ideas why this is the case?whateverMon, 20 Nov 2017 15:57:39 +0100https://ask.sagemath.org/question/39670/Creating user-defined rings.https://ask.sagemath.org/question/37839/creating-user-defined-rings/I want to create rings of the form {-(p-1)/2, ... , 0, ... , (p-1)/2} , but Zmod(p) gives {0, ... , p-1}. How can this be done? Is there a way I could create custom-rings from lists? Like `range(-d. d+1)` ?feynhatThu, 08 Jun 2017 10:19:07 +0200https://ask.sagemath.org/question/37839/Trying to understand a Univariate Quotient Polynomial Ring over Finite Fieldhttps://ask.sagemath.org/question/36464/trying-to-understand-a-univariate-quotient-polynomial-ring-over-finite-field/This might be a silly question and I am sorry for my lack of knowledge in abstract algebra.
I am trying to understand a Univariate Quotient Polynomial Ring over Finite Field but I want to make sure I am correct. So, if we have a polynomial, for example: $p = c_1 + c_2x^1 + c_3x^2 + \dots \ c_nx^{n-1}$ where $c_{i} \in \mathbb{Z}$.
Now to bring this polynomial into Quotient Polynomial Ring over Finite Field, for example: $r = x^{1024} + 1$ as a irreducible polynomial and some prime $q$ as a modulus.
First we need to find a quotient of division of $p / r$ and then for every coefficient in $p$ we need to $\bmod q$. Am I right? or completely off track?
I just want to know how SageMath does something like this:
modulus = 12289 # some prime
R.<X> = PolynomialRing(GF(modulus))
Y.<x> = R.quotient(X^(1024) + 1)
The reason I am asking this question is because I wrote something like this to simulate above SageMath code but it returns false:
import random
from itertools import izip
from math import fabs
dimension = 25 # degree of polynomials
modulus = 40961 # modulus
# ring = x^dimension + 1
ring = [1] + [0 for _ in range(dimension - 1)] + [1]
# Quotient polynomial ring
R.<X> = PolynomialRing(GF(modulus)) # Gaussian field of integers
Y.<x> = R.quotient(X^(dimension) + 1) # Cyclotomic field
def division(N, D):
dD = degree(D)
dN = degree(N)
if dD < 0: raise ZeroDivisionError
if dN >= dD:
q = [0] * dN
while dN >= dD:
d = [0] * (dN - dD) + D
mult = q[dN - dD] = N[-1] / d[-1]
d = [coeff * mult for coeff in d]
N = [abs(coeffN - coeffd) for coeffN, coeffd in izip(N, d)]
dN = degree(N)
r = N
else:
q = [0]
r = N
return (q, r)
def degree(poly):
while poly and poly[-1] == 0:
poly.pop() # normalize
return len(poly) - 1
def gen():
return [random.randint(100, 200) for _ in range(2^11)]
def ring_correct(poly, irreduciblePoly, modulus):
poly = division(poly, irreduciblePoly)[0]
poly = map(lambda x: x % modulus, poly)
return poly
T.<t> = PolynomialRing(ZZ, 'x')
a = gen()
print Y(a).list() == T(ring_correct(a, ring, modulus)).list()
Thanks in advance.Node.jsMon, 06 Feb 2017 15:59:35 +0100https://ask.sagemath.org/question/36464/Generating (Z/nZ[x])/(x^N-1)https://ask.sagemath.org/question/29826/generating-znzxxn-1/ Hey Guys, i am absolutely new to sage but want to use it for some algebraic calculations. Therefore i must generate the Polynomial ring R=$(Z/nZ[x])/(x^N-1)$ to calcuate some inverses and products of some polynomials in R.
I hope it's not a too stupid question and apologize for bothering you guys with this but i still hope someone can give me an answer :).
(ofc for some given n and N)
bruno171092Thu, 08 Oct 2015 12:57:14 +0200https://ask.sagemath.org/question/29826/IntegerModRing representationhttps://ask.sagemath.org/question/7485/integermodring-representation/How can I generate the elements of IntegerModring(n) in symmetric representation? For example Integers(6) = {0, 1,-1,2, -2, 3}czsanSun, 10 Oct 2010 10:35:27 +0200https://ask.sagemath.org/question/7485/Extension/coercion of finite rings & fieldshttps://ask.sagemath.org/question/9864/extensioncoercion-of-finite-rings-fields/Hi ...
again harping on my theme of p-adics: here is a characteristic-p toy model of the problem I had [here](http://ask.sagemath.org/question/2309/solving-polynomial-equations-over-p-adic-fields). Will someone please tell me how to do what this code is trying to do?!!
sage: K.<X> = GF(3^2,name='X'); # creates (residue) field which is GF(3)[X]
sage: R = IntegerModRing(3^2)[X]; # extends Z/p^2 by that same X to form quadratic extn - seemingly successfully
sage: print R(X+5); # I try to use X but it still treats it like an "alien" quantity in R ....
thanks!!GaryMakThu, 28 Feb 2013 16:18:17 +0100https://ask.sagemath.org/question/9864/Modular Arithmetic Question using Sagehttps://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/Hey forumgoers, just have a question using Sage. I am having trouble with a few questions asked to me, heres the questions, how do can you compute (n-1)! mod n for n < 100. Find a formula relating the number of idempotents in Zsubn with the number of distinct prime factors that n has.
An element a in Z(subn) is a square if there is some b element of Z(subn) such that a^2=b. Find the number of squares in Z(sub p^n). Mathstudent2010Tue, 09 Nov 2010 15:58:58 +0100https://ask.sagemath.org/question/7758/