mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
29 lines
85 KiB
JavaScript
29 lines
85 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.8.3-SNAPSHOT
|
|
* @date 2013-05-29
|
|
*
|
|
* @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");if(null!=e&&!m(e)||null!=t&&!m(t))throw new TypeError("Two numbers expected in Complex constructor");this.re=e||0,this.im=t||0}function t(e){if(!(this instanceof t))throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof t||e instanceof g)this._data=e.toArray();else if(e instanceof Array)this._data=e;else{if(null!=e)throw new TypeError("Unsupported type of data ("+$["typeof"](e)+")");this._data=[]}this._size=en.size(this._data)}function r(e,n){return en.validateIndex(n,e.length),e[n-1]}function i(e,n){return n.forEach(function(n){e=r(e,n)}),$.clone(e)}function a(e,n){var t=n[0];return t.map?t.map(function(n){return r(e,n)}):[r(e,t)]}function o(e,n){var t=n[0],i=n[1];if(t.map)return i.map?t.map(function(n){var t=r(e,n);return i.map(function(e){return r(t,e)})}):t.map(function(n){return[r(r(e,n),i)]});if(i.map){var a=r(e,t);return[i.map(function(e){return r(a,e)})]}return[[r(r(e,t),i)]]}function s(e,n,t){var i=t==n.length-1,a=n[t],o=function(a){var o=r(e,a);return i?o:s(o,n,t+1)};return a.map?a.map(o):[o(a)]}function f(e,n,t){if(en.validateIndex(n),t instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[n-1]=t}function u(e,n,t,r){var i=!1;t.length>n.length&&(i=!0);for(var a=0;a<t.length;a++){var o=t[a];en.validateIndex(o),(null==n[a]||o>n[a])&&(n[a]=o,i=!0)}i&&en.resize(e,n,0);var s=n.length;t.forEach(function(n,t){s-1>t?e=e[n-1]:e[n-1]=r})}function c(e,n,t,r){var i=t[0];en.validateIndex(i),i>n[0]&&(en.resize(e,[i],0),n[0]=i),e[i-1]=r}function l(e,n,t,r){var i=t[0],a=t[1];en.validateIndex(i),en.validateIndex(a);var o=!1;i>(n[0]||0)&&(n[0]=i,o=!0),a>(n[1]||0)&&(n[1]=a,o=!0),o&&en.resize(e,n,0),e[i-1][a-1]=r}function h(e,n,t,r,i){var a=r==t.length-1,o=t[r],s=function(o,s){if(a)f(e,o,i[s]),o>(n[r]||0)&&(n[r]=o);else{var u=e[o-1];u instanceof Array||(e[o-1]=u=[u]),o>(n[r]||0)&&(n[r]=o),h(u,n,t,r+1,i[s])}};if(o.map){var u=o.size&&o.size()||o.length;if(u!=i.length)throw new RangeError("Dimensions mismatch ("+u+" != "+i.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 m(e){return e instanceof Number||"number"==typeof e}function v(e){return e==Math.round(e)}function g(e,n,t){if(!(this instanceof g))throw new SyntaxError("Range constructor must be called with the new operator");if(null!=e&&!m(e))throw new TypeError("Parameter start must be a number");if(null!=t&&!m(t))throw new TypeError("Parameter end must be a number");if(null!=n&&!m(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 w(e,n){var t=$.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 d(e){return e instanceof String||"string"==typeof e}function y(e,n){if(!(this instanceof y))throw new Error("Unit constructor must be called with the new operator");if(null!=e&&!m(e))throw new TypeError("First parameter in Unit constructor must be a number");if(null!=n&&!d(n))throw new TypeError("Second parameter in Unit constructor must be a string");if(null!=n){var t=E(n);if(!t)throw new SyntaxError('String "'+n+'" is no unit');this.unit=t.unit,this.prefix=t.prefix}else this.unit=y.UNIT_NONE,this.prefix=y.PREFIX_NONE;null!=e?(this.value=this._normalize(e),this.fixPrefix=!1):(this.value=null,this.fixPrefix=!0)}function E(e){for(var n=y.UNITS,t=0,r=n.length;r>t;t++){var i=n[t];if(en.endsWith(e,i.name)){var a=e.length-i.name.length,o=e.substring(0,a),s=i.prefixes[o];if(void 0!==s)return{unit:i,prefix:s}}}return null}function x(e,n){var t=void 0;if(2==arguments.length){var r=$["typeof"](n);t="Function "+e+"("+r+") not supported"}else if(arguments.length>2){for(var i=[],a=1;a<arguments.length;a++)i.push($["typeof"](arguments[a]));t="Function "+e+"("+i.join(", ")+") not supported"}else t="Unsupported parameter in function "+e;return new TypeError(t)}function N(e,n,t,r){var i="Wrong number of arguments in function "+e+" ("+n+" provided, "+t+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(i)}function O(){}function b(e){this.value=e}function M(e,n,t){this.name=e,this.fn=n,this.params=t}function A(e,n){this.name=e,this.scope=n}function S(e,n,t){if(this.object=e,this.params=n,this.paramScopes=t,this.hasContextParams=!1,n)for(var r={type:$.type.SymbolNode,properties:{name:"end"}},i=0,a=n.length;a>i;i++)if(n[i].find(r).length>0){this.hasContextParams=!0;break}}function T(e){this.nodes=e||[]}function U(){this.params=[],this.visible=[]}function R(e,n,t){this.name=e,this.expr=n,this.scope=t}function z(e,n,t,r,i){this.name=e,this.params=n,this.paramScopes=t,this.expr=r,this.scope=i,this.hasContextParams=!1;for(var a={type:$.type.SymbolNode,properties:{name:"end"}},o=0,s=n.length;s>o;o++)if(n[o].find(a).length>0){this.hasContextParams=!0;break}}function L(e,n,t,r,i){this.name=e,this.variables=n,this.scope=i,this.fn=function(){var i=n?n.length:0;if(arguments.length!=i)throw N(e,arguments.length,i);for(var a=0;i>a;a++)r.set(n[a],arguments[a]);return t.eval()},this.fn.toString=function(){return e+"("+n.join(", ")+")"}}function _(){this.idMax=-1,this.updateSeq=0,this.scope=new $.expr.Scope,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}function q(e,t){var r=t.re*t.re+t.im*t.im;return new n((e.re*t.re+e.im*t.im)/r,(e.im*t.re-e.re*t.im)/r)}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 new n(e.re*t.re-e.im*t.im,e.re*t.im+e.im*t.re)}function B(e,n){var t=$.log(e),r=$.multiply(t,n);return $.exp(r)}function C(e,n){if(n){var t=Math.pow(10,n);return Math.round(e*t)/t}return Math.round(e)}function G(e,n,t,r){if(t>r){if(e.length!=n.length)throw new Error("Dimensions mismatch ("+e.length+" != "+n.length+")");for(var i=[],a=0;a<e.length;a++)i[a]=G(e[a],n[a],t,r+1);return i}return e.concat(n)}function F(e,n,t){var r=$.multiply,i=$.subtract;if(1==n)return e[0][0];if(2==n)return i(r(e[0][0],e[1][1]),r(e[1][0],e[0][1]));for(var a=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 en.deepEqual(e,$.eye(n).valueOf())?$.round(a,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}a*=-1}for(var l=e[s][o],u=0;t>u;u++)e[s][u]=e[s][u]/l;a*=l;for(var h=0;n>h;h++)if(h!=s)for(var p=e[h][o],u=0;t>u;u++)e[h][u]=e[h][u]-e[s][u]*p;o++}return en.deepEqual(e,$.eye(n).valueOf())?$.round(a,6):0}function V(e,n,t){var r,i,a,o,s,f=$.add,u=$.unaryminus,c=$.multiply,l=$.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 h=$.det(e);if(0==h)throw Error("Cannot calculate inverse, determinant is zero");return[[l(e[1][1],h),l(u(e[0][1]),h)],[l(u(e[1][0]),h),l(e[0][0],h)]]}var p=e.concat();for(r=0;n>r;r++)p[r]=p[r].concat();for(var m=$.eye(n).valueOf(),v=0;t>v;v++){for(r=v;n>r&&0==p[r][v];)r++;if(r==n||0==p[r][v])throw Error("Cannot calculate inverse, determinant is zero");r!=v&&(s=p[v],p[v]=p[r],p[r]=s,s=m[v],m[v]=m[r],m[r]=s);var g=p[v],w=m[v];for(r=0;n>r;r++){var d=p[r],y=m[r];if(r!=v){if(0!=d[v]){for(a=l(u(d[v]),g[v]),i=v;t>i;i++)d[i]=f(d[i],c(a,g[i]));for(i=0;t>i;i++)y[i]=f(y[i],c(a,w[i]))}}else{for(a=g[v],i=v;t>i;i++)d[i]=l(d[i],a);for(i=0;t>i;i++)y[i]=l(y[i],a)}}}return m}function j(e){if(1==e.length)return j(e[0]);for(var n=0,t=e.length;t>n;n++){var r=e[n];r instanceof Array&&(e[n]=j(r))}return e}function D(e,n){var r,i;return e instanceof Array||e instanceof g?(r=$.matrix(e),i=r.get(n),i.valueOf()):e instanceof t?e.get(n):d(e)?H(e,n):(r=$.matrix([e]),i=r.get(n),i.valueOf())}function H(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 i="",a=e.length;for(t=0,r=n.length;r>t;t++){var o=n[t];en.validateIndex(o,a),i+=e.charAt(o-1)}return i}function k(e,n,r){if(e instanceof Array||e instanceof g){var i=$.matrix($.clone(e));return i.set(n,r),i.valueOf()}return e instanceof t?e.clone().set(n,r):d(e)?Y(e,n,r):(i=$.matrix([e]),i.set(n,r),i.isScalar()?i.toScalar():i.valueOf())}function Y(e,n,t){var r,i;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 a=e.length,o=[];for(r=0;a>r;r++)o[r]=e.charAt(r);for(r=0,i=n.length;i>r;r++){var s=n[r];en.validateIndex(s),o[s-1]=t.charAt(r)}if(o.length>a)for(r=a-1,i=o.length;i>r;r++)o[r]||(o[r]=" ");return o.join("")}function W(e){for(var n=$.larger,t=e[0],r=1,i=e.length;i>r;r++){var a=e[r];n(a,t)&&(t=a)}return t}function K(e,n,t){for(var r=$.larger,i=[],a=0;t>a;a++){for(var o=e[0][a],s=1;n>s;s++){var f=e[s][a];r(f,o)&&(o=f)}i[a]=o}return i}function Z(e){for(var n=$.smaller,t=e[0],r=1,i=e.length;i>r;r++){var a=e[r];n(a,t)&&(t=a)}return t}function X(e,n,t){for(var r=$.smaller,i=[],a=0;t>a;a++){for(var o=e[0][a],s=1;n>s;s++){var f=e[s][a];r(f,o)&&(o=f)}i[a]=o}return i}function Q(e,n,t){(t.override||void 0===$[e])&&($[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($,e)}:n,w(e,n))}function J(e){return"function"==typeof e||m(e)||d(e)||e instanceof n||e instanceof y}var $={type:{},expr:{node:{}},options:{precision:5}};"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=$),"undefined"!=typeof exports&&(exports=$),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return $}),"undefined"!=typeof window&&(window.math=$);var en=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 i,a=e.length;if(a!=t[r])throw new RangeError("Dimension mismatch ("+a+" != "+t[r]+")");if(r<t.length-1){var o=r+1;for(i=0;a>i;i++){var s=e[i];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(t.length-1)+" < "+t.length+")");n(e[i],t,o)}}else for(i=0;a>i;i++)if(e[i]instanceof Array)throw new RangeError("Dimension mismatch ("+(t.length+1)+" > "+t.length+")")}function r(e,n,t){if(t<n.length-1){var i=e[0];if(1!=e.length||!(i instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");r(i,n,t+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function i(e,n,t,r){if(!(e instanceof Array))throw new TypeError("Array expected");var a=e.length,o=n[t];if(a!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?$.clone(r):0;else e.length=n[t];a=e.length}if(t<n.length-1){var f=t+1;for(s=0;a>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),i(u,n,f,r)}else for(s=0;a>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var a={};a.formatNumber=function(e,n){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var t=Math.abs(e);if(t>.001&&1e5>t||0==t)return a.toPrecision(e,n);var r=Math.round(Math.log(t)/Math.LN10),i=e/Math.pow(10,r);return a.toPrecision(i,n)+"e"+r},a.toPrecision=function(e,n){return void 0==n&&(n=$.options.precision),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 a.formatArray=function(e){if(e instanceof Array){for(var n="[",t=e.length,r=0;t>r;r++)0!=r&&(n+=", "),n+=a.formatArray(e[r]);return n+="]"}return $.format(e)},a.formatArray2d=function(e){var n="[",t=a.size(e);if(2!=t.length)throw new RangeError("Array must be two dimensional (size: "+a.formatArray(t)+")");for(var r=t[0],i=t[1],o=0;r>o;o++){0!=o&&(n+="; ");for(var s=e[o],f=0;i>f;f++){0!=f&&(n+=", ");var u=s[f];void 0!=u&&(n+=$.format(u))}}return n+="]"},a.argsToArray=function(e){var n;if(0==e.length)n=[];else if(1==e.length)n=e[0],n instanceof t&&(n=n.toVector()),n instanceof g&&(n=n.valueOf()),n instanceof Array||(n=[n]);else{n=[];for(var r=0;r<e.length;r++)n[r]=e[r]}return n},a.endsWith=function(e,n){var t=e.length-n.length,r=e.length;return e.substring(t,r)===n},a.extend=function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e},a.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},a.map=function(e,n){if(e instanceof Array||e instanceof t||e instanceof g)return e.map(function(e){return n(e)});throw new TypeError("Array expected")},a.map2=function(e,n,r){var i,o,s;if(e instanceof t||n instanceof t)return new t(a.map2(e.valueOf(),n.valueOf(),r));if(e instanceof g||n instanceof g)return a.map2(e.valueOf(),n.valueOf(),r);if(e instanceof Array)if(n instanceof Array){if(e.length!=n.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+n.length+")");for(i=[],o=e.length,s=0;o>s;s++)i[s]=r(e[s],n[s])}else for(i=[],o=e.length,s=0;o>s;s++)i[s]=r(e[s],n);else if(n instanceof Array)for(i=[],o=n.length,s=0;o>s;s++)i[s]=r(e,n[s]);else i=r(e,n);return i},a.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)},a.mapObject=function(e,n){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},a.deepEqual=function(e,n){var t,r,i;if(e instanceof Array){if(!(n instanceof Array))return!1;for(r=0,i=e.length;i>r;r++)if(!a.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)&&!a.deepEqual(e[t],n[t]))return!1;for(t in n)if(n.hasOwnProperty(t)&&!a.deepEqual(e[t],n[t]))return!1;return!0}return e.valueOf()==n.valueOf()},a.size=function(n){var t=e(n);return a.validate(n,t),t},a.validate=function(e,t){var i=0==t.length;if(i){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=t.indexOf(0);o?(t.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+a.formatArray(t)+")")}),r(e,t,0)):n(e,t,0)}},a.validateIndex=function(e,n){if(!m(e)||!v(e))throw new TypeError("Index must be an integer (value: "+e+")");if(1>e)throw new RangeError("Index out of range ("+e+" < 1)");if(n&&e>n)throw new RangeError("Index out of range ("+e+" > "+n+")")},a.resize=function(e,n,t){if(!(n instanceof Array))throw new TypeError("Size must be an array (size is "+$["typeof"](n)+")");n.forEach(function(e){if(!m(e)||!v(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+a.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: "+a.formatArray(n)+")")}),i(e,n,0,t)},a}();$.type.Complex=n,function(){function e(){for(;" "==c||" "==c;)i()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function i(){u++,c=f.charAt(u)}function a(e){u=e,c=f.charAt(u)}function o(){var e,n="";if(e=u,"+"==c?i():"-"==c&&(n+=c,i()),!t(c))return a(e),null;if("."==c){if(n+=c,i(),!r(c))return a(e),null}else{for(;r(c);)n+=c,i();"."==c&&(n+=c,i())}for(;r(c);)n+=c,i();if("E"==c||"e"==c){if(n+=c,i(),("+"==c||"-"==c)&&(n+=c,i()),!r(c))return a(e),null;for(;r(c);)n+=c,i()}return n}function s(){var e=f.charAt(u+1);if("I"==c||"i"==c)return i(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var n="+"==c?"1":"-1";return i(),i(),n}return null}var f,u,c;n.parse=function(t){if(f=t,u=-1,c="",!d(f))return null;i(),e();var r=o();if(r){if("I"==c||"i"==c)return i(),e(),c?null:new n(0,Number(r));e();var a=c;if("+"!=a&&"-"!=a)return e(),c?null:new n(Number(r),0);i(),e();var l=o();if(l){if("I"!=c&&"i"!=c)return null;i()}else if(l=s(),!l)return null;return"-"==a&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),i(),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=en.formatNumber(this.re),t=en.formatNumber(this.im);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+" - "+en.formatNumber(Math.abs(this.im))+"i"},$.type.Matrix=t,t.prototype.get=function(e){var n;if(e instanceof t)n=1==e.size().length||!e.size().some(function(e){return 1!=e}),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Invalid index");n=!e.some(function(e){var n=$.size(e);return 0!=n.length&&n!=[1]})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(n)switch(e.length){case 1:return r(this._data,e[0]);case 2:return r(r(this._data,e[0]),e[1]);default:return i(this._data,e)}else switch(e.length){case 1:return new t(a(this._data,e));case 2:return new t(o(this._data,e));default:return new t(s(this._data,e,0))}},t.prototype.set=function(e,n){var r;if(e instanceof t)r=1==e.size().length||!e.size().some(function(e){return 1!=e}),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Invalid index");r=!e.some(function(e){var n=$.size(e);return 0!=n.length&&n!=[1]})}if((n instanceof t||n instanceof g)&&(n=n.valueOf()),e.length<this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(r){if(0!=$.size(n).length)throw new TypeError("Scalar value expected");switch(e.length){case 1:c(this._data,this._size,e,n);break;case 2:l(this._data,this._size,e,n);break;default:u(this._data,this._size,e,n)}}else{var i=this._size.concat();h(this._data,i,e,0,n),en.deepEqual(this._size,i)||(p(this._data),this.resize(i))}return this},t.prototype.resize=function(e,n){en.resize(this._data,e,n),this._size=$.clone(e)},t.prototype.clone=function(){var e=new t;return e._data=$.clone(this._data),e._size=$.clone(this._size),e},t.prototype.size=function(){return this._size},t.prototype.map=function(e){var n=this,r=new t,i=[],a=function(t,r){return t instanceof Array?t.map(function(e,n){return i[r]=n+1,a(e,r+1)}):e(t,i,n)};return r._data=a(this._data,0),r._size=$.clone(this._size),r},t.prototype.forEach=function(e){var n=this,t=[],r=function(i,a){i instanceof Array?i.forEach(function(e,n){t[a]=n+1,r(e,a+1)}):e(i,t,n)};r(this._data,0)},t.prototype.toScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=e[0];return e instanceof Array?null:$.clone(e)},t.prototype.isScalar=function(){return this._size.every(function(e){return 1>=e})},t.prototype.toVector=function(){var e=0,n=void 0,t=[];if(this._size.forEach(function(r,i){r>1&&(e++,n=i),t[i]=0}),0==e){var r=this.toScalar();return r?[r]:[]}if(1==e){var i=[],a=function(e){e instanceof Array?e.forEach(a):i.push(e)};return a(this._data),i}return null},t.prototype.isVector=function(){var e=0;return this._size.forEach(function(n){n>1&&e++}),1>=e},t.prototype.toArray=function(){return $.clone(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.toString=function(){return $.format(this._data)},$.type.Range=g,g.parse=function(e){if(!d(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 g(t[0],1,t[1]);case 3:return new g(t[0],t[1],t[2]);default:return null}},g.prototype.clone=function(){return new g(this.start,this.step,this.end)},g.prototype.size=function(){var e=0,n=Number(this.start),t=Number(this.step),r=Number(this.end),i=r-n;return $.sign(t)==$.sign(i)?e=Math.floor(i/t)+1:0==i&&(e=1),isNaN(e)&&(e=0),[e]},g.prototype.forEach=function(e){var n=Number(this.start),t=Number(this.step),r=Number(this.end),i=0;if(t>0)for(;r>=n;)e(n,i,this),n+=t,i++;else if(0>t)for(;n>=r;)e(n,i,this),n+=t,i++},g.prototype.map=function(e){var n=[];return this.forEach(function(t,r,i){n[r]=e(t,r,i)}),n},g.prototype.toMatrix=function(){return new t(this.toArray())},g.prototype.toArray=function(){var e=[];return this.forEach(function(n,t){e[t]=n}),e},g.prototype.toVector=g.prototype.toArray,g.prototype.isVector=function(){return!0},g.prototype.toScalar=function(){var e=this.toArray();return 1==e.length?e[0]:null},g.prototype.isScalar=function(){return 1==this.size()[0]},g.prototype.valueOf=function(){return this.toArray()},g.prototype.toString=function(){var e=$.format(Number(this.start));return 1!=this.step&&(e+=":"+$.format(Number(this.step))),e+=":"+$.format(Number(this.end))},$.type.Selector=function(e){if(!(this instanceof $.type.Selector))throw new SyntaxError("Selector constructor must be called with the new operator");this.value=e instanceof $.type.Selector?e.value:e||void 0},$.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 $.type.Selector($.subset(n,e))},set:function(e,n){var t=this.value;if(!t)throw Error("Selector value is undefined");return new $.type.Selector($.subset(t,e,n))},valueOf:function(){return this.value},toString:function(){return $.format(this.value)}},$.type.Unit=y,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 i(e){f=e,u=s.charAt(f)}function a(){var e,a="";if(e=f,"+"==u?r():"-"==u&&(a+=u,r()),!n(u))return i(e),null;if("."==u){if(a+=u,r(),!t(u))return i(e),null}else{for(;t(u);)a+=u,r();"."==u&&(a+=u,r())}for(;t(u);)a+=u,r();if("E"==u||"e"==u){if(a+=u,r(),("+"==u||"-"==u)&&(a+=u,r()),!t(u))return i(e),null;for(;t(u);)a+=u,r()}return a}function o(){var n="";for(e();u&&" "!=u&&" "!=u;)n+=u,r();return n||null}var s,f,u;y.parse=function(n){if(s=n,f=-1,u="",!d(s))return null;r(),e();var t,i=a();return i?(t=o(),r(),e(),u?null:i&&t?new y(Number(i),t):null):(t=o(),r(),e(),u?null:new y(null,t))}}(),y.prototype.clone=function(){var e=new y;for(var n in this)this.hasOwnProperty(n)&&(e[n]=this[n]);return e},y.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},y.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},y.isPlainUnit=function(e){return null!=E(e)},y.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},y.prototype.equalBase=function(e){return this.unit.base===e.unit.base},y.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},y.prototype["in"]=function(e){var n;if(d(e)){if(n=new y(null,e),!this.equalBase(n))throw new Error("Units do not match");return n.value=this.value,n}if(e instanceof y){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")},y.prototype.toNumber=function(e){var n=this["in"](e),t=this.fixPrefix?n._bestPrefix():n.prefix;return n._unnormalize(n.value,t.value)},y.prototype.toString=function(){var e,n;if(this.fixPrefix)e=this._unnormalize(this.value),n=null!=this.value?en.formatNumber(e)+" ":"",n+=this.prefix.name+this.unit.name;else{var t=this._bestPrefix();e=this._unnormalize(this.value,t.value),n=null!=this.value?en.formatNumber(e)+" ":"",n+=t.name+this.unit.name}return n},y.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),n=y.PREFIX_NONE,t=Math.abs(Math.log(e/n.value)/Math.LN10-1.2),r=this.unit.prefixes;for(var i in r)if(r.hasOwnProperty(i)){var a=r[i];if(a.scientific){var o=Math.abs(Math.log(e/a.value)/Math.LN10-1.2);t>o&&(n=a,t=o)}}return n},y.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}}},y.PREFIX_NONE={name:"",value:1,scientific:!0},y.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var nn=y.BASE_UNITS,tn=y.PREFIXES;y.BASE_UNIT_NONE={},y.UNIT_NONE={name:"",base:y.BASE_UNIT_NONE,value:1,offset:0},y.UNITS=[{name:"meter",base:nn.LENGTH,prefixes:tn.LONG,value:1,offset:0},{name:"inch",base:nn.LENGTH,prefixes:tn.NONE,value:.0254,offset:0},{name:"foot",base:nn.LENGTH,prefixes:tn.NONE,value:.3048,offset:0},{name:"yard",base:nn.LENGTH,prefixes:tn.NONE,value:.9144,offset:0},{name:"mile",base:nn.LENGTH,prefixes:tn.NONE,value:1609.344,offset:0},{name:"link",base:nn.LENGTH,prefixes:tn.NONE,value:.201168,offset:0},{name:"rod",base:nn.LENGTH,prefixes:tn.NONE,value:5.02921,offset:0},{name:"chain",base:nn.LENGTH,prefixes:tn.NONE,value:20.1168,offset:0},{name:"angstrom",base:nn.LENGTH,prefixes:tn.NONE,value:1e-10,offset:0},{name:"m",base:nn.LENGTH,prefixes:tn.SHORT,value:1,offset:0},{name:"ft",base:nn.LENGTH,prefixes:tn.NONE,value:.3048,offset:0},{name:"yd",base:nn.LENGTH,prefixes:tn.NONE,value:.9144,offset:0},{name:"mi",base:nn.LENGTH,prefixes:tn.NONE,value:1609.344,offset:0},{name:"li",base:nn.LENGTH,prefixes:tn.NONE,value:.201168,offset:0},{name:"rd",base:nn.LENGTH,prefixes:tn.NONE,value:5.02921,offset:0},{name:"ch",base:nn.LENGTH,prefixes:tn.NONE,value:20.1168,offset:0},{name:"mil",base:nn.LENGTH,prefixes:tn.NONE,value:254e-7,offset:0},{name:"m2",base:nn.SURFACE,prefixes:tn.SHORT,value:1,offset:0},{name:"sqin",base:nn.SURFACE,prefixes:tn.NONE,value:64516e-8,offset:0},{name:"sqft",base:nn.SURFACE,prefixes:tn.NONE,value:.09290304,offset:0},{name:"sqyd",base:nn.SURFACE,prefixes:tn.NONE,value:.83612736,offset:0},{name:"sqmi",base:nn.SURFACE,prefixes:tn.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:nn.SURFACE,prefixes:tn.NONE,value:25.29295,offset:0},{name:"sqch",base:nn.SURFACE,prefixes:tn.NONE,value:404.6873,offset:0},{name:"sqmil",base:nn.SURFACE,prefixes:tn.NONE,value:6.4516e-10,offset:0},{name:"m3",base:nn.VOLUME,prefixes:tn.SHORT,value:1,offset:0},{name:"L",base:nn.VOLUME,prefixes:tn.SHORT,value:.001,offset:0},{name:"litre",base:nn.VOLUME,prefixes:tn.LONG,value:.001,offset:0},{name:"cuin",base:nn.VOLUME,prefixes:tn.NONE,value:16387064e-12,offset:0},{name:"cuft",base:nn.VOLUME,prefixes:tn.NONE,value:.028316846592,offset:0},{name:"cuyd",base:nn.VOLUME,prefixes:tn.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:nn.VOLUME,prefixes:tn.NONE,value:5e-6,offset:0},{name:"tablespoon",base:nn.VOLUME,prefixes:tn.NONE,value:15e-6,offset:0},{name:"minim",base:nn.VOLUME,prefixes:tn.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:nn.VOLUME,prefixes:tn.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:nn.VOLUME,prefixes:tn.NONE,value:2957353e-11,offset:0},{name:"gill",base:nn.VOLUME,prefixes:tn.NONE,value:.0001182941,offset:0},{name:"cup",base:nn.VOLUME,prefixes:tn.NONE,value:.0002365882,offset:0},{name:"pint",base:nn.VOLUME,prefixes:tn.NONE,value:.0004731765,offset:0},{name:"quart",base:nn.VOLUME,prefixes:tn.NONE,value:.0009463529,offset:0},{name:"gallon",base:nn.VOLUME,prefixes:tn.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:nn.VOLUME,prefixes:tn.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:nn.VOLUME,prefixes:tn.NONE,value:.1589873,offset:0},{name:"hogshead",base:nn.VOLUME,prefixes:tn.NONE,value:.238481,offset:0},{name:"fldr",base:nn.VOLUME,prefixes:tn.NONE,value:36966911e-13,offset:0},{name:"floz",base:nn.VOLUME,prefixes:tn.NONE,value:2957353e-11,offset:0},{name:"gi",base:nn.VOLUME,prefixes:tn.NONE,value:.0001182941,offset:0},{name:"cp",base:nn.VOLUME,prefixes:tn.NONE,value:.0002365882,offset:0},{name:"pt",base:nn.VOLUME,prefixes:tn.NONE,value:.0004731765,offset:0},{name:"qt",base:nn.VOLUME,prefixes:tn.NONE,value:.0009463529,offset:0},{name:"gal",base:nn.VOLUME,prefixes:tn.NONE,value:.003785412,offset:0},{name:"bbl",base:nn.VOLUME,prefixes:tn.NONE,value:.1173478,offset:0},{name:"obl",base:nn.VOLUME,prefixes:tn.NONE,value:.1589873,offset:0},{name:"g",base:nn.MASS,prefixes:tn.SHORT,value:.001,offset:0},{name:"gram",base:nn.MASS,prefixes:tn.LONG,value:.001,offset:0},{name:"ton",base:nn.MASS,prefixes:tn.SHORT,value:907.18474,offset:0},{name:"tonne",base:nn.MASS,prefixes:tn.SHORT,value:1e3,offset:0},{name:"grain",base:nn.MASS,prefixes:tn.NONE,value:6479891e-11,offset:0},{name:"dram",base:nn.MASS,prefixes:tn.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:nn.MASS,prefixes:tn.NONE,value:.028349523125,offset:0},{name:"poundmass",base:nn.MASS,prefixes:tn.NONE,value:.45359237,offset:0},{name:"hundredweight",base:nn.MASS,prefixes:tn.NONE,value:45.359237,offset:0},{name:"stick",base:nn.MASS,prefixes:tn.NONE,value:.115,offset:0},{name:"gr",base:nn.MASS,prefixes:tn.NONE,value:6479891e-11,offset:0},{name:"dr",base:nn.MASS,prefixes:tn.NONE,value:.0017718451953125,offset:0},{name:"oz",base:nn.MASS,prefixes:tn.NONE,value:.028349523125,offset:0},{name:"lbm",base:nn.MASS,prefixes:tn.NONE,value:.45359237,offset:0},{name:"cwt",base:nn.MASS,prefixes:tn.NONE,value:45.359237,offset:0},{name:"s",base:nn.TIME,prefixes:tn.SHORT,value:1,offset:0},{name:"min",base:nn.TIME,prefixes:tn.NONE,value:60,offset:0},{name:"h",base:nn.TIME,prefixes:tn.NONE,value:3600,offset:0},{name:"seconds",base:nn.TIME,prefixes:tn.LONG,value:1,offset:0},{name:"second",base:nn.TIME,prefixes:tn.LONG,value:1,offset:0},{name:"sec",base:nn.TIME,prefixes:tn.LONG,value:1,offset:0},{name:"minutes",base:nn.TIME,prefixes:tn.NONE,value:60,offset:0},{name:"minute",base:nn.TIME,prefixes:tn.NONE,value:60,offset:0},{name:"hours",base:nn.TIME,prefixes:tn.NONE,value:3600,offset:0},{name:"hour",base:nn.TIME,prefixes:tn.NONE,value:3600,offset:0},{name:"day",base:nn.TIME,prefixes:tn.NONE,value:86400,offset:0},{name:"days",base:nn.TIME,prefixes:tn.NONE,value:86400,offset:0},{name:"rad",base:nn.ANGLE,prefixes:tn.NONE,value:1,offset:0},{name:"deg",base:nn.ANGLE,prefixes:tn.NONE,value:.017453292519943295,offset:0},{name:"grad",base:nn.ANGLE,prefixes:tn.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:nn.ANGLE,prefixes:tn.NONE,value:6.283185307179586,offset:0},{name:"A",base:nn.CURRENT,prefixes:tn.SHORT,value:1,offset:0},{name:"ampere",base:nn.CURRENT,prefixes:tn.LONG,value:1,offset:0},{name:"K",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1,offset:0},{name:"degC",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1,offset:273.15},{name:"degF",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1/1.8,offset:459.67},{name:"degR",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1/1.8,offset:0},{name:"kelvin",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1,offset:0},{name:"celsius",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1,offset:273.15},{name:"fahrenheit",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:nn.TEMPERATURE,prefixes:tn.NONE,value:1/1.8,offset:0},{name:"mol",base:nn.AMOUNT_OF_SUBSTANCE,prefixes:tn.NONE,value:1,offset:0},{name:"mole",base:nn.AMOUNT_OF_SUBSTANCE,prefixes:tn.NONE,value:1,offset:0},{name:"cd",base:nn.LUMINOUS_INTENSITY,prefixes:tn.NONE,value:1,offset:0},{name:"candela",base:nn.LUMINOUS_INTENSITY,prefixes:tn.NONE,value:1,offset:0},{name:"N",base:nn.FORCE,prefixes:tn.SHORT,value:1,offset:0},{name:"newton",base:nn.FORCE,prefixes:tn.LONG,value:1,offset:0},{name:"lbf",base:nn.FORCE,prefixes:tn.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:nn.FORCE,prefixes:tn.NONE,value:4.4482216152605,offset:0},{name:"b",base:nn.BIT,prefixes:tn.BINARY_SHORT,value:1,offset:0},{name:"bits",base:nn.BIT,prefixes:tn.BINARY_LONG,value:1,offset:0},{name:"B",base:nn.BIT,prefixes:tn.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:nn.BIT,prefixes:tn.BINARY_LONG,value:8,offset:0}],$.E=Math.E,$.LN2=Math.LN2,$.LN10=Math.LN10,$.LOG2E=Math.LOG2E,$.LOG10E=Math.LOG10E,$.PI=Math.PI,$.SQRT1_2=Math.SQRT1_2,$.SQRT2=Math.SQRT2,$.I=new n(0,1),$.pi=$.PI,$.e=$.E,$.i=$.I,$.expr.node.Node=O,O.prototype.eval=function(){throw new Error("Cannot evaluate a Node interface")
|
|
},O.prototype.find=function(e){return this.match(e)?[this]:[]},O.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},O.prototype.toString=function(){return""},b.prototype=new O,$.expr.node.ConstantNode=b,b.prototype.eval=function(){return this.value},b.prototype.toString=function(){return $.format(this.value||null)},M.prototype=new O,$.expr.node.OperatorNode=M,M.prototype.eval=function(){return this.fn.apply(this,this.params.map(function(e){return e.eval()}))},M.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);var t=this.params;if(t)for(var r=0,i=t.length;i>r;r++)n=n.concat(t[r].find(e));return n},M.prototype.toString=function(){var e=this.params;if(this.fn===$.unaryminus)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 M&&(n="("+n+")");var t=e[1].toString();return e[1]instanceof M&&(t="("+t+")"),n+" "+this.name+" "+t;default:return this.name+"("+this.params.join(", ")+")"}},A.prototype=new O,$.expr.node.SymbolNode=A,A.prototype.eval=function(){var e=this.scope.get(this.name);if(void 0===e)throw new Error("Undefined symbol "+this.name);return e},A.prototype.toString=function(){return this.name},S.prototype=new O,$.expr.node.ParamsNode=S,S.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 i,a=this.paramScopes;if(i=r.size?r.size():void 0!==r.length?[r.length]:[],a&&i)for(e=0,n=this.params.length;n>e;e++){var o=a[e];o&&o.set("end",i[e])}}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):$.subset(r,f)},S.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,i=t.length;i>r;r++)n=n.concat(t[r].find(e));return n},S.prototype.toString=function(){var e=this.object?this.object.toString():"";return this.params&&(e+="("+this.params.join(", ")+")"),e},T.prototype=new O,$.expr.node.MatrixNode=T,function(){function e(e){for(var n=[],r=e.length,i=0;r>i;i++){for(var a=e[i],o=a.length,s=null,f=null,u=0;o>u;u++){var c,l=$.clone(a[u]);if(l instanceof t){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 g?(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 h=0;f>h;h++)s[h]=s[h].concat(l[h])}}n=n.concat(s)}return n}T.prototype.eval=function(){for(var n=this.nodes,r=[],i=!1,a=0,o=n.length;o>a;a++){for(var s=n[a],f=[],u=0,c=s.length;c>u;u++){var l=s[u].eval();(l instanceof t||l instanceof g||l instanceof Array)&&(i=!0),f[u]=l}r[a]=f}return i&&(r=e(r)),new t(r)},T.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);for(var t=this.nodes,r=0,i=t.length;i>r;r++)for(var a=t[r],o=0,s=a.length;s>o;o++)n=n.concat(a[o].find(e));return n},T.prototype.toString=function(){return en.formatArray(this.nodes)}}(),U.prototype=new O,$.expr.node.BlockNode=U,U.prototype.add=function(e,n){var t=this.params.length;this.params[t]=e,this.visible[t]=void 0!=n?n:!0},U.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},U.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);var t=this.params;if(t)for(var r=0,i=t.length;i>r;r++)n=n.concat(t[r].find(e));return n},U.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 O,$.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()},z.prototype=new O,$.expr.node.UpdateNode=z,z.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 i=0,a=this.params.length;a>i;i++){var o=r[i];o&&o.set("end",t[i])}}var s=[];this.params.forEach(function(e){s.push(e.eval())});var f=this.expr.eval();return e=$.subset(n,s,f),this.scope.set(this.name,e),e},z.prototype.find=function(e){var n=[];this.match(e)&&n.push(this);var t=this.params;if(t)for(var r=0,i=t.length;i>r;r++)n=n.concat(t[r].find(e));return this.expr&&(n=n.concat(this.expr.find(e))),n},z.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=this.expr.toString()},L.prototype=new O,$.expr.node.FunctionNode=L,L.prototype.eval=function(){return this.scope.set(this.name,this.fn),this.fn},L.prototype.find=function(e){var n=[];return this.match(e)&&n.push(this),this.expr&&(n=n.concat(this.expr.find(e))),n},L.prototype.toString=function(){return this.fn.toString()},$.expr.Scope=function(){if(this.parentScope=null,this.subScopes=null,this.symbols={},this.cache={},arguments.length>0){var e=arguments[0];e instanceof $.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)}},$.expr.Scope.prototype={createSubScope:function(){var e=new $.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=$[e],void 0!==n?(this.cache[e]=$,n):y.isPlainUnit(e)?(n=new y(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,i=t.length;i>r;r++)t[r].clear();this.clearCache()},clearCache:function(){this.cache={}}},$.expr.Parser=function(){if(!(this instanceof $.expr.Parser))throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new $.expr.Scope},$.expr.Parser.prototype.parse=function(e){return $.parse(e,this.scope)},$.expr.Parser.prototype.eval=function(e){var n=$.parse(e,this.scope);return n.eval()},$.expr.Parser.prototype.get=function(e){return this.scope.get(e)},$.expr.Parser.prototype.set=function(e,n){this.scope.set(e,n)},$.expr.Parser.prototype.remove=function(e){this.scope.remove(e)},$.expr.Parser.prototype.clear=function(){this.scope.clear()},$.expr.Expression=function(e){this.id=e.id,this.scope=e.scope,this.nextNode=e.nextNode,this.previousNode=e.previousNode,this.updateSeq=0,this.node=void 0,this.symbols={},this.assignments={},this.updates={},this.result=void 0,this.setExpr(e.expression)},$.expr.Expression.prototype.setExpr=function(e){this.expression=e||"",this.scope.clear(),this._parse(),this._analyse()},$.expr.Expression.prototype.getExpr=function(){return this.expression},$.expr.Expression.prototype.getResult=function(){return this.result},$.expr.Expression.prototype._parse=function(){try{this.node=$.parse(this.expression,this.scope)}catch(e){var n="Error: "+String(e.message||e);this.node=new b(n)}},$.expr.Expression.prototype._analyse=function(){var e,n,t;if(this.node){var r=this.node.find({type:$.expr.node.SymbolNode});for(this.symbols={},e=0,n=r.length;n>e;e++)t=r[e],this.symbols[t.name]=t;var i=this.node.find({type:$.expr.node.AssignmentNode});for(this.assignments={},e=0,n=i.length;n>e;e++)t=i[e],this.assignments[t.name]=t;var a=this.node.find({type:$.expr.node.UpdateNode});for(this.updates={},e=0,n=a.length;n>e;e++)t=a[e],this.updates[t.name]=t}},$.expr.Expression.prototype.eval=function(){try{this.scope.clear(),this.result=this.node.eval()}catch(e){this.scope.clear(),this.result="Error: "+String(e.message||e)}return this.result},$.expr.Workspace=_,_.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},_.prototype.append=function(e){var n=this._getNewId(),t=this.lastNode?this.lastNode.scope:this.scope,r=new $.expr.Scope(t),i=new $.expr.Expression({id:n,expression:e,scope:r,nextNode:void 0,previousNode:this.lastNode});return this.nodes[n]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([n]),n},_.prototype.insertBefore=function(e,n){var t=this.nodes[n];if(!t)throw new RangeError('Node with id "'+n+'" not found');var r=t.previousNode,i=this._getNewId(),a=r?r.scope:this.scope,o=new $.expr.Scope(a),s=new $.expr.Expression({id:i,expression:e,scope:o,nextNode:t,previousNode:r});this.nodes[i]=s,r?r.nextNode=s:this.firstNode=s,t.previousNode=s,t.scope.parentScope=s.scope;var f=this.getDependencies(i);return-1==f.indexOf(i)&&f.unshift(i),this._update(f),i},_.prototype.insertAfter=function(e,n){var t=this.nodes[n];if(!t)throw new RangeError('Node with id "'+n+'" not found');var r=t.nextNode;return r?this.insertBefore(e,r.id):this.append(e)},_.prototype.remove=function(e){var n=this.nodes[e];if(!n)throw new RangeError('Node with id "'+e+'" not found');var t=this.getDependencies(e),r=n.previousNode,i=n.nextNode;r?r.nextNode=i:this.firstNode=i,i?i.previousNode=r:this.lastNode=r;var a=r?r.scope:this.scope;i&&(i.scope.parentScope=a),delete this.nodes[e],this._update(t)},_.prototype.replace=function(e,n){var t=this.nodes[n];if(!t)throw new RangeError('Node with id "'+n+'" not found');var r=[n];_._merge(r,this.getDependencies(n)),t.setExpr(e),_._merge(r,this.getDependencies(n)),this._update(r)},_._merge=function(e,n){for(var t=0,r=n.length;r>t;t++){var i=n[t];-1==e.indexOf(i)&&e.push(i)}},_.prototype.getDependencies=function(e){var n,t=this.nodes[e],r=[],i={};if(!t)throw new RangeError('Node with id "'+e+'" not found');var a=function(e,n){var t,r=e.assignments,a=e.updates;for(t in r)r.hasOwnProperty(t)&&(i[t]=n);for(t in a)a.hasOwnProperty(t)&&(i[t]=n)};for(a(t,!0),t=t.nextNode;t;){var o=t.symbols,s=!1;for(n in o)if(o.hasOwnProperty(n)&&1==i[n]){s=!0;break}s?(a(t,!0),r.push(t.id)):a(t,!1),t=t.nextNode}return r},_.prototype.getExpr=function(e){var n=this.nodes[e];if(!n)throw new RangeError('Node with id "'+e+'" not found');return n.getExpr()},_.prototype.getResult=function(e){var n=this.nodes[e];if(!n)throw new RangeError('Node with id "'+e+'" not found');return n.getResult()},_.prototype._update=function(e){this.updateSeq++;for(var n=this.updateSeq,t=this.nodes,r=0,i=e.length;i>r;r++){var a=e[r],o=t[a];o&&(o.eval(),o.updateSeq=n)}},_.prototype.getChanges=function(e){var n=[],t=this.firstNode;for(e=e||0;t;)t.updateSeq>e&&n.push(t.id),t=t.nextNode;return{ids:n,updateSeq:this.updateSeq}},_.prototype._getNewId=function(){return this.idMax++,this.idMax},_.prototype.toString=function(){return JSON.stringify(this.toJSON())},_.prototype.toJSON=function(){for(var e=[],n=this.firstNode;n;){var t={id:n.id,expression:n.expression,dependencies:this.getDependencies(n.id)};try{t.result=n.getResult()}catch(r){t.result="Error: "+String(r.message||r)}e.push(t),n=n.nextNode}return e},$.abs=function(e){if(1!=arguments.length)throw N("abs",arguments.length,1);if(m(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 t)return en.map(e,$.abs);if(e.valueOf()!==e)return $.abs(e.valueOf());throw x("abs",e)},$.add=function(e,r){if(2!=arguments.length)throw N("add",arguments.length,2);if(m(e)){if(m(r))return e+r;if(r instanceof n)return new n(e+r.re,r.im)}else if(e instanceof n){if(m(r))return new n(e.re+r,e.im);if(r instanceof n)return new n(e.re+r.re,e.im+r.im)}else if(e instanceof y&&r instanceof y){if(!e.equalBase(r))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==r.value)throw new Error("Unit on right hand side of operator + has an undefined value");var i=e.clone();return i.value+=r.value,i.fixPrefix=!1,i}if(d(e)||d(r))return e+r;if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.add);if(e.valueOf()!==e||r.valueOf()!==r)return $.add(e.valueOf(),r.valueOf());throw x("add",e,r)},$.ceil=function(e){if(1!=arguments.length)throw N("ceil",arguments.length,1);if(m(e))return Math.ceil(e);if(e instanceof n)return new n(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof t)return en.map(e,$.ceil);if(e.valueOf()!==e)return $.ceil(e.valueOf());throw x("ceil",e)},$.cube=function(e){if(1!=arguments.length)throw N("cube",arguments.length,1);if(m(e))return e*e*e;if(e instanceof n)return $.multiply($.multiply(e,e),e);if(e instanceof Array||e instanceof t)return en.map(e,$.cube);if(e.valueOf()!==e)return $.cube(e.valueOf());throw x("cube",e)},$.divide=function(e,r){if(2!=arguments.length)throw N("divide",arguments.length,2);if(m(e)){if(m(r))return e/r;if(r instanceof n)return q(new n(e,0),r)}if(e instanceof n){if(m(r))return q(e,new n(r,0));if(r instanceof n)return q(e,r)}if(e instanceof y&&m(r)){var i=e.clone();return i.value/=r,i}if(e instanceof Array||e instanceof t)return r instanceof Array||r instanceof t?$.multiply(e,$.inv(r)):en.map2(e,r,$.divide);if(r instanceof Array||r instanceof t)return $.multiply(e,$.inv(r));if(e.valueOf()!==e||r.valueOf()!==r)return $.divide(e.valueOf(),r.valueOf());throw x("divide",e,r)},$.equal=function an(e,r){if(2!=arguments.length)throw N("equal",arguments.length,2);if(m(e)){if(m(r))return e==r;if(r instanceof n)return e==r.re&&0==r.im}if(e instanceof n){if(m(r))return e.re==r&&0==e.im;if(r instanceof n)return e.re==r.re&&e.im==r.im}if(e instanceof y&&r instanceof y){if(!e.equalBase(r))throw new Error("Cannot compare units with different base");return e.value==r.value}if(d(e)||d(r))return e==r;if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.equal);if(e.valueOf()!==e||r.valueOf()!==r)return an(e.valueOf(),r.valueOf());throw x("equal",e,r)},$.exp=function(e){if(1!=arguments.length)throw N("exp",arguments.length,1);if(m(e))return Math.exp(e);if(e instanceof n){var r=Math.exp(e.re);return new n(r*Math.cos(e.im),r*Math.sin(e.im))}if(e instanceof Array||e instanceof t)return en.map(e,$.exp);if(e.valueOf()!==e)return $.exp(e.valueOf());throw x("exp",e)},$.fix=function(e){if(1!=arguments.length)throw N("fix",arguments.length,1);if(m(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof n)return new n(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 t)return en.map(e,$.fix);if(e.valueOf()!==e)return $.fix(e.valueOf());throw x("fix",e)},$.floor=function(e){if(1!=arguments.length)throw N("floor",arguments.length,1);if(m(e))return Math.floor(e);if(e instanceof n)return new n(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof t)return en.map(e,$.floor);if(e.valueOf()!==e)return $.floor(e.valueOf());throw x("floor",e)},$.gcd=function(){var e,n=arguments[0],r=arguments[1];if(2==arguments.length){if(m(n)&&m(r)){if(!v(n)||!v(r))throw new Error("Parameters in function gcd must be integer numbers");for(;0!=r;)e=r,r=n%e,n=e;return Math.abs(n)}if(n instanceof Array||n instanceof t||r instanceof Array||r instanceof t)return en.map2(n,r,$.gcd);if(n.valueOf()!==n||r.valueOf()!==r)return $.gcd(n.valueOf(),r.valueOf());throw x("gcd",n,r)}if(arguments.length>2){for(var i=1;i<arguments.length;i++)n=$.gcd(n,arguments[i]);return n}throw new SyntaxError("Function gcd expects two or more arguments")},$.larger=function(e,r){if(2!=arguments.length)throw N("larger",arguments.length,2);if(m(e)){if(m(r))return e>r;if(r instanceof n)return e>$.abs(r)}if(e instanceof n){if(m(r))return $.abs(e)>r;if(r instanceof n)return $.abs(e)>$.abs(r)}if(e instanceof y&&r instanceof y){if(!e.equalBase(r))throw new Error("Cannot compare units with different base");return e.value>r.value}if(d(e)||d(r))return e>r;if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.larger);if(e.valueOf()!==e||r.valueOf()!==r)return $.larger(e.valueOf(),r.valueOf());throw x("larger",e,r)},$.largereq=function(e,r){if(2!=arguments.length)throw N("largereq",arguments.length,2);if(m(e)){if(m(r))return e>=r;if(r instanceof n)return e>=$.abs(r)}if(e instanceof n){if(m(r))return $.abs(e)>=r;if(r instanceof n)return $.abs(e)>=$.abs(r)}if(e instanceof y&&r instanceof y){if(!e.equalBase(r))throw new Error("Cannot compare units with different base");return e.value>=r.value}if(d(e)||d(r))return e>=r;if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.largereq);if(e.valueOf()!==e||r.valueOf()!==r)return $.largereq(e.valueOf(),r.valueOf());throw x("largereq",e,r)},$.lcm=function(){var e,n=arguments[0],r=arguments[1];if(2==arguments.length){if(m(n)&&m(r)){if(!v(n)||!v(r))throw new Error("Parameters in function lcm must be integer numbers");for(var i=n*r;0!=r;)e=r,r=n%e,n=e;return Math.abs(i/n)}if(n instanceof Array||n instanceof t||r instanceof Array||r instanceof t)return en.map2(n,r,$.lcm);if(n.valueOf()!==n||r.valueOf()!==r)return $.lcm(n.valueOf(),r.valueOf());throw x("lcm",n,r)}if(arguments.length>2){for(var a=1;a<arguments.length;a++)n=$.lcm(n,arguments[a]);return n}throw new SyntaxError("Function lcm expects two or more arguments")},$.log=function(e,r){if(1==arguments.length){if(m(e))return e>=0?Math.log(e):$.log(new n(e,0));if(e instanceof n)return new n(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof t)return en.map(e,$.log);if(e.valueOf()!==e)return $.log(e.valueOf());throw x("log",e)}if(2==arguments.length)return $.divide($.log(e),$.log(r));throw N("log",arguments.length,1,2)},$.log10=function(e){if(1!=arguments.length)throw N("log10",arguments.length,1);if(m(e))return e>=0?Math.log(e)/Math.LN10:$.log10(new n(e,0));if(e instanceof n)return new n(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 t)return en.map(e,$.log10);if(e.valueOf()!==e)return $.log10(e.valueOf());throw x("log10",e)},$.mod=function(e,n){if(2!=arguments.length)throw N("mod",arguments.length,2);if(m(e)&&m(n))return I(e,n);if(e instanceof Array||e instanceof t||n instanceof Array||n instanceof t)return en.map2(e,n,$.mod);if(e.valueOf()!==e||n.valueOf()!==n)return $.mod(e.valueOf(),n.valueOf());throw x("mod",e,n)},$.multiply=function on(e,r){if(2!=arguments.length)throw N("multiply",arguments.length,2);if(m(e)){if(m(r))return e*r;if(r instanceof n)return P(new n(e,0),r);if(r instanceof y)return o=r.clone(),o.value*=e,o}else if(e instanceof n){if(m(r))return P(e,new n(r,0));if(r instanceof n)return P(e,r)}else if(e instanceof y){if(m(r))return o=e.clone(),o.value*=r,o}else{if(e instanceof Array){if(r instanceof Array){var i=en.size(e),a=en.size(r);if(2!=i.length)throw new Error("Can only multiply a 2 dimensional matrix (A has "+i.length+" dimensions)");if(2!=a.length)throw new Error("Can only multiply a 2 dimensional matrix (B has "+a.length+" dimensions)");if(i[1]!=a[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+i[0]+"x"+i[1]+", B is "+a[0]+"x"+a[1]+", "+a[1]+" != "+a[0]+")");for(var o=[],s=i[0],f=a[1],u=i[1],on=$.multiply,c=$.add,l=0;s>l;l++){o[l]=[];for(var h=0;f>h;h++){for(var p=null,v=0;u>v;v++){var g=on(e[l][v],r[v][h]);p=null==p?g:c(p,g)}o[l][h]=p}}return o}return r instanceof t?new t($.multiply(e.valueOf(),r.valueOf())):en.map2(e,r,$.multiply)}if(e instanceof t)return new t($.multiply(e.valueOf(),r.valueOf()))}if(r instanceof Array)return en.map2(e,r,$.multiply);if(r instanceof t)return new t($.multiply(e.valueOf(),r.valueOf()));if(e.valueOf()!==e||r.valueOf()!==r)return $.multiply(e.valueOf(),r.valueOf());throw x("multiply",e,r)},$.pow=function(e,r){if(2!=arguments.length)throw N("pow",arguments.length,2);if(m(e)){if(m(r))return v(r)||e>=0?Math.pow(e,r):B(new n(e,0),new n(r,0));if(r instanceof n)return B(new n(e,0),r)}else if(e instanceof n){if(m(r))return B(e,new n(r,0));if(r instanceof n)return B(e,r)}else{if(e instanceof Array){if(!m(r)||!v(r)||0>r)throw new TypeError("For A^b, b must be a positive integer (value is "+r+")");var i=en.size(e);if(2!=i.length)throw new Error("For A^b, A must be 2 dimensional (A has "+i.length+" dimensions)");if(i[0]!=i[1])throw new Error("For A^b, A must be square (size is "+i[0]+"x"+i[1]+")");if(0==r)return $.eye(i[0]);for(var a=e,o=1;r>o;o++)a=$.multiply(e,a);return a}if(e instanceof t)return new t($.pow(e.valueOf(),r))}if(e.valueOf()!==e||r.valueOf()!==r)return $.pow(e.valueOf(),r.valueOf());throw x("pow",e,r)},$.round=function(e,r){if(1!=arguments.length&&2!=arguments.length)throw N("round",arguments.length,1,2);if(void 0==r){if(m(e))return Math.round(e);if(e instanceof n)return new n(Math.round(e.re),Math.round(e.im));if(e instanceof Array||e instanceof t)return en.map(e,$.round);if(e.valueOf()!==e)return $.round(e.valueOf());throw x("round",e)}if(!m(r))throw new TypeError("Number of decimals in function round must be an integer");if(r!==Math.round(r))throw new TypeError("Number of decimals in function round must be integer");if(0>r||r>9)throw new Error("Number of decimals in function round must be in te range of 0-9");if(m(e))return C(e,r);if(e instanceof n)return new n(C(e.re,r),C(e.im,r));if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.round);if(e.valueOf()!==e||r.valueOf()!==r)return $.round(e.valueOf(),r.valueOf());throw x("round",e,r)},$.sign=function sn(e){if(1!=arguments.length)throw N("sign",arguments.length,1);if(m(e)){var sn;return sn=e>0?1:0>e?-1:0}if(e instanceof n){var r=Math.sqrt(e.re*e.re+e.im*e.im);return new n(e.re/r,e.im/r)}if(e instanceof Array||e instanceof t)return en.map(e,$.sign);if(e.valueOf()!==e)return $.sign(e.valueOf());throw x("sign",e)},$.smaller=function(e,r){if(2!=arguments.length)throw N("smaller",arguments.length,2);if(m(e)){if(m(r))return r>e;if(r instanceof n)return e<$.abs(r)}if(e instanceof n){if(m(r))return $.abs(e)<r;if(r instanceof n)return $.abs(e)<$.abs(r)}if(e instanceof y&&r instanceof y){if(!e.equalBase(r))throw new Error("Cannot compare units with different base");return e.value<r.value}if(d(e)||d(r))return r>e;if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.smaller);if(e.valueOf()!==e||r.valueOf()!==r)return $.smaller(e.valueOf(),r.valueOf());throw x("smaller",e,r)},$.smallereq=function(e,r){if(2!=arguments.length)throw N("smallereq",arguments.length,2);if(m(e)){if(m(r))return r>=e;if(r instanceof n)return e<=$.abs(r)}if(e instanceof n){if(m(r))return $.abs(e)<=r;if(r instanceof n)return $.abs(e)<=$.abs(r)}if(e instanceof y&&r instanceof y){if(!e.equalBase(r))throw new Error("Cannot compare units with different base");return e.value<=r.value}if(d(e)||d(r))return r>=e;if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.smallereq);if(e.valueOf()!==e||r.valueOf()!==r)return $.smallereq(e.valueOf(),r.valueOf());throw x("smallereq",e,r)},$.sqrt=function(e){if(1!=arguments.length)throw N("sqrt",arguments.length,1);if(m(e))return e>=0?Math.sqrt(e):$.sqrt(new n(e,0));if(e instanceof n){var r=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new n(.5*Math.sqrt(2*(r+e.re)),.5*Math.sqrt(2*(r-e.re))):new n(.5*Math.sqrt(2*(r+e.re)),-.5*Math.sqrt(2*(r-e.re)))}if(e instanceof Array||e instanceof t)return en.map(e,$.sqrt);if(e.valueOf()!==e)return $.sqrt(e.valueOf());throw x("sqrt",e)},$.square=function(e){if(1!=arguments.length)throw N("square",arguments.length,1);if(m(e))return e*e;if(e instanceof n)return $.multiply(e,e);if(e instanceof Array||e instanceof t)return en.map(e,$.square);if(e.valueOf()!==e)return $.square(e.valueOf());throw x("square",e)},$.subtract=function(e,r){if(2!=arguments.length)throw N("subtract",arguments.length,2);if(m(e)){if(m(r))return e-r;if(r instanceof n)return new n(e-r.re,-r.im)}else if(e instanceof n){if(m(r))return new n(e.re-r,e.im);if(r instanceof n)return new n(e.re-r.re,e.im-r.im)}else if(e instanceof y&&r instanceof y){if(!e.equalBase(r))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==r.value)throw new Error("Unit on right hand side of operator - has an undefined value");var i=e.clone();return i.value-=r.value,i.fixPrefix=!1,i}if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.subtract);if(e.valueOf()!==e||r.valueOf()!==r)return $.subtract(e.valueOf(),r.valueOf());throw x("subtract",e,r)},$.unaryminus=function(e){if(1!=arguments.length)throw N("unaryminus",arguments.length,1);if(m(e))return-e;if(e instanceof n)return new n(-e.re,-e.im);if(e instanceof y){var r=e.clone();return r.value=-e.value,r}if(e instanceof Array||e instanceof t)return en.map(e,$.unaryminus);if(e.valueOf()!==e)return $.unaryminus(e.valueOf());throw x("unaryminus",e)},$.unequal=function(e,r){if(2!=arguments.length)throw N("unequal",arguments.length,2);if(m(e)){if(m(r))return e!=r;if(r instanceof n)return e!=r.re||0!=r.im}if(e instanceof n){if(m(r))return e.re!=r||0!=e.im;if(r instanceof n)return e.re!=r.re||e.im!=r.im}if(e instanceof y&&r instanceof y){if(!e.equalBase(r))throw new Error("Cannot compare units with different base");return e.value!=r.value}if(d(e)||d(r))return e!=r;if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.unequal);if(e.valueOf()!==e||r.valueOf()!==r)return $.unequal(e.valueOf(),r.valueOf());throw x("unequal",e,r)},$.xgcd=function fn(e,n){if(2==arguments.length){if(m(e)&&m(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=fn(n,e%n),r=t[0],i=t[1],a=t[2];return[r,a,i-a*Math.floor(e/n)]}throw x("xgcd",e,n)}throw new SyntaxError("Function xgcd expects two arguments")},$.arg=function(e){if(1!=arguments.length)throw N("arg",arguments.length,1);return m(e)?Math.atan2(0,e):e instanceof n?Math.atan2(e.im,e.re):e instanceof Array||e instanceof t?en.map(e,$.arg):e.valueOf()!==e?$.arg(e.valueOf()):$.atan2(0,e)},$.conj=function(e){if(1!=arguments.length)throw N("conj",arguments.length,1);return m(e)?e:e instanceof n?new n(e.re,-e.im):e instanceof Array||e instanceof t?en.map(e,$.conj):e.valueOf()!==e?$.conj(e.valueOf()):clone(e)},$.im=function(e){if(1!=arguments.length)throw N("im",arguments.length,1);return m(e)?0:e instanceof n?e.im:e instanceof Array||e instanceof t?en.map(e,$.im):e.valueOf()!==e?$.im(e.valueOf()):0},$.re=function(e){if(1!=arguments.length)throw N("re",arguments.length,1);return m(e)?e:e instanceof n?e.re:e instanceof Array||e instanceof t?en.map(e,$.re):e.valueOf()!==e?$.re(e.valueOf()):$.clone(e)},$.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(d(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 N("complex",arguments.length,0,2)}},$.matrix=function(e){if(arguments.length>1)throw N("matrix",arguments.length,0,1);return new t(e)},$.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 N("number",arguments.length,0,1)}},$.parser=function(){return new $.expr.Parser},$.range=function(e){switch(arguments.length){case 1:if(e instanceof g)return e.clone();if(d(e)){var n=g.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 g(arguments[0],null,arguments[1]);case 3:return new g(arguments[0],arguments[1],arguments[2]);default:throw N("range",arguments.length,2,3)}},$.unit=function(){switch(arguments.length){case 1:var e=arguments[0];if(e instanceof y)return e.clone();if(d(e)){if(y.isPlainUnit(e))return new y(null,e);var n=y.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 y(arguments[0],arguments[1]);default:throw N("unit",arguments.length,1,2)}},$.workspace=function(){return new $.expr.Workspace},$.concat=function(){var e,n,r=arguments.length,i=-1,a=!1,o=[];for(e=0;r>e;e++){var s=arguments[e];if(s instanceof t&&(a=!0),e==r-1&&m(s)){if(n=i,i=s,!v(i)||1>i)throw new TypeError("Dimension number must be a positive integer (dim = "+i+")");if(e>0&&i>n)throw new RangeError("Dimension out of range ("+i+" > "+n+")")}else{if(!(s instanceof Array||s instanceof t))throw x("concat",s);var f=$.clone(s.valueOf()),u=$.size(s);if(o[e]=f,n=i,i=u.length,e>0&&i!=n)throw new RangeError("Dimension mismatch ("+n+" != "+i+")")}}if(0==o.length)throw new SyntaxError("At least one matrix expected");for(var c=o.shift();o.length;)c=G(c,o.shift(),i-1,0);return a?new t(c):c},$.det=function(e){if(1!=arguments.length)throw N("det",arguments.length,1);var n=$.size(e);switch(n.length){case 0:return $.clone(e);case 1:if(1==n[0])return $.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+$.format(n)+")");case 2:var t=n[0],r=n[1];if(t==r)return F(e.valueOf(),t,r);throw new RangeError("Matrix must be square (size: "+$.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+$.format(n)+")")}},$.diag=function(e,n){var r,i,a,o;if(1!=arguments.length&&2!=arguments.length)throw N("diag",arguments.length,1,2);if(n){if(!m(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 t||e instanceof g||(e=new t(e));var u;switch(e.isVector()?(e=e.toVector(),u=[e.length]):u=e.size(),u.length){case 1:i=e.valueOf();var c=new t;for(c.resize([i.length+f,i.length+s]),r=c.valueOf(),o=i.length,a=0;o>a;a++)r[a+f][a+s]=$.clone(i[a]);return c;case 2:for(i=[],r=e.valueOf(),o=Math.min(u[0]-f,u[1]-s),a=0;o>a;a++)i[a]=$.clone(r[a+f][a+s]);return new t(i);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}},$.eye=function(){var e=en.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw N("eye",e.length,0,2);var n=e[0],r=e[1];if(!m(n)||!v(n)||1>n)throw new Error("Parameters in function eye must be positive integers");if(r&&(!m(r)||!v(r)||1>r))throw new Error("Parameters in function eye must be positive integers");var i=new t;i.resize(e);for(var a=$.min(e),o=i.valueOf(),s=0;a>s;s++)o[s][s]=1;return i},$.inv=function(e){if(1!=arguments.length)throw N("inv",arguments.length,1);var n=$.size(e);switch(n.length){case 0:return $.divide(1,e);case 1:if(1==n[0])return e instanceof t?new t([$.divide(1,e.valueOf()[0])]):[$.divide(1,e[0])];throw new RangeError("Matrix must be square (size: "+$.format(n)+")");case 2:var r=n[0],i=n[1];if(r==i)return e instanceof t?new t(V(e.valueOf(),r,i)):V(e,r,i);throw new RangeError("Matrix must be square (size: "+$.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+$.format(n)+")")
|
|
}},$.ones=function(){var e=en.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new t,r=1;return n.resize(e,r),n},$.size=function(e){if(1!=arguments.length)throw N("size",arguments.length,1);if(m(e)||e instanceof n||e instanceof y||null==e)return[];if(d(e))return[e.length];if(e instanceof Array)return en.size(e);if(e instanceof t)return e.size();if(e.valueOf()!==e)return $.size(e.valueOf());throw x("size",e)},$.squeeze=function(e){if(1!=arguments.length)throw N("squeeze",arguments.length,1);return e instanceof Array?j($.clone(e)):e instanceof t?j(e.toArray()):e.valueOf()instanceof Array?j($.clone(e.valueOf())):$.clone(e)},$.subset=function(){switch(arguments.length){case 2:return D(arguments[0],arguments[1]);case 3:return k(arguments[0],arguments[1],arguments[2]);default:throw N("subset",arguments.length,2,3)}},$.transpose=function(e){if(1!=arguments.length)throw N("transpose",arguments.length,1);var n=$.size(e);switch(n.length){case 0:return $.clone(e);case 1:return $.clone(e);case 2:for(var r,i=n[1],a=n[0],o=e instanceof t,s=e.valueOf(),f=[],u=$.clone,c=0;i>c;c++){r=f[c]=[];for(var l=0;a>l;l++)r[l]=u(s[l][c])}return 0==a&&(f[0]=[]),o?new t(f):f;default:throw new RangeError("Matrix must be two dimensional (size: "+$.format(n)+")")}},$.zeros=function(){var e=en.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new t;return n.resize(e),n},$.factorial=function(e){if(1!=arguments.length)throw N("factorial",arguments.length,1);if(m(e)){if(!v(e)||0>e)throw new TypeError("Positive integer value expected in function factorial");var n=e,r=n;for(n--;n>1;)r*=n,n--;return 0==r&&(r=1),r}if(e instanceof Array||e instanceof t)return en.map(e,$.factorial);if(e.valueOf()!==e)return $.factorial(e.valueOf());throw x("factorial",e)},$.random=function(){if(0!=arguments.length)throw N("random",arguments.length,0);return Math.random()},$.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 t||e instanceof g){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=$.size(e);if(1==n.length){if(0==e.length)throw new Error("Cannot calculate max of an empty vector");return W(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 t||e instanceof g)return new t(K(e.valueOf(),n[0],n[1]));throw x("max",e)}throw new RangeError("Cannot calculate max for multi dimensional matrix")}return W(arguments)},$.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 t||e instanceof g){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=$.size(e);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 t||e instanceof g)return new t(X(e.valueOf(),n[0],n[1]));throw x("min",e)}throw new RangeError("Cannot calculate min for multi dimensional matrix")}return Z(arguments)},$.acos=function(e){if(1!=arguments.length)throw N("acos",arguments.length,1);if(m(e))return e>=-1&&1>=e?Math.acos(e):$.acos(new n(e,0));if(e instanceof n){var r=new n(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),i=$.sqrt(r),a=new n(i.re-e.im,i.im+e.re),o=$.log(a);return new n(1.5707963267948966-o.im,o.re)}if(e instanceof Array||e instanceof t)return en.map(e,$.acos);if(e.valueOf()!==e)return $.acos(e.valueOf());throw x("acos",e)},$.asin=function(e){if(1!=arguments.length)throw N("asin",arguments.length,1);if(m(e))return e>=-1&&1>=e?Math.asin(e):$.asin(new n(e,0));if(e instanceof n){var r=e.re,i=e.im,a=new n(i*i-r*r+1,-2*r*i),o=$.sqrt(a),s=new n(o.re-i,o.im+r),f=$.log(s);return new n(f.im,-f.re)}if(e instanceof Array||e instanceof t)return en.map(e,$.asin);if(e.valueOf()!==e)return $.asin(e.valueOf());throw x("asin",e)},$.atan=function(e){if(1!=arguments.length)throw N("atan",arguments.length,1);if(m(e))return Math.atan(e);if(e instanceof n){var r=e.re,i=e.im,a=r*r+(1-i)*(1-i),o=new n((1-i*i-r*r)/a,-2*r/a),s=$.log(o);return new n(-.5*s.im,.5*s.re)}if(e instanceof Array||e instanceof t)return en.map(e,$.atan);if(e.valueOf()!==e)return $.atan(e.valueOf());throw x("atan",e)},$.atan2=function(e,r){if(2!=arguments.length)throw N("atan2",arguments.length,2);if(m(e)){if(m(r))return Math.atan2(e,r)}else if(e instanceof n&&m(r))return Math.atan2(e.re,r);if(e instanceof Array||e instanceof t||r instanceof Array||r instanceof t)return en.map2(e,r,$.atan2);if(r.valueOf()!==r||e.valueOf()!==e)return $.atan2(e.valueOf(),r.valueOf());throw x("atan2",e,r)},$.cos=function(e){if(1!=arguments.length)throw N("cos",arguments.length,1);if(m(e))return Math.cos(e);if(e instanceof n)return new n(.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 y){if(!e.hasBase(y.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(e.value)}if(e instanceof Array||e instanceof t)return en.map(e,$.cos);if(e.valueOf()!==e)return $.cos(e.valueOf());throw x("cos",e)},$.cot=function(e){if(1!=arguments.length)throw N("cot",arguments.length,1);if(m(e))return 1/Math.tan(e);if(e instanceof n){var r=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new n(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(Math.exp(-4*e.im)-1)/r)}if(e instanceof y){if(!e.hasBase(y.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 t)return en.map(e,$.cot);if(e.valueOf()!==e)return $.cot(e.valueOf());throw x("cot",e)},$.csc=function(e){if(1!=arguments.length)throw N("csc",arguments.length,1);if(m(e))return 1/Math.sin(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return new n(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.cos(e.re)*(Math.exp(-e.im)-Math.exp(e.im))/r)}if(e instanceof y){if(!e.hasBase(y.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 t)return en.map(e,$.csc);if(e.valueOf()!==e)return $.csc(e.valueOf());throw x("csc",e)},$.sec=function(e){if(1!=arguments.length)throw N("sec",arguments.length,1);if(m(e))return 1/Math.cos(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return new n(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.sin(e.re)*(Math.exp(e.im)-Math.exp(-e.im))/r)}if(e instanceof y){if(!e.hasBase(y.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 t)return en.map(e,$.sec);if(e.valueOf()!==e)return $.sec(e.valueOf());throw x("sec",e)},$.sin=function(e){if(1!=arguments.length)throw N("sin",arguments.length,1);if(m(e))return Math.sin(e);if(e instanceof n)return new n(.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 y){if(!e.hasBase(y.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(e.value)}if(e instanceof Array||e instanceof t)return en.map(e,$.sin);if(e.valueOf()!==e)return $.sin(e.valueOf());throw x("sin",e)},$.tan=function(e){if(1!=arguments.length)throw N("tan",arguments.length,1);if(m(e))return Math.tan(e);if(e instanceof n){var r=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new n(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(1-Math.exp(-4*e.im))/r)}if(e instanceof y){if(!e.hasBase(y.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(e.value)}if(e instanceof Array||e instanceof t)return en.map(e,$.tan);if(e.valueOf()!==e)return $.tan(e.valueOf());throw x("tan",e)},$["in"]=function(e,n){if(2!=arguments.length)throw N("in",arguments.length,2);if(e instanceof y&&(n instanceof y||d(n)))return e["in"](n);if(e instanceof Array||e instanceof t||n instanceof Array||n instanceof t)return en.map2(e,n,$["in"]);if(e.valueOf()!==e||n.valueOf()!==n)return $["in"](e.valueOf(),n.valueOf());throw x("in",e,n)},$.clone=function(n){if(1!=arguments.length)throw N("clone",arguments.length,1);if(null==n)return n;if("function"==typeof n.clone)return n.clone();if(m(n)||d(n)||e(n))return n;if(n instanceof Array){var t=$.clone;return n.map(function(e){return t(e)})}if(n instanceof Object)return en.mapObject(n,$.clone);throw x("clone",n)},$.eval=function(e,n){if(1!=arguments.length&&2!=arguments.length)throw N("eval",arguments.length,1,2);var r;if(r=n?n instanceof $.expr.Scope?n:new $.expr.Scope(n):new $.expr.Scope,d(e)){var i=$.parse(e,r);return i.eval()}if(e instanceof Array||e instanceof t)return en.map(e,function(e){var n=$.parse(e,r);return n.eval()});throw new TypeError("String or matrix expected")},$.format=function(e,n){var t=arguments.length;if(1!=t&&2!=t)throw N("format",t,1,2);if(1==t){var r=arguments[0];return m(r)?en.formatNumber(r):r instanceof Array?en.formatArray(r):d(r)?'"'+r+'"':r instanceof Object?r.toString():String(r)}if(!d(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("."),i=n[r.shift()];r.length&&void 0!=i;){var a=r.shift();i=a?i[a]:i+"."}return void 0!=i?i:e})},$["import"]=function(e,n){var t,r={override:!1,wrap:!0};if(n&&n instanceof Object&&en.extend(r,n),d(e)){if("undefined"==typeof require)throw new Error("Cannot load file: require not available.");var i=require(e);$["import"](i)}else if(J(e)){if(t=e.name,!t)throw new Error("Cannot import an unnamed function or object");(r.override||void 0===$[t])&&Q(t,e,r)}else if(e instanceof Object)for(t in e)if(e.hasOwnProperty(t)){var a=e[t];J(a)?Q(t,a,r):$["import"](a)}},function(){function e(){J++,nn=Q.charAt(J)}function r(){J=0,nn=Q.charAt(0)}function i(){for(rn=X.NULL,tn="";" "==nn||" "==nn;)e();if("#"==nn)for(;"\n"!=nn&&""!=nn;)e();if(""==nn)return rn=X.DELIMITER,void 0;if("!"==nn)return rn=X.DELIMITER,tn+=nn,e(),"="==nn&&(tn+=nn,e()),void 0;if("-"==nn||","==nn||"("==nn||")"==nn||"["==nn||"]"==nn||'"'==nn||"'"==nn||"\n"==nn||";"==nn||":"==nn)return rn=X.DELIMITER,tn+=nn,e(),void 0;if(a(nn))for(rn=X.DELIMITER;a(nn);)tn+=nn,e();else if(s(nn)){if(rn=X.NUMBER,"."==nn)tn+=nn,e(),f(nn)||(rn=X.UNKNOWN);else{for(;f(nn);)tn+=nn,e();"."==nn&&(tn+=nn,e())}for(;f(nn);)tn+=nn,e();if("E"==nn||"e"==nn)for(tn+=nn,e(),("+"==nn||"-"==nn)&&(tn+=nn,e()),f(nn)||(rn=X.UNKNOWN);f(nn);)tn+=nn,e()}else{if(!o(nn)){for(rn=X.UNKNOWN;""!=nn;)tn+=nn,e();throw W('Syntax error in part "'+tn+'"')}for(rn=X.SYMBOL;o(nn)||f(nn);)tn+=nn,e()}}function a(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==e||"!"==e||"'"==e}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(e){r(),i();var n;if(n=""==tn?new b(void 0):c(e),""!=tn)throw rn==X.DELIMITER?Z("Unknown operator "+tn):W('Unexpected part "'+tn+'"');return n}function c(e){var n,t,r;for("\n"!=tn&&";"!=tn&&""!=tn&&(n=l(e));"\n"==tn||";"==tn;)t||(t=new U,n&&(r=";"!=tn,t.add(n,r))),i(),"\n"!=tn&&";"!=tn&&""!=tn&&(n=l(e),r=";"!=tn,t.add(n,r));return t?t:(n||(n=l(e)),n)}function l(e){var n=h(e),t="ans";return new R(t,n,e)}function h(e){if(rn==X.SYMBOL&&"function"==tn){if(i(),rn!=X.SYMBOL)throw W("Function name expected");var n=tn;if(i(),"("!=tn)throw W("Opening parenthesis ( expected");for(var t=e.createSubScope(),r=[];;){if(i(),rn!=X.SYMBOL)throw W("Variable name expected");if(r.push(tn),i(),","!=tn){if(")"==tn)break;throw W('Comma , or closing parenthesis ) expected"')}}if(i(),"="!=tn)throw W("Equal sign = expected");i();var a=p(t);return new L(n,r,a,t,e)}return p(e)}function p(e){var n,t,r,a,o=m(e);if("="==tn){if(o instanceof A)return i(),n=o.name,t=null,a=p(e),new R(n,a,e);if(o instanceof S&&o.object instanceof A)return i(),n=o.object.name,t=o.params,r=o.paramScopes,a=p(e),new z(n,t,r,a,e);throw W("Symbol expected at the left hand side of assignment operator =")}return o}function m(e){var n,t,r,a=[];if(n=":"==tn?new b(1):v(e),":"==tn){for(a.push(n);":"==tn;)i(),")"==tn||","==tn||""==tn?a.push(new A("end",e)):a.push(v(e));a.length&&(t="range",r=$.range,n=new M(t,r,a))}return n}function v(e){var n,t,r,a,o;for(n=g(e),t={"in":"in"};void 0!==t[tn];)r=tn,a=$[t[r]],i(),o=[n,g(e)],n=new M(r,a,o);return n}function g(e){var n=w(e);return n}function w(e){var n,t,r,a,o;for(n=E(e),t={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==t[tn];)r=tn,a=$[t[r]],i(),o=[n,E(e)],n=new M(r,a,o);return n}function E(e){var n,t,r,a,o;for(n=x(e),t={"+":"add","-":"subtract"};void 0!==t[tn];)r=tn,a=$[t[r]],i(),o=[n,x(e)],n=new M(r,a,o);return n}function x(e){var n,t,r,a,o;for(n=O(e),t={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==t[tn];)r=tn,a=$[t[r]],i(),o=[n,O(e)],n=new M(r,a,o);return n}function O(e){var n,t,r;return"-"==tn?(n=tn,t=$.unaryminus,i(),r=[_(e)],new M(n,t,r)):_(e)}function _(e){var n,t,r,a,o,s;for(r=[q(e)];"^"==tn;)i(),r.push(q(e));for(n=r.pop();r.length;)t=r.pop(),a="^",o=$.pow,s=[t,n],n=new M(a,o,s);return n}function q(e){var n,t,r,a;for(n=I(e);"!"==tn;)t=tn,r=$.factorial,i(),a=[n],n=new M(t,r,a);return n}function I(e){var n,t,r,a;for(n=P(e);"'"==tn;)t=tn,r=$.transpose,i(),a=[n],n=new M(t,r,a);return n}function P(e){return B(e)}function B(e){var n,t;return rn==X.SYMBOL?(t=tn,i(),n=new A(t,e),C(e,n)):G(e)}function C(e,n){for(var t,r,a;"("==tn;){if(t=[],r=[],i(),")"!=tn)for(a=e.createSubScope(),r.push(a),t.push(m(a));","==tn;)i(),a=e.createSubScope(),r.push(a),t.push(m(a));if(")"!=tn)throw W("Parenthesis ) missing");i(),n=new S(n,t,r)}return n}function G(n){var t,r,a;if('"'==tn){for(r="",a="";""!=nn&&('"'!=nn||"\\"==a);)r+=nn,a=nn,e();if(i(),'"'!=tn)throw W('End of string " missing');return i(),t=new b(r),t=C(n,t)}return F(n)}function F(e){var n,t,r,a,o,s;if("["==tn){for(i();"\n"==tn;)i();if("]"!=tn){for(t=[],r=0,a=0,t[0]=[p(e)];","==tn||";"==tn;){for(","==tn?a++:(r++,a=0,t[r]=[]),i();"\n"==tn;)i();for(t[r][a]=p(e);"\n"==tn;)i()}for(o=t.length,s=t.length>0?t[0].length:0,r=1;o>r;r++)if(t[r].length!=s)throw Z("Number of columns must match ("+t[r].length+" != "+s+")");if("]"!=tn)throw W("End of matrix ] missing");i(),n=new T(t)}else i(),n=new T([[]]);return n=C(e,n)}return V(e)}function V(e){var t,r,a;if(rn==X.NUMBER){if(a="."==tn?0:Number(tn),i(),rn==X.SYMBOL){if("i"==tn||"I"==tn)return r=new n(0,a),i(),new b(r);if(y.isPlainUnit(tn))return r=new y(a,tn),i(),new b(r);throw K('Unknown unit "'+tn+'"')}return t=new b(a),t=C(e,t)}return j(e)}function j(e){var n;if("("==tn){if(i(),n=p(e),")"!=tn)throw W("Parenthesis ) expected");return i(),n=C(e,n)}return D(e)}function D(){throw""==tn?W("Unexpected end of expression"):W("Value expected")}function H(){return void 0}function k(){return J-tn.length+1}function Y(e){var n=H(),t=k();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 K(e){return new TypeError(Y(e))}function Z(e){return new Error(Y(e))}$.parse=function(e,n){if(1!=arguments.length&&2!=arguments.length)throw N("parse",arguments.length,1,2);var r;if(r=n?n instanceof $.expr.Scope?n:new $.expr.Scope(n):new $.expr.Scope,d(e))return Q=e||"",u(r);if(e instanceof Array||e instanceof t)return en.map(e,function(e){return Q=e||"",u(r)});throw new TypeError("String or matrix expected")};var X={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},Q="",J=0,nn="",tn="",rn=X.NULL}(),$.select=function(e){return new $.type.Selector(e)},$["typeof"]=function(e){if(1!=arguments.length)throw N("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 $)if($.hasOwnProperty(n)&&e.constructor==$[n])return n.toLowerCase();for(n in $.type)if($.type.hasOwnProperty(n)&&e.constructor==$.type[n])return n.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t},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,i;if(null==this)throw new TypeError(" this is null or not defined");var a=Object(this),o=a.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(n&&(t=n),r=new Array(o),i=0;o>i;){var s,f;i in a&&(s=a[i],f=e.call(t,s,i,a),r[i]=f),i++}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],i=0;t>i;i++)if(i in n&&!e.call(r,n[i],i,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],i=0;t>i;i++)if(i in n&&e.call(r,n[i],i,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(){},i=function(){return t.apply(this instanceof r&&e?this:e,n.concat(Array.prototype.slice.call(arguments)))};return r.prototype=this.prototype,i.prototype=new r,i});for(var rn in $)$.hasOwnProperty(rn)&&rn&&w(rn,$[rn])}(); |