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

Tetranacci #1399

Open
wants to merge 4 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_tetranacci_constant(ca_t res, ca_ctx_t ctx)

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

.. 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:: TetranacciConstant

``TetranacciConstant`` is the Tetranacci constant `T_t`.

.. 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_tetranacci_constant(qqbar_t res)

Sets *res* to the Tetranacci constant `T_t`.

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, TetranacciConstant, 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
65 changes: 65 additions & 0 deletions examples/tetranacci.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 Tt as fexpr:\n");

fexpr_set_symbol_str(T, "TetranacciConstant");

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 Tt as ca:\n");

ca_tetranacci_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 Tt as qqbar:\n");

qqbar_tetranacci_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_tetranacci_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_TetranacciConstant:
ca_tetranacci_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/tetranacci.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_tetranacci_constant(ca_t res, ca_ctx_t ctx)
{
qqbar_t tc;
qqbar_init(tc);
qqbar_tetranacci_constant(tc);

ca_set_qqbar(res, tc, ctx);

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

if (op == FEXPR_TetranacciConstant)
{
/* Subexpressions */
arb_t t1, t2, l1, p1;

/* Init */
arb_init(t1);
arb_init(t2);
arb_init(l1);
arb_init(p1);

/* t1 := 3*sqrt(1689) */
arb_sqrt_ui(t1, 1689, prec);
arb_mul_ui(t1, t1, 3, prec);

/* l1 := (cbrt(t1 - 65) - cbrt(t1 + 65)) / (12 * cbrt(2)) */
arb_zero(l1);

/* First part of l1 */
arb_sub_ui(t2, t1, 65, prec);
arb_root_ui(t2, t2, 3, prec);

arb_add(l1, l1, t2, prec);

/* Second part of l1 */
arb_add_ui(t2, t1, 65, prec);
arb_root_ui(t2, t2, 3, prec);

arb_sub(l1, l1, t2, prec);

/* Denominator of l1 */
arb_set_ui(t2, 2);
arb_root_ui(t2, t2, 3, prec);
arb_mul_ui(t2, t2, 12, prec);

/* Combine l1 */
arb_div(l1, l1, t2, prec);

/* p1 := sqrt(l1 + 11/48) */
arb_set_ui(p1, 11);
arb_div_ui(p1, p1, 48, prec);

arb_add(p1, p1, l1, prec);
arb_sqrt(p1, p1, prec);

/* t2 := 1/4 - p1 */
arb_one(t2);
arb_mul_2exp_si(t2, t2, -2);
arb_add(t2, t2, p1, prec);

/* Invert p1 */
arb_inv(p1, p1, prec);

/* Final result */
arb_one(acb_realref(res));
arb_div_ui(acb_realref(res), acb_realref(res), 6, prec);

arb_set_ui(t1, 7);
arb_div_ui(t1, t1, 24, prec);
arb_mul(t1, t1, p1, prec);
arb_add(acb_realref(res), acb_realref(res), t1, prec);

arb_sqr(t1, t2, prec);
arb_add(acb_realref(res), acb_realref(res), t1, prec);

arb_mul_ui(t1, t2, 2, prec);
arb_mul(t1, t1, l1, prec);
arb_mul(t1, t1, p1, prec);
arb_sub(acb_realref(res), acb_realref(res), t1, prec);

arb_sqrt(acb_realref(res), acb_realref(res), prec);

arb_add(acb_realref(res), acb_realref(res), t2, prec);

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

/* Free */
arb_clear(t1);
arb_clear(t2);
arb_clear(l1);
arb_clear(p1);

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 @@ -431,6 +431,7 @@ typedef enum
FEXPR_SymmetricPolynomial,
FEXPR_Tan,
FEXPR_Tanh,
FEXPR_TetranacciConstant,
FEXPR_Theta,
FEXPR_Theta_,
FEXPR_True,
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 @@ -413,6 +413,7 @@ const fexpr_symbol_info fexpr_builtin_table[FEXPR_BUILTIN_LENGTH] = {
{ FEXPR_SymmetricPolynomial, "SymmetricPolynomial", "e", fexpr_write_latex_subscript_call, },
{ FEXPR_Tan, "Tan", "\\tan", NULL, },
{ FEXPR_Tanh, "Tanh", "\\tanh", NULL, },
{ FEXPR_TetranacciConstant, "TetranacciConstant", "T_t", NULL, },
{ FEXPR_Theta, "Theta", "\\Theta", NULL },
{ FEXPR_Theta_, "Theta_", "\\Theta", fexpr_write_latex_subscript },
{ FEXPR_True, "True", "\\operatorname{True}", 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_tetranacci_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_TetranacciConstant))
{
qqbar_tetranacci_constant(res);
return 1;
}

return 0;
}

Expand Down
105 changes: 105 additions & 0 deletions src/qqbar/tetranacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
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_tetranacci_constant(qqbar_t res)
{
/* Subexpressions */
arb_t t1, t2, l1, p1;

fmpz_poly_zero(QQBAR_POLY(res));
fmpz_poly_set_coeff_si(QQBAR_POLY(res), 4, 1);
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(t1);
arb_init(t2);
arb_init(l1);
arb_init(p1);

/* t1 := 3*sqrt(1689) */
arb_sqrt_ui(t1, 1689, QQBAR_DEFAULT_PREC);
arb_mul_ui(t1, t1, 3, QQBAR_DEFAULT_PREC);

/* l1 := (cbrt(t1 - 65) - cbrt(t1 + 65)) / (12 * cbrt(2)) */
arb_zero(l1);

/* First part of l1 */
arb_sub_ui(t2, t1, 65, QQBAR_DEFAULT_PREC);
arb_root_ui(t2, t2, 3, QQBAR_DEFAULT_PREC);

arb_add(l1, l1, t2, QQBAR_DEFAULT_PREC);

/* Second part of l1 */
arb_add_ui(t2, t1, 65, QQBAR_DEFAULT_PREC);
arb_root_ui(t2, t2, 3, QQBAR_DEFAULT_PREC);

arb_sub(l1, l1, t2, QQBAR_DEFAULT_PREC);

/* Denominator of l1 */
arb_set_ui(t2, 2);
arb_root_ui(t2, t2, 3, QQBAR_DEFAULT_PREC);
arb_mul_ui(t2, t2, 12, QQBAR_DEFAULT_PREC);

/* Combine l1 */
arb_div(l1, l1, t2, QQBAR_DEFAULT_PREC);

/* p1 := sqrt(l1 + 11/48) */
arb_set_ui(p1, 11);
arb_div_ui(p1, p1, 48, QQBAR_DEFAULT_PREC);

arb_add(p1, p1, l1, QQBAR_DEFAULT_PREC);
arb_sqrt(p1, p1, QQBAR_DEFAULT_PREC);

/* t2 := 1/4 - p1 */
arb_one(t2);
arb_mul_2exp_si(t2, t2, -2);
arb_add(t2, t2, p1, QQBAR_DEFAULT_PREC);

/* Invert p1 */
arb_inv(p1, p1, QQBAR_DEFAULT_PREC);

/* Final result */
arb_one(acb_realref(QQBAR_ENCLOSURE(res)));
arb_div_ui(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), 6, QQBAR_DEFAULT_PREC);

arb_set_ui(t1, 7);
arb_div_ui(t1, t1, 24, QQBAR_DEFAULT_PREC);
arb_mul(t1, t1, p1, QQBAR_DEFAULT_PREC);
arb_add(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), t1, QQBAR_DEFAULT_PREC);

arb_sqr(t1, t2, QQBAR_DEFAULT_PREC);
arb_add(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), t1, QQBAR_DEFAULT_PREC);

arb_mul_ui(t1, t2, 2, QQBAR_DEFAULT_PREC);
arb_mul(t1, t1, l1, QQBAR_DEFAULT_PREC);
arb_mul(t1, t1, p1, QQBAR_DEFAULT_PREC);
arb_sub(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), t1, QQBAR_DEFAULT_PREC);

arb_sqrt(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), QQBAR_DEFAULT_PREC);

arb_add(acb_realref(QQBAR_ENCLOSURE(res)), acb_realref(QQBAR_ENCLOSURE(res)), t2, QQBAR_DEFAULT_PREC);

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

/* Free */
arb_clear(t1);
arb_clear(t2);
arb_clear(l1);
arb_clear(p1);
}