Ask Your Question

klx's profile - activity

2023-02-21 14:55:33 +0200 received badge  Notable Question (source)
2023-02-12 05:05:35 +0200 received badge  Famous Question (source)
2022-12-29 16:25:16 +0200 received badge  Notable Question (source)
2022-10-15 13:40:55 +0200 received badge  Popular Question (source)
2022-10-06 16:15:40 +0200 received badge  Notable Question (source)
2022-10-06 16:15:40 +0200 received badge  Popular Question (source)
2022-10-04 00:44:39 +0200 commented answer finding 4-torsion point on elliptic curve

https://doc.sagemath.org/html/en/reference/arithmetic_curves/sage/schemes/elliptic_curves/ell_point.html

2022-04-13 02:22:59 +0200 marked best answer ExtGCD in Finite Fields

I want to implement Extended GCD with SageMath so that the internal can be printed. The below is a modification of this. This should be straightforward, however, I might miss something;

def extended_euclides(a,b):

    s = 0; old_s = 1
    t = 1; old_t = 0
    r = b; old_r = a

    while r != 0:
        quotient,rem = old_r.quo_rem(r)

        old_r, r = r, old_r - quotient*r
        old_s, s = s, old_s - quotient*s
        old_t, t = t, old_t - quotient*t
    return [old_r, old_s, old_t]

K.<a> =  GF(2^8, modulus=x^8+x^4+x^3+x+1)
print(K)
print("m = ", K.modulus())

g = a^7 + a^5 + a^4 + a
h = a^4 + a^2 + 1

r,s,t = extended_euclides(g,h)

print("The GCD of \n \t [ {} ] and  \n \t [ {} ]  is \n\t [ {} ]".format(g,h,r))
print("Its B├ęzout coefficients are {} and {}".format(s,t))
assert r == g.gcd(h), "The gcd should be {}!".format(g.gcd(h))
assert r == s*g + t*h, "The cofactors are wrong!"

In the end, I've got the assertion error AssertionError: The gcd should be 1!

Any idea to solve this?

2022-04-13 02:22:58 +0200 commented answer ExtGCD in Finite Fields

I see. I rather consider calculating it over the finite field instead of polynomials. Since the polynomials are always l

2022-04-12 11:14:57 +0200 edited question ExtGCD in Finite Fields

ExtGCD in Finite Fields I want to implement Extended GCD with SageMath so that the internal can be printed. The below is

2022-04-12 11:02:29 +0200 asked a question ExtGCD in Finite Fields

ExtGCD in Finite Fields I want to implement Extended GCD with SageMath so that the internal can be printed. The below is

2022-02-05 12:52:08 +0200 received badge  Popular Question (source)
2021-12-07 15:47:37 +0200 received badge  Famous Question (source)
2021-11-10 19:16:40 +0200 commented answer Using SageMath Finite Field Extension on Python.

This should be the code. You have forgotten the ** instead of ^ from sage.all import * F = GF(2) R = F['x']; (x,) = R.

2021-11-10 19:04:19 +0200 commented answer Using SageMath Finite Field Extension on Python.

This should be the code. You have forgotten the ** instead of ^ from sage.all import * F = GF(2) R = F['x']; (x,) = R.

2021-11-10 18:41:27 +0200 marked best answer Using SageMath Finite Field Extension on Python.

Yes, I want to the reverse, use the SageMath in Python.

I've seen this on ask.sagemath and stackoverflow

I want to use this in Python

k = GF(2)
R.<x> = k[]
k.extension(x^1000 + x^5 + x^4 + x^3 + 1, 'a')

The python code

from sage.all import *

F = GF(2)
R.<x> = k[]
K = F.extension(x^4 + x + 1, 'a')

print(K)

the R.<x> = k[] fails...

Is there a way to do this in python?

My final aim is finding the multiplicative inverse of an element using python with the sagemath import.

2021-11-10 18:41:21 +0200 commented answer Using SageMath Finite Field Extension on Python.

This should be the code. You have forgotten the ** instead of ^ from sage.all import * F = GF(2) R = F['x']; (x,) = R.

2021-11-10 17:44:41 +0200 edited question Using SageMath Finite Field Extension on Python.

Using SageMath Finite Field Extension on Python. Yes, I want to the reverse, use the SageMath in Python. I've seen this

2021-11-10 17:43:18 +0200 asked a question Using SageMath Finite Field Extension on Python.

Using SageMath Finite Field Extension on Python. Yes, I want to the reverse, use the SageMath in Python. I've seen this

2021-11-03 19:05:08 +0200 commented answer Change of variables in symbolic computation

Also, I've seen this answer of yours and the function is not working, at least for me. Something has changed with Python

2021-11-03 19:04:41 +0200 commented answer Change of variables in symbolic computation

Also, I've seen this answer of yours and the function is not working, at least for me.

2021-11-03 19:04:16 +0200 commented answer Change of variables in symbolic computation

Also, I've seen this answer of yours and the function is not working, at least for me.

2021-11-03 18:59:39 +0200 commented answer Change of variables in symbolic computation

