/
thm4reconst.c
129 lines (108 loc) · 3.49 KB
/
thm4reconst.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2008 Philip Greggory Lee.
// Contact me at: rocketman768@gmail.com
// This file is part of KregularKompute.
//
// KregularKompute is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// KregularKompute is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with KregularKompute. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "algorithms.h"
#define M_ITEMS 2048 // The max number of items m[] can have.
// If this program is crapping out, this
// is probably the reason.
// Program verifies case l=ell from Theorem 4.
// Reads input from stdin about location of files.
// Format is:
// prime file
// prime2 file2
// ...
// Where prime, prime2,... represent the moduli of file, file2,... .
int main(int argc, char *argv[])
{
unsigned long int ell, i, n, num, thisprime, numprimes;
unsigned long int three_to_ell, three_to_ellMinusOne, nbound;
unsigned long int *a, *m;
mpz_t answer;
int items;
char thisfilename[128];
FILE **datafiles;
if( argc < 2 )
{
fprintf( stderr, "\nUsage:\n\t%s ell\n", argv[0] );
fprintf( stderr, "Makes sure that the case l=ell is true for Theorem 4 in\n`Parity of 5-regular and 13-regular Partition Functions'");
return 1;
}
// Parse arguments.
ell = strtoul(argv[1], NULL, 10);
// Allocate memory for stuff.
m = malloc( sizeof(unsigned long) * M_ITEMS );
a = malloc( sizeof(unsigned long) * M_ITEMS );
datafiles = malloc( sizeof(FILE *) * M_ITEMS );
mpz_init(answer);
// Set up constants.
three_to_ell = 1;
three_to_ellMinusOne = 1;
for( i=0; i < ell; ++i )
three_to_ell *= 3;
for( i=0; i < ell-1; ++i )
three_to_ellMinusOne *= 3;
nbound = 7*three_to_ellMinusOne + 3;
// Set up primes and files.
i = 0;
while(1)
{
items = fscanf( stdin, "%lu %s\n", &thisprime, thisfilename );
if( items == 2 )
{
datafiles[i] = fopen( thisfilename, "r" );
m[i] = thisprime;
i++;
}
else
break;
}
// Now we know how many primes we're working with.
numprimes = i;
for( n=1; n <= nbound; ++n )
{
// Set num to number in b_13 fn in thm4.
num = three_to_ell*n + (5*three_to_ellMinusOne - 1)/2;
// Set up the a[] array.
for( i=0; i < numprimes; ++i )
{
fseek( datafiles[i], 4L*num, SEEK_SET );
fread( &a[i], 4, 1, datafiles[i] );
}
// Get result from chinese remainder thm.
crt( answer, a, m, numprimes );
// If it's not zero mod 3...oh shit.
if( mpz_mod_ui( answer, answer, (unsigned long)3 ) != 0 )
{
printf("Failed case: n=%lu num=%lu b_13(num)=", n, num);
mpz_out_str(stdout, 10, answer);
printf("\n");
fflush(stdout);
exit(1);
}
}
printf("Yay! Case l=%lu is true!\n", ell);
// Close all files.
for( i = 0; i < numprimes; ++i )
fclose( datafiles[i] );
// Free all memory.
free(a);
free(m);
free(datafiles);
return 0;
}