Skip to content

Commit e62a1b6

Browse files
author
Raoul Bourquin
committed
Represent ca_tribonacci_constant in Q(a) where a^3-a^2-a-1 = 0
1 parent 379f608 commit e62a1b6

File tree

2 files changed

+7
-43
lines changed

2 files changed

+7
-43
lines changed

doc/source/ca.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ Special values
351351

352352
.. function:: void ca_tribonacci_constant(ca_t res, ca_ctx_t ctx)
353353

354-
Sets *res* to the Tribonacci constant `T_c`.
354+
Sets *res* to the Tribonacci constant `T_c`. This creates an element
355+
of the algebraic number field `\mathbb{Q}(T_c)`.
355356

356357
.. function:: void ca_unknown(ca_t res, ca_ctx_t ctx)
357358

src/ca/tribonacci.c

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,11 @@
1414
void
1515
ca_tribonacci_constant(ca_t res, ca_ctx_t ctx)
1616
{
17-
/* Subexpressions */
18-
ca_t third, r33, r33p, r33m;
17+
qqbar_t tc;
18+
qqbar_init(tc);
19+
qqbar_tribonacci_constant(tc);
1920

20-
/* Init */
21-
ca_init(third, ctx);
22-
ca_init(r33, ctx);
23-
ca_init(r33p, ctx);
24-
ca_init(r33m, ctx);
21+
ca_set_qqbar(res, tc, ctx);
2522

26-
/* third := 1/3 */
27-
ca_one(third, ctx);
28-
ca_div_ui(third, third, 3, ctx);
29-
30-
/* r33 := 3*sqrt(33) */
31-
ca_sqrt_ui(r33, 33, ctx);
32-
ca_mul_ui(r33, r33, 3, ctx);
33-
34-
/* r33p := cbrt(19 + r33) */
35-
ca_add_ui(r33p, r33, 19, ctx);
36-
/* Todo: now suitable root function in calcium yet */
37-
/* ca_root_ui(r33p, r33p, 3, ctx); */
38-
ca_pow(r33p, r33p, third, ctx);
39-
40-
/* r33m := cbrt(19 - r33) */
41-
ca_sub_si(r33m, r33, 19, ctx);
42-
ca_neg(r33m, r33m, ctx);
43-
/* Todo: now suitable root function in calcium yet */
44-
/* ca_root_ui(r33m, r33m, 3, ctx); */
45-
ca_pow(r33m, r33m, third, ctx);
46-
47-
/* res := 1 */
48-
ca_one(res, ctx);
49-
/* res += r33p */
50-
ca_add(res, res, r33p, ctx);
51-
/* res += r33m */
52-
ca_add(res, res, r33m, ctx);
53-
/* res /= 3 */
54-
ca_div_ui(res, res, 3, ctx);
55-
56-
/* Free */
57-
ca_clear(third, ctx);
58-
ca_clear(r33, ctx);
59-
ca_clear(r33p, ctx);
60-
ca_clear(r33m, ctx);
23+
qqbar_clear(tc);
6124
}

0 commit comments

Comments
 (0)