I guess substitute_expression is for something else, however, I couldn't find it in the docs.

2021-11-03 09:39:49 +0200 marked best answer Change of variables in symbolic computation

I need to change Y into 1/2 *( y - a1 * x - a3) so that I can change variables in Elliptic curves.

var("X,Y,Z,x,y,a1,a2,a3,a4,a5,a6")
F = Y^2  *Z + a1 * X*Y *Z + a3 *Y *Z^2 - X^3 - a2 *X^2 * Z + a4*X*Z^ 2 + a6*Z^3
print(F)
F.substitute_expression(Y == 1/2 *( y - a1 * x - a3))  
print(F)

This produces an error on the 4th line;

AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'substitute_expression'

What is the proper way to change the variables?

2021-11-02 19:11:58 +0200 asked a question Change of variables in symbolic computation

Change of variables in symbolic computation I need to change Y into 1/2 *( y - a1 * x - a3) so that I can change variabl

2021-02-16 14:53:44 +0200 answered a question evaluating inverse erf
def probit(p):
    return (sqrt(2)*erfinv(2*p-1)).n()

print(probit(0.025)) #Wikipedia Verification
print(probit(0.975))

P1 = [] 
for n in xsrange(1,100):
    P1.append( ( n , probit(n/100.0)) )

G1 = point2d(P1,color='blue',pointsize=10)
G1.show()
2021-02-16 13:50:52 +0200 commented answer evaluating inverse erf
2021-02-16 13:47:44 +0200 asked a question probit, erfinv, and inconsistency with Wikipedia

I've used the erfinv

def probit(p):
    return e^(sqrt(2)*erfinv(2*p-1)).n()

print(probit(0.025))
print(probit(0.975))

and outputs

0.140863494093217
7.09907138423134

Wikipedia states that

$\operatorname{probit}(0.025) = -1.96 = -\operatorname{probit}(0.975)$

Interestingly

print(e^(sqrt(2)*erfinv(1/2)).n())

outputs

1.96303108415826

Am I missing a point here?

2021-02-06 13:18:41 +0200 received badge  Enthusiast
2021-01-19 20:28:01 +0200 commented answer Solving symbolic equations to IntegerModRing(26)

[k_1 + 11x2, k_2 + 11x2, k_3, k_4 + 1, x1 + 23*x2, 2]. I've got this as an experiment, what is the value of k_3 and the last 2?

2021-01-19 20:24:05 +0200 commented answer Solving symbolic equations to IntegerModRing(26)

No automatic way form basis to eq.sub?

2021-01-19 20:10:04 +0200 received badge  Commentator
2021-01-19 20:10:04 +0200 commented answer Solving symbolic equations to IntegerModRing(26)

Sorry, $i$ was a typo that takes your time. Is this the only way? I was expecting that the symbolic package can try solve by Gaussian Elimination.

2021-01-19 17:21:56 +0200 asked a question Solving symbolic equations to IntegerModRing(26)

To solve the Hill Cipher a have setup symbolic equations;

R = IntegerModRing(26)
a,b,c,d,x1,x2 = var('k_1,k_2,k_3,k_4,x1,x2')
K = Matrix(SR,[[a,b],[c,d]]); K
print(K)

pl = vector(SR,[1,29])
ci = vector(SR,[8,21])
eq1,eq2 = (K*pl-ci)

pl = vector(SR,[25,22])
ci = vector(SR,[x1,i])
eq3,eq4 = (K*pl-ci)


pl = vector(SR,[7,16])
ci = vector(SR,[x2,19])
eq5,eq6 = (K*pl-ci)

solve((eq1,eq2,eq3,eq4,eq5,eq6), [a,b,c,d,x1,x2])

There is a problem that The symbolic equations are not working modulo 26. For example, the first equation is

k_1 + 29*k_2 - 8

So how can I properly turn them into modulo 26 and solve the equations in modulo 26?

2021-01-16 15:50:02 +0200 marked best answer Drawing a line not segment

I want to draw a line passing through a point P and Q on an elliptic curve.

E = EllipticCurve([0,0,0,4,20])
print(E)
E.plot(xmin=-20, xmax=20, ymin=-20, ymax=20)
plotE = E.plot()
P=E(1,5)
R = - (P + P)
plotE += line([P.xy(),R.xy()],color='red')

Using this only draw a line segment from P to Q. How can I draw a line? I've looked on the doc but did not see an option for this. Any solution?

2021-01-16 15:50:02 +0200 commented answer Drawing a line not segment

Sorry, cells mixed! I have put it into a curve defined over GF. Yes, it is working. Thanks.

2021-01-16 10:56:45 +0200 received badge  Notable Question (source)
2021-01-15 23:58:51 +0200 commented answer Drawing a line not segment

PR = (lift(vR - vP)).normalized() is needed and after that TypeError: unsupported operand parent(s) for -: 'Vector space of dimension 2 over Finite Field of size 29' and 'Vector space of dimension 2 over Symbolic Ring' on the last line