math-exercises 3.0.209 → 3.0.211

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 (31) hide show
  1. package/lib/exercises/math/functions/continuity/index.d.ts +2 -0
  2. package/lib/exercises/math/functions/continuity/index.d.ts.map +1 -1
  3. package/lib/exercises/math/functions/continuity/index.js +2 -0
  4. package/lib/exercises/math/functions/continuity/pyContinuityBalayageInstructionCompletion.d.ts +11 -0
  5. package/lib/exercises/math/functions/continuity/pyContinuityBalayageInstructionCompletion.d.ts.map +1 -0
  6. package/lib/exercises/math/functions/continuity/pyContinuityBalayageInstructionCompletion.js +276 -0
  7. package/lib/exercises/math/functions/continuity/pyContinuityDichotomyInstructionCompletion.d.ts +10 -0
  8. package/lib/exercises/math/functions/continuity/pyContinuityDichotomyInstructionCompletion.d.ts.map +1 -0
  9. package/lib/exercises/math/functions/continuity/pyContinuityDichotomyInstructionCompletion.js +265 -0
  10. package/lib/exercises/math/integration/algorithms/index.d.ts +2 -0
  11. package/lib/exercises/math/integration/algorithms/index.d.ts.map +1 -0
  12. package/lib/exercises/math/integration/algorithms/index.js +1 -0
  13. package/lib/exercises/math/integration/algorithms/pyIntegrationInstructionCompletion.d.ts +10 -0
  14. package/lib/exercises/math/integration/algorithms/pyIntegrationInstructionCompletion.d.ts.map +1 -0
  15. package/lib/exercises/math/integration/algorithms/pyIntegrationInstructionCompletion.js +273 -0
  16. package/lib/exercises/math/integration/index.d.ts +1 -0
  17. package/lib/exercises/math/integration/index.d.ts.map +1 -1
  18. package/lib/exercises/math/integration/index.js +1 -0
  19. package/lib/exercises/math/limits/algorithms/index.d.ts +2 -0
  20. package/lib/exercises/math/limits/algorithms/index.d.ts.map +1 -0
  21. package/lib/exercises/math/limits/algorithms/index.js +1 -0
  22. package/lib/exercises/math/limits/algorithms/pyLimitProgramExecution.d.ts +17 -0
  23. package/lib/exercises/math/limits/algorithms/pyLimitProgramExecution.d.ts.map +1 -0
  24. package/lib/exercises/math/limits/algorithms/pyLimitProgramExecution.js +353 -0
  25. package/lib/exercises/math/limits/index.d.ts +1 -0
  26. package/lib/exercises/math/limits/index.d.ts.map +1 -1
  27. package/lib/exercises/math/limits/index.js +1 -0
  28. package/lib/index.d.ts +23 -0
  29. package/lib/index.d.ts.map +1 -1
  30. package/lib/tests/singleExo.test.js +2 -2
  31. package/package.json +1 -1
@@ -3,4 +3,6 @@ export * from "./piecewiseFunctionContinuity.js";
3
3
  export * from "./isFunctionContinuousFromGraph.js";
4
4
  export * from "./signTableFromVarTableWithZeroes.js";
5
5
  export * from "./thirdDegreeZeroesFramingWithCalculator.js";
6
+ export * from "./pyContinuityBalayageInstructionCompletion.js";
7
+ export * from "./pyContinuityDichotomyInstructionCompletion.js";
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/continuity/index.ts"],"names":[],"mappings":"AAAA,cAAc,4CAA4C,CAAC;AAC3D,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6CAA6C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/continuity/index.ts"],"names":[],"mappings":"AAAA,cAAc,4CAA4C,CAAC;AAC3D,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,iDAAiD,CAAC"}
@@ -3,3 +3,5 @@ export * from "./piecewiseFunctionContinuity.js";
3
3
  export * from "./isFunctionContinuousFromGraph.js";
4
4
  export * from "./signTableFromVarTableWithZeroes.js";
5
5
  export * from "./thirdDegreeZeroesFramingWithCalculator.js";
