Skip to content
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

Tribonacci #1398

Open
wants to merge 7 commits into
base: main
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
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
4 changes: 3 additions & 1 deletion doc/source/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ References

.. [Whiteman1956] \Whiteman, A. L. : A sum connected with the series for the partition function, Pacific Journal of Mathematics 6:1 (1956) 159--176

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

.. [Zip1985] \R. Zippel. "Simplification of expressions involving radicals". Journal of Symbolic Computation (1985) 1, 189-210. https://doi.org/10.1016/S0747-7171(85)80014-6

.. [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
Expand All @@ -295,4 +297,4 @@ References

.. [vdH2006] \J. van der Hoeven, "Computations with effective real numbers". Theoretical Computer Science, Volume 351, Issue 1, 14 February 2006, Pages 52-60. https://doi.org/10.1016/j.tcs.2005.09.060

All referenced works: [AbbottBronsteinMulders1999]_, [Apostol1997]_, [Ari2011]_, [Ari2012]_, [Arn2010]_, [ArnoldMonagan2011]_, [BBC1997]_, [BBC2000]_, [BBK2014]_, [BD1992]_, [BF2020]_, [BFSS2006]_, [BJ2013]_, [BM1980]_, [BZ1992]_, [BZ2011]_, [BaiWag1980]_, [BerTas2010]_, [Blo2009]_, [Bodrato2010]_, [Boe2020]_, [Bog2012]_, [Bor1987]_, [Bor2000]_, [Bre1978]_, [Bre1979]_, [Bre2010]_, [BrentKung1978]_, [BuhlerCrandallSompolski1992]_, [CGHJK1996]_, [CP2005]_, [Car1995]_, [Car2004]_, [Chen2003]_, [Cho1999]_, [Coh1996]_, [Coh2000]_, [Col1971]_, [CraPom2005]_, [DYF1999]_, [DelegliseNicolasZimmermann2009]_, [DomKanTro1987]_, [Dup2006]_, [Dus1999]_, [EHJ2016]_, [EM2004]_, [Fie2007]_, [FieHof2014]_, [Fil1992]_, [GCL1992]_, [GG2003]_, [GS2003]_, [GVL1996]_, [Gas2018]_, [GowWag2008]_, [GraMol2010]_, [HM2017]_, [HS1967]_, [HZ2004]_, [HanZim2004]_, [Har2010]_, [Har2012]_, [Har2015]_, [Har2018]_, [Hart2010]_, [Hen1956]_, [Hoe2001]_, [Hoe2009]_, [Hor1972]_, [Iliopoulos1989]_, [JB2018]_, [JM2018]_, [JR1999]_, [Joh2012]_, [Joh2013]_, [Joh2014a]_, [Joh2014b]_, [Joh2014c]_, [Joh2015]_, [Joh2016]_, [Joh2017]_, [Joh2017a]_, [Joh2017b]_, [Joh2018a]_, [Joh2018b]_, [JvdP2002]_, [Kahan1991]_, [KanBac1979]_, [Kar1998]_, [Knu1997]_, [Kob2010]_, [Kri2013]_, [Leh1970]_, [LukPatWil1996]_, [MP2006]_, [MPFR2012]_, [MasRob1996]_, [Mic2007]_, [Miy2010]_, [Mos1971]_, [Mul2000]_, [NIST2012]_, [NakTurWil1997]_, [Olv1997]_, [PP2010]_, [PS1973]_, [PS1991]_, [Paterson1973]_, [PernetStein2010]_, [Pet1999]_, [Pla2011]_, [Pla2017]_, [RF1994]_, [Rad1973]_, [Rademacher1937]_, [Ric1992]_, [Ric1995]_, [Ric1997]_, [Ric2007]_, [Ric2009]_, [RosSch1962]_, [Rum2010]_, [Smi2001]_, [SorWeb2016]_, [Ste2002]_, [Ste2010]_, [Stehle2010]_, [Stein2007]_, [Sut2007]_, [StoMul1998]_, [Str1997]_, [Str2012]_, [Tak2000]_, [ThullYap1990]_, [Tre2008]_, [Tru2011]_, [Tru2014]_, [Tur1953]_, [Villard2007]_, [WaktinsZeitlin1993]_, [Wei2000]_, [Whiteman1956]_, [Zip1985]_, [vHP2012]_, [vdH1995]_, [vdH2006]_
All referenced works: [AbbottBronsteinMulders1999]_, [Apostol1997]_, [Ari2011]_, [Ari2012]_, [Arn2010]_, [ArnoldMonagan2011]_, [BBC1997]_, [BBC2000]_, [BBK2014]_, [BD1992]_, [BF2020]_, [BFSS2006]_, [BJ2013]_, [BM1980]_, [BZ1992]_, [BZ2011]_, [BaiWag1980]_, [BerTas2010]_, [Blo2009]_, [Bodrato2010]_, [Boe2020]_, [Bog2012]_, [Bor1987]_, [Bor2000]_, [Bre1978]_, [Bre1979]_, [Bre2010]_, [BrentKung1978]_, [BuhlerCrandallSompolski1992]_, [CGHJK1996]_, [CP2005]_, [Car1995]_, [Car2004]_, [Chen2003]_, [Cho1999]_, [Coh1996]_, [Coh2000]_, [Col1971]_, [CraPom2005]_, [DYF1999]_, [DelegliseNicolasZimmermann2009]_, [DomKanTro1987]_, [Dup2006]_, [Dus1999]_, [EHJ2016]_, [EM2004]_, [Fie2007]_, [FieHof2014]_, [Fil1992]_, [GCL1992]_, [GG2003]_, [GS2003]_, [GVL1996]_, [Gas2018]_, [GowWag2008]_, [GraMol2010]_, [HM2017]_, [HS1967]_, [HZ2004]_, [HanZim2004]_, [Har2010]_, [Har2012]_, [Har2015]_, [Har2018]_, [Hart2010]_, [Hen1956]_, [Hoe2001]_, [Hoe2009]_, [Hor1972]_, [Iliopoulos1989]_, [JB2018]_, [JM2018]_, [JR1999]_, [Joh2012]_, [Joh2013]_, [Joh2014a]_, [Joh2014b]_, [Joh2014c]_, [Joh2015]_, [Joh2016]_, [Joh2017]_, [Joh2017a]_, [Joh2017b]_, [Joh2018a]_, [Joh2018b]_, [JvdP2002]_, [Kahan1991]_, [KanBac1979]_, [Kar1998]_, [Knu1997]_, [Kob2010]_, [Kri2013]_, [Leh1970]_, [LukPatWil1996]_, [MP2006]_, [MPFR2012]_, [MasRob1996]_, [Mic2007]_, [Miy2010]_, [Mos1971]_, [Mul2000]_, [NIST2012]_, [NakTurWil1997]_, [Olv1997]_, [PP2010]_, [PS1973]_, [PS1991]_, [Paterson1973]_, [PernetStein2010]_, [Pet1999]_, [Pla2011]_, [Pla2017]_, [RF1994]_, [Rad1973]_, [Rademacher1937]_, [Ric1992]_, [Ric1995]_, [Ric1997]_, [Ric2007]_, [Ric2009]_, [RosSch1962]_, [Rum2010]_, [Smi2001]_, [SorWeb2016]_, [Ste2002]_, [Ste2010]_, [Stehle2010]_, [Stein2007]_, [Sut2007]_, [StoMul1998]_, [Str1997]_, [Str2012]_, [Tak2000]_, [ThullYap1990]_, [Tre2008]_, [Tru2011]_, [Tru2014]_, [Tur1953]_, [Villard2007]_, [WaktinsZeitlin1993]_, [Wei2000]_, [Whiteman1956]_, [Wol1998]_, [Zip1985]_, [vHP2012]_, [vdH1995]_, [vdH2006]_
65 changes: 65 additions & 0 deletions examples/tribonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* This file is public domain. Author: Raoul Bourquin. */

#include <stdlib.h>
#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;
}
2 changes: 2 additions & 0 deletions src/ca.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,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 src/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 src/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);
}
46 changes: 46 additions & 0 deletions src/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 src/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 src/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 src/qqbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,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 src/qqbar/set_fexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,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
64 changes: 64 additions & 0 deletions src/qqbar/tribonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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 "fmpz_poly.h"
#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);
}