pimath 0.0.73 → 0.0.76

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 (56) hide show
  1. package/dist/pi.js +112 -73
  2. package/dist/pi.js.map +1 -1
  3. package/dist/pi.min.js +1 -1
  4. package/dist/pi.min.js.map +1 -1
  5. package/docs/assets/highlight.css +78 -78
  6. package/docs/assets/main.js +52 -52
  7. package/docs/assets/search.js +1 -1
  8. package/docs/assets/style.css +1413 -1413
  9. package/docs/classes/Logicalset.Logicalset-1.html +5 -5
  10. package/docs/classes/Polynom.Rational.html +4 -4
  11. package/docs/classes/Vector.Point.html +1 -1
  12. package/docs/classes/Vector.Vector-1.html +1 -1
  13. package/docs/classes/algebra_equation.Equation.html +26 -26
  14. package/docs/classes/algebra_linearSystem.LinearSystem.html +1 -1
  15. package/docs/classes/algebra_monom.Monom.html +114 -114
  16. package/docs/classes/algebra_polynom.Polynom.html +30 -30
  17. package/docs/classes/coefficients_fraction.Fraction.html +19 -19
  18. package/docs/classes/coefficients_nthroot.NthRoot.html +3 -3
  19. package/docs/classes/expressions_numexp.NumExp.html +1 -1
  20. package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +1 -1
  21. package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +1 -1
  22. package/docs/classes/geometry_circle.Circle.html +3 -3
  23. package/docs/classes/geometry_line.Line.html +3 -3
  24. package/docs/classes/geometry_triangle.Triangle.html +16 -16
  25. package/docs/classes/numeric.Numeric.html +14 -14
  26. package/docs/classes/shutingyard.Shutingyard.html +18 -18
  27. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +1 -1
  28. package/docs/enums/geometry_line.LinePropriety.html +1 -1
  29. package/docs/enums/shutingyard.ShutingyardMode.html +1 -1
  30. package/docs/enums/shutingyard.ShutingyardType.html +1 -1
  31. package/docs/index.html +10 -10
  32. package/docs/interfaces/algebra_equation.ISolution.html +3 -3
  33. package/docs/interfaces/algebra_polynom.IEuclidian.html +1 -0
  34. package/docs/interfaces/geometry_triangle.remarquableLines.html +1 -1
  35. package/docs/modules/Logicalset.html +2 -2
  36. package/docs/modules/Polynom.html +2 -2
  37. package/docs/modules/Vector.html +2 -2
  38. package/docs/modules/algebra_monom.html +1 -1
  39. package/docs/modules/algebra_polynom.html +1 -1
  40. package/docs/modules/coefficients_fraction.html +1 -1
  41. package/docs/modules/shutingyard.html +1 -1
  42. package/esm/maths/algebra/polynom.js +94 -73
  43. package/esm/maths/algebra/polynom.js.map +1 -1
  44. package/esm/maths/algebra/rational.d.ts +1 -0
  45. package/esm/maths/algebra/rational.js +5 -0
  46. package/esm/maths/algebra/rational.js.map +1 -1
  47. package/esm/maths/expressions/numexp.js +10 -0
  48. package/esm/maths/expressions/numexp.js.map +1 -1
  49. package/esm/maths/shutingyard.js +3 -0
  50. package/esm/maths/shutingyard.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/maths/algebra/polynom.ts +107 -78
  53. package/src/maths/algebra/rational.ts +6 -0
  54. package/src/maths/expressions/numexp.ts +7 -0
  55. package/src/maths/shutingyard.ts +3 -0
  56. package/tests/algebra/polynom.test.ts +12 -2
@@ -101,17 +101,39 @@ export class Polynom {
101
101
  get texFactors(): string {
102
102
  this.factorize()
103
103
 
104
- if (this.factors.length === 0) {
104
+ if (this.factors.length <= 1) {
105
105
  return this.tex
106
106
  }
107
- let tex = ''
107
+
108
+ // Build an array of texFactors with the number of similar items.
109
+ let factorsCount: { [Key: string]: { degree: number, factor: Polynom } } = {}
108
110
  for (let f of this.factors) {
109
- if (f.monoms.length > 1) {
110
- tex += `(${f.tex})`
111
+ if (factorsCount[f.tex] !== undefined) {
112
+ factorsCount[f.tex].degree++
111
113
  } else {
112
- tex = f.tex + tex;
114
+ factorsCount[f.tex] = {
115
+ degree: 1,
116
+ factor: f
117
+ }
118
+ }
119
+ }
120
+
121
+ // First round to put the 'monom' first
122
+ let simpleFactor = new Polynom().one()
123
+
124
+ for (let item of Object.values(factorsCount).filter(item => item.factor.monoms.length === 1)) {
125
+ simpleFactor.multiply(item.factor)
126
+ }
127
+
128
+ let tex = simpleFactor.isOne() ? '' : simpleFactor.tex
129
+
130
+ // Loop through all factors that contains at least 2 monoms.
131
+ for (let item of Object.values(factorsCount).filter(item => item.factor.monoms.length > 1)) {
132
+ if (item.factor.length > 1) {
133
+ tex += `\\left( ${item.factor.tex} \\right)${item.degree > 1 ? '^{ ' + item.degree + ' }' : ''}`
113
134
  }
114
135
  }
136
+
115
137
  return tex;
116
138
  }
117
139
 
@@ -780,96 +802,103 @@ export class Polynom {
780
802
  * @param maxValue Defines the greatest value to search to (default is 20).
781
803
  */
782
804
  factorize = (letter?: string): Polynom[] => {
783
- if (this.dirty_factors) {
784
- let factors: Polynom[] = [];
785
-
786
- let P = this.clone().reorder()
787
-
788
- // Extract the common monom
789
- // 2x^3+6x^2 => 2x^2
790
- let M = P.commonMonom()
791
- if (!M.isOne()) {
792
- let tempPolynom: Polynom = new Polynom(M)
793
- factors = [tempPolynom.clone()]
794
- P = P.euclidian(tempPolynom).quotient;
795
- }
805
+ if (!this.dirty_factors) {
806
+ return this._factors
807
+ }
796
808
 
797
- // Main loop
798
- let securityLoop = P.degree().clone().multiply(2).value,
799
- maxDegree = 1
800
- while (securityLoop >= 0) {
801
- securityLoop--
802
- if (P.monoms.length < 2) {
803
- // The polynom has only one monom => 7x^2
804
- // No need to continue.
805
- if (!P.isOne()) {
806
- factors.push(P.clone())
807
- P.one()
808
- }
809
- break
810
- } else if (P.degree(letter).isOne()) {
811
- // The polynom is a first degree polynom => 3x-5
812
- // No need to continue
809
+
810
+ let factors: Polynom[] = [];
811
+ let P = this.clone().reorder()
812
+
813
+ // Extract the common monom
814
+ // 2x^3+6x^2 => 2x^2
815
+ let M = P.commonMonom()
816
+ // If the polynom starts with a negative monom, factorize it.
817
+ if(P.monomByDegree().coefficient.isStrictlyNegative() && M.coefficient.isStrictlyPositive()){
818
+ M.opposed()
819
+ }
820
+
821
+ if (!M.isOne()) {
822
+ let tempPolynom: Polynom = new Polynom(M)
823
+ factors = [tempPolynom.clone()]
824
+ P = P.euclidian(tempPolynom).quotient;
825
+ }
826
+
827
+ // Main loop
828
+ let securityLoop = P.degree().clone().multiply(2).value,
829
+ maxDegree = 1
830
+ while (securityLoop >= 0) {
831
+ securityLoop--
832
+ if (P.monoms.length < 2) {
833
+ // The polynom has only one monom => 7x^2
834
+ // No need to continue.
835
+ if (!P.isOne()) {
813
836
  factors.push(P.clone())
814
837
  P.one()
815
- break
816
- } else {
817
- // Create the list of all "potential" polynom dividers.
818
- let allDividers: Polynom[] = this._getAllPotentialFactors(P, maxDegree, letter)
819
- maxDegree = P.degree(letter).value
838
+ }
839
+ break
840
+ } else if (P.degree(letter).isOne()) {
841
+ // The polynom is a first degree polynom => 3x-5
842
+ // No need to continue
843
+ factors.push(P.clone())
844
+ P.one()
845
+ break
846
+ } else {
847
+ // Create the list of all "potential" polynom dividers.
848
+ let allDividers: Polynom[] = this._getAllPotentialFactors(P, maxDegree, letter)
849
+ maxDegree = P.degree(letter).value
820
850
 
821
- // Actually: 100ms
822
- while (allDividers.length > 0) {
823
- let div = allDividers[0]
851
+ // Actually: 100ms
852
+ while (allDividers.length > 0) {
853
+ let div = allDividers[0]
824
854
 
825
- if (!P.isDividableBy(div)) {
826
- // Not dividable. Remove it from the list
827
- allDividers.shift()
828
- } else {
829
- // It's dividable - so make the division
830
- let result = P.euclidian(div)
855
+ if (!P.isDividableBy(div)) {
856
+ // Not dividable. Remove it from the list
857
+ allDividers.shift()
858
+ } else {
859
+ // It's dividable - so make the division
860
+ let result = P.euclidian(div)
831
861
 
832
- // Add the factor
833
- factors.push(div)
862
+ // Add the factor
863
+ factors.push(div)
834
864
 
835
- // As it's dividable, get the quotient.
836
- P = result.quotient.clone()
865
+ // As it's dividable, get the quotient.
866
+ P = result.quotient.clone()
837
867
 
838
- // filter all dividers that are no more suitable.
839
- allDividers = allDividers.filter(x => {
840
- let pX = P.monoms[0],
841
- pC = P.monoms[P.monoms.length - 1],
842
- dX = x.monoms[0],
843
- dC = x.monoms[x.monoms.length - 1]
868
+ // filter all dividers that are no more suitable.
869
+ allDividers = allDividers.filter(x => {
870
+ let pX = P.monoms[0],
871
+ pC = P.monoms[P.monoms.length - 1],
872
+ dX = x.monoms[0],
873
+ dC = x.monoms[x.monoms.length - 1]
844
874
 
845
- // Check last item (degree zero)
846
- if (!pC.isDivisible(dC)) {
847
- return false
848
- }
875
+ // Check last item (degree zero)
876
+ if (!pC.isDivisible(dC)) {
877
+ return false
878
+ }
849
879
 
850
- // Check the first item (degree max)
851
- if (!pX.isDivisible(dX)) {
852
- return false
853
- }
880
+ // Check the first item (degree max)
881
+ if (!pX.isDivisible(dX)) {
882
+ return false
883
+ }
854
884
 
855
- return true
856
- })
857
- }
885
+ return true
886
+ })
858
887
  }
859
888
  }
860
889
  }
890
+ }
861
891
 
862
- // Maybe there is still something in the Polynom (not everything was possible to factorize)
863
- if (!P.isOne()) {
864
- factors.push(P.clone())
865
- }
892
+ // Maybe there is still something in the Polynom (not everything was possible to factorize)
893
+ if (!P.isOne()) {
894
+ factors.push(P.clone())
895
+ }
866
896
 
867
- // Save the factors
868
- this._factors = factors
897
+ // Save the factors
898
+ this._factors = factors
869
899
 
870
- // The factors list is no more dirty
871
- this.dirty_factors = false
872
- }
900
+ // The factors list is no more dirty
901
+ this.dirty_factors = false
873
902
 
874
903
  return this._factors;
875
904
  }
@@ -100,6 +100,12 @@ export class Rational {
100
100
  return this
101
101
  }
102
102
 
103
+ factorize = (letter?: string): Rational => {
104
+ this._numerator.factorize(letter)
105
+ this._denominator.factorize(letter)
106
+ return this
107
+ }
108
+
103
109
  simplify = (P: Polynom): Rational => {
104
110
  let NumeratorEuclidien = this._numerator.euclidian(P);
105
111
  if (!NumeratorEuclidien.reminder.isZero()) {
@@ -145,6 +145,13 @@ export class NumExp {
145
145
  this._addToStack(stack, Math.tan(a))
146
146
  } else if(element.token === 'sqrt') {
147
147
  this._addToStack(stack, Math.sqrt(a))
148
+ }else if(element.token ==='nthrt') {
149
+ // TODO: support nthrt in num. exp.
150
+ // this._addToStack(stack, Math.pow(a, 1/b))
151
+ } else if(element.token === 'ln'){
152
+ this._addToStack(stack, Math.log(a))
153
+ } else if(element.token === 'log') {
154
+ this._addToStack(stack, Math.log10(a))
148
155
  }
149
156
  }
150
157
  }
@@ -90,6 +90,9 @@ export class Shutingyard {
90
90
  'cos': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
91
91
  'tan': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
92
92
  'sqrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
93
+ 'nthrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
94
+ 'ln': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
95
+ 'log': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
93
96
  }
94
97
  this._uniformize = false
95
98
  } else if (this._mode === ShutingyardMode.EXPRESSION) {
@@ -5,6 +5,7 @@ import {Polynom} from "../../src/maths/algebra/polynom";
5
5
  import {Fraction} from "../../src/maths/coefficients/fraction";
6
6
  import exp = require("constants");
7
7
 
8
+
8
9
  describe('Polynom tests', () => {
9
10
  it('Parse polynom', () => {
10
11
  const options = new Polynom('2x(x+3)^2(x-1)');
@@ -86,14 +87,23 @@ describe('Polynom tests', () => {
86
87
  let P = new Polynom('x^6-16x^5-58x^4+1592x^3-1207x^2-37576x+94864')
87
88
 
88
89
  P.factorize()
89
- expect(P.factors.map(x=>x.tex)).to.have.all.members([ 'x-4', 'x-4', 'x+7', 'x+7', 'x-11', 'x-11' ])
90
+ expect(P.factors.map(x => x.tex)).to.have.all.members(['x-4', 'x-4', 'x+7', 'x+7', 'x-11', 'x-11'])
91
+ });
92
+
93
+ it('should factorize and regroup', function () {
94
+ let P = new Polynom('7x(x-3)(x+5)(x^2-9)3x')
95
+ P.factorize()
96
+ expect(P.texFactors).to.be.equal('21x^{2}\\left( x+3 \\right)\\left( x-3 \\right)^{ 2 }\\left( x+5 \\right)')
97
+
98
+ const P2 = new Polynom('-2x^3+18x')
99
+ P2.factorize()
100
+ expect(P2.texFactors).to.be.equal('-2x\\left( x+3 \\right)\\left( x-3 \\right)')
90
101
  });
91
102
  })
92
103
 
93
104
  describe('Polynom parsing with rational power', () => {
94
105
  it('should parse with rational powers', () => {
95
106
  const P = new Polynom('3x^(2/3)-5x+5/3');
96
-
97
107
  expect(P.tex).to.be.equal('3x^{\\tfrac{ 2 }{ 3 }}-5x+\\frac{ 5 }{ 3 }')
98
108
  })
99
109
  })