@khanacademy/kas 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE.txt +21 -0
- package/README.md +94 -0
- package/dist/es/index.js +2 -0
- package/dist/es/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.flow +2 -0
- package/dist/index.js.map +1 -0
- package/experimenter.html +75 -0
- package/package.json +38 -0
- package/src/__genfiles__/parser.js +840 -0
- package/src/__genfiles__/unitparser.js +679 -0
- package/src/__tests__/checking-form_test.js +76 -0
- package/src/__tests__/comparing_test.js +322 -0
- package/src/__tests__/compilation_test.js +97 -0
- package/src/__tests__/evaluating_test.js +73 -0
- package/src/__tests__/index_test.js +364 -0
- package/src/__tests__/parsing_test.js +480 -0
- package/src/__tests__/rendering_test.js +272 -0
- package/src/__tests__/transforming_test.js +331 -0
- package/src/__tests__/units_test.js +188 -0
- package/src/compare.js +69 -0
- package/src/index.js +2 -0
- package/src/nodes.js +3504 -0
- package/src/parser-generator.js +212 -0
- package/src/unitvalue.jison +161 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("underscore")),n=function(){var t=function(t,e,n,i){for(n=n||{},i=t.length;i--;n[t[i]]=e);return n},e=[1,11],n=[1,9],i=[8,17],r=[6,11],s=[6,11,13,17],a={trace:function(){},yy:{},symbols_:{error:2,unitvalue:3,magnitude:4,unit:5,EOF:6,float:7,POW:8,int:9,multatoms:10,DIV:11,expatom:12,MUL:13,atom:14,"^":15,nat:16,ATOM:17,FLOAT:18,NAT:19,NEG:20,$accept:0,$end:1},terminals_:{2:"error",6:"EOF",8:"POW",11:"DIV",13:"MUL",15:"^",17:"ATOM",18:"FLOAT",19:"NAT",20:"NEG"},productions_:[0,[3,3],[3,2],[4,3],[4,1],[5,3],[5,1],[10,3],[10,2],[10,1],[12,3],[12,1],[14,1],[7,1],[7,1],[16,1],[9,2],[9,1]],performAction:function(t,e,n,i,r,s,a){var o=s.length-1;switch(r){case 1:return{type:"unitMagnitude",magnitude:s[o-2],unit:s[o-1]};case 2:return{type:"unitStandalone",unit:s[o-1]};case 3:this.$=s[o-2]+"e"+s[o];break;case 4:case 13:case 14:case 15:case 17:this.$=s[o];break;case 5:this.$={num:s[o-2],denom:s[o]};break;case 6:this.$={num:s[o],denom:null};break;case 7:this.$=[s[o-2]].concat(s[o]);break;case 8:this.$=[s[o-1]].concat(s[o]);break;case 9:this.$=[s[o]];break;case 10:this.$={name:s[o-2],pow:s[o]};break;case 11:this.$={name:s[o],pow:1};break;case 12:this.$=t;break;case 16:this.$="-"+s[o]}},table:[{3:1,4:2,5:3,7:4,10:5,12:8,14:10,16:7,17:e,18:[1,6],19:n},{1:[3]},{5:12,10:5,12:8,14:10,17:e},{6:[1,13]},{8:[1,14],17:[2,4]},{6:[2,6],11:[1,15]},t(i,[2,13]),t(i,[2,14]),t(r,[2,9],{12:8,14:10,10:17,13:[1,16],17:e}),t([6,8,11,13,17],[2,15]),t(s,[2,11],{15:[1,18]}),t([6,11,13,15,17],[2,12]),{6:[1,19]},{1:[2,2]},{9:20,19:[1,22],20:[1,21]},{10:23,12:8,14:10,17:e},{10:24,12:8,14:10,17:e},t(r,[2,8]),{16:25,19:n},{1:[2,1]},{17:[2,3]},{19:[1,26]},{17:[2,17]},{6:[2,5]},t(r,[2,7]),t(s,[2,10]),{17:[2,16]}],defaultActions:{13:[2,2],19:[2,1],20:[2,3],22:[2,17],23:[2,5],26:[2,16]},parseError:function(t,e){if(!e.recoverable)throw new Error(t);this.trace(t)},parse:function(t){var e=this,n=[0],i=[null],r=[],s=this.table,a="",o=0,c=0,u=2,l=1,h=r.slice.call(arguments,1),f=Object.create(this.lexer),p={yy:{}};for(var d in this.yy)Object.prototype.hasOwnProperty.call(this.yy,d)&&(p.yy[d]=this.yy[d]);f.setInput(t,p.yy),p.yy.lexer=f,p.yy.parser=this,void 0===f.yylloc&&(f.yylloc={});var y=f.yylloc;r.push(y);var g=f.options&&f.options.ranges;function m(){var t;return"number"!=typeof(t=f.lex()||l)&&(t=e.symbols_[t]||t),t}"function"==typeof p.yy.parseError?this.parseError=p.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var v,x,w,b,_,k,M,E,I={};;){if(x=n[n.length-1],this.defaultActions[x]?w=this.defaultActions[x]:(null==v&&(v=m()),w=s[x]&&s[x][v]),void 0===w||!w.length||!w[0]){var S="";for(_ in E=[],s[x])this.terminals_[_]&&_>u&&E.push("'"+this.terminals_[_]+"'");S=f.showPosition?"Parse error on line "+(o+1)+":\n"+f.showPosition()+"\nExpecting "+E.join(", ")+", got '"+(this.terminals_[v]||v)+"'":"Parse error on line "+(o+1)+": Unexpected "+(v==l?"end of input":"'"+(this.terminals_[v]||v)+"'"),this.parseError(S,{text:f.match,token:this.terminals_[v]||v,line:f.yylineno,loc:y,expected:E})}if(w[0]instanceof Array&&w.length>1)throw new Error("Parse Error: multiple actions possible at state: "+x+", token: "+v);switch(w[0]){case 1:n.push(v),i.push(f.yytext),r.push(f.yylloc),n.push(w[1]),v=null,c=f.yyleng,a=f.yytext,o=f.yylineno,y=f.yylloc;break;case 2:if(k=this.productions_[w[1]][1],I.$=i[i.length-k],I._$={first_line:r[r.length-(k||1)].first_line,last_line:r[r.length-1].last_line,first_column:r[r.length-(k||1)].first_column,last_column:r[r.length-1].last_column},g&&(I._$.range=[r[r.length-(k||1)].range[0],r[r.length-1].range[1]]),void 0!==(b=this.performAction.apply(I,[a,c,o,p.yy,w[1],i,r].concat(h))))return b;k&&(n=n.slice(0,-1*k*2),i=i.slice(0,-1*k),r=r.slice(0,-1*k)),n.push(this.productions_[w[1]][0]),i.push(I.$),r.push(I._$),M=s[n[n.length-2]][n[n.length-1]],n.push(M);break;case 3:return!0}}return!0}},o={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var i=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var r=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===i.length?this.yylloc.first_column:0)+i[i.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[r[0],r[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,i,r;if(this.options.backtrack_lexer&&(r={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(r.yylloc.range=this.yylloc.range.slice(0))),(i=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=i.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:i?i[i.length-1].length-i[i.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var s in r)this[s]=r[s];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,i;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var r=this._currentRules(),s=0;s<r.length;s++)if((n=this._input.match(this.rules[r[s]]))&&(!e||n[0].length>e[0].length)){if(e=n,i=s,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,r[s])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,r[i]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var t=this.next();return t||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,n,i){switch(n){case 0:return 11;case 1:return"(";case 2:return")";case 3:return 8;case 4:return 15;case 5:return 13;case 6:return 18;case 7:return 19;case 8:return 20;case 9:case 10:case 11:return 17;case 12:break;case 13:return 6}},rules:[/^(?:\/)/,/^(?:\()/,/^(?:\))/,/^(?:(\*|x|\u00d7|\u2219|\u22c5|\u00b7)\s*10\s*\^)/,/^(?:\^)/,/^(?:\*)/,/^(?:[0-9]+\.[0-9]+)/,/^(?:[0-9]+)/,/^(?:-)/,/^(?:\u00b0( ?)[cCfF])/,/^(?:fl\.? oz\.?)/,/^(?:[\u00b5]?([A-Za-z-]+|[\u2103\u2109\u212b]))/,/^(?:\s+)/,/^(?:$)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13],inclusive:!0}}};function c(){this.yy={}}return a.lexer=o,c.prototype=a,a.Parser=c,new c}();const i=n;var r=function(){var t=function(t,e,n,i){for(n=n||{},i=t.length;i--;n[t[i]]=e);return n},e=[1,7],n=[1,17],i=[1,13],r=[1,14],s=[1,15],a=[1,32],o=[1,22],c=[1,23],u=[1,24],l=[1,25],h=[1,26],f=[1,33],p=[1,27],d=[1,28],y=[1,29],g=[1,30],m=[1,20],v=[1,36],x=[1,37],w=[5,6,8,10,33,35,41,43,45],b=[1,39],_=[1,40],k=[5,6,8,10,12,14,16,19,21,22,28,29,30,31,32,33,34,35,37,39,41,42,43,44,45,46],M=[10,16,19,21,22,28,29,30,31,32,34,37,39,42,43,44,46],E=[5,6,8,10,12,14,16,18,19,21,22,28,29,30,31,32,33,34,35,37,39,41,42,43,44,45,46],I={trace:function(){},yy:{},symbols_:{error:2,equation:3,expression:4,SIGN:5,EOF:6,additive:7,"+":8,multiplicative:9,"-":10,triglog:11,"*":12,negative:13,"/":14,trig:15,TRIG:16,trigfunc:17,"^":18,TRIGINV:19,logbase:20,ln:21,log:22,_:23,subscriptable:24,power:25,primitive:26,variable:27,VAR:28,CONST:29,INT:30,FLOAT:31,"{":32,"}":33,"(":34,")":35,function:36,FUNC:37,invocation:38,sqrt:39,"[":40,"]":41,abs:42,"|":43,"LEFT|":44,"RIGHT|":45,FRAC:46,$accept:0,$end:1},terminals_:{2:"error",5:"SIGN",6:"EOF",8:"+",10:"-",12:"*",14:"/",16:"TRIG",18:"^",19:"TRIGINV",21:"ln",22:"log",23:"_",28:"VAR",29:"CONST",30:"INT",31:"FLOAT",32:"{",33:"}",34:"(",35:")",37:"FUNC",39:"sqrt",40:"[",41:"]",42:"abs",43:"|",44:"LEFT|",45:"RIGHT|",46:"FRAC"},productions_:[0,[3,4],[3,2],[3,1],[4,1],[7,3],[7,3],[7,1],[9,2],[9,3],[9,3],[9,1],[13,2],[13,1],[15,1],[17,1],[17,3],[17,1],[20,1],[20,1],[20,3],[11,2],[11,2],[11,1],[25,3],[25,1],[27,1],[24,3],[24,1],[24,1],[24,1],[24,1],[24,3],[24,3],[36,1],[38,4],[38,4],[38,7],[38,4],[38,3],[38,3],[38,4],[26,1],[26,1],[26,7]],performAction:function(t,e,n,i,r,s,a){var o=s.length-1;switch(r){case 1:return new i.Eq(s[o-3],s[o-2],s[o-1]);case 2:return s[o-1];case 3:return new i.Add([]);case 4:case 7:case 11:case 13:case 15:case 20:case 23:case 25:case 42:case 43:this.$=s[o];break;case 5:this.$=i.Add.createOrAppend(s[o-2],s[o]);break;case 6:this.$=i.Add.createOrAppend(s[o-2],i.Mul.handleNegative(s[o],"subtract"));break;case 8:this.$=i.Mul.fold(i.Mul.createOrAppend(s[o-1],s[o]));break;case 9:this.$=i.Mul.fold(i.Mul.createOrAppend(s[o-2],s[o]));break;case 10:this.$=i.Mul.fold(i.Mul.handleDivide(s[o-2],s[o]));break;case 12:this.$=i.Mul.handleNegative(s[o]);break;case 14:case 17:this.$=[t];break;case 16:this.$=s[o-2].concat(s[o]);break;case 18:this.$=i.Log.natural();break;case 19:this.$=i.Log.common();break;case 21:this.$=i.Trig.create(s[o-1],s[o]);break;case 22:this.$=i.Log.create(s[o-1],s[o]);break;case 24:this.$=new i.Pow(s[o-2],s[o]);break;case 26:case 34:this.$=t;break;case 27:this.$=new i.Var(s[o-2],s[o]);break;case 28:this.$=new i.Var(s[o]);break;case 29:this.$=new i.Const(t.toLowerCase());break;case 30:this.$=i.Int.create(Number(t));break;case 31:this.$=i.Float.create(Number(t));break;case 32:this.$=s[o-1].completeParse();break;case 33:this.$=s[o-1].completeParse().addHint("parens");break;case 35:case 36:this.$=i.Pow.sqrt(s[o-1]);break;case 37:this.$=new i.Pow.nthroot(s[o-1],s[o-4]);break;case 38:case 39:case 40:this.$=new i.Abs(s[o-1]);break;case 41:this.$=new i.Func(s[o-3],s[o-1]);break;case 44:this.$=i.Mul.handleDivide(s[o-4],s[o-1])}},table:[{3:1,4:2,6:[1,3],7:4,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{1:[3]},{5:[1,34],6:[1,35]},{1:[2,3]},t([5,6],[2,4],{8:v,10:x}),t(w,[2,7],{17:9,20:10,25:11,15:12,26:16,24:18,38:19,27:21,36:31,11:38,12:b,14:_,16:n,19:i,21:r,22:s,28:a,29:o,30:c,31:u,32:l,34:h,37:f,39:p,42:d,44:g,46:m}),t(k,[2,11]),{10:e,11:8,13:41,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},t(k,[2,13]),{10:e,11:8,13:42,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{10:e,11:8,13:43,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},t(k,[2,23]),t(M,[2,15],{18:[1,44]}),t(M,[2,17]),t(M,[2,18]),t(M,[2,19],{23:[1,45]}),t(k,[2,25],{18:[1,46]}),t([10,16,18,19,21,22,28,29,30,31,32,34,37,39,42,43,44,46],[2,14]),t(E,[2,42]),t(E,[2,43]),{32:[1,47]},t(E,[2,28],{23:[1,48]}),t(E,[2,29]),t(E,[2,30]),t(E,[2,31]),{7:49,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{7:50,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{32:[1,52],34:[1,51],40:[1,53]},{34:[1,54]},{7:55,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{7:56,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{34:[1,57]},t([5,6,8,10,12,14,16,18,19,21,22,23,28,29,30,31,32,33,34,35,37,39,41,42,43,44,45,46],[2,26]),{34:[2,34]},{4:58,7:4,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{1:[2,2]},{9:59,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{9:60,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},t(k,[2,8]),{10:e,11:8,13:61,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{10:e,11:8,13:62,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},t(k,[2,12]),t(k,[2,21]),t(k,[2,22]),{10:e,11:8,13:63,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{24:64,27:21,28:a,29:o,30:c,31:u,32:l,34:h},{10:e,11:8,13:65,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{7:66,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{24:67,27:21,28:a,29:o,30:c,31:u,32:l,34:h},{8:v,10:x,33:[1,68]},{8:v,10:x,35:[1,69]},{7:70,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{7:71,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{7:72,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{7:73,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{8:v,10:x,43:[1,74]},{8:v,10:x,45:[1,75]},{7:76,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{6:[1,77]},t(w,[2,5],{17:9,20:10,25:11,15:12,26:16,24:18,38:19,27:21,36:31,11:38,12:b,14:_,16:n,19:i,21:r,22:s,28:a,29:o,30:c,31:u,32:l,34:h,37:f,39:p,42:d,44:g,46:m}),t(w,[2,6],{17:9,20:10,25:11,15:12,26:16,24:18,38:19,27:21,36:31,11:38,12:b,14:_,16:n,19:i,21:r,22:s,28:a,29:o,30:c,31:u,32:l,34:h,37:f,39:p,42:d,44:g,46:m}),t(k,[2,9]),t(k,[2,10]),t(M,[2,16]),t(M,[2,20]),t(k,[2,24]),{8:v,10:x,33:[1,78]},t(E,[2,27]),t(E,[2,32]),t(E,[2,33]),{8:v,10:x,35:[1,79]},{8:v,10:x,33:[1,80]},{8:v,10:x,41:[1,81]},{8:v,10:x,35:[1,82]},t(E,[2,39]),t(E,[2,40]),{8:v,10:x,35:[1,83]},{1:[2,1]},{32:[1,84]},t(E,[2,35]),t(E,[2,36]),{32:[1,85]},t(E,[2,38]),t(E,[2,41]),{7:86,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{7:87,9:5,10:e,11:8,13:6,15:12,16:n,17:9,19:i,20:10,21:r,22:s,24:18,25:11,26:16,27:21,28:a,29:o,30:c,31:u,32:l,34:h,36:31,37:f,38:19,39:p,42:d,43:y,44:g,46:m},{8:v,10:x,33:[1,88]},{8:v,10:x,33:[1,89]},t(E,[2,44]),t(E,[2,37])],defaultActions:{3:[2,3],33:[2,34],35:[2,2],77:[2,1]},parseError:function(t,e){if(!e.recoverable)throw new Error(t);this.trace(t)},parse:function(t){var e=this,n=[0],i=[null],r=[],s=this.table,a="",o=0,c=0,u=2,l=1,h=r.slice.call(arguments,1),f=Object.create(this.lexer),p={yy:{}};for(var d in this.yy)Object.prototype.hasOwnProperty.call(this.yy,d)&&(p.yy[d]=this.yy[d]);f.setInput(t,p.yy),p.yy.lexer=f,p.yy.parser=this,void 0===f.yylloc&&(f.yylloc={});var y=f.yylloc;r.push(y);var g=f.options&&f.options.ranges;function m(){var t;return"number"!=typeof(t=f.lex()||l)&&(t=e.symbols_[t]||t),t}"function"==typeof p.yy.parseError?this.parseError=p.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var v,x,w,b,_,k,M,E,I={};;){if(x=n[n.length-1],this.defaultActions[x]?w=this.defaultActions[x]:(null==v&&(v=m()),w=s[x]&&s[x][v]),void 0===w||!w.length||!w[0]){var S="";for(_ in E=[],s[x])this.terminals_[_]&&_>u&&E.push("'"+this.terminals_[_]+"'");S=f.showPosition?"Parse error on line "+(o+1)+":\n"+f.showPosition()+"\nExpecting "+E.join(", ")+", got '"+(this.terminals_[v]||v)+"'":"Parse error on line "+(o+1)+": Unexpected "+(v==l?"end of input":"'"+(this.terminals_[v]||v)+"'"),this.parseError(S,{text:f.match,token:this.terminals_[v]||v,line:f.yylineno,loc:y,expected:E})}if(w[0]instanceof Array&&w.length>1)throw new Error("Parse Error: multiple actions possible at state: "+x+", token: "+v);switch(w[0]){case 1:n.push(v),i.push(f.yytext),r.push(f.yylloc),n.push(w[1]),v=null,c=f.yyleng,a=f.yytext,o=f.yylineno,y=f.yylloc;break;case 2:if(k=this.productions_[w[1]][1],I.$=i[i.length-k],I._$={first_line:r[r.length-(k||1)].first_line,last_line:r[r.length-1].last_line,first_column:r[r.length-(k||1)].first_column,last_column:r[r.length-1].last_column},g&&(I._$.range=[r[r.length-(k||1)].range[0],r[r.length-1].range[1]]),void 0!==(b=this.performAction.apply(I,[a,c,o,p.yy,w[1],i,r].concat(h))))return b;k&&(n=n.slice(0,-1*k*2),i=i.slice(0,-1*k),r=r.slice(0,-1*k)),n.push(this.productions_[w[1]][0]),i.push(I.$),r.push(I._$),M=s[n[n.length-2]][n[n.length-1]],n.push(M);break;case 3:return!0}}return!0}},S={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var i=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var r=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===i.length?this.yylloc.first_column:0)+i[i.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[r[0],r[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,i,r;if(this.options.backtrack_lexer&&(r={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(r.yylloc.range=this.yylloc.range.slice(0))),(i=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=i.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:i?i[i.length-1].length-i[i.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var s in r)this[s]=r[s];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,i;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var r=this._currentRules(),s=0;s<r.length;s++)if((n=this._input.match(this.rules[r[s]]))&&(!e||n[0].length>e[0].length)){if(e=n,i=s,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,r[s])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,r[i]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var t=this.next();return t||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{flex:!0},performAction:function(t,e,n,i){switch(n){case 0:case 1:case 2:break;case 3:return"INT";case 4:return"FLOAT";case 5:case 15:return"^";case 6:case 7:case 8:case 9:return"*";case 10:case 11:return"/";case 12:case 13:return"-";case 14:return"+";case 16:case 18:return"(";case 17:case 19:return")";case 20:return"[";case 21:return"]";case 22:case 24:return"{";case 23:case 25:return"}";case 26:return"_";case 27:return"|";case 28:return"LEFT|";case 29:return"RIGHT|";case 30:return"!";case 31:return"SIGN";case 32:case 34:case 40:return e.yytext="<=","SIGN";case 33:case 35:case 41:return e.yytext=">=","SIGN";case 36:case 37:case 38:case 39:return e.yytext="<>","SIGN";case 42:case 43:return"FRAC";case 44:return"sqrt";case 45:return"abs";case 46:return"ln";case 47:return"log";case 48:case 49:case 50:case 51:return"TRIG";case 52:return e.yytext="sin","TRIG";case 53:return e.yytext="cos","TRIG";case 54:return e.yytext="tan","TRIG";case 55:return e.yytext="csc","TRIG";case 56:return e.yytext="sec","TRIG";case 57:return e.yytext="cot","TRIG";case 58:return e.yytext="arcsin","TRIG";case 59:return e.yytext="arccos","TRIG";case 60:return e.yytext="arctan","TRIG";case 61:return e.yytext="arccsc","TRIG";case 62:return e.yytext="arcsec","TRIG";case 63:return e.yytext="arccot","TRIG";case 64:case 65:return"TRIGINV";case 66:return e.yytext="sinh","TRIG";case 67:return e.yytext="cosh","TRIG";case 68:case 71:return e.yytext="tanh","TRIG";case 69:return e.yytext="csch","TRIG";case 70:return e.yytext="sech","TRIG";case 72:return"CONST";case 73:case 74:return e.yytext="pi","CONST";case 75:case 78:return"VAR";case 76:case 77:return e.yytext="theta","VAR";case 79:case 80:return e.yytext="phi","VAR";case 81:return t.symbolLexer(e.yytext);case 82:return"EOF";case 83:return"INVALID";case 84:console.log(e.yytext)}},rules:[/^(?:\s+)/,/^(?:\\space)/,/^(?:\\ )/,/^(?:[0-9]+\.?)/,/^(?:([0-9]+)?\.[0-9]+)/,/^(?:\*\*)/,/^(?:\*)/,/^(?:\\cdot|·)/,/^(?:\\times|×)/,/^(?:\\ast)/,/^(?:\/)/,/^(?:\\div|÷)/,/^(?:-)/,/^(?:−)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\))/,/^(?:\\left\()/,/^(?:\\right\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\\left\{)/,/^(?:\\right\})/,/^(?:_)/,/^(?:\|)/,/^(?:\\left\|)/,/^(?:\\right\|)/,/^(?:\!)/,/^(?:<=|>=|<>|<|>|=)/,/^(?:\\le)/,/^(?:\\ge)/,/^(?:\\leq)/,/^(?:\\geq)/,/^(?:=\/=)/,/^(?:\\ne)/,/^(?:\\neq)/,/^(?:≠)/,/^(?:≤)/,/^(?:≥)/,/^(?:\\frac)/,/^(?:\\dfrac)/,/^(?:sqrt|\\sqrt)/,/^(?:abs|\\abs)/,/^(?:ln|\\ln)/,/^(?:log|\\log)/,/^(?:sin|cos|tan)/,/^(?:csc|sec|cot)/,/^(?:sinh|cosh|tanh)/,/^(?:csch|sech|coth)/,/^(?:\\sin)/,/^(?:\\cos)/,/^(?:\\tan)/,/^(?:\\csc)/,/^(?:\\sec)/,/^(?:\\cot)/,/^(?:\\arcsin)/,/^(?:\\arccos)/,/^(?:\\arctan)/,/^(?:\\arccsc)/,/^(?:\\arcsec)/,/^(?:\\arccot)/,/^(?:arcsin|arccos|arctan)/,/^(?:arccsc|arcsec|arccot)/,/^(?:\\sinh)/,/^(?:\\cosh)/,/^(?:\\tanh)/,/^(?:\\csch)/,/^(?:\\sech)/,/^(?:\\coth)/,/^(?:pi)/,/^(?:π)/,/^(?:\\pi)/,/^(?:theta)/,/^(?:θ)/,/^(?:\\theta)/,/^(?:phi)/,/^(?:φ)/,/^(?:\\phi)/,/^(?:[a-zA-Z])/,/^(?:$)/,/^(?:.)/,/^(?:.)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84],inclusive:!0}}};function D(){this.yy={}}return I.lexer=S,D.prototype=I,I.Parser=D,new D}(),s=function(){throw new Error("Abstract method - must override for expr: "+this.print())},a=function(t){throw new Error(t)},o=function(t){return t!=t};function c(){}function u(){}function l(){this.terms=1===arguments.length?arguments[0]:e.default.toArray(arguments)}function h(){this.terms=1===arguments.length?arguments[0]:e.default.toArray(arguments)}function f(t,e){this.base=t,this.exp=e}function p(t,e){this.base=t,this.power=e}function d(t,e){this.type=t,this.arg=e}function y(t){this.arg=t}function g(t,e,n){this.left=t,this.type=e,this.right=n}function m(){}function v(t,e){this.symbol=t,this.arg=e}function x(t,e){this.symbol=t,this.subscript=e}function w(t){this.symbol=t}function b(){}function _(t,e){var n=t,i=e;i<0&&(n=-n,i=-i),this.n=n,this.d=i}function k(t){this.n=t}function M(t){this.n=t}e.default.extend(c.prototype,{func:s,args:s,construct:function(t){var e=new this.func;return this.func.apply(e,t),e},recurse:function(t){var n=Array.prototype.slice.call(arguments,1),i=e.default.map(this.args(),(function(i){return e.default.isString(i)?i:i[t].apply(i,n)}));return this.construct(i)},eval:s,codegen:s,compile:function(){var t=this.codegen();try{return new Function("vars","return "+t+";")}catch(e){throw new Error("Function did not compile: "+t)}},print:s,tex:s,asTex:function(t){t=t||{},e.default.defaults(t,{display:!0,dynamic:!0,times:!1});var n=this.tex();return t.display&&(n="\\displaystyle "+n),t.dynamic&&(n=(n=n.replace(/\(/g,"\\left(")).replace(/\)/g,"\\right)")),t.times&&(n=n.replace(/\\cdot/g,"\\times")),n},name:function(){return this.func.name?this.func.name:this.func.toString().match(/^function\s*([^\s(]+)/)[1]},repr:function(){return this.name()+"("+e.default.map(this.args(),(function(t){return e.default.isString(t)?t:t.repr()})).join(",")+")"},strip:function(){return this.recurse("strip")},normalize:function(){return this.recurse("normalize")},expand:function(){return this.recurse("expand")},factor:function(t){return this.recurse("factor",t)},collect:function(t){return this.recurse("collect",t)},equals:function(t){return this.normalize().print()===t.normalize().print()},simplify:function(t){t=e.default.extend({once:!1},t);var n=this.factor(t),i=n.collect(t);n.equals(i)&&(i=this.collect(t));var r=i.expand(t),s=r.collect(t);r.equals(s)&&(s=i.collect(t));var a=s;return t.once||this.equals(a)?a:a.simplify(t)},isSimplified:function(){return this.equals(this.simplify())},exprArgs:function(){return e.default.filter(this.args(),(function(t){return t instanceof c}))},getVars:function(t){return e.default.uniq(e.default.flatten(e.default.invoke(this.exprArgs(),"getVars",t))).sort()},getConsts:function(){return e.default.uniq(e.default.flatten(e.default.invoke(this.exprArgs(),"getConsts"))).sort()},getUnits:function(){return e.default.flatten(e.default.invoke(this.exprArgs(),"getUnits"))},is:function(t){return this instanceof t},has:function(t){return this instanceof t||e.default.any(this.exprArgs(),(function(e){return e.has(t)}))},raiseToThe:function(t){return new f(this,t)},isSubtract:function(){return!1},isDivide:function(){return!1},isRoot:function(){return!1},needsExplicitMul:function(){return this.args()[0].needsExplicitMul()},sameVars:function(t){var n=this.getVars(),i=t.getVars(),r=function(t,n){return!e.default.difference(t,n).length},s=function(t){return e.default.uniq(e.default.invoke(t,"toLowerCase")).sort()};return{equal:r(n,i),equalIgnoringCase:r(s(n),s(i))}},compare:function(t){if(t instanceof g)return!1;var n=e.default.union(this.getVars(!0),t.getVars(!0)),i=function(t,e){var n=function(t,e){return Math.abs(t)<1||Math.abs(e)<1?Math.abs(t-e):Math.abs(1-t/e)}(t,e);return t===e||o(t)&&o(e)||n<Math.pow(10,-9)};if(!n.length&&!this.has(I)&&!t.has(I))return i(this.eval(),t.eval());var r=this.collect(),s=t.collect(),a=this.getUnits(),c=t.getUnits();if(!e.default.isEqual(a,c))return!1;for(var u=0;u<12;u++){var l,h={},f=Math.pow(10,1+Math.floor(3*u/12)),p=u%2==0;if(e.default.each(n,(function(t){var n,i;h[t]=p?(i=f-(n=-f),Math.random()*i+n):e.default.random(-f,f)})),r.has(v)||s.has(v)||r.has(I)||s.has(I)){var d=r.partialEval(h),y=s.partialEval(h);l=d.simplify().equals(y.simplify())}else{l=i(d=r.eval(h),y=s.eval(h))}if(!l)return!1}return!0},partialEval:function(t){return this instanceof I?this:this.has(v)?this instanceof v?new v(this.symbol,this.arg.partialEval(t)):this.recurse("partialEval",t):new M(this.eval(t).toFixed(9)).collect()},sameForm:function(t){return this.strip().equals(t.strip())},findGCD:function(t){return this.equals(t)?t:b.One},getDenominator:function(){return b.One},asMul:function(){return new h(b.One,this)},isPositive:s,isNegative:function(){return!1},asPositiveFactor:function(){return this.isPositive()?this:b.One},addHint:function(t){if(!t)return this;var n=this.construct(this.args());return n.hints=e.default.clone(this.hints),n.hints[t]=!0,n},hints:{parens:!1},asExpr:function(){return this},completeParse:function(){return this.recurse("completeParse")},abs:s,negate:function(){return new h(b.Neg,this)}}),u.prototype=new c,e.default.extend(u.prototype,{args:function(){return this.terms},normalize:function(){var t=e.default.sortBy(e.default.invoke(this.terms,"normalize"),(function(t){return t.print()}));return new this.func(t)},expand:function(){return this.recurse("expand").flatten()},partition:function(){var t=e.default.groupBy(this.terms,(function(t){return t instanceof b})),n=t[!0]||[],i=t[!1]||[];return[new this.func(n),new this.func(i)]},flatten:function(){var t=this,n=e.default.reject(this.terms,(function(e){return e.equals(t.identity)}));if(0===n.length)return t.identity;if(1===n.length)return n[0];var i=e.default.groupBy(n,(function(e){return e instanceof t.func})),r=i[!0]||[],s=(i[!1]||[]).concat(e.default.flatten(e.default.pluck(r,"terms"),!0));return new t.func(s)},identity:void 0,reduce:s,isPositive:function(){var t=e.default.invoke(this.terms,"collect");return e.default.all(e.default.invoke(t,"isPositive"))},replace:function(t,n){var i;i=t instanceof c?e.default.indexOf(this.terms,t):t;var r=[];e.default.isArray(n)?r=n:n&&(r=[n]);var s=this.terms.slice(0,i).concat(r).concat(this.terms.slice(i+1));return new this.func(s)},remove:function(t){return this.replace(t)},getDenominator:function(){return new h(e.default.invoke(this.terms,"getDenominator")).flatten()}}),l.prototype=new u,e.default.extend(l.prototype,{func:l,eval:function(t,n){return e.default.reduce(this.terms,(function(e,i){return e+i.eval(t,n)}),0)},codegen:function(){return e.default.map(this.terms,(function(t){return"("+t.codegen()+")"})).join(" + ")||"0"},print:function(){return e.default.invoke(this.terms,"print").join("+")},tex:function(){var t="";return e.default.each(this.terms,(function(e){!t||e.isSubtract()?t+=e.tex():t+="+"+e.tex()})),t},collect:function(t){var n=e.default.invoke(this.terms,"collect",t),i=[];e.default.each(n,(function(e){if(e instanceof h){var n=e.partition();i.push([n[1].flatten(),n[0].reduce(t)])}else e instanceof b?i.push([b.One,e]):i.push([e,b.One])}));var r=e.default.groupBy(i,(function(t){return t[0].normalize().print()})),s=e.default.compact(e.default.map(r,(function(n){var i=n[0][0];return new h(new l(e.default.zip.apply(e.default,n)[1]).reduce(t),i).collect(t)})));return new l(s).flatten()},factor:function(t){t=e.default.extend({keepNegative:!1},t);var n,i=e.default.invoke(this.terms,"collect");n=i[0]instanceof h?i[0].terms:[i[0]],e.default.each(e.default.rest(this.terms),(function(t){n=e.default.map(n,(function(e){return t.findGCD(e)}))})),!t.keepNegative&&this.isNegative()&&n.push(b.Neg),n=new h(n).flatten().collect();var r=e.default.map(i,(function(t){return h.handleDivide(t,n).simplify()}));return r=new l(r).flatten(),h.createOrAppend(n,r).flatten()},reduce:function(t){return e.default.reduce(this.terms,(function(e,n){return e.add(n,t)}),this.identity)},needsExplicitMul:function(){return!1},isNegative:function(){var t=e.default.invoke(this.terms,"collect");return e.default.all(e.default.invoke(t,"isNegative"))},negate:function(){return new l(e.default.invoke(this.terms,"negate"))}}),h.prototype=new u,e.default.extend(h.prototype,{func:h,eval:function(t,n){return e.default.reduce(this.terms,(function(e,i){return e*i.eval(t,n)}),1)},codegen:function(){return e.default.map(this.terms,(function(t){return"("+t.codegen()+")"})).join(" * ")||"0"},print:function(){return e.default.map(this.terms,(function(t){return t instanceof l?"("+t.print()+")":t.print()})).join("*")},getUnits:function(){var t=e.default(this.terms).chain().map((function(t){return t.getUnits()})).flatten().value();return t.sort(((t,e)=>t.unit.localeCompare(e.unit))),t},tex:function(){for(var t,n=" \\cdot ",i=e.default.groupBy(this.terms,(function(t){return t.isDivide()?"inverse":t instanceof b?"number":"other"})),r=i.inverse||[],s=i.number||[],a=i.other||[],o="",c=0;c<s.length;c++){if(s[c]instanceof _&&!(s[c]instanceof k)&&a.length>0&&r.length>0){var u=s.slice();u.splice(c,1);var p=u.concat(r).concat(a);return s[c].tex()+new h(p).tex()}}if(0===(s=e.default.compact(e.default.map(s,(function(t){var n=t instanceof _&&!(t instanceof k),i=!t.hints.fraction||r.length>0;if(n&&i){r.push(new f(new k(t.d),b.Div));var s=new k(t.n);return s.hints=t.hints,e.default.any(t.hints)?s:null}return t})))).length&&1===a.length)t=a[0].tex();else{var d="";e.default.each(s,(function(t){t.hints.subtract&&t.hints.entered?(o+="-",d+=(d?n:"")+t.abs().tex()):t instanceof k&&-1===t.n&&(t.hints.negate||t.hints.subtract)?o+="-":d+=(d?n:"")+t.tex()})),e.default.each(a,(function(t){t.needsExplicitMul()?d+=(d?n:"")+t.tex():d+=t instanceof l?"("+t.tex()+")":t.tex()})),t=d||"1"}if(r.length){var y=new h(e.default.invoke(r,"asDivide")).flatten().tex();return o+"\\frac{"+t+"}{"+y+"}"}return o+t},strip:function(){return new h(e.default.map(this.terms,(function(t){return t instanceof b?t.abs():t.strip()}))).flatten()},expand:function(){var t=function(t){return t instanceof l},n=function(t){return t instanceof f&&t.exp.isNegative()},i=this.recurse("expand").flatten(),r=e.default.any(i.terms,t),s=e.default.any(i.terms,(function(e){return n(e)&&t(e.base)}));if(!r&&!s)return i;var a=e.default.groupBy(i.terms,n),o=a[!1]||[],c=a[!0]||[];if(r){var u=e.default.groupBy(o,t),p=u[!0]||[],d=u[!1]||[],y=e.default.reduce(p,(function(t,n){return e.default.reduce(t,(function(t,i){return t.concat(e.default.map(n.terms,(function(t){return i.concat(t)})))}),[])}),[[]]);o=[new l(e.default.map(y,(function(t){return new h(d.concat(t)).flatten()})))]}s&&(c=[new f(new h(e.default.invoke(c,"getDenominator")).flatten().expand(),b.Div)]);return new h(o.concat(c)).flatten()},factor:function(t){var n=this.recurse("factor",t).flatten();if(!(n instanceof h))return n;var i=e.default.groupBy(n.terms,(function(t){return t instanceof _})),r=e.default.reduce(i[!0],(function(t,e){return{n:t.n*e.n,d:t.d*e.d}}),{n:1,d:1});return r=1===r.d?new k(r.n):new _(r.n,r.d),new h((i[!1]||[]).concat(r)).flatten()},collect:function(t){var n=this.recurse("collect",t).partition(),i=n[0].reduce(t);if(0===i.eval())return b.Zero;var r=n[1].flatten();if(!(r instanceof h))return new h(i,r).flatten();r=r.terms;var s=[];e.default.each(r,(function(t){t instanceof f?s.push([t.base,t.exp]):s.push([t,b.One])}));var a=e.default.groupBy(s,(function(t){return t[0].normalize().print()})),o=e.default.compact(e.default.map(a,(function(n){var i=n[0][0],r=new l(e.default.zip.apply(e.default,n)[1]).collect(t);return r instanceof b&&0===r.eval()?null:[i,r]}))),c=(s=e.default.groupBy(o,(function(t){return t[0]instanceof d&&t[0].isBasic()?"trig":t[0]instanceof p?"log":"expr"}))).trig||[],u=s.log||[],y=s.expr||[];if(c.length>1){var g=e.default.groupBy(c,(function(t){return t[0].arg.normalize().print()}));c=[],e.default.each(g,(function(n){var i=n[0][0].arg,r={sin:b.Zero,cos:b.Zero};e.default.each(n,(function(t){r[t[0].type]=t[1]})),h.handleNegative(r.sin).collect(t).equals(r.cos)&&(r=r.cos.isNegative()?{tan:r.sin}:{cot:r.cos}),e.default.each(r,(function(t,e){c.push([new d(e,i),t])}))}))}if(u.length>1){var m=e.default.groupBy(u,(function(t){return t[0].base.normalize().print()}));u=[],e.default.each(m,(function(e){2===e.length&&h.handleNegative(e[0][1]).collect(t).equals(e[1][1])?e[0][1].isNegative()?u.push([new p(e[0][0].power,e[1][0].power),e[1][1]]):u.push([new p(e[1][0].power,e[0][0].power),e[0][1]]):u=u.concat(e)}))}s=c.concat(u).concat(y);var v=e.default.map(s,(function(e){return new f(e[0],e[1]).collect(t)}));return new h([i].concat(v)).flatten()},isSubtract:function(){return e.default.any(this.terms,(function(t){return t instanceof b&&t.hints.subtract}))},factorIn:function(t){var n=this.partition()[0].terms,i=n.length&&e.default.all(n,(function(t){return t.n>0}));if(i){var r=n[0].negate();return r.hints=n[0].hints,this.replace(n[0],r.addHint(t))}return new h([b.negativeOne(t)].concat(this.terms))},factorOut:function(){var t=!1,n=e.default.compact(e.default.map(this.terms,(function(e,n,i){return!t&&e instanceof b&&e.hints.divide?(t=!0,-1!==e.n?e.negate():null):e})));return 1===n.length?n[0]:new h(n)},reduce:function(t){return e.default.reduce(this.terms,(function(e,n){return e.mul(n,t)}),this.identity)},findGCD:function(t){return new h(e.default.invoke(this.terms,"findGCD",t)).flatten()},asMul:function(){return this},asPositiveFactor:function(){return this.isPositive()?this:new h(e.default.invoke(this.collect().terms,"asPositiveFactor")).flatten()},isNegative:function(){return e.default.any(e.default.invoke(this.collect().terms,"isNegative"))},fold:function(){return h.fold(this)},negate:function(){var t=function(t){return t instanceof b};if(e.default.any(this.terms,t)){var n=e.default.find(this.terms,t);return this.replace(n,n.negate())}return new h([b.Neg].concat(this.terms))}}),e.default.each([l,h],(function(t){e.default.extend(t,{createOrAppend:function(e,n){return e instanceof t?new t(e.terms.concat(n)):new t(e,n)}})})),e.default.extend(h,{handleNegative:function(t,e){if(t instanceof b&&t.n>0){var n=t.negate();return n.hints=t.hints,n.addHint(e)}return t instanceof h?t.factorIn(e):new h(b.negativeOne(e),t)},handleDivide:function(t,n){if(n instanceof h){var i=h.handleDivide(t,n.terms[0]),r=new h(e.default.rest(n.terms)).flatten();return h.handleDivide(i,r)}var s=function(t){return t instanceof k};if(s(n)&&t instanceof h&&e.default.any(t.terms,s)){var a=t.terms.slice().reverse(),o=e.default.find(a,(function(t){return t instanceof _}));if(!s(o))return new h(t.terms.concat([new _(1,n.n).addHint("fraction")]));var c=new _(o.n,n.n);return c.hints=o.hints,o===a[0]&&(c=c.addHint("fraction")),o.n<0&&n.n<0?(c.d=-c.d,t.replace(o,[b.Neg,c])):t.replace(o,c)}var u=function(t,e){if(e instanceof k){if(t instanceof k)return t.n<0&&e.n<0?[b.Neg,new _(t.n,-e.n).addHint("fraction")]:[new _(t.n,e.n).addHint("fraction")];var n=new _(1,e.eval());return e.eval()<0?[t,n.addHint("negate")]:[t,n]}var i;if(e instanceof d&&e.exp){var r=e.exp;e.exp=void 0,e=new f(e,r)}return i=e instanceof f?new f(e.base,h.handleNegative(e.exp,"divide")):new f(e,b.Div),t instanceof k&&1===t.n?[i]:[t,i]};if(t instanceof h){var l=u(e.default.last(t.terms),n);return new h(e.default.initial(t.terms).concat(l))}return new h(l=u(t,n)).flatten()},fold:function(t){if(t instanceof h){var n=e.default.find(e.default.initial(t.terms),(function(t){return(t instanceof d||t instanceof p)&&t.hints.open})),i=e.default.indexOf(t.terms,n);if(n){var r,s=e.default.last(t.terms);if(!(n.hints.parens||s.hints.parens||s.has(d)||s.has(p)))return r=n instanceof d?d.create([n.type,n.exp],h.createOrAppend(n.arg,s).fold()):p.create(n.base,h.createOrAppend(n.power,s).fold()),0===i?r:new h(t.terms.slice(0,i).concat(r)).fold();n.hints.open=!1}var a=t.partition()[0].terms,o=function(t){return t.n>0},c=function(t){return-1===t.n&&t.hints.negate};if(a.length>1&&e.default.some(a,c)&&e.default.some(a,o)&&e.default.every(a,(function(t){return o(t)||c(t)}))){var u=e.default.indexOf(t.terms,e.default.find(t.terms,c)),l=e.default.indexOf(t.terms,e.default.find(t.terms,o));if(u<l)return t.replace(l,t.terms[l].negate()).remove(u)}}return t}}),f.prototype=new c,e.default.extend(f.prototype,{func:f,args:function(){return[this.base,this.exp]},eval:function(t,e){var n=this.base.eval(t,e),i=this.exp.eval(t,e);if(n<0){var r=this.exp.simplify();if(r instanceof M){var s=r.n,a=(s-s.toFixed()).toString().length-2,o=Math.pow(10,a);r=new _(s*o,o).simplify()}if(r instanceof _)if(Math.abs(r.d)%2==1)return(Math.abs(r.n)%2==1?-1:1)*Math.pow(-1*n,i)}return Math.pow(n,i)},getUnits:function(){return this.base.getUnits().map(function(t){return{unit:t.unit,pow:t.pow*this.exp.n}}.bind(this))},codegen:function(){return"Math.pow("+this.base.codegen()+", "+this.exp.codegen()+")"},print:function(){var t=this.base.print();return(this.base instanceof u||this.base instanceof f)&&(t="("+t+")"),t+"^("+this.exp.print()+")"},tex:function(){if(this.isDivide())return"\\frac{1}{"+this.asDivide().tex()+"}";if(this.isRoot())return 1!==this.exp.n&&a("Node marked with hint 'root' does not have exponent of form 1/x."),2===this.exp.d?"\\sqrt{"+this.base.tex()+"}":"\\sqrt["+this.exp.d+"]{"+this.base.tex()+"}";if(this.base instanceof d&&!this.base.isInverse()&&this.exp instanceof b&&this.exp.isSimple()&&this.exp.eval()>=0){var t=this.base.tex({split:!0});return t[0]+"^{"+this.exp.tex()+"}"+t[1]}var e=this.base.tex();return this.base instanceof u||this.base instanceof f||this.base instanceof b&&!this.base.isSimple()?e="("+e+")":(this.base instanceof d||this.base instanceof p)&&(e="["+e+"]"),e+"^{"+this.exp.tex()+"}"},needsExplicitMul:function(){return!this.isRoot()&&this.base.needsExplicitMul()},expand:function(){var t=this.recurse("expand");if(t.base instanceof h)return new h(e.default.map(t.base.terms,(function(e){return new f(e,t.exp)}))).expand();if(t.base instanceof l&&t.exp instanceof k&&t.exp.abs().eval()>1){for(var n=t.exp.eval()>0,i=t.exp.abs().eval(),r=function(t){return n?t:new f(t,b.Div)},s={1:t.base},a=2;a<=i;a*=2){var o=new h(s[a/2],s[a/2]);s[a]=o.expand().collect()}if(e.default.has(s,i))return r(s[i]);var c=e.default.map(i.toString(2).split(""),(function(t,e,n){return Number(t)*Math.pow(2,n.length-e-1)}));return c=e.default.without(c,0),r(o=new h(e.default.pick(s,c)).expand().collect())}return t.exp instanceof l?new h(e.default.map(t.exp.terms,(function(e){return new f(t.base,e).expand()}))).expand():t},factor:function(){var t=this.recurse("factor");return t.base instanceof h?new h(e.default.map(t.base.terms,(function(e){return e instanceof k&&t.exp.equals(b.Div)?new _(1,e.n):new f(e,t.exp)}))):t},collect:function(t){if(this.base instanceof f)return new f(this.base.base,s=h.createOrAppend(this.base.exp,this.exp)).collect(t);var n=this.recurse("collect",t),i=function(t){return t instanceof p&&t.base.equals(n.base)};if(n.exp instanceof b&&0===n.exp.eval())return b.One;if(n.exp instanceof b&&1===n.exp.eval())return n.base;if(i(n.exp))return n.exp.power;if(n.exp instanceof h&&e.default.any(n.exp.terms,i)){var r=e.default.find(n.exp.terms,i);return new f(r.power,s=n.exp.remove(r).flatten()).collect(t)}if(n.base instanceof b&&n.exp instanceof b){if(t&&t.preciseFloats){var s=n.exp.asRational(),a=n.base.getDecimalPlaces();if(new f(n.base,new _(1,s.d)).collect().getDecimalPlaces()>a){var o=new f(n.base,new k(s.n)).collect();return new f(o,new _(1,s.d))}}return n.base.raiseToThe(n.exp,t)}return n},isDivide:function(){var t=function(t){return t instanceof b&&t.hints.divide};return t(this.exp)||this.exp instanceof h&&e.default.any(this.exp.terms,t)},asDivide:function(){if(this.exp instanceof b){if(-1===this.exp.eval())return this.base;var t=this.exp.negate();return t.hints=e.default.clone(this.exp.hints),t.hints.divide=!1,new f(this.base,t)}if(this.exp instanceof h)return new f(this.base,this.exp.factorOut());a("called asDivide() on an Expr that wasn't a Num or Mul")},isRoot:function(){return this.exp instanceof _&&this.exp.hints.root},isSquaredTrig:function(){return this.base instanceof d&&!this.base.isInverse()&&this.exp instanceof b&&2===this.exp.eval()},getDenominator:function(){if(this.exp instanceof b&&-1===this.exp.eval())return h.createOrAppend(this.base,this.base.getDenominator()).flatten();if(this.exp.isNegative()){var t=new f(this.base,h.handleNegative(this.exp).collect());return h.createOrAppend(t,t.collect().getDenominator()).flatten()}return this.base instanceof b?new f(this.base.getDenominator(),this.exp).collect():b.One},findGCD:function(t){var e,n;if(t instanceof f?(e=t.base,n=t.exp):(e=t,n=b.One),this.base.equals(e)){if(this.exp.equals(n))return this;if(this.exp instanceof b&&n instanceof b)return new f(this.base,b.min(this.exp,n)).collect();if(this.exp instanceof b||n instanceof b)return b.One;var i=this.exp.asMul().partition(),r=n.asMul().partition();if(i[1].equals(r[1]))return new f(e,new h(b.min(i[0].reduce(),r[0].reduce()),i[1].flatten()).flatten()).collect()}return b.One},isPositive:function(){if(this.base.isPositive())return!0;var t=this.exp.simplify();return t instanceof k&&t.eval()%2==0},asPositiveFactor:function(){if(this.isPositive())return this;var t=this.exp.simplify();if(t instanceof k){var e=t.eval();if(e>2)return new f(this.base,new k(e-1));if(e<-2)return new f(this.base,new k(e+1))}return b.One}}),e.default.extend(f,{sqrt:function(t){return new f(t,b.Sqrt)},nthroot:function(t,e){return new f(t,h.fold(h.handleDivide(new k(1),e)).addHint("root"))}}),p.prototype=new c,e.default.extend(p.prototype,{func:p,args:function(){return[this.base,this.power]},eval:function(t,e){return Math.log(this.power.eval(t,e))/Math.log(this.base.eval(t,e))},codegen:function(){return"(Math.log("+this.power.codegen()+") / Math.log("+this.base.codegen()+"))"},print:function(){var t="("+this.power.print()+")";return this.isNatural()?"ln"+t:"log_("+this.base.print()+") "+t},tex:function(){var t="("+this.power.tex()+")";return this.isNatural()?"\\ln"+t:"\\log_{"+this.base.tex()+"}"+t},collect:function(t){var e=this.recurse("collect",t);return e.power instanceof b&&1===e.power.eval()?b.Zero:e.base.equals(e.power)?b.One:e.power instanceof f&&e.power.base.equals(e.base)?e.power.exp:e},expand:function(){var t=this.recurse("expand");return t.power instanceof h?new l(e.default.map(t.power.terms,(function(e){return new p(t.base,e).expand()}))):t.power instanceof f?new h(t.power.exp,new p(t.base,t.power.base).expand()).flatten():t.isNatural()?t:h.handleDivide(new p(w.e,t.power),new p(w.e,t.base))},hints:e.default.extend(p.prototype.hints,{open:!1}),isPositive:function(){var t=this.collect();return t.base instanceof b&&t.power instanceof b&&this.eval()>0},needsExplicitMul:function(){return!1},isNatural:function(){return this.base.equals(w.e)}}),e.default.extend(p,{natural:function(){return w.e},common:function(){return b.Ten},create:function(t,e){var n=new p(t,e);return e.hints.parens||(n=n.addHint("open")),n}}),d.prototype=new c,e.default.extend(d.prototype,{func:d,args:function(){return[this.type,this.arg]},functions:{sin:{eval:Math.sin,codegen:"Math.sin((",tex:"\\sin",expand:function(){return this}},cos:{eval:Math.cos,codegen:"Math.cos((",tex:"\\cos",expand:function(){return this}},tan:{eval:Math.tan,codegen:"Math.tan((",tex:"\\tan",expand:function(){return h.handleDivide(d.sin(this.arg),d.cos(this.arg))}},csc:{eval:function(t){return 1/Math.sin(t)},codegen:"(1/Math.sin(",tex:"\\csc",expand:function(){return h.handleDivide(b.One,d.sin(this.arg))}},sec:{eval:function(t){return 1/Math.cos(t)},codegen:"(1/Math.cos(",tex:"\\sec",expand:function(){return h.handleDivide(b.One,d.cos(this.arg))}},cot:{eval:function(t){return 1/Math.tan(t)},codegen:"(1/Math.tan(",tex:"\\cot",expand:function(){return h.handleDivide(d.cos(this.arg),d.sin(this.arg))}},arcsin:{eval:Math.asin,codegen:"Math.asin((",tex:"\\arcsin"},arccos:{eval:Math.acos,codegen:"Math.acos((",tex:"\\arccos"},arctan:{eval:Math.atan,codegen:"Math.atan((",tex:"\\arctan"},arccsc:{eval:function(t){return Math.asin(1/t)},codegen:"Math.asin(1/(",tex:"\\operatorname{arccsc}"},arcsec:{eval:function(t){return Math.acos(1/t)},codegen:"Math.acos(1/(",tex:"\\operatorname{arcsec}"},arccot:{eval:function(t){return Math.atan(1/t)},codegen:"Math.atan(1/(",tex:"\\operatorname{arccot}"},sinh:{eval:function(t){return(Math.exp(t)-Math.exp(-t))/2},codegen:function(t){return"((Math.exp("+t+") - Math.exp(-("+t+"))) / 2)"},tex:"\\sinh",expand:function(){return this}},cosh:{eval:function(t){return(Math.exp(t)+Math.exp(-t))/2},codegen:function(t){return"((Math.exp("+t+") + Math.exp(-("+t+"))) / 2)"},tex:"\\cosh",expand:function(){return this}},tanh:{eval:function(t){return(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))},codegen:function(t){return"((Math.exp("+t+") - Math.exp(-("+t+"))) / (Math.exp("+t+") + Math.exp(-("+t+"))))"},tex:"\\tanh",expand:function(){return h.handleDivide(d.sinh(this.arg),d.cosh(this.arg))}},csch:{eval:function(t){return 2/(Math.exp(t)-Math.exp(-t))},codegen:function(t){return"(2 / (Math.exp("+t+") - Math.exp(-("+t+"))))"},tex:"\\csch",expand:function(){return h.handleDivide(b.One,d.sinh(this.arg))}},sech:{eval:function(t){return 2/(Math.exp(t)+Math.exp(-t))},codegen:function(t){return"(2 / (Math.exp("+t+") + Math.exp(-("+t+"))))"},tex:"\\sech",expand:function(){return h.handleDivide(b.One,d.cosh(this.arg))}},coth:{eval:function(t){return(Math.exp(t)+Math.exp(-t))/(Math.exp(t)-Math.exp(-t))},codegen:function(t){return"((Math.exp("+t+") + Math.exp(-("+t+"))) / (Math.exp("+t+") - Math.exp(-("+t+"))))"},tex:"\\coth",expand:function(){return h.handleDivide(d.cosh(this.arg),d.sinh(this.arg))}}},isEven:function(){return e.default.contains(["cos","sec"],this.type)},isInverse:function(){return 0===this.type.indexOf("arc")},isBasic:function(){return e.default.contains(["sin","cos"],this.type)},eval:function(t,e){return(0,this.functions[this.type].eval)(this.arg.eval(t,e))},codegen:function(){var t=this.functions[this.type].codegen;if("function"==typeof t)return t(this.arg.codegen());if("string"==typeof t)return t+this.arg.codegen()+"))";throw new Error("codegen not implemented for "+this.type)},print:function(){return this.type+"("+this.arg.print()+")"},tex:function(t){var e=this.functions[this.type].tex,n="("+this.arg.tex()+")";return t&&t.split?[e,n]:e+n},hints:e.default.extend(d.prototype.hints,{open:!1}),isPositive:function(){return this.collect().arg instanceof b&&this.eval()>0},completeParse:function(){if(this.exp){var t=new f(this,this.exp);return this.exp=void 0,t}return this},needsExplicitMul:function(){return!1},expand:function(){var t=this.recurse("expand");if(t.isInverse())return t;var n=t.functions[t.type].expand;return e.default.bind(n,t)()},collect:function(t){var e,n=this.recurse("collect",t);return!n.isInverse()&&n.arg.isNegative()?(e=n.arg instanceof b?n.arg.abs():h.handleDivide(n.arg,b.Neg).collect(t),n.isEven()?new d(n.type,e):new h(b.Neg,new d(n.type,e))):n}}),e.default.extend(d,{create:function(t,e){var n=t[0],i=t[1];i&&i.equals(b.Neg)&&(n="arc"+n,i=void 0);var r=new d(n,e);return e.hints.parens||(r=r.addHint("open")),i&&(r.exp=i),r},sin:function(t){return new d("sin",t)},cos:function(t){return new d("cos",t)},sinh:function(t){return new d("sinh",t)},cosh:function(t){return new d("cosh",t)}}),y.prototype=new c,e.default.extend(y.prototype,{func:y,args:function(){return[this.arg]},eval:function(t,e){return Math.abs(this.arg.eval(t,e))},codegen:function(){return"Math.abs("+this.arg.codegen()+")"},print:function(){return"abs("+this.arg.print()+")"},tex:function(){return"\\left|"+this.arg.tex()+"\\right|"},collect:function(t){var n=this.recurse("collect",t);if(n.arg.isPositive())return n.arg;if(n.arg instanceof b)return n.arg.abs();if(n.arg instanceof h){var i=e.default.groupBy(n.arg.terms,(function(t){return t.isPositive()?"positive":t instanceof b?"number":"other"})),r=i.positive.concat(e.default.invoke(i.number,"abs"));return i.other.length&&r.push(new y(new h(i.other).flatten())),new h(r).flatten()}return n},expand:function(){var t=this.recurse("expand");return t.arg instanceof h?new h(e.default.map(t.arg.terms,(function(t){return new y(t)}))):t},isPositive:function(){return!0}}),g.prototype=new c,e.default.extend(g.prototype,{func:g,args:function(){return[this.left,this.type,this.right]},needsExplicitMul:function(){return!1},print:function(){return this.left.print()+this.type+this.right.print()},signs:{"=":" = ","<":" < ",">":" > ","<>":" \\ne ","<=":" \\le ",">=":" \\ge "},tex:function(){return this.left.tex()+this.signs[this.type]+this.right.tex()},normalize:function(){var t=this.recurse("normalize");return e.default.contains([">",">="],t.type)?new g(t.right,t.type.replace(">","<"),t.left):t},asExpr:function(t){var n=function(t){return t instanceof b&&t.isSimple()&&0===t.eval()},i=[];this.left instanceof l?i=e.default.clone(this.left.terms):n(this.left)||(i=[this.left]),this.right instanceof l?i=i.concat(this.right.negate().terms):n(this.right)||i.push(this.right.negate());var r=!this.isEquality();i=e.default.invoke(i,"collect",{preciseFloats:!0});for(var s=0;s<i.length;s++){var a=i[s].getDenominator();r&&!a.isPositive()&&(a=a.asPositiveFactor()),a.equals(b.One)||(i=e.default.map(i,(function(t){return h.createOrAppend(t,a).simplify({once:!0,preciseFloats:!0})})))}var o=new l(i).flatten();return t?o:this.divideThrough(o)},divideThrough:function(t){var n=!this.isEquality(),i=t.simplify({once:!0}),r=i.factor({keepNegative:n});if(!(r instanceof h))return t;var s=r.terms,a=e.default.groupBy(s,(function(t){return t instanceof l})),o=a[!0]||[],c=a[!1]||[];if(o.length&&this.isEquality())return new h(o).flatten();var u=c;o.length||(u=e.default.reject(u,(function(t){return!!t.getVars().length}))),n&&(u=e.default.invoke(u,"asPositiveFactor")),u=e.default.reject(u,(function(t){return t.equals(b.One)})),u=e.default.map(u,(function(t){return new f(t,b.Div)}));var p=new h(s.concat(u)).collect();return p.equals(r)?i:p},isEquality:function(){return e.default.contains(["=","<>"],this.type)},compare:function(t){if(!(t instanceof g))return!1;var e=this.normalize(),n=t.normalize();if(e.type!==n.type)return!1;var i=e.divideThrough(e.asExpr(!0).collect()),r=n.divideThrough(n.asExpr(!0).collect());return e.isEquality()?i.compare(r)||i.compare(h.handleNegative(r)):i.compare(r)},sameForm:function(t){var e=this.normalize(),n=t.normalize(),i=e.left.sameForm(n.left)&&e.right.sameForm(n.right);return e.isEquality()?i||e.left.sameForm(n.right)&&e.right.sameForm(n.left):i},isSimplified:function(){var t=this.asExpr(!0),e=this.divideThrough(t).simplify();return t.equals(e)&&this.left.isSimplified()&&this.right.isSimplified()}}),e.default.extend(g.prototype,{solveLinearEquationForVariable:function(t){var n=this.asExpr();if(!n.is(l)||2!==n.terms.length)throw new Error("Can only handle linear equations of the form a + bx (= 0)");var i,r,s;return(s=n.terms[0]).has(x)&&e.default.contains(s.getVars(),t.symbol)?(i=h.handleNegative(n.terms[1]),r=h.handleDivide(n.terms[0],t)):(i=h.handleNegative(n.terms[0]),r=h.handleDivide(n.terms[1],t)),h.handleDivide(i,r).simplify()}}),m.prototype=new c,e.default.extend(m.prototype,{needsExplicitMul:function(){return!1},findGCD:function(t){return t instanceof m||t instanceof b?this.equals(t)?this:b.One:t.findGCD(this)}}),v.prototype=new m,e.default.extend(v.prototype,{func:v,args:function(){return[this.symbol,this.arg]},print:function(){return this.symbol+"("+this.arg.print()+")"},tex:function(){return this.symbol+"("+this.arg.tex()+")"},eval:function(t,n){var i=this.arg,r=t[this.symbol],s=e.default.extend(e.default.clone(t),{x:i.eval(t,n)}),a=E(r,n);return a.parsed?a.expr.eval(s,n):a},codegen:function(){return'vars["'+this.symbol+'"]('+this.arg.codegen()+")"},getUnits:function(){return this.arg.getUnits()},getVars:function(t){return t?this.arg.getVars():e.default.union(this.arg.getVars(),[this.symbol]).sort()},getConsts:function(){return this.arg.getConsts()}}),x.prototype=new m,e.default.extend(x.prototype,{func:x,args:function(){return[this.symbol,this.subscript]},exprArgs:function(){return[]},recurse:function(){return this},print:function(){var t="";return this.subscript&&(t="_("+this.subscript.print()+")"),this.symbol+t},prettyPrint:function(){var t=this.subscript;return t&&(t instanceof b||t instanceof m)?this.symbol+"_"+t.print():this.print()},tex:function(){var t="";return this.subscript&&(t="_{"+this.subscript.tex()+"}"),(this.symbol.length>1?"\\":"")+this.symbol+t},repr:function(){return"Var("+this.print()+")"},eval:function(t,e){return t[this.prettyPrint()]},codegen:function(){return'vars["'+this.prettyPrint()+'"]'},getVars:function(){return[this.prettyPrint()]},isPositive:function(){return!1}}),w.prototype=new m,e.default.extend(w.prototype,{func:w,args:function(){return[this.symbol]},recurse:function(){return this},eval:function(t,e){return"pi"===this.symbol?Math.PI:"e"===this.symbol?Math.E:void 0},codegen:function(){return"pi"===this.symbol?"Math.PI":"e"===this.symbol?"Math.E":void 0},print:function(){return this.symbol},tex:function(){return"pi"===this.symbol?"\\pi ":"e"===this.symbol?"e":void 0},isPositive:function(){return this.eval()>0},abs:function(){return this.eval()>0?this:h.handleNegative(this)},getConsts:function(){return[this.print()]}}),w.e=new w("e"),w.pi=new w("pi"),b.prototype=new c,e.default.extend(b.prototype,{repr:function(){return this.print()},strip:function(){return this.abs()},recurse:function(){return this},codegen:function(){return this.print()},add:s,mul:s,negate:s,isSubtract:function(){return this.hints.subtract},abs:s,needsExplicitMul:function(){return!0},findGCD:s,isPositive:function(){return this.eval()>0},isNegative:function(){return this.eval()<0},asPositiveFactor:function(){return this.isPositive()?this:this.abs()},hints:e.default.extend(b.prototype.hints,{negate:!1,subtract:!1,divide:!1,root:!1,fraction:!1,entered:!1}),isSimple:s,getDecimalPlaces:function(){var t=(""+this.n).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0},asRational:s}),_.prototype=new b,e.default.extend(_.prototype,{func:_,args:function(){return[this.n,this.d]},eval:function(){return this.n/this.d},print:function(){return this.n.toString()+"/"+this.d.toString()},tex:function(){var t="\\frac{"+Math.abs(this.n).toString()+"}{"+this.d.toString()+"}";return this.n<0?"-"+t:t},add:function(t,e){return t instanceof _?new _(this.n*t.d+this.d*t.n,this.d*t.d).collect():t.add(this,e)},mul:function(t,e){return t instanceof _?new _(this.n*t.n,this.d*t.d).collect():t.mul(this,e)},collect:function(){var t=b.findGCD(this.n,this.d),e=this.n/t,n=this.d/t;return 1===n?new k(e):new _(e,n)},negate:function(){return new _(-this.n,this.d)},abs:function(){return new _(Math.abs(this.n),this.d)},findGCD:function(t){return t instanceof _?new _(b.findGCD(this.n*t.d,t.n*this.d),this.d*t.d).collect():t instanceof k?new _(b.findGCD(this.n,t.n),this.d):t.findGCD(this)},raiseToThe:function(t){if(t instanceof k){var e=t.eval()>0,n=t.abs().eval(),i=Math.pow(this.n,n),r=Math.pow(this.d,n);return e?new _(i,r).collect():new _(r,i).collect()}return new M(this.eval()).raiseToThe(t)},getDenominator:function(){return new k(this.d)},isSimple:function(){return!1},asRational:function(){return this}}),k.prototype=new _(0,1),e.default.extend(k.prototype,{func:k,args:function(){return[this.n]},print:function(){return this.n.toString()},tex:function(){return this.n.toString()},negate:function(){return new k(-this.n)},abs:function(){return new k(Math.abs(this.n))},isSimple:function(){return!0},findGCD:function(t){return t instanceof k?new k(b.findGCD(this.n,t.n)):t.findGCD(this)}}),e.default.extend(k,{create:function(t){return new k(t).addHint("entered")}}),M.prototype=new b,e.default.extend(M.prototype,{func:M,args:function(){return[this.n]},eval:function(){return this.n},print:function(){return this.n.toString()},tex:function(){return this.n.toString()},add:function(t,e){return e&&e.preciseFloats?M.toDecimalPlaces(this.n+t.eval(),Math.max(this.getDecimalPlaces(),t.getDecimalPlaces())):new M(this.n+t.eval()).collect()},mul:function(t,e){return e&&e.preciseFloats?M.toDecimalPlaces(this.n*t.eval(),this.getDecimalPlaces()+t.getDecimalPlaces()):new M(this.n*t.eval()).collect()},collect:function(){return this},negate:function(){return new M(-this.n)},abs:function(){return new M(Math.abs(this.n))},findGCD:function(t){return t instanceof b?new M(b.findGCD(this.eval(),t.eval())).collect():t.findGCD(this)},raiseToThe:function(t,e){return e&&e.preciseFloats&&t instanceof k&&t.n>1?M.toDecimalPlaces(new f(this,t).eval(),this.getDecimalPlaces()*t.n):new M(new f(this,t).eval()).collect()},asRational:function(){var t=this.n.toString().split(".");return 1===t.length?new _(this.n,1):new _(Number(t.join("")),Math.pow(10,t[1].length)).collect()},getDenominator:function(){return this.asRational().getDenominator()},isSimple:function(){return!0}}),e.default.extend(M,{create:function(t){return new M(t).addHint("entered")},toDecimalPlaces:function(t,e){return new M(+t.toFixed(Math.min(e,20))).collect()}}),e.default.extend(b,{negativeOne:function(t){return"subtract"===t?b.Sub:"divide"===t?b.Div:b.Neg},findGCD:function(t,e){var n;if(t=Math.abs(t),e=Math.abs(e),t!==Math.floor(t)||e!==Math.floor(e))return 1;for(;e;)n=t%e,t=e,e=n;return t},min:function(){return e.default.min(e.default.toArray(arguments),(function(t){return t.eval()}))},max:function(){return e.default.max(e.default.toArray(arguments),(function(t){return t.eval()}))}}),b.Neg=new k(-1).addHint("negate"),b.Sub=new k(-1).addHint("subtract"),b.Div=new k(-1).addHint("divide"),b.Sqrt=new _(1,2).addHint("root"),b.Zero=new k(0),b.One=new k(1),b.Ten=new k(10),l.prototype.identity=b.Zero,h.prototype.identity=b.One;r.yy={Add:l,Mul:h,Pow:f,Log:p,Trig:d,Eq:g,Abs:y,Func:v,Const:w,Var:x,Int:k,Float:M,parseError:function(t,e){throw new Error(e.loc.first_column)},constants:["e"],symbolLexer:function(t){return e.default.contains(r.yy.constants,t)?"CONST":e.default.contains(r.yy.functions,t)?"FUNC":"VAR"}};const E=function(t,n){try{return n&&n.functions?r.yy.functions=e.default.without(n.functions,"i"):r.yy.functions=[],n&&n.decimal_separator&&(t=t.split(n.decimal_separator).join(".")),{parsed:!0,expr:r.parse(t).completeParse()}}catch(t){return{parsed:!1,error:t.message}}};function I(t){this.symbol=t}I.prototype=new m;var S=function(t){if(e.default(D).has(t)||e.default(T).has(t))return new I(t);var n=e.default(e.default(A).keys()).find((function(e){return new RegExp("^"+e).test(t)}));if(n){var i=t.replace(new RegExp("^"+n),"");if(e.default(D).has(i)||T[i]&&T[i].prefixes===N)return new h(A[n],new I(i));throw new Error(i+" does not allow prefixes")}return new I(t)};e.default.extend(I.prototype,{func:I,args:function(){return[this.symbol]},recurse:function(){return this},eval:function(t,e){return 1},getUnits:function(){return[{unit:this.symbol,pow:1}]},codegen:function(){return"1"},print:function(){return this.symbol},tex:function(){return this.symbol},collect:function(t){if(e.default(D).has(this.symbol))return this;if(e.default(T).has(this.symbol))return T[this.symbol].conversion;throw new Error("could not understand unit: "+this.symbol)}});var D={m:new I("m"),g:new I("g"),s:new I("s"),A:new I("A"),K:new I("K"),mol:new I("mol"),cd:new I("cd")},A={a:new f(new k(10),new k(-18)),f:new f(new k(10),new k(-15)),p:new f(new k(10),new k(-12)),n:new f(new k(10),new k(-9)),u:new f(new k(10),new k(-6)),m:new f(new k(10),new k(-3)),c:new f(new k(10),new k(-2)),d:new f(new k(10),new k(-1)),da:new k(10),h:new f(new k(10),new k(2)),k:new f(new k(10),new k(3)),M:new f(new k(10),new k(6)),G:new f(new k(10),new k(9)),T:new f(new k(10),new k(12)),P:new f(new k(10),new k(15)),E:new f(new k(10),new k(18)),hella:new f(new k(10),new k(27))},N={},O={},P=function(t,e){var n=t.split("|"),i=n[0].trim(),r=n[1].trim(),s=b.One;""!==i&&(s=E(i).expr);var a=r.split("/"),o=[s];return a[0]&&a[0].split(" ").filter((function(t){return""!==t})).map((function(t){o.push(new I(t))})),a[1]&&a[1].split(" ").filter((function(t){return""!==t})).map((function(t){o.push(new f(new I(t),b.Div))})),{conversion:new h(o),prefixes:e}},T={Da:P("1.6605388628 x 10^-24 | g",N),u:P("| Da",O),meter:P("| m",O),meters:P("| m",O),in:P("254 / 10000 | m",O),ft:P("3048 / 10000 | m",O),yd:P("9144 / 10000 | m",O),mi:P("1609344 / 1000 | m",O),ly:P("9.4607 x 10^15 | m",O),nmi:P("1852 | m",O),"Å":P("10^-10 | m",O),pc:P("3.0857 x 10^16 | m",O),min:P("60 | s",O),hr:P("3600 | s",O),sec:P("| s",O),day:P("86400 | s",O),wk:P("604800 | s",O),fortnight:P("14 | day",O),shake:P("10^-8 | s",O),olympiad:P("126200000 | s",O),"°C":P("1 | K",O),"°F":P("5/9 | K",O),"°R":P("5/9 | K",O),e:P("1.6021765314 x 10^-19 | C",O),c:P("299792458 | m / s",O),kn:P("514/1000 | m / s",O),kt:P("| kn",O),knot:P("| kn",O),J:P("| N m",N),BTU:P("1060 | J",O),cal:P("4184 / 1000 | J",N),eV:P("1.602176514 x 10^-19 | J",N),erg:P("10^−7 | J",N),W:P("| J / s",N),"H-e":P("80 | W",O),N:P("1000 | g m / s s",N),lb:P("4448221615 / 1000000000 | N",O),dyn:P("10^-5 | N",O),Pa:P("1 | N / m m m",N),bar:P("10^5 | Pa",N),"㏔":P("1/1000 | bar",O),"㍴":P("| bar",O),atm:P("101325 | Pa",O),Torr:P("1/760 | atm",O),mmHg:P("| Torr",O),ha:P("10^4 | m m",O),b:P("10^−28 | m m",N),barn:P("| b",N),acre:P("4046.87 | m m",O),skilodge:P("10^-31 | m m",O),outhouse:P("10^-34 | m m",O),shed:P("10^-52 | m m",O),L:P("1/1000 | m m m",N),gal:P("3785/1000 | L",N),cup:P("1/16 | gal",O),qt:P("1/4 | gal",O),quart:P("| qt",O),p:P("1/8 | gal",O),pt:P("| p",O),pint:P("| p",O),"fl oz":P("1/8 | cup",O),"fl. oz.":P("1/8 | cup",O),tbsp:P("1/16 | cup",O),tsp:P("1/3 | tbsp",O),rev:P("2 pi | rad",O),deg:P("180 pi | rad",O),"°":P("| deg",O),arcminute:P("1/60 | deg",O),arcsec:P("1/3600 | deg",O),Hu:P("1000 | dB",N),dozen:P("12 |",O),mol:P("6.0221412927 x 10^23 |",N),"%":P("1/100 |",O),percent:P("| %",O),ppm:P("1/1000000 |",O),V:P("1000 | g m m / s s C",N),C:P("| A s",N),ampere:P("| A",O),"Ω":P("| V / A",N),ohm:P("| Ω",O),F:P("| C / V",N),H:P("| ohm s",N),T:P("1000 | g / C s",N),Wb:P("1000 | g m m / C s",N),lm:P("pi x 10^4 | cd / m m",O),lx:P("| lm / m m",O),nit:P("| cd / m m",O),sb:P("10^4 | cd / m m",O),stilb:P("1 | sb",O),apostilb:P("1 / pi x 10^(-4) | sb",O),blondel:P("| apostilb",O),asb:P("| apostilb",O),la:P("| lm",O),Lb:P("| lm",O),sk:P("10^-7 | lm",O),skot:P("| sk",O),bril:P("10^-11 | lm",O),Hz:P("| / s",N)};const q=b.Zero,F=b.One;exports.Abs=y,exports.Add=l,exports.Const=w,exports.Eq=g,exports.Float=M,exports.Func=v,exports.Int=k,exports.Log=p,exports.Mul=h,exports.One=F,exports.Pow=f,exports.Rational=_,exports.Trig=d,exports.Unit=I,exports.Var=x,exports.Zero=q,exports.compare=function(t,n,i){var r={form:!1,simplify:!1};i=void 0!==i?e.default.extend(r,i):r;var s,a=t.sameVars(n);return a.equal?t.compare(n)?i.form&&!t.sameForm(n)?{equal:!1,message:"Your answer is not in the correct form."}:i.simplify&&!t.isSimplified()?{equal:!1,message:"Your answer is not fully expanded and simplified."}:{equal:!0,message:null}:{equal:!1,message:null}:(s=a.equalIgnoringCase?"Check your variables; one or more are using the wrong case (upper or lower).":"Check your variables; you may have used the wrong letter for one or more of them.",{equal:!1,wrongVariableCase:a.equalIgnoringCase,wrongVariableNames:!a.equalIgnoringCase,message:s})},exports.parse=E,exports.unitParse=function(t){try{var n=i.parse(t),r=[];e.default(n.unit.num).each((function(t){r.push(new f(S(t.name),new k(t.pow)))})),e.default(n.unit.denom).each((function(t){r.push(new f(S(t.name),new k(-1*t.pow)))}));var s=new h(r).flatten();return"unitMagnitude"===n.type?{parsed:!0,unit:s,expr:new h([new M(+n.magnitude)].concat(r)),coefficient:n.magnitude,type:n.type}:{parsed:!0,unit:s,type:n.type}}catch(t){return{parsed:!1,error:t.message}}};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|