forked from flintlib/flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzassenhaus_recombination.c
146 lines (111 loc) · 4.33 KB
/
zassenhaus_recombination.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*=============================================================================
This file is part of FLINT.
FLINT 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 2 of the License, or
(at your option) any later version.
FLINT 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 FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Andy Novocin
Copyright (C) 2011 William Hart
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdlib.h>
#include "fmpz_poly_factor.h"
#define TRACE 0
void fmpz_poly_factor_zassenhaus_recombination(fmpz_poly_factor_t final_fac,
const fmpz_poly_factor_t lifted_fac,
const fmpz_poly_t F, const fmpz_t P, long exp)
{
const long r = lifted_fac->num;
long k, *used_arr, *sub_arr;
fmpz_poly_t f, Q, R, tryme;
fmpz *leadF;
used_arr = flint_calloc(2 * r, sizeof(long));
sub_arr = used_arr + r;
fmpz_poly_init(f);
fmpz_poly_init(Q);
fmpz_poly_init(R);
fmpz_poly_init(tryme);
fmpz_poly_set(f, F);
#if TRACE == 1
fmpz_poly_factor_print(lifted_fac); printf(" lifted_fac\n");
#endif
leadF = fmpz_poly_lead(F);
for (k = 1; k < r; k++)
{
long count = 0, indx = k - 1, l;
for(l = 0; l < k; l++)
sub_arr[l] = l;
sub_arr[indx]--;
while ((indx >= 0))
{
sub_arr[indx] = sub_arr[indx] + 1;
for (l = indx + 1; l < k; l++)
sub_arr[l] = sub_arr[l - 1] + 1;
if (sub_arr[k - 1] > r - 1)
indx--;
else
{
for(l = 0; l < k; l++)
{
if (used_arr[sub_arr[l]] == 1)
break;
}
/* Need to involve leadF, perhaps set coeff 0 to leadF and do
leadF * rest and check if under M_bits... here I'm using a
trial division... */
fmpz_poly_set_fmpz(tryme, leadF);
for(l = 0; l < k; l++)
fmpz_poly_mul(tryme, tryme, lifted_fac->p + (sub_arr[l]));
fmpz_poly_scalar_smod_fmpz(tryme, tryme, P);
fmpz_poly_primitive_part(tryme, tryme);
fmpz_poly_divrem(Q, R, f, tryme);
#if TRACE == 1
fmpz_poly_print(tryme); printf(" is tryme\n");
fmpz_poly_print(R); printf(" is R\n");
#endif
if (fmpz_poly_is_zero(R))
{
fmpz_poly_factor_insert(final_fac, tryme, exp);
for(l = 0; l < k; l++)
{
used_arr[sub_arr[l]] = 1;
count++;
}
fmpz_poly_set(f, Q);
leadF = fmpz_poly_lead(f);
/* If r - count = k then the rest are irreducible.
TODO: Add a test for that case */
}
indx = k - 1;
}
}
/* This is where we switch to the next loop for k. So we will have
found all factors using <= k local factors. We should/could update
f to be the rest divided away (or multiply the remaining), could
also adjust r. It is the number of remaining factors so if you
update then test if r = k or k+1 in which case the remaining f is
irreducible. */
}
{
long test = 0;
for (k = 0; k < r; k++)
test = test + used_arr[k];
if (test == 0)
fmpz_poly_factor_insert(final_fac, f, exp);
}
fmpz_poly_clear(f);
fmpz_poly_clear(tryme);
fmpz_poly_clear(Q);
fmpz_poly_clear(R);
flint_free(used_arr);
}
#undef TRACE