math-exercises 2.2.96 → 2.2.97
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/lib/exercises/math/calcul/index.js +1 -0
- package/lib/exercises/math/calculLitteral/distributivity/doubleDistributivity.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/distributivity/doubleDistributivity.js +85 -32
- package/lib/exercises/math/calculLitteral/distributivity/simpleDistributivity.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/distributivity/simpleDistributivity.js +17 -6
- package/lib/tree/parsers/polynomialParser.d.ts.map +1 -1
- package/lib/tree/parsers/polynomialParser.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doubleDistributivity.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/distributivity/doubleDistributivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"doubleDistributivity.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/distributivity/doubleDistributivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,0BAA0B,CAAC;AAYlC,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AA+JF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAmBtD,CAAC"}
|
|
@@ -10,12 +10,47 @@ const multiplyNode_1 = require("../../../../tree/nodes/operators/multiplyNode");
|
|
|
10
10
|
const operatorComposition_1 = require("../../../../tree/utilities/operatorComposition");
|
|
11
11
|
const alignTex_1 = require("../../../../utils/latex/alignTex");
|
|
12
12
|
const shuffle_1 = require("../../../../utils/alea/shuffle");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
13
|
+
const handleVEAError_1 = require("../../../../utils/errors/handleVEAError");
|
|
14
|
+
const polynomialParser_1 = require("../../../../tree/parsers/polynomialParser");
|
|
15
|
+
const getStatementNode = (identifiers) => {
|
|
16
|
+
const { affine1Coeffs, affine2Coeffs } = identifiers;
|
|
17
|
+
const affines = [
|
|
18
|
+
new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]),
|
|
19
|
+
new affine_1.Affine(affine2Coeffs[1], affine2Coeffs[0]),
|
|
20
|
+
];
|
|
17
21
|
const statementTree = new multiplyNode_1.MultiplyNode(affines[0].toTree(), affines[1].toTree());
|
|
22
|
+
return statementTree;
|
|
23
|
+
};
|
|
24
|
+
const getStartStatement = (identifiers) => {
|
|
25
|
+
return getStatementNode(identifiers).toTex();
|
|
26
|
+
};
|
|
27
|
+
const getInstruction = (identifiers) => {
|
|
28
|
+
return `Développer et réduire :
|
|
29
|
+
|
|
30
|
+
$$
|
|
31
|
+
${getStartStatement(identifiers)}
|
|
32
|
+
$$`;
|
|
33
|
+
};
|
|
34
|
+
const getAnswer = (identifiers) => {
|
|
35
|
+
const { affine1Coeffs, affine2Coeffs } = identifiers;
|
|
36
|
+
const affines = [
|
|
37
|
+
new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]),
|
|
38
|
+
new affine_1.Affine(affine2Coeffs[1], affine2Coeffs[0]),
|
|
39
|
+
];
|
|
18
40
|
const answer = affines[0].multiply(affines[1]).toTree().toTex();
|
|
41
|
+
return answer;
|
|
42
|
+
};
|
|
43
|
+
const getHint = (identifiers) => {
|
|
44
|
+
return "Multiplie chaque terme du premier facteur par chaque terme du second facteur, puis regroupe les termes similaires.";
|
|
45
|
+
};
|
|
46
|
+
const getCorrection = (identifiers) => {
|
|
47
|
+
const statementTex = getStartStatement(identifiers);
|
|
48
|
+
const answer = getAnswer(identifiers);
|
|
49
|
+
const { affine1Coeffs, affine2Coeffs } = identifiers;
|
|
50
|
+
const affines = [
|
|
51
|
+
new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]),
|
|
52
|
+
new affine_1.Affine(affine2Coeffs[1], affine2Coeffs[0]),
|
|
53
|
+
];
|
|
19
54
|
const subTerms = [
|
|
20
55
|
new multiplyNode_1.MultiplyNode(affines[0].a.toTree(), "x".toTree()),
|
|
21
56
|
affines[0].b.toTree(),
|
|
@@ -28,30 +63,37 @@ const getDoubleDistributivityQuestion = () => {
|
|
|
28
63
|
new multiplyNode_1.MultiplyNode(subTerms[1], subTerms[2], { forceTimesSign: true }),
|
|
29
64
|
new multiplyNode_1.MultiplyNode(subTerms[1], subTerms[3], { forceTimesSign: true }),
|
|
30
65
|
];
|
|
31
|
-
|
|
66
|
+
return `
|
|
67
|
+
${(0, alignTex_1.alignTex)([
|
|
68
|
+
[statementTex, "=", (0, operatorComposition_1.operatorComposition)(addNode_1.AddNode, subMultiplications).toTex()],
|
|
69
|
+
[
|
|
70
|
+
"",
|
|
71
|
+
"=",
|
|
72
|
+
(0, operatorComposition_1.operatorComposition)(addNode_1.AddNode, subMultiplications.map((e) => e.simplify())).toTex(),
|
|
73
|
+
],
|
|
74
|
+
["", "=", answer],
|
|
75
|
+
])}
|
|
76
|
+
|
|
77
|
+
`;
|
|
78
|
+
};
|
|
79
|
+
const getDoubleDistributivityQuestion = () => {
|
|
80
|
+
const affines = affine_1.AffineConstructor.differentRandoms(2, undefined, {
|
|
81
|
+
excludes: [0],
|
|
82
|
+
});
|
|
83
|
+
const statementTree = new multiplyNode_1.MultiplyNode(affines[0].toTree(), affines[1].toTree());
|
|
84
|
+
const identifiers = {
|
|
85
|
+
affine1Coeffs: affines[0].coefficients,
|
|
86
|
+
affine2Coeffs: affines[1].coefficients,
|
|
87
|
+
};
|
|
32
88
|
const question = {
|
|
33
|
-
instruction:
|
|
89
|
+
instruction: getInstruction(identifiers),
|
|
34
90
|
startStatement: statementTree.toTex(),
|
|
35
|
-
answer,
|
|
91
|
+
answer: getAnswer(identifiers),
|
|
36
92
|
keys: ["x"],
|
|
37
93
|
answerFormat: "tex",
|
|
38
|
-
identifiers
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
hint: "Multiplie chaque terme du premier facteur par chaque terme du second facteur, puis regroupe les termes similaires.",
|
|
43
|
-
correction: `
|
|
44
|
-
${(0, alignTex_1.alignTex)([
|
|
45
|
-
[statementTex, "=", (0, operatorComposition_1.operatorComposition)(addNode_1.AddNode, subMultiplications).toTex()],
|
|
46
|
-
[
|
|
47
|
-
"",
|
|
48
|
-
"=",
|
|
49
|
-
(0, operatorComposition_1.operatorComposition)(addNode_1.AddNode, subMultiplications.map((e) => e.simplify())).toTex(),
|
|
50
|
-
],
|
|
51
|
-
["", "=", answer],
|
|
52
|
-
])}
|
|
53
|
-
|
|
54
|
-
`,
|
|
94
|
+
identifiers,
|
|
95
|
+
hint: getHint(identifiers),
|
|
96
|
+
correction: getCorrection(identifiers),
|
|
55
97
|
};
|
|
56
98
|
return question;
|
|
57
99
|
};
|
|
@@ -79,14 +121,21 @@ const getPropositions = (n, { answer, affine1Coeffs, affine2Coeffs }) => {
|
|
|
79
121
|
}
|
|
80
122
|
return (0, shuffle_1.shuffle)(propositions);
|
|
81
123
|
};
|
|
82
|
-
const isAnswerValid = (ans, {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
124
|
+
const isAnswerValid = (ans, { answer }) => {
|
|
125
|
+
try {
|
|
126
|
+
const parsed = (0, polynomialParser_1.polynomialParser)(ans);
|
|
127
|
+
if (!parsed)
|
|
128
|
+
return false;
|
|
129
|
+
return (parsed
|
|
130
|
+
.simplify({
|
|
131
|
+
forbidFactorize: true,
|
|
132
|
+
towardsDistribute: true,
|
|
133
|
+
})
|
|
134
|
+
.toTex() === answer);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
return (0, handleVEAError_1.handleVEAError)(err);
|
|
138
|
+
}
|
|
90
139
|
};
|
|
91
140
|
exports.doubleDistributivity = {
|
|
92
141
|
id: "doubleDistri",
|
|
@@ -102,4 +151,8 @@ exports.doubleDistributivity = {
|
|
|
102
151
|
isAnswerValid,
|
|
103
152
|
subject: "Mathématiques",
|
|
104
153
|
hasHintAndCorrection: true,
|
|
154
|
+
getInstruction,
|
|
155
|
+
getAnswer,
|
|
156
|
+
getCorrection,
|
|
157
|
+
getHint,
|
|
105
158
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleDistributivity.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/distributivity/simpleDistributivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"simpleDistributivity.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/distributivity/simpleDistributivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,0BAA0B,CAAC;AAalC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAqGF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAmBtD,CAAC"}
|
|
@@ -10,6 +10,8 @@ const addNode_1 = require("../../../../tree/nodes/operators/addNode");
|
|
|
10
10
|
const multiplyNode_1 = require("../../../../tree/nodes/operators/multiplyNode");
|
|
11
11
|
const alignTex_1 = require("../../../../utils/latex/alignTex");
|
|
12
12
|
const shuffle_1 = require("../../../../utils/alea/shuffle");
|
|
13
|
+
const handleVEAError_1 = require("../../../../utils/errors/handleVEAError");
|
|
14
|
+
const polynomialParser_1 = require("../../../../tree/parsers/polynomialParser");
|
|
13
15
|
const buildStatement = (identifiers) => {
|
|
14
16
|
const { a, b, coeff } = identifiers;
|
|
15
17
|
const affine = new affine_1.Affine(a, b);
|
|
@@ -18,7 +20,11 @@ const buildStatement = (identifiers) => {
|
|
|
18
20
|
};
|
|
19
21
|
const getInstruction = (identifiers) => {
|
|
20
22
|
const statementTex = buildStatement(identifiers).toTex();
|
|
21
|
-
return `Développer et réduire :
|
|
23
|
+
return `Développer et réduire :
|
|
24
|
+
|
|
25
|
+
$$
|
|
26
|
+
${statementTex}
|
|
27
|
+
$$`;
|
|
22
28
|
};
|
|
23
29
|
const getAnswer = (identifiers) => {
|
|
24
30
|
const { a, b, coeff } = identifiers;
|
|
@@ -75,11 +81,16 @@ const getPropositions = (n, { answer, a, b, coeff }) => {
|
|
|
75
81
|
}
|
|
76
82
|
return (0, shuffle_1.shuffle)(propositions);
|
|
77
83
|
};
|
|
78
|
-
const isAnswerValid = (ans, { a, b, coeff }) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
const isAnswerValid = (ans, { answer, a, b, coeff }) => {
|
|
85
|
+
try {
|
|
86
|
+
const parsed = (0, polynomialParser_1.polynomialParser)(ans);
|
|
87
|
+
if (!parsed)
|
|
88
|
+
return false;
|
|
89
|
+
return parsed.simplify().toTex() === answer;
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
return (0, handleVEAError_1.handleVEAError)(err);
|
|
93
|
+
}
|
|
83
94
|
};
|
|
84
95
|
exports.simpleDistributivity = {
|
|
85
96
|
id: "simpleDistri",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polynomialParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/polynomialParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AASvD,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;
|
|
1
|
+
{"version":3,"file":"polynomialParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/polynomialParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AASvD,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,eAAO,MAAM,gBAAgB,QAAS,MAAM,SAAS,IAAI,8OAkCxD,CAAC"}
|
|
@@ -10,6 +10,7 @@ const latexParser_1 = require("./latexParser");
|
|
|
10
10
|
const monomParser_1 = require("./monomParser");
|
|
11
11
|
const numberParser_1 = require("./numberParser");
|
|
12
12
|
//!parses polynomes sous forme développée
|
|
13
|
+
//! ne surtout pas transformer ça en un parse généraliste (qui pourrait parse une forme factorisée par exemple)
|
|
13
14
|
//minDegree = 0, max = undefined
|
|
14
15
|
const polynomialParser = (ans, opts) => {
|
|
15
16
|
try {
|