# solve linear system in GF(7)

hi i would like to solve a small linear system in GF(7) whats the syntax ?

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(eqns,A0,A1,B0,B1,B2,B3) will do it in Q or R by default.

thank you

edit retag close merge delete

Sort by ยป oldest newest most voted

The usual way, which works for any field F, is to work with matrices, instead of symbolic expressions:

sage: F = GF(7)
sage: F
Finite Field of size 7
sage: M = Matrix(F, [[-1,5,1,2,4,1], [-3,2,1,4,2,1], [-6,6,1,6,1,6], [-5,2,1,1,1,1], [-4,2,1,3,2,6], [-2,4,1,5,4,6]])
sage: M
[6 5 1 2 4 1]
[4 2 1 4 2 1]
[1 6 1 6 1 6]
[2 2 1 1 1 1]
[3 2 1 3 2 6]
[5 4 1 5 4 6]
sage: M.parent()
Full MatrixSpace of 6 by 6 dense matrices over Finite Field of size 7
sage: v = vector(F, (3,1,-6,-5,6,6))
sage: v
(3, 1, 1, 2, 6, 6)
sage: v.parent()
Vector space of dimension 6 over Finite Field of size 7
sage: M.solve_right(v)
(1, 2, 2, 0, 4, 4)
sage: M * vector((1, 2, 2, 0, 4, 4))
(3, 1, 1, 2, 6, 6)
sage: M * vector((1, 2, 2, 0, 4, 4)) == v
True


For non-prime finite fields, you can access to the generator as follows:

sage: F = GF(49)
sage: F
Finite Field in z2 of size 7^2
sage: F.inject_variables()
Defining z2
sage: z2^6
2*z2 + 4
sage: z2^8
3

more
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)].

more

thank you very much its magic !!!!!!

( 2016-05-30 02:00:32 +0200 )edit

can anyone tell what to do if we were in a finite field GF(49), solve_mod wouldn't work right ? how would i need to do then ?

( 2016-05-30 02:44:20 +0200 )edit

It works in the same way:

solve_mod(eqns,49)


The result is:

[(20, 5, 26, 14, 10, 45)].

( 2016-05-30 12:09:20 +0200 )edit
1

are you sure it does that ? GF(49) is a Finite Field, usually we express its elements with its generator. i think your code is solving in Z/49Z which is not exactly the same.

( 2016-05-30 15:31:45 +0200 )edit
1

@castor: Careful, GF(49) is not Z/49.

( 2016-05-30 18:14:24 +0200 )edit