math-exercises 1.0.1 → 1.1.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 (98) hide show
  1. package/nodemon.json +1 -2
  2. package/package.json +1 -1
  3. package/src/exercises/calcul/addAndSub.js +34 -0
  4. package/src/exercises/calcul/addAndSub.ts +32 -0
  5. package/src/exercises/calcul/priority.ts +33 -0
  6. package/src/exercises/calculLitteral/distributivity/allIdentities.js +25 -0
  7. package/src/exercises/calculLitteral/distributivity/allIdentities.ts +24 -0
  8. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.js +31 -0
  9. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.ts +31 -0
  10. package/src/exercises/calculLitteral/distributivity/firstIdentity.js +30 -0
  11. package/src/exercises/calculLitteral/distributivity/firstIdentity.ts +31 -0
  12. package/src/exercises/calculLitteral/distributivity/secondIdentity.js +33 -0
  13. package/src/exercises/calculLitteral/distributivity/secondIdentity.ts +33 -0
  14. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.js +33 -0
  15. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.ts +31 -0
  16. package/src/exercises/calculLitteral/distributivity/thirdIdentity.js +30 -0
  17. package/src/exercises/calculLitteral/distributivity/thirdIdentity.ts +32 -0
  18. package/src/exercises/calculLitteral/equation/equationType1Exercise.js +38 -0
  19. package/src/exercises/calculLitteral/equation/equationType1Exercise.ts +39 -0
  20. package/src/exercises/calculLitteral/equation/equationType2Exercise.js +41 -0
  21. package/src/exercises/calculLitteral/equation/equationType2Exercise.ts +41 -0
  22. package/src/exercises/calculLitteral/equation/equationType3Exercise.js +42 -0
  23. package/src/exercises/calculLitteral/equation/equationType3Exercise.ts +43 -0
  24. package/src/exercises/calculLitteral/equation/equationType4Exercise.js +44 -0
  25. package/src/exercises/calculLitteral/equation/equationType4Exercise.ts +51 -0
  26. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.js +28 -23
  27. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.ts +36 -22
  28. package/src/exercises/exercise.js +5 -0
  29. package/src/exercises/exercise.ts +9 -1
  30. package/src/exercises/exercises.ts +27 -0
  31. package/src/exercises/squareRoots/simpifySquareRoot.js +29 -0
  32. package/src/exercises/squareRoots/simpifySquareRoot.ts +25 -0
  33. package/src/expression/expression.js +3 -1
  34. package/src/expression/expression.ts +4 -0
  35. package/src/index.js +8 -6
  36. package/src/index.ts +18 -6
  37. package/src/mathutils/arithmetic/isSquare.js +7 -0
  38. package/src/mathutils/arithmetic/primeFactors.js +22 -0
  39. package/src/numbers/integer/integer.js +15 -0
  40. package/src/numbers/integer/integer.ts +20 -2
  41. package/src/numbers/nombre.js +9 -0
  42. package/src/numbers/nombre.ts +13 -0
  43. package/src/numbers/rationals/rational.js +23 -1
  44. package/src/numbers/rationals/rational.ts +37 -3
  45. package/src/numbers/reals/real.js +15 -0
  46. package/src/numbers/reals/real.ts +15 -1
  47. package/src/numbers/reals/squareRoot.js +85 -0
  48. package/src/numbers/reals/squareRoot.ts +44 -21
  49. package/src/polynomials/affine.js +5 -4
  50. package/src/polynomials/affine.ts +16 -21
  51. package/src/polynomials/polynomial.js +47 -11
  52. package/src/polynomials/polynomial.ts +57 -17
  53. package/src/sets/discreteSet.js +4 -4
  54. package/src/sets/discreteSet.ts +10 -9
  55. package/src/sets/emptySet.ts +5 -5
  56. package/src/sets/intervals/intervals.js +33 -9
  57. package/src/sets/intervals/intervals.ts +41 -12
  58. package/src/sets/mathSet.ts +5 -3
  59. package/src/sets/mathSetInterface.ts +4 -2
  60. package/src/tree/latexParser/latexParse.js +76 -0
  61. package/src/tree/latexParser/latexParse.ts +82 -0
  62. package/src/tree/nodes/functions/sqrtNode.js +18 -0
  63. package/src/tree/nodes/functions/sqrtNode.ts +16 -0
  64. package/src/tree/nodes/node.js +10 -0
  65. package/src/tree/nodes/node.ts +14 -0
  66. package/src/tree/nodes/numbers/numberNode.js +19 -0
  67. package/src/tree/nodes/numbers/numberNode.ts +19 -0
  68. package/src/tree/nodes/operators/addNode.js +18 -0
  69. package/src/tree/nodes/operators/addNode.ts +17 -0
  70. package/src/tree/nodes/operators/divideNode.js +22 -0
  71. package/src/tree/nodes/operators/divideNode.ts +23 -0
  72. package/src/tree/nodes/operators/equalNode.js +18 -0
  73. package/src/tree/nodes/operators/equalNode.ts +17 -0
  74. package/src/tree/nodes/operators/multiplyNode.js +18 -0
  75. package/src/tree/nodes/operators/multiplyNode.ts +18 -0
  76. package/src/{operations/operation.js → tree/nodes/operators/operatorNode.js} +0 -0
  77. package/src/tree/nodes/operators/operatorNode.ts +3 -0
  78. package/src/tree/nodes/operators/oppositeNode.js +18 -0
  79. package/src/tree/nodes/operators/oppositeNode.ts +17 -0
  80. package/src/tree/nodes/operators/powerNode.js +18 -0
  81. package/src/tree/nodes/operators/powerNode.ts +17 -0
  82. package/src/tree/nodes/operators/substractNode.js +18 -0
  83. package/src/tree/nodes/operators/substractNode.ts +17 -0
  84. package/src/tree/nodes/variables/variableNode.js +20 -0
  85. package/src/tree/nodes/variables/variableNode.ts +18 -0
  86. package/src/equations/equations.ts +0 -16
  87. package/src/exercises/calculLitteral/factorisation/factorisation.js +0 -39
  88. package/src/latex/add.js +0 -7
  89. package/src/latex/latex.js +0 -37
  90. package/src/latex/latex.ts +0 -35
  91. package/src/latex/monome.ts +0 -0
  92. package/src/latex/multiply.ts +0 -5
  93. package/src/numbers/number.ts +0 -4
  94. package/src/operations/add.js +0 -9
  95. package/src/operations/add.ts +0 -9
  96. package/src/operations/operation.ts +0 -6
  97. package/src/operations/substract.js +0 -9
  98. package/src/operations/substract.ts +0 -9
