Snippets of code

Before studying the real thing, I think it would be useful to have a look at the following toy-size programs.

Simple arithmetic with polynomials


Code:
#include "my_gmp.H"
#include "algebras.H"
#include <iostream>
using namespace std;


int main(){
	AffineAlgebra<ZZ> A;
	Polynomial<ZZ> I, x, y, P, Q;

	x= A.new_variable("X");
	y= A.new_variable("Y");
	I= A.one();
	
	P= x*x + y*x + y*5;
	Q= I + x*(-1) + y*y*y;

	cout << "P= " << P << endl
		<< "Q= " << Q << endl
		<< "and P*Q=" << P*Q << endl; 	


	return 0;
}

Output:
P= X^2 + 5Y + XY
Q= I + -1X + Y^3
and P*Q=X^2 + -1X^3 + 5Y + -4XY + -1X^2Y + X^2Y^3 + 5Y^4 + XY^4

Comments:

Quotient algebras


Code:
#include "my_gmp.H"
#include "algebras.H"
#include <iostream>
#include "ftwo.H"
using namespace std;


int main(){
	AffineAlgebra<F_2> A;
	Polynomial<F_2> I, u, x;
	//let us create the field with 4 elements:
	u= A.new_variable("u");
	I= A.one();
	A.add_relation(I + u + u*u);
	
	x= I+u;
	
	cout << "any element to the third power is 1..." << endl
		<< "and indeed (1+u)^3= " << x*x*x << endl
		<< "which is also " << A.reduced_form(x*x*x) << endl;

	return 0;
}

Output:
any element to the third power is 1...
and indeed (1+u)^3= I + u + u^2 + u^3
which is also I

Comments:

Grobner basis


Code:
#include "my_gmp.H"
#include "algebras.H"
#include <iostream>
#include "ftwo.H"
using namespace std;


int main(){
	AffineAlgebra<F_2> A;
	Polynomial<F_2> I, y, x;
	x= A.new_variable("x");
	y= A.new_variable("y");
	I= A.one();
	A.add_relation(x*x + y*y +x*y);
	A.add_relation(x*x*y + x*y*y);
	
	cout << A << endl;
	cout << "y^4=" << A.reduced_form(y*y*y*y) << endl;
	
	A.find_grobner_basis();
	
	cout << endl << A << endl;
	cout << "y^4=" << A.reduced_form(y*y*y*y) << endl;
	
	return 0;
}

Output:
generators:
x y 
relations:
x^2 + xy + y^2
x^2y + xy^2

y^4=x^3y

generators:
x y 
relations:
x^2 + xy + y^2
x^3

y^4=0

Comments:

Do algebras have elements?

No! although polynomials have a link to algebras:
Code:
#include "my_gmp.H"
#include "algebras.H"
#include <iostream>
#include "ftwo.H"
using namespace std;


int main(){
	AffineAlgebra<ZZ> A;
	Polynomial<ZZ> I, y, x;
	x= A.new_variable("x");
	y= A.new_variable("y");
	
	AffineAlgebra<ZZ> B;
	Polynomial<ZZ> J, u, v;
	u= B.new_variable("u");
	v= B.new_variable("v");
	
	Polynomial<ZZ> P;
	P= x*x + y*4 + x*y*2;
	
	cout << "P= " << P << endl;
	P.alphabet= &B;
	cout << "and now P= " << P << endl;
	
	return 0;
}

Output:
P= x^2 + 4y + 2xy
and now P= u^2 + 4v + 2uv


Comments:

Copying algebras

When copying an algebra is needed, you will see the following sort of code (context as in the previous program):
Code:
	B= A;
	B.fix_alphabets();

Comments: