示例#1
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);
}
	/**
	 \brief print useful information to the screen
	 */
	virtual void print()
	{
		SolverDoublePrecision::print();
		
		std::cout << "multilintolin evaluator data (double):" << std::endl;
		for (int ii=0; ii<num_linears; ii++) {
			
			std::stringstream name;
			name << "old_linear_" << ii;
			print_point_to_screen_matlab(old_linear[ii],name.str());
		}
		
		for (int ii=0; ii<num_linears; ii++) {
			
			std::stringstream name;
			name << "current_linear_" << ii;
			print_point_to_screen_matlab(current_linear[ii],name.str());
		}
	}
示例#3
0
void UbermasterProcess::critreal(WitnessSet & W, vec_mp *pi, VertexSet & V)
{
	
	
	
	SystemRandomizer randomizer;
	
	randomizer.setup(W.num_variables()-1-W.dimension(),solve_options.PPD.num_funcs);
	
	
	
	print_point_to_screen_matlab(pi[0],"pi");

	FILE *OUT;
	OUT = safe_fopen_write("most_recent_pi");
	
	print_vec_out_mp(OUT, pi[0]); /* Print vector to file */
	fclose(OUT);
	
	NullspaceConfiguration ns_config; // this is set up in the nullspace call.
	
	SolverOutput solve_out;
	
	
	
	
	compute_crit_nullspace_left(solve_out, // the returned value
						   W,            // input the original witness set
						   std::make_shared<SystemRandomizer>(randomizer),
						   pi,
						   W.dimension(),  // dimension of ambient complex object
						   W.dimension(),   //  target dimension to find
						   W.dimension(),   // COdimension of the critical set to find.
						   program_options,
						   solve_options,
						   &ns_config);
	
	
	WitnessSet W_crit, W_nonsing, W_sing;
	
	solve_out.get_noninfinite_w_mult_full(W_crit);
	solve_out.get_nonsing_finite_multone(W_nonsing);
	solve_out.get_sing_finite(W_sing);
	
	W_crit.write_dehomogenized_coordinates("crit_data");
	W_nonsing.write_dehomogenized_coordinates("nonsingular");
	W_sing.write_dehomogenized_coordinates("singular");
	
	
	
	return;
}
示例#4
0
	/**
	 \brief print some relevant data to the screen

	 */
	void print()
	{
		std::cout << "num_variables " << num_variables << std::endl;
		std::cout << "num_mid_vars " << num_mid_vars << std::endl;
		std::cout << "SLP_top "      << SLP_top->size << std::endl;
		std::cout << "SLP_bottom " << SLP_bottom->size << std::endl;
		std::cout << "SLP_mid " << SLP_mid->size << std::endl;

		print_comp_matlab(u_target,"u_target");
		print_comp_matlab(v_target,"v_target");

		print_comp_matlab(crit_val_left,"crit_val_left");
		print_comp_matlab(crit_val_right,"crit_val_right");


		std::cout << num_projections << " projections: " << std::endl;
		for (int ii=0; ii<2; ii++) {
			print_point_to_screen_matlab(this->pi[ii],"pi");
		}

	};
示例#5
0
int compute_crit_nullspace_right(SolverOutput & solve_out, // the returned value
						   const WitnessSet & W,
						   std::shared_ptr<SystemRandomizer> randomizer,
						   vec_mp *pi, // an array of projections, the number of which is the target dimensions
						   int ambient_dim,
						   BertiniRealConfig & program_options,
						   SolverConfiguration & solve_options,
						   NullspaceConfiguration *ns_config)
{
	//many of the 1's here should be replaced by the number of patch equations, or the number of variable_groups
	
	
	
	
	
	// get the max degree of the derivative functions.  this is unique to the left nullspace formulation, as the functions become mixed together
	int max_degree;
	
	
	nullspace_config_setup_right(ns_config,
						   pi,
						   ambient_dim,
						   &max_degree,
						   randomizer,
						   W,
						   solve_options);
	
	
	
	
	
	if (max_degree==0) {
		// this will probably need tweaking when the dimension is higher than 1.  but who really is going to decompose a linear surface?
		solve_out.copy_patches(W);
		ns_concluding_modifications(solve_out, W, ns_config);
		
		
		std::cout << "the highest degree of any derivative equation is 0.  Returning empty SolverOutput." << std::endl;
		//then there cannot possibly be any critical points, with respect to ANY projection.  simply return an empty but complete set.
		
		return 0;
	}
	
	
	
	
	
	
	//
	///
	/////        end setup
	////////
	//////////////
	///////////////////////////
	
	
	
	
	
	
	int offset;
	WitnessSet Wtemp, Wtemp2;
	
	
	//  2.  Do a bunch of homotopies in $x$, each set of which will be followed by a single linear solve in $v$.
	if (program_options.verbose_level()>=3) {
		std::cout << "building up linprod start system for left nullspace" << std::endl;
	}
	
	// setup for the multilin moves
	//  these are for feeding into the multilin solver -- and that's it.  the majority will be overridden in the while loop as the start x linears
	vec_mp *multilin_linears = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp)); // target dim is the number of linears in the input witness set
	for (unsigned int ii=0; ii<W.num_linears(); ii++) {
		init_vec_mp2(multilin_linears[ii],W.num_variables(), solve_options.T.AMP_max_prec);
		multilin_linears[ii]->size = W.num_variables();
		vec_cp_mp(multilin_linears[ii], W.linear(ii));
	}
	
	MultilinConfiguration ml_config(solve_options,randomizer);
	
	
	
	// this is for performing the matrix inversion to get ahold of the $v$ values corresponding to $x$
	mat_mp tempmat;  init_mat_mp2(tempmat, ns_config->num_v_vars, ns_config->num_v_vars,solve_options.T.AMP_max_prec);
	tempmat->rows = tempmat->cols = ns_config->num_v_vars;
	
	offset = ns_config->num_v_vars-1;
	for (int jj=0; jj<ns_config->num_v_vars; jj++)
		set_mp(&tempmat->entry[offset][jj], &ns_config->v_patch->coord[jj]);
	
	
	// for holding the result of the matrix inversion
	vec_mp result; init_vec_mp2(result,ns_config->num_v_vars,solve_options.T.AMP_max_prec);  result->size = ns_config->num_v_vars;
	
	// use this for the matrix inversion
	vec_mp invert_wrt_me;
	init_vec_mp2(invert_wrt_me,ns_config->num_v_vars,solve_options.T.AMP_max_prec); invert_wrt_me->size = ns_config->num_v_vars;
	for (int ii=0; ii<ns_config->num_v_vars-1; ii++)
		set_zero_mp(&invert_wrt_me->coord[ii]); // set zero
	
	set_one_mp(&invert_wrt_me->coord[ns_config->num_v_vars-1]); // the last entry is set to 1 for the patch equation
	
	
	
	
	
	
	vec_mp temppoint;  init_vec_mp2(temppoint, ns_config->num_natural_vars +ns_config->num_synth_vars + ns_config->num_v_vars,solve_options.T.AMP_max_prec);
	temppoint->size = ns_config->num_natural_vars + ns_config->num_synth_vars + ns_config->num_v_vars;
	
	
	WitnessSet W_step_one;
	W_step_one.set_num_variables(W.num_variables());
	W_step_one.set_num_natural_variables(W.num_natural_variables());
	W_step_one.copy_patches(W);
	W_step_one.copy_names(W);
	
	
	WitnessSet W_linprod;
	W_linprod.set_num_variables(ns_config->num_natural_vars + ns_config->num_v_vars + ns_config->num_synth_vars);
	W_linprod.set_num_natural_variables(W.num_natural_variables());
	
	
	if (program_options.quick_run()<=1)
		solve_options.robust = true;
	else
		solve_options.robust = false;
	
	
	
	
	
	for (int ii=0; ii<randomizer->num_rand_funcs(); ii++) {
		
		int differentiated_degree = randomizer->randomized_degree(ii)-1; // the -1 is for differentiating.  this could be 0.
		
		if (differentiated_degree==0) {
			continue;
		}
		else{
			for (int jj=0; jj<differentiated_degree; jj++) {
				
				//copy in the linear for the solve
				vec_cp_mp(multilin_linears[0], ns_config->starting_linears[ii][jj]);
				
				// the remainder of the linears are left alone (stay stationary).
				
				if (program_options.verbose_level()>=6) {
					std::cout << "moving FROM this set:\n";
					for (unsigned int ii=0; ii<W.num_linears(); ii++) {
						print_point_to_screen_matlab(W.linear(ii),"L");
					}
					std::cout << "\nTO this set:\n";
					for (unsigned int ii=0; ii<W.num_linears(); ii++) {
						print_point_to_screen_matlab(multilin_linears[ii],"ELL");
					}
				}
				
				
				
				// actually solve WRT the linears
				
				
				SolverOutput fillme;
				multilin_solver_master_entry_point(W,         // WitnessSet
												   fillme, // the new data is put here!
												   multilin_linears,
												   ml_config,
												   solve_options);
				
				WitnessSet Wtemp;
				fillme.get_noninfinite_w_mult_full(Wtemp); // should be ordered
				
				W_step_one.merge(Wtemp, &solve_options.T);
				
				Wtemp.reset();
			}
			
			
			
			int curr_index = 0;
			for (int kk=0; kk<ns_config->num_v_vars; kk++) { // subtract one from upper limit because of the patch equation
				if (kk!=ii) {
					
					for (int mm=0; mm<ns_config->num_v_vars; mm++){
						set_mp(&tempmat->entry[curr_index][mm], &ns_config->v_linears[kk]->coord[mm]);}
					
					curr_index++;
				}
			}
			
			
			// invert the matrix for the v variables.
			matrixSolve_mp(result, tempmat,  invert_wrt_me);
			
			//set the bottom part of the temppoint, which will be a startpoint for the nullspace call later.
			offset = ns_config->num_natural_vars+ns_config->num_synth_vars;
			for (int mm=0; mm<ns_config->num_v_vars; mm++)
				set_mp(&temppoint->coord[mm+offset], &result->coord[mm]);
			
			
			//set the top part, x, of the start point, and copy it in.
			for (unsigned int kk=0; kk<W_step_one.num_points(); kk++) {
				for (int mm=0; mm<ns_config->num_natural_vars+ns_config->num_synth_vars; mm++) {
					set_mp(&temppoint->coord[mm], & W_step_one.point(kk)->coord[mm]);
				}
				W_linprod.add_point(temppoint);
			}
			
			
			
			W_step_one.reset();
			W_step_one.set_num_variables(W.num_variables());
			W_step_one.set_num_natural_variables(W.num_natural_variables());
			W_step_one.copy_patches(W);  // necessary?
			W_step_one.copy_names(W); // necessary?
		}
		
		
		
		
		
		
		
	}
	
	
	for (int ii=0; ii<1; ii++)
		clear_vec_mp(multilin_linears[ii]);
	free(multilin_linears);
	
	clear_vec_mp(temppoint);
	
	
	
	int num_before = W_linprod.num_points();
	W_linprod.sort_for_unique(&solve_options.T);
	if (num_before - W_linprod.num_points()>0) {
		std::cout << "there were non-unique start points" << std::endl;
		mypause();
	}
	
	
	
	W_linprod.set_num_natural_variables(ns_config->num_v_vars+ns_config->num_synth_vars);
	W_linprod.copy_patches(W);
	W_linprod.copy_names(W);
	
	//set some solver options
	
	if (program_options.quick_run()<=0)
		solve_options.robust = true;
	else
		solve_options.robust = false;
	
	
	
	solve_options.use_midpoint_checker = 0;
	
	
	
	if (program_options.verbose_level()>=6)
		ns_config->print();
	
	
	
	if (program_options.verbose_level()>=3) {
		std::cout << "running nullspace right method" << std::endl;
	}
	
	
	
	
	nullspacejac_solver_master_entry_point(solve_options.T.MPType,
										   W_linprod, // carries with it the start points, but not the linears.
										   solve_out,   // the created data goes in here.
										   ns_config,
										   solve_options);
	
	
	ns_concluding_modifications(solve_out, W, ns_config);
	
	
	clear_mat_mp(tempmat);
	clear_vec_mp(invert_wrt_me);
	clear_vec_mp(result);
	
	
	return SUCCESSFUL;
}
int sphere_eval_d(point_d funcVals, point_d parVals, vec_d parDer, mat_d Jv, mat_d Jp,
				  point_d current_variable_values, comp_d pathVars,
				  void const *ED)
{ // evaluates a special homotopy type, built for bertini_real
	
	sphere_eval_data_d *BED = (sphere_eval_data_d *)ED; // to avoid having to cast every time
	
	
	BED->SLP_memory.set_globals_to_this();
	
	int ii, jj, mm; // counters
	int offset;
	comp_d one_minus_s, gamma_s;
	comp_d temp, temp2;
	comp_d func_val_sphere, func_val_start;
	
	set_one_d(one_minus_s);
	sub_d(one_minus_s, one_minus_s, pathVars);  // one_minus_s = (1 - s)
	mul_d(gamma_s, BED->gamma, pathVars);       // gamma_s = gamma * s
	
	
	vec_d patchValues; init_vec_d(patchValues, 0);
	vec_d temp_function_values; init_vec_d(temp_function_values,0);
	vec_d AtimesF; init_vec_d(AtimesF,BED->randomizer()->num_rand_funcs()); AtimesF->size = BED->randomizer()->num_rand_funcs();// declare  // initialize
	
	
	
	mat_d temp_jacobian_functions; init_mat_d(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_d temp_jacobian_parameters; init_mat_d(temp_jacobian_parameters,0,0);
	mat_d Jv_Patch; init_mat_d(Jv_Patch, 0, 0);
	mat_d AtimesJ; init_mat_d(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_d(funcVals,BED->num_variables); funcVals->size = BED->num_variables;
	change_size_mat_d(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_d(&Jv->entry[ii][jj]);
	
	
	
	// evaluate the SLP to get the system's whatnot.
	evalProg_d(temp_function_values, parVals, parDer, temp_jacobian_functions, temp_jacobian_parameters, current_variable_values, pathVars, BED->SLP);
	
	
	// evaluate the patch
	patch_eval_d(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_d(parVals, 1);
	change_size_vec_d(parDer, 1);
	change_size_mat_d(Jp, BED->num_variables, 1); Jp->rows = BED->num_variables; Jp->cols = 1;
	for (ii=0; ii<BED->num_variables; ii++)
		set_zero_d(&Jp->entry[ii][0]);
	
	
	parVals->size = parDer->size = 1;
	set_d(&parVals->coord[0], pathVars); // s = t
	set_one_d(&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_d(&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_d(&Jv->entry[ii][jj],&AtimesJ->entry[ii][jj]);
	
	//Jp is 0 for the equations.
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	///////////////////
	//
	//  the sphere equation.
	//
	//////////////////////////
	
	offset = BED->randomizer()->num_rand_funcs();
	
	mul_d(func_val_sphere, BED->radius, BED->radius);
	neg_d(func_val_sphere, func_val_sphere);
	mul_d(func_val_sphere, func_val_sphere, &current_variable_values->coord[0]);
	mul_d(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_d(temp2, &BED->center->coord[ii-1], &current_variable_values->coord[0]); // temp2 = c_{i-1}*h
		
		sub_d(temp, &current_variable_values->coord[ii], temp2);  // temp = x_i - h*c_{i-1}
		mul_d(temp2, temp, temp);                                 // temp2 = (x_i - h*c_{i-1})^2
		add_d(func_val_sphere, func_val_sphere, temp2);           // f_sph += (x_i - h*c_{i-1})^2
	}
	
	
	
	set_one_d(func_val_start);
	for (mm=0; mm<2; ++mm) {
		dot_product_d(temp, BED->starting_linear[mm], current_variable_values);
		mul_d(func_val_start, func_val_start, temp);
		//f_start *= L_i (x)
	}
	
	
	// combine the function values
	mul_d(temp, one_minus_s, func_val_sphere);
	mul_d(temp2, gamma_s, func_val_start);
	add_d(&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_d(temp2, &BED->center->coord[ii-1], &current_variable_values->coord[0]); // temp2 = c_{i-1}*h
		sub_d(temp, &current_variable_values->coord[ii], temp2) // temp = x_i - c_{i-1}*h
		mul_d(&Jv->entry[offset][ii], BED->two, temp); // Jv = 2*(x_i - c_{i-1}*h)
		mul_d(&Jv->entry[offset][ii], &Jv->entry[offset][ii], one_minus_s); // Jv = (1-t)*2*(x_i - c_{i-1}*h)
																			// multiply these entries by (1-t)
		
		mul_d(temp2, &BED->center->coord[ii-1], temp);  // temp2 = c_{i-1} * ( x_i - c_{i-1} * h )
		add_d(&Jv->entry[offset][0], &Jv->entry[offset][0], temp2); // Jv[0] += c_{i-1} * ( x_i - c_{i-1} * h )
	}
	
	
	
	// the homogenizing var deriv
	mul_d(temp, &current_variable_values->coord[0], BED->radius);
	mul_d(temp, temp, BED->radius);  // temp = r^2 h
	
	add_d(&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_d(&Jv->entry[offset][0], &Jv->entry[offset][0]); // Jv[0] = -Jv[0]
	mul_d(&Jv->entry[offset][0], &Jv->entry[offset][0], BED->two);  // Jv[0] *= 2
	mul_d(&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[0] = -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_d(temp, BED->starting_linear[0], current_variable_values);
		mul_d(temp, temp, &BED->starting_linear[1]->coord[ii]);
		
		dot_product_d(temp2, BED->starting_linear[1], current_variable_values);
		mul_d(temp2, temp2, &BED->starting_linear[0]->coord[ii]);
		
		add_d(temp, temp, temp2);
		mul_d(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_d(&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_d(&Jp->entry[offset][0], func_val_sphere);
	mul_d(temp, BED->gamma, func_val_start);
	add_d(&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_d(&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_d(&Jv->entry[mm+offset][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_d(&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_d(&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_point_to_screen_matlab(BED->center,"center");
		print_comp_matlab(BED->radius,"radius");
		
		printf("gamma = %lf+1i*%lf;\n", BED->gamma->r, BED->gamma->i);
		printf("time = %lf+1i*%lf;\n", pathVars->r, pathVars->i);
		print_point_to_screen_matlab(current_variable_values,"currvars");
		print_point_to_screen_matlab(funcVals,"F");
		print_matrix_to_screen_matlab(Jv,"Jv");
		print_matrix_to_screen_matlab(Jp,"Jp");
		
	}
	
	
	BED->SLP_memory.set_globals_null();
	
	clear_vec_d(patchValues);
	clear_vec_d(temp_function_values);
	clear_vec_d(AtimesF);
	
	
	clear_mat_d(temp_jacobian_functions);
	clear_mat_d(temp_jacobian_parameters);
	clear_mat_d(Jv_Patch);
	clear_mat_d(AtimesJ);
	
#ifdef printpathsphere
	BED->num_steps++;
	vec_d dehommed; init_vec_d(dehommed,BED->num_variables-1); dehommed->size = BED->num_variables-1;
	dehomogenize(&dehommed,current_variable_values);
	fprintf(BED->FOUT,"%.15lf %.15lf ", pathVars->r, pathVars->i);
	for (ii=0; ii<BED->num_variables-1; ++ii) {
		fprintf(BED->FOUT,"%.15lf %.15lf ",dehommed->coord[ii].r,dehommed->coord[ii].i);
	}
	fprintf(BED->FOUT,"\n");
	clear_vec_d(dehommed);
#endif
	
	
	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 check_issoln_sphere_d(endgame_data_t *EG,
						  tracker_config_t *T,
						  void const *ED)
{
	sphere_eval_data_d *BED = (sphere_eval_data_d *)ED; // to avoid having to cast every time
	
	BED->SLP_memory.set_globals_to_this();
	int ii;
	
	
	
	
	double n1, n2, max_rat;
	point_d f;
	eval_struct_d e;
	
	
	init_point_d(f, 1);
	init_eval_struct_d(e,0, 0, 0);
	
	max_rat = MAX(T->ratioTol,0.99999);
	
	// setup threshold based on given threshold and precision
	//	if (num_digits > 300)
	//		num_digits = 300;
	//	num_digits -= 2;
	double tol = MAX(T->funcResTol, 1e-8);
	
	
	if (EG->prec>=64){
		vec_d terminal_pt;  init_vec_d(terminal_pt,1);
		vec_mp_to_d(terminal_pt,EG->PD_mp.point);
		evalProg_d(e.funcVals, e.parVals, e.parDer, e.Jv, e.Jp, terminal_pt, EG->PD_d.time, BED->SLP);
		clear_vec_d(terminal_pt);
	}
	else{
		evalProg_d(e.funcVals, e.parVals, e.parDer, e.Jv, e.Jp, EG->PD_d.point, EG->PD_d.time, BED->SLP);
	}
	
	
	if (EG->last_approx_prec>=64) {
		vec_d prev_pt;  init_vec_d(prev_pt,1);
		vec_mp_to_d(prev_pt,EG->PD_mp.point);
		evalProg_d(f, e.parVals, e.parDer, e.Jv, e.Jp, prev_pt, EG->PD_d.time, BED->SLP);
		clear_vec_d(prev_pt);}
	else{
		evalProg_d(f, e.parVals, e.parDer, e.Jv, e.Jp, EG->last_approx_d, EG->PD_d.time, BED->SLP);
	}
	
	// compare the function values
	int isSoln = 1;
	for (ii = 0; (ii < BED->SLP->numFuncs) && isSoln; ii++)
	{
		n1 = d_abs_d( &e.funcVals->coord[ii]); // corresponds to final point
		n2 = d_abs_d( &f->coord[ii]); // corresponds to the previous point
		
		if (tol <= n1 && n1 <= n2)
		{ // compare ratio
			if (n1 > max_rat * n2){
				isSoln = 0;
				printf("labeled as non_soln due to max_rat (d) 1 coord %d\n",ii);
			}
		}
		else if (tol <= n2 && n2 <= n1)
		{ // compare ratio
			if (n2 > max_rat * n1){
				isSoln = 0;
				printf("labeled as non_soln due to max_rat (d) 2 coord %d\n",ii);
			}
		}
	}
	
	if (!isSoln) {
		print_point_to_screen_matlab(e.funcVals,"terminal_func_vals");
		print_point_to_screen_matlab(f,"prev");
		printf("tol was %le\nmax_rat was %le\n",tol,max_rat);
	}
	
	
	clear_eval_struct_d(e);
	clear_vec_d(f);
	
	BED->SLP_memory.set_globals_null();
	
	
	return isSoln;
	
}