1 /*
2     Copyright (C) 2012 Sebastian Pancratz
3     Copyright (C) 2013 Tom Bachmann (C++ adaptation)
4 
5     This file is part of FLINT.
6 
7     FLINT is free software: you can redistribute it and/or modify it under
8     the terms of the GNU Lesser General Public License (LGPL) as published
9     by the Free Software Foundation; either version 2.1 of the License, or
10     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
11 */
12 
13 /*
14     Demo FLINT program to demonstrate some use of the
15     function fmpz_mod_poly_radix() for radix conversion
16     over $\mathbf{Z}/n \mathbf{Z}$.
17 */
18 
19 #include <cstdio>
20 #include <ctime>
21 #include "fmpz_mod_polyxx.h"
22 
23 using namespace std;
24 using namespace flint;
25 
main(void)26 int main(void)
27 {
28     const slong n = 12376;
29     const slong N = n / 26;
30 
31     frandxx state;
32 
33     fmpzxx m(17);
34     m = m.pow(26u);
35 
36     fmpz_mod_polyxx A(m), B(m);
37 
38     A.set_coeff(3, 5);
39     A.set_coeff(4, 4);
40 
41     B.set_coeff(0, 1);
42     B.set_coeff(2, 1);
43     B.set_coeff(3, 5);
44     B.set_coeff(4, 1);
45     B.set_coeff(5, 5);
46     B.set_coeff(8, 8);
47     B.set_coeff(9, 8);
48     B.set_coeff(10, 5);
49     B.set_coeff(12, 6);
50     B.set_coeff(13, 1);
51 
52     fmpz_mod_polyxx r(A.pow(3u) * fmpzxx(4) + B.pow(2u) * fmpzxx(27));
53 
54     fmpz_mod_poly_vecxx b(N + 1, m);
55 
56     fmpz_mod_polyxx t = fmpz_mod_polyxx::randtest(m, state, n + 1);
57 
58     flint_printf("Radix conversion\n");
59     flint_printf("----------------\n");
60     flint_printf("  Degree of the radix:     %wd\n", r.degree());
61     flint_printf("  Bit size of the modulus: %wd\n", (slong) bits(r.modulus()));
62     flint_printf("  Degree of the input:     %wd\n", t.degree());
63 
64     clock_t c0 = clock();
65     fmpz_mod_poly_radixxx S(r, n + 1);
66     clock_t c1 = clock();
67     double c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
68 
69     flint_printf("  Precomputation:          %fs\n", c);
70 
71     c0 = clock();
72     b = t.radix(S);
73     c1 = clock();
74     c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
75 
76     flint_printf("  Conversion:              %fs\n", c);
77 
78     return 0;
79 }
80 
81