Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:15:33

0001 /*
0002     Copyright (C) 2011, 2012 Sebastian Pancratz
0003 
0004     This file is part of FLINT.
0005 
0006     FLINT is free software: you can redistribute it and/or modify it under
0007     the terms of the GNU Lesser General Public License (LGPL) as published
0008     by the Free Software Foundation; either version 3 of the License, or
0009     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
0010 */
0011 
0012 #ifndef PADIC_H
0013 #define PADIC_H
0014 
0015 #ifdef PADIC_INLINES_C
0016 #define PADIC_INLINE
0017 #else
0018 #define PADIC_INLINE static inline
0019 #endif
0020 
0021 #include "fmpz.h"
0022 #include "padic_types.h"
0023 
0024 #ifdef __cplusplus
0025 extern "C" {
0026 #endif
0027 
0028 #define PADIC_DEFAULT_PREC WORD(20)
0029 
0030 #define PADIC_TEST_PREC_MIN WORD(-100)
0031 #define PADIC_TEST_PREC_MAX  WORD(100)
0032 
0033 #define padic_val(x)   ((x)->v)
0034 #define padic_prec(x)  ((x)->N)
0035 
0036 PADIC_INLINE
0037 fmpz * padic_unit(const padic_t x)
0038 {
0039    return (fmpz *)(&(x->u));
0040 }
0041 
0042 PADIC_INLINE
0043 slong padic_get_val(const padic_t x)
0044 {
0045    return x->v;
0046 }
0047 
0048 PADIC_INLINE
0049 slong padic_get_prec(const padic_t x)
0050 {
0051    return x->N;
0052 }
0053 
0054 /* Context *******************************************************************/
0055 
0056 void padic_ctx_init(padic_ctx_t ctx, const fmpz_t p, slong min, slong max, enum padic_print_mode mode);
0057 void padic_ctx_clear(padic_ctx_t ctx);
0058 
0059 PADIC_INLINE
0060 int _padic_ctx_pow_ui(fmpz_t rop, ulong e, const padic_ctx_t ctx)
0061 {
0062     if (ctx->min <= (slong) e && (slong) e < ctx->max)
0063     {
0064         *rop   = *(ctx->pow + (e - ctx->min));
0065         return 0;
0066     }
0067     else
0068     {
0069         slong l = (slong) e;
0070         if (l < 0)
0071         {
0072             flint_throw(FLINT_ERROR, "Exception (_padic_ctx_pow_ui). Power too large.\ne = %wu\nl = %wd\n", e, l);
0073         }
0074 
0075         fmpz_init(rop);
0076         fmpz_pow_ui(rop, ctx->p, e);
0077         return 1;
0078     }
0079 }
0080 
0081 PADIC_INLINE
0082 void padic_ctx_pow_ui(fmpz_t rop, ulong e, const padic_ctx_t ctx)
0083 {
0084     if (ctx->min <= (slong) e && (slong) e < ctx->max)
0085         fmpz_set(rop, ctx->pow + (e - ctx->min));
0086     else
0087     {
0088         slong l = (slong) e;
0089         if (l < 0)
0090         {
0091             flint_throw(FLINT_ERROR, "Exception (padic_ctx_pow_ui). Power too large.\ne = %wu\nl = %wd\n", e, l);
0092         }
0093 
0094         fmpz_pow_ui(rop, ctx->p, e);
0095     }
0096 }
0097 
0098 /* Memory management *********************************************************/
0099 
0100 void padic_init(padic_t rop);
0101 void padic_init2(padic_t rop, slong N);
0102 void padic_clear(padic_t rop);
0103 
0104 PADIC_INLINE void _padic_canonicalise(padic_t rop, const padic_ctx_t ctx)
0105 {
0106     if (!fmpz_is_zero(padic_unit(rop)))
0107     {
0108         padic_val(rop) += _fmpz_remove(padic_unit(rop), ctx->p, ctx->pinv);
0109     }
0110     else
0111     {
0112         padic_val(rop) = 0;
0113     }
0114 }
0115 
0116 void _padic_reduce(padic_t rop, const padic_ctx_t ctx);
0117 void padic_reduce(padic_t rop, const padic_ctx_t ctx);
0118 
0119 /* Randomisation *************************************************************/
0120 
0121 void padic_randtest(padic_t rop, flint_rand_t state, const padic_ctx_t ctx);
0122 void padic_randtest_not_zero(padic_t rop, flint_rand_t state, const padic_ctx_t ctx);
0123 void padic_randtest_int(padic_t rop, flint_rand_t state, const padic_ctx_t ctx);
0124 
0125 /* Assignments and conversions ***********************************************/
0126 
0127 void padic_set_si(padic_t rop, slong op, const padic_ctx_t ctx);
0128 void padic_set_ui(padic_t rop, ulong op, const padic_ctx_t ctx);
0129 void padic_set_fmpz(padic_t rop, const fmpz_t op, const padic_ctx_t ctx);
0130 void padic_set_fmpq(padic_t rop, const fmpq_t op, const padic_ctx_t ctx);
0131 #ifdef __GMP_H__
0132 void padic_set_mpz(padic_t rop, const mpz_t op, const padic_ctx_t ctx);
0133 void padic_set_mpq(padic_t rop, const mpq_t op, const padic_ctx_t ctx);
0134 #endif
0135 void padic_set(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0136 
0137 void padic_get_fmpz(fmpz_t rop, const padic_t op, const padic_ctx_t ctx);
0138 void padic_get_fmpq(fmpq_t rop, const padic_t op, const padic_ctx_t ctx);
0139 #ifdef __GMP_H__
0140 void padic_get_mpz(mpz_t rop, const padic_t op, const padic_ctx_t ctx);
0141 void padic_get_mpq(mpq_t rop, const padic_t op, const padic_ctx_t ctx);
0142 #endif
0143 
0144 PADIC_INLINE void padic_swap(padic_t op1, padic_t op2)
0145 {
0146     FLINT_SWAP(padic_struct, *op1, *op2);
0147 }
0148 
0149 PADIC_INLINE void padic_zero(padic_t rop)
0150 {
0151     fmpz_zero(padic_unit(rop));
0152     padic_val(rop) = 0;
0153 }
0154 
0155 PADIC_INLINE void padic_one(padic_t rop)
0156 {
0157     if (padic_prec(rop) > 0)
0158     {
0159         fmpz_one(padic_unit(rop));
0160         padic_val(rop) = 0;
0161     }
0162     else
0163         padic_zero(rop);
0164 }
0165 
0166 /* Comparison ****************************************************************/
0167 
0168 PADIC_INLINE int padic_is_zero(const padic_t op)
0169 {
0170     return fmpz_is_zero(padic_unit(op));
0171 }
0172 
0173 PADIC_INLINE int padic_is_one(const padic_t op)
0174 {
0175     return fmpz_is_one(padic_unit(op)) && (padic_val(op) == 0);
0176 }
0177 
0178 PADIC_INLINE int padic_equal(const padic_t op1, const padic_t op2)
0179 {
0180     return (padic_val(op1) == padic_val(op2)) &&
0181            (fmpz_equal(padic_unit(op1), padic_unit(op2)));
0182 }
0183 
0184 /* Arithmetic operations *****************************************************/
0185 
0186 slong * _padic_lifts_exps(slong *n, slong N);
0187 
0188 void _padic_lifts_pows(fmpz *pow, const slong *a, slong n, const fmpz_t p);
0189 
0190 void padic_add(padic_t rop, const padic_t op1, const padic_t op2, const padic_ctx_t ctx);
0191 void padic_sub(padic_t rop, const padic_t op1, const padic_t op2, const padic_ctx_t ctx);
0192 
0193 void padic_neg(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0194 
0195 void padic_mul(padic_t rop, const padic_t op1, const padic_t op2, const padic_ctx_t ctx);
0196 
0197 void padic_shift(padic_t rop, const padic_t op, slong v, const padic_ctx_t ctx);
0198 
0199 void padic_div(padic_t rop, const padic_t op1, const padic_t op2, const padic_ctx_t ctx);
0200 
0201 void _padic_inv_precompute(padic_inv_t S, const fmpz_t p, slong N);
0202 void _padic_inv_clear(padic_inv_t S);
0203 
0204 void _padic_inv_precomp(fmpz_t rop, const fmpz_t op, const padic_inv_t S);
0205 void _padic_inv(fmpz_t rop, const fmpz_t op, const fmpz_t p, slong N);
0206 
0207 void padic_inv(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0208 
0209 int _padic_sqrt(fmpz_t rop, const fmpz_t op, const fmpz_t p, slong N);
0210 int padic_sqrt(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0211 
0212 void padic_pow_si(padic_t rop, const padic_t op, slong e, const padic_ctx_t ctx);
0213 
0214 /* Exponential ***************************************************************/
0215 
0216 slong _padic_exp_bound(slong v, slong N, const fmpz_t p);
0217 
0218 void _padic_exp(fmpz_t rop, const fmpz_t u, slong v, const fmpz_t p, slong N);
0219 void _padic_exp_rectangular(fmpz_t rop, const fmpz_t u, slong v, const fmpz_t p, slong N);
0220 void _padic_exp_balanced(fmpz_t rop, const fmpz_t u, slong v, const fmpz_t p, slong N);
0221 
0222 int padic_exp(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0223 int padic_exp_rectangular(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0224 int padic_exp_balanced(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0225 
0226 /* Logarithm *****************************************************************/
0227 
0228 slong _padic_log_bound(slong v, slong N, const fmpz_t p);
0229 
0230 void _padic_log(fmpz_t z, const fmpz_t y, slong v, const fmpz_t p, slong N);
0231 void _padic_log_rectangular(fmpz_t z, const fmpz_t y, slong v, const fmpz_t p, slong N);
0232 void _padic_log_satoh(fmpz_t z, const fmpz_t y, slong v, const fmpz_t p, slong N);
0233 void _padic_log_balanced(fmpz_t z, const fmpz_t y, slong FLINT_UNUSED(v), const fmpz_t p, slong N);
0234 
0235 int padic_log(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0236 int padic_log_rectangular(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0237 int padic_log_satoh(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0238 int padic_log_balanced(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0239 
0240 /* Special functions *********************************************************/
0241 
0242 void _padic_teichmuller(fmpz_t rop, const fmpz_t op, const fmpz_t p, slong N);
0243 void padic_teichmuller(padic_t rop, const padic_t op, const padic_ctx_t ctx);
0244 
0245 ulong padic_val_fac_ui_2(ulong N);
0246 ulong padic_val_fac_ui(ulong N, const fmpz_t p);
0247 void padic_val_fac(fmpz_t rop, const fmpz_t op, const fmpz_t p);
0248 
0249 /* Input and output **********************************************************/
0250 
0251 char * _padic_get_str(char * str, const padic_t op, const fmpz_t p, enum padic_print_mode mode);
0252 char * padic_get_str(char * str, const padic_t op, const padic_ctx_t ctx);
0253 
0254 #ifdef FLINT_HAVE_FILE
0255 int _padic_fprint(FILE * file, const fmpz_t u, slong v, const padic_ctx_t ctx);
0256 int padic_fprint(FILE * file, const padic_t op, const padic_ctx_t ctx);
0257 #endif
0258 
0259 int _padic_print(const fmpz_t u, slong v, const padic_ctx_t ctx);
0260 int padic_print(const padic_t op, const padic_ctx_t ctx);
0261 void padic_debug(const padic_t op);
0262 
0263 #ifdef __cplusplus
0264 }
0265 #endif
0266 
0267 #endif