pimath 0.0.40 → 0.0.41
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/dist/pi.js +288 -92
- 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/search.js +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/maths/algebra/equation.d.ts +6 -2
- package/esm/maths/algebra/equation.js +49 -9
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +2 -1
- package/esm/maths/algebra/polynom.js +98 -62
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +10 -0
- package/esm/maths/algebra/rational.js +101 -10
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +3 -1
- package/esm/maths/coefficients/fraction.js +33 -4
- 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/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/maths/algebra/equation.ts +58 -12
- package/src/maths/algebra/polynom.ts +100 -68
- package/src/maths/algebra/rational.ts +136 -20
- package/src/maths/coefficients/fraction.ts +39 -5
- package/src/maths/coefficients/{nthroot.ts → nthRoot.ts} +5 -5
- package/tests/algebra/equation.test.ts +38 -0
- package/tests/algebra/monom.test.ts +1 -4
- package/tests/algebra/rationnal.test.ts +29 -5
- package/tests/coefficients/fraction.test.ts +43 -1
- package/tests/geometry/circle.test.ts +4 -2
package/dist/pi.js
CHANGED
|
@@ -14,7 +14,7 @@ const numexp_1 = __webpack_require__(735);
|
|
|
14
14
|
const shutingyard_1 = __webpack_require__(505);
|
|
15
15
|
const random_1 = __webpack_require__(330);
|
|
16
16
|
const fraction_1 = __webpack_require__(506);
|
|
17
|
-
const
|
|
17
|
+
const nthRoot_1 = __webpack_require__(872);
|
|
18
18
|
const monom_1 = __webpack_require__(937);
|
|
19
19
|
const polynom_1 = __webpack_require__(38);
|
|
20
20
|
const equation_1 = __webpack_require__(760);
|
|
@@ -33,7 +33,7 @@ exports.l = {
|
|
|
33
33
|
Numeric: numeric_1.Numeric,
|
|
34
34
|
NumExp: numexp_1.NumExp,
|
|
35
35
|
Fraction: fraction_1.Fraction,
|
|
36
|
-
Root:
|
|
36
|
+
Root: nthRoot_1.NthRoot,
|
|
37
37
|
Monom: monom_1.Monom,
|
|
38
38
|
Polynom: polynom_1.Polynom,
|
|
39
39
|
Equation: equation_1.Equation,
|
|
@@ -61,11 +61,16 @@ window.Pi = exports.l;
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
64
|
-
exports.Equation = void 0;
|
|
64
|
+
exports.Equation = exports.PARTICULAR_SOLUTION = void 0;
|
|
65
65
|
const polynom_1 = __webpack_require__(38);
|
|
66
66
|
const numeric_1 = __webpack_require__(956);
|
|
67
67
|
const fraction_1 = __webpack_require__(506);
|
|
68
|
-
const
|
|
68
|
+
const nthRoot_1 = __webpack_require__(872);
|
|
69
|
+
var PARTICULAR_SOLUTION;
|
|
70
|
+
(function (PARTICULAR_SOLUTION) {
|
|
71
|
+
PARTICULAR_SOLUTION["real"] = "\\mathbb{R}";
|
|
72
|
+
PARTICULAR_SOLUTION["varnothing"] = "\\varnothing";
|
|
73
|
+
})(PARTICULAR_SOLUTION = exports.PARTICULAR_SOLUTION || (exports.PARTICULAR_SOLUTION = {}));
|
|
69
74
|
class Equation {
|
|
70
75
|
/**
|
|
71
76
|
* Create an Equation using two polynoms.
|
|
@@ -74,8 +79,8 @@ class Equation {
|
|
|
74
79
|
*/
|
|
75
80
|
constructor(...equations) {
|
|
76
81
|
// Undetermined texSolutions.
|
|
77
|
-
this._varnothing =
|
|
78
|
-
this._real =
|
|
82
|
+
this._varnothing = PARTICULAR_SOLUTION.varnothing;
|
|
83
|
+
this._real = PARTICULAR_SOLUTION.real;
|
|
79
84
|
// ------------------------------------------
|
|
80
85
|
// Creation / parsing functions
|
|
81
86
|
// -----------------------------------------------
|
|
@@ -270,6 +275,8 @@ class Equation {
|
|
|
270
275
|
default:
|
|
271
276
|
this._solveDegree3plus();
|
|
272
277
|
}
|
|
278
|
+
// cleanup the solutions.
|
|
279
|
+
this._solutions = Equation.makeSolutionsUnique(this._solutions);
|
|
273
280
|
return this;
|
|
274
281
|
};
|
|
275
282
|
this.test = (values) => {
|
|
@@ -400,7 +407,7 @@ class Equation {
|
|
|
400
407
|
}
|
|
401
408
|
else {
|
|
402
409
|
this._solutions = [{
|
|
403
|
-
tex: v.
|
|
410
|
+
tex: v.tex,
|
|
404
411
|
value: v.value,
|
|
405
412
|
exact: v
|
|
406
413
|
}];
|
|
@@ -460,7 +467,7 @@ class Equation {
|
|
|
460
467
|
];
|
|
461
468
|
}
|
|
462
469
|
else {
|
|
463
|
-
nthDelta = new
|
|
470
|
+
nthDelta = new nthRoot_1.NthRoot(delta).reduce();
|
|
464
471
|
if (nthDelta.hasRadical()) {
|
|
465
472
|
// -b +- coeff\sqrt{radical}
|
|
466
473
|
// -------------------------
|
|
@@ -634,9 +641,27 @@ class Equation {
|
|
|
634
641
|
}
|
|
635
642
|
return this._solutions;
|
|
636
643
|
};
|
|
637
|
-
this._solveDegree3plus = () => {
|
|
638
|
-
//
|
|
639
|
-
|
|
644
|
+
this._solveDegree3plus = (letter) => {
|
|
645
|
+
// Push everything to the left
|
|
646
|
+
// factorize
|
|
647
|
+
// solve each factors.
|
|
648
|
+
let equ = this.clone().moveLeft();
|
|
649
|
+
equ.left.factorize();
|
|
650
|
+
this._solutions = [];
|
|
651
|
+
equ.left.factors.forEach(factor => {
|
|
652
|
+
if (factor.degree(letter).leq(2)) {
|
|
653
|
+
let factorAsEquation = new Equation(factor, 0);
|
|
654
|
+
factorAsEquation.solve();
|
|
655
|
+
factorAsEquation.solutions.forEach(solution => {
|
|
656
|
+
this._solutions.push(solution);
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
console.log(factor.tex, ': cannot actually get the solution of this equation');
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
// TODO: check equation resolution for more than degree 2
|
|
664
|
+
// this._solutions = [{tex: 'solve x - not yet handled', value: NaN, exact: false}]; // ESLint remove system :(
|
|
640
665
|
return this._solutions;
|
|
641
666
|
};
|
|
642
667
|
// Default equation
|
|
@@ -751,6 +776,21 @@ class Equation {
|
|
|
751
776
|
set randomizeDefaults(value) {
|
|
752
777
|
this._randomizeDefaults = value;
|
|
753
778
|
}
|
|
779
|
+
static makeSolutionsUnique(solutions, sorted) {
|
|
780
|
+
let solutionAsTex = [], uniqueSolutions = solutions.filter(sol => {
|
|
781
|
+
if (!solutionAsTex.includes(sol.tex)) {
|
|
782
|
+
solutionAsTex.push(sol.tex);
|
|
783
|
+
return true;
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
if (sorted === true) {
|
|
790
|
+
uniqueSolutions.sort((a, b) => a.value - b.value);
|
|
791
|
+
}
|
|
792
|
+
return uniqueSolutions;
|
|
793
|
+
}
|
|
754
794
|
}
|
|
755
795
|
exports.Equation = Equation;
|
|
756
796
|
|
|
@@ -2043,6 +2083,7 @@ const monom_1 = __webpack_require__(937);
|
|
|
2043
2083
|
const shutingyard_1 = __webpack_require__(505);
|
|
2044
2084
|
const numeric_1 = __webpack_require__(956);
|
|
2045
2085
|
const fraction_1 = __webpack_require__(506);
|
|
2086
|
+
const equation_1 = __webpack_require__(760);
|
|
2046
2087
|
/**
|
|
2047
2088
|
* Polynom class can handle polynoms, reorder, resolve, ...
|
|
2048
2089
|
* ```
|
|
@@ -2545,6 +2586,7 @@ class Polynom {
|
|
|
2545
2586
|
P = P.euclidian(tempPolynom).quotient;
|
|
2546
2587
|
}
|
|
2547
2588
|
let securityLoop = P.degree().clone().multiply(2).value;
|
|
2589
|
+
let result;
|
|
2548
2590
|
// securityLoop = 0
|
|
2549
2591
|
while (securityLoop >= 0) {
|
|
2550
2592
|
securityLoop--;
|
|
@@ -2560,7 +2602,7 @@ class Polynom {
|
|
|
2560
2602
|
for (let m1d of m1) {
|
|
2561
2603
|
for (let m2d of m2) {
|
|
2562
2604
|
// if(m1d.degree()===m2d.degree()){continue}
|
|
2563
|
-
let dividerPolynom = new Polynom()
|
|
2605
|
+
let dividerPolynom = new Polynom();
|
|
2564
2606
|
dividerPolynom.monoms = [m1d.clone(), m2d.clone()];
|
|
2565
2607
|
result = P.euclidian(dividerPolynom);
|
|
2566
2608
|
if (result.reminder.isZero()) {
|
|
@@ -2578,72 +2620,103 @@ class Polynom {
|
|
|
2578
2620
|
}
|
|
2579
2621
|
}
|
|
2580
2622
|
}
|
|
2623
|
+
if (!P.isOne()) {
|
|
2624
|
+
factors.push(P.clone());
|
|
2625
|
+
}
|
|
2581
2626
|
this.factors = factors;
|
|
2582
2627
|
return factors;
|
|
2583
2628
|
};
|
|
2584
2629
|
// TODO: get zeroes for more than first degree and for more than natural degrees
|
|
2585
2630
|
this.getZeroes = () => {
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2631
|
+
let equ = new equation_1.Equation(this.clone(), 0);
|
|
2632
|
+
equ.solve();
|
|
2633
|
+
return equ.solutions;
|
|
2634
|
+
//
|
|
2635
|
+
// const Z: Fraction[] = [];
|
|
2636
|
+
//
|
|
2637
|
+
// // ISolution: {tex: string, value: number, exact: boolean|Fraction|...}
|
|
2638
|
+
//
|
|
2639
|
+
// switch (this.degree().value) {
|
|
2640
|
+
// case 0:
|
|
2641
|
+
// if (this._monoms[0].coefficient.value === 0) {
|
|
2642
|
+
// return [{
|
|
2643
|
+
// tex: '\\mathbb{R}',
|
|
2644
|
+
// value: NaN,
|
|
2645
|
+
// exact: false
|
|
2646
|
+
// }];
|
|
2647
|
+
// } else {
|
|
2648
|
+
// return [{
|
|
2649
|
+
// tex: '\\varnothing',
|
|
2650
|
+
// value: NaN,
|
|
2651
|
+
// exact: false
|
|
2652
|
+
// }];
|
|
2653
|
+
// }
|
|
2654
|
+
// case 1:
|
|
2655
|
+
// // There is only one monoms,
|
|
2656
|
+
// if (this._monoms.length === 1) {
|
|
2657
|
+
// return [{
|
|
2658
|
+
// tex: '0',
|
|
2659
|
+
// value: 0,
|
|
2660
|
+
// exact: new Fraction().zero()
|
|
2661
|
+
// }];
|
|
2662
|
+
// } else {
|
|
2663
|
+
// const P = this.clone().reduce().reorder();
|
|
2664
|
+
// const coeff = P.monoms[1].coefficient.opposed().divide(P.monoms[0].coefficient)
|
|
2665
|
+
// return [{
|
|
2666
|
+
// tex: coeff.tex,
|
|
2667
|
+
// value: coeff.value,
|
|
2668
|
+
// exact: coeff
|
|
2669
|
+
// }];
|
|
2670
|
+
// }
|
|
2671
|
+
// // TODO: Determine the zeros of an equation of second degree.
|
|
2672
|
+
// //case 2:
|
|
2673
|
+
// default:
|
|
2674
|
+
// // Make sure the polynom is factorized.
|
|
2675
|
+
// if (this._factors.length === 0) {
|
|
2676
|
+
// this.factorize()
|
|
2677
|
+
// }
|
|
2678
|
+
//
|
|
2679
|
+
// let zeroes:Fraction[] = [], zeroesAsTex = [];
|
|
2680
|
+
// for (let P of this._factors) {
|
|
2681
|
+
// if (P.degree().greater(2)) {
|
|
2682
|
+
// // TODO: get zeroes of polynom with a degree greater than 2.
|
|
2683
|
+
//
|
|
2684
|
+
// } else if (P.degree().value === 2) {
|
|
2685
|
+
// let A = P.monomByDegree(2).coefficient,
|
|
2686
|
+
// B = P.monomByDegree(1).coefficient,
|
|
2687
|
+
// C = P.monomByDegree(0).coefficient,
|
|
2688
|
+
// D = B.clone().pow(2).subtract(A.clone().multiply(C).multiply(4));
|
|
2689
|
+
//
|
|
2690
|
+
// if (D.value > 0) {
|
|
2691
|
+
// /*console.log('Two zeroes for ', P.tex); */
|
|
2692
|
+
// let x1 = (-(B.value) + Math.sqrt(D.value)) / (2 * A.value),
|
|
2693
|
+
// x2 = (-(B.value) - Math.sqrt(D.value)) / (2 * A.value);
|
|
2694
|
+
//
|
|
2695
|
+
// zeroes.push(new Fraction(x1.toFixed(3)).reduce());
|
|
2696
|
+
// zeroes.push(new Fraction(x2.toFixed(3)).reduce());
|
|
2697
|
+
// } else if (D.value === 0) {
|
|
2698
|
+
// /*console.log('One zero for ', P.tex); */
|
|
2699
|
+
// } else {
|
|
2700
|
+
// console.log('No zero for ', P.tex);
|
|
2701
|
+
// }
|
|
2702
|
+
// } else {
|
|
2703
|
+
// for (let z of P.getZeroes()) {
|
|
2704
|
+
// // Check if the zero is already in the list.
|
|
2705
|
+
// // if (z === false || z === true) {
|
|
2706
|
+
// // continue;
|
|
2707
|
+
// // }
|
|
2708
|
+
// if (zeroesAsTex.indexOf(z.frac) === -1) {
|
|
2709
|
+
// zeroes.push(z);
|
|
2710
|
+
// zeroesAsTex.push(z.frac);
|
|
2711
|
+
// }
|
|
2712
|
+
// }
|
|
2713
|
+
// }
|
|
2714
|
+
// }
|
|
2715
|
+
//
|
|
2716
|
+
//
|
|
2717
|
+
// return zeroes;
|
|
2718
|
+
// }
|
|
2719
|
+
// return Z;
|
|
2647
2720
|
};
|
|
2648
2721
|
// TODO: analyse the next functions to determine if they are useful or not...
|
|
2649
2722
|
this.monomByDegree = (degree, letter) => {
|
|
@@ -3015,6 +3088,9 @@ class Polynom {
|
|
|
3015
3088
|
}
|
|
3016
3089
|
get texFactors() {
|
|
3017
3090
|
this.factorize();
|
|
3091
|
+
if (this.factors.length === 0) {
|
|
3092
|
+
return this.tex;
|
|
3093
|
+
}
|
|
3018
3094
|
let tex = '';
|
|
3019
3095
|
for (let f of this.factors) {
|
|
3020
3096
|
if (f.monoms.length > 1) {
|
|
@@ -3210,6 +3286,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
3210
3286
|
exports.Rational = void 0;
|
|
3211
3287
|
const polynom_1 = __webpack_require__(38);
|
|
3212
3288
|
const fraction_1 = __webpack_require__(506);
|
|
3289
|
+
const equation_1 = __webpack_require__(760);
|
|
3213
3290
|
/**
|
|
3214
3291
|
* Rational class can handle rational polynoms
|
|
3215
3292
|
*/
|
|
@@ -3227,18 +3304,15 @@ class Rational {
|
|
|
3227
3304
|
};
|
|
3228
3305
|
this.domain = () => {
|
|
3229
3306
|
let zeroes = this._denominator.getZeroes();
|
|
3230
|
-
if (zeroes.length === 0 || zeroes[0] ===
|
|
3231
|
-
return
|
|
3307
|
+
if (zeroes.length === 0 || zeroes[0].tex === equation_1.PARTICULAR_SOLUTION.real) {
|
|
3308
|
+
return equation_1.PARTICULAR_SOLUTION.real;
|
|
3232
3309
|
}
|
|
3233
|
-
else if (zeroes[0] ===
|
|
3234
|
-
return
|
|
3310
|
+
else if (zeroes[0].tex === equation_1.PARTICULAR_SOLUTION.varnothing) {
|
|
3311
|
+
return equation_1.PARTICULAR_SOLUTION.varnothing;
|
|
3235
3312
|
}
|
|
3236
3313
|
else {
|
|
3237
3314
|
return '\\mathbb{R}\\setminus\\left{' +
|
|
3238
|
-
zeroes.map(x =>
|
|
3239
|
-
return (typeof x === 'boolean') ? '' : x.frac;
|
|
3240
|
-
})
|
|
3241
|
-
.join(';') + '\\right}';
|
|
3315
|
+
zeroes.map(x => x.tex).join(';') + '\\right}';
|
|
3242
3316
|
}
|
|
3243
3317
|
};
|
|
3244
3318
|
this.amplify = (P) => {
|
|
@@ -3246,6 +3320,12 @@ class Rational {
|
|
|
3246
3320
|
this._denominator.multiply(P);
|
|
3247
3321
|
return this;
|
|
3248
3322
|
};
|
|
3323
|
+
this.derivative = (letter) => {
|
|
3324
|
+
let N = this._numerator.clone(), D = this._denominator.clone(), dN = N.clone().derivative(letter), dD = D.clone().derivative(letter);
|
|
3325
|
+
this._numerator = dN.clone().multiply(D).subtract(N.clone().multiply(dD));
|
|
3326
|
+
this._denominator = D.clone().pow(2);
|
|
3327
|
+
return this;
|
|
3328
|
+
};
|
|
3249
3329
|
this.simplify = (P) => {
|
|
3250
3330
|
let NumeratorEuclidien = this._numerator.euclidian(P);
|
|
3251
3331
|
if (!NumeratorEuclidien.reminder.isZero()) {
|
|
@@ -3325,6 +3405,95 @@ class Rational {
|
|
|
3325
3405
|
}
|
|
3326
3406
|
}
|
|
3327
3407
|
};
|
|
3408
|
+
this.makeTableOfSigns = () => {
|
|
3409
|
+
// Factorize the numerator and the denominator
|
|
3410
|
+
this._numerator.factorize();
|
|
3411
|
+
this._denominator.factorize();
|
|
3412
|
+
let zeroes = equation_1.Equation.makeSolutionsUnique([...this._numerator.getZeroes(), ...this._denominator.getZeroes()], true), NFactors = this._numerator.factors, DFactors = this._denominator.factors;
|
|
3413
|
+
let tableOfSigns = [], result = [];
|
|
3414
|
+
NFactors.forEach(factor => {
|
|
3415
|
+
tableOfSigns.push(this._makeOneLineOfTableOfSigns(factor, zeroes, 'z'));
|
|
3416
|
+
});
|
|
3417
|
+
DFactors.forEach(factor => {
|
|
3418
|
+
tableOfSigns.push(this._makeOneLineOfTableOfSigns(factor, zeroes, 'd'));
|
|
3419
|
+
});
|
|
3420
|
+
// Empty line
|
|
3421
|
+
tableOfSigns.push([]);
|
|
3422
|
+
// Add the final row as cumulative
|
|
3423
|
+
let resultLine = tableOfSigns[0].map((x, index) => {
|
|
3424
|
+
if (index === 0) {
|
|
3425
|
+
return '';
|
|
3426
|
+
}
|
|
3427
|
+
if (index === tableOfSigns[0].length - 1) {
|
|
3428
|
+
return '';
|
|
3429
|
+
}
|
|
3430
|
+
if (index % 2 === 0) {
|
|
3431
|
+
return 't';
|
|
3432
|
+
}
|
|
3433
|
+
return '+';
|
|
3434
|
+
});
|
|
3435
|
+
for (let current of tableOfSigns) {
|
|
3436
|
+
for (let i = 0; i < current.length; i++) {
|
|
3437
|
+
if (i % 2 === 0) {
|
|
3438
|
+
// t, z or d
|
|
3439
|
+
if (resultLine[i] === 'd') {
|
|
3440
|
+
continue;
|
|
3441
|
+
}
|
|
3442
|
+
if (current[i] !== 't') {
|
|
3443
|
+
resultLine[i] = current[i];
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
else {
|
|
3447
|
+
// + or -
|
|
3448
|
+
if (current[i] === '-') {
|
|
3449
|
+
resultLine[i] = resultLine[i] === '+' ? '-' : '+';
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
// Add the variation line.
|
|
3455
|
+
// TODO: add the variation line.
|
|
3456
|
+
tableOfSigns.push(resultLine);
|
|
3457
|
+
let tos = {
|
|
3458
|
+
factors: [...NFactors, ...DFactors],
|
|
3459
|
+
zeroes: zeroes,
|
|
3460
|
+
signs: tableOfSigns,
|
|
3461
|
+
tex: ''
|
|
3462
|
+
};
|
|
3463
|
+
this._makeTexFromTableOfSigns(tos);
|
|
3464
|
+
return tos;
|
|
3465
|
+
};
|
|
3466
|
+
this._makeTexFromTableOfSigns = (tos) => {
|
|
3467
|
+
let tex = `\\begin{tikzpicture}
|
|
3468
|
+
\\tkzTabInit[lgt=3,espcl=2,deltacl=0]{/1.2,\\(${tos.factors.map(x => x.tex).join('\\)/1,\\(')}\\)/1,/.1,\\(f(x)\\)/1.2}{{\\scriptsize \\hspace{1cm} \\(-\\infty\\)},\\(${tos.zeroes.map(x => x.tex).join('\\),\\(')}\\),{\\scriptsize \\hspace{-1cm} \\(+\\infty\\)}}`;
|
|
3469
|
+
tos.signs.forEach(list => {
|
|
3470
|
+
tex += (`\n\\tkzTabLine{${list.join(',')}}`);
|
|
3471
|
+
});
|
|
3472
|
+
tex += `\n\\end{tikzpicture}`;
|
|
3473
|
+
tos.tex = tex;
|
|
3474
|
+
return tex;
|
|
3475
|
+
};
|
|
3476
|
+
this._makeOneLineOfTableOfSigns = (factor, zeroes, zeroSign) => {
|
|
3477
|
+
let oneLine = [],
|
|
3478
|
+
// TODO : check if there is no zero ?
|
|
3479
|
+
currentZero = factor.getZeroes().map(x => x.tex);
|
|
3480
|
+
// First +/- sign, before the first zero
|
|
3481
|
+
oneLine.push('');
|
|
3482
|
+
oneLine.push(factor.evaluate(zeroes[0].value - 1).sign() === 1 ? '+' : '-');
|
|
3483
|
+
for (let i = 0; i < zeroes.length; i++) {
|
|
3484
|
+
// Add the zero if it's the current one
|
|
3485
|
+
oneLine.push(currentZero.includes(zeroes[i].tex) ? zeroSign : 't');
|
|
3486
|
+
// + / - sign after the current zero
|
|
3487
|
+
if (i < zeroes.length - 1) {
|
|
3488
|
+
oneLine.push(factor.evaluate((zeroes[i].value + zeroes[i + 1].value) / 2).sign() === 1 ? '+' : '-');
|
|
3489
|
+
}
|
|
3490
|
+
else if (i === zeroes.length - 1) {
|
|
3491
|
+
oneLine.push(factor.evaluate(zeroes[i].value + 1).sign() === 1 ? '+' : '-');
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
oneLine.push('');
|
|
3495
|
+
return oneLine;
|
|
3496
|
+
};
|
|
3328
3497
|
this._numerator = numerator ? numerator.clone() : new polynom_1.Polynom();
|
|
3329
3498
|
this._denominator = denominator ? denominator.clone() : new polynom_1.Polynom();
|
|
3330
3499
|
}
|
|
@@ -3338,8 +3507,6 @@ class Rational {
|
|
|
3338
3507
|
return `\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`;
|
|
3339
3508
|
}
|
|
3340
3509
|
get texFactors() {
|
|
3341
|
-
this._numerator.factorize();
|
|
3342
|
-
this._denominator.factorize();
|
|
3343
3510
|
return `\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
|
|
3344
3511
|
}
|
|
3345
3512
|
}
|
|
@@ -3684,7 +3851,7 @@ class Fraction {
|
|
|
3684
3851
|
return Math.abs(this._numerator) === Infinity;
|
|
3685
3852
|
};
|
|
3686
3853
|
this.isFinite = () => {
|
|
3687
|
-
return !this.isInfinity();
|
|
3854
|
+
return !this.isInfinity() && !this.isNaN();
|
|
3688
3855
|
};
|
|
3689
3856
|
this.isSquare = () => {
|
|
3690
3857
|
return Math.sqrt(this._numerator) % 1 === 0 && Math.sqrt(this._denominator) % 1 === 0;
|
|
@@ -3729,9 +3896,6 @@ class Fraction {
|
|
|
3729
3896
|
}
|
|
3730
3897
|
return this;
|
|
3731
3898
|
}
|
|
3732
|
-
get isFraction() {
|
|
3733
|
-
return true;
|
|
3734
|
-
}
|
|
3735
3899
|
// ------------------------------------------
|
|
3736
3900
|
// Getter and setter
|
|
3737
3901
|
// ------------------------------------------
|
|
@@ -3805,20 +3969,52 @@ Fraction.min = (...fractions) => {
|
|
|
3805
3969
|
}
|
|
3806
3970
|
return M;
|
|
3807
3971
|
};
|
|
3972
|
+
Fraction.average = (...fractions) => {
|
|
3973
|
+
let M = new Fraction().zero();
|
|
3974
|
+
for (let f of fractions) {
|
|
3975
|
+
M.add(f);
|
|
3976
|
+
}
|
|
3977
|
+
M.divide(fractions.length);
|
|
3978
|
+
return M;
|
|
3979
|
+
};
|
|
3980
|
+
Fraction.unique = (fractions, sorted) => {
|
|
3981
|
+
// TODO: make sure it's wokring -> test !
|
|
3982
|
+
let unique = {}, distinct = [];
|
|
3983
|
+
fractions.forEach(x => {
|
|
3984
|
+
if (!unique[x.clone().reduce().tex]) {
|
|
3985
|
+
distinct.push(x.clone());
|
|
3986
|
+
unique[x.tex] = true;
|
|
3987
|
+
}
|
|
3988
|
+
});
|
|
3989
|
+
if (sorted) {
|
|
3990
|
+
return Fraction.sort(distinct);
|
|
3991
|
+
}
|
|
3992
|
+
else {
|
|
3993
|
+
return distinct;
|
|
3994
|
+
}
|
|
3995
|
+
};
|
|
3996
|
+
Fraction.sort = (fractions, reverse) => {
|
|
3997
|
+
// Todo make sure it's the correct order, not reverse -> make a test
|
|
3998
|
+
let sorted = fractions.sort((a, b) => a.value - b.value);
|
|
3999
|
+
if (reverse) {
|
|
4000
|
+
sorted.reverse();
|
|
4001
|
+
}
|
|
4002
|
+
return sorted;
|
|
4003
|
+
};
|
|
3808
4004
|
|
|
3809
4005
|
|
|
3810
4006
|
/***/ }),
|
|
3811
4007
|
|
|
3812
|
-
/***/
|
|
4008
|
+
/***/ 872:
|
|
3813
4009
|
/***/ ((__unused_webpack_module, exports) => {
|
|
3814
4010
|
|
|
3815
4011
|
|
|
3816
4012
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3817
|
-
exports.
|
|
4013
|
+
exports.NthRoot = void 0;
|
|
3818
4014
|
/**
|
|
3819
|
-
*
|
|
4015
|
+
* NthRoot is something like "a+b\sqrt{3}
|
|
3820
4016
|
*/
|
|
3821
|
-
class
|
|
4017
|
+
class NthRoot {
|
|
3822
4018
|
constructor(...values) {
|
|
3823
4019
|
// ------------------------------------------
|
|
3824
4020
|
// Creation / parsing functions
|
|
@@ -3924,7 +4120,7 @@ class Nthroot {
|
|
|
3924
4120
|
return this._coefficient * Math.pow(this._radical, 1 / this._nth);
|
|
3925
4121
|
}
|
|
3926
4122
|
}
|
|
3927
|
-
exports.
|
|
4123
|
+
exports.NthRoot = NthRoot;
|
|
3928
4124
|
|
|
3929
4125
|
|
|
3930
4126
|
/***/ }),
|