pimath 0.0.42 → 0.0.43

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.
Files changed (57) hide show
  1. package/.eslintrc.js +23 -23
  2. package/dist/pi.js +327 -579
  3. package/dist/pi.js.map +1 -1
  4. package/dist/pi.min.js +1 -1
  5. package/dist/pi.min.js.map +1 -1
  6. package/docs/assets/highlight.css +78 -78
  7. package/docs/assets/icons.css +1043 -1043
  8. package/docs/assets/main.js +52 -52
  9. package/docs/assets/search.js +1 -1
  10. package/docs/assets/style.css +1388 -1388
  11. package/docs/classes/{algebra.Equation.html → Algebra.Equation.html} +25 -25
  12. package/docs/classes/algebra.Logicalset.html +4 -4
  13. package/docs/classes/algebra.Monom.html +113 -113
  14. package/docs/classes/algebra.Polynom.html +29 -29
  15. package/docs/classes/algebra.Rational.html +3 -3
  16. package/docs/classes/coefficients.Fraction.html +18 -18
  17. package/docs/classes/coefficients.Nthroot.html +2 -2
  18. package/docs/classes/geometry.Circle.html +2 -2
  19. package/docs/classes/geometry.Line.html +2 -2
  20. package/docs/classes/geometry.Triangle.html +16 -16
  21. package/docs/classes/numeric.Numeric.html +13 -13
  22. package/docs/classes/shutingyard.Shutingyard.html +17 -17
  23. package/docs/index.html +10 -10
  24. package/docs/modules/{algebra.html → Algebra.html} +0 -0
  25. package/docs/modules/{random.html → Random.html} +0 -0
  26. package/esm/index.d.ts +2 -2
  27. package/esm/index.js +2 -2
  28. package/esm/maths/algebra/equation.d.ts +2 -7
  29. package/esm/maths/algebra/equation.js +9 -52
  30. package/esm/maths/algebra/equation.js.map +1 -1
  31. package/esm/maths/algebra/polynom.d.ts +1 -4
  32. package/esm/maths/algebra/polynom.js +62 -120
  33. package/esm/maths/algebra/polynom.js.map +1 -1
  34. package/esm/maths/algebra/rational.d.ts +6 -16
  35. package/esm/maths/algebra/rational.js +30 -141
  36. package/esm/maths/algebra/rational.js.map +1 -1
  37. package/esm/maths/coefficients/fraction.d.ts +1 -3
  38. package/esm/maths/coefficients/fraction.js +5 -37
  39. package/esm/maths/coefficients/fraction.js.map +1 -1
  40. package/esm/maths/coefficients/{nthRoot.d.ts → nthroot.d.ts} +5 -5
  41. package/esm/maths/coefficients/{nthRoot.js → nthroot.js} +5 -5
  42. package/esm/maths/coefficients/{nthRoot.js.map → nthroot.js.map} +1 -1
  43. package/esm/maths/geometry/line.js +0 -8
  44. package/esm/maths/geometry/line.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/index.ts +2 -2
  47. package/src/maths/algebra/equation.ts +12 -61
  48. package/src/maths/algebra/polynom.ts +68 -128
  49. package/src/maths/algebra/rational.ts +98 -242
  50. package/src/maths/coefficients/fraction.ts +6 -44
  51. package/src/maths/coefficients/{nthRoot.ts → nthroot.ts} +5 -5
  52. package/src/maths/geometry/line.ts +1 -0
  53. package/tests/algebra/monom.test.ts +4 -1
  54. package/tests/coefficients/fraction.test.ts +1 -43
  55. package/tests/geometry/circle.test.ts +2 -4
  56. package/tests/algebra/equation.test.ts +0 -38
  57. package/tests/algebra/rationnal.test.ts +0 -68
@@ -2,28 +2,22 @@ import {Polynom} from "./polynom";
2
2
  import {literalType, Monom} from "./monom";
3
3
  import {Numeric} from "../numeric";
4
4
  import {Fraction} from "../coefficients/fraction";
5
- import {NthRoot} from "../coefficients/nthRoot";
5
+ import {Nthroot} from "../coefficients/nthroot";
6
6
 
7
7
  /**
8
8
  * Equation is a class to manage equations...
9
9
  */
