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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

//! *See the [FLINT documentation](http://flintlib.org/doc/padic.html).


use crate::deps::*;
use crate::flint::*;
use crate::fmpz::{fmpz, fmpz_t};
use crate::fmpq::fmpq;
use libc::{c_char, c_int, c_uint, FILE};


#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct padic_struct {
    pub u: fmpz,
    pub v: mp_limb_signed_t,
    pub N: mp_limb_signed_t,
}

pub type padic_t = [padic_struct; 1usize];

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct padic_ctx_struct {
    pub p: fmpz_t,
    pub pinv: f64,
    pub pow: *mut fmpz,
    pub min: mp_limb_signed_t,
    pub max: mp_limb_signed_t,
    pub mode: padic_print_mode,
}

pub type padic_ctx_t = [padic_ctx_struct; 1usize];

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct padic_inv_struct {
    pub n: mp_limb_signed_t,
    pub pow: *mut fmpz,
}

pub type padic_inv_t = [padic_inv_struct; 1usize];

pub const padic_print_mode_PADIC_TERSE: padic_print_mode = 0;
pub const padic_print_mode_PADIC_SERIES: padic_print_mode = 1;
pub const padic_print_mode_PADIC_VAL_UNIT: padic_print_mode = 2;

pub type padic_print_mode = c_uint;

