假设你的有限域为$ GF(8)$,所有的计算功能(如add()
,mul()
)必须在相同的字段(GF(8))上进行计算。
您在有限域上计算矩阵逆的方式与您在其他域中计算的方式完全相同,并且高斯 - 约旦消除可以实现。
以下是用于计算GF(256)上的矩阵求逆的代码(From:https://github.com/foool/nclib/blob/master/gmatrixu8.cc)的一部分。希望它能帮助你。
void GMatrixU8::Inverse(){
GMatrixU8 mat_inv;
int w = this->ww;
int dim;
int i, nzero_row, j;
int temp, jtimes;
dim = this->rr;
mat_inv.Make_identity(this->rr, this->cc, this->ww);
for(i = 0; i < dim; i++){
nzero_row = i;
if(0 == Get(i,i)){
do{
++nzero_row;
if(nzero_row >= dim){ ERROR("Non-full rank matrix!"); }
temp = Get(nzero_row, i);
}while((0 == temp)&&(nzero_row < dim));
Swap_rows(i, nzero_row);
mat_inv.Swap_rows(i, nzero_row);
}
for(j = 0; j < dim; j++){
if(0 == Get(j,i))
continue;
if(j != i){
jtimes = galois_single_divide(Get(j,i), Get(i,i), w);
Row_plus_irow(j, i, jtimes);
mat_inv.Row_plus_irow(j, i, jtimes);
}else{
jtimes = galois_inverse(Get(i, i), w);
Row_to_irow(i , jtimes);
mat_inv.Row_to_irow(i , jtimes);
}
}
}
this->ele = mat_inv.ele;
}
采取一个看看https://jeremykun.com/2014/03/13/programming-with-finite-fields/ – MishaVacic
@MishaVacic你确定这个讨论矩阵? – dimitris93
可能是这个https://www.quora.com/How-can-I-use-Python-to-compute-matrix-on-finite-field – MishaVacic