1 /*
2     Copyright (C) 2012 Sebastian Pancratz
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include "qadic.h"
13 
14 /*
15     Computes the norm of an element $x$ of $\mathbf{Z}_q$ via the identity
16 
17         $\Norm(x) = \exp \Trace \log (x)$
18 
19     whenever $y = 1-x$ has valuation $v$ greater than $(p-1)^{-1}$.
20 
21     Assumes that $y$ is non-zero.
22  */
23 
_qadic_norm_analytic(fmpz_t rop,const fmpz * y,slong v,slong len,const fmpz * a,const slong * j,slong lena,const fmpz_t p,slong N)24 void _qadic_norm_analytic(fmpz_t rop, const fmpz *y, slong v, slong len,
25                           const fmpz *a, const slong *j, slong lena,
26                           const fmpz_t p, slong N)
27 {
28     const slong d = j[lena - 1];
29     fmpz_t pN, tru;
30     slong trv;
31     fmpz *lg;
32 
33     fmpz_init(pN);
34     fmpz_init(tru);
35     lg = _fmpz_vec_init(d);
36 
37     fmpz_pow_ui(pN, p, N);
38 
39     _qadic_log(lg, y, v, len, a, j, lena, p, N, pN);
40 
41     _qadic_trace(tru, lg, d, a, j, lena, pN);
42 
43     if (!fmpz_is_zero(tru))
44     {
45         trv = fmpz_remove(tru, tru, p);
46         _padic_exp(rop, tru, trv, p, N);
47         fmpz_mod(rop, rop, pN);
48     }
49     else
50     {
51         fmpz_one(rop);
52     }
53 
54     fmpz_clear(pN);
55     fmpz_clear(tru);
56     _fmpz_vec_clear(lg, d);
57 }
58 
qadic_norm_analytic(padic_t rop,const qadic_t op,const qadic_ctx_t ctx)59 void qadic_norm_analytic(padic_t rop, const qadic_t op, const qadic_ctx_t ctx)
60 {
61     const slong N  = padic_prec(rop);
62     const slong d  = qadic_ctx_degree(ctx);
63     const fmpz *p = (&ctx->pctx)->p;
64 
65     /* N(p^v u) = p^{dv} N(u) */
66 
67     if (qadic_is_zero(op) || d * op->val >= N)
68     {
69         padic_zero(rop);
70     }
71     else if (op->length == 1)
72     {
73         fmpz_t pN;
74         int alloc;
75 
76         alloc = _padic_ctx_pow_ui(pN, N - d * op->val, (&ctx->pctx));
77 
78         fmpz_powm_ui(padic_unit(rop), op->coeffs + 0, d, pN);
79         padic_val(rop) = d * op->val;
80 
81         if (alloc)
82             fmpz_clear(pN);
83     }
84     else  /* len >= 2 */
85     {
86         fmpz *y;
87         slong w;
88 
89         y = _fmpz_vec_init(op->length);
90 
91         _fmpz_vec_neg(y, op->coeffs, op->length);
92         fmpz_add_ui(y + 0, y + 0, 1);
93         w = _fmpz_vec_ord_p(y, op->length, p);
94 
95         if ((w < 2 && *p == WORD(2)) || w < 1)
96         {
97             flint_printf("ERROR (qadic_norm_analytic).  w = %wd.\n", w);
98             flint_abort();
99         }
100 
101         _qadic_norm_analytic(padic_unit(rop), y, w, op->length,
102                              ctx->a, ctx->j, ctx->len, p, N - d * op->val);
103         padic_val(rop) = d * op->val;
104 
105         _fmpz_vec_clear(y, op->length);
106     }
107 }
108 
109