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