void qadic_trace(padic_t rop, const qadic_t op, const qadic_ctx_t ctx) { const slong N = padic_prec(rop); if (qadic_is_zero(op) || op->val >= N) { padic_zero(rop); } else { fmpz_t pN; int alloc; alloc = _padic_ctx_pow_ui(pN, N - op->val, &ctx->pctx); _qadic_trace(padic_unit(rop), op->coeffs, op->length, ctx->a, ctx->j, ctx->len, pN); padic_val(rop) = op->val; _padic_canonicalise(rop, &ctx->pctx); if (alloc) fmpz_clear(pN); } }
void padic_teichmuller(padic_t rop, const padic_t op, const padic_ctx_t ctx) { if (padic_val(op) < 0) { flint_printf("Exception (padic_teichmuller). op is not a p-adic integer.\n"); abort(); } if (padic_is_zero(op) || padic_val(op) > 0 || padic_prec(rop) <= 0) { padic_zero(rop); } else { _padic_teichmuller(padic_unit(rop), padic_unit(op), ctx->p, padic_prec(rop)); padic_val(rop) = 0; } }
int padic_log_balanced(padic_t rop, const padic_t op, const padic_ctx_t ctx) { if (padic_val(op) < 0) { return 0; } else { fmpz_t x; int ans; fmpz_init(x); padic_get_fmpz(x, op, ctx); fmpz_sub_ui(x, x, 1); if (fmpz_is_zero(x)) { padic_zero(rop); ans = 1; } else { fmpz_t t; long v; fmpz_init(t); v = fmpz_remove(t, x, ctx->p); fmpz_clear(t); if (v >= 2 || (*(ctx->p) != 2L && v >= 1)) { if (v >= ctx->N) { padic_zero(rop); } else { _padic_log_balanced(padic_unit(rop), x, v, ctx->p, ctx->N); padic_val(rop) = 0; padic_reduce(rop, ctx); } ans = 1; } else { ans = 0; } } fmpz_clear(x); return ans; } }
void _padic_reduce(padic_t rop, const padic_ctx_t ctx) { if (!fmpz_is_zero(padic_unit(rop))) { if (padic_val(rop) < ctx->N) { int alloc; fmpz_t pow; alloc = _padic_ctx_pow_ui(pow, ctx->N - padic_val(rop), ctx); fmpz_mod(padic_unit(rop), padic_unit(rop), pow); if (alloc) fmpz_clear(pow); } else { fmpz_zero(padic_unit(rop)); padic_val(rop) = 0; } } }
void qadic_norm_resultant(padic_t rop, const qadic_t op, const qadic_ctx_t ctx) { const slong N = padic_prec(rop); const slong d = qadic_ctx_degree(ctx); /* N(p^v u) = p^{dv} N(u) */ if (qadic_is_zero(op) || d * op->val >= N) { padic_zero(rop); } else { _qadic_norm_resultant(padic_unit(rop), op->coeffs, op->length, ctx->a, ctx->j, ctx->len, (&ctx->pctx)->p, N - d * op->val); padic_val(rop) = d * op->val; } }
char * _padic_get_str(char * str, const padic_t op, const padic_ctx_t ctx) { const fmpz * u = padic_unit(op); const long v = padic_val(op); if (fmpz_is_zero(u)) { if (!str) { str = flint_malloc(2); } str[0] = '0'; str[1] = '\0'; return str; } if (ctx->mode == PADIC_TERSE) { if (v == 0) { str = fmpz_get_str(str, 10, u); } else if (v > 0) { fmpz_t t; fmpz_init(t); fmpz_pow_ui(t, ctx->p, v); fmpz_mul(t, t, u); str = fmpz_get_str(str, 10, t); fmpz_clear(t); } else /* v < 0 */ { fmpz_t t; fmpz_init(t); fmpz_pow_ui(t, ctx->p, -v); str = _fmpq_get_str(str, 10, u, t); fmpz_clear(t); } } else if (ctx->mode == PADIC_SERIES) { char *s; fmpz_t x; fmpz_t d; long j, N; if (fmpz_sgn(u) < 0) { printf("ERROR (_padic_get_str). u < 0 in SERIES mode.\n"); abort(); } N = fmpz_clog(u, ctx->p) + v; if (!str) { long b = (N - v) * (2 * fmpz_sizeinbase(ctx->p, 10) + z_sizeinbase(FLINT_MAX(FLINT_ABS(v), FLINT_ABS(N)), 10) + 5) + 1; str = flint_malloc(b); if (!str) { printf("ERROR (_padic_get_str). Memory allocation failed.\n"); abort(); } } s = str; fmpz_init(d); fmpz_init(x); fmpz_set(x, u); /* Unroll first step */ j = 0; { fmpz_mod(d, x, ctx->p); /* d = u mod p^{j+1} */ fmpz_sub(x, x, d); /* x = x - d */ fmpz_divexact(x, x, ctx->p); /* x = x / p */ if (!fmpz_is_zero(d)) { if (j + v != 0) { fmpz_get_str(s, 10, d); while (*++s != '\0') ; *s++ = '*'; fmpz_get_str(s, 10, ctx->p); while (*++s != '\0') ; *s++ = '^'; sprintf(s, "%ld", j + v); while (*++s != '\0') ; } else { fmpz_get_str(s, 10, d); while (*++s != '\0') ; } } j++; } for ( ; !fmpz_is_zero(x); j++) { fmpz_mod(d, x, ctx->p); /* d = u mod p^{j+1} */ fmpz_sub(x, x, d); /* x = x - d */ fmpz_divexact(x, x, ctx->p); /* x = x / p */ if (!fmpz_is_zero(d)) { if (j + v != 0) { *s++ = ' '; *s++ = '+'; *s++ = ' '; fmpz_get_str(s, 10, d); while (*++s != '\0') ; *s++ = '*'; fmpz_get_str(s, 10, ctx->p); while (*++s != '\0') ; *s++ = '^'; sprintf(s, "%ld", j + v); while (*++s != '\0') ; } else { *s++ = ' '; *s++ = '+'; *s++ = ' '; fmpz_get_str(s, 10, d); while (*++s != '\0') ; } } } fmpz_clear(x); fmpz_clear(d); } else /* ctx->mode == PADIC_VAL_UNIT */ { if (!str) { long b = fmpz_sizeinbase(u, 10) + fmpz_sizeinbase(ctx->p, 10) + z_sizeinbase(v, 10) + 4; str = flint_malloc(b); if (!str) { printf("ERROR (_padic_get_str). Memory allocation failed.\n"); abort(); } } if (v == 0) { str = fmpz_get_str(str, 10, u); } else if (v == 1) { char *s = str; fmpz_get_str(s, 10, u); while (*++s != '\0') ; *s++ = '*'; fmpz_get_str(s, 10, ctx->p); } else { char *s = str; fmpz_get_str(s, 10, u); while (*++s != '\0') ; *s++ = '*'; fmpz_get_str(s, 10, ctx->p); while (*++s != '\0') ; *s++ = '^'; sprintf(s, "%ld", v); } } return str; }
int main(void) { long l, len = 20; long runs[] = { 100000000, 1000000, 1000000, 1000000, 100000, 100000, 10000, 10000, 10000, 1000, 100, 100, 10, 1, 1, 1, 1, 1, 1, 1 }; long N[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, WORD(1) << 11, WORD(1) << 12, WORD(1) << 13, WORD(1) << 14, WORD(1) << 15, WORD(1) << 16, WORD(1) << 17, WORD(1) << 18, WORD(1) << 19 }; long T[20] = {0}; flint_printf("Benchmark for p-adic exponential (rectangular).\n"); fflush(stdout); for (l = 0; l < FLINT_MIN(17, len); l++) { FLINT_TEST_INIT(state); long n = N[l], r; clock_t c0, c1; long double cputime; fmpz_t p; padic_ctx_t ctx; padic_t d, z; fmpz_init_set_ui(p, 17); padic_ctx_init(ctx, p, n, n, PADIC_VAL_UNIT); padic_init(d); padic_init(z); if (n > 1) { fmpz_t f = {WORD(3)}, pow; fmpz_init(pow); fmpz_pow_ui(pow, p, n - 1); fmpz_pow_ui(padic_unit(d), f, 3 * n); fmpz_mod(padic_unit(d), padic_unit(d), pow); padic_val(d) = 1; fmpz_clear(pow); } c0 = clock(); for (r = runs[l]; (r); r--) { padic_exp_rectangular(z, d, ctx); padic_zero(z); } c1 = clock(); cputime = (long double) (c1 - c0) / (long double) CLOCKS_PER_SEC; T[l] = (slong) (cputime * (1000000000 / runs[l])); flint_printf("%2ld, %4XYXYXYXY, %9ld, %wd\n", l, cputime, runs[l], T[l]); padic_clear(d); padic_clear(z); fmpz_clear(p); padic_ctx_clear(ctx); flint_randclear(state); } flint_printf("Output as a list:\n"); for (l = 0; l < len; l++) flint_printf("%wd, ", T[l]); flint_printf("\n"); }
int main(void) { long l, len = 20; long runs[] = { 1000000, 1000000, 1000000, 1000000, 100000, 100000, 100000, 100000, 10000, 10000, 10000, 1000, 1000, 100, 100, 10, 10, 1, 1, 1 }; long N[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, WORD(1) << 11, WORD(1) << 12, WORD(1) << 13, WORD(1) << 14, WORD(1) << 15, WORD(1) << 16, WORD(1) << 17, WORD(1) << 18, WORD(1) << 19 }; long T[20] = {0}; flint_printf("Benchmark for p-adic Teichmuller.\n"); fflush(stdout); for (l = 0; l < len; l++) { FLINT_TEST_INIT(state); long n = N[l], r; clock_t c0, c1; long double cputime; fmpz_t p; padic_ctx_t ctx; padic_t c, z; fmpz_init_set_ui(p, 17); padic_ctx_init(ctx, p, n, n, PADIC_VAL_UNIT); padic_init(c); padic_init(z); fmpz_set_ui(padic_unit(c), 3); c0 = clock(); for (r = runs[l]; (r); r--) { padic_teichmuller(z, c, ctx); padic_zero(z); } c1 = clock(); cputime = (long double) (c1 - c0) / (long double) CLOCKS_PER_SEC; T[l] = (slong) (cputime * (1000000000 / runs[l])); flint_printf("%2ld, %4XYXYXYXY, %7ld, %wd\n", l, cputime, runs[l], T[l]); padic_clear(c); padic_clear(z); fmpz_clear(p); padic_ctx_clear(ctx); flint_randclear(state); } flint_printf("Output as a list:\n"); for (l = 0; l < len; l++) flint_printf("%wd, ", T[l]); flint_printf("\n"); }