1 /*
2 Copyright (C) 2011 Fredrik Johansson
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 "flint.h"
15 #include "fmpz.h"
16 #include "fmpz_mat.h"
17 #include "fmpz_poly.h"
18 #include "fmpz_poly_mat.h"
19
20 int
main(void)21 main(void)
22 {
23 slong i;
24
25 FLINT_TEST_INIT(state);
26
27 flint_printf("sqrlow....");
28 fflush(stdout);
29
30 /* Compare with sqr */
31 for (i = 0; i < 30 * flint_test_multiplier(); i++)
32 {
33 fmpz_poly_mat_t A, B, C;
34 slong n, bits, deg, len;
35
36 n = n_randint(state, 20);
37 deg = 1 + n_randint(state, 10);
38 bits = 1 + n_randint(state, 100);
39 len = n_randint(state, 10);
40
41 fmpz_poly_mat_init(A, n, n);
42 fmpz_poly_mat_init(B, n, n);
43 fmpz_poly_mat_init(C, n, n);
44
45 fmpz_poly_mat_randtest(A, state, deg, bits);
46 fmpz_poly_mat_randtest(B, state, deg, bits); /* noise in output */
47 fmpz_poly_mat_randtest(C, state, deg, bits); /* noise in output */
48
49 fmpz_poly_mat_sqrlow(B, A, len);
50 fmpz_poly_mat_sqr(C, A);
51 fmpz_poly_mat_truncate(C, len);
52
53 if (!fmpz_poly_mat_equal(B, C))
54 {
55 flint_printf("FAIL:\n");
56 flint_printf("A:\n");
57 fmpz_poly_mat_print(A, "x");
58 flint_printf("B:\n");
59 fmpz_poly_mat_print(B, "x");
60 flint_printf("C:\n");
61 fmpz_poly_mat_print(C, "x");
62 flint_printf("\n");
63 abort();
64 }
65
66 fmpz_poly_mat_clear(A);
67 fmpz_poly_mat_clear(B);
68 fmpz_poly_mat_clear(C);
69 }
70
71 /* Check aliasing */
72 for (i = 0; i < 10 * flint_test_multiplier(); i++)
73 {
74 fmpz_poly_mat_t A, B;
75 slong n, bits, deg, len;
76
77 n = n_randint(state, 20);
78 deg = 1 + n_randint(state, 10);
79 bits = 1 + n_randint(state, 100);
80 len = n_randint(state, 10);
81
82 fmpz_poly_mat_init(A, n, n);
83 fmpz_poly_mat_init(B, n, n);
84
85 fmpz_poly_mat_randtest(A, state, deg, bits);
86 fmpz_poly_mat_randtest(B, state, deg, bits);
87
88 fmpz_poly_mat_sqrlow(B, A, len);
89 fmpz_poly_mat_sqrlow(A, A, len);
90
91 if (!fmpz_poly_mat_equal(B, A))
92 {
93 flint_printf("FAIL:\n");
94 flint_printf("A:\n");
95 fmpz_poly_mat_print(A, "x");
96 flint_printf("B:\n");
97 fmpz_poly_mat_print(B, "x");
98 flint_printf("\n");
99 abort();
100 }
101
102 fmpz_poly_mat_clear(A);
103 fmpz_poly_mat_clear(B);
104 }
105
106 FLINT_TEST_CLEANUP(state);
107
108 flint_printf("PASS\n");
109 return 0;
110 }
111