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("neg....");
28 fflush(stdout);
29
30 /* Check evaluation homomorphism */
31 for (i = 0; i < 100 * flint_test_multiplier(); i++)
32 {
33 fmpz_poly_mat_t A, B;
34 fmpz_mat_t a, b, c;
35 fmpz_t x;
36 slong m, n, bits, deg;
37
38 m = n_randint(state, 20);
39 n = n_randint(state, 20);
40 deg = 1 + n_randint(state, 10);
41 bits = 1 + n_randint(state, 100);
42
43 fmpz_poly_mat_init(A, m, n);
44 fmpz_poly_mat_init(B, m, n);
45
46 fmpz_mat_init(a, m, n);
47 fmpz_mat_init(b, m, n);
48 fmpz_mat_init(c, m, n);
49
50 fmpz_init(x);
51
52 fmpz_poly_mat_randtest(A, state, deg, bits);
53 fmpz_poly_mat_neg(B, A);
54
55 fmpz_randtest(x, state, 1 + n_randint(state, 100));
56
57 fmpz_poly_mat_evaluate_fmpz(a, A, x);
58 fmpz_poly_mat_evaluate_fmpz(b, B, x);
59 fmpz_mat_neg(c, a);
60
61 if (!fmpz_mat_equal(b, c))
62 {
63 flint_printf("FAIL:\n");
64 flint_printf("A:\n");
65 fmpz_poly_mat_print(A, "x");
66 flint_printf("B:\n");
67 fmpz_poly_mat_print(B, "x");
68 flint_printf("\n");
69 abort();
70 }
71
72 fmpz_poly_mat_clear(A);
73 fmpz_poly_mat_clear(B);
74
75 fmpz_mat_clear(a);
76 fmpz_mat_clear(b);
77 fmpz_mat_clear(c);
78
79 fmpz_clear(x);
80 }
81
82 /* Check aliasing B and A */
83 for (i = 0; i < 100 * flint_test_multiplier(); i++)
84 {
85 fmpz_poly_mat_t A, B;
86 slong m, n, bits, deg;
87
88 m = n_randint(state, 20);
89 n = n_randint(state, 20);
90 deg = 1 + n_randint(state, 10);
91 bits = 1 + n_randint(state, 100);
92
93 fmpz_poly_mat_init(A, m, n);
94 fmpz_poly_mat_init(B, m, n);
95
96 fmpz_poly_mat_randtest(A, state, deg, bits);
97
98 fmpz_poly_mat_neg(B, A);
99 fmpz_poly_mat_neg(A, A);
100
101 if (!fmpz_poly_mat_equal(B, A))
102 {
103 flint_printf("FAIL:\n");
104 flint_printf("A:\n");
105 fmpz_poly_mat_print(A, "x");
106 flint_printf("B:\n");
107 fmpz_poly_mat_print(B, "x");
108 flint_printf("\n");
109 abort();
110 }
111
112 fmpz_poly_mat_clear(A);
113 fmpz_poly_mat_clear(B);
114 }
115
116 FLINT_TEST_CLEANUP(state);
117
118 flint_printf("PASS\n");
119 return 0;
120 }
121