Example #1
0
File: evalf.cpp Project: mulab/mU
var Evalf(Var x, size_t y)
{
	size_t z = mpf_get_default_prec();
	mpf_set_default_prec((uint)(LOG_2_10 * y));
	var r = Evalf(x);
	mpf_set_default_prec(z);
	if(FltQ(r)) mpf_set_prec(CFlt(r),(uint)(LOG_2_10 * y));
	return r;
}
Example #2
0
File: evalf.cpp Project: mulab/mU
var Evalf(Var x)
{
	switch(Type(x))
	{
	case TYPE(int):
		{
			var r = Flt();
			F::SetZ(r,x);
			return r;
		}
		break;
	case TYPE(rat):
		{
			var r = Flt();
			F::SetQ(r,x);
			return r;
		}
		break;
	case TYPE(flt):
		{
			var r = Flt();
			F::Set(r,x);
			mpf_set_prec(CFlt(r),mpf_get_default_prec());
			return r;
		}
		break;
	case TYPE(sym):
		{
			std::map<Var,attr_t>::const_iterator
				iter = Attributes.find(x);
			if(iter != Attributes.end() &&
				iter->second.count(Constant))
				return CProcs[x](0);
		}
		break;
	case TYPE(vec):
		{
			size_t n = Size(x);
			var r = Vec(n);
			for(size_t i = 0; i < n; ++i)
				At(r,i) = Evalf(At(x,i));
			return r;
		}
		break;
	case TYPE(ex):
		{
			var b = Evalf(Body(x));
			return Eval(Ex(Head(x),b));
		}
		break;
	}
	return x;
}
bool checkSelfConjugate(vec_mp test_point,
						BertiniRealConfig & program_options,
						boost::filesystem::path input_file)
{
	
	
	// setup input file
	int *declarations = NULL;
	partition_parse(&declarations, input_file, "func_input_real", "config_real",0); // the 0 means not self conjugate
	free(declarations);
	
	
	//check existence of the required witness_data file.
	FILE *IN = safe_fopen_read("witness_data");
	fclose(IN);
	
	
	
	
	//we put the point and its conjugate into the same member points file and run the membership test simultaneously with one bertini call.
	membership_test_input_file("input_membership_test", "func_input_real", "config_real",3);
	
	
	//setup  member_points file, including both the first witness point, and its complex-conjugate
	write_member_points_sc(test_point);//,fmt
	
	
	int blabla;
	parse_input_file("input_membership_test", &blabla);
	membershipMain(13423, blabla, 0, 1, 0);
	initMP(mpf_get_default_prec());
	
	
	std::vector<int> component_numbers = read_incidence_matrix();
	
	
	
	
	if (component_numbers[0]==component_numbers[1]) {
//		printf("component IS self conjugate\n");
		return true;
	}
	else
	{
//		printf("component is NOT self conjugate\n");
		return false;
	}
	
	
}
Example #4
0
int main(int argc,char *argv[])
{
    mpf_t mpfVal,mpf1;
    unsigned long i;

    mpf_set_default_prec(9000);
    mpf_init_set_ui(mpf1,1);
    printf ("%ld\n",mpf_get_default_prec());

    for (i=997; i>=997; i--) {
        mpf_init(mpfVal);
        mpf_div_ui(mpfVal,mpf1,i);
        printf("%ld: ",i);
        (void) mpf_out_str(stdout,10,2000,mpfVal);

        mpf_clear(mpfVal);
    }
}
int get_incidence_number(vec_mp test_point,
						 BertiniRealConfig & program_options,
						 boost::filesystem::path input_file)
{
	

	
	// setup input file
	int *declarations = NULL;
	partition_parse(&declarations, input_file, "func_input_real", "config_real",0); // the 0 means not self conjugate
	free(declarations);
	
	
	//check existence of the required witness_data file.
	FILE *IN = NULL;
	IN = safe_fopen_read("witness_data"); fclose(IN);
	
	
	
	//only need to do this once.  we put the point and its conjugate into the same member points file and run the membership test simultaneously with one bertini call.
	membership_test_input_file("input_membership_test", "func_input_real", "config_real",3);
	
	//setup  member_points file, including both the first witness point, and its complex-conjugate
	write_member_points_singlept(test_point);
	
	
//	std::vector<std::string> command_line_options;
//	command_line_options.push_back("input_membership_test");
//	
	int blabla;
	parse_input_file("input_membership_test", &blabla);
	membershipMain(13423, blabla, 0, 1, 0);
	initMP(mpf_get_default_prec());
	
//	bertini_main_wrapper(command_line_options, 1, 0,0);
	
	
	std::vector<int> component_number = read_incidence_matrix();
	
	return component_number[0];
}
Example #6
0
TQString const KNumber::toTQString(int width, int prec) const
{
  TQString tmp_str;

  if (*this == Zero) // important to avoid infinite loops below
    return "0";
  switch (type()) {
  case IntegerType:
    if (width > 0) { //result needs to be cut-off
      bool tmp_bool = _fraction_input; // stupid work-around
      _fraction_input = false;
      tmp_str = (KNumber("1.0")*(*this)).toTQString(width, -1);
      _fraction_input = tmp_bool;
    } else
      tmp_str = TQString(_num->ascii());
    break;
  case FractionType:
    if (_float_output) {
      bool tmp_bool = _fraction_input; // stupid work-around
      _fraction_input = false;
      tmp_str = (KNumber("1.0")*(*this)).toTQString(width, -1);
      _fraction_input = tmp_bool;
    } else { // _float_output == false
      if(_splitoffinteger_output) {
	// split off integer part
	KNumber int_part = this->integerPart();
	if (int_part == Zero)
	  tmp_str = TQString(_num->ascii());
	else if (int_part < Zero)
	  tmp_str = int_part.toTQString() + " " + (int_part - *this)._num->ascii();
	else
	  tmp_str = int_part.toTQString() + " " + (*this - int_part)._num->ascii();
      } else
	tmp_str = TQString(_num->ascii());

      if (width > 0  &&  tmp_str.length() > width) {
	//result needs to be cut-off
	bool tmp_bool = _fraction_input; // stupid work-around
	_fraction_input = false;
	tmp_str = (KNumber("1.0")*(*this)).toTQString(width, -1);
	_fraction_input = tmp_bool;
      }
    }

    break;
  case FloatType:
    if (width > 0)
      tmp_str = TQString(_num->ascii(width));
    else
      // rough estimate for  maximal decimal precision (10^3 = 2^10)
      tmp_str = TQString(_num->ascii(3*mpf_get_default_prec()/10));
    break;
  default:
    return TQString(_num->ascii());
  }
  
  if (prec >= 0)
    return roundNumber(tmp_str, prec);
  else
    return tmp_str;
}
int check_issoln_sphere_mp(endgame_data_t *EG,
						   tracker_config_t *T,
						   void const *ED)
{
	sphere_eval_data_mp *BED = (sphere_eval_data_mp *)ED; // to avoid having to cast every time
	BED->SLP_memory.set_globals_to_this();
	int ii;
	
	for (ii = 0; ii < T->numVars; ii++)
	{
		if (!(mpfr_number_p(EG->PD_mp.point->coord[ii].r) && mpfr_number_p(EG->PD_mp.point->coord[ii].i)))
		{
			printf("got not a number\n");
			print_point_to_screen_matlab(EG->PD_mp.point,"bad solution");
			return 0;
		}
	}
	
	
	mpf_t n1, n2, zero_thresh, max_rat;
	mpf_init(n1); mpf_init(n2); mpf_init(zero_thresh); mpf_init(max_rat);
	
	mpf_set_d(max_rat, MAX(T->ratioTol,0.99999));
	
	point_mp f; init_point_mp(f, 1);f->size = 1;
	eval_struct_mp e; init_eval_struct_mp(e, 0, 0, 0);
	
	
	int num_digits = prec_to_digits((int) mpf_get_default_prec());
	// setup threshold based on given threshold and precision
	if (num_digits > 300)
		num_digits = 300;
	num_digits -= 4;
	double my_guarantor = MAX(T->funcResTol, 1e-8);
	double tol = MAX(my_guarantor, pow(10,-num_digits));
	mpf_set_d(zero_thresh, tol);
	
	//this one guaranteed by entry condition
	//	sphere_eval_mp(e.funcVals, e.parVals, e.parDer, e.Jv, e.Jp, EG->PD_mp.point, EG->PD_mp.time, ED);
	evalProg_mp(e.funcVals, e.parVals, e.parDer, e.Jv, e.Jp, EG->PD_mp.point, EG->PD_mp.time, BED->SLP);
	//	print_point_to_screen_matlab(e.funcVals,"howfaroff");
	
	if (EG->last_approx_prec < 64)
	{ // copy to _mp
		vec_mp temp_vec;  init_vec_mp(temp_vec,0);
		point_d_to_mp(temp_vec, EG->last_approx_d);
		evalProg_mp(f, e.parVals, e.parDer, e.Jv, e.Jp, temp_vec, EG->PD_mp.time, BED->SLP);
		clear_vec_mp(temp_vec);
	}
	else
	{
		evalProg_mp(f, e.parVals, e.parDer, e.Jv, e.Jp, EG->last_approx_mp, EG->PD_mp.time, BED->SLP);
	}
	
	// compare the function values
	int isSoln = 1;
	for (ii = 0; ii < BED->SLP->numFuncs && isSoln; ii++)
	{
		mpf_abs_mp(n1, &e.funcVals->coord[ii]);
		mpf_abs_mp(n2, &f->coord[ii]);
		
		if ( (mpf_cmp(zero_thresh, n1) <= 0) &&  (mpf_cmp(n1, n2) <= 0) )
		{ // compare ratio
			mpf_mul(n2, max_rat, n2);
			if (mpf_cmp(n1, n2) > 0){
				isSoln = 0;
				printf("labeled as non_soln due to max_rat (mp) 1\n");
			}
		}
		else if ( (mpf_cmp(zero_thresh, n2) <= 0) &&  (mpf_cmp(n2, n1) <= 0) )
		{ // compare ratio
			mpf_mul(n1, max_rat, n1);
			if (mpf_cmp(n2, n1) > 0){
				isSoln = 0;
				printf("labeled as non_soln due to max_rat (mp) 2\n");
			}
		}
	}
	
	
	
	if (!isSoln) {
		
		print_point_to_screen_matlab(e.funcVals,"terminal_func_vals");
		printf("tol was %le\nmax_rat was ",tol);
		mpf_out_str(NULL,10,15,max_rat);
		std::cout << "\n";
	}
	
	
	
	mpf_clear(n1); mpf_clear(n2); mpf_clear(zero_thresh); mpf_clear(max_rat);
	
	
	clear_eval_struct_mp(e);
	clear_vec_mp(f);
	
	BED->SLP_memory.set_globals_null();
	return isSoln;
	
}