pimath 0.0.128 → 0.0.130
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/main.d.ts +39 -0
- package/dist/maths/algebra/equation.d.ts +120 -0
- package/dist/maths/algebra/linearSystem.d.ts +40 -0
- package/dist/maths/algebra/logicalset.d.ts +28 -0
- package/dist/maths/algebra/monom.d.ts +207 -0
- package/dist/maths/algebra/polynom.d.ts +155 -0
- package/dist/maths/algebra/rational.d.ts +44 -0
- package/dist/maths/algebra/study/rationalStudy.d.ts +14 -0
- package/dist/maths/algebra/study.d.ts +140 -0
- package/dist/maths/coefficients/fraction.d.ts +90 -0
- package/dist/maths/coefficients/nthRoot.d.ts +23 -0
- package/dist/maths/geometry/circle.d.ts +46 -0
- package/dist/maths/geometry/line.d.ts +102 -0
- package/dist/maths/geometry/point.d.ts +36 -0
- package/dist/maths/geometry/triangle.d.ts +92 -0
- package/dist/maths/geometry/vector.d.ts +38 -0
- package/dist/maths/numeric.d.ts +28 -0
- package/dist/maths/numexp.d.ts +19 -0
- package/dist/maths/randomization/random.d.ts +26 -0
- package/dist/maths/randomization/randomCore.d.ts +7 -0
- package/dist/maths/randomization/rndFraction.d.ts +13 -0
- package/dist/maths/randomization/rndGeometryCircle.d.ts +13 -0
- package/dist/maths/randomization/rndGeometryLine.d.ts +13 -0
- package/dist/maths/randomization/rndGeometryPoint.d.ts +13 -0
- package/dist/maths/randomization/rndHelpers.d.ts +23 -0
- package/dist/maths/randomization/rndMonom.d.ts +13 -0
- package/dist/maths/randomization/rndPolynom.d.ts +14 -0
- package/dist/maths/randomization/rndTypes.d.ts +40 -0
- package/dist/maths/shutingyard.d.ts +59 -0
- package/dist/pimath.js +85 -85
- package/lib/main.ts +42 -0
- package/{src → lib}/maths/algebra/equation.ts +52 -58
- package/{src → lib}/maths/algebra/linearSystem.ts +5 -6
- package/lib/maths/algebra/logicalset.ts +183 -0
- package/{src → lib}/maths/algebra/monom.ts +7 -8
- package/{src → lib}/maths/algebra/polynom.ts +2 -2
- package/{src → lib}/maths/algebra/study.ts +9 -9
- package/{src → lib}/maths/coefficients/fraction.ts +4 -4
- package/{src → lib}/maths/geometry/circle.ts +6 -9
- package/{src → lib}/maths/geometry/line.ts +1 -1
- package/{src → lib}/maths/geometry/vector.ts +35 -34
- package/{src → lib}/maths/numexp.ts +91 -77
- package/{src → lib}/maths/randomization/rndHelpers.ts +1 -1
- package/{src → lib}/maths/randomization/rndMonom.ts +13 -13
- package/{src → lib}/maths/randomization/rndPolynom.ts +24 -24
- package/package.json +11 -12
- package/.eslintrc.js +0 -24
- package/.idea/$CACHE_FILE$ +0 -6
- package/.idea/PI.iml +0 -14
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -19
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +0 -192
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +0 -2404
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +0 -1362
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +0 -90
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +0 -4
- package/.idea/vcs.xml +0 -6
- package/dist/demo/exercises.html +0 -283
- package/dist/demo/matrices.html +0 -39
- package/dist/demo/playground.html +0 -20
- package/dist/demo.css +0 -3
- package/dist/pimath.umd.cjs +0 -15
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -78
- package/docs/assets/main.js +0 -59
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1383
- package/docs/classes/Logicalset.Logicalset.html +0 -217
- package/docs/classes/Polynom.Rational.html +0 -397
- package/docs/classes/Vector-1.Vector.html +0 -490
- package/docs/classes/Vector.Point.html +0 -337
- package/docs/classes/algebra_equation.Equation.html +0 -790
- package/docs/classes/algebra_linearSystem.LinearSystem.html +0 -404
- package/docs/classes/algebra_monom.Monom.html +0 -962
- package/docs/classes/algebra_polynom.Polynom.html +0 -1275
- package/docs/classes/coefficients_fraction.Fraction.html +0 -934
- package/docs/classes/geometry_circle.Circle.html +0 -472
- package/docs/classes/geometry_line.Line.html +0 -774
- package/docs/classes/geometry_triangle.Triangle.html +0 -429
- package/docs/classes/numeric.Numeric.html +0 -265
- package/docs/classes/shutingyard.Shutingyard.html +0 -250
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +0 -83
- package/docs/enums/geometry_line.LinePropriety.html +0 -97
- package/docs/enums/shutingyard.ShutingyardMode.html +0 -97
- package/docs/enums/shutingyard.ShutingyardType.html +0 -111
- package/docs/index.html +0 -63
- package/docs/interfaces/algebra_equation.ISolution.html +0 -105
- package/docs/interfaces/algebra_polynom.IEuclidian.html +0 -87
- package/docs/interfaces/geometry_triangle.remarquableLines.html +0 -163
- package/docs/modules/Logicalset.html +0 -65
- package/docs/modules/Polynom.html +0 -65
- package/docs/modules/Vector-1.html +0 -65
- package/docs/modules/Vector.html +0 -65
- package/docs/modules/algebra_equation.html +0 -69
- package/docs/modules/algebra_linearSystem.html +0 -61
- package/docs/modules/algebra_monom.html +0 -65
- package/docs/modules/algebra_polynom.html +0 -69
- package/docs/modules/coefficients_fraction.html +0 -65
- package/docs/modules/geometry_circle.html +0 -61
- package/docs/modules/geometry_line.html +0 -65
- package/docs/modules/geometry_triangle.html +0 -65
- package/docs/modules/numeric.html +0 -61
- package/docs/modules/shutingyard.html +0 -75
- package/docs/types/algebra_monom.literalType.html +0 -61
- package/docs/types/algebra_polynom.PolynomParsingType.html +0 -56
- package/docs/types/coefficients_fraction.FractionParsingType.html +0 -56
- package/docs/types/shutingyard.Token.html +0 -63
- package/docs/types/shutingyard.tokenType.html +0 -68
- package/docs/variables/shutingyard.tokenConstant.html +0 -61
- package/index.html +0 -15
- package/public/demo/exercises.html +0 -283
- package/public/demo/matrices.html +0 -39
- package/public/demo/playground.html +0 -20
- package/public/demo.css +0 -3
- package/src/demo/exercises.ts +0 -0
- package/src/demo/matrices.ts +0 -61
- package/src/demo/playground.ts +0 -153
- package/src/main.ts +0 -42
- package/src/maths/algebra/logicalset.ts +0 -183
- package/tests/algebra/equation.test.ts +0 -64
- package/tests/algebra/linear.test.ts +0 -58
- package/tests/algebra/monom.test.ts +0 -78
- package/tests/algebra/polynom.test.ts +0 -343
- package/tests/algebra/rationnal.test.ts +0 -64
- package/tests/algebra/study.test.ts +0 -48
- package/tests/coefficients/fraction.test.ts +0 -131
- package/tests/custom.test.ts +0 -33
- package/tests/geometry/circle.test.ts +0 -404
- package/tests/geometry/line.test.ts +0 -36
- package/tests/numeric.test.ts +0 -43
- package/tests/numexp.test.ts +0 -89
- package/tests/shutingyard.test.ts +0 -58
- package/tsconfig.json +0 -52
- package/tsconfig.testing.json +0 -28
- package/typedoc.katex.js +0 -11
- package/vite.config.js +0 -23
- package/webpack-production-min.config.js +0 -26
- package/webpack-production.config.js +0 -26
- package/webpack.config.js +0 -26
- /package/{src → lib}/maths/algebra/rational.ts +0 -0
- /package/{src → lib}/maths/algebra/study/rationalStudy.ts +0 -0
- /package/{src → lib}/maths/coefficients/nthRoot.ts +0 -0
- /package/{src → lib}/maths/geometry/point.ts +0 -0
- /package/{src → lib}/maths/geometry/triangle.ts +0 -0
- /package/{src → lib}/maths/numeric.ts +0 -0
- /package/{src → lib}/maths/randomization/random.ts +0 -0
- /package/{src → lib}/maths/randomization/randomCore.ts +0 -0
- /package/{src → lib}/maths/randomization/rndFraction.ts +0 -0
- /package/{src → lib}/maths/randomization/rndGeometryCircle.ts +0 -0
- /package/{src → lib}/maths/randomization/rndGeometryLine.ts +0 -0
- /package/{src → lib}/maths/randomization/rndGeometryPoint.ts +0 -0
- /package/{src → lib}/maths/randomization/rndTypes.ts +0 -0
- /package/{src → lib}/maths/shutingyard.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Polynom} from "./polynom";
|
|
2
2
|
import {literalType, Monom} from "./monom";
|
|
3
|
-
import {Numeric} from "../numeric";
|
|
3
|
+
import {Numeric} from "../numeric.ts";
|
|
4
4
|
import {Fraction} from "../coefficients/fraction";
|
|
5
5
|
import {NthRoot} from "../coefficients/nthRoot";
|
|
6
6
|
|
|
@@ -15,8 +15,8 @@ export interface ISolution {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export enum PARTICULAR_SOLUTION {
|
|
18
|
-
real="\\mathbb{R}",
|
|
19
|
-
varnothing="\\varnothing"
|
|
18
|
+
real = "\\mathbb{R}",
|
|
19
|
+
varnothing = "\\varnothing"
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class Equation {
|
|
@@ -25,6 +25,14 @@ export class Equation {
|
|
|
25
25
|
// Undetermined texSolutions.
|
|
26
26
|
private _varnothing: string = PARTICULAR_SOLUTION.varnothing;
|
|
27
27
|
private _real: string = PARTICULAR_SOLUTION.real;
|
|
28
|
+
private _left: Polynom; // Left part of the equation
|
|
29
|
+
private _right: Polynom; // Right part of the equation
|
|
30
|
+
private _sign: string; // Signe of the equation, by default =
|
|
31
|
+
private _solutions: ISolution[]
|
|
32
|
+
// -----------------------------------------------
|
|
33
|
+
private _randomizeDefaults: { [key: string]: number | string | boolean } = {
|
|
34
|
+
degree: 2
|
|
35
|
+
};
|
|
28
36
|
|
|
29
37
|
/**
|
|
30
38
|
* Create an Equation using two polynoms.
|
|
@@ -63,7 +71,8 @@ export class Equation {
|
|
|
63
71
|
return this;
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
|
|
74
|
+
// ------------------------------------------
|
|
75
|
+
// Getter and setter
|
|
67
76
|
|
|
68
77
|
get left(): Polynom {
|
|
69
78
|
return this._left;
|
|
@@ -73,21 +82,14 @@ export class Equation {
|
|
|
73
82
|
this._left = value;
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
private _right: Polynom; // Right part of the equation
|
|
77
|
-
|
|
78
85
|
get right(): Polynom {
|
|
79
86
|
return this._right;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
// ------------------------------------------
|
|
83
|
-
// Getter and setter
|
|
84
|
-
|
|
85
89
|
set right(value: Polynom) {
|
|
86
90
|
this._right = value;
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
private _sign: string; // Signe of the equation, by default =
|
|
90
|
-
|
|
91
93
|
get sign(): string {
|
|
92
94
|
return this._sign;
|
|
93
95
|
}
|
|
@@ -97,8 +99,6 @@ export class Equation {
|
|
|
97
99
|
this._sign = this._formatSign(value);
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
private _solutions: ISolution[]
|
|
101
|
-
|
|
102
102
|
// ------------------------------------------
|
|
103
103
|
get solutions(): ISolution[] {
|
|
104
104
|
return this._solutions
|
|
@@ -166,18 +166,9 @@ export class Equation {
|
|
|
166
166
|
return this.variables.length;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
hasVariable = (letter: string): boolean => {
|
|
170
|
-
return this.variables.includes(letter)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
169
|
// ------------------------------------------
|
|
174
170
|
// Creation / parsing functions
|
|
175
171
|
|
|
176
|
-
// -----------------------------------------------
|
|
177
|
-
private _randomizeDefaults: { [key: string]: number | string | boolean } = {
|
|
178
|
-
degree: 2
|
|
179
|
-
};
|
|
180
|
-
|
|
181
172
|
get randomizeDefaults(): { [key: string]: number | string | boolean } {
|
|
182
173
|
return this._randomizeDefaults;
|
|
183
174
|
}
|
|
@@ -186,6 +177,27 @@ export class Equation {
|
|
|
186
177
|
this._randomizeDefaults = value;
|
|
187
178
|
}
|
|
188
179
|
|
|
180
|
+
static makeSolutionsUnique(solutions: ISolution[], sorted?: boolean): ISolution[] {
|
|
181
|
+
let solutionAsTex: string[] = [],
|
|
182
|
+
uniqueSolutions = solutions.filter(sol => {
|
|
183
|
+
if (!solutionAsTex.includes(sol.tex)) {
|
|
184
|
+
solutionAsTex.push(sol.tex)
|
|
185
|
+
return true
|
|
186
|
+
} else {
|
|
187
|
+
return false
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
if (sorted === true) {
|
|
192
|
+
uniqueSolutions.sort((a, b) => a.value - b.value)
|
|
193
|
+
}
|
|
194
|
+
return uniqueSolutions
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
hasVariable = (letter: string): boolean => {
|
|
198
|
+
return this.variables.includes(letter)
|
|
199
|
+
}
|
|
200
|
+
|
|
189
201
|
// ------------------------------------------
|
|
190
202
|
parse = (equationString: string): Equation => {
|
|
191
203
|
let pStr: string[], strSign: string | false;
|
|
@@ -210,13 +222,13 @@ export class Equation {
|
|
|
210
222
|
return this;
|
|
211
223
|
};
|
|
212
224
|
|
|
225
|
+
// -----------------------------------------------
|
|
226
|
+
// Equations generators and randomizers
|
|
227
|
+
|
|
213
228
|
clone = (): Equation => {
|
|
214
229
|
return new Equation().create(this._left.clone(), this._right.clone(), this._sign + '');
|
|
215
230
|
};
|
|
216
231
|
|
|
217
|
-
// -----------------------------------------------
|
|
218
|
-
// Equations generators and randomizers
|
|
219
|
-
|
|
220
232
|
randomize = (opts?: {}, sign?: string): Equation => {
|
|
221
233
|
// TODO: Generate equations randomly, using config.
|
|
222
234
|
return new Equation().create(new Polynom(), new Polynom(), sign);
|
|
@@ -244,8 +256,8 @@ export class Equation {
|
|
|
244
256
|
|
|
245
257
|
// Fetch all zero degree monoms.
|
|
246
258
|
this._left.monoms
|
|
247
|
-
.filter(m=>m.degree().isZero())
|
|
248
|
-
.forEach(m=> {
|
|
259
|
+
.filter(m => m.degree().isZero())
|
|
260
|
+
.forEach(m => {
|
|
249
261
|
const move = m.clone()
|
|
250
262
|
this._left.subtract(move)
|
|
251
263
|
this._right.subtract(move)
|
|
@@ -258,6 +270,10 @@ export class Equation {
|
|
|
258
270
|
return this;
|
|
259
271
|
};
|
|
260
272
|
|
|
273
|
+
|
|
274
|
+
// -----------------------------------------------
|
|
275
|
+
// Equations operations
|
|
276
|
+
|
|
261
277
|
/**
|
|
262
278
|
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
263
279
|
*/
|
|
@@ -267,10 +283,6 @@ export class Equation {
|
|
|
267
283
|
return this;
|
|
268
284
|
}
|
|
269
285
|
|
|
270
|
-
|
|
271
|
-
// -----------------------------------------------
|
|
272
|
-
// Equations operations
|
|
273
|
-
|
|
274
286
|
/**
|
|
275
287
|
* Reorder the polynom to have only one letter on the left, the rest on the right.
|
|
276
288
|
* @param letter
|
|
@@ -381,15 +393,15 @@ export class Equation {
|
|
|
381
393
|
return this._left.isMultiVariable || this._right.isMultiVariable;
|
|
382
394
|
};
|
|
383
395
|
|
|
396
|
+
// -----------------------------------------------
|
|
397
|
+
// Equations helpers
|
|
398
|
+
// -----------------------------------------------
|
|
399
|
+
|
|
384
400
|
letters = (): string[] => {
|
|
385
401
|
// @ts-ignore
|
|
386
402
|
return [...new Set([...this._left.letters(), ...this._right.letters()])];
|
|
387
403
|
}
|
|
388
404
|
|
|
389
|
-
// -----------------------------------------------
|
|
390
|
-
// Equations helpers
|
|
391
|
-
// -----------------------------------------------
|
|
392
|
-
|
|
393
405
|
// -----------------------------------------------
|
|
394
406
|
solve = (): Equation => {
|
|
395
407
|
// Initialise the variables:
|
|
@@ -416,23 +428,6 @@ export class Equation {
|
|
|
416
428
|
return this;
|
|
417
429
|
};
|
|
418
430
|
|
|
419
|
-
static makeSolutionsUnique(solutions: ISolution[], sorted?: boolean):ISolution[] {
|
|
420
|
-
let solutionAsTex:string[] = [],
|
|
421
|
-
uniqueSolutions = solutions.filter(sol=>{
|
|
422
|
-
if(!solutionAsTex.includes(sol.tex)){
|
|
423
|
-
solutionAsTex.push(sol.tex)
|
|
424
|
-
return true
|
|
425
|
-
}else{
|
|
426
|
-
return false
|
|
427
|
-
}
|
|
428
|
-
})
|
|
429
|
-
|
|
430
|
-
if(sorted===true){
|
|
431
|
-
uniqueSolutions.sort((a, b)=>a.value-b.value)
|
|
432
|
-
}
|
|
433
|
-
return uniqueSolutions
|
|
434
|
-
}
|
|
435
|
-
|
|
436
431
|
test = (values: literalType): Boolean => {
|
|
437
432
|
return this.left.evaluate(values).isEqual(this.right.evaluate(values))
|
|
438
433
|
}
|
|
@@ -583,8 +578,7 @@ export class Equation {
|
|
|
583
578
|
exact: v
|
|
584
579
|
}]
|
|
585
580
|
}
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
581
|
+
} else {
|
|
588
582
|
if (m1.value === 0) {
|
|
589
583
|
// In this case, the coefficient of the x variable is zero.
|
|
590
584
|
if (m0.value === 0 && this.isAlsoEqual()) {
|
|
@@ -664,7 +658,7 @@ export class Equation {
|
|
|
664
658
|
// -------------------------
|
|
665
659
|
// 2a
|
|
666
660
|
let gcd = Numeric.gcd(b, 2 * a, nthDelta.coefficient),
|
|
667
|
-
am = a/gcd, bm = b/gcd
|
|
661
|
+
am = a / gcd, bm = b / gcd
|
|
668
662
|
nthDelta.coefficient = nthDelta.coefficient / gcd;
|
|
669
663
|
|
|
670
664
|
if (a < 0) {
|
|
@@ -878,14 +872,14 @@ export class Equation {
|
|
|
878
872
|
|
|
879
873
|
this._solutions = []
|
|
880
874
|
|
|
881
|
-
equ.left.factors.forEach(factor=>{
|
|
882
|
-
if(factor.degree(letter).leq(2)) {
|
|
875
|
+
equ.left.factors.forEach(factor => {
|
|
876
|
+
if (factor.degree(letter).leq(2)) {
|
|
883
877
|
let factorAsEquation = new Equation(factor, 0)
|
|
884
878
|
factorAsEquation.solve()
|
|
885
879
|
factorAsEquation.solutions.forEach(solution => {
|
|
886
880
|
this._solutions.push(solution)
|
|
887
881
|
})
|
|
888
|
-
}else{
|
|
882
|
+
} else {
|
|
889
883
|
console.log(factor.tex, ': cannot actually get the solution of this equation')
|
|
890
884
|
}
|
|
891
885
|
})
|
|
@@ -2,7 +2,7 @@ import {Equation, ISolution} from "./equation";
|
|
|
2
2
|
import {Monom} from "./monom";
|
|
3
3
|
import {Fraction} from "../coefficients/fraction";
|
|
4
4
|
import {Polynom} from "./polynom";
|
|
5
|
-
import {Numeric} from "../numeric";
|
|
5
|
+
import {Numeric} from "../numeric.ts";
|
|
6
6
|
|
|
7
7
|
// TODO: Must check and rework
|
|
8
8
|
export class LinearSystem {
|
|
@@ -121,6 +121,10 @@ export class LinearSystem {
|
|
|
121
121
|
return `(${display.join(';')})`;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
get resolutionSteps(): { [p: string]: { equations: Equation[]; operations: string[][] }[] } {
|
|
125
|
+
return this._resolutionSteps;
|
|
126
|
+
}
|
|
127
|
+
|
|
124
128
|
buildTex = (equations: Equation[], operators?: (string[])[]): string => {
|
|
125
129
|
let equStr: string[],
|
|
126
130
|
equArray: string[] = [],
|
|
@@ -191,11 +195,6 @@ export class LinearSystem {
|
|
|
191
195
|
|
|
192
196
|
}
|
|
193
197
|
|
|
194
|
-
|
|
195
|
-
get resolutionSteps(): { [p: string]: { equations: Equation[]; operations: string[][] }[] } {
|
|
196
|
-
return this._resolutionSteps;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
198
|
// ------------------------------------------
|
|
200
199
|
// Creation / parsing functions
|
|
201
200
|
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polynom module contains everything necessary to handle polynoms.
|
|
3
|
+
* @module Logicalset
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {Shutingyard, ShutingyardMode} from '../shutingyard.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Polynom class can handle polynoms, reorder, resolve, ...
|
|
10
|
+
*/
|
|
11
|
+
export class Logicalset {
|
|
12
|
+
private _rawString: string;
|
|
13
|
+
private _rpn: { token: string, tokenType: string }[]
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {string} value (optional) Default polynom to parse on class creation
|
|
18
|
+
*/
|
|
19
|
+
constructor(value: string) {
|
|
20
|
+
this._rawString = value
|
|
21
|
+
this.parse(value)
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get isLogicalset() {
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
get rpn(): { token: string, tokenType: string }[] {
|
|
30
|
+
return this._rpn
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get tex(): string {
|
|
34
|
+
let varStack: { token: string, tokenType: string } [] = []
|
|
35
|
+
|
|
36
|
+
for (let token of this._rpn) {
|
|
37
|
+
if (token.tokenType === 'variable') {
|
|
38
|
+
varStack.push(token);
|
|
39
|
+
} else {
|
|
40
|
+
switch (token.token) {
|
|
41
|
+
case '&':
|
|
42
|
+
if (varStack.length >= 2) {
|
|
43
|
+
let second = varStack.pop(),
|
|
44
|
+
first = varStack.pop()
|
|
45
|
+
|
|
46
|
+
if (first.tokenType === 'mix') {
|
|
47
|
+
first.token = `( ${first.token} )`
|
|
48
|
+
}
|
|
49
|
+
if (second.tokenType === 'mix') {
|
|
50
|
+
second.token = `( ${second.token} )`
|
|
51
|
+
}
|
|
52
|
+
varStack.push({token: `${first.token} \\cap ${second.token}`, tokenType: 'mix'})
|
|
53
|
+
}
|
|
54
|
+
break
|
|
55
|
+
case '|':
|
|
56
|
+
if (varStack.length >= 2) {
|
|
57
|
+
let second = varStack.pop(),
|
|
58
|
+
first = varStack.pop()
|
|
59
|
+
|
|
60
|
+
if (first.tokenType === 'mix') {
|
|
61
|
+
first.token = `( ${first.token} )`
|
|
62
|
+
}
|
|
63
|
+
if (second.tokenType === 'mix') {
|
|
64
|
+
second.token = `( ${second.token} )`
|
|
65
|
+
}
|
|
66
|
+
varStack.push({token: `${first.token} \\cup ${second.token}`, tokenType: 'mix'})
|
|
67
|
+
}
|
|
68
|
+
break
|
|
69
|
+
case '-':
|
|
70
|
+
if (varStack.length >= 2) {
|
|
71
|
+
let second = varStack.pop(),
|
|
72
|
+
first = varStack.pop()
|
|
73
|
+
|
|
74
|
+
if (first.tokenType === 'mix') {
|
|
75
|
+
first.token = `( ${first.token} )`
|
|
76
|
+
}
|
|
77
|
+
if (second.tokenType === 'mix') {
|
|
78
|
+
second.token = `( ${second.token} )`
|
|
79
|
+
}
|
|
80
|
+
varStack.push({token: `${first.token} \\setminus ${second.token}`, tokenType: 'mix'})
|
|
81
|
+
}
|
|
82
|
+
break
|
|
83
|
+
case '!':
|
|
84
|
+
if (varStack.length >= 1) {
|
|
85
|
+
let first = varStack.pop()
|
|
86
|
+
varStack.push({token: `\\overline{ ${first.token} }`, tokenType: 'variable'})
|
|
87
|
+
}
|
|
88
|
+
break
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return varStack[0].token
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
evaluate(tokenSets: { [key: string]: unknown[] }, reference?: unknown[]): unknown[] {
|
|
97
|
+
let varStack: (Set<unknown>)[] = []
|
|
98
|
+
|
|
99
|
+
let referenceSet: Set<unknown>
|
|
100
|
+
if (reference === undefined) {
|
|
101
|
+
referenceSet = new Set()
|
|
102
|
+
for (let key in tokenSets) {
|
|
103
|
+
referenceSet = new Set([...referenceSet, ...tokenSets[key]])
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
referenceSet = new Set(reference)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for (let token of this._rpn) {
|
|
110
|
+
if (token.tokenType === 'variable') {
|
|
111
|
+
// The variable has no token - assume it's empty.
|
|
112
|
+
if (tokenSets[token.token] === undefined) {
|
|
113
|
+
varStack.push(new Set())
|
|
114
|
+
} else {
|
|
115
|
+
varStack.push(new Set(tokenSets[token.token]));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
} else {
|
|
119
|
+
switch (token.token) {
|
|
120
|
+
case '&':
|
|
121
|
+
if (varStack.length >= 2) {
|
|
122
|
+
let second = varStack.pop(),
|
|
123
|
+
first = varStack.pop()
|
|
124
|
+
|
|
125
|
+
varStack.push(new Set([...first].filter(x => second.has(x))))
|
|
126
|
+
}
|
|
127
|
+
break
|
|
128
|
+
case '|':
|
|
129
|
+
if (varStack.length >= 2) {
|
|
130
|
+
let second = varStack.pop(),
|
|
131
|
+
first = varStack.pop()
|
|
132
|
+
varStack.push(new Set([...first, ...second]))
|
|
133
|
+
}
|
|
134
|
+
break
|
|
135
|
+
case '-':
|
|
136
|
+
if (varStack.length >= 2) {
|
|
137
|
+
let second = varStack.pop(),
|
|
138
|
+
first = varStack.pop()
|
|
139
|
+
varStack.push(new Set([...first].filter(x => !second.has(x))))
|
|
140
|
+
}
|
|
141
|
+
break
|
|
142
|
+
case '!':
|
|
143
|
+
if (varStack.length >= 1) {
|
|
144
|
+
let first = varStack.pop()
|
|
145
|
+
|
|
146
|
+
varStack.push(new Set([...referenceSet].filter(x => !first.has(x))))
|
|
147
|
+
}
|
|
148
|
+
break
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return [...varStack[0]].sort();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
vennAB(): any[] {
|
|
157
|
+
return this.evaluate({
|
|
158
|
+
A: ['A', 'AB'],
|
|
159
|
+
B: ['B', 'AB']
|
|
160
|
+
},
|
|
161
|
+
['A', 'B', 'AB', 'E']
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
vennABC(): any[] {
|
|
166
|
+
return this.evaluate({
|
|
167
|
+
A: ['A', 'AB', 'AC', 'ABC'],
|
|
168
|
+
B: ['B', 'AB', 'BC', 'ABC'],
|
|
169
|
+
C: ['C', 'AC', 'BC', 'ABC']
|
|
170
|
+
},
|
|
171
|
+
['A', 'B', 'C', 'AB', 'AC', 'BC', 'E']
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private parse = (value: string): Logicalset => {
|
|
176
|
+
// TODO: Must format the value string to convert some items...
|
|
177
|
+
|
|
178
|
+
// Parse the updated value to the shutingyard algorithm
|
|
179
|
+
this._rpn = new Shutingyard(ShutingyardMode.SET).parse(value).rpn;
|
|
180
|
+
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/***
|
|
2
2
|
* Monom class
|
|
3
3
|
*/
|
|
4
|
-
import {Numeric} from "../numeric";
|
|
5
|
-
import {Shutingyard, ShutingyardType, Token} from "../shutingyard";
|
|
4
|
+
import {Numeric} from "../numeric.ts";
|
|
5
|
+
import {Shutingyard, ShutingyardType, Token} from "../shutingyard.ts";
|
|
6
6
|
import {Fraction} from "../coefficients/fraction";
|
|
7
7
|
|
|
8
8
|
export type literalType = {
|
|
@@ -10,6 +10,9 @@ export type literalType = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class Monom {
|
|
13
|
+
private _coefficient: Fraction;
|
|
14
|
+
private _literal: literalType;
|
|
15
|
+
|
|
13
16
|
/**
|
|
14
17
|
* Create a Monom
|
|
15
18
|
* Defined as \\(k \\cdot x^{n}\\), where \\( k,n \in \\mathbb{Q}\\).
|
|
@@ -27,7 +30,8 @@ export class Monom {
|
|
|
27
30
|
return this;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
// ------------------------------------------
|
|
34
|
+
// Getter and setter
|
|
31
35
|
|
|
32
36
|
// ------------------------------------------
|
|
33
37
|
/**
|
|
@@ -38,9 +42,6 @@ export class Monom {
|
|
|
38
42
|
return this._coefficient;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
// ------------------------------------------
|
|
42
|
-
// Getter and setter
|
|
43
|
-
|
|
44
45
|
/**
|
|
45
46
|
* Set the coefficient \\(k\\) value of the monom
|
|
46
47
|
* @param {Fraction | number | string} F
|
|
@@ -49,8 +50,6 @@ export class Monom {
|
|
|
49
50
|
this._coefficient = new Fraction(F);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
private _literal: literalType;
|
|
53
|
-
|
|
54
53
|
/**
|
|
55
54
|
* Get the literal part of \\(x^{n_1}y^{n_2}\\) as dictionary \\[\\begin{array}{ll}x&=n_1\\\\y&=n_2\\end{array}\\]
|
|
56
55
|
* @returns {literalType}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {literalType, Monom} from './monom';
|
|
6
|
-
import {Shutingyard, ShutingyardType, Token} from '../shutingyard';
|
|
7
|
-
import {Numeric} from '../numeric';
|
|
6
|
+
import {Shutingyard, ShutingyardType, Token} from '../shutingyard.ts';
|
|
7
|
+
import {Numeric} from '../numeric.ts';
|
|
8
8
|
import {Fraction} from "../coefficients/fraction";
|
|
9
9
|
import {Equation, ISolution} from "./equation";
|
|
10
10
|
|
|
@@ -8,7 +8,7 @@ import {ISolution} from "./equation";
|
|
|
8
8
|
import {Polynom} from "./polynom";
|
|
9
9
|
import {Fraction} from "../coefficients/fraction";
|
|
10
10
|
import {Point} from "../geometry/point";
|
|
11
|
-
import {NumExp} from "../numexp";
|
|
11
|
+
import {NumExp} from "../numexp.ts";
|
|
12
12
|
|
|
13
13
|
export type StudyableFunction = Rational
|
|
14
14
|
|
|
@@ -125,22 +125,22 @@ export class Study {
|
|
|
125
125
|
this.fx = fx
|
|
126
126
|
|
|
127
127
|
this._config = {
|
|
128
|
-
name
|
|
128
|
+
name: 'f',
|
|
129
129
|
variable: 'x',
|
|
130
|
-
domain
|
|
131
|
-
asymptotes
|
|
132
|
-
signs
|
|
133
|
-
derivative
|
|
134
|
-
variations
|
|
130
|
+
domain: true,
|
|
131
|
+
asymptotes: true,
|
|
132
|
+
signs: true,
|
|
133
|
+
derivative: true,
|
|
134
|
+
variations: true,
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
if (config) {
|
|
138
138
|
if (typeof config === 'string') {
|
|
139
139
|
const d = config.split(',')
|
|
140
140
|
this._config = {}
|
|
141
|
-
let n = d.filter(x=>x.includes('(') && x.includes(')'))
|
|
141
|
+
let n = d.filter(x => x.includes('(') && x.includes(')'))
|
|
142
142
|
|
|
143
|
-
if(n.length===1){
|
|
143
|
+
if (n.length === 1) {
|
|
144
144
|
this._config.name = n[0].split('(')[0]
|
|
145
145
|
this._config.variable = n[0].split('(')[1].split(')')[0]
|
|
146
146
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Numeric} from "../numeric";
|
|
1
|
+
import {Numeric} from "../numeric.ts";
|
|
2
2
|
|
|
3
3
|
export type FractionParsingType = number | string | Fraction
|
|
4
4
|
|
|
@@ -65,7 +65,7 @@ export class Fraction {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
get texWithSign():string {
|
|
68
|
+
get texWithSign(): string {
|
|
69
69
|
return this.isPositive() ? `+${this.tex}` : this.tex;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -231,7 +231,7 @@ export class Fraction {
|
|
|
231
231
|
// The given value is a float number
|
|
232
232
|
// Get the number of decimals after the float sign
|
|
233
233
|
let [unit, decimal] = (value.toString()).split('.')
|
|
234
|
-
let p: number = decimal?decimal.length:0;
|
|
234
|
+
let p: number = decimal ? decimal.length : 0;
|
|
235
235
|
|
|
236
236
|
// Detect if the decimal part is periodic or not...
|
|
237
237
|
|
|
@@ -336,7 +336,7 @@ export class Fraction {
|
|
|
336
336
|
// Parse the value.
|
|
337
337
|
// If it's a fraction, return a clone of it
|
|
338
338
|
// If it's an integer, return the fraction F/1
|
|
339
|
-
for(let value of values){
|
|
339
|
+
for (let value of values) {
|
|
340
340
|
let F = new Fraction(value)
|
|
341
341
|
this._numerator = this._numerator * F.numerator;
|
|
342
342
|
this._denominator = this._denominator * F.denominator;
|
|
@@ -2,13 +2,18 @@ import {Point} from "./point";
|
|
|
2
2
|
import {Line, LinePropriety} from "./line";
|
|
3
3
|
import {Vector} from "./vector";
|
|
4
4
|
import {Triangle} from "./triangle";
|
|
5
|
-
import {Numeric} from "../numeric";
|
|
5
|
+
import {Numeric} from "../numeric.ts";
|
|
6
6
|
import {Fraction} from "../coefficients/fraction";
|
|
7
7
|
import {Equation} from "../algebra/equation";
|
|
8
8
|
import {Polynom} from "../algebra/polynom";
|
|
9
9
|
import {Monom} from "../algebra/monom";
|
|
10
10
|
|
|
11
11
|
export class Circle {
|
|
12
|
+
private _center: Point;
|
|
13
|
+
private _squareRadius: Fraction;
|
|
14
|
+
private _cartesian: Equation;
|
|
15
|
+
private _exists: boolean;
|
|
16
|
+
|
|
12
17
|
constructor(...values: unknown[]) {
|
|
13
18
|
this._exists = false
|
|
14
19
|
|
|
@@ -17,26 +22,18 @@ export class Circle {
|
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
private _center: Point;
|
|
21
|
-
|
|
22
25
|
get center(): Point {
|
|
23
26
|
return this._center;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
private _squareRadius: Fraction;
|
|
27
|
-
|
|
28
29
|
get squareRadius(): Fraction {
|
|
29
30
|
return this._squareRadius
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
private _cartesian: Equation;
|
|
33
|
-
|
|
34
33
|
get cartesian(): Equation {
|
|
35
34
|
return this._cartesian
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
private _exists: boolean;
|
|
39
|
-
|
|
40
37
|
get exists(): boolean {
|
|
41
38
|
return this._exists;
|
|
42
39
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {Vector} from "./vector";
|
|
6
6
|
import {Point} from "./point";
|
|
7
|
-
import {Numeric} from "../numeric";
|
|
7
|
+
import {Numeric} from "../numeric.ts";
|
|
8
8
|
import {Fraction} from "../coefficients/fraction";
|
|
9
9
|
import {Equation} from "../algebra/equation";
|
|
10
10
|
import {Polynom} from "../algebra/polynom";
|