math-exercises 1.2.8 → 1.2.10

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 (216) hide show
  1. package/lib/exercises/calcul/addAndSub.js +40 -0
  2. package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -0
  3. package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +31 -0
  4. package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -0
  5. package/lib/exercises/calcul/fractions/fractionsDivision.js +29 -0
  6. package/lib/exercises/calcul/fractions/fractionsProduct.js +29 -0
  7. package/lib/exercises/calcul/fractions/fractionsSum.js +29 -0
  8. package/lib/exercises/calcul/fractions/simplifyFraction.js +25 -0
  9. package/lib/exercises/calcul/operations/operationsPriorities.js +88 -0
  10. package/lib/exercises/calcul/operations/operationsPrioritiesWithoutRelative.js +111 -0
  11. package/{src → lib}/exercises/calcul/operationsPriorities.js +88 -89
  12. package/{src → lib}/exercises/calcul/rounding/rounding.js +86 -87
  13. package/{src → lib}/exercises/calculLitteral/distributivity/allIdentities.js +27 -27
  14. package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +31 -0
  15. package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +32 -0
  16. package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +33 -0
  17. package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +33 -0
  18. package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +32 -0
  19. package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +38 -0
  20. package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +41 -0
  21. package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +42 -0
  22. package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +44 -0
  23. package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +39 -0
  24. package/{src → lib}/exercises/exercise.js +7 -7
  25. package/lib/exercises/exercises.js +95 -0
  26. package/lib/exercises/geometry/cartesian/midpoint.js +29 -0
  27. package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +29 -0
  28. package/lib/exercises/geometry/vectors/scalarProductViaNorms.js +27 -0
  29. package/lib/exercises/powers/powersDivision.js +45 -0
  30. package/lib/exercises/powers/powersOfTenToDecimal.js +33 -0
  31. package/lib/exercises/powers/powersPower.js +44 -0
  32. package/lib/exercises/powers/powersProduct.js +45 -0
  33. package/lib/exercises/powers/scientificToDecimal.js +38 -0
  34. package/{src → lib}/exercises/squareRoots/simpifySquareRoot.js +28 -28
  35. package/lib/exercises/utils/getDistinctQuestions.js +16 -0
  36. package/lib/geometry/point.js +27 -0
  37. package/lib/geometry/vector.js +31 -0
  38. package/lib/index.js +10 -0
  39. package/lib/mathutils/arithmetic/coprimesOf.js +13 -0
  40. package/lib/mathutils/arithmetic/dividersOf.js +12 -0
  41. package/{src → lib}/mathutils/arithmetic/gcd.js +7 -7
  42. package/{src → lib}/mathutils/arithmetic/isSquare.js +7 -7
  43. package/{src → lib}/mathutils/arithmetic/lcd.js +12 -12
  44. package/lib/mathutils/arithmetic/nonCoprimesOf.js +13 -0
  45. package/lib/mathutils/arithmetic/nonDividersOf.js +14 -0
  46. package/{src → lib}/mathutils/arithmetic/primeFactors.js +22 -22
  47. package/lib/mathutils/decimals/decimalPartLengthOf.js +14 -0
  48. package/lib/mathutils/random/randTupleInt.js +30 -0
  49. package/{src → lib}/mathutils/random/randint.js +18 -18
  50. package/{src → lib}/mathutils/round.js +8 -8
  51. package/{src → lib}/numbers/decimals/decimal.js +140 -144
  52. package/{src → lib}/numbers/epsilon.js +10 -10
  53. package/{src → lib}/numbers/integer/integer.js +68 -72
  54. package/{src → lib}/numbers/integer/power.js +52 -53
  55. package/{src → lib}/numbers/nombre.js +10 -10
  56. package/lib/numbers/rationals/rational.js +113 -0
  57. package/lib/numbers/reals/real.js +16 -0
  58. package/lib/numbers/reals/squareRoot.js +63 -0
  59. package/lib/polynomials/affine.js +42 -0
  60. package/lib/polynomials/polynomial.js +125 -0
  61. package/lib/sets/discreteSet.js +28 -0
  62. package/{src/sets/emptySet.ts → lib/sets/emptySet.js} +6 -6
  63. package/{src → lib}/sets/intervals/intervals.js +108 -113
  64. package/lib/sets/intervals/union.js +1 -0
  65. package/lib/sets/mathSet.js +10 -0
  66. package/lib/sets/mathSetInterface.js +2 -0
  67. package/{src → lib}/tree/nodes/functions/functionNode.js +18 -19
  68. package/lib/tree/nodes/functions/oppositeNode.js +13 -0
  69. package/lib/tree/nodes/functions/sqrtNode.js +15 -0
  70. package/{src → lib}/tree/nodes/node.js +10 -10
  71. package/lib/tree/nodes/numbers/numberNode.js +18 -0
  72. package/lib/tree/nodes/operators/addNode.js +15 -0
  73. package/lib/tree/nodes/operators/divideNode.js +17 -0
  74. package/lib/tree/nodes/operators/equalNode.js +13 -0
  75. package/lib/tree/nodes/operators/fractionNode.js +17 -0
  76. package/lib/tree/nodes/operators/multiplyNode.js +13 -0
  77. package/{src → lib}/tree/nodes/operators/operatorNode.js +35 -37
  78. package/lib/tree/nodes/operators/powerNode.js +13 -0
  79. package/lib/tree/nodes/operators/substractNode.js +13 -0
  80. package/lib/tree/nodes/variables/variableNode.js +16 -0
  81. package/{src → lib}/tree/parsers/derivateParser.js +60 -60
  82. package/{src → lib}/tree/parsers/latexParser.js +117 -117
  83. package/lib/utils/arrayEqual.js +13 -0
  84. package/{src → lib}/utils/coin.js +7 -7
  85. package/{src → lib}/utils/random.js +7 -7
  86. package/lib/utils/shuffle.js +15 -0
  87. package/package.json +35 -28
  88. package/nodemon.json +0 -5
  89. package/src/exercises/calcul/addAndSub.js +0 -40
  90. package/src/exercises/calcul/addAndSub.ts +0 -39
  91. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.js +0 -35
  92. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.ts +0 -36
  93. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.js +0 -31
  94. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.ts +0 -32
  95. package/src/exercises/calcul/fractions/fractionAndIntegerSum.js +0 -32
  96. package/src/exercises/calcul/fractions/fractionAndIntegerSum.ts +0 -31
  97. package/src/exercises/calcul/fractions/fractionsDivision.js +0 -29
  98. package/src/exercises/calcul/fractions/fractionsDivision.ts +0 -30
  99. package/src/exercises/calcul/fractions/fractionsProduct.js +0 -29
  100. package/src/exercises/calcul/fractions/fractionsProduct.ts +0 -29
  101. package/src/exercises/calcul/fractions/fractionsSum.js +0 -29
  102. package/src/exercises/calcul/fractions/fractionsSum.ts +0 -28
  103. package/src/exercises/calcul/fractions/simplifyFraction.js +0 -25
  104. package/src/exercises/calcul/fractions/simplifyFraction.ts +0 -24
  105. package/src/exercises/calcul/operationsPriorities.ts +0 -115
  106. package/src/exercises/calcul/rounding/rounding.ts +0 -87
  107. package/src/exercises/calculLitteral/distributivity/allIdentities.ts +0 -26
  108. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.js +0 -31
  109. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.ts +0 -33
  110. package/src/exercises/calculLitteral/distributivity/firstIdentity.js +0 -32
  111. package/src/exercises/calculLitteral/distributivity/firstIdentity.ts +0 -33
  112. package/src/exercises/calculLitteral/distributivity/secondIdentity.js +0 -33
  113. package/src/exercises/calculLitteral/distributivity/secondIdentity.ts +0 -35
  114. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.js +0 -33
  115. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.ts +0 -33
  116. package/src/exercises/calculLitteral/distributivity/thirdIdentity.js +0 -32
  117. package/src/exercises/calculLitteral/distributivity/thirdIdentity.ts +0 -34
  118. package/src/exercises/calculLitteral/equation/equationType1Exercise.js +0 -38
  119. package/src/exercises/calculLitteral/equation/equationType1Exercise.ts +0 -38
  120. package/src/exercises/calculLitteral/equation/equationType2Exercise.js +0 -41
  121. package/src/exercises/calculLitteral/equation/equationType2Exercise.ts +0 -41
  122. package/src/exercises/calculLitteral/equation/equationType3Exercise.js +0 -42
  123. package/src/exercises/calculLitteral/equation/equationType3Exercise.ts +0 -43
  124. package/src/exercises/calculLitteral/equation/equationType4Exercise.js +0 -44
  125. package/src/exercises/calculLitteral/equation/equationType4Exercise.ts +0 -46
  126. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.js +0 -39
  127. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.ts +0 -54
  128. package/src/exercises/exercise.ts +0 -22
  129. package/src/exercises/exercises.js +0 -85
  130. package/src/exercises/exercises.ts +0 -94
  131. package/src/exercises/powers/powersDivision.js +0 -46
  132. package/src/exercises/powers/powersDivision.ts +0 -51
  133. package/src/exercises/powers/powersOfTenToDecimal.js +0 -33
  134. package/src/exercises/powers/powersOfTenToDecimal.ts +0 -37
  135. package/src/exercises/powers/powersPower.js +0 -45
  136. package/src/exercises/powers/powersPower.ts +0 -55
  137. package/src/exercises/powers/powersProduct.js +0 -46
  138. package/src/exercises/powers/powersProduct.ts +0 -51
  139. package/src/exercises/powers/scientificToDecimal.js +0 -38
  140. package/src/exercises/powers/scientificToDecimal.ts +0 -44
  141. package/src/exercises/squareRoots/simpifySquareRoot.ts +0 -27
  142. package/src/exercises/utils/getDistinctQuestions.js +0 -18
  143. package/src/exercises/utils/getDistinctQuestions.ts +0 -14
  144. package/src/index.js +0 -5
  145. package/src/index.ts +0 -13
  146. package/src/mathutils/arithmetic/coprimesOf.js +0 -13
  147. package/src/mathutils/arithmetic/coprimesOf.ts +0 -9
  148. package/src/mathutils/arithmetic/dividersOf.ts +0 -7
  149. package/src/mathutils/arithmetic/gcd.ts +0 -3
  150. package/src/mathutils/arithmetic/isSquare.ts +0 -3
  151. package/src/mathutils/arithmetic/lcd.ts +0 -7
  152. package/src/mathutils/arithmetic/nonCoprimesOf.ts +0 -9
  153. package/src/mathutils/arithmetic/nonDividersOf.ts +0 -12
  154. package/src/mathutils/arithmetic/primeFactors.ts +0 -18
  155. package/src/mathutils/decimals/decimalPartLengthOf.ts +0 -10
  156. package/src/mathutils/random/randint.ts +0 -12
  157. package/src/mathutils/round.ts +0 -5
  158. package/src/numbers/decimals/decimal.ts +0 -140
  159. package/src/numbers/epsilon.ts +0 -7
  160. package/src/numbers/integer/integer.ts +0 -72
  161. package/src/numbers/integer/power.ts +0 -49
  162. package/src/numbers/nombre.ts +0 -15
  163. package/src/numbers/number.js +0 -8
  164. package/src/numbers/rationals/rational.js +0 -128
  165. package/src/numbers/rationals/rational.ts +0 -122
  166. package/src/numbers/reals/real.js +0 -17
  167. package/src/numbers/reals/real.ts +0 -17
  168. package/src/numbers/reals/squareRoot.js +0 -85
  169. package/src/numbers/reals/squareRoot.ts +0 -70
  170. package/src/polynomials/affine.js +0 -71
  171. package/src/polynomials/affine.ts +0 -60
  172. package/src/polynomials/polynomial.js +0 -128
  173. package/src/polynomials/polynomial.ts +0 -137
  174. package/src/sets/discreteSet.js +0 -30
  175. package/src/sets/discreteSet.ts +0 -30
  176. package/src/sets/intervals/intervals.ts +0 -122
  177. package/src/sets/intervals/union.ts +0 -0
  178. package/src/sets/mathSet.js +0 -11
  179. package/src/sets/mathSet.ts +0 -12
  180. package/src/sets/mathSetInterface.js +0 -2
  181. package/src/sets/mathSetInterface.ts +0 -10
  182. package/src/tree/latexParser/latexParse.js +0 -117
  183. package/src/tree/nodes/functions/functionNode.ts +0 -18
  184. package/src/tree/nodes/functions/oppositeNode.js +0 -30
  185. package/src/tree/nodes/functions/oppositeNode.ts +0 -12
  186. package/src/tree/nodes/functions/sqrtNode.js +0 -33
  187. package/src/tree/nodes/functions/sqrtNode.ts +0 -12
  188. package/src/tree/nodes/node.ts +0 -12
  189. package/src/tree/nodes/numbers/numberNode.js +0 -16
  190. package/src/tree/nodes/numbers/numberNode.ts +0 -16
  191. package/src/tree/nodes/operators/addNode.js +0 -33
  192. package/src/tree/nodes/operators/addNode.ts +0 -13
  193. package/src/tree/nodes/operators/divideNode.js +0 -34
  194. package/src/tree/nodes/operators/divideNode.ts +0 -16
  195. package/src/tree/nodes/operators/equalNode.js +0 -30
  196. package/src/tree/nodes/operators/equalNode.ts +0 -11
  197. package/src/tree/nodes/operators/fractionNode.js +0 -34
  198. package/src/tree/nodes/operators/fractionNode.ts +0 -16
  199. package/src/tree/nodes/operators/multiplyNode.js +0 -30
  200. package/src/tree/nodes/operators/multiplyNode.ts +0 -12
  201. package/src/tree/nodes/operators/operatorNode.ts +0 -36
  202. package/src/tree/nodes/operators/oppositeNode.js +0 -18
  203. package/src/tree/nodes/operators/powerNode.js +0 -30
  204. package/src/tree/nodes/operators/powerNode.ts +0 -12
  205. package/src/tree/nodes/operators/substractNode.js +0 -30
  206. package/src/tree/nodes/operators/substractNode.ts +0 -11
  207. package/src/tree/nodes/variables/variableNode.js +0 -17
  208. package/src/tree/nodes/variables/variableNode.ts +0 -15
  209. package/src/tree/parsers/derivateParser.ts +0 -66
  210. package/src/tree/parsers/latexParser.ts +0 -122
  211. package/src/utils/coin.ts +0 -3
  212. package/src/utils/random.ts +0 -3
  213. package/src/utils/randomIn.js +0 -7
  214. package/src/utils/shuffle.js +0 -24
  215. package/src/utils/shuffle.ts +0 -11
  216. package/tsconfig.json +0 -110
@@ -1,128 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.Polynomial = void 0;
4
- var numberNode_1 = require("../tree/nodes/numbers/numberNode");
5
- var addNode_1 = require("../tree/nodes/operators/addNode");
6
- var multiplyNode_1 = require("../tree/nodes/operators/multiplyNode");
7
- var oppositeNode_1 = require("../tree/nodes/functions/oppositeNode");
8
- var powerNode_1 = require("../tree/nodes/operators/powerNode");
9
- var variableNode_1 = require("../tree/nodes/variables/variableNode");
10
- var Polynomial = /** @class */ (function () {
11
- /**
12
- *
13
- * @param coefficients coefficients[i] est le coeff de x^i
14
- * @param variable
15
- */
16
- function Polynomial(coefficients, variable) {
17
- if (variable === void 0) { variable = "x"; }
18
- if (coefficients.length === 0)
19
- throw Error("coeffs must be not null");
20
- if (coefficients[coefficients.length - 1] === 0) {
21
- throw Error("n-th coeff must be not null");
22
- }
23
- this.coefficients = coefficients;
24
- this.variable = variable;
25
- this.degree = coefficients.length - 1;
26
- }
27
- Polynomial.prototype.equals = function (P) {
28
- return P.degree === this.degree && this.coefficients.every(function (coeff, i) { return coeff === P.coefficients[i]; });
29
- };
30
- Polynomial.prototype.getRoots = function () { };
31
- Polynomial.prototype.add = function (P) {
32
- if (P.variable !== this.variable)
33
- throw Error("Can't add two polynomials with different variables");
34
- var newDegree = P.degree === this.degree && P.coefficients[P.degree] === -this.coefficients[this.degree]
35
- ? P.degree - 1
36
- : Math.max(P.degree, this.degree);
37
- var res = [];
38
- for (var i = 0; i < newDegree + 1; i++) {
39
- res[i] = P.coefficients[i] + this.coefficients[i];
40
- }
41
- return new Polynomial(res, this.variable);
42
- };
43
- Polynomial.prototype.times = function (nb) {
44
- return new Polynomial(this.coefficients.map(function (coeff) { return coeff * nb; }), this.variable);
45
- };
46
- Polynomial.prototype.multiply = function (Q) {
47
- if (Q.variable !== this.variable)
48
- throw Error("Can't multiply two polynomials with different variables");
49
- var p = this.degree;
50
- var q = Q.degree;
51
- var res = Array.apply(0, new Array(this.degree)).map(function (i) { return 0; });
52
- for (var k = 0; k <= p + q; k++) {
53
- var sum = 0;
54
- for (var m = 0; m <= k; m++) {
55
- sum += (this.coefficients[m] || 0) * (Q.coefficients[k - m] || 0);
56
- }
57
- res[k] = sum;
58
- }
59
- return new Polynomial(res, this.variable);
60
- };
61
- Polynomial.prototype.opposite = function () {
62
- return new Polynomial(this.coefficients.map(function (coeff) { return -coeff; }), this.variable);
63
- };
64
- Polynomial.prototype.toTree = function () {
65
- var _this = this;
66
- var recursive = function (cursor) {
67
- var coeff = _this.coefficients[cursor];
68
- if (coeff === 0)
69
- return recursive(cursor - 1);
70
- if (cursor === 0) {
71
- return new numberNode_1.NumberNode(coeff);
72
- }
73
- var monome = cursor > 1
74
- ? new powerNode_1.PowerNode(new variableNode_1.VariableNode(_this.variable), new numberNode_1.NumberNode(cursor))
75
- : new variableNode_1.VariableNode(_this.variable);
76
- var res;
77
- if (coeff === 1)
78
- res = monome;
79
- else if (coeff === -1)
80
- res = new oppositeNode_1.OppositeNode(monome);
81
- else
82
- res = new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(coeff), monome);
83
- var nextCoeff;
84
- for (var i = cursor - 1; i > -1; i--) {
85
- if (_this.coefficients[i]) {
86
- nextCoeff = _this.coefficients[i];
87
- break;
88
- }
89
- }
90
- if (nextCoeff) {
91
- return new addNode_1.AddNode(res, recursive(cursor - 1));
92
- }
93
- else {
94
- return res;
95
- }
96
- };
97
- return recursive(this.degree);
98
- };
99
- Polynomial.prototype.toTex = function () {
100
- var s = "";
101
- for (var i = this.degree; i > -1; i--) {
102
- var coeff = this.coefficients[i];
103
- if (coeff === 0)
104
- continue;
105
- if (i === 0)
106
- s += coeff > 0 ? "+".concat(coeff) : coeff;
107
- else if (i === this.degree) {
108
- s += coeff === 1 ? "" : coeff === -1 ? "-" : coeff;
109
- }
110
- else {
111
- s += coeff === 1 ? "+" : coeff === -1 ? "-" : coeff > 0 ? "+".concat(coeff) : coeff;
112
- }
113
- //x^n
114
- if (i === 0)
115
- continue;
116
- if (i === 1)
117
- s += this.variable;
118
- else
119
- s += "".concat(this.variable, "^{").concat(i, "}");
120
- }
121
- return s;
122
- };
123
- Polynomial.prototype.toString = function () {
124
- return this.toTex();
125
- };
126
- return Polynomial;
127
- }());
128
- exports.Polynomial = Polynomial;
@@ -1,137 +0,0 @@
1
- import { Node } from "../tree/nodes/node";
2
- import { NumberNode } from "../tree/nodes/numbers/numberNode";
3
- import { AddNode } from "../tree/nodes/operators/addNode";
4
- import { MultiplyNode } from "../tree/nodes/operators/multiplyNode";
5
- import { OppositeNode } from "../tree/nodes/functions/oppositeNode";
6
- import { PowerNode } from "../tree/nodes/operators/powerNode";
7
- import { SubstractNode } from "../tree/nodes/operators/substractNode";
8
- import { VariableNode } from "../tree/nodes/variables/variableNode";
9
-
10
- export class Polynomial {
11
- degree: number;
12
- variable: string;
13
- /**
14
- * coefficients[i] est le coeff de x^i
15
- */
16
- coefficients: number[];
17
-
18
- /**
19
- *
20
- * @param coefficients coefficients[i] est le coeff de x^i
21
- * @param variable
22
- */
23
- constructor(coefficients: number[], variable: string = "x") {
24
- if (coefficients.length === 0) throw Error("coeffs must be not null");
25
- if (coefficients[coefficients.length - 1] === 0) {
26
- throw Error("n-th coeff must be not null");
27
- }
28
- this.coefficients = coefficients;
29
- this.variable = variable;
30
- this.degree = coefficients.length - 1;
31
- }
32
- equals(P: Polynomial): boolean {
33
- return P.degree === this.degree && this.coefficients.every((coeff, i) => coeff === P.coefficients[i]);
34
- }
35
- getRoots() {}
36
- add(P: Polynomial): Polynomial {
37
- if (P.variable !== this.variable) throw Error("Can't add two polynomials with different variables");
38
-
39
- const newDegree =
40
- P.degree === this.degree && P.coefficients[P.degree] === -this.coefficients[this.degree]
41
- ? P.degree - 1
42
- : Math.max(P.degree, this.degree);
43
-
44
- const res: number[] = [];
45
- for (let i = 0; i < newDegree + 1; i++) {
46
- res[i] = P.coefficients[i] + this.coefficients[i];
47
- }
48
- return new Polynomial(res, this.variable);
49
- }
50
- times(nb: number): Polynomial {
51
- return new Polynomial(
52
- this.coefficients.map((coeff) => coeff * nb),
53
- this.variable
54
- );
55
- }
56
- multiply(Q: Polynomial): Polynomial {
57
- if (Q.variable !== this.variable) throw Error("Can't multiply two polynomials with different variables");
58
-
59
- const p = this.degree;
60
- const q = Q.degree;
61
- const res: number[] = Array.apply(0, new Array(this.degree)).map((i) => 0);
62
-
63
- for (let k = 0; k <= p + q; k++) {
64
- let sum = 0;
65
- for (let m = 0; m <= k; m++) {
66
- sum += (this.coefficients[m] || 0) * (Q.coefficients[k - m] || 0);
67
- }
68
- res[k] = sum;
69
- }
70
-
71
- return new Polynomial(res, this.variable);
72
- }
73
-
74
- opposite(): Polynomial {
75
- return new Polynomial(
76
- this.coefficients.map((coeff) => -coeff),
77
- this.variable
78
- );
79
- }
80
-
81
- toTree(): Node {
82
- const recursive = (cursor: number): Node => {
83
- const coeff = this.coefficients[cursor];
84
- if (coeff === 0) return recursive(cursor - 1);
85
-
86
- if (cursor === 0) {
87
- return new NumberNode(coeff);
88
- }
89
-
90
- const monome =
91
- cursor > 1
92
- ? new PowerNode(new VariableNode(this.variable), new NumberNode(cursor))
93
- : new VariableNode(this.variable);
94
-
95
- let res: Node;
96
- if (coeff === 1) res = monome;
97
- else if (coeff === -1) res = new OppositeNode(monome);
98
- else res = new MultiplyNode(new NumberNode(coeff), monome);
99
-
100
- let nextCoeff;
101
- for (let i = cursor - 1; i > -1; i--) {
102
- if (this.coefficients[i]) {
103
- nextCoeff = this.coefficients[i];
104
- break;
105
- }
106
- }
107
- if (nextCoeff) {
108
- return new AddNode(res, recursive(cursor - 1));
109
- } else {
110
- return res;
111
- }
112
- };
113
- return recursive(this.degree);
114
- }
115
-
116
- toTex(): string {
117
- let s = "";
118
- for (let i = this.degree; i > -1; i--) {
119
- const coeff = this.coefficients[i];
120
- if (coeff === 0) continue;
121
- if (i === 0) s += coeff > 0 ? `+${coeff}` : coeff;
122
- else if (i === this.degree) {
123
- s += coeff === 1 ? "" : coeff === -1 ? "-" : coeff;
124
- } else {
125
- s += coeff === 1 ? "+" : coeff === -1 ? "-" : coeff > 0 ? `+${coeff}` : coeff;
126
- }
127
- //x^n
128
- if (i === 0) continue;
129
- if (i === 1) s += this.variable;
130
- else s += `${this.variable}^{${i}}`;
131
- }
132
- return s;
133
- }
134
- toString(): string {
135
- return this.toTex();
136
- }
137
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.DiscreteSet = void 0;
4
- var random_1 = require("../utils/random");
5
- var DiscreteSet = /** @class */ (function () {
6
- function DiscreteSet(elements) {
7
- var _this = this;
8
- this.elements = Array.from(new Set(elements));
9
- var tex = "\\{";
10
- this.elements.forEach(function (el, index) {
11
- tex += el.tex;
12
- if (index < _this.elements.length - 1)
13
- tex += ";";
14
- else
15
- tex += "\\}";
16
- });
17
- this.tex = tex;
18
- }
19
- DiscreteSet.prototype.toTex = function () {
20
- return this.tex;
21
- };
22
- DiscreteSet.prototype.includes = function (el) {
23
- return this.elements.some(function (nb) { return nb.value === el.value && nb.tex === el.tex; });
24
- };
25
- DiscreteSet.prototype.getRandomElement = function () {
26
- return (0, random_1.random)(this.elements);
27
- };
28
- return DiscreteSet;
29
- }());
30
- exports.DiscreteSet = DiscreteSet;
@@ -1,30 +0,0 @@
1
- import { Nombre } from "../numbers/nombre";
2
- import { random } from "../utils/random";
3
- import { MathSetInterface } from "./mathSetInterface";
4
-
5
- export class DiscreteSet implements MathSetInterface {
6
- elements: Nombre[];
7
- tex: string;
8
- constructor(elements: Nombre[]) {
9
- this.elements = Array.from(new Set(elements));
10
- let tex = "\\{";
11
- this.elements.forEach((el, index) => {
12
- tex += el.tex;
13
- if (index < this.elements.length - 1) tex += ";";
14
- else tex += "\\}";
15
- });
16
- this.tex = tex;
17
- }
18
-
19
- toTex(): string {
20
- return this.tex;
21
- }
22
-
23
- includes(el: Nombre): boolean {
24
- return this.elements.some((nb) => nb.value === el.value && nb.tex === el.tex);
25
- }
26
-
27
- getRandomElement(): Nombre {
28
- return random(this.elements);
29
- }
30
- }
@@ -1,122 +0,0 @@
1
- import { EPSILON } from "../../numbers/epsilon";
2
- import { Nombre, NumberType } from "../../numbers/nombre";
3
- import { round } from "../../mathutils/round";
4
- import { MathSetInterface } from "../mathSetInterface";
5
- import { DiscreteSet } from "../discreteSet";
6
- import { MathSet } from "../mathSet";
7
- import { Integer } from "../../numbers/integer/integer";
8
- import { Real } from "../../numbers/reals/real";
9
-
10
- enum BoundType {
11
- OO = "]a;b[",
12
- OF = "]a;b]",
13
- FO = "[a;b[",
14
- FF = "[a;b]",
15
- }
16
-
17
- export class Interval implements MathSetInterface {
18
- min: number;
19
- max: number;
20
- boundType: BoundType;
21
- type: NumberType;
22
- tex: string;
23
- /**
24
- * [[a; b]] pour un interval d'integer; [a;b] pour des réels
25
- */
26
- constructor(tex = "[-10; 10]") {
27
- this.tex = tex;
28
- const isInt = tex[1] === "[" || tex[1] === "]";
29
- this.type = isInt ? NumberType.Integer : NumberType.Real;
30
- const left = tex[0];
31
- const right = tex[tex.length - 1];
32
- const [a, b] = tex
33
- .slice(isInt ? 2 : 1, isInt ? tex.length - 2 : tex.length - 1)
34
- .split(";");
35
-
36
- switch (`${left}a;b${right}`) {
37
- case "[a;b]":
38
- this.boundType = BoundType.FF;
39
- break;
40
- case "]a;b[":
41
- this.boundType = BoundType.OO;
42
- break;
43
- case "[a;b[":
44
- this.boundType = BoundType.FO;
45
- break;
46
- case "]a;b]":
47
- this.boundType = BoundType.OF;
48
- break;
49
- default:
50
- throw console.error("wrong interval");
51
- }
52
- function getBound(bound: string) {
53
- return bound === "-\\infty"
54
- ? Number.NEGATIVE_INFINITY
55
- : bound === "+\\infty"
56
- ? Number.POSITIVE_INFINITY
57
- : Number(bound);
58
- }
59
- this.min = getBound(a);
60
- this.max = getBound(b);
61
- }
62
-
63
- // union(interval: Interval): MathSet {
64
- //[a,b] [c,d]
65
- //si a=c return a, max(b,d)
66
- //si si b = d return min(a,c), b
67
- //si a=d return c,b sauf si OXXO
68
- //si b=c return a,d sauf si XOOX
69
- //si c > b ou d < a alors union disjointe avec plus petit en 1er
70
- //sinon return min(a,c), max(b,d)
71
- //res = a
72
- // return new MathSet();
73
- // }
74
- exclude(nb: number) {
75
- const rand = () => {
76
- let x;
77
- do {
78
- x = this.getRandomElement();
79
- } while (x.value === nb);
80
- return x;
81
- };
82
- return new MathSet(this.toTex() + `\\{${nb}\\}`, rand);
83
- }
84
-
85
- difference(set: DiscreteSet): MathSet {
86
- const rand = () => {
87
- let x;
88
- do {
89
- x = this.getRandomElement();
90
- } while (set.includes(x));
91
- return x;
92
- };
93
-
94
- return new MathSet(this.toTex() + `\\ ${set.toTex()}`, rand);
95
- }
96
-
97
- toTex(): string {
98
- return this.tex;
99
- }
100
-
101
- getRandomElement(
102
- precision: number = this.type === NumberType.Integer ? 0 : 2
103
- ): Nombre {
104
- if (this.min === -Infinity || this.max === Infinity)
105
- throw Error("Can't chose amongst infinity");
106
- let min =
107
- this.boundType === BoundType.OO || this.boundType === BoundType.OF
108
- ? this.min + EPSILON
109
- : this.min;
110
- let max =
111
- this.boundType === BoundType.OO || this.boundType === BoundType.FO
112
- ? this.max - EPSILON
113
- : this.max;
114
- const value = round(min + Math.random() * (max - this.min), precision);
115
- switch (this.type) {
116
- case NumberType.Integer:
117
- return new Integer(value);
118
- default:
119
- return new Real(value, value.toString());
120
- }
121
- }
122
- }
File without changes
@@ -1,11 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.MathSet = void 0;
4
- var MathSet = /** @class */ (function () {
5
- function MathSet(tex, getRandomElement) {
6
- this.tex = tex;
7
- this.getRandomElement = getRandomElement;
8
- }
9
- return MathSet;
10
- }());
11
- exports.MathSet = MathSet;
@@ -1,12 +0,0 @@
1
- import { Nombre } from "../numbers/nombre";
2
- import { DiscreteSet } from "./discreteSet";
3
- import { MathSetInterface } from "./mathSetInterface";
4
-
5
- export class MathSet implements MathSetInterface {
6
- tex: string;
7
- getRandomElement: () => Nombre;
8
- constructor(tex: string, getRandomElement: () => Nombre) {
9
- this.tex = tex;
10
- this.getRandomElement = getRandomElement;
11
- }
12
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
@@ -1,10 +0,0 @@
1
- import { Nombre } from "../numbers/nombre";
2
-
3
- export interface MathSetInterface {
4
- tex: string;
5
- getRandomElement: () => Nombre;
6
- // constructor(tex: string, getRandomElement: () => number) {
7
- // this.tex = tex;
8
- // this.getRandomElement = getRandomElement;
9
- // }
10
- }
@@ -1,117 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.latexParse = void 0;
4
- var functionNode_1 = require("../nodes/functions/functionNode");
5
- var node_1 = require("../nodes/node");
6
- var operatorNode_1 = require("../nodes/operators/operatorNode");
7
- function latexParse(node) {
8
- if (!node) {
9
- console.log("parsing a null node ???");
10
- return "";
11
- }
12
- switch (node.type) {
13
- case node_1.NodeType.variable:
14
- return node.tex;
15
- case node_1.NodeType.number:
16
- return node.tex;
17
- case node_1.NodeType.operator:
18
- var operatorNode = node;
19
- var rightTex = latexParse(operatorNode.rightChild);
20
- var leftTex = latexParse(operatorNode.leftChild);
21
- var leftChild = operatorNode.leftChild, rightChild = operatorNode.rightChild;
22
- switch (operatorNode.id) {
23
- case operatorNode_1.OperatorIds.add:
24
- return "".concat(leftTex, " ").concat(rightTex[0] === "-" ? "" : "+ ").concat(rightTex);
25
- case operatorNode_1.OperatorIds.substract: {
26
- var needBrackets = (rightChild.type === node_1.NodeType.operator &&
27
- [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(rightChild.id)) ||
28
- rightTex[0] === "-";
29
- if (needBrackets)
30
- rightTex = "(".concat(rightTex, ")");
31
- return "".concat(leftTex, " - ").concat(rightTex);
32
- }
33
- case operatorNode_1.OperatorIds.multiply: {
34
- if (leftChild.type === node_1.NodeType.operator) {
35
- if ([operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract, operatorNode_1.OperatorIds.divide].includes(leftChild.id))
36
- leftTex = "(".concat(leftTex, ")");
37
- }
38
- var needBrackets = rightTex[0] === "-";
39
- if (rightChild.type === node_1.NodeType.operator) {
40
- var operatorRightChild = rightChild;
41
- needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorRightChild.id));
42
- }
43
- if (needBrackets)
44
- rightTex = "(".concat(rightTex, ")");
45
- // permet de gérer le cas 3*2^x
46
- var showTimesSign = !isNaN(+rightTex[0]) || rightChild.type === node_1.NodeType.number;
47
- if (rightChild.type === node_1.NodeType.operator) {
48
- var operatorRightChild = rightChild;
49
- showTimesSign || (showTimesSign = [operatorNode_1.OperatorIds.fraction].includes(operatorRightChild.id));
50
- }
51
- return "".concat(leftTex).concat(showTimesSign ? "\\times " : "").concat(rightTex);
52
- }
53
- case operatorNode_1.OperatorIds.divide: {
54
- if (leftChild.type === node_1.NodeType.operator) {
55
- if ([operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract, operatorNode_1.OperatorIds.multiply].includes(leftChild.id))
56
- leftTex = "(".concat(leftTex, ")");
57
- }
58
- var needBrackets = rightTex[0] === "-";
59
- if (rightChild.type === node_1.NodeType.operator) {
60
- var operatorRightChild = rightChild;
61
- needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorRightChild.id));
62
- }
63
- if (needBrackets)
64
- rightTex = "(".concat(rightTex, ")");
65
- return "".concat(leftTex, " \\div ").concat(rightTex);
66
- }
67
- case operatorNode_1.OperatorIds.fraction: {
68
- return "\\frac{".concat(leftTex, "}{").concat(rightTex, "}");
69
- }
70
- case operatorNode_1.OperatorIds.power: {
71
- var needBrackets = leftTex[0] === "-";
72
- if (leftChild.type === node_1.NodeType.operator) {
73
- var childOperator = leftChild;
74
- needBrackets || (needBrackets = [
75
- operatorNode_1.OperatorIds.add,
76
- operatorNode_1.OperatorIds.substract,
77
- operatorNode_1.OperatorIds.multiply,
78
- operatorNode_1.OperatorIds.divide,
79
- operatorNode_1.OperatorIds.fraction,
80
- operatorNode_1.OperatorIds.power,
81
- ].includes(childOperator.id));
82
- }
83
- if (needBrackets)
84
- leftTex = "(".concat(leftTex, ")");
85
- return "".concat(leftTex, "^{").concat(rightTex, "}");
86
- }
87
- case operatorNode_1.OperatorIds.equal: {
88
- return "".concat(leftTex, " = ").concat(rightTex);
89
- }
90
- default:
91
- return node.tex;
92
- }
93
- case node_1.NodeType["function"]: {
94
- var functionNode = node;
95
- var child = functionNode.child;
96
- var childTex = latexParse(functionNode.child);
97
- switch (functionNode.id) {
98
- case functionNode_1.FunctionsIds.sqrt: {
99
- return "\\sqrt{".concat(childTex, "}");
100
- }
101
- case functionNode_1.FunctionsIds.opposite: {
102
- var needBrackets = childTex[0] === "-";
103
- if (child.type === node_1.NodeType.operator) {
104
- var operatorChild = child;
105
- needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorChild.id));
106
- }
107
- if (needBrackets)
108
- childTex = "(".concat(childTex, ")");
109
- return "-".concat(childTex);
110
- }
111
- }
112
- }
113
- default:
114
- return "";
115
- }
116
- }
117
- exports.latexParse = latexParse;
@@ -1,18 +0,0 @@
1
- import { Node, NodeType } from "../node";
2
-
3
- export enum FunctionsIds {
4
- opposite,
5
- sqrt,
6
- }
7
-
8
- export abstract class FunctionNode implements Node {
9
- id: FunctionsIds;
10
- child: Node;
11
- type = NodeType.function;
12
- tex: string;
13
- constructor(id: FunctionsIds, child: Node, tex: string) {
14
- this.id = id;
15
- this.child = child;
16
- this.tex = tex;
17
- }
18
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- exports.__esModule = true;
18
- exports.OppositeNode = void 0;
19
- var functionNode_1 = require("./functionNode");
20
- var OppositeNode = /** @class */ (function (_super) {
21
- __extends(OppositeNode, _super);
22
- function OppositeNode(child) {
23
- return _super.call(this, functionNode_1.FunctionsIds.opposite, child, "-") || this;
24
- }
25
- OppositeNode.prototype.toString = function () {
26
- return "-(".concat(this.child, ")");
27
- };
28
- return OppositeNode;
29
- }(functionNode_1.FunctionNode));
30
- exports.OppositeNode = OppositeNode;
@@ -1,12 +0,0 @@
1
- import { Node, NodeType } from "../node";
2
- import { OperatorNode } from "../operators/operatorNode";
3
- import { FunctionNode, FunctionsIds } from "./functionNode";
4
-
5
- export class OppositeNode extends FunctionNode {
6
- constructor(child: Node) {
7
- super(FunctionsIds.opposite, child, "-");
8
- }
9
- toString(): string {
10
- return `-(${this.child})`;
11
- }
12
- }