在 C++ 中对 GF(2^6) 执行矩阵运算(例如乘积和逆运算)
Performing matrix-operations (e.g. product and inverse) over GF(2^6) in C++
我想用C++语言在伽罗瓦场GF(64(上实现一些矩阵运算,例如乘积和逆计算。 我通常使用特征库在双精度类型中执行此类操作。
在 Matlab 中,可以使用函数在 GF 上转换矩阵:A_gf = gf(A, 6(;在 A_gf GF(64(上定义的所有后续操作都在 GF(64( 中自动完成,例如 A: inv(A( 的逆函数。
你知道我是否可以在C++做类似的事情吗?
据我所知,本征不支持有限域算术。本机支持的唯一类型是本机类型。
如注释中所述,您可以添加自己的自定义类型:eigen.tuxfamily.org/dox/TopicCustomizing_CustomScalar.html
您最好使用 FLINT 或 NTL 库。
由于您的有限域具有特征 2(因为阶数是 2 的幂(,因此您可以在 NTL 中使用超过 GF2E 的矩阵优化算术(GF(2^6( 是 GF(2( 的扩展(。 https://libntl.org/doc/GF2E.cpp.html
所以你可能想在弗林特上使用 NTL。 您还希望确保使用 gf2x 作为后端,请查看安装 NTL 的文档。
对于超过GF2E的矩阵,以下是文档 https://libntl.org/doc/mat_GF2E.cpp.html:
#include<NTL/GF2XFactoring.h>
#include<NTL/GF2X.h>
#include<NTL/GF2E.h>
#include<NTL/mat_GF2E.h>
// The two first includes might not be necessary
using namespace NTL;
using namespace std;
int main()
{
// You have to compute first a "good" polynomial as modulus, of degree 64.
/* GF2X P = {(GF2)1, 1, 0, 1, 1, 0, 1}; */
GF2X P;
BuildSparseIrred(P, 6); // generate an irreducible polynomial P
// of degree 6 over GF(17)
GF2E::init(P); // define GF(2^6)
mat_GF2E m; // declare matrices over GF(2^6)
vec_GF2E x, b;
GF2E d;
random(m, 10, 10);
random(b, 10);
solve(d, x, m, b);
cout << "Matrix : " << m << endl;
cout << "vector : " << b << endl;
cout << "The solution of the system M*x = b is :" << endl;
cout << x << endl;
/* (To be completed) */
return 0;
}
有些情况针对多项式模量进行了优化:
GF2XModulus例程优化了几个重要的特殊情况:
f = X^
- n + X^k + 1,其中 k <= min((n+1(/2, n-NTL_BITS_PER_LONG(
f = X^n + X^{k_3} + X^{k_2} +- X^{k_1} + 1, 其中 k_3 <= min((n+1(/2, n-NTL_BITS_PER_LONG(
- f = X^n + g,其中 deg(g( 很小
因此,理想的做法是找到前两种阶数为 6 的先情况之一的多项式,以加快计算速度。
相关文章:
- 使用C++中的模板和运算符重载执行矩阵运算
- GCC本机矩阵运算库
- 位阵列上的快速AND运算
- 字符串中int的加法运算
- 算术运算的结果类似于:C浮点变量中的1/3
- 如何使用OpenMP并行化此矩阵时间矢量运算
- 如何在两个 boost::multi_arrays (C++) 之间执行数学运算?
- 如何在 vtk Poly 数据上进行布尔运算?
- MSVC 无法根据模板参数进行数学运算,这是一个错误吗?
- 避免指针运算,修复叮当整齐错误
- 使用双精度的浮点运算
- 如何在 c++ 中使用带有数学运算的引用/指针?
- 更快的C++算术运算
- 是否存在用于 C 或 C++ 中常见数学运算(例如最小值、最大值和平均值)的可导入库?
- 为什么循环体中的一个基本算术运算执行得比两个算术运算慢
- 两个字符串之间的数学运算
- 为什么对无符号字符进行算术运算会将它们提升为有符号整数
- 何时使用按位运算而不是算术替代方法?
- Arduino 上数学运算的计时速度 - 异常
- 在 C++ 中对 GF(2^6) 执行矩阵运算(例如乘积和逆运算)