示例#1
0
/* Computes p*Delta.							*
 * This will only be run once!						*/
struct polynomial compute_delta(void)
{
	int i;
	struct polynomial A, B, C;
	A.leading = NULL;
	B.leading = NULL;
	C.leading = NULL;

	A = copy_pol(myf);
	B = copy_pol(myf);
	for (i = 2; i <= p; i++)
	{
		C = pol_mult(A, B);
		free_tail(B.leading);
		B = C;
		C.leading = NULL;
		C.degree = 0;
	}
	free_tail(A.leading);
	A.leading = NULL;
	A.degree = 0;
	A = frobenius(myf);

	/* Replace A by negative. */
	times_int(-1, &A);

	/* Add -F(f) + f^p */
	C = pol_add(A, B);

	free_tail(A.leading);
	free_tail(B.leading);
	
	return(C);
}
示例#2
0
/* Warning: destroys aa! */
void test_split(struct polynomial **aa, struct polynomial orig)
{
	int i, j, aalen;
	struct polynomial tmp;
	tmp.leading = NULL;
	
	if (orig.degree != aa[0]->degree) {
		printf("Wrong degrees! Stop.");
		exit(1);
	}
	
	aalen = 1 + aa[0]->degree/d;
	
	for (i = 1; i + 1 <= aalen; i++) {
		printf(" %d \n", i);
		tmp = pol_mult(myf, *aa[i]);
		free_tail(aa[i]->leading);
		merge_add(aa[0], tmp);
		for (j = i + 1; j + 1 <= aalen; j++) {
			tmp = pol_mult(myf, *aa[j]);
			free_tail(aa[j]->leading);
			*aa[j] = tmp;
		}
	}
	times_int(-1, aa[0]);
	printf("Here is the test result: \n");
	print_pol(pol_add(*aa[0], orig));
	return;
}
示例#3
0
/* ppp does not get changed */
unsigned int
zero_on_division(struct polynomial ppp, unsigned int ss, struct polynomial **vh)
{
	struct polynomial tmp[ss];
	struct term mon;
	struct polynomial pp;
	unsigned int i, dividing, uit;
	make_scalar(mon.c);
	pp.leading = NULL;
	for (i = 0; i + 1 <= ss; i++) {
		tmp[i].leading = NULL;
	}

	pp.degree = ppp.degree;
	copy_tail(ppp.leading,&(pp.leading));
	while (pp.leading) {
		i = 0;
		dividing = 1;
		while ((i + 1<=ss) && dividing) {
			if (deelbaar(vh[i]->leading, pp.leading)) {
				/* No sign in front of ppterm->c */
				sc_div(pp.leading->c, vh[i]->leading->c, mon.c);
				/* Change sign mon.c */
				sc_negate(mon.c);
				mon.n1 = pp.leading->n1 - vh[i]->leading->n1;
				mon.n2 = pp.leading->n2 - vh[i]->leading->n2;
				mon.n3 = pp.leading->n3 - vh[i]->leading->n3;
				mon.n4 = pp.leading->n4 - vh[i]->leading->n4;
				if (tmp[i].leading) {
					times_term(mon, *(vh[i]), &(tmp[i]));
				} else {
					tmp[i] = make_times_term(mon, *(vh[i]));
				}
				rep_pol_add(&pp, tmp[i]);
				dividing = 0;
			} else {
				i = i + 1;
			}
		}
		if (dividing) {
			uit = 0;
			goto out;
		}
	}
	uit = 1;

out:
	for (i = 0; i + 1 <= ss; i++) {
		free_tail(tmp[i].leading);
	}
	free_tail(pp.leading);
	free_scalar(mon.c);
	return(uit);
}
示例#4
0
文件: trie.c 项目: hroptatyr/uterus
/**
 * @brief Free a trie object
 *
 * @param trie  : the trie object to free
 *
 * Destruct the @a trie and free its allocated memory.
 */
void
free_trie(trie_t trie)
{
	free_darray(trie->da);
	free_tail(trie->tail);
	free(trie);
	return;
}
示例#5
0
/* Scalar multiple of a split polynomial. */
void free_star(struct polynomial **bb)
{
	int i, len;

	len = 1 + bb[0]->degree/d;
	for (i = 0; i + 1 <= len; i++) {
		free_tail(bb[i]->leading);
		free(bb[i]);
	}
	return;
}
示例#6
0
int main()
{
	unsigned int nr;
	int i, retry;
	int *coeff;
	struct term *tt;
	struct polynomial uit;
	struct polynomial T;
	T.leading = NULL;
	
#ifdef KIJKEN
	printf("Debug is set! To unset do not define KIJKEN.\n");
#endif
	/* Setup the scalars. */
	setup_scalars();

	uit = make_initial_pol(d, 1);
	nr = number_terms(uit);
	coeff = (int *)malloc(nr*sizeof(int));
	for (i = 0; i + 1 <= nr; i++) {
		coeff[i] = 0;
	}
	retry = 1;
	while (retry == 1) {
		next_one(nr, coeff);
		if (is_min(nr, coeff, uit)) {
			myf = copy_pol(uit);
			tt = myf.leading;
			i = 0;
			while (tt) {
				tt->c = coeff[i];
				i++;
				tt = tt->next;
			}
			clean_pol(&myf);
			retry = setup(1);
		} else {
			retry = -1;
		}

		/* retry == 4 means quasi-smooth */
		if (retry == 4) {
			for (i = 0; i + 1 <= nr; i++) {
				printf("%d ", coeff[i]);
			}
			printf("  %d", G.len);
			printf("\n");
		}

		if (retry >= 0) {
			/* Free up G and myf. */
			free_tail(myf.leading);
			for (i = 0; i + 1 <= G.len; i++) {
				free_tail(G.ff[i]->leading);
			}
		}
		retry = 1;
	}
	
	exit(0);
}