sellquiz
Version:
An open source domain-specific language for online assessment
1 lines • 91.8 kB
JavaScript
var sellquiz=function(e,t,s){"use strict";function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var r,n=i(t),a=i(s);function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var s=0;s<t.length;s++){var i=t[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function h(e,t,s){return t&&p(e.prototype,t),s&&p(e,s),e}function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";e||(console.log(t),"undefined"!=typeof process?process.exit(-1):alert(t))}!function(e){e.T_UNKNOWN="T_UNKNOWN",e.T_REAL="T_REAL",e.T_DOTS="T_DOTS",e.T_SET="T_SET",e.T_BOOL="T_BOOL",e.T_FUNCTION="T_FUNCTION",e.T_COMPLEX="T_COMPLEX",e.T_COMPLEX_SET="T_COMPLEX_SET",e.T_MATRIX="T_MATRIX",e.T_MATRIX_DEF="T_MATRIX_DEF",e.T_MATRIX_TRANSPOSE="T_MATRIX_TRANSPOSE",e.T_MATRIX_OF_FUNCTIONS="T_MATRIX_OF_FUNCTIONS",e.T_STRING="T_STRING",e.T_STRING_LIST="T_STRING_LIST",e.T_PROGRAMMING="T_PROGRAMMING"}(r||(r={}));var u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r.T_UNKNOWN,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-9;l(this,e),this.hint_html="",this.type=t,this.value=s,this.precision=i}return h(e,[{key:"exportDictionary",value:function(e){var t={};return t.id=e,t.type=this.type,t.value=this.value.toString(),t.precision=this.precision,t.hint=this.hint_html,t}},{key:"importDictionary",value:function(e){switch(this.type=r[e.type],this.type){case r.T_REAL:this.value=parseFloat(e.value);break;default:o(!1,"SellSymbol:importFromDictionary(): UNIMPLMENTED")}this.precision=e.precision,this.hint_html=e.hint}},{key:"toAsciiMath",value:function(){var e="";switch(this.type){case r.T_BOOL:return this.value?"true":"false";case r.T_UNKNOWN:return"ERROR";case r.T_REAL:return this.value;case r.T_DOTS:return"...";case r.T_SET:case r.T_COMPLEX_SET:e="{ ";for(var t=0;t<this.value.length;t++)e+=(t>0?", ":"")+this.value[t].toAsciiMath();return e+=" }";case r.T_FUNCTION:case r.T_COMPLEX:return e=this.value.toString();case r.T_MATRIX:case r.T_MATRIX_OF_FUNCTIONS:return e=(e=(e=this.value.toString()).replaceAll("[","(")).replaceAll("]",")");default:o(!1,"unimplemented SellSymbol::toAsciiMath(..) for "+this.type)}}}]),e}(),c=function e(t,s,i){l(this,e),this.str=t,this.line=s,this.col=i},v=function(){function e(){l(this,e)}return h(e,null,[{key:"isAlpha",value:function(e){return e>="A"&&e<="Z"||e>="a"&&e<="z"||"_"==e||"Ä"==e||"Ö"==e||"Ü"==e||"ß"==e||"ä"==e||"ö"==e||"ü"==e}},{key:"isNum",value:function(e){return e>="1"&&e<="9"}},{key:"isNum0",value:function(e){return"0"==e||this.isNum(e)}},{key:"isIdentifier",value:function(e){for(var t=0;t<e.length;t++){var s=e[t];if(0==t){if(0==this.isAlpha(s))return!1}else if(0==this.isAlpha(s)&&0==this.isNum0(s))return!1}return!0}},{key:"isInteger",value:function(e){if(0==e.length)return!1;var t=0;if("-"===e[0]&&(t=1,1==e.length))return!1;for(var s=t;s<e.length;s++){var i=e[s];if(0==this.isNum0(i))return!1}return!0}},{key:"isReal",value:function(e){return 0==isNaN(parseFloat(e))}},{key:"tokenize",value:function(e){for(var t=new Array,s="",i=1,r=1,n=1,a=!e.startsWith("\t")&&!e.startsWith(" "),l=0;l<e.length;l++){var p=e[l],h="";l<e.length-1&&(h=e[l+1]);var o="";switch(l<e.length-2&&(o=e[l+2]),p){case" ":case"\t":case"\n":s.length>0&&t.push(new c(s,r,i)),s="",i=n,"\n"===p?(r++,n=0):" "===p&&t.push(new c(p,r,i));break;case"_":a?(s.length>0&&t.push(new c(s,r,i)),s="",i=n,"_"==p&&"_"==h&&(p="__",l++),t.push(new c(p,r,i)),i=n):(0==s.length&&(i=n),s+=p);break;case"(":case")":case"{":case"}":case"[":case"]":case"+":case"-":case"*":case"/":case"^":case"~":case"#":case".":case",":case";":case":":case"=":case"@":case"|":case"$":case"?":case"!":case'"':case"<":case">":case"`":case"\\":case"'":s.length>0&&t.push(new c(s,r,i)),s="",i=n,":"==p&&"="==h?(p=":=",l++):"^"==p&&"^"==h?(p="^^",l++):"\\"==p&&"\\"==h?(p="\\\\",l++):"-"==p&&">"==h?(p="->",l++):"|"==p&&"-"==h&&">"==o?(p="|->",l+=2):"<"==p&&"="==h?(p="<=",l++):">"==p&&"="==h?(p=">=",l++):"="==p&&"="==h?(p="==",l++):"!"==p&&"="==h?(p="!=",l++):"."==p&&"."==h&&"."==o?(p="...",l+=2):"`"==p&&"`"==h&&"`"==o&&(p="```",l+=2),t.push(new c(p,r,i)),i=n;break;default:0==s.length&&(i=n),s+=p}n++}return s.length>0&&t.push(new c(s,r,i)),t}},{key:"printTokenList",value:function(e){for(var t=0;t<e.length;t++){var s=e[t];console.log(s.line+":"+s.col+":"+s.str)}}},{key:"randomInt",value:function(e,t){return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e)+e)}},{key:"splitStringAndKeepDelimiters",value:function(e,t){for(var s=Array(),i="",r=0;r<e.length;r++){for(var n=!0,a="",l=0;l<t.length;l++){var p=t[l];if(n=!0,r+p.length>e.length)n=!1;else for(var h=0;h<p.length;h++)if(e[r+h]!=p[h]){n=!1;break}if(n){a=p;break}}n?(i.length>0&&(s.push(i),i=""),s.push(a),r+=a.length-1):i+=e[r]}return i.length>0&&s.push(i),s}}]),e}(),m=function(){function e(t){l(this,e),this.p=t}return h(e,[{key:"parseTitle",value:function(){this.p.parseWhitespaces=!0;for(var e="";!this.p.is("§EOL")&&!this.p.is("§END");)this.p.isIdent()?(e+=this.p.tk,this.p.next()):this.p.is("#")?(this.p.next(),this.p.isIdent()?(this.p.tk,this.p.next()):this.p.err("expected identifer after '#'")):(e+=this.p.charToHTML(this.p.tk),this.p.next());this.p.terminal("§EOL"),this.p.parseWhitespaces=!1,this.p.q.titleHtml=e}},{key:"endItemizeIfApplicable",value:function(){this.p.isItemizeItem&&(this.p.q.html+="</li>"),this.p.isItemize&&(this.p.q.html+="</ul>"),this.p.isItemizeItem=!1,this.p.isItemize=!1}},{key:"parseText",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];for(this.p.parseWhitespaces=!0;!(this.p.is("§END")||this.p.is("§CODE_START")||e&&this.p.is("§EOL"));)if(1!=this.p.tk_col||this.p.is("*")||this.endItemizeIfApplicable(),this.p.is("§EOL")&&this.p.singleMultipleChoiceFeedbackHTML.length>0&&(this.p.q.html+=" "+this.p.singleMultipleChoiceFeedbackHTML,this.p.singleMultipleChoiceFeedbackHTML="",this.p.q.html+="]§"),this.p.is("§EOL")&&this.p.isItemizeItem)this.p.next(),this.p.q.html+="</li>",this.p.isItemizeItem=!1;else if(1==this.p.tk_col&&this.p.is("["))this.parseSingleMultipleChoice(!1);else if(1==this.p.tk_col&&this.p.is("("))this.parseSingleMultipleChoice(!0);else if(1==this.p.tk_col&&this.p.is("*"))this.parseItemize();else if(this.p.is("`"))this.p.q.html+=this.parseInlineListing();else if(this.p.is("```"))this.p.q.html+=this.parseListing();else if(this.p.is("$"))this.p.imParser.parseInlineMath();else if(this.p.is("#"))this.p.q.html+=this.p.imInputParser.parseIM_Input();else if(this.p.isIdent()){var t=v.splitStringAndKeepDelimiters(this.p.tk,["__","_"]);this.p.next();for(var s=0;s<t.length;s++)"_"===t[s]?(this.p.isItalicFont=!this.p.isItalicFont,this.p.q.html+=this.p.isItalicFont?"<i>":"</i>"):"__"===t[s]?(this.p.isBoldFont=!this.p.isBoldFont,this.p.q.html+=this.p.isBoldFont?"<b>":"</b>"):this.p.q.html+=t[s]}else this.p.q.html+=this.p.charToHTML(this.p.tk),this.p.next();this.p.parseWhitespaces=!1,this.endItemizeIfApplicable()}},{key:"parseItemize",value:function(){this.p.terminal("*"),0==this.p.isItemize&&(this.p.q.html+="<ul>"),this.p.isItemize=!0,this.p.isItemizeItem=!0,this.p.q.html+="<li>"}},{key:"parseSingleMultipleChoice",value:function(e){this.p.parseWhitespaces=!1;var t=!1;if(e?this.p.terminal("("):this.p.terminal("["),this.p.is("x"))this.p.next(),t=!0;else if(!this.p.is("]")&&!this.p.is(")")&&!this.p.is(" ")){this.p.codeParser.parseExpr();var s=this.p.q.stack.pop();s.type!=r.T_BOOL&&this.p.err("expression must be boolean"),t=s.value}e?this.p.terminal(")"):this.p.terminal("]"),this.p.parseWhitespaces=!0;var i=e?"_sc_":"_mc_",n=new u(r.T_BOOL,t),a=i+this.p.createUniqueID();this.p.q.symbols[a]=n,this.p.q.solutionSymbols[a]=n;var l=new q;l.htmlElementId="sellquiz_input_"+a,l.solutionVariableId=a,l.htmlElementId_feedback="sellquiz_feedback_"+a,l.htmlElementInputType=L.CHECKBOX,this.p.q.inputs.push(l);var p=e?"radio":"checkbox";this.p.q.html+="\n§[",this.p.q.html+='<input id="'+l.htmlElementId+'" type="'+p+'" name="sell_input" /> ',this.p.singleMultipleChoiceFeedbackHTML=' <span id="'+l.htmlElementId_feedback+'"></span>\n'}},{key:"parseInlineListing",value:function(){var e="";for(this.p.terminal("`"),e+='<code class="text-primary">';!this.p.is("`")&&!this.p.is("§END");)e+=this.p.tk,this.p.next();return this.p.terminal("`"),e+="</code>"}},{key:"parseListing",value:function(){var e="";for(this.p.terminal("```");!this.p.is("```")&&!this.p.is("§END");)if(this.p.is("§EOL"))for(e+="\n",this.p.next();this.p.is(" ");)e+=" ",this.p.next();else this.p.is("\t")?(e+=" ",this.p.next()):(e+=this.p.tk,this.p.next());e=(e=(e=e.replaceAll("<","<")).replaceAll(">",">")).replaceAll("\n","<br/>"),this.p.terminal("```");var t="";return t+='<hr class="mt-2 mb-0"/>',t+='<code class="text-primary">',t+=e,t+="</code>",t+='<hr class="mt-0 mb-0"/>'}}]),e}(),d=function(){function e(){l(this,e)}return h(e,null,[{key:"mat_idx",value:function(e,t,s,i){return s*t+i}},{key:"mat_get_row_count",value:function(e){return e.size()[0]}},{key:"mat_get_col_count",value:function(e){return e.size()[1]}},{key:"mat_get_element_value",value:function(e,t,s){return e.subset(n.index(t,s))}},{key:"mat_submatrix",value:function(e,t,s,i,r){var a=e.size()[0],l=e.size()[1];if(-1==s&&(s=a-1),-1==r&&(r=l-1),t>s||i>r)return null;if(t<0||i<0||t>=a||i>=l)return null;if(s<0||r<0||s>=a||r>=l)return null;for(var p=s-t+1,h=r-i+1,o=n.zeros(p,h),u=t;u<=s;u++)for(var c=i;c<=r;c++){var v=e.subset(n.index(u,c));o=this.mat_set_element(o,u-t,c-i,v)}return o}},{key:"mat_rank",value:function(e){for(var t=e.size()[0],s=e.size()[1],i=[],r=0;r<t;r++)for(var a=0;a<s;a++)i.push(e.subset(n.index(r,a)));for(var l=0,p=[],h=0;h<s;h++)p.push(!1);for(var o=0;o<t;o++){var u=void 0;for(u=0;u<s&&(p[u]||!(Math.abs(i[this.mat_idx(t,s,o,u)])>1e-12));u++);if(u!=s){l++,p[u]=!0;for(var c=o+1;c<t;c++)i[this.mat_idx(t,s,c,u)]/=i[this.mat_idx(t,s,o,u)];for(var v=0;v<s;v++)if(v!=u&&Math.abs(i[this.mat_idx(t,s,o,v)])>1e-12)for(var m=o+1;m<t;m++)i[this.mat_idx(t,s,m,v)]-=i[this.mat_idx(t,s,m,u)]*i[this.mat_idx(t,s,o,v)]}}return l}},{key:"mat_is_symmetric",value:function(e){var t=e.size()[0],s=e.size()[1];if(t!=s)return!1;for(var i=0;i<s;i++)for(var r=i+1;r<s;r++){var a=e.subset(n.index(i,r)),l=e.subset(n.index(r,i));if(n.abs(a-l)>1e-14)return!1}return!0}},{key:"mat_triu",value:function(e){for(var t=e.size()[0],s=e.size()[1],i=n.zeros(t,s),r=0;r<t;r++)for(var a=0;a<s;a++){var l=e.subset(n.index(r,a));a<r&&(l=0),i=i.subset(n.index(r,a),l)}return i}},{key:"mat_norm2",value:function(e){for(var t=e.size()[0],s=e.size()[1],i=0,r=0;r<t;r++)for(var a=0;a<s;a++){var l=e.subset(n.index(r,a));i+=l*l}return n.sqrt(i)}},{key:"mat_vecdot",value:function(e,t){var s=e.size()[0],i=e.size()[1],r=t.size()[0],a=t.size()[1];1==i&&1==a&&s==r||o(!1,"mat_vecdot(..): invalid input");for(var l=0,p=0;p<s;p++)l+=e.subset(n.index(p,0))*t.subset(n.index(p,0));return l}},{key:"mat_veccross",value:function(e,t){var s=e.size()[0],i=e.size()[1],r=t.size()[0],a=t.size()[1];1==i&&1==a&&3==s&&3==r||o(!1,"mat_veccross(..): invalid input");var l=this.mat_get_element_value(e,0,0),p=this.mat_get_element_value(e,1,0),h=this.mat_get_element_value(e,2,0),u=this.mat_get_element_value(t,0,0),c=this.mat_get_element_value(t,1,0),v=this.mat_get_element_value(t,2,0),m=n.zeros(3,1);return m=(m=(m=m.subset(n.index(0,0),p*v-h*c)).subset(n.index(1,0),h*u-l*v)).subset(n.index(2,0),l*c-p*u)}},{key:"mat_is_row_zero",value:function(e,t,s,i){for(var r=0;r<s;r++)if(Math.abs(e[this.mat_idx(t,s,i,r)])>1e-12)return!1;return!0}},{key:"mat_is_zero",value:function(e){for(var t=e.size()[0],s=e.size()[1],i=0;i<t;i++)for(var r=0;r<s;r++){var a=e.subset(n.index(i,r));if(Math.abs(a)>1e-12)return!1}return!0}},{key:"linsolve",value:function(e,t){return e.size()[0],e.size()[1],n.lusolve(e.clone(),t.clone())}},{key:"mat_kernel",value:function(e){for(var t,s=n.lup(e).U,i=s.size()[0],r=s.size()[1],a=[],l=0;l<i;l++)for(var p=0;p<r;p++)a.push(s.subset(n.index(l,p)));for(t=0;t<i&&!this.mat_is_row_zero(a,i,r,t);t++);for(var h=t-1;h>=1;h--)for(var o=h-1;o>=0;o--)for(var u=a[this.mat_idx(i,r,o,h)]/a[this.mat_idx(i,r,h,h)],c=0;c<r;c++)a[this.mat_idx(i,r,o,c)]-=u*a[this.mat_idx(i,r,h,c)];for(var v=0;v<t;v++)for(var m=a[this.mat_idx(i,r,v,v)],d=0;d<r;d++)a[this.mat_idx(i,r,v,d)]/=m;for(var f=r,_=r-t,y=[],b=0;b<f*_;b++)y.push(0);for(var k=0;k<_;k++)y[this.mat_idx(f,_,f-1-k,_-1-k)]=-1;for(var g=0;g<t;g++)for(var T=0;T<_;T++)y[this.mat_idx(f,_,g,T)]=a[this.mat_idx(i,r,g,T+t)];for(var x=n.zeros(f,_),I=0;I<f;I++)for(var E=0;E<_;E++)x=x.subset(n.index(I,E),y[this.mat_idx(f,_,I,E)]);return y}},{key:"mat_set_element",value:function(e,t,s,i){var r=e.size()[0],a=e.size()[1];return t<0||t>=r||s<0||s>=a?null:e=e.subset(n.index(t,s),i)}},{key:"mat_mod",value:function(e,t){for(var s=e.size()[0],i=e.size()[1],r=n.zeros(s,i),a=0;a<s;a++)for(var l=0;l<i;l++){var p=Math.round(e.subset(n.index(a,l)));p=n.mod(p,t),r=r.subset(n.index(a,l),p)}return r}},{key:"mat_compare_numerically",value:function(e,t){var s=e.size()[0],i=e.size()[1],r=t.size()[0],a=t.size()[1];if(s!=r&&i!=a)return!1;for(var l=0;l<s;l++)for(var p=0;p<i;p++){var h=e.subset(n.index(l,p)),o=t.subset(n.index(l,p));if(Math.abs(h-o)>1e-12)return!1}return!0}},{key:"mat_compare_numerically_except_scaling_factor",value:function(e,t){var s=1e-12,i=e.size()[0],r=e.size()[1],a=t.size()[0],l=t.size()[1];if(i!=a&&r!=l)return!1;for(var p=!0,h=1,o=0;o<i;o++)for(var u=0;u<r;u++){var c=e.subset(n.index(o,u)),v=t.subset(n.index(o,u));if(Math.abs(c*h-v)>s){if(!p)return!1;if(p=!1,Math.abs(c)<s||Math.abs(v)<s)return!1;h=v/c}}return!0}}]),e}(),f=function e(t,s){l(this,e),this.type=t,this.v=s,this.deriv=null},_=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];l(this,e),this.symbolIDs=t,this.stack=[],this.state="",this.contains_forbidden_ode_subtree=!1}return h(e,[{key:"clear",value:function(){this.stack=[]}},{key:"importTerm",value:function(e){var t=n.parse(e);return this.importMathJsTermJsRecursively(t)}},{key:"importMathJsTermJsRecursively",value:function(e){switch(e.type){case"ConstantNode":this.pushConstant(e.value);break;case"SymbolNode":this.pushVariable(e.name);break;case"OperatorNode":case"ParenthesisNode":for(;"ParenthesisNode"==e.type;)e=e.content;if("unaryMinus"==e.fn){if(0==this.importMathJsTermJsRecursively(e.args[0]))return!1;this.pushUnaryOperation("-")}else{if("+"!=e.op&&"-"!=e.op&&"*"!=e.op&&"/"!=e.op&&"^"!=e.op)return console.log("warning: SellSymTerm::importMathJsTermJsRecursively(..): unknown/unimplemented operation "+e.op),!1;if(0==this.importMathJsTermJsRecursively(e.args[0]))return!1;if(0==this.importMathJsTermJsRecursively(e.args[1]))return!1;this.pushBinaryOperation(e.op)}break;case"FunctionNode":if("exp"!=e.name&&"sin"!=e.name&&"cos"!=e.name&&"sqrt"!=e.name)return console.log("warning: SellSymTerm::importMathJsTermJsRecursively(..): unknown/unimplemented function "+e.name),!1;if(0==this.importMathJsTermJsRecursively(e.args[0]))return!1;this.pushUnaryFunction(e.name);break;default:return console.log("warning: SellSymTerm::importMathJsTermJsRecursively(..): unknown/unimplemented node type "+e.type),!1}return!0}},{key:"pushVariable",value:function(e){this.stack.push(new f("var",e))}},{key:"pushOdeFunction",value:function(e){this.stack.push(new f("ode_fun",e))}},{key:"pushConstant",value:function(e){e=parseFloat(e),this.stack.push(new f("const",e))}},{key:"pushSymbolicTerm",value:function(e){0==e.stack.length?this.stack.push(new f("const",0)):this.stack.push(e.stack[0])}},{key:"pushUnaryFunction",value:function(e){var t=this.stack.pop();this.stack.push(new f("fct1",[e,t]))}},{key:"pushBinaryFunction",value:function(e){var t=this.stack.pop(),s=this.stack.pop();this.stack.push(new f("fct2",[e,s,t]))}},{key:"pushDiff",value:function(){var t=this.stack.pop(),s=this.stack.pop(),i=new e;i.symbolIDs=this.symbolIDs,i.stack.push(s);var r=i.derivate(t.v);this.pushSymbolicTerm(r)}},{key:"pushUnaryOperation",value:function(e){var t=this.stack.pop();this.stack.push(new f("uniop",[e,t]))}},{key:"pushBinaryOperation",value:function(e){e=e.replace("add","+").replace("sub","-").replace("mul","*").replace("div","/").replace("pow","^");var t=this.stack.pop(),s=this.stack.pop();if("const"==s.type&&"const"==t.type){var i;switch(i=0,e){case"+":i=s.v+t.v;break;case"-":i=s.v-t.v;break;case"*":i=s.v*t.v;break;case"/":i=s.v/t.v;break;case"^":i=n.pow(s.v,t.v);break;default:alert("unimplemented: SellSymTerm:pushBinaryOperation(..): operator "+e)}this.stack.push(new f("const",i))}else this.stack.push(new f("binop",[e,s,t]))}},{key:"appendVariableSet",value:function(e,t){for(var s=0;s<t.length;s++){for(var i=!1,r=0;r<e.length;r++)if(t[s]===e[r]){i=!0;break}0==i&&e.push(t[s])}}},{key:"getVariables",value:function(){var e,t,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=[];switch(null==s&&(s=this.stack[0]),s.type){case"var":this.appendVariableSet(i,[s.v]);break;case"const":break;case"uniop":e=this.getVariables(s.v[1]),this.appendVariableSet(i,e);break;case"binop":e=this.getVariables(s.v[1]),this.appendVariableSet(i,e),t=this.getVariables(s.v[2]),this.appendVariableSet(i,t);break;case"ode_fun":this.appendVariableSet(i,[s.v]);break;case"fct1":e=this.getVariables(s.v[1]),this.appendVariableSet(i,e);break;case"fct2":e=this.getVariables(s.v[1]),this.appendVariableSet(i,e),t=this.getVariables(s.v[2]),this.appendVariableSet(i,t);break;default:alert("unimplemented: SellSymTerm:getVariables(..): "+s.type)}return i}},{key:"getOdeOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=0;switch(null==e&&(e=this.stack[0]),e.type){case"uniop":t=n.max(t,this.getOdeOrder(e.v[1]));break;case"binop":t=n.max(t,this.getOdeOrder(e.v[1])),t=n.max(t,this.getOdeOrder(e.v[2]));break;case"fct2":"diff_ode"==e.v[0]?t=n.max(t,1):"diff2_ode"==e.v[0]&&(t=n.max(t,2))}return t}},{key:"optimizeOdeConstants",value:function(){var e,t,s,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;switch(null==i&&(i=this.stack[0]),i.type){case"var":break;case"uniop":this.optimizeOdeConstants(i.v[1]),"var"===(e=i.v[1]).type&&e.v.startsWith("C")&&(i.type="var",i.v=e.v);break;case"binop":this.optimizeOdeConstants(i.v[1]),this.optimizeOdeConstants(i.v[2]),t=i.v[1],s=i.v[2],"var"===t.type&&t.v.startsWith("C")&&"const"===s.type?(i.type="var",i.v=t.v):"var"===s.type&&s.v.startsWith("C")&&"const"===t.type&&(i.type="var",i.v=s.v);break;case"fct1":this.optimizeOdeConstants(i.v[1]),"var"===(e=i.v[1]).type&&e.v.startsWith("C")&&(i.type="var",i.v=e.v)}}},{key:"searchForForbiddenODESecondOrderSubterms",value:function(){var e,t,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=[];switch(null==s&&(s=this.stack[0]),s.type){case"var":this.appendVariableSet(i,[s.v]);break;case"const":break;case"uniop":e=this.searchForForbiddenODESecondOrderSubterms(s.v[1]),this.appendVariableSet(i,e);break;case"binop":e=this.searchForForbiddenODESecondOrderSubterms(s.v[1]),this.appendVariableSet(i,e),t=this.searchForForbiddenODESecondOrderSubterms(s.v[2]),this.appendVariableSet(i,t);break;case"ode_fun":this.appendVariableSet(i,[s.v]);break;case"fct1":e=this.searchForForbiddenODESecondOrderSubterms(s.v[1]),this.appendVariableSet(i,e);break;case"fct2":e=this.searchForForbiddenODESecondOrderSubterms(s.v[1]),this.appendVariableSet(i,e),t=this.searchForForbiddenODESecondOrderSubterms(s.v[2]),this.appendVariableSet(i,t);break;default:alert("unimplemented: SellSymTerm:searchForForbiddenODESecondOrderSubterms(..): "+s.type)}if(console.log("TEST:"),console.log(i),2==i.length){this.contains_forbidden_ode_subtree=!0;for(var r=0;r<i.length;r++)0==i[r].startsWith("C")&&(this.contains_forbidden_ode_subtree=!1)}return i}},{key:"getOperator",value:function(e){var t="";return"uniop"!=e.type&&"binop"!=e.type||(t=e.v[0]),t}},{key:"getOperatorPrecedence",value:function(e){var t=0;switch(e){case"+":case"-":t=10;break;case"*":case"/":t=20;break;case"^":t=30;break;case"":t=99;break;default:alert("unimplemented: SellSymTerm:getOperatorPrecedence(..): op="+e)}return t}},{key:"toString",value:function(){var e,t,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i="",r=!1;switch(null==s&&(r=!0,s=this.stack[0]),s.type){case"var":i=s.v;break;case"const":i=s.v.toString(),n.abs(s.v-3.141592653589793)<1e-12&&(i="pi");break;case"uniop":i=s.v[0]+this.toString(s.v[1]),"uniop"==s.v[1].type&&(i="("+i+")");break;case"ode_fun":i=s.v.id+"("+s.v.mathsymbol_ids[0]+")";break;case"binop":var a=this.toString(s.v[1]),l=this.toString(s.v[2]),p=s.v[0],h=this.getOperatorPrecedence(p),o=this.getOperator(s.v[1]),u=this.getOperatorPrecedence(o),c=this.getOperator(s.v[2]),v=this.getOperatorPrecedence(c);(u<h||"/"===p)&&(a="("+a+")"),v<h||l.startsWith("-")?l="("+l+")":"-"!==p&&"/"!==p||"const"!==s.v[2].type&&(l="("+l+")"),i=a+p+l;break;case"fct1":e=s.v[0],t=this.toString(s.v[1]),i="exp"===e&&t.length<5?"e^("+t+")":e+"("+t+")";break;case"fct2":i="diff_ode"===(e=s.v[0])?s.v[1].v.id+"'("+s.v[2].v+")":"diff2_ode"===e?s.v[1].v.id+"''("+s.v[2].v+")":e+"("+this.toString(s.v[1])+", "+this.toString(s.v[2])+")";break;default:alert("unimplemented: SellSymTerm:toString(..): "+s.type)}return r&&i.startsWith("(")&&(i=i),i}},{key:"derivate",value:function(t){var s,i,r,n,a,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,p=null==l;switch(p&&(l=this.stack[0]),l.type){case"var":l.deriv=new f("const",l.v==t?1:0);break;case"const":l.deriv=new f("const",0);break;case"uniop":switch(s=l.v[1],this.derivate(t,s),r=l.v[0]){case"-":l.deriv=new f("uniop",[r,s.deriv]);break;default:alert("unimplemented: SellSymTerm:derivate(..): uniop: "+r)}break;case"binop":switch(s=l.v[1],this.derivate(t,s),i=l.v[2],this.derivate(t,i),r=l.v[0]){case"+":case"-":l.deriv=new f("binop",[r,s.deriv,i.deriv]);break;case"*":l.deriv=new f("binop",["+",new f("binop",["*",s.deriv,i]),new f("binop",["*",i.deriv,s])]);break;case"/":l.deriv=new f("binop",["/",new f("binop",["-",new f("binop",["*",s.deriv,i]),new f("binop",["*",i.deriv,s])]),new f("binop",["*",i,i])]);break;case"^":"const"!==i.type&&alert("unimplemented: SellSymTerm:derivate(..): derivation of u^v with v != const"),l.deriv=new f("binop",["*",s.deriv,new f("binop",["*",i,new f("binop",["^",s,new f("binop",["-",i,new f("const",1)])])])]);break;default:alert("unimplemented: SellSymTerm:derivate(..): binop: "+r)}break;case"fct1":switch(n=l.v[0],a=l.v[1],this.derivate(t,a),n){case"sin":l.deriv=new f("binop",["*",a.deriv,new f("fct1",["cos",a])]);break;case"cos":l.deriv=new f("uniop",["-",new f("binop",["*",a.deriv,new f("fct1",["sin",a])])]);break;case"exp":l.deriv=new f("binop",["*",a.deriv,new f("fct1",["exp",a])]);break;case"sqrt":l.deriv=new f("binop",["/",a.deriv,new f("binop",["*",new f("const",2),new f("fct1",["sqrt",a])])]);break;default:alert("unimplemented: SellSymTerm:derivate(..): fct1: "+n)}break;default:alert("unimplemented: SellSymTerm:derivate(..): "+l.type)}if(p){var h=new e;return h.symbolIDs=this.symbolIDs,h.stack=[this.stack[0].deriv],h.optimize(),h}return null}},{key:"eval",value:function(e){var t,s,i,r,a,l,p=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;switch(t=0,null==p&&(p=this.stack[0]),p.type){case"var":if(!(p.v in e))return alert("SellSymTerm:eval(..): variable "+p.v+" has no value!"),0;t=parseFloat(e[p.v]);break;case"const":t=p.v;break;case"uniop":switch(s=this.eval(e,p.v[1]),r=p.v[0]){case"-":t=-s;break;default:alert("unimplemented: SellSymTerm:eval(..): uniop: "+r)}break;case"binop":switch(s=this.eval(e,p.v[1]),i=this.eval(e,p.v[2]),r=p.v[0]){case"+":t=s+i;break;case"-":t=s-i;break;case"*":t=s*i;break;case"/":t=s/i;break;case"^":t=n.pow(s,i);break;default:alert("unimplemented: SellSymTerm:eval(..): binop: "+r)}break;case"fct1":switch(a=p.v[0],l=this.eval(e,p.v[1]),a){case"sin":t=n.sin(l);break;case"cos":t=n.cos(l);break;case"exp":t=n.exp(l);break;case"sqrt":t=n.sqrt(l);break;default:alert("unimplemented: SellSymTerm:eval(..): fct1: "+a)}break;case"fct2":switch(a=p.v[0]){case"diff_ode":case"diff2_ode":var h=null,o=p.v[1].v.id;o in e?h=e[o]:alert("SellSymTerm:eval(..): unknown term "+o);var u=p.v[2].v,c=h.derivate(u);"diff2_ode"===a&&(c=c.derivate(u)),t=c.eval(e);break;default:alert("unimplemented: SellSymTerm:eval(..): fct1: "+a)}break;case"ode_fun":var v=p.v.id,m=null;v in e?m=e[v]:alert("SellSymTerm:eval(..): unknown term "+v),t=m.eval(e);break;default:alert("unimplemented: SellSymTerm:eval(..): "+p.type)}return t}},{key:"optimize",value:function(){var e,t,s,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=null==i;if(r&&(i=this.stack[0]),"uniop"===i.type)e=i.v[0],t=this.optimize(i.v[1]),i.v[1]=t,"-"===e&&"const"==t.type&&0==t.v&&(i.type="const",i.v=0);else if("fct1"===i.type)t=this.optimize(i.v[1]),i.v[1]=t;else if("binop"===i.type)if(e=i.v[0],t=this.optimize(i.v[1]),i.v[1]=t,s=this.optimize(i.v[2]),i.v[2]=s,"const"===t.type&&"const"===s.type)switch(i.type="const",e){case"+":i.v=t.v+s.v;break;case"-":i.v=t.v-s.v;break;case"*":i.v=t.v*s.v;break;case"/":i.v=t.v/s.v;break;default:alert("unimplemented: SellSymTerm:optimize(..): binop: "+e)}else"*"===e&&("const"===t.type&&0==t.v||"const"===s.type&&0==s.v)?(i.type="const",i.v=0):"*"===e&&"const"===t.type&&1==t.v?(i.type=s.type,i.v=s.v):"*"===e&&"const"===t.type&&-1==t.v?i=new f("uniop",["-",s]):"*"===e&&"const"===s.type&&1==s.v?(i.type=t.type,i.v=t.v):"*"===e&&"const"===s.type&&-1==t.v?i=new f("uniop",["-",t]):"+"===e&&"const"===t.type&&0==t.v?(i.type=s.type,i.v=s.v):"+"===e&&"const"===s.type&&0==s.v||"-"===e&&"const"===s.type&&0==s.v||"^"===e&&"const"===s.type&&1==s.v?(i.type=t.type,i.v=t.v):"-"===e&&"uniop"===s.type&&"-"===s.v[0]?i=new f("binop",["+",t,s.v[1]]):"+"===e&&"uniop"===s.type&&"-"===s.v[0]&&(i=new f("binop",["-",t,s.v[1]]));return r&&(this.stack[0]=i),i}},{key:"integrateNumerically",value:function(e,t,s){if(s<t)return-this.integrateNumerically(e,s,t);for(var i=(s-t)/1e6,r=0,n=t;n<s;n+=i){r+=(this.eval({varId:n})+this.eval({varId:n+i}))/2*i}return r}},{key:"compareWithStringTerm",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];this.state="",0==e.length&&(e="0");var s=this.getVariables();t.length>0&&(s=t);for(var i=50,r=-1,a=1,l=1e-6,p=0;p<i;p++){for(var h={},o=0;o<s.length;o++)h[s[o]]=n.random(r,a);var u=this.eval(h);if(u>1e3)p--;else{var c=0;try{c=n.evaluate(e,h)}catch(e){return this.state="syntaxerror",!1}if("number"!=typeof c)return this.state="syntaxerror",!1;if(n.abs(u-c)>=l)return!1}}return!0}}]),e}(),y=function(){function e(t,s){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];l(this,e),this.m=t,this.n=s,this.elements=i}return h(e,[{key:"toString",value:function(){for(var e="[",t=0;t<this.m;t++){t>0&&(e+=", "),e+="[";for(var s=0;s<this.n;s++)s>0&&(e+=", "),e+=this.elements[t*this.n+s].toString();e+="]"}return e+="]"}}]),e}(),b=function(){function e(t){l(this,e),this.p=t}return h(e,[{key:"getFunctionList",value:function(){return["abs","binomial","integrate","conj","sqrt","xgcd","det","rank","inv","eye","eigenvalues_sym","triu","sin","cos","asin","acos","tan","atan","norm2","dot","cross","linsolve","is_zero","min","max"]}},{key:"parseCode",value:function(){for(this.p.terminal("§CODE_START");!this.p.is("§CODE_END")&&!this.p.is("§END");)this.p.is("input")?(this.parseCodeProp(),this.p.terminal("§EOL")):this.p.is("?")?(this.parseCodeHint(),this.p.terminal("§EOL")):this.p.is("JavaBlock")||this.p.is("JavaMethod")||this.p.is("Python")?this.p.progParser.parseProg():(this.parseAssign(),this.p.terminal("§EOL"));this.p.is("§END")||this.p.terminal("§CODE_END")}},{key:"parseCodeProp",value:function(){this.p.is("input")?this.p.next():this.p.err("expected input");var e=!1;this.p.is("rows")?(this.p.next(),e=!0):this.p.is("cols")?(this.p.next(),e=!1):this.p.err("expected 'rows' or 'cols'"),this.p.terminal(":=");var t=!0;this.p.is("resizable")?(this.p.next(),t=!0):this.p.is("static")?(this.p.next(),t=!1):this.p.err("expected 'resizable' or 'static'"),e?this.p.resizableRows=t:this.p.resizableCols=t}},{key:"parseCodeHint",value:function(){this.p.is("?")?this.p.next():this.p.err("expected ?");var e=this.p.q.lastParsedInputSymbol;null==e&&this.p.err("Hint/explanation is forbidden, since there is no preceding input field");var t=this.p.q.html.length;this.p.textParser.parseText(!0),e.hint_html=this.p.q.html.substr(t),this.p.q.html=this.p.q.html.substr(0,t)}},{key:"chooseFromSet",value:function(e){var t;if(4==e.length&&e[2].type===r.T_DOTS){var s=e[0].value,i=e[3].value,n=parseFloat(e[1].value)-s;t=Math.floor(Math.random()*(i-s+n)/n)*n+s}else{t=e[Math.floor(Math.random()*e.length)].value}return t}},{key:"parseAssign",value:function(){this.p.q.stack=[];var e=!1,t=[],s=[],i=!1,a=0,l=0;if(this.p.ident(),t.push(this.p.id),"i"!==this.p.id&&"e"!==this.p.id||this.p.err("id '"+this.p.id+"' is a reserved symbol"),this.p.is("(")){for(e=!0,this.p.next(),this.p.ident(),s.push(this.p.id);this.p.is(",");)this.p.next(),this.p.ident(),s.push(this.p.id);this.p.terminal(")")}else if(this.p.is("[")){this.p.next(),i=!0,this.parseExpr();var p=this.p.q.stack.pop();p.type==r.T_REAL&&v.isInteger(p.value)||this.p.err("row index is not an integer value"),a=p.value,this.p.terminal(","),this.parseExpr(),(p=this.p.q.stack.pop()).type==r.T_REAL&&v.isInteger(p.value)||this.p.err("column index is not an integer value"),l=p.value,this.p.terminal("]")}else for(;this.p.is(",");)this.p.next(),this.p.ident(),t.push(this.p.id);if(this.p.is(":=")||this.p.is("=")){this.p.next(),e?this.p.codeSymParser.parseSymbolicTerm(s):this.parseExpr();var h=this.p.q.stack.pop();if(i){h.type!=r.T_REAL&&this.p.err("right-hand side must be of type real"),t[0]in this.p.q.symbols||this.p.err("unkown symbol '"+t[0]+"'");var o=this.p.q.symbols[t[0]];o.type!=r.T_MATRIX&&this.p.err("symbol '"+t[0]+"' is not a matrix"),o.value=d.mat_set_element(o.value,a-1,l-1,h.value),null==o.value&&this.p.err("invalid indices")}else for(var c=0;c<t.length;c++)this.p.q.symbols[t[c]]=h}else if(this.p.is("in"))if(e&&this.p.err("cannot apply 'in' to a function"),this.p.next(),this.p.is("MM")){this.parseMatrixDef();for(var m=this.p.q.stack.pop(),f=m.value[0],_=m.value[1],y=m.value[2],b=m.value[3],k=m.value[4],g=0;g<t.length;g++){var T=n.zeros(f,_),x=0;do{for(var I=0;I<f;I++)for(var E=0;E<_;E++){var S=this.chooseFromSet(y.value);T.subset(n.index(I,E),S)}if(k)for(var w=1;w<f;w++)for(var M=0;M<w;M++){var A=T.subset(n.index(w,M));T=T.subset(n.index(M,w),A)}if(!b)break;x>256&&this.p.err("matrix generation failed: too many iterations"),x++}while(n.abs(n.det(T))<1e-16);this.p.q.symbols[t[g]]=new u(r.T_MATRIX,T)}}else if(this.p.is("{")||this.p.isIdent()){this.p.is("{")?this.parseSet():this.parseExpr();var O=this.p.q.stack.pop();O.type!=r.T_SET&&this.p.err("expected a set");for(var L=this.p.backupLexer(),R=0;;){R>1e3&&this.p.err("constraints for random variables cannot be fulfilled"),R++;for(var q=0;q<t.length;q++){var C=this.chooseFromSet(O.value);this.p.q.symbols[t[q]]=new u(r.T_REAL,C)}if(this.p.replayLexer(L),!this.p.is("with"))break;this.p.next(),this.parseExpr();var N=this.p.q.stack.pop();if(N.type!=r.T_BOOL&&this.p.err("constraint must be boolean"),N.value)break}}else this.p.err("unexpected '"+this.p.tk+"'");else this.p.err("expected ':=' or '=' or 'in'")}},{key:"parseExpr",value:function(){this.parseOr()}},{key:"parseOr",value:function(){if(this.parseAnd(),this.p.is("or")){var e=this.p.tk;this.p.next(),this.parseAnd();var t=this.p.q.stack.pop(),s=this.p.q.stack.pop();s.type==r.T_BOOL&&t.type==r.T_BOOL?this.p.pushSym(r.T_BOOL,s.value||t.value):this.p.err("types not compatible for '"+e+"' (must be boolean)")}}},{key:"parseAnd",value:function(){if(this.parseEqual(),this.p.is("and")){var e=this.p.tk;this.p.next(),this.parseEqual();var t=this.p.q.stack.pop(),s=this.p.q.stack.pop();s.type==r.T_BOOL&&t.type==r.T_BOOL?this.p.pushSym(r.T_BOOL,s.value&&t.value):this.p.err("types not compatible for '"+e+"' (must be boolean)")}}},{key:"parseEqual",value:function(){if(this.parseCompare(),this.p.is("==")||this.p.is("!=")){var e=this.p.tk;this.p.next(),this.parseCompare();var t=this.p.q.stack.pop(),s=this.p.q.stack.pop();if(s.type==r.T_REAL&&t.type==r.T_REAL){var i=n.abs(s.value-t.value)<1e-14;switch(e){case"==":this.p.pushSym(r.T_BOOL,i);break;case"!=":this.p.pushSym(r.T_BOOL,!i)}}else if(s.type==r.T_MATRIX&&t.type==r.T_MATRIX){var a=d.mat_compare_numerically(s.value,t.value);switch(e){case"==":this.p.pushSym(r.T_BOOL,a);break;case"!=":this.p.pushSym(r.T_BOOL,!a)}}else this.p.err("types not compatible for '"+e+"'")}}},{key:"parseCompare",value:function(){if(this.parseAdd(),this.p.is("<=")||this.p.is("<")||this.p.is(">=")||this.p.is(">")){var e=this.p.tk;this.p.next(),this.parseAdd();var t=this.p.q.stack.pop(),s=this.p.q.stack.pop();if(s.type==r.T_REAL&&t.type==r.T_REAL)switch(e){case"<=":this.p.pushSym(r.T_BOOL,s.value<=t.value);break;case"<":this.p.pushSym(r.T_BOOL,s.value<t.value);break;case">=":this.p.pushSym(r.T_BOOL,s.value>=t.value);break;case">":this.p.pushSym(r.T_BOOL,s.value>t.value)}else this.p.err("types not compatible for '"+e+"'")}}},{key:"parseAdd",value:function(){for(this.parseMul();this.p.is("+")||this.p.is("-");){var e=this.p.tk;this.p.next(),this.parseMul();var t=this.p.q.stack.pop(),s=this.p.q.stack.pop();if(s.type==r.T_REAL&&t.type==r.T_REAL)switch(e){case"+":this.p.pushSym(r.T_REAL,s.value+t.value);break;case"-":this.p.pushSym(r.T_REAL,s.value-t.value)}else if(s.type!=r.T_REAL&&s.type!=r.T_COMPLEX||t.type!=r.T_REAL&&t.type!=r.T_COMPLEX)if(s.type==r.T_MATRIX&&t.type==r.T_MATRIX){var i=s.value.size()[0],a=s.value.size()[1],l=t.value.size()[0],p=t.value.size()[1];i==l&&a==p||this.p.err("cannot apply '"+e+"' on ("+i+"x"+a+") and ("+l+"x"+p+") matrices"),this.p.pushSym(r.T_MATRIX,"+"==e?n.add(s.value,t.value):n.subtract(s.value,t.value))}else this.p.err("types not compatible for '"+e+"'");else switch(e){case"+":this.p.pushSym(r.T_COMPLEX,n.add(s.value,t.value));break;case"-":this.p.pushSym(r.T_COMPLEX,n.subtract(s.value,t.value))}}}},{key:"parseMul",value:function(){for(this.parsePow();this.p.is("*")||this.p.is("/")||this.p.is("mod");){var e=this.p.tk;this.p.next(),this.parsePow();var t=this.p.q.stack.pop(),s=this.p.q.stack.pop();if(s.type==r.T_REAL&&t.type==r.T_REAL)switch(e){case"*":this.p.pushSym(r.T_REAL,s.value*t.value);break;case"/":this.p.pushSym(r.T_REAL,s.value/t.value);break;case"mod":this.p.isNumberInt(s.value)&&this.p.isNumberInt(t.value)||this.p.err("operator 'mod' expectes integral operands"),this.p.pushSym(r.T_REAL,n.mod(n.round(s.value),n.round(t.value)))}else if(s.type!=r.T_REAL&&s.type!=r.T_COMPLEX||t.type!=r.T_REAL&&t.type!=r.T_COMPLEX)if(s.type==r.T_MATRIX&&t.type==r.T_MATRIX)switch(e){case"*":var i=s.value.size()[0],a=s.value.size()[1],l=t.value.size()[0],p=t.value.size()[1];a!=l&&this.p.err("cannot multiply ("+i+"x"+a+") and ("+l+"x"+p+") matrices"),this.p.pushSym(r.T_MATRIX,n.multiply(s.value,t.value));break;case"/":case"mod":this.p.err("types not compatible for '"+e+"'")}else if(s.type==r.T_MATRIX&&t.type==r.T_REAL)switch(e){case"*":this.p.pushSym(r.T_MATRIX,n.multiply(s.value,t.value));break;case"mod":this.p.isNumberInt(t.value)||this.p.err("operator 'mod' expectes integral operands"),this.p.pushSym(r.T_MATRIX,d.mat_mod(s.value,t.value));break;default:console.log(s.value.toString()),this.p.err("types not compatible for '"+e+"'")}else if(s.type==r.T_REAL&&t.type==r.T_MATRIX)switch(e){case"*":this.p.pushSym(r.T_MATRIX,n.multiply(s.value,t.value));break;default:this.p.err("types not compatible for '"+e+"'")}else this.p.err("types not compatible for '"+e+"'");else switch(e){case"*":this.p.pushSym(r.T_COMPLEX,n.multiply(s.value,t.value));break;case"/":this.p.pushSym(r.T_COMPLEX,n.divide(s.value,t.value));break;case"mod":this.p.err("types not compatible for '"+e+"'")}}}},{key:"parsePow",value:function(){for(this.parseUnary();this.p.is("^");){var e=this.p.tk;this.p.next(),this.parseUnary();var t=this.p.q.stack.pop(),s=this.p.q.stack.pop();if(s.type==r.T_REAL&&t.type==r.T_REAL)switch(e){case"^":this.p.pushSym(r.T_REAL,n.pow(s.value,t.value))}else if(s.type!=r.T_REAL&&s.type!=r.T_COMPLEX||t.type!=r.T_REAL&&t.type!=r.T_COMPLEX)if(s.type==r.T_MATRIX&&t.type==r.T_MATRIX_TRANSPOSE)switch(e){case"^":this.p.pushSym(r.T_MATRIX,n.transpose(s.value))}else this.p.err("types not compatible for '"+e+"'");else switch(e){case"^":this.p.pushSym(r.T_COMPLEX,n.pow(s.value,t.value))}}}},{key:"parseUnary",value:function(){if(this.p.is("-")){this.p.next(),this.parseUnary();var e=this.p.q.stack.pop();e.type==r.T_REAL?this.p.pushSym(r.T_REAL,-e.value):this.p.err("unary '-' must be followed by type real")}else if(this.p.isInt()){var t=parseInt(this.p.tk);this.p.next(),this.p.is(".")&&(this.p.next(),v.isInteger(this.p.tk)||this.p.err("expected decimal places after '.'"),t=parseFloat(t+"."+this.p.tk),this.p.next()),this.p.q.stack.push(new u(r.T_REAL,t))}else if(this.p.is("true"))this.p.next(),this.p.q.stack.push(new u(r.T_BOOL,!0));else if(this.p.is("false"))this.p.next(),this.p.q.stack.push(new u(r.T_BOOL,!1));else if(this.p.is("not")){this.p.next(),this.parseUnary();var s=this.p.q.stack.pop();s.type!=r.T_BOOL&&this.p.err("expected boolean datatype as argument for 'not'"),this.p.q.stack.push(new u(r.T_BOOL,!s.value))}else if(this.p.is("i")||this.p.is("j"))this.p.q.stack.push(new u(r.T_COMPLEX,n.complex(0,1))),this.p.next();else if(this.p.is("T"))this.p.q.stack.push(new u(r.T_MATRIX_TRANSPOSE,"T")),this.p.next();else if(this.getFunctionList().includes(this.p.tk))this.parseFunctionCall();else if(this.p.isIdent()){var i=this.p.tk;this.p.next(),i in this.p.q.symbols==0&&this.p.err("unknown identifier '"+i+"'");var a=this.p.q.symbols[i];if(a.type==r.T_FUNCTION&&this.p.is("(")){this.p.next(),this.parseAdd();for(var l=[this.p.q.stack.pop()];this.p.is(",");)this.p.next(),this.parseAdd(),l.push(this.p.q.stack.pop());var p=a.value,h=p.symbolIDs;h.length!=l.length&&this.p.err("number of arguments does not correspond to function definition");for(var o={},c=0;c<h.length;c++)l[c].type!=r.T_REAL&&this.p.err("all arguements must be scalar and real valued"),o[h[c]]=l[c].value;var m=p.eval(o),d=new u(r.T_REAL,m);this.p.q.stack.push(d),this.p.terminal(")")}else this.p.q.stack.push(a)}else this.p.is("...")?(this.p.next(),this.p.q.stack.push(new u(r.T_DOTS))):this.p.is("{")?this.parseSet():this.p.is("[")?this.parseMatrix():this.p.is("(")?(this.p.next(),this.parseExpr(),this.p.terminal(")")):this.p.err("expected unary, got '"+this.p.tk+"'");this.p.is("!")&&this.parseFactorial()}},{key:"parseMatrix",value:function(){this.p.terminal("[");for(var e=-1,t=0,s=[],i=null;this.p.is("[")||this.p.is(",");){t>0&&this.p.terminal(","),this.p.terminal("[");for(var a=0;!this.p.is("]")&&!this.p.is("§EOF");){a>0&&this.p.terminal(","),this.parseExpr();var l=this.p.q.stack.pop();l.type!=r.T_REAL&&l.type!=r.T_FUNCTION&&this.p.err("matrix element must be of type real or function"),null==i?i=l.type:l.type!=i&&this.p.err("all matrix elements must have same type"),s.push(l.value),a++}-1==e?e=a:a!=e&&this.p.err("matrix has different number of cols per row"),this.p.terminal("]"),t++}(t<1||e<1)&&this.p.err("matrix must have at least one row and one column"),this.p.terminal("]");var p=null,h=i==r.T_REAL?r.T_MATRIX:r.T_MATRIX_OF_FUNCTIONS;if(h==r.T_MATRIX){p=n.zeros(t,e),o(s.length==t*e);for(var c=0;c<t;c++)for(var v=0;v<e;v++)p=d.mat_set_element(p,c,v,s[c*e+v])}else p=new y(t,e,s);this.p.q.stack.push(new u(h,p))}},{key:"parseFunctionCall",value:function(){this.p.ident();var e=this.p.id;this.p.terminal("(");for(var t=[];!this.p.is(")")&&!this.p.is("§EOL")&&!this.p.is("§EOF");)t.length>0&&this.p.terminal(","),"integrate"==e&&1==t.length?(this.p.ident(),t.push(this.p.id)):(this.parseExpr(),t.push(this.p.q.stack.pop()));if(this.p.terminal(")"),"abs"===e)(1!=t.length||t[0].type!=r.T_REAL&&t[0].type!=r.T_COMPLEX)&&this.p.err("signature must be 'abs(real|complex)'"),this.p.pushSym(r.T_REAL,n.abs(t[0].value));else if("sqrt"===e){(1!=t.length||t[0].type!=r.T_REAL&&t[0].type!=r.T_COMPLEX)&&this.p.err("signature must be 'sqrt(real|complex)'");var s=n.sqrt(t[0].value),i="Complex"==n.typeOf(s);this.p.pushSym(i?r.T_COMPLEX:r.T_REAL,s)}else if(["sin","asin","cos","acos","tan","atan"].includes(e)){1==t.length&&t[0].type==r.T_REAL||this.p.err("signature must be '"+e+"(real)'");var a=0;switch(e){case"sin":a=n.sin(t[0].value);break;case"asin":a=n.asin(t[0].value);break;case"cos":a=n.cos(t[0].value);break;case"acos":a=n.acos(t[0].value);break;case"tan":a=n.tan(t[0].value);break;case"atan":a=n.atan(t[0].value);break;default:this.p.err("UNIMPLEMENTED: "+e)}this.p.pushSym(r.T_REAL,a)}else if("conj"===e)1==t.length&&t[0].type==r.T_COMPLEX||this.p.err("signature must be 'conj(complex)'"),this.p.pushSym(r.T_COMPLEX,n.conj(t[0].value));else if("binomial"===e)2==t.length&&t[0].type==r.T_REAL&&t[1].type==r.T_REAL&&this.p.isNumberInt(t[0].value)&&this.p.isNumberInt(t[1].value)||this.p.err("signature must be 'binomial(int,int)'"),this.p.pushSym(r.T_REAL,n.combinations(n.round(t[0].value),n.round(t[1].value)));else if("xgcd"===e)3==t.length&&t[0].type==r.T_REAL&&t[1].type==r.T_REAL&&t[2].type==r.T_REAL&&this.p.isNumberInt(t[0].value)&&this.p.isNumberInt(t[1].value)&&this.p.isNumberInt(t[2].value)||this.p.err("signature must be 'xgcd(int,int,int)'"),this.p.pushSym(r.T_REAL,n.subset(n.xgcd(t[0].value,t[1].value),n.index(t[2].value-1)));else if("integrate"===e){4==t.length&&t[0].type==r.T_FUNCTION&&"string"==typeof t[1]&&t[2].type==r.T_REAL&&t[3].type==r.T_REAL||this.p.err("signature must be 'integrate(function, string, real, real)'");var l=t[0].value.integrateNumerically(t[1],t[2].value,t[3].value);this.p.pushSym(r.T_REAL,l,.001)}else if(["det","rank","inv","eigenvalues_sym","triu","norm2"].includes(e))if(1==t.length&&t[0].type==r.T_MATRIX||this.p.err("signature must be '"+e+"(matrix)'"),"det"===e)this.p.pushSym(r.T_REAL,n.det(t[0].value));else if("rank"===e)this.p.pushSym(r.T_REAL,d.mat_rank(t[0].value));else if("inv"===e)this.p.pushSym(r.T_MATRIX,n.inv(t[0].value));else if("eigenvalues_sym"===e){d.mat_is_symmetric(t[0].value)||this.p.err("matrix is not symmetric");for(var p=n.eigs(t[0].value).values._data,h=[],c=0;c<p.length;c++)h.push(new u(r.T_REAL,p[c]));this.p.pushSym(r.T_SET,h)}else"triu"===e?this.p.pushSym(r.T_MATRIX,d.mat_triu(t[0].value)):"norm2"===e?this.p.pushSym(r.T_REAL,d.mat_norm2(t[0].value)):o(!1);else if("eye"===e)1==t.length&&t[0].type==r.T_REAL&&this.p.isNumberInt(t[0].value)||this.p.err("signature must be 'eye(integer)'"),this.p.pushSym(r.T_MATRIX,n.identity(n.round(t[0].value)));else if("dot"===e)2==t.length&&t[0].type==r.T_MATRIX&&t[1].type==r.T_MATRIX||this.p.err("signature must be 'dot(columnVector,columnVector)'"),1!=d.mat_get_col_count(t[0].value)&&this.p.err("signature must be 'dot(columnVector,columnVector)'"),1!=d.mat_get_col_count(t[1].value)&&this.p.err("signature must be 'dot(columnVector,columnVector)'"),d.mat_get_row_count(t[0].value)!=d.mat_get_row_count(t[1].value)&&this.p.err("vectors in 'dot(..)' must have equal length"),this.p.pushSym(r.T_REAL,d.mat_vecdot(t[0].value,t[1].value));else if("cross"===e)2==t.length&&t[0].type==r.T_MATRIX&&t[1].type==r.T_MATRIX||this.p.err("signature must be 'cross(columnVector,columnVector)'"),1!=d.mat_get_col_count(t[0].value)&&this.p.err("signature must be 'cross(columnVector,columnVector)'"),1!=d.mat_get_col_count(t[1].value)&&this.p.err("signature must be 'cross(columnVector,columnVector)'"),3!=d.mat_get_row_count(t[0].value)&&this.p.err("vectors in 'cross(..)' must have length 3"),3!=d.mat_get_row_count(t[1].value)&&this.p.err("vectors in 'cross(..)' must have length 3"),this.p.pushSym(r.T_MATRIX,d.mat_veccross(t[0].value,t[1].value));else if("linsolve"===e)2==t.length&&t[0].type==r.T_MATRIX&&t[1].type==r.T_MATRIX||this.p.err("signature must be 'linsolve(matrix,columnVector)'"),d.mat_get_col_count(t[0].value)!=d.mat_get_row_count(t[0].value)&&this.p.err("matrix must be square, i.e. m=n"),1!=d.mat_get_col_count(t[1].value)&&this.p.err("second parameter must be a colum vector"),d.mat_get_row_count(t[0].value)!=d.mat_get_row_count(t[1].value)&&this.p.err("number of rows of matrix and does not match vector"),this.p.pushSym(r.T_MATRIX,d.linsolve(t[0].value,t[1].value));else if("is_zero"===e)1==t.length&&t[0].type==r.T_MATRIX||this.p.err("signature must be 'is_zero(matrix)'"),this.p.pushSym(r.T_BOOL,d.mat_is_zero(t[0].value));else if("min"===e){1==t.length&&t[0].type==r.T_SET||this.p.err("signature must be 'min(set)'");for(var v=1e13,m=0;m<t[0].value.length;m++)t[0].value[m].value<v&&(v=t[0].value[m].value);this.p.pushSym(r.T_REAL,v)}else if("max"===e){1==t.length&&t[0].type==r.T_SET||this.p.err("signature must be 'max(set)'");for(var f=-1e13,_=0;_<t[0].value.length;_++)t[0].value[_].value>f&&(f=t[0].value[_].value);this.p.pushSym(r.T_REAL,f)}else this.p.err("unimplemented function call '"+e+"'")}},{key:"parseFactorial",value:function(){this.p.terminal("!");var e=this.p.q.stack.pop();e.type==r.T_REAL?this.p.pushSym(r.T_REAL,n.factorial(e.value)):this.p.err("types not compatible for '!'")}},{key:"parseMatrixDef",value:function(){this.p.terminal("MM"),this.p.terminal("("),this.parseExpr();var e=this.p.q.stack.pop();e.type===r.T_REAL&&this.p.isNumberInt(e.value)||this.p.err("expected integer for the number of rows");var t=n.round(e.value);t<=0&&this.p.err("number of matrix cols must be > 0 (actually is '"+t+"')"),this.p.terminal("x"),this.parseExpr();var s=this.p.q.stack.pop();s.type===r.T_REAL&&this.p.isNumberInt(s.value)||this.p.err("expected integer for the number of columns");var i=n.round(s.value);i<=0&&this.p.err("number of matrix rows must be > 0 (actually is '"+i+"')"),this.p.terminal("|"),this.parseExpr();var a=this.p.q.stack.pop();a.type!==r.T_SET&&this.p.err("expected set from which matrix elements are drawn");for(var l=!1,p=!1;this.p.is(",");){this.p.next();var h=this.p.tk;switch(h){case"invertible":l=!0;break;case"symmetric":p=!0;break;default:this.p.err("unknown property '"+h+"'")}this.p.next()}this.p.terminal(")"),this.p.pushSym(r.T_MATRIX_DEF,[t,i,a,l,p])}},{key:"parseSet",value:function(){this.p.terminal("{");var e=0,t=new u(r.T_SET);t.value=[];for(var s=!1;!this.p.is("}")&&!this.p.is("§EOF");){e>0&&this.p.terminal(","),this.parseExpr();var i=this.p.q.stack.pop();t.value.push(i),i.type!==r.T_REAL&&(2==e&&i.type===r.T_DOTS?s=!0:i.type===r.T_COMPLEX?t.type=r.T_COMPLEX_SET:this.p.err("set must consist of real values only")),e++}if((s&&4!=e||s&&t.type==r.T_COMPLEX_SET)&&this.p.err("if set contains '...', then it must have 4 real-valued elements"),t.type==r.T_COMPLEX_SET)for(var a=0;a<t.value.length;a++)t.value[a].type==r.T_REAL&&(t.value[a].value=n.complex(t.value[a].value,0));this.p.q.stack.push(t),this.p.terminal("}")}}]),e}(),k=function(){function e(t){l(this,e),this.p=t}return h(e,[{key:"parseSymbolicTerm",value:function(e){var t=new _(e);this.parseSymbolicTerm_Add(t),t.optimize(),this.p.q.stack.push(new u(r.T_FUNCTION,t))}},{key:"parseSymbolicTerm_Expr",value:function(e){this.parseSymbolicTerm_Add(e)}},{key:"parseSymbolicTerm_Add",value:function(e){for(this.parseSymbolicTerm_Mul(e);this.p.is("+")||this.p.is("-");){var t=this.p.tk;this.p.next(),this.parseSymbolicTerm_Mul(e),e.pushBinaryOperation(t)}}},{key:"parseSymbolicTerm_Mul",value:function(e){for(this.parseSymbolicTerm_Pow(e);this.p.is("*")||this.p.is("/");){var t=this.p.tk;this.p.next(),this.parseSymbolicTerm_Pow(e),e.pushBinaryOperation(t)}}},{key:"parseSymbolicTerm_Pow",value:function(e){for(this.parseSymbolicTerm_Unary(e);this.p.is("^");){var t=this.p.tk;this.p.next(),this.parseSymbolicTerm_Unary(e),e.pushBinaryOperation(t)}}},{key:"parseSymbolicTerm_Unary",value:function(e){if(this.p.is("("))this.p.terminal("("),this.parseSymbolicTerm_Expr(e),this.p.terminal(")");else if(this.p.isNumber()){var t=parseFloat(this.p.tk);this.p.next(),this.p.is("!")&&(this.p.isNumberInt(t)||this.p.err("expected integer for '!'"),this.p.next(),t=n.factorial(t)),e.pushConstant(t)}else if(["exp","sin","cos","sqrt"].includes(this.p.tk)){var s=this.p.tk;this.p.next(),this.p.terminal("("),this.parseSymbolicTerm_Expr(e),this.p.terminal(")"),e.pushUnaryFunction(s)}else if(this.p.is("diff")){this.p.next(),this.p.terminal("("),this.parseSymbolicTerm_Expr(e),this.p.terminal(","),this.p.ident();var i=this.p.id;this.p.terminal(")"),e.pushVariable(i),e.pushDiff()}else if(this.p.isIdent()){var a=this.p.tk;if(this.p.next(),a in this.p.q.symbols){var l=this.p.q.symbols[a];if(l.type===r.T_REAL)e.pushConstant(l.value);else if(l.type==r.T_FUNCTION)if(this.p.is("(")){var p=[];for(this.p.terminal("(");!this.p.is(")")&&!this.p.is("§EOF");){p.length>0&&this.p.terminal(","),this.p.codeParser.parseExpr();var h=this.p.q.stack.pop();h.type!==r.T_REAL&&this.p.err("paremeter must be of type 'real'"),p.push(h.value)}this.p.terminal(")"),l.value.symbolIDs.length!=p.length&&this.p.err("number of parameters does not match definition of function '"+a+"'");for(var o={},u=0;u<l.value.symbolIDs.length;u++)o[l.value.symbolIDs[u]]=p[u];e.pushConstant(l.value.eval(o))}else e.pushSymbolicTerm(l.value);else this.p.err("identifer '"+a+"' must be of type 'real'")}else e.pushVariable(a)}else this.p.is("-")?(this.p.next(),this.parseSymbolicTerm_Pow(e),e.pushUnaryOperation("-")):this.p.err("expected unary")}}]),e}(),g=function(){function e(t){l(this,e),this.p=t}return h(e,[{key:"parseInlineMath",value:function(){var e="";for(this.p.terminal("$"),e+=" `";!this.p.is("$")&&!this.p.is("§END");)e+=this.parseIM_Expr();e+="` ",this.p.terminal("$"),this.p.q.html+=' <span style="font-size: 13pt;">'+e.replaceAll("``","")+"</span> "}},{key:"parseIM_Expr",value:function(){return this.parseIM_List()}},{key:"parseIM_List",value:funct