pimath 0.0.91 → 0.0.92

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 (42) hide show
  1. package/.eslintrc.js +23 -23
  2. package/dist/pi.js +359 -275
  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/main.js +52 -52
  7. package/docs/classes/Logicalset.Logicalset-1.html +4 -4
  8. package/docs/classes/Polynom.Rational.html +3 -3
  9. package/docs/classes/algebra_equation.Equation.html +25 -25
  10. package/docs/classes/algebra_monom.Monom.html +113 -113
  11. package/docs/classes/algebra_polynom.Polynom.html +29 -29
  12. package/docs/classes/coefficients_fraction.Fraction.html +18 -18
  13. package/docs/classes/coefficients_nthroot.NthRoot.html +2 -2
  14. package/docs/classes/geometry_circle.Circle.html +2 -2
  15. package/docs/classes/geometry_line.Line.html +2 -2
  16. package/docs/classes/geometry_triangle.Triangle.html +16 -16
  17. package/docs/classes/numeric.Numeric.html +13 -13
  18. package/docs/classes/shutingyard.Shutingyard.html +17 -17
  19. package/docs/index.html +10 -10
  20. package/docs/interfaces/algebra_equation.ISolution.html +2 -2
  21. package/esm/maths/algebra/monom.d.ts +8 -2
  22. package/esm/maths/algebra/monom.js +20 -0
  23. package/esm/maths/algebra/monom.js.map +1 -1
  24. package/esm/maths/algebra/polynom.d.ts +8 -4
  25. package/esm/maths/algebra/polynom.js +7 -0
  26. package/esm/maths/algebra/polynom.js.map +1 -1
  27. package/esm/maths/algebra/rational.d.ts +8 -4
  28. package/esm/maths/algebra/rational.js +3 -0
  29. package/esm/maths/algebra/rational.js.map +1 -1
  30. package/esm/maths/algebra/study/rationalStudy.d.ts +11 -1
  31. package/esm/maths/algebra/study/rationalStudy.js +62 -13
  32. package/esm/maths/algebra/study/rationalStudy.js.map +1 -1
  33. package/esm/maths/algebra/study.d.ts +13 -4
  34. package/esm/maths/algebra/study.js +10 -3
  35. package/esm/maths/algebra/study.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/maths/algebra/monom.ts +25 -0
  38. package/src/maths/algebra/polynom.ts +9 -0
  39. package/src/maths/algebra/rational.ts +4 -0
  40. package/src/maths/algebra/study/rationalStudy.ts +68 -9
  41. package/src/maths/algebra/study.ts +11 -2
  42. package/tests/algebra/study.test.ts +8 -10
@@ -825,6 +825,31 @@ export class Monom {
825
825
  return r;
826
826
  };
827
827
 
