pimath 0.0.25 → 0.0.29
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/dev/index.html +10 -7
- package/dev/pi.js +251 -98
- package/dev/pi.js.map +1 -1
- package/dist/pi.js +1 -1
- package/dist/pi.js.map +1 -1
- package/docs/assets/search.js +1 -1
- 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 +45 -44
- package/docs/classes/algebra.Polynom.html +9 -9
- package/docs/classes/algebra.Rational.html +2 -2
- package/docs/classes/coefficients.Fraction.html +6 -6
- package/docs/classes/coefficients.Nthroot.html +1 -1
- package/docs/classes/geometry.Circle.html +1 -1
- package/docs/classes/geometry.Line.html +2 -2
- package/docs/classes/geometry.Point.html +1 -1
- package/docs/classes/geometry.Triangle.html +5 -5
- 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.html +1 -1
- package/docs/modules/random.Random.html +1 -1
- package/docs/modules/random.html +1 -1
- package/esm/main.js +2 -0
- package/esm/main.js.map +1 -1
- package/esm/maths/algebra/logicalset.js +1 -1
- package/esm/maths/algebra/logicalset.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +2 -1
- package/esm/maths/algebra/monom.js +7 -1
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.js +1 -1
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +1 -1
- package/esm/maths/algebra/rational.js +2 -2
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/geometry/line.d.ts +1 -0
- package/esm/maths/geometry/line.js +3 -0
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/vector.js +7 -2
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/numexp.d.ts +16 -0
- package/esm/maths/numexp.js +119 -0
- package/esm/maths/numexp.js.map +1 -0
- package/esm/maths/shutingyard.d.ts +21 -4
- package/esm/maths/shutingyard.js +76 -76
- package/esm/maths/shutingyard.js.map +1 -1
- package/package.json +1 -1
- package/src/main.ts +2 -0
- package/src/maths/algebra/logicalset.ts +2 -2
- package/src/maths/algebra/monom.ts +35 -22
- package/src/maths/algebra/polynom.ts +1 -1
- package/src/maths/algebra/rational.ts +1 -1
- package/src/maths/geometry/line.ts +3 -0
- package/src/maths/geometry/vector.ts +10 -2
- package/src/maths/numexp.ts +138 -0
- package/src/maths/shutingyard.ts +94 -97
- package/tests/algebra/monom.test.ts +1 -1
- package/tests/algebra/polynom.test.ts +10 -1
- package/tests/numexp.test.ts +14 -0
- package/tests/shutingyard.test.ts +3 -3
- package/tsconfig.json +0 -1
- package/esm/docs.d.ts +0 -6
- package/esm/docs.js +0 -7
- package/esm/docs.js.map +0 -1
- package/esm/maths/random/random.d.ts +0 -13
- package/esm/maths/random/random.js +0 -27
- package/esm/maths/random/random.js.map +0 -1
package/dev/index.html
CHANGED
|
@@ -29,14 +29,18 @@
|
|
|
29
29
|
</head>
|
|
30
30
|
<body>
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
<template x-for="(item, index) of output" :key="index"
|
|
34
|
-
<div class="katex-left" x-html="`\\[${item}\\]`"></div
|
|
35
|
-
</template
|
|
36
|
-
|
|
32
|
+
<!--<div x-data="dev()">-->
|
|
33
|
+
<!-- <template x-for="(item, index) of output" :key="index">-->
|
|
34
|
+
<!-- <div class="katex-left" x-html="`\\[${item}\\]`"></div>-->
|
|
35
|
+
<!-- </template>-->
|
|
36
|
+
<!--</div>-->
|
|
37
37
|
|
|
38
38
|
<script>
|
|
39
|
-
|
|
39
|
+
// let ne = new Pi.NumExp('5/x*sin(x*x)')
|
|
40
|
+
let ne = new Pi.NumExp('5/x*sqrt(x^2)')
|
|
41
|
+
|
|
42
|
+
console.log(ne.rpn)
|
|
43
|
+
console.log(ne.evaluate({x: 0}))
|
|
40
44
|
|
|
41
45
|
function dev () {
|
|
42
46
|
let output = []
|
|
@@ -224,7 +228,6 @@
|
|
|
224
228
|
]
|
|
225
229
|
}
|
|
226
230
|
|
|
227
|
-
|
|
228
231
|
</script>
|
|
229
232
|
</body>
|
|
230
233
|
</html>
|
package/dev/pi.js
CHANGED
|
@@ -664,9 +664,6 @@ class LinearSystem {
|
|
|
664
664
|
}
|
|
665
665
|
return this;
|
|
666
666
|
}
|
|
667
|
-
get isLinearSystem() {
|
|
668
|
-
return true;
|
|
669
|
-
}
|
|
670
667
|
get equations() {
|
|
671
668
|
return this._equations;
|
|
672
669
|
}
|
|
@@ -881,7 +878,7 @@ class Logicalset {
|
|
|
881
878
|
}
|
|
882
879
|
;
|
|
883
880
|
parse = (value) => {
|
|
884
|
-
this._rpn = new shutingyard_1.Shutingyard(
|
|
881
|
+
this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.SET).parse(value).rpn;
|
|
885
882
|
return this;
|
|
886
883
|
};
|
|
887
884
|
evaluate(tokenSets, reference) {
|
|
@@ -1039,7 +1036,7 @@ class Monom {
|
|
|
1039
1036
|
return this._coefficient;
|
|
1040
1037
|
}
|
|
1041
1038
|
set coefficient(F) {
|
|
1042
|
-
this._coefficient = F;
|
|
1039
|
+
this._coefficient = new coefficients_1.Fraction(F);
|
|
1043
1040
|
}
|
|
1044
1041
|
get literal() {
|
|
1045
1042
|
return this._literal;
|
|
@@ -1178,6 +1175,12 @@ class Monom {
|
|
|
1178
1175
|
let d = this.display;
|
|
1179
1176
|
return (d[0] !== '-' ? '+' : '') + d;
|
|
1180
1177
|
}
|
|
1178
|
+
get texWithSign() {
|
|
1179
|
+
if (this.coefficient.isStrictlyPositive()) {
|
|
1180
|
+
return '+' + this.tex;
|
|
1181
|
+
}
|
|
1182
|
+
return this.tex;
|
|
1183
|
+
}
|
|
1181
1184
|
get tex() {
|
|
1182
1185
|
let L = '', letters = Object.keys(this._literal).sort();
|
|
1183
1186
|
for (let letter of letters) {
|
|
@@ -1906,7 +1909,7 @@ class Polynom {
|
|
|
1906
1909
|
const degreeP = P.degree(letter);
|
|
1907
1910
|
let newM;
|
|
1908
1911
|
let MaxIteration = this.degree(letter).clone().multiply(2);
|
|
1909
|
-
while (reminder.degree(letter)
|
|
1912
|
+
while (reminder.degree(letter).geq(degreeP) && MaxIteration.isPositive()) {
|
|
1910
1913
|
MaxIteration.subtract(1);
|
|
1911
1914
|
newM = reminder.monomByDegree(undefined, letter).clone().divide(maxMP);
|
|
1912
1915
|
if (newM.isZero()) {
|
|
@@ -2417,7 +2420,7 @@ exports.Polynom = Polynom;
|
|
|
2417
2420
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2418
2421
|
exports.Rational = void 0;
|
|
2419
2422
|
const polynom_1 = __webpack_require__(/*! ./polynom */ "./src/maths/algebra/polynom.ts");
|
|
2420
|
-
const
|
|
2423
|
+
const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
|
|
2421
2424
|
class Rational {
|
|
2422
2425
|
_rawString;
|
|
2423
2426
|
_numerator;
|
|
@@ -2516,7 +2519,7 @@ class Rational {
|
|
|
2516
2519
|
}
|
|
2517
2520
|
}
|
|
2518
2521
|
else {
|
|
2519
|
-
return this._numerator.evaluate({ letter: new
|
|
2522
|
+
return this._numerator.evaluate({ letter: new coefficients_1.Fraction(value) }).divide(this._denominator.evaluate({ letter: new coefficients_1.Fraction(value) }));
|
|
2520
2523
|
}
|
|
2521
2524
|
};
|
|
2522
2525
|
}
|
|
@@ -3513,6 +3516,9 @@ class Line {
|
|
|
3513
3516
|
isSameAs = (line) => {
|
|
3514
3517
|
return this.slope.isEqual(line.slope) && this.height.isEqual(line.height);
|
|
3515
3518
|
};
|
|
3519
|
+
isVertical = () => {
|
|
3520
|
+
return this.slope.isInfinity();
|
|
3521
|
+
};
|
|
3516
3522
|
simplify = () => {
|
|
3517
3523
|
let lcm = numeric_1.Numeric.lcm(this._a.denominator, this._b.denominator, this._c.denominator), gcd = numeric_1.Numeric.gcd(this._a.numerator, this._b.numerator, this._c.numerator);
|
|
3518
3524
|
this.parseByCoefficient(this._a.clone().multiply(lcm).divide(gcd), this._b.clone().multiply(lcm).divide(gcd), this._c.clone().multiply(lcm).divide(gcd));
|
|
@@ -4063,12 +4069,17 @@ class Vector {
|
|
|
4063
4069
|
this._y = values[1].y.clone().subtract(values[0].y);
|
|
4064
4070
|
return this;
|
|
4065
4071
|
}
|
|
4066
|
-
if (values[0].
|
|
4072
|
+
if (values[0] instanceof fraction_1.Fraction || !isNaN(values[0])) {
|
|
4067
4073
|
this._x = new fraction_1.Fraction(values[0]);
|
|
4068
4074
|
}
|
|
4069
|
-
if (values[1].
|
|
4075
|
+
if (values[1] instanceof fraction_1.Fraction || !isNaN(values[1])) {
|
|
4070
4076
|
this._y = new fraction_1.Fraction(values[1]);
|
|
4071
4077
|
}
|
|
4078
|
+
if ((typeof values[0] === 'object' && !isNaN(values[0].x) && !isNaN(values[0].x)) &&
|
|
4079
|
+
(typeof values[1] === 'object' && !isNaN(values[1].x) && !isNaN(values[1].x))) {
|
|
4080
|
+
this._x = new fraction_1.Fraction(+values[1].x - values[0].x);
|
|
4081
|
+
this._y = new fraction_1.Fraction(+values[1].y - values[0].y);
|
|
4082
|
+
}
|
|
4072
4083
|
}
|
|
4073
4084
|
return this;
|
|
4074
4085
|
};
|
|
@@ -4231,6 +4242,134 @@ class Numeric {
|
|
|
4231
4242
|
exports.Numeric = Numeric;
|
|
4232
4243
|
|
|
4233
4244
|
|
|
4245
|
+
/***/ }),
|
|
4246
|
+
|
|
4247
|
+
/***/ "./src/maths/numexp.ts":
|
|
4248
|
+
/*!*****************************!*\
|
|
4249
|
+
!*** ./src/maths/numexp.ts ***!
|
|
4250
|
+
\*****************************/
|
|
4251
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
4252
|
+
|
|
4253
|
+
|
|
4254
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4255
|
+
exports.NumExp = void 0;
|
|
4256
|
+
const shutingyard_1 = __webpack_require__(/*! ./shutingyard */ "./src/maths/shutingyard.ts");
|
|
4257
|
+
const coefficients_1 = __webpack_require__(/*! ./coefficients */ "./src/maths/coefficients/index.ts");
|
|
4258
|
+
class NumExp {
|
|
4259
|
+
_rpn;
|
|
4260
|
+
_expression;
|
|
4261
|
+
constructor(value) {
|
|
4262
|
+
this._expression = value;
|
|
4263
|
+
this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
|
|
4264
|
+
}
|
|
4265
|
+
get rpn() {
|
|
4266
|
+
return this._rpn;
|
|
4267
|
+
}
|
|
4268
|
+
get expression() {
|
|
4269
|
+
return this._expression;
|
|
4270
|
+
}
|
|
4271
|
+
_extractDecimalPart(value) {
|
|
4272
|
+
let decimal = value.toString();
|
|
4273
|
+
if (!decimal.includes('.')) {
|
|
4274
|
+
return '';
|
|
4275
|
+
}
|
|
4276
|
+
decimal = decimal.split('.')[1];
|
|
4277
|
+
return decimal.substring(0, decimal.length - 2);
|
|
4278
|
+
}
|
|
4279
|
+
_numberCorrection(value) {
|
|
4280
|
+
const epsilon = 0.00000000000001, number_of_digits = 6;
|
|
4281
|
+
let decimal = this._extractDecimalPart(value);
|
|
4282
|
+
if (decimal === '') {
|
|
4283
|
+
return value;
|
|
4284
|
+
}
|
|
4285
|
+
const n9 = decimal.match(/9+$/g);
|
|
4286
|
+
const n0 = decimal.match(/0+$/g);
|
|
4287
|
+
if (n9 && n9[0].length >= number_of_digits) {
|
|
4288
|
+
let mod = this._extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
|
|
4289
|
+
if (mod0 && mod0[0].length >= number_of_digits) {
|
|
4290
|
+
return +((value + epsilon).toString().split(mod0[0])[0]);
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
if (n0 && n0[0].length >= number_of_digits) {
|
|
4294
|
+
let mod = this._extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
|
|
4295
|
+
if (mod9 && mod9[0].length >= number_of_digits) {
|
|
4296
|
+
return +(value.toString().split(n0[0])[0]);
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
return value;
|
|
4300
|
+
}
|
|
4301
|
+
_addToStack(stack, value) {
|
|
4302
|
+
stack.push(this._numberCorrection(value));
|
|
4303
|
+
}
|
|
4304
|
+
evaluate(values) {
|
|
4305
|
+
let stack = [];
|
|
4306
|
+
for (const element of this._rpn) {
|
|
4307
|
+
if (element.tokenType === shutingyard_1.ShutingyardType.COEFFICIENT) {
|
|
4308
|
+
if (!isNaN(+element.token)) {
|
|
4309
|
+
this._addToStack(stack, +element.token);
|
|
4310
|
+
}
|
|
4311
|
+
else {
|
|
4312
|
+
this._addToStack(stack, new coefficients_1.Fraction(element.token).value);
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4315
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.VARIABLE) {
|
|
4316
|
+
if (values[element.token] !== undefined) {
|
|
4317
|
+
this._addToStack(stack, +values[element.token]);
|
|
4318
|
+
}
|
|
4319
|
+
}
|
|
4320
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.CONSTANT) {
|
|
4321
|
+
this._addToStack(stack, shutingyard_1.tokenConstant[element.token]);
|
|
4322
|
+
}
|
|
4323
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.OPERATION) {
|
|
4324
|
+
if (element.token === '*') {
|
|
4325
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4326
|
+
this._addToStack(stack, a * b);
|
|
4327
|
+
}
|
|
4328
|
+
else if (element.token === '/') {
|
|
4329
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4330
|
+
this._addToStack(stack, a / b);
|
|
4331
|
+
}
|
|
4332
|
+
else if (element.token === '+') {
|
|
4333
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4334
|
+
this._addToStack(stack, a + b);
|
|
4335
|
+
}
|
|
4336
|
+
else if (element.token === '-') {
|
|
4337
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4338
|
+
this._addToStack(stack, a - b);
|
|
4339
|
+
}
|
|
4340
|
+
else if (element.token === '^') {
|
|
4341
|
+
const b = +stack.pop(), a = +stack.pop();
|
|
4342
|
+
this._addToStack(stack, Math.pow(a, b));
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
else if (element.tokenType === shutingyard_1.ShutingyardType.FUNCTION) {
|
|
4346
|
+
const a = +stack.pop();
|
|
4347
|
+
if (element.token === 'sin') {
|
|
4348
|
+
this._addToStack(stack, Math.sin(a));
|
|
4349
|
+
}
|
|
4350
|
+
else if (element.token === 'cos') {
|
|
4351
|
+
this._addToStack(stack, Math.cos(a));
|
|
4352
|
+
}
|
|
4353
|
+
else if (element.token === 'tan') {
|
|
4354
|
+
this._addToStack(stack, Math.tan(a));
|
|
4355
|
+
}
|
|
4356
|
+
else if (element.token === 'sqrt') {
|
|
4357
|
+
this._addToStack(stack, Math.sqrt(a));
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4361
|
+
if (stack.length === 1) {
|
|
4362
|
+
return stack[0];
|
|
4363
|
+
}
|
|
4364
|
+
else {
|
|
4365
|
+
console.error('There was a problem parsing', this._expression, '. The RPN array is', this._rpn);
|
|
4366
|
+
return 0;
|
|
4367
|
+
}
|
|
4368
|
+
}
|
|
4369
|
+
}
|
|
4370
|
+
exports.NumExp = NumExp;
|
|
4371
|
+
|
|
4372
|
+
|
|
4234
4373
|
/***/ }),
|
|
4235
4374
|
|
|
4236
4375
|
/***/ "./src/maths/random/index.ts":
|
|
@@ -4348,6 +4487,7 @@ class rndFraction extends randomCore_1.randomCore {
|
|
|
4348
4487
|
super();
|
|
4349
4488
|
this._defaultConfig = {
|
|
4350
4489
|
negative: true,
|
|
4490
|
+
max: 10,
|
|
4351
4491
|
reduced: true,
|
|
4352
4492
|
zero: true,
|
|
4353
4493
|
natural: false
|
|
@@ -4357,16 +4497,16 @@ class rndFraction extends randomCore_1.randomCore {
|
|
|
4357
4497
|
generate = () => {
|
|
4358
4498
|
let Q = new coefficients_1.Fraction();
|
|
4359
4499
|
if (this._config.negative) {
|
|
4360
|
-
Q.numerator = index_1.Random.numberSym(
|
|
4500
|
+
Q.numerator = index_1.Random.numberSym(this._config.max, this._config.zero);
|
|
4361
4501
|
}
|
|
4362
4502
|
else {
|
|
4363
|
-
Q.numerator = index_1.Random.number(this._config.zero ? 0 : 1,
|
|
4503
|
+
Q.numerator = index_1.Random.number(this._config.zero ? 0 : 1, this._config.max);
|
|
4364
4504
|
}
|
|
4365
4505
|
if (this._config.natural) {
|
|
4366
4506
|
Q.denominator = 1;
|
|
4367
4507
|
}
|
|
4368
4508
|
else {
|
|
4369
|
-
Q.denominator = index_1.Random.number(1,
|
|
4509
|
+
Q.denominator = index_1.Random.number(1, this._config.max);
|
|
4370
4510
|
}
|
|
4371
4511
|
return this._config.reduced ? Q.reduce() : Q;
|
|
4372
4512
|
};
|
|
@@ -4445,7 +4585,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
4445
4585
|
exports.rndMonom = void 0;
|
|
4446
4586
|
const randomCore_1 = __webpack_require__(/*! ./randomCore */ "./src/maths/random/randomCore.ts");
|
|
4447
4587
|
const index_1 = __webpack_require__(/*! ./index */ "./src/maths/random/index.ts");
|
|
4448
|
-
const
|
|
4588
|
+
const algebra_1 = __webpack_require__(/*! ../algebra */ "./src/maths/algebra/index.ts");
|
|
4449
4589
|
class rndMonom extends randomCore_1.randomCore {
|
|
4450
4590
|
constructor(userConfig) {
|
|
4451
4591
|
super();
|
|
@@ -4458,12 +4598,17 @@ class rndMonom extends randomCore_1.randomCore {
|
|
|
4458
4598
|
this._config = this.mergeConfig(userConfig, this._defaultConfig);
|
|
4459
4599
|
}
|
|
4460
4600
|
generate = () => {
|
|
4461
|
-
let M = new
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4601
|
+
let M = new algebra_1.Monom();
|
|
4602
|
+
if (typeof this._config.fraction === "boolean") {
|
|
4603
|
+
M.coefficient = index_1.Random.fraction({
|
|
4604
|
+
zero: this._config.zero,
|
|
4605
|
+
reduced: true,
|
|
4606
|
+
natural: !this._config.fraction
|
|
4607
|
+
});
|
|
4608
|
+
}
|
|
4609
|
+
else {
|
|
4610
|
+
M.coefficient = index_1.Random.fraction(this._config.fraction);
|
|
4611
|
+
}
|
|
4467
4612
|
if (this._config.letters.length > 1) {
|
|
4468
4613
|
for (let L of this._config.letters.split('')) {
|
|
4469
4614
|
M.setLetter(L, 0);
|
|
@@ -4508,7 +4653,8 @@ class rndPolynom extends randomCore_1.randomCore {
|
|
|
4508
4653
|
unit: false,
|
|
4509
4654
|
factorable: false,
|
|
4510
4655
|
allowNullMonom: true,
|
|
4511
|
-
numberOfMonoms: 0
|
|
4656
|
+
numberOfMonoms: 0,
|
|
4657
|
+
positive: true
|
|
4512
4658
|
};
|
|
4513
4659
|
this._config = this.mergeConfig(userConfig, this._defaultConfig);
|
|
4514
4660
|
}
|
|
@@ -4529,8 +4675,13 @@ class rndPolynom extends randomCore_1.randomCore {
|
|
|
4529
4675
|
}
|
|
4530
4676
|
P.add(M);
|
|
4531
4677
|
}
|
|
4678
|
+
if (this._config.positive && P.monomByDegree().coefficient.isNegative()) {
|
|
4679
|
+
P.monomByDegree().coefficient.opposed();
|
|
4680
|
+
}
|
|
4532
4681
|
if (this._config.numberOfMonoms > 0 && this._config.numberOfMonoms < P.length) {
|
|
4533
|
-
|
|
4682
|
+
let M = P.monomByDegree().clone();
|
|
4683
|
+
P.monoms = index_1.Random.array(P.monoms.slice(1), this._config.numberOfMonoms - 1);
|
|
4684
|
+
P.add(M).reorder().reduce();
|
|
4534
4685
|
}
|
|
4535
4686
|
return P;
|
|
4536
4687
|
};
|
|
@@ -4570,49 +4721,80 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
4570
4721
|
|
|
4571
4722
|
|
|
4572
4723
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4573
|
-
exports.Shutingyard = void 0;
|
|
4724
|
+
exports.Shutingyard = exports.ShutingyardMode = exports.ShutingyardType = exports.tokenConstant = void 0;
|
|
4725
|
+
exports.tokenConstant = {
|
|
4726
|
+
pi: Math.PI,
|
|
4727
|
+
e: Math.exp(1)
|
|
4728
|
+
};
|
|
4729
|
+
var ShutingyardType;
|
|
4730
|
+
(function (ShutingyardType) {
|
|
4731
|
+
ShutingyardType["VARIABLE"] = "variable";
|
|
4732
|
+
ShutingyardType["COEFFICIENT"] = "coefficient";
|
|
4733
|
+
ShutingyardType["OPERATION"] = "operation";
|
|
4734
|
+
ShutingyardType["CONSTANT"] = "constant";
|
|
4735
|
+
ShutingyardType["FUNCTION"] = "function";
|
|
4736
|
+
ShutingyardType["MONOM"] = "monom";
|
|
4737
|
+
})(ShutingyardType = exports.ShutingyardType || (exports.ShutingyardType = {}));
|
|
4738
|
+
var ShutingyardMode;
|
|
4739
|
+
(function (ShutingyardMode) {
|
|
4740
|
+
ShutingyardMode["POLYNOM"] = "polynom";
|
|
4741
|
+
ShutingyardMode["SET"] = "set";
|
|
4742
|
+
ShutingyardMode["NUMERIC"] = "numeric";
|
|
4743
|
+
})(ShutingyardMode = exports.ShutingyardMode || (exports.ShutingyardMode = {}));
|
|
4574
4744
|
class Shutingyard {
|
|
4575
4745
|
_rpn = [];
|
|
4576
4746
|
_mode;
|
|
4577
4747
|
_tokenConfig;
|
|
4748
|
+
_tokenConstant;
|
|
4578
4749
|
_uniformize;
|
|
4750
|
+
_tokenKeys;
|
|
4579
4751
|
constructor(mode) {
|
|
4580
|
-
this._mode = typeof mode === 'undefined' ?
|
|
4752
|
+
this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
|
|
4581
4753
|
this.tokenConfigInitialization();
|
|
4582
4754
|
}
|
|
4583
|
-
isOperation(token) {
|
|
4584
|
-
if (token[0].match(/[+\-*/^]/g)) {
|
|
4585
|
-
return true;
|
|
4586
|
-
}
|
|
4587
|
-
return false;
|
|
4588
|
-
}
|
|
4589
4755
|
tokenConfigInitialization() {
|
|
4590
|
-
if (this._mode ===
|
|
4756
|
+
if (this._mode === ShutingyardMode.SET) {
|
|
4757
|
+
this._tokenConfig = {
|
|
4758
|
+
'&': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4759
|
+
'|': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4760
|
+
'!': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4761
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION }
|
|
4762
|
+
};
|
|
4763
|
+
this._uniformize = false;
|
|
4764
|
+
}
|
|
4765
|
+
else if (this._mode === ShutingyardMode.NUMERIC) {
|
|
4591
4766
|
this._tokenConfig = {
|
|
4592
|
-
'
|
|
4593
|
-
'
|
|
4594
|
-
'
|
|
4595
|
-
'
|
|
4767
|
+
'^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4768
|
+
'*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4769
|
+
'/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4770
|
+
'+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4771
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4772
|
+
'%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4773
|
+
'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4774
|
+
'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4775
|
+
'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4776
|
+
'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4596
4777
|
};
|
|
4597
4778
|
this._uniformize = false;
|
|
4598
4779
|
}
|
|
4599
4780
|
else {
|
|
4600
4781
|
this._tokenConfig = {
|
|
4601
|
-
'^': { precedence: 4, associative: 'right' },
|
|
4602
|
-
'*': { precedence: 3, associative: 'left' },
|
|
4603
|
-
'/': { precedence: 3, associative: 'left' },
|
|
4604
|
-
'+': { precedence: 2, associative: 'left' },
|
|
4605
|
-
'-': { precedence: 2, associative: 'left' },
|
|
4606
|
-
'%': { precedence: 3, associative: 'right' },
|
|
4607
|
-
'sin': { precedence: 4, associative: 'right' },
|
|
4608
|
-
'cos': { precedence: 4, associative: 'right' },
|
|
4609
|
-
'
|
|
4782
|
+
'^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4783
|
+
'*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4784
|
+
'/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4785
|
+
'+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4786
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
4787
|
+
'%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
|
|
4788
|
+
'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4789
|
+
'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4790
|
+
'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
4610
4791
|
};
|
|
4611
4792
|
this._uniformize = true;
|
|
4612
4793
|
}
|
|
4794
|
+
this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length);
|
|
4613
4795
|
return this._tokenConfig;
|
|
4614
4796
|
}
|
|
4615
|
-
|
|
4797
|
+
NextToken(expr, start) {
|
|
4616
4798
|
let token, tokenType;
|
|
4617
4799
|
token = '';
|
|
4618
4800
|
tokenType = '';
|
|
@@ -4629,75 +4811,43 @@ class Shutingyard {
|
|
|
4629
4811
|
tokenType = 'function-argument';
|
|
4630
4812
|
}
|
|
4631
4813
|
else {
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
if (expr.substr(start, key.length) === key) {
|
|
4814
|
+
for (let key of this._tokenKeys) {
|
|
4815
|
+
if (expr.substring(start, start + key.length) === key) {
|
|
4635
4816
|
token += key;
|
|
4636
|
-
tokenType =
|
|
4817
|
+
tokenType = this._tokenConfig[key].type;
|
|
4818
|
+
break;
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
for (let key in exports.tokenConstant) {
|
|
4822
|
+
if (expr.substring(start, start + key.length) === key) {
|
|
4823
|
+
token += key;
|
|
4824
|
+
tokenType = ShutingyardType.CONSTANT;
|
|
4637
4825
|
break;
|
|
4638
4826
|
}
|
|
4639
4827
|
}
|
|
4640
4828
|
if (token === '') {
|
|
4641
4829
|
if (expr[start].match(/[0-9]/)) {
|
|
4642
|
-
|
|
4643
|
-
|
|
4830
|
+
if (this._mode === ShutingyardMode.POLYNOM) {
|
|
4831
|
+
token = expr.substring(start).match(/^([0-9.,/]+)/)[0];
|
|
4832
|
+
}
|
|
4833
|
+
else {
|
|
4834
|
+
token = expr.substring(start).match(/^([0-9.,]+)/)[0];
|
|
4835
|
+
}
|
|
4836
|
+
tokenType = ShutingyardType.COEFFICIENT;
|
|
4644
4837
|
}
|
|
4645
4838
|
else if (expr[start].match(/[a-zA-Z]/)) {
|
|
4646
|
-
token = expr.
|
|
4647
|
-
tokenType =
|
|
4839
|
+
token = expr.substring(start).match(/^([a-zA-Z])/)[0];
|
|
4840
|
+
tokenType = ShutingyardType.VARIABLE;
|
|
4648
4841
|
}
|
|
4649
4842
|
else {
|
|
4650
4843
|
console.log('Unidentified token', expr[start], expr, start);
|
|
4651
4844
|
token = expr[start];
|
|
4652
|
-
tokenType =
|
|
4845
|
+
tokenType = ShutingyardType.MONOM;
|
|
4653
4846
|
}
|
|
4654
4847
|
}
|
|
4655
4848
|
}
|
|
4656
4849
|
return [token, start + token.length, tokenType];
|
|
4657
4850
|
}
|
|
4658
|
-
NextToken(expr, start) {
|
|
4659
|
-
let tokenMatch, token, tokenType;
|
|
4660
|
-
this.NextToken2(expr, start);
|
|
4661
|
-
tokenMatch = (expr.substr(start).match(/^[0-9/a-zA-Z^]+/g)) || [];
|
|
4662
|
-
if (expr.substr(start, start + 3).match(/^(sin|cos|tan)/g)) {
|
|
4663
|
-
token = expr.substr(start, 3);
|
|
4664
|
-
tokenType = 'function';
|
|
4665
|
-
}
|
|
4666
|
-
else if (tokenMatch.length > 0) {
|
|
4667
|
-
token = tokenMatch[0];
|
|
4668
|
-
tokenType = 'monom';
|
|
4669
|
-
}
|
|
4670
|
-
else if (expr[start].match(/[+\-*/^]/g)) {
|
|
4671
|
-
token = expr[start];
|
|
4672
|
-
tokenType = 'operation';
|
|
4673
|
-
}
|
|
4674
|
-
else if (expr[start].match(/[&|!]/g)) {
|
|
4675
|
-
token = expr[start];
|
|
4676
|
-
tokenType = 'operation';
|
|
4677
|
-
}
|
|
4678
|
-
else if (expr[start] === '(') {
|
|
4679
|
-
token = '(';
|
|
4680
|
-
tokenType = '(';
|
|
4681
|
-
}
|
|
4682
|
-
else if (expr[start] === ')') {
|
|
4683
|
-
token = ')';
|
|
4684
|
-
tokenType = ')';
|
|
4685
|
-
}
|
|
4686
|
-
else if (expr[start] === ',') {
|
|
4687
|
-
token = ',';
|
|
4688
|
-
tokenType = 'function-argument';
|
|
4689
|
-
}
|
|
4690
|
-
else {
|
|
4691
|
-
token = tokenMatch[0];
|
|
4692
|
-
tokenType = 'monom';
|
|
4693
|
-
if (token === '') {
|
|
4694
|
-
token = expr[start];
|
|
4695
|
-
tokenType = 'monom';
|
|
4696
|
-
console.log('SHUTING YARD - NEXT TOKEN: error at ', start);
|
|
4697
|
-
}
|
|
4698
|
-
}
|
|
4699
|
-
return [token, start + token.length, tokenType];
|
|
4700
|
-
}
|
|
4701
4851
|
Uniformizer(expr) {
|
|
4702
4852
|
if (!this._uniformize) {
|
|
4703
4853
|
return expr;
|
|
@@ -4725,11 +4875,12 @@ class Shutingyard {
|
|
|
4725
4875
|
console.log('SECURITY LEVEL 1 EXIT');
|
|
4726
4876
|
break;
|
|
4727
4877
|
}
|
|
4728
|
-
[token, tokenPos, tokenType] = this.
|
|
4878
|
+
[token, tokenPos, tokenType] = this.NextToken(expr, tokenPos);
|
|
4729
4879
|
switch (tokenType) {
|
|
4730
4880
|
case 'monom':
|
|
4731
4881
|
case 'coefficient':
|
|
4732
4882
|
case 'variable':
|
|
4883
|
+
case 'constant':
|
|
4733
4884
|
outQueue.push({
|
|
4734
4885
|
token,
|
|
4735
4886
|
tokenType
|
|
@@ -4842,6 +4993,7 @@ var exports = __webpack_exports__;
|
|
|
4842
4993
|
|
|
4843
4994
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4844
4995
|
const numeric_1 = __webpack_require__(/*! ./maths/numeric */ "./src/maths/numeric.ts");
|
|
4996
|
+
const numexp_1 = __webpack_require__(/*! ./maths/numexp */ "./src/maths/numexp.ts");
|
|
4845
4997
|
const shutingyard_1 = __webpack_require__(/*! ./maths/shutingyard */ "./src/maths/shutingyard.ts");
|
|
4846
4998
|
const random_1 = __webpack_require__(/*! ./maths/random */ "./src/maths/random/index.ts");
|
|
4847
4999
|
const coefficients_1 = __webpack_require__(/*! ./maths/coefficients */ "./src/maths/coefficients/index.ts");
|
|
@@ -4850,6 +5002,7 @@ const geometry_1 = __webpack_require__(/*! ./maths/geometry */ "./src/maths/geom
|
|
|
4850
5002
|
window.Pi = {
|
|
4851
5003
|
ShutingYard: shutingyard_1.Shutingyard,
|
|
4852
5004
|
Numeric: numeric_1.Numeric,
|
|
5005
|
+
NumExp: numexp_1.NumExp,
|
|
4853
5006
|
Fraction: coefficients_1.Fraction,
|
|
4854
5007
|
Root: coefficients_1.Nthroot,
|
|
4855
5008
|
Monom: algebra_1.Monom,
|