Skip to content

Commit

Permalink
published
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkaliski committed Dec 10, 2012
1 parent b26b8e5 commit 06e6836
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 85 deletions.
33 changes: 17 additions & 16 deletions README.md
@@ -1,10 +1,10 @@
numeric.ly.js - an advanced mathematics toolkit for JavaScript and Node.js
Numbers - an advanced mathematics toolkit for JavaScript and Node.js
developed by Steve Kaliski, [@sjkaliski](http://twitter.com/sjkaliski)


## Description

Numeric.ly provides a comprehensive set of mathematical tools that currently are not offered in JavaScript. These tools include:
Numbers provides a comprehensive set of mathematical tools that currently are not offered in JavaScript. These tools include:

* Basic calculations
* Calculus
Expand All @@ -13,7 +13,7 @@ Numeric.ly provides a comprehensive set of mathematical tools that currently are
* Statistics
* More...

A few things to note before using: JavaScript, like many languages, does not necessarily manage floating points as well as we'd all like it to. For example, if adding decimals, the addition tool won't return the exact value. This is an unfortunate error. Precautions have been made to account for this. After including numeric, you can set an error bound. Anything in this will be considered an "acceptable outcome."
A few things to note before using: JavaScript, like many languages, does not necessarily manage floating points as well as we'd all like it to. For example, if adding decimals, the addition tool won't return the exact value. This is an unfortunate error. Precautions have been made to account for this. After including numbers, you can set an error bound. Anything in this will be considered an "acceptable outcome."

The primary uses cases are client side operations which the DOM will recognize (e.g. 1.1px == 1px). It can be used for data analysis, calculations, etc. on the server as well.

Expand All @@ -26,17 +26,18 @@ For example, if we wanted to estimate the integral of sin(x) from -2 to 4, we co
Use riemann integrals (with 200 subdivisions)

```javascript
var numbers = require('numbers');
var func = function(x) {
return Math.sin(x);
}

numeric.calculus.riemann(func, -2, 4, 200);
numbers.calculus.riemann(func, -2, 4, 200);
```

Or adaptive simpson quadrature (with epsilon .0001)

```javascript
numeric.calculus.adaptiveSimpson(func, -2, 4, .0001);
numbers.calculus.adaptiveSimpson(func, -2, 4, .0001);
```

Say we wanted to run some matrix calculations:
Expand All @@ -47,36 +48,36 @@ We can add two matrices
var array1 = [0, 1, 2];
var array2 = [3, 4, 5];

numeric.matrix.addition(array1, array2);
numbers.matrix.addition(array1, array2);
```

We can transpose a matrix

```javascript
numeric.matrix.transpose(array);
numbers.matrix.transpose(array);
```

Numeric.ly also includes some basic prime number analysis. We can check if a number is prime:

```javascript
//basic check
numeric.prime.simple(number);
numbers.prime.simple(number);

//elliptic analysis (good for huge numbers)
numeric.prime.elliptic(number);
numbers.prime.elliptic(number);
```

The statistics tools include mean, median, mode, standard deviation, random sample generator, correlation, confidence intervals, t-test, chi-square, and more.

```javascript
numeric.statistic.mean(array);
numeric.statistic.median(array);
numeric.statistic.mode(array);
numeric.statistic.standardDev(array);
numeric.statistic.randomSample(lower, upper, n);
numeric.statistic.correlation(array1, array2);
numbers.statistic.mean(array);
numbers.statistic.median(array);
numbers.statistic.mode(array);
numbers.statistic.standardDev(array);
numbers.statistic.randomSample(lower, upper, n);
numbers.statistic.correlation(array1, array2);
```
For further documentation, check out our [JSDoc](http://jsdoc.info/sjkaliski/numeric.ly/)
For further documentation, check out our [JSDoc](http://jsdoc.info/sjkaliski/numbers.js/)

## Test

Expand Down
2 changes: 1 addition & 1 deletion index.js
@@ -1 +1 @@
module.exports = require('./lib/numeric.js');
module.exports = require('./lib/numbers.js');
32 changes: 32 additions & 0 deletions lib/numbers.js
@@ -0,0 +1,32 @@
/**
* numbers.js
*
* top level management of numbers extensions
*
* (C) 2012 Steve Kaliski
* MIT License
*
*/
var numbers = exports;


// Expose methods
numbers.basic = require('./numbers/basic');
numbers.calculus = require('./numbers/calculus');
numbers.matrix = require('./numbers/matrix');
numbers.prime = require('./numbers/prime');
numbers.statistic = require('./numbers/statistic');
numbers.useless = require('./numbers/useless');

/**
* @property {Number} EPSILON Epsilon (error bound) to be used
* in calculations. Can be set and retrieved freely.
*
* Given the float-point handling by JavaScript, as well as
* the numbersal proficiency of some methods, it is common
* practice to include a bound by which discrepency between
* the "true" answer and the returned value is acceptable.
*
* If no value is provided, 0.001 is default.
*/
numbers.EPSILON = 0.001;
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/numeric/calculus.js → lib/numbers/calculus.js
@@ -1,4 +1,4 @@
var numeric = require('../numeric');
var numbers = require('../numbers');
var calculus = exports;


Expand Down Expand Up @@ -100,7 +100,7 @@ function simpsonRecursive (func, a, b, whole, eps) {
* @return {Number} area underneath curve
*/
calculus.adaptiveSimpson = function (func, a, b, eps) {
eps = (typeof eps === "undefined") ? numeric.EPSILON : eps;
eps = (typeof eps === "undefined") ? numbers.EPSILON : eps;

return simpsonRecursive(func, a, b, simpsonDef(func, a, b), eps);
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions lib/numeric.js

This file was deleted.

11 changes: 6 additions & 5 deletions package.json
@@ -1,12 +1,12 @@
{
"author": "Steve Kaliski <sjkaliski@gmail.com> (https://github.com/sjkaliski)",
"name": "numeric.ly",
"description": "Advanced mathematics library for JavaScript",
"name": "numbers",
"description": "Advanced Mathematics Library for JavaScript",
"version": "0.0.1",
"homepage": "https://github.com/sjkaliski/numeric.ly",
"homepage": "https://github.com/sjkaliski/numbers.js",
"repository": {
"type": "git",
"url": "git://github.com/sjkaliski/numeric.ly"
"url": "git://github.com/sjkaliski/numbers.js"
},
"contributors": [
"David Byrd (https://github.com/davidbyrd11)",
Expand All @@ -19,7 +19,8 @@
"keywords": [
"math",
"mathematics",
"numerical"
"numbers",
"statistics"
],
"dependencies": {
"mocha": "~1.5.0"
Expand Down
18 changes: 9 additions & 9 deletions test/basic.test.js
@@ -1,46 +1,46 @@
var assert = require('assert');
var numeric = require('../index.js');
var basic = numeric.basic;
var numbers = require('../index.js');
var basic = numbers.basic;

suite('numeric', function() {
suite('numbers', function() {

console.log('\n\n\033[34mTesting Standard Mathematics\033[0m');

// numeric.addition
// numbers.addition
test('addition should return the sum of items in an array', function (done) {
assert.equal(6, basic.addition([0,1,2,3]));
assert.equal(0, basic.addition([0,-3,5,-2]));
done();
});

// numeric.subtraction
// numbers.subtraction
test('subtraction should return the difference of items in an array', function (done) {
assert.equal(0, basic.subtraction([0,1,2,3]));
done();
});

// numeric.product
// numbers.product
test('product should return the product of items in an array', function (done) {
assert.equal(24, basic.product([1,2,3,4]));
assert.equal(-6, basic.product([-3,2]));
done();
});

// numeric.factorial
// numbers.factorial
test('factorial should return the product of n * (n - 1) * (n - 2) * ... * 1', function (done) {
assert.equal(24, basic.factorial(4));
assert.equal(120, basic.factorial(5));
done();
});

// numeric.gcd
// numbers.gcd
test('gcd should return the greatest common denominator of two integers', function (done) {
assert.equal(6, basic.gcd(1254, 5298));
assert.equal(1, basic.gcd(78699786, 78978965));
done();
});

// numeric.lcm
// numbers.lcm
test('lcm should return the least common multiple of two integers', function (done) {
assert.equal(240, basic.lcm(12, 80));
done();
Expand Down
12 changes: 6 additions & 6 deletions test/calculus.test.js
@@ -1,8 +1,8 @@
var assert = require('assert');
var numeric = require('../index.js');
var calculus = numeric.calculus;
var numbers = require('../index.js');
var calculus = numbers.calculus;

suite('numeric', function() {
suite('numbers', function() {

console.log('\n\n\033[34mTesting Calculus Mathematics\033[0m');

Expand All @@ -13,7 +13,7 @@ suite('numeric', function() {

var res = calculus.pointDiff(func, 5);

assert.equal(true, 2 - res < numeric.EPSILON);
assert.equal(true, 2 - res < numbers.EPSILON);
done();
});

Expand All @@ -35,7 +35,7 @@ suite('numeric', function() {

var res = calculus.adaptiveSimpson(func, 0, 100);

assert.equal(true, res - numeric.EPSILON < 666666.66667 < res + numeric.EPSILON);
assert.equal(true, res - numbers.EPSILON < 666666.66667 < res + numbers.EPSILON);
done();
});

Expand All @@ -46,7 +46,7 @@ suite('numeric', function() {

var res = calculus.limit(func, 10, 'middle');

assert.equal(true, res - numeric.EPSILON < 91.29 < res + numeric.EPSILON);
assert.equal(true, res - numbers.EPSILON < 91.29 < res + numbers.EPSILON);
done();
});

Expand Down
6 changes: 3 additions & 3 deletions test/matrix.test.js
@@ -1,8 +1,8 @@
var assert = require('assert');
var numeric = require('../index.js');
var matrix = numeric.matrix;
var numbers = require('../index.js');
var matrix = numbers.matrix;

suite('numeric', function() {
suite('numbers', function() {

console.log('\n\n\033[34mTesting Matrix Mathematics\033[0m');

Expand Down
6 changes: 3 additions & 3 deletions test/prime.test.js
@@ -1,8 +1,8 @@
var assert = require('assert');
var numeric = require('../index.js');
var prime = numeric.prime;
var numbers = require('../index.js');
var prime = numbers.prime;

suite('numeric', function() {
suite('numbers', function() {

console.log('\n\n\033[34mTesting Prime Number Mathematics\033[0m');

Expand Down
8 changes: 4 additions & 4 deletions test/statistic.test.js
@@ -1,8 +1,8 @@
var assert = require('assert');
var numeric = require('../index.js');
var statistic = numeric.statistic;
var numbers = require('../index.js');
var statistic = numbers.statistic;

suite('numeric', function() {
suite('numbers', function() {

console.log('\n\n\033[34mTesting Statistics Mathematics\033[0m');

Expand Down Expand Up @@ -41,7 +41,7 @@ suite('numeric', function() {

test('should return the standard deviation of an array of numbers', function(done) {
var res = statistic.standardDev([-5, -4, -1, 0, 5, 100]);
assert.equal(true, res - numeric.EPSILON < 37.777 < res + numeric.EPSILON);
assert.equal(true, res - numbers.EPSILON < 37.777 < res + numbers.EPSILON);
done();
});

Expand Down
8 changes: 4 additions & 4 deletions test/useless.test.js
@@ -1,12 +1,12 @@
var assert = require('assert');
var numeric = require('../index.js');
var useless = numeric.useless;
var numbers = require('../index.js');
var useless = numbers.useless;

suite('numeric', function() {
suite('numbers', function() {

console.log('\n\n\033[34mTesting Useless Mathematics\033[0m');

//numeric.useless.collatz
//numbers.useless.collatz
test('collatz should populate the given array with a collatz sequence', function (done) {
var result = [];
useless.collatz(7, result);
Expand Down

0 comments on commit 06e6836

Please sign in to comment.