pimath 0.0.120 → 0.0.122

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 (175) hide show
  1. package/.idea/PI.iml +7 -1
  2. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +90 -0
  3. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]1/shelved.patch +107 -0
  4. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +4 -0
  5. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_1.xml +4 -0
  6. package/LICENSE.md +1 -1
  7. package/dev/pimath.js +7929 -0
  8. package/dev/pimath.js.map +1 -0
  9. package/dist/{pi.js → pimath.js} +7613 -7840
  10. package/dist/pimath.js.map +1 -0
  11. package/dist/pimath.min.js +2 -0
  12. package/dist/pimath.min.js.map +1 -0
  13. package/docs/assets/main.js +58 -58
  14. package/docs/assets/search.js +1 -1
  15. package/docs/assets/style.css +1367 -1280
  16. package/docs/classes/Logicalset.Logicalset.html +221 -212
  17. package/docs/classes/Polynom.Rational.html +391 -388
  18. package/docs/classes/Vector-1.Vector.html +494 -448
  19. package/docs/classes/Vector.Point.html +341 -342
  20. package/docs/classes/algebra_equation.Equation.html +796 -753
  21. package/docs/classes/algebra_linearSystem.LinearSystem.html +408 -397
  22. package/docs/classes/algebra_monom.Monom.html +967 -910
  23. package/docs/classes/algebra_polynom.Polynom.html +1281 -1260
  24. package/docs/classes/coefficients_fraction.Fraction.html +939 -931
  25. package/docs/classes/geometry_circle.Circle.html +476 -476
  26. package/docs/classes/geometry_line.Line.html +779 -719
  27. package/docs/classes/geometry_triangle.Triangle.html +429 -420
  28. package/docs/classes/numeric.Numeric.html +269 -263
  29. package/docs/classes/shutingyard.Shutingyard.html +259 -248
  30. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +89 -88
  31. package/docs/enums/geometry_line.LinePropriety.html +102 -102
  32. package/docs/enums/shutingyard.ShutingyardMode.html +106 -102
  33. package/docs/enums/shutingyard.ShutingyardType.html +120 -116
  34. package/docs/index.html +63 -65
  35. package/docs/interfaces/algebra_equation.ISolution.html +111 -109
  36. package/docs/interfaces/algebra_polynom.IEuclidian.html +93 -92
  37. package/docs/interfaces/geometry_triangle.remarquableLines.html +150 -150
  38. package/docs/modules/Logicalset.html +69 -74
  39. package/docs/modules/Polynom.html +69 -74
  40. package/docs/modules/Vector-1.html +69 -74
  41. package/docs/modules/Vector.html +69 -74
  42. package/docs/modules/algebra_equation.html +75 -81
  43. package/docs/modules/algebra_linearSystem.html +65 -71
  44. package/docs/modules/algebra_monom.html +70 -76
  45. package/docs/modules/algebra_polynom.html +75 -81
  46. package/docs/modules/coefficients_fraction.html +70 -76
  47. package/docs/modules/geometry_circle.html +65 -71
  48. package/docs/modules/geometry_line.html +70 -76
  49. package/docs/modules/geometry_triangle.html +70 -76
  50. package/docs/modules/numeric.html +65 -71
  51. package/docs/modules/shutingyard.html +84 -90
  52. package/docs/types/algebra_monom.literalType.html +66 -70
  53. package/docs/types/algebra_polynom.PolynomParsingType.html +62 -66
  54. package/docs/types/coefficients_fraction.FractionParsingType.html +61 -65
  55. package/docs/types/shutingyard.Token.html +72 -76
  56. package/docs/types/shutingyard.tokenType.html +77 -81
  57. package/docs/variables/shutingyard.tokenConstant.html +70 -74
  58. package/esm/index.d.ts +38 -41
  59. package/esm/index.js +43 -46
  60. package/esm/index.js.map +1 -1
  61. package/esm/maths/algebra/equation.d.ts +119 -117
  62. package/esm/maths/algebra/equation.js +796 -785
  63. package/esm/maths/algebra/equation.js.map +1 -1
  64. package/esm/maths/algebra/linearSystem.d.ts +39 -38
  65. package/esm/maths/algebra/linearSystem.js +278 -262
  66. package/esm/maths/algebra/linearSystem.js.map +1 -1
  67. package/esm/maths/algebra/logicalset.d.ts +28 -28
  68. package/esm/maths/algebra/logicalset.js +157 -157
  69. package/esm/maths/algebra/monom.d.ts +206 -206
  70. package/esm/maths/algebra/monom.js +908 -908
  71. package/esm/maths/algebra/monom.js.map +1 -1
  72. package/esm/maths/algebra/polynom.d.ts +157 -157
  73. package/esm/maths/algebra/polynom.js +1277 -1277
  74. package/esm/maths/algebra/rational.d.ts +45 -45
  75. package/esm/maths/algebra/rational.js +183 -183
  76. package/esm/maths/algebra/study/rationalStudy.d.ts +28 -28
  77. package/esm/maths/algebra/study/rationalStudy.js +243 -243
  78. package/esm/maths/algebra/study.d.ts +143 -142
  79. package/esm/maths/algebra/study.js +378 -377
  80. package/esm/maths/algebra/study.js.map +1 -1
  81. package/esm/maths/coefficients/fraction.d.ts +90 -90
  82. package/esm/maths/coefficients/fraction.js +516 -516
  83. package/esm/maths/coefficients/fraction.js.map +1 -1
  84. package/esm/maths/coefficients/nthRoot.d.ts +23 -23
  85. package/esm/maths/coefficients/nthRoot.js +136 -136
  86. package/esm/maths/geometry/circle.d.ts +45 -45
  87. package/esm/maths/geometry/circle.js +323 -323
  88. package/esm/maths/geometry/line.d.ts +99 -99
  89. package/esm/maths/geometry/line.js +481 -481
  90. package/esm/maths/geometry/line.js.map +1 -1
  91. package/esm/maths/geometry/point.d.ts +34 -34
  92. package/esm/maths/geometry/point.js +166 -166
  93. package/esm/maths/geometry/point.js.map +1 -1
  94. package/esm/maths/geometry/triangle.d.ts +85 -85
  95. package/esm/maths/geometry/triangle.js +268 -268
  96. package/esm/maths/geometry/vector.d.ts +41 -41
  97. package/esm/maths/geometry/vector.js +197 -197
  98. package/esm/maths/geometry/vector.js.map +1 -1
  99. package/esm/maths/numeric.d.ts +28 -28
  100. package/esm/maths/numeric.js +180 -180
  101. package/esm/maths/numexp.d.ts +19 -0
  102. package/esm/maths/numexp.js +186 -0
  103. package/esm/maths/numexp.js.map +1 -0
  104. package/esm/maths/randomization/random.d.ts +23 -23
  105. package/esm/maths/randomization/random.js +78 -78
  106. package/esm/maths/randomization/random.js.map +1 -1
  107. package/esm/maths/randomization/randomCore.d.ts +7 -7
  108. package/esm/maths/randomization/randomCore.js +21 -21
  109. package/esm/maths/randomization/rndFraction.d.ts +12 -12
  110. package/esm/maths/randomization/rndFraction.js +43 -43
  111. package/esm/maths/randomization/rndGeometryLine.d.ts +12 -12
  112. package/esm/maths/randomization/rndGeometryLine.js +45 -45
  113. package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -12
  114. package/esm/maths/randomization/rndGeometryPoint.js +60 -60
  115. package/esm/maths/randomization/rndHelpers.d.ts +23 -23
  116. package/esm/maths/randomization/rndHelpers.js +76 -76
  117. package/esm/maths/randomization/rndMonom.d.ts +12 -12
  118. package/esm/maths/randomization/rndMonom.js +52 -52
  119. package/esm/maths/randomization/rndPolynom.d.ts +13 -13
  120. package/esm/maths/randomization/rndPolynom.js +74 -74
  121. package/esm/maths/randomization/rndTypes.d.ts +34 -34
  122. package/esm/maths/randomization/rndTypes.js +2 -2
  123. package/esm/maths/shutingyard.d.ts +59 -59
  124. package/esm/maths/shutingyard.js +442 -442
  125. package/esm/maths/shutingyard.js.map +1 -1
  126. package/package.json +11 -11
  127. package/public/index.html +50 -81
  128. package/public/playground.html +7 -8
  129. package/src/index.ts +1 -4
  130. package/src/maths/algebra/equation.ts +16 -0
  131. package/src/maths/algebra/linearSystem.ts +20 -0
  132. package/src/maths/algebra/study.ts +12 -10
  133. package/src/maths/{expressions/numexp.ts → numexp.ts} +2 -2
  134. package/tests/algebra/equation.test.ts +19 -5
  135. package/tests/algebra/linear.test.ts +3 -11
  136. package/tests/algebra/polynom.test.ts +7 -8
  137. package/tests/algebra/rationnal.test.ts +1 -1
  138. package/tests/algebra/study.test.ts +2 -9
  139. package/tests/coefficients/fraction.test.ts +8 -8
  140. package/tests/custom.test.ts +33 -37
  141. package/tests/numeric.test.ts +1 -2
  142. package/tests/numexp.test.ts +13 -5
  143. package/tests/shutingyard.test.ts +3 -3
  144. package/webpack-production-min.config.js +1 -1
  145. package/webpack-production.config.js +1 -1
  146. package/webpack.config.js +1 -1
  147. package/dist/pi.js.map +0 -1
  148. package/dist/pi.min.js +0 -2
  149. package/dist/pi.min.js.map +0 -1
  150. package/docs/classes/expressions_numexp.NumExp.html +0 -236
  151. package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +0 -317
  152. package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +0 -285
  153. package/docs/modules/expressions_numexp.html +0 -71
  154. package/docs/modules/expressions_polynomexp.html +0 -73
  155. package/docs/modules.html +0 -76
  156. package/graph.svg +0 -1033
  157. package/src/maths/expressions/ExpressionTree.ts +0 -172
  158. package/src/maths/expressions/expression.ts +0 -286
  159. package/src/maths/expressions/expressionFactor.ts +0 -190
  160. package/src/maths/expressions/expressionMember.ts +0 -233
  161. package/src/maths/expressions/expressionOperators.ts +0 -49
  162. package/src/maths/expressions/expressionParser.ts +0 -295
  163. package/src/maths/expressions/factors/ExpFactor.ts +0 -39
  164. package/src/maths/expressions/factors/ExpFactorConstant.ts +0 -60
  165. package/src/maths/expressions/factors/ExpFactorExponential.ts +0 -26
  166. package/src/maths/expressions/factors/ExpFactorNumber.ts +0 -72
  167. package/src/maths/expressions/factors/ExpFactorPower.ts +0 -42
  168. package/src/maths/expressions/factors/ExpFactorTrigo.ts +0 -53
  169. package/src/maths/expressions/factors/ExpFactorVariable.ts +0 -45
  170. package/src/maths/expressions/internals.ts +0 -14
  171. package/src/maths/expressions/polynomexp.bkp.ts +0 -221
  172. package/src/maths/expressions/polynomexp.ts +0 -310
  173. package/tests/expressions/expressions.test.ts +0 -145
  174. package/tests/expressions/expressiontree.test.ts +0 -11
  175. package/tests/polynomexp.test.ts +0 -12
@@ -1,379 +1,380 @@
1
- "use strict";
2
- /**
3
- * Rational polynom module contains everything necessary to handle rational polynoms.
4
- * @module Polynom
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Study = exports.TABLE_OF_SIGNS = exports.FUNCTION_EXTREMA = exports.ASYMPTOTE_POSITION = exports.ASYMPTOTE = exports.ZEROTYPE = void 0;
8
- const fraction_1 = require("../coefficients/fraction");
9
- const numexp_1 = require("../expressions/numexp");
10
- var ZEROTYPE;
11
- (function (ZEROTYPE) {
12
- ZEROTYPE["ZERO"] = "z";
13
- ZEROTYPE["DEFENCE"] = "d";
14
- ZEROTYPE["NOTHING"] = "t";
15
- })(ZEROTYPE = exports.ZEROTYPE || (exports.ZEROTYPE = {}));
16
- var ASYMPTOTE;
17
- (function (ASYMPTOTE) {
18
- ASYMPTOTE["VERTICAL"] = "av";
19
- ASYMPTOTE["HORIZONTAL"] = "ah";
20
- ASYMPTOTE["SLOPE"] = "ao";
21
- ASYMPTOTE["HOLE"] = "hole";
22
- })(ASYMPTOTE = exports.ASYMPTOTE || (exports.ASYMPTOTE = {}));
23
- var ASYMPTOTE_POSITION;
24
- (function (ASYMPTOTE_POSITION) {
25
- ASYMPTOTE_POSITION["LT"] = "LT";
26
- ASYMPTOTE_POSITION["RT"] = "RT";
27
- ASYMPTOTE_POSITION["LB"] = "LB";
28
- ASYMPTOTE_POSITION["RB"] = "RB";
29
- })(ASYMPTOTE_POSITION = exports.ASYMPTOTE_POSITION || (exports.ASYMPTOTE_POSITION = {}));
30
- var FUNCTION_EXTREMA;
31
- (function (FUNCTION_EXTREMA) {
32
- FUNCTION_EXTREMA["MIN"] = "min";
33
- FUNCTION_EXTREMA["MAX"] = "max";
34
- FUNCTION_EXTREMA["FLAT"] = "flat";
35
- FUNCTION_EXTREMA["NOTHING"] = "";
36
- })(FUNCTION_EXTREMA = exports.FUNCTION_EXTREMA || (exports.FUNCTION_EXTREMA = {}));
37
- var TABLE_OF_SIGNS;
38
- (function (TABLE_OF_SIGNS) {
39
- TABLE_OF_SIGNS["SIGNS"] = "signs";
40
- TABLE_OF_SIGNS["GROWS"] = "grows";
41
- TABLE_OF_SIGNS["VARIATIONS"] = "variatins";
42
- })(TABLE_OF_SIGNS = exports.TABLE_OF_SIGNS || (exports.TABLE_OF_SIGNS = {}));
43
- /**
44
- * The study class is a "function study" class that will get:
45
- * fx : get the function
46
- * domain : string
47
- * zeroes : Object (tex, IZero)
48
- * signs : table of signs + tex output using tkz-tab
49
- * av : vertical asymptotic
50
- * ah : horizontal asymptotic
51
- * ao : obliques
52
- * deltaX : position relative
53
- * dx : derivative
54
- * grows : growing table + tex output using tkz-tab
55
- * ddx : dérivée seconde
56
- * variations : variation table + tex output using tkz-tab
57
- */
58
- class Study {
59
- constructor(fx, config) {
60
- this.makeStudy = () => {
61
- this._zeroes = this.makeZeroes();
62
- if (this._config.signs)
63
- this._signs = this.makeSigns();
64
- if (this._config.asymptotes)
65
- this._asymptotes = this.makeAsymptotes();
66
- if (this._config.derivative)
67
- this._derivative = this.makeDerivative();
68
- if (this._config.variations)
69
- this._variations = this.makeVariation();
70
- // Table of signs / derivative / variation
71
- if (this._config.signs)
72
- this._signs.tex = this.texSigns;
73
- if (this._config.derivative)
74
- this._derivative.tex = this.texGrows;
75
- if (this._config.variations)
76
- this._variations.tex = this.texVariations;
77
- };
78
- this.indexOfZero = (zeroes, zero) => {
79
- for (let i = 0; i < zeroes.length; i++) {
80
- if (zeroes[i].tex === zero.tex) {
81
- return i;
82
- }
83
- }
84
- return -1;
85
- };
86
- this.makeOneLineForSigns = (factor, zeroes, zeroSign) => {
87
- let oneLine = [], currentZero = factor.getZeroes().map(x => x.tex);
88
- // First +/- sign, before the first zero
89
- oneLine.push('');
90
- if (factor.degree().isZero()) {
91
- oneLine.push(factor.monoms[0].coefficient.sign() === 1 ? '+' : '-');
92
- }
93
- else {
94
- oneLine.push(factor.evaluate(zeroes[0].value - 1).sign() === 1 ? '+' : '-');
95
- }
96
- for (let i = 0; i < zeroes.length; i++) {
97
- // Add the zero if it's the current one
98
- oneLine.push(currentZero.includes(zeroes[i].tex) ? zeroSign : ZEROTYPE.NOTHING);
99
- // + / - sign after the current zero
100
- if (i < zeroes.length - 1) {
101
- oneLine.push(factor.evaluate((zeroes[i].value + zeroes[i + 1].value) / 2).sign() === 1 ? '+' : '-');
102
- }
103
- else if (i === zeroes.length - 1) {
104
- oneLine.push(factor.evaluate(zeroes[i].value + 1).sign() === 1 ? '+' : '-');
105
- }
106
- }
107
- oneLine.push('');
108
- return oneLine;
109
- };
110
- this.makeSignsResult = (signs) => {
111
- // Initialize the result line with the first line of the signs table
112
- let resultLine = signs[0].map((x, index) => {
113
- if (index === 0 || index === signs[0].length - 1) {
114
- return '';
115
- }
116
- if (index % 2 === 0) {
117
- return 't';
118
- }
119
- return '+';
120
- });
121
- // Go through each lines (except the first)
122
- for (let current of signs) {
123
- for (let i = 0; i < current.length; i++) {
124
- if (i % 2 === 0) {
125
- // t, z or d
126
- if (resultLine[i] === 'd') {
127
- continue;
128
- }
129
- if (current[i] !== 't') {
130
- resultLine[i] = current[i];
131
- }
132
- }
133
- else {
134
- // + or -
135
- if (current[i] === '-') {
136
- resultLine[i] = resultLine[i] === '+' ? '-' : '+';
137
- }
138
- }
139
- }
140
- }
141
- return resultLine;
142
- };
143
- this.makeGrowsResult = (tos) => {
144
- // Use the last line (=> resultLine) to grab the necessary information
145
- let signsAsArray = Object.values(tos.signs), resultLine = signsAsArray[signsAsArray.length - 1], growsLine = [], extremes = {}, zeroes = tos.zeroes;
146
- // Get the extremes
147
- for (let i = 0; i < zeroes.length; i++) {
148
- // Get the corresponding item in the resultLine.
149
- let pos = 2 * i + 2;
150
- if (resultLine[pos] === 'z') {
151
- // It's a zero. Get the coordinates
152
- let x, y, zero = zeroes[i].exact, pt, xTex, yTex, pointType;
153
- // TODO: NumExp should parse something that isn't yet plotFunction
154
- let exp = new numexp_1.NumExp(this.fx.plotFunction);
155
- if (zero instanceof fraction_1.Fraction) {
156
- let value = zero, evalY = this.fx.evaluate(value);
157
- x = zero.value;
158
- y = evalY.value;
159
- xTex = zero.tex;
160
- yTex = evalY.tex;
161
- }
162
- else {
163
- x = zeroes[i].value;
164
- y = exp.evaluate({ x });
165
- xTex = x.toFixed(2);
166
- yTex = y.toFixed(2);
167
- }
168
- // Determine the type of the zero.
169
- if (resultLine[pos - 1] === resultLine[pos + 1]) {
170
- pointType = FUNCTION_EXTREMA.FLAT;
171
- }
172
- else if (resultLine[pos - 1] === '+') {
173
- pointType = FUNCTION_EXTREMA.MAX;
174
- }
175
- else {
176
- pointType = FUNCTION_EXTREMA.MIN;
177
- }
178
- // Add the point to the list
179
- extremes[zeroes[i].tex] = {
180
- type: pointType,
181
- tex: { x: xTex, y: yTex },
182
- value: { x, y }
183
- };
184
- }
185
- }
186
- // Create the grows line, based on tkz-tab
187
- // \tkzTabLine{ , + , z , - , d , - , z , + , }
188
- // \tkzTabVar{ -/ , +/$3$ , -D+/ , -/$1$ , +/ }
189
- growsLine.push(resultLine[1] === '+' ? '-/' : '+/');
190
- for (let i = 1; i < resultLine.length - 1; i++) {
191
- if (resultLine[i] === "z") {
192
- let extr = extremes[zeroes[(i - 2) / 2].tex];
193
- growsLine.push(`${resultLine[i - 1]}/\\(${extr.type}(${extr.tex.x};${extr.tex.y})\\)`);
194
- }
195
- else if (resultLine[i] === 'd') {
196
- growsLine.push(`${resultLine[i - 1]}D${resultLine[i + 1] === '+' ? '-' : '+'}/`);
197
- }
198
- }
199
- growsLine.push(`${resultLine[resultLine.length - 2]}/`);
200
- return { growsLine, extremes };
201
- };
202
- this.makeVariationsResult = (tos) => {
203
- // TODO: make variations result is not yet implemented.
204
- let extremes = {}, varsLine = [];
205
- return { varsLine, extremes };
206
- };
207
- this.drawCode = () => {
208
- // Function as string
209
- let code = `f(x)=${this.fx.plotFunction}`;
210
- // Asymptotes
211
- let i = 1;
212
- this.asymptotes.forEach(asymptote => {
213
- if (asymptote.type === ASYMPTOTE.VERTICAL) {
214
- code += `\nav_${i}=line x=${asymptote.zero.value}->red,dash`;
215
- i++;
216
- }
217
- else if (asymptote.type === ASYMPTOTE.HORIZONTAL) {
218
- code += `\nah=line y=${asymptote.fx.monoms[0].coefficient.value}->orange,dash`;
219
- }
220
- else if (asymptote.type === ASYMPTOTE.SLOPE) {
221
- code += `\nao=line y=${asymptote.fx.plotFunction}->red,dash`;
222
- }
223
- i++;
224
- });
225
- // Extremes
226
- for (let zero in this.derivative.extremes) {
227
- let extreme = this.derivative.extremes[zero];
228
- code += `\nM_${i}(${extreme.value.x},${extreme.value.y})*`;
229
- i++;
230
- }
231
- // Zeroes
232
- this.zeroes.forEach(zero => {
233
- if (zero.type === ZEROTYPE.ZERO) {
234
- code += `\nZ_${i}(${zero.value},0)*`;
235
- i++;
236
- }
237
- });
238
- return code;
239
- };
240
- this._makeTexFromTableOfSigns = (tos) => {
241
- let factors = tos.factors.map(x => `\\(${x.tex}\\)/1`), factorsFx = `\\(${this._name}(x)\\)/1.2`, zeroes = tos.zeroes;
242
- // Add the last lines "label"
243
- if (tos.type === TABLE_OF_SIGNS.GROWS) {
244
- factorsFx = `\\(${this._name}'(x)\\)/1.2,\\(f(x)\\)/2`;
245
- }
246
- else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
247
- factorsFx = `\\(${this._name}''(x)\\)/1.2,\\(f(x)\\)/2`;
248
- }
249
- // Create the tikzPicture header
1
+ "use strict";
2
+ /**
3
+ * Rational polynom module contains everything necessary to handle rational polynoms.
4
+ * @module Polynom
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Study = exports.TABLE_OF_SIGNS = exports.FUNCTION_EXTREMA = exports.ASYMPTOTE_POSITION = exports.ASYMPTOTE = exports.ZEROTYPE = void 0;
8
+ const fraction_1 = require("../coefficients/fraction");
9
+ const numexp_1 = require("../numexp");
10
+ var ZEROTYPE;
11
+ (function (ZEROTYPE) {
12
+ ZEROTYPE["ZERO"] = "z";
13
+ ZEROTYPE["DEFENCE"] = "d";
14
+ ZEROTYPE["NOTHING"] = "t";
15
+ })(ZEROTYPE || (exports.ZEROTYPE = ZEROTYPE = {}));
16
+ var ASYMPTOTE;
17
+ (function (ASYMPTOTE) {
18
+ ASYMPTOTE["VERTICAL"] = "av";
19
+ ASYMPTOTE["HORIZONTAL"] = "ah";
20
+ ASYMPTOTE["SLOPE"] = "ao";
21
+ ASYMPTOTE["HOLE"] = "hole";
22
+ })(ASYMPTOTE || (exports.ASYMPTOTE = ASYMPTOTE = {}));
23
+ var ASYMPTOTE_POSITION;
24
+ (function (ASYMPTOTE_POSITION) {
25
+ ASYMPTOTE_POSITION["LT"] = "LT";
26
+ ASYMPTOTE_POSITION["RT"] = "RT";
27
+ ASYMPTOTE_POSITION["LB"] = "LB";
28
+ ASYMPTOTE_POSITION["RB"] = "RB";
29
+ })(ASYMPTOTE_POSITION || (exports.ASYMPTOTE_POSITION = ASYMPTOTE_POSITION = {}));
30
+ var FUNCTION_EXTREMA;
31
+ (function (FUNCTION_EXTREMA) {
32
+ FUNCTION_EXTREMA["MIN"] = "min";
33
+ FUNCTION_EXTREMA["MAX"] = "max";
34
+ FUNCTION_EXTREMA["FLAT"] = "flat";
35
+ FUNCTION_EXTREMA["NOTHING"] = "";
36
+ })(FUNCTION_EXTREMA || (exports.FUNCTION_EXTREMA = FUNCTION_EXTREMA = {}));
37
+ var TABLE_OF_SIGNS;
38
+ (function (TABLE_OF_SIGNS) {
39
+ TABLE_OF_SIGNS["SIGNS"] = "signs";
40
+ TABLE_OF_SIGNS["GROWS"] = "grows";
41
+ TABLE_OF_SIGNS["VARIATIONS"] = "variatins";
42
+ })(TABLE_OF_SIGNS || (exports.TABLE_OF_SIGNS = TABLE_OF_SIGNS = {}));
43
+ /**
44
+ * The study class is a "function study" class that will get:
45
+ * fx : get the function
46
+ * domain : string
47
+ * zeroes : Object (tex, IZero)
48
+ * signs : table of signs + tex output using tkz-tab
49
+ * av : vertical asymptotic
50
+ * ah : horizontal asymptotic
51
+ * ao : obliques
52
+ * deltaX : position relative
53
+ * dx : derivative
54
+ * grows : growing table + tex output using tkz-tab
55
+ * ddx : dérivée seconde
56
+ * variations : variation table + tex output using tkz-tab
57
+ */
58
+ class Study {
59
+ constructor(fx, config) {
60
+ this.makeStudy = () => {
61
+ this._zeroes = this.makeZeroes();
62
+ if (this._config.signs)
63
+ this._signs = this.makeSigns();
64
+ if (this._config.asymptotes)
65
+ this._asymptotes = this.makeAsymptotes();
66
+ if (this._config.derivative)
67
+ this._derivative = this.makeDerivative();
68
+ if (this._config.variations)
69
+ this._variations = this.makeVariation();
70
+ // Table of signs / derivative / variation
71
+ if (this._config.signs)
72
+ this._signs.tex = this.texSigns;
73
+ if (this._config.derivative)
74
+ this._derivative.tex = this.texGrows;
75
+ if (this._config.variations)
76
+ this._variations.tex = this.texVariations;
77
+ };
78
+ this.indexOfZero = (zeroes, zero) => {
79
+ for (let i = 0; i < zeroes.length; i++) {
80
+ if (zeroes[i].tex === zero.tex) {
81
+ return i;
82
+ }
83
+ }
84
+ return -1;
85
+ };
86
+ this.makeOneLineForSigns = (factor, zeroes, zeroSign) => {
87
+ let oneLine = [], currentZero = factor.getZeroes().map(x => x.tex);
88
+ // First +/- sign, before the first zero
89
+ oneLine.push('');
90
+ if (factor.degree().isZero()) {
91
+ oneLine.push(factor.monoms[0].coefficient.sign() === 1 ? '+' : '-');
92
+ }
93
+ else {
94
+ oneLine.push(factor.evaluate(zeroes[0].value - 1).sign() === 1 ? '+' : '-');
95
+ }
96
+ for (let i = 0; i < zeroes.length; i++) {
97
+ // Add the zero if it's the current one
98
+ oneLine.push(currentZero.includes(zeroes[i].tex) ? zeroSign : ZEROTYPE.NOTHING);
99
+ // + / - sign after the current zero
100
+ if (i < zeroes.length - 1) {
101
+ oneLine.push(factor.evaluate((zeroes[i].value + zeroes[i + 1].value) / 2).sign() === 1 ? '+' : '-');
102
+ }
103
+ else if (i === zeroes.length - 1) {
104
+ oneLine.push(factor.evaluate(zeroes[i].value + 1).sign() === 1 ? '+' : '-');
105
+ }
106
+ }
107
+ oneLine.push('');
108
+ return oneLine;
109
+ };
110
+ this.makeSignsResult = (signs) => {
111
+ // Initialize the result line with the first line of the signs table
112
+ let resultLine = signs[0].map((x, index) => {
113
+ if (index === 0 || index === signs[0].length - 1) {
114
+ return '';
115
+ }
116
+ if (index % 2 === 0) {
117
+ return 't';
118
+ }
119
+ return '+';
120
+ });
121
+ // Go through each lines (except the first)
122
+ for (let current of signs) {
123
+ for (let i = 0; i < current.length; i++) {
124
+ if (i % 2 === 0) {
125
+ // t, z or d
126
+ if (resultLine[i] === 'd') {
127
+ continue;
128
+ }
129
+ if (current[i] !== 't') {
130
+ resultLine[i] = current[i];
131
+ }
132
+ }
133
+ else {
134
+ // + or -
135
+ if (current[i] === '-') {
136
+ resultLine[i] = resultLine[i] === '+' ? '-' : '+';
137
+ }
138
+ }
139
+ }
140
+ }
141
+ return resultLine;
142
+ };
143
+ this.makeGrowsResult = (tos) => {
144
+ // Use the last line (=> resultLine) to grab the necessary information
145
+ let signsAsArray = Object.values(tos.signs), resultLine = signsAsArray[signsAsArray.length - 1], growsLine = [], extremes = {}, zeroes = tos.zeroes;
146
+ // Get the extremes
147
+ for (let i = 0; i < zeroes.length; i++) {
148
+ // Get the corresponding item in the resultLine.
149
+ let pos = 2 * i + 2;
150
+ if (resultLine[pos] === 'z') {
151
+ // It's a zero. Get the coordinates
152
+ let x, y, zero = zeroes[i].exact, pt, xTex, yTex, pointType;
153
+ // TODO: NumExp should parse something that isn't yet plotFunction
154
+ let exp = new numexp_1.NumExp(this.fx.plotFunction);
155
+ if (zero instanceof fraction_1.Fraction) {
156
+ let value = zero, evalY = this.fx.evaluate(value);
157
+ x = zero.value;
158
+ y = evalY.value;
159
+ xTex = zero.tex;
160
+ yTex = evalY.tex;
161
+ }
162
+ else {
163
+ x = zeroes[i].value;
164
+ y = exp.evaluate({ x });
165
+ xTex = x.toFixed(2);
166
+ yTex = y.toFixed(2);
167
+ }
168
+ // Determine the type of the zero.
169
+ if (resultLine[pos - 1] === resultLine[pos + 1]) {
170
+ pointType = FUNCTION_EXTREMA.FLAT;
171
+ }
172
+ else if (resultLine[pos - 1] === '+') {
173
+ pointType = FUNCTION_EXTREMA.MAX;
174
+ }
175
+ else {
176
+ pointType = FUNCTION_EXTREMA.MIN;
177
+ }
178
+ // Add the point to the list
179
+ extremes[zeroes[i].tex] = {
180
+ type: pointType,
181
+ tex: { x: xTex, y: yTex },
182
+ value: { x, y }
183
+ };
184
+ }
185
+ }
186
+ // Create the grows line, based on tkz-tab
187
+ // \tkzTabLine{ , + , z , - , d , - , z , + , }
188
+ // \tkzTabVar{ -/ , +/$3$ , -D+/ , -/$1$ , +/ }
189
+ growsLine.push(resultLine[1] === '+' ? '-/' : '+/');
190
+ for (let i = 1; i < resultLine.length - 1; i++) {
191
+ if (resultLine[i] === "z") {
192
+ let extr = extremes[zeroes[(i - 2) / 2].tex];
193
+ growsLine.push(`${resultLine[i - 1]}/\\(${extr.type}(${extr.tex.x};${extr.tex.y})\\)`);
194
+ }
195
+ else if (resultLine[i] === 'd') {
196
+ growsLine.push(`${resultLine[i - 1]}D${resultLine[i + 1] === '+' ? '-' : '+'}/`);
197
+ }
198
+ }
199
+ growsLine.push(`${resultLine[resultLine.length - 2]}/`);
200
+ return { growsLine, extremes };
201
+ };
202
+ this.makeVariationsResult = (tos) => {
203
+ // TODO: make variations result is not yet implemented.
204
+ let extremes = {}, varsLine = [];
205
+ return { varsLine, extremes };
206
+ };
207
+ this.drawCode = () => {
208
+ // Function as string
209
+ let code = `f(x)=${this.fx.plotFunction}`;
210
+ // Asymptotes
211
+ let i = 1;
212
+ this.asymptotes.forEach(asymptote => {
213
+ if (asymptote.type === ASYMPTOTE.VERTICAL) {
214
+ code += `\nav_${i}=line x=${asymptote.zero.value}->red,dash`;
215
+ i++;
216
+ }
217
+ else if (asymptote.type === ASYMPTOTE.HORIZONTAL) {
218
+ code += `\nah=line y=${asymptote.fx.monoms[0].coefficient.value}->orange,dash`;
219
+ }
220
+ else if (asymptote.type === ASYMPTOTE.SLOPE) {
221
+ code += `\nao=line y=${asymptote.fx.plotFunction}->red,dash`;
222
+ }
223
+ i++;
224
+ });
225
+ // Extremes
226
+ for (let zero in this.derivative.extremes) {
227
+ let extreme = this.derivative.extremes[zero];
228
+ code += `\nM_${i}(${extreme.value.x},${extreme.value.y})*`;
229
+ i++;
230
+ }
231
+ // Zeroes
232
+ this.zeroes.forEach(zero => {
233
+ if (zero.type === ZEROTYPE.ZERO) {
234
+ code += `\nZ_${i}(${zero.value},0)*`;
235
+ i++;
236
+ }
237
+ });
238
+ return code;
239
+ };
240
+ this._makeTexFromTableOfSigns = (tos) => {
241
+ let factors = tos.factors.map(x => `\\(${x.tex}\\)/1`), factorsFx = `\\(${this._config.name}(${this._config.variable})\\)/1.2`, zeroes = tos.zeroes;
242
+ // Add the last lines "label"
243
+ if (tos.type === TABLE_OF_SIGNS.GROWS) {
244
+ factorsFx = `\\(${this._config.name}'(${this._config.variable})\\)/1.2,\\(f(x${this._config.variable})\\)/2`;
245
+ }
246
+ else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
247
+ factorsFx = `\\(${this._config.name}''(${this._config.variable})\\)/1.2,\\(f(${this._config.variable})\\)/2`;
248
+ }
249
+ // Create the tikzPicture header
250
250
  let tex = `\\begin{tikzpicture}
251
- \\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\\)}}`;
252
- let pos;
253
- for (pos = 0; pos < tos.factors.length; pos++) {
254
- tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`);
255
- }
256
- // Add the result line
257
- tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`);
258
- // Add the grows / vars line
259
- if (tos.type === TABLE_OF_SIGNS.GROWS) {
260
- tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`);
261
- }
262
- else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
263
- // TODO: Check variations table for as tex
264
- tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`);
265
- }
266
- tex += `\n\\end{tikzpicture}`;
267
- return tex;
268
- };
269
- this.fx = fx;
270
- this._config = {
271
- name: 'f',
272
- domain: true,
273
- asymptotes: true,
274
- signs: true,
275
- derivative: true,
276
- variations: true,
277
- };
278
- if (config) {
279
- if (typeof config === 'string') {
280
- const d = config.split(',');
281
- this._config = {};
282
- let n = d.filter(x => x.includes('(x)'));
283
- if (n.length === 1) {
284
- this._config.name = n[0].split('(x)')[0];
285
- }
286
- this._config.domain = d.includes('d');
287
- this._config.asymptotes = d.includes('a');
288
- this._config.signs = d.includes('signs');
289
- this._config.derivative = d.includes('dx');
290
- this._config.variations = d.includes('ddx');
291
- }
292
- else {
293
- this._config = config;
294
- }
295
- }
296
- this._name = this._config?.name ?? 'f';
297
- this.makeStudy();
298
- return this;
299
- }
300
- get name() {
301
- return this._name;
302
- }
303
- set name(value) {
304
- this._name = value;
305
- }
306
- get config() {
307
- return this._config;
308
- }
309
- set config(value) {
310
- this._config = value;
311
- }
312
- get zeroes() {
313
- return this._zeroes;
314
- }
315
- get domain() {
316
- return this.fx.domain();
317
- }
318
- get signs() {
319
- return this._signs;
320
- }
321
- get asymptotes() {
322
- return this._asymptotes;
323
- }
324
- get derivative() {
325
- return this._derivative;
326
- }
327
- get texSigns() {
328
- return this._makeTexFromTableOfSigns(this._signs);
329
- }
330
- get texGrows() {
331
- return this._makeTexFromTableOfSigns(this._derivative);
332
- }
333
- get texVariations() {
334
- return this._makeTexFromTableOfSigns(this._variations);
335
- }
336
- makeZeroes() {
337
- return [];
338
- }
339
- ;
340
- makeSigns() {
341
- return {
342
- type: TABLE_OF_SIGNS.SIGNS,
343
- fx: null,
344
- factors: [],
345
- zeroes: [],
346
- signs: [],
347
- extremes: {},
348
- tex: ''
349
- };
350
- }
351
- ;
352
- makeAsymptotes() {
353
- return [];
354
- }
355
- makeDerivative() {
356
- return {
357
- type: TABLE_OF_SIGNS.GROWS,
358
- fx: null,
359
- factors: [],
360
- zeroes: [],
361
- signs: [],
362
- extremes: {},
363
- tex: ''
364
- };
365
- }
366
- makeVariation() {
367
- return {
368
- type: TABLE_OF_SIGNS.VARIATIONS,
369
- fx: null,
370
- factors: [],
371
- zeroes: [],
372
- signs: [],
373
- extremes: {},
374
- tex: ''
375
- };
376
- }
377
- }
378
- exports.Study = Study;
251
+ \\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\\)}}`;
252
+ let pos;
253
+ for (pos = 0; pos < tos.factors.length; pos++) {
254
+ tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`);
255
+ }
256
+ // Add the result line
257
+ tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`);
258
+ // Add the grows / vars line
259
+ if (tos.type === TABLE_OF_SIGNS.GROWS) {
260
+ tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`);
261
+ }
262
+ else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
263
+ // TODO: Check variations table for as tex
264
+ tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`);
265
+ }
266
+ tex += `\n\\end{tikzpicture}`;
267
+ return tex;
268
+ };
269
+ this.fx = fx;
270
+ this._config = {
271
+ name: 'f',
272
+ variable: 'x',
273
+ domain: true,
274
+ asymptotes: true,
275
+ signs: true,
276
+ derivative: true,
277
+ variations: true,
278
+ };
279
+ if (config) {
280
+ if (typeof config === 'string') {
281
+ const d = config.split(',');
282
+ this._config = {};
283
+ let n = d.filter(x => x.includes('(') && x.includes(')'));
284
+ if (n.length === 1) {
285
+ this._config.name = n[0].split('(')[0];
286
+ this._config.variable = n[0].split('(')[1].split(')')[0];
287
+ }
288
+ this._config.domain = d.includes('d');
289
+ this._config.asymptotes = d.includes('a');
290
+ this._config.signs = d.includes('signs');
291
+ this._config.derivative = d.includes('dx');
292
+ this._config.variations = d.includes('ddx');
293
+ }
294
+ else {
295
+ this._config = config;
296
+ }
297
+ }
298
+ this.makeStudy();
299
+ return this;
300
+ }
301
+ get name() {
302
+ return this._config.name;
303
+ }
304
+ set name(value) {
305
+ this._config.name = value;
306
+ }
307
+ get config() {
308
+ return this._config;
309
+ }
310
+ set config(value) {
311
+ this._config = value;
312
+ }
313
+ get zeroes() {
314
+ return this._zeroes;
315
+ }
316
+ get domain() {
317
+ return this.fx.domain();
318
+ }
319
+ get signs() {
320
+ return this._signs;
321
+ }
322
+ get asymptotes() {
323
+ return this._asymptotes;
324
+ }
325
+ get derivative() {
326
+ return this._derivative;
327
+ }
328
+ get texSigns() {
329
+ return this._makeTexFromTableOfSigns(this._signs);
330
+ }
331
+ get texGrows() {
332
+ return this._makeTexFromTableOfSigns(this._derivative);
333
+ }
334
+ get texVariations() {
335
+ return this._makeTexFromTableOfSigns(this._variations);
336
+ }
337
+ makeZeroes() {
338
+ return [];
339
+ }
340
+ ;
341
+ makeSigns() {
342
+ return {
343
+ type: TABLE_OF_SIGNS.SIGNS,
344
+ fx: null,
345
+ factors: [],
346
+ zeroes: [],
347
+ signs: [],
348
+ extremes: {},
349
+ tex: ''
350
+ };
351
+ }
352
+ ;
353
+ makeAsymptotes() {
354
+ return [];
355
+ }
356
+ makeDerivative() {
357
+ return {
358
+ type: TABLE_OF_SIGNS.GROWS,
359
+ fx: null,
360
+ factors: [],
361
+ zeroes: [],
362
+ signs: [],
363
+ extremes: {},
364
+ tex: ''
365
+ };
366
+ }
367
+ makeVariation() {
368
+ return {
369
+ type: TABLE_OF_SIGNS.VARIATIONS,
370
+ fx: null,
371
+ factors: [],
372
+ zeroes: [],
373
+ signs: [],
374
+ extremes: {},
375
+ tex: ''
376
+ };
377
+ }
378
+ }
379
+ exports.Study = Study;
379
380
  //# sourceMappingURL=study.js.map