Ask Your Question
1

solve linear system in GF(7)

asked 2016-05-29 19:12:03 +0100

fagui gravatar image

updated 2022-10-15 13:27:33 +0100

FrédéricC gravatar image

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2016-05-30 17:45:22 +0100

tmonteil gravatar image

updated 2016-05-30 17:52:55 +0100

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
edit flag offensive delete link more
1

answered 2016-05-29 23:03:20 +0100

castor gravatar image
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)].
edit flag offensive delete link more

Comments

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

fagui gravatar imagefagui ( 2016-05-30 02:00:32 +0100 )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 ?

fagui gravatar imagefagui ( 2016-05-30 02:44:20 +0100 )edit

It works in the same way:

solve_mod(eqns,49)

The result is:

[(20, 5, 26, 14, 10, 45)].
castor gravatar imagecastor ( 2016-05-30 12:09:20 +0100 )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.

fagui gravatar imagefagui ( 2016-05-30 15:31:45 +0100 )edit
1

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

slelievre gravatar imageslelievre ( 2016-05-30 18:14:24 +0100 )edit

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: 2016-05-29 19:11:15 +0100

Seen: 3,882 times

Last updated: May 30 '16