Example #1
0
	void init()
	{
		T_ = NULL;
		
		same_point_tolerance_ = 1e-5;
		num_projections_ = 0;
		projections_ = NULL;
		curr_projection_ = -1;
		
		curr_input_index_ = -2;
		
		this->num_vertices_ = 0;
		this->num_natural_variables_ = 0;
		
		init_vec_mp(checker_1_,0);
		init_vec_mp(checker_2_,0);
		
		
		
		init_mp(this->diff_);

		mpf_init(abs_);
		mpf_init(zerothresh_);
		mpf_set_d(zerothresh_, 1e-8);
	}
Example #2
0
	/**
	 \brief add a projection to the solver.
	 \param proj the new projection to add.
	 */
	void add_projection(vec_mp proj)
	{
		if (this->num_projections==0) {
			this->pi = (vec_mp *) br_malloc(sizeof(vec_mp));
		}
		else {
			this->pi = (vec_mp *) br_realloc(pi,(this->num_projections+1) *sizeof(vec_mp));
		}

		init_vec_mp(pi[num_projections],0);
		vec_cp_mp(pi[num_projections], proj);

		if (this->MPType==2){
			if (this->num_projections==0) {
				this->pi_full_prec = (vec_mp *) br_malloc(sizeof(vec_mp));
			}
			else {
				this->pi_full_prec = (vec_mp *) br_realloc(pi_full_prec,(this->num_projections+1) *sizeof(vec_mp));
			}

			init_vec_mp2(pi_full_prec[num_projections],0,1024);
			vec_cp_mp(pi_full_prec[num_projections], proj);
		}
		num_projections++;

	}
int write_member_points_singlept(vec_mp point_to_write)
{
	FILE *OUT = NULL;
	
	
	
	OUT = safe_fopen_write("member_points");
	
	
	vec_mp result;
	init_vec_mp(result,0);
	dehomogenize(&result,point_to_write);
	
	fprintf(OUT,"1\n\n");
	for(int ii=0; ii<result->size; ii++){
		print_mp(OUT,0,&result->coord[ii]);
		fprintf(OUT,"\n");
	}
	
	
	fclose(OUT);
	
	
	clear_vec_mp(result);
	
	return 0;
}
int write_member_points_sc(vec_mp point_to_write)
{
	FILE *OUT = NULL;
	int ii;
	
	
	remove("member_points");
	OUT = safe_fopen_write("member_points");
	
	
	vec_mp result;
	init_vec_mp(result,0);
	dehomogenize(&result,point_to_write);
	
	fprintf(OUT,"2\n\n");
	for(ii=0;ii<result->size;ii++)
	{
		print_mp(OUT,0,&result->coord[ii]);  fprintf(OUT,"\n");
	}
	
	
	comp_mp temp; init_mp(temp);
	fprintf(OUT,"\n");
	for(ii=0;ii<result->size;ii++)
	{
		conjugate_mp(temp, &result->coord[ii]);
		print_mp(OUT,0,temp);  fprintf(OUT,"\n");
	}
	fclose(OUT);
	
	clear_vec_mp(result);  clear_mp(temp);
	
	return 0;
}
Example #5
0
void WitnessSet::write_dehomogenized_coordinates(boost::filesystem::path filename) const
{

	
	vec_mp result; init_vec_mp(result,1);
	
	
	FILE *OUT = safe_fopen_write(filename.c_str()); // open the output file.
	
	fprintf(OUT,"%zu\n\n",num_points()); // print the header line
	for (unsigned int ii=0; ii<num_points(); ++ii) {
		if (this->num_synth_vars()>0) {
			dehomogenize(&result,point(ii), num_natty_vars_);
		}
		else{
			dehomogenize(&result,point(ii));
		}
		
		for (int jj=0; jj<num_natty_vars_-1; jj++) {
			print_mp(OUT, 0, &result->coord[jj]);
			fprintf(OUT, "\n");
		}
		fprintf(OUT,"\n");
	}
	
	fclose(OUT);
	
	clear_vec_mp(result);
	return;
}
	void copy(const multilintolin_eval_data_mp & other)
	{
		SolverMultiplePrecision::copy(other);
		
		
		if (this->num_linears==0) {
			current_linear = (vec_mp *) br_malloc(other.num_linears*sizeof(vec_mp));
			old_linear = (vec_mp *) br_malloc(other.num_linears*sizeof(vec_mp));
		}
		else
		{
			current_linear = (vec_mp *) br_realloc(current_linear, other.num_linears*sizeof(vec_mp));
			old_linear = (vec_mp *) br_realloc(old_linear, other.num_linears*sizeof(vec_mp));
		}
		
		for (int ii=0; ii<other.num_linears; ii++) {
			init_vec_mp(current_linear[ii],0);
			init_vec_mp(old_linear[ii],0);
			vec_cp_mp(current_linear[ii],other.current_linear[ii]);
			vec_cp_mp(old_linear[ii],other.old_linear[ii]);
		}
		
		
		
		if (this->MPType==2) {
			if (this->num_linears==0) {
				current_linear_full_prec = (vec_mp *) br_malloc(other.num_linears*sizeof(vec_mp));
				old_linear_full_prec = (vec_mp *) br_malloc(num_linears*sizeof(vec_mp));
			}
			else
			{
				current_linear_full_prec = (vec_mp *) br_realloc(current_linear_full_prec, other.num_linears*sizeof(vec_mp));
				old_linear_full_prec = (vec_mp *) br_realloc(old_linear_full_prec, other.num_linears*sizeof(vec_mp));
			}
			
			for (int ii=0; ii<other.num_linears; ii++) {
				init_vec_mp2(current_linear_full_prec[ii],0,1024);
				init_vec_mp2(old_linear_full_prec[ii],0,1024);
				vec_cp_mp(current_linear_full_prec[ii],other.current_linear_full_prec[ii]);
				vec_cp_mp(old_linear_full_prec[ii],other.old_linear_full_prec[ii]);
			}
		}
		
		this->num_linears= other.num_linears;
	} // re: copy
