Ejemplo n.º 1
0
void unipoly::copyobject_to(base &x)
{
#ifdef COPY_VERBOSE
	cout << "unipoly::copyobject_to()\n";
	print_as_vector(cout);
#endif
	Vector::copyobject_to(x);
	x.as_unipoly().settype_unipoly();
#ifdef COPY_VERBOSE
	x.as_unipoly().print_as_vector(cout);
#endif
}
Ejemplo n.º 2
0
void unipoly::add_to(base &x, base &y)
{
	unipoly& px = x.as_unipoly();
	unipoly py;
	base a;
	INT d1, d2, d3, i;
	
	if (s_kind() != UNIPOLY) {
		cout << "unipoly::add_to() this not a unipoly\n";
		exit(1);
		}
	if (x.s_kind() != UNIPOLY) {
		cout << "unipoly::add_to() x is not a unipoly\n";
		exit(1);
		}
	d1 = degree();
	d2 = px.degree();
	d3 = MAXIMUM(d1, d2);
	
	py.m_l(d3 + 1);
	a = s_i(0);
	a.zero();
	for (i = 0; i <= d1; i++) {
		py[i] = s_i(i);
		}
	for (; i <= d3; i++) {
		py[i] = a;
		}
	for (i = 0; i <= d2; i++) {
		py[i] += px.s_i(i);
		}
	py.swap(y);
}
Ejemplo n.º 3
0
void unipoly::mult_to(base &x, base &y)
{
	unipoly& px = x.as_unipoly();
	unipoly py;
	base a;
	INT d1, d2, d3, i, j, k;
	
	if (s_kind() != UNIPOLY) {
		cout << "unipoly::mult_to() this not a unipoly\n";
		exit(1);
		}
	if (x.s_kind() != UNIPOLY) {
		cout << "unipoly::mult_to() x is not a unipoly\n";
		exit(1);
		}
	d1 = degree();
	d2 = px.degree();
	d3 = d1 + d2;
	
	py.m_l(d3 + 1);
	a = s_i(0);
	a.zero();
	for (i = 0; i <= d3; i++) {
		py[i] = a;
		}
	for (i = 0; i <= d1; i++) {
		for (j = 0; j <= d2; j++) {
			k = i + j;
			a.mult(s_i(i), px.s_i(j));
			py[k] += a;
			}
		}
	py.swap(y);
}
Ejemplo n.º 4
0
void unipoly::normalize(base &p)
{
	if (p.s_kind() != UNIPOLY) {
		cout << "unipoly::normalize() p not an UNIPOLY" << endl;
		exit(1);
		}
	unipoly p1 = p.as_unipoly();
	unipoly q, r;
	
	integral_division(p1, q, r, 0); 
	swap(r);
}
Ejemplo n.º 5
0
INT unipoly::compare_with_euklidean(base &a)
{
	INT d1, d2;
	unipoly &pa = a.as_unipoly();
	
	d1 = degree();
	d2 = pa.degree();
	if (d1 < d2)
		return -1;
	else if (d1 > d2)
		return 1;
	return 0;
}
Ejemplo n.º 6
0
void unipoly::integral_division(base &x, base &q, base &r, INT verbose_level)
{
	INT f_v = (verbose_level >= 1);
	INT dm, dn, dq, i, j, ii, jj;
	base a, av, b, bav, c;
	unipoly &n = x.as_unipoly();
	unipoly qq, rr;
	
	if (f_v) {
		cout << "unipoly::integral_division" << endl;
		cout << "m=" << *this << endl;
		cout << "n=" << x << endl;
		}
	dm = degree();
	dn = n.degree();
	if (dn == 0) {
		if (n[0].is_zero()) {
			cout << "unipoly::integral_division(): division by zero" << endl;
			exit(1);
			}
		}
	if (dn > dm) {
		if (f_v) {
			cout << "unipoly::integral_division dn > dm, no division possible" << endl;
			}
		qq.zero();
		rr = *this;
		qq.swap(q);
		rr.swap(r);
		return;
		}
	dq = dm - dn;
	qq.m_l(dq + 1);
	rr = *this;
	// cout << "rr=" << rr << endl;
	a = n[dn];
	if (f_v) {
		cout << "unipoly::integral_division a=" << a << endl;
		}
	av = a;
	av.invert();
	if (f_v) {
		cout << "unipoly::integral_division av=" << av << endl;
		}
	for (i = dm, j = dq; i >= dn; i--, j--) {
		if (f_v) {
			cout << "unipoly::integral_division i=" << i << " j=" << j << endl;
			}

		b = rr[i];
		if (f_v) {
			cout << "unipoly::integral_division b=" << b << endl;
			cout << "unipoly::integral_division av=" << av << endl;
			cout << "unipoly::integral_division before mult" << endl;
			}

		bav.mult(b, av);
		qq[j] = bav;
		// cout << "i=" << i << " bav=" << bav << endl;
		for (ii = i, jj = dn; jj >= 0; ii--, jj--) {
			if (f_v) {
				cout << "unipoly::integral_division ii=" << ii << " jj=" << jj << endl;
				}
			c = n[jj];
			c *= bav;
			c.negate();
			rr[ii] += c; // rr[ii] -= bav * this[jj]
			if (ii == i && !rr[ii].is_zero()) {
				cout << "unipoly::integral_division(): ii == i && !rr[ii].is_zero()\n";
				exit(1);
				}
			// cout << "c=" << c << endl;
			// cout << "rr[ii]=" << rr[ii] << endl;
			}
		// cout << "i=" << i << " rr=" << rr << endl;
		}
	qq.swap(q);
	rr.swap(r);
	if (f_v) {
		cout << "q=" << q << endl;
		cout << "r=" << r << endl;
		}
}