@@ -0,0 +1,17 @@
1
+ import { Node, NodeType } from "../node";
2
+ import { OperatorNode } from "./operatorNode";
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 = "=";
10
+ constructor(leftChild: Node, rightChild: Node) {
11
+ this.leftChild = leftChild;
12
+ this.rightChild = rightChild;
13
+ }
14
+ toString(): string {
15
+ return `${this.leftChild} = ${this.rightChild}`;
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.MultiplyNode = void 0;
4
+ var node_1 = require("../node");
5
+ var MultiplyNode = /** @class */ (function () {
6
+ 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;
12
+ }
13
+ MultiplyNode.prototype.toString = function () {
14
+ return "(".concat(this.leftChild, ")*(").concat(this.rightChild, ")");
15
+ };
16
+ return MultiplyNode;
17
+ }());
18
+ exports.MultiplyNode = MultiplyNode;
@@ -0,0 +1,18 @@
1
+ import { Node, NodeType } from "../node";
2
+ import { OperatorNode } from "./operatorNode";
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";
10
+ constructor(leftChild: Node, rightChild: Node) {
11
+ this.leftChild = leftChild;
12
+ this.rightChild = rightChild;
13
+ }
14
+
15
+ toString(): string {
16
+ return `(${this.leftChild})*(${this.rightChild})`;
17
+ }
18
+ }
@@ -0,0 +1,3 @@
1
+ export interface OperatorNode {
2
+ id: string;
3
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.OppositeNode = void 0;
4
+ var node_1 = require("../node");
5
+ var OppositeNode = /** @class */ (function () {
6
+ function OppositeNode(leftChild) {
7
+ this.type = node_1.NodeType.operator;
8
+ this.id = "opposite";
9
+ this.tex = "-";
10
+ this.leftChild = leftChild;
11
+ this.rightChild = null;
12
+ }
13
+ OppositeNode.prototype.toString = function () {
14
+ return "-(".concat(this.leftChild, ")");
15
+ };
16
+ return OppositeNode;
17
+ }());
18
+ exports.OppositeNode = OppositeNode;
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.PowerNode = void 0;
4
+ var node_1 = require("../node");
5
+ var PowerNode = /** @class */ (function () {
6
+ 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;
12
+ }
13
+ PowerNode.prototype.toString = function () {
14
+ return "(".concat(this.leftChild, ")^{").concat(this.rightChild, "}");
15
+ };
16
+ return PowerNode;
17
+ }());
18
+ exports.PowerNode = PowerNode;
@@ -0,0 +1,17 @@
1
+ import { Node, NodeType } from "../node";
2
+
3
+ export class PowerNode implements Node {
4
+ tex = "^";
5
+ type = NodeType.operator;
6
+ id = "power";
7
+ leftChild: Node;
8
+ rightChild: Node;
9
+ constructor(leftChild: Node, rightChild: Node) {
10
+ this.leftChild = leftChild;
11
+ this.rightChild = rightChild;
12
+ }
13
+
14
+ toString(): string {
15
+ return `(${this.leftChild})^{${this.rightChild}}`;
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.SubstractNode = void 0;
4
+ var node_1 = require("../node");
5
+ var SubstractNode = /** @class */ (function () {
6
+ 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;
12
+ }
13
+ SubstractNode.prototype.toString = function () {
14
+ return "".concat(this.leftChild, "-(").concat(this.rightChild, ")");
15
+ };
16
+ return SubstractNode;
17
+ }());
18
+ exports.SubstractNode = SubstractNode;
@@ -0,0 +1,17 @@
1
+ import { Node, NodeType } from "../node";
2
+ import { OperatorNode } from "./operatorNode";
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 = "-";
10
+ constructor(leftChild: Node, rightChild: Node) {
11
+ this.leftChild = leftChild;
12
+ this.rightChild = rightChild;
13
+ }
14
+ toString(): string {
15
+ return `${this.leftChild}-(${this.rightChild})`;
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.VariableNode = void 0;
4
+ var node_1 = require("../node");
5
+ var VariableNode = /** @class */ (function () {
6
+ function VariableNode(tex) {
7
+ this.id = "variable";
8
+ this.leftChild = null;
9
+ this.rightChild = null;
10
+ if (tex.length !== 1 || !tex.match("[a-zA-Z]"))
11
+ throw Error("variable must be a letter");
12
+ this.tex = tex;
13
+ this.type = node_1.NodeType.variable;
14
+ }
15
+ VariableNode.prototype.toString = function () {
16
+ return "".concat(this.tex);
17
+ };
18
+ return VariableNode;
19
+ }());
20
+ exports.VariableNode = VariableNode;
@@ -0,0 +1,18 @@
1
+ import { Node, NodeType } from "../node";
2
+
3
+ export class VariableNode implements Node {
4
+ tex: string;
5
+ type: NodeType;
6
+ id = "variable";
7
+ leftChild = null;
8
+ rightChild = null;
9
+ constructor(tex: string) {
10
+ if (tex.length !== 1 || !tex.match("[a-zA-Z]"))
11
+ throw Error("variable must be a letter");
12
+ this.tex = tex;
13
+ this.type = NodeType.variable;
14
+ }
15
+ toString(): string {
16
+ return `${this.tex}`;
17
+ }
18
+ }
@@ -1,16 +0,0 @@
1
- export abstract class EquationConstructor{
2
- firstDegree({tex:string}){
3
-
4
- }
5
- }
6
-
7
- export class Equation {
8
- leftTerm: string;
9
- rightTerm: string;
10
-
11
- solve(){
12
-
13
- }
14
-
15
-
16
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.getFactoType1Question = exports.FactoType1Exercise = void 0;
4
- var add_1 = require("../../../operations/add");
5
- var substract_1 = require("../../../operations/substract");
6
- var affine_1 = require("../../../polynomials/affine");
7
- var random_1 = require("../../../utils/random");
8
- var shuffle_1 = require("../../../utils/shuffle");
9
- var getDistinctQuestions_1 = require("../../utils/getDistinctQuestions");
10
- /**
11
- *
12
- * @returns type (ax+b)(cx+d) +- (ax+b)(ex+f)
13
- */
14
- var FactoType1Exercise = /** @class */ (function () {
15
- function FactoType1Exercise(nbOfQuestions) {
16
- this.connector = "=";
17
- this.instruction = "Factoriser :";
18
- this.label = "Factorisation du type $(ax+b)(cx+d) \\pm (ax+b)(ex+f)$";
19
- this.levels = ["3", "2"];
20
- this.section = "Calcul Littéral";
21
- this.questions = (0, getDistinctQuestions_1.getDistinctQuestions)(exports.getFactoType1Question, nbOfQuestions);
22
- }
23
- return FactoType1Exercise;
24
- }());
25
- exports.FactoType1Exercise = FactoType1Exercise;
26
- var getFactoType1Question = function () {
27
- var affines = affine_1.AffineConstructor.differentRandoms(3);
28
- var permut = [
29
- [affines[0], affines[1]],
30
- [affines[0], affines[2]],
31
- ];
32
- (0, shuffle_1.shuffle)(permut[0]);
33
- (0, shuffle_1.shuffle)(permut[1]);
34
- var operation = (0, random_1.random)([add_1.add, substract_1.substract]);
35
- var statement = "(".concat(permut[0][0], ")(").concat(permut[0][1], ") ").concat(operation.tex, " (").concat(permut[1][0], ")(").concat(permut[1][1], ")");
36
- var answer = "(".concat(affines[0], ")(").concat(operation.apply(affines[1], affines[2]), ")");
37
- return { statement: statement, answer: answer };
38
- };
39
- exports.getFactoType1Question = getFactoType1Question;
package/src/latex/add.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.add = void 0;
4
- function add(nb) {
5
- return nb === 0 ? "" : "".concat(nb > 0 ? "+" : "").concat(nb);
6
- }
7
- exports.add = add;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.Latex = exports.LatexConstructor = void 0;
4
- var LatexConstructor = /** @class */ (function () {
5
- function LatexConstructor() {
6
- }
7
- LatexConstructor.fromString = function (s) {
8
- return new Latex(s);
9
- };
10
- LatexConstructor.monome = function (n, l) {
11
- return;
12
- };
13
- return LatexConstructor;
14
- }());
15
- exports.LatexConstructor = LatexConstructor;
16
- var Latex = /** @class */ (function () {
17
- function Latex(tex) {
18
- this.tex = tex;
19
- }
20
- Latex.prototype.toTex = function () {
21
- return this.tex;
22
- };
23
- Latex.prototype.add = function (term) {
24
- var s = this.tex;
25
- switch (typeof term) {
26
- case "number":
27
- this.tex += term === 0 ? "" : "".concat(term > 0 ? "+" : "").concat(term);
28
- break;
29
- default:
30
- break;
31
- }
32
- return this.tex;
33
- // return new Latex(s);
34
- };
35
- return Latex;
36
- }());
37
- exports.Latex = Latex;
@@ -1,35 +0,0 @@
1
- import { Expression } from "../expression/expression";
2
-
3
- export abstract class LatexConstructor {
4
- static fromString(s: string): Latex {
5
- return new Latex(s);
6
- }
7
- static monome(n: number, l: Latex) {
8
- return;
9
- }
10
- }
11
- export class Latex {
12
- tex: string;
13
- constructor(tex: string) {
14
- this.tex = tex;
15
- }
16
-
17
- toTex(): string {
18
- return this.tex;
19
- }
20
-
21
- add(term: number | Expression): string {
22
- let s = this.tex;
23
- switch (typeof term) {
24
- case "number":
25
- this.tex += term === 0 ? "" : `${term > 0 ? "+" : ""}${term}`;
26
- break;
27
- default:
28
- break;
29
- }
30
- return this.tex;
31
- // return new Latex(s);
32
- }
33
-
34
- //créer un type monome ?
35
- }
File without changes
@@ -1,5 +0,0 @@
1
- import { Expression } from "../expression/expression";
2
-
3
- export function muliply(a: number | Expression, b: number | Expression) {
4
- // return nb === 0 ? "" : `${nb > 0 ? "+" : ""}${nb}`;
5
- }
@@ -1,4 +0,0 @@
1
- export enum NumberType {
2
- Integer,
3
- Real,
4
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.add = void 0;
4
- exports.add = {
5
- tex: "+",
6
- apply: function (a, b) {
7
- return a.add(b);
8
- }
9
- };
@@ -1,9 +0,0 @@
1
- import { Expression } from "../expression/expression";
2
- import { Operation } from "./operation";
3
-
4
- export const add: Operation = {
5
- tex: "+",
6
- apply: (a: Expression, b: Expression): Expression => {
7
- return a.add(b);
8
- },
9
- };
@@ -1,6 +0,0 @@
1
- import { Expression } from "../expression/expression";
2
-
3
- export interface Operation {
4
- tex: string;
5
- apply: Function;
6
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.substract = void 0;
4
- exports.substract = {
5
- tex: "-",
6
- apply: function (a, b) {
7
- return a.add(b.opposite());
8
- }
9
- };
@@ -1,9 +0,0 @@
1
- import { Expression } from "../expression/expression";
2
- import { Operation } from "./operation";
3
-
4
- export const substract: Operation = {
5
- tex: "-",
6
- apply: (a: Expression, b: Expression): Expression => {
7
- return a.add(b.opposite());
8
- },
9
- };