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
|
/*
Copyright (C) 2020 Fredrik Johansson
This file is part of Calcium.
Calcium 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 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "ca.h"
/* todo: fast check in number field */
truth_t
ca_check_is_integer(const ca_t x, ca_ctx_t ctx)
{
if (CA_IS_SPECIAL(x))
{
if (ca_is_unknown(x, ctx))
return T_UNKNOWN;
return T_FALSE;
}
else if (CA_IS_QQ(x, ctx))
{
if (fmpz_is_one(fmpq_denref(CA_FMPQ(x))))
return T_TRUE;
else
return T_FALSE;
}
else if (CA_FIELD_IS_NF(CA_FIELD(x, ctx)))
{
return nf_elem_is_integer(CA_NF_ELEM(x), CA_FIELD_NF(CA_FIELD(x, ctx))) ? T_TRUE : T_FALSE;
}
else
{
acb_t t;
truth_t res;
slong prec, prec_limit;
res = T_UNKNOWN;
acb_init(t);
prec_limit = ctx->options[CA_OPT_PREC_LIMIT];
prec_limit = FLINT_MAX(prec_limit, 64);
for (prec = 64; (prec <= prec_limit) && (res == T_UNKNOWN); prec *= 2)
{
ca_get_acb_raw(t, x, prec, ctx);
if (!acb_contains_int(t))
{
res = T_FALSE;
break;
}
/* try qqbar computation */
/* todo: precision to do this should depend on complexity of the polynomials, degree of the elements... */
if (prec == 64)
{
qqbar_t a;
qqbar_init(a);
if (ca_get_qqbar(a, x, ctx))
res = qqbar_is_integer(a) ? T_TRUE : T_FALSE;
qqbar_clear(a);
}
}
acb_clear(t);
return res;
}
}
|