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, 11 Jun 2020 20:40:09 +0200Real analytic Eisenstein serieshttps://ask.sagemath.org/question/51911/real-analytic-eisenstein-series/I'd to compute values of a certain function in Sage, a kind of a modular form, the so-called [real analytic Eisenstein series](https://en.wikipedia.org/wiki/Real_analytic_Eisenstein_series). Does anybody know how to do it? I could not have found the Sage name for it.
More precisely, I would like to plot the the graph of the real analytic Eisenstein series, their real and imaginary values in a square of the complex plane (variable z) each for a certain value of the parameter s. Thus s is fixed in each of the graphs.
Real analytic Eisenstein series (also this is this their name at wikipedia) are defined for a complex z and a complex s. They are not the [Eisenstein series](https://en.wikipedia.org/wiki/Eisenstein_series) defined for complex z and an integer k. If s is k and an integer, they are connected by the multiple of Im(z)^s. Thus an easy connection, but I'd like to know the value of the series for a complex s. They are modular functions, not holomorphic and connected to theta series.svarotThu, 11 Jun 2020 20:40:09 +0200https://ask.sagemath.org/question/51911/How to solve an equation over finite field for exponent variable?https://ask.sagemath.org/question/48869/how-to-solve-an-equation-over-finite-field-for-exponent-variable/I want to resolve the following equation for exponent $n$ for given value $v$:
$$ v\equiv(r\cdot ((b+r)^n- (b-r)^n)) \cdot (2 \cdot r \cdot ((b+r)^{n-1}- (b-r)^{n-1}))^{-1} \mod P$$
with
$$r^2 = 4\cdot a+b^2 \mod P$$
and a prime $P$
Looking for a function $f(v) = n$.
The values $a,b$ are chosen in that way that for $n=[1,..,P]$ the results $v$ will be all values in ${{0,..,P-1 }\brace{ }}=\mathbb{F}_P $. That works iff there is no such root $r$ in $\mathbb{F}_P$ exists for $a, b$. If both parts in formula above are expanded only $r^2$ is left over.
*Example*:
$P=11; a=5; b=3 -> r^2=7$
R.<a,b,r,v,n>=PolynomialRing(GF(11))
[ r*((b+r)^n-(b-r)^n)/ (2* r*((b+r)^(n-1)-(b-r)^(n-1)) ) for n in R.base() if n>1]
[b,
(-5*b^2 + 2*r^2)/(-3*b),
(-3*b^3 - 3*b*r^2)/(b^2 + 4*r^2),
(-b^4 - 2*b^2*r^2 + 2*r^4)/(5*b^3 + 5*b*r^2),
(b^5 - 4*b^3*r^2 + b*r^4)/(-2*b^4 - 4*b^2*r^2 + 4*r^4),
(3*b^6 + 4*b^4*r^2 - 2*b^2*r^4 + 2*r^6)/(2*b^5 + 3*b^3*r^2 + 2*b*r^4),
(5*b^7 + 2*b^5*r^2 + 2*b^3*r^4 + 5*b*r^6)/(-5*b^6 - 3*b^4*r^2 - 4*b^2*r^4 + 4*r^6),
(-4*b^8 + 3*b^6*r^2 - b^4*r^4 - 5*b^2*r^6 + 2*r^8)/(-b^7 + 4*b^5*r^2 + 4*b^3*r^4 - b*r^6),
(-2*b^9 - 2*b^7*r^2 - 2*b^5*r^4 - 2*b^3*r^6 - 2*b*r^8)/(3*b^8 - 5*b^6*r^2 - 2*b^4*r^4 + b^2*r^6 + 4*r^8)]
in values: $0, 3 , 1 , 8 , 5 , 4 , 7 ,10 , 9 , 6 , 2 , 0 , 3 , 1 , ...$
There is some special case for $n=1$. With this the part which need to be inverted is $0$. In that case $v$ is assigned to 0.
-----------------------------------------
As a alternative form without any root $r$ (for $n>2$):
$$v\equiv \frac{2 \cdot \sum_{k=1}^{\lfloor n/2\rfloor} {n-1\choose 2k-1} b^{n-2k}(r^2)^{k} }{4\cdot \sum_{k=1}^{\lfloor (n-1)/2 \rfloor} {n-2 \choose 2k- 1} b^{n-2k-1} (r^2)^{k } } \mod P$$
in sagemath:
a,b,r,v,k,n=var('a b r v k n')
(sum( 2*binomial(n-1, 2*k-1) * b^(n-2*k)*(4*a+b^2)^(k) , k,1,floor( n/2) ))*(sum(4* binomial(n-2, 2*k-1) * b^(n-2*k-1)*(4*a+b^2)^(k) , k,1, floor( (n-1)/2) ))^(-1)-v
But only got it working with normal variables.
-------
How can I solve such equation in sagemath?
R.<n>=PolynomialRing(GF(11))
(2*k-8).roots(); #multiplication works
(2^k-8).roots(); #power not working
($a,b,r^2$ can be exchanged with current values)maanMon, 25 Nov 2019 04:25:03 +0100https://ask.sagemath.org/question/48869/How to solve an equation over finite field?https://ask.sagemath.org/question/48835/how-to-solve-an-equation-over-finite-field/ I would like to solve an equation like
solve( ((k^2)%17)==8,k)
or
R = GF(17)
solve(R(k)^2==8,k)
or as math equation: $k^2 \equiv 8 \mod 17$
This would be true for e.g. $k=5$
If I use the solve function above in sagemath I get an empty result $[]$ for first and 'self must be a numeric expression' for second.
How can I solve such equation?maanThu, 21 Nov 2019 13:41:43 +0100https://ask.sagemath.org/question/48835/Rounding, using modular arithmetic, etc. in find_fit?https://ask.sagemath.org/question/46299/rounding-using-modular-arithmetic-etc-in-find_fit/I'm learning how to use find_fit and it works great for polynomials, but I'd like to include expressions that require integers. My variables are all integers, and my coefficients are expected to be relatively simple rationals (i.e. small denominators). In particular, I'd like to use a model like:
model(x,y) = (a*x+b*y+c)%(d*x+e*y+f)
However, I get the expected error:
TypeError: unsupported operand parent(s) for %: 'Symbolic Ring' and 'Symbolic Ring'
If I try to convert (dx+ey+f) to an integer within the model using int(), ceiling(), etc. then it won't convert, since of course it's a symbolic expression. Is there a way to round within a symbolic expression? Or any suggestions for other workarounds? Thanks!
edit: I was able to get it to run, but it doesn't provide an acceptable solution. I imagine it's due to how find_fit works with user-defined functions but I don't know enough about the inner-workings to work that out. Here is my code:
data = [(i,(i%2) ) for i in range(30)]
var('a, b, c, d, x')
def f(x, a, b, c, d):
return int(a+b*x)%int(c*x+d)
fit = find_fit(data, f, parameters = [a, b, c, d], variables = [x], solution_dict = True)
print fit
and the output is
{d: 1.0, c: 1.0, b: 1.0, a: 1.0}
I would like it to return, say,
{d: 2.0, c: 0.0, b: 1.0, a: 0.0}
Is there a way to make this work a bit better for my needs?ctennenhSun, 21 Apr 2019 14:20:34 +0200https://ask.sagemath.org/question/46299/Multivariable equation in multiplicative group Z_phttps://ask.sagemath.org/question/39004/multivariable-equation-in-multiplicative-group-z_p/ I am able to, in wolfram alpha, plug in the equation
> 11=x*(y^119)^149mod151
where all numbers are in Z_151
and wolfram is able to give me a set of non-zero solutions (x,y) that I think satisfy (11*y^119, y)
I have tried using symbolic equations and the sage quickstart for number theory to replicate this functionality, but I am getting stuck on some integer conversion TypeErrors in sage.
I have tried to set it up like:
> x,y = var('x,y');
> qe=(mod(x*(y^119)^149,151)==mod(11,151))
Can someone help me set up this equation, and then solve for all possible non-zero solutions?
THanks!dcoleFri, 29 Sep 2017 15:19:36 +0200https://ask.sagemath.org/question/39004/calculating the modulo of a "number" in a binary finite fieldhttps://ask.sagemath.org/question/38735/calculating-the-modulo-of-a-number-in-a-binary-finite-field/Polynomial equations in binary finite fields are often represented as numbers. eg. $x^2 + 1$ is basically the same thing as $1x^2 + 0x^1 + 1x^0$ and thus would be represented as $101_2$ or $5_{10}$.
In that spirit I'm trying to use a hexadecimal number to represent a polynomial equation. The polynomial equation is larger than the modulo I'm using ($x^{113} + x^9 + 1$) so I'm trying to get the result of the modulo operation.
Here's what I've tried:
BF.<a> = FiniteField(2^113);
X = Integer(0x61661990d3b1f7a608ad095a01d727380850d2592f5b9f88f66a20e8);
X_bf = BF._cache.fetch_int(X);
X_bf.mod(x^113 + x^9 + 1)
Unfortunately, this doesn't seem to work and instead gets me the following error messages:
TypeError Traceback (most recent call last)
<ipython-input-4-dba4addbde0d> in <module>()
2
3 X = Integer(Integer(0x61661990d3b1f7a608ad095a01d727380850d2592f5b9f88f66a20e8));
----> 4 X_bf = BF._cache.fetch_int(X);
5
6 X_bf.mod(x**Integer(113) + x**Integer(9) + Integer(1))
/home/sage/sage-8.0/src/sage/rings/finite_rings/element_ntl_gf2e.pyx in sage.rings.finite_rings.element_ntl_gf2e.Cache_ntl_gf2e.fetch_int (/home/sage/sage/src/build/cythonized/sage/rings/finite_rings/element_ntl_gf2e.cpp:7596)()
400 raise ValueError("Cannot coerce element %s to this field." % e)
401
--> 402 cpdef FiniteField_ntl_gf2eElement fetch_int(self, number):
403 """
404 Given an integer less than `p^n` with base `2`
/home/sage/sage-8.0/src/sage/rings/finite_rings/element_ntl_gf2e.pyx in sage.rings.finite_rings.element_ntl_gf2e.Cache_ntl_gf2e.fetch_int (/home/sage/sage/src/build/cythonized/sage/rings/finite_rings/element_ntl_gf2e.cpp:7212)()
431
432 if number < 0 or number >= self.order():
--> 433 raise TypeError("n must be between 0 and self.order()")
434
435 if isinstance(number, int) or isinstance(number, long):
TypeError: n must be between 0 and self.order()
I realize that what I'm doing isn't technically a finite field but idk how else I might get a "number" turned into a polynomial equation.
Any ideas?neubertMon, 04 Sep 2017 08:02:35 +0200https://ask.sagemath.org/question/38735/pre-reduction multiplication result in binary fieldhttps://ask.sagemath.org/question/38734/pre-reduction-multiplication-result-in-binary-field/The following will do multiplication in a finite field:
X = Integer(0x009D73616F35F4AB1407D73562C10F);
Y = Integer(0x00A52830277958EE84D1315ED31886);
F.<x> = GF(2)[];
p = x^113 + x^9 + 1;
BF = GF(2^113, 'x', modulus=p);
X_bf = BF._cache.fetch_int(X);
Y_bf = BF._cache.fetch_int(Y);
temp = Y * X; temp
The problem with this is that the result you get back has had the reduction step already ran. I'd like to see the multiplication result pre-reduction.
Any ideas?neubertMon, 04 Sep 2017 05:44:52 +0200https://ask.sagemath.org/question/38734/Solving modular systems of equationhttps://ask.sagemath.org/question/37146/solving-modular-systems-of-equation/ I am trying to solve a system of equations mod $p$, for $p$ prime. I have build matrices $A$ and $b$ and I am using the function solve_right() to solve $Ax = b$. But I need to solve $Ax = b$ mod $p$. Is there any functions that could do that ? thanks !Sasha-dptSun, 02 Apr 2017 17:31:52 +0200https://ask.sagemath.org/question/37146/Speeding up power_modhttps://ask.sagemath.org/question/35296/speeding-up-power_mod/ Recently I've been working a bit with modular arithmetic and big numbers. An incredibly useful tool for that is modular exponentiation by repeated squaring, implemented using power_mod function. Earlier I was using Julia for that (together with BigInt there), and I was quite disappointed to find out that in Sage modular exponentiation is noticably slower for (very) large moduli - slowdown by a factor of 3 modulo 10^5000 and by a factor of almost 10 modulo 10^50000 (I didn't test larger ones). I don't know if the reason for this is that Julia uses some faster modular exponentiation algorithm (I didn't manage to find how it is implemented), or whether it is because the BigInt makes it that significantly easier for CPU to work with these.
So my question is, is there some way to speed up the modular exponentiation in Sage?WojowuFri, 28 Oct 2016 22:00:30 +0200https://ask.sagemath.org/question/35296/Can't multiply two variables together due to type (I think)https://ask.sagemath.org/question/25001/cant-multiply-two-variables-together-due-to-type-i-think/ I'm trying to digitally sign a test message in Sage using DSA (DSS). After running my code, I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_28.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("IyBDaGVjayB0aGUgc2lnbmF0dXJlCmNoZWNrX3NpZyhtLHAscSxnLHIscyx5KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpUuKk65/___code___.py", line 3, in <module>
exec compile(u'check_sig(m,p,q,g,r,s,y)
File "", line 1, in <module>
File "/tmp/tmppjN9Gi/___code___.py", line 7, in check_sig
u_2 = mod(r*w,q)
File "element.pyx", line 1701, in sage.structure.element.RingElement.__mul__ (sage/structure/element.c:14531)
File "coerce.pyx", line 856, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:8169)
TypeError: unsupported operand parent(s) for '*': 'Ring of integers modulo 98007532214006523718033513010741500921668410005086660781341579786663143142637' and 'Ring of integers modulo 44449'
The offending line is: `u_2 = mod(r*w,q)`. I think the issue here is I'm multiplying `r` and `w` where:
r = mod(mod(g^k,p),q)
w = mod(1/s,q)
However, these are both `mod q`. Why can't I perform a multiplication on them? Is there some kind of casting I have to do?darxius_sageTue, 25 Nov 2014 17:22:21 +0100https://ask.sagemath.org/question/25001/Modular reduction in Galois fieldshttps://ask.sagemath.org/question/10069/modular-reduction-in-galois-fields/I want to compute x^6 mod x^5+x^2+1 in the Galois Field GF(2^5). Does anyone know how to do this in SAGE?Christian_KossmannSun, 28 Apr 2013 07:04:04 +0200https://ask.sagemath.org/question/10069/Discrepancy between Graph.modular_decomposition() and Wikipediahttps://ask.sagemath.org/question/9267/discrepancy-between-graphmodular_decomposition-and-wikipedia/I am either confused, or am seeing a bug, or there's a bug on Wikipedia.
There's a diagram on the page about modular decomposition referenced by the docs: http://en.wikipedia.org/wiki/Modular_decomposition http://en.wikipedia.org/wiki/File:ModularDecomposition.png
It shows a 'series' module containing 2,3,4.
But when I recreate that graph and run modular_decomposition() on it I get something that seems different:
<pre>
W = Graph()
W.add_edges([[1,2],[1,4],[1,3],[2,4],[2,5],[2,6],[2,7],[3,4],[3,5],[3,6],[3,7],[4,5],[4,6],[4,7],[5,6],[5,7],[6,8],[6,9],[6,10],[6,11],[7,8],[7,9],[7,10],[7,11],[8,9],[8,10],[8,11],[9,10],[9,11]])
W.plot(vertex_size=100)
W.modular_decomposition()</pre>
results in
<pre>
('Prime',
[
('Serie',
[
('Parallel',
[
10,
11
]
),
9,
8
]
),
('Parallel',
[
6,
7
]
),
5,
1,
4,
('Parallel',
[
2,
3
]
)
]
)</pre>
Which shows 8,9,10,11 in a 'series' but not 2,3,4.
Am I getting something wrong or missing something?akmSun, 26 Aug 2012 16:55:25 +0200https://ask.sagemath.org/question/9267/