Repository: josdejong/mathjs
Pull request #380 (2015-05-26 07:36:39)

Added intersection function
Computes:
- Line and line intersection in 2D and 3D
- Line and plane intersection in 3D

Also created folder `geometry` for `intersect.js`


Patch:
diff --git a/HISTORY.md b/HISTORY.md
index 6897284f7..d541f59d0 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,15 +1,8 @@
 # History
 
 
-## not yet released, version 1.7.1-SNAPSHOT
+## not yet released, version 1.6.1-SNAPSHOT
 
-- Improved the performance of `median` (see #373). Thanks @BigFav.
-
-
-## 2015-05-14, version 1.7.0
-
-- Implemented function `quantileSeq` and `partitionSelect`. Thanks @BigFav.
-- Implemented functions `stirlingS2` and `bellNumbers`. Thanks @devanp92.
 - Extended the command line interface with a `mode` option to output either
   the expressions result, string representation, or tex representation.
   Thanks @FSMaxB.
diff --git a/docs/chaining.md b/docs/chaining.md
index a97272e54..98ee51eee 100644
--- a/docs/chaining.md
+++ b/docs/chaining.md
@@ -4,7 +4,7 @@ Math.js supports chaining operations by wrapping a value into a `Chain`.
 A chain can be created with the function `math.chain(value)`
 (formerly `math.select(value)`).
 All functions available in the math namespace can be executed via the chain.
-The functions will be executed with the chain's value as the first argument,
+The functions will be executed with the chain's value as first argument,
 followed by extra arguments provided by the function call itself.
 
 ```js
diff --git a/docs/datatypes/bignumbers.md b/docs/datatypes/bignumbers.md
index 8bf4fb6bb..f36474cde 100644
--- a/docs/datatypes/bignumbers.md
+++ b/docs/datatypes/bignumbers.md
@@ -1,7 +1,7 @@
 # BigNumbers
 
 For calculations with an arbitrary precision, math.js supports a `BigNumber`
-datatype. BigNumber support is powered by
+data type. BigNumber support is powered by
 [decimal.js](https://github.com/MikeMcl/decimal.js/).
 
 ## Usage
@@ -63,7 +63,7 @@ math.divide(math.bignumber(0.3), math.bignumber(0.2));  // BigNumber, 1.5
 It's important to realize that BigNumbers do not solve *all* problems related
 to precision and round-off errors. Numbers with an infinite number of digits
 cannot be represented with a regular number nor a BigNumber. Though a BigNumber
-can store a much larger number of digits, the amount of digits remains limited
+can store a much larger number of digits, the amount of digits remains limited,
 if only to keep calculations fast enough to remain practical.
 
 ```js
diff --git a/docs/datatypes/complex_numbers.md b/docs/datatypes/complex_numbers.md
index d0e8a507c..099617c80 100644
--- a/docs/datatypes/complex_numbers.md
+++ b/docs/datatypes/complex_numbers.md
@@ -1,9 +1,9 @@
 # Complex Numbers
 
-Math.js supports the creation, manipulation, and calculations with complex numbers.
+Math.js supports creation, manipulation, and calculations with complex numbers.
 
 In mathematics, a complex number is an expression of the form `a + bi`,
-where `a` and `b` are real numbers and `i` represents the imaginary number
+where `a` and `b` are real numbers, and `i` represents the imaginary number
 defined as `i^2 = -1`. (In other words, `i` is the square root of `-1`.)
 The real number `a` is called the real part of the complex number,
 and the real number `b` is the imaginary part. For example, `3 + 2i` is a
@@ -57,7 +57,7 @@ The properties `re` and `im` of a complex number can be read and replaced.
 A `Complex` object has the following functions:
 
 - `clone()`. Create a clone of the complex number.
-- `equals(other)`. Test whether a complex number equals another complex value.
+- `equals(other)`. Test whether a complex number equals an other complex value.
   Two complex numbers are equal when both their real and imaginary parts are
   equal.
 - `format([precision: number])`. Get a string representation of the complex number,
diff --git a/docs/datatypes/matrices.md b/docs/datatypes/matrices.md
index c34867679..70deb19ea 100644
--- a/docs/datatypes/matrices.md
+++ b/docs/datatypes/matrices.md
@@ -46,7 +46,8 @@ math.ones(2, 3);                              // Matrix, [[1, 1, 1], [1, 1, 1]]
 ## Creation
 
 A matrix can be created from an array using the function `math.matrix`. The
-provided array can contain nested arrays in order to create a multi-dimensional matrix. When called without arguments, an empty matrix will be
+provided array can contain nested arrays in order to create a multi
+dimensional matrix. When called without arguments, an empty matrix will be
 created.
 
 ```js
@@ -151,9 +152,9 @@ math.det(d);                              // 23
 
 Math.js uses geometric dimensions:
 
-- A scalar is zero-dimensional.
-- A vector is one-dimensional.
-- A matrix is two or multi-dimensional.
+- A scalar is zero dimensional.
+- A vector is one dimensional.
+- A matrix is two or multi dimensional.
 
 The size of a matrix can be calculated with the function `size`. Function `size`
 returns a `Matrix` or `Array`, depending on the configuration option `matrix`.
@@ -166,11 +167,11 @@ math.size(2.4);                               // Matrix, []
 math.size(math.complex(3, 2));                // Matrix, []
 math.size(math.unit('5.3 mm'));               // Matrix, []
 
-// get the size of a one-dimensional matrix (a vector) and a string
+// get the size of a one dimensional matrix (a vector) and a string
 math.size([0, 1, 2, 3]);                      // Array, [4]
 math.size('hello world');                     // Matrix, [11]
 
-// get the size of a two-dimensional matrix
+// get the size of a two dimensional matrix
 var a = [[0, 1, 2, 3]];                       // Array
 var b = math.matrix([[0, 1, 2], [3, 4, 5]]);  // Matrix
 math.size(a);                                 // Array, [1, 4]
@@ -179,7 +180,7 @@ math.size(b);                                 // Matrix, [2, 3]
 // matrices have a function size (always returns an Array)
 b.size();                                     // Array, [2, 3]
 
-// get the size of a multi-dimensional matrix
+// get the size of a multi dimensional matrix
 var c = [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]];
 math.size(c);                                 // Array, [2, 2, 3]
 ```
@@ -188,9 +189,9 @@ math.size(c);                                 // Array, [2, 2, 3]
 ## Resizing
 
 Matrices can be resized using their `resize` function. This function is called
-with an Array with the new size as the first argument, and accepts an optional
+with an Array with the new size as first argument, and accepts an optional
 default value. If no default value is provided, new entries will be filled with
-zero. To leave new entries uninitialized, specify `math.uninitialized` as the
+zero. To leave new entries uninitialized, specify `math.uninitialized` as 
 default value.
 
 ```js
@@ -316,7 +317,7 @@ Math.js supports both dense matrices as well as sparse matrices. Sparse matrices
 
 Math.js supports three type of matrices:
 
-- Dense matrix (`'dense'`, `default`) A regular, dense matrix, supporting multi-dimensional matrices. This is the default matrix type.
+- Dense matrix (`'dense'`, `default`) A regular, dense matrix, supporting multi dimensional matrices. This is the default matrix type.
 - Compressed row storage (`'crs'`): A two dimensional sparse matrix implementation.
 - Compressed column storage (`'ccs'`): A two dimensional sparse matrix implementation.
 
diff --git a/docs/datatypes/numbers.md b/docs/datatypes/numbers.md
index 0a828a1ca..18a086995 100644
--- a/docs/datatypes/numbers.md
+++ b/docs/datatypes/numbers.md
@@ -2,8 +2,8 @@
 
 Math.js supports two types of numbers:
 
-- Number for fast floating point arithmetic described on this page.
-- BigNumber for arbitrary precision arithmetic described on the page
+- Number for fast floating point arithmetic, described on this page.
+- BigNumber for arbitrary precision arithmetic, describe on the page
   [BigNumbers](bignumbers.md).
 
 ## Configuration
@@ -26,7 +26,7 @@ Math.js uses the built-in JavaScript Number type. A Number is a floating point
 number with a limited precision of 64 bits, about 16 digits. The largest integer
 number which can be represented by a JavaScript Number
 is `+/- 9007199254740992` (`+/- 2^53`). Because of the limited precision of
-floating point numbers round-off errors can occur during calculations.
+floating point numbers, round-off errors can occur during calculations.
 This can be easily demonstrated:
 
 ```js
@@ -36,7 +36,7 @@ math.add(0.1, 0.2);   // 0.30000000000000004
 ```
 
 In most cases, round-off errors don't matter: they have no significant
-impact on the results. However, it looks ugly when displaying output to a user.
+impact on the results. However it looks ugly when displaying output to a user.
 A solution is to limit the precision just below the actual precision of 16
 digits in the displayed output:
 
diff --git a/docs/expressions/customization.md b/docs/expressions/customization.md
index 6dc28193a..c680e94a5 100644
--- a/docs/expressions/customization.md
+++ b/docs/expressions/customization.md
@@ -10,7 +10,7 @@ return value by writing a *transform* for the function. A transform is a
 function wrapping around a function to be transformed or completely replaces
 a function.
 
-For example, the functions for math.js use zero-based matrix indices (as is
+For example, the functions or math.js use zero-based matrix indices (as is
 common in programing languages), but the expression parser uses one-based
 indices. To enable this, all functions dealing with indices have a transform,
 which changes input from one-based to zero-based, and transforms output (and
diff --git a/docs/expressions/index.md b/docs/expressions/index.md
index 61674fd3c..c20246623 100644
--- a/docs/expressions/index.md
+++ b/docs/expressions/index.md
@@ -5,7 +5,7 @@ The parser supports all data types, functions and constants available in math.js
 
 Whilst the math.js library is aimed at JavaScript developers, the expression
 parser is aimed at end users: mathematicians, engineers, students, pupils.
-The syntax of the expression parser differs from JavaScript and the low-level
+The syntax of the expression parser differs from JavaScript and the low level
 math.js library.
 
 This section is divided in the following pages:
diff --git a/docs/expressions/parsing.md b/docs/expressions/parsing.md
index 54d8ceba0..db12d8fcb 100644
--- a/docs/expressions/parsing.md
+++ b/docs/expressions/parsing.md
@@ -21,7 +21,7 @@ math.eval([expr1, expr2, expr3, ...], scope)
 ```
 
 Function `eval` accepts a single expression or an array with
-expressions as the first argument and has an optional second argument
+expressions as first argument, and has an optional second argument
 containing a scope with variables and functions. The scope is a regular
 JavaScript Object. The scope will be used to resolve symbols, and to write
 assigned variables or function.
@@ -58,7 +58,7 @@ math.compile([expr1, expr2, expr3, ...]);
 ```
 
 Function `compile` accepts a single expression or an array with
-expressions as the argument. Function `compile` returns an object with a function
+expressions as argument. Function `compile` returns an object with a function
 `eval([scope])`, which can be executed to evaluate the expression against an
 (optional) scope:
 
@@ -92,7 +92,7 @@ math.parse([expr1, expr2, expr3, ...])
 ```
 
 Function `parse` accepts a single expression or an array with
-expressions as the argument. Function `parse` returns a the root node of the tree,
+expressions as argument. Function `parse` returns a the root node of the tree,
 which can be successively compiled and evaluated:
 
 ```js
diff --git a/docs/expressions/syntax.md b/docs/expressions/syntax.md
index 7bac66f51..af0158a4a 100644
--- a/docs/expressions/syntax.md
+++ b/docs/expressions/syntax.md
@@ -148,7 +148,7 @@ parser.eval('g(2, 3)'); // 8
 
 ## Constants and variables
 
-Math.js has a number of built-in constants such as `pi` and `e`.
+Math.js has a number of built in constants such as `pi` and `e`.
 All available constants are listed on he page
 [Constants](../constants.md).
 
@@ -259,7 +259,7 @@ Math.js supports BigNumbers for calculations with an arbitrary precision.
 The pros and cons of Number and BigNumber are explained in detail on the page
 [Numbers](../datatypes/numbers.md).
 
-BigNumbers are slower but have a higher precision. Calculations with big
+BigNumbers are slower, but have a higher precision. Calculations with big
 numbers are supported only by arithmetic functions.
 
 BigNumbers can be created using the `bignumber` function:
@@ -390,9 +390,9 @@ math.eval('eval("2 + 3")'); // 5
 
 Matrices can be created by entering a series of values between square brackets,
 elements are separated by a comma `,`.
-A matrix like `[1, 2, 3]` will create a vector, a 1-dimensional matrix with
-size `[3]`. To create a multi-dimensional matrix, matrices can be nested into
-each other. For easier creation of two-dimensional matrices, a semicolon `;`
+A matrix like `[1, 2, 3]` will create a vector, a 1 dimensional matrix with
+size `[3]`. To create a multi dimensional matrix, matrices can be nested into
+each other. For easier creation of two dimensional matrices, a semicolon `;`
 can be used to separate rows in a matrix.
 
 ```js
@@ -405,7 +405,7 @@ math.eval('[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]');    // Matrix, size [2, 2, 2]
 math.eval('[1, 2, 3; 4, 5, 6]');                      // Matrix, size [2, 3]
 ```
 
-Another way to create filled matrices is using the functions `zeros`, `ones`,
+An other way to create filled matrices is using the functions `zeros`, `ones`,
 `eye`, and `range`.
 
 ```js
@@ -422,15 +422,15 @@ math.eval('1:4');             // Matrix, [1, 2, 3, 4],              size [4]
 math.eval('0:2:10');          // Matrix, [0, 2, 4, 6, 8, 10],       size [6]
 ```
 
-A subset can be retrieved from a matrix using indexes and a subset of a matrix
+A subset can be retrieved from a matrix using indexes, and a subset of a matrix
 can be replaced by using indexes. Indexes are enclosed in square brackets, and
 contain a number or a range for each of the matrix dimensions. A range can have
-its start and/or end undefined. When the start is undefined, the range will start
-at 1, when the end is undefined, the range will end at the end of the matrix.
+its start and/or end undefined. When start is undefined, the range will start
+at 1, when end is undefined, the range will end at the end of the matrix.
 There is a context variable `end` available as well to denote the end of the
 matrix.
 
-*IMPORTANT: matrix indexes and ranges work differently from the math.js indexes
+*IMPORTANT: matrix indexes and ranges work different from the math.js indexes
 in JavaScript: They are one-based with an included upper-bound, similar to most
 math applications.*
 
@@ -456,19 +456,19 @@ parser.eval('c[end - 1 : -1 : 2]');   // Matrix, [8, 7, 6]
 ```
 
 
-## Multi-line expressions
+## Multi line expressions
 
 An expression can contain multiple lines, and expressions can be spread over
 multiple lines. Lines can be separated by a newline character `\n` or by a
-semicolon `;`. Output of statements followed by a semicolon will be hidden from
+semicolon `;`. Output of statements followed by a semicolon will be hided from
 the output, and empty lines are ignored. The output is returned as a `ResultSet`,
 with an entry for every visible statement.
 
 ```js
-// a multi-line expression
+// a multi line expression
 math.eval('1 * 3 \n 2 * 3 \n 3 * 3');   // ResultSet, [3, 6, 9]
 
-// semicolon statements are hidden from the output
+// semicolon statements are hided from the output
 math.eval('a=3; b=4; a + b \n a * b');  // ResultSet, [7, 12]
 
 // single expression spread over multiple lines
@@ -509,7 +509,7 @@ math.eval('2 + 3i');          // Complex, 2 + 3i
 
 ## Comments
 
-Comments can be added to explain or describe calculations in the text. A comment
+Comments can be added to explain or describe calculations in text. A comment
 starts with a sharp sign character `#`, and ends at the end of the line. A line
 can contain a comment only, or can contain an expression followed by a comment.
 
diff --git a/docs/extension.md b/docs/extension.md
index 5e45f5ea6..9452fa01c 100644
--- a/docs/extension.md
+++ b/docs/extension.md
@@ -20,7 +20,7 @@ argument can be an object with options. The following options are available:
   If true, the functions will be wrapped in a wrapper function which
   converts data types like Matrix to primitive data types like Array.
   The wrapper is needed when extending math.js with libraries which do not
-  support the math.js data types. The default value is false.
+  support the math.js data types. Default value is false.
 
 Math.js can be extended with functions and variables:
 
diff --git a/docs/reference/functions/bellNumbers.md b/docs/reference/functions/bellNumbers.md
deleted file mode 100644
index 5c033f0c7..000000000
--- a/docs/reference/functions/bellNumbers.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Function bellNumbers
-
-Calculate the Bell Number for an `n` element set.
-
-## Syntax
-
-```js
-math.bellNumbers(n)
-```
-
-### Parameters
-
-Parameter | Type | Description
---------- | ---- | -----------
-`n` | Number &#124; BigNumber | Function input
-
-### Returns
-
-Type | Description
----- | -----------
-Number &#124; BigNumber | The number of ways to partition a set of n elements.
-
-
-## Examples
-
-```js
-math.bellNumbers(5);           // returns Number 52
-math.bellNumbers(math.bignumber(10)); // returns Number 115975
-```
-
-
-## See also
-
-[combinations](combinations.md),
-[stirlingS2](stirlingS2.md)
-
-
-<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
diff --git a/docs/reference/functions/composition.md b/docs/reference/functions/composition.md
deleted file mode 100644
index 31dc7c238..000000000
--- a/docs/reference/functions/composition.md
+++ /dev/null
@@ -1,40 +0,0 @@
-# Function composition
-
-Calculate the number of ways to split `n` into `k` nonempty parts.
-
-## Syntax
-
-```js
-math.composition(n, k)
-```
-
-### Parameters
-
-Parameter | Type | Description
---------- | ---- | -----------
-`n` | Number &#124; BigNumber |  Total number of objects
-`k` | Number &#124; BigNumber |  Number of objects in the subset
-
-### Returns
-
-Type | Description
----- | -----------
-Number &#124; BigNumber | The number of ways to split a set of n elements into k nonempty sets.
-
-
-## Examples
-
-```js
-math.composition(8, 3);           // returns Number 21
-math.composition(math.bignumber(70), math.bignumber(3)); // returns Number 2346
-```
-
-
-## See also
-
-[combinations.js](combinations.md),
-[stirlingS2.js](stirlingS2.md),
-[bellNumbers.js](bellNumbers.md)
-
-
-<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
diff --git a/docs/reference/functions/stirlingS2.md b/docs/reference/functions/stirlingS2.md
deleted file mode 100644
index 68c5cbf1a..000000000
--- a/docs/reference/functions/stirlingS2.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Function stirlingS2
-
-Calculate the Stirling number of the second kind for partitioning a set of n elements into k nonempty sets.
-
-## Syntax
-
-```js
-math.stirlingS2(n, k)
-```
-
-### Parameters
-
-Parameter | Type | Description
---------- | ---- | -----------
-`n` | Number &#124; BigNumber |  Function input
-`k` | Number &#124; BigNumber |  Function input
-
-### Returns
-
-Type | Description
----- | -----------
-Number &#124; BigNumber | The number of ways to partition a set of n elements into k nonempty sets.
-
-
-## Examples
-
-```js
-math.stirlingS2(5, 2);           // returns Number 15
-math.stirlingS2(math.bignumber(10), math.bignumber(4)); // returns Number 34105
-```
-
-
-## See also
-
-[combinations.js](combinations.md)
-
-
-<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
diff --git a/lib/expression/docs/function/geometry/intersect.js b/lib/expression/docs/function/geometry/intersect.js
new file mode 100644
index 000000000..40b10697a
--- /dev/null
+++ b/lib/expression/docs/function/geometry/intersect.js
@@ -0,0 +1,14 @@
+module.exports = {
+  'name': 'intersect',
+  'category': 'Geometry',
+  'syntax': [
+    'intersect(expr1, expr2, expr3, expr4)',
+    'intersect(expr1, expr2, expr3)'
+  ],
+  'description': 'Computes the intersection point of lines and/or planes.',
+  'examples': [
+    'intersect([0, 0], [10, 10], [10, 0], [0, 10])',
+    'intersect([1, 0, 1],  [4, -2, 2], [1, 1, 1, 6])'
+  ],
+  'seealso': []
+};
diff --git a/lib/expression/docs/index.js b/lib/expression/docs/index.js
index 1f9e0b95e..f0ce36788 100644
--- a/lib/expression/docs/index.js
+++ b/lib/expression/docs/index.js
@@ -78,6 +78,9 @@ exports.unit = require('./function/construction/unit');
 exports['eval'] =  require('./function/expression/eval');
 exports.help =  require('./function/expression/help');
 
+// functions - geometry
+exports.intersect = require('./function/geometry/intersect');
+
 // functions - logical
 exports['and'] = require('./function/logical/and');
 exports['not'] = require('./function/logical/not');
diff --git a/lib/function/geometry/intersect.js b/lib/function/geometry/intersect.js
new file mode 100644
index 000000000..c07cd6064
--- /dev/null
+++ b/lib/function/geometry/intersect.js
@@ -0,0 +1,134 @@
+'use strict';
+
+module.exports = function(math) {
+  var array = require('../../util/array');
+  var Matrix = math.type.Matrix;
+
+  /**
+  * Calculates the point of intersection of two lines in two or three dimensions
+  * and of a line and a plane in three dimensions. The inputs are in the form of
+  * arrays or 1 dimensional matrices. The line intersection functions return null
+  * if the lines do not meet.
+  *
+  * Syntax:
+  *
+  *	math.intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)
+  *	math.intersect(endPoint1, endPoint2, planeCoefficients)
+  *
+  * Examples:
+  *
+  *    math.intersect([0, 0], [10, 10], [10, 0], [0, 10]);              // Returns [5, 5]
+  *    math.intersect([0, 0, 0], [10, 10, 0], [10, 0, 0], [0, 10, 0]);  // Returns [5, 5, 0]
+  *    math.intersect([1, 0, 1],  [4, -2, 2], [1, 1, 1, 6]);            // Returns [7, -4, 3]
+  *
+  * Caveats:
+  *	Fill the plane coefficients as 'x + y + z = c' and not as 'x + y + z + c = 0'
+  *
+  * @param  {Array | Matrix} w   Co-ordinates of first end-point of first line
+  * @param  {Array | Matrix} x   Co-ordinates of second end-point of first line
+  * @param  {Array | Matrix} y   Co-ordinates of first end-point of second line
+  *                              OR Co-efficients of the plane's equation
+  * @param  {Array | Matrix} z   Co-ordinates of second end-point of second line
+  *                              OR null if the calculation is for line and plane
+  * @return {Array}              Returns the point of intersection of lines/lines-planes
+  */
+  math.intersect = function intersect(w, x, y, z) {
+    //check for correct type and modify it accordingly
+    if (w instanceof Matrix) {
+      w = w.toArray();
+    }
+    else if (x instanceof Matrix) {
+      x = x.toArray();
+    }
+    else if (y instanceof Matrix) {
+      y = y.toArray();
+    }
+    else if (z instanceof Matrix) {
+      z = z.toArray();
+    }
+
+    if (!(Array.isArray(w) || Array.isArray(x) || Array.isArray(y) || Array.isArray(z))){
+      throw new math.error.UnsupportedTypeError('intersect', math['typeof'](w), math['typeof'](x), math['typeof'](y), math['typeof'](z));
+    }
+    
+    //decide which function to call based on type of arguments
+    switch (arguments.length) {
+      case 3:
+        if(arguments[0].length === 3 && arguments[1].length === 3 && arguments[2].length === 4){
+          return _intersectLinePlane(arguments[0][0], arguments[0][1], arguments[0][2], arguments[1][0], arguments[1][1], arguments[1][2], arguments[2][0], arguments[2][1], arguments[2][2], arguments[2][3]);
+        }
+        else{
+          throw new TypeError('Arguments are not correct');
+        }
+        break;
+      case 4:
+        var is2D = (arguments[0].length === 2 && arguments[1].length === 2 && arguments[2].length === 2 && arguments[3].length === 2);
+        var is3D = (arguments[0].length === 3 && arguments[1].length === 3 && arguments[2].length === 3 && arguments[3].length === 3);
+        if (is2D){
+          return _intersect2d(arguments[0][0], arguments[0][1], arguments[1][0], arguments[1][1], arguments[2][0], arguments[2][1], arguments[3][0], arguments[3][1]);
+          break;
+        }
+        else if(is3D){
+          return _intersect3d(arguments[0][0], arguments[0][1], arguments[0][2], arguments[1][0], arguments[1][1], arguments[1][2], arguments[2][0], arguments[2][1], arguments[2][2], arguments[3][0], arguments[3][1], arguments[3][2]);
+          break
+        }
+      default:
+        throw new math.error.ArgumentsError('intersect', arguments.length, 3, 4);
+      }
+    };
+
+  function _intersect2d(x1, y1, x2, y2, x3, y3, x4, y4){
+    var d1343 = (x1 - x3)*(x4 - x3) + (y1 - y3)*(y4 - y3);
+    var d4321 = (x4 - x3)*(x2 - x1) + (y4 - y3)*(y2 - y1);
+    var d1321 = (x1 - x3)*(x2 - x1) + (y1 - y3)*(y2 - y1);
+    var d4343 = (x4 - x3)*(x4 - x3) + (y4 - y3)*(y4 - y3);
+    var d2121 = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
+    var ta = ( d1343*d4321 - d1321*d4343 ) / ( d2121*d4343 - d4321*d4321 );
+    var tb = ( d1343 + ta * d4321 ) / (d4343);
+   
+    var pax = x1 + ta * (x2 - x1);
+    var pay = y1 + ta * (y2 - y1);
+    var pbx = x3 + tb * (x4 - x3);
+    var pby = y3 + tb * (y4 - y3);
+    if (pax === pbx && pay === pby){
+      return [pax, pay];
+    }
+    else{
+      return null;
+    }
+  }
+
+  function _intersect3d(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4){
+    var d1343 = (x1 - x3)*(x4 - x3) + (y1 - y3)*(y4 - y3) + (z1 - z3)*(z4 - z3);
+    var d4321 = (x4 - x3)*(x2 - x1) + (y4 - y3)*(y2 - y1) + (z4 - z3)*(z2 - z1);
+    var d1321 = (x1 - x3)*(x2 - x1) + (y1 - y3)*(y2 - y1) + (z1 - z3)*(z2 - z1);
+    var d4343 = (x4 - x3)*(x4 - x3) + (y4 - y3)*(y4 - y3) + (z4 - z3)*(z4 - z3);
+    var d2121 = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1) + (z2 - z1)*(z2 - z1);
+    var ta = ( d1343*d4321 - d1321*d4343 ) / ( d2121*d4343 - d4321*d4321 );
+    var tb = ( d1343 + ta * d4321 ) / (d4343);
+    
+    var pax = x1 + ta * (x2 - x1);
+    var pay = y1 + ta * (y2 - y1);
+    var paz = z1 + ta * (z2 - z1);
+    var pbx = x3 + tb * (x4 - x3);
+    var pby = y3 + tb * (y4 - y3);
+    var pbz = z3 + tb * (z4 - z3);
+    if (pax === pbx && pay === pby && paz === pbz){
+      return [pax, pay, paz];
+    }
+    else{
+      return null;
+    }
+  }
+  
+  function _intersectLinePlane(x1, y1, z1, x2, y2, z2, x, y, z, c){
+    var t = (c - x1*x - y1*y - z1*z)/(x2*x + y2*y + z2*z - x1 - y1 - z1);
+    var px = x1 + t * (x2 - x1);
+    var py = y1 + t * (y2 - y1);
+    var pz = z1 + t * (z2 - z1);
+    return [px, py, pz];
+    // TODO: Add cases when line is parallel to the plane:
+    //       (a) no intersection,
+    //       (b) line contained in plane
+  }
+}
\ No newline at end of file
diff --git a/lib/function/statistics/median.js b/lib/function/statistics/median.js
index ad68d35bc..bd9282b9d 100644
--- a/lib/function/statistics/median.js
+++ b/lib/function/statistics/median.js
@@ -45,7 +45,7 @@ module.exports = function (math) {
     if (isCollection(args)) {
       if (arguments.length == 1) {
         // median([a, b, c, d, ...])
-        return _median(args.valueOf(), false);
+        return _median(args.valueOf());
       }
       else if (arguments.length == 2) {
         // median([a, b, c, d, ...], dim)
@@ -59,43 +59,31 @@ module.exports = function (math) {
     }
     else {
       // median(a, b, c, d, ...)
-      var argArr = new Array(arguments.length);
-      for (var i = 0; i < argArr.length; ++i) {
-        argArr[i] = arguments[i];
-      }
-      return _median(argArr, true);
+      return _median(Array.prototype.slice.call(arguments));
     }
   };
 
   /**
    * Recursively calculate the median of an n-dimensional array
    * @param {Array} array
-   * @param {Boolean} isFlat
    * @return {Number} median
    * @private
    */
-  function _median(array, isFlat) {
-    if (!isFlat) {
-      array = flatten(array);
-    }
+  function _median(array) {
+    var flat = flatten(array);
+
+    flat.sort(math.compare);
+
+    var num = flat.length;
 
-    var num = array.length;
     if (num == 0) {
       throw new Error('Cannot calculate median of an empty array');
     }
 
     if (num % 2 == 0) {
       // even: return the average of the two middle values
-      var mid = num / 2 - 1;
-      var right = math.partitionSelect(array, mid + 1);
-
-      // array now partitioned at mid + 1, take max of left part
-      var left = array[mid];
-      for (var i = 0; i < mid; ++i) {
-        if (math.compare(array[i], left) > 0) {
-          left = array[i];
-        }
-      }
+      var left = flat[num / 2 - 1];
+      var right = flat[num / 2];
 
       if (!isNumber(left) && !(left instanceof BigNumber) && !(left instanceof Unit)) {
         throw new math.error.UnsupportedTypeError('median', math['typeof'](left));
@@ -108,7 +96,7 @@ module.exports = function (math) {
     }
     else {
       // odd: return the middle value
-      var middle = math.partitionSelect(array, (num - 1) / 2);
+      var middle = flat[(num - 1) / 2];
 
       if (!isNumber(middle) && !(middle instanceof BigNumber) && !(middle instanceof Unit)) {
         throw new math.error.UnsupportedTypeError('median', math['typeof'](middle));
diff --git a/lib/function/statistics/quantileSeq.js b/lib/function/statistics/quantileSeq.js
deleted file mode 100644
index e42eba100..000000000
--- a/lib/function/statistics/quantileSeq.js
+++ /dev/null
@@ -1,258 +0,0 @@
-'use strict';
-
-module.exports = function (math) {
-  var util = require('../../util/index');
-  var collection = math.collection;
-  var BigNumber = math.type.BigNumber;
-  var Unit = require('../../type/Unit');
-
-  var isArray = Array.isArray;
-  var isBoolean = util.boolean.isBoolean;
-  var isCollection = collection.isCollection;
-  var isInteger = util.number.isInteger;
-  var isNumber = util.number.isNumber;
-
-  var add = math.add;
-  var flatten = util.array.flatten;
-  var multiply = math.multiply;
-
-  /**
-   * Compute the prob order quantile of a matrix or a list with values.
-   * The sequence is sorted and the middle value is returned.
-   * Supported types of sequence values are: Number, BigNumber, Unit
-   * Supported types of probablity are: Number, BigNumber
-   *
-   * In case of a (multi dimensional) array or matrix, the prob order quantile
-   * of all elements will be calculated.
-   *
-   * Syntax:
-   *
-   *     math.quantileSeq(A, prob[, sorted])
-   *     math.quantileSeq(A, [prob1, prob2, ...][, sorted])
-   *     math.quantileSeq(A, N[, sorted])
-   *
-   * Examples:
-   *
-   *     math.quantileSeq([3, -1, 5, 7], 0.5);         // returns 4
-   *     math.quantileSeq([3, -1, 5, 7], [1/3, 2/3]);  // returns [3, 5]
-   *     math.quantileSeq([3, -1, 5, 7], 2);           // returns [3, 5]
-   *     math.quantileSeq([-1, 3, 5, 7], 0.5, true);   // returns 4
-   *
-   * See also:
-   *
-   *     median, mean, min, max, sum, prod, std, var
-   *
-   * @param {Array, Matrix} data                A single matrix or Array
-   * @param {Number, BigNumber, Array} probOrN  prob is the order of the quantile, while N is
-   *                                            the amount of evenly distributed steps of
-   *                                            probabilities; only one of these options can
-   *                                            be provided
-   * @param {Boolean} sorted=False              is data sorted in ascending order
-   * @return {Number, BigNumber, Unit, Array}   Quantile(s)
-   */
-  math.quantileSeq = function quantileSeq(data, probOrN, sorted) {
-    var probArr, dataArr, one;
-
-    if (arguments.length < 2 || arguments.length > 3) {
-      throw new SyntaxError('Function quantileSeq requires two or three parameters');
-    }
-
-    if (isCollection(data)) {
-      sorted = sorted || false;
-      if (isBoolean(sorted)) {
-        dataArr = data.valueOf();
-        if (isNumber(probOrN)) {
-          if (probOrN < 0) {
-            throw new Error('N/prob must be non-negative');
-          }
-
-          if (probOrN <= 1) {
-            // quantileSeq([a, b, c, d, ...], prob[,sorted])
-            return _quantileSeq(dataArr, probOrN, sorted);
-          }
-
-          if (probOrN > 1) {
-            // quantileSeq([a, b, c, d, ...], N[,sorted])
-            if (!isInteger(probOrN)) {
-              throw new Error('N must be a positive integer');
-            }
-
-            var nPlusOne = probOrN + 1;
-            probArr = new Array(probOrN);
-            for (var i = 0; i < probOrN;) {
-              probArr[i] = _quantileSeq(dataArr, (++i) / nPlusOne, sorted);
-            }
-            return probArr;
-          }
-        }
-
-        if (probOrN instanceof BigNumber) {
-          if (probOrN.isNegative()) {
-            throw new Error('N/prob must be non-negative');
-          }
-
-          one = probOrN.constructor.ONE;
-
-          if (probOrN.lte(one)) {
-            // quantileSeq([a, b, c, d, ...], prob[,sorted])
-            return _quantileSeq(dataArr, probOrN, sorted);
-          }
-
-          if (probOrN.gt(one)) {
-            // quantileSeq([a, b, c, d, ...], N[,sorted])
-            if (!probOrN.isInteger()) {
-              throw new Error('N must be a positive integer');
-            }
-
-            // largest possible Array length is 2^32-1;
-            // 2^32 < 10^15, thus safe conversion guaranteed
-            var intN = probOrN.toNumber();
-            if (intN > 4294967295) {
-              throw new Error('N must be less than or equal to 2^32-1, as that is the maximum length of an Array');
-            }
-
-            var nPlusOne = new BigNumber(intN + 1);
-            probArr = new Array(intN);
-            for (var i = 0; i < intN;) {
-              probArr[i] = _quantileSeq(dataArr, new BigNumber(++i).div(nPlusOne), sorted);
-            }
-            return probArr;
-          }
-        }
-
-        if (isArray(probOrN)) {
-          // quantileSeq([a, b, c, d, ...], [prob1, prob2, ...][,sorted])
-          probArr = new Array(probOrN.length);
-          for (var i = 0; i < probArr.length; ++i) {
-            var currProb = probOrN[i];
-            if (isNumber(currProb)) {
-              if (currProb < 0 || currProb > 1) {
-                throw new Error('Probability must be between 0 and 1, inclusive');
-              }
-            } else if (currProb instanceof BigNumber) {
-              one = currProb.constructor.ONE;
-              if (currProb.isNegative() || currProb.gt(one)) {
-                throw new Error('Probability must be between 0 and 1, inclusive');
-              }
-            } else {
-              throw new math.error.UnsupportedTypeError('quantileSeq', math['typeof'](currProb));
-            }
-
-            probArr[i] = _quantileSeq(dataArr, currProb, sorted);
-          }
-          return probArr;
-        }
-
-        throw new math.error.UnsupportedTypeError('quantileSeq', math['typeof'](probOrN));
-      }
-
-      throw new math.error.UnsupportedTypeError('quantileSeq', math['typeof'](sorted));
-    }
-
-    throw new math.error.UnsupportedTypeError('quantileSeq', math['typeof'](data));
-  };
-
-  /**
-   * Calculate the prob order quantile of an n-dimensional array.
-   * 
-   * @param {Array} array
-   * @param {Number, BigNumber} prob
-   * @param {Boolean} sorted
-   * @return {Number, BigNumber, Unit} prob order quantile
-   * @private
-   */
-  function _quantileSeq(array, prob, sorted) {
-    var flat = flatten(array);
-    var len = flat.length;
-    if (len === 0) {
-      throw new Error('Cannot calculate quantile of an empty sequence');
-    }
-
-    if (isNumber(prob)) {
-      var index = prob * (len-1);
-      var fracPart = index % 1;
-      if (fracPart === 0) {
-        var value = sorted ? flat[index] : math.partitionSelect(flat, index);
-
-        typecheck(value);
-
-        return value;
-      }
-
-      var integerPart = Math.floor(index);
-
-      var left, right;
-      if (sorted) {
-        left = flat[integerPart];
-        right = flat[integerPart+1];
-      } else {
-        right = math.partitionSelect(flat, integerPart+1);
-
-        // max of partition is kth largest
-        left = flat[integerPart];
-        for (var i = 0; i < integerPart; ++i) {
-          if (math.compare(flat[i], left) > 0) {
-            left = flat[i];
-          }
-        }
-      }
-
-      typecheck(left, right);
-
-      // Q(prob) = (1-f)*A[floor(index)] + f*A[floor(index)+1]
-      return add(multiply(left, 1 - fracPart), multiply(right, fracPart));
-    }
-
-    // If prob is a BigNumber
-    var index = prob.times(len-1);
-    if (index.isInteger()) {
-      index = index.toNumber();
-      var value = sorted ? flat[index] : math.partitionSelect(flat, index);
-
-      typecheck(value);
-
-      return value;
-    }
-
-    var integerPart = index.floor();
-    var fracPart = index.minus(integerPart);
-    var integerPartNumber = integerPart.toNumber();
-
-    var left, right;
-    if (sorted) {
-      left = flat[integerPartNumber];
-      right = flat[integerPartNumber+1];
-    } else {
-      right = math.partitionSelect(flat, integerPartNumber+1);
-
-      // max of partition is kth largest
-      left = flat[integerPartNumber];
-      for (var i = 0; i < integerPartNumber; ++i) {
-        if (math.compare(flat[i], left) > 0) {
-          left = flat[i];
-        }
-      }
-    }
-
-    typecheck(left, right);
-
-    // Q(prob) = (1-f)*A[floor(index)] + f*A[floor(index)+1]
-    var one = fracPart.constructor.ONE;
-    return add(multiply(left, one.minus(fracPart)), multiply(right, fracPart));
-  }
-
-  /**
-   * Check if array value types are valid, throw error otherwise.
-   * @param {*} x
-   * @param {*} y
-   * @private
-   */
-  function typecheck(x, y) {
-    if (!isNumber(x) && !(x instanceof BigNumber) && !(x instanceof Unit)) {
-      throw new math.error.UnsupportedTypeError('quantileSeq', math['typeof'](x));
-    }
-    if (y !== undefined && !isNumber(y) && !(y instanceof BigNumber) && !(y instanceof Unit)) {
-      throw new math.error.UnsupportedTypeError('quantileSeq', math['typeof'](y));
-    }
-  }
-};
diff --git a/lib/function/utils/partitionSelect.js b/lib/function/utils/partitionSelect.js
deleted file mode 100644
index b3c11939d..000000000
--- a/lib/function/utils/partitionSelect.js
+++ /dev/null
@@ -1,143 +0,0 @@
-'use strict';
-
-module.exports = function (math) {
-  var util = require('../../util/index');
-  var Matrix = math.type.Matrix;
-
-  var isNumber = util.number.isNumber;
-  var isInteger = util.number.isInteger;
-
-  /**
-   * Partition-based selection of an array or 1D matrix.
-   * Will find the kth smallest value, and mutates the input array.
-   * Currently uses Quickselect.
-   *
-   * Syntax:
-   *
-   *    math.partitionSelect(x, k)
-   *    math.partitionSelect(x, k, compare)
-   *
-   * Examples:
-   *
-   *    math.partitionSelect([5, 10, 1], 2);           // returns 10
-   *    math.partitionSelect(['C', 'B', 'A', 'D'], 1); // returns 'B'
-   *
-   *    function sortByLength (a, b) {
-   *      return a.length - b.length;
-   *    }
-   *    math.partitionSelect(['Langdon', 'Tom', 'Sara'], 2, sortByLength); // returns 'Langdon'
-   *
-   * See also:
-   *
-   *    sort
-   *
-   * @param {Matrix | Array} x    A one dimensional matrix or array to sort
-   * @param {Number} k            The kth smallest value to be retrieved; zero-based index
-   * @param {Function | 'asc' | 'desc'} [compare='asc']
-   *        An optional comparator function. The function is called as
-   *        `compare(a, b)`, and must return 1 when a > b, -1 when a < b,
-   *        and 0 when a == b.
-   * @return {*} Returns the kth lowest value.
-   */
-  math.partitionSelect = function (x, k, compare) {
-    var _compare;
-
-    if (arguments.length === 2) {
-      _compare = math.compare;
-    }
-    else if (arguments.length === 3) {
-      if (typeof compare === 'function') {
-        _compare = compare;
-      }
-      else if (compare === 'asc') {
-        _compare = math.compare;
-      }
-      else if (compare === 'desc') {
-        _compare = function (a, b) {
-          return -math.compare(a, b);
-        }
-      }
-      else {
-        throw new math.error.UnsupportedTypeError('partitionSelect', math['typeof'](compare));
-      }
-    }
-    else {
-      throw new math.error.ArgumentsError('partitionSelect', arguments.length, 2, 3);
-    }
-
-    if (isNumber(k)) {
-      if (isInteger(k) && k >= 0) {
-        if (x instanceof Matrix) {
-          var size = x.size();
-          if (size.length > 1) {
-            throw new Error('Only one dimensional matrices supported');
-          }
-          return quickselect(x.valueOf(), k, _compare);
-        }
-
-        if (Array.isArray(x)) {
-          return quickselect(x, k, _compare);
-        }
-
-        throw new math.error.UnsupportedTypeError('partitionSelect', math['typeof'](x));
-      }
-
-      throw new Error('k must be a non-negative integer');
-    }
-
-    throw new math.error.UnsupportedTypeError('partitionSelect', math['typeof'](k));
-  };
-
-  /**
-   * Quickselect algorithm.
-   * Code adapted from:
-   * http://blog.teamleadnet.com/2012/07/quick-select-algorithm-find-kth-element.html
-   *
-   * @param {Array} arr
-   * @param {Number} k
-   * @param {Function} compare
-   * @private
-   */
-  function quickselect(arr, k, compare) {
-    if (k >= arr.length) {
-      throw new Error('k out of bounds');
-    }
-
-    var from = 0;
-    var to = arr.length - 1;
-
-    // if from == to we reached the kth element
-    while (from < to) {
-      var r = from;
-      var w = to;
-      var pivot = arr[Math.floor(Math.random() * (to - from + 1)) + from];
-
-      // stop if the reader and writer meets
-      while (r < w) {
-        // arr[r] >= pivot
-        if (compare(arr[r], pivot) >= 0) { // put the large values at the end
-          var tmp = arr[w];
-          arr[w] = arr[r];
-          arr[r] = tmp;
-          --w;
-        } else { // the value is smaller than the pivot, skip
-          ++r;
-        }
-      }
-
-      // if we stepped up (r++) we need to step one down (arr[r] > pivot)
-      if (compare(arr[r], pivot) > 0) {
-        --r;
-      }
-
-      // the r pointer is on the end of the first k elements
-      if (k <= r) {
-        to = r;
-      } else {
-        from = r + 1;
-      }
-    }
-
-    return arr[k];
-  }
-};
diff --git a/lib/math.js b/lib/math.js
index dad929236..42015cb48 100644
--- a/lib/math.js
+++ b/lib/math.js
@@ -153,7 +153,7 @@ function create (config) {
   if (typeof BigNumber.convert !== 'function') {
     /**
      * Try to convert a Number in to a BigNumber.
-     * If the number has 15 or more significant digits, the Number cannot be
+     * If the number has 15 or mor significant digits, the Number cannot be
      * converted to BigNumber and will return the original number.
      * @param {Number} number
      * @return {BigNumber | Number} bignumber
@@ -277,7 +277,10 @@ function create (config) {
   require('./function/complex/conj')(math, _config);
   require('./function/complex/re')(math, _config);
   require('./function/complex/im')(math, _config);
-
+  
+  // functions - geometry
+  require('./function/geometry/intersect')(math, _config);
+  
   // functions - logical
   require('./function/logical/and')(math, _config);
   require('./function/logical/not')(math, _config);
@@ -329,7 +332,6 @@ function create (config) {
   require('./function/statistics/mean')(math, _config);
   require('./function/statistics/median')(math, _config);
   require('./function/statistics/prod')(math, _config);
-  require('./function/statistics/quantileSeq')(math, _config);
   require('./function/statistics/std')(math, _config);
   require('./function/statistics/sum')(math, _config);
   require('./function/statistics/var')(math, _config);
@@ -370,7 +372,6 @@ function create (config) {
   require('./function/utils/format')(math, _config);
   require('./function/utils/import')(math, _config);
   require('./function/utils/map')(math, _config);
-  require('./function/utils/partitionSelect')(math, _config);
   require('./function/utils/print')(math, _config);
   require('./function/utils/sort')(math, _config);
   require('./function/utils/typeof')(math, _config);
diff --git a/lib/util/bignumber.js b/lib/util/bignumber.js
index 7a92a0473..a4ef68b23 100644
--- a/lib/util/bignumber.js
+++ b/lib/util/bignumber.js
@@ -1406,21 +1406,3 @@ exports.toFixed = function(value, precision) {
   // Note: the (precision || 0) is needed as the toFixed of BigNumber has an
   // undefined default precision instead of 0.
 };
-
-/**
-* Determines if n is a positive integer
-* @param {Number} n   Value to determine if it is a positive integer
-* @return {Boolean}   Whether the number is positive
-*/
-exports.isPositiveInteger = function(n) {
-  if (n instanceof BigNumber && n.isInteger() && n.gt(0)) {
-    return true;
-  }
-
-  if (isNumber(n) && n.isInteger() && n > 0) {
-    return true;
-  }
-
-  return false;
-}
-
diff --git a/lib/util/number.js b/lib/util/number.js
index 3ff7c7ecb..9d82ebf5d 100644
--- a/lib/util/number.js
+++ b/lib/util/number.js
@@ -257,4 +257,3 @@ exports.nearlyEqual = function(x, y, epsilon) {
   // Infinite and Number or negative Infinite and positive Infinite cases
   return false;
 };
-


Test patch:
diff --git a/test/function/geometry/intersect.test.js b/test/function/geometry/intersect.test.js
new file mode 100644
index 000000000..25f018ed4
--- /dev/null
+++ b/test/function/geometry/intersect.test.js
@@ -0,0 +1,35 @@
+var assert = require('assert');
+var error = require('../../../lib/error/index');
+var math = require('../../../index');
+
+describe('intersect', function() {
+  it('should calculate the intersection point of two 2D lines', function() {
+    assert.deepEqual(math.intersect([0, 0], [10, 10], [10, 0], [0, 10]), [5, 5]);
+  });
+
+  it('should calculate the intersection point of two 3D lines', function() {
+    assert.deepEqual(math.intersect([0, 0, 0], [10, 10, 0], [10, 0, 0], [0, 10, 0]), [5, 5, 0]);
+  });
+
+  it('should calculate the intersection point of a line and a plane', function() {
+    assert.deepEqual(math.intersect([1, 0, 1], [4, -2, 2], [1, 1, 1, 6]), [7, -4, 3]);
+  });
+  
+  it('should return null if the points do not intersect', function() {
+    assert.deepEqual(math.intersect([0, 1, 0], [0, 0, 0], [1, 1, 0], [1, 0, 0]), null);
+    assert.deepEqual(math.intersect([0, 1], [0, 0], [1, 1], [1, 0]), null);
+  });
+
+  it('should throw an error when number of arguments are other than 3 or 4', function() {
+    assert.throws(function () {math.intersect([2, 0, 1], [1, 1, 1, 6])});
+    assert.throws(function () {math.intersect([2, 0, 1], [1, 1, 6], [2, 0, 1], [1, 1, 6], [0, 8, 1])});
+  });
+  
+  it('should throw an error for incompatible parameter types', function() {
+    assert.throws(function () {math.intersect(2, 3, 6)}, TypeError);
+    assert.throws(function () {math.intersect([2, 0, 1], [1, 1, 1], [5, 1, 10])}, /Arguments are not correct/);
+    assert.throws(function () {math.intersect([], [], [], [])});
+    assert.throws(function () {math.intersect([2, 8, 9], 3, 6)}, TypeError);
+    assert.throws(function () {math.intersect(a, b, c, d)});
+  });
+});
diff --git a/test/function/statistics/quantileSeq.test.js b/test/function/statistics/quantileSeq.test.js
deleted file mode 100644
index 2532a4434..000000000
--- a/test/function/statistics/quantileSeq.test.js
+++ /dev/null
@@ -1,186 +0,0 @@
-var assert = require('assert'),
-    approx = require('../../../tools/approx'),
-    math = require('../../../index'),
-    bignumber = math.bignumber,
-    quantileSeq = math.quantileSeq;
-
-describe('quantileSeq', function() {
-
-  it('should return the quantileSeq from an array with number probability', function() {
-    var lst = [3.7, 2.7, 3.3, 1.3, 2.2, 3.1];
-    assert.equal(quantileSeq(lst, 0), 1.3);
-    assert.equal(quantileSeq(lst, 0.1), 1.75);
-    assert.equal(quantileSeq(lst, 0.2), 2.2);
-    assert.equal(quantileSeq(lst, 0.25), 2.325);
-    assert.equal(quantileSeq(lst, 0.25, false), 2.325);
-    assert.equal(quantileSeq(lst, 0.3), 2.45);
-    assert.equal(quantileSeq(lst, 0.4), 2.7);
-    approx.equal(quantileSeq(lst, 0.5), 2.9);
-    assert.equal(quantileSeq(lst, 0.6), 3.1);
-    assert.equal(quantileSeq(lst, 0.7), 3.2);
-    approx.equal(quantileSeq(lst, 0.75), 3.25);
-    assert.equal(quantileSeq(lst, 0.8), 3.3);
-    assert.equal(quantileSeq(lst, 0.9), 3.5);
-    assert.equal(quantileSeq(lst, 1), 3.7);
-  });
-
-  it('should return the quantileSeq from an ascending array with number probability', function() {
-    var lst = [1.3, 2.2, 2.7, 3.1, 3.3, 3.7];
-    assert.equal(quantileSeq(lst, 0, true), 1.3);
-    assert.equal(quantileSeq(lst, 0.1, true), 1.75);
-    assert.equal(quantileSeq(lst, 0.2, true), 2.2);
-    assert.equal(quantileSeq(lst, 0.25, true), 2.325);
-    assert.equal(quantileSeq(lst, 0.3, true), 2.45);
-    assert.equal(quantileSeq(lst, 0.4, true), 2.7);
-    approx.equal(quantileSeq(lst, 0.5, true), 2.9);
-    assert.equal(quantileSeq(lst, 0.6, true), 3.1);
-    assert.equal(quantileSeq(lst, 0.7, true), 3.2);
-    approx.equal(quantileSeq(lst, 0.75, true), 3.25);
-    assert.equal(quantileSeq(lst, 0.8, true), 3.3);
-    assert.equal(quantileSeq(lst, 0.9, true), 3.5);
-    assert.equal(quantileSeq(lst, 1, true), 3.7);
-  });
-
-  it('should return the quantileSeq from an array with BigNumber probability', function() {
-    var lst = [3.7, 2.7, 3.3, 1.3, 2.2, 3.1];
-    assert.equal(quantileSeq(lst, bignumber(0)), 1.3);
-    assert.equal(quantileSeq(lst, bignumber(0.1)), 1.75);
-    assert.equal(quantileSeq(lst, bignumber(0.2)), 2.2);
-    assert.equal(quantileSeq(lst, bignumber(0.25)), 2.325);
-    assert.equal(quantileSeq(lst, bignumber(0.3)), 2.45);
-    assert.equal(quantileSeq(lst, bignumber(0.4)), 2.7);
-    assert.equal(quantileSeq(lst, bignumber(0.5)), 2.9);
-    assert.equal(quantileSeq(lst, bignumber(0.6)), 3.1);
-    assert.equal(quantileSeq(lst, bignumber(0.7)), 3.2);
-    assert.equal(quantileSeq(lst, bignumber(0.75)), 3.25);
-    assert.equal(quantileSeq(lst, bignumber(0.8)), 3.3);
-    assert.equal(quantileSeq(lst, bignumber(0.9)), 3.5);
-    assert.equal(quantileSeq(lst, bignumber(1)), 3.7);
-  });
-
-  it('should return the quantileSeq of an array of bignumbers with number probability', function() {
-    approx.equal(quantileSeq([bignumber(0.5377),bignumber(1.8339),bignumber(-2.2588),bignumber(0.8622),
-                              bignumber(0.3188),bignumber(-1.3077),bignumber(-0.4336),bignumber(0.3426),
-                              bignumber(3.5784),bignumber(2.7694)],0.3),
-                              0.09308);
-  });
-
-  it('should return the quantileSeq of an array of bignumbers with BigNumber probability', function() {
-    assert.deepEqual(quantileSeq([bignumber(0.5377),bignumber(1.8339),bignumber(-2.2588),bignumber(0.8622),
-                                  bignumber(0.3188),bignumber(-1.3077),bignumber(-0.4336),bignumber(0.3426),
-                                  bignumber(3.5784),bignumber(2.7694)],bignumber(0.3)),
-                                  bignumber(0.09308));
-  });
-
-  it('should return the quantileSeq of units', function() {
-    assert.deepEqual(quantileSeq([math.unit('5mm'), math.unit('15mm'), math.unit('10mm')], 0.5), math.unit('10mm'));
-  });
-
-  it('should return the quantileSeq from an 1d matrix', function() {
-    assert.equal(quantileSeq(math.matrix([2,4,6,8,10,12,14]), 0.25), 5);
-  });
-
-  it('should return the quantileSeq from a 2d array', function() {
-    approx.equal(quantileSeq([
-      [3.7, 2.7, 3.3],
-      [1.3, 2.2, 3.1]
-    ], 0.75), 3.25);
-  });
-
-  it('should return the quantileSeq from an ascending 2d array', function() {
-    approx.equal(quantileSeq([
-      [1.3, 2.2, 2.7],
-      [3.1, 3.3, 3.7]
-    ], 0.75, true), 3.25);
-  });
-
-  it('should return the quantileSeq from a 2d matrix', function() {
-    approx.equal(quantileSeq(math.matrix([
-      [3.7, 2.7, 3.3],
-      [1.3, 2.2, 3.1]
-    ]), 0.75), 3.25);
-  });
-
-  it('should return the quantileSeq from an ascending 2d matrix', function() {
-    approx.equal(quantileSeq(math.matrix([
-      [1.3, 2.2, 2.7],
-      [3.1, 3.3, 3.7]
-    ]), 0.75, true), 3.25);
-  });
-
-  it('should return list quantiles for list of number probabilities', function() {
-    var lst = [3.7, 2.7, 3.3, 1.3, 2.2, 3.1];
-    approx.deepEqual(quantileSeq(lst, [0.25, 0.5, 0.75]), [2.325, 2.9, 3.25]);
-    approx.deepEqual(quantileSeq(lst, [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]),
-                     [1.75, 2.2, 2.45, 2.7, 2.9, 3.1, 3.2, 3.3, 3.5]);
-  });
-
-  it('should return list quantiles for list of BigNumber probabilities', function() {
-    var lst = [3.7, 2.7, 3.3, 1.3, 2.2, 3.1];
-    assert.deepEqual(quantileSeq(lst, [bignumber(0.25), bignumber(0.5), bignumber(0.75)]),
-                     [bignumber(2.325), bignumber(2.9), bignumber(3.25)]);
-    assert.equal(quantileSeq(lst, [bignumber(0.1), bignumber(0.2), bignumber(0.3), bignumber(0.4),
-                                   bignumber(0.5), bignumber(0.6), bignumber(0.7), bignumber(0.8),
-                                   bignumber(0.9)]).toString(), '1.75,2.2,2.45,2.7,2.9,3.1,3.2,3.3,3.5');
-  });
-
-  it('should return list quantiles for list of number and BigNumber probabilities', function() {
-    var lst = [3.7, 2.7, 3.3, 1.3, 2.2, 3.1];
-    approx.deepEqual(quantileSeq(lst, [0.25, bignumber(0.5), 0.75]), [2.325, 2.9, 3.25]);
-    approx.deepEqual(quantileSeq(lst, [0.1, 0.2, bignumber(0.3), 0.4, 0.5, 0.6, 0.7, bignumber(0.8), 0.9]),
-                     [1.75, 2.2, 2.45, 2.7, 2.9, 3.1, 3.2, 3.3, 3.5]);
-  });
-
-  it('should return the evenly number spaced quantiles of an array', function() {
-    var lst = [3.7, 2.7, 3.3, 1.3, 2.2, 3.1];
-    approx.deepEqual(quantileSeq(lst, 3), [2.325, 2.9, 3.25]);
-    approx.deepEqual(quantileSeq(lst, 9), [1.75, 2.2, 2.45, 2.7, 2.9, 3.1, 3.2, 3.3, 3.5]);
-  });
-
-  it('should return the evenly BigNumber spaced quantiles of an array', function() {
-    var lst = [3.7, 2.7, 3.3, 1.3, 2.2, 3.1];
-    assert.deepEqual(quantileSeq(lst, bignumber(3)), [bignumber(2.325), bignumber(2.9), bignumber(3.25)]);
-    assert.equal(quantileSeq(lst, bignumber(9)).toString(), "1.75,2.2,2.45,2.7,2.9,3.1,3.2,3.3,3.5");
-  });
-
-  it('should throw an error if called with invalid number of arguments', function() {
-    assert.throws(function() {quantileSeq()}, SyntaxError);
-    assert.throws(function() {quantileSeq(2)}, SyntaxError);
-    assert.throws(function() {quantileSeq([], 2, 3, 1)}, SyntaxError);
-  });
-
-  it('should throw an error if called with unsupported type of arguments', function() {
-    assert.throws(function () {quantileSeq([2,4,6,8,10,12,14], 0.25, 10)}, math.error.UnsupportedTypeError);
-    assert.throws(function () {quantileSeq([2,4,6,8,10,12,14], [0.25, 2])}, math.error.UnsuppoError);
-    assert.throws(function () {quantileSeq('A', 'C', 'B')}, math.error.UnsupportedTypeError);
-    assert.throws(function () {quantileSeq(true, false, true)}, math.error.UnsupportedTypeError);
-    assert.throws(function () {quantileSeq(0, 'B')}, math.error.UnsupportedTypeError);
-    assert.throws(function () {quantileSeq(math.complex(2,3), math.complex(-1,2))}, TypeError);
-  });
-
-  it('should throw error for bad probabilities and splits', function() {
-    assert.throws(function () {quantileSeq([2,4,6,8,10,12,14], [0.23, 2, 0.2])}, Error);
-    assert.throws(function () {quantileSeq([2,4,6,8,10,12,14], [0.23, bignumber(2), 0.2])}, Error);
-    assert.throws(function () {quantileSeq([2,4,6,8,10,12,14], -2)}, Error);
-    assert.throws(function () {quantileSeq([2,4,6,8,10,12,14], bignumber(-2))}, Error);
-  });
-
-  it('should throw an error if called with an empty array', function() {
-    assert.throws(function() {quantileSeq([])});
-  });
-
-  it('should not mutate the input', function () {
-    var a = [3,2,1];
-    quantileSeq(a, 0.2);
-    quantileSeq(a, 2);
-    quantileSeq(a, [0.1, 0.3]);
-    assert.deepEqual(a,[3,2,1]);
-  });
-
-  /*
-  it('should LaTeX quantileSeq', function () {
-    var expression = math.parse('quantileSeq(1,2,3,4,0.3)');
-    assert.equal(expression.toTex(), '\\mathrm{quantile}\\left(1,2,3,4,0.3\\right)');
-  });
-  */
-});
diff --git a/test/function/trigonometry/cot.test.js b/test/function/trigonometry/cot.test.js
index 072400dcf..2a02d4780 100644
--- a/test/function/trigonometry/cot.test.js
+++ b/test/function/trigonometry/cot.test.js
@@ -57,6 +57,7 @@ describe('cot', function() {
 
     /* Pass in more digits of pi. */
     var biggerPi = biggermath.pi;
+    console.log(biggerPi.constructor.precision);
     assert.deepEqual(bigmath.cot(biggerPi.div(4)).toString(), '1');
     assert.deepEqual(bigmath.cot(biggerPi.times(3).div(4)).toString(), '-1');
     assert.deepEqual(bigmath.cot(biggerPi.times(5).div(4)).toString(), '1');
diff --git a/test/function/utils/partitionSelect.test.js b/test/function/utils/partitionSelect.test.js
deleted file mode 100644
index 3322e9acb..000000000
--- a/test/function/utils/partitionSelect.test.js
+++ /dev/null
@@ -1,109 +0,0 @@
-var assert = require('assert');
-var error = require('../../../lib/error/index');
-var math = require('../../../index');
-var matrix = math.matrix;
-var partitionSelect = math.partitionSelect;
-
-describe('partitionSelect', function() {
-
-  it('should sort an array with numbers', function() {
-    assert.equal(partitionSelect([5,10,1], 0), 1);
-    assert.equal(partitionSelect([5,10,1], 1), 5);
-    assert.equal(partitionSelect([5,10,1], 2), 10);
-  });
-
-  it('should sort an array with strings', function() {
-    assert.equal(partitionSelect(['C', 'B', 'A', 'D'], 0), 'A');
-    assert.equal(partitionSelect(['C', 'B', 'A', 'D'], 1), 'B');
-    assert.equal(partitionSelect(['C', 'B', 'A', 'D'], 2), 'C');
-    assert.equal(partitionSelect(['C', 'B', 'A', 'D'], 3), 'D');
-  });
-
-  it('should sort a Matrix', function() {
-    assert.equal(partitionSelect(matrix([5,10,1]), 0), 1);
-    assert.equal(partitionSelect(matrix([5,10,1]), 1), 5);
-    assert.equal(partitionSelect(matrix([5,10,1]), 2), 10);
-  });
-
-  it('should sort an array in ascending order', function() {
-    assert.equal(partitionSelect([5,10,1], 0, 'asc'), 1);
-    assert.equal(partitionSelect([5,10,1], 1, 'asc'), 5);
-    assert.equal(partitionSelect([5,10,1], 2, 'asc'), 10);
-  });
-
-  it('should sort an array in descending order', function() {
-    assert.equal(partitionSelect([5,10,1], 0, 'desc'), 10);
-    assert.equal(partitionSelect([5,10,1], 1, 'desc'), 5);
-    assert.equal(partitionSelect([5,10,1], 2, 'desc'), 1);
-  });
-
-  it('should sort an array with a custom compare function', function() {
-    function sortByLength (a, b) {
-      return a.length - b.length;
-    }
-    assert.equal(partitionSelect(['Langdon', 'Tom', 'Sara'], 0, sortByLength), 'Tom');
-    assert.equal(partitionSelect(['Langdon', 'Tom', 'Sara'], 1, sortByLength), 'Sara');
-    assert.equal(partitionSelect(['Langdon', 'Tom', 'Sara'], 2, sortByLength), 'Langdon');
-  });
-
-  it('should mutate the input array, leaving it partitioned at k', function() {
-    var arr = [3, 2, 4, 6, -2, 5];
-    partitionSelect(arr, 3);
-
-    for (var i = 0; i < 3; ++i) {
-      assert.ok(arr[i] <= arr[3]);
-    }
-    assert.ok(arr[3] === 4);
-    for (var i = 4; i < arr.length; ++i) {
-      assert.ok(arr[3] <= arr[i]);
-    }
-  });
-
-  it('should mutate the input matrix, leaving it partitioned at k', function() {
-    var m = matrix([3, 2, 4, 6, -2, 5]);
-    partitionSelect(m, 3);
-
-    m.forEach(function (value, index, matrix) {
-      if (index[0] < 3) {
-        assert.ok(value <= 4);
-      } else if (index[0] === 3) {
-        assert.ok(value === 4);
-      } else {
-        assert.ok(value >= 4);
-      }
-    });
-  });
-
-  it('should throw an error if called with a multi dimensional matrix', function() {
-    assert.throws(function() { partitionSelect(matrix([[1,2],[3,4]]), 2) }, /Only one dimensional matrices supported/);
-  });
-
-  it('should throw an error if called with a non-negative k, within the bounds of the array', function() {
-    assert.throws(function() { partitionSelect([1], -2) }, /k must be a non-negative integer/);
-    assert.throws(function() { partitionSelect([3, 2, 1], 1.2) }, /k must be a non-negative integer/);
-    assert.throws(function() { partitionSelect([3, 2, 1], 3) }, /k out of bounds/);
-    assert.throws(function() { partitionSelect([], 0) }, /k out of bounds/);
-  });
-
-  it('should throw an error if called with unsupported type', function() {
-    assert.throws(function() { partitionSelect(2, 2) }, math.error.UnsupportedTypeError);
-    assert.throws(function() { partitionSelect('string', 2) }, math.error.UnsupportedTypeError);
-    assert.throws(function() { partitionSelect([1], 'string') }, math.error.UnsupportedTypeError);
-    assert.throws(function() { partitionSelect([1], 1, 'function') }, math.error.UnsupportedTypeError);
-    assert.throws(function() { partitionSelect([1], 1, {}) }, math.error.UnsupportedTypeError);
-  });
-
-  it('should throw an error if called with invalid number of arguments', function() {
-    assert.throws(function() { partitionSelect() }, math.error.ArgumentsError);
-    assert.throws(function() { partitionSelect([]) }, math.error.ArgumentsError);
-    assert.throws(function() { partitionSelect([], 2, 'foo', 3) }, math.error.ArgumentsError);
-  });
-
-  /*
-  it('should LaTeX sort', function () {
-    var expression = math.parse('sort([3,2,1])');
-    assert.equal(expression.toTex(), '\\mathrm{sort}\\left(\\begin{bmatrix}3\\\\2\\\\1\\\\\\end{bmatrix}\\right)');
-  });
-  */
-
-});
diff --git a/test/util/bignumber.test.js b/test/util/bignumber.test.js
index 319f34e2d..359b2586d 100644
--- a/test/util/bignumber.test.js
+++ b/test/util/bignumber.test.js
@@ -278,27 +278,4 @@ describe('bignumber', function() {
 
   });
 
-    it('should determine if input is a integer', function() {
-        assert.equal(bignumber.isPositiveInteger([new BigNumber(1)]), false);
-        assert.equal(bignumber.isPositiveInteger(false), false);
-        assert.equal(bignumber.isPositiveInteger('test'), false);
-        assert.equal(bignumber.isPositiveInteger({a:new BigNumber(1)}), false);
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(0.1)), false);
-    });
-
-    it('should determine if integer is positive', function() {
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(1)), true);
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(0)), false);
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(0)), false);
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(-0)), false);
-    });
-
-    it('should determine if BigNumber is positive', function() {
-        BigNumber = require('decimal.js');
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(10)), true);
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(-10)), false);
-        assert.equal(bignumber.isPositiveInteger(new BigNumber(100000)), true);
-    });
-
 });
-