math-exercises 2.2.81 → 2.2.82

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 (101) hide show
  1. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType2.d.ts +4 -1
  2. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType2.d.ts.map +1 -1
  3. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType2.js +79 -30
  4. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType3.d.ts +4 -1
  5. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType3.d.ts.map +1 -1
  6. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType3.js +89 -39
  7. package/lib/exercises/math/calculLitteral/inequations/squareFunctionInequation.d.ts.map +1 -1
  8. package/lib/exercises/math/calculLitteral/inequations/squareFunctionInequation.js +37 -17
  9. package/lib/exercises/math/calculLitteral/simplifying/evaluateExpression.d.ts.map +1 -1
  10. package/lib/exercises/math/calculLitteral/simplifying/evaluateExpression.js +55 -15
  11. package/lib/exercises/math/derivation/derivative/convexityQuadrinomials.d.ts.map +1 -1
  12. package/lib/exercises/math/derivation/derivative/convexityQuadrinomials.js +9 -18
  13. package/lib/exercises/math/derivation/derivative/thirdDegreeFunctionVariation.d.ts.map +1 -1
  14. package/lib/exercises/math/derivation/derivative/thirdDegreeFunctionVariation.js +11 -11
  15. package/lib/exercises/math/functions/absolute/absolueValueInequationsSup.d.ts.map +1 -1
  16. package/lib/exercises/math/functions/absolute/absolueValueInequationsSup.js +10 -2
  17. package/lib/exercises/math/functions/absolute/absoluteValueInequations.d.ts.map +1 -1
  18. package/lib/exercises/math/functions/absolute/absoluteValueInequations.js +11 -4
  19. package/lib/exercises/math/functions/basics/graphicEquation.d.ts.map +1 -1
  20. package/lib/exercises/math/functions/basics/graphicEquation.js +46 -28
  21. package/lib/exercises/math/functions/basics/graphicInequation.d.ts.map +1 -1
  22. package/lib/exercises/math/functions/basics/graphicInequation.js +0 -1
  23. package/lib/exercises/math/functions/basics/graphicInequationAffine.d.ts.map +1 -1
  24. package/lib/exercises/math/functions/basics/graphicInequationAffine.js +10 -3
  25. package/lib/exercises/math/functions/basics/twoFunctionsInequation.d.ts.map +1 -1
  26. package/lib/exercises/math/functions/basics/twoFunctionsInequation.js +74 -58
  27. package/lib/exercises/math/functions/logarithm/log10Simplifying.d.ts.map +1 -1
  28. package/lib/exercises/math/functions/logarithm/log10Simplifying.js +1 -0
  29. package/lib/exercises/math/functions/square/squareImageInterval.d.ts.map +1 -1
  30. package/lib/exercises/math/functions/square/squareImageInterval.js +13 -4
  31. package/lib/exercises/math/functions/trinoms/secondDegreeInequation.d.ts.map +1 -1
  32. package/lib/exercises/math/functions/trinoms/secondDegreeInequation.js +10 -6
  33. package/lib/exercises/math/functions/trinoms/trinomSignFromRoots.d.ts.map +1 -1
  34. package/lib/exercises/math/functions/trinoms/trinomSignFromRoots.js +12 -6
  35. package/lib/exercises/math/geometry/convexity/convexityQuadrinomialsGeo.d.ts.map +1 -1
  36. package/lib/exercises/math/geometry/convexity/convexityQuadrinomialsGeo.js +9 -14
  37. package/lib/exercises/math/matrices/matrixInversibilityDomain.d.ts.map +1 -1
  38. package/lib/exercises/math/matrices/matrixInversibilityDomain.js +15 -2
  39. package/lib/exercises/math/probaStat/binomial/binomialInequation.d.ts.map +1 -1
  40. package/lib/exercises/math/python/pyForLoop1Exercise.d.ts.map +1 -1
  41. package/lib/exercises/math/sequences/genericSequenceVariations.d.ts.map +1 -1
  42. package/lib/exercises/math/sets/intervals/inequalityToInterval.d.ts +2 -4
  43. package/lib/exercises/math/sets/intervals/inequalityToInterval.d.ts.map +1 -1
  44. package/lib/exercises/math/sets/intervals/inequalityToInterval.js +28 -25
  45. package/lib/exercises/math/sets/intervals/intervalToInequality.d.ts +2 -4
  46. package/lib/exercises/math/sets/intervals/intervalToInequality.d.ts.map +1 -1
  47. package/lib/exercises/math/sets/intervals/intervalToInequality.js +40 -78
  48. package/lib/exercises/math/sets/intervals/intervalsIntersection.d.ts +3 -7
  49. package/lib/exercises/math/sets/intervals/intervalsIntersection.d.ts.map +1 -1
  50. package/lib/exercises/math/sets/intervals/intervalsIntersection.js +91 -31
  51. package/lib/exercises/math/sets/intervals/intervalsUnion.d.ts +3 -7
  52. package/lib/exercises/math/sets/intervals/intervalsUnion.d.ts.map +1 -1
  53. package/lib/exercises/math/sets/intervals/intervalsUnion.js +58 -19
  54. package/lib/exercises/pc/index.d.ts +4 -0
  55. package/lib/exercises/pc/index.d.ts.map +1 -1
  56. package/lib/exercises/pc/index.js +4 -6
  57. package/lib/exercises/vea/equationVEA.js +2 -2
  58. package/lib/geogebra/lagrange.d.ts.map +1 -1
  59. package/lib/geogebra/spline.d.ts.map +1 -1
  60. package/lib/index.d.ts +38 -20
  61. package/lib/index.d.ts.map +1 -1
  62. package/lib/math/geometry/point.d.ts.map +1 -1
  63. package/lib/math/inequations/inequation.d.ts +1 -1
  64. package/lib/math/inequations/inequation.d.ts.map +1 -1
  65. package/lib/math/numbers/integer/integer.d.ts.map +1 -1
  66. package/lib/math/numbers/rationals/rational.d.ts +2 -3
  67. package/lib/math/numbers/rationals/rational.d.ts.map +1 -1
  68. package/lib/math/polynomials/trinom.d.ts +2 -4
  69. package/lib/math/polynomials/trinom.d.ts.map +1 -1
  70. package/lib/playground.d.ts.map +1 -1
  71. package/lib/playground.js +4 -4
  72. package/lib/tree/nodes/equations/equationSolutionNode.d.ts +0 -1
  73. package/lib/tree/nodes/equations/equationSolutionNode.d.ts.map +1 -1
  74. package/lib/tree/nodes/equations/equationSolutionNode.js +0 -3
  75. package/lib/tree/nodes/inequations/inequationNode.d.ts +2 -1
  76. package/lib/tree/nodes/inequations/inequationNode.d.ts.map +1 -1
  77. package/lib/tree/nodes/inequations/inequationNode.js +4 -3
  78. package/lib/tree/nodes/inequations/inequationSolutionNode.d.ts +0 -1
  79. package/lib/tree/nodes/inequations/inequationSolutionNode.d.ts.map +1 -1
  80. package/lib/tree/nodes/inequations/inequationSolutionNode.js +0 -3
  81. package/lib/tree/nodes/numbers/numberNode.d.ts +1 -1
  82. package/lib/tree/nodes/operators/multiplyNode.d.ts.map +1 -1
  83. package/lib/tree/nodes/operators/multiplyNode.js +6 -1
  84. package/lib/tree/nodes/sets/closure.d.ts +5 -0
  85. package/lib/tree/nodes/sets/closure.d.ts.map +1 -1
  86. package/lib/tree/nodes/sets/closure.js +32 -0
  87. package/lib/tree/nodes/sets/discreteSetNode.d.ts +4 -4
  88. package/lib/tree/nodes/sets/discreteSetNode.d.ts.map +1 -1
  89. package/lib/tree/nodes/sets/discreteSetNode.js +3 -4
  90. package/lib/tree/nodes/sets/intervalNode.d.ts +13 -1
  91. package/lib/tree/nodes/sets/intervalNode.d.ts.map +1 -1
  92. package/lib/tree/nodes/sets/intervalNode.js +154 -3
  93. package/lib/tree/parsers/discreteSetParser.d.ts +2 -2
  94. package/lib/tree/parsers/discreteSetParser.d.ts.map +1 -1
  95. package/lib/tree/parsers/discreteSetParser.js +2 -1
  96. package/lib/tree/parsers/equationSolutionParser.js +1 -1
  97. package/lib/tree/parsers/powerParser.d.ts +1 -1
  98. package/lib/tree/parsers/rationalParser.d.ts +1 -1
  99. package/lib/tree/parsers/unionIntervalParser.d.ts.map +1 -1
  100. package/lib/tree/parsers/unionIntervalParser.js +3 -1
  101. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"intervalNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/sets/intervalNode.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO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a,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;gBAEf,CAAC,EAAE,aAAa,EAChB,CAAC,EAAE,aAAa,EAChB,OAAO,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,WAAW;IAWpB,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW;IAMjC,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW;IAoBpC,YAAY,CAAC,WAAW,CAAC,EAAE,aAAa;IA4BxC,YAAY;IAIZ,MAAM,CAAC,CAAC,EAAE,YAAY;IAMtB,iBAAiB;IAGjB,qBAAqB;IAGrB,sBAAsB;IAGtB,wBAAwB;IAYxB,YAAY;IAkCZ,KAAK;IAWL,SAAS,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE;IAOvC,aAAa,IAAI,uBAAuB;IAUxC,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO;IAiB7C,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe;IAS/B,YAAY;IAGZ,aAAa;IAGb,QAAQ,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO;IAanC,UAAU,CAAC,QAAQ,EAAE,YAAY;IAEjC,YAAY,CAAC,QAAQ,EAAE,YAAY;IAwDnC,KAAK,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,GAAG,iBAAiB;CAkDhE"}
@@ -1,20 +1,84 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IntervalNode = exports.isIntervalNode = void 0;
3
+ exports.IntervalNode = exports.IntervalNodeConstructor = exports.isIntervalNode = void 0;
4
+ const randint_1 = require("../../../math/utils/random/randint");
5
+ const coinFlip_1 = require("../../../utils/alea/coinFlip");
4
6
  const random_1 = require("../../../utils/alea/random");
5
7
  const cartesianProducts_1 = require("../../../utils/arrays/cartesianProducts");
6
8
  const inequationNode_1 = require("../inequations/inequationNode");
7
9
  const node_1 = require("../node");
10
+ const nodeConstructor_1 = require("../nodeConstructor");
8
11
  const constantNode_1 = require("../numbers/constantNode");
9
12
  const infiniteNode_1 = require("../numbers/infiniteNode");
10
13
  const variableNode_1 = require("../variables/variableNode");
11
14
  const closure_1 = require("./closure");
15
+ const discreteSetNode_1 = require("./discreteSetNode");
12
16
  const setNode_1 = require("./setNode");
13
17
  const unionIntervalNode_1 = require("./unionIntervalNode");
14
18
  function isIntervalNode(a) {
15
19
  return (0, setNode_1.isSetNode)(a) && a.id === setNode_1.SetIds.interval;
16
20
  }
