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 <gmp.h>
15 #include <mpfr.h>
16 #include "flint.h"
17 #include "fmpz.h"
18 #include "fmpz_vec.h"
19 #include "arith.h"
20 #include "ulong_extras.h"
21
22 /* Values mod 10^9 generated with Sage */
23 static const ulong testdata[][2] =
24 {
25 {100000, 421098519},
26 {100001, 33940350},
27 {100002, 579731933},
28 {100003, 625213730},
29 {100004, 539454200},
30 {100005, 69672418},
31 {100006, 865684292},
32 {100007, 641916724},
33 {100008, 36737908},
34 {100009, 293498270},
35 {100010, 177812057},
36 {100011, 756857293},
37 {100012, 950821113},
38 {100013, 824882014},
39 {100014, 533894560},
40 {100015, 660734788},
41 {100016, 835912257},
42 {100017, 302982816},
43 {100018, 468609888},
44 {100019, 221646940},
45 {1000000, 104673818},
46 {1000001, 980212296},
47 {1000002, 709795681},
48 {1000003, 530913758},
49 {1000004, 955452980},
50 {1000005, 384388683},
51 {1000006, 138665072},
52 {1000007, 144832602},
53 {1000008, 182646067},
54 {1000009, 659145045},
55 {1000010, 17911162},
56 {1000011, 606326324},
57 {1000012, 99495156},
58 {1000013, 314860251},
59 {1000014, 497563335},
60 {1000015, 726842109},
61 {1000016, 301469541},
62 {1000017, 227491620},
63 {1000018, 704160927},
64 {1000019, 995311980},
65 {10000000, 677288980},
66 {10000001, 433805210},
67 {10000002, 365406948},
68 {10000003, 120899894},
69 {10000004, 272822040},
70 {10000005, 71938624},
71 {10000006, 637670808},
72 {10000007, 766947591},
73 {10000008, 980210244},
74 {10000009, 965734705},
75 {10000010, 187411691},
76 {10000011, 485652153},
77 {10000012, 825498761},
78 {10000013, 895802660},
79 {10000014, 152775845},
80 {10000015, 791493402},
81 {10000016, 299640598},
82 {10000017, 383615481},
83 {10000018, 378922331},
84 {10000019, 37059200},
85 {100000000, 836637702},
86 {100000001, 66421565},
87 {100000002, 747849093},
88 {100000003, 465329748},
89 {100000004, 166747980},
90 {0, 0},
91 };
92
main(void)93 int main(void)
94 {
95 fmpz_t p;
96 fmpz * v;
97
98 slong i;
99
100 FLINT_TEST_INIT(state);
101
102 flint_printf("number_of_partitions....");
103 fflush(stdout);
104
105 fmpz_init(p);
106 v = _fmpz_vec_init(3000);
107
108 arith_number_of_partitions_vec(v, 3000);
109
110 for (i = 0; i < 3000; i++)
111 {
112 arith_number_of_partitions(p, i);
113 if (!fmpz_equal(p, v + i))
114 {
115 flint_printf("FAIL:\n");
116 flint_printf("p(%wd) does not agree with power series\n", i);
117 flint_printf("Computed p(%wd): ", i); fmpz_print(p); flint_printf("\n");
118 flint_printf("Expected: "); fmpz_print(v + i); flint_printf("\n");
119 abort();
120 }
121 }
122
123 _fmpz_vec_clear(v, 3000);
124
125 for (i = 0; testdata[i][0] != 0; i++)
126 {
127 arith_number_of_partitions(p, testdata[i][0]);
128
129 if (fmpz_fdiv_ui(p, 1000000000) != testdata[i][1])
130 {
131 flint_printf("FAIL:\n");
132 flint_printf("p(%wd) does not agree with known value mod 10^9\n",
133 testdata[i][0]);
134 flint_printf("Computed: %wu\n", fmpz_fdiv_ui(p, 1000000000));
135 flint_printf("Expected: %wu\n", testdata[i][1]);
136 abort();
137 }
138 }
139
140 fmpz_clear(p);
141
142 FLINT_TEST_CLEANUP(state);
143
144 flint_printf("PASS\n");
145 return 0;
146 }
147