Example #7
0
void WitnessSet::print_to_screen() const
{
	
	vec_mp dehom;  init_vec_mp(dehom,1); dehom->size = 1;
	
	std::stringstream varname;
	
	std::cout << "witness set has " << num_vars_ << " total variables, " << num_natty_vars_ << " natural variables." << std::endl;
	
	
	std::cout << "dim " << dim_ << ", comp " << comp_num_ << std::endl;
	std::cout << "input file name " << input_filename_ << std::endl;

	
	printf("******\n%zu points\n******\n",num_points());
	std::cout << color::green();
	for (unsigned ii=0; ii<num_points(); ii++) {
		
		dehomogenize(&dehom, point(ii), num_natty_vars_);
		
		varname << "point_" << ii;
		
		print_point_to_screen_matlab(dehom,varname.str());
		varname.str("");
	}
	std::cout << color::console_default();
	
	std::cout << color::blue();
	printf("******\n%zu linears\n******\n",num_linears());
	
	for (unsigned ii=0; ii<num_linears(); ii++) {
		varname << "linear_" << ii;
		print_point_to_screen_matlab(linear(ii),varname.str());
		varname.str("");
	}
	std::cout << color::console_default();
	
	std::cout << color::cyan();
	printf("******\n%zu patches\n******\n",num_patches());
	
	for (unsigned ii=0; ii<num_patches(); ii++) {
		varname << "patch_" << ii;
		print_point_to_screen_matlab(patch(ii),varname.str());
		varname.str("");
	}
	std::cout << color::console_default();
	
	std::cout << "variable names:\n";
	for (unsigned ii=0; ii< num_var_names(); ii++) {
		std::cout << name(ii) << "\n";
	}
	printf("\n\n");
	
	
	clear_vec_mp(dehom);
}
void sphere_eval_data_mp::init()
{
	this->is_solution_checker_d = &check_issoln_sphere_d;
	this->is_solution_checker_mp = &check_issoln_sphere_mp;
	this->evaluator_function_d = &sphere_eval_d;
	this->evaluator_function_mp = &sphere_eval_mp;
	this->precision_changer = &change_sphere_eval_prec;
	this->dehomogenizer = &sphere_dehom;
	
	
	
	this->num_static_linears = 0; // we will copy these out of the witness set.
	static_linear = static_linear_full_prec = NULL;
	
	
	starting_linear = (vec_mp *) br_malloc(2*sizeof(vec_mp));;
	for (int ii=0; ii<2; ii++) {
		init_vec_mp(starting_linear[ii],0);
	}
	
	init_vec_mp(center, 0);
	init_mp(radius);
	
	if (MPType==2) {
		init_vec_mp2(center_full_prec,0,1024);
		init_mp2(radius_full_prec,1024);
		
		starting_linear_full_prec = (vec_mp *) br_malloc(2*sizeof(vec_mp));
		for (int ii=0; ii<2; ii++) {
			init_vec_mp2(starting_linear_full_prec[ii],0,1024);
		}
		
		init_mp2(two_full_prec,1024);
		set_zero_mp(two_full_prec);
		mpf_set_str(two_full_prec->r, "2.0", 10);
	}
	
	init_mp(two);
	set_zero_mp(two);
	mpf_set_str(two->r, "2.0", 10);
	
    num_natural_vars = 0;
}
Example #9
0
void WitnessSet::sort_for_real(tracker_config_t * T)
{
	

	
	
	int *real_indicator = new int[num_points()];
	int counter = 0;
	
	vec_mp result; init_vec_mp(result,num_natty_vars_-1);
	result->size = num_natty_vars_-1;
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		vec_mp & curr_point = point(ii);
		for (int jj=1; jj<num_natty_vars_; jj++) {
			div_mp(&result->coord[jj-1], &curr_point->coord[jj], &curr_point->coord[0]);
		}
		real_indicator[ii] = checkForReal_mp(result, T->real_threshold);
		
		if (real_indicator[ii]==1) {
			counter++;
		}
	}
	
	
	vec_mp *tempvec = (vec_mp *)br_malloc(counter * sizeof(vec_mp));
	
	counter = 0;  // reset
	for (unsigned int ii=0; ii<num_points(); ii++) {
		vec_mp & curr_point = point(ii);
		if (real_indicator[ii]==1) {
			
			init_vec_mp2(tempvec[counter],this->num_vars_,1024); tempvec[counter]->size = this->num_vars_;
			vec_cp_mp(tempvec[counter],curr_point);
			counter++;
		}
		else{
			
		}
	}
	
	clear_vec_mp(result);
	
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		clear_vec_mp(point(ii));
	}
	free(pts_mp_);
	
	pts_mp_ = tempvec;
	num_pts_ = counter;
	
	delete[] real_indicator;
	return;
}
Example #10
0
void WitnessSet::write_dehomogenized_coordinates(boost::filesystem::path filename,std::set<unsigned int> indices) const
{
	
	for (auto ii=indices.begin(); ii!=indices.end(); ++ii) {
		if (*ii >= this->num_points()) {
			std::cout << "requested to print out-of-range point index " << *ii << " to a dehomogenized file." << std::endl;
			std::cout << "[this WitnessSet contains " << num_points() << " points.]" << std::endl;
			br_exit(66190);
		}
	}
	
	
	
	
	vec_mp result; init_vec_mp(result,1);
	
	
	FILE *OUT = safe_fopen_write(filename.c_str()); // open the output file.
	
	fprintf(OUT,"%lu\n\n",indices.size()); // print the header line
	for (auto ii=indices.begin(); ii!=indices.end(); ++ii) {
		if (this->num_synth_vars()>0) {
			dehomogenize(&result,this->point(*ii), num_natty_vars_);
		}
		else{
			dehomogenize(&result,this->point(*ii));
		}
		
		for (int jj=0; jj<num_natty_vars_-1; jj++) {
			print_mp(OUT, 0, &result->coord[jj]);
			fprintf(OUT, "\n");
		}
		fprintf(OUT,"\n");
	}
	
	fclose(OUT);
	
	clear_vec_mp(result);
	return;
}
	void copy(const nullspacejac_eval_data_mp & other)
	{
		
		clear();
		reset_counters();
		
		
		
		
		if (other.num_additional_linears>0) {
			
			
			this->additional_linears_terminal						= (vec_mp *) br_malloc(other.num_additional_linears*sizeof(vec_mp));
			this->additional_linears_terminal_full_prec = (vec_mp *) br_malloc(other.num_additional_linears*sizeof(vec_mp));
			this->additional_linears_starting						= (vec_mp *) br_malloc(other.num_additional_linears*sizeof(vec_mp));
			this->additional_linears_starting_full_prec = (vec_mp *) br_malloc(other.num_additional_linears*sizeof(vec_mp));
			
			for (int ii=0; ii<other.num_additional_linears; ii++) {
				vec_cp_mp(this->additional_linears_terminal[ii],						other.additional_linears_terminal[ii]);
				vec_cp_mp(this->additional_linears_terminal_full_prec[ii],	other.additional_linears_terminal_full_prec[ii]);
				
				vec_cp_mp(this->additional_linears_starting[ii],						other.additional_linears_starting[ii]);
				vec_cp_mp(this->additional_linears_starting_full_prec[ii],	other.additional_linears_starting_full_prec[ii]);
			}
		}
		else {} // other.num_additional_linears == 0
		
		this->num_additional_linears = other.num_additional_linears;
		
		if (other.num_jac_equations) {
			this->starting_linears_full_prec = (vec_mp **) br_malloc(other.num_jac_equations*sizeof(vec_mp *));
			this->starting_linears = (vec_mp **) br_malloc(other.num_jac_equations*sizeof(vec_mp *));
			
			for (int ii=0; ii<other.num_jac_equations; ii++) {
				this->starting_linears_full_prec[ii] = (vec_mp *) br_malloc(other.max_degree*sizeof(vec_mp ));
				this->starting_linears[ii] = (vec_mp *) br_malloc(other.max_degree*sizeof(vec_mp ));
				for (int jj=0; jj<other.max_degree; jj++) {
					init_vec_mp(this->starting_linears[ii][jj],0);
					init_vec_mp2(this->starting_linears_full_prec[ii][jj],0,1024);
					vec_cp_mp(this->starting_linears[ii][jj],other.starting_linears[ii][jj]);
					vec_cp_mp(this->starting_linears_full_prec[ii][jj],other.starting_linears_full_prec[ii][jj]);
				}
			}
		}
		else{}
		
		
		
		this->num_jac_equations = other.num_jac_equations;
		this->max_degree = other.max_degree;
		
		
		if (other.num_v_linears) {
			this->v_linears = (vec_mp *) br_malloc(other.num_v_linears*sizeof(vec_mp));
			this->v_linears_full_prec = (vec_mp *) br_malloc(other.num_v_linears*sizeof(vec_mp));
			for (int ii=0; ii<num_v_linears; ii++) {
				init_vec_mp(this->v_linears[ii],0);
				init_vec_mp2(this->v_linears_full_prec[ii],0,1024);
				vec_cp_mp(this->v_linears[ii],other.v_linears[ii]);
				vec_cp_mp(this->v_linears_full_prec[ii],other.v_linears_full_prec[ii]);
			}
		}
		else{}
		
		vec_cp_mp(this->v_patch, other.v_patch);
		vec_cp_mp(this->v_patch_full_prec, other.v_patch_full_prec);
		
		mat_cp_mp(this->jac_with_proj, other.jac_with_proj);
		mat_cp_mp(this->jac_with_proj_full_prec, other.jac_with_proj_full_prec);
		

		
		
		
		
		if (other.num_projections>0) {
			this->target_projection = (vec_mp *) br_malloc(other.num_projections*sizeof(vec_mp));
			this->target_projection_full_prec = (vec_mp *) br_malloc(other.num_projections*sizeof(vec_mp));
			
			for (int ii=0; ii<num_projections; ii++) {
				init_vec_mp(this->target_projection[ii],0);
				init_vec_mp2(this->target_projection[ii],0,1024);
				vec_cp_mp(this->target_projection[ii],other.target_projection[ii]);
				vec_cp_mp(this->target_projection_full_prec[ii],other.target_projection_full_prec[ii]);
			}
		}
		else{}
		
		
		this->num_jac_equations = other.num_jac_equations;
		this->target_dim = other.target_dim;   // r			the dimension of the real set we are looking for
		this->ambient_dim = other.ambient_dim;  // k			the dimension of the complex component we are looking IN.
		this->target_crit_codim = other.target_crit_codim;    // \ell.  must be at least one (1), and at most target_dim (r).
		
		this->num_v_vars = other.num_v_vars;  // N   number of variables in original problem statement (including homogenizing variables)
		this->num_natural_vars = other.num_natural_vars;  // N-k+\ell
		this->num_synth_vars = other.num_synth_vars;
		
		this->max_degree = other.max_degree;						// the max degree of differentiated (randomized) functions
		
		
		this->num_projections = other.num_projections;
		this->num_v_linears = other.num_v_linears;
		this->num_additional_linears = other.num_additional_linears;
		
		
		
	} // re: copy
