@cortex-js/compute-engine 0.8.0 → 0.9.0

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.
Files changed (83) hide show
  1. package/dist/compute-engine.esm.js +7800 -6891
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +41 -88
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -5
  9. package/dist/types/common/utils.d.ts +1 -0
  10. package/dist/types/compute-engine/assume.d.ts +6 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +10 -14
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +74 -16
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +10 -5
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -4
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +16 -14
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +20 -19
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +8 -7
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +18 -12
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -3
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +7 -7
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +18 -0
  27. package/dist/types/compute-engine/compute-engine.d.ts +64 -33
  28. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  29. package/dist/types/compute-engine/domain-utils.d.ts +2 -8
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -9
  43. package/dist/types/compute-engine/latex-syntax/public.d.ts +14 -6
  44. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
  46. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  47. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  48. package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -3
  49. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +5 -6
  51. package/dist/types/compute-engine/library/arithmetic-power.d.ts +3 -2
  52. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  53. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  54. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  55. package/dist/types/compute-engine/library/core.d.ts +1 -1
  56. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  57. package/dist/types/compute-engine/library/library.d.ts +1 -1
  58. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  59. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  60. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  61. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  62. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  63. package/dist/types/compute-engine/numerics/{numeric-decimal.d.ts → numeric-bignum.d.ts} +10 -6
  64. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  65. package/dist/types/compute-engine/numerics/numeric.d.ts +10 -6
  66. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  67. package/dist/types/compute-engine/numerics/rationals.d.ts +56 -0
  68. package/dist/types/compute-engine/public.d.ts +200 -247
  69. package/dist/types/compute-engine/rules.d.ts +7 -1
  70. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  71. package/dist/types/compute-engine/solve.d.ts +17 -0
  72. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/flatten.d.ts +2 -1
  74. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  75. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  76. package/dist/types/compute-engine/symbolic/product.d.ts +30 -12
  77. package/dist/types/compute-engine/symbolic/sum.d.ts +13 -7
  78. package/dist/types/compute-engine/symbolic/utils.d.ts +7 -29
  79. package/dist/types/compute-engine.d.ts +2 -2
  80. package/dist/types/math-json/math-json-format.d.ts +2 -2
  81. package/dist/types/math-json/utils.d.ts +11 -41
  82. package/dist/types/math-json.d.ts +3 -3
  83. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- /** CortexJS Compute Engine 0.8.0 */
2
- var global,factory;global=this,factory=function(e){function i(e){return!("kind"in e)||"symbol"===e.kind}function t(e){return!("kind"in e)||"function"===e.kind}function n(e){return"kind"in e&&"matchfix"===e.kind}function r(e){return"kind"in e&&"infix"===e.kind}function a(e){return"kind"in e&&"prefix"===e.kind}function s(e){return"kind"in e&&"postfix"===e.kind}function o(e){return"kind"in e&&"environment"===e.kind}var l,u,c=9e15,h=1e9,m="0123456789abcdef",d="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",f="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",g={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-c,maxE:c,crypto:!1},p=!0,v="[DecimalError] ",b=v+"Invalid argument: ",y=v+"Precision limit exceeded",x=v+"crypto unavailable",N="[object Decimal]",_=Math.floor,S=Math.pow,w=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,E=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,k=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,I=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,A=1e7,M=d.length-1,F=f.length-1,O={toStringTag:N};function V(e){var i,t,n,r=e.length-1,a="",s=e[0];if(r>0){for(a+=s,i=1;i<r;i++)(t=7-(n=e[i]+"").length)&&(a+=Z(t)),a+=n;(t=7-(n=(s=e[i])+"").length)&&(a+=Z(t))}else if(0===s)return"0";for(;s%10==0;)s/=10;return a+s}function T(e,i,t){if(e!==~~e||e<i||e>t)throw Error(b+e)}function q(e,i,t,n){var r,a,s,o;for(a=e[0];a>=10;a/=10)--i;return--i<0?(i+=7,r=0):(r=Math.ceil((i+1)/7),i%=7),a=S(10,7-i),o=e[r]%a|0,null==n?i<3?(0==i?o=o/100|0:1==i&&(o=o/10|0),s=t<4&&99999==o||t>3&&49999==o||5e4==o||0==o):s=(t<4&&o+1==a||t>3&&o+1==a/2)&&(e[r+1]/a/100|0)==S(10,i-2)-1||(o==a/2||0==o)&&0==(e[r+1]/a/100|0):i<4?(0==i?o=o/1e3|0:1==i?o=o/100|0:2==i&&(o=o/10|0),s=(n||t<4)&&9999==o||!n&&t>3&&4999==o):s=((n||t<4)&&o+1==a||!n&&t>3&&o+1==a/2)&&(e[r+1]/a/1e3|0)==S(10,i-3)-1,s}function C(e,i,t){for(var n,r,a=[0],s=0,o=e.length;s<o;){for(r=a.length;r--;)a[r]*=i;for(a[0]+=m.indexOf(e.charAt(s++)),n=0;n<a.length;n++)a[n]>t-1&&(void 0===a[n+1]&&(a[n+1]=0),a[n+1]+=a[n]/t|0,a[n]%=t)}return a.reverse()}O.absoluteValue=O.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),P(e)},O.ceil=function(){return P(new this.constructor(this),this.e+1,2)},O.clampedTo=O.clamp=function(e,i){var t=this,n=t.constructor;if(e=new n(e),i=new n(i),!e.s||!i.s)return new n(NaN);if(e.gt(i))throw Error(b+i);return t.cmp(e)<0?e:t.cmp(i)>0?i:new n(t)},O.comparedTo=O.cmp=function(e){var i,t,n,r,a=this,s=a.d,o=(e=new a.constructor(e)).d,l=a.s,u=e.s;if(!s||!o)return l&&u?l!==u?l:s===o?0:!s^l<0?1:-1:NaN;if(!s[0]||!o[0])return s[0]?l:o[0]?-u:0;if(l!==u)return l;if(a.e!==e.e)return a.e>e.e^l<0?1:-1;for(i=0,t=(n=s.length)<(r=o.length)?n:r;i<t;++i)if(s[i]!==o[i])return s[i]>o[i]^l<0?1:-1;return n===r?0:n>r^l<0?1:-1},O.cosine=O.cos=function(){var e,i,t=this,n=t.constructor;return t.d?t.d[0]?(e=n.precision,i=n.rounding,n.precision=e+Math.max(t.e,t.sd())+7,n.rounding=1,t=function(e,i){var t,n,r;if(i.isZero())return i;(n=i.d.length)<32?r=""+1/X(4,t=Math.ceil(n/3)):(t=16,r="2.3283064365386962890625e-10"),e.precision+=t,i=J(e,1,i.times(r),new e(1));for(var a=t;a--;){var s=i.times(i);i=s.times(s).minus(s).times(8).plus(1)}return e.precision-=t,i}(n,ee(n,t)),n.precision=e,n.rounding=i,P(2==u||3==u?t.neg():t,e,i,!0)):new n(1):new n(NaN)},O.cubeRoot=O.cbrt=function(){var e,i,t,n,r,a,s,o,l,u,c=this,h=c.constructor;if(!c.isFinite()||c.isZero())return new h(c);for(p=!1,(a=c.s*S(c.s*c,1/3))&&Math.abs(a)!=1/0?n=new h(a.toString()):(t=V(c.d),(a=((e=c.e)-t.length+1)%3)&&(t+=1==a||-2==a?"0":"00"),a=S(t,1/3),e=_((e+1)/3)-(e%3==(e<0?-1:2)),(n=new h(t=a==1/0?"5e"+e:(t=a.toExponential()).slice(0,t.indexOf("e")+1)+e)).s=c.s),s=(e=h.precision)+3;;)if(u=(l=(o=n).times(o).times(o)).plus(c),n=D(u.plus(c).times(o),u.plus(l),s+2,1),V(o.d).slice(0,s)===(t=V(n.d)).slice(0,s)){if("9999"!=(t=t.slice(s-3,s+1))&&(r||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(P(n,e+1,1),i=!n.times(n).times(n).eq(c));break}if(!r&&(P(o,e+1,0),o.times(o).times(o).eq(c))){n=o;break}s+=4,r=1}return p=!0,P(n,e,h.rounding,i)},O.decimalPlaces=O.dp=function(){var e,i=this.d,t=NaN;if(i){if(t=7*((e=i.length-1)-_(this.e/7)),e=i[e])for(;e%10==0;e/=10)t--;t<0&&(t=0)}return t},O.dividedBy=O.div=function(e){return D(this,new this.constructor(e))},O.dividedToIntegerBy=O.divToInt=function(e){var i=this.constructor;return P(D(this,new i(e),0,1,1),i.precision,i.rounding)},O.equals=O.eq=function(e){return 0===this.cmp(e)},O.floor=function(){return P(new this.constructor(this),this.e+1,3)},O.greaterThan=O.gt=function(e){return this.cmp(e)>0},O.greaterThanOrEqualTo=O.gte=function(e){var i=this.cmp(e);return 1==i||0===i},O.hyperbolicCosine=O.cosh=function(){var e,i,t,n,r,a=this,s=a.constructor,o=new s(1);if(!a.isFinite())return new s(a.s?1/0:NaN);if(a.isZero())return o;t=s.precision,n=s.rounding,s.precision=t+Math.max(a.e,a.sd())+4,s.rounding=1,(r=a.d.length)<32?i=""+1/X(4,e=Math.ceil(r/3)):(e=16,i="2.3283064365386962890625e-10"),a=J(s,1,a.times(i),new s(1),!0);for(var l,u=e,c=new s(8);u--;)l=a.times(a),a=o.minus(l.times(c.minus(l.times(c))));return P(a,s.precision=t,s.rounding=n,!0)},O.hyperbolicSine=O.sinh=function(){var e,i,t,n,r=this,a=r.constructor;if(!r.isFinite()||r.isZero())return new a(r);if(i=a.precision,t=a.rounding,a.precision=i+Math.max(r.e,r.sd())+4,a.rounding=1,(n=r.d.length)<3)r=J(a,2,r,r,!0);else{e=(e=1.4*Math.sqrt(n))>16?16:0|e,r=J(a,2,r=r.times(1/X(5,e)),r,!0);for(var s,o=new a(5),l=new a(16),u=new a(20);e--;)s=r.times(r),r=r.times(o.plus(s.times(l.times(s).plus(u))))}return a.precision=i,a.rounding=t,P(r,i,t,!0)},O.hyperbolicTangent=O.tanh=function(){var e,i,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(e=n.precision,i=n.rounding,n.precision=e+7,n.rounding=1,D(t.sinh(),t.cosh(),n.precision=e,n.rounding=i)):new n(t.s)},O.inverseCosine=O.acos=function(){var e,i=this,t=i.constructor,n=i.abs().cmp(1),r=t.precision,a=t.rounding;return-1!==n?0===n?i.isNeg()?$(t,r,a):new t(0):new t(NaN):i.isZero()?$(t,r+4,a).times(.5):(t.precision=r+6,t.rounding=1,i=i.asin(),e=$(t,r+4,a).times(.5),t.precision=r,t.rounding=a,e.minus(i))},O.inverseHyperbolicCosine=O.acosh=function(){var e,i,t=this,n=t.constructor;return t.lte(1)?new n(t.eq(1)?0:NaN):t.isFinite()?(e=n.precision,i=n.rounding,n.precision=e+Math.max(Math.abs(t.e),t.sd())+4,n.rounding=1,p=!1,t=t.times(t).minus(1).sqrt().plus(t),p=!0,n.precision=e,n.rounding=i,t.ln()):new n(t)},O.inverseHyperbolicSine=O.asinh=function(){var e,i,t=this,n=t.constructor;return!t.isFinite()||t.isZero()?new n(t):(e=n.precision,i=n.rounding,n.precision=e+2*Math.max(Math.abs(t.e),t.sd())+6,n.rounding=1,p=!1,t=t.times(t).plus(1).sqrt().plus(t),p=!0,n.precision=e,n.rounding=i,t.ln())},O.inverseHyperbolicTangent=O.atanh=function(){var e,i,t,n,r=this,a=r.constructor;return r.isFinite()?r.e>=0?new a(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(e=a.precision,i=a.rounding,n=r.sd(),Math.max(n,e)<2*-r.e-1?P(new a(r),e,i,!0):(a.precision=t=n-r.e,r=D(r.plus(1),new a(1).minus(r),t+e,1),a.precision=e+4,a.rounding=1,r=r.ln(),a.precision=e,a.rounding=i,r.times(.5))):new a(NaN)},O.inverseSine=O.asin=function(){var e,i,t,n,r=this,a=r.constructor;return r.isZero()?new a(r):(i=r.abs().cmp(1),t=a.precision,n=a.rounding,-1!==i?0===i?((e=$(a,t+4,n).times(.5)).s=r.s,e):new a(NaN):(a.precision=t+6,a.rounding=1,r=r.div(new a(1).minus(r.times(r)).sqrt().plus(1)).atan(),a.precision=t,a.rounding=n,r.times(2)))},O.inverseTangent=O.atan=function(){var e,i,t,n,r,a,s,o,l,u=this,c=u.constructor,h=c.precision,m=c.rounding;if(u.isFinite()){if(u.isZero())return new c(u);if(u.abs().eq(1)&&h+4<=F)return(s=$(c,h+4,m).times(.25)).s=u.s,s}else{if(!u.s)return new c(NaN);if(h+4<=F)return(s=$(c,h+4,m).times(.5)).s=u.s,s}for(c.precision=o=h+10,c.rounding=1,e=t=Math.min(28,o/7+2|0);e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(p=!1,i=Math.ceil(o/7),n=1,l=u.times(u),s=new c(u),r=u;-1!==e;)if(r=r.times(l),a=s.minus(r.div(n+=2)),r=r.times(l),void 0!==(s=a.plus(r.div(n+=2))).d[i])for(e=i;s.d[e]===a.d[e]&&e--;);return t&&(s=s.times(2<<t-1)),p=!0,P(s,c.precision=h,c.rounding=m,!0)},O.isFinite=function(){return!!this.d},O.isInteger=O.isInt=function(){return!!this.d&&_(this.e/7)>this.d.length-2},O.isNaN=function(){return!this.s},O.isNegative=O.isNeg=function(){return this.s<0},O.isPositive=O.isPos=function(){return this.s>0},O.isZero=function(){return!!this.d&&0===this.d[0]},O.lessThan=O.lt=function(e){return this.cmp(e)<0},O.lessThanOrEqualTo=O.lte=function(e){return this.cmp(e)<1},O.logarithm=O.log=function(e){var i,t,n,r,a,s,o,l,u=this,c=u.constructor,h=c.precision,m=c.rounding;if(null==e)e=new c(10),i=!0;else{if(t=(e=new c(e)).d,e.s<0||!t||!t[0]||e.eq(1))return new c(NaN);i=e.eq(10)}if(t=u.d,u.s<0||!t||!t[0]||u.eq(1))return new c(t&&!t[0]?-1/0:1!=u.s?NaN:t?0:1/0);if(i)if(t.length>1)a=!0;else{for(r=t[0];r%10==0;)r/=10;a=1!==r}if(p=!1,s=U(u,o=h+5),n=i?z(c,o+10):U(e,o),q((l=D(s,n,o,1)).d,r=h,m))do{if(s=U(u,o+=10),n=i?z(c,o+10):U(e,o),l=D(s,n,o,1),!a){+V(l.d).slice(r+1,r+15)+1==1e14&&(l=P(l,h+1,0));break}}while(q(l.d,r+=10,m));return p=!0,P(l,h,m)},O.minus=O.sub=function(e){var i,t,n,r,a,s,o,l,u,c,h,m,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return d.s&&e.s?d.d?e.s=-e.s:e=new f(e.d||d.s!==e.s?d:NaN):e=new f(NaN),e;if(d.s!=e.s)return e.s=-e.s,d.plus(e);if(u=d.d,m=e.d,o=f.precision,l=f.rounding,!u[0]||!m[0]){if(m[0])e.s=-e.s;else{if(!u[0])return new f(3===l?-0:0);e=new f(d)}return p?P(e,o,l):e}if(t=_(e.e/7),c=_(d.e/7),u=u.slice(),a=c-t){for((h=a<0)?(i=u,a=-a,s=m.length):(i=m,t=c,s=u.length),a>(n=Math.max(Math.ceil(o/7),s)+2)&&(a=n,i.length=1),i.reverse(),n=a;n--;)i.push(0);i.reverse()}else{for((h=(n=u.length)<(s=m.length))&&(s=n),n=0;n<s;n++)if(u[n]!=m[n]){h=u[n]<m[n];break}a=0}for(h&&(i=u,u=m,m=i,e.s=-e.s),s=u.length,n=m.length-s;n>0;--n)u[s++]=0;for(n=m.length;n>a;){if(u[--n]<m[n]){for(r=n;r&&0===u[--r];)u[r]=A-1;--u[r],u[n]+=A}u[n]-=m[n]}for(;0===u[--s];)u.pop();for(;0===u[0];u.shift())--t;return u[0]?(e.d=u,e.e=R(u,t),p?P(e,o,l):e):new f(3===l?-0:0)},O.modulo=O.mod=function(e){var i,t=this,n=t.constructor;return e=new n(e),!t.d||!e.s||e.d&&!e.d[0]?new n(NaN):!e.d||t.d&&!t.d[0]?P(new n(t),n.precision,n.rounding):(p=!1,9==n.modulo?(i=D(t,e.abs(),0,3,1)).s*=e.s:i=D(t,e,0,n.modulo,1),i=i.times(e),p=!0,t.minus(i))},O.naturalExponential=O.exp=function(){return W(this)},O.naturalLogarithm=O.ln=function(){return U(this)},O.negated=O.neg=function(){var e=new this.constructor(this);return e.s=-e.s,P(e)},O.plus=O.add=function(e){var i,t,n,r,a,s,o,l,u,c,h=this,m=h.constructor;if(e=new m(e),!h.d||!e.d)return h.s&&e.s?h.d||(e=new m(e.d||h.s===e.s?h:NaN)):e=new m(NaN),e;if(h.s!=e.s)return e.s=-e.s,h.minus(e);if(u=h.d,c=e.d,o=m.precision,l=m.rounding,!u[0]||!c[0])return c[0]||(e=new m(h)),p?P(e,o,l):e;if(a=_(h.e/7),n=_(e.e/7),u=u.slice(),r=a-n){for(r<0?(t=u,r=-r,s=c.length):(t=c,n=a,s=u.length),r>(s=(a=Math.ceil(o/7))>s?a+1:s+1)&&(r=s,t.length=1),t.reverse();r--;)t.push(0);t.reverse()}for((s=u.length)-(r=c.length)<0&&(r=s,t=c,c=u,u=t),i=0;r;)i=(u[--r]=u[r]+c[r]+i)/A|0,u[r]%=A;for(i&&(u.unshift(i),++n),s=u.length;0==u[--s];)u.pop();return e.d=u,e.e=R(u,n),p?P(e,o,l):e},O.precision=O.sd=function(e){var i,t=this;if(void 0!==e&&e!==!!e&&1!==e&&0!==e)throw Error(b+e);return t.d?(i=j(t.d),e&&t.e+1>i&&(i=t.e+1)):i=NaN,i},O.round=function(){var e=this,i=e.constructor;return P(new i(e),e.e+1,i.rounding)},O.sine=O.sin=function(){var e,i,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(e=n.precision,i=n.rounding,n.precision=e+Math.max(t.e,t.sd())+7,n.rounding=1,t=function(e,i){var t,n=i.d.length;if(n<3)return i.isZero()?i:J(e,2,i,i);t=(t=1.4*Math.sqrt(n))>16?16:0|t,i=J(e,2,i=i.times(1/X(5,t)),i);for(var r,a=new e(5),s=new e(16),o=new e(20);t--;)r=i.times(i),i=i.times(a.plus(r.times(s.times(r).minus(o))));return i}(n,ee(n,t)),n.precision=e,n.rounding=i,P(u>2?t.neg():t,e,i,!0)):new n(NaN)},O.squareRoot=O.sqrt=function(){var e,i,t,n,r,a,s=this,o=s.d,l=s.e,u=s.s,c=s.constructor;if(1!==u||!o||!o[0])return new c(!u||u<0&&(!o||o[0])?NaN:o?s:1/0);for(p=!1,0==(u=Math.sqrt(+s))||u==1/0?(((i=V(o)).length+l)%2==0&&(i+="0"),u=Math.sqrt(i),l=_((l+1)/2)-(l<0||l%2),n=new c(i=u==1/0?"5e"+l:(i=u.toExponential()).slice(0,i.indexOf("e")+1)+l)):n=new c(u.toString()),t=(l=c.precision)+3;;)if(n=(a=n).plus(D(s,a,t+2,1)).times(.5),V(a.d).slice(0,t)===(i=V(n.d)).slice(0,t)){if("9999"!=(i=i.slice(t-3,t+1))&&(r||"4999"!=i)){+i&&(+i.slice(1)||"5"!=i.charAt(0))||(P(n,l+1,1),e=!n.times(n).eq(s));break}if(!r&&(P(a,l+1,0),a.times(a).eq(s))){n=a;break}t+=4,r=1}return p=!0,P(n,l,c.rounding,e)},O.tangent=O.tan=function(){var e,i,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(e=n.precision,i=n.rounding,n.precision=e+10,n.rounding=1,(t=t.sin()).s=1,t=D(t,new n(1).minus(t.times(t)).sqrt(),e+10,0),n.precision=e,n.rounding=i,P(2==u||4==u?t.neg():t,e,i,!0)):new n(NaN)},O.times=O.mul=function(e){var i,t,n,r,a,s,o,l,u,c=this,h=c.constructor,m=c.d,d=(e=new h(e)).d;if(e.s*=c.s,!(m&&m[0]&&d&&d[0]))return new h(!e.s||m&&!m[0]&&!d||d&&!d[0]&&!m?NaN:m&&d?0*e.s:e.s/0);for(t=_(c.e/7)+_(e.e/7),(l=m.length)<(u=d.length)&&(a=m,m=d,d=a,s=l,l=u,u=s),a=[],n=s=l+u;n--;)a.push(0);for(n=u;--n>=0;){for(i=0,r=l+n;r>n;)o=a[r]+d[n]*m[r-n-1]+i,a[r--]=o%A|0,i=o/A|0;a[r]=(a[r]+i)%A|0}for(;!a[--s];)a.pop();return i?++t:a.shift(),e.d=a,e.e=R(a,t),p?P(e,h.precision,h.rounding):e},O.toBinary=function(e,i){return ie(this,2,e,i)},O.toDecimalPlaces=O.toDP=function(e,i){var t=this,n=t.constructor;return t=new n(t),void 0===e?t:(T(e,0,h),void 0===i?i=n.rounding:T(i,0,8),P(t,e+t.e+1,i))},O.toExponential=function(e,i){var t,n=this,r=n.constructor;return void 0===e?t=L(n,!0):(T(e,0,h),void 0===i?i=r.rounding:T(i,0,8),t=L(n=P(new r(n),e+1,i),!0,e+1)),n.isNeg()&&!n.isZero()?"-"+t:t},O.toFixed=function(e,i){var t,n,r=this,a=r.constructor;return void 0===e?t=L(r):(T(e,0,h),void 0===i?i=a.rounding:T(i,0,8),t=L(n=P(new a(r),e+r.e+1,i),!1,e+n.e+1)),r.isNeg()&&!r.isZero()?"-"+t:t},O.toFraction=function(e){var i,t,n,r,a,s,o,l,u,c,h,m,d=this,f=d.d,g=d.constructor;if(!f)return new g(d);if(u=t=new g(1),n=l=new g(0),s=(a=(i=new g(n)).e=j(f)-d.e-1)%7,i.d[0]=S(10,s<0?7+s:s),null==e)e=a>0?i:u;else{if(!(o=new g(e)).isInt()||o.lt(u))throw Error(b+o);e=o.gt(i)?a>0?i:u:o}for(p=!1,o=new g(V(f)),c=g.precision,g.precision=a=7*f.length*2;h=D(o,i,0,1,1),1!=(r=t.plus(h.times(n))).cmp(e);)t=n,n=r,r=u,u=l.plus(h.times(r)),l=r,r=i,i=o.minus(h.times(r)),o=r;return r=D(e.minus(t),n,0,1,1),l=l.plus(r.times(u)),t=t.plus(r.times(n)),l.s=u.s=d.s,m=D(u,n,a,1).minus(d).abs().cmp(D(l,t,a,1).minus(d).abs())<1?[u,n]:[l,t],g.precision=c,p=!0,m},O.toHexadecimal=O.toHex=function(e,i){return ie(this,16,e,i)},O.toNearest=function(e,i){var t=this,n=t.constructor;if(t=new n(t),null==e){if(!t.d)return t;e=new n(1),i=n.rounding}else{if(e=new n(e),void 0===i?i=n.rounding:T(i,0,8),!t.d)return e.s?t:e;if(!e.d)return e.s&&(e.s=t.s),e}return e.d[0]?(p=!1,t=D(t,e,0,i,1).times(e),p=!0,P(t)):(e.s=t.s,t=e),t},O.toNumber=function(){return+this},O.toOctal=function(e,i){return ie(this,8,e,i)},O.toPower=O.pow=function(e){var i,t,n,r,a,s,o=this,l=o.constructor,u=+(e=new l(e));if(!(o.d&&e.d&&o.d[0]&&e.d[0]))return new l(S(+o,u));if((o=new l(o)).eq(1))return o;if(n=l.precision,a=l.rounding,e.eq(1))return P(o,n,a);if((i=_(e.e/7))>=e.d.length-1&&(t=u<0?-u:u)<=9007199254740991)return r=B(l,o,t,n),e.s<0?new l(1).div(r):P(r,n,a);if((s=o.s)<0){if(i<e.d.length-1)return new l(NaN);if(0==(1&e.d[i])&&(s=1),0==o.e&&1==o.d[0]&&1==o.d.length)return o.s=s,o}return(i=0!=(t=S(+o,u))&&isFinite(t)?new l(t+"").e:_(u*(Math.log("0."+V(o.d))/Math.LN10+o.e+1)))>l.maxE+1||i<l.minE-1?new l(i>0?s/0:0):(p=!1,l.rounding=o.s=1,t=Math.min(12,(i+"").length),(r=W(e.times(U(o,n+t)),n)).d&&q((r=P(r,n+5,1)).d,n,a)&&(i=n+10,+V((r=P(W(e.times(U(o,i+t)),i),i+5,1)).d).slice(n+1,n+15)+1==1e14&&(r=P(r,n+1,0))),r.s=s,p=!0,l.rounding=a,P(r,n,a))},O.toPrecision=function(e,i){var t,n=this,r=n.constructor;return void 0===e?t=L(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(T(e,1,h),void 0===i?i=r.rounding:T(i,0,8),t=L(n=P(new r(n),e,i),e<=n.e||n.e<=r.toExpNeg,e)),n.isNeg()&&!n.isZero()?"-"+t:t},O.toSignificantDigits=O.toSD=function(e,i){var t=this.constructor;return void 0===e?(e=t.precision,i=t.rounding):(T(e,1,h),void 0===i?i=t.rounding:T(i,0,8)),P(new t(this),e,i)},O.toString=function(){var e=this,i=e.constructor,t=L(e,e.e<=i.toExpNeg||e.e>=i.toExpPos);return e.isNeg()&&!e.isZero()?"-"+t:t},O.truncated=O.trunc=function(){return P(new this.constructor(this),this.e+1,1)},O.valueOf=O.toJSON=function(){var e=this,i=e.constructor,t=L(e,e.e<=i.toExpNeg||e.e>=i.toExpPos);return e.isNeg()?"-"+t:t};var D=function(){function e(e,i,t){var n,r=0,a=e.length;for(e=e.slice();a--;)n=e[a]*i+r,e[a]=n%t|0,r=n/t|0;return r&&e.unshift(r),e}function i(e,i,t,n){var r,a;if(t!=n)a=t>n?1:-1;else for(r=a=0;r<t;r++)if(e[r]!=i[r]){a=e[r]>i[r]?1:-1;break}return a}function t(e,i,t,n){for(var r=0;t--;)e[t]-=r,r=e[t]<i[t]?1:0,e[t]=r*n+e[t]-i[t];for(;!e[0]&&e.length>1;)e.shift()}return function(n,r,a,s,o,u){var c,h,m,d,f,g,p,v,b,y,x,N,S,w,E,k,I,M,F,O,V=n.constructor,T=n.s==r.s?1:-1,q=n.d,C=r.d;if(!(q&&q[0]&&C&&C[0]))return new V(n.s&&r.s&&(q?!C||q[0]!=C[0]:C)?q&&0==q[0]||!C?0*T:T/0:NaN);for(u?(f=1,h=n.e-r.e):(u=A,f=7,h=_(n.e/f)-_(r.e/f)),F=C.length,I=q.length,y=(b=new V(T)).d=[],m=0;C[m]==(q[m]||0);m++);if(C[m]>(q[m]||0)&&h--,null==a?(w=a=V.precision,s=V.rounding):w=o?a+(n.e-r.e)+1:a,w<0)y.push(1),g=!0;else{if(w=w/f+2|0,m=0,1==F){for(d=0,C=C[0],w++;(m<I||d)&&w--;m++)E=d*u+(q[m]||0),y[m]=E/C|0,d=E%C|0;g=d||m<I}else{for((d=u/(C[0]+1)|0)>1&&(C=e(C,d,u),q=e(q,d,u),F=C.length,I=q.length),k=F,N=(x=q.slice(0,F)).length;N<F;)x[N++]=0;(O=C.slice()).unshift(0),M=C[0],C[1]>=u/2&&++M;do{d=0,(c=i(C,x,F,N))<0?(S=x[0],F!=N&&(S=S*u+(x[1]||0)),(d=S/M|0)>1?(d>=u&&(d=u-1),1==(c=i(p=e(C,d,u),x,v=p.length,N=x.length))&&(d--,t(p,F<v?O:C,v,u))):(0==d&&(c=d=1),p=C.slice()),(v=p.length)<N&&p.unshift(0),t(x,p,N,u),-1==c&&(c=i(C,x,F,N=x.length))<1&&(d++,t(x,F<N?O:C,N,u)),N=x.length):0===c&&(d++,x=[0]),y[m++]=d,c&&x[0]?x[N++]=q[k]||0:(x=[q[k]],N=1)}while((k++<I||void 0!==x[0])&&w--);g=void 0!==x[0]}y[0]||y.shift()}if(1==f)b.e=h,l=g;else{for(m=1,d=y[0];d>=10;d/=10)m++;b.e=m+h*f-1,P(b,o?a+b.e+1:a,s,g)}return b}}();function P(e,i,t,n){var r,a,s,o,l,u,c,h,m,d=e.constructor;e:if(null!=i){if(!(h=e.d))return e;for(r=1,o=h[0];o>=10;o/=10)r++;if((a=i-r)<0)a+=7,s=i,l=(c=h[m=0])/S(10,r-s-1)%10|0;else if((m=Math.ceil((a+1)/7))>=(o=h.length)){if(!n)break e;for(;o++<=m;)h.push(0);c=l=0,r=1,s=(a%=7)-7+1}else{for(c=o=h[m],r=1;o>=10;o/=10)r++;l=(s=(a%=7)-7+r)<0?0:c/S(10,r-s-1)%10|0}if(n=n||i<0||void 0!==h[m+1]||(s<0?c:c%S(10,r-s-1)),u=t<4?(l||n)&&(0==t||t==(e.s<0?3:2)):l>5||5==l&&(4==t||n||6==t&&(a>0?s>0?c/S(10,r-s):0:h[m-1])%10&1||t==(e.s<0?8:7)),i<1||!h[0])return h.length=0,u?(i-=e.e+1,h[0]=S(10,(7-i%7)%7),e.e=-i||0):h[0]=e.e=0,e;if(0==a?(h.length=m,o=1,m--):(h.length=m+1,o=S(10,7-a),h[m]=s>0?(c/S(10,r-s)%S(10,s)|0)*o:0),u)for(;;){if(0==m){for(a=1,s=h[0];s>=10;s/=10)a++;for(s=h[0]+=o,o=1;s>=10;s/=10)o++;a!=o&&(e.e++,h[0]==A&&(h[0]=1));break}if(h[m]+=o,h[m]!=A)break;h[m--]=0,o=1}for(a=h.length;0===h[--a];)h.pop()}return p&&(e.e>d.maxE?(e.d=null,e.e=NaN):e.e<d.minE&&(e.e=0,e.d=[0])),e}function L(e,i,t){if(!e.isFinite())return Q(e);var n,r=e.e,a=V(e.d),s=a.length;return i?(t&&(n=t-s)>0?a=a.charAt(0)+"."+a.slice(1)+Z(n):s>1&&(a=a.charAt(0)+"."+a.slice(1)),a=a+(e.e<0?"e":"e+")+e.e):r<0?(a="0."+Z(-r-1)+a,t&&(n=t-s)>0&&(a+=Z(n))):r>=s?(a+=Z(r+1-s),t&&(n=t-r-1)>0&&(a=a+"."+Z(n))):((n=r+1)<s&&(a=a.slice(0,n)+"."+a.slice(n)),t&&(n=t-s)>0&&(r+1===s&&(a+="."),a+=Z(n))),a}function R(e,i){var t=e[0];for(i*=7;t>=10;t/=10)i++;return i}function z(e,i,t){if(i>M)throw p=!0,t&&(e.precision=t),Error(y);return P(new e(d),i,1,!0)}function $(e,i,t){if(i>F)throw Error(y);return P(new e(f),i,t,!0)}function j(e){var i=e.length-1,t=7*i+1;if(i=e[i]){for(;i%10==0;i/=10)t--;for(i=e[0];i>=10;i/=10)t++}return t}function Z(e){for(var i="";e--;)i+="0";return i}function B(e,i,t,n){var r,a=new e(1),s=Math.ceil(n/7+4);for(p=!1;;){if(t%2&&te((a=a.times(i)).d,s)&&(r=!0),0===(t=_(t/2))){t=a.d.length-1,r&&0===a.d[t]&&++a.d[t];break}te((i=i.times(i)).d,s)}return p=!0,a}function G(e){return 1&e.d[e.d.length-1]}function H(e,i,t){for(var n,r=new e(i[0]),a=0;++a<i.length;){if(!(n=new e(i[a])).s){r=n;break}r[t](n)&&(r=n)}return r}function W(e,i){var t,n,r,a,s,o,l,u=0,c=0,h=0,m=e.constructor,d=m.rounding,f=m.precision;if(!e.d||!e.d[0]||e.e>17)return new m(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(null==i?(p=!1,l=f):l=i,o=new m(.03125);e.e>-2;)e=e.times(o),h+=5;for(l+=n=Math.log(S(2,h))/Math.LN10*2+5|0,t=a=s=new m(1),m.precision=l;;){if(a=P(a.times(e),l,1),t=t.times(++c),V((o=s.plus(D(a,t,l,1))).d).slice(0,l)===V(s.d).slice(0,l)){for(r=h;r--;)s=P(s.times(s),l,1);if(null!=i)return m.precision=f,s;if(!(u<3&&q(s.d,l-n,d,u)))return P(s,m.precision=f,d,p=!0);m.precision=l+=10,t=a=o=new m(1),c=0,u++}s=o}}function U(e,i){var t,n,r,a,s,o,l,u,c,h,m,d=1,f=e,g=f.d,v=f.constructor,b=v.rounding,y=v.precision;if(f.s<0||!g||!g[0]||!f.e&&1==g[0]&&1==g.length)return new v(g&&!g[0]?-1/0:1!=f.s?NaN:g?0:f);if(null==i?(p=!1,c=y):c=i,v.precision=c+=10,n=(t=V(g)).charAt(0),!(Math.abs(a=f.e)<15e14))return u=z(v,c+2,y).times(a+""),f=U(new v(n+"."+t.slice(1)),c-10).plus(u),v.precision=y,null==i?P(f,y,b,p=!0):f;for(;n<7&&1!=n||1==n&&t.charAt(1)>3;)n=(t=V((f=f.times(e)).d)).charAt(0),d++;for(a=f.e,n>1?(f=new v("0."+t),a++):f=new v(n+"."+t.slice(1)),h=f,l=s=f=D(f.minus(1),f.plus(1),c,1),m=P(f.times(f),c,1),r=3;;){if(s=P(s.times(m),c,1),V((u=l.plus(D(s,new v(r),c,1))).d).slice(0,c)===V(l.d).slice(0,c)){if(l=l.times(2),0!==a&&(l=l.plus(z(v,c+2,y).times(a+""))),l=D(l,new v(d),c,1),null!=i)return v.precision=y,l;if(!q(l.d,c-10,b,o))return P(l,v.precision=y,b,p=!0);v.precision=c+=10,u=s=f=D(h.minus(1),h.plus(1),c,1),m=P(f.times(f),c,1),r=o=1}l=u,r+=2}}function Q(e){return e.s*e.s/0+""}function Y(e,i){var t,n,r;for((t=i.indexOf("."))>-1&&(i=i.replace(".","")),(n=i.search(/e/i))>0?(t<0&&(t=n),t+=+i.slice(n+1),i=i.substring(0,n)):t<0&&(t=i.length),n=0;48===i.charCodeAt(n);n++);for(r=i.length;48===i.charCodeAt(r-1);--r);if(i=i.slice(n,r)){if(r-=n,e.e=t=t-n-1,e.d=[],n=(t+1)%7,t<0&&(n+=7),n<r){for(n&&e.d.push(+i.slice(0,n)),r-=7;n<r;)e.d.push(+i.slice(n,n+=7));n=7-(i=i.slice(n)).length}else n-=r;for(;n--;)i+="0";e.d.push(+i),p&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function K(e,i){var t,n,r,a,s,o,l,u,c;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),I.test(i))return Y(e,i)}else if("Infinity"===i||"NaN"===i)return+i||(e.s=NaN),e.e=NaN,e.d=null,e;if(E.test(i))t=16,i=i.toLowerCase();else if(w.test(i))t=2;else{if(!k.test(i))throw Error(b+i);t=8}for((a=i.search(/p/i))>0?(l=+i.slice(a+1),i=i.substring(2,a)):i=i.slice(2),s=(a=i.indexOf("."))>=0,n=e.constructor,s&&(a=(o=(i=i.replace(".","")).length)-a,r=B(n,new n(t),a,2*a)),a=c=(u=C(i,t,A)).length-1;0===u[a];--a)u.pop();return a<0?new n(0*e.s):(e.e=R(u,c),e.d=u,p=!1,s&&(e=D(e,r,4*o)),l&&(e=e.times(Math.abs(l)<54?S(2,l):Ze.pow(2,l))),p=!0,e)}function J(e,i,t,n,r){var a,s,o,l,u=e.precision,c=Math.ceil(u/7);for(p=!1,l=t.times(t),o=new e(n);;){if(s=D(o.times(l),new e(i++*i++),u,1),o=r?n.plus(s):n.minus(s),n=D(s.times(l),new e(i++*i++),u,1),void 0!==(s=o.plus(n)).d[c]){for(a=c;s.d[a]===o.d[a]&&a--;);if(-1==a)break}a=o,o=n,n=s,s=a}return p=!0,s.d.length=c+1,s}function X(e,i){for(var t=e;--i;)t*=e;return t}function ee(e,i){var t,n=i.s<0,r=$(e,e.precision,1),a=r.times(.5);if((i=i.abs()).lte(a))return u=n?4:1,i;if((t=i.divToInt(r)).isZero())u=n?3:2;else{if((i=i.minus(t.times(r))).lte(a))return u=G(t)?n?2:3:n?4:1,i;u=G(t)?n?1:4:n?3:2}return i.minus(r).abs()}function ie(e,i,t,n){var r,a,s,o,u,c,d,f,g,p=e.constructor,v=void 0!==t;if(v?(T(t,1,h),void 0===n?n=p.rounding:T(n,0,8)):(t=p.precision,n=p.rounding),e.isFinite()){for(v?(r=2,16==i?t=4*t-3:8==i&&(t=3*t-2)):r=i,(s=(d=L(e)).indexOf("."))>=0&&(d=d.replace(".",""),(g=new p(1)).e=d.length-s,g.d=C(L(g),10,r),g.e=g.d.length),a=u=(f=C(d,10,r)).length;0==f[--u];)f.pop();if(f[0]){if(s<0?a--:((e=new p(e)).d=f,e.e=a,f=(e=D(e,g,t,n,0,r)).d,a=e.e,c=l),s=f[t],o=r/2,c=c||void 0!==f[t+1],c=n<4?(void 0!==s||c)&&(0===n||n===(e.s<0?3:2)):s>o||s===o&&(4===n||c||6===n&&1&f[t-1]||n===(e.s<0?8:7)),f.length=t,c)for(;++f[--t]>r-1;)f[t]=0,t||(++a,f.unshift(1));for(u=f.length;!f[u-1];--u);for(s=0,d="";s<u;s++)d+=m.charAt(f[s]);if(v){if(u>1)if(16==i||8==i){for(s=16==i?4:3,--u;u%s;u++)d+="0";for(u=(f=C(d,r,i)).length;!f[u-1];--u);for(s=1,d="1.";s<u;s++)d+=m.charAt(f[s])}else d=d.charAt(0)+"."+d.slice(1);d=d+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)d="0"+d;d="0."+d}else if(++a>u)for(a-=u;a--;)d+="0";else a<u&&(d=d.slice(0,a)+"."+d.slice(a))}else d=v?"0p+0":"0";d=(16==i?"0x":2==i?"0b":8==i?"0o":"")+d}else d=Q(e);return e.s<0?"-"+d:d}function te(e,i){if(e.length>i)return e.length=i,!0}function ne(e){return new this(e).abs()}function re(e){return new this(e).acos()}function ae(e){return new this(e).acosh()}function se(e,i){return new this(e).plus(i)}function oe(e){return new this(e).asin()}function le(e){return new this(e).asinh()}function ue(e){return new this(e).atan()}function ce(e){return new this(e).atanh()}function he(e,i){e=new this(e),i=new this(i);var t,n=this.precision,r=this.rounding,a=n+4;return e.s&&i.s?e.d||i.d?!i.d||e.isZero()?(t=i.s<0?$(this,n,r):new this(0)).s=e.s:!e.d||i.isZero()?(t=$(this,a,1).times(.5)).s=e.s:i.s<0?(this.precision=a,this.rounding=1,t=this.atan(D(e,i,a,1)),i=$(this,a,1),this.precision=n,this.rounding=r,t=e.s<0?t.minus(i):t.plus(i)):t=this.atan(D(e,i,a,1)):(t=$(this,a,1).times(i.s>0?.25:.75)).s=e.s:t=new this(NaN),t}function me(e){return new this(e).cbrt()}function de(e){return P(e=new this(e),e.e+1,2)}function fe(e,i,t){return new this(e).clamp(i,t)}function ge(e){if(!e||"object"!=typeof e)throw Error(v+"Object expected");var i,t,n,r=!0===e.defaults,a=["precision",1,h,"rounding",0,8,"toExpNeg",-c,0,"toExpPos",0,c,"maxE",0,c,"minE",-c,0,"modulo",0,9];for(i=0;i<a.length;i+=3)if(t=a[i],r&&(this[t]=g[t]),void 0!==(n=e[t])){if(!(_(n)===n&&n>=a[i+1]&&n<=a[i+2]))throw Error(b+t+": "+n);this[t]=n}if(t="crypto",r&&(this[t]=g[t]),void 0!==(n=e[t])){if(!0!==n&&!1!==n&&0!==n&&1!==n)throw Error(b+t+": "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(x);this[t]=!0}else this[t]=!1}return this}function pe(e){return new this(e).cos()}function ve(e){return new this(e).cosh()}function be(e,i){return new this(e).div(i)}function ye(e){return new this(e).exp()}function xe(e){return P(e=new this(e),e.e+1,3)}function Ne(){var e,i,t=new this(0);for(p=!1,e=0;e<arguments.length;)if((i=new this(arguments[e++])).d)t.d&&(t=t.plus(i.times(i)));else{if(i.s)return p=!0,new this(1/0);t=i}return p=!0,t.sqrt()}function _e(e){return e instanceof Ze||e&&e.toStringTag===N||!1}function Se(e){return new this(e).ln()}function we(e,i){return new this(e).log(i)}function Ee(e){return new this(e).log(2)}function ke(e){return new this(e).log(10)}function Ie(){return H(this,arguments,"lt")}function Ae(){return H(this,arguments,"gt")}function Me(e,i){return new this(e).mod(i)}function Fe(e,i){return new this(e).mul(i)}function Oe(e,i){return new this(e).pow(i)}function Ve(e){var i,t,n,r,a=0,s=new this(1),o=[];if(void 0===e?e=this.precision:T(e,1,h),n=Math.ceil(e/7),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(n));a<n;)(r=i[a])>=429e7?i[a]=crypto.getRandomValues(new Uint32Array(1))[0]:o[a++]=r%1e7;else{if(!crypto.randomBytes)throw Error(x);for(i=crypto.randomBytes(n*=4);a<n;)(r=i[a]+(i[a+1]<<8)+(i[a+2]<<16)+((127&i[a+3])<<24))>=214e7?crypto.randomBytes(4).copy(i,a):(o.push(r%1e7),a+=4);a=n/4}else for(;a<n;)o[a++]=1e7*Math.random()|0;for(e%=7,(n=o[--a])&&e&&(r=S(10,7-e),o[a]=(n/r|0)*r);0===o[a];a--)o.pop();if(a<0)t=0,o=[0];else{for(t=-1;0===o[0];t-=7)o.shift();for(n=1,r=o[0];r>=10;r/=10)n++;n<7&&(t-=7-n)}return s.e=t,s.d=o,s}function Te(e){return P(e=new this(e),e.e+1,this.rounding)}function qe(e){return(e=new this(e)).d?e.d[0]?e.s:0*e.s:e.s||NaN}function Ce(e){return new this(e).sin()}function De(e){return new this(e).sinh()}function Pe(e){return new this(e).sqrt()}function Le(e,i){return new this(e).sub(i)}function Re(){var e=0,i=arguments,t=new this(i[e]);for(p=!1;t.s&&++e<i.length;)t=t.plus(i[e]);return p=!0,P(t,this.precision,this.rounding)}function ze(e){return new this(e).tan()}function $e(e){return new this(e).tanh()}function je(e){return P(e=new this(e),e.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString,O[Symbol.toStringTag]="Decimal";var Ze=O.constructor=function e(i){var t,n,r;function a(e){var i,t,n,r=this;if(!(r instanceof a))return new a(e);if(r.constructor=a,_e(e))return r.s=e.s,void(p?!e.d||e.e>a.maxE?(r.e=NaN,r.d=null):e.e<a.minE?(r.e=0,r.d=[0]):(r.e=e.e,r.d=e.d.slice()):(r.e=e.e,r.d=e.d?e.d.slice():e.d));if("number"==(n=typeof e)){if(0===e)return r.s=1/e<0?-1:1,r.e=0,void(r.d=[0]);if(e<0?(e=-e,r.s=-1):r.s=1,e===~~e&&e<1e7){for(i=0,t=e;t>=10;t/=10)i++;return void(p?i>a.maxE?(r.e=NaN,r.d=null):i<a.minE?(r.e=0,r.d=[0]):(r.e=i,r.d=[e]):(r.e=i,r.d=[e]))}return 0*e!=0?(e||(r.s=NaN),r.e=NaN,void(r.d=null)):Y(r,e.toString())}if("string"!==n)throw Error(b+e);return 45===(t=e.charCodeAt(0))?(e=e.slice(1),r.s=-1):(43===t&&(e=e.slice(1)),r.s=1),I.test(e)?Y(r,e):K(r,e)}if(a.prototype=O,a.ROUND_UP=0,a.ROUND_DOWN=1,a.ROUND_CEIL=2,a.ROUND_FLOOR=3,a.ROUND_HALF_UP=4,a.ROUND_HALF_DOWN=5,a.ROUND_HALF_EVEN=6,a.ROUND_HALF_CEIL=7,a.ROUND_HALF_FLOOR=8,a.EUCLID=9,a.config=a.set=ge,a.clone=e,a.isDecimal=_e,a.abs=ne,a.acos=re,a.acosh=ae,a.add=se,a.asin=oe,a.asinh=le,a.atan=ue,a.atanh=ce,a.atan2=he,a.cbrt=me,a.ceil=de,a.clamp=fe,a.cos=pe,a.cosh=ve,a.div=be,a.exp=ye,a.floor=xe,a.hypot=Ne,a.ln=Se,a.log=we,a.log10=ke,a.log2=Ee,a.max=Ie,a.min=Ae,a.mod=Me,a.mul=Fe,a.pow=Oe,a.random=Ve,a.round=Te,a.sign=qe,a.sin=Ce,a.sinh=De,a.sqrt=Pe,a.sub=Le,a.sum=Re,a.tan=ze,a.tanh=$e,a.trunc=je,void 0===i&&(i={}),i&&!0!==i.defaults)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)i.hasOwnProperty(n=r[t++])||(i[n]=this[n]);return a.config(i),a}(g);d=new Ze(d),f=new Ze(f);var Be={exports:{}};!function(e,i){!function(i){var t=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:.5*(Math.exp(e)+Math.exp(-e))},n=Math.sinh||function(e){return Math.abs(e)<1e-9?e:.5*(Math.exp(e)-Math.exp(-e))},r=function(){throw SyntaxError("Invalid Param")};function a(e,i){var t=Math.abs(e),n=Math.abs(i);return 0===e?Math.log(n):0===i?Math.log(t):t<3e3&&n<3e3?.5*Math.log(e*e+i*i):.5*Math.log((e/=2)*e+(i/=2)*i)+Math.LN2}function s(e,i){if(!(this instanceof s))return new s(e,i);var t=function(e,i){var t={re:0,im:0};if(null==e)t.re=t.im=0;else if(void 0!==i)t.re=e,t.im=i;else switch(typeof e){case"object":if("im"in e&&"re"in e)t.re=e.re,t.im=e.im;else if("abs"in e&&"arg"in e){if(!Number.isFinite(e.abs)&&Number.isFinite(e.arg))return s.INFINITY;t.re=e.abs*Math.cos(e.arg),t.im=e.abs*Math.sin(e.arg)}else if("r"in e&&"phi"in e){if(!Number.isFinite(e.r)&&Number.isFinite(e.phi))return s.INFINITY;t.re=e.r*Math.cos(e.phi),t.im=e.r*Math.sin(e.phi)}else 2===e.length?(t.re=e[0],t.im=e[1]):r();break;case"string":t.im=t.re=0;var n=e.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),a=1,o=0;null===n&&r();for(var l=0;l<n.length;l++){var u=n[l];" "===u||"\t"===u||"\n"===u||("+"===u?a++:"-"===u?o++:"i"===u||"I"===u?(a+o===0&&r()," "===n[l+1]||isNaN(n[l+1])?t.im+=parseFloat((o%2?"-":"")+"1"):(t.im+=parseFloat((o%2?"-":"")+n[l+1]),l++),a=o=0):((a+o===0||isNaN(u))&&r(),"i"===n[l+1]||"I"===n[l+1]?(t.im+=parseFloat((o%2?"-":"")+u),l++):t.re+=parseFloat((o%2?"-":"")+u),a=o=0))}a+o>0&&r();break;case"number":t.im=0,t.re=e;break;default:r()}return isNaN(t.re)||t.im,t}(e,i);this.re=t.re,this.im=t.im}s.prototype={re:0,im:0,sign:function(){var e=this.abs();return new s(this.re/e,this.im/e)},add:function(e,i){var t=new s(e,i);return this.isInfinite()&&t.isInfinite()?s.NAN:this.isInfinite()||t.isInfinite()?s.INFINITY:new s(this.re+t.re,this.im+t.im)},sub:function(e,i){var t=new s(e,i);return this.isInfinite()&&t.isInfinite()?s.NAN:this.isInfinite()||t.isInfinite()?s.INFINITY:new s(this.re-t.re,this.im-t.im)},mul:function(e,i){var t=new s(e,i);return this.isInfinite()&&t.isZero()||this.isZero()&&t.isInfinite()?s.NAN:this.isInfinite()||t.isInfinite()?s.INFINITY:0===t.im&&0===this.im?new s(this.re*t.re,0):new s(this.re*t.re-this.im*t.im,this.re*t.im+this.im*t.re)},div:function(e,i){var t=new s(e,i);if(this.isZero()&&t.isZero()||this.isInfinite()&&t.isInfinite())return s.NAN;if(this.isInfinite()||t.isZero())return s.INFINITY;if(this.isZero()||t.isInfinite())return s.ZERO;e=this.re,i=this.im;var n,r,a=t.re,o=t.im;return 0===o?new s(e/a,i/a):Math.abs(a)<Math.abs(o)?new s((e*(r=a/o)+i)/(n=a*r+o),(i*r-e)/n):new s((e+i*(r=o/a))/(n=o*r+a),(i-e*r)/n)},pow:function(e,i){var t=new s(e,i);if(e=this.re,i=this.im,t.isZero())return s.ONE;if(0===t.im){if(0===i&&e>0)return new s(Math.pow(e,t.re),0);if(0===e)switch((t.re%4+4)%4){case 0:return new s(Math.pow(i,t.re),0);case 1:return new s(0,Math.pow(i,t.re));case 2:return new s(-Math.pow(i,t.re),0);case 3:return new s(0,-Math.pow(i,t.re))}}if(0===e&&0===i&&t.re>0&&t.im>=0)return s.ZERO;var n=Math.atan2(i,e),r=a(e,i);return e=Math.exp(t.re*r-t.im*n),i=t.im*r+t.re*n,new s(e*Math.cos(i),e*Math.sin(i))},sqrt:function(){var e,i,t=this.re,n=this.im,r=this.abs();if(t>=0){if(0===n)return new s(Math.sqrt(t),0);e=.5*Math.sqrt(2*(r+t))}else e=Math.abs(n)/Math.sqrt(2*(r-t));return i=t<=0?.5*Math.sqrt(2*(r-t)):Math.abs(n)/Math.sqrt(2*(r+t)),new s(e,n<0?-i:i)},exp:function(){var e=Math.exp(this.re);return this.im,new s(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){var e=this.re,i=this.im;return new s(Math.expm1(e)*Math.cos(i)+function(e){var i=Math.PI/4;if(-i>e||e>i)return Math.cos(e)-1;var t=e*e;return t*(t*(t*(t*(t*(t*(t*(t/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-.5)}(i),Math.exp(e)*Math.sin(i))},log:function(){var e=this.re,i=this.im;return new s(a(e,i),Math.atan2(i,e))},abs:function(){return e=this.re,i=this.im,t=Math.abs(e),n=Math.abs(i),t<3e3&&n<3e3?Math.sqrt(t*t+n*n):(t<n?(t=n,n=e/i):n=i/e,t*Math.sqrt(1+n*n));var e,i,t,n},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){var e=this.re,i=this.im;return new s(Math.sin(e)*t(i),Math.cos(e)*n(i))},cos:function(){var e=this.re,i=this.im;return new s(Math.cos(e)*t(i),-Math.sin(e)*n(i))},tan:function(){var e=2*this.re,i=2*this.im,r=Math.cos(e)+t(i);return new s(Math.sin(e)/r,n(i)/r)},cot:function(){var e=2*this.re,i=2*this.im,r=Math.cos(e)-t(i);return new s(-Math.sin(e)/r,n(i)/r)},sec:function(){var e=this.re,i=this.im,r=.5*t(2*i)+.5*Math.cos(2*e);return new s(Math.cos(e)*t(i)/r,Math.sin(e)*n(i)/r)},csc:function(){var e=this.re,i=this.im,r=.5*t(2*i)-.5*Math.cos(2*e);return new s(Math.sin(e)*t(i)/r,-Math.cos(e)*n(i)/r)},asin:function(){var e=this.re,i=this.im,t=new s(i*i-e*e+1,-2*e*i).sqrt(),n=new s(t.re-i,t.im+e).log();return new s(n.im,-n.re)},acos:function(){var e=this.re,i=this.im,t=new s(i*i-e*e+1,-2*e*i).sqrt(),n=new s(t.re-i,t.im+e).log();return new s(Math.PI/2-n.im,n.re)},atan:function(){var e=this.re,i=this.im;if(0===e){if(1===i)return new s(0,1/0);if(-1===i)return new s(0,-1/0)}var t=e*e+(1-i)*(1-i),n=new s((1-i*i-e*e)/t,-2*e/t).log();return new s(-.5*n.im,.5*n.re)},acot:function(){var e=this.re,i=this.im;if(0===i)return new s(Math.atan2(1,e),0);var t=e*e+i*i;return 0!==t?new s(e/t,-i/t).atan():new s(0!==e?e/0:0,0!==i?-i/0:0).atan()},asec:function(){var e=this.re,i=this.im;if(0===e&&0===i)return new s(0,1/0);var t=e*e+i*i;return 0!==t?new s(e/t,-i/t).acos():new s(0!==e?e/0:0,0!==i?-i/0:0).acos()},acsc:function(){var e=this.re,i=this.im;if(0===e&&0===i)return new s(Math.PI/2,1/0);var t=e*e+i*i;return 0!==t?new s(e/t,-i/t).asin():new s(0!==e?e/0:0,0!==i?-i/0:0).asin()},sinh:function(){var e=this.re,i=this.im;return new s(n(e)*Math.cos(i),t(e)*Math.sin(i))},cosh:function(){var e=this.re,i=this.im;return new s(t(e)*Math.cos(i),n(e)*Math.sin(i))},tanh:function(){var e=2*this.re,i=2*this.im,r=t(e)+Math.cos(i);return new s(n(e)/r,Math.sin(i)/r)},coth:function(){var e=2*this.re,i=2*this.im,r=t(e)-Math.cos(i);return new s(n(e)/r,-Math.sin(i)/r)},csch:function(){var e=this.re,i=this.im,r=Math.cos(2*i)-t(2*e);return new s(-2*n(e)*Math.cos(i)/r,2*t(e)*Math.sin(i)/r)},sech:function(){var e=this.re,i=this.im,r=Math.cos(2*i)+t(2*e);return new s(2*t(e)*Math.cos(i)/r,-2*n(e)*Math.sin(i)/r)},asinh:function(){var e=this.im;this.im=-this.re,this.re=e;var i=this.asin();return this.re=-this.im,this.im=e,e=i.re,i.re=-i.im,i.im=e,i},acosh:function(){var e=this.acos();if(e.im<=0){var i=e.re;e.re=-e.im,e.im=i}else i=e.im,e.im=-e.re,e.re=i;return e},atanh:function(){var e=this.re,i=this.im,t=e>1&&0===i,n=1-e,r=1+e,o=n*n+i*i,l=0!==o?new s((r*n-i*i)/o,(i*n+r*i)/o):new s(-1!==e?e/0:0,0!==i?i/0:0),u=l.re;return l.re=a(l.re,l.im)/2,l.im=Math.atan2(l.im,u)/2,t&&(l.im=-l.im),l},acoth:function(){var e=this.re,i=this.im;if(0===e&&0===i)return new s(0,Math.PI/2);var t=e*e+i*i;return 0!==t?new s(e/t,-i/t).atanh():new s(0!==e?e/0:0,0!==i?-i/0:0).atanh()},acsch:function(){var e=this.re,i=this.im;if(0===i)return new s(0!==e?Math.log(e+Math.sqrt(e*e+1)):1/0,0);var t=e*e+i*i;return 0!==t?new s(e/t,-i/t).asinh():new s(0!==e?e/0:0,0!==i?-i/0:0).asinh()},asech:function(){var e=this.re,i=this.im;if(this.isZero())return s.INFINITY;var t=e*e+i*i;return 0!==t?new s(e/t,-i/t).acosh():new s(0!==e?e/0:0,0!==i?-i/0:0).acosh()},inverse:function(){if(this.isZero())return s.INFINITY;if(this.isInfinite())return s.ZERO;var e=this.re,i=this.im,t=e*e+i*i;return new s(e/t,-i/t)},conjugate:function(){return new s(this.re,-this.im)},neg:function(){return new s(-this.re,-this.im)},ceil:function(e){return e=Math.pow(10,e||0),new s(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=Math.pow(10,e||0),new s(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=Math.pow(10,e||0),new s(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,i){var t=new s(e,i);return Math.abs(t.re-this.re)<=s.EPSILON&&Math.abs(t.im-this.im)<=s.EPSILON},clone:function(){return new s(this.re,this.im)},toString:function(){var e=this.re,i=this.im,t="";return this.isNaN()?"NaN":this.isInfinite()?"Infinity":(Math.abs(e)<s.EPSILON&&(e=0),Math.abs(i)<s.EPSILON&&(i=0),0===i?t+e:(0!==e?(t+=e,t+=" ",i<0?(i=-i,t+="-"):t+="+",t+=" "):i<0&&(i=-i,t+="-"),1!==i&&(t+=i),t+"i"))},toVector:function(){return[this.re,this.im]},valueOf:function(){return 0===this.im?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return 0===this.im&&0===this.re},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!(this.isNaN()||this.isFinite())}},s.ZERO=new s(0,0),s.ONE=new s(1,0),s.I=new s(0,1),s.PI=new s(Math.PI,0),s.E=new s(Math.E,0),s.INFINITY=new s(1/0,1/0),s.NAN=new s(NaN,NaN),s.EPSILON=1e-15,Object.defineProperty(s,"__esModule",{value:!0}),s.default=s,s.Complex=s,e.exports=s}()}(Be);const Ge=8205;function He(e){return e===Ge||65038===e||65039===e||e>=127995&&e<=128e3||e>=129456&&e<=129460||e>=917536&&e<=917632}function We(e){return e>=127462&&e<=127487}class Ue{constructor(e){this.obeyspaces=!1,this.s=function(e){if(/^[\u0020-\u00FF]*$/.test(e))return e;const i=[],t=function(e){const i=[];for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n>=55296&&n<=56319){const i=e.charCodeAt(t+1);i>=56320&&i<=57343&&(n=65536+1024*(n-55296)+(i-56320),t++)}i.push(n)}return i}(e);let n=0;for(;n<t.length;){const e=t[n++],r=t[n];if(r===Ge){const e=n-1;for(n+=2;t[n]===Ge;)n+=2;i.push(String.fromCodePoint(...t.slice(e,2*n-e+1)))}else if(He(r)){const e=n-1;for(;He(t[n]);)n+=t[n]===Ge?2:1;i.push(String.fromCodePoint(...t.slice(e,2*n-e-1)))}else We(e)?(n+=1,i.push(String.fromCodePoint(...t.slice(n-2,2)))):i.push(String.fromCodePoint(e))}return i}(e),this.pos=0}end(){return this.pos>=this.s.length}get(){return this.pos<this.s.length?this.s[this.pos++]:""}peek(){return this.s[this.pos]}match(e){let i;return i="string"==typeof this.s?e.exec(this.s.slice(this.pos)):e.exec(this.s.slice(this.pos).join("")),(null==i?void 0:i[0])?(this.pos+=i[0].length,i[0]):null}next(){if(this.end())return null;if(!this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]+/))return"<space>";if(this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]/))return"<space>";const e=this.get();if("\\"===e){if(!this.end()){let e=this.match(/^[a-zA-Z*]+/);if(e)this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]*/);else if(e=this.get()," "===e)return"<space>";return"\\"+e}}else{if("{"===e)return"<{>";if("}"===e)return"<}>";if("^"===e){if("^"===this.peek()){this.get();const e=this.match(/^(\^(\^(\^(\^[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f][0-9a-f]/);if(e)return String.fromCodePoint(parseInt(e.slice(e.lastIndexOf("^")+1),16))}return e}if("#"===e){if(!this.end()){let e=!1;if(/[0-9?]/.test(this.peek())&&(e=!0,this.pos+1<this.s.length)){const i=this.s[this.pos+1];e=/[^0-9A-Za-z]/.test(i)}return e?"#"+this.get():"#"}}else if("$"===e)return"$"===this.peek()?(this.get(),"<$$>"):"<$>"}return e}}function Qe(e,i){var t,n,r,a;let s=[],o=e.next();if(o)if("\\relax"===o);else if("\\noexpand"===o)o=e.next(),o&&s.push(o);else if("\\obeyspaces"===o)e.obeyspaces=!0;else if("\\space"===o||"~"===o)s.push("<space>");else if("\\bgroup"===o)s.push("<{>");else if("\\egroup"===o)s.push("<}>");else if("\\string"===o)o=e.next(),o&&("\\"===o[0]?Array.from(o).forEach((e=>s.push("\\"===e?"\\backslash":e))):"<{>"===o?s.push("\\{"):"<space>"===o?s.push("~"):"<}>"===o&&s.push("\\}"));else if("\\csname"===o){for(;"<space>"===e.peek();)e.next();let r="",a=!1,l=[];do{if(0===l.length)if(/^#[0-9?]$/.test(e.peek())){const r=e.get().slice(1);l=Ye(null!==(n=null!==(t=null==i?void 0:i[r])&&void 0!==t?t:null==i?void 0:i["?"])&&void 0!==n?n:"\\placeholder{}",i),o=l[0]}else o=e.next(),l=o?[o]:[];a=0===l.length,a||"\\endcsname"!==o||(a=!0,l.shift()),a||(a="<$>"===o||"<$$>"===o||"<{>"===o||"<}>"===o||!!o&&o.length>1&&"\\"===o[0]),a||(r+=l.shift())}while(!a);r&&s.push("\\"+r),s=s.concat(l)}else if("\\endcsname"===o);else if(o.length>1&&"#"===o[0]){const e=o.slice(1);s=s.concat(Ye(null!==(a=null!==(r=null==i?void 0:i[e])&&void 0!==r?r:null==i?void 0:i["?"])&&void 0!==a?a:"\\placeholder{}",i))}else s.push(o);return s}function Ye(e,i){const t=e.toString().split(/\r?\n/);let n="",r="";for(const e of t){n+=r,r=" ";const i=e.match(/((?:\\%)|[^%])*/);null!==i&&(n+=i[0])}const a=new Ue(n),s=[];do{s.push(...Qe(a,i))}while(!a.end());return s}function Ke(e){let i="",t="";for(const n of e)n&&(/[a-zA-Z*]/.test(n[0])&&(t+=i),i=/\\[a-zA-Z]+\*?$/.test(n)?" ":"",t+=n);return t}function Je(e){let i=[];if(Array.isArray(e))for(const t of e)Array.isArray(t)?i=[...i,...t]:i.push(t);else i=[e];return Ke(i.map((e=>{var i;return null!==(i={"<space>":" ","<$$>":"$$","<$>":"$","<{>":"{","<}>":"}"}[e])&&void 0!==i?i:e})))}const Xe="Divide",ei="Multiply",ii="Power",ti="Prime",ni="ComplexInfinity",ri="ExponentialE",ai="ImaginaryUnit";function si(e){return null!==e&&"object"==typeof e&&"num"in e}function oi(e){return null!==e&&"object"==typeof e&&"sym"in e}function li(e){return null!==e&&"object"==typeof e&&"fn"in e}function ui(e){return!/[\u0000-\u0020\u0022\u0060\ufffe\uffff]/.test(e)&&!/^[\u0021\u0022\u0024-\u0029\u002e\u003a\u003f\u0040\u005b\u005d\u005e\u007b\u007d\u007e]/.test(e)}function ci(e){return null==e?null:"object"==typeof e&&"str"in e?e.str:"string"!=typeof e||e.length<2||"'"!==e[0]||"'"!==e[e.length-1]?null:e.substring(1,e.length-1)}function hi(e){return null==e?null:Array.isArray(e)?e[0]:li(e)?e.fn[0]:null}function mi(e){const i=hi(e);return"string"==typeof i?i:""}function di(e,i){var t,n;return null==e?null:Array.isArray(e)?null!==(t=e[i])&&void 0!==t?t:null:li(e)&&null!==(n=e.fn[i])&&void 0!==n?n:null}function fi(e){return null==e?null:Array.isArray(e)?e.slice(1):li(e)?e.fn.slice(1):null}function gi(e){return di(e,1)}function pi(e){return null==e?0:Array.isArray(e)?Math.max(0,e.length-1):li(e)?Math.max(0,e.fn.length-1):0}function vi(e){if(null==e)return null;const i=oi(e)?e.sym:e;return"string"!=typeof i||i.length>=2&&"'"===i[0]&&"'"===i[i.length-1]?null:i}function bi(e){var i;const t=hi(e);if("KeyValuePair"===t||"Tuple"===t||"Pair"===t){const t=ci(di(e,1));return t?[t,null!==(i=di(e,2))&&void 0!==i?i:"Nothing"]:null}return null}function yi(e){if(null===e)return null;if("object"==typeof e&&"dict"in e)return e.dict;const i=bi(e);if(i)return{[i[0]]:i[1]};if("Dictionary"===hi(e)){const i={};for(let t=1;t<pi(e);t++){const n=bi(di(e,t));n&&(i[n[0]]=n[1])}return i}return null}function xi(e){var i;if(null==e)return null;if("number"==typeof e)return e;if(si(e)){let t=e.num.toLowerCase().replace(/[nd]$/g,"").replace(/[\u0009-\u000d\u0020\u00a0]/g,"");if(/\([0-9]+\)$/.test(t)){const[e,n,r]=null!==(i=t.match(/(.+)\(([0-9]+)\)$/))&&void 0!==i?i:[];t=n+r.repeat(Math.ceil(16/r.length))}return"nan"===t?NaN:"+infinity"===t?1/0:"-infinity"===t?-1/0:parseFloat(t)}const t=vi(e);return"NaN"===t?NaN:"+Infinity"===t?1/0:"-Infinity"===t?-1/0:null}function Ni(e){var i,t;if(null==e)return[null,null];if("Half"===vi(e))return[1,2];if(function(e){return null===e||!Array.isArray(e)&&("object"!=typeof e||!("fn"in e||"dic"in e))}(e))return[null,null];const n=hi(e);if(!n)return[null,null];let r=null,a=null;if("Negate"===n&&([r,a]=Ni(di(e,1)),null!==r&&null!==a))return[-r,a];if("Rational"===n)return[null!==(i=xi(di(e,1)))&&void 0!==i?i:NaN,null!==(t=xi(di(e,2)))&&void 0!==t?t:NaN];if("Power"===n){const i=xi(di(e,2));1===i?(r=xi(di(e,1)),a=1):-1===i&&(r=1,a=xi(di(e,1)))}return"Divide"===n&&(r=xi(di(e,1)),a=xi(di(e,2))),"Multiply"===n&&hi(di(e,2))===ii&&-1===xi(di(di(e,2),2))&&(r=xi(di(e,1)),a=xi(di(di(e,2),1))),null===r||null===a?[null,null]:Number.isInteger(r)&&Number.isInteger(a)?[r,a]:[null,null]}function _i(e,i){var t;const n=hi(e);if(null!==n)return[_i(n,i),...(null!==(t=fi(e))&&void 0!==t?t:[]).map((e=>_i(e,i)))];const r=yi(e);if(null!==r){const e=Object.keys(r),t={};for(const n of e)t[n]=_i(r[n],i);return{dict:t}}const a=vi(e);return a&&i[a]?i[a]:e}function Si(e,i){let t=null;if(Array.isArray(e)&&(t=e),li(e)&&(t=e.fn),null===t)return[];let n=1;const r=[];for(;n<t.length;)r.push(i(t[n])),n+=1;return r}function wi(e,i,t,n="both"){var r,a,s,o,l,u;if("non"===n)return[e,i,t];const c=hi(i),h=hi(t);return"left"===n?c===e?[e,...null!==(r=fi(i))&&void 0!==r?r:[],t]:[e,i,t]:"right"===n?h===e?[e,i,...null!==(a=fi(t))&&void 0!==a?a:[]]:[e,i,t]:c===e&&h===e?[e,...null!==(s=fi(i))&&void 0!==s?s:[],...null!==(o=fi(t))&&void 0!==o?o:[]]:c===e?[e,...null!==(l=fi(i))&&void 0!==l?l:[],t]:h===e?[e,i,...null!==(u=fi(t))&&void 0!==u?u:[]]:[e,i,t]}function Ei(e){var i;let t=hi(e);if(null===e)return null;if("Delimiter"===t){if(null===(e=di(e,1)))return[];if("Sequence"!==hi(e))return[e]}return t=hi(e),"Sequence"===t?null!==(i=fi(e))&&void 0!==i?i:[]:null}function ki(e){return null!==e&&"Sequence"===hi(e)&&0===pi(e)}function Ii(e){return null===e||ki(e)?["Error","'missing'"]:e}function Ai(e,i){return i>2?"solidus":"radical"}function Mi(e,i){return i>3?"inline-solidus":"quotient"}function Fi(e,i,t,n){return null===t?"\\sqrt{}":(n=null!=n?n:2,"solidus"===i?e.wrapShort(t)+"^{1\\/"+e.serialize(n)+"}":"quotient"===i?e.wrapShort(t)+"^{\\frac{1}{"+e.serialize(n)+"}}":2===xi(n)?"\\sqrt{"+e.serialize(t)+"}":"\\sqrt["+e.serialize(n)+"]{"+e.serialize(t)+"}")}function Oi(e,i){if(null===i)return"";const t=Ii(di(i,1)),n=Ii(di(i,2)),r=Mi(0,e.level);if("inline-solidus"===r||"nice-solidus"===r){const i=e.wrapShort(t),a=e.wrapShort(n);return"inline-solidus"===r?`${i}\\/${a}`:`^{${i}}\\!\\!/\\!_{${a}}`}return"reciprocal"===r?e.wrap(t)+e.wrap(n)+"^{-1}":"factor"===r?"\\frac{1}{"+e.serialize(n)+"}"+e.wrap(t):`\\frac{${e.serialize(t)}}{${e.serialize(n)}}`}function Vi(e,i){var t;const n=hi(i),r=Ii(di(i,1)),a=Ii(di(i,2));if("Sqrt"===n)return Fi(e,Ai(0,e.level),r,2);if("Root"===n)return Fi(e,Ai(0,e.level),r,a);const s=null!==(t=xi(a))&&void 0!==t?t:1;if(-1===s)return e.serialize([Xe,"1",r]);if(s<0)return e.serialize([Xe,"1",[ii,r,-s]]);if("Divide"===hi(a)||"Rational"===hi(a)){if(1===xi(di(a,1)))return Fi(e,Ai(0,e.level),r,di(a,2))}else if(hi(a)===ii&&-1===xi(di(a,2)))return Fi(e,Ai(0,e.level),r,di(a,1));return e.wrapShort(r)+"^{"+e.serialize(a)+"}"}const Ti=[{name:"CatalanConstant",serialize:"G"},{name:"GoldenRatio",serialize:"\\varphi"},{name:"EulerGamma",serialize:"\\gamma"},{name:"Degrees",serialize:"\\frac{\\pi}{180}"},{trigger:["\\infty"],parse:{num:"+Infinity"}},{name:ni,trigger:["\\tilde","\\infty"],serialize:"\\tilde\\infty"},{trigger:["\\tilde","<{>","\\infty","<}>"],parse:ni},{name:"Pi",trigger:["\\pi"]},{trigger:["\u03c0"],parse:"Pi"},{name:ri,trigger:["e"],serialize:"\\exponentialE"},{trigger:["\\mathrm","<{>","e","<}>"],parse:ri},{trigger:["\\exponentialE"],parse:ri},{name:ai,trigger:["\\imaginaryI"]},{trigger:["i"],parse:ai},{trigger:["\\mathrm","<{>","i","<}>"],parse:ai},{name:"Abs",kind:"matchfix",openDelimiter:"|",closeDelimiter:"|",parse:(e,i)=>ki(i)?null:["Abs",i]},{name:"Add",trigger:["+"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,t)=>{if(275<i.minPrec)return null;const n=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:275}));return null===n?null:wi("Add",t,n)},serialize:function(e,i){var t,n;e.level-=1;const r=hi(i);let a="",s=di(i,1);if("Negate"===r)a="-"+e.wrap(s,276);else if("Add"===r){let r=null!==(t=xi(s))&&void 0!==t?t:NaN,o=!Number.isNaN(r)&&Number.isInteger(r)&&Math.abs(r)<=1e3;a=e.serialize(s);const l=pi(i)+1;for(let t=2;t<l;t++){s=di(i,t),r=null!==(n=xi(s))&&void 0!==n?n:NaN;const l=!Number.isNaN(r)&&Number.isInteger(r)&&Math.abs(r)<=1e3;let u=!1;if(null!==s&&o){const[i,t]=Ni(s);null!==i&&null!==t&&isFinite(i)&&isFinite(t)&&t>1&&t<=100&&i>0&&i<=100&&(a=Ke([a,e.options.invisiblePlus,e.serialize(s)]),u=!0)}if(!u)if(r<0)a+=e.serialize(s);else if("Negate"===hi(s))a+=e.wrap(s,275);else{const i=e.wrap(s,275);"-"===i[0]||"+"===i[0]?a+=i:a=a+"+"+i}o=l}}else if("Subtract"===r){a=e.wrap(s,275);const t=di(i,2);if(null!==t){const i=e.wrap(t,275);"-"===i[0]?a+="+"+i.slice(1):"+"===i[0]?a+="-"+i.slice(1):a=a+"-"+i}}return e.level+=1,a}},{kind:"prefix",trigger:["+"],precedence:275,parse:(e,i)=>275<i.minPrec?null:e.matchExpression(Object.assign(Object.assign({},i),{minPrec:400}))},{name:"Ceil",kind:"matchfix",openDelimiter:"\\lceil",closeDelimiter:"\\rceil"},{name:"Complex",precedence:274,serialize:(e,i)=>{const t=xi(di(i,1)),n=xi(di(i,2));if(0===n)return e.serialize(di(i,1));const r=1===n?"\\imaginaryI":-1===n?"-\\imaginaryI":Ke([e.serialize(di(i,2)),"\\imaginaryI"]);return 0===t?r:Ke(null!==n&&n<0?[e.serialize(di(i,1)),r]:[e.serialize(di(i,1)),"+",r])}},{name:"Divide",trigger:"\\frac",precedence:660,parse:function(e){var i,t;const n=Ii(e.matchRequiredLatexArgument()),r=Ii(e.matchRequiredLatexArgument());if("PartialDerivative"===hi(n)&&("PartialDerivative"===hi(r)||"Multiply"===hi(r)&&"PartialDerivative"===hi(di(r,1)))){const a=null!==(i=di(n,3))&&void 0!==i?i:null;let s=di(n,1);null===s&&(s=Ii(e.matchExpression()));let o=[];if("Multiply"===hi(r)){for(const e of null!==(t=fi(r))&&void 0!==t?t:[])if("PartialDerivative"===hi(e)){const i=di(e,2);i&&o.push(i)}}else{const e=di(r,2);e&&o.push(e)}return o.length>1&&(o=["List",...o]),["PartialDerivative",s,...o,null===a?1:a]}return["Divide",n,r]},serialize:Oi},{kind:"infix",trigger:"\\over",precedence:660,parse:"Divide"},{trigger:["\\/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["\\div"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{name:"Exp",serialize:(e,i)=>Ke(["\\exponentialE^{",e.serialize(Ii(di(i,1))),"}"])},{name:"Factorial",trigger:["!"],kind:"postfix",precedence:810},{name:"Factorial2",trigger:["!","!"],kind:"postfix",precedence:810},{name:"Floor",kind:"matchfix",openDelimiter:"\\lfloor",closeDelimiter:"\\rfloor"},{trigger:"floor",kind:"function",parse:e=>{const i=e.matchArguments("enclosure");return null===i?"Floor":["Floor",...i]}},{name:"Gcd",trigger:"gcd",kind:"function"},{name:"Half",serialize:"\\frac12"},{name:"Lg",serialize:(e,i)=>"\\ln_{10}"+e.wrapArguments(i)},{name:"Lb",trigger:"\\lb",parse:e=>{const i=e.matchArguments("implicit");return null===i?null:["Log",...i,2]}},{name:"Ln",serialize:(e,i)=>"\\ln"+e.wrapArguments(i)},{name:"Log",trigger:"\\ln",parse:e=>{var i;let t=null,n=null;e.match("_")&&(t=null!==(i=e.matchStringArgument())&&void 0!==i?i:e.next(),n=Number.parseFloat(null!=t?t:"10"));const r=e.matchArguments("implicit");return null===r?null:10===n?["Lg",...r]:2===n?["Lb",...r]:null===t?["Ln",...r]:["Log",...r,t]},serialize:(e,i)=>{const t=function(e){return di(e,2)}(i);return t?Ke(["\\ln_{",t.toString(),"}",e.wrap(gi(i))]):"\\ln"+e.wrapArguments(i)}},{name:"Lcm",trigger:"lcm",kind:"function"},{name:"MinusPlus",trigger:["\\mp"],kind:"infix",associativity:"both",precedence:270},{name:"Multiply",trigger:["\\times"],kind:"infix",associativity:"both",precedence:390,serialize:function e(i,t){var n;if(null===t)return"";i.level-=1;let r="";const[a,s]=function(e){var i,t;if("Multiply"!==hi(e))return[[],[]];const n=[],r=[],a=null!==(i=fi(e))&&void 0!==i?i:[];for(const e of a)if("Power"===hi(e)){const i=di(e,1),a=di(e,2);if("Negate"===hi(a)){const e=di(a,1);i&&e&&r.push([ii,i,e])}else{const s=null!==(t=xi(a))&&void 0!==t?t:NaN;-1===s?i&&r.push(i):s<0?i&&r.push([ii,i,-s]):n.push(e)}}else if("Rational"===hi(e)&&2===pi(e)){const i=di(e,1),t=di(e,2);1!==xi(i)&&n.push(i),1!==xi(t)&&r.push(t)}else{const[i,t]=Ni(e);null!==i?(1!==i&&n.push(i),r.push(t)):n.push(e)}return[n,r]}(t);if(s.length>0&&(r=1===s.length&&1===s[0]?0===a.length?"1":1===a.length?i.serialize(a[0]):e(i,[ei,...a]):i.serialize([Xe,1===a.length?a[0]:[ei,...a],1===s.length?s[0]:[ei,...s]])),r)return i.level+=1,r;let o=!1,l=null;const u=pi(t)+1;let c=!1;for(let e=1;e<u;e++){if(l=di(t,e),null===l)continue;let a;if("number"==typeof l||si(l))a=i.serialize(l),"-1"!==a||r?("-"===a[0]&&(a=a.slice(1),o=!o),r=r?Ke([r,i.options.multiply,a]):a):(r="",o=!o),c=!0;else{if("Power"===hi(l)){const[e,t]=Ni(di(l,2));if(1===e&&null!==t){r+=Fi(i,Ai(0,i.level),di(l,1),t),c=!1;continue}}if("Power"!==hi(l)||isNaN(null!==(n=xi(di(l,1)))&&void 0!==n?n:NaN)){if("Negate"===hi(l)&&(l=di(l,1),o=!o),a=i.wrap(l,390),r){const e=hi(l);r=!c||"Divide"!==e&&"Rational"!==e?i.options.invisibleMultiply?Ke([r,i.options.invisibleMultiply,a]):Ke([r,a]):Ke([r,i.options.multiply,a])}else r=a;c=!1}else a=i.serialize(l),r=r?Ke([r,i.options.multiply,a]):a,c=!0}}return i.level+=1,o?"-"+r:r}},{trigger:["\\cdot"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,t)=>{if(391<i.minPrec)return null;const n=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:392}));return null===n?null:wi("Multiply",t,n)}},{trigger:["*"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,t)=>{if(391<i.minPrec)return null;const n=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:392}));return null===n?null:["Multiply",t,n]}},{name:"Negate",trigger:["-"],kind:"prefix",parse:(e,i)=>{if(276<i.minPrec)return null;const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:400}));return null===t?null:["Negate",t]},precedence:275},{kind:"matchfix",openDelimiter:"||",closeDelimiter:"||",parse:(e,i)=>ki(i)?null:["Norm",i]},{name:"Norm",kind:"matchfix",openDelimiter:["\\left","\\Vert"],closeDelimiter:["\\right","\\Vert"]},{name:"PlusMinus",trigger:["\\pm"],kind:"infix",associativity:"both",precedence:270},{name:ii,trigger:["^"],kind:"infix",serialize:Vi},{trigger:"\\prod",precedence:265,name:"Product",parse:qi("Product"),serialize:Ci("\\prod")},{name:"Rational",precedence:660,serialize:(e,i)=>i&&1===pi(i)?"\\mathrm{Rational}"+e.wrapArguments(i):Oi(e,i)},{name:"Root",serialize:Vi},{name:"Round",trigger:"round",kind:"function"},{name:"Square",precedence:720,serialize:(e,i)=>e.wrapShort(di(i,1))+"^2"},{trigger:"\\sum",precedence:265,name:"Sum",parse:qi("Sum"),serialize:Ci("\\sum")},{name:"Sign",trigger:"sgn",kind:"function"},{name:"Sqrt",trigger:["\\sqrt"],parse:function(e){const i=e.matchOptionalLatexArgument(),t=e.matchRequiredLatexArgument();return null===t||ki(t)?null!==i?["Root",["Error","'missing'"],Ii(i)]:["Sqrt",["Error","'missing'"]]:null!==i?["Root",t,i]:["Sqrt",t]},serialize:Vi},{name:"Subtract",trigger:["-"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,t)=>{if(276<i.minPrec)return null;const n=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:277}));return null===n?null:["Subtract",t,n]}}];function qi(e){return i=>{var t,n;i.skipSpace();let r=null,a=null;for(;!(a&&r||"_"!==i.peek&&"^"!==i.peek);)i.match("_")?a=i.matchRequiredLatexArgument():i.match("^")&&(r=i.matchRequiredLatexArgument()),i.skipSpace();("Nothing"===a||ki(a))&&(a=null),("Nothing"===r||ki(r))&&(r=null);let s=null,o=null;"Equal"===hi(a)?(s=di(a,1),o=di(a,2)):s=a;const l=vi(s);l&&(null===(t=i.computeEngine)||void 0===t||t.pushScope({symbolTable:{symbols:[{name:l,domain:"Integer"}]}}));let u=i.matchExpression({minPrec:266});return u&&l&&(u=["Lambda",_i(u,{[l]:"_"})]),l&&(null===(n=i.computeEngine)||void 0===n||n.popScope()),u?r?[e,u,["Tuple",null!=s?s:"Nothing",null!=o?o:1,r]]:o?[e,u,["Tuple",null!=s?s:"Nothing",o]]:s?[e,u,["Tuple",s]]:[e,u]:[e]}}function Ci(e){return(i,t)=>{var n;if(!di(t,1))return e;let r=di(t,2);const a=hi(r);"Tuple"!==a&&"Triple"!==a&&"Pair"!==a&&"Single"!==a&&(r=null);const s=null!==(n=di(r,1))&&void 0!==n?n:"n";let o=di(t,1);if("Lambda"===hi(o)&&di(o,1)&&(o=_i(di(o,1),{_:s,_1:s})),!r)return di(t,2)?Ke([e,"_{",i.serialize(di(t,2)),"}",i.serialize(o)]):Ke([e,"_n",i.serialize(o)]);const l=di(r,2);let u=[];"Nothing"!==vi(s)&&l?u=[i.serialize(s),"=",i.serialize(l)]:"Nothing"!==vi(s)?u=[i.serialize(s)]:l&&(u=[i.serialize(l)]),u.length>0&&(u=["_{",...u,"}"]);let c=[];return di(r,3)&&(c=["^{",i.serialize(di(r,3)),"}"]),Ke([e,...c,...u,i.serialize(o)])}}function Di(e=""){return(i,t)=>{var n;return(null!==(n=fi(t))&&void 0!==n?n:[]).map((e=>i.serialize(e))).join(e)}}const Pi=[{trigger:["\\placeholder"],parse:e=>{if(e.skipSpaceTokens(),e.match("["))for(;!e.match("]")&&!e.atBoundary;)e.next();if(e.skipSpaceTokens(),e.match("<{>"))for(;!e.match("<}>")&&!e.atBoundary;)e.next();return"Nothing"}},{name:"BaseForm",kind:"function",serialize:(e,i)=>{var t,n;const r=null!==(t=xi(di(i,2)))&&void 0!==t?t:NaN;if(isFinite(r)&&r>=2&&r<=36){const e=null!==(n=xi(di(i,1)))&&void 0!==n?n:NaN;if(isFinite(e)&&Number.isInteger(e)){let i=Number(e).toString(r),t=0;if(2===r||10===r?t=4:16===r?t=2:r>16&&(t=4),t>0){const e=i;i="";for(let n=0;n<e.length;n++)n>0&&n%t==0&&(i="\\, "+i),i=e[e.length-n-1]+i}return`(\\text{${i}}_{${r}}`}}return"\\operatorname{BaseForm}("+e.serialize(di(i,1))+", "+e.serialize(di(i,2))+")"}},{name:"Delimiter",serialize:(e,i)=>{var t,n,r,a,s;const o=pi(i);if(0===o)return"";const l=e.options.groupStyle(i,e.level+1),u=di(i,1);if(1===o)return e.wrapString(e.serialize(u),l);let c="",h="",m="";if(o>1){const e=null!==(t=ci(di(i,2)))&&void 0!==t?t:"";h=null!==(n=e[0])&&void 0!==n?n:"",m=null!==(r=e[1])&&void 0!==r?r:"",c=null!==(a=e[2])&&void 0!==a?a:""}const d="List"===hi(u)?Di(c)(e,u):e.serialize(u);return e.wrapString(d,l,null!==(s=ci(di(i,2)))&&void 0!==s?s:void 0),h&&m?`${h} ${d} ${m}`:e.wrapString(d,l)}},{name:"Domain",serialize:(e,i)=>"Error"===hi(i)?e.serialize(i):e.serialize(di(i,1))},{name:"Error",serialize:(e,i)=>{var t;if("missing"===ci(di(i,1)))return`\\textcolor{red}{${null!==(t=e.options.missingSymbol)&&void 0!==t?t:"\\placeholder{}"}}`;const n=function(e,i){var t;const n=di(i,2);return n?"Latex"===hi(n)?Ri(null!==(t=ci(di(n,1)))&&void 0!==t?t:""):"Hold"===hi(n)?e.serialize(di(n,1)):e.serialize(n):""}(e,i);return"string"==typeof ci(di(i,1))?`\\texttt{\\textcolor{red}{${n||"\\blacksquare"}}}`:`\\texttt{\\textcolor{red}{${e.serialize(di(i,1))||n||"\\blacksquare"}}}`}},{name:"ErrorCode",serialize:(e,i)=>{var t;const n=ci(di(i,1));return"missing"===n?null!==(t=e.options.missingSymbol)&&void 0!==t?t:"\\placeholder{}":"unexpected-command"===n||"unexpected-operator"===n||"unexpected-token"===n||"invalid-symbol-name"===n||"unknown-environment"===n||"unknown-environment"===n||"unexpected-base"===n||"incompatible-domain"===n||"invalid-domain-expression"===n?"":"\\texttt{\\textcolor{red}{\\blacksquare}}"}},{name:"FromLatex",serialize:(e,i)=>`\\texttt{${Ri(ci(di(i,1)))}}`},{name:"Latex",serialize:(e,i)=>null===i?"":Ke(Si(i,(i=>{var t;return null!==(t=ci(i))&&void 0!==t?t:e.serialize(i)})))},{name:"LatexString",serialize:(e,i)=>null===i?"":Ke(Si(i,(i=>e.serialize(i))))},{name:"LatexTokens",serialize:function(e,i){return null===i?"":Ke(Si(i,(i=>{const t=ci(i);return null===t?e.serialize(i):"<{>"===t?"{":"<}>"===t?"}":"<$>"===t?"$":"<$$>"===t?"$$":"<space>"===t?" ":t})))}},{name:"List",kind:"matchfix",openDelimiter:"[",closeDelimiter:"]",parse:(e,i)=>{var t;return null===i?["List"]:"Sequence"!==hi(i)&&"List"!==hi(i)?["List",i]:["List",...null!==(t=fi(i))&&void 0!==t?t:[]]},serialize:(e,i)=>Ke(["\\lbrack",Di(", ")(e,i),"\\rbrack"])},{kind:"matchfix",openDelimiter:"(",closeDelimiter:")",parse:(e,i)=>{var t;return null===i?null:"Sequence"===hi(i)||"List"===hi(i)?0===pi(i)?["Delimiter"]:["Delimiter",["List",...null!==(t=fi(i))&&void 0!==t?t:[]]]:["Delimiter",i]}},{name:"Sequence",trigger:[","],kind:"infix",precedence:20,parse:(e,i,t)=>{if(i.minPrec>=20)return null;const n=["List",t];let r=!1;for(;!r;){for(r=!0,e.skipSpace();e.match(",");)n.push("Nothing"),e.skipSpace();if(e.atTerminator(i))n.push("Nothing");else{const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:20}));n.push(null!=t?t:"Nothing"),r=null===t}r||(e.skipSpace(),r=!e.match(","))}return n},serialize:Di(", ")},{trigger:[";"],kind:"infix",precedence:19,parse:(e,i,t)=>{var n,r;if(i.minPrec>=19)return null;const a=["Sequence",...null!==(n=Ei(t))&&void 0!==n?n:["List",t]];for(;;){for(e.skipSpace();e.match(",");)a.push("Nothing"),e.skipSpace();if(e.atEnd){a.push("Nothing");break}const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:19}));if(null===t){a.push("Nothing");break}if(a.push(...null!==(r=Ei(t))&&void 0!==r?r:["List",t]),e.skipSpace(),!e.match(","))break}return a}},{name:"String",trigger:["\\text"],parse:e=>Li(e),serialize:(e,i)=>{const t=fi(i);return null===t||0===t.length?"\\text{}":Ke(["\\text{",t.map((i=>e.serialize(i))).join(""),"}"])}},{name:"Subscript",trigger:["_"],kind:"infix",serialize:(e,i)=>2===pi(i)?e.serialize(di(i,1))+"_{"+e.serialize(di(i,2))+"}":"_{"+e.serialize(di(i,1))+"}"},{name:"Superplus",trigger:["^","+"],kind:"postfix"},{name:"Subplus",trigger:["_","+"],kind:"postfix"},{name:"Superminus",trigger:["^","-"],kind:"postfix"},{name:"Subminus",trigger:["_","-"],kind:"postfix"},{trigger:["^","*"],kind:"postfix",parse:(e,i)=>["Superstar",i]},{name:"Superstar",trigger:["^","\\star"],kind:"postfix"},{trigger:["_","*"],kind:"postfix",parse:(e,i)=>["Substar",i]},{name:"Substar",trigger:["_","\\star"],kind:"postfix"},{name:"Superdagger",trigger:["^","\\dagger"],kind:"postfix"},{trigger:["^","\\dag"],kind:"postfix",parse:(e,i)=>["Superdagger",i]},{name:ti,trigger:["^","\\prime"],kind:"postfix"},{trigger:["^","\\doubleprime"],kind:"postfix",parse:(e,i)=>[ti,Ii(i),2]},{name:"InverseFunction",serialize:(e,i)=>e.serialize(di(i,1))+"^{-1}"},{name:"Derivative",serialize:(e,i)=>{var t;const n=null!==(t=xi(di(i,1)))&&void 0!==t?t:NaN;if(!isFinite(n))return"";const r=e.serialize(di(i,2));return 1===n?r+"^{\\prime}":2===n?r+"^{\\doubleprime}":r+"^{("+Number(n).toString()+")}"}},{name:"Piecewise",trigger:"cases",kind:"environment",parse:e=>{const i=e.matchTabular("cases");return i?["Piecewise",["List",...i.map((e=>{var i,t;return["Tuple",null!==(i=e[1])&&void 0!==i?i:"Nothing",null!==(t=e[0])&&void 0!==t?t:["Sequence"]]}))]]:["Sequence"]},serialize:(e,i)=>{var t;if("List"!==hi(di(i,1)))return"";const n=null!==(t=fi(di(i,1)))&&void 0!==t?t:[],r=[];let a="";for(const i of n){if(("Tuple"===hi(i)||"Pair"===hi(i))&&(r.push(a),di(i,2))){r.push(e.serialize(di(i,2)));const t=di(i,1);null!==t&&r.push("&",e.serialize(t))}a="\\\\"}return Ke(["\\begin{cases}",...r,"\\end{cases}"])}}];function Li(e,i){var t,n,r;if(!e.match("<{>"))return"''";const a=[];let s,o="",l=null;for(;!e.atEnd&&!e.match("<}>");)if("<{>"===e.peek)a.push(Li(e));else if(e.match("\\textbf")&&e.match("<{>"))a.push(Li(e,{"font-weight":"bold"}));else if(e.match("\\color")&&e.match("<{>")){const i=e.matchColor();i&&e.match("<}>")&&(null!==l&&o?a.push(["Style",o,{dict:l}]):o&&a.push(["String",o]),o="",l={color:i})}else if(e.match("<space>"))o+=" ";else if(e.match("<$>")){const i=e.index,n=null!==(t=e.matchExpression())&&void 0!==t?t:["Sequence"];e.skipSpace(),e.match("<$>")?a.push(n):(o+="$",e.index=i)}else if(e.match("<$$>")){const i=e.index,t=null!==(n=e.matchExpression())&&void 0!==n?n:["Sequence"];e.skipSpace(),e.match("<$$>")?a.push(t):(o+="$$",e.index=i)}else o+=null!==(r=e.matchChar())&&void 0!==r?r:"";return null!==l&&o?a.push(["Style",`'${o}'`,{dict:l}]):o&&a.push(`'${o}'`),s=1===a.length?a[0]:a.every((e=>null!==ci(e)))?"'"+a.map((e=>ci(e))).join()+"'":["String",...a],i?["Style",s,{dict:i}]:s}function Ri(e){return null===e?"":e.replace(/[{}\[\]\\:\-\$%]/g,(e=>{var i;return null!==(i={"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "}[e])&&void 0!==i?i:"\\"+e}))}function zi(e){return i=>{const t=i.matchRequiredLatexArgument();return null===t?[e]:[e,t]}}const $i=[{name:"Overscript",trigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",trigger:["\\underset"],kind:"infix",precedence:700},{name:"Increment",trigger:["+","+"],kind:"postfix",precedence:880},{name:"Decrement",trigger:["-","-"],kind:"postfix",precedence:880},{name:"PreIncrement",trigger:["+","+"],kind:"prefix",precedence:880},{name:"PreDecrement",trigger:["-","-"],kind:"prefix",precedence:880},{name:"Ring",trigger:["\\circ"],kind:"infix",precedence:265},{name:"Transpose",trigger:["^","T"],kind:"infix"},{name:"ConjugateTranspose",trigger:["^","H"],kind:"infix"},{name:"StringJoin",trigger:["\\lt","\\gt"],kind:"infix",precedence:780},{name:"Starstar",trigger:["\\star","\\star"],kind:"infix",precedence:780},{name:"PartialDerivative",trigger:["\\partial"],kind:"prefix",parse:e=>{var i,t;let n=!1,r="Nothing",a="Nothing";for(;!n;)e.skipSpace(),e.match("_")?a=e.matchRequiredLatexArgument():e.match("^")?r=e.matchRequiredLatexArgument():n=!0;const s=Ei(a);if(s&&(a=["List",...s]),null===a||null===r)return null;let o=null!==(i=e.matchRequiredLatexArgument())&&void 0!==i?i:"Nothing";return"Nothing"===o||ki(o)||(o=[o,...null!==(t=e.matchArguments("enclosure"))&&void 0!==t?t:["Nothing"]]),["PartialDerivative",o,a,r]},serialize:(e,i)=>{var t;let n="\\partial";const r=di(i,1),a=di(i,2),s=di(i,3);return null!==a&&"Nothing"!==a&&("List"===hi(a)?n+="_{"+e.serialize(["Sequence",...null!==(t=fi(a))&&void 0!==t?t:[]])+"}":n+="_{"+e.serialize(a)+"}"),null!==s&&"Nothing"!==s&&(n+="^{"+e.serialize(s)+"}"),null!==r&&"Nothing"!==r&&(n+=e.serialize(r)),n},precedence:740},{name:"OverBar",trigger:["\\overline"],parse:zi("OverBar")},{name:"UnderBar",trigger:["\\underline"],parse:zi("UnderBar")},{name:"OverVector",trigger:["\\vec"],parse:zi("OverVector")},{name:"OverTilde",trigger:["\\tilde"],parse:zi("OverTilde")},{name:"OverHat",trigger:["\\hat"],parse:zi("OverHat")},{name:"OverRightArrow",trigger:["\\overrightarrow"],parse:zi("OverRightArrow")},{name:"OverLeftArrow",trigger:["\\overleftarrow"],parse:zi("OverLeftArrow")},{name:"OverRightDoubleArrow",trigger:["\\Overrightarrow"],parse:zi("OverRightDoubleArrow")},{name:"OverLeftHarpoon",trigger:["\\overleftharpoon"],parse:zi("OverLeftHarpoon")},{name:"OverRightHarpoon",trigger:["\\overrightharpoon"],parse:zi("OverRightHarpoon")},{name:"OverLeftRightArrow",trigger:["\\overleftrightarrow"],parse:zi("OverLeftRightArrow")},{name:"OverBrace",trigger:["\\overbrace"],parse:zi("OverBrace")},{name:"OverLineSegment",trigger:["\\overlinesegment"],parse:zi("OverLineSegment")},{name:"OverGroup",trigger:["\\overgroup"],parse:zi("OverGroup")},{trigger:["\\displaystyle"],parse:()=>["Sequence"]},{trigger:["\\textstyle"],parse:()=>["Sequence"]},{trigger:["\\scriptstyle"],parse:()=>["Sequence"]},{trigger:["\\scriptscriptstyle"],parse:()=>["Sequence"]},{trigger:["\\tiny"],parse:()=>["Sequence"]},{trigger:["\\scriptsize"],parse:()=>["Sequence"]},{trigger:["\\footnotesize"],parse:()=>["Sequence"]},{trigger:["\\small"],parse:()=>["Sequence"]},{trigger:["\\normalsize"],parse:()=>["Sequence"]},{trigger:["\\large"],parse:()=>["Sequence"]},{trigger:["\\Large"],parse:()=>["Sequence"]},{trigger:["\\LARGE"],parse:()=>["Sequence"]},{trigger:["\\huge"],parse:()=>["Sequence"]},{trigger:["\\Huge"],parse:()=>["Sequence"]},{name:"Style",serialize:(e,i)=>{let t=e.serialize(di(i,1));const n=yi(di(i,2));if(null===n)return t;"block"===ci(n.display)?t=Ke(["{\\displaystyle",t,"}"]):"inline"===ci(n.display)?t=Ke(["{\\textstyle",t,"}"]):"script"===ci(n.display)?t=Ke(["{\\scriptstyle",t,"}"]):"scriptscript"===ci(n.display)&&(t=Ke(["{\\scriptscriptstyle",t,"}"]));const r=xi(n.size);return null!==r&&r>=1&&r<=10&&(t=Ke(["{",{1:"\\tiny",2:"\\scriptsize",3:"\\footnotesize",4:"\\small",5:"\\normalsize",6:"\\large",7:"\\Large",8:"\\LARGE",9:"\\huge",10:"\\Huge"}[r],t,"}"])),t}},{trigger:["\\!"],parse:()=>["HorizontalSpacing",-3]},{trigger:["\\ "],parse:()=>["HorizontalSpacing",6]},{trigger:["\\:"],parse:()=>["HorizontalSpacing",4]},{trigger:["\\enskip"],parse:()=>["HorizontalSpacing",9]},{trigger:["\\quad"],parse:()=>["HorizontalSpacing",18]},{trigger:["\\qquad"],parse:()=>["HorizontalSpacing",36]},{trigger:["\\,"],parse:()=>["HorizontalSpacing",3]},{trigger:["\\;"],parse:()=>["HorizontalSpacing",5]},{trigger:["\\enspace"],parse:()=>["HorizontalSpacing",9]},{name:"HorizontalSpacing",serialize:(e,i)=>{var t;if(di(i,2))return e.serialize(di(i,1));const n=xi(di(i,1));return null===n?"":null!==(t={"-3":"\\!",6:"\\ ",3:"\\,",4:"\\:",5:"\\;",9:"\\enspace",18:"\\quad",36:"\\qquad"}[n])&&void 0!==t?t:""}}];function ji(e){return i=>{var t,n;let r=!1,a=0;if(i.skipSpace(),i.match("^")){if(i.skipSpace(),i.match("<{>")){i.skipSpace(),i.match("-")&&i.match("1")&&(r=!0);do{i.match("\\doubleprime")&&(a+=2),i.match("\\prime")&&(a+=1),i.match("'")&&(a+=1)}while(!i.match("<}>")&&!i.atEnd)}let e=!1;for(;!e;)i.skipSpace(),i.match("\\doubleprime")?a+=2:i.match("\\prime")||i.match("'")?a+=1:e=!0}let s=null!==(n=null!==(t={"\\arcsin":"Arcsin","\\arccos":"Arccos","\\arctan":"Arctan","\\arctg":"Arctan","\\arcctg":"Arctan","\\arcsec":"Arcsec","\\arccsc":" Arccsc","\\arsinh":"Arsinh","\\arcosh":"Arcosh","\\artanh":"Artanh","\\arcsech":"Arcsech","\\arccsch":"Arcsch","\\ch":"Cosh","\\cos":"Cos","\\cosec":"Csc","\\cosh":"Csch","\\cot":"Cot","\\cotg":"Cot","\\coth":"Coth","\\csc":"Csc","\\ctg":"Cot","\\cth":"Coth","\\sec":"Sec","\\sin":"Sin","\\sinh":"Sinh","\\sh":"Sinh","\\tan":"Tan","\\tanh":"Tanh","\\tg":"Tan","\\th":"Tanh"}[null!=e?e:""])&&void 0!==t?t:e)&&void 0!==n?n:"";r&&(s=["InverseFunction",s]),a>=1&&(s=["Derivative",a,s]);const o=i.matchArguments("implicit");return null===o?s:[s,...o]}}const Zi=[{name:"Arcsin",trigger:["\\arcsin"],parse:ji("Arcsin")},{name:"Arccos",trigger:["\\arccos"],parse:ji("Arccos")},{name:"Arctan",trigger:["\\arctan"],parse:ji("Arctan")},{trigger:["\\arctg"],parse:ji("Arctan")},{name:"Arccot",trigger:["\\arcctg"],parse:ji("Arccot")},{name:"Arcsec",trigger:["\\arcsec"],parse:ji("Arcsec")},{name:"Arccsc",trigger:["\\arccsc"],parse:ji("Arccsc")},{name:"Arsinh",trigger:["\\arsinh"],parse:ji("Arsinh")},{name:"Arcosh",trigger:["\\arcosh"],parse:ji("Arcosh")},{name:"Artanh",trigger:["\\artanh"],parse:ji("Artanh")},{name:"Arsech",trigger:["\\arsech"],parse:ji("Arsech")},{name:"Arcsch",trigger:["\\arcsch"],parse:ji("Arcsch")},{trigger:["\\ch"],parse:ji("Cosh")},{name:"Cosec",trigger:["\\cosec"],parse:ji("Cosec")},{name:"Cosh",trigger:["\\cosh"],parse:ji("Cosh")},{name:"Cot",trigger:["\\cot"],parse:ji("Cot")},{trigger:["\\cotg"],parse:ji("Cot")},{name:"Coth",trigger:["\\coth"],parse:ji("Coth")},{name:"Csc",trigger:["\\csc"],parse:ji("Csc")},{trigger:["\\ctg"],parse:ji("Cot")},{trigger:["\\cth"],parse:ji("Cotanh")},{name:"Sec",trigger:["\\sec"],parse:ji("Sec")},{name:"Sinh",trigger:["\\sinh"],parse:ji("Sinh")},{trigger:["\\sh"],parse:ji("Sinh")},{name:"Tan",trigger:["\\tan"],parse:ji("Tan")},{trigger:["\\tg"],parse:ji("Tan")},{name:"Tanh",trigger:["\\tanh"],parse:ji("Tanh")},{trigger:["\\th"],parse:ji("Tanh")},{name:"Cos",trigger:["\\cos"],parse:ji("Cos")},{name:"Sin",trigger:["\\sin"],parse:ji("Sin")}],Bi=[{name:"AlgebraicNumber",trigger:"\\bar\\Q"},{name:"ComplexNumber",trigger:["\\C"]},{trigger:"\\mathbb{C}",parse:"ComplexNumber"},{name:"ImaginaryNumber",trigger:["\\imaginaryI\\R"]},{name:"ExtendedComplexNumber",trigger:["\\bar\\C"]},{name:"EmptySet",trigger:["\\emptyset"]},{trigger:["\\varnothing"],parse:"EmptySet"},{name:"Integer",trigger:["\\Z"]},{trigger:"\\mathbb{Z}",parse:"Integer"},{name:"RationalNumber",trigger:["\\Q"]},{name:"RealNumber",trigger:["\\R"]},{name:"ExtendedRealNumber",trigger:["\\bar\\R"]},{name:"TranscendentalNumber",trigger:"\\R-\\bar\\Q"},{trigger:"\\R\\backslash\\bar\\Q",parse:"TranscendentalNumber"},{name:"NegativeNumber",trigger:"\\R^-"},{trigger:"\\R^{-}",parse:"NegativeNumber"},{trigger:"\\R_-",parse:"NegativeNumber"},{trigger:"\\R_{-}",parse:"NegativeNumber"},{trigger:"\\R^{\\lt}",parse:"NegativeNumber"},{name:"PositiveNumber",trigger:"\\R^+"},{trigger:"\\R^{+}",parse:"PositiveNumber"},{trigger:"\\R_+",parse:"PositiveNumber"},{trigger:"\\R_{+}",parse:"PositiveNumber"},{trigger:"\\R^{\\gt}",parse:"PositiveNumber"},{name:"NonPositiveNumber",trigger:"\\R^{0-}"},{trigger:"\\R^{-0}",parse:"NonPositiveNumber"},{trigger:"\\R^{\\leq}",parse:"NonPositiveNumber"},{name:"NegativeInteger",trigger:"\\Z^-"},{trigger:"\\Z^-",parse:"NegativeInteger"},{trigger:"\\Z^{-}",parse:"NegativeInteger"},{trigger:"\\Z_-",parse:"NegativeInteger"},{trigger:"\\Z_{-}",parse:"NegativeInteger"},{trigger:"\\Z^{\\lt}",parse:"NegativeInteger"},{name:"PositiveInteger",trigger:"\\Z^+"},{trigger:"\\Z^{+}",parse:"PositiveInteger"},{trigger:"\\Z_+",parse:"PositiveInteger"},{trigger:"\\Z_{+}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt0}",parse:"PositiveInteger"},{trigger:"\\N^+",parse:"PositiveInteger"},{trigger:"\\N^{+}",parse:"PositiveInteger"},{trigger:"\\N^*",parse:"PositiveInteger"},{trigger:"\\N^{*}",parse:"PositiveInteger"},{trigger:"\\N^\\star",parse:"PositiveInteger"},{trigger:"\\N^{\\star}",parse:"PositiveInteger"},{trigger:"\\N_1",parse:"PositiveInteger"},{trigger:"\\N_{1}",parse:"PositiveInteger"},{name:"NonNegativeInteger",trigger:["\\N"]},{trigger:"\\Z^{+0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{0+}",parse:"NonNegativeInteger"},{trigger:"\\mathbb{N}",parse:"NonNegativeInteger"},{trigger:"\\N_0",parse:"NonNegativeInteger"},{trigger:"\\N_{0}",parse:"NonNegativeInteger"},{name:"CartesianProduct",trigger:["\\times"],kind:"infix",associativity:"right",precedence:390,parse:(e,i,t)=>{if(390<i.minPrec)return null;const n=e.computeEngine;if(!n||!n.box(t).domain.isCompatible("Set"))return null;const r=e.index,a=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:390}));return null===a||!0!==n.box(t).domain.isCompatible("Set")?(e.index=r,null):["CartesianProduct",t,a]}},{name:"Complement",trigger:["^","\\complement"],kind:"infix"},{name:"Intersection",trigger:["\\cap"],kind:"infix",precedence:350},{name:"Interval",serialize:Gi},{name:"Multiple",serialize:Gi},{name:"Union",trigger:["\\cup"],kind:"infix",precedence:350},{name:"Range",serialize:Gi},{name:"SetMinus",trigger:["\\setminus"],kind:"infix",precedence:650},{name:"SymmetricDifference",trigger:["\\triangle"],kind:"infix",precedence:260},{trigger:["\\ni"],kind:"infix",associativity:"right",precedence:160,parse:(e,i,t)=>{const n=e.matchExpression(i);return null===n?null:["Element",n,t]}},{name:"Element",trigger:["\\in"],kind:"infix",precedence:240},{name:"NotElement",trigger:["\\notin"],kind:"infix",precedence:240},{name:"NotSubset",trigger:["\\nsubset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSuperset",trigger:["\\nsupset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSubsetNotEqual",trigger:["\\nsubseteq"],kind:"infix",associativity:"right",precedence:240},{name:"NotSupersetNotEqual",trigger:["\\nsupseteq"],kind:"infix",associativity:"right",precedence:240},{name:"SquareSubset",trigger:["\\sqsubset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSubsetEqual",trigger:["\\sqsubseteq"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSuperset",trigger:["\\sqsupset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSupersetEqual",trigger:["\\sqsupseteq"],kind:"infix",associativity:"right",precedence:265},{name:"Subset",trigger:["\\subset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\subsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{trigger:["\\varsubsetneqq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{name:"SubsetEqual",trigger:["\\subseteq"],kind:"infix",precedence:240},{name:"Superset",trigger:["\\supset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\supsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{trigger:["\\varsupsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{name:"SupersetEqual",trigger:["\\supseteq"],kind:"infix",associativity:"right",precedence:240}];function Gi(e,i){var t;if(null===i)return"";const n=hi(i);if(null===n)return"";if("Set"===n)return 0===pi(i)?"\\emptyset":2===pi(i)&&"Condition"===hi(di(i,2))?Ke(["\\left\\lbrace",e.serialize(di(i,1)),"\\middle\\mid",e.serialize(di(i,2)),"\\right\\rbrace"]):Ke(["\\left\\lbrace",...(null!==(t=fi(i))&&void 0!==t?t:[]).map((i=>e.serialize(i)+" ,")),"\\right\\rbrace"]);if("Range"===n)return Ke(["\\mathopen\\lbrack",e.serialize(di(i,1)),", ",e.serialize(di(i,2)),"\\mathclose\\rbrack"]);if("Interval"===n){let t=di(i,1),n=di(i,2),r=!1,a=!1;return"Open"===hi(t)&&(t=di(t,1),r=!0),"Open"===hi(n)&&(n=di(n,1),a=!0),Ke(["\\mathopen"+(r?"\\rbrack":"\\lbrack"),e.serialize(t),", ",e.serialize(n),"\\mathclose"+(a?"\\lbrack":"\\rbrack")])}return e.numericSetStyle(i,e.level),""}function Hi(e){return i=>{var t;i.skipSpace();let n=null,r=null;for(;!(r&&n||"_"!==i.peek&&"^"!==i.peek);)i.match("_")?r=i.matchRequiredLatexArgument():i.match("^")&&(n=i.matchRequiredLatexArgument()),i.skipSpace();("Nothing"===r||ki(r))&&(r=null),("Nothing"===n||ki(n))&&(n=null);let[a,s]=function(e){const i=e.index;let t=!1,n=e.matchExpression({minPrec:266,condition:()=>(e.matchAll(["\\mathrm","<{>","d","<}>"])&&(t=!0),t)});return t||(e.index=i,n=e.matchExpression({minPrec:266,condition:()=>(e.match("d")&&(t=!0),t)})),n&&!t?Ui(n):[n,t?vi(e.matchSymbol()):null]}(i);if(a&&!s&&"Add"===hi(a)){const i=[],o=[];for(const e of null!==(t=fi(a))&&void 0!==t?t:[])if(s)o.push(e);else{let t;[t,s]=Ui(e),i.push(null!=t?t:e)}if(null!==s&&o.length>0)return["Add",Wi(e,["Add",...i],s,r,n),...o]}return Wi(e,a,s,r,n)}}function Wi(e,i,t,n,r){return i&&t&&(i=["Lambda",_i(i,{[t]:"_"})]),!i||r||n||t?(null!=i||(i="Nothing"),r?[e,i,["Tuple",null!=t?t:"Nothing",null!=n?n:"Nothing",r]]:n?[e,i,["Tuple",null!=t?t:"Nothing",n]]:t?[e,i,t]:[e]):[e,i]}function Ui(e){const i=hi(e),t=di(e,1);if(!t)return[e,null];if("Multiply"===i){const i=fi(e);if(i&&i.length>1&&"d"===vi(i[i.length-2]))return 2===i.length?[null,vi(i[1])]:3===i.length?[i[0],vi(i[2])]:[["Multiply",...i.slice(0,-2)],vi(i[i.length-1])]}else if("Delimiter"===i){const[i,n]=Ui(t);if(n)return i?[["Delimiter",i,...fi(e).slice(1)],n]:[null,n]}else if("Add"===i){const i=fi(e);if(i&&i.length>0){const[e,t]=Ui(i[i.length-1]);if(t){if(e)return[["Add",...i.slice(0,-1),e],t];if(i.length>2)return[["Add",...i.slice(0,-1)],t];if(i.length>2)return[i[0],t]}}}else if("Negate"===i){const[e,i]=Ui(t);if(i)return[e?["Negate",e]:null,i]}else if("Divide"===i){const[i,n]=Ui(t);if(n)return[["Divide",null!=i?i:1,di(e,2)],n]}else{const i=fi(e);if(1===(null==i?void 0:i.length)){const[t,n]=Ui(i[0]);if(n)return[[hi(e),t],n]}}return[e,null]}function Qi(e){return(i,t)=>{var n;if(!di(t,1))return e;let r=di(t,2);const a=hi(r);let s=null;"Tuple"!==a&&"Triple"!==a&&"Pair"!==a&&"Single"!==a?(s=vi(r),r=null):s=null!==(n=vi(di(r,1)))&&void 0!==n?n:"x";let o=di(t,1);if("Lambda"===hi(o)&&di(o,1)&&(o=_i(di(o,1),{_:null!=s?s:"x",_1:null!=s?s:"x"})),!r)return Ke(s?[e,i.serialize(o),"\\mathrm{d}",s]:[e,i.serialize(o)]);let l=r?[i.serialize(di(r,2))]:[];l.length>0&&(l=["_{",...l,"}"]);let u=[];return di(r,3)&&(u=["^{",i.serialize(di(r,3)),"}"]),Ke([e,...u,...l,i.serialize(o),...s&&"Nothing"!==vi(s)?["\\,\\mathrm{d}",i.serialize(s)]:[]])}}const Yi=[{name:"Integrate",trigger:["\\int"],parse:Hi("Integrate"),serialize:Qi("\\int")},{trigger:["\\iint"],parse:Hi("Integrate")},{name:"CircularIntegrate",trigger:["\\oint"],parse:Hi("CircularIntegrate"),serialize:Qi("\\oint")}],Ki=[["Alpha","\\alpha",945],["Beta","\\beta",946],["Delta","\\delta",948],["Epsilon","\\epsilon",949],["EpsilonSymbol","\\varepsilon",1013],["Zeta","\\zeta",950],["Eta","\\eta",951],["Theta","\\theta",952],["ThetaSymbol","\\vartheta",977],["Iota","\\iota",953],["Kappa","\\kappa",954],["KappaSymbol","\\varkappa",1008],["Lambda","\\lambda",955],["Mu","\\mu",956],["Nu","\\nu",957],["Xi","\\xi",958],["Omicron","\\omicron",959],["PiSymbol","\\varpi",982],["Rho","\\rho",961],["RhoSymbol","\\varrho",1009],["Sigma","\\sigma",963],["FinalSigma","\\varsigma",962],["Tau","\\tau",964],["Phi","\\phi",981],["PhiLetter","\\varphi",966],["Upsilon","\\upsilon",965],["Chi","\\chi",967],["Psi","\\psi",968],["Omega","\\omega",969],["CapitalAlpha","\\Alpha",913],["CapitalBeta","\\Beta",914],["CapitalGamma","\\Gamma",915],["CapitalDelta","\\Delta",916],["CapitalEpsilon","\\Epsilon",917],["CapitalZeta","\\Zeta",918],["CapitalEta","\\Eta",919],["CapitalTheta","\\Theta",920],["CapitaIota","\\Iota",921],["CapitalKappa","\\Kappa",922],["CapitalLambda","\\Lambda",923],["CapitalMu","\\Mu",924],["CapitalNu","\\Nu",925],["CapitalXi","\\Xi",926],["CapitalOmicron","\\Omicron",927],["CapitalPi","\\Pi",928],["CapitalRho","\\Rho",929],["CapitalSigma","\\Sigma",931],["CapitalTau","\\Tau",932],["CapitalPhi","\\Phi",934],["CapitalUpsilon","\\Upsilon",933],["CapitalChi","\\Chi",935],["CapitalPsi","\\Psi",936],["CapitalOmega","\\Omega",937],["Digamma","\\digamma",989],["Alef","\\aleph",8501],["Bet","\\beth",8502],["Gimel","\\gimel",8503],["Dalet","\\daleth",8504],["TurnedCapitalF","\\Finv",8498],["TurnedCapitalG","\\Game",8513],["Weierstrass","\\wp",8472],["Eth","\\eth",240],["InvertedOhm","\\mho",8487],["BlackClubSuit","\\clubsuit",9827],["WhiteHeartSuit","\\heartsuit",9825],["BlackSpadeSuit","\\spadesuit",9824],["WhiteDiamondSuit","\\diamondsuit",9826],["Sharp","\\sharp",9839],["Flat","\\flat",9837],["Natural","\\natural",9838]],Ji=[...Ki.map((([e,i,t])=>({name:e,trigger:[i],parse:e}))),...Ki.map((([e,i,t])=>({trigger:[String.fromCodePoint(t)],parse:e})))],Xi={"(":"(",")":")","[":"\\lbrack","]":"\\rbrack","{":"\\lbrace","}":"\\rbrace","<":"\\langle",">":"\\rangle","|":"\\vert","||":"\\Vert","\\lceil":"\\lceil","\\lfloor":"\\lfloor","\\rceil":"\\rceil","\\rfloor":"\\rfloor"};function et(e){return Array.isArray(e)?e.length:1}function it(e,l){var u,c,h,m,d,f,g,p;if(!function(e,i){var t,o;const l=null!==(o=null!==(t=e.name)&&void 0!==t?t:e.trigger)&&void 0!==o?o:e.openDelimiter;if(void 0!==e.serialize&&!e.name)return i({severity:"warning",message:["invalid-dictionary-entry",l,"Unexpected serialize property without a name property"]}),!1;if(n(e)){if(e.trigger)return i({severity:"warning",message:["invalid-dictionary-entry",l,`Unexpected 'trigger' "${e.trigger}". 'matchfix' operators use a 'openDelimiter' and 'closeDelimiter' instead of a trigger. `]}),!1;if(!e.openDelimiter||!e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected `openDelimiter` and a `closeDelimiter` for matchfix operator"]}),!1;if(typeof e.openDelimiter!=typeof e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected `openDelimiter` and `closeDelimiter` to both be strings or array of LatexToken"]}),!1}if(r(e)||s(e)||a(e)){if(Array.isArray(e.trigger)&&("_"===e.trigger[0]||"^"===e.trigger[0])||"string"==typeof e.trigger&&(e.trigger.startsWith("^")||e.trigger.startsWith("_"))){if(void 0!==e.precedence||void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",l,'Unexpected "precedence" or "associativity" for superscript/subscript operator']}),!1}else if(void 0===e.precedence)return i({severity:"warning",message:["invalid-dictionary-entry",l,`Expected a "precedence" for ${e.kind} operator`]}),!1}else if(void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",l,'Unexpected "associativity" operator']}),!1;return n(e)||e.trigger||e.name?void 0!==e.parse||void 0!==e.name||(i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected a 'parse' or 'name'"]}),!1):(i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected at least a 'trigger' or a 'name'"]}),!1)}(e,l))return[null,null];const v={name:e.name,kind:"kind"in e?e.kind:"symbol"};if("matchfix"===v.kind&&n(e)){if(v.openDelimiter=e.openDelimiter,v.closeDelimiter=e.closeDelimiter,"function"==typeof e.serialize)v.serialize=e.serialize;else{const e="string"==typeof v.openDelimiter?Xi[v.openDelimiter]:Je(v.openDelimiter),i="string"==typeof v.closeDelimiter?Xi[v.closeDelimiter]:Je(v.closeDelimiter);v.serialize=(t,n)=>Ke([e,t.serialize(di(n,1)),i])}if("function"==typeof e.parse)v.parse=e.parse;else{const i=null!==(u=e.parse)&&void 0!==u?u:e.name;v.parse=(e,t)=>[i,t]}return[null,v]}if("environment"===v.kind&&o(e)){const i=e.trigger;return v.serialize=null!==(c=e.serialize)&&void 0!==c?c:(e,t)=>`\\begin{${i}}${e.serialize(di(t,1))}\\end{${i}}`,v.parse=null!==(h=e.parse)&&void 0!==h?h:()=>null,[i,v]}const b="string"==typeof e.trigger?Ye(e.trigger,[]):e.trigger,y=b?Je(b):"";if("function"===v.kind&&t(e))return v.serialize=e.serialize,y&&!e.serialize&&(v.serialize=(e,i)=>`\\mathrm{${y}}${e.wrapArguments(i)}`),v.parse=e.parse,!v.parse&&e.name&&(v.parse=i=>{const t=i.matchArguments("enclosure");return null===t?e.name:[e.name,...t]}),[y,v];if(e.trigger,"symbol"===v.kind&&i(e)&&(v.precedence=null!==(m=e.precedence)&&void 0!==m?m:1e4),"infix"!==v.kind&&"prefix"!==v.kind&&"postfix"!==v.kind||!(r(e)||a(e)||s(e))||(!b||"^"!==b[0]&&"_"!==b[0]?v.precedence=null!==(d=e.precedence)&&void 0!==d?d:1e4:v.precedence=720),"infix"===v.kind&&r(e))if(v.associativity=null!==(f=e.associativity)&&void 0!==f?f:"non","function"==typeof e.parse)v.parse=e.parse;else if(!b||"^"!==b[0]&&"_"!==b[0]){const i=null!==(p=e.parse)&&void 0!==p?p:e.name,t=v.precedence,n=v.associativity;v.parse=(e,r,a)=>{if(t<r.minPrec)return null;const s=Ii(e.matchExpression(Object.assign(Object.assign({},r),{minPrec:t})));return"string"==typeof i?wi(i,a,s,n):[i,a,s]}}else{const i=null!==(g=e.parse)&&void 0!==g?g:e.name;v.parse=(e,t,n)=>[i,Ii(di(n,1)),Ii(di(n,2))]}else if("function"==typeof e.parse)v.parse=e.parse;else if(void 0!==e.parse)v.parse=()=>e.parse;else if(void 0===e.parse&&void 0!==e.name)if("postfix"===v.kind)v.parse=(i,t)=>t?[e.name,t]:null;else if("prefix"===v.kind){const i=v.precedence,t=e.name;v.parse=(e,n)=>{if(i<n.minPrec)return null;const r=e.matchExpression(Object.assign(Object.assign({},n),{minPrec:i}));return null===r?null:[t,r]}}return"function"==typeof e.serialize||"string"==typeof e.serialize?v.serialize=e.serialize:b&&("postfix"===v.kind?v.serialize="#1"+y:"prefix"===v.kind?v.serialize=y+"#1":"infix"===v.kind?v.serialize="#1"+y+"#2":"symbol"===v.kind?v.serialize=y:v.serialize=""),[null!=b?b:null,v]}const tt={algebra:[{name:"To",trigger:["\\to"],kind:"infix",precedence:270}],arithmetic:Ti,calculus:Yi,core:Pi,logic:[{name:"True",trigger:["\\mathrm","<{>","T","r","u","e","<}>"],serialize:"\\mathrm{True}"},{name:"False",trigger:["\\mathrm","<{>","F","a","l","s","e","<}>"],serialize:"\\mathrm{False}"},{name:"Maybe",trigger:["\\mathrm","<{>","M","a","y","b","e","<}>"],serialize:"\\mathrm{Maybe}"}],relop:[{trigger:["!","<"],kind:"infix",associativity:"right",precedence:246,parse:"NotLess"},{name:"NotLess",trigger:["\\nless"],kind:"infix",associativity:"right",precedence:246},{trigger:["<"],kind:"infix",associativity:"right",precedence:245,parse:"Less"},{name:"Less",trigger:["\\lt"],kind:"infix",associativity:"right",precedence:245},{trigger:["<","="],kind:"infix",associativity:"right",precedence:241,parse:"LessEqual"},{name:"LessEqual",trigger:["\\le"],kind:"infix",associativity:"right",precedence:241},{trigger:["\\leq"],kind:"infix",associativity:"right",precedence:241,parse:"Equal"},{trigger:["\\leqslant"],kind:"infix",associativity:"right",precedence:265,parse:"LessEqual"},{name:"LessNotEqual",trigger:["\\lneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotLessNotEqual",trigger:["\\nleqq"],kind:"infix",associativity:"right",precedence:260},{name:"LessOverEqual",trigger:["\\leqq"],kind:"infix",associativity:"right",precedence:265},{name:"GreaterOverEqual",trigger:["\\geqq"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"Equal",trigger:["="],kind:"infix",associativity:"right",precedence:260},{trigger:["*","="],kind:"infix",associativity:"right",precedence:260,parse:"StarEqual"},{name:"StarEqual",trigger:["\\star","="],kind:"infix",associativity:"right",precedence:260},{name:"PlusEqual",trigger:["+","="],kind:"infix",associativity:"right",precedence:260},{name:"MinusEqual",trigger:["-","="],kind:"infix",associativity:"right",precedence:260},{name:"SlashEqual",trigger:["/","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqual",trigger:["=","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqualEqual",trigger:["=","=","="],kind:"infix",associativity:"right",precedence:265},{name:"TildeFullEqual",trigger:["\\cong"],kind:"infix",associativity:"right",precedence:260},{name:"NotTildeFullEqual",trigger:["\\ncong"],kind:"infix",associativity:"right",precedence:260},{trigger:[":","="],kind:"infix",associativity:"right",precedence:260,parse:"Assign"},{name:"Assign",trigger:["\\coloneq"],kind:"infix",associativity:"right",precedence:260},{name:"Approx",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"NotApprox",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"ApproxEqual",trigger:["\\approxeq"],kind:"infix",associativity:"right",precedence:260},{name:"NotApproxEqual",trigger:["!","\\approxeq"],kind:"infix",associativity:"right",precedence:250},{name:"NotEqual",trigger:["\\ne"],kind:"infix",associativity:"right",precedence:255},{name:"Unequal",trigger:["!","="],kind:"infix",associativity:"right",precedence:260},{name:"GreaterEqual",trigger:["\\ge"],kind:"infix",associativity:"right",precedence:242},{trigger:["\\geq"],kind:"infix",associativity:"right",precedence:242,parse:"GreaterEqual"},{trigger:[">","="],kind:"infix",associativity:"right",precedence:243,parse:"GreaterEqual"},{trigger:["\\geqslant"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"GreaterNotEqual",trigger:["\\gneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotGreaterNotEqual",trigger:["\\ngeqq"],kind:"infix",associativity:"right",precedence:260},{trigger:[">"],kind:"infix",associativity:"right",precedence:245,parse:"Greater"},{name:"Greater",trigger:["\\gt"],kind:"infix",associativity:"right",precedence:245},{name:"NotGreater",trigger:["\\ngtr"],kind:"infix",associativity:"right",precedence:244},{trigger:["!",">"],kind:"infix",associativity:"right",precedence:244,parse:"NotGreater"},{name:"RingEqual",trigger:["\\circeq"],kind:"infix",associativity:"right",precedence:260},{name:"TriangleEqual",trigger:["\\triangleq"],kind:"infix",associativity:"right",precedence:260},{name:"DotEqual",trigger:["\\doteq"],kind:"infix",associativity:"right",precedence:265},{name:"DotEqualDot",trigger:["\\doteqdot"],kind:"infix",associativity:"right",precedence:265},{name:"FallingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"RisingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"QuestionEqual",trigger:["\\questeq"],kind:"infix",associativity:"right",precedence:260},{name:"Equivalent",trigger:["\\equiv"],kind:"infix",associativity:"right",precedence:260},{trigger:["\\iff"],kind:"infix",parse:"Equivalent",associativity:"right",precedence:260},{name:"MuchLess",trigger:["\\ll"],kind:"infix",associativity:"right",precedence:260},{name:"MuchGreater",trigger:["\\gg"],kind:"infix",associativity:"right",precedence:260},{name:"Precedes",trigger:["\\prec"],kind:"infix",associativity:"right",precedence:260},{name:"Succeeds",trigger:["\\succ"],kind:"infix",associativity:"right",precedence:260},{name:"PrecedesEqual",trigger:["\\preccurlyeq"],kind:"infix",associativity:"right",precedence:260},{name:"SucceedsEqual",trigger:["\\curlyeqprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotPrecedes",trigger:["\\nprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotSucceeds",trigger:["\\nsucc"],kind:"infix",associativity:"right",precedence:260},{name:"Between",trigger:["\\between"],kind:"infix",associativity:"right",precedence:265}],other:$i,physics:[{name:"mu-0",trigger:"\\mu_0"}],sets:Bi,symbols:Ji,trigonometry:Zi},nt={"(":["\\lparen","("],")":["\\rparen",")"],"[":["\\lbrack"],"]":["\\rbrack"],"<":["<","\\langle"],">":[">","\\rangle"],"{":["\\{","\\lbrace"],"}":["\\}","\\rbrace"],":":[":","\\colon"],"|":["|","\\|","\\lvert","\\rvert"],"||":["||","\\Vert","\\lVert","\\rVert"],"\\lfloor":["\\lfloor"],"\\rfloor":["\\rfloor"],"\\lceil":["\\lceil"],"\\rceil":["\\rceil"],"\\ulcorner":["\\ulcorner"],"\\urcorner":["\\urcorner"],"\\llcorner":["\\llcorner"],"\\lrcorner":["\\lrcorner"],"\\lgroup":["\\lgroup"],"\\rgroup":["\\rgroup"],"\\lmoustache":["\\lmoustache"],"\\rmoustache":["\\rmoustache"]},rt={":":[":","\\colon"],"|":["|","\\|","\\mid","\\mvert"]},at={"\\left":"\\right","\\bigl":"\\bigr","\\Bigl":"\\Bigr","\\biggl":"\\biggr","\\Biggl":"\\Biggr","\\big":"\\big","\\Big":"\\Big","\\bigg":"\\bigg","\\Bigg":"\\Bigg"},st=["\\middle","\\bigm","\\Bigm","\\biggm","\\Biggm","\\big","\\Big","\\bigg","\\Bigg"],ot={"(":")","[":"]","\\{":"\\}","\\lbrace":"\\rbrace","\\lparen":"\\rparen","\\langle":"\\rangle","\\lfloor":"\\rfloor","\\lceil":"\\rceil","\\vert":"\\vert","\\lvert":"\\rvert","\\Vert":"\\Vert","\\lVert":"\\rVert","\\lbrack":"\\rbrack","\\ulcorner":"\\urcorner","\\llcorner":"\\lrcorner","\\lgroup":"\\rgroup","\\lmoustache":"\\rmoustache"},lt={precision:6,positiveInfinity:"\\infty",negativeInfinity:"-\\infty",notANumber:"\\operatorname{NaN}",decimalMarker:".",groupSeparator:"\\,",exponentProduct:"\\cdot",beginExponentMarker:"10^{",endExponentMarker:"}",notation:"auto",truncationMarker:"\\ldots",beginRepeatingDigits:"\\overline{",endRepeatingDigits:"}",imaginaryNumber:"\\imaginaryI",avoidExponentsInRange:[-7,20]},ut={applyInvisibleOperator:"auto",skipSpace:!0,parseArgumentsOfUnknownLatexCommands:!0,parseNumbers:!0,parseUnknownSymbol:(e,i)=>{var t;return void 0!==(null===(t=i.computeEngine)||void 0===t?void 0:t.lookupFunction(e))?"function":/^[a-zA-Z]+$/.test(e)?"symbol":"unknown"},preserveLatex:!1};class ct{constructor(e,i,t,n){this.index=0,this._boundaries=[],this._lastPeek="",this._peekCounter=0,this._tokens=e,this.options=Object.assign(Object.assign(Object.assign({},lt),ut),i),this._dictionary=t,this.computeEngine=n,this._positiveInfinityTokens=Ye(this.options.positiveInfinity,[]),this._negativeInfinityTokens=Ye(this.options.negativeInfinity,[]),this._notANumberTokens=Ye(this.options.notANumber,[]),this._decimalMarkerTokens=Ye(this.options.decimalMarker,[]),this._groupSeparatorTokens=Ye(this.options.groupSeparator,[]),this._exponentProductTokens=Ye(this.options.exponentProduct,[]),this._beginExponentMarkerTokens=Ye(this.options.beginExponentMarker,[]),this._endExponentMarkerTokens=Ye(this.options.endExponentMarker,[]),this._truncationMarkerTokens=Ye(this.options.truncationMarker,[]),this._beginRepeatingDigitsTokens=Ye(this.options.beginRepeatingDigits,[]),this._endRepeatingDigitsTokens=Ye(this.options.endRepeatingDigits,[]),this._imaginaryNumberTokens=Ye(this.options.imaginaryNumber,[])}updateOptions(e){for(const[i,t]of Object.entries(e)){if(!(i in this.options))throw Error(`Unexpected option "${i}"`);this.options[i]=t,"string"==typeof t&&("positiveInfinity"===i&&(this._positiveInfinityTokens=Ye(t,[])),"negativeInfinity"===i&&(this._negativeInfinityTokens=Ye(t,[])),"notANumber"===i&&(this._notANumberTokens=Ye(t,[])),"decimalMarker"===i&&(this._decimalMarkerTokens=Ye(t,[])),"groupSeparator"===i&&(this._groupSeparatorTokens=Ye(t,[])),"exponentProduct"===i&&(this._exponentProductTokens=Ye(t,[])),"beginExponentMarker"===i&&(this._beginExponentMarkerTokens=Ye(t,[])),"endExponentMarker"===i&&(this._endExponentMarkerTokens=Ye(t,[])),"truncationMarker"===i&&(this._truncationMarkerTokens=Ye(t,[])),"beginRepeatingDigits"===i&&(this._beginRepeatingDigitsTokens=Ye(t,[])),"endRepeatingDigits"===i&&(this._endRepeatingDigitsTokens=Ye(t,[])),"imaginaryNumber"===i&&(this._imaginaryNumberTokens=Ye(t,[])))}}get atEnd(){return this.index>=this._tokens.length}get peek(){const e=this._tokens[this.index];if(e===this._lastPeek?this._peekCounter+=1:this._peekCounter=0,this._peekCounter>=1024)throw Error(`Infinite loop detected while parsing "${this.latex(0)}" at ${this._lastPeek} (index ${this.index})`);return this._lastPeek=e,e}next(){return this._tokens[this.index++]}atTerminator(e){return!!this.atBoundary||!(!(null==e?void 0:e.condition)||!e.condition(this))}get atBoundary(){if(this.atEnd)return!0;const e=this.index;for(const i of this._boundaries)if(this.matchAll(i.tokens))return this.index=e,!0;return!1}addBoundary(e){this._boundaries.push({index:this.index,tokens:e})}removeBoundary(){this._boundaries.pop()}matchBoundary(){const e=this._boundaries[this._boundaries.length-1],i=e&&this.matchAll(e.tokens);return i&&this._boundaries.pop(),i}boundaryError(e){const i=this._boundaries[this._boundaries.length-1];return this._boundaries.pop(),this.error(e,i.index)}latex(e,i){return Je(this._tokens.slice(e,i))}latexAhead(e){return this.latex(this.index,this.index+e)}latexBefore(){return this.latex(0,this.index)}latexAfter(){return this.latex(this.index)}lookAhead(){let e=Math.min(this._dictionary.lookahead,this._tokens.length-this.index);const i=Array(e+1);for(;e>0;)i[e]=this.latexAhead(e--);return i}peekDefinitions(e){let i;if("function"===e){const e=this.index;if(this.match("\\operatorname")||this.match("\\mathrm")||this.match("\\mathit")){const i=this.matchStringArgument(),t=this.index-e;return this.index=e,null!==i&&this._dictionary.function.has(i)?this._dictionary.function.get(i).map((e=>[e,t])):null}return null}i="operator"===e?this.lookAhead().map(((e,i)=>{var t,n,r,a,s;return null!==(a=null!==(n=null===(t=this._dictionary.infix[i])||void 0===t?void 0:t.get(e))&&void 0!==n?n:null===(r=this._dictionary.postfix[i])||void 0===r?void 0:r.get(e))&&void 0!==a?a:null===(s=this._dictionary.prefix[i])||void 0===s?void 0:s.get(e)})):this.lookAhead().map(((i,t)=>{var n;return null===(n=this._dictionary[e][t])||void 0===n?void 0:n.get(i)}));const t=[];for(let e=i.length;e>0;e--)if(void 0!==i[e])for(const n of i[e])t.push([n,e]);return 0===t.length?null:t}skipSpaceTokens(){for(;this.match("<space>"););}skipSpace(){if(!this.atEnd&&"<{>"===this.peek){const e=this.index;for(this.next();this.match("<space>"););if("<}>"===this.next())return this.skipSpace(),!0;this.index=e}if(!this.options.skipSpace)return!1;let e=!1;for(;this.match("<space>");)e=!0;return e&&this.skipSpace(),e}matchChar(){var e;const i=this.index;let t=0;for(;this.match("^");)t+=1;if(t>=2){let e="",i=0;for(;i!=t;){const t=this.matchAny(["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]);if(!t)break;e+=t,i+=1}if(e.length===t)return String.fromCodePoint(Number.parseInt(e,16))}else{if(this.match("\\char")){let i=Math.floor(null!==(e=this.matchLatexNumber())&&void 0!==e?e:NaN);return(!Number.isFinite(i)||i<0||i>1114111)&&(i=10067),String.fromCodePoint(i)}if(this.match("\\unicode"))if(this.skipSpaceTokens(),"<{>"===this.peek){this.next();const e=this.matchLatexNumber();if(this.match("<}>")&&null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}else{const e=this.matchLatexNumber();if(null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}}return this.index=i,this.next()}matchColor(e=!1){let i="";for(;!this.atEnd&&"}"!==this.peek;)i+=this.next();return i}matchLatexDimension(){return null}match(e){return this._tokens[this.index]===e&&(this.index++,!0)}matchAll(e){if("string"==typeof e&&(e=[e]),0===e.length)return!1;let i=!0,t=0;do{i=this._tokens[this.index+t]===e[t++]}while(i&&t<e.length);return i&&(this.index+=t),i}matchAny(e){return e.includes(this._tokens[this.index])?this._tokens[this.index++]:""}matchSequence(e){const i=[];for(;e.includes(this._tokens[this.index]);)i.push(this._tokens[this.index++]);return i}matchOptionalSign(){let e=!!this.matchAny(["-","\u2212"]);for(;this.matchAny(["+","\ufe62"])||this.skipSpace();)this.matchAny(["-","\u2212"])&&(e=!e);return e?"-":"+"}matchDecimalDigits(e){var i;null!=e||(e={}),null!==(i=e.withGrouping)&&void 0!==i||(e.withGrouping=!1);let t="",n=!1;for(;!n;)if(t+=this.matchSequence(["0","1","2","3","4","5","6","7","8","9"]).join(""),n=!0,e.withGrouping&&this.options.groupSeparator){const e=this.index;this.skipSpace(),this.matchAll(this._groupSeparatorTokens)&&(this.skipSpace(),/[0-9]/.test(this.peek)?n=!1:this.index=e)}return t}matchSignedInteger(e){var i;null!=e||(e={}),null!==(i=e.withGrouping)&&void 0!==i||(e.withGrouping=!1);const t=this.index,n=this.matchOptionalSign(),r=this.matchDecimalDigits(e);return r?"-"===n?"-"+r:r:(this.index=t,"")}matchExponent(){const e=this.index;if(this.matchAny(["e","E"])){const e=this.matchSignedInteger({withGrouping:!1});if(e)return"e"+e}if(this.index=e,this.match("\\times")&&(this.skipSpaceTokens(),this.match("1")&&this.match("0")&&this.match("^"))){if(/[0-9]/.test(this.peek))return"e"+this.next();if(this.match("<{>")){this.skipSpaceTokens();const e=this.matchSignedInteger();if(this.skipSpaceTokens(),this.match("<}>")&&e)return"e"+e}}if(this.index=e,this.skipSpaceTokens(),this.match("\\%"))return"e-2";if(this.index=e,this.matchAll(this._exponentProductTokens)&&(this.skipSpaceTokens(),this.matchAll(this._beginExponentMarkerTokens))){this.skipSpaceTokens();const e=this.matchSignedInteger();if(this.skipSpaceTokens(),this.matchAll(this._endExponentMarkerTokens)&&e)return"e"+e}return this.index=e,""}matchRepeatingDecimal(){const e=this.index;let i="";return this.match("(")?(i=this.matchDecimalDigits(),i&&this.match(")")?"("+i+")":""):(this.index=e,this.matchAll(["\\left","("])?(i=this.matchDecimalDigits(),i&&this.matchAll(["\\right",")"])?"("+i+")":""):(this.index=e,this.matchAll(["\\overline","<{>"])?(i=this.matchDecimalDigits(),i&&this.match("<}>")?"("+i+")":""):(this.index=e,this.matchAll(this._beginRepeatingDigitsTokens)?(i=this.matchDecimalDigits(),i&&this.matchAll(this._endRepeatingDigitsTokens)?"("+i+")":""):(this.index=e,""))))}matchNumber(){if(!this.options.parseNumbers)return"";const e=this.index;this.skipSpace(),this.match("+");let i="",t=!1;if(this.match(".")||this.matchAll(this._decimalMarkerTokens)){const i=this.peek;if("\\overline"===i&&i===this._beginRepeatingDigitsTokens[0]&&!/[0-9]\(/.test(i))return this.index=e,"";t=!0}else if(i=this.matchDecimalDigits({withGrouping:!0}),!i)return this.index=e,"";let n=!1;if(t||!this.match(".")&&!this.matchAll(this._decimalMarkerTokens)?t&&(i="0."+this.matchDecimalDigits({withGrouping:!0}),n=!0):(i+="."+this.matchDecimalDigits({withGrouping:!0}),n=!0),n){const e=this.matchRepeatingDecimal();e?i+=e:this.match("\\ldots")||this.matchAll(this._truncationMarkerTokens)}return i+this.matchExponent()}matchLatexNumber(e=!0){var i,t;let n=!1,r=this.peek;for(;"<space>"===r||"+"===r||"-"===r;)"-"===r&&(n=!n),this.next(),r=this.peek;let a=10,s=["0","1","2","3","4","5","6","7","8","9"];if(this.match("'"))a=8,s=["0","1","2","3","4","5","6","7"],e=!0;else if(this.match('"')||this.match("x"))a=16,s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],e=!0;else if(this.match("`"))return r=this.next(),r?r.startsWith("\\")&&2===r.length?(n?-1:1)*(null!==(i=r.codePointAt(1))&&void 0!==i?i:0):(n?-1:1)*(null!==(t=r.codePointAt(0))&&void 0!==t?t:0):null;let o="";for(;s.includes(this.peek);)o+=this.next();if(!e&&this.match("."))for(o+=".";s.includes(this.peek);)o+=this.next();const l=e?Number.parseInt(o,a):Number.parseFloat(o);return Number.isNaN(l)?null:n?-l:l}matchPrefixOperator(e){e||(e={minPrec:0}),e.minPrec||(e=Object.assign(Object.assign({},e),{minPrec:0}));const i=this.peekDefinitions("prefix");if(null===i)return null;const t=this.index;for(const[n,r]of i){this.index=t+r;const i=n.parse(this,e);if(i)return i}return this.index=t,null}matchInfixOperator(e,i){i||(i={minPrec:0}),i.minPrec||(i=Object.assign(Object.assign({},i),{minPrec:0}));const t=this.peekDefinitions("infix");if(null===t)return null;const n=this.index;for(const[r,a]of t)if(r.precedence>=i.minPrec){this.index=n+a;const t=r.parse(this,i,e);if(t)return t}return this.index=n,null}matchArguments(e){var i,t,n,r;if(!e)return null;const a=this.index,s=this.matchEnclosure();if("enclosure"===e&&"Delimiter"===hi(s))return"Sequence"===di(s,1)?null!==(i=fi(di(s,1)))&&void 0!==i?i:[]:[null!==(t=di(s,1))&&void 0!==t?t:["Sequence"]];if("implicit"===e){if("Delimiter"===hi(s))return"Sequence"===di(s,1)?null!==(n=Ei(s))&&void 0!==n?n:[]:[null!==(r=di(s,1))&&void 0!==r?r:["Sequence"]];if(null!==s)return[s];const e=this.matchExpression({minPrec:390});return null!==e?[e]:null}return this.index=a,null}matchOpenDelimiter(e,i){var t;const n=this.index,r=at[this.peek];r&&this.next();const a=null!==(t=nt[e])&&void 0!==t?t:[e],s=r?[r]:[];return a.includes("||")&&this.matchAll(["|","|"])?(s.push("|"),s.push("|"),s):a.includes(this.peek)?(ot[e]===i?s.push(ot[this.peek]):s.push(i),this.next(),s):(this.index=n,null)}matchMiddleDelimiter(e){var i;const t=null!==(i=rt[e])&&void 0!==i?i:[e];if(st.includes(this.peek)){const e=this.index;return this.next(),t.includes(this.peek)?(this.next(),!0):(this.index=e,!1)}return!!t.include(this.peek)&&(this.next(),!0)}matchEnclosure(){const e=this._dictionary.matchfix;if(0===e.length)return null;const i=this.index;for(const t of e){if(this.index=i,Array.isArray(t.openDelimiter)){if(!this.matchAll(t.openDelimiter))continue;this.addBoundary(t.closeDelimiter);const e=this.matchExpression();if(this.skipSpace(),!this.matchBoundary()){this.removeBoundary();continue}const i=t.parse(this,null!=e?e:["Sequence"]);if(null===i)continue;return i}const e=this.matchOpenDelimiter(t.openDelimiter,t.closeDelimiter);if(null===e)continue;if(this.matchAll(e)){const e=t.parse(this,["Sequence"]);if(null===e)continue;return e}this.addBoundary(e);const n=this.index;let r=this.matchExpression();if(this.skipSpace(),!this.matchBoundary()&&(this.removeBoundary(),this.index=n,r=this.matchExpression(),!this.matchAll(e))){if(!this.atEnd)continue;return this.index=n,null}const a=t.parse(this,null!=r?r:["Sequence"]);if(null!==a)return a}return this.index=i,null}matchIdentifier(){let e=null;return this.match("\\operatorname")||this.match("\\mathit")||this.match("\\mathrm")?(e=this.matchStringArgument(),null===e||ui(e),e):(e=this.peek,/[a-zA-Z]/.test(e)?this.next():null)}matchFunction(){var e,i;const t=this.index,n=this.peekDefinitions("function");if(n)for(const[e,i]of n){if(this.index=t+i,"function"!=typeof e.parse){const i=Ei(this.matchEnclosure());return i?[e.name,...i]:e.name}{const i=e.parse(this);if(i)return i}}this.index=t;let r=null;if(this.match("\\operatorname")||this.match("\\mathit")||this.match("\\mathrm")){if(r=this.matchStringArgument(),null===r)return this.error("expected-string-argument",t);if(!ui(r))return this.error("invalid-symbol-name",t)}if(r||(r=this.next(),ui(r)||(r=null)),r&&"function"===(null===(i=(e=this.options).parseUnknownSymbol)||void 0===i?void 0:i.call(e,r,this))){const e=Ei(this.matchEnclosure());return e?[r,...e]:r}return this.index=t,null}matchSymbol(){var e,i;const t=this.index;let n=null;const r=this.peekDefinitions("symbol");if(r)for(const[e,i]of r){if(this.index=t+i,"function"!=typeof e.parse)return e.name;{const i=e.parse(this);if(i)return i}}if(this.index=t,this.match("\\operatorname")||this.match("\\mathit")||this.match("\\mathrm")){if(n=this.matchStringArgument(),null===n)return this.error("expected-string-argument",t);if(!ui(n))return this.error("invalid-symbol-name",t)}return n||(n=this.next()),n&&ui(n)&&"symbol"===(null===(i=(e=this.options).parseUnknownSymbol)||void 0===i?void 0:i.call(e,n,this))?n:(this.index=t,null)}matchOptionalLatexArgument(){const e=this.index;if(this.skipSpaceTokens(),this.match("[")){this.addBoundary(["]"]);const e=this.matchExpression();return this.skipSpace(),this.matchBoundary()?e:this.boundaryError("expected-closing-delimiter")}return this.index=e,null}matchRequiredLatexArgument(){const e=this.index;if(this.skipSpaceTokens(),this.match("<{>")){this.addBoundary(["<}>"]);const e=this.matchExpression();return this.skipSpace(),this.matchBoundary()?null!=e?e:["Sequence"]:this.boundaryError("expected-closing-delimiter")}return/^[0-9]$/.test(this.peek)?parseInt(this.next()):/^[^\\#]$/.test(this.peek)?this.next():this.matchSymbol()||(this.index=e,null)}matchSupsub(e){var i,t,n;if(null===e)return null;const r=this.index;this.skipSpace();const a=[],s=[];let o=r;for(;"_"===this.peek||"^"===this.peek;){if(this.match("_"))if(o=this.index,this.match("_")||this.match("^"))s.push(this.error("syntax-error",o));else{const e=null!==(i=this.matchRequiredLatexArgument())&&void 0!==i?i:this.matchStringArgument();if(null===e)return this.error("missing",r);s.push(e)}else if(this.match("^"))if(o=this.index,this.match("_")||this.match("^"))a.push(this.error("syntax-error",o));else{const e=this.matchRequiredLatexArgument();if(null===e)return this.error("missing",r);a.push(e)}o=this.index,this.skipSpace()}if(0===a.length&&0===s.length)return this.index=r,e;let l=e;if(s.length>0){const e=null===(t=this._dictionary.infix[1])||void 0===t?void 0:t.get("_");if(e){const i=["Subscript",l,1===s.length?s[0]:["List",...s]];for(const t of e)if(l="function"==typeof t.parse?t.parse(this,{minPrec:0},i):i,l)break}}if(a.length>0){const e=null===(n=this._dictionary.infix[1])||void 0===n?void 0:n.get("^");if(e){const i=["Superscript",l,1===a.length?a[0]:["List",...a]];for(const t of e)if(l="function"==typeof t.parse?t.parse(this,{minPrec:0},i):i,l)break}}return null===l&&(this.index=r),l}matchPostfix(e){if(null===e)return null;const i=this.peekDefinitions("postfix");if(null===i)return null;const t=this.index;for(const[n,r]of i){this.index=t+r;const i=n.parse(this,e);if(null!==i)return i}return this.index=t,null}matchString(){let e="";for(;!this.atBoundary;){const i=this.peek;if("<$>"===i||"<$$>"===i)return"";"<space>"===i?(this.next(),e+=" "):(i[0],e+=this.next())}return e}matchStringArgument(){const e=this.index;if(this.skipSpaceTokens(),this.match("<{>")){for(this.addBoundary(["<}>"]);this.match("<space>"););const e=this.matchString();if(this.matchBoundary())return e.trimEnd();this.removeBoundary()}return this.index=e,null}matchTabular(){var e;const i=[];let t=[],n=null;for(;!this.atBoundary;)if(this.skipSpace(),this.match("&"))t.push(null!=n?n:"Nothing"),n=null;else if(this.match("\\\\")||this.match("\\cr"))this.skipSpace(),this.matchOptionalLatexArgument(),null!==n&&t.push(n),i.push(t),t=[],n=null;else{const i=[];let t=this.peek;for(;"&"!==t&&"\\\\"!==t&&"\\cr"!==t&&!this.atBoundary;)n=this.matchExpression({condition:e=>{const i=e.peek;return"&"===i||"\\\\"===i||"\\cr"===i}}),n?i.push(n):(i.push(["Error",["'unexpected-token'",t]]),this.next()),this.skipSpace(),t=this.peek;n=i.length>1?["Sequence",...i]:null!==(e=i[0])&&void 0!==e?e:"Nothing"}return null!==n&&t.push(n),t.length>0&&i.push(t),i}matchEnvironment(){const e=this.index;if(!this.match("\\begin"))return null;const i=this.matchStringArgument();if(null===i)return this.error("expected-environment-name",e);this.addBoundary(["\\end","<{>",...i.split(""),"<}>"]);const t=this._dictionary.environment.get(i);if(!t)return this.matchTabular(),this.skipSpace(),this.matchBoundary()?this.error(["unknown-environment",{str:i}],e):this.boundaryError("unbalanced-environment");const n=t.parse(this,[],[]);return this.skipSpace(),this.matchBoundary()?null!==n?this.decorate(n,e):(this.index=e,null):this.boundaryError("unbalanced-environment")}applyInvisibleOperator(e,i){var t;if(null===i||"Error"===hi(i)||"Nothing"===vi(i)||ki(i)||this.atTerminator(e)||null===this.options.applyInvisibleOperator)return null;if(null!==this.peekDefinitions("operator"))return null;const n=this.index,r=this.matchExpression(Object.assign(Object.assign({},e),{minPrec:390}));if(null===r||"Nothing"===vi(r)||ki(r))return this.index=n,null;if("Error"===hi(r))return wi("Sequence",i,r);if("function"==typeof this.options.applyInvisibleOperator)return this.options.applyInvisibleOperator(this,i,r);const a=vi(i);if(a&&"function"===this.options.parseUnknownSymbol(a,this)){const e=Ei(r);return e?[i,...e]:a}const s=xi(i);if(null!==s&&Number.isInteger(s)){const e=hi(r);if("Divide"===e||"Rational"===e){const[e,t]=[xi(di(r,1)),xi(di(r,2))];if(null!==e&&null!==t&&e>0&&e<=1e3&&t>1&&t<=1e3&&Number.isInteger(e)&&Number.isInteger(t))return["Add",i,r]}}if("Delimiter"===hi(r)){if("Sequence"===hi(di(r,1)))return[null!=a?a:i,...null!==(t=fi(di(r,1)))&&void 0!==t?t:[]];if(!di(r,1)||"Nothing"===vi(di(r,1)))return wi("Sequence",i,this.error("expected-expression",n))}return"Sequence"===hi(r)||"Sequence"===hi(i)||null!==ci(i)||null!==ci(r)||null!==yi(i)||null!==yi(r)?wi("Sequence",i,r):wi("Multiply",i,r)}matchUnexpectedLatexCommand(){var e,i;const t=this.index;let n=this.peekDefinitions("operator");if(n){if(n=this.peekDefinitions("postfix"),n){const[e,i]=n[0];if(this.index+=i,"function"==typeof e.parse){const i=e.parse(this,this.error("missing",t));if(i)return i}return e.name?[e.name,this.error("missing",t)]:this.error("unexpected-operator",t)}if(n=this.peekDefinitions("prefix"),n){const[i,r]=n[0];if(this.index+=r,"function"==typeof i.parse){const e=i.parse(this,{minPrec:0});if(e)return e}return i.name?[i.name,null!==(e=this.matchExpression())&&void 0!==e?e:this.error("missing",t)]:this.error("unexpected-operator",t)}if(n=this.peekDefinitions("infix"),n){const[e,r]=n[0];if(this.index+=r,"function"==typeof e.parse){const i=e.parse(this,{minPrec:0},this.error("missing",t));if(i)return i}return e.name?[e.name,this.error("missing",t),null!==(i=this.matchExpression())&&void 0!==i?i:this.error("missing",t)]:this.error("unexpected-operator",t)}}const r=this.peek;if(!r||"\\"!==r[0])return null;if(this.next(),this.skipSpaceTokens(),"\\end"===r){const e=this.matchStringArgument();return null===e?this.error("expected-environment-name",t):this.error(["unbalanced-environment",{str:e}],t)}for(;this.match("[");){let e=0;for(;!this.atEnd&&0===e&&"]"!==this.peek;)"["===this.peek&&(e+=1),"]"===this.peek&&(e-=1),this.next();this.match("]")}for(;this.match("<{>");){let e=0;for(;!this.atEnd&&0===e&&"<}>"!==this.peek;)"<{>"===this.peek&&(e+=1),"<}>"===this.peek&&(e-=1),this.next();this.match("<}>")}return this.error(["unexpected-command",{str:r}],t)}matchPrimary(){var e;if(this.atBoundary)return null;let i=null;const t=this.index;if(this.match("<}>"))return this.error("unexpected-closing-delimiter",t);if(this.match("<{>")){if(this.addBoundary(["<}>"]),i=this.matchExpression(),null===i)return this.boundaryError("expected-expression");if(!this.matchBoundary())return this.decorate(["Sequence",i,this.boundaryError("expected-closing-delimiter")],t)}if(null===i){const e=this.matchNumber();e&&(i={num:e})}if(null===i&&(i=this.matchEnclosure()),null===i&&(i=this.matchEnvironment()),null===i&&this.matchAll(this._positiveInfinityTokens)&&(i={num:"+Infinity"}),null===i&&this.matchAll(this._negativeInfinityTokens)&&(i={num:"-Infinity"}),null===i&&this.matchAll(this._notANumberTokens)&&(i={num:"NaN"}),null===i&&(i=null!==(e=this.matchFunction())&&void 0!==e?e:this.matchSymbol()),null!==i){i=this.decorate(i,t);let e=null,n=this.index;do{if(e=this.matchPostfix(i),i=null!=e?e:i,this.index===n&&null!==e)break;n=this.index}while(null!==e)}return null===i&&(i=this.matchUnexpectedLatexCommand()),null!==i&&(i=this.matchSupsub(i)),this.decorate(i,t)}matchExpression(e){const i=this.index;if(this.skipSpace(),this.atBoundary)return this.index=i,null;e||(e={minPrec:0}),void 0===e.minPrec&&(e.minPrec=0);let t=this.matchPrefixOperator(Object.assign(Object.assign({},e),{minPrec:0}));if(null===t&&(t=this.matchPrimary(),"Sequence"===hi(t)&&0===pi(t)&&(t=null)),t){let i=!1;for(;!i&&!this.atTerminator(e);){this.skipSpace();let n=this.matchInfixOperator(t,e);null===n&&(n=this.applyInvisibleOperator(e,t)),null!==n?t=n:i=!0}}return this.decorate(t,i)}decorate(e,i){if(null===e)return null;if(!this.options.preserveLatex)return e;const t=this.latex(i,this.index);return Array.isArray(e)?e={latex:t,fn:e}:"number"==typeof e?e={latex:t,num:Number(e).toString()}:"string"==typeof e?e={latex:t,sym:e}:"object"==typeof e&&null!==e&&(e.latex=t),e}error(e,i){return"string"==typeof e?["Error",{str:e},["Latex",{str:this.latex(i,this.index)}]]:["Error",["ErrorCode",{str:e[0]},...e.slice(1)],["Latex",{str:this.latex(i,this.index)}]]}}function ht(e,i){const t=e.length,n=e;e=e.slice(0,-1);for(let t=0;t<e.length-16;t++){const n=e.substring(0,t);for(let r=0;r<17;r++){const a=e.substring(t,t+r+1),s=Math.floor((e.length-n.length)/a.length);if(s>1&&(n+a.repeat(s+1)).startsWith(e))return"0"===a?n.replace(/(\d{3})/g,"$1"+i.groupSeparator):n.replace(/(\d{3})/g,"$1"+i.groupSeparator)+i.beginRepeatingDigits+a+i.endRepeatingDigits}}const r=t>i.precision-1;return e=n,r&&(e=e.substring(0,i.precision-1)),i.groupSeparator&&(e=e.replace(/(\d{3})/g,"$1"+i.groupSeparator)).endsWith(i.groupSeparator)&&(e=e.slice(0,-i.groupSeparator.length)),r?e+i.truncationMarker:e}function mt(e,i){var t;return e?i.beginExponentMarker?i.beginExponentMarker+e+(null!==(t=i.endExponentMarker)&&void 0!==t?t:""):"10^{"+e+"}":""}class dt{constructor(e,i,t){this.level=-1,this.options=e,e.invisibleMultiply&&(/#1/.test(e.invisibleMultiply)&&/#2/.test(e.invisibleMultiply)||t([{severity:"warning",message:["expected-argument","invisibleMultiply"]}])),this.onError=t,this.dictionary=i}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i])}wrap(e,i){if(null===e)return"";if(void 0===i)return this.wrapString(this.serialize(e),this.options.groupStyle(e,this.level+1));if("number"==typeof e||si(e)||"string"==typeof e||oi(e))return this.serialize(e);const t=hi(e);if("string"==typeof t&&"Delimiter"!==t&&"Subscript"!==t){const n=this.dictionary.name.get(t);if(n&&("symbol"===n.kind||"prefix"===n.kind||"infix"===n.kind||"postfix"===n.kind)&&n.precedence<i)return this.wrapString(this.serialize(e),this.options.applyFunctionStyle(e,this.level))}return this.serialize(e)}wrapShort(e){if(null===e)return"";const i=this.serialize(e);return"Delimiter"===hi(e)&&1===pi(e)||"number"==typeof e||si(e)||/(^(.|\\[a-zA-Z*]+))$/.test(i)?i:this.wrapString(i,this.options.groupStyle(e,this.level+1))}wrapString(e,i,t){var n,r;if("none"===i)return e;const a=null!==(n=null==t?void 0:t[0])&&void 0!==n?n:"(",s=null!==(r=null==t?void 0:t[1])&&void 0!==r?r:")";return"."!==a&&"."!==s||"paren"!==i||(i="leftright"),"leftright"===i?`${"."===a?"":"\\left("+a}${e}${"."===s?"":"\\right("+s})`:"big"===i?`${"."===a?"":"\\Bigl("+a}${e}${"."===s?"":"\\Bigr("+s})`:a+e+s}wrapArguments(e){var i;return this.wrapString((null!==(i=fi(e))&&void 0!==i?i:[]).map((e=>this.serialize(e))).join(", "),this.options.applyFunctionStyle(e,this.level))}serializeSymbol(e,i){var t;return hi(e)?this.serializeFunction(e,i):"string"==typeof(null==i?void 0:i.serialize)?i.serialize:"function"==typeof(null==i?void 0:i.serialize)?i.serialize(this,e):null!==(t=pt(vi(e),"upright."))&&void 0!==t?t:""}serializeFunction(e,i){var t,n;const r=hi(e);if(!r)return this.serializeSymbol(e,i);const a=null!==(t=fi(e))&&void 0!==t?t:[];if(i)return"function"==typeof i.serialize?i.serialize(this,e):Ke([null!==(n=i.serialize)&&void 0!==n?n:r,this.wrapArguments(e)]);if("string"==typeof r&&r.length>0&&"\\"===r[0])return Ke([r,...a.map((e=>`{${this.serialize(e)}}`))]);if("string"==typeof r)return pt(r,"upright.")+this.wrapArguments(e);const s=this.options.applyFunctionStyle(e,this.level);return"\\mathrm{Apply}"+this.wrapString(this.serialize(r)+", "+this.serialize(["List",...a]),s)}serializeDictionary(e){return`\\left\\lbrack\\begin{array}{lll}${Object.keys(e).map((i=>`\\textbf{${i}} & \\rightarrow & ${this.serialize(e[i])}`)).join("\\\\")}\\end{array}\\right\\rbrack`}serialize(e){if(null==e)return"";this.level+=1;try{const i=(()=>{var i;const t=function(e,i){var t,n,r;if(null===e)return"";let a;if("number"==typeof e)a=e;else{if("object"!=typeof e||!("num"in e))return"";a=e.num}if(a===1/0||"Infinity"===a||"+Infinity"===a)return i.positiveInfinity;if(a===-1/0||"-Infinity"===a)return i.negativeInfinity;if("NaN"===a||"number"==typeof a&&Number.isNaN(a))return i.notANumber;if("number"==typeof a)return"engineering"===i.notation?function(e,i){if(0===e)return"0";const t=Math.abs(e);let n=Math.round(Math.log10(t));n-=n%3,t>Math.pow(10,i.avoidExponentsInRange[0])&&t<Math.pow(10,i.avoidExponentsInRange[1])&&(n=0);const r=t/Math.pow(10,n);let a="";const s=r.toString().match(/^(.*)\.(.*)$/);(null==s?void 0:s[1])&&s[2]&&(a=s[1]+i.decimalMarker+s[2]),i.groupSeparator&&(a=ht(r.toExponential(),i));let o="";return 0!==n&&(o=mt(n.toString(),i)),(e<0?"-":"")+a+o}(a,i):function(e,i){var t;let n,r=e.match(/^(.*)[e|E]([-+]?[0-9]+)$/i);(null==r?void 0:r[1])&&r[2]&&(n=mt(r[2],i));let a=null!==(t=null==r?void 0:r[1])&&void 0!==t?t:e,s="";return r=(n?r[1]:e).match(/^(.*)\.(.*)$/),(null==r?void 0:r[1])&&r[2]&&(a=r[1],s=r[2]),i.groupSeparator&&(a=a.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator),s=ht(s,i)),s&&(s=i.decimalMarker+s),n?"1"!==a||s?a+s+i.exponentProduct+n:n:a+s}(a.toString(),i);if(/[0-9][nd]$/.test(a)&&(a=a.slice(0,-1)),a=a.replace(/[\u0009-\u000d\u0020\u00a0]/g,""),/\([0-9]+\)$/.test(a)){const[e,n,r]=null!==(t=a.match(/(.+)\(([0-9]+)\)$/))&&void 0!==t?t:[];a=n+r.repeat(Math.ceil(i.precision/r.length))}let s="";for("-"===a[0]?(s="-",a=a.substring(1)):"+"===a[0]&&(a=a.substring(1));"0"===a[0];)a=a.substring(1);if(0===a.length)return s+"0";"."===a[0]&&(a="0"+a);let o="";if(a.indexOf(".")>=0){const e=a.match(/(\d*)\.(\d*)([e|E]([-+]?[0-9]*))?/);if(!e)return"";const t=e[1],r=e[2];if(o=null!==(n=e[4])&&void 0!==n?n:"","0"===t){let e=0;for(;"0"===r[e]&&e<r.length;)e+=1;let t="";if(e<=4)t="0"+i.decimalMarker,t+=r.substring(0,e),t+=ht(a.substring(t.length),i);else if(e+1>=i.precision)t="0",s="";else{t=a[e];const n=ht(a.substring(e+1),i);n&&(t+=i.decimalMarker+n)}"0"!==t&&(!(a.length-1>i.precision)||i.endRepeatingDigits&&t.endsWith(i.endRepeatingDigits)||!i.truncationMarker||t.endsWith(i.truncationMarker)||(t+=i.truncationMarker),e>4&&(t+=i.exponentProduct+mt(""+(1-e),i))),a=t}else{a=t.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator);const e=ht(r,i);e&&(a+=i.decimalMarker+e)}}else if(a.length>i.precision){const e=a.length;if(e>i.avoidExponentsInRange[1]){let t=a[0];const n=ht(a.substring(1),i);n&&(t+=i.decimalMarker+n,i.truncationMarker&&!t.endsWith(i.truncationMarker)&&i.endRepeatingDigits&&!t.endsWith(i.endRepeatingDigits)&&(t+=i.truncationMarker)),"1"!==t?t+=i.exponentProduct:t="",a=t+mt(""+(e-1),i)}}else{const e=a.match(/([0-9]*)\.?([0-9]*)([e|E]([-+]?[0-9]+))?/);e&&(a=e[1],e[2]&&(a+=i.decimalMarker+e[2]),o=null!==(r=e[4])&&void 0!==r?r:""),a=a.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator)}const l=mt(o,i);return"1"===a&&l?s+l:(l&&(a=a+i.exponentProduct+l),s+a)}(e,this.options);if(t)return t;const n=ci(e);if(null!==n)return`\\text{${n}}`;const r=vi(e);if(null!==r){const i=this.dictionary.name.get(r);if("symbol"===(null==i?void 0:i.kind))return this.serializeSymbol(e,i);if("function"===(null==i?void 0:i.kind))return this.serializeFunction(e,i)}const a=yi(e);if(null!==a)return this.serializeDictionary(a);const s=mi(e);if(s){if("\\"===s[0]){const t=null!==(i=fi(e))&&void 0!==i?i:[];return 0===t.length?s:s+"{"+t.map((e=>this.serialize(e))).filter((e=>!!e)).join("}{")+"}"}const t=this.dictionary.name.get(s);if(t)return"function"==typeof t.serialize?t.serialize(this,e):"infix"===t.kind||"postfix"===t.kind||"prefix"===t.kind?function(e,i,t){let n="";const r=pi(i),a=mi(i);if("postfix"===t.kind)return 1!==r&&e.onError([{severity:"warning",message:["postfix-operator-requires-one-operand",e.serializeSymbol(a)]}]),ft(t.serialize,[e.wrap(di(i,1),t.precedence)]);if("prefix"===t.kind)return 1!==r&&e.onError([{severity:"warning",message:["prefix-operator-requires-one-operand",e.serializeSymbol(a)]}]),ft(t.serialize,[e.wrap(di(i,1),t.precedence+1)]);if("infix"===t.kind){n=e.wrap(di(i,1),t.precedence);for(let a=2;a<r+1;a++){const r=di(i,a);null!==r&&(n=ft(t.serialize,[n,e.wrap(r,t.precedence)]))}}return n}(this,e,t):"symbol"===t.kind?this.serializeSymbol(e,t):"function"===t.kind?this.serializeFunction(e,t):""}if(Array.isArray(e)||li(e)||null!==vi(e))return this.serializeSymbol(e);this.onError([{severity:"warning",message:["syntax-error",e?JSON.stringify(e):"undefined"]}])})();return this.level-=1,null!=i?i:""}catch(e){}return this.level-=1,""}applyFunctionStyle(e,i){return this.options.applyFunctionStyle(e,i)}groupStyle(e,i){return this.options.groupStyle(e,i)}rootStyle(e,i){return this.options.rootStyle(e,i)}fractionStyle(e,i){return this.options.fractionStyle(e,i)}logicStyle(e,i){return this.options.logicStyle(e,i)}powerStyle(e,i){return this.options.powerStyle(e,i)}numericSetStyle(e,i){return this.options.numericSetStyle(e,i)}}function ft(e,i){var t;let n=e;for(let e=0;e<i.length;e++){let r=null!==(t=i[e])&&void 0!==t?t:"";if(/[a-zA-Z*]/.test(r[0])){const i=n.match(RegExp("(.*)#"+Number(e+1).toString()));i&&/\\[a-zA-Z*]+/.test(i[1])&&(r=" "+r)}n=n.replace("#"+Number(e+1).toString(),r)}return n}const gt=["alpha","beta","gamma","Gamma","delta","Delta","epsilon","zeta","eta","theta","Theta","iota","kappa","lambda","Lambda","mu","nu","xi","Xi","pi","Pi","rho","sigma","Sigma","tau","upsilon","phi","Phi","varphi","chi","psi","Psi","omega","Omega","aleph","ast","blacksquare","bot","bullet","circ","diamond","times","top","square","star"];function pt(e,i="italic."){var t;if(null===e)return null;const n=e.match(/^(_+)(.*)/);if(n)return`\\text{${"\\_".repeat(n[1].length)+vt(n[2])}}`;let r;[r,e]=function(e){const i=e.match(/^([a-zA-Z-]+\.)(.*)/);return i?[i[1],i[2]]:["",e]}(e);const a=vt(e);return 1!==a.length||r?(r||(r=i),(null!==(t={"upright.":"\\mathrm{_}","italic.":"\\mathit{_}","bold-italic.":"\\mathbf{\\mathit{_}}","script.":"\\mathscr{_}","calligraphic.":"\\mathcal{_}","bold-script.":"\\mathbf{\\mathscr{_}}","bold-calligraphic.":"\\mathbf{\\mathcal{_}}","fraktur.":"\\mathfrak{_}","gothic.":"\\mathfrak{_}","bold-gothic.":"\\mathbf{\\mathfrak{_}}","bold-fraktur.":"\\mathbf{\\mathfrak{_}}","sans-serif.":"\\mathsf{_}","bold-sans-serif.":"\\mathbf{\\mathsf{_}}","italic-sans-serif.":"\\mathit{\\mathsf{_}}","monospace.":"\\mathtt{_}","blackboard.":"\\mathbb{_}","double-struck.":"\\mathbb{_}"}[r])&&void 0!==t?t:"\\mathit{_}").replace("_",a)):a}function vt(e){const i=e.indexOf("_");if(i>0){const t=e.substring(0,i),n=e.substring(i+1);return n?n.startsWith('"')&&n.endsWith('"')?`${vt(t)}_\\mathrm{${vt(n.substring(1,-1))}}`:`${vt(t)}_{${vt(n)}}`:pt(t)+"\\_"}const t=e.match(/([^0-9]+?)([0-9]+)$/);return t?0===t[1].length?e:`${vt(t[1])}_{${t[2]}}`:gt.includes(e)?"\\"+e:e=e.replace(/[{}\[\]\\:\-\$%]/g,(e=>{var i;return null!==(i={"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash ","-":'\\unicode{"2013}'}[e])&&void 0!==i?i:"\\"+e}))}const bt={invisibleMultiply:"",invisiblePlus:"",multiply:"\\times",missingSymbol:"\\blacksquare",applyFunctionStyle:function(e,i){return"paren"},groupStyle:function(e,i){return"paren"},rootStyle:Ai,fractionStyle:Mi,logicStyle:function(e,i){return"boolean"},powerStyle:function(e,i){return"solidus"},numericSetStyle:function(e,i){return"compact"}};class yt{constructor(e){var i,t;this.onError=null!==(i=e.onError)&&void 0!==i?i:e=>{if("undefined"!=typeof window)for(const i of e);},this.computeEngine=e.computeEngine;const n=Object.assign({},e);delete n.dictionary,delete n.onError,this.options=Object.assign(Object.assign(Object.assign(Object.assign({},lt),ut),bt),n),this.dictionary=function(e,i){var t,n;const r={lookahead:1,name:new Map,function:new Map,symbol:[],infix:[],prefix:[],postfix:[],environment:new Map,matchfix:[]};for(const a of e){const[e,s]=it(a,i);if(null!==s)if(void 0!==s.name&&(r.name.has(s.name)&&i({severity:"warning",message:["invalid-dictionary-entry",s.name,"Duplicate definition"]}),r.name.set(s.name,s)),"matchfix"===s.kind)r.matchfix.push(s);else if("environment"===s.kind){const e=Je(null!==(t=a.trigger)&&void 0!==t?t:"");r.environment.has(e)&&i({severity:"warning",message:["invalid-dictionary-entry",e,"Duplicate environment definition"]}),r.environment.set(e,s)}else if(e){const i=Je(null!==(n=a.trigger)&&void 0!==n?n:""),t=et(e);if(r.lookahead=Math.max(r.lookahead,t),"function"===s.kind)r.function.has(i)?r.function.set(i,[...r.function.get(i),s]):r.function.set(i,[s]);else if("symbol"===s.kind){void 0===r.symbol[t]&&(r.symbol[t]=new Map);const e=r.symbol[t];e.has(i)?e.get(i).push(s):e.set(i,[s])}else if("prefix"===s.kind){void 0===r.prefix[t]&&(r.prefix[t]=new Map);const e=r.prefix[t];e.has(i)?e.get(i).push(s):e.set(i,[s])}else if("infix"===s.kind){void 0===r.infix[t]&&(r.infix[t]=new Map);const e=r.infix[t];e.has(i)?e.get(i).push(s):e.set(i,[s])}else if("postfix"===s.kind){void 0===r.postfix[t]&&(r.postfix[t]=new Map);const e=r.postfix[t];e.has(i)?e.get(i).push(s):e.set(i,[s])}}}return r}(null!==(t=e.dictionary)&&void 0!==t?t:yt.getDictionary(),(e=>this.onError([e])))}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i]);this.serializer.updateOptions(e)}static getDictionary(e="all"){if("all"===e){const e=[];for(const i of Object.keys(tt))tt[i]&&e.push(...tt[i]);return e}return tt[e]?[...tt[e]]:[]}parse(e){const i=new ct(Ye(e,[]),this.options,this.dictionary,this.computeEngine);let t=i.matchExpression();if(!i.atEnd){const e=i.peekDefinitions("infix");if(e){const n=i.index,[r,a]=e[0];i.index+=a;const s=r.parse(i,{minPrec:0},null!=t?t:i.error("missing",n));if(s)return s;if(r.name)return[r.name,null!=t?t:i.error("missing",n),i.error("missing",n)];i.index=n}const n=i.index,r=i.next();for(;!i.atEnd;)i.next();const a=i.error([r.length>1&&r.startsWith("\\")?"unexpected-command":"unexpected-token",{str:Je([r])}],n);t=t?["Sequence",t,a]:a}return null!=t||(t=["Sequence"]),this.options.preserveLatex&&(Array.isArray(t)?t={latex:e,fn:t}:"number"==typeof t?t={latex:e,num:Number(t).toString()}:"string"==typeof t?t={latex:e,sym:t}:"object"==typeof t&&null!==t&&(t.latex=e)),null!=t?t:["Sequence"]}serialize(e){return this.serializer.serialize(e)}get serializer(){return this._serializer||(this._serializer=new dt(this.options,this.dictionary,this.onError)),this._serializer}}const xt=["Error","Dictionary","Function","List","Tuple","Intersection","Union","Maybe","Sequence","Interval","Range","Head","Symbol","Value"],Nt={NumericFunction:["Function",["Sequence","Number"],"Number"],RealFunction:["Function",["Sequence","ExtendedRealNumber"],"ExtendedRealNumber"],TrigonometricFunction:["Function","Number","Number"],LogicOperator:["Function","MaybeBoolean",["Maybe","MaybeBoolean"],"MaybeBoolean"],Predicate:["Function",["Sequence","Anything"],"MaybeBoolean"],RelationalOperator:["Function","Anything","Anything","MaybeBoolean"]},_t={Anything:[],Value:"Anything",Domain:"Anything",DomainExpression:"Domain",Void:"Nothing",Nothing:["DomainExpression","Boolean","String","Symbol","Tuple","List","Dictionary","InfiniteSet","FiniteSet","ImaginaryNumber","TranscendentalNumber","PositiveInteger","NegativeInteger","NonPositiveInteger","NonNegativeInteger","PositiveNumber","NegativeNumber","NonPositiveNumber","NonNegativeNumber","Scalar","TrigonometricFunction","LogicOperator","RelationalOperator"],MaybeBoolean:"Value",Boolean:"MaybeBoolean",String:"Boolean",Symbol:"Boolean",Collection:"Value",List:"Collection",Dictionary:"Collection",Sequence:"Collection",Tuple:"Sequence",Set:"Collection",InfiniteSet:"Set",FiniteSet:"Set",Function:"Anything",Predicate:"Function",LogicOperator:"Predicate",RelationalOperator:"Predicate",NumericFunction:"Function",RealFunction:"NumericFunction",TrigonometricFunction:"RealFunction",Number:"Value",ExtendedComplexNumber:"Number",ComplexNumber:"ExtendedComplexNumber",ImaginaryNumber:"ComplexNumber",ExtendedRealNumber:"ExtendedComplexNumber",RealNumber:["ComplexNumber","ExtendedRealNumber"],PositiveNumber:"NonNegativeNumber",NonNegativeNumber:"RealNumber",NonPositiveNumber:"NegativeNumber",NegativeNumber:"RealNumber",TranscendentalNumber:"RealNumber",AlgebraicNumber:"RealNumber",RationalNumber:"AlgebraicNumber",Integer:"RationalNumber",PositiveInteger:"NonNegativeInteger",NonNegativeInteger:"Integer",NonPositiveInteger:"NegativeInteger",NegativeInteger:"Integer",Tensor:"Value",Matrix:"Tensor",Scalar:["Row","Column"],Row:"Vector",Column:"Vector",Vector:"Matrix"};let St;function wt(e){return!!e&&void 0!==_t[e]}function Et(e){if(St||(St={},Et("Void")),St[e])return Array.from(St[e]);let i=[];if("string"!=typeof e||!_t[e]){if(!Array.isArray(e))throw Error("Unknown domain literal "+e);if(!xt.includes(e[0]))throw Error("Unknown domain constructor "+e[0]);return"Function"===e[0]||"Head"===e[0]?Et("Function"):"Symbol"===e[0]?Et("Symbol"):"Tuple"===e[0]?Et("Tuple"):"List"===e[0]?Et("List"):"Dictionary"===e[0]?Et("Dictionary"):"Range"===e[0]?Et("Integer"):"Interval"===e[0]?Et("RealNumberExtended"):"Maybe"===e[0]||"Sequence"===e[0]?Et(e[1]):("Literal"===e[0]||"Union"===e[0]||e[0],["Anything"])}if("string"==typeof _t[e])i=[_t[e],...Et(_t[e])];else if(Array.isArray(_t[e]))for(const t of _t[e])i.push(t),i.push(...Et(t));return St[e]=new Set(i),i}const kt=Math.log10(Math.pow(2,53)),It=1e-10,At=1e6,Mt=1e6,Ft=new Set([2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001,4003,4007,4013,4019,4021,4027,4049,4051,4057,4073,4079,4091,4093,4099,4111,4127,4129,4133,4139,4153,4157,4159,4177,4201,4211,4217,4219,4229,4231,4241,4243,4253,4259,4261,4271,4273,4283,4289,4297,4327,4337,4339,4349,4357,4363,4373,4391,4397,4409,4421,4423,4441,4447,4451,4457,4463,4481,4483,4493,4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,5011,5021,5023,5039,5051,5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,5153,5167,5171,5179,5189,5197,5209,5227,5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919]);function Ot(e,i){const t=function(e){if(e<=3)return{[e]:1};const i={};let t=!1;for(;!t;){if(e%2==0){i[2]?i[2]+=1:i[2]=1,e/=2;continue}if(e%3==0){i[3]?i[3]+=1:i[3]=1,e/=3;continue}if(1===e)return i;const n=Math.sqrt(e);t=!0;for(let r=6;r<=n+6;r+=6){if(e%(r-1)==0){i[r-1]?i[r-1]+=1:i[r-1]=1,e/=r-1,t=!1;break}if(e%(r+1)==0){i[r+1]?i[r+1]+=1:i[r+1]=1,e/=r+1,t=!1;break}}}return i[e]=1,i}(e);let n=1,r=1;for(const e of Object.keys(t)){const a=parseFloat(e);n*=Math.pow(a,Math.floor(t[e]/i)),r*=Math.pow(a,t[e]%i)}return[n,r]}function Vt(e,i){if(0===e)return i;if(0===i)return e;if(e===i)return e;if(!Number.isInteger(e)||!Number.isInteger(i))return NaN;for(;0!==i;)[e,i]=[i,e%i];return e<0?-e:e}function Tt([e,i]){if(1===e||1===i)return[e,i];i<0&&([e,i]=[-e,-i]);const t=Vt(e,i);return t<=1?[e,i]:[e/t,i/t]}const qt=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],Ct=[.999999999999997,57.15623566586292,-59.59796035547549,14.13609797474174,-.4919138160976202,3399464998481188e-20,4652362892704857e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.0002174396181152126,-.0001643181065367639,8441822398385274e-20,-261908384015814e-19,3689918265953162e-21];function Dt(e){if(e<0)return NaN;let i=Ct[0];for(let t=14;t>0;--t)i+=Ct[t]/(e+t);const t=e+4.7421875+.5;return.9189385332046727+(e+.5)*Math.log(t)-t+Math.log(i)-Math.log(e)}function Pt(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*Pt(1-e));if(e>100)return Math.exp(Dt(e));e-=1;let i=qt[0];for(let t=1;t<9;t++)i+=qt[t]/(e+t);const t=e+7+.5;return 2.5066282746310002*Math.pow(t,e+.5)*Math.exp(-t)*i}function Lt(e,i=10){let t=0;for(let n=0;n<e.length;n++){const r={" ":-1,"\xa0":-1,"\u2000":-1,"\u2001":-1,"\u2002":-1,"\u2003":-1,"\u2004":-1,"\u2005":-1,"\u2006":-1,"\u2007":-1,"\u2008":-1,"\u2009":-1,"\u200a":-1,"\u200b":-1,"\u202f":-1,"\u205f":-1,_:-1,",":-1,0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,g:16,h:17,i:18,j:19,k:20,l:21,m:22,n:23,o:24,p:25,q:26,r:27,s:28,t:29,u:30,v:31,w:32,x:33,y:34,z:35}[e[n]];if(-1!==r){if(void 0===r)return[t,e.substring(n)];if(r>=i)return[t,e.substring(n)];t=t*i+r}}return[t,""]}function Rt(e){return"string"==typeof e&&e.startsWith("$")&&e.endsWith("$")}function zt(e){return"string"==typeof e&&e.startsWith("$")&&e.endsWith("$")?e.slice(1,-1):null}function $t(e){if("ImaginaryUnit"===e.symbol)return 1;if(e.isLiteral){const i=e.complexValue;if(i&&0===i.re)return i.im}if("Negate"===e.head){const i=$t(e.op1);return null===i?null:-i}let i=0;if("Multiply"===e.head&&2===e.nops){let t;"ImaginaryUnit"===e.op1.symbol?t=e.op2:"ImaginaryUnit"===e.op2.symbol&&(t=e.op1),t&&t.isLiteral&&(i=t.asFloat)}return i}function jt(e){if(e.symbol){const i=e.symbolDefinition;return(null==i?void 0:i.constant)?[]:[e.symbol]}if(!e.ops&&!e.keys)return[];const i=[];if(e.ops)for(const t of e.ops)i.push(...jt(t));if(e.keys)for(const t of e.keys)i.push(...jt(e.getKey(t)));return i}function Zt(e,i){if(e.symbol)return i.add(e.symbol),i;if(!e.ops&&!e.keys)return i;if(e.ops)for(const t of e.ops)Zt(t,i);if(e.keys)for(const t of e.keys)Zt(e.getKey(t),i);return i}function Bt(e,i){if(e.ops){const t=i&&e.head!==i?[]:[e];for(const n of e.ops)t.push(...Bt(n,i))}else if(e.keys){const t=i&&e.head!==i?[]:[e];for(const n of e.keys)t.push(...Bt(e.getKey(n),i));return t}return i&&e.head!==i?[]:[e]}function Gt(e){return"decimal"===e.numericMode||"auto"===e.numericMode&&e.precision>Math.floor(kt)}function Ht(e){return"auto"===e.numericMode||"complex"===e.numericMode}function Wt(e){let i=0;for(let t=0;t<e.length;t++)i=Math.imul(31,i)+e.charCodeAt(t)|0;return Math.abs(i)}function Ut(e,i){var t;if(null==i)return null;if("number"==typeof i)return e.decimal(i);if(si(i)){let n=i.num.toLowerCase().replace(/[nd]$/g,"").replace(/[\u0009-\u000d\u0020\u00a0]/g,"");if(/\([0-9]+\)$/.test(n)){const[i,r,a]=null!==(t=n.match(/(.+)\(([0-9]+)\)$/))&&void 0!==t?t:[];n=r+a.repeat(Math.ceil(e.precision/a.length))}return"nan"===n?e.decimal("NaN"):"infinity"===n||"+infinity"===n?e.decimal("+Infinity"):"-infinity"===n?e.decimal("-Infinity"):e.decimal(n)}return null}class Qt{constructor(e,i){this.engine=e,void 0!==(null==i?void 0:i.latex)&&(this._latex=i.latex),void 0!==(null==i?void 0:i.wikidata)&&(this._wikidata=i.wikidata)}valueOf(){var e,i,t;return"True"===this.symbol||"False"!==this.symbol&&(null!==(t=null!==(i=null!==(e=this.asFloat)&&void 0!==e?e:this.string)&&void 0!==i?i:this.symbol)&&void 0!==t?t:JSON.stringify(this.json))}toString(){return this.valueOf()+""}[Symbol.toPrimitive](e){if("string"===e)return this.toString();if("number"===e){const e=this.valueOf();return"number"==typeof e?e:null}return this.toString()}toJSON(){return this.json}is(e){return null!=e&&this.isSame(this.engine.box(e))}get latex(){var e;return null!==(e=this._latex)&&void 0!==e?e:this.engine.serialize(this)}set latex(e){this._latex=e}get symbol(){return null}get isNothing(){return!1}get string(){return null}getSubexpressions(e){return Bt(this,e)}get subexpressions(){return this.getSubexpressions("")}get symbols(){return[...Zt(this,new Set)].map((e=>this.engine.symbol(e)))}get errors(){return this.getSubexpressions("Error")}get ops(){return null}get nops(){return 0}get op1(){return this.engine.symbol("Nothing")}get op2(){return this.engine.symbol("Nothing")}get op3(){return this.engine.symbol("Nothing")}get isValid(){return!0}get isPure(){return!1}get isFree(){return!1}get isConstant(){return!1}get canonical(){return this}apply(e,i){return this}subs(e){return this}solve(e){return null}replace(e){return null}has(e){return!1}get isNaN(){}get isZero(){}get isNotZero(){}get isOne(){}get isNegativeOne(){}get isInfinity(){}get isFinite(){}get isEven(){}get isOdd(){}get isPrime(){}get isComposite(){}get machineValue(){return null}get rationalValue(){return[null,null]}get decimalValue(){return null}get complexValue(){return null}get asFloat(){return null}get asSmallInteger(){return null}get asRational(){return[null,null]}get sgn(){return null}isLess(e){}isLessEqual(e){}isGreater(e){}isGreaterEqual(e){}get isPositive(){}get isNonNegative(){}get isNegative(){}get isNonPositive(){}isCompatible(e,i){return!1}get description(){}get url(){}get isLiteral(){return!1}get wikidata(){return this._wikidata}set wikidata(e){this._wikidata=e}get complexity(){}get basedDefinition(){}get symbolDefinition(){}get functionDefinition(){}bind(e){}unbind(){}get keys(){return null}get keysCount(){return 0}getKey(e){}hasKey(e){return!1}get value(){}set value(e){throw Error(`Can't change the value of \\(${this.latex}\\)`)}get numericValue(){}isSubdomainOf(e){}get domain(){return this.engine.domain("Void")}set domain(e){throw Error(`Can't change the domain of \\(${this.latex}\\)`)}get explicitDomain(){return this.domain}get isNumber(){}get isInteger(){}get isRational(){}get isAlgebraic(){return!1}get isReal(){}get isExtendedReal(){}get isComplex(){}get isImaginary(){}get isExtendedComplex(){}simplify(e){return this}evaluate(e){return this.simplify(e)}N(e){return this.evaluate()}}function Yt([e,i]){if(e.equals(1)||i.equals(1))return[e,i];i.lessThan(0)&&([e,i]=[e.neg(),i.neg()]);const t=function(e,i){for(;!i.isZero();)[e,i]=[i,e.modulo(i)];return e.abs()}(e,i);return t.lessThanOrEqualTo(1)?[e,i]:[e.div(t),i.div(t)]}function Kt(e,i){if(!i.isInteger()||i.isNegative())return e._DECIMAL_NAN;if(i.lessThan(10))return e.decimal([1,1,2,6,24,120,720,5040,40320,362880,3628800][i.toNumber()]);if(i.gt(Number.MAX_SAFE_INTEGER)){let t=e._DECIMAL_ONE,n=e._DECIMAL_TWO;for(;n.lessThan(i);)t=t.mul(n),n=n.add(1);return t}if(i.modulo(2).eq(1))return i.times(Kt(e,i.minus(1)));let t=i.toNumber(),n=i,r=i;for(;t>2;)t-=2,n=n.add(t),r=r.mul(n);return r}function Jt(e,i){if(i.isNegative())return e._DECIMAL_NAN;const t=e.cache("gamma-p-ln",(()=>["0.99999999999999709182","57.156235665862923517","-59.597960355475491248","14.136097974741747174","-0.49191381609762019978","0.33994649984811888699e-4","0.46523628927048575665e-4","-0.98374475304879564677e-4","0.15808870322491248884e-3","-0.21026444172410488319e-3","0.2174396181152126432e-3","-0.16431810653676389022e-3","0.84418223983852743293e-4","-0.2619083840158140867e-4","0.36899182659531622704e-5"].map((i=>e.decimal(i)))));let n=t[0];for(let e=t.length-1;e>0;--e)n=n.add(t[e].div(i.add(e)));const r=e.cache("gamma-g-ln",(()=>e.decimal(607).div(128))),a=i.add(r).add(e._DECIMAL_HALF);return e._DECIMAL_NEGATIVE_ONE.acos().mul(e._DECIMAL_TWO).log().mul(e._DECIMAL_HALF).add(a.log().mul(i.add(e._DECIMAL_HALF)).minus(a).add(n.log()).minus(i.log()))}function Xt(e,i){if(i.lessThan(e._DECIMAL_HALF)){const t=e._DECIMAL_NEGATIVE_ONE.acos();return t.div(t.mul(i).sin().mul(Xt(e,e._DECIMAL_ONE.sub(i))))}if(i.greaterThan(100))return Jt(e,i).exp();i=i.sub(1);const t=e.cache("lanczos-7-c",(()=>["0.99999999999980993227684700473478","676.520368121885098567009190444019","-1259.13921672240287047156078755283","771.3234287776530788486528258894","-176.61502916214059906584551354","12.507343278686904814458936853","-0.13857109526572011689554707","9.984369578019570859563e-6","1.50563273514931155834e-7"].map(e.decimal)));let n=t[0];for(let e=1;e<9;e++)n=n.add(t[e].div(i.add(e)));const r=i.add(7).add(e._DECIMAL_HALF);return e._DECIMAL_NEGATIVE_ONE.acos().times(e._DECIMAL_TWO).sqrt().mul(n.mul(r.neg().exp()).mul(r.pow(i.add(e._DECIMAL_HALF))))}function en(e){return!(e.d.length>3||3===e.d.length&&e.d[0]>=90)&&e.e<308&&e.e>-306}function tn(e,i){var t;const n=[];for(const r of e)r.ops&&r.head===i?n.push(...null!==(t=tn(r.ops,i))&&void 0!==t?t:r.ops):n.push(r);return n.length===e.length?null:n}function nn(e){if("Power"===e.head&&e.op2.isLiteral){const i=e.op2.asSmallInteger;return null!==i&&i>0?i:1}if("Multiply"===e.head){let i=1;for(const t of e.ops){const e=nn(t);e>1&&(i+=e)}return i}return 1}function rn(e){if("Power"===e.head&&e.op2.isLiteral){const i=e.op2.asSmallInteger;return null!==i&&i>0?i:1}if("Multiply"===e.head){let i=1;for(const t of e.ops)i=Math.max(i,nn(t));return i}return 1}function an(e){return e.symbol?e.symbol:e.ops?e.ops.map((e=>an(e))).filter((e=>e.length>0)).join('"'):""}const sn=1e5;function on(e,i){var t,n,r,a,s,o,l,u;if(e.isLiteral&&null!==e.asFloat)return i.isLiteral&&null!==i.asFloat?e.asFloat-i.asFloat:-1;if(e.isLiteral&&e.complexValue)return i.isLiteral&&i.complexValue?e.complexValue.re===i.complexValue.re?Math.abs(e.complexValue.im)===Math.abs(i.complexValue.im)?e.complexValue.im-i.complexValue.im:Math.abs(e.complexValue.im)-Math.abs(i.complexValue.im):e.complexValue.re-i.complexValue.re:i.isLiteral&&i.isNumber?1:-1;if(e.symbol)return i.symbol?e.symbol===i.symbol?0:e.symbol>i.symbol?1:-1:i.isLiteral&&i.isNumber?1:-1;if(e.ops){if(i.ops){const s=null!==(n=null===(t=e.functionDefinition)||void 0===t?void 0:t.complexity)&&void 0!==n?n:sn,o=null!==(a=null===(r=i.functionDefinition)||void 0===r?void 0:r.complexity)&&void 0!==a?a:sn;return s===o?"string"==typeof e.head&&"string"==typeof i.head?e.head===i.head?ln(e)-ln(i):e.head<i.head?1:-1:ln(e)-ln(i):s-o}return i.isLiteral&&i.isNumber||i.symbol?1:-1}if(e.string)return i.string?e.string.length!==i.string.length?i.string.length-e.string.length:i.string<e.string?-1:e.string>i.string?1:0:i.keys?-1:1;if(e.keys&&i.keys){if(e.keysCount!==i.keysCount)return i.keysCount-e.keysCount;let t=0,n=0;for(const e of i.keys)t+=null!==(s=i.getKey(e).complexity)&&void 0!==s?s:sn;for(const i of e.keys)n+=null!==(o=e.getKey(i).complexity)&&void 0!==o?o:sn;return n-t}return(null!==(l=e.complexity)&&void 0!==l?l:sn)-(null!==(u=i.complexity)&&void 0!==u?u:sn)}function ln(e){return null!==e.keys?1+e.keysCount:e.ops?("string"==typeof e.head?1:ln(e.head))+[...e.ops].reduce(((e,i)=>e+ln(i)),0):1}function un(e){var i;const t=e.engine;let n=1,r=1;if("Multiply"===e.head){const i=[];for(const t of e.ops)if(t.isLiteral){const[e,a]=t.asRational;null!==e&&null!==a?(n*=e,r*=a):i.push(t)}else i.push(t);return[n,r]=Tt([n,r]),n===r?[[1,1],e]:0===i.length?[[n,r],t._ONE]:1===i.length?[[n,r],i[0]]:[[n,r],t.mul(i)]}if("Divide"===e.head){let[[i,n],r]=un(e.op1);const[[a,s],o]=un(e.op2),[l,u]=Tt([i*s,a*n]);return r.isOne&&o.isOne?[[l,u],t._ONE]:o.isOne?[[l,u],r]:[[l,u],t.fn("Divide",[r,o]).canonical]}if("Power"===e.head){if(!e.op2.isLiteral)return[[1,1],e];let[[i,n],r]=un(e.op1);if(1===i&&1===n)return[[1,1],e];const a=e.op2,s=a.asSmallInteger;if(null!==s){if(-1===s)return[[n,i],t.inverse(r)];if(Math.log10(Math.abs(i))*Math.abs(s)<15&&Math.log10(Math.abs(n))*Math.abs(s)<15)return s>0?[[Math.pow(i,s),Math.pow(n,s)],t.power(r,a)]:[[Math.pow(n,-s),Math.pow(i,-s)],t.power(r,a)]}const[o,l]=a.rationalValue;if(null!==o&&null!==l&&i>0&&1===Math.abs(o)){const[s,u]=Ot(i,l),[c,h]=Ot(n,l);return 1===s&&1===c?[[1,1],e]:[1===o?[s,c]:[c,s],t.power(t.mul([t.number([u,h]),r]),a)]}return[[1,1],e]}if("Negate"===e.head){const[i,t]=un(e.op1);return[[-i[0],i[1]],t]}if(e.isLiteral){if(e.decimalValue){if(e.decimalValue.isInteger()&&en(e.decimalValue))return[[e.decimalValue.toNumber(),1],t._ONE];if(null===(i=e.decimalValue)||void 0===i?void 0:i.isNegative())return[[-1,1],t.number(e.decimalValue.neg())]}if(null!==e.machineValue){if(Number.isInteger(e.machineValue))return[[e.machineValue,1],t._ONE];if(e.machineValue<0)return[[-1,1],t.number(-e.machineValue)]}const[n,r]=e.rationalValue;if(null!==n&&null!==r)return[[n,r],t._ONE];if(null!==e.complexValue){const i=e.complexValue;if(i.re<0)return[[-1,1],t.number(t.complex(-i.re,-i.im))]}}return[[1,1],e]}function cn(e){var i;if("Negate"===e.head)return[-1,e.op1];if(!e.isLiteral)return[1,e];const t=e.engine;if(null!==e.machineValue&&e.machineValue<0)return[-1,t.number(-e.machineValue)];if(null===(i=e.decimalValue)||void 0===i?void 0:i.isNegative())return[-1,t.number(e.decimalValue.neg())];if(null!==e.complexValue){const i=e.complexValue;if(i.re<0)return[-1,t.number(t.complex(-i.re,-i.im))]}const[n,r]=e.rationalValue;return null!==n&&null!==r&&n<0?[-1,t.number([-n,r])]:[1,e]}class hn{constructor(e,i){if(this._terms=[],this._literal=[1,1],this._hasInfinity=!1,this._hasZero=!1,this.engine=e,i)for(const e of i)this.addTerm(e)}get isEmpty(){return!1===this._hasInfinity&&!1===this._hasZero&&this._literal[0]===this._literal[1]&&0===this._terms.length}addTerm(e){if(e.isNothing)return;if(e.isLiteral){if(e.isOne)return;if(e.isZero)return void(this._hasZero=!0);if(e.isNegativeOne)return void(this._literal[0]*=-1);if(e.isInfinity)return this._hasInfinity=!0,void(e.isNegative&&(this._literal[0]*=-1))}let[i,t]=un(e);if(this._literal=[this._literal[0]*i[0],this._literal[1]*i[1]],t.isLiteral&&t.isOne)return;let n=[1,1];if("Power"===t.head&&t.op2.isLiteral){const[e,i]=t.op2.asRational;null!==e&&null!==i&&(n=[e,i],t=t.op1)}let r=!1;if(1===n[1]||t.isNonNegative)for(const e of this._terms)if(e.term.isSame(t)){const[i,t]=e.exponent,[a,s]=n;e.exponent=[i*s+t*a,t*s],r=!0;break}r||this._terms.push({exponent:n,term:t})}groupedByDegrees(e){const i=this.engine,t=[],n=[];this._hasInfinity&&n.push(i._POSITIVE_INFINITY),this._literal=Tt(this._literal),1===this._literal[0]&&1===this._literal[1]||((null==e?void 0:e.splitRational)?(1!==this._literal[0]&&n.push(i.number(this._literal[0]).canonical),1!==this._literal[1]&&t.push({exponent:[-1,1],terms:[i.number(this._literal[1]).canonical]})):n.push(i.number(this._literal).canonical)),n.length>0&&t.push({exponent:[1,1],terms:n});for(const e of this._terms){if(0===e.exponent[0])continue;let i=!1;for(const n of t)if(e.exponent[0]===n.exponent[0]&&e.exponent[1]===n.exponent[1]){n.terms.push(e.term),i=!0;break}i||t.push({exponent:Tt(e.exponent),terms:[e.term]})}return t}terms(){return fn(this.engine,this.groupedByDegrees())}asNumeratorDenominator(){var e,i;const t=this.groupedByDegrees(),n=[],r=[];for(const e of t)e.exponent[0]>=0?n.push(e):r.push({exponent:[-e.exponent[0],e.exponent[1]],terms:e.terms});const a=this.engine;let s=fn(a,n);s=null!==(e=tn(s,"Multiply"))&&void 0!==e?e:s;let o=a._ONE;1===s.length?o=s[0]:s.length>0&&(o=a._fn("Multiply",s));let l=fn(a,r);l=null!==(i=tn(l,"Multiply"))&&void 0!==i?i:l;let u=a._ONE;return 1===l.length?u=l[0]:l.length>0&&(u=a._fn("Multiply",l)),[o,u]}asExpression(){var e;const i=this.engine;if(this._hasInfinity){if(this._hasZero)return i._NAN;if(0===this._terms.length)return this._literal[0]>0?i._POSITIVE_INFINITY:i._NEGATIVE_INFINITY}if(this._hasZero)return i._ZERO;if(0===this._terms.length)return i.number(this._literal).canonical;let t=fn(i,this.groupedByDegrees({splitRational:!1}));return this._hasInfinity&&t.push(i._POSITIVE_INFINITY),t=null!==(e=tn(t,"Multiply"))&&void 0!==e?e:t,0===t.length?i._ONE:1===t.length?t[0]:this.engine._fn("Multiply",t)}asRationalExpression(){const[e,i]=this.asNumeratorDenominator();return i.isOne?e:i.isNegativeOne?this.engine.negate(e):this.engine._fn("Divide",[e,i])}}function mn(e){const[i,t]=e;return i===t?0:i>0&&Number.isInteger(i/t)?1:i>0?2:Number.isInteger(i/t)?3:4}function dn(e,i){const t=mn(e.exponent),n=mn(i.exponent);return t!==n?t-n:e.exponent[0]/e.exponent[1]-i.exponent[0]/i.exponent[1]}function fn(e,i){var t;const n=(i=i.sort(dn)).map((i=>{var t;const n=null!==(t=tn(i.terms,"Multiply"))&&void 0!==t?t:i.terms,r=n.length<=1?n[0]:e._fn("Multiply",n.sort(on));return i.exponent[0]===i.exponent[1]?r:e.power(r,i.exponent)}));return null!==(t=tn(n,"Multiply"))&&void 0!==t?t:n}function gn(e,i,t,n){var r,a;const s=e.jsonSerializationOptions.exclude;if(("Rational"===i||"Divide"===i)&&2===t.length&&t[0].isLiteral&&t[1].isLiteral&&1===t[0].asSmallInteger&&2===t[1].asSmallInteger&&!s.includes("Half"))return pn(e,"Half",Object.assign(Object.assign({},n),{wikidata:"Q39373172"}));if("Negate"===i&&(null===(r=t[0])||void 0===r?void 0:r.isLiteral)&&1===t.length){if(null!==t[0].machineValue)return vn(e,-t[0].machineValue);if(null!==t[0].decimalValue)return vn(e,t[0].decimalValue.neg());if(null!==t[0].complexValue)return vn(e,t[0].complexValue.neg());const[i,n]=t[0].rationalValue;if(null!==i&&null!==n)return vn(e,[-i,n])}if("string"==typeof i&&s.includes(i)){if("Rational"===i&&2===t.length)return gn(e,"Divide",t,n);if("Complex"===i&&2===t.length)return gn(e,"Add",[t[0],e._fn("Multiply",[t[1],e.symbol("ImaginaryUnit")])],n);if("Sqrt"===i&&1===t.length)return gn(e,"Power",[t[0],s.includes("Half")?e.number([1,2]):e._HALF],n);if("Root"===i&&2===t.length&&t[1].isLiteral){const i=t[1].asSmallInteger;if(2===i)return gn(e,"Sqrt",[t[0]]);if(null!==i)return i<0?gn(e,"Divide",[e._ONE,e._fn("Power",[t[0],e.number([1,-i])])],n):gn(e,"Power",[t[0],e.number([1,-i])],n)}if("Square"===i&&1===t.length)return gn(e,"Power",[t[0],e._TWO],n);if("Exp"===i&&1===t.length)return gn(e,"Power",[e.symbol("ExponentialE"),t[0]],n);if("Subtract"===i&&2===t.length)return gn(e,"Add",[t[0],e._fn("Negate",[t[1]])],n);if("Subtract"===i&&1===t.length)return gn(e,"Negate",t,n)}if("Add"===i&&2===t.length&&!s.includes("Subtract")){if(t[1].isLiteral){const i=t[1].asSmallInteger;if(null!==i&&i<0)return gn(e,"Subtract",[t[0],e.number(-i)],n)}if("Negate"===t[1].head)return gn(e,"Subtract",[t[0],t[1].op1],n)}if("Tuple"===i){if(1===t.length&&!s.includes("Single"))return gn(e,"Single",t,n);if(2===t.length&&!s.includes("Pair"))return gn(e,"Pair",t,n);if(3===t.length&&!s.includes("Triple"))return gn(e,"Triple",t,n)}const o=["string"==typeof i?i:i.json,...t.map((e=>e.json))],l=Object.assign({},null!=n?n:{});return e.jsonSerializationOptions.metadata.includes("latex")?l.latex=null!==(a=l.latex)&&void 0!==a?a:e.serialize({fn:o}):l.latex="",e.jsonSerializationOptions.metadata.includes("wikidata")||(l.wikidata=""),l.latex||l.wikidata||!e.jsonSerializationOptions.shorthands.includes("function")?l.latex&&l.wikidata?{fn:o,latex:l.latex,wikidata:l.wikidata}:l.latex?{fn:o,latex:l.latex}:l.wikidata?{fn:o,wikidata:l.wikidata}:{fn:o}:o}function pn(e,i,t){var n,r;if("Half"===i&&e.jsonSerializationOptions.exclude.includes("Half"))return vn(e,[1,2],t);if(t=Object.assign({},t),e.jsonSerializationOptions.metadata.includes("latex")?(t.latex=null!==(n=t.latex)&&void 0!==n?n:e.serialize({sym:i}),void 0!==t.latex&&(t.latex=t.latex)):t.latex=void 0,e.jsonSerializationOptions.metadata.includes("wikidata")){if(void 0===t.wikidata){const n=null===(r=e.lookupSymbol(i))||void 0===r?void 0:r.wikidata;void 0!==n&&(t.wikidata=n)}}else t.wikidata=void 0;return void 0===t.latex&&void 0===t.wikidata&&e.jsonSerializationOptions.shorthands.includes("symbol")?i:void 0!==t.latex&&void 0!==t.wikidata?{sym:i,latex:t.latex,wikidata:t.wikidata}:void 0!==t.latex?{sym:i,latex:t.latex}:void 0!==t.wikidata?{sym:i,wikidata:t.wikidata}:{sym:i}}function vn(e,i,t){var n,r,a;t=Object.assign({},t),e.jsonSerializationOptions.metadata.includes("latex")||(t.latex=void 0);const s=void 0===t.latex&&!e.jsonSerializationOptions.metadata.includes("latex")&&e.jsonSerializationOptions.shorthands.includes("number");let o="";if(i instanceof Ze){if(i.isNaN()?o="NaN":i.isFinite()||(o=i.isPositive()?"+Infinity":"-Infinity"),!o){if(s&&en(i)&&i.precision()<15)return i.toNumber();o=i.isInteger()&&i.e<i.precision()+4?i.toFixed(0):bn(e,i.toString())}return e.jsonSerializationOptions.metadata.includes("latex")&&(t.latex=null!==(n=t.latex)&&void 0!==n?n:e.serialize({num:o})),void 0!==t.latex?{num:o,latex:t.latex}:{num:o}}if(i instanceof Be.exports.Complex)return i.isInfinite()?pn(e,"ComplexInfinity",t):i.isNaN()?(o="NaN",e.jsonSerializationOptions.metadata.includes("latex")&&(t.latex=null!==(r=t.latex)&&void 0!==r?r:e.serialize({num:o})),void 0!==t.latex?{num:o,latex:t.latex}:{num:o}):gn(e,"Complex",[e.number(i.re),e.number(i.im)],Object.assign(Object.assign({},t),{wikidata:"Q11567"}));if(Array.isArray(i))return void 0===t.latex&&void 0===t.wikidata&&!e.jsonSerializationOptions.metadata.includes("latex")&&e.jsonSerializationOptions.shorthands.includes("function")&&e.jsonSerializationOptions.shorthands.includes("number")?["Rational",i[0],i[1]]:gn(e,"Rational",[e.number(i[0]),e.number(i[1])],t);if(Number.isNaN(i)&&(o="NaN"),!Number.isFinite(i)&&i>0&&(o="+Infinity"),!Number.isFinite(i)&&i<0&&(o="-Infinity"),!o){if(s)return i;o=bn(e,i.toString())}return e.jsonSerializationOptions.metadata.includes("latex")&&(t.latex=null!==(a=t.latex)&&void 0!==a?a:e.serialize({num:o})),void 0!==t.latex?{num:o,latex:t.latex}:{num:o}}function bn(e,i){var t;if(!e.jsonSerializationOptions.repeatingDecimal)return i;let[n,r,a,s]=null!==(t=i.match(/^(.*)\.([0-9]+)([e|E][-+]?[0-9]+)?$/))&&void 0!==t?t:[];if(!a)return i;const o=a[a.length-1];a=a.slice(0,-1);let l="";for(let e=0;e<a.length-16;e++){l=a.substring(0,e);for(let t=0;t<=16;t++){const n=a.substring(e,e+t+1),u=Math.floor((a.length-l.length)/n.length);if(u>1&&(l+n.repeat(u+1)).startsWith(a))return"0"===n?"0"===o?r+"."+l+(null!=s?s:""):i:r+"."+l+"("+n+")"+(null!=s?s:"")}}return i}class yn extends Qt{constructor(e,i,t){super(e,t),this._value=Nn(e,i)}get isCanonical(){return!0}get canonical(){return this}get isValid(){return"Error"!==this.ctor}get json(){const e=Mn(this.engine,this._value);return"Error"===hi(e)?e:["Domain",e]}get literal(){return"string"==typeof this._value?this._value:null}get ctor(){return"string"==typeof this._value?null:this._value[0]}get domainArgs(){return"string"==typeof this._value?null:this._value.slice(1)}get domainArg1(){return"string"==typeof this._value?null:this._value[1]}get codomain(){return"string"==typeof this._value?null:this.engine.domain(this._value[this._value.length-1])}get hash(){return void 0===this._hash&&(this._hash=Wt(Fn(this._value))),this._hash}isEqual(e){return On(this._value,e)}isSame(e){return On(this._value,e)}is(e){return On(this._value,e)}isCompatible(e,i="covariant"){const t=this._value,n=e instanceof yn?e._value:e,r=Array.isArray(n)?n[0]:null;if(r){const e=n[1];if("Invariant"===r)return!En(e,t)&&!En(t,e);if("Covariant"===r)return En(t,e);if("Contravariant"===r)return En(e,t);if("Bivariant"===r)return En(t,e)&&En(e,t)}return"covariant"===i?En(t,n):"contravariant"===i?En(n,t):"bivariant"===i?En(n,t)&&En(t,n):!En(n,t)&&!En(t,n)}match(e,i){return e instanceof yn&&this.isSame(e)?{}:null}get head(){return"Domain"}get domain(){return this.engine.domain("Domain")}get isNothing(){return"Nothing"===this._value}get isFunction(){return"Function"===this.ctor||"Function"===this._value}get isNumeric(){return this.isCompatible(this.engine.domain("Number"))}get isRelationalOperator(){return"RelationalOperator"===this._value||"Function"===this.ctor&&2===this.domainArgs.length&&!!this.codomain.isCompatible("MaybeBoolean")}}function xn(e,i,t){if(i instanceof yn)return i;if("string"==typeof i){const n=Nt[i];if(n)return xn(e,n);if(!wt(i))throw Error("Expected a domain literal, got "+i);return new yn(e,i,t)}if(!Array.isArray(i)||0===i.length)throw Error("Expected a valid domain");const n=i[0];if(!xt.includes(n))throw Error("Expected domain constructor, got "+n);return new yn(e,i,t)}function Nn(e,i){if("string"==typeof i){if(!wt(i))throw Error("Unknown domain literal");return i}if(i instanceof yn)return i._value;const t=i[0];if("Range"===t){if(1===i.length)return"Integer";let t=e._ONE,n=e._POSITIVE_INFINITY;2===i.length?n=e.box(i[1]).evaluate():3===i.length&&(t=e.box(i[1]).evaluate(),n=e.box(i[2]).evaluate());const r=_n(t),a=_n(n);if(null===r||null===a)throw Error(`Invalid range [${r}, ${a}] `);return a<r&&([t,n]=[n,t]),r===-1/0&&a===1/0?"Integer":1===r&&a===1/0?"PositiveInteger":0===r&&a===1/0?"NonNegativeInteger":r===-1/0&&-1===a?"NegativeInteger":r===-1/0&&0===a?"NonPositiveInteger":["Range",e.number(r),e.number(a)]}if("Interval"===t){if(3!==i.length)throw Error("Invalid range "+i);let[t,n]=Sn(e,i[1]),[r,a]=Sn(e,i[2]);if(null===n||null===a)throw Error("Invalid range "+i);return a<n&&([n,a]=[a,n],[t,r]=[r,t]),0===n&&a===1/0?t?"PositiveNumber":"NonNegativeNumber":n===-1/0&&0===a?r?"NegativeNumber":"NonPositiveNumber":["Interval",t?["Open",e.number(n)]:e.number(n),r?["Open",e.number(a)]:e.number(a)]}if("Function"===t)return["Function",...i.slice(1).map((i=>Nn(e,i)))];if("Dictionary"===t)return["Dictionary",Nn(e,i[1])];if("List"===t)return["List",Nn(e,i[1])];if("Tuple"===t)return["Tuple",...i.slice(1).map((i=>Nn(e,i)))];if("Union"===t)return["Union",...i.slice(1).map((i=>Nn(e,i)))];if("Intersection"===t)return["Intersection",...i.slice(1).map((i=>Nn(e,i)))];if("Covariant"===t||"Contravariant"===t||"Invariant"===t)return[t,Nn(e,i[1])];if("Maybe"===t)return["Maybe",Nn(e,i[1])];if("Sequence"===t)return["Sequence",Nn(e,i[1])];if("Head"===t)return["Head",i[1]];if("Symbol"===t)return["Symbol",i[1]];if("Value"===t)return["Value",e.box(i[1])];if("Error"===t)return["Error",...i.slice(1).map((i=>e.box(i)))];throw Error("Unexpected domain constructor "+t)}function _n(e){return e.isInfinity?e.isPositive?1/0:-1/0:e.asSmallInteger}function Sn(e,i){return Array.isArray(i)&&"Open"===i[0]?[!0,_n(e.box(i[1]).evaluate())]:[!1,_n(e.box(i).evaluate())]}function wn(e){if(e instanceof yn)return!0;if("string"==typeof e)return wt(e);if(Array.isArray(e)){if(e.length<=1)return!1;const i=e[0];return!("string"!=typeof i||!xt.includes(i))&&e.every((e=>null!==e))}return!1}function En(e,i){const t="string"==typeof i?i:null;if("Anything"===t)return!0;const n="string"==typeof e?e:null;if(n&&t)return n===t||An(Et(n),t);if(t){const i=e[0];return"Function"===i?"Function"===t:"Dictionary"===i?"Dictionary"===t:"List"===i?"List"===t:"Tuple"===i?"Tuple"===t:"Interval"===i?En("ExtendedRealNumber",t):"Range"!==i||En("Integer",t)}const r=i[0];if("Function"===r){if("Function"===n)return!0;if(n)return!1;if("Function"!==e[0])return!1;if(!En(e[e.length-1],i[i.length-1]))return!1;const t=e.slice(1,-1),r=i.slice(1,-1);for(let e=0;e<=t.length-1;e++){const i=Array.isArray(t[e])?t[e][0]:null;if(void 0===r[e])return"Maybe"===i;if("Sequence"===i){const i=t[e][1];for(let t=e;t<r.length-1;t++)if(!En(r[t],i))return!1;return!0}if(!En(r[e],t[e]))return!1}return!(r.length>t.length)}return"Intersection"===r?i.slice(1,-1).every((i=>En(e,i))):"Union"===r?i.slice(1,-1).some((i=>En(e,i))):"Maybe"===r&&("Nothing"===n||En(e,i[1]))}function kn(e,i){const t=In(e),n=In(i),r=[t,...Et(t)],a=[n,...Et(n)];for(;!An(a,r[0]);)r.shift();return e.engine.domain(r[0])}function In(e){let i=e.literal;return i||(i=e.ctor,"Maybe"===i?"Anything":"Interval"===i?"RealNumber":"Range"===i?"Integer":"Head"===i?"Function":"Union"===i||"Intersection"===i?"Anything":i)}function An(e,i){for(const t of e)if(t===i)return!0;return!1}function Mn(e,i){if(i instanceof Qt)return i.json;if("string"==typeof i)return i;if("Error"===i[0])return i[2]?["Error",Mn(e,i[1]),Mn(e,i[2])]:["Error",Mn(e,i[1])];const t=[pn(e,i[0])];if(i.length>1)for(let t=1;t<=i.length-1;t++)Mn(e,i[t]);return t}function Fn(e){if("string"==typeof e)return"domain:"+e;let i="domain:"+this.ctor;for(const e of this.domainArgs)i+=":"+Fn(e);return i}function On(e,i){if("string"==typeof i)return this._value===i;if(i instanceof yn)return On(e,i._value);if("string"==typeof e)return e===i;if(!Array.isArray(i))return!1;if(e[0]!==i[0])return!1;if(i.length!==e.length)return!1;for(let t=1;t<=e.length-1;t++)if(e[t]instanceof Qt){if(!(i[t]instanceof Qt))return!1;if(!i[t].isEqual(i[t]))return!1}else if("string"==typeof e[t]){if("string"!=typeof i[t])return!1;if(e[t]!==i[t])return!1}else if(!On(e[t],i[t]))return!1;return!0}function Vn(e){const i=e.engine,t=e.head;if(t&&e.op1.symbol){const n=e.op1.symbol;let r=i.lookupSymbol(n);if(r||(r=i.defineSymbol({name:n})),"Equal"===t)return e.op1.value=e.op2.evaluate(),"ok";if("Element"===t){let t=e.op2;if("Domain"!==t.head&&(t=i.domain(t.json)),wn(t))return e.op1.domain=i.domain(t),"ok"}else if("Greater"===t){const i=e.op2.evaluate();if(r.value)return r.value.isGreater(i)?"tautology":"contradiction";if(i.isZero)return r.positive=!0,"ok"}}return"not-a-predicate"}class Tn extends Qt{constructor(e,i,t){super(e,t),this._value=new Map,this._isCanonical=!1;for(const t of Object.keys(i))this._value.set(t,e.box(i[t]));e._register(this)}unbind(){for(const[e,i]of this._value)i.unbind()}get hash(){let e=Wt("Dictionary");for(const[i,t]of this._value)e^=Wt(i)^t.hash;return e}get complexity(){return 97}get head(){return"Dictionary"}get isPure(){return!1}getKey(e){return this._value.get(e)}hasKey(e){return this._value.has(e)}get keys(){return this._value.keys()}get keysCount(){return this._value.size}has(e){for(const[i,t]of this._value)if(t.has(e))return!0;return!1}get domain(){const e=["Dictionary"];for(const[i,t]of this._value)e.push(["Tuple",i,t.domain]);return this.engine.domain(e)}get json(){if(this.engine.jsonSerializationOptions.shorthands.includes("dictionary")){const e={};for(const i of this._value.keys())e[i]=this._value.get(i).json;return{dict:e}}const e=[];for(const i of this._value.keys())e.push(this.engine._fn("KeyValuePair",[this.engine.string(i),this._value.get(i)]));return gn(this.engine,"Dictionary",e,{latex:this._latex})}isSame(e){if(this===e)return!0;if(!(e instanceof Tn))return!1;if(this._value.size!==e._value.size)return!1;for(const[i,t]of this._value){const n=e.getKey(i);if(!n||!t.isSame(n))return!1}return!0}match(e,i){if(!(e instanceof Tn))return null;if(this._value.size!==e._value.size)return null;let t={};for(const[i,n]of this._value){const r=e.getKey(i);if(!r)return null;const a=n.match(r);if(null===a)return null;t=Object.assign(Object.assign({},t),a)}return t}isEqual(e){if(this===e)return!0;if(!(e instanceof Tn))return!1;if(!e.keys||this._value.size!==e._value.size)return!1;for(const[i,t]of this._value){const n=e.getKey(i);if(!n||!t.isEqual(n))return!1}return!0}apply(e,i){const t={};for(const i of this.keys)t[i]=this.engine.box(e(this.getKey(i)));return i?this.engine.fn(i,[{dict:t}]):new Tn(this.engine,t)}evaluate(e){return this.apply((i=>{var t;return null!==(t=i.evaluate(e))&&void 0!==t?t:i}))}get isCanonical(){return this._isCanonical}set isCanonical(e){this._isCanonical=e}get canonical(){if(this.isCanonical)return this;const e=this.apply((e=>e.canonical));return e.isCanonical=!0,e}simplify(e){var i;return null===(i=null==e?void 0:e.recursive)||void 0===i||i?this.apply((i=>{var t;return null!==(t=i.simplify(e))&&void 0!==t?t:i})):this}N(e){return this.apply((i=>i.N(e)))}replace(e,i){let t=0;const n={};for(const r of this.keys){const a=this.getKey(r),s=a.replace(e,i);null!==s&&(t+=1),n[r]=null!=s?s:a}return 0===t?null:new Tn(this.engine,n)}subs(e){const i={};for(const t of this.keys)i[t]=this.getKey(t).subs(e);return new Tn(this.engine,i)}}function qn(e,i){var t;const n=new Set;for(const[r,a,s]of i){let i=e.pattern(r);const o={};for(const t of jt(i))o[t]=e.symbol("_"+t);let l;i=i.subs(o);const u=zt(null==s?void 0:s.condition);if(u){const i=e.parse(u).subs(o);l=e=>{var t;return"True"===(null===(t=i.subs(e).value)||void 0===t?void 0:t.symbol)}}else l=null==s?void 0:s.condition;const c=Rt(a)?e.parse(a):e.box(a);c&&n.add([i,c.subs(o),null!==(t=null==s?void 0:s.priority)&&void 0!==t?t:0,l])}return n}function Cn([e,i,t,n],r,a){const s=e.match(r,a);return null===s?null:"function"!=typeof n||n(s)?i.subs(s):null}function Dn(e,i,t){var n,r;const a=null!==(n=null==t?void 0:t.iterationLimit)&&void 0!==n?n:1;let s=0;const o=null!==(r=null==t?void 0:t.once)&&void 0!==r&&r;let l=!1,u=!1;try{for(;!l&&s<a;){l=!0;for(const n of i){const i=Cn(n,e,t);if(null!==i&&i!==e){if(o)return i;l=!1,u=!0,e=i}}s+=1}}catch(e){}return u?e:null}const Pn=[];function Ln(e,i){if(null==i)return e;if(e===i)return e;const t=e.engine,n=t.box(i);return t.costFunction(n)<=1.7*t.costFunction(e)?n:e}class Rn extends Qt{constructor(e,i,t,n){var r,a,s,o,l;if(null!=n||(n={}),null!==(r=n.canonical)&&void 0!==r||(n.canonical=!1),super(e,n.metadata),this._scope=e.context,this._head=i,this._ops=t,n.canonical&&(this._canonical=this),this._def=null!==(a=n.def)&&void 0!==a?a:null,this._codomain=null,"string"!=typeof this._head)this._codomain=this._head.domain.codomain;else if(this._def){const i=this._def.signature;"function"==typeof i.codomain?this._codomain=null!==(s=i.codomain(e,this._ops.map((e=>e.domain))))&&void 0!==s?s:null:this._codomain=null!==(o=i.codomain)&&void 0!==o?o:null}this._codomain||(this._codomain=null!==(l=e.defaultDomain)&&void 0!==l?l:e.domain("Void")),e._register(this)}get hash(){if(void 0!==this._hash)return this._hash;let e=0;for(const i of this._ops)e=e<<1^i.hash|0;return e="string"==typeof this._head?e^Wt(this._head)|0:e^this._head.hash|0,this._hash=e,e}get isCanonical(){return this._canonical===this}set isCanonical(e){this._canonical=e?this:void 0}get isLiteral(){return!1}get isPure(){var e;if(!this.isCanonical)return!1;if(void 0!==this._isPure)return this._isPure;let i;return void 0!==(null===(e=this.functionDefinition)||void 0===e?void 0:e.pure)&&(i=this.functionDefinition.pure),!1!==i&&(i=this._ops.every((e=>e.isPure))),this._isPure=i,i}get json(){return this._canonical===this?function(e,i,t,n){var r,a;const s=e.jsonSerializationOptions.exclude;if("Add"===i&&2===t.length&&!s.includes("Subtract")){if(t[0].isLiteral){const i=t[0].asSmallInteger;if(null!==i&&i<0)return gn(e,"Subtract",[t[1],e.number(-i)],n)}if("Negate"===t[0].head)return gn(e,"Subtract",[t[1],t[0].op1],n)}if("Divide"===i&&e.jsonSerializationOptions.exclude.includes("Divide"))return gn(e,"Multiply",[t[0],e._fn("Power",[t[1],e._NEGATIVE_ONE])],n);if("Multiply"===i&&!e.jsonSerializationOptions.exclude.includes("Divide")){const i=new hn(e,t).asRationalExpression();if("Divide"===i.head)return gn(e,i.head,i.ops,n)}if("Power"===i){if(!s.includes("Exp")&&"ExponentialE"===(null===(r=t[0])||void 0===r?void 0:r.symbol))return gn(e,"Exp",[t[1]],n);if(null===(a=t[1])||void 0===a?void 0:a.isLiteral){const i=t[1].asSmallInteger;if(!s.includes("Square")&&2===i)return gn(e,"Square",[t[0]],n);if(!e.jsonSerializationOptions.exclude.includes("Divide")){if(-1===i)return gn(e,"Divide",[e._ONE,t[0]],n);if(null!==i&&i<0)return gn(e,"Divide",[e._ONE,e.power(t[0],-i)],n)}const[r,a]=t[1].rationalValue;if(1===r){if(!s.includes("Sqrt")&&2===a)return gn(e,"Sqrt",[t[0]],n);if(!s.includes("Root"))return gn(e,"Root",[t[0],e.number(a)],n)}if(-1===r){if(!s.includes("Sqrt")&&2===a)return gn(e,"Divide",[e._ONE,e._fn("Sqrt",[t[0]])],n);if(!s.includes("Root"))return gn(e,"Divide",[e._ONE,e._fn("Root",[t[0],e.number(a)])],n)}}}return gn(e,i,t,n)}(this.engine,this._head,this._ops,{latex:this._latex,wikidata:this._wikidata}):gn(this.engine,this._head,this._ops,{latex:this._latex,wikidata:this._wikidata})}get head(){return this._head}get ops(){return this._ops}get nops(){return this._ops.length}get op1(){var e;return null!==(e=this._ops[0])&&void 0!==e?e:this.engine.symbol("Nothing")}get op2(){var e;return null!==(e=this._ops[1])&&void 0!==e?e:this.engine.symbol("Nothing")}get op3(){var e;return null!==(e=this._ops[2])&&void 0!==e?e:this.engine.symbol("Nothing")}get isValid(){return"string"!=typeof this._head?!1!==this._head.isValid&&this._ops.every((e=>e.isValid)):"Error"!==this._head&&(this._canonical!==this||void 0!==this.functionDefinition&&!!this._ops.every((e=>e.isValid)))}get canonical(){return this._canonical||(this.isValid?this._canonical=zn(this.engine,this._head,this._ops):this._canonical=this),this._canonical}*map(e){let i=0;for(;i<this._ops.length;)yield e(this._ops[i++])}apply(e,i){const t=null!=i?i:this.head;let n=!1;const r=[];for(const i of this._ops){const t=e(i);i!==t&&(n=!0),r.push(this.engine.box(t))}return n||this.head!==t?this.engine.fn(t,r):this}subs(e){return zn(this.engine,this._head,this._ops.map((i=>i.subs(e))))}replace(e,i){return Dn(this,e,i)}has(e){if("string"==typeof this._head)if("string"==typeof e){if(this._head===e)return!0}else if(e.includes(this._head))return!0;for(const i of this._ops)if(i.has(e))return!0;return!1}isSame(e){if(this===e)return!0;if(!(e instanceof Rn))return!1;if(this.nops!==e.nops)return!1;if("string"==typeof this.head){if(this.head!==e.head)return!1}else{if("string"==typeof e.head)return!1;if(!e.head||!this.head.isSame(e.head))return!1}const i=this._ops,t=e._ops;for(let e=0;e<i.length;e++)if(!i[e].isSame(t[e]))return!1;return!0}match(e,i){if(!(e instanceof Rn))return null;let t={};if("string"==typeof this.head){if(this.head!==e.head)return null}else{if("string"==typeof e.head)return null;{if(!e.head)return null;const n=this.head.match(e.head,i);if(null===n)return null;t=Object.assign(Object.assign({},t),n)}}const n=this._ops,r=e._ops;for(let e=0;e<n.length;e++){const a=n[e].match(r[e],i);if(null===a)return null;t=Object.assign(Object.assign({},t),a)}return t}unbind(){this._value=void 0,this._numericValue=void 0}get wikidata(){var e,i,t;if(this.isCanonical)return null!==(t=null!==(e=this._wikidata)&&void 0!==e?e:null===(i=this.functionDefinition)||void 0===i?void 0:i.wikidata)&&void 0!==t?t:void 0}get description(){if(!this.isCanonical)return;const e=this.functionDefinition;return e?e.description?"string"==typeof e.description?[e.description]:e.description:void 0:[]}get url(){var e,i;return this.isCanonical?null!==(i=null===(e=this.functionDefinition)||void 0===e?void 0:e.url)&&void 0!==i?i:void 0:""}get complexity(){var e,i;if(this.isCanonical)return null!==(i=null===(e=this.functionDefinition)||void 0===e?void 0:e.complexity)&&void 0!==i?i:sn}get functionDefinition(){if(this.isCanonical)return null!==this._def?this._def:void 0}bind(e){}get value(){var e;return this.isCanonical?this.isPure?(this._value||(this._value=this.evaluate()),this._value):void 0:null!==(e=this.canonical.value)&&void 0!==e?e:this.canonical}get numericValue(){if(this._numericValue)return this._numericValue;if(!this.isCanonical)return this.canonical.numericValue;if(this.isPure){const e=this.N();this._numericValue=e===this?void 0:e}else this._numericValue=void 0;return this._numericValue}get domain(){return this.isCanonical?this._codomain:this.canonical.domain}isEqual(e){var i,t;if(!this.isCanonical)return this.canonical.isEqual(e);if((e=null!==(i=e.canonical.numericValue)&&void 0!==i?i:e.canonical).isNumber&&this.isNumber){const i=this.engine,n=i.add([this,i.negate(e)]).N();if(n.isZero)return!0;const r=n.asFloat;return null!==r&&0===i.chop(r)||(null!==(t=this.value)&&void 0!==t?t:this.evaluate()).isSame(e)}return this.domain.isRelationalOperator&&e.domain.isRelationalOperator,this.isSame(e)}isLess(e){var i;if(!this.isCanonical)return this.canonical.isLess(e);if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e<0}const t=this.engine;e=null!==(i=e.canonical.numericValue)&&void 0!==i?i:e.canonical;const n=t.add([this,t.negate(e)]).N().asFloat;return null===n?void 0:n<0}isLessEqual(e){var i;if(!this.isCanonical)return this.canonical.isLess(e);if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e<=0}const t=this.engine;e=null!==(i=e.canonical.numericValue)&&void 0!==i?i:e.canonical;const n=t.add([this,t.negate(e)]).N().asFloat;return null===n?void 0:n<=0||0===t.chop(n)}isGreater(e){var i;if(!this.isCanonical)return this.canonical.isLess(e);if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e>0}const t=this.engine;e=null!==(i=e.canonical.numericValue)&&void 0!==i?i:e.canonical;const n=t.add([this,t.negate(e)]).N().asFloat;return null===n?void 0:n>0}isGreaterEqual(e){var i;if(!this.isCanonical)return this.canonical.isLess(e);if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e>=0}const t=this.engine;e=null!==(i=e.canonical.numericValue)&&void 0!==i?i:e.canonical;const n=t.add([this,t.negate(e)]).N().asFloat;return null===n?void 0:n>=0||0===t.chop(n)}get isZero(){const e=this.sgn;return null!==e&&("number"==typeof e?0===e:void 0)}get isNotZero(){const e=this.sgn;return null!==e&&("number"==typeof e?0!==e:void 0)}get isOne(){return this.isEqual(this.engine.number(1))}get isNegativeOne(){return this.isEqual(this.engine.number(-1))}get isPositive(){const e=this.sgn;return null!==e&&("number"==typeof e?e>0:void 0)}get isNonPositive(){const e=this.sgn;return null!==e&&("number"==typeof e?e<=0:void 0)}get isNegative(){const e=this.sgn;return null!==e&&("number"==typeof e?e<0:void 0)}get isNonNegative(){const e=this.sgn;return null!==e&&("number"==typeof e?e>=0:void 0)}get isNumber(){return this.domain.isCompatible("Number")}get isInteger(){return this.domain.isCompatible("Integer")}get isRational(){return this.domain.isCompatible("RationalNumber")}get isAlgebraic(){return this.domain.isCompatible("AlgebraicNumber")}get isReal(){return this.domain.isCompatible("RealNumber")}get isExtendedReal(){return this.domain.isCompatible("ExtendedRealNumber")}get isComplex(){return this.domain.isCompatible("ComplexNumber")}get isImaginary(){return this.domain.isCompatible("ImaginaryNumber")}get sgn(){var e,i,t,n,r,a,s,o,l;if(!this.isCanonical)return this.canonical.sgn;const u=this.head;if("Negate"===u){const i=null===(e=this._ops[0])||void 0===e?void 0:e.sgn;if(void 0===i)return;return null===i?null:0===i?0:i>0?-1:1}if("Multiply"===u){const e=this._ops.reduce(((e,i)=>{var t;return e*(null!==(t=i.sgn)&&void 0!==t?t:NaN)}),1);return isNaN(e)?null:e>0?1:e<0?-1:0}if("Add"===u){let e=0,i=0,t=0;const n=this._ops.length;for(const n of this._ops){const r=n.sgn;if(null==r)break;0===r&&(t+=1),r>0&&(e+=1),r<0&&(i+=1)}return t===n?0:e===n?1:i===n?-1:null}if("Divide"===u){const e=null===(i=this._ops[0])||void 0===i?void 0:i.sgn,n=null===(t=this._ops[1])||void 0===t?void 0:t.sgn;return null===e||null===n||void 0===e||void 0===n?null:0===e?0:e>0&&n>0||e<0&&n<0?1:-1}if("Square"===u)return(null===(n=this._ops[0])||void 0===n?void 0:n.isImaginary)?-1:(null===(r=this._ops[0])||void 0===r?void 0:r.isZero)?0:1;if("Abs"===u)return(null===(a=this._ops[0])||void 0===a?void 0:a.isZero)?0:1;if("Sqrt"===u)return(null===(s=this._ops[0])||void 0===s?void 0:s.isZero)?0:(null===(o=this._ops[0])||void 0===o?void 0:o.isImaginary)?null:1;const c=(null!==(l=this.numericValue)&&void 0!==l?l:this.N()).asSmallInteger;return null!==c?0===c?0:c<0?-1:1:void 0}simplify(e){var i,t,n;if(!this.isValid)return this;if(!this.isCanonical)return this.canonical.simplify(e);const r=this.functionDefinition;let a,s=this._ops;if(s=r?jn(r.name,s,r.hold,r.associative,(i=>i.simplify(e))):jn("",s,"none",!1,(i=>i.simplify(e))),"string"!=typeof this._head)return $n(this.engine,this._head,s).simplify(e);if(r)if(r.inert)a=null!==(t=null===(i=s[0])||void 0===i?void 0:i.canonical)&&void 0!==t?t:this;else{const e=r.signature;(null==e?void 0:e.simplify)&&(a=e.simplify(this.engine,s))}a||(a=this.engine.fn(this._head,s).canonical);const o=null!==(n=null==e?void 0:e.rules)&&void 0!==n?n:this.engine.cache("standard-simplification-rules",(()=>qn(this.engine,Pn)),(e=>{for(const[i,t,n,r]of e)i.unbind(),t.unbind();return e}));let l=0,u=!1;do{const e=a.replace(o);null!==e?(a=Ln(e,a),a===e&&(u=!0)):u=!0,l+=1}while(!u&&l<this.engine.iterationLimit);return a}evaluate(e){var i,t;if(!this.isValid)return this;if(!this.isCanonical)return this.canonical.evaluate(e);const n=this.functionDefinition;let r=this._ops;if(r=n?jn(n.name,r,n.hold,n.associative,(i=>i.evaluate(e))):jn("",r,"none",!1,(i=>i.evaluate(e))),"string"!=typeof this._head)return $n(this.engine,this._head,r).evaluate(e);if(!n)return this.engine.fn(this._head,r).canonical;if(n.inert)return null!==(i=r[0])&&void 0!==i?i:this;const a=n.signature;return a&&(null==a?void 0:a.evaluate)?"function"!=typeof a.evaluate?$n(this.engine,a.evaluate,r).evaluate(e):null!==(t=a.evaluate(this.engine,r))&&void 0!==t?t:this.engine.fn(this._head,r).canonical:this.engine.fn(this._head,r).canonical}N(e){var i,t,n;if(!this.isValid)return this;if(!this.isCanonical)return this.canonical.N(e);const r=this.functionDefinition;let a=this._ops;if(a=r?jn(r.name,a,r.hold,r.associative,(i=>i.N(e))):jn("",a,"none",!1,(i=>i.N(e))),"string"!=typeof this._head)return $n(this.engine,this._head,a).N(e);if(!r)return this.engine.fn(this._head,a).canonical;if(r.inert)return null!==(i=a[0])&&void 0!==i?i:this;const s=r.signature,o=null!==(n=null===(t=null==s?void 0:s.N)||void 0===t?void 0:t.call(s,this.engine,a))&&void 0!==n?n:this.engine.fn(this._head,a).evaluate();if(o.isLiteral){if(!Ht(this.engine)&&o.complexValue)return this.engine._NAN;if(!Gt(this.engine)&&o.decimalValue)return this.engine.number(o.decimalValue.toNumber())}return o}solve(e){return null}}function zn(e,i,t,n){var r,a,s;if(null!=n||(n={}),n.canonical=!0,t=function(e){const i=[];for(const t of e)"Sequence"===t.head?t.ops&&i.push(...t.ops):i.push(t);return i}(t=t.map((e=>e.canonical))),"string"!=typeof i&&(i=null!==(r=i.evaluate().symbol)&&void 0!==r?r:i),"string"!=typeof i)return new Rn(e,i,t,n);if(null===e.context)return new Rn(e,i,t,n);const o=e.lookupFunction(i,e.context);if(!o)return new Rn(e,i,t,n);o.associative&&(t=null!==(a=tn(t,i))&&void 0!==a?a:t),o.scoped&&e.pushScope();const l=o.signature;if(t=null!==(s=function(e,i,t,n){var r;const a=t.map((e=>e.domain)),s=e.domain(["Function",...a,"Anything"]);if(i.domain.isCompatible(s))return null;const o=i.domain.domainArgs.slice(0,-1),l=[],u=Math.max(o.length,a.length);for(let i=0;i<=u-1;i++)if(void 0===o[i])l.push(e.error("unexpected-argument",t[i]));else{const n=Array.isArray(o[i])?o[i][0]:null;if(void 0===a[i]){"Maybe"===n?l.push(e.symbol("Nothing")):l.push(e.error(["missing",o[i]]));break}if("Sequence"===n){const n=e.domain(o[i][1]);for(let r=i;r<=a.length-1;r++)a[r].isCompatible(n)?l.push(t[r]):l.push(e.error(["incompatible-domain",n,e.domain(a[r])],t[r]));break}(null===(r=t[i].symbol)||void 0===r?void 0:r.startsWith("_"))||a[i].isCompatible(e.domain(o[i]))?l.push(t[i]):l.push(e.error(["incompatible-domain",e.domain(o[i],a[i])],t[i]))}return l}(e,l,t))&&void 0!==s?s:t,!t.every((e=>e.isValid)))return o.scoped&&e.popScope(),new Rn(e,i,t,Object.assign(Object.assign({},n),{def:o}));if(l.canonical){const i=l.canonical(e,t);return i.isValid&&i.isCanonical,i}if(1===t.length&&t[0].head===i){if(o.involution)return t[0].op1;o.idempotent&&(t=t[0].ops)}return t.length>1&&!0===o.commutative&&(t=t.sort(on)),o.scoped&&e.popScope(),new Rn(e,i,t,Object.assign(Object.assign({},n),{def:o}))}function $n(e,i,t){const n={__:i.engine.tuple(t),"_#":i.engine.number(t.length)};let r=1;for(const e of t)n["_"+r++]=e;return n._=n._1,i.subs(n)}function jn(e,i,t,n,r){var a,s;if(0===i.length)return[];n&&(i=null!==(a=tn(i,e))&&void 0!==a?a:i);const o=[];for(let e=0;e<i.length;e++)if("Hold"===i[e].head)o.push(i[e].op1);else{let n;if("ReleaseHold"===i[e].head?n=i[e].op1:Zn(t,i.length-1,e)?n=i[e]:o.push(i[e]),n){const e=r(n);null!==e&&o.push(e)}}return n&&null!==(s=tn(o,e))&&void 0!==s?s:o}function Zn(e,i,t){return"all"!==e&&("none"===e||("first"===e?0!==t:"rest"===e?0===t:"last"===e?t!==i:"most"===e&&t===i))}function Bn(e){if("number"==typeof e&&!isNaN(e))return isFinite(e)?0===e?"NonNegativeInteger":Number.isInteger(e)?e>0?"PositiveInteger":e<0?"NegativeInteger":"Integer":e>0?"PositiveNumber":e<0?"NegativeNumber":"RealNumber":"ExtendedRealNumber";if(e instanceof Ze)return e.isNaN()?"Number":e.isFinite()?e.isZero()?"NonNegativeInteger":e.isInteger()?e.gt(0)?"PositiveInteger":e.lt(0)?"NegativeInteger":"Integer":e.gt(0)?"PositiveNumber":e.lt(0)?"NegativeNumber":"RealNumber":"ExtendedRealNumber";if(e instanceof Be.exports.Complex){const i=e;return 0===i.im?Bn(i.re):0===i.re&&0!==i.im?"ImaginaryNumber":"ComplexNumber"}if(Array.isArray(e)){const[i,t]=Tt(e);if(!Number.isNaN(i)&&!Number.isNaN(t))return 1!==t?"RationalNumber":Bn(i)}return"Number"}function Gn(e){if(!Number.isInteger(e)||!Number.isFinite(e)||Number.isNaN(e)||e<=1)return!1;if(e<=7919)return Ft.has(e);for(const i of Ft)if(e%i==0)return!1;return e>=0x3ffffffffffe5?!!function(e,i){let t=0,n=e-1;for(;n%2==0;)n/=2,++t;e:do{let i=Math.pow(2+Math.floor(Math.random()*(e-3)),n)%e;if(1!==i&&i!==e-1){for(let n=t-1;n--;){if(i=i*i%e,1===i)return!1;if(i===e-1)continue e}return!1}}while(--i);return!0}(e,30)&&void 0:e===function(e){if(1===e)return 1;if(e%2==0)return 2;if(e%3==0)return 3;if(e%5==0)return 5;const i=Math.floor(Math.sqrt(e));let t=7;for(;t<=i;){if(e%t==0)return t;if(e%(t+4)==0)return t+4;if(e%(t+6)==0)return t+6;if(e%(t+10)==0)return t+10;if(e%(t+12)==0)return t+12;if(e%(t+16)==0)return t+16;if(e%(t+22)==0)return t+22;if(e%(t+24)==0)return t+24;t+=30}return e}(e)}class Hn extends Qt{constructor(e,i,t){if(super(e,t),this._isCanonical=!0,i instanceof Be.exports.Complex)Number.isNaN(i.re)||Number.isNaN(i.im)?this._value=NaN:0===e.chop(i.im)?this._value=i.re:this._value=Ht(e)?i:NaN;else if(Array.isArray(i)){let[e,t]=i;t<0&&([e,t]=[-e,-t]),1===t?this._value=e:0===e?this._value=0===t?NaN:e:(this._value=[e,t],this._isCanonical=1===Vt(e,t))}else i instanceof Ze?this._value=Gt(e)?i:i.toNumber():"number"==typeof i?this._value=i:Gt(e)?this._value=e.decimal(i):"string"==typeof i&&(this._value=Number.parseFloat(i));"number"==typeof this._value?Number.isInteger(this._value)?this._head="Integer":this._head="Number":this._value instanceof Be.exports.Complex?this._head="ComplexNumber":Array.isArray(this._value)?this._head="RationalNumber":this._value instanceof Ze?this._value.isInteger()?this._head="Integer":this._head="RealNumber":this._head="Number",e._register(this)}get hash(){if(void 0!==this._hash)return this._hash;let e=0;return e="number"==typeof this._value?Wt(this._value.toString()):this._value instanceof Be.exports.Complex?Wt(this._value.re.toString()+" +i "+this._value.im.toString()):this._value instanceof Ze?Wt(this._value.toString()):Wt(this._value[0].toString()+" / "+this._value[1].toString()),this._hash=e,e}get head(){return this._head}get isPure(){return!0}get isLiteral(){return!0}get isCanonical(){return this._isCanonical}set isCanonical(e){this._isCanonical=e}get complexity(){return 1}get value(){return this}get numericValue(){if(!Array.isArray(this._value))return this;const[e,i]=this._value,t=this.engine;return Gt(t)?new Hn(t,t.decimal(e).div(i)):new Hn(t,e/i)}get machineValue(){return"number"==typeof this._value?this._value:null}get decimalValue(){return this._value instanceof Ze?this._value:null}get complexValue(){return this._value instanceof Be.exports.Complex?this._value:null}get rationalValue(){return Array.isArray(this._value)?this._value:[null,null]}get asFloat(){return"number"==typeof this._value?this._value:this._value instanceof Ze?this._value.isNaN()?NaN:this._value.isFinite()?this._value.toNumber():this._value.isPositive()?1/0:-1/0:Array.isArray(this._value)?this._value[0]/this._value[1]:null}get asSmallInteger(){if("number"==typeof this._value)return Number.isInteger(this._value)&&this._value>=-1e6&&this._value<=At?this._value:null;if(this._value instanceof Ze)return this._value.isInteger()&&this._value.gte(-1e6)&&this._value.lte(At)?this._value.toNumber():null;if(Array.isArray(this._value)){const e=this._value[0]/this._value[1];return Number.isInteger(e)&&e>=-1e6&&e<=At?e:null}return 0===this.engine.chop(this._value.im)&&Number.isInteger(this._value.re)&&this._value.re>=-1e6&&this._value.re<=At?this._value.re:null}get asRational(){const[e,i]=this.rationalValue;if(null!==e&&null!==i)return[e,i];const t=this.asSmallInteger;return null!==t?[t,1]:[null,null]}get domain(){return void 0===this._domain&&(this._domain=this.engine.domain(Bn(this._value))),this._domain}get json(){return vn(this.engine,this._value,{latex:this._latex})}get sgn(){if(this.isZero)return 0;if(this._value instanceof Be.exports.Complex)return null;if("number"==typeof this._value)return this._value<0?-1:this._value>0?1:null;if(this._value instanceof Ze)return this._value.isNegative()?-1:this._value.isPositive()?1:null;if(Array.isArray(this._value)){const[e,i]=this._value;return 0===e&&0!==i?0:e<0?-1:e>0?1:null}return null}isSame(e){if(this===e)return!0;if(!(e instanceof Hn))return!1;if(Array.isArray(this._value)){if(!Array.isArray(e._value))return!1;const[i,t]=e._value;return this._value[0]===i&&this._value[1]===t}return this._value instanceof Ze?e._value instanceof Ze&&this._value.eq(e._value):this._value instanceof Be.exports.Complex?e._value instanceof Be.exports.Complex&&this._value.equals(e._value):"number"==typeof this._value&&"number"==typeof e._value&&this._value===e._value}isEqual(e){var i,t;if(this===e)return!0;const n=e.numericValue;if(void 0===n)return!1;if(!(n instanceof Hn))return!1;if(Array.isArray(this._value)){const e=n.asFloat;return null!==e&&0===this.engine.chop(this._value[0]/this._value[1]-e)}if(this._value instanceof Ze)return 0===this.engine.chop(this._value.sub(null!==(t=null!==(i=n.decimalValue)&&void 0!==i?i:n.asFloat)&&void 0!==t?t:NaN));if(this._value instanceof Be.exports.Complex){if(n instanceof Be.exports.Complex)return 0===this.engine.chop(n.re-this._value.re)&&0===this.engine.chop(n.im-this._value.im);if(0!==this._value.im)return!1}const r=this.asFloat,a=n.asFloat;return null!==r&&null!==a&&0===this.engine.chop(a-r)}match(e,i){var t;return this.isEqualWithTolerance(e,null!==(t=null==i?void 0:i.numericTolerance)&&void 0!==t?t:0)?{}:null}isEqualWithTolerance(e,i){var t,n;if(this===e)return!0;if(!(e instanceof Hn))return!1;if(Array.isArray(this._value)){const t=e.asFloat;return null!==t&&Math.abs(this._value[0]/this._value[1]-t)<=i}if(this._value instanceof Ze)return this._value.sub(null!==(n=null!==(t=e.decimalValue)&&void 0!==t?t:e.asFloat)&&void 0!==n?n:NaN).abs().lte(i);if(this._value instanceof Be.exports.Complex){if(e._value instanceof Be.exports.Complex)return Math.abs(e._value.re-this._value.re)<=i&&Math.abs(e._value.im-this._value.im)<=i;if(0!==this._value.im)return!1}const r=this.asFloat,a=e.asFloat;return null!==r&&null!==a&&Math.abs(a-r)<=i}isLess(e){if(e=e.N(),!this.isImaginary&&!e.isImaginary){if("number"==typeof this._value){const i=e.machineValue;if(null!==i)return this._value<i;const t=e.decimalValue;if(null!==t)return t.greaterThanOrEqualTo(this._value);const[n,r]=e.rationalValue;return null!==n&&null!==r&&this._value*r<n}if(this._value instanceof Ze){const i=e.machineValue;if(null!==i)return this._value.lt(i);const t=e.decimalValue;if(null!==t)return this._value.lt(t);const[n,r]=e.rationalValue;return null!==n&&null!==r&&this._value.mul(r).lt(n)}if(Array.isArray(this._value)){const[i,t]=this._value;if("number"==typeof e)return i<e*t;const[n,r]=e.rationalValue;if(null!==n&&null!==r)return i*r<n*t;const a=e.decimalValue;return null!==a&&a.mul(i).lt(t)}this._value,Be.exports.Complex}}isLessEqual(e){e=e.N();const i=this.isLess(e);if(void 0===i)return;const t=this.isEqual(e);return void 0!==t?i||t:void 0}isGreater(e){const i=this.isLess(e);if(void 0!==i)return!i}isGreaterEqual(e){e=e.N();const i=this.isLess(e);if(void 0===i)return;const t=this.isEqual(e);return void 0!==t?!i||t:void 0}get isPositive(){const e=this.sgn;if(null!=e)return e>0}get isNonNegative(){const e=this.sgn;if(null!=e)return e>=0}get isNegative(){const e=this.sgn;if(null!=e)return e<0}get isNonPositive(){const e=this.sgn;if(null!=e)return e<=0}get isZero(){return!Array.isArray(this._value)&&(0===this._value||0===this.engine.chop(this._value))}get isNotZero(){return!!Array.isArray(this._value)||0!==this._value&&0!==this.engine.chop(this._value)}get isOne(){if("number"==typeof this._value)return 1===this._value;if(this._value instanceof Ze)return this._value.equals(this.engine._DECIMAL_ONE);if(Array.isArray(this._value)){const[e,i]=this._value;return 0!==i&&e===i}return this._value.equals(1)}get isNegativeOne(){if("number"==typeof this._value)return-1===this._value;if(this._value instanceof Ze)return this._value.equals(this.engine._DECIMAL_NEGATIVE_ONE);if(Array.isArray(this._value)){const[e,i]=this._value;return e<0&&0!==i&&-e===i}return this._value.equals(-1)}get isOdd(){return!(!this.isOne&&!this.isNegativeOne)||!this.isZero&&!!this.isInteger&&("number"==typeof this._value?this._value%2!=0:this._value instanceof Ze?!this._value.mod(2).isZero():void 0)}get isEven(){return!this.isOne&&!this.isNegativeOne&&(!!this.isZero||!!this.isInteger&&("number"==typeof this._value?this._value%2==0:this._value instanceof Ze?this._value.mod(2).isZero():void 0))}get isPrime(){return!(!this.isInteger||!this.isFinite||this.isNonPositive||this.isOne||this.isZero)&&("number"==typeof this._value?Gn(this._value):this._value instanceof Ze?Gn(this._value.toNumber()):void 0)}get isComposite(){return!(!this.isInteger||!this.isFinite||this.isNonPositive||this.isOne||this.isZero)&&("number"==typeof this._value?!Gn(this._value):this._value instanceof Ze?!Gn(this._value.toNumber()):void 0)}get isInfinity(){return"number"==typeof this._value?!Number.isFinite(this._value)&&!Number.isNaN(this._value):(this._value instanceof Ze||this._value instanceof Be.exports.Complex)&&!this._value.isFinite()&&!this._value.isNaN()}get isNaN(){return"number"==typeof this._value?Number.isNaN(this._value):(this._value instanceof Ze&&this._value.isNaN(),this._value instanceof Be.exports.Complex&&this._value.isNaN(),!1)}get isFinite(){return!this.isInfinity&&!isNaN}get isNumber(){return!0}get isInteger(){return"number"==typeof this._value?Number.isInteger(this._value):this._value instanceof Ze&&this._value.isInteger()}get isRational(){return!!Array.isArray(this._value)||this.isInteger}get isAlgebraic(){if(this.isRational)return!0}get isReal(){return!(!this.isFinite||this._value instanceof Be.exports.Complex&&0!==this.engine.chop(this._value.im))}get isExtendedReal(){return this.isInfinity||this.isReal}get isComplex(){return!this.isNaN}get isImaginary(){return this._value instanceof Be.exports.Complex&&0!==this._value.im}get isExtendedComplex(){return this.isInfinity||!this.isNaN}get canonical(){if(this._isCanonical)return this;if(Array.isArray(this._value)){const[e,i]=Tt(this._value);return Number.isNaN(e)||Number.isNaN(i)?this.engine._NAN:1===i?this.engine.number(e):0===i?0!==e&&Number.isFinite(e)?e<0?this.engine._NEGATIVE_INFINITY:this.engine._POSITIVE_INFINITY:this.engine._NAN:0===e?this.engine._ZERO:this.engine.number([e,i])}return this}simplify(e){return this.canonical}N(e){if(Array.isArray(this._value)){const e=this.engine,[i,t]=this._value;return Gt(e)?e.number(e.decimal(i).div(t)):e.number(i/t)}return this}}class Wn extends Qt{constructor(e,i,t){super(e,t),this._string=i.normalize(),e._register(this)}get hash(){return Wt("String"+this._string)}get json(){return e=this.engine,i=this._string,e.jsonSerializationOptions.shorthands.includes("string")?`'${i}'`:{str:i};var e,i}get head(){return"String"}get isPure(){return!0}get isLiteral(){return!0}get isCanonical(){return!0}set isCanonical(e){}get domain(){return this.engine.domain("String")}get complexity(){return 19}get string(){return this._string}isEqual(e){return e.string===this._string}isSame(e){return e.string===this._string}match(e,i){return e instanceof Wn&&this._string===e._string?{}:null}}function Un(e,i){if(null==i)return e._fn("Sequence",[]);if(i instanceof Qt)return i;if(Array.isArray(i)){if("number"==typeof i[0]){const[t,n]=i;return"number"==typeof n&&Number.isInteger(t)&&Number.isInteger(n)?e.number(i):Kn(e,"Divide",i)}return"string"==typeof i[0]?Kn(e,i[0],i.slice(1)):new Rn(e,Un(e,i[0]),i.slice(1).map((i=>Un(e,i))))}if("number"==typeof i||i instanceof Be.exports.Complex||i instanceof Ze)return e.number(i);if("string"==typeof i)return i.startsWith("'")&&i.endsWith("'")?new Wn(e,i.slice(1,-1)):e.symbol(i);if("object"==typeof i){const t={latex:i.latex,wikidata:i.wikidata};if("dict"in i)return new Tn(e,i.dict,t);if("fn"in i)return"string"==typeof i.fn[0]?Kn(e,i.fn[0],i.fn.slice(1),t):new Rn(e,Un(e,i.fn[0]),i.fn.slice(1).map((i=>Un(e,i))),{metadata:t});if("str"in i)return new Wn(e,i.str,t);if("sym"in i)return e.symbol(i.sym,t);if("num"in i)return e.number(i,t)}return e.symbol("Undefined")}function Qn(e,i,t){var n;if(i instanceof Hn)return i;if(Array.isArray(i)){if(2!==i.length)throw Error("Array argument to boxNumber() should be two integers");let[n,r]=i;if("number"!=typeof n||"number"!=typeof r)throw Error("Array argument to boxNumber() should be two integers");if(!Number.isInteger(n)||!Number.isInteger(r))throw Error("Array argument to boxNumber() should be two integers");if(r===n)return 0===r?e._NAN:e._ONE;if(1===r)i=n;else{if(-1!==r)return 1===n&&2===r?e._HALF:new Hn(e,[n,r],t);i=-n}}if(i instanceof Be.exports.Complex){if(i.isNaN())return e._NAN;if(i.isZero())return e._ZERO;if(i.isInfinite())return e._COMPLEX_INFINITY;if(0!==i.im)return Ht(e)?new Hn(e,i,t):e._NAN;i=i.re}if(i instanceof Ze){const n=i.toNumber();return isNaN(n)?e._NAN:-1===n?e._NEGATIVE_ONE:0===n?e._ZERO:1===n?e._ONE:2===n?e._TWO:Number.isFinite(n)?new Hn(e,Gt(e)?i:n,t):n<0?e._NEGATIVE_INFINITY:e._POSITIVE_INFINITY}if("object"==typeof i&&"num"in i)if("number"==typeof i.num)i=i.num;else if("string"==typeof i.num){let r=i.num.toLowerCase();if(/[0-9][nd]$/.test(r)&&(r=r.slice(0,-1)),r=r.replace(/[\u0009-\u000d\u0020\u00a0]/g,""),/\([0-9]+\)$/.test(r)){const[i,t,a]=null!==(n=r.match(/(.+)\(([0-9]+)\)$/))&&void 0!==n?n:[];r=t+a.repeat(Math.ceil(e.precision/a.length))}return"nan"===r?e._NAN:"infinity"===r||"+infinity"===r?e._POSITIVE_INFINITY:"-infinity"===r?e._NEGATIVE_INFINITY:"0"===r?e._ZERO:"1"===r?e._ONE:"-1"===r?e._NEGATIVE_ONE:"2"===r?e._TWO:new Hn(e,r,t)}if("number"==typeof i){if(Number.isNaN(i))return e._NAN;if(!Number.isFinite(i)&&i>0&&e._POSITIVE_INFINITY,!Number.isFinite(i)&&i<0&&e._NEGATIVE_INFINITY,-1===i)return e._NEGATIVE_ONE;if(0===i)return e._ZERO;if(1===i)return e._ONE;if(2===i)return e._TWO}return"number"==typeof i?new Hn(e,i,t):null}function Yn(e,i){if(null===i)return e.error("missing");if("object"==typeof i&&i instanceof Qt)return i;if("string"==typeof(i=Ii(i)))return Un(e,i);if(Array.isArray(i)){const t=i.map((i=>Yn(e,i)));return new Rn(e,t[0],t.slice(1))}if("object"==typeof i){if("dict"in i)return new Tn(e,i.dict);if("fn"in i)return Yn(e,i.fn);if("str"in i)return new Wn(e,i.str);if("sym"in i)return Un(e,i.sym);if("num"in i)return Un(e,i.num)}return Un(e,i)}function Kn(e,i,t,n){var r,a,s,o;if("Hold"===i){const i=new Rn(e,"Hold",[Yn(e,t[0])],{metadata:n});return i.isCanonical=!0,i}if("Domain"===i)return xn(e,t[0],n);if("String"===i)return 0===t.length?new Wn(e,"",n):new Wn(e,t.map((e=>{var i;return null!==(i=Jn(e))&&void 0!==i?i:""})).join(""),n);if("Symbol"===i&&t.length>0)return e.symbol(t.map((e=>{var i;return null!==(i=Jn(e))&&void 0!==i?i:""})).join(""),n);if(("Divide"===i||"Rational"===i)&&2===t.length){if(t[0]instanceof Qt&&t[1]instanceof Qt){if(t[0].isLiteral&&t[1].isLiteral&&t[0].isInteger&&t[1].isInteger){const[i,s]=[null!==(r=t[0].machineValue)&&void 0!==r?r:t[0].asSmallInteger,null!==(a=t[1].machineValue)&&void 0!==a?a:t[1].asSmallInteger];return null!==i&&null!==s?e.number([i,s],n):new Rn(e,"Rational",[t[0],t[1]],{metadata:n})}}else{const i=t[0],r=t[1],[a,s]=[Ut(e,i),Ut(e,r)];if((null==a?void 0:a.isInteger())&&(null==s?void 0:s.isInteger()))return en(a)&&en(s)?e.number([a.toNumber(),s.toNumber()],n):new Rn(e,"Rational",[e.box(i),e.box(r)],{metadata:n})}i="Divide"}if("Number"===i&&1===t.length)return Un(e,t[0]);if("Complex"===i){if(1===t.length){const i=Un(e,t[0]),r=i.asFloat;return null!==r&&0!==r?new Hn(e,e.complex(0,r),n):e.mul([i,e._I])}if(2===t.length){const i=Un(e,t[0]),r=Un(e,t[1]),a=i.asFloat,s=r.asFloat;return null!==s&&null!==a?0===s&&0===a?e._ZERO:null!==s&&0!==s?new Hn(e,e.complex(a,s),n):i:e.add([i,e.mul([r,e._I])],n)}}if("Negate"===i&&1===t.length){if("number"==typeof t[0])return e.number(-t[0],n);if(t[0]instanceof Qt&&t[0].machineValue)return e.number(-t[0].machineValue,n)}if("Single"===i)return t.length<1?e.error("expected-argument","'Single"):t.length>1?e.error("unexpected-argument","'Single"):new Rn(e,"Tuple",[e.box(t[0])],{metadata:n});if("Pair"===i)return t.length<2?e.error("expected-argument","'Pair"):t.length>2?e.error("unexpected-argument","'Pair"):new Rn(e,"Tuple",[e.box(t[0]),e.box(t[1])],{metadata:n});if("KeyValuePair"===i)return t.length<2?e.error("expected-argument","'KeyValuePair"):t.length>2?e.error("unexpected-argument","'KeyValuePair"):new Rn(e,"KeyValuePair",[e.box(t[0]),e.box(t[1])],{metadata:n});if("Triple"===i)return t.length<3?e.error("expected-argument","'Triple"):t.length>3?e.error("unexpected-argument","'Triple"):new Rn(e,"Tuple",t.map((i=>e.box(i))),{metadata:n});if("Dictionary"===i){const i={};for(const n of t){const t=e.box(n),r=t.head;if("KeyValuePair"===r||"Pair"===r||"Tuple"===r&&2===t.nops){const e=t.op1;if(e.isValid&&!e.isNothing){const n=t.op2;let r=null!==(s=e.symbol)&&void 0!==s?s:e.string;if(!r&&e.isLiteral){const i=null!==(o=e.machineValue)&&void 0!==o?o:e.asSmallInteger;i&&Number.isFinite(i)&&Number.isInteger(i)&&(r=i.toString())}r&&(i[r]=n)}}}return new Tn(e,i,n)}return new Rn(e,i,t.map((i=>Un(e,i))),{metadata:n})}function Jn(e){var i,t;if("string"==typeof e)return e;if(e instanceof Qt)return null!==(t=null!==(i=e.string)&&void 0!==i?i:e.symbol)&&void 0!==t?t:e.toString();if("object"==typeof e){if("str"in e)return e.str;if("fn"in e&&"String"===e.fn[0]&&"string"==typeof e.fn[1])return e.fn[1]}return Array.isArray(e)&&"String"===e[0]&&"string"==typeof e[1]?e[1]:null}function Xn(e,i){if(!e.isLiteral)return null;let t;null!==e.machineValue&&(t=-e.machineValue),e.decimalValue&&(t=e.decimalValue.neg()),e.complexValue&&(t=e.complexValue.neg());const[n,r]=e.rationalValue;return null!==n&&null!==r&&(t=[-n,r]),void 0!==t?e.engine.number(t,i):null}function er(e,i){var t;if("Negate"===e.head)return e.op1;if(e.isLiteral)return Xn(e,i);if("Add"===e.head){let n=e.ops.map((e=>er(e)));return n=null!==(t=tn(n,"Add"))&&void 0!==t?t:n,e.engine.add(n,i)}return e.engine._fn("Negate",[e],i)}function ir(e){var i;if("Negate"===e.head)return e.op1;if(e.isLiteral)return Xn(e);const t=e.engine;if("Add"===e.head){let n=e.ops.map((e=>ir(e)));return n=null!==(i=tn(n,"Add"))&&void 0!==i?i:n,t.add(n)}return"Multiply"===e.head?function(e,i){let t=[],n=!1;for(const e of i)n||"Negate"!==e.head?t.push(e):(n=!0,t.push(e.op1));if(n)return e.mul(t);t=[];for(const e of i)!n&&e.isLiteral&&e.isInteger?(n=!0,t.push(ir(e))):t.push(e);if(n)return e.mul(t);t=[];for(const e of i)!n&&e.isLiteral&&e.isNumber?(n=!0,t.push(ir(e))):t.push(e);return n?e.mul(t):e._fn("Negate",[e._fn("Multiply",i)])}(t,e.ops):"Divide"===e.head?t.divide(ir(e.op1),e.op2):t._fn("Negate",[e])}function tr(e,i,t="simplify"){return ir(i)}class nr{constructor(e,i){if(this._literal=[0,1],this._imaginary=0,this._posInfinityCount=0,this._negInfinityCount=0,this._terms=[],this.engine=e,i)for(const e of i)this.addTerm(e)}get isEmpty(){return 0===this._terms.length&&0===this._literal[0]&&0===this._imaginary&&0===this._negInfinityCount&&0===this._posInfinityCount}addTerm(e,i){if(e.isNothing)return;if(void 0===i&&(i=[1,1]),e.isLiteral){if(e.isInfinity)return void(e.isPositive?this._posInfinityCount+=1:this._negInfinityCount+=1);const[t,n]=e.asRational;if(null!==t&&null!==n)return void(this._literal=[i[0]*(this._literal[0]*n+t*this._literal[1]),i[1]*n*this._literal[1]]);if(e.complexValue){let t=e.complexValue.re,n=e.complexValue.im;if(Number.isInteger(t)&&Math.abs(t)<=At&&(this._literal[0]+=this._literal[1]*t*i[0]/i[1],t=0),Number.isInteger(n)&&Math.abs(n)<=At&&(this._imaginary+=n*i[0]/i[1],n=0),0===t&&0===n)return;e=this.engine.number(this.engine.complex(t,n)).canonical}}let t;if([t,e]=un(e),0===t[0])return;if(t=[t[0]*i[0],t[1]*i[1]],"Add"===e.head){for(const i of e.ops)this.addTerm(i,t);return}let n=!1;if(!e.isLiteral)if(this._terms.length>500){const i=e.hash;for(let r=0;r<this._terms.length;r++)if(!this._terms[r].term.isLiteral&&i===this._terms[r].term.hash&&e.isSame(this._terms[r].term)){const[e,i]=this._terms[r].coef,[a,s]=t;this._terms[r].coef=[e*s+i*a,i*s],n=!0;break}}else for(let i=0;i<this._terms.length;i++)if(!this._terms[i].term.isLiteral&&e.isSame(this._terms[i].term)){const[e,r]=this._terms[i].coef,[a,s]=t;this._terms[i].coef=[e*s+r*a,r*s],n=!0;break}n||this._terms.push({term:e,coef:t})}terms(){var e;const i=this.engine;if(this._posInfinityCount>0&&this._negInfinityCount>0)return[i._NAN];if(this._posInfinityCount>0)return[i._POSITIVE_INFINITY];if(this._negInfinityCount>0)return[i._NEGATIVE_INFINITY];if(0===this._terms.length)return 0===this._literal[0]&&0===this._imaginary?[]:0===this._imaginary?[i.number(this._literal).canonical]:0===this._literal[0]?[i.number(i.complex(0,this._imaginary)).canonical]:[i.number(this._literal).canonical,i.number(i.complex(0,this._imaginary)).canonical];const t=[];for(const{coef:[e,n],term:r}of this._terms)0!==e&&(e===n?t.push(r):e===-n?t.push(i.negate(r)):1===n?t.push(i.mul([i.number(e).canonical,r])):1===e?t.push(i.divide(r,i.number(n).canonical)):0!==e&&t.push(i.mul([i.number([e,n]).canonical,r])));return 0!==this._literal[0]&&t.push(i.number(this._literal).canonical),0!==this._imaginary&&t.push(i.number(i.complex(0,this._imaginary)).canonical),null!==(e=tn(t,"Add"))&&void 0!==e?e:t}asExpression(){const e=this.engine,i=this.terms();return 0===i.length?e._ZERO:1===i.length?i[0]:e._fn("Add",function(e,i){return i.sort(((e,i)=>{const t=an(e),n=an(i);if(t<n)return-1;if(t>n)return 1;const r=nn(e),a=nn(i);if(r!==a)return a-r;const s=rn(e),o=rn(i);return s!==o?s-o:on(e,i)}))}(0,i))}}function rr(e,i){var t;if(0===(i=(i=null!==(t=tn(i,"Add"))&&void 0!==t?t:i).filter((e=>!(e.isLiteral&&e.isZero)))).length)return e.number(0);if(1===i.length)return i[0];if(2===i.length){let t=0,n=0;if(i[0].isLiteral&&(n=i[0].machineValue,null===n&&i[0].decimalValue&&(n=i[0].asFloat)),null!==n&&0!==n?t=$t(i[1]):(t=$t(i[0]),0!==t&&(n=i[1].machineValue,null===n&&i[1].decimalValue&&(n=i[1].asFloat))),null!==n&&null!==t&&0!==t)return e.number(e.complex(n,t))}return e._fn("Add",i)}function ar(e,i,t="eval"){var n,r;for(const t of i){if(t.isImaginary&&t.isInfinity)return e.symbol("ComplexInfinity");if(t.isNaN||"Undefined"===t.symbol)return e._NAN}const a=new nr(e);let[s,o]=[0,1],[l,u]=[e._DECIMAL_ZERO,e._DECIMAL_ONE],c=0,h=0,m=e._DECIMAL_ZERO,d=Be.exports.Complex.ZERO;for(const t of i)if(!t.isNothing&&!t.isZero)if(t.isLiteral){const[i,n]=t.rationalValue;null!==i&&null!==n?[s,o]=Tt([s*n+o*i,o*n]):null!==t.decimalValue?t.decimalValue.isInteger()?l=l.add(u.mul(t.decimalValue)):m=m.add(t.decimalValue):null!==t.machineValue?Gt(e)?Number.isInteger(t.machineValue)?l=l.add(u.mul(t.machineValue)):m=m.add(t.machineValue):Number.isInteger(t.machineValue)?h+=t.machineValue:c+=t.machineValue:null!==t.complexValue?d=d.add(t.complexValue):a.addTerm(t)}else if("Rational"===t.head&&2===t.nops){const[e,i]=[null!==(n=t.op1.decimalValue)&&void 0!==n?n:t.op1.machineValue,null!==(r=t.op2.decimalValue)&&void 0!==r?r:t.op1.machineValue];null!==e&&null!==i?(l=l.mul(i).add(u.mul(e)),u=u.mul(i)):a.addTerm(t)}else a.addTerm(t);if(!Ht(e)&&0!==d.im)return e._NAN;if(Gt(e)||0!==e.chop(m)||!l.isZero()){let i=m;if(0!==c&&(i=i.add(c)),0!==d.re&&(i=i.add(d.re)),l=l.add(u.mul(h)),l=l.mul(o).add(u.mul(s)),u=u.mul(o),[l,u]=Yt([l,u]),u.eq(1)?i=i.add(l):"N"===t?i=i.add(l.div(u)):a.addTerm(e.box(["Rational",e.number(l),e.number(u)]).canonical),0!==d.im)if(en(i)){const t=e.number(e.complex(i.toNumber(),d.im));if(a.isEmpty)return t;a.addTerm(t)}else a.addTerm(e.number(e.complex(0,d.im))),a.addTerm(e.number(i));else{if(a.isEmpty)return e.number(i);a.addTerm(e.number(i))}return a.asExpression()}if("N"===t||1===o){const i=c+h+d.re+s/o,t=e.number(0===d.im?i:e.complex(i,d.im));if(a.isEmpty)return t;a.addTerm(t)}else{0!==s?1===o?c+=h+s:([s,o]=Tt([s+o*h,o]),a.addTerm(e.number([s,o]))):c+=h;const i=c+d.re,t=e.number(0===d.im?i:e.complex(i,d.im));if(a.isEmpty)return t;a.addTerm(t)}return a.asExpression()}function sr(e,i,t,n){var r,a,s;if("Lambda"!==i.head)return;const o=i.op1;let l=1,u=Mt;if("Tuple"!==t.head&&"Triple"!==t.head&&"Pair"!==t.head&&"Single"!==t.head||(l=null!==(r=t.op2.asSmallInteger)&&void 0!==r?r:1,u=null!==(a=t.op3.asSmallInteger)&&void 0!==a?a:Mt),l>=u||u-l>=200)return;if("evaluate"===n||"simplify"===n){const i=[];for(let t=l;t<=u;t++){const n=e.number(t);i.push(o.subs({_1:n,_:n}))}return"simplify"===n?e.add(i).simplify():e.add(i).evaluate()}if(Gt(e)){let i=e.decimal(0);for(let t=l;t<=u;t++){const n=e.number(t),r=o.subs({_1:n,_:n}).evaluate(),a=null!==(s=r.decimalValue)&&void 0!==s?s:r.asFloat;if(!a)return;i=i.add(a)}}let c=0;for(let i=l;i<=u;i++){const t=e.number(i),n=o.subs({_1:t,_:t}).evaluate();if(!n.asFloat)return;c+=n.asFloat}return e.number(c)}function or(e,i,t,n){var r,a;if("ComplexInfinity"===t.symbol)return e._NAN;if(t.isLiteral){if(t.isZero)return e._ONE;if(i.isLiteral){const s=null!==(r=i.machineValue)&&void 0!==r?r:i.asFloat;if(1===s)return e._ONE;if(0===s){if(t.isPositive)return e._ZERO;if(t.isNegative)return e._COMPLEX_INFINITY}if(t.isOne)return i;if(t.isNegativeOne){if(1===s)return e._ONE;if(-1===s)return e._NEGATIVE_ONE;if(i.isInfinity)return e._ZERO;const[t,r]=i.rationalValue;if(null!==t&&null!==r)return e.number([r,t],n);const o=i.asFloat;if(null!==o&&Number.isInteger(o))return e.number([1,o],n);if(null===(a=i.decimalValue)||void 0===a?void 0:a.isInteger())en(i.decimalValue)?e.number([1,i.decimalValue.toNumber()],n):e._fn("Rational",[e._ONE,i],n);else if(null!==s&&Number.isInteger(s)&&!i.decimalValue)return e.number([1,s],n);return e._fn("Power",[i,e._NEGATIVE_ONE],n)}const o=t.asFloat;if(.5===o||-.5===o){const t=i.asSmallInteger;if(null!==t&&t>0){const[i,n]=Ot(t,2);if(1===n&&1===i)return e._ONE;if(1!==i)return 1===n?e.number(o>=0?i:[1,i]):e.mul([e.number(i),e.power(e.number(n),e._HALF)])}return o>0?e._fn("Power",[i,e._HALF],n):e._fn("Power",[i,e.number([-1,2])],n)}if(i.isInfinity){if(t.complexValue){const i=t.complexValue.re;if(0===i)return e._NAN;if(i<0)return e._ZERO;if(i>0)return e._COMPLEX_INFINITY}if(i.isNegative){if(t.isInfinity)return e._NAN}else if(i.isPositive){if(t.isNegativeOne)return e._ZERO;if(t.isInfinity)return t.isNegative?e._ZERO:e._POSITIVE_INFINITY}}if(t.isInfinity&&(i.isOne||i.isNegativeOne))return e._NAN;const[l,u]=i.asRational;if(null!==l&&null!==u){const i=t.asSmallInteger;if(null!==i)return-1===i?e.number([u,l]):i>0?e.number([Math.pow(l,i),Math.pow(u,i)]):e.number([Math.pow(u,-i),Math.pow(l,-i)])}}}if("Power"===i.head&&i.op1.isReal){const n=t.asSmallInteger;if(null!==n){const t=i.op2.asSmallInteger;if(null!==t)return e._fn("Power",[i.op1,e.number(n*t)])}if(i.op1.isNonNegative){const[n,r]=t.asRational;if(null!==n&&null!==r){const[t,a]=i.op2.asRational;if(null!==t&&null!==a)return e._fn("Power",[i.op1,e.number([n*t,r*a])])}}}return"Multiply"===i.head&&null!==t.asSmallInteger?e._fn("Multiply",i.ops.map((i=>e.power(i,t)))):null}function lr(e,i){if(i.machineValue)return e.number(Math.pow(i.machineValue,2));if(i.decimalValue)return e.number(i.decimalValue.pow(2));if(i.complexValue)return e.number(i.complexValue.pow(2));const[t,n]=i.rationalValue;if(null!==t&&null!==n)return e.number([Math.pow(n,2),Math.pow(t,2)]);if("Multiply"===i.head)return e._fn("Multiply",i.ops.map((i=>lr(e,i))));if("Power"===i.head){const t=i.op2.asSmallInteger;return null!==t?e._fn("Power",[i.op1,e.number(2*t)]):e._fn("Power",[i.op1,e.mul([e._TWO,i.op2])])}return e._fn("Power",[i,e._TWO])}function ur(e,i,t,n){var r,a,s,o,l,u,c,h,m;if("simplify"!==n&&i.isLiteral&&t.isLiteral&&("N"===n||!i.isInteger)){if(i.complexValue)return e.number(i.complexValue.pow(null!==(a=null!==(r=t.complexValue)&&void 0!==r?r:t.asFloat)&&void 0!==a?a:NaN));if(t.complexValue){const n=null!==(l=null!==(s=i.asFloat)&&void 0!==s?s:null===(o=i.decimalValue)||void 0===o?void 0:o.toNumber())&&void 0!==l?l:null;if(null!==n)return e.number(e.complex(n).pow(t.complexValue))}return i.decimalValue?e.number(i.decimalValue.pow(null!==(u=t.decimalValue)&&void 0!==u?u:t.asFloat)):null!==i.asFloat&&(t.decimalValue||Gt(e))?e.number(e.decimal(i.asFloat).pow(null!==(c=t.decimalValue)&&void 0!==c?c:t.asFloat)):e.number(Math.pow(null!==(h=i.asFloat)&&void 0!==h?h:NaN,null!==(m=t.asFloat)&&void 0!==m?m:NaN))}if(i.isLiteral&&null!==i.asSmallInteger){const[n,r]=t.rationalValue;if(!(1!==n&&-1!==n||2!==r&&3!==r)){const[a,s]=Ot(i.asSmallInteger,r);if(1===s&&1===a)return e._ONE;if(1===a)return;return 1===s?e.number(n>=0?a:[1,a]):e.mul([e.number(a),e.power(e.number(s),t)])}}if("Power"===i.head&&-1===i.op2.asSmallInteger&&-1===t.asSmallInteger)return i.op1}function cr(e,i){var t;return 0===(i=null!==(t=tn(i,"Multiply"))&&void 0!==t?t:i).length?e.number(1):1===i.length?i[0]:2===i.length?mr(i[0],i[1]):new hn(e,i).asExpression()}function hr(e,i,t="evaluate"){for(const t of i)if(t.isNaN||"Undefined"===t.symbol)return e._NAN;let[n,r]=[1,1],[a,s]=[e._DECIMAL_ONE,e._DECIMAL_ONE],o=1,l=e._DECIMAL_ONE,u=Be.exports.Complex.ONE;const c=new hn(e);for(const t of i)if(!t.isNothing&&!t.isOne)if(t.isLiteral){const[i,h]=t.rationalValue;null!==i&&null!==h?Gt(e)?[a,s]=Yt([a.mul(i),s.mul(h)]):[n,r]=Tt([n*i,r*h]):null!==t.decimalValue?t.decimalValue.isInteger()?a=a.mul(t.decimalValue):l=l.mul(t.decimalValue):null!==t.machineValue?Gt(e)?Number.isInteger(t.machineValue)?a=a.mul(t.machineValue):l=l.mul(t.machineValue):o*=t.machineValue:null!==t.complexValue?u=u.mul(t.complexValue):c.addTerm(t)}else c.addTerm(t);if(0!==u.im){if(!Ht(e))return e._NAN;o*=l.toNumber(),l=e._DECIMAL_ONE,n*=a.toNumber(),r*=s.toNumber(),a=e._DECIMAL_ONE,s=e._DECIMAL_ONE}if(s.eq(e._DECIMAL_ONE)&&en(a)&&(n=r*a.toNumber(),a=e._DECIMAL_ONE),0!==u.im||!Gt(e)&&l.eq(e._DECIMAL_ONE)&&a.eq(e._DECIMAL_ONE)&&s.eq(e._DECIMAL_ONE)){let i,a=o;if("N"===t?a=a*n/r:c.addTerm(e.number([n,r])),i=1!==u.re||0!==u.im?e.number(u.mul(a)):e.number(a),c.isEmpty)return i;c.addTerm(i)}else{let i=l.mul(o);if("N"===t?(i=i.mul(n).div(r),i=i.mul(a).div(s)):1===r?s.eq(1)?i=i.mul(a).mul(n):c.addTerm(e.box(["Rational",e.number(a.mul(n)),e.number(s)])):(c.addTerm(e.number([n,r])),c.addTerm(e.box(["Rational",e.number(a),e.number(s)]).canonical)),1!==u.re||0!==u.im)if(en(i)){const t=e.number(e.complex(u.mul(i.toNumber())));if(c.isEmpty)return t;c.addTerm(t)}else{if(c.isEmpty)return e._fn("Multiply",[e.number(u),e.number(i)]);c.addTerm(e.number(u)),c.addTerm(e.number(i))}else{if(c.isEmpty)return e.number(i);c.addTerm(e.number(i))}}return c.asExpression()}function mr(e,i,t){const n=e.engine;if(e.isLiteral&&i.isLiteral&&e.isInteger&&i.isInteger){if(e.decimalValue&&i.decimalValue)return n.number(e.decimalValue.mul(i.decimalValue));if(e.machineValue&&i.machineValue)return n.number(e.machineValue*i.machineValue)}if(e.isNothing)return i;if(i.isNothing)return e;if(e.isLiteral&&e.isOne)return i;if(i.isLiteral&&i.isOne)return e;if(e.isLiteral&&e.isNegativeOne)return er(i);if(i.isLiteral&&i.isNegativeOne)return er(e);let r=1,a=e,s=i;if(a.isLiteral&&null!==a.asRational||(s=i,a=e),"Negate"===s.head&&(s=s.op1,r=-r),a.isLiteral){const[e,i]=a.asRational;if(null!==e&&null!==i){if(e===i)return s;if(0===e)return n._ZERO;if("Add"===s.head)return r<0&&(a=er(a)),n.add(s.ops.map((e=>mr(a,e))),t);if(s.isLiteral){const[a,o]=s.asRational;if(null!==a&&null!==o)return n.number(Tt([r*e*a,o*i]),t)}return r<0?n._fn("Multiply",[er(a),s],t):n._fn("Multiply",[a,s],t)}}if(a.hash===s.hash&&a.isSame(s))return lr(n,a);const o=new hn(n,[a,s]);return r>0?o.asExpression():er(o.asExpression(),t)}function dr(e,i,t,n){var r,a,s;if("Lambda"!==i.head)return;const o=i.op1;let l=1,u=Mt;if("Tuple"!==t.head&&"Triple"!==t.head&&"Pair"!==t.head&&"Single"!==t.head||(l=null!==(r=t.op2.asSmallInteger)&&void 0!==r?r:1,u=null!==(a=t.op3.asSmallInteger)&&void 0!==a?a:Mt),l>=u||u-l>=200)return;if("evaluate"===n||"simplify"===n){const i=[];for(let t=l;t<=u;t++){const n=e.number(t);i.push(o.subs({_1:n,_:n}))}return"simplify"===n?e.mul(i).simplify():e.mul(i).evaluate()}if(Gt(e)){let i=e.decimal(1);for(let t=l;t<=u;t++){const n=e.number(t),r=o.subs({_1:n,_:n}).evaluate(),a=null!==(s=r.decimalValue)&&void 0!==s?s:r.asFloat;if(!a)return;i=i.mul(a)}}let c=1;for(let i=l;i<=u;i++){const t=e.number(i),n=o.subs({_1:t,_:t}).evaluate();if(!n.asFloat)return;c*=n.asFloat}return e.number(c)}function fr(e,i,t){if(i.isLiteral&&t.isLiteral){if(i.isOne)return e.inverse(t);if(i.isNegativeOne)return er(e.inverse(t));if(t.isOne)return i;if(t.isNegativeOne)return er(i);const[n,r]=[i.asSmallInteger,t.asSmallInteger];if(null!==n&&null!==r&&0!==r)return e.number(Tt([n,r]));if(i.isInteger&&t.isInteger){let[n,r]=cn(i),[a,s]=cn(t);return s.isOne?n*a<0?er(r):r:n*a>0?e._fn("Rational",[r,s]):e._fn("Rational",[e.negate(r),s])}}if(!("Divide"!==i.head&&"Rational"!==i.head||"Divide"!==t.head&&"Rational"!==t.head))return fr(e,e.mul([i.op1,t.op2]),e.mul([i.op2,t.op1]));if(i.isLiteral){const[n,r]=i.rationalValue;if(null!==n&&null!==r)return fr(e,e.mul([e.number(n),t]),e.number(r))}if(t.isLiteral){const[n,r]=t.rationalValue;if(null!==n&&null!==r)return fr(e,e.mul([i,e.number(r)]),e.number(n))}if("Divide"===i.head||"Rational"===i.head)return fr(e,e.mul([i.op1,t]),i.op2);if("Divide"===t.head||"Rational"===t.head)return fr(e,e.mul([i,t.op2]),t.op1);let[n,r]=cn(i),[a,s]=cn(t);return r=r.canonical,s=s.canonical,s.isLiteral&&s.isOne?n*a<0?er(r):r:(s=e.inverse(s),r.isOne?s:r.isNegativeOne?er(s):n*a>0?e.mul([r,s]):er(e.mul([r,s])))}function gr(e,i,t){var n,r;if(i.isLiteral&&t.isLiteral){const[a,s]=[i.asSmallInteger,t.asSmallInteger];if(null!==a&&null!==s&&0!==s)return e.number(Tt([a,s]));if(i.isInteger&&t.isInteger){let[a,s]=[null!==(n=i.decimalValue)&&void 0!==n?n:i.machineValue?e.decimal(i.machineValue):null,null!==(r=t.decimalValue)&&void 0!==r?r:t.machineValue?e.decimal(t.machineValue):null];if(null!==a&&null!==s)return[a,s]=Yt([a,s]),s.eq(1)?e.number(a):en(a)&&en(s)?e.number([a.toNumber(),s.toNumber()]):e._fn("Rational",[e.number(a),e.number(s)])}}}const pr=[{functions:[{name:"Abs",wikidata:"Q3317982",threadable:!0,idempotent:!0,complexity:1200,signature:{domain:["Function","ExtendedRealNumber","NonNegativeNumber"],simplify:(e,i)=>vr(e,i[0],"simplify"),evaluate:(e,i)=>vr(e,i[0],"evaluate"),N:(e,i)=>vr(e,i[0],"N")}},{name:"Add",wikidata:"Q32043",associative:!0,commutative:!0,threadable:!0,idempotent:!0,complexity:1300,signature:{domain:"NumericFunction",codomain:(e,i)=>function(e,i){let t=null;for(const e of i){if(!e.isNumeric)return null;t=t?kn(t,e):e}return t}(0,i),canonical:(e,i)=>rr(e,i),simplify:(e,i)=>function(e,i){const t=new nr(e);for(const n of i){if(n.isImaginary&&n.isInfinity)return e.symbol("ComplexInfinity");if(n.isNaN||"Undefined"===n.symbol)return e._NAN;n.isZero||t.addTerm(n)}return t.asExpression()}(e,i),evaluate:(e,i)=>ar(e,i),N:(e,i)=>ar(e,i,"N")}},{name:"Ceil",description:"Rounds a number up to the next largest integer",complexity:1250,signature:{domain:["Function","Number","Integer"],evaluate:(e,i)=>{const t=i[0];return t.decimalValue?e.number(t.decimalValue.ceil()):t.complexValue?e.number(t.complexValue.ceil(0)):null!==t.asFloat?e.number(Math.ceil(t.asFloat)):void 0}}},{name:"Chop",associative:!0,threadable:!0,idempotent:!0,complexity:1200,signature:{domain:["Function","Number","Number"],evaluate:(e,i)=>{const t=i[0];return t.decimalValue?e.number(e.chop(t.decimalValue)):t.complexValue?e.number(e.chop(t.complexValue)):null!==t.asFloat?e.number(e.chop(t.asFloat)):void 0}}},{name:"Complex",wikidata:"Q11567",complexity:500},{name:"Divide",wikidata:"Q1226939",complexity:2500,signature:{domain:["Function","Number","Number","Number"],canonical:(e,i)=>fr(e,i[0],i[1]),simplify:(e,i)=>gr(e,i[0],i[1])}},{name:"Exp",wikidata:"Q168698",threadable:!0,complexity:3500,signature:{domain:["Function","Number","Number"],canonical:(e,i)=>e.power(e.symbol("ExponentialE"),i[0])}},{name:"Erf",description:"Complementary Error Function",complexity:7500},{name:"Erfc",description:"Complementary Error Function",complexity:7500},{name:"Factorial",description:"The factorial function",wikidata:"Q120976",complexity:9e3,signature:{domain:["Function","Number","Number"],evaluate:(e,i)=>{const t=i[0].asSmallInteger;return null!==t&&t>=0?Gt(e)?e.number(Kt(e,e.decimal(t))):e.number(function(e){if(!Number.isInteger(e)||e<0)return NaN;let i=1;for(let t=2;t<=e;t++)i*=t;return i}(t)):i[0].complexValue?e.number(i[0].complexValue.add(1)):null!==i[0].asFloat?e.number(Pt(1+i[0].asFloat)):void 0}}},{name:"Floor",wikidata:"Q56860783",complexity:1250,signature:{domain:["Function","ExtendedRealNumber","ExtendedRealNumber"],evaluate:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.floor()):i[0].complexValue?e.number(i[0].complexValue.floor(0)):null!==i[0].asFloat?e.number(Math.floor(i[0].asFloat)):void 0}},{name:"Gamma",wikidata:"Q190573",complexity:8e3,signature:{domain:["Function","Number","Number","Number"],N:(e,i)=>i[0].decimalValue?e.number(Xt(e,i[0].decimalValue)):i[0].complexValue?e.number(i[0].complexValue):null!==i[0].asFloat?e.number(Pt(i[0].asFloat)):void 0}},{name:"LogGamma",complexity:8e3,signature:{domain:["Function","Number","Number","Number"],N:(e,i)=>i[0].decimalValue?e.number(Jt(e,i[0].decimalValue)):i[0].complexValue?e.number(i[0].complexValue):null!==i[0].asFloat?e.number(Dt(i[0].asFloat)):void 0}},{name:"Ln",description:"Natural Logarithm",wikidata:"Q204037",complexity:4e3,signature:{domain:["Function","Number","Number"],N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.log()):i[0].complexValue?e.number(i[0].complexValue.log()):null!==i[0].asFloat?e.number(Math.log(i[0].asFloat)):void 0}},{name:"Log",description:"Log(z, b = 10) = Logarithm of base b",wikidata:"Q11197",complexity:4100,signature:{domain:["Function","Number",["Maybe","Number"],"Number"],N:(e,i)=>{var t,n,r,a,s,o,l,u;const c=i[0],h=null!==(t=i[1])&&void 0!==t?t:e.number(10);if(c.decimalValue){const i=null!==(r=null===(n=h.decimalValue)||void 0===n?void 0:n.log())&&void 0!==r?r:e.decimal(null!==(a=h.asFloat)&&void 0!==a?a:NaN).log();return e.number(c.decimalValue.log().div(i))}if(c.complexValue){const i=null!==(o=null===(s=h.complexValue)||void 0===s?void 0:s.log())&&void 0!==o?o:e.complex(null!==(l=h.asFloat)&&void 0!==l?l:NaN).log();return e.number(c.complexValue.log().div(i))}if(null!==c.asFloat)return e.number(Math.log(c.asFloat)/Math.log(null!==(u=h.asFloat)&&void 0!==u?u:NaN))}}},{name:"Lb",description:"Base-2 Logarithm",wikidata:"Q581168",complexity:4100,signature:{domain:["Function","Number","Number"],N:(e,i)=>{const t=i[0];return t.decimalValue?e.number(t.decimalValue.log().div(e._DECIMAL_TWO)):t.complexValue?e.number(t.complexValue.log().div(e.complex(2))):null!==t.asFloat?e.number(Math.log2(t.asFloat)):void 0}}},{name:"Lg",description:"Base-10 Logarithm",wikidata:"Q966582",complexity:4100,signature:{domain:["Function","Number","Number"],N:(e,i)=>{const t=i[0];return t.decimalValue?e.number(t.decimalValue.log().div(e.decimal(10))):t.complexValue?e.number(t.complexValue.log().div(e.complex(10))):null!==t.asFloat?e.number(Math.log10(t.asFloat)):void 0}}},{name:"Max",description:"Maximum of two or more numbers",complexity:1200,signature:{domain:["Function",["Sequence","Number"],"Number"],simplify:(e,i)=>0===i.length?e._NEGATIVE_INFINITY:1===i.length?i[0]:e.box(["Max",...i]),evaluate:(e,i)=>{if(0===i.length)return e._NEGATIVE_INFINITY;let t;const n=[];for(const e of i)e.isNumber&&void 0!==e.numericValue?t&&!e.isGreater(t)||(t=e):n.push(e);return n.length>0?e.box(t?["Max",t,...n]:["Max",...n]):null!=t?t:e._NAN}}},{name:"Min",description:"Minimum of two or more numbers",complexity:1200,signature:{domain:["Function",["Sequence","Number"],"Number"],simplify:(e,i)=>0===i.length?e._NEGATIVE_INFINITY:1===i.length?i[0]:e.box(["Min",...i]),evaluate:(e,i)=>{if(0===i.length)return e._NEGATIVE_INFINITY;let t;const n=[];for(const e of i)e.isNumber&&void 0!==e.numericValue?t&&!e.isLess(t)||(t=e):n.push(e);return n.length>0?e.box(t?["Min",t,...n]:["Min",...n]):null!=t?t:e._NAN}}},{name:"Multiply",wikidata:"Q40276",associative:!0,commutative:!0,idempotent:!0,complexity:2100,signature:{domain:"NumericFunction",canonical:(e,i)=>cr(e,i),simplify:(e,i)=>function(e,i){const t=new hn(e);for(const n of i){if(n.isNaN||"Undefined"===n.symbol)return e._NAN;t.addTerm(n)}return t.asExpression()}(e,i),evaluate:(e,i)=>hr(e,i),N:(e,i)=>hr(e,i,"N")}},{name:"Negate",description:"Additive Inverse",wikidata:"Q715358",complexity:2e3,signature:{domain:["Function","Number","Number"],codomain:(e,i)=>{if(!i[0].literal)return i[0];const t={PositiveNumber:"NegativeNumber",NonNegativeNumber:"NonPositiveNumber",NonPositiveNumber:"NonNegativeNumber",NegativeNumber:"PositiveNumber",PositiveInteger:"NegativeInteger",NonNegativeInteger:"NonPositiveInteger",NonPositiveInteger:"NonNegativeInteger",NegativeInteger:"PositiveInteger"}[i[0].literal];return t?e.domain(t):i[0]},canonical:(e,i)=>er(i[0]),simplify:(e,i)=>tr(0,i[0],"simplify"),evaluate:(e,i)=>tr(0,i[0],"evaluate"),N:(e,i)=>tr(0,i[0],"N"),sgn:(e,i)=>{const t=i[0];return t.isZero?0:t.isPositive?-1:t.isNegative?1:void 0}}},{name:"Power",wikidata:"Q33456",commutative:!1,complexity:3500,signature:{domain:["Function","Number","Number","Number"],canonical:(e,i)=>{var t;return null!==(t=or(e,i[0],i[1]))&&void 0!==t?t:e._fn("Power",i)},simplify:(e,i)=>ur(e,i[0],i[1],"simplify"),evaluate:(e,i)=>ur(e,i[0],i[1],"evaluate"),N:(e,i)=>ur(e,i[0],i[1],"N")}},{name:"Product",wikidata:"Q901718",complexity:1e3,hold:"first",signature:{domain:["Function","Anything","Tuple","Number"],canonical:(e,i)=>function(e,i,t){var n,r,a,s,o,l;let u,c=null,h=null,m=null;return t&&"Tuple"!==t.head&&"Triple"!==t.head&&"Pair"!==t.head&&"Single"!==t.head?c=t:t&&(c=null!==(r=null===(n=t.ops)||void 0===n?void 0:n[0])&&void 0!==r?r:null,h=null!==(s=null===(a=t.ops)||void 0===a?void 0:a[1])&&void 0!==s?s:null,m=null!==(l=null===(o=t.ops)||void 0===o?void 0:o[2])&&void 0!==l?l:null),u=null!==c&&c.symbol?"Lambda"===i.head?i.op1:i.subs({[c.symbol]:"_"}):"Lambda"===i.head?i.op1:i,null!=c||(c=e.symbol("Nothing")),t=m?e.tuple([c,null!=h?h:e.symbol("Nothing"),m]):h&&m?e.tuple([c,h,m]):h?e.tuple([c,h]):c,e._fn("Product",[e._fn("Lambda",[u]),t])}(e,i[0],i[1]),simplify:(e,i)=>dr(e,i[0],i[1],"simplify"),evaluate:(e,i)=>dr(e,i[0],i[1],"evaluate"),N:(e,i)=>dr(e,i[0],i[1],"N")}},{name:"Rational",complexity:2400,signature:{domain:["Function","RealNumber",["Maybe","Integer"],"RationalNumber"],canonical:(e,i)=>2===i.length?fr(e,i[0],i[1]):e._fn("Rational",i),simplify:(e,i)=>{if(2===i.length)return gr(e,i[0],i[1])},evaluate:(e,i)=>{var t;if(2===i.length){const[t,n]=[i[0].asSmallInteger,i[1].asSmallInteger];return null!==t&&null!==n?e.number([t,n]):void 0}const n=null!==(t=i[0].N().asFloat)&&void 0!==t?t:null;if(null===n)return;const r=function(e){if(!Number.isFinite(e))return e;if(0==e%1)return e;let i=Math.floor(e),t=1,n=0,r=i,a=1;for(;e-i>1e-15*a*a;){i=Math.floor(e=1/(e-i));const s=t;t=r;const o=n;n=a,r=s+i*t,a=o+i*n}return[r,a]}(n);return"number"==typeof r?e.number(r):e.number([r[0],r[1]])},N:(e,i)=>{var t,n;if(2===i.length){const[r,a]=[i[0].machineValue,i[1].machineValue];if(null!==r&&null!==a)return e.number(r/a);const[s,o]=[null!==(t=i[0].decimalValue)&&void 0!==t?t:i[0].asFloat?e.decimal(i[0].asFloat):null,null!==(n=i[1].decimalValue)&&void 0!==n?n:i[1].asFloat?e.decimal(i[1].asFloat):null];if(null!==s&&null!==o)return e.number(s.div(o))}}}},{name:"Root",complexity:3200,signature:{domain:["Function","Number","RationalNumber","Number"],canonical:(e,i)=>{var t;const n=e.inverse(i[1]);return null!==(t=or(e,i[0],n))&&void 0!==t?t:e._fn("Power",[i[0],n])},N:(e,i)=>{var t,n,r;const a=i[0],s=i[1];if(a.decimalValue)return e.number(a.decimalValue.pow(e._DECIMAL_ONE.div(null!==(t=s.asFloat)&&void 0!==t?t:NaN)));if(a.complexValue){const i=s.complexValue?Be.exports.Complex.ONE.div(s.complexValue):e.complex(1/(null!==(n=s.asFloat)&&void 0!==n?n:NaN));return e.number(a.complexValue.pow(i))}return null!==a.asFloat?e.number(Math.pow(a.asFloat,null!==(r=s.asFloat)&&void 0!==r?r:NaN)):void 0}}},{name:"Round",complexity:1250,signature:{domain:["Function","Number","Number"],evaluate:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.round()):i[0].complexValue?e.number(i[0].complexValue.round(0)):null!==i[0].asFloat?e.number(Math.round(i[0].asFloat)):void 0}},{name:"Sign",complexity:1200,signature:{domain:["Function","Number",["Range",-1,1]],simplify:(e,i)=>{const t=i[0].sgn;return 0===t?e._ZERO:1===t?e._ONE:-1===t?e._NEGATIVE_ONE:void 0},evaluate:(e,i)=>{const t=i[0].sgn;return 0===t?e._ZERO:1===t?e._ONE:-1===t?e._NEGATIVE_ONE:void 0},N:(e,i)=>{const t=i[0].sgn;return 0===t?e._ZERO:1===t?e._ONE:-1===t?e._NEGATIVE_ONE:void 0}}},{name:"SignGamma",description:"The sign of the gamma function: -1 or +1",complexity:7900},{name:"Sqrt",description:"Square Root",wikidata:"Q134237",complexity:3e3,signature:{domain:["Function","Number","Number"],canonical:(e,i)=>{var t;return null!==(t=or(e,i[0],e._HALF))&&void 0!==t?t:e._fn("Power",[i[0],e._HALF])},simplify:(e,i)=>br(e,i[0],"simplify"),evaluate:(e,i)=>br(e,i[0],"evaluate"),N:(e,i)=>br(e,i[0],"N")}},{name:"Square",wikidata:"Q3075175",complexity:3100,signature:{domain:["Function","Number","Number"],canonical:(e,i)=>{var t;return null!==(t=or(e,i[0],e._TWO))&&void 0!==t?t:e._fn("Power",[i[0],e._TWO])},evaluate:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.mul(i[0].decimalValue)):i[0].complexValue?e.number(i[0].complexValue.mul(i[0].complexValue)):null!==i[0].asFloat?e.number(i[0].asFloat*i[0].asFloat):void 0}},{name:"Subscript",hold:"last",signature:{domain:["Function","Anything","Anything","Anything"],codomain:(e,i)=>(i[0].isFunction,i[0]),canonical:(e,i)=>{var t,n;const r=i[0],a=i[1];if(r.string&&a.isLiteral&&null!==a.asSmallInteger){const i=a.asSmallInteger;if(i>1&&i<=36){const[t,n]=Lt(r.string,i);return n?e.error(["unexpected-digit",n[0]],["Latex",e.string(r.string)]):e.number(t)}}if(r.symbol){if(null===(t=r.symbolDefinition)||void 0===t?void 0:t.at)return e._fn("At",[r,a]);let i=null!==(n=a.string)&&void 0!==n?n:a.symbol;if(!i&&a.isLiteral&&null!==a.asSmallInteger&&(i=a.asSmallInteger.toString()),i)return e.symbol(r.symbol+"_"+i)}return e._fn("Subscript",i)}}},{name:"Subtract",wikidata:"Q40754",complexity:1350,signature:{domain:["Function","Number",["Maybe","Number"],"Number"],canonical:(e,i)=>1===i.length?er(i[0]):rr(e,[i[0],er(i[1])]),evaluate:(e,i)=>{var t,n,r,a,s,o;const l=i[0],u=i[1];return l.complexValue||u.complexValue?e.number(e.complex(null!==(t=l.complexValue)&&void 0!==t?t:l.asFloat).sub(null!==(n=u.complexValue)&&void 0!==n?n:u.asFloat)):l.decimalValue||u.decimalValue?e.number(e.decimal(null!==(a=null!==(r=l.decimalValue)&&void 0!==r?r:l.asFloat)&&void 0!==a?a:NaN).sub(null!==(o=null!==(s=u.decimalValue)&&void 0!==s?s:u.asFloat)&&void 0!==o?o:NaN)):null!==l.asFloat&&null!==u.asFloat?e.number(l.asFloat-u.asFloat):void 0}}},{name:"Sum",wikidata:"Q218005",complexity:1e3,hold:"first",signature:{domain:["Function","Anything","Tuple","Number"],canonical:(e,i)=>function(e,i,t){var n,r,a,s,o,l;let u,c=null,h=null,m=null;return t&&"Tuple"!==t.head&&"Triple"!==t.head&&"Pair"!==t.head&&"Single"!==t.head?c=t:t&&(c=null!==(r=null===(n=t.ops)||void 0===n?void 0:n[0])&&void 0!==r?r:null,h=null!==(s=null===(a=t.ops)||void 0===a?void 0:a[1])&&void 0!==s?s:null,m=null!==(l=null===(o=t.ops)||void 0===o?void 0:o[2])&&void 0!==l?l:null),u=null!==c&&c.symbol?"Lambda"===i.head?i.op1:i.subs({[c.symbol]:"_"}):"Lambda"===i.head?i.op1:i,null!=c||(c=e.symbol("Nothing")),t=m?e.tuple([c,null!=h?h:e.symbol("Nothing"),m]):h&&m?e.tuple([c,h,m]):h?e.tuple([c,h]):c,e._fn("Sum",[e._fn("Lambda",[u]),t])}(e,i[0],i[1]),simplify:(e,i)=>sr(e,i[0],i[1],"simplify"),evaluate:(e,i)=>sr(e,i[0],i[1],"evaluate"),N:(e,i)=>sr(e,i[0],i[1],"N")}}]},{symbols:[{name:"MachineEpsilon",domain:"RealNumber",constant:!0,real:!0,value:{num:Number.EPSILON.toString()}},{name:"Half",constant:!0,hold:!1,value:["Rational",1,2]},{name:"ImaginaryUnit",domain:"ImaginaryNumber",constant:!0,hold:!0,wikidata:"Q193796",imaginary:!0,value:["Complex",0,1]},{name:"ExponentialE",domain:"TranscendentalNumber",algebraic:!1,wikidata:"Q82435",constant:!0,hold:!0,real:!0,value:e=>Gt(e)?e._DECIMAL_ONE.exp():Math.exp(1)},{name:"GoldenRatio",domain:"AlgebraicNumber",wikidata:"Q41690",constant:!0,algebraic:!0,hold:!1,value:["Divide",["Add",1,["Sqrt",5]],2]},{name:"CatalanConstant",domain:"RealNumber",algebraic:void 0,wikidata:"Q855282",constant:!0,value:{num:"0.91596559417721901505460351493238411077414937428167\n 21342664981196217630197762547694793565129261151062\n 48574422619196199579035898803325859059431594737481\n 15840699533202877331946051903872747816408786590902\n 47064841521630002287276409423882599577415088163974\n 70252482011560707644883807873370489900864775113225\n 99713434074854075532307685653357680958352602193823\n 23950800720680355761048235733942319149829836189977\n 06903640418086217941101917532743149978233976105512\n 24779530324875371878665828082360570225594194818097\n 53509711315712615804242723636439850017382875977976\n 53068370092980873887495610893659771940968726844441\n 66804621624339864838916280448281506273022742073884\n 31172218272190472255870531908685735423498539498309\n 91911596738846450861515249962423704374517773723517\n 75440708538464401321748392999947572446199754961975\n 87064007474870701490937678873045869979860644874974\n 64387206238513712392736304998503539223928787979063\n 36440323547845358519277777872709060830319943013323\n 16712476158709792455479119092126201854803963934243\n "}},{name:"EulerGamma",domain:"RealNumber",algebraic:void 0,wikidata:"Q273023",constant:!0,value:{num:"0.57721566490153286060651209008240243104215933593992359880576723488486772677766\n 467093694706329174674951463144724980708248096050401448654283622417399764492353\n 625350033374293733773767394279259525824709491600873520394816567085323315177661\n 152862119950150798479374508570574002992135478614669402960432542151905877553526\n 733139925401296742051375413954911168510280798423487758720503843109399736137255\n 306088933126760017247953783675927135157722610273492913940798430103417771778088\n 154957066107501016191663340152278935867965497252036212879226555953669628176388\n 792726801324310104765059637039473949576389065729679296010090151251959509222435\n 014093498712282479497471956469763185066761290638110518241974448678363808617494\n 551698927923018773910729457815543160050021828440960537724342032854783670151773\n 943987003023703395183286900015581939880427074115422278197165230110735658339673"}}]},{functions:[{name:"PreIncrement",signature:{domain:["Function","Number","Number"]}},{name:"PreDecrement",signature:{domain:["Function","Number","Number"]}}]}];function vr(e,i,t){if("simplify"!==t||i.isLiteral){if(null!==i.machineValue)return e.number(Math.abs(i.machineValue));if(i.decimalValue)return e.number(i.decimalValue.abs());if(i.complexValue)return e.number(i.complexValue.abs());const[n,r]=i.rationalValue;if(null===n||null===r)return;return e.number("N"===t?Math.abs(n/r):[Math.abs(n),r])}return i.isNonNegative?i:i.isNegative?e.negate(i):void 0}function br(e,i,t){if(i.isOne)return e._ONE;if(i.isZero)return e._ZERO;if("N"===t||"evaluate"===t&&!i.isInteger)return i.complexValue?e.number(i.complexValue.sqrt()):i.isNonNegative?i.decimalValue?e.number(i.decimalValue.sqrt()):null!==i.asFloat?e.number(Math.sqrt(i.asFloat)):void 0:Ht(e)?e.number(e.complex(i.asFloat).sqrt()):e._NAN;if(null!==i.asSmallInteger){const[t,n]=Ot(i.asSmallInteger,2);if(1===n)return e.number(t);if(1!==t)return this._fn("Multiply",[t,e._fn("Sqrt",[e.box(n).canonical])])}}const yr=[{symbols:[{name:"Nothing",domain:"Nothing"}]},{functions:[{name:"KeyValuePair",description:"A key/value pair",complexity:8200,signature:{domain:["Function","String","Anything",["Tuple","String","Anything"]],codomain:(e,i)=>e.domain(["Tuple","String",i[1]]),canonical:(e,i)=>e.tuple(i)}},{name:"Single",description:"A tuple with a single element",complexity:8200,signature:{domain:["Function","Anything",["Tuple","Anything"]],codomain:(e,i)=>e.domain(["Tuple",i[0]]),canonical:(e,i)=>e.tuple(i)}},{name:"Pair",description:"A tuple of two elements",complexity:8200,signature:{domain:["Function","Anything","Anything",["Tuple","Anything","Anything"]],codomain:(e,i)=>e.domain(["Tuple",i[0],i[1]]),canonical:(e,i)=>e.tuple(i)}},{name:"Triple",description:"A tuple of three elements",complexity:8200,signature:{domain:["Function","Anything","Anything","Anything",["Tuple","Anything","Anything","Anything"]],codomain:(e,i)=>e.domain(["Tuple",i[0],i[1],i[2]]),canonical:(e,i)=>e.tuple(i)}},{name:"Tuple",description:"A fixed number of heterogeneous elements",complexity:8200,signature:{domain:["Function",["Sequence","Anything"],["Tuple",["Sequence","Anything"]]],codomain:(e,i)=>e.domain(["Tuple",...i])}}]},{functions:[{name:"BaseForm",description:"`BaseForm(expr, base=10)`",complexity:9e3,inert:!0,signature:{domain:["Function","Value",["Maybe","Integer"],"Value"],codomain:(e,i)=>i[0]}},{name:"Delimiter",complexity:9e3,hold:"first",signature:{domain:["Function","Anything",["Maybe","String"],["Maybe","String"],"Anything"],codomain:(e,i)=>i[0],canonical:(e,i)=>i[0].canonical}},{name:"Error",complexity:500,inert:!0,signature:{domain:["Function","Anything",["Maybe","Anything"],"Void"]}},{name:"ErrorCode",complexity:500,inert:!0,signature:{domain:["Function","Anything",["Maybe",["Sequence","Anything"]],"Anything"]}},{name:"HorizontalSpacing",signature:{domain:"Function",canonical:(e,i)=>2===i.length?i[0].canonical:e.box(["Sequence"])}},{name:"Style",complexity:9e3,inert:!0,signature:{domain:["Function","Anything",["Maybe","Dictionary"],"Anything"]}}]},{functions:[{name:"Apply",signature:{domain:"Function"}},{name:"About",signature:{domain:"Function"}},{name:"Block",signature:{domain:"Function"}},{name:"Domain",signature:{domain:["Function","Anything","Domain"],canonical:(e,i)=>e.domain(i[0])}},{name:"Evaluate",hold:"all",signature:{domain:["Function","Anything","Anything"],codomain:(e,i)=>i[0],evaluate:(e,i)=>i[0].evaluate()}},{name:"FromDigits",description:"`FromDigits(s, base=10)` return an integer representation of the string `s` in base `base`.",signature:{domain:["Function","String",["Maybe",["Range",1,36]],"Integer"],evaluate:(e,i)=>{const t=i[0];if(!t.string)return e.error(["incompatible-domain","String",t.domain.json],["Latex",t.latex]);const n=i[1];if(n.isNothing)return e.number(Number.parseInt(t.string,10));if(null===n.machineValue)return e.error(["unexpected-base",n.latex],["Latex",n.latex]);const r=n.machineValue;if(r<2||r>36)return e.error(["unexpected-base",r],["Latex",n.latex]);const[a,s]=Lt(t.string,r);return s?e.error(["unexpected-digit",s[0]],["Latex",s]):e.number(a)}}},{name:"Head",signature:{domain:"Function",evaluate:(e,i)=>{const t=i[0];return"string"==typeof t.head?e.symbol(t.head):t.head}}},{name:"Html",signature:{domain:["Function","Value","String"],evaluate:(e,i)=>(i.length,e.string(""))}},{name:"IntegerString",description:"`IntegerString(n, base=10)` return a string representation of the integer `n` in base `base`.",signature:{domain:["Function","Integer",["Maybe","Integer"],"String"],evaluate:(e,i)=>{var t,n,r,a;const s=i[0],o=null!==(r=null!==(t=s.machineValue)&&void 0!==t?t:null===(n=s.decimalValue)||void 0===n?void 0:n.toNumber())&&void 0!==r?r:NaN;if(Number.isNaN(o)||!Number.isInteger(o))return void e.signal(e._fn("IntegerString",i),`Expected first argument as an integer. Got \\(${s.latex}$\\)`);const l=i[1];if(l.isNothing)return s.machineValue?e.string(Math.abs(s.machineValue).toString()):s.decimalValue?e.string(s.decimalValue.abs().toString()):e.string(Math.abs(Math.round(null!==(a=s.asFloat)&&void 0!==a?a:NaN)).toString());if(null===l.asSmallInteger)return void e.signal(e._fn("IntegerString",i),`Expected \`base\` as an integer between 2 and 36. Got \\(${l.latex}$\\)`);const u=l.asSmallInteger;if(!(u<2||u>36))return e.string(Math.abs(o).toString(u));e.signal(e._fn("IntegerString",i),"Expected `base` as an integer between 2 and 36. Got "+u)}}},{name:"Lambda",wikidata:"Q567612",hold:"all",signature:{domain:["Function","Anything","Function"],canonical:(e,i)=>e._fn("Lambda",[i[0].canonical]),evaluate:(e,i)=>{var t;return $n(0,i[0],null!==(t=i[1].ops)&&void 0!==t?t:[]).evaluate()}}},{name:"Latex",inert:!0,signature:{domain:["Function","String","String"]}},{name:"LatexString",hold:"all",signature:{domain:["Function",["Sequence","Anything"],"String"],evaluate:(e,i)=>e.string(Ke(i.map((i=>e.serialize(i)))))}},{name:"LatexTokens",hold:"all",signature:{domain:["Function","Anything",["List","String"]],evaluate:(e,i)=>{var t;if(0===i.length)return e._fn("List",[]);let n="";return n="Latex"===i[0].head?null!==(t=i[0].op1.string)&&void 0!==t?t:"":"LatexString"===i[0].head?i[0].op1.latex:i[0].latex,e._fn("List",Ye(n,[]).map((i=>e.string(i))))}}},{name:"JoinLatexTokens",signature:{domain:["Function",["Sequence","String"],"String"],evaluate:(e,i)=>0===i.length?e.string(""):e.string(Ke(i.map((e=>{var i;return null!==(i=e.string)&&void 0!==i?i:""}))))}},{name:"FromLatex",signature:{domain:["Function","String","Anything"],evaluate:(e,i)=>{var t;return 0===i.length?e.box(["Sequence"]):e.parse(null!==(t=i[0].string)&&void 0!==t?t:"")}}},{name:"Signatures",signature:{domain:["Function","Symbol",["Maybe",["List","Domain"]]],evaluate:(e,i)=>{const t=i[0].symbol;if(!t)return e.symbol("Nothing");const n=e.lookupFunction(t);return n?e.fn("List",[n.signature.domain]):e.symbol("Nothing")}}},{name:"String",threadable:!0,signature:{domain:["Function",["Maybe","Anything"],"String"],evaluate:(e,i)=>0===i.length?e.string(""):e.string(i.map((e=>{var i;return null!==(i=e.string)&&void 0!==i?i:`\\(${e.latex}$\\)`})).join(""))}},{name:"Symbol",complexity:500,description:"Construct a new symbol with a name formed by concatenating the arguments",threadable:!0,hold:"all",signature:{domain:["Function",["Sequence","Anything"],"Anything"],canonical:(e,i)=>{if(0===i.length)return e.symbol("Nothing");const t=i.map((e=>{var i,t,n,r;return null!==(r=null!==(t=null!==(i=e.symbol)&&void 0!==i?i:e.string)&&void 0!==t?t:e.isLiteral?null===(n=e.asSmallInteger)||void 0===n?void 0:n.toString():null)&&void 0!==r?r:""})).join("");return t.length>0?e.symbol(t):e.symbol("Nothing")}}},{name:"SymbolName",signature:{domain:["Function","Anything",["Maybe","String"]],evaluate:(e,i)=>i[0].symbol?e.string(i[0].symbol):e.symbol("Nothing")}},{name:"Tail",signature:{domain:["Function","Value",["List","Value"]],evaluate:(e,i)=>{var t;return e._fn("List",null!==(t=i[0].ops)&&void 0!==t?t:[])}}},{name:"Timing",description:"`Timing(expr)` evaluates `expr` and return a `Pair` of the number of second elapsed for the evaluation, and the value of the evaluation",signature:{domain:["Function","Value",["Maybe","Integer"],["Tuple","Value","Number"]],evaluate:(e,i)=>{var t;if("Nothing"===i[1].symbol){const t=globalThis.performance.now(),n=i[0].evaluate(),r=1e3*(globalThis.performance.now()-t);return e.pair(e.number(r),n)}let n,r=Math.max(3,Math.round(null!==(t=i[1].asSmallInteger)&&void 0!==t?t:3)),a=[];for(;r>0;){const e=globalThis.performance.now();n=i[0].evaluate(),a.push(1e3*(globalThis.performance.now()-e)),r-=1}const s=Math.max(...a),o=Math.min(...a);a=a.filter((e=>e>o&&e<s));const l=a.reduce(((e,i)=>e+i),0);return 0===l?e.pair(e.number(s),n):e.pair(e.number(l/a.length),n)}}}]}],xr={symbols:[{name:"True",wikidata:"Q16751793",domain:"Boolean",constant:!0},{name:"False",wikidata:"Q5432619",domain:"Boolean",constant:!0},{name:"Maybe",wikidata:"Q781546",domain:"MaybeBoolean",constant:!0}],functions:[{name:"And",wikidata:"Q191081",threadable:!0,associative:!0,commutative:!0,idempotent:!0,complexity:1e4,signature:{domain:"LogicOperator",simplify:Nr,evaluate:Nr}},{name:"Or",wikidata:"Q1651704",threadable:!0,associative:!0,commutative:!0,idempotent:!0,complexity:1e4,signature:{domain:"LogicOperator",simplify:_r,evaluate:_r}},{name:"Not",wikidata:"Q190558",involution:!0,complexity:10100,signature:{domain:"LogicOperator",simplify:Sr,evaluate:Sr}},{name:"Equivalent",wikidata:"Q220433",complexity:10200,signature:{domain:"LogicOperator",simplify:wr,evaluate:wr}},{name:"Implies",wikidata:"Q7881229",complexity:10200,signature:{domain:"LogicOperator",simplify:Er,evaluate:Er}},{name:"Exists",signature:{domain:"MaybeBoolean"}},{name:"If",hold:"rest",signature:{domain:"Function",codomain:(e,i)=>e.domain(["Union",i[0],i[1]]),simplify:(e,i)=>{const t=i[0];return t&&"True"===t.symbol?i[1]?i[1].simplify():e.box("Nothing"):i[2]?i[2].simplify():e.box("Nothing")},evaluate:(e,i)=>{const t=i[0];return t&&"True"===t.symbol?i[1]?i[1].evaluate():e.box("Nothing"):i[2]?i[2].evaluate():e.box("Nothing")},N:(e,i)=>{const t=i[0];return t&&"True"===t.symbol?i[1]?i[1].N():e.box("Nothing"):i[2]?i[2].N():e.box("Nothing")}}},{name:"Loop",hold:"all",signature:{domain:"Function",simplify:(e,i)=>{var t,n;return null!==(n=null===(t=i[0])||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box("Nothing")},evaluate:(e,i)=>{var t;const n=null!==(t=i[0])&&void 0!==t?t:e.box("Nothing");if(n.isNothing)return n;let r,a=0;do{r=n.evaluate(),a+=1}while("Return"!==r.head&&a<e.iterationLimit);return"Return"===r.head?r.op1:e.error("iteration-limit-exceeded")},N:(e,i)=>{const t=i[0];return t&&"True"===t.symbol?i[1]?i[1].N():e.box("Nothing"):i[2]?i[2].N():e.box("Nothing")}}}]};function Nr(e,i){if(0===i.length)return e.symbol("True");const t=[];for(const n of i){if("False"===n.symbol)return e.symbol("False");if("True"!==n.symbol){let i=!1;for(const r of t)if(r.isSame(n))i=!0;else if("Not"===n.head&&n.op1.isSame(r)||"Not"===r.head&&r.op1.isSame(n))return e.symbol("False");i||t.push(n)}}return 0===t.length?e.symbol("True"):1===t.length?t[0]:e._fn("And",t)}function _r(e,i){if(0===i.length)return e.symbol("True");const t=[];for(const n of i){if("True"===n.symbol)return e.symbol("True");if("False"!==n.symbol){let i=!1;for(const r of t)if(r.isSame(n))i=!0;else if("Not"===n.head&&n.op1.isSame(r)||"Not"===r.head&&r.op1.isSame(n))return e.symbol("True");i||t.push(n)}}return 0===t.length?e.symbol("True"):1===t.length?t[0]:e._fn("Or",t)}function Sr(e,i){const t=i[0].symbol;return"True"===t?e.symbol("False"):"False"===t?e.symbol("True"):"Maybe"===t?e.symbol("Maybe"):void 0}function wr(e,i){const t=i[0].symbol,n=i[1].symbol;return"True"===t&&"True"===n||"False"===t&&"False"===n?e.symbol("True"):"True"===t&&"False"===n||"False"===t&&"True"===n?e.symbol("False"):"Maybe"===t||"Maybe"===n?e.symbol("Maybe"):void 0}function Er(e,i){const t=i[0].symbol,n=i[1].symbol;return"True"===t&&"True"===n||"False"===t&&"False"===n||"False"===t&&"True"===n?e.symbol("True"):"True"===t&&"False"===n?e.symbol("False"):"Maybe"===t||"Maybe"===n?e.symbol("Maybe"):void 0}function kr(e,i){const t=e.engine;return"Negate"===e.head&&"Negate"===i.head?kr(e.op1,i.op1):"Negate"===e.head?er(kr(e.op1,i)):"Negate"===i.head?er(kr(e,i.op1)):"Add"===e.head?t.add(e.ops.map((e=>kr(e,i)))):"Add"===i.head?t.add(i.ops.map((i=>kr(e,i)))):t.mul([e,i])}function Ir(e,i){if(1===i)return e;const t=kr(e,e);return 2===i?t:i%2==0?Ir(t,i/2):kr(Ir(t,Math.round(i/2)-1),e)}const Ar=[{functions:[{name:"Expand",description:"Expand out products and positive integer powers",signature:{domain:["Function","Value","Value"],evaluate:(e,i)=>function(e){if("Multiply"===(e=e.simplify()).head)return 2===e.nops?kr(e.op1,e.op2):e.ops.reduce(((e,i)=>kr(e,i)),e.engine._ONE);if("Power"===e.head){const i=e.op1.head;if("Multiply"===i)return e.engine.mul(e.op1.ops.map((i=>e.engine.power(i,e.op2))));if("Negate"===i){const i=e.op2.asSmallInteger;if(null!==i&&i>0)return i%2==0?e.engine.power(e.op1.op1,e.op2):e.engine.negate(e.engine.power(e.op1.op1,e.op2))}if("Add"===i){const i=e.op2.asSmallInteger;if(null!==i)return i>0?Ir(e.op1,i).simplify():e.engine.inverse(Ir(e.op1,-i).simplify())}}return e}(i[0])}}]}],Mr=[{symbols:[{name:"Degrees",domain:"RealNumber",constant:!0,value:["Divide","Pi",180]},{name:"Pi",domain:"TranscendentalNumber",algebraic:!1,constant:!0,hold:!0,wikidata:"Q167",value:e=>Gt(e)?e._DECIMAL_PI:Math.PI}],functions:[{name:"Hypot",signature:{domain:["Function","Number","Number","NonNegativeNumber"],simplify:(e,i)=>e.box(["Sqrt",["Add",["Square",i[0]],["Square",i[1]]]]).simplify(),evaluate:["Sqrt",["Add",["Square","_1"],["Square","_2"]]]}},{name:"Sin",complexity:5e3,signature:{domain:["Function","Number",["Interval",-1,1]],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Sin",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:Ht(e)?e.box(["Divide",["Subtract",["Exp",["Multiply","ImaginaryUnit",i[0]]],["Exp",["Multiply","ImaginaryUnit",["Negate",i[0]]]]],["Complex",0,2]]).simplify():void 0},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Sin",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(e.chop(i[0].decimalValue.sin())):i[0].complexValue?e.number(i[0].complexValue.sin()):null!==i[0].asFloat?e.number(Math.sin(i[0].asFloat)):void 0}}]},{functions:[{name:"Arctan",wikidata:"Q2257242",complexity:5200,signature:{domain:["Function","Number","ExtendedRealNumber"],simplify:(e,i)=>{var t;return null===(t=Dr(e,"Arctan",i[0]))||void 0===t?void 0:t.simplify()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.atan()):i[0].complexValue?e.number(i[0].complexValue.atan()):null!==i[0].asFloat?e.number(Math.atan(i[0].asFloat)):void 0}},{name:"Arctan2",wikidata:"Q776598",complexity:5200,signature:{domain:["Function","Number","Number","Number"],N:(e,i)=>i[0].decimalValue&&i[1].decimalValue?e.number(Ze.atan2(i[0].decimalValue,i[1].decimalValue)):null!==i[0].asFloat&&null!==i[1].asFloat?e.number(Math.atan2(i[0].asFloat,i[1].asFloat)):void 0}},{name:"Cos",complexity:5050,signature:{domain:["Function","Number",["Interval",-1,1]],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Cos",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Sin",["Add",i[0],["Multiply","Half","Pi"]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Cos",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.cos()):i[0].complexValue?e.number(i[0].complexValue.cos()):null!==i[0].asFloat?e.number(Math.cos(i[0].asFloat)):void 0}},{name:"Tan",complexity:5100,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Tan",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",["Sin",i[0]],["Cos",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Tan",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.tan()):i[0].complexValue?e.number(i[0].complexValue.tan()):null!==i[0].asFloat?e.number(Math.tan(i[0].asFloat)):void 0}}]},{functions:[{name:"Arcosh",complexity:6200,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Arcoshh",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Ln",["Add",i[0],["Sqrt",["Subtract",["Square",i[0]],1]]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Arcoshh",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.acosh()):i[0].complexValue?e.number(i[0].complexValue.acosh()):null!==i[0].asFloat?e.number(Math.acosh(i[0].asFloat)):void 0}},{name:"Arcsin",complexity:5500,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Arcsin",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Multiply",2,["Arctan2",i[0],["Add",1,["Sqrt",["Subtract",1,["Square",i[0]]]]]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Arcsin",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.asin()):i[0].complexValue?e.number(i[0].complexValue.asin()):null!==i[0].asFloat?e.number(Math.asin(i[0].asFloat)):void 0}},{name:"Arsinh",complexity:6100,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Arsinh",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Ln",["Add",i[0],["Sqrt",["Add",["Square",i[0]],1]]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Arsinh",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.asinh()):i[0].complexValue?e.number(i[0].complexValue.asinh()):null!==i[0].asFloat?e.number(Math.asinh(i[0].asFloat)):void 0}},{name:"Artanh",complexity:6300,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Artanh",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Multiply","Half",["Ln",["Divide",["Add",1,i[0]],["Subtract",1,i[0]]]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Artanh",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.atanh()):i[0].complexValue?e.number(i[0].complexValue.atanh()):null!==i[0].asFloat?e.number(Math.atanh(i[0].asFloat)):void 0}},{name:"Cosh",complexity:6050,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Cosh",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Multiply","Half",["Add",["Exp",i[0]],["Exp",["Negate",i[0]]]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Cosh",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.cosh()):i[0].complexValue?e.number(i[0].complexValue.cosh()):null!==i[0].asFloat?e.number(Math.cosh(i[0].asFloat)):void 0}},{name:"Cot",complexity:5600,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Cot",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",["Cos",i[0]],["Sin",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Cot",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(e._DECIMAL_ONE.div(i[0].decimalValue.tan())):i[0].complexValue?e.number(i[0].complexValue.tan().inverse()):null!==i[0].asFloat?e.number(1/Math.tan(i[0].asFloat)):void 0}},{name:"Csc",description:"Cosecant",complexity:5600,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Csc",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",1,["Sin",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Csc",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(e._DECIMAL_ONE.div(i[0].decimalValue.sin())):i[0].complexValue?e.number(i[0].complexValue.sin().inverse()):null!==i[0].asFloat?e.number(1/Math.sin(i[0].asFloat)):void 0}},{name:"Haversine",wikidata:"Q2528380",signature:{domain:["Function","ExtendedRealNumber",["Interval",0,1]],evaluate:["Divide",["Subtract",1,["Cos","_1"]],2]}},{name:"InverseHaversine",signature:{domain:["Function","ExtendedRealNumber","RealNumber"],evaluate:["Multiply",2,["Arcsin",["Sqrt","_1"]]]}},{name:"Sec",description:"Secant, inverse of cosine",complexity:5500,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Sec",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",1,["Cos",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Sec",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(e._DECIMAL_ONE.div(i[0].decimalValue.cos())):i[0].complexValue?e.number(i[0].complexValue.cos().inverse()):null!==i[0].asFloat?e.number(1/Math.cos(i[0].asFloat)):void 0}},{name:"Sinh",complexity:6e3,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Sinh",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Multiply","Half",["Subtract",["Exp",i[0]],["Exp",["Negate",i[0]]]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Sinh",i[0]))||void 0===t?void 0:t.evaluate()}}}]},{functions:[{name:"Csch",complexity:6200,signature:{domain:["Function","Number","ExtendedRealNumber"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Csch",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",1,["Sinh",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Csch",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(e._DECIMAL_ONE.div(i[0].decimalValue.sinh())):i[0].complexValue?e.number(i[0].complexValue.sinh().inverse()):null!==i[0].asFloat?e.number(1/Math.sinh(i[0].asFloat)):void 0}},{name:"Sech",complexity:6200,signature:{domain:["Function","Number",["Interval",-1,1]],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Sech",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",1,["Cosh",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Sech",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(e._DECIMAL_ONE.div(i[0].decimalValue.cosh())):i[0].complexValue?e.number(i[0].complexValue.cosh().inverse()):null!==i[0].asFloat?e.number(1/Math.cosh(i[0].asFloat)):void 0}},{name:"Tanh",complexity:6200,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Tanh",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",["Sinh",i[0]],["Cosh",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Tanh",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.tanh()):i[0].complexValue?e.number(i[0].complexValue.tanh()):null!==i[0].asFloat?e.number(Math.tanh(i[0].asFloat)):void 0}}]},{functions:[{name:"Arccos",complexity:5550,signature:{domain:["Function","Number","ExtendedRealNumber"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Arccos",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Subtract",["Divide","Pi",2],["Arcsin",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Arccos",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(i[0].decimalValue.acos()):i[0].complexValue?e.number(i[0].complexValue.acos()):null!==i[0].asFloat?e.number(Math.acos(i[0].asFloat)):void 0}},{name:"Coth",complexity:6300,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var t,n;return null!==(n=null===(t=Dr(e,"Coth",i[0]))||void 0===t?void 0:t.simplify())&&void 0!==n?n:e.box(["Divide",1,["Tanh",i[0]]]).simplify()},evaluate:(e,i)=>{var t;return null===(t=Dr(e,"Coth",i[0]))||void 0===t?void 0:t.evaluate()},N:(e,i)=>i[0].decimalValue?e.number(e._DECIMAL_ONE.div(i[0].decimalValue.tanh())):i[0].complexValue?e.number(i[0].complexValue.tanh().inverse()):null!==i[0].asFloat?e.number(1/Math.tanh(i[0].asFloat)):void 0}},{name:"InverseFunction",signature:{domain:["Function","Function","Function"],simplify:(e,i)=>Pr(e,i[0]),evaluate:(e,i)=>Pr(e,i[0])}}]}],Fr=["Sqrt",2],Or=["Sqrt",3],Vr=["Sqrt",5],Tr=["Sqrt",6],qr=[[[0,1],{Sin:0,Cos:1,Tan:0,Cot:NaN,Sec:1,Csc:NaN}],[[1,12],{Sin:["Divide",["Subtract",Tr,Fr],4],Cos:["Divide",["Add",Tr,Fr],4],Tan:["Subtract",2,Or],Cot:["Add",2,Or],Sec:["Subtract",Tr,Fr],Csc:["Add",Tr,Fr]}],[[1,10],{Sin:["Divide",["Subtract",Vr,1],4],Cos:["Divide",["Sqrt",["Add",10,["Multiply",2,Vr]]],4],Tan:["Divide",["Sqrt",["Subtract",25,["Multiply",10,Vr]]],4],Cot:["Sqrt",["Add",5,["Multiply",2,Vr]]],Sec:["Divide",["Sqrt",["Subtract",50,["Multiply",10,Vr]]],5],Csc:["Add",1,Vr]}],[[1,8],{Sin:"$\\frac\\sqrt{2-\\sqrt2}{2}$",Cos:"$\\frac {\\sqrt {2+{\\sqrt {2}}}}{2}$",Tan:"$\\sqrt{2} - 1$",Cot:"$\\sqrt{2} + 1$",Sec:"$\\sqrt{ 4 - 2\\sqrt{2}}$",Csc:"$\\sqrt{ 4 + 2\\sqrt{2}}$"}],[[1,6],{Sin:"$\\frac{1}{2}$",Cos:"$\\frac{\\sqrt{3}}{2}$",Tan:"$\\frac{\\sqrt{3}}{3}$",Cot:"$\\frac{2\\sqrt{3}}{3}$",Sec:"$\\sqrt{3}$",Csc:2}],[[1,5],{Sin:"$\\frac{\\sqrt{10- 2\\sqrt{5}}} {4}$",Cos:"$\\frac{1+ \\sqrt{5}} {4}$",Tan:"$\\sqrt{5-2\\sqrt5}$",Cot:"$\\frac{\\sqrt{25+10\\sqrt5}} {5}$",Sec:"$\\sqrt{5} - 1$",Csc:"$\\frac{\\sqrt{50+10\\sqrt{5}}} {5}$"}],[[1,4],{Sin:["Divide",Fr,2],Cos:["Divide",Fr,2],Tan:1,Cot:1,Sec:Fr,Csc:Fr}],[[3,10],{Sin:"$\\frac{1+ \\sqrt{5}} {4}$",Cos:"$\\frac{\\sqrt{10- 2\\sqrt{5}}} {4}$",Tan:"$\\frac{\\sqrt{25+10\\sqrt5}} {5}$",Cot:"$\\sqrt{5-2\\sqrt5}$",Sec:"$$",Csc:"$\\frac{\\sqrt{50+10\\sqrt{5}}} {5}$"}],[[1,3],{Sin:["Divide",Or,2],Cos:"Half",Tan:Or,Cot:["Divide",Or,3],Sec:2,Csc:["Divide",["Multiply",2,Or],3]}],[[3,8],{Sin:"$\\frac{ \\sqrt{2 + \\sqrt{2}} } {2}$",Cos:"$\\frac{ \\sqrt{2 - \\sqrt{2}} } {2}$",Tan:"$\\sqrt{2} + 1$",Cot:"$\\sqrt{2} - 1$",Sec:"$\\sqrt{ 4 + 2 \\sqrt{2} }$",Csc:"$\\sqrt{ 4 - 2 \\sqrt{2} }$"}],[[2,5],{Sin:"$\\frac{\\sqrt{10+ 2\\sqrt{5}}} {4}$",Cos:"$\\frac{\\sqrt{5}-1} {4}$",Tan:"$\\sqrt{5+2\\sqrt{5}}$",Cot:"$\\frac{\\sqrt{25-10\\sqrt{5}}} {5}$",Sec:"$1 + \\sqrt{5}$",Csc:"$\\frac{\\sqrt{50-10\\sqrt{5}}} {5}$"}],[[5,12],{Sin:"$\\frac{\\sqrt{6} + \\sqrt{2}} {4}$",Cos:"$\\frac{ \\sqrt{6} - \\sqrt{2}} {4}$",Tan:"$2+\\sqrt{3}$",Cot:"$2-\\sqrt{3}$",Sec:"$\\sqrt{6}+\\sqrt{2}$",Csc:"$\\sqrt{6} - \\sqrt{2}$"}],[[1,2],{Sin:1,Cos:0,Tan:NaN,Cot:0,Sec:NaN,Csc:1}]],Cr={Sin:[[1,"Sin"],[1,"Cos"],[-1,"Sin"],[-1,"Cos"]],Cos:[[1,"Cos"],[-1,"Sin"],[-1,"Cos"],[1,"Sin"]],Sec:[[1,"Sec"],[-1,"Csc"],[-1,"Sec"],[1,"Csc"]],Csc:[[1,"Csc"],[1,"Sec"],[-1,"Csc"],[-1,"Sec"]],Tan:[[1,"Tan"],[-1,"Cot"],[1,"Tan"],[-1,"Cot"]],Cot:[[1,"Cot"],[-1,"Tan"],[1,"Cot"],[-1,"Tan"]]};function Dr(e,i,t){var n,r,a,s,o,l;const u=e.cache("constructible-trigonometric-values",(()=>{var i;const t=[];for(const[n,r]of qr){const a={};for(const t of Object.keys(r))a[t]=(null!==(i=e.parse(zt(r[t])))&&void 0!==i?i:e.box(r[t])).canonical;t.push([n,a])}return t}),(e=>{for(const[i,t]of e)for(const e of Object.values(t))e.unbind();return e}));if(!(t=null!==(n=t.numericValue)&&void 0!==n?n:t).isLiteral)return;let c=null!==(s=null!==(r=t.asFloat)&&void 0!==r?r:null===(a=t.decimalValue)||void 0===a?void 0:a.toNumber())&&void 0!==s?s:null;if(null===c)return;c%=2*Math.PI;const h="Cos"!==i&&"Sec"!==i?Math.sign(c):1;c=Math.abs(c);const m=Math.floor(2*c/Math.PI);let d;c%=Math.PI/2,[d,i]=null!==(l=null===(o=Cr[i])||void 0===o?void 0:o[m])&&void 0!==l?l:[1,i],d*=h;for(const[[t,n],r]of u)if(0===e.chop(c-Math.PI*t/n))return d<0?er(r[i]):r[i]}function Pr(e,i){const t=i.symbol;if("string"!=typeof t)return i;const n={Sin:"Arcsin",Cos:"Arccos",Tan:"Arctan",Sec:"Arcsec",Csc:" Arccsc",Sinh:"Arsinh",Cosh:"Arcosh",Tanh:"Artanh",Sech:"Arcsech",Csch:"Arcsch",Arcosh:"Cosh",Arcos:"Cos",Arccsc:"Csc",Arcsch:"Csch",Arcsec:"Sec",Arcsin:"Sin",Arsinh:"Sinh",Arctan:"Tan",Artanh:"Tanh"}[t];return n?e.symbol(n):i}function Lr(e){return Object.fromEntries(Object.entries(e).filter((([e,i])=>void 0!==i)))}function Rr(e){const i=Object.assign({},e);return e.zero||e.one||e.negativeOne?(i.number=!0,i.integer=!0,i.rational=!0,i.algebraic=!0,i.real=!0,i.extendedReal=!0,i.complex=!0,i.extendedComplex=!0,i.imaginary=!1,i.positive=!1,i.nonPositive=!0,i.negative=!1,i.nonNegative=!0,i.zero=e.zero,i.notZero=!e.zero,i.one=e.one,i.negativeOne=e.negativeOne,i.negativeOne=!1,i.infinity=!1,i.NaN=!1,i.finite=!0,i.even=e.one,i.odd=!e.one,i.prime=!1,i.composite=!1,i):(!0===i.notZero&&(i.imaginary||(i.real=!0),i.zero=!1),(i.positive||i.nonNegative)&&(i.negativeOne=!1),i.positive?(i.nonPositive=!1,i.negative=!1,i.nonNegative=!0):i.nonPositive?(i.positive=!1,i.negative=i.notZero,i.nonNegative=!i.zero):i.negative?(i.positive=!1,i.nonPositive=i.notZero,i.nonNegative=!1):i.nonNegative&&(i.positive=i.notZero,i.nonPositive=!i.zero,i.negative=!1),(i.positive||i.negative||i.nonPositive||i.nonNegative)&&(i.number=!0,i.finite?i.real=!0:i.finite||(i.complex=!0),i.imaginary=!1),i.infinity&&(i.finite=!1,i.NaN=!1),i.finite&&(i.number=!0,i.complex=!0,i.infinity=!1,i.NaN=!1),e.even&&(i.odd=!1),e.odd&&(i.even=!1),i.integer&&(i.rational=!0),i.rational&&(i.algebraic=!0),i.algebraic&&(i.real=!0),i.extendedReal&&(i.real=!0),i.real&&(i.complex=!0),i.imaginary&&(i.complex=!0),i.extendedComplex&&(i.complex=!0),i.complex&&(i.number=!0),i.real&&i.infinity&&(i.extendedReal=!0),i.complex&&i.infinity&&(i.extendedComplex=!0),(i.even||i.infinity||i.NaN||i.negative||i.imaginary||!1===i.integer)&&(i.prime=!1),i.number&&i.prime&&(i.composite=!1),i)}function zr(e){if(!e)return{};const i={};if(e.isNumeric){const t=e.symbol;i.number=!0,"Integer"===t&&(i.integer=!0),"RationalNumber"===t&&(i.rational=!0),"AlgebraicNumber"===t&&(i.algebraic=!0),"TranscendentalNumber"===t&&(i.algebraic=!1,i.real=!0),"ExtendedRealNumber"===t&&(i.extendedReal=!0),"RealNumber"===t&&(i.real=!0),"ImaginaryNumber"===t&&(i.imaginary=!0),"ExtendedComplexNumber"===t&&(i.extendedComplex=!0),"ComplexNumber"===t&&(i.complex=!0)}else i.number=!1,i.integer=!1,i.rational=!1,i.algebraic=!1,i.real=!1,i.extendedReal=!1,i.complex=!1,i.extendedComplex=!1,i.imaginary=!1,i.positive=!1,i.nonPositive=!1,i.negative=!1,i.nonNegative=!1,i.zero=!1,i.notZero=!1,i.one=!1,i.negativeOne=!1,i.infinity=!1,i.NaN=!1,i.odd=!1,i.even=!1,i.prime=!1,i.composite=!1;return Lr(Rr(i))}function $r(e){return Lr({number:(e=e.canonical).isNumber,integer:e.isInteger,rational:e.isRational,algebraic:e.isAlgebraic,real:e.isReal,extendedReal:e.isExtendedReal,complex:e.isComplex,extendedComplex:e.isExtendedComplex,imaginary:e.isImaginary,positive:e.isPositive,nonPositive:e.isNonPositive,negative:e.isNegative,nonNegative:e.isNonNegative,zero:e.isZero,notZero:e.isNotZero,one:e.isOne,negativeOne:e.isNegativeOne,infinity:e.isInfinity,NaN:e.isNaN,finite:e.isFinite,even:e.isEven,odd:e.isOdd,prime:e.isPrime,composite:e.isComposite})}class jr{constructor(e,i){var t,n;if(!e.context)throw Error("No context available");this._engine=e,this.scope=e.context,this._def=i,this.name=i.name,this.constant=null!==(t=i.constant)&&void 0!==t&&t,this.hold=null===(n=i.hold)||void 0===n||n,this._value=null,this._domain=null}reset(){var e;null===(e=this._value)||void 0===e||e.unbind(),this.unbind()}unbind(){this._value=null,this._domain=null}bind(){var e,i;this._value=null;const t=this._def,n=this._engine,r=Lr({description:t.description,wikidata:t.wikidata,number:t.number,integer:t.integer,rational:t.rational,algebraic:t.algebraic,real:t.real,extendedReal:t.extendedReal,complex:t.complex,zero:t.zero,notZero:t.notZero,one:t.one,negativeOne:t.negativeOne,infinity:t.infinity,NaN:t.NaN,finite:t.finite,even:t.even,odd:t.odd,prime:t.prime,composite:t.composite});if("value"in t&&"number"==typeof t.value){const e=n.number(t.value);let i;const a=t.domain?n.domain(t.domain):void 0;return i=a&&e.domain.isCompatible(a)?a:e.domain,this._value=e,this._domain=i,this.setProps($r(e)),this.setProps(zr(i)),void this.setProps(r)}let a,s;if(Rt(t.value)?a=n.parse(t.value):"function"==typeof t.value?a=n.box(null!==(e=t.value(n))&&void 0!==e?e:"Undefined"):t.value&&(a=n.box(t.value)),!a&&!1===t.hold)throw Error(`Symbol definition "${t.name}": Expected a value when "hold=false" `);a=null==a?void 0:a.canonical;const o=t.domain?n.domain(t.domain):void 0;s=!o||a&&!a.domain.isCompatible(o)?null!==(i=null==a?void 0:a.domain)&&void 0!==i?i:n.defaultDomain:o,this._value=a,this._domain=s,a&&this.setProps($r(a)),this.setProps(zr(s)),this.setProps(r)}get value(){var e;return null===this._value&&this.bind(),null!==(e=this._value)&&void 0!==e?e:void 0}set value(e){if(null===this._value&&this.bind(),this.constant)throw Error(`The value of the constant "${this.name}" cannot be changed`);"number"==typeof e&&(e=this._engine.box(e)),this._value=null!=e?e:null,e&&this.setProps($r(e))}get domain(){var e;return null===this._domain&&this.bind(),null!==(e=this._domain)&&void 0!==e?e:void 0}set domain(e){var i;if(!e)return void(this._domain=void 0);e=this._engine.domain(e);const t=null===(i=this.value)||void 0===i?void 0:i.domain;t&&!t.isCompatible(e)&&(e=t),this._domain=e,this.setProps(zr(e))}updateFlags(e){this.setProps(Rr(e))}setProps(e){e.wikidata&&(this.wikidata=e.wikidata),e.description&&(this.description=e.description),void 0!==e.number&&(this._number=e.number),void 0!==e.integer&&(this._integer=e.integer),void 0!==e.rational&&(this._rational=e.rational),void 0!==e.algebraic&&(this._algebraic=e.algebraic),void 0!==e.real&&(this._real=e.real),void 0!==e.extendedReal&&(this._extendedReal=e.extendedReal),void 0!==e.complex&&(this._complex=e.complex),void 0!==e.extendedComplex&&(this._extendedComplex=e.extendedComplex),void 0!==e.imaginary&&(this._imaginary=e.imaginary),void 0!==e.positive&&(this._positive=e.positive),void 0!==e.nonPositive&&(this._nonPositive=e.nonPositive),void 0!==e.negative&&(this._negative=e.negative),void 0!==e.nonNegative&&(this._nonNegative=e.nonNegative),void 0!==e.zero&&(this._zero=e.zero),void 0!==e.notZero&&(this._notZero=e.notZero),void 0!==e.one&&(this._one=e.one),void 0!==e.negativeOne&&(this._negativeOne=e.negativeOne),void 0!==e.infinity&&(this._infinity=e.infinity),void 0!==e.finite&&(this._finite=e.finite),void 0!==e.NaN&&(this._NaN=e.NaN),void 0!==e.even&&(this._even=e.even),void 0!==e.odd&&(this._odd=e.odd),void 0!==e.prime&&(this._prime=e.prime),void 0!==e.composite&&(this._composite=e.composite)}get number(){return null===this._value&&this.bind(),this._number}set number(e){this.updateFlags({number:e})}get integer(){return null===this._value&&this.bind(),this._integer}set integer(e){this.updateFlags({integer:e})}get rational(){return null===this._value&&this.bind(),this._rational}set rational(e){this.updateFlags({rational:e})}get algebraic(){return null===this._value&&this.bind(),this._algebraic}set algebraic(e){this.updateFlags({algebraic:e})}get real(){return null===this._value&&this.bind(),this._real}set real(e){this.updateFlags({real:e})}get extendedReal(){return null===this._value&&this.bind(),this._extendedReal}set extendedReal(e){this.updateFlags({extendedReal:e})}get complex(){return null===this._value&&this.bind(),this._complex}set complex(e){this.updateFlags({complex:e})}get extendedComplex(){return null===this._value&&this.bind(),this._extendedComplex}set extendedComplex(e){this.updateFlags({extendedComplex:e})}get imaginary(){return null===this._value&&this.bind(),this._imaginary}set imaginary(e){this.updateFlags({imaginary:e})}get positive(){return null===this._value&&this.bind(),this._positive}set positive(e){this.updateFlags({positive:e})}get nonPositive(){return null===this._value&&this.bind(),this._nonPositive}set nonPositive(e){this.updateFlags({nonPositive:e})}get negative(){return null===this._value&&this.bind(),this._negative}set negative(e){this.updateFlags({negative:e})}get nonNegative(){return null===this._value&&this.bind(),this._nonNegative}set nonNegative(e){this.updateFlags({nonNegative:e})}get zero(){return null===this._value&&this.bind(),this._zero}set zero(e){this.updateFlags({zero:e})}get notZero(){return null===this._value&&this.bind(),this._notZero}set notZero(e){this.updateFlags({notZero:e})}get one(){return null===this._value&&this.bind(),this._one}set one(e){this.updateFlags({one:e})}get negativeOne(){return null===this._value&&this.bind(),this._negativeOne}set negativeOne(e){this.updateFlags({negativeOne:e})}get infinity(){return null===this._value&&this.bind(),this._infinity}set infinity(e){this.updateFlags({infinity:e})}get finite(){return null===this._value&&this.bind(),this._finite}set finite(e){this.updateFlags({finite:e})}get NaN(){return null===this._value&&this.bind(),this._NaN}set NaN(e){this.updateFlags({NaN:e})}get even(){return null===this._value&&this.bind(),this._even}set even(e){this.updateFlags({even:e})}get odd(){return null===this._value&&this.bind(),this._odd}set odd(e){this.updateFlags({odd:e})}get prime(){var e;if(null===this._value&&this.bind(),void 0===this._prime&&(null===(e=this._value)||void 0===e?void 0:e.isNumber))if(!this._value.isInteger||this._value.isNonPositive)this._prime=!1,this._composite=!1;else{const e=this._value.asFloat;null!==e?(this._prime=Gn(e),this._composite=!this._prime):(this._prime=void 0,this._composite=void 0)}return this._prime}set prime(e){this.updateFlags({prime:e})}get composite(){if(null===this._value&&this.bind(),void 0===this._composite){const e=this.prime;this._composite=void 0===e?void 0:!e}return this._composite}set composite(e){this.updateFlags({composite:e})}}class Zr{constructor(e,i){var t,n,r,a,s,o,l,u,c,h,m,d,f;if(!e.context)throw Error("No context available");this.engine=e,this.scope=e.context;const g=null!==(t=i.idempotent)&&void 0!==t&&t,p=null!==(n=i.involution)&&void 0!==n&&n;if(g&&p)throw Error(`Function Definition "${i.name}": the 'idempotent' and 'involution' flags are mutually exclusive`);if(this.name=i.name,this.description=i.description,this.wikidata=i.wikidata,this.threadable=null!==(r=i.threadable)&&void 0!==r&&r,this.associative=null!==(a=i.associative)&&void 0!==a&&a,this.commutative=null!==(s=i.commutative)&&void 0!==s&&s,this.idempotent=g,this.involution=p,this.inert=null!==(o=i.inert)&&void 0!==o&&o,this.numeric=null!==(l=i.numeric)&&void 0!==l&&l,this.scoped=null!==(u=i.scoped)&&void 0!==u&&u,this.pure=null===(c=i.pure)||void 0===c||c,this.complexity=null!==(h=i.complexity)&&void 0!==h?h:sn,this.hold=null!==(m=i.hold)&&void 0!==m?m:"none",this.inert){if(i.hold)throw Error(`Function Definition "${i.name}": an inert function should not have a hold`);if(this.hold="rest",i.signature){const e=i.signature;if("simplify"in e||"evaluate"in e||"N"in e||"evalDimension"in e||"sgn"in e||"compile"in e)throw Error(`Function Definition "${i.name}": an inert function should only have 'canonical' or 'codomain' handlers`)}if(this.threadable)throw Error(`Function Definition "${i.name}": an inert function should not be threadable`);if(this.associative)throw Error(`Function Definition "${i.name}": an inert function should not be associative`);if(this.commutative)throw Error(`Function Definition "${i.name}": an inert function should not be commutative`);if(this.idempotent)throw Error(`Function Definition "${i.name}": an inert function should not be idempotent`);if(this.involution)throw Error(`Function Definition "${i.name}": an inert function should not be involution`);if(!this.pure)throw Error(`Function Definition "${i.name}": an inert function should be pure`)}if(i.signature){const t=i.signature,n=t.domain?e.domain(t.domain):i.numeric?e.domain("NumericFunction"):e.domain("Function");if(!n.isValid)throw Error(`Function Definition "${i.name}": invalid domain ${JSON.stringify(t.domain)}`);const r=null!==(f=null!==(d=t.codomain)&&void 0!==d?d:n.codomain)&&void 0!==f?f:i.numeric?e.domain("Number"):e.domain("Anything");this.signature={domain:n,codomain:r,canonical:t.canonical,simplify:t.simplify,evaluate:t.evaluate?"function"==typeof t.evaluate?t.evaluate:e.lambda(t.evaluate,n):void 0,N:t.N,evalDimension:t.evalDimension,sgn:t.sgn,compile:t.compile}}else i.numeric?this.signature={domain:e.domain("NumericFunction"),codomain:e.domain("Number")}:this.signature={domain:e.domain("Function"),codomain:e.domain("Anything")}}reset(){}}function Br(e,i){return new Zr(e,i)}function Gr(e){if("all"===e)return Gr(["domains","core","control-structures","logic","collections","relop","numeric","arithmetic","algebra","calculus","combinatorics","linear-algebra","other","physics","polynomials","statistics","trigonometry","dimensions","units"]);"string"==typeof e&&(e=[e]);const i=[];for(const t of e){const e=Hr[t];if(!e)throw Error("Unknown library category "+t);Array.isArray(e)?i.push(...e):i.push(e)}return i}const Hr={algebra:[],arithmetic:pr,calculus:[{functions:[{name:"Integrate",wikidata:"Q80091",signature:{domain:["Function","Anything",["Union","Tuple","Symbol"],"Number"]}}]}],combinatorics:[],"control-structures":[],dimensions:[],domains:[],core:yr,collections:[{symbols:[{name:"EmptySet",domain:"Set",constant:!0,wikidata:"Q226183"}],functions:[{name:"Element",complexity:11200,signature:{domain:"Predicate"}},{name:"NotElement",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("Element",i)])}},{name:"Subset",complexity:11200,signature:{domain:"Predicate"}},{name:"NotSubset",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("Subset",i)])}},{name:"Superset",complexity:11200,signature:{domain:"Predicate"}},{name:"SupersetEqual",complexity:11200,signature:{domain:"Predicate"}},{name:"NotSuperset",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("Superset",i)])}},{name:"NotSupersetEqual",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("SupersetEqual",i)])}},{name:"SubsetEqual",complexity:11200,signature:{domain:"Predicate"}},{name:"NotSubsetNotEqual",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("SubsetEqual",i)])}},{name:"CartesianProduct",wikidata:"Q173740",signature:{domain:["Function","Set",["Sequence","Set"],"Set"]}},{name:"Complement",wikidata:"Q242767",signature:{domain:["Function","Set","Set"]}},{name:"Intersection",wikidata:"Q185837",threadable:!0,associative:!0,commutative:!0,involution:!0,signature:{domain:["Function","Set",["Sequence","Set"],"Set"],evaluate:function(e,i){return e.symbol("EmptySet")}}},{name:"Union",wikidata:"Q185359",threadable:!0,associative:!0,commutative:!0,involution:!0,signature:{domain:["Function","Set",["Sequence","Set"],"Set"],evaluate:function(e,i){return e.symbol("False")}}},{name:"SetMinus",wikidata:"Q18192442",signature:{domain:["Function","Set","Value","Set"],evaluate:function(e,i){return e.symbol("EmptySet")}}},{name:"SymmetricDifference",wikidata:"Q1147242",signature:{domain:["Function","Set",["Sequence","Set"],"Set"]}}]},{functions:[{name:"Sequence",signature:{domain:"Function"}}]}],"linear-algebra":[],logic:xr,numeric:[],other:[],relop:{functions:[{name:"Equal",commutative:!0,complexity:11e3,signature:{domain:"RelationalOperator",evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let t;for(const n of i)if(t){if(!1===t.isEqual(n))return e.symbol("False")}else t=n;return e.symbol("True")}}},{name:"NotEqual",wikidata:"Q28113351",commutative:!0,complexity:11e3,signature:{domain:"RelationalOperator",evaluate:(e,i)=>{if(i.length<2)return e.symbol("False");let t;for(const n of i)if(t){if(!0===t.isEqual(n))return e.symbol("False")}else t=n;return e.symbol("True")}}},{name:"Less",complexity:11e3,signature:{domain:"RelationalOperator",evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let t;for(const n of i){if(!n.isNumber)return;if(t){const i=e.fn("Subtract",[n,t]).N().sgn;if(null==i)return;if(i<=0)return e.symbol("False");t=n}else t=n}return e.symbol("True")}}},{name:"NotLess",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Less",i)])}},{name:"Greater",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Less",i.reverse()),evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let t;for(const n of i){if(!n.isNumber)return;if(t){const i=e.fn("Subtract",[n,t]).N().sgn;if(null==i)return;if(i>=0)return e.symbol("False");t=n}else t=n}return e.symbol("True")}}},{name:"NotGreater",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Greater",i)])}},{name:"LessEqual",complexity:11e3,signature:{domain:"RelationalOperator",evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let t;for(const n of i){if(!n.isNumber)return;if(t){const i=e.fn("Subtract",[n,t]).N().sgn;if(null==i)return;if(i<0)return e.symbol("False");t=n}else t=n}return e.symbol("True")}}},{name:"NotLessNotEqual",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("LessEqual",i)])}},{name:"GreaterEqual",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("LessEqual",i.reverse()),evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let t;for(const n of i){if(!n.isNumber)return;if(t){const i=e.fn("Subtract",[n,t]).N().sgn;if(null==i)return;if(i>0)return e.symbol("False");t=n}else t=n}return e.symbol("True")}}},{name:"NotGreaterNotEqual",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("GreaterEqual",i)])}},{name:"TildeFullEqual",description:"Indicate isomorphism, congruence and homotopic equivalence",signature:{domain:"RelationalOperator"}},{name:"NotTildeFullEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("TildeFullEqual",i)])}},{name:"TildeEqual",description:"Approximately or asymptotically equal",complexity:11e3,signature:{domain:"RelationalOperator"}},{name:"NotTildeEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("TildeEqual",i)])}},{name:"Approx",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotApprox",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Approx",i)])}},{name:"ApproxEqual",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotApproxEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("ApproxEqual",i)])}},{name:"ApproxNotEqual",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotApproxNotEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("ApproxNotEqual",i)])}},{name:"Precedes",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotPrecedes",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Precedes",i)])}},{name:"Succeeds",signature:{domain:"RelationalOperator"}},{name:"NotSucceeds",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Succeeds",i)])}}]},polynomials:Ar,physics:{symbols:[{name:"Mu-0",description:"Vaccum permeability",constant:!0,wikidata:"Q1515261",domain:"RealNumber",value:125663706212e-17}]},statistics:[],trigonometry:Mr,units:[]};function Wr(e){if("object"!=typeof e||!("name"in e)||!e.name)throw Error("Missing name for definition"+JSON.stringify(e));const i=e.name.normalize();if(!ui(i))throw Error("Invalid definition name "+i);return i}function Ur(e,i){var t,n;if(!e.context)throw Error("No context available");null!==(t=(n=e.context).symbolTable)&&void 0!==t||(n.symbolTable={symbols:new Map,functions:new Map,symbolWikidata:new Map,functionWikidata:new Map});const r=e.context.symbolTable;if(i.symbols)for(const t of i.symbols){const i=Wr(t),n=new jr(e,t);if(t.wikidata){if(r.symbolWikidata.has(t.wikidata))throw Error(`Duplicate symbol with wikidata ${t.wikidata}, ${i} and ${r.symbolWikidata.get(t.wikidata).name}`);r.symbolWikidata.set(t.wikidata,n)}if(r.symbols.has(i))throw Error(`Duplicate symbol definition ${i}:\n${JSON.stringify(r.symbols.get(i))}\n${JSON.stringify(t)}`);r.symbols.set(i,n)}if(i.functions)for(const t of i.functions){const i=Wr(t),n=Br(e,t);if(t.wikidata){if(r.functionWikidata.has(t.wikidata))throw Error(`Duplicate function with wikidata ${t.wikidata}, ${i} and ${r.functionWikidata.get(t.wikidata).name}`);r.functionWikidata.set(t.wikidata,n)}if(r.functions.has(i))throw Error(`Duplicate function definition ${i}:\n${JSON.stringify(r.symbols.get(i))}\n${JSON.stringify(t)}`);r.functions.set(i,n)}}function Qr(e){return Number.isInteger(e)?Math.floor(Math.log2(Math.abs(e))/Math.log2(10))+(e>0?1:2):2}const Yr=function e(i){var t,n;if(i.symbol)return 1;if(i.isLiteral){if(i.isZero)return 1;if(i.isInteger&&null!==i.asFloat)return Qr(i.asFloat);const[e,t]=i.rationalValue;if(null!==e&&null!==t)return Qr(e)+Qr(t)+1;if(i.complexValue){const e=i.complexValue;return Qr(e.re)+Qr(e.im)+1}if(i.isNumber)return 2}const r=i.head;return("string"==typeof r?1:e(r))+(null!==(n=null===(t=i.ops)||void 0===t?void 0:t.reduce(((i,t)=>i+e(t)),0))&&void 0!==n?n:0)};class Kr{constructor(e){this._items=e?e instanceof Kr?new Map(e._items):new Map(e):new Map}has(e){for(const i of this._items.keys())if(i.isSame(e))return!0;return!1}get(e){for(const[i,t]of this._items)if(i.isSame(e))return t}clear(){this._items.clear()}set(e,i){for(const t of this._items.keys())if(t.isSame(e))return void this._items.set(t,i);this._items.set(e,i)}delete(e){this._items.delete(e)}[Symbol.iterator](){return this._items.entries()}entries(){return this._items.entries()}}class Jr extends Qt{constructor(e,i,t){super(e,t),this._pattern=Rt(i)?e.parse(i):e.box(i),this._pattern.isCanonical&&(this._canonicalPattern=this._pattern)}get hash(){return Wt("Pattern")^this._pattern.hash}unbind(){var e;this._pattern.unbind(),null===(e=this._canonicalPattern)||void 0===e||e.unbind()}get json(){return gn(this.engine,"Pattern",[this._pattern])}get head(){return"Pattern"}get domain(){return this.engine.domain("Pattern")}get isCanonical(){return!0}set isCanonical(e){}isSame(e){return this===e||e instanceof Jr&&this._pattern.isSame(e._pattern)}isEqual(e){return e instanceof Jr&&this._pattern.isEqual(e._pattern)}match(e,i){var t,n,r;let a=this._pattern;return null!==(t=null==i?void 0:i.exact)&&void 0!==t&&t||(this._canonicalPattern||(this._canonicalPattern=this._pattern.canonical),a=this._canonicalPattern),function(e,i,t){var n;return ea(e,i,{},{numericTolerance:null!==(n=null==t?void 0:t.numericTolerance)&&void 0!==n?n:It})||null}(e,a,{recursive:null!==(n=null==i?void 0:i.recursive)&&void 0!==n&&n,numericTolerance:null!==(r=null==i?void 0:i.numericTolerance)&&void 0!==r?r:0})}test(e,i){return null!==this.match(e,i)}count(e,i){let t=0;for(const n of e)null!==this.match(n,i)&&(t+=1);return t}subs(e){return new Jr(this.engine,this._pattern.subs(e).canonical)}}function Xr(e,i,t){const n=function(e){const i=e.match(/^__?_?([a-zA-Z0-9]+)/);return null===i?"":i[1]}(e);return""===n?t:t[n]?i.isSame(i.engine.box(t[n]))?t:null:(t[n]=i,t)}function ea(e,i,t,n){const r=e.engine;if(i instanceof Hn)return e instanceof Hn?0===n.numericTolerance?i.isSame(e)?ia(r,t):null:i.isEqualWithTolerance(e,n.numericTolerance)?ia(r,t):null:null;const a=i.string;if(null!==a)return e.string===a?ia(r,t):null;const s=i.symbol;if(null!==s)return s.startsWith("_")?Xr(s,e,ia(r,t)):s===e.symbol?ia(r,t):null;if(i.nops!==e.nops)return null;const o=i.keys;if(null!==o){const i=e.keys;if(null===i)return null;for(const e of o){const r=ea(i[e],o[e],t,n);if(null===r)return null;t=r}return ia(r,t)}if(i.ops){const a=i.head;if("string"==typeof a&&a.startsWith("_"))return Xr(a,r.box(e.head),ia(r,t));{const i=ea(r.box(e.head),r.pattern(a),t,n);if(null===i)return null;t=i}const s=e.ops;let o=Object.assign({},t),l=0;const u=i.ops.map((e=>r.pattern(e)));for(;l<i.nops;){const e=u[l],i=e.symbol;if(null!==i)if(i.startsWith("__")){let e=0;if(void 0===u[l+1])e=s.length+1;else{let i=!1;for(;!i&&e<s.length;)i=null!==ea(s[e],u[l+1],t,n),e+=1;if(!i)return null}if(!i.startsWith("___")&&e<=1)return null;o=Xr(i,r.fn("Sequence",s.splice(0,e-1)),ia(r,o))}else if(i.startsWith("_"))o=Xr(i,s.shift(),ia(r,o));else{const i=ea(s.shift(),e,t,n);if(null===i)return null;o=Object.assign(Object.assign({},o),i)}else{const i=ea(s.shift(),e,t,n);if(null===i)return null;o=Object.assign(Object.assign({},o),i)}if(null===o)return null;l+=1}return ia(r,o)}return null}function ia(e,i){return null===i?null:Object.fromEntries(Object.entries(i).map((([i,t])=>[i,e.box(t)])))}function ta(e){return null!=e&&"constant"in e}class na extends Qt{constructor(e,i,t){super(e,t),this._scope=e.context,this._name=i,this._def=null,e._register(this)}get hash(){return void 0===this._hash&&(this._hash=Wt(this._name)),this._hash}unbind(){var e;return null===(e=this._def)||void 0===e?void 0:e.reset()}get isPure(){var e,i,t,n,r;return null!==(r=null!==(t=(null===(e=this.symbolDefinition)||void 0===e?void 0:e.constant)&&(null===(i=this.symbolDefinition.value)||void 0===i?void 0:i.isPure))&&void 0!==t?t:null===(n=this.functionDefinition)||void 0===n?void 0:n.pure)&&void 0!==r&&r}get isFree(){var e;return!(null===(e=this.symbolDefinition)||void 0===e?void 0:e.value)}get isConstant(){var e,i;return null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.constant)&&void 0!==i&&i}get isCanonical(){var e;return!1!==(null===(e=this.symbolDefinition)||void 0===e?void 0:e.hold)}set isCanonical(e){}get canonical(){var e,i,t,n,r,a;return!0===(null===(e=this.symbolDefinition)||void 0===e?void 0:e.hold)?this:null!==(a=null!==(n=null===(t=null===(i=this.symbolDefinition)||void 0===i?void 0:i.value)||void 0===t?void 0:t.value)&&void 0!==n?n:null===(r=this.symbolDefinition)||void 0===r?void 0:r.value)&&void 0!==a?a:this}get wikidata(){var e,i,t;return null!==(t=null!==(e=this._wikidata)&&void 0!==e?e:null===(i=this.baseDefinition)||void 0===i?void 0:i.wikidata)&&void 0!==t?t:void 0}get description(){if(this.baseDefinition&&this.baseDefinition.description)return"string"==typeof this.baseDefinition.description?[this.baseDefinition.description]:this.baseDefinition.description}get url(){var e,i;return null!==(i=null===(e=this.baseDefinition)||void 0===e?void 0:e.url)&&void 0!==i?i:void 0}get complexity(){return 7}get head(){return"Symbol"}get symbol(){return this._name}get isNothing(){return"Nothing"===this._name}get isLiteral(){return!1}get baseDefinition(){var e;return null===this._def&&this.bind(this._scope),null!==(e=this._def)&&void 0!==e?e:void 0}get symbolDefinition(){return null===this._def&&this.bind(this._scope),ta(this._def)?this._def:void 0}get functionDefinition(){return null===this._def&&this.bind(this._scope),null!=(e=this._def)&&"signature"in e?this._def:void 0;var e}bind(e){if("_"===this._name[0]||null===e)return void(this._def=void 0);let i;if(i=this.engine.lookupSymbol(this._name,this._wikidata,e),(null==i?void 0:i.wikidata)&&this._wikidata&&i.wikidata!==this._wikidata&&(i=void 0),i)return this._name=i.name,void(this._def=i);i=this.engine.lookupFunction(this._name,e),i?this._def=i:null!==this.engine.defaultDomain&&(this._def=this.engine.defineSymbol(Object.assign({name:this._name,wikidata:this._wikidata,domain:this.engine.defaultDomain},zr(this.engine.defaultDomain))),this._name=this._def.name)}get value(){var e,i;return null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.value)&&void 0!==i?i:this}set value(e){var i,t;if("_"===this._name[0])throw Error(`The value of the wildcard "${this._name}" cannot be changed`);let n;if(this.engine.forget(this._name),void 0!==e){const t=this.engine.box(e);n=null!==(i=t.value)&&void 0!==i?i:t.evaluate()}(null==n?void 0:n.domain.isCompatible("Function"))?this._def=this.engine.defineFunction({name:this._name,signature:{domain:n.domain,evaluate:n}}):this._def&&ta(this._def)?this._def.value=n:this._def=this.engine.defineSymbol({name:this._name,value:n,domain:null!==(t=this.engine.defaultDomain)&&void 0!==t?t:this.engine.domain("Anything")})}get numericValue(){var e,i,t;return null!==(t=null===(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.value)||void 0===i?void 0:i.numericValue)&&void 0!==t?t:void 0}get domain(){var e,i;return this.functionDefinition?this.engine.domain("Function"):null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.domain)&&void 0!==i?i:this.engine.domain("Anything")}set domain(e){if("_"===this._name[0])throw Error(`The domain of the wildcard "${this._name}" cannot be changed`);e.isCompatible("Function")?(this.engine.forget(this._name),this._def=this.engine.defineFunction({name:this._name,signature:{domain:e}})):ta(this._def)?this._def.domain=e:(this.engine.forget(this._name),this._def=this.engine.defineSymbol(Object.assign({name:this._name,domain:e},zr(e))))}get explicitDomain(){var e,i;return this.functionDefinition?this.engine.domain("Function"):null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.domain)&&void 0!==i?i:void 0}get json(){return pn(this.engine,this._name,{latex:this._latex,wikidata:this._wikidata})}get sgn(){const e=this.numericValue;if(e&&e!==this){const i=e.sgn;if(void 0!==i)return i}const i=this.symbolDefinition;if(i){if(!0===i.zero)return 0;if(!0===i.positive)return 1;if(!0===i.negative)return-1}}has(e){return"string"==typeof e?this._name===e:e.includes(this._name)}isSame(e){return this===e||e instanceof na&&this._name===e._name}match(e,i){return e instanceof na&&this._name===e._name?{}:null}isEqual(e){var i,t;if(!this.isCanonical)return this.canonical.isEqual(e);if(this===(e=e.canonical))return!0;if(null!==e.symbol)return e.symbol===this._name;const n=null===(t=null===(i=this.symbolDefinition)||void 0===i?void 0:i.value)||void 0===t?void 0:t.numericValue;if(n){const i=e.numericValue;if(i)return n.isEqual(i)}if(e.isZero){if(this.isZero)return!0;if(this.isNotZero)return!1}return!(this.isZero&&e.isNotZero||!(this.engine.ask(["Equal",this,e]).length>0)&&(this.engine.ask(["NotEqual",this,e]).length,1))}isLess(e){if(null!==e.symbol&&e.symbol===this._name)return!1;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e<0}}isLessEqual(e){if(null!==e.symbol&&e.symbol===this._name)return!0;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e<=0}return this.isLess(e)||this.isEqual(e)}isGreater(e){if(null!==e.symbol&&e.symbol===this._name)return!1;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e>0}}isGreaterEqual(e){if(null!==e.symbol&&e.symbol===this._name)return!0;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e>=0}return this.isGreater(e)||this.isEqual(e)}get isFunction(){return!!this.functionDefinition}get isZero(){var e,i,t,n;return null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.zero)&&void 0!==i?i:null===(n=null===(t=this.symbolDefinition)||void 0===t?void 0:t.value)||void 0===n?void 0:n.isZero}get isNotZero(){var e;const i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.notZero;if("boolean"==typeof i)return i;const t=this.sgn;return"number"==typeof t?0!==t:void 0}get isOne(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.one}get isNegativeOne(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.negativeOne}get isOdd(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.odd}get isEven(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.even}get isPrime(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.prime}get isComposite(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.composite}get isInfinity(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.infinity}get isNaN(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.NaN}get isPositive(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.positive}get isNonPositive(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.nonPositive}get isNegative(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.negative}get isNonNegative(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.nonNegative}get isNumber(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.number}get isInteger(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.integer}get isRational(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.rational}get isAlgebraic(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.rational}get isReal(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.real}get isExtendedReal(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.extendedReal}get isComplex(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.complex}get isImaginary(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.imaginary}simplify(e){var i,t;const n=(null==e?void 0:e.rules)&&null!==(i=this.replace(e.rules))&&void 0!==i?i:this;if(!1===(null===(t=n.symbolDefinition)||void 0===t?void 0:t.hold)){const i=n.value;if(i)return i.simplify(e)}return n}evaluate(e){var i,t;const n=this.symbolDefinition;return n?!0===n.hold?this:null!==(t=null===(i=n.value)||void 0===i?void 0:i.evaluate(e))&&void 0!==t?t:this:this}N(e){var i,t,n,r;const a=null===(i=this.symbolDefinition)||void 0===i?void 0:i.value;return null!==(r=null!==(n=null!==(t=null==a?void 0:a.N(e))&&void 0!==t?t:null==a?void 0:a.evaluate(e))&&void 0!==n?n:a)&&void 0!==r?r:this}replace(e,i){return Dn(this,e,i)}subs(e){return e[this._name]?this.engine.box(e[this._name]):this}}class ra{constructor(e){var i,t,n,r;if(this._cache={},this._commonSymbols={True:null,False:null,Maybe:null,All:null,Nothing:null,None:null,Undefined:null,Pi:null,ImaginaryUnit:null},this._commonNumbers={0:null,1:null,2:null,3:null,4:null,5:null,6:null,7:null,8:null,9:null,10:null},this._commonDomains={Anything:null,Nothing:null,Boolean:null,MaybeBoolean:null,String:null,Domain:null,Symbol:null,Integer:null,RationalNumber:null,AlgebraicNumber:null,RealNumber:null,ExtendedRealNumber:null,ImaginaryNumber:null,ComplexNumber:null,ExtendedComplexNumber:null,Number:null,PositiveInteger:null,TranscendentalNumber:null,PositiveNumber:null,Function:null,NumericFunction:null,RealFunction:null,TrigonometricFunction:null,HyperbolicFunction:null,LogicOperator:null,Predicate:null,RelationalOperator:null,Expression:null,BooleanExpression:null,NumericExpression:null},void 0!==e&&"object"!=typeof e)throw Error("Unexpected argument");this._latexDictionary=null==e?void 0:e.latexDictionary,this._jsonSerializationOptions={exclude:[],shorthands:["function","symbol","string","dictionary","number"],metadata:[],repeatingDecimal:!0},this._stats={highwaterMark:0,symbols:new Set,expressions:new Set},this._defaultDomain=null,this._numericMode=null!==(i=null==e?void 0:e.numericMode)&&void 0!==i?i:"auto",this._precision=Math.max(null!==(t=null==e?void 0:e.numericPrecision)&&void 0!==t?t:100,Math.floor(kt)),this._decimal=Ze.clone({precision:this._precision}),this.tolerance=null!==(n=null==e?void 0:e.tolerance)&&void 0!==n?n:It,this._ZERO=new Hn(this,0),this._ONE=new Hn(this,1),this._TWO=new Hn(this,2),this._HALF=new Hn(this,[1,2]),this._NEGATIVE_ONE=new Hn(this,-1),this._I=new Hn(this,Be.exports.Complex.I),this._NAN=new Hn(this,NaN),this._POSITIVE_INFINITY=new Hn(this,1/0),this._NEGATIVE_INFINITY=new Hn(this,-1/0),this._COMPLEX_INFINITY=new Hn(this,Be.exports.Complex.INFINITY),this.reset();const a=null!==(r=null==e?void 0:e.symbolTables)&&void 0!==r?r:ra.getSymbolTables();this.pushScope({symbolTable:a,scope:{warn:e=>{for(const i of e)i.message},timeLimit:2,memoryLimit:1,recursionLimit:1024}}),null===(null==e?void 0:e.assumptions)?this.pushScope():this.pushScope({assumptions:null==e?void 0:e.assumptions});for(const e of Object.keys(this._commonDomains))this._commonDomains[e]&&!this._commonDomains[e].symbolDefinition&&this._commonDomains[e].bind(this.context);for(const e of Object.keys(this._commonSymbols))this._commonSymbols[e]&&!this._commonSymbols[e].symbolDefinition&&this._commonSymbols[e].bind(this.context);if(null==e?void 0:e.defaultDomain){const i=this.domain(e.defaultDomain);i.isValid?this._defaultDomain=i:this._defaultDomain=this.domain("ExtendedRealNumber")}else this._defaultDomain=this.domain("ExtendedRealNumber")}static getSymbolTables(e="all"){return Gr(e)}reset(){var e,i;this._DECIMAL_NEGATIVE_ONE=this.decimal(-1),this._DECIMAL_NAN=this.decimal(NaN),this._DECIMAL_ZERO=this.decimal(0),this._DECIMAL_ONE=this.decimal(1),this._DECIMAL_TWO=this.decimal(2),this._DECIMAL_HALF=this._DECIMAL_ONE.div(this._DECIMAL_TWO),this._DECIMAL_PI=this._DECIMAL_NEGATIVE_ONE.acos();const t=this._stats.symbols.values(),n=this._stats.expressions.values();this._stats.symbols=new Set,this._stats.expressions=new Set;for(const e of t)e.unbind();for(const e of n)e.unbind();for(const e of Object.values(this._commonDomains))null==e||e.unbind();for(const e of Object.values(this._commonSymbols))null==e||e.unbind();let r=this.context;for(;r;){if(null===(e=r.symbolTable)||void 0===e?void 0:e.functions)for(const[e,i]of r.symbolTable.functions)i.reset();if(null===(i=r.symbolTable)||void 0===i?void 0:i.symbols)for(const[e,i]of r.symbolTable.symbols)i.reset();r=r.parentScope}for(const e of Object.keys(this._cache))this._cache[e].value&&(this._cache[e].purge?this._cache[e].value=this._cache[e].purge(this._cache[e].value):delete this._cache[e])}_register(e){this._stats.highwaterMark+=1}_unregister(e){}get stats(){const e=this._stats.expressions;return this._stats.expressions=null,this._stats.expressions=e,Object.assign({},this._stats)}get precision(){return this._precision}set precision(e){if("machine"===e&&(e=Math.floor(kt)),e!==this._precision){if("number"!=typeof e||e<=0)throw Error('Expected "machine" or a positive number');this._latexSyntax&&this.latexSyntax.updateOptions({precision:e,avoidExponentsInRange:[-6,e]}),this._precision=Math.max(e,Math.floor(kt)),this._decimal=this._decimal.config({precision:this._precision}),this.reset()}}get numericMode(){return this._numericMode}set numericMode(e){if(e!==this._numericMode){if("string"!=typeof e)throw Error("Expected a string");this._numericMode=e,"complex"!==e&&"machine"!==e||(this._precision=Math.floor(kt)),this._latexSyntax&&this.latexSyntax.options.precision>this._precision&&this.latexSyntax.updateOptions({precision:this._precision}),this.reset()}}get timeLimit(){let e=this.context;for(;e;){if(void 0!==e.timeLimit)return e.timeLimit;e=e.parentScope}return 2}get iterationLimit(){let e=this.context;for(;e;){if(void 0!==e.iterationLimit)return e.iterationLimit;e=e.parentScope}return 1024}get recursionLimit(){let e=this.context;for(;e;){if(void 0!==e.recursionLimit)return e.recursionLimit;e=e.parentScope}return 1024}get defaultDomain(){return this._defaultDomain}set defaultDomain(e){if(null===e)this._defaultDomain=null;else{const i=this.domain(e);if(!i.isValid)throw Error("Invalid domain "+e);this._defaultDomain=i}}get tolerance(){return this._tolerance}set tolerance(e){this._tolerance="number"==typeof e&&Number.isFinite(e)?Math.max(e,0):It,this._decimalTolerance=this.decimal(this._tolerance)}decimal(e){return new this._decimal(e)}complex(e,i){return new Be.exports.Complex(e,i)}chop(e){return"number"==typeof e&&Math.abs(e)<=this._tolerance||e instanceof Ze&&e.abs().lte(this._decimalTolerance)||e instanceof Be.exports.Complex&&Math.abs(e.re)<=this._tolerance&&Math.abs(e.im)<=this._tolerance?0:e}get latexSyntax(){return this._latexSyntax||(this._latexSyntax=new yt({computeEngine:this,dictionary:this._latexDictionary,precision:this.precision,avoidExponentsInRange:[-6,this.precision],onError:e=>{throw Error(e[0].message.toString())}})),this._latexSyntax}static getLatexDictionary(e="all"){return yt.getDictionary(e)}set costFunction(e){"function"!=typeof e&&(this._cost=Yr),this._cost=e}get costFunction(){var e;return null!==(e=this._cost)&&void 0!==e?e:Yr}lookupSymbol(e,i,t){var n,r;if("string"!=typeof e)throw Error("Expected a string");if(e.startsWith("_")||!this.context)return;let a;if(null!=t||(t=this.context),i)for(;t&&!a;)a=null===(n=t.symbolTable)||void 0===n?void 0:n.symbolWikidata.get(i),t=t.parentScope;if(e.length>0)for(t=this.context;t&&!a;)a=null===(r=t.symbolTable)||void 0===r?void 0:r.symbols.get(e),t=t.parentScope;return a}lookupFunction(e,i){var t;if("string"!=typeof e)throw Error("Expected a string");if(!e.startsWith("_")&&this.context)for(null!=i||(i=this.context);i;){const n=null===(t=i.symbolTable)||void 0===t?void 0:t.functions.get(e);if(n)return n;i=i.parentScope}}defineSymbol(e){if(!this.context)throw Error("Symbol cannot be defined: no scope available");const i=new jr(this,e);return this.context.symbolTable||(this.context.symbolTable={symbols:new Map,functions:new Map,symbolWikidata:new Map,functionWikidata:new Map}),i.name&&this.context.symbolTable.symbols.set(i.name,i),i.wikidata&&this.context.symbolTable.symbolWikidata.set(i.wikidata,i),i}defineFunction(e){if(!this.context)throw Error("Function cannot be defined: no scope available");const i=Br(this,e);return this.context.symbolTable||(this.context.symbolTable={symbols:new Map,functions:new Map,symbolWikidata:new Map,functionWikidata:new Map}),i.name&&this.context.symbolTable.functions.set(e.name,i),i.wikidata&&this.context.symbolTable.functionWikidata.set(i.wikidata,i),i}pushScope(e){var i;if(void 0!==e&&"object"!=typeof e)throw Error("Expected an object literal");if(null===this.context)throw Error("No parent scope available");if(this.context=Object.assign(Object.assign({},null==e?void 0:e.scope),{parentScope:this.context,assumptions:this.context?new Kr(this.context.assumptions):new Kr}),null==e?void 0:e.symbolTable)if(Array.isArray(e.symbolTable))for(const i of e.symbolTable)Ur(this,i);else Ur(this,e.symbolTable);if(void 0!==(null==e?void 0:e.assumptions))for(const t of e.assumptions)this.assume(null!==(i=this.parse(zt(t)))&&void 0!==i?i:t)}popScope(){var e;if(!this.context)throw Error("No scope available");const i=null===(e=this.context)||void 0===e?void 0:e.parentScope;if(this.context.warnings){const e=[...this.context.warnings];this.context.warnings=[],this.context.warn&&this.context.warn(e)}i&&this.context.warnings&&this.context.warnings.length>0&&(i.warnings?i.warnings=[...i.warnings,...this.context.warnings]:i.warnings=[...this.context.warnings]),this.context=i}get assumptions(){if(!this.context)throw Error("No scope available");return this.context.assumptions||(this.context.assumptions=new Kr),this.context.assumptions}shouldContinueExecution(){return void 0===this.deadline||this.deadline>=Date.now()}checkContinueExecution(){if(!this.shouldContinueExecution())throw Error("timeout")}assert(e,i,t,n){e||this.signal(i,t,n)}signal(e,i,t){"object"==typeof e&&"message"in e?t=e.message:e.latex,void 0===t||"string"==typeof t||Array.isArray(t)&&t.map((e=>e.toString())).join(", ")}cache(e,i,t){var n;if(void 0===this._cache[e])try{this._cache[e]={build:i,purge:t,value:i()}}catch(e){}return null===(n=this._cache[e])||void 0===n?void 0:n.value}box(e){return Un(this,e)}fn(e,i,t){var n,r,a,s,o,l,u,c,h,m,d;if("Hold"===e)return this._fn("Hold",i,t);if(i=i.map((e=>e.canonical)),"String"===e)return this.string(i.map((e=>{var i;return null!==(i=e.string)&&void 0!==i?i:e.latex})).join(""),t);if("Symbol"===e)return this.symbol(i.map((e=>{var i;return null!==(i=e.string)&&void 0!==i?i:e.latex})).join(""),t);if(("Divide"===e||"Rational"===e)&&2===i.length){const[e,t]=[null!==(n=i[0].machineValue)&&void 0!==n?n:i[0].asSmallInteger,null!==(r=i[1].machineValue)&&void 0!==r?r:i[1].asSmallInteger];if(null!==e&&null!==t&&Number.isInteger(e)&&Number.isInteger(t))return this.number([e,t])}if("Number"===e){if(1===i.length){const e=i[0],t=null!==(s=null!==(a=e.decimalValue)&&void 0!==a?a:e.complexValue)&&void 0!==s?s:e.machineValue;if(null!==t)return this.number(t);const[n,r]=e.rationalValue;if(null!==n&&null!==r)return this.number([n,r])}return this._NAN}if("Complex"===e){if(1===i.length){const e=i[0].asFloat;return null!==e?this.number(this.complex(0,e)):this.mul([i[0],this._I])}if(2===i.length){const e=i[0].asFloat,n=i[1].asFloat;return null!==e&&null!==n&&this.number(this.complex(e,n)),0===n?i[0]:this.add([i[0],this.mul([i[1],this._I])],t)}}if("Negate"===e&&1===i.length)return er(null!==(o=i[0])&&void 0!==o?o:this.error("missing"),t);if("Single"===e||"Pair"===e||"Triple"===e||"KeyValuePair"===e)return this.tuple(i,t);if("Dictionary"===e){const e={};for(const t of i)if("Tuple"===t.head){const i=t.op1;if(i.isValid&&!i.isNothing){t.op2;let n=null!==(l=i.symbol)&&void 0!==l?l:i.string;if(!n&&i.isLiteral){const e=null!==(u=i.machineValue)&&void 0!==u?u:i.asSmallInteger;e&&Number.isFinite(e)&&Number.isInteger(e)&&(n=e.toString())}n&&e[n]}}return new Tn(this,e,t)}return"Add"===e?this.add(i,t):"Multiply"===e?this.mul(i,t):"Divide"===e?this.divide(null!==(c=i[0])&&void 0!==c?c:this.error("missing"),null!==(h=i[1])&&void 0!==h?h:this.error("missing"),t):"Power"===e?this.power(null!==(m=i[0])&&void 0!==m?m:this.error("missing"),null!==(d=i[1])&&void 0!==d?d:this.error("missing"),t):zn(this,e,i,{metadata:t})}_fn(e,i,t){return new Rn(this,e,i,{metadata:t,canonical:!0,def:"string"==typeof e&&this.context?this.lookupFunction(e,this.context):void 0})}error(e,i){if(i&&Array.isArray(i)&&"Latex"===i[0]&&(void 0!==i[1]&&i[1]||(i=""),"object"==typeof i[1]&&"str"in i[1]&&!i[1].str&&(i="")),Array.isArray(e)&&"invalid-domain"===e[0])return xn(this,["Error",["ErrorCode","'invalid-domain'",e[1]]]);const t="string"==typeof e?this.string(e):this._fn("ErrorCode",[this.string(e[0]),...e.slice(1).map((e=>this.box(e).canonical))]);return i?this._fn("Error",[t,this.box(i).canonical]):this._fn("Error",[t])}add(e,i){const t=rr(this,e);return void 0!==(null==i?void 0:i.latex)&&(t.latex=i.latex),void 0!==(null==i?void 0:i.wikidata)&&(t.wikidata=i.wikidata),t}mul(e,i){const t=cr(this,e);return void 0!==(null==i?void 0:i.latex)&&(t.latex=i.latex),void 0!==(null==i?void 0:i.wikidata)&&(t.wikidata=i.wikidata),t}power(e,i,t){var n;let r=null;if("number"==typeof i?r=i:Array.isArray(i)?1===i[1]&&(r=i[0]):r=i.machineValue,1===r)return e;if(-1===r&&e.isLiteral){const[i,t]=e.rationalValue;if(null!==i&&null!==t)return this.number([t,i]);const n=e.asSmallInteger;if(null!==n)return this.number([1,n])}return("number"==typeof i||Array.isArray(i))&&(i=this.number(i)),null!==(n=or(this,e,i,t))&&void 0!==n?n:this._fn("Power",[e,i],t)}inverse(e,i){var t;let n=this._NEGATIVE_ONE;if("Power"===e.head){if(e.op2.isNegativeOne)return e.op1;n=er(e.op2),e=e.op1}return null!==(t=or(this,e,n,i))&&void 0!==t?t:this._fn("Power",[e,n],i)}negate(e,i){return er(e,i)}divide(e,i,t){const n=fr(this,e,i);return void 0!==(null==t?void 0:t.latex)&&(n.latex=t.latex),void 0!==(null==t?void 0:t.wikidata)&&(n.wikidata=t.wikidata),n}pair(e,i,t){return this._fn("Tuple",[e.canonical,i.canonical],t)}tuple(e,i){return this._fn("Tuple",e.map((e=>e.canonical)),i)}string(e,i){return new Wn(this,e,i)}symbol(e,i){var t;if("NaN"===(e=e.normalize()))return this._NAN;if("Infinity"===e)return this._POSITIVE_INFINITY;if("+Infinity"===e)return this._POSITIVE_INFINITY;if("-Infinity"===e)return this._NEGATIVE_INFINITY;if("Half"===e)return this._HALF;if(!ui(e))return this.error(["invalid-symbol-name",{str:e}],["Latex",{str:null!==(t=null==i?void 0:i.latex)&&void 0!==t?t:""}]);if(void 0!==(null==i?void 0:i.latex))return new na(this,e,i);let n=this._commonSymbols[e];return n?(null==i?void 0:i.wikidata)&&n.wikidata&&n.wikidata!==i.wikidata?new na(this,e,i):n:null===n?(n=new na(this,e),this._commonSymbols[e]=n,n):new na(this,e,i)}domain(e,i){var t;return e instanceof yn?e:(e instanceof Qt&&e.symbol&&(e=e.symbol),"string"==typeof e&&(null===this._commonDomains[e]&&(this._commonDomains[e]=xn(this,e,i)),this._commonDomains[e])?this._commonDomains[e]:wn(e)?xn(this,e,i):this.error(["invalid-domain",{str:JSON.stringify(e)}],["Latex",{str:null!==(t=null==i?void 0:i.latex)&&void 0!==t?t:""}]))}lambda(e,i){const t=this.context;this.context=null;const n=this.box(e);return this.context=t,n}number(e,i){var t,n;if(Array.isArray(e)&&1===e[1]&&(e=e[0]),"number"==typeof e){if(-1===e)return this._NEGATIVE_ONE;if(null===this._commonNumbers[e]&&(this._commonNumbers[e]=null!==(t=Qn(this,e))&&void 0!==t?t:null),this._commonNumbers[e])return this._commonNumbers[e]}return null!==(n=Qn(this,e,i))&&void 0!==n?n:this._NAN}rules(e){return qn(this,e)}pattern(e){return new Jr(this,e)}parse(e){var i;return"string"!=typeof e?null:this.box(this.latexSyntax.parse(null!==(i=zt(e))&&void 0!==i?i:e))}serialize(e){return"object"==typeof e&&"json"in e?this.latexSyntax.serialize(e.json):this.latexSyntax.serialize(e)}get latexOptions(){const e=this.latexSyntax;return new Proxy(Object.assign(Object.assign({},this.latexSyntax.options),this.latexSyntax.serializer.options),{set:(i,t,n)=>t in i&&(e.updateOptions({[t]:n}),!0)})}set latexOptions(e){this.latexSyntax.updateOptions(e)}get jsonSerializationOptions(){return this._jsonSerializationOptions}set jsonSerializationOptions(e){e.exclude&&(this._jsonSerializationOptions.exclude=[...e.exclude]),e.shorthands&&("all"===e.shorthands||e.shorthands.includes("all")?this._jsonSerializationOptions.shorthands=["function","symbol","string","dictionary","number"]:this._jsonSerializationOptions.shorthands=[...e.shorthands]),e.metadata&&("all"===e.metadata||e.metadata.includes("all")?this._jsonSerializationOptions.metadata=["latex","wikidata"]:this._jsonSerializationOptions.metadata=[...e.metadata])}ask(e){const i=this.pattern(e),t=[];for(const[e,n]of this.assumptions){const r=i.match(e,{numericTolerance:this._tolerance});null!==r&&!0===n&&t.push(r)}return t}infer(e,i){if("string"!=typeof e){if(!e.symbol)return"internal-error";e=e.symbol}return"ok"}assume(e,i){try{const t=zt(e),n=t?this.parse(t):this.box(e);return i?wn(i)?Vn(this.box(["Element",n,this.domain(i)])):Vn(this.box(["Equal",n,i])):Vn(n)}catch(e){return"internal-error"}}forget(e){if(!this.context)throw Error("No scope available");if(void 0===e)return this.context.symbolTable=void 0,void this.assumptions.clear();if(Array.isArray(e))for(const i of e)this.forget(i);else if("string"==typeof e){this.context.symbolTable&&(this.context.symbolTable.symbols.delete(e),this.context.symbolTable.symbolWikidata.delete(e),this.context.symbolTable.functions.delete(e),this.context.symbolTable.functionWikidata.delete(e));for(const[i,t]of this.assumptions)jt(i).includes(e)&&this.assumptions.delete(i)}}}e.ComputeEngine=ra,e.getVars=jt,e.isEnvironmentEntry=o,e.isFunctionEntry=t,e.isInfixEntry=r,e.isMatchfixEntry=n,e.isPostfixEntry=s,e.isPrefixEntry=a,e.isSymbolEntry=i,e.version="0.8.0",Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).ComputeEngine={});
1
+ /** CortexJS Compute Engine 0.9.0 */
2
+ var global,factory;global=this,factory=function(e){function i(e){return!("kind"in e)||"symbol"===e.kind}function n(e){return!("kind"in e)||"function"===e.kind}function t(e){return"kind"in e&&"matchfix"===e.kind}function r(e){return"kind"in e&&"infix"===e.kind}function s(e){return"kind"in e&&"prefix"===e.kind}function o(e){return"kind"in e&&"postfix"===e.kind}function a(e){return"kind"in e&&"environment"===e.kind}var l,u,c=9e15,h=1e9,m="0123456789abcdef",d="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",f="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",g={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-c,maxE:c,crypto:!1},p=!0,v="[DecimalError] ",b=v+"Invalid argument: ",y=v+"Precision limit exceeded",N=v+"crypto unavailable",_="[object Decimal]",x=Math.floor,S=Math.pow,w=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,k=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,E=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,A=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,I=1e7,M=d.length-1,q=f.length-1,O={toStringTag:_};function T(e){var i,n,t,r=e.length-1,s="",o=e[0];if(r>0){for(s+=o,i=1;i<r;i++)(n=7-(t=e[i]+"").length)&&(s+=G(n)),s+=t;(n=7-(t=(o=e[i])+"").length)&&(s+=G(n))}else if(0===o)return"0";for(;o%10==0;)o/=10;return s+o}function F(e,i,n){if(e!==~~e||e<i||e>n)throw Error(b+e)}function C(e,i,n,t){var r,s,o,a;for(s=e[0];s>=10;s/=10)--i;return--i<0?(i+=7,r=0):(r=Math.ceil((i+1)/7),i%=7),s=S(10,7-i),a=e[r]%s|0,null==t?i<3?(0==i?a=a/100|0:1==i&&(a=a/10|0),o=n<4&&99999==a||n>3&&49999==a||5e4==a||0==a):o=(n<4&&a+1==s||n>3&&a+1==s/2)&&(e[r+1]/s/100|0)==S(10,i-2)-1||(a==s/2||0==a)&&0==(e[r+1]/s/100|0):i<4?(0==i?a=a/1e3|0:1==i?a=a/100|0:2==i&&(a=a/10|0),o=(t||n<4)&&9999==a||!t&&n>3&&4999==a):o=((t||n<4)&&a+1==s||!t&&n>3&&a+1==s/2)&&(e[r+1]/s/1e3|0)==S(10,i-3)-1,o}function D(e,i,n){for(var t,r,s=[0],o=0,a=e.length;o<a;){for(r=s.length;r--;)s[r]*=i;for(s[0]+=m.indexOf(e.charAt(o++)),t=0;t<s.length;t++)s[t]>n-1&&(void 0===s[t+1]&&(s[t+1]=0),s[t+1]+=s[t]/n|0,s[t]%=n)}return s.reverse()}O.absoluteValue=O.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),L(e)},O.ceil=function(){return L(new this.constructor(this),this.e+1,2)},O.clampedTo=O.clamp=function(e,i){var n=this,t=n.constructor;if(e=new t(e),i=new t(i),!e.s||!i.s)return new t(NaN);if(e.gt(i))throw Error(b+i);return n.cmp(e)<0?e:n.cmp(i)>0?i:new t(n)},O.comparedTo=O.cmp=function(e){var i,n,t,r,s=this,o=s.d,a=(e=new s.constructor(e)).d,l=s.s,u=e.s;if(!o||!a)return l&&u?l!==u?l:o===a?0:!o^l<0?1:-1:NaN;if(!o[0]||!a[0])return o[0]?l:a[0]?-u:0;if(l!==u)return l;if(s.e!==e.e)return s.e>e.e^l<0?1:-1;for(i=0,n=(t=o.length)<(r=a.length)?t:r;i<n;++i)if(o[i]!==a[i])return o[i]>a[i]^l<0?1:-1;return t===r?0:t>r^l<0?1:-1},O.cosine=O.cos=function(){var e,i,n=this,t=n.constructor;return n.d?n.d[0]?(e=t.precision,i=t.rounding,t.precision=e+Math.max(n.e,n.sd())+7,t.rounding=1,n=function(e,i){var n,t,r;if(i.isZero())return i;(t=i.d.length)<32?r=""+1/X(4,n=Math.ceil(t/3)):(n=16,r="2.3283064365386962890625e-10"),e.precision+=n,i=K(e,1,i.times(r),new e(1));for(var s=n;s--;){var o=i.times(i);i=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,i}(t,ee(t,n)),t.precision=e,t.rounding=i,L(2==u||3==u?n.neg():n,e,i,!0)):new t(1):new t(NaN)},O.cubeRoot=O.cbrt=function(){var e,i,n,t,r,s,o,a,l,u,c=this,h=c.constructor;if(!c.isFinite()||c.isZero())return new h(c);for(p=!1,(s=c.s*S(c.s*c,1/3))&&Math.abs(s)!=1/0?t=new h(s.toString()):(n=T(c.d),(s=((e=c.e)-n.length+1)%3)&&(n+=1==s||-2==s?"0":"00"),s=S(n,1/3),e=x((e+1)/3)-(e%3==(e<0?-1:2)),(t=new h(n=s==1/0?"5e"+e:(n=s.toExponential()).slice(0,n.indexOf("e")+1)+e)).s=c.s),o=(e=h.precision)+3;;)if(u=(l=(a=t).times(a).times(a)).plus(c),t=P(u.plus(c).times(a),u.plus(l),o+2,1),T(a.d).slice(0,o)===(n=T(t.d)).slice(0,o)){if("9999"!=(n=n.slice(o-3,o+1))&&(r||"4999"!=n)){+n&&(+n.slice(1)||"5"!=n.charAt(0))||(L(t,e+1,1),i=!t.times(t).times(t).eq(c));break}if(!r&&(L(a,e+1,0),a.times(a).times(a).eq(c))){t=a;break}o+=4,r=1}return p=!0,L(t,e,h.rounding,i)},O.decimalPlaces=O.dp=function(){var e,i=this.d,n=NaN;if(i){if(n=7*((e=i.length-1)-x(this.e/7)),e=i[e])for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},O.dividedBy=O.div=function(e){return P(this,new this.constructor(e))},O.dividedToIntegerBy=O.divToInt=function(e){var i=this.constructor;return L(P(this,new i(e),0,1,1),i.precision,i.rounding)},O.equals=O.eq=function(e){return 0===this.cmp(e)},O.floor=function(){return L(new this.constructor(this),this.e+1,3)},O.greaterThan=O.gt=function(e){return this.cmp(e)>0},O.greaterThanOrEqualTo=O.gte=function(e){var i=this.cmp(e);return 1==i||0===i},O.hyperbolicCosine=O.cosh=function(){var e,i,n,t,r,s=this,o=s.constructor,a=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return a;n=o.precision,t=o.rounding,o.precision=n+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?i=""+1/X(4,e=Math.ceil(r/3)):(e=16,i="2.3283064365386962890625e-10"),s=K(o,1,s.times(i),new o(1),!0);for(var l,u=e,c=new o(8);u--;)l=s.times(s),s=a.minus(l.times(c.minus(l.times(c))));return L(s,o.precision=n,o.rounding=t,!0)},O.hyperbolicSine=O.sinh=function(){var e,i,n,t,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(i=s.precision,n=s.rounding,s.precision=i+Math.max(r.e,r.sd())+4,s.rounding=1,(t=r.d.length)<3)r=K(s,2,r,r,!0);else{e=(e=1.4*Math.sqrt(t))>16?16:0|e,r=K(s,2,r=r.times(1/X(5,e)),r,!0);for(var o,a=new s(5),l=new s(16),u=new s(20);e--;)o=r.times(r),r=r.times(a.plus(o.times(l.times(o).plus(u))))}return s.precision=i,s.rounding=n,L(r,i,n,!0)},O.hyperbolicTangent=O.tanh=function(){var e,i,n=this,t=n.constructor;return n.isFinite()?n.isZero()?new t(n):(e=t.precision,i=t.rounding,t.precision=e+7,t.rounding=1,P(n.sinh(),n.cosh(),t.precision=e,t.rounding=i)):new t(n.s)},O.inverseCosine=O.acos=function(){var e,i=this,n=i.constructor,t=i.abs().cmp(1),r=n.precision,s=n.rounding;return-1!==t?0===t?i.isNeg()?V(n,r,s):new n(0):new n(NaN):i.isZero()?V(n,r+4,s).times(.5):(n.precision=r+6,n.rounding=1,i=i.asin(),e=V(n,r+4,s).times(.5),n.precision=r,n.rounding=s,e.minus(i))},O.inverseHyperbolicCosine=O.acosh=function(){var e,i,n=this,t=n.constructor;return n.lte(1)?new t(n.eq(1)?0:NaN):n.isFinite()?(e=t.precision,i=t.rounding,t.precision=e+Math.max(Math.abs(n.e),n.sd())+4,t.rounding=1,p=!1,n=n.times(n).minus(1).sqrt().plus(n),p=!0,t.precision=e,t.rounding=i,n.ln()):new t(n)},O.inverseHyperbolicSine=O.asinh=function(){var e,i,n=this,t=n.constructor;return!n.isFinite()||n.isZero()?new t(n):(e=t.precision,i=t.rounding,t.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,t.rounding=1,p=!1,n=n.times(n).plus(1).sqrt().plus(n),p=!0,t.precision=e,t.rounding=i,n.ln())},O.inverseHyperbolicTangent=O.atanh=function(){var e,i,n,t,r=this,s=r.constructor;return r.isFinite()?r.e>=0?new s(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(e=s.precision,i=s.rounding,t=r.sd(),Math.max(t,e)<2*-r.e-1?L(new s(r),e,i,!0):(s.precision=n=t-r.e,r=P(r.plus(1),new s(1).minus(r),n+e,1),s.precision=e+4,s.rounding=1,r=r.ln(),s.precision=e,s.rounding=i,r.times(.5))):new s(NaN)},O.inverseSine=O.asin=function(){var e,i,n,t,r=this,s=r.constructor;return r.isZero()?new s(r):(i=r.abs().cmp(1),n=s.precision,t=s.rounding,-1!==i?0===i?((e=V(s,n+4,t).times(.5)).s=r.s,e):new s(NaN):(s.precision=n+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=n,s.rounding=t,r.times(2)))},O.inverseTangent=O.atan=function(){var e,i,n,t,r,s,o,a,l,u=this,c=u.constructor,h=c.precision,m=c.rounding;if(u.isFinite()){if(u.isZero())return new c(u);if(u.abs().eq(1)&&h+4<=q)return(o=V(c,h+4,m).times(.25)).s=u.s,o}else{if(!u.s)return new c(NaN);if(h+4<=q)return(o=V(c,h+4,m).times(.5)).s=u.s,o}for(c.precision=a=h+10,c.rounding=1,e=n=Math.min(28,a/7+2|0);e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(p=!1,i=Math.ceil(a/7),t=1,l=u.times(u),o=new c(u),r=u;-1!==e;)if(r=r.times(l),s=o.minus(r.div(t+=2)),r=r.times(l),void 0!==(o=s.plus(r.div(t+=2))).d[i])for(e=i;o.d[e]===s.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),p=!0,L(o,c.precision=h,c.rounding=m,!0)},O.isFinite=function(){return!!this.d},O.isInteger=O.isInt=function(){return!!this.d&&x(this.e/7)>this.d.length-2},O.isNaN=function(){return!this.s},O.isNegative=O.isNeg=function(){return this.s<0},O.isPositive=O.isPos=function(){return this.s>0},O.isZero=function(){return!!this.d&&0===this.d[0]},O.lessThan=O.lt=function(e){return this.cmp(e)<0},O.lessThanOrEqualTo=O.lte=function(e){return this.cmp(e)<1},O.logarithm=O.log=function(e){var i,n,t,r,s,o,a,l,u=this,c=u.constructor,h=c.precision,m=c.rounding;if(null==e)e=new c(10),i=!0;else{if(n=(e=new c(e)).d,e.s<0||!n||!n[0]||e.eq(1))return new c(NaN);i=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new c(n&&!n[0]?-1/0:1!=u.s?NaN:n?0:1/0);if(i)if(n.length>1)s=!0;else{for(r=n[0];r%10==0;)r/=10;s=1!==r}if(p=!1,o=W(u,a=h+5),t=i?$(c,a+10):W(e,a),C((l=P(o,t,a,1)).d,r=h,m))do{if(o=W(u,a+=10),t=i?$(c,a+10):W(e,a),l=P(o,t,a,1),!s){+T(l.d).slice(r+1,r+15)+1==1e14&&(l=L(l,h+1,0));break}}while(C(l.d,r+=10,m));return p=!0,L(l,h,m)},O.minus=O.sub=function(e){var i,n,t,r,s,o,a,l,u,c,h,m,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return d.s&&e.s?d.d?e.s=-e.s:e=new f(e.d||d.s!==e.s?d:NaN):e=new f(NaN),e;if(d.s!=e.s)return e.s=-e.s,d.plus(e);if(u=d.d,m=e.d,a=f.precision,l=f.rounding,!u[0]||!m[0]){if(m[0])e.s=-e.s;else{if(!u[0])return new f(3===l?-0:0);e=new f(d)}return p?L(e,a,l):e}if(n=x(e.e/7),c=x(d.e/7),u=u.slice(),s=c-n){for((h=s<0)?(i=u,s=-s,o=m.length):(i=m,n=c,o=u.length),s>(t=Math.max(Math.ceil(a/7),o)+2)&&(s=t,i.length=1),i.reverse(),t=s;t--;)i.push(0);i.reverse()}else{for((h=(t=u.length)<(o=m.length))&&(o=t),t=0;t<o;t++)if(u[t]!=m[t]){h=u[t]<m[t];break}s=0}for(h&&(i=u,u=m,m=i,e.s=-e.s),o=u.length,t=m.length-o;t>0;--t)u[o++]=0;for(t=m.length;t>s;){if(u[--t]<m[t]){for(r=t;r&&0===u[--r];)u[r]=I-1;--u[r],u[t]+=I}u[t]-=m[t]}for(;0===u[--o];)u.pop();for(;0===u[0];u.shift())--n;return u[0]?(e.d=u,e.e=z(u,n),p?L(e,a,l):e):new f(3===l?-0:0)},O.modulo=O.mod=function(e){var i,n=this,t=n.constructor;return e=new t(e),!n.d||!e.s||e.d&&!e.d[0]?new t(NaN):!e.d||n.d&&!n.d[0]?L(new t(n),t.precision,t.rounding):(p=!1,9==t.modulo?(i=P(n,e.abs(),0,3,1)).s*=e.s:i=P(n,e,0,t.modulo,1),i=i.times(e),p=!0,n.minus(i))},O.naturalExponential=O.exp=function(){return H(this)},O.naturalLogarithm=O.ln=function(){return W(this)},O.negated=O.neg=function(){var e=new this.constructor(this);return e.s=-e.s,L(e)},O.plus=O.add=function(e){var i,n,t,r,s,o,a,l,u,c,h=this,m=h.constructor;if(e=new m(e),!h.d||!e.d)return h.s&&e.s?h.d||(e=new m(e.d||h.s===e.s?h:NaN)):e=new m(NaN),e;if(h.s!=e.s)return e.s=-e.s,h.minus(e);if(u=h.d,c=e.d,a=m.precision,l=m.rounding,!u[0]||!c[0])return c[0]||(e=new m(h)),p?L(e,a,l):e;if(s=x(h.e/7),t=x(e.e/7),u=u.slice(),r=s-t){for(r<0?(n=u,r=-r,o=c.length):(n=c,t=s,o=u.length),r>(o=(s=Math.ceil(a/7))>o?s+1:o+1)&&(r=o,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for((o=u.length)-(r=c.length)<0&&(r=o,n=c,c=u,u=n),i=0;r;)i=(u[--r]=u[r]+c[r]+i)/I|0,u[r]%=I;for(i&&(u.unshift(i),++t),o=u.length;0==u[--o];)u.pop();return e.d=u,e.e=z(u,t),p?L(e,a,l):e},O.precision=O.sd=function(e){var i,n=this;if(void 0!==e&&e!==!!e&&1!==e&&0!==e)throw Error(b+e);return n.d?(i=j(n.d),e&&n.e+1>i&&(i=n.e+1)):i=NaN,i},O.round=function(){var e=this,i=e.constructor;return L(new i(e),e.e+1,i.rounding)},O.sine=O.sin=function(){var e,i,n=this,t=n.constructor;return n.isFinite()?n.isZero()?new t(n):(e=t.precision,i=t.rounding,t.precision=e+Math.max(n.e,n.sd())+7,t.rounding=1,n=function(e,i){var n,t=i.d.length;if(t<3)return i.isZero()?i:K(e,2,i,i);n=(n=1.4*Math.sqrt(t))>16?16:0|n,i=K(e,2,i=i.times(1/X(5,n)),i);for(var r,s=new e(5),o=new e(16),a=new e(20);n--;)r=i.times(i),i=i.times(s.plus(r.times(o.times(r).minus(a))));return i}(t,ee(t,n)),t.precision=e,t.rounding=i,L(u>2?n.neg():n,e,i,!0)):new t(NaN)},O.squareRoot=O.sqrt=function(){var e,i,n,t,r,s,o=this,a=o.d,l=o.e,u=o.s,c=o.constructor;if(1!==u||!a||!a[0])return new c(!u||u<0&&(!a||a[0])?NaN:a?o:1/0);for(p=!1,0==(u=Math.sqrt(+o))||u==1/0?(((i=T(a)).length+l)%2==0&&(i+="0"),u=Math.sqrt(i),l=x((l+1)/2)-(l<0||l%2),t=new c(i=u==1/0?"5e"+l:(i=u.toExponential()).slice(0,i.indexOf("e")+1)+l)):t=new c(u.toString()),n=(l=c.precision)+3;;)if(t=(s=t).plus(P(o,s,n+2,1)).times(.5),T(s.d).slice(0,n)===(i=T(t.d)).slice(0,n)){if("9999"!=(i=i.slice(n-3,n+1))&&(r||"4999"!=i)){+i&&(+i.slice(1)||"5"!=i.charAt(0))||(L(t,l+1,1),e=!t.times(t).eq(o));break}if(!r&&(L(s,l+1,0),s.times(s).eq(o))){t=s;break}n+=4,r=1}return p=!0,L(t,l,c.rounding,e)},O.tangent=O.tan=function(){var e,i,n=this,t=n.constructor;return n.isFinite()?n.isZero()?new t(n):(e=t.precision,i=t.rounding,t.precision=e+10,t.rounding=1,(n=n.sin()).s=1,n=P(n,new t(1).minus(n.times(n)).sqrt(),e+10,0),t.precision=e,t.rounding=i,L(2==u||4==u?n.neg():n,e,i,!0)):new t(NaN)},O.times=O.mul=function(e){var i,n,t,r,s,o,a,l,u,c=this,h=c.constructor,m=c.d,d=(e=new h(e)).d;if(e.s*=c.s,!(m&&m[0]&&d&&d[0]))return new h(!e.s||m&&!m[0]&&!d||d&&!d[0]&&!m?NaN:m&&d?0*e.s:e.s/0);for(n=x(c.e/7)+x(e.e/7),(l=m.length)<(u=d.length)&&(s=m,m=d,d=s,o=l,l=u,u=o),s=[],t=o=l+u;t--;)s.push(0);for(t=u;--t>=0;){for(i=0,r=l+t;r>t;)a=s[r]+d[t]*m[r-t-1]+i,s[r--]=a%I|0,i=a/I|0;s[r]=(s[r]+i)%I|0}for(;!s[--o];)s.pop();return i?++n:s.shift(),e.d=s,e.e=z(s,n),p?L(e,h.precision,h.rounding):e},O.toBinary=function(e,i){return ie(this,2,e,i)},O.toDecimalPlaces=O.toDP=function(e,i){var n=this,t=n.constructor;return n=new t(n),void 0===e?n:(F(e,0,h),void 0===i?i=t.rounding:F(i,0,8),L(n,e+n.e+1,i))},O.toExponential=function(e,i){var n,t=this,r=t.constructor;return void 0===e?n=R(t,!0):(F(e,0,h),void 0===i?i=r.rounding:F(i,0,8),n=R(t=L(new r(t),e+1,i),!0,e+1)),t.isNeg()&&!t.isZero()?"-"+n:n},O.toFixed=function(e,i){var n,t,r=this,s=r.constructor;return void 0===e?n=R(r):(F(e,0,h),void 0===i?i=s.rounding:F(i,0,8),n=R(t=L(new s(r),e+r.e+1,i),!1,e+t.e+1)),r.isNeg()&&!r.isZero()?"-"+n:n},O.toFraction=function(e){var i,n,t,r,s,o,a,l,u,c,h,m,d=this,f=d.d,g=d.constructor;if(!f)return new g(d);if(u=n=new g(1),t=l=new g(0),o=(s=(i=new g(t)).e=j(f)-d.e-1)%7,i.d[0]=S(10,o<0?7+o:o),null==e)e=s>0?i:u;else{if(!(a=new g(e)).isInt()||a.lt(u))throw Error(b+a);e=a.gt(i)?s>0?i:u:a}for(p=!1,a=new g(T(f)),c=g.precision,g.precision=s=7*f.length*2;h=P(a,i,0,1,1),1!=(r=n.plus(h.times(t))).cmp(e);)n=t,t=r,r=u,u=l.plus(h.times(r)),l=r,r=i,i=a.minus(h.times(r)),a=r;return r=P(e.minus(n),t,0,1,1),l=l.plus(r.times(u)),n=n.plus(r.times(t)),l.s=u.s=d.s,m=P(u,t,s,1).minus(d).abs().cmp(P(l,n,s,1).minus(d).abs())<1?[u,t]:[l,n],g.precision=c,p=!0,m},O.toHexadecimal=O.toHex=function(e,i){return ie(this,16,e,i)},O.toNearest=function(e,i){var n=this,t=n.constructor;if(n=new t(n),null==e){if(!n.d)return n;e=new t(1),i=t.rounding}else{if(e=new t(e),void 0===i?i=t.rounding:F(i,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(p=!1,n=P(n,e,0,i,1).times(e),p=!0,L(n)):(e.s=n.s,n=e),n},O.toNumber=function(){return+this},O.toOctal=function(e,i){return ie(this,8,e,i)},O.toPower=O.pow=function(e){var i,n,t,r,s,o,a=this,l=a.constructor,u=+(e=new l(e));if(!(a.d&&e.d&&a.d[0]&&e.d[0]))return new l(S(+a,u));if((a=new l(a)).eq(1))return a;if(t=l.precision,s=l.rounding,e.eq(1))return L(a,t,s);if((i=x(e.e/7))>=e.d.length-1&&(n=u<0?-u:u)<=9007199254740991)return r=Z(l,a,n,t),e.s<0?new l(1).div(r):L(r,t,s);if((o=a.s)<0){if(i<e.d.length-1)return new l(NaN);if(0==(1&e.d[i])&&(o=1),0==a.e&&1==a.d[0]&&1==a.d.length)return a.s=o,a}return(i=0!=(n=S(+a,u))&&isFinite(n)?new l(n+"").e:x(u*(Math.log("0."+T(a.d))/Math.LN10+a.e+1)))>l.maxE+1||i<l.minE-1?new l(i>0?o/0:0):(p=!1,l.rounding=a.s=1,n=Math.min(12,(i+"").length),(r=H(e.times(W(a,t+n)),t)).d&&C((r=L(r,t+5,1)).d,t,s)&&(i=t+10,+T((r=L(H(e.times(W(a,i+n)),i),i+5,1)).d).slice(t+1,t+15)+1==1e14&&(r=L(r,t+1,0))),r.s=o,p=!0,l.rounding=s,L(r,t,s))},O.toPrecision=function(e,i){var n,t=this,r=t.constructor;return void 0===e?n=R(t,t.e<=r.toExpNeg||t.e>=r.toExpPos):(F(e,1,h),void 0===i?i=r.rounding:F(i,0,8),n=R(t=L(new r(t),e,i),e<=t.e||t.e<=r.toExpNeg,e)),t.isNeg()&&!t.isZero()?"-"+n:n},O.toSignificantDigits=O.toSD=function(e,i){var n=this.constructor;return void 0===e?(e=n.precision,i=n.rounding):(F(e,1,h),void 0===i?i=n.rounding:F(i,0,8)),L(new n(this),e,i)},O.toString=function(){var e=this,i=e.constructor,n=R(e,e.e<=i.toExpNeg||e.e>=i.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n},O.truncated=O.trunc=function(){return L(new this.constructor(this),this.e+1,1)},O.valueOf=O.toJSON=function(){var e=this,i=e.constructor,n=R(e,e.e<=i.toExpNeg||e.e>=i.toExpPos);return e.isNeg()?"-"+n:n};var P=function(){function e(e,i,n){var t,r=0,s=e.length;for(e=e.slice();s--;)t=e[s]*i+r,e[s]=t%n|0,r=t/n|0;return r&&e.unshift(r),e}function i(e,i,n,t){var r,s;if(n!=t)s=n>t?1:-1;else for(r=s=0;r<n;r++)if(e[r]!=i[r]){s=e[r]>i[r]?1:-1;break}return s}function n(e,i,n,t){for(var r=0;n--;)e[n]-=r,r=e[n]<i[n]?1:0,e[n]=r*t+e[n]-i[n];for(;!e[0]&&e.length>1;)e.shift()}return function(t,r,s,o,a,u){var c,h,m,d,f,g,p,v,b,y,N,_,S,w,k,E,A,M,q,O,T=t.constructor,F=t.s==r.s?1:-1,C=t.d,D=r.d;if(!(C&&C[0]&&D&&D[0]))return new T(t.s&&r.s&&(C?!D||C[0]!=D[0]:D)?C&&0==C[0]||!D?0*F:F/0:NaN);for(u?(f=1,h=t.e-r.e):(u=I,f=7,h=x(t.e/f)-x(r.e/f)),q=D.length,A=C.length,y=(b=new T(F)).d=[],m=0;D[m]==(C[m]||0);m++);if(D[m]>(C[m]||0)&&h--,null==s?(w=s=T.precision,o=T.rounding):w=a?s+(t.e-r.e)+1:s,w<0)y.push(1),g=!0;else{if(w=w/f+2|0,m=0,1==q){for(d=0,D=D[0],w++;(m<A||d)&&w--;m++)k=d*u+(C[m]||0),y[m]=k/D|0,d=k%D|0;g=d||m<A}else{for((d=u/(D[0]+1)|0)>1&&(D=e(D,d,u),C=e(C,d,u),q=D.length,A=C.length),E=q,_=(N=C.slice(0,q)).length;_<q;)N[_++]=0;(O=D.slice()).unshift(0),M=D[0],D[1]>=u/2&&++M;do{d=0,(c=i(D,N,q,_))<0?(S=N[0],q!=_&&(S=S*u+(N[1]||0)),(d=S/M|0)>1?(d>=u&&(d=u-1),1==(c=i(p=e(D,d,u),N,v=p.length,_=N.length))&&(d--,n(p,q<v?O:D,v,u))):(0==d&&(c=d=1),p=D.slice()),(v=p.length)<_&&p.unshift(0),n(N,p,_,u),-1==c&&(c=i(D,N,q,_=N.length))<1&&(d++,n(N,q<_?O:D,_,u)),_=N.length):0===c&&(d++,N=[0]),y[m++]=d,c&&N[0]?N[_++]=C[E]||0:(N=[C[E]],_=1)}while((E++<A||void 0!==N[0])&&w--);g=void 0!==N[0]}y[0]||y.shift()}if(1==f)b.e=h,l=g;else{for(m=1,d=y[0];d>=10;d/=10)m++;b.e=m+h*f-1,L(b,a?s+b.e+1:s,o,g)}return b}}();function L(e,i,n,t){var r,s,o,a,l,u,c,h,m,d=e.constructor;e:if(null!=i){if(!(h=e.d))return e;for(r=1,a=h[0];a>=10;a/=10)r++;if((s=i-r)<0)s+=7,o=i,l=(c=h[m=0])/S(10,r-o-1)%10|0;else if((m=Math.ceil((s+1)/7))>=(a=h.length)){if(!t)break e;for(;a++<=m;)h.push(0);c=l=0,r=1,o=(s%=7)-7+1}else{for(c=a=h[m],r=1;a>=10;a/=10)r++;l=(o=(s%=7)-7+r)<0?0:c/S(10,r-o-1)%10|0}if(t=t||i<0||void 0!==h[m+1]||(o<0?c:c%S(10,r-o-1)),u=n<4?(l||t)&&(0==n||n==(e.s<0?3:2)):l>5||5==l&&(4==n||t||6==n&&(s>0?o>0?c/S(10,r-o):0:h[m-1])%10&1||n==(e.s<0?8:7)),i<1||!h[0])return h.length=0,u?(i-=e.e+1,h[0]=S(10,(7-i%7)%7),e.e=-i||0):h[0]=e.e=0,e;if(0==s?(h.length=m,a=1,m--):(h.length=m+1,a=S(10,7-s),h[m]=o>0?(c/S(10,r-o)%S(10,o)|0)*a:0),u)for(;;){if(0==m){for(s=1,o=h[0];o>=10;o/=10)s++;for(o=h[0]+=a,a=1;o>=10;o/=10)a++;s!=a&&(e.e++,h[0]==I&&(h[0]=1));break}if(h[m]+=a,h[m]!=I)break;h[m--]=0,a=1}for(s=h.length;0===h[--s];)h.pop()}return p&&(e.e>d.maxE?(e.d=null,e.e=NaN):e.e<d.minE&&(e.e=0,e.d=[0])),e}function R(e,i,n){if(!e.isFinite())return Q(e);var t,r=e.e,s=T(e.d),o=s.length;return i?(n&&(t=n-o)>0?s=s.charAt(0)+"."+s.slice(1)+G(t):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):r<0?(s="0."+G(-r-1)+s,n&&(t=n-o)>0&&(s+=G(t))):r>=o?(s+=G(r+1-o),n&&(t=n-r-1)>0&&(s=s+"."+G(t))):((t=r+1)<o&&(s=s.slice(0,t)+"."+s.slice(t)),n&&(t=n-o)>0&&(r+1===o&&(s+="."),s+=G(t))),s}function z(e,i){var n=e[0];for(i*=7;n>=10;n/=10)i++;return i}function $(e,i,n){if(i>M)throw p=!0,n&&(e.precision=n),Error(y);return L(new e(d),i,1,!0)}function V(e,i,n){if(i>q)throw Error(y);return L(new e(f),i,n,!0)}function j(e){var i=e.length-1,n=7*i+1;if(i=e[i]){for(;i%10==0;i/=10)n--;for(i=e[0];i>=10;i/=10)n++}return n}function G(e){for(var i="";e--;)i+="0";return i}function Z(e,i,n,t){var r,s=new e(1),o=Math.ceil(t/7+4);for(p=!1;;){if(n%2&&ne((s=s.times(i)).d,o)&&(r=!0),0===(n=x(n/2))){n=s.d.length-1,r&&0===s.d[n]&&++s.d[n];break}ne((i=i.times(i)).d,o)}return p=!0,s}function B(e){return 1&e.d[e.d.length-1]}function U(e,i,n){for(var t,r=new e(i[0]),s=0;++s<i.length;){if(!(t=new e(i[s])).s){r=t;break}r[n](t)&&(r=t)}return r}function H(e,i){var n,t,r,s,o,a,l,u=0,c=0,h=0,m=e.constructor,d=m.rounding,f=m.precision;if(!e.d||!e.d[0]||e.e>17)return new m(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(null==i?(p=!1,l=f):l=i,a=new m(.03125);e.e>-2;)e=e.times(a),h+=5;for(l+=t=Math.log(S(2,h))/Math.LN10*2+5|0,n=s=o=new m(1),m.precision=l;;){if(s=L(s.times(e),l,1),n=n.times(++c),T((a=o.plus(P(s,n,l,1))).d).slice(0,l)===T(o.d).slice(0,l)){for(r=h;r--;)o=L(o.times(o),l,1);if(null!=i)return m.precision=f,o;if(!(u<3&&C(o.d,l-t,d,u)))return L(o,m.precision=f,d,p=!0);m.precision=l+=10,n=s=a=new m(1),c=0,u++}o=a}}function W(e,i){var n,t,r,s,o,a,l,u,c,h,m,d=1,f=e,g=f.d,v=f.constructor,b=v.rounding,y=v.precision;if(f.s<0||!g||!g[0]||!f.e&&1==g[0]&&1==g.length)return new v(g&&!g[0]?-1/0:1!=f.s?NaN:g?0:f);if(null==i?(p=!1,c=y):c=i,v.precision=c+=10,t=(n=T(g)).charAt(0),!(Math.abs(s=f.e)<15e14))return u=$(v,c+2,y).times(s+""),f=W(new v(t+"."+n.slice(1)),c-10).plus(u),v.precision=y,null==i?L(f,y,b,p=!0):f;for(;t<7&&1!=t||1==t&&n.charAt(1)>3;)t=(n=T((f=f.times(e)).d)).charAt(0),d++;for(s=f.e,t>1?(f=new v("0."+n),s++):f=new v(t+"."+n.slice(1)),h=f,l=o=f=P(f.minus(1),f.plus(1),c,1),m=L(f.times(f),c,1),r=3;;){if(o=L(o.times(m),c,1),T((u=l.plus(P(o,new v(r),c,1))).d).slice(0,c)===T(l.d).slice(0,c)){if(l=l.times(2),0!==s&&(l=l.plus($(v,c+2,y).times(s+""))),l=P(l,new v(d),c,1),null!=i)return v.precision=y,l;if(!C(l.d,c-10,b,a))return L(l,v.precision=y,b,p=!0);v.precision=c+=10,u=o=f=P(h.minus(1),h.plus(1),c,1),m=L(f.times(f),c,1),r=a=1}l=u,r+=2}}function Q(e){return e.s*e.s/0+""}function Y(e,i){var n,t,r;for((n=i.indexOf("."))>-1&&(i=i.replace(".","")),(t=i.search(/e/i))>0?(n<0&&(n=t),n+=+i.slice(t+1),i=i.substring(0,t)):n<0&&(n=i.length),t=0;48===i.charCodeAt(t);t++);for(r=i.length;48===i.charCodeAt(r-1);--r);if(i=i.slice(t,r)){if(r-=t,e.e=n=n-t-1,e.d=[],t=(n+1)%7,n<0&&(t+=7),t<r){for(t&&e.d.push(+i.slice(0,t)),r-=7;t<r;)e.d.push(+i.slice(t,t+=7));t=7-(i=i.slice(t)).length}else t-=r;for(;t--;)i+="0";e.d.push(+i),p&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function J(e,i){var n,t,r,s,o,a,l,u,c;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),A.test(i))return Y(e,i)}else if("Infinity"===i||"NaN"===i)return+i||(e.s=NaN),e.e=NaN,e.d=null,e;if(k.test(i))n=16,i=i.toLowerCase();else if(w.test(i))n=2;else{if(!E.test(i))throw Error(b+i);n=8}for((s=i.search(/p/i))>0?(l=+i.slice(s+1),i=i.substring(2,s)):i=i.slice(2),o=(s=i.indexOf("."))>=0,t=e.constructor,o&&(s=(a=(i=i.replace(".","")).length)-s,r=Z(t,new t(n),s,2*s)),s=c=(u=D(i,n,I)).length-1;0===u[s];--s)u.pop();return s<0?new t(0*e.s):(e.e=z(u,c),e.d=u,p=!1,o&&(e=P(e,r,4*a)),l&&(e=e.times(Math.abs(l)<54?S(2,l):Ge.pow(2,l))),p=!0,e)}function K(e,i,n,t,r){var s,o,a,l,u=e.precision,c=Math.ceil(u/7);for(p=!1,l=n.times(n),a=new e(t);;){if(o=P(a.times(l),new e(i++*i++),u,1),a=r?t.plus(o):t.minus(o),t=P(o.times(l),new e(i++*i++),u,1),void 0!==(o=a.plus(t)).d[c]){for(s=c;o.d[s]===a.d[s]&&s--;);if(-1==s)break}s=a,a=t,t=o,o=s}return p=!0,o.d.length=c+1,o}function X(e,i){for(var n=e;--i;)n*=e;return n}function ee(e,i){var n,t=i.s<0,r=V(e,e.precision,1),s=r.times(.5);if((i=i.abs()).lte(s))return u=t?4:1,i;if((n=i.divToInt(r)).isZero())u=t?3:2;else{if((i=i.minus(n.times(r))).lte(s))return u=B(n)?t?2:3:t?4:1,i;u=B(n)?t?1:4:t?3:2}return i.minus(r).abs()}function ie(e,i,n,t){var r,s,o,a,u,c,d,f,g,p=e.constructor,v=void 0!==n;if(v?(F(n,1,h),void 0===t?t=p.rounding:F(t,0,8)):(n=p.precision,t=p.rounding),e.isFinite()){for(v?(r=2,16==i?n=4*n-3:8==i&&(n=3*n-2)):r=i,(o=(d=R(e)).indexOf("."))>=0&&(d=d.replace(".",""),(g=new p(1)).e=d.length-o,g.d=D(R(g),10,r),g.e=g.d.length),s=u=(f=D(d,10,r)).length;0==f[--u];)f.pop();if(f[0]){if(o<0?s--:((e=new p(e)).d=f,e.e=s,f=(e=P(e,g,n,t,0,r)).d,s=e.e,c=l),o=f[n],a=r/2,c=c||void 0!==f[n+1],c=t<4?(void 0!==o||c)&&(0===t||t===(e.s<0?3:2)):o>a||o===a&&(4===t||c||6===t&&1&f[n-1]||t===(e.s<0?8:7)),f.length=n,c)for(;++f[--n]>r-1;)f[n]=0,n||(++s,f.unshift(1));for(u=f.length;!f[u-1];--u);for(o=0,d="";o<u;o++)d+=m.charAt(f[o]);if(v){if(u>1)if(16==i||8==i){for(o=16==i?4:3,--u;u%o;u++)d+="0";for(u=(f=D(d,r,i)).length;!f[u-1];--u);for(o=1,d="1.";o<u;o++)d+=m.charAt(f[o])}else d=d.charAt(0)+"."+d.slice(1);d=d+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)d="0"+d;d="0."+d}else if(++s>u)for(s-=u;s--;)d+="0";else s<u&&(d=d.slice(0,s)+"."+d.slice(s))}else d=v?"0p+0":"0";d=(16==i?"0x":2==i?"0b":8==i?"0o":"")+d}else d=Q(e);return e.s<0?"-"+d:d}function ne(e,i){if(e.length>i)return e.length=i,!0}function te(e){return new this(e).abs()}function re(e){return new this(e).acos()}function se(e){return new this(e).acosh()}function oe(e,i){return new this(e).plus(i)}function ae(e){return new this(e).asin()}function le(e){return new this(e).asinh()}function ue(e){return new this(e).atan()}function ce(e){return new this(e).atanh()}function he(e,i){e=new this(e),i=new this(i);var n,t=this.precision,r=this.rounding,s=t+4;return e.s&&i.s?e.d||i.d?!i.d||e.isZero()?(n=i.s<0?V(this,t,r):new this(0)).s=e.s:!e.d||i.isZero()?(n=V(this,s,1).times(.5)).s=e.s:i.s<0?(this.precision=s,this.rounding=1,n=this.atan(P(e,i,s,1)),i=V(this,s,1),this.precision=t,this.rounding=r,n=e.s<0?n.minus(i):n.plus(i)):n=this.atan(P(e,i,s,1)):(n=V(this,s,1).times(i.s>0?.25:.75)).s=e.s:n=new this(NaN),n}function me(e){return new this(e).cbrt()}function de(e){return L(e=new this(e),e.e+1,2)}function fe(e,i,n){return new this(e).clamp(i,n)}function ge(e){if(!e||"object"!=typeof e)throw Error(v+"Object expected");var i,n,t,r=!0===e.defaults,s=["precision",1,h,"rounding",0,8,"toExpNeg",-c,0,"toExpPos",0,c,"maxE",0,c,"minE",-c,0,"modulo",0,9];for(i=0;i<s.length;i+=3)if(n=s[i],r&&(this[n]=g[n]),void 0!==(t=e[n])){if(!(x(t)===t&&t>=s[i+1]&&t<=s[i+2]))throw Error(b+n+": "+t);this[n]=t}if(n="crypto",r&&(this[n]=g[n]),void 0!==(t=e[n])){if(!0!==t&&!1!==t&&0!==t&&1!==t)throw Error(b+n+": "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(N);this[n]=!0}else this[n]=!1}return this}function pe(e){return new this(e).cos()}function ve(e){return new this(e).cosh()}function be(e,i){return new this(e).div(i)}function ye(e){return new this(e).exp()}function Ne(e){return L(e=new this(e),e.e+1,3)}function _e(){var e,i,n=new this(0);for(p=!1,e=0;e<arguments.length;)if((i=new this(arguments[e++])).d)n.d&&(n=n.plus(i.times(i)));else{if(i.s)return p=!0,new this(1/0);n=i}return p=!0,n.sqrt()}function xe(e){return e instanceof Ge||e&&e.toStringTag===_||!1}function Se(e){return new this(e).ln()}function we(e,i){return new this(e).log(i)}function ke(e){return new this(e).log(2)}function Ee(e){return new this(e).log(10)}function Ae(){return U(this,arguments,"lt")}function Ie(){return U(this,arguments,"gt")}function Me(e,i){return new this(e).mod(i)}function qe(e,i){return new this(e).mul(i)}function Oe(e,i){return new this(e).pow(i)}function Te(e){var i,n,t,r,s=0,o=new this(1),a=[];if(void 0===e?e=this.precision:F(e,1,h),t=Math.ceil(e/7),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(t));s<t;)(r=i[s])>=429e7?i[s]=crypto.getRandomValues(new Uint32Array(1))[0]:a[s++]=r%1e7;else{if(!crypto.randomBytes)throw Error(N);for(i=crypto.randomBytes(t*=4);s<t;)(r=i[s]+(i[s+1]<<8)+(i[s+2]<<16)+((127&i[s+3])<<24))>=214e7?crypto.randomBytes(4).copy(i,s):(a.push(r%1e7),s+=4);s=t/4}else for(;s<t;)a[s++]=1e7*Math.random()|0;for(e%=7,(t=a[--s])&&e&&(r=S(10,7-e),a[s]=(t/r|0)*r);0===a[s];s--)a.pop();if(s<0)n=0,a=[0];else{for(n=-1;0===a[0];n-=7)a.shift();for(t=1,r=a[0];r>=10;r/=10)t++;t<7&&(n-=7-t)}return o.e=n,o.d=a,o}function Fe(e){return L(e=new this(e),e.e+1,this.rounding)}function Ce(e){return(e=new this(e)).d?e.d[0]?e.s:0*e.s:e.s||NaN}function De(e){return new this(e).sin()}function Pe(e){return new this(e).sinh()}function Le(e){return new this(e).sqrt()}function Re(e,i){return new this(e).sub(i)}function ze(){var e=0,i=arguments,n=new this(i[e]);for(p=!1;n.s&&++e<i.length;)n=n.plus(i[e]);return p=!0,L(n,this.precision,this.rounding)}function $e(e){return new this(e).tan()}function Ve(e){return new this(e).tanh()}function je(e){return L(e=new this(e),e.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString,O[Symbol.toStringTag]="Decimal";var Ge=O.constructor=function e(i){var n,t,r;function s(e){var i,n,t,r=this;if(!(r instanceof s))return new s(e);if(r.constructor=s,xe(e))return r.s=e.s,void(p?!e.d||e.e>s.maxE?(r.e=NaN,r.d=null):e.e<s.minE?(r.e=0,r.d=[0]):(r.e=e.e,r.d=e.d.slice()):(r.e=e.e,r.d=e.d?e.d.slice():e.d));if("number"==(t=typeof e)){if(0===e)return r.s=1/e<0?-1:1,r.e=0,void(r.d=[0]);if(e<0?(e=-e,r.s=-1):r.s=1,e===~~e&&e<1e7){for(i=0,n=e;n>=10;n/=10)i++;return void(p?i>s.maxE?(r.e=NaN,r.d=null):i<s.minE?(r.e=0,r.d=[0]):(r.e=i,r.d=[e]):(r.e=i,r.d=[e]))}return 0*e!=0?(e||(r.s=NaN),r.e=NaN,void(r.d=null)):Y(r,e.toString())}if("string"!==t)throw Error(b+e);return 45===(n=e.charCodeAt(0))?(e=e.slice(1),r.s=-1):(43===n&&(e=e.slice(1)),r.s=1),A.test(e)?Y(r,e):J(r,e)}if(s.prototype=O,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=ge,s.clone=e,s.isDecimal=xe,s.abs=te,s.acos=re,s.acosh=se,s.add=oe,s.asin=ae,s.asinh=le,s.atan=ue,s.atanh=ce,s.atan2=he,s.cbrt=me,s.ceil=de,s.clamp=fe,s.cos=pe,s.cosh=ve,s.div=be,s.exp=ye,s.floor=Ne,s.hypot=_e,s.ln=Se,s.log=we,s.log10=Ee,s.log2=ke,s.max=Ae,s.min=Ie,s.mod=Me,s.mul=qe,s.pow=Oe,s.random=Te,s.round=Fe,s.sign=Ce,s.sin=De,s.sinh=Pe,s.sqrt=Le,s.sub=Re,s.sum=ze,s.tan=$e,s.tanh=Ve,s.trunc=je,void 0===i&&(i={}),i&&!0!==i.defaults)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],n=0;n<r.length;)i.hasOwnProperty(t=r[n++])||(i[t]=this[t]);return s.config(i),s}(g);function Ze(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}d=new Ge(d),f=new Ge(f);var Be={exports:{}};!function(e,i){!function(i){var n=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:.5*(Math.exp(e)+Math.exp(-e))},t=Math.sinh||function(e){return Math.abs(e)<1e-9?e:.5*(Math.exp(e)-Math.exp(-e))},r=function(){throw SyntaxError("Invalid Param")};function s(e,i){var n=Math.abs(e),t=Math.abs(i);return 0===e?Math.log(t):0===i?Math.log(n):n<3e3&&t<3e3?.5*Math.log(e*e+i*i):.5*Math.log((e/=2)*e+(i/=2)*i)+Math.LN2}function o(e,i){if(!(this instanceof o))return new o(e,i);var n=function(e,i){var n={re:0,im:0};if(null==e)n.re=n.im=0;else if(void 0!==i)n.re=e,n.im=i;else switch(typeof e){case"object":if("im"in e&&"re"in e)n.re=e.re,n.im=e.im;else if("abs"in e&&"arg"in e){if(!Number.isFinite(e.abs)&&Number.isFinite(e.arg))return o.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if("r"in e&&"phi"in e){if(!Number.isFinite(e.r)&&Number.isFinite(e.phi))return o.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else 2===e.length?(n.re=e[0],n.im=e[1]):r();break;case"string":n.im=n.re=0;var t=e.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),s=1,a=0;null===t&&r();for(var l=0;l<t.length;l++){var u=t[l];" "===u||"\t"===u||"\n"===u||("+"===u?s++:"-"===u?a++:"i"===u||"I"===u?(s+a===0&&r()," "===t[l+1]||isNaN(t[l+1])?n.im+=parseFloat((a%2?"-":"")+"1"):(n.im+=parseFloat((a%2?"-":"")+t[l+1]),l++),s=a=0):((s+a===0||isNaN(u))&&r(),"i"===t[l+1]||"I"===t[l+1]?(n.im+=parseFloat((a%2?"-":"")+u),l++):n.re+=parseFloat((a%2?"-":"")+u),s=a=0))}s+a>0&&r();break;case"number":n.im=0,n.re=e;break;default:r()}return isNaN(n.re)||n.im,n}(e,i);this.re=n.re,this.im=n.im}o.prototype={re:0,im:0,sign:function(){var e=this.abs();return new o(this.re/e,this.im/e)},add:function(e,i){var n=new o(e,i);return this.isInfinite()&&n.isInfinite()?o.NAN:this.isInfinite()||n.isInfinite()?o.INFINITY:new o(this.re+n.re,this.im+n.im)},sub:function(e,i){var n=new o(e,i);return this.isInfinite()&&n.isInfinite()?o.NAN:this.isInfinite()||n.isInfinite()?o.INFINITY:new o(this.re-n.re,this.im-n.im)},mul:function(e,i){var n=new o(e,i);return this.isInfinite()&&n.isZero()||this.isZero()&&n.isInfinite()?o.NAN:this.isInfinite()||n.isInfinite()?o.INFINITY:0===n.im&&0===this.im?new o(this.re*n.re,0):new o(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,i){var n=new o(e,i);if(this.isZero()&&n.isZero()||this.isInfinite()&&n.isInfinite())return o.NAN;if(this.isInfinite()||n.isZero())return o.INFINITY;if(this.isZero()||n.isInfinite())return o.ZERO;e=this.re,i=this.im;var t,r,s=n.re,a=n.im;return 0===a?new o(e/s,i/s):Math.abs(s)<Math.abs(a)?new o((e*(r=s/a)+i)/(t=s*r+a),(i*r-e)/t):new o((e+i*(r=a/s))/(t=a*r+s),(i-e*r)/t)},pow:function(e,i){var n=new o(e,i);if(e=this.re,i=this.im,n.isZero())return o.ONE;if(0===n.im){if(0===i&&e>0)return new o(Math.pow(e,n.re),0);if(0===e)switch((n.re%4+4)%4){case 0:return new o(Math.pow(i,n.re),0);case 1:return new o(0,Math.pow(i,n.re));case 2:return new o(-Math.pow(i,n.re),0);case 3:return new o(0,-Math.pow(i,n.re))}}if(0===e&&0===i&&n.re>0&&n.im>=0)return o.ZERO;var t=Math.atan2(i,e),r=s(e,i);return e=Math.exp(n.re*r-n.im*t),i=n.im*r+n.re*t,new o(e*Math.cos(i),e*Math.sin(i))},sqrt:function(){var e,i,n=this.re,t=this.im,r=this.abs();if(n>=0){if(0===t)return new o(Math.sqrt(n),0);e=.5*Math.sqrt(2*(r+n))}else e=Math.abs(t)/Math.sqrt(2*(r-n));return i=n<=0?.5*Math.sqrt(2*(r-n)):Math.abs(t)/Math.sqrt(2*(r+n)),new o(e,t<0?-i:i)},exp:function(){var e=Math.exp(this.re);return this.im,new o(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){var e=this.re,i=this.im;return new o(Math.expm1(e)*Math.cos(i)+function(e){var i=Math.PI/4;if(-i>e||e>i)return Math.cos(e)-1;var n=e*e;return n*(n*(n*(n*(n*(n*(n*(n/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-.5)}(i),Math.exp(e)*Math.sin(i))},log:function(){var e=this.re,i=this.im;return new o(s(e,i),Math.atan2(i,e))},abs:function(){return e=this.re,i=this.im,n=Math.abs(e),t=Math.abs(i),n<3e3&&t<3e3?Math.sqrt(n*n+t*t):(n<t?(n=t,t=e/i):t=i/e,n*Math.sqrt(1+t*t));var e,i,n,t},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){var e=this.re,i=this.im;return new o(Math.sin(e)*n(i),Math.cos(e)*t(i))},cos:function(){var e=this.re,i=this.im;return new o(Math.cos(e)*n(i),-Math.sin(e)*t(i))},tan:function(){var e=2*this.re,i=2*this.im,r=Math.cos(e)+n(i);return new o(Math.sin(e)/r,t(i)/r)},cot:function(){var e=2*this.re,i=2*this.im,r=Math.cos(e)-n(i);return new o(-Math.sin(e)/r,t(i)/r)},sec:function(){var e=this.re,i=this.im,r=.5*n(2*i)+.5*Math.cos(2*e);return new o(Math.cos(e)*n(i)/r,Math.sin(e)*t(i)/r)},csc:function(){var e=this.re,i=this.im,r=.5*n(2*i)-.5*Math.cos(2*e);return new o(Math.sin(e)*n(i)/r,-Math.cos(e)*t(i)/r)},asin:function(){var e=this.re,i=this.im,n=new o(i*i-e*e+1,-2*e*i).sqrt(),t=new o(n.re-i,n.im+e).log();return new o(t.im,-t.re)},acos:function(){var e=this.re,i=this.im,n=new o(i*i-e*e+1,-2*e*i).sqrt(),t=new o(n.re-i,n.im+e).log();return new o(Math.PI/2-t.im,t.re)},atan:function(){var e=this.re,i=this.im;if(0===e){if(1===i)return new o(0,1/0);if(-1===i)return new o(0,-1/0)}var n=e*e+(1-i)*(1-i),t=new o((1-i*i-e*e)/n,-2*e/n).log();return new o(-.5*t.im,.5*t.re)},acot:function(){var e=this.re,i=this.im;if(0===i)return new o(Math.atan2(1,e),0);var n=e*e+i*i;return 0!==n?new o(e/n,-i/n).atan():new o(0!==e?e/0:0,0!==i?-i/0:0).atan()},asec:function(){var e=this.re,i=this.im;if(0===e&&0===i)return new o(0,1/0);var n=e*e+i*i;return 0!==n?new o(e/n,-i/n).acos():new o(0!==e?e/0:0,0!==i?-i/0:0).acos()},acsc:function(){var e=this.re,i=this.im;if(0===e&&0===i)return new o(Math.PI/2,1/0);var n=e*e+i*i;return 0!==n?new o(e/n,-i/n).asin():new o(0!==e?e/0:0,0!==i?-i/0:0).asin()},sinh:function(){var e=this.re,i=this.im;return new o(t(e)*Math.cos(i),n(e)*Math.sin(i))},cosh:function(){var e=this.re,i=this.im;return new o(n(e)*Math.cos(i),t(e)*Math.sin(i))},tanh:function(){var e=2*this.re,i=2*this.im,r=n(e)+Math.cos(i);return new o(t(e)/r,Math.sin(i)/r)},coth:function(){var e=2*this.re,i=2*this.im,r=n(e)-Math.cos(i);return new o(t(e)/r,-Math.sin(i)/r)},csch:function(){var e=this.re,i=this.im,r=Math.cos(2*i)-n(2*e);return new o(-2*t(e)*Math.cos(i)/r,2*n(e)*Math.sin(i)/r)},sech:function(){var e=this.re,i=this.im,r=Math.cos(2*i)+n(2*e);return new o(2*n(e)*Math.cos(i)/r,-2*t(e)*Math.sin(i)/r)},asinh:function(){var e=this.im;this.im=-this.re,this.re=e;var i=this.asin();return this.re=-this.im,this.im=e,e=i.re,i.re=-i.im,i.im=e,i},acosh:function(){var e=this.acos();if(e.im<=0){var i=e.re;e.re=-e.im,e.im=i}else i=e.im,e.im=-e.re,e.re=i;return e},atanh:function(){var e=this.re,i=this.im,n=e>1&&0===i,t=1-e,r=1+e,a=t*t+i*i,l=0!==a?new o((r*t-i*i)/a,(i*t+r*i)/a):new o(-1!==e?e/0:0,0!==i?i/0:0),u=l.re;return l.re=s(l.re,l.im)/2,l.im=Math.atan2(l.im,u)/2,n&&(l.im=-l.im),l},acoth:function(){var e=this.re,i=this.im;if(0===e&&0===i)return new o(0,Math.PI/2);var n=e*e+i*i;return 0!==n?new o(e/n,-i/n).atanh():new o(0!==e?e/0:0,0!==i?-i/0:0).atanh()},acsch:function(){var e=this.re,i=this.im;if(0===i)return new o(0!==e?Math.log(e+Math.sqrt(e*e+1)):1/0,0);var n=e*e+i*i;return 0!==n?new o(e/n,-i/n).asinh():new o(0!==e?e/0:0,0!==i?-i/0:0).asinh()},asech:function(){var e=this.re,i=this.im;if(this.isZero())return o.INFINITY;var n=e*e+i*i;return 0!==n?new o(e/n,-i/n).acosh():new o(0!==e?e/0:0,0!==i?-i/0:0).acosh()},inverse:function(){if(this.isZero())return o.INFINITY;if(this.isInfinite())return o.ZERO;var e=this.re,i=this.im,n=e*e+i*i;return new o(e/n,-i/n)},conjugate:function(){return new o(this.re,-this.im)},neg:function(){return new o(-this.re,-this.im)},ceil:function(e){return e=Math.pow(10,e||0),new o(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=Math.pow(10,e||0),new o(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=Math.pow(10,e||0),new o(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,i){var n=new o(e,i);return Math.abs(n.re-this.re)<=o.EPSILON&&Math.abs(n.im-this.im)<=o.EPSILON},clone:function(){return new o(this.re,this.im)},toString:function(){var e=this.re,i=this.im,n="";return this.isNaN()?"NaN":this.isInfinite()?"Infinity":(Math.abs(e)<o.EPSILON&&(e=0),Math.abs(i)<o.EPSILON&&(i=0),0===i?n+e:(0!==e?(n+=e,n+=" ",i<0?(i=-i,n+="-"):n+="+",n+=" "):i<0&&(i=-i,n+="-"),1!==i&&(n+=i),n+"i"))},toVector:function(){return[this.re,this.im]},valueOf:function(){return 0===this.im?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return 0===this.im&&0===this.re},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!(this.isNaN()||this.isFinite())}},o.ZERO=new o(0,0),o.ONE=new o(1,0),o.I=new o(0,1),o.PI=new o(Math.PI,0),o.E=new o(Math.E,0),o.INFINITY=new o(1/0,1/0),o.NAN=new o(NaN,NaN),o.EPSILON=1e-15,Object.defineProperty(o,"__esModule",{value:!0}),o.default=o,o.Complex=o,e.exports=o}()}(Be);var Ue=Ze(Be.exports);const He=8205;function We(e){return e===He||65038===e||65039===e||e>=127995&&e<=128e3||e>=129456&&e<=129460||e>=917536&&e<=917632}function Qe(e){return e>=127462&&e<=127487}class Ye{constructor(e){this.obeyspaces=!1,this.s=function(e){if(/^[\u0020-\u00FF]*$/.test(e))return e;const i=[],n=function(e){const i=[];for(let n=0;n<e.length;n++){let t=e.charCodeAt(n);if(t>=55296&&t<=56319){const i=e.charCodeAt(n+1);i>=56320&&i<=57343&&(t=65536+1024*(t-55296)+(i-56320),n++)}i.push(t)}return i}(e);let t=0;for(;t<n.length;){const e=n[t++],r=n[t];if(r===He){const e=t-1;for(t+=2;n[t]===He;)t+=2;i.push(String.fromCodePoint(...n.slice(e,2*t-e+1)))}else if(We(r)){const e=t-1;for(;We(n[t]);)t+=n[t]===He?2:1;i.push(String.fromCodePoint(...n.slice(e,2*t-e-1)))}else Qe(e)?(t+=1,i.push(String.fromCodePoint(...n.slice(t-2,2)))):i.push(String.fromCodePoint(e))}return i}(e),this.pos=0}end(){return this.pos>=this.s.length}get(){return this.pos<this.s.length?this.s[this.pos++]:""}peek(){return this.s[this.pos]}match(e){let i;return i="string"==typeof this.s?e.exec(this.s.slice(this.pos)):e.exec(this.s.slice(this.pos).join("")),(null==i?void 0:i[0])?(this.pos+=i[0].length,i[0]):null}next(){if(this.end())return null;if(!this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]+/))return"<space>";if(this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]/))return"<space>";const e=this.get();if("\\"===e){if(!this.end()){let e=this.match(/^[a-zA-Z*]+/);if(e)this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]*/);else if(e=this.get()," "===e)return"<space>";return"\\"+e}}else{if("{"===e)return"<{>";if("}"===e)return"<}>";if("^"===e){if("^"===this.peek()){this.get();const e=this.match(/^(\^(\^(\^(\^[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f][0-9a-f]/);if(e)return String.fromCodePoint(parseInt(e.slice(e.lastIndexOf("^")+1),16))}return e}if("#"===e){if(!this.end()){let e=!1;if(/[0-9?]/.test(this.peek())&&(e=!0,this.pos+1<this.s.length)){const i=this.s[this.pos+1];e=/[^0-9A-Za-z]/.test(i)}return e?"#"+this.get():"#"}}else if("$"===e)return"$"===this.peek()?(this.get(),"<$$>"):"<$>"}return e}}function Je(e,i){var n,t,r,s;let o=[],a=e.next();if(a)if("\\relax"===a);else if("\\noexpand"===a)a=e.next(),a&&o.push(a);else if("\\obeyspaces"===a)e.obeyspaces=!0;else if("\\space"===a||"~"===a)o.push("<space>");else if("\\bgroup"===a)o.push("<{>");else if("\\egroup"===a)o.push("<}>");else if("\\string"===a)a=e.next(),a&&("\\"===a[0]?Array.from(a).forEach((e=>o.push("\\"===e?"\\backslash":e))):"<{>"===a?o.push("\\{"):"<space>"===a?o.push("~"):"<}>"===a&&o.push("\\}"));else if("\\csname"===a){for(;"<space>"===e.peek();)e.next();let r="",s=!1,l=[];do{if(0===l.length)if(/^#[0-9?]$/.test(e.peek())){const r=e.get().slice(1);l=Ke(null!==(t=null!==(n=null==i?void 0:i[r])&&void 0!==n?n:null==i?void 0:i["?"])&&void 0!==t?t:"\\placeholder{}",i),a=l[0]}else a=e.next(),l=a?[a]:[];s=0===l.length,s||"\\endcsname"!==a||(s=!0,l.shift()),s||(s="<$>"===a||"<$$>"===a||"<{>"===a||"<}>"===a||!!a&&a.length>1&&"\\"===a[0]),s||(r+=l.shift())}while(!s);r&&o.push("\\"+r),o=o.concat(l)}else if("\\endcsname"===a);else if(a.length>1&&"#"===a[0]){const e=a.slice(1);o=o.concat(Ke(null!==(s=null!==(r=null==i?void 0:i[e])&&void 0!==r?r:null==i?void 0:i["?"])&&void 0!==s?s:"\\placeholder{}",i))}else o.push(a);return o}function Ke(e,i){const n=e.toString().split(/\r?\n/);let t="",r="";for(const e of n){t+=r,r=" ";const i=e.match(/((?:\\%)|[^%])*/);null!==i&&(t+=i[0])}const s=new Ye(t),o=[];do{o.push(...Je(s,i))}while(!s.end());return o}function Xe(e){let i="",n="";for(const t of e)t&&(/[a-zA-Z*]/.test(t[0])&&(n+=i),i=/\\[a-zA-Z]+\*?$/.test(t)?" ":"",n+=t);return n}function ei(e){let i=[];if(Array.isArray(e))for(const n of e)Array.isArray(n)?i=[...i,...n]:i.push(n);else i=[e];return Xe(i.map((e=>{var i;return null!==(i={"<space>":" ","<$$>":"$$","<$>":"$","<{>":"{","<}>":"}"}[e])&&void 0!==i?i:e})))}function ii(e){return null!==e&&"object"==typeof e&&"num"in e}function ni(e){return null!==e&&"object"==typeof e&&"sym"in e}function ti(e){return null!==e&&"object"==typeof e&&"fn"in e}function ri(e){return!/[\u0000-\u0020\u0022\u0060\ufffe\uffff]/.test(e)&&!/^[\u0021\u0022\u0024-\u0029\u002e\u003a\u003f\u0040\u005b\u005d\u005e\u007b\u007d\u007e\+\-[0-9]]/.test(e)}function si(e){return null==e?null:"object"==typeof e&&"str"in e?e.str:"string"!=typeof e||e.length<2||"'"!==e[0]||"'"!==e[e.length-1]?null:e.substring(1,e.length-1)}function oi(e){var i;if(null==e||null!==si(e))return null;const n=ai(e);return null!==n?[n,...(null!==(i=ui(e))&&void 0!==i?i:[]).map((e=>oi(e))).filter((e=>null!==e))]:e}function ai(e){return null==e?null:Array.isArray(e)?e[0]:ti(e)?e.fn[0]:null}function li(e){const i=ai(e);return"string"==typeof i?i:""}function ui(e){return null==e?null:Array.isArray(e)?e.slice(1):ti(e)?e.fn.slice(1):null}function ci(e,i){var n,t;return null==e?null:Array.isArray(e)?null!==(n=e[i])&&void 0!==n?n:null:ti(e)&&null!==(t=e.fn[i])&&void 0!==t?t:null}function hi(e){return ci(e,1)}function mi(e){return ci(e,2)}function di(e){return null==e?0:Array.isArray(e)?Math.max(0,e.length-1):ti(e)?Math.max(0,e.fn.length-1):0}function fi(e){if(null==e)return null;if("string"==typeof e){if(/^[+\-\.0-9]/.test(e))return null;if(e.length>=2&&"'"===e[0]&&"'"===e[e.length-1])return null}const i=ni(e)?e.sym:e;return"string"!=typeof i?null:i}function gi(e){var i;const n=ai(e);if("KeyValuePair"===n||"Tuple"===n||"Pair"===n){const n=si(hi(e));return n?[n,null!==(i=mi(e))&&void 0!==i?i:"Nothing"]:null}return null}function pi(e){if(null===e)return null;if("object"==typeof e&&"dict"in e)return e.dict;const i=gi(e);if(i)return{[i[0]]:i[1]};if("Dictionary"===ai(e)){const i={};for(let n=1;n<di(e);n++){const t=gi(ci(e,n));t&&(i[t[0]]=t[1])}return i}return null}function vi(e){var i;if("nan"===(e=e.toLowerCase().replace(/[nd]$/g,"").replace(/[\u0009-\u000d\u0020\u00a0]/g,"")))return NaN;if("+infinity"===e)return 1/0;if("-infinity"===e)return-1/0;if(/\([0-9]+\)/.test(e)){const[n,t,r,s]=null!==(i=e.match(/(.+)\(([0-9]+)\)(.*)$/))&&void 0!==i?i:[];e=t+r.repeat(Math.ceil(16/r.length))+(null!=s?s:"")}return parseFloat(e)}function bi(e){return null==e?null:"number"==typeof e?e:ii(e)?vi(e.num):"string"==typeof e?vi(e):null}function yi(e){var i,n;if(null==e)return null;if("Half"===fi(e))return[1,2];const t=ai(e);if(!t)return null;let r=null,s=null;if("Negate"===t){const i=yi(hi(e));if(i)return[-i[0],i[1]]}if("Rational"!==t&&"Divide"!==t||(r=null!==(i=bi(hi(e)))&&void 0!==i?i:NaN,s=null!==(n=bi(mi(e)))&&void 0!==n?n:NaN),"Power"===t){const i=bi(mi(e));1===i?(r=bi(hi(e)),s=1):-1===i&&(r=1,s=bi(hi(e)))}return"Multiply"===t&&"Power"===ai(mi(e))&&-1===bi(mi(mi(e)))&&(r=bi(hi(e)),s=bi(hi(mi(e)))),null===r||null===s?null:Number.isInteger(r)&&Number.isInteger(s)?[r,s]:null}function Ni(e,i){var n;const t=ai(e);if(null!==t)return[Ni(t,i),...(null!==(n=ui(e))&&void 0!==n?n:[]).map((e=>Ni(e,i)))];const r=pi(e);if(null!==r){const e=Object.keys(r),n={};for(const t of e)n[t]=Ni(r[t],i);return{dict:n}}const s=fi(e);return s&&i[s]?i[s]:e}function _i(e,i){let n=null;if(Array.isArray(e)&&(n=e),ti(e)&&(n=e.fn),null===n)return[];let t=1;const r=[];for(;t<n.length;)r.push(i(n[t])),t+=1;return r}function xi(e,i,n,t="both"){var r,s,o,a,l,u;if("non"===t)return[e,i,n];const c=ai(i),h=ai(n);return"left"===t?c===e?[e,...null!==(r=ui(i))&&void 0!==r?r:[],n]:[e,i,n]:"right"===t?h===e?[e,i,...null!==(s=ui(n))&&void 0!==s?s:[]]:[e,i,n]:c===e&&h===e?[e,...null!==(o=ui(i))&&void 0!==o?o:[],...null!==(a=ui(n))&&void 0!==a?a:[]]:c===e?[e,...null!==(l=ui(i))&&void 0!==l?l:[],n]:h===e?[e,i,...null!==(u=ui(n))&&void 0!==u?u:[]]:[e,i,n]}function Si(e){var i;let n=ai(e);if(null===e)return null;if("Delimiter"===n){if(null===(e=ci(e,1)))return[];if("Sequence"!==ai(e))return[e]}return n=ai(e),"Sequence"===n?null!==(i=ui(e))&&void 0!==i?i:[]:null}function wi(e){return null!==e&&"Sequence"===ai(e)&&0===di(e)}function ki(e){return null===e||wi(e)?["Error","'missing'"]:e}function Ei(e){return"Square"===e[0]?Ei(e.slice(1))+2:e.reduce(((e,i)=>e+Ai(i)),0)}function Ai(e){if(null===e)return 0;if("number"==typeof e||"string"==typeof e)return 1;if(ii(e)||ni(e)||function(e){return null!==e&&"object"==typeof e&&"str"in e}(e))return 1;if(Array.isArray(e))return Ei(e);if("fn"in e)return Ei(e.fn);const i=pi(e);if(i){const e=Object.keys(i);return 1+e.length+e.reduce(((e,n)=>e+Ai(i[n])),0)}return 0}function Ii(e,i){return i>2?"solidus":"radical"}function Mi(e,i){if(i>3)return"inline-solidus";if("Divide"===ai(e)){const[i,n]=[Ai(hi(e)),Ai(mi(e))];if(n<=2&&i>3)return"factor";if(i<=2&&n>3)return"reciprocal"}return"quotient"}function qi(e,i,n,t){return null===n?"\\sqrt{}":(t=null!=t?t:2,"solidus"===i?e.wrapShort(n)+"^{1\\/"+e.serialize(t)+"}":"quotient"===i?e.wrapShort(n)+"^{\\frac{1}{"+e.serialize(t)+"}}":2===bi(t)?"\\sqrt{"+e.serialize(n)+"}":"\\sqrt["+e.serialize(t)+"]{"+e.serialize(n)+"}")}function Oi(e,i){if(null===i)return"";const n=ki(ci(i,1)),t=ki(ci(i,2)),r=Mi(i,e.level);if("inline-solidus"===r||"nice-solidus"===r){const i=e.wrapShort(n),s=e.wrapShort(t);return"inline-solidus"===r?`${i}\\/${s}`:`^{${i}}\\!\\!/\\!_{${s}}`}return"reciprocal"===r?1===bi(n)?e.wrap(t)+"^{-1}":e.wrap(n)+e.wrap(t)+"^{-1}":"factor"===r?1===bi(t)?e.wrap(n):"\\frac{1}{"+e.serialize(t)+"}"+e.wrap(n):`\\frac{${e.serialize(n)}}{${e.serialize(t)}}`}function Ti(e,i){var n;const t=ai(i),r=ki(ci(i,1));if("Sqrt"===t)return qi(e,Ii(0,e.level-1),r,2);const s=ki(ci(i,2));if("Root"===t)return qi(e,Ii(0,e.level-1),r,s);const o=null!==(n=bi(s))&&void 0!==n?n:1;if(-1===o)return e.serialize(["Divide","1",r]);if(o<0)return e.serialize(["Divide","1",["Power",r,-o]]);if("Divide"===ai(s)||"Rational"===ai(s)){if(1===bi(ci(s,1)))return qi(e,Ii(0,e.level),r,ci(s,2));if(2===bi(ci(s,2)))return`${e.serialize(["Sqrt",r])}^{${e.serialize(ci(s,1))}}`}else if("Power"===ai(s)&&-1===bi(ci(s,2)))return qi(e,Ii(0,e.level),r,ci(s,1));return e.wrapShort(r)+"^{"+e.serialize(s)+"}"}const Fi=[{name:"CatalanConstant",serialize:"G"},{name:"GoldenRatio",serialize:"\\varphi"},{name:"EulerGamma",serialize:"\\gamma"},{name:"Degrees",trigger:["\\degree"],kind:"postfix",precedence:880,parse:(e,i)=>["Degrees",i],serialize:(e,i)=>Xe([e.serialize(ci(i,1)),"\\degree"])},{trigger:["\\deg"],kind:"postfix",precedence:880,parse:(e,i)=>["Degrees",i]},{trigger:["^","<{>","\\circ","<}>"],kind:"postfix",parse:(e,i)=>["Degrees",i]},{trigger:["^","\\circ"],kind:"postfix",parse:(e,i)=>["Degrees",i]},{trigger:["\xb0"],kind:"postfix",precedence:880,parse:(e,i)=>["Degrees",i]},{trigger:["\\ang"],parse:e=>{const i=e.matchRequiredLatexArgument();return null===i?["Degrees"]:["Degrees",i]}},{trigger:["\\infty"],parse:{num:"+Infinity"}},{name:"ComplexInfinity",trigger:["\\tilde","\\infty"],serialize:"\\tilde\\infty"},{trigger:["\\tilde","<{>","\\infty","<}>"],parse:"ComplexInfinity"},{name:"Pi",trigger:["\\pi"]},{trigger:["\u03c0"],parse:"Pi"},{name:"ExponentialE",trigger:["\\exponentialE"],parse:"ExponentialE",serialize:"\\exponentialE"},{name:"ImaginaryUnit",trigger:["\\imaginaryI"]},{name:"Abs",kind:"matchfix",openDelimiter:"|",closeDelimiter:"|",parse:(e,i)=>wi(i)?null:["Abs",i]},{trigger:"abs",kind:"function",parse:e=>{const i=e.matchArguments("enclosure");return null===i?"Abs":["Abs",...i]}},{name:"Add",trigger:["+"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,n)=>{if(275<i.minPrec)return null;const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:275}));return null===t?null:xi("Add",n,t)},serialize:function(e,i){var n,t,r,s;e.level-=1;const o=ai(i);let a="",l=ci(i,1);if("Negate"===o)a="-"+e.wrap(l,276);else if("Add"===o){if(2===di(i)){let r,s;if(bi(ci(i,1))&&yi(ci(i,2))?(r=ci(i,1),s=ci(i,2)):bi(ci(i,2))&&yi(ci(i,1))&&(r=ci(i,2),s=ci(i,1)),r&&s){const i=null!==(n=bi(r))&&void 0!==n?n:NaN,o=null!==(t=yi(s))&&void 0!==t?t:[NaN,NaN];if(isFinite(i)&&Number.isInteger(i)&&i>=0&&i<=1e3&&isFinite(o[0])&&isFinite(o[1])&&o[0]>0&&o[0]<=100&&o[1]<=100)return a=Xe([e.serialize(r),e.options.invisiblePlus,e.serialize(s)]),e.level+=1,a}}let o=null!==(r=bi(l))&&void 0!==r?r:NaN;a=e.serialize(l);const u=di(i)+1;for(let n=2;n<u;n++)if(l=ci(i,n),o=null!==(s=bi(l))&&void 0!==s?s:NaN,o<0)a+=e.serialize(l);else if("Negate"===ai(l))a+=e.wrap(l,275);else{const i=e.wrap(l,275);"-"===i[0]||"+"===i[0]?a+=i:a+="+"+i}}else if("Subtract"===o){a=e.wrap(l,275);const n=ci(i,2);if(null!==n){const i=e.wrap(n,275);"-"===i[0]?a+="+"+i.slice(1):"+"===i[0]?a+="-"+i.slice(1):a=a+"-"+i}}return e.level+=1,a}},{kind:"prefix",trigger:["+"],precedence:275,parse:(e,i)=>275<i.minPrec?null:e.matchExpression(Object.assign(Object.assign({},i),{minPrec:400}))},{name:"Ceil",kind:"matchfix",openDelimiter:"\\lceil",closeDelimiter:"\\rceil"},{trigger:"ceil",kind:"function",parse:e=>{const i=e.matchArguments("enclosure");return null===i?"Ceil":["Ceil",...i]}},{name:"Complex",precedence:274,serialize:(e,i)=>{const n=bi(ci(i,1)),t=bi(ci(i,2));if(0===t)return e.serialize(ci(i,1));const r=1===t?"\\imaginaryI":-1===t?"-\\imaginaryI":Xe([e.serialize(ci(i,2)),"\\imaginaryI"]);return 0===n?r:Xe(null!==t&&t<0?[e.serialize(ci(i,1)),r]:[e.serialize(ci(i,1)),"+",r])}},{name:"Divide",trigger:"\\frac",precedence:660,parse:function(e){var i,n;const t=ki(e.matchRequiredLatexArgument()),r=ki(e.matchRequiredLatexArgument());if("PartialDerivative"===ai(t)&&("PartialDerivative"===ai(r)||"Multiply"===ai(r)&&"PartialDerivative"===ai(ci(r,1)))){const s=null!==(i=ci(t,3))&&void 0!==i?i:null;let o=ci(t,1);null===o&&(o=ki(e.matchExpression()));let a=[];if("Multiply"===ai(r)){for(const e of null!==(n=ui(r))&&void 0!==n?n:[])if("PartialDerivative"===ai(e)){const i=ci(e,2);i&&a.push(i)}}else{const e=ci(r,2);e&&a.push(e)}return a.length>1&&(a=["List",...a]),["PartialDerivative",o,...a,null===s?1:s]}return["Divide",t,r]},serialize:Oi},{kind:"infix",trigger:"\\over",precedence:660,parse:"Divide"},{trigger:["\\/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["\\div"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{name:"Exp",serialize:(e,i)=>Xe(["\\exponentialE^{",e.serialize(ki(ci(i,1))),"}"])},{name:"Factorial",trigger:["!"],kind:"postfix",precedence:810},{name:"Factorial2",trigger:["!","!"],kind:"postfix",precedence:810},{name:"Floor",kind:"matchfix",openDelimiter:"\\lfloor",closeDelimiter:"\\rfloor"},{trigger:"floor",kind:"function",parse:e=>{const i=e.matchArguments("enclosure");return null===i?"Floor":["Floor",...i]}},{name:"Gcd",trigger:"gcd",kind:"function"},{name:"Half",serialize:"\\frac12"},{name:"Lg",trigger:["\\lg"],serialize:(e,i)=>"\\log_{10}"+e.wrapArguments(i),parse:e=>{const i=e.matchArguments("implicit");return null===i?["Lg"]:["Log",...i,10]}},{name:"Lb",trigger:"\\lb",parse:e=>{const i=e.matchArguments("implicit");return null===i?["Log"]:["Log",...i,2]}},{name:"Ln",trigger:["\\ln"],serialize:(e,i)=>"\\ln"+e.wrapArguments(i),parse:e=>Pi("Ln",e)},{name:"Log",trigger:["\\log"],parse:e=>Pi("Log",e),serialize:(e,i)=>{const n=mi(i);return n?Xe(["\\log_{",n.toString(),"}",e.wrap(hi(i))]):"\\log"+e.wrapArguments(i)}},{name:"Lcm",trigger:"lcm",kind:"function"},{name:"MinusPlus",trigger:["\\mp"],kind:"infix",associativity:"both",precedence:270},{name:"Multiply",trigger:["\\times"],kind:"infix",associativity:"both",precedence:390,serialize:function e(i,n){var t;if(null===n)return"";i.level-=1;let r="";const[s,o]=function(e){var i,n;if("Multiply"!==ai(e))return[[],[]];const t=[],r=[],s=null!==(i=ui(e))&&void 0!==i?i:[];for(const e of s)if("Power"===ai(e)){const i=ci(e,1),s=ci(e,2);if("Negate"===ai(s)){const e=ci(s,1);i&&e&&r.push(["Power",i,e])}else{const o=null!==(n=bi(s))&&void 0!==n?n:NaN;-1===o?i&&r.push(i):o<0?i&&r.push(["Power",i,-o]):t.push(e)}}else if("Rational"===ai(e)&&2===di(e)){const i=ci(e,1),n=ci(e,2);1!==bi(i)&&t.push(i),1!==bi(n)&&r.push(n)}else{const i=yi(e);null!==i?(1!==i[0]&&t.push(i[0]),r.push(i[1])):t.push(e)}return[t,r]}(n);if(o.length>0&&(r=1===o.length&&1===o[0]?0===s.length?"1":1===s.length?i.serialize(s[0]):e(i,["Multiply",...s]):i.serialize(["Divide",1===s.length?s[0]:["Multiply",...s],1===o.length?o[0]:["Multiply",...o]])),r)return i.level+=1,r;let a=!1,l=null;const u=di(n)+1;let c=!1;for(let e=1;e<u;e++){if(l=ci(n,e),null===l)continue;let s;if("number"==typeof l||ii(l))s=i.serialize(l),"-1"!==s||r?("-"===s[0]&&(s=s.slice(1),a=!a),r=r?Xe([r,i.options.multiply,s]):s):(r="",a=!a),c=!0;else{if("Power"===ai(l)){const e=yi(ci(l,2));if(e){const[n,t]=e;if(1===n&&null!==t){r+=qi(i,Ii(0,i.level),ci(l,1),t),c=!1;continue}}}if("Power"!==ai(l)||isNaN(null!==(t=bi(ci(l,1)))&&void 0!==t?t:NaN)){if("Negate"===ai(l)&&(l=ci(l,1),a=!a),s=i.wrap(l,390),r){const e=ai(l);r=!c||"Divide"!==e&&"Rational"!==e?i.options.invisibleMultiply?Xe([r,i.options.invisibleMultiply,s]):Xe([r,s]):Xe([r,i.options.multiply,s])}else r=s;c=!1}else s=i.serialize(l),r=r?Xe([r,i.options.multiply,s]):s,c=!0}}return i.level+=1,a?"-"+r:r}},{trigger:["\\cdot"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,n)=>{if(391<i.minPrec)return null;const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:392}));return null===t?["Multiply",n,["Error","'missing'"]]:xi("Multiply",n,t)}},{trigger:["*"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,n)=>{if(391<i.minPrec)return null;const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:392}));return null===t?["Multiply",n,["Error","'missing'"]]:xi("Multiply",n,t)}},{name:"Negate",trigger:["-"],kind:"prefix",parse:(e,i)=>276<i.minPrec?null:["Negate",ki(e.matchExpression(Object.assign(Object.assign({},i),{minPrec:400})))],precedence:275},{kind:"matchfix",openDelimiter:"||",closeDelimiter:"||",parse:(e,i)=>wi(i)?null:["Norm",i]},{name:"Norm",kind:"matchfix",openDelimiter:["\\left","\\Vert"],closeDelimiter:["\\right","\\Vert"]},{name:"PlusMinus",trigger:["\\pm"],kind:"infix",associativity:"both",precedence:270},{name:"Power",trigger:["^"],kind:"infix",serialize:Ti},{trigger:"\\prod",precedence:265,name:"Product",parse:Ci("Product"),serialize:Di("\\prod")},{name:"Rational",precedence:660,serialize:(e,i)=>i&&1===di(i)?"\\mathrm{Rational}"+e.wrapArguments(i):Oi(e,i)},{name:"Root",serialize:Ti},{name:"Round",trigger:"round",kind:"function"},{name:"Square",precedence:720,serialize:(e,i)=>e.wrapShort(ci(i,1))+"^2"},{trigger:"\\sum",precedence:265,name:"Sum",parse:Ci("Sum"),serialize:Di("\\sum")},{name:"Sign",trigger:"sgn",kind:"function"},{name:"Sqrt",trigger:["\\sqrt"],parse:function(e){const i=e.matchOptionalLatexArgument(),n=e.matchRequiredLatexArgument();return null===n||wi(n)?null!==i?["Root",["Error","'missing'"],ki(i)]:["Sqrt",["Error","'missing'"]]:null!==i?["Root",n,i]:["Sqrt",n]},serialize:Ti},{name:"Subtract",trigger:["-"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,n)=>276<i.minPrec?null:["Subtract",n,ki(e.matchExpression(Object.assign(Object.assign({},i),{minPrec:277})))]}];function Ci(e){return i=>{var n,t;i.skipSpace();let r=null,s=null;for(;!(s&&r||"_"!==i.peek&&"^"!==i.peek);)i.match("_")?s=i.matchRequiredLatexArgument():i.match("^")&&(r=i.matchRequiredLatexArgument()),i.skipSpace();("Nothing"===s||wi(s))&&(s=null),("Nothing"===r||wi(r))&&(r=null);let o=null,a=null;"Equal"===ai(s)?(o=ci(s,1),a=ci(s,2)):o=s;const l=fi(o);l&&(null===(n=i.computeEngine)||void 0===n||n.pushScope({symbolTable:{symbols:[{name:l,domain:"Integer"}]}}));const u=i.matchExpression({minPrec:266});return l&&(null===(t=i.computeEngine)||void 0===t||t.popScope()),u?r?[e,u,["Tuple",o?["Hold",o]:"Nothing",null!=a?a:1,r]]:a?[e,u,["Tuple",o?["Hold",o]:"Nothing",a]]:o?[e,u,["Tuple",["Hold",o]]]:[e,u]:[e]}}function Di(e){return(i,n)=>{if(!ci(n,1))return e;let t=ci(n,2);const r=ai(t);"Tuple"!==r&&"Triple"!==r&&"Pair"!==r&&"Single"!==r&&(t=null);let s=ci(t,1);s&&"Hold"===ai(s)&&(s=ci(s,1));const o=ci(n,1);if(!t)return ci(n,2)?Xe([e,"_{",i.serialize(ci(n,2)),"}",i.serialize(o)]):Xe([e,"_n",i.serialize(o)]);const a=ci(t,2);let l=[];s&&"Nothing"!==fi(s)&&a?l=[i.serialize(s),"=",i.serialize(a)]:s&&"Nothing"!==fi(s)?l=[i.serialize(s)]:a&&(l=[i.serialize(a)]),l.length>0&&(l=["_{",...l,"}"]);let u=[];return ci(t,3)&&(u=["^{",i.serialize(ci(t,3)),"}"]),Xe([e,...u,...l,i.serialize(o)])}}function Pi(e,i){var n;let t=null,r=null;i.match("_")&&(t=null!==(n=i.matchStringArgument())&&void 0!==n?n:i.next(),r=Number.parseFloat(null!=t?t:"10"));const s=i.matchArguments("implicit");return null===s?[e]:10===r?["Log",s[0]]:2===r?["Lb",...s]:null===t?[e,...s]:["Log",...s,t]}function Li(e,i,n,t,r){if(i.minPrec>=t)return null;const s=[n];let o=!1;for(;!o;){for(o=!0,e.skipSpace();e.match(r);)s.push("Nothing"),e.skipSpace();if(e.atTerminator(i))s.push("Nothing");else{const n=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:t}));s.push(null!=n?n:"Nothing"),o=null===n}o||(e.skipSpace(),o=!e.match(r))}return s}function Ri(e=""){return(i,n)=>{var t;return(null!==(t=ui(n))&&void 0!==t?t:[]).map((e=>i.serialize(e))).join(e)}}const zi=[{trigger:["\\placeholder"],parse:e=>{if(e.skipSpaceTokens(),e.match("["))for(;!e.match("]")&&!e.atBoundary;)e.next();if(e.skipSpaceTokens(),e.match("<{>"))for(;!e.match("<}>")&&!e.atBoundary;)e.next();return"Nothing"}},{name:"BaseForm",kind:"function",serialize:(e,i)=>{var n,t;const r=null!==(n=bi(ci(i,2)))&&void 0!==n?n:NaN;if(isFinite(r)&&r>=2&&r<=36){const e=null!==(t=bi(ci(i,1)))&&void 0!==t?t:NaN;if(isFinite(e)&&Number.isInteger(e)){let i=Number(e).toString(r),n=0;if(2===r||10===r?n=4:16===r?n=2:r>16&&(n=4),n>0){const e=i;i="";for(let t=0;t<e.length;t++)t>0&&t%n==0&&(i="\\, "+i),i=e[e.length-t-1]+i}return`(\\text{${i}}_{${r}}`}}return"\\operatorname{BaseForm}("+e.serialize(ci(i,1))+", "+e.serialize(ci(i,2))+")"}},{name:"Delimiter",serialize:(e,i)=>{var n,t,r,s,o;const a=di(i);if(0===a)return"";const l=e.options.groupStyle(i,e.level+1),u=ci(i,1);if(1===a)return e.wrapString(e.serialize(u),l);let c="",h="",m="";if(a>1){const e=null!==(n=si(ci(i,2)))&&void 0!==n?n:"";h=null!==(t=e[0])&&void 0!==t?t:"",m=null!==(r=e[1])&&void 0!==r?r:"",c=null!==(s=e[2])&&void 0!==s?s:""}const d="List"===ai(u)?Ri(c)(e,u):e.serialize(u);return e.wrapString(d,l,null!==(o=si(ci(i,2)))&&void 0!==o?o:void 0),h&&m?`${h} ${d} ${m}`:e.wrapString(d,l)}},{name:"Domain",serialize:(e,i)=>"Error"===ai(i)?e.serialize(i):`\\mathbf{${e.serialize(ci(i,1))}}`},{name:"Error",serialize:(e,i)=>{var n;if("missing"===si(ci(i,1)))return`\\error{${null!==(n=e.options.missingSymbol)&&void 0!==n?n:"\\placeholder{}"}}`;const t=function(e,i){var n;const t=ci(i,2);return t?"Latex"===ai(t)?`\\texttt{${Vi(null!==(n=si(ci(t,1)))&&void 0!==n?n:"")}}`:"Hold"===ai(t)?e.serialize(ci(t,1)):e.serialize(t):""}(e,i)||"\\blacksquare",r=ci(i,1);return"incompatible-domain"===("ErrorCode"===ai(r)?si(ci(r,1)):si(r))?`\\mathtip{\\error{${t}}{\\in ${e.serialize(ci(r,3))}\\notin ${e.serialize(ci(r,2))}}`:`\\error{${t}}`}},{name:"ErrorCode",serialize:(e,i)=>{var n;const t=si(ci(i,1));return"missing"===t?null!==(n=e.options.missingSymbol)&&void 0!==n?n:"\\placeholder{}":"unexpected-command"===t||"unexpected-operator"===t||"unexpected-token"===t||"invalid-symbol-name"===t||"unknown-environment"===t||"unexpected-base"===t||"incompatible-domain"===t||"invalid-domain-expression"===t?"":`\\texttip{\\error{\\blacksquare}}{\\mathtt{${t}}}`}},{name:"FromLatex",serialize:(e,i)=>`\\texttt{${Vi(si(ci(i,1)))}}`},{name:"Latex",serialize:(e,i)=>null===i?"":Xe(_i(i,(i=>{var n;return null!==(n=si(i))&&void 0!==n?n:e.serialize(i)})))},{name:"LatexString",serialize:(e,i)=>null===i?"":Xe(_i(i,(i=>e.serialize(i))))},{name:"LatexTokens",serialize:function(e,i){return null===i?"":Xe(_i(i,(i=>{const n=si(i);return null===n?e.serialize(i):"<{>"===n?"{":"<}>"===n?"}":"<$>"===n?"$":"<$$>"===n?"$$":"<space>"===n?" ":n})))}},{name:"List",kind:"matchfix",openDelimiter:"[",closeDelimiter:"]",parse:(e,i)=>{var n;return null===i?["List"]:"Sequence"!==ai(i)&&"List"!==ai(i)?["List",i]:["List",...null!==(n=ui(i))&&void 0!==n?n:[]]},serialize:(e,i)=>Xe(["\\lbrack",Ri(", ")(e,i),"\\rbrack"])},{kind:"matchfix",openDelimiter:"(",closeDelimiter:")",parse:(e,i)=>{var n;return null===i?null:"Sequence"===ai(i)||"List"===ai(i)?0===di(i)?["Delimiter"]:["Delimiter",["Sequence",...null!==(n=ui(i))&&void 0!==n?n:[]]]:["Delimiter",i]}},{trigger:[","],kind:"infix",precedence:20,parse:(e,i,n)=>{const t=Li(e,i,n,20,",");return null===t?null:["Sequence",...t]}},{name:"Sequence",serialize:Ri("")},{trigger:[";"],kind:"infix",precedence:19,parse:(e,i,n)=>{const t=Li(e,i,n,19,";");return null===t?null:["Sequence",...t.map((e=>{var i;return"Sequence"===ai(e)?["List",...null!==(i=ui(e))&&void 0!==i?i:[]]:e}))]}},{name:"String",trigger:["\\text"],parse:e=>$i(e),serialize:(e,i)=>{const n=ui(i);return null===n||0===n.length?"\\text{}":Xe(["\\text{",n.map((i=>e.serialize(i))).join(""),"}"])}},{name:"Subscript",trigger:["_"],kind:"infix",serialize:(e,i)=>2===di(i)?e.serialize(ci(i,1))+"_{"+e.serialize(ci(i,2))+"}":"_{"+e.serialize(ci(i,1))+"}"},{name:"Superplus",trigger:["^","+"],kind:"postfix"},{name:"Subplus",trigger:["_","+"],kind:"postfix"},{name:"Superminus",trigger:["^","-"],kind:"postfix"},{name:"Subminus",trigger:["_","-"],kind:"postfix"},{trigger:["^","*"],kind:"postfix",parse:(e,i)=>["Superstar",i]},{name:"Superstar",trigger:["^","\\star"],kind:"postfix"},{trigger:["_","*"],kind:"postfix",parse:(e,i)=>["Substar",i]},{name:"Substar",trigger:["_","\\star"],kind:"postfix"},{name:"Superdagger",trigger:["^","\\dagger"],kind:"postfix"},{trigger:["^","\\dag"],kind:"postfix",parse:(e,i)=>["Superdagger",i]},{name:"Prime",trigger:["^","\\prime"],kind:"postfix"},{trigger:["^","\\doubleprime"],kind:"postfix",parse:(e,i)=>["Prime",ki(i),2]},{name:"InverseFunction",serialize:(e,i)=>e.serialize(ci(i,1))+"^{-1}"},{name:"Derivative",serialize:(e,i)=>{var n;const t=null!==(n=bi(ci(i,1)))&&void 0!==n?n:NaN;if(!isFinite(t))return"";const r=e.serialize(ci(i,2));return 1===t?r+"^{\\prime}":2===t?r+"^{\\doubleprime}":r+"^{("+Number(t).toString()+")}"}},{name:"Which",trigger:"cases",kind:"environment",parse:e=>{var i;const n=e.matchTabular("cases");if(!n)return["Which"];const t=["Which"];for(const e of n)if(1===e.length)t.push("True"),t.push(e[0]);else if(2===e.length){const n=si(e[1]);t.push(n?"True":null!==(i=oi(e[1]))&&void 0!==i?i:"True"),t.push(e[0])}return t},serialize:(e,i)=>{var n;if("List"!==ai(ci(i,1)))return"";const t=null!==(n=ui(ci(i,1)))&&void 0!==n?n:[],r=[];let s="";for(const i of t){if(("Tuple"===ai(i)||"Pair"===ai(i))&&(r.push(s),ci(i,2))){r.push(e.serialize(ci(i,2)));const n=ci(i,1);null!==n&&r.push("&",e.serialize(n))}s="\\\\"}return Xe(["\\begin{cases}",...r,"\\end{cases}"])}}];function $i(e,i){var n,t,r;if(!e.match("<{>"))return"''";const s=[];let o,a="",l=null;for(;!e.atEnd&&!e.match("<}>");)if("<{>"===e.peek)s.push($i(e));else if(e.match("\\textbf")&&e.match("<{>"))s.push($i(e,{"font-weight":"bold"}));else if(e.match("\\color")&&e.match("<{>")){const i=e.matchColor();i&&e.match("<}>")&&(null!==l&&a?s.push(["Style",a,{dict:l}]):a&&s.push(["String",a]),a="",l={color:i})}else if(e.match("<space>"))a+=" ";else if(e.match("<$>")){const i=e.index,t=null!==(n=e.matchExpression())&&void 0!==n?n:["Sequence"];e.skipSpace(),e.match("<$>")?s.push(t):(a+="$",e.index=i)}else if(e.match("<$$>")){const i=e.index,n=null!==(t=e.matchExpression())&&void 0!==t?t:["Sequence"];e.skipSpace(),e.match("<$$>")?s.push(n):(a+="$$",e.index=i)}else a+=null!==(r=e.matchChar())&&void 0!==r?r:"";return null!==l&&a?s.push(["Style",`'${a}'`,{dict:l}]):a&&s.push(`'${a}'`),o=1===s.length?s[0]:s.every((e=>null!==si(e)))?"'"+s.map((e=>si(e))).join()+"'":["String",...s],i?["Style",o,{dict:i}]:o}function Vi(e){return null===e?"":e.replace(/[{}\[\]\\:\-\$%]/g,(e=>{var i;return null!==(i={"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "}[e])&&void 0!==i?i:"\\"+e}))}function ji(e){return i=>{const n=i.matchRequiredLatexArgument();return null===n?[e]:[e,n]}}const Gi=[{name:"Overscript",trigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",trigger:["\\underset"],kind:"infix",precedence:700},{name:"Increment",trigger:["+","+"],kind:"postfix",precedence:880},{name:"Decrement",trigger:["-","-"],kind:"postfix",precedence:880},{name:"PreIncrement",trigger:["+","+"],kind:"prefix",precedence:880},{name:"PreDecrement",trigger:["-","-"],kind:"prefix",precedence:880},{name:"Ring",trigger:["\\circ"],kind:"infix",precedence:265},{name:"Transpose",trigger:["^","T"],kind:"infix"},{name:"ConjugateTranspose",trigger:["^","H"],kind:"infix"},{name:"StringJoin",trigger:["\\lt","\\gt"],kind:"infix",precedence:780},{name:"Starstar",trigger:["\\star","\\star"],kind:"infix",precedence:780},{name:"PartialDerivative",trigger:["\\partial"],kind:"prefix",parse:e=>{var i,n;let t=!1,r="Nothing",s="Nothing";for(;!t;)e.skipSpace(),e.match("_")?s=e.matchRequiredLatexArgument():e.match("^")?r=e.matchRequiredLatexArgument():t=!0;const o=Si(s);if(o&&(s=["List",...o]),null===s||null===r)return null;let a=null!==(i=e.matchRequiredLatexArgument())&&void 0!==i?i:"Nothing";return"Nothing"===a||wi(a)||(a=[a,...null!==(n=e.matchArguments("enclosure"))&&void 0!==n?n:["Nothing"]]),["PartialDerivative",a,s,r]},serialize:(e,i)=>{var n;let t="\\partial";const r=ci(i,1),s=ci(i,2),o=ci(i,3);return null!==s&&"Nothing"!==s&&("List"===ai(s)?t+="_{"+e.serialize(["Sequence",...null!==(n=ui(s))&&void 0!==n?n:[]])+"}":t+="_{"+e.serialize(s)+"}"),null!==o&&"Nothing"!==o&&(t+="^{"+e.serialize(o)+"}"),null!==r&&"Nothing"!==r&&(t+=e.serialize(r)),t},precedence:740},{name:"OverBar",trigger:["\\overline"],parse:ji("OverBar")},{name:"UnderBar",trigger:["\\underline"],parse:ji("UnderBar")},{name:"OverVector",trigger:["\\vec"],parse:ji("OverVector")},{name:"OverTilde",trigger:["\\tilde"],parse:ji("OverTilde")},{name:"OverHat",trigger:["\\hat"],parse:ji("OverHat")},{name:"OverRightArrow",trigger:["\\overrightarrow"],parse:ji("OverRightArrow")},{name:"OverLeftArrow",trigger:["\\overleftarrow"],parse:ji("OverLeftArrow")},{name:"OverRightDoubleArrow",trigger:["\\Overrightarrow"],parse:ji("OverRightDoubleArrow")},{name:"OverLeftHarpoon",trigger:["\\overleftharpoon"],parse:ji("OverLeftHarpoon")},{name:"OverRightHarpoon",trigger:["\\overrightharpoon"],parse:ji("OverRightHarpoon")},{name:"OverLeftRightArrow",trigger:["\\overleftrightarrow"],parse:ji("OverLeftRightArrow")},{name:"OverBrace",trigger:["\\overbrace"],parse:ji("OverBrace")},{name:"OverLineSegment",trigger:["\\overlinesegment"],parse:ji("OverLineSegment")},{name:"OverGroup",trigger:["\\overgroup"],parse:ji("OverGroup")},{trigger:["\\displaystyle"],parse:()=>["Sequence"]},{trigger:["\\textstyle"],parse:()=>["Sequence"]},{trigger:["\\scriptstyle"],parse:()=>["Sequence"]},{trigger:["\\scriptscriptstyle"],parse:()=>["Sequence"]},{trigger:["\\tiny"],parse:()=>["Sequence"]},{trigger:["\\scriptsize"],parse:()=>["Sequence"]},{trigger:["\\footnotesize"],parse:()=>["Sequence"]},{trigger:["\\small"],parse:()=>["Sequence"]},{trigger:["\\normalsize"],parse:()=>["Sequence"]},{trigger:["\\large"],parse:()=>["Sequence"]},{trigger:["\\Large"],parse:()=>["Sequence"]},{trigger:["\\LARGE"],parse:()=>["Sequence"]},{trigger:["\\huge"],parse:()=>["Sequence"]},{trigger:["\\Huge"],parse:()=>["Sequence"]},{name:"Style",serialize:(e,i)=>{let n=e.serialize(ci(i,1));const t=pi(ci(i,2));if(null===t)return n;"block"===si(t.display)?n=Xe(["{\\displaystyle",n,"}"]):"inline"===si(t.display)?n=Xe(["{\\textstyle",n,"}"]):"script"===si(t.display)?n=Xe(["{\\scriptstyle",n,"}"]):"scriptscript"===si(t.display)&&(n=Xe(["{\\scriptscriptstyle",n,"}"]));const r=bi(t.size);return null!==r&&r>=1&&r<=10&&(n=Xe(["{",{1:"\\tiny",2:"\\scriptsize",3:"\\footnotesize",4:"\\small",5:"\\normalsize",6:"\\large",7:"\\Large",8:"\\LARGE",9:"\\huge",10:"\\Huge"}[r],n,"}"])),n}},{trigger:["\\!"],parse:()=>["HorizontalSpacing",-3]},{trigger:["\\ "],parse:()=>["HorizontalSpacing",6]},{trigger:["\\:"],parse:()=>["HorizontalSpacing",4]},{trigger:["\\enskip"],parse:()=>["HorizontalSpacing",9]},{trigger:["\\quad"],parse:()=>["HorizontalSpacing",18]},{trigger:["\\qquad"],parse:()=>["HorizontalSpacing",36]},{trigger:["\\,"],parse:()=>["HorizontalSpacing",3]},{trigger:["\\;"],parse:()=>["HorizontalSpacing",5]},{trigger:["\\enspace"],parse:()=>["HorizontalSpacing",9]},{name:"HorizontalSpacing",serialize:(e,i)=>{var n;if(ci(i,2))return e.serialize(ci(i,1));const t=bi(ci(i,1));return null===t?"":null!==(n={"-3":"\\!",6:"\\ ",3:"\\,",4:"\\:",5:"\\;",9:"\\enspace",18:"\\quad",36:"\\qquad"}[t])&&void 0!==n?n:""}}];function Zi(e){return i=>{var n,t;let r=!1,s=0,o=null;if(i.skipSpace(),i.match("^")){i.skipSpace();const e=i.index;if(i.match("<{>")){if(i.skipSpace(),i.match("-")&&i.match("1")&&(i.skipSpace(),i.match("<}>")&&(r=!0)),!r){let e=!1;for(;!e;)i.skipSpace(),i.match("\\doubleprime")?s+=2:i.match("\\prime")||i.match("'")?s+=1:e=!0;i.match("<}>")||(s=0)}if(0!==s||r||(i.index=e,o=i.matchRequiredLatexArgument()),0===s){let e=!1;for(;!e;)i.skipSpace(),i.match("\\doubleprime")?s+=2:i.match("\\prime")||i.match("'")?s+=1:e=!0}}}let a=null!==(t=null!==(n={"\\arcsin":"Arcsin","\\arccos":"Arccos","\\arctan":"Arctan","\\arctg":"Arctan","\\arcctg":"Arctan","\\arcsec":"Arcsec","\\arccsc":" Arccsc","\\arsinh":"Arsinh","\\arcosh":"Arcosh","\\artanh":"Artanh","\\arcsech":"Arcsech","\\arccsch":"Arcsch","\\ch":"Cosh","\\cos":"Cos","\\cosec":"Csc","\\cosh":"Csch","\\cot":"Cot","\\cotg":"Cot","\\coth":"Coth","\\csc":"Csc","\\ctg":"Cot","\\cth":"Coth","\\sec":"Sec","\\sin":"Sin","\\sinh":"Sinh","\\sh":"Sinh","\\tan":"Tan","\\tanh":"Tanh","\\tg":"Tan","\\th":"Tanh"}[null!=e?e:""])&&void 0!==n?n:e)&&void 0!==t?t:"";r&&(a=["InverseFunction",a]),s>=1&&(a=["Derivative",s,a]);const l=i.matchArguments("implicit");return null===l?o?[["Power",[a,"_"],o]]:a:o?["Power",[a,...l],o]:[a,...l]}}const Bi=[{name:"Arcsin",trigger:["\\arcsin"],parse:Zi("Arcsin")},{name:"Arccos",trigger:["\\arccos"],parse:Zi("Arccos")},{name:"Arctan",trigger:["\\arctan"],parse:Zi("Arctan")},{trigger:["\\arctg"],parse:Zi("Arctan")},{name:"Arccot",trigger:["\\arcctg"],parse:Zi("Arccot")},{name:"Arcsec",trigger:"arcsec",parse:Zi("Arcsec")},{name:"Arccsc",trigger:["\\arccsc"],parse:Zi("Arccsc")},{name:"Arsinh",trigger:["\\arsinh"],parse:Zi("Arsinh")},{name:"Arcosh",trigger:["\\arcosh"],parse:Zi("Arcosh")},{name:"Artanh",trigger:["\\artanh"],parse:Zi("Artanh")},{name:"Arsech",trigger:["\\arsech"],parse:Zi("Arsech")},{name:"Arcsch",trigger:["\\arcsch"],parse:Zi("Arcsch")},{trigger:["\\ch"],parse:Zi("Cosh")},{name:"Cosec",trigger:["\\cosec"],parse:Zi("Cosec")},{name:"Cosh",trigger:["\\cosh"],parse:Zi("Cosh")},{name:"Cot",trigger:["\\cot"],parse:Zi("Cot")},{trigger:["\\cotg"],parse:Zi("Cot")},{name:"Coth",trigger:["\\coth"],parse:Zi("Coth")},{name:"Csc",trigger:["\\csc"],parse:Zi("Csc")},{trigger:["\\ctg"],parse:Zi("Cot")},{trigger:["\\cth"],parse:Zi("Cotanh")},{name:"Sec",trigger:["\\sec"],parse:Zi("Sec")},{name:"Sinh",trigger:["\\sinh"],parse:Zi("Sinh")},{trigger:["\\sh"],parse:Zi("Sinh")},{name:"Tan",trigger:["\\tan"],parse:Zi("Tan")},{trigger:["\\tg"],parse:Zi("Tan")},{name:"Tanh",trigger:["\\tanh"],parse:Zi("Tanh")},{trigger:["\\th"],parse:Zi("Tanh")},{name:"Cos",trigger:["\\cos"],parse:Zi("Cos")},{name:"Sin",trigger:["\\sin"],parse:Zi("Sin")}],Ui=[{name:"AlgebraicNumber",trigger:"\\bar\\Q"},{name:"ComplexNumber",trigger:["\\C"]},{trigger:"\\mathbb{C}",parse:"ComplexNumber"},{name:"ImaginaryNumber",trigger:["\\imaginaryI\\R"]},{name:"ExtendedComplexNumber",trigger:["\\bar\\C"]},{name:"EmptySet",trigger:["\\emptyset"]},{trigger:["\\varnothing"],parse:"EmptySet"},{name:"Integer",trigger:["\\Z"]},{trigger:"\\mathbb{Z}",parse:"Integer"},{name:"RationalNumber",trigger:["\\Q"]},{name:"RealNumber",trigger:["\\R"]},{trigger:"\\mathbb{R}",parse:"RealNumber"},{name:"ExtendedRealNumber",trigger:["\\bar\\R"]},{name:"TranscendentalNumber",trigger:"\\R-\\bar\\Q"},{trigger:"\\R\\backslash\\bar\\Q",parse:"TranscendentalNumber"},{name:"NegativeNumber",trigger:"\\R^-"},{trigger:"\\R^{-}",parse:"NegativeNumber"},{trigger:"\\R_-",parse:"NegativeNumber"},{trigger:"\\R_{-}",parse:"NegativeNumber"},{trigger:"\\R^{\\lt}",parse:"NegativeNumber"},{name:"PositiveNumber",trigger:"\\R^+"},{trigger:"\\R^{+}",parse:"PositiveNumber"},{trigger:"\\R_+",parse:"PositiveNumber"},{trigger:"\\R_{+}",parse:"PositiveNumber"},{trigger:"\\R^{\\gt}",parse:"PositiveNumber"},{name:"NonPositiveNumber",trigger:"\\R^{0-}"},{trigger:"\\R^{-0}",parse:"NonPositiveNumber"},{trigger:"\\R^{\\leq}",parse:"NonPositiveNumber"},{name:"NegativeInteger",trigger:"\\Z^-"},{trigger:"\\Z^-",parse:"NegativeInteger"},{trigger:"\\Z^{-}",parse:"NegativeInteger"},{trigger:"\\Z_-",parse:"NegativeInteger"},{trigger:"\\Z_{-}",parse:"NegativeInteger"},{trigger:"\\Z^{\\lt}",parse:"NegativeInteger"},{name:"PositiveInteger",trigger:"\\Z^+"},{trigger:"\\Z^{+}",parse:"PositiveInteger"},{trigger:"\\Z_+",parse:"PositiveInteger"},{trigger:"\\Z_{+}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt0}",parse:"PositiveInteger"},{trigger:"\\N^+",parse:"PositiveInteger"},{trigger:"\\N^{+}",parse:"PositiveInteger"},{trigger:"\\N^*",parse:"PositiveInteger"},{trigger:"\\N^{*}",parse:"PositiveInteger"},{trigger:"\\N^\\star",parse:"PositiveInteger"},{trigger:"\\N^{\\star}",parse:"PositiveInteger"},{trigger:"\\N_1",parse:"PositiveInteger"},{trigger:"\\N_{1}",parse:"PositiveInteger"},{name:"NonNegativeInteger",trigger:["\\N"]},{trigger:"\\Z^{+0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{0+}",parse:"NonNegativeInteger"},{trigger:"\\mathbb{N}",parse:"NonNegativeInteger"},{trigger:"\\N_0",parse:"NonNegativeInteger"},{trigger:"\\N_{0}",parse:"NonNegativeInteger"},{name:"CartesianProduct",trigger:["\\times"],kind:"infix",associativity:"right",precedence:390,parse:(e,i,n)=>{if(390<i.minPrec)return null;const t=e.computeEngine;if(!t||!t.box(n).domain.isCompatible("Set"))return null;const r=e.index,s=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:390}));return null===s||!0!==t.box(n).domain.isCompatible("Set")?(e.index=r,null):["CartesianProduct",n,s]}},{name:"Complement",trigger:["^","\\complement"],kind:"infix"},{name:"Intersection",trigger:["\\cap"],kind:"infix",precedence:350},{name:"Interval",serialize:Hi},{name:"Multiple",serialize:Hi},{name:"Union",trigger:["\\cup"],kind:"infix",precedence:350},{name:"Range",serialize:Hi},{name:"SetMinus",trigger:["\\setminus"],kind:"infix",precedence:650},{name:"SymmetricDifference",trigger:["\\triangle"],kind:"infix",precedence:260},{trigger:["\\ni"],kind:"infix",associativity:"right",precedence:160,parse:(e,i,n)=>{const t=e.matchExpression(i);return null===t?null:["Element",t,n]}},{name:"Element",trigger:["\\in"],kind:"infix",precedence:240},{name:"NotElement",trigger:["\\notin"],kind:"infix",precedence:240},{name:"NotSubset",trigger:["\\nsubset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSuperset",trigger:["\\nsupset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSubsetNotEqual",trigger:["\\nsubseteq"],kind:"infix",associativity:"right",precedence:240},{name:"NotSupersetNotEqual",trigger:["\\nsupseteq"],kind:"infix",associativity:"right",precedence:240},{name:"SquareSubset",trigger:["\\sqsubset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSubsetEqual",trigger:["\\sqsubseteq"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSuperset",trigger:["\\sqsupset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSupersetEqual",trigger:["\\sqsupseteq"],kind:"infix",associativity:"right",precedence:265},{name:"Subset",trigger:["\\subset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\subsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{trigger:["\\varsubsetneqq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{name:"SubsetEqual",trigger:["\\subseteq"],kind:"infix",precedence:240},{name:"Superset",trigger:["\\supset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\supsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{trigger:["\\varsupsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{name:"SupersetEqual",trigger:["\\supseteq"],kind:"infix",associativity:"right",precedence:240}];function Hi(e,i){var n;if(null===i)return"";const t=ai(i);if(null===t)return"";if("Set"===t)return 0===di(i)?"\\emptyset":2===di(i)&&"Condition"===ai(ci(i,2))?Xe(["\\left\\lbrace",e.serialize(ci(i,1)),"\\middle\\mid",e.serialize(ci(i,2)),"\\right\\rbrace"]):Xe(["\\left\\lbrace",...(null!==(n=ui(i))&&void 0!==n?n:[]).map((i=>e.serialize(i)+" ,")),"\\right\\rbrace"]);if("Range"===t)return Xe(["\\mathopen\\lbrack",e.serialize(ci(i,1)),", ",e.serialize(ci(i,2)),"\\mathclose\\rbrack"]);if("Interval"===t){let n=ci(i,1),t=ci(i,2),r=!1,s=!1;return"Open"===ai(n)&&(n=ci(n,1),r=!0),"Open"===ai(t)&&(t=ci(t,1),s=!0),Xe(["\\mathopen"+(r?"\\rbrack":"\\lbrack"),e.serialize(n),", ",e.serialize(t),"\\mathclose"+(s?"\\lbrack":"\\rbrack")])}return e.numericSetStyle(i,e.level),""}function Wi(e){return i=>{var n;i.skipSpace();let t=null,r=null;for(;!(null!==r&&null!==t||"_"!==i.peek&&"^"!==i.peek);)i.match("_")?r=i.matchRequiredLatexArgument():i.match("^")&&(t=i.matchRequiredLatexArgument()),i.skipSpace();("Nothing"===r||wi(r))&&(r=null),("Nothing"===t||wi(t))&&(t=null);let[s,o]=function(e){const i=e.index;let n=!1,t=e.matchExpression({minPrec:266,condition:()=>(e.matchAll(["\\mathrm","<{>","d","<}>"])&&(n=!0),n)});return n||(e.index=i,t=e.matchExpression({minPrec:266,condition:()=>(e.match("d")&&(n=!0),n)})),t&&!n?Yi(t):[t,n?fi(e.matchSymbol()):null]}(i);if(s&&!o&&("Add"===ai(s)||"Subtract"===ai(s))){const a=[],l=[];for(const e of null!==(n=ui(s))&&void 0!==n?n:[])if(o)l.push(e);else{let i;[i,o]=Yi(e),a.push(null!=i?i:e)}if(null!==o&&l.length>0)return["Add",Qi(i,e,["Add",...a],o,r,t),...l]}return Qi(i,e,s,o,r,t)}}function Qi(e,i,n,t,r,s){if(n&&null===s&&null===r&&!t)return[i,n];if(null!=n||(n="Nothing"),e.computeEngine){const i=e.computeEngine;t&&i.pushScope({symbolTable:{symbols:[{name:t,domain:"ExtendedRealNumber"}]}}),n=i.box(n).json,t&&i.popScope()}const o=t?["Hold",t]:null;return null!==s?[i,n,["Tuple",null!=o?o:"Nothing",null!=r?r:"Nothing",s]]:null!==r?[i,n,["Tuple",null!=o?o:"Nothing",r]]:o?[i,n,o]:[i,n]}function Yi(e){const i=ai(e),n=ci(e,1);if(!n)return[e,null];if("Multiply"===i){const i=ui(e);if(i&&i.length>1){if("d"===fi(i[i.length-2]))return 2===i.length?[null,fi(i[1])]:3===i.length?[i[0],fi(i[2])]:[["Multiply",...i.slice(0,-2)],fi(i[i.length-1])];const[e,n]=Yi(i[i.length-1]);if(e)return[["Multiply",...i.slice(0,-1),e],n]}}else if("Delimiter"===i){const[i,t]=Yi(n);if(t)return i?[["Delimiter",i,...ui(e).slice(1)],t]:[null,t]}else if("Add"===i){const i=ui(e);if(i&&i.length>0){const[e,n]=Yi(i[i.length-1]);if(n){if(e)return[["Add",...i.slice(0,-1),e],n];if(i.length>2)return[["Add",...i.slice(0,-1)],n];if(i.length>2)return[i[0],n]}}}else if("Negate"===i){const[e,i]=Yi(n);if(i)return[e?["Negate",e]:null,i]}else if("Divide"===i){const[i,t]=Yi(n);if(t)return[["Divide",null!=i?i:1,ci(e,2)],t]}else{const i=ui(e);if(1===(null==i?void 0:i.length)){const[n,t]=Yi(i[0]);if(t)return[[ai(e),n],t]}}return[e,null]}function Ji(e){return(i,n)=>{var t;if(!ci(n,1))return e;let r=ci(n,2);const s=ai(r);let o=null;"Tuple"!==s&&"Triple"!==s&&"Pair"!==s&&"Single"!==s?(o=fi(r),r=null):o=null!==(t=fi(ci(r,1)))&&void 0!==t?t:"x";let a=ci(n,1);if("Lambda"===ai(a)&&ci(a,1)&&(a=Ni(ci(a,1),{_:null!=o?o:"x",_1:null!=o?o:"x"})),!r)return Xe(o?[e,i.serialize(a),"\\mathrm{d}",o]:[e,i.serialize(a)]);let l=r?[i.serialize(ci(r,2))]:[];l.length>0&&(l=["_{",...l,"}"]);let u=[];return ci(r,3)&&(u=["^{",i.serialize(ci(r,3)),"}"]),Xe([e,...u,...l,i.serialize(a),...o&&"Nothing"!==fi(o)?["\\,\\mathrm{d}",i.serialize(o)]:[]])}}const Ki=[{name:"Integrate",trigger:["\\int"],parse:Wi("Integrate"),serialize:Ji("\\int")},{trigger:["\\iint"],parse:Wi("Integrate")},{name:"CircularIntegrate",trigger:["\\oint"],parse:Wi("CircularIntegrate"),serialize:Ji("\\oint")}],Xi=[["Alpha","\\alpha",945],["Beta","\\beta",946],["Gamma","\\gamma",947],["Delta","\\delta",948],["Epsilon","\\epsilon",949],["EpsilonSymbol","\\varepsilon",1013],["Zeta","\\zeta",950],["Eta","\\eta",951],["Theta","\\theta",952],["ThetaSymbol","\\vartheta",977],["Iota","\\iota",953],["Kappa","\\kappa",954],["KappaSymbol","\\varkappa",1008],["Lambda","\\lambda",955],["Mu","\\mu",956],["Nu","\\nu",957],["Xi","\\xi",958],["Omicron","\\omicron",959],["PiSymbol","\\varpi",982],["Rho","\\rho",961],["RhoSymbol","\\varrho",1009],["Sigma","\\sigma",963],["FinalSigma","\\varsigma",962],["Tau","\\tau",964],["Phi","\\phi",981],["PhiLetter","\\varphi",966],["Upsilon","\\upsilon",965],["Chi","\\chi",967],["Psi","\\psi",968],["Omega","\\omega",969],["CapitalAlpha","\\Alpha",913],["CapitalBeta","\\Beta",914],["CapitalGamma","\\Gamma",915],["CapitalDelta","\\Delta",916],["CapitalEpsilon","\\Epsilon",917],["CapitalZeta","\\Zeta",918],["CapitalEta","\\Eta",919],["CapitalTheta","\\Theta",920],["CapitaIota","\\Iota",921],["CapitalKappa","\\Kappa",922],["CapitalLambda","\\Lambda",923],["CapitalMu","\\Mu",924],["CapitalNu","\\Nu",925],["CapitalXi","\\Xi",926],["CapitalOmicron","\\Omicron",927],["CapitalPi","\\Pi",928],["CapitalRho","\\Rho",929],["CapitalSigma","\\Sigma",931],["CapitalTau","\\Tau",932],["CapitalPhi","\\Phi",934],["CapitalUpsilon","\\Upsilon",933],["CapitalChi","\\Chi",935],["CapitalPsi","\\Psi",936],["CapitalOmega","\\Omega",937],["Digamma","\\digamma",989],["Alef","\\aleph",8501],["Bet","\\beth",8502],["Gimel","\\gimel",8503],["Dalet","\\daleth",8504],["TurnedCapitalF","\\Finv",8498],["TurnedCapitalG","\\Game",8513],["Weierstrass","\\wp",8472],["Eth","\\eth",240],["InvertedOhm","\\mho",8487],["BlackClubSuit","\\clubsuit",9827],["WhiteHeartSuit","\\heartsuit",9825],["BlackSpadeSuit","\\spadesuit",9824],["WhiteDiamondSuit","\\diamondsuit",9826],["Sharp","\\sharp",9839],["Flat","\\flat",9837],["Natural","\\natural",9838]],en=[...Xi.map((([e,i,n])=>({name:e,trigger:[i],parse:e}))),...Xi.map((([e,i,n])=>({trigger:[String.fromCodePoint(n)],parse:e})))],nn={"(":"(",")":")","[":"\\lbrack","]":"\\rbrack","{":"\\lbrace","}":"\\rbrace","<":"\\langle",">":"\\rangle","|":"\\vert","||":"\\Vert","\\lceil":"\\lceil","\\lfloor":"\\lfloor","\\rceil":"\\rceil","\\rfloor":"\\rfloor"};function tn(e){return Array.isArray(e)?e.length:1}function rn(e,l){var u,c,h,m,d,f,g,p;if(!function(e,i){var n,a;const l=null!==(a=null!==(n=e.name)&&void 0!==n?n:e.trigger)&&void 0!==a?a:e.openDelimiter;if(void 0!==e.serialize&&!e.name)return i({severity:"warning",message:["invalid-dictionary-entry",l,"Unexpected serialize property without a name property"]}),!1;if(t(e)){if(e.trigger)return i({severity:"warning",message:["invalid-dictionary-entry",l,`Unexpected 'trigger' "${e.trigger}". 'matchfix' operators use a 'openDelimiter' and 'closeDelimiter' instead of a trigger. `]}),!1;if(!e.openDelimiter||!e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected `openDelimiter` and a `closeDelimiter` for matchfix operator"]}),!1;if(typeof e.openDelimiter!=typeof e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected `openDelimiter` and `closeDelimiter` to both be strings or array of LatexToken"]}),!1}if(r(e)||o(e)||s(e)){if(Array.isArray(e.trigger)&&("_"===e.trigger[0]||"^"===e.trigger[0])||"string"==typeof e.trigger&&(e.trigger.startsWith("^")||e.trigger.startsWith("_"))){if(void 0!==e.precedence||void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",l,'Unexpected "precedence" or "associativity" for superscript/subscript operator']}),!1}else if(void 0===e.precedence)return i({severity:"warning",message:["invalid-dictionary-entry",l,`Expected a "precedence" for ${e.kind} operator`]}),!1}else if(void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",l,'Unexpected "associativity" operator']}),!1;return t(e)||e.trigger||e.name?void 0!==e.parse||void 0!==e.name||(i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected a 'parse' or 'name'"]}),!1):(i({severity:"warning",message:["invalid-dictionary-entry",l,"Expected at least a 'trigger' or a 'name'"]}),!1)}(e,l))return[null,null];const v={name:e.name,kind:"kind"in e?e.kind:"symbol"};if("matchfix"===v.kind&&t(e)){if(v.openDelimiter=e.openDelimiter,v.closeDelimiter=e.closeDelimiter,"function"==typeof e.serialize)v.serialize=e.serialize;else{const e="string"==typeof v.openDelimiter?nn[v.openDelimiter]:ei(v.openDelimiter),i="string"==typeof v.closeDelimiter?nn[v.closeDelimiter]:ei(v.closeDelimiter);v.serialize=(n,t)=>Xe([e,n.serialize(ci(t,1)),i])}if("function"==typeof e.parse)v.parse=e.parse;else{const i=null!==(u=e.parse)&&void 0!==u?u:e.name;v.parse=(e,n)=>[i,n]}return[null,v]}if("environment"===v.kind&&a(e)){const i=e.trigger;return v.serialize=null!==(c=e.serialize)&&void 0!==c?c:(e,n)=>`\\begin{${i}}${e.serialize(ci(n,1))}\\end{${i}}`,v.parse=null!==(h=e.parse)&&void 0!==h?h:()=>null,[i,v]}const b="string"==typeof e.trigger?Ke(e.trigger,[]):e.trigger,y=b?ei(b):"";if("function"===v.kind&&n(e))return v.serialize=e.serialize,y&&!e.serialize&&(v.serialize=(e,i)=>`\\mathrm{${y}}${e.wrapArguments(i)}`),v.parse=e.parse,!v.parse&&e.name&&(v.parse=i=>{const n=i.matchArguments("enclosure");return null===n?e.name:[e.name,...n]}),[y,v];if(e.trigger,"symbol"===v.kind&&i(e)&&(v.precedence=null!==(m=e.precedence)&&void 0!==m?m:1e4),"infix"!==v.kind&&"prefix"!==v.kind&&"postfix"!==v.kind||!(r(e)||s(e)||o(e))||(!b||"^"!==b[0]&&"_"!==b[0]?v.precedence=null!==(d=e.precedence)&&void 0!==d?d:1e4:v.precedence=720),"infix"===v.kind&&r(e))if(v.associativity=null!==(f=e.associativity)&&void 0!==f?f:"non","function"==typeof e.parse)v.parse=e.parse;else if(!b||"^"!==b[0]&&"_"!==b[0]){const i=null!==(p=e.parse)&&void 0!==p?p:e.name,n=v.precedence,t=v.associativity;v.parse=(e,r,s)=>{if(n<r.minPrec)return null;const o=ki(e.matchExpression(Object.assign(Object.assign({},r),{minPrec:n})));return"string"==typeof i?xi(i,s,o,t):[i,s,o]}}else{const i=null!==(g=e.parse)&&void 0!==g?g:e.name;v.parse=(e,n,t)=>[i,ki(ci(t,1)),ki(ci(t,2))]}else if("function"==typeof e.parse)v.parse=e.parse;else if(void 0!==e.parse)v.parse=()=>e.parse;else if(void 0===e.parse&&void 0!==e.name)if("postfix"===v.kind)v.parse=(i,n)=>n?[e.name,n]:null;else if("prefix"===v.kind){const i=v.precedence,n=e.name;v.parse=(e,t)=>{if(i<t.minPrec)return null;const r=e.matchExpression(Object.assign(Object.assign({},t),{minPrec:i}));return null===r?null:[n,r]}}return"function"==typeof e.serialize||"string"==typeof e.serialize?v.serialize=e.serialize:b&&("postfix"===v.kind?v.serialize="#1"+y:"prefix"===v.kind?v.serialize=y+"#1":"infix"===v.kind?v.serialize="#1"+y+"#2":"symbol"===v.kind?v.serialize=y:v.serialize=""),[null!=b?b:null,v]}const sn={algebra:[{name:"To",trigger:["\\to"],kind:"infix",precedence:270}],arithmetic:Fi,calculus:Ki,core:zi,logic:[{name:"True",trigger:["\\mathrm","<{>","T","r","u","e","<}>"],serialize:"\\mathrm{True}"},{name:"False",trigger:["\\mathrm","<{>","F","a","l","s","e","<}>"],serialize:"\\mathrm{False}"},{name:"Maybe",trigger:["\\mathrm","<{>","M","a","y","b","e","<}>"],serialize:"\\mathrm{Maybe}"}],relop:[{trigger:["!","<"],kind:"infix",associativity:"right",precedence:246,parse:"NotLess"},{name:"NotLess",trigger:["\\nless"],kind:"infix",associativity:"right",precedence:246},{trigger:["<"],kind:"infix",associativity:"right",precedence:245,parse:"Less"},{name:"Less",trigger:["\\lt"],kind:"infix",associativity:"right",precedence:245},{trigger:["<","="],kind:"infix",associativity:"right",precedence:241,parse:"LessEqual"},{name:"LessEqual",trigger:["\\le"],kind:"infix",associativity:"right",precedence:241},{trigger:["\\leq"],kind:"infix",associativity:"right",precedence:241,parse:"Equal"},{trigger:["\\leqslant"],kind:"infix",associativity:"right",precedence:265,parse:"LessEqual"},{name:"LessNotEqual",trigger:["\\lneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotLessNotEqual",trigger:["\\nleqq"],kind:"infix",associativity:"right",precedence:260},{name:"LessOverEqual",trigger:["\\leqq"],kind:"infix",associativity:"right",precedence:265},{name:"GreaterOverEqual",trigger:["\\geqq"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"Equal",trigger:["="],kind:"infix",associativity:"right",precedence:260},{trigger:["*","="],kind:"infix",associativity:"right",precedence:260,parse:"StarEqual"},{name:"StarEqual",trigger:["\\star","="],kind:"infix",associativity:"right",precedence:260},{name:"PlusEqual",trigger:["+","="],kind:"infix",associativity:"right",precedence:260},{name:"MinusEqual",trigger:["-","="],kind:"infix",associativity:"right",precedence:260},{name:"SlashEqual",trigger:["/","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqual",trigger:["=","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqualEqual",trigger:["=","=","="],kind:"infix",associativity:"right",precedence:265},{name:"TildeFullEqual",trigger:["\\cong"],kind:"infix",associativity:"right",precedence:260},{name:"NotTildeFullEqual",trigger:["\\ncong"],kind:"infix",associativity:"right",precedence:260},{trigger:[":","="],kind:"infix",associativity:"right",precedence:260,parse:"Assign"},{name:"Assign",trigger:["\\coloneq"],kind:"infix",associativity:"right",precedence:260},{name:"Approx",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"NotApprox",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"ApproxEqual",trigger:["\\approxeq"],kind:"infix",associativity:"right",precedence:260},{name:"NotApproxEqual",trigger:["!","\\approxeq"],kind:"infix",associativity:"right",precedence:250},{name:"NotEqual",trigger:["\\ne"],kind:"infix",associativity:"right",precedence:255},{name:"Unequal",trigger:["!","="],kind:"infix",associativity:"right",precedence:260},{name:"GreaterEqual",trigger:["\\ge"],kind:"infix",associativity:"right",precedence:242},{trigger:["\\geq"],kind:"infix",associativity:"right",precedence:242,parse:"GreaterEqual"},{trigger:[">","="],kind:"infix",associativity:"right",precedence:243,parse:"GreaterEqual"},{trigger:["\\geqslant"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"GreaterNotEqual",trigger:["\\gneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotGreaterNotEqual",trigger:["\\ngeqq"],kind:"infix",associativity:"right",precedence:260},{trigger:[">"],kind:"infix",associativity:"right",precedence:245,parse:"Greater"},{name:"Greater",trigger:["\\gt"],kind:"infix",associativity:"right",precedence:245},{name:"NotGreater",trigger:["\\ngtr"],kind:"infix",associativity:"right",precedence:244},{trigger:["!",">"],kind:"infix",associativity:"right",precedence:244,parse:"NotGreater"},{name:"RingEqual",trigger:["\\circeq"],kind:"infix",associativity:"right",precedence:260},{name:"TriangleEqual",trigger:["\\triangleq"],kind:"infix",associativity:"right",precedence:260},{name:"DotEqual",trigger:["\\doteq"],kind:"infix",associativity:"right",precedence:265},{name:"DotEqualDot",trigger:["\\doteqdot"],kind:"infix",associativity:"right",precedence:265},{name:"FallingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"RisingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"QuestionEqual",trigger:["\\questeq"],kind:"infix",associativity:"right",precedence:260},{name:"Equivalent",trigger:["\\equiv"],kind:"infix",associativity:"right",precedence:260},{trigger:["\\iff"],kind:"infix",parse:"Equivalent",associativity:"right",precedence:260},{name:"MuchLess",trigger:["\\ll"],kind:"infix",associativity:"right",precedence:260},{name:"MuchGreater",trigger:["\\gg"],kind:"infix",associativity:"right",precedence:260},{name:"Precedes",trigger:["\\prec"],kind:"infix",associativity:"right",precedence:260},{name:"Succeeds",trigger:["\\succ"],kind:"infix",associativity:"right",precedence:260},{name:"PrecedesEqual",trigger:["\\preccurlyeq"],kind:"infix",associativity:"right",precedence:260},{name:"SucceedsEqual",trigger:["\\curlyeqprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotPrecedes",trigger:["\\nprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotSucceeds",trigger:["\\nsucc"],kind:"infix",associativity:"right",precedence:260},{name:"Between",trigger:["\\between"],kind:"infix",associativity:"right",precedence:265}],other:Gi,physics:[{name:"mu-0",trigger:"\\mu_0"}],sets:Ui,symbols:en,trigonometry:Bi},on={"(":["\\lparen","("],")":["\\rparen",")"],"[":["\\lbrack"],"]":["\\rbrack"],"<":["<","\\langle"],">":[">","\\rangle"],"{":["\\{","\\lbrace"],"}":["\\}","\\rbrace"],":":[":","\\colon"],"|":["|","\\|","\\lvert","\\rvert"],"||":["||","\\Vert","\\lVert","\\rVert"],"\\lfloor":["\\lfloor"],"\\rfloor":["\\rfloor"],"\\lceil":["\\lceil"],"\\rceil":["\\rceil"],"\\ulcorner":["\\ulcorner"],"\\urcorner":["\\urcorner"],"\\llcorner":["\\llcorner"],"\\lrcorner":["\\lrcorner"],"\\lgroup":["\\lgroup"],"\\rgroup":["\\rgroup"],"\\lmoustache":["\\lmoustache"],"\\rmoustache":["\\rmoustache"]},an={":":[":","\\colon"],"|":["|","\\|","\\mid","\\mvert"]},ln={"\\left":"\\right","\\bigl":"\\bigr","\\Bigl":"\\Bigr","\\biggl":"\\biggr","\\Biggl":"\\Biggr","\\big":"\\big","\\Big":"\\Big","\\bigg":"\\bigg","\\Bigg":"\\Bigg"},un=["\\middle","\\bigm","\\Bigm","\\biggm","\\Biggm","\\big","\\Big","\\bigg","\\Bigg"],cn={"(":")","[":"]","\\{":"\\}","\\lbrace":"\\rbrace","\\lparen":"\\rparen","\\langle":"\\rangle","\\lfloor":"\\rfloor","\\lceil":"\\rceil","\\vert":"\\vert","\\lvert":"\\rvert","\\Vert":"\\Vert","\\lVert":"\\rVert","\\lbrack":"\\rbrack","\\ulcorner":"\\urcorner","\\llcorner":"\\lrcorner","\\lgroup":"\\rgroup","\\lmoustache":"\\rmoustache"},hn={precision:6,positiveInfinity:"\\infty",negativeInfinity:"-\\infty",notANumber:"\\operatorname{NaN}",decimalMarker:".",groupSeparator:"\\,",exponentProduct:"\\cdot",beginExponentMarker:"10^{",endExponentMarker:"}",notation:"auto",truncationMarker:"\\ldots",beginRepeatingDigits:"\\overline{",endRepeatingDigits:"}",imaginaryUnit:"\\imaginaryI",avoidExponentsInRange:[-7,20]},mn={applyInvisibleOperator:"auto",skipSpace:!0,parseArgumentsOfUnknownLatexCommands:!0,parseNumbers:!0,parseUnknownIdentifier:(e,i)=>{var n;return void 0!==(null===(n=i.computeEngine)||void 0===n?void 0:n.lookupFunction(e))?"function":/^[a-zA-Z]/.test(e)?"symbol":"unknown"},preserveLatex:!1};class dn{constructor(e,i,n,t){this.index=0,this._boundaries=[],this._lastPeek="",this._peekCounter=0,this._tokens=e,this.options=Object.assign(Object.assign(Object.assign({},hn),mn),i),this._dictionary=n,this.computeEngine=t,this._positiveInfinityTokens=Ke(this.options.positiveInfinity,[]),this._negativeInfinityTokens=Ke(this.options.negativeInfinity,[]),this._notANumberTokens=Ke(this.options.notANumber,[]),this._decimalMarkerTokens=Ke(this.options.decimalMarker,[]),this._groupSeparatorTokens=Ke(this.options.groupSeparator,[]),this._exponentProductTokens=Ke(this.options.exponentProduct,[]),this._beginExponentMarkerTokens=Ke(this.options.beginExponentMarker,[]),this._endExponentMarkerTokens=Ke(this.options.endExponentMarker,[]),this._truncationMarkerTokens=Ke(this.options.truncationMarker,[]),this._beginRepeatingDigitsTokens=Ke(this.options.beginRepeatingDigits,[]),this._endRepeatingDigitsTokens=Ke(this.options.endRepeatingDigits,[]),this._imaginaryNumberTokens=Ke(this.options.imaginaryUnit,[])}updateOptions(e){for(const[i,n]of Object.entries(e)){if(!(i in this.options))throw Error(`Unexpected option "${i}"`);this.options[i]=n,"string"==typeof n&&("positiveInfinity"===i&&(this._positiveInfinityTokens=Ke(n,[])),"negativeInfinity"===i&&(this._negativeInfinityTokens=Ke(n,[])),"notANumber"===i&&(this._notANumberTokens=Ke(n,[])),"decimalMarker"===i&&(this._decimalMarkerTokens=Ke(n,[])),"groupSeparator"===i&&(this._groupSeparatorTokens=Ke(n,[])),"exponentProduct"===i&&(this._exponentProductTokens=Ke(n,[])),"beginExponentMarker"===i&&(this._beginExponentMarkerTokens=Ke(n,[])),"endExponentMarker"===i&&(this._endExponentMarkerTokens=Ke(n,[])),"truncationMarker"===i&&(this._truncationMarkerTokens=Ke(n,[])),"beginRepeatingDigits"===i&&(this._beginRepeatingDigitsTokens=Ke(n,[])),"endRepeatingDigits"===i&&(this._endRepeatingDigitsTokens=Ke(n,[])),"imaginaryNumber"===i&&(this._imaginaryNumberTokens=Ke(n,[])))}}get atEnd(){return this.index>=this._tokens.length}get peek(){const e=this._tokens[this.index];if(e===this._lastPeek?this._peekCounter+=1:this._peekCounter=0,this._peekCounter>=1024)throw Error(`Infinite loop detected while parsing "${this.latex(0)}" at ${this._lastPeek} (index ${this.index})`);return this._lastPeek=e,e}next(){return this._tokens[this.index++]}atTerminator(e){return!!this.atBoundary||!(!(null==e?void 0:e.condition)||!e.condition(this))}get atBoundary(){if(this.atEnd)return!0;const e=this.index;for(const i of this._boundaries)if(this.matchAll(i.tokens))return this.index=e,!0;return!1}addBoundary(e){this._boundaries.push({index:this.index,tokens:e})}removeBoundary(){this._boundaries.pop()}matchBoundary(){const e=this._boundaries[this._boundaries.length-1],i=e&&this.matchAll(e.tokens);return i&&this._boundaries.pop(),i}boundaryError(e){const i=this._boundaries[this._boundaries.length-1];return this._boundaries.pop(),this.error(e,i.index)}latex(e,i){return ei(this._tokens.slice(e,i))}latexAhead(e){return this.latex(this.index,this.index+e)}latexBefore(){return this.latex(0,this.index)}latexAfter(){return this.latex(this.index)}lookAhead(){let e=Math.min(this._dictionary.lookahead,this._tokens.length-this.index);if(e<0)return[];const i=Array(e+1);for(;e>0;)i[e]=this.latexAhead(e--);return i}peekDefinitions(e){let i;if("function"===e){const e=this.index;if(this.match("\\operatorname")||this.match("\\mathrm")||this.match("\\mathit")){const i=this.matchStringArgument(),n=this.index-e;return this.index=e,null!==i&&this._dictionary.function.has(i)?this._dictionary.function.get(i).map((e=>[e,n])):null}return null}i="operator"===e?this.lookAhead().map(((e,i)=>{var n,t,r,s,o;return null!==(s=null!==(t=null===(n=this._dictionary.infix[i])||void 0===n?void 0:n.get(e))&&void 0!==t?t:null===(r=this._dictionary.postfix[i])||void 0===r?void 0:r.get(e))&&void 0!==s?s:null===(o=this._dictionary.prefix[i])||void 0===o?void 0:o.get(e)})):this.lookAhead().map(((i,n)=>{var t;return null===(t=this._dictionary[e][n])||void 0===t?void 0:t.get(i)}));const n=[];for(let e=i.length;e>0;e--)if(void 0!==i[e])for(const t of i[e])n.push([t,e]);return 0===n.length?null:n}skipSpaceTokens(){for(;this.match("<space>"););}skipSpace(){if(!this.options.skipSpace)return!1;if(!this.atEnd&&"<{>"===this.peek){const e=this.index;for(this.next();this.match("<space>"););if("<}>"===this.next())return this.skipSpace(),!0;this.index=e}let e=!1;for(;this.match("<space>");)e=!0;return e&&this.skipSpace(),e}skipVisualSpace(){this.options.skipSpace&&(this.skipSpace(),["\\!","\\,","\\:","\\;","\\enskip","\\enspace","\\space","\\quad","\\qquad"].includes(this.peek)&&(this.next(),this.skipVisualSpace()),this.skipSpace())}matchChar(){var e;const i=this.index;let n=0;for(;this.match("^");)n+=1;if(n>=2){let e="",i=0;for(;i!=n;){const n=this.matchAny(["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]);if(!n)break;e+=n,i+=1}if(e.length===n)return String.fromCodePoint(Number.parseInt(e,16))}else{if(this.match("\\char")){let i=Math.floor(null!==(e=this.matchLatexNumber())&&void 0!==e?e:NaN);return(!Number.isFinite(i)||i<0||i>1114111)&&(i=10067),String.fromCodePoint(i)}if(this.match("\\unicode"))if(this.skipSpaceTokens(),"<{>"===this.peek){this.next();const e=this.matchLatexNumber();if(this.match("<}>")&&null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}else{const e=this.matchLatexNumber();if(null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}}return this.index=i,this.next()}matchColor(e=!1){let i="";for(;!this.atEnd&&"}"!==this.peek;)i+=this.next();return i}matchLatexDimension(){return null}match(e){return this._tokens[this.index]===e&&(this.index++,!0)}matchAll(e){if("string"==typeof e&&(e=[e]),0===e.length)return!1;let i=!0,n=0;do{i=this._tokens[this.index+n]===e[n++]}while(i&&n<e.length);return i&&(this.index+=n),i}matchAny(e){return e.includes(this._tokens[this.index])?this._tokens[this.index++]:""}matchSequence(e){const i=[];for(;e.includes(this._tokens[this.index]);)i.push(this._tokens[this.index++]);return i}matchOptionalSign(){let e=!!this.matchAny(["-","\u2212"]);for(;this.matchAny(["+","\ufe62"])||this.skipSpace();)this.matchAny(["-","\u2212"])&&(e=!e);return e?"-":"+"}matchDecimalDigits(e){var i;null!=e||(e={}),null!==(i=e.withGrouping)&&void 0!==i||(e.withGrouping=!1);const n=[];let t=!1;for(;!t;){for(;/^[0-9]$/.test(this.peek);)n.push(this.next()),this.skipVisualSpace();if(t=!0,e.withGrouping&&this.options.groupSeparator){const e=this.index;this.skipVisualSpace(),this.matchAll(this._groupSeparatorTokens)&&(this.skipVisualSpace(),/^[0-9]$/.test(this.peek)?t=!1:this.index=e)}}return n.join("")}matchSignedInteger(e){var i;null!=e||(e={}),null!==(i=e.withGrouping)&&void 0!==i||(e.withGrouping=!1);const n=this.index,t=this.matchOptionalSign(),r=this.matchDecimalDigits(e);return r?"-"===t?"-"+r:r:(this.index=n,"")}matchExponent(){const e=this.index;if(this.matchAny(["e","E"])){const e=this.matchSignedInteger({withGrouping:!1});if(e)return"e"+e}if(this.index=e,this.match("\\times")&&(this.skipSpaceTokens(),this.match("1")&&this.match("0")&&this.match("^"))){if(/^[0-9]$/.test(this.peek))return"e"+this.next();if(this.match("<{>")){this.skipSpaceTokens();const e=this.matchSignedInteger();if(this.skipSpaceTokens(),this.match("<}>")&&e)return"e"+e}}if(this.index=e,this.skipSpaceTokens(),this.match("\\%"))return"e-2";if(this.index=e,this.matchAll(this._exponentProductTokens)&&(this.skipSpaceTokens(),this.matchAll(this._beginExponentMarkerTokens))){this.skipSpaceTokens();const e=this.matchSignedInteger();if(this.skipSpaceTokens(),this.matchAll(this._endExponentMarkerTokens)&&e)return"e"+e}return this.index=e,""}matchRepeatingDecimal(){const e=this.index;let i="";return this.match("(")?(i=this.matchDecimalDigits(),i&&this.match(")")?"("+i+")":(this.index=e,"")):(this.index=e,this.matchAll(["\\left","("])?(i=this.matchDecimalDigits(),i&&this.matchAll(["\\right",")"])?"("+i+")":(this.index=e,"")):(this.index=e,this.matchAll(["\\overline","<{>"])?(i=this.matchDecimalDigits(),i&&this.match("<}>")?"("+i+")":(this.index=e,"")):(this.index=e,this.matchAll(this._beginRepeatingDigitsTokens)?(i=this.matchDecimalDigits(),i&&this.matchAll(this._endRepeatingDigitsTokens)?"("+i+")":(this.index=e,"")):(this.index=e,""))))}matchNumber(){if(!this.options.parseNumbers)return"";const e=this.index;this.skipVisualSpace(),this.match("+");let i="",n=!1;if(this.match(".")||this.matchAll(this._decimalMarkerTokens)){const i=this.peek;if("\\overline"!==i&&i!==this._beginRepeatingDigitsTokens[0]&&!/[0-9\(]/.test(i))return this.index=e,"";n=!0}else if(i=this.matchDecimalDigits({withGrouping:!0}),!i)return this.index=e,"";let t=!0;if(n||!this.match(".")&&!this.matchAll(this._decimalMarkerTokens)?n?i="0."+this.matchDecimalDigits({withGrouping:!0}):t=!1:i+="."+this.matchDecimalDigits({withGrouping:!0}),t){const e=this.matchRepeatingDecimal();e?i+=e:this.match("\\ldots")||this.matchAll(this._truncationMarkerTokens)}return this.skipVisualSpace(),i+this.matchExponent()}matchLatexNumber(e=!0){var i,n;let t=!1,r=this.peek;for(;"<space>"===r||"+"===r||"-"===r;)"-"===r&&(t=!t),this.next(),r=this.peek;let s=10,o=["0","1","2","3","4","5","6","7","8","9"];if(this.match("'"))s=8,o=["0","1","2","3","4","5","6","7"],e=!0;else if(this.match('"')||this.match("x"))s=16,o=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],e=!0;else if(this.match("`"))return r=this.next(),r?r.startsWith("\\")&&2===r.length?(t?-1:1)*(null!==(i=r.codePointAt(1))&&void 0!==i?i:0):(t?-1:1)*(null!==(n=r.codePointAt(0))&&void 0!==n?n:0):null;let a="";for(;o.includes(this.peek);)a+=this.next();if(!e&&this.match("."))for(a+=".";o.includes(this.peek);)a+=this.next();const l=e?Number.parseInt(a,s):Number.parseFloat(a);return Number.isNaN(l)?null:t?-l:l}matchPrefixOperator(e){e||(e={minPrec:0}),e.minPrec||(e=Object.assign(Object.assign({},e),{minPrec:0}));const i=this.peekDefinitions("prefix");if(null===i)return null;const n=this.index;for(const[t,r]of i){this.index=n+r;const i=t.parse(this,e);if(i)return i}return this.index=n,null}matchInfixOperator(e,i){i||(i={minPrec:0}),i.minPrec||(i=Object.assign(Object.assign({},i),{minPrec:0}));const n=this.peekDefinitions("infix");if(null===n)return null;const t=this.index;for(const[r,s]of n)if(r.precedence>=i.minPrec){this.index=t+s;const n=r.parse(this,i,e);if(n)return n}return this.index=t,null}matchArguments(e){var i,n,t,r;if(!e)return null;const s=this.index,o=this.matchEnclosure();if("enclosure"===e&&"Delimiter"===ai(o))return"Sequence"===ci(o,1)?null!==(i=ui(ci(o,1)))&&void 0!==i?i:[]:[null!==(n=ci(o,1))&&void 0!==n?n:["Sequence"]];if("implicit"===e){if("Delimiter"===ai(o))return"Sequence"===ai(ci(o,1))?null!==(t=Si(o))&&void 0!==t?t:[]:[null!==(r=ci(o,1))&&void 0!==r?r:["Sequence"]];if(null!==o)return[o];const e=this.matchExpression({minPrec:390});return null!==e?[e]:null}return this.index=s,null}matchFunctionSuffix(){return null}matchOpenDelimiter(e,i){var n;const t=this.index,r=ln[this.peek];r&&this.next();const s=null!==(n=on[e])&&void 0!==n?n:[e],o=r?[r]:[];return s.includes("||")&&this.matchAll(["|","|"])?(o.push("|"),o.push("|"),o):s.includes(this.peek)?(cn[e]===i?o.push(cn[this.peek]):o.push(i),this.next(),o):(this.index=t,null)}matchMiddleDelimiter(e){var i;const n=null!==(i=an[e])&&void 0!==i?i:[e];if(un.includes(this.peek)){const e=this.index;return this.next(),n.includes(this.peek)?(this.next(),!0):(this.index=e,!1)}return!!n.include(this.peek)&&(this.next(),!0)}matchEnclosureOpen(){const e=this._dictionary.matchfix;if(0===e.length)return null;const i=this.index;for(const n of e){if(this.index=i,Array.isArray(n.openDelimiter)){if(this.matchAll(n.openDelimiter))return ei(n.closeDelimiter);continue}const e=this.matchOpenDelimiter(n.openDelimiter,n.closeDelimiter);if(null!==e)return ei(e)}return this.index=i,null}matchEnclosureClose(){const e=this._dictionary.matchfix;if(0===e.length)return null;const i=this.index;for(const n of e){if(this.index=i,Array.isArray(n.closeDelimiter)){if(this.matchAll(n.closeDelimiter))return ei(n.openDelimiter);continue}this.index=i;let e=this.peek;const t=Object.keys(ln).find((i=>ln[i]===e));t&&this.next();let r=[];e=this.peek;const s=Object.keys(cn).find((i=>cn[i]===e));if(s&&(r=[s]),t&&(r=[t,...r]),r.length>0)return this.next(),ei(r)}return this.index=i,null}matchEnclosure(){const e=this._dictionary.matchfix;if(0===e.length)return null;const i=this.index;for(const n of e){if(this.index=i,Array.isArray(n.openDelimiter)){if(!this.matchAll(n.openDelimiter))continue;this.addBoundary(n.closeDelimiter);const e=this.matchExpression();if(this.skipSpace(),!this.matchBoundary()){this.removeBoundary();continue}const i=n.parse(this,null!=e?e:["Sequence"]);if(null===i)continue;return i}const e=this.matchOpenDelimiter(n.openDelimiter,n.closeDelimiter);if(null===e)continue;if(this.matchAll(e)){const e=n.parse(this,["Sequence"]);if(null===e)continue;return e}this.addBoundary(e);const t=this.index;let r=this.matchExpression();if(this.skipSpace(),!this.matchBoundary()&&(this.removeBoundary(),this.index=t,r=this.matchExpression(),!this.matchAll(e))){if(!this.atEnd)continue;return this.index=i,null}const s=n.parse(this,null!=r?r:["Sequence"]);if(null!==s)return s}return this.index=i,null}matchIdentifier(){if(this.match("\\operatorname")||this.match("\\mathit")||this.match("\\mathrm")){const e=this.index,i=this.matchStringArgument();return null===i?this.error("expected-string-argument",e):null!==i&&ri(i)?i:this.error("invalid-symbol-name",e)}return/^[a-zA-Z]$/.test(this.peek)?this.next():null}matchFunction(){var e,i;const n=this.index,t=this.peekDefinitions("function");if(t)for(const[e,i]of t){if(this.index=n+i,"function"!=typeof e.parse){const i=this.matchArguments("enclosure");return i?[e.name,...i]:e.name}{const i=e.parse(this);if(i)return i}}this.index=n;const r=this.matchIdentifier();if(null===r)return this.index=n,null;if("string"!=typeof r)return r;if("function"===(null===(i=(e=this.options).parseUnknownIdentifier)||void 0===i?void 0:i.call(e,r,this))){const e=this.matchArguments("enclosure");return e?[r,...e]:r}return this.index=n,null}matchSymbol(){var e,i;const n=this.index,t=this.peekDefinitions("symbol");if(t)for(const[e,i]of t){if(this.index=n+i,"function"!=typeof e.parse)return e.name;{const i=e.parse(this);if(i)return i}}this.index=n;const r=this.matchIdentifier();return null===r?(this.index=n,null):"string"!=typeof r||r&&"symbol"===(null===(i=(e=this.options).parseUnknownIdentifier)||void 0===i?void 0:i.call(e,r,this))?r:(this.index=n,null)}matchOptionalLatexArgument(){const e=this.index;if(this.skipSpaceTokens(),this.match("[")){this.addBoundary(["]"]);const e=this.matchExpression();return this.skipSpace(),this.matchBoundary()?e:this.boundaryError("expected-closing-delimiter")}return this.index=e,null}matchRequiredLatexArgument(e){e||(e=[...'!"#$%&(),/;:?@[]`|~'.split(""),"\\left","\\bigl"]);const i=this.index;if(this.skipSpaceTokens(),this.match("<{>")){this.addBoundary(["<}>"]);const e=this.matchExpression();return this.skipSpace(),this.matchBoundary()?null!=e?e:["Sequence"]:this.boundaryError("expected-closing-delimiter")}return e.includes(this.peek)?(this.index=i,null):/^[0-9]$/.test(this.peek)?parseInt(this.next()):/^[^\\#]$/.test(this.peek)?this.next():this.matchSymbol()||(this.index=i,null)}matchSupsub(e){var i,n,t;if(null===e)return null;const r=this.index;this.skipSpace();const s=[],o=[];let a=r;for(;"_"===this.peek||"^"===this.peek;){if(this.match("_"))if(a=this.index,this.match("_")||this.match("^"))o.push(this.error("syntax-error",a));else{const e=null!==(i=this.matchRequiredLatexArgument())&&void 0!==i?i:this.matchStringArgument();if(null===e)return this.error("missing",r);o.push(e)}else if(this.match("^"))if(a=this.index,this.match("_")||this.match("^"))s.push(this.error("syntax-error",a));else{const e=this.matchRequiredLatexArgument();if(null===e)return this.error("missing",r);s.push(e)}a=this.index,this.skipSpace()}if(0===s.length&&0===o.length)return this.index=r,e;let l=e;if(o.length>0){const e=null===(n=this._dictionary.infix[1])||void 0===n?void 0:n.get("_");if(e){const i=["Subscript",l,1===o.length?o[0]:["List",...o]];for(const n of e)if(l="function"==typeof n.parse?n.parse(this,{minPrec:0},i):i,l)break}}if(s.length>0){const e=null===(t=this._dictionary.infix[1])||void 0===t?void 0:t.get("^");if(e){const i=["Superscript",l,1===s.length?s[0]:["List",...s]];for(const n of e)if(l="function"==typeof n.parse?n.parse(this,{minPrec:0},i):i,l)break}}return null===l&&(this.index=r),l}matchPostfix(e){if(null===e)return null;const i=this.peekDefinitions("postfix");if(null===i)return null;const n=this.index;for(const[t,r]of i){this.index=n+r;const i=t.parse(this,e);if(null!==i)return i}return this.index=n,null}matchString(){let e="";for(;!this.atBoundary;){const i=this.peek;if("<$>"===i||"<$$>"===i)return"";"<space>"===i?(this.next(),e+=" "):(i[0],e+=this.next())}return e}matchStringArgument(){const e=this.index;if(this.skipSpaceTokens(),this.match("<{>")){for(this.addBoundary(["<}>"]);this.match("<space>"););const e=this.matchString();if(this.matchBoundary())return e.trimEnd();this.removeBoundary()}return this.index=e,null}matchTabular(){var e;const i=[];let n=[],t=null;for(;!this.atBoundary;)if(this.skipSpace(),this.match("&"))n.push(null!=t?t:"Nothing"),t=null;else if(this.match("\\\\")||this.match("\\cr"))this.skipSpace(),this.matchOptionalLatexArgument(),null!==t&&n.push(t),i.push(n),n=[],t=null;else{const i=[];let n=this.peek;for(;"&"!==n&&"\\\\"!==n&&"\\cr"!==n&&!this.atBoundary;)t=this.matchExpression({condition:e=>{const i=e.peek;return"&"===i||"\\\\"===i||"\\cr"===i}}),t?i.push(t):(i.push(["Error",["'unexpected-token'",n]]),this.next()),this.skipSpace(),n=this.peek;t=i.length>1?["Sequence",...i]:null!==(e=i[0])&&void 0!==e?e:"Nothing"}return null!==t&&n.push(t),n.length>0&&i.push(n),i}matchEnvironment(){const e=this.index;if(!this.match("\\begin"))return null;const i=this.matchStringArgument();if(null===i)return this.error("expected-environment-name",e);this.addBoundary(["\\end","<{>",...i.split(""),"<}>"]);const n=this._dictionary.environment.get(i);if(!n)return this.matchTabular(),this.skipSpace(),this.matchBoundary()?this.error(["unknown-environment",{str:i}],e):this.boundaryError("unbalanced-environment");const t=n.parse(this,[],[]);return this.skipSpace(),this.matchBoundary()?null!==t?this.decorate(t,e):(this.index=e,null):this.boundaryError("unbalanced-environment")}applyInvisibleOperator(e,i){var n;if(null===i||"Error"===ai(i)||"Nothing"===fi(i)||wi(i)||this.atTerminator(e)||null===this.options.applyInvisibleOperator)return null;if(null!==this.peekDefinitions("operator"))return null;const t=this.index,r=this.matchExpression(Object.assign(Object.assign({},e),{minPrec:390}));if(null===r||"Nothing"===fi(r)||wi(r))return this.index=t,null;if("Error"===ai(r))return xi("Sequence",i,r);if("function"==typeof this.options.applyInvisibleOperator)return this.options.applyInvisibleOperator(this,i,r);const s=fi(i);if(s&&"function"===this.options.parseUnknownIdentifier(s,this)){const e=Si(r);return e?[i,...e]:s}const o=bi(i);if(null!==o&&Number.isInteger(o)){const e=ai(r);if("Divide"===e||"Rational"===e){const[e,n]=[bi(ci(r,1)),bi(ci(r,2))];if(null!==e&&null!==n&&e>0&&e<=1e3&&n>1&&n<=1e3&&Number.isInteger(e)&&Number.isInteger(n))return["Add",i,r]}}if("Delimiter"===ai(r)){if("Sequence"===ai(ci(r,1)))return[null!=s?s:i,...null!==(n=ui(ci(r,1)))&&void 0!==n?n:[]];if(!ci(r,1)||"Nothing"===fi(ci(r,1)))return xi("Sequence",i,this.error("expected-expression",t))}return"Sequence"===ai(r)||"Sequence"===ai(i)||null!==si(i)||null!==si(r)||null!==pi(i)||null!==pi(r)?xi("Sequence",i,r):xi("Multiply",i,r)}matchUnexpectedLatexCommand(){var e,i;const n=this.index;let t=this.peekDefinitions("operator");if(t){if(t=this.peekDefinitions("postfix"),t){const[e,i]=t[0];if(this.index+=i,"function"==typeof e.parse){const i=e.parse(this,this.error("missing",n));if(i)return i}return e.name?[e.name,this.error("missing",n)]:this.error("unexpected-operator",n)}if(t=this.peekDefinitions("prefix"),t){const[i,r]=t[0];if(this.index+=r,"function"==typeof i.parse){const e=i.parse(this,{minPrec:0});if(e)return e}return i.name?[i.name,null!==(e=this.matchExpression())&&void 0!==e?e:this.error("missing",n)]:this.error("unexpected-operator",n)}if(t=this.peekDefinitions("infix"),t){const[e,r]=t[0];if(this.index+=r,"function"==typeof e.parse){const i=e.parse(this,{minPrec:0},this.error("missing",n));if(i)return i}return e.name?[e.name,this.error("missing",n),null!==(i=this.matchExpression())&&void 0!==i?i:this.error("missing",n)]:this.error("unexpected-operator",n)}}const r=this.peek;if(!r||"\\"!==r[0])return null;if(this.next(),this.skipSpaceTokens(),"\\end"===r){const e=this.matchStringArgument();return null===e?this.error("expected-environment-name",n):this.error(["unbalanced-environment",{str:e}],n)}for(;this.match("[");){let e=0;for(;!this.atEnd&&0===e&&"]"!==this.peek;)"["===this.peek&&(e+=1),"]"===this.peek&&(e-=1),this.next();this.match("]")}const s=this.index;this.index=n;const o=this.matchEnclosureOpen();if(o)return this.error(["expected-close-delimiter",o],s);const a=this.matchEnclosureClose();if(a)return this.error(["expected-open-delimiter",a],n);for(this.index=s;this.match("<{>");){let e=0;for(;!this.atEnd&&0===e&&"<}>"!==this.peek;)"<{>"===this.peek&&(e+=1),"<}>"===this.peek&&(e-=1),this.next();this.match("<}>")}return this.error(["unexpected-command",{str:r}],n)}matchPrimary(){var e;if(this.atBoundary)return null;let i=null;const n=this.index;if(this.match("<}>"))return this.error("unexpected-closing-delimiter",n);if(this.match("<{>")){if(this.addBoundary(["<}>"]),i=this.matchExpression(),null===i)return this.boundaryError("expected-expression");if(!this.matchBoundary())return this.decorate(["Sequence",i,this.boundaryError("expected-closing-delimiter")],n)}if(null===i){const e=this.matchNumber();e&&(i={num:e})}if(null===i&&(i=this.matchEnclosure()),null===i&&(i=this.matchEnvironment()),null===i&&this.matchAll(this._positiveInfinityTokens)&&(i={num:"+Infinity"}),null===i&&this.matchAll(this._negativeInfinityTokens)&&(i={num:"-Infinity"}),null===i&&this.matchAll(this._notANumberTokens)&&(i={num:"NaN"}),null===i&&(i=null!==(e=this.matchFunction())&&void 0!==e?e:this.matchSymbol()),null!==i){i=this.decorate(i,n);let e=null,t=this.index;do{if(e=this.matchPostfix(i),i=null!=e?e:i,this.index===t&&null!==e)break;t=this.index}while(null!==e)}return null===i&&(i=this.matchUnexpectedLatexCommand()),null!==i&&(i=this.matchSupsub(i)),this.decorate(i,n)}matchExpression(e){const i=this.index;if(this.skipSpace(),this.atBoundary)return this.index=i,null;e||(e={minPrec:0}),void 0===e.minPrec&&(e.minPrec=0);let n=this.matchPrefixOperator(Object.assign(Object.assign({},e),{minPrec:0}));if(null===n&&(n=this.matchPrimary(),"Sequence"===ai(n)&&0===di(n)&&(n=null)),n){let i=!1;for(;!i&&!this.atTerminator(e);){this.skipSpace();let t=this.matchInfixOperator(n,e);null===t&&(t=this.applyInvisibleOperator(e,n)),null!==t?n=t:i=!0}}return this.decorate(n,i)}decorate(e,i){if(null===e)return null;if(!this.options.preserveLatex)return e;const n=this.latex(i,this.index);return Array.isArray(e)?e={latex:n,fn:e}:"number"==typeof e?e={latex:n,num:Number(e).toString()}:"string"==typeof e?e={latex:n,sym:e}:"object"==typeof e&&null!==e&&(e.latex=n),e}error(e,i){return"string"==typeof e?["Error",{str:e},["Latex",{str:this.latex(i,this.index)}]]:["Error",["ErrorCode",{str:e[0]},...e.slice(1)],["Latex",{str:this.latex(i,this.index)}]]}}function fn(e,i){const n=e.length,t=e;e=e.slice(0,-1);for(let n=0;n<e.length-16;n++){const t=e.substring(0,n);for(let r=0;r<17;r++){const s=e.substring(n,n+r+1),o=Math.floor((e.length-t.length)/s.length);if(o>1&&(t+s.repeat(o+1)).startsWith(e))return"0"===s?t.replace(/(\d{3})/g,"$1"+i.groupSeparator):t.replace(/(\d{3})/g,"$1"+i.groupSeparator)+i.beginRepeatingDigits+s+i.endRepeatingDigits}}const r=n>i.precision-1;return e=t,r&&(e=e.substring(0,i.precision-1)),i.groupSeparator&&(e=e.replace(/(\d{3})/g,"$1"+i.groupSeparator)).endsWith(i.groupSeparator)&&(e=e.slice(0,-i.groupSeparator.length)),r?e+i.truncationMarker:e}function gn(e,i){var n;return e?i.beginExponentMarker?i.beginExponentMarker+e+(null!==(n=i.endExponentMarker)&&void 0!==n?n:""):"10^{"+e+"}":""}class pn{constructor(e,i,n){this.level=-1,this.options=e,e.invisibleMultiply&&(/#1/.test(e.invisibleMultiply)&&/#2/.test(e.invisibleMultiply)||n([{severity:"warning",message:["expected-argument","invisibleMultiply"]}])),this.onError=n,this.dictionary=i}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i])}wrap(e,i){if(null===e)return"";if(void 0===i)return this.wrapString(this.serialize(e),this.options.groupStyle(e,this.level+1));if("number"==typeof e||ii(e)||"string"==typeof e||ni(e))return this.serialize(e);const n=ai(e);if("string"==typeof n&&"Delimiter"!==n&&"Subscript"!==n){const t=this.dictionary.name.get(n);if(t&&("symbol"===t.kind||"prefix"===t.kind||"infix"===t.kind||"postfix"===t.kind)&&t.precedence<i)return this.wrapString(this.serialize(e),this.options.applyFunctionStyle(e,this.level))}return this.serialize(e)}wrapShort(e){if(null===e)return"";const i=this.serialize(e);return"Delimiter"===ai(e)&&1===di(e)||"number"==typeof e||ii(e)||/(^(.|\\[a-zA-Z*]+))$/.test(i)?i:this.wrapString(i,this.options.groupStyle(e,this.level+1))}wrapString(e,i,n){var t,r;if("none"===i)return e;const s=null!==(t=null==n?void 0:n[0])&&void 0!==t?t:"(",o=null!==(r=null==n?void 0:n[1])&&void 0!==r?r:")";return"."!==s&&"."!==o||"paren"!==i||(i="leftright"),"leftright"===i?`${"."===s?"":"\\left("+s}${e}${"."===o?"":"\\right("+o})`:"big"===i?`${"."===s?"":"\\Bigl("+s}${e}${"."===o?"":"\\Bigr("+o})`:s+e+o}wrapArguments(e){var i;return this.wrapString((null!==(i=ui(e))&&void 0!==i?i:[]).map((e=>this.serialize(e))).join(", "),this.options.applyFunctionStyle(e,this.level))}serializeSymbol(e,i){var n;return ai(e)?this.serializeFunction(e,i):"string"==typeof(null==i?void 0:i.serialize)?i.serialize:"function"==typeof(null==i?void 0:i.serialize)?i.serialize(this,e):null!==(n=yn(fi(e),"upright."))&&void 0!==n?n:""}serializeFunction(e,i){var n,t;const r=ai(e);if(!r)return this.serializeSymbol(e,i);const s=null!==(n=ui(e))&&void 0!==n?n:[];if(i)return"function"==typeof i.serialize?i.serialize(this,e):Xe([null!==(t=i.serialize)&&void 0!==t?t:r,this.wrapArguments(e)]);if("string"==typeof r&&r.length>0&&"\\"===r[0])return Xe([r,...s.map((e=>`{${this.serialize(e)}}`))]);if("string"==typeof r)return yn(r,"upright.")+this.wrapArguments(e);const o=this.options.applyFunctionStyle(e,this.level);return"\\mathrm{Apply}"+this.wrapString(this.serialize(r)+", "+this.serialize(["List",...s]),o)}serializeDictionary(e){return`\\left\\lbrack\\begin{array}{lll}${Object.keys(e).map((i=>`\\textbf{${i}} & \\rightarrow & ${this.serialize(e[i])}`)).join("\\\\")}\\end{array}\\right\\rbrack`}serialize(e){if(null==e)return"";this.level+=1;try{const i=(()=>{var i;const n=function(e,i){var n,t,r;if(null===e)return"";let s;if("number"==typeof e||"string"==typeof e)s=e;else{if("object"!=typeof e||!("num"in e))return"";s=e.num}if("number"==typeof s)return s===1/0?i.positiveInfinity:s===-1/0?i.negativeInfinity:Number.isNaN(s)?i.notANumber:"engineering"===i.notation?function(e,i){if(0===e)return"0";const n=Math.abs(e);let t=Math.round(Math.log10(n));t-=t%3,n>Math.pow(10,i.avoidExponentsInRange[0])&&n<Math.pow(10,i.avoidExponentsInRange[1])&&(t=0);const r=n/Math.pow(10,t);let s="";const o=r.toString().match(/^(.*)\.(.*)$/);(null==o?void 0:o[1])&&o[2]&&(s=o[1]+i.decimalMarker+o[2]),i.groupSeparator&&(s=fn(r.toExponential(),i));let a="";return 0!==t&&(a=gn(t.toString(),i)),(e<0?"-":"")+s+a}(s,i):function(e,i){var n;let t,r=e.match(/^(.*)[e|E]([-+]?[0-9]+)$/i);(null==r?void 0:r[1])&&r[2]&&(t=gn(r[2],i));let s=null!==(n=null==r?void 0:r[1])&&void 0!==n?n:e,o="";return r=(t?r[1]:e).match(/^(.*)\.(.*)$/),(null==r?void 0:r[1])&&r[2]&&(s=r[1],o=r[2]),i.groupSeparator&&(s=s.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator),o=fn(o,i)),o&&(o=i.decimalMarker+o),t?"1"!==s||o?s+o+i.exponentProduct+t:t:s+o}(s.toString(),i);if(s=s.toLowerCase().replace(/[\u0009-\u000d\u0020\u00a0]/g,""),"infinity"===s||"+infinity"===s)return i.positiveInfinity;if("-infinity"===s)return i.negativeInfinity;if("nan"===s)return i.notANumber;if(!/^[-+\.]?[0-9]/.test(s))return"";if(s=s.replace(/[nd]$/,""),/\([0-9]+\)/.test(s)){const[e,t,r,o]=null!==(n=s.match(/(.+)\(([0-9]+)\)(.*)$/))&&void 0!==n?n:[];s=t+r.repeat(Math.ceil(i.precision/r.length))+o}let o="";for("-"===s[0]?(o="-",s=s.substring(1)):"+"===s[0]&&(s=s.substring(1));"0"===s[0];)s=s.substring(1);if(0===s.length)return o+"0";"."===s[0]&&(s="0"+s);let a="";if(s.indexOf(".")>=0){const e=s.match(/(\d*)\.(\d*)([e|E]([-+]?[0-9]*))?/);if(!e)return"";const n=e[1],r=e[2];if(a=null!==(t=e[4])&&void 0!==t?t:"","0"===n){let e=0;for(;"0"===r[e]&&e<r.length;)e+=1;let n="";if(e<=4)n="0"+i.decimalMarker,n+=r.substring(0,e),n+=fn(s.substring(n.length),i);else if(e+1>=i.precision)n="0",o="";else{n=s[e];const t=fn(s.substring(e+1),i);t&&(n+=i.decimalMarker+t)}"0"!==n&&(!(s.length-1>i.precision)||i.endRepeatingDigits&&n.endsWith(i.endRepeatingDigits)||!i.truncationMarker||n.endsWith(i.truncationMarker)||(n+=i.truncationMarker),e>4&&(n+=i.exponentProduct+gn(""+(1-e),i))),s=n}else{s=n.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator);const e=fn(r,i);e&&(s+=i.decimalMarker+e)}}else if(s.length>i.precision){const e=s.length;if(e>i.avoidExponentsInRange[1]){let n=s[0];const t=fn(s.substring(1),i);t&&(n+=i.decimalMarker+t,i.truncationMarker&&!n.endsWith(i.truncationMarker)&&i.endRepeatingDigits&&!n.endsWith(i.endRepeatingDigits)&&(n+=i.truncationMarker)),"1"!==n?n+=i.exponentProduct:n="",s=n+gn(""+(e-1),i)}}else{const e=s.match(/([0-9]*)\.?([0-9]*)([e|E]([-+]?[0-9]+))?/);e&&(s=e[1],e[2]&&(s+=i.decimalMarker+e[2]),a=null!==(r=e[4])&&void 0!==r?r:""),s=s.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator)}const l=gn(a,i);return"1"===s&&l?o+l:(l&&(s=s+i.exponentProduct+l),o+s)}(e,this.options);if(n)return n;const t=si(e);if(null!==t)return`\\text{${t}}`;const r=fi(e);if(null!==r){const i=this.dictionary.name.get(r);if("symbol"===(null==i?void 0:i.kind))return this.serializeSymbol(e,i);if("function"===(null==i?void 0:i.kind))return this.serializeFunction(e,i)}const s=pi(e);if(null!==s)return this.serializeDictionary(s);const o=li(e);if(o){if("\\"===o[0]){const n=null!==(i=ui(e))&&void 0!==i?i:[];return 0===n.length?o:o+"{"+n.map((e=>this.serialize(e))).filter((e=>!!e)).join("}{")+"}"}const n=this.dictionary.name.get(o);if(n)return"function"==typeof n.serialize?n.serialize(this,e):"infix"===n.kind||"postfix"===n.kind||"prefix"===n.kind?function(e,i,n){let t="";const r=di(i),s=li(i);if("postfix"===n.kind)return 1!==r&&e.onError([{severity:"warning",message:["postfix-operator-requires-one-operand",e.serializeSymbol(s)]}]),vn(n.serialize,[e.wrap(ci(i,1),n.precedence)]);if("prefix"===n.kind)return 1!==r&&e.onError([{severity:"warning",message:["prefix-operator-requires-one-operand",e.serializeSymbol(s)]}]),vn(n.serialize,[e.wrap(ci(i,1),n.precedence+1)]);if("infix"===n.kind){t=e.wrap(ci(i,1),n.precedence);for(let s=2;s<r+1;s++){const r=ci(i,s);null!==r&&(t=vn(n.serialize,[t,e.wrap(r,n.precedence)]))}}return t}(this,e,n):"symbol"===n.kind?this.serializeSymbol(e,n):"function"===n.kind?this.serializeFunction(e,n):""}if(Array.isArray(e)||ti(e)||null!==fi(e))return this.serializeSymbol(e);this.onError([{severity:"warning",message:["syntax-error",e?JSON.stringify(e):"undefined"]}])})();return this.level-=1,null!=i?i:""}catch(e){}return this.level-=1,""}applyFunctionStyle(e,i){return this.options.applyFunctionStyle(e,i)}groupStyle(e,i){return this.options.groupStyle(e,i)}rootStyle(e,i){return this.options.rootStyle(e,i)}fractionStyle(e,i){return this.options.fractionStyle(e,i)}logicStyle(e,i){return this.options.logicStyle(e,i)}powerStyle(e,i){return this.options.powerStyle(e,i)}numericSetStyle(e,i){return this.options.numericSetStyle(e,i)}}function vn(e,i){var n;let t=e;for(let e=0;e<i.length;e++){let r=null!==(n=i[e])&&void 0!==n?n:"";if(/[a-zA-Z*]/.test(r[0])){const i=t.match(RegExp("(.*)#"+Number(e+1).toString()));i&&/\\[a-zA-Z*]+/.test(i[1])&&(r=" "+r)}t=t.replace("#"+Number(e+1).toString(),r)}return t}const bn=["alpha","beta","gamma","Gamma","delta","Delta","epsilon","zeta","eta","theta","Theta","iota","kappa","lambda","Lambda","mu","nu","xi","Xi","pi","Pi","rho","sigma","Sigma","tau","upsilon","phi","Phi","varphi","chi","psi","Psi","omega","Omega","aleph","ast","blacksquare","bot","bullet","circ","diamond","times","top","square","star"];function yn(e,i="italic."){var n;if(null===e)return null;const t=e.match(/^(_+)(.*)/);if(t)return`\\text{${"\\_".repeat(t[1].length)+Nn(t[2])}}`;let r;[r,e]=function(e){const i=e.match(/^([a-zA-Z-]+\.)(.*)/);return i?[i[1],i[2]]:["",e]}(e);const s=Nn(e);return 1!==s.length||r?(r||(r=i),(null!==(n={"upright.":"\\mathrm{_}","italic.":"\\mathit{_}","bold-italic.":"\\mathbf{\\mathit{_}}","script.":"\\mathscr{_}","calligraphic.":"\\mathcal{_}","bold-script.":"\\mathbf{\\mathscr{_}}","bold-calligraphic.":"\\mathbf{\\mathcal{_}}","fraktur.":"\\mathfrak{_}","gothic.":"\\mathfrak{_}","bold-gothic.":"\\mathbf{\\mathfrak{_}}","bold-fraktur.":"\\mathbf{\\mathfrak{_}}","sans-serif.":"\\mathsf{_}","bold-sans-serif.":"\\mathbf{\\mathsf{_}}","italic-sans-serif.":"\\mathit{\\mathsf{_}}","monospace.":"\\mathtt{_}","blackboard.":"\\mathbb{_}","double-struck.":"\\mathbb{_}"}[r])&&void 0!==n?n:"\\mathit{_}").replace("_",s)):s}function Nn(e){const i=e.indexOf("_");if(i>0){const n=e.substring(0,i),t=e.substring(i+1);return t?t.startsWith('"')&&t.endsWith('"')?`${Nn(n)}_\\mathrm{${Nn(t.substring(1,-1))}}`:`${Nn(n)}_{${Nn(t)}}`:yn(n)+"\\_"}const n=e.match(/(.*?)(-?[0-9]+)$/);return n?0===n[1].length?e:`${Nn(n[1])}_{${n[2]}}`:bn.includes(e)?"\\"+e:e=e.replace(/[{}\[\]\\:\-\$%]/g,(e=>{var i;return null!==(i={"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash ","-":'\\unicode{"2013}'}[e])&&void 0!==i?i:"\\"+e}))}const _n={invisibleMultiply:"",invisiblePlus:"",multiply:"\\times",missingSymbol:"\\blacksquare",applyFunctionStyle:function(e,i){return"paren"},groupStyle:function(e,i){return"paren"},rootStyle:Ii,fractionStyle:Mi,logicStyle:function(e,i){return"boolean"},powerStyle:function(e,i){return"solidus"},numericSetStyle:function(e,i){return"compact"}};class xn{constructor(e){var i,n;this.onError=null!==(i=e.onError)&&void 0!==i?i:e=>{if("undefined"!=typeof window)for(const i of e);},this.computeEngine=e.computeEngine;const t=Object.assign({},e);delete t.dictionary,delete t.onError,this.options=Object.assign(Object.assign(Object.assign(Object.assign({},hn),mn),_n),t),this.dictionary=function(e,i){var n,t;const r={lookahead:1,name:new Map,function:new Map,symbol:[],infix:[],prefix:[],postfix:[],environment:new Map,matchfix:[]};for(const s of e){const[e,o]=rn(s,i);if(null!==o)if(void 0!==o.name&&(r.name.has(o.name)&&i({severity:"warning",message:["invalid-dictionary-entry",o.name,"Duplicate definition"]}),r.name.set(o.name,o)),"matchfix"===o.kind)r.matchfix.push(o);else if("environment"===o.kind){const e=ei(null!==(n=s.trigger)&&void 0!==n?n:"");r.environment.has(e)&&i({severity:"warning",message:["invalid-dictionary-entry",e,"Duplicate environment definition"]}),r.environment.set(e,o)}else if(e){const i=ei(null!==(t=s.trigger)&&void 0!==t?t:""),n=tn(e);if(r.lookahead=Math.max(r.lookahead,n),"function"===o.kind)r.function.has(i)?r.function.set(i,[...r.function.get(i),o]):r.function.set(i,[o]);else if("symbol"===o.kind){void 0===r.symbol[n]&&(r.symbol[n]=new Map);const e=r.symbol[n];e.has(i)?e.get(i).push(o):e.set(i,[o])}else if("prefix"===o.kind){void 0===r.prefix[n]&&(r.prefix[n]=new Map);const e=r.prefix[n];e.has(i)?e.get(i).push(o):e.set(i,[o])}else if("infix"===o.kind){void 0===r.infix[n]&&(r.infix[n]=new Map);const e=r.infix[n];e.has(i)?e.get(i).push(o):e.set(i,[o])}else if("postfix"===o.kind){void 0===r.postfix[n]&&(r.postfix[n]=new Map);const e=r.postfix[n];e.has(i)?e.get(i).push(o):e.set(i,[o])}}}return r}(null!==(n=e.dictionary)&&void 0!==n?n:xn.getDictionary(),(e=>this.onError([e])))}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i]);this.serializer.updateOptions(e)}static getDictionary(e="all"){if("all"===e){const e=[];for(const i of Object.keys(sn))sn[i]&&e.push(...sn[i]);return e}return sn[e]?[...sn[e]]:[]}parse(e){const i=new dn(Ke(e,[]),this.options,this.dictionary,this.computeEngine);let n=i.matchExpression();if(!i.atEnd){const e=i.peekDefinitions("infix");if(e){const t=i.index,[r,s]=e[0];i.index+=s;const o=r.parse(i,{minPrec:0},null!=n?n:i.error("missing",t));if(o)return o;if(r.name)return[r.name,null!=n?n:i.error("missing",t),i.error("missing",t)];i.index=t}const t=i.index,r=i.matchEnclosureOpen();if(r){const e=i.error(["expected-close-delimiter",r],t);return n?["Sequence",n,e]:e}const s=i.matchEnclosureClose();if(s){const e=i.error(["expected-open-delimiter",s],t);return n?["Sequence",n,e]:e}const o=i.index,a=i.next();for(;!i.atEnd;)i.next();const l=i.error([a.length>1&&a.startsWith("\\")?"unexpected-command":"unexpected-token",{str:ei([a])}],o);n=n?["Sequence",n,l]:l}return null!=n||(n=["Sequence"]),this.options.preserveLatex&&(Array.isArray(n)?n={latex:e,fn:n}:"number"==typeof n?n={latex:e,num:Number(n).toString()}:"string"==typeof n?n={latex:e,sym:n}:"object"==typeof n&&null!==n&&(n.latex=e)),null!=n?n:["Sequence"]}serialize(e){return this.serializer.serialize(e)}get serializer(){return this._serializer||(this._serializer=new pn(this.options,this.dictionary,this.onError)),this._serializer}}const Sn=Math.log10(Math.pow(2,53)),wn=1e-10,kn=1e6,En=1e6,An=new Set([2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001,4003,4007,4013,4019,4021,4027,4049,4051,4057,4073,4079,4091,4093,4099,4111,4127,4129,4133,4139,4153,4157,4159,4177,4201,4211,4217,4219,4229,4231,4241,4243,4253,4259,4261,4271,4273,4283,4289,4297,4327,4337,4339,4349,4357,4363,4373,4391,4397,4409,4421,4423,4441,4447,4451,4457,4463,4481,4483,4493,4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,5011,5021,5023,5039,5051,5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,5153,5167,5171,5179,5189,5197,5209,5227,5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919]);function In(e){var i,n;if(e<=3)return{[e]:1};const t={};let r=0;for(;e%2==0;)r+=1,e/=2;for(r>0&&(t[2]=r),r=0;e%3==0;)r+=1,e/=3;r>0&&(t[3]=r);let s=!1;for(;!s;){if(1===e)return t;const r=Math.sqrt(e);s=!0;for(let o=6;o<=r+6;o+=6){if(e%(o-1)==0){t[o-1]=(null!==(i=t[o-1])&&void 0!==i?i:0)+1,e/=o-1,s=!1;break}if(e%(o+1)==0){t[o+1]=(null!==(n=t[o+1])&&void 0!==n?n:0)+1,e/=o+1,s=!1;break}}}return t[e]=1,t}function Mn(e,i){const n=In(e);let t=1,r=1;for(const e of Object.keys(n)){const s=parseInt(e);t*=Math.pow(s,Math.floor(n[e]/i)),r*=Math.pow(s,n[e]%i)}return[t,r]}const qn=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],On=[.999999999999997,57.15623566586292,-59.59796035547549,14.13609797474174,-.4919138160976202,3399464998481188e-20,4652362892704857e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.0002174396181152126,-.0001643181065367639,8441822398385274e-20,-261908384015814e-19,3689918265953162e-21];function Tn(e){if(e<0)return NaN;let i=On[0];for(let n=14;n>0;--n)i+=On[n]/(e+n);const n=e+4.7421875+.5;return.9189385332046727+(e+.5)*Math.log(n)-n+Math.log(i)-Math.log(e)}function Fn(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*Fn(1-e));if(e>100)return Math.exp(Tn(e));e-=1;let i=qn[0];for(let n=1;n<9;n++)i+=qn[n]/(e+n);const n=e+7+.5;return 2.5066282746310002*Math.pow(n,e+.5)*Math.exp(-n)*i}function Cn(e,i=10){let n=0;for(let t=0;t<e.length;t++){const r={" ":-1,"\xa0":-1,"\u2000":-1,"\u2001":-1,"\u2002":-1,"\u2003":-1,"\u2004":-1,"\u2005":-1,"\u2006":-1,"\u2007":-1,"\u2008":-1,"\u2009":-1,"\u200a":-1,"\u200b":-1,"\u202f":-1,"\u205f":-1,_:-1,",":-1,0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,g:16,h:17,i:18,j:19,k:20,l:21,m:22,n:23,o:24,p:25,q:26,r:27,s:28,t:29,u:30,v:31,w:32,x:33,y:34,z:35}[e[t]];if(-1!==r){if(void 0===r)return[n,e.substring(t)];if(r>=i)return[n,e.substring(t)];n=n*i+r}}return[n,""]}function Dn(e){const i=e.numericValue;if(null===i)return null;if("number"==typeof i)return i;if(i instanceof Ge)return i.toNumber();if(Array.isArray(i)){const[e,n]=i;return"number"==typeof e&&"number"==typeof n?e/n:e.div(n).toNumber()}return null}function Pn(e){const i=e.numericValue;if(null===i)return null;if(i instanceof Ge)return i;if("number"==typeof i)return e.engine.bignum(i);if(Array.isArray(i)){const[n,t]=i;return"number"==typeof n&&"number"==typeof t?e.engine.bignum(n/t):n.div(t)}return null}function Ln(e){const i=e.numericValue;if(null===i)return null;if("number"==typeof i)return Number.isInteger(i)&&i>=-1e6&&i<=kn?i:null;if(i instanceof Ge){if(i.isInteger()){const e=i.toNumber();if(e>=-1e6&&e<=kn)return e}return null}if(e.isCanonical)return null;const n=i;if(Array.isArray(n)){const[e,i]=n;let t;return t="number"==typeof e&&"number"==typeof i?e/i:e.div(i).toNumber(),Number.isInteger(t)&&t>=-1e6&&t<=kn?t:null}return null}function Rn(e,i){return"number"==typeof e&&Math.abs(e)<=i||e instanceof Ge&&e.abs().lte(i)||e instanceof Ue&&Math.abs(e.re)<=i&&Math.abs(e.im)<=i?0:e}function zn(e){return"string"==typeof e&&e.startsWith("$")&&e.endsWith("$")}function $n(e){return"string"==typeof e&&e.startsWith("$")&&e.endsWith("$")?e.slice(1,-1):null}function Vn(e){if("ImaginaryUnit"===e.symbol)return 1;const i=e.numericValue;if(null!==i&&i instanceof Ue&&0===i.re)return i.im;if("Negate"===e.head){const i=Vn(e.op1);return null===i?null:-i}if("Multiply"===e.head&&2===e.nops){if("ImaginaryUnit"===e.op1.symbol)return Dn(e.op2);if("ImaginaryUnit"===e.op2.symbol)return Dn(e.op1)}return 0}function jn(e){if(e.symbol){const i=e.symbolDefinition;return(null==i?void 0:i.constant)?[]:[e.symbol]}if(!e.ops&&!e.keys)return[];const i=[];if(e.ops)for(const n of e.ops)i.push(...jn(n));if(e.keys)for(const n of e.keys)i.push(...jn(e.getKey(n)));return i}function Gn(e,i){if(e.symbol)return i.add(e.symbol),i;if(!e.ops&&!e.keys)return i;if(e.ops)for(const n of e.ops)Gn(n,i);if(e.keys)for(const n of e.keys)Gn(e.getKey(n),i);return i}function Zn(e,i){const n=i&&e.head!==i?[]:[e];if(e.ops)for(const t of e.ops)n.push(...Zn(t,i));else if(e.keys)for(const t of e.keys)n.push(...Zn(e.getKey(t),i));return n}function Bn(e){return"bignum"===e.numericMode||"auto"===e.numericMode}function Un(e){return"auto"===e.numericMode||"complex"===e.numericMode}function Hn(e){let i=0;for(let n=0;n<e.length;n++)i=Math.imul(31,i)+e.charCodeAt(n)|0;return Math.abs(i)}function Wn(e,i){var n;if(null==i)return null;if("number"==typeof i)return e.bignum(i);if(ii(i)){let t=i.num.toLowerCase().replace(/[nd]$/g,"").replace(/[\u0009-\u000d\u0020\u00a0]/g,"");if(/\([0-9]+\)/.test(t)){const[i,r,s,o]=null!==(n=t.match(/(.+)\(([0-9]+)\)(.*)$/))&&void 0!==n?n:[];t=r+s.repeat(Math.ceil(e.precision/s.length))+(null!=o?o:"")}return"nan"===t?e.bignum("NaN"):"infinity"===t||"+infinity"===t?e.bignum("+Infinity"):"-infinity"===t?e.bignum("-Infinity"):e.bignum(t)}return null}function Qn(e,i){var n;const t=new Set;for(const[r,s,o]of i){let i;const a=$n(null==o?void 0:o.condition);if(a){const n=e.pattern(a);i=e=>{var i;return"True"===(null===(i=n.subs(e).value)||void 0===i?void 0:i.symbol)}}else i=null==o?void 0:o.condition;t.add([e.pattern(r),e.pattern(s),null!==(n=null==o?void 0:o.priority)&&void 0!==n?n:0,i])}return t}function Yn([e,i,n,t],r,s,o){const a=e.match(r,Object.assign({substitution:s},o));return null===a?null:"function"!=typeof t||t(a)?i.subs(a,{canonical:!0}):null}function Jn(e,i,n){var t,r;const s=null!==(t=null==n?void 0:n.iterationLimit)&&void 0!==t?t:1;let o=0;const a=null!==(r=null==n?void 0:n.once)&&void 0!==r&&r;let l=!1,u=!1;try{for(;!l&&o<s;){l=!0;for(const t of i){const i=Yn(t,e,{},n);if(null!==i&&i!==e){if(a)return i;l=!1,u=!0,e=i}}o+=1}}catch(e){}return u?e:null}function Kn(e,i){var n;const t=[];for(const r of e)r.ops&&r.head===i?t.push(...null!==(n=Kn(r.ops,i))&&void 0!==n?n:r.ops):t.push(r);return t.length===e.length?null:t}function Xn(e){const i=[];for(const n of e)"Sequence"===n.head?n.ops&&i.push(...n.ops):i.push(n);return i}function et(e,i,n){if(i.length===n)return i;const t=[...i.slice(0,n)];let r=Math.min(n,i.length);for(;r<n;)t.push(e.error("missing")),r+=1;for(;r<i.length;)t.push(e.error("unexpected-argument",i[r])),r+=1;return t}function it(e,i,n){let t=[];if(void 0===n)t=i.map((i=>e.box(i)));else for(let r=0;r<=Math.max(n-1,i.length-1);r++)r>n-1?t.push(e.error("unexpected-argument",i[r])):t.push(void 0!==i[r]?e.box(i[r]):e.error(["missing","Number"]));return Xn(t).map((i=>!i.isValid||i.isNumber?i:e.error(["incompatible-domain","Number",i.domain],i)))}function nt(e,i,n){const t=e.engine,r=i.map((e=>e.domain)),s=t.domain(["Function",...r,null!=n?n:"Anything"]);if(e.isCompatible(s))return null;const o=e.domainArgs.slice(0,-1),a=Math.max(o.length,r.length);let l=[],u=[...i];for(let e=0;e<=a-1;e++)[l,u]=rt(t,o[e],l,u);for(;l.length>0&&"Nothing"===l[l.length-1].symbol;)l.pop();return l}function tt(e,i,n){return void 0===n?e.error("unexpected-argument",i):void 0===i?e.error(["missing",n]):i.isValid?(null==i?void 0:i.domain.isCompatible(e.domain(n)))?i:e.error(["incompatible-domain",n,i.domain],i):i}function rt(e,i,n,t){let r=t.shift();if(void 0===i)return[[...n,e.error("unexpected-argument",r)],t];if(!Array.isArray(i))return r?r.domain.isCompatible(e.domain(i))?[[...n,r],t]:[[...n,e.error(["incompatible-domain",i,r.domain],r)],t]:[[...n,e.error(["missing",i])],t];const s=i[0];if(void 0===r){let r=!1;if("Union"===s){for(let e=1;e<=i.length-1;e++)if("Nothing"===i[e]){r=!0;break}}else"Maybe"===s&&(r=!0);return r?[[...n,e.symbol("Nothing")],t]:[[...n,e.error(["missing",i])],t]}if("Union"===s){let s=!1;for(let n=1;n<=i.length-1;n++)if(r.domain.isCompatible(e.domain(i[n]))){s=!0;break}return s?[[...n,r],t]:[[...n,e.error(["incompatible-domain",i,r.domain],r)],t]}if("Sequence"===s){const s=e.domain(i[1]);if(!r||!r.domain.isCompatible(s))return[[...n,e.error(["incompatible-domain",s,r.domain],r)],t];let o=!1;const a=[...n,r];for(;!o;)r=t.shift(),r?r.domain.isCompatible(s)?a.push(r):(t.unshift(r),o=!1):o=!1;return[a,t]}return"Maybe"===s?void 0===r||"Nothing"===r.symbol?[[...n,e.symbol("Nothing")],t]:rt(e,i[1],n,[r,...t]):[[...n,r],t]}const st=[4,2,4,2,4,6,2,6];function ot(e,i,n){const t=function(e,i){var n;if(i.lt(Number.MAX_SAFE_INTEGER)){const n=In(i.toNumber()),t=new Map;for(const i of Object.keys(n))t.set(e.bignum(i),n[i]);return t}const t=new Map;let r=0;for(;i.mod(2).isZero();)r+=1,i=i.div(2);for(r>0&&t.set("2",r),r=0;i.mod(3).isZero();)r+=1,i=i.div(3);for(r>0&&t.set("3",r);i.mod(5).isZero();)r+=1,i=i.div(5);r>0&&t.set("5",r);let s=e.bignum(7),o=s.toString(),a=0;for(;s.mul(s).lt(i);)i.mod(s).isZero()?(t.set(o,(null!==(n=t.get(o))&&void 0!==n?n:0)+1),i=i.div(s)):(s=s.add(st[a]),o=s.toString(),a=a<7?a+1:0);i.eq(1)||t.set(i.toString(),1);const l=new Map;for(const[i,n]of t)l.set(e.bignum(i),n);return l}(e,i);let r=e.bignum(1),s=e.bignum(1);for(const[i,o]of t){const t=e.bignum(o);r=r.mul(i.pow(t.div(n).floor())),s=s.mul(i.pow(t.mod(n)))}return[r,s]}function at(e,i){if(!i.isInteger()||i.isNegative())return e._BIGNUM_NAN;if(i.lessThan(10))return e.bignum([1,1,2,6,24,120,720,5040,40320,362880,3628800][i.toNumber()]);if(i.gt(Number.MAX_SAFE_INTEGER)){let n=e._BIGNUM_ONE,t=e._BIGNUM_TWO;for(;t.lessThan(i);)n=n.mul(t),t=t.add(1);return n}if(i.modulo(2).eq(1))return i.times(at(e,i.minus(1)));let n=i.toNumber(),t=i,r=i;for(;n>2;)n-=2,t=t.add(n),r=r.mul(t);return r}function lt(e,i){if(i.isNegative())return e._BIGNUM_NAN;const n=e.cache("gamma-p-ln",(()=>["0.99999999999999709182","57.156235665862923517","-59.597960355475491248","14.136097974741747174","-0.49191381609762019978","0.33994649984811888699e-4","0.46523628927048575665e-4","-0.98374475304879564677e-4","0.15808870322491248884e-3","-0.21026444172410488319e-3","0.2174396181152126432e-3","-0.16431810653676389022e-3","0.84418223983852743293e-4","-0.2619083840158140867e-4","0.36899182659531622704e-5"].map((i=>e.bignum(i)))));let t=n[0];for(let e=n.length-1;e>0;--e)t=t.add(n[e].div(i.add(e)));const r=e.cache("gamma-g-ln",(()=>e.bignum(607).div(128))),s=i.add(r).add(e._BIGNUM_HALF);return e._BIGNUM_NEGATIVE_ONE.acos().mul(e._BIGNUM_TWO).log().mul(e._BIGNUM_HALF).add(s.log().mul(i.add(e._BIGNUM_HALF)).minus(s).add(t.log()).minus(i.log()))}function ut(e,i){if(i.lessThan(e._BIGNUM_HALF)){const n=e._BIGNUM_NEGATIVE_ONE.acos();return n.div(n.mul(i).sin().mul(ut(e,e._BIGNUM_ONE.sub(i))))}if(i.greaterThan(100))return lt(e,i).exp();i=i.sub(1);const n=e.cache("lanczos-7-c",(()=>["0.99999999999980993227684700473478","676.520368121885098567009190444019","-1259.13921672240287047156078755283","771.3234287776530788486528258894","-176.61502916214059906584551354","12.507343278686904814458936853","-0.13857109526572011689554707","9.984369578019570859563e-6","1.50563273514931155834e-7"].map((i=>e.bignum(i)))));let t=n[0];for(let e=1;e<9;e++)t=t.add(n[e].div(i.add(e)));const r=i.add(7).add(e._BIGNUM_HALF);return e._BIGNUM_NEGATIVE_ONE.acos().times(e._BIGNUM_TWO).sqrt().mul(t.mul(r.neg().exp()).mul(r.pow(i.add(e._BIGNUM_HALF))))}function ct(e){return!e.isFinite()||!(e.d.length>3||3===e.d.length&&e.d[0]>=90)&&e.e<308&&e.e>-306}function ht(e){return null!==e&&Array.isArray(e)}function mt(e){return null!==e&&Array.isArray(e)&&"number"==typeof e[0]}function dt(e){return null!==e&&Array.isArray(e)&&e[0]instanceof Ge}function ft(e){return 0===e[0]||e[0]instanceof Ge&&e[0].isZero()}function gt(e){return e[0]===e[1]||"number"!=typeof e[0]&&e[0].eq(e[1])}function pt(e){return"number"==typeof e[0]?e[0]===-e[1]:e[0].eq(e[1].neg())}function vt(e){return"number"==typeof e[0]?e[0]:e[0].toNumber()}function bt(e){return"number"==typeof e[1]?e[1]:e[1].toNumber()}function yt(e){return mt(e)?e[0]<0:e[0].isNeg()}function Nt(e){return mt(e)?[-e[0],e[1]]:[e[0].neg(),e[1]]}function _t(e){return mt(e)?e[0]<0?[-e[1],-e[0]]:[e[1],e[0]]:e[0].isNeg()?[e[1].neg(),e[0].neg()]:[e[1],e[0]]}function xt(e){const i=e.numericValue;if(null!==i)return Array.isArray(i)?i:"number"==typeof i&&Number.isInteger(i)?[i,1]:i instanceof Ge&&i.isInteger()?[i,e.engine._BIGNUM_ONE]:void 0}function St(e){return mt(e)?e:[e[0].toNumber(),e[1].toNumber()]}function wt(e,i){if(Array.isArray(i))return dt(i)?[i[1].mul(e[0]).add(i[0].mul(e[1])),i[1].mul(e[1])]:dt(e)?[e[0].mul(i[1]).add(e[1].mul(i[0])),e[1].mul(i[1])]:[i[1]*e[0]+i[0]*e[1],i[1]*e[1]];const n=i.numericValue;if(null!==n&&"number"==typeof n)return mt(e)?[e[0]+e[1]*n,e[1]]:[e[0].add(e[1].mul(n)),e[1]];if(n instanceof Ge){if(mt(e)){const t=i.engine;return[t.bignum(n.mul(e[1]).add(e[0])),t.bignum(e[1])]}return[e[0].add(e[1].mul(n)),e[1]]}return Array.isArray(n)?dt(n)?[n[1].mul(e[0]).add(n[0].mul(e[1])),n[1].mul(e[1])]:dt(e)?[e[0].mul(n[1]).add(e[1].mul(n[0])),e[1].mul(n[1])]:[n[1]*e[0]+n[0]*e[1],n[1]*e[1]]:e}function kt(e,i){if(Array.isArray(i))return dt(e)?[e[0].mul(i[0]),e[1].mul(i[1])]:dt(i)?[i[0].mul(e[0]),i[1].mul(e[1])]:[i[0]*e[0],i[1]*e[1]];const n=i.numericValue;return null!==n&&"number"==typeof n?mt(e)?[e[0]*n,e[1]]:[e[0].mul(n),e[1]]:n instanceof Ge?mt(e)?[n.mul(e[0]),i.engine.bignum(e[1])]:[n.mul(e[0]),e[1]]:Array.isArray(n)?dt(n)?[n[0].mul(e[0]),n[1].mul(e[1])]:mt(e)?[e[0]*n[0],e[1]*n[1]]:[e[0].mul(n[0]),e[1].mul(n[1])]:e}function Et(e,i){return i<0&&(e=_t(e),i=-i),0===i?[1,1]:1===i?e:mt(e)?[Math.pow(e[0],i),Math.pow(e[1],i)]:[e[0].pow(i),e[1].pow(i)]}function At(e){if(mt(e)){if(1===e[0]||1===e[1])return e;e[1]<0&&(e=[-e[0],-e[1]]);const i=function(e,i){if(0===e)return i;if(0===i)return e;if(e===i)return e;if(!Number.isInteger(e)||!Number.isInteger(i))return NaN;for(;0!==i;)[e,i]=[i,e%i];return e<0?-e:e}(e[0],e[1]);return i<=1?e:[e[0]/i,e[1]/i]}if(e[0].equals(1)||e[1].equals(1))return e;e[1].isNegative()&&(e=[e[0].neg(),e[1].neg()]);const i=function(e,i){for(;!i.isZero();)[e,i]=[i,e.modulo(i)];return e.abs()}(e[0],e[1]);return i.lessThanOrEqualTo(1)?e:[e[0].div(i),e[1].div(i)]}function It(e){const i=e.engine;if("Multiply"===e.head){const n=[];let t=[1,1];for(const i of e.ops){const e=i.numericValue;null===e||e instanceof Ue?n.push(i):t=kt(t,i)}return t=At(t),gt(t)?[[1,1],e]:0===n.length?[t,i._ONE]:1===n.length?[t,n[0]]:[t,i.mul(n)]}if("Divide"===e.head){let[n,t]=It(e.op1);const[r,s]=It(e.op2),o=At(kt(n,_t(r)));return t.isOne&&s.isOne?[o,i._ONE]:s.isOne?[o,t]:[o,i.fn("Divide",[t,s])]}if("Power"===e.head){if(!e.op2.isLiteral)return[[1,1],e];let[n,t]=It(e.op1);if(gt(n))return[[1,1],e];const r=e.op2,s=Ln(r);if(-1===s)return[_t(n),i.inverse(t)];if(null!==s)return[Et(n,s),i.power(t,r)];if(null!==r.numericValue&&Array.isArray(r.numericValue)){const[s,o]=St(r.numericValue),[a,l]=St(n);if(a>0&&1===Math.abs(s)){const[n,u]=Mn(a,o),[c,h]=Mn(l,o);return 1===n&&1===c?[[1,1],e]:[1===s?[n,c]:[c,n],i.power(i.mul([i.number([u,h]),t]),r)]}}return[[1,1],e]}if("Negate"===e.head){const[i,n]=It(e.op1);return[Nt(i),n]}const n=e.numericValue;if(null!==n){if(n instanceof Ge){if(n.isInteger()&&ct(n))return[[n.toNumber(),1],i._ONE];if(n.isNegative())return[[-1,1],i.number(n.neg())]}if("number"==typeof n){if(Number.isInteger(n))return[[n,1],i._ONE];if(n<0)return[[-1,1],i.number(-n)]}if(Array.isArray(n))return[n,i._ONE];if(n instanceof Ue&&n.re<0)return[[-1,1],i.number(i.complex(-n.re,-n.im))]}return[[1,1],e]}function Mt(e,i,n){if(e===i)return 0;const t=e.N(),r=i.N();if(!t.isLiteral||!r.isLiteral){const n=e.sgn,t=i.sgn;if("number"!=typeof n||"number"!=typeof t)return;return 0===n&&0===t?0:n<0&&t>0?-1:n>0&&t<0?1:void 0}null!=n||(n=e.engine.tolerance);const s=t.numericValue,o=r.numericValue;if(s instanceof Ue&&o instanceof Ue)return 0===Rn(s.re-o.re,n)&&0===Rn(s.im-o.im,n)?0:void 0;if(s instanceof Ue||o instanceof Ue)return;const a=xt(r);if(!a)return;const l=wt(Nt(a),t),u=mt(l)?Rn(l[0]/l[1],n):Rn(l[0].div(l[1]),n);return 0===u?0:"number"==typeof u?u>0?1:-1:u.isPos()?1:-1}function qt(e,i){let n=e.numericValue;return null===n?null:("number"==typeof n&&(n=-n),n instanceof Ge&&(n=n.neg()),n instanceof Be.exports.Complex&&(n=n.neg()),Array.isArray(n)&&(n=Nt(n)),e.engine.number(n,{metadata:i}))}function Ot(e,i){var n,t;if("Negate"===e.head)return tt(e.engine,null===(n=e.op1)||void 0===n?void 0:n.canonical,"Number");if((e=tt(e.engine,e.canonical,"Number")).isLiteral)return qt(e,i);if("Add"===e.head){let n=e.ops.map((e=>Ot(e)));return n=null!==(t=Kn(n,"Add"))&&void 0!==t?t:n,e.engine.add(n,i)}return e.engine._fn("Negate",[e],i)}function Tt(e){var i;if("Negate"===e.head)return e.op1;if(e.isLiteral)return qt(e);const n=e.engine;if("Add"===e.head){let t=e.ops.map((e=>Tt(e)));return t=null!==(i=Kn(t,"Add"))&&void 0!==i?i:t,n.add(t)}return"Multiply"===e.head?function(e,i){let n=[],t=!1;for(const e of i)t||"Negate"!==e.head?n.push(e):(t=!0,n.push(e.op1));if(t)return e.mul(n);n=[];for(const e of i)!t&&e.isLiteral&&e.isInteger?(t=!0,n.push(Tt(e))):n.push(e);if(t)return e.mul(n);n=[];for(const e of i)!t&&e.isLiteral&&e.isNumber?(t=!0,n.push(Tt(e))):n.push(e);return t?e.mul(n):e._fn("Negate",[e._fn("Multiply",i)])}(n,e.ops):"Divide"===e.head?n.divide(Tt(e.op1),e.op2):n._fn("Negate",[e])}function Ft(e,i,n="simplify"){return Tt(i)}function Ct(e,i){const n=e.engine;return"Negate"===e.head&&"Negate"===i.head?Ct(e.op1,i.op1):"Negate"===e.head?Ot(Ct(e.op1,i)):"Negate"===i.head?Ot(Ct(e,i.op1)):(e=Pt(e),i=Pt(i),"Add"===e.head?n.add(e.ops.map((e=>Ct(e,i)))):"Add"===i.head?n.add(i.ops.map((i=>Ct(e,i)))):n.mul([e,i]))}function Dt(e,i){if(1===i)return e;const n=Ct(e,e);return 2===i?n:i%2==0?Dt(n,i/2):Ct(Dt(n,Math.round(i/2)-1),e)}function Pt(e){const i=(e=e.simplify()).engine;if("Add"===e.head)return i.add(e.ops.map((e=>Pt(e)))).simplify();if("Negate"===e.head)return Ct(i._NEGATIVE_ONE,e.op1).simplify();if("Subtract"===e.head)return i.add([Pt(e.op1),Ct(i._NEGATIVE_ONE,e.op1)]).simplify();if("Divide"===e.head)return i.divide(Pt(e.op1),Pt(e.op2)).simplify();if("Multiply"===e.head)return 2===e.nops?Ct(e.op1,e.op2):e.ops.reduce(((e,i)=>Ct(e,i)),i._ONE).simplify();if("Power"===e.head){const n=e.op1.head;if("Multiply"===n)return i.mul(e.op1.ops.map((n=>i.power(n,e.op2)))).simplify();if("Negate"===n){const n=Ln(e.op2);if(null!==n&&n>0)return n%2==0?i.power(e.op1.op1,e.op2).simplify():i.negate(i.power(e.op1.op1,e.op2)).simplify()}if("Add"===n){const n=Ln(e.op2);if(null!==n)return n>0?Dt(e.op1,n).simplify():i.inverse(Dt(e.op1,-n)).simplify()}}return e.simplify()}const Lt=[[["Multiply","_x","_a"],["0"]],[["Add","_a","_x"],["Negate","_a"]],[["Add",["Negate","_x"],"_a"],"_a"],[["Add",["Multiply","_x","_a"],"_b"],["Divide",["Negate","_b"],"_a"]],[["Add",["Multiply",["Power","_x",2],"_a"],["Multiply","_x","_b"],"_c"],["Divide",["Add",["Negate","_b"],["Sqrt",["Subtract",["Square","_b"],["Multiply",4,"_a","_c"]]]],["Multiply",2,"_a"]]],[["Add",["Multiply",["Power","_x",2],"_a"],["Multiply","_x","_b"],"_c"],["Divide",["Subtract",["Negate","_b"],["Sqrt",["Subtract",["Square","_b"],["Multiply",4,"_a","_c"]]]],["Multiply",2,"_a"]]],[["Add",["Multiply",["Power","_x",2],"_a"],["Multiply","_x","_b"]],0],[["Add",["Multiply",["Power","_x",2],"_a"],["Multiply","_x","_b"]],["Divide",["Negate","_b"],"_a"]],[["Add",["Multiply",["Power","_x",2],"_a"],"_b"],["Sqrt",["Divide",["Negate","_b"],"_a"]]],[["Add",["Multiply",["Power","_x",2],"_a"],"_b"],["Negate",["Sqrt",["Divide",["Negate","_b"],"_a"]]]]];function Rt(e,i){const n=e.engine;"Equal"===e.head&&(e=n.add([e.op1.canonical,n.negate(e.op2.canonical)]).simplify());const t=n.cache("univariate-roots-rules",(()=>Qn(n,Lt))),r=function(e,i,n){const t=[];for(const r of i){const i=Yn(r,e,n);null!==i&&t.push(i)}return t}(Pt(e).subs({[i]:"_x"},{canonical:!1}),t,{_x:n.symbol("_x")});return r.map((e=>e.canonical.evaluate()))}function zt(e){return"Element"===e.head?function(e){var i;const n=e.engine,t=function(e){const i=e.symbols;return 0===i.length?[]:i.filter((i=>!$t(e.engine,i.symbol))).map((e=>e.symbol))}(e.op1);if(1===t.length){const i=n.domain(e.op2.evaluate().json);return i.isValid?(i.isCompatible("Function")?n.defineFunction({name:t[0]}):n.defineSymbol({name:t[0],domain:i}),"ok"):"not-a-predicate"}if(e.op1.symbol&&$t(n,e.op1.symbol)){const t=n.domain(e.op2.evaluate().json);if(!t.isValid)return"not-a-predicate";const r=n.lookupSymbol(e.op1.symbol);if(r)return r.domain&&!t.isCompatible(r.domain)?"contradiction":(r.domain=t,"ok");const s=n.lookupFunction(e.op1.symbol);return(null===(i=null==s?void 0:s.signature)||void 0===i?void 0:i.domain)?t.isCompatible(s.signature.domain)?t.isCompatible(s.signature.domain,"bivariant")?"tautology":"not-a-predicate":"contradiction":"ok"}if(t.length>0)return n.assumptions.set(e,!0),"ok";const r=e.evaluate();return"True"===r.symbol?"tautology":"False"===r.symbol?"contradiction":"not-a-predicate"}(e):"Equal"===e.head?function(e){const i=Vt(e);if(0===i.length){const i=e.evaluate();return"True"===i.symbol?"tautology":"False"===i.symbol?"contradiction":"not-a-predicate"}const n=e.engine,t=e.op1.symbol;if(t&&!jt(n,t)&&!e.op2.has(t)){const i=e.op2.evaluate();if(!i.isValid)return"not-a-predicate";const r=n.lookupSymbol(t);return r?r.domain&&!i.domain.isCompatible(r.domain)?"contradiction":(r.value=i,"ok"):(n.defineSymbol({name:t,value:i}),"ok")}if(1===i.length){const t=i[0],r=Rt(e,t);0===r.length&&n.assumptions.set(n.box(["Equal",n.add([e.op1.canonical,n.negate(e.op2.canonical)]).simplify(),0]),!0);const s=1===r.length?r[0]:n.box(["List",...r]),o=n.lookupSymbol(t);return o?o.domain&&!r.every((e=>s.domain.isCompatible(e.domain)))?"contradiction":(o.value=s,"ok"):(n.defineSymbol({name:t,value:s}),"ok")}return n.assumptions.set(e,!0),"ok"}(e):function(e){const i=e.head;return"string"==typeof i&&["Less","Greater","LessEqual","GreaterEqual"].includes(i)}(e)?function(e){const i=e.engine;if(e.op1.symbol&&!$t(i,e.op1.symbol))return e.op2.evaluate().isZero?"Less"===e.head?i.defineSymbol({name:e.op1.symbol,domain:i.domain("NegativeNumber")}):"LessEqual"===e.head?i.defineSymbol({name:e.op1.symbol,domain:i.domain("NonPositiveNumber")}):"Greater"===e.head?i.defineSymbol({name:e.op1.symbol,domain:i.domain("PositiveNumber")}):"GreaterEqual"===e.head&&i.defineSymbol({name:e.op1.symbol,domain:i.domain("NonNegativeNumber")}):(i.defineSymbol({name:e.op1.symbol,domain:i.domain("ExtendedRealNumber")}),i.assumptions.set(e,!0)),"ok";let n,t,r="";if("Less"===e.head?(n=e.op1,t=e.op2,r="<"):"LessEqual"===e.head?(n=e.op1,t=e.op2,r="<="):"Greater"===e.head?(n=e.op2,t=e.op1,r="<"):"GreaterEqual"===e.head&&(n=e.op2,t=e.op1,r="<="),!r)return"internal-error";const s=i.add([n.canonical,i.negate(t.canonical)]).simplify(),o=Vt(s),a=i.box(["<"===r?"Less":"LessEqual",s,0]).evaluate();return 0===o.length?"True"===a.symbol?"tautology":"False"===a.symbol?"contradiction":"not-a-predicate":(1===o.length&&i.defineSymbol({name:o[0],domain:"ExtendedRealNumber"}),i.assumptions.set(a,!0),"ok")}(e):"not-a-predicate"}function $t(e,i){var n;return void 0!==(null!==(n=e.lookupSymbol(i))&&void 0!==n?n:e.lookupFunction(i))}function Vt(e){const i=e.symbols;return 0===i.length?[]:i.filter((i=>!jt(e.engine,i.symbol))).map((e=>e.symbol))}function jt(e,i){var n;return!e.lookupFunction(i)&&void 0!==(null===(n=e.lookupSymbol(i))||void 0===n?void 0:n.value)}class Gt{constructor(e,i){this.engine=e,void 0!==(null==i?void 0:i.latex)&&(this._latex=i.latex),void 0!==(null==i?void 0:i.wikidata)&&(this._wikidata=i.wikidata)}valueOf(){var e,i,n;return"True"===this.symbol||"False"!==this.symbol&&(null!==(n=null!==(i=null!==(e=Dn(this))&&void 0!==e?e:this.string)&&void 0!==i?i:this.symbol)&&void 0!==n?n:JSON.stringify(this.json))}toString(){if(this.symbol)return this.symbol;if(this.string)return this.string;const e=this.numericValue;if(null!==e){if("number"==typeof e)return e.toString();if(mt(e))return`${e[0].toString()}/${e[1].toString()}`;if(dt(e))return`${e[0].toString()}/${e[1].toString()}`;if(e instanceof Be.exports.Complex){const i=1===e.im?"":-1===e.im?"-":e.im.toString();return 0===e.re?i+"i":e.im<0?`${e.re.toString()}${i}i`:`${e.re.toString()}+${i}i`}}return JSON.stringify(this.json)}[Symbol.toPrimitive](e){if("number"===e){const e=this.valueOf();return"number"==typeof e?e:null}return this.toString()}toJSON(){return this.json}get scope(){return null}is(e){return null!=e&&this.isSame(this.engine.box(e))}get latex(){var e;return null!==(e=this._latex)&&void 0!==e?e:this.engine.serialize(this)}set latex(e){this._latex=e}get symbol(){return null}get isNothing(){return!1}get string(){return null}getSubexpressions(e){return Zn(this,e)}get subexpressions(){return this.getSubexpressions("")}get symbols(){return[...Gn(this,new Set)].map((e=>this.engine.symbol(e,{canonical:!1})))}get errors(){return this.getSubexpressions("Error")}get ops(){return null}get nops(){return 0}get op1(){return this.engine.symbol("Nothing")}get op2(){return this.engine.symbol("Nothing")}get op3(){return this.engine.symbol("Nothing")}get isValid(){return!0}get isPure(){return!1}get isExact(){return!0}get isFree(){return!1}get isConstant(){return!1}get canonical(){return this}apply(e,i){return this}subs(e,i){return(null==i?void 0:i.canonical)?this.canonical:this}solve(e){return null}replace(e){return null}has(e){return!1}get isNaN(){}get isZero(){}get isNotZero(){}get isOne(){}get isNegativeOne(){}get isInfinity(){}get isFinite(){}get isEven(){}get isOdd(){}get isPrime(){}get isComposite(){}get numericValue(){return null}get sgn(){return null}isLess(e){}isLessEqual(e){}isGreater(e){}isGreaterEqual(e){}get isPositive(){}get isNonNegative(){}get isNegative(){}get isNonPositive(){}isCompatible(e,i){return!1}get description(){}get url(){}get isLiteral(){return!1}get wikidata(){return this._wikidata}set wikidata(e){this._wikidata=e}get complexity(){}get basedDefinition(){}get symbolDefinition(){}get functionDefinition(){}bind(e){}unbind(){}get keys(){return null}get keysCount(){return 0}getKey(e){}hasKey(e){return!1}get value(){}set value(e){throw Error(`Can't change the value of \\(${this.latex}\\)`)}get domain(){return this.engine.domain("Void")}set domain(e){throw Error(`Can't change the domain of \\(${this.latex}\\)`)}get explicitDomain(){return this.domain}get isNumber(){}get isInteger(){}get isRational(){}get isAlgebraic(){return!1}get isReal(){}get isExtendedReal(){}get isComplex(){}get isImaginary(){}get isExtendedComplex(){}simplify(e){return this}evaluate(e){return this.simplify(e)}N(e){return this.evaluate()}}function Zt(e){if("Power"===e.head&&e.op2.isLiteral){const i=Ln(e.op2);return null!==i&&i>0?i:1}if("Multiply"===e.head){let i=1;for(const n of e.ops){const e=Zt(n);e>1&&(i+=e)}return i}return 1}function Bt(e){if("Power"===e.head&&e.op2.isLiteral){const i=Ln(e.op2);return null!==i&&i>0?i:1}if("Multiply"===e.head){let i=1;for(const n of e.ops)i=Math.max(i,Zt(n));return i}return 1}function Ut(e){return e.symbol?e.symbol:e.ops?e.ops.map((e=>Ut(e))).filter((e=>e.length>0)).join('"'):""}const Ht=1e5;function Wt(e,i){return i.sort(((e,i)=>{const n=Ut(e),t=Ut(i);if(n<t)return-1;if(n>t)return 1;const r=Zt(e),s=Zt(i);if(r!==s)return s-r;const o=Bt(e),a=Bt(i);return o!==a?o-a:Qt(e,i)}))}function Qt(e,i){var n,t,r,s,o,a,l,u;const c=Dn(e);if(e.isLiteral&&null!==c){const e=Dn(i);return i.isLiteral&&null!==e?c-e:-1}if(e.isLiteral&&e.numericValue instanceof Ue)return i.isLiteral&&i.numericValue instanceof Ue?e.numericValue.re===i.numericValue.re?Math.abs(e.numericValue.im)===Math.abs(i.numericValue.im)?e.numericValue.im-i.numericValue.im:Math.abs(e.numericValue.im)-Math.abs(i.numericValue.im):e.numericValue.re-i.numericValue.re:i.isLiteral&&i.isNumber?1:-1;if(e.symbol)return i.symbol?e.symbol===i.symbol?0:e.symbol>i.symbol?1:-1:i.isLiteral&&i.isNumber?1:-1;if(e.ops){if(i.ops){const o=null!==(t=null===(n=e.functionDefinition)||void 0===n?void 0:n.complexity)&&void 0!==t?t:Ht,a=null!==(s=null===(r=i.functionDefinition)||void 0===r?void 0:r.complexity)&&void 0!==s?s:Ht;return o===a?"string"==typeof e.head&&"string"==typeof i.head?e.head===i.head?Yt(e)-Yt(i):e.head<i.head?1:-1:Yt(e)-Yt(i):o-a}return i.isLiteral&&i.isNumber||i.symbol?1:-1}if(e.string)return i.string?e.string.length!==i.string.length?i.string.length-e.string.length:i.string<e.string?-1:e.string>i.string?1:0:i.keys?-1:1;if(e.keys&&i.keys){if(e.keysCount!==i.keysCount)return i.keysCount-e.keysCount;let n=0,t=0;for(const e of i.keys)n+=null!==(o=i.getKey(e).complexity)&&void 0!==o?o:Ht;for(const i of e.keys)t+=null!==(a=e.getKey(i).complexity)&&void 0!==a?a:Ht;return t-n}return(null!==(l=e.complexity)&&void 0!==l?l:Ht)-(null!==(u=i.complexity)&&void 0!==u?u:Ht)}function Yt(e){return null!==e.keys?1+e.keysCount:e.ops?("string"==typeof e.head?1:Yt(e.head))+[...e.ops].reduce(((e,i)=>e+Yt(i)),0):1}class Jt{constructor(e,i,n){if(this._terms=[],this._hasInfinity=!1,this._hasZero=!1,this._isCanonical=!0,null!=n||(n={}),"canonical"in n||(n.canonical=!0),this._isCanonical=n.canonical,this.engine=e,this._sign=1,this._rational=Bn(e)?[e._BIGNUM_ONE,e._BIGNUM_ONE]:[1,1],this._complex=Ue.ONE,this._bignum=e._BIGNUM_ONE,this._number=1,i)for(const e of i)this.addTerm(e)}get isEmpty(){return this._isCanonical?0===this._terms.length&&!1===this._hasInfinity&&!1===this._hasZero&&1===this._sign&&gt(this._rational)&&1===this._complex.re&&0===this._complex.im&&this._bignum.eq(this.engine._BIGNUM_ONE)&&1===this._number:0===this._terms.length}addTerm(e){if(this._isCanonical){if(e.isNothing)return;if(e.isLiteral){if(e.isOne)return;if(e.isZero)return void(this._hasZero=!0);if(e.isNegativeOne)return void(this._sign*=-1);if(e.isInfinity)return this._hasInfinity=!0,void(e.isNegative&&(this._sign*=-1));let i=e.numericValue;if("number"==typeof i)return i<0&&(this._sign*=-1),i=Math.abs(i),void(Number.isInteger(i)?this._rational=kt(this._rational,[i,1]):Bn(this.engine)?this._bignum=this._bignum.mul(i):this._number*=i);if(i instanceof Ge)return i.isNegative()&&(this._sign*=-1,i=i.neg()),void(i.isInteger()?this._rational=kt(this._rational,[i,this.engine._BIGNUM_ONE]):Bn(this.engine)?this._bignum=this._bignum.mul(i):this._number*=i.toNumber());if(i instanceof Ue)return void(this._complex=this._complex.mul(i));if(ht(i))return this._rational=kt(this._rational,i),void(yt(this._rational)&&(this._sign*=-1,this._rational=Nt(this._rational)))}}let i=e;if(this._isCanonical){let n;[n,i]=It(e),this._rational=kt(this._rational,n),yt(this._rational)&&(this._sign*=-1,this._rational=Nt(this._rational))}if(i.isLiteral&&i.isOne)return;let n=[1,1];if("Power"===i.head&&i.op2.isLiteral){const e=xt(i.op2);e&&(n=e,i=i.op1)}let t=!1;for(const e of this._terms)if(e.term.isSame(i)){e.exponent=wt(e.exponent,n),t=!0;break}t||this._terms.push({term:i,exponent:n})}unitTerms(e){const i=this.engine;if("numeric"===e){if(!Un(i)&&0!==this._complex.im)return null;if(Bn(i)){let e=i._BIGNUM_ONE;if(gt(this._rational)||(e=dt(this._rational)?this._rational[0].div(this._rational[1]):i.bignum(this._rational[0]).div(this._rational[1])),e=e.mul(this._bignum).mul(this._sign*this._number),0!==this._complex.im){const n=this._complex.mul(e.toNumber());return n.equals(1)?[]:[{exponent:[1,1],terms:[i.number(n)]}]}return e=e.mul(this._complex.re),e.equals(1)?[]:[{exponent:[1,1],terms:[i.number(e)]}]}{let e=1;if(gt(this._rational)||(e=dt(this._rational)?this._rational[0].toNumber()/this._rational[1].toNumber():this._rational[0]/this._rational[1]),e*=this._sign*this._number*this._bignum.toNumber(),0!==this._complex.im){const n=this._complex.mul(e);return n.equals(1)?[]:[{exponent:[1,1],terms:[i.number(n)]}]}return e*=this._complex.re,1===e?[]:[{exponent:[1,1],terms:[i.number(e)]}]}}const n=[],t=[];this._hasInfinity&&t.push(i._POSITIVE_INFINITY),this._rational=At(this._rational),1===this._complex.re&&0===this._complex.im||(0===this._complex.im&&(this._number*=Math.abs(this._complex.re)),this._complex.re<0?this._rational=Nt(this._rational):t.push(i.number(this._complex)));let r=this._sign*this._number,s=this._bignum;return gt(this._rational)||("rational"===e?(1!==vt(this._rational)&&(dt(this._rational)?s=s.mul(this._rational[0]):r*=this._rational[0]),1!==bt(this._rational)&&n.push({exponent:[-1,1],terms:[i.number(this._rational[1])]})):t.push(i.number(this._rational))),s.equals(i._BIGNUM_ONE)?1!==r&&t.push(i.number(r)):t.push(i.number(s.mul(r))),t.length>0&&n.push({exponent:[1,1],terms:t}),n}groupedByDegrees(e){var i;null!=e||(e={}),"mode"in e||(e.mode="expression");const n=this.engine;if("numeric"===e.mode){if(0!==this._complex.im&&!Un(n))return null;if(this._hasInfinity)return[{exponent:[1,1],terms:[n._POSITIVE_INFINITY]}]}const t=this.unitTerms(null!==(i=e.mode)&&void 0!==i?i:"expression");if(null===t)return null;for(const e of this._terms){const i=At(e.exponent);if(0===i[0])continue;let n=!1;for(const r of t)if(i[0]===r.exponent[0]&&i[1]===r.exponent[1]){r.terms.push(e.term),n=!0;break}n||t.push({exponent:i,terms:[e.term]})}return t}asExpression(e="evaluate"){var i;const n=this.engine;if(this._hasInfinity){if(this._hasZero)return n._NAN;if(0===this._terms.length)return vt(this._rational)>0?n._POSITIVE_INFINITY:n._NEGATIVE_INFINITY}if(this._hasZero)return n._ZERO;const t=this.groupedByDegrees({mode:"N"===e?"numeric":"expression"});if(null===t)return n._NAN;let r=er(n,t);return r=null!==(i=Kn(r,"Multiply"))&&void 0!==i?i:r,0===r.length?n._ONE:1===r.length?r[0]:this.engine._fn("Multiply",r)}asNumeratorDenominator(){var e,i;const n=this.groupedByDegrees({mode:"rational"});if(null===n)return[this.engine._NAN,this.engine._NAN];const t=[],r=[];for(const e of n)"number"==typeof e.exponent[0]&&e.exponent[0]>=0||"number"!=typeof e.exponent[0]&&e.exponent[0].isPositive()?t.push(e):r.push({exponent:Nt(e.exponent),terms:e.terms});const s=this.engine;let o=er(s,t);o=null!==(e=Kn(o,"Multiply"))&&void 0!==e?e:o;let a=s._ONE;1===o.length?a=o[0]:o.length>0&&(a=s._fn("Multiply",o));let l=er(s,r);l=null!==(i=Kn(l,"Multiply"))&&void 0!==i?i:l;let u=s._ONE;return 1===l.length?u=l[0]:l.length>0&&(u=s._fn("Multiply",l)),[a,u]}asRationalExpression(){const[e,i]=this.asNumeratorDenominator();if(i.isLiteral){if(i.isOne)return e;if(i.isNegativeOne)return this.engine.negate(e)}return this.engine._fn("Divide",[e,i])}}function Kt(e){if(gt(e))return 0;const[i,n]=[vt(e),bt(e)];return i>0&&Number.isInteger(i/n)?1:i>0?2:Number.isInteger(i/n)?3:4}function Xt(e,i){const n=Kt(e.exponent),t=Kt(i.exponent);return n!==t?n-t:dt(e.exponent)&&dt(i.exponent)?e.exponent[0].div(e.exponent[1]).sub(i.exponent[0].div(i.exponent[1])).toNumber():dt(e.exponent)&&mt(i.exponent)?e.exponent[0].div(e.exponent[1]).sub(i.exponent[0]/i.exponent[1]).toNumber():mt(e.exponent)&&dt(i.exponent)?i.exponent[0].div(i.exponent[1]).add(-e.exponent[0]/e.exponent[1]).toNumber():e.exponent[0]/e.exponent[1]-i.exponent[0]/i.exponent[1]}function er(e,i){var n;const t=(i=i.sort(Xt)).map((i=>{var n;const t=null!==(n=Kn(i.terms,"Multiply"))&&void 0!==n?n:i.terms,r=t.length<=1?t[0]:e._fn("Multiply",t.sort(Qt));return gt(i.exponent)?r:e.power(r,i.exponent)}));return null!==(n=Kn(t,"Multiply"))&&void 0!==n?n:t}function ir(e,i,n,t){if(i.isLiteral){if(ht(i.numericValue))return vt(i.numericValue)<0?nr(e,"Subtract",[n,e.number(Nt(i.numericValue))],t):null;const r=Ln(i);if(null!==r&&r<0)return nr(e,"Subtract",[n,e.number(-r)],t)}return"Negate"===i.head?nr(e,"Subtract",[n,i.op1],t):null}function nr(e,i,n,t){var r;const s=e.jsonSerializationOptions.exclude;if(("Rational"===i||"Divide"===i)&&2===n.length&&1===Ln(n[0])&&2===Ln(n[1])&&!s.includes("Half"))return tr(e,"Half",Object.assign(Object.assign({},t),{wikidata:"Q39373172"}));if(1===n.length){const t=n[0].numericValue;if("Negate"===i&&null!==t){if("number"==typeof t)return rr(e,-t);if(t instanceof Ge)return rr(e,t.neg());if(t instanceof Be.exports.Complex)return rr(e,t.neg());if(ht(t))return rr(e,Nt(t))}}if("string"==typeof i&&s.includes(i)){if("Rational"===i&&2===n.length)return nr(e,"Divide",n,t);if("Complex"===i&&2===n.length)return nr(e,"Add",[n[0],e._fn("Multiply",[n[1],e.symbol("ImaginaryUnit")])],t);if("Sqrt"===i&&1===n.length)return nr(e,"Power",[n[0],s.includes("Half")?e.number([1,2]):e._HALF],t);if("Root"===i&&2===n.length&&n[1].isLiteral){const i=Ln(n[1]);if(2===i)return nr(e,"Sqrt",[n[0]]);if(null!==i)return i<0?nr(e,"Divide",[e._ONE,e._fn("Power",[n[0],e.number([1,-i])])],t):nr(e,"Power",[n[0],e.number([1,-i])],t)}if("Square"===i&&1===n.length)return nr(e,"Power",[n[0],e.number(2)],t);if("Exp"===i&&1===n.length)return nr(e,"Power",[e.symbol("ExponentialE"),n[0]],t);if("Subtract"===i&&2===n.length)return nr(e,"Add",[n[0],e._fn("Negate",[n[1]])],t);if("Subtract"===i&&1===n.length)return nr(e,"Negate",n,t)}if("Add"===i&&2===n.length&&!s.includes("Subtract")){if(n[1].isLiteral){const i=Ln(n[1]);if(null!==i&&i<0)return nr(e,"Subtract",[n[0],e.number(-i)],t)}if("Negate"===n[1].head)return nr(e,"Subtract",[n[0],n[1].op1],t)}if("Tuple"===i){if(1===n.length&&!s.includes("Single"))return nr(e,"Single",n,t);if(2===n.length&&!s.includes("Pair"))return nr(e,"Pair",n,t);if(3===n.length&&!s.includes("Triple"))return nr(e,"Triple",n,t)}const o=["string"==typeof i?i:i.json,...n.map((e=>e.json))],a=Object.assign({},null!=t?t:{});return e.jsonSerializationOptions.metadata.includes("latex")?a.latex=null!==(r=a.latex)&&void 0!==r?r:e.serialize({fn:o}):a.latex="",e.jsonSerializationOptions.metadata.includes("wikidata")||(a.wikidata=""),a.latex||a.wikidata||!e.jsonSerializationOptions.shorthands.includes("function")?a.latex&&a.wikidata?{fn:o,latex:a.latex,wikidata:a.wikidata}:a.latex?{fn:o,latex:a.latex}:a.wikidata?{fn:o,wikidata:a.wikidata}:{fn:o}:o}function tr(e,i,n){var t,r;if("Half"===i&&e.jsonSerializationOptions.exclude.includes("Half"))return rr(e,[1,2],n);if(n=Object.assign({},n),e.jsonSerializationOptions.metadata.includes("latex")?(n.latex=null!==(t=n.latex)&&void 0!==t?t:e.serialize({sym:i}),void 0!==n.latex&&(n.latex=n.latex)):n.latex=void 0,e.jsonSerializationOptions.metadata.includes("wikidata")){if(void 0===n.wikidata){const t=null===(r=e.lookupSymbol(i))||void 0===r?void 0:r.wikidata;void 0!==t&&(n.wikidata=t)}}else n.wikidata=void 0;return void 0===n.latex&&void 0===n.wikidata&&e.jsonSerializationOptions.shorthands.includes("symbol")?i:void 0!==n.latex&&void 0!==n.wikidata?{sym:i,latex:n.latex,wikidata:n.wikidata}:void 0!==n.latex?{sym:i,latex:n.latex}:void 0!==n.wikidata?{sym:i,wikidata:n.wikidata}:{sym:i}}function rr(e,i,n){var t,r,s;n=Object.assign({},n),e.jsonSerializationOptions.metadata.includes("latex")||(n.latex=void 0);const o=void 0===n.latex&&void 0===n.wikidata&&!e.jsonSerializationOptions.metadata.includes("latex")&&e.jsonSerializationOptions.shorthands.includes("number");let a="";if(i instanceof Ge){if(i.isNaN())a="NaN";else if(i.isFinite()){if(o&&ct(i))return i.toNumber();if(i.isInteger()&&i.e<i.precision()+4)a=i.toFixed(0);else{const n=e.jsonSerializationOptions.precision;if(a=sr(e,"max"===n?i.toString():i.toPrecision("auto"===n?e.precision:n)),o){const e=i.toNumber();if(e.toString()===a)return e}}}else a=i.isPositive()?"+Infinity":"-Infinity";return e.jsonSerializationOptions.metadata.includes("latex")&&(n.latex=null!==(t=n.latex)&&void 0!==t?t:e.serialize({num:a})),void 0!==n.latex?{num:a,latex:n.latex}:o?a:{num:a}}if(i instanceof Be.exports.Complex)return i.isInfinite()?tr(e,"ComplexInfinity",n):i.isNaN()?(a="NaN",e.jsonSerializationOptions.metadata.includes("latex")&&(n.latex=null!==(r=n.latex)&&void 0!==r?r:e.serialize({num:a})),void 0!==n.latex?{num:a,latex:n.latex}:{num:a}):nr(e,"Complex",[e.number(i.re),e.number(i.im)],Object.assign(Object.assign({},n),{wikidata:"Q11567"}));if(ht(i))return o&&e.jsonSerializationOptions.shorthands.includes("function")&&mt(i)?["Rational",i[0],i[1]]:nr(e,"Rational",[e.number(i[0]),e.number(i[1])],Object.assign({},n));if(Number.isNaN(i))a="NaN";else if(Number.isFinite(i)){if(o)return i;a=sr(e,i.toString())}else a=i>0?"+Infinity":"-Infinity";return e.jsonSerializationOptions.metadata.includes("latex")&&(n.latex=null!==(s=n.latex)&&void 0!==s?s:e.serialize({num:a})),void 0!==n.latex?{num:a,latex:n.latex}:{num:a}}function sr(e,i){var n;if(!e.jsonSerializationOptions.repeatingDecimals)return i;let[t,r,s,o]=null!==(n=i.match(/^(.*)\.([0-9]+)([e|E][-+]?[0-9]+)?$/))&&void 0!==n?n:[];if(!s)return i.toLowerCase();const a=s[s.length-1];s=s.slice(0,-1);let l="";for(let e=0;e<s.length-16;e++){l=s.substring(0,e);for(let n=0;n<=16;n++){const t=s.substring(e,e+n+1),u=Math.floor((s.length-l.length)/t.length);if(u>1&&(l+t.repeat(u+1)).startsWith(s))return"0"===t?"0"===a?r+"."+l+(null!=o?o:""):i:r+"."+l+"("+t+")"+(null!=o?o:"")}}for(s+=a;s.endsWith("0");)s=s.slice(0,-1);return o?`${r}.${s}${o.toLowerCase()}`:`${r}.${s}`}class or extends Gt{constructor(e,i,n){var t;null!=n||(n={}),super(e,n.metadata),this._value=new Map;const r=null===(t=n.canonical)||void 0===t||t;for(const n of Object.keys(i))this._value.set(n,e.box(i[n],{canonical:r}));e._register(this)}unbind(){for(const[e,i]of this._value)i.unbind()}get hash(){let e=Hn("Dictionary");for(const[i,n]of this._value)e^=Hn(i)^n.hash;return e}get complexity(){return 97}get head(){return"Dictionary"}get isPure(){return!1}getKey(e){return this._value.get(e)}hasKey(e){return this._value.has(e)}get keys(){return this._value.keys()}get keysCount(){return this._value.size}has(e){for(const[i,n]of this._value)if(n.has(e))return!0;return!1}get domain(){const e=["Dictionary"];for(const[i,n]of this._value)e.push(["Tuple",i,n.domain]);return this.engine.domain(e)}get json(){if(this.engine.jsonSerializationOptions.shorthands.includes("dictionary")){const e={};for(const i of this._value.keys())e[i]=this._value.get(i).json;return{dict:e}}const e=[];for(const i of this._value.keys())e.push(this.engine._fn("KeyValuePair",[this.engine.string(i),this._value.get(i)]));return nr(this.engine,"Dictionary",e,{latex:this._latex})}isSame(e){if(this===e)return!0;if(!(e instanceof or))return!1;if(this._value.size!==e._value.size)return!1;for(const[i,n]of this._value){const t=e.getKey(i);if(!t||!n.isSame(t))return!1}return!0}match(e,i){if(!(e instanceof or))return null;if(this._value.size!==e._value.size)return null;let n={};for(const[i,t]of this._value){const r=e.getKey(i);if(!r)return null;const s=t.match(r);if(null===s)return null;n=Object.assign(Object.assign({},n),s)}return n}isEqual(e){if(this===e)return!0;if(!(e instanceof or))return!1;if(!e.keys||this._value.size!==e._value.size)return!1;for(const[i,n]of this._value){const t=e.getKey(i);if(!t||!n.isEqual(t))return!1}return!0}apply(e,i){const n={};for(const i of this.keys)n[i]=this.engine.box(e(this.getKey(i)));return i?this.engine.fn(i,[{dict:n}]):new or(this.engine,n)}evaluate(e){return this.apply((i=>{var n;return null!==(n=i.evaluate(e))&&void 0!==n?n:i}))}get isCanonical(){return this._isCanonical}set isCanonical(e){this._isCanonical=e}get canonical(){if(this.isCanonical)return this;const e=this.apply((e=>e.canonical));return e.isCanonical=!0,e}simplify(e){var i;return null===(i=null==e?void 0:e.recursive)||void 0===i||i?this.apply((i=>{var n;return null!==(n=i.simplify(e))&&void 0!==n?n:i})):this}N(e){return this.apply((i=>i.N(e)))}replace(e,i){let n=0;const t={};for(const r of this.keys){const s=this.getKey(r),o=s.replace(e,i);null!==o&&(n+=1),t[r]=null!=o?o:s}return 0===n?null:new or(this.engine,t)}subs(e,i){const n={};for(const t of this.keys)n[t]=this.getKey(t).subs(e,i);return new or(this.engine,n,i)}}const ar=[];function lr(e,i){if(null==i)return e;if(e===i)return e;const n=e.engine,t=n.box(i);return n.costFunction(t)<=1.7*n.costFunction(e)?t:e}class ur extends Gt{constructor(e,i,n,t){var r,s,o,a,l;if(null!=t||(t={}),null!==(r=t.canonical)&&void 0!==r||(t.canonical=!1),super(e,t.metadata),this._scope=e.context,this._head=i,this._ops=n,this._def=null!==(s=t.def)&&void 0!==s?s:null,t.canonical&&(this._def||(this._def=e.lookupFunction(i,e.context)),this._canonical=this),this._codomain=null,t.canonical){if("string"!=typeof this._head)this._codomain=this._head.domain.codomain;else if(this._def){const i=this._def.signature;"function"==typeof i.codomain?this._codomain=null!==(o=i.codomain(e,this._ops))&&void 0!==o?o:null:this._codomain=null!==(a=i.codomain)&&void 0!==a?a:null}this._codomain||(this._codomain=null!==(l=e.defaultDomain)&&void 0!==l?l:e.domain("Void"))}else this._codomain=e.domain("Anything");e._register(this)}get hash(){if(void 0!==this._hash)return this._hash;let e=0;for(const i of this._ops)e=e<<1^i.hash|0;return e="string"==typeof this._head?e^Hn(this._head)|0:e^this._head.hash|0,this._hash=e,e}get isCanonical(){return this._canonical===this}set isCanonical(e){this._canonical=e?this:void 0}get isLiteral(){return!1}get isPure(){var e;if(!this.isCanonical)return!1;if(void 0!==this._isPure)return this._isPure;let i;return void 0!==(null===(e=this.functionDefinition)||void 0===e?void 0:e.pure)&&(i=this.functionDefinition.pure),!1!==i&&(i=this._ops.every((e=>e.isPure))),this._isPure=i,i}get json(){return this.isValid&&this._canonical===this?function(e,i,n,t){var r,s,o,a;const l=e.jsonSerializationOptions.exclude;if("Add"===i&&2===n.length&&!l.includes("Subtract")){const i=null!==(r=ir(e,n[0],n[1],t))&&void 0!==r?r:ir(e,n[1],n[0],t);if(i)return i}if("Divide"===i&&2===n.length&&l.includes("Divide"))return nr(e,"Multiply",[n[0],e._fn("Power",[n[1],e._NEGATIVE_ONE])],t);if("Multiply"===i&&!l.includes("Negate")&&(null===(s=n[0])||void 0===s?void 0:s.isLiteral)&&-1===Dn(n[0]))return nr(e,"Negate",[e._fn("Multiply",n.slice(1))],t);if("Multiply"===i&&!l.includes("Divide")){const i=new Jt(e,n,{canonical:!1}).asRationalExpression();if("Divide"===i.head)return nr(e,i.head,i.ops,t)}if("Power"===i){if(!l.includes("Exp")&&"ExponentialE"===(null===(o=n[0])||void 0===o?void 0:o.symbol))return nr(e,"Exp",[n[1]],t);if(null===(a=n[1])||void 0===a?void 0:a.isLiteral){const i=Ln(n[1]);if(2===i&&!l.includes("Square"))return nr(e,"Square",[n[0]],t);if(null!==i&&i<0&&!l.includes("Divide"))return nr(e,"Divide",[e._ONE,-1===i?n[0]:e.power(n[0],-i)],t);const r=n[1].numericValue;if(!l.includes("Sqrt")&&.5===r)return nr(e,"Sqrt",[n[0]],t);if(!l.includes("Sqrt")&&-.5===r)return nr(e,"Divide",[e._ONE,e._fn("Sqrt",[n[0]])],t);if(ht(r)){const i=vt(r),s=bt(r);if(1===i){if(!l.includes("Sqrt")&&2===s)return nr(e,"Sqrt",[n[0]],t);if(!l.includes("Root"))return nr(e,"Root",[n[0],e.number(r[1])],t)}if(-1===i){if(!l.includes("Sqrt")&&2===s)return nr(e,"Divide",[e._ONE,e._fn("Sqrt",[n[0]])],t);if(!l.includes("Root"))return nr(e,"Divide",[e._ONE,e._fn("Root",[n[0],e.number(r[1])])],t)}}}}return nr(e,i,n,t)}(this.engine,this._head,this._ops,{latex:this._latex,wikidata:this._wikidata}):nr(this.engine,this._head,this._ops,{latex:this._latex,wikidata:this._wikidata})}get scope(){return this._scope}get head(){return this._head}get ops(){return this._ops}get nops(){return this._ops.length}get op1(){var e;return null!==(e=this._ops[0])&&void 0!==e?e:this.engine.symbol("Nothing")}get op2(){var e;return null!==(e=this._ops[1])&&void 0!==e?e:this.engine.symbol("Nothing")}get op3(){var e;return null!==(e=this._ops[2])&&void 0!==e?e:this.engine.symbol("Nothing")}get isValid(){return"Error"!==this._head&&!("string"!=typeof this._head&&!this._head.isValid)&&this._ops.every((e=>e.isValid))}get canonical(){return this._canonical||(this._canonical=this.isValid?cr(this.engine,this._head,this._ops):this),this._canonical}*map(e){let i=0;for(;i<this._ops.length;)yield e(this._ops[i++])}subs(e,i){null!=i||(i={}),"canonical"in i||(i.canonical=!0);const n=this._ops.map((n=>n.subs(e,i)));return i.canonical&&n.every((e=>e.isValid))?cr(this.engine,this._head,n):new ur(this.engine,this._head,n,{canonical:!1})}replace(e,i){return Jn(this,e,i)}has(e){if("string"==typeof this._head)if("string"==typeof e){if(this._head===e)return!0}else if(e.includes(this._head))return!0;for(const i of this._ops)if(i.has(e))return!0;return!1}isSame(e){if(this===e)return!0;if(!(e instanceof ur))return!1;if(this.nops!==e.nops)return!1;if("string"==typeof this.head){if(this.head!==e.head)return!1}else{if("string"==typeof e.head)return!1;if(!e.head||!this.head.isSame(e.head))return!1}const i=this._ops,n=e._ops;for(let e=0;e<i.length;e++)if(!i[e].isSame(n[e]))return!1;return!0}match(e,i){if(!(e instanceof ur))return null;let n={};if("string"==typeof this.head){if(this.head!==e.head)return null}else{if("string"==typeof e.head)return null;{if(!e.head)return null;const t=this.head.match(e.head,i);if(null===t)return null;n=Object.assign(Object.assign({},n),t)}}const t=this._ops,r=e._ops;for(let e=0;e<t.length;e++){const s=t[e].match(r[e],i);if(null===s)return null;n=Object.assign(Object.assign({},n),s)}return n}unbind(){this._value=void 0,this._numericValue=void 0}get wikidata(){var e,i,n;if(this.isCanonical)return null!==(n=null!==(e=this._wikidata)&&void 0!==e?e:null===(i=this.functionDefinition)||void 0===i?void 0:i.wikidata)&&void 0!==n?n:void 0}get description(){if(!this.isCanonical)return;const e=this.functionDefinition;return e?e.description?"string"==typeof e.description?[e.description]:e.description:void 0:[]}get url(){var e,i;return this.isCanonical?null!==(i=null===(e=this.functionDefinition)||void 0===e?void 0:e.url)&&void 0!==i?i:void 0:""}get complexity(){var e,i;if(this.isCanonical)return null!==(i=null===(e=this.functionDefinition)||void 0===e?void 0:e.complexity)&&void 0!==i?i:Ht}get functionDefinition(){if(this.isCanonical)return null!==this._def?this._def:void 0}bind(e){}get value(){if(this.isCanonical&&this.isPure)return this._value||(this._value=this.evaluate()),this._value}isEqual(e){const i=Mt(this,e);return 0===i||void 0===i&&this.isSame(e)}isLess(e){const i=Mt(this,e);if(void 0!==i)return i<0}isLessEqual(e){const i=Mt(this,e);if(void 0!==i)return i<=0}isGreater(e){const i=Mt(this,e);if(void 0!==i)return i>0}isGreaterEqual(e){const i=Mt(this,e);if(void 0!==i)return i>=0}get isZero(){const e=this.sgn;return null!==e&&("number"==typeof e?0===e:void 0)}get isNotZero(){const e=this.sgn;return null!==e&&("number"==typeof e?0!==e:void 0)}get isOne(){return this.isEqual(this.engine._ONE)}get isNegativeOne(){return this.isEqual(this.engine._NEGATIVE_ONE)}get isPositive(){const e=this.sgn;return null!==e&&("number"==typeof e?e>0:void 0)}get isNonPositive(){const e=this.sgn;return null!==e&&("number"==typeof e?e<=0:void 0)}get isNegative(){const e=this.sgn;return null!==e&&("number"==typeof e?e<0:void 0)}get isNonNegative(){const e=this.sgn;return null!==e&&("number"==typeof e?e>=0:void 0)}get isNumber(){return this.domain.isCompatible("Number")}get isInteger(){return this.domain.isCompatible("Integer")}get isRational(){return this.domain.isCompatible("RationalNumber")}get isAlgebraic(){return this.domain.isCompatible("AlgebraicNumber")}get isReal(){return this.domain.isCompatible("RealNumber")}get isExtendedReal(){return this.domain.isCompatible("ExtendedRealNumber")}get isComplex(){return this.domain.isCompatible("ComplexNumber")}get isImaginary(){return this.domain.isCompatible("ImaginaryNumber")}get sgn(){var e,i,n,t,r,s,o,a;if(!this.isCanonical)return;const l=this.head;if("Negate"===l){const i=null===(e=this._ops[0])||void 0===e?void 0:e.sgn;if(void 0===i)return;return null===i?null:0===i?0:i>0?-1:1}if("Multiply"===l){const e=this._ops.reduce(((e,i)=>{var n;return e*(null!==(n=i.sgn)&&void 0!==n?n:NaN)}),1);return isNaN(e)?null:e>0?1:e<0?-1:0}if("Add"===l){let e=0,i=0,n=0;const t=this._ops.length;for(const t of this._ops){const r=t.sgn;if(null==r)break;0===r&&(n+=1),r>0&&(e+=1),r<0&&(i+=1)}return n===t?0:e===t?1:i===t?-1:null}if("Divide"===l){const e=null===(i=this._ops[0])||void 0===i?void 0:i.sgn,t=null===(n=this._ops[1])||void 0===n?void 0:n.sgn;return null===e||null===t||void 0===e||void 0===t?null:0===e?0:e>0&&t>0||e<0&&t<0?1:-1}if("Square"===l)return(null===(t=this._ops[0])||void 0===t?void 0:t.isImaginary)?-1:(null===(r=this._ops[0])||void 0===r?void 0:r.isZero)?0:1;if("Abs"===l)return(null===(s=this._ops[0])||void 0===s?void 0:s.isZero)?0:1;if("Sqrt"===l)return(null===(o=this._ops[0])||void 0===o?void 0:o.isZero)?0:(null===(a=this._ops[0])||void 0===a?void 0:a.isImaginary)?null:1;const u=Dn(this.N());return null!==u?0===u?0:u<0?-1:1:void 0}get domain(){return this._codomain}simplify(e){var i,n,t,r;if(!this.isValid)return this;if(!this.isCanonical)return this.canonical.simplify(e);const s=this.functionDefinition,o=mr(this._ops,null!==(i=null==s?void 0:s.hold)&&void 0!==i?i:"none",(null==s?void 0:s.associative)?s.name:"",(i=>i.simplify(e)));if("string"!=typeof this._head){const i=hr(this._head,o);return"string"!=typeof i.head?i:i.simplify(e)}let a;if(s)if(s.inert)a=null!==(t=null===(n=o[0])||void 0===n?void 0:n.canonical)&&void 0!==t?t:this;else{const e=s.signature;(null==e?void 0:e.simplify)&&(a=e.simplify(this.engine,o))}a||(a=this.engine.fn(this._head,o));const l=null!==(r=null==e?void 0:e.rules)&&void 0!==r?r:this.engine.cache("standard-simplification-rules",(()=>Qn(this.engine,ar)),(e=>{for(const[i,n,t,r]of e)i.unbind(),n.unbind();return e}));let u=0,c=!1;do{const e=a.replace(l);null!==e?(a=lr(e,a),a===e&&(c=!0)):c=!0,u+=1}while(!c&&u<this.engine.iterationLimit);return a}evaluate(e){var i,n,t;if(!this.isValid)return this;if(!this.isCanonical)return this.canonical.evaluate(e);const r=this.functionDefinition,s=mr(this._ops,null!==(i=null==r?void 0:r.hold)&&void 0!==i?i:"none",(null==r?void 0:r.associative)?r.name:"",(i=>i.evaluate(e)));if("string"!=typeof this._head){const i=hr(this._head,s);return"string"!=typeof i.head?i:i.evaluate(e)}if(!r)return this.engine.fn(this._head,s);if(r.inert)return null!==(n=s[0])&&void 0!==n?n:this;const o=r.signature;return o&&o.evaluate?"function"!=typeof o.evaluate?hr(o.evaluate,s):null!==(t=o.evaluate(this.engine,s))&&void 0!==t?t:this.engine.fn(this._head,s):this.engine.fn(this._head,s)}N(e){var i,n,t,r;if(!this.isValid)return this;if(!this.isCanonical)return this.canonical.N(e);if(this._numericValue)return this._numericValue;const s=this.functionDefinition,o=mr(this._ops,null!==(i=null==s?void 0:s.hold)&&void 0!==i?i:"none",(null==s?void 0:s.associative)?s.name:"",(i=>i.N(e)));if("string"!=typeof this._head){const i=hr(this._head,o);return"string"!=typeof i.head?i:i.N(e)}if(!s)return this.engine.fn(this._head,o);if(s.inert)return null!==(n=o[0])&&void 0!==n?n:this;const a=s.signature;let l=null!==(r=null===(t=null==a?void 0:a.N)||void 0===t?void 0:t.call(a,this.engine,o))&&void 0!==r?r:this.engine.fn(this._head,o).evaluate();const u=l.numericValue;return null!==u&&(!Un(this.engine)&&u instanceof Ue?l=this.engine._NAN:!Bn(this.engine)&&u instanceof Ge&&(l=this.engine.number(u.toNumber()))),this.isPure&&(this._numericValue=l),l}solve(e){return 1!==e.length?null:Rt(this.simplify(),e[0])}}function cr(e,i,n,t){var r,s,o;if("string"!=typeof i&&(i=null!==(r=i.evaluate().symbol)&&void 0!==r?r:i),"string"==typeof i){const r=function(e,i,n,t){var r;let s=[];if("Add"===i||"Multiply"===i)s=it(e,n);else if("Negate"===i||"Square"===i||"Sqrt"===i)s=it(e,n,1);else{if("Divide"!==i&&"Power"!==i)return null;s=it(e,n,2)}if(!s.every((e=>e.isValid)))return new ur(e,i,s,{metadata:t,canonical:!1});if("Add"===i)return e.add(s,t);if("Negate"===i)return e.negate(null!==(r=s[0])&&void 0!==r?r:e.error("missing"),t);if("Multiply"===i)return e.mul(s,t);if("Divide"===i)return e.divide(s[0],s[1],t);if("Power"===i)return e.power(s[0],s[1],t);if("Square"===i)return e.power(s[0],e.number(2),t);if("Sqrt"===i){const i=s[0].canonical;return i.isLiteral&&i.isRational?new ur(e,"Sqrt",[i],{metadata:t,canonical:!0}):e.power(i,e.number([1,2]),t)}return"Pair"===i?e.pair(s[0],s[1],t):"Tuple"===i?e.tuple(s,t):null}(e,i,n,t);if(r)return r}else if(!i.isValid)return new ur(e,i,n.map((i=>e.box(i,{canonical:!1}))),{metadata:t,canonical:!1});const a=e.lookupFunction(i,e.context);if("string"!=typeof i||!a)return new ur(e,i,Xn(n.map((i=>e.box(i)))),{metadata:t,canonical:!0});let l=[];for(let i=0;i<n.length;i++)if(dr(a.hold,n.length-1,i))l.push(e.box(n[i]));else{const t=e.box(n[i],{canonical:!1});"ReleaseHold"===t.head?l.push(t.op1.canonical):l.push(t)}const u=a.signature;if(u.canonical)return u.canonical(e,l)||new ur(e,i,l,{metadata:t,canonical:!1});if(l=Xn(l),a.associative&&(l=null!==(s=Kn(l,i))&&void 0!==s?s:l),!l.every((e=>e.isValid)))return new ur(e,i,l,{metadata:t,canonical:!1});if(l=null!==(o=nt(u.domain,l))&&void 0!==o?o:l,!l.every((e=>e.isValid)))return new ur(e,i,l,{metadata:t,canonical:!1});if(1===l.length&&l[0].head===i){if(a.involution)return l[0].op1;a.idempotent&&(l=l[0].ops)}return l.length>1&&!0===a.commutative&&(l=l.sort(Qt)),new ur(e,i,l,{metadata:t,def:a,canonical:!0})}function hr(e,i){var n;if("Lambda"!==e.head)return e.engine._fn(e.evaluate(),i);const t={__:e.engine.tuple(i),"_#":e.engine.number(i.length)};let r=1;for(const e of i)t["_"+r++]=e;t._=t._1;const s=this.context;this.context=null!==(n=e.scope)&&void 0!==n?n:null;const o=e.subs(t).evaluate();return this.context=s,o}function mr(e,i,n,t){var r,s;if(0===e.length)return[];n&&(e=null!==(r=Kn(e,n))&&void 0!==r?r:e);const o=[];for(let n=0;n<e.length;n++)if("Hold"===e[n].head)o.push(e[n]);else{let r;if("ReleaseHold"===e[n].head?r=e[n].op1:dr(i,e.length-1,n)?r=e[n]:o.push(e[n]),r){const e=t(r);null!==e&&o.push(e)}}return n&&null!==(s=Kn(o,n))&&void 0!==s?s:o}function dr(e,i,n){return"all"!==e&&("none"===e||("first"===e?0!==n:"rest"===e?0===n:"last"===e?n!==i:"most"===e&&n===i))}function fr(e){if(!Number.isInteger(e)||!Number.isFinite(e)||Number.isNaN(e)||e<=1)return!1;if(e<=7919)return An.has(e);for(const i of An)if(e%i==0)return!1;return e>=0x3ffffffffffe5?!!function(e,i){let n=0,t=e-1;for(;t%2==0;)t/=2,++n;e:do{let i=Math.pow(2+Math.floor(Math.random()*(e-3)),t)%e;if(1!==i&&i!==e-1){for(let t=n-1;t--;){if(i=i*i%e,1===i)return!1;if(i===e-1)continue e}return!1}}while(--i);return!0}(e,30)&&void 0:e===function(e){if(1===e)return 1;if(e%2==0)return 2;if(e%3==0)return 3;if(e%5==0)return 5;const i=Math.floor(Math.sqrt(e));let n=7;for(;n<=i;){if(e%n==0)return n;if(e%(n+4)==0)return n+4;if(e%(n+6)==0)return n+6;if(e%(n+10)==0)return n+10;if(e%(n+12)==0)return n+12;if(e%(n+16)==0)return n+16;if(e%(n+22)==0)return n+22;if(e%(n+24)==0)return n+24;n+=30}return e}(e)}class gr extends Gt{constructor(e,i,n){if(null!=n||(n={}),super(e,n.metadata),this._isCanonical=!0,ht(i)){"canonical"in n||(n.canonical=!0);const[t,r]=i;n.canonical?(this._value=pr(e,i),this._isCanonical=!0):(this._value=i,this._isCanonical=!1)}else this._value=pr(e,i),this._isCanonical=!0;e._register(this)}get hash(){if(void 0!==this._hash)return this._hash;let e=0;return e="number"==typeof this._value?Hn(this._value.toString()):this._value instanceof Be.exports.Complex?Hn(this._value.re.toString()+" +i "+this._value.im.toString()):this._value instanceof Ge?Hn(this._value.toString()):Hn(this._value[0].toString()+" / "+this._value[1].toString()),this._hash=e,e}get head(){return"Number"}get isPure(){return!0}get isLiteral(){return!0}get isExact(){return"number"==typeof this._value?Number.isInteger(this._value):this._value instanceof Ge?this._value.isInteger():this._value instanceof Be.exports.Complex?Number.isInteger(this._value.re)&&Number.isInteger(this._value.im):ht(this._value)}get isCanonical(){return this._isCanonical}set isCanonical(e){this._isCanonical=e}get complexity(){return 1}get value(){return this}get numericValue(){return this._value}get domain(){return void 0===this._domain&&(this._domain=this.engine.domain(function(e){if("number"==typeof e&&!isNaN(e))return isFinite(e)?Number.isInteger(e)?e>0?"PositiveInteger":e<0?"NegativeInteger":"Integer":e>0?"PositiveNumber":e<0?"NegativeNumber":"RealNumber":"ExtendedRealNumber";if(e instanceof Ge)return e.isNaN()?"Number":e.isFinite()?e.isInteger()?e.isPositive()?"PositiveInteger":e.isNegative()?"NegativeInteger":"Integer":e.isPositive()?"PositiveNumber":e.isNegative()?"NegativeNumber":"RealNumber":"ExtendedRealNumber";if(e instanceof Be.exports.Complex)return 0===e.re?"ImaginaryNumber":"ComplexNumber";if(Array.isArray(e)){const[i,n]=e;return"RationalNumber"}return"Number"}(this._value))),this._domain}get json(){return rr(this.engine,this._value,{latex:this._latex})}get sgn(){if(this.isZero)return 0;if(this._value instanceof Be.exports.Complex)return null;if("number"==typeof this._value)return this._value<0?-1:this._value>0?1:null;if(this._value instanceof Ge)return this._value.isNegative()?-1:this._value.isPositive()?1:null;if(Array.isArray(this._value)){const[e,i]=this._value;return 0===e&&0!==i?0:e<0?-1:e>0?1:null}return null}isSame(e){if(this===e)return!0;if(!(e instanceof gr))return!1;if(Array.isArray(this._value)){if(!Array.isArray(e._value))return!1;const[i,n]=e._value;return this._value[0]===i&&this._value[1]===n}return this._value instanceof Ge?e._value instanceof Ge&&this._value.eq(e._value):this._value instanceof Be.exports.Complex?e._value instanceof Be.exports.Complex&&this._value.equals(e._value):"number"==typeof this._value&&"number"==typeof e._value&&this._value===e._value}isEqual(e){if(this===e)return!0;const i=e.N();return i instanceof gr&&0===Mt(this.N(),i)}match(e,i){var n;return this.isEqualWithTolerance(e,null!==(n=null==i?void 0:i.numericTolerance)&&void 0!==n?n:0)?{}:null}isEqualWithTolerance(e,i){return e instanceof gr&&0===Mt(this,e,i)}isLess(e){const i=Mt(this,e);if(void 0!==i)return i<0}isLessEqual(e){const i=Mt(this,e);if(void 0!==i)return i<=0}isGreater(e){return e.isLessEqual(this)}isGreaterEqual(e){return e.isLess(this)}get isPositive(){const e=this.sgn;if(null!=e)return e>0}get isNonNegative(){const e=this.sgn;if(null!=e)return e>=0}get isNegative(){const e=this.sgn;if(null!=e)return e<0}get isNonPositive(){const e=this.sgn;if(null!=e)return e<=0}get isZero(){return 0===this._value||(this._value instanceof Ge||this._value instanceof Be.exports.Complex)&&this._value.isZero()}get isNotZero(){return"number"==typeof this._value&&0!==this._value||(this._value instanceof Ge?!this._value.isZero():!(this._value instanceof Be.exports.Complex&&this._value.isZero()))}get isOne(){return"number"==typeof this._value?1===this._value:this._value instanceof Ge?this._value.equals(this.engine._BIGNUM_ONE):this._value instanceof Be.exports.Complex?0===this._value.im&&1===this._value.re:gt(this._value)}get isNegativeOne(){return"number"==typeof this._value?-1===this._value:this._value instanceof Ge?this._value.equals(this.engine._BIGNUM_NEGATIVE_ONE):Array.isArray(this._value)?pt(this._value):this._value.equals(-1)}get isOdd(){return!(!this.isOne&&!this.isNegativeOne)||!this.isZero&&!!this.isInteger&&("number"==typeof this._value?this._value%2!=0:this._value instanceof Ge?!this._value.mod(2).isZero():void 0)}get isEven(){return!this.isOne&&!this.isNegativeOne&&(!!this.isZero||!!this.isInteger&&("number"==typeof this._value?this._value%2==0:this._value instanceof Ge?this._value.mod(2).isZero():void 0))}get isPrime(){return!(!this.isInteger||!this.isFinite||this.isNonPositive||this.isOne||this.isZero)&&("number"==typeof this._value?fr(this._value):this._value instanceof Ge?fr(this._value.toNumber()):void 0)}get isComposite(){return!(!this.isInteger||!this.isFinite||this.isNonPositive||this.isOne||this.isZero)&&("number"==typeof this._value?!fr(this._value):this._value instanceof Ge?!fr(this._value.toNumber()):void 0)}get isInfinity(){return"number"==typeof this._value?!Number.isFinite(this._value)&&!Number.isNaN(this._value):(this._value instanceof Ge||this._value instanceof Be.exports.Complex)&&!this._value.isFinite()&&!this._value.isNaN()}get isNaN(){return"number"==typeof this._value?Number.isNaN(this._value):(this._value instanceof Ge&&this._value.isNaN(),this._value instanceof Be.exports.Complex&&this._value.isNaN(),!1)}get isFinite(){return!this.isInfinity&&!this.isNaN}get isNumber(){return!0}get isInteger(){return"number"==typeof this._value?Number.isInteger(this._value):this._value instanceof Ge&&this._value.isInteger()}get isRational(){return!!Array.isArray(this._value)||this.isInteger}get isAlgebraic(){if(this.isRational)return!0}get isReal(){return!(!this.isFinite||this._value instanceof Be.exports.Complex&&0!==this.engine.chop(this._value.im))}get isExtendedReal(){return this.isInfinity||this.isReal}get isComplex(){return!this.isNaN}get isImaginary(){return this._value instanceof Be.exports.Complex}get isExtendedComplex(){return this.isInfinity||!this.isNaN}get canonical(){return this._isCanonical?this:this.engine.number(pr(this.engine,this._value))}simplify(e){return this.canonical}N(e){if(!Array.isArray(this._value))return this;const i=this.engine,[n,t]=this._value;return"number"!=typeof n||"number"!=typeof t||Bn(i)?i.number(i.bignum(n).div(t)):i.number(n/t)}}function pr(e,i){if(i instanceof Ge&&ct(i))return i.toNumber();if(!ht(i))return i;let[n,t]=i;if(n instanceof Ge&&t instanceof Ge){if(!ct(n)||!ct(t))return n.isNaN()||t.isNaN()?NaN:([n,t]=At([n,t]),t.isNegative()&&([n,t]=[n.neg(),t.neg()]),t.eq(e._BIGNUM_ONE)?n:t.isZero()?n.isZero()||!n.isFinite()?NaN:n.isNegative()?-1/0:1/0:[n,t]);[n,t]=[n.toNumber(),t.toNumber()]}return Number.isNaN(n)||Number.isNaN(t)?NaN:([n,t]=At([n,t]),t<0&&([n,t]=[-n,-t]),1===t?n:0===t?0!==n&&Number.isFinite(n)?n<0?-1/0:1/0:NaN:0===n?n:[n,t])}class vr extends Gt{constructor(e,i,n){super(e,n),this._string=i.normalize(),e._register(this)}get hash(){return Hn("String"+this._string)}get json(){return e=this.engine,i=this._string,e.jsonSerializationOptions.shorthands.includes("string")?`'${i}'`:{str:i};var e,i}get head(){return"String"}get isPure(){return!0}get isLiteral(){return!0}get isCanonical(){return!0}set isCanonical(e){}get domain(){return this.engine.domain("String")}get complexity(){return 19}get string(){return this._string}isEqual(e){return e.string===this._string}isSame(e){return e.string===this._string}match(e,i){return e instanceof vr&&this._string===e._string?{}:null}}function br(e,i,n){var t;if("number"==typeof i||i instanceof Ge)return new gr(e,i,n);if(null!=n||(n={}),"canonical"in n||(n.canonical=!0),ht(i)){if(2!==i.length)throw Error("Array argument to `boxNumber()` should be two integers or two bignums");const[t,r]=i;if(t instanceof Ge&&r instanceof Ge){if(!t.isInteger()||!r.isInteger())throw Error("Array argument to `boxNumber()` should be two integers");return t.eq(r)?r.isZero()?e._NAN:e._ONE:r.eq(1)?e.number(t,n):r.eq(-1)?e.number(t.negated(),n):t.eq(1)&&r.eq(2)?e._HALF:new gr(e,[t,r],n)}if("number"!=typeof t||"number"!=typeof r)throw Error("Array argument to `boxNumber()` should be two integers or two bignums");if(!Number.isInteger(t)||!Number.isInteger(r))throw Error("Array argument to `boxNumber()` should be two integers");return r===t?0===r?e._NAN:e._ONE:1===r?e.number(t,n):-1===r?e.number(-t,n):1===t&&2===r?e._HALF:new gr(e,[t,r],n)}if(i instanceof Be.exports.Complex)return i.isNaN()?e._NAN:i.isZero()?e._ZERO:i.isInfinite()?e._COMPLEX_INFINITY:0===e.chop(i.im)?e.number(i.re,n):new gr(e,i,n);let r="";if("string"==typeof i)r=i;else if("object"==typeof i&&"num"in i){if("number"==typeof i.num)return e.number(i.num,n);if("string"!=typeof i.num)throw Error("MathJSON `num` property should be a string of digits");r=i.num}if(r){if(r=r.toLowerCase(),/[0-9][nd]$/.test(r)&&(r=r.slice(0,-1)),r=r.replace(/[\u0009-\u000d\u0020\u00a0]/g,""),"nan"===r)return e._NAN;if("infinity"===r||"+infinity"===r)return e._POSITIVE_INFINITY;if("-infinity"===r)return e._NEGATIVE_INFINITY;if("0"===r)return e._ZERO;if("1"===r)return e._ONE;if("-1"===r)return e._NEGATIVE_ONE;if(/\([0-9]+\)/.test(r)){const[i,n,s,o]=null!==(t=r.match(/(.+)\(([0-9]+)\)(.+)?$/))&&void 0!==t?t:[];r=n+s.repeat(Math.ceil(e.precision/s.length))+(null!=o?o:"")}return br(e,e.bignum(r),n)}return null}function yr(e,i,n){if(null===i)return e.error("missing");if("object"==typeof i&&i instanceof Gt)return i;if("string"==typeof(i=ki(i)))return _r(e,i,n);if(Array.isArray(i)){const t=i.map((i=>yr(e,i,n)));return new ur(e,t[0],t.slice(1))}if("object"==typeof i){if("dict"in i)return new or(e,i.dict);if("fn"in i)return yr(e,i.fn,n);if("str"in i)return new vr(e,i.str);if("sym"in i)return _r(e,i.sym,n);if("num"in i)return _r(e,i.num,n)}return _r(e,i,n)}function Nr(e,i,n,t){var r;if("Hold"===i)return new ur(e,"Hold",[yr(e,n[0],t)],Object.assign(Object.assign({},t),{canonical:!0}));if("Error"===i||"ErrorCode"===i)return e._fn(i,n.map((i=>e.box(i,{canonical:!1}))),t.metadata);if("Domain"===i)return e.domain(n[0],t.metadata);if("Number"===i&&1===n.length)return _r(e,n[0],t);if("String"===i)return 0===n.length?new vr(e,"",t.metadata):new vr(e,n.map((e=>{var i;return null!==(i=xr(e))&&void 0!==i?i:""})).join(""),t.metadata);if("Symbol"===i&&n.length>0)return e.symbol(n.map((e=>{var i;return null!==(i=xr(e))&&void 0!==i?i:""})).join(""),t);if(("Divide"===i||"Rational"===i)&&2===n.length){if(n[0]instanceof Gt&&n[1]instanceof Gt){const[i,r]=[Pn(n[0]),Pn(n[1])];if((null==i?void 0:i.isInteger())&&(null==r?void 0:r.isInteger()))return e.number([i,r],t)}else{const[i,r]=[Wn(e,n[0]),Wn(e,n[1])];if((null==i?void 0:i.isInteger())&&(null==r?void 0:r.isInteger()))return e.number([i,r],t)}i="Divide"}if("Complex"===i){if(1===n.length){const i=_r(e,n[0],t),r=Dn(i);return null!==r&&0!==r?e.number(e.complex(0,r),t):e.mul([i,e._I])}if(2===n.length){const i=_r(e,n[0],t),r=_r(e,n[1],t),s=Dn(i),o=Dn(r);return null!==o&&null!==s?0===o&&0===s?e._ZERO:null!==o&&0!==o?e.number(e.complex(s,o),t):i:e.add([i,e.mul([r,e._I])],t.metadata)}}if("Negate"===i&&1===n.length){const i=n[0];if("number"==typeof i)return e.number(-i,t);if(i instanceof Ge)return e.number(i.neg(),t);const r=e.box(i,t).numericValue;if(null!==r){if("number"==typeof r)return e.number(-r,t);if(r instanceof Ge)return e.number(r.neg(),t);if(r instanceof Be.exports.Complex)return e.number(r.neg());if(ht(r))return e.number(Nt(r))}}if("Dictionary"===i){const i={};for(const t of n){const n=e.box(t),s=n.head;if("KeyValuePair"===s||"Pair"===s||"Tuple"===s&&2===n.nops){const e=n.op1;if(e.isValid&&!e.isNothing){const t=n.op2;let s=null!==(r=e.symbol)&&void 0!==r?r:e.string;if(!s&&e.isLiteral){const i="number"==typeof e.numericValue?e.numericValue:Ln(e);i&&Number.isFinite(i)&&Number.isInteger(i)&&(s=i.toString())}s&&(i[s]=t)}}}return new or(e,i,t)}return t.canonical?cr(e,i,n,t.metadata):new ur(e,i,n.map((i=>_r(e,i,{canonical:!1}))),t)}function _r(e,i,n){if(null==i)return e._fn("Sequence",[]);if(null!=n||(n={}),"canonical"in n||(n.canonical=!0),i instanceof Gt)return n.canonical?i.canonical:i;if(Array.isArray(i)){if(mt(i))return Number.isInteger(i[0])&&Number.isInteger(i[1])?e.number(i):Nr(e,"Divide",i,n);if(dt(i))return i[0].isInteger()&&i[1].isInteger()?e.number(i):Nr(e,"Divide",i,n);if("string"==typeof i[0])return Nr(e,i[0],i.slice(1),n);const t=i.slice(1).map((i=>_r(e,i,n))),r=hr(_r(e,i[0],n),t);return r.symbol?new ur(e,r.symbol,t):r}if("number"==typeof i||i instanceof Be.exports.Complex||i instanceof Ge)return e.number(i);if("string"==typeof i)return i.startsWith("'")&&i.endsWith("'")?new vr(e,i.slice(1,-1)):/^[+-]?[0-9]/.test(i)?e.number(i):e.symbol(i,n);if("object"==typeof i){const t={latex:i.latex,wikidata:i.wikidata};if("dict"in i)return new or(e,i.dict,{canonical:!0,metadata:t});if("fn"in i)return"string"==typeof i.fn[0]?Nr(e,i.fn[0],i.fn.slice(1),n):new ur(e,_r(e,i.fn[0],n),i.fn.slice(1).map((i=>_r(e,i,n))),{metadata:t});if("str"in i)return new vr(e,i.str,t);if("sym"in i)return e.symbol(i.sym,n);if("num"in i)return e.number(i,n)}return e.symbol("Undefined")}function xr(e){var i,n;if("string"==typeof e)return e;if(e instanceof Gt)return null!==(n=null!==(i=e.string)&&void 0!==i?i:e.symbol)&&void 0!==n?n:e.toString();if("object"==typeof e){if("str"in e)return e.str;if("fn"in e&&"String"===e.fn[0]&&"string"==typeof e.fn[1])return e.fn[1]}return Array.isArray(e)&&"String"===e[0]&&"string"==typeof e[1]?e[1]:null}class Sr{constructor(e,i,n){if(this._imaginary=0,this._posInfinityCount=0,this._negInfinityCount=0,this._terms=[],this._isCanonical=!0,null!=n||(n={}),"canonical"in n||(n.canonical=!0),this._isCanonical=n.canonical,this.engine=e,this._rational=Bn(e)?[e._BIGNUM_ZERO,e._BIGNUM_ONE]:[0,1],this._bignum=e._BIGNUM_ZERO,this._number=0,i)for(const e of i)this.addTerm(e)}get isEmpty(){return this._isCanonical?0===this._terms.length&&ft(this._rational)&&0===this._imaginary&&0===this._number&&this._bignum.isZero()&&0===this._negInfinityCount&&0===this._posInfinityCount:0===this._terms.length}addTerm(e,i){if(this._isCanonical){if(e.isNothing)return;if(e.isLiteral){if(e.isInfinity)return void(e.isPositive?this._posInfinityCount+=1:this._negInfinityCount+=1);const n=xt(e);if(n)return void(this._rational=wt(this._rational,void 0===i?n:kt(n,i)));const t=e.numericValue;if(null!==t&&"number"==typeof t)return void(Bn(this.engine)?this._bignum=this._bignum.add(t):this._number+=t);if(null!==t&&t instanceof Ge)return void(this._bignum=this._bignum.add(t));if(null!==t&&t instanceof Ue){let n=t.re,r=t.im;if(Number.isInteger(n)?(this._rational=wt(this._rational,kt([n,1],null!=i?i:[1,1])),n=0):(Bn(this.engine)?this._bignum=this._bignum.add(n):this._number+=n,n=0),Number.isInteger(r)&&(void 0===i?this._imaginary+=r:mt(i)?this._imaginary+=r*i[0]/i[1]:this._imaginary+=i[0].mul(r).div(i[1]).toNumber(),r=0),0===n&&0===r)return;e=this.engine.number(this.engine.complex(n,r))}}}let n;if([n,e]=It(e),ft(n))return;if(void 0!==i&&(n=kt(n,i)),"Negate"===e.head)return void this.addTerm(e.op1,Nt(n));if("Add"===e.head){for(const i of e.ops)this.addTerm(i,n);return}let t=!1;if(!e.isLiteral)if(this._terms.length>500){const i=e.hash;for(let r=0;r<this._terms.length;r++)if(!this._terms[r].term.isLiteral&&i===this._terms[r].term.hash&&e.isSame(this._terms[r].term)){this._terms[r].coef=wt(this._terms[r].coef,n),t=!0;break}}else for(let i=0;i<this._terms.length;i++)if(!this._terms[i].term.isLiteral&&e.isSame(this._terms[i].term)){this._terms[i].coef=wt(this._terms[i].coef,n),t=!0;break}t||this._terms.push({term:e,coef:n})}terms(e){var i;const n=this.engine;if(this._posInfinityCount>0&&this._negInfinityCount>0)return[n._NAN];if(this._posInfinityCount>0)return[n._POSITIVE_INFINITY];if(this._negInfinityCount>0)return[n._NEGATIVE_INFINITY];if(0!==this._imaginary&&!Un(n))return[n._NAN];const t=[];for(const{coef:e,term:i}of this._terms)ft(e)||(gt(e)?t.push(i):pt(e)?t.push(n.negate(i)):1===bt(e)?t.push(n.mul([n.number(e[0]),i])):1===vt(e)?t.push(n.divide(i,n.number(e[1]))):t.push(n.mul([n.number(e),i])));if("numeric"===e)if(Bn(this.engine)){let e=this._bignum.add(this._number);ft(this._rational)||(e=e.add(n.bignum(this._rational[0]).div(this._rational[1]))),0!==this._imaginary?t.push(n.number(n.complex(e.toNumber(),this._imaginary))):0!==n.chop(e)&&t.push(n.number(e))}else{let e=this._bignum.toNumber()+this._number;ft(this._rational)||(e+=vt(this._rational)/bt(this._rational)),0!==this._imaginary?t.push(n.number(n.complex(e,this._imaginary))):0!==n.chop(e)&&t.push(n.number(e))}else{if(ft(this._rational)||t.push(n.number(this._rational)),0!==this._imaginary){if(!Un(n))return[n._NAN];t.push(n.number(n.complex(0,this._imaginary)))}if(Bn(this.engine)){const e=this._bignum.add(this._number);0!==n.chop(e)&&t.push(n.number(e))}else 0!==n.chop(this._bignum)&&t.push(n.number(this._bignum)),0!==n.chop(this._number)&&t.push(n.number(this._number))}return null!==(i=Kn(t,"Add"))&&void 0!==i?i:t}asExpression(e){const i=this.engine,n=this.terms(e);return 0===n.length?i._ZERO:1===n.length?n[0]:i._fn("Add",Wt(0,n))}}const wr=["Error","Dictionary","Function","List","Tuple","Intersection","Union","Maybe","Sequence","Interval","Range","Head","Symbol","Value"],kr={NumericFunction:["Function",["Sequence","Number"],"Number"],RealFunction:["Function",["Sequence","ExtendedRealNumber"],"ExtendedRealNumber"],TrigonometricFunction:["Function","Number","Number"],LogicOperator:["Function","MaybeBoolean",["Maybe","MaybeBoolean"],"MaybeBoolean"],Predicate:["Function",["Sequence","Anything"],"MaybeBoolean"],RelationalOperator:["Function","Anything","Anything","MaybeBoolean"]},Er={Anything:[],Value:"Anything",Domain:"Anything",DomainExpression:"Domain",Void:"Nothing",Nothing:["DomainExpression","Boolean","String","Symbol","Tuple","List","Dictionary","InfiniteSet","FiniteSet","ImaginaryNumber","TranscendentalNumber","PositiveInteger","NegativeInteger","NonPositiveInteger","NonNegativeInteger","PositiveNumber","NegativeNumber","NonPositiveNumber","NonNegativeNumber","Scalar","TrigonometricFunction","LogicOperator","RelationalOperator"],MaybeBoolean:"Value",Boolean:"MaybeBoolean",String:"Boolean",Symbol:"Boolean",Collection:"Value",List:"Collection",Dictionary:"Collection",Sequence:"Collection",Tuple:"Sequence",Set:"Collection",InfiniteSet:"Set",FiniteSet:"Set",Function:"Anything",Predicate:"Function",LogicOperator:"Predicate",RelationalOperator:"Predicate",NumericFunction:"Function",RealFunction:"NumericFunction",TrigonometricFunction:"RealFunction",Number:"Value",ExtendedComplexNumber:"Number",ComplexNumber:"ExtendedComplexNumber",ImaginaryNumber:"ComplexNumber",ExtendedRealNumber:"ExtendedComplexNumber",RealNumber:["ComplexNumber","ExtendedRealNumber"],PositiveNumber:"NonNegativeNumber",NonNegativeNumber:"RealNumber",NonPositiveNumber:"NegativeNumber",NegativeNumber:"RealNumber",TranscendentalNumber:"RealNumber",AlgebraicNumber:"RealNumber",RationalNumber:"AlgebraicNumber",Integer:"RationalNumber",PositiveInteger:"NonNegativeInteger",NonNegativeInteger:"Integer",NonPositiveInteger:"NegativeInteger",NegativeInteger:"Integer",Tensor:"Value",Matrix:"Tensor",Scalar:["Row","Column"],Row:"Vector",Column:"Vector",Vector:"Matrix"};let Ar;function Ir(e){return!!e&&void 0!==Er[e]}function Mr(e){if(Ar||(Ar={},Mr("Void")),Ar[e])return Array.from(Ar[e]);let i=[];if("string"!=typeof e||!Er[e]){if(!Array.isArray(e))throw Error("Unknown domain literal "+e);if(!wr.includes(e[0]))throw Error("Unknown domain constructor "+e[0]);return"Function"===e[0]||"Head"===e[0]?Mr("Function"):"Symbol"===e[0]?Mr("Symbol"):"Tuple"===e[0]?Mr("Tuple"):"List"===e[0]?Mr("List"):"Dictionary"===e[0]?Mr("Dictionary"):"Range"===e[0]?Mr("Integer"):"Interval"===e[0]?Mr("RealNumberExtended"):"Maybe"===e[0]||"Sequence"===e[0]?Mr(e[1]):("Literal"===e[0]||"Union"===e[0]||e[0],["Anything"])}if("string"==typeof Er[e])i=[Er[e],...Mr(Er[e])];else if(Array.isArray(Er[e]))for(const n of Er[e])i.push(n),i.push(...Mr(n));return Ar[e]=new Set(i),i}class qr extends Gt{constructor(e,i,n){super(e,n),this._value=Tr(e,i)}get isCanonical(){return!0}get canonical(){return this}get isValid(){return"Error"!==this.ctor}get json(){const e=Vr(this.engine,this._value);return"Error"===ai(e)?e:["Domain",e]}get literal(){return"string"==typeof this._value?this._value:null}get ctor(){return"string"==typeof this._value?null:this._value[0]}get domainArgs(){return"string"==typeof this._value?null:this._value.slice(1)}get domainArg1(){return"string"==typeof this._value?null:this._value[1]}get codomain(){return"string"==typeof this._value?null:this.engine.domain(this._value[this._value.length-1])}get hash(){return void 0===this._hash&&(this._hash=Hn(jr(this._value))),this._hash}isEqual(e){return Gr(this._value,e)}isSame(e){return Gr(this._value,e)}is(e){return Gr(this._value,e)}isCompatible(e,i="covariant"){const n=this._value,t=e instanceof qr?e._value:e,r=Array.isArray(t)?t[0]:null;if(r){const e=t[1];if("Covariant"===r)return Pr(n,e);if("Contravariant"===r)return Pr(e,n);if("Invariant"===r)return!Pr(e,n)&&!Pr(n,e);if("Bivariant"===r)return Pr(n,e)&&Pr(e,n)}return"covariant"===i?Pr(n,t):"contravariant"===i?Pr(t,n):"bivariant"===i?Pr(t,n)&&Pr(n,t):!Pr(t,n)&&!Pr(n,t)}match(e,i){return e instanceof qr&&this.isSame(e)?{}:null}get head(){return"Domain"}get domain(){return this.engine.domain("Domain")}get isNothing(){return"Nothing"===this._value}get isFunction(){return"Function"===this.ctor||"Function"===this._value}get isNumeric(){return this.isCompatible(this.engine.domain("Number"))}get isRelationalOperator(){return"RelationalOperator"===this._value||"Function"===this.ctor&&2===this.domainArgs.length&&!!this.codomain.isCompatible("MaybeBoolean")}}function Or(e,i,n){if(i instanceof qr)return i;if(i instanceof Gt&&(i=i.json),"string"==typeof i){const t=kr[i];if(t)return Or(e,t);if(!Ir(i))throw Error("Expected a domain literal, got "+i);return new qr(e,i,n)}if(!Array.isArray(i)||0===i.length)throw Error("Expected a valid domain");const t=i[0];if(!wr.includes(t))throw Error("Expected domain constructor, got "+t);return new qr(e,i,n)}function Tr(e,i){if("string"==typeof i){if(!Ir(i))throw Error("Unknown domain literal");return i}if(i instanceof qr)return i._value;const n=i[0];if("Range"===n){if(1===i.length)return"Integer";let n=1,t=1/0;2===i.length?t=i[1]:3===i.length&&(n=i[1],t=i[2]);const r=Fr(e,n),s=Fr(e,t);if(null===r||null===s)throw Error(`Invalid range [${r}, ${s}] `);return s<r&&([n,t]=[t,n]),r===-1/0&&s===1/0?"Integer":1===r&&s===1/0?"PositiveInteger":0===r&&s===1/0?"NonNegativeInteger":r===-1/0&&-1===s?"NegativeInteger":r===-1/0&&0===s?"NonPositiveInteger":["Range",e.number(r),e.number(s)]}if("Interval"===n){if(3!==i.length)throw Error("Invalid range "+i);let[n,t]=Cr(e,i[1]),[r,s]=Cr(e,i[2]);if(null===t||null===s)throw Error("Invalid range "+i);return s<t&&([t,s]=[s,t],[n,r]=[r,n]),0===t&&s===1/0?n?"PositiveNumber":"NonNegativeNumber":t===-1/0&&0===s?r?"NegativeNumber":"NonPositiveNumber":["Interval",n?["Open",e.number(t)]:e.number(t),r?["Open",e.number(s)]:e.number(s)]}if("Function"===n)return["Function",...i.slice(1).map((i=>Tr(e,i)))];if("Dictionary"===n)return["Dictionary",Tr(e,i[1])];if("List"===n)return["List",Tr(e,i[1])];if("Tuple"===n)return["Tuple",...i.slice(1).map((i=>Tr(e,i)))];if("Union"===n)return["Union",...i.slice(1).map((i=>Tr(e,i)))];if("Intersection"===n)return["Intersection",...i.slice(1).map((i=>Tr(e,i)))];if("Covariant"===n||"Contravariant"===n||"Invariant"===n)return[n,Tr(e,i[1])];if("Maybe"===n)return["Maybe",Tr(e,i[1])];if("Sequence"===n)return["Sequence",Tr(e,i[1])];if("Head"===n)return["Head",i[1]];if("Symbol"===n)return["Symbol",i[1]];if("Value"===n)return["Value",e.box(i[1])];if("Error"===n)return["Error",...i.slice(1).map((i=>e.box(i)))];throw Error("Unexpected domain constructor "+n)}function Fr(e,i){if("number"==typeof i)return i;const n=e.box(i).evaluate();return n.isInfinity?n.isPositive?1/0:-1/0:Ln(n)}function Cr(e,i){return Array.isArray(i)&&"Open"===i[0]?[!0,Fr(e,i[1])]:[!1,Fr(e,i)]}function Dr(e){if(e instanceof qr)return!0;if(e instanceof Gt&&(e=e.json),"string"==typeof e)return Ir(e);if(Array.isArray(e)){if(e.length<=1)return!1;const i=e[0];return!("string"!=typeof i||!wr.includes(i))&&("List"===i?2===e.length&&Dr(e[1]):"Tuple"===i||"Function"===i||"Maybe"===i||"Sequence"===i||"Intersection"===i||"Union"===i?e.slice(1,-1).every((e=>Dr(e))):e.every((e=>null!==e)))}return!1}function Pr(e,i){const[n,t]=Lr([e],i);return!(!n||0!==t.length)}function Lr(e,i){let n=e.shift();const t="string"==typeof i?i:null;if("Anything"===t)return[!0,e];const r="string"==typeof n?n:null;if(r&&t)return r===t?[!0,e]:[$r(Mr(r),t),e];if(t){const i=n[0];return"Function"===i?["Function"===t,e]:"Dictionary"===i?["Dictionary"===t,e]:"List"===i?["List"===t,e]:"Tuple"===i?["Tuple"===t,e]:"Interval"===i?[Pr("ExtendedRealNumber",t),e]:"Range"===i?[Pr("Integer",t),e]:[!0,e]}const s=i[0];if("Function"===s){if("Function"===r)return[!0,e];if(r)return[!1,e];if("Function"!==n[0])return[!1,e];if(1===n.length&&1===i.length)return[!0,e];if(!Pr(n[n.length-1],i[i.length-1]))return[!1,e];const t=n.slice(1,-1);let s=i.slice(1,-1);for(let i=0;i<=t.length-1;i++){if(0===s.length)return"Maybe"!==(Array.isArray(t[i])?t[i][0]:null)?[!1,e]:[!0,e];{let n=!1;if([n,s]=Lr(s,t[i]),!n)return[!1,e]}}return[0===s.length,e]}if("Intersection"===s)return[i.slice(1,-1).every((e=>Pr(n,e))),e];if("Union"===s)return[i.slice(1,-1).some((e=>Pr(n,e))),e];if("Maybe"===s)return"Nothing"===r?[!0,e]:Lr([n,...e],i[1]);if("Sequence"===s){const t=i[1];if(!Pr(n,t))return[!1,e];n=e.shift();let r=!0;for(;e.length>0&&r;)[r,e]=Lr(e,t),n=e.shift();return[!0,e]}if("Tuple"===s){if(!Array.isArray(n)||"Tuple"!==n[0])return[!1,e];if(n.length>i.length)return[!1,e];for(let t=1;t<=i.length-1;t++)if(!n[t]||!Pr(n[t],i[t]))return[!1,e];return[!0,e]}if("Range"===s){if(!Array.isArray(n)||"Range"!==n[0])return[!1,e];const t=Dn(n[1]),r=Dn(n[2]),s=Dn(i[1]),o=Dn(i[2]);return[null!==t&&null!==r&&null!==s&&null!==o&&t>=s&&r<=o,e]}if("Interval"===s){if(!Array.isArray(n)||"Interval"!==n[0])return[!1,e];const t=Dn(n[1]),r=Dn(n[2]),s=Dn(i[1]),o=Dn(i[2]);return[null!==t&&null!==r&&null!==s&&null!==o&&t>=s&&r<=o,e]}return[!1,e]}function Rr(e,i){const n=zr(e),t=zr(i),r=[n,...Mr(n)],s=[t,...Mr(t)];for(;!$r(s,r[0]);)r.shift();return e.engine.domain(r[0])}function zr(e){let i=e.literal;return i||(i=e.ctor,"Maybe"===i?"Anything":"Interval"===i?"RealNumber":"Range"===i?"Integer":"Head"===i?"Function":"Union"===i||"Intersection"===i?"Anything":i)}function $r(e,i){for(const n of e)if(n===i)return!0;return!1}function Vr(e,i){if(i instanceof Gt)return i.json;if("string"==typeof i)return i;if("Error"===i[0])return i[2]?["Error",Vr(e,i[1]),Vr(e,i[2])]:["Error",Vr(e,i[1])];const n=[tr(e,i[0])];if(i.length>1)for(let t=1;t<=i.length-1;t++)n.push(Vr(e,i[t]));return n}function jr(e){if("string"==typeof e)return"domain:"+e;let i="domain:"+this.ctor;for(const e of this.domainArgs)i+=":"+jr(e);return i}function Gr(e,i){if("string"==typeof i)return this._value===i;if(i instanceof qr)return Gr(e,i._value);if("string"==typeof e)return e===i;if(!Array.isArray(i))return!1;if(e[0]!==i[0])return!1;if(i.length!==e.length)return!1;for(let n=1;n<=e.length-1;n++)if(e[n]instanceof Gt){if(!(i[n]instanceof Gt))return!1;if(!i[n].isEqual(i[n]))return!1}else if("string"==typeof e[n]){if("string"!=typeof i[n])return!1;if(e[n]!==i[n])return!1}else if(!Gr(e[n],i[n]))return!1;return!0}function Zr(e,i){var n;if(i.every((e=>e.isCanonical)),0===(i=(i=null!==(n=Kn(Xn(i.map((e=>e.canonical))),"Add"))&&void 0!==n?n:i).filter((e=>!(e.isLiteral&&e.isZero)))).length)return e.number(0);if(1===i.length)return i[0];if(2===i.length){let n=0,t=0;if(null!==i[0].numericValue&&(t=Dn(i[0])),null!==t&&0!==t?n=Vn(i[1]):(n=Vn(i[0]),0!==n&&null!==i[1].numericValue&&(t=Dn(i[1]))),null!==t&&null!==n&&0!==n)return e.number(e.complex(t,n))}return i.length>1&&(i=Wt(0,i)),e._fn("Add",i)}function Br(e,i,n="evaluate"){for(const t of i){if(t.isImaginary&&t.isInfinity)return e.symbol("ComplexInfinity");if(t.isNaN||"Undefined"===t.symbol)return e._NAN;t.isExact||(n="N")}return"N"===n&&(i=i.map((e=>e.N()))),new Sr(e,i).asExpression("N"===n?"numeric":"expression")}function Ur(e,i,n,t){var r,s,o,a;const l=i;let u=1,c=En,h="Nothing";if("Tuple"!==n.head&&"Triple"!==n.head&&"Pair"!==n.head&&"Single"!==n.head||(h=null!==(r="Hold"===n.op1.head?n.op1.op1.symbol:n.op1.symbol)&&void 0!==r?r:"Nothing",u=null!==(s=Ln(n.op2))&&void 0!==s?s:1,c=null!==(o=Ln(n.op3))&&void 0!==o?o:En),u>=c||c-u>=200)return;const m=e.context;if(e.context=null!==(a=l.scope)&&void 0!==a?a:e.context,"simplify"===t){const i=[];if(l.scope)for(let n=u;n<=c;n++)e.set({[h]:n}),i.push(l.simplify());else for(let e=u;e<=c;e++)i.push(l.simplify());return e.context=m,e.add(i).simplify()}if("evaluate"===t){const i=[];if(l.scope)for(let n=u;n<=c;n++)e.set({[h]:n}),i.push(l.evaluate());else for(let e=u;e<=c;e++)i.push(l.evaluate());return e.context=m,e.add(i).evaluate()}let d=Bn(e)?[e._BIGNUM_ZERO,e._BIGNUM_ONE]:[0,1];if(l.scope)for(let i=u;i<=c;i++){e.set({[h]:i});const n=l.N();if(!n.isLiteral)return void(e.context=m);d=wt(d,n)}else for(let e=u;e<=c;e++){const e=l.N();if(!e.isLiteral)return;d=wt(d,e)}return e.context=m,mt(d)?e.number(d[0]/d[1]):e.number(d[0].div(d[1]))}function Hr(e){if("Negate"===e.head)return[-1,e.op1];const i=e.numericValue;if(null===i)return[1,e];const n=e.engine;return"number"==typeof i&&i<0?[-1,n.number(-i)]:i instanceof Ge&&i.isNegative()?[-1,n.number(i.neg())]:i instanceof Ue&&i.re<0?[-1,n.number(n.complex(-i.re,-i.im))]:mt(i)&&i[0]<0?[-1,n.number([-i[0],i[1]])]:dt(i)&&i[0].isNegative()?[-1,n.number([i[0].neg(),i[1]])]:[1,e]}function Wr(e,i,n,t){if(e.isLiteral)return e.engine.number(function(e,i,n,t){var r;const s=e.numericValue;return"number"==typeof s?Bn(e.engine)&&n?e.engine.chop(n(e.engine.bignum(s))):e.engine.chop(i(s)):s instanceof Ge?e.engine.chop(null!==(r=null==n?void 0:n(s))&&void 0!==r?r:i(s.toNumber())):mt(s)?Bn(e.engine)&&n?e.engine.chop(n(e.engine.bignum(s[0]).div(s[1]))):e.engine.chop(i(s[0]/s[1])):dt(s)?n?e.engine.chop(n(s[0].div(s[1]))):e.engine.chop(i(s[0].toNumber()/s[1].toNumber())):s instanceof Ue&&t&&Un(e.engine)?e.engine.chop(t(s)):NaN}(e,i,n,t))}function Qr(e,i,n,t,r){if(e.isLiteral&&i.isLiteral)return e.engine.number(function(e,i,n,t,r){var s,o,a,l,u;const c=e.engine;let h=e.numericValue;mt(h)&&(h=h[0]/h[1]);let m,d,f=i.numericValue;return mt(f)&&(f=f[0]/f[1]),Bn(c)||"number"!=typeof h||"number"!=typeof f?(h instanceof Ge?m=h:dt(h)?m=h[0].div(h[1]):null!==h&&"number"==typeof h&&(m=c.bignum(h)),f instanceof Ge?d=f:dt(f)?d=f[0].div(f[1]):null!==f&&"number"==typeof f&&(d=c.bignum(f)),m&&d?null!==(s=null==t?void 0:t(m,d))&&void 0!==s?s:n(m.toNumber(),d.toNumber()):(h instanceof Ue||f instanceof Ue)&&r&&Un(c)?r(c.complex(null!==(a=null!==(o=h)&&void 0!==o?o:null==m?void 0:m.toNumber())&&void 0!==a?a:NaN),c.complex(null!==(u=null!==(l=f)&&void 0!==l?l:null==d?void 0:d.toNumber())&&void 0!==u?u:NaN)):NaN):n(h,f)}(e,i,n,t,r))}function Yr(e,i,n,t){if(i=tt(e,null==i?void 0:i.canonical,"Number"),"ComplexInfinity"===(n=tt(e,null==n?void 0:n.canonical,"Number")).symbol)return e._NAN;if(n.isLiteral){if(n.isZero)return e._ONE;if(i.isLiteral){const r=Dn(i);if(1===r)return e._ONE;if(0===r){if(n.isPositive)return e._ZERO;if(n.isNegative)return e._COMPLEX_INFINITY}if(n.isOne)return i;if(n.isNegativeOne){if(1===r)return e._ONE;if(-1===r)return e._NEGATIVE_ONE;if(i.isInfinity)return e._ZERO;const n=i.numericValue;if(null!==n){if("number"==typeof n&&Number.isInteger(n))return e.number([1,n],{metadata:t});if(n instanceof Ge&&n.isInteger())return e.number([e._BIGNUM_ONE,n],{metadata:t});if(ht(n))return e.number(_t(n),{metadata:t})}return e._fn("Power",[i,e._NEGATIVE_ONE],t)}const s=Dn(n);if(.5===s||-.5===s){const n=Ln(i);if(null!==n&&n>0){const[i,t]=Mn(n,2);if(1===t&&1===i)return e._ONE;if(1!==i)return 1===t?e.number(s>=0?i:[1,i]):e.mul([e.number(i),e.power(e.number(t),e._HALF)])}return s>0?e._fn("Power",[i,e._HALF],t):e._fn("Power",[i,e.number([-1,2])],t)}if(i.isInfinity){if(n.numericValue instanceof Ue){const i=n.numericValue.re;if(0===i)return e._NAN;if(i<0)return e._ZERO;if(i>0)return e._COMPLEX_INFINITY}if(i.isNegative){if(n.isInfinity)return e._NAN}else if(i.isPositive){if(n.isNegativeOne)return e._ZERO;if(n.isInfinity)return n.isNegative?e._ZERO:e._POSITIVE_INFINITY}}if(n.isInfinity&&(i.isOne||i.isNegativeOne))return e._NAN;const o=xt(i);if(o){const i=Ln(n);if(null!==i&&-1===i)return e.number(_t(o))}}}if("Power"===i.head&&i.op1.isReal){const t=Ln(n);if(null!==t){const n=Ln(i.op2);if(null!==n)return e.power(i.op1,e.number(t*n))}if(i.op1.isNonNegative){const t=xt(n);if(t){const n=xt(i.op2);if(n)return e.power(i.op1,e.number(kt(t,n)))}}}return"Multiply"===i.head&&null!==Ln(n)?e._fn("Multiply",i.ops.map((i=>e.power(i,n)))):null}function Jr(e,i){const n=i.numericValue;if("number"==typeof n)return e.number(n*n);if(n instanceof Ge)return e.number(n.pow(2));if(n instanceof Ue)return e.number(n.pow(2));if(mt(n))return e.number([n[1]*n[1],n[0]*n[0]]);if(dt(n))return e.number([n[1].pow(2),n[0].pow(2)]);if("Multiply"===i.head)return e._fn("Multiply",i.ops.map((i=>Jr(e,i))));if("Power"===i.head){const n=Ln(i.op2);return null!==n?e.power(i.op1,e.number(2*n)):e.power(i.op1,e.mul([e.number(2),i.op2]))}return e.power(i,e.number(2))}function Kr(e,i,n){var t,r,s,o;if(null===i.numericValue||null===n.numericValue)return;if(i.numericValue instanceof Ue)return n.numericValue instanceof Ue?e.number(i.numericValue.pow(n.numericValue)):e.number(i.numericValue.pow(null!==(t=Dn(n))&&void 0!==t?t:NaN));if(n.numericValue instanceof Ue){const t=null!==(r=Dn(i))&&void 0!==r?r:null;return null!==t?e.number(e.complex(t).pow(n.numericValue)):void 0}const a=function(e){if("number"==typeof e.numericValue){const i=1/e.numericValue;return Number.isInteger(i)?i:null}if(e.numericValue instanceof Ge){const i=e.engine._BIGNUM_ONE.div(e.numericValue);return i.isInt()?i.toNumber():null}if(!ht(e.numericValue))return null;const[i,n]=[vt(e.numericValue),bt(e.numericValue)];return 1!==i&&-1!==i?null:i*n}(n);if(Bn(e)||i.numericValue instanceof Ge||n.numericValue instanceof Ge){const t=Pn(i),r=Pn(n);if(!t||!r)return;if(2===a)return t.isNeg()?Un(e)?e.mul([e._I,e.number(t.neg().sqrt())]):e._NAN:e.number(t.sqrt());if(!r.isInteger()&&t.isNeg()){if(!Un(e))return e._NAN;const i=e.complex(t.toNumber()),n=e.complex(r.toNumber());return e.number(i.pow(n))}return e.number(t.pow(r))}const l=null!==(s=Dn(n))&&void 0!==s?s:NaN,u=null!==(o=Dn(i))&&void 0!==o?o:NaN;if(2===a)return u<0?Un(e)?e.mul([e._I,e.number(Math.sqrt(-u))]):e._NAN:e.number(Math.sqrt(u));if(!Number.isInteger(l)&&u<0){if(!Un(e))return e._NAN;const i=e.complex(u),n=e.complex(l);return e.number(i.pow(n))}return e.number(Math.pow(u,l))}function Xr(e,i,n,t){var r,s;if("Multiply"===i.head){let o=Bn(e)?[e._BIGNUM_ONE,e._BIGNUM_ONE]:[1,1];const a=[];for(const e of i.ops){const i=xt(e);i?o=kt(o,i):a.push(e)}if(!gt(o))return e.mul([null!==(r=es(e,e.number(o),t))&&void 0!==r?r:e._ONE,e.power(null!==(s=Xr(e,e.mul(a),n,t))&&void 0!==s?s:e.mul(a),n)])}if("Power"===i.head){if(-1===Ln(i.op2)&&-1===Ln(n))return i.op1;const r=xt(i.op2),s=xt(n);if(r&&s){const n=kt(r,s);return ft(n)?e._ONE:gt(n)?i.op1:e.power(i.op1,n)}if("N"===t){const t=Dn(i.op2),r=Dn(n);if(null!==t&&null!==r){const n=t*r;return 0===n?e._ONE:1===n?i.op1:e.power(i.op1,n)}}}if("N"!==t&&i.isLiteral&&i.isInteger){if(Ln(n))return Kr(e,i,n);const t=xt(n);if(t){const[r,s]=[vt(t),bt(t)];if(!(1!==r&&-1!==r||2!==s&&3!==s))if(Bn(e)||i.numericValue instanceof Ge){const t=Pn(i);if(s%2==0&&t.isNeg()&&!Un(e))return e._NAN;const o=t.isNegative()?s%2==0?e._I:e._NEGATIVE_ONE:e._ONE,[a,l]=ot(e,t.abs(),s);if(l.eq(1)&&a.eq(1))return o;if(!a.eq(1))return l.eq(1)?e.mul([o,e.number(r>=0?a:[e.bignum(1),a])]):e.mul([o,e.number(a),e.power(e.number(l),n)])}else if("number"==typeof i.numericValue){if(s%2==0&&i.numericValue<0&&!Un(e))return e._NAN;const[t,o]=Mn(Math.abs(i.numericValue),s),a=i.numericValue<0?s%2==0?e._I:e._NEGATIVE_ONE:e._ONE;if(1===o&&1===t)return a;if(1!==t)return 1===o?e.mul([a,e.number(r>=0?t:[1,t])]):e.mul([a,e.number(t),e.power(e.number(o),n)])}return i.isNegative?Un?e.mul([e._I,e.fn("Sqrt",[e.negate(i)])]):e._NAN:void 0}}if("simplify"!==t&&i.isLiteral&&n.isLiteral)return Kr(e,i,n)}function es(e,i,n){if(i.isOne)return e._ONE;if(i.isZero)return e._ZERO;if(i.isNegativeOne)return Un(e)?e._I:e._NAN;if(i.isNegative&&!Un(e))return e._NAN;const t=xt(i);if("N"===n||"evaluate"===n&&!t)return Wr(i,(i=>i<0?e.complex(i).sqrt():Math.sqrt(i)),(i=>i.isNeg()?e.complex(i.toNumber()).sqrt():i.sqrt()),(e=>e.sqrt()));const r=Ln(i);if(null!==r){const[i,n]=Mn(Math.abs(r),2);return r<0?(1===n&&e.mul([e.number(e.complex(0,i))]),e.mul([e.number(e.complex(0,i)),e.sqrt(e.number(n))])):1===n?e.number(i):e.mul([e.number(i),e.sqrt(e.number(n))])}if(t){if(mt(t)&&!Bn(e)){const[i,n]=t;if(Math.abs(i)<Number.MAX_SAFE_INTEGER&&n<Number.MAX_SAFE_INTEGER){const[t,r]=Mn(Math.abs(i),2),[s,o]=Mn(n,2);return i<0?e.mul([e.number([t,s]),e.sqrt(e.number([r,o])),e._I]):e.mul([e.number([t,s]),e.sqrt(e.number([r,o]))])}}if(dt(t)||Bn(e)){const i=e.bignum(t[0]),[n,r]=ot(e,i.abs(),2),[s,o]=ot(e,e.bignum(t[1]),2);return i.isNeg()?e.mul([e.number([n,s]),e.sqrt(e.number([r,o])),e._I]):e.mul([e.number([n,s]),e.sqrt(e.number([r,o]))])}}}function is(e,i){var n;return 0===(i=null!==(n=Kn(Xn(i).map((e=>e.canonical)),"Multiply"))&&void 0!==n?n:i).length?e.number(1):1===i.length?i[0]:2===i.length?rs(i[0],i[1]):ns(e,i)}function ns(e,i){const n=new Jt(e);for(const t of i){if(t.isNaN||"Undefined"===t.symbol)return e._NAN;n.addTerm(t)}return n.asExpression()}function ts(e,i,n="evaluate"){for(const t of i){if(t.isNaN||"Undefined"===t.symbol)return e._NAN;t.isExact||(n="N")}return"N"===n&&(i=i.map((e=>e.N()))),new Jt(e,i).asExpression(n)}function rs(e,i,n){var t;const r=e.engine;if(e.isLiteral&&i.isLiteral&&e.isInteger&&i.isInteger)return null!==(t=Qr(e,i,((e,i)=>e*i),((e,i)=>e.mul(i))))&&void 0!==t?t:r._NAN;if(e.isNothing)return i;if(i.isNothing)return e;if(e.isLiteral&&e.isOne)return i;if(i.isLiteral&&i.isOne)return e;if(e.isLiteral&&e.isNegativeOne)return Ot(i);if(i.isLiteral&&i.isNegativeOne)return Ot(e);let s=1,o=e,a=i;if(o.isLiteral||(a=i,o=e),"Negate"===a.head&&(a=a.op1,s=-s),o.isLiteral){const e=xt(o);if(e){if(gt(e))return a;if(ft(e))return r._ZERO;if("Add"===a.head)return s<0&&(o=Ot(o)),r.add(a.ops.map((e=>rs(o,e))),n);if(a.isLiteral){const i=xt(a);if(i){const t=kt(e,i);return r.number(s<0?Nt(t):t,{metadata:n})}}return s<0?r._fn("Multiply",[Ot(o),a],n):r._fn("Multiply",[o,a],n)}}if(o.hash===a.hash&&o.isSame(a))return Jr(r,o);const l=new Jt(r,[o,a]);return s>0?l.asExpression():Ot(l.asExpression(),n)}function ss(e,i,n,t){var r,s;if("Lambda"!==i.head)return;const o=i.op1;let a=1,l=En;if("Tuple"!==n.head&&"Triple"!==n.head&&"Pair"!==n.head&&"Single"!==n.head||(a=null!==(r=Ln(n.op2))&&void 0!==r?r:1,l=null!==(s=Ln(n.op3))&&void 0!==s?s:En),a>=l||l-a>=200)return;if("evaluate"===t||"simplify"===t){const i=[];for(let n=a;n<=l;n++){const t=e.number(n);i.push(o.subs({_1:t,_:t}))}const n=e.mul(i);return"simplify"===t?n.simplify():n.evaluate()}let u=Bn(e)?[e._BIGNUM_ONE,e._BIGNUM_ONE]:[1,1];for(let i=a;i<=l;i++){const n=e.number(i),t=o.subs({_1:n,_:n}).N();if(!t.isLiteral)return;u=kt(u,t)}return mt(u)?e.number(u[0]/u[1]):e.number(u[0].div(u[1]))}function os(e,i,n){if(i=tt(e,i,"Number"),n=tt(e,n,"Number"),!i.isValid||!n.isValid)return e._fn("Divide",[i,n]);if(i.isLiteral&&n.isLiteral){if(n.isOne)return i;if(n.isNegativeOne)return Ot(i);if(i.isOne)return e.inverse(n);if(i.isNegativeOne)return Ot(e.inverse(n));const t=xt(i),r=xt(n);if(t&&r&&!ft(r))return e.number(kt(t,_t(r)))}if(!("Divide"!==i.head&&"Rational"!==i.head||"Divide"!==n.head&&"Rational"!==n.head))return os(e,e.mul([i.op1,n.op2]),e.mul([i.op2,n.op1]));if(i.isLiteral){const t=i.numericValue;if(mt(t)){const[i,r]=t;return os(e,e.mul([e.number(i),n]),e.number(r))}if(dt(t)){const[i,r]=t;return os(e,e.mul([e.number(i),n]),e.number(r))}}if(n.isLiteral){const t=n.numericValue;if(mt(t)){const[n,r]=t;return os(e,e.mul([i,e.number(r)]),e.number(n))}if(dt(t)){const[n,r]=t;return os(e,e.mul([i,e.number(r)]),e.number(n))}}if("Divide"===i.head||"Rational"===i.head)return os(e,e.mul([i.op1,n]),i.op2);if("Divide"===n.head||"Rational"===n.head)return os(e,e.mul([i,n.op2]),n.op1);let[t,r]=Hr(i),[s,o]=Hr(n);if(r=r.canonical,o=o.canonical,o.isLiteral&&o.isOne)return t*s<0?Ot(r):r;if(o=e.inverse(o),r.isLiteral){if(r.isOne)return o;if(r.isNegativeOne)return Ot(o)}return t*s>0?e.mul([r,o]):Ot(e.mul([r,o]))}function as(e,i,n){if(i.isLiteral&&n.isLiteral){const t=xt(i),r=xt(n);if(t&&r&&!ft(r))return e.number(kt(t,_t(r)))}}const ls=[{functions:[{name:"Abs",wikidata:"Q3317982",threadable:!0,idempotent:!0,complexity:1200,signature:{domain:["Function","Number","NonNegativeNumber"],simplify:(e,i)=>us(e,i[0],"simplify"),evaluate:(e,i)=>us(e,i[0],"evaluate"),N:(e,i)=>us(e,i[0],"N")}},{name:"Add",wikidata:"Q32043",associative:!0,commutative:!0,threadable:!0,idempotent:!0,complexity:1300,signature:{domain:"NumericFunction",codomain:(e,i)=>function(e,i){let n=null;for(const e of i){if(!e.isNumeric)return null;n=n?Rr(n,e):e}return n}(0,i.map((e=>e.domain))),canonical:(e,i)=>Zr(e,i),simplify:(e,i)=>function(e,i){const n=new Sr(e);for(const t of i){if(t.isImaginary&&t.isInfinity)return e.symbol("ComplexInfinity");if(t.isNaN||"Undefined"===t.symbol)return e._NAN;t.isZero||n.addTerm(t)}return n.asExpression("expression")}(e,i),evaluate:(e,i)=>Br(e,i),N:(e,i)=>Br(e,i,"N")}},{name:"Ceil",description:"Rounds a number up to the next largest integer",complexity:1250,signature:{domain:["Function","Number","Integer"],evaluate:(e,i)=>Wr(i[0],Math.ceil,(e=>e.ceil()),(e=>e.ceil(0)))}},{name:"Chop",associative:!0,threadable:!0,idempotent:!0,complexity:1200,signature:{domain:["Function","Number","Number"],evaluate:(e,i)=>Wr(i[0],(i=>e.chop(i)),(i=>e.chop(i)),(i=>e.chop(i)))}},{name:"Complex",wikidata:"Q11567",complexity:500},{name:"Divide",wikidata:"Q1226939",complexity:2500,signature:{domain:["Function","Number","Number","Number"],canonical:(e,i)=>os(e,i[0],i[1]),simplify:(e,i)=>as(e,i[0],i[1])}},{name:"Exp",wikidata:"Q168698",threadable:!0,complexity:3500,signature:{domain:["Function","Number","Number"],canonical:(e,i)=>e.power(e.symbol("ExponentialE"),tt(e,i[0],"Number"))}},{name:"Erf",description:"Complementary Error Function",complexity:7500},{name:"Erfc",description:"Complementary Error Function",complexity:7500},{name:"Factorial",description:"The factorial function",wikidata:"Q120976",complexity:9e3,signature:{domain:["Function","Number","Number"],evaluate:(e,i)=>{const n=Ln(i[0]);if(null!==n&&n>=0)return Bn(e)?e.number(at(e,e.bignum(n))):e.number(function(e){if(!Number.isInteger(e)||e<0)return NaN;let i=1;for(let n=2;n<=e;n++)i*=n;return i}(n));const t=i[0].numericValue;if(null!==t&&t instanceof Ue)return e.number(t.add(1));const r=Dn(i[0]);return null!==r?e.number(Fn(1+r)):void 0}}},{name:"Floor",wikidata:"Q56860783",complexity:1250,signature:{domain:["Function","Number","ExtendedRealNumber"],evaluate:(e,i)=>Wr(i[0],Math.floor,(e=>e.floor()),(e=>e.floor(0)))}},{name:"Gamma",wikidata:"Q190573",complexity:8e3,signature:{domain:["Function","Number","Number","Number"],N:(e,i)=>Wr(i[0],(e=>Fn(e)),(i=>ut(e,i)),(e=>e))}},{name:"LogGamma",complexity:8e3,signature:{domain:["Function","Number","Number","Number"],N:(e,i)=>Wr(i[0],(e=>Tn(e)),(i=>lt(e,i)),(e=>e))}},{name:"Ln",description:"Natural Logarithm",wikidata:"Q204037",complexity:4e3,signature:{domain:["Function","Number","Number"],N:(e,i)=>Wr(i[0],(i=>i>=0?Math.log(i):e.complex(i).log()),(i=>i.isNeg()?e.complex(i.toNumber()).log():i.ln()),(e=>e.log()))}},{name:"Log",description:"Log(z, b = 10) = Logarithm of base b",wikidata:"Q11197",complexity:4100,signature:{domain:["Function","Number",["Maybe","Number"],"Number"],canonical:(e,i)=>{if(1===(i=Xn(i)).length)return e._fn("Log",[tt(e,i[0].canonical,"Number")]);if(2===i.length){const n=tt(e,i[1].canonical,"Number");return 10===n.numericValue?e._fn("Log",[tt(e,i[0].canonical,"Number")]):e._fn("Log",[tt(e,i[0].canonical,"Number"),n])}return e._fn("Log",et(e,i,2))},N:(e,i)=>void 0===i[1]?Wr(i[0],(i=>i>=0?Math.log10(i):e.complex(i).log().div(Math.LN10)),(i=>i.isNeg()?e.complex(i.toNumber()).log().div(Math.LN10):Ge.log10(i)),(e=>e.log().div(Math.LN10))):Qr(i[0],i[1],((e,i)=>Math.log(e)/Math.log(i)),((e,i)=>e.log(i)),((e,i)=>e.log().div("number"==typeof i?Math.log(i):i.log())))}},{name:"Lb",description:"Base-2 Logarithm",wikidata:"Q581168",complexity:4100,signature:{domain:["Function","Number","Number"],N:(e,i)=>Wr(i[0],(i=>i>=0?Math.log2(i):e.complex(i).log().div(Math.LN2)),(i=>i.isNeg()?Ge.log10(i):e.complex(i.toNumber()).log().div(Math.LN2)),(e=>e.log().div(Math.LN2)))}},{name:"Lg",description:"Base-10 Logarithm",wikidata:"Q966582",complexity:4100,signature:{domain:["Function","Number","Number"],N:(e,i)=>Wr(i[0],(i=>i>=0?Math.log10(i):e.complex(i).log().div(Math.LN10)),(i=>i.isNeg()?e.complex(i.toNumber()).log().div(Math.LN10):Ge.log10(i)),(e=>e.log().div(Math.LN10)))}},{name:"Max",description:"Maximum of two or more numbers",complexity:1200,signature:{domain:["Function",["Sequence","Number"],"Number"],simplify:(e,i)=>0===i.length?e._NEGATIVE_INFINITY:1===i.length?i[0]:e.box(["Max",...i]),evaluate:(e,i)=>{if(0===i.length)return e._NEGATIVE_INFINITY;let n;const t=[];for(const e of i)e.isNumber&&void 0!==e.numericValue?n&&!e.isGreater(n)||(n=e):t.push(e);return t.length>0?e.box(n?["Max",n,...t]:["Max",...t]):null!=n?n:e._NAN}}},{name:"Min",description:"Minimum of two or more numbers",complexity:1200,signature:{domain:["Function",["Sequence","Number"],"Number"],simplify:(e,i)=>0===i.length?e._NEGATIVE_INFINITY:1===i.length?i[0]:e.box(["Min",...i]),evaluate:(e,i)=>{if(0===i.length)return e._NEGATIVE_INFINITY;let n;const t=[];for(const e of i)e.isNumber&&void 0!==e.numericValue?n&&!e.isLess(n)||(n=e):t.push(e);return t.length>0?e.box(n?["Min",n,...t]:["Min",...t]):null!=n?n:e._NAN}}},{name:"Multiply",wikidata:"Q40276",associative:!0,commutative:!0,idempotent:!0,complexity:2100,signature:{domain:"NumericFunction",canonical:(e,i)=>is(e,i),simplify:(e,i)=>ns(e,i),evaluate:(e,i)=>ts(e,i),N:(e,i)=>ts(e,i,"N")}},{name:"Negate",description:"Additive Inverse",wikidata:"Q715358",complexity:2e3,signature:{domain:["Function","Number","Number"],codomain:(e,i)=>{const n=i[0].domain;if(!n.literal)return n;const t={PositiveNumber:"NegativeNumber",NonNegativeNumber:"NonPositiveNumber",NonPositiveNumber:"NonNegativeNumber",NegativeNumber:"PositiveNumber",PositiveInteger:"NegativeInteger",NonNegativeInteger:"NonPositiveInteger",NonPositiveInteger:"NonNegativeInteger",NegativeInteger:"PositiveInteger"}[n.literal];return t?e.domain(t):n},canonical:(e,i)=>Ot(i[0]),simplify:(e,i)=>Ft(0,i[0],"simplify"),evaluate:(e,i)=>Ft(0,i[0],"evaluate"),N:(e,i)=>Ft(0,i[0],"N"),sgn:(e,i)=>{const n=i[0].sgn;if(null!=n)return 0===n?0:n>0?-1:n<0?1:void 0}}},{name:"Power",wikidata:"Q33456",commutative:!1,complexity:3500,signature:{domain:["Function","Number","Number","Number"],canonical:(e,i)=>{var n;return null!==(n=Yr(e,i[0],i[1]))&&void 0!==n?n:e._fn("Power",i)},simplify:(e,i)=>Xr(e,i[0],i[1],"simplify"),evaluate:(e,i)=>Xr(e,i[0],i[1],"evaluate"),N:(e,i)=>Xr(e,i[0],i[1],"N")}},{name:"Product",wikidata:"Q901718",complexity:1e3,hold:"first",signature:{domain:["Function","Anything","Tuple","Number"],canonical:(e,i)=>function(e,i,n){var t,r,s,o,a,l,u,c;null!=i||(i=e.error(["missing","Function"]));let h=null,m=null,d=null;return n&&"Tuple"!==n.head&&"Triple"!==n.head&&"Pair"!==n.head&&"Single"!==n.head?h=n:n&&(h=null!==(r=null===(t=n.ops)||void 0===t?void 0:t[0])&&void 0!==r?r:null,m=null!==(a=null===(o=null===(s=n.ops)||void 0===s?void 0:s[1])||void 0===o?void 0:o.canonical)&&void 0!==a?a:null,d=null!==(c=null===(u=null===(l=n.ops)||void 0===l?void 0:l[2])||void 0===u?void 0:u.canonical)&&void 0!==c?c:null),h&&"Hold"===h.head&&(h=h.op1),h&&"ReleaseHold"===h.head&&(h=h.op1.evaluate()),null!=h||(h=e.symbol("Nothing")),h=h.symbol?e.hold(h):e.error(["incompatible-domain","Symbol",h.domain]),m&&(m=tt(e,m,"ExtendedRealNumber")),d&&(m=tt(e,d,"ExtendedRealNumber")),n=m&&d?e.tuple([h,m,d]):d?e.tuple([h,null!=m?m:e._NEGATIVE_INFINITY,d]):m?e.tuple([h,m]):h,e._fn("Product",[i,n])}(e,i[0],i[1]),simplify:(e,i)=>ss(e,i[0],i[1],"simplify"),evaluate:(e,i)=>ss(e,i[0],i[1],"evaluate"),N:(e,i)=>ss(e,i[0],i[1],"N")}},{name:"Rational",complexity:2400,signature:{domain:["Function","Number",["Maybe","Number"],"RationalNumber"],canonical:(e,i)=>{var n;return 0===(i=Xn(i)).length?e._fn("Rational",[e.error(["missing","Number"])]):1===i.length?e._fn("Rational",[tt(e,i[0].canonical,"ExtendedRealNumber")]):2===(i=null!==(n=nt(e.domain(["Function","Integer","Integer","RationalNumber"]),i))&&void 0!==n?n:i).length&&i[0].isValid&&i[1].isValid?os(e,i[0],i[1]):e._fn("Rational",i)},simplify:(e,i)=>{if(2===i.length)return as(e,i[0],i[1])},evaluate:(e,i)=>{if(2===i.length){const[n,t]=[Ln(i[0]),Ln(i[1])];return null!==n&&null!==t?e.number([n,t]):void 0}const n=Dn(i[0].N());if(null!==n)return e.number(function(e){if(!Number.isFinite(e))return e;if(0==e%1)return e;let i=Math.floor(e),n=1,t=0,r=i,s=1;for(;e-i>1e-15*s*s;){i=Math.floor(e=1/(e-i));const o=n;n=r;const a=t;t=s,r=o+i*n,s=a+i*t}return[r,s]}(n))},N:(e,i)=>1===i.length?i[0]:Qr(i[0],i[1],((e,i)=>e/i),((e,i)=>e.div(i)),((e,i)=>e.div(i)))}},{name:"Root",complexity:3200,signature:{domain:["Function","Number","Number","Number"],canonical:(e,i)=>{var n,t,r;if((i=Xn(i)).length>2)return e._fn("Root",et(e,i,2));const[s,o]=[tt(e,null===(n=i[0])||void 0===n?void 0:n.canonical,"Number"),tt(e,null===(t=i[1])||void 0===t?void 0:t.canonical,"Number")];return o.isValid&&s.isValid?null!==(r=Yr(e,s,e.inverse(o)))&&void 0!==r?r:e._fn("Power",[s,e.inverse(o)]):e._fn("Root",[s,o])}}},{name:"Round",complexity:1250,signature:{domain:["Function","Number","Number"],evaluate:(e,i)=>Wr(i[0],Math.round,(e=>e.round()),(e=>e.round(0)))}},{name:"Sign",complexity:1200,signature:{domain:["Function","Number",["Range",-1,1]],simplify:(e,i)=>{const n=i[0].sgn;return 0===n?e._ZERO:1===n?e._ONE:-1===n?e._NEGATIVE_ONE:void 0},evaluate:(e,i)=>{const n=i[0].sgn;return 0===n?e._ZERO:1===n?e._ONE:-1===n?e._NEGATIVE_ONE:void 0},N:(e,i)=>{const n=i[0].sgn;return 0===n?e._ZERO:1===n?e._ONE:-1===n?e._NEGATIVE_ONE:void 0}}},{name:"SignGamma",description:"The sign of the gamma function: -1 or +1",complexity:7900},{name:"Sqrt",description:"Square Root",wikidata:"Q134237",complexity:3e3,signature:{domain:["Function","Number","Number"],canonical:(e,i)=>{var n;return null!==(n=Yr(e,i[0],e._HALF))&&void 0!==n?n:e._fn("Power",[i[0],e._HALF])},simplify:(e,i)=>es(e,i[0],"simplify"),evaluate:(e,i)=>es(e,i[0],"evaluate"),N:(e,i)=>es(e,i[0],"N")}},{name:"Square",wikidata:"Q3075175",complexity:3100,signature:{domain:["Function","Number","Number"],canonical:(e,i)=>{var n;return null!==(n=Yr(e,i[0],e.number(2)))&&void 0!==n?n:e._fn("Power",[i[0],e.number(2)])}}},{name:"Subtract",wikidata:"Q40754",complexity:1350,signature:{domain:["Function","Number",["Maybe","Number"],"Number"],canonical:(e,i)=>1===(i=Xn(i.map((e=>e.canonical)))).length?Ot(i[0]):2!==(i=et(e,i,2)).length?e._fn("Subtract",i):i.every((e=>e.isValid))?Zr(e,[i[0],Ot(i[1])]):e._fn("Subtract",i)}},{name:"Sum",wikidata:"Q218005",complexity:1e3,hold:"all",signature:{domain:["Function","Anything","Tuple","Number"],canonical:(e,i)=>function(e,i,n){var t,r,s,o,a,l,u,c,h;null!=i||(i=e.error(["missing","Function"]));let m=null,d=null,f=null;n&&"Tuple"!==n.head&&"Triple"!==n.head&&"Pair"!==n.head&&"Single"!==n.head?m=n:n&&(m=null!==(r=null===(t=n.ops)||void 0===t?void 0:t[0])&&void 0!==r?r:null,d=null!==(a=null===(o=null===(s=n.ops)||void 0===s?void 0:s[1])||void 0===o?void 0:o.canonical)&&void 0!==a?a:null,f=null!==(c=null===(u=null===(l=n.ops)||void 0===l?void 0:l[2])||void 0===u?void 0:u.canonical)&&void 0!==c?c:null),"Hold"===(null==m?void 0:m.head)&&(m=m.op1),"ReleaseHold"===(null==m?void 0:m.head)&&(m=null===(h=m.op1)||void 0===h?void 0:h.evaluate()),null!=m||(m=e.symbol("Nothing")),m.symbol||(m=e.error(["incompatible-domain","Symbol",m.domain])),m.symbol&&e.pushScope({symbolTable:{symbols:[{name:m.symbol,domain:"Integer"}]}});const g=i.canonical;return m.symbol&&(e.popScope(),m=m=e.hold(m)),n=d&&f?e.tuple([m,d,f]):f?e.tuple([m,null!=d?d:e._NEGATIVE_INFINITY,f]):d?e.tuple([m,d]):m,e._fn("Sum",[g,n])}(e,i[0],i[1]),simplify:(e,i)=>Ur(e,i[0],i[1],"simplify"),evaluate:(e,i)=>Ur(e,i[0],i[1],"evaluate"),N:(e,i)=>Ur(e,i[0],i[1],"N")}}]},{symbols:[{name:"e",domain:"TranscendentalNumber",constant:!0,hold:!1,value:"ExponentialE"},{name:"i",domain:"ImaginaryNumber",constant:!0,hold:!1,imaginary:!0,value:"ImaginaryUnit"},{name:"MachineEpsilon",domain:"RealNumber",hold:!0,constant:!0,real:!0,value:{num:Number.EPSILON.toString()}},{name:"Half",constant:!0,hold:!1,value:["Rational",1,2]},{name:"ImaginaryUnit",domain:"ImaginaryNumber",constant:!0,hold:!0,wikidata:"Q193796",imaginary:!0,value:["Complex",0,1]},{name:"ExponentialE",domain:"TranscendentalNumber",algebraic:!1,wikidata:"Q82435",constant:!0,hold:!0,real:!0,value:e=>Bn(e)?e._BIGNUM_ONE.exp():Math.exp(1)},{name:"GoldenRatio",domain:"AlgebraicNumber",wikidata:"Q41690",constant:!0,algebraic:!0,hold:!1,value:["Divide",["Add",1,["Sqrt",5]],2]},{name:"CatalanConstant",domain:"RealNumber",algebraic:void 0,wikidata:"Q855282",constant:!0,hold:!0,value:{num:"0.91596559417721901505460351493238411077414937428167\n 21342664981196217630197762547694793565129261151062\n 48574422619196199579035898803325859059431594737481\n 15840699533202877331946051903872747816408786590902\n 47064841521630002287276409423882599577415088163974\n 70252482011560707644883807873370489900864775113225\n 99713434074854075532307685653357680958352602193823\n 23950800720680355761048235733942319149829836189977\n 06903640418086217941101917532743149978233976105512\n 24779530324875371878665828082360570225594194818097\n 53509711315712615804242723636439850017382875977976\n 53068370092980873887495610893659771940968726844441\n 66804621624339864838916280448281506273022742073884\n 31172218272190472255870531908685735423498539498309\n 91911596738846450861515249962423704374517773723517\n 75440708538464401321748392999947572446199754961975\n 87064007474870701490937678873045869979860644874974\n 64387206238513712392736304998503539223928787979063\n 36440323547845358519277777872709060830319943013323\n 16712476158709792455479119092126201854803963934243\n "}},{name:"EulerGamma",domain:"RealNumber",algebraic:void 0,wikidata:"Q273023",hold:!0,constant:!0,value:{num:"0.57721566490153286060651209008240243104215933593992359880576723488486772677766\n 467093694706329174674951463144724980708248096050401448654283622417399764492353\n 625350033374293733773767394279259525824709491600873520394816567085323315177661\n 152862119950150798479374508570574002992135478614669402960432542151905877553526\n 733139925401296742051375413954911168510280798423487758720503843109399736137255\n 306088933126760017247953783675927135157722610273492913940798430103417771778088\n 154957066107501016191663340152278935867965497252036212879226555953669628176388\n 792726801324310104765059637039473949576389065729679296010090151251959509222435\n 014093498712282479497471956469763185066761290638110518241974448678363808617494\n 551698927923018773910729457815543160050021828440960537724342032854783670151773\n 943987003023703395183286900015581939880427074115422278197165230110735658339673"}}]},{functions:[{name:"PreIncrement",signature:{domain:["Function","Number","Number"]}},{name:"PreDecrement",signature:{domain:["Function","Number","Number"]}}]}];function us(e,i,n){if("simplify"!==n){const t=i.numericValue;if(null!==t){if("number"==typeof t)return e.number(Math.abs(t));if(t instanceof Ge)return e.number(t.abs());if(t instanceof Ue)return e.number(t.abs());if(mt(t))return e.number("N"===n?Math.abs(t[0]/t[1]):[Math.abs(t[0]),t[1]]);if(dt(t)){const[i,r]=t;return e.number("N"===n?i.div(r).abs():[i.abs(),r])}}}return i.isNonNegative?i:i.isNegative?e.negate(i):void 0}const cs=[{functions:[{name:"Integrate",wikidata:"Q80091",hold:"all",signature:{domain:["Function","Anything",["Union","Nothing","Tuple","Symbol"],"Number"],canonical:(e,i)=>{var n,t,r,s,o,a,l,u,c;const h=null!==(n=i[0])&&void 0!==n?n:e.error(["missing","Function"]);let m=i[1],d=null,f=null,g=null;return m&&"Tuple"!==m.head&&"Triple"!==m.head&&"Pair"!==m.head&&"Single"!==m.head?d=m:m&&(d=null!==(r=null===(t=m.ops)||void 0===t?void 0:t[0])&&void 0!==r?r:null,f=null!==(a=null===(o=null===(s=m.ops)||void 0===s?void 0:s[1])||void 0===o?void 0:o.canonical)&&void 0!==a?a:null,g=null!==(c=null===(u=null===(l=m.ops)||void 0===l?void 0:l[2])||void 0===u?void 0:u.canonical)&&void 0!==c?c:null),d&&"Hold"===d.head&&(d=d.op1),d&&"ReleaseHold"===d.head&&(d=d.op1.evaluate()),null!=d||(d=e.symbol("Nothing")),d.symbol||(d=e.error(["incompatible-domain","Symbol",d.domain])),f&&(f=tt(e,f,"Number")),g&&(g=tt(e,g,"Number")),m=f&&g?e.tuple([d,f,g]):g?e.tuple([d,e._NEGATIVE_INFINITY,g]):f?e.tuple([d,f]):d,e._fn("Integrate",[h,m])}}}]}],hs=[{symbols:[{name:"Nothing",domain:"Nothing"}]},{functions:[{name:"List",complexity:8200,signature:{domain:["Function",["Maybe",["Sequence","Anything"]],"List"]}},{name:"KeyValuePair",description:"A key/value pair",complexity:8200,signature:{domain:["Function","String","Anything",["Tuple","String","Anything"]],codomain:(e,i)=>e.domain(["Tuple","String",i[1].domain]),canonical:(e,i)=>{var n,t;const r=tt(e,null===(n=i[0])||void 0===n?void 0:n.canonical,"String"),s=tt(e,null===(t=i[1])||void 0===t?void 0:t.canonical,"Value");return e.tuple([r,s])}}},{name:"Single",description:"A tuple with a single element",complexity:8200,signature:{domain:["Function","Anything",["Tuple","Anything"]],codomain:(e,i)=>e.domain(["Tuple",i[0].domain]),canonical:(e,i)=>e.tuple(et(e,i.map((e=>e.canonical)),1))}},{name:"Pair",description:"A tuple of two elements",complexity:8200,signature:{domain:["Function","Anything","Anything",["Tuple","Anything","Anything"]],codomain:(e,i)=>e.domain(["Tuple",i[0].domain,i[1].domain]),canonical:(e,i)=>e.tuple(et(e,i.map((e=>e.canonical)),2))}},{name:"Triple",description:"A tuple of three elements",complexity:8200,signature:{domain:["Function","Anything","Anything","Anything",["Tuple","Anything","Anything","Anything"]],codomain:(e,i)=>e.domain(["Tuple",i[0].domain,i[1].domain,i[2].domain]),canonical:(e,i)=>e.tuple(et(e,i.map((e=>e.canonical)),3))}},{name:"Tuple",description:"A fixed number of heterogeneous elements",complexity:8200,signature:{domain:["Function",["Sequence","Anything"],["Tuple",["Sequence","Anything"]]],canonical:(e,i)=>e.tuple(i.map((e=>e.canonical))),codomain:(e,i)=>e.domain(["Tuple",...i.map((e=>e.domain))])}}]},{functions:[{name:"BaseForm",description:"`BaseForm(expr, base=10)`",complexity:9e3,inert:!0,signature:{domain:["Function","Value",["Maybe","Integer"],"Value"],codomain:(e,i)=>i[0].domain}},{name:"Delimiter",complexity:9e3,hold:"first",signature:{domain:["Function","Anything",["Maybe","String"],["Maybe","String"],"Anything"],codomain:(e,i)=>i[0].domain,canonical:(e,i)=>{var n,t;return null!==(t=null===(n=i[0])||void 0===n?void 0:n.canonical)&&void 0!==t?t:e.box(["Sequence"])}}},{name:"Error",complexity:500,signature:{domain:["Function","Anything",["Maybe","Anything"],"Void"],canonical:(e,i)=>e._fn("Error",i)}},{name:"ErrorCode",complexity:500,hold:"all",signature:{domain:["Function","String",["Maybe",["Sequence","Anything"]],"Anything"],canonical:(e,i)=>{var n,t;const r=tt(e,i[0],"String").string;return"incompatible-domain"===r?e._fn("ErrorCode",[e.string(r),e.domain(null!==(n=i[1])&&void 0!==n?n:"Anything"),e.domain(null!==(t=i[2])&&void 0!==t?t:"Anything")]):e._fn("ErrorCode",i)}}},{name:"Hold",hold:"all",signature:{domain:"Function",codomain:(e,i)=>i[0].symbol?e.domain("Symbol"):e.domain("Anything"),canonical:(e,i)=>1!==i.length?e._fn("Hold",et(e,i,1)):e._fn("Hold",[tt(e,i[0],"Anything")])}},{name:"HorizontalSpacing",signature:{domain:"Function",canonical:(e,i)=>2===i.length?i[0].canonical:e.box(["Sequence"])}},{name:"Style",complexity:9e3,inert:!0,signature:{domain:["Function","Anything",["Maybe","Dictionary"],"Anything"]}}]},{functions:[{name:"Apply",signature:{domain:"Function",evaluate:(e,i)=>hr(i[0],i.slice(1))}},{name:"About",signature:{domain:"Function"}},{name:"Block",signature:{domain:"Function"}},{name:"Domain",signature:{domain:["Function","Anything","Domain"],canonical:(e,i)=>e.domain(et(e,i.map((e=>e.canonical)),1)[0])}},{name:"Evaluate",hold:"all",signature:{domain:["Function","Anything","Anything"],codomain:(e,i)=>i[0].domain,canonical:(e,i)=>e._fn("Evaluate",et(e,i.map((e=>e.canonical)),1)),evaluate:(e,i)=>i[0].evaluate()}},{name:"Head",signature:{domain:"Function",evaluate:(e,i)=>{var n;const t=i[0];return"string"==typeof(null==t?void 0:t.head)?e.symbol(t.head):null!==(n=null==t?void 0:t.head)&&void 0!==n?n:e.symbol("Nothing")}}},{name:"Html",signature:{domain:["Function","Value","String"],evaluate:(e,i)=>(i.length,e.string(""))}},{name:"Lambda",wikidata:"Q567612",hold:"all",signature:{domain:["Function","Anything","Function"],codomain:(e,i)=>i[0].domain,canonical:(e,i)=>e._fn("Lambda",et(e,i,1))}},{name:"Signatures",signature:{domain:["Function","Symbol",["Maybe",["List","Domain"]]],canonical:(e,i)=>(i=et(e,i,1))[0].symbol?e._fn("Signatures",i):e._fn("Signatures",[e.error(["incompatible-domain","Symbol",i[0].domain],i[0])]),evaluate:(e,i)=>{const n=i[0].symbol;if(!n)return e.symbol("Nothing");const t=e.lookupFunction(n);return t?e.fn("List",[t.signature.domain]):e.symbol("Nothing")}}},{name:"Subscript",hold:"last",signature:{domain:["Function","Anything","Anything","Anything"],codomain:(e,i)=>(i[0].isFunction,i[0].domain),canonical:(e,i)=>{var n,t;const r=i[0],s=i[1];if(r.string&&s.isLiteral&&null!==Ln(s)){const i=Ln(s);if(i>1&&i<=36){const[n,t]=Cn(r.string,i);return t?e.error(["unexpected-digit",t[0]],["Latex",e.string(r.string)]):e.number(n)}}if(r.symbol){if(null===(n=r.symbolDefinition)||void 0===n?void 0:n.at)return e._fn("At",[r,s.canonical]);let i=null!==(t=s.string)&&void 0!==t?t:s.symbol;if(!i&&s.isLiteral&&null!==Ln(s)&&(i=Ln(s).toString()),i)return e.symbol(r.symbol+"_"+i)}return"Sequence"===s.head&&e._fn("Subscript",[r,e._fn("List",s.ops)]),e._fn("Subscript",i)}}},{name:"Symbol",complexity:500,description:"Construct a new symbol with a name formed by concatenating the arguments",threadable:!0,hold:"all",signature:{domain:["Function",["Sequence","Anything"],"Anything"],canonical:(e,i)=>{if(0===i.length)return e.symbol("Nothing");const n=i.map((e=>{var i,n,t,r;return null!==(r=null!==(n=null!==(i=e.symbol)&&void 0!==i?i:e.string)&&void 0!==n?n:e.isLiteral?null===(t=Ln(e))||void 0===t?void 0:t.toString():null)&&void 0!==r?r:""})).join("");return n.length>0?e.symbol(n):e.symbol("Nothing")}}},{name:"Tail",signature:{domain:["Function","Value",["List","Value"]],evaluate:(e,i)=>{var n;return i[0]?e._fn("List",null!==(n=i[0].ops)&&void 0!==n?n:[]):e._fn("List",[])}}},{name:"Timing",description:"`Timing(expr)` evaluates `expr` and return a `Pair` of the number of second elapsed for the evaluation, and the value of the evaluation",signature:{domain:["Function","Value",["Maybe","Integer"],["Tuple","Value","Number"]],evaluate:(e,i)=>{var n;if("Nothing"===i[1].symbol){const n=globalThis.performance.now(),t=i[0].evaluate(),r=1e3*(globalThis.performance.now()-n);return e.pair(e.number(r),t)}let t,r=Math.max(3,Math.round(null!==(n=Ln(i[1]))&&void 0!==n?n:3)),s=[];for(;r>0;){const e=globalThis.performance.now();t=i[0].evaluate(),s.push(1e3*(globalThis.performance.now()-e)),r-=1}const o=Math.max(...s),a=Math.min(...s);s=s.filter((e=>e>a&&e<o));const l=s.reduce(((e,i)=>e+i),0);return 0===l?e.pair(e.number(o),t):e.pair(e.number(l/s.length),t)}}}]},{functions:[{name:"FromDigits",description:"`FromDigits(s, base=10)` return an integer representation of the string `s` in base `base`.",signature:{domain:["Function","String",["Maybe",["Range",1,36]],"Integer"],evaluate:(e,i)=>{const n=i[0];if(!n.string)return e.error(["incompatible-domain","String",n.domain],n);const t=i[1];if(t.isNothing)return e.number(Number.parseInt(n.string,10));if(null===t.numericValue)return e.error(["unexpected-base",t.latex],t);const r=Dn(t);if(!Number.isInteger(r)||r<2||r>36)return e.error(["unexpected-base",r],t);const[s,o]=Cn(n.string,r);return o?e.error(["unexpected-digit",o[0]],{str:o}):e.number(s)}}},{name:"IntegerString",description:"`IntegerString(n, base=10)` return a string representation of the integer `n` in base `base`.",signature:{domain:["Function","Integer",["Maybe","Integer"],"String"],evaluate:(e,i)=>{var n,t;const r=i[0],s=null!==(n=Dn(r))&&void 0!==n?n:NaN;if(Number.isNaN(s)||!Number.isInteger(s))return void e.signal(e._fn("IntegerString",i),`Expected first argument as an integer. Got \\(${r.latex}$\\)`);const o=i[1];if(o.isNothing){const i=r.numericValue;return"number"==typeof i?e.string(Math.abs(i).toString()):i instanceof Ge?e.string(i.abs().toString()):e.string(Math.abs(Math.round(null!==(t=Dn(r))&&void 0!==t?t:NaN)).toString())}if(null===Ln(o))return void e.signal(e._fn("IntegerString",i),`Expected \`base\` as an integer between 2 and 36. Got \\(${o.latex}$\\)`);const a=Ln(o);if(!(a<2||a>36))return e.string(Math.abs(s).toString(a));e.signal(e._fn("IntegerString",i),"Expected `base` as an integer between 2 and 36. Got "+a)}}},{name:"String",threadable:!0,signature:{domain:["Function",["Maybe","Anything"],"String"],evaluate:(e,i)=>0===i.length?e.string(""):e.string(i.map((e=>{var i;return null!==(i=e.string)&&void 0!==i?i:e.toString()})).join(""))}}]},{functions:[{name:"JoinLatexTokens",signature:{domain:["Function",["Maybe",["Sequence","Anything"]],"String"],evaluate:(e,i)=>e.box(["Latex",e.string(ei(i.map((e=>{var i;return null!==(i=e.string)&&void 0!==i?i:e.latex}))))])}},{name:"Latex",signature:{domain:["Function",["Maybe",["Sequence","Anything"]],"String"],evaluate:(e,i)=>0===i.length?e.string(""):e.string(Xe(i.map((e=>{var i;return null!==(i=e.string)&&void 0!==i?i:e.toString()}))))}},{name:"SerializeLatex",hold:"all",signature:{domain:["Function",["Maybe",["Sequence","Anything"]],"String"],evaluate:(e,i)=>e.box(["Latex",e.string(Xe(i.map((e=>e.latex))))])}},{name:"SplitAsLatexTokens",description:"Split a LaTeX string into a list of LaTeX tokens",hold:"all",signature:{domain:["Function",["Maybe","Anything"],["List","String"]],evaluate:(e,i)=>{var n;if(0===i.length)return e._fn("List",[]);let t="";return t="Latex"===i[0].head?null!==(n=i[0].op1.string)&&void 0!==n?n:"":"LatexString"===i[0].head?Xe(i[0].ops.map((e=>e.latex))):i[0].latex,e._fn("List",Ke(t,[]).map((i=>e.string(i))))}}},{name:"ParseLatex",description:"Parse a LaTeX string and evaluate to a corresponding expression",signature:{domain:["Function",["Maybe","String"],"Anything"],evaluate:(e,i)=>{var n;return 0!==i.length&&i[0].string&&null!==(n=e.parse(i[0].string))&&void 0!==n?n:e.box(["Sequence"])}}}]}],ms={symbols:[{name:"True",wikidata:"Q16751793",domain:"Boolean",constant:!0},{name:"False",wikidata:"Q5432619",domain:"Boolean",constant:!0},{name:"Maybe",wikidata:"Q781546",domain:"MaybeBoolean",constant:!0}],functions:[{name:"And",wikidata:"Q191081",threadable:!0,associative:!0,commutative:!0,idempotent:!0,complexity:1e4,signature:{domain:"LogicOperator",simplify:ds,evaluate:ds}},{name:"Or",wikidata:"Q1651704",threadable:!0,associative:!0,commutative:!0,idempotent:!0,complexity:1e4,signature:{domain:"LogicOperator",simplify:fs,evaluate:fs}},{name:"Not",wikidata:"Q190558",involution:!0,complexity:10100,signature:{domain:"LogicOperator",simplify:gs,evaluate:gs}},{name:"Equivalent",wikidata:"Q220433",complexity:10200,signature:{domain:"LogicOperator",simplify:ps,evaluate:ps}},{name:"Implies",wikidata:"Q7881229",complexity:10200,signature:{domain:"LogicOperator",simplify:vs,evaluate:vs}},{name:"Exists",signature:{domain:"MaybeBoolean"}},{name:"If",hold:"rest",signature:{domain:"Function",codomain:(e,i)=>e.domain(["Union",i[0],i[1]]),simplify:(e,i)=>{const n=i[0];return n&&"True"===n.symbol?i[1]?i[1].simplify():e.box("Nothing"):i[2]?i[2].simplify():e.box("Nothing")},evaluate:(e,i)=>{const n=i[0];return n&&"True"===n.symbol?i[1]?i[1].evaluate():e.box("Nothing"):i[2]?i[2].evaluate():e.box("Nothing")},N:(e,i)=>{const n=i[0];return n&&"True"===n.symbol?i[1]?i[1].N():e.box("Nothing"):i[2]?i[2].N():e.box("Nothing")}}},{name:"Loop",hold:"all",signature:{domain:"Function",simplify:(e,i)=>{var n,t;return null!==(t=null===(n=i[0])||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box("Nothing")},evaluate:(e,i)=>{var n;const t=null!==(n=i[0])&&void 0!==n?n:e.box("Nothing");if(t.isNothing)return t;let r,s=0;do{r=t.evaluate(),s+=1}while("Return"!==r.head&&s<e.iterationLimit);return"Return"===r.head?r.op1:e.error("iteration-limit-exceeded")},N:(e,i)=>{const n=i[0];return n&&"True"===n.symbol?i[1]?i[1].N():e.box("Nothing"):i[2]?i[2].N():e.box("Nothing")}}},{name:"Which",hold:"all",signature:{domain:"Function",codomain:(e,i)=>function(e,i){let n=null;for(let e=1;e<=i.length-1;e+=2)n=n?Rr(n,i[e].domain):i[e].domain;return null!=n?n:e.domain("Nothing")}(e,i),evaluate:(e,i)=>bs(e,i,"evaluate"),N:(e,i)=>bs(e,i,"N")}}]};function ds(e,i){if(0===i.length)return e.symbol("True");const n=[];for(const t of i){if("False"===t.symbol)return e.symbol("False");if("True"!==t.symbol){let i=!1;for(const r of n)if(r.isSame(t))i=!0;else if("Not"===t.head&&t.op1.isSame(r)||"Not"===r.head&&r.op1.isSame(t))return e.symbol("False");i||n.push(t)}}return 0===n.length?e.symbol("True"):1===n.length?n[0]:e._fn("And",n)}function fs(e,i){if(0===i.length)return e.symbol("True");const n=[];for(const t of i){if("True"===t.symbol)return e.symbol("True");if("False"!==t.symbol){let i=!1;for(const r of n)if(r.isSame(t))i=!0;else if("Not"===t.head&&t.op1.isSame(r)||"Not"===r.head&&r.op1.isSame(t))return e.symbol("True");i||n.push(t)}}return 0===n.length?e.symbol("True"):1===n.length?n[0]:e._fn("Or",n)}function gs(e,i){const n=i[0].symbol;return"True"===n?e.symbol("False"):"False"===n?e.symbol("True"):"Maybe"===n?e.symbol("Maybe"):void 0}function ps(e,i){const n=i[0].symbol,t=i[1].symbol;return"True"===n&&"True"===t||"False"===n&&"False"===t?e.symbol("True"):"True"===n&&"False"===t||"False"===n&&"True"===t?e.symbol("False"):"Maybe"===n||"Maybe"===t?e.symbol("Maybe"):void 0}function vs(e,i){const n=i[0].symbol,t=i[1].symbol;return"True"===n&&"True"===t||"False"===n&&"False"===t||"False"===n&&"True"===t?e.symbol("True"):"True"===n&&"False"===t?e.symbol("False"):"Maybe"===n||"Maybe"===t?e.symbol("Maybe"):void 0}function bs(e,i,n){let t=0;for(;t<i.length-1;){if("True"===i[t].evaluate().symbol)return i[t+1]?"N"===n?i[t+1].N():i[t+1].evaluate():e.symbol("Undefined");t+=2}return e.symbol("Undefined")}const ys=[{functions:[{name:"Expand",description:"Expand out products and positive integer powers",signature:{domain:["Function","Value","Value"],evaluate:(e,i)=>Pt(i[0])}}]}],Ns={functions:[{name:"Equal",commutative:!0,complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>{var n;return i=null!==(n=Kn(Xn(i).map((e=>e.canonical)),"Equal"))&&void 0!==n?n:i,e._fn("Equal",i)},evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let n;for(const t of i)if(n){if(!0!==n.isEqual(t))return e.symbol("False")}else n=t;return e.symbol("True")}}},{name:"NotEqual",wikidata:"Q28113351",commutative:!0,complexity:11e3,signature:{domain:"RelationalOperator",evaluate:(e,i)=>{if(i.length<2)return e.symbol("False");let n;for(const t of i)if(n){if(!0===n.isEqual(t))return e.symbol("False")}else n=t;return e.symbol("True")}}},{name:"Less",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>{var n;return i=null!==(n=Kn(Xn(i).map((e=>e.canonical)),"Less"))&&void 0!==n?n:i,e._fn("Less",i)},evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let n;for(const t of i){if(!t.isNumber)return;if(n){const i=e.fn("Subtract",[t,n]).N().sgn;if(null==i)return;if(i<=0)return e.symbol("False");n=t}else n=t}return e.symbol("True")}}},{name:"NotLess",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Less",i)])}},{name:"Greater",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Less",i.reverse()),evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let n;for(const t of i){if(!t.isNumber)return;if(n){const i=e.fn("Subtract",[t,n]).N().sgn;if(null==i)return;if(i>=0)return e.symbol("False");n=t}else n=t}return e.symbol("True")}}},{name:"NotGreater",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Greater",i)])}},{name:"LessEqual",complexity:11e3,signature:{domain:"RelationalOperator",evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let n;for(const t of i){if(!t.isNumber)return;if(n){const i=e.fn("Subtract",[t,n]).N().sgn;if(null==i)return;if(i<0)return e.symbol("False");n=t}else n=t}return e.symbol("True")}}},{name:"NotLessNotEqual",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("LessEqual",i)])}},{name:"GreaterEqual",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("LessEqual",i.reverse()),evaluate:(e,i)=>{if(i.length<2)return e.symbol("True");let n;for(const t of i){if(!t.isNumber)return;if(n){const i=e.fn("Subtract",[t,n]).N().sgn;if(null==i)return;if(i>0)return e.symbol("False");n=t}else n=t}return e.symbol("True")}}},{name:"NotGreaterNotEqual",complexity:11e3,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("GreaterEqual",i)])}},{name:"TildeFullEqual",description:"Indicate isomorphism, congruence and homotopic equivalence",signature:{domain:"RelationalOperator"}},{name:"NotTildeFullEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("TildeFullEqual",i)])}},{name:"TildeEqual",description:"Approximately or asymptotically equal",complexity:11e3,signature:{domain:"RelationalOperator"}},{name:"NotTildeEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("TildeEqual",i)])}},{name:"Approx",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotApprox",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Approx",i)])}},{name:"ApproxEqual",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotApproxEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("ApproxEqual",i)])}},{name:"ApproxNotEqual",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotApproxNotEqual",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("ApproxNotEqual",i)])}},{name:"Precedes",complexity:11100,signature:{domain:"RelationalOperator"}},{name:"NotPrecedes",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Precedes",i)])}},{name:"Succeeds",signature:{domain:"RelationalOperator"}},{name:"NotSucceeds",complexity:11100,signature:{domain:"RelationalOperator",canonical:(e,i)=>e._fn("Not",[e._fn("Succeeds",i)])}}]},_s={symbols:[{name:"EmptySet",domain:"Set",constant:!0,wikidata:"Q226183"}],functions:[{name:"Element",complexity:11200,hold:"all",signature:{domain:"Predicate",canonical:(e,i)=>2===(i=et(e,Xn(i).map((e=>e.canonical)),2)).length&&Dr(i[1])?e._fn("Element",[i[0],e.domain(i[1])]):e._fn("Element",i),evaluate:(e,i)=>function(e,i){const[n,t]=i;if(t.string)return n.string&&t.string.includes(n.string)?e.symbol("True"):e.symbol("False");if(t.keys){if(n.string)for(const i of t.keys)if(i===n.string)return e.symbol("True");return e.symbol("False")}if("List"===t.head){if("List"===n.head){let i=!1;for(let r=0;r<t.nops-n.nops+1;++r){i=!0;for(let e=0;e<n.nops;++e)if(!t.ops[r+e].isEqual(n.ops[e])){i=!1;break}if(i)return e.symbol("True")}return e.symbol("False")}const i="Hold"===n.head?n.op1:n;for(const n of t.ops)if(i.isEqual(n))return e.symbol("True");return e.symbol("False")}return Dr(t)?n.domain.isCompatible(e.domain(t))?e.symbol("True"):e.symbol("False"):e._fn("Element",[n,t])}(e,i)}},{name:"NotElement",complexity:11200,hold:"all",signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("Element",i)])}},{name:"Subset",complexity:11200,signature:{domain:"Predicate"}},{name:"NotSubset",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("Subset",i)])}},{name:"Superset",complexity:11200,signature:{domain:"Predicate"}},{name:"SupersetEqual",complexity:11200,signature:{domain:"Predicate"}},{name:"NotSuperset",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("Superset",i)])}},{name:"NotSupersetEqual",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("SupersetEqual",i)])}},{name:"SubsetEqual",complexity:11200,signature:{domain:"Predicate"}},{name:"NotSubsetNotEqual",complexity:11200,signature:{domain:"Predicate",canonical:(e,i)=>e.fn("Not",[e.fn("SubsetEqual",i)])}},{name:"CartesianProduct",wikidata:"Q173740",signature:{domain:["Function","Set",["Sequence","Set"],"Set"]}},{name:"Complement",wikidata:"Q242767",signature:{domain:["Function","Set","Set"]}},{name:"Intersection",wikidata:"Q185837",threadable:!0,associative:!0,commutative:!0,involution:!0,signature:{domain:["Function","Set",["Sequence","Set"],"Set"],evaluate:function(e,i){return e.symbol("EmptySet")}}},{name:"Union",wikidata:"Q185359",threadable:!0,associative:!0,commutative:!0,involution:!0,signature:{domain:["Function","Set",["Sequence","Set"],"Set"],evaluate:function(e,i){return e.symbol("False")}}},{name:"SetMinus",wikidata:"Q18192442",signature:{domain:["Function","Set","Value","Set"],evaluate:function(e,i){return e.symbol("EmptySet")}}},{name:"SymmetricDifference",wikidata:"Q1147242",signature:{domain:["Function","Set",["Sequence","Set"],"Set"]}}]},xs=[{symbols:[{name:"Pi",domain:"TranscendentalNumber",algebraic:!1,constant:!0,hold:!0,wikidata:"Q167",value:e=>Bn(e)?e._BIGNUM_PI:Math.PI}],functions:[{name:"Degrees",signature:{domain:["Function","Number","Number"],canonical:(e,i)=>{if(1!==(i=et(e,Xn(i),1)).length)return e.box(["Degrees",i]);const n=tt(e,i[0].canonical,"Number");return n.isValid&&n.isLiteral?e.mul([n,e.box(["Divide","Pi",180])]):e.box(["Degrees",n])},evaluate:(e,i)=>e.mul([i[0],e.box(["Divide","Pi",180])])}},{name:"Hypot",signature:{domain:["Function","Number","Number","NonNegativeNumber"],simplify:(e,i)=>e.box(["Sqrt",["Add",["Square",i[0]],["Square",i[1]]]]).simplify(),evaluate:["Lambda",["Sqrt",["Add",["Square","_1"],["Square","_2"]]]]}},{name:"Sin",complexity:5e3,signature:{domain:["Function","Number",["Interval",-1,1]],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Sin",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:Un(e)?e.box(["Divide",["Subtract",["Exp",["Multiply","ImaginaryUnit",i[0]]],["Exp",["Multiply","ImaginaryUnit",["Negate",i[0]]]]],["Complex",0,2]]).simplify():void 0},evaluate:(e,i)=>Os(e,"evaluate","Sin",i[0]),N:(e,i)=>Os(e,"N","Sin",i[0])}}]},{functions:[{name:"Arctan",wikidata:"Q2257242",complexity:5200,signature:{domain:["Function","Number","ExtendedRealNumber"],simplify:(e,i)=>{var n;return null===(n=Ms(e,"Arctan",i[0]))||void 0===n?void 0:n.simplify()},evaluate:(e,i)=>Os(e,"evaluate","Arctan",i[0]),N:(e,i)=>Os(e,"N","Arctan",i[0])}},{name:"Arctan2",wikidata:"Q776598",complexity:5200,signature:{domain:["Function","Number","Number","Number"],N:(e,i)=>Qr(i[0],i[1],Math.atan2,((e,i)=>Ge.atan2(e,i)))}},{name:"Cos",complexity:5050,signature:{domain:["Function","Number",["Interval",-1,1]],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Cos",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Sin",["Add",i[0],["Multiply","Half","Pi"]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Cos",i[0]),N:(e,i)=>Os(e,"N","Cos",i[0])}},{name:"Tan",complexity:5100,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Tan",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",["Sin",i[0]],["Cos",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Tan",i[0]),N:(e,i)=>Os(e,"N","Tan",i[0])}}]},{functions:[{name:"Arcosh",complexity:6200,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Arcosh",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Ln",["Add",i[0],["Sqrt",["Subtract",["Square",i[0]],1]]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Arcosh",i[0]),N:(e,i)=>Os(e,"N","Arcosh",i[0])}},{name:"Arcsin",complexity:5500,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Arcsin",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Multiply",2,["Arctan2",i[0],["Add",1,["Sqrt",["Subtract",1,["Square",i[0]]]]]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Arcsin",i[0]),N:(e,i)=>Os(e,"N","Arcsin",i[0])}},{name:"Arsinh",complexity:6100,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Arsinh",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Ln",["Add",i[0],["Sqrt",["Add",["Square",i[0]],1]]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Arsinh",i[0]),N:(e,i)=>Os(e,"N","Arsinh",i[0])}},{name:"Artanh",complexity:6300,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Artanh",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Multiply","Half",["Ln",["Divide",["Add",1,i[0]],["Subtract",1,i[0]]]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Artanh",i[0]),N:(e,i)=>Os(e,"N","Artanh",i[0])}},{name:"Cosh",complexity:6050,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Cosh",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Multiply","Half",["Add",["Exp",i[0]],["Exp",["Negate",i[0]]]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Cosh",i[0]),N:(e,i)=>Os(e,"N","Cosh",i[0])}},{name:"Cot",complexity:5600,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Cot",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",["Cos",i[0]],["Sin",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Cot",i[0]),N:(e,i)=>Os(e,"N","Cot",i[0])}},{name:"Csc",description:"Cosecant",complexity:5600,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Csc",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",1,["Sin",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Csc",i[0]),N:(e,i)=>Os(e,"N","Csc",i[0])}},{name:"Haversine",wikidata:"Q2528380",signature:{domain:["Function","ExtendedRealNumber",["Interval",0,1]],evaluate:["Lambda",["Divide",["Subtract",1,["Cos","_1"]],2]]}},{name:"InverseHaversine",signature:{domain:["Function","ExtendedRealNumber","RealNumber"],evaluate:["Lambda",["Multiply",2,["Arcsin",["Sqrt","_1"]]]]}},{name:"Sec",description:"Secant, inverse of cosine",complexity:5500,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Sec",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",1,["Cos",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Sec",i[0]),N:(e,i)=>Os(e,"N","Sec",i[0])}},{name:"Sinh",complexity:6e3,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Sinh",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Multiply","Half",["Subtract",["Exp",i[0]],["Exp",["Negate",i[0]]]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Sinh",i[0]),N:(e,i)=>Os(e,"N","Sinh",i[0])}}]},{functions:[{name:"Csch",complexity:6200,signature:{domain:["Function","Number","ExtendedRealNumber"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Csch",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",1,["Sinh",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Csch",i[0]),N:(e,i)=>Os(e,"N","Csch",i[0])}},{name:"Sech",complexity:6200,signature:{domain:["Function","Number",["Interval",-1,1]],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Sech",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",1,["Cosh",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Sech",i[0]),N:(e,i)=>Os(e,"N","Sech",i[0])}},{name:"Tanh",complexity:6200,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Tanh",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",["Sinh",i[0]],["Cosh",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Tanh",i[0]),N:(e,i)=>Os(e,"N","Tanh",i[0])}}]},{functions:[{name:"Arccos",complexity:5550,signature:{domain:["Function","Number","ExtendedRealNumber"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Arccos",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Subtract",["Divide","Pi",2],["Arcsin",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Arccos",i[0]),N:(e,i)=>Os(e,"N","Arccos",i[0])}},{name:"Arccot",numeric:!0,signature:{domain:["Function","Number","ExtendedRealNumber"],evaluate:(e,i)=>Os(e,"evaluate","Arccot",i[0]),N:(e,i)=>Os(e,"N","Arccot",i[0])}},{name:"Arcoth",numeric:!0,signature:{domain:["Function","Number","ExtendedRealNumber"],evaluate:(e,i)=>Os(e,"evaluate","Arcoth",i[0]),N:(e,i)=>Os(e,"N","Arcoth",i[0])}},{name:"Arcsch",numeric:!0,signature:{domain:["Function","Number","ExtendedRealNumber"],evaluate:(e,i)=>Os(e,"evaluate","Arcsch",i[0]),N:(e,i)=>Os(e,"N","Arcsch",i[0])}},{name:"Arcsec",numeric:!0,signature:{domain:["Function","Number","ExtendedRealNumber"],evaluate:(e,i)=>Os(e,"evaluate","Arcsec",i[0]),N:(e,i)=>Os(e,"N","Arcsec",i[0])}},{name:"Arsech",numeric:!0,signature:{domain:["Function","Number","ExtendedRealNumber"],evaluate:(e,i)=>Os(e,"evaluate","Arsech",i[0]),N:(e,i)=>Os(e,"N","Arsech",i[0])}},{name:"Arccsc",numeric:!0,signature:{domain:["Function","Number","ExtendedRealNumber"],evaluate:(e,i)=>Os(e,"evaluate","Arccsc",i[0]),N:(e,i)=>Os(e,"N","Arccsc",i[0])}},{name:"Coth",complexity:6300,signature:{domain:["Function","Number","Number"],simplify:(e,i)=>{var n,t;return null!==(t=null===(n=Ms(e,"Coth",i[0]))||void 0===n?void 0:n.simplify())&&void 0!==t?t:e.box(["Divide",1,["Tanh",i[0]]]).simplify()},evaluate:(e,i)=>Os(e,"evaluate","Coth",i[0]),N:(e,i)=>Os(e,"N","Coth",i[0])}},{name:"InverseFunction",signature:{domain:["Function","Function","Function"],canonical:(e,i)=>{var n;return null!==(n=qs(e,i=et(e,Xn(i),1).map((e=>e.canonical))))&&void 0!==n?n:e._fn("InverseFunction",i)},simplify:(e,i)=>qs(e,i),evaluate:(e,i)=>qs(e,i)}}]}],Ss=["Sqrt",2],ws=["Sqrt",3],ks=["Sqrt",5],Es=["Sqrt",6],As=[[[0,1],{Sin:0,Cos:1,Tan:0,Cot:NaN,Sec:1,Csc:NaN}],[[1,12],{Sin:["Divide",["Subtract",Es,Ss],4],Cos:["Divide",["Add",Es,Ss],4],Tan:["Subtract",2,ws],Cot:["Add",2,ws],Sec:["Subtract",Es,Ss],Csc:["Add",Es,Ss]}],[[1,10],{Sin:["Divide",["Subtract",ks,1],4],Cos:["Divide",["Sqrt",["Add",10,["Multiply",2,ks]]],4],Tan:["Divide",["Sqrt",["Subtract",25,["Multiply",10,ks]]],4],Cot:["Sqrt",["Add",5,["Multiply",2,ks]]],Sec:["Divide",["Sqrt",["Subtract",50,["Multiply",10,ks]]],5],Csc:["Add",1,ks]}],[[1,8],{Sin:"$\\frac\\sqrt{2-\\sqrt2}{2}$",Cos:"$\\frac {\\sqrt {2+{\\sqrt {2}}}}{2}$",Tan:"$\\sqrt{2} - 1$",Cot:"$\\sqrt{2} + 1$",Sec:"$\\sqrt{ 4 - 2\\sqrt{2}}$",Csc:"$\\sqrt{ 4 + 2\\sqrt{2}}$"}],[[1,6],{Sin:"$\\frac{1}{2}$",Cos:"$\\frac{\\sqrt{3}}{2}$",Tan:"$\\frac{\\sqrt{3}}{3}$",Cot:"$\\frac{2\\sqrt{3}}{3}$",Sec:"$\\sqrt{3}$",Csc:2}],[[1,5],{Sin:"$\\frac{\\sqrt{10- 2\\sqrt{5}}} {4}$",Cos:"$\\frac{1+ \\sqrt{5}} {4}$",Tan:"$\\sqrt{5-2\\sqrt5}$",Cot:"$\\frac{\\sqrt{25+10\\sqrt5}} {5}$",Sec:"$\\sqrt{5} - 1$",Csc:"$\\frac{\\sqrt{50+10\\sqrt{5}}} {5}$"}],[[1,4],{Sin:["Divide",Ss,2],Cos:["Divide",Ss,2],Tan:1,Cot:1,Sec:Ss,Csc:Ss}],[[3,10],{Sin:"$\\frac{1+ \\sqrt{5}} {4}$",Cos:"$\\frac{\\sqrt{10- 2\\sqrt{5}}} {4}$",Tan:"$\\frac{\\sqrt{25+10\\sqrt5}} {5}$",Cot:"$\\sqrt{5-2\\sqrt5}$",Sec:"$$",Csc:"$\\frac{\\sqrt{50+10\\sqrt{5}}} {5}$"}],[[1,3],{Sin:["Divide",ws,2],Cos:"Half",Tan:ws,Cot:["Divide",ws,3],Sec:2,Csc:["Divide",["Multiply",2,ws],3]}],[[3,8],{Sin:"$\\frac{ \\sqrt{2 + \\sqrt{2}} } {2}$",Cos:"$\\frac{ \\sqrt{2 - \\sqrt{2}} } {2}$",Tan:"$\\sqrt{2} + 1$",Cot:"$\\sqrt{2} - 1$",Sec:"$\\sqrt{ 4 + 2 \\sqrt{2} }$",Csc:"$\\sqrt{ 4 - 2 \\sqrt{2} }$"}],[[2,5],{Sin:"$\\frac{\\sqrt{10+ 2\\sqrt{5}}} {4}$",Cos:"$\\frac{\\sqrt{5}-1} {4}$",Tan:"$\\sqrt{5+2\\sqrt{5}}$",Cot:"$\\frac{\\sqrt{25-10\\sqrt{5}}} {5}$",Sec:"$1 + \\sqrt{5}$",Csc:"$\\frac{\\sqrt{50-10\\sqrt{5}}} {5}$"}],[[5,12],{Sin:"$\\frac{\\sqrt{6} + \\sqrt{2}} {4}$",Cos:"$\\frac{ \\sqrt{6} - \\sqrt{2}} {4}$",Tan:"$2+\\sqrt{3}$",Cot:"$2-\\sqrt{3}$",Sec:"$\\sqrt{6}+\\sqrt{2}$",Csc:"$\\sqrt{6} - \\sqrt{2}$"}],[[1,2],{Sin:1,Cos:0,Tan:NaN,Cot:0,Sec:NaN,Csc:1}]],Is={Sin:[[1,"Sin"],[1,"Cos"],[-1,"Sin"],[-1,"Cos"]],Cos:[[1,"Cos"],[-1,"Sin"],[-1,"Cos"],[1,"Sin"]],Sec:[[1,"Sec"],[-1,"Csc"],[-1,"Sec"],[1,"Csc"]],Csc:[[1,"Csc"],[1,"Sec"],[-1,"Csc"],[-1,"Sec"]],Tan:[[1,"Tan"],[-1,"Cot"],[1,"Tan"],[-1,"Cot"]],Cot:[[1,"Cot"],[-1,"Tan"],[1,"Cot"],[-1,"Tan"]]};function Ms(e,i,n){var t,r,s;const o=e.cache("constructible-trigonometric-values",(()=>{var i;const n=[];for(const[t,r]of As){const s={};for(const n of Object.keys(r))s[n]=null!==(i=e.parse($n(r[n])))&&void 0!==i?i:e.box(r[n]);n.push([t,s])}return n}),(e=>{for(const[i,n]of e)for(const e of Object.values(n))e.unbind();return e}));if(!(n=n.N()).isLiteral)return;let a=null!==(t=Dn(n))&&void 0!==t?t:null;if(null===a)return;a%=2*Math.PI;const l="Cos"!==i&&"Sec"!==i?Math.sign(a):1;a=Math.abs(a);const u=Math.floor(2*a/Math.PI);let c;a%=Math.PI/2,[c,i]=null!==(s=null===(r=Is[i])||void 0===r?void 0:r[u])&&void 0!==s?s:[1,i],c*=l;for(const[[n,t],r]of o)if(0===e.chop(a-Math.PI*n/t))return c<0?Ot(r[i]):r[i]}function qs(e,i){if(1!==i.length)return;const n=i[0],t=n.symbol;if("string"!=typeof t)return;if("InverseFunction"===t)return n.op1;const r={Sin:"Arcsin",Cos:"Arccos",Tan:"Arctan",Sec:"Arcsec",Csc:" Arccsc",Sinh:"Arsinh",Cosh:"Arcosh",Tanh:"Artanh",Sech:"Arcsech",Csch:"Arcsch",Arcosh:"Cosh",Arccos:"Cos",Arccsc:"Csc",Arcsch:"Csch",Arcsec:"Sec",Arcsin:"Sin",Arsinh:"Sinh",Arctan:"Tan",Artanh:"Tanh"}[t];return r?e.symbol(r):void 0}function Os(e,i,n,t){var r;if("evaluate"===i){const i=null===(r=Ms(e,n,t))||void 0===r?void 0:r.evaluate();if(i)return i;if(t.isExact)return}switch(n){case"Arccos":return Wr(t,Math.acos,(e=>e.acos()),(e=>e.acos()));case"Arccot":return Wr(t,(e=>Math.atan2(1,e)),(i=>Ge.atan2(e._BIGNUM_ONE,i)),(e=>e.inverse().atan()));case"Arccsc":return Wr(t,(e=>Math.asin(1/e)),(i=>e._BIGNUM_ONE.div(i).asin()),(e=>e.inverse().asin()));case"Arcosh":return Wr(t,Math.acosh,(e=>e.acosh()),(e=>e.acosh()));case"Arcoth":return Wr(t,(e=>e),(e=>e.acosh()),(e=>e.acosh()));case"Arcsch":return Wr(t,(e=>Math.log(1/e+Math.sqrt(1/(e*e)+1))),(i=>e._BIGNUM_ONE.div(i.mul(i)).add(e._BIGNUM_ONE).sqrt().add(e._BIGNUM_ONE.div(i)).log()),(e=>e.mul(e).inverse().add(1).sqrt().add(e.inverse()).log()));case"Arcsec":return Wr(t,(e=>Math.acos(1/e)),(i=>e._BIGNUM_ONE.div(i).acos()),(e=>e.inverse().acos()));case"Arcsin":return Wr(t,Math.asin,(e=>e.asin()),(e=>e.asin()));case"Arsech":return Wr(t,(e=>Math.log((1+Math.sqrt(1-e*e))/e)),(i=>e._BIGNUM_ONE.sub(i.mul(i).add(e._BIGNUM_ONE).div(i)).log()),(i=>e.complex(1).sub(i.mul(i)).add(1).div(i).log()));case"Arsinh":return Wr(t,Math.asinh,(e=>e.asinh()),(e=>e.asinh()));case"Arctan":return Wr(t,Math.atan,(e=>e.atan()),(e=>e.atan()));case"Artanh":return Wr(t,Math.atanh,(e=>e.atanh()),(e=>e.atanh()));case"Cos":return Wr(t,Math.cos,(e=>e.cos()),(e=>e.cos()));case"Cosh":return Wr(t,Math.cosh,(e=>e.cosh()),(e=>e.cosh()));case"Cot":return Wr(t,(e=>1/Math.tan(e)),(i=>e._BIGNUM_ONE.div(i.tan())),(e=>e.tan().inverse()));case"Coth":return Wr(t,(e=>1/Math.tanh(e)),(i=>e._BIGNUM_ONE.div(i.tanh())),(e=>e.tanh().inverse()));case"Csc":return Wr(t,(e=>1/Math.sin(e)),(i=>e._BIGNUM_ONE.div(i.sin())),(e=>e.sin().inverse()));case"Csch":return Wr(t,(e=>1/Math.sinh(e)),(i=>e._BIGNUM_ONE.div(i.sinh())),(e=>e.sinh().inverse()));case"Sec":return Wr(t,(e=>1/Math.cos(e)),(i=>e._BIGNUM_ONE.div(i.cos())),(e=>e.cos().inverse()));case"Sech":return Wr(t,(e=>1/Math.cosh(e)),(i=>e._BIGNUM_ONE.div(i.cosh())),(e=>e.cosh().inverse()));case"Sin":return Wr(t,Math.sin,(e=>e.sin()),(e=>e.sin()));case"Sinh":return Wr(t,Math.sinh,(e=>e.sinh()),(e=>e.sinh()));case"Tan":return Wr(t,Math.tan,(e=>e.tan()),(e=>e.tan()));case"Tanh":return Wr(t,Math.tanh,(e=>e.tanh()),(e=>e.tanh()))}}function Ts(e){return Object.fromEntries(Object.entries(e).filter((([e,i])=>void 0!==i)))}function Fs(e){const i=Object.assign({},e);return e.zero||e.one||e.negativeOne?(i.number=!0,i.integer=!0,i.rational=!0,i.algebraic=!0,i.real=!0,i.extendedReal=!0,i.complex=!0,i.extendedComplex=!0,i.imaginary=!1,i.positive=!1,i.nonPositive=!0,i.negative=!1,i.nonNegative=!0,i.zero=e.zero,i.notZero=!e.zero,i.one=e.one,i.negativeOne=e.negativeOne,i.negativeOne=!1,i.infinity=!1,i.NaN=!1,i.finite=!0,i.even=e.one,i.odd=!e.one,i.prime=!1,i.composite=!1,i):(!0===i.notZero&&(i.imaginary||(i.real=!0),i.zero=!1),(i.positive||i.nonNegative)&&(i.negativeOne=!1),i.positive?(i.nonPositive=!1,i.negative=!1,i.nonNegative=!0):i.nonPositive?(i.positive=!1,i.negative=i.notZero,i.nonNegative=!i.zero):i.negative?(i.positive=!1,i.nonPositive=i.notZero,i.nonNegative=!1):i.nonNegative&&(i.positive=i.notZero,i.nonPositive=!i.zero,i.negative=!1),(i.positive||i.negative||i.nonPositive||i.nonNegative)&&(i.number=!0,i.finite?i.real=!0:i.finite||(i.complex=!0),i.imaginary=!1),i.infinity&&(i.finite=!1,i.NaN=!1),i.finite&&(i.number=!0,i.complex=!0,i.infinity=!1,i.NaN=!1),e.even&&(i.odd=!1),e.odd&&(i.even=!1),i.integer&&(i.rational=!0),i.rational&&(i.algebraic=!0),i.algebraic&&(i.real=!0),i.real&&(i.extendedReal=!0),i.real&&(i.complex=!0),i.imaginary&&(i.complex=!0),i.extendedComplex&&(i.complex=!0),i.complex&&(i.number=!0),i.real&&i.infinity&&(i.extendedReal=!0),i.complex&&i.infinity&&(i.extendedComplex=!0),(i.even||i.infinity||i.NaN||i.negative||i.imaginary||!1===i.integer)&&(i.prime=!1),i.number&&i.prime&&(i.composite=!1),i)}function Cs(e){if(!e)return{};const i={};if(e.isNumeric){const n=e.literal;i.number=!0,"Integer"===n&&(i.integer=!0),"RationalNumber"===n&&(i.rational=!0),"AlgebraicNumber"===n&&(i.algebraic=!0),"TranscendentalNumber"===n&&(i.algebraic=!1,i.real=!0),"ExtendedRealNumber"===n&&(i.extendedReal=!0),"RealNumber"===n&&(i.real=!0),"ImaginaryNumber"===n&&(i.imaginary=!0),"ExtendedComplexNumber"===n&&(i.extendedComplex=!0),"ComplexNumber"===n&&(i.complex=!0),"PositiveNumber"===n&&(i.notZero=!0,i.real=!0,i.positive=!0),"NegativeNumber"===n&&(i.notZero=!0,i.real=!0,i.negative=!0),"NonNegativeNumber"===n&&(i.real=!0,i.positive=!0),"NonPositiveNumber"===n&&(i.real=!0,i.negative=!0),"PositiveInteger"===n&&(i.notZero=!0,i.integer=!0,i.positive=!0),"NegativeNumber"===n&&(i.notZero=!0,i.integer=!0,i.negative=!0),"NonNegativeNumber"===n&&(i.integer=!0,i.positive=!0),"NonPositiveNumber"===n&&(i.integer=!0,i.negative=!0)}else i.number=!1,i.integer=!1,i.rational=!1,i.algebraic=!1,i.real=!1,i.extendedReal=!1,i.complex=!1,i.extendedComplex=!1,i.imaginary=!1,i.positive=!1,i.nonPositive=!1,i.negative=!1,i.nonNegative=!1,i.zero=!1,i.notZero=!1,i.one=!1,i.negativeOne=!1,i.infinity=!1,i.NaN=!1,i.odd=!1,i.even=!1,i.prime=!1,i.composite=!1;return Ts(Fs(i))}function Ds(e){return Ts({number:(e=e.canonical).isNumber,integer:e.isInteger,rational:e.isRational,algebraic:e.isAlgebraic,real:e.isReal,extendedReal:e.isExtendedReal,complex:e.isComplex,extendedComplex:e.isExtendedComplex,imaginary:e.isImaginary,positive:e.isPositive,nonPositive:e.isNonPositive,negative:e.isNegative,nonNegative:e.isNonNegative,zero:e.isZero,notZero:e.isNotZero,one:e.isOne,negativeOne:e.isNegativeOne,infinity:e.isInfinity,NaN:e.isNaN,finite:e.isFinite,even:e.isEven,odd:e.isOdd,prime:e.isPrime,composite:e.isComposite})}class Ps{constructor(e,i){var n,t;if(!e.context)throw Error("No context available");this._engine=e,this.scope=e.context,this._def=i,this.name=i.name,this.constant=null!==(n=i.constant)&&void 0!==n&&n,this.hold=null!==(t=i.hold)&&void 0!==t&&t,this._value=null,this._domain=null}reset(){var e;null===(e=this._value)||void 0===e||e.unbind(),this.unbind()}unbind(){this._value=null,this._domain=null}bind(){var e,i;this._value=null;const n=this._def,t=this._engine,r=Ts({description:n.description,wikidata:n.wikidata,number:n.number,integer:n.integer,rational:n.rational,algebraic:n.algebraic,real:n.real,extendedReal:n.extendedReal,complex:n.complex,zero:n.zero,notZero:n.notZero,one:n.one,negativeOne:n.negativeOne,infinity:n.infinity,NaN:n.NaN,finite:n.finite,even:n.even,odd:n.odd,prime:n.prime,composite:n.composite});if("value"in n&&"number"==typeof n.value){const e=t.number(n.value);let i;const s=n.domain?t.domain(n.domain):void 0;return i=s&&e.domain.isCompatible(s)?s:e.domain,this._value=e,this._domain=i,this.setProps(Ds(e)),this.setProps(Cs(i)),void this.setProps(r)}let s,o;if(zn(n.value)?s=t.parse(n.value):"function"==typeof n.value?s=t.box(null!==(e=n.value(t))&&void 0!==e?e:"Undefined"):n.value&&(s=t.box(n.value)),!s&&!1===n.hold)throw Error(`Symbol definition "${n.name}": Expected a value when "hold=false" `);s=null==s?void 0:s.canonical;const a=n.domain?t.domain(n.domain):void 0;o=!a||s&&!s.domain.isCompatible(a)?null!==(i=null==s?void 0:s.domain)&&void 0!==i?i:t.defaultDomain:a,this._value=s,this._domain=o,s&&this.setProps(Ds(s)),this.setProps(Cs(o)),this.setProps(r)}get value(){var e;return null===this._value&&this.bind(),null!==(e=this._value)&&void 0!==e?e:void 0}set value(e){if(null===this._value&&this.bind(),this.constant)throw Error(`The value of the constant "${this.name}" cannot be changed`);"number"==typeof e&&(e=this._engine.box(e)),this._value=null!=e?e:null,e&&this.setProps(Ds(e))}get domain(){var e;return null===this._domain&&this.bind(),null!==(e=this._domain)&&void 0!==e?e:void 0}set domain(e){var i;if(!e)return void(this._domain=void 0);e=this._engine.domain(e);const n=null===(i=this.value)||void 0===i?void 0:i.domain;n&&!n.isCompatible(e)&&(e=n),this._domain=e,this.setProps(Cs(e))}updateFlags(e){this.setProps(Fs(e))}setProps(e){e.wikidata&&(this.wikidata=e.wikidata),e.description&&(this.description=e.description),void 0!==e.number&&(this._number=e.number),void 0!==e.integer&&(this._integer=e.integer),void 0!==e.rational&&(this._rational=e.rational),void 0!==e.algebraic&&(this._algebraic=e.algebraic),void 0!==e.real&&(this._real=e.real),void 0!==e.extendedReal&&(this._extendedReal=e.extendedReal),void 0!==e.complex&&(this._complex=e.complex),void 0!==e.extendedComplex&&(this._extendedComplex=e.extendedComplex),void 0!==e.imaginary&&(this._imaginary=e.imaginary),void 0!==e.positive&&(this._positive=e.positive),void 0!==e.nonPositive&&(this._nonPositive=e.nonPositive),void 0!==e.negative&&(this._negative=e.negative),void 0!==e.nonNegative&&(this._nonNegative=e.nonNegative),void 0!==e.zero&&(this._zero=e.zero),void 0!==e.notZero&&(this._notZero=e.notZero),void 0!==e.one&&(this._one=e.one),void 0!==e.negativeOne&&(this._negativeOne=e.negativeOne),void 0!==e.infinity&&(this._infinity=e.infinity),void 0!==e.finite&&(this._finite=e.finite),void 0!==e.NaN&&(this._NaN=e.NaN),void 0!==e.even&&(this._even=e.even),void 0!==e.odd&&(this._odd=e.odd),void 0!==e.prime&&(this._prime=e.prime),void 0!==e.composite&&(this._composite=e.composite)}get number(){return null===this._value&&this.bind(),this._number}set number(e){this.updateFlags({number:e})}get integer(){return null===this._value&&this.bind(),this._integer}set integer(e){this.updateFlags({integer:e})}get rational(){return null===this._value&&this.bind(),this._rational}set rational(e){this.updateFlags({rational:e})}get algebraic(){return null===this._value&&this.bind(),this._algebraic}set algebraic(e){this.updateFlags({algebraic:e})}get real(){return null===this._value&&this.bind(),this._real}set real(e){this.updateFlags({real:e})}get extendedReal(){return null===this._value&&this.bind(),this._extendedReal}set extendedReal(e){this.updateFlags({extendedReal:e})}get complex(){return null===this._value&&this.bind(),this._complex}set complex(e){this.updateFlags({complex:e})}get extendedComplex(){return null===this._value&&this.bind(),this._extendedComplex}set extendedComplex(e){this.updateFlags({extendedComplex:e})}get imaginary(){return null===this._value&&this.bind(),this._imaginary}set imaginary(e){this.updateFlags({imaginary:e})}get positive(){return null===this._value&&this.bind(),this._positive}set positive(e){this.updateFlags({positive:e})}get nonPositive(){return null===this._value&&this.bind(),this._nonPositive}set nonPositive(e){this.updateFlags({nonPositive:e})}get negative(){return null===this._value&&this.bind(),this._negative}set negative(e){this.updateFlags({negative:e})}get nonNegative(){return null===this._value&&this.bind(),this._nonNegative}set nonNegative(e){this.updateFlags({nonNegative:e})}get zero(){return null===this._value&&this.bind(),this._zero}set zero(e){this.updateFlags({zero:e})}get notZero(){return null===this._value&&this.bind(),this._notZero}set notZero(e){this.updateFlags({notZero:e})}get one(){return null===this._value&&this.bind(),this._one}set one(e){this.updateFlags({one:e})}get negativeOne(){return null===this._value&&this.bind(),this._negativeOne}set negativeOne(e){this.updateFlags({negativeOne:e})}get infinity(){return null===this._value&&this.bind(),this._infinity}set infinity(e){this.updateFlags({infinity:e})}get finite(){return null===this._value&&this.bind(),this._finite}set finite(e){this.updateFlags({finite:e})}get NaN(){return null===this._value&&this.bind(),this._NaN}set NaN(e){this.updateFlags({NaN:e})}get even(){return null===this._value&&this.bind(),this._even}set even(e){this.updateFlags({even:e})}get odd(){return null===this._value&&this.bind(),this._odd}set odd(e){this.updateFlags({odd:e})}get prime(){var e;if(null===this._value&&this.bind(),void 0===this._prime&&(null===(e=this._value)||void 0===e?void 0:e.isNumber))if(!this._value.isInteger||this._value.isNonPositive)this._prime=!1,this._composite=!1;else{const e=Dn(this._value);null!==e?(this._prime=fr(e),this._composite=!this._prime):(this._prime=void 0,this._composite=void 0)}return this._prime}set prime(e){this.updateFlags({prime:e})}get composite(){if(null===this._value&&this.bind(),void 0===this._composite){const e=this.prime;this._composite=void 0===e?void 0:!e}return this._composite}set composite(e){this.updateFlags({composite:e})}}class Ls{constructor(e,i){var n,t,r,s,o,a,l,u,c,h,m,d;if(!e.context)throw Error("No context available");this.engine=e,this.scope=e.context;const f=null!==(n=i.idempotent)&&void 0!==n&&n,g=null!==(t=i.involution)&&void 0!==t&&t;if(f&&g)throw Error(`Function Definition "${i.name}": the 'idempotent' and 'involution' flags are mutually exclusive`);if(this.name=i.name,this.description=i.description,this.wikidata=i.wikidata,this.threadable=null!==(r=i.threadable)&&void 0!==r&&r,this.associative=null!==(s=i.associative)&&void 0!==s&&s,this.commutative=null!==(o=i.commutative)&&void 0!==o&&o,this.idempotent=f,this.involution=g,this.inert=null!==(a=i.inert)&&void 0!==a&&a,this.numeric=null!==(l=i.numeric)&&void 0!==l&&l,this.pure=null===(u=i.pure)||void 0===u||u,this.complexity=null!==(c=i.complexity)&&void 0!==c?c:Ht,this.hold=null!==(h=i.hold)&&void 0!==h?h:"none",this.inert){if(i.hold)throw Error(`Function Definition "${i.name}": an inert function should not have a hold`);if(this.hold="rest",i.signature){const e=i.signature;if("simplify"in e||"evaluate"in e||"N"in e||"evalDimension"in e||"sgn"in e||"compile"in e)throw Error(`Function Definition "${i.name}": an inert function should only have 'canonical' or 'codomain' handlers`)}if(this.threadable)throw Error(`Function Definition "${i.name}": an inert function should not be threadable`);if(this.associative)throw Error(`Function Definition "${i.name}": an inert function should not be associative`);if(this.commutative)throw Error(`Function Definition "${i.name}": an inert function should not be commutative`);if(this.idempotent)throw Error(`Function Definition "${i.name}": an inert function should not be idempotent`);if(this.involution)throw Error(`Function Definition "${i.name}": an inert function should not be involution`);if(!this.pure)throw Error(`Function Definition "${i.name}": an inert function should be pure`)}if(i.signature){const n=i.signature,t=n.domain?e.domain(n.domain):i.numeric?e.domain("NumericFunction"):e.domain("Function");if(!t.isValid)throw Error(`Function Definition "${i.name}": invalid domain ${JSON.stringify(n.domain)}`);const r=null!==(d=null!==(m=n.codomain)&&void 0!==m?m:t.codomain)&&void 0!==d?d:i.numeric?e.domain("Number"):e.domain("Anything");this.signature={domain:t,codomain:r,canonical:n.canonical,simplify:n.simplify,evaluate:n.evaluate?"function"==typeof n.evaluate?n.evaluate:e.box(n.evaluate,{canonical:!1}):void 0,N:n.N,evalDimension:n.evalDimension,sgn:n.sgn,compile:n.compile}}else i.numeric?this.signature={domain:e.domain("NumericFunction"),codomain:e.domain("Number")}:this.signature={domain:e.domain("Function"),codomain:e.domain("Anything")}}reset(){}}function Rs(e,i){return new Ls(e,i)}function zs(e){if("all"===e)return zs(["domains","core","control-structures","logic","collections","relop","numeric","arithmetic","algebra","calculus","combinatorics","linear-algebra","other","physics","polynomials","statistics","trigonometry","dimensions","units"]);"string"==typeof e&&(e=[e]);const i=[];for(const n of e){const e=$s[n];if(!e)throw Error("Unknown library category "+n);Array.isArray(e)?i.push(...e):i.push(e)}return i}const $s={algebra:[],arithmetic:ls,calculus:cs,combinatorics:[],"control-structures":[],dimensions:[],domains:[],core:hs,collections:[_s,{functions:[{name:"Sequence",signature:{domain:"Function"}}]}],"linear-algebra":[],logic:ms,numeric:[],other:[],relop:Ns,polynomials:ys,physics:{symbols:[{name:"Mu-0",description:"Vaccum permeability",constant:!0,wikidata:"Q1515261",domain:"RealNumber",value:125663706212e-17}]},statistics:[],trigonometry:xs,units:[]};function Vs(e){if("object"!=typeof e||!("name"in e)||!e.name)throw Error("Missing name for definition"+JSON.stringify(e));const i=e.name.normalize();if(!ri(i))throw Error("Invalid definition name "+i);return i}function js(e,i){var n,t;if(!e.context)throw Error("No context available");null!==(n=(t=e.context).symbolTable)&&void 0!==n||(t.symbolTable={symbols:new Map,functions:new Map,symbolWikidata:new Map,functionWikidata:new Map});const r=e.context.symbolTable;if(i.symbols)for(const n of i.symbols){const i=Vs(n),t=new Ps(e,n);if(n.wikidata){if(r.symbolWikidata.has(n.wikidata))throw Error(`Duplicate symbol with wikidata ${n.wikidata}, ${i} and ${r.symbolWikidata.get(n.wikidata).name}`);r.symbolWikidata.set(n.wikidata,t)}if(r.symbols.has(i))throw Error(`Duplicate symbol definition ${i}:\n${JSON.stringify(r.symbols.get(i))}\n${JSON.stringify(n)}`);r.symbols.set(i,t)}if(i.functions)for(const n of i.functions){const i=Vs(n),t=Rs(e,n);if(n.wikidata){if(r.functionWikidata.has(n.wikidata))throw Error(`Duplicate function with wikidata ${n.wikidata}, ${i} and ${r.functionWikidata.get(n.wikidata).name}`);r.functionWikidata.set(n.wikidata,t)}if(r.functions.has(i))throw Error(`Duplicate function definition ${i}:\n${JSON.stringify(r.symbols.get(i))}\n${JSON.stringify(n)}`);r.functions.set(i,t)}}function Gs(e){return Number.isInteger(e)?Math.floor(Math.log2(Math.abs(e))/Math.log2(10))+(e>0?1:2):2}const Zs=function e(i){var n,t;if(i.symbol)return 1;if(i.isLiteral){if(i.isZero)return 1;if(i.isInteger&&null!==Dn(i))return Gs(Dn(i));const e=i.numericValue;if(ht(e))return mt(e)?Gs(e[0])+Gs(e[1])+1:Gs(e[0].toNumber())+Gs(e[1].toNumber())+1;if(e instanceof Ue)return Gs(e.re)+Gs(e.im)+1;if(i.isNumber)return 2}const r=i.head;return("string"==typeof r?1:e(r))+(null!==(t=null===(n=i.ops)||void 0===n?void 0:n.reduce(((i,n)=>i+e(n)),0))&&void 0!==t?t:0)};class Bs{constructor(e){this._items=e?e instanceof Bs?new Map(e._items):new Map(e):new Map}has(e){for(const i of this._items.keys())if(i.isSame(e))return!0;return!1}get(e){for(const[i,n]of this._items)if(i.isSame(e))return n}clear(){this._items.clear()}set(e,i){for(const n of this._items.keys())if(n.isSame(e))return void this._items.set(n,i);this._items.set(e,i)}delete(e){this._items.delete(e)}[Symbol.iterator](){return this._items.entries()}entries(){return this._items.entries()}}class Us extends Gt{constructor(e,i,n){super(e,n),this._pattern=zn(i)?e.parse(i,{canonical:!1}):e.box(i,{canonical:!1})}get hash(){return Hn("Pattern")^this._pattern.hash}unbind(){this._pattern.unbind()}get json(){return nr(this.engine,"Pattern",[this._pattern])}get head(){return"Pattern"}get domain(){return this.engine.domain("Pattern")}get isCanonical(){return!0}set isCanonical(e){}isSame(e){return this===e||e instanceof Us&&this._pattern.isSame(e._pattern)}isEqual(e){return e instanceof Us&&this._pattern.isEqual(e._pattern)}match(e,i){var n,t,r;return function(e,i,n){var t,r;return Qs(e,i,null!==(t=n.substitution)&&void 0!==t?t:{},{numericTolerance:null!==(r=null==n?void 0:n.numericTolerance)&&void 0!==r?r:wn})||null}(e,this._pattern,{recursive:null!==(n=null==i?void 0:i.recursive)&&void 0!==n&&n,numericTolerance:null!==(t=null==i?void 0:i.numericTolerance)&&void 0!==t?t:0,substitution:null!==(r=null==i?void 0:i.substitution)&&void 0!==r?r:{}})}test(e,i){return null!==this.match(e,i)}count(e,i){let n=0;for(const t of e)null!==this.match(t,i)&&(n+=1);return n}subs(e,i){return this._pattern.subs(e,i)}}function Hs(e){var i;if("string"==typeof e)return e.startsWith("_");if(null===(i=e.symbol)||void 0===i?void 0:i.startsWith("_"))return!0;if(e.ops)return Hs(e.head)||e.ops.some(Hs);if(e.keys)for(const i of e.keys)if(Hs(e.getKey(i)))return!0;return!1}function Ws(e,i,n){const t=function(e){const i=e.match(/^(__?_?[a-zA-Z0-9]+)/);return null===i?"":i[1]}(e);return""===t?n:void 0!==n[t]?i.isSame(n[t])?n:null:Hs(i)?null:Object.assign(Object.assign({},n),{[t]:i})}function Qs(e,i,n,t){const r=e.engine;if("Pattern"===i.head)return i.match(e,Object.assign({substitution:n},t));if(i instanceof gr)return e instanceof gr?0===t.numericTolerance?i.isSame(e)?n:null:i.isEqualWithTolerance(e,t.numericTolerance)?n:null:null;const s=i.string;if(null!==s)return e.string===s?n:null;const o=i.symbol;if(null!==o)return o.startsWith("_")?Ws(o,e,n):o===e.symbol?n:null;if(i.nops!==e.nops)return null;const a=i.keys;if(null!==a){const i=e.keys;if(null===i)return null;for(const e of a){const r=Qs(i[e],a[e],n,t);if(null===r)return null;n=r}return n}if(i.ops){const s=i.head;if("string"==typeof s&&s.startsWith("_"))return Ws(s,r.box(e.head),n);let o;if("string"==typeof s&&"string"==typeof e.head){if(s!==e.head)return null;o=r.lookupFunction(s)}else{const i=Qs(r.box(e.head,{canonical:!1}),r.box(s,{canonical:!1}),n,t);if(null===i)return null;n=i}return(null==o?void 0:o.commutative)?function(e,i,n,t){const r=function(e){const i=[],n=(e,t=[])=>{if(0===e.length)i.push(t);else for(let i=0;i<e.length;i++){const r=e.slice(),s=r.splice(i,1);n(r.slice(),t.concat(s))}};return n(e),i}(i.ops);for(const i of r){const r=Ys(e.engine,e.ops,i,n,t);if(null!==r)return r}return null}(e,i,n,t):function(e,i,n,t){const r=e.engine,s=[...e.ops];let o=Object.assign({},n),a=0;const l=i.ops;for(;a<i.nops;){const e=l[a],i=e.symbol;if(null!==i)if(i.startsWith("__")){let e=0;if(void 0===l[a+1])e=s.length+1;else{let i=!1;for(;!i&&e<s.length;)i=null!==Qs(s[e],l[a+1],o,t),e+=1;if(!i)return null}if(!i.startsWith("___")&&e<=1)return null;o=Ws(i,r.fn("Sequence",s.splice(0,e-1)),o)}else if(i.startsWith("_"))o=Ws(i,s.shift(),o);else{const i=Qs(s.shift(),e,o,t);if(null===i)return null;o=i}else{const i=Qs(s.shift(),e,o,t);if(null===i)return null;o=i}if(null===o)return null;a+=1}return o}(e,i,n,t)}return null}function Ys(e,i,n,t,r){var s;let o=Object.assign({},t);i=[...i];let a=!1;for(const e of n)if("__"===e.symbol)a=!0;else{let n=null;if(null===(s=e.symbol)||void 0===s?void 0:s.startsWith("_")){for(let t=0;t<=i.length-1;t++)if(n=Ws(e.symbol,i[t],o),null!==n){i.splice(t,1);break}}else for(let t=0;t<=i.length-1;t++)if(n=Qs(i[t],e,o,r),null!==n){i.splice(t,1);break}if(null===n)return null;o=n}return!a&&i.length>0?null:(null!==o&&a&&(o.__=e._fn("Sequence",i)),o)}function Js(e){return null!=e&&"constant"in e}class Ks extends Gt{constructor(e,i,n){super(e,null==n?void 0:n.metadata),this._name=i,this._scope=!i.startsWith("_")&&(null==n?void 0:n.canonical)?e.context:null,this._def=null,e._register(this)}get hash(){return void 0===this._hash&&(this._hash=Hn(this._name)),this._hash}unbind(){var e;null===(e=this._def)||void 0===e||e.reset(),this._def=null}get isPure(){var e,i,n,t,r;return null!==(r=null!==(n=(null===(e=this.symbolDefinition)||void 0===e?void 0:e.constant)&&(null===(i=this.symbolDefinition.value)||void 0===i?void 0:i.isPure))&&void 0!==n?n:null===(t=this.functionDefinition)||void 0===t?void 0:t.pure)&&void 0!==r&&r}get json(){return tr(this.engine,this._name,{latex:this._latex,wikidata:this._wikidata})}get scope(){return this._scope}get isFree(){var e;return!(null===(e=this.symbolDefinition)||void 0===e?void 0:e.value)}get isConstant(){var e,i;return null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.constant)&&void 0!==i&&i}get isCanonical(){return null!==this._scope}set isCanonical(e){this._scope=e?this.engine.context:null,this._def=null}get canonical(){return this._scope?this:this.engine.box(this._name)}get wikidata(){var e,i,n;return null!==(n=null!==(e=this._wikidata)&&void 0!==e?e:null===(i=this.baseDefinition)||void 0===i?void 0:i.wikidata)&&void 0!==n?n:void 0}get description(){if(this.baseDefinition&&this.baseDefinition.description)return"string"==typeof this.baseDefinition.description?[this.baseDefinition.description]:this.baseDefinition.description}get url(){var e,i;return null!==(i=null===(e=this.baseDefinition)||void 0===e?void 0:e.url)&&void 0!==i?i:void 0}get complexity(){return 7}get head(){return"Symbol"}get symbol(){return this._name}get isNothing(){return"Nothing"===this._name}get isLiteral(){return!1}get baseDefinition(){var e;return null===this._def&&this.bind(this._scope),null!==(e=this._def)&&void 0!==e?e:void 0}get symbolDefinition(){return null===this._def&&this.bind(this._scope),Js(this._def)?this._def:void 0}get functionDefinition(){return null===this._def&&this.bind(this._scope),null!=(e=this._def)&&"signature"in e?this._def:void 0;var e}bind(e){if("_"===this._name[0]||null===e)return void(this._def=void 0);let i;if(i=this.engine.lookupSymbol(this._name,this._wikidata,e),(null==i?void 0:i.wikidata)&&this._wikidata&&i.wikidata!==this._wikidata&&(i=void 0),i)return this._name=i.name,void(this._def=i);i=this.engine.lookupFunction(this._name,e),i?this._def=i:null!==this.engine.defaultDomain&&(this._def=this.engine.defineSymbol(Object.assign({name:this._name,wikidata:this._wikidata,domain:this.engine.defaultDomain},Cs(this.engine.defaultDomain))),this._name=this._def.name)}get value(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.value}set value(e){var i,n;if("_"===this._name[0])throw Error(`The value of the wildcard "${this._name}" cannot be changed`);let t;if(this.engine.forget(this._name),void 0!==e){const n=this.engine.box(e);t=null!==(i=n.value)&&void 0!==i?i:n.evaluate()}(null==t?void 0:t.domain.isCompatible("Function"))?this._def=this.engine.defineFunction({name:this._name,signature:{domain:t.domain,evaluate:t}}):this._def&&Js(this._def)?this._def.value=t:this._def=this.engine.defineSymbol({name:this._name,value:t,domain:null!==(n=this.engine.defaultDomain)&&void 0!==n?n:this.engine.domain("Anything")})}get domain(){var e,i,n;return this.functionDefinition?this.engine.domain("Function"):null!==(n=null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.domain)&&void 0!==i?i:this.engine.defaultDomain)&&void 0!==n?n:this.engine.domain("Anything")}set domain(e){if("_"===this._name[0])throw Error(`The domain of the wildcard "${this._name}" cannot be changed`);const i=this.engine.domain(e);i.isCompatible("Function")?(this.engine.forget(this._name),this._def=this.engine.defineFunction({name:this._name,signature:{domain:i}})):Js(this._def)?this._def.domain=i:(this.engine.forget(this._name),this._def=this.engine.defineSymbol(Object.assign({name:this._name,domain:i},Cs(i))))}get explicitDomain(){var e,i;return this.functionDefinition?this.engine.domain("Function"):null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.domain)&&void 0!==i?i:void 0}get sgn(){const e=this.N();if(e&&e!==this){const i=e.sgn;if(void 0!==i)return i}const i=this.symbolDefinition;if(i){if(!0===i.zero)return 0;if(!0===i.positive)return 1;if(!0===i.negative)return-1}}has(e){return"string"==typeof e?this._name===e:e.includes(this._name)}isSame(e){return this===e||e instanceof Ks&&this._name===e._name}match(e,i){return e instanceof Ks&&this._name===e._name?{}:null}isEqual(e){var i,n;if(!this.isCanonical)return this.canonical.isEqual(e);if(this===(e=e.canonical))return!0;if(null!==e.symbol)return e.symbol===this._name;const t=null===(n=null===(i=this.symbolDefinition)||void 0===i?void 0:i.value)||void 0===n?void 0:n.N();if(t)return t.isEqual(e.N());if(e.isZero){if(this.isZero)return!0;if(this.isNotZero)return!1}return!(this.isZero&&e.isNotZero||!(this.engine.ask(["Equal",this,e]).length>0)&&(this.engine.ask(["NotEqual",this,e]).length,1))}isLess(e){if(null!==e.symbol&&e.symbol===this._name)return!1;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e<0}}isLessEqual(e){if(null!==e.symbol&&e.symbol===this._name)return!0;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e<=0}return this.isLess(e)||this.isEqual(e)}isGreater(e){if(null!==e.symbol&&e.symbol===this._name)return!1;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e>0}}isGreaterEqual(e){if(null!==e.symbol&&e.symbol===this._name)return!0;if(e.isZero){const e=this.sgn;if(null===e)return!1;if(void 0!==e)return e>=0}return this.isGreater(e)||this.isEqual(e)}get isFunction(){return!!this.functionDefinition}get isZero(){var e,i,n,t;return null!==(i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.zero)&&void 0!==i?i:null===(t=null===(n=this.symbolDefinition)||void 0===n?void 0:n.value)||void 0===t?void 0:t.isZero}get isNotZero(){var e;const i=null===(e=this.symbolDefinition)||void 0===e?void 0:e.notZero;if("boolean"==typeof i)return i;const n=this.sgn;return"number"==typeof n?0!==n:void 0}get isOne(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.one}get isNegativeOne(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.negativeOne}get isOdd(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.odd}get isEven(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.even}get isPrime(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.prime}get isComposite(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.composite}get isInfinity(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.infinity}get isNaN(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.NaN}get isPositive(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.positive}get isNonPositive(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.nonPositive}get isNegative(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.negative}get isNonNegative(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.nonNegative}get isNumber(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.number}get isInteger(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.integer}get isRational(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.rational}get isAlgebraic(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.rational}get isReal(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.real}get isExtendedReal(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.extendedReal}get isComplex(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.complex}get isImaginary(){var e;return null===(e=this.symbolDefinition)||void 0===e?void 0:e.imaginary}simplify(e){var i,n;const t=(null==e?void 0:e.rules)&&null!==(i=this.replace(e.rules))&&void 0!==i?i:this;if(!1===(null===(n=t.symbolDefinition)||void 0===n?void 0:n.hold)){const i=t.value;if(i)return i.simplify(e)}return t}evaluate(e){const i=this.symbolDefinition;return i&&!i.hold&&i.value?i.value.evaluate():this}N(e){var i;const n=null===(i=this.symbolDefinition)||void 0===i?void 0:i.value;return n?n.N(e):this}replace(e,i){return Jn(this,e,i)}subs(e,i){return void 0===e[this._name]?(null==i?void 0:i.canonical)?this.canonical:this:this.engine.box(e[this._name],i)}}function Xs(e,i){const n=e.lookupSymbol(i,void 0,e.context);return n&&!1===n.hold&&n.value?e.box(n.value):new Ks(e,i,{canonical:!0})}class eo{constructor(e){var i,n,t,r;if(this._cache={},this._commonSymbols={True:null,False:null,Maybe:null,All:null,Nothing:null,None:null,Undefined:null,Function:null,Pi:null,ImaginaryUnit:null},this._commonNumbers={"-5":null,"-4":null,"-3":null,"-2":null,2:null,3:null,4:null,5:null,6:null,7:null,8:null,9:null,10:null,11:null,12:null,36:null},this._commonDomains={Anything:null,Nothing:null,Boolean:null,MaybeBoolean:null,String:null,Domain:null,Symbol:null,Integer:null,RationalNumber:null,AlgebraicNumber:null,RealNumber:null,ExtendedRealNumber:null,ImaginaryNumber:null,ComplexNumber:null,ExtendedComplexNumber:null,Number:null,PositiveInteger:null,TranscendentalNumber:null,PositiveNumber:null,Function:null,NumericFunction:null,RealFunction:null,TrigonometricFunction:null,HyperbolicFunction:null,LogicOperator:null,Predicate:null,RelationalOperator:null,Expression:null,BooleanExpression:null,NumericExpression:null},void 0!==e&&"object"!=typeof e)throw Error("Unexpected argument");this._latexDictionary=null==e?void 0:e.latexDictionary,this._jsonSerializationOptions={exclude:[],shorthands:["function","symbol","string","dictionary","number"],metadata:[],precision:"max",repeatingDecimals:!0},this._useRawJsonSerializationOptions=!1,this._rawJsonSerializationOptions={exclude:[],shorthands:["function","symbol","string","dictionary","number"],metadata:[],precision:"max",repeatingDecimals:!0},this._stats={highwaterMark:0,symbols:new Set,expressions:new Set},this._defaultDomain=null,this._numericMode=null!==(i=null==e?void 0:e.numericMode)&&void 0!==i?i:"auto",this._precision=Math.max(null!==(n=null==e?void 0:e.numericPrecision)&&void 0!==n?n:100,Math.floor(Sn)),this._bignum=Ge.clone({precision:this._precision}),this.tolerance=null!==(t=null==e?void 0:e.tolerance)&&void 0!==t?t:wn,this._ZERO=new gr(this,0),this._ONE=new gr(this,1),this._HALF=new gr(this,[1,2]),this._NEGATIVE_ONE=new gr(this,-1),this._I=new gr(this,Be.exports.Complex.I),this._NAN=new gr(this,NaN),this._POSITIVE_INFINITY=new gr(this,1/0),this._NEGATIVE_INFINITY=new gr(this,-1/0),this._COMPLEX_INFINITY=new gr(this,Be.exports.Complex.INFINITY),this.reset();const s=null!==(r=null==e?void 0:e.symbolTables)&&void 0!==r?r:eo.getSymbolTables();this.pushScope({symbolTable:s,scope:{warn:e=>{for(const i of e)i.message},timeLimit:2,memoryLimit:1,recursionLimit:1024}}),null===(null==e?void 0:e.assumptions)?this.pushScope():this.pushScope({assumptions:null==e?void 0:e.assumptions});for(const e of Object.keys(this._commonDomains))this._commonDomains[e]&&!this._commonDomains[e].symbolDefinition&&this._commonDomains[e].bind(this.context);for(const e of Object.keys(this._commonSymbols))this._commonSymbols[e]&&!this._commonSymbols[e].symbolDefinition&&this._commonSymbols[e].bind(this.context);if(null==e?void 0:e.defaultDomain){const i=this.domain(e.defaultDomain);i.isValid?this._defaultDomain=i:this._defaultDomain=this.domain("ExtendedRealNumber")}else this._defaultDomain=this.domain("ExtendedRealNumber")}static getSymbolTables(e="all"){return zs(e)}reset(){var e,i,n;this._BIGNUM_NEGATIVE_ONE=this.bignum(-1),this._BIGNUM_NAN=this.bignum(NaN),this._BIGNUM_ZERO=this.bignum(0),this._BIGNUM_ONE=this.bignum(1),this._BIGNUM_TWO=this.bignum(2),this._BIGNUM_HALF=this._BIGNUM_ONE.div(this._BIGNUM_TWO),this._BIGNUM_PI=this._BIGNUM_NEGATIVE_ONE.acos();const t=this._stats.symbols.values(),r=this._stats.expressions.values();this._stats.symbols=new Set,this._stats.expressions=new Set;for(const e of t)e.unbind();for(const e of r)e.unbind();for(const e of Object.values(this._commonDomains))null==e||e.unbind();for(const e of Object.values(this._commonSymbols))null==e||e.unbind();let s=this.context;for(;s;){if(null===(e=s.symbolTable)||void 0===e?void 0:e.functions)for(const[e,i]of s.symbolTable.functions)i.reset();if(null===(i=s.symbolTable)||void 0===i?void 0:i.symbols)for(const[e,i]of s.symbolTable.symbols)i.reset();s=null!==(n=s.parentScope)&&void 0!==n?n:null}for(const e of Object.keys(this._cache))this._cache[e].value&&(this._cache[e].purge?this._cache[e].value=this._cache[e].purge(this._cache[e].value):delete this._cache[e])}_register(e){this._stats.highwaterMark+=1}_unregister(e){}get stats(){const e=this._stats.expressions;return this._stats.expressions=null,this._stats.expressions=e,Object.assign({},this._stats)}get precision(){return"machine"===this._numericMode||"complex"===this._numericMode?Math.floor(Sn):this._precision}set precision(e){var i;if("machine"===e&&(e=Math.floor(Sn)),e!==this._precision){if("number"!=typeof e||e<=0)throw Error('Expected "machine" or a positive number');null===(i=this._latexSyntax)||void 0===i||i.updateOptions({precision:e,avoidExponentsInRange:[-6,e]}),this._precision=Math.max(e,Math.floor(Sn)),this.jsonSerializationOptions.precision>this._precision&&(this.jsonSerializationOptions={precision:this._precision}),"auto"!==this._numericMode&&"bignum"!==this._numericMode&&this._precision>Math.floor(Sn)&&(this._numericMode="auto"),this._bignum=this._bignum.config({precision:this._precision}),this.reset()}}get numericMode(){return this._numericMode}set numericMode(e){if(e!==this._numericMode){if("string"!=typeof e)throw Error("Expected a string");this._numericMode=e,"complex"!==e&&"machine"!==e||(this._precision=Math.floor(Sn)),this._latexSyntax&&this.latexSyntax.options.precision>this._precision&&this.latexSyntax.updateOptions({precision:this._precision}),this.jsonSerializationOptions.precision>this._precision&&(this.jsonSerializationOptions={precision:this._precision}),this.reset()}}get timeLimit(){var e;let i=this.context;for(;i;){if(void 0!==i.timeLimit)return i.timeLimit;i=null!==(e=i.parentScope)&&void 0!==e?e:null}return 2}get iterationLimit(){var e;let i=this.context;for(;i;){if(void 0!==i.iterationLimit)return i.iterationLimit;i=null!==(e=i.parentScope)&&void 0!==e?e:null}return 1024}get recursionLimit(){var e;let i=this.context;for(;i;){if(void 0!==i.recursionLimit)return i.recursionLimit;i=null!==(e=i.parentScope)&&void 0!==e?e:null}return 1024}get defaultDomain(){return this._defaultDomain}set defaultDomain(e){if(null===e)this._defaultDomain=null;else{const i=this.domain(e);if(!i.isValid)throw Error("Invalid domain "+e);this._defaultDomain=i}}get tolerance(){return this._tolerance}set tolerance(e){this._tolerance="number"==typeof e&&Number.isFinite(e)?Math.max(e,0):wn,this._bignumTolerance=this.bignum(this._tolerance)}bignum(e){return new this._bignum(e)}complex(e,i){return new Be.exports.Complex(e,i)}chop(e){return"number"==typeof e&&Math.abs(e)<=this._tolerance||e instanceof Ge&&e.abs().lte(this._bignumTolerance)||e instanceof Be.exports.Complex&&Math.abs(e.re)<=this._tolerance&&Math.abs(e.im)<=this._tolerance?0:e}get latexSyntax(){return this._latexSyntax||(this._latexSyntax=new xn({computeEngine:this,dictionary:this._latexDictionary,precision:this.precision,avoidExponentsInRange:[-6,this.precision],onError:e=>{throw Error(e[0].message.toString())}})),this._latexSyntax}static getLatexDictionary(e="all"){return xn.getDictionary(e)}set costFunction(e){"function"!=typeof e&&(this._cost=Zs),this._cost=e}get costFunction(){var e;return null!==(e=this._cost)&&void 0!==e?e:Zs}lookupSymbol(e,i,n){var t,r;if("string"!=typeof e)throw Error("Expected a string");if(0===e.length||e.startsWith("_")||!this.context)return;let s;if(null!=n||(n=this.context),i)for(;n&&!s;)s=null===(t=n.symbolTable)||void 0===t?void 0:t.symbolWikidata.get(i),n=n.parentScope;if(e.length>0)for(n=this.context;n&&!s;)s=null===(r=n.symbolTable)||void 0===r?void 0:r.symbols.get(e),n=n.parentScope;return s}lookupFunction(e,i){var n;if("string"==typeof e&&!e.startsWith("_")&&this.context)for(null!=i||(i=this.context);i;){const t=null===(n=i.symbolTable)||void 0===n?void 0:n.functions.get(e);if(t)return t;i=i.parentScope}}defineSymbol(e){if(!this.context)throw Error("Symbol cannot be defined: no scope available");if(0===e.name.length||!ri(e.name))throw Error("Invalid identifier "+e.name);const i=new Ps(this,e);return this.context.symbolTable||(this.context.symbolTable={symbols:new Map,functions:new Map,symbolWikidata:new Map,functionWikidata:new Map}),i.name&&this.context.symbolTable.symbols.set(i.name,i),i.wikidata&&this.context.symbolTable.symbolWikidata.set(i.wikidata,i),i}defineFunction(e){if(!this.context)throw Error("Function cannot be defined: no scope available");if(0===e.name.length||!ri(e.name))throw Error("Invalid identifier "+e.name);const i=Rs(this,e);return this.context.symbolTable||(this.context.symbolTable={symbols:new Map,functions:new Map,symbolWikidata:new Map,functionWikidata:new Map}),i.name&&this.context.symbolTable.functions.set(e.name,i),i.wikidata&&this.context.symbolTable.functionWikidata.set(i.wikidata,i),i}pushScope(e){var i;if(void 0!==e&&"object"!=typeof e)throw Error("Expected an object literal");if(null===this.context)throw Error("No parent scope available");if(this.context=Object.assign(Object.assign({},null==e?void 0:e.scope),{parentScope:this.context,assumptions:this.context?new Bs(this.context.assumptions):new Bs}),null==e?void 0:e.symbolTable)if(Array.isArray(e.symbolTable))for(const i of e.symbolTable)js(this,i);else js(this,e.symbolTable);if(void 0!==(null==e?void 0:e.assumptions))for(const n of e.assumptions)this.assume(null!==(i=this.parse($n(n)))&&void 0!==i?i:n)}popScope(){var e;if(!this.context)throw Error("No scope available");const i=null===(e=this.context)||void 0===e?void 0:e.parentScope;if(this.context.warnings){const e=[...this.context.warnings];this.context.warnings=[],this.context.warn&&this.context.warn(e)}i&&this.context.warnings&&this.context.warnings.length>0&&(i.warnings?i.warnings=[...i.warnings,...this.context.warnings]:i.warnings=[...this.context.warnings]),this.context=null!=i?i:null}set(e){for(const i of Object.keys(e))if("Nothing"!==i){const n=this.lookupSymbol(i),t=this.box(e[i]);if(n){if(n.domain&&!t.domain.isCompatible(n.domain))throw Error(`Expected value with domain ${n.domain.toString()} for "${i}"`);n.value=t}else t.domain.isNumeric?this.defineSymbol({name:i,value:t,domain:"Number"}):this.defineSymbol({name:i,value:t})}}let(e){for(const i of Object.keys(e))if("Nothing"!==i){const n=e[i];"value"in n||"domain"in n&&"Function"!==n.domain?this.defineSymbol(Object.assign(Object.assign({},n),{name:i})):this.defineFunction(Object.assign(Object.assign({},n),{name:i}))}}get assumptions(){if(!this.context)throw Error("No scope available");return this.context.assumptions||(this.context.assumptions=new Bs),this.context.assumptions}shouldContinueExecution(){return void 0===this.deadline||this.deadline>=Date.now()}checkContinueExecution(){if(!this.shouldContinueExecution())throw Error("timeout")}assert(e,i,n,t){e||this.signal(i,n,t)}signal(e,i,n){"object"==typeof e&&"message"in e?n=e.message:e.latex,void 0===n||"string"==typeof n||Array.isArray(n)&&n.map((e=>e.toString())).join(", ")}cache(e,i,n){var t;if(void 0===this._cache[e])try{this._cache[e]={build:i,purge:n,value:i()}}catch(e){}return null===(t=this._cache[e])||void 0===t?void 0:t.value}box(e,i){return _r(this,e,i)}fn(e,i,n){return Nr(this,e,i,{metadata:n,canonical:!0})}_fn(e,i,n){return new ur(this,e,i,{metadata:n,canonical:!0,def:this.lookupFunction(e,this.context)})}error(e,i){if(i instanceof Gt?i=this.rawJson(i):i&&Array.isArray(i)&&"Latex"===i[0]&&(void 0!==i[1]&&i[1]||(i=""),"object"==typeof i[1]&&"str"in i[1]&&!i[1].str&&(i="")),Array.isArray(e)&&"invalid-domain"===e[0])return Or(this,["Error",["ErrorCode","'invalid-domain'",e[1]]]);const n="string"==typeof e?this.string(e):new ur(this,"ErrorCode",[this.string(e[0]),...e.slice(1).map((e=>this.box(e,{canonical:!1})))]);return new ur(this,"Error",i?[n,this.box(i,{canonical:!1})]:[n],{canonical:!1})}hold(e){return this._fn("Hold",[this.box(e,{canonical:!1})])}add(e,i){const n=Zr(this,e=Xn(e));return void 0!==(null==i?void 0:i.latex)&&(n.latex=i.latex),void 0!==(null==i?void 0:i.wikidata)&&(n.wikidata=i.wikidata),n}negate(e,i){return Ot(e,i)}mul(e,i){const n=is(this,e=Xn(e));return void 0!==(null==i?void 0:i.latex)&&(n.latex=i.latex),void 0!==(null==i?void 0:i.wikidata)&&(n.wikidata=i.wikidata),n}divide(e,i,n){const t=os(this,e,i);return void 0!==(null==n?void 0:n.latex)&&(t.latex=n.latex),void 0!==(null==n?void 0:n.wikidata)&&(t.wikidata=n.wikidata),t}sqrt(e,i){return this.power(e,[1,2],i)}power(e,i,n){var t;let r=null;if(i instanceof Gt){const e=i.numericValue;null!==e&&("number"==typeof e&&(i=e),ht(e)&&(i=e))}if("number"==typeof i?r=i:ht(i)&&(mt(i)&&1===i[1]&&(r=i[0]),dt(i)&&i[1].equals(1)&&(r=i[0].toNumber())),1===r)return e;const s=e.numericValue;if(-1===r&&null!==s){if("number"==typeof s&&Number.isInteger(s))return this.number([1,s]);if(s instanceof Ge&&s.isInteger())return this.number([e.engine._BIGNUM_ONE,s]);if(ht(s))return this.number((dt(s),[s[1],s[0]]))}return("number"==typeof i||ht(i))&&(i=this.number(i)),null!==(t=Yr(this,e,i,n))&&void 0!==t?t:this._fn("Power",[e,i],n)}inverse(e,i){var n;let t=this._NEGATIVE_ONE;if("Power"===e.head){if(e.op2.isNegativeOne)return e.op1;t=Ot(e.op2),e=e.op1}return null!==(n=Yr(this,e,t,i))&&void 0!==n?n:this._fn("Power",[e,t],i)}pair(e,i,n){return new ur(this,"Tuple",[e.canonical,i.canonical],{metadata:n,canonical:!0})}tuple(e,i){return new ur(this,"Tuple",e.map((e=>e.canonical)),{metadata:i,canonical:!0})}string(e,i){return new vr(this,e,i)}symbol(e,i){var n,t,r;if(null!=i||(i={}),"canonical"in i||(i.canonical=!0),"NaN"===(e=e.normalize()))return this._NAN;if("Infinity"===e)return this._POSITIVE_INFINITY;if("+Infinity"===e)return this._POSITIVE_INFINITY;if("-Infinity"===e)return this._NEGATIVE_INFINITY;if("Half"===e)return this._HALF;if(!ri(e)){const t=null===(n=null==i?void 0:i.metadata)||void 0===n?void 0:n.latex,r=`'${e}'`;if(t)return this.error(["invalid-symbol-name",r],t?["Latex",`'${t}'`]:r)}if(void 0!==(null===(t=null==i?void 0:i.metadata)||void 0===t?void 0:t.latex)&&!i.canonical)return new Ks(this,e,i);let s=this._commonSymbols[e];return s?(null===(r=null==i?void 0:i.metadata)||void 0===r?void 0:r.wikidata)&&s.wikidata&&s.wikidata!==i.metadata.wikidata?i.canonical?Xs(this,e):new Ks(this,e,i):s:null===s?(s=Xs(this,e),this._commonSymbols[e]=s,s):i.canonical?Xs(this,e):new Ks(this,e,i)}domain(e,i){var n;return e instanceof qr?e:(e instanceof Gt&&e.symbol&&(e=e.symbol),"string"==typeof e&&(null===this._commonDomains[e]&&(this._commonDomains[e]=Or(this,e,i)),this._commonDomains[e])?this._commonDomains[e]:Dr(e)?Or(this,e,i):this.error(["invalid-domain",{str:JSON.stringify(e)}],["Latex",{str:null!==(n=null==i?void 0:i.latex)&&void 0!==n?n:""}]))}number(e,i){var n;if(null!=i||(i={}),"canonical"in i||(i.canonical=!0),void 0===i.metadata&&"number"==typeof e){const i=e;if(1===i)return this._ONE;if(0===i)return this._ZERO;if(-1===i)return this._NEGATIVE_ONE;if(isNaN(i))return this._NAN;if(!Number.isFinite(i))return i<0?this._NEGATIVE_INFINITY:this._POSITIVE_INFINITY;if(Number.isInteger(i)&&null===this._commonNumbers[i])return this._commonNumbers[i]=br(this,e),null===this._commonNumbers[i]?this._NAN:this._commonNumbers[i]}return null!==(n=br(this,e,i))&&void 0!==n?n:this._NAN}rules(e){return Qn(this,e)}pattern(e){return new Us(this,e)}parse(e,i){var n;return"string"!=typeof e?null:this.box(this.latexSyntax.parse(null!==(n=$n(e))&&void 0!==n?n:e),i)}serialize(e){if("object"==typeof e&&"json"in e){const i="engine"in e?e.engine:this;return this.latexSyntax.serialize(this.rawJson(i.box(e,{canonical:!1})))}return this.latexSyntax.serialize(e)}get latexOptions(){const e=this.latexSyntax;return new Proxy(Object.assign(Object.assign({},this.latexSyntax.options),this.latexSyntax.serializer.options),{set:(i,n,t)=>n in i&&(e.updateOptions({[n]:t}),!0)})}set latexOptions(e){this.latexSyntax.updateOptions(e)}get jsonSerializationOptions(){return this._useRawJsonSerializationOptions?this._rawJsonSerializationOptions:this._jsonSerializationOptions}set jsonSerializationOptions(e){e.exclude&&(this._jsonSerializationOptions.exclude=[...e.exclude]),e.shorthands&&("all"===e.shorthands||e.shorthands.includes("all")?this._jsonSerializationOptions.shorthands=["function","symbol","string","dictionary","number"]:this._jsonSerializationOptions.shorthands=[...e.shorthands]),e.metadata&&("all"===e.metadata||e.metadata.includes("all")?this._jsonSerializationOptions.metadata=["latex","wikidata"]:this._jsonSerializationOptions.metadata=[...e.metadata]),"number"==typeof e.precision&&e.precision>0&&(this._jsonSerializationOptions.precision=e.precision),"boolean"==typeof e.repeatingDecimals&&(this._jsonSerializationOptions.repeatingDecimals=e.repeatingDecimals)}rawJson(e){const i=this._useRawJsonSerializationOptions;this._useRawJsonSerializationOptions=!0;const n=e.json;return this._useRawJsonSerializationOptions=i,n}ask(e){const i=this.pattern(e),n=[];for(const[e,t]of this.assumptions){const r=i.match(e,{numericTolerance:this._tolerance});null!==r&&!0===t&&n.push(r)}return n}infer(e,i){if("string"!=typeof e){if(!e.symbol)return"internal-error";e=e.symbol}return"ok"}assume(e,i){try{const n=$n(e),t=n?this.parse(n,{canonical:!1}):this.box(e,{canonical:!1});return i?Dr(i)?zt(this.box(["Element",t,this.domain(i)])):zt(this.box(["Equal",t,i])):zt(t)}catch(e){return"internal-error"}}forget(e){if(!this.context)throw Error("No scope available");if(void 0===e)return this.context.symbolTable=void 0,void this.assumptions.clear();if(Array.isArray(e))for(const i of e)this.forget(i);else if("string"==typeof e){this.context.symbolTable&&(this.context.symbolTable.symbols.delete(e),this.context.symbolTable.symbolWikidata.delete(e),this.context.symbolTable.functions.delete(e),this.context.symbolTable.functionWikidata.delete(e));for(const[i,n]of this.assumptions)jn(i).includes(e)&&this.assumptions.delete(i)}}}e.ComputeEngine=eo,e.getVars=jn,e.isEnvironmentEntry=a,e.isFunctionEntry=n,e.isInfixEntry=r,e.isMatchfixEntry=t,e.isPostfixEntry=o,e.isPrefixEntry=s,e.isSymbolEntry=i,e.version="0.9.0",Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).ComputeEngine={});