mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
30 lines
108 KiB
JavaScript
30 lines
108 KiB
JavaScript
/**
|
|
* 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 0.11.2-SNAPSHOT
|
|
* @date 2013-08-02
|
|
*
|
|
* @license
|
|
* Copyright (C) 2013 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(){function e(e){return e instanceof Boolean||"boolean"==typeof e}function n(e,t){if(!(this instanceof n))throw new SyntaxError("Complex constructor must be called with the new operator");switch(arguments.length){case 0:this.re=0,this.im=0;break;case 2:if(!g(e)||!g(t))throw new TypeError("Two numbers expected in Complex constructor");this.re=e,this.im=t;break;default:if(0!=arguments.length&&2!=arguments.length)throw new SyntaxError("Two or zero arguments expected in Complex constructor")}}function t(e){e&&nn.extend(this,e)}function r(e){if(!(this instanceof r))throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof r||e instanceof d)this._data=e.toArray();else if(e instanceof Array)this._data=e;else{if(null!=e)throw new TypeError("Unsupported type of data ("+en["typeof"](e)+")");this._data=[]}this._size=nn.size(this._data)}function a(e,n){return nn.validateIndex(n,e.length),e[n]}function i(e,n){return n.forEach(function(n){e=a(e,n)}),en.clone(e)}function o(e,n){var t=n[0];return t.map?t.map(function(n){return a(e,n)}):[a(e,t)]}function s(e,n){var t=n[0],r=n[1];if(t.map)return r.map?t.map(function(n){var t=a(e,n);return r.map(function(e){return a(t,e)})}):t.map(function(n){return[a(a(e,n),r)]});if(r.map){var i=a(e,t);return[r.map(function(e){return a(i,e)})]}return[[a(a(e,t),r)]]}function f(e,n,t){var r=t==n.length-1,i=n[t],o=function(i){var o=a(e,i);return r?o:f(o,n,t+1)};return i.map?i.map(o):[o(i)]}function u(e,n,t){if(nn.validateIndex(n),t instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[n]=t}function c(e,n,t,r){var a=!1;t.length>n.length&&(a=!0);for(var i=0;i<t.length;i++){var o=t[i];nn.validateIndex(o),(null==n[i]||o+1>n[i])&&(n[i]=o+1,a=!0)}a&&nn.resize(e,n,0);var s=n.length;t.forEach(function(n,t){s-1>t?e=e[n]:e[n]=r})}function l(e,n,t,r){var a=t[0];nn.validateIndex(a),a+1>n[0]&&(nn.resize(e,[a+1],0),n[0]=a+1),e[a]=r}function m(e,n,t,r){var a=t[0],i=t[1];nn.validateIndex(a),nn.validateIndex(i);var o=!1;a+1>(n[0]||0)&&(n[0]=a+1,o=!0),i+1>(n[1]||0)&&(n[1]=i+1,o=!0),o&&nn.resize(e,n,0),e[a][i]=r}function h(e,n,t,r,a){var i=r==t.length-1,o=t[r],s=function(o,s){if(i)u(e,o,a[s]),o+1>(n[r]||0)&&(n[r]=o+1);else{var f=e[o];f instanceof Array||(e[o]=f=[f]),o+1>(n[r]||0)&&(n[r]=o+1),h(f,n,t,r+1,a[s])}};if(o.map){var f=o.size&&o.size()||o.length;if(f!=a.length)throw new RangeError("Dimensions mismatch ("+f+" != "+a.length+")");o.map(s)}else s(o,0)}function p(e){for(var n=0,t=e.length;t>n;n++){var r=e[n];r instanceof Array?p(r):void 0==r&&(e[n]=0)}}function g(e){return e instanceof Number||"number"==typeof e}function v(e){return e==Math.round(e)}function d(e,n,t){if(!(this instanceof d))throw new SyntaxError("Range constructor must be called with the new operator");if(null!=e&&!g(e))throw new TypeError("Parameter start must be a number");if(null!=t&&!g(t))throw new TypeError("Parameter end must be a number");if(null!=n&&!g(n))throw new TypeError("Parameter step must be a number");this.start=null!=e?e:0,this.end=null!=t?t:0,this.step=null!=n?n:1}function y(e,n){var t=en.type.Selector,r=Array.prototype.slice;t.prototype[e]="function"==typeof n?function(){var e=[this.value].concat(r.call(arguments,0));return new t(n.apply(this,e))}:new t(n)}function x(e){return e instanceof String||"string"==typeof e}function w(e,n){if(!(this instanceof w))throw new Error("Unit constructor must be called with the new operator");if(null!=e&&!g(e))throw new TypeError("First parameter in Unit constructor must be a number");if(null!=n&&!x(n))throw new TypeError("Second parameter in Unit constructor must be a string");if(null!=n){var t=b(n);if(!t)throw new SyntaxError('String "'+n+'" is no unit');this.unit=t.unit,this.prefix=t.prefix}else this.unit=w.UNIT_NONE,this.prefix=w.PREFIX_NONE;null!=e?(this.value=this._normalize(e),this.fixPrefix=!1):(this.value=null,this.fixPrefix=!0)}function b(e){for(var n=w.UNITS,t=0,r=n.length;r>t;t++){var a=n[t];if(nn.endsWith(e,a.name)){var i=e.length-a.name.length,o=e.substring(0,i),s=a.prefixes[o];if(void 0!==s)return{unit:a,prefix:s}}}return null}function E(e,n){var t=void 0;if(2==arguments.length){var r=en["typeof"](n);t="Function "+e+"("+r+") not supported"}else if(arguments.length>2){for(var a=[],i=1;i<arguments.length;i++)a.push(en["typeof"](arguments[i]));t="Function "+e+"("+a.join(", ")+") not supported"}else t="Unsupported parameter in function "+e;return new TypeError(t)}function O(e,n,t,r){var a="Wrong number of arguments in function "+e+" ("+n+" provided, "+t+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(a)}function N(){}function M(e){this.value=e}function A(e,n,t){this.name=e,this.fn=n,this.params=t}function S(e,n){this.name=e,this.scope=n}function T(e,n,t){if(this.object=e,this.params=n,this.paramScopes=t,this.hasContextParams=!1,n)for(var r={type:en.type.SymbolNode,properties:{name:"end"}},a=0,i=n.length;i>a;a++)if(n[a].find(r).length>0){this.hasContextParams=!0;break}}function q(e){this.nodes=e||[]}function z(){this.params=[],this.visible=[]}function R(e,n,t){this.name=e,this.expr=n,this.scope=t}function C(e,n,t,r,a){this.name=e,this.params=n,this.paramScopes=t,this.expr=r,this.scope=a,this.hasContextParams=!1;for(var i={type:en.type.SymbolNode,properties:{name:"end"}},o=0,s=n.length;s>o;o++)if(n[o].find(i).length>0){this.hasContextParams=!0;break}}function U(e,n,t,r,a){this.name=e,this.variables=n,this.expr=t,this.scope=a,this.fn=function(){var a=n?n.length:0;if(arguments.length!=a)throw O(e,arguments.length,a);for(var i=0;a>i;i++)r.set(n[i],arguments[i]);return t.eval()},this.fn.toString=function(){return e+"("+n.join(", ")+")"}}function L(e,t){var r=t.re*t.re+t.im*t.im;return 0!=r?n.create((e.re*t.re+e.im*t.im)/r,(e.im*t.re-e.re*t.im)/r):n.create(0!=e.re?e.re/0:0,0!=e.im?e.im/0:0)}function I(e,n){if(n>0)return e>0?e%n:0==e?0:e-n*Math.floor(e/n);if(0==n)return e;throw new Error("Cannot calculate mod for a negative divisor")}function P(e,t){return 0==e.im?0==t.im?e.re*t.re:0==t.re?new n(0,e.re*t.im):new n(e.re*t.re,e.re*t.im):0==e.re?0==t.im?new n(0,e.im*t.re):0==t.re?-e.im*t.im:new n(-e.im*t.im,e.im*t.re):0==t.im?new n(e.re*t.re,e.im*t.re):0==t.re?new n(-e.im*t.im,e.re*t.im):new n(e.re*t.re-e.im*t.im,e.re*t.im+e.im*t.re)}function _(e,n){var t=en.log(e),r=en.multiply(t,n);return en.exp(r)}function B(e,n){if(n){var t=Math.pow(10,n);return Math.round(e*t)/t}return Math.round(e)}function G(e){if(e instanceof Array||e instanceof r||e instanceof d){for(var n=e.valueOf(),t="[",a=n.length,i=0;a>i;i++)0!=i&&(t+=", "),t+=G(n[i]);return t+="]"}return g(e)?nn.formatNumber(e):e.toString()}function j(e,n,t,r){if(t>r){if(e.length!=n.length)throw new Error("Dimensions mismatch ("+e.length+" != "+n.length+")");for(var a=[],i=0;i<e.length;i++)a[i]=j(e[i],n[i],t,r+1);return a}return e.concat(n)}function k(e,n,t){var r=en.multiply,a=en.subtract;if(1==n)return e[0][0];if(2==n)return a(r(e[0][0],e[1][1]),r(e[1][0],e[0][1]));for(var i=1,o=0,s=0;n>s&&!(o>=t);s++){for(var f=s;0==e[f][o];)if(f++,f==n&&(f=s,o++,o==t))return nn.deepEqual(e,en.eye(n).valueOf())?en.round(i,6):0;if(f!=s){for(var u=0;t>u;u++){var c=e[f][u];e[f][u]=e[s][u],e[s][u]=c}i*=-1}for(var l=e[s][o],u=0;t>u;u++)e[s][u]=e[s][u]/l;i*=l;for(var m=0;n>m;m++)if(m!=s)for(var h=e[m][o],u=0;t>u;u++)e[m][u]=e[m][u]-e[s][u]*h;o++}return nn.deepEqual(e,en.eye(n).valueOf())?en.round(i,6):0}function F(e,n,t){var r,a,i,o,s,f=en.add,u=en.unary,c=en.multiply,l=en.divide;if(1==n){if(o=e[0][0],0==o)throw Error("Cannot calculate inverse, determinant is zero");return[[l(1,o)]]}if(2==n){var m=en.det(e);if(0==m)throw Error("Cannot calculate inverse, determinant is zero");return[[l(e[1][1],m),l(u(e[0][1]),m)],[l(u(e[1][0]),m),l(e[0][0],m)]]}var h=e.concat();for(r=0;n>r;r++)h[r]=h[r].concat();for(var p=en.eye(n).valueOf(),g=0;t>g;g++){for(r=g;n>r&&0==h[r][g];)r++;if(r==n||0==h[r][g])throw Error("Cannot calculate inverse, determinant is zero");r!=g&&(s=h[g],h[g]=h[r],h[r]=s,s=p[g],p[g]=p[r],p[r]=s);var v=h[g],d=p[g];for(r=0;n>r;r++){var y=h[r],x=p[r];if(r!=g){if(0!=y[g]){for(i=l(u(y[g]),v[g]),a=g;t>a;a++)y[a]=f(y[a],c(i,v[a]));for(a=0;t>a;a++)x[a]=f(x[a],c(i,d[a]))}}else{for(i=v[g],a=g;t>a;a++)y[a]=l(y[a],i);for(a=0;t>a;a++)x[a]=l(x[a],i)}}}return p}function V(e){if(1==e.length)return V(e[0]);for(var n=0,t=e.length;t>n;n++){var r=e[n];r instanceof Array&&(e[n]=V(r))}return e}function H(e,n){var t,a;return e instanceof Array||e instanceof d?(t=en.matrix(e),a=t.get(n),a.valueOf()):e instanceof r?e.get(n):x(e)?D(e,n):(t=en.matrix([e]),a=t.get(n),a.valueOf())}function D(e,n){var t,r;if(n=n.valueOf(),1!=n.length)throw new RangeError("Dimension mismatch ("+n.length+" != 1)");n instanceof Array&&(n=n[0]),n=n.valueOf(),n instanceof Array||(n=[n]);var a="",i=e.length;for(t=0,r=n.length;r>t;t++){var o=n[t];nn.validateIndex(o,i),a+=e.charAt(o)}return a}function Y(e,n,t){if(e instanceof Array||e instanceof d){var a=en.matrix(en.clone(e));return a.set(n,t),a.valueOf()}return e instanceof r?e.clone().set(n,t):x(e)?W(e,n,t):(a=en.matrix([e]),a.set(n,t),a.isScalar()?a.toScalar():a.valueOf())}function W(e,n,t){var r,a;if(n=n.valueOf(),1!=n.length)throw new RangeError("Dimension mismatch ("+n.length+" != 1)");if(n instanceof Array&&(n=n[0]),n=n.valueOf(),n instanceof Array||(n=[n]),n.length!=t.length)throw new RangeError("Dimension mismatch ("+n.length+" != "+t.length+")");var i=e.length,o=[];for(r=0;i>r;r++)o[r]=e.charAt(r);for(r=0,a=n.length;a>r;r++){var s=n[r];nn.validateIndex(s),o[s]=t.charAt(r)}if(o.length>i)for(r=i-1,a=o.length;a>r;r++)o[r]||(o[r]=" ");return o.join("")}function Q(e){for(var n=en.larger,t=e[0],r=1,a=e.length;a>r;r++){var i=e[r];n(i,t)&&(t=i)}return t}function K(e,n,t){for(var r=en.larger,a=[],i=0;t>i;i++){for(var o=e[0][i],s=1;n>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function Z(e){for(var n=en.smaller,t=e[0],r=1,a=e.length;a>r;r++){var i=e[r];n(i,t)&&(t=i)}return t}function X(e,n,t){for(var r=en.smaller,a=[],i=0;t>i;i++){for(var o=e[0][i],s=1;n>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function $(e,n,t){(t.override||void 0===en[e])&&(en[e]=t.wrap&&"function"==typeof n?function(){for(var e=[],t=0,r=arguments.length;r>t;t++)e[t]=arguments[t].valueOf();return n.apply(en,e)}:n,y(e,n))}function J(e){return"function"==typeof e||g(e)||x(e)||e instanceof n||e instanceof w}var en={type:{},expr:{node:{handlers:{}}},docs:{},options:{precision:5}},nn=function(){function e(n){if(n instanceof Array){var t=n.length;if(t){var r=e(n[0]);return 0==r[0]?[0].concat(r):[t].concat(r)}return[t]}return[]}function n(e,t,r){var a,i=e.length;if(i!=t[r])throw new RangeError("Dimension mismatch ("+i+" != "+t[r]+")");if(r<t.length-1){var o=r+1;for(a=0;i>a;a++){var s=e[a];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(t.length-1)+" < "+t.length+")");n(e[a],t,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(t.length+1)+" > "+t.length+")")}function t(e,n,r){if(r<n.length-1){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");t(a,n,r+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,n,t,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=n[t];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?en.clone(r):0;else e.length=n[t];i=e.length}if(t<n.length-1){var f=t+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,n,f,r)}else for(s=0;i>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var i={};i.formatNumber=function(e,n){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(isNaN(e))return"NaN";var t=Math.abs(e);if(t>.001&&1e5>t||0==t)return i.toPrecision(e,n);var r=Math.round(Math.log(t)/Math.LN10),a=e/Math.pow(10,r);return i.toPrecision(a,n)+"e"+r},i.toPrecision=function(e,n){return e.toPrecision(n).replace(o,function(e,n,t){return e.substring(0,e.length-(n.length?0:1)-t.length)})};var o=/\.(\d*?)(0+)$/g;return i.formatArray=function(e){if(e instanceof Array){for(var n="[",t=e.length,r=0;t>r;r++)0!=r&&(n+=", "),n+=i.formatArray(e[r]);return n+="]"}return en.format(e)},i.formatArray2d=function(e){var n="[",t=i.size(e);if(2!=t.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(t)+")");for(var r=t[0],a=t[1],o=0;r>o;o++){0!=o&&(n+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(n+=", ");var u=s[f];void 0!=u&&(n+=en.format(u))}}return n+="]"},i.argsToArray=function(e){var n;if(0==e.length)n=[];else if(1==e.length)n=e[0],n instanceof r&&(n=n.toVector()),n instanceof d&&(n=n.valueOf()),n instanceof Array||(n=[n]);else{n=[];for(var t=0;t<e.length;t++)n[t]=e[t]}return n},i.endsWith=function(e,n){var t=e.length-n.length,r=e.length;return e.substring(t,r)===n},i.extend=function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e},i.deepExtend=function s(e,n){for(var t in n)n.hasOwnProperty(t)&&(n[t]&&n[t].constructor===Object?(void 0===e[t]&&(e[t]={}),e[t].constructor===Object?s(e[t],n[t]):e[t]=n[t]):e[t]=n[t]);return e},i.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},i.map=function(e,n){if(e instanceof Array||e instanceof r||e instanceof d)return e.map(function(e){return n(e)});throw new TypeError("Array expected")},i.deepMap=function f(e,n){return e instanceof Array||e instanceof r||e instanceof d?e.map(function(e){return f(e,n)}):n(e)},i.map2=function(e,n,t){var a,o,s;if(e instanceof r||n instanceof r)return new r(i.map2(e.valueOf(),n.valueOf(),t));if(e instanceof d||n instanceof d)return i.map2(e.valueOf(),n.valueOf(),t);if(e instanceof Array)if(n instanceof Array){if(e.length!=n.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+n.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=t(e[s],n[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=t(e[s],n);else if(n instanceof Array)for(a=[],o=n.length,s=0;o>s;s++)a[s]=t(e,n[s]);else a=t(e,n);return a},i.deepMap2=function u(e,n,t){var a,i,o;if(e instanceof r||n instanceof r)return new r(u(e.valueOf(),n.valueOf(),t));if(e instanceof d||n instanceof d)return u(e.valueOf(),n.valueOf(),t);if(e instanceof Array)if(n instanceof Array){if(e.length!=n.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+n.length+")");for(a=[],i=e.length,o=0;i>o;o++)a[o]=u(e[o],n[o],t)}else for(a=[],i=e.length,o=0;i>o;o++)a[o]=u(e[o],n,t);else if(n instanceof Array)for(a=[],i=n.length,o=0;i>o;o++)a[o]=u(e,n[o],t);else a=t(e,n);return a},i.forEach=function(e,n){if(e instanceof Array)e.forEach(n);else for(var t in e)e.hasOwnProperty(t)&&n(e[t],t,e)},i.mapObject=function(e,n){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},i.deepEqual=function(e,n){var t,r,a;if(e instanceof Array){if(!(n instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],n[r]))return!1;return!0}if(e instanceof Object){if(n instanceof Array||!(n instanceof Object))return!1;for(t in e)if(e.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;for(t in n)if(n.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;return!0}return e.valueOf()==n.valueOf()},i.size=function(n){var t=e(n);return i.validate(n,t),t},i.validate=function(e,r){var a=0==r.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=r.indexOf(0);o?(r.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(r)+")")}),t(e,r,0)):n(e,r,0)}},i.validateIndex=function(e,n){if(!g(e)||!v(e))throw new TypeError("Index must be an integer (value: "+e+")");if(0>e)throw new RangeError("Index out of range ("+e+" < 0)");if(void 0!==n&&e>=n)throw new RangeError("Index out of range ("+e+" >= "+n+")")},i.resize=function(e,n,t){if(!(n instanceof Array))throw new TypeError("Size must be an array (size is "+en["typeof"](n)+")");n.forEach(function(e){if(!g(e)||!v(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(n)+")")});var r=-1!=n.indexOf(0);r&&n.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(n)+")")}),a(e,n,0,t)},i}();en.type.Complex=n,function(){function e(){for(;" "==c||" "==c;)a()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function a(){u++,c=f.charAt(u)}function i(e){u=e,c=f.charAt(u)}function o(){var e,n="";if(e=u,"+"==c?a():"-"==c&&(n+=c,a()),!t(c))return i(e),null;if("."==c){if(n+=c,a(),!r(c))return i(e),null}else{for(;r(c);)n+=c,a();"."==c&&(n+=c,a())}for(;r(c);)n+=c,a();if("E"==c||"e"==c){if(n+=c,a(),("+"==c||"-"==c)&&(n+=c,a()),!r(c))return i(e),null;for(;r(c);)n+=c,a()}return n}function s(){var e=f.charAt(u+1);if("I"==c||"i"==c)return a(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var n="+"==c?"1":"-1";return a(),a(),n}return null}var f,u,c;n.create=function(e,t){return 0==t?e:new n(e,t)},n.parse=function(t){if(f=t,u=-1,c="",!x(f))return null;a(),e();var r=o();if(r){if("I"==c||"i"==c)return a(),e(),c?null:new n(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new n(Number(r),0);a(),e();var l=o();if(l){if("I"!=c&&"i"!=c)return null;a()}else if(l=s(),!l)return null;return"-"==i&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),a(),e(),c?null:new n(Number(r),Number(l))}return(r=s())?(e(),c?null:new n(0,Number(r))):null}}(),n.prototype.clone=function(){return new n(this.re,this.im)},n.prototype.toString=function(){var e="",n=nn.formatNumber(this.re,en.options.precision),t=nn.formatNumber(this.im,en.options.precision);return e=0==this.im?n:0==this.re?1==this.im?"i":-1==this.im?"-i":t+"i":this.im>0?1==this.im?n+" + i":n+" + "+t+"i":-1==this.im?n+" - i":n+" - "+nn.formatNumber(Math.abs(this.im),en.options.precision)+"i"},en.type.Help=t,t.prototype.toString=function(){var e="\n";if(this.name&&(e+="Name: "+this.name+"\n\n"),this.category&&(e+="Category: "+this.category+"\n\n"),this.syntax&&(e+="Syntax:\n "+this.syntax.join("\n ")+"\n\n"),this.examples){var n=en.parser();e+="Examples:\n";for(var r=0;r<this.examples.length;r++){var a,i=this.examples[r];try{a=n.eval(i)}catch(o){a=o}e+=" "+i+"\n",!a||a instanceof t||(e+=" "+en.format(a)+"\n")}e+="\n"}return this.seealso&&(e+="See also: "+this.seealso.join(", ")+"\n"),e},t.prototype.toJSON=function(){return nn.extend({},this)},en.type.Matrix=r,r.prototype.get=function(e){var n;if(e instanceof r)n=1==e.size().length||!e.size().some(function(e){return 0!=e}),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Invalid index");n=!e.some(function(e){var n=en.size(e);return 0!=n.length&&n!=[0]})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(n)switch(e.length){case 1:return a(this._data,e[0]);case 2:return a(a(this._data,e[0]),e[1]);default:return i(this._data,e)}else switch(e.length){case 1:return new r(o(this._data,e));case 2:return new r(s(this._data,e));default:return new r(f(this._data,e,0))}},r.prototype.set=function(e,n){var t;if(e instanceof r)t=1==e.size().length||!e.size().some(function(e){return 0!=e}),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Invalid index");t=!e.some(function(e){var n=en.size(e);return 0!=n.length&&n!=[0]})}if((n instanceof r||n instanceof d)&&(n=n.valueOf()),e.length<this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(t){if(0!=en.size(n).valueOf().length)throw new TypeError("Scalar value expected");switch(e.length){case 1:l(this._data,this._size,e,n);break;case 2:m(this._data,this._size,e,n);break;default:c(this._data,this._size,e,n)}}else{var a=this._size.concat();h(this._data,a,e,0,n),nn.deepEqual(this._size,a)||(p(this._data),this.resize(a))}return this},r.prototype.resize=function(e,n){nn.resize(this._data,e,n),this._size=en.clone(e)},r.prototype.clone=function(){var e=new r;return e._data=en.clone(this._data),e._size=en.clone(this._size),e},r.prototype.size=function(){return this._size},r.prototype.map=function(e){var n=this,t=new r,a=[],i=function(t,r){return t instanceof Array?t.map(function(e,n){return a[r]=n,i(e,r+1)}):e(t,a,n)};return t._data=i(this._data,0),t._size=en.clone(this._size),t},r.prototype.forEach=function(e){var n=this,t=[],r=function(a,i){a instanceof Array?a.forEach(function(e,n){t[i]=n,r(e,i+1)}):e(a,t,n)};r(this._data,0)},r.prototype.toScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=e[0];return e instanceof Array?null:en.clone(e)},r.prototype.isScalar=function(){return this._size.every(function(e){return 1>=e})},r.prototype.toVector=function(){var e=0,n=void 0,t=[];if(this._size.forEach(function(r,a){r>1&&(e++,n=a),t[a]=0}),0==e){var r=this.toScalar();return r?[r]:[]}if(1==e){var a=[],i=function(e){e instanceof Array?e.forEach(i):a.push(e)};return i(this._data),a}return null},r.prototype.isVector=function(){var e=0;return this._size.forEach(function(n){n>1&&e++}),1>=e},r.prototype.toArray=function(){return en.clone(this._data)},r.prototype.valueOf=function(){return this._data},r.prototype.toString=function(){return en.format(this._data)},en.type.Range=d,d.parse=function(e){if(!x(e))return null;var n=e.split(":"),t=n.map(function(e){return Number(e)}),r=t.some(function(e){return isNaN(e)});if(r)return null;switch(t.length){case 2:return new d(t[0],1,t[1]);case 3:return new d(t[0],t[1],t[2]);default:return null}},d.prototype.clone=function(){return new d(this.start,this.step,this.end)},d.prototype.size=function(){var e=0,n=Number(this.start),t=Number(this.step),r=Number(this.end),a=r-n;return en.sign(t)==en.sign(a)?e=Math.floor(a/t)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},d.prototype.forEach=function(e){var n=Number(this.start),t=Number(this.step),r=Number(this.end),a=0;if(t>0)for(;r>=n;)e(n,a,this),n+=t,a++;else if(0>t)for(;n>=r;)e(n,a,this),n+=t,a++},d.prototype.map=function(e){var n=[];return this.forEach(function(t,r,a){n[r]=e(t,r,a)}),n},d.prototype.toMatrix=function(){return new r(this.toArray())},d.prototype.toArray=function(){var e=[];return this.forEach(function(n,t){e[t]=n}),e},d.prototype.toVector=d.prototype.toArray,d.prototype.isVector=function(){return!0},d.prototype.toScalar=function(){var e=this.toArray();return 1==e.length?e[0]:null},d.prototype.isScalar=function(){return 1==this.size()[0]},d.prototype.valueOf=function(){return this.toArray()},d.prototype.toString=function(){var e=en.format(Number(this.start));return 1!=this.step&&(e+=":"+en.format(Number(this.step))),e+=":"+en.format(Number(this.end))},en.type.Selector=function(e){if(!(this instanceof en.type.Selector))throw new SyntaxError("Selector constructor must be called with the new operator");this.value=e instanceof en.type.Selector?e.value:e},en.type.Selector.prototype={done:function(){return this.value},get:function(e){var n=this.value;if(!n)throw Error("Selector value is undefined");return new en.type.Selector(en.subset(n,e))},set:function(e,n){var t=this.value;if(!t)throw Error("Selector value is undefined");return new en.type.Selector(en.subset(t,e,n))},valueOf:function(){return this.value},toString:function(){return en.format(this.value)}},en.type.Unit=w,function(){function e(){for(;" "==u||" "==u;)r()}function n(e){return e>="0"&&"9">=e||"."==e}function t(e){return e>="0"&&"9">=e}function r(){f++,u=s.charAt(f)}function a(e){f=e,u=s.charAt(f)}function i(){var e,i="";if(e=f,"+"==u?r():"-"==u&&(i+=u,r()),!n(u))return a(e),null;if("."==u){if(i+=u,r(),!t(u))return a(e),null}else{for(;t(u);)i+=u,r();"."==u&&(i+=u,r())}for(;t(u);)i+=u,r();if("E"==u||"e"==u){if(i+=u,r(),("+"==u||"-"==u)&&(i+=u,r()),!t(u))return a(e),null;for(;t(u);)i+=u,r()}return i}function o(){var n="";for(e();u&&" "!=u&&" "!=u;)n+=u,r();return n||null}var s,f,u;w.parse=function(n){if(s=n,f=-1,u="",!x(s))return null;r(),e();var t,a=i();return a?(t=o(),r(),e(),u?null:a&&t?new w(Number(a),t):null):(t=o(),r(),e(),u?null:new w(null,t))}}(),w.prototype.clone=function(){var e=new w;for(var n in this)this.hasOwnProperty(n)&&(e[n]=this[n]);return e},w.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},w.prototype._unnormalize=function(e,n){return void 0==n?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/n-this.unit.offset},w.isPlainUnit=function(e){return null!=b(e)},w.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},w.prototype.equalBase=function(e){return this.unit.base===e.unit.base},w.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},w.prototype["in"]=function(e){var n;if(x(e)){if(n=new w(null,e),!this.equalBase(n))throw new Error("Units do not match");return n.value=this.value,n}if(e instanceof w){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");if(null==e.unit)throw new Error("Unit expected on the right hand side of function in");return n=e.clone(),n.value=this.value,n.fixPrefix=!0,n}throw new Error("String or Unit expected as parameter")},w.prototype.toNumber=function(e){var n=this["in"](e),t=this.fixPrefix?n._bestPrefix():n.prefix;return n._unnormalize(n.value,t.value)},w.prototype.toString=function(){var e,n;if(this.fixPrefix)e=this._unnormalize(this.value),n=null!=this.value?nn.formatNumber(e,en.options.precision)+" ":"",n+=this.prefix.name+this.unit.name;else{var t=this._bestPrefix();e=this._unnormalize(this.value,t.value),n=null!=this.value?nn.formatNumber(e,en.options.precision)+" ":"",n+=t.name+this.unit.name}return n},w.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),n=w.PREFIX_NONE,t=Math.abs(Math.log(e/n.value)/Math.LN10-1.2),r=this.unit.prefixes;for(var a in r)if(r.hasOwnProperty(a)){var i=r[a];if(i.scientific){var o=Math.abs(Math.log(e/i.value)/Math.LN10-1.2);t>o&&(n=i,t=o)}}return n},w.PREFIXES={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}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1024,scientific:!0},M:{name:"M",value:Math.pow(1024,2),scientific:!0},G:{name:"G",value:Math.pow(1024,3),scientific:!0},T:{name:"T",value:Math.pow(1024,4),scientific:!0},P:{name:"P",value:Math.pow(1024,5),scientific:!0},E:{name:"E",value:Math.pow(1024,6),scientific:!0},Z:{name:"Z",value:Math.pow(1024,7),scientific:!0},Y:{name:"Y",value:Math.pow(1024,8),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:1024,scientific:!0},mega:{name:"mega",value:Math.pow(1024,2),scientific:!0},giga:{name:"giga",value:Math.pow(1024,3),scientific:!0},tera:{name:"tera",value:Math.pow(1024,4),scientific:!0},peta:{name:"peta",value:Math.pow(1024,5),scientific:!0},exa:{name:"exa",value:Math.pow(1024,6),scientific:!0},zetta:{name:"zetta",value:Math.pow(1024,7),scientific:!0},yotta:{name:"yotta",value:Math.pow(1024,8),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}}},w.PREFIX_NONE={name:"",value:1,scientific:!0},w.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var tn=w.BASE_UNITS,rn=w.PREFIXES;w.BASE_UNIT_NONE={},w.UNIT_NONE={name:"",base:w.BASE_UNIT_NONE,value:1,offset:0},w.UNITS=[{name:"meter",base:tn.LENGTH,prefixes:rn.LONG,value:1,offset:0},{name:"inch",base:tn.LENGTH,prefixes:rn.NONE,value:.0254,offset:0},{name:"foot",base:tn.LENGTH,prefixes:rn.NONE,value:.3048,offset:0},{name:"yard",base:tn.LENGTH,prefixes:rn.NONE,value:.9144,offset:0},{name:"mile",base:tn.LENGTH,prefixes:rn.NONE,value:1609.344,offset:0},{name:"link",base:tn.LENGTH,prefixes:rn.NONE,value:.201168,offset:0},{name:"rod",base:tn.LENGTH,prefixes:rn.NONE,value:5.02921,offset:0},{name:"chain",base:tn.LENGTH,prefixes:rn.NONE,value:20.1168,offset:0},{name:"angstrom",base:tn.LENGTH,prefixes:rn.NONE,value:1e-10,offset:0},{name:"m",base:tn.LENGTH,prefixes:rn.SHORT,value:1,offset:0},{name:"ft",base:tn.LENGTH,prefixes:rn.NONE,value:.3048,offset:0},{name:"yd",base:tn.LENGTH,prefixes:rn.NONE,value:.9144,offset:0},{name:"mi",base:tn.LENGTH,prefixes:rn.NONE,value:1609.344,offset:0},{name:"li",base:tn.LENGTH,prefixes:rn.NONE,value:.201168,offset:0},{name:"rd",base:tn.LENGTH,prefixes:rn.NONE,value:5.02921,offset:0},{name:"ch",base:tn.LENGTH,prefixes:rn.NONE,value:20.1168,offset:0},{name:"mil",base:tn.LENGTH,prefixes:rn.NONE,value:254e-7,offset:0},{name:"m2",base:tn.SURFACE,prefixes:rn.SHORT,value:1,offset:0},{name:"sqin",base:tn.SURFACE,prefixes:rn.NONE,value:64516e-8,offset:0},{name:"sqft",base:tn.SURFACE,prefixes:rn.NONE,value:.09290304,offset:0},{name:"sqyd",base:tn.SURFACE,prefixes:rn.NONE,value:.83612736,offset:0},{name:"sqmi",base:tn.SURFACE,prefixes:rn.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:tn.SURFACE,prefixes:rn.NONE,value:25.29295,offset:0},{name:"sqch",base:tn.SURFACE,prefixes:rn.NONE,value:404.6873,offset:0},{name:"sqmil",base:tn.SURFACE,prefixes:rn.NONE,value:6.4516e-10,offset:0},{name:"m3",base:tn.VOLUME,prefixes:rn.SHORT,value:1,offset:0},{name:"L",base:tn.VOLUME,prefixes:rn.SHORT,value:.001,offset:0},{name:"litre",base:tn.VOLUME,prefixes:rn.LONG,value:.001,offset:0},{name:"cuin",base:tn.VOLUME,prefixes:rn.NONE,value:16387064e-12,offset:0},{name:"cuft",base:tn.VOLUME,prefixes:rn.NONE,value:.028316846592,offset:0},{name:"cuyd",base:tn.VOLUME,prefixes:rn.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:tn.VOLUME,prefixes:rn.NONE,value:5e-6,offset:0},{name:"tablespoon",base:tn.VOLUME,prefixes:rn.NONE,value:15e-6,offset:0},{name:"minim",base:tn.VOLUME,prefixes:rn.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:tn.VOLUME,prefixes:rn.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:tn.VOLUME,prefixes:rn.NONE,value:2957353e-11,offset:0},{name:"gill",base:tn.VOLUME,prefixes:rn.NONE,value:.0001182941,offset:0},{name:"cup",base:tn.VOLUME,prefixes:rn.NONE,value:.0002365882,offset:0},{name:"pint",base:tn.VOLUME,prefixes:rn.NONE,value:.0004731765,offset:0},{name:"quart",base:tn.VOLUME,prefixes:rn.NONE,value:.0009463529,offset:0},{name:"gallon",base:tn.VOLUME,prefixes:rn.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:tn.VOLUME,prefixes:rn.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:tn.VOLUME,prefixes:rn.NONE,value:.1589873,offset:0},{name:"hogshead",base:tn.VOLUME,prefixes:rn.NONE,value:.238481,offset:0},{name:"fldr",base:tn.VOLUME,prefixes:rn.NONE,value:36966911e-13,offset:0},{name:"floz",base:tn.VOLUME,prefixes:rn.NONE,value:2957353e-11,offset:0},{name:"gi",base:tn.VOLUME,prefixes:rn.NONE,value:.0001182941,offset:0},{name:"cp",base:tn.VOLUME,prefixes:rn.NONE,value:.0002365882,offset:0},{name:"pt",base:tn.VOLUME,prefixes:rn.NONE,value:.0004731765,offset:0},{name:"qt",base:tn.VOLUME,prefixes:rn.NONE,value:.0009463529,offset:0},{name:"gal",base:tn.VOLUME,prefixes:rn.NONE,value:.003785412,offset:0},{name:"bbl",base:tn.VOLUME,prefixes:rn.NONE,value:.1173478,offset:0},{name:"obl",base:tn.VOLUME,prefixes:rn.NONE,value:.1589873,offset:0},{name:"g",base:tn.MASS,prefixes:rn.SHORT,value:.001,offset:0},{name:"gram",base:tn.MASS,prefixes:rn.LONG,value:.001,offset:0},{name:"ton",base:tn.MASS,prefixes:rn.SHORT,value:907.18474,offset:0},{name:"tonne",base:tn.MASS,prefixes:rn.SHORT,value:1e3,offset:0},{name:"grain",base:tn.MASS,prefixes:rn.NONE,value:6479891e-11,offset:0},{name:"dram",base:tn.MASS,prefixes:rn.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:tn.MASS,prefixes:rn.NONE,value:.028349523125,offset:0},{name:"poundmass",base:tn.MASS,prefixes:rn.NONE,value:.45359237,offset:0},{name:"hundredweight",base:tn.MASS,prefixes:rn.NONE,value:45.359237,offset:0},{name:"stick",base:tn.MASS,prefixes:rn.NONE,value:.115,offset:0},{name:"gr",base:tn.MASS,prefixes:rn.NONE,value:6479891e-11,offset:0},{name:"dr",base:tn.MASS,prefixes:rn.NONE,value:.0017718451953125,offset:0},{name:"oz",base:tn.MASS,prefixes:rn.NONE,value:.028349523125,offset:0},{name:"lbm",base:tn.MASS,prefixes:rn.NONE,value:.45359237,offset:0},{name:"cwt",base:tn.MASS,prefixes:rn.NONE,value:45.359237,offset:0},{name:"s",base:tn.TIME,prefixes:rn.SHORT,value:1,offset:0},{name:"min",base:tn.TIME,prefixes:rn.NONE,value:60,offset:0},{name:"h",base:tn.TIME,prefixes:rn.NONE,value:3600,offset:0},{name:"seconds",base:tn.TIME,prefixes:rn.LONG,value:1,offset:0},{name:"second",base:tn.TIME,prefixes:rn.LONG,value:1,offset:0},{name:"sec",base:tn.TIME,prefixes:rn.LONG,value:1,offset:0},{name:"minutes",base:tn.TIME,prefixes:rn.NONE,value:60,offset:0},{name:"minute",base:tn.TIME,prefixes:rn.NONE,value:60,offset:0},{name:"hours",base:tn.TIME,prefixes:rn.NONE,value:3600,offset:0},{name:"hour",base:tn.TIME,prefixes:rn.NONE,value:3600,offset:0},{name:"day",base:tn.TIME,prefixes:rn.NONE,value:86400,offset:0},{name:"days",base:tn.TIME,prefixes:rn.NONE,value:86400,offset:0},{name:"rad",base:tn.ANGLE,prefixes:rn.NONE,value:1,offset:0},{name:"deg",base:tn.ANGLE,prefixes:rn.NONE,value:.017453292519943295,offset:0},{name:"grad",base:tn.ANGLE,prefixes:rn.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:tn.ANGLE,prefixes:rn.NONE,value:6.283185307179586,offset:0},{name:"A",base:tn.CURRENT,prefixes:rn.SHORT,value:1,offset:0},{name:"ampere",base:tn.CURRENT,prefixes:rn.LONG,value:1,offset:0},{name:"K",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1,offset:0},{name:"degC",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1,offset:273.15},{name:"degF",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1/1.8,offset:459.67},{name:"degR",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1/1.8,offset:0},{name:"kelvin",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1,offset:0},{name:"celsius",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1,offset:273.15},{name:"fahrenheit",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:tn.TEMPERATURE,prefixes:rn.NONE,value:1/1.8,offset:0},{name:"mol",base:tn.AMOUNT_OF_SUBSTANCE,prefixes:rn.NONE,value:1,offset:0},{name:"mole",base:tn.AMOUNT_OF_SUBSTANCE,prefixes:rn.NONE,value:1,offset:0},{name:"cd",base:tn.LUMINOUS_INTENSITY,prefixes:rn.NONE,value:1,offset:0},{name:"candela",base:tn.LUMINOUS_INTENSITY,prefixes:rn.NONE,value:1,offset:0},{name:"N",base:tn.FORCE,prefixes:rn.SHORT,value:1,offset:0},{name:"newton",base:tn.FORCE,prefixes:rn.LONG,value:1,offset:0},{name:"lbf",base:tn.FORCE,prefixes:rn.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:tn.FORCE,prefixes:rn.NONE,value:4.4482216152605,offset:0},{name:"b",base:tn.BIT,prefixes:rn.BINARY_SHORT,value:1,offset:0},{name:"bits",base:tn.BIT,prefixes:rn.BINARY_LONG,value:1,offset:0},{name:"B",base:tn.BIT,prefixes:rn.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:tn.BIT,prefixes:rn.BINARY_LONG,value:8,offset:0}],en.pi=Math.PI,en.e=Math.E,en.tau=2*Math.PI,en.i=new n(0,1),en.Infinity=1/0,en.NaN=0/0,en["true"]=!0,en["false"]=!1,en.E=Math.E,en.LN2=Math.LN2,en.LN10=Math.LN10,en.LOG2E=Math.LOG2E,en.LOG10E=Math.LOG10E,en.PI=Math.PI,en.SQRT1_2=Math.SQRT1_2,en.SQRT2=Math.SQRT2,en.expr.node.Node=N,N.prototype.eval=function(){throw new Error("Cannot evaluate a Node interface")
|
|
},N.prototype.find=function(e){return this.match(e)?[this]:[]},N.prototype.match=function(e){var n=!0;if(e&&(!e.type||this instanceof e.type||(n=!1),n&&e.properties))for(var t in e.properties)if(e.properties.hasOwnProperty(t)&&this[t]!=e.properties[t]){n=!1;break}return n},N.prototype.toString=function(){return""},M.prototype=new N,en.expr.node.ConstantNode=M,M.prototype.eval=function(){return this.value},M.prototype.toString=function(){return en.format(this.value)},A.prototype=new N,en.expr.node.OperatorNode=A,A.prototype.eval=function(){return this.fn.apply(this,this.params.map(function(e){return e.eval()}))},A.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);var t=this.params;if(t)for(var r=0,a=t.length;a>r;r++)n=n.concat(t[r].find(e));return n},A.prototype.toString=function(){var e=this.params;if(this.fn===en.unary)return"-"+e[0].toString();switch(e.length){case 1:return e[0].toString()+this.name;case 2:var n=e[0].toString();e[0]instanceof A&&(n="("+n+")");var t=e[1].toString();return e[1]instanceof A&&(t="("+t+")"),n+" "+this.name+" "+t;default:return this.name+"("+this.params.join(", ")+")"}},S.prototype=new N,en.expr.node.SymbolNode=S,S.prototype.eval=function(){var e=this.scope.get(this.name);if(void 0===e)throw new Error("Undefined symbol "+this.name);return e},S.prototype.toString=function(){return this.name},T.prototype=new N,en.expr.node.ParamsNode=T,T.prototype.eval=function(){var e,n,t=this.object;if(void 0==t)throw new Error("Node undefined");var r=t.eval();if(this.hasContextParams){var a,i=this.paramScopes;if(a=r.size?r.size():void 0!==r.length?[r.length]:[],i&&a)for(e=0,n=this.params.length;n>e;e++){var o=i[e];o&&o.set("end",a[e]-1)}}var s=this.params,f=[];for(e=0,n=this.params.length;n>e;e++)f[e]=s[e].eval();return"function"==typeof r?r.apply(this,f):en.subset(r,f)},T.prototype.find=function(e){var n=[];this.match(e)&&n.push(this),this.object&&(n=n.concat(this.object.find(e)));var t=this.params;if(t)for(var r=0,a=t.length;a>r;r++)n=n.concat(t[r].find(e));return n},T.prototype.toString=function(){var e=this.object?this.object.toString():"";return this.params&&(e+="("+this.params.join(", ")+")"),e},q.prototype=new N,en.expr.node.MatrixNode=q,function(){function e(e){for(var n=[],t=e.length,a=0;t>a;a++){for(var i=e[a],o=i.length,s=null,f=null,u=0;o>u;u++){var c,l=en.clone(i[u]);if(l instanceof r){if(c=l.size(),l=l.valueOf(),1==c.length)l=[l],c=[1,c[0]];else if(c.length>2)throw new Error("Cannot merge a multi dimensional matrix")}else l instanceof d?(l=[l.valueOf()],c=[1,l[0].length]):l instanceof Array?(c=[1,l.length],l=[l]):(c=[1,1],l=[[l]]);if(null==s)s=l,f=c[0];else{if(c[0]!=f)throw new Error("Dimension mismatch ("+c[0]+" != "+f+")");for(var m=0;f>m;m++)s[m]=s[m].concat(l[m])}}n=n.concat(s)}return n}q.prototype.eval=function(){for(var n=this.nodes,t=[],a=!1,i=0,o=n.length;o>i;i++){for(var s=n[i],f=[],u=0,c=s.length;c>u;u++){var l=s[u].eval();(l instanceof r||l instanceof d||l instanceof Array)&&(a=!0),f[u]=l}t[i]=f}return a&&(t=e(t)),new r(t)},q.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);for(var t=this.nodes,r=0,a=t.length;a>r;r++)for(var i=t[r],o=0,s=i.length;s>o;o++)n=n.concat(i[o].find(e));return n},q.prototype.toString=function(){return nn.formatArray(this.nodes)}}(),z.prototype=new N,en.expr.node.BlockNode=z,z.prototype.add=function(e,n){var t=this.params.length;this.params[t]=e,this.visible[t]=void 0!=n?n:!0},z.prototype.eval=function(){for(var e=[],n=0,t=this.params.length;t>n;n++){var r=this.params[n].eval();this.visible[n]&&e.push(r)}return e},z.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);var t=this.params;if(t)for(var r=0,a=t.length;a>r;r++)n=n.concat(t[r].find(e));return n},z.prototype.toString=function(){for(var e=[],n=0,t=this.params.length;t>n;n++)this.visible[n]&&e.push("\n "+this.params[n].toString());return"["+e.join(",")+"\n]"},R.prototype=new N,en.expr.node.AssignmentNode=R,R.prototype.eval=function(){if(void 0===this.expr)throw new Error("Undefined symbol "+this.name);var e=this.expr.eval();return this.scope.set(this.name,e),e},R.prototype.find=function(e){var n=[];return this.match(e)&&n.push(this),this.expr&&(n=n.concat(this.expr.find(e))),n},R.prototype.toString=function(){return this.name+" = "+this.expr.toString()},C.prototype=new N,en.expr.node.UpdateNode=C,C.prototype.eval=function(){if(void 0===this.expr)throw new Error("Undefined symbol "+this.name);var e;this.params;var n=this.scope.get(this.name);if(void 0==n)throw new Error("Undefined symbol "+this.name);if(this.hasContextParams){var t,r=this.paramScopes;if(t=n.size?n.size():void 0!==n.length?[n.length]:[],r&&t)for(var a=0,i=this.params.length;i>a;a++){var o=r[a];o&&o.set("end",t[a]-1)}}var s=[];this.params.forEach(function(e){s.push(e.eval())});var f=this.expr.eval();return e=en.subset(n,s,f),this.scope.set(this.name,e),e},C.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);var t=this.params;if(t)for(var r=0,a=t.length;a>r;r++)n=n.concat(t[r].find(e));return this.expr&&(n=n.concat(this.expr.find(e))),n},C.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=this.expr.toString()},U.prototype=new N,en.expr.node.FunctionNode=U,U.prototype.eval=function(){return this.scope.set(this.name,this.fn),this.fn},U.prototype.find=function(e){var n=[];return this.match(e)&&n.push(this),this.expr&&(n=n.concat(this.expr.find(e))),n},U.prototype.toString=function(){return this.fn.toString()},en.expr.Scope=function(){if(this.parentScope=null,this.subScopes=null,this.symbols={},this.cache={},arguments.length>0){var e=arguments[0];e instanceof en.expr.Scope?this.parentScope=e:e instanceof Object&&(this.symbols=e)}if(arguments.length>1){var n=arguments[1];n instanceof Object&&(this.symbols=n)}},en.expr.Scope.prototype={createSubScope:function(){var e=new en.expr.Scope(this);return this.subScopes||(this.subScopes=[]),this.subScopes.push(e),e},get:function(e){var n;if(n=this.symbols[e],void 0!==n)return n;var t=this.cache[e];if(t)return t[e];for(var r=this.parentScope;r;){if(n=r.symbols[e],void 0!==n)return this.cache[e]=r.symbols,n;r=r.parentScope}return n=en[e],void 0!==n?(this.cache[e]=en,n):w.isPlainUnit(e)?(n=new w(null,e),this.cache[e]={},this.cache[e][e]=n,n):void 0},has:function(e){return void 0!==this.symbols[e]},set:function(e,n){return this.symbols[e]=n},remove:function(e){delete this.symbols[e]},clear:function(){var e=this.symbols;for(var n in e)e.hasOwnProperty(n)&&delete e[n];if(this.subScopes)for(var t=this.subScopes,r=0,a=t.length;a>r;r++)t[r].clear();this.clearCache()},clearCache:function(){this.cache={}}},en.expr.Parser=function(){if(!(this instanceof en.expr.Parser))throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new en.expr.Scope},en.expr.Parser.prototype.parse=function(e){return en.parse(e,this.scope)},en.expr.Parser.prototype.eval=function(e){var n=en.parse(e,this.scope);return n.eval()},en.expr.Parser.prototype.get=function(e){return this.scope.get(e)},en.expr.Parser.prototype.set=function(e,n){this.scope.set(e,n)},en.expr.Parser.prototype.remove=function(e){this.scope.remove(e)},en.expr.Parser.prototype.clear=function(){this.scope.clear()},en.abs=function(e){if(1!=arguments.length)throw O("abs",arguments.length,1);if(g(e))return Math.abs(e);if(e instanceof n)return Math.sqrt(e.re*e.re+e.im*e.im);if(e instanceof Array||e instanceof r)return nn.map(e,en.abs);if(e.valueOf()!==e)return en.abs(e.valueOf());throw E("abs",e)},en.add=function(e,t){if(2!=arguments.length)throw O("add",arguments.length,2);if(g(e)){if(g(t))return e+t;if(t instanceof n)return n.create(e+t.re,t.im)}else if(e instanceof n){if(g(t))return n.create(e.re+t,e.im);if(t instanceof n)return n.create(e.re+t.re,e.im+t.im)}else if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Units do not match");if(null==e.value)throw new Error("Unit on left hand side of operator + has an undefined value");if(null==t.value)throw new Error("Unit on right hand side of operator + has an undefined value");var a=e.clone();return a.value+=t.value,a.fixPrefix=!1,a}if(x(e)||x(t))return e+t;if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.add);if(e.valueOf()!==e||t.valueOf()!==t)return en.add(e.valueOf(),t.valueOf());throw E("add",e,t)},en.ceil=function(e){if(1!=arguments.length)throw O("ceil",arguments.length,1);if(g(e))return Math.ceil(e);if(e instanceof n)return n.create(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof r)return nn.map(e,en.ceil);if(e.valueOf()!==e)return en.ceil(e.valueOf());throw E("ceil",e)},en.cube=function(e){if(1!=arguments.length)throw O("cube",arguments.length,1);if(g(e))return e*e*e;if(e instanceof n)return en.multiply(en.multiply(e,e),e);if(e instanceof Array||e instanceof r)return nn.map(e,en.cube);if(e.valueOf()!==e)return en.cube(e.valueOf());throw E("cube",e)},en.divide=function(e,t){if(2!=arguments.length)throw O("divide",arguments.length,2);if(g(e)){if(g(t))return e/t;if(t instanceof n)return L(new n(e,0),t)}if(e instanceof n){if(g(t))return L(e,new n(t,0));if(t instanceof n)return L(e,t)}if(e instanceof w&&g(t)){var a=e.clone();return a.value/=t,a}if(e instanceof Array||e instanceof r)return t instanceof Array||t instanceof r?en.multiply(e,en.inv(t)):nn.map2(e,t,en.divide);if(t instanceof Array||t instanceof r)return en.multiply(e,en.inv(t));if(e.valueOf()!==e||t.valueOf()!==t)return en.divide(e.valueOf(),t.valueOf());throw E("divide",e,t)},en.edivide=function(e,n){if(2!=arguments.length)throw O("edivide",arguments.length,2);return nn.deepMap2(e,n,en.divide)},en.emultiply=function(e,n){if(2!=arguments.length)throw O("emultiply",arguments.length,2);return nn.deepMap2(e,n,en.multiply)},en.epow=function(e,n){if(2!=arguments.length)throw O("epow",arguments.length,2);return nn.deepMap2(e,n,en.pow)},en.equal=function fn(e,t){if(2!=arguments.length)throw O("equal",arguments.length,2);if(g(e)){if(g(t))return e==t;if(t instanceof n)return e==t.re&&0==t.im}if(e instanceof n){if(g(t))return e.re==t&&0==e.im;if(t instanceof n)return e.re==t.re&&e.im==t.im}if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Cannot compare units with different base");return e.value==t.value}if(x(e)||x(t))return e==t;if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.equal);if(e.valueOf()!==e||t.valueOf()!==t)return fn(e.valueOf(),t.valueOf());throw E("equal",e,t)},en.exp=function(e){if(1!=arguments.length)throw O("exp",arguments.length,1);if(g(e))return Math.exp(e);if(e instanceof n){var t=Math.exp(e.re);return n.create(t*Math.cos(e.im),t*Math.sin(e.im))}if(e instanceof Array||e instanceof r)return nn.map(e,en.exp);if(e.valueOf()!==e)return en.exp(e.valueOf());throw E("exp",e)},en.fix=function(e){if(1!=arguments.length)throw O("fix",arguments.length,1);if(g(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof n)return n.create(e.re>0?Math.floor(e.re):Math.ceil(e.re),e.im>0?Math.floor(e.im):Math.ceil(e.im));if(e instanceof Array||e instanceof r)return nn.map(e,en.fix);if(e.valueOf()!==e)return en.fix(e.valueOf());throw E("fix",e)},en.floor=function(e){if(1!=arguments.length)throw O("floor",arguments.length,1);if(g(e))return Math.floor(e);if(e instanceof n)return n.create(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof r)return nn.map(e,en.floor);if(e.valueOf()!==e)return en.floor(e.valueOf());throw E("floor",e)},en.gcd=function(){var e,n=arguments[0],t=arguments[1];if(2==arguments.length){if(g(n)&&g(t)){if(!v(n)||!v(t))throw new Error("Parameters in function gcd must be integer numbers");for(;0!=t;)e=t,t=n%e,n=e;return Math.abs(n)}if(n instanceof Array||n instanceof r||t instanceof Array||t instanceof r)return nn.map2(n,t,en.gcd);if(n.valueOf()!==n||t.valueOf()!==t)return en.gcd(n.valueOf(),t.valueOf());throw E("gcd",n,t)}if(arguments.length>2){for(var a=1;a<arguments.length;a++)n=en.gcd(n,arguments[a]);return n}throw new SyntaxError("Function gcd expects two or more arguments")},en.larger=function(e,t){if(2!=arguments.length)throw O("larger",arguments.length,2);if(g(e)){if(g(t))return e>t;if(t instanceof n)return e>en.abs(t)}if(e instanceof n){if(g(t))return en.abs(e)>t;if(t instanceof n)return en.abs(e)>en.abs(t)}if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Cannot compare units with different base");return e.value>t.value}if(x(e)||x(t))return e>t;if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.larger);if(e.valueOf()!==e||t.valueOf()!==t)return en.larger(e.valueOf(),t.valueOf());throw E("larger",e,t)},en.largereq=function(e,t){if(2!=arguments.length)throw O("largereq",arguments.length,2);if(g(e)){if(g(t))return e>=t;if(t instanceof n)return e>=en.abs(t)}if(e instanceof n){if(g(t))return en.abs(e)>=t;if(t instanceof n)return en.abs(e)>=en.abs(t)}if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Cannot compare units with different base");return e.value>=t.value}if(x(e)||x(t))return e>=t;if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.largereq);if(e.valueOf()!==e||t.valueOf()!==t)return en.largereq(e.valueOf(),t.valueOf());throw E("largereq",e,t)},en.lcm=function(){var e,n=arguments[0],t=arguments[1];if(2==arguments.length){if(g(n)&&g(t)){if(!v(n)||!v(t))throw new Error("Parameters in function lcm must be integer numbers");for(var a=n*t;0!=t;)e=t,t=n%e,n=e;return Math.abs(a/n)}if(n instanceof Array||n instanceof r||t instanceof Array||t instanceof r)return nn.map2(n,t,en.lcm);if(n.valueOf()!==n||t.valueOf()!==t)return en.lcm(n.valueOf(),t.valueOf());throw E("lcm",n,t)}if(arguments.length>2){for(var i=1;i<arguments.length;i++)n=en.lcm(n,arguments[i]);return n}throw new SyntaxError("Function lcm expects two or more arguments")},en.log=function(e,t){if(1==arguments.length){if(g(e))return e>=0?Math.log(e):en.log(new n(e,0));if(e instanceof n)return n.create(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof r)return nn.map(e,en.log);if(e.valueOf()!==e)return en.log(e.valueOf());throw E("log",e)}if(2==arguments.length)return en.divide(en.log(e),en.log(t));throw O("log",arguments.length,1,2)},en.log10=function(e){if(1!=arguments.length)throw O("log10",arguments.length,1);if(g(e))return e>=0?Math.log(e)/Math.LN10:en.log10(new n(e,0));if(e instanceof n)return n.create(Math.log(Math.sqrt(e.re*e.re+e.im*e.im))/Math.LN10,Math.atan2(e.im,e.re)/Math.LN10);if(e instanceof Array||e instanceof r)return nn.map(e,en.log10);if(e.valueOf()!==e)return en.log10(e.valueOf());throw E("log10",e)},en.mod=function(e,n){if(2!=arguments.length)throw O("mod",arguments.length,2);if(g(e)&&g(n))return I(e,n);if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return nn.map2(e,n,en.mod);if(e.valueOf()!==e||n.valueOf()!==n)return en.mod(e.valueOf(),n.valueOf());throw E("mod",e,n)},en.multiply=function un(e,t){if(2!=arguments.length)throw O("multiply",arguments.length,2);if(g(e)){if(g(t))return e*t;if(t instanceof n)return P(new n(e,0),t);if(t instanceof w)return o=t.clone(),o.value*=e,o}else if(e instanceof n){if(g(t))return P(e,new n(t,0));if(t instanceof n)return P(e,t)}else if(e instanceof w){if(g(t))return o=e.clone(),o.value*=t,o}else{if(e instanceof Array){if(t instanceof Array){var a=nn.size(e),i=nn.size(t);if(2!=a.length)throw new Error("Can only multiply a 2 dimensional matrix (A has "+a.length+" dimensions)");if(2!=i.length)throw new Error("Can only multiply a 2 dimensional matrix (B has "+i.length+" dimensions)");if(a[1]!=i[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+a[0]+"x"+a[1]+", B is "+i[0]+"x"+i[1]+", "+i[1]+" != "+i[0]+")");for(var o=[],s=a[0],f=i[1],u=a[1],un=en.multiply,c=en.add,l=0;s>l;l++){o[l]=[];for(var m=0;f>m;m++){for(var h=null,p=0;u>p;p++){var v=un(e[l][p],t[p][m]);h=null==h?v:c(h,v)}o[l][m]=h}}return o}return t instanceof r?new r(en.multiply(e.valueOf(),t.valueOf())):nn.map2(e,t,en.multiply)}if(e instanceof r)return new r(en.multiply(e.valueOf(),t.valueOf()))}if(t instanceof Array)return nn.map2(e,t,en.multiply);if(t instanceof r)return new r(en.multiply(e.valueOf(),t.valueOf()));if(e.valueOf()!==e||t.valueOf()!==t)return en.multiply(e.valueOf(),t.valueOf());throw E("multiply",e,t)},en.pow=function(e,t){if(2!=arguments.length)throw O("pow",arguments.length,2);if(g(e)){if(g(t))return v(t)||e>=0?Math.pow(e,t):_(new n(e,0),new n(t,0));if(t instanceof n)return _(new n(e,0),t)}else if(e instanceof n){if(g(t))return _(e,new n(t,0));if(t instanceof n)return _(e,t)}else{if(e instanceof Array){if(!g(t)||!v(t)||0>t)throw new TypeError("For A^b, b must be a positive integer (value is "+t+")");var a=nn.size(e);if(2!=a.length)throw new Error("For A^b, A must be 2 dimensional (A has "+a.length+" dimensions)");if(a[0]!=a[1])throw new Error("For A^b, A must be square (size is "+a[0]+"x"+a[1]+")");if(0==t)return en.eye(a[0]);for(var i=e,o=1;t>o;o++)i=en.multiply(e,i);return i}if(e instanceof r)return new r(en.pow(e.valueOf(),t))}if(e.valueOf()!==e||t.valueOf()!==t)return en.pow(e.valueOf(),t.valueOf());throw E("pow",e,t)},en.round=function(e,t){if(1!=arguments.length&&2!=arguments.length)throw O("round",arguments.length,1,2);if(void 0==t){if(g(e))return Math.round(e);if(e instanceof n)return n.create(Math.round(e.re),Math.round(e.im));if(e instanceof Array||e instanceof r)return nn.map(e,en.round);if(e.valueOf()!==e)return en.round(e.valueOf());throw E("round",e)}if(!g(t))throw new TypeError("Number of decimals in function round must be an integer");if(t!==Math.round(t))throw new TypeError("Number of decimals in function round must be integer");if(0>t||t>9)throw new Error("Number of decimals in function round must be in te range of 0-9");if(g(e))return B(e,t);if(e instanceof n)return n.create(B(e.re,t),B(e.im,t));if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.round);if(e.valueOf()!==e||t.valueOf()!==t)return en.round(e.valueOf(),t.valueOf());throw E("round",e,t)},en.sign=function cn(e){if(1!=arguments.length)throw O("sign",arguments.length,1);if(g(e)){var cn;return cn=e>0?1:0>e?-1:0}if(e instanceof n){var t=Math.sqrt(e.re*e.re+e.im*e.im);return n.create(e.re/t,e.im/t)}if(e instanceof Array||e instanceof r)return nn.map(e,en.sign);if(e.valueOf()!==e)return en.sign(e.valueOf());throw E("sign",e)},en.smaller=function(e,t){if(2!=arguments.length)throw O("smaller",arguments.length,2);if(g(e)){if(g(t))return t>e;if(t instanceof n)return e<en.abs(t)}if(e instanceof n){if(g(t))return en.abs(e)<t;if(t instanceof n)return en.abs(e)<en.abs(t)}if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Cannot compare units with different base");return e.value<t.value}if(x(e)||x(t))return t>e;if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.smaller);if(e.valueOf()!==e||t.valueOf()!==t)return en.smaller(e.valueOf(),t.valueOf());throw E("smaller",e,t)},en.smallereq=function(e,t){if(2!=arguments.length)throw O("smallereq",arguments.length,2);if(g(e)){if(g(t))return t>=e;if(t instanceof n)return e<=en.abs(t)}if(e instanceof n){if(g(t))return en.abs(e)<=t;if(t instanceof n)return en.abs(e)<=en.abs(t)}if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Cannot compare units with different base");return e.value<=t.value}if(x(e)||x(t))return t>=e;if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.smallereq);if(e.valueOf()!==e||t.valueOf()!==t)return en.smallereq(e.valueOf(),t.valueOf());throw E("smallereq",e,t)},en.sqrt=function(e){if(1!=arguments.length)throw O("sqrt",arguments.length,1);if(g(e))return e>=0?Math.sqrt(e):en.sqrt(new n(e,0));if(e instanceof n){var t=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?n.create(.5*Math.sqrt(2*(t+e.re)),.5*Math.sqrt(2*(t-e.re))):n.create(.5*Math.sqrt(2*(t+e.re)),-.5*Math.sqrt(2*(t-e.re)))}if(e instanceof Array||e instanceof r)return nn.map(e,en.sqrt);if(e.valueOf()!==e)return en.sqrt(e.valueOf());throw E("sqrt",e)},en.square=function(e){if(1!=arguments.length)throw O("square",arguments.length,1);if(g(e))return e*e;if(e instanceof n)return en.multiply(e,e);if(e instanceof Array||e instanceof r)return nn.map(e,en.square);if(e.valueOf()!==e)return en.square(e.valueOf());throw E("square",e)},en.subtract=function(e,t){if(2!=arguments.length)throw O("subtract",arguments.length,2);if(g(e)){if(g(t))return e-t;if(t instanceof n)return n.create(e-t.re,-t.im)}else if(e instanceof n){if(g(t))return n.create(e.re-t,e.im);if(t instanceof n)return n.create(e.re-t.re,e.im-t.im)}else if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Units do not match");if(null==e.value)throw new Error("Unit on left hand side of operator - has an undefined value");if(null==t.value)throw new Error("Unit on right hand side of operator - has an undefined value");var a=e.clone();return a.value-=t.value,a.fixPrefix=!1,a}if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.subtract);if(e.valueOf()!==e||t.valueOf()!==t)return en.subtract(e.valueOf(),t.valueOf());throw E("subtract",e,t)},en.unary=function(e){if(1!=arguments.length)throw O("unary",arguments.length,1);if(g(e))return-e;if(e instanceof n)return n.create(-e.re,-e.im);if(e instanceof w){var t=e.clone();return t.value=-e.value,t}if(e instanceof Array||e instanceof r)return nn.map(e,en.unary);if(e.valueOf()!==e)return en.unary(e.valueOf());throw E("unary",e)},en.unaryminus=function(){throw new Error("Function unaryminus is deprecated, use unary instead")},en.unequal=function(e,t){if(2!=arguments.length)throw O("unequal",arguments.length,2);if(g(e)){if(g(t))return e!=t;if(t instanceof n)return e!=t.re||0!=t.im}if(e instanceof n){if(g(t))return e.re!=t||0!=e.im;if(t instanceof n)return e.re!=t.re||e.im!=t.im}if(e instanceof w&&t instanceof w){if(!e.equalBase(t))throw new Error("Cannot compare units with different base");return e.value!=t.value}if(x(e)||x(t))return e!=t;if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.unequal);if(e.valueOf()!==e||t.valueOf()!==t)return en.unequal(e.valueOf(),t.valueOf());throw E("unequal",e,t)},en.xgcd=function ln(e,n){if(2==arguments.length){if(g(e)&&g(n)){if(!v(e)||!v(n))throw new Error("Parameters in function xgcd must be integer numbers");if(0==n)return[e,1,0];var t=ln(n,e%n),r=t[0],a=t[1],i=t[2];return[r,i,a-i*Math.floor(e/n)]}throw E("xgcd",e,n)}throw new SyntaxError("Function xgcd expects two arguments")},en.arg=function(e){if(1!=arguments.length)throw O("arg",arguments.length,1);return g(e)?Math.atan2(0,e):e instanceof n?Math.atan2(e.im,e.re):e instanceof Array||e instanceof r?nn.map(e,en.arg):e.valueOf()!==e?en.arg(e.valueOf()):en.atan2(0,e)},en.conj=function(e){if(1!=arguments.length)throw O("conj",arguments.length,1);return g(e)?e:e instanceof n?n.create(e.re,-e.im):e instanceof Array||e instanceof r?nn.map(e,en.conj):e.valueOf()!==e?en.conj(e.valueOf()):clone(e)},en.im=function(e){if(1!=arguments.length)throw O("im",arguments.length,1);return g(e)?0:e instanceof n?e.im:e instanceof Array||e instanceof r?nn.map(e,en.im):e.valueOf()!==e?en.im(e.valueOf()):0},en.re=function(e){if(1!=arguments.length)throw O("re",arguments.length,1);return g(e)?e:e instanceof n?e.re:e instanceof Array||e instanceof r?nn.map(e,en.re):e.valueOf()!==e?en.re(e.valueOf()):en.clone(e)},en["boolean"]=function(e){if(1!=arguments.length)throw O("boolean",arguments.length,0,1);if("true"===e||e===!0)return!0;if("false"===e||e===!1)return!1;if(g(e))return 0!==e;if(x(e)){var n=e.toLowerCase();if("true"===n)return!0;if("false"===n)return!1;var t=Number(e);if(""!=e&&!isNaN(t))return 0!==t}throw new SyntaxError(e.toString()+" is no valid boolean")},en.complex=function(){switch(arguments.length){case 0:return new n(0,0);case 1:var e=arguments[0];if(e instanceof n)return e.clone();if(x(e)){var t=n.parse(e);if(t)return t;throw new SyntaxError('String "'+e+'" is no valid complex number')}throw new TypeError("Two numbers or a single string expected in function complex");case 2:return new n(arguments[0],arguments[1]);default:throw O("complex",arguments.length,0,2)}},en.matrix=function(e){if(arguments.length>1)throw O("matrix",arguments.length,0,1);return new r(e)},en.number=function(e){switch(arguments.length){case 0:return 0;case 1:var n=Number(e);if(isNaN(n)&&(n=Number(e.valueOf())),isNaN(n))throw new SyntaxError(e.toString()+" is no valid number");return n;default:throw O("number",arguments.length,0,1)}},en.parser=function(){return new en.expr.Parser},en.range=function(e){switch(arguments.length){case 1:if(e instanceof d)return e.clone();if(x(e)){var n=d.parse(e);if(n)return n;throw new SyntaxError('String "'+n+'" is no valid range')}throw new TypeError("Two or three numbers or a single string expected in function range");case 2:return new d(arguments[0],null,arguments[1]);case 3:return new d(arguments[0],arguments[1],arguments[2]);default:throw O("range",arguments.length,2,3)}},en.string=function(e){switch(arguments.length){case 0:return"";case 1:return G(e);default:throw O("string",arguments.length,0,1)}},en.unit=function(){switch(arguments.length){case 1:var e=arguments[0];if(e instanceof w)return e.clone();if(x(e)){if(w.isPlainUnit(e))return new w(null,e);var n=w.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid unit')}throw new TypeError("A string or a number and string expected in function unit");case 2:return new w(arguments[0],arguments[1]);default:throw O("unit",arguments.length,1,2)}},en.workspace=function(){throw new Error("Workspace is no longer supported, sorry...")},en.concat=function(){var e,n,t=arguments.length,a=-1,i=!1,o=[];for(e=0;t>e;e++){var s=arguments[e];if(s instanceof r&&(i=!0),e==t-1&&g(s)){if(n=a,a=s,!v(a)||0>a)throw new TypeError("Dimension number must be a positive integer (dim = "+a+")");if(e>0&&a>n)throw new RangeError("Dimension out of range ("+a+" > "+n+")")}else{if(!(s instanceof Array||s instanceof r))throw E("concat",s);var f=en.clone(s).valueOf(),u=en.size(s).valueOf();if(o[e]=f,n=a,a=u.length-1,e>0&&a!=n)throw new RangeError("Dimension mismatch ("+n+" != "+a+")")}}if(0==o.length)throw new SyntaxError("At least one matrix expected");for(var c=o.shift();o.length;)c=j(c,o.shift(),a,0);return i?new r(c):c},en.det=function(e){if(1!=arguments.length)throw O("det",arguments.length,1);var n=en.size(e).valueOf();switch(n.length){case 0:return en.clone(e);case 1:if(1==n[0])return en.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+en.format(n)+")");case 2:var t=n[0],r=n[1];if(t==r)return k(e.valueOf(),t,r);throw new RangeError("Matrix must be square (size: "+en.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+en.format(n)+")")}},en.diag=function(e,n){var t,a,i,o;if(1!=arguments.length&&2!=arguments.length)throw O("diag",arguments.length,1,2);if(n){if(!g(n)||!v(n))throw new TypeError("Second parameter in function diag must be an integer")}else n=0;var s=n>0?n:0,f=0>n?-n:0;e instanceof r||e instanceof d||(e=new r(e));var u;switch(e.isVector()?(e=e.toVector(),u=[e.length]):u=e.size(),u.length){case 1:a=e.valueOf();var c=new r;for(c.resize([a.length+f,a.length+s]),t=c.valueOf(),o=a.length,i=0;o>i;i++)t[i+f][i+s]=en.clone(a[i]);return c;case 2:for(a=[],t=e.valueOf(),o=Math.min(u[0]-f,u[1]-s),i=0;o>i;i++)a[i]=en.clone(t[i+f][i+s]);return new r(a);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}},en.eye=function(){var e=nn.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw O("eye",e.length,0,2);var n=e[0],t=e[1];if(!g(n)||!v(n)||1>n)throw new Error("Parameters in function eye must be positive integers");if(t&&(!g(t)||!v(t)||1>t))throw new Error("Parameters in function eye must be positive integers");var a=new r;a.resize(e);for(var i=en.min(e),o=a.valueOf(),s=0;i>s;s++)o[s][s]=1;return a},en.inv=function(e){if(1!=arguments.length)throw O("inv",arguments.length,1);var n=en.size(e).valueOf();switch(n.length){case 0:return en.divide(1,e);case 1:if(1==n[0])return e instanceof r?new r([en.divide(1,e.valueOf()[0])]):[en.divide(1,e[0])];throw new RangeError("Matrix must be square (size: "+en.format(n)+")");case 2:var t=n[0],a=n[1];if(t==a)return e instanceof r?new r(F(e.valueOf(),t,a)):F(e,t,a);throw new RangeError("Matrix must be square (size: "+en.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+en.format(n)+")")}},en.ones=function(){var e=nn.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new r,t=1;return n.resize(e,t),n},en.size=function(e){if(1!=arguments.length)throw O("size",arguments.length,1);if(g(e)||e instanceof n||e instanceof w||null==e)return[];if(x(e))return[e.length];if(e instanceof Array)return nn.size(e);if(e instanceof r)return new r(e.size());if(e.valueOf()!==e)return en.size(e.valueOf());throw E("size",e)},en.squeeze=function(e){if(1!=arguments.length)throw O("squeeze",arguments.length,1);return e instanceof Array?V(en.clone(e)):e instanceof r?en.matrix(V(e.toArray())):e.valueOf()instanceof Array?V(en.clone(e.valueOf())):en.clone(e)},en.subset=function(){switch(arguments.length){case 2:return H(arguments[0],arguments[1]);case 3:return Y(arguments[0],arguments[1],arguments[2]);default:throw O("subset",arguments.length,2,3)}},en.transpose=function(e){if(1!=arguments.length)throw O("transpose",arguments.length,1);var n=en.size(e).valueOf();switch(n.length){case 0:return en.clone(e);case 1:return en.clone(e);case 2:for(var t,a=n[1],i=n[0],o=e instanceof r,s=e.valueOf(),f=[],u=en.clone,c=0;a>c;c++){t=f[c]=[];for(var l=0;i>l;l++)t[l]=u(s[l][c])}return 0==i&&(f[0]=[]),o?new r(f):f;default:throw new RangeError("Matrix must be two dimensional (size: "+en.format(n)+")")}},en.zeros=function(){var e=nn.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new r;return n.resize(e),n},en.factorial=function(e){if(1!=arguments.length)throw O("factorial",arguments.length,1);if(g(e)){if(!v(e)||0>e)throw new TypeError("Positive integer value expected in function factorial");var n=e,t=n;for(n--;n>1;)t*=n,n--;return 0==t&&(t=1),t}if(e instanceof Array||e instanceof r)return nn.map(e,en.factorial);if(e.valueOf()!==e)return en.factorial(e.valueOf());throw E("factorial",e)};var an={uniform:function(){return Math.random},normal:function(){return function(){for(var e,n,t=-1;0>t||t>1;)e=Math.random(),n=Math.random(),t=1/6*Math.pow(-2*Math.log(e),.5)*Math.cos(2*Math.PI*n)+.5;return t}}};en.distribution=function(e){if(!an.hasOwnProperty(e))throw new Error("unknown distribution "+e);var n=Array.prototype.slice.call(arguments,1),t=an[e].apply(this,n);return function(e){return{random:function(n,t){return void 0===t&&(t=1),void 0===n&&(n=0),n+e()*(t-n)},randomInt:function(e,n){return Math.floor(this.random(e,n))}}}(t)};var on=en.distribution("uniform");en.random=on.random,en.randomInt=on.randomInt,en.max=function(e){if(0==arguments.length)throw new Error("Function max requires one or more parameters (0 provided)");if(e instanceof Array||e instanceof r||e instanceof d){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=en.size(e).valueOf();if(1==n.length){if(0==e.length)throw new Error("Cannot calculate max of an empty vector");return Q(e.valueOf())}if(2==n.length){if(0==n[0]||0==n[1])throw new Error("Cannot calculate max of an empty matrix");if(e instanceof Array)return K(e,n[0],n[1]);if(e instanceof r||e instanceof d)return new r(K(e.valueOf(),n[0],n[1]));throw E("max",e)}throw new RangeError("Cannot calculate max for multi dimensional matrix")}return Q(arguments)},en.min=function(e){if(0==arguments.length)throw new Error("Function min requires one or more parameters (0 provided)");
|
|
if(e instanceof Array||e instanceof r||e instanceof d){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=en.size(e).valueOf();if(1==n.length){if(0==e.length)throw new Error("Cannot calculate min of an empty vector");return Z(e.valueOf())}if(2==n.length){if(0==n[0]||0==n[1])throw new Error("Cannot calculate min of an empty matrix");if(e instanceof Array)return X(e,n[0],n[1]);if(e instanceof r||e instanceof d)return new r(X(e.valueOf(),n[0],n[1]));throw E("min",e)}throw new RangeError("Cannot calculate min for multi dimensional matrix")}return Z(arguments)},en.acos=function(e){if(1!=arguments.length)throw O("acos",arguments.length,1);if(g(e))return e>=-1&&1>=e?Math.acos(e):en.acos(new n(e,0));if(e instanceof n){var t,a=n.create(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),i=en.sqrt(a);t=i instanceof n?n.create(i.re-e.im,i.im+e.re):n.create(i-e.im,e.re);var o=en.log(t);return o instanceof n?n.create(1.5707963267948966-o.im,o.re):new n(1.5707963267948966,o)}if(e instanceof Array||e instanceof r)return nn.map(e,en.acos);if(e.valueOf()!==e)return en.acos(e.valueOf());throw E("acos",e)},en.asin=function(e){if(1!=arguments.length)throw O("asin",arguments.length,1);if(g(e))return e>=-1&&1>=e?Math.asin(e):en.asin(new n(e,0));if(e instanceof n){var t,a=e.re,i=e.im,o=n.create(i*i-a*a+1,-2*a*i),s=en.sqrt(o);t=s instanceof n?n.create(s.re-i,s.im+a):n.create(s-i,a);var f=en.log(t);return f instanceof n?n.create(f.im,-f.re):n.create(0,-f)}if(e instanceof Array||e instanceof r)return nn.map(e,en.asin);if(e.valueOf()!==e)return en.asin(e.valueOf());throw E("asin",e)},en.atan=function(e){if(1!=arguments.length)throw O("atan",arguments.length,1);if(g(e))return Math.atan(e);if(e instanceof n){var t=e.re,a=e.im,i=t*t+(1-a)*(1-a),o=n.create((1-a*a-t*t)/i,-2*t/i),s=en.log(o);return s instanceof n?n.create(-.5*s.im,.5*s.re):n.create(0,.5*s)}if(e instanceof Array||e instanceof r)return nn.map(e,en.atan);if(e.valueOf()!==e)return en.atan(e.valueOf());throw E("atan",e)},en.atan2=function(e,t){if(2!=arguments.length)throw O("atan2",arguments.length,2);if(g(e)){if(g(t))return Math.atan2(e,t)}else if(e instanceof n&&g(t))return Math.atan2(e.re,t);if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return nn.map2(e,t,en.atan2);if(t.valueOf()!==t||e.valueOf()!==e)return en.atan2(e.valueOf(),t.valueOf());throw E("atan2",e,t)},en.cos=function(e){if(1!=arguments.length)throw O("cos",arguments.length,1);if(g(e))return Math.cos(e);if(e instanceof n)return n.create(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.sin(e.re)*(Math.exp(-e.im)-Math.exp(e.im)));if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(e.value)}if(e instanceof Array||e instanceof r)return nn.map(e,en.cos);if(e.valueOf()!==e)return en.cos(e.valueOf());throw E("cos",e)},en.cot=function(e){if(1!=arguments.length)throw O("cot",arguments.length,1);if(g(e))return 1/Math.tan(e);if(e instanceof n){var t=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return n.create(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/t,(Math.exp(-4*e.im)-1)/t)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(e.value)}if(e instanceof Array||e instanceof r)return nn.map(e,en.cot);if(e.valueOf()!==e)return en.cot(e.valueOf());throw E("cot",e)},en.csc=function(e){if(1!=arguments.length)throw O("csc",arguments.length,1);if(g(e))return 1/Math.sin(e);if(e instanceof n){var t=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return n.create(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/t,.5*Math.cos(e.re)*(Math.exp(-e.im)-Math.exp(e.im))/t)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(e.value)}if(e instanceof Array||e instanceof r)return nn.map(e,en.csc);if(e.valueOf()!==e)return en.csc(e.valueOf());throw E("csc",e)},en.sec=function(e){if(1!=arguments.length)throw O("sec",arguments.length,1);if(g(e))return 1/Math.cos(e);if(e instanceof n){var t=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return n.create(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/t,.5*Math.sin(e.re)*(Math.exp(e.im)-Math.exp(-e.im))/t)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(e.value)}if(e instanceof Array||e instanceof r)return nn.map(e,en.sec);if(e.valueOf()!==e)return en.sec(e.valueOf());throw E("sec",e)},en.sin=function(e){if(1!=arguments.length)throw O("sin",arguments.length,1);if(g(e))return Math.sin(e);if(e instanceof n)return n.create(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.cos(e.re)*(Math.exp(e.im)-Math.exp(-e.im)));if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(e.value)}if(e instanceof Array||e instanceof r)return nn.map(e,en.sin);if(e.valueOf()!==e)return en.sin(e.valueOf());throw E("sin",e)},en.tan=function(e){if(1!=arguments.length)throw O("tan",arguments.length,1);if(g(e))return Math.tan(e);if(e instanceof n){var t=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return n.create(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/t,(1-Math.exp(-4*e.im))/t)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(e.value)}if(e instanceof Array||e instanceof r)return nn.map(e,en.tan);if(e.valueOf()!==e)return en.tan(e.valueOf());throw E("tan",e)},en["in"]=function(e,n){if(2!=arguments.length)throw O("in",arguments.length,2);if(e instanceof w&&(n instanceof w||x(n)))return e["in"](n);if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return nn.map2(e,n,en["in"]);if(e.valueOf()!==e||n.valueOf()!==n)return en["in"](e.valueOf(),n.valueOf());throw E("in",e,n)},en.clone=function(n){if(1!=arguments.length)throw O("clone",arguments.length,1);if(null==n)return n;if("function"==typeof n.clone)return n.clone();if(g(n)||x(n)||e(n))return n;if(n instanceof Array){var t=en.clone;return n.map(function(e){return t(e)})}if(n instanceof Object)return nn.mapObject(n,en.clone);throw E("clone",n)},en.eval=function(e,n){if(1!=arguments.length&&2!=arguments.length)throw O("eval",arguments.length,1,2);var t;if(t=n?n instanceof en.expr.Scope?n:new en.expr.Scope(n):new en.expr.Scope,x(e)){var a=en.parse(e,t);return a.eval()}if(e instanceof Array||e instanceof r)return nn.map(e,function(e){var n=en.parse(e,t);return n.eval()});throw new TypeError("String or matrix expected")},en.format=function(e,n){var t=arguments.length;if(1!=t&&2!=t)throw O("format",t,1,2);if(1==t){var r=arguments[0];return g(r)?nn.formatNumber(r,en.options.precision):r instanceof Array?nn.formatArray(r):x(r)?'"'+r+'"':r instanceof Object?r.toString():String(r)}if(!x(e))throw new TypeError("String expected as first parameter in function format");if(!(n instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,t){for(var r=t.split("."),a=n[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})},en.help=function(e){if(1!=arguments.length)throw new SyntaxError("Wrong number of arguments in function help ("+arguments.length+" provided, 1 expected)");var n=null;if(e instanceof String||"string"==typeof e)n=e;else{var r;for(r in en)if(en.hasOwnProperty(r)&&e===en[r]){n=r;break}if(!n)for(r in en.type)if(en.type.hasOwnProperty(r)&&e===en.type[r]){n=r;break}}if(n){var a=en.docs[n];if(!a)throw new Error('No documentation found on "'+n+'"');return new t(a)}throw new Error('Could not find search term "'+e+'"')},en["import"]=function(e,n){var t,r={override:!1,wrap:!0};if(n&&n instanceof Object&&nn.extend(r,n),x(e)){if("undefined"==typeof require)throw new Error("Cannot load file: require not available.");var a=require(e);en["import"](a)}else if(J(e)){if(t=e.name,!t)throw new Error("Cannot import an unnamed function or object");(r.override||void 0===en[t])&&$(t,e,r)}else if(e instanceof Object)for(t in e)if(e.hasOwnProperty(t)){var i=e[t];J(i)?$(t,i,r):en["import"](i)}},function(){function e(){tn=0,rn=J.charAt(0)}function t(){tn++,rn=J.charAt(tn)}function a(){return J.charAt(tn+1)}function i(){for(on=Z.NULL,an="";" "==rn||" "==rn;)t();if("#"==rn)for(;"\n"!=rn&&""!=rn;)t();if(""==rn)return on=Z.DELIMITER,void 0;var e=rn+a();if(X[e])return on=Z.DELIMITER,an=e,t(),t(),void 0;if(X[rn])return on=Z.DELIMITER,an=rn,t(),void 0;if(s(rn)){if(on=Z.NUMBER,"."==rn)an+=rn,t(),f(rn)||(on=Z.UNKNOWN);else{for(;f(rn);)an+=rn,t();"."==rn&&(an+=rn,t())}for(;f(rn);)an+=rn,t();if("E"==rn||"e"==rn)for(an+=rn,t(),("+"==rn||"-"==rn)&&(an+=rn,t()),f(rn)||(on=Z.UNKNOWN);f(rn);)an+=rn,t()}else{if(!o(rn)){for(on=Z.UNKNOWN;""!=rn;)an+=rn,t();throw W('Syntax error in part "'+an+'"')}for(on=Z.SYMBOL;o(rn)||f(rn);)an+=rn,t()}}function o(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e}function s(e){return e>="0"&&"9">=e||"."==e}function f(e){return e>="0"&&"9">=e}function u(n){e(),i();var t;if(t=""==an?new M(void 0):c(n),""!=an)throw on==Z.DELIMITER?K("Unknown operator "+an):W('Unexpected part "'+an+'"');return t}function c(e){var n,t,r;for("\n"!=an&&";"!=an&&""!=an&&(n=l(e));"\n"==an||";"==an;)t||(t=new z,n&&(r=";"!=an,t.add(n,r))),i(),"\n"!=an&&";"!=an&&""!=an&&(n=l(e),r=";"!=an,t.add(n,r));return t?t:(n||(n=l(e)),n)}function l(e){var n=m(e),t="ans";return new R(t,n,e)}function m(e){if(on==Z.SYMBOL&&"function"==an){if(i(),on!=Z.SYMBOL)throw W("Function name expected");var n=an;if(i(),"("!=an)throw W("Opening parenthesis ( expected");for(var t=e.createSubScope(),r=[];;){if(i(),on!=Z.SYMBOL)throw W("Variable name expected");if(r.push(an),i(),","!=an){if(")"==an)break;throw W('Comma , or closing parenthesis ) expected"')}}if(i(),"="!=an)throw W("Equal sign = expected");i();var a=h(t);return new U(n,r,a,t,e)}return h(e)}function h(e){var n,t,r,a,o=p(e);if("="==an){if(o instanceof S)return i(),n=o.name,t=null,a=h(e),new R(n,a,e);if(o instanceof T&&o.object instanceof S)return i(),n=o.object.name,t=o.params,r=o.paramScopes,a=h(e),new C(n,t,r,a,e);throw W("Symbol expected at the left hand side of assignment operator =")}return o}function p(e){var n,t,r,a=[];if(n=":"==an?new M(0):g(e),":"==an){for(a.push(n);":"==an;)i(),")"==an||","==an||""==an?a.push(new S("end",e)):a.push(g(e));a.length&&(t="range",r=en.range,n=new A(t,r,a))}return n}function g(e){var n,t,r,a,o;for(n=v(e),t={"in":"in"};void 0!==t[an];)r=an,a=en[t[r]],i(),o=[n,v(e)],n=new A(r,a,o);return n}function v(e){var n=d(e);return n}function d(e){var n,t,r,a,o;for(n=y(e),t={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==t[an];)r=an,a=en[t[r]],i(),o=[n,y(e)],n=new A(r,a,o);return n}function y(e){var n,t,r,a,o;for(n=b(e),t={"+":"add","-":"subtract"};void 0!==t[an];)r=an,a=en[t[r]],i(),o=[n,b(e)],n=new A(r,a,o);return n}function b(e){var n,t,r,a,o;for(n=E(e),t={"*":"multiply",".*":"emultiply","/":"divide","./":"edivide","%":"mod",mod:"mod"};void 0!==t[an];)r=an,a=en[t[r]],i(),o=[n,E(e)],n=new A(r,a,o);return n}function E(e){var n,t,r;return"-"==an?(n=an,t=en.unary,i(),r=[N(e)],new A(n,t,r)):N(e)}function N(e){var n,t,r,a,o,s,f;for(r=[L(e)],a=[];"^"==an||".^"==an;)a.push(an),i(),r.push(L(e));for(n=r.pop();r.length;)t=r.pop(),o=a.pop(),s="^"==o?en.pow:en.epow,f=[t,n],n=new A(o,s,f);return n}function L(e){var n,t,r,a;for(n=I(e);"!"==an;)t=an,r=en.factorial,i(),a=[n],n=new A(t,r,a);return n}function I(e){var n,t,r,a;for(n=P(e);"'"==an;)t=an,r=en.transpose,i(),a=[n],n=new A(t,r,a);return n}function P(e){var n,t,r,a;if(on==Z.SYMBOL&&$[an]){if(a=$[an],i(),"("==an){if(n=[],t=[],i(),")"!=an)for(r=e.createSubScope(),t.push(r),n.push(p(r));","==an;)i(),r=e.createSubScope(),t.push(r),n.push(p(r));if(")"!=an)throw W("Parenthesis ) expected");i()}return new a(n,t)}return _(e)}function _(e){var n,t;return on==Z.SYMBOL?(t=an,i(),n=new S(t,e),B(e,n)):G(e)}function B(e,n){for(var t,r,a;"("==an;){if(t=[],r=[],i(),")"!=an)for(a=e.createSubScope(),r.push(a),t.push(p(a));","==an;)i(),a=e.createSubScope(),r.push(a),t.push(p(a));if(")"!=an)throw W("Parenthesis ) expected");i(),n=new T(n,t,r)}return n}function G(e){var n,r,a;if('"'==an){for(r="",a="";""!=rn&&('"'!=rn||"\\"==a);)r+=rn,a=rn,t();if(i(),'"'!=an)throw W('End of string " expected');return i(),n=new M(r),n=B(e,n)}return j(e)}function j(e){var n,t,r,a,o,s;if("["==an){for(i();"\n"==an;)i();if("]"!=an){for(t=[],r=0,a=0,t[0]=[h(e)];","==an||";"==an;){for(","==an?a++:(r++,a=0,t[r]=[]),i();"\n"==an;)i();for(t[r][a]=h(e);"\n"==an;)i()}for(o=t.length,s=t.length>0?t[0].length:0,r=1;o>r;r++)if(t[r].length!=s)throw K("Number of columns must match ("+t[r].length+" != "+s+")");if("]"!=an)throw W("End of matrix ] expected");i(),n=new q(t)}else i(),n=new q([[]]);return n=B(e,n)}return k(e)}function k(e){var t,r,a;if(on==Z.NUMBER){if(a="."==an?0:Number(an),i(),on==Z.SYMBOL){if("i"==an||"I"==an)return r=new n(0,a),i(),new M(r);if(w.isPlainUnit(an))return r=new w(a,an),i(),new M(r);throw Q('Unknown unit "'+an+'"')}return t=new M(a),t=B(e,t)}return F(e)}function F(e){var n;if("("==an){if(i(),n=h(e),")"!=an)throw W("Parenthesis ) expected");return i(),n=B(e,n)}return V(e)}function V(){throw""==an?W("Unexpected end of expression"):W("Value expected")}function H(){return void 0}function D(){return tn-an.length+1}function Y(e){var n=H(),t=D();return void 0===n?void 0===t?e:e+" (char "+t+")":e+" (line "+n+", char "+t+")"}function W(e){return new SyntaxError(Y(e))}function Q(e){return new TypeError(Y(e))}function K(e){return new Error(Y(e))}en.parse=function(e,n){if(1!=arguments.length&&2!=arguments.length)throw O("parse",arguments.length,1,2);var t;if(t=n?n instanceof en.expr.Scope?n:new en.expr.Scope(n):new en.expr.Scope,x(e))return J=e||"",u(t);if(e instanceof Array||e instanceof r)return nn.map(e,function(e){return J=e||"",u(t)});throw new TypeError("String or matrix expected")};var Z={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},X={",":!0,"(":!0,")":!0,"[":!0,"]":!0,'"':!0,"\n":!0,";":!0,"+":!0,"-":!0,"*":!0,".*":!0,"/":!0,"./":!0,"%":!0,"^":!0,".^":!0,"!":!0,"'":!0,"=":!0,":":!0,"==":!0,"!=":!0,"<":!0,">":!0,"<=":!0,">=":!0},$=en.expr.node.handlers,J="",tn=0,rn="",an="",on=Z.NULL}(),en.select=function(e){return new en.type.Selector(e)},en["typeof"]=function(e){if(1!=arguments.length)throw O("typeof",arguments.length,1);var n,t=typeof e;if("object"==t){if(null==e)return"null";if(e instanceof Boolean)return"boolean";if(e instanceof Number)return"number";if(e instanceof String)return"string";if(e instanceof Array)return"array";if(e instanceof Date)return"date";if(e.constructor){for(n in en)if(en.hasOwnProperty(n)&&e.constructor==en[n])return n.toLowerCase();for(n in en.type)if(en.type.hasOwnProperty(n)&&e.constructor==en.type[n])return n.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t},en.docs.Infinity={name:"Infinity",category:"Constants",syntax:["Infinity"],description:"Infinity, a number which is larger than the maximum number that can be handled by a floating point number.",examples:["Infinity","1 / 0"],seealso:[]},en.docs.LN10={name:"LN10",category:"Constants",syntax:["LN10"],description:"Returns the natural logarithm of 10, approximately equal to 2.302",examples:["LN10","log(10)"],seealso:[]},en.docs.LN2={name:"LN2",category:"Constants",syntax:["LN2"],description:"Returns the natural logarithm of 2, approximately equal to 0.693",examples:["LN2","log(2)"],seealso:[]},en.docs.LOG10E={name:"LOG10E",category:"Constants",syntax:["LOG10E"],description:"Returns the base-10 logarithm of E, approximately equal to 0.434",examples:["LOG10E","log(e, 10)"],seealso:[]},en.docs.LOG2E={name:"LOG2E",category:"Constants",syntax:["LOG2E"],description:"Returns the base-2 logarithm of E, approximately equal to 1.442",examples:["LOG2E","log(e, 2)"],seealso:[]},en.docs.NaN={name:"NaN",category:"Constants",syntax:["NaN"],description:"Not a number",examples:["NaN","0 / 0"],seealso:[]},en.docs.SQRT1_2={name:"SQRT1_2",category:"Constants",syntax:["SQRT1_2"],description:"Returns the square root of 1/2, approximately equal to 0.707",examples:["SQRT1_2","sqrt(1/2)"],seealso:[]},en.docs.SQRT2={name:"SQRT2",category:"Constants",syntax:["SQRT2"],description:"Returns the square root of 2, approximately equal to 1.414",examples:["SQRT2","sqrt(2)"],seealso:[]},en.docs.e=en.docs.E={name:"e",category:"Constants",syntax:["e"],description:"Euler's number, the base of the natural logarithm. Approximately equal to 2.71828",examples:["e","e ^ 2","exp(2)","log(e)"],seealso:["exp"]},en.docs["false"]={name:"false",category:"Constants",syntax:["false"],description:"Boolean value false",examples:["false"],seealso:["true"]},en.docs.i={name:"i",category:"Constants",syntax:["i"],description:"Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.",examples:["i","i * i","sqrt(-1)"],seealso:[]},en.docs.pi=en.docs.PI={name:"pi",category:"Constants",syntax:["pi"],description:"The number pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, and is approximately equal to 3.14159",examples:["pi","sin(pi/2)"],seealso:["tau"]},en.docs.tau={name:"tau",category:"Constants",syntax:["pi"],description:"Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi, approximately 6.2832.",examples:["tau","2 * pi"],seealso:["pi"]},en.docs["true"]={name:"true",category:"Constants",syntax:["true"],description:"Boolean value true",examples:["true"],seealso:["false"]},en.docs.abs={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},en.docs.add={name:"add",category:"Operators",syntax:["x + y","add(x, y)"],description:"Add two values.",examples:["2.1 + 3.6","ans - 3.6","3 + 2i",'"hello" + " world"',"3 cm + 2 inch"],seealso:["subtract"]},en.docs.ceil={name:"ceil",category:"Arithmetic",syntax:["ceil(x)"],description:"Round a value towards plus infinity.If x is complex, both real and imaginary part are rounded towards plus infinity.",examples:["ceil(3.2)","ceil(3.8)","ceil(-4.2)"],seealso:["floor","fix","round"]},en.docs.cube={name:"cube",category:"Arithmetic",syntax:["cube(x)"],description:"Compute the cube of a value. The cube of x is x * x * x.",examples:["cube(2)","2^3","2 * 2 * 2"],seealso:["multiply","square","pow"]},en.docs.divide={name:"divide",category:"Operators",syntax:["x / y","divide(x, y)"],description:"Divide two values.",examples:["2 / 3","ans * 3","4.5 / 2","3 + 4 / 2","(3 + 4) / 2","18 km / 4.5"],seealso:["multiply"]},en.docs.edivide={name:"edivide",category:"Operators",syntax:["x ./ y","edivide(x, y)"],description:"divide two values element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","b = [2, 1, 1; 3, 2, 5]","a ./ b"],seealso:["multiply","emultiply","divide"]},en.docs.emultiply={name:"emultiply",category:"Operators",syntax:["x .* y","emultiply(x, y)"],description:"multiply two values element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","b = [2, 1, 1; 3, 2, 5]","a .* b"],seealso:["multiply","divide","edivide"]},en.docs.epow={name:"epow",category:"Operators",syntax:["x .^ y","epow(x, y)"],description:"Calculates the power of x to y element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","a .^ 2"],seealso:["pow"]},en.docs.equal={name:"equal",category:"Operators",syntax:["x == y","equal(x, y)"],description:"Check equality of two values. Returns 1 if the values are equal, and 0 if not.",examples:["2+2 == 3","2+2 == 4","a = 3.2","b = 6-2.8","a == b","50cm == 0.5m"],seealso:["unequal","smaller","larger","smallereq","largereq"]},en.docs.exp={name:"exp",category:"Arithmetic",syntax:["exp(x)"],description:"Calculate the exponent of a value.",examples:["exp(1.3)","e ^ 1.3","log(exp(1.3))","x = 2.4","(exp(i*x) == cos(x) + i*sin(x)) # Euler's formula"],seealso:["square","multiply","log"]},en.docs.fix={name:"fix",category:"Arithmetic",syntax:["fix(x)"],description:"Round a value towards zero.If x is complex, both real and imaginary part are rounded towards zero.",examples:["fix(3.2)","fix(3.8)","fix(-4.2)","fix(-4.8)"],seealso:["ceil","floor","round"]},en.docs.floor={name:"floor",category:"Arithmetic",syntax:["floor(x)"],description:"Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.",examples:["floor(3.2)","floor(3.8)","floor(-4.2)"],seealso:["ceil","fix","round"]},en.docs.gcd={name:"gcd",category:"Arithmetic",syntax:["gcd(a, b)","gcd(a, b, c, ...)"],description:"Compute the greatest common divisor.",examples:["gcd(8, 12)","gcd(-4, 6)","gcd(25, 15, -10)"],seealso:["lcm","xgcd"]},en.docs.larger={name:"larger",category:"Operators",syntax:["x > y","larger(x, y)"],description:"Check if value x is larger than y. Returns 1 if x is larger than y, and 0 if not.",examples:["2 > 3","5 > 2*2","a = 3.3","b = 6-2.8","(a > b)","(b < a)","5 cm > 2 inch"],seealso:["equal","unequal","smaller","smallereq","largereq"]},en.docs.largereq={name:"largereq",category:"Operators",syntax:["x >= y","largereq(x, y)"],description:"Check if value x is larger or equal to y. Returns 1 if x is larger or equal to y, and 0 if not.",examples:["2 > 1+1","2 >= 1+1","a = 3.2","b = 6-2.8","(a > b)"],seealso:["equal","unequal","smallereq","smaller","largereq"]},en.docs.lcm={name:"lcm",category:"Arithmetic",syntax:["lcm(x, y)"],description:"Compute the least common multiple.",examples:["lcm(4, 6)","lcm(6, 21)","lcm(6, 21, 5)"],seealso:["gcd"]},en.docs.log={name:"log",category:"Arithmetic",syntax:["log(x)","log(x, base)"],description:"Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).",examples:["log(3.5)","a = log(2.4)","exp(a)","10 ^ 3","log(1000, 10)","log(1000) / log(10)","b = logb(1024, 2)","2 ^ b"],seealso:["exp","log10"]},en.docs.log10={name:"log10",category:"Arithmetic",syntax:["log10(x)"],description:"Compute the 10-base logarithm of a value.",examples:["log10(1000)","10 ^ 3","log10(0.01)","log(1000) / log(10)","log(1000, 10)"],seealso:["exp","log"]},en.docs.mod={name:"mod",category:"Operators",syntax:["x % y","x mod y","mod(x, y)"],description:"Calculates the modulus, the remainder of an integer division.",examples:["7 % 3","11 % 2","10 mod 4","function isOdd(x) = x % 2","isOdd(2)","isOdd(3)"],seealso:[]},en.docs.multiply={name:"multiply",category:"Operators",syntax:["x * y","multiply(x, y)"],description:"multiply two values.",examples:["2.1 * 3.6","ans / 3.6","2 * 3 + 4","2 * (3 + 4)","3 * 2.1 km"],seealso:["divide"]},en.docs.pow={name:"pow",category:"Operators",syntax:["x ^ y","pow(x, y)"],description:"Calculates the power of x to y, x^y.",examples:["2^3 = 8","2*2*2","1 + e ^ (pi * i)"],seealso:["unequal","smaller","larger","smallereq","largereq"]},en.docs.round={name:"round",category:"Arithmetic",syntax:["round(x)","round(x, n)"],description:"round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.",examples:["round(3.2)","round(3.8)","round(-4.2)","round(-4.8)","round(pi, 3)","round(123.45678, 2)"],seealso:["ceil","floor","fix"]},en.docs.sign={name:"sign",category:"Arithmetic",syntax:["sign(x)"],description:"Compute the sign of a value. The sign of a value x is 1 when x>1, -1 when x<0, and 0 when x=0.",examples:["sign(3.5)","sign(-4.2)","sign(0)"],seealso:["abs"]},en.docs.smaller={name:"smaller",category:"Operators",syntax:["x < y","smaller(x, y)"],description:"Check if value x is smaller than value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 3","5 < 2*2","a = 3.3","b = 6-2.8","(a < b)","5 cm < 2 inch"],seealso:["equal","unequal","larger","smallereq","largereq"]},en.docs.smallereq={name:"smallereq",category:"Operators",syntax:["x <= y","smallereq(x, y)"],description:"Check if value x is smaller or equal to value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 1+1","2 <= 1+1","a = 3.2","b = 6-2.8","(a < b)"],seealso:["equal","unequal","larger","smaller","largereq"]},en.docs.sqrt={name:"sqrt",category:"Arithmetic",syntax:["sqrt(x)"],description:"Compute the square root value. If x = y * y, then y is the square root of x.",examples:["sqrt(25)","5 * 5","sqrt(-1)"],seealso:["square","multiply"]},en.docs.square={name:"square",category:"Arithmetic",syntax:["square(x)"],description:"Compute the square of a value. The square of x is x * x.",examples:["square(3)","sqrt(9)","3^2","3 * 3"],seealso:["multiply","pow","sqrt","cube"]},en.docs.subtract={name:"subtract",category:"Operators",syntax:["x - y","subtract(x, y)"],description:"subtract two values.",examples:["5.3 - 2","ans + 2","2/3 - 1/6","2 * 3 - 3","2.1 km - 500m"],seealso:["add"]},en.docs.unary={name:"unary",category:"Operators",syntax:["-x","unary(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},en.docs.unequal={name:"unequal",category:"Operators",syntax:["x != y","unequal(x, y)"],description:"Check unequality of two values. Returns 1 if the values are unequal, and 0 if they are equal.",examples:["2+2 != 3","2+2 != 4","a = 3.2","b = 6-2.8","a != b","50cm != 0.5m","5 cm != 2 inch"],seealso:["equal","smaller","larger","smallereq","largereq"]},en.docs.xgcd={name:"xgcd",category:"Arithmetic",syntax:["xgcd(a, b)"],description:"Calculate the extended greatest common divisor for two values",examples:["xgcd(8, 12)","gcd(8, 12)","xgcd(36163, 21199)"],seealso:["gcd","lcm"]},en.docs.arg={name:"arg",category:"Complex",syntax:["arg(x)"],description:"Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).",examples:["arg(2 + 2i)","atan2(3, 2)","arg(2 - 3i)"],seealso:["re","im","conj","abs"]},en.docs.conj={name:"conj",category:"Complex",syntax:["conj(x)"],description:"Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.",examples:["conj(2 + 3i)","conj(2 - 3i)","conj(-5.2i)"],seealso:["re","im","abs","arg"]},en.docs.im={name:"im",category:"Complex",syntax:["im(x)"],description:"Get the imaginary part of a complex number.",examples:["im(2 + 3i)","re(2 + 3i)","im(-5.2i)","im(2.4)"],seealso:["re","conj","abs","arg"]},en.docs.re={name:"re",category:"Complex",syntax:["re(x)"],description:"Get the real part of a complex number.",examples:["re(2 + 3i)","im(2 + 3i)","re(-5.2i)","re(2.4)"],seealso:["im","conj","abs","arg"]},en.docs["boolean"]={name:"boolean",category:"Type",syntax:["x","boolean(x)"],description:"Convert a string or number into a boolean.",examples:["boolean(0)","boolean(1)","boolean(3)",'boolean("true")','boolean("false")'],seealso:["complex","matrix","range","string","unit"]},en.docs.complex={name:"complex",category:"Type",syntax:["complex()","complex(re, im)","complex(string)"],description:"Create a complex number.",examples:["complex()","complex(2, 3)",'complex("7 - 2i")'],seealso:["boolean","matrix","number","range","string","unit"]},en.docs.matrix={name:"matrix",category:"Type",syntax:["[]","[a1, b1, ...; a2, b2, ...]","matrix()","matrix([...])"],description:"Create a matrix.",examples:["[]","[1, 2, 3]","[1, 2, 3; 4, 5, 6]","matrix()","matrix([3, 4])"],seealso:["boolean","complex","number","range","string","unit"]},en.docs.number={name:"number",category:"Type",syntax:["x","number(x)"],description:"Create a number or convert a string or boolean into a number.",examples:["2","2e3","4.05","number(2)",'number("7.2")',"number(true)"],seealso:["boolean","complex","matrix","range","string","unit"]},en.docs.range={name:"range",category:"Type",syntax:["start:end","start:step:end","range(start, end)","range(start, step, end)","range(string)"],description:"Create a range.",examples:["1:5","3:-1:-3","range(3, 6)","range(0, 2, 10)",'range("4:10")',"a = [1, 2, 3; 4, 5, 6]","a(:, 1:2)"],seealso:["boolean","complex","matrix","number","string","unit"]},en.docs.string={name:"string",category:"Type",syntax:['"text"',"string(x)"],description:"Create a string or convert a value to a string",examples:['"Hello World!"',"string(4.2)","string(3 + 2i)"],seealso:["boolean","complex","matrix","number","range","unit"]},en.docs.unit={name:"unit",category:"Type",syntax:["value unit","unit(value, unit)","unit(string)"],description:"Create a unit.",examples:["5.5 mm","3 inch",'unit(7.1, "kilogram")','unit("23 deg")'],seealso:["boolean","complex","matrix","number","range","string"]},en.docs.concat={name:"concat",category:"Matrix",syntax:["concat(a, b, c, ...)","concat(a, b, c, ..., dim)"],description:"Concatenate matrices. By default, the matrices are concatenated by the first dimension. The dimension on which to concatenate can be provided as last argument.",examples:["a = [1, 2; 5, 6]","b = [3, 4; 7, 8]","concat(a, b)","[a, b]","concat(a, b, 2)","[a; b]"],seealso:["det","diag","eye","inv","ones","size","squeeze","subset","transpose","zeros"]},en.docs.det={name:"det",category:"Matrix",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["concat","diag","eye","inv","ones","size","squeeze","subset","transpose","zeros"]},en.docs.diag={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],description:"Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned.When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.",examples:["diag(1:4)","diag(1:4, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["concat","det","eye","inv","ones","size","squeeze","subset","transpose","zeros"]},en.docs.eye={name:"eye",category:"Matrix",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["concat","det","diag","inv","ones","size","squeeze","subset","transpose","zeros"]},en.docs.inv={name:"inv",category:"Matrix",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["concat","det","diag","eye","ones","size","squeeze","subset","transpose","zeros"]},en.docs.ones={name:"ones",category:"Matrix",syntax:["ones(n)","ones(m, n)","ones(m, n, p, ...)","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["concat","det","diag","eye","inv","size","squeeze","subset","transpose","zeros"]},en.docs.size={name:"size",category:"Matrix",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["concat","det","diag","eye","inv","ones","squeeze","subset","transpose","zeros"]},en.docs.squeeze={name:"squeeze",category:"Matrix",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["concat","det","diag","eye","inv","ones","size","subset","transpose","zeros"]},en.docs.subset={name:"subset",category:"Matrix",syntax:["value(index)","value(index) = replacement","subset(value, [index])","subset(value, [index], replacement)"],description:"Get or set a subset of a matrix or string.",examples:["d = [1, 2; 3, 4]","e = []","e(0, 0:1) = [5, 6]","e(1, :) = [7, 8]","f = d * e","f(1, 0)","f(:, 0)"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","transpose","zeros"]},en.docs.transpose={name:"transpose",category:"Matrix",syntax:["x'","transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","a'","transpose(a)"],seealso:["concat","det","diag","eye","inv","ones","size","squeeze","subset","zeros"]},en.docs.zeros={name:"zeros",category:"Matrix",syntax:["zeros(n)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["concat","det","diag","eye","inv","ones","size","squeeze","subset","transpose"]},en.docs.factorial={name:"factorial",category:"Probability",syntax:["x!","factorial(x)"],description:"Compute the factorial of a value",examples:["5!","5*4*3*2*1","3!"],seealso:[]},en.docs.random={name:"random",category:"Probability",syntax:["random(min, max)"],description:"Return a random number between 0 and 1.",examples:["random()"],seealso:[]},en.docs.randInt={name:"randInt",category:"Probability",syntax:["randInt()"],description:"Return a random number between 0 and 1.",examples:["randInt()"],seealso:[]},en.docs.max={name:"max",category:"Statistics",syntax:["max(a, b, c, ...)"],description:"Compute the maximum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["min"]},en.docs.min={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["min(2, 3, 4, 1)","min(2.7, 7.1, -4.5, 2.0, 4.1)","max(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["max"]},en.docs.acos={name:"acos",category:"Trigonometry",syntax:["acos(x)"],description:"Compute the inverse cosine of a value in radians.",examples:["acos(0.5)","acos(cos(2.3))"],seealso:["cos","acos","asin"]},en.docs.asin={name:"asin",category:"Trigonometry",syntax:["asin(x)"],description:"Compute the inverse sine of a value in radians.",examples:["asin(0.5)","asin(sin(2.3))"],seealso:["sin","acos","asin"]},en.docs.atan={name:"atan",category:"Trigonometry",syntax:["atan(x)"],description:"Compute the inverse tangent of a value in radians.",examples:["atan(0.5)","atan(tan(2.3))"],seealso:["tan","acos","asin"]},en.docs.atan2={name:"atan2",category:"Trigonometry",syntax:["atan2(y, x)"],description:"Computes the principal value of the arc tangent of y/x in radians.",examples:["atan2(2, 2) / pi","angle = 60 deg in rad","x = cos(angle)","y = sin(angle)","atan2(y, x)"],seealso:["sin","cos","tan"]},en.docs.cos={name:"cos",category:"Trigonometry",syntax:["cos(x)"],description:"Compute the cosine of x in radians.",examples:["cos(2)","cos(pi / 4) ^ 2","cos(180 deg)","cos(60 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["acos","sin","tan"]},en.docs.cot={name:"cot",category:"Trigonometry",syntax:["cot(x)"],description:"Compute the cotangent of x in radians. Defined as 1/tan(x)",examples:["cot(2)","1 / tan(2)"],seealso:["sec","csc","tan"]},en.docs.csc={name:"csc",category:"Trigonometry",syntax:["csc(x)"],description:"Compute the cosecant of x in radians. Defined as 1/sin(x)",examples:["csc(2)","1 / sin(2)"],seealso:["sec","cot","sin"]},en.docs.sec={name:"sec",category:"Trigonometry",syntax:["sec(x)"],description:"Compute the secant of x in radians. Defined as 1/cos(x)",examples:["sec(2)","1 / cos(2)"],seealso:["cot","csc","cos"]},en.docs.sin={name:"sin",category:"Trigonometry",syntax:["sin(x)"],description:"Compute the sine of x in radians.",examples:["sin(2)","sin(pi / 4) ^ 2","sin(90 deg)","sin(30 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["asin","cos","tan"]},en.docs.tan={name:"tan",category:"Trigonometry",syntax:["tan(x)"],description:"Compute the tangent of x in radians.",examples:["tan(0.5)","sin(0.5) / cos(0.5)","tan(pi / 4)","tan(45 deg)"],seealso:["atan","sin","cos"]},en.docs["in"]={name:"in",category:"Units",syntax:["x in unit","in(x, unit)"],description:"Change the unit of a value.",examples:["5 inch in cm","3.2kg in g","16 bytes in bits"],seealso:[]},en.docs.clone={name:"clone",category:"Utils",syntax:["clone(x)"],description:"Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices",examples:["clone(3.5)","clone(2 - 4i)","clone(45 deg)","clone([1, 2; 3, 4])",'clone("hello world")'],seealso:[]},en.docs.eval={name:"eval",category:"Utils",syntax:["eval(expression)","eval([expr1, expr2, expr3, ...])"],description:"Evaluate an expression or an array with expressions.",examples:['eval("2 + 3")','eval("sqrt(" + 4 + ")")'],seealso:[]},en.docs.format={name:"format",category:"Utils",syntax:["format(value)"],description:"Format a value of any type as string.",examples:["format(2.3)","format(3 - 4i)","format([])"],seealso:[]},en.docs.help={name:"help",category:"Utils",syntax:["help(object)","help(string)"],description:"Display documentation on a function or data type.",examples:["help(sqrt)",'help("complex")'],seealso:[]},en.docs["import"]={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},en.docs["typeof"]={name:"typeof",category:"Utils",syntax:["typeof(x)"],description:"Get the type of a variable.",examples:["typeof(3.5)","typeof(2 - 4i)","typeof(45 deg)",'typeof("hello world")'],seealso:[]},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var n=0;n<this.length;n++)if(this[n]==e)return n;
|
|
return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,n){for(var t=0,r=this.length;r>t;++t)e.call(n||this,this[t],t,this)}),Array.prototype.map||(Array.prototype.map=function(e,n){var t,r,a;if(null==this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(n&&(t=n),r=new Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(t,s,a,i),r[a]=f),a++}return r}),Array.prototype.every||(Array.prototype.every=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&!e.call(r,n[a],a,n))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&e.call(r,n[a],a,n))return!0;return!1}),Function.prototype.bind||(Function.prototype.bind=function(e){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var n=Array.prototype.slice.call(arguments,1),t=this,r=function(){},a=function(){return t.apply(this instanceof r&&e?this:e,n.concat(Array.prototype.slice.call(arguments)))};return r.prototype=this.prototype,a.prototype=new r,a});for(var sn in en)en.hasOwnProperty(sn)&&sn&&y(sn,en[sn]);"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=en),"undefined"!=typeof exports&&(exports=en),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return en}),"undefined"!=typeof window&&(window.math?nn.deepExtend(window.math,en):window.math=en)}(); |