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.Thu, 08 Apr 2021 04:40:24 +0200"Ratio" of two elements in a ringhttps://ask.sagemath.org/question/56538/ratio-of-two-elements-in-a-ring/Suppose I have a $\mathbb{Q}$-algebra R, and I have two elements x and y in R. I happen to know that x is a scalar multiple of y. Is there a way to figure out what the scalar is?
In other words, I want to identify the $\mathbb{Q}$-span of y with 1-dimensional vector space, choose an isomorphism of this vector space with $\mathbb{Q}$ (sending y to 1), and see where x goes.
The general context is that R is a finite-dimensional graded $\mathbb{Q}$-algebra (given as a quotient of a polynomial ring), and the top degree piece has dimension 1. I have an isomorphism of this top degree piece with $\mathbb{Q}$ (defined by sending a certain element to 1), and I want to be able to compute what it does to other elements.
An example of such a ring: let $A = \mathbb{Q}[x_1, x_2, x_3, x_4]$. Let $I_1 = (x_1x_3, x_2x_4)$. Let $I_2 = (x_1 + x_3, x_2 + x_4)$. Let $R = A/(I_1 + I_2)$.
(Note that $R$ is the Stanley-Reisner ring of simplicial complex (a triangulation of the circle) modulo a linear system of parameters. So it is graded by degree, and as the simplicial complex is a circle, the degree 2 is a 1-dimensional vector space.)
Let $y = x_1 x_2$, and let $x = (x_1 + x_4)(x_2 + x_3)$. Then x is a scalar multiple of y (as they are both in degree 2), and I would like to know what the scalar is.
(In this case, x = 2y.)
Later edit: fixed typovukovThu, 08 Apr 2021 04:40:24 +0200https://ask.sagemath.org/question/56538/How to import rings in python modulehttps://ask.sagemath.org/question/55403/how-to-import-rings-in-python-module/I'm trying to build a sage 9 code into a format of python module with .py file, and run the module in the sage command line. Most of the issue could be fixed through this webpage https://doc.sagemath.org/html/en/tutorial/programming.html by importing packages with command line such as
import_statements('is_integer')
i.e. set up the sage environment manually. However, a built in mechanism in sage was the usage of rings. i.e.
1/3 in sage automatically returned 1/3 in rational ring, but when put the code in python module and run it in sage command line.
sage: module_name.value1
was in class 'float' or 'int'
How to set up the environment so that the module could run operation in sage rings automatically?ShoutOutAndCalculateThu, 21 Jan 2021 07:10:55 +0100https://ask.sagemath.org/question/55403/what does the .<...> notation mean?https://ask.sagemath.org/question/53981/what-does-the-notation-mean/I was reading about Basic Rings, and the notation
`ratpoly.<t> = PolynomialRing(QQ)`
popped up. What is the <> for? It's not a function call, although I can see what it does. And the ratpoly has no meaning. I substituted skunkpoly with the same result. I can't seem to find much about it.cybervigilanteTue, 20 Oct 2020 05:04:17 +0200https://ask.sagemath.org/question/53981/Where can I find out about rings?https://ask.sagemath.org/question/52822/where-can-i-find-out-about-rings/ Where is there a ground-up tutorial on Sage rings? I've come across them but the docs are spotty or high level. Sometimes they cause problems but I'm not sure why. A Python integer will fail in a simple calculation but work when cast to a Sage ring integer but I have no idea why.cybervigilanteMon, 03 Aug 2020 09:19:52 +0200https://ask.sagemath.org/question/52822/Monomial with power modulo nhttps://ask.sagemath.org/question/51855/monomial-with-power-modulo-n/ I need to implement the following formal structure
$$ax^\gamma, \gamma \in \mathbb{Z}/n\mathbb{Z}, a \in \mathbb{R}$$ and $x$ is a formal variable.
I tried
```
ZZ6 = Integers(6)
x = var('x')
x^ZZ6(9) + x^ZZ6(11)
```
And get value `x^8`, whereas I need `x^ZZ6(8)`.
How can I do this in sage?
only1saleTue, 09 Jun 2020 11:15:48 +0200https://ask.sagemath.org/question/51855/How to make objects execute their operations in a specific field/ring?https://ask.sagemath.org/question/51593/how-to-make-objects-execute-their-operations-in-a-specific-fieldring/Providing some context: i want to create a class to operate on isogeny graphs of elliptic curves. So it should have the $j$-invariants (integers modulo $p$) as nodes and the existence of $l$-isogenies as edges.
To compute the edges i need to do some calculations on GF(p) and some others on the ring PolynomialRing(GF(p), ['X', 'Y']).
How do i make sure the operations happen on their specific rings and don't change the field outside of the class?JGCWed, 27 May 2020 23:21:45 +0200https://ask.sagemath.org/question/51593/Polynomial division in quotient rings?https://ask.sagemath.org/question/50406/polynomial-division-in-quotient-rings/I have a working example shown below to help explain my question.
R.<x> = GF(2)[];
I = R.ideal([x^2 - 1])
S.<u> = R.quotient_ring(I)
f = x^2 + x
g = x
print(f.quo_rem(g))
f = u^2 + u
g = u
print(f.quo_rem(g))
The first quo_rem call works fine, but the second does not. Is polynomial division not supported for quotient rings, or am I calling it the wrong way? I'm specifically interested in doing this for multivariate polynomials, but I can't seem to get it to work for a single variable either.
Related to the question, I am interested in understanding this division in quotient rings better. If the operation isn't supported in sage, any sort of references/algorithms on how to do such a calculation would be very helpful and appreciated.hshackleSun, 29 Mar 2020 00:49:43 +0100https://ask.sagemath.org/question/50406/Representative in Quotient Ringhttps://ask.sagemath.org/question/49721/representative-in-quotient-ring/ Hello everyone!
So I'm using Sage to reduce a bunch of monomials modulo an ideal $I$ in a ring $R = \mathbb{C}[x_1,x_2,...,x_n]$. Sage, however, decides that it should reduce things and use the high index terms as a basis, instead of the lower-index terms. For example, if $I = < x_1 + x_2 + x_3 >$ for $n = 3$, Sage will reduce $x_1$ into $-x_2 - x_3$, and use $x_2$ and $x_3$ as generators, whereas I want it to use $x_1$ and $x_2$ as generators instead, and have it say $x_3 = -x_1 - x_2$. Is there a way to do this?
Thank you!RaymondChouFri, 31 Jan 2020 06:52:13 +0100https://ask.sagemath.org/question/49721/Having trouble importing the lazy_laurent_series modulehttps://ask.sagemath.org/question/48608/having-trouble-importing-the-lazy_laurent_series-module/I am trying to import and use lazy Laurent series rings in sage, documented here: (http://doc.sagemath.org/html/en/reference/power_series/sage/rings/lazy_laurent_series_ring.html). I have the latest version of sage installed, and yet when I attempt to import/install the package it is nowhere to be found.
from sage.rings.lazy_laurent_series_ring import LazyLaurentSeriesRing
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-db0f55e1138b> in <module>()
----> 1 from sage.rings.lazy_laurent_series_ring import LazyLaurentSeriesRing
ImportError: No module named lazy_laurent_series_ring
I then tried to download it, perhaps I am not downloading the correct package? Where is it hiding?
sage -i lazy_laurent_series
Error: package 'lazy_laurent_series' not found
Note: if it is an old-style package, use -p instead of -i to install itmasseygirlTue, 05 Nov 2019 00:56:54 +0100https://ask.sagemath.org/question/48608/How can I assign different degrees to the variables of a polynomial ring?https://ask.sagemath.org/question/47290/how-can-i-assign-different-degrees-to-the-variables-of-a-polynomial-ring/ In defining a polynomial ring, is there any way to assign varying degrees to the variables?
For example I want to define the polynomial ring Q[x, y, z] but I want x to be of degree 1, y to be degree 2, and z to be degree 3. I am looking for a way to do this in general not just for a small number of variables.
Laughematician760Mon, 29 Jul 2019 07:07:55 +0200https://ask.sagemath.org/question/47290/Create Matrix in RREF with indeterminateshttps://ask.sagemath.org/question/47185/create-matrix-in-rref-with-indeterminates/Hi all,
I would like to be able to create a Matrix over a multivariable polynomial ring (in particular over R = PolynomialRing(QQ, 'x',(n-k)*n)) in Sage that has a particular form. I would like to create a $k \times n$ matrices that is in RREF form, where I can choose where the pivots should be and fill in the rest with variables from my polynomial ring. (I am assuming full rank, so there will be $k$ pivots with $n \choose k$ possible choices)
$\begin{bmatrix} 1 & x1 & 0 & x2 & \cdots\\\
0 & 0 & 1 & x3 & \cdots\\\
0 & 0 & 0 & 0 &\cdots \\\
\vdots & \vdots & \vdots & \vdots & \ddots \end{bmatrix}$
Is there any way I can do this in Sage by just indicating which columns I want to have the pivots in?BarkTue, 16 Jul 2019 17:36:05 +0200https://ask.sagemath.org/question/47185/Computations in the ring of integers of a number fieldhttps://ask.sagemath.org/question/46252/computations-in-the-ring-of-integers-of-a-number-field/Suppose I have some number field $K$, with its ring of integers $O_K$ = K.ring_of_integers(). If $I$ is an ideal of $O_K$ (or, if $I$ is a fractional ideal of $K$), I'd like to be able to compute with the ring $O_K/I$. For example, I'd like to be able to ask how big that ring is.
K.<omega> = NumberField(x^2+x+1)
OK = K.ring_of_integers()
R.<a,b> = OK.quo(OK.ideal(9))
R.cardinality()
gives a NotImplementedError. (Even though cardinality shows up as one of the supported methods if I type R.??).
Or, again for example, I'd like to be able to determine the ring structure of $R$, or the structure of its group of units, but none of these methods seem to actually be supported.
The type of R is sage.rings.quotient_ring.QuotientRing_generic_with_category.
What am I missing?rogerlWed, 17 Apr 2019 23:57:20 +0200https://ask.sagemath.org/question/46252/Dividing Boolean Polynomials in Sage.https://ask.sagemath.org/question/45224/dividing-boolean-polynomials-in-sage/ Hi all,
I'm working in a Boolean Polynomial Ring. I have an equation generator. My objective is to divide the highest possible monomial by the leading monomial of my equations.
NUMBER_OF_VARIABLES = 15
B = BooleanPolynomialRing(NUMBER_OF_VARIABLES,'x', order = 'degrevlex')
Each equation that I generate looks something like this.
f = x6*x2*x1 + x6*x5*x4 + x9*x5*x4 + x9*x6*x0 + x10*x2*x1 + x10*x4*x1 + x11*x9*x7 + x11*x10*x0 + x12*x4*x0 + x12*x7*x3 + x12*x9*x0 + x12*x10*x3 + x12*x10*x5 + x13*x7*x0 + x13*x7*x5 + x13*x8*x6 + x13*x10*x9 + x13*x11*x2 + x14*x5*x4 + x14*x11*x5 + x14*x13*x12 + x6*x3 + x7*x2 + x9*x1 + x10*x9 + x14*x8 + x14*x13 + x3 + x7 + x8 + 1
Getting the leading monomial of f:
print f.lm()
>>> x6*x2*x1
Getting the highest possible monomial of my ring (15 variables)
print f.set().vars()
>>> x14*x13*x12*x11*x10*x9*x8*x7*x6*x5*x4*x3*x2*x1*x0
But somehow I get an error when I try to divide them.
f.set().vars()/f.lm()
>>> bad operand type for unary ~: 'sage.rings.polynomial.pbori.BooleanMonomial'
I checked the documentation and nothing seems to work. I have tried all of the methods below and they do not work.
f.set().vars().divide(f.lm())
# http://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/pbori.html
f.set().vars().reduce(Ideal([f.lm()]))
# https://stackoverflow.com/questions/35233406/multivariate-polynomial-division-in-sage
I'm really at a loss here. I've seen answers whereby the code `q,r = dividend.maxima_methods().divide(divisor)` is used, but this seems like such a simple thing to do. Surely I'm missing something out. Why isn't division working? Multiplication and addition works, so why shouldn't division work?
Stockfish3709Tue, 29 Jan 2019 02:43:21 +0100https://ask.sagemath.org/question/45224/Gaussians as Euclidean Domainhttps://ask.sagemath.org/question/44271/gaussians-as-euclidean-domain/Follow up to [a comment](https://ask.sagemath.org/question/44251/making-a-quotient-with-gaussian-elements/?comment=44265#post-id-44265) by @nbruin in a previous question:
> One reason that Euclidean division isn't available by default on ZI is because as far as sage is concerned, it's a quadratic ring, and those generally are not euclidean rings. There are some quadratic rings that are, but most of them are only euclidean with rather obscure euclidean norms. The fact that Z[i] is euclidean with the "standard" norm is really quite anomalous among quadratic rings.
> If you're interested in studying euclidean rings you probably should write some utility functions yourself to help you with it (or search if such utilities are already available). You could even consider writing a new ring subclass for Euclidean rings. To illustrate that sage doesn't know that ZI is a euclidean domain:
sage: ZI in EuclideanDomains()
False
context: `ZI = QuadraticField(-1, 'I').ring_of_integers()`
My question is: Is there a built in way in SageMath to work with Gaussian integers as an Euclidean domain?JsevillamolTue, 13 Nov 2018 17:48:43 +0100https://ask.sagemath.org/question/44271/Making a quotient with Gaussian elementshttps://ask.sagemath.org/question/44251/making-a-quotient-with-gaussian-elements/I want to implement the euclidean algorithm for arbitrary euclidean domains.
In particular, I want it to work with Gaussians.
# Extended Euclides Algorithm
def extended_euclides(a,b):
r0 = a; r1 = b
s0 = 1; s1 = 0
t0 = 0; t1 = 1
while r1 != 0:
q = r0 // r1
r0, r1 = r1, r0 - q * r1
s0, s1 = s1, s0 - q * s1
t0, t1 = t1, t0 - q * t1
return r0, s0, t0
When I run
# Gaussian integers example
ZI = QuadraticField(-1, 'I').ring_of_integers()
a = ZI(-87 + 47*I); b = ZI(-90 + 43*I)
r,s,t = extended_euclides(a,b)
print("The GCD of {} and {} is {}".format(a,b,r))
print("Its Bézout coefficients are {} and {}".format(s,t))
assert(r == s*a + t*b)
I get the output
The GCD of 47*I - 87 and 43*I - 90 is 43*I - 90
Its Bézout coefficients are 0 and 1
Which is wrong. My understading of what is happening is that the quotient `//` is not giving me the integer quotient, but promoting it to rational quotient.
How do I compute the gaussian integer quotient?JsevillamolMon, 12 Nov 2018 15:04:31 +0100https://ask.sagemath.org/question/44251/polynomials with roots of unity as coefficientshttps://ask.sagemath.org/question/42307/polynomials-with-roots-of-unity-as-coefficients/I have three polynomials $(1+x)^L+1$, $(1+\omega x)^L+$ and $(1+\omega^2 x)^L+1$ where $\omega$ is cube root of unity and L is some constant, for example, 2 or 3. I want to find the GCD of these polynomials. How do I define these polynomials in sagemath with coefficients as roots of unity?arpitThu, 10 May 2018 22:48:58 +0200https://ask.sagemath.org/question/42307/cokernel of a map between modules over polynomial ringshttps://ask.sagemath.org/question/42154/cokernel-of-a-map-between-modules-over-polynomial-rings/Define a polynomial ring $R$ as $F_{2}\left[x_{1},x_{1}^{-1},....x_{D},x_{D}^{-1}\right]$ where $D$ is the dimension and $\mathbb{F}_{2}$ is a binary field.
Let $G$ be a free $R$-module of some labels and has rank $t$. $P$
be a free $R$-module of Pauli operators. $\sigma$ is a map from
$G$ to $P$. I want to write a snippet to calculate the cokernel
of this map.
Just for example (taken from page 54 of arxiv.1305.6973 or page 41 of arxiv.1607.01387),
though this is not essential for the question, I can have two ``interaction''
terms in terms of 2-dimensional Pauli operators $X$, $Z$ and Identity
operator $I$ on 4 sites with two 2-dimensional systems per site as
$
II(0,0)-IX(0,1)-XI(1,0)-XX(1,1)
$
and
$
ZZ(0,0)-IZ(0,1)-ZI(1,0)-II(1,1)
$
where on each site $\left(x,y\right)$ (mentioned in the bracket after
the Pauli operators), the first(second) Pauli acts on the first(second)
two dimensional system on that site. The map $\sigma$ can be written
as
$
\sigma=\left(\begin{array}{cc}
y+xy & 0 \\
x+xy & 0 \\
0 & 1+y \\
0 & 1+x
\end{array}\right)
$
where for example, $y+xy$ is a polynomial that specifies the action
on the first two dimensional system as
$
y+x y=0 \hspace{1mm} x^0 y^0+ 1 \hspace{1mm} x^0 y^1+0 \hspace{1mm} x^1 y^0 +1 \hspace{1mm} x^1 y^1
$
where the exponents are the coordinates of the sites and coefficients
$0$ and $1$ imply whether there is a Pauli acting or not.arpitWed, 25 Apr 2018 04:02:38 +0200https://ask.sagemath.org/question/42154/Eigenvalues of matrix with entries in polynomial ringhttps://ask.sagemath.org/question/8797/eigenvalues-of-matrix-with-entries-in-polynomial-ring/Hi!
I just wrote some code on the sage-combinat queue which computes a matrix with entries in a polynomial ring R = PolynomialRing(QQ, 'x', n)
sage: P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]), linear_extension = True)
sage: L = P.linear_extensions()
sage: M = L.markov_chain_transition_matrix(labeling = 'source')
sage: M
[-x0 - x1 - x2 x3 x0 + x3 0 0]
[ x1 + x2 -x0 - x1 - x3 0 x1 0]
[ 0 x1 -x0 - x3 0 x1]
[ 0 x0 0 -x0 - x1 - x2 x0 + x3]
[ x0 0 0 x0 + x2 -x0 - x1 - x3]
sage: M.eigenvalues()
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
/Applications/sage-5.0.beta7/devel/sage-combinat/sage/combinat/posets/<ipython console> in <module>()
/Applications/sage-5.0.beta7/local/lib/python2.7/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.eigenvalues (sage/matrix/matrix2.c:26415)()
/Applications/sage-5.0.beta7/local/lib/python2.7/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.fcp (sage/matrix/matrix2.c:11089)()
/Applications/sage-5.0.beta7/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.factor (sage/rings/polynomial/polynomial_element.c:22655)()
NotImplementedError:
Is it possible to compute this some other way or is this just not yet implemented (which would surprise me!).
Thanks,
Anne
-----
Edit (originally posted as an answer by the original poster of the question)
Here is an easier example with the question:
sage: R = PolynomialRing(QQ, 'x', 2)
sage: x = R.gens()
sage: M = matrix([[x[0],x[1]],[x[1],x[0]]])
sage: M.eigenvalues()
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
/Applications/sage-5.0.beta7/devel/sage-combinat/sage/combinat/posets/<ipython console> in <module>()
/Applications/sage-5.0.beta7/local/lib/python2.7/site-packages/sage/matrix /matrix2.so in sage.matrix.matrix2.Matrix.eigenvalues (sage/matrix/matrix2.c:26415)()
/Applications/sage-5.0.beta7/local/lib/python2.7/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.fcp (sage/matrix/matrix2.c:11089)()
/Applications/sage-5.0.beta7/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.factor (sage/rings/polynomial/polynomial_element.c:22655)()
NotImplementedError:Anne SchillingFri, 16 Mar 2012 20:05:50 +0100https://ask.sagemath.org/question/8797/What is the best way to work with ratios of polynomials?https://ask.sagemath.org/question/41760/what-is-the-best-way-to-work-with-ratios-of-polynomials/What is the best way to work with ratios of polynomials with (real and complex) coefficients that can vary from very small to very big values? As I have to keep precision, I am working with symbolic expressions (type 'sage.symbolic.expression.Expression'), but as I operate with the expressions, they become bigger and bigger, and it is more and more difficult to plot them or find its roots, for example.
I perceived that making
# symbolic_expression is some symbolic polynomial with real or complex coefficients
symbolic_expression.polynomial(RR)
symbolic_expression.polynomial(CC)
simplifies the polynomials and eases computations but, as I understand, this converts the symbolic expressions to the real (RR) and complex (CC) rings, rounding the coefficients of the polynomials to machine precision and, in this manner, numerical errors would propagate in my computations. In this scenario, I would need to increase this conversion precision to an arbitrary value that guarantees correct results at the end of all computations.
I've read something about polynomial rings, symbolic ring, etc. I am studying this, but I still don't know what a ring is. Is symbolic ring the same thing as symbolic expressions? Does polynomial rings enable better performance and arbitrary precision?
Cordially
***** EDIT *****
I complement my question to answer to @B r u n o comment.
First, I would like to thank @B r u n o and @slelievre for the tips! I start to better understand things now.
Basically, I generate three polynomials. These polynomials are the basis of my work. I then operate on these polynomials generating other functions, e.g., as the ratio of these polynomials, and continue operating on the new functions, transforming them, plotting, finding the roots of the numerator and denominator polynomials, etc.
I'm slowly improving the code. I started with a plain script, then I created some functions to organize the code, in a procedural approach, and now I am moving to an object-oriented paradigm. This helps me better visualize and understand the problem. I even created a graphical interface to ease the interaction with the program, so as I can easily experiment with different input variables.
The code snippet below reflects the current state of the code it illustrates some inputs to test the code, how I generate my three basic polynomials and some derived functions. Sorry if the code seems silly :-/, I'm not used to develop software, I am still studying.
class FilterPrototype:
def __init(self):
pass
def generate_polynomials(self):
pass
def generate_s21(self, e_poly, p_poly):
return p_poly.polynomial(CC)/e_poly.polynomial(CC)
def generate_s11(self, e_poly, f_poly):
return f_poly.polynomial(CC)/e_poly.polynomial(CC)
def generate_group_delay(self, s21):
return -(1/s21(s=i*omega)*s21(s=i*omega).diff(omega)).imag()
def plot(self, symb_express, bounds):
pl = plot(symb_express, bounds[0], bounds[1])
pl.show()
return list(pl[0])
class ApproxArbitraryPhase(FilterPrototype):
def __init__(self, spec_type, spec, e_order, p_order):
self.spec_type = spec_type # type of specification
self.spec = spec # filter specification
self.e_order = e_order # order of the denominator polynomial
self.p_order = p_order # order of the numerator polynomial
def generate_polynomials(self):
listOmega = [] # List of frequencies (in radians per second)
for a in range(self.e_order + 1):
listOmega.append(a/self.e_order)
if self.spec_type == "group delay":
group_delay_spec(omega) = sage_eval(self.spec, locals={'omega':omega})
elif self.spec_type == "phase":
root.destroy()
sys.exit("You cannot specify a phase. This is yet not implemented.")
else:
root.destroy()
sys.exit("""The spec_type should be "group delay" or "phase".""")
phase(omega) = group_delay_spec(omega).integral(omega)
listPhases = [0]
for a in range(1, self.e_order+1):
listPhases.append(phase(listOmega[a]))
alpha0 = listOmega[1]/tan(listPhases[1])
listAlpha = [alpha0]
for a in range(1, self.e_order):
firstline = listOmega[a+1]^2 - listOmega[a]^2
lastline = alpha0 - listOmega[a+1]/tan(listPhases[a+1])
ic = 1
while ic < a:
lastline = listAlpha[ic] - ((listOmega[a+1]^2 - listOmega[ic]^2)/lastline)
ic+=1
listAlpha.append(firstline/lastline)
ePolynomials = [1, s + listAlpha[0]]
for a in range(2, self.e_order+1):
ePolynomials.append(listAlpha[a-1]*ePolynomials[a-1] + (s^2 + listOmega[a-1]^2)*ePolynomials[a-2])
ePoly = ePolynomials[self.e_order]
pMod = sqrt(ePoly(s=i*omega)*ePoly(s=-i*omega))
integrand = []
for a in range(self.p_order+1):
integrand.append(pMod*chebyshev_T(a, omega)/sqrt(1-omega^2))
c = []
for a in range(self.p_order+1):
if a == 0:
c.append((1/pi)*Rational(integrand[a].nintegral(omega, -1, 1)[0]))
else:
c.append((2/pi)*Rational(integrand[a].nintegral(omega, -1, 1)[0]))
up = 0
for a in range(self.p_order+1):
up = up + c[a]*chebyshev_T(a, omega)
eMod(omega) = (ePoly(s=i*omega)).polynomial(CC)
den = lambda omega: up/abs(eMod(omega))
pl = plot(den(omega), -1, 1) # to improve the precision of norm_factor, the plot_points=200 parameter of the plot function should be augmented
plPoints = []
for pair in list(pl[0]):
plPoints.append(pair[1])
normFactor = Rational(max(plPoints))
pPoly(omega) = up/normFactor
pPoly(s) = pPoly(omega=s/I)
fMod2 = ePoly(s=s)*ePoly(s=-s) - pPoly(s=s)*pPoly(s=-s)
solutions = fMod2.roots(ring=CC)
fPoly = 0
for solution in solutions:
if solution[0].real() < 0 or (solution[0].real() == 0 and solution[0].imag() < 0):
if fPoly == 0:
fPoly = (s - solution[0])
else:
fPoly = fPoly*(s - solution[0])
return (ePoly, fPoly, pPoly)
if __name__ == "__main__":
# execute only if run as a script
s = var("s")
omega = var("omega", domain=RR)
filtro = ApproxArbitraryPhase("group delay", "omega + 5/2", 4, 4)
# filtro = ApproxArbitraryPhase("group delay", "omega + 9/2", 6, 6)
# filtro = ApproxArbitraryPhase("group delay", "-omega + 27/5", 6, 6)
# filtro = ApproxArbitraryPhase("group delay", "piecewise([([0,0.5], 2*omega + 143/20), ((0.5,1), 163/20), ([1,1], 163/20)])", 8, 8)
# filtro = ApproxArbitraryPhase("group delay", "3/5*omega + 106/25", 6, 4)
e,f,p = filtro.generate_polynomials()
print(e)
print(f)
print(p(s))
s21 = filtro.generate_s21(e, p(s))
print(s21)
s11 = filtro.generate_s11(e, f) # possui polinomio do numerador com coeficientes imaginarios
print(s11)
gd = filtro.generate_group_delay(s21)
print(gd)
points_s21 = filtro.plot(20*log(abs(s21(s=i*omega)),10), [-1.5, 1.5])
# print(points_s21)
points_s11 = filtro.plot(20*log(abs(s11(s=i*omega)),10), [-1.5, 1.5])
# print(points_s11)
points_gd = filtro.plot(gd, [-1.5, 1.5])
# print(points_gd)joaoffMon, 26 Mar 2018 11:45:25 +0200https://ask.sagemath.org/question/41760/how to define Skew Polynomial Ring over Cyclotomic Fieldhttps://ask.sagemath.org/question/40199/how-to-define-skew-polynomial-ring-over-cyclotomic-field/how to define Skew Polynomial Ring in x over Cyclotomic Field of order 7 and degree 6 twisted by zeta7 |--> zeta7^2
when i execute those commands
K = CyclotomicField(7)
sigma = K.hom([K.gen()^2])
S.< x > = K['x',sigma]
I have this message error
> AssertionError: coercion from
> Cyclotomic Field of order 7 and degree
> 6 to Skew Polynomial Ring in x over
> Cyclotomic Field of order 7 and degree
> 6 twisted by zeta7 |--> zeta7^2
> already registered or discoveredBouzidi AhmedSun, 17 Dec 2017 11:36:39 +0100https://ask.sagemath.org/question/40199/Elliptic Curves defined over Z/nZ rings for general nhttps://ask.sagemath.org/question/36504/elliptic-curves-defined-over-znz-rings-for-general-n/ An Elliptic curve is the union of its affine part Eaff(Z/nZ)={ [x,y,1] in P2(Z/nZ) such that y2 =x3+ax+b }
and the point at infinity O = [0,1,0]
P2(Z/nZ) is the projective plane:
T = { (x,y,z) in (Z/nZ)^3 such that gcd(x,y,z,n) = 1}
P2(Z/nZ) = (T / ~) where ~ is the equivalence relation defined by
(x,y,z) ~ (x0,y0,z0) iff there is an INVERSIBLE element u in Z/nZ ⇤ such that (x,y,z) = u(x0,y0,z0).
I found those doc pages
http://fe.math.kobe-u.ac.jp/icms2010-dvd/SAGE/www.sagemath.org/doc/reference/sage/schemes/elliptic_curves/ell_generic.html
http://doc.sagemath.org/html/en/reference/curves/sage/schemes/elliptic_curves/constructor.html
I think to define an Elliptic Curve here with
q=10
E1 = EllipticCurve(Zmod(q),[0,1])
E1
> Elliptic Curve defined by y^2 = x^3 +
> 1 over Ring of integers modulo 10
but
E1.points()
is not working. is there a method to get all the points of this Elliptic Curve ? its cardinality etc ????
faguiThu, 09 Feb 2017 16:25:57 +0100https://ask.sagemath.org/question/36504/How to find Kernel of a Matrix in $\mathbb{Z}/n$https://ask.sagemath.org/question/33890/how-to-find-kernel-of-a-matrix-in-mathbbzn/ When I tried to find it directly using
A.kernel()
it said
Cannot compute a matrix kernel over Ring of integers modulo 11053185041
vishbThu, 23 Jun 2016 08:16:00 +0200https://ask.sagemath.org/question/33890/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 21:07:11 +0200https://ask.sagemath.org/question/33322/Coding p-adic Newton's method to solve polynomials?https://ask.sagemath.org/question/32608/coding-p-adic-newtons-method-to-solve-polynomials/ I'm confused as to how to code the p-adic Newton's method in order to solve polynomials, and specifying solutions to a specific number of p-adic digits. Any help?veryconfusedSat, 20 Feb 2016 20:54:57 +0100https://ask.sagemath.org/question/32608/convert polynomial rings from Sage to Singularhttps://ask.sagemath.org/question/32596/convert-polynomial-rings-from-sage-to-singular/Suppose I have a ring R in sage (I have in mind a polynomial ring modulo some ideal). Is there a way to convert it into a ring in Singular?
I want to use the tensor product function (which singular provides) on two rings (and then convert back to sage) but singular doesn't have (natural) constructors for the rings I'd like to tensor. admiraltsoFri, 19 Feb 2016 19:03:01 +0100https://ask.sagemath.org/question/32596/Twisted Polynomial Ring(Construct new Class)https://ask.sagemath.org/question/31584/twisted-polynomial-ringconstruct-new-class/ I would like to implement a class of twisted polynomial rings, which assigns to ring $K$ in characterstic $p$ a ring $K[\tau]$, whose underlying additive structure is just an ordinary polynomial ring in $\tau$, but with the multiplication defined by $\tau x=x^p \tau$.
Is it possible to construct this as a usual polynomial ring and modify the multiplication in some way?
I am totally new to Sage and Python, and I couldn't even figure out the parent/element dynamics, i.e. what exactly I have to specify for my object to fit with the usual Sage classes. The thematic tutorials on the documentation page don't really specify a general way to deal with this, so I am lost where to start. Nick123Tue, 15 Dec 2015 15:06:27 +0100https://ask.sagemath.org/question/31584/Multiplicative group of integers mod n?https://ask.sagemath.org/question/29914/multiplicative-group-of-integers-mod-n/ I'm guessing this is pretty basic, but I'm also new to Sage and can't find anything about it.
I know [how to work with the ring of integers mod n](http://doc.sagemath.org/html/en/reference/rings_standard/sage/rings/finite_rings/integer_mod_ring.html). Is there something analogous for the [multiplicative group of integers mod n](https://en.wikipedia.org/wiki/Multiplicative_group_of_integers_modulo_n)?
Something like:
G = Mult_Integers(5)
list(G)
[1, 2, 3, 4]
Googling has been surprisingly fruitless.
Thanks!
EDIT: @Nathann: right, but I'm not talking about {0, 1, 2, . . ., n-1}, but {1, 2, 3, . . ., n-1}, which [is a group with multiplication](https://en.wikipedia.org/wiki/Multiplicative_group_of_integers_modulo_n).zqcmSun, 11 Oct 2015 17:42:26 +0200https://ask.sagemath.org/question/29914/Can I localize a ring at a prime ideal?https://ask.sagemath.org/question/29480/can-i-localize-a-ring-at-a-prime-ideal/ In my particular case, it's a ring of integers in a number field.TaylorThu, 17 Sep 2015 04:22:44 +0200https://ask.sagemath.org/question/29480/How to find Smith normal form of a matrix over regular rings?https://ask.sagemath.org/question/23711/how-to-find-smith-normal-form-of-a-matrix-over-regular-rings/Let $A$ be a matrix over ring $^{\mathbb{Z}}/_{6\mathbb{Z}}$. How to find an invertible matrix $P$ and $Q$ such that the matrix $PAQ$ isa Smith Normal Form of $A$?Jerol Videl LiowFri, 08 Aug 2014 08:38:16 +0200https://ask.sagemath.org/question/23711/RingMorphism defined by a python functionhttps://ask.sagemath.org/question/10795/ringmorphism-defined-by-a-python-function/Is there a way to define a `RingHomomorphism` object that calls a user defined function? I know this is possible for `SetMorphism`, but I can't find a way to do the same for rings.
My use case: I have a python (or cython) function defining an embedding of a (finite) field into another. Of course, I could evaluate it on the generators of the domain and create a `RingHomomorphism_im_gens` object, but my function is much faster to evaluate.
LucaMon, 02 Dec 2013 18:00:15 +0100https://ask.sagemath.org/question/10795/