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 <https://www.gnu.org/licenses/>.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <gmp.h>
15 #include "flint.h"
16 #include "arith.h"
17 #include "fmpz_vec.h"
18
19 #define N 10
20
21 static const fmpz known[N][N] = {
22 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
23 {1, 2, 0, 0, 2, 0, 0, 0, 0, 2},
24 {1, 4, 4, 0, 4, 8, 0, 0, 4, 4},
25 {1, 6, 12, 8, 6, 24, 24, 0, 12, 30},
26 {1, 8, 24, 32, 24, 48, 96, 64, 24, 104},
27 {1, 10, 40, 80, 90, 112, 240, 320, 200, 250},
28 {1, 12, 60, 160, 252, 312, 544, 960, 1020, 876},
29 {1, 14, 84, 280, 574, 840, 1288, 2368, 3444, 3542},
30 {1, 16, 112, 448, 1136, 2016, 3136, 5504, 9328, 12112},
31 {1, 18, 144, 672, 2034, 4320, 7392, 12672, 22608, 34802}
32 };
33
main(void)34 int main(void)
35 {
36 fmpz * r;
37 fmpz_t t;
38 slong i, j;
39
40 FLINT_TEST_INIT(state);
41
42 flint_printf("sum_of_squares....");
43 fflush(stdout);
44
45 r = _fmpz_vec_init(N);
46 fmpz_init(t);
47
48 for (i = 0; i < N; i++)
49 {
50 arith_sum_of_squares_vec(r, i, N);
51
52 for (j = 0; j < N; j++)
53 {
54 fmpz_set_ui(t, j);
55 arith_sum_of_squares(t, i, t);
56
57 if (!fmpz_equal(t, r + j) || !fmpz_equal(t, known[i] + j))
58 {
59 flint_printf("FAIL:\n");
60 flint_printf("i, j = %wd, %wd, r[j] = %wd, r(j) = %wd, "
61 "expected: %wd\n",
62 i, j, fmpz_get_si(r + j), fmpz_get_si(t), known[i][j]);
63 abort();
64 }
65 }
66 }
67
68 _fmpz_vec_clear(r, N);
69 fmpz_clear(t);
70
71 FLINT_TEST_CLEANUP(state);
72 flint_printf("PASS\n");
73 return 0;
74 }
75