math-exercises 3.0.208 → 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 (101) hide show
  1. package/lib/exercises/math/arithmetic/congruenceBasicComputation.d.ts +8 -0
  2. package/lib/exercises/math/arithmetic/congruenceBasicComputation.d.ts.map +1 -0
  3. package/lib/exercises/math/arithmetic/congruenceBasicComputation.js +93 -0
  4. package/lib/exercises/math/arithmetic/index.d.ts +2 -0
  5. package/lib/exercises/math/arithmetic/index.d.ts.map +1 -0
  6. package/lib/exercises/math/arithmetic/index.js +1 -0
  7. package/lib/exercises/math/functions/affines/adjustment/affineAdjustment.d.ts.map +1 -1
  8. package/lib/exercises/math/functions/affines/adjustment/affineAdjustment.js +15 -0
  9. package/lib/exercises/math/functions/affines/adjustment/affineAdjustmentRsquared.d.ts.map +1 -1
  10. package/lib/exercises/math/functions/affines/adjustment/affineAdjustmentRsquared.js +15 -0
  11. package/lib/exercises/math/functions/continuity/index.d.ts +2 -0
  12. package/lib/exercises/math/functions/continuity/index.d.ts.map +1 -1
  13. package/lib/exercises/math/functions/continuity/index.js +2 -0
  14. package/lib/exercises/math/functions/continuity/pyContinuityBalayageInstructionCompletion.d.ts +11 -0
  15. package/lib/exercises/math/functions/continuity/pyContinuityBalayageInstructionCompletion.d.ts.map +1 -0
  16. package/lib/exercises/math/functions/continuity/pyContinuityBalayageInstructionCompletion.js +276 -0
  17. package/lib/exercises/math/functions/continuity/pyContinuityDichotomyInstructionCompletion.d.ts +10 -0
  18. package/lib/exercises/math/functions/continuity/pyContinuityDichotomyInstructionCompletion.d.ts.map +1 -0
  19. package/lib/exercises/math/functions/continuity/pyContinuityDichotomyInstructionCompletion.js +265 -0
  20. package/lib/exercises/math/functions/logarithm/log10Simplifying.d.ts.map +1 -1
  21. package/lib/exercises/math/functions/logarithm/log10Simplifying.js +72 -33
  22. package/lib/exercises/math/functions/logarithm/logEquation.d.ts.map +1 -1
  23. package/lib/exercises/math/functions/logarithm/logEquation.js +40 -2
  24. package/lib/exercises/math/functions/logarithm/logPowerEquation.d.ts.map +1 -1
  25. package/lib/exercises/math/functions/logarithm/logPowerEquation.js +55 -6
  26. package/lib/exercises/math/functions/logarithm/logSimplifiying.d.ts.map +1 -1
  27. package/lib/exercises/math/functions/logarithm/logSimplifiying.js +45 -5
  28. package/lib/exercises/math/index.d.ts +1 -0
  29. package/lib/exercises/math/index.d.ts.map +1 -1
  30. package/lib/exercises/math/index.js +1 -0
  31. package/lib/exercises/math/integration/algorithms/index.d.ts +2 -0
  32. package/lib/exercises/math/integration/algorithms/index.d.ts.map +1 -0
  33. package/lib/exercises/math/integration/algorithms/index.js +1 -0
  34. package/lib/exercises/math/integration/algorithms/pyIntegrationInstructionCompletion.d.ts +10 -0
  35. package/lib/exercises/math/integration/algorithms/pyIntegrationInstructionCompletion.d.ts.map +1 -0
  36. package/lib/exercises/math/integration/algorithms/pyIntegrationInstructionCompletion.js +273 -0
  37. package/lib/exercises/math/integration/index.d.ts +1 -0
  38. package/lib/exercises/math/integration/index.d.ts.map +1 -1
  39. package/lib/exercises/math/integration/index.js +1 -0
  40. package/lib/exercises/math/limits/algorithms/index.d.ts +2 -0
  41. package/lib/exercises/math/limits/algorithms/index.d.ts.map +1 -0
  42. package/lib/exercises/math/limits/algorithms/index.js +1 -0
  43. package/lib/exercises/math/limits/algorithms/pyLimitProgramExecution.d.ts +17 -0
  44. package/lib/exercises/math/limits/algorithms/pyLimitProgramExecution.d.ts.map +1 -0
  45. package/lib/exercises/math/limits/algorithms/pyLimitProgramExecution.js +353 -0
  46. package/lib/exercises/math/limits/index.d.ts +1 -0
  47. package/lib/exercises/math/limits/index.d.ts.map +1 -1
  48. package/lib/exercises/math/limits/index.js +1 -0
  49. package/lib/exercises/math/probaStat/density/findParamToMakeDensity.d.ts +8 -0
  50. package/lib/exercises/math/probaStat/density/findParamToMakeDensity.d.ts.map +1 -0
  51. package/lib/exercises/math/probaStat/density/findParamToMakeDensity.js +127 -0
  52. package/lib/exercises/math/probaStat/density/index.d.ts +2 -0
  53. package/lib/exercises/math/probaStat/density/index.d.ts.map +1 -0
  54. package/lib/exercises/math/probaStat/density/index.js +1 -0
  55. package/lib/exercises/math/probaStat/exponential/exponentialLawAverage.d.ts +7 -0
  56. package/lib/exercises/math/probaStat/exponential/exponentialLawAverage.d.ts.map +1 -0
  57. package/lib/exercises/math/probaStat/exponential/exponentialLawAverage.js +95 -0
  58. package/lib/exercises/math/probaStat/exponential/exponentialLawComputeIntervalProba.d.ts +9 -0
  59. package/lib/exercises/math/probaStat/exponential/exponentialLawComputeIntervalProba.d.ts.map +1 -0
  60. package/lib/exercises/math/probaStat/exponential/exponentialLawComputeIntervalProba.js +115 -0
  61. package/lib/exercises/math/probaStat/exponential/exponentialLawComputeProba.d.ts +8 -0
  62. package/lib/exercises/math/probaStat/exponential/exponentialLawComputeProba.d.ts.map +1 -0
  63. package/lib/exercises/math/probaStat/exponential/exponentialLawComputeProba.js +110 -0
  64. package/lib/exercises/math/probaStat/exponential/index.d.ts +4 -0
  65. package/lib/exercises/math/probaStat/exponential/index.d.ts.map +1 -0
  66. package/lib/exercises/math/probaStat/exponential/index.js +3 -0
  67. package/lib/exercises/math/probaStat/geometric/geometricLawAverage.d.ts +8 -0
  68. package/lib/exercises/math/probaStat/geometric/geometricLawAverage.d.ts.map +1 -0
  69. package/lib/exercises/math/probaStat/geometric/geometricLawAverage.js +124 -0
  70. package/lib/exercises/math/probaStat/geometric/geometricLawComputeProba.d.ts +9 -0
  71. package/lib/exercises/math/probaStat/geometric/geometricLawComputeProba.d.ts.map +1 -0
  72. package/lib/exercises/math/probaStat/geometric/geometricLawComputeProba.js +121 -0
  73. package/lib/exercises/math/probaStat/geometric/index.d.ts +3 -0
  74. package/lib/exercises/math/probaStat/geometric/index.d.ts.map +1 -0
  75. package/lib/exercises/math/probaStat/geometric/index.js +2 -0
  76. package/lib/exercises/math/probaStat/index.d.ts +4 -0
  77. package/lib/exercises/math/probaStat/index.d.ts.map +1 -1
  78. package/lib/exercises/math/probaStat/index.js +4 -0
  79. package/lib/exercises/math/probaStat/stats2var/fineAdjustementExercise.d.ts.map +1 -1
  80. package/lib/exercises/math/probaStat/stats2var/fineAdjustementExercise.js +15 -0
  81. package/lib/exercises/math/probaStat/uniform/index.d.ts +3 -0
  82. package/lib/exercises/math/probaStat/uniform/index.d.ts.map +1 -0
  83. package/lib/exercises/math/probaStat/uniform/index.js +2 -0
  84. package/lib/exercises/math/probaStat/uniform/uniformAverage.d.ts +8 -0
  85. package/lib/exercises/math/probaStat/uniform/uniformAverage.d.ts.map +1 -0
  86. package/lib/exercises/math/probaStat/uniform/uniformAverage.js +100 -0
  87. package/lib/exercises/math/probaStat/uniform/uniformLawComputeProba.d.ts +10 -0
  88. package/lib/exercises/math/probaStat/uniform/uniformLawComputeProba.d.ts.map +1 -0
  89. package/lib/exercises/math/probaStat/uniform/uniformLawComputeProba.js +105 -0
  90. package/lib/index.d.ts +52 -1
  91. package/lib/index.d.ts.map +1 -1
  92. package/lib/latexTester.js +1 -0
  93. package/lib/tests/pdfs/formatMdToLatex.js +1 -1
  94. package/lib/tests/singleExo.test.js +2 -2
  95. package/lib/tree/nodes/functions/log10Node.d.ts +1 -0
  96. package/lib/tree/nodes/functions/log10Node.d.ts.map +1 -1
  97. package/lib/tree/nodes/functions/log10Node.js +12 -1
  98. package/lib/tree/nodes/functions/logNode.d.ts +1 -0
  99. package/lib/tree/nodes/functions/logNode.d.ts.map +1 -1
  100. package/lib/tree/nodes/functions/logNode.js +12 -1
  101. package/package.json +1 -1
@@ -0,0 +1,8 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ a: number;
4
+ mod: number;
5
+ };
6
+ export declare const congruenceBasicComputation: Exercise<Identifiers>;
7
+ export {};
8
+ //# sourceMappingURL=congruenceBasicComputation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"congruenceBasicComputation.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/arithmetic/congruenceBasicComputation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAMrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAmFF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAkB5D,CAAC"}
@@ -0,0 +1,93 @@
1
+ import { addValidProp, shuffleProps, propWhile, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { numberVEA } from "../../../exercises/vea/numberVEA.js";
4
+ import { randint } from "../../../math/utils/random/randint.js";
5
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
6
+ const getPropositions = (n, { answer, mod }) => {
7
+ const propositions = [];
8
+ addValidProp(propositions, answer);
9
+ tryToAddWrongProp(propositions, mod.frenchify());
10
+ propWhile(propositions, n, () => {
11
+ tryToAddWrongProp(propositions, randint(1, 20).frenchify());
12
+ });
13
+ return shuffleProps(propositions, n);
14
+ };
15
+ const getAnswer = (identifiers) => {
16
+ const { a, mod } = identifiers;
17
+ return Math.floor(a % mod).frenchify();
18
+ };
19
+ const getInstruction = (identifiers) => {
20
+ const { a, mod } = identifiers;
21
+ return `Déterminer $x$ tel que $0\\leq x < ${mod}$ et :
22
+
23
+ $$
24
+ ${a} \\equiv x \\ [${mod}]
25
+ $$`;
26
+ };
27
+ const getHint = (identifiers) => {
28
+ const { a, mod } = identifiers;
29
+ return `Puisque $0\\leq x < ${mod}$ et $${a} \\equiv x \\ [${mod}]$, alors $x$ est le reste de la division euclidienne de $${a}$ par $${mod}$.`;
30
+ };
31
+ const getCorrection = (identifiers) => {
32
+ const { a, mod } = identifiers;
33
+ const left = a % mod;
34
+ const quot = Math.floor(a / mod);
35
+ return `$x$ est le reste de la division euclidienne de $${a}$ par $${mod}$.
36
+
37
+ Or,
38
+
39
+ $$
40
+ ${a} = ${quot}\\times ${mod} + ${left}
41
+ $$
42
+
43
+ Ainsi, $x= ${left}$`;
44
+ };
45
+ const getKeys = () => {
46
+ return [];
47
+ };
48
+ const isAnswerValid = (ans, { answer }) => {
49
+ try {
50
+ return numberVEA(ans, answer);
51
+ }
52
+ catch (err) {
53
+ return handleVEAError(err);
54
+ }
55
+ };
56
+ const getCongruenceBasicComputationQuestion = () => {
57
+ const mod = randint(2, 12);
58
+ const a = randint(mod, mod * 3);
59
+ const identifiers = {
60
+ a,
61
+ mod,
62
+ };
63
+ return getQuestionFromIdentifiers(identifiers);
64
+ };
65
+ const getQuestionFromIdentifiers = (identifiers) => {
66
+ return {
67
+ answer: getAnswer(identifiers),
68
+ instruction: getInstruction(identifiers),
69
+ keys: getKeys(identifiers),
70
+ answerFormat: "tex",
71
+ identifiers,
72
+ hint: getHint(identifiers),
73
+ correction: getCorrection(identifiers),
74
+ };
75
+ };
76
+ export const congruenceBasicComputation = {
77
+ id: "congruenceBasicComputation",
78
+ connector: "=",
79
+ label: "Déterminer $x$ tel que $x$ est congru à $a$ modulo $n$",
80
+ isSingleStep: true,
81
+ generator: (nb, opts) => getDistinctQuestions(() => getCongruenceBasicComputationQuestion(opts), nb),
82
+ qcmTimer: 60,
83
+ freeTimer: 60,
84
+ getPropositions,
85
+ isAnswerValid,
86
+ subject: "Mathématiques",
87
+ getInstruction,
88
+ getHint,
89
+ getCorrection,
90
+ getAnswer,
91
+ getQuestionFromIdentifiers,
92
+ hasHintAndCorrection: true,
93
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./congruenceBasicComputation.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/arithmetic/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./congruenceBasicComputation.js";
@@ -1 +1 @@
1
- {"version":3,"file":"affineAdjustment.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/functions/affines/adjustment/affineAdjustment.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAgBrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AA8KF,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,WAAW,CAa1D,CAAC"}
1
+ {"version":3,"file":"affineAdjustment.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/functions/affines/adjustment/affineAdjustment.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAgBrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AA6LF,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,WAAW,CAc1D,CAAC"}
@@ -66,6 +66,18 @@ const getAffineAdjustmentQuestion = () => {
66
66
  const identifiers = { xValues, yValues };
67
67
  return getQuestionFromIdentifiers(identifiers);
68
68
  };
69
+ const getHint = () => {
70
+ return `Utilise la calculatrice. Va dans le menu "Stats", puis entre les données de la série.`;
71
+ };
72
+ const getCorrection = (identifiers) => {
73
+ return `On utilise la calculatrice. On se rend dans le menu "Stats", puis on entre les données de la série. La calculatrice nous donne alors les indicateurs statistiques de cette série, et parmi eux, l'équation de la droite d'ajustement obtenue par la méthode des moindres carrés.
74
+
75
+ On trouve, arrondie au dixième :
76
+
77
+ $$
78
+ ${getAnswer(identifiers)}
79
+ $$`;
80
+ };
69
81
  const getQuestionFromIdentifiers = (identifiers) => {
70
82
  const question = {
71
83
  answer: getAnswer(identifiers),
@@ -80,6 +92,8 @@ const getQuestionFromIdentifiers = (identifiers) => {
80
92
  firstRowIsHeader: false,
81
93
  },
82
94
  },
95
+ hint: getHint(identifiers),
96
+ correction: getCorrection(identifiers),
83
97
  };
84
98
  return question;
85
99
  };
@@ -125,5 +139,6 @@ export const affineAdjustmentExercise = {
125
139
  getPropositions,
126
140
  isAnswerValid,
127
141
  subject: "Mathématiques",
142
+ hasHintAndCorrection: true,
128
143
  getQuestionFromIdentifiers,
129
144
  };
@@ -1 +1 @@
1
- {"version":3,"file":"affineAdjustmentRsquared.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/functions/affines/adjustment/affineAdjustmentRsquared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAcrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAqHF,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,WAAW,CAalE,CAAC"}
1
+ {"version":3,"file":"affineAdjustmentRsquared.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/functions/affines/adjustment/affineAdjustmentRsquared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAcrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAqIF,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,WAAW,CAclE,CAAC"}
@@ -36,6 +36,18 @@ const getAffineAdjustmentRsquaredQuestion = () => {
36
36
  const identifiers = { xValues, yValues };
37
37
  return getQuestionFromIdentifiers(identifiers);
38
38
  };
39
+ const getHint = () => {
40
+ return `Utilise la calculatrice. Va dans le menu "Stats", puis entre les données de la série.`;
41
+ };
42
+ const getCorrection = (identifiers) => {
43
+ return `On utilise la calculatrice. On se rend dans le menu "Stats", puis on entre les données de la série. La calculatrice nous donne alors les indicateurs statistiques de cette série, et parmi eux, le coefficient de détermination $R^2$.
44
+
45
+ On trouve, arrondie au dixième :
46
+
47
+ $$
48
+ R^2 \\approx ${getAnswer(identifiers)}
49
+ $$`;
50
+ };
39
51
  const getQuestionFromIdentifiers = (identifiers) => {
40
52
  const question = {
41
53
  answer: getAnswer(identifiers),
@@ -50,6 +62,8 @@ const getQuestionFromIdentifiers = (identifiers) => {
50
62
  firstRowIsHeader: false,
51
63
  },
52
64
  },
65
+ hint: getHint(identifiers),
66
+ correction: getCorrection(identifiers),
53
67
  };
54
68
  return question;
55
69
  };
@@ -89,4 +103,5 @@ export const affineAdjustmentRsquaredExercise = {
89
103
  isAnswerValid,
90
104
  subject: "Mathématiques",
91
105
  getQuestionFromIdentifiers,
106
+ hasHintAndCorrection: true,
92
107
  };
@@ -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"}