pimath 0.0.119 → 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.
Files changed (173) hide show
  1. package/.eslintrc.js +23 -23
  2. package/.idea/PI.iml +7 -1
  3. package/dev/pimath.js +7929 -0
  4. package/dev/pimath.js.map +1 -0
  5. package/dist/{pi.js → pimath.js} +7612 -7829
  6. package/dist/pimath.js.map +1 -0
  7. package/dist/pimath.min.js +2 -0
  8. package/dist/pimath.min.js.map +1 -0
  9. package/docs/assets/main.js +3 -3
  10. package/docs/assets/search.js +1 -1
  11. package/docs/assets/style.css +450 -363
  12. package/docs/classes/Logicalset.Logicalset.html +119 -110
  13. package/docs/classes/Polynom.Rational.html +230 -227
  14. package/docs/classes/Vector-1.Vector.html +319 -273
  15. package/docs/classes/Vector.Point.html +189 -190
  16. package/docs/classes/algebra_equation.Equation.html +489 -446
  17. package/docs/classes/algebra_linearSystem.LinearSystem.html +228 -217
  18. package/docs/classes/algebra_monom.Monom.html +564 -507
  19. package/docs/classes/algebra_polynom.Polynom.html +774 -753
  20. package/docs/classes/coefficients_fraction.Fraction.html +573 -565
  21. package/docs/classes/geometry_circle.Circle.html +299 -299
  22. package/docs/classes/geometry_line.Line.html +511 -451
  23. package/docs/classes/geometry_triangle.Triangle.html +273 -264
  24. package/docs/classes/numeric.Numeric.html +138 -132
  25. package/docs/classes/shutingyard.Shutingyard.html +144 -133
  26. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +47 -46
  27. package/docs/enums/geometry_line.LinePropriety.html +58 -58
  28. package/docs/enums/shutingyard.ShutingyardMode.html +62 -58
  29. package/docs/enums/shutingyard.ShutingyardType.html +74 -70
  30. package/docs/index.html +31 -33
  31. package/docs/interfaces/algebra_equation.ISolution.html +61 -59
  32. package/docs/interfaces/algebra_polynom.IEuclidian.html +47 -46
  33. package/docs/interfaces/geometry_triangle.remarquableLines.html +74 -74
  34. package/docs/modules/Logicalset.html +33 -38
  35. package/docs/modules/Polynom.html +33 -38
  36. package/docs/modules/Vector-1.html +33 -38
  37. package/docs/modules/Vector.html +33 -38
  38. package/docs/modules/algebra_equation.html +35 -41
  39. package/docs/modules/algebra_linearSystem.html +31 -37
  40. package/docs/modules/algebra_monom.html +33 -39
  41. package/docs/modules/algebra_polynom.html +35 -41
  42. package/docs/modules/coefficients_fraction.html +33 -39
  43. package/docs/modules/geometry_circle.html +31 -37
  44. package/docs/modules/geometry_line.html +33 -39
  45. package/docs/modules/geometry_triangle.html +33 -39
  46. package/docs/modules/numeric.html +31 -37
  47. package/docs/modules/shutingyard.html +41 -47
  48. package/docs/types/algebra_monom.literalType.html +33 -37
  49. package/docs/types/algebra_polynom.PolynomParsingType.html +33 -37
  50. package/docs/types/coefficients_fraction.FractionParsingType.html +32 -36
  51. package/docs/types/shutingyard.Token.html +38 -42
  52. package/docs/types/shutingyard.tokenType.html +40 -44
  53. package/docs/variables/shutingyard.tokenConstant.html +37 -41
  54. package/esm/index.d.ts +38 -41
  55. package/esm/index.js +43 -46
  56. package/esm/index.js.map +1 -1
  57. package/esm/maths/algebra/equation.d.ts +119 -117
  58. package/esm/maths/algebra/equation.js +796 -785
  59. package/esm/maths/algebra/equation.js.map +1 -1
  60. package/esm/maths/algebra/linearSystem.d.ts +39 -38
  61. package/esm/maths/algebra/linearSystem.js +278 -262
  62. package/esm/maths/algebra/linearSystem.js.map +1 -1
  63. package/esm/maths/algebra/logicalset.d.ts +28 -28
  64. package/esm/maths/algebra/logicalset.js +157 -157
  65. package/esm/maths/algebra/monom.d.ts +206 -206
  66. package/esm/maths/algebra/monom.js +908 -908
  67. package/esm/maths/algebra/monom.js.map +1 -1
  68. package/esm/maths/algebra/polynom.d.ts +157 -157
  69. package/esm/maths/algebra/polynom.js +1277 -1277
  70. package/esm/maths/algebra/rational.d.ts +45 -45
  71. package/esm/maths/algebra/rational.js +183 -183
  72. package/esm/maths/algebra/study/rationalStudy.d.ts +28 -28
  73. package/esm/maths/algebra/study/rationalStudy.js +243 -243
  74. package/esm/maths/algebra/study.d.ts +142 -142
  75. package/esm/maths/algebra/study.js +377 -377
  76. package/esm/maths/algebra/study.js.map +1 -1
  77. package/esm/maths/coefficients/fraction.d.ts +90 -90
  78. package/esm/maths/coefficients/fraction.js +516 -516
  79. package/esm/maths/coefficients/fraction.js.map +1 -1
  80. package/esm/maths/coefficients/nthRoot.d.ts +23 -23
  81. package/esm/maths/coefficients/nthRoot.js +136 -136
  82. package/esm/maths/geometry/circle.d.ts +45 -45
  83. package/esm/maths/geometry/circle.js +323 -323
  84. package/esm/maths/geometry/line.d.ts +99 -99
  85. package/esm/maths/geometry/line.js +481 -481
  86. package/esm/maths/geometry/line.js.map +1 -1
  87. package/esm/maths/geometry/point.d.ts +34 -34
  88. package/esm/maths/geometry/point.js +166 -166
  89. package/esm/maths/geometry/point.js.map +1 -1
  90. package/esm/maths/geometry/triangle.d.ts +85 -85
  91. package/esm/maths/geometry/triangle.js +268 -268
  92. package/esm/maths/geometry/vector.d.ts +41 -41
  93. package/esm/maths/geometry/vector.js +197 -197
  94. package/esm/maths/geometry/vector.js.map +1 -1
  95. package/esm/maths/numeric.d.ts +28 -28
  96. package/esm/maths/numeric.js +180 -169
  97. package/esm/maths/numeric.js.map +1 -1
  98. package/esm/maths/numexp.d.ts +19 -0
  99. package/esm/maths/numexp.js +186 -0
  100. package/esm/maths/numexp.js.map +1 -0
  101. package/esm/maths/randomization/random.d.ts +23 -23
  102. package/esm/maths/randomization/random.js +78 -78
  103. package/esm/maths/randomization/random.js.map +1 -1
  104. package/esm/maths/randomization/randomCore.d.ts +7 -7
  105. package/esm/maths/randomization/randomCore.js +21 -21
  106. package/esm/maths/randomization/rndFraction.d.ts +12 -12
  107. package/esm/maths/randomization/rndFraction.js +43 -43
  108. package/esm/maths/randomization/rndGeometryLine.d.ts +12 -12
  109. package/esm/maths/randomization/rndGeometryLine.js +45 -45
  110. package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -12
  111. package/esm/maths/randomization/rndGeometryPoint.js +60 -60
  112. package/esm/maths/randomization/rndHelpers.d.ts +23 -23
  113. package/esm/maths/randomization/rndHelpers.js +76 -76
  114. package/esm/maths/randomization/rndMonom.d.ts +12 -12
  115. package/esm/maths/randomization/rndMonom.js +52 -52
  116. package/esm/maths/randomization/rndPolynom.d.ts +13 -13
  117. package/esm/maths/randomization/rndPolynom.js +74 -74
  118. package/esm/maths/randomization/rndTypes.d.ts +34 -34
  119. package/esm/maths/randomization/rndTypes.js +2 -2
  120. package/esm/maths/shutingyard.d.ts +59 -59
  121. package/esm/maths/shutingyard.js +442 -442
  122. package/esm/maths/shutingyard.js.map +1 -1
  123. package/package.json +11 -11
  124. package/public/index.html +50 -81
  125. package/public/playground.html +7 -8
  126. package/src/index.ts +2 -5
  127. package/src/maths/algebra/equation.ts +16 -0
  128. package/src/maths/algebra/linearSystem.ts +20 -0
  129. package/src/maths/algebra/study.ts +1 -1
  130. package/src/maths/numeric.ts +49 -48
  131. package/src/maths/{expressions/numexp.ts → numexp.ts} +2 -2
  132. package/tests/algebra/equation.test.ts +19 -5
  133. package/tests/algebra/linear.test.ts +3 -11
  134. package/tests/algebra/polynom.test.ts +7 -8
  135. package/tests/algebra/rationnal.test.ts +1 -1
  136. package/tests/algebra/study.test.ts +2 -9
  137. package/tests/coefficients/fraction.test.ts +8 -8
  138. package/tests/custom.test.ts +33 -37
  139. package/tests/numeric.test.ts +1 -2
  140. package/tests/numexp.test.ts +1 -5
  141. package/tests/shutingyard.test.ts +3 -3
  142. package/webpack-production-min.config.js +1 -1
  143. package/webpack-production.config.js +1 -1
  144. package/webpack.config.js +1 -1
  145. package/dist/pi.js.map +0 -1
  146. package/dist/pi.min.js +0 -2
  147. package/dist/pi.min.js.map +0 -1
  148. package/docs/classes/expressions_numexp.NumExp.html +0 -236
  149. package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +0 -317
  150. package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +0 -285
  151. package/docs/modules/expressions_numexp.html +0 -71
  152. package/docs/modules/expressions_polynomexp.html +0 -73
  153. package/docs/modules.html +0 -76
  154. package/graph.svg +0 -1033
  155. package/src/maths/expressions/ExpressionTree.ts +0 -172
  156. package/src/maths/expressions/expression.ts +0 -286
  157. package/src/maths/expressions/expressionFactor.ts +0 -190
  158. package/src/maths/expressions/expressionMember.ts +0 -233
  159. package/src/maths/expressions/expressionOperators.ts +0 -49
  160. package/src/maths/expressions/expressionParser.ts +0 -295
  161. package/src/maths/expressions/factors/ExpFactor.ts +0 -39
  162. package/src/maths/expressions/factors/ExpFactorConstant.ts +0 -60
  163. package/src/maths/expressions/factors/ExpFactorExponential.ts +0 -26
  164. package/src/maths/expressions/factors/ExpFactorNumber.ts +0 -72
  165. package/src/maths/expressions/factors/ExpFactorPower.ts +0 -42
  166. package/src/maths/expressions/factors/ExpFactorTrigo.ts +0 -53
  167. package/src/maths/expressions/factors/ExpFactorVariable.ts +0 -45
  168. package/src/maths/expressions/internals.ts +0 -14
  169. package/src/maths/expressions/polynomexp.bkp.ts +0 -221
  170. package/src/maths/expressions/polynomexp.ts +0 -310
  171. package/tests/expressions/expressions.test.ts +0 -145
  172. package/tests/expressions/expressiontree.test.ts +0 -11
  173. package/tests/polynomexp.test.ts +0 -12