extern "C" {
    pub fn padic_ctx_init(
        ctx: *mut padic_ctx_struct,
        p: *const fmpz,
        min: mp_limb_signed_t,
        max: mp_limb_signed_t,
        mode: padic_print_mode,
    );
    pub fn padic_unit(x: *const padic_struct) -> *mut fmpz;
    pub fn padic_get_val(x: *const padic_struct) -> mp_limb_signed_t;
    pub fn padic_get_prec(x: *const padic_struct) -> mp_limb_signed_t;
    pub fn padic_ctx_clear(ctx: *mut padic_ctx_struct);
    pub fn _padic_ctx_pow_ui(
        rop: *mut fmpz,
        e: mp_limb_t,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_ctx_pow_ui(rop: *mut fmpz, e: mp_limb_t, ctx: *const padic_ctx_struct);
    pub fn padic_init(rop: *mut padic_struct);
    pub fn padic_init2(rop: *mut padic_struct, N: mp_limb_signed_t);
    pub fn padic_clear(rop: *mut padic_struct);
    pub fn _padic_canonicalise(rop: *mut padic_struct, ctx: *const padic_ctx_struct);
    pub fn _padic_reduce(rop: *mut padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_reduce(rop: *mut padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_randtest(
        rop: *mut padic_struct,
        state: *const flint_rand_s,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_randtest_not_zero(
        rop: *mut padic_struct,
        state: *const flint_rand_s,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_randtest_int(
        rop: *mut padic_struct,
        state: *const flint_rand_s,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_set(rop: *mut padic_struct, op: *const padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_set_si(rop: *mut padic_struct, op: mp_limb_signed_t, ctx: *const padic_ctx_struct);
    pub fn padic_set_ui(rop: *mut padic_struct, op: mp_limb_t, ctx: *const padic_ctx_struct);
    pub fn padic_set_fmpz(rop: *mut padic_struct, op: *const fmpz, ctx: *const padic_ctx_struct);
    pub fn padic_set_fmpq(rop: *mut padic_struct, op: *const fmpq, ctx: *const padic_ctx_struct);
    pub fn padic_set_mpz(rop: *mut padic_struct, op: *const __mpz_struct, ctx: *const padic_ctx_struct);
    pub fn padic_set_mpq(rop: *mut padic_struct, op: *const __mpq_struct, ctx: *const padic_ctx_struct);
    pub fn padic_get_fmpz(rop: *mut fmpz, op: *const padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_get_fmpq(rop: *mut fmpq, op: *const padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_get_mpz(rop: *mut __mpz_struct, op: *const padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_get_mpq(rop: *mut __mpq_struct, op: *const padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_swap(op1: *mut padic_struct, op2: *const padic_struct);
    pub fn padic_zero(rop: *mut padic_struct);
    pub fn padic_one(rop: *mut padic_struct);
    pub fn padic_is_zero(op: *const padic_struct) -> c_int;
    pub fn padic_is_one(op: *const padic_struct) -> c_int;
    pub fn padic_equal(op1: *const padic_struct, op2: *const padic_struct) -> c_int;
    pub fn _padic_lifts_exps(
        n: *mut mp_limb_signed_t,
        N: mp_limb_signed_t,
    ) -> *const mp_limb_signed_t;
    pub fn _padic_lifts_pows(
        pow: *mut fmpz,
        a: *const mp_limb_signed_t,
        n: mp_limb_signed_t,
        p: *const fmpz,
    );
    pub fn padic_add(
        rop: *mut padic_struct,
        op1: *const padic_struct,
        op2: *const padic_struct,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_sub(
        rop: *mut padic_struct,
        op1: *const padic_struct,
        op2: *const padic_struct,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_neg(rop: *mut padic_struct, op: *const padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_mul(
        rop: *mut padic_struct,
        op1: *const padic_struct,
        op2: *const padic_struct,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_shift(
        rop: *mut padic_struct,
        op: *const padic_struct,
        v: mp_limb_signed_t,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_div(
        rop: *mut padic_struct,
        op1: *const padic_struct,
        op2: *const padic_struct,
        ctx: *const padic_ctx_struct,
    );
    pub fn _padic_inv_precompute(S: *mut padic_inv_struct, p: *const fmpz, N: mp_limb_signed_t);
    pub fn _padic_inv_clear(S: *mut padic_inv_struct);
    pub fn _padic_inv_precomp(rop: *mut fmpz, op: *const fmpz, S: *const padic_inv_struct);
    pub fn _padic_inv(rop: *mut fmpz, op: *const fmpz, p: *const fmpz, N: mp_limb_signed_t);
    pub fn padic_inv(rop: *mut padic_struct, op: *const padic_struct, ctx: *const padic_ctx_struct);
    pub fn padic_sqrt(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_pow_si(
        rop: *mut padic_struct,
        op: *const padic_struct,
        e: mp_limb_signed_t,
        ctx: *const padic_ctx_struct,
    );
    pub fn _padic_exp_bound(
        v: mp_limb_signed_t,
        N: mp_limb_signed_t,
        p: *const fmpz,
    ) -> mp_limb_signed_t;
    pub fn _padic_exp(
        rop: *mut fmpz,
        u: *const fmpz,
        v: mp_limb_signed_t,
        p: *const fmpz,
        N: mp_limb_signed_t,
    );
    pub fn _padic_exp_rectangular(
        rop: *mut fmpz,
        u: *const fmpz,
        v: mp_limb_signed_t,
        p: *const fmpz,
        N: mp_limb_signed_t,
    );
    pub fn _padic_exp_balanced(
        rop: *mut fmpz,
        u: *const fmpz,
        v: mp_limb_signed_t,
        p: *const fmpz,
        N: mp_limb_signed_t,
    );
    pub fn padic_exp(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_exp_rectangular(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_exp_balanced(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn _padic_log_bound(
        v: mp_limb_signed_t,
        N: mp_limb_signed_t,
        p: *const fmpz,
    ) -> mp_limb_signed_t;
    pub fn _padic_log(
        z: *mut fmpz,
        y: *const fmpz,
        v: mp_limb_signed_t,
        p: *const fmpz,
        N: mp_limb_signed_t,
    );
    pub fn _padic_log_rectangular(
        z: *mut fmpz,
        y: *const fmpz,
        v: mp_limb_signed_t,
        p: *const fmpz,
        N: mp_limb_signed_t,
    );
    pub fn _padic_log_satoh(
        z: *mut fmpz,
        y: *const fmpz,
        v: mp_limb_signed_t,
        p: *const fmpz,
        N: mp_limb_signed_t,
    );
    pub fn _padic_log_balanced(
        z: *mut fmpz,
        y: *const fmpz,
        v: mp_limb_signed_t,
        p: *const fmpz,
        N: mp_limb_signed_t,
    );
    pub fn padic_log(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_log_rectangular(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_log_satoh(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_log_balanced(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn _padic_teichmuller(rop: *mut fmpz, op: *const fmpz, p: *const fmpz, N: mp_limb_signed_t);
    pub fn padic_teichmuller(
        rop: *mut padic_struct,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    );
    pub fn padic_val_fac_ui_2(N: mp_limb_t) -> mp_limb_t;
    pub fn padic_val_fac_ui(N: mp_limb_t, p: *const fmpz) -> mp_limb_t;
    pub fn padic_val_fac(rop: *mut fmpz, op: *const fmpz, p: *const fmpz);
    pub fn _padic_get_str(
        str_: *const c_char,
        op: *const padic_struct,
        p: *const fmpz,
        mode: padic_print_mode,
    ) -> *const c_char;
    pub fn padic_get_str(
        str_: *const c_char,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> *const c_char;
    pub fn _padic_fprint(
        file: *mut FILE,
        u: *const fmpz,
        v: mp_limb_signed_t,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_fprint(
        file: *mut FILE,
        op: *const padic_struct,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn _padic_print(
        u: *mut fmpz,
        v: mp_limb_signed_t,
        ctx: *const padic_ctx_struct,
    ) -> c_int;
    pub fn padic_print(op: *mut padic_struct, ctx: *const padic_ctx_struct) -> c_int;
    pub fn padic_debug(op: *mut padic_struct);
}