✻ Legend ✻
Rye — is a JavaScript library that allows to work with finite (Galois) fields. With Rye you can construct prime fields as well as build extension of existing field. And yes, you can use it in your browser!
✻ How to use? ✻
First, construct a prime field:
// When using with Node.js you have to add:
// var PrimeField = require('rye').PrimeField;
var field = new PrimeField(7);
// Fields have + and * operations
field.add(5, 4); // = 2
field.mul(2, 6); // = 5
// Fields have 1 and 0
field.add(field.nullElement(), 3); // = 3
field.mul(field.oneElement(), 5); // = 5
// Opposite element, inverse element, etc.
field.opp(3); // = 4
field.inv(3); // = 5
Now, make a polynomial ring based on this field:
var ring = new PolynomRing(field);
// Construct polynomials
var polynom = ring.polynom([3, 0, 4]); // 3 + 4x^2
var nullPolynom = ring.polynom(); // 0
// Each polynomial has a degree
polynom.degree(); // = 2
nullPolynom.degree(); // = -Infinity
// You can add, multiply, divide polynomials
ring.add(polynom, ring.polynom([5, 1])); // = [1, 1, 4]
ring.mod(polynom, nullPolynom); // Exception: division by zero!
Finally, extend your field by factorizing ring using irreducible polynomial:
var extField = new FactorRing(ring, ring.polynom([3, 1, 2]));
// This structure is also a field (of course, if the polynomial
// is irreducible, otherwise it is a ring)
var extFieldOrder = extField.order; // == 7^2
✻ Demo ✻
You can see the library in action in this demo. MathJax library is used for rendering formulas.
✻ Specs ✻
Check this out! The library's code is well test-covered (in fact, spec-covered). Mocha test framework is used for tests.
✻ I want it! ✻
There is no need to clone github repo. You can use the library right now!
Node.js version is also available:
npm install rye