givaro
givaro copied to clipboard
[feature request] allow field.irreducible() and field.generator() as argument in the field constructor
tl;dr:
given an existing field variable field
, trying to construct a copy with
Field(prime, power, field.irreducible(), field.generator())
will not work.
Too short to not read:
Let's consider for example
typedef GFqDom<IdentificationInteger> Field;
Currently, even for same sizes, the constructor of Field will generally not return the same field because the irreducible polynomial seem to be chosen randomly in some way and will thus differ. Thus in order to produce the same field the constructor must be called with:
Field field(prime, power, irreducible, generator)
(In principle, the generator can differ too but this does not seem to happen, it seems to default to 1 in log representation).
The irreducible and generator of an existing field can be obtained with
field.irreducible()
and
field.generator()
The problem is that the Field constructor expects the irreducible and generators as polynomials while the Field class returns integers.
The only way to make it work is with
#include <givaro/modular.h> // Needed for padic2polynomial function below
Field(prime, power, padic2polynomial(field.irreducible()), padic2polynomial(field.generator()))
with
auto padic2polynomial (Field::Element padic) {
// Create polynomial field with integer representation
//// Create the integer prime field
Modular<int> PrimeField(3);
//// Create the polynomial field
Poly1Dom < Modular<int>, Dense > Polynomials( PrimeField, Indeter("X") );
//// Create a padic polynomial field which has the methods to convert a padic integer to a polynomial
Poly1PadicDom< Modular<int>, Dense > ConverterDomain(Polynomials);
// Define the polynomial variable
Poly1PadicDom< Modular<int>, Dense >::Element polynomial;
// Convert the integer to a polynomial
ConverterDomain.radix(polynomial, padic);
return polynomial;
}
It would make more sense if Field
would return the same format that it expects, and it would made sense for the format to be a Fied::Element
so that they can be added to vectors of actual elements, so that the information of how to interpret some elements can be transferred with the elements.