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
@@ -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.SubstractNode = void 0;
4
- var node_1 = require("../node");
5
- var SubstractNode = /** @class */ (function () {
19
+ var operatorNode_1 = require("./operatorNode");
20
+ var SubstractNode = /** @class */ (function (_super) {
21
+ __extends(SubstractNode, _super);
6
22
  function SubstractNode(leftChild, rightChild) {
7
- this.type = node_1.NodeType.operator;
8
- this.id = "substract";
9
- this.tex = "-";
10
- this.leftChild = leftChild;
11
- this.rightChild = rightChild;
23
+ return _super.call(this, operatorNode_1.OperatorIds.substract, leftChild, rightChild, false, "-") || this;
12
24
  }
13
25
  SubstractNode.prototype.toString = function () {
14
26
  return "".concat(this.leftChild, "-(").concat(this.rightChild, ")");
15
27
  };
16
28
  return SubstractNode;
17
- }());
29
+ }(operatorNode_1.OperatorNode));
18
30
  exports.SubstractNode = SubstractNode;
@@ -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 SubstractNode implements Node, OperatorNode {
5
- leftChild: Node;
6
- rightChild: Node;
7
- type: NodeType = NodeType.operator;
8
- id: string = "substract";
9
- tex = "-";
4
+ export class SubstractNode extends OperatorNode {
10
5
  constructor(leftChild: Node, rightChild: Node) {
11
- this.leftChild = leftChild;
12
- this.rightChild = rightChild;
6
+ super(OperatorIds.substract, leftChild, rightChild, false, "-");
13
7
  }
14
8
  toString(): string {
15
9
  return `${this.leftChild}-(${this.rightChild})`;
@@ -4,13 +4,10 @@ exports.VariableNode = void 0;
4
4
  var node_1 = require("../node");
5
5
  var VariableNode = /** @class */ (function () {
6
6
  function VariableNode(tex) {
7
- this.id = "variable";
8
- this.leftChild = null;
9
- this.rightChild = null;
7
+ this.type = node_1.NodeType.variable;
10
8
  if (tex.length !== 1 || !tex.match("[a-zA-Z]"))
11
9
  throw Error("variable must be a letter");
12
10
  this.tex = tex;
13
- this.type = node_1.NodeType.variable;
14
11
  }
15
12
  VariableNode.prototype.toString = function () {
16
13
  return "".concat(this.tex);
@@ -2,16 +2,13 @@ import { Node, NodeType } from "../node";
2
2
 
3
3
  export class VariableNode implements Node {
4
4
  tex: string;
5
- type: NodeType;
6
- id = "variable";
7
- leftChild = null;
8
- rightChild = null;
5
+ type = NodeType.variable;
6
+
9
7
  constructor(tex: string) {
10
- if (tex.length !== 1 || !tex.match("[a-zA-Z]"))
11
- throw Error("variable must be a letter");
8
+ if (tex.length !== 1 || !tex.match("[a-zA-Z]")) throw Error("variable must be a letter");
12
9
  this.tex = tex;
13
- this.type = NodeType.variable;
14
10
  }
11
+
15
12
  toString(): string {
16
13
  return `${this.tex}`;
17
14
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.coin = void 0;
4
+ var coin = function () {
5
+ return Math.random() < 0.5;
6
+ };
7
+ exports.coin = coin;
@@ -0,0 +1,3 @@
1
+ export const coin = (): Boolean => {
2
+ return Math.random() < 0.5;
3
+ };
@@ -1,13 +1,24 @@
1
1
  "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
2
11
  exports.__esModule = true;
3
12
  exports.shuffle = void 0;
4
13
  /* Randomize array in-place using Durstenfeld shuffle algorithm */
5
14
  function shuffle(array) {
6
- for (var i = array.length - 1; i > 0; i--) {
15
+ var res = __spreadArray([], array, true);
16
+ for (var i = res.length - 1; i > 0; i--) {
7
17
  var j = Math.floor(Math.random() * (i + 1));
8
- var temp = array[i];
9
- array[i] = array[j];
10
- array[j] = temp;
18
+ var temp = res[i];
19
+ res[i] = res[j];
20
+ res[j] = temp;
11
21
  }
22
+ return res;
12
23
  }
13
24
  exports.shuffle = shuffle;
@@ -1,9 +1,11 @@
1
1
  /* Randomize array in-place using Durstenfeld shuffle algorithm */
2
- export function shuffle<T>(array: T[]) {
3
- for (var i = array.length - 1; i > 0; i--) {
2
+ export function shuffle<T>(array: T[]): T[] {
3
+ const res = [...array];
4
+ for (var i = res.length - 1; i > 0; i--) {
4
5
  var j = Math.floor(Math.random() * (i + 1));
5
- var temp = array[i];
6
- array[i] = array[j];
7
- array[j] = temp;
6
+ var temp = res[i];
7
+ res[i] = res[j];
8
+ res[j] = temp;
8
9
  }
10
+ return res;
9
11
  }
@@ -1,33 +0,0 @@
1
- import { randint } from "../../mathutils/random/randint";
2
- import { Interval } from "../../sets/intervals/intervals";
3
- import { Exercise, Question } from "../exercise";
4
- import { getDistinctQuestions } from "../utils/getDistinctQuestions";
5
-
6
- /**
7
- * a*b ±c±d
8
- * a/b ±c±d
9
- */
10
- // export const priorityExercise: Exercise = {
11
- // connector: "=",
12
- // instruction: "Simplifier : ",
13
- // label: "Priorités opératoires",
14
- // levels: ["6", "5", "4"],
15
- // section: "Calculs",
16
- // generator: (nb: number) => getDistinctQuestions(getPriorityQuestions, nb),
17
- // };
18
-
19
- // export function getPriorityQuestions(): Question {
20
- // const nbOfTerms = randint(3, 5);
21
- // const max = 20;
22
- // const terms = [];
23
- // const interval = new Interval(`[[${-max}; ${max}]]`).exclude(0);
24
- // for (let i = 0; i < nbOfTerms; i++) {
25
- // terms.push(interval.getRandomElement());
26
- // }
27
- // const tex = new Latex("");
28
- // terms.forEach((term) => tex.add(term));
29
- // const statement = tex.toTex();
30
- // const answer = terms.reduce((acc, curr) => acc + curr).toString();
31
- // const question: Question = { statement, answer };
32
- // return question;
33
- // }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.ExpressionType = void 0;
4
- var ExpressionType;
5
- (function (ExpressionType) {
6
- ExpressionType[ExpressionType["real"] = 0] = "real";
7
- ExpressionType[ExpressionType["affine"] = 1] = "affine";
8
- ExpressionType[ExpressionType["polynomial"] = 2] = "polynomial";
9
- })(ExpressionType = exports.ExpressionType || (exports.ExpressionType = {}));
@@ -1,13 +0,0 @@
1
- export enum ExpressionType {
2
- real,
3
- affine,
4
- polynomial,
5
- }
6
-
7
- export interface Expression {
8
- // type: ExpressionType;
9
- add(expression: Expression): Expression;
10
- multiply(expression: Expression): Expression;
11
- opposite(): Expression;
12
- toTex(): string;
13
- }
@@ -1,17 +0,0 @@
1
- import { Node, NodeType } from "../node";
2
- import { OperatorNode } from "./operatorNode";
3
-
4
- export class OppositeNode implements Node, OperatorNode {
5
- leftChild: Node;
6
- rightChild: null;
7
- type: NodeType = NodeType.operator;
8
- id: string = "opposite";
9
- tex = "-";
10
- constructor(leftChild: Node) {
11
- this.leftChild = leftChild;
12
- this.rightChild = null;
13
- }
14
- toString(): string {
15
- return `-(${this.leftChild})`;
16
- }
17
- }