Name:

implementconstant implements a constant in arbitrary precision

Library names:

void sollya_lib_implementconstant(sollya_obj_t, ...); void sollya_lib_v_implementconstant(sollya_obj_t, va_list);

Usage:

implementconstant(expr) : constant -> void implementconstant(expr,filename) : (constant, string) -> void implementconstant(expr,filename,functionname) : (constant, string, string) -> void

Description:

Example 1:

   > implementconstant(exp(1)+log(2)/sqrt(1/10));
                   [ The first 100 lines of the output have been removed ]
       cause this generated code and its skeleton and the resulting Sollya
       output files to be licensed under the CeCILL-C licence without this
       special exception.
       
       This special exception was added by the Sollya copyright holders in
       version 4.1 of Sollya.
       
   */
   
   
   #include <mpfr.h>
   
   void
   const_something (mpfr_ptr y, mp_prec_t prec)
   {
     /* Declarations */
     mpfr_t tmp1;
     mpfr_t tmp2;
     mpfr_t tmp3;
     mpfr_t tmp4;
     mpfr_t tmp5;
     mpfr_t tmp6;
     mpfr_t tmp7;
   
     /* Initializations */
     mpfr_init2 (tmp2, prec+5);
     mpfr_init2 (tmp1, prec+3);
     mpfr_init2 (tmp4, prec+8);
     mpfr_init2 (tmp3, prec+7);
     mpfr_init2 (tmp6, prec+11);
     mpfr_init2 (tmp7, prec+11);
     mpfr_init2 (tmp5, prec+11);
   
     /* Core */
     mpfr_set_prec (tmp2, prec+4);
     mpfr_set_ui (tmp2, 1, MPFR_RNDN);
     mpfr_set_prec (tmp1, prec+3);
     mpfr_exp (tmp1, tmp2, MPFR_RNDN);
     mpfr_set_prec (tmp4, prec+8);
     mpfr_set_ui (tmp4, 2, MPFR_RNDN);
     mpfr_set_prec (tmp3, prec+7);
     mpfr_log (tmp3, tmp4, MPFR_RNDN);
     mpfr_set_prec (tmp6, prec+11);
     mpfr_set_ui (tmp6, 1, MPFR_RNDN);
     mpfr_set_prec (tmp7, prec+11);
     mpfr_set_ui (tmp7, 10, MPFR_RNDN);
     mpfr_set_prec (tmp5, prec+11);
     mpfr_div (tmp5, tmp6, tmp7, MPFR_RNDN);
     mpfr_set_prec (tmp4, prec+7);
     mpfr_sqrt (tmp4, tmp5, MPFR_RNDN);
     mpfr_set_prec (tmp2, prec+5);
     mpfr_div (tmp2, tmp3, tmp4, MPFR_RNDN);
     mpfr_set_prec (y, prec+3);
     mpfr_add (y, tmp1, tmp2, MPFR_RNDN);
   
     /* Cleaning stuff */
     mpfr_clear(tmp1);
     mpfr_clear(tmp2);
     mpfr_clear(tmp3);
     mpfr_clear(tmp4);
     mpfr_clear(tmp5);
     mpfr_clear(tmp6);
     mpfr_clear(tmp7);
   }

Example 2:

   > implementconstant(sin(13/17),"sine_of_thirteen_seventeenth.c");
   > bashevaluate("tail -n 30 sine_of_thirteen_seventeenth.c");
   #include <mpfr.h>
   
   void
   const_something (mpfr_ptr y, mp_prec_t prec)
   {
     /* Declarations */
     mpfr_t tmp1;
     mpfr_t tmp2;
     mpfr_t tmp3;
   
     /* Initializations */
     mpfr_init2 (tmp2, prec+6);
     mpfr_init2 (tmp3, prec+6);
     mpfr_init2 (tmp1, prec+6);
   
     /* Core */
     mpfr_set_prec (tmp2, prec+6);
     mpfr_set_ui (tmp2, 13, MPFR_RNDN);
     mpfr_set_prec (tmp3, prec+6);
     mpfr_set_ui (tmp3, 17, MPFR_RNDN);
     mpfr_set_prec (tmp1, prec+6);
     mpfr_div (tmp1, tmp2, tmp3, MPFR_RNDN);
     mpfr_set_prec (y, prec+2);
     mpfr_sin (y, tmp1, MPFR_RNDN);
   
     /* Cleaning stuff */
     mpfr_clear(tmp1);
     mpfr_clear(tmp2);
     mpfr_clear(tmp3);
   }

Example 3:

   > implementconstant(asin(1/3 * pi),default,"arcsin_of_one_third_pi");
                   [ The first 100 lines of the output have been removed ]
       cause this generated code and its skeleton and the resulting Sollya
       output files to be licensed under the CeCILL-C licence without this
       special exception.
       
       This special exception was added by the Sollya copyright holders in
       version 4.1 of Sollya.
       
   */
   
   
   #include <mpfr.h>
   
   void
   arcsin_of_one_third_pi (mpfr_ptr y, mp_prec_t prec)
   {
     /* Declarations */
     mpfr_t tmp1;
     mpfr_t tmp2;
     mpfr_t tmp3;
   
     /* Initializations */
     mpfr_init2 (tmp2, prec+8);
     mpfr_init2 (tmp3, prec+8);
     mpfr_init2 (tmp1, prec+8);
   
     /* Core */
     mpfr_set_prec (tmp2, prec+8);
     mpfr_const_pi (tmp2, MPFR_RNDN);
     mpfr_set_prec (tmp3, prec+8);
     mpfr_set_ui (tmp3, 3, MPFR_RNDN);
     mpfr_set_prec (tmp1, prec+8);
     mpfr_div (tmp1, tmp2, tmp3, MPFR_RNDN);
     mpfr_set_prec (y, prec+2);
     mpfr_asin (y, tmp1, MPFR_RNDN);
   
     /* Cleaning stuff */
     mpfr_clear(tmp1);
     mpfr_clear(tmp2);
     mpfr_clear(tmp3);
   }

Example 4:

   > implementconstant(ceil(log(19 + 1/3)),"constant_code.c","magic_constant");
   > bashevaluate("tail -n -9 constant_code.c");
   void
   magic_constant (mpfr_ptr y, mp_prec_t prec)
   {
     /* Initializations */
   
     /* Core */
     mpfr_set_prec (y, prec);
     mpfr_set_ui (y, 3, MPFR_RNDN);
   }

Example 5:

   > bashexecute("gcc -fPIC -Wall -c libraryconstantexample.c -I$HOME/.local/include");
   > bashexecute("gcc -shared -o libraryconstantexample libraryconstantexample.o -lgmp -lmpfr");
   > euler_gamma = libraryconstant("./libraryconstantexample");
   > implementconstant(euler_gamma^(1/3), "euler.c");
   > bashevaluate("tail -n -17 euler.c");
   void
   const_something (mpfr_ptr y, mp_prec_t prec)
   {
     /* Declarations */
     mpfr_t tmp1;
   
     /* Initializations */
     mpfr_init2 (tmp1, prec+1);
   
     /* Core */
     euler_gamma (tmp1, prec+1);
     mpfr_set_prec (y, prec+2);
     mpfr_root (y, tmp1, 3, MPFR_RNDN);
   
     /* Cleaning stuff */
     mpfr_clear(tmp1);
   }
See also: implementpoly, libraryconstant, library, function, bashevaluate
Go back to the list of commands