Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

Implementing linear maps and their inverses in SageMath and Magma

asked 0 years ago

anonymous user

Anonymous

updated 0 years ago

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.

Preview: (hide)

Comments

On a minor note, it's better to define B2 as a vector B2 = vector(reversed((2*G).basis_function_space())) and then sum(coeff * b for coeff, b in zip(coeffs, B2)) can be replaced by simply the dot-product: coeffs * B2.

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 0 years ago

Max Alekseyev gravatar image

Matrix Y_matrix has size 16 x 15 and the full rank 15. If you add parameter check=False to Y_matrix.solve_right(...) and then print the difference Y_matrix * coeffs - vector(alpha.list()), you will see that the obtained solution does nullify the first 15 components in this difference, but not the 16th one. Given that the rank of Y_matrix is 15, it means that vector(alpha.list()) does not belong to the span of Y_matrix, and Sage is correct by saying that there are no solutions.

Preview: (hide)
link

Comments

Conceptually the code should be trying to find the preimage of an element which is in the image of a map (if I understood it correctly), so I think the question is where the code is going wrong.

rburing gravatar imagerburing ( 0 years ago )

Then I would first rewrite Y(...) in the form of multiplying by Y_matrix, and verify that they produce consistent results. Apparently, something is off here.

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 145 times

Last updated: Jan 17