pimath 0.0.120 → 0.0.121
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/.eslintrc.js +23 -23
- package/.idea/PI.iml +7 -1
- package/dev/pimath.js +7929 -0
- package/dev/pimath.js.map +1 -0
- package/dist/{pi.js → pimath.js} +7612 -7840
- package/dist/pimath.js.map +1 -0
- package/dist/pimath.min.js +2 -0
- package/dist/pimath.min.js.map +1 -0
- package/docs/assets/main.js +3 -3
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +450 -363
- package/docs/classes/Logicalset.Logicalset.html +119 -110
- package/docs/classes/Polynom.Rational.html +230 -227
- package/docs/classes/Vector-1.Vector.html +319 -273
- package/docs/classes/Vector.Point.html +189 -190
- package/docs/classes/algebra_equation.Equation.html +489 -446
- package/docs/classes/algebra_linearSystem.LinearSystem.html +228 -217
- package/docs/classes/algebra_monom.Monom.html +564 -507
- package/docs/classes/algebra_polynom.Polynom.html +774 -753
- package/docs/classes/coefficients_fraction.Fraction.html +573 -565
- package/docs/classes/geometry_circle.Circle.html +299 -299
- package/docs/classes/geometry_line.Line.html +511 -451
- package/docs/classes/geometry_triangle.Triangle.html +273 -264
- package/docs/classes/numeric.Numeric.html +138 -132
- package/docs/classes/shutingyard.Shutingyard.html +144 -133
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +47 -46
- package/docs/enums/geometry_line.LinePropriety.html +58 -58
- package/docs/enums/shutingyard.ShutingyardMode.html +62 -58
- package/docs/enums/shutingyard.ShutingyardType.html +74 -70
- package/docs/index.html +31 -33
- package/docs/interfaces/algebra_equation.ISolution.html +61 -59
- package/docs/interfaces/algebra_polynom.IEuclidian.html +47 -46
- package/docs/interfaces/geometry_triangle.remarquableLines.html +74 -74
- package/docs/modules/Logicalset.html +33 -38
- package/docs/modules/Polynom.html +33 -38
- package/docs/modules/Vector-1.html +33 -38
- package/docs/modules/Vector.html +33 -38
- package/docs/modules/algebra_equation.html +35 -41
- package/docs/modules/algebra_linearSystem.html +31 -37
- package/docs/modules/algebra_monom.html +33 -39
- package/docs/modules/algebra_polynom.html +35 -41
- package/docs/modules/coefficients_fraction.html +33 -39
- package/docs/modules/geometry_circle.html +31 -37
- package/docs/modules/geometry_line.html +33 -39
- package/docs/modules/geometry_triangle.html +33 -39
- package/docs/modules/numeric.html +31 -37
- package/docs/modules/shutingyard.html +41 -47
- package/docs/types/algebra_monom.literalType.html +33 -37
- package/docs/types/algebra_polynom.PolynomParsingType.html +33 -37
- package/docs/types/coefficients_fraction.FractionParsingType.html +32 -36
- package/docs/types/shutingyard.Token.html +38 -42
- package/docs/types/shutingyard.tokenType.html +40 -44
- package/docs/variables/shutingyard.tokenConstant.html +37 -41
- package/esm/index.d.ts +38 -41
- package/esm/index.js +43 -46
- package/esm/index.js.map +1 -1
- package/esm/maths/algebra/equation.d.ts +119 -117
- package/esm/maths/algebra/equation.js +796 -785
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/linearSystem.d.ts +39 -38
- package/esm/maths/algebra/linearSystem.js +278 -262
- package/esm/maths/algebra/linearSystem.js.map +1 -1
- package/esm/maths/algebra/logicalset.d.ts +28 -28
- package/esm/maths/algebra/logicalset.js +157 -157
- package/esm/maths/algebra/monom.d.ts +206 -206
- package/esm/maths/algebra/monom.js +908 -908
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +157 -157
- package/esm/maths/algebra/polynom.js +1277 -1277
- package/esm/maths/algebra/rational.d.ts +45 -45
- package/esm/maths/algebra/rational.js +183 -183
- package/esm/maths/algebra/study/rationalStudy.d.ts +28 -28
- package/esm/maths/algebra/study/rationalStudy.js +243 -243
- package/esm/maths/algebra/study.d.ts +142 -142
- package/esm/maths/algebra/study.js +377 -377
- package/esm/maths/algebra/study.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +90 -90
- package/esm/maths/coefficients/fraction.js +516 -516
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/coefficients/nthRoot.d.ts +23 -23
- package/esm/maths/coefficients/nthRoot.js +136 -136
- package/esm/maths/geometry/circle.d.ts +45 -45
- package/esm/maths/geometry/circle.js +323 -323
- package/esm/maths/geometry/line.d.ts +99 -99
- package/esm/maths/geometry/line.js +481 -481
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.d.ts +34 -34
- package/esm/maths/geometry/point.js +166 -166
- package/esm/maths/geometry/point.js.map +1 -1
- package/esm/maths/geometry/triangle.d.ts +85 -85
- package/esm/maths/geometry/triangle.js +268 -268
- package/esm/maths/geometry/vector.d.ts +41 -41
- package/esm/maths/geometry/vector.js +197 -197
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/numeric.d.ts +28 -28
- package/esm/maths/numeric.js +180 -180
- package/esm/maths/numexp.d.ts +19 -0
- package/esm/maths/numexp.js +186 -0
- package/esm/maths/numexp.js.map +1 -0
- package/esm/maths/randomization/random.d.ts +23 -23
- package/esm/maths/randomization/random.js +78 -78
- package/esm/maths/randomization/random.js.map +1 -1
- package/esm/maths/randomization/randomCore.d.ts +7 -7
- package/esm/maths/randomization/randomCore.js +21 -21
- package/esm/maths/randomization/rndFraction.d.ts +12 -12
- package/esm/maths/randomization/rndFraction.js +43 -43
- package/esm/maths/randomization/rndGeometryLine.d.ts +12 -12
- package/esm/maths/randomization/rndGeometryLine.js +45 -45
- package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -12
- package/esm/maths/randomization/rndGeometryPoint.js +60 -60
- package/esm/maths/randomization/rndHelpers.d.ts +23 -23
- package/esm/maths/randomization/rndHelpers.js +76 -76
- package/esm/maths/randomization/rndMonom.d.ts +12 -12
- package/esm/maths/randomization/rndMonom.js +52 -52
- package/esm/maths/randomization/rndPolynom.d.ts +13 -13
- package/esm/maths/randomization/rndPolynom.js +74 -74
- package/esm/maths/randomization/rndTypes.d.ts +34 -34
- package/esm/maths/randomization/rndTypes.js +2 -2
- package/esm/maths/shutingyard.d.ts +59 -59
- package/esm/maths/shutingyard.js +442 -442
- package/esm/maths/shutingyard.js.map +1 -1
- package/package.json +11 -11
- package/public/index.html +50 -81
- package/public/playground.html +7 -8
- package/src/index.ts +2 -5
- package/src/maths/algebra/equation.ts +16 -0
- package/src/maths/algebra/linearSystem.ts +20 -0
- package/src/maths/algebra/study.ts +1 -1
- package/src/maths/{expressions/numexp.ts → numexp.ts} +2 -2
- package/tests/algebra/equation.test.ts +19 -5
- package/tests/algebra/linear.test.ts +3 -11
- package/tests/algebra/polynom.test.ts +7 -8
- package/tests/algebra/rationnal.test.ts +1 -1
- package/tests/algebra/study.test.ts +2 -9
- package/tests/coefficients/fraction.test.ts +8 -8
- package/tests/custom.test.ts +33 -37
- package/tests/numeric.test.ts +1 -2
- package/tests/numexp.test.ts +1 -5
- package/tests/shutingyard.test.ts +3 -3
- package/webpack-production-min.config.js +1 -1
- package/webpack-production.config.js +1 -1
- package/webpack.config.js +1 -1
- package/dist/pi.js.map +0 -1
- package/dist/pi.min.js +0 -2
- package/dist/pi.min.js.map +0 -1
- package/docs/classes/expressions_numexp.NumExp.html +0 -236
- package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +0 -317
- package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +0 -285
- package/docs/modules/expressions_numexp.html +0 -71
- package/docs/modules/expressions_polynomexp.html +0 -73
- package/docs/modules.html +0 -76
- package/graph.svg +0 -1033
- package/src/maths/expressions/ExpressionTree.ts +0 -172
- package/src/maths/expressions/expression.ts +0 -286
- package/src/maths/expressions/expressionFactor.ts +0 -190
- package/src/maths/expressions/expressionMember.ts +0 -233
- package/src/maths/expressions/expressionOperators.ts +0 -49
- package/src/maths/expressions/expressionParser.ts +0 -295
- package/src/maths/expressions/factors/ExpFactor.ts +0 -39
- package/src/maths/expressions/factors/ExpFactorConstant.ts +0 -60
- package/src/maths/expressions/factors/ExpFactorExponential.ts +0 -26
- package/src/maths/expressions/factors/ExpFactorNumber.ts +0 -72
- package/src/maths/expressions/factors/ExpFactorPower.ts +0 -42
- package/src/maths/expressions/factors/ExpFactorTrigo.ts +0 -53
- package/src/maths/expressions/factors/ExpFactorVariable.ts +0 -45
- package/src/maths/expressions/internals.ts +0 -14
- package/src/maths/expressions/polynomexp.bkp.ts +0 -221
- package/src/maths/expressions/polynomexp.ts +0 -310
- package/tests/expressions/expressions.test.ts +0 -145
- package/tests/expressions/expressiontree.test.ts +0 -11
- package/tests/polynomexp.test.ts +0 -12
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import {ExpFactorNumber, ExpFactorVariable, ExpressionFactor} from "./internals";
|
|
2
|
-
|
|
3
|
-
export class ExpressionMember {
|
|
4
|
-
private _factors: ExpressionFactor[]
|
|
5
|
-
|
|
6
|
-
constructor(...values: ExpressionFactor[]) {
|
|
7
|
-
this._factors = values
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get factors(): ExpressionFactor[] {
|
|
11
|
-
return this._factors;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
set factors(value: ExpressionFactor[]) {
|
|
15
|
-
this._factors = value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get numerator(): ExpressionFactor[] {
|
|
19
|
-
return this._factors.filter(factor => factor.power > 0)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get denominator(): ExpressionFactor[] {
|
|
23
|
-
return this._factors.filter(factor => factor.power < 0)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get tex(): string {
|
|
27
|
-
return this.toString(true)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get display(): string {
|
|
31
|
-
return this.toString(false)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
toString(asTex: boolean): string {
|
|
35
|
-
if (asTex === undefined) {
|
|
36
|
-
asTex = true
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let outputArray = this.factors.map(x => {
|
|
40
|
-
return {
|
|
41
|
-
value: asTex ? x.tex : x.display,
|
|
42
|
-
valueWithoutParentheses: asTex ? x.makeTeX(1, 0):x.makeDisplay(1, 0),
|
|
43
|
-
denominator: x.power < 0,
|
|
44
|
-
number: (x instanceof ExpFactorNumber)
|
|
45
|
-
}
|
|
46
|
-
}), output: string = ''
|
|
47
|
-
|
|
48
|
-
while (outputArray.length > 0) {
|
|
49
|
-
let item = outputArray.shift()
|
|
50
|
-
|
|
51
|
-
if (item.denominator) {
|
|
52
|
-
if (asTex) {
|
|
53
|
-
output += `\\frac{1}{ ${item.valueWithoutParentheses} }`
|
|
54
|
-
} else {
|
|
55
|
-
output += `1/(${item.valueWithoutParentheses})`
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
if (outputArray.length > 0 && outputArray[0].denominator) {
|
|
59
|
-
let item2 = outputArray.shift()
|
|
60
|
-
if (asTex) {
|
|
61
|
-
output += `\\frac{ ${item.valueWithoutParentheses} }{ ${item2.valueWithoutParentheses} }`
|
|
62
|
-
} else {
|
|
63
|
-
output += `(${item.valueWithoutParentheses})/(${item2.valueWithoutParentheses})`
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
output += item.value
|
|
67
|
-
|
|
68
|
-
// Check if we need to add the multiplication sign.
|
|
69
|
-
if (outputArray.length > 0) {
|
|
70
|
-
if (item.number && outputArray[0].number) {
|
|
71
|
-
if(outputArray.length>1){
|
|
72
|
-
if(!outputArray[1].denominator){
|
|
73
|
-
output +=asTex ? " \\cdot " : "*"
|
|
74
|
-
}
|
|
75
|
-
}else{
|
|
76
|
-
output +=asTex ? " \\cdot " : "*"
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return output
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// opposed(): ExpressionMember {
|
|
89
|
-
// let firstMember = this.factors[0]
|
|
90
|
-
//
|
|
91
|
-
// if (firstMember === undefined) {
|
|
92
|
-
// return this
|
|
93
|
-
// }
|
|
94
|
-
//
|
|
95
|
-
// if (firstMember instanceof ExpFactorNumber) {
|
|
96
|
-
// if (firstMember.hasPower() || firstMember.hasRoot()) {
|
|
97
|
-
// this.factors.unshift(new ExpFactorNumber(-1))
|
|
98
|
-
// } else {
|
|
99
|
-
// firstMember.number = -firstMember.number
|
|
100
|
-
// }
|
|
101
|
-
// } else {
|
|
102
|
-
// this.factors.unshift(new ExpFactorNumber(-1))
|
|
103
|
-
// }
|
|
104
|
-
//
|
|
105
|
-
// return this
|
|
106
|
-
// }
|
|
107
|
-
|
|
108
|
-
add(value: ExpressionFactor): ExpressionMember {
|
|
109
|
-
this._factors.push(value)
|
|
110
|
-
return this
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
addFactors(...values: ExpressionFactor[]): ExpressionMember {
|
|
114
|
-
|
|
115
|
-
for (let value of values) {
|
|
116
|
-
this._factors.push(value)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return this
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
isZero(): Boolean {
|
|
123
|
-
|
|
124
|
-
if (this._factors.length === 0) {
|
|
125
|
-
return true
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
for (let factor of this._factors) {
|
|
129
|
-
if (factor.isZero()) {
|
|
130
|
-
return true
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return false
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
hasVariable(variable?: string): boolean {
|
|
138
|
-
|
|
139
|
-
if (variable === undefined) {
|
|
140
|
-
return !this.isNumeric()
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
for (let factor of this._factors) {
|
|
145
|
-
if (factor.hasVariable(variable)) {
|
|
146
|
-
return true
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return false
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
isNumeric(): boolean {
|
|
154
|
-
for (let factor of this._factors) {
|
|
155
|
-
if (factor instanceof ExpFactorVariable) {
|
|
156
|
-
return false
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return true
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Returns the "coefficient", ie a member with only numeric values factors.
|
|
165
|
-
*/
|
|
166
|
-
coefficient(): ExpressionMember {
|
|
167
|
-
let EM = new ExpressionMember()
|
|
168
|
-
|
|
169
|
-
for (let factor of this.factors) {
|
|
170
|
-
if (factor.isNumeric()) {
|
|
171
|
-
EM.add(factor)
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return EM
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Returns a member with all factors containing a literal part.
|
|
179
|
-
*/
|
|
180
|
-
literal(): ExpressionMember {
|
|
181
|
-
let EM = new ExpressionMember()
|
|
182
|
-
|
|
183
|
-
for (let factor of this.factors) {
|
|
184
|
-
if (!factor.isNumeric()) {
|
|
185
|
-
EM.add(factor)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return EM
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
similarTo(member: ExpressionMember): boolean {
|
|
192
|
-
// TODO: identify two "similar" member, ie with the same literal parts.
|
|
193
|
-
return true
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
reduce(): ExpressionMember {
|
|
197
|
-
// Merge all ExpFactorNumbers that are number
|
|
198
|
-
let numerator = new ExpFactorNumber(1),
|
|
199
|
-
denominator = new ExpFactorNumber(1, -1),
|
|
200
|
-
literal: ExpressionFactor[] = []
|
|
201
|
-
|
|
202
|
-
for (let factor of this.factors) {
|
|
203
|
-
// Reduce the factor
|
|
204
|
-
factor.reduce()
|
|
205
|
-
|
|
206
|
-
if (factor instanceof ExpFactorNumber && factor.root === 1) {
|
|
207
|
-
if (factor.power > 0) {
|
|
208
|
-
numerator.number = numerator.number * (factor.number ** factor.power)
|
|
209
|
-
} else {
|
|
210
|
-
denominator.number = denominator.number * (factor.number ** (-factor.power))
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
literal.push(factor)
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
let EM = new ExpressionMember()
|
|
218
|
-
|
|
219
|
-
// There is a numerator
|
|
220
|
-
if(numerator.number!==1){
|
|
221
|
-
EM.addFactors(numerator)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// No denominator.
|
|
225
|
-
if(denominator.number!==1){
|
|
226
|
-
EM.addFactors(denominator)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Add the other factors
|
|
230
|
-
EM.addFactors(...literal)
|
|
231
|
-
return EM
|
|
232
|
-
}
|
|
233
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {Expression} from "./expression";
|
|
2
|
-
import {ExpFactor} from "./factors/ExpFactor";
|
|
3
|
-
import {ExpressionMember} from "./expressionMember";
|
|
4
|
-
|
|
5
|
-
export class expressionOperators {
|
|
6
|
-
static reduce(expr:Expression):Expression {
|
|
7
|
-
let output = new Expression()
|
|
8
|
-
|
|
9
|
-
return null
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static add(...values: Expression[]): Expression {
|
|
13
|
-
let output = new Expression()
|
|
14
|
-
for(let expr of values){
|
|
15
|
-
output.addMembers(...expr.members)
|
|
16
|
-
}
|
|
17
|
-
return output
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static subtract(a: Expression, b: Expression): Expression{
|
|
21
|
-
let output = new Expression()
|
|
22
|
-
output.add(a)
|
|
23
|
-
output.subtract(b)
|
|
24
|
-
return output
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static multiply(...values: Expression[]): Expression{
|
|
28
|
-
let output = new Expression(),
|
|
29
|
-
member = new ExpressionMember()
|
|
30
|
-
|
|
31
|
-
for(let expr of values){
|
|
32
|
-
member.add(new ExpFactor(expr))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return output.add(member)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static divide(a: Expression, b: Expression): Expression{
|
|
39
|
-
let output = new Expression(),
|
|
40
|
-
member = new ExpressionMember()
|
|
41
|
-
|
|
42
|
-
// Add the first element as factor
|
|
43
|
-
member.add(new ExpFactor(a))
|
|
44
|
-
// Divide by the second element.
|
|
45
|
-
member.add(new ExpFactor(b, -1))
|
|
46
|
-
|
|
47
|
-
return output.add(member)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ExpFactor,
|
|
3
|
-
ExpFactorConstant,
|
|
4
|
-
ExpFactorNumber,
|
|
5
|
-
ExpFactorPower,
|
|
6
|
-
ExpFactorTrigo,
|
|
7
|
-
ExpFactorVariable,
|
|
8
|
-
Expression,
|
|
9
|
-
ExpressionFactor,
|
|
10
|
-
ExpressionMember,
|
|
11
|
-
Shutingyard,
|
|
12
|
-
ShutingyardMode,
|
|
13
|
-
ShutingyardType,
|
|
14
|
-
TRIGONOMETRIC
|
|
15
|
-
} from "./internals";
|
|
16
|
-
|
|
17
|
-
function dlog(...values: unknown[]): void {
|
|
18
|
-
if (false) {
|
|
19
|
-
console.log(...values)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class ExpressionParser {
|
|
24
|
-
private _expression: Expression
|
|
25
|
-
|
|
26
|
-
constructor(value: string) {
|
|
27
|
-
this._expression = this.parse(value)
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get expression(): Expression {
|
|
32
|
-
return this._expression
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
private parse(value: string): Expression {
|
|
37
|
-
let expr: Expression[],
|
|
38
|
-
SY = new Shutingyard(ShutingyardMode.EXPRESSION).parse(value),
|
|
39
|
-
rpn = SY.rpn,
|
|
40
|
-
stack: (Expression | ExpressionMember | ExpressionFactor)[] = []
|
|
41
|
-
|
|
42
|
-
dlog(SY.rpn)
|
|
43
|
-
dlog(SY.normalize(value))
|
|
44
|
-
for (let item of rpn) {
|
|
45
|
-
dlog('BEFORE', item.token, stack.map(s => s.tex))
|
|
46
|
-
switch (item.tokenType) {
|
|
47
|
-
case ShutingyardType.COEFFICIENT:
|
|
48
|
-
stack.push(new ExpFactorNumber(+item.token))
|
|
49
|
-
break
|
|
50
|
-
|
|
51
|
-
case ShutingyardType.CONSTANT:
|
|
52
|
-
stack.push(new ExpFactorConstant(item.token))
|
|
53
|
-
break
|
|
54
|
-
|
|
55
|
-
case ShutingyardType.VARIABLE:
|
|
56
|
-
stack.push(new ExpFactorVariable(item.token))
|
|
57
|
-
break
|
|
58
|
-
|
|
59
|
-
case ShutingyardType.OPERATION:
|
|
60
|
-
// for an operation, the stack length should be two
|
|
61
|
-
if (stack.length >= 2) {
|
|
62
|
-
let b = stack.pop(),
|
|
63
|
-
a = stack.pop()
|
|
64
|
-
// dlog('OPERATION A - B', stack.map(s=>s.tex))
|
|
65
|
-
switch (item.token) {
|
|
66
|
-
case "+":
|
|
67
|
-
stack.push(this.tokenOperationPlus(a, b))
|
|
68
|
-
break
|
|
69
|
-
case "-":
|
|
70
|
-
stack.push(this.tokenOperationMinus(a, b))
|
|
71
|
-
break
|
|
72
|
-
|
|
73
|
-
case "*":
|
|
74
|
-
stack.push(this.tokenOperationMultiply(a, b))
|
|
75
|
-
break;
|
|
76
|
-
|
|
77
|
-
case "/":
|
|
78
|
-
stack.push(this.tokenOperationDivide(a, b))
|
|
79
|
-
break;
|
|
80
|
-
|
|
81
|
-
case "^":
|
|
82
|
-
stack.push(this.tokenOperationPower(a, b))
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
} else {
|
|
87
|
-
// TODO: handle stack size of one when applying an operation
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
break
|
|
91
|
-
|
|
92
|
-
case ShutingyardType.FUNCTION:
|
|
93
|
-
let a = stack.pop()
|
|
94
|
-
|
|
95
|
-
if (item.token === 'sqrt') {
|
|
96
|
-
stack.push(this.tokenOperationSqrt(a))
|
|
97
|
-
} else if (item.token === 'nthrt') {
|
|
98
|
-
stack.push(this.tokenOperationRoot(a, stack.pop()))
|
|
99
|
-
} else if (item.token in TRIGONOMETRIC) {
|
|
100
|
-
if (!(a instanceof Expression)) {
|
|
101
|
-
a = new Expression(a)
|
|
102
|
-
}
|
|
103
|
-
stack.push(new ExpFactorTrigo(item.token, a))
|
|
104
|
-
}
|
|
105
|
-
break
|
|
106
|
-
|
|
107
|
-
default:
|
|
108
|
-
throw('Something went wrong while parsing ' + value + ' at ' + item.token)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
dlog('AFTER', item.token, stack.map(s => s.tex))
|
|
112
|
-
dlog('----------')
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// Build the output expression.
|
|
117
|
-
let output = new Expression()
|
|
118
|
-
for (let item of stack) {
|
|
119
|
-
if (item instanceof Expression) {
|
|
120
|
-
output.addMembers(...item.members)
|
|
121
|
-
} else if (item instanceof ExpressionMember) {
|
|
122
|
-
output.addMembers(item)
|
|
123
|
-
} else if (item instanceof ExpressionFactor) {
|
|
124
|
-
output.addMembers(item)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return output
|
|
129
|
-
// TODO: in the stack, there might be an Expression, ExpressionMember or an ExpressionFactor.
|
|
130
|
-
// @ts-ignore
|
|
131
|
-
// return new Expression(...stack.map(
|
|
132
|
-
// item=>{
|
|
133
|
-
// return item instanceof ExpressionFactor ? new ExpressionMember(item) : item;
|
|
134
|
-
// }
|
|
135
|
-
// ))
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
private tokenOperationPlus(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): Expression {
|
|
140
|
-
|
|
141
|
-
if (a instanceof ExpressionMember || a instanceof ExpressionFactor) {
|
|
142
|
-
a = new Expression(a)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return a.add(b)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
private tokenOperationMultiply(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): ExpressionMember {
|
|
149
|
-
let EM = new ExpressionMember()
|
|
150
|
-
if (a instanceof Expression) {
|
|
151
|
-
EM.addFactors(new ExpFactor(a))
|
|
152
|
-
// a = new ExpFactor(a)
|
|
153
|
-
} else if (a instanceof ExpressionMember) {
|
|
154
|
-
// a.add()
|
|
155
|
-
EM.addFactors(...a.factors)
|
|
156
|
-
// a = new ExpFactor(new Expression(a))
|
|
157
|
-
} else if (a instanceof ExpressionFactor) {
|
|
158
|
-
// Do nothing
|
|
159
|
-
EM.addFactors(a)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (b instanceof Expression) {
|
|
163
|
-
// b = new ExpFactor(b)
|
|
164
|
-
EM.addFactors(new ExpFactor(b))
|
|
165
|
-
} else if (b instanceof ExpressionMember) {
|
|
166
|
-
// b = new ExpFactor(new Expression(b))
|
|
167
|
-
EM.addFactors(...b.factors)
|
|
168
|
-
} else if (b instanceof ExpressionFactor) {
|
|
169
|
-
// Do nothing
|
|
170
|
-
EM.addFactors(b)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return EM
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private tokenOperationDivide(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): ExpressionMember {
|
|
177
|
-
let EM = new ExpressionMember()
|
|
178
|
-
|
|
179
|
-
if (a instanceof Expression) {
|
|
180
|
-
EM.addFactors(new ExpFactor(a))
|
|
181
|
-
} else if (a instanceof ExpressionMember) {
|
|
182
|
-
EM.addFactors(...a.factors)
|
|
183
|
-
} else if (a instanceof ExpressionFactor) {
|
|
184
|
-
// Do nothing
|
|
185
|
-
EM.addFactors(a)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (b instanceof Expression) {
|
|
189
|
-
EM.addFactors(new ExpFactor(b, -1))
|
|
190
|
-
} else if (b instanceof ExpressionMember) {
|
|
191
|
-
EM.addFactors(new ExpFactor(new Expression(b), -1))
|
|
192
|
-
} else if (b instanceof ExpressionFactor) {
|
|
193
|
-
// Do nothing
|
|
194
|
-
b.power = -b.power
|
|
195
|
-
EM.addFactors(b)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return EM
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private tokenOperationPower(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): ExpressionFactor {
|
|
202
|
-
if (a instanceof Expression) {
|
|
203
|
-
// Do nothing
|
|
204
|
-
} else if (a instanceof ExpressionMember) {
|
|
205
|
-
a = new Expression(a)
|
|
206
|
-
} else if (a instanceof ExpressionFactor) {
|
|
207
|
-
// Make a new factor of itself
|
|
208
|
-
console.log(a)
|
|
209
|
-
if (a.power === 1 && b instanceof ExpFactorNumber) {
|
|
210
|
-
a.power = b.value
|
|
211
|
-
return a
|
|
212
|
-
} else {
|
|
213
|
-
a = new Expression(new ExpressionMember(a))
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// b can be :
|
|
218
|
-
// number 3
|
|
219
|
-
// any other expression
|
|
220
|
-
//
|
|
221
|
-
if (b instanceof Expression) {
|
|
222
|
-
// Do nothing
|
|
223
|
-
} else if (b instanceof ExpressionMember) {
|
|
224
|
-
b = new Expression(b)
|
|
225
|
-
} else if (b instanceof ExpFactorNumber) {
|
|
226
|
-
return new ExpFactor(a, b.value)
|
|
227
|
-
} else if (b instanceof ExpressionFactor) {
|
|
228
|
-
b = new Expression(new ExpressionMember(b))
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return new ExpFactorPower(a, b)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private tokenOperationMinus(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): Expression {
|
|
235
|
-
if (a instanceof ExpressionMember) {
|
|
236
|
-
a = new Expression(a)
|
|
237
|
-
} else if (a instanceof ExpressionFactor) {
|
|
238
|
-
a = new Expression(new ExpressionMember(a))
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (b instanceof ExpressionMember) {
|
|
242
|
-
b = new Expression(b)
|
|
243
|
-
} else if (b instanceof ExpressionFactor) {
|
|
244
|
-
b = new Expression(new ExpressionMember(b))
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return a.subtract(b)
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
private tokenOperationSqrt(a: Expression | ExpressionMember | ExpressionFactor): Expression | ExpressionFactor {
|
|
252
|
-
|
|
253
|
-
// Transform the argument to expression
|
|
254
|
-
if (a instanceof Expression) {
|
|
255
|
-
return new ExpFactor(a, 1, 2)
|
|
256
|
-
} else if (a instanceof ExpressionMember) {
|
|
257
|
-
if (a.factors.length === 1 && !a.factors[0].hasPower()) {
|
|
258
|
-
a.factors[0].root = 2
|
|
259
|
-
return a.factors[0]
|
|
260
|
-
} else {
|
|
261
|
-
return new ExpFactor(new Expression(a), 1, 2)
|
|
262
|
-
}
|
|
263
|
-
} else if (a instanceof ExpressionFactor) {
|
|
264
|
-
if (!a.hasPower()) {
|
|
265
|
-
a.root = 2
|
|
266
|
-
return a
|
|
267
|
-
} else {
|
|
268
|
-
return new ExpFactor(new Expression(a), 1, 2)
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
// Fallback
|
|
272
|
-
return a
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
private tokenOperationRoot(a:Expression | ExpressionMember | ExpressionFactor, b:Expression | ExpressionMember | ExpressionFactor): ExpFactor {
|
|
276
|
-
// a is the power
|
|
277
|
-
// b is the argument
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
// Transform the argument to expression
|
|
282
|
-
if (!(b instanceof Expression)) {
|
|
283
|
-
b = new Expression(b)
|
|
284
|
-
}
|
|
285
|
-
// the "a" value is the nth root. It must be a number
|
|
286
|
-
let n = 2
|
|
287
|
-
if (a instanceof ExpFactorNumber) {
|
|
288
|
-
n = a.number
|
|
289
|
-
} else {
|
|
290
|
-
throw "The nth root value must be a number, not " + a.tex
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return new ExpFactor(b, 1, n)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {Expression, ExpressionFactor} from "../internals";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export class ExpFactor extends ExpressionFactor {
|
|
5
|
-
|
|
6
|
-
derivative(variable: string): Expression {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
integrate(variable: string): Expression {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
makeTeX(numberOfFactors?: number, position?: number): string {
|
|
15
|
-
// TODO: no need to wrap if it's single ?
|
|
16
|
-
if (this.hasRoot() || this.hasPower()) {
|
|
17
|
-
return this.texPower(this.texRoot(
|
|
18
|
-
this.argument.tex
|
|
19
|
-
// this.wrapWithParentheses(this.argument.tex)
|
|
20
|
-
))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (numberOfFactors === 1) {
|
|
24
|
-
return this.argument.tex
|
|
25
|
-
} else {
|
|
26
|
-
return this.argument.isFactor() ? this.argument.tex : this.wrapWithParentheses(this.argument.tex)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
makeDisplay(numberOfFactors?: number, position?: number): string {
|
|
31
|
-
if (this.hasRoot() || this.hasPower()) {
|
|
32
|
-
return this.displayPower(this.texRoot(
|
|
33
|
-
this.wrapWithParentheses(this.argument.display, false)
|
|
34
|
-
))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return this.argument.isFactor() ? this.argument.display : this.wrapWithParentheses(this.argument.display)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {Expression} from "../internals";
|
|
2
|
-
import {ExpressionFactor} from "../internals";
|
|
3
|
-
|
|
4
|
-
export class ExpFactorConstant extends ExpressionFactor {
|
|
5
|
-
private _constant: string
|
|
6
|
-
private _availableConstant: { [Key: string]:{value: number, tex: string} }
|
|
7
|
-
constructor(value: string, power?: number, root?: number) {
|
|
8
|
-
if (typeof value !== "string") {
|
|
9
|
-
throw `The number ${value} is not a valid value.`
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
super(null, power, root);
|
|
13
|
-
|
|
14
|
-
this._availableConstant = {
|
|
15
|
-
'pi': {
|
|
16
|
-
value: Math.PI,
|
|
17
|
-
tex: '\\pi'
|
|
18
|
-
},
|
|
19
|
-
'e': {
|
|
20
|
-
value: Math.E,
|
|
21
|
-
tex: '\\text{e}'
|
|
22
|
-
},
|
|
23
|
-
'phi': {
|
|
24
|
-
value: (1+ Math.sqrt(5))/2,
|
|
25
|
-
tex: '\\phi'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this._constant = value
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get value():number {
|
|
33
|
-
// TODO: constant value
|
|
34
|
-
return Math.pow(0, this.root/this.root)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get constant(): string {
|
|
38
|
-
return this._constant
|
|
39
|
-
}
|
|
40
|
-
makeTeX(): string {
|
|
41
|
-
let tex = this._availableConstant[this._constant].tex
|
|
42
|
-
return this.texPower(this.texRoot(tex))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
derivative(variable: string): Expression {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
integrate(variable: string): Expression {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
hasVariable(variable?: string): boolean {
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
makeDisplay(numberOfFactors?: number, position?: number): string {
|
|
58
|
-
return this._constant;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {Expression} from "../internals";
|
|
2
|
-
import {ExpressionFactor} from "../internals";
|
|
3
|
-
|
|
4
|
-
export class ExpFactorExponential extends ExpressionFactor {
|
|
5
|
-
|
|
6
|
-
derivative(variable: string): Expression {
|
|
7
|
-
return undefined
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
integrate(variable: string): Expression {
|
|
11
|
-
return undefined
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
makeTeX(): string {
|
|
15
|
-
let tex: string = `\\text{e}^{ ${ this.argument.tex } }`
|
|
16
|
-
|
|
17
|
-
return this.texPowerAndRoot(tex)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
makeDisplay(numberOfFactors?: number, position?: number): string {
|
|
21
|
-
let display: string = `e^( ${ this.argument.tex } )`
|
|
22
|
-
|
|
23
|
-
return this.displayPowerAndRoot(display)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}
|