1 // ========================================================== //
2 // Copyright(c)'1994-2009 by The Givaro group
3 // This file is part of Givaro.
4 // Givaro is governed by the CeCILL-B license under French law
5 // and abiding by the rules of distribution of free software.
6 // see the COPYRIGHT file for more details.
7 // Time-stamp: <12 Jun 15 18:47:22 Jean-Guillaume.Dumas@imag.fr>
8 // Check of irreducible polynomial and generators of GFq
9 // ========================================================== //
10 //
11 /*! @file examples/FiniteField/GFirreducible.C
12 * @ingroup examples
13 * @ingroup finitefields
14 * @example examples/FiniteField/GFirreducible.C
15 * @brief NO DOC
16 */
17 #include <givaro/gfq.h>
18 #include <givaro/givpower.h>
19 #include <givaro/givtimer.h>
20
21 using namespace Givaro;
22
23
24
main(int argc,char ** argv)25 int main(int argc, char** argv)
26 {
27
28 int64_t p = (argc>1?atoi(argv[1]):5);
29 int64_t e = (argc>2?atoi(argv[2]):3);
30 typedef GFqDom<int64_t>::Residu_t TT ;
31 GFqDom<int64_t> GFq((TT)p, (TT)e);
32 GFqDom<int64_t> PrimeField((TT)p,1);
33 std::cout << "Working in GF(" << p << '^' << e << ')' << std::endl;
34 std::cout << "Elements are polynomials in X modulo " << p << std::endl;
35
36 Poly1Dom< GFqDom<int64_t>, Dense > Pdom( PrimeField, Indeter("X") );
37
38 // First get the irreducible polynomial irred
39 // via irred = X^e - mQ
40 // and X^e = X^(e-1) * X
41 GFqDom<int64_t>::Element temo, t, tmp;
42 Poly1Dom< GFqDom<int64_t>, Dense >::Element G, H, J, mQ, irred, modP;
43
44 Pdom.init(G, Degree((int64_t)GFq.exponent()-1)); // X^(e-1)
45 GFq.init(temo,G); // internal representation
46
47 Pdom.init(H, Degree(1) ); // X
48 GFq.init(t,H); // internal representation
49
50 GFq.init(tmp);
51
52 GFq.mul(tmp, temo, t); // internal representation of X^e
53 GFq.negin(tmp); // internal representation of -X^e, i.e. of the irreducible polynomial without the largest monomial, X^e
54
55 int64_t lowerpart;
56 // p-adic value of the lower part of the irreducible polynomial
57 GFq.convert(lowerpart, tmp);
58 std::cout << ' ' << p << "-adic value of the lower part of the irreducible : " << lowerpart << std::endl;
59
60 int64_t ptoe = power(p,e); // p-adic value of X^e
61 std::cout << ' ' << p << '^' << e << " is : " << ptoe << std::endl;
62
63 std::cout << " --> Computed irreducible: " << ptoe+lowerpart << std::endl;
64 std::cout << "Stored irreducible: " << GFq.irreducible() << std::endl;
65
66 Poly1PadicDom< GFqDom<int64_t>, Dense > PAD(Pdom);
67 Poly1PadicDom< GFqDom<int64_t>, Dense >::Element Polynomial;
68
69 PAD.radix(Polynomial, GFq.irreducible());
70
71 std::cout << "Irreducible polynomial coefficients: ";
72 for(Poly1PadicDom< GFqDom<int64_t>, Dense >::Element::iterator it = Polynomial.begin(); it != Polynomial.end(); ++it)
73 PrimeField.write(std::cout << ' ', *it);
74 std::cout << std::endl;
75
76
77 PAD.write(std::cout << "The latter " << GFq.irreducible() << " represents: ", Polynomial)
78 << " in " << p << "-adic"
79 << std::endl;
80
81
82
83 return 0;
84
85 }
86 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
87 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
88