10
- export interface ISolution {
10
+ interface ISolution {
11
11
  tex: string,
12
12
  value: number,
13
13
  exact: unknown
14
14
  }
15
15
 
16
- export enum PARTICULAR_SOLUTION {
17
- real="\\mathbb{R}",
18
- varnothing="\\varnothing"
19
- }
20
-
21
16
  export class Equation {
22
17
  private _polynom: Polynom; // Used to solve the equation // TODO: remove the private value ?
23
-
24
18
  // Undetermined texSolutions.
25
- private _varnothing: string = PARTICULAR_SOLUTION.varnothing;
26
- private _real: string = PARTICULAR_SOLUTION.real;
19
+ private _varnothing: string = '\\varnothing';
20
+ private _real: string = '\\mathbb{R}';
27
21
 
28
22
  /**
29
23
  * Create an Equation using two polynoms.
@@ -165,9 +159,6 @@ export class Equation {
165
159
  return this.variables.length;
166
160
  }
167
161
 
168
- hasVariable = (letter: string): boolean => {
169
- return this.variables.includes(letter)
170
- }
171
162
 
172
163
  // ------------------------------------------
173
164
  // Creation / parsing functions
@@ -406,29 +397,9 @@ export class Equation {
406
397
  default:
407
398
  this._solveDegree3plus();
408
399
  }
409
-
410
- // cleanup the solutions.
411
- this._solutions = Equation.makeSolutionsUnique(this._solutions)
412
400
  return this;
413
401
  };
414
402
 
415
- static makeSolutionsUnique(solutions: ISolution[], sorted?: boolean):ISolution[] {
416
- let solutionAsTex:string[] = [],
417
- uniqueSolutions = solutions.filter(sol=>{
418
- if(!solutionAsTex.includes(sol.tex)){
419
- solutionAsTex.push(sol.tex)
420
- return true
421
- }else{
422
- return false
423
- }
424
- })
425
-
426
- if(sorted===true){
427
- uniqueSolutions.sort((a, b)=>a.value-b.value)
428
- }
429
- return uniqueSolutions
430
- }
431
-
432
403
  test = (values: literalType): Boolean => {
433
404
  return this.left.evaluate(values).isEqual(this.right.evaluate(values))
434
405
  }
@@ -555,13 +526,12 @@ export class Equation {
555
526
  }
556
527
  } else {
557
528
  this._solutions = [{
558
- tex: v.tex,
529
+ tex: v.display,
559
530
  value: v.value,
560
531
  exact: v
561
532
  }]
562
533
  }
563
- }
564
- else {
534
+ } else {
565
535
  if (m1.value === 0) {
566
536
  // In this case, the coefficient of the x variable is zero.
567
537
  if (m0.value === 0 && this.isAlsoEqual()) {
@@ -595,7 +565,7 @@ export class Equation {
595
565
  let aF = this._polynom.monomByDegree(2, letter).coefficient,
596
566
  bF = this._polynom.monomByDegree(1, letter).coefficient,
597
567
  cF = this._polynom.monomByDegree(0, letter).coefficient,
598
- delta: number, nthDelta: NthRoot,
568
+ delta: number, nthDelta: Nthroot,
599
569
  lcm = Numeric.lcm(aF.denominator, bF.denominator, cF.denominator),
600
570
  a = aF.multiply(lcm).value,
601
571
  b = bF.multiply(lcm).value,
@@ -624,7 +594,7 @@ export class Equation {
624
594
  }
625
595
  ]
626
596
  } else {
627
- nthDelta = new NthRoot(delta).reduce();
597
+ nthDelta = new Nthroot(delta).reduce();
628
598
  if (nthDelta.hasRadical()) {
629
599
  // -b +- coeff\sqrt{radical}
630
600
  // -------------------------
@@ -726,6 +696,7 @@ export class Equation {
726
696
  }];
727
697
  }
728
698
 
699
+
729
700
  // Handle now the inequations.
730
701
  if (!this.isStrictEqual()) {
731
702
  if (this._solutions.length === 2) {
@@ -792,29 +763,9 @@ export class Equation {
792
763
  return this._solutions;
793
764
  };
794
765
 
795
- private _solveDegree3plus = (letter?: string): ISolution[] => {
796
- // Push everything to the left
797
- // factorize
798
- // solve each factors.
799
- let equ = this.clone().moveLeft()
800
- equ.left.factorize()
801
-
802
- this._solutions = []
803
-
804
- equ.left.factors.forEach(factor=>{
805
- if(factor.degree(letter).leq(2)) {
806
- let factorAsEquation = new Equation(factor, 0)
807
- factorAsEquation.solve()
808
- factorAsEquation.solutions.forEach(solution => {
809
- this._solutions.push(solution)
810
- })
811
- }else{
812
- console.log(factor.tex, ': cannot actually get the solution of this equation')
813
- }
814
- })
815
-
816
- // TODO: check equation resolution for more than degree 2
817
- // this._solutions = [{tex: 'solve x - not yet handled', value: NaN, exact: false}]; // ESLint remove system :(
766
+ private _solveDegree3plus = (): ISolution[] => {
767
+ // TODO: try to resolve equations with a degree superior than 2.
768
+ this._solutions = [{tex: 'solve x - not yet handled', value: NaN, exact: false}]; // ESLint remove system :(
818
769
  return this._solutions;
819
770
  };
820
771
  }
@@ -6,7 +6,6 @@ import {literalType, Monom} from './monom';
6
6
  import {Shutingyard, ShutingyardType, Token} from '../shutingyard';
7
7
  import {Numeric} from '../numeric';
8
8
  import {Fraction} from "../coefficients/fraction";
9
- import {Equation, ISolution} from "./equation";
10
9
 
11
10
  export type PolynomParsingType = string | Polynom | number | Fraction | Monom
12
11
 
@@ -66,9 +65,6 @@ export class Polynom {
66
65
  get texFactors(): string {
67
66
  this.factorize()
68
67
 
69
- if(this.factors.length===0){
70
- return this.tex
71
- }
72
68
  let tex = ''
73
69
  for (let f of this.factors) {
74
70
  if (f.monoms.length > 1) {
@@ -777,7 +773,6 @@ export class Polynom {
777
773
  }
778
774
 
779
775
  let securityLoop = P.degree().clone().multiply(2).value
780
- let result
781
776
  // securityLoop = 0
782
777
 
783
778
  while (securityLoop >= 0) {
@@ -796,8 +791,8 @@ export class Polynom {
796
791
  for (let m1d of m1) {
797
792
  for (let m2d of m2) {
798
793
  // if(m1d.degree()===m2d.degree()){continue}
799
- let dividerPolynom = new Polynom()
800
-
794
+ let dividerPolynom = new Polynom(),
795
+ result
801
796
  dividerPolynom.monoms = [m1d.clone(), m2d.clone()]
802
797
  result = P.euclidian(dividerPolynom)
803
798
 
@@ -818,104 +813,77 @@ export class Polynom {
818
813
  }
819
814
  }
820
815
 
821
- if(!P.isOne()){factors.push(P.clone())}
822
-
823
816
  this.factors = factors
824
817
  return factors;
825
818
  }
826
819
 
827
820
  // TODO: get zeroes for more than first degree and for more than natural degrees
828
- getZeroes = (): ISolution[] => {
829
- let equ = new Equation(this.clone(), 0)
830
- equ.solve()
831
- return equ.solutions
832
-
833
- //
834
- // const Z: Fraction[] = [];
835
- //
836
- // // ISolution: {tex: string, value: number, exact: boolean|Fraction|...}
837
- //
838
- // switch (this.degree().value) {
839
- // case 0:
840
- // if (this._monoms[0].coefficient.value === 0) {
841
- // return [{
842
- // tex: '\\mathbb{R}',
843
- // value: NaN,
844
- // exact: false
845
- // }];
846
- // } else {
847
- // return [{
848
- // tex: '\\varnothing',
849
- // value: NaN,
850
- // exact: false
851
- // }];
852
- // }
853
- // case 1:
854
- // // There is only one monoms,
855
- // if (this._monoms.length === 1) {
856
- // return [{
857
- // tex: '0',
858
- // value: 0,
859
- // exact: new Fraction().zero()
860
- // }];
861
- // } else {
862
- // const P = this.clone().reduce().reorder();
863
- // const coeff = P.monoms[1].coefficient.opposed().divide(P.monoms[0].coefficient)
864
- // return [{
865
- // tex: coeff.tex,
866
- // value: coeff.value,
867
- // exact: coeff
868
- // }];
869
- // }
870
- // // TODO: Determine the zeros of an equation of second degree.
871
- // //case 2:
872
- // default:
873
- // // Make sure the polynom is factorized.
874
- // if (this._factors.length === 0) {
875
- // this.factorize()
876
- // }
877
- //
878
- // let zeroes:Fraction[] = [], zeroesAsTex = [];
879
- // for (let P of this._factors) {
880
- // if (P.degree().greater(2)) {
881
- // // TODO: get zeroes of polynom with a degree greater than 2.
882
- //
883
- // } else if (P.degree().value === 2) {
884
- // let A = P.monomByDegree(2).coefficient,
885
- // B = P.monomByDegree(1).coefficient,
886
- // C = P.monomByDegree(0).coefficient,
887
- // D = B.clone().pow(2).subtract(A.clone().multiply(C).multiply(4));
888
- //
889
- // if (D.value > 0) {
890
- // /*console.log('Two zeroes for ', P.tex); */
891
- // let x1 = (-(B.value) + Math.sqrt(D.value)) / (2 * A.value),
892
- // x2 = (-(B.value) - Math.sqrt(D.value)) / (2 * A.value);
893
- //
894
- // zeroes.push(new Fraction(x1.toFixed(3)).reduce());
895
- // zeroes.push(new Fraction(x2.toFixed(3)).reduce());
896
- // } else if (D.value === 0) {
897
- // /*console.log('One zero for ', P.tex); */
898
- // } else {
899
- // console.log('No zero for ', P.tex);
900
- // }
901
- // } else {
902
- // for (let z of P.getZeroes()) {
903
- // // Check if the zero is already in the list.
904
- // // if (z === false || z === true) {
905
- // // continue;
906
- // // }
907
- // if (zeroesAsTex.indexOf(z.frac) === -1) {
908
- // zeroes.push(z);
909
- // zeroesAsTex.push(z.frac);
910
- // }
911
- // }
912
- // }
913
- // }
914
- //
915
- //
916
- // return zeroes;
917
- // }
918
- // return Z;
821
+ getZeroes = (): (Fraction | boolean)[] => {
822
+ const Z: Fraction[] = [];
823
+
824
+ switch (this.degree().value) {
825
+ case 0:
826
+ if (this._monoms[0].coefficient.value === 0) {
827
+ return [true];
828
+ } else {
829
+ return [false];
830
+ }
831
+ case 1:
832
+ // There is only one monoms,
833
+ if (this._monoms.length === 1) {
834
+ return [new Fraction().zero()];
835
+ } else {
836
+ const P = this.clone().reduce().reorder();
837
+ return [P.monoms[1].coefficient.opposed().divide(P.monoms[0].coefficient)];
838
+ }
839
+ // TODO: Determine the zeros of an equation of second degree.
840
+ //case 2:
841
+ default:
842
+ // Make sure the polynom is factorized.
843
+ if (this._factors.length === 0) {
844
+ this.factorize()
845
+ }
846
+
847
+ let zeroes = [], zeroesAsTex = [];
848
+ for (let P of this._factors) {
849
+ if (P.degree().greater(2)) {
850
+ // TODO: Handle other polynom.
851
+
852
+ } else if (P.degree().value === 2) {
853
+ let A = P.monomByDegree(2).coefficient,
854
+ B = P.monomByDegree(1).coefficient,
855
+ C = P.monomByDegree(0).coefficient,
856
+ D = B.clone().pow(2).subtract(A.clone().multiply(C).multiply(4));
857
+
858
+ if (D.value > 0) {
859
+ /*console.log('Two zeroes for ', P.tex); */
860
+ let x1 = (-(B.value) + Math.sqrt(D.value)) / (2 * A.value),
861
+ x2 = (-(B.value) - Math.sqrt(D.value)) / (2 * A.value);
862
+
863
+ zeroes.push(new Fraction(x1.toFixed(3)).reduce());
864
+ zeroes.push(new Fraction(x2.toFixed(3)).reduce());
865
+ } else if (D.value === 0) {
866
+ /*console.log('One zero for ', P.tex); */
867
+
868
+ } else {
869
+ console.log('No zero for ', P.tex);
870
+ }
871
+ } else {
872
+ for (let z of P.getZeroes()) {
873
+ // Check if the zero is already in the list.
874
+ if (z === false || z === true) {
875
+ continue;
876
+ }
877
+ if (zeroesAsTex.indexOf(z.frac) === -1) {
878
+ zeroes.push(z);
879
+ zeroesAsTex.push(z.frac);
880
+ }
881
+ }
882
+ }
883
+ }
884
+ return zeroes;
885
+ }
886
+ return Z;
919
887
  };
920
888
 
921
889
  // TODO: analyse the next functions to determine if they are useful or not...
@@ -1027,34 +995,6 @@ export class Polynom {
1027
995
  return M;
1028
996
  }
1029
997
 
1030
- limitToInfinity = (letter?: string): Fraction => {
1031
- const M = this.monomByDegree(undefined, letter),
1032
- sign = M.coefficient.sign(),
1033
- degree = M.degree(letter)
1034
-
1035
- if (degree.isStrictlyPositive()) {
1036
- return sign === 1 ? (new Fraction()).infinite() : (new Fraction()).infinite().opposed()
1037
- } else if (degree.isZero()) {
1038
- return M.coefficient
1039
- }
1040
-
1041
- // Any other cases
1042
- return (new Fraction()).zero()
1043
- }
1044
- limitToNegativeInfinity = (letter?: string): Fraction => {
1045
- const M = this.monomByDegree(undefined, letter),
1046
- sign = M.coefficient.sign(),
1047
- degree = M.degree(letter)
1048
-
1049
- if (degree.isStrictlyPositive()) {
1050
- return sign === -1 ? (new Fraction()).infinite() : (new Fraction()).infinite().opposed()
1051
- } else if (degree.isZero()) {
1052
- return M.coefficient
1053
- }
1054
-
1055
- // Any other cases
1056
- return (new Fraction()).zero()
1057
- }
1058
998
  private _parseString(inputStr: string, ...values: unknown[]): Polynom {
1059
999
  if (values === undefined || values.length === 0) {
1060
1000
  inputStr = '' + inputStr;