I'm not entirely sure if this is the right forum for this but here goes: Let $l$ be a prime and let $p\equiv 1 (\text{mod} \ l)$ be prime as well. Let $\zeta \in \mathbb{Z}$ be a primitive $l$-th root of unity modulo $p$. I have a list of integers, call it $B$. I will call two numbers $a,b$ from $B$ equivalent if $a \equiv \zeta^kb \ (\text{mod} \ p)$ for some $k=0,...,l-1$. I would like to create a new list $A$ containing one and only one element from the equivalence classes of $B$. For example if $l=5,p=31, \zeta=2$ and $B=\{3,4,17\}$, then $A=\{3,4\}$ since $3 \not \equiv 2^k4 \ (\text{mod} \ 31)$ for all $k$ and $3 \equiv 2^117 \ (\text{mod} \ 31)$. I have a very limited understanding of coding. I know that I probably need to create a list $A$ containing the first element of $B$ and then do a for loop running through the elements $B[i]$ of $B$, then within that loop, run through the elements $a$ of $A$ and if $B[i]\not \equiv \zeta^ka \ (\text{mod} \ p)$ for all $k$, then $A.append(B[i])$. What I'm struggling with is how to add the element $B[i]$ once it has "passed this test" and how do I get the loop to move past $B[i]$ once it has failed the test. I'm not sure if I should be using for loops or while loops. Any help would be very much appreciated. Thank you.
2026-03-27 05:36:32.1774589792
Help with SAGE/python: removing elements from a list with respect to an equivalence relation
276 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
There are 1 best solutions below
Related Questions in PYTHON
- Solve an equation with binary rotation and xor
- Function to rotate on a 3D sphere at a fixed distance?
- Verify the Riemann Hypothesis for first 1000 zeros.
- confused by the description of numpy.linalg.lstsq
- Rotate around a specific point instead of 0,0,0
- Calculating $\pi$: using a spigot and starting from middle
- Prove by the Principle of Recursion
- Use recursion to prove the bounds of the Fibonacci numbers when $n\geq 2$
- How to perform a double (numerical) integration of $f(x,y)$ over an irregular sample of $x$ and $y$ values
- What does s(n) = s(n) mean?
Related Questions in SAGEMATH
- Simultaneous diagonalization on more than two matrices
- Polynomial ring over finite field - inverting a polynomial non-prime
- Learn mathematical thinking with open source (SageMath, GeoGebra, ....)
- How can I find the dimension of an eigenspace?
- Why does the cube root of a polynomial in a finite field produce a different polynomial when re-cubed?
- What happens with subdivisions of normal fans in Sage?
- Software package for plotting 3-d splines
- in SAGE, how to convert a permutation into coxeter-generators (simple reflections)?
- simplify_full() for sage matrices
- Sage--use spkg coxeter3 in Sage notebook
Trending Questions
- Induction on the number of equations
- How to convince a math teacher of this simple and obvious fact?
- Find $E[XY|Y+Z=1 ]$
- Refuting the Anti-Cantor Cranks
- What are imaginary numbers?
- Determine the adjoint of $\tilde Q(x)$ for $\tilde Q(x)u:=(Qu)(x)$ where $Q:U→L^2(Ω,ℝ^d$ is a Hilbert-Schmidt operator and $U$ is a Hilbert space
- Why does this innovative method of subtraction from a third grader always work?
- How do we know that the number $1$ is not equal to the number $-1$?
- What are the Implications of having VΩ as a model for a theory?
- Defining a Galois Field based on primitive element versus polynomial?
- Can't find the relationship between two columns of numbers. Please Help
- Is computer science a branch of mathematics?
- Is there a bijection of $\mathbb{R}^n$ with itself such that the forward map is connected but the inverse is not?
- Identification of a quadrilateral as a trapezoid, rectangle, or square
- Generator of inertia group in function field extension
Popular # Hahtags
second-order-logic
numerical-methods
puzzle
logic
probability
number-theory
winding-number
real-analysis
integration
calculus
complex-analysis
sequences-and-series
proof-writing
set-theory
functions
homotopy-theory
elementary-number-theory
ordinary-differential-equations
circles
derivatives
game-theory
definite-integrals
elementary-set-theory
limits
multivariable-calculus
geometry
algebraic-number-theory
proof-verification
partial-derivative
algebra-precalculus
Popular Questions
- What is the integral of 1/x?
- How many squares actually ARE in this picture? Is this a trick question with no right answer?
- Is a matrix multiplied with its transpose something special?
- What is the difference between independent and mutually exclusive events?
- Visually stunning math concepts which are easy to explain
- taylor series of $\ln(1+x)$?
- How to tell if a set of vectors spans a space?
- Calculus question taking derivative to find horizontal tangent line
- How to determine if a function is one-to-one?
- Determine if vectors are linearly independent
- What does it mean to have a determinant equal to zero?
- Is this Batman equation for real?
- How to find perpendicular vector to another vector?
- How to find mean and median from histogram
- How many sides does a circle have?
You're right that you want to do some kind of loop. If I understand you correctly, you want to do this:
It's worth reading this carefully and trying to understand what it does. For each $b$, we check it against each $a$. If ever $b \sim a$, we set
keep_b = Falseso that when we know to through $b$ out. Ifkeep_bmanages to beTrueat the end, that means it survived testing against each $a \in A$, so it's from a new equivalence class. We keep it, and now that it's in $A$ we'll check future $b$s against it as well.There are slicker approaches (There's a couple obvious optimizations and I'm sure there's many that I don't see), but my goal with this code was ease-of-understanding. If you want to optimize it, you might ask on the sage forum or on stackoverflow.
I hope this helps ^_^