pimath 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pi.js +1 -1
- package/dist/pi.js.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/algebra.Algebra.Equation.html +26 -0
- package/docs/classes/algebra.Algebra.LinearSystem.html +1 -0
- package/docs/classes/algebra.Algebra.LogicalSet.html +3 -0
- package/docs/classes/algebra.Algebra.Monom.html +36 -36
- package/docs/classes/algebra.Algebra.Polynom.html +11 -11
- package/docs/classes/algebra.Algebra.Rational.html +2 -0
- package/docs/classes/algebra.Equation.html +9 -9
- package/docs/classes/algebra.LinearSystem.html +1 -1
- package/docs/classes/algebra.Logicalset.html +2 -2
- package/docs/classes/algebra.Monom.html +36 -36
- package/docs/classes/algebra.Polynom.html +12 -12
- package/docs/classes/algebra.Rational.html +2 -2
- package/docs/classes/coefficients.Fraction.html +4 -4
- package/docs/classes/coefficients.Nthroot.html +1 -1
- package/docs/classes/geometry.Circle.html +1 -1
- package/docs/classes/geometry.Geometry.Circle.html +1 -0
- package/docs/classes/geometry.Geometry.Line.html +1 -0
- package/docs/classes/geometry.Geometry.Point.html +1 -0
- package/docs/classes/geometry.Geometry.Triangle.html +9 -0
- package/docs/classes/geometry.Geometry.Vector.html +1 -0
- package/docs/classes/geometry.Line.html +1 -1
- package/docs/classes/geometry.Point.html +1 -1
- package/docs/classes/geometry.Triangle.html +6 -6
- package/docs/classes/geometry.Vector.html +1 -1
- package/docs/classes/numeric.Numeric.html +5 -5
- package/docs/classes/shutingyard.Shutingyard.html +5 -5
- package/docs/interfaces/geometry.remarquableLines.html +1 -1
- package/docs/modules/algebra.Algebra.html +1 -1
- package/docs/modules/geometry.Geometry.html +1 -0
- package/docs/modules/geometry.html +1 -1
- package/docs/modules/random.Random.html +1 -1
- package/docs/modules/random.html +1 -1
- package/esm/maths/algebra/index.d.ts +12 -0
- package/esm/maths/algebra/index.js +16 -0
- package/esm/maths/algebra/index.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +2 -0
- package/esm/maths/algebra/polynom.js +3 -0
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/geometry/index.d.ts +17 -0
- package/esm/maths/geometry/index.js +23 -0
- package/esm/maths/geometry/index.js.map +1 -1
- package/esm/maths/random/index.js +1 -1
- package/esm/maths/random/index.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/index.ts +8 -0
- package/src/maths/algebra/polynom.ts +5 -1
- package/src/maths/geometry/index.ts +15 -1
- package/src/maths/random/index.ts +2 -2
package/dist/pi.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{"use strict";class e{static round(e,t=2){return Number(Math.round(Number(e+"e"+t))+"e-"+t)}static prime(e){let t=[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,7927,7933,7937,7949,7951,7963,7993,8009,8011,8017,8039,8053,8059,8069,8081,8087,8089,8093,8101,8111,8117,8123,8147,8161,8167,8171,8179,8191,8209,8219,8221,8231,8233,8237,8243,8263,8269,8273,8287,8291,8293,8297,8311,8317,8329,8353,8363,8369,8377,8387,8389,8419,8423,8429,8431,8443,8447,8461,8467,8501,8513,8521,8527,8537,8539,8543,8563,8573,8581,8597,8599,8609,8623,8627,8629,8641,8647,8663,8669,8677,8681,8689,8693,8699,8707,8713,8719,8731,8737,8741,8747,8753,8761,8779,8783,8803,8807,8819,8821,8831,8837,8839,8849,8861,8863,8867,8887,8893,8923,8929,8933,8941,8951,8963,8969,8971,8999,9001,9007,9011,9013,9029,9041,9043,9049,9059,9067,9091,9103,9109,9127,9133,9137,9151,9157,9161,9173,9181,9187,9199,9203,9209,9221,9227,9239,9241,9257,9277,9281,9283,9293,9311,9319,9323,9337,9341,9343,9349,9371,9377,9391,9397,9403,9413,9419,9421,9431,9433,9437,9439,9461,9463,9467,9473,9479,9491,9497,9511,9521,9533,9539,9547,9551,9587,9601,9613,9619,9623,9629,9631,9643,9649,9661,9677,9679,9689,9697,9719,9721,9733,9739,9743,9749,9767,9769,9781,9787,9791,9803,9811,9817,9829,9833,9839,9851,9857,9859,9871,9883,9887,9901,9907,9923,9929,9931,9941,9949,9967,9973];return void 0===e?t:t.slice(0,Math.max(t.length,e))}static dividers(e){let t;const i=Math.sqrt(Math.abs(e));t=[];for(let s=1;s<=i;s++)e%s==0&&(t.push(s),t.push(e/s));return t.sort((function(e,t){return e-t})),[...new Set(t)]}static gcd(...e){let t=function(e,i){return 0===i?e:t(i,e%i)},i=1,s=2;if(0===e.length)return 1;if(1===e.length)return 0===e[0]?1:e[0];if(i=t(e[0],e[1]),1===i)return 1;for(s=2;s<e.length&&(i=t(i,e[s]),1!==i);s++);return Math.abs(i)}static lcm(...t){return t.reduce((function(t,i){return Math.abs(t*i/e.gcd(t,i))}))}}class t{_rpn=[];_mode;_tokenConfig;_uniformize;constructor(e){this._mode=void 0===e?"polynom":e,this.tokenConfigInitialization()}isOperation(e){return!!e[0].match(/[+\-*/^]/g)}tokenConfigInitialization(){return"set"===this._mode?(this._tokenConfig={"&":{precedence:3,associative:"left"},"|":{precedence:3,associative:"left"},"!":{precedence:4,associative:"right"},"-":{precedence:2,associative:"left"}},this._uniformize=!1):(this._tokenConfig={"^":{precedence:4,associative:"right"},"*":{precedence:3,associative:"left"},"/":{precedence:3,associative:"left"},"+":{precedence:2,associative:"left"},"-":{precedence:2,associative:"left"},"%":{precedence:3,associative:"right"},sin:{precedence:4,associative:"right"},cos:{precedence:4,associative:"right"},tab:{precedence:4,associative:"right"}},this._uniformize=!0),this._tokenConfig}NextToken2(e,t){let i,s;if(i="",s="","("===e[t])i="(",s="(";else if(")"===e[t])i=")",s=")";else if(","===e[t])i=",",s="function-argument";else{const n=Object.keys(this._tokenConfig).sort(((e,t)=>t.length-e.length));for(let r of n)if(e.substr(t,r.length)===r){i+=r,s="operation";break}""===i&&(e[t].match(/[0-9]/)?(i=e.substr(t).match(/^([0-9.,/]+)/)[0],s="coefficient"):e[t].match(/[a-zA-Z]/)?(i=e.substr(t).match(/^([a-zA-Z])/)[0],s="variable"):(console.log("Unidentified token",e[t],e,t),i=e[t],s="monom"))}return[i,t+i.length,s]}NextToken(e,t){let i,s,n;return this.NextToken2(e,t),i=e.substr(t).match(/^[0-9/a-zA-Z^]+/g)||[],e.substr(t,t+3).match(/^(sin|cos|tan)/g)?(s=e.substr(t,3),n="function"):i.length>0?(s=i[0],n="monom"):e[t].match(/[+\-*/^]/g)||e[t].match(/[&|!]/g)?(s=e[t],n="operation"):"("===e[t]?(s="(",n="("):")"===e[t]?(s=")",n=")"):","===e[t]?(s=",",n="function-argument"):(s=i[0],n="monom",""===s&&(s=e[t],n="monom",console.log("SHUTING YARD - NEXT TOKEN: error at ",t))),[s,t+s.length,n]}Uniformizer(e){if(!this._uniformize)return e;let t;t=e.replace(/\)\(/g,")*("),t=t.replace(/([\da-zA-Z])(\()/g,"$1*$2"),t=t.replace(/(\))([\da-zA-Z])/g,"$1*$2"),t=t.replace(/([0-9])([a-zA-Z])/g,"$1*$2"),t=t.replace(/([a-zA-Z])([0-9])/g,"$1*$2"),t=t.replace(/([abcxyz])([abcxyz])/g,"$1*$2");let i=["sin","cos","tan"];for(let e of i)t=t.replace(new RegExp(e+"\\*","g"),e);return t}parse(e,t){let i=[],s=[],n="",r=0,o="",l=0;e=this.Uniformizer(e);let h,a=50;for(;r<e.length;){if(a--,0===a){console.log("SECURITY LEVEL 1 EXIT");break}switch([n,r,o]=this.NextToken2(e,r),o){case"monom":case"coefficient":case"variable":i.push({token:n,tokenType:o});break;case"operation":if(l=s.length,s.length>0){let e=s[s.length-1];for(h=50;e.token in this._tokenConfig&&("left"===this._tokenConfig[n].associative&&this._tokenConfig[n].precedence<=this._tokenConfig[e.token].precedence||"right"===this._tokenConfig[n].associative&&this._tokenConfig[n].precedence<this._tokenConfig[e.token].precedence);){if(h--,0===h){console.log("SECURITY LEVEL 2 OPERATION EXIT");break}if(i.push(s.pop()||{token:"",tokenType:"operation"}),0===s.length)break;e=s[s.length-1]}}s.push({token:n,tokenType:o});break;case"function-argument":for(h=50;"("!==s[s.length-1].token&&s.length>0;){if(h--,0===h){console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");break}i.push(s.pop()||{token:n,tokenType:o})}break;case"(":s.push({token:n,tokenType:o}),"-"===e[r]&&i.push({token:"0",tokenType:"coefficient"});break;case")":for(h=50;"("!==s[s.length-1].token&&s.length>1;){if(h--,0===h){console.log("SECURITY LEVEL 2 CLOSING PARENTHESE EXIT");break}i.push(s.pop()||{token:n,tokenType:o})}s.pop();break;case"function":s.push({token:n,tokenType:o});break;default:console.log(`SHUTING YARD: ${o} : ${n} `)}}return this._rpn=i.concat(s.reverse()),this}get rpn(){return this._rpn}}class i{_config;_defaultConfig;mergeConfig=(e,t)=>void 0!==e?{...t,...e}:t;generate=()=>{};config=e=>(this._config=this.mergeConfig(e,this._defaultConfig),this)}class s{_numerator;_denominator;constructor(e,t){return this._numerator=1,this._denominator=1,void 0!==e&&this.parse(e,t),this}get isFraction(){return!0}get numerator(){return this._numerator}set numerator(e){this._numerator=e}get denominator(){return this._denominator}set denominator(e){this._denominator=e}get value(){return this._numerator/this._denominator}get tex(){return 1===this._denominator?`${this._numerator}`:this._numerator<0?`-\\frac{ ${-this._numerator} }{ ${this._denominator} }`:`\\frac{ ${this._numerator} }{ ${this._denominator} }`}get display(){return 1===this._denominator?`${this._numerator}`:`${this._numerator}/${this._denominator}`}get frac(){return this.tex}get dfrac(){return this.tex.replace("\\frac","\\dfrac")}parse=(e,t)=>{let i;if(null===e||""===e)return this._numerator=0,this._denominator=1,this;switch(typeof e){case"string":if(i=e.split("/"),i.length>2)throw"Two many divide signs";if(i.map((e=>""===e||isNaN(Number(e)))).includes(!0))throw"Not a number";if(1===i.length)return this.parse(+i[0]);2===i.length?"0"===i[1]?(this._numerator=NaN,this._denominator=1):(this._numerator=+i[0],this._denominator=+i[1]):(this._numerator=NaN,this._denominator=1);break;case"number":if(Number.isSafeInteger(e))this._numerator=+e,void 0!==t&&Number.isSafeInteger(t)?this._denominator=+t:this._denominator=1;else{let i=e.toString().split(".")[1].length;void 0===t?(this._numerator=e*Math.pow(10,i),this._denominator=Math.pow(10,i)):Number.isSafeInteger(t)&&(this._numerator=e*Math.pow(10,i)-Math.floor(e*Math.pow(10,i-t)),this.denominator=Math.pow(10,i)-Math.pow(10,i-t))}break;case"object":e.isFraction&&(this._numerator=+e.numerator,this._denominator=+e.denominator)}return this};clone=()=>{let e=new s;return e.numerator=+this._numerator,e.denominator=+this._denominator,e};zero=()=>(this._numerator=0,this._denominator=1,this);one=()=>(this._numerator=1,this._denominator=1,this);infinite=()=>(this._numerator=1/0,this._denominator=1,this);invalid=()=>(this._numerator=NaN,this._denominator=1,this);opposed=()=>(this._numerator=-this._numerator,this);add=e=>{let t=this._numerator,i=this._denominator;return this._numerator=t*e.denominator+e.numerator*i,this._denominator=i*e.denominator,this.reduce()};subtract=e=>this.add(e.clone().opposed());multiply=e=>{let t=new s(e);return this._numerator=this._numerator*t.numerator,this._denominator=this._denominator*t.denominator,this.reduce()};divide=e=>{let t=new s(e);if(0===t.numerator)return(new s).infinite();let i=+this._numerator,n=+this._denominator;return this._numerator=i*t.denominator,this._denominator=n*t.numerator,this.reduce()};invert=()=>{let e=+this._numerator,t=+this._denominator;return this._numerator=t,this._denominator=e,this};pow=e=>Number.isSafeInteger(e)?(this.reduce(),e<0&&this.invert(),this._numerator=this._numerator**Math.abs(e),this._denominator=this._denominator**Math.abs(e),this):this.invalid();root=e=>(0===e||(e<0&&this.invert(),Math.pow(this._numerator,Math.abs(1/e)),Math.pow(this._denominator,Math.abs(1/e)),this._numerator=Math.pow(this._numerator,Math.abs(1/e)),this._denominator=Math.pow(this._denominator,Math.abs(1/e))),this);sqrt=()=>this.root(2);abs=()=>(this._numerator=Math.abs(this._numerator),this._denominator=Math.abs(this._denominator),this);reduce=()=>{let t=e.gcd(this._numerator,this._denominator);return this._numerator=this._numerator/t,this._denominator=this._denominator/t,this._denominator<0&&(this._denominator=-this._denominator,this._numerator=-this._numerator),this};amplify=e=>(Number.isSafeInteger(e)&&(this._numerator*=e,this._denominator*=e),this);compare=(e,t)=>{switch(void 0===t&&(t="="),t){case">":return this.value>e.value;case">=":return this.value>=e.value;case"<":return this.value<e.value;case"<=":return this.value<=e.value;case"=":return this.value===e.value;case"<>":return this.value!==e.value;default:return!1}};lesser=e=>this.compare(e,"<");leq=e=>this.compare(e,"<=");greater=e=>this.compare(e,">");geq=e=>this.compare(e,">=");isEqual=e=>this.compare(e,"=");isDifferent=e=>this.compare(e,"<>");isOpposed=e=>this.isEqual(e.clone().opposed());isInverted=e=>this.isEqual((new s).one().divide(e.clone()));isZero=()=>0===this._numerator;isOne=()=>1===this._numerator&&1===this._denominator;isPositive=()=>1===this.sign();isNegative=()=>-1===this.sign();isNaN=()=>isNaN(this._numerator);isInfinity=()=>this._numerator===1/0;isFinite=()=>!this.isInfinity();isSquare=()=>Math.sqrt(this._numerator)%1==0&&Math.sqrt(this._denominator)%1==0;isReduced=()=>1===Math.abs(e.gcd(this._numerator,this._denominator));sign=()=>this._numerator*this._denominator>=0?1:-1;areEquals=(...e)=>{for(let t=0;t<e.length;t++)if(!this.isEqual(e[t]))return!1;return!0}}class n{_coefficient;_literal;constructor(e){return this.zero(),void 0!==e&&this.parse(e),this}get isMonom(){return!0}get coefficient(){return this._coefficient}set coefficient(e){this._coefficient=e}get literal(){return this._literal}get literalSqrt(){if(this.isLitteralSquare()){let e={};for(let t in this._literal)e[t]=this._literal[t]/2;return e}return this._literal}set literal(e){this._literal=e}set literalStr(e){for(const t of[...e.matchAll(/([a-z])\^([+-]?[0-9]+)/g)])t[1]in this._literal||(this._literal[t[1]]=0),this._literal[t[1]]+=+t[2];for(const t of[...e.matchAll(/([a-z](?!\^))/g)])t[1]in this._literal||(this._literal[t[1]]=0),this._literal[t[1]]+=1}get variables(){return this.clone().clean(),Object.keys(this._literal)}get display(){let e="";for(let t in this._literal)0!==this._literal[t]&&(e+=`${t}`,this._literal[t]>1&&(e+=`^${this._literal[t]}`));return""===e?0!=this._coefficient.value?`${this._coefficient.display}`:"":1===this._coefficient.value?e:-1===this._coefficient.value?`-${e}`:0===this._coefficient.value?"0":`${this._coefficient.display}${e}`}get dividers(){if(1!==this.coefficient.denominator)return[this.clone()];if(this.coefficient.numerator>1e4)return[this.clone()];const t=e.dividers(Math.abs(this.coefficient.numerator));let i=[];for(let e in this.literal)i=this._getLitteralDividers(i,e);const r=[];if(i.length>0&&t.length>0)for(let e of t)for(let t of i){let i=new n;i.coefficient=new s(e),i.literal=t,r.push(i)}else if(0===t.length)for(let e of i){let t=new n;t.coefficient=(new s).one(),t.literal=e,r.push(t)}else for(let e of t){let t=new n;t.coefficient=new s(e),r.push(t)}return 0===r.length?[(new n).one()]:r}_getLitteralDividers(e,t){let i=[];for(let s=0;s<=this.literal[t];s++)if(0===e.length){let e={};e[t]=s,i.push(e)}else for(let n of e){let e={};for(let t in n)e[t]=n[t];e[t]=s,i.push(e)}return i}get displayWithSign(){let e=this.display;return("-"!==e[0]?"+":"")+e}get tex(){let e="";for(let t in this._literal)0!==this._literal[t]&&(e+=`${t}`,this._literal[t]>1&&(e+=`^${this._literal[t]}`));return""===e?0!=this._coefficient.value?`${this._coefficient.dfrac}`:"0":1===this._coefficient.value?e:-1===this._coefficient.value?`-${e}`:0===this._coefficient.value?"0":`${this._coefficient.dfrac}${e}`}parse=e=>{this.literalStr=e,this._coefficient=new s;for(const t of[...e.replace(/([a-z])|(\^[+-]?[0-9]+)/g,",").split(",")])""!==t.trim()&&this._coefficient.multiply(new s(t.trim()));return this};clone=()=>{let e=new n;e.coefficient=this._coefficient.clone();for(let t in this._literal)e.setLetter(t,this._literal[t]);return e};zero=()=>(this._coefficient=(new s).zero(),this._literal={},this);one=()=>(this._coefficient=(new s).one(),this._literal={},this);clean=()=>{for(let e in this._literal)0===this._literal[e]&&delete this._literal[e];return this};opposed=()=>(this._coefficient.opposed(),this);add=(...e)=>{for(let t of e)this.isSameAs(t)?this._coefficient.add(t.coefficient):console.log("Add: Is not similar: ",t.display);return this};subtract=(...e)=>{for(let t of e)this.isSameAs(t)?this._coefficient.add(t.coefficient.clone().opposed()):console.log("Subtract: Is not similar: ",t.display);return this};multiply=(...e)=>{for(let t of e){this._coefficient.multiply(t.coefficient);for(let e in t.literal)this._literal[e]=void 0===this._literal[e]?t.literal[e]:this._literal[e]+t.literal[e]}return this};multiplyByNumber=e=>(this._coefficient.multiply(e),this);divide=(...e)=>{for(let t of e){this._coefficient.divide(t.coefficient);for(let e in t.literal)this._literal[e]=void 0===this._literal[e]?-t.literal[e]:this._literal[e]-t.literal[e],0===this._literal[e]&&delete this._literal[e]}return this};pow=e=>{this._coefficient.pow(e);for(let t in this._literal)this._literal[t]*=e;return this};root=e=>this;sqrt=()=>{if(this.isSquare()){this._coefficient.sqrt();for(let e in this._literal)this._literal[e]/=2}return this.root(2)};compare=(e,t)=>{switch(void 0===t&&(t="="),t){case"=":return!!this.compare(e,"same")&&this._coefficient.isEqual(e.coefficient);case"same":let t=this.variables,i=e.variables,s=t.concat(i.filter((e=>t.indexOf(e)<0)));for(let t of s){if(void 0===this._literal[t]||void 0===e.literal[t])return!1;if(this._literal[t]!==e.literal[t])return!1}return!0;default:return!1}};isZero(){return 0===this._coefficient.value}isOne(){return 1===this._coefficient.value&&0===this.variables.length}isEqual=e=>this.compare(e,"=");isSameAs=e=>this.compare(e,"same");isSquare=()=>!!this.coefficient.isSquare()&&this.isLitteralSquare();isLitteralSquare=()=>{for(let e in this.literal)if(this.literal[e]%2!=0)return!1;return!0};hasLetter=e=>this._literal[void 0===e?"x":e]>0;setLetter=(e,t)=>{t<=0||!Number.isSafeInteger(t)?void 0!==this._literal[e]&&delete this._literal[e]:this._literal[e]=t};degree=e=>0===this.variables.length?0:void 0===e?Object.values(this._literal).reduce(((e,t)=>e+t)):void 0===this._literal[e]?0:this._literal[e];evaluate=e=>{let t=this.coefficient.clone();if("number"==typeof e||e instanceof s){let t={};return t[this.variables[0]]=new s(e),this.evaluate(t)}if("object"==typeof e)for(let i in this._literal){if(void 0===e[i])return(new s).zero();let n=new s(e[i]);t.multiply(n.pow(this._literal[i]))}return t};derivative=e=>{if(void 0===e&&(e="x"),this.hasLetter(e)){let t=+this._literal[e],i=this.clone();return i._literal[e]-=1,i._coefficient.multiply(new s(""+t)),i}return(new n).zero()};primitive=e=>{void 0===e&&(e="x");let t=this.clone();return t.hasLetter(e)?(t.coefficient=t.coefficient.clone().divide(t.degree(e)+1),t.setLetter(e,t.degree(e)+1)):(t.coefficient.isZero()&&(t.coefficient=(new s).one()),t.setLetter(e,1)),t};static lcm=(...t)=>{let i=new n,r=t.map((e=>e.coefficient.numerator)),o=t.map((e=>e.coefficient.denominator)),l=e.gcd(...r),h=e.lcm(...o);i.coefficient=new s(l,h).reduce();for(let e of t){for(let t in i.literal)t in e.literal||(i.literal[t]=0);for(let t in e.literal)void 0===i.literal[t]&&e.literal[t]>0?i.literal[t]=e.literal[t]:i.literal[t]=Math.min(e.literal[t],i.literal[t])}return i};static xmultiply=(...e)=>{let t=(new n).one();for(let i of e)t.multiply(i);return t};areSameAs=(...e)=>{for(let t=0;t<e.length;t++)if(!this.isSameAs(e[t]))return!1;return!0};areEquals=(...e)=>{if(!this.areSameAs(...e))return!1;for(let t of e)if(!this._coefficient.isEqual(t.coefficient))return!1;return!0}}class r extends i{constructor(e){super(),this._defaultConfig={letters:"x",degree:2,fraction:!0,zero:!1},this._config=this.mergeConfig(e,this._defaultConfig)}generate=()=>{let e=new n;if(e.coefficient.parse(a.numberSym(10,this._config.zero),this._config.fraction?a.number(1,10):1).reduce(),this._config.letters.length>1){for(let t of this._config.letters.split(""))e.setLetter(t,0);for(let t=0;t<this._config.degree;t++){const t=a.item(this._config.letters.split(""));e.setLetter(t,e.degree(t)+1)}}else e.setLetter(this._config.letters,this._config.degree);return e}}class o{_rawString;_monoms;_factors;_texString;constructor(e,...t){return this._monoms=[],this._factors=[],void 0!==e&&this.parse(e,...t),this}get isPolynom(){return!0}get monoms(){return this._monoms}set monoms(e){this._monoms=e}get factors(){return this._factors}set factors(e){this._factors=e}get texFactors(){this.factorize();let e="";for(let t of this.factors)t.monoms.length>1?e+=`(${t.tex})`:e=t.tex+e;return e}get texString(){return this._texString}get length(){return this._monoms.length}get display(){return this.genDisplay()}get raw(){return this._rawString}get tex(){return this.genDisplay("tex")}get isMultiVariable(){for(const e of this._monoms)if(e.variables.length>1)return!0;return!1}get variables(){let e=[];for(const t of this._monoms)e=e.concat(t.variables);return e=[...new Set(e)],e}get numberOfVars(){return this.variables.length}genDisplay=(e,t,i)=>{let s="";for(const i of this._monoms)0!==i.coefficient.value&&(s+=`${1!==i.coefficient.sign()||""===s&&!0!==t?"":"+"}${"tex"===e?i.tex:i.display}`);return!0===i&&this.length>1&&(s="tex"===e?`\\left( ${s} \\right)`:`(${s})`),""===s&&(s="0"),s};parse=(e,...t)=>{if(void 0===t||0===t.length){if(e=""+e,this._rawString=e,""!==e&&!isNaN(Number(e))){this.empty();let t=new n;return t.coefficient=new s(e),t.literalStr="",this.add(t),this}return this.shutingYardToReducedPolynom(e)}if(/^[a-z]/.test(e)){this.empty();let i=t.map((e=>new s(e)));if(e.length>1){let t=e.split(""),s=0;for(let e of i){let i=new n;i.coefficient=e.clone(),i.literalStr=t[s]||"",this.add(i),s++}}else{let t=i.length-1;for(let s of i){let i=new n;i.coefficient=s.clone(),i.literalStr=`${e}^${t}`,this.add(i),t--}}return this}return this.zero()};shutingYardToReducedPolynom=e=>{const i=(new t).parse(e).rpn;let s,r,l,h=[],a=null;for(const e of i){if("coefficient"===e.tokenType||"variable"===e.tokenType)l=(new o).zero(),l.monoms=[new n(e.token)],h.push(l.clone());else if("operation"===e.tokenType)switch(r=h.pop()||(new o).zero(),s=h.pop()||(new o).zero(),e.token){case"+":h.push(s.add(r));break;case"-":h.push(s.subtract(r));break;case"*":h.push(s.multiply(r));break;case"^":h.push(s.pow(+a))}a=e.token}return this._monoms=h[0].monoms,this};clone=()=>{const e=new o,t=[];for(const e of this._monoms)t.push(e.clone());return e.monoms=t,e};zero=()=>(this._monoms=[],this._monoms.push((new n).zero()),this._rawString="0",this);one=()=>(this._monoms=[],this._monoms.push((new n).one()),this._rawString="1",this);empty=()=>(this._monoms=[],this._rawString="",this);_randomizeDefaults={degree:2,unit:!0,fractions:!1,factorable:!1,letters:"x",allowNullMonom:!1,numberOfMonoms:!1};get randomizeDefaults(){return this._randomizeDefaults}set randomizeDefaults(e){this._randomizeDefaults=e}randomize=e=>{let t=new o;void 0===e&&(e={});for(let t in this._randomizeDefaults)void 0===e[t]&&(e[t]=this._randomizeDefaults[t]);return t};rndFactorable=(e=2,t=!1,i="x")=>{this._factors=[];for(let s=0;s<e;s++){let e=!0===t||s>=t,n=a.polynom({degree:1,unit:e,fraction:!1,letters:i});this._factors.push(n)}this.empty().monoms=this._factors[0].monoms;for(let e=1;e<this._factors.length;e++)this.multiply(this._factors[e]);return this};opposed=()=>(this._monoms=this._monoms.map((e=>e.opposed())),this);add=(...e)=>{for(let t of e)t.isPolynom?this._monoms=this._monoms.concat(t.monoms):t.isMonom?this._monoms.push(t.clone()):Number.isSafeInteger(t)?this._monoms.push(new n(t.toString())):this._monoms.push(new n(t));return this.reduce()};subtract=(...e)=>{for(let t of e)t.isPolynom?this._monoms=this._monoms.concat(t.clone().opposed().monoms):t.isMonom?this._monoms.push(t.clone().opposed()):Number.isSafeInteger(t)?this._monoms.push(new n(t.toString()).opposed()):this._monoms.push(new n(t).opposed());return this.reduce()};multiply=e=>e.isPolynom?this.multiplyByPolynom(e):e.isFraction?this.multiplyByFraction(e):e.isMonom?this.multiplyByMonom(e):Number.isSafeInteger(e)?this.multiplyByInteger(e):this;multiplyByPolynom=e=>{const t=[];for(const i of this._monoms)for(const s of e.monoms)t.push(n.xmultiply(i,s));return this._monoms=t,this.reduce()};multiplyByFraction=e=>{for(const t of this._monoms)t.coefficient.multiply(e);return this.reduce()};multiplyByInteger=e=>this.multiplyByFraction(new s(e));multiplyByMonom=e=>{for(const t of this._monoms)t.multiply(e);return this.reduce()};euclidian=e=>{const t=e.variables[0],i=(new o).zero(),s=this.clone().reorder(t);if(0===e.variables.length)return{quotient:i,reminder:s};const n=e.monomByDegree(void 0,t),r=e.degree(t);let l,h=2*this.degree(t);for(;s.degree(t)>=r&&h>=0&&(h--,l=s.monomByDegree(void 0,t).clone().divide(n),!l.isZero());)i.add(l),s.subtract(e.clone().multiply(l));return{quotient:i,reminder:s}};divide=e=>{if(e.isFraction)this.divideByFraction(e);else if(Number.isSafeInteger(e))return this.divideByInteger(e)};divideByInteger=e=>{const t=new s(e);for(const e of this._monoms)e.coefficient.divide(t);return this};divideByFraction=e=>{for(const t of this._monoms)t.coefficient.divide(e);return this};pow=e=>{if(!Number.isSafeInteger(e))return this.zero();if(e<0)return this.zero();if(0===e)return new o;const t=this.clone();for(let i=1;i<e;i++)this.multiply(t);return this.reduce()};compare=(e,t)=>{void 0===t&&(t="=");const i=this.clone().reduce().reorder(),s=e.clone().reduce().reorder();switch(t){case"=":if(i.length!==s.length||i.degree()!==s.degree())return!1;for(const e in i.monoms)if(!i.monoms[e].isEqual(s.monoms[e]))return!1;return!0;case"same":if(i.length!==s.length||i.degree()!==s.degree())return!1;for(const e in i.monoms)if(!i.monoms[e].isSameAs(s.monoms[e]))return!1;return!0;default:return!1}};isZero(){return 1===this._monoms.length&&this._monoms[0].coefficient.isZero()||0===this._monoms.length}isOne(){return 1===this._monoms.length&&this._monoms[0].coefficient.isOne()}isEqual=e=>this.compare(e,"=");isSameAs=e=>this.compare(e,"same");isOpposedAt=e=>this.compare(e.clone().opposed(),"=");isFactorized=e=>{let t;if(e.match(/\(/g).length!==e.match(/\)/g).length)return!1;try{t=new o(e)}catch(e){return!1}if(!this.isEqual(t))return!1;let i=e.replaceAll("*",""),s=""+i,n=[];for(let e of i.matchAll(/\(([a-z0-9+\-]+)\)(\^[0-9]*)?/g)){if(void 0!==e[2])for(let t=0;t<+e[2].substr(1);t++)n.push(e[1]);else n.push(e[1]);s=s.replaceAll(e[0],"")}""!==s&&n.push(s);let r=n.map((e=>new o(e)));this.factorize();let l=1;for(let e of this.factors)for(let t=0;t<r.length;t++){if(e.isEqual(r[t])){r.splice(t,1);break}if(e.isOpposedAt(r[t])){r.splice(t,1),l=-l;break}}return 0===r.length&&1===l};isDeveloped=e=>{let t;if(e.match(/\(/g).length+e.match(/\)/g).length)return!1;try{t=new o(e)}catch(e){return!1}return!!this.isEqual(t)&&e.replaceAll("[*s]","")===t.reduce().reorder().display};reduce=()=>{for(let e=0;e<this._monoms.length;e++)for(let t=e+1;t<this._monoms.length;t++)this._monoms[e].isSameAs(this.monoms[t])&&(this._monoms[e].add(this.monoms[t]),this._monoms.splice(t,1));this._monoms=this._monoms.filter((e=>0!==e.coefficient.value));for(const e of this._monoms)e.coefficient.reduce();return 0===this.length?(new o).zero():this};reorder=(e="x")=>(this._monoms.sort((function(t,i){return i.degree(e)-t.degree(e)})),this.reduce());degree=e=>{let t=0;for(const i of this._monoms)t=Math.max(i.degree(e),t);return t};letters=()=>{let e=new Set;for(let t of this._monoms)e=new Set([...e,...t.variables]);return[...e]};replaceBy=(e,t)=>{let i;const s=(new o).zero();for(const n of this.monoms)void 0===n.literal[e]||0===n.literal[e]?s.add(n.clone()):(i=+n.literal[e],delete n.literal[e],s.add(t.clone().pow(i).multiply(n)));return this._monoms=s.reduce().reorder().monoms,this};evaluate=e=>{const t=(new s).zero();return this._monoms.forEach((i=>{t.add(i.evaluate(e))})),t};derivative=e=>{let t=new o;for(let i of this._monoms)t.add(i.derivative(e));return t};primitive=e=>{let t=new o;for(let i of this._monoms)t.add(i.primitive(e));return t};integrate=(e,t,i)=>{const s=this.primitive(i);void 0===i&&(i="x");let n={},r={};return n[i]=e,r[i]=t,s.evaluate(r).subtract(s.evaluate(n))};factorize_OLD=e=>{this._factors=[];let t=this.clone(),i=0;t.monomByDegree().coefficient.numerator<0&&this._factors.push(new o("-1"));let n=t.commonMonom();if(!n.isOne()){let e=new o;e.monoms=[n],0===this._factors.length?this._factors.push(e):(this._factors=[],this._factors.push(e.opposed())),t=t.euclidian(e).quotient,i=e.degree()}if(t.degree()<=1)this._factors.push(t.clone());else{let n,r=new s,l=t.degree();e=void 0===e?20:e;for(let s=1;s<=e;s++)for(let h=-e;h<=e;h++){if(r.parse(-h,s),t.evaluate({x:r}))for(n=new o(`${s}x+${h}`);0===t.evaluate({x:r}).value;)this._factors.push(n.clone()),i++,t=t.euclidian(n).quotient;if(i>l)return this}if(t.degree()>1)return this._factors.push(t.clone()),this}return this};factorize=e=>{let t,i=[],s=this.clone().reorder(),n=s.commonMonom();n.isOne()||(t=new o,t.monoms=[n],i=[t.clone()],s=s.euclidian(t).quotient);let r=2*s.degree();for(;r>=0;){if(r--,s.monoms.length<2){s.isOne()||i.push(s.clone());break}{let e=s.monoms[0].dividers,t=s.monoms[s.monoms.length-1].dividers;for(let n of e)for(let e of t){let t,r=new o;r.monoms=[n.clone(),e.clone()],t=s.euclidian(r),t.reminder.isZero()?(s=t.quotient.clone(),i.push(r)):(r.monoms=[n.clone(),e.clone().opposed()],t=s.euclidian(r),t.reminder.isZero()&&(s=t.quotient.clone(),i.push(r)))}}}return this.factors=i,i};_factorize2ndDegree=e=>{let t,i,s,n,r,l,h,a,c;if(1===this.numberOfVars)return s=this.monomByDegree(2,e).coefficient,n=this.monomByDegree(1,e).coefficient,r=this.monomByDegree(0,e).coefficient,l=n.clone().pow(2).subtract(s.clone().multiply(r).multiply(4)),l.isZero()?(h=n.clone().opposed().divide(s.clone().multiply(2)),t=new o(e).subtract(h.display).multiply(h.denominator),i=new o(e).subtract(h.display).multiply(h.denominator),c=s.divide(h.denominator).divide(h.denominator),c.isOne()?[t,i]:[new o(c.display),t,i]):l.isPositive()&&l.isSquare()?(h=n.clone().opposed().add(l.clone().sqrt()).divide(s.clone().multiply(2)),a=n.clone().opposed().subtract(l.clone().sqrt()).divide(s.clone().multiply(2)),c=s.divide(h.denominator).divide(a.denominator),c.isOne()?[new o(e).subtract(h.display).multiply(h.denominator),new o(e).subtract(a.display).multiply(a.denominator)]:[new o(c.display),new o(e).subtract(h.display).multiply(h.denominator),new o(e).subtract(a.display).multiply(a.denominator)]):[this.clone()];if(s=this.monomByDegree(2,e),n=this.monomByDegree(1,e),r=this.monomByDegree(0,e),s.isLitteralSquare()&&r.isLitteralSquare()&&n.clone().pow(2).isSameAs(s.clone().multiply(r))){let e,t=new o("x",s.coefficient,n.coefficient,r.coefficient)._factorize2ndDegree("x"),i=[];if(t.length>=2){for(let n of t)0===n.degree()?i.push(n.clone()):(e=n.clone(),e.monoms[0].literal=s.literalSqrt,e.monoms[1].literal=r.literalSqrt,i.push(e.clone()));return i}}return[this.clone()]};_factorizeByGroups=()=>[];getZeroes=()=>{switch(this.degree()){case 0:return 0===this._monoms[0].coefficient.value?[!0]:[!1];case 1:if(1===this._monoms.length)return[(new s).zero()];{const e=this.clone().reduce().reorder();return[e.monoms[1].coefficient.opposed().divide(e.monoms[0].coefficient)]}default:0===this._factors.length&&this.factorize();let e=[],t=[];for(let i of this._factors)if(i.degree()>2);else if(2===i.degree()){let t=i.monomByDegree(2).coefficient,n=i.monomByDegree(1).coefficient,r=i.monomByDegree(0).coefficient,o=n.clone().pow(2).subtract(t.clone().multiply(r).multiply(4));if(o.value>0){let i=(-n.value+Math.sqrt(o.value))/(2*t.value),r=(-n.value-Math.sqrt(o.value))/(2*t.value);e.push(new s(i.toFixed(3)).reduce()),e.push(new s(r.toFixed(3)).reduce())}else 0===o.value||console.log("No zero for ",i.tex)}else for(let s of i.getZeroes())!1!==s&&!0!==s&&-1===t.indexOf(s.frac)&&(e.push(s),t.push(s.frac));return e}return[]};monomByDegree=(e,t)=>{if(void 0===e)return this.monomByDegree(this.degree(t),t);const i=this.clone().reduce();for(const s of i._monoms)if(s.degree(t)===e)return s.clone();return(new n).zero()};monomsByDegree=(e,t)=>{if(void 0===e)return this.monomsByDegree(this.degree(t));let i=[];const s=this.clone().reduce();for(const n of s._monoms)n.degree(t)===e&&i.push(n.clone());return i};monomByLetter=e=>{const t=this.clone().reduce();for(const i of t._monoms)if(i.hasLetter(e))return i.clone();return(new n).zero()};getDenominators=()=>{const e=[];for(const t of this._monoms)e.push(t.coefficient.denominator);return e};getNumerators=()=>{const e=[];for(const t of this._monoms)e.push(t.coefficient.numerator);return e};lcmDenominator=()=>e.lcm(...this.getDenominators());gcdDenominator=()=>e.gcd(...this.getDenominators());lcmNumerator=()=>e.lcm(...this.getNumerators());gcdNumerator=()=>e.gcd(...this.getNumerators());commonMonom=()=>{let e,t,i=(new n).one(),r=this.degree();e=this.gcdNumerator(),t=this.gcdDenominator(),i.coefficient=new s(e,t);for(let e of this.variables){i.setLetter(e,r);for(let t of this._monoms)if(i.setLetter(e,Math.min(t.degree(e),i.degree(e))),0===i.degree(e))break}return i};makeItComplicate=(e=1)=>(this._texString="",this.degree()<1||a.number(0,this.degree()-1),this);factorizePartial=t=>{if(this._texString="",this.length<=1)return this;let i,s,r,l,h,a;for(let c=0;c<this.length;c++){i=this._monoms[c].clone();for(let u=c+1;u<this.length;u++)if(s=this._monoms[u].clone(),h=e.gcd(i.coefficient.numerator,s.coefficient.numerator),1!==h)return r=n.lcm(i,s),a=1===i.coefficient.sign()?"+":"-",this._texString=`${!0===t?a:"+"===a?"":a}${r.tex}`,l=(new o).add(i.divide(r)).add(s.divide(r)),this._texString+=l.genDisplay("tex",!1,!0),this._texString+=this.clone().subtract(l.clone().multiply(r)).genDisplay("tex",!0,!1),this}return this._texString=this.genDisplay("tex",t),this};minify=()=>(this.multiply(this.lcmDenominator()).divide(this.gcdNumerator()).reduce(),this.reduce());canDivide=(e,t="x")=>{const i=e.degree(),s={};if(0===i)return!e.isZero;if(1===i){const i=e.getZeroes();return!0!==i[0]&&!1!==i[0]&&(s[t]=i[0],0===this.evaluate(s).value)}return i>1&&(console.log("Currently, only first degree polynom are supported"),!1)}}class l extends i{constructor(e){super(),this._defaultConfig={letters:"x",degree:2,fraction:!1,zero:!1,unit:!1,factorable:!1,allowNullMonom:!0,numberOfMonoms:0},this._config=this.mergeConfig(e,this._defaultConfig)}generate=()=>{let e,t=(new o).empty();for(let i=this._config.degree;i>=0;i--)e=new r({letters:this._config.letters,degree:i,fraction:this._config.fraction,zero:i!==this._config.degree&&this._config.allowNullMonom}).generate(),this._config.unit&&this._config.degree===i&&e.coefficient.one(),t.add(e);return this._config.numberOfMonoms>0&&this._config.numberOfMonoms<t.length&&(console.log(t.monoms.length),t.monoms=a.array(t.monoms,this._config.numberOfMonoms)),t};factorable=()=>new o}class h{static randomBool(e=.5){return Math.random()<e}static randomInt(e,t){return void 0===t?this.randomInt(0,e):Math.floor(Math.random()*(t-e+1)+e)}static randomIntSym(e,t){return!1===t?this.randomBool()?this.randomInt(1,e):-this.randomInt(1,e):this.randomInt(-e,e)}static randomArray(e,t){return void 0===t&&(t=1),e.length<=0?Object.values(e):h.shuffleArray(e).slice(0,t)}static randomItem(e){return 0===e.length?"":this.randomArray(e,1)[0]}static shuffleArray(e){let t=Object.values(e);for(let e=t.length-1;e>0;e--){const i=Math.floor(Math.random()*(e+1)),s=t[e];t[e]=t[i],t[i]=s}return t}}var a,c;!function(e){e.polynom=function(e){return new l(e).generate()},e.monom=function(e){return new r(e).generate()},e.number=function(e,t){return h.randomInt(e,t)},e.numberSym=function(e,t){return h.randomIntSym(e,t)},e.bool=function(e){return h.randomBool(e)},e.array=function(e,t){return h.randomArray(e,t)},e.item=function(e){return h.randomItem(e)},e.shuffle=function(e){h.shuffleArray(e)}}(a||(a={}));class u{_radical;_nth;_coefficient;_isValid;constructor(){this._radical=1,this._coefficient=1,this._nth=2,this._isValid=!0}get radical(){return this._radical}set radical(e){this._radical=e}get nth(){return this._nth}set nth(e){Number.isSafeInteger(e)&&e>=2?this._nth=e:(console.log("Error setting the nth root"),this._nth=2)}get coefficient(){return this._coefficient}set coefficient(e){this._coefficient=e}get tex(){let e;return e=1===this._coefficient?"":-1===this._coefficient?"-":this._coefficient.toString(),1===this._radical?`${this._coefficient}`:2===this._nth?`${e}\\sqrt{${this._radical}}`:`${e}\\sqrt[${this._nth}]{${this._radical}}`}get value(){return this._coefficient*Math.pow(this._radical,1/this._nth)}parse=(e,t,i)=>(this._coefficient=void 0===i?1:i,this._nth=void 0===t?2:t,this._radical=void 0===e?1:e,this._nth%2==0&&this._radical<0&&(this._isValid=!1),this);reduce=()=>{let e=Math.floor(Math.pow(this._radical,1/this._nth));for(;e>1;)this._radical%Math.pow(e,this._nth)!=0?e--:(this._coefficient*=e,this._radical=this._radical/Math.pow(e,this._nth),e=Math.floor(Math.pow(this._radical,1/this._nth)));return this};multiply=e=>(this._radical*=e.radical,this.reduce());hasRadical=()=>!(1===this._radical||0===this._radical||!1===this._isValid)}class m{_left;_right;_sign;_polynom;_solutions;_varnothing="\\varnothing";_real="\\mathbb{R}";constructor(...e){if(this._left=(new o).zero(),this._right=(new o).zero(),this._sign="=",1===e.length){if(!0===e[0].isEquation)return e[0].clone();this.parse(e[0])}else{if(2!==e.length)return this;this.left=e[0].isPolynom?e[0].clone():new o(e[0]),this.right=e[1].isPolynom?e[1].clone():new o(e[1])}return this}get isEquation(){return!0}get solutions(){return this._solutions}get solution(){return 1!==this._solutions.length||this._solutions[0]!==this._real&&this._solutions[0]!==this._varnothing&&!this._solutions[0].includes("\\left")?`S = \\left{ ${this._solutions.join(";")} \\right}`:`S = ${this._solutions[0]}`}get isReal(){return void 0===this._solutions&&this.solve(),this._solutions[0]===this._real}get isVarnothing(){return void 0===this._solutions&&this.solve(),this._solutions[0]===this._varnothing}get signAsTex(){return">="===this._sign||"=>"===this._sign||"geq"===this._sign?"\\geq":"<="===this._sign||"=<"===this._sign||"leq"===this._sign?"\\leq":this._sign}get tex(){return`${this._left.tex}${this.signAsTex}${this._right.tex}`}get raw(){return`${this._left.raw}${this.signAsTex}${this._right.raw}`}get variables(){return[...new Set(this._right.variables.concat(this._left.variables))]}get numberOfVars(){return this.variables.length}get left(){return this._left}set left(e){this._left=e}get right(){return this._right}set right(e){this._right=e}get sign(){return this._sign}set sign(e){this._sign=this._formatSign(e)}parse=e=>{let t,i;if(i=this._findSign(e),!1!==i)return t=e.split(i),this.create(new o(t[0]),new o(t[1]),this._formatSign(i));console.log("The equation is not valid (no sign found)")};_findSign=e=>e.includes("geq")?e.includes("\\geq")?"\\geq":"geq":e.includes("leq")?e.includes("\\leq")?"\\leq":"leq":e.includes(">=")?">=":e.includes("=>")?"=>":e.includes(">")?">":e.includes("<=")?"<=":e.includes("=<")?"=<":e.includes("<")?"<":e.includes("=")?"=":(console.log("Equation: parse string : sign not found"),!1);_formatSign=e=>void 0===e?"=":e.includes("geq")||e.includes(">=")||e.includes("=>")?">=":e.includes(">")?">":e.includes("leq")||e.includes("<=")||e.includes("=<")?"<=":e.includes("<")?"<":"=";_reverseSign=()=>"="===this._sign?this:this._sign.includes("<")?(this._sign.replace("<",">"),this):this._sign.includes(">")?(this._sign.replace(">","<"),this):this;create=(e,t,i)=>(this._left=e,this._right=t,this._sign=this._formatSign(i),this);clone=()=>(new m).create(this._left.clone(),this._right.clone(),this._sign+"");_randomizeDefaults={degree:2};get randomizeDefaults(){return this._randomizeDefaults}set randomizeDefaults(e){this._randomizeDefaults=e}randomize=(e,t)=>(new m).create(new o,new o,t);moveLeft=()=>(this._left=this._left.clone().subtract(this._right),this._right.zero(),this);reorder=e=>{if(this._left.subtract(this._right),this._right.zero(),e)return this.moveLeft();let t;for(let e of this._left.monoms)0===e.degree()&&(t=e.clone(),this._left.subtract(t),this._right.subtract(t));return this._left.reorder(),this._right.reorder(),this};simplify=()=>(this.multiply(e.lcm(...this._left.getDenominators(),...this._right.getDenominators())),this.divide(e.gcd(...this._left.getNumerators(),...this._right.getNumerators())),this);isolate=e=>{if(1!==this.degree(e))return!1;if(this.isMultiVariable())return!1;let t,i;this._left.subtract(this._right),this._right.zero();for(let i of this._left.monoms)i.hasLetter(e)||(t=i.clone(),this._left.add(t.clone().opposed()),this._right.add(t.clone().opposed()));return 1===this._left.length&&(i=this._left.monoms[0].coefficient.clone(),this._left.divide(i),this._right.divide(i),this)};replaceBy=(e,t)=>(this._left.replaceBy(e,t),this._right.replaceBy(e,t),this);multiply=e=>{let t=new s(e);return this._left.multiply(t),this._right.multiply(t),"="!==this._sign&&-1===t.sign()&&this._reverseSign(),this};divide=e=>{let t=new s(e);return t.isZero()?this:this.multiply(t.invert())};degree=e=>Math.max(this._left.degree(e),this._right.degree(e));isMultiVariable=()=>this._left.isMultiVariable||this._right.isMultiVariable;letters=()=>[...new Set([...this._left.letters(),...this._right.letters()])];solve=e=>{switch(this._solutions=[],this._polynom=this._left.clone().subtract(this._right),this._polynom.degree(e)){case 0:case 1:this._solveDegree1(e);break;case 2:this._solveDegree2(e);break;default:this._solveDegree3plus(e)}return this};isGreater=()=>-1!==this._sign.indexOf(">")||-1!==this._sign.indexOf("geq");isStrictEqual=()=>"="===this._sign;isAlsoEqual=()=>-1!==this._sign.indexOf("=")||-1!==this._sign.indexOf("geq")||-1!==this._sign.indexOf("leq")||void 0;_solveDegree1=e=>{const t=this._polynom.monomByDegree(1,e).coefficient,i=this._polynom.monomByDegree(0,e).coefficient,s=i.clone().opposed().divide(t).display;let n;return this.isStrictEqual()?0===t.value?0===i.value?this._solutions=[this._real]:this._solutions=[this._varnothing]:this._solutions=[s]:(n=0===t.value?0===i.value&&this.isAlsoEqual()?"\\mathbb{R}":i.value>0?this.isGreater()?this._real:this._varnothing:this.isGreater()?this._varnothing:this._real:this.isGreater()&&1===t.sign()||!this.isGreater()&&-1===t.sign()?`\\left${this.isAlsoEqual()?"\\[":"\\]"}${s};+\\infty\\right\\[`:`\\left\\]-\\infty;${s} \\right\\${this.isAlsoEqual()?"\\]":"\\["}`,this._solutions=[n]),this._solutions};_solveDegree2=t=>{let i,n,r,o,l,h,a=this._polynom.monomByDegree(2,t).coefficient,c=this._polynom.monomByDegree(1,t).coefficient,m=this._polynom.monomByDegree(0,t).coefficient,f=e.lcm(a.denominator,c.denominator,m.denominator),_=a.multiply(f).value,d=c.multiply(f).value;if(i=d*d-4*_*m.multiply(f).value,i>0)if(r=(-d-Math.sqrt(i))/(2*_),o=(-d+Math.sqrt(i))/(2*_),i>1e5)this._solutions=[((-d-Math.sqrt(i))/(2*_)).toFixed(5),((-d+Math.sqrt(i))/(2*_)).toFixed(5)];else if(n=(new u).parse(i).reduce(),n.hasRadical()){let t=e.gcd(d,2*_,n.coefficient);n.coefficient=n.coefficient/t,this._solutions=0!==d?2*_/t==1?[`${-d/t} - ${n.tex}`,`${-d/t} + ${n.tex}`]:[`\\dfrac{${-d/t} - ${n.tex} }{ ${2*_/t} }`,`\\dfrac{${-d/t} + ${n.tex} }{ ${2*_/t} }`]:2*_/t==1?[`- ${n.tex}`,`${n.tex}`]:[`\\dfrac{- ${n.tex} }{ ${2*_/t} }`,`\\dfrac{${n.tex} }{ ${2*_/t} }`]}else this._solutions=[new s(-d-n.coefficient,2*_).reduce().dfrac,new s(-d+n.coefficient,2*_).reduce().dfrac];else this._solutions=0===i?[new s(-d,2*_).reduce().dfrac]:[this._varnothing];return this.isStrictEqual()||(2===this._solutions.length?(l=r<o?this._solutions[0]:this._solutions[1],h=r<o?this._solutions[1]:this._solutions[0],this.isGreater()&&1===a.sign()||!this.isGreater()&&-1===a.sign()?this._solutions=[`\\left]-\\infty ; ${l}\\right${this.isAlsoEqual()?"]":"["} \\cup \\left${this.isAlsoEqual()?"[":"]"}${h};+\\infty\\right[`]:this._solutions=[`\\left${this.isAlsoEqual()?"[":"]"}${l} ; ${h}\\right${this.isAlsoEqual()?"]":"["}`]):1===this._solutions.length&&this._solutions[0]!==this._varnothing?this.isAlsoEqual()?(this.isGreater()&&1===a.sign()||!this.isGreater()&&-1===a.sign())&&(this._solutions=[this._real]):this.isGreater()&&1===a.sign()||!this.isGreater()&&-1===a.sign()?this._solutions=[`\\left]-\\infty ; ${this._solutions[0]}\\right[ \\cup \\left]${this._solutions[0]};+\\infty\\right[`]:this._solutions=[this._varnothing]:this.isGreater()?this._solutions=[1===a.sign()?this._real:this._varnothing]:this._solutions=[-1===a.sign()?this._real:this._varnothing]),this._solutions};_solveDegree3plus=e=>(this._solutions=[e],this._solutions)}class f{_solutions;_resolutionSteps;_equations;_letters;constructor(...e){return this._equations=[],this._letters="xy".split(""),void 0!==e&&e.length>0&&this.parse(...e),this}get isLinerarSystem(){return!0}get equations(){return this._equations}set equations(e){this._equations=e}get letters(){return this._letters.join("")}set letters(e){this._letters=e.split("")}get isSolvable(){return this.variables.length===this._equations.length}get variables(){let e=[];for(let t of this._equations)e=e.concat(t.variables);return[...new Set(e)].sort()}get tex(){let e,t,i=this.clone().reorder(),s=i.variables,n=[];for(let r of i.equations){e=[];for(let i of s)t=r.left.monomByLetter(i),0===e.length?e.push(t.isZero()?"":t.tex):e.push(t.isZero()?"":(1===t.coefficient.sign()?"+":"")+t.tex);e.push("="),e.push(r.right.tex),n.push(e.join("&"))}return`\\left\\{\\begin{array}{${"r".repeat(s.length)}cl}${n.join("\\\\ ")}\\end{array}\\right.`}get texSolution(){let e=[];void 0===this._solutions&&this.solve();for(let t in this._solutions){if(this._solutions[t].isReal)return void console.log(`Undetermined (letter ${t})`);if(this._solutions[t].isVarnothing)return void console.log(`Undefined (letter ${t})`);e.push(this._solutions[t].value.dfrac)}return`(${e.join(";")})`}parse=(...e)=>(this._equations=e.map((e=>new m(e))),this._findLetters(),this);setCoefficient=(...e)=>{this._equations=[];let t=0;for(;t<e.length-this._letters.length;){let i=(new o).parse(this._letters.join(""),...e.slice(t,t+this._letters.length)),s=new o(e[t+this._letters.length].toString()),n=(new m).create(i,s);this._equations.push(n.clone()),t=t+this._letters.length+1}return this};clone=()=>(new f).parse(...this._equations.map((e=>e.clone())));setLetters=(...e)=>(this._letters=e,this);_findLetters=()=>{let e=new Set;for(let t of this._equations)e=new Set([...e,...t.variables]);return this._letters=[...e],this};generate=(...e)=>{let t=[];for(let i of e)"number"==typeof i?t.push(new s(i.toString())):t.push(i.clone());this._equations=[];for(let i=0;i<e.length;i++)this._equations.push(this._generateOneEquation(...t));return this};_generateOneEquation=(...e)=>{let t,i=[],n=(new s).zero(),r=["x","y","z","t","u","v","w","a","b","c","d","e","f","g","h","i","j","k","l"],o="";for(let t=0;t<e.length;t++)i.push(a.numberSym(5)),n.add(e[t].clone().multiply(i[t])),o+=`${i[t]<0?i[t]:"+"+i[t]}${r[t]}`;return t=new m(`${o}=${n.display}`),1!=t.right.monoms[0].coefficient.denominator&&t.multiply(new s(t.right.monoms[0].coefficient.denominator,1)),this._checkIfLinerCombination(t)?t:this._generateOneEquation(...e)};_linearReduction(e,t,i){let s=e.left.monomByDegree(1,i).coefficient.clone(),n=t.left.monomByDegree(1,i).coefficient.clone().opposed();return this.mergeEquations(e,t,n,s)}mergeEquations=(e,t,i,n)=>{let r=e.clone().multiply(new s(i)),o=t.clone().multiply(new s(n));return r.left.add(o.left),r.right.add(o.right),r};reorder=()=>{for(let e of this._equations)e.reorder();return this};solve=()=>{this._solutions={},this._resolutionSteps=[],this.reorder();let e=this.variables.sort();for(let t of e)this._solutions[t]=this._solveOneLetter(t,e);return this};_checkIfLinerCombination=e=>!0;_solveOneLetter(e,t){let i=this.clone().equations,n=[];for(let s of t)if(s!==e){for(let e=0;e<i.length-1;e++)n.push(this._linearReduction(i[e],i[e+1],s));this._resolutionSteps.push((new f).parse(...n)),i=this._resolutionSteps[this._resolutionSteps.length-1].clone().equations,n=[]}let r=this._resolutionSteps[this._resolutionSteps.length-1].equations[0];return r.solve(),{value:new s(r.solutions[0]),isReal:r.isReal,isVarnothing:r.isVarnothing}}log=()=>{let e="";for(let t of this._equations)console.log(t.tex),e+=`${t.tex}\\n}`;return e}}!function(e){e.Polynom=class extends o{},e.Monom=class extends n{}}(c||(c={}));class _{_x;_y;constructor(...e){this._x=(new s).zero(),this._y=(new s).zero(),void 0!==e&&this.parse(...e)}get isVector(){return!0}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}get normSquare(){return this._x.clone().pow(2).add(this._y.clone().pow(2))}get norm(){return Math.sqrt(this.normSquare.value)}get tex(){return`\\begin{pmatrix}${this._x.tex} \\\\ ${this._y.tex} \\end{pmatrix}`}parse=(...e)=>{if(this.zero(),0===e.length)return this;if(1===e.length)return e[0].isVector?e[0].clone():this._parseString(e[0]);if(e.length>=2){if(e[0].isPoint&&e[1].isPoint)return this._x=e[1].x.clone().subtract(e[0].x),this._y=e[1].y.clone().subtract(e[0].y),this;!e[0].isFraction&&isNaN(e[0])||(this._x=new s(e[0])),!e[1].isFraction&&isNaN(e[1])||(this._y=new s(e[1]))}return this};clone=()=>{let e=new _;return null!==this._x&&(e.x=this._x.clone()),null!==this._y&&(e.y=this._y.clone()),e};reset=()=>(this._x=null,this._y=null,this);zero=()=>(this.reset(),this._x=new s(null),this._y=new s(null),this);one=()=>(this._x=new s,this._y=new s,this);_parseString=e=>{let t=e.split(/[,;\s]/g);return this.x=new s(t[0]||null),this.y=new s(t[1]||null),this};opposed=()=>(this._x.opposed(),this._y.opposed(),this);add=e=>(this._x.add(e.x),this._y.add(e.y),this);subtract=e=>this.add(e.clone().opposed());scalarProductWithVector=e=>this._x.clone().multiply(e.x).add(this._y.clone().multiply(e.y));static scalarProduct=(e,t)=>e.x.value*t.x.value+e.y.value*t.y.value;normal=()=>{let e=this.x.clone().opposed(),t=this.y.clone();return this._x=t,this._y=e,this};isNormalTo=e=>this.scalarProductWithVector(e).isZero();multiplyByScalar=e=>{let t=new s(e);return this._x.multiply(t),this._y.multiply(t),this};divideByScalar=e=>this.multiplyByScalar(new s(e).invert());simplify=()=>this.multiplyByScalar(e.lcm(this._x.denominator,this._y.denominator)).divideByScalar(e.gcd(this._x.numerator,this._y.numerator));angleWith=(e,t,i)=>{let s=this.scalarProductWithVector(e).value,n=i?1:180/Math.PI;return t&&(s=Math.abs(s)),n*Math.acos(s/(this.norm*e.norm))}}class d{_x;_y;_exist;constructor(...e){return this._x=(new s).zero(),this._y=(new s).zero(),void 0!==e&&this.parse(...e),this}get isPoint(){return!0}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}get tex(){let e=[];return e.push(this._x.tex),e.push(this._y.tex),`\\left(${e.join(";")}\\right)`}parse=(...e)=>{if(this.zero(),0===e.length)return this;if(1===e.length){if(e[0]instanceof d)return this._x=e[0].x.clone(),this._y=e[0].y.clone(),this;if("string"==typeof e[0]){let t=e[0].split(",");if(2===t.length)return this._x=new s(t[0]).reduce(),this._y=new s(t[1]).reduce(),this}if(void 0===e[0].x||void 0===e[0].y)return this.zero();this._x=new s(e[0].x).reduce(),this._y=new s(e[0].y).reduce()}return 2===e.length&&(this._x=new s(e[0]).reduce(),this._y=new s(e[1]).reduce()),this};clone=()=>(this._x=this._x.clone(),this._y=this._y.clone(),this);zero=()=>(this._x=new s(null),this._y=new s(null),this);origin=()=>(this.zero(),this);middleOf=(e,t)=>(this._x=e.x.clone().add(t.x).divide(2),this._y=e.y.clone().add(t.y).divide(2),this);texValues=e=>{let t=[];return t.push(this._x.value.toFixed(void 0===e?2:e)),t.push(this._y.value.toFixed(void 0===e?2:e)),`\\left(${t.join(";")}\\right)`};static pmatrix=(e,t,i)=>void 0===i?`\\begin{pmatrix} ${e.tex?e.tex:e} \\\\ ${t.tex?t.tex:t} \\end{pmatrix}`:`\\begin{pmatrix} ${e.tex?e.tex:e} \\\\ ${t.tex?t.tex:t} \\\\ ${i.tex?i.tex:i} \\end{pmatrix}`}class g{_a;_b;_c;_OA;_d;_n;_exists;constructor(...e){return this._exists=!1,void 0!==e&&this.parse(...e),this}get isLine(){return!0}get exists(){return this._exists}get equation(){return new m((new o).parse("xy",this._a,this._b,this._c),new o("0")).simplify()}get tex(){let e=this.equation;return this._a.isNegative()&&e.multiply(-1),{canonical:e.tex,mxh:this.slope.isInfinity()?"x="+this.OA.x.tex:"y="+(new o).parse("x",this.slope,this.height).tex,parametric:`${d.pmatrix("x","y")} = ${d.pmatrix(this._OA.x,this._OA.y)} + k\\cdot ${d.pmatrix(this._d.x,this._d.y)}`}}get a(){return this._a}set a(e){this._a=e}get b(){return this._b}set b(e){this._b=e}get c(){return this._c}set c(e){this._c=e}get OA(){return this._OA}set OA(e){this._OA=e}get d(){return this._d}get n(){return this._n}get normal(){return new _(this._a,this._b)}set d(e){this._d=e}get slope(){return this._a.clone().opposed().divide(this._b)}get height(){return this._c.clone().opposed().divide(this._b)}parse=(...e)=>{if(this._exists=!1,3===e.length)return this.parseByCoefficient(e[0],e[1],e[2]);if(2===e.length){if(e[0].isPoint&&e[1].isVector)return this.parseByPointAndVector(e[0],e[1]);if(e[0].isPoint&&e[1].isPoint)return this.parseByPointAndVector(e[0],new _(e[0],e[1]))}else if(1===e.length){if(e[0].isLine)return e[0].clone();let t=new m(e[0]);if(t.isEquation){t.reorder(!0);let e=new Set(t.letters());if(!e.has("x")&&!e.has("y"))return;for(let t of["x","y"])e.has(t)&&e.delete(t);return e.size>0?(console.log("Extra variable in the equation."),this):this.parseByCoefficient(t.left.monomByLetter("x").coefficient,t.left.monomByLetter("y").coefficient,t.left.monomByDegree(0).coefficient)}}return console.log("Someting wrong happend while creating the line"),this};parseByCoefficient=(e,t,i)=>(this._a=new s(e),this._b=new s(t),this._c=new s(i),this._d=new _(this._b.clone(),this._a.clone().opposed()),this._OA=new d((new s).zero(),this._c.clone()),this._n=this._d.clone().normal(),this._exists=!0,this);parseByPointAndVector=(e,t)=>(this.parseByCoefficient(t.y,t.x.clone().opposed(),e.x.clone().multiply(t.y).subtract(e.y.clone().multiply(t.x)).opposed()),this._OA=e.clone(),this._d=t.clone(),this._n=this._d.clone().normal(),this._exists=!0,this);clone=()=>(this._a=this._a.clone(),this._b=this._b.clone(),this._c=this._c.clone(),this._d=this._d.clone(),this._OA=this._OA.clone(),this._n=this._n.clone(),this);isParellelTo=e=>this.slope.isEqual(e.slope)&&this.height.isDifferent(e.height);isSameAs=e=>this.slope.isEqual(e.slope)&&this.height.isEqual(e.height);simplifyDirection=()=>{let t=e.lcm(this._d.x.denominator,this._d.y.denominator),i=e.gcd(this._d.x.numerator,this._d.y.numerator);return this._d.x.multiply(t).divide(i),this._d.y.multiply(t).divide(i),this};intersection=e=>{let t=new d,i=!1,s=!1;return this._b.isZero()||e.b.isZero(),this.isParellelTo(e)?(t.x=null,t.y=null,i=!0):this.isSameAs(e)?(t.x=null,t.y=null,s=!0):(t.x=this._b.clone().multiply(e.c).subtract(this._c.clone().multiply(e.b)).divide(this._a.clone().multiply(e.b).subtract(this._b.clone().multiply(e.a))),t.y=this._a.clone().multiply(e.c).subtract(this._c.clone().multiply(e.a)).divide(this._b.clone().multiply(e.a).subtract(this._a.clone().multiply(e.b)))),{point:t,hasIntersection:!(i||s),isParallel:i,isSame:s}};distanceTo(e){let t=e.x.clone().multiply(this._a).add(e.y.clone().multiply(this._b)).add(this._c).abs(),i=this.normal.normSquare;if(i.isZero())return{value:NaN,tex:"Not a line",fraction:(new s).infinite()};let n=t.value/Math.sqrt(i.value),r=t.clone().divide(i.clone().sqrt());return i.isSquare()?{value:n,tex:r.tex,fraction:r}:{value:n,tex:`\\frac{${t.tex}}{\\sqrt{${i.tex}}}`,fraction:r}}hitSegment(e,t){let i=this.intersection(new g(e,t));return!!i.hasIntersection&&i.point.x.value>=Math.min(e.x.value,t.x.value)&&i.point.x.value<=Math.max(e.x.value,t.x.value)&&i.point.y.value>=Math.min(e.y.value,t.y.value)&&i.point.y.value<=Math.max(e.y.value,t.y.value)}canonicalAsFloatCoefficient(e){void 0===e&&(e=2),this._a.value,this._b.value,this._c.value;let t="";return this._a.isZero()||(t=this._a.isOne()?"x":this._a.clone().opposed().isOne()?"-x":this._a.value.toFixed(e)+"x"),this._b.isZero()||(this._b.isPositive()&&(t+="+"),t+=this._b.value.toFixed(e)+"y"),this._c.isZero()||(this._c.isPositive()&&(t+="+"),t+=this._c.value.toFixed(e)),t+"=0"}}window.Pi={ShutingYard:t,Numeric:e,Fraction:s,Root:u,Monom:n,Polynom:o,Equation:m,LinearSystem:f,Rational:class{_rawString;_numerator;_denominator;constructor(e,t){this._numerator=e?e.clone():new o,this._denominator=t?t.clone():new o}clone=()=>(this._numerator=this._numerator.clone(),this._denominator=this._denominator.clone(),this);get tex(){return`\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`}get texFactors(){return this._numerator.factorize(),this._denominator.factorize(),`\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`}get numerator(){return this._numerator}get denominator(){return this._denominator}domain=()=>{let e=this._denominator.getZeroes();return 0===e.length||!1===e[0]?"\\mathbb{R}":!0===e[0]?"\\varnothing":"\\mathbb{R}\\setminus\\left{"+e.map((e=>"boolean"==typeof e?"":e.frac)).join(";")+"\\right}"};amplify=e=>(this._numerator.multiply(e),this._denominator.multiply(e),this);simplify=e=>{let t=this._numerator.euclidian(e);if(!t.reminder.isZero())return this;let i=this._denominator.euclidian(e);return i.reminder.isZero()?(this._numerator=t.quotient,this._denominator=i.quotient,this):this};reduce=()=>{console.log(this._numerator.tex),this._numerator.factorize(),console.log(this._numerator.factors.map((e=>e.tex)));for(let e of this._numerator.factors)this.simplify(e);return this};opposed=()=>(this._numerator.opposed(),this);add=e=>{let t=this._denominator.clone();return this.amplify(e._denominator),this._numerator.add(e._numerator.clone().multiply(t)),this};subtract=e=>this.add(e.clone().opposed());limits=(e,t)=>{if(e!==1/0&&e!==-1/0)return this._numerator.evaluate({letter:e}).divide(this._denominator.evaluate({letter:e}));{let i=this._numerator.monomByDegree(this._numerator.degree(t),t),s=this._denominator.monomByDegree(this._denominator.degree(t),t);if(i.divide(s),i.degree(t)>0)return i.coefficient.sign()*Math.pow(e>0?1:-1,i.degree(t)%2)==1?1/0:-1/0;if(0===i.degree(t))return i.coefficient;if(i.degree(t)>0)return i.coefficient.sign()*Math.pow(-1,i.degree(t)%2)==1?0:-0}}},Logicalset:class{_rawString;_rpn;constructor(e){return this._rawString=e,this.parse(e),this}get isLogicalset(){return!0}parse=e=>(this._rpn=new t("set").parse(e).rpn,this);evaluate(e,t){let i,s=[];if(void 0===t){i=new Set;for(let t in e)i=new Set([...i,...e[t]])}else i=new Set(t);for(let t of this._rpn)if("variable"===t.tokenType)void 0===e[t.token]?s.push(new Set):s.push(new Set(e[t.token]));else switch(t.token){case"&":if(s.length>=2){let e=s.pop(),t=s.pop();s.push(new Set([...t].filter((t=>e.has(t)))))}break;case"|":if(s.length>=2){let e=s.pop(),t=s.pop();s.push(new Set([...t,...e]))}break;case"-":if(s.length>=2){let e=s.pop(),t=s.pop();s.push(new Set([...t].filter((t=>!e.has(t)))))}break;case"!":if(s.length>=1){let e=s.pop();s.push(new Set([...i].filter((t=>!e.has(t)))))}}return[...s[0]].sort()}vennAB(){return this.evaluate({A:["A","AB"],B:["B","AB"]},["A","B","AB","E"])}vennABC(){return this.evaluate({A:["A","AB","AC","ABC"],B:["B","AB","BC","ABC"],C:["C","AC","BC","ABC"]},["A","B","C","AB","AC","BC","E"])}get rpn(){return this._rpn}get tex(){let e=[];for(let t of this._rpn)if("variable"===t.tokenType)e.push(t);else switch(t.token){case"&":if(e.length>=2){let t=e.pop(),i=e.pop();"mix"===i.tokenType&&(i.token=`( ${i.token} )`),"mix"===t.tokenType&&(t.token=`( ${t.token} )`),e.push({token:`${i.token} \\cap ${t.token}`,tokenType:"mix"})}break;case"|":if(e.length>=2){let t=e.pop(),i=e.pop();"mix"===i.tokenType&&(i.token=`( ${i.token} )`),"mix"===t.tokenType&&(t.token=`( ${t.token} )`),e.push({token:`${i.token} \\cup ${t.token}`,tokenType:"mix"})}break;case"-":if(e.length>=2){let t=e.pop(),i=e.pop();"mix"===i.tokenType&&(i.token=`( ${i.token} )`),"mix"===t.tokenType&&(t.token=`( ${t.token} )`),e.push({token:`${i.token} \\setminus ${t.token}`,tokenType:"mix"})}break;case"!":if(e.length>=1){let t=e.pop();e.push({token:`\\overline{ ${t.token} }`,tokenType:"variable"})}}return e[0].token}},Random:a,Geometry:{Vector:_,Point:d,Line:g,Triangle:class{_A;_B;_C;_lines;_middles;_remarquables;constructor(...e){return e.length>0&&this.parse(...e),this}get isTriangle(){return!0}get A(){return this._A}get B(){return this._B}get C(){return this._C}get AB(){return this.getSegment("A","B")}get BA(){return this.getSegment("B","A")}get BC(){return this.getSegment("B","C")}get CB(){return this.getSegment("C","B")}get AC(){return this.getSegment("A","C")}get CA(){return this.getSegment("C","A")}get isRectangle(){return!!this.AB.isNormalTo(this.BC)||!!this.AB.isNormalTo(this.AC)||!!this.BC.isNormalTo(this.AC)}get isEquilateral(){return this.AB.normSquare.isEqual(this.BC.normSquare)&&this.AB.normSquare.isEqual(this.AC.normSquare)}get isIsocele(){return this.AB.normSquare.isEqual(this.BC.normSquare)||this.AB.normSquare.isEqual(this.AC.normSquare)||this.BC.normSquare.isEqual(this.AC.normSquare)}get lines(){return this._lines}get remarquables(){return this._remarquables}parse=(...e)=>{if(6===e.length){let t=e.map((e=>new s(e)));return this.parse(new d(t[0],t[1]),new d(t[2],t[3]),new d(t[4],t[5]))}if(3===e.length){if(3===e.filter((e=>"string"==typeof e)).length)return this.parse(...e.map((e=>new g(e))));if(3===e.filter((e=>!0===e.isLine)).length){this._lines={AB:e[0],BC:e[1],AC:e[2]};let t=e[0].intersection(e[1]);if(!t.hasIntersection)return this;if(this._B=t.point.clone(),t=e[1].intersection(e[2]),!t.hasIntersection)return this;if(this._C=t.point.clone(),t=e[2].intersection(e[0]),!t.hasIntersection)return this;this._A=t.point.clone()}else{if(e.filter((e=>!0===e.isPoint)).length<3)return this.parse(new d(e[0]),new d(e[1]),new d(e[2]));this._A=e[0].clone(),this._B=e[1].clone(),this._C=e[2].clone(),this._lines={AB:new g(this._A,this._B),BC:new g(this._B,this._C),AC:new g(this._A,this._C)}}}else if(1===e.length&&!0===e[0].isTriangle)return e[0].clone();return this._updateTriangle(),this};clone=()=>(this._A=this._A.clone(),this._B=this._B.clone(),this._C=this._C.clone(),this._lines={AB:this._lines.AB.clone(),BC:this._lines.BC.clone(),AC:this._lines.AC.clone()},this._updateTriangle(),this);_updateTriangle=()=>{this._middles={AB:(new d).middleOf(this._A,this._B),AC:(new d).middleOf(this._A,this._C),BC:(new d).middleOf(this._B,this._C)},this._remarquables=this._calculateRemarquableLines()};getPointByName=e=>{switch(e.toUpperCase()){case"A":return this._A;case"B":return this._B;case"C":return this._C}return this._A};getSegment=(e,t)=>new _(this.getPointByName(e),this.getPointByName(t));_calculateRemarquableLines=()=>{let e={medians:{A:new g(this._A,this._middles.BC),B:new g(this._B,this._middles.AC),C:new g(this._C,this._middles.AB),intersection:null},mediators:{AB:new g(this._middles.AB,new _(this._A,this._B).normal()),AC:new g(this._middles.AC,new _(this._A,this._C).normal()),BC:new g(this._middles.BC,new _(this._B,this._C).normal()),intersection:null},heights:{A:new g(this._A,new _(this._B,this._C).normal()),B:new g(this._B,new _(this._A,this._C).normal()),C:new g(this._C,new _(this._A,this._B).normal()),intersection:null},bisectors:{A:this._calculateBisectors("A"),B:this._calculateBisectors("B"),C:this._calculateBisectors("C"),intersection:null}};return e.medians.intersection=e.medians.A.intersection(e.medians.B).point,e.mediators.intersection=e.mediators.AB.intersection(e.mediators.BC).point,e.heights.intersection=e.heights.A.intersection(e.heights.B).point,e.bisectors.intersection=e.bisectors.A.intersection(e.bisectors.B).point,e};_calculateBisectors=e=>{let t,i,s=this.lines;"A"===e?(t=s.AB,i=s.AC):"B"===e?(t=s.AB,i=s.BC):"C"===e&&(t=s.BC,i=s.AC);let n=new g(new m(t.equation.left.clone().multiply(i.n.simplify().norm),i.equation.left.clone().multiply(t.n.simplify().norm)).reorder(!0).simplify()),r=new g(new m(t.equation.left.clone().multiply(i.n.simplify().norm),i.equation.left.clone().multiply(t.n.simplify().norm).opposed()).reorder(!0).simplify());return"A"===e?n.hitSegment(this.B,this.C)?n:r:"B"===e?n.hitSegment(this.A,this.C)?n:r:"C"===e?n.hitSegment(this.B,this.A)?n:r:n}},Circle:class{_center;_radius;_exists;constructor(...e){this._exists=!1,void 0!==e&&this.parse(...e)}parse(...e){2===e.length&&(this._center=new d(e[0]),this._radius=new s(e[1]))}get tex(){let e,t;return e=this._center.x.isZero()?"x^2":`\\left(x-${this._center.x.tex}\\right)^2`,t=this._center.y.isZero()?"y^2":`\\left(y-${this._center.y.tex}\\right)^2`,`${e}+${t}=${this._radius.pow(2).tex}`}get developed(){return new m(new o(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`),new o(`${this._radius.pow(2).display}`)).moveLeft().tex}}}}})();
|
|
1
|
+
(()=>{"use strict";class e{static round(e,t=2){return Number(Math.round(Number(e+"e"+t))+"e-"+t)}static prime(e){let t=[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,7927,7933,7937,7949,7951,7963,7993,8009,8011,8017,8039,8053,8059,8069,8081,8087,8089,8093,8101,8111,8117,8123,8147,8161,8167,8171,8179,8191,8209,8219,8221,8231,8233,8237,8243,8263,8269,8273,8287,8291,8293,8297,8311,8317,8329,8353,8363,8369,8377,8387,8389,8419,8423,8429,8431,8443,8447,8461,8467,8501,8513,8521,8527,8537,8539,8543,8563,8573,8581,8597,8599,8609,8623,8627,8629,8641,8647,8663,8669,8677,8681,8689,8693,8699,8707,8713,8719,8731,8737,8741,8747,8753,8761,8779,8783,8803,8807,8819,8821,8831,8837,8839,8849,8861,8863,8867,8887,8893,8923,8929,8933,8941,8951,8963,8969,8971,8999,9001,9007,9011,9013,9029,9041,9043,9049,9059,9067,9091,9103,9109,9127,9133,9137,9151,9157,9161,9173,9181,9187,9199,9203,9209,9221,9227,9239,9241,9257,9277,9281,9283,9293,9311,9319,9323,9337,9341,9343,9349,9371,9377,9391,9397,9403,9413,9419,9421,9431,9433,9437,9439,9461,9463,9467,9473,9479,9491,9497,9511,9521,9533,9539,9547,9551,9587,9601,9613,9619,9623,9629,9631,9643,9649,9661,9677,9679,9689,9697,9719,9721,9733,9739,9743,9749,9767,9769,9781,9787,9791,9803,9811,9817,9829,9833,9839,9851,9857,9859,9871,9883,9887,9901,9907,9923,9929,9931,9941,9949,9967,9973];return void 0===e?t:t.slice(0,Math.max(t.length,e))}static dividers(e){let t;const i=Math.sqrt(Math.abs(e));t=[];for(let s=1;s<=i;s++)e%s==0&&(t.push(s),t.push(e/s));return t.sort((function(e,t){return e-t})),[...new Set(t)]}static gcd(...e){let t=function(e,i){return 0===i?e:t(i,e%i)},i=1,s=2;if(0===e.length)return 1;if(1===e.length)return 0===e[0]?1:e[0];if(i=t(e[0],e[1]),1===i)return 1;for(s=2;s<e.length&&(i=t(i,e[s]),1!==i);s++);return Math.abs(i)}static lcm(...t){return t.reduce((function(t,i){return Math.abs(t*i/e.gcd(t,i))}))}}class t{_rpn=[];_mode;_tokenConfig;_uniformize;constructor(e){this._mode=void 0===e?"polynom":e,this.tokenConfigInitialization()}isOperation(e){return!!e[0].match(/[+\-*/^]/g)}tokenConfigInitialization(){return"set"===this._mode?(this._tokenConfig={"&":{precedence:3,associative:"left"},"|":{precedence:3,associative:"left"},"!":{precedence:4,associative:"right"},"-":{precedence:2,associative:"left"}},this._uniformize=!1):(this._tokenConfig={"^":{precedence:4,associative:"right"},"*":{precedence:3,associative:"left"},"/":{precedence:3,associative:"left"},"+":{precedence:2,associative:"left"},"-":{precedence:2,associative:"left"},"%":{precedence:3,associative:"right"},sin:{precedence:4,associative:"right"},cos:{precedence:4,associative:"right"},tab:{precedence:4,associative:"right"}},this._uniformize=!0),this._tokenConfig}NextToken2(e,t){let i,s;if(i="",s="","("===e[t])i="(",s="(";else if(")"===e[t])i=")",s=")";else if(","===e[t])i=",",s="function-argument";else{const n=Object.keys(this._tokenConfig).sort(((e,t)=>t.length-e.length));for(let r of n)if(e.substr(t,r.length)===r){i+=r,s="operation";break}""===i&&(e[t].match(/[0-9]/)?(i=e.substr(t).match(/^([0-9.,/]+)/)[0],s="coefficient"):e[t].match(/[a-zA-Z]/)?(i=e.substr(t).match(/^([a-zA-Z])/)[0],s="variable"):(console.log("Unidentified token",e[t],e,t),i=e[t],s="monom"))}return[i,t+i.length,s]}NextToken(e,t){let i,s,n;return this.NextToken2(e,t),i=e.substr(t).match(/^[0-9/a-zA-Z^]+/g)||[],e.substr(t,t+3).match(/^(sin|cos|tan)/g)?(s=e.substr(t,3),n="function"):i.length>0?(s=i[0],n="monom"):e[t].match(/[+\-*/^]/g)||e[t].match(/[&|!]/g)?(s=e[t],n="operation"):"("===e[t]?(s="(",n="("):")"===e[t]?(s=")",n=")"):","===e[t]?(s=",",n="function-argument"):(s=i[0],n="monom",""===s&&(s=e[t],n="monom",console.log("SHUTING YARD - NEXT TOKEN: error at ",t))),[s,t+s.length,n]}Uniformizer(e){if(!this._uniformize)return e;let t;t=e.replace(/\)\(/g,")*("),t=t.replace(/([\da-zA-Z])(\()/g,"$1*$2"),t=t.replace(/(\))([\da-zA-Z])/g,"$1*$2"),t=t.replace(/([0-9])([a-zA-Z])/g,"$1*$2"),t=t.replace(/([a-zA-Z])([0-9])/g,"$1*$2"),t=t.replace(/([abcxyz])([abcxyz])/g,"$1*$2");let i=["sin","cos","tan"];for(let e of i)t=t.replace(new RegExp(e+"\\*","g"),e);return t}parse(e,t){let i=[],s=[],n="",r=0,o="",l=0;e=this.Uniformizer(e);let h,a=50;for(;r<e.length;){if(a--,0===a){console.log("SECURITY LEVEL 1 EXIT");break}switch([n,r,o]=this.NextToken2(e,r),o){case"monom":case"coefficient":case"variable":i.push({token:n,tokenType:o});break;case"operation":if(l=s.length,s.length>0){let e=s[s.length-1];for(h=50;e.token in this._tokenConfig&&("left"===this._tokenConfig[n].associative&&this._tokenConfig[n].precedence<=this._tokenConfig[e.token].precedence||"right"===this._tokenConfig[n].associative&&this._tokenConfig[n].precedence<this._tokenConfig[e.token].precedence);){if(h--,0===h){console.log("SECURITY LEVEL 2 OPERATION EXIT");break}if(i.push(s.pop()||{token:"",tokenType:"operation"}),0===s.length)break;e=s[s.length-1]}}s.push({token:n,tokenType:o});break;case"function-argument":for(h=50;"("!==s[s.length-1].token&&s.length>0;){if(h--,0===h){console.log("SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT");break}i.push(s.pop()||{token:n,tokenType:o})}break;case"(":s.push({token:n,tokenType:o}),"-"===e[r]&&i.push({token:"0",tokenType:"coefficient"});break;case")":for(h=50;"("!==s[s.length-1].token&&s.length>1;){if(h--,0===h){console.log("SECURITY LEVEL 2 CLOSING PARENTHESE EXIT");break}i.push(s.pop()||{token:n,tokenType:o})}s.pop();break;case"function":s.push({token:n,tokenType:o});break;default:console.log(`SHUTING YARD: ${o} : ${n} `)}}return this._rpn=i.concat(s.reverse()),this}get rpn(){return this._rpn}}class i{_config;_defaultConfig;mergeConfig=(e,t)=>void 0!==e?{...t,...e}:t;generate=()=>{};config=e=>(this._config=this.mergeConfig(e,this._defaultConfig),this)}class s{_numerator;_denominator;constructor(e,t){return this._numerator=1,this._denominator=1,void 0!==e&&this.parse(e,t),this}get isFraction(){return!0}get numerator(){return this._numerator}set numerator(e){this._numerator=e}get denominator(){return this._denominator}set denominator(e){this._denominator=e}get value(){return this._numerator/this._denominator}get tex(){return 1===this._denominator?`${this._numerator}`:this._numerator<0?`-\\frac{ ${-this._numerator} }{ ${this._denominator} }`:`\\frac{ ${this._numerator} }{ ${this._denominator} }`}get display(){return 1===this._denominator?`${this._numerator}`:`${this._numerator}/${this._denominator}`}get frac(){return this.tex}get dfrac(){return this.tex.replace("\\frac","\\dfrac")}parse=(e,t)=>{let i;if(null===e||""===e)return this._numerator=0,this._denominator=1,this;switch(typeof e){case"string":if(i=e.split("/"),i.length>2)throw"Two many divide signs";if(i.map((e=>""===e||isNaN(Number(e)))).includes(!0))throw"Not a number";if(1===i.length)return this.parse(+i[0]);2===i.length?"0"===i[1]?(this._numerator=NaN,this._denominator=1):(this._numerator=+i[0],this._denominator=+i[1]):(this._numerator=NaN,this._denominator=1);break;case"number":if(Number.isSafeInteger(e))this._numerator=+e,void 0!==t&&Number.isSafeInteger(t)?this._denominator=+t:this._denominator=1;else{let i=e.toString().split(".")[1].length;void 0===t?(this._numerator=e*Math.pow(10,i),this._denominator=Math.pow(10,i)):Number.isSafeInteger(t)&&(this._numerator=e*Math.pow(10,i)-Math.floor(e*Math.pow(10,i-t)),this.denominator=Math.pow(10,i)-Math.pow(10,i-t))}break;case"object":e.isFraction&&(this._numerator=+e.numerator,this._denominator=+e.denominator)}return this};clone=()=>{let e=new s;return e.numerator=+this._numerator,e.denominator=+this._denominator,e};zero=()=>(this._numerator=0,this._denominator=1,this);one=()=>(this._numerator=1,this._denominator=1,this);infinite=()=>(this._numerator=1/0,this._denominator=1,this);invalid=()=>(this._numerator=NaN,this._denominator=1,this);opposed=()=>(this._numerator=-this._numerator,this);add=e=>{let t=this._numerator,i=this._denominator;return this._numerator=t*e.denominator+e.numerator*i,this._denominator=i*e.denominator,this.reduce()};subtract=e=>this.add(e.clone().opposed());multiply=e=>{let t=new s(e);return this._numerator=this._numerator*t.numerator,this._denominator=this._denominator*t.denominator,this.reduce()};divide=e=>{let t=new s(e);if(0===t.numerator)return(new s).infinite();let i=+this._numerator,n=+this._denominator;return this._numerator=i*t.denominator,this._denominator=n*t.numerator,this.reduce()};invert=()=>{let e=+this._numerator,t=+this._denominator;return this._numerator=t,this._denominator=e,this};pow=e=>Number.isSafeInteger(e)?(this.reduce(),e<0&&this.invert(),this._numerator=this._numerator**Math.abs(e),this._denominator=this._denominator**Math.abs(e),this):this.invalid();root=e=>(0===e||(e<0&&this.invert(),Math.pow(this._numerator,Math.abs(1/e)),Math.pow(this._denominator,Math.abs(1/e)),this._numerator=Math.pow(this._numerator,Math.abs(1/e)),this._denominator=Math.pow(this._denominator,Math.abs(1/e))),this);sqrt=()=>this.root(2);abs=()=>(this._numerator=Math.abs(this._numerator),this._denominator=Math.abs(this._denominator),this);reduce=()=>{let t=e.gcd(this._numerator,this._denominator);return this._numerator=this._numerator/t,this._denominator=this._denominator/t,this._denominator<0&&(this._denominator=-this._denominator,this._numerator=-this._numerator),this};amplify=e=>(Number.isSafeInteger(e)&&(this._numerator*=e,this._denominator*=e),this);compare=(e,t)=>{switch(void 0===t&&(t="="),t){case">":return this.value>e.value;case">=":return this.value>=e.value;case"<":return this.value<e.value;case"<=":return this.value<=e.value;case"=":return this.value===e.value;case"<>":return this.value!==e.value;default:return!1}};lesser=e=>this.compare(e,"<");leq=e=>this.compare(e,"<=");greater=e=>this.compare(e,">");geq=e=>this.compare(e,">=");isEqual=e=>this.compare(e,"=");isDifferent=e=>this.compare(e,"<>");isOpposed=e=>this.isEqual(e.clone().opposed());isInverted=e=>this.isEqual((new s).one().divide(e.clone()));isZero=()=>0===this._numerator;isOne=()=>1===this._numerator&&1===this._denominator;isPositive=()=>1===this.sign();isNegative=()=>-1===this.sign();isNaN=()=>isNaN(this._numerator);isInfinity=()=>this._numerator===1/0;isFinite=()=>!this.isInfinity();isSquare=()=>Math.sqrt(this._numerator)%1==0&&Math.sqrt(this._denominator)%1==0;isReduced=()=>1===Math.abs(e.gcd(this._numerator,this._denominator));sign=()=>this._numerator*this._denominator>=0?1:-1;areEquals=(...e)=>{for(let t=0;t<e.length;t++)if(!this.isEqual(e[t]))return!1;return!0}}class n{_coefficient;_literal;constructor(e){return this.zero(),void 0!==e&&this.parse(e),this}get isMonom(){return!0}get coefficient(){return this._coefficient}set coefficient(e){this._coefficient=e}get literal(){return this._literal}get literalSqrt(){if(this.isLitteralSquare()){let e={};for(let t in this._literal)e[t]=this._literal[t]/2;return e}return this._literal}set literal(e){this._literal=e}set literalStr(e){for(const t of[...e.matchAll(/([a-z])\^([+-]?[0-9]+)/g)])t[1]in this._literal||(this._literal[t[1]]=0),this._literal[t[1]]+=+t[2];for(const t of[...e.matchAll(/([a-z](?!\^))/g)])t[1]in this._literal||(this._literal[t[1]]=0),this._literal[t[1]]+=1}get variables(){return this.clone().clean(),Object.keys(this._literal)}get display(){let e="";for(let t in this._literal)0!==this._literal[t]&&(e+=`${t}`,this._literal[t]>1&&(e+=`^${this._literal[t]}`));return""===e?0!=this._coefficient.value?`${this._coefficient.display}`:"":1===this._coefficient.value?e:-1===this._coefficient.value?`-${e}`:0===this._coefficient.value?"0":`${this._coefficient.display}${e}`}get dividers(){if(1!==this.coefficient.denominator)return[this.clone()];if(this.coefficient.numerator>1e4)return[this.clone()];const t=e.dividers(Math.abs(this.coefficient.numerator));let i=[];for(let e in this.literal)i=this._getLitteralDividers(i,e);const r=[];if(i.length>0&&t.length>0)for(let e of t)for(let t of i){let i=new n;i.coefficient=new s(e),i.literal=t,r.push(i)}else if(0===t.length)for(let e of i){let t=new n;t.coefficient=(new s).one(),t.literal=e,r.push(t)}else for(let e of t){let t=new n;t.coefficient=new s(e),r.push(t)}return 0===r.length?[(new n).one()]:r}_getLitteralDividers(e,t){let i=[];for(let s=0;s<=this.literal[t];s++)if(0===e.length){let e={};e[t]=s,i.push(e)}else for(let n of e){let e={};for(let t in n)e[t]=n[t];e[t]=s,i.push(e)}return i}get displayWithSign(){let e=this.display;return("-"!==e[0]?"+":"")+e}get tex(){let e="";for(let t in this._literal)0!==this._literal[t]&&(e+=`${t}`,this._literal[t]>1&&(e+=`^${this._literal[t]}`));return""===e?0!=this._coefficient.value?`${this._coefficient.dfrac}`:"0":1===this._coefficient.value?e:-1===this._coefficient.value?`-${e}`:0===this._coefficient.value?"0":`${this._coefficient.dfrac}${e}`}parse=e=>{this.literalStr=e,this._coefficient=new s;for(const t of[...e.replace(/([a-z])|(\^[+-]?[0-9]+)/g,",").split(",")])""!==t.trim()&&this._coefficient.multiply(new s(t.trim()));return this};clone=()=>{let e=new n;e.coefficient=this._coefficient.clone();for(let t in this._literal)e.setLetter(t,this._literal[t]);return e};zero=()=>(this._coefficient=(new s).zero(),this._literal={},this);one=()=>(this._coefficient=(new s).one(),this._literal={},this);clean=()=>{for(let e in this._literal)0===this._literal[e]&&delete this._literal[e];return this};opposed=()=>(this._coefficient.opposed(),this);add=(...e)=>{for(let t of e)this.isSameAs(t)?this._coefficient.add(t.coefficient):console.log("Add: Is not similar: ",t.display);return this};subtract=(...e)=>{for(let t of e)this.isSameAs(t)?this._coefficient.add(t.coefficient.clone().opposed()):console.log("Subtract: Is not similar: ",t.display);return this};multiply=(...e)=>{for(let t of e){this._coefficient.multiply(t.coefficient);for(let e in t.literal)this._literal[e]=void 0===this._literal[e]?t.literal[e]:this._literal[e]+t.literal[e]}return this};multiplyByNumber=e=>(this._coefficient.multiply(e),this);divide=(...e)=>{for(let t of e){this._coefficient.divide(t.coefficient);for(let e in t.literal)this._literal[e]=void 0===this._literal[e]?-t.literal[e]:this._literal[e]-t.literal[e],0===this._literal[e]&&delete this._literal[e]}return this};pow=e=>{this._coefficient.pow(e);for(let t in this._literal)this._literal[t]*=e;return this};root=e=>this;sqrt=()=>{if(this.isSquare()){this._coefficient.sqrt();for(let e in this._literal)this._literal[e]/=2}return this.root(2)};compare=(e,t)=>{switch(void 0===t&&(t="="),t){case"=":return!!this.compare(e,"same")&&this._coefficient.isEqual(e.coefficient);case"same":let t=this.variables,i=e.variables,s=t.concat(i.filter((e=>t.indexOf(e)<0)));for(let t of s){if(void 0===this._literal[t]||void 0===e.literal[t])return!1;if(this._literal[t]!==e.literal[t])return!1}return!0;default:return!1}};isZero(){return 0===this._coefficient.value}isOne(){return 1===this._coefficient.value&&0===this.variables.length}isEqual=e=>this.compare(e,"=");isSameAs=e=>this.compare(e,"same");isSquare=()=>!!this.coefficient.isSquare()&&this.isLitteralSquare();isLitteralSquare=()=>{for(let e in this.literal)if(this.literal[e]%2!=0)return!1;return!0};hasLetter=e=>this._literal[void 0===e?"x":e]>0;setLetter=(e,t)=>{t<=0||!Number.isSafeInteger(t)?void 0!==this._literal[e]&&delete this._literal[e]:this._literal[e]=t};degree=e=>0===this.variables.length?0:void 0===e?Object.values(this._literal).reduce(((e,t)=>e+t)):void 0===this._literal[e]?0:this._literal[e];evaluate=e=>{let t=this.coefficient.clone();if("number"==typeof e||e instanceof s){let t={};return t[this.variables[0]]=new s(e),this.evaluate(t)}if("object"==typeof e)for(let i in this._literal){if(void 0===e[i])return(new s).zero();let n=new s(e[i]);t.multiply(n.pow(this._literal[i]))}return t};derivative=e=>{if(void 0===e&&(e="x"),this.hasLetter(e)){let t=+this._literal[e],i=this.clone();return i._literal[e]-=1,i._coefficient.multiply(new s(""+t)),i}return(new n).zero()};primitive=e=>{void 0===e&&(e="x");let t=this.clone();return t.hasLetter(e)?(t.coefficient=t.coefficient.clone().divide(t.degree(e)+1),t.setLetter(e,t.degree(e)+1)):(t.coefficient.isZero()&&(t.coefficient=(new s).one()),t.setLetter(e,1)),t};static lcm=(...t)=>{let i=new n,r=t.map((e=>e.coefficient.numerator)),o=t.map((e=>e.coefficient.denominator)),l=e.gcd(...r),h=e.lcm(...o);i.coefficient=new s(l,h).reduce();for(let e of t){for(let t in i.literal)t in e.literal||(i.literal[t]=0);for(let t in e.literal)void 0===i.literal[t]&&e.literal[t]>0?i.literal[t]=e.literal[t]:i.literal[t]=Math.min(e.literal[t],i.literal[t])}return i};static xmultiply=(...e)=>{let t=(new n).one();for(let i of e)t.multiply(i);return t};areSameAs=(...e)=>{for(let t=0;t<e.length;t++)if(!this.isSameAs(e[t]))return!1;return!0};areEquals=(...e)=>{if(!this.areSameAs(...e))return!1;for(let t of e)if(!this._coefficient.isEqual(t.coefficient))return!1;return!0}}class r extends i{constructor(e){super(),this._defaultConfig={letters:"x",degree:2,fraction:!0,zero:!1},this._config=this.mergeConfig(e,this._defaultConfig)}generate=()=>{let e=new n;if(e.coefficient.parse(a.numberSym(10,this._config.zero),this._config.fraction?a.number(1,10):1).reduce(),this._config.letters.length>1){for(let t of this._config.letters.split(""))e.setLetter(t,0);for(let t=0;t<this._config.degree;t++){const t=a.item(this._config.letters.split(""));e.setLetter(t,e.degree(t)+1)}}else e.setLetter(this._config.letters,this._config.degree);return e}}class o{_rawString;_monoms;_factors;_texString;constructor(e,...t){return this._monoms=[],this._factors=[],void 0!==e&&this.parse(e,...t),this}get isPolynom(){return!0}get monoms(){return this._monoms}set monoms(e){this._monoms=e}get factors(){return this._factors}set factors(e){this._factors=e}get texFactors(){this.factorize();let e="";for(let t of this.factors)t.monoms.length>1?e+=`(${t.tex})`:e=t.tex+e;return e}get texString(){return this._texString}get length(){return this._monoms.length}get display(){return this.genDisplay()}get raw(){return this._rawString}get tex(){return this.genDisplay("tex")}get isMultiVariable(){for(const e of this._monoms)if(e.variables.length>1)return!0;return!1}get variables(){let e=[];for(const t of this._monoms)e=e.concat(t.variables);return e=[...new Set(e)],e}get numberOfVars(){return this.variables.length}genDisplay=(e,t,i)=>{let s="";for(const i of this._monoms)0!==i.coefficient.value&&(s+=`${1!==i.coefficient.sign()||""===s&&!0!==t?"":"+"}${"tex"===e?i.tex:i.display}`);return!0===i&&this.length>1&&(s="tex"===e?`\\left( ${s} \\right)`:`(${s})`),""===s&&(s="0"),s};parse=(e,...t)=>{if(void 0===t||0===t.length){if(e=""+e,this._rawString=e,""!==e&&!isNaN(Number(e))){this.empty();let t=new n;return t.coefficient=new s(e),t.literalStr="",this.add(t),this}return this.shutingYardToReducedPolynom(e)}if(/^[a-z]/.test(e)){this.empty();let i=t.map((e=>new s(e)));if(e.length>1){let t=e.split(""),s=0;for(let e of i){let i=new n;i.coefficient=e.clone(),i.literalStr=t[s]||"",this.add(i),s++}}else{let t=i.length-1;for(let s of i){let i=new n;i.coefficient=s.clone(),i.literalStr=`${e}^${t}`,this.add(i),t--}}return this}return this.zero()};shutingYardToReducedPolynom=e=>{const i=(new t).parse(e).rpn;let s,r,l,h=[],a=null;for(const e of i){if("coefficient"===e.tokenType||"variable"===e.tokenType)l=(new o).zero(),l.monoms=[new n(e.token)],h.push(l.clone());else if("operation"===e.tokenType)switch(r=h.pop()||(new o).zero(),s=h.pop()||(new o).zero(),e.token){case"+":h.push(s.add(r));break;case"-":h.push(s.subtract(r));break;case"*":h.push(s.multiply(r));break;case"^":h.push(s.pow(+a))}a=e.token}return this._monoms=h[0].monoms,this};clone=()=>{const e=new o,t=[];for(const e of this._monoms)t.push(e.clone());return e.monoms=t,e};zero=()=>(this._monoms=[],this._monoms.push((new n).zero()),this._rawString="0",this);one=()=>(this._monoms=[],this._monoms.push((new n).one()),this._rawString="1",this);empty=()=>(this._monoms=[],this._rawString="",this);random(e){return a.polynom(e)}_randomizeDefaults={degree:2,unit:!0,fractions:!1,factorable:!1,letters:"x",allowNullMonom:!1,numberOfMonoms:!1};get randomizeDefaults(){return this._randomizeDefaults}set randomizeDefaults(e){this._randomizeDefaults=e}randomize=e=>{let t=new o;void 0===e&&(e={});for(let t in this._randomizeDefaults)void 0===e[t]&&(e[t]=this._randomizeDefaults[t]);return t};rndFactorable=(e=2,t=!1,i="x")=>{this._factors=[];for(let s=0;s<e;s++){let e=!0===t||s>=t,n=a.polynom({degree:1,unit:e,fraction:!1,letters:i});this._factors.push(n)}this.empty().monoms=this._factors[0].monoms;for(let e=1;e<this._factors.length;e++)this.multiply(this._factors[e]);return this};opposed=()=>(this._monoms=this._monoms.map((e=>e.opposed())),this);add=(...e)=>{for(let t of e)t.isPolynom?this._monoms=this._monoms.concat(t.monoms):t.isMonom?this._monoms.push(t.clone()):Number.isSafeInteger(t)?this._monoms.push(new n(t.toString())):this._monoms.push(new n(t));return this.reduce()};subtract=(...e)=>{for(let t of e)t.isPolynom?this._monoms=this._monoms.concat(t.clone().opposed().monoms):t.isMonom?this._monoms.push(t.clone().opposed()):Number.isSafeInteger(t)?this._monoms.push(new n(t.toString()).opposed()):this._monoms.push(new n(t).opposed());return this.reduce()};multiply=e=>e.isPolynom?this.multiplyByPolynom(e):e.isFraction?this.multiplyByFraction(e):e.isMonom?this.multiplyByMonom(e):Number.isSafeInteger(e)?this.multiplyByInteger(e):this;multiplyByPolynom=e=>{const t=[];for(const i of this._monoms)for(const s of e.monoms)t.push(n.xmultiply(i,s));return this._monoms=t,this.reduce()};multiplyByFraction=e=>{for(const t of this._monoms)t.coefficient.multiply(e);return this.reduce()};multiplyByInteger=e=>this.multiplyByFraction(new s(e));multiplyByMonom=e=>{for(const t of this._monoms)t.multiply(e);return this.reduce()};euclidian=e=>{const t=e.variables[0],i=(new o).zero(),s=this.clone().reorder(t);if(0===e.variables.length)return{quotient:i,reminder:s};const n=e.monomByDegree(void 0,t),r=e.degree(t);let l,h=2*this.degree(t);for(;s.degree(t)>=r&&h>=0&&(h--,l=s.monomByDegree(void 0,t).clone().divide(n),!l.isZero());)i.add(l),s.subtract(e.clone().multiply(l));return{quotient:i,reminder:s}};divide=e=>{if(e.isFraction)this.divideByFraction(e);else if(Number.isSafeInteger(e))return this.divideByInteger(e)};divideByInteger=e=>{const t=new s(e);for(const e of this._monoms)e.coefficient.divide(t);return this};divideByFraction=e=>{for(const t of this._monoms)t.coefficient.divide(e);return this};pow=e=>{if(!Number.isSafeInteger(e))return this.zero();if(e<0)return this.zero();if(0===e)return new o;const t=this.clone();for(let i=1;i<e;i++)this.multiply(t);return this.reduce()};compare=(e,t)=>{void 0===t&&(t="=");const i=this.clone().reduce().reorder(),s=e.clone().reduce().reorder();switch(t){case"=":if(i.length!==s.length||i.degree()!==s.degree())return!1;for(const e in i.monoms)if(!i.monoms[e].isEqual(s.monoms[e]))return!1;return!0;case"same":if(i.length!==s.length||i.degree()!==s.degree())return!1;for(const e in i.monoms)if(!i.monoms[e].isSameAs(s.monoms[e]))return!1;return!0;default:return!1}};isZero(){return 1===this._monoms.length&&this._monoms[0].coefficient.isZero()||0===this._monoms.length}isOne(){return 1===this._monoms.length&&this._monoms[0].coefficient.isOne()}isEqual=e=>this.compare(e,"=");isSameAs=e=>this.compare(e,"same");isOpposedAt=e=>this.compare(e.clone().opposed(),"=");isFactorized=e=>{let t;if(e.match(/\(/g).length!==e.match(/\)/g).length)return!1;try{t=new o(e)}catch(e){return!1}if(!this.isEqual(t))return!1;let i=e.replaceAll("*",""),s=""+i,n=[];for(let e of i.matchAll(/\(([a-z0-9+\-]+)\)(\^[0-9]*)?/g)){if(void 0!==e[2])for(let t=0;t<+e[2].substr(1);t++)n.push(e[1]);else n.push(e[1]);s=s.replaceAll(e[0],"")}""!==s&&n.push(s);let r=n.map((e=>new o(e)));this.factorize();let l=1;for(let e of this.factors)for(let t=0;t<r.length;t++){if(e.isEqual(r[t])){r.splice(t,1);break}if(e.isOpposedAt(r[t])){r.splice(t,1),l=-l;break}}return 0===r.length&&1===l};isDeveloped=e=>{let t;if(e.match(/\(/g).length+e.match(/\)/g).length)return!1;try{t=new o(e)}catch(e){return!1}return!!this.isEqual(t)&&e.replaceAll("[*s]","")===t.reduce().reorder().display};reduce=()=>{for(let e=0;e<this._monoms.length;e++)for(let t=e+1;t<this._monoms.length;t++)this._monoms[e].isSameAs(this.monoms[t])&&(this._monoms[e].add(this.monoms[t]),this._monoms.splice(t,1));this._monoms=this._monoms.filter((e=>0!==e.coefficient.value));for(const e of this._monoms)e.coefficient.reduce();return 0===this.length?(new o).zero():this};reorder=(e="x")=>(this._monoms.sort((function(t,i){return i.degree(e)-t.degree(e)})),this.reduce());degree=e=>{let t=0;for(const i of this._monoms)t=Math.max(i.degree(e),t);return t};letters=()=>{let e=new Set;for(let t of this._monoms)e=new Set([...e,...t.variables]);return[...e]};replaceBy=(e,t)=>{let i;const s=(new o).zero();for(const n of this.monoms)void 0===n.literal[e]||0===n.literal[e]?s.add(n.clone()):(i=+n.literal[e],delete n.literal[e],s.add(t.clone().pow(i).multiply(n)));return this._monoms=s.reduce().reorder().monoms,this};evaluate=e=>{const t=(new s).zero();return this._monoms.forEach((i=>{t.add(i.evaluate(e))})),t};derivative=e=>{let t=new o;for(let i of this._monoms)t.add(i.derivative(e));return t};primitive=e=>{let t=new o;for(let i of this._monoms)t.add(i.primitive(e));return t};integrate=(e,t,i)=>{const s=this.primitive(i);void 0===i&&(i="x");let n={},r={};return n[i]=e,r[i]=t,s.evaluate(r).subtract(s.evaluate(n))};factorize_OLD=e=>{this._factors=[];let t=this.clone(),i=0;t.monomByDegree().coefficient.numerator<0&&this._factors.push(new o("-1"));let n=t.commonMonom();if(!n.isOne()){let e=new o;e.monoms=[n],0===this._factors.length?this._factors.push(e):(this._factors=[],this._factors.push(e.opposed())),t=t.euclidian(e).quotient,i=e.degree()}if(t.degree()<=1)this._factors.push(t.clone());else{let n,r=new s,l=t.degree();e=void 0===e?20:e;for(let s=1;s<=e;s++)for(let h=-e;h<=e;h++){if(r.parse(-h,s),t.evaluate({x:r}))for(n=new o(`${s}x+${h}`);0===t.evaluate({x:r}).value;)this._factors.push(n.clone()),i++,t=t.euclidian(n).quotient;if(i>l)return this}if(t.degree()>1)return this._factors.push(t.clone()),this}return this};factorize=e=>{let t,i=[],s=this.clone().reorder(),n=s.commonMonom();n.isOne()||(t=new o,t.monoms=[n],i=[t.clone()],s=s.euclidian(t).quotient);let r=2*s.degree();for(;r>=0;){if(r--,s.monoms.length<2){s.isOne()||i.push(s.clone());break}{let e=s.monoms[0].dividers,t=s.monoms[s.monoms.length-1].dividers;for(let n of e)for(let e of t){let t,r=new o;r.monoms=[n.clone(),e.clone()],t=s.euclidian(r),t.reminder.isZero()?(s=t.quotient.clone(),i.push(r)):(r.monoms=[n.clone(),e.clone().opposed()],t=s.euclidian(r),t.reminder.isZero()&&(s=t.quotient.clone(),i.push(r)))}}}return this.factors=i,i};_factorize2ndDegree=e=>{let t,i,s,n,r,l,h,a,c;if(1===this.numberOfVars)return s=this.monomByDegree(2,e).coefficient,n=this.monomByDegree(1,e).coefficient,r=this.monomByDegree(0,e).coefficient,l=n.clone().pow(2).subtract(s.clone().multiply(r).multiply(4)),l.isZero()?(h=n.clone().opposed().divide(s.clone().multiply(2)),t=new o(e).subtract(h.display).multiply(h.denominator),i=new o(e).subtract(h.display).multiply(h.denominator),c=s.divide(h.denominator).divide(h.denominator),c.isOne()?[t,i]:[new o(c.display),t,i]):l.isPositive()&&l.isSquare()?(h=n.clone().opposed().add(l.clone().sqrt()).divide(s.clone().multiply(2)),a=n.clone().opposed().subtract(l.clone().sqrt()).divide(s.clone().multiply(2)),c=s.divide(h.denominator).divide(a.denominator),c.isOne()?[new o(e).subtract(h.display).multiply(h.denominator),new o(e).subtract(a.display).multiply(a.denominator)]:[new o(c.display),new o(e).subtract(h.display).multiply(h.denominator),new o(e).subtract(a.display).multiply(a.denominator)]):[this.clone()];if(s=this.monomByDegree(2,e),n=this.monomByDegree(1,e),r=this.monomByDegree(0,e),s.isLitteralSquare()&&r.isLitteralSquare()&&n.clone().pow(2).isSameAs(s.clone().multiply(r))){let e,t=new o("x",s.coefficient,n.coefficient,r.coefficient)._factorize2ndDegree("x"),i=[];if(t.length>=2){for(let n of t)0===n.degree()?i.push(n.clone()):(e=n.clone(),e.monoms[0].literal=s.literalSqrt,e.monoms[1].literal=r.literalSqrt,i.push(e.clone()));return i}}return[this.clone()]};_factorizeByGroups=()=>[];getZeroes=()=>{switch(this.degree()){case 0:return 0===this._monoms[0].coefficient.value?[!0]:[!1];case 1:if(1===this._monoms.length)return[(new s).zero()];{const e=this.clone().reduce().reorder();return[e.monoms[1].coefficient.opposed().divide(e.monoms[0].coefficient)]}default:0===this._factors.length&&this.factorize();let e=[],t=[];for(let i of this._factors)if(i.degree()>2);else if(2===i.degree()){let t=i.monomByDegree(2).coefficient,n=i.monomByDegree(1).coefficient,r=i.monomByDegree(0).coefficient,o=n.clone().pow(2).subtract(t.clone().multiply(r).multiply(4));if(o.value>0){let i=(-n.value+Math.sqrt(o.value))/(2*t.value),r=(-n.value-Math.sqrt(o.value))/(2*t.value);e.push(new s(i.toFixed(3)).reduce()),e.push(new s(r.toFixed(3)).reduce())}else 0===o.value||console.log("No zero for ",i.tex)}else for(let s of i.getZeroes())!1!==s&&!0!==s&&-1===t.indexOf(s.frac)&&(e.push(s),t.push(s.frac));return e}return[]};monomByDegree=(e,t)=>{if(void 0===e)return this.monomByDegree(this.degree(t),t);const i=this.clone().reduce();for(const s of i._monoms)if(s.degree(t)===e)return s.clone();return(new n).zero()};monomsByDegree=(e,t)=>{if(void 0===e)return this.monomsByDegree(this.degree(t));let i=[];const s=this.clone().reduce();for(const n of s._monoms)n.degree(t)===e&&i.push(n.clone());return i};monomByLetter=e=>{const t=this.clone().reduce();for(const i of t._monoms)if(i.hasLetter(e))return i.clone();return(new n).zero()};getDenominators=()=>{const e=[];for(const t of this._monoms)e.push(t.coefficient.denominator);return e};getNumerators=()=>{const e=[];for(const t of this._monoms)e.push(t.coefficient.numerator);return e};lcmDenominator=()=>e.lcm(...this.getDenominators());gcdDenominator=()=>e.gcd(...this.getDenominators());lcmNumerator=()=>e.lcm(...this.getNumerators());gcdNumerator=()=>e.gcd(...this.getNumerators());commonMonom=()=>{let e,t,i=(new n).one(),r=this.degree();e=this.gcdNumerator(),t=this.gcdDenominator(),i.coefficient=new s(e,t);for(let e of this.variables){i.setLetter(e,r);for(let t of this._monoms)if(i.setLetter(e,Math.min(t.degree(e),i.degree(e))),0===i.degree(e))break}return i};makeItComplicate=(e=1)=>(this._texString="",this.degree()<1||a.number(0,this.degree()-1),this);factorizePartial=t=>{if(this._texString="",this.length<=1)return this;let i,s,r,l,h,a;for(let c=0;c<this.length;c++){i=this._monoms[c].clone();for(let u=c+1;u<this.length;u++)if(s=this._monoms[u].clone(),h=e.gcd(i.coefficient.numerator,s.coefficient.numerator),1!==h)return r=n.lcm(i,s),a=1===i.coefficient.sign()?"+":"-",this._texString=`${!0===t?a:"+"===a?"":a}${r.tex}`,l=(new o).add(i.divide(r)).add(s.divide(r)),this._texString+=l.genDisplay("tex",!1,!0),this._texString+=this.clone().subtract(l.clone().multiply(r)).genDisplay("tex",!0,!1),this}return this._texString=this.genDisplay("tex",t),this};minify=()=>(this.multiply(this.lcmDenominator()).divide(this.gcdNumerator()).reduce(),this.reduce());canDivide=(e,t="x")=>{const i=e.degree(),s={};if(0===i)return!e.isZero;if(1===i){const i=e.getZeroes();return!0!==i[0]&&!1!==i[0]&&(s[t]=i[0],0===this.evaluate(s).value)}return i>1&&(console.log("Currently, only first degree polynom are supported"),!1)}}class l extends i{constructor(e){super(),this._defaultConfig={letters:"x",degree:2,fraction:!1,zero:!1,unit:!1,factorable:!1,allowNullMonom:!0,numberOfMonoms:0},this._config=this.mergeConfig(e,this._defaultConfig)}generate=()=>{let e,t=(new o).empty();for(let i=this._config.degree;i>=0;i--)e=new r({letters:this._config.letters,degree:i,fraction:this._config.fraction,zero:i!==this._config.degree&&this._config.allowNullMonom}).generate(),this._config.unit&&this._config.degree===i&&e.coefficient.one(),t.add(e);return this._config.numberOfMonoms>0&&this._config.numberOfMonoms<t.length&&(console.log(t.monoms.length),t.monoms=a.array(t.monoms,this._config.numberOfMonoms)),t};factorable=()=>new o}class h{static randomBool(e=.5){return Math.random()<e}static randomInt(e,t){return void 0===t?this.randomInt(0,e):Math.floor(Math.random()*(t-e+1)+e)}static randomIntSym(e,t){return!1===t?this.randomBool()?this.randomInt(1,e):-this.randomInt(1,e):this.randomInt(-e,e)}static randomArray(e,t){return void 0===t&&(t=1),e.length<=0?Object.values(e):h.shuffleArray(e).slice(0,t)}static randomItem(e){return 0===e.length?"":this.randomArray(e,1)[0]}static shuffleArray(e){let t=Object.values(e);for(let e=t.length-1;e>0;e--){const i=Math.floor(Math.random()*(e+1)),s=t[e];t[e]=t[i],t[i]=s}return t}}var a,c,u;!function(e){e.polynom=function(e){return new l(e).generate()},e.monom=function(e){return new r(e).generate()},e.number=function(e,t){return h.randomInt(e,t)},e.numberSym=function(e,t){return h.randomIntSym(e,t)},e.bool=function(e){return h.randomBool(e)},e.array=function(e,t){return h.randomArray(e,t)},e.item=function(e){return h.randomItem(e)},e.shuffle=function(e){h.shuffleArray(e)}}(a||(a={}));class m{_radical;_nth;_coefficient;_isValid;constructor(){this._radical=1,this._coefficient=1,this._nth=2,this._isValid=!0}get radical(){return this._radical}set radical(e){this._radical=e}get nth(){return this._nth}set nth(e){Number.isSafeInteger(e)&&e>=2?this._nth=e:(console.log("Error setting the nth root"),this._nth=2)}get coefficient(){return this._coefficient}set coefficient(e){this._coefficient=e}get tex(){let e;return e=1===this._coefficient?"":-1===this._coefficient?"-":this._coefficient.toString(),1===this._radical?`${this._coefficient}`:2===this._nth?`${e}\\sqrt{${this._radical}}`:`${e}\\sqrt[${this._nth}]{${this._radical}}`}get value(){return this._coefficient*Math.pow(this._radical,1/this._nth)}parse=(e,t,i)=>(this._coefficient=void 0===i?1:i,this._nth=void 0===t?2:t,this._radical=void 0===e?1:e,this._nth%2==0&&this._radical<0&&(this._isValid=!1),this);reduce=()=>{let e=Math.floor(Math.pow(this._radical,1/this._nth));for(;e>1;)this._radical%Math.pow(e,this._nth)!=0?e--:(this._coefficient*=e,this._radical=this._radical/Math.pow(e,this._nth),e=Math.floor(Math.pow(this._radical,1/this._nth)));return this};multiply=e=>(this._radical*=e.radical,this.reduce());hasRadical=()=>!(1===this._radical||0===this._radical||!1===this._isValid)}class f{_left;_right;_sign;_polynom;_solutions;_varnothing="\\varnothing";_real="\\mathbb{R}";constructor(...e){if(this._left=(new o).zero(),this._right=(new o).zero(),this._sign="=",1===e.length){if(!0===e[0].isEquation)return e[0].clone();this.parse(e[0])}else{if(2!==e.length)return this;this.left=e[0].isPolynom?e[0].clone():new o(e[0]),this.right=e[1].isPolynom?e[1].clone():new o(e[1])}return this}get isEquation(){return!0}get solutions(){return this._solutions}get solution(){return 1!==this._solutions.length||this._solutions[0]!==this._real&&this._solutions[0]!==this._varnothing&&!this._solutions[0].includes("\\left")?`S = \\left{ ${this._solutions.join(";")} \\right}`:`S = ${this._solutions[0]}`}get isReal(){return void 0===this._solutions&&this.solve(),this._solutions[0]===this._real}get isVarnothing(){return void 0===this._solutions&&this.solve(),this._solutions[0]===this._varnothing}get signAsTex(){return">="===this._sign||"=>"===this._sign||"geq"===this._sign?"\\geq":"<="===this._sign||"=<"===this._sign||"leq"===this._sign?"\\leq":this._sign}get tex(){return`${this._left.tex}${this.signAsTex}${this._right.tex}`}get raw(){return`${this._left.raw}${this.signAsTex}${this._right.raw}`}get variables(){return[...new Set(this._right.variables.concat(this._left.variables))]}get numberOfVars(){return this.variables.length}get left(){return this._left}set left(e){this._left=e}get right(){return this._right}set right(e){this._right=e}get sign(){return this._sign}set sign(e){this._sign=this._formatSign(e)}parse=e=>{let t,i;if(i=this._findSign(e),!1!==i)return t=e.split(i),this.create(new o(t[0]),new o(t[1]),this._formatSign(i));console.log("The equation is not valid (no sign found)")};_findSign=e=>e.includes("geq")?e.includes("\\geq")?"\\geq":"geq":e.includes("leq")?e.includes("\\leq")?"\\leq":"leq":e.includes(">=")?">=":e.includes("=>")?"=>":e.includes(">")?">":e.includes("<=")?"<=":e.includes("=<")?"=<":e.includes("<")?"<":e.includes("=")?"=":(console.log("Equation: parse string : sign not found"),!1);_formatSign=e=>void 0===e?"=":e.includes("geq")||e.includes(">=")||e.includes("=>")?">=":e.includes(">")?">":e.includes("leq")||e.includes("<=")||e.includes("=<")?"<=":e.includes("<")?"<":"=";_reverseSign=()=>"="===this._sign?this:this._sign.includes("<")?(this._sign.replace("<",">"),this):this._sign.includes(">")?(this._sign.replace(">","<"),this):this;create=(e,t,i)=>(this._left=e,this._right=t,this._sign=this._formatSign(i),this);clone=()=>(new f).create(this._left.clone(),this._right.clone(),this._sign+"");_randomizeDefaults={degree:2};get randomizeDefaults(){return this._randomizeDefaults}set randomizeDefaults(e){this._randomizeDefaults=e}randomize=(e,t)=>(new f).create(new o,new o,t);moveLeft=()=>(this._left=this._left.clone().subtract(this._right),this._right.zero(),this);reorder=e=>{if(this._left.subtract(this._right),this._right.zero(),e)return this.moveLeft();let t;for(let e of this._left.monoms)0===e.degree()&&(t=e.clone(),this._left.subtract(t),this._right.subtract(t));return this._left.reorder(),this._right.reorder(),this};simplify=()=>(this.multiply(e.lcm(...this._left.getDenominators(),...this._right.getDenominators())),this.divide(e.gcd(...this._left.getNumerators(),...this._right.getNumerators())),this);isolate=e=>{if(1!==this.degree(e))return!1;if(this.isMultiVariable())return!1;let t,i;this._left.subtract(this._right),this._right.zero();for(let i of this._left.monoms)i.hasLetter(e)||(t=i.clone(),this._left.add(t.clone().opposed()),this._right.add(t.clone().opposed()));return 1===this._left.length&&(i=this._left.monoms[0].coefficient.clone(),this._left.divide(i),this._right.divide(i),this)};replaceBy=(e,t)=>(this._left.replaceBy(e,t),this._right.replaceBy(e,t),this);multiply=e=>{let t=new s(e);return this._left.multiply(t),this._right.multiply(t),"="!==this._sign&&-1===t.sign()&&this._reverseSign(),this};divide=e=>{let t=new s(e);return t.isZero()?this:this.multiply(t.invert())};degree=e=>Math.max(this._left.degree(e),this._right.degree(e));isMultiVariable=()=>this._left.isMultiVariable||this._right.isMultiVariable;letters=()=>[...new Set([...this._left.letters(),...this._right.letters()])];solve=e=>{switch(this._solutions=[],this._polynom=this._left.clone().subtract(this._right),this._polynom.degree(e)){case 0:case 1:this._solveDegree1(e);break;case 2:this._solveDegree2(e);break;default:this._solveDegree3plus(e)}return this};isGreater=()=>-1!==this._sign.indexOf(">")||-1!==this._sign.indexOf("geq");isStrictEqual=()=>"="===this._sign;isAlsoEqual=()=>-1!==this._sign.indexOf("=")||-1!==this._sign.indexOf("geq")||-1!==this._sign.indexOf("leq")||void 0;_solveDegree1=e=>{const t=this._polynom.monomByDegree(1,e).coefficient,i=this._polynom.monomByDegree(0,e).coefficient,s=i.clone().opposed().divide(t).display;let n;return this.isStrictEqual()?0===t.value?0===i.value?this._solutions=[this._real]:this._solutions=[this._varnothing]:this._solutions=[s]:(n=0===t.value?0===i.value&&this.isAlsoEqual()?"\\mathbb{R}":i.value>0?this.isGreater()?this._real:this._varnothing:this.isGreater()?this._varnothing:this._real:this.isGreater()&&1===t.sign()||!this.isGreater()&&-1===t.sign()?`\\left${this.isAlsoEqual()?"\\[":"\\]"}${s};+\\infty\\right\\[`:`\\left\\]-\\infty;${s} \\right\\${this.isAlsoEqual()?"\\]":"\\["}`,this._solutions=[n]),this._solutions};_solveDegree2=t=>{let i,n,r,o,l,h,a=this._polynom.monomByDegree(2,t).coefficient,c=this._polynom.monomByDegree(1,t).coefficient,u=this._polynom.monomByDegree(0,t).coefficient,f=e.lcm(a.denominator,c.denominator,u.denominator),_=a.multiply(f).value,d=c.multiply(f).value;if(i=d*d-4*_*u.multiply(f).value,i>0)if(r=(-d-Math.sqrt(i))/(2*_),o=(-d+Math.sqrt(i))/(2*_),i>1e5)this._solutions=[((-d-Math.sqrt(i))/(2*_)).toFixed(5),((-d+Math.sqrt(i))/(2*_)).toFixed(5)];else if(n=(new m).parse(i).reduce(),n.hasRadical()){let t=e.gcd(d,2*_,n.coefficient);n.coefficient=n.coefficient/t,this._solutions=0!==d?2*_/t==1?[`${-d/t} - ${n.tex}`,`${-d/t} + ${n.tex}`]:[`\\dfrac{${-d/t} - ${n.tex} }{ ${2*_/t} }`,`\\dfrac{${-d/t} + ${n.tex} }{ ${2*_/t} }`]:2*_/t==1?[`- ${n.tex}`,`${n.tex}`]:[`\\dfrac{- ${n.tex} }{ ${2*_/t} }`,`\\dfrac{${n.tex} }{ ${2*_/t} }`]}else this._solutions=[new s(-d-n.coefficient,2*_).reduce().dfrac,new s(-d+n.coefficient,2*_).reduce().dfrac];else this._solutions=0===i?[new s(-d,2*_).reduce().dfrac]:[this._varnothing];return this.isStrictEqual()||(2===this._solutions.length?(l=r<o?this._solutions[0]:this._solutions[1],h=r<o?this._solutions[1]:this._solutions[0],this.isGreater()&&1===a.sign()||!this.isGreater()&&-1===a.sign()?this._solutions=[`\\left]-\\infty ; ${l}\\right${this.isAlsoEqual()?"]":"["} \\cup \\left${this.isAlsoEqual()?"[":"]"}${h};+\\infty\\right[`]:this._solutions=[`\\left${this.isAlsoEqual()?"[":"]"}${l} ; ${h}\\right${this.isAlsoEqual()?"]":"["}`]):1===this._solutions.length&&this._solutions[0]!==this._varnothing?this.isAlsoEqual()?(this.isGreater()&&1===a.sign()||!this.isGreater()&&-1===a.sign())&&(this._solutions=[this._real]):this.isGreater()&&1===a.sign()||!this.isGreater()&&-1===a.sign()?this._solutions=[`\\left]-\\infty ; ${this._solutions[0]}\\right[ \\cup \\left]${this._solutions[0]};+\\infty\\right[`]:this._solutions=[this._varnothing]:this.isGreater()?this._solutions=[1===a.sign()?this._real:this._varnothing]:this._solutions=[-1===a.sign()?this._real:this._varnothing]),this._solutions};_solveDegree3plus=e=>(this._solutions=[e],this._solutions)}class _{_solutions;_resolutionSteps;_equations;_letters;constructor(...e){return this._equations=[],this._letters="xy".split(""),void 0!==e&&e.length>0&&this.parse(...e),this}get isLinerarSystem(){return!0}get equations(){return this._equations}set equations(e){this._equations=e}get letters(){return this._letters.join("")}set letters(e){this._letters=e.split("")}get isSolvable(){return this.variables.length===this._equations.length}get variables(){let e=[];for(let t of this._equations)e=e.concat(t.variables);return[...new Set(e)].sort()}get tex(){let e,t,i=this.clone().reorder(),s=i.variables,n=[];for(let r of i.equations){e=[];for(let i of s)t=r.left.monomByLetter(i),0===e.length?e.push(t.isZero()?"":t.tex):e.push(t.isZero()?"":(1===t.coefficient.sign()?"+":"")+t.tex);e.push("="),e.push(r.right.tex),n.push(e.join("&"))}return`\\left\\{\\begin{array}{${"r".repeat(s.length)}cl}${n.join("\\\\ ")}\\end{array}\\right.`}get texSolution(){let e=[];void 0===this._solutions&&this.solve();for(let t in this._solutions){if(this._solutions[t].isReal)return void console.log(`Undetermined (letter ${t})`);if(this._solutions[t].isVarnothing)return void console.log(`Undefined (letter ${t})`);e.push(this._solutions[t].value.dfrac)}return`(${e.join(";")})`}parse=(...e)=>(this._equations=e.map((e=>new f(e))),this._findLetters(),this);setCoefficient=(...e)=>{this._equations=[];let t=0;for(;t<e.length-this._letters.length;){let i=(new o).parse(this._letters.join(""),...e.slice(t,t+this._letters.length)),s=new o(e[t+this._letters.length].toString()),n=(new f).create(i,s);this._equations.push(n.clone()),t=t+this._letters.length+1}return this};clone=()=>(new _).parse(...this._equations.map((e=>e.clone())));setLetters=(...e)=>(this._letters=e,this);_findLetters=()=>{let e=new Set;for(let t of this._equations)e=new Set([...e,...t.variables]);return this._letters=[...e],this};generate=(...e)=>{let t=[];for(let i of e)"number"==typeof i?t.push(new s(i.toString())):t.push(i.clone());this._equations=[];for(let i=0;i<e.length;i++)this._equations.push(this._generateOneEquation(...t));return this};_generateOneEquation=(...e)=>{let t,i=[],n=(new s).zero(),r=["x","y","z","t","u","v","w","a","b","c","d","e","f","g","h","i","j","k","l"],o="";for(let t=0;t<e.length;t++)i.push(a.numberSym(5)),n.add(e[t].clone().multiply(i[t])),o+=`${i[t]<0?i[t]:"+"+i[t]}${r[t]}`;return t=new f(`${o}=${n.display}`),1!=t.right.monoms[0].coefficient.denominator&&t.multiply(new s(t.right.monoms[0].coefficient.denominator,1)),this._checkIfLinerCombination(t)?t:this._generateOneEquation(...e)};_linearReduction(e,t,i){let s=e.left.monomByDegree(1,i).coefficient.clone(),n=t.left.monomByDegree(1,i).coefficient.clone().opposed();return this.mergeEquations(e,t,n,s)}mergeEquations=(e,t,i,n)=>{let r=e.clone().multiply(new s(i)),o=t.clone().multiply(new s(n));return r.left.add(o.left),r.right.add(o.right),r};reorder=()=>{for(let e of this._equations)e.reorder();return this};solve=()=>{this._solutions={},this._resolutionSteps=[],this.reorder();let e=this.variables.sort();for(let t of e)this._solutions[t]=this._solveOneLetter(t,e);return this};_checkIfLinerCombination=e=>!0;_solveOneLetter(e,t){let i=this.clone().equations,n=[];for(let s of t)if(s!==e){for(let e=0;e<i.length-1;e++)n.push(this._linearReduction(i[e],i[e+1],s));this._resolutionSteps.push((new _).parse(...n)),i=this._resolutionSteps[this._resolutionSteps.length-1].clone().equations,n=[]}let r=this._resolutionSteps[this._resolutionSteps.length-1].equations[0];return r.solve(),{value:new s(r.solutions[0]),isReal:r.isReal,isVarnothing:r.isVarnothing}}log=()=>{let e="";for(let t of this._equations)console.log(t.tex),e+=`${t.tex}\\n}`;return e}}class d{_rawString;_rpn;constructor(e){return this._rawString=e,this.parse(e),this}get isLogicalset(){return!0}parse=e=>(this._rpn=new t("set").parse(e).rpn,this);evaluate(e,t){let i,s=[];if(void 0===t){i=new Set;for(let t in e)i=new Set([...i,...e[t]])}else i=new Set(t);for(let t of this._rpn)if("variable"===t.tokenType)void 0===e[t.token]?s.push(new Set):s.push(new Set(e[t.token]));else switch(t.token){case"&":if(s.length>=2){let e=s.pop(),t=s.pop();s.push(new Set([...t].filter((t=>e.has(t)))))}break;case"|":if(s.length>=2){let e=s.pop(),t=s.pop();s.push(new Set([...t,...e]))}break;case"-":if(s.length>=2){let e=s.pop(),t=s.pop();s.push(new Set([...t].filter((t=>!e.has(t)))))}break;case"!":if(s.length>=1){let e=s.pop();s.push(new Set([...i].filter((t=>!e.has(t)))))}}return[...s[0]].sort()}vennAB(){return this.evaluate({A:["A","AB"],B:["B","AB"]},["A","B","AB","E"])}vennABC(){return this.evaluate({A:["A","AB","AC","ABC"],B:["B","AB","BC","ABC"],C:["C","AC","BC","ABC"]},["A","B","C","AB","AC","BC","E"])}get rpn(){return this._rpn}get tex(){let e=[];for(let t of this._rpn)if("variable"===t.tokenType)e.push(t);else switch(t.token){case"&":if(e.length>=2){let t=e.pop(),i=e.pop();"mix"===i.tokenType&&(i.token=`( ${i.token} )`),"mix"===t.tokenType&&(t.token=`( ${t.token} )`),e.push({token:`${i.token} \\cap ${t.token}`,tokenType:"mix"})}break;case"|":if(e.length>=2){let t=e.pop(),i=e.pop();"mix"===i.tokenType&&(i.token=`( ${i.token} )`),"mix"===t.tokenType&&(t.token=`( ${t.token} )`),e.push({token:`${i.token} \\cup ${t.token}`,tokenType:"mix"})}break;case"-":if(e.length>=2){let t=e.pop(),i=e.pop();"mix"===i.tokenType&&(i.token=`( ${i.token} )`),"mix"===t.tokenType&&(t.token=`( ${t.token} )`),e.push({token:`${i.token} \\setminus ${t.token}`,tokenType:"mix"})}break;case"!":if(e.length>=1){let t=e.pop();e.push({token:`\\overline{ ${t.token} }`,tokenType:"variable"})}}return e[0].token}}class g{_rawString;_numerator;_denominator;constructor(e,t){this._numerator=e?e.clone():new o,this._denominator=t?t.clone():new o}clone=()=>(this._numerator=this._numerator.clone(),this._denominator=this._denominator.clone(),this);get tex(){return`\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`}get texFactors(){return this._numerator.factorize(),this._denominator.factorize(),`\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`}get numerator(){return this._numerator}get denominator(){return this._denominator}domain=()=>{let e=this._denominator.getZeroes();return 0===e.length||!1===e[0]?"\\mathbb{R}":!0===e[0]?"\\varnothing":"\\mathbb{R}\\setminus\\left{"+e.map((e=>"boolean"==typeof e?"":e.frac)).join(";")+"\\right}"};amplify=e=>(this._numerator.multiply(e),this._denominator.multiply(e),this);simplify=e=>{let t=this._numerator.euclidian(e);if(!t.reminder.isZero())return this;let i=this._denominator.euclidian(e);return i.reminder.isZero()?(this._numerator=t.quotient,this._denominator=i.quotient,this):this};reduce=()=>{console.log(this._numerator.tex),this._numerator.factorize(),console.log(this._numerator.factors.map((e=>e.tex)));for(let e of this._numerator.factors)this.simplify(e);return this};opposed=()=>(this._numerator.opposed(),this);add=e=>{let t=this._denominator.clone();return this.amplify(e._denominator),this._numerator.add(e._numerator.clone().multiply(t)),this};subtract=e=>this.add(e.clone().opposed());limits=(e,t)=>{if(e!==1/0&&e!==-1/0)return this._numerator.evaluate({letter:e}).divide(this._denominator.evaluate({letter:e}));{let i=this._numerator.monomByDegree(this._numerator.degree(t),t),s=this._denominator.monomByDegree(this._denominator.degree(t),t);if(i.divide(s),i.degree(t)>0)return i.coefficient.sign()*Math.pow(e>0?1:-1,i.degree(t)%2)==1?1/0:-1/0;if(0===i.degree(t))return i.coefficient;if(i.degree(t)>0)return i.coefficient.sign()*Math.pow(-1,i.degree(t)%2)==1?0:-0}}}!function(e){e.Polynom=class extends o{},e.Monom=class extends n{},e.LinearSystem=class extends _{},e.Equation=class extends f{},e.LogicalSet=class extends d{},e.Rational=class extends g{}}(c||(c={}));class p{_x;_y;constructor(...e){this._x=(new s).zero(),this._y=(new s).zero(),void 0!==e&&this.parse(...e)}get isVector(){return!0}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}get normSquare(){return this._x.clone().pow(2).add(this._y.clone().pow(2))}get norm(){return Math.sqrt(this.normSquare.value)}get tex(){return`\\begin{pmatrix}${this._x.tex} \\\\ ${this._y.tex} \\end{pmatrix}`}parse=(...e)=>{if(this.zero(),0===e.length)return this;if(1===e.length)return e[0].isVector?e[0].clone():this._parseString(e[0]);if(e.length>=2){if(e[0].isPoint&&e[1].isPoint)return this._x=e[1].x.clone().subtract(e[0].x),this._y=e[1].y.clone().subtract(e[0].y),this;!e[0].isFraction&&isNaN(e[0])||(this._x=new s(e[0])),!e[1].isFraction&&isNaN(e[1])||(this._y=new s(e[1]))}return this};clone=()=>{let e=new p;return null!==this._x&&(e.x=this._x.clone()),null!==this._y&&(e.y=this._y.clone()),e};reset=()=>(this._x=null,this._y=null,this);zero=()=>(this.reset(),this._x=new s(null),this._y=new s(null),this);one=()=>(this._x=new s,this._y=new s,this);_parseString=e=>{let t=e.split(/[,;\s]/g);return this.x=new s(t[0]||null),this.y=new s(t[1]||null),this};opposed=()=>(this._x.opposed(),this._y.opposed(),this);add=e=>(this._x.add(e.x),this._y.add(e.y),this);subtract=e=>this.add(e.clone().opposed());scalarProductWithVector=e=>this._x.clone().multiply(e.x).add(this._y.clone().multiply(e.y));static scalarProduct=(e,t)=>e.x.value*t.x.value+e.y.value*t.y.value;normal=()=>{let e=this.x.clone().opposed(),t=this.y.clone();return this._x=t,this._y=e,this};isNormalTo=e=>this.scalarProductWithVector(e).isZero();multiplyByScalar=e=>{let t=new s(e);return this._x.multiply(t),this._y.multiply(t),this};divideByScalar=e=>this.multiplyByScalar(new s(e).invert());simplify=()=>this.multiplyByScalar(e.lcm(this._x.denominator,this._y.denominator)).divideByScalar(e.gcd(this._x.numerator,this._y.numerator));angleWith=(e,t,i)=>{let s=this.scalarProductWithVector(e).value,n=i?1:180/Math.PI;return t&&(s=Math.abs(s)),n*Math.acos(s/(this.norm*e.norm))}}class y{_x;_y;_exist;constructor(...e){return this._x=(new s).zero(),this._y=(new s).zero(),void 0!==e&&this.parse(...e),this}get isPoint(){return!0}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}get tex(){let e=[];return e.push(this._x.tex),e.push(this._y.tex),`\\left(${e.join(";")}\\right)`}parse=(...e)=>{if(this.zero(),0===e.length)return this;if(1===e.length){if(e[0]instanceof y)return this._x=e[0].x.clone(),this._y=e[0].y.clone(),this;if("string"==typeof e[0]){let t=e[0].split(",");if(2===t.length)return this._x=new s(t[0]).reduce(),this._y=new s(t[1]).reduce(),this}if(void 0===e[0].x||void 0===e[0].y)return this.zero();this._x=new s(e[0].x).reduce(),this._y=new s(e[0].y).reduce()}return 2===e.length&&(this._x=new s(e[0]).reduce(),this._y=new s(e[1]).reduce()),this};clone=()=>(this._x=this._x.clone(),this._y=this._y.clone(),this);zero=()=>(this._x=new s(null),this._y=new s(null),this);origin=()=>(this.zero(),this);middleOf=(e,t)=>(this._x=e.x.clone().add(t.x).divide(2),this._y=e.y.clone().add(t.y).divide(2),this);texValues=e=>{let t=[];return t.push(this._x.value.toFixed(void 0===e?2:e)),t.push(this._y.value.toFixed(void 0===e?2:e)),`\\left(${t.join(";")}\\right)`};static pmatrix=(e,t,i)=>void 0===i?`\\begin{pmatrix} ${e.tex?e.tex:e} \\\\ ${t.tex?t.tex:t} \\end{pmatrix}`:`\\begin{pmatrix} ${e.tex?e.tex:e} \\\\ ${t.tex?t.tex:t} \\\\ ${i.tex?i.tex:i} \\end{pmatrix}`}class v{_a;_b;_c;_OA;_d;_n;_exists;constructor(...e){return this._exists=!1,void 0!==e&&this.parse(...e),this}get isLine(){return!0}get exists(){return this._exists}get equation(){return new f((new o).parse("xy",this._a,this._b,this._c),new o("0")).simplify()}get tex(){let e=this.equation;return this._a.isNegative()&&e.multiply(-1),{canonical:e.tex,mxh:this.slope.isInfinity()?"x="+this.OA.x.tex:"y="+(new o).parse("x",this.slope,this.height).tex,parametric:`${y.pmatrix("x","y")} = ${y.pmatrix(this._OA.x,this._OA.y)} + k\\cdot ${y.pmatrix(this._d.x,this._d.y)}`}}get a(){return this._a}set a(e){this._a=e}get b(){return this._b}set b(e){this._b=e}get c(){return this._c}set c(e){this._c=e}get OA(){return this._OA}set OA(e){this._OA=e}get d(){return this._d}get n(){return this._n}get normal(){return new p(this._a,this._b)}set d(e){this._d=e}get slope(){return this._a.clone().opposed().divide(this._b)}get height(){return this._c.clone().opposed().divide(this._b)}parse=(...e)=>{if(this._exists=!1,3===e.length)return this.parseByCoefficient(e[0],e[1],e[2]);if(2===e.length){if(e[0].isPoint&&e[1].isVector)return this.parseByPointAndVector(e[0],e[1]);if(e[0].isPoint&&e[1].isPoint)return this.parseByPointAndVector(e[0],new p(e[0],e[1]))}else if(1===e.length){if(e[0].isLine)return e[0].clone();let t=new f(e[0]);if(t.isEquation){t.reorder(!0);let e=new Set(t.letters());if(!e.has("x")&&!e.has("y"))return;for(let t of["x","y"])e.has(t)&&e.delete(t);return e.size>0?(console.log("Extra variable in the equation."),this):this.parseByCoefficient(t.left.monomByLetter("x").coefficient,t.left.monomByLetter("y").coefficient,t.left.monomByDegree(0).coefficient)}}return console.log("Someting wrong happend while creating the line"),this};parseByCoefficient=(e,t,i)=>(this._a=new s(e),this._b=new s(t),this._c=new s(i),this._d=new p(this._b.clone(),this._a.clone().opposed()),this._OA=new y((new s).zero(),this._c.clone()),this._n=this._d.clone().normal(),this._exists=!0,this);parseByPointAndVector=(e,t)=>(this.parseByCoefficient(t.y,t.x.clone().opposed(),e.x.clone().multiply(t.y).subtract(e.y.clone().multiply(t.x)).opposed()),this._OA=e.clone(),this._d=t.clone(),this._n=this._d.clone().normal(),this._exists=!0,this);clone=()=>(this._a=this._a.clone(),this._b=this._b.clone(),this._c=this._c.clone(),this._d=this._d.clone(),this._OA=this._OA.clone(),this._n=this._n.clone(),this);isParellelTo=e=>this.slope.isEqual(e.slope)&&this.height.isDifferent(e.height);isSameAs=e=>this.slope.isEqual(e.slope)&&this.height.isEqual(e.height);simplifyDirection=()=>{let t=e.lcm(this._d.x.denominator,this._d.y.denominator),i=e.gcd(this._d.x.numerator,this._d.y.numerator);return this._d.x.multiply(t).divide(i),this._d.y.multiply(t).divide(i),this};intersection=e=>{let t=new y,i=!1,s=!1;return this._b.isZero()||e.b.isZero(),this.isParellelTo(e)?(t.x=null,t.y=null,i=!0):this.isSameAs(e)?(t.x=null,t.y=null,s=!0):(t.x=this._b.clone().multiply(e.c).subtract(this._c.clone().multiply(e.b)).divide(this._a.clone().multiply(e.b).subtract(this._b.clone().multiply(e.a))),t.y=this._a.clone().multiply(e.c).subtract(this._c.clone().multiply(e.a)).divide(this._b.clone().multiply(e.a).subtract(this._a.clone().multiply(e.b)))),{point:t,hasIntersection:!(i||s),isParallel:i,isSame:s}};distanceTo(e){let t=e.x.clone().multiply(this._a).add(e.y.clone().multiply(this._b)).add(this._c).abs(),i=this.normal.normSquare;if(i.isZero())return{value:NaN,tex:"Not a line",fraction:(new s).infinite()};let n=t.value/Math.sqrt(i.value),r=t.clone().divide(i.clone().sqrt());return i.isSquare()?{value:n,tex:r.tex,fraction:r}:{value:n,tex:`\\frac{${t.tex}}{\\sqrt{${i.tex}}}`,fraction:r}}hitSegment(e,t){let i=this.intersection(new v(e,t));return!!i.hasIntersection&&i.point.x.value>=Math.min(e.x.value,t.x.value)&&i.point.x.value<=Math.max(e.x.value,t.x.value)&&i.point.y.value>=Math.min(e.y.value,t.y.value)&&i.point.y.value<=Math.max(e.y.value,t.y.value)}canonicalAsFloatCoefficient(e){void 0===e&&(e=2),this._a.value,this._b.value,this._c.value;let t="";return this._a.isZero()||(t=this._a.isOne()?"x":this._a.clone().opposed().isOne()?"-x":this._a.value.toFixed(e)+"x"),this._b.isZero()||(this._b.isPositive()&&(t+="+"),t+=this._b.value.toFixed(e)+"y"),this._c.isZero()||(this._c.isPositive()&&(t+="+"),t+=this._c.value.toFixed(e)),t+"=0"}}class w{_A;_B;_C;_lines;_middles;_remarquables;constructor(...e){return e.length>0&&this.parse(...e),this}get isTriangle(){return!0}get A(){return this._A}get B(){return this._B}get C(){return this._C}get AB(){return this.getSegment("A","B")}get BA(){return this.getSegment("B","A")}get BC(){return this.getSegment("B","C")}get CB(){return this.getSegment("C","B")}get AC(){return this.getSegment("A","C")}get CA(){return this.getSegment("C","A")}get isRectangle(){return!!this.AB.isNormalTo(this.BC)||!!this.AB.isNormalTo(this.AC)||!!this.BC.isNormalTo(this.AC)}get isEquilateral(){return this.AB.normSquare.isEqual(this.BC.normSquare)&&this.AB.normSquare.isEqual(this.AC.normSquare)}get isIsocele(){return this.AB.normSquare.isEqual(this.BC.normSquare)||this.AB.normSquare.isEqual(this.AC.normSquare)||this.BC.normSquare.isEqual(this.AC.normSquare)}get lines(){return this._lines}get remarquables(){return this._remarquables}parse=(...e)=>{if(6===e.length){let t=e.map((e=>new s(e)));return this.parse(new y(t[0],t[1]),new y(t[2],t[3]),new y(t[4],t[5]))}if(3===e.length){if(3===e.filter((e=>"string"==typeof e)).length)return this.parse(...e.map((e=>new v(e))));if(3===e.filter((e=>!0===e.isLine)).length){this._lines={AB:e[0],BC:e[1],AC:e[2]};let t=e[0].intersection(e[1]);if(!t.hasIntersection)return this;if(this._B=t.point.clone(),t=e[1].intersection(e[2]),!t.hasIntersection)return this;if(this._C=t.point.clone(),t=e[2].intersection(e[0]),!t.hasIntersection)return this;this._A=t.point.clone()}else{if(e.filter((e=>!0===e.isPoint)).length<3)return this.parse(new y(e[0]),new y(e[1]),new y(e[2]));this._A=e[0].clone(),this._B=e[1].clone(),this._C=e[2].clone(),this._lines={AB:new v(this._A,this._B),BC:new v(this._B,this._C),AC:new v(this._A,this._C)}}}else if(1===e.length&&!0===e[0].isTriangle)return e[0].clone();return this._updateTriangle(),this};clone=()=>(this._A=this._A.clone(),this._B=this._B.clone(),this._C=this._C.clone(),this._lines={AB:this._lines.AB.clone(),BC:this._lines.BC.clone(),AC:this._lines.AC.clone()},this._updateTriangle(),this);_updateTriangle=()=>{this._middles={AB:(new y).middleOf(this._A,this._B),AC:(new y).middleOf(this._A,this._C),BC:(new y).middleOf(this._B,this._C)},this._remarquables=this._calculateRemarquableLines()};getPointByName=e=>{switch(e.toUpperCase()){case"A":return this._A;case"B":return this._B;case"C":return this._C}return this._A};getSegment=(e,t)=>new p(this.getPointByName(e),this.getPointByName(t));_calculateRemarquableLines=()=>{let e={medians:{A:new v(this._A,this._middles.BC),B:new v(this._B,this._middles.AC),C:new v(this._C,this._middles.AB),intersection:null},mediators:{AB:new v(this._middles.AB,new p(this._A,this._B).normal()),AC:new v(this._middles.AC,new p(this._A,this._C).normal()),BC:new v(this._middles.BC,new p(this._B,this._C).normal()),intersection:null},heights:{A:new v(this._A,new p(this._B,this._C).normal()),B:new v(this._B,new p(this._A,this._C).normal()),C:new v(this._C,new p(this._A,this._B).normal()),intersection:null},bisectors:{A:this._calculateBisectors("A"),B:this._calculateBisectors("B"),C:this._calculateBisectors("C"),intersection:null}};return e.medians.intersection=e.medians.A.intersection(e.medians.B).point,e.mediators.intersection=e.mediators.AB.intersection(e.mediators.BC).point,e.heights.intersection=e.heights.A.intersection(e.heights.B).point,e.bisectors.intersection=e.bisectors.A.intersection(e.bisectors.B).point,e};_calculateBisectors=e=>{let t,i,s=this.lines;"A"===e?(t=s.AB,i=s.AC):"B"===e?(t=s.AB,i=s.BC):"C"===e&&(t=s.BC,i=s.AC);let n=new v(new f(t.equation.left.clone().multiply(i.n.simplify().norm),i.equation.left.clone().multiply(t.n.simplify().norm)).reorder(!0).simplify()),r=new v(new f(t.equation.left.clone().multiply(i.n.simplify().norm),i.equation.left.clone().multiply(t.n.simplify().norm).opposed()).reorder(!0).simplify());return"A"===e?n.hitSegment(this.B,this.C)?n:r:"B"===e?n.hitSegment(this.A,this.C)?n:r:"C"===e?n.hitSegment(this.B,this.A)?n:r:n}}class x{_center;_radius;_exists;constructor(...e){this._exists=!1,void 0!==e&&this.parse(...e)}parse(...e){2===e.length&&(this._center=new y(e[0]),this._radius=new s(e[1]))}get tex(){let e,t;return e=this._center.x.isZero()?"x^2":`\\left(x-${this._center.x.tex}\\right)^2`,t=this._center.y.isZero()?"y^2":`\\left(y-${this._center.y.tex}\\right)^2`,`${e}+${t}=${this._radius.pow(2).tex}`}get developed(){return new f(new o(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`),new o(`${this._radius.pow(2).display}`)).moveLeft().tex}}!function(e){e.Circle=class extends x{},e.Line=class extends v{},e.Point=class extends y{},e.Triangle=class extends w{},e.Vector=class extends p{}}(u||(u={})),window.Pi={ShutingYard:t,Numeric:e,Fraction:s,Root:m,Monom:n,Polynom:o,Equation:f,LinearSystem:_,Rational:g,Logicalset:d,Random:a,Geometry:{Vector:p,Point:y,Line:v,Triangle:w,Circle:x}}})();
|
|
2
2
|
//# sourceMappingURL=pi.js.map
|