pimath 0.0.26 → 0.0.30
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 +15 -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/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/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/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/numexp.test.ts +27 -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numexp.js","sourceRoot":"","sources":["../../src/maths/numexp.ts"],"names":[],"mappings":";;;AAAA,+CAA2F;AAC3F,iDAAwC;AAExC,MAAa,MAAM;IACP,IAAI,CAAwC;IAC5C,WAAW,CAAQ;IAE3B,YAAY,KAAa;QACrB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,yBAAW,CAAC,6BAAe,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAA;IACzE,CAAC;IAED,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAEO,mBAAmB,CAAC,KAAa;QACrC,IAAI,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAA;QAE9B,IAAI,CAAC,OAAO,CAAC,QAAQ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3
3
|
precedence: number;
|
|
4
4
|
associative: string;
|
|
5
|
+
type: string;
|
|
5
6
|
};
|
|
6
7
|
};
|
|
8
|
+
export declare const tokenConstant: {
|
|
9
|
+
[Key: string]: number;
|
|
10
|
+
};
|
|
11
|
+
export declare enum ShutingyardType {
|
|
12
|
+
VARIABLE = "variable",
|
|
13
|
+
COEFFICIENT = "coefficient",
|
|
14
|
+
OPERATION = "operation",
|
|
15
|
+
CONSTANT = "constant",
|
|
16
|
+
FUNCTION = "function",
|
|
17
|
+
MONOM = "monom"
|
|
18
|
+
}
|
|
19
|
+
export declare enum ShutingyardMode {
|
|
20
|
+
POLYNOM = "polynom",
|
|
21
|
+
SET = "set",
|
|
22
|
+
NUMERIC = "numeric"
|
|
23
|
+
}
|
|
7
24
|
export declare class Shutingyard {
|
|
8
25
|
private _rpn;
|
|
9
|
-
readonly _mode:
|
|
26
|
+
readonly _mode: ShutingyardMode;
|
|
10
27
|
private _tokenConfig;
|
|
28
|
+
private _tokenConstant;
|
|
11
29
|
private _uniformize;
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
private _tokenKeys;
|
|
31
|
+
constructor(mode?: ShutingyardMode);
|
|
14
32
|
tokenConfigInitialization(): tokenType;
|
|
15
|
-
NextToken2(expr: string, start: number): [string, number, string];
|
|
16
33
|
NextToken(expr: string, start: number): [string, number, string];
|
|
17
34
|
Uniformizer(expr: string): string;
|
|
18
35
|
parse(expr: string, operators?: string[]): Shutingyard;
|
package/esm/maths/shutingyard.js
CHANGED
|
@@ -1,48 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Shutingyard = void 0;
|
|
3
|
+
exports.Shutingyard = exports.ShutingyardMode = exports.ShutingyardType = exports.tokenConstant = void 0;
|
|
4
|
+
exports.tokenConstant = {
|
|
5
|
+
pi: Math.PI,
|
|
6
|
+
e: Math.exp(1)
|
|
7
|
+
};
|
|
8
|
+
var ShutingyardType;
|
|
9
|
+
(function (ShutingyardType) {
|
|
10
|
+
ShutingyardType["VARIABLE"] = "variable";
|
|
11
|
+
ShutingyardType["COEFFICIENT"] = "coefficient";
|
|
12
|
+
ShutingyardType["OPERATION"] = "operation";
|
|
13
|
+
ShutingyardType["CONSTANT"] = "constant";
|
|
14
|
+
ShutingyardType["FUNCTION"] = "function";
|
|
15
|
+
ShutingyardType["MONOM"] = "monom";
|
|
16
|
+
})(ShutingyardType = exports.ShutingyardType || (exports.ShutingyardType = {}));
|
|
17
|
+
var ShutingyardMode;
|
|
18
|
+
(function (ShutingyardMode) {
|
|
19
|
+
ShutingyardMode["POLYNOM"] = "polynom";
|
|
20
|
+
ShutingyardMode["SET"] = "set";
|
|
21
|
+
ShutingyardMode["NUMERIC"] = "numeric";
|
|
22
|
+
})(ShutingyardMode = exports.ShutingyardMode || (exports.ShutingyardMode = {}));
|
|
4
23
|
class Shutingyard {
|
|
5
24
|
_rpn = [];
|
|
6
25
|
_mode;
|
|
7
26
|
_tokenConfig;
|
|
27
|
+
_tokenConstant;
|
|
8
28
|
_uniformize;
|
|
29
|
+
_tokenKeys;
|
|
9
30
|
constructor(mode) {
|
|
10
|
-
this._mode = typeof mode === 'undefined' ?
|
|
31
|
+
this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
|
|
11
32
|
this.tokenConfigInitialization();
|
|
12
33
|
}
|
|
13
|
-
isOperation(token) {
|
|
14
|
-
if (token[0].match(/[+\-*/^]/g)) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
34
|
tokenConfigInitialization() {
|
|
20
|
-
if (this._mode ===
|
|
35
|
+
if (this._mode === ShutingyardMode.SET) {
|
|
21
36
|
this._tokenConfig = {
|
|
22
|
-
'&': { precedence: 3, associative: 'left' },
|
|
23
|
-
'|': { precedence: 3, associative: 'left' },
|
|
24
|
-
'!': { precedence: 4, associative: 'right' },
|
|
25
|
-
'-': { precedence: 2, associative: 'left' }
|
|
37
|
+
'&': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
38
|
+
'|': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
39
|
+
'!': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
40
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION }
|
|
41
|
+
};
|
|
42
|
+
this._uniformize = false;
|
|
43
|
+
}
|
|
44
|
+
else if (this._mode === ShutingyardMode.NUMERIC) {
|
|
45
|
+
this._tokenConfig = {
|
|
46
|
+
'^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
47
|
+
'*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
48
|
+
'/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
49
|
+
'+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
50
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
51
|
+
'%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
|
|
52
|
+
'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
53
|
+
'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
54
|
+
'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
55
|
+
'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
26
56
|
};
|
|
27
57
|
this._uniformize = false;
|
|
28
58
|
}
|
|
29
59
|
else {
|
|
30
60
|
this._tokenConfig = {
|
|
31
|
-
'^': { precedence: 4, associative: 'right' },
|
|
32
|
-
'*': { precedence: 3, associative: 'left' },
|
|
33
|
-
'/': { precedence: 3, associative: 'left' },
|
|
34
|
-
'+': { precedence: 2, associative: 'left' },
|
|
35
|
-
'-': { precedence: 2, associative: 'left' },
|
|
36
|
-
'%': { precedence: 3, associative: 'right' },
|
|
37
|
-
'sin': { precedence: 4, associative: 'right' },
|
|
38
|
-
'cos': { precedence: 4, associative: 'right' },
|
|
39
|
-
'
|
|
61
|
+
'^': { precedence: 4, associative: 'right', type: ShutingyardType.OPERATION },
|
|
62
|
+
'*': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
63
|
+
'/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
|
|
64
|
+
'+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
65
|
+
'-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
|
|
66
|
+
'%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
|
|
67
|
+
'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
68
|
+
'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
69
|
+
'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
40
70
|
};
|
|
41
71
|
this._uniformize = true;
|
|
42
72
|
}
|
|
73
|
+
this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length);
|
|
43
74
|
return this._tokenConfig;
|
|
44
75
|
}
|
|
45
|
-
|
|
76
|
+
NextToken(expr, start) {
|
|
46
77
|
let token, tokenType;
|
|
47
78
|
token = '';
|
|
48
79
|
tokenType = '';
|
|
@@ -59,75 +90,43 @@ class Shutingyard {
|
|
|
59
90
|
tokenType = 'function-argument';
|
|
60
91
|
}
|
|
61
92
|
else {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
93
|
+
for (let key of this._tokenKeys) {
|
|
94
|
+
if (expr.substring(start, start + key.length) === key) {
|
|
95
|
+
token += key;
|
|
96
|
+
tokenType = this._tokenConfig[key].type;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (let key in exports.tokenConstant) {
|
|
101
|
+
if (expr.substring(start, start + key.length) === key) {
|
|
65
102
|
token += key;
|
|
66
|
-
tokenType =
|
|
103
|
+
tokenType = ShutingyardType.CONSTANT;
|
|
67
104
|
break;
|
|
68
105
|
}
|
|
69
106
|
}
|
|
70
107
|
if (token === '') {
|
|
71
108
|
if (expr[start].match(/[0-9]/)) {
|
|
72
|
-
|
|
73
|
-
|
|
109
|
+
if (this._mode === ShutingyardMode.POLYNOM) {
|
|
110
|
+
token = expr.substring(start).match(/^([0-9.,/]+)/)[0];
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
token = expr.substring(start).match(/^([0-9.,]+)/)[0];
|
|
114
|
+
}
|
|
115
|
+
tokenType = ShutingyardType.COEFFICIENT;
|
|
74
116
|
}
|
|
75
117
|
else if (expr[start].match(/[a-zA-Z]/)) {
|
|
76
|
-
token = expr.
|
|
77
|
-
tokenType =
|
|
118
|
+
token = expr.substring(start).match(/^([a-zA-Z])/)[0];
|
|
119
|
+
tokenType = ShutingyardType.VARIABLE;
|
|
78
120
|
}
|
|
79
121
|
else {
|
|
80
122
|
console.log('Unidentified token', expr[start], expr, start);
|
|
81
123
|
token = expr[start];
|
|
82
|
-
tokenType =
|
|
124
|
+
tokenType = ShutingyardType.MONOM;
|
|
83
125
|
}
|
|
84
126
|
}
|
|
85
127
|
}
|
|
86
128
|
return [token, start + token.length, tokenType];
|
|
87
129
|
}
|
|
88
|
-
NextToken(expr, start) {
|
|
89
|
-
let tokenMatch, token, tokenType;
|
|
90
|
-
this.NextToken2(expr, start);
|
|
91
|
-
tokenMatch = (expr.substr(start).match(/^[0-9/a-zA-Z^]+/g)) || [];
|
|
92
|
-
if (expr.substr(start, start + 3).match(/^(sin|cos|tan)/g)) {
|
|
93
|
-
token = expr.substr(start, 3);
|
|
94
|
-
tokenType = 'function';
|
|
95
|
-
}
|
|
96
|
-
else if (tokenMatch.length > 0) {
|
|
97
|
-
token = tokenMatch[0];
|
|
98
|
-
tokenType = 'monom';
|
|
99
|
-
}
|
|
100
|
-
else if (expr[start].match(/[+\-*/^]/g)) {
|
|
101
|
-
token = expr[start];
|
|
102
|
-
tokenType = 'operation';
|
|
103
|
-
}
|
|
104
|
-
else if (expr[start].match(/[&|!]/g)) {
|
|
105
|
-
token = expr[start];
|
|
106
|
-
tokenType = 'operation';
|
|
107
|
-
}
|
|
108
|
-
else if (expr[start] === '(') {
|
|
109
|
-
token = '(';
|
|
110
|
-
tokenType = '(';
|
|
111
|
-
}
|
|
112
|
-
else if (expr[start] === ')') {
|
|
113
|
-
token = ')';
|
|
114
|
-
tokenType = ')';
|
|
115
|
-
}
|
|
116
|
-
else if (expr[start] === ',') {
|
|
117
|
-
token = ',';
|
|
118
|
-
tokenType = 'function-argument';
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
token = tokenMatch[0];
|
|
122
|
-
tokenType = 'monom';
|
|
123
|
-
if (token === '') {
|
|
124
|
-
token = expr[start];
|
|
125
|
-
tokenType = 'monom';
|
|
126
|
-
console.log('SHUTING YARD - NEXT TOKEN: error at ', start);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return [token, start + token.length, tokenType];
|
|
130
|
-
}
|
|
131
130
|
Uniformizer(expr) {
|
|
132
131
|
if (!this._uniformize) {
|
|
133
132
|
return expr;
|
|
@@ -155,11 +154,12 @@ class Shutingyard {
|
|
|
155
154
|
console.log('SECURITY LEVEL 1 EXIT');
|
|
156
155
|
break;
|
|
157
156
|
}
|
|
158
|
-
[token, tokenPos, tokenType] = this.
|
|
157
|
+
[token, tokenPos, tokenType] = this.NextToken(expr, tokenPos);
|
|
159
158
|
switch (tokenType) {
|
|
160
159
|
case 'monom':
|
|
161
160
|
case 'coefficient':
|
|
162
161
|
case 'variable':
|
|
162
|
+
case 'constant':
|
|
163
163
|
outQueue.push({
|
|
164
164
|
token,
|
|
165
165
|
tokenType
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shutingyard.js","sourceRoot":"","sources":["../../src/maths/shutingyard.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"shutingyard.js","sourceRoot":"","sources":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BAE7C,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAqB;wBACvF,gBAAgB,EAAE,CAAC;wBACnB,IAAI,gBAAgB,KAAK,CAAC,EAAE;4BACxB,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;4BACxD,MAAM;yBACT;wBAED,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,EAAC,KAAK,EAAC,SAAS,EAAC,CAAC,CAAC;qBACvD;oBAGD,OAAO,CAAC,GAAG,EAAE,CAAC;oBACd,MAAM;gBACV,KAAK,UAAU;oBACX,OAAO,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,SAAS,EAAC,CAAC,CAAC;oBACjC,MAAM;gBACV;oBAEI,OAAO,CAAC,GAAG,CAAC,iBAAiB,SAAS,MAAM,KAAK,GAAG,CAAC,CAAC;aAC7D;SAIJ;QAGD,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC;IAChB,CAAC;IAID,IAAI,GAAG;QAEH,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;CAGJ;AArUD,kCAqUC"}
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Numeric} from "./maths/numeric";
|
|
2
|
+
import {NumExp} from "./maths/numexp";
|
|
2
3
|
import {Shutingyard} from "./maths/shutingyard";
|
|
3
4
|
import {Random} from "./maths/random";
|
|
4
5
|
import {Fraction, Nthroot} from "./maths/coefficients";
|
|
@@ -10,6 +11,7 @@ import {Line, Circle, Triangle, Point, Vector} from "./maths/geometry";
|
|
|
10
11
|
(<any>window).Pi = {
|
|
11
12
|
ShutingYard: Shutingyard,
|
|
12
13
|
Numeric: Numeric,
|
|
14
|
+
NumExp: NumExp,
|
|
13
15
|
Fraction: Fraction,
|
|
14
16
|
Root: Nthroot,
|
|
15
17
|
Monom: Monom,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module Logicalset
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {Shutingyard} from '../shutingyard';
|
|
6
|
+
import {Shutingyard, ShutingyardMode} from '../shutingyard';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Polynom class can handle polynoms, reorder, resolve, ...
|
|
@@ -30,7 +30,7 @@ import {Shutingyard} from '../shutingyard';
|
|
|
30
30
|
// TODO: Must format the value string to convert some items...
|
|
31
31
|
|
|
32
32
|
// Parse the updated value to the shutingyard algorithm
|
|
33
|
-
this._rpn = new Shutingyard(
|
|
33
|
+
this._rpn = new Shutingyard(ShutingyardMode.SET).parse(value).rpn;
|
|
34
34
|
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/***
|
|
2
2
|
* Monom class
|
|
3
|
-
* Defined as coefficient * literal
|
|
4
|
-
* Examples: 3x^2, 3/5x^2, ...
|
|
5
3
|
*/
|
|
6
4
|
import {Fraction} from "../coefficients";
|
|
7
5
|
import {Numeric} from "../numeric";
|
|
@@ -16,8 +14,10 @@ export class Monom {
|
|
|
16
14
|
private _literal: literalType;
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
|
-
* Create
|
|
20
|
-
*
|
|
17
|
+
* Create a Monom
|
|
18
|
+
* Defined as \\(k \\cdot x^{n}\\), where \\( k,n \in \\mathbb{Q}\\).
|
|
19
|
+
* Examples: \\(3x^2\\) or \\(3/5x^2\\)
|
|
20
|
+
* @param value (optional) string The value that should be parse. Can be a Monom, a Fraction, a string or a number. If nothing is provided, it will return the trivial monom (0).
|
|
21
21
|
*/
|
|
22
22
|
constructor(value?: unknown) {
|
|
23
23
|
this.zero();
|
|
@@ -34,29 +34,35 @@ export class Monom {
|
|
|
34
34
|
// Getter and setter
|
|
35
35
|
// ------------------------------------------
|
|
36
36
|
/**
|
|
37
|
-
* Get the coefficient
|
|
37
|
+
* Get the coefficient \\(k\\) of the Monom \\(k\\cdot x^{n}\\)
|
|
38
|
+
* @returns {Fraction}
|
|
38
39
|
*/
|
|
39
40
|
get coefficient(): Fraction {
|
|
40
41
|
return this._coefficient;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
|
-
* Set the coefficient value of the monom
|
|
45
|
-
* @param F
|
|
45
|
+
* Set the coefficient \\(k\\) value of the monom
|
|
46
|
+
* @param {Fraction | number | string} F
|
|
46
47
|
*/
|
|
47
|
-
set coefficient(F: Fraction) {
|
|
48
|
-
this._coefficient = F;
|
|
48
|
+
set coefficient(F: Fraction | number | string) {
|
|
49
|
+
this._coefficient = new Fraction(F);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
|
-
* Get the literal part
|
|
53
|
+
* Get the literal part of \\(x^{n_1}y^{n_2}\\) as dictionary \\[\\begin{array}{ll}x&=n_1\\\\y&=n_2\\end{array}\\]
|
|
54
|
+
* @returns {literalType}
|
|
53
55
|
*/
|
|
54
56
|
get literal(): literalType {
|
|
55
57
|
return this._literal;
|
|
56
58
|
}
|
|
57
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Get the literal square roots of the Monom.
|
|
62
|
+
* TODO: remove this getter ? Is it used and is it correct ?
|
|
63
|
+
* @returns {literalType}
|
|
64
|
+
*/
|
|
58
65
|
get literalSqrt(): literalType {
|
|
59
|
-
|
|
60
66
|
if (this.isLiteralSquare()) {
|
|
61
67
|
let L: literalType = {}
|
|
62
68
|
for (let key in this._literal) {
|
|
@@ -69,8 +75,8 @@ export class Monom {
|
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
/**
|
|
72
|
-
* Set the literal part of the monom
|
|
73
|
-
* @param L
|
|
78
|
+
* Set the literal part of the monom. Must be a dictionary {x: Fraction, y: Fraction, ...}
|
|
79
|
+
* @param {literalType} L
|
|
74
80
|
*/
|
|
75
81
|
set literal(L: literalType) {
|
|
76
82
|
this._literal = L;
|
|
@@ -230,11 +236,18 @@ export class Monom {
|
|
|
230
236
|
* Display the monom, forcing the '+' sign to appear
|
|
231
237
|
*/
|
|
232
238
|
get displayWithSign(): string {
|
|
233
|
-
// TODO: Rename or remove this getter ?
|
|
234
239
|
let d: String = this.display;
|
|
235
240
|
return (d[0] !== '-' ? '+' : '') + d;
|
|
236
241
|
}
|
|
237
242
|
|
|
243
|
+
get texWithSign(): string {
|
|
244
|
+
if (this.coefficient.isStrictlyPositive()) {
|
|
245
|
+
return '+' + this.tex
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return this.tex
|
|
249
|
+
}
|
|
250
|
+
|
|
238
251
|
/**
|
|
239
252
|
* Get the tex output of the monom
|
|
240
253
|
*/
|
|
@@ -281,15 +294,15 @@ export class Monom {
|
|
|
281
294
|
*/
|
|
282
295
|
parse = (inputStr: unknown): Monom => {
|
|
283
296
|
|
|
284
|
-
if(typeof inputStr === 'string') {
|
|
297
|
+
if (typeof inputStr === 'string') {
|
|
285
298
|
this._shutingYardToReducedMonom(inputStr)
|
|
286
|
-
}else if(typeof inputStr ==='number') {
|
|
299
|
+
} else if (typeof inputStr === 'number') {
|
|
287
300
|
this._coefficient = new Fraction(inputStr)
|
|
288
301
|
this._literal = {}
|
|
289
|
-
}else if(inputStr instanceof Fraction) {
|
|
302
|
+
} else if (inputStr instanceof Fraction) {
|
|
290
303
|
this._coefficient = inputStr.clone()
|
|
291
304
|
this._literal = {}
|
|
292
|
-
}else if(inputStr instanceof Monom){
|
|
305
|
+
} else if (inputStr instanceof Monom) {
|
|
293
306
|
this._coefficient = inputStr._coefficient.clone()
|
|
294
307
|
this._literal = this.copyLiterals(inputStr.literal)
|
|
295
308
|
}
|
|
@@ -384,7 +397,7 @@ export class Monom {
|
|
|
384
397
|
};
|
|
385
398
|
|
|
386
399
|
copyLiterals = (literal: literalType): literalType => {
|
|
387
|
-
let L:literalType = {}
|
|
400
|
+
let L: literalType = {}
|
|
388
401
|
|
|
389
402
|
for (let k in literal) {
|
|
390
403
|
L[k] = literal[k].clone()
|
|
@@ -392,7 +405,7 @@ export class Monom {
|
|
|
392
405
|
return L
|
|
393
406
|
}
|
|
394
407
|
|
|
395
|
-
makeSame = (M: Monom):Monom => {
|
|
408
|
+
makeSame = (M: Monom): Monom => {
|
|
396
409
|
// Copy the literal parts.
|
|
397
410
|
for (let k in M._literal) {
|
|
398
411
|
this.setLetter(k, M._literal[k].clone());
|
|
@@ -451,7 +464,7 @@ export class Monom {
|
|
|
451
464
|
add = (...M: Monom[]): Monom => {
|
|
452
465
|
for (let m of M) {
|
|
453
466
|
if (this.isSameAs(m)) {
|
|
454
|
-
if(this.isZero()){
|
|
467
|
+
if (this.isZero()) {
|
|
455
468
|
this.makeSame(m)
|
|
456
469
|
}
|
|
457
470
|
this._coefficient.add(m.coefficient);
|
|
@@ -469,7 +482,7 @@ export class Monom {
|
|
|
469
482
|
subtract = (...M: Monom[]): Monom => {
|
|
470
483
|
for (let m of M) {
|
|
471
484
|
if (this.isSameAs(m)) {
|
|
472
|
-
if(this.isZero()){
|
|
485
|
+
if (this.isZero()) {
|
|
473
486
|
this.makeSame(m)
|
|
474
487
|
}
|
|
475
488
|
this._coefficient.add(m.clone().coefficient.opposed());
|
|
@@ -312,6 +312,9 @@ export class Line {
|
|
|
312
312
|
isSameAs = (line: Line): Boolean => {
|
|
313
313
|
return this.slope.isEqual(line.slope) && this.height.isEqual(line.height);
|
|
314
314
|
}
|
|
315
|
+
isVertical = (): Boolean => {
|
|
316
|
+
return this.slope.isInfinity()
|
|
317
|
+
}
|
|
315
318
|
simplify = (): Line => {
|
|
316
319
|
let lcm = Numeric.lcm(this._a.denominator, this._b.denominator, this._c.denominator),
|
|
317
320
|
gcd = Numeric.gcd(this._a.numerator, this._b.numerator, this._c.numerator);
|
|
@@ -81,12 +81,20 @@ export class Vector {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// Fractions or a number are give
|
|
84
|
-
if (values[0]
|
|
84
|
+
if (values[0] instanceof Fraction || !isNaN(values[0])) {
|
|
85
85
|
this._x = new Fraction(values[0])
|
|
86
86
|
}
|
|
87
|
-
if (values[1]
|
|
87
|
+
if (values[1] instanceof Fraction || !isNaN(values[1])) {
|
|
88
88
|
this._y = new Fraction(values[1])
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
if(
|
|
92
|
+
(typeof values[0] === 'object' && !isNaN(values[0].x) && !isNaN(values[0].x)) &&
|
|
93
|
+
(typeof values[1] === 'object' && !isNaN(values[1].x) && !isNaN(values[1].x))
|
|
94
|
+
){
|
|
95
|
+
this._x = new Fraction(+values[1].x-values[0].x)
|
|
96
|
+
this._y = new Fraction(+values[1].y-values[0].y)
|
|
97
|
+
}
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
return this;
|