2017-08-17 421 views
2

我正在使用Python中的有限域。我有一个包含多项式的矩阵,每个多项式表示为一个整数。例如,多项式x^3 + x + 1表示为11,这是因为:有限域:计算矩阵的逆

x^3 + x + 1 ==> (1,0,1,1) ==> (8,0,2,1) ==> 8 + 0 + 2 + 1 ==> 11 

给定一个矩阵,例如:

6, 2, 1 
7, 0, 4 
1, 7, 3 

我如何计算Python中的矩阵的逆?我已经实现了以下功能(多项式,不是多项式的矩阵):add()sub()mul()div()inv()

+1

采取一个看看https://jeremykun.com/2014/03/13/programming-with-finite-fields/ – MishaVacic

+0

@MishaVacic你确定这个讨论矩阵? – dimitris93

+0

可能是这个https://www.quora.com/How-can-I-use-Python-to-compute-matrix-on-finite-field – MishaVacic

回答

0
  1. 假设你的有限域为$ GF(8)$,所有的计算功能(如add(),mul())必须在相同的字段(GF(8))上进行计算。

  2. 您在有限域上计算矩阵逆的方式与您在其他域中计算的方式完全相同,并且高斯 - 约旦消除可以实现。

以下是用于计算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; 
}