Ask Your Question

castor's profile - activity

2018-01-04 14:51:09 -0500 commented question Changes of variable from quartic to Weierstrass

Just a tiny modification of the above code:

u,v=polygens(QQ,'u,v')
E=Curve(-v^2 + u^4-2*u^3+5*u^2+8*u+4)
Jacobian(E, morphism=True)

it yields:

Scheme morphism:
  From: Affine Plane Curve over Rational Field defined by u^4 - 2*u^3 + 5*u^2 - v^2 + 8*u + 4
  To:   Elliptic Curve defined by y^2 = x^3 - 121/3*x + 1690/27 over Rational Field
  Defn: Defined on coordinates by sending (u, v) to
        (7/3*u^4*v + 58/3*u^3*v - 1/3*u^2*v - 88/3*u*v - 8/3*v : -12*u^6 + 12*u^5 + 120*u^4 + 120*u^3 + 180*u^2 + 12*u - 48 : -v^3)
2017-01-25 08:33:28 -0500 commented answer points on elliptic curve

Thanks @nbruin for the correction, now using the second suggested test we may go as

E=EllipticCurve([0,0,0,-3267,45630])
P=E([51,-108])
F=EllipticCurve([0,27,0,-4077,51705])
Q=F([-57,432])
[(m,n) for m in [1..100] for n in [1..100] if (m*P).xy()[0] == (n*Q).xy()[0]]

the result is simply [].

2017-01-24 15:05:56 -0500 answered a question points on elliptic curve

I guess the second point Q is given by [-57,216]. I use it in what follows.

    E=EllipticCurve([0,0,0,-3267,45630])
    P=E([51,-108])
    Q=E([-57,216])
    [(m,n) for m in [1..10] for n in [1..10] if (m*P)[0]==(n*Q)[0]]

The result is:

[(2, 2), (4, 4), (6, 6), (8, 8), (10, 10)]

e.g. 2P=(339 : 6156 : 1) and 2Q=(339 : -6156 : 1).

2017-01-04 12:30:45 -0500 answered a question FunctionField with more than 1 variable

Thank you for the workaround, it helps to compute what I need. There is a small gap at the end, I need to define a polynomial ring over the function field and factor certain polynomials over it. The error message is that it is not implemeted, but I know some factors and I could reduce the problem to a quadratic polynomial.

2017-01-04 08:41:55 -0500 asked a question FunctionField with more than 1 variable

I have tried the following to construct an appropriate function field:

F.<a,b>=FunctionField(QQ,2)

as a result I got

TypeError: create_key() got multiple values for keyword argument 'names'

after that I looked for the documentation but only find one variable examples. I also tried a few more versions like

F.<a,b>=FunctionField(QQ,names=('a','b'))

but did not work. Thank for any advice in this direction in advance.

2016-11-28 08:13:01 -0500 received badge  Nice Answer (source)
2016-11-27 12:05:54 -0500 answered a question How to get latex expression in exponential notation?

The following may help:

P.<J,K>=LaurentPolynomialRing(QQ,2)
u1=J/K
latex(u1)

it gives what you need J K^{-1}.

2016-11-27 05:30:33 -0500 received badge  Scholar (source)
2016-11-27 05:23:33 -0500 answered a question Constant coefficient of Laurent Polynomials

You may try the following:

a = var(",".join( "a%i" %i for i in range(0, 7)))
R.<x,y> = LaurentPolynomialRing(SR,2)
f = x*y + a6*x + a4*y + x*y^-1 + x^-1*y + a3*y^-1 + a1*x^-1 + x^-1*y^-1
(f/(x^1*y^0)).constant_coefficient()

It gives a6 as you expect and e.g.

 (f/(x^0*y^1)).constant_coefficient()

is equal to a4. Also you can determine the coefficient of any monomial:

(f/(x^0*y^1)).coefficient(x^-1*y^-2)

is 1.

2016-11-20 15:39:14 -0500 received badge  Good Answer (source)
2016-11-19 17:07:50 -0500 received badge  Nice Answer (source)
2016-11-19 16:15:54 -0500 answered a question General power of a matrix?

In many cases the following works:

A=matrix(SR,[[1,2],[2,1]])
D,P=A.eigenmatrix_right()
n=var('n')
An=P*matrix(SR,[[D[0,0]^n,0],[0,D[1,1]^n]])*P.inverse()
An

Here one obtains An as follows:

[1/2*3^n + 1/2*(-1)^n 1/2*3^n - 1/2*(-1)^n]
[1/2*3^n - 1/2*(-1)^n 1/2*3^n + 1/2*(-1)^n].

It does not work if the given matrix is not similar to a diagonal matrix.

2016-11-03 11:59:49 -0500 commented answer point addition on elliptic curve

