Beispiel #1
0
	/**
	 \brief add a projection to the set, and get its index.
	 
	 Add a projection to the set, and get its index.  Does not test for uniqueness of the projection, assumes it is not in there yet.
	 
	 \return the index of the added projection
	 \param proj the projection to add.
	 
	 */
	int add_projection(vec_mp proj){
		
		if (this->num_projections_==0) {
			projections_ = (vec_mp *) br_malloc(sizeof(vec_mp));
		}
		else{
			this->projections_ = (vec_mp *)br_realloc(this->projections_, (this->num_projections_+1) * sizeof(vec_mp));
		}
		
		
		init_vec_mp2(this->projections_[num_projections_],num_natural_variables_,T_->AMP_max_prec);
		this->projections_[num_projections_]->size = num_natural_variables_;
		
		
		if (proj->size != num_natural_variables_) {
			vec_mp tempvec;
			init_vec_mp2(tempvec,num_natural_variables_,T_->AMP_max_prec); tempvec->size = num_natural_variables_;
			for (int kk=0; kk<num_natural_variables_; kk++) {
				set_mp(&tempvec->coord[kk], &proj->coord[kk]);
			}
			vec_cp_mp(projections_[num_projections_], tempvec);
			clear_vec_mp(tempvec);
		}
		else
		{
			vec_cp_mp(projections_[num_projections_], proj);
		}
		

		num_projections_++;
		
		return num_projections_;
	}
	/**
	 \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 change_sphere_eval_prec(void const *ED, int new_prec)
{
	
	sphere_eval_data_mp *BED = (sphere_eval_data_mp *)ED; // to avoid having to cast every time
	
	
	
	BED->SLP->precision = new_prec;
	// change the precision for the patch
	changePatchPrec_mp(new_prec, &BED->patch);
	
	
	if (new_prec != BED->curr_prec){
		
		if (BED->verbose_level() >=8){
			std::cout << color::brown();
			printf("prec  %ld\t-->\t%d\n",BED->curr_prec, new_prec);
			std::cout << color::console_default();
		}
		
		BED->curr_prec = new_prec;
		
		setprec_mp(BED->gamma, new_prec);
		mpf_set_q(BED->gamma->r, BED->gamma_rat[0]);
		mpf_set_q(BED->gamma->i, BED->gamma_rat[1]);
		
		for (int ii=0; ii<1; ++ii){
			change_prec_point_mp(BED->starting_linear[ii],new_prec);
			vec_cp_mp(BED->starting_linear[ii], BED->starting_linear_full_prec[ii]);
		}
		
		for (int ii=0; ii<BED->num_static_linears; ++ii){
			change_prec_point_mp(BED->static_linear[ii],new_prec);
			vec_cp_mp(BED->static_linear[ii], BED->static_linear_full_prec[ii]);
		}
		
		change_prec_point_mp(BED->center, new_prec);
		vec_cp_mp(BED->center, BED->center_full_prec);
		
		setprec_mp(BED->radius, new_prec);
		set_mp(BED->radius, BED->radius_full_prec);
		
		setprec_mp(BED->two, new_prec);
		set_mp(BED->two, BED->two_full_prec);
		
		BED->randomizer()->change_prec(new_prec);
		
	}
	
	
	return 0;
}
Beispiel #4
0
int LinearHolder::add_linear(vec_mp new_linear)
{

	if (num_linears_!=0 && L_mp_==NULL) {
		printf("trying to add linear to linear holder with non-zero num_linears and NULL container!\n");
		br_exit(9711);
	}

	if (num_linears_==0 && L_mp_!=NULL) {
		printf("trying to add linear to linear holder with num_linears==0 and non-NULL container!\n");
		br_exit(9711);
	}


	if (num_linears_==0) {
		L_mp_ = (vec_mp *)br_malloc(sizeof(vec_mp));
	}
	else{
		L_mp_ = (vec_mp *)br_realloc(L_mp_, (num_linears_+1) * sizeof(vec_mp));
	}

	init_vec_mp2(L_mp_[num_linears_], new_linear->size,new_linear->curr_prec);
	L_mp_[num_linears_]->size = new_linear->size;
	vec_cp_mp(L_mp_[num_linears_], new_linear);

	this->num_linears_++;


	return num_linears_-1;
}
Beispiel #5
0
int PointHolder::add_point(vec_mp new_point)
{

	if (num_pts_!=0 && this->pts_mp_==NULL) {
		printf("trying to add point to PointHolder with non-zero num_points and NULL container!\n");
		br_exit(9713);
	}

	if (num_pts_==0 && this->pts_mp_!=NULL) {
		printf("trying to add point to PointHolder with num_points==0 and non-NULL container!\n");
		br_exit(9713);
	}


	if (num_pts_==0) {
		pts_mp_ = (vec_mp *)br_malloc(sizeof(vec_mp));
	}
	else{
		pts_mp_ = (vec_mp *)br_realloc(pts_mp_, (num_pts_+1) * sizeof(vec_mp));
	}

	init_vec_mp2(pts_mp_[num_pts_], new_point->size, new_point->curr_prec);
	pts_mp_[num_pts_]->size = new_point->size;
	vec_cp_mp(pts_mp_[num_pts_], new_point);

	num_pts_++;

	return num_pts_-1;
}
	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
Beispiel #7
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;
}
Beispiel #8
0
	void copy(const VertexSet &other)
	{
		set_tracker_config(other.T());
		
		
		this->curr_projection_ = other.curr_projection_;
		if (this->num_projections_==0 && other.num_projections_>0) {
			projections_ = (vec_mp *) br_malloc(other.num_projections_*sizeof(vec_mp));
		}
		else if(this->num_projections_>0 && other.num_projections_>0) {
			projections_ = (vec_mp *) br_realloc(projections_,other.num_projections_*sizeof(vec_mp));
		}
		else if (this->num_projections_>0 && other.num_projections_==0){
			for (int ii=0; ii<this->num_projections_; ii++) {
				clear_vec_mp(projections_[ii]);
			}
			free(projections_);
		}
		
		for (int ii=0; ii<other.num_projections_; ii++) {
			if (ii>=this->num_projections_){
				init_vec_mp2(projections_[ii],1,1024); projections_[ii]->size = 1;
			}
			vec_cp_mp(projections_[ii],other.projections_[ii]);
		}
		
		this->num_projections_ = other.num_projections_;
		
		
		curr_input_index_ = other.curr_input_index_;
		filenames_ = other.filenames_;
		
		
		this->num_vertices_ = other.num_vertices_;
		this->num_natural_variables_ = other.num_natural_variables_;
		
		this->vertices_ = other.vertices_;
		
		vec_cp_mp(this->checker_1_,other.checker_1_);
		vec_cp_mp(this->checker_2_,other.checker_2_);
		
	}
Beispiel #9
0
void WitnessSet::only_first_vars(int num_vars)
{
	
	vec_mp tempvec;  init_vec_mp2(tempvec, num_vars, 1024);
	tempvec->size = num_vars;
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		vec_mp & curr_point = point(ii);
		
		for (int jj=0; jj<num_vars; jj++) {
			set_mp(&tempvec->coord[jj], &curr_point->coord[jj]);
		}
		
		change_size_vec_mp(curr_point, num_vars);  curr_point->size = num_vars;
		vec_cp_mp(curr_point, tempvec);
	}
	
	
	this->num_vars_ = num_vars;
	
	int patch_size_counter = 0, trim_from_here =  0;
	for (unsigned int ii=0; ii<num_patches(); ii++) {
		patch_size_counter += patch(ii)->size;
		if (patch_size_counter == num_vars)
		{
			trim_from_here = ii+1;
		}
	}
	
	if (trim_from_here==0) {
		std::cerr << "problem: the sum of the patch sizes never equalled the number of variables to trim to...\nhence, the trimming operation could not complete." << std::endl;
		this->print_to_screen();
		deliberate_segfault();
	}
	
	for (unsigned int ii=trim_from_here; ii<num_patches(); ii++) {
		clear_vec_mp(patch(ii));
	}
	
	patch_mp_ = (vec_mp *) br_realloc(patch_mp_, trim_from_here* sizeof(vec_mp));
	num_patches_ = trim_from_here;
	
	for (unsigned int ii=0; ii<num_linears(); ii++) {
		linear(ii)->size = num_vars;
	}
	
	clear_vec_mp(tempvec);
	return;
}
Beispiel #10
0
int PatchHolder::add_patch(vec_mp new_patch)
{

	if (num_patches_!=0 && patch_mp_==NULL) {
		printf("trying to add patch to witness set with non-zero num_patches and NULL container!\n");
		deliberate_segfault();
	}

	if (num_patches_==0 && patch_mp_!=NULL) {
		printf("trying to add point to witness set with num_points==0 and non-NULL container!\n");
		deliberate_segfault();
	}


	if (num_patches_==0) {
		patch_mp_ = (vec_mp *)br_malloc(sizeof(vec_mp));
	}
	else{
		patch_mp_ = (vec_mp *)br_realloc(patch_mp_, (num_patches_+1) * sizeof(vec_mp));
	}

	init_vec_mp2(patch_mp_[num_patches_], new_patch->size,new_patch->curr_prec);
	patch_mp_[num_patches_]->size = new_patch->size;
	vec_cp_mp(patch_mp_[num_patches_], new_patch);

	this->num_patches_++;


	int burnsome = 0;
	for (unsigned int ii=0; ii<this->num_patches_; ii++) {
		burnsome += this->patch_mp_[ii]->size;
	}


	return num_patches_-1;
}
	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
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;
	
}
Beispiel #13
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;
}
Beispiel #14
0
// T is necessary for the tolerances.
void WitnessSet::sort_for_unique(tracker_config_t * T)
{
	
	if (num_vars_==0) {
		throw std::logic_error("sorting witness set with 0 variables for uniqueness");
	}
	
	int curr_uniqueness;
	int num_good_pts = 0;
	std::vector<int> is_unique;
	
	for (unsigned int ii = 0; ii<num_points(); ++ii) {
		vec_mp &curr_point = point(ii);
		
		curr_uniqueness = 1;
		
		int prev_size_1 = curr_point->size;  curr_point->size = num_natty_vars_; // cache and change to natural number
		
		for (unsigned int jj=ii+1; jj<num_points(); ++jj) {
			vec_mp & inner_point = point(jj);
			int prev_size_2 = inner_point->size; inner_point->size = num_natty_vars_; // cache and change to natural number
			if ( isSamePoint_homogeneous_input(curr_point,inner_point,T->final_tol_times_mult) ){
				curr_uniqueness = 0;
			}
			inner_point->size = prev_size_2; // restore
		}
		curr_point->size = prev_size_1; // restore
		
		if (curr_uniqueness==1) {
			is_unique.push_back(1);
			num_good_pts++;
		}
		else {
			is_unique.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_unique[ii]==1) {
			
			init_vec_mp2(transferme[counter],num_vars_,1024);  transferme[counter]->size = num_vars_;
			vec_cp_mp(transferme[counter], point(ii));
			counter++;
		}
	}
	
	if (counter!= num_good_pts) {
		std::logic_error("counter mismatch");
	}
	
	if (num_points()>0) {
		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;
	
	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;
}
Beispiel #16
0
void Vertex::set_point(const vec_mp new_point)
{
	change_prec_vec_mp(this->pt_mp_, new_point->curr_prec);
	vec_cp_mp(this->pt_mp_, new_point);
}
Beispiel #17
0
void nullspace_config_setup_right(NullspaceConfiguration *ns_config,
								  vec_mp *pi, // an array of projections, the number of which is the target dimensions
								  int ambient_dim,
								  int *max_degree, // a pointer to the value
								  std::shared_ptr<SystemRandomizer> randomizer,
								  const WitnessSet & W,
								  SolverConfiguration & solve_options)
{
	
	ns_config->set_side(nullspace_handedness::RIGHT);
	
	
	
	int toss;
	parse_input_file(W.input_filename(), &toss); // re-create the parsed files for the stuffs (namely the SLP).
	
	ns_config->set_randomizer(randomizer); // set the pointer.  this randomizer is for the underlying system.
	
	*max_degree = randomizer->max_degree()-1; // minus one for differentiated degree
	ns_config->max_degree = *max_degree;
	
	
	
	// set some integers
	
	ns_config->num_projections = ambient_dim;
	
	ns_config->num_v_vars = W.num_natural_variables()-1;
	
	
	ns_config->num_synth_vars = W.num_synth_vars(); // this may get a little crazy if we chain into this more than once.  this code is written to be called into only one time beyond the first.
	ns_config->num_natural_vars = W.num_natural_variables();
	
	ns_config->ambient_dim = ambient_dim;
	
	
	ns_config->target_projection = (vec_mp *) br_malloc(ns_config->num_projections * sizeof(vec_mp));
	for (int ii=0; ii<ns_config->num_projections; ii++) {
		init_vec_mp2(ns_config->target_projection[ii], W.num_variables(),solve_options.T.AMP_max_prec);
		ns_config->target_projection[ii]->size = W.num_variables();
		vec_cp_mp(ns_config->target_projection[ii], pi[ii]);
	}
	
	
	
	ns_config->num_jac_equations = (ns_config->num_natural_vars - 1);// N-1;  the subtraction of 1 is for the 1 hom-var.
																	 // me must omit any previously added synthetic vars.
	
	ns_config->num_additional_linears = ambient_dim-1;
	
	ns_config->num_v_linears = ns_config->num_jac_equations;
	
	
	
	// this check is correct.
	int check_num_func = randomizer->num_rand_funcs() + ns_config->num_jac_equations + ns_config->num_additional_linears + W.num_patches() + 1; // +1 for v patch from this incoming computation
	int check_num_vars = ns_config->num_natural_vars + ns_config->num_synth_vars + ns_config->num_v_vars;
	if (check_num_func != check_num_vars) {
		std::cout << color::red();
		std::cout << "mismatch in number of equations...\n" << std::endl;
		std::cout << "left: " << check_num_func << " right " << check_num_vars << std::endl;
		std::cout << color::console_default();
		throw std::logic_error("logic error in nullspace_left");
	}
	
	

	
	
	
	// set up the linears in $v$  ( the M_i linears)
	ns_config->v_linears = (vec_mp *)br_malloc(ns_config->num_v_linears*sizeof(vec_mp));
	for (int ii=0; ii<ns_config->num_v_linears; ii++) {
		init_vec_mp2(ns_config->v_linears[ii],ns_config->num_v_vars,solve_options.T.AMP_max_prec);
		ns_config->v_linears[ii]->size = ns_config->num_v_vars;
		for (int jj=0; jj<ns_config->num_v_vars; jj++){
			get_comp_rand_mp(&ns_config->v_linears[ii]->coord[jj]); // should this be real? no.
		}
	}
	
	
	// the last of the linears will be used for the slicing, and passed on to later routines
	int offset = 1;
	
	
	ns_config->additional_linears_terminal = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp));
	ns_config->additional_linears_starting = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp));
	
	for (int ii=0; ii<ns_config->num_additional_linears; ii++) {
		init_vec_mp2(ns_config->additional_linears_terminal[ii],W.num_variables(),solve_options.T.AMP_max_prec);
		ns_config->additional_linears_terminal[ii]->size = W.num_variables();
		
		for (int jj=0; jj<W.num_natural_variables(); jj++){
			get_comp_rand_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]); // should this be real?  no.
		}
		for (int jj=W.num_natural_variables(); jj<W.num_variables(); jj++) {
			set_zero_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]);
		}
		
		
		init_vec_mp2(ns_config->additional_linears_starting[ii],W.num_variables(),solve_options.T.AMP_max_prec);
		ns_config->additional_linears_starting[ii]->size = W.num_variables();
		vec_cp_mp(ns_config->additional_linears_starting[ii], W.linear(ii+offset));
	}
	
	
	// set up the patch in $v$.  we will include this in an inversion matrix to get the starting $v$ values.
	init_vec_mp2(ns_config->v_patch,ns_config->num_v_vars,solve_options.T.AMP_max_prec);
	ns_config->v_patch->size = ns_config->num_v_vars;
	for (int ii=0; ii<ns_config->num_v_vars; ii++) {
		get_comp_rand_mp(&ns_config->v_patch->coord[ii]);
	}
	
	
	
	mat_mp temp_getter;  init_mat_mp2(temp_getter,0, 0,solve_options.T.AMP_max_prec);
	temp_getter->rows = 0; temp_getter->cols = 0;
	
	
	
	//the 'ns_config->starting_linears' will be used for the x variables.  we will homotope to these 1 at a time
	ns_config->starting_linears = (vec_mp **)br_malloc( randomizer->num_rand_funcs()*sizeof(vec_mp *));
	for (int ii=0; ii<randomizer->num_rand_funcs(); ii++) {
		
		int curr_degree = std::max(0,randomizer->randomized_degree(ii)-1);
		
		
		ns_config->starting_linears[ii] = (vec_mp *) br_malloc(curr_degree*sizeof(vec_mp));
		
		make_matrix_random_mp(temp_getter,curr_degree, W.num_natural_variables(), solve_options.T.AMP_max_prec); // this matrix is nearly orthogonal
		
		for (unsigned int jj=0; jj<curr_degree; jj++) {
			init_vec_mp2(ns_config->starting_linears[ii][jj],W.num_variables(),solve_options.T.AMP_max_prec);
			ns_config->starting_linears[ii][jj]->size = W.num_variables();
			
			for (int kk=0; kk<W.num_natural_variables(); kk++) {
				set_mp(&ns_config->starting_linears[ii][jj]->coord[kk], &temp_getter->entry[jj][kk]);
			}
			
			for (int kk=W.num_natural_variables(); kk<W.num_variables(); kk++) {
				set_zero_mp(&ns_config->starting_linears[ii][jj]->coord[kk]);
			}
		}
		
	}
	
	
	clear_mat_mp(temp_getter);
	
	
	
	return;
}
Beispiel #18
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;
}