6
+ export * from "./pyContinuityBalayageInstructionCompletion.js";
7
+ export * from "./pyContinuityDichotomyInstructionCompletion.js";
@@ -0,0 +1,11 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
3
+ type Identifiers = {
4
+ nodeIdsInterval: NodeIdentifiers;
5
+ nodeIdsDistanceMax: NodeIdentifiers;
6
+ nbStepsPerBalayage: number;
7
+ keyIncomplete: string;
8
+ };
9
+ export declare const pyContinuityBalayageInstructionCompletion: Exercise<Identifiers>;
10
+ export {};
11
+ //# sourceMappingURL=pyContinuityBalayageInstructionCompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyContinuityBalayageInstructionCompletion.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/continuity/pyContinuityBalayageInstructionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAoB7C,KAAK,WAAW,GAAG;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,eAAe,CAAC;IACpC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAmVF,eAAO,MAAM,yCAAyC,EAAE,QAAQ,CAAC,WAAW,CAkBzE,CAAC"}
@@ -0,0 +1,276 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { randint } from "../../../../math/utils/random/randint.js";
4
+ import { NodeConstructor, } from "../../../../tree/nodes/nodeConstructor.js";
5
+ import { power } from "../../../../tree/nodes/operators/powerNode.js";
6
+ import { ClosureType } from "../../../../tree/nodes/sets/closure.js";
7
+ import { IntervalNode } from "../../../../tree/nodes/sets/intervalNode.js";
8
+ import { random } from "../../../../utils/alea/random.js";
9
+ const codify = (strPython) => {
10
+ return `\`\`\`python
11
+ ${strPython}
12
+ \`\`\``;
13
+ };
14
+ const codifyChunk = (strPython) => {
15
+ return `\`${strPython}\``;
16
+ };
17
+ const createStrPythonForNode = (node) => {
18
+ return node.toMathString().replaceAll("^", "**");
19
+ };
20
+ const getHydrated = (identifiers) => {
21
+ const { nodeIdsInterval, nodeIdsDistanceMax } = identifiers;
22
+ const nodeInterval = NodeConstructor.fromIdentifiers(nodeIdsInterval);
23
+ const nodeDistanceMax = NodeConstructor.fromIdentifiers(nodeIdsDistanceMax);
24
+ return {
25
+ nodeInterval,
26
+ nodeDistanceMax,
27
+ };
28
+ };
29
+ const _getStrPythonProgram = (identifiers) => {
30
+ const { nbStepsPerBalayage } = identifiers;
31
+ const { nodeInterval, nodeDistanceMax } = getHydrated(identifiers);
32
+ const [strIntervalBoundA, strIntervalBoundB] = [
33
+ nodeInterval.a,
34
+ nodeInterval.b,
35
+ ].map(createStrPythonForNode);
36
+ const strDistanceMax = createStrPythonForNode(nodeDistanceMax);
37
+ const strNbStepsPerBalayage = createStrPythonForNode(nbStepsPerBalayage.toTree());
38
+ return `def encadrement(f,a,b, precision):
39
+ xL,xR = a,b #
40
+ while True:
41
+ pas = (xR-xL)/${strNbStepsPerBalayage} #
42
+ xL,xR = balayage(f,xL,xR,pas) #
43
+ if(xR-xL < precision): #
44
+ return xL,xR
45
+
46
+ def balayage(f, a, b, pas):
47
+ x = a #
48
+ while x <= b:
49
+ if f(x) * f(x + pas) <= 0: #
50
+ return x, x + pas
51
+ x += pas #
52
+ return None
53
+
54
+ xL,xR = encadrement(f, ${strIntervalBoundA} , ${strIntervalBoundB} , ${strDistanceMax})
55
+ print(xL, "<=", "alpha", "<=", xR)`;
56
+ };
57
+ const getStrPythonProgramComplete = (identifiers) => {
58
+ const identifiersTweaked = {
59
+ ...identifiers,
60
+ keyIncomplete: "",
61
+ };
62
+ return getStrPythonProgramIncomplete(identifiersTweaked);
63
+ };
64
+ const getStrPythonProgramIncomplete = (identifiers) => {
65
+ const { keyIncomplete } = identifiers;
66
+ const { strEncadrementInitialization, strEncadrementPas, strEncadrementBalayage, strEncadrementCondition, strBalayageInitialization, strBalayageCondition, strBalayageNextify, strCallEncadrement, } = Object.fromEntries(Object.entries(getDictStrCompletion(identifiers)).map(([key, str]) => key === keyIncomplete ? [key, "..."] : [key, str]));
67
+ return `def encadrement(f,a,b, precision):
68
+ ${strEncadrementInitialization}
69
+ while True:
70
+ ${strEncadrementPas}
71
+ ${strEncadrementBalayage}
72
+ ${strEncadrementCondition}
73
+ return xL,xR
74
+
75
+ def balayage(f, a, b, pas):
76
+ ${strBalayageInitialization}
77
+ while x <= b:
78
+ ${strBalayageCondition}
79
+ return x, x + pas
80
+ ${strBalayageNextify}
81
+ return None
82
+
83
+ ${strCallEncadrement}
84
+ print(xL, "<=", "alpha", "<=", xR)`;
85
+ };
86
+ const getDictStrCompletion = (identifiers) => {
87
+ const { nbStepsPerBalayage } = identifiers;
88
+ const { nodeInterval, nodeDistanceMax } = getHydrated(identifiers);
89
+ const [strIntervalBoundA, strIntervalBoundB] = [
90
+ nodeInterval.a,
91
+ nodeInterval.b,
92
+ ].map(createStrPythonForNode);
93
+ const strDistanceMax = createStrPythonForNode(nodeDistanceMax);
94
+ const strNbStepsPerBalayage = createStrPythonForNode(nbStepsPerBalayage.toTree());
95
+ return {
96
+ strEncadrementInitialization: `xL,xR = a,b`,
97
+ strEncadrementPas: `pas = (xR-xL)/${strNbStepsPerBalayage}`,
98
+ strEncadrementBalayage: `xL,xR = balayage(f,xL,xR,pas)`,
99
+ strEncadrementCondition: `if(xR-xL < precision):`,
100
+ strBalayageInitialization: `x = a`,
101
+ strBalayageCondition: `if f(x) * f(x + pas) <= 0:`,
102
+ strBalayageNextify: `x += pas`,
103
+ strCallEncadrement: `xL,xR = encadrement(f,${strIntervalBoundA}, ${strIntervalBoundB},${strDistanceMax})`,
104
+ };
105
+ };
106
+ const getInstruction = (identifiers) => {
107
+ const { nbStepsPerBalayage } = identifiers;
108
+ const { nodeInterval, nodeDistanceMax } = getHydrated(identifiers);
109
+ return `On considère une fonction $f$ strictement monotone sur $${nodeInterval.toTex()}$ et qui change de signe sur cet intervalle.
110
+ On veut déterminer un encadrement de $\\alpha$ tel que $f(\\alpha)=0$ en utilisant un algorithme de balayage, avec à chaque fois $${nbStepsPerBalayage.frenchify()}$ pas par balayage.
111
+
112
+ Dans le programme suivant,
113
+ on suppose que l'on dispose d'une fonction ${codifyChunk("f")}
114
+ telle que ${codifyChunk("f(x)")} retourne $f(x)$.
115
+
116
+ Par quoi faut-il remplacer les pointillés dans le programme suivant
117
+ pour qu'il affiche un encadrement de $\\alpha$ avec un écart strictement inférieur à $${nodeDistanceMax.toTex()}$ ?
118
+
119
+ ${codify(getStrPythonProgramIncomplete(identifiers))}
120
+
121
+ `;
122
+ };
123
+ const getAnswer = (identifiers) => {
124
+ const { keyIncomplete } = identifiers;
125
+ const dictStrCompletion = getDictStrCompletion(identifiers);
126
+ return codifyChunk(dictStrCompletion[keyIncomplete]);
127
+ };
128
+ const getHint = (identifiers) => {
129
+ const { keyIncomplete } = identifiers;
130
+ switch (keyIncomplete) {
131
+ case "strEncadrementInitialization":
132
+ return `Au départ, notre première estimation pour l'abscisse "à gauche" est $a$ et notre première estimation pour l'abscisse "à droite" est $b$.`;
133
+ case "strEncadrementPas": {
134
+ const { nbStepsPerBalayage } = identifiers;
135
+ return `Si la largeur de l'intervalle est $b-a$, et qu'on le coupe en $${nbStepsPerBalayage}$ segments, quelle est la longueur d'un segment ?`;
136
+ }
137
+ case "strEncadrementBalayage":
138
+ return `On veut trouver les nouvelles abscisses "à gauche" et "à droite" obtenue après un balayage.`;
139
+ case "strEncadrementCondition":
140
+ return `Écris en Python "Si la différence de l'abscisse "à droite" avec l'abscisse "à gauche" est inférieure à $precision$ alors"`;
141
+ case "strBalayageInitialization":
142
+ return `On balaye de façon croissante les abscisses. On commence par les abscisses les plus petites.`;
143
+ case "strBalayageCondition":
144
+ return `Pour détecter un changement de signe de $f$, on utilise la propriété suivante : Le produit de deux nombres de signes différents est négatif.`;
145
+ case "strBalayageNextify":
146
+ return `Si on n'a pas encore détecté de changement de signe, on passe au segment suivant.`;
147
+ default:
148
+ throw new Error("Unsupported keyIncomplete: " + keyIncomplete);
149
+ }
150
+ };
151
+ const getCorrection = (identifiers) => {
152
+ return `Voici le programme complet :
153
+
154
+ ${codify(getStrPythonProgramComplete(identifiers))}
155
+
156
+ `;
157
+ };
158
+ const getPropositions = (n, { answer, ...identifiers }) => {
159
+ const propositions = [];
160
+ addValidProp(propositions, answer, "raw");
161
+ const { keyIncomplete } = identifiers;
162
+ const { nbStepsPerBalayage } = identifiers;
163
+ const strNbStepsPerBalayage = createStrPythonForNode(nbStepsPerBalayage.toTree());
164
+ switch (keyIncomplete) {
165
+ case "strEncadrementInitialization":
166
+ {
167
+ ["xL,xR = 0,0", "xR,xL = a,b", "xR,xL = 0,0"].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
168
+ }
169
+ break;
170
+ case "strEncadrementPas":
171
+ {
172
+ [
173
+ `pas = ${strNbStepsPerBalayage}`,
174
+ `pas = (xR-xL) * ${strNbStepsPerBalayage}`,
175
+ `pas = xL + 1/${strNbStepsPerBalayage}`,
176
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
177
+ }
178
+ break;
179
+ case "strEncadrementBalayage":
180
+ {
181
+ [
182
+ "xL,xR = balayage(f,a,b,pas)",
183
+ "a,b = balayage(f,xL,xR,pas)",
184
+ `xL,xR = balayage(f,xL,xR,${strNbStepsPerBalayage})`,
185
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
186
+ }
187
+ break;
188
+ case "strEncadrementCondition":
189
+ {
190
+ [
191
+ "if(xR-xL < precision):",
192
+ "if(xR-xL > precision):",
193
+ "if(xL-xR < precision):",
194
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
195
+ }
196
+ break;
197
+ case "strBalayageInitialization":
198
+ {
199
+ ["x = 0", "x = b", "x = pas"].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
200
+ }
201
+ break;
202
+ case "strBalayageCondition":
203
+ {
204
+ [
205
+ "if f(x) - f(x + pas) <= 0:",
206
+ "if f(x) < 0 and f(x + pas) > 0:",
207
+ "if f(x) > 0 and f(x + pas) < 0:",
208
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
209
+ }
210
+ break;
211
+ case "strBalayageNextify":
212
+ {
213
+ ["x = a + pas", "x += x + pas", "x + pas"].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
214
+ }
215
+ break;
216
+ default:
217
+ throw new Error("Unsupported keyIncomplete: " + keyIncomplete);
218
+ }
219
+ return shuffleProps(propositions, n);
220
+ };
221
+ const createRandomIdentifiers = () => {
222
+ const nodeDistanceMax = power(10, randint(-3, 0));
223
+ const keyIncomplete = random([
224
+ "strEncadrementInitialization",
225
+ "strEncadrementPas",
226
+ "strEncadrementBalayage",
227
+ "strEncadrementCondition",
228
+ "strBalayageInitialization",
229
+ "strBalayageCondition",
230
+ "strBalayageNextify",
231
+ // "strCallEncadrement",
232
+ ]);
233
+ const nodeInterval = (() => {
234
+ const a = randint(-5, 5);
235
+ const b = a + randint(1, 5);
236
+ return new IntervalNode(a.toTree(), b.toTree(), ClosureType.FF);
237
+ })();
238
+ const nbStepsPerBalayage = random([10, 20, 50, 100]);
239
+ const identifiers = {
240
+ nodeIdsInterval: nodeInterval.toIdentifiers(),
241
+ nodeIdsDistanceMax: nodeDistanceMax.toIdentifiers(),
242
+ keyIncomplete,
243
+ nbStepsPerBalayage,
244
+ };
245
+ return identifiers;
246
+ };
247
+ const getPyContinuityBalayageInstructionCompletionQuestion = () => {
248
+ const identifiers = createRandomIdentifiers();
249
+ return getQuestionFromIdentifiers(identifiers);
250
+ };
251
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
252
+ const question = {
253
+ answer: getAnswer(identifiers, opts),
254
+ instruction: getInstruction(identifiers, opts),
255
+ keys: [],
256
+ answerFormat: "tex",
257
+ identifiers,
258
+ hint: getHint(identifiers, opts),
259
+ correction: getCorrection(identifiers, opts),
260
+ options: opts,
261
+ };
262
+ return question;
263
+ };
264
+ export const pyContinuityBalayageInstructionCompletion = {
265
+ id: "pyContinuityBalayageInstructionCompletion",
266
+ label: "Compléter le script d'un algorithme d'encadrement par balayage de $\\alpha$ tel que $f(\\alpha)=0$",
267
+ isSingleStep: true,
268
+ generator: (nb, opts) => getDistinctQuestions(() => getPyContinuityBalayageInstructionCompletionQuestion(opts), nb),
269
+ qcmTimer: 60,
270
+ freeTimer: 60,
271
+ getPropositions,
272
+ subject: "Mathématiques",
273
+ getQuestionFromIdentifiers,
274
+ hasHintAndCorrection: true,
275
+ answerType: "QCU",
276
+ };
@@ -0,0 +1,10 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
3
+ type Identifiers = {
4
+ nodeIdsInterval: NodeIdentifiers;
5
+ nodeIdsDistanceMax: NodeIdentifiers;
6
+ keyIncomplete: string;
7
+ };
8
+ export declare const pyContinuityDichotomyInstructionCompletion: Exercise<Identifiers>;
9
+ export {};
10
+ //# sourceMappingURL=pyContinuityDichotomyInstructionCompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyContinuityDichotomyInstructionCompletion.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/continuity/pyContinuityDichotomyInstructionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAoB7C,KAAK,WAAW,GAAG;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,eAAe,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAiUF,eAAO,MAAM,0CAA0C,EAAE,QAAQ,CAAC,WAAW,CAkB1E,CAAC"}
@@ -0,0 +1,265 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { randint } from "../../../../math/utils/random/randint.js";
4
+ import { NodeConstructor, } from "../../../../tree/nodes/nodeConstructor.js";
5
+ import { power } from "../../../../tree/nodes/operators/powerNode.js";
6
+ import { ClosureType } from "../../../../tree/nodes/sets/closure.js";
7
+ import { IntervalNode } from "../../../../tree/nodes/sets/intervalNode.js";
8
+ import { random } from "../../../../utils/alea/random.js";
9
+ const codify = (strPython) => {
10
+ return `\`\`\`python
11
+ ${strPython}
12
+ \`\`\``;
13
+ };
14
+ const codifyChunk = (strPython) => {
15
+ return `\`${strPython}\``;
16
+ };
17
+ const createStrPythonForNode = (node) => {
18
+ return node.toMathString().replaceAll("^", "**");
19
+ };
20
+ const getHydrated = (identifiers) => {
21
+ const { nodeIdsInterval, nodeIdsDistanceMax } = identifiers;
22
+ const nodeInterval = NodeConstructor.fromIdentifiers(nodeIdsInterval);
23
+ const nodeDistanceMax = NodeConstructor.fromIdentifiers(nodeIdsDistanceMax);
24
+ return {
25
+ nodeInterval,
26
+ nodeDistanceMax,
27
+ };
28
+ };
29
+ const _getStrPythonProgram = (identifiers) => {
30
+ const { nodeInterval, nodeDistanceMax } = getHydrated(identifiers);
31
+ const [strIntervalBoundA, strIntervalBoundB] = [
32
+ nodeInterval.a,
33
+ nodeInterval.b,
34
+ ].map(createStrPythonForNode);
35
+ const strDistanceMax = createStrPythonForNode(nodeDistanceMax);
36
+ return `def encadrement(f,a,b, precision):
37
+ xL,xR = a,b #
38
+ while True:
39
+ xL,xR = dichotomie(f,xL,xR) #
40
+ if(xR-xL < precision): #
41
+ return xL,xR
42
+
43
+ def dichotomie(f, a, b):
44
+ m = (a+b) / 2 #
45
+ if f(a) * f(m) <= 0: #
46
+ return a, m #
47
+ else:
48
+ return m,b #
49
+
50
+ xL,xR = encadrement(f, ${strIntervalBoundA} , ${strIntervalBoundB} , ${strDistanceMax})
51
+ print(xL, "<=", "alpha", "<=", xR)`;
52
+ };
53
+ const getStrPythonProgramComplete = (identifiers) => {
54
+ const identifiersTweaked = {
55
+ ...identifiers,
56
+ keyIncomplete: "",
57
+ };
58
+ return getStrPythonProgramIncomplete(identifiersTweaked);
59
+ };
60
+ const getStrPythonProgramIncomplete = (identifiers) => {
61
+ const { keyIncomplete } = identifiers;
62
+ const { strEncadrementInitialization, strEncadrementDichotomie, strEncadrementCondition, strDichotomieM, strDichotomieCondition, strDichotomieBlockValid, strDichotomieBlockInvalid, strCallEncadrement, } = Object.fromEntries(Object.entries(getDictStrCompletion(identifiers)).map(([key, str]) => key === keyIncomplete ? [key, "..."] : [key, str]));
63
+ return `def encadrement(f,a,b, precision):
64
+ ${strEncadrementInitialization}
65
+ while True:
66
+ ${strEncadrementDichotomie}
67
+ ${strEncadrementCondition}
68
+ return xL,xR
69
+
70
+ def dichotomie(f, a, b):
71
+ ${strDichotomieM}
72
+ ${strDichotomieCondition}
73
+ ${strDichotomieBlockValid}
74
+ else:
75
+ ${strDichotomieBlockInvalid}
76
+
77
+ ${strCallEncadrement}
78
+ print(xL, "<=", "alpha", "<=", xR)`;
79
+ };
80
+ const getDictStrCompletion = (identifiers) => {
81
+ const { nodeInterval, nodeDistanceMax } = getHydrated(identifiers);
82
+ const [strIntervalBoundA, strIntervalBoundB] = [
83
+ nodeInterval.a,
84
+ nodeInterval.b,
85
+ ].map(createStrPythonForNode);
86
+ const strDistanceMax = createStrPythonForNode(nodeDistanceMax);
87
+ return {
88
+ strEncadrementInitialization: `xL,xR = a,b`,
89
+ strEncadrementDichotomie: `xL,xR = dichotomie(f,xL,xR)`,
90
+ strEncadrementCondition: `if(xR-xL < precision):`,
91
+ strDichotomieM: `m = (a+b)/2`,
92
+ strDichotomieCondition: `if f(a) * f(m) <= 0:`,
93
+ strDichotomieBlockValid: `return a,m`,
94
+ strDichotomieBlockInvalid: `return m,b`,
95
+ strCallEncadrement: `xL,xR = encadrement(f,${strIntervalBoundA}, ${strIntervalBoundB},${strDistanceMax})`,
96
+ };
97
+ };
98
+ const getInstruction = (identifiers) => {
99
+ const { nodeInterval, nodeDistanceMax } = getHydrated(identifiers);
100
+ return `On considère une fonction $f$ strictement monotone sur $${nodeInterval.toTex()}$ et qui change de signe sur cet intervalle.
101
+ On veut déterminer un encadrement de $\\alpha$ tel que $f(\\alpha)=0$ en utilisant un algorithme de dichotomie.
102
+
103
+ Dans le programme suivant,
104
+ on suppose que l'on dispose d'une fonction ${codifyChunk("f")}
105
+ telle que ${codifyChunk("f(x)")} retourne $f(x)$.
106
+
107
+ Par quoi faut-il remplacer les pointillés dans le programme suivant
108
+ pour qu'il affiche un encadrement de $\\alpha$ avec un écart strictement inférieur à $${nodeDistanceMax.toTex()}$ ?
109
+
110
+ ${codify(getStrPythonProgramIncomplete(identifiers))}
111
+
112
+ `;
113
+ };
114
+ const getAnswer = (identifiers) => {
115
+ const { keyIncomplete } = identifiers;
116
+ const dictStrCompletion = getDictStrCompletion(identifiers);
117
+ return codifyChunk(dictStrCompletion[keyIncomplete]);
118
+ };
119
+ const getHint = (identifiers) => {
120
+ const { keyIncomplete } = identifiers;
121
+ switch (keyIncomplete) {
122
+ case "strEncadrementInitialization":
123
+ return `Au départ, notre première estimation pour l'abscisse "à gauche" est $a$ et notre première estimation pour l'abscisse "à droite" est $b$.`;
124
+ case "strEncadrementDichotomie":
125
+ return `On veut trouver les nouvelles abscisses "à gauche" et "à droite" obtenue après dichotomie.`;
126
+ case "strEncadrementCondition":
127
+ return `Écris en Python "Si la différence de l'abscisse "à droite" avec l'abscisse "à gauche" est inférieure à $precision$ alors"`;
128
+ case "strDichotomieM":
129
+ return `Dans un algorithme par dichotomie, on coupe l'intervalle considéré en $2$ et on détermine si l'on garde le côté gauche ou le côté droit.`;
130
+ case "strDichotomieCondition":
131
+ return `Pour détecter un changement de signe de $f$, on utilise la propriété suivante : Le produit de deux nombres de signes différents est négatif.`;
132
+ case "strDichotomieBlockValid":
133
+ return `On a coupé en deux et dans ce cas, on veut garder le côté gauche.`;
134
+ case "strDichotomieBlockInvalid":
135
+ return `On a coupé en deux et dans ce cas, on veut garder le côté droit.`;
136
+ default:
137
+ throw new Error("Unsupported keyIncomplete: " + keyIncomplete);
138
+ }
139
+ };
140
+ const getCorrection = (identifiers) => {
141
+ return `Voici le programme complet :
142
+
143
+ ${codify(getStrPythonProgramComplete(identifiers))}
144
+
145
+ `;
146
+ };
147
+ const getPropositions = (n, { answer, ...identifiers }) => {
148
+ const propositions = [];
149
+ addValidProp(propositions, answer, "raw");
150
+ const { keyIncomplete } = identifiers;
151
+ switch (keyIncomplete) {
152
+ case "strEncadrementInitialization":
153
+ {
154
+ ["xL,xR = 0,0", "xR,xL = a,b", "xR,xL = 0,0"].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
155
+ }
156
+ break;
157
+ case "strEncadrementDichotomie":
158
+ {
159
+ [
160
+ "xR,xL = dichotomie(f,a,b)",
161
+ "a,b = dichotomie(f,xL,xR)",
162
+ `dichotomie(f,xL,xR)`,
163
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
164
+ }
165
+ break;
166
+ case "strEncadrementCondition":
167
+ {
168
+ [
169
+ "if(xR-xL < precision):",
170
+ "if(xR-xL > precision):",
171
+ "if(xL-xR < precision):",
172
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
173
+ }
174
+ break;
175
+ case "strDichotomieM":
176
+ {
177
+ ["m = (b-a)/2", "m = a+b", "m = b-a"].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
178
+ }
179
+ break;
180
+ case "strDichotomieCondition":
181
+ {
182
+ [
183
+ "if f(a) - f(m) <= 0:",
184
+ "if f(a) < 0 and f(m) > 0:",
185
+ "if f(a) > 0 and f(m) < 0:",
186
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
187
+ }
188
+ break;
189
+ case "strDichotomieBlockValid":
190
+ {
191
+ [
192
+ "return a, (a+m)/2",
193
+ "return (a+m)/2, m",
194
+ "return (a+m)/2, (b+m)/2",
195
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
196
+ }
197
+ break;
198
+ case "strDichotomieBlockInvalid":
199
+ {
200
+ [
201
+ "return m, (m+b)/2",
202
+ "return (m+b)/2, b",
203
+ "return (a+m)/2, (b+m)/2",
204
+ ].forEach((str) => tryToAddWrongProp(propositions, codifyChunk(str), "raw"));
205
+ }
206
+ break;
207
+ default:
208
+ throw new Error("Unsupported keyIncomplete: " + keyIncomplete);
209
+ }
210
+ return shuffleProps(propositions, n);
211
+ };
212
+ const createRandomIdentifiers = () => {
213
+ const nodeDistanceMax = power(10, randint(-3, 0));
214
+ const keyIncomplete = random([
215
+ "strEncadrementInitialization",
216
+ "strEncadrementDichotomie",
217
+ "strEncadrementCondition",
218
+ "strDichotomieM",
219
+ "strDichotomieCondition",
220
+ "strDichotomieBlockValid",
221
+ "strDichotomieBlockInvalid",
222
+ // "strCallEncadrement",
223
+ ]);
224
+ const nodeInterval = (() => {
225
+ const a = randint(-5, 5);
226
+ const b = a + randint(1, 5);
227
+ return new IntervalNode(a.toTree(), b.toTree(), ClosureType.FF);
228
+ })();
229
+ const identifiers = {
230
+ nodeIdsInterval: nodeInterval.toIdentifiers(),
231
+ nodeIdsDistanceMax: nodeDistanceMax.toIdentifiers(),
232
+ keyIncomplete,
233
+ };
234
+ return identifiers;
235
+ };
236
+ const getPyContinuityDichotomyInstructionCompletionQuestion = () => {
237
+ const identifiers = createRandomIdentifiers();
238
+ return getQuestionFromIdentifiers(identifiers);
239
+ };
240
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
241
+ const question = {
242
+ answer: getAnswer(identifiers, opts),
243
+ instruction: getInstruction(identifiers, opts),
244
+ keys: [],
245
+ answerFormat: "tex",
246
+ identifiers,
247
+ hint: getHint(identifiers, opts),
248
+ correction: getCorrection(identifiers, opts),
249
+ options: opts,
250
+ };
251
+ return question;
252
+ };
253
+ export const pyContinuityDichotomyInstructionCompletion = {
254
+ id: "pyContinuityDichotomyInstructionCompletion",
255
+ label: "Compléter le script d'un algorithme d'encadrement par dichotomie de $\\alpha$ tel que $f(\\alpha)=0$",
256
+ isSingleStep: true,
257
+ generator: (nb, opts) => getDistinctQuestions(() => getPyContinuityDichotomyInstructionCompletionQuestion(opts), nb),
258
+ qcmTimer: 60,
259
+ freeTimer: 60,
260
+ getPropositions,
261
+ subject: "Mathématiques",
262
+ getQuestionFromIdentifiers,
263
+ hasHintAndCorrection: true,
264
+ answerType: "QCU",
265
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./pyIntegrationInstructionCompletion.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/integration/algorithms/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./pyIntegrationInstructionCompletion.js";
@@ -0,0 +1,10 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
3
+ type Identifiers = {
4
+ nodeIdsInterval: NodeIdentifiers;
5
+ nodeIdsDistanceMax: NodeIdentifiers;
6
+ keyIncomplete: string;
7
+ };
8
+ export declare const pyIntegrationInstructionCompletion: Exercise<Identifiers>;
9
+ export {};
10
+ //# sourceMappingURL=pyIntegrationInstructionCompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyIntegrationInstructionCompletion.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/integration/algorithms/pyIntegrationInstructionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAoB7C,KAAK,WAAW,GAAG;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,eAAe,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAsUF,eAAO,MAAM,kCAAkC,EAAE,QAAQ,CAAC,WAAW,CAgBpE,CAAC"}