math-exercises 1.2.10 → 1.3.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.
- package/README.md +63 -0
- package/lib/exercises/calcul/addAndSub.js +8 -9
- package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +7 -8
- package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +9 -9
- package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +7 -8
- package/lib/exercises/calcul/fractions/fractionsDivision.js +8 -9
- package/lib/exercises/calcul/fractions/fractionsProduct.js +8 -9
- package/lib/exercises/calcul/fractions/fractionsSum.js +8 -9
- package/lib/exercises/calcul/fractions/simplifyFraction.js +2 -3
- package/lib/exercises/calcul/operations/operationsPriorities.js +25 -15
- package/lib/exercises/calcul/rounding/rounding.js +33 -34
- package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +9 -10
- package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +9 -10
- package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +10 -11
- package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +9 -10
- package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +9 -10
- package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +9 -10
- package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +11 -12
- package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +11 -12
- package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +12 -13
- package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +11 -12
- package/lib/exercises/geometry/cartesian/midpoint.js +1 -1
- package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +9 -10
- package/lib/exercises/powers/powersDivision.js +14 -15
- package/lib/exercises/powers/powersOfTenToDecimal.js +6 -7
- package/lib/exercises/powers/powersPower.js +12 -13
- package/lib/exercises/powers/powersProduct.js +14 -15
- package/lib/exercises/powers/scientificToDecimal.js +8 -9
- package/lib/exercises/squareRoots/simpifySquareRoot.js +8 -9
- package/lib/exercises/utils/getDistinctQuestions.js +1 -2
- package/lib/geometry/point.js +4 -4
- package/lib/geometry/vector.js +3 -3
- package/lib/index.js +4 -5
- package/lib/tree/nodes/functions/oppositeNode.js +16 -3
- package/lib/tree/nodes/functions/sqrtNode.js +6 -3
- package/lib/tree/nodes/numbers/numberNode.js +1 -1
- package/lib/tree/nodes/operators/addNode.js +7 -3
- package/lib/tree/nodes/operators/divideNode.js +20 -3
- package/lib/tree/nodes/operators/equalNode.js +6 -3
- package/lib/tree/nodes/operators/fractionNode.js +6 -3
- package/lib/tree/nodes/operators/multiplyNode.js +26 -3
- package/lib/tree/nodes/operators/operatorNode.js +3 -3
- package/lib/tree/nodes/operators/powerNode.js +23 -3
- package/lib/tree/nodes/operators/substractNode.js +14 -3
- package/lib/tree/nodes/variables/variableNode.js +9 -6
- package/lib/tree/parsers/derivateParser.js +61 -59
- package/lib/tree/parsers/latexParser.js +109 -116
- package/lib/tree/parsers/simplify.js +51 -0
- package/package.json +5 -2
|
@@ -1,117 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
default:
|
|
114
|
-
return "";
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.latexParser = latexParser;
|
|
2
|
+
// import { FunctionNode, FunctionsIds } from "../nodes/functions/functionNode";
|
|
3
|
+
// import { Node, NodeType } from "../nodes/node";
|
|
4
|
+
// import { OperatorIds, OperatorNode } from "../nodes/operators/operatorNode";
|
|
5
|
+
// export function latexParser(node: Node): string {
|
|
6
|
+
// if (!node) {
|
|
7
|
+
// console.log("parsing a null node ???");
|
|
8
|
+
// return "";
|
|
9
|
+
// }
|
|
10
|
+
// switch (node.type) {
|
|
11
|
+
// case NodeType.variable:
|
|
12
|
+
// return node.tex;
|
|
13
|
+
// case NodeType.number:
|
|
14
|
+
// return node.tex;
|
|
15
|
+
// case NodeType.operator:
|
|
16
|
+
// const operatorNode = node as OperatorNode;
|
|
17
|
+
// let rightTex = latexParser(operatorNode.rightChild);
|
|
18
|
+
// let leftTex = latexParser(operatorNode.leftChild);
|
|
19
|
+
// const { leftChild, rightChild } = operatorNode;
|
|
20
|
+
// switch (operatorNode.id) {
|
|
21
|
+
// case OperatorIds.add:
|
|
22
|
+
// return `${leftTex} ${rightTex[0] === "-" ? "" : "+ "}${rightTex}`;
|
|
23
|
+
// case OperatorIds.substract: {
|
|
24
|
+
// const needBrackets =
|
|
25
|
+
// (rightChild.type === NodeType.operator &&
|
|
26
|
+
// [OperatorIds.add, OperatorIds.substract].includes((rightChild as OperatorNode).id)) ||
|
|
27
|
+
// rightTex[0] === "-";
|
|
28
|
+
// if (needBrackets) rightTex = `(${rightTex})`;
|
|
29
|
+
// return `${leftTex} - ${rightTex}`;
|
|
30
|
+
// }
|
|
31
|
+
// case OperatorIds.multiply: {
|
|
32
|
+
// if (leftChild.type === NodeType.operator) {
|
|
33
|
+
// if ([OperatorIds.add, OperatorIds.substract, OperatorIds.divide].includes((leftChild as OperatorNode).id))
|
|
34
|
+
// leftTex = `(${leftTex})`;
|
|
35
|
+
// }
|
|
36
|
+
// let needBrackets = rightTex[0] === "-";
|
|
37
|
+
// if (rightChild.type === NodeType.operator) {
|
|
38
|
+
// const operatorRightChild = rightChild as OperatorNode;
|
|
39
|
+
// needBrackets ||= [OperatorIds.add, OperatorIds.substract].includes(operatorRightChild.id);
|
|
40
|
+
// }
|
|
41
|
+
// if (needBrackets) rightTex = `(${rightTex})`;
|
|
42
|
+
// // permet de gérer le cas 3*2^x
|
|
43
|
+
// let showTimesSign = !isNaN(+rightTex[0]) || rightChild.type === NodeType.number;
|
|
44
|
+
// if (rightChild.type === NodeType.operator) {
|
|
45
|
+
// const operatorRightChild = rightChild as OperatorNode;
|
|
46
|
+
// showTimesSign ||= [OperatorIds.fraction].includes(operatorRightChild.id);
|
|
47
|
+
// }
|
|
48
|
+
// return `${leftTex}${showTimesSign ? "\\times " : ""}${rightTex}`;
|
|
49
|
+
// }
|
|
50
|
+
// case OperatorIds.divide: {
|
|
51
|
+
// if (leftChild.type === NodeType.operator) {
|
|
52
|
+
// if ([OperatorIds.add, OperatorIds.substract, OperatorIds.multiply].includes((leftChild as OperatorNode).id))
|
|
53
|
+
// leftTex = `(${leftTex})`;
|
|
54
|
+
// }
|
|
55
|
+
// let needBrackets = rightTex[0] === "-";
|
|
56
|
+
// if (rightChild.type === NodeType.operator) {
|
|
57
|
+
// const operatorRightChild = rightChild as OperatorNode;
|
|
58
|
+
// needBrackets ||= [OperatorIds.add, OperatorIds.substract].includes(operatorRightChild.id);
|
|
59
|
+
// }
|
|
60
|
+
// if (needBrackets) rightTex = `(${rightTex})`;
|
|
61
|
+
// return `${leftTex} \\div ${rightTex}`;
|
|
62
|
+
// }
|
|
63
|
+
// case OperatorIds.fraction: {
|
|
64
|
+
// return `\\frac{${leftTex}}{${rightTex}}`;
|
|
65
|
+
// }
|
|
66
|
+
// case OperatorIds.power: {
|
|
67
|
+
// let needBrackets = leftTex[0] === "-";
|
|
68
|
+
// if (leftChild.type === NodeType.operator) {
|
|
69
|
+
// const childOperator = leftChild as OperatorNode;
|
|
70
|
+
// needBrackets ||= [
|
|
71
|
+
// OperatorIds.add,
|
|
72
|
+
// OperatorIds.substract,
|
|
73
|
+
// OperatorIds.multiply,
|
|
74
|
+
// OperatorIds.divide,
|
|
75
|
+
// OperatorIds.fraction,
|
|
76
|
+
// OperatorIds.power,
|
|
77
|
+
// ].includes(childOperator.id);
|
|
78
|
+
// }
|
|
79
|
+
// if (needBrackets) leftTex = `(${leftTex})`;
|
|
80
|
+
// return `${leftTex}^{${rightTex}}`;
|
|
81
|
+
// }
|
|
82
|
+
// case OperatorIds.equal: {
|
|
83
|
+
// return `${leftTex} = ${rightTex}`;
|
|
84
|
+
// }
|
|
85
|
+
// default:
|
|
86
|
+
// return node.tex;
|
|
87
|
+
// }
|
|
88
|
+
// case NodeType.function: {
|
|
89
|
+
// const functionNode = node as FunctionNode;
|
|
90
|
+
// const child = functionNode.child;
|
|
91
|
+
// let childTex = latexParser(functionNode.child);
|
|
92
|
+
// switch (functionNode.id) {
|
|
93
|
+
// case FunctionsIds.sqrt: {
|
|
94
|
+
// return `\\sqrt{${childTex}}`;
|
|
95
|
+
// }
|
|
96
|
+
// case FunctionsIds.opposite: {
|
|
97
|
+
// let needBrackets = childTex[0] === "-";
|
|
98
|
+
// if (child.type === NodeType.operator) {
|
|
99
|
+
// const operatorChild = child as OperatorNode;
|
|
100
|
+
// needBrackets ||= [OperatorIds.add, OperatorIds.substract].includes(operatorChild.id);
|
|
101
|
+
// }
|
|
102
|
+
// if (needBrackets) childTex = `(${childTex})`;
|
|
103
|
+
// return `-${childTex}`;
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
// default:
|
|
108
|
+
// return "";
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simplifyNode = void 0;
|
|
4
|
+
const mathjs_1 = require("mathjs");
|
|
5
|
+
const oppositeNode_1 = require("../nodes/functions/oppositeNode");
|
|
6
|
+
const sqrtNode_1 = require("../nodes/functions/sqrtNode");
|
|
7
|
+
const numberNode_1 = require("../nodes/numbers/numberNode");
|
|
8
|
+
const addNode_1 = require("../nodes/operators/addNode");
|
|
9
|
+
const fractionNode_1 = require("../nodes/operators/fractionNode");
|
|
10
|
+
const multiplyNode_1 = require("../nodes/operators/multiplyNode");
|
|
11
|
+
const powerNode_1 = require("../nodes/operators/powerNode");
|
|
12
|
+
const substractNode_1 = require("../nodes/operators/substractNode");
|
|
13
|
+
const variableNode_1 = require("../nodes/variables/variableNode");
|
|
14
|
+
const simplifyNode = (node) => {
|
|
15
|
+
console.log(node.toMathString());
|
|
16
|
+
return mathjsNodeToNode((0, mathjs_1.simplify)(node.toMathString()));
|
|
17
|
+
};
|
|
18
|
+
exports.simplifyNode = simplifyNode;
|
|
19
|
+
const mathjsNodeToNode = (mathjsNode) => {
|
|
20
|
+
console.log(mathjsNode);
|
|
21
|
+
if (mathjsNode.isSymbolNode) {
|
|
22
|
+
return new variableNode_1.VariableNode(mathjsNode.name);
|
|
23
|
+
}
|
|
24
|
+
else if (mathjsNode.isConstantNode) {
|
|
25
|
+
return new numberNode_1.NumberNode(mathjsNode.value);
|
|
26
|
+
}
|
|
27
|
+
else if (mathjsNode.isOperatorNode) {
|
|
28
|
+
switch (mathjsNode.fn) {
|
|
29
|
+
case 'add':
|
|
30
|
+
return new addNode_1.AddNode(mathjsNodeToNode(mathjsNode.args[0]), mathjsNodeToNode(mathjsNode.args[1]));
|
|
31
|
+
case 'substract':
|
|
32
|
+
return new substractNode_1.SubstractNode(mathjsNodeToNode(mathjsNode.args[0]), mathjsNodeToNode(mathjsNode.args[1]));
|
|
33
|
+
case 'unaryMinus':
|
|
34
|
+
return new oppositeNode_1.OppositeNode(mathjsNodeToNode(mathjsNode.args[0]));
|
|
35
|
+
case 'divide':
|
|
36
|
+
return new fractionNode_1.FractionNode(mathjsNodeToNode(mathjsNode.args[0]), mathjsNodeToNode(mathjsNode.args[1]));
|
|
37
|
+
case 'multiply':
|
|
38
|
+
return new multiplyNode_1.MultiplyNode(mathjsNodeToNode(mathjsNode.args[0]), mathjsNodeToNode(mathjsNode.args[1]));
|
|
39
|
+
case 'pow':
|
|
40
|
+
return new powerNode_1.PowerNode(mathjsNodeToNode(mathjsNode.args[0]), mathjsNodeToNode(mathjsNode.args[1]));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (mathjsNode.isFunctionNode) {
|
|
44
|
+
const fn = mathjsNode.fn;
|
|
45
|
+
switch (fn.name) {
|
|
46
|
+
case 'sqrt':
|
|
47
|
+
return new sqrtNode_1.SqrtNode(mathjsNodeToNode(mathjsNode.args[0]));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
throw Error('unrecognized mathjs node');
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "math-exercises",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Générateurs d'exercices et questions mathématiques en latex",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -31,5 +31,8 @@
|
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/krirkrirk/math-exercices/issues"
|
|
33
33
|
},
|
|
34
|
-
"homepage": "https://github.com/krirkrirk/math-exercices#readme"
|
|
34
|
+
"homepage": "https://github.com/krirkrirk/math-exercices#readme",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"mathjs": "^11.5.1"
|
|
37
|
+
}
|
|
35
38
|
}
|