828
+ evaluateAsNumeric = (values: { [Key: string]: number } | number): number => {
829
+ let r = this.coefficient.value
830
+
831
+ if (typeof values === 'number') {
832
+ let tmpValues: { [Key: string]: number } = {}
833
+ tmpValues[this.variables[0]] = values
834
+ return this.evaluateAsNumeric(tmpValues);
835
+ }
836
+
837
+ if (typeof values === 'object') {
838
+ if (this.variables.length === 0) {
839
+ return this.coefficient.value
840
+ }
841
+ for (let L in this._literal) {
842
+ if (values[L] === undefined) {
843
+ return 0;
844
+ }
845
+
846
+ r *= values[L] ** (this._literal[L].value)
847
+ }
848
+ }
849
+
850
+ return r
851
+ }
852
+
828
853
  /**
829
854
  * Derivative the monom
830
855
  * @param letter
@@ -817,6 +817,15 @@ export class Polynom {
817
817
  return r;
818
818
  };
819
819
 
820
+ evaluateAsNumeric = (values: { [Key: string]: number } | number): number => {
821
+ let r = 0
822
+ this._monoms.forEach(monom => {
823
+ r += monom.evaluateAsNumeric(values)
824
+ })
825
+
826
+ return r
827
+ }
828
+
820
829
  derivative = (letter?: string): Polynom => {
821
830
  let dP = new Polynom();
822
831
 
@@ -217,6 +217,10 @@ export class Rational {
217
217
  return N.divide(D)
218
218
  };
219
219
 
220
+ evaluateAsNumeric = (values: { [Key: string]: number } | number): number => {
221
+ return this._numerator.evaluateAsNumeric(values) / this._denominator.evaluateAsNumeric(values)
222
+ }
223
+
220
224
  study = (): RationalStudy => {
221
225
  return new RationalStudy(this)
222
226
  }
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import {
17
17
  ASYMPTOTE,
18
+ ASYMPTOTE_POSITION,
18
19
  FUNCTION_EXTREMA,
19
20
  IAsymptote,
20
21
  ITableOfSigns,
@@ -40,8 +41,7 @@ export class RationalStudy extends Study {
40
41
  };
41
42
 
42
43
  makeSigns(): ITableOfSigns {
43
- let tos = this._getSigns(this.fx, this.zeroes)
44
- return tos
44
+ return this._getSigns(this.fx, this.zeroes)
45
45
  };
46
46
 
47
47
  makeAsymptotes(): IAsymptote[] {
@@ -51,9 +51,10 @@ export class RationalStudy extends Study {
51
51
  let asymptotes: IAsymptote[] = []
52
52
  this.zeroes.filter(x => x.type === ZEROTYPE.DEFENCE).forEach(zero => {
53
53
  // Check if it's a hole or an asymptote
54
- // TODO: Check for a hole ! Means calculate the limits !
55
54
  let Ztype = ASYMPTOTE.VERTICAL,
56
55
  tex = `x=${zero.tex}`
56
+
57
+ // Check if it's a hole: the reduced polynom should not be null
57
58
  if (zero.exact instanceof Fraction) {
58
59
  if (reduced.denominator.evaluate(zero.exact).isNotZero()) {
59
60
  Ztype = ASYMPTOTE.HOLE
@@ -66,14 +67,48 @@ export class RationalStudy extends Study {
66
67
  }
67
68
  }
68
69
 
70
+ // Get the position before and after the asymptote.
71
+ const delta = 0.000001
72
+ let before = this.fx.evaluateAsNumeric(zero.value - delta),
73
+ after = this.fx.evaluateAsNumeric(zero.value + delta),
74
+ position: ASYMPTOTE_POSITION[] = [],
75
+ pm = ""
76
+
77
+ if (after < -10000) {
78
+ position.push(ASYMPTOTE_POSITION.RB)
79
+ pm += "m"
80
+ } else if (after > 10000) {
81
+ position.push(ASYMPTOTE_POSITION.RT)
82
+ pm += "p"
83
+ }
84
+
85
+ if (before < -10000) {
86
+ position.push(ASYMPTOTE_POSITION.LB)
87
+ pm += "m"
88
+ } else if (before > 10000) {
89
+ position.push(ASYMPTOTE_POSITION.LT)
90
+ pm += "p"
91
+ }
92
+
93
+ // Left and right are to infinity
94
+ // TODO: handle the case were one side of the asymptote isn't infinity (not possible in rational study?!)
95
+ if (pm === "pp") {
96
+ pm = "+"
97
+ } else if (pm === "mm") {
98
+ pm = "-"
99
+ } else {
100
+ pm = `\\${pm}`
101
+ }
102
+
69
103
  asymptotes.push({
70
104
  fx: null,
71
105
  type: Ztype,
72
106
  tex: tex,
73
107
  zero: zero,
74
- limits: `\\lim_{x\\to${zero.tex} }\\ f(x) = \\pm\\infty`,
108
+ limits: `\\lim_{x\\to${zero.tex} }\\ f(x) = ${pm}\\infty`,
75
109
  deltaX: null,
76
- tableOfSign: null
110
+ tableOfSign: null,
111
+ position
77
112
  })
78
113
  })
79
114
 
@@ -87,7 +122,7 @@ export class RationalStudy extends Study {
87
122
  let {reminder} = reduced.euclidian(),
88
123
  deltaX = new Rational(reminder, reduced.denominator)
89
124
 
90
-
125
+ // Determine the position above or below on the left / right of the asymptote.
91
126
  asymptotes.push({
92
127
  fx: new Polynom(H),
93
128
  type: ASYMPTOTE.HORIZONTAL,
@@ -95,7 +130,8 @@ export class RationalStudy extends Study {
95
130
  zero: null,
96
131
  limits: `\\lim_{x\\to\\infty}\\ f(x) = ${Htex}`,
97
132
  deltaX,
98
- tableOfSign: this._getSigns(deltaX)
133
+ tableOfSign: this._getSigns(deltaX),
134
+ position: this._getHorizontalAsymptoteRelativePositon(deltaX)
99
135
  })
100
136
  } else if (DDegree.greater(NDegree)) {
101
137
  asymptotes.push({
@@ -105,7 +141,8 @@ export class RationalStudy extends Study {
105
141
  zero: null,
106
142
  limits: `\\lim_{x\\to\\infty}\\ f(x) = ${0}`,
107
143
  deltaX: null,
108
- tableOfSign: null
144
+ tableOfSign: null,
145
+ position: this._getHorizontalAsymptoteRelativePositon(this.fx)
109
146
  })
110
147
  } else if (NDegree.value - 1 === DDegree.value) {
111
148
  // Calculate the slope
@@ -119,13 +156,35 @@ export class RationalStudy extends Study {
119
156
  zero: null,
120
157
  limits: ``,
121
158
  deltaX: new Rational(reminder, reduced.denominator),
122
- tableOfSign: this._getSigns(deltaX)
159
+ tableOfSign: this._getSigns(deltaX),
160
+ position: this._getHorizontalAsymptoteRelativePositon(deltaX)
123
161
  })
124
162
  }
125
163
 
126
164
  return asymptotes
127
165
  };
128
166
 
167
+ _getHorizontalAsymptoteRelativePositon(deltaX: Rational, delta: number = 1000000): ASYMPTOTE_POSITION[] {
168
+
169
+ let position: ASYMPTOTE_POSITION[] = [],
170
+ before = deltaX.evaluateAsNumeric(-delta),
171
+ after = deltaX.evaluateAsNumeric(delta)
172
+
173
+ if (before >= 0) {
174
+ position.push(ASYMPTOTE_POSITION.LT)
175
+ } else {
176
+ position.push(ASYMPTOTE_POSITION.LB)
177
+ }
178
+
179
+ if (after >= 0) {
180
+ position.push(ASYMPTOTE_POSITION.RT)
181
+ } else {
182
+ position.push(ASYMPTOTE_POSITION.RB)
183
+ }
184
+
185
+ return position
186
+ }
187
+
129
188
  makeDerivative(): ITableOfSigns {
130
189
  let dx = this.fx.clone().derivative(),
131
190
  tos = this._getSigns(dx, this._getZeroes(dx), TABLE_OF_SIGNS.GROWS)
@@ -31,6 +31,12 @@ export enum ASYMPTOTE {
31
31
  HOLE = "hole"
32
32
  }
33
33
 
34
+ export enum ASYMPTOTE_POSITION {
35
+ "LT" = "LT",
36
+ "RT" = "RT",
37
+ "LB" = "LB",
38
+ "RB" = "RB"
39
+ }
34
40
  export interface IAsymptote {
35
41
  fx: Polynom,
36
42
  deltaX: StudyableFunction
@@ -38,7 +44,8 @@ export interface IAsymptote {
38
44
  tex: string,
39
45
  type: ASYMPTOTE,
40
46
  zero: IZero,
41
- tableOfSign: ITableOfSigns
47
+ position: ASYMPTOTE_POSITION[]
48
+ tableOfSign: ITableOfSigns,
42
49
  }
43
50
 
44
51
  export enum FUNCTION_EXTREMA {
@@ -74,7 +81,7 @@ export interface ITableOfSigns {
74
81
  export enum TABLE_OF_SIGNS {
75
82
  SIGNS = "signs",
76
83
  GROWS = "grows",
77
- VARIATIONS = "variatins"
84
+ VARIATIONS = "variations"
78
85
  }
79
86
 
80
87
  /**
@@ -150,7 +157,9 @@ export class Study {
150
157
  this._variations = this.makeVariation()
151
158
 
152
159
  this._signs.tex = this.texSigns
160
+
153
161
  this._derivative.tex = this.texGrows
162
+
154
163
  this._variations.tex = this.texVariations
155
164
 
156
165
  };
@@ -10,16 +10,6 @@ describe('Study tests', () => {
10
10
  // new Rational('x^2-4x-4', 'x+7')
11
11
  new Rational('(3x-2)(x-3)(x+4)', 'x^2-5x+6')
12
12
  )
13
-
14
- // console.log(study.texSigns)
15
- // console.log(study.asymptotes)
16
- // console.log(study.derivative.fx.texFactors)
17
- // console.log(study.texGrows)
18
- //
19
- //
20
- // console.log('----------------')
21
-
22
-
23
13
  let AO = study.asymptotes.filter(x => x.type === ASYMPTOTE.SLOPE)[0]
24
14
 
25
15
  console.log(AO.tableOfSign.signs)
@@ -40,4 +30,12 @@ describe('Study tests', () => {
40
30
  "Z_9(1.3333333333333333,0)*")
41
31
  });
42
32
 
33
+ it('should get the before/after state of asymptotes', function () {
34
+ const study = new RationalStudy(
35
+ new Rational("x+5", "x-3")
36
+ // new Rational("x^2+5", "(x-3)^2")
37
+ )
38
+
39
+ expect(study.asymptotes[0].position).to.have.all.members(["LB", "RT"])
40
+ });
43
41
  })