In fact I just picked up some points to demonstrate point addition over this domain. As I see now your point Q is given, it is not a general point (X,Y) so I am not sure if you really need this FunctionField stuff. Anyway, you can combine @slelievre code with mine:

k.<a> = NumberField(x^4 - 5*x^2 - 32)
K.<B> = k.extension(x^2+2)
kX.<X>=FunctionField(K)
R.<Y> = kX[]
kY.<Y> = kX.extension(Y^2-X^3+3267*X-45630)
E=EllipticCurve(kY,[0,0,0,-3267,45630])
P=E(15+36*B, 27*a*(a^2-4*B-5))
Q=E(51,108)
P+Q

that provides

((-a^3 + 3*a - 38)*B + 1/2*a^3 - 21/2*a + 7 : (-20*a^3 + 78*a - 58)*B +
11/2*a^3 - 375/2*a - 304 : 1)

and 2*P+Q is a nice point

(-57 : 216 ...
(more)
2016-11-02 14:58:08 -0500 answered a question point addition on elliptic curve

Something that may help:

k.<a,b>=NumberField([x^2 - 30*x + 2817,x^4 + 30*x^3 - 18252*x^2 + 280530*x +6465339])
kX.<X>=FunctionField(k)
R.<Y> = kX[]
kY.<Y> = kX.extension(Y^2-X^3+3267*X-45630)
E=EllipticCurve(kY,[-3267,45630])
Q=E([X,Y])
P1=E([15,0])
P2=E([1/5184*(-b^3 - 45*b^2 + 14985*b - 133515),0])
print(P1+Q)
print(P2+Q)

Here the answer is as follows:

((15*X - 2817)/(X - 15) : ((-2592)/(-X^2 + 30*X - 225))*Y : 1)

and

(((-1/5184*b^3 - 5/576*b^2 + 185/64*b - 4945/192)*X + 5/864*b^3 +
25/96*b^2 - 2775/32*b + 114869/32)/(X + 1/5184*b^3 + 5/576*b^2 -
185/64*b + 4945/192) : ((5/576*b^3 + 25/64*b^2 - 8325/64*b +
449151/64)/(-X^2 + (-1/2592*b^3 - 5/288*b^2 + 185/32*b - 4945/96)*X -
5/1728*b^3 - 25/192*b^2 + 2775/64*b - 219413/64))*Y : 1).
2016-10-28 17:15:35 -0500 answered a question Elliptic curve defined with parameter

You may try the following

K.<u> = FunctionField(GF(5,'a'))
E=EllipticCurve([0,u,0,16*u,0])

there are many functions to be applied for your curve E: SageMath Doc. Define a point e.g. and compute the double point:

P=E([0,0])
2*P

To determine some more "small" points on your curve:

[E.lift_x(s+t*u, all=True) for s in [0..4] for t in [0..4] if E.is_x_coord(s+t*u)]

which provides:

[[(0 : 0 : 1)], [(4*u : 2*u : 1), (4*u : 3*u : 1)], [(4 : 2 : 1), (4 : 3 : 1)]].
2016-10-27 11:53:47 -0500 commented answer programming of looping to print selected value of m

Is not x=(121043P-2*P)[0]?

2016-10-27 07:23:50 -0500 answered a question Polynomial ring modulus integer to univariate polynomial ring over the Integers

Your code is almost there, probably you need the following:

from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler
f=DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], 8, 3.0)()
R.<X> = PolynomialRing(GF(13))
Y.<t> = R.quotient(X^1024 + 1)
Y(f)

Here you obtain

10*t^7 + 5*t^6 + 3*t^4 + 7*t^3 + 12*t^2 + 2*t + 1
2016-10-27 07:14:36 -0500 answered a question programming of looping to print selected value of m

You may try something like

Qp=pAdicField(13)
E=EllipticCurve(Qp,[0,0,0,-3267,45630])
P=E([-21,324])
p=13 #because I am working 13-adically
for m in [1..10]:
    R=12104*m*P
    S=-2*P
    Q=R+S
    x=Q[0]    
    y=Q[1]
    W=(81*x^16 + 40662*x^15 + 14353281*x^14 - 460241028*x^13 - 644722959186*x^12 + 39379675354740*x^11 + 5212980804862026*x^10 - 415546630058854656*x^9 - 8202010485984353739*x^8 + 1396767997483732402758*x^7 - 27550698906220673513787*x^6 - 1044392234943529703379852*x^5 + 60770398462922893831446348*x^4 - 1284453663719469166478575296*x^3 + 14183844641879715988450074288*x^2 - 81800517874945025246941522368*x + 196162341839727571433321441856)- (3240*x^14 + 456840*x^13 + 188268624*x^12 - 45834271200*x^11 - 2435651997264*x^10 + 682353767281968*x^9 - 7053953405575680*x^8 - 2553415737499629216*x^7 + 98906717445152189544*x^6 + 1348117411901578667784*x^5 - 162666175355778441465360*x^4 + 4276857451171442758058304*x^3 - 54456600108308451946891776*x^2 + 350065581968511893813480064*x - 918312303919436410092339456)*y
    D=W[0]
    T=kronecker(D,p)  
    if T == 1:
        print(m)

but when m=3 you have

W=13^-32 + 12*13^-31 + 5*13^-30 + 4*13^-29 + 10*13^-28 + 13^-27 + 10*13^-26 + 8*13^-25 + 3*13^-24 + 11*13^-23 + 11*13^-22 + 9*13^-21 + 12*13^-20 + 4*13^-19 + 6*13^-18 + 13^-17 + O(13^-16)

and D=W[0] will not be defined. The same happens for m=5 also and for many other values I would guess.

2016-10-27 06:45:57 -0500 answered a question change p-adic precision in elliptic curve

Your code is pretty close to what you want:

Qp=pAdicField(13,4)
E=EllipticCurve(Qp,[0,0,0,-3267,45630]); E
P=E([-21,324]);P

the answer is

(5 + 11*13 + 12*13^2 + 12*13^3 + O(13^4) : 12 + 11*13 + 13^2 + O(13^4) : 1 + O(13^4)).
2016-10-16 15:39:14 -0500 answered a question n-th power of matrices

You can find an interactive Sage application here: http://shrek.unideb.hu/~tengely/Magya... the last part is "Mátrixok n-edik hatványának zárt alakja", it is in Hungarian, but the mathematics and Sage command will help I think. In case of your example this code will not work, the eigenvalue 1 has multiplicity larger than 1. To make it work the computation related to the eigenvectors should be modified. At the above page the matrix is given by matrix([[1,2,1],[6,-1,0],[-1,-2,-1]]) and after pushing the "Számolás" button you see the general form of the $n$th power of this matrix. If you have a diagonalizable matrix the above code should do the job.

2016-10-12 11:26:41 -0500 received badge  Student (source)
2016-10-12 10:40:53 -0500 asked a question Groupring element in pretty_print

I have the following code:

G37=GroupAlgebra(SymmetricGroup(3),GF(7))
M37=MatrixSpace(G37,2,2)
S3=SymmetricGroup(3).list()
@interact
def _(a11=input_grid(1,6, default = [1,2,0,0,0,0], label='$a_{11}$'),a12=input_grid(1,6, default = [0,1,2,2,3,3], label='$a_{12}$'),a21=input_grid(1,6, default = [0,3,4,2,3,4], label='$a_{21}$'),a22=input_grid(1,6, default = [0,1,1,0,0,0], label='$a_{22}$')):
            A11=sum([G37(a11[0][k])*G37(S3[k]) for k in [0..5]])
            A12=sum([G37(a12[0][k])*G37(S3[k]) for k in [0..5]])
            A21=sum([G37(a21[0][k])*G37(S3[k]) for k in [0..5]])
            A22=sum([G37(a22[0][k])*G37(S3[k]) for k in [0..5]])
            pretty_print(html('$A=%s$'%latex(M37([A11,A12,A21,A22]))))

The first element $A_{11}$ appears as $+2(1,2)$ instead of $()+2(1,2).$ Is it possible to protect the groupring element $()$ somehow? Thanks for the answers in advance.

2016-10-12 10:23:19 -0500 commented answer solve linear system in GF(7)

Completely right, thank you for the comment.

2016-05-30 05:09:20 -0500 commented answer solve linear system in GF(7)

It works in the same way:

solve_mod(eqns,49)

The result is:

[(20, 5, 26, 14, 10, 45)].
2016-05-29 16:03:20 -0500 answered a question solve linear system in GF(7)
var('A0','A1','B0','B1','B2','B3')
eqns =[-A0 + 5*A1 + B0 + 2*B1 + 4*B2 + B3 + 3 == 0,-3*A0 + 2*A1 + B0 + 4*B1 + 2*B2 + B3 + 1 == 0,-6*A0 + 6*A1 + B0 + 6*B1 + B2 + 6*B3 - 6 == 0,-5*A0 + 2*A1 + B0 + B1 + B2 + B3 - 5 == 0,-4*A0 + 2*A1 + B0 + 3*B1 + 2*B2 + 6*B3 + 6 == 0,-2*A0 + 4*A1 + B0 + 5*B1 + 4*B2 + 6*B3 + 6 == 0]
solve_mod(eqns,7)

The result is:

[(6, 5, 5, 0, 3, 3)].
2016-05-03 17:11:02 -0500 answered a question Help with matrices over multivariable polynomial ring

You can define a function to do the same for arbitrary $n$ (I am just guessing the shape of your matrices)

def MultiMatrix(n):
      R = PolynomialRing(GF(2), n, 'x')
      M = MatrixSpace(R,n,n)
      return M([[R.gen(k)^(2^l) for k in [0..n-1]] for l in [1..n]])

Then we have

MultiMatrix(3)
[x0^2 x1^2 x2^2]
[x0^4 x1^4 x2^4]
[x0^8 x1^8 x2^8]

and

MultiMatrix(4)
[ x0^2  x1^2  x2^2  x3^2]
[ x0^4  x1^4  x2^4  x3^4]
[ x0^8  x1^8  x2^8  x3^8]
[x0^16 x1^16 x2^16 x3^16].
2016-03-24 13:34:19 -0500 received badge  Nice Answer (source)
2016-03-23 15:43:10 -0500 received badge  Editor (source)
2016-03-23 15:42:39 -0500 answered a question solve a system of two equations for a derivative

In your case it would be something like this:

var('t');
x=function('x')(t)
y=function('y')(t)
de1 = diff(x,t) - diff(y,t) == x
de2 = diff(y,t) == y
desolve_system([de1, de2], [x,y])

and the result is as follows:

[x(t) == t*e^t*y(0) + e^t*x(0), y(t) == e^t*y(0)]
2016-03-23 15:30:35 -0500 answered a question elliptic curve finite field

As an example:

E=EllipticCurve(GF(11),[2,7])
E.plot()
2015-11-01 02:46:17 -0500 received badge  Nice Answer (source)
2015-10-31 16:42:23 -0500 received badge  Teacher (source)
2015-10-31 15:41:24 -0500 answered a question Reliable integer root function?

nth_root(n,truncate_mode=1) does the job, e.g. Integer(124).nth_root(3,truncate_mode=1) is (4,False)

2015-06-08 16:24:59 -0500 answered a question Assigning variables in a list

As far as I see you look for something like:


var('x,y,z,w,a,b,c,d') 
V2=[x,y,z,w,a,b,c,d]
s=[V2[i]==V2[7-i] for i in [0..3]]
solve(s,x,y,z,w,a,b,c,d)

Here one obtains that


[[x == r1, y == r2, z == r3, w == r4, a ==r4, b == r3, c == r2, d == r1]]
, where r1,r2,r3,r4 are parameters.

2013-07-12 09:05:15 -0500 received badge  Supporter (source)
2013-07-12 09:04:49 -0500 commented answer Strange output using qsub

Thank you for the hint to run sage QE.sage instead of sage < QE.sage. Now I obtained the correct output. The examples provided in the documentation work well. I modified the following: @parallel def f(a,b): return a*b for X, Y in sorted(list(f([(2,3),(3,5),(5,7)]))): print X, Y since I also have a function in two variables. I also tried to fix one of the variables, but it turned out that the problem is different. In my function I use Pari procedures as well, I try to figure out if that is the problem. I found a nice package mpi4py, that needs more work than @parallel but seems very useful for future computations. I am at the beginning of the road. There are three queues test.q, serial.q and parallel.q I do not know where the relevant files are ... (more)

2013-07-10 10:27:58 -0500 asked a question Strange output using qsub

I wrote a Sage code and it works fine on my notebook: nohup < QE.sage > QE.txt & the output file QE.txt looks OK. When I try to use the same code on a cluster using qsub -q test.q QE.sh then the output is

----------------------------------------------------------------------
| Sage Version 5.9, Release Date: 2013-04-30                         |
| Type "notebook()" for the browser-based notebook interface.        |
| Type "help()" for help.                                            |
----------------------------------------------------------------------
.[?1034hsage: ....: ....: ....: sage: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ...
.: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ..
..: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: .
...: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....:
....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....:
 ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....
: sage: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ...
.: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: sage: sage: ....: ....: ....: ....: ....: ....: ....:
Exiting Sage (CPU time 0m1.86s, Wall time 0m1.88s).

here QE.sh is as follows

#!/bin/sh
#$ -N QE.sage
module load sage
sage < QE.sage

Also if I use @parallel() on my notebook, then it works as expected:

@parallel(ncpus=2)
def szamol(a,b):
  w=QEllCur([a,b,1])
  if w==-1:
    return "bad input"
  else:
    return w

W=list(szamol([(a,b) for a in range(-2,3) for b in range(-2,3)]))
for X, Y in sorted(W): print X, Y

The CPU time is about 2 sec on my notebook using 2 cores on the cluster using less than 12 cores it prints the first pair and that is it after running (not waiting in the que) more than 2 hours.

My questions are:

  1. how to get the same output using my code on a (linux) cluster as using it on my (linux) notebook?

  2. how to use @parallel() on a cluster?