Example #12
0
void WitnessSet::sort_for_inside_sphere(comp_mp radius, vec_mp center)
{
	
	
	
	
	int num_good_pts = 0;
	
	
	std::vector<int> is_ok;
	
	vec_mp temp_vec; init_vec_mp(temp_vec,0);
	comp_mp temp; init_mp(temp);
	
	for (unsigned int ii = 0; ii<num_points(); ++ii) {
		
		
		
		dehomogenize(&temp_vec, point(ii),num_natty_vars_);
		temp_vec->size = center->size;
		
		norm_of_difference(temp->r, temp_vec, center);
		if ( mpf_cmp(temp->r, radius->r) < 0   ){
			is_ok.push_back(1);
			num_good_pts++;
		}
		else
		{
			is_ok.push_back(0);
		}
		
		
		
	}
	
	
	
	vec_mp *transferme = (vec_mp *)br_malloc(num_good_pts*sizeof(vec_mp));
	int counter = 0;
	for (unsigned int ii=0; ii<num_points(); ++ii) {
		if (is_ok[ii]==1) {
			init_vec_mp2(transferme[counter],0,1024);  transferme[counter]->size = 0;
			vec_cp_mp(transferme[counter], point(ii));
			counter++;
		}
	}
	
	if (counter!= num_good_pts) {
		printf("counter mismatch\n");
		br_exit(271);
	}
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		clear_vec_mp(point(ii));
	}
	free(pts_mp_);
	
	
	num_pts_ = num_good_pts;
	pts_mp_ = transferme;
	
	clear_vec_mp(temp_vec);
	clear_mp(temp);
	return;
}
int sphere_eval_data_mp::setup(SphereConfiguration & config,
							   const WitnessSet & W,
							   SolverConfiguration & solve_options)
{
	
	
	if (config.randomizer().use_count()==0) {
		std::cout << "don't have randomizer set up!" << std::endl;
		br_exit(-97621);
	}
	
	if (!config.have_mem) {
		std::cout << "don't have memory!" << std::endl;
		br_exit(-3231);
	}
	
	this->SLP_memory = config.SLP_memory;
	
	num_natural_vars = W.num_natural_variables();
	num_variables = W.num_variables();
	
	
	// set up the vectors to hold the linears.
	if (this->num_static_linears==0) {
		static_linear = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp));
	}
	else
	{
		static_linear = (vec_mp *) br_realloc(static_linear, W.num_linears()*sizeof(vec_mp));
	}
	
	for (unsigned int ii=0; ii<W.num_linears(); ii++) {
		init_vec_mp(static_linear[ii],0);
		vec_cp_mp(static_linear[ii],W.linear(ii));
	}
	
	
	
	set_mp(this->radius, config.radius);
	vec_cp_mp(this->center, config.center);
	if (this->center->size < W.num_variables()) {
        int old_size = this->center->size;
        increase_size_vec_mp(this->center, W.num_variables());
        this->center->size = W.num_variables();
        
        for (int ii=old_size; ii<W.num_variables(); ii++) {
            set_zero_mp(&this->center->coord[ii]);
        }
    }
    
    
	if (this->MPType==2) {
		
		set_mp(this->radius_full_prec, config.radius);
		vec_cp_mp(this->center_full_prec, config.center);
        if (this->center_full_prec->size < W.num_variables()) {
            int old_size = this->center_full_prec->size;
            increase_size_vec_mp(this->center_full_prec, W.num_variables());
            this->center_full_prec->size = W.num_variables();
            
            for (int ii=old_size; ii<W.num_variables(); ii++) {
                set_zero_mp(&this->center_full_prec->coord[ii]);
            }
        }
        
        
		
		if (this->num_static_linears==0) {
			static_linear_full_prec = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp));
		}
		else
		{
			static_linear_full_prec = (vec_mp *) br_realloc(static_linear_full_prec, W.num_linears()*sizeof(vec_mp));
		}
		
		for (unsigned int ii=0; ii<W.num_linears(); ii++) {
			init_vec_mp2(static_linear_full_prec[ii],0,1024);
			
			vec_cp_mp(static_linear_full_prec[ii], W.linear(ii));
		}
	}
	
	this->num_static_linears = W.num_linears();
	
	
	
	
	
	for (int ii=0; ii<2; ii++) {
		vec_cp_mp( this->starting_linear[ii], config.starting_linear[ii]);
		
		if (MPType==2) {
			vec_cp_mp(this->starting_linear_full_prec[ii], config.starting_linear[ii]);
		}
	}
	
	
	
	
	
	// the usual
	
	verbose_level(solve_options.verbose_level());
	
	SolverMultiplePrecision::setup(config.SLP, config.randomizer());
	
	generic_setup_patch(&patch,W);
	
	if (solve_options.use_gamma_trick==1)
		get_comp_rand_mp(this->gamma); // set gamma to be random complex value
	else{
		set_one_mp(this->gamma);
	}
	
	comp_d temp;
	if (this->MPType==2) {
		if (solve_options.use_gamma_trick==1){
			get_comp_rand_rat(temp, this->gamma, this->gamma_rat, 64, solve_options.T.AMP_max_prec, 0, 0);
		}
		else{
			set_one_mp(this->gamma);
			set_one_rat(this->gamma_rat);
		}
	}
	
	

	
	return 0;
}
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;
	
}
int sphere_eval_data_mp::receive(ParallelismConfig & mpi_config)
{
	
	int *buffer = new int[2];
	MPI_Bcast(buffer, 1, MPI_INT, mpi_config.head(), mpi_config.comm());
	
	if (buffer[0] != SPHERE_SOLVER) {
		std::cout << "worker failed to confirm it is receiving the SPHERE_SOLVER type eval data" << std::endl;
		mpi_config.abort(777);
	}
	
	SolverMultiplePrecision::receive(mpi_config);
	
	
	// now can actually receive the data from whoever.
	MPI_Bcast(buffer, 2, MPI_INT, mpi_config.head(), mpi_config.comm());
	
	num_natural_vars = buffer[0];
	num_static_linears = buffer[1];
	
	delete[] buffer;
	
	//starting linears already created and initted
	static_linear = (vec_mp *) br_malloc(num_static_linears*sizeof(vec_mp));
	
	if (this->MPType==2) {
		static_linear_full_prec = (vec_mp *) br_malloc(num_static_linears*sizeof(vec_mp));
		
		for (int ii=0; ii<num_static_linears; ii++) {
			
			init_vec_mp(static_linear[ii],1);
			init_vec_mp2(static_linear_full_prec[ii],1,1024);
			
			bcast_vec_mp(static_linear_full_prec[ii], mpi_config.id(), mpi_config.head());
			
			vec_cp_mp(static_linear[ii],static_linear_full_prec[ii]);
			
		}
		
		for (int ii=0; ii<2; ii++) {
			
			bcast_vec_mp(starting_linear_full_prec[ii], mpi_config.id(), mpi_config.head());
			
			vec_cp_mp(starting_linear[ii],starting_linear_full_prec[ii]);
		}
		
		bcast_vec_mp(center_full_prec, mpi_config.id(), mpi_config.head());
		
		bcast_comp_mp(radius_full_prec, mpi_config.id(), mpi_config.head());
		
		vec_cp_mp(center, center_full_prec);
		set_mp(radius, radius_full_prec);
	}
	else{ // MPType == 1
		for (int ii=0; ii<num_static_linears; ii++) {
			init_vec_mp(static_linear[ii],1);
			bcast_vec_mp(static_linear[ii], mpi_config.id(), mpi_config.head());
		}
		
		for (int ii=0; ii<2; ii++) {
			bcast_vec_mp(starting_linear[ii], mpi_config.id(), mpi_config.head());
		}
		
		bcast_vec_mp(center, mpi_config.id(), mpi_config.head());
		bcast_comp_mp(radius, mpi_config.id(), mpi_config.head());
	}
	
	
	return SUCCESSFUL;
	
}
//this derived from basic_eval_d
int sphere_eval_mp(point_mp funcVals, point_mp parVals, vec_mp parDer, mat_mp Jv, mat_mp Jp, point_mp current_variable_values, comp_mp pathVars, void const *ED)
{ // evaluates a special homotopy type, built for bertini_real
	
	//	print_comp_mp_matlab(pathVars,"pathvars");
	
	
	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, jj, mm; // counters
	int offset;
	comp_mp one_minus_s, gamma_s;
	comp_mp temp, temp2;
	comp_mp func_val_sphere, func_val_start;
	init_mp(one_minus_s);  init_mp(gamma_s);
	init_mp(temp);  init_mp(temp2);
	init_mp(func_val_start);
	init_mp(func_val_sphere);
	
	set_one_mp(one_minus_s);
	sub_mp(one_minus_s, one_minus_s, pathVars);  // one_minus_s = (1 - s)
	mul_mp(gamma_s, BED->gamma, pathVars);       // gamma_s = gamma * s
	
	
	vec_mp patchValues; init_vec_mp(patchValues, 0);
	vec_mp temp_function_values; init_vec_mp(temp_function_values,0);
	vec_mp AtimesF; init_vec_mp(AtimesF,BED->randomizer()->num_rand_funcs()); AtimesF->size = BED->randomizer()->num_rand_funcs();// declare  // initialize
	
	
	
	mat_mp temp_jacobian_functions; init_mat_mp(temp_jacobian_functions,BED->randomizer()->num_base_funcs(),BED->num_variables);
	temp_jacobian_functions->rows = BED->randomizer()->num_base_funcs(); temp_jacobian_functions->cols = BED->num_variables;
	mat_mp temp_jacobian_parameters; init_mat_mp(temp_jacobian_parameters,0,0);
	mat_mp Jv_Patch; init_mat_mp(Jv_Patch, 0, 0);
	mat_mp AtimesJ; init_mat_mp(AtimesJ,BED->randomizer()->num_rand_funcs(),BED->num_variables);
	AtimesJ->rows = BED->randomizer()->num_rand_funcs(); AtimesJ->cols = BED->num_variables;
	
	
	//set the sizes
	change_size_vec_mp(funcVals,BED->num_variables); funcVals->size = BED->num_variables;
	change_size_mat_mp(Jv, BED->num_variables, BED->num_variables); Jv->rows = Jv->cols = BED->num_variables; //  -> this should be square!!!
	
	for (ii=0; ii<BED->num_variables; ii++)
		for (jj=0; jj<BED->num_variables; jj++)
			set_zero_mp(&Jv->entry[ii][jj]);
	
	
	
	// evaluate the SLP to get the system's whatnot.
	evalProg_mp(temp_function_values, parVals, parDer, temp_jacobian_functions, temp_jacobian_parameters, current_variable_values, pathVars, BED->SLP);
	
	
	// evaluate the patch
	patch_eval_mp(patchValues, parVals, parDer, Jv_Patch, Jp, current_variable_values, pathVars, &BED->patch);  // Jp is ignored
	
	
	// we assume that the only parameter is s = t and setup parVals & parDer accordingly.
	// note that you can only really do this AFTER you are done calling other evaluators.
	// set parVals & parDer correctly
	
	// i.e. these must remain here, or below.  \/
	change_size_point_mp(parVals, 1);
	change_size_vec_mp(parDer, 1);
	change_size_mat_mp(Jp, BED->num_variables, 1); Jp->rows = BED->num_variables; Jp->cols = 1;
	for (ii=0; ii<BED->num_variables; ii++)
		set_zero_mp(&Jp->entry[ii][0]);
	
	
	parVals->size = parDer->size = 1;
	set_mp(&parVals->coord[0], pathVars); // s = t
	set_one_mp(&parDer->coord[0]);       // ds/dt = 1
	
	
	
	///////////////////////////
	//
	// the original (randomized) functions.
	//
	///////////////////////////////////
	
	BED->randomizer()->randomize(AtimesF,AtimesJ,temp_function_values,temp_jacobian_functions,&current_variable_values->coord[0]);
	
	
	for (ii=0; ii<AtimesF->size; ii++)  // for each function, after (real orthogonal) randomization
		set_mp(&funcVals->coord[ii], &AtimesF->coord[ii]);
	
	
	for (ii = 0; ii < BED->randomizer()->num_rand_funcs(); ii++)
		for (jj = 0; jj < BED->num_variables; jj++)
			set_mp(&Jv->entry[ii][jj],&AtimesJ->entry[ii][jj]);
	
	//Jp is 0 for the equations.
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	///////////////////
	//
	//  the sphere equation.
	//
	//////////////////////////
	
	offset = BED->randomizer()->num_rand_funcs();
	
	mul_mp(func_val_sphere, BED->radius, BED->radius);
	neg_mp(func_val_sphere, func_val_sphere);
	mul_mp(func_val_sphere, func_val_sphere, &current_variable_values->coord[0]);
	mul_mp(func_val_sphere, func_val_sphere, &current_variable_values->coord[0]);
	//f_sph = -r^2*h^2
	
	
	
	for (int ii=1; ii<BED->num_natural_vars; ii++) {
		mul_mp(temp2, &BED->center->coord[ii-1], &current_variable_values->coord[0]); // temp2 = c_{i-1}*h
		
		sub_mp(temp, &current_variable_values->coord[ii], temp2);  // temp = x_i - h*c_{i-1}
		mul_mp(temp2, temp, temp);                                 // temp2 = (x_i - h*c_{i-1})^2
		add_mp(func_val_sphere, func_val_sphere, temp2);           // f_sph += (x_i - h*c_{i-1})^2
	}
	
	
	
	set_one_mp(func_val_start);
	for (mm=0; mm<2; ++mm) {
		dot_product_mp(temp, BED->starting_linear[mm], current_variable_values);
		mul_mp(func_val_start, func_val_start, temp);
		//f_start *= L_i (x)
	}
	
	
	// combine the function values
	mul_mp(temp, one_minus_s, func_val_sphere);
	mul_mp(temp2, gamma_s, func_val_start);
	add_mp(&funcVals->coord[offset], temp, temp2);
	// f = (1-t) f_sph + gamma t f_start
	
	
	
	
	//// / / / / / /    now the derivatives wrt x
	
	//  first we store the derivatives of the target function, the sphere.  then we will add the part for the linear product start.
	
	
	
	//ddx for sphere
	
	
	
	for (int ii=1; ii<BED->num_natural_vars; ii++) {
		mul_mp(temp2, &BED->center->coord[ii-1], &current_variable_values->coord[0]); // temp2 = c_{i-1}*h
		sub_mp(temp, &current_variable_values->coord[ii], temp2) // temp = x_i - c_{i-1}*h
		mul_mp(&Jv->entry[offset][ii], BED->two, temp); // Jv = 2*(x_i - c_{i-1}*h)
		mul_mp(&Jv->entry[offset][ii], &Jv->entry[offset][ii], one_minus_s); // Jv = (1-t)*2*(x_i - c_{i-1}*h)
		
		
		mul_mp(temp2, &BED->center->coord[ii-1], temp);  // temp2 = c_{i-1} * ( x_i - c_{i-1} * h )
		add_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], temp2); // Jv[0] += c_{i-1} * ( x_i - c_{i-1} * h )
	}
	// multiply these entries by (1-t)
	
	
	// the homogenizing var deriv
	mul_mp(temp, &current_variable_values->coord[0], BED->radius);
	mul_mp(temp, temp, BED->radius);  // temp = r^2 h
	
	add_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], temp); // Jv[0] = \sum_{i=1}^n {c_{i-1} * ( x_i - c_{i-1} * h )} + r^2 h
	neg_mp(&Jv->entry[offset][0], &Jv->entry[offset][0]); // Jv[0] = -Jv[0]
	mul_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], BED->two);  // Jv[0] *= 2
	mul_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], one_minus_s);  // Jv[0] *= (1-t)
	
	// f = \sum{ ( x_i - c_{i-1} * h )^2 } - r^2 h^2
	//Jv = -2(1-t) (  \sum_{i=1}^n {  c_{i-1} * ( x_i - c_{i-1} * h )  } + r^2 h )
	
	
	// a hardcoded product rule for the two linears.
	for (int ii=0; ii<BED->num_variables; ii++) {
		
		dot_product_mp(temp, BED->starting_linear[0], current_variable_values);
		mul_mp(temp, temp, &BED->starting_linear[1]->coord[ii]);
		
		dot_product_mp(temp2, BED->starting_linear[1], current_variable_values);
		mul_mp(temp2, temp2, &BED->starting_linear[0]->coord[ii]);
		
		add_mp(temp, temp, temp2);
		mul_mp(temp2, temp, gamma_s);
		
		//temp2 = gamma s * (L_1(x) * L_0[ii] + L_0(x) * L_1[ii])
		
		//temp2 now has the value of the derivative of the start system wrt x_i
		
		add_mp(&Jv->entry[offset][ii], &Jv->entry[offset][ii], temp2);
	}
	
	
	
	// finally, the Jp entry for sphere equation's homotopy.
	//Jp = -f_sph + gamma f_start
	neg_mp(&Jp->entry[offset][0], func_val_sphere);
	mul_mp(temp, BED->gamma, func_val_start);
	add_mp(&Jp->entry[offset][0], &Jp->entry[offset][0], temp);
	
	
	
	
	
	
	
	//////////////
	//
	// function values for the static linears
	//
	////////////////////
	
	offset++;
	for (mm=0; mm<BED->num_static_linears; ++mm) {
		dot_product_mp(&funcVals->coord[mm+offset], BED->static_linear[mm], current_variable_values);
	}
	
	for (mm=0; mm<BED->num_static_linears; ++mm) {
		for (ii=0; ii<BED->num_variables; ii++) {
			set_mp(&Jv->entry[offset+mm][ii], &BED->static_linear[mm]->coord[ii]);
		}
	}
	
	//Jp is 0 for the static linears
	
	
	
	//////////////
	//
	// the entries for the patch equations.
	//
	////////////////////
	if (offset+BED->num_static_linears != BED->num_variables-BED->patch.num_patches) {
		std::cout << color::red() << "mismatch in offset!\nleft: " <<
		offset+BED->num_static_linears << " right " << BED->num_variables-BED->patch.num_patches << color::console_default() << std::endl;
		mypause();
	}
	
	offset = BED->num_variables-BED->patch.num_patches;
	for (ii=0; ii<BED->patch.num_patches; ii++)
		set_mp(&funcVals->coord[ii+offset], &patchValues->coord[ii]);
	
	
	for (ii = 0; ii<BED->patch.num_patches; ii++)  // for each patch equation
	{  // Jv = Jv_Patch
		for (jj = 0; jj<BED->num_variables; jj++) // for each variable
			set_mp(&Jv->entry[ii+offset][jj], &Jv_Patch->entry[ii][jj]);
	}
	
	//Jp is 0 for the patch.
	
	
	
	
	
	// done!  yay!
	
	if (BED->verbose_level()==16 || BED->verbose_level()==-16) {
		//uncomment to see screen output of important variables at each solve step.
		
		print_comp_matlab(pathVars, "t_mp");
		print_comp_matlab(BED->gamma, "gamma_mp");
		print_point_to_screen_matlab(current_variable_values,"currvars_mp");
		print_point_to_screen_matlab(funcVals,"F_mp");
		print_matrix_to_screen_matlab(Jv,"Jv_mp");
		print_matrix_to_screen_matlab(Jp,"Jp_mp");
		
		
	}
	
	
	BED->SLP_memory.set_globals_null();
	
	clear_mp(temp);
	clear_mp(temp2);
	clear_mp(gamma_s);
	clear_mp(one_minus_s);
	clear_mp(func_val_sphere);
	clear_mp(func_val_start);
	
	clear_vec_mp(patchValues);
	clear_vec_mp(temp_function_values);
	clear_vec_mp(AtimesF);
	
	
	clear_mat_mp(temp_jacobian_functions);
	clear_mat_mp(temp_jacobian_parameters);
	clear_mat_mp(Jv_Patch);
	clear_mat_mp(AtimesJ);
	
	
	
	
	return 0;
}