1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Sebastian Pancratz
******************************************************************************/
/*
Demo FLINT program to demonstrate some use of the
function fmpz_mod_poly_radix() for radix conversion
over $\mathbf{Z}/n \mathbf{Z}$.
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz_mod_poly.h"
int main(void)
{
const slong n = 12376;
const slong N = n / 26;
clock_t c0, c1;
double c;
slong i;
fmpz_t a, m;
fmpz_mod_poly_t A, B, r, t;
fmpz_mod_poly_radix_t S;
fmpz_mod_poly_struct **b;
FLINT_TEST_INIT(state);
fmpz_init(a);
fmpz_init(m);
fmpz_set_ui(m, 17);
fmpz_pow_ui(m, m, 26);
fmpz_mod_poly_init(A, m);
fmpz_mod_poly_init(B, m);
fmpz_mod_poly_init(r, m);
fmpz_mod_poly_init(t, m);
fmpz_mod_poly_set_coeff_ui(A, 3, 5);
fmpz_mod_poly_set_coeff_ui(A, 4, 4);
fmpz_mod_poly_set_coeff_ui(B, 0, 1);
fmpz_mod_poly_set_coeff_ui(B, 2, 1);
fmpz_mod_poly_set_coeff_ui(B, 3, 5);
fmpz_mod_poly_set_coeff_ui(B, 4, 1);
fmpz_mod_poly_set_coeff_ui(B, 5, 5);
fmpz_mod_poly_set_coeff_ui(B, 8, 8);
fmpz_mod_poly_set_coeff_ui(B, 9, 8);
fmpz_mod_poly_set_coeff_ui(B, 10, 5);
fmpz_mod_poly_set_coeff_ui(B, 12, 6);
fmpz_mod_poly_set_coeff_ui(B, 13, 1);
fmpz_mod_poly_pow(r, A, 3);
fmpz_set_ui(a, 4);
fmpz_mod_poly_scalar_mul_fmpz(r, r, a);
fmpz_mod_poly_pow(t, B, 2);
fmpz_set_ui(a, 27);
fmpz_mod_poly_scalar_mul_fmpz(t, t, a);
fmpz_mod_poly_add(r, r, t);
b = flint_malloc((N + 1) * sizeof(fmpz_mod_poly_struct *));
for (i = 0; i <= N; i++)
{
b[i] = flint_malloc(sizeof(fmpz_mod_poly_struct));
fmpz_mod_poly_init(b[i], m);
}
fmpz_mod_poly_randtest(t, state, n + 1);
flint_printf("Radix conversion\n");
flint_printf("----------------\n");
flint_printf(" Degree of the radix: %wd\n", fmpz_mod_poly_degree(r));
flint_printf(" Bit size of the modulus: %wd\n", (slong) fmpz_bits(fmpz_mod_poly_modulus(r)));
flint_printf(" Degree of the input: %wd\n", fmpz_mod_poly_degree(t));
c0 = clock();
fmpz_mod_poly_radix_init(S, r, n + 1);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
flint_printf(" Precomputation: %fs\n", c);
c0 = clock();
fmpz_mod_poly_radix(b, t, S);
c1 = clock();
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
flint_printf(" Conversion: %fs\n", c);
fmpz_clear(a);
fmpz_clear(m);
fmpz_mod_poly_clear(A);
fmpz_mod_poly_clear(B);
fmpz_mod_poly_clear(r);
fmpz_mod_poly_clear(t);
fmpz_mod_poly_radix_clear(S);
for (i = 0; i <= N; i++)
{
fmpz_mod_poly_clear(b[i]);
flint_free(b[i]);
}
flint_free(b);
flint_randclear(state);
return EXIT_SUCCESS;
}
|