Implementing linear maps and their inverses in SageMath and Magma

asked 2025-01-01 20:25:05 +0100

anonymous user

Anonymous

updated 2025-01-07 23:11:07 +0100

I am currently trying to implement the linear maps in this post: https://math.stackexchange.com/questi... in Magma and SageMath. So far I have successfully implemented the maps in Magma and am currently trying to implement $X$ in SageMath.

My Magma code for $X$:

k := 8;
Fq := GF(2^k);
F := FunctionField(Fq);
places := Places(F, 1);
G := &+[places[i]: i in [2..k]];
B1 := Basis(G);
places := [places[i]: i in [k+1..2*k]];
X_matrix := Matrix([[Evaluate(f, P): P in places]: f in B1]);
X := function(f)
  return Vector([Evaluate(f, P) : P in places]);
end function;
X_inv := function(v)
   coeffs:= Solution(X_matrix, v);
   return &+[coeffs[i] * B1[i]: i in [1..k]];
end function;

My SageMath code for $X$:

k = 8
m = 16
Fq = GF(2^k)
F.<x> = FunctionField(Fq)
places = F.places()
G = sum(places[i] for i in range(1,k))
B1 = list(reversed(G.basis_function_space()))
places = places[k:2*k]
X_matrix = matrix([[f.evaluate(p) for p in places] for f in B1])
def X(f):
    return vector([f.evaluate(p) for p in places])
def X_inv(v):
    coeffs = X_matrix.solve_right(v)
    return sum(coeff * b for coeff, b in zip(coeffs, B1))

Edit: I was able to solve the problem by doing X_matrix.transpose() Now I am trying to implement Y. My Magma code for $Y$:

B2 := Basis(2*G);
m := 16;
P := RandomPlace(F, m);
Fqm := ResidueClassField(P);
Y_matrix := Matrix([Eltseq(a): a in [Evaluate(f, P): f in B2]]);
Y := function(f)
    return Evaluate(f, P);
end function;
Y_inv := function(alpha)
    coeffs := Solution(Y_matrix, Vector(Eltseq(alpha)));
    return &+[coeffs[i] * B2[i]: i in [1..#B2]];
end function;

My Sage code for $Y$:

B2 = list(reversed((2*G).basis_function_space()))
O = F.maximal_order()
R = O._ring
Q = R.irreducible_element(16)
P = O.ideal(Q).place()
L.<y> = Fq.extension(Q)
morph = F.hom(y)
Y_matrix = matrix([morph(a).list() for a in [f.evaluate(P) for f in B2]]).transpose()
def Y(f):
    return morph(f.evaluate(P))
def Y_inv(alpha):
    coeffs = Y_matrix.solve_right(vector(alpha.list()))
    return sum(coeff * b for coeff, b in zip(coeffs, B2))

However, when I try to test the functions:

V = vector([Fq.from_integer(1), Fq.from_integer(3), Fq.from_integer(5), Fq.from_integer(7), Fq.from_integer(9), Fq.from_integer(11), Fq.from_integer(13), Fq.from_integer(15)])
a = Y(X_inv(V))
Y_inv(a)

I get the error:

ValueError: matrix equation has no solutions

for the line

coeffs = Y_matrix.solve_right(vector(alpha.list()))

Any help on why this occurs would be much appreciated.

edit retag flag offensive close merge delete