@@ -1,172 +0,0 @@
1
- import {Shutingyard, ShutingyardMode, ShutingyardType, Token} from "../shutingyard";
2
-
3
- export class ExpressionTree {
4
- private _root: ExpressionNode
5
- private _rpn: Token[]
6
-
7
- constructor(value: string) {
8
- this._root = this._parse(value)
9
- }
10
-
11
- get tex(): string {
12
- return this._root.tex
13
- }
14
-
15
- print(): string {
16
- return this._root.print(0, []).join('\n')
17
- }
18
-
19
- private _parse(value: string) {
20
- let SY = new Shutingyard(ShutingyardMode.EXPRESSION).parse(value)
21
-
22
- // Store the rpn
23
- this._rpn = SY.rpn
24
-
25
- // Build the tree with nodes.
26
- let stack: ExpressionNode[] = []
27
-
28
- for (let item of this._rpn) {
29
- switch (item.tokenType) {
30
- case ShutingyardType.COEFFICIENT:
31
- stack.push(new ExpressionNode(item.tokenType, item.token))
32
- break
33
- case ShutingyardType.CONSTANT:
34
- stack.push(new ExpressionNode(item.tokenType, item.token))
35
- break
36
- case ShutingyardType.VARIABLE:
37
- stack.push(new ExpressionNode(item.tokenType, item.token))
38
- break
39
- case ShutingyardType.OPERATION:
40
- if (stack.length >= 2) {
41
- let b = stack.pop(),
42
- a = stack.pop()
43
-
44
- stack.push(new ExpressionNode(item.token, a, b))
45
- }
46
- break
47
- case ShutingyardType.FUNCTION:
48
- let a = stack.pop()
49
-
50
- switch (item.token) {
51
- case 'nthrt':
52
- stack.push(new ExpressionNode(item.token, a, stack.pop()))
53
- break
54
- default:
55
- stack.push(new ExpressionNode(item.token, a))
56
- }
57
-
58
- break
59
- default:
60
- throw(`Something went wrong while parsing ${value} at ${item.token}`)
61
- }
62
- }
63
-
64
- return stack[0]
65
- }
66
- }
67
-
68
- const operationFunction: string[] = ['nthrt']
69
- const softwrap: string[] = ['*', '^', 'sqrt', 'nthrt']
70
- function TeXit(value: ExpressionNode | string, parentheses?:boolean, soft?:boolean): string {
71
- if (value === undefined) {
72
- return ''
73
- }
74
- if (value === null) {
75
- return ''
76
- }
77
-
78
- let addParentheses = parentheses===true
79
- if(addParentheses){
80
- if(soft===true){
81
- if(value instanceof ExpressionNode){
82
- if(value.isSingle()){
83
- addParentheses = false
84
- }
85
- // The current element might not need to be wrapped.
86
- if(softwrap.includes(value.op)){
87
- addParentheses = false
88
- }
89
- }else{
90
- addParentheses = false
91
- }
92
- }
93
- }
94
-
95
- if (value instanceof ExpressionNode) {
96
- return addParentheses===true?`\\left( ${ value.tex } \\right) `:value.tex
97
- } else {
98
- return value
99
- }
100
- }
101
-
102
- export class ExpressionNode {
103
- private _children: (ExpressionNode | string)[]
104
- private _op: string
105
-
106
- constructor(op: string, ...children: (ExpressionNode | string)[]) {
107
- this._op = op
108
- this._children = children
109
- }
110
-
111
- get op(): string {
112
- return this._op;
113
- }
114
-
115
- get tex(): string {
116
- let a = this._children[0],
117
- b = this._children[1]
118
-
119
- switch (this._op) {
120
- case ShutingyardType.COEFFICIENT:
121
- case ShutingyardType.CONSTANT:
122
- case ShutingyardType.VARIABLE:
123
- if (typeof a === "string") {
124
- return a
125
- } else {
126
- return ''
127
- }
128
- case '+':
129
- return `${TeXit(a)} ${this._op} ${TeXit(b)}`
130
- case'-':
131
- return `${TeXit(a)} ${this._op} ${TeXit(b, true, true)}`
132
- case '*':
133
- return `${TeXit(a, true, true)} \\cdot ${TeXit(b, true, true)}`
134
- case '/':
135
- return `\\frac{ ${TeXit(a)} }{ ${TeXit(b)} }`
136
- case '^':
137
- return `${TeXit(a, true)}^{ ${TeXit(b)} }`
138
- case 'sqrt':
139
- return `\\sqrt{ ${TeXit(a)} }`
140
- default:
141
- throw(`Something went wrong with ${this._op}`)
142
- }
143
- }
144
-
145
- isSingle() {
146
- return this._op === ShutingyardType.COEFFICIENT ||
147
- this._op === ShutingyardType.VARIABLE ||
148
- this._op === ShutingyardType.CONSTANT
149
- }
150
-
151
- print(tab: number, stack: string[]): string[] {
152
- // Tabulation
153
- let tabChr = ''
154
- for (let i = 0; i < tab; i++) {
155
- tabChr += '\t'
156
- }
157
-
158
- // Walk through all nodes.
159
- let row: string[] = [`${tabChr}${this._op}`]
160
-
161
- for (let child of this._children) {
162
- if (child instanceof ExpressionNode) {
163
- row = [...child.print(tab + 1, row)]
164
- } else {
165
- row[row.length - 1] += ` -> ${child}`
166
- }
167
-
168
- }
169
-
170
- return [...stack, ...row]
171
- }
172
- }
@@ -1,286 +0,0 @@
1
- import {
2
- ExpFactor,
3
- ExpFactorConstant,
4
- ExpFactorNumber, ExpFactorPower,
5
- ExpFactorVariable,
6
- ExpressionFactor,
7
- ExpressionMember
8
- } from "./internals";
9
-
10
- export type ExpressionMemberType = { member: ExpressionMember, sign: number }
11
-
12
- export class Expression {
13
- private _members: ExpressionMemberType[]
14
-
15
- constructor(...values: (ExpressionMember | ExpressionFactor | ExpressionMemberType)[]) {
16
- this._members = []
17
- this.addMembers(...values)
18
- return this
19
- }
20
-
21
- get tex(): string {
22
- let tex: string = ""
23
- for (let item of this._members) {
24
-
25
- try {
26
- if (tex === "") {
27
- tex = (item.sign === -1 ? "-" : "") + item.member.tex
28
- } else {
29
- tex += (item.sign === -1 ? "-" : "+") + item.member.tex
30
- }
31
- } catch {
32
- console.log('Error while generating the TeX code for ', item.constructor.name)
33
- }
34
- }
35
- return tex
36
- }
37
-
38
- get display(): string {
39
- let display: string = ""
40
- for (let item of this._members) {
41
-
42
- try {
43
- if (display === "") {
44
- display = (item.sign === -1 ? "-" : "") + item.member.display
45
- } else {
46
- display += (item.sign === -1 ? "-" : "+") + item.member.display
47
- }
48
- } catch {
49
- console.log('Error while generating the display code for ', item.constructor.name)
50
- }
51
- }
52
- return display
53
- }
54
-
55
- get members(): ExpressionMemberType[] {
56
- return this._members;
57
- }
58
-
59
- set members(value: ExpressionMemberType[]) {
60
- this._members = value;
61
- }
62
-
63
- addMembers(...values: (ExpressionMemberType | ExpressionMember | ExpressionFactor)[]): Expression {
64
- for (let item of values) {
65
- if (item instanceof ExpressionMember) {
66
- this._members.push({
67
- member: item,
68
- sign: 1
69
- })
70
- } else if (item instanceof ExpressionFactor) {
71
- this._members.push({
72
- member: new ExpressionMember(item),
73
- sign: 1
74
- })
75
- } else {
76
- this._members.push(item)
77
- }
78
- }
79
-
80
- return this
81
- }
82
-
83
- add(value: Expression | ExpressionMember | ExpressionFactor) {
84
- if (value instanceof Expression) {
85
- this.members = this.members.concat(...value.members)
86
- } else if (value instanceof ExpressionMember) {
87
- this.members.push({
88
- member: value,
89
- sign: 1
90
- }
91
- )
92
- } else if (value instanceof ExpressionFactor) {
93
- this.members.push({
94
- member: new ExpressionMember(value),
95
- sign: 1
96
- })
97
- }
98
-
99
- return this
100
- }
101
-
102
- subtract(value: Expression | ExpressionMember | ExpressionFactor) {
103
-
104
- if (value instanceof Expression) {
105
- this.members = this.members.concat(
106
- ...value.members
107
- .map(item => {
108
- return {member: item.member, sign: -item.sign}
109
- }
110
- )
111
- )
112
- } else if (value instanceof ExpressionMember) {
113
- this.members.push({
114
- member: value,
115
- sign: -1
116
- }
117
- )
118
- } else if (value instanceof ExpressionFactor) {
119
- this.members.push({
120
- member: new ExpressionMember(value),
121
- sign: -1
122
- })
123
- }
124
-
125
- return this
126
- }
127
-
128
- variables(): string[] {
129
- let values: string[] = [],
130
- varFactor: ExpFactorVariable[]
131
-
132
-
133
- values = this.getAllFactors().filter(x => x instanceof ExpFactorVariable).map(x => {
134
- return x instanceof ExpFactorVariable ? x.variable : null
135
- })
136
-
137
- return [...new Set(values)]
138
- }
139
-
140
- isPolynom(): Boolean {
141
- // Allow variable, number, factor, power, constant
142
- let factors = this.getAllFactors()
143
-
144
- for (let factor of factors) {
145
- // No root
146
- if (factor.root > 1) {
147
- return false
148
- }
149
-
150
- // Allow power, as long as the power argument is numeric
151
- if(factor instanceof ExpFactorPower){
152
- if(!factor.powerArgument.isNumeric()){return false}
153
- // TODO: the power must be an integer value.
154
-
155
- if(!factor.powerArgument.isNumber()){return false}
156
- }
157
-
158
- // Allow some type of factors.
159
- if (!(
160
- factor instanceof ExpFactor ||
161
- factor instanceof ExpFactorConstant ||
162
- factor instanceof ExpFactorNumber ||
163
- factor instanceof ExpFactorVariable
164
- )) {
165
- return false
166
- }
167
- }
168
-
169
- return true
170
- }
171
-
172
- getAllFactors(): ExpressionFactor[] {
173
- let EF: ExpressionFactor[] = []
174
-
175
- for (let item of this._members) {
176
- for (let factor of item.member.factors) {
177
- EF.push(factor)
178
- for(let expr of factor.getArguments()){
179
- EF = EF.concat(...expr.getAllFactors())
180
- }
181
- }
182
- }
183
-
184
- return EF
185
- }
186
-
187
- hasVariable(variable?: string): boolean {
188
-
189
- if (variable === undefined) {
190
- return !this.isNumeric()
191
- }
192
-
193
-
194
- for (let item of this._members) {
195
- if (item.member.hasVariable(variable)) {
196
- return true
197
- }
198
- }
199
-
200
- // The variable hasn't been found !
201
- return false
202
- }
203
-
204
- isZero(): boolean {
205
- // TODO: Must check if all the members has a value of zero
206
- if (this._members.length === 0) {
207
- return true
208
- }
209
-
210
- for (let item of this._members) {
211
- if (item.member.isZero()) {
212
- return true
213
- }
214
- }
215
-
216
- return false
217
- }
218
-
219
- isNumeric(): boolean {
220
- for (let item of this._members) {
221
- if (!item.member.isNumeric()) {
222
- return false
223
- }
224
- }
225
- return true;
226
- }
227
-
228
- isNumber(): boolean {
229
- if(this._members.length===1) {
230
- if (this._members[0]?.member.factors[0] instanceof ExpFactorNumber) {
231
- return this._members[0].member.factors[0].root === 1
232
- }
233
- }
234
-
235
- return false
236
- }
237
-
238
- isSingle(): Boolean {
239
- if (this.members.length > 1) {
240
- return false
241
- } else if (this.members[0]?.member.factors.length > 1) {
242
- return false
243
- } else {
244
- return true
245
- }
246
-
247
- }
248
-
249
- isFactor(): Boolean {
250
- return this.members.length === 1
251
- }
252
-
253
-
254
- structure(depth?: number): string {
255
- let struct: string[] = [],
256
- indent = "",
257
- dftIndent = "\t"
258
-
259
- if (depth === undefined) {
260
- depth = 0
261
- }
262
- for (let i = 0; i < depth; i++) {
263
- indent += dftIndent
264
- }
265
-
266
- struct.push(`${indent}${this.constructor.name}: ${this.tex}`)
267
- for (let item of this._members) {
268
- struct.push(`${indent}${dftIndent}${item.member.constructor.name}: ${item.member.tex}`)
269
- for (let factor of item.member.factors) {
270
- struct.push(`${indent}${dftIndent}${dftIndent}${factor.constructor.name}: ${factor.tex} ; power: ${factor.power}; root: ${factor.root}`)
271
- if (factor.argument !== null) {
272
- struct.push(factor.argument.structure(depth + 3))
273
- }
274
- }
275
- }
276
- return struct.join('\n')
277
- }
278
-
279
- reduce():Expression {
280
- for(let item of this.members){
281
- item.member.reduce()
282
- }
283
- return this
284
- }
285
- }
286
-
@@ -1,190 +0,0 @@
1
- import {Expression} from "./internals";
2
- import {Numeric} from "../numeric";
3
-
4
- export abstract class ExpressionFactor {
5
- constructor(
6
- private _argument: Expression,
7
- private _power?: number,
8
- private _root?: number,
9
- private _inline?: boolean
10
- ) {
11
- if (this._power === undefined) {
12
- this._power = 1
13
- }
14
- if (this._root === undefined) {
15
- this._root = 1
16
- }
17
- if (this._inline === undefined) {
18
- this._inline = false
19
- }
20
- }
21
-
22
- get inline(): boolean {
23
- return this._inline;
24
- }
25
-
26
- set inline(value: boolean) {
27
- this._inline = value;
28
- }
29
-
30
- get tex(): string {
31
- return this.makeTeX()
32
- }
33
-
34
- get display(): string {
35
- return this.makeDisplay()
36
- }
37
-
38
- get power(): number {
39
- return this._power;
40
- }
41
-
42
- set power(value: number) {
43
- if (!Number.isSafeInteger(value)) {
44
- throw `Power value (${value}) is not a safe integer`
45
- }
46
- this._power = value;
47
- }
48
-
49
- get root(): number {
50
- return this._root;
51
- }
52
-
53
- set root(value: number) {
54
- if (!Number.isSafeInteger(value)) {
55
- throw `Root value (${value}) is not a safe integer`
56
- }
57
- this._root = value;
58
- }
59
-
60
- get argument(): Expression {
61
- return this._argument;
62
- }
63
-
64
- set argument(value: Expression) {
65
- this._argument = value;
66
- }
67
-
68
- abstract makeTeX(numberOfFactors?: number, position?: number): string
69
-
70
- abstract makeDisplay(numberOfFactors?: number, position?: number): string
71
-
72
- abstract derivative(variable: string): Expression
73
-
74
- abstract integrate(variable: string): Expression
75
-
76
- getArguments(): Expression[] {
77
- if (this._argument !== null){
78
- return [this.argument]
79
- }
80
- return []
81
- }
82
- hasVariable(variable?: string): boolean {
83
-
84
- if (variable === undefined) {
85
- return !this.isNumeric()
86
- }
87
-
88
- // The argument is an Expression
89
- if (this._argument instanceof Expression) {
90
- return this._argument.hasVariable(variable)
91
- }
92
-
93
- return false
94
- }
95
-
96
- isNumeric(): boolean {
97
- for(let expressionArgument of this.getArguments()){
98
- if(!expressionArgument.isNumeric()){return false}
99
- }
100
- return true
101
- }
102
-
103
- hasRoot(): boolean {
104
- return this.root > 1
105
- }
106
-
107
- hasPower(inline?: boolean): boolean {
108
- if (inline === true) {
109
- return !(this.power === 1)
110
- } else {
111
- return !(this.power === 1 || this.power === -1)
112
- }
113
- }
114
-
115
-
116
- texPowerAndRoot(tex: string): string {
117
- return this.texPower(this.texRoot(tex))
118
- }
119
-
120
- displayPowerAndRoot(display: string): string {
121
- return this.displayPower(this.displayRoot(display))
122
- }
123
-
124
- displayPower(display: string):string {
125
- if (this.hasPower(this.inline)) {
126
- return `${display}^(${Math.abs(this.power)})`
127
- }
128
-
129
- return display
130
- }
131
-
132
- displayRoot(display: string): string {
133
- if (this.root === 2) {
134
- return `sqrt( ${display} )`
135
- } else if (this.root > 2) {
136
- return `nthrt(${display},${this.root})`
137
- }
138
-
139
- return display
140
- }
141
-
142
- texPower(tex: string): string {
143
- if (this.hasPower(this.inline)) {
144
- return `${tex}^{ ${Math.abs(this.power)} }`
145
- }
146
-
147
- return tex
148
- }
149
-
150
- wrapWithParentheses(tex: string, asTex?: boolean): string {
151
- if(asTex===undefined || asTex===true) {
152
- return `\\left( ${tex} \\right)`
153
- }else{
154
- return `( ${tex} )`
155
- }
156
- }
157
-
158
- texRoot(tex: string): string {
159
- if (this.root === 2) {
160
- return `\\sqrt{ ${tex} }`
161
- } else if (this.root > 2) {
162
- return `\\sqrt[${this.root}]{ ${tex} }`
163
- }
164
-
165
- return tex
166
- }
167
-
168
- isZero(): Boolean {
169
- if (this._argument instanceof Expression) {
170
- return this._argument.isZero()
171
- }
172
-
173
- return this._argument === 0
174
- }
175
-
176
- reduce(): ExpressionFactor {
177
- let gcd = Numeric.gcd(this.root, this.power)
178
-
179
- if(gcd>1){
180
- this.root = this.root/gcd
181
- this.power = this.power/gcd
182
- }
183
-
184
- for(let expressionArgument of this.getArguments()){
185
- expressionArgument.reduce()
186
- }
187
-
188
- return this
189
- }
190
- }