pimath 0.0.42 → 0.0.43
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 +327 -579
- 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/icons.css +1043 -1043
- package/docs/assets/main.js +52 -52
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1388 -1388
- package/docs/classes/{algebra.Equation.html → Algebra.Equation.html} +25 -25
- package/docs/classes/algebra.Logicalset.html +4 -4
- package/docs/classes/algebra.Monom.html +113 -113
- package/docs/classes/algebra.Polynom.html +29 -29
- package/docs/classes/algebra.Rational.html +3 -3
- package/docs/classes/coefficients.Fraction.html +18 -18
- package/docs/classes/coefficients.Nthroot.html +2 -2
- package/docs/classes/geometry.Circle.html +2 -2
- package/docs/classes/geometry.Line.html +2 -2
- package/docs/classes/geometry.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/modules/{algebra.html → Algebra.html} +0 -0
- package/docs/modules/{random.html → Random.html} +0 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/maths/algebra/equation.d.ts +2 -7
- package/esm/maths/algebra/equation.js +9 -52
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +1 -4
- package/esm/maths/algebra/polynom.js +62 -120
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +6 -16
- package/esm/maths/algebra/rational.js +30 -141
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +1 -3
- package/esm/maths/coefficients/fraction.js +5 -37
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/coefficients/{nthRoot.d.ts → nthroot.d.ts} +5 -5
- package/esm/maths/coefficients/{nthRoot.js → nthroot.js} +5 -5
- package/esm/maths/coefficients/{nthRoot.js.map → nthroot.js.map} +1 -1
- package/esm/maths/geometry/line.js +0 -8
- package/esm/maths/geometry/line.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/maths/algebra/equation.ts +12 -61
- package/src/maths/algebra/polynom.ts +68 -128
- package/src/maths/algebra/rational.ts +98 -242
- package/src/maths/coefficients/fraction.ts +6 -44
- package/src/maths/coefficients/{nthRoot.ts → nthroot.ts} +5 -5
- package/src/maths/geometry/line.ts +1 -0
- package/tests/algebra/monom.test.ts +4 -1
- package/tests/coefficients/fraction.test.ts +1 -43
- package/tests/geometry/circle.test.ts +2 -4
- package/tests/algebra/equation.test.ts +0 -38
- package/tests/algebra/rationnal.test.ts +0 -68
|
@@ -5,287 +5,143 @@
|
|
|
5
5
|
|
|
6
6
|
import {Polynom} from "./polynom";
|
|
7
7
|
import {Fraction} from "../coefficients/fraction";
|
|
8
|
-
import {literalType} from "./monom";
|
|
9
|
-
import {Equation, ISolution, PARTICULAR_SOLUTION} from "./equation";
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* Rational class can handle rational polynoms
|
|
13
11
|
*/
|
|
14
|
-
export class Rational {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
private _numerator: Polynom;
|
|
28
|
-
|
|
29
|
-
get numerator(): Polynom {
|
|
30
|
-
return this._numerator
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private _denominator: Polynom;
|
|
34
|
-
|
|
35
|
-
get denominator(): Polynom {
|
|
36
|
-
return this._denominator
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get tex(): string {
|
|
40
|
-
return `\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get texFactors(): string {
|
|
44
|
-
return `\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
clone = (): Rational => {
|
|
48
|
-
this._numerator = this._numerator.clone()
|
|
49
|
-
this._denominator = this._denominator.clone()
|
|
50
|
-
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
domain = (): string => {
|
|
55
|
-
let zeroes = this._denominator.getZeroes();
|
|
56
|
-
if (zeroes.length === 0 || zeroes[0].tex === PARTICULAR_SOLUTION.real) {
|
|
57
|
-
return PARTICULAR_SOLUTION.real
|
|
58
|
-
} else if (zeroes[0].tex === PARTICULAR_SOLUTION.varnothing) {
|
|
59
|
-
return PARTICULAR_SOLUTION.varnothing
|
|
60
|
-
} else {
|
|
61
|
-
return '\\mathbb{R}\\setminus\\left\\{' +
|
|
62
|
-
zeroes.map(x => x.tex).join(';') + '\\right\\}'
|
|
12
|
+
export class Rational {
|
|
13
|
+
private _rawString: string;
|
|
14
|
+
private _numerator: Polynom;
|
|
15
|
+
private _denominator: Polynom;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param numerator
|
|
20
|
+
* @param denominator
|
|
21
|
+
*/
|
|
22
|
+
constructor(numerator?: Polynom, denominator?: Polynom) {
|
|
23
|
+
this._numerator = numerator ? numerator.clone() : new Polynom();
|
|
24
|
+
this._denominator = denominator ? denominator.clone() : new Polynom();
|
|
63
25
|
}
|
|
64
|
-
}
|
|
65
26
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
27
|
+
clone = (): Rational => {
|
|
28
|
+
this._numerator = this._numerator.clone()
|
|
29
|
+
this._denominator = this._denominator.clone()
|
|
72
30
|
|
|
73
|
-
derivative = (letter?: string): Rational => {
|
|
74
|
-
let N = this._numerator.clone(),
|
|
75
|
-
D = this._denominator.clone(),
|
|
76
|
-
dN = N.clone().derivative(letter),
|
|
77
|
-
dD = D.clone().derivative(letter)
|
|
78
|
-
|
|
79
|
-
this._numerator = dN.clone().multiply(D).subtract(N.clone().multiply(dD))
|
|
80
|
-
this._denominator = D.clone().pow(2)
|
|
81
|
-
|
|
82
|
-
return this
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
simplify = (P: Polynom): Rational => {
|
|
86
|
-
let NumeratorEuclidien = this._numerator.euclidian(P);
|
|
87
|
-
if (!NumeratorEuclidien.reminder.isZero()) {
|
|
88
31
|
return this;
|
|
89
32
|
}
|
|
90
33
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return this;
|
|
34
|
+
get tex(): string {
|
|
35
|
+
return `\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`;
|
|
94
36
|
}
|
|
95
37
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
38
|
+
get texFactors(): string {
|
|
39
|
+
this._numerator.factorize()
|
|
40
|
+
this._denominator.factorize()
|
|
100
41
|
|
|
101
|
-
|
|
102
|
-
this._numerator.factorize();
|
|
103
|
-
for (let f of this._numerator.factors) {
|
|
104
|
-
this.simplify(f);
|
|
42
|
+
return `\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`
|
|
105
43
|
}
|
|
106
44
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
opposed = (): Rational => {
|
|
111
|
-
this._numerator.opposed();
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
add = (R: Rational): Rational => {
|
|
115
|
-
// 1. Make sure both rational are at the same denominator
|
|
116
|
-
// 2. Add the numerators.
|
|
117
|
-
// 3. Simplify
|
|
118
|
-
|
|
119
|
-
// Store the adding denominator
|
|
120
|
-
let denominator = this._denominator.clone()
|
|
121
|
-
|
|
122
|
-
// Amplif the main rational polynom by the adding denominator
|
|
123
|
-
this.amplify(R._denominator)
|
|
124
|
-
|
|
125
|
-
// Add to the numerator the adding value...
|
|
126
|
-
this._numerator.add(R._numerator.clone().multiply(denominator));
|
|
127
|
-
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
subtract = (R: Rational): Rational => {
|
|
132
|
-
return this.add(R.clone().opposed())
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
limits = (value: Fraction | number, offset?: string, letter?: string): Fraction => {
|
|
136
|
-
if (value === Infinity || value === -Infinity) {
|
|
137
|
-
let {quotient, reminder} = this._numerator.clone().euclidian(this._denominator)
|
|
138
|
-
|
|
139
|
-
// quotient is positive => it will be infinite.
|
|
140
|
-
if (quotient.degree(letter).isStrictlyPositive()) {
|
|
141
|
-
return value === Infinity ? quotient.limitToInfinity(letter) : quotient.limitToNegativeInfinity(letter)
|
|
142
|
-
// return quotient.monomByDegree(undefined, letter).coefficient.sign()===1?(new Fraction()).infinite():(new Fraction()).infinite().opposed()
|
|
143
|
-
} else {
|
|
144
|
-
return quotient.monomByDegree(undefined, letter).coefficient
|
|
145
|
-
}
|
|
146
|
-
} else {
|
|
147
|
-
let evalValues: literalType = {},
|
|
148
|
-
evalValuesOffset: literalType = {},
|
|
149
|
-
theLimit: Fraction | number,
|
|
150
|
-
theSign: number,
|
|
151
|
-
FR = this.clone().reduce()
|
|
152
|
-
|
|
153
|
-
evalValues[letter === undefined ? 'x' : letter] = new Fraction(value)
|
|
45
|
+
get numerator(): Polynom {
|
|
46
|
+
return this._numerator
|
|
47
|
+
}
|
|
154
48
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
49
|
+
get denominator(): Polynom {
|
|
50
|
+
return this._denominator
|
|
51
|
+
}
|
|
158
52
|
|
|
159
|
-
|
|
53
|
+
domain = (): string => {
|
|
54
|
+
let zeroes = this._denominator.getZeroes();
|
|
55
|
+
if (zeroes.length === 0 || zeroes[0] === false) {
|
|
56
|
+
return '\\mathbb{R}'
|
|
57
|
+
} else if (zeroes[0] === true) {
|
|
58
|
+
return '\\varnothing'
|
|
160
59
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
theLimit = FR._numerator.evaluate(evalValues)
|
|
168
|
-
.divide(FR._denominator.evaluate(evalValues))
|
|
169
|
-
theSign = FR._numerator.evaluate(evalValuesOffset)
|
|
170
|
-
.divide(FR._denominator.evaluate(evalValuesOffset)).sign()
|
|
171
|
-
|
|
172
|
-
if (theLimit.isInfinity()) {
|
|
173
|
-
return theSign === 1 ? theLimit.abs() : theLimit.abs().opposed()
|
|
174
|
-
} else {
|
|
175
|
-
return theLimit
|
|
176
|
-
}
|
|
60
|
+
return '\\mathbb{R}\\setminus\\left{' +
|
|
61
|
+
zeroes.map(x => {
|
|
62
|
+
return (typeof x === 'boolean') ? '' : x.frac
|
|
63
|
+
})
|
|
64
|
+
.join(';') + '\\right}'
|
|
177
65
|
}
|
|
178
66
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
makeTableOfSigns = (): { factors: Polynom[], zeroes: ISolution[], signs: (string[])[], tex: string } => {
|
|
182
|
-
// Factorize the numerator and the denominator
|
|
183
|
-
this._numerator.factorize()
|
|
184
|
-
this._denominator.factorize()
|
|
185
|
-
|
|
186
|
-
let zeroes = Equation.makeSolutionsUnique([...this._numerator.getZeroes(), ...this._denominator.getZeroes()], true),
|
|
187
|
-
NFactors = this._numerator.factors,
|
|
188
|
-
DFactors = this._denominator.factors
|
|
189
67
|
|
|
190
|
-
|
|
191
|
-
|
|
68
|
+
amplify = (P: Polynom): Rational => {
|
|
69
|
+
this._numerator.multiply(P);
|
|
70
|
+
this._denominator.multiply(P);
|
|
192
71
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
})
|
|
196
|
-
DFactors.forEach(factor => {
|
|
197
|
-
tableOfSigns.push(this._makeOneLineOfTableOfSigns(factor, zeroes, 'd'))
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
// Empty line
|
|
201
|
-
tableOfSigns.push([])
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
202
74
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
if (index === tableOfSigns[0].length - 1) {
|
|
209
|
-
return ''
|
|
75
|
+
simplify = (P: Polynom): Rational => {
|
|
76
|
+
let NumeratorEuclidien = this._numerator.euclidian(P);
|
|
77
|
+
if (!NumeratorEuclidien.reminder.isZero()) {
|
|
78
|
+
return this;
|
|
210
79
|
}
|
|
211
|
-
if (index % 2 === 0) {
|
|
212
|
-
return 't'
|
|
213
|
-
}
|
|
214
|
-
return '+'
|
|
215
|
-
})
|
|
216
80
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// t, z or d
|
|
221
|
-
if (resultLine[i] === 'd') {
|
|
222
|
-
continue
|
|
223
|
-
}
|
|
224
|
-
if (current[i] !== 't') {
|
|
225
|
-
resultLine[i] = current[i]
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
// + or -
|
|
229
|
-
if (current[i] === '-') {
|
|
230
|
-
resultLine[i] = resultLine[i] === '+' ? '-' : '+'
|
|
231
|
-
}
|
|
232
|
-
}
|
|
81
|
+
let DenominatorEuclidien = this._denominator.euclidian(P);
|
|
82
|
+
if (!DenominatorEuclidien.reminder.isZero()) {
|
|
83
|
+
return this;
|
|
233
84
|
}
|
|
234
|
-
}
|
|
235
85
|
|
|
236
|
-
|
|
237
|
-
|
|
86
|
+
this._numerator = NumeratorEuclidien.quotient;
|
|
87
|
+
this._denominator = DenominatorEuclidien.quotient;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
238
90
|
|
|
239
|
-
|
|
91
|
+
reduce = (): Rational => {
|
|
92
|
+
console.log(this._numerator.tex)
|
|
93
|
+
this._numerator.factorize();
|
|
94
|
+
console.log(this._numerator.factors.map(x => x.tex))
|
|
95
|
+
for (let f of this._numerator.factors) {
|
|
96
|
+
this.simplify(f);
|
|
97
|
+
}
|
|
240
98
|
|
|
241
|
-
|
|
242
|
-
factors: [...NFactors, ...DFactors],
|
|
243
|
-
zeroes: zeroes,
|
|
244
|
-
signs: tableOfSigns,
|
|
245
|
-
tex: ''
|
|
99
|
+
return this;
|
|
246
100
|
}
|
|
247
101
|
|
|
248
|
-
|
|
102
|
+
opposed = (): Rational => {
|
|
103
|
+
this._numerator.opposed();
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
add = (R: Rational): Rational => {
|
|
107
|
+
// 1. Make sure both rational are at the same denominator
|
|
108
|
+
// 2. Add the numerators.
|
|
109
|
+
// 3. Simplify
|
|
249
110
|
|
|
250
|
-
|
|
251
|
-
|
|
111
|
+
// Store the adding denominator
|
|
112
|
+
let denominator = this._denominator.clone()
|
|
252
113
|
|
|
253
|
-
|
|
114
|
+
// Amplif the main rational polynom by the adding denominator
|
|
115
|
+
this.amplify(R._denominator)
|
|
254
116
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
tos.signs.forEach(list => {
|
|
258
|
-
tex += (`\n\\tkzTabLine{${list.join(',')}}`)
|
|
259
|
-
})
|
|
260
|
-
tex += `\n\\end{tikzpicture}`
|
|
117
|
+
// Add to the numerator the adding value...
|
|
118
|
+
this._numerator.add(R._numerator.clone().multiply(denominator));
|
|
261
119
|
|
|
262
|
-
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
263
122
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
let oneLine: string[] = [],
|
|
268
|
-
// TODO : check if there is no zero ?
|
|
269
|
-
currentZero = factor.getZeroes().map(x=>x.tex)
|
|
123
|
+
subtract = (R: Rational): Rational => {
|
|
124
|
+
return this.add(R.clone().opposed())
|
|
125
|
+
}
|
|
270
126
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
127
|
+
limits = (value: Fraction | number, letter?: string): Fraction | number => {
|
|
128
|
+
if (value === Infinity || value === -Infinity) {
|
|
129
|
+
let N = this._numerator.monomByDegree(this._numerator.degree(letter), letter),
|
|
130
|
+
D = this._denominator.monomByDegree(this._denominator.degree(letter), letter)
|
|
274
131
|
|
|
275
|
-
|
|
276
|
-
// Add the zero if it's the current one
|
|
277
|
-
oneLine.push(currentZero.includes(zeroes[i].tex) ? zeroSign : 't')
|
|
132
|
+
N.divide(D)
|
|
278
133
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
134
|
+
if (N.degree(letter).isStrictlyPositive()) {
|
|
135
|
+
return N.coefficient.sign() * (Math.pow((value > 0 ? 1 : -1), N.degree(letter).value % 2)) === 1 ? Infinity : -Infinity
|
|
136
|
+
}
|
|
137
|
+
if (N.degree(letter).isZero()) {
|
|
138
|
+
return N.coefficient
|
|
139
|
+
}
|
|
140
|
+
if (N.degree(letter).isStrictlyPositive()) {
|
|
141
|
+
return N.coefficient.sign() * (Math.pow(-1, N.degree(letter).value % 2)) === 1 ? 0 : -0
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
return this._numerator.evaluate({letter: new Fraction(value)}).divide(this._denominator.evaluate({letter: new Fraction(value)}))
|
|
284
145
|
}
|
|
285
|
-
|
|
286
146
|
}
|
|
287
|
-
oneLine.push('')
|
|
288
|
-
|
|
289
|
-
return oneLine
|
|
290
147
|
}
|
|
291
|
-
}
|
|
@@ -21,6 +21,10 @@ export class Fraction {
|
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
get isFraction() {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
// ------------------------------------------
|
|
25
29
|
// Getter and setter
|
|
26
30
|
// ------------------------------------------
|
|
@@ -47,10 +51,6 @@ export class Fraction {
|
|
|
47
51
|
|
|
48
52
|
// Display getter
|
|
49
53
|
get tex(): string {
|
|
50
|
-
if(this.isInfinity()){
|
|
51
|
-
return `${this.sign()===1?'+':'-'}\\infty`
|
|
52
|
-
}
|
|
53
|
-
|
|
54
54
|
if (this._denominator === 1) {
|
|
55
55
|
return `${this._numerator}`;
|
|
56
56
|
} else if (this._numerator < 0) {
|
|
@@ -346,44 +346,6 @@ export class Fraction {
|
|
|
346
346
|
return M
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
static average = (...fractions: (Fraction|number)[]): Fraction => {
|
|
350
|
-
let M = new Fraction().zero()
|
|
351
|
-
|
|
352
|
-
for(let f of fractions){
|
|
353
|
-
M.add(f)
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
M.divide(fractions.length)
|
|
357
|
-
|
|
358
|
-
return M
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
static unique = (fractions: Fraction[], sorted?: boolean): Fraction[] => {
|
|
362
|
-
// TODO: make sure it's wokring -> test !
|
|
363
|
-
let unique:{[Key:string]:boolean} = {},
|
|
364
|
-
distinct: Fraction[] = []
|
|
365
|
-
fractions.forEach(x => {
|
|
366
|
-
if(!unique[x.clone().reduce().tex]){
|
|
367
|
-
distinct.push(x.clone())
|
|
368
|
-
unique[x.tex]=true
|
|
369
|
-
}
|
|
370
|
-
})
|
|
371
|
-
|
|
372
|
-
if(sorted) {
|
|
373
|
-
return Fraction.sort(distinct)
|
|
374
|
-
}else{
|
|
375
|
-
return distinct
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
static sort = (fractions: Fraction[], reverse?:boolean): Fraction[] => {
|
|
379
|
-
// Todo make sure it's the correct order, not reverse -> make a test
|
|
380
|
-
let sorted = fractions.sort((a, b)=>a.value-b.value)
|
|
381
|
-
|
|
382
|
-
if(reverse){sorted.reverse()}
|
|
383
|
-
|
|
384
|
-
return sorted
|
|
385
|
-
}
|
|
386
|
-
|
|
387
349
|
// ------------------------------------------
|
|
388
350
|
// Mathematical operations specific to fractions
|
|
389
351
|
// ------------------------------------------
|
|
@@ -501,10 +463,10 @@ export class Fraction {
|
|
|
501
463
|
return isNaN(this._numerator);
|
|
502
464
|
}
|
|
503
465
|
isInfinity = (): boolean => {
|
|
504
|
-
return
|
|
466
|
+
return this._numerator === Infinity;
|
|
505
467
|
}
|
|
506
468
|
isFinite = (): boolean => {
|
|
507
|
-
return !this.isInfinity()
|
|
469
|
+
return !this.isInfinity();
|
|
508
470
|
}
|
|
509
471
|
isSquare = (): boolean => {
|
|
510
472
|
return Math.sqrt(this._numerator) % 1 === 0 && Math.sqrt(this._denominator) % 1 === 0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Nthroot is something like "a+b\sqrt{3}
|
|
3
3
|
*/
|
|
4
|
-
export class
|
|
4
|
+
export class Nthroot {
|
|
5
5
|
private _radical: number;
|
|
6
6
|
private _nth: number;
|
|
7
7
|
private _coefficient: number;
|
|
@@ -80,7 +80,7 @@ export class NthRoot {
|
|
|
80
80
|
// ------------------------------------------
|
|
81
81
|
// Creation / parsing functions
|
|
82
82
|
// ------------------------------------------
|
|
83
|
-
parse = (radical: number, nthroot?: number, coefficient?: number):
|
|
83
|
+
parse = (radical: number, nthroot?: number, coefficient?: number): Nthroot => {
|
|
84
84
|
this._coefficient = (coefficient === undefined) ? 1 : coefficient;
|
|
85
85
|
this._nth = (nthroot === undefined) ? 2 : nthroot;
|
|
86
86
|
this._radical = (radical === undefined) ? 1 : radical;
|
|
@@ -94,7 +94,7 @@ export class NthRoot {
|
|
|
94
94
|
// ------------------------------------------
|
|
95
95
|
// Mathematical operations
|
|
96
96
|
// ------------------------------------------
|
|
97
|
-
reduce = ():
|
|
97
|
+
reduce = (): Nthroot => {
|
|
98
98
|
// Max value to test.
|
|
99
99
|
let V = Math.floor(Math.pow(this._radical, 1 / this._nth));
|
|
100
100
|
while (V > 1) {
|
|
@@ -112,7 +112,7 @@ export class NthRoot {
|
|
|
112
112
|
return this;
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
multiply = (N:
|
|
115
|
+
multiply = (N: Nthroot): Nthroot => {
|
|
116
116
|
this._radical *= N.radical;
|
|
117
117
|
return this.reduce();
|
|
118
118
|
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
+
import {Monom} from "../../src/maths/algebra";
|
|
2
3
|
import {Random} from "../../src/maths/randomization/random";
|
|
3
4
|
import {describe} from "mocha";
|
|
4
|
-
import {
|
|
5
|
+
import {Fraction} from "../../src/maths/coefficients";
|
|
6
|
+
import {Shutingyard} from "../../src/maths/shutingyard";
|
|
7
|
+
import {log} from "util";
|
|
5
8
|
|
|
6
9
|
describe('Monom with integer power', () => {
|
|
7
10
|
it('parsing', () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {expect} from "chai";
|
|
2
|
-
import {Fraction} from "../../src/maths/coefficients
|
|
3
|
-
import {describe} from "mocha";
|
|
2
|
+
import {Fraction} from "../../src/maths/coefficients";
|
|
4
3
|
|
|
5
4
|
describe('Fraction tests', () => { // the tests container
|
|
6
5
|
|
|
@@ -34,45 +33,4 @@ describe('Fraction tests', () => { // the tests container
|
|
|
34
33
|
expect(F.isReduced()).to.be.true
|
|
35
34
|
expect(Q.isReduced()).to.be.false
|
|
36
35
|
})
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe("Fraction static functions", ()=>{
|
|
42
|
-
it('should sort fractions', function () {
|
|
43
|
-
let list = [
|
|
44
|
-
new Fraction('3.5'),
|
|
45
|
-
new Fraction('-2.5'),
|
|
46
|
-
new Fraction('3.1'),
|
|
47
|
-
new Fraction('3.54'),
|
|
48
|
-
new Fraction('1.5')
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
expect(Fraction.sort(list).map(x=>x.value)).to.eql([ -2.5, 1.5, 3.1, 3.5, 3.54 ])
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should make a list of fractions unique', function () {
|
|
55
|
-
let list = [
|
|
56
|
-
new Fraction('3.5'),
|
|
57
|
-
new Fraction('-2.5'),
|
|
58
|
-
new Fraction('7/2'),
|
|
59
|
-
new Fraction('3.50'),
|
|
60
|
-
new Fraction('1.5')
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
expect(Fraction.unique(list, true).map(x=>x.value)).to.be.eql([ -2.5, 1.5, 3.5 ])
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('shoudl get the average of fractions', function() {
|
|
68
|
-
let list = [
|
|
69
|
-
new Fraction('3.5'),
|
|
70
|
-
new Fraction('-2.5'),
|
|
71
|
-
new Fraction('7/2'),
|
|
72
|
-
new Fraction('3.50'),
|
|
73
|
-
new Fraction('1.5')
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
expect(Fraction.average(...list).tex).to.be.equal('\\frac{ 19 }{ 10 }')
|
|
77
|
-
})
|
|
78
36
|
})
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {describe} from "mocha";
|
|
2
|
+
import {Circle, Line, Point} from "../../src/maths/geometry";
|
|
3
|
+
import {Fraction} from "../../src/maths/coefficients";
|
|
2
4
|
import {expect} from "chai";
|
|
3
|
-
import {Circle} from "../../src/maths/geometry/circle";
|
|
4
|
-
import {Line} from "../../src/maths/geometry/line";
|
|
5
|
-
import {Point} from "../../src/maths/geometry/point";
|
|
6
|
-
import {Fraction} from "../../src/maths/coefficients/fraction";
|
|
7
5
|
|
|
8
6
|
describe('Circle', function () {
|
|
9
7
|
it('should calculate the intersection of a circle and a line', function () {
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {describe} from "mocha";
|
|
2
|
-
import {Rational} from "../../src/maths/algebra/rational";
|
|
3
|
-
import {Polynom} from "../../src/maths/algebra/polynom";
|
|
4
|
-
import {expect} from "chai";
|
|
5
|
-
import {Equation} from "../../src/maths/algebra/equation";
|
|
6
|
-
|
|
7
|
-
describe('Equations tests', () => {
|
|
8
|
-
it('should get the solutions', () => {
|
|
9
|
-
|
|
10
|
-
let E1 = new Equation('3x+8', '0')
|
|
11
|
-
E1.solve()
|
|
12
|
-
expect(E1.solutions[0].tex).to.be.equal('-\\frac{ 8 }{ 3 }')
|
|
13
|
-
|
|
14
|
-
let E2 = new Equation('x^2+5x+6', '0')
|
|
15
|
-
E2.solve()
|
|
16
|
-
expect(E2.solutions.map(x=>x.tex)).to.have.all.members(['-3', '-2'])
|
|
17
|
-
|
|
18
|
-
let E3 = new Equation('(x-3)(x+2)(3x-5)', '0')
|
|
19
|
-
E3.solve()
|
|
20
|
-
expect(E3.solutions.map(x=>x.tex)).to.have.all.members([ '-2', '3', '\\frac{ 5 }{ 3 }' ])
|
|
21
|
-
|
|
22
|
-
let E4 = new Equation('x^2+x+10', '0')
|
|
23
|
-
E4.solve()
|
|
24
|
-
expect(E4.solutions.map(x=>x.tex)).to.have.all.members([ '\\varnothing' ])
|
|
25
|
-
|
|
26
|
-
let E5 = new Equation('(x-3)(x+2)(x-5)(x-7)(x+2)', 0)
|
|
27
|
-
E5.solve()
|
|
28
|
-
expect(E5.solutions.map(x=>x.tex)).to.have.all.members([ '-2', '3', '5', '7' ] )
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let E6 = new Equation('5x^2+7x-31', 0)
|
|
32
|
-
E6.solve()
|
|
33
|
-
expect(E6.solutions.map(x=>x.tex)).to.have.all.members([
|
|
34
|
-
'\\dfrac{-7 - \\sqrt{669} }{ 10 }',
|
|
35
|
-
'\\dfrac{-7 + \\sqrt{669} }{ 10 }'
|
|
36
|
-
] )
|
|
37
|
-
})
|
|
38
|
-
})
|