math-exercises 1.1.0 → 1.2.0

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 (124) hide show
  1. package/package.json +2 -2
  2. package/src/exercises/calcul/addAndSub.js +19 -13
  3. package/src/exercises/calcul/addAndSub.ts +31 -23
  4. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -0
  5. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.ts +38 -0
  6. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.js +31 -0
  7. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.ts +32 -0
  8. package/src/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -0
  9. package/src/exercises/calcul/fractions/fractionAndIntegerSum.ts +31 -0
  10. package/src/exercises/calcul/fractions/fractionsDivision.js +29 -0
  11. package/src/exercises/calcul/fractions/fractionsDivision.ts +30 -0
  12. package/src/exercises/calcul/fractions/fractionsProduct.js +29 -0
  13. package/src/exercises/calcul/fractions/fractionsProduct.ts +29 -0
  14. package/src/exercises/calcul/fractions/fractionsSum.js +29 -0
  15. package/src/exercises/calcul/fractions/fractionsSum.ts +28 -0
  16. package/src/exercises/calcul/fractions/simplifyFraction.js +25 -0
  17. package/src/exercises/calcul/fractions/simplifyFraction.ts +24 -0
  18. package/src/exercises/calcul/operationsPriorities.js +89 -0
  19. package/src/exercises/calcul/operationsPriorities.ts +118 -0
  20. package/src/exercises/calcul/rounding/roundToUnit.js +70 -0
  21. package/src/exercises/calcul/rounding/roundToUnit.ts +68 -0
  22. package/src/exercises/calculLitteral/distributivity/allIdentities.js +2 -0
  23. package/src/exercises/calculLitteral/distributivity/allIdentities.ts +2 -0
  24. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.js +3 -3
  25. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.ts +2 -0
  26. package/src/exercises/calculLitteral/distributivity/firstIdentity.js +2 -0
  27. package/src/exercises/calculLitteral/distributivity/firstIdentity.ts +2 -0
  28. package/src/exercises/calculLitteral/distributivity/secondIdentity.js +3 -3
  29. package/src/exercises/calculLitteral/distributivity/secondIdentity.ts +2 -0
  30. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.js +3 -3
  31. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.ts +2 -0
  32. package/src/exercises/calculLitteral/distributivity/thirdIdentity.js +4 -2
  33. package/src/exercises/calculLitteral/distributivity/thirdIdentity.ts +2 -0
  34. package/src/exercises/calculLitteral/equation/equationType1Exercise.js +3 -3
  35. package/src/exercises/calculLitteral/equation/equationType1Exercise.ts +4 -5
  36. package/src/exercises/calculLitteral/equation/equationType2Exercise.js +3 -3
  37. package/src/exercises/calculLitteral/equation/equationType2Exercise.ts +5 -5
  38. package/src/exercises/calculLitteral/equation/equationType3Exercise.js +3 -3
  39. package/src/exercises/calculLitteral/equation/equationType3Exercise.ts +5 -5
  40. package/src/exercises/calculLitteral/equation/equationType4Exercise.js +3 -3
  41. package/src/exercises/calculLitteral/equation/equationType4Exercise.ts +7 -12
  42. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.js +4 -9
  43. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.ts +3 -6
  44. package/src/exercises/calculLitteral/reduction.ts +27 -0
  45. package/src/exercises/exercise.ts +2 -0
  46. package/src/exercises/exercises.js +83 -0
  47. package/src/exercises/exercises.ts +58 -0
  48. package/src/exercises/powers/powersDivision.js +46 -0
  49. package/src/exercises/powers/powersDivision.ts +51 -0
  50. package/src/exercises/powers/powersOfTenToDecimal.js +33 -0
  51. package/src/exercises/powers/powersOfTenToDecimal.ts +37 -0
  52. package/src/exercises/powers/powersPower.js +45 -0
  53. package/src/exercises/powers/powersPower.ts +55 -0
  54. package/src/exercises/powers/powersProduct.js +46 -0
  55. package/src/exercises/powers/powersProduct.ts +51 -0
  56. package/src/exercises/powers/scientificToDecimal.js +38 -0
  57. package/src/exercises/powers/scientificToDecimal.ts +44 -0
  58. package/src/exercises/squareRoots/simpifySquareRoot.js +2 -3
  59. package/src/exercises/squareRoots/simpifySquareRoot.ts +2 -0
  60. package/src/index.js +8 -8
  61. package/src/index.ts +5 -16
  62. package/src/mathutils/arithmetic/coprimesOf.js +13 -0
  63. package/src/mathutils/arithmetic/coprimesOf.ts +9 -0
  64. package/src/mathutils/arithmetic/dividersOf.ts +7 -0
  65. package/src/mathutils/arithmetic/lcd.js +12 -0
  66. package/src/mathutils/arithmetic/lcd.ts +7 -0
  67. package/src/mathutils/arithmetic/nonCoprimesOf.ts +9 -0
  68. package/src/mathutils/arithmetic/nonDividersOf.ts +12 -0
  69. package/src/mathutils/decimals/decimalPartLengthOf.ts +10 -0
  70. package/src/mathutils/random/randint.js +11 -2
  71. package/src/mathutils/random/randint.ts +10 -2
  72. package/src/numbers/decimals/decimal.js +144 -0
  73. package/src/numbers/decimals/decimal.ts +140 -0
  74. package/src/numbers/integer/integer.js +61 -4
  75. package/src/numbers/integer/integer.ts +58 -7
  76. package/src/numbers/integer/power.js +53 -0
  77. package/src/numbers/integer/power.ts +49 -0
  78. package/src/numbers/nombre.js +3 -2
  79. package/src/numbers/nombre.ts +2 -0
  80. package/src/numbers/rationals/rational.js +96 -10
  81. package/src/numbers/rationals/rational.ts +81 -15
  82. package/src/numbers/reals/real.js +2 -0
  83. package/src/numbers/reals/real.ts +3 -1
  84. package/src/numbers/reals/squareRoot.ts +3 -10
  85. package/src/polynomials/affine.ts +2 -6
  86. package/src/polynomials/polynomial.js +4 -13
  87. package/src/polynomials/polynomial.ts +8 -25
  88. package/src/tree/latexParser/latexParse.js +81 -34
  89. package/src/tree/latexParser/latexParse.ts +85 -39
  90. package/src/tree/nodes/functions/functionNode.js +19 -0
  91. package/src/tree/nodes/functions/functionNode.ts +18 -0
  92. package/src/tree/nodes/functions/oppositeNode.js +30 -0
  93. package/src/tree/nodes/functions/oppositeNode.ts +12 -0
  94. package/src/tree/nodes/functions/sqrtNode.js +24 -9
  95. package/src/tree/nodes/functions/sqrtNode.ts +5 -9
  96. package/src/tree/nodes/node.ts +1 -3
  97. package/src/tree/nodes/numbers/numberNode.js +3 -6
  98. package/src/tree/nodes/numbers/numberNode.ts +4 -7
  99. package/src/tree/nodes/operators/addNode.js +23 -8
  100. package/src/tree/nodes/operators/addNode.ts +3 -7
  101. package/src/tree/nodes/operators/divideNode.js +21 -9
  102. package/src/tree/nodes/operators/divideNode.ts +4 -11
  103. package/src/tree/nodes/operators/equalNode.js +20 -8
  104. package/src/tree/nodes/operators/equalNode.ts +3 -9
  105. package/src/tree/nodes/operators/fractionNode.js +34 -0
  106. package/src/tree/nodes/operators/fractionNode.ts +16 -0
  107. package/src/tree/nodes/operators/multiplyNode.js +20 -8
  108. package/src/tree/nodes/operators/multiplyNode.ts +3 -9
  109. package/src/tree/nodes/operators/operatorNode.js +35 -0
  110. package/src/tree/nodes/operators/operatorNode.ts +35 -2
  111. package/src/tree/nodes/operators/powerNode.js +20 -8
  112. package/src/tree/nodes/operators/powerNode.ts +3 -8
  113. package/src/tree/nodes/operators/substractNode.js +20 -8
  114. package/src/tree/nodes/operators/substractNode.ts +3 -9
  115. package/src/tree/nodes/variables/variableNode.js +1 -4
  116. package/src/tree/nodes/variables/variableNode.ts +4 -7
  117. package/src/utils/coin.js +7 -0
  118. package/src/utils/coin.ts +3 -0
  119. package/src/utils/shuffle.js +15 -4
  120. package/src/utils/shuffle.ts +7 -5
  121. package/src/exercises/calcul/priority.ts +0 -33
  122. package/src/expression/expression.js +0 -9
  123. package/src/expression/expression.ts +0 -13
  124. package/src/tree/nodes/operators/oppositeNode.ts +0 -17
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.FunctionNode = exports.FunctionsIds = void 0;
4
+ var node_1 = require("../node");
5
+ var FunctionsIds;
6
+ (function (FunctionsIds) {
7
+ FunctionsIds[FunctionsIds["opposite"] = 0] = "opposite";
8
+ FunctionsIds[FunctionsIds["sqrt"] = 1] = "sqrt";
9
+ })(FunctionsIds = exports.FunctionsIds || (exports.FunctionsIds = {}));
10
+ var FunctionNode = /** @class */ (function () {
11
+ function FunctionNode(id, child, tex) {
12
+ this.type = node_1.NodeType["function"];
13
+ this.id = id;
14
+ this.child = child;
15
+ this.tex = tex;
16
+ }
17
+ return FunctionNode;
18
+ }());
19
+ exports.FunctionNode = FunctionNode;
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,30 @@
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;
@@ -0,0 +1,12 @@
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
+ }
@@ -1,18 +1,33 @@
1
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
+ })();
2
17
  exports.__esModule = true;
3
18
  exports.SqrtNode = void 0;
4
19
  var node_1 = require("../node");
5
- var SqrtNode = /** @class */ (function () {
6
- function SqrtNode(leftChild) {
7
- this.type = node_1.NodeType["function"];
8
- this.id = "sqrt";
9
- this.tex = "\\sqrt";
10
- this.leftChild = leftChild;
11
- this.rightChild = null;
20
+ var functionNode_1 = require("./functionNode");
21
+ var SqrtNode = /** @class */ (function (_super) {
22
+ __extends(SqrtNode, _super);
23
+ function SqrtNode(child) {
24
+ var _this = _super.call(this, functionNode_1.FunctionsIds.sqrt, child, "\\sqrt") || this;
25
+ _this.type = node_1.NodeType["function"];
26
+ return _this;
12
27
  }
13
28
  SqrtNode.prototype.toString = function () {
14
- return "sqrt(".concat(this.leftChild, ")");
29
+ return "sqrt(".concat(this.child, ")");
15
30
  };
16
31
  return SqrtNode;
17
- }());
32
+ }(functionNode_1.FunctionNode));
18
33
  exports.SqrtNode = SqrtNode;
@@ -1,16 +1,12 @@
1
1
  import { Node, NodeType } from "../node";
2
+ import { FunctionNode, FunctionsIds } from "./functionNode";
2
3
 
3
- export class SqrtNode implements Node {
4
- leftChild: Node;
5
- rightChild: null;
4
+ export class SqrtNode extends FunctionNode {
6
5
  type: NodeType = NodeType.function;
7
- id: string = "sqrt";
8
- tex = "\\sqrt";
9
- constructor(leftChild: Node) {
10
- this.leftChild = leftChild;
11
- this.rightChild = null;
6
+ constructor(child: Node) {
7
+ super(FunctionsIds.sqrt, child, "\\sqrt");
12
8
  }
13
9
  toString(): string {
14
- return `sqrt(${this.leftChild})`;
10
+ return `sqrt(${this.child})`;
15
11
  }
16
12
  }
@@ -8,7 +8,5 @@ export enum NodeType {
8
8
  export interface Node {
9
9
  type: NodeType;
10
10
  tex: string;
11
- id: string;
12
- leftChild: Node | null;
13
- rightChild: Node | null;
11
+ toString: () => string;
14
12
  }
@@ -3,13 +3,10 @@ exports.__esModule = true;
3
3
  exports.NumberNode = void 0;
4
4
  var node_1 = require("../node");
5
5
  var NumberNode = /** @class */ (function () {
6
- function NumberNode(value) {
7
- this.id = "number";
8
- this.leftChild = null;
9
- this.rightChild = null;
10
- this.value = value;
11
- this.tex = value + "";
6
+ function NumberNode(value, tex) {
12
7
  this.type = node_1.NodeType.number;
8
+ this.value = value;
9
+ this.tex = tex || value + "";
13
10
  }
14
11
  NumberNode.prototype.toString = function () {
15
12
  return "".concat(this.tex);
@@ -3,14 +3,11 @@ import { Node, NodeType } from "../node";
3
3
  export class NumberNode implements Node {
4
4
  tex: string;
5
5
  value: number;
6
- type: NodeType;
7
- id = "number";
8
- leftChild = null;
9
- rightChild = null;
10
- constructor(value: number) {
6
+ type: NodeType = NodeType.number;
7
+
8
+ constructor(value: number, tex?: string) {
11
9
  this.value = value;
12
- this.tex = value + "";
13
- this.type = NodeType.number;
10
+ this.tex = tex || value + "";
14
11
  }
15
12
 
16
13
  toString(): string {
@@ -1,18 +1,33 @@
1
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
+ })();
2
17
  exports.__esModule = true;
3
18
  exports.AddNode = void 0;
4
- var node_1 = require("../node");
5
- var AddNode = /** @class */ (function () {
19
+ var operatorNode_1 = require("./operatorNode");
20
+ var AddNode = /** @class */ (function (_super) {
21
+ __extends(AddNode, _super);
6
22
  function AddNode(leftChild, rightChild) {
7
- this.type = node_1.NodeType.operator;
8
- this.id = "add";
9
- this.tex = "+";
10
- this.leftChild = leftChild;
11
- this.rightChild = rightChild;
23
+ var _this = _super.call(this, operatorNode_1.OperatorIds.add, leftChild, rightChild, true, "+") || this;
24
+ _this.leftChild = leftChild;
25
+ _this.rightChild = rightChild;
26
+ return _this;
12
27
  }
13
28
  AddNode.prototype.toString = function () {
14
29
  return "".concat(this.leftChild, " + ").concat(this.rightChild);
15
30
  };
16
31
  return AddNode;
17
- }());
32
+ }(operatorNode_1.OperatorNode));
18
33
  exports.AddNode = AddNode;
@@ -1,13 +1,9 @@
1
1
  import { Node, NodeType } from "../node";
2
- import { OperatorNode } from "./operatorNode";
2
+ import { OperatorIds, OperatorNode } from "./operatorNode";
3
3
 
4
- export class AddNode implements Node, OperatorNode {
5
- leftChild: Node;
6
- rightChild: Node;
7
- type: NodeType = NodeType.operator;
8
- id: string = "add";
9
- tex = "+";
4
+ export class AddNode extends OperatorNode {
10
5
  constructor(leftChild: Node, rightChild: Node) {
6
+ super(OperatorIds.add, leftChild, rightChild, true, "+");
11
7
  this.leftChild = leftChild;
12
8
  this.rightChild = rightChild;
13
9
  }
@@ -1,22 +1,34 @@
1
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
+ })();
2
17
  exports.__esModule = true;
3
18
  exports.DivideNode = void 0;
4
- var node_1 = require("../node");
5
- var DivideNode = /** @class */ (function () {
19
+ var operatorNode_1 = require("./operatorNode");
20
+ var DivideNode = /** @class */ (function (_super) {
21
+ __extends(DivideNode, _super);
6
22
  /**
7
23
  * @param leftChild num
8
24
  * @param rightChild denum
9
25
  */
10
26
  function DivideNode(leftChild, rightChild) {
11
- this.type = node_1.NodeType.operator;
12
- this.id = "divide";
13
- this.tex = "\\frac";
14
- this.leftChild = leftChild;
15
- this.rightChild = rightChild;
27
+ return _super.call(this, operatorNode_1.OperatorIds.divide, leftChild, rightChild, false, "\\div") || this;
16
28
  }
17
29
  DivideNode.prototype.toString = function () {
18
- return "\\frac{".concat(this.leftChild, "}{").concat(this.rightChild, "}");
30
+ return "(".concat(this.leftChild, ") \\div (").concat(this.rightChild, ")");
19
31
  };
20
32
  return DivideNode;
21
- }());
33
+ }(operatorNode_1.OperatorNode));
22
34
  exports.DivideNode = DivideNode;
@@ -1,23 +1,16 @@
1
1
  import { Node, NodeType } from "../node";
2
- import { OperatorNode } from "./operatorNode";
3
-
4
- export class DivideNode implements Node, OperatorNode {
5
- leftChild: Node;
6
- rightChild: Node;
7
- type: NodeType = NodeType.operator;
8
- id: string = "divide";
9
- tex = "\\frac";
2
+ import { OperatorIds, OperatorNode } from "./operatorNode";
10
3
 
4
+ export class DivideNode extends OperatorNode {
11
5
  /**
12
6
  * @param leftChild num
13
7
  * @param rightChild denum
14
8
  */
15
9
  constructor(leftChild: Node, rightChild: Node) {
16
- this.leftChild = leftChild;
17
- this.rightChild = rightChild;
10
+ super(OperatorIds.divide, leftChild, rightChild, false, "\\div");
18
11
  }
19
12
 
20
13
  toString(): string {
21
- return `\\frac{${this.leftChild}}{${this.rightChild}}`;
14
+ return `(${this.leftChild}) \\div (${this.rightChild})`;
22
15
  }
23
16
  }
@@ -1,18 +1,30 @@
1
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
+ })();
2
17
  exports.__esModule = true;
3
18
  exports.EqualNode = void 0;
4
- var node_1 = require("../node");
5
- var EqualNode = /** @class */ (function () {
19
+ var operatorNode_1 = require("./operatorNode");
20
+ var EqualNode = /** @class */ (function (_super) {
21
+ __extends(EqualNode, _super);
6
22
  function EqualNode(leftChild, rightChild) {
7
- this.type = node_1.NodeType.operator;
8
- this.id = "equal";
9
- this.tex = "=";
10
- this.leftChild = leftChild;
11
- this.rightChild = rightChild;
23
+ return _super.call(this, operatorNode_1.OperatorIds.equal, leftChild, rightChild, true, "=") || this;
12
24
  }
13
25
  EqualNode.prototype.toString = function () {
14
26
  return "".concat(this.leftChild, " = ").concat(this.rightChild);
15
27
  };
16
28
  return EqualNode;
17
- }());
29
+ }(operatorNode_1.OperatorNode));
18
30
  exports.EqualNode = EqualNode;
@@ -1,15 +1,9 @@
1
1
  import { Node, NodeType } from "../node";
2
- import { OperatorNode } from "./operatorNode";
2
+ import { OperatorIds, OperatorNode } from "./operatorNode";
3
3
 
4
- export class EqualNode implements Node, OperatorNode {
5
- leftChild: Node;
6
- rightChild: Node;
7
- type: NodeType = NodeType.operator;
8
- id: string = "equal";
9
- tex = "=";
4
+ export class EqualNode extends OperatorNode {
10
5
  constructor(leftChild: Node, rightChild: Node) {
11
- this.leftChild = leftChild;
12
- this.rightChild = rightChild;
6
+ super(OperatorIds.equal, leftChild, rightChild, true, "=");
13
7
  }
14
8
  toString(): string {
15
9
  return `${this.leftChild} = ${this.rightChild}`;
@@ -0,0 +1,34 @@
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.FractionNode = void 0;
19
+ var operatorNode_1 = require("./operatorNode");
20
+ var FractionNode = /** @class */ (function (_super) {
21
+ __extends(FractionNode, _super);
22
+ /**
23
+ * @param leftChild num
24
+ * @param rightChild denum
25
+ */
26
+ function FractionNode(leftChild, rightChild) {
27
+ return _super.call(this, operatorNode_1.OperatorIds.fraction, leftChild, rightChild, false, "\\frac") || this;
28
+ }
29
+ FractionNode.prototype.toString = function () {
30
+ return "\\frac{".concat(this.leftChild, "}{").concat(this.rightChild, "}");
31
+ };
32
+ return FractionNode;
33
+ }(operatorNode_1.OperatorNode));
34
+ exports.FractionNode = FractionNode;
@@ -0,0 +1,16 @@
1
+ import { Node, NodeType } from "../node";
2
+ import { OperatorIds, OperatorNode } from "./operatorNode";
3
+
4
+ export class FractionNode extends OperatorNode {
5
+ /**
6
+ * @param leftChild num
7
+ * @param rightChild denum
8
+ */
9
+ constructor(leftChild: Node, rightChild: Node) {
10
+ super(OperatorIds.fraction, leftChild, rightChild, false, "\\frac");
11
+ }
12
+
13
+ toString(): string {
14
+ return `\\frac{${this.leftChild}}{${this.rightChild}}`;
15
+ }
16
+ }
@@ -1,18 +1,30 @@
1
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
+ })();
2
17
  exports.__esModule = true;
3
18
  exports.MultiplyNode = void 0;
4
- var node_1 = require("../node");
5
- var MultiplyNode = /** @class */ (function () {
19
+ var operatorNode_1 = require("./operatorNode");
20
+ var MultiplyNode = /** @class */ (function (_super) {
21
+ __extends(MultiplyNode, _super);
6
22
  function MultiplyNode(leftChild, rightChild) {
7
- this.type = node_1.NodeType.operator;
8
- this.id = "multiply";
9
- this.tex = "\\times";
10
- this.leftChild = leftChild;
11
- this.rightChild = rightChild;
23
+ return _super.call(this, operatorNode_1.OperatorIds.multiply, leftChild, rightChild, true, "\\times") || this;
12
24
  }
13
25
  MultiplyNode.prototype.toString = function () {
14
26
  return "(".concat(this.leftChild, ")*(").concat(this.rightChild, ")");
15
27
  };
16
28
  return MultiplyNode;
17
- }());
29
+ }(operatorNode_1.OperatorNode));
18
30
  exports.MultiplyNode = MultiplyNode;
@@ -1,15 +1,9 @@
1
1
  import { Node, NodeType } from "../node";
2
- import { OperatorNode } from "./operatorNode";
2
+ import { OperatorIds, OperatorNode } from "./operatorNode";
3
3
 
4
- export class MultiplyNode implements Node, OperatorNode {
5
- leftChild: Node;
6
- rightChild: Node;
7
- type: NodeType = NodeType.operator;
8
- id: string = "multiply";
9
- tex = "\\times";
4
+ export class MultiplyNode extends OperatorNode {
10
5
  constructor(leftChild: Node, rightChild: Node) {
11
- this.leftChild = leftChild;
12
- this.rightChild = rightChild;
6
+ super(OperatorIds.multiply, leftChild, rightChild, true, "\\times");
13
7
  }
14
8
 
15
9
  toString(): string {
@@ -1,2 +1,37 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
+ exports.OperatorNode = exports.OperatorIds = void 0;
4
+ var coin_1 = require("../../../utils/coin");
5
+ var node_1 = require("../node");
6
+ var OperatorIds;
7
+ (function (OperatorIds) {
8
+ OperatorIds[OperatorIds["add"] = 0] = "add";
9
+ OperatorIds[OperatorIds["substract"] = 1] = "substract";
10
+ OperatorIds[OperatorIds["multiply"] = 2] = "multiply";
11
+ OperatorIds[OperatorIds["fraction"] = 3] = "fraction";
12
+ OperatorIds[OperatorIds["divide"] = 4] = "divide";
13
+ OperatorIds[OperatorIds["power"] = 5] = "power";
14
+ OperatorIds[OperatorIds["equal"] = 6] = "equal";
15
+ })(OperatorIds = exports.OperatorIds || (exports.OperatorIds = {}));
16
+ var OperatorNode = /** @class */ (function () {
17
+ function OperatorNode(id, leftChild, rightChild, isCommutative, tex) {
18
+ this.type = node_1.NodeType.operator;
19
+ this.id = id;
20
+ this.leftChild = leftChild;
21
+ this.rightChild = rightChild;
22
+ this.isCommutative = isCommutative;
23
+ this.tex = tex;
24
+ }
25
+ /**shuffles in place */
26
+ OperatorNode.prototype.shuffle = function () {
27
+ var _a;
28
+ if (!this.isCommutative)
29
+ return this;
30
+ if ((0, coin_1.coin)())
31
+ return this;
32
+ _a = [this.rightChild, this.leftChild], this.leftChild = _a[0], this.rightChild = _a[1];
33
+ return this;
34
+ };
35
+ return OperatorNode;
36
+ }());
37
+ exports.OperatorNode = OperatorNode;
@@ -1,3 +1,36 @@
1
- export interface OperatorNode {
2
- id: string;
1
+ import { coin } from "../../../utils/coin";
2
+ import { Node, NodeType } from "../node";
3
+
4
+ export enum OperatorIds {
5
+ add,
6
+ substract,
7
+ multiply,
8
+ fraction,
9
+ divide,
10
+ power,
11
+ equal,
12
+ }
13
+
14
+ export abstract class OperatorNode implements Node {
15
+ id: OperatorIds;
16
+ leftChild: Node;
17
+ rightChild: Node;
18
+ isCommutative: boolean;
19
+ type = NodeType.operator;
20
+ tex: string;
21
+ constructor(id: OperatorIds, leftChild: Node, rightChild: Node, isCommutative: boolean, tex: string) {
22
+ this.id = id;
23
+ this.leftChild = leftChild;
24
+ this.rightChild = rightChild;
25
+ this.isCommutative = isCommutative;
26
+ this.tex = tex;
27
+ }
28
+
29
+ /**shuffles in place */
30
+ shuffle(): Node {
31
+ if (!this.isCommutative) return this;
32
+ if (coin()) return this;
33
+ [this.leftChild, this.rightChild] = [this.rightChild, this.leftChild];
34
+ return this;
35
+ }
3
36
  }
@@ -1,18 +1,30 @@
1
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
+ })();
2
17
  exports.__esModule = true;
3
18
  exports.PowerNode = void 0;
4
- var node_1 = require("../node");
5
- var PowerNode = /** @class */ (function () {
19
+ var operatorNode_1 = require("./operatorNode");
20
+ var PowerNode = /** @class */ (function (_super) {
21
+ __extends(PowerNode, _super);
6
22
  function PowerNode(leftChild, rightChild) {
7
- this.tex = "^";
8
- this.type = node_1.NodeType.operator;
9
- this.id = "power";
10
- this.leftChild = leftChild;
11
- this.rightChild = rightChild;
23
+ return _super.call(this, operatorNode_1.OperatorIds.power, leftChild, rightChild, false, "^") || this;
12
24
  }
13
25
  PowerNode.prototype.toString = function () {
14
26
  return "(".concat(this.leftChild, ")^{").concat(this.rightChild, "}");
15
27
  };
16
28
  return PowerNode;
17
- }());
29
+ }(operatorNode_1.OperatorNode));
18
30
  exports.PowerNode = PowerNode;
@@ -1,14 +1,9 @@
1
1
  import { Node, NodeType } from "../node";
2
+ import { OperatorIds, OperatorNode } from "./operatorNode";
2
3
 
3
- export class PowerNode implements Node {
4
- tex = "^";
5
- type = NodeType.operator;
6
- id = "power";
7
- leftChild: Node;
8
- rightChild: Node;
4
+ export class PowerNode extends OperatorNode {
9
5
  constructor(leftChild: Node, rightChild: Node) {
10
- this.leftChild = leftChild;
11
- this.rightChild = rightChild;
6
+ super(OperatorIds.power, leftChild, rightChild, false, "^");
12
7
  }
13
8
 
14
9
  toString(): string {