pimath 0.0.63 → 0.0.66
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 +77 -25
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +0 -1
- package/esm/maths/algebra/rational.js +2 -4
- package/esm/maths/algebra/study/rationalStudy.d.ts +1 -7
- package/esm/maths/algebra/study/rationalStudy.js +29 -17
- package/esm/maths/algebra/study/rationalStudy.js.map +1 -1
- package/esm/maths/algebra/study.d.ts +11 -11
- package/esm/maths/algebra/study.js +48 -8
- package/esm/maths/algebra/study.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/study/rationalStudy.ts +32 -21
- package/src/maths/algebra/study.ts +60 -8
- package/tests/algebra/study.test.ts +29 -4
package/dist/pi.js
CHANGED
|
@@ -3444,6 +3444,7 @@ exports.Rational = Rational;
|
|
|
3444
3444
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3445
3445
|
exports.Study = exports.TABLE_OF_SIGNS = exports.FUNCTION_EXTREMA = exports.ASYMPTOTE = exports.ZEROTYPE = void 0;
|
|
3446
3446
|
const fraction_1 = __webpack_require__(506);
|
|
3447
|
+
const numexp_1 = __webpack_require__(735);
|
|
3447
3448
|
var ZEROTYPE;
|
|
3448
3449
|
(function (ZEROTYPE) {
|
|
3449
3450
|
ZEROTYPE["ZERO"] = "z";
|
|
@@ -3493,6 +3494,9 @@ class Study {
|
|
|
3493
3494
|
this._asymptotes = this.makeAsymptotes();
|
|
3494
3495
|
this._derivative = this.makeDerivative();
|
|
3495
3496
|
this._variations = this.makeVariation();
|
|
3497
|
+
this._signs.tex = this.texSigns;
|
|
3498
|
+
this._derivative.tex = this.texGrows;
|
|
3499
|
+
this._variations.tex = this.texVariations;
|
|
3496
3500
|
};
|
|
3497
3501
|
this.indexOfZero = (zeroes, zero) => {
|
|
3498
3502
|
for (let i = 0; i < zeroes.length; i++) {
|
|
@@ -3559,7 +3563,7 @@ class Study {
|
|
|
3559
3563
|
}
|
|
3560
3564
|
return resultLine;
|
|
3561
3565
|
};
|
|
3562
|
-
this.makeGrowsResult = (
|
|
3566
|
+
this.makeGrowsResult = (tos) => {
|
|
3563
3567
|
// Use the last line (=> resultLine) to grab the necessary information
|
|
3564
3568
|
let signsAsArray = Object.values(tos.signs), resultLine = signsAsArray[signsAsArray.length - 1], growsLine = [], extremes = {}, zeroes = tos.zeroes;
|
|
3565
3569
|
// Get the extremes
|
|
@@ -3569,8 +3573,10 @@ class Study {
|
|
|
3569
3573
|
if (resultLine[pos] === 'z') {
|
|
3570
3574
|
// It's a zero. Get the coordinates
|
|
3571
3575
|
let x, y, zero = zeroes[i].exact, pt, xTex, yTex, pointType;
|
|
3576
|
+
// TODO: NumExp should parse something that isn't yet plotFunction
|
|
3577
|
+
let exp = new numexp_1.NumExp(this.fx.plotFunction);
|
|
3572
3578
|
if (zero instanceof fraction_1.Fraction) {
|
|
3573
|
-
let value = zero, evalY = fx.evaluate(value);
|
|
3579
|
+
let value = zero, evalY = this.fx.evaluate(value);
|
|
3574
3580
|
x = zero.value;
|
|
3575
3581
|
y = evalY.value;
|
|
3576
3582
|
xTex = zero.tex;
|
|
@@ -3578,7 +3584,7 @@ class Study {
|
|
|
3578
3584
|
}
|
|
3579
3585
|
else {
|
|
3580
3586
|
x = zeroes[i].value;
|
|
3581
|
-
y =
|
|
3587
|
+
y = exp.evaluate({ x });
|
|
3582
3588
|
xTex = x.toFixed(2);
|
|
3583
3589
|
yTex = y.toFixed(2);
|
|
3584
3590
|
}
|
|
@@ -3616,7 +3622,7 @@ class Study {
|
|
|
3616
3622
|
growsLine.push(`${resultLine[resultLine.length - 2]}/`);
|
|
3617
3623
|
return { growsLine, extremes };
|
|
3618
3624
|
};
|
|
3619
|
-
this.makeVariationsResult = (
|
|
3625
|
+
this.makeVariationsResult = (tos) => {
|
|
3620
3626
|
// TODO: make variations result is not yet implemented.
|
|
3621
3627
|
let extremes = {}, varsLine = [];
|
|
3622
3628
|
return { varsLine, extremes };
|
|
@@ -3650,6 +3656,39 @@ class Study {
|
|
|
3650
3656
|
tex += `\n\\end{tikzpicture}`;
|
|
3651
3657
|
return tex;
|
|
3652
3658
|
};
|
|
3659
|
+
this.drawCode = () => {
|
|
3660
|
+
// Function as string
|
|
3661
|
+
let code = `f(x)=${this.fx.plotFunction}`;
|
|
3662
|
+
// Asymptotes
|
|
3663
|
+
let i = 1;
|
|
3664
|
+
this.asymptotes.forEach(asymptote => {
|
|
3665
|
+
if (asymptote.type === ASYMPTOTE.VERTICAL) {
|
|
3666
|
+
code += `\nav_${i}=line x=${asymptote.zero.value}->red,dash`;
|
|
3667
|
+
i++;
|
|
3668
|
+
}
|
|
3669
|
+
else if (asymptote.type === ASYMPTOTE.HORIZONTAL) {
|
|
3670
|
+
code += `\nah=line y=${asymptote.fx.monoms[0].coefficient.value}->orange,dash`;
|
|
3671
|
+
}
|
|
3672
|
+
else if (asymptote.type === ASYMPTOTE.SLOPE) {
|
|
3673
|
+
code += `\nao=line y=${asymptote.fx.plotFunction}->red,dash`;
|
|
3674
|
+
}
|
|
3675
|
+
i++;
|
|
3676
|
+
});
|
|
3677
|
+
// Extremes
|
|
3678
|
+
for (let zero in this.derivative.extremes) {
|
|
3679
|
+
let extreme = this.derivative.extremes[zero];
|
|
3680
|
+
code += `\nM_${i}(${extreme.value.x},${extreme.value.y})*`;
|
|
3681
|
+
i++;
|
|
3682
|
+
}
|
|
3683
|
+
// Zeroes
|
|
3684
|
+
this.zeroes.forEach(zero => {
|
|
3685
|
+
if (zero.type === ZEROTYPE.ZERO) {
|
|
3686
|
+
code += `\nZ_${i}(${zero.value},0)*`;
|
|
3687
|
+
i++;
|
|
3688
|
+
}
|
|
3689
|
+
});
|
|
3690
|
+
return code;
|
|
3691
|
+
};
|
|
3653
3692
|
this.fx = fx;
|
|
3654
3693
|
this.makeStudy();
|
|
3655
3694
|
return this;
|
|
@@ -3669,7 +3708,7 @@ class Study {
|
|
|
3669
3708
|
get derivative() {
|
|
3670
3709
|
return this._derivative;
|
|
3671
3710
|
}
|
|
3672
|
-
get
|
|
3711
|
+
get texSigns() {
|
|
3673
3712
|
return this._makeTexFromTableOfSigns(this._signs);
|
|
3674
3713
|
}
|
|
3675
3714
|
get texGrows() {
|
|
@@ -3689,7 +3728,8 @@ class Study {
|
|
|
3689
3728
|
factors: [],
|
|
3690
3729
|
zeroes: [],
|
|
3691
3730
|
signs: [],
|
|
3692
|
-
extremes: {}
|
|
3731
|
+
extremes: {},
|
|
3732
|
+
tex: ''
|
|
3693
3733
|
};
|
|
3694
3734
|
}
|
|
3695
3735
|
;
|
|
@@ -3703,7 +3743,8 @@ class Study {
|
|
|
3703
3743
|
factors: [],
|
|
3704
3744
|
zeroes: [],
|
|
3705
3745
|
signs: [],
|
|
3706
|
-
extremes: {}
|
|
3746
|
+
extremes: {},
|
|
3747
|
+
tex: ''
|
|
3707
3748
|
};
|
|
3708
3749
|
}
|
|
3709
3750
|
makeVariation() {
|
|
@@ -3713,7 +3754,8 @@ class Study {
|
|
|
3713
3754
|
factors: [],
|
|
3714
3755
|
zeroes: [],
|
|
3715
3756
|
signs: [],
|
|
3716
|
-
extremes: {}
|
|
3757
|
+
extremes: {},
|
|
3758
|
+
tex: ''
|
|
3717
3759
|
};
|
|
3718
3760
|
}
|
|
3719
3761
|
}
|
|
@@ -3746,19 +3788,19 @@ exports.RationalStudy = void 0;
|
|
|
3746
3788
|
const study_1 = __webpack_require__(996);
|
|
3747
3789
|
const rational_1 = __webpack_require__(107);
|
|
3748
3790
|
const fraction_1 = __webpack_require__(506);
|
|
3791
|
+
const polynom_1 = __webpack_require__(38);
|
|
3749
3792
|
class RationalStudy extends study_1.Study {
|
|
3750
3793
|
constructor(fx) {
|
|
3751
|
-
console.log('RATIONAL STUDY');
|
|
3752
3794
|
super(fx);
|
|
3753
3795
|
return this;
|
|
3754
3796
|
}
|
|
3755
3797
|
makeZeroes() {
|
|
3756
|
-
console.log('GETTING ZEROES');
|
|
3757
3798
|
return this._getZeroes(this.fx);
|
|
3758
3799
|
}
|
|
3759
3800
|
;
|
|
3760
3801
|
makeSigns() {
|
|
3761
|
-
|
|
3802
|
+
let tos = this._getSigns(this.fx, this.zeroes);
|
|
3803
|
+
return tos;
|
|
3762
3804
|
}
|
|
3763
3805
|
;
|
|
3764
3806
|
makeAsymptotes() {
|
|
@@ -3782,44 +3824,52 @@ class RationalStudy extends study_1.Study {
|
|
|
3782
3824
|
}
|
|
3783
3825
|
}
|
|
3784
3826
|
asymptotes.push({
|
|
3827
|
+
fx: null,
|
|
3785
3828
|
type: Ztype,
|
|
3786
3829
|
tex: tex,
|
|
3787
3830
|
zero: zero,
|
|
3788
3831
|
limits: `\\lim_{x\\to${zero.tex} }\\ f(x) = \\pm\\infty`,
|
|
3789
|
-
deltaX: null
|
|
3832
|
+
deltaX: null,
|
|
3833
|
+
tableOfSign: null
|
|
3790
3834
|
});
|
|
3791
3835
|
});
|
|
3792
3836
|
// Sloped asymptote
|
|
3793
3837
|
let NDegree = this.fx.numerator.degree(), DDegree = this.fx.denominator.degree();
|
|
3794
3838
|
if (NDegree.isEqual(DDegree)) {
|
|
3795
|
-
let H = this.fx.numerator.monomByDegree().coefficient.clone().divide(this.fx.denominator.monomByDegree().coefficient).tex;
|
|
3796
|
-
let { reminder } = reduced.euclidian();
|
|
3839
|
+
let H = this.fx.numerator.monomByDegree().coefficient.clone().divide(this.fx.denominator.monomByDegree().coefficient), Htex = H.tex;
|
|
3840
|
+
let { reminder } = reduced.euclidian(), deltaX = new rational_1.Rational(reminder, reduced.denominator);
|
|
3797
3841
|
asymptotes.push({
|
|
3842
|
+
fx: new polynom_1.Polynom(H),
|
|
3798
3843
|
type: study_1.ASYMPTOTE.HORIZONTAL,
|
|
3799
|
-
tex: `y=${
|
|
3844
|
+
tex: `y=${Htex}`,
|
|
3800
3845
|
zero: null,
|
|
3801
|
-
limits: `\\lim_{x\\to\\infty}\\ f(x) = ${
|
|
3802
|
-
deltaX
|
|
3846
|
+
limits: `\\lim_{x\\to\\infty}\\ f(x) = ${Htex}`,
|
|
3847
|
+
deltaX,
|
|
3848
|
+
tableOfSign: this._getSigns(deltaX)
|
|
3803
3849
|
});
|
|
3804
3850
|
}
|
|
3805
3851
|
else if (DDegree.greater(NDegree)) {
|
|
3806
3852
|
asymptotes.push({
|
|
3853
|
+
fx: new polynom_1.Polynom('0'),
|
|
3807
3854
|
type: study_1.ASYMPTOTE.HORIZONTAL,
|
|
3808
3855
|
tex: `y=0`,
|
|
3809
3856
|
zero: null,
|
|
3810
3857
|
limits: `\\lim_{x\\to\\infty}\\ f(x) = ${0}`,
|
|
3811
|
-
deltaX: null
|
|
3858
|
+
deltaX: null,
|
|
3859
|
+
tableOfSign: null
|
|
3812
3860
|
});
|
|
3813
3861
|
}
|
|
3814
3862
|
else if (NDegree.value - 1 === DDegree.value) {
|
|
3815
3863
|
// Calculate the slope
|
|
3816
|
-
let { quotient, reminder } = reduced.euclidian();
|
|
3864
|
+
let { quotient, reminder } = reduced.euclidian(), deltaX = new rational_1.Rational(reminder, reduced.denominator);
|
|
3817
3865
|
asymptotes.push({
|
|
3866
|
+
fx: quotient.clone(),
|
|
3818
3867
|
type: study_1.ASYMPTOTE.SLOPE,
|
|
3819
3868
|
tex: `y=${quotient.tex}`,
|
|
3820
3869
|
zero: null,
|
|
3821
3870
|
limits: ``,
|
|
3822
|
-
deltaX: new rational_1.Rational(reminder, reduced.denominator)
|
|
3871
|
+
deltaX: new rational_1.Rational(reminder, reduced.denominator),
|
|
3872
|
+
tableOfSign: this._getSigns(deltaX)
|
|
3823
3873
|
});
|
|
3824
3874
|
}
|
|
3825
3875
|
return asymptotes;
|
|
@@ -3827,18 +3877,16 @@ class RationalStudy extends study_1.Study {
|
|
|
3827
3877
|
;
|
|
3828
3878
|
makeDerivative() {
|
|
3829
3879
|
let dx = this.fx.clone().derivative(), tos = this._getSigns(dx, this._getZeroes(dx), study_1.TABLE_OF_SIGNS.GROWS);
|
|
3830
|
-
|
|
3831
|
-
let result = this.makeGrowsResult(this.fx, tos);
|
|
3880
|
+
let result = this.makeGrowsResult(tos);
|
|
3832
3881
|
tos.signs.push(result.growsLine);
|
|
3833
3882
|
tos.extremes = result.extremes;
|
|
3834
|
-
console.log(tos.signs.length);
|
|
3835
3883
|
return tos;
|
|
3836
3884
|
}
|
|
3837
3885
|
;
|
|
3838
3886
|
makeVariation() {
|
|
3839
3887
|
// Get the zeroes, make signs.
|
|
3840
3888
|
let dx = this.derivative.fx.clone().derivative(), tos = this._getSigns(dx, this._getZeroes(dx), study_1.TABLE_OF_SIGNS.VARIATIONS);
|
|
3841
|
-
let result = this.makeVariationsResult(
|
|
3889
|
+
let result = this.makeVariationsResult(tos);
|
|
3842
3890
|
tos.signs.push(result.varsLine);
|
|
3843
3891
|
tos.extremes = result.extremes;
|
|
3844
3892
|
return tos;
|
|
@@ -3880,6 +3928,9 @@ class RationalStudy extends study_1.Study {
|
|
|
3880
3928
|
_getSigns(fx, zeroes, typeOfTable) {
|
|
3881
3929
|
// Factorize the rational
|
|
3882
3930
|
let signs = [], factors = [];
|
|
3931
|
+
if (zeroes === undefined) {
|
|
3932
|
+
zeroes = this._getZeroes(fx);
|
|
3933
|
+
}
|
|
3883
3934
|
fx.numerator.factors.forEach(factor => {
|
|
3884
3935
|
signs.push(this.makeOneLineForSigns(factor, zeroes, study_1.ZEROTYPE.ZERO));
|
|
3885
3936
|
factors.push(factor.clone());
|
|
@@ -3895,7 +3946,8 @@ class RationalStudy extends study_1.Study {
|
|
|
3895
3946
|
factors,
|
|
3896
3947
|
zeroes,
|
|
3897
3948
|
signs,
|
|
3898
|
-
extremes: {}
|
|
3949
|
+
extremes: {},
|
|
3950
|
+
tex: ''
|
|
3899
3951
|
};
|
|
3900
3952
|
}
|
|
3901
3953
|
}
|