UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.

28 lines 305 kB
/** * math.js * https://github.com/josdejong/mathjs * * Math.js is an extensive math library for JavaScript and Node.js, * It features real and complex numbers, units, matrices, a large set of * mathematical functions, and a flexible expression parser. * * @version 1.5.2 * @date 2015-04-09 * * @license * Copyright (C) 2013-2015 Jos de Jong <wjosdejong@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):"object"==typeof exports?exports.math=r():e.math=r()}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var i=t[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){e.exports=t(1)},function(e,r,t){"use strict";function n(e){if("function"!=typeof Object.create)throw new Error("ES5 not supported by this JavaScript engine. Please load the es5-shim and es5-sham library for compatibility.");var r={},a={matrix:"matrix",number:"number",precision:64,epsilon:1e-14};r.config=function(e){if(e){if(i.deepExtend(a,e),e.precision&&r.type.BigNumber.config({precision:e.precision}),t(4)(r,a),e.number&&e.number.defaultType)throw new Error("setting `number.defaultType` is deprecated. Use `number` instead.");if(e.number&&e.number.precision)throw new Error("setting `number.precision` is deprecated. Use `precision` instead.");if(e.matrix&&e.matrix.defaultType)throw new Error("setting `matrix.defaultType` is deprecated. Use `matrix` instead.");if(e.matrix&&e.matrix["default"])throw new Error("setting `matrix.default` is deprecated. Use `matrix` instead.");if(e.decimals)throw new Error("setting `decimals` is deprecated. Use `precision` instead.")}return i.clone(a)},r.create=n;var s=t(5).constructor();if(s.prototype.toJSON=function(){return{mathjs:"BigNumber",value:this.toString()}},s.fromJSON=function(e){return new s(e.value)},"function"!=typeof s.prototype.clone&&(s.prototype.clone=function(){return this}),"function"==typeof s.convert)throw new Error("Cannot add function convert to BigNumber: function already exists");return s.convert=function(e){return o(e)>15?e:new s(e)},r.error=t(6),r.type={},r.type.Complex=t(7),r.type.Range=t(8),r.type.Index=t(9),r.type.Matrix=t(10)(a),r.type.Unit=t(11),r.type.Help=t(12),r.type.ResultSet=t(13),r.type.BigNumber=s,r.collection=t(14)(r,a),r.type.CcsMatrix=t(15)(r,a),r.type.CrsMatrix=t(16)(r,a),r.type.DenseMatrix=t(17)(r,a),r.type.Matrix._storage.ccs=r.type.CcsMatrix,r.type.Matrix._storage.crs=r.type.CrsMatrix,r.type.Matrix._storage.dense=r.type.DenseMatrix,r.type.Matrix._storage["default"]=r.type.DenseMatrix,r.expression={},r.expression.node=t(18),r.expression.parse=t(19)(r,a),r.expression.Parser=t(20)(r,a),r.expression.docs=t(21),r.json={reviver:t(22)(r,a)},t(34)(r,a),t(35)(r,a),t(36)(r,a),t(37)(r,a),t(38)(r,a),t(39)(r,a),t(40)(r,a),t(41)(r,a),t(42)(r,a),t(43)(r,a),t(44)(r,a),t(45)(r,a),t(46)(r,a),t(47)(r,a),t(48)(r,a),t(49)(r,a),t(50)(r,a),t(51)(r,a),t(52)(r,a),t(53)(r,a),t(54)(r,a),t(55)(r,a),t(56)(r,a),t(57)(r,a),t(58)(r,a),t(59)(r,a),t(60)(r,a),t(61)(r,a),t(62)(r,a),t(63)(r,a),t(64)(r,a),t(65)(r,a),t(66)(r,a),t(67)(r,a),t(68)(r,a),t(69)(r,a),t(70)(r,a),t(71)(r,a),t(72)(r,a),t(73)(r,a),t(74)(r,a),t(75)(r,a),t(76)(r,a),t(77)(r,a),t(78)(r,a),t(79)(r,a),t(80)(r,a),t(81)(r,a),t(82)(r,a),t(83)(r,a),t(84)(r,a),t(85)(r,a),t(86)(r,a),t(87)(r,a),t(88)(r,a),t(89)(r,a),t(90)(r,a),t(91)(r,a),t(92)(r,a),t(93)(r,a),t(94)(r,a),t(95)(r,a),t(96)(r,a),t(97)(r,a),t(98)(r,a),t(99)(r,a),t(100)(r,a),t(101)(r,a),t(102)(r,a),t(103)(r,a),t(104)(r,a),t(105)(r,a),t(106)(r,a),t(107)(r,a),t(108)(r,a),t(109)(r,a),t(110)(r,a),t(111)(r,a),t(112)(r,a),t(113)(r,a),t(114)(r,a),t(115)(r,a),t(116)(r,a),t(117)(r,a),t(118)(r,a),t(119)(r,a),t(120)(r,a),t(121)(r,a),t(122)(r,a),t(123)(r,a),t(124)(r,a),t(125)(r,a),t(126)(r,a),t(127)(r,a),t(128)(r,a),t(129)(r,a),t(130)(r,a),t(131)(r,a),t(132)(r,a),t(133)(r,a),t(134)(r,a),t(135)(r,a),t(136)(r,a),t(137)(r,a),t(138)(r,a),t(139)(r,a),t(140)(r,a),t(141)(r,a),t(142)(r,a),t(143)(r,a),t(144)(r,a),t(145)(r,a),t(146)(r,a),t(147)(r,a),t(148)(r,a),t(149)(r,a),t(150)(r,a),t(151)(r,a),t(152)(r,a),t(153)(r,a),t(154)(r,a),t(155)(r,a),t(156)(r,a),t(157)(r,a),t(158)(r,a),t(159)(r,a),t(160)(r,a),t(161)(r,a),t(162)(r,a),t(163)(r,a),t(164)(r,a),t(165)(r,a),t(166)(r,a),r.ifElse=function(){throw new Error("Function ifElse is deprecated. Use the conditional operator instead.")},t(4)(r,a),r.expression.transform={concat:t(23)(r,a),filter:t(24)(r,a),forEach:t(25)(r,a),index:t(26)(r,a),map:t(27)(r,a),max:t(28)(r,a),mean:t(29)(r,a),min:t(30)(r,a),range:t(31)(r,a),subset:t(32)(r,a)},r.chaining={},r.chaining.Chain=t(33)(r,a),r.chaining.Selector=r.chaining.Chain,r.config(a),r.config(e),r}var i=t(2),o=t(3).digits,a=n();"undefined"!=typeof window&&(window.mathjs=a),e.exports=a},function(e,r,t){"use strict";r.clone=function n(e){var r=typeof e;if("number"===r||"string"===r||"boolean"===r||null===e||void 0===e)return e;if("function"==typeof e.clone)return e.clone();if(Array.isArray(e))return e.map(function(e){return n(e)});if(e instanceof Number)return new Number(e.valueOf());if(e instanceof String)return new String(e.valueOf());if(e instanceof Boolean)return new Boolean(e.valueOf());if(e instanceof Date)return new Date(e.valueOf());if(e instanceof RegExp)throw new TypeError("Cannot clone "+e);var t={};for(var i in e)e.hasOwnProperty(i)&&(t[i]=n(e[i]));return t},r.extend=function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t]);return e},r.deepExtend=function i(e,r){if(Array.isArray(r))throw new TypeError("Arrays are not supported by deepExtend");for(var t in r)if(r.hasOwnProperty(t))if(r[t]&&r[t].constructor===Object)void 0===e[t]&&(e[t]={}),e[t].constructor===Object?i(e[t],r[t]):e[t]=r[t];else{if(Array.isArray(r[t]))throw new TypeError("Arrays are not supported by deepExtend");e[t]=r[t]}return e},r.deepEqual=function(e,t){var n,i,o;if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!=t.length)return!1;for(i=0,o=e.length;o>i;i++)if(!r.deepEqual(e[i],t[i]))return!1;return!0}if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!r.deepEqual(e[n],t[n]))return!1;for(n in t)if(!r.deepEqual(e[n],t[n]))return!1;return!0}return typeof e==typeof t&&e==t},r.canDefineProperty=function(){try{if(Object.defineProperty)return Object.defineProperty({},"x",{}),!0}catch(e){}return!1},r.lazy=function(e,t,n){if(r.canDefineProperty()){var i,o=!0;Object.defineProperty(e,t,{get:function(){return o&&(i=n(),o=!1),i},set:function(e){i=e,o=!1}})}else e[t]=n()}},function(e,r,t){"use strict";var n=t(167);r.isNumber=function(e){return e instanceof Number||"number"==typeof e},r.isInteger=function(e){return e==Math.round(e)},r.sign=function(e){return e>0?1:0>e?-1:0},r.format=function(e,t){if("function"==typeof t)return t(e);if(e===1/0)return"Infinity";if(e===-(1/0))return"-Infinity";if(isNaN(e))return"NaN";var n="auto",i=void 0;switch(t&&(t.notation&&(n=t.notation),r.isNumber(t)?i=t:t.precision&&(i=t.precision)),n){case"fixed":return r.toFixed(e,i);case"exponential":return r.toExponential(e,i);case"auto":return r.toPrecision(e,i,t&&t.exponential).replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],r=arguments[4];return"."!==e?e+r:r});default:throw new Error('Unknown notation "'+n+'". Choose "auto", "exponential", or "fixed".')}},r.toExponential=function(e,r){return new n(e).toExponential(r)},r.toFixed=function(e,r){return new n(e).toFixed(r)},r.toPrecision=function(e,r,t){return new n(e).toPrecision(r,t)},r.digits=function(e){return e.toExponential().replace(/e.*$/,"").replace(/^0\.?0*|\./,"").length},r.DBL_EPSILON=Number.EPSILON||2.220446049250313e-16,r.nearlyEqual=function(e,t,n){if(null==n)return e==t;if(e==t)return!0;if(isNaN(e)||isNaN(t))return!1;if(isFinite(e)&&isFinite(t)){var i=Math.abs(e-t);return i<r.DBL_EPSILON?!0:i<=Math.max(Math.abs(e),Math.abs(t))*n}return!1}},function(e,r,t){"use strict";e.exports=function(e,r){var n=t(2),i=t(168),o=t(7),a=e.type.BigNumber;e["true"]=!0,e["false"]=!1,e["null"]=null,e.uninitialized=t(169).UNINITIALIZED,"bignumber"===r.number?(e.Infinity=new a(1/0),e.NaN=new a(0/0),n.lazy(e,"pi",function(){return i.pi(r.precision)}),n.lazy(e,"tau",function(){return i.tau(r.precision)}),n.lazy(e,"e",function(){return i.e(r.precision)}),n.lazy(e,"phi",function(){return i.phi(r.precision)}),n.lazy(e,"E",function(){return e.e}),n.lazy(e,"LN2",function(){return new a(2).ln()}),n.lazy(e,"LN10",function(){return new a(10).ln()}),n.lazy(e,"LOG2E",function(){return new a(1).div(new a(2).ln())}),n.lazy(e,"LOG10E",function(){return new a(1).div(new a(10).ln())}),n.lazy(e,"PI",function(){return e.pi}),n.lazy(e,"SQRT1_2",function(){return new a("0.5").sqrt()}),n.lazy(e,"SQRT2",function(){return new a(2).sqrt()})):(e.Infinity=1/0,e.NaN=0/0,e.pi=Math.PI,e.tau=2*Math.PI,e.e=Math.E,e.phi=1.618033988749895,e.E=e.e,e.LN2=Math.LN2,e.LN10=Math.LN10,e.LOG2E=Math.LOG2E,e.LOG10E=Math.LOG10E,e.PI=e.pi,e.SQRT1_2=Math.SQRT1_2,e.SQRT2=Math.SQRT2),e.i=new o(0,1),e.version=t(170)}},function(e,r,t){var n=t(340);e.exports=n},function(e,r,t){"use strict";r.ArgumentsError=t(171),r.DimensionError=t(172),r.IndexError=t(173),r.UnsupportedTypeError=t(174)},function(e,r,t){"use strict";function n(e,r){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");switch(arguments.length){case 0:this.re=0,this.im=0;break;case 1:var t=arguments[0];if("object"==typeof t){if("re"in t&&"im"in t){var i=new n(t.re,t.im);this.re=i.re,this.im=i.im;break}if("r"in t&&"phi"in t){var i=n.fromPolar(t.r,t.phi);this.re=i.re,this.im=i.im;break}}throw new SyntaxError("Object with the re and im or r and phi properties expected.");case 2:if(!h(e)||!h(r))throw new TypeError("Two numbers expected in Complex constructor");this.re=e,this.im=r;break;default:throw new SyntaxError("One, two or three arguments expected in Complex constructor")}}function i(){for(;" "==x||" "==x;)s()}function o(e){return e>="0"&&"9">=e||"."==e}function a(e){return e>="0"&&"9">=e}function s(){y++,x=v.charAt(y)}function u(e){y=e,x=v.charAt(y)}function c(){var e,r="";if(e=y,"+"==x?s():"-"==x&&(r+=x,s()),!o(x))return u(e),null;if("."==x){if(r+=x,s(),!a(x))return u(e),null}else{for(;a(x);)r+=x,s();"."==x&&(r+=x,s())}for(;a(x);)r+=x,s();if("E"==x||"e"==x){if(r+=x,s(),("+"==x||"-"==x)&&(r+=x,s()),!a(x))return u(e),null;for(;a(x);)r+=x,s()}return r}function f(){var e=v.charAt(y+1);if("I"==x||"i"==x)return s(),"1";if(!("+"!=x&&"-"!=x||"I"!=e&&"i"!=e)){var r="+"==x?"1":"-1";return s(),s(),r}return null}var l=t(175),p=t(11),m=l.number,h=l.number.isNumber,g=p.isUnit,d=l.string.isString;n.isComplex=function(e){return e instanceof n};var v,y,x;n.parse=function(e){if(v=e,y=-1,x="",!d(v))return null;s(),i();var r=c();if(r){if("I"==x||"i"==x)return s(),i(),x?null:new n(0,Number(r));i();var t=x;if("+"!=t&&"-"!=t)return i(),x?null:new n(Number(r),0);s(),i();var o=c();if(o){if("I"!=x&&"i"!=x)return null;s()}else if(o=f(),!o)return null;return"-"==t&&(o="-"==o[0]?"+"+o.substring(1):"-"+o),s(),i(),x?null:new n(Number(r),Number(o))}return(r=f())?(i(),x?null:new n(0,Number(r))):null},n.fromPolar=function(e){switch(arguments.length){case 1:var r=arguments[0];if("object"==typeof r)return n.fromPolar(r.r,r.phi);throw new TypeError("Input has to be an object with r and phi keys.");case 2:var t=arguments[0],i=arguments[1];if(h(t)){if(g(i)&&i.hasBase(p.BASE_UNITS.ANGLE)&&(i=i.toNumber("rad")),h(i))return new n(t*Math.cos(i),t*Math.sin(i));throw new TypeError("Phi is not a number nor an angle unit.")}throw new TypeError("Radius r is not a number.");default:throw new SyntaxError("Wrong number of arguments in function fromPolar")}},n.prototype.toPolar=function(){return{r:Math.sqrt(this.re*this.re+this.im*this.im),phi:Math.atan2(this.im,this.re)}},n.prototype.clone=function(){return new n(this.re,this.im)},n.prototype.equals=function(e){return this.re===e.re&&this.im===e.im},n.prototype.format=function(e){var r="",t=this.im,n=this.re,i=m.format(this.re,e),o=m.format(this.im,e),a=h(e)?e:e?e.precision:null;if(null!==a){var s=Math.pow(10,-a);Math.abs(n/t)<s&&(n=0),Math.abs(t/n)<s&&(t=0)}return r=0==t?i:0==n?1==t?"i":-1==t?"-i":o+"i":t>0?1==t?i+" + i":i+" + "+o+"i":-1==t?i+" - i":i+" - "+o.substring(1)+"i"},n.prototype.toString=function(){return this.format()},n.prototype.toJSON=function(){return{mathjs:"Complex",re:this.re,im:this.im}},n.fromJSON=function(e){return new n(e)},n.prototype.valueOf=n.prototype.toString,e.exports=n},function(e,r,t){"use strict";function n(e,r,t){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(null!=e&&!o.isNumber(e))throw new TypeError("Parameter start must be a number");if(null!=r&&!o.isNumber(r))throw new TypeError("Parameter end must be a number");if(null!=t&&!o.isNumber(t))throw new TypeError("Parameter step must be a number");this.start=null!=e?parseFloat(e):0,this.end=null!=r?parseFloat(r):0,this.step=null!=t?parseFloat(t):1}{var i=t(175),o=i.number,a=i.string;i.array}n.parse=function(e){if(!a.isString(e))return null;var r=e.split(":"),t=r.map(function(e){return parseFloat(e)}),i=t.some(function(e){return isNaN(e)});if(i)return null;switch(t.length){case 2:return new n(t[0],t[1]);case 3:return new n(t[0],t[2],t[1]);default:return null}},n.prototype.clone=function(){return new n(this.start,this.end,this.step)},n.isRange=function(e){return e instanceof n},n.prototype.size=function(){var e=0,r=this.start,t=this.step,n=this.end,i=n-r;return o.sign(t)==o.sign(i)?e=Math.ceil(i/t):0==i&&(e=0),isNaN(e)&&(e=0),[e]},n.prototype.min=function(){var e=this.size()[0];return e>0?this.step>0?this.start:this.start+(e-1)*this.step:void 0},n.prototype.max=function(){var e=this.size()[0];return e>0?this.step>0?this.start+(e-1)*this.step:this.start:void 0},n.prototype.forEach=function(e){var r=this.start,t=this.step,n=this.end,i=0;if(t>0)for(;n>r;)e(r,i,this),r+=t,i++;else if(0>t)for(;r>n;)e(r,i,this),r+=t,i++},n.prototype.map=function(e){var r=[];return this.forEach(function(t,n,i){r[n]=e(t,n,i)}),r},n.prototype.toArray=function(){var e=[];return this.forEach(function(r,t){e[t]=r}),e},n.prototype.valueOf=function(){return this.toArray()},n.prototype.format=function(e){var r=o.format(this.start,e);return 1!=this.step&&(r+=":"+o.format(this.step,e)),r+=":"+o.format(this.end,e)},n.prototype.toString=function(){return this.format()},n.prototype.toJSON=function(){return{mathjs:"Range",start:this.start,end:this.end,step:this.step}},n.fromJSON=function(e){return new n(e.start,e.end,e.step)},e.exports=n},function(e,r,t){"use strict";function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");this._ranges=[],this._isScalar=!0;for(var r=0,t=arguments.length;t>r;r++){var o=arguments[r];if(o instanceof a)this._ranges.push(o),this._isScalar=!1;else if(f(o))this._ranges.push(i(o)),this._isScalar=!1;else if(u(o))this._ranges.push(i([o,o+1]));else{var s=o.valueOf();if(!f(s))throw new TypeError("Ranges must be an Array, Number, or Range");this._ranges.push(i(s)),this._isScalar=!1}}}function i(e){for(var r=e.length,t=0;r>t;t++)if(!u(e[t])||!c(e[t]))throw new TypeError("Index parameters must be integer numbers");switch(e.length){case 2:return new a(e[0],e[1]);case 3:return new a(e[0],e[1],e[2]);default:throw new SyntaxError("Wrong number of arguments in Index (2 or 3 expected)")}}var o=t(175),a=t(8),s=o.number,u=s.isNumber,c=s.isInteger,f=Array.isArray;n.prototype.clone=function(){var e=new n;return e._ranges=o.object.clone(this._ranges),e._isScalar=this._isScalar,e},n.isIndex=function(e){return e instanceof n},n.create=function(e){var r=new n;return n.apply(r,e),r},n.prototype.size=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r];e[r]=n.size()[0]}return e},n.prototype.max=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r];e[r]=n.max()}return e},n.prototype.min=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r];e[r]=n.min()}return e},n.prototype.forEach=function(e){for(var r=0,t=this._ranges.length;t>r;r++)e(this._ranges[r],r,this)},n.prototype.range=function(e){return this._ranges[e]||null},n.prototype.isScalar=function(){return this._isScalar},n.prototype.toArray=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r],i=[],o=n.start,a=n.end,s=n.step;if(s>0)for(;a>o;)i.push(o),o+=s;else if(0>s)for(;o>a;)i.push(o),o+=s;e.push(i)}return e},n.prototype.valueOf=n.prototype.toArray,n.prototype.toString=function(){for(var e=[],r=0,t=this._ranges.length;t>r;r++){var n=this._ranges[r],i=s.format(n.start);1!=n.step&&(i+=":"+s.format(n.step)),i+=":"+s.format(n.end),e.push(i)}return"["+e.join(", ")+"]"},n.prototype.toJSON=function(){return{mathjs:"Index",ranges:this._ranges}},n.fromJSON=function(e){return n.create(e.ranges)},e.exports=n},function(e,r,t){"use strict";var n=t(176),i=n.isString;e.exports=function(e){function r(){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator")}return r.isMatrix=function(e){return e instanceof r},r.storage=function(e){if(!i(e))throw new TypeError("format must be a string value");var t=r._storage[e];if(!t)throw new SyntaxError("Unsupported matrix storage format: "+e);return t},r._storage={},r.prototype.storage=function(){throw new Error("Cannot invoke storage on a Matrix interface")},r.prototype.subset=function(e,r,t){throw new Error("Cannot invoke subset on a Matrix interface")},r.prototype.get=function(e){throw new Error("Cannot invoke get on a Matrix interface")},r.prototype.set=function(e,r,t){throw new Error("Cannot invoke set on a Matrix interface")},r.prototype.resize=function(e,r){throw new Error("Cannot invoke resize on a Matrix interface")},r.prototype.clone=function(){throw new Error("Cannot invoke clone on a Matrix interface")},r.prototype.size=function(){throw new Error("Cannot invoke size on a Matrix interface")},r.prototype.map=function(e,r){throw new Error("Cannot invoke map on a Matrix interface")},r.prototype.forEach=function(e){throw new Error("Cannot invoke forEach on a Matrix interface")},r.prototype.toArray=function(){throw new Error("Cannot invoke toArray on a Matrix interface")},r.prototype.valueOf=function(){throw new Error("Cannot invoke valueOf on a Matrix interface")},r.prototype.format=function(e){throw new Error("Cannot invoke format on a Matrix interface")},r.prototype.toString=function(){throw new Error("Cannot invoke toString on a Matrix interface")},r.prototype.transpose=function(){throw new Error("Cannot invoke transpose on a Matrix interface")},r.prototype.trace=function(){throw new Error("Cannot invoke transpose on a Matrix interface")},r.prototype.multiply=function(e){throw new Error("Cannot invoke multiply on a Matrix interface")},r}},function(e,r,t){"use strict";function n(e,r){if(!(this instanceof n))throw new Error("Constructor must be called with the new operator");if(void 0!=e&&!y(e))throw new TypeError("First parameter in Unit constructor must be a number");if(void 0!=r&&(!x(r)||""==r))throw new TypeError("Second parameter in Unit constructor must be a string");if(void 0!=r){var t=l(r);if(!t)throw new SyntaxError('Unknown unit "'+r+'"');this.unit=t.unit,this.prefix=t.prefix}else this.unit=M,this.prefix=b;this.value=void 0!=e?this._normalize(e):null,this.fixPrefix=!1}function i(){for(;" "==h||" "==h;)s()}function o(e){return e>="0"&&"9">=e||"."==e}function a(e){return e>="0"&&"9">=e}function s(){m++,h=p.charAt(m)}function u(e){m=e,h=p.charAt(m)}function c(){var e,r="";if(e=m,"+"==h?s():"-"==h&&(r+=h,s()),!o(h))return u(e),null;if("."==h){if(r+=h,s(),!a(h))return u(e),null}else{for(;a(h);)r+=h,s();"."==h&&(r+=h,s())}for(;a(h);)r+=h,s();if("E"==h||"e"==h){if(r+=h,s(),("+"==h||"-"==h)&&(r+=h,s()),!a(h))return u(e),null;for(;a(h);)r+=h,s()}return r}function f(){var e="";for(i();h&&" "!=h&&" "!=h;)e+=h,s();return e||null}function l(e){for(var r in _)if(_.hasOwnProperty(r)&&v.endsWith(e,r)){var t=_[r],n=e.length-r.length,i=e.substring(0,n),o=t.prefixes[i];if(void 0!==o)return{unit:t,prefix:o}}return null}var p,m,h,g=t(175),d=g.number,v=g.string,y=g.number.isNumber,x=g.string.isString;n.parse=function(e){if(p=e,m=-1,h="",!x(p))return null;s(),i();var r,t=c();if(t){if(r=f(),s(),i(),h)return null;if(t&&r)try{return new n(Number(t),r)}catch(o){}}else{if(r=f(),s(),i(),h)return null;if(r)try{return new n(null,r)}catch(o){}}return null},n.isUnit=function(e){return e instanceof n},n.prototype.clone=function(){var e=new n;for(var r in this)this.hasOwnProperty(r)&&(e[r]=this[r]);return e},n.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},n.prototype._denormalize=function(e,r){return void 0==r?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/r-this.unit.offset},n.isValuelessUnit=function(e){return null!=l(e)},n.prototype.hasBase=function(e){return this.unit.base===e},n.prototype.equalBase=function(e){return this.unit.base===e.unit.base},n.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},n.prototype.to=function(e){var r,t=null==this.value?this._normalize(1):this.value;if(x(e)){if(r=new n(null,e),!this.equalBase(r))throw new Error("Units do not match");return r.value=t,r.fixPrefix=!0,r}if(e instanceof n){if(!this.equalBase(e))throw new Error("Units do not match");if(null!==e.value)throw new Error("Cannot convert to a unit with a value");return r=e.clone(),r.value=t,r.fixPrefix=!0,r}throw new Error("String or Unit expected as parameter")},n.prototype.toNumber=function(e){var r=this.to(e);return r._denormalize(r.value,r.prefix.value)},n.prototype.toString=function(){return this.format()},n.prototype.toJSON=function(){return{mathjs:"Unit",value:this._denormalize(this.value),unit:this.prefix.name+this.unit.name,fixPrefix:this.fixPrefix}},n.fromJSON=function(e){var r=new n(e.value,e.unit);return r.fixPrefix=e.fixPrefix||!1,r},n.prototype.valueOf=n.prototype.toString,n.prototype.format=function(e){var r,t;if(null===this.value||this.fixPrefix)r=this._denormalize(this.value),t=null!==this.value?d.format(r,e)+" ":"",t+=this.prefix.name+this.unit.name;else{var n=this._bestPrefix();r=this._denormalize(this.value,n.value),t=d.format(r,e)+" ",t+=n.name+this.unit.name}return t},n.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),r=b,t=Math.abs(Math.log(e/r.value)/Math.LN10-1.2),n=this.unit.prefixes;for(var i in n)if(n.hasOwnProperty(i)){var o=n[i];if(o.scientific){var a=Math.abs(Math.log(e/o.value)/Math.LN10-1.2);t>a&&(r=o,t=a)}}return r};var w={NONE:{"":{name:"",value:1,scientific:!0}},SHORT:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:10,scientific:!1},h:{name:"h",value:100,scientific:!1},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},d:{name:"d",value:.1,scientific:!1},c:{name:"c",value:.01,scientific:!1},m:{name:"m",value:.001,scientific:!0},u:{name:"u",value:1e-6,scientific:!0},n:{name:"n",value:1e-9,scientific:!0},p:{name:"p",value:1e-12,scientific:!0},f:{name:"f",value:1e-15,scientific:!0},a:{name:"a",value:1e-18,scientific:!0},z:{name:"z",value:1e-21,scientific:!0},y:{name:"y",value:1e-24,scientific:!0}},LONG:{"":{name:"",value:1,scientific:!0},deca:{name:"deca",value:10,scientific:!1},hecto:{name:"hecto",value:100,scientific:!1},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},deci:{name:"deci",value:.1,scientific:!1},centi:{name:"centi",value:.01,scientific:!1},milli:{name:"milli",value:.001,scientific:!0},micro:{name:"micro",value:1e-6,scientific:!0},nano:{name:"nano",value:1e-9,scientific:!0},pico:{name:"pico",value:1e-12,scientific:!0},femto:{name:"femto",value:1e-15,scientific:!0},atto:{name:"atto",value:1e-18,scientific:!0},zepto:{name:"zepto",value:1e-21,scientific:!0},yocto:{name:"yocto",value:1e-24,scientific:!0}},SQUARED:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:100,scientific:!1},h:{name:"h",value:1e4,scientific:!1},k:{name:"k",value:1e6,scientific:!0},M:{name:"M",value:1e12,scientific:!0},G:{name:"G",value:1e18,scientific:!0},T:{name:"T",value:1e24,scientific:!0},P:{name:"P",value:1e30,scientific:!0},E:{name:"E",value:1e36,scientific:!0},Z:{name:"Z",value:1e42,scientific:!0},Y:{name:"Y",value:1e48,scientific:!0},d:{name:"d",value:.01,scientific:!1},c:{name:"c",value:1e-4,scientific:!1},m:{name:"m",value:1e-6,scientific:!0},u:{name:"u",value:1e-12,scientific:!0},n:{name:"n",value:1e-18,scientific:!0},p:{name:"p",value:1e-24,scientific:!0},f:{name:"f",value:1e-30,scientific:!0},a:{name:"a",value:1e-36,scientific:!0},z:{name:"z",value:1e-42,scientific:!0},y:{name:"y",value:1e-42,scientific:!0}},CUBIC:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:1e3,scientific:!1},h:{name:"h",value:1e6,scientific:!1},k:{name:"k",value:1e9,scientific:!0},M:{name:"M",value:1e18,scientific:!0},G:{name:"G",value:1e27,scientific:!0},T:{name:"T",value:1e36,scientific:!0},P:{name:"P",value:1e45,scientific:!0},E:{name:"E",value:1e54,scientific:!0},Z:{name:"Z",value:1e63,scientific:!0},Y:{name:"Y",value:1e72,scientific:!0},d:{name:"d",value:.001,scientific:!1},c:{name:"c",value:1e-6,scientific:!1},m:{name:"m",value:1e-9,scientific:!0},u:{name:"u",value:1e-18,scientific:!0},n:{name:"n",value:1e-27,scientific:!0},p:{name:"p",value:1e-36,scientific:!0},f:{name:"f",value:1e-45,scientific:!0},a:{name:"a",value:1e-54,scientific:!0},z:{name:"z",value:1e-63,scientific:!0},y:{name:"y",value:1e-72,scientific:!0}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},Ki:{name:"Ki",value:1024,scientific:!0},Mi:{name:"Mi",value:Math.pow(1024,2),scientific:!0},Gi:{name:"Gi",value:Math.pow(1024,3),scientific:!0},Ti:{name:"Ti",value:Math.pow(1024,4),scientific:!0},Pi:{name:"Pi",value:Math.pow(1024,5),scientific:!0},Ei:{name:"Ei",value:Math.pow(1024,6),scientific:!0},Zi:{name:"Zi",value:Math.pow(1024,7),scientific:!0},Yi:{name:"Yi",value:Math.pow(1024,8),scientific:!0}},BINARY_LONG:{"":{name:"",value:1,scientific:!0},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},kibi:{name:"kibi",value:1024,scientific:!0},mebi:{name:"mebi",value:Math.pow(1024,2),scientific:!0},gibi:{name:"gibi",value:Math.pow(1024,3),scientific:!0},tebi:{name:"tebi",value:Math.pow(1024,4),scientific:!0},pebi:{name:"pebi",value:Math.pow(1024,5),scientific:!0},exi:{name:"exi",value:Math.pow(1024,6),scientific:!0},zebi:{name:"zebi",value:Math.pow(1024,7),scientific:!0},yobi:{name:"yobi",value:Math.pow(1024,8),scientific:!0}}},b={name:"",value:1,scientific:!0},E={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}},N={},M={name:"",base:N,value:1,offset:0},_={meter:{name:"meter",base:E.LENGTH,prefixes:w.LONG,value:1,offset:0},inch:{name:"inch",base:E.LENGTH,prefixes:w.NONE,value:.0254,offset:0},foot:{name:"foot",base:E.LENGTH,prefixes:w.NONE,value:.3048,offset:0},yard:{name:"yard",base:E.LENGTH,prefixes:w.NONE,value:.9144,offset:0},mile:{name:"mile",base:E.LENGTH,prefixes:w.NONE,value:1609.344,offset:0},link:{name:"link",base:E.LENGTH,prefixes:w.NONE,value:.201168,offset:0},rod:{name:"rod",base:E.LENGTH,prefixes:w.NONE,value:5.02921,offset:0},chain:{name:"chain",base:E.LENGTH,prefixes:w.NONE,value:20.1168,offset:0},angstrom:{name:"angstrom",base:E.LENGTH,prefixes:w.NONE,value:1e-10,offset:0},m:{name:"m",base:E.LENGTH,prefixes:w.SHORT,value:1,offset:0},"in":{name:"in",base:E.LENGTH,prefixes:w.NONE,value:.0254,offset:0},ft:{name:"ft",base:E.LENGTH,prefixes:w.NONE,value:.3048,offset:0},yd:{name:"yd",base:E.LENGTH,prefixes:w.NONE,value:.9144,offset:0},mi:{name:"mi",base:E.LENGTH,prefixes:w.NONE,value:1609.344,offset:0},li:{name:"li",base:E.LENGTH,prefixes:w.NONE,value:.201168,offset:0},rd:{name:"rd",base:E.LENGTH,prefixes:w.NONE,value:5.02921,offset:0},ch:{name:"ch",base:E.LENGTH,prefixes:w.NONE,value:20.1168,offset:0},mil:{name:"mil",base:E.LENGTH,prefixes:w.NONE,value:254e-7,offset:0},m2:{name:"m2",base:E.SURFACE,prefixes:w.SQUARED,value:1,offset:0},sqin:{name:"sqin",base:E.SURFACE,prefixes:w.NONE,value:64516e-8,offset:0},sqft:{name:"sqft",base:E.SURFACE,prefixes:w.NONE,value:.09290304,offset:0},sqyd:{name:"sqyd",base:E.SURFACE,prefixes:w.NONE,value:.83612736,offset:0},sqmi:{name:"sqmi",base:E.SURFACE,prefixes:w.NONE,value:2589988.110336,offset:0},sqrd:{name:"sqrd",base:E.SURFACE,prefixes:w.NONE,value:25.29295,offset:0},sqch:{name:"sqch",base:E.SURFACE,prefixes:w.NONE,value:404.6873,offset:0},sqmil:{name:"sqmil",base:E.SURFACE,prefixes:w.NONE,value:6.4516e-10,offset:0},m3:{name:"m3",base:E.VOLUME,prefixes:w.CUBIC,value:1,offset:0},L:{name:"L",base:E.VOLUME,prefixes:w.SHORT,value:.001,offset:0},l:{name:"l",base:E.VOLUME,prefixes:w.SHORT,value:.001,offset:0},litre:{name:"litre",base:E.VOLUME,prefixes:w.LONG,value:.001,offset:0},cuin:{name:"cuin",base:E.VOLUME,prefixes:w.NONE,value:16387064e-12,offset:0},cuft:{name:"cuft",base:E.VOLUME,prefixes:w.NONE,value:.028316846592,offset:0},cuyd:{name:"cuyd",base:E.VOLUME,prefixes:w.NONE,value:.764554857984,offset:0},teaspoon:{name:"teaspoon",base:E.VOLUME,prefixes:w.NONE,value:5e-6,offset:0},tablespoon:{name:"tablespoon",base:E.VOLUME,prefixes:w.NONE,value:15e-6,offset:0},drop:{name:"drop",base:E.VOLUME,prefixes:w.NONE,value:5e-8,offset:0},gtt:{name:"gtt",base:E.VOLUME,prefixes:w.NONE,value:5e-8,offset:0},minim:{name:"minim",base:E.VOLUME,prefixes:w.NONE,value:6.161152e-8,offset:0},fluiddram:{name:"fluiddram",base:E.VOLUME,prefixes:w.NONE,value:36966911e-13,offset:0},fluidounce:{name:"fluidounce",base:E.VOLUME,prefixes:w.NONE,value:2957353e-11,offset:0},gill:{name:"gill",base:E.VOLUME,prefixes:w.NONE,value:.0001182941,offset:0},cc:{name:"cc",base:E.VOLUME,prefixes:w.NONE,value:1e-6,offset:0},cup:{name:"cup",base:E.VOLUME,prefixes:w.NONE,value:.0002365882,offset:0},pint:{name:"pint",base:E.VOLUME,prefixes:w.NONE,value:.0004731765,offset:0},quart:{name:"quart",base:E.VOLUME,prefixes:w.NONE,value:.0009463529,offset:0},gallon:{name:"gallon",base:E.VOLUME,prefixes:w.NONE,value:.003785412,offset:0},beerbarrel:{name:"beerbarrel",base:E.VOLUME,prefixes:w.NONE,value:.1173478,offset:0},oilbarrel:{name:"oilbarrel",base:E.VOLUME,prefixes:w.NONE,value:.1589873,offset:0},hogshead:{name:"hogshead",base:E.VOLUME,prefixes:w.NONE,value:.238481,offset:0},fldr:{name:"fldr",base:E.VOLUME,prefixes:w.NONE,value:36966911e-13,offset:0},floz:{name:"floz",base:E.VOLUME,prefixes:w.NONE,value:2957353e-11,offset:0},gi:{name:"gi",base:E.VOLUME,prefixes:w.NONE,value:.0001182941,offset:0},cp:{name:"cp",base:E.VOLUME,prefixes:w.NONE,value:.0002365882,offset:0},pt:{name:"pt",base:E.VOLUME,prefixes:w.NONE,value:.0004731765,offset:0},qt:{name:"qt",base:E.VOLUME,prefixes:w.NONE,value:.0009463529,offset:0},gal:{name:"gal",base:E.VOLUME,prefixes:w.NONE,value:.003785412,offset:0},bbl:{name:"bbl",base:E.VOLUME,prefixes:w.NONE,value:.1173478,offset:0},obl:{name:"obl",base:E.VOLUME,prefixes:w.NONE,value:.1589873,offset:0},g:{name:"g",base:E.MASS,prefixes:w.SHORT,value:.001,offset:0},gram:{name:"gram",base:E.MASS,prefixes:w.LONG,value:.001,offset:0},ton:{name:"ton",base:E.MASS,prefixes:w.SHORT,value:907.18474,offset:0},tonne:{name:"tonne",base:E.MASS,prefixes:w.SHORT, value:1e3,offset:0},grain:{name:"grain",base:E.MASS,prefixes:w.NONE,value:6479891e-11,offset:0},dram:{name:"dram",base:E.MASS,prefixes:w.NONE,value:.0017718451953125,offset:0},ounce:{name:"ounce",base:E.MASS,prefixes:w.NONE,value:.028349523125,offset:0},poundmass:{name:"poundmass",base:E.MASS,prefixes:w.NONE,value:.45359237,offset:0},hundredweight:{name:"hundredweight",base:E.MASS,prefixes:w.NONE,value:45.359237,offset:0},stick:{name:"stick",base:E.MASS,prefixes:w.NONE,value:.115,offset:0},stone:{name:"stone",base:E.MASS,prefixes:w.NONE,value:6350,offset:0},gr:{name:"gr",base:E.MASS,prefixes:w.NONE,value:6479891e-11,offset:0},dr:{name:"dr",base:E.MASS,prefixes:w.NONE,value:.0017718451953125,offset:0},oz:{name:"oz",base:E.MASS,prefixes:w.NONE,value:.028349523125,offset:0},lbm:{name:"lbm",base:E.MASS,prefixes:w.NONE,value:.45359237,offset:0},cwt:{name:"cwt",base:E.MASS,prefixes:w.NONE,value:45.359237,offset:0},s:{name:"s",base:E.TIME,prefixes:w.SHORT,value:1,offset:0},min:{name:"min",base:E.TIME,prefixes:w.NONE,value:60,offset:0},h:{name:"h",base:E.TIME,prefixes:w.NONE,value:3600,offset:0},second:{name:"second",base:E.TIME,prefixes:w.LONG,value:1,offset:0},sec:{name:"sec",base:E.TIME,prefixes:w.LONG,value:1,offset:0},minute:{name:"minute",base:E.TIME,prefixes:w.NONE,value:60,offset:0},hour:{name:"hour",base:E.TIME,prefixes:w.NONE,value:3600,offset:0},day:{name:"day",base:E.TIME,prefixes:w.NONE,value:86400,offset:0},rad:{name:"rad",base:E.ANGLE,prefixes:w.NONE,value:1,offset:0},deg:{name:"deg",base:E.ANGLE,prefixes:w.NONE,value:.017453292519943295,offset:0},grad:{name:"grad",base:E.ANGLE,prefixes:w.NONE,value:.015707963267948967,offset:0},cycle:{name:"cycle",base:E.ANGLE,prefixes:w.NONE,value:6.283185307179586,offset:0},A:{name:"A",base:E.CURRENT,prefixes:w.SHORT,value:1,offset:0},ampere:{name:"ampere",base:E.CURRENT,prefixes:w.LONG,value:1,offset:0},K:{name:"K",base:E.TEMPERATURE,prefixes:w.NONE,value:1,offset:0},degC:{name:"degC",base:E.TEMPERATURE,prefixes:w.NONE,value:1,offset:273.15},degF:{name:"degF",base:E.TEMPERATURE,prefixes:w.NONE,value:1/1.8,offset:459.67},degR:{name:"degR",base:E.TEMPERATURE,prefixes:w.NONE,value:1/1.8,offset:0},kelvin:{name:"kelvin",base:E.TEMPERATURE,prefixes:w.NONE,value:1,offset:0},celsius:{name:"celsius",base:E.TEMPERATURE,prefixes:w.NONE,value:1,offset:273.15},fahrenheit:{name:"fahrenheit",base:E.TEMPERATURE,prefixes:w.NONE,value:1/1.8,offset:459.67},rankine:{name:"rankine",base:E.TEMPERATURE,prefixes:w.NONE,value:1/1.8,offset:0},mol:{name:"mol",base:E.AMOUNT_OF_SUBSTANCE,prefixes:w.NONE,value:1,offset:0},mole:{name:"mole",base:E.AMOUNT_OF_SUBSTANCE,prefixes:w.NONE,value:1,offset:0},cd:{name:"cd",base:E.LUMINOUS_INTENSITY,prefixes:w.NONE,value:1,offset:0},candela:{name:"candela",base:E.LUMINOUS_INTENSITY,prefixes:w.NONE,value:1,offset:0},N:{name:"N",base:E.FORCE,prefixes:w.SHORT,value:1,offset:0},newton:{name:"newton",base:E.FORCE,prefixes:w.LONG,value:1,offset:0},lbf:{name:"lbf",base:E.FORCE,prefixes:w.NONE,value:4.4482216152605,offset:0},poundforce:{name:"poundforce",base:E.FORCE,prefixes:w.NONE,value:4.4482216152605,offset:0},b:{name:"b",base:E.BIT,prefixes:w.BINARY_SHORT,value:1,offset:0},bits:{name:"bits",base:E.BIT,prefixes:w.BINARY_LONG,value:1,offset:0},B:{name:"B",base:E.BIT,prefixes:w.BINARY_SHORT,value:8,offset:0},bytes:{name:"bytes",base:E.BIT,prefixes:w.BINARY_LONG,value:8,offset:0}},A={meters:"meter",inches:"inch",feet:"foot",yards:"yard",miles:"mile",links:"link",rods:"rod",chains:"chain",angstroms:"angstrom",litres:"litre",teaspoons:"teaspoon",tablespoons:"tablespoon",minims:"minim",fluiddrams:"fluiddram",fluidounces:"fluidounce",gills:"gill",cups:"cup",pints:"pint",quarts:"quart",gallons:"gallon",beerbarrels:"beerbarrel",oilbarrels:"oilbarrel",hogsheads:"hogshead",gtts:"gtt",grams:"gram",tons:"ton",tonnes:"tonne",grains:"grain",drams:"dram",ounces:"ounce",poundmasses:"poundmass",hundredweights:"hundredweight",sticks:"stick",seconds:"second",minutes:"minute",hours:"hour",days:"day",radians:"rad",degrees:"deg",gradients:"grad",cycles:"cycle",amperes:"ampere",moles:"mole"};for(var T in A)if(A.hasOwnProperty(T)){var O=_[A[T]],S=Object.create(O);S.name=T,_[T]=S}_.lt=_.l,_.liter=_.litre,_.liters=_.litres,_.lb=_.lbm,_.lbs=_.lbm,n.PREFIXES=w,n.BASE_UNITS=E,n.UNITS=_,e.exports=n},function(e,r,t){"use strict";function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(!e)throw new Error('Argument "doc" missing');this.doc=e}var i=t(175),o=i.object,a=i.string;n.isHelp=function(e){return e instanceof n},n.prototype.toText=function(e){var r=this.doc||{},t="\n";if(r.name&&(t+="Name: "+r.name+"\n\n"),r.category&&(t+="Category: "+r.category+"\n\n"),r.description&&(t+="Description:\n "+r.description+"\n\n"),r.syntax&&(t+="Syntax:\n "+r.syntax.join("\n ")+"\n\n"),r.examples){var i=e&&e.parser();t+="Examples:\n";for(var o=0;o<r.examples.length;o++){var s=r.examples[o];if(t+=" "+s+"\n",i){var u;try{u=i.eval(s)}catch(c){u=c}void 0===u||u instanceof n||(t+=" "+a.format(u,{precision:14})+"\n")}}t+="\n"}return r.seealso&&(t+="See also: "+r.seealso.join(", ")+"\n"),t},n.prototype.toString=function(){return this.toText()},n.prototype.toJSON=function(){var e=o.clone(this.doc);return e.mathjs="Help",e},n.fromJSON=function(e){var r={};for(var t in e)"mathjs"!==t&&(r[t]=e[t]);return new n(r)},n.prototype.valueOf=n.prototype.toString,e.exports=n},function(e,r,t){"use strict";function n(e){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");this.entries=e||[]}n.prototype.valueOf=function(){return this.entries},n.prototype.toString=function(){return"["+this.entries.join(", ")+"]"},n.prototype.toJSON=function(){return{mathjs:"ResultSet",entries:this.entries}},n.fromJSON=function(e){return new n(e.entries)},e.exports=n},function(e,r,t){"use strict";var n=t(175),i=t(173),o=t(172),a=n.array,s=n.array.isArray;e.exports=function(e){function r(e,n,i){var o,a,u,c;if(0>=n){if(s(e[0])){for(c=t(e),a=[],o=0;o<c.length;o++)a[o]=r(c[o],n-1,i);return a}for(u=e[0],o=1;o<e.length;o++)u=i(u,e[o]);return u}for(a=[],o=0;o<e.length;o++)a[o]=r(e[o],n-1,i);return a}function t(e){var r,t,n=e.length,i=e[0].length,o=[];for(t=0;i>t;t++){var a=[];for(r=0;n>r;r++)a.push(e[r][t]);o.push(a)}return o}var u=e.type.Matrix,c={};return c.argsToArray=function(e){if(0===e.length)return[];if(1==e.length){var r=e[0];return r instanceof u&&(r=r.valueOf()),s(r)||(r=[r]),r}return n.array.argsToArray(e)},c.isCollection=function(e){return s(e)||e instanceof u},c.deepMap=function f(e,r,t){return e&&"function"==typeof e.map?e.map(function(e){return f(e,r,t)}):r(e)},c.deepMap2=function l(r,t,n){var i,a,c;if(s(r))if(s(t)){if(r.length!=t.length)throw new o(r.length,t.length);for(i=[],a=r.length,c=0;a>c;c++)i[c]=l(r[c],t[c],n)}else{if(t instanceof u)return i=l(r,t.valueOf(),n),e.matrix(i);for(i=[],a=r.length,c=0;a>c;c++)i[c]=l(r[c],t,n)}else{if(r instanceof u)return t instanceof u?(i=l(r.valueOf(),t.valueOf(),n),e.matrix(i)):(i=l(r.valueOf(),t,n),e.matrix(i));if(s(t))for(i=[],a=t.length,c=0;a>c;c++)i[c]=l(r,t[c],n);else{if(t instanceof u)return i=l(r,t.valueOf(),n),e.matrix(i);i=n(r,t)}}return i},c.reduce=function(t,n,o){var c=s(t)?a.size(t):t.size();if(0>n)throw new i(n);if(n>=c.length)throw new i(n,c.length);return t instanceof u?e.matrix(r(t.valueOf(),n,o)):r(t,n,o)},c.deepForEach=function p(e,r){e instanceof u&&(e=e.valueOf());for(var t=0,n=e.length;n>t;t++){var i=e[t];s(i)?p(i,r):r(i)}},c}},function(e,r,t){"use strict";var n=t(175),i=t(172),o=n.array,a=n.object,s=n.string,u=n.number,c=Array.isArray,f=n.number.isNumber,l=n.number.isInteger,p=o.validateIndex;e.exports=function(e){function r(e){if(!(this instanceof r))throw new SyntaxError("Constructor must be called with the new operator");if(e instanceof h)"CcsMatrix"===e.type?(this._values=a.clone(e._values),this._index=a.clone(e._index),this._ptr=a.clone(e._ptr),this._size=a.clone(e._size)):g(this,e.valueOf());else if(e&&c(e.values)&&c(e.index)&&c(e.ptr)&&c(e.size))this._values=e.values,this._index=e.index,this._ptr=e.ptr,this._size=e.size;else if(c(e))g(this,e);else{if(e)throw new TypeError("Unsupported type of data ("+n.types.type(e)+")");this._values=[],this._index=[],this._ptr=[0],this._size=[0]}}var t=e.type.Index,m=e.type.BigNumber,h=e.type.Matrix,g=function(r,t){r._values=[],r._index=[],r._ptr=[];var n=t.length,i=0;if(n>0){var o=0;do{r._ptr.push(r._values.length);for(var a=0;n>a;a++){var s=t[a];if(c(s)){if(0===o&&i<s.length&&(i=s.length),o<s.length){var u=s[o];e.equal(u,0)||(r._values.push(u),r._index.push(a))}}else 0===o&&1>i&&(i=1),e.equal(s,0)||(r._values.push(s),r._index.push(a))}o++}while(i>o)}r._ptr.push(r._values.length),r._size=[n,i]};r.prototype=new e.type.Matrix,r.prototype.type="CcsMatrix",r.prototype.storage=function(){return"ccs"},r.prototype.subset=function(e,r,t){switch(arguments.length){case 1:return d(this,e);case 2:case 3:return v(this,e,r,t);default:throw new SyntaxError("Wrong number of arguments")}};var d=function(e,r){if(!(r instanceof t))throw new TypeError("Invalid index");var n=r.isScalar();if(n)return e.get(r.min());var o=r.size();if(o.length!=e._size.length)throw new i(o.length,e._size.length);for(var a=r.min(),s=r.max(),u=0,c=e._size.length;c>u;u++)p(a[u],e._size[u]),p(s[u],e._size[u]);var f=function(e){return e};return E(e,a[0],s[0],a[1],s[1],f,!1)},v=function(e,r,n,s){if(!(r instanceof t))throw new TypeError("Invalid index");var u,c=r.size(),f=r.isScalar();if(n instanceof h?(u=n.size(),n=n.toArray()):u=o.size(n),f){if(0!==u.length)throw new TypeError("Scalar expected");e.set(r.min(),n,s)}else{if(1!==c.length&&2!==c.length)throw new i(c.length,e._size.length,"<");if(u.length<c.length){for(var l=0,p=0;1===c[l]&&1===u[l];)l++;for(;1===c[l];)p++,l++;n=o.unsqueeze(n,c.length,p,u)}if(!a.deepEqual(c,u))throw new i(c,u,">");for(var m=r.min()[0],g=r.min()[1],d=u[0],v=u[1],y=0;d>y;y++)for(var x=0;v>x;x++){var w=n[y][x];e.set([y+m,x+g],w,s)}}return e};r.prototype.get=function(e){if(!c(e))throw new TypeError("Array expected");if(e.length!=this._size.length)throw new i(e.length,this._size.length);var r=e[0],t=e[1];p(r,this._size[0]),p(t,this._size[1]);var n=y(r,this._ptr[t],this._ptr[t+1],this._index);return n<this._ptr[t+1]&&this._index[n]===r?a.clone(this._values[n]):0},r.prototype.set=function(r,t,n){if(!c(r))throw new TypeError("Array expected");if(r.length!=this._size.length)throw new i(r.length,this._size.length);var o=r[0],a=r[1],s=this._size[0],u=this._size[1];(o>s-1||a>u-1)&&(b(this,Math.max(o+1,s),Math.max(a+1,u),n),s=this._size[0],u=this._size[1]),p(o,s),p(a,u);var f=y(o,this._ptr[a],this._ptr[a+1],this._index);return f<this._ptr[a+1]&&this._index[f]===o?e.equal(t,0)?x(f,a,this._values,this._index,this._ptr):this._values[f]=t:w(f,o,a,t,this._values,this._index,this._ptr),this};var y=function(e,r,t,n){if(t-r===0||e>n[t-1])return t;for(;t>r;){var i=~~((r+t)/2),o=n[i];if(o>e)t=i;else{if(!(e>o))return i;r=i+1}}return r},x=function(e,r,t,n,i){t.splice(e,1),n.splice(e,1);for(var o=r+1;o<i.length;o++)i[o]--},w=function(e,r,t,n,i,o,a){i.splice(e,0,n),o.splice(e,0,r);for(var s=t+1;s<a.length;s++)a[s]++};r.prototype.resize=function(e,r,t){if(!c(e))throw new TypeError("Array expected");if(2!==e.length)throw new Error("Only two dimensions matrix are supported");e.forEach(function(r){if(!u.isNumber(r)||!u.isInteger(r)||0>r)throw new TypeError("Invalid size, must contain positive integers (size: "+s.format(e)+")")});var n=t?this.clone():this;return b(n,e[0],e[1],r)};var b=function(r,t,n,i){var o,a,s,u=i||0,c=!e.equal(u,0),f=r._size[0],l=r._size[1];if(n>l){for(a=l;n>a;a++)if(r._ptr[a]=r._values.length,c)for(o=0;f>o;o++)r._values.push(u),r._index.push(o);r._ptr[n]=r._values.length}else l>n&&(r._ptr.splice(n+1,l-n),r._values.splice(r._ptr[n],r._values.length),r._index.splice(r._ptr[n],r._index.length));if(l=n,t>f){if(c){var p=0;for(a=0;l>a;a++){r._ptr[a]=r._ptr[a]+p,s=r._ptr[a+1]+p;var m=0;for(o=f;t>o;o++,m++)r._values.splice(s+m,0,u),r._index.splice(s+m,0,o),p++}r._ptr[l]=r._values.length}}else if(f>t){var h=0;for(a=0;l>a;a++){r._ptr[a]=r._ptr[a]-h;var g=r._ptr[a],d=r._ptr[a+1]-h;for(s=g;d>s;s++)o=r._index[s],o>t-1&&(r._values.splice(s,1),r._index.splice(s,1),h++)}r._ptr[a]=r._values.length}return r._size[0]=t,r._size[1]=n,r};r.prototype.clone=function(){var e=new r({values:a.clone(this._values),index:a.clone(this._index),ptr:a.clone(this._ptr),size:a.clone(this._size)});return e},r.prototype.size=function(){return a.clone(this._size)},r.prototype.map=function(e,r){var t=this,n=this._size[0],i=this._size[1],o=function(r,n,i){return e(r,[n,i],t)};return E(this,0,n-1,0,i-1,o,r)};var E=function(t,n,i,o,a,s,u){for(var c=[],f=[],l=[],p=function(r,t,n){r=s(r,t,n),e.equal(r,0)||(c.push(r),f.push(t))},m=o;a>=m;m++){l.push(c.length);for(var h=t._ptr[m],g=t._ptr[m+1],d=n,v=h;g>v;v++){var y=t._index[v];if(y>=n&&i>=y){if(!u)for(var x=d;y>x;x++)p(0,x-n,m-o);p(t._values[v],y-n,m-o)}d=y+1}if(!u)for(var w=d;i>=w;w++)p(0,w-n,m-o)}return l.push(c.length),new r({values:c,index:f,ptr:l,size:[i-n+1,a-o+1]})};r.prototype.forEach=function(e,r){for(var t=this,n=this._size[0],i=this._size[1],o=0;i>o;o++){for(var a=this._ptr[o],s=this._ptr[o+1],u=0,c=a;s>c;c++){var f=this._index[c];if(!r)for(var l=u;f>l;l++)e(0,[l,o],t);e(this._values[c],[f,o],t),u=f+1}if(!r)for(var p=u;n>p;p++)e(0,[p,o],t)}},r.prototype.toArray=function(){return N(this,!0)},r.prototype.valueOf=function(){return N(this,!1)};var N=function(e,r){for(var t=[],n=e._size[0],i=e._size[1],o=0;i>o;o++){for(var s=e._ptr[o],u=e._ptr[o+1],c=0,f=s;u>f;f++){for(var l=e._index[f],p=c;l>p;p++)(t[p]=t[p]||[])[o]=0;(t[l]=t[l]||[])[o]=r?a.clone(e._values[f]):e._values[f],c=l+1}for(var m=c;n>m;m++)(t[m]=t[m]||[])[o]=0}return t};r.prototype.format=function(e){for(var r=this._size[0],t=this._size[1],n="CCS ["+s.format(r,e)+" x "+s.format(t,e)+"] density: "+s.format(this._values.length/(r*t),e)+"\n",i=0;t>i;i++)for(var o=this._ptr[i],a=this._ptr[i+1],u=o;a>u;u++){var c=this._index[u];n+="\n ("+s.format(c,e)+", "+s.format(i,e)+") ==> "+s.format(this._values[u],e)}return n},r.prototype.toString=function(){return s.format(this.toArray())},r.prototype.toJSON=function(){return{mathjs:"CcsMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size}},r.prototype.transpose=function(){var r=this._size[0],t=this._size[1];if(0===t)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+s.format(this._size)+")");return new e.type.CrsMatrix({values:a.clone(this._values),index:a.clone(this._index),ptr:a.clone(this._ptr),size:[t,r]})},r.prototype.diagonal=function(e){if(e){if(e instanceof m&&(e=e.toNumber()),!f(e)||!l(e))throw new TypeError("The parameter k must be an integer number")}else e=0;for(var r=e>0?e:0,t=0>e?-e:0,n=this._size[0],i=this._size[1],o=Math.min(n-t,i-r),s=[],u=r;i>u&&s.length<o;u++){for(var c=this._ptr[u],p=this._ptr[u+1],h=!1,g=c;p>g;g++){var d=this._index[g];if(d===u-r+t){h=!0,s.push(a.clone(this._values[g]));break}if(d>u-r+t)break}!h&&s.length<o&&s.push(0)}return s},r.fromJSON=function(e){return new r(e)},r.diagonal=function(t,n,i){if(!c(t))throw new TypeError("Array expected, size parameter");if(2!==t.length)throw new Error("Only two dimensions matrix are supported");if(t=t.map(function(e){if(e instanceof m&&(e=e.toNumber()),!f(e)||!l(e)||1>e)throw new Error("Size values must be positive integers");return e}),i){if(i instanceof m&&(i=i.toNumber()),!f(i)||!l(i))throw new TypeError("The parameter k must be an integer number")}else i=0;var o,a=i>0?i:0,s=0>i?-i:0,u=t[0],p=t[1],h=Math.min(u-s,p-a);if(c(n)){if(n.length!==h)throw new Error("Invalid value array length");o=function(e){return n[e]}}else o=function(){return n};for(var g=[],d=[],v=[],y=0;p>y;y++){v.push(g.length);var x=y-a;if(x>=0&&h>x){var w=o(x);e.equal(w,0)||(d.push(x+s),g.push(w))}}return v.push(g.length),new r({values:g,index:d,ptr:v,size:[u,p]})},r.prototype.trace=function(){var r=this._size,t=r[0],n=r[1];if(t===n){var i=0;if(this._values.length>0)for(var o=0;n>o;o++)for(var a=this._ptr[o],u=this._ptr[o+1],c=a;u>c;c++){var f=this._index[c];if(f===o){i=e.add(i,this._values[c]);break}if(f>o)break}return i}throw new RangeError("Matrix must be square (size: "+s.format(r)+")")},r.prototype.multiply=function(r){var t=this._size[0],n=this._size[1];if(r instanceof h){var i=r.size();if(1===i.length)return M(this,i[0],1,function(e){return r.get([e])});if(2===i.length)return M(this,i[0],i[1],function(e,t){return r.get([e,t])});throw new Error("Can only multiply a 1 or 2 dimensional matrix (value has "+i.length+" dimensions)")}if(c(r)){var a=o.size(r);if(1===a.length)return M(this,a[0],1,function(e){return r[e]});if(2===a.length)return M(this,a[0],a[1],function(e,t){return r[e][t]});throw new Error("Can only multiply a 1 or 2 dimensional matrix (value has "+a.length+" dimensions)")}var s=function(t){return e.multiply(t,r)};return E(this,0,t-1,0,n-1,s,!1)};var M=function(t,n,i,o){var a=t._size[0],s=t._size[1];if(s!==n)throw new RangeError("Dimension mis