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

Golden ratio #43

Open
wants to merge 3 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_phi(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
25 changes: 25 additions & 0 deletions ca/phi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (C) 2020 Fredrik Johansson
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_phi(ca_t res, ca_ctx_t ctx)
{
qqbar_t phi;
qqbar_init(phi);
qqbar_phi(phi);

ca_set_qqbar(res, phi, ctx);

qqbar_clear(phi);
}
4 changes: 1 addition & 3 deletions ca/set_fexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ _ca_set_fexpr(ca_t res, fexpr_vec_t inputs, ca_vec_t outputs, const fexpr_t expr
ca_euler(res, ctx);
return 1;
case FEXPR_GoldenRatio:
ca_sqrt_ui(res, 5, ctx);
ca_add_ui(res, res, 1, ctx);
ca_div_ui(res, res, 2, ctx);
ca_phi(res, ctx);
return 1;
case FEXPR_Infinity:
ca_pos_inf(res, ctx);
Expand Down
4 changes: 4 additions & 0 deletions doc/source/ca.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ Special values
Sets *res* to Euler's constant `\gamma`. This creates an element
of the (transcendental?) number field `\mathbb{Q}(\gamma)`.

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

Sets *res* to the golden ratio `\varphi`.

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

Sets *res* to the meta-value *Unknown*.
Expand Down
64 changes: 64 additions & 0 deletions examples/golden_ratio.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 Phi;
fexpr_init(Phi);

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

fexpr_set_symbol_str(Phi, "GoldenRatio");

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

fexpr_clear(Phi);
}


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

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

ca_phi(Phi, ctx);

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

ca_clear(Phi, ctx);
}


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

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

qqbar_phi(Phi);

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

qqbar_clear(Phi);
}


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

flint_cleanup();
return EXIT_SUCCESS;
}