forked from flintlib/flint
/
unity_zp_sqr.c
107 lines (85 loc) · 2.6 KB
/
unity_zp_sqr.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
/*=============================================================================
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) 2015 Vladimir Glazachev
******************************************************************************/
#include "aprcl.h"
void
unity_zp_sqr(unity_zp f, const unity_zp g)
{
if (g->poly->length == 0)
{
fmpz_mod_poly_zero(f->poly);
return;
}
fmpz_mod_poly_fit_length(f->poly, g->poly->length * 2 - 1);
_fmpz_poly_sqr(f->poly->coeffs, g->poly->coeffs, g->poly->length);
_fmpz_mod_poly_set_length(f->poly, 2 * g->poly->length - 1);
_unity_zp_reduce_cyclotomic_divmod(f);
}
void
unity_zp_sqr_inplace(unity_zp f, const unity_zp g, fmpz_t * t)
{
/* squaring for p^k = 4 */
if (f->p == 2 && f->exp == 2)
{
unity_zp_sqr4(f, g, t);
return;
}
/* squaring for p^k = 8 */
if (f->p == 2 && f->exp == 3)
{
unity_zp_sqr8(f, g, t);
return;
}
/* squaring for p^k = 16 */
if (f->p == 2 && f->exp == 4)
{
unity_zp_sqr16(f, g, t);
return;
}
/* squaring for p^k = 3 */
if (f->p == 3 && f->exp == 1)
{
unity_zp_sqr3(f, g, t);
return;
}
/* squaring for p^k = 9 */
if (f->p == 3 && f->exp == 2)
{
unity_zp_sqr9(f, g, t);
return;
}
/* squaring for p^k = 5 */
if (f->p == 5 && f->exp == 1)
{
unity_zp_sqr5(f, g, t);
return;
}
/* squaring for p^k = 7 */
if (f->p == 7 && f->exp == 1)
{
unity_zp_sqr7(f, g, t);
return;
}
/* squaring for p^k = 11 */
if (f->p == 11 && f->exp == 1)
{
unity_zp_sqr11(f, g, t);
return;
}
/* traditional squaring */
unity_zp_sqr(f, g);
}