pimath 0.0.38 → 0.0.39
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 +72 -19
- 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/polynom.d.ts +2 -0
- package/esm/maths/algebra/polynom.js +22 -0
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +6 -6
- package/esm/maths/algebra/rational.js +39 -19
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/coefficients/fraction.js +3 -0
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/geometry/line.js +8 -0
- package/esm/maths/geometry/line.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/polynom.ts +28 -0
- package/src/maths/algebra/rational.ts +129 -101
- package/src/maths/coefficients/fraction.ts +4 -0
- package/src/maths/geometry/line.ts +6 -0
- package/src/maths/geometry/point.ts +2 -2
- package/tests/algebra/rationnal.test.ts +44 -0
package/dist/pi.js
CHANGED
|
@@ -2736,6 +2736,28 @@ class Polynom {
|
|
|
2736
2736
|
}
|
|
2737
2737
|
return M;
|
|
2738
2738
|
};
|
|
2739
|
+
this.limitToInfinity = (letter) => {
|
|
2740
|
+
const M = this.monomByDegree(undefined, letter), sign = M.coefficient.sign(), degree = M.degree(letter);
|
|
2741
|
+
if (degree.isStrictlyPositive()) {
|
|
2742
|
+
return sign === 1 ? (new fraction_1.Fraction()).infinite() : (new fraction_1.Fraction()).infinite().opposed();
|
|
2743
|
+
}
|
|
2744
|
+
else if (degree.isZero()) {
|
|
2745
|
+
return M.coefficient;
|
|
2746
|
+
}
|
|
2747
|
+
// Any other cases
|
|
2748
|
+
return (new fraction_1.Fraction()).zero();
|
|
2749
|
+
};
|
|
2750
|
+
this.limitToNegativeInfinity = (letter) => {
|
|
2751
|
+
const M = this.monomByDegree(undefined, letter), sign = M.coefficient.sign(), degree = M.degree(letter);
|
|
2752
|
+
if (degree.isStrictlyPositive()) {
|
|
2753
|
+
return sign === -1 ? (new fraction_1.Fraction()).infinite() : (new fraction_1.Fraction()).infinite().opposed();
|
|
2754
|
+
}
|
|
2755
|
+
else if (degree.isZero()) {
|
|
2756
|
+
return M.coefficient;
|
|
2757
|
+
}
|
|
2758
|
+
// Any other cases
|
|
2759
|
+
return (new fraction_1.Fraction()).zero();
|
|
2760
|
+
};
|
|
2739
2761
|
this.genDisplay = (output, forceSign, wrapParentheses) => {
|
|
2740
2762
|
let P = '';
|
|
2741
2763
|
for (const k of this._monoms) {
|
|
@@ -3238,9 +3260,7 @@ class Rational {
|
|
|
3238
3260
|
return this;
|
|
3239
3261
|
};
|
|
3240
3262
|
this.reduce = () => {
|
|
3241
|
-
console.log(this._numerator.tex);
|
|
3242
3263
|
this._numerator.factorize();
|
|
3243
|
-
console.log(this._numerator.factors.map(x => x.tex));
|
|
3244
3264
|
for (let f of this._numerator.factors) {
|
|
3245
3265
|
this.simplify(f);
|
|
3246
3266
|
}
|
|
@@ -3265,27 +3285,55 @@ class Rational {
|
|
|
3265
3285
|
this.subtract = (R) => {
|
|
3266
3286
|
return this.add(R.clone().opposed());
|
|
3267
3287
|
};
|
|
3268
|
-
this.limits = (value, letter) => {
|
|
3288
|
+
this.limits = (value, offset, letter) => {
|
|
3269
3289
|
if (value === Infinity || value === -Infinity) {
|
|
3270
|
-
let
|
|
3271
|
-
|
|
3272
|
-
if (
|
|
3273
|
-
return
|
|
3274
|
-
|
|
3275
|
-
if (N.degree(letter).isZero()) {
|
|
3276
|
-
return N.coefficient;
|
|
3290
|
+
let { quotient, reminder } = this._numerator.clone().euclidian(this._denominator);
|
|
3291
|
+
// quotient is positive => it will be infinite.
|
|
3292
|
+
if (quotient.degree(letter).isStrictlyPositive()) {
|
|
3293
|
+
return value === Infinity ? quotient.limitToInfinity(letter) : quotient.limitToNegativeInfinity(letter);
|
|
3294
|
+
// return quotient.monomByDegree(undefined, letter).coefficient.sign()===1?(new Fraction()).infinite():(new Fraction()).infinite().opposed()
|
|
3277
3295
|
}
|
|
3278
|
-
|
|
3279
|
-
return
|
|
3296
|
+
else {
|
|
3297
|
+
return quotient.monomByDegree(undefined, letter).coefficient;
|
|
3280
3298
|
}
|
|
3281
3299
|
}
|
|
3282
3300
|
else {
|
|
3283
|
-
|
|
3301
|
+
let evalValues = {}, evalValuesOffset = {}, theLimit, theSign, FR = this.clone().reduce();
|
|
3302
|
+
evalValues[letter === undefined ? 'x' : letter] = new fraction_1.Fraction(value);
|
|
3303
|
+
if (offset !== 'above' && offset !== 'below') {
|
|
3304
|
+
theLimit = FR._numerator.evaluate(evalValues)
|
|
3305
|
+
.divide(FR._denominator.evaluate(evalValues));
|
|
3306
|
+
return theLimit.isInfinity() ? theLimit.abs() : theLimit;
|
|
3307
|
+
}
|
|
3308
|
+
else {
|
|
3309
|
+
if (offset === 'above') {
|
|
3310
|
+
evalValuesOffset[letter === undefined ? 'x' : letter] = (new fraction_1.Fraction(value)).add(0.000001);
|
|
3311
|
+
}
|
|
3312
|
+
else if (offset === 'below') {
|
|
3313
|
+
evalValuesOffset[letter === undefined ? 'x' : letter] = (new fraction_1.Fraction(value)).subtract(0.000001);
|
|
3314
|
+
}
|
|
3315
|
+
theLimit = FR._numerator.evaluate(evalValues)
|
|
3316
|
+
.divide(FR._denominator.evaluate(evalValues));
|
|
3317
|
+
theSign = FR._numerator.evaluate(evalValuesOffset)
|
|
3318
|
+
.divide(FR._denominator.evaluate(evalValuesOffset)).sign();
|
|
3319
|
+
if (theLimit.isInfinity()) {
|
|
3320
|
+
return theSign === 1 ? theLimit.abs() : theLimit.abs().opposed();
|
|
3321
|
+
}
|
|
3322
|
+
else {
|
|
3323
|
+
return theLimit;
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3284
3326
|
}
|
|
3285
3327
|
};
|
|
3286
3328
|
this._numerator = numerator ? numerator.clone() : new polynom_1.Polynom();
|
|
3287
3329
|
this._denominator = denominator ? denominator.clone() : new polynom_1.Polynom();
|
|
3288
3330
|
}
|
|
3331
|
+
get numerator() {
|
|
3332
|
+
return this._numerator;
|
|
3333
|
+
}
|
|
3334
|
+
get denominator() {
|
|
3335
|
+
return this._denominator;
|
|
3336
|
+
}
|
|
3289
3337
|
get tex() {
|
|
3290
3338
|
return `\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`;
|
|
3291
3339
|
}
|
|
@@ -3294,12 +3342,6 @@ class Rational {
|
|
|
3294
3342
|
this._denominator.factorize();
|
|
3295
3343
|
return `\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
|
|
3296
3344
|
}
|
|
3297
|
-
get numerator() {
|
|
3298
|
-
return this._numerator;
|
|
3299
|
-
}
|
|
3300
|
-
get denominator() {
|
|
3301
|
-
return this._denominator;
|
|
3302
|
-
}
|
|
3303
3345
|
}
|
|
3304
3346
|
exports.Rational = Rational;
|
|
3305
3347
|
|
|
@@ -3710,6 +3752,9 @@ class Fraction {
|
|
|
3710
3752
|
}
|
|
3711
3753
|
// Display getter
|
|
3712
3754
|
get tex() {
|
|
3755
|
+
if (this.isInfinity()) {
|
|
3756
|
+
return `${this.sign() === 1 ? '+' : '-'}\\infty`;
|
|
3757
|
+
}
|
|
3713
3758
|
if (this._denominator === 1) {
|
|
3714
3759
|
return `${this._numerator}`;
|
|
3715
3760
|
}
|
|
@@ -4696,6 +4741,14 @@ class Line {
|
|
|
4696
4741
|
return this.parseByPointAndVector(values[0], values[1]);
|
|
4697
4742
|
}
|
|
4698
4743
|
}
|
|
4744
|
+
else if (values[0] instanceof point_1.Point && values[1] instanceof Line) {
|
|
4745
|
+
if (values[2] === LinePropriety.Parallel || values[2] === null) {
|
|
4746
|
+
return this.parseByPointAndLine(values[0], values[1], LinePropriety.Parallel);
|
|
4747
|
+
}
|
|
4748
|
+
else {
|
|
4749
|
+
return this.parseByPointAndLine(values[0], values[1], LinePropriety.Perpendicular);
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4699
4752
|
}
|
|
4700
4753
|
// TODO: Add the ability to create line from a normal vector
|
|
4701
4754
|
console.log('Someting wrong happend while creating the line');
|