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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
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 "qqbar.h"
int
qqbar_acot_pi(slong * p, ulong * q, const qqbar_t x)
{
slong deg = qqbar_degree(x);
*p = 0;
*q = 1;
if (deg == 1)
{
if (qqbar_is_zero(x))
{
*p = 1;
*q = 2;
return 1;
}
if (qqbar_is_one(x))
{
*p = 1;
*q = 4;
return 1;
}
if (qqbar_is_neg_one(x))
{
*p = -1;
*q = 4;
return 1;
}
return 0;
}
else if (deg == 2)
{
fmpz a, b, c;
a = QQBAR_COEFFS(x)[0];
b = QQBAR_COEFFS(x)[1];
c = QQBAR_COEFFS(x)[2];
if (a == -3 && b == 0 && c == 1)
{
*p = qqbar_sgn_re(x);
*q = 6;
return 1;
}
if (a == -1 && b == 0 && c == 3)
{
*p = qqbar_sgn_re(x);
*q = 3;
return 1;
}
if (a == -1 && b == 2 && c == 1)
{
*p = (qqbar_sgn_re(x) == 1) ? 3 : -1;
*q = 8;
return 1;
}
if (a == -1 && b == -2 && c == 1)
{
*p = (qqbar_sgn_re(x) == 1) ? 1 : -3;
*q = 8;
return 1;
}
if (a == 1 && b == -4 && c == 1)
{
/* root is ~0.267 or ~3.73 -- accuracy should not be that bad */
if (arb_contains_si(acb_realref(QQBAR_ENCLOSURE(x)), 1))
flint_throw(FLINT_ERROR, "(%s)\n", __func__);
*p = (arf_cmpabs_2exp_si(arb_midref(acb_realref(QQBAR_ENCLOSURE(x))), 0) < 0) ? 5 : 1;
*q = 12;
return 1;
}
if (a == 1 && b == 4 && c == 1)
{
if (arb_contains_si(acb_realref(QQBAR_ENCLOSURE(x)), -1))
flint_throw(FLINT_ERROR, "(%s)\n", __func__);
*p = (arf_cmpabs_2exp_si(arb_midref(acb_realref(QQBAR_ENCLOSURE(x))), 0) < 0) ? -5 : -1;
*q = 12;
return 1;
}
return 0;
}
else if ((deg % 2 != 0) || !qqbar_is_real(x))
{
return 0;
}
else
{
int res;
qqbar_t t;
qqbar_init(t);
qqbar_inv(t, x);
res = qqbar_atan_pi(p, q, t);
qqbar_clear(t);
return res;
}
}