Skip to content

Tribonacci #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ca.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ void ca_pi(ca_t res, ca_ctx_t ctx);
void ca_pi_i(ca_t res, ca_ctx_t ctx);
void ca_euler(ca_t res, ca_ctx_t ctx);

void ca_tribonacci_constant(ca_t res, ca_ctx_t ctx);

void ca_unknown(ca_t x, ca_ctx_t ctx);

void ca_undefined(ca_t x, ca_ctx_t ctx);
Expand Down
3 changes: 3 additions & 0 deletions ca/set_fexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ _ca_set_fexpr(ca_t res, fexpr_vec_t inputs, ca_vec_t outputs, const fexpr_t expr
ca_add_ui(res, res, 1, ctx);
ca_div_ui(res, res, 2, ctx);
return 1;
case FEXPR_TribonacciConstant:
ca_tribonacci_constant(res, ctx);
return 1;
case FEXPR_Infinity:
ca_pos_inf(res, ctx);
return 1;
Expand Down
24 changes: 24 additions & 0 deletions ca/tribonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright (C) 2022 Raoul Bourquin

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"

void
ca_tribonacci_constant(ca_t res, ca_ctx_t ctx)
{
qqbar_t tc;
qqbar_init(tc);
qqbar_tribonacci_constant(tc);

ca_set_qqbar(res, tc, ctx);

qqbar_clear(tc);
}
4 changes: 3 additions & 1 deletion doc/source/bibliography.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bibliography

(In the PDF edition, this section is empty. See the bibliography listing at the end of the document.)

All referenced works: [BBK2014]_, [BF2020]_, [BFSS2006]_, [Boe2020]_, [Car2004]_, [Cho1999]_, [Coh1996]_, [Coh2000]_, [Fie2007]_, [GCL1992]_, [Har2010]_, [Har2015]_, [Har2018]_, [Joh2017]_, [JR1999]_, [Mos1971]_, [MP2006]_, [RF1994]_, [Ric1992]_, [Ric1995]_, [Ric1997]_, [Ric2007]_, [Ric2009]_, [Ste2002]_, [Ste2010]_, [Str1997]_, [Str2012]_, [vdH1995]_, [vdH2006]_, [vHP2012]_, [Zip1985]_.
All referenced works: [BBK2014]_, [BF2020]_, [BFSS2006]_, [Boe2020]_, [Car2004]_, [Cho1999]_, [Coh1996]_, [Coh2000]_, [Fie2007]_, [GCL1992]_, [Har2010]_, [Har2015]_, [Har2018]_, [Joh2017]_, [JR1999]_, [Mos1971]_, [MP2006]_, [RF1994]_, [Ric1992]_, [Ric1995]_, [Ric1997]_, [Ric2007]_, [Ric2009]_, [Ste2002]_, [Ste2010]_, [Str1997]_, [Str2012]_, [Wol1998]_, [vdH1995]_, [vdH2006]_, [vHP2012]_, [Zip1985]_.

.. [BBK2014] \D. H. Bailey, J. M. Borwein and A. D. Kaiser. "Automated simplification of large symbolic expressions". Journal of Symbolic Computation Volume 60, January 2014, Pages 120-136. https://doi.org/10.1016/j.jsc.2013.09.001

Expand Down Expand Up @@ -61,6 +61,8 @@ All referenced works: [BBK2014]_, [BF2020]_, [BFSS2006]_, [Boe2020]_, [Car2004]_

.. [Str2012] \A. Strzebonski. "Real root isolation for exp-log-arctan functions". Journal of Symbolic Computation 47 (2012) 282–314. https://doi.org/10.1016/j.jsc.2011.11.004

.. [Wol1998] \D. A. Wolfram. "Solving Generalized Fibonacci Recurrences". The Fibonacci Quarterly 36 (1998) 129-145.

.. [vHP2012] \M. van Hoeij and V. Pal. "Isomorphisms of algebraic number fields". Journal de Théorie des Nombres de Bordeaux, Vol. 24, No. 2 (2012), pp. 293-305. https://doi.org/10.2307/43973105

.. [vdH1995] \J. van der Hoeven, "Automatic numerical expansions". Proc. of the conference Real numbers and computers (1995), 261-274. https://www.texmacs.org/joris/ane/ane-abs.html
Expand Down
5 changes: 5 additions & 0 deletions doc/source/ca.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ Special values
Sets *res* to Euler's constant `\gamma`. This creates an element
of the (transcendental?) number field `\mathbb{Q}(\gamma)`.

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

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

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

Sets *res* to the meta-value *Unknown*.
Expand Down
4 changes: 4 additions & 0 deletions doc/source/fexpr_builtin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ Particular numbers

``GoldenRatio`` is the golden ratio `\varphi`.

.. macro:: TribonacciConstant

``TribonacciConstant`` is the Tribonacci constant `T_c`.

.. macro:: Euler

``Euler`` is Euler's constant `\gamma`.
Expand Down
6 changes: 5 additions & 1 deletion doc/source/qqbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ Special values

Sets *res* to the golden ratio `\varphi = \tfrac{1}{2}(\sqrt{5} + 1)`.

.. function:: void qqbar_tribonacci_constant(qqbar_t res)

Sets *res* to the Tribonacci constant `T_c = \tfrac{1}{3}(1 + \sqrt[3]{19 + 3\sqrt{33}} + \sqrt[3]{19 - 3\sqrt{33}})`.

Input and output
-------------------------------------------------------------------------------

Expand Down Expand Up @@ -811,7 +815,7 @@ Symbolic expressions and conversion to radicals
* Arithmetic operations with algebraic operands
* Square roots of algebraic numbers
* Powers with algebraic base and exponent an explicit rational number
* NumberI, GoldenRatio, RootOfUnity
* NumberI, GoldenRatio, TribonacciConstant, RootOfUnity
* Floor, Ceil, Abs, Sign, Csgn, Conjugate, Re, Im, Max, Min
* Trigonometric functions with argument an explicit rational number times Pi
* Exponentials with argument an explicit rational number times Pi * NumberI
Expand Down
64 changes: 64 additions & 0 deletions examples/tribonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* This file is public domain. Author: Raoul Bourquin. */

#include "ca.h"


void main_fexpr()
{
fexpr_t T;
fexpr_init(T);

flint_printf("Evaluating Tc as fexpr:\n");

fexpr_set_symbol_str(T, "TribonacciConstant");

fexpr_print(T);
printf("\n\n");

fexpr_clear(T);
}


void main_ca()
{
ca_ctx_t ctx;
ca_t T;
ca_ctx_init(ctx);
ca_init(T, ctx);

flint_printf("Evaluating Tc as ca:\n");

ca_tribonacci_constant(T, ctx);

ca_print(T, ctx);
printf("\n\n");

ca_clear(T, ctx);
}


void main_qqbar()
{
qqbar_t T;
qqbar_init(T);

flint_printf("Evaluating Tc as qqbar:\n");

qqbar_tribonacci_constant(T);

qqbar_printn(T, 50);
printf("\n");

qqbar_clear(T);
}


int main(int argc, char *argv[])
{
main_fexpr();
main_ca();
main_qqbar();

flint_cleanup();
return EXIT_SUCCESS;
}
46 changes: 46 additions & 0 deletions fexpr/numerical_enclosure.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,52 @@ fexpr_get_acb_raw(acb_t res, const fexpr_t expr, slong prec)
return 1;
}

if (op == FEXPR_TribonacciConstant)
{
/* Subexpressions */
arb_t r33, r33p, r33m;

/* Init */
arb_init(r33);
arb_init(r33p);
arb_init(r33m);

/* r33 := 3*sqrt(33) */
arb_sqrt_ui(r33, 33, prec);
arb_mul_ui(r33, r33, 3, prec);

/* r33p := cbrt(19 + r33) */
arb_add_ui(r33p, r33, 19, prec);
arb_root_ui(r33p, r33p, 3, prec);

/* r33m := cbrt(19 - r33) */
arb_sub_si(r33m, r33, 19, prec);
arb_neg(r33m, r33m);
arb_root_ui(r33m, r33m, 3, prec);

/* res := 1 */
arb_one(acb_realref(res));

/* res += r33p */
arb_add(acb_realref(res), acb_realref(res), r33p, prec);

/* res += r33m */
arb_add(acb_realref(res), acb_realref(res), r33m, prec);

/* res /= 3 */
arb_div_ui(acb_realref(res), acb_realref(res), 3, prec);

/* zero imag part */
arb_zero(acb_imagref(res));

/* Free */
arb_clear(r33);
arb_clear(r33p);
arb_clear(r33m);

return 1;
}

acb_indeterminate(res);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions fexpr_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ typedef enum
FEXPR_Tanh,
FEXPR_Theta,
FEXPR_Theta_,
FEXPR_TribonacciConstant,
FEXPR_True,
FEXPR_Tuple,
FEXPR_Tuples,
Expand Down
1 change: 1 addition & 0 deletions fexpr_builtin/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ const fexpr_symbol_info fexpr_builtin_table[FEXPR_BUILTIN_LENGTH] = {
{ FEXPR_Tanh, "Tanh", "\\tanh", NULL, },
{ FEXPR_Theta, "Theta", "\\Theta", NULL },
{ FEXPR_Theta_, "Theta_", "\\Theta", fexpr_write_latex_subscript },
{ FEXPR_TribonacciConstant, "TribonacciConstant", "T_c", NULL, },
{ FEXPR_True, "True", "\\operatorname{True}", NULL, },
{ FEXPR_Tuple, "Tuple", "", fexpr_write_latex_collection, },
{ FEXPR_Tuples, "Tuples", "", NULL, },
Expand Down
2 changes: 2 additions & 0 deletions qqbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ void qqbar_i(qqbar_t res);

void qqbar_phi(qqbar_t res);

void qqbar_tribonacci_constant(qqbar_t res);

/* Random generation */

void qqbar_randtest(qqbar_t res, flint_rand_t state, slong deg, slong bits);
Expand Down
6 changes: 6 additions & 0 deletions qqbar/set_fexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ qqbar_set_fexpr(qqbar_t res, const fexpr_t expr)
return 1;
}

if (fexpr_is_builtin_symbol(expr, FEXPR_TribonacciConstant))
{
qqbar_tribonacci_constant(res);
return 1;
}

return 0;
}

Expand Down
63 changes: 63 additions & 0 deletions qqbar/tribonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright (C) 2022 Raoul Bourquin

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 "qqbar.h"

void
qqbar_tribonacci_constant(qqbar_t res)
{
/* Subexpressions */
arb_t r33, r33p, r33m;

fmpz_poly_zero(QQBAR_POLY(res));
fmpz_poly_set_coeff_si(QQBAR_POLY(res), 3, 1);
fmpz_poly_set_coeff_si(QQBAR_POLY(res), 2, -1);
fmpz_poly_set_coeff_si(QQBAR_POLY(res), 1, -1);
fmpz_poly_set_coeff_si(QQBAR_POLY(res), 0, -1);

/* Init */
arb_init(r33);
arb_init(r33p);
arb_init(r33m);

/* r33 := 3*sqrt(33) */
arb_sqrt_ui(r33, 33, QQBAR_DEFAULT_PREC);
arb_mul_ui(r33, r33, 3, QQBAR_DEFAULT_PREC);

/* r33p := cbrt(19 + r33) */
arb_add_ui(r33p, r33, 19, QQBAR_DEFAULT_PREC);
arb_root_ui(r33p, r33p, 3, QQBAR_DEFAULT_PREC);

/* r33m := cbrt(19 - r33) */
arb_sub_si(r33m, r33, 19, QQBAR_DEFAULT_PREC);
arb_neg(r33m, r33m);
arb_root_ui(r33m, r33m, 3, QQBAR_DEFAULT_PREC);

/* res := 1 */
arb_one(acb_realref(QQBAR_ENCLOSURE(res)));

/* res += r33p */
arb_add(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), r33p, QQBAR_DEFAULT_PREC);

/* res += r33m */
arb_add(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), r33m, QQBAR_DEFAULT_PREC);

/* res /= 3 */
arb_div_ui(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), 3, QQBAR_DEFAULT_PREC);

/* zero imag part */
arb_zero(acb_imagref(QQBAR_ENCLOSURE(res)));

/* Free */
arb_clear(r33);
arb_clear(r33p);
arb_clear(r33m);
}