math-exercises 3.0.215 → 3.0.217

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 (128) hide show
  1. package/lib/exercises/math/arithmetic/whichDayInXDays.d.ts.map +1 -1
  2. package/lib/exercises/math/arithmetic/whichDayInXDays.js +2 -1
  3. package/lib/exercises/math/calculLitteral/equation/exp/expOfFEqualsExpOfGEquation.d.ts.map +1 -1
  4. package/lib/exercises/math/calculLitteral/equation/exp/expOfFEqualsExpOfGEquation.js +19 -32
  5. package/lib/exercises/math/complex/unitRoots/giveOneSolutionToComplexPowNEqualsOne.js +1 -1
  6. package/lib/exercises/math/conversion/clock/index.d.ts +0 -1
  7. package/lib/exercises/math/conversion/clock/index.d.ts.map +1 -1
  8. package/lib/exercises/math/conversion/clock/index.js +1 -1
  9. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.js +2 -2
  10. package/lib/exercises/math/graphs/adjacentMatrixPath.d.ts +10 -0
  11. package/lib/exercises/math/graphs/adjacentMatrixPath.d.ts.map +1 -0
  12. package/lib/exercises/math/graphs/adjacentMatrixPath.js +89 -0
  13. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.d.ts +7 -0
  14. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.d.ts.map +1 -0
  15. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.js +98 -0
  16. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.d.ts +8 -0
  17. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.d.ts.map +1 -0
  18. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.js +96 -0
  19. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.d.ts +15 -0
  20. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.d.ts.map +1 -0
  21. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.js +262 -0
  22. package/lib/exercises/math/graphs/graphsCheckIsConnectedGraph.d.ts +11 -0
  23. package/lib/exercises/math/graphs/graphsCheckIsConnectedGraph.d.ts.map +1 -0
  24. package/lib/exercises/math/graphs/graphsCheckIsConnectedGraph.js +178 -0
  25. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.d.ts +11 -0
  26. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.d.ts.map +1 -0
  27. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.js +178 -0
  28. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.d.ts +19 -0
  29. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.d.ts.map +1 -0
  30. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.js +301 -0
  31. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.d.ts +16 -0
  32. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.d.ts.map +1 -0
  33. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.js +207 -0
  34. package/lib/exercises/math/graphs/graphsDegreeOfVertex.d.ts +15 -0
  35. package/lib/exercises/math/graphs/graphsDegreeOfVertex.d.ts.map +1 -0
  36. package/lib/exercises/math/graphs/graphsDegreeOfVertex.js +232 -0
  37. package/lib/exercises/math/graphs/graphsOrderOfGraph.d.ts +14 -0
  38. package/lib/exercises/math/graphs/graphsOrderOfGraph.d.ts.map +1 -0
  39. package/lib/exercises/math/graphs/graphsOrderOfGraph.js +222 -0
  40. package/lib/exercises/math/graphs/index.d.ts +10 -0
  41. package/lib/exercises/math/graphs/index.d.ts.map +1 -0
  42. package/lib/exercises/math/graphs/index.js +9 -0
  43. package/lib/exercises/math/index.d.ts +1 -0
  44. package/lib/exercises/math/index.d.ts.map +1 -1
  45. package/lib/exercises/math/index.js +1 -0
  46. package/lib/exercises/math/integration/fromExpr/integralFromExpr.d.ts.map +1 -1
  47. package/lib/exercises/math/integration/fromExpr/integralFromExpr.js +2 -0
  48. package/lib/exercises/math/matrices/areMatricesInverse.d.ts +9 -0
  49. package/lib/exercises/math/matrices/areMatricesInverse.d.ts.map +1 -0
  50. package/lib/exercises/math/matrices/areMatricesInverse.js +106 -0
  51. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.d.ts +9 -0
  52. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.d.ts.map +1 -0
  53. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.js +144 -0
  54. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.d.ts +8 -0
  55. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.d.ts.map +1 -0
  56. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.js +148 -0
  57. package/lib/exercises/math/matrices/index.d.ts +12 -0
  58. package/lib/exercises/math/matrices/index.d.ts.map +1 -1
  59. package/lib/exercises/math/matrices/index.js +12 -0
  60. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.d.ts +8 -0
  61. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.d.ts.map +1 -0
  62. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.js +132 -0
  63. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.d.ts +8 -0
  64. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.d.ts.map +1 -0
  65. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.js +152 -0
  66. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.d.ts +8 -0
  67. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.d.ts.map +1 -0
  68. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.js +155 -0
  69. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.d.ts +8 -0
  70. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.d.ts.map +1 -0
  71. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.js +142 -0
  72. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.d.ts +8 -0
  73. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.d.ts.map +1 -0
  74. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.js +237 -0
  75. package/lib/exercises/math/matrices/matrixComputeLinearCombination.d.ts +15 -0
  76. package/lib/exercises/math/matrices/matrixComputeLinearCombination.d.ts.map +1 -0
  77. package/lib/exercises/math/matrices/matrixComputeLinearCombination.js +232 -0
  78. package/lib/exercises/math/matrices/matrixComputePower.d.ts +12 -0
  79. package/lib/exercises/math/matrices/matrixComputePower.d.ts.map +1 -0
  80. package/lib/exercises/math/matrices/matrixComputePower.js +230 -0
  81. package/lib/exercises/math/matrices/matrixComputeProduct.d.ts +9 -0
  82. package/lib/exercises/math/matrices/matrixComputeProduct.d.ts.map +1 -0
  83. package/lib/exercises/math/matrices/matrixComputeProduct.js +178 -0
  84. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.d.ts +8 -0
  85. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.d.ts.map +1 -0
  86. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.js +105 -0
  87. package/lib/exercises/math/spaceGeometry/parametricLine/lineLineRelativePositionsFromParametricLines.d.ts.map +1 -1
  88. package/lib/exercises/math/spaceGeometry/parametricLine/lineLineRelativePositionsFromParametricLines.js +56 -3
  89. package/lib/exercises/math/spaceGeometry/planes/findNormalVectorFromPlaneEquation.d.ts.map +1 -1
  90. package/lib/exercises/math/spaceGeometry/planes/findNormalVectorFromPlaneEquation.js +6 -0
  91. package/lib/exercises/vea/matrixVEA.d.ts +2 -0
  92. package/lib/exercises/vea/matrixVEA.d.ts.map +1 -0
  93. package/lib/exercises/vea/matrixVEA.js +1 -0
  94. package/lib/exercises/vea/treeTableVEA.d.ts.map +1 -1
  95. package/lib/exercises/vea/treeTableVEA.js +2 -0
  96. package/lib/index.d.ts +86 -13
  97. package/lib/index.d.ts.map +1 -1
  98. package/lib/math/geometry/point.d.ts.map +1 -1
  99. package/lib/math/geometry/point.js +3 -1
  100. package/lib/math/graphs/graph.d.ts +43 -0
  101. package/lib/math/graphs/graph.d.ts.map +1 -0
  102. package/lib/math/graphs/graph.js +447 -0
  103. package/lib/math/matrices/matrix.d.ts +42 -3
  104. package/lib/math/matrices/matrix.d.ts.map +1 -1
  105. package/lib/math/matrices/matrix.js +173 -7
  106. package/lib/math/matrices/parseMatrix.d.ts +3 -0
  107. package/lib/math/matrices/parseMatrix.d.ts.map +1 -0
  108. package/lib/math/matrices/parseMatrix.js +22 -0
  109. package/lib/math/systems/generalSystem.d.ts +2 -0
  110. package/lib/math/systems/generalSystem.d.ts.map +1 -1
  111. package/lib/math/systems/generalSystem.js +5 -0
  112. package/lib/math/utils/graphs/graphRenderer.d.ts +25 -0
  113. package/lib/math/utils/graphs/graphRenderer.d.ts.map +1 -0
  114. package/lib/math/utils/graphs/graphRenderer.js +123 -0
  115. package/lib/playground.d.ts +6 -1
  116. package/lib/playground.d.ts.map +1 -1
  117. package/lib/playground.js +6 -5
  118. package/lib/tree/parsers/latexParser.d.ts +1 -1
  119. package/lib/tree/utilities/nodeSimplifier.d.ts +1 -1
  120. package/lib/types/keyIds.d.ts +2 -0
  121. package/lib/types/keyIds.d.ts.map +1 -1
  122. package/lib/utils/arrays/arrayChunks.d.ts +9 -0
  123. package/lib/utils/arrays/arrayChunks.d.ts.map +1 -0
  124. package/lib/utils/arrays/arrayChunks.js +34 -0
  125. package/lib/utils/strings/ordinalSuffixed.d.ts +2 -0
  126. package/lib/utils/strings/ordinalSuffixed.d.ts.map +1 -0
  127. package/lib/utils/strings/ordinalSuffixed.js +5 -0
  128. package/package.json +7 -1
@@ -0,0 +1,232 @@
1
+ import { GeneratorOptionTarget, GeneratorOptionType, addValidProp, propWhile, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { Matrix, MatrixConstructor, } from "../../../math/matrices/matrix.js";
4
+ import { parseMatrix } from "../../../math/matrices/parseMatrix.js";
5
+ import { NodeConstructor, } from "../../../tree/nodes/nodeConstructor.js";
6
+ import { add } from "../../../tree/nodes/operators/addNode.js";
7
+ import { multiply } from "../../../tree/nodes/operators/multiplyNode.js";
8
+ import { probaLawFlip } from "../../../utils/alea/probaLawFlip.js";
9
+ import { shuffle } from "../../../utils/alea/shuffle.js";
10
+ import { zip } from "../../../utils/arrays/arrayZip.js";
11
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
12
+ import { alignTex } from "../../../utils/latex/alignTex.js";
13
+ const getHydrated = (identifiers) => {
14
+ const { matIdsA, matIdsB, nodeIdsKA, nodeIdsKB } = identifiers;
15
+ const [matA, matB] = [matIdsA, matIdsB].map((matIds) => MatrixConstructor.fromIdentifiers(matIds));
16
+ const [nodeKA, nodeKB] = [nodeIdsKA, nodeIdsKB].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
17
+ const nodeExprInstruction = add(multiply(nodeKA, "A".toTree()), multiply(nodeKB, "B".toTree()));
18
+ return {
19
+ matA,
20
+ matB,
21
+ nodeKA,
22
+ nodeKB,
23
+ nodeExprInstruction,
24
+ };
25
+ };
26
+ const getInstruction = (identifiers) => {
27
+ const { matA, matB, nodeExprInstruction } = getHydrated(identifiers);
28
+ return `Soient :
29
+
30
+ $$
31
+ A = ${matA.toTex()}
32
+ $$
33
+
34
+ $$
35
+ B = ${matB.toTex()}
36
+ $$
37
+
38
+ Calculer $${nodeExprInstruction.toTex()}$.`;
39
+ };
40
+ const getAnswer = (identifiers) => {
41
+ const { matA, matB, nodeKA, nodeKB } = getHydrated(identifiers);
42
+ const matLinComb = matA.times(nodeKA).add(matB.times(nodeKB));
43
+ const matLinCombSimplified = matLinComb.simplify({ towardsDistribute: true });
44
+ return matLinCombSimplified.toTex();
45
+ };
46
+ const getHint = (_identifiers, optsIn) => {
47
+ const opts = optsIn ?? optsDefault;
48
+ return `Soient $A$ et $B$ deux matrices à $2$ lignes et $2$ colonnes. Soit $k$ un nombre réel.
49
+
50
+ $$
51
+ A = \\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}
52
+ $$
53
+
54
+ $$
55
+ B = \\begin{pmatrix} r & s \\\\ t & u \\end{pmatrix}
56
+ $$
57
+
58
+ alors :
59
+
60
+ $$
61
+ A + B = \\begin{pmatrix} a+r & b+s \\\\ c+t & d+u \\end{pmatrix}
62
+ $$
63
+
64
+ ${(() => {
65
+ switch (opts.typeLinComb) {
66
+ case "Combinaison linéaire":
67
+ return `
68
+
69
+ $$
70
+ kA = \\begin{pmatrix} ka & kb \\\\ kc & kd \\end{pmatrix}
71
+ $$
72
+
73
+ `;
74
+ default:
75
+ return "";
76
+ }
77
+ })()}`;
78
+ };
79
+ const getCorrection = (identifiers, optsIn) => {
80
+ const opts = optsIn ?? optsDefault;
81
+ const { matA, matB, nodeExprInstruction, nodeKA, nodeKB } = getHydrated(identifiers);
82
+ const matKAA = matA.times(nodeKA);
83
+ const matKBB = matB.times(nodeKB);
84
+ const matLinComb = matKAA.add(matKBB);
85
+ const [texKA, texKB] = [nodeKA, nodeKB]
86
+ .map((node) => node.toTex())
87
+ .map((str) => (str === "1" ? "" : str.startsWith("-") ? `(${str})` : str));
88
+ switch (opts.typeLinComb) {
89
+ case "Combinaison linéaire":
90
+ return `${alignTex([
91
+ ["", nodeExprInstruction.toTex()],
92
+ ["=", `${texKA} ${matA.toTex()} + ${texKB} ${matB.toTex()}`],
93
+ ["=", `${matKAA.toTex()} + ${matKBB.toTex()}`],
94
+ ["=", matLinComb.toTex()],
95
+ ["=", matLinComb.simplify({ towardsDistribute: true }).toTex()],
96
+ ])}`;
97
+ case "Somme simple":
98
+ return `${alignTex([
99
+ ["", nodeExprInstruction.toTex()],
100
+ ["=", `${matKAA.toTex()} + ${matKBB.toTex()}`],
101
+ ["=", matLinComb.toTex()],
102
+ ["=", matLinComb.simplify({ towardsDistribute: true }).toTex()],
103
+ ])}`;
104
+ default:
105
+ throw new Error("Unsupported opts.typeLinComb: " + opts.typeLinComb);
106
+ }
107
+ };
108
+ const getPropositions = (n, { answer, ...identifiers }, optsIn) => {
109
+ const opts = optsIn ?? optsDefault;
110
+ const propositions = [];
111
+ addValidProp(propositions, answer);
112
+ const { matA, matB, nodeKA, nodeKB } = getHydrated(identifiers);
113
+ const matKAA = matA.times(nodeKA);
114
+ const matKBB = matB.times(nodeKB);
115
+ //student: (kA A) * (kB B)
116
+ {
117
+ const matWrong = matKAA.matrixProduct(matKBB);
118
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
119
+ }
120
+ //student: strange addition which resembles product
121
+ {
122
+ function matrixSumWrong(mat1, mat2) {
123
+ const mat2Transposed = mat2.transposed();
124
+ const arrElementSumWrong = mat1.elements.map((row) => mat2Transposed.elements.map((column) => zip(row, column).reduce((acc, [nodeAik, nodeBkj], i) => {
125
+ const nodeAikBkj = add(nodeAik, nodeBkj);
126
+ if (i === 0) {
127
+ return nodeAikBkj;
128
+ }
129
+ else {
130
+ return add(acc, nodeAikBkj);
131
+ }
132
+ }, (0).toTree())));
133
+ return new Matrix(arrElementSumWrong);
134
+ }
135
+ const matWrong = matrixSumWrong(matKAA, matKBB);
136
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
137
+ }
138
+ //filler
139
+ {
140
+ propWhile(propositions, n, () => {
141
+ const identifiersWrong = createRandomIdentifiers(opts);
142
+ tryToAddWrongProp(propositions, getAnswer(identifiersWrong));
143
+ });
144
+ }
145
+ return shuffleProps(propositions, n);
146
+ };
147
+ const getKeys = () => {
148
+ return ["mat-2-2"];
149
+ };
150
+ const isAnswerValid = (ans, { answer }) => {
151
+ try {
152
+ const matAns = parseMatrix(ans);
153
+ const matAnswer = parseMatrix(answer);
154
+ return matAns.equals(matAnswer);
155
+ }
156
+ catch (e) {
157
+ handleVEAError(e);
158
+ return false;
159
+ }
160
+ };
161
+ const createRandomIdentifiers = (opts) => {
162
+ const [nodeKA, nodeKB] = (() => {
163
+ switch (opts.typeLinComb) {
164
+ case "Somme simple":
165
+ return [(1).toTree(), (1).toTree()];
166
+ case "Combinaison linéaire":
167
+ return shuffle(probaLawFlip([
168
+ [[(1).toTree(), (2).toTree()], 0.35],
169
+ [[(1).toTree(), (3).toTree()], 0.25],
170
+ [[(1).toTree(), (-2).toTree()], 0.15],
171
+ [[(1).toTree(), (-1).toTree()], 0.15],
172
+ ]));
173
+ default:
174
+ throw new Error("Unsupported opts.typeLinComb: " + opts.typeLinComb);
175
+ }
176
+ })();
177
+ const matA = MatrixConstructor.random(2, 2);
178
+ const matB = MatrixConstructor.random(2, 2);
179
+ const identifiers = {
180
+ matIdsA: matA.toIdentifiers(),
181
+ matIdsB: matB.toIdentifiers(),
182
+ nodeIdsKA: nodeKA.toIdentifiers(),
183
+ nodeIdsKB: nodeKB.toIdentifiers(),
184
+ };
185
+ return identifiers;
186
+ };
187
+ const getMatrixComputeLinearCombinationQuestion = (optsIn) => {
188
+ const opts = optsIn ?? optsDefault;
189
+ const identifiers = createRandomIdentifiers(opts);
190
+ return getQuestionFromIdentifiers(identifiers, opts);
191
+ };
192
+ const getQuestionFromIdentifiers = (identifiers, optsIn) => {
193
+ const question = {
194
+ answer: getAnswer(identifiers),
195
+ instruction: getInstruction(identifiers),
196
+ keys: getKeys(identifiers),
197
+ answerFormat: "tex",
198
+ identifiers,
199
+ hint: getHint(identifiers, optsIn),
200
+ correction: getCorrection(identifiers, optsIn),
201
+ options: optsIn,
202
+ };
203
+ return question;
204
+ };
205
+ const optsDefault = {
206
+ typeLinComb: "Combinaison linéaire",
207
+ };
208
+ const options = [
209
+ {
210
+ id: "typeLinComb",
211
+ label: "Type de combinaison linéaire",
212
+ target: GeneratorOptionTarget.generation,
213
+ type: GeneratorOptionType.select,
214
+ values: ["Somme simple", "Combinaison linéaire"],
215
+ defaultValue: optsDefault.typeLinComb,
216
+ },
217
+ ];
218
+ export const matrixComputeLinearCombination = {
219
+ id: "matrixComputeLinearCombination",
220
+ connector: "=",
221
+ label: "Calculer une combinaison linéaire de deux matrices",
222
+ isSingleStep: true,
223
+ generator: (nb, opts) => getDistinctQuestions(() => getMatrixComputeLinearCombinationQuestion(opts), nb),
224
+ options,
225
+ qcmTimer: 60,
226
+ freeTimer: 60,
227
+ getPropositions,
228
+ isAnswerValid,
229
+ subject: "Mathématiques",
230
+ getQuestionFromIdentifiers,
231
+ hasHintAndCorrection: true,
232
+ };
@@ -0,0 +1,12 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ import { MatrixIdentifiers } from "../../../math/matrices/matrix.js";
3
+ type Identifiers = {
4
+ matIdsA: MatrixIdentifiers;
5
+ exponent: number;
6
+ };
7
+ type Options = {
8
+ exponent: string;
9
+ };
10
+ export declare const matrixComputePower: Exercise<Identifiers, Options>;
11
+ export {};
12
+ //# sourceMappingURL=matrixComputePower.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrixComputePower.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/matrices/matrixComputePower.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAmBT,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAGL,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAQvC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA4PF,KAAK,OAAO,GAAG;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAgBF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAe7D,CAAC"}
@@ -0,0 +1,230 @@
1
+ import { GeneratorOptionTarget, GeneratorOptionType, addValidProp, propWhile, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { Matrix, MatrixConstructor, } from "../../../math/matrices/matrix.js";
4
+ import { parseMatrix } from "../../../math/matrices/parseMatrix.js";
5
+ import { multiply } from "../../../tree/nodes/operators/multiplyNode.js";
6
+ import { power } from "../../../tree/nodes/operators/powerNode.js";
7
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
8
+ import { alignTex } from "../../../utils/latex/alignTex.js";
9
+ const getHydrated = (identifiers) => {
10
+ const { matIdsA, exponent } = identifiers;
11
+ const [matA] = [matIdsA].map((matIds) => MatrixConstructor.fromIdentifiers(matIds));
12
+ const nodeExprInstruction = power("A".toTree(), exponent);
13
+ return {
14
+ matA,
15
+ nodeExprInstruction,
16
+ };
17
+ };
18
+ const getInstruction = (identifiers) => {
19
+ const { matA, nodeExprInstruction } = getHydrated(identifiers);
20
+ return `Soit :
21
+
22
+ $$
23
+ A = ${matA.toTex()}
24
+ $$
25
+
26
+ Calculer $${nodeExprInstruction.toTex()}$.`;
27
+ };
28
+ const getAnswer = (identifiers) => {
29
+ const { exponent } = identifiers;
30
+ const { matA } = getHydrated(identifiers);
31
+ const matProduct = matA.power(exponent);
32
+ const matProductSimplified = matProduct.simplify({ towardsDistribute: true });
33
+ return matProductSimplified.toTex();
34
+ };
35
+ const getHint = () => {
36
+ const matA = new Matrix([
37
+ ["a".toTree(), "b".toTree()],
38
+ ["c".toTree(), "d".toTree()],
39
+ ]);
40
+ const matASpaced = new Matrix([
41
+ ["\\ \\ \\ a".toTree(), "\\ \\ \\ \\ \\ b \\ \\ \\ ".toTree()],
42
+ ["\\ \\ \\ c".toTree(), "\\ \\ \\ \\ \\ d \\ \\ \\ ".toTree()],
43
+ ]);
44
+ return `Soient $A$ une matrice à $2$ lignes et $2$ colonnes à coefficients réels.
45
+
46
+ $$
47
+ A = ${matA.toTex()}
48
+ $$
49
+
50
+ Pour calculer $A^2=AA$,
51
+ tu peux disposer les matrices de cette façon pour ne pas te tromper :
52
+
53
+ $$
54
+ \\begin{matrix} {\\begin{matrix} \\ & \\ \\\\ \\ & \\ \\end{matrix}} & {${matASpaced.toTex()}} \\\\ {${matA.toTex()}} & {\\begin{pmatrix} {...} & {ab+bd} \\\\ {...} & {...} \\end{pmatrix}} \\end{matrix}
55
+ $$
56
+
57
+ Ce qui donne :
58
+
59
+ $$
60
+ A^2 = AA = ${matA.matrixProduct(matA).toTex()}
61
+ $$
62
+
63
+ Continue ainsi pour les autres puissances de $A$ :
64
+
65
+ $$
66
+ A^3 = AAA = A^2 A
67
+ $$
68
+
69
+ etc.
70
+
71
+ `;
72
+ };
73
+ const getCorrection = (identifiers) => {
74
+ const { exponent } = identifiers;
75
+ const { matA } = getHydrated(identifiers);
76
+ const matA2 = matA.matrixProduct(matA);
77
+ const matA2Simplified = matA2.simplify({ towardsDistribute: true });
78
+ const matA3 = matA2Simplified.matrixProduct(matA);
79
+ const matA3Simplified = matA3.simplify({ towardsDistribute: true });
80
+ switch (exponent) {
81
+ case 2:
82
+ return `${alignTex([
83
+ ["", "A^2"],
84
+ ["=", `${matA.toTex()} ${matA.toTex()}`],
85
+ ["=", matA2.toTex()],
86
+ ["=", matA2Simplified.toTex()],
87
+ ])}`;
88
+ case 3:
89
+ return `
90
+
91
+ ${alignTex([
92
+ ["", "A^2"],
93
+ ["=", `${matA.toTex()} ${matA.toTex()}`],
94
+ ["=", matA2.toTex()],
95
+ ["=", matA2Simplified.toTex()],
96
+ ])}
97
+
98
+ ${alignTex([
99
+ ["", "A^3"],
100
+ ["=", "A^2 A"],
101
+ ["=", `${matA2Simplified.toTex()} ${matA.toTex()}`],
102
+ ["=", matA3.toTex()],
103
+ ["=", matA3Simplified.toTex()],
104
+ ])}
105
+
106
+ `;
107
+ default:
108
+ throw new Error("Unsupported exponent: " + exponent);
109
+ }
110
+ };
111
+ const getPropositions = (n, { answer, ...identifiers }, optsIn) => {
112
+ const opts = optsIn ?? optsDefault;
113
+ const propositions = [];
114
+ addValidProp(propositions, answer);
115
+ const { exponent } = identifiers;
116
+ const { matA } = getHydrated(identifiers);
117
+ function createPowerFuncWrong(funcAB) {
118
+ const func = (matA, exponent) => [...Array(exponent).keys()].reduce((acc, i) => {
119
+ if (i === 0) {
120
+ return matA;
121
+ }
122
+ else {
123
+ return funcAB(acc, matA);
124
+ }
125
+ }, matA);
126
+ return func;
127
+ }
128
+ //student: AB = A+B
129
+ {
130
+ const powerFuncWrong = createPowerFuncWrong((matA, matB) => matA.add(matB));
131
+ const matWrong = powerFuncWrong(matA, exponent);
132
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
133
+ }
134
+ //student: AB = (a_{ij}b_{ij})
135
+ {
136
+ function matrixProductWrong(mat1, mat2) {
137
+ const arrElementSumWrong = mat1.elements.map((row, i) => row.map((elt1, j) => {
138
+ const elt2 = mat2.elements[i][j];
139
+ return multiply(elt1, elt2);
140
+ }));
141
+ return new Matrix(arrElementSumWrong);
142
+ }
143
+ const powerFuncWrong = createPowerFuncWrong(matrixProductWrong);
144
+ const matWrong = powerFuncWrong(matA, exponent);
145
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
146
+ }
147
+ //student: AB = (sum(a_{ik}b_{jk}))
148
+ {
149
+ const powerFuncWrong = createPowerFuncWrong((matA, matB) => matA.matrixProduct(matB.transposed()));
150
+ const matWrong = powerFuncWrong(matA, exponent);
151
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
152
+ }
153
+ //filler
154
+ {
155
+ propWhile(propositions, n, () => {
156
+ const identifiersWrong = createRandomIdentifiers(opts);
157
+ tryToAddWrongProp(propositions, getAnswer(identifiersWrong));
158
+ });
159
+ }
160
+ return shuffleProps(propositions, n);
161
+ };
162
+ const getKeys = () => {
163
+ return ["mat-2-2"];
164
+ };
165
+ const isAnswerValid = (ans, { answer }) => {
166
+ try {
167
+ const matAns = parseMatrix(ans);
168
+ const matAnswer = parseMatrix(answer);
169
+ return matAns.equals(matAnswer);
170
+ }
171
+ catch (e) {
172
+ handleVEAError(e);
173
+ return false;
174
+ }
175
+ };
176
+ const createRandomIdentifiers = (opts) => {
177
+ const matA = MatrixConstructor.random(2, 2);
178
+ const exponent = parseInt(opts.exponent);
179
+ const identifiers = {
180
+ matIdsA: matA.toIdentifiers(),
181
+ exponent,
182
+ };
183
+ return identifiers;
184
+ };
185
+ const getMatrixComputePowerQuestion = (optsIn) => {
186
+ const opts = optsIn ?? optsDefault;
187
+ const identifiers = createRandomIdentifiers(opts);
188
+ return getQuestionFromIdentifiers(identifiers, opts);
189
+ };
190
+ const getQuestionFromIdentifiers = (identifiers, optsIn) => {
191
+ const question = {
192
+ answer: getAnswer(identifiers),
193
+ instruction: getInstruction(identifiers),
194
+ keys: getKeys(identifiers),
195
+ answerFormat: "tex",
196
+ identifiers,
197
+ hint: getHint(identifiers),
198
+ correction: getCorrection(identifiers),
199
+ options: optsIn,
200
+ };
201
+ return question;
202
+ };
203
+ const optsDefault = {
204
+ exponent: "2",
205
+ };
206
+ const options = [
207
+ {
208
+ id: "exponent",
209
+ label: "Valeur de l'exposant",
210
+ target: GeneratorOptionTarget.generation,
211
+ type: GeneratorOptionType.select,
212
+ values: ["2", "3"],
213
+ defaultValue: optsDefault.exponent,
214
+ },
215
+ ];
216
+ export const matrixComputePower = {
217
+ id: "matrixComputePower",
218
+ connector: "=",
219
+ label: "Calculer une puissance d'une matrice",
220
+ isSingleStep: true,
221
+ generator: (nb, opts) => getDistinctQuestions(() => getMatrixComputePowerQuestion(opts), nb),
222
+ options,
223
+ qcmTimer: 60,
224
+ freeTimer: 60,
225
+ getPropositions,
226
+ isAnswerValid,
227
+ subject: "Mathématiques",
228
+ getQuestionFromIdentifiers,
229
+ hasHintAndCorrection: true,
230
+ };
@@ -0,0 +1,9 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ import { MatrixIdentifiers } from "../../../math/matrices/matrix.js";
3
+ type Identifiers = {
4
+ matIdsA: MatrixIdentifiers;
5
+ matIdsB: MatrixIdentifiers;
6
+ };
7
+ export declare const matrixComputeProduct: Exercise<Identifiers>;
8
+ export {};
9
+ //# sourceMappingURL=matrixComputeProduct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrixComputeProduct.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/matrices/matrixComputeProduct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAgBT,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAGL,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAOvC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AA0MF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CActD,CAAC"}
@@ -0,0 +1,178 @@
1
+ import { addValidProp, propWhile, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { Matrix, MatrixConstructor, } from "../../../math/matrices/matrix.js";
4
+ import { parseMatrix } from "../../../math/matrices/parseMatrix.js";
5
+ import { multiply } from "../../../tree/nodes/operators/multiplyNode.js";
6
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
7
+ import { alignTex } from "../../../utils/latex/alignTex.js";
8
+ const getHydrated = (identifiers) => {
9
+ const { matIdsA, matIdsB } = identifiers;
10
+ const [matA, matB] = [matIdsA, matIdsB].map((matIds) => MatrixConstructor.fromIdentifiers(matIds));
11
+ const nodeExprInstruction = multiply("A".toTree(), "B".toTree()).simplify();
12
+ return {
13
+ matA,
14
+ matB,
15
+ nodeExprInstruction,
16
+ };
17
+ };
18
+ const getInstruction = (identifiers) => {
19
+ const { matA, matB, nodeExprInstruction } = getHydrated(identifiers);
20
+ return `Soient :
21
+
22
+ $$
23
+ A = ${matA.toTex()}
24
+ $$
25
+
26
+ $$
27
+ B = ${matB.toTex()}
28
+ $$
29
+
30
+ Calculer $${nodeExprInstruction.toTex()}$.`;
31
+ };
32
+ const getAnswer = (identifiers) => {
33
+ const { matA, matB } = getHydrated(identifiers);
34
+ const matProduct = matA.matrixProduct(matB);
35
+ const matProductSimplified = matProduct.simplify({ towardsDistribute: true });
36
+ return matProductSimplified.toTex();
37
+ };
38
+ const getHint = () => {
39
+ const matA = new Matrix([
40
+ ["a".toTree(), "b".toTree()],
41
+ ["c".toTree(), "d".toTree()],
42
+ ]);
43
+ const matB = new Matrix([
44
+ ["r".toTree(), "s".toTree()],
45
+ ["t".toTree(), "u".toTree()],
46
+ ]);
47
+ const matBSpaced = new Matrix([
48
+ ["\\ \\ \\ r".toTree(), "\\ \\ \\ \\ \\ s \\ \\ \\ ".toTree()],
49
+ ["\\ \\ \\ t".toTree(), "\\ \\ \\ \\ \\ u \\ \\ \\ ".toTree()],
50
+ ]);
51
+ return `Soient $A$ et $B$ deux matrices à $2$ lignes et $2$ colonnes à coefficients réels.
52
+
53
+ $$
54
+ A = ${matA.toTex()}
55
+ $$
56
+
57
+ $$
58
+ B = ${matB.toTex()}
59
+ $$
60
+
61
+ Pour calculer le produit matriciel $AB$,
62
+ tu peux disposer les matrices $A$ et $B$ de cette façon pour ne pas te tromper :
63
+
64
+ $$
65
+ \\begin{matrix} {\\begin{matrix} \\ & \\ \\\\ \\ & \\ \\end{matrix}} & {${matBSpaced.toTex()}} \\\\ {${matA.toTex()}} & {\\begin{pmatrix} {...} & {as+bu} \\\\ {...} & {...} \\end{pmatrix}} \\end{matrix}
66
+ $$
67
+
68
+ Ce qui donne :
69
+
70
+ $$
71
+ AB = ${matA.matrixProduct(matB).toTex()}
72
+ $$
73
+
74
+ `;
75
+ };
76
+ const getCorrection = (identifiers) => {
77
+ const { matA, matB, nodeExprInstruction } = getHydrated(identifiers);
78
+ const matProduct = matA.matrixProduct(matB);
79
+ const matProductSimplified = matProduct.simplify({ towardsDistribute: true });
80
+ return `${alignTex([
81
+ ["", nodeExprInstruction.toTex()],
82
+ ["=", `${matA.toTex()} ${matB.toTex()}`],
83
+ ["=", matProduct.toTex()],
84
+ ["=", matProductSimplified.toTex()],
85
+ ])}`;
86
+ };
87
+ const getPropositions = (n, { answer, ...identifiers }) => {
88
+ const propositions = [];
89
+ addValidProp(propositions, answer);
90
+ const { matA, matB } = getHydrated(identifiers);
91
+ //student: AB = A+B
92
+ {
93
+ const matWrong = matA.add(matB);
94
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
95
+ }
96
+ //student: AB = (a_{ij}b_{ij})
97
+ {
98
+ function matrixProductWrong(mat1, mat2) {
99
+ const arrElementSumWrong = mat1.elements.map((row, i) => row.map((elt1, j) => {
100
+ const elt2 = mat2.elements[i][j];
101
+ return multiply(elt1, elt2);
102
+ }));
103
+ return new Matrix(arrElementSumWrong);
104
+ }
105
+ const matWrong = matrixProductWrong(matA, matB);
106
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
107
+ }
108
+ //student: AB = (sum(a_{ik}b_{jk}))
109
+ {
110
+ const matWrong = matA.matrixProduct(matB.transposed());
111
+ tryToAddWrongProp(propositions, matWrong.simplify({ towardsDistribute: true }).toTex());
112
+ }
113
+ //filler
114
+ {
115
+ propWhile(propositions, n, () => {
116
+ const identifiersWrong = createRandomIdentifiers();
117
+ tryToAddWrongProp(propositions, getAnswer(identifiersWrong));
118
+ });
119
+ }
120
+ return shuffleProps(propositions, n);
121
+ };
122
+ const getKeys = () => {
123
+ return ["mat-2-2"];
124
+ };
125
+ const isAnswerValid = (ans, { answer }) => {
126
+ try {
127
+ const matAns = parseMatrix(ans);
128
+ const matAnswer = parseMatrix(answer);
129
+ return matAns.equals(matAnswer);
130
+ }
131
+ catch (e) {
132
+ handleVEAError(e);
133
+ return false;
134
+ }
135
+ };
136
+ const createRandomIdentifiers = () => {
137
+ const nodeKA = (1).toTree();
138
+ const nodeKB = (2).toTree();
139
+ const matA = MatrixConstructor.random(2, 2);
140
+ const matB = MatrixConstructor.random(2, 2);
141
+ const identifiers = {
142
+ matIdsA: matA.toIdentifiers(),
143
+ matIdsB: matB.toIdentifiers(),
144
+ nodeIdsKA: nodeKA.toIdentifiers(),
145
+ nodeIdsKB: nodeKB.toIdentifiers(),
146
+ };
147
+ return identifiers;
148
+ };
149
+ const getMatrixComputeProductQuestion = () => {
150
+ const identifiers = createRandomIdentifiers();
151
+ return getQuestionFromIdentifiers(identifiers);
152
+ };
153
+ const getQuestionFromIdentifiers = (identifiers) => {
154
+ const question = {
155
+ answer: getAnswer(identifiers),
156
+ instruction: getInstruction(identifiers),
157
+ keys: getKeys(identifiers),
158
+ answerFormat: "tex",
159
+ identifiers,
160
+ hint: getHint(identifiers),
161
+ correction: getCorrection(identifiers),
162
+ };
163
+ return question;
164
+ };
165
+ export const matrixComputeProduct = {
166
+ id: "matrixComputeProduct",
167
+ connector: "=",
168
+ label: "Calculer le produit de deux matrices",
169
+ isSingleStep: true,
170
+ generator: (nb) => getDistinctQuestions(getMatrixComputeProductQuestion, nb),
171
+ qcmTimer: 60,
172
+ freeTimer: 60,
173
+ getPropositions,
174
+ isAnswerValid,
175
+ subject: "Mathématiques",
176
+ getQuestionFromIdentifiers,
177
+ hasHintAndCorrection: true,
178
+ };
@@ -0,0 +1,8 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ import { GeneralSystemIdentifiers } from "../../../math/systems/generalSystem.js";
3
+ type Identifiers = {
4
+ systemIds: GeneralSystemIdentifiers;
5
+ };
6
+ export declare const writeMatrixAssociatedToSystem: Exercise<Identifiers>;
7
+ export {};
8
+ //# sourceMappingURL=writeMatrixAssociatedToSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeMatrixAssociatedToSystem.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/matrices/writeMatrixAssociatedToSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAEL,wBAAwB,EACzB,MAAM,qCAAqC,CAAC;AAG7C,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,wBAAwB,CAAC;CACrC,CAAC;AA6FF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,CAqB/D,CAAC"}