示例#1
0
	void clear()
	{

		clear_mp(v_target);
		clear_mp(u_target);
		clear_mp(crit_val_left);
		clear_mp(crit_val_right);

		if (num_projections>0) {
			for (int ii=0; ii<num_projections; ii++) {
				clear_vec_mp(pi[ii]);
			}
			free(pi);
		}

	}
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;
}
示例#3
0
	void clear()
	{
		clear_vec_mp(checker_1_);
		clear_vec_mp(checker_2_);
		
		clear_mp(diff_);
		
		mpf_clear(abs_);
		mpf_clear(zerothresh_);
		
		for (int ii=0; ii<num_projections_; ii++) {
			clear_vec_mp(projections_[ii]);
		}
		free(projections_);
	}
示例#4
0
	/**
	 \brief reset to empty state.
	 */
	void clear()
	{

		if (this->num_projections>0) {
			for (int ii=0; ii<num_projections; ii++) {
				clear_vec_mp(pi[ii]);
			}
			free(pi);
		}

		clear_mp(v_target);
		clear_mp(u_target);

		clear_mp(crit_val_left);
		clear_mp(crit_val_right);

		clear_mp(u_start);
		clear_mp(v_start);

		clear_mp(half);
		clear_mp(one);
		clear_mp(zero);


		if (this->MPType==2){

			if (this->num_projections>0) {
				for (int ii=0; ii<num_projections; ii++) {
					clear_vec_mp(pi_full_prec[ii]);
				}
				free(pi_full_prec);
			}

			clear_mp(v_target_full_prec);
			clear_mp(u_target_full_prec);

			clear_mp(crit_val_left_full_prec);
			clear_mp(crit_val_right_full_prec);

			clear_mp(u_start_full_prec);
			clear_mp(v_start_full_prec);

			clear_mp(half_full_prec);
			clear_mp(one_full_prec);
			clear_mp(zero_full_prec);

		}



	} // re: clear
示例#5
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_dehom(point_d out_d, point_mp out_mp, int *out_prec, point_d in_d, point_mp in_mp, int in_prec, void const *ED_d, void const *ED_mp)
{
	sphere_eval_data_d *BED_d = NULL;
	sphere_eval_data_mp *BED_mp = NULL;
	
	*out_prec = in_prec;
	
	
	
	if (in_prec < 64)
	{ // compute out_d
		sphere_eval_data_d *BED_d = (sphere_eval_data_d *)ED_d;
		
		comp_d denom;
		change_size_vec_d(out_d,in_d->size-1);
		out_d->size = in_d->size-1;
		
		set_d(denom, &in_d->coord[0]);
		
		for (int ii=0; ii<BED_d->num_variables-1; ++ii) {
			set_d(&out_d->coord[ii],&in_d->coord[ii+1]);
			div_d(&out_d->coord[ii],&out_d->coord[ii],denom); //  result[ii] = dehom_me[ii+1]/dehom_me[0].
		}
		
		
		
		//		print_point_to_screen_matlab(in_d,"in");
		//		print_point_to_screen_matlab(out_d,"out");
		
		
	}
	else
	{ // compute out_mp
		sphere_eval_data_mp *BED_mp = (sphere_eval_data_mp *)ED_mp;
		
		setprec_point_mp(out_mp, *out_prec);
		
		comp_mp denom; init_mp(denom);
		change_size_vec_mp(out_mp,in_mp->size-1);
		out_mp->size = in_mp->size-1;
		
		set_mp(denom, &in_mp->coord[0]);
		
		for (int ii=0; ii<BED_mp->num_variables-1; ++ii) {
			set_mp(&out_mp->coord[ii],&in_mp->coord[ii+1]);
			div_mp(&out_mp->coord[ii],&out_mp->coord[ii],denom); //  result[ii] = dehom_me[ii+1]/dehom_me[0].
		}
		
		
		clear_mp(denom);
		
		
		// set prec on out_mp
		
		
		//		print_point_to_screen_matlab(in_mp,"in");
		//		print_point_to_screen_matlab(out_mp,"out");
		
	}
	
	
	BED_d = NULL;
	BED_mp = NULL;
	
	
	
	
	return 0;
}
//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;
}