pimath 0.0.62 → 0.0.63

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 CHANGED
@@ -3264,6 +3264,7 @@ exports.Rational = void 0;
3264
3264
  const polynom_1 = __webpack_require__(38);
3265
3265
  const fraction_1 = __webpack_require__(506);
3266
3266
  const equation_1 = __webpack_require__(760);
3267
+ const rationalStudy_1 = __webpack_require__(572);
3267
3268
  /**
3268
3269
  * Rational class can handle rational polynoms
3269
3270
  */
@@ -3389,6 +3390,9 @@ class Rational {
3389
3390
  let N = this._numerator.evaluate(values), D = this._denominator.evaluate(values);
3390
3391
  return N.divide(D);
3391
3392
  };
3393
+ this.study = () => {
3394
+ return new rationalStudy_1.RationalStudy(this);
3395
+ };
3392
3396
  if (numerator instanceof polynom_1.Polynom) {
3393
3397
  this._numerator = numerator.clone();
3394
3398
  }
@@ -3427,6 +3431,477 @@ class Rational {
3427
3431
  exports.Rational = Rational;
3428
3432
 
3429
3433
 
3434
+ /***/ }),
3435
+
3436
+ /***/ 996:
3437
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3438
+
3439
+
3440
+ /**
3441
+ * Rational polynom module contains everything necessary to handle rational polynoms.
3442
+ * @module Polynom
3443
+ */
3444
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3445
+ exports.Study = exports.TABLE_OF_SIGNS = exports.FUNCTION_EXTREMA = exports.ASYMPTOTE = exports.ZEROTYPE = void 0;
3446
+ const fraction_1 = __webpack_require__(506);
3447
+ var ZEROTYPE;
3448
+ (function (ZEROTYPE) {
3449
+ ZEROTYPE["ZERO"] = "z";
3450
+ ZEROTYPE["DEFENCE"] = "d";
3451
+ ZEROTYPE["NOTHING"] = "t";
3452
+ })(ZEROTYPE = exports.ZEROTYPE || (exports.ZEROTYPE = {}));
3453
+ var ASYMPTOTE;
3454
+ (function (ASYMPTOTE) {
3455
+ ASYMPTOTE["VERTICAL"] = "av";
3456
+ ASYMPTOTE["HORIZONTAL"] = "ah";
3457
+ ASYMPTOTE["SLOPE"] = "ao";
3458
+ ASYMPTOTE["HOLE"] = "hole";
3459
+ })(ASYMPTOTE = exports.ASYMPTOTE || (exports.ASYMPTOTE = {}));
3460
+ var FUNCTION_EXTREMA;
3461
+ (function (FUNCTION_EXTREMA) {
3462
+ FUNCTION_EXTREMA["MIN"] = "min";
3463
+ FUNCTION_EXTREMA["MAX"] = "max";
3464
+ FUNCTION_EXTREMA["FLAT"] = "flat";
3465
+ FUNCTION_EXTREMA["NOTHING"] = "";
3466
+ })(FUNCTION_EXTREMA = exports.FUNCTION_EXTREMA || (exports.FUNCTION_EXTREMA = {}));
3467
+ var TABLE_OF_SIGNS;
3468
+ (function (TABLE_OF_SIGNS) {
3469
+ TABLE_OF_SIGNS[TABLE_OF_SIGNS["DEFAULT"] = 0] = "DEFAULT";
3470
+ TABLE_OF_SIGNS[TABLE_OF_SIGNS["GROWS"] = 1] = "GROWS";
3471
+ TABLE_OF_SIGNS[TABLE_OF_SIGNS["VARIATIONS"] = 2] = "VARIATIONS";
3472
+ })(TABLE_OF_SIGNS = exports.TABLE_OF_SIGNS || (exports.TABLE_OF_SIGNS = {}));
3473
+ /**
3474
+ * The study class is a "function study" class that will get:
3475
+ * fx : get the function
3476
+ * domain : string
3477
+ * zeroes : Object (tex, IZero)
3478
+ * signs : table of signs + tex output using tkz-tab
3479
+ * av : vertical asymptotic
3480
+ * ah : horizontal asymptotic
3481
+ * ao : obliques
3482
+ * deltaX : position relative
3483
+ * dx : derivative
3484
+ * grows : growing table + tex output using tkz-tab
3485
+ * ddx : dérivée seconde
3486
+ * variations : variation table + tex output using tkz-tab
3487
+ */
3488
+ class Study {
3489
+ constructor(fx) {
3490
+ this.makeStudy = () => {
3491
+ this._zeroes = this.makeZeroes();
3492
+ this._signs = this.makeSigns();
3493
+ this._asymptotes = this.makeAsymptotes();
3494
+ this._derivative = this.makeDerivative();
3495
+ this._variations = this.makeVariation();
3496
+ };
3497
+ this.indexOfZero = (zeroes, zero) => {
3498
+ for (let i = 0; i < zeroes.length; i++) {
3499
+ if (zeroes[i].tex === zero.tex) {
3500
+ return i;
3501
+ }
3502
+ }
3503
+ return -1;
3504
+ };
3505
+ this.makeOneLineForSigns = (factor, zeroes, zeroSign) => {
3506
+ let oneLine = [], currentZero = factor.getZeroes().map(x => x.tex);
3507
+ // First +/- sign, before the first zero
3508
+ oneLine.push('');
3509
+ if (factor.degree().isZero()) {
3510
+ oneLine.push(factor.monoms[0].coefficient.sign() === 1 ? '+' : '-');
3511
+ }
3512
+ else {
3513
+ oneLine.push(factor.evaluate(zeroes[0].value - 1).sign() === 1 ? '+' : '-');
3514
+ }
3515
+ for (let i = 0; i < zeroes.length; i++) {
3516
+ // Add the zero if it's the current one
3517
+ oneLine.push(currentZero.includes(zeroes[i].tex) ? zeroSign : ZEROTYPE.NOTHING);
3518
+ // + / - sign after the current zero
3519
+ if (i < zeroes.length - 1) {
3520
+ oneLine.push(factor.evaluate((zeroes[i].value + zeroes[i + 1].value) / 2).sign() === 1 ? '+' : '-');
3521
+ }
3522
+ else if (i === zeroes.length - 1) {
3523
+ oneLine.push(factor.evaluate(zeroes[i].value + 1).sign() === 1 ? '+' : '-');
3524
+ }
3525
+ }
3526
+ oneLine.push('');
3527
+ return oneLine;
3528
+ };
3529
+ this.makeSignsResult = (signs) => {
3530
+ // Initialize the result line with the first line of the signs table
3531
+ let resultLine = signs[0].map((x, index) => {
3532
+ if (index === 0 || index === signs[0].length - 1) {
3533
+ return '';
3534
+ }
3535
+ if (index % 2 === 0) {
3536
+ return 't';
3537
+ }
3538
+ return '+';
3539
+ });
3540
+ // Go through each lines (except the first)
3541
+ for (let current of signs) {
3542
+ for (let i = 0; i < current.length; i++) {
3543
+ if (i % 2 === 0) {
3544
+ // t, z or d
3545
+ if (resultLine[i] === 'd') {
3546
+ continue;
3547
+ }
3548
+ if (current[i] !== 't') {
3549
+ resultLine[i] = current[i];
3550
+ }
3551
+ }
3552
+ else {
3553
+ // + or -
3554
+ if (current[i] === '-') {
3555
+ resultLine[i] = resultLine[i] === '+' ? '-' : '+';
3556
+ }
3557
+ }
3558
+ }
3559
+ }
3560
+ return resultLine;
3561
+ };
3562
+ this.makeGrowsResult = (fx, tos) => {
3563
+ // Use the last line (=> resultLine) to grab the necessary information
3564
+ let signsAsArray = Object.values(tos.signs), resultLine = signsAsArray[signsAsArray.length - 1], growsLine = [], extremes = {}, zeroes = tos.zeroes;
3565
+ // Get the extremes
3566
+ for (let i = 0; i < zeroes.length; i++) {
3567
+ // Get the corresponding item in the resultLine.
3568
+ let pos = 2 * i + 2;
3569
+ if (resultLine[pos] === 'z') {
3570
+ // It's a zero. Get the coordinates
3571
+ let x, y, zero = zeroes[i].exact, pt, xTex, yTex, pointType;
3572
+ if (zero instanceof fraction_1.Fraction) {
3573
+ let value = zero, evalY = fx.evaluate(value);
3574
+ x = zero.value;
3575
+ y = evalY.value;
3576
+ xTex = zero.tex;
3577
+ yTex = evalY.tex;
3578
+ }
3579
+ else {
3580
+ x = zeroes[i].value;
3581
+ y = fx.evaluate(zeroes[i].value).value;
3582
+ xTex = x.toFixed(2);
3583
+ yTex = y.toFixed(2);
3584
+ }
3585
+ // Determine the type of the zero.
3586
+ if (resultLine[pos - 1] === resultLine[pos + 1]) {
3587
+ pointType = FUNCTION_EXTREMA.FLAT;
3588
+ }
3589
+ else if (resultLine[pos - 1] === '+') {
3590
+ pointType = FUNCTION_EXTREMA.MAX;
3591
+ }
3592
+ else {
3593
+ pointType = FUNCTION_EXTREMA.MIN;
3594
+ }
3595
+ // Add the point to the list
3596
+ extremes[zeroes[i].tex] = {
3597
+ type: pointType,
3598
+ tex: { x: xTex, y: yTex },
3599
+ value: { x, y }
3600
+ };
3601
+ }
3602
+ }
3603
+ // Create the grows line, based on tkz-tab
3604
+ // \tkzTabLine{ , + , z , - , d , - , z , + , }
3605
+ // \tkzTabVar{ -/ , +/$3$ , -D+/ , -/$1$ , +/ }
3606
+ growsLine.push(resultLine[1] === '+' ? '-/' : '+/');
3607
+ for (let i = 1; i < resultLine.length - 1; i++) {
3608
+ if (resultLine[i] === "z") {
3609
+ let extr = extremes[zeroes[(i - 2) / 2].tex];
3610
+ growsLine.push(`${resultLine[i - 1]}/\\(${extr.type}(${extr.tex.x};${extr.tex.y})\\)`);
3611
+ }
3612
+ else if (resultLine[i] === 'd') {
3613
+ growsLine.push(`${resultLine[i - 1]}D${resultLine[i + 1] === '+' ? '-' : '+'}/`);
3614
+ }
3615
+ }
3616
+ growsLine.push(`${resultLine[resultLine.length - 2]}/`);
3617
+ return { growsLine, extremes };
3618
+ };
3619
+ this.makeVariationsResult = (fx, tos) => {
3620
+ // TODO: make variations result is not yet implemented.
3621
+ let extremes = {}, varsLine = [];
3622
+ return { varsLine, extremes };
3623
+ };
3624
+ this._makeTexFromTableOfSigns = (tos) => {
3625
+ let factors = tos.factors.map(x => `\\(${x.tex}\\)/1`), factorsFx = "\\(fx\\)/1.2", zeroes = tos.zeroes;
3626
+ // Add the last lines "label"
3627
+ if (tos.type === TABLE_OF_SIGNS.GROWS) {
3628
+ factorsFx = "\\(f'(x)\\)/1.2,\\(f(x)\\)/2";
3629
+ }
3630
+ else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
3631
+ factorsFx = "\\(f''(x)\\)/1.2,\\(f(x)\\)/2";
3632
+ }
3633
+ // Create the tikzPicture header
3634
+ let tex = `\\begin{tikzpicture}
3635
+ \\tkzTabInit[lgt=3,espcl=2,deltacl=0]{/1.2,${factors.join(',')},/.1,${factorsFx} }{{\\scriptsize \\hspace{1cm} \\(-\\infty\\)},\\(${zeroes.map(x => x.tex).join('\\),\\(')}\\),{\\scriptsize \\hspace{-1cm} \\(+\\infty\\)}}`;
3636
+ let pos;
3637
+ for (pos = 0; pos < tos.factors.length; pos++) {
3638
+ tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`);
3639
+ }
3640
+ // Add the result line
3641
+ tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`);
3642
+ // Add the grows / vars line
3643
+ if (tos.type === TABLE_OF_SIGNS.GROWS) {
3644
+ tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`);
3645
+ }
3646
+ else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
3647
+ // TODO: Check variations table for as tex
3648
+ tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`);
3649
+ }
3650
+ tex += `\n\\end{tikzpicture}`;
3651
+ return tex;
3652
+ };
3653
+ this.fx = fx;
3654
+ this.makeStudy();
3655
+ return this;
3656
+ }
3657
+ get zeroes() {
3658
+ return this._zeroes;
3659
+ }
3660
+ get domain() {
3661
+ return this.fx.domain();
3662
+ }
3663
+ get signs() {
3664
+ return this._signs;
3665
+ }
3666
+ get asymptotes() {
3667
+ return this._asymptotes;
3668
+ }
3669
+ get derivative() {
3670
+ return this._derivative;
3671
+ }
3672
+ get tex() {
3673
+ return this._makeTexFromTableOfSigns(this._signs);
3674
+ }
3675
+ get texGrows() {
3676
+ return this._makeTexFromTableOfSigns(this._derivative);
3677
+ }
3678
+ get texVariations() {
3679
+ return this._makeTexFromTableOfSigns(this._variations);
3680
+ }
3681
+ makeZeroes() {
3682
+ return [];
3683
+ }
3684
+ ;
3685
+ makeSigns() {
3686
+ return {
3687
+ type: TABLE_OF_SIGNS.DEFAULT,
3688
+ fx: null,
3689
+ factors: [],
3690
+ zeroes: [],
3691
+ signs: [],
3692
+ extremes: {}
3693
+ };
3694
+ }
3695
+ ;
3696
+ makeAsymptotes() {
3697
+ return [];
3698
+ }
3699
+ makeDerivative() {
3700
+ return {
3701
+ type: TABLE_OF_SIGNS.GROWS,
3702
+ fx: null,
3703
+ factors: [],
3704
+ zeroes: [],
3705
+ signs: [],
3706
+ extremes: {}
3707
+ };
3708
+ }
3709
+ makeVariation() {
3710
+ return {
3711
+ type: TABLE_OF_SIGNS.VARIATIONS,
3712
+ fx: null,
3713
+ factors: [],
3714
+ zeroes: [],
3715
+ signs: [],
3716
+ extremes: {}
3717
+ };
3718
+ }
3719
+ }
3720
+ exports.Study = Study;
3721
+
3722
+
3723
+ /***/ }),
3724
+
3725
+ /***/ 572:
3726
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3727
+
3728
+
3729
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3730
+ exports.RationalStudy = void 0;
3731
+ /**
3732
+ * The study class is a "function study" class that will get:
3733
+ * fx : get the function
3734
+ * domain : string
3735
+ * zeroes : Object (tex, IZero)
3736
+ * signs : table of signs + tex output using tkz-tab
3737
+ * av : vertical asymptotic
3738
+ * ah : horizontal asymptotic
3739
+ * ao : obliques
3740
+ * deltaX : position relative
3741
+ * dx : derivative
3742
+ * grows : growing table + tex output using tkz-tab
3743
+ * ddx : dérivée seconde
3744
+ * variations : variation table + tex output using tkz-tab
3745
+ */
3746
+ const study_1 = __webpack_require__(996);
3747
+ const rational_1 = __webpack_require__(107);
3748
+ const fraction_1 = __webpack_require__(506);
3749
+ class RationalStudy extends study_1.Study {
3750
+ constructor(fx) {
3751
+ console.log('RATIONAL STUDY');
3752
+ super(fx);
3753
+ return this;
3754
+ }
3755
+ makeZeroes() {
3756
+ console.log('GETTING ZEROES');
3757
+ return this._getZeroes(this.fx);
3758
+ }
3759
+ ;
3760
+ makeSigns() {
3761
+ return this._getSigns(this.fx, this.zeroes);
3762
+ }
3763
+ ;
3764
+ makeAsymptotes() {
3765
+ const reduced = this.fx.clone().reduce();
3766
+ // Vertical
3767
+ let asymptotes = [];
3768
+ this.zeroes.filter(x => x.type === study_1.ZEROTYPE.DEFENCE).forEach(zero => {
3769
+ // Check if it's a hole or an asymptote
3770
+ // TODO: Check for a hole ! Means calculate the limits !
3771
+ let Ztype = study_1.ASYMPTOTE.VERTICAL, tex = `x=${zero.tex}`;
3772
+ if (zero.exact instanceof fraction_1.Fraction) {
3773
+ if (reduced.denominator.evaluate(zero.exact).isNotZero()) {
3774
+ Ztype = study_1.ASYMPTOTE.HOLE;
3775
+ tex = `(${zero.tex};${reduced.evaluate(zero.exact).tex})`;
3776
+ }
3777
+ }
3778
+ else {
3779
+ if (reduced.denominator.evaluate(zero.value).isNotZero()) {
3780
+ Ztype = study_1.ASYMPTOTE.HOLE;
3781
+ tex = `(${zero.tex};${reduced.evaluate(zero.value).tex})`;
3782
+ }
3783
+ }
3784
+ asymptotes.push({
3785
+ type: Ztype,
3786
+ tex: tex,
3787
+ zero: zero,
3788
+ limits: `\\lim_{x\\to${zero.tex} }\\ f(x) = \\pm\\infty`,
3789
+ deltaX: null
3790
+ });
3791
+ });
3792
+ // Sloped asymptote
3793
+ let NDegree = this.fx.numerator.degree(), DDegree = this.fx.denominator.degree();
3794
+ 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();
3797
+ asymptotes.push({
3798
+ type: study_1.ASYMPTOTE.HORIZONTAL,
3799
+ tex: `y=${H}`,
3800
+ zero: null,
3801
+ limits: `\\lim_{x\\to\\infty}\\ f(x) = ${H}`,
3802
+ deltaX: new rational_1.Rational(reminder, reduced.denominator)
3803
+ });
3804
+ }
3805
+ else if (DDegree.greater(NDegree)) {
3806
+ asymptotes.push({
3807
+ type: study_1.ASYMPTOTE.HORIZONTAL,
3808
+ tex: `y=0`,
3809
+ zero: null,
3810
+ limits: `\\lim_{x\\to\\infty}\\ f(x) = ${0}`,
3811
+ deltaX: null
3812
+ });
3813
+ }
3814
+ else if (NDegree.value - 1 === DDegree.value) {
3815
+ // Calculate the slope
3816
+ let { quotient, reminder } = reduced.euclidian();
3817
+ asymptotes.push({
3818
+ type: study_1.ASYMPTOTE.SLOPE,
3819
+ tex: `y=${quotient.tex}`,
3820
+ zero: null,
3821
+ limits: ``,
3822
+ deltaX: new rational_1.Rational(reminder, reduced.denominator)
3823
+ });
3824
+ }
3825
+ return asymptotes;
3826
+ }
3827
+ ;
3828
+ makeDerivative() {
3829
+ let dx = this.fx.clone().derivative(), tos = this._getSigns(dx, this._getZeroes(dx), study_1.TABLE_OF_SIGNS.GROWS);
3830
+ console.log(tos.factors.length, tos.signs.length);
3831
+ let result = this.makeGrowsResult(this.fx, tos);
3832
+ tos.signs.push(result.growsLine);
3833
+ tos.extremes = result.extremes;
3834
+ console.log(tos.signs.length);
3835
+ return tos;
3836
+ }
3837
+ ;
3838
+ makeVariation() {
3839
+ // Get the zeroes, make signs.
3840
+ 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(this.fx, tos);
3842
+ tos.signs.push(result.varsLine);
3843
+ tos.extremes = result.extremes;
3844
+ return tos;
3845
+ }
3846
+ ;
3847
+ _getZeroes(fx) {
3848
+ // All zeroes.
3849
+ let zeroes = [];
3850
+ fx.numerator.getZeroes().filter(x => !isNaN(x.value)).forEach(z => {
3851
+ // add the item
3852
+ zeroes.push({
3853
+ tex: z.tex,
3854
+ value: z.value,
3855
+ exact: z.exact,
3856
+ extrema: study_1.FUNCTION_EXTREMA.NOTHING,
3857
+ type: study_1.ZEROTYPE.ZERO
3858
+ });
3859
+ });
3860
+ fx.denominator.getZeroes().filter(x => !isNaN(x.value)).forEach(z => {
3861
+ let idx = this.indexOfZero(zeroes, z);
3862
+ if (idx !== -1) {
3863
+ zeroes[idx].type = study_1.ZEROTYPE.DEFENCE;
3864
+ }
3865
+ else {
3866
+ // Add the item
3867
+ zeroes.push({
3868
+ tex: z.tex,
3869
+ value: z.value,
3870
+ exact: z.exact,
3871
+ extrema: study_1.FUNCTION_EXTREMA.NOTHING,
3872
+ type: study_1.ZEROTYPE.DEFENCE
3873
+ });
3874
+ }
3875
+ });
3876
+ // sort all zeroes
3877
+ zeroes.sort((a, b) => a.value - b.value);
3878
+ return zeroes;
3879
+ }
3880
+ _getSigns(fx, zeroes, typeOfTable) {
3881
+ // Factorize the rational
3882
+ let signs = [], factors = [];
3883
+ fx.numerator.factors.forEach(factor => {
3884
+ signs.push(this.makeOneLineForSigns(factor, zeroes, study_1.ZEROTYPE.ZERO));
3885
+ factors.push(factor.clone());
3886
+ });
3887
+ fx.denominator.factors.forEach(factor => {
3888
+ signs.push(this.makeOneLineForSigns(factor, zeroes, study_1.ZEROTYPE.DEFENCE));
3889
+ factors.push(factor.clone());
3890
+ });
3891
+ signs.push(this.makeSignsResult(signs));
3892
+ return {
3893
+ type: typeOfTable,
3894
+ fx,
3895
+ factors,
3896
+ zeroes,
3897
+ signs,
3898
+ extremes: {}
3899
+ };
3900
+ }
3901
+ }
3902
+ exports.RationalStudy = RationalStudy;
3903
+
3904
+
3430
3905
  /***/ }),
3431
3906
 
3432
3907
  /***/ 506: