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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module Vector
|
|
4
4
|
*/
|
|
5
5
|
import {Fraction} from "../coefficients/fraction";
|
|
6
|
-
import {Numeric} from "../numeric";
|
|
6
|
+
import {Numeric} from "../numeric.ts";
|
|
7
7
|
import {Point} from "./point";
|
|
8
8
|
|
|
9
9
|
export class Vector {
|
|
@@ -26,7 +26,7 @@ export class Vector {
|
|
|
26
26
|
return this._x;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
set x(value: Fraction|number|string) {
|
|
29
|
+
set x(value: Fraction | number | string) {
|
|
30
30
|
this._x = new Fraction(value);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ export class Vector {
|
|
|
34
34
|
return this._y;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
set y(value: Fraction|number|string) {
|
|
37
|
+
set y(value: Fraction | number | string) {
|
|
38
38
|
this._y = new Fraction(value);
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -58,6 +58,18 @@ export class Vector {
|
|
|
58
58
|
// Creation / parsing functions
|
|
59
59
|
// ------------------------------------------
|
|
60
60
|
|
|
61
|
+
get isNull(): boolean {
|
|
62
|
+
return this.x.isZero() && this.y.isZero()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static scalarProduct = (v1: Vector, v2: Vector): Fraction => {
|
|
66
|
+
return v1.x.clone().multiply(v2.x).add(v1.y.clone().multiply(v2.y));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
static determinant = (v1: Vector, v2: Vector): Fraction => {
|
|
70
|
+
return v1.x.clone().multiply(v2.y).subtract(v1.y.clone().multiply(v2.x))
|
|
71
|
+
}
|
|
72
|
+
|
|
61
73
|
parse = (...values: any): Vector => {
|
|
62
74
|
// TODO: Must be more strict about what is given and limit to two dimensional vectors.p
|
|
63
75
|
// Maybe more than one value was given...
|
|
@@ -92,12 +104,12 @@ export class Vector {
|
|
|
92
104
|
this._y = new Fraction(values[1])
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
if(
|
|
107
|
+
if (
|
|
96
108
|
(typeof values[0] === 'object' && !isNaN(values[0].x) && !isNaN(values[0].x)) &&
|
|
97
109
|
(typeof values[1] === 'object' && !isNaN(values[1].x) && !isNaN(values[1].x))
|
|
98
|
-
){
|
|
99
|
-
this._x = new Fraction(+values[1].x-values[0].x)
|
|
100
|
-
this._y = new Fraction(+values[1].y-values[0].y)
|
|
110
|
+
) {
|
|
111
|
+
this._x = new Fraction(+values[1].x - values[0].x)
|
|
112
|
+
this._y = new Fraction(+values[1].y - values[0].y)
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
|
|
@@ -122,6 +134,9 @@ export class Vector {
|
|
|
122
134
|
return this;
|
|
123
135
|
}
|
|
124
136
|
|
|
137
|
+
// ------------------------------------------
|
|
138
|
+
// Mathematical operations
|
|
139
|
+
|
|
125
140
|
zero = (): Vector => {
|
|
126
141
|
this.reset();
|
|
127
142
|
this._x = new Fraction(null);
|
|
@@ -135,18 +150,6 @@ export class Vector {
|
|
|
135
150
|
return this;
|
|
136
151
|
}
|
|
137
152
|
|
|
138
|
-
private _parseString = (value: string): Vector => {
|
|
139
|
-
// Split comma, semi colon or single space.
|
|
140
|
-
let components = value.split(/[,;\s]/g);
|
|
141
|
-
|
|
142
|
-
// Validate the fraction values.
|
|
143
|
-
this.x = new Fraction(components[0] || null);
|
|
144
|
-
this.y = new Fraction(components[1] || null);
|
|
145
|
-
return this;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// ------------------------------------------
|
|
149
|
-
// Mathematical operations
|
|
150
153
|
// ------------------------------------------
|
|
151
154
|
opposed = (): Vector => {
|
|
152
155
|
this._x.opposed();
|
|
@@ -174,14 +177,6 @@ export class Vector {
|
|
|
174
177
|
return Vector.determinant(this, V)
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
static scalarProduct = (v1: Vector, v2: Vector): Fraction => {
|
|
178
|
-
return v1.x.clone().multiply(v2.x).add(v1.y.clone().multiply(v2.y));
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
static determinant = (v1: Vector, v2: Vector): Fraction => {
|
|
182
|
-
return v1.x.clone().multiply(v2.y).subtract(v1.y.clone().multiply(v2.x))
|
|
183
|
-
}
|
|
184
|
-
|
|
185
180
|
normal = (): Vector => {
|
|
186
181
|
let x = this.x.clone().opposed(), y = this.y.clone();
|
|
187
182
|
this._x = y;
|
|
@@ -197,10 +192,6 @@ export class Vector {
|
|
|
197
192
|
return this.scalarProductWithVector(v).isZero()
|
|
198
193
|
}
|
|
199
194
|
|
|
200
|
-
get isNull(): boolean {
|
|
201
|
-
return this.x.isZero() && this.y.isZero()
|
|
202
|
-
}
|
|
203
|
-
|
|
204
195
|
multiplyByScalar = (k: any): Vector => {
|
|
205
196
|
let scalar = new Fraction(k);
|
|
206
197
|
this._x.multiply(scalar);
|
|
@@ -211,15 +202,15 @@ export class Vector {
|
|
|
211
202
|
divideByScalar = (k: any): Vector => {
|
|
212
203
|
return this.multiplyByScalar(new Fraction(k).invert());
|
|
213
204
|
}
|
|
214
|
-
// ------------------------------------------
|
|
215
|
-
// Vector functions
|
|
216
|
-
// ------------------------------------------
|
|
217
205
|
|
|
218
206
|
simplify = (): Vector => {
|
|
219
207
|
// Multiply by the lcm of denominators.
|
|
220
208
|
return this.multiplyByScalar(Numeric.lcm(this._x.denominator, this._y.denominator))
|
|
221
209
|
.divideByScalar(Numeric.gcd(this._x.numerator, this._y.numerator));
|
|
222
210
|
}
|
|
211
|
+
// ------------------------------------------
|
|
212
|
+
// Vector functions
|
|
213
|
+
// ------------------------------------------
|
|
223
214
|
|
|
224
215
|
simplifyDirection = (): Vector => {
|
|
225
216
|
let lcm = Numeric.lcm(this.x.denominator, this.y.denominator),
|
|
@@ -239,4 +230,14 @@ export class Vector {
|
|
|
239
230
|
|
|
240
231
|
return toDegree * Math.acos(scalar / (this.norm * V.norm));
|
|
241
232
|
}
|
|
233
|
+
|
|
234
|
+
private _parseString = (value: string): Vector => {
|
|
235
|
+
// Split comma, semi colon or single space.
|
|
236
|
+
let components = value.split(/[,;\s]/g);
|
|
237
|
+
|
|
238
|
+
// Validate the fraction values.
|
|
239
|
+
this.x = new Fraction(components[0] || null);
|
|
240
|
+
this.y = new Fraction(components[1] || null);
|
|
241
|
+
return this;
|
|
242
|
+
};
|
|
242
243
|
}
|
|
@@ -6,11 +6,11 @@ export class NumExp {
|
|
|
6
6
|
private _expression: string
|
|
7
7
|
private _isValid: boolean
|
|
8
8
|
|
|
9
|
-
constructor(value: string, uniformize?:boolean) {
|
|
9
|
+
constructor(value: string, uniformize?: boolean) {
|
|
10
10
|
this._expression = value
|
|
11
11
|
try {
|
|
12
|
-
this._rpn = new Shutingyard(ShutingyardMode.NUMERIC).parse(value, uniformize || uniformize===undefined).rpn
|
|
13
|
-
}catch(e){
|
|
12
|
+
this._rpn = new Shutingyard(ShutingyardMode.NUMERIC).parse(value, uniformize || uniformize === undefined).rpn
|
|
13
|
+
} catch (e) {
|
|
14
14
|
this._rpn = null
|
|
15
15
|
this._isValid = false
|
|
16
16
|
}
|
|
@@ -21,17 +21,17 @@ export class NumExp {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
get isValid(): boolean {
|
|
24
|
-
if(this._isValid===undefined){
|
|
24
|
+
if (this._isValid === undefined) {
|
|
25
25
|
try {
|
|
26
26
|
const v = this.evaluate({x: 0})
|
|
27
|
-
}catch{
|
|
27
|
+
} catch {
|
|
28
28
|
this._isValid = false
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
return this._isValid
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
set isValid(value: boolean){
|
|
34
|
+
set isValid(value: boolean) {
|
|
35
35
|
this._isValid = value
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -39,68 +39,10 @@ export class NumExp {
|
|
|
39
39
|
return this._expression;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
private _extractDecimalPart(value: number): string {
|
|
43
|
-
let decimal = value.toString()
|
|
44
|
-
|
|
45
|
-
if (!decimal.includes('.')) {
|
|
46
|
-
return ''
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
decimal = decimal.split('.')[1]
|
|
50
|
-
|
|
51
|
-
return decimal.substring(0, decimal.length - 2)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private _numberCorrection(value: number): number {
|
|
55
|
-
// Must modify the number if it's like:
|
|
56
|
-
// a: 3.0000000000000003
|
|
57
|
-
// b: 3.9999999999999994
|
|
58
|
-
// remove the last character
|
|
59
|
-
// check if around n last characters are either 0 or 9
|
|
60
|
-
// if it is, 'round' the number.
|
|
61
|
-
|
|
62
|
-
const epsilon = 0.00000000000001,
|
|
63
|
-
number_of_digits = 6
|
|
64
|
-
|
|
65
|
-
const decimal = this._extractDecimalPart(value)
|
|
66
|
-
if(decimal===''){return value}
|
|
67
|
-
|
|
68
|
-
const n9 = decimal.match(/9+$/g)
|
|
69
|
-
const n0 = decimal.match(/0+$/g)
|
|
70
|
-
|
|
71
|
-
if (n9 && n9[0].length >= number_of_digits) {
|
|
72
|
-
// New tested values.
|
|
73
|
-
const mod = this._extractDecimalPart(value + epsilon),
|
|
74
|
-
mod0 = mod.match(/0+$/g)
|
|
75
|
-
|
|
76
|
-
if(mod0 && mod0[0].length>= number_of_digits){
|
|
77
|
-
// The value can be changed. Remove all zeros!
|
|
78
|
-
return +((value+epsilon).toString().split(mod0[0])[0])
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (n0 && n0[0].length >= number_of_digits) {
|
|
83
|
-
// New tested values.
|
|
84
|
-
const mod = this._extractDecimalPart(value - epsilon),
|
|
85
|
-
mod9 = mod.match(/9+$/g)
|
|
86
|
-
|
|
87
|
-
if(mod9 && mod9[0].length>= number_of_digits){
|
|
88
|
-
// The value can be changed. Remove all nines!
|
|
89
|
-
return +(value.toString().split(n0[0])[0])
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return value
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private _addToStack(stack:number[], value: number): void {
|
|
97
|
-
stack.push(this._numberCorrection(value))
|
|
98
|
-
}
|
|
99
|
-
|
|
100
42
|
evaluate(values?: { [Key: string]: number }): number {
|
|
101
43
|
const stack: number[] = []
|
|
102
44
|
|
|
103
|
-
if(this._rpn===null){
|
|
45
|
+
if (this._rpn === null) {
|
|
104
46
|
this._isValid = false
|
|
105
47
|
return 0
|
|
106
48
|
}
|
|
@@ -125,51 +67,63 @@ export class NumExp {
|
|
|
125
67
|
if (element.token === '*') {
|
|
126
68
|
const b = stack.pop(),
|
|
127
69
|
a = stack.pop()
|
|
128
|
-
if(a === undefined || b === undefined){
|
|
70
|
+
if (a === undefined || b === undefined) {
|
|
71
|
+
this.isValid = false
|
|
72
|
+
}
|
|
129
73
|
this._addToStack(stack, a * b)
|
|
130
74
|
} else if (element.token === '/') {
|
|
131
75
|
const b = stack.pop(),
|
|
132
76
|
a = stack.pop()
|
|
133
|
-
if(a === undefined || b === undefined){
|
|
77
|
+
if (a === undefined || b === undefined) {
|
|
78
|
+
this.isValid = false
|
|
79
|
+
}
|
|
134
80
|
this._addToStack(stack, a / b)
|
|
135
81
|
} else if (element.token === '+') {
|
|
136
82
|
const b = stack.pop(),
|
|
137
83
|
a = stack.pop()
|
|
138
|
-
if(a === undefined || b === undefined){
|
|
84
|
+
if (a === undefined || b === undefined) {
|
|
85
|
+
this.isValid = false
|
|
86
|
+
}
|
|
139
87
|
this._addToStack(stack, (+a) + (+b))
|
|
140
88
|
} else if (element.token === '-') {
|
|
141
89
|
const b = stack.pop(),
|
|
142
90
|
a = stack.pop() || 0
|
|
143
|
-
if(b === undefined){
|
|
91
|
+
if (b === undefined) {
|
|
92
|
+
this.isValid = false
|
|
93
|
+
}
|
|
144
94
|
this._addToStack(stack, a - b)
|
|
145
95
|
} else if (element.token === '^') {
|
|
146
96
|
const b = stack.pop(),
|
|
147
97
|
a = stack.pop()
|
|
148
|
-
if(a === undefined || b === undefined){
|
|
98
|
+
if (a === undefined || b === undefined) {
|
|
99
|
+
this.isValid = false
|
|
100
|
+
}
|
|
149
101
|
this._addToStack(stack, Math.pow(a, b))
|
|
150
102
|
}
|
|
151
103
|
} else if (element.tokenType === ShutingyardType.FUNCTION) {
|
|
152
104
|
const a = stack.pop()
|
|
153
|
-
if(a === undefined){
|
|
105
|
+
if (a === undefined) {
|
|
106
|
+
this.isValid = false
|
|
107
|
+
}
|
|
154
108
|
if (element.token === 'sin') {
|
|
155
109
|
this._addToStack(stack, Math.sin(a))
|
|
156
110
|
} else if (element.token === 'cos') {
|
|
157
111
|
this._addToStack(stack, Math.cos(a))
|
|
158
112
|
} else if (element.token === 'tan') {
|
|
159
113
|
this._addToStack(stack, Math.tan(a))
|
|
160
|
-
} else if(element.token === 'sqrt') {
|
|
114
|
+
} else if (element.token === 'sqrt') {
|
|
161
115
|
this._addToStack(stack, Math.sqrt(a))
|
|
162
|
-
}else if(element.token ==='nthrt') {
|
|
116
|
+
} else if (element.token === 'nthrt') {
|
|
163
117
|
// TODO: support nthrt in num. exp.
|
|
164
118
|
let b = stack.pop()
|
|
165
|
-
if(a%2===0 && b<0){
|
|
119
|
+
if (a % 2 === 0 && b < 0) {
|
|
166
120
|
this._addToStack(stack, NaN)
|
|
167
|
-
}else {
|
|
121
|
+
} else {
|
|
168
122
|
this._addToStack(stack, (b < 0 ? -1 : 1) * Math.pow(Math.abs(b), 1 / a))
|
|
169
123
|
}
|
|
170
|
-
} else if(element.token === 'ln'){
|
|
124
|
+
} else if (element.token === 'ln') {
|
|
171
125
|
this._addToStack(stack, Math.log(a))
|
|
172
|
-
} else if(element.token === 'log') {
|
|
126
|
+
} else if (element.token === 'log') {
|
|
173
127
|
this._addToStack(stack, Math.log10(a))
|
|
174
128
|
}
|
|
175
129
|
}
|
|
@@ -181,4 +135,64 @@ export class NumExp {
|
|
|
181
135
|
throw `There was a problem parsing: ${this._expression}`
|
|
182
136
|
}
|
|
183
137
|
}
|
|
138
|
+
|
|
139
|
+
private _extractDecimalPart(value: number): string {
|
|
140
|
+
let decimal = value.toString()
|
|
141
|
+
|
|
142
|
+
if (!decimal.includes('.')) {
|
|
143
|
+
return ''
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
decimal = decimal.split('.')[1]
|
|
147
|
+
|
|
148
|
+
return decimal.substring(0, decimal.length - 2)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private _numberCorrection(value: number): number {
|
|
152
|
+
// Must modify the number if it's like:
|
|
153
|
+
// a: 3.0000000000000003
|
|
154
|
+
// b: 3.9999999999999994
|
|
155
|
+
// remove the last character
|
|
156
|
+
// check if around n last characters are either 0 or 9
|
|
157
|
+
// if it is, 'round' the number.
|
|
158
|
+
|
|
159
|
+
const epsilon = 0.00000000000001,
|
|
160
|
+
number_of_digits = 6
|
|
161
|
+
|
|
162
|
+
const decimal = this._extractDecimalPart(value)
|
|
163
|
+
if (decimal === '') {
|
|
164
|
+
return value
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const n9 = decimal.match(/9+$/g)
|
|
168
|
+
const n0 = decimal.match(/0+$/g)
|
|
169
|
+
|
|
170
|
+
if (n9 && n9[0].length >= number_of_digits) {
|
|
171
|
+
// New tested values.
|
|
172
|
+
const mod = this._extractDecimalPart(value + epsilon),
|
|
173
|
+
mod0 = mod.match(/0+$/g)
|
|
174
|
+
|
|
175
|
+
if (mod0 && mod0[0].length >= number_of_digits) {
|
|
176
|
+
// The value can be changed. Remove all zeros!
|
|
177
|
+
return +((value + epsilon).toString().split(mod0[0])[0])
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (n0 && n0[0].length >= number_of_digits) {
|
|
182
|
+
// New tested values.
|
|
183
|
+
const mod = this._extractDecimalPart(value - epsilon),
|
|
184
|
+
mod9 = mod.match(/9+$/g)
|
|
185
|
+
|
|
186
|
+
if (mod9 && mod9[0].length >= number_of_digits) {
|
|
187
|
+
// The value can be changed. Remove all nines!
|
|
188
|
+
return +(value.toString().split(n0[0])[0])
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return value
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private _addToStack(stack: number[], value: number): void {
|
|
196
|
+
stack.push(this._numberCorrection(value))
|
|
197
|
+
}
|
|
184
198
|
}
|
|
@@ -10,19 +10,6 @@ export class rndMonom extends randomCore {
|
|
|
10
10
|
declare protected _config: randomMonomConfig
|
|
11
11
|
declare protected _defaultConfig: randomMonomConfig
|
|
12
12
|
|
|
13
|
-
constructor(userConfig?: randomMonomConfig) {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
this._defaultConfig = {
|
|
17
|
-
letters: 'x',
|
|
18
|
-
degree: 2,
|
|
19
|
-
fraction: true,
|
|
20
|
-
zero: false
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this._config = this.mergeConfig(userConfig, this._defaultConfig)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
13
|
generate = (): Monom => {
|
|
27
14
|
// Create a monom instance
|
|
28
15
|
let M = new Monom()
|
|
@@ -54,4 +41,17 @@ export class rndMonom extends randomCore {
|
|
|
54
41
|
|
|
55
42
|
return M
|
|
56
43
|
}
|
|
44
|
+
|
|
45
|
+
constructor(userConfig?: randomMonomConfig) {
|
|
46
|
+
super();
|
|
47
|
+
|
|
48
|
+
this._defaultConfig = {
|
|
49
|
+
letters: 'x',
|
|
50
|
+
degree: 2,
|
|
51
|
+
fraction: true,
|
|
52
|
+
zero: false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this._config = this.mergeConfig(userConfig, this._defaultConfig)
|
|
56
|
+
}
|
|
57
57
|
}
|
|
@@ -12,28 +12,8 @@ export class rndPolynom extends randomCore {
|
|
|
12
12
|
declare protected _config: randomPolynomConfig
|
|
13
13
|
declare protected _defaultConfig: randomPolynomConfig
|
|
14
14
|
|
|
15
|
-
constructor(userConfig?: randomPolynomConfig) {
|
|
16
|
-
super();
|
|
17
|
-
|
|
18
|
-
// Default config for a random polynom
|
|
19
|
-
this._defaultConfig = {
|
|
20
|
-
letters: 'x',
|
|
21
|
-
degree: 2,
|
|
22
|
-
fraction: false,
|
|
23
|
-
zero: false,
|
|
24
|
-
unit: false,
|
|
25
|
-
factorable: false,
|
|
26
|
-
allowNullMonom: true,
|
|
27
|
-
numberOfMonoms: 0,
|
|
28
|
-
positive: true
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Merge config with initialiser
|
|
32
|
-
this._config = this.mergeConfig(userConfig, this._defaultConfig)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
15
|
generate = (): Polynom => {
|
|
36
|
-
if(this._config.factorable && this._config.degree>1){
|
|
16
|
+
if (this._config.factorable && this._config.degree > 1) {
|
|
37
17
|
return this.factorable()
|
|
38
18
|
}
|
|
39
19
|
|
|
@@ -60,7 +40,7 @@ export class rndPolynom extends randomCore {
|
|
|
60
40
|
}
|
|
61
41
|
|
|
62
42
|
// Make sure the first monom is positive.
|
|
63
|
-
if(this._config.positive && P.monomByDegree().coefficient.isNegative()){
|
|
43
|
+
if (this._config.positive && P.monomByDegree().coefficient.isNegative()) {
|
|
64
44
|
P.monomByDegree().coefficient.opposed()
|
|
65
45
|
}
|
|
66
46
|
|
|
@@ -68,12 +48,32 @@ export class rndPolynom extends randomCore {
|
|
|
68
48
|
if (this._config.numberOfMonoms > 0 && this._config.numberOfMonoms < P.length) {
|
|
69
49
|
// Get the greatest degree monom
|
|
70
50
|
let M = P.monomByDegree().clone()
|
|
71
|
-
P.monoms = Random.array(P.monoms.slice(1), this._config.numberOfMonoms-1)
|
|
51
|
+
P.monoms = Random.array(P.monoms.slice(1), this._config.numberOfMonoms - 1)
|
|
72
52
|
P.add(M).reorder().reduce()
|
|
73
53
|
}
|
|
74
54
|
return P
|
|
75
55
|
}
|
|
76
56
|
|
|
57
|
+
constructor(userConfig?: randomPolynomConfig) {
|
|
58
|
+
super();
|
|
59
|
+
|
|
60
|
+
// Default config for a random polynom
|
|
61
|
+
this._defaultConfig = {
|
|
62
|
+
letters: 'x',
|
|
63
|
+
degree: 2,
|
|
64
|
+
fraction: false,
|
|
65
|
+
zero: false,
|
|
66
|
+
unit: false,
|
|
67
|
+
factorable: false,
|
|
68
|
+
allowNullMonom: true,
|
|
69
|
+
numberOfMonoms: 0,
|
|
70
|
+
positive: true
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Merge config with initialiser
|
|
74
|
+
this._config = this.mergeConfig(userConfig, this._defaultConfig)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
77
|
factorable = (): Polynom => {
|
|
78
78
|
let P = new Polynom().one()
|
|
79
79
|
|
|
@@ -81,7 +81,7 @@ export class rndPolynom extends randomCore {
|
|
|
81
81
|
_factorableConfig.degree = 1
|
|
82
82
|
_factorableConfig.factorable = false
|
|
83
83
|
|
|
84
|
-
for(let i=0; i<this._config.degree;i++){
|
|
84
|
+
for (let i = 0; i < this._config.degree; i++) {
|
|
85
85
|
P.multiply(Random.polynom(_factorableConfig))
|
|
86
86
|
}
|
|
87
87
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pimath",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.130",
|
|
4
4
|
"description": "A math library for teacher :)",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "dist/pimath.js",
|
|
7
|
+
"types": "dist/pimath.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"lib"
|
|
11
|
+
],
|
|
6
12
|
"scripts": {
|
|
7
13
|
"test": "mocha -r ts-node/register 'tests/**/*.test.ts'",
|
|
8
14
|
"dev": "vite serve",
|
|
9
|
-
"build": "tsc && vite build",
|
|
15
|
+
"build": "tsc --p ./tsconfig-build.json && vite build",
|
|
10
16
|
"preview": "vite preview",
|
|
11
17
|
"docs": "typedoc"
|
|
12
18
|
},
|
|
@@ -28,15 +34,8 @@
|
|
|
28
34
|
"ts-loader": "^9.4.4",
|
|
29
35
|
"ts-node": "^10.9.1",
|
|
30
36
|
"typedoc": "^0.25.1",
|
|
31
|
-
"typescript": "^5.2.2"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"vite": "^5.2.10"
|
|
35
|
-
},
|
|
36
|
-
"exports": {
|
|
37
|
-
".": {
|
|
38
|
-
"import": "./dist/pimath.js",
|
|
39
|
-
"require": "./dist/pimath.umd.cjs"
|
|
40
|
-
}
|
|
37
|
+
"typescript": "^5.2.2",
|
|
38
|
+
"vite": "^5.2.10",
|
|
39
|
+
"vite-plugin-dts": "^3.9.0"
|
|
41
40
|
}
|
|
42
41
|
}
|
package/.eslintrc.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": true,
|
|
4
|
-
"es6": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"eslint:recommended",
|
|
8
|
-
"plugin:@typescript-eslint/eslint-recommended"
|
|
9
|
-
],
|
|
10
|
-
"globals": {
|
|
11
|
-
"Atomics": "readonly",
|
|
12
|
-
"SharedArrayBuffer": "readonly"
|
|
13
|
-
},
|
|
14
|
-
"parser": "@typescript-eslint/parser",
|
|
15
|
-
"parserOptions": {
|
|
16
|
-
"ecmaVersion": 2018,
|
|
17
|
-
"sourceType": "module"
|
|
18
|
-
},
|
|
19
|
-
"plugins": [
|
|
20
|
-
"@typescript-eslint"
|
|
21
|
-
],
|
|
22
|
-
"rules": {
|
|
23
|
-
}
|
|
24
|
-
};
|
package/.idea/$CACHE_FILE$
DELETED
package/.idea/PI.iml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/docs" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/esm" />
|
|
8
|
-
<excludeFolder url="file://$MODULE_DIR$/public" />
|
|
9
|
-
<excludeFolder url="file://$MODULE_DIR$/dev" />
|
|
10
|
-
</content>
|
|
11
|
-
<orderEntry type="inheritedJdk" />
|
|
12
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
13
|
-
</component>
|
|
14
|
-
</module>
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
package/.idea/php.xml
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="MessDetectorOptionsConfiguration">
|
|
4
|
-
<option name="transferred" value="true" />
|
|
5
|
-
</component>
|
|
6
|
-
<component name="PHPCSFixerOptionsConfiguration">
|
|
7
|
-
<option name="transferred" value="true" />
|
|
8
|
-
</component>
|
|
9
|
-
<component name="PHPCodeSnifferOptionsConfiguration">
|
|
10
|
-
<option name="transferred" value="true" />
|
|
11
|
-
</component>
|
|
12
|
-
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
|
|
13
|
-
<component name="PhpStanOptionsConfiguration">
|
|
14
|
-
<option name="transferred" value="true" />
|
|
15
|
-
</component>
|
|
16
|
-
<component name="PsalmOptionsConfiguration">
|
|
17
|
-
<option name="transferred" value="true" />
|
|
18
|
-
</component>
|
|
19
|
-
</project>
|