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
/*
Copyright (C) 2011, 2012 Sebastian Pancratz
Copyright (C) 2012 Fredrik Johansson
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "padic.h"
slong _padic_exp_bound(slong v, slong N, const fmpz_t p)
{
if (fmpz_fits_si(p))
{
fmpz_t n, d, f;
slong i;
fmpz_init(n);
fmpz_init(d);
fmpz_init(f);
fmpz_sub_ui(f, p, 1);
fmpz_mul_ui(n, f, N);
fmpz_sub_ui(n, n, 1);
fmpz_mul_ui(d, f, v);
fmpz_sub_ui(d, d, 1);
fmpz_cdiv_q(f, n, d);
i = fmpz_get_si(f);
fmpz_clear(n);
fmpz_clear(d);
fmpz_clear(f);
return i;
}
else
{
return (N + (v - 1)) / v;
}
}
void _padic_exp(fmpz_t rop, const fmpz_t u, slong v, const fmpz_t p, slong N)
{
if (N < 1024)
_padic_exp_rectangular(rop, u, v, p, N);
else
_padic_exp_balanced(rop, u, v, p, N);
}
int padic_exp(padic_t rop, const padic_t op, const padic_ctx_t ctx)
{
const slong N = padic_prec(rop);
const slong v = padic_val(op);
const fmpz *p = ctx->p;
if (padic_is_zero(op))
{
padic_one(rop);
return 1;
}
if ((fmpz_equal_ui(p, 2) && v <= 1) || (v <= 0))
{
return 0;
}
else
{
if (v < N)
{
_padic_exp(padic_unit(rop), padic_unit(op), padic_val(op), p, N);
padic_val(rop) = 0;
}
else
{
padic_one(rop);
}
return 1;
}
}