pimath 0.0.64 → 0.0.67
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/dist/pi.js +236 -56
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/docs/assets/highlight.css +78 -78
- package/docs/assets/main.js +52 -52
- package/docs/assets/style.css +1413 -1413
- package/docs/classes/Logicalset.Logicalset-1.html +4 -4
- package/docs/classes/Polynom.Rational.html +3 -3
- package/docs/classes/algebra_equation.Equation.html +25 -25
- package/docs/classes/algebra_monom.Monom.html +113 -113
- package/docs/classes/algebra_polynom.Polynom.html +29 -29
- package/docs/classes/coefficients_fraction.Fraction.html +18 -18
- package/docs/classes/coefficients_nthroot.NthRoot.html +2 -2
- package/docs/classes/geometry_circle.Circle.html +2 -2
- package/docs/classes/geometry_line.Line.html +2 -2
- package/docs/classes/geometry_triangle.Triangle.html +16 -16
- package/docs/classes/numeric.Numeric.html +13 -13
- package/docs/classes/shutingyard.Shutingyard.html +17 -17
- package/docs/index.html +10 -10
- package/docs/interfaces/algebra_equation.ISolution.html +2 -2
- package/docs/modules/Logicalset.html +2 -2
- package/docs/modules/Polynom.html +2 -2
- package/docs/modules/Vector.html +2 -2
- package/esm/maths/algebra/equation.js +2 -2
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +4 -5
- package/esm/maths/algebra/polynom.js +2 -2
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +8 -10
- package/esm/maths/algebra/rational.js +9 -5
- package/esm/maths/algebra/study/rationalStudy.d.ts +1 -2
- package/esm/maths/algebra/study/rationalStudy.js +32 -20
- package/esm/maths/algebra/study/rationalStudy.js.map +1 -1
- package/esm/maths/algebra/study.d.ts +16 -24
- package/esm/maths/algebra/study.js +65 -24
- package/esm/maths/algebra/study.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +8 -6
- package/esm/maths/coefficients/fraction.js +34 -17
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/expressions/expression.d.ts +21 -0
- package/esm/maths/expressions/expression.js +161 -0
- package/esm/maths/expressions/expression.js.map +1 -0
- package/esm/maths/expressions/expressionFactor.d.ts +29 -0
- package/esm/maths/expressions/expressionFactor.js +109 -0
- package/esm/maths/expressions/expressionFactor.js.map +1 -0
- package/esm/maths/expressions/expressionMember.d.ts +16 -0
- package/esm/maths/expressions/expressionMember.js +90 -0
- package/esm/maths/expressions/expressionMember.js.map +1 -0
- package/esm/maths/expressions/expressionOperators.d.ts +8 -0
- package/esm/maths/expressions/expressionOperators.js +42 -0
- package/esm/maths/expressions/expressionOperators.js.map +1 -0
- package/esm/maths/expressions/expressionParser.d.ts +12 -0
- package/esm/maths/expressions/expressionParser.js +219 -0
- package/esm/maths/expressions/expressionParser.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactor.d.ts +7 -0
- package/esm/maths/expressions/factors/ExpFactor.js +22 -0
- package/esm/maths/expressions/factors/ExpFactor.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorConstant.d.ts +13 -0
- package/esm/maths/expressions/factors/ExpFactorConstant.js +49 -0
- package/esm/maths/expressions/factors/ExpFactorConstant.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorExponential.d.ts +7 -0
- package/esm/maths/expressions/factors/ExpFactorExponential.js +18 -0
- package/esm/maths/expressions/factors/ExpFactorExponential.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorNumber.d.ts +13 -0
- package/esm/maths/expressions/factors/ExpFactorNumber.js +36 -0
- package/esm/maths/expressions/factors/ExpFactorNumber.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorPower.d.ts +9 -0
- package/esm/maths/expressions/factors/ExpFactorPower.js +22 -0
- package/esm/maths/expressions/factors/ExpFactorPower.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorSin.d.ts +7 -0
- package/esm/maths/expressions/factors/ExpFactorSin.js +22 -0
- package/esm/maths/expressions/factors/ExpFactorSin.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorTrigo.d.ts +19 -0
- package/esm/maths/expressions/factors/ExpFactorTrigo.js +40 -0
- package/esm/maths/expressions/factors/ExpFactorTrigo.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorVariable.d.ts +12 -0
- package/esm/maths/expressions/factors/ExpFactorVariable.js +33 -0
- package/esm/maths/expressions/factors/ExpFactorVariable.js.map +1 -0
- package/esm/maths/expressions/internals.d.ts +12 -0
- package/esm/maths/expressions/internals.js +29 -0
- package/esm/maths/expressions/internals.js.map +1 -0
- package/esm/maths/shutingyard.d.ts +4 -1
- package/esm/maths/shutingyard.js +137 -21
- package/esm/maths/shutingyard.js.map +1 -1
- package/graph.svg +1033 -0
- package/package.json +1 -1
- package/src/maths/algebra/equation.ts +2 -2
- package/src/maths/algebra/polynom.ts +1 -0
- package/src/maths/algebra/study/rationalStudy.ts +26 -12
- package/src/maths/algebra/study.ts +48 -5
- package/src/maths/coefficients/fraction.ts +111 -86
- package/src/maths/expressions/expression.ts +191 -0
- package/src/maths/expressions/expressionFactor.ts +138 -0
- package/src/maths/expressions/expressionMember.ts +114 -0
- package/src/maths/expressions/expressionOperators.ts +49 -0
- package/src/maths/expressions/expressionParser.ts +249 -0
- package/src/maths/expressions/factors/ExpFactor.ts +26 -0
- package/src/maths/expressions/factors/ExpFactorConstant.ts +56 -0
- package/src/maths/expressions/factors/ExpFactorExponential.ts +19 -0
- package/src/maths/expressions/factors/ExpFactorNumber.ts +44 -0
- package/src/maths/expressions/factors/ExpFactorPower.ts +24 -0
- package/src/maths/expressions/factors/ExpFactorTrigo.ts +44 -0
- package/src/maths/expressions/factors/ExpFactorVariable.ts +40 -0
- package/src/maths/expressions/internals.ts +14 -0
- package/src/maths/shutingyard.ts +156 -26
- package/tests/algebra/study.test.ts +29 -4
- package/tests/coefficients/fraction.test.ts +17 -0
- package/tests/expressions/expressions.test.ts +124 -0
- package/tests/shutingyard.test.ts +22 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40_[Changes]/shelved.patch +0 -21
- package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40__Changes_.xml +0 -4
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
get expression(): Expression {
|
|
31
|
+
return this._expression
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
private parse(value: string): Expression {
|
|
36
|
+
let expr: Expression[],
|
|
37
|
+
SY = new Shutingyard(ShutingyardMode.EXPRESSION).parse(value),
|
|
38
|
+
rpn = SY.rpn,
|
|
39
|
+
stack: (Expression | ExpressionMember | ExpressionFactor)[] = []
|
|
40
|
+
|
|
41
|
+
dlog(SY.rpn)
|
|
42
|
+
dlog(SY.normalize(value))
|
|
43
|
+
for (let item of rpn) {
|
|
44
|
+
dlog('BEFORE', item.token, stack.map(s => s.tex))
|
|
45
|
+
switch (item.tokenType) {
|
|
46
|
+
case ShutingyardType.COEFFICIENT:
|
|
47
|
+
stack.push(new ExpFactorNumber(+item.token))
|
|
48
|
+
break
|
|
49
|
+
|
|
50
|
+
case ShutingyardType.CONSTANT:
|
|
51
|
+
stack.push(new ExpFactorConstant(item.token))
|
|
52
|
+
break
|
|
53
|
+
|
|
54
|
+
case ShutingyardType.VARIABLE:
|
|
55
|
+
stack.push(new ExpFactorVariable(item.token))
|
|
56
|
+
break
|
|
57
|
+
|
|
58
|
+
case ShutingyardType.OPERATION:
|
|
59
|
+
// for an operation, the stack length should be two
|
|
60
|
+
if (stack.length >= 2) {
|
|
61
|
+
let b = stack.pop(),
|
|
62
|
+
a = stack.pop()
|
|
63
|
+
// dlog('OPERATION A - B', stack.map(s=>s.tex))
|
|
64
|
+
switch (item.token) {
|
|
65
|
+
case "+":
|
|
66
|
+
stack.push(this.tokenOperationPlus(a, b))
|
|
67
|
+
break
|
|
68
|
+
case "-":
|
|
69
|
+
stack.push(this.tokenOperationMinus(a, b))
|
|
70
|
+
break
|
|
71
|
+
|
|
72
|
+
case "*":
|
|
73
|
+
stack.push(this.tokenOperationMultiply(a, b))
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case "/":
|
|
77
|
+
stack.push(this.tokenOperationDivide(a, b))
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case "^":
|
|
81
|
+
stack.push(this.tokenOperationPower(a, b))
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
} else {
|
|
86
|
+
// TODO: handle stack size of one when applying an operation
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
break
|
|
90
|
+
|
|
91
|
+
case ShutingyardType.FUNCTION:
|
|
92
|
+
let a = stack.pop()
|
|
93
|
+
|
|
94
|
+
if (item.token === 'sqrt') {
|
|
95
|
+
let b = stack.pop()
|
|
96
|
+
// Transform the argument to expression
|
|
97
|
+
if(! (a instanceof Expression)){a = new Expression(a)}
|
|
98
|
+
stack.push(new ExpFactor(a, 1, 2))
|
|
99
|
+
} else if (item.token === 'nthrt') {
|
|
100
|
+
// TODO: suppose it's a number
|
|
101
|
+
let b = stack.pop()
|
|
102
|
+
// Transform the argument to expression
|
|
103
|
+
if(! (b instanceof Expression)){b = new Expression(b)}
|
|
104
|
+
// the "a" value is the nth root. It must be a number
|
|
105
|
+
let n = 2
|
|
106
|
+
if(a instanceof ExpFactorNumber){
|
|
107
|
+
n = a.number
|
|
108
|
+
}else{
|
|
109
|
+
throw "The nth root value must be a number, not " + a.tex
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
stack.push(new ExpFactor(b, 1, n))
|
|
113
|
+
} else if (item.token in TRIGONOMETRIC) {
|
|
114
|
+
if(! (a instanceof Expression)){a = new Expression(a)}
|
|
115
|
+
stack.push(new ExpFactorTrigo(item.token, a))
|
|
116
|
+
}
|
|
117
|
+
break
|
|
118
|
+
|
|
119
|
+
default:
|
|
120
|
+
throw('Something went wrong while parsing ' + value + ' at ' + item.token)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
dlog('AFTER', item.token, stack.map(s => s.tex))
|
|
124
|
+
dlog('----------')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
// Build the output expression.
|
|
129
|
+
let output = new Expression()
|
|
130
|
+
for (let item of stack) {
|
|
131
|
+
if (item instanceof Expression) {
|
|
132
|
+
output.addMembers(...item.members)
|
|
133
|
+
} else if (item instanceof ExpressionMember) {
|
|
134
|
+
output.addMembers(item)
|
|
135
|
+
} else if (item instanceof ExpressionFactor) {
|
|
136
|
+
output.addMembers(item)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return output
|
|
141
|
+
// TODO: in the stack, there might be an Expression, ExpressionMember or an ExpressionFactor.
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
// return new Expression(...stack.map(
|
|
144
|
+
// item=>{
|
|
145
|
+
// return item instanceof ExpressionFactor ? new ExpressionMember(item) : item;
|
|
146
|
+
// }
|
|
147
|
+
// ))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
private tokenOperationPlus(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): Expression {
|
|
152
|
+
|
|
153
|
+
if (a instanceof ExpressionMember || a instanceof ExpressionFactor) {
|
|
154
|
+
a = new Expression(a)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return a.add(b)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private tokenOperationMultiply(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): ExpressionMember {
|
|
161
|
+
if (a instanceof Expression) {
|
|
162
|
+
a = new ExpFactor(a)
|
|
163
|
+
} else if (a instanceof ExpressionMember) {
|
|
164
|
+
a = new ExpFactor(new Expression(a))
|
|
165
|
+
} else if (a instanceof ExpressionFactor) {
|
|
166
|
+
// Do nothing
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (b instanceof Expression) {
|
|
170
|
+
b = new ExpFactor(b)
|
|
171
|
+
} else if (b instanceof ExpressionMember) {
|
|
172
|
+
b = new ExpFactor(new Expression(b))
|
|
173
|
+
} else if (b instanceof ExpressionFactor) {
|
|
174
|
+
// Do nothing
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// a and b are ExpressionFactors - multiply them
|
|
178
|
+
|
|
179
|
+
return new ExpressionMember(a, b)
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private tokenOperationDivide(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): ExpressionMember {
|
|
184
|
+
if (a instanceof Expression) {
|
|
185
|
+
a = new ExpFactor(a)
|
|
186
|
+
} else if (a instanceof ExpressionMember) {
|
|
187
|
+
a = new ExpFactor(new Expression(a))
|
|
188
|
+
} else if (a instanceof ExpressionFactor) {
|
|
189
|
+
// Do nothing
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (b instanceof Expression) {
|
|
193
|
+
b = new ExpFactor(b, -1)
|
|
194
|
+
} else if (b instanceof ExpressionMember) {
|
|
195
|
+
b = new ExpFactor(new Expression(b), -1)
|
|
196
|
+
} else if (b instanceof ExpressionFactor) {
|
|
197
|
+
// Do nothing
|
|
198
|
+
b.power = -b.power
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// a and b are ExpressionFactors - multiply them
|
|
202
|
+
return new ExpressionMember(a, b)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private tokenOperationPower(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): ExpressionFactor {
|
|
206
|
+
if (a instanceof Expression) {
|
|
207
|
+
// Do nothing
|
|
208
|
+
} else if (a instanceof ExpressionMember) {
|
|
209
|
+
a = new Expression(a)
|
|
210
|
+
} else if (a instanceof ExpressionFactor) {
|
|
211
|
+
// Make a new factor of itself
|
|
212
|
+
a = new Expression(new ExpressionMember(a))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// b can be :
|
|
216
|
+
// number 3
|
|
217
|
+
// any other expression
|
|
218
|
+
//
|
|
219
|
+
if (b instanceof Expression) {
|
|
220
|
+
// Do nothing
|
|
221
|
+
} else if (b instanceof ExpressionMember) {
|
|
222
|
+
b = new Expression(b)
|
|
223
|
+
} else if (b instanceof ExpFactorNumber) {
|
|
224
|
+
return new ExpFactor(a, b.value)
|
|
225
|
+
} else if (b instanceof ExpressionFactor) {
|
|
226
|
+
b = new Expression(new ExpressionMember(b))
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return new ExpFactorPower(a, b)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private tokenOperationMinus(a: Expression | ExpressionMember | ExpressionFactor, b: Expression | ExpressionMember | ExpressionFactor): Expression {
|
|
233
|
+
if (a instanceof ExpressionMember) {
|
|
234
|
+
a = new Expression(a)
|
|
235
|
+
} else if (a instanceof ExpressionFactor) {
|
|
236
|
+
a = new Expression(new ExpressionMember(a))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (b instanceof ExpressionMember) {
|
|
240
|
+
b = new Expression(b)
|
|
241
|
+
} else if (b instanceof ExpressionFactor) {
|
|
242
|
+
b = new Expression(new ExpressionMember(b))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return a.subtract(b)
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {Expression} from "../internals";
|
|
2
|
+
import {ExpressionFactor} from "../internals";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class ExpFactor extends ExpressionFactor {
|
|
6
|
+
|
|
7
|
+
derivative(variable: string): Expression {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
integrate(variable: string): Expression {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
makeTeX(numberOfFactors?: number, position?: number): string {
|
|
16
|
+
// If there is a root value, no need to make further checks
|
|
17
|
+
// TODO: no need to wrap if it's single ?
|
|
18
|
+
if(this.hasRoot() || this.hasPower()){
|
|
19
|
+
return this.texPower(this.texRoot(
|
|
20
|
+
this.wrapWithParentheses(this.argument.tex)
|
|
21
|
+
))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return this.argument.isFactor() ? this.argument.tex: this.wrapWithParentheses(this.argument.tex)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {Expression} from "../internals";
|
|
2
|
+
import {ExpressionFactor} from "../internals";
|
|
3
|
+
|
|
4
|
+
export class ExpFactorNumber extends ExpressionFactor {
|
|
5
|
+
private _number: number
|
|
6
|
+
constructor(value: number, power?: number, root?: number) {
|
|
7
|
+
super(null, power, root);
|
|
8
|
+
|
|
9
|
+
if (typeof value !== "number") {
|
|
10
|
+
throw `The number ${value} is not a valid value.`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
this._number = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get value():number {
|
|
17
|
+
return Math.pow(this._number, this.root/this.root)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get number(): number {
|
|
21
|
+
return this._number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
set number(value: number) {
|
|
26
|
+
this._number = value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
makeTeX(): string {
|
|
30
|
+
return this.texPower(this.texRoot(this._number.toString()))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
derivative(variable: string): Expression {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
integrate(variable: string): Expression {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
hasVariable(variable?: string): boolean {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {Expression} from "../internals";
|
|
2
|
+
import {ExpressionFactor} from "../internals";
|
|
3
|
+
|
|
4
|
+
export class ExpFactorPower extends ExpressionFactor {
|
|
5
|
+
private powerArgument: Expression
|
|
6
|
+
constructor(radical: Expression, power: Expression, power2?: number, root?:number) {
|
|
7
|
+
super(radical, power2, root);
|
|
8
|
+
|
|
9
|
+
this.powerArgument = power
|
|
10
|
+
}
|
|
11
|
+
derivative(variable: string): Expression {
|
|
12
|
+
return undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
integrate(variable: string): Expression {
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
makeTeX(): string {
|
|
20
|
+
let tex: string = `{ ${ this.argument.tex } }^{ ${this.powerArgument.tex } }`
|
|
21
|
+
|
|
22
|
+
return this.texPowerAndRoot(this.wrapWithParentheses(tex))
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {Expression} from "../internals";
|
|
2
|
+
import {ExpressionFactor} from "../internals";
|
|
3
|
+
|
|
4
|
+
export enum TRIGONOMETRIC {
|
|
5
|
+
sin='sin',
|
|
6
|
+
cos='cos',
|
|
7
|
+
tan='tan',
|
|
8
|
+
cot='cot',
|
|
9
|
+
asin='asin',
|
|
10
|
+
atan='atan',
|
|
11
|
+
acos='acos',
|
|
12
|
+
acot='acot'
|
|
13
|
+
}
|
|
14
|
+
export class ExpFactorTrigo extends ExpressionFactor {
|
|
15
|
+
|
|
16
|
+
private _trigo: string
|
|
17
|
+
constructor(trigo: string, argument: Expression, power?: number, root?: number) {
|
|
18
|
+
|
|
19
|
+
super(argument, power, root);
|
|
20
|
+
|
|
21
|
+
if(! (trigo in TRIGONOMETRIC)){
|
|
22
|
+
throw `The ${ trigo } is not a valid trigonometric function.`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this._trigo = trigo
|
|
26
|
+
}
|
|
27
|
+
derivative(variable: string): Expression {
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
integrate(variable: string): Expression {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
makeTeX(): string {
|
|
36
|
+
let tex = `\\${this._trigo}`
|
|
37
|
+
if(this.root>1){
|
|
38
|
+
tex += `^{ ${this.root} }`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
tex+= `\\left( ${this.argument.tex} \\right)`
|
|
42
|
+
return this.texRoot(tex);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {Expression} from "../internals";
|
|
2
|
+
import {ExpressionFactor} from "../internals";
|
|
3
|
+
|
|
4
|
+
export class ExpFactorVariable extends ExpressionFactor {
|
|
5
|
+
private _variable: string
|
|
6
|
+
constructor(value: string, power?: number, root?: number) {
|
|
7
|
+
super(null, power, root);
|
|
8
|
+
|
|
9
|
+
if (typeof value !== "string") {
|
|
10
|
+
throw `The variable ${value} is not a valid value.`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
this._variable = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
get variable(): string {
|
|
18
|
+
return this._variable;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
set variable(value: string) {
|
|
22
|
+
this._variable = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
makeTeX(): string {
|
|
26
|
+
return this.texPower(this.texRoot(this._variable))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
derivative(variable: string): Expression {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
integrate(variable: string): Expression {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
hasVariable(variable?: string): boolean {
|
|
38
|
+
return this._variable === variable
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./expression"
|
|
2
|
+
export * from "./expressionParser"
|
|
3
|
+
export * from "./expressionMember"
|
|
4
|
+
|
|
5
|
+
export * from "./expressionFactor"
|
|
6
|
+
export * from "./factors/ExpFactor"
|
|
7
|
+
export * from "./factors/ExpFactorConstant"
|
|
8
|
+
export * from "./factors/ExpFactorExponential"
|
|
9
|
+
export * from "./factors/ExpFactorNumber"
|
|
10
|
+
export * from "./factors/ExpFactorPower"
|
|
11
|
+
export * from "./factors/ExpFactorTrigo"
|
|
12
|
+
export * from "./factors/ExpFactorVariable"
|
|
13
|
+
|
|
14
|
+
export * from "../shutingyard"
|