pimath 0.0.23 → 0.0.27
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/demo.css +3 -0
- package/dev/index.html +217 -53
- package/dev/pi.js +581 -220
- 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 +11 -13
- package/docs/classes/algebra.LinearSystem.html +1 -1
- package/docs/classes/algebra.Logicalset.html +3 -3
- package/docs/classes/algebra.Monom.html +50 -49
- package/docs/classes/algebra.Polynom.html +12 -25
- package/docs/classes/algebra.Rational.html +3 -3
- package/docs/classes/coefficients.Fraction.html +10 -6
- package/docs/classes/coefficients.Nthroot.html +3 -1
- package/docs/classes/geometry.Circle.html +3 -1
- package/docs/classes/geometry.Line.html +3 -1
- package/docs/classes/geometry.Point.html +1 -1
- package/docs/classes/geometry.Triangle.html +6 -6
- package/docs/classes/geometry.Vector.html +1 -1
- package/docs/classes/numeric.Numeric.html +5 -5
- package/docs/classes/shutingyard.Shutingyard.html +5 -5
- package/docs/index.html +1 -1
- package/docs/interfaces/geometry.remarquableLines.html +1 -1
- package/docs/modules/algebra.html +1 -1
- package/docs/modules/coefficients.html +1 -1
- package/docs/modules/geometry.html +1 -1
- package/docs/modules/numeric.html +1 -1
- package/docs/modules/random.Random.html +1 -1
- package/docs/modules/random.html +1 -1
- package/docs/modules/shutingyard.html +1 -1
- package/docs/modules.html +1 -1
- package/esm/main.js +2 -0
- package/esm/main.js.map +1 -1
- package/esm/maths/algebra/equation.d.ts +11 -5
- package/esm/maths/algebra/equation.js +159 -52
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/linearSystem.d.ts +3 -4
- package/esm/maths/algebra/linearSystem.js +2 -5
- package/esm/maths/algebra/linearSystem.js.map +1 -1
- package/esm/maths/algebra/logicalset.d.ts +2 -2
- package/esm/maths/algebra/logicalset.js +1 -1
- package/esm/maths/algebra/logicalset.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +5 -3
- package/esm/maths/algebra/monom.js +29 -2
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +6 -6
- package/esm/maths/algebra/polynom.js +4 -4
- 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.d.ts +2 -2
- package/esm/maths/coefficients/fraction.js +1 -1
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/coefficients/nthroot.d.ts +1 -1
- package/esm/maths/coefficients/nthroot.js +4 -1
- package/esm/maths/coefficients/nthroot.js.map +1 -1
- package/esm/maths/geometry/circle.d.ts +12 -3
- package/esm/maths/geometry/circle.js +125 -39
- package/esm/maths/geometry/circle.js.map +1 -1
- package/esm/maths/geometry/line.d.ts +1 -2
- package/esm/maths/geometry/line.js +1 -4
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.d.ts +3 -4
- package/esm/maths/geometry/point.js +18 -15
- package/esm/maths/geometry/point.js.map +1 -1
- package/esm/maths/geometry/triangle.d.ts +0 -1
- package/esm/maths/geometry/triangle.js +3 -4
- package/esm/maths/geometry/triangle.js.map +1 -1
- package/esm/maths/geometry/vector.js +2 -1
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/numexp.d.ts +11 -0
- package/esm/maths/numexp.js +107 -0
- package/esm/maths/numexp.js.map +1 -0
- package/esm/maths/random/rndFraction.js +4 -3
- package/esm/maths/random/rndFraction.js.map +1 -1
- package/esm/maths/random/rndMonom.d.ts +1 -1
- package/esm/maths/random/rndMonom.js +12 -7
- package/esm/maths/random/rndMonom.js.map +1 -1
- package/esm/maths/random/rndPolynom.js +8 -2
- package/esm/maths/random/rndPolynom.js.map +1 -1
- package/esm/maths/random/rndTypes.d.ts +3 -1
- package/esm/maths/shutingyard.d.ts +21 -4
- package/esm/maths/shutingyard.js +72 -74
- package/esm/maths/shutingyard.js.map +1 -1
- package/package.json +3 -5
- package/src/main.ts +2 -0
- package/src/maths/algebra/equation.ts +183 -73
- package/src/maths/algebra/linearSystem.ts +262 -265
- package/src/maths/algebra/logicalset.ts +3 -3
- package/src/maths/algebra/monom.ts +54 -35
- package/src/maths/algebra/polynom.ts +10 -10
- package/src/maths/algebra/rational.ts +1 -1
- package/src/maths/coefficients/fraction.ts +11 -7
- package/src/maths/coefficients/nthroot.ts +8 -1
- package/src/maths/geometry/circle.ts +160 -45
- package/src/maths/geometry/line.ts +4 -8
- package/src/maths/geometry/point.ts +25 -18
- package/src/maths/geometry/triangle.ts +3 -5
- package/src/maths/geometry/vector.ts +4 -3
- package/src/maths/numexp.ts +127 -0
- package/src/maths/random/rndFraction.ts +4 -3
- package/src/maths/random/rndMonom.ts +39 -35
- package/src/maths/random/rndPolynom.ts +13 -3
- package/src/maths/random/rndTypes.ts +4 -2
- package/src/maths/shutingyard.ts +144 -94
- package/tests/algebra/monom.test.ts +18 -4
- package/tests/algebra/polynom.test.ts +19 -4
- package/tests/geometry/circle.test.ts +28 -0
- package/tests/shutingyard.test.ts +3 -3
- package/tsconfig.json +4 -1
- package/typedoc.katex.js +11 -0
- package/docs/classes/algebra.Algebra.Equation.html +0 -26
- package/docs/classes/algebra.Algebra.LinearSystem.html +0 -1
- package/docs/classes/algebra.Algebra.LogicalSet.html +0 -3
- package/docs/classes/algebra.Algebra.Monom.html +0 -111
- package/docs/classes/algebra.Algebra.Polynom.html +0 -36
- package/docs/classes/algebra.Algebra.Rational.html +0 -2
- package/docs/classes/geometry.Geometry.Circle.html +0 -1
- package/docs/classes/geometry.Geometry.Line.html +0 -1
- package/docs/classes/geometry.Geometry.Point.html +0 -1
- package/docs/classes/geometry.Geometry.Triangle.html +0 -9
- package/docs/classes/geometry.Geometry.Vector.html +0 -1
- package/docs/modules/algebra.Algebra.html +0 -1
- package/docs/modules/geometry.Geometry.html +0 -1
- package/src/maths/algebra/monom_bck.backup +0 -746
package/src/maths/shutingyard.ts
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
import {loadHighlighter} from "typedoc/dist/lib/utils/highlighter";
|
|
2
|
+
import exp = require("constants");
|
|
2
3
|
|
|
3
4
|
type tokenType = {
|
|
4
5
|
[key: string]: {
|
|
5
6
|
precedence: number,
|
|
6
|
-
associative: string
|
|
7
|
+
associative: string,
|
|
8
|
+
type: string
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
export const tokenConstant:{[Key:string]:number} = {
|
|
13
|
+
pi: Math.PI,
|
|
14
|
+
e: Math.exp(1)
|
|
15
|
+
}
|
|
16
|
+
export enum ShutingyardType {
|
|
17
|
+
VARIABLE='variable',
|
|
18
|
+
COEFFICIENT='coefficient',
|
|
19
|
+
OPERATION = 'operation',
|
|
20
|
+
CONSTANT = 'constant',
|
|
21
|
+
FUNCTION = 'function',
|
|
22
|
+
MONOM = 'monom'
|
|
23
|
+
}
|
|
24
|
+
export enum ShutingyardMode {
|
|
25
|
+
POLYNOM= 'polynom',
|
|
26
|
+
SET = 'set',
|
|
27
|
+
NUMERIC = 'numeric'
|
|
28
|
+
}
|
|
29
|
+
|
|
10
30
|
export class Shutingyard {
|
|
11
31
|
private _rpn: { token: string, tokenType: string }[] = [];
|
|
12
|
-
readonly _mode:
|
|
32
|
+
readonly _mode: ShutingyardMode;
|
|
13
33
|
private _tokenConfig: tokenType;
|
|
34
|
+
private _tokenConstant: {[Key:string]: number}
|
|
14
35
|
private _uniformize: boolean;
|
|
36
|
+
private _tokenKeys: string[]
|
|
15
37
|
|
|
16
|
-
constructor(mode?:
|
|
17
|
-
this._mode = typeof mode === 'undefined' ?
|
|
38
|
+
constructor(mode?: ShutingyardMode ) {
|
|
39
|
+
this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
|
|
18
40
|
this.tokenConfigInitialization()
|
|
19
41
|
}
|
|
20
42
|
|
|
@@ -23,41 +45,55 @@ export class Shutingyard {
|
|
|
23
45
|
* Defined operations: + - * / ^ sin cos tan
|
|
24
46
|
* @param token
|
|
25
47
|
*/
|
|
26
|
-
isOperation(token: string): boolean {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
48
|
+
// isOperation(token: string): boolean {
|
|
49
|
+
// if (token[0].match(/[+\-*/^]/g)) {
|
|
50
|
+
// return true;
|
|
51
|
+
// }
|
|
52
|
+
// //
|
|
53
|
+
// // if (token.match(/^sin|cos|tan/g)) {
|
|
54
|
+
// // return true;
|
|
55
|
+
// // }
|
|
56
|
+
//
|
|
57
|
+
// return false;
|
|
58
|
+
// }
|
|
37
59
|
|
|
38
60
|
tokenConfigInitialization(): tokenType {
|
|
39
|
-
if (this._mode ===
|
|
61
|
+
if (this._mode === ShutingyardMode.SET) {
|
|
40
62
|
this._tokenConfig = {
|
|
41
|
-
'&': {precedence: 3, associative: 'left'},
|
|
42
|
-
'|': {precedence: 3, associative: 'left'},
|
|
43
|
-
'!': {precedence: 4, associative: 'right'},
|
|
44
|
-
'-': {precedence: 2, associative: 'left'}
|
|
63
|
+
'&': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
64
|
+
'|': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
65
|
+
'!': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
|
|
66
|
+
'-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION}
|
|
45
67
|
}
|
|
46
68
|
this._uniformize = false;
|
|
69
|
+
}else if (this._mode === ShutingyardMode.NUMERIC){
|
|
70
|
+
this._tokenConfig = {
|
|
71
|
+
'^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
|
|
72
|
+
'*': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
73
|
+
'/': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
74
|
+
'+': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
75
|
+
'-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
76
|
+
'%': {precedence: 3, associative: 'right', type: ShutingyardType.OPERATION},
|
|
77
|
+
'sin': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
78
|
+
'cos': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
79
|
+
'tan': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
80
|
+
}
|
|
47
81
|
} else {
|
|
48
82
|
this._tokenConfig = {
|
|
49
|
-
'^': {precedence: 4, associative: 'right'},
|
|
50
|
-
'*': {precedence: 3, associative: 'left'},
|
|
51
|
-
'/': {precedence: 3, associative: 'left'},
|
|
52
|
-
'+': {precedence: 2, associative: 'left'},
|
|
53
|
-
'-': {precedence: 2, associative: 'left'},
|
|
54
|
-
'%': {precedence: 3, associative: 'right'},
|
|
55
|
-
'sin': {precedence: 4, associative: 'right'},
|
|
56
|
-
'cos': {precedence: 4, associative: 'right'},
|
|
57
|
-
'
|
|
83
|
+
'^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
|
|
84
|
+
'*': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
85
|
+
'/': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
86
|
+
'+': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
87
|
+
'-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
88
|
+
'%': {precedence: 3, associative: 'right', type: ShutingyardType.OPERATION},
|
|
89
|
+
'sin': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
90
|
+
'cos': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
91
|
+
'tan': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
58
92
|
}
|
|
59
93
|
this._uniformize = true
|
|
60
94
|
}
|
|
95
|
+
|
|
96
|
+
this._tokenKeys = Object.keys(this._tokenConfig).sort((a,b)=>b.length-a.length)
|
|
61
97
|
return this._tokenConfig
|
|
62
98
|
}
|
|
63
99
|
|
|
@@ -86,12 +122,23 @@ export class Shutingyard {
|
|
|
86
122
|
tokenType = 'function-argument';
|
|
87
123
|
} else{
|
|
88
124
|
// Order token keys by token characters length (descending)
|
|
89
|
-
|
|
125
|
+
// TODO: this is done each time ! SHould be done once !
|
|
126
|
+
// const keys = Object.keys(this._tokenConfig).sort((a,b)=>b.length-a.length)
|
|
90
127
|
|
|
91
|
-
|
|
92
|
-
|
|
128
|
+
// Extract operation and function tokens
|
|
129
|
+
for(let key of this._tokenKeys){
|
|
130
|
+
if(expr.substring(start, start+key.length) === key){
|
|
93
131
|
token += key;
|
|
94
|
-
tokenType =
|
|
132
|
+
tokenType = this._tokenConfig[key].type
|
|
133
|
+
break
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Extract constant
|
|
138
|
+
for(let key in tokenConstant){
|
|
139
|
+
if(expr.substring(start, start+key.length) === key){
|
|
140
|
+
token += key;
|
|
141
|
+
tokenType = ShutingyardType.CONSTANT
|
|
95
142
|
break
|
|
96
143
|
}
|
|
97
144
|
}
|
|
@@ -99,79 +146,81 @@ export class Shutingyard {
|
|
|
99
146
|
if(token===''){
|
|
100
147
|
// No function found ! Might be a coefficient !
|
|
101
148
|
if( expr[start].match(/[0-9]/) ) {
|
|
102
|
-
|
|
103
|
-
|
|
149
|
+
if(this._mode === ShutingyardMode.POLYNOM) {
|
|
150
|
+
token = expr.substring(start).match(/^([0-9.,/]+)/)[0]
|
|
151
|
+
}else{
|
|
152
|
+
token = expr.substring(start).match(/^([0-9.,]+)/)[0]
|
|
153
|
+
}
|
|
154
|
+
tokenType = ShutingyardType.COEFFICIENT
|
|
104
155
|
}else if (expr[start].match(/[a-zA-Z]/)) {
|
|
105
|
-
token = expr.
|
|
106
|
-
tokenType =
|
|
156
|
+
token = expr.substring(start).match(/^([a-zA-Z])/)[0]
|
|
157
|
+
tokenType = ShutingyardType.VARIABLE
|
|
107
158
|
}else{
|
|
108
159
|
console.log('Unidentified token', expr[start], expr, start)
|
|
109
160
|
token = expr[start]
|
|
110
|
-
tokenType =
|
|
161
|
+
tokenType = ShutingyardType.MONOM
|
|
111
162
|
}
|
|
112
163
|
|
|
113
164
|
}
|
|
114
165
|
}
|
|
115
166
|
|
|
116
|
-
|
|
117
|
-
// console.log(token, tokenType)
|
|
118
167
|
return [token, start + token.length, tokenType];
|
|
119
168
|
}
|
|
120
169
|
|
|
121
|
-
NextToken(expr: string, start: number): [string, number, string] {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
170
|
+
// NextToken(expr: string, start: number): [string, number, string] {
|
|
171
|
+
// let tokenMatch: string[], token: string, tokenType: string;
|
|
172
|
+
//
|
|
173
|
+
// this.NextToken2(expr, start)
|
|
174
|
+
// // Detect a fraction monoms or return empty array
|
|
175
|
+
// tokenMatch = (expr.substring(start).match(/^[0-9/a-zA-Z^]+/g)) || [];
|
|
176
|
+
//
|
|
177
|
+
// if (expr.substring(start, start + 3).match(/^(sin|cos|tan)/g)) {
|
|
178
|
+
// token = expr.substring(start, start+3)
|
|
179
|
+
// tokenType = 'function'
|
|
180
|
+
// } else if (tokenMatch.length > 0) {
|
|
181
|
+
// token = tokenMatch[0];
|
|
182
|
+
// tokenType = 'monom';
|
|
183
|
+
// }
|
|
184
|
+
// // It's an operation !
|
|
185
|
+
// else if (expr[start].match(/[+\-*/^]/g)) {
|
|
186
|
+
// token = expr[start];
|
|
187
|
+
// tokenType = 'operation';
|
|
188
|
+
// } else if (expr[start].match(/[&|!]/g)) {
|
|
189
|
+
// token = expr[start];
|
|
190
|
+
// tokenType = 'operation';
|
|
191
|
+
// }
|
|
192
|
+
// // It's an opening parenthese
|
|
193
|
+
// else if (expr[start] === '(') {
|
|
194
|
+
// token = '(';
|
|
195
|
+
// tokenType = '(';
|
|
196
|
+
// }
|
|
197
|
+
// // It's a closing parenthese
|
|
198
|
+
// else if (expr[start] === ')') {
|
|
199
|
+
// token = ')';
|
|
200
|
+
// tokenType = ')';
|
|
201
|
+
// }
|
|
202
|
+
// // It's an argument separator for a function
|
|
203
|
+
// else if (expr[start] === ',') {
|
|
204
|
+
// token = ',';
|
|
205
|
+
// tokenType = 'function-argument';
|
|
206
|
+
// }
|
|
207
|
+
// // It's a monom.
|
|
208
|
+
// else {
|
|
209
|
+
// // TODO: Actually, negative exposant aren't supported.
|
|
210
|
+
// // token = (expr.substring(start).match(/^[\da-z\^]+/g)[0])||'';
|
|
211
|
+
// token = tokenMatch[0];
|
|
212
|
+
// tokenType = 'monom';
|
|
213
|
+
//
|
|
214
|
+
// if (token === '') {
|
|
215
|
+
// token = expr[start];
|
|
216
|
+
// tokenType = 'monom';
|
|
217
|
+
// console.log('SHUTING YARD - NEXT TOKEN: error at ', start);
|
|
218
|
+
// }
|
|
219
|
+
// }
|
|
220
|
+
//
|
|
221
|
+
// // console.log(token, start + token.length, tokenType);
|
|
222
|
+
// return [token, start + token.length, tokenType];
|
|
223
|
+
// }
|
|
175
224
|
|
|
176
225
|
/**
|
|
177
226
|
* Sanitize an expression by adding missing common operation (multiplication between parentheseses)
|
|
@@ -247,6 +296,7 @@ export class Shutingyard {
|
|
|
247
296
|
case 'monom':
|
|
248
297
|
case 'coefficient':
|
|
249
298
|
case 'variable':
|
|
299
|
+
case 'constant':
|
|
250
300
|
outQueue.push({
|
|
251
301
|
token,
|
|
252
302
|
tokenType
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
2
|
import {Monom} from "../../src/maths/algebra";
|
|
3
3
|
import {Random} from "../../src/maths/random";
|
|
4
|
-
import
|
|
4
|
+
import {describe} from "mocha";
|
|
5
|
+
import {Fraction} from "../../src/maths/coefficients";
|
|
5
6
|
|
|
6
|
-
describe('Monom tests', ()=> {
|
|
7
|
-
it('parsing', ()=>{
|
|
7
|
+
describe('Monom tests', () => {
|
|
8
|
+
it('parsing', () => {
|
|
8
9
|
const M0a = new Monom('3');
|
|
9
10
|
expect(M0a.tex).to.be.equal('3')
|
|
10
11
|
|
|
@@ -30,7 +31,7 @@ describe('Monom tests', ()=> {
|
|
|
30
31
|
expect(M5.tex).to.be.equal('-24x^{7/3}y^{-5}')
|
|
31
32
|
})
|
|
32
33
|
|
|
33
|
-
it('basic operations', ()=>{
|
|
34
|
+
it('basic operations', () => {
|
|
34
35
|
const M1 = new Monom('3x'),
|
|
35
36
|
M2 = new Monom('2x')
|
|
36
37
|
|
|
@@ -64,3 +65,16 @@ describe('Monom tests', ()=> {
|
|
|
64
65
|
expect(M.degree().value).to.be.greaterThan(0)
|
|
65
66
|
});
|
|
66
67
|
})
|
|
68
|
+
|
|
69
|
+
describe('Monom as numerical expression WIP', () => {
|
|
70
|
+
it('should create a numerical expression', () => {
|
|
71
|
+
let M = new Monom()
|
|
72
|
+
|
|
73
|
+
M.coefficient = new Fraction(3, 7)
|
|
74
|
+
M.setLetter('3', new Fraction(0.5).reduce())
|
|
75
|
+
|
|
76
|
+
console.log(M.tex)
|
|
77
|
+
// TODO: Problem while displaying numerical expression
|
|
78
|
+
console.log(M.display)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
2
|
import {Fraction} from "../../src/maths/coefficients";
|
|
3
|
-
import {Polynom} from "../../src/maths/algebra";
|
|
3
|
+
import {Monom, Polynom} from "../../src/maths/algebra";
|
|
4
4
|
import {Random} from "../../src/maths/random";
|
|
5
|
+
import {describe} from "mocha";
|
|
5
6
|
|
|
6
7
|
describe('Polynom tests', () => {
|
|
7
8
|
it('Parse polynom', () => {
|
|
@@ -38,10 +39,24 @@ describe('Polynom tests', () => {
|
|
|
38
39
|
it('Random Polynom of degree 5', function () {
|
|
39
40
|
let P = Random.polynom({
|
|
40
41
|
degree: 6,
|
|
41
|
-
numberOfMonoms: 3
|
|
42
|
+
numberOfMonoms: 3,
|
|
43
|
+
positive: true,
|
|
44
|
+
fraction: {
|
|
45
|
+
max: 3
|
|
46
|
+
}
|
|
42
47
|
})
|
|
43
48
|
|
|
44
49
|
expect(P.length).to.be.equal(3)
|
|
45
|
-
expect(P.degree().value).to.be.
|
|
50
|
+
expect(P.degree().value).to.be.equal(6)
|
|
46
51
|
});
|
|
47
|
-
|
|
52
|
+
|
|
53
|
+
it('should calculate correctly the quotient and reminder', function () {
|
|
54
|
+
let P = new Polynom('(x-3)(x^2+5x-4)+12'),
|
|
55
|
+
D = new Polynom('x-3')
|
|
56
|
+
|
|
57
|
+
let euclidian = P.euclidian(D);
|
|
58
|
+
|
|
59
|
+
expect(euclidian.quotient.tex).to.be.equal('x^{2}+5x-4')
|
|
60
|
+
expect(euclidian.reminder.tex).to.be.equal('12')
|
|
61
|
+
});
|
|
62
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {describe} from "mocha";
|
|
2
|
+
import {Circle, Line, Point} from "../../src/maths/geometry";
|
|
3
|
+
import {Fraction} from "../../src/maths/coefficients";
|
|
4
|
+
import {expect} from "chai";
|
|
5
|
+
|
|
6
|
+
describe('Circle', function () {
|
|
7
|
+
it('should calculate the intersection of a circle and a line', function () {
|
|
8
|
+
let C = new Circle(
|
|
9
|
+
new Point(8, 6),
|
|
10
|
+
20,
|
|
11
|
+
true
|
|
12
|
+
),
|
|
13
|
+
LT = new Line('2x+y-32=0'),
|
|
14
|
+
LS = new Line('3x-y-8=0'),
|
|
15
|
+
IPT = C.lineIntersection(LT),
|
|
16
|
+
IPS = C.lineIntersection(LS)
|
|
17
|
+
|
|
18
|
+
expect(IPT).to.be.length(1)
|
|
19
|
+
expect(IPT[0].x.value).to.be.equal(12)
|
|
20
|
+
expect(IPT[0].y.value).to.be.equal(8)
|
|
21
|
+
|
|
22
|
+
expect(IPS).to.be.length(2)
|
|
23
|
+
expect(IPS[0].x.value).to.be.equal(4)
|
|
24
|
+
expect(IPS[0].y.value).to.be.equal(4)
|
|
25
|
+
expect(IPS[1].x.value).to.be.equal(6)
|
|
26
|
+
expect(IPS[1].y.value).to.be.equal(10)
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {Shutingyard} from "../src/maths/shutingyard";
|
|
2
|
+
import {Shutingyard, ShutingyardMode} from "../src/maths/shutingyard";
|
|
3
3
|
|
|
4
4
|
describe('Shuting yard', () => { // the tests container
|
|
5
5
|
it('RPN for polynom', () => {
|
|
@@ -28,8 +28,8 @@ describe('Shuting yard', () => { // the tests container
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
it('Custom RPN', () => {
|
|
31
|
-
const SY1: Shutingyard = new Shutingyard(
|
|
32
|
-
const SY2: Shutingyard = new Shutingyard(
|
|
31
|
+
const SY1: Shutingyard = new Shutingyard(ShutingyardMode.SET).parse('(A|B)&C');
|
|
32
|
+
const SY2: Shutingyard = new Shutingyard(ShutingyardMode.SET).parse('(A-B)&!C');
|
|
33
33
|
expect(SY1.rpn.map(x=>x.token)).to.have.all.members(['A', 'B', '|', 'C', '&'])
|
|
34
34
|
expect(SY2.rpn.map(x=>x.token)).to.have.all.members(['A', 'B', '-', 'C', '!', '&'])
|
|
35
35
|
})
|
package/tsconfig.json
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"src/maths/numeric.ts",
|
|
9
9
|
"src/maths/shutingyard.ts"
|
|
10
10
|
],
|
|
11
|
+
"plugin": [
|
|
12
|
+
"./typedoc.katex.js"
|
|
13
|
+
],
|
|
11
14
|
"out": "docs"
|
|
12
15
|
},
|
|
13
16
|
"compilerOptions": {
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
"module": "commonjs",
|
|
17
20
|
"target": "esnext",
|
|
18
21
|
"allowJs": true,
|
|
19
|
-
// "jsx": "react",
|
|
22
|
+
// "jsx": "react-jsx",
|
|
20
23
|
"sourceMap": true,
|
|
21
24
|
"moduleResolution": "node",
|
|
22
25
|
"declaration": true,
|
package/typedoc.katex.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { JSX } = require("typedoc");
|
|
2
|
+
|
|
3
|
+
exports.load = function (app) {
|
|
4
|
+
app.renderer.hooks.on("head.end", () => {
|
|
5
|
+
return JSX.createElement(JSX.Fragment, null,
|
|
6
|
+
JSX.createElement("link", { rel: "stylesheet", href: "https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css", integrity: "sha384-R4558gYOUz8mP9YWpZJjofhk+zx0AS11p36HnD2ZKj/6JR5z27gSSULCNHIRReVs", crossorigin: "anonymous" },
|
|
7
|
+
JSX.createElement("script", { defer: true, src: "https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js", integrity: "sha384-z1fJDqw8ZApjGO3/unPWUPsIymfsJmyrDVWC8Tv/a1HeOtGmkwNd/7xUS0Xcnvsx", crossorigin: "anonymous" }),
|
|
8
|
+
JSX.createElement("script", { defer: true, src: "https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/contrib/auto-render.min.js", integrity: "sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR", crossorigin: "anonymous", onload: "renderMathInElement(document.body);" })),
|
|
9
|
+
"}); }");
|
|
10
|
+
});
|
|
11
|
+
}
|