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
/*
Copyright (C) 2020 Fredrik Johansson
This file is part of FLINT.
FLINT 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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "ca.h"
truth_t
ca_check_is_real(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))
{
return T_TRUE;
}
else if (CA_IS_QQ_I(x, ctx))
{
const fmpz *n;
n = QNF_ELEM_NUMREF(CA_NF_ELEM(x));
if (fmpz_is_zero(n + 1))
return T_TRUE;
return T_FALSE;
}
else /* todo: first inspect extension numbers */
{
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 (arb_is_zero(acb_imagref(t)))
{
res = T_TRUE;
break;
}
if (!arb_contains_zero(acb_imagref(t)))
{
res = T_FALSE;
break;
}
/* try conjugation */
/* todo: precision to do this should depend on complexity of the polynomials, degree of the elements... */
if (prec == 64)
{
ca_t t;
ca_init(t, ctx);
ca_conj_deep(t, x, ctx);
res = ca_check_equal(t, x, ctx);
ca_clear(t, ctx);
if (res != T_UNKNOWN)
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_sgn_im(a) == 0) ? T_TRUE : T_FALSE;
qqbar_clear(a);
}
}
acb_clear(t);
return res;
}
}