1 /*
2     Copyright (C) 2010, 2020 William Hart
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <gmp.h>
15 #include "flint.h"
16 #include "fmpz.h"
17 #include "fmpz_poly.h"
18 #include "ulong_extras.h"
19 
20 int
main(void)21 main(void)
22 {
23     int i, result;
24     FLINT_TEST_INIT(state);
25 
26     flint_printf("mul_SS_precache....");
27     fflush(stdout);
28 
29     /* Check aliasing of a and b */
30     for (i = 0; i < 200 * flint_test_multiplier(); i++)
31     {
32         fmpz_poly_t a, b, c;
33 	fmpz_poly_mul_precache_t pre;
34 
35         fmpz_poly_init(a);
36         fmpz_poly_init(b);
37         fmpz_poly_init(c);
38         fmpz_poly_randtest(b, state, n_randint(state, 50), 200);
39         fmpz_poly_randtest(c, state, n_randint(state, 50), 200);
40 
41         fmpz_poly_mul_SS_precache_init(pre, 50, 200, c);
42 
43         fmpz_poly_mul_SS(a, b, c);
44         fmpz_poly_mul_SS_precache(b, b, pre);
45 
46         result = (fmpz_poly_equal(a, b));
47         if (!result)
48         {
49             flint_printf("FAIL:\n");
50             fmpz_poly_print(a), flint_printf("\n\n");
51             fmpz_poly_print(b), flint_printf("\n\n");
52             abort();
53         }
54 
55 	fmpz_poly_mul_precache_clear(pre);
56 
57         fmpz_poly_clear(a);
58         fmpz_poly_clear(b);
59         fmpz_poly_clear(c);
60     }
61 
62     /* Compare with mul_KS */
63     for (i = 0; i < 200 * flint_test_multiplier(); i++)
64     {
65         fmpz_poly_t a, b, c, d;
66         fmpz_poly_mul_precache_t pre;
67 	int k;
68 
69         fmpz_poly_init(a);
70         fmpz_poly_init(b);
71         fmpz_poly_init(c);
72         fmpz_poly_init(d);
73         fmpz_poly_randtest(c, state, n_randint(state, 50), 200);
74 
75 	fmpz_poly_mul_SS_precache_init(pre, 50, 200, c);
76 
77 	for (k = 0; k < 3; k++)
78 	{
79 	   fmpz_poly_randtest(b, state, n_randint(state, 50), 200);
80 
81            fmpz_poly_mul_KS(a, b, c);
82            fmpz_poly_mul_SS_precache(d, b, pre);
83 
84            result = (fmpz_poly_equal(a, d));
85            if (!result)
86            {
87                flint_printf("FAIL:\n");
88                fmpz_poly_print(a), flint_printf("\n\n");
89                fmpz_poly_print(d), flint_printf("\n\n");
90                abort();
91            }
92 	}
93 
94 	fmpz_poly_mul_precache_clear(pre);
95 
96         fmpz_poly_clear(a);
97         fmpz_poly_clear(b);
98         fmpz_poly_clear(c);
99         fmpz_poly_clear(d);
100     }
101 
102     FLINT_TEST_CLEANUP(state);
103 
104     flint_printf("PASS\n");
105     return 0;
106 }
107