Package Exports
- peo
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (peo) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Prime Exponent Object
(PEO, Peo class)
A Prime Exponent Object (Peo) is a JavaScript object which stores small or large rational numbers as an object of the form {2:1000, 3:-567, 65536:-1} = 2^1000 * 3^-567 * 65537^-1, i.e. as an object with keys equal to primes, and values equal to the exponent of that prime.
The class contains:
- A central data store of these primes and exponents
- Some cached data, e.g. numeric, textual or fractional representation (the latter using Fraction class from
fraction.js) - An API with many functions to manipulate the Peo.
Note that the Peo is designed to be immutable, i.e. all the API functions return a new Peo when any modification has taken place.
Install
npm install peo
Usage
var Peo = require('peo')var peo = new Peo(80, 14)console.log(peo.getText()) // "40/7"console.log(peo.getNum()) // 40console.log(peo.getDenom()) // 7console.log(peo.getVal()) // 5.7142857142857135
Test
npm testnpm run examples
API
Constructors
new Peo(a) // integer anew Peo(a, b) // fraction a/bnew Peo(a, b, n) // fraction (a/b)^nnew Peo(fr) // fr a Fraction from fraction.jsnew Peo(fr, n) // fr^nnew Peo({p1:e1, ...,pk:ek}) // equivalent to p1^e1 * ... * pk^eknew Peo({p1:e1, ...,pk:ek}, n) // equivalent to p1^(n*e1) * ... * pk^(n*ek)
These constructors have been tested up to (11/2)^1000000000 = new Peo(11, 2, 10^9)
Peo can handle large numbers! (With small-ish prime factors.)
Static or Class methods
Peo.binom(n, r) // returns 'n choose r', e.g. binomial coefficientPeo.fact(a) // returns a! = a * (a-1) * ... * 1 (Factorial function)Peo.fact(a, b) // returns a * (a-1) * ... * (a-(b-1))Peo.fact(a, b, c) // returns a * (a+c) * ... * (a+c(b-1))Peo.prim(a) // returns product of primes between 1 and aPeo.prim(a, b) // returns product of primes between a and b
Instance methods
(The underscore _ represents your own instance of Peo class)
Accessing prime exponents
_.checkPrimeExps({p1:e1,...}) // returns Boolean_.getPrimeExp(p) // returns numeric, the exponent_.getPrimeExps([p1,...]) // returns {p1:e1,...}
General functions
_.copy() // returns a copy of the original peo_.toString() // returns a text representation of the Peo (same as .getText()
Maths operations
_.get1() // returns a new identity Peo, e.g. new Peo(1)_.mult(other) // returns a new Peo which is this*other_.mult(other, n) // returns a new Peo which is this*(other^n)_.pow(n) // returns a new Peo which is this^n
Numeric values
_.getDenom() // returns the denominator of the fraction_.getFraction() // returns relevant Fraction object from fraction.js_.getNum() // returns the numerator of the fraction_.getText() // returns a text representation of the Peo_.getVal() // returns a decimal representation of the Peo
Logarithmic numeric values
_.getLog(b) // returns log of Peo to base b (if omitted, natural log)_.getLogDenom(b) // returns log of Peo denominator_.getLogNum(b) // returns log of Peo numerator
Numeric stats
_.countDistinctFactors() // returns the number of distinct prime factors of the Peo_.countFactors() // returns the total number of prime factors of the Peo_.getHighestPrime() // returns the highest prime in the Peo_.getLowestPrime() // returns the lowest prime in the Peo