int main(void) {
  sollya_obj_t a;
  mpfi_t res;
  int s;

  mpfi_init2(res, 100);

  sollya_lib_init();
  sollya_lib_install_msg_callback(callback, NULL);

  a = SOLLYA_CONST(4);
  s = sollya_lib_get_interval_from_range(res, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to %w.\n\n", a, res);
  sollya_lib_clear_obj(a);


  /* Exact conversion */
  a = sollya_lib_parse_string("[1, 3]");
  s = sollya_lib_get_interval_from_range(res, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to %w.\n\n", a, res);
  sollya_lib_clear_obj(a);

  /* Another exact conversion */
  a = SOLLYA_CONST(100);
  sollya_lib_set_prec_and_print(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_powers();
  sollya_lib_set_display(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_parse_string("[exp(1), pi]");
  s = sollya_lib_get_interval_from_range(res, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to\n%w (should be [430728948929449700355022696705 * 2^(-97), 995610453248924340922087778489 * 2^(-98)]).\n\n", a, res);
  sollya_lib_clear_obj(a);


  /* Inexact conversion */
  a = SOLLYA_CONST(165);
  sollya_lib_set_prec_and_print(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_decimal();
  sollya_lib_set_display(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_parse_string("[exp(1), pi]");
  s = sollya_lib_get_interval_from_range(res, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to\n%w (the first one should be enclosed in the second one).\n\n", a, res);
  sollya_lib_clear_obj(a);


  mpfi_clear(res);
  sollya_lib_close();
  return 0;
}
Exemple #2
0
int main(void) {
  sollya_obj_t a[8];
  int r[5];
  int i;

  sollya_lib_init();

  for (i=0;i<8;i++) a[i] = NULL;
  for (i=0;i<5;i++) r[i] = 0;

  a[0] = sollya_lib_parse_string("{ .a = 5; .b = exp(_x_); .c = { .d = 17; .e = sin(_x_) }}");
  a[1] = SOLLYA_EXP(SOLLYA_ASIN(SOLLYA_X_));
  a[2] = SOLLYA_LOG(SOLLYA_ATAN(SOLLYA_X_));
  r[0] = sollya_lib_create_structure(&(a[3]), NULL, "u", a[1]);
  sollya_lib_printf("Adding element \"%s\" with content %b to an empty thing: %s, yielding %b\n","u",a[1],(r[0]?"Success":"Failure"),a[3]);
  r[1] = sollya_lib_create_structure(&(a[4]), a[3], "v", a[2]);
  sollya_lib_printf("Adding element \"%s\" with content %b to %b: %s, yielding %b\n","v",a[2],a[3],(r[1]?"Success":"Failure"),a[4]);
  r[2] = sollya_lib_create_structure(&(a[5]), a[0], "v", a[3]);
  sollya_lib_printf("Adding element \"%s\" with content %b to %b: %s, yielding %b\n","v",a[3],a[0],(r[2]?"Success":"Failure"),a[5]);
  r[3] = sollya_lib_create_structure(&(a[6]), a[1], "v", a[3]);
  sollya_lib_printf("Adding element \"%s\" with content %b to %b: %s, yielding %b\n","v",a[3],a[1],(r[3]?"Success":"Failure"),a[6]);
  r[4] = sollya_lib_create_structure(&(a[7]), a[4], "u", a[3]);
  sollya_lib_printf("Adding element \"%s\" with content %b to %b: %s, yielding %b\n","u",a[3],a[4],(r[4]?"Success":"Failure"),a[7]);

  for (i=0;i<8;i++) 
    if (a[i] != NULL) sollya_lib_clear_obj(a[i]);

  sollya_lib_close();
  return 0;
}
Exemple #3
0
int main(void) {
  sollya_obj_t a[A_DIM], b[A_DIM];
  int i;

  sollya_lib_init();
  sollya_lib_install_msg_callback(callback, NULL);

  a[0] = SOLLYA_CONST(17.0);
  a[1] = SOLLYA_EXP(SOLLYA_ADD(SOLLYA_SIN(SOLLYA_X_), SOLLYA_X_));
  a[2] = sollya_lib_parse_string("(x + 1)^7");
  a[3] = SOLLYA_SIN(SOLLYA_MUL(SOLLYA_CONST(17.0),SOLLYA_X_));
  a[4] = SOLLYA_X_;
  a[5] = SOLLYA_ADD(SOLLYA_EXP(SOLLYA_X_),SOLLYA_ATAN(SOLLYA_X_));
  a[6] = SOLLYA_SUB(SOLLYA_EXP(SOLLYA_X_),SOLLYA_ATAN(SOLLYA_X_));
  a[7] = SOLLYA_MUL(SOLLYA_EXP(SOLLYA_X_),SOLLYA_ATAN(SOLLYA_X_));
  a[8] = SOLLYA_DIV(SOLLYA_EXP(SOLLYA_X_),SOLLYA_ATAN(SOLLYA_X_));
  a[9] = SOLLYA_SQRT(SOLLYA_X_);
  a[10] = SOLLYA_EXP(SOLLYA_X_);
  a[11] = SOLLYA_LOG(SOLLYA_X_);
  a[12] = SOLLYA_LOG2(SOLLYA_X_);
  a[13] = SOLLYA_LOG10(SOLLYA_X_);
  a[14] = SOLLYA_SIN(SOLLYA_X_);
  a[15] = SOLLYA_COS(SOLLYA_X_);
  a[16] = SOLLYA_TAN(SOLLYA_X_);
  a[17] = SOLLYA_ASIN(SOLLYA_X_);
  a[18] = SOLLYA_ACOS(SOLLYA_X_);
  a[19] = SOLLYA_ATAN(SOLLYA_X_);
  a[20] = SOLLYA_POW(SOLLYA_EXP(SOLLYA_X_),SOLLYA_ATAN(SOLLYA_X_));
  a[21] = SOLLYA_NEG(SOLLYA_X_);
  a[22] = SOLLYA_ABS(SOLLYA_X_);
  a[23] = SOLLYA_ERF(SOLLYA_X_);
  a[24] = SOLLYA_ERFC(SOLLYA_X_);
  a[25] = SOLLYA_LOG1P(SOLLYA_X_);
  a[26] = SOLLYA_EXPM1(SOLLYA_X_);
  a[27] = SOLLYA_SINH(SOLLYA_X_);
  a[28] = SOLLYA_COSH(SOLLYA_X_);
  a[29] = SOLLYA_TANH(SOLLYA_X_);
  a[30] = SOLLYA_ASINH(SOLLYA_X_);
  a[31] = SOLLYA_ACOSH(SOLLYA_X_);
  a[32] = SOLLYA_ATANH(SOLLYA_X_);
  a[33] = SOLLYA_PI;

  for (i=0;i<A_DIM;i++) {
      b[i] = sollya_lib_diff(a[i]);
      sollya_lib_printf("The derivative of %b is %b\n",a[i],b[i]);
  }

  for (i=0;i<A_DIM;i++) {
    sollya_lib_clear_obj(a[i]);
  }

  for (i=0;i<A_DIM;i++) {
    sollya_lib_clear_obj(b[i]);
  }

  sollya_lib_close();
  return 0;
}
Exemple #4
0
int main(void) {
  sollya_obj_t a[8], b[5], c[8 * 5];
  int i, j;

  sollya_lib_init();

  a[0] = SOLLYA_ADD(SOLLYA_X_, SOLLYA_ADD(SOLLYA_CONST(1.0),SOLLYA_POW(SOLLYA_X_,SOLLYA_CONST(2.0))));
  a[1] = SOLLYA_ADD(SOLLYA_MUL(SOLLYA_ADD(SOLLYA_MUL(SOLLYA_CONST(5.0),SOLLYA_X_),SOLLYA_CONST(7.0)),SOLLYA_X_),SOLLYA_CONST(9.0));
  a[2] = SOLLYA_ADD(SOLLYA_ADD(SOLLYA_X_, SOLLYA_ADD(SOLLYA_CONST(1.0),SOLLYA_POW(SOLLYA_X_,SOLLYA_CONST(2.0)))),
		    SOLLYA_ADD(SOLLYA_MUL(SOLLYA_ADD(SOLLYA_MUL(SOLLYA_CONST(5.0),SOLLYA_X_),SOLLYA_CONST(7.0)),SOLLYA_X_),SOLLYA_CONST(9.0)));
  a[3] = SOLLYA_ADD(SOLLYA_X_, SOLLYA_ADD(SOLLYA_EXP(SOLLYA_CONST(1.0)),SOLLYA_POW(SOLLYA_X_,SOLLYA_CONST(2.0))));
  a[4] = SOLLYA_ADD(SOLLYA_MUL(SOLLYA_ADD(SOLLYA_MUL(SOLLYA_LOG(SOLLYA_CONST(5.0)),SOLLYA_X_),SOLLYA_ATAN(SOLLYA_CONST(7.0))),SOLLYA_X_),SOLLYA_ERFC(SOLLYA_CONST(9.0)));
  a[5] = SOLLYA_ADD(SOLLYA_ADD(SOLLYA_X_, SOLLYA_ADD(SOLLYA_EXP(SOLLYA_CONST(1.0)),SOLLYA_POW(SOLLYA_X_,SOLLYA_CONST(2.0)))),
		    SOLLYA_ADD(SOLLYA_MUL(SOLLYA_ADD(SOLLYA_MUL(SOLLYA_LOG(SOLLYA_CONST(5.0)),SOLLYA_X_),SOLLYA_ATAN(SOLLYA_CONST(7.0))),SOLLYA_X_),SOLLYA_ERFC(SOLLYA_CONST(9.0))));
  a[6] = SOLLYA_EXP(SOLLYA_X_);
  a[7] = SOLLYA_POW(SOLLYA_ADD(SOLLYA_X_,SOLLYA_CONST(1.0)),SOLLYA_CONST(15));

  b[0] = sollya_lib_parse_string("[|1|]");
  b[1] = sollya_lib_parse_string("[|1,3,5|]");
  b[2] = sollya_lib_parse_string("[|0,2,7,11...|]");
  b[3] = sollya_lib_parse_string("[|1,3,5,17|]");
  b[4] = sollya_lib_parse_string("[|0...|]");

  for (i=0;i<8;i++) {
    for (j=0;j<5;j++) {
      c[i * 5 + j] = sollya_lib_subpoly(a[i],b[j]);
      sollya_lib_printf("The subpolynomial with monomials %b taken out of %b is %b\n",b[j],a[i],c[i * 5 + j]);
    }
  }

  for (i=0;i<8;i++) {
    sollya_lib_clear_obj(a[i]);
  }

  for (i=0;i<5;i++) {
    sollya_lib_clear_obj(b[i]);
  }
  
  for (i=0;i<8*5;i++) {
    sollya_lib_clear_obj(c[i]);
  }

  sollya_lib_close();
  return 0;
}
int main(void) {
  sollya_obj_t a[51];
  int t[51];
  int i;

  sollya_lib_init();

  a[0] = sollya_lib_absolute();
  a[1] = sollya_lib_binary();
  a[2] = sollya_lib_decimal();
  a[3] = sollya_lib_default();
  a[4] = sollya_lib_dyadic();
  a[5] = sollya_lib_error();
  a[6] = sollya_lib_false();
  a[7] = sollya_lib_file();
  a[8] = sollya_lib_fixed();
  a[9] = sollya_lib_floating();
  a[10] = sollya_lib_hexadecimal();
  a[11] = sollya_lib_honorcoeffprec();
  a[12] = sollya_lib_off();
  a[13] = sollya_lib_on();
  a[14] = sollya_lib_perturb();
  a[15] = sollya_lib_pi();
  a[16] = sollya_lib_postscript();
  a[17] = sollya_lib_postscriptfile();
  a[18] = sollya_lib_powers();
  a[19] = sollya_lib_relative();
  a[20] = sollya_lib_true();
  a[21] = sollya_lib_void();
  a[22] = sollya_lib_constant_from_double(1.0);
  a[23] = sollya_lib_free_variable();
  a[24] = sollya_lib_string("triple_double_obj");
  a[25] = sollya_lib_string("");
  a[26] = sollya_lib_list(NULL, 0);
  a[27] = sollya_lib_list(a, 2);
  a[28] = sollya_lib_end_elliptic_list(a, 2);
  a[29] = sollya_lib_parse_string("[1, 2]");
  a[30] = sollya_lib_round_down();
  a[31] = sollya_lib_round_up();
  a[32] = sollya_lib_round_towards_zero();
  a[33] = sollya_lib_round_to_nearest();
  a[34] = sollya_lib_double_obj();
  a[35] = sollya_lib_build_function_double(sollya_lib_free_variable());
  a[36] = sollya_lib_single_obj();
  a[37] = sollya_lib_build_function_single(sollya_lib_free_variable());
  a[38] = sollya_lib_quad_obj();
  a[39] = sollya_lib_build_function_quad(sollya_lib_free_variable());
  a[40] = sollya_lib_halfprecision_obj();
  a[41] = sollya_lib_build_function_halfprecision(sollya_lib_free_variable());
  a[42] = sollya_lib_doubleextended_obj();
  a[43] = sollya_lib_build_function_doubleextended(sollya_lib_free_variable());
  a[44] = sollya_lib_double_double_obj();
  a[45] = sollya_lib_build_function_double_double(sollya_lib_free_variable());
  a[46] = sollya_lib_triple_double_obj();
  a[47] = sollya_lib_build_function_triple_double(sollya_lib_free_variable());
  a[48] = sollya_lib_build_function_cos(sollya_lib_constant_from_int(5));
  a[49] = sollya_lib_end_elliptic_list(NULL, 0);
  a[50] = sollya_lib_parse_string("{.a = 5; .b = exp(_x_)}");

  for(i=0;i<51;i++)  t[i] = sollya_lib_is_triple_double_obj(a[i]);

  if (t[0]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects absolute\n");
  if (t[1]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects binary\n");
  if (t[2]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects decimal\n");
  if (t[3]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects default\n");
  if (t[4]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects dyadic\n");
  if (t[5]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects error\n");
  if (t[6]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects false\n");
  if (t[7]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects file\n");
  if (t[8]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects fixed\n");
  if (t[9]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects floating\n");
  if (t[10]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects hexadecimal\n");
  if (t[11]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects honorcoeffprec\n");
  if (t[12]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects off\n");
  if (t[13]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects on\n");
  if (t[14]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects perturb\n");
  if (t[15]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects pi\n");
  if (t[16]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects postscript\n");
  if (t[17]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects postscriptfile\n");
  if (t[18]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects powers\n");
  if (t[19]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects relative\n");
  if (t[20]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects true\n");
  if (t[21]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects void\n");
  if (t[22]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects a constant\n");
  if (t[23]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects free_variable\n");
  if (t[24]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects the string \"triple_double_obj\"\n");
  if (t[25]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects the empty string.\n");
  if (t[26]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects the empty list.\n");
  if (t[27]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects a non empty list.\n");
  if (t[28]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects a non empty end-elliptic list.\n");
  if (t[29]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects a range.\n");
  if (t[30]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects RD.\n");
  if (t[31]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects RU.\n");
  if (t[32]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects RZ.\n");
  if (t[33]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects RN.\n");
  if (t[34]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects D as symbol.\n");
  if (t[35]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects D(_x_).\n");
  if (t[36]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects S as symbol.\n");
  if (t[37]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects S(_x_).\n");
  if (t[38]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects QD as symbol.\n");
  if (t[39]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects QD(_x_).\n");
  if (t[40]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects HP as symbol.\n");
  if (t[41]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects HP(_x_).\n");
  if (t[42]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects DE as symbol.\n");
  if (t[43]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects DE(_x_).\n");
  if (t[44]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects DD as symbol.\n");
  if (t[45]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects DD(_x_).\n");
  if (t[46]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects TD as symbol.\n");
  if (t[47]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects TD(_x_).\n");
  if (t[48]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects a constant expression.\n");
  if (t[49]) sollya_lib_printf("sollya_lib_is_triple_double_obj detects an empty end-elliptic list.\n");
  if (t[50]) sollya_lib_printf("sollya_lib_obj_is_structure detects structure { .a = 5; .b = exp(_x_)}.\n");

  for(i=0;i<51;i++) sollya_lib_clear_obj(a[i]);
  sollya_lib_close();
  return 0;
}
Exemple #6
0
int main(void) {
  sollya_obj_t a[A_DIM];
  int i;

  sollya_lib_init();
  sollya_lib_install_msg_callback(callback, NULL);

  /* checkinfnorm(sin(x),[0;1.75], 1); */
  for (i=0;i<A_DIM;i++) {
    a[i] = NULL;
  }
  
  a[0] = SOLLYA_SIN(SOLLYA_X_);
  a[1] = sollya_lib_parse_string("[0;1.75]");
  a[2] = SOLLYA_CONST(1.0);

  a[A_DIM-1] = sollya_lib_checkinfnorm(a[0],a[1],a[2]);
  
  sollya_lib_printf("checkinfnorm(%b, %b, %b) = %b - expecting true\n",a[0],a[1],a[2],a[A_DIM-1]);
  
  for (i=0;i<A_DIM;i++) {
    if (a[i] != NULL) sollya_lib_clear_obj(a[i]);
  }

  /* checkinfnorm(sin(x),[0;1.75], 1/2); */
  for (i=0;i<A_DIM;i++) {
    a[i] = NULL;
  }
  
  a[0] = SOLLYA_SIN(SOLLYA_X_);
  a[1] = sollya_lib_parse_string("[0;1.75]");
  a[2] = SOLLYA_CONST(0.5);

  a[A_DIM-1] = sollya_lib_checkinfnorm(a[0],a[1],a[2]);
  
  sollya_lib_printf("checkinfnorm(%b, %b, %b) = %b - expecting false\n",a[0],a[1],a[2],a[A_DIM-1]);
  
  for (i=0;i<A_DIM;i++) {
    if (a[i] != NULL) sollya_lib_clear_obj(a[i]);
  }

  /* checkinfnorm(sin(x),[0;20/39], 1/2);*/
  for (i=0;i<A_DIM;i++) {
    a[i] = NULL;
  }
  
  a[0] = SOLLYA_SIN(SOLLYA_X_);
  a[1] = sollya_lib_parse_string("[0;23983616612609688914111751100985157245635816089863b-165]");
  a[2] = SOLLYA_CONST(0.5);

  a[A_DIM-1] = sollya_lib_checkinfnorm(a[0],a[1],a[2]);
  
  sollya_lib_printf("checkinfnorm(%b, %b, %b) = %b - expecting true\n",a[0],a[1],a[2],a[A_DIM-1]);
  
  for (i=0;i<A_DIM;i++) {
    if (a[i] != NULL) sollya_lib_clear_obj(a[i]);
  }

  /* checkinfnorm(11692536319630510474283968587625525849426869787677b-163 + x * (23384922893552793741208186896732057180708286140565b-164 + x * (46692941277611593554424973690517694800554713844979b-166 + x * (3891678517537147456387754739468835779118224484425b-164 + x * (1024072943597638219514404758611859127188920401873b-164 + x * 26154763285557255659575812244171511366994513699585b-171)))) - exp(x),[-1;1], dirtyinfnorm(func, [-1;1])); */

  for (i=0;i<A_DIM;i++) {
    a[i] = NULL;
  }
  
  a[0] = sollya_lib_parse_string("11692536319630510474283968587625525849426869787677b-163 + _x_ * (23384922893552793741208186896732057180708286140565b-164 + _x_ * (46692941277611593554424973690517694800554713844979b-166 + _x_ * (3891678517537147456387754739468835779118224484425b-164 + _x_ * (1024072943597638219514404758611859127188920401873b-164 + _x_ * 26154763285557255659575812244171511366994513699585b-171)))) - exp(_x_)");
  a[1] = sollya_lib_parse_string("[-1;1]");
  a[2] = sollya_lib_dirtyinfnorm(a[0],a[1]);

  a[A_DIM-1] = sollya_lib_checkinfnorm(a[0],a[1],a[2]);
  
  sollya_lib_printf("checkinfnorm(%b, %b, %b) = %b - expecting false\n",a[0],a[1],a[2],a[A_DIM-1]);
  
  for (i=0;i<A_DIM;i++) {
    if (a[i] != NULL) sollya_lib_clear_obj(a[i]);
  }

  /* checkinfnorm(11692536319630510474283968587625525849426869787677b-163 + x * (23384922893552793741208186896732057180708286140565b-164 + x * (46692941277611593554424973690517694800554713844979b-166 + x * (3891678517537147456387754739468835779118224484425b-164 + x * (1024072943597638219514404758611859127188920401873b-164 + x * 26154763285557255659575812244171511366994513699585b-171)))) - exp(x),[-1;1], round(dirtyinfnorm(func, [-1;1])),25,RU); with modified diam = 1b-20 */

  for (i=0;i<A_DIM;i++) {
    a[i] = NULL;
  }
  
  a[0] = sollya_lib_parse_string("11692536319630510474283968587625525849426869787677b-163 + _x_ * (23384922893552793741208186896732057180708286140565b-164 + _x_ * (46692941277611593554424973690517694800554713844979b-166 + _x_ * (3891678517537147456387754739468835779118224484425b-164 + _x_ * (1024072943597638219514404758611859127188920401873b-164 + _x_ * 26154763285557255659575812244171511366994513699585b-171)))) - exp(_x_)");
  a[1] = sollya_lib_parse_string("[-1;1]");
  a[2] = sollya_lib_dirtyinfnorm(a[0],a[1]);
  a[3] = SOLLYA_CONST(25.0);
  a[4] = sollya_lib_round_up();
  a[5] = sollya_lib_round(a[2],a[3],a[4]);
  a[6] = sollya_lib_parse_string("1b-20");
  
  sollya_lib_set_diam(a[6]);

  a[A_DIM-1] = sollya_lib_checkinfnorm(a[0],a[1],a[5]);
  
  sollya_lib_printf("checkinfnorm(%b, %b, %b) = %b - expecting true\n",a[0],a[1],a[5],a[A_DIM-1]);
  
  for (i=0;i<A_DIM;i++) {
    if (a[i] != NULL) sollya_lib_clear_obj(a[i]);
  }

  sollya_lib_close();
  return 0;
}
Exemple #7
0
int main(void) {
  sollya_obj_t a, b, res;

  sollya_lib_init();
  sollya_lib_install_msg_callback(callback, NULL);

  a = SOLLYA_CONST(1);
  b = sollya_lib_parse_string("[1,2]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = SOLLYA_CONST(4);
  b = sollya_lib_parse_string("[1,2]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("17 + log2(13)/log2(9)");
  b = sollya_lib_parse_string("[18,19]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("17 + log2(13)/log2(9)");
  b = sollya_lib_parse_string("[1,2]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/3) - sqrt(3)/2");
  b = sollya_lib_parse_string("[1,2]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/3) - sqrt(3)/2");
  b = sollya_lib_parse_string("[0,2]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/3) - sqrt(3)/2");
  b = sollya_lib_parse_string("[-1,0]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/3) - sqrt(3)/2");
  b = sollya_lib_parse_string("[-1,1]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/6)");
  b = sollya_lib_parse_string("[1/2,1]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/6)");
  b = sollya_lib_parse_string("[0,1/2]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/6)");
  b = sollya_lib_parse_string("[0,1]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("sin(pi/6)");
  b = sollya_lib_parse_string("[1,2]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[1,2]");
  b = sollya_lib_parse_string("[3,4]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[2,3]");
  b = sollya_lib_parse_string("[1,4]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[1,3]");
  b = sollya_lib_parse_string("[2,4]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_string("e");
  b = sollya_lib_string("Hello");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = SOLLYA_CONST(1);
  b = sollya_lib_string("H1llo");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);


  /* Testing inclusion when NaN is a bound */
  a = sollya_lib_parse_string("[@NaN@,3]");
  b = sollya_lib_parse_string("[2,4]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[@NaN@,5]");
  b = sollya_lib_parse_string("[2,4]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[2,4]");
  b = sollya_lib_parse_string("[@NaN@,3]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[2,4]");
  b = sollya_lib_parse_string("[@NaN@,5]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[@NaN@,4]");
  b = sollya_lib_parse_string("[2, @NaN@]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  a = sollya_lib_parse_string("[@NaN@,4]");
  b = sollya_lib_parse_string("[@NaN@, 5]");
  res = sollya_lib_cmp_in(a, b);
  sollya_lib_printf("%b in %b returns %b\n", a, b, res);
  sollya_lib_clear_obj(a);
  sollya_lib_clear_obj(b);
  sollya_lib_clear_obj(res);

  sollya_lib_close();
  return 0;
}
Exemple #8
0
	void FixComplexKCM::init()
	{
		if(lsb_in>msb_in) 
		{
			throw string("FixComplexKCM: Error, lsbIn>msbIn");
		}

		// definition of the source file name, used for info and error reporting
		// using REPORT 
		srcFileName="FixComplexKCM";

		// definition of the name of the operator
		ostringstream name;
		name << "FixComplexKCM_" << vhdlize(msb_in) <<"_" << vhdlize(lsb_in) 
			<< "_" << vhdlize(lsb_out) << "_" << vhdlize(constant_re) << "_" <<
			vhdlize(constant_im) << "_" << ((signedInput) ? "" : "un") <<
			"signed" ;

		setName(name.str());
		
		// Copyright 
		setCopyrightString("3IF 2015 dev team (2015)");

		input_width = 1 + msb_in - lsb_in;
		
		// declaring inputs
		addInput ("ReIN" , input_width);
		addInput ("ImIN" , input_width);

		//Computing constants for testBench and in order to know constant width
		sollya_obj_t nodeIm, nodeRe;	
		nodeRe = sollya_lib_parse_string(constant_re.c_str());
		
		if(sollya_lib_obj_is_error(nodeRe))
		{
			ostringstream error;
			error << srcFileName <<" : Unable to parse string \""  <<
				constant_re << "\" as a numeric constant" << endl;
			throw error.str();
		}
		
		nodeIm = sollya_lib_parse_string(constant_im.c_str());
		if(sollya_lib_obj_is_error(nodeIm))
		{
			ostringstream error;
			error << srcFileName <<" : Unable to parse string \""  <<
				constant_im << "\" as a numeric constant" << endl;
			throw error.str();
		}

		mpfr_inits2(10000, mpfr_constant_re, mpfr_constant_im, NULL);

		sollya_lib_get_constant(mpfr_constant_re, nodeRe);
		sollya_lib_get_constant(mpfr_constant_im, nodeIm);

		constantReNeg = (mpfr_sgn(mpfr_constant_re) < 0);
		constantImNeg = (mpfr_sgn(mpfr_constant_im) < 0);

		mpfr_t log2C;
		mpfr_init2(log2C, 100); 
		
		//Constant real part width
		mpfr_log2(log2C, mpfr_constant_re, GMP_RNDN);
		constantReMsb = mpfr_get_si(log2C, GMP_RNDU);

		//Constant imaginary part width
		mpfr_log2(log2C, mpfr_constant_im, GMP_RNDN);
		constantImMsb = mpfr_get_si(log2C, GMP_RNDU);

		//Free
		mpfr_clear(log2C);

		int constantMaxMSB = max(constantReMsb, constantImMsb);	

		//Do we need an extra sign bit ?
		bool extraSignBitRe = !signedInput && (constantReNeg || !constantImNeg);
		bool extraSignBitIm = !signedInput && (constantReNeg || constantImNeg);

		int msbout_re, msbout_im; 
		msbout_re = msbout_im = msb_in + constantMaxMSB +1;
		if(extraSignBitRe)
		{
			msbout_re++;
		}
		if(extraSignBitIm)
		{
			msbout_im++;
		}
		
		outputre_width = msbout_re - lsb_out + 1;
		outputim_width = msbout_im - lsb_out + 1;

		if(outputre_width < 0 || outputim_width < 0)
		{
			THROWERROR("Computed msb will be lower than asked lsb."
					" Result would always be zero ");
		}

	}
Exemple #9
0
	CRFPConstMult::CRFPConstMult(Target* target, int wE_in, int wF_in, int wE_out, int wF_out, string _constant):
		FPConstMult(target, wE_in, wF_in, wE_out, wF_out), 
		constant (_constant) 
	{
#if 0
		sollya_obj_t node;
		mpfr_t mpR;
		mpz_t zz;

		srcFileName="CRFPConstMult";
		/* Convert the input string into a sollya evaluation tree */
		node = sollya_lib_parse_string(constant.c_str());	
		/* If  parse error throw an exception */
		if (sollya_lib_obj_is_error(node))
			{
				ostringstream error;
				error << srcFileName << ": Unable to parse string "<< constant << " as a numeric constant" <<endl;
				throw error.str();
			}

		mpfr_inits(mpR, NULL);
		sollya_lib_get_constant(mpR, node);


		if(verbose){
			double r;
			r = mpfr_get_d(mpR, GMP_RNDN);
			cout << "  Constant evaluates to " <<r <<endl; 
		}
		// compute the precision -- TODO with NWB

		cst_width =  2*wF_in+4;
		REPORT(0, "***** WARNING Taking constant with 2*wF_in+4 bits. Correct rounding is not yet guaranteed. This is being implemented." );


		REPORT(INFO, "Required significand precision to reach correct rounding is " << cst_width  ); 

		mpfr_set_prec(mpfrC, cst_width);
		sollya_lib_get_constant(mpR, node);

		// Now convert mpR into exponent + integral significand


		// sign
		cst_sgn = mpfr_sgn(mpR);
		if(cst_sgn<0)
			mpfr_neg(mpR, mpR, GMP_RNDN);

		// compute exponent and mantissa
		cst_exp_when_mantissa_1_2 = mpfr_get_exp(mpR) - 1; //mpfr_get_exp() assumes significand in [1/2,1)  
		cst_exp_when_mantissa_int = cst_exp_when_mantissa_1_2 - cst_width + 1; 
		mpfr_init2(mpfr_cst_sig, cst_width);
		mpfr_div_2si(mpfr_cst_sig, mpR, cst_exp_when_mantissa_1_2, GMP_RNDN);
		REPORT(INFO, "mpfr_cst_sig  = " << mpfr_get_d(mpfr_cst_sig, GMP_RNDN));


		// Build the corresponding FPConstMult.

	
		// initialize mpfr_xcut_sig = 2/cst_sig, will be between 1 and 2
		mpfr_init2(mpfr_xcut_sig, 32*(cst_width+wE_in+wE_out)); // should be accurate enough
		mpfr_set_d(mpfr_xcut_sig, 2.0, GMP_RNDN);               // exaxt op
		mpfr_div(mpfr_xcut_sig, mpfr_xcut_sig, mpfr_cst_sig, GMP_RNDD);

		// now  round it down to wF_in+1 bits 
		mpfr_t xcut_wF;
		mpfr_init2(xcut_wF, wF_in+1);
		mpfr_set(xcut_wF, mpfr_xcut_sig, GMP_RNDD);
		mpfr_mul_2si(xcut_wF, xcut_wF, wF_in, GMP_RNDN);

		// It should now be an int; cast it into a mpz, then a mpz_class 
		mpz_init2(zz, wF_in+1);
		mpfr_get_z(zz, xcut_wF, GMP_RNDN);
		xcut_sig_rd = mpz_class(zz);
		mpz_clear(zz);

		REPORT(DETAILED, "mpfr_xcut_sig = " << mpfr_get_d(mpfr_xcut_sig, GMP_RNDN) );

		// Now build the mpz significand
		mpfr_mul_2si(mpfr_cst_sig,  mpfr_cst_sig, cst_width, GMP_RNDN);
   
		// It should now be an int; cast it into a mpz, then a mpz_class 
		mpz_init2(zz, cst_width);
		mpfr_get_z(zz, mpfr_cst_sig, GMP_RNDN);
		cst_sig = mpz_class(zz);
		mpz_clear(zz);
		REPORT(DETAILED, "mpzclass cst_sig = " << cst_sig);


		// build the name
		ostringstream name; 
		name <<"FPConstMult_"<<(cst_sgn==0?"":"M") <<cst_sig<<"b"
			  <<(cst_exp_when_mantissa_int<0?"M":"")<<abs(cst_exp_when_mantissa_int)
			  <<"_"<<wE_in<<"_"<<wF_in<<"_"<<wE_out<<"_"<<wF_out;
		uniqueName_=name.str();


		// cleaning up
		mpfr_clears(mpR, mpfr_xcut_sig, xcut_wF, mpfr_cst_sig, NULL);

		icm = new IntConstMult(target, wF_in+1, cst_sig);
		oplist.push_back(icm);

		buildVHDL();

#endif
	}
int main(void) {
  sollya_obj_t a;
  mpfr_t resleft, resright;
  int s;

  mpfr_init2(resleft, 100);
  mpfr_init2(resright, 120);

  sollya_lib_init();
  sollya_lib_install_msg_callback(callback, NULL);

  a = SOLLYA_CONST(4);
  s = sollya_lib_get_bounds_from_range(resleft, resright, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to\n[%v, %v].\n\n", a, resleft, resright);
  sollya_lib_clear_obj(a);


  /* Exact conversion */
  a = sollya_lib_parse_string("[1, 3]");
  s = sollya_lib_get_bounds_from_range(resleft, resright, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to\n[%v, %v] (should be the same).\n\n", a, resleft, resright);
  sollya_lib_clear_obj(a);

  /* Another exact conversion */
  a = SOLLYA_CONST(100);
  sollya_lib_set_prec_and_print(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_powers();
  sollya_lib_set_display(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_parse_string("[exp(1), pi]");
  s = sollya_lib_get_bounds_from_range(resleft, resright, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to\n[%v, %v] (should be [430728948929449700355022696705 * 2^(-97), 995610453248924340922087778489 * 2^(-98)]).\n\n", a, resleft, resright);
  sollya_lib_clear_obj(a);

  /* Inexact conversion at one side only */
  a = SOLLYA_CONST(110);
  sollya_lib_set_prec_and_print(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_decimal();
  sollya_lib_set_display(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_parse_string("[exp(1), pi]");
  s = sollya_lib_get_bounds_from_range(resleft, resright, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to\n[%v, %v] (left bound of the second one should be smaller than left bound of the first one. Right bounds should be equal .\n\n", a, resleft, resright);
  sollya_lib_clear_obj(a);


  /* Inexact conversion */
  a = SOLLYA_CONST(165);
  sollya_lib_set_prec_and_print(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_decimal();
  sollya_lib_set_display(a);
  sollya_lib_clear_obj(a);
  a = sollya_lib_parse_string("[exp(1), pi]");
  s = sollya_lib_get_bounds_from_range(resleft, resright, a);
  if (s==0) sollya_lib_printf("%b is not a range\n\n", a);
  else sollya_lib_printf("%b has been converted to\n[%v, %v] (the first one should be enclosed in the second one).\n\n", a, resleft, resright);
  sollya_lib_clear_obj(a);


  mpfr_clear(resleft);
  mpfr_clear(resright);
  sollya_lib_close();
  return 0;
}
int main(void) {
  sollya_obj_t a, prec;
  mpz_t res;
  int i;

  sollya_lib_init();
  mpz_init(res);

  prec = SOLLYA_CONST(20);
  sollya_lib_set_prec_and_print(prec);
  sollya_lib_clear_obj(prec);

  /* something that is obviously not a constant */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("[1;2]");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf("\n\n");
  }
  sollya_lib_clear_obj(a);


  /* something that could be interpreted as constant but that is not a */
  /* constant, strictly speaking */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("[1;1]");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf("\n\n");
  }
  sollya_lib_clear_obj(a);


  /* something that is constant, but it is not obvious */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("3*cos(2*x)/(2*sin(x)*cos(x))");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf("\n\n");
  }
  sollya_lib_clear_obj(a);


  /* An obvious constant */
  mpz_set_ui(res, 17);
  a = SOLLYA_CONST(3);
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting 3)\n\n");
  }
  sollya_lib_clear_obj(a);

  /* A constant, but that does not fit on 20 bits */
  mpz_set_ui(res, 17);
  a = SOLLYA_CONST(1073741824);
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting 1073741824)\n\n");
  }
  sollya_lib_clear_obj(a);

  /* A negative constant */
  mpz_set_ui(res, 17);
  a = SOLLYA_CONST(-3);
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting -3)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* A constant that does not fit in a integer */
  mpz_set_ui(res, 17);
  a = SOLLYA_CONST(1);
  for (i=1;i<=90;i++) a = SOLLYA_MUL(a, SOLLYA_CONST(2));
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expected 1237940039285380274899124224)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* The same, but negative */
  mpz_set_ui(res, 17);
  a = SOLLYA_CONST(-1);
  for (i=1;i<=90;i++) a = SOLLYA_MUL(a, SOLLYA_CONST(2));
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expected -1237940039285380274899124224)\n\n");
  }
  sollya_lib_clear_obj(a);



  /* A constant expression exactly representable as an int but it cannot be decided. */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("(1b200+1)-1b200*(log2(3)/log2(7) - log(3)/log(7) + 1)");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting 1)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* A constant expression very close to the middle between two integers
   and it cannot be decided. */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("1 + 1b-400 + 0.5*(log2(3)/log2(7) - log(3)/log(7) + 1)");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting either 1 or 2 -- 2 would be better)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* A constant expression very close to the middle between two doubles */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("1 + 1b-400 + 0.5");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting either 1 or 2 -- 2 would be better)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* A constant expression exactly at the middle between two doubles, but
     it cannot be decided. */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("1 - 0.5*(log2(3)/log2(7) - log(3)/log(7) + 1)");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting either 0 or 1 -- 0 would be better)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* The same constant but decidable */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("1 - 0.5");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting either 0 or 1 -- 0 would be better)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* Another constant expression exactly at the middle between two doubles, but
     it cannot be decided. */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("1 + 1.5*(log2(3)/log2(7) - log(3)/log(7) + 1)");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting either 2 or 3 -- 2 would be better)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* The same constant but decidable. */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("1 + 1.5");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting either 2 or 3 -- 2 would be better)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* A transcendantal constant. */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("exp(pi) + log(2)");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting either 23 or 24 -- 24 would be better)\n\n");
  }
  sollya_lib_clear_obj(a);


  /* A constant hard to evaluate because exactly zero but undecidable. */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("log10(2)/log10(3) - log(2)/log(3)");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting 0).\n\n");
  }
  sollya_lib_clear_obj(a);


  /* A constant very hard to evaluate (cf. tevaluate_function_at_constant_expression). */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("(sin((pi) / 3) - sqrt(3) / 2) * (1 * 2^(100000)) + 3");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to some number. Expecting that the above warning message states that faithtul evaluation is *NOT* possible.\n\n", a);
  }
  sollya_lib_clear_obj(a);



  /* Trying -inf */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("-@Inf@");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expected 0)\n\n");
  }
  sollya_lib_clear_obj(a);


/* Trying NaN */
  mpz_set_ui(res, 17);
  a = sollya_lib_parse_string("@NaN@");
  if (!sollya_lib_get_constant_as_mpz(res, a))
    sollya_lib_printf("%b is not a constant.\n\n", a);
  else {
    sollya_lib_printf("%b has been converted to ", a); gmp_printf("%Zd", res); sollya_lib_printf(" (expecting 0).\n\n");
  }
  sollya_lib_clear_obj(a);


  mpz_clear(res);
  sollya_lib_close();
  return 0;
}