17
21
  exports.isIntervalNode = isIntervalNode;
22
+ class IntervalNodeConstructor {
23
+ static random() {
24
+ const randType = (0, randint_1.randint)(0, 6);
25
+ let a, b;
26
+ let min, max, closure;
27
+ switch (randType) {
28
+ case 0:
29
+ min = infiniteNode_1.MinusInfinityNode;
30
+ max = (0, randint_1.randint)(-10, 10).toTree();
31
+ closure = (0, coinFlip_1.coinFlip)() ? closure_1.ClosureType.OF : closure_1.ClosureType.OO;
32
+ break;
33
+ case 1:
34
+ min = (0, randint_1.randint)(-10, 10).toTree();
35
+ max = infiniteNode_1.PlusInfinityNode;
36
+ closure = (0, coinFlip_1.coinFlip)() ? closure_1.ClosureType.OO : closure_1.ClosureType.FO;
37
+ break;
38
+ case 2:
39
+ a = (0, randint_1.randint)(-10, 10);
40
+ min = a.toTree();
41
+ max = (0, randint_1.randint)(a + 1, a + 10).toTree();
42
+ closure = closure_1.ClosureType.FF;
43
+ break;
44
+ case 3:
45
+ a = (0, randint_1.randint)(-10, 10);
46
+ min = a.toTree();
47
+ max = (0, randint_1.randint)(a + 1, a + 10).toTree();
48
+ closure = closure_1.ClosureType.OF;
49
+ break;
50
+ case 4:
51
+ a = (0, randint_1.randint)(-10, 10);
52
+ min = a.toTree();
53
+ max = (0, randint_1.randint)(a + 1, a + 10).toTree();
54
+ closure = closure_1.ClosureType.FO;
55
+ break;
56
+ case 5:
57
+ default:
58
+ a = (0, randint_1.randint)(-10, 10);
59
+ min = a.toTree();
60
+ max = (0, randint_1.randint)(a + 1, a + 10).toTree();
61
+ closure = closure_1.ClosureType.OO;
62
+ break;
63
+ }
64
+ return new IntervalNode(min, max, closure);
65
+ }
66
+ static differentRandoms(nb) {
67
+ const res = [];
68
+ for (let i = 0; i < nb; i++) {
69
+ let interval;
70
+ do {
71
+ interval = this.random();
72
+ } while (res.some((int) => int.equals(interval)));
73
+ res.push(this.random());
74
+ }
75
+ return res;
76
+ }
77
+ static fromIdentifiers(ids) {
78
+ return new IntervalNode((0, nodeConstructor_1.reifyAlgebraic)(ids.leftChild), (0, nodeConstructor_1.reifyAlgebraic)(ids.rightChild), ids.closure, ids.opts);
79
+ }
80
+ }
81
+ exports.IntervalNodeConstructor = IntervalNodeConstructor;
18
82
  class IntervalNode {
19
83
  constructor(a, b, closure, opts) {
20
84
  this.type = node_1.NodeType.set;
@@ -59,8 +123,8 @@ class IntervalNode {
59
123
  toMathString() {
60
124
  return this.toTex();
61
125
  }
62
- toMathjs() {
63
- return this.toTex();
126
+ equals(i) {
127
+ return (i.a.equals(this.a) && i.b.equals(this.b) && i.closure === this.closure);
64
128
  }
65
129
  toReversedClosure() {
66
130
  return new IntervalNode(this.a, this.b, closure_1.Closure.reverse(this.closure));
@@ -140,5 +204,92 @@ class IntervalNode {
140
204
  simplify(opts) {
141
205
  return new IntervalNode(this.a.simplify(opts), this.b.simplify(opts), this.closure, this.opts);
142
206
  }
207
+ isLeftClosed() {
208
+ return this.closure === closure_1.ClosureType.FF || this.closure === closure_1.ClosureType.FO;
209
+ }
210
+ isRightClosed() {
211
+ return this.closure === closure_1.ClosureType.FF || this.closure === closure_1.ClosureType.OF;
212
+ }
213
+ includes(a) {
214
+ const ev = a.evaluate();
215
+ const aEv = this.a.evaluate();
216
+ const bEv = this.b.evaluate();
217
+ if (ev === Number.NEGATIVE_INFINITY)
218
+ return aEv === Number.NEGATIVE_INFINITY;
219
+ if (ev === Number.POSITIVE_INFINITY)
220
+ return bEv === Number.POSITIVE_INFINITY;
221
+ if (Math.abs(ev - aEv) < 0.0000000001)
222
+ return this.isLeftClosed();
223
+ if (Math.abs(ev - bEv) < 0.0000000001)
224
+ return this.isRightClosed();
225
+ return ev > aEv && ev < bEv;
226
+ }
227
+ isDisjoint(otherInt) { }
228
+ intersection(otherInt) {
229
+ const [thisA, thisB] = [this.a.evaluate(), this.b.evaluate()];
230
+ const [otherA, otherB] = [otherInt.a.evaluate(), otherInt.b.evaluate()];
231
+ const ordered = thisA < otherA ? [this, otherInt] : [otherInt, this];
232
+ const orderedEv = ordered.map((e) => {
233
+ return [e.a.evaluate(), e.b.evaluate()];
234
+ });
235
+ const orderedBrackets = ordered.map((int) => closure_1.Closure.toBrackets(int.closure));
236
+ if (ordered[0].includes(ordered[1].a) ||
237
+ Math.abs(thisA - otherA) < 0.0000000001) {
238
+ if (Math.abs(orderedEv[0][1] - orderedEv[1][0]) < 0.0000000001) {
239
+ return new discreteSetNode_1.DiscreteSetNode([ordered[1].a]);
240
+ }
241
+ let leftBracket = "[";
242
+ if (Math.abs(thisA - otherA) < 0.0000000001) {
243
+ leftBracket = closure_1.Closure.getMostLeftStrict(orderedBrackets[0][0], orderedBrackets[1][0]);
244
+ }
245
+ else
246
+ leftBracket = orderedBrackets[1][0];
247
+ let rightBracket = "[";
248
+ if (Math.abs(thisB - otherB) < 0.0000000001) {
249
+ rightBracket = closure_1.Closure.getMostRightStrict(orderedBrackets[0][1], orderedBrackets[1][1]);
250
+ return new IntervalNode(ordered[1].a, ordered[1].b, closure_1.Closure.fromBrackets(leftBracket, rightBracket));
251
+ }
252
+ else {
253
+ const rightBornIndex = ordered[0].b.evaluate() < ordered[1].b.evaluate() ? 0 : 1;
254
+ const right = ordered[rightBornIndex].b;
255
+ rightBracket = orderedBrackets[rightBornIndex][1];
256
+ return new IntervalNode(ordered[1].a, right, closure_1.Closure.fromBrackets(leftBracket, rightBracket));
257
+ }
258
+ }
259
+ else {
260
+ return discreteSetNode_1.EmptySet;
261
+ }
262
+ }
263
+ union(otherInt) {
264
+ const [thisA, thisB] = [this.a.evaluate(), this.b.evaluate()];
265
+ const [otherA, otherB] = [otherInt.a.evaluate(), otherInt.b.evaluate()];
266
+ const ordered = thisA < otherA ? [this, otherInt] : [otherInt, this];
267
+ const orderedBrackets = ordered.map((int) => closure_1.Closure.toBrackets(int.closure));
268
+ if (ordered[0].includes(ordered[1].a) ||
269
+ ordered[1].includes(ordered[0].b) ||
270
+ ordered[1].includes(ordered[0].a) ||
271
+ Math.abs(thisA - otherA) < 0.0000000001) {
272
+ let leftBracket = "[";
273
+ if (Math.abs(thisA - otherA) < 0.0000000001) {
274
+ leftBracket = closure_1.Closure.getLessLeftStrict(orderedBrackets[0][0], orderedBrackets[1][0]);
275
+ }
276
+ else
277
+ leftBracket = orderedBrackets[0][0];
278
+ let rightBracket = "[";
279
+ if (Math.abs(thisB - otherB) < 0.0000000001) {
280
+ rightBracket = closure_1.Closure.getLessRightStrict(orderedBrackets[0][1], orderedBrackets[1][1]);
281
+ return new IntervalNode(ordered[0].a, ordered[1].b, closure_1.Closure.fromBrackets(leftBracket, rightBracket));
282
+ }
283
+ else {
284
+ const rightBornIndex = ordered[0].b.evaluate() > ordered[1].b.evaluate() ? 0 : 1;
285
+ const right = ordered[rightBornIndex].b;
286
+ rightBracket = orderedBrackets[rightBornIndex][1];
287
+ return new IntervalNode(ordered[0].a, right, closure_1.Closure.fromBrackets(leftBracket, rightBracket));
288
+ }
289
+ }
290
+ else {
291
+ return new unionIntervalNode_1.UnionIntervalNode([ordered[0], ordered[1]], this.opts);
292
+ }
293
+ }
143
294
  }
144
295
  exports.IntervalNode = IntervalNode;
@@ -1,3 +1,3 @@
1
- import { AlgebraicNode } from "../nodes/algebraicNode";
2
- export declare const discreteSetParser: (str: string) => false | AlgebraicNode[];
1
+ import { DiscreteSetNode } from "../nodes/sets/discreteSetNode";
2
+ export declare const discreteSetParser: (str: string) => false | DiscreteSetNode;
3
3
  //# sourceMappingURL=discreteSetParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discreteSetParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/discreteSetParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,wBAAwB,CAAC;AAMxE,eAAO,MAAM,iBAAiB,QAAS,MAAM,4BAe5C,CAAC"}
1
+ {"version":3,"file":"discreteSetParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/discreteSetParser.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAIhE,eAAO,MAAM,iBAAiB,QAAS,MAAM,4BAe5C,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.discreteSetParser = void 0;
4
+ const discreteSetNode_1 = require("../nodes/sets/discreteSetNode");
4
5
  const latexParser_1 = require("./latexParser");
5
6
  const discreteSetParser = (str) => {
6
7
  try {
@@ -14,7 +15,7 @@ const discreteSetParser = (str) => {
14
15
  const elements = formated.split(";").map((e) => (0, latexParser_1.parseAlgebraic)(e));
15
16
  if (elements.some((e) => !e))
16
17
  return false;
17
- return elements;
18
+ return new discreteSetNode_1.DiscreteSetNode(elements);
18
19
  }
19
20
  catch (err) {
20
21
  return false;
@@ -17,7 +17,7 @@ const equationSolutionParser = (str, variable = "x") => {
17
17
  : undefined;
18
18
  if (varNode === undefined)
19
19
  return false;
20
- if (children[varNode].name !== "x")
20
+ if (children[varNode].name !== variable)
21
21
  return false;
22
22
  const scalar = children[(varNode + 1) % 2];
23
23
  if (!(0, algebraicNode_1.isAlgebraicNode)(scalar) || !scalar.isNumeric)
@@ -1,2 +1,2 @@
1
- export declare const powerParser: (ans: string) => false | import("../nodes/operators/fractionNode").FractionNode | import("../nodes/functions/sqrtNode").SqrtNode | import("../nodes/operators/powerNode").PowerNode;
1
+ export declare const powerParser: (ans: string) => false | import("../nodes/functions/sqrtNode").SqrtNode | import("../nodes/operators/powerNode").PowerNode | import("../nodes/operators/fractionNode").FractionNode;
2
2
  //# sourceMappingURL=powerParser.d.ts.map
@@ -1,3 +1,3 @@
1
1
  import { FractionNode } from "../nodes/operators/fractionNode";
2
- export declare const rationalParser: (ans: string) => false | import("../nodes/numbers/constantNode").ConstantNode | import("../nodes/numbers/numberNode").NumberNode | FractionNode | import("../nodes/functions/oppositeNode").OppositeNode<import("../nodes/algebraicNode").AlgebraicNode>;
2
+ export declare const rationalParser: (ans: string) => false | import("../nodes/numbers/constantNode").ConstantNode | import("../nodes/numbers/numberNode").NumberNode | import("../nodes/functions/oppositeNode").OppositeNode<import("../nodes/algebraicNode").AlgebraicNode> | FractionNode;
3
3
  //# sourceMappingURL=rationalParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unionIntervalParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/unionIntervalParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAIpE,KAAK,IAAI,GAAG;IACV,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AACF,eAAO,MAAM,mBAAmB,QAAS,MAAM,SAAS,IAAI,6CAe3D,CAAC"}
1
+ {"version":3,"file":"unionIntervalParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/unionIntervalParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAIpE,KAAK,IAAI,GAAG;IACV,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AACF,eAAO,MAAM,mBAAmB,QAAS,MAAM,SAAS,IAAI,6CAmB3D,CAAC"}
@@ -17,7 +17,9 @@ const unionIntervalParser = (ans, opts) => {
17
17
  return false;
18
18
  if (intervals.length === 1)
19
19
  return intervals[0];
20
- return new unionIntervalNode_1.UnionIntervalNode(intervals);
20
+ return new unionIntervalNode_1.UnionIntervalNode(intervals.sort((a, b) => {
21
+ return a.a.evaluate() - b.a.evaluate();
22
+ }));
21
23
  }
22
24
  catch (err) {
23
25
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "math-exercises",
3
- "version": "2.2.81",
3
+ "version": "2.2.82",
4
4
  "description": "Math exercises generator for middle school and high school",
5
5
  "main": "lib/index.js",
6
6
  "files": [