math-exercises 3.0.199 → 3.0.200

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 (123) hide show
  1. package/lib/exercises/exercise.d.ts +14 -1
  2. package/lib/exercises/exercise.d.ts.map +1 -1
  3. package/lib/exercises/math/_debug/debugReorder1.d.ts +8 -0
  4. package/lib/exercises/math/_debug/debugReorder1.d.ts.map +1 -0
  5. package/lib/exercises/math/_debug/debugReorder1.js +81 -0
  6. package/lib/exercises/math/_debug/debugReorder2.d.ts +10 -0
  7. package/lib/exercises/math/_debug/debugReorder2.d.ts.map +1 -0
  8. package/lib/exercises/math/_debug/debugReorder2.js +88 -0
  9. package/lib/exercises/math/_debug/debugReorder3.d.ts +10 -0
  10. package/lib/exercises/math/_debug/debugReorder3.d.ts.map +1 -0
  11. package/lib/exercises/math/_debug/debugReorder3.js +81 -0
  12. package/lib/exercises/math/_debug/index.d.ts +3 -1
  13. package/lib/exercises/math/_debug/index.d.ts.map +1 -1
  14. package/lib/exercises/math/_debug/index.js +3 -1
  15. package/lib/exercises/math/calcul/factorial/index.d.ts +2 -0
  16. package/lib/exercises/math/calcul/factorial/index.d.ts.map +1 -0
  17. package/lib/exercises/math/calcul/factorial/index.js +1 -0
  18. package/lib/exercises/math/calcul/factorial/simplifyQuotientOfFactorialToProduct.d.ts +8 -0
  19. package/lib/exercises/math/calcul/factorial/simplifyQuotientOfFactorialToProduct.d.ts.map +1 -0
  20. package/lib/exercises/math/calcul/factorial/simplifyQuotientOfFactorialToProduct.js +199 -0
  21. package/lib/exercises/math/combinatory/combination/index.d.ts +3 -0
  22. package/lib/exercises/math/combinatory/combination/index.d.ts.map +1 -0
  23. package/lib/exercises/math/combinatory/combination/index.js +2 -0
  24. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.d.ts +11 -0
  25. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.d.ts.map +1 -0
  26. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.js +225 -0
  27. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.d.ts +13 -0
  28. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.d.ts.map +1 -0
  29. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.js +285 -0
  30. package/lib/exercises/math/dataRepresentations/scatterPlot/scatterPlotInterpreting.d.ts.map +1 -1
  31. package/lib/exercises/math/dataRepresentations/scatterPlot/scatterPlotInterpreting.js +1 -1
  32. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.d.ts +9 -0
  33. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.d.ts.map +1 -0
  34. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.js +209 -0
  35. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.d.ts +9 -0
  36. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.d.ts.map +1 -0
  37. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.js +359 -0
  38. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts +11 -0
  39. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts.map +1 -0
  40. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.js +445 -0
  41. package/lib/exercises/math/functions/affines/affineVarTableOnBoundedInterval.d.ts.map +1 -1
  42. package/lib/exercises/math/functions/affines/affineVarTableOnBoundedInterval.js +2 -3
  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 -1
  46. package/lib/exercises/math/limits/sequenceGeometricLimit.d.ts.map +1 -1
  47. package/lib/exercises/math/limits/sequenceGeometricLimit.js +9 -0
  48. package/lib/exercises/math/primitive/constantPrimitive.d.ts +8 -5
  49. package/lib/exercises/math/primitive/constantPrimitive.d.ts.map +1 -1
  50. package/lib/exercises/math/primitive/constantPrimitive.js +40 -21
  51. package/lib/exercises/math/probaStat/stats2var/averagePoint.d.ts.map +1 -1
  52. package/lib/exercises/math/probaStat/stats2var/averagePoint.js +34 -2
  53. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.d.ts +15 -0
  54. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.d.ts.map +1 -0
  55. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.js +255 -0
  56. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.d.ts +15 -0
  57. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.d.ts.map +1 -0
  58. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.js +242 -0
  59. package/lib/exercises/math/sequences/geometric/graph/geometricPlaceFirstPoints.js +4 -4
  60. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.d.ts +12 -0
  61. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.d.ts.map +1 -0
  62. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.js +161 -0
  63. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.d.ts +10 -0
  64. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.d.ts.map +1 -0
  65. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.js +224 -0
  66. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts +18 -0
  67. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts.map +1 -0
  68. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.js +198 -0
  69. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.d.ts +10 -0
  70. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.d.ts.map +1 -0
  71. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.js +231 -0
  72. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.d.ts +19 -0
  73. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.d.ts.map +1 -0
  74. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.js +187 -0
  75. package/lib/exercises/math/sets/cartesianProduct/index.d.ts +7 -0
  76. package/lib/exercises/math/sets/cartesianProduct/index.d.ts.map +1 -0
  77. package/lib/exercises/math/sets/cartesianProduct/index.js +6 -0
  78. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.d.ts +15 -0
  79. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.d.ts.map +1 -0
  80. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.js +291 -0
  81. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.d.ts +15 -0
  82. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.d.ts.map +1 -0
  83. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.js +274 -0
  84. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.d.ts +17 -0
  85. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.d.ts.map +1 -0
  86. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.js +228 -0
  87. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.d.ts +17 -0
  88. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.d.ts.map +1 -0
  89. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.js +388 -0
  90. package/lib/exercises/math/sets/combinations/index.d.ts +4 -0
  91. package/lib/exercises/math/sets/combinations/index.d.ts.map +1 -0
  92. package/lib/exercises/math/sets/combinations/index.js +3 -0
  93. package/lib/exercises/math/sets/combinations/proposeCombination.d.ts +15 -0
  94. package/lib/exercises/math/sets/combinations/proposeCombination.d.ts.map +1 -0
  95. package/lib/exercises/math/sets/combinations/proposeCombination.js +347 -0
  96. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.d.ts +16 -0
  97. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.d.ts.map +1 -0
  98. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.js +186 -0
  99. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.d.ts +17 -0
  100. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.d.ts.map +1 -0
  101. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.js +232 -0
  102. package/lib/exercises/math/sets/partialPermutations/index.d.ts +4 -0
  103. package/lib/exercises/math/sets/partialPermutations/index.d.ts.map +1 -0
  104. package/lib/exercises/math/sets/partialPermutations/index.js +3 -0
  105. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.d.ts +15 -0
  106. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.d.ts.map +1 -0
  107. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.js +343 -0
  108. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.d.ts +8 -0
  109. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.d.ts.map +1 -0
  110. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.js +193 -0
  111. package/lib/index.d.ts +15 -1
  112. package/lib/index.d.ts.map +1 -1
  113. package/lib/math/sets/setOperations.d.ts +9 -0
  114. package/lib/math/sets/setOperations.d.ts.map +1 -0
  115. package/lib/math/sets/setOperations.js +84 -0
  116. package/lib/math/sets/tuple.d.ts +12 -0
  117. package/lib/math/sets/tuple.d.ts.map +1 -0
  118. package/lib/math/sets/tuple.js +17 -0
  119. package/lib/server.js +25 -0
  120. package/lib/tree/utilities/nodePrinter.d.ts +7 -0
  121. package/lib/tree/utilities/nodePrinter.d.ts.map +1 -0
  122. package/lib/tree/utilities/nodePrinter.js +36 -0
  123. package/package.json +1 -1
@@ -0,0 +1,209 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { AffineConstructor } from "../../../../../math/polynomials/affine.js";
4
+ import { cos, CosNode } from "../../../../../tree/nodes/functions/cosNode.js";
5
+ import { opposite } from "../../../../../tree/nodes/functions/oppositeNode.js";
6
+ import { sin } from "../../../../../tree/nodes/functions/sinNode.js";
7
+ import { NodeConstructor, } from "../../../../../tree/nodes/nodeConstructor.js";
8
+ import { add } from "../../../../../tree/nodes/operators/addNode.js";
9
+ import { multiply, } from "../../../../../tree/nodes/operators/multiplyNode.js";
10
+ import { parseAlgebraic } from "../../../../../tree/parsers/latexParser.js";
11
+ import { NodeComparator } from "../../../../../tree/utilities/nodeComparator.js";
12
+ import { NodePrinter } from "../../../../../tree/utilities/nodePrinter.js";
13
+ import { handleVEAError } from "../../../../../utils/errors/handleVEAError.js";
14
+ import { alignTex } from "../../../../../utils/latex/alignTex.js";
15
+ const getInstruction = (identifiers) => {
16
+ const { nodeIdsU, nodeIdsV } = identifiers;
17
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
18
+ const nodeF = multiply(nodeU, nodeV);
19
+ return `Déterminer la dérivée de la fonction $f$ définie sur $\\mathbb{R}$ par :
20
+
21
+ $$
22
+ f(x) = ${nodeF.toTex()}
23
+ $$`;
24
+ };
25
+ const getAnswerNode = (identifiers) => {
26
+ const { nodeIdsU, nodeIdsV } = identifiers;
27
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
28
+ const [nodeAXPlusB, nodeCXPlusD] = [nodeU, nodeV].map((node) => node.child);
29
+ const [nodeA, nodeC] = [nodeAXPlusB, nodeCXPlusD].map((nodeAffine) => nodeAffine.derivative().simplify({ towardsDistribute: true }));
30
+ //u = sin(ax+b), v = cos(cx+d)
31
+ //u' = a cos(ax+b), v' = c(-sin(cx+d))
32
+ //f' = u'v+uv'
33
+ return add(multiply(multiply(nodeA, cos(nodeAXPlusB)), cos(nodeCXPlusD)), multiply(sin(nodeAXPlusB), multiply(nodeC, opposite(sin(nodeCXPlusD)))));
34
+ };
35
+ const getAnswer = (identifiers) => {
36
+ return getAnswerNode(identifiers).simplify().toTex();
37
+ };
38
+ const getHint = (_identifiers) => {
39
+ return `Si $u$ et $v$ sont deux fonctions dérivables alors, pour $x$ dans l'ensemble de dérivation de $uv$, on a :
40
+
41
+ $$
42
+ (uv)'(x) = u'(x)v(x)+u(x)v'(x)
43
+ $$
44
+
45
+ Et pour $x$ dans l'ensemble de dérivation de $u \\circ v = x \\mapsto u(v(x))$, on a :
46
+
47
+ $$
48
+ (u \\circ v)'(x) = v'(x)u'(v(x))
49
+ $$
50
+
51
+ `;
52
+ };
53
+ const getCorrection = (identifiers) => {
54
+ const { nodeIdsU, nodeIdsV } = identifiers;
55
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
56
+ const [nodeUPrime, nodeVPrime] = [nodeU, nodeV].map((node) => {
57
+ const nodeDerivativeUgly = node.derivative();
58
+ const nodeDerivativePretty = multiply(nodeDerivativeUgly.leftChild.simplify(), nodeDerivativeUgly.rightChild);
59
+ return nodeDerivativePretty;
60
+ });
61
+ return `On doit calculer la dérivée d'un produit.
62
+
63
+ Ici, $f(x) = u(x)v(x)$ avec :
64
+
65
+ $$
66
+ u(x) = ${nodeU.toTex()}
67
+ $$
68
+
69
+ $$
70
+ v(x) = ${nodeV.toTex()}
71
+ $$
72
+
73
+ On calcule (dérivées de fonctions composées):
74
+
75
+ $$
76
+ u'(x) = ${nodeUPrime.toTex()}
77
+ $$
78
+
79
+ $$
80
+ v'(x) = ${nodeVPrime.toTex()}
81
+ $$
82
+
83
+ Donc :
84
+
85
+ ${alignTex([
86
+ [`f'(x)`, `=`, `(uv)'(x)`],
87
+ [``, `=`, `u'(x)v(x)+u(x)v'(x)`],
88
+ //déborde de l'écran :
89
+ // [
90
+ // ``,
91
+ // `=`,
92
+ // add(multiply(nodeUPrime, nodeV), multiply(nodeU, nodeVPrime)).toTex(),
93
+ // ],
94
+ //remplacé par:
95
+ ...(() => {
96
+ const tex2 = multiply(nodeU, nodeVPrime).simplify().toTex();
97
+ const tex2Refined = (() => {
98
+ if (tex2.startsWith("-")) {
99
+ return tex2.replace("-", "- \\ ");
100
+ }
101
+ else {
102
+ return `+ \\ ${tex2}`;
103
+ }
104
+ })();
105
+ return [
106
+ [``, `=`, multiply(nodeUPrime, nodeV).simplify().toTex()],
107
+ [``, `\\ `, tex2Refined],
108
+ ];
109
+ })(),
110
+ ])}
111
+
112
+ `;
113
+ };
114
+ const getPropositions = (n, { answer: _answer, ...identifiers }) => {
115
+ const { nodeIdsU, nodeIdsV } = identifiers;
116
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
117
+ const [nodeUPrime, _nodeVPrime] = [nodeU, nodeV].map((node) => node.derivative().simplify());
118
+ const [nodeAXPlusB, nodeCXPlusD] = [nodeU, nodeV].map((node) => node.child);
119
+ const [nodeA, nodeC] = [nodeAXPlusB, nodeCXPlusD].map((nodeAffine) => nodeAffine.derivative().simplify({ towardsDistribute: true }));
120
+ const maxWidthForTex = 70;
121
+ const propositions = [];
122
+ const nodeAnswer = getAnswerNode(identifiers).simplify();
123
+ addValidProp(propositions, NodePrinter.toTexWithMaxWidth(nodeAnswer, maxWidthForTex));
124
+ //student: wrong derivative of cos: cos'=sin
125
+ {
126
+ class MyCosNodeWrong extends CosNode {
127
+ derivative(varName) {
128
+ return multiply(this.child.derivative(varName), sin(this.child));
129
+ }
130
+ }
131
+ const nodeVPrimeWrong = new MyCosNodeWrong(nodeCXPlusD).derivative();
132
+ const nodeDerivativeWrong = add(multiply(nodeUPrime, nodeV), multiply(nodeU, nodeVPrimeWrong)).simplify();
133
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeDerivativeWrong, maxWidthForTex));
134
+ }
135
+ //student: wrong derivative of composition: sin(ax+b)' = cos(ax+b), etc.
136
+ {
137
+ const nodeUPrimeWrong = cos(nodeAXPlusB);
138
+ const nodeVPrimeWrong = opposite(sin(nodeCXPlusD));
139
+ const nodeDerivativeWrong = add(multiply(nodeUPrimeWrong, nodeV), multiply(nodeU, nodeVPrimeWrong)).simplify();
140
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeDerivativeWrong, maxWidthForTex));
141
+ }
142
+ //student: wrong derivative of composition: sin(ax+b)' = a sin(ax+b), etc.
143
+ {
144
+ const nodeUPrimeWrong = multiply(nodeA, nodeU);
145
+ const nodeVPrimeWrong = multiply(nodeC, nodeV);
146
+ const nodeDerivativeWrong = add(multiply(nodeUPrimeWrong, nodeV), multiply(nodeU, nodeVPrimeWrong)).simplify();
147
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeDerivativeWrong, maxWidthForTex));
148
+ }
149
+ //student: makes it as if f(x) = sin(ax+b) + cos(cx+d)
150
+ {
151
+ const nodeDerivativeWrong = add(multiply(nodeA, cos(nodeAXPlusB)), multiply(nodeC, opposite(sin(nodeCXPlusD)))).simplify();
152
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeDerivativeWrong, maxWidthForTex));
153
+ }
154
+ //student: makes it as if f(x) = sin(ax+b) + cos(cx+d) + multiply
155
+ {
156
+ const nodeDerivativeWrong = multiply(multiply(nodeA, cos(nodeAXPlusB)), multiply(nodeC, opposite(sin(nodeCXPlusD)))).simplify();
157
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeDerivativeWrong, maxWidthForTex));
158
+ }
159
+ return shuffleProps(propositions, n);
160
+ };
161
+ const isAnswerValid = (ans, { answer, ...identifiers }) => {
162
+ try {
163
+ const nodeAns = parseAlgebraic(ans);
164
+ const nodeAnswer = getAnswerNode(identifiers);
165
+ return NodeComparator.isEqualViaRandomEvaluations(nodeAns, nodeAnswer, 3);
166
+ }
167
+ catch (e) {
168
+ handleVEAError(e);
169
+ return false;
170
+ }
171
+ };
172
+ const getProductOfSinAXPlusBCosCXPlusDDerivativeQuestion = () => {
173
+ const [nodeAXPlusB, nodeCXPlusD] = AffineConstructor.differentRandoms(2, undefined, { excludes: [0, 1] }).map((affine) => affine.toTree());
174
+ const nodeU = sin(nodeAXPlusB);
175
+ const nodeV = cos(nodeCXPlusD);
176
+ const identifiers = {
177
+ nodeIdsU: nodeU.toIdentifiers(),
178
+ nodeIdsV: nodeV.toIdentifiers(),
179
+ };
180
+ return getQuestionFromIdentifiers(identifiers);
181
+ };
182
+ const getQuestionFromIdentifiers = (identifiers) => {
183
+ const question = {
184
+ answer: getAnswer(identifiers),
185
+ instruction: getInstruction(identifiers),
186
+ keys: ["x", "sin", "cos", "tan"],
187
+ answerFormat: "tex",
188
+ identifiers,
189
+ hint: getHint(identifiers),
190
+ correction: getCorrection(identifiers),
191
+ };
192
+ return question;
193
+ };
194
+ export const productOfSinAXPlusBCosCXPlusDDerivative = {
195
+ id: "productOfSinAXPlusBCosCXPlusDDerivative",
196
+ connector: "=",
197
+ label: "Dérivée de $\\sin(ax+b)\\cos(cx+d)$",
198
+ isSingleStep: true,
199
+ generator: (nb) => getDistinctQuestions(getProductOfSinAXPlusBCosCXPlusDDerivativeQuestion, nb),
200
+ qcmTimer: 60,
201
+ freeTimer: 60,
202
+ getPropositions,
203
+ isAnswerValid,
204
+ subject: "Mathématiques",
205
+ getInstruction,
206
+ getAnswer,
207
+ getQuestionFromIdentifiers,
208
+ hasHintAndCorrection: true,
209
+ };
@@ -0,0 +1,9 @@
1
+ import { Exercise } from "../../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../../tree/nodes/nodeConstructor.js";
3
+ type Identifiers = {
4
+ nodeIdsU: NodeIdentifiers;
5
+ nodeIdsV: NodeIdentifiers;
6
+ };
7
+ export declare const sinAndCosMixedWithPowDerivative: Exercise<Identifiers>;
8
+ export {};
9
+ //# sourceMappingURL=sinAndCosMixedWithSquareDerivative.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sinAndCosMixedWithSquareDerivative.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAkBrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAwT7C,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,EAAE,eAAe,CAAC;CAC3B,CAAC;AA0VF,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,WAAW,CAiBjE,CAAC"}
@@ -0,0 +1,359 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { nodeByReplacingNodeAtPath, } from "../../../../../math/utils/functions/functionComposition.js";
4
+ import { randint } from "../../../../../math/utils/random/randint.js";
5
+ import { cos, CosNode } from "../../../../../tree/nodes/functions/cosNode.js";
6
+ import { FunctionsIds, isFunctionNode, } from "../../../../../tree/nodes/functions/functionNode.js";
7
+ import { sin, SinNode } from "../../../../../tree/nodes/functions/sinNode.js";
8
+ import { NodeIds } from "../../../../../tree/nodes/node.js";
9
+ import { NodeConstructor, } from "../../../../../tree/nodes/nodeConstructor.js";
10
+ import { add } from "../../../../../tree/nodes/operators/addNode.js";
11
+ import { multiply, } from "../../../../../tree/nodes/operators/multiplyNode.js";
12
+ import { isOperatorNode, OperatorIds, } from "../../../../../tree/nodes/operators/operatorNode.js";
13
+ import { isPowerNode, power, PowerNode, square, } from "../../../../../tree/nodes/operators/powerNode.js";
14
+ import { VariableNode } from "../../../../../tree/nodes/variables/variableNode.js";
15
+ import { parseAlgebraic } from "../../../../../tree/parsers/latexParser.js";
16
+ import { NodeComparator } from "../../../../../tree/utilities/nodeComparator.js";
17
+ import { NodePrinter } from "../../../../../tree/utilities/nodePrinter.js";
18
+ import { coinFlip } from "../../../../../utils/alea/coinFlip.js";
19
+ import { random } from "../../../../../utils/alea/random.js";
20
+ import { shuffle } from "../../../../../utils/alea/shuffle.js";
21
+ import { handleVEAError } from "../../../../../utils/errors/handleVEAError.js";
22
+ import { alignTex } from "../../../../../utils/latex/alignTex.js";
23
+ import { opposite } from "../../../../../tree/nodes/functions/oppositeNode.js";
24
+ import { substract } from "../../../../../tree/nodes/operators/substractNode.js";
25
+ const wrongifyViaOverriding = (node, funcDerivativeCos, funcDerivativeSin, funcDerivativePower) => {
26
+ class MyCosNodeWrong extends CosNode {
27
+ derivative(varName) {
28
+ return wrongifyViaOverriding(funcDerivativeCos(this, varName), funcDerivativeCos, funcDerivativeSin, funcDerivativePower);
29
+ }
30
+ // toTex(): string {
31
+ // return `\\text{cøs}\\left(${this.child.toTex()}\\right)`;
32
+ // }
33
+ simplify(opts = {}) {
34
+ return wrongifyViaOverriding(trueNodify(this).simplify(opts), funcDerivativeCos, funcDerivativeSin, funcDerivativePower);
35
+ }
36
+ }
37
+ class MySinNodeWrong extends SinNode {
38
+ derivative(varName) {
39
+ return wrongifyViaOverriding(funcDerivativeSin(this, varName), funcDerivativeCos, funcDerivativeSin, funcDerivativePower);
40
+ }
41
+ // toTex(): string {
42
+ // return `\\text{siin}\\left(${this.child.toTex()}\\right)`;
43
+ // }
44
+ simplify(opts = {}) {
45
+ return wrongifyViaOverriding(trueNodify(this).simplify(opts), funcDerivativeCos, funcDerivativeSin, funcDerivativePower);
46
+ }
47
+ }
48
+ class MyPowerNodeWrong extends PowerNode {
49
+ derivative(varName) {
50
+ return wrongifyViaOverriding(funcDerivativePower(this, varName), funcDerivativeCos, funcDerivativeSin, funcDerivativePower);
51
+ }
52
+ // toTex(): string {
53
+ // return `\\text{siin}\\left(${this.child.toTex()}\\right)`;
54
+ // }
55
+ simplify(opts = {}) {
56
+ return wrongifyViaOverriding(trueNodify(this).simplify(opts), funcDerivativeCos, funcDerivativeSin, funcDerivativePower);
57
+ }
58
+ }
59
+ class NodeConstructorWrong extends NodeConstructor {
60
+ static fromIdentifiers(identifiers, _log) {
61
+ switch (identifiers.id) {
62
+ case NodeIds.cos:
63
+ return new MyCosNodeWrong(NodeConstructorWrong.fromIdentifiers(identifiers.child));
64
+ case NodeIds.sin:
65
+ return new MySinNodeWrong(NodeConstructorWrong.fromIdentifiers(identifiers.child));
66
+ case NodeIds.power:
67
+ return new MyPowerNodeWrong(NodeConstructorWrong.fromIdentifiers(identifiers.leftChild), NodeConstructorWrong.fromIdentifiers(identifiers.rightChild));
68
+ default: {
69
+ const node = super.fromIdentifiers(identifiers);
70
+ if (isOperatorNode(node)) {
71
+ const [nodeLeftChild, nodeRightChild] = [
72
+ identifiers.leftChild,
73
+ identifiers.rightChild,
74
+ ].map((nodeIds) => NodeConstructorWrong.fromIdentifiers(nodeIds));
75
+ node.leftChild = nodeLeftChild;
76
+ node.rightChild = nodeRightChild;
77
+ return node;
78
+ }
79
+ else if (isFunctionNode(node)) {
80
+ const nodeChild = NodeConstructorWrong.fromIdentifiers(identifiers.child);
81
+ node.child = nodeChild;
82
+ return node;
83
+ }
84
+ else {
85
+ return node;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ function myNodeByReplacingNodeAtPath(nodeCarrier, path, nodeInjected) {
92
+ return nodeByReplacingNodeAtPath(nodeCarrier, path, nodeInjected, -1, {}, NodeConstructorWrong.fromIdentifiers);
93
+ }
94
+ if (isOperatorNode(node)) {
95
+ switch (node.id) {
96
+ case OperatorIds.power:
97
+ return new MyPowerNodeWrong(wrongifyViaOverriding(node.leftChild, funcDerivativeCos, funcDerivativeSin, funcDerivativePower), wrongifyViaOverriding(node.rightChild, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
98
+ default:
99
+ return myNodeByReplacingNodeAtPath(myNodeByReplacingNodeAtPath(node, { keys: ["leftChild"] }, wrongifyViaOverriding(node.leftChild, funcDerivativeCos, funcDerivativeSin, funcDerivativePower)), { keys: ["rightChild"] }, wrongifyViaOverriding(node.rightChild, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
100
+ }
101
+ }
102
+ else if (isFunctionNode(node)) {
103
+ switch (node.id) {
104
+ case FunctionsIds.cos:
105
+ return new MyCosNodeWrong(wrongifyViaOverriding(node.child, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
106
+ case FunctionsIds.sin:
107
+ return new MySinNodeWrong(wrongifyViaOverriding(node.child, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
108
+ default:
109
+ return myNodeByReplacingNodeAtPath(node, { keys: ["child"] }, wrongifyViaOverriding(node.child, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
110
+ }
111
+ }
112
+ else {
113
+ return node;
114
+ }
115
+ };
116
+ const trueNodify = (node) => {
117
+ if (isOperatorNode(node)) {
118
+ return nodeByReplacingNodeAtPath(nodeByReplacingNodeAtPath(node, { keys: ["leftChild"] }, trueNodify(node.leftChild)), { keys: ["rightChild"] }, trueNodify(node.rightChild));
119
+ }
120
+ else if (isFunctionNode(node)) {
121
+ switch (node.id) {
122
+ case FunctionsIds.cos:
123
+ return new CosNode(trueNodify(node.child));
124
+ case FunctionsIds.sin:
125
+ return new SinNode(trueNodify(node.child));
126
+ default:
127
+ return nodeByReplacingNodeAtPath(node, { keys: ["child"] }, trueNodify(node.child));
128
+ }
129
+ }
130
+ else {
131
+ return node;
132
+ }
133
+ };
134
+ const getPrettyNodeDerivative = (node) => {
135
+ const nodeDerivativeUgly = node.derivative();
136
+ const nodeDerivativeRight = nodeDerivativeUgly.rightChild;
137
+ const nodeDerivativeRightRight = nodeDerivativeRight.rightChild;
138
+ const nodeDerivativePretty = multiply(nodeDerivativeRight.leftChild, multiply(nodeDerivativeRightRight.leftChild.simplify(), nodeDerivativeRightRight.rightChild));
139
+ return nodeDerivativePretty;
140
+ };
141
+ const getInstruction = (identifiers) => {
142
+ const { nodeIdsU, nodeIdsV } = identifiers;
143
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
144
+ const nodeF = add(nodeU, nodeV).simplify();
145
+ return `Déterminer la dérivée de la fonction $f$ définie sur $\\mathbb{R}$ par :
146
+
147
+ $$
148
+ f(x) = ${nodeF.toTex()}
149
+ $$`;
150
+ };
151
+ const getAnswerNode = (identifiers) => {
152
+ const { nodeIdsU, nodeIdsV } = identifiers;
153
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
154
+ const [nodeUPrime, nodeVPrime] = [nodeU, nodeV].map(getPrettyNodeDerivative);
155
+ //f' = u' + v'
156
+ return add(nodeUPrime, nodeVPrime);
157
+ };
158
+ const getAnswer = (identifiers) => {
159
+ return getAnswerNode(identifiers).simplify().toTex();
160
+ };
161
+ const getHint = (_identifiers) => {
162
+ return `Si $u$ et $v$ sont deux fonctions dérivables alors, pour $x$ dans l'ensemble de dérivation de $u$ et de $v$, on a :
163
+
164
+ $$
165
+ (u+v)'(x) = u'(x)+v'(x)
166
+ $$
167
+
168
+ Et pour $x$ dans l'ensemble de dérivation de $u \\circ v = x \\mapsto u(v(x))$, on a :
169
+
170
+ $$
171
+ (u \\circ v)'(x) = v'(x)u'(v(x))
172
+ $$
173
+
174
+ `;
175
+ };
176
+ const getCorrection = (identifiers) => {
177
+ const { nodeIdsU, nodeIdsV } = identifiers;
178
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
179
+ const [nodeUPrime, nodeVPrime] = [nodeU, nodeV].map(getPrettyNodeDerivative);
180
+ return `On doit calculer la dérivée d'une somme.
181
+
182
+ Ici, $f(x) = u(x) + v(x)$ avec :
183
+
184
+ $$
185
+ u(x) = ${nodeU.toTex({})}
186
+ $$
187
+
188
+ $$
189
+ v(x) = ${nodeV.toTex()}
190
+ $$
191
+
192
+ On calcule (dérivées de fonctions composées):
193
+
194
+ $$
195
+ u'(x) = ${nodeUPrime.toTex()}
196
+ $$
197
+
198
+ $$
199
+ v'(x) = ${nodeVPrime.toTex()}
200
+ $$
201
+
202
+ Donc :
203
+
204
+ ${alignTex([
205
+ [`f'(x)`, `=`, `u'(x)+v'(x)`],
206
+ [``, `=`, getAnswerNode(identifiers).simplify().toTex()],
207
+ ])}
208
+
209
+ `;
210
+ };
211
+ const getPropositions = (n, { answer: _answer, ...identifiers }) => {
212
+ const { nodeIdsU, nodeIdsV } = identifiers;
213
+ const [nodeU, nodeV] = [nodeIdsU, nodeIdsV].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
214
+ const [_nodeUPrime, _nodeVPrime] = [nodeU, nodeV].map((node) => node.derivative().simplify());
215
+ const maxWidthForTex = 70;
216
+ const propositions = [];
217
+ const nodeAnswer = getAnswerNode(identifiers).simplify();
218
+ addValidProp(propositions, NodePrinter.toTexWithMaxWidth(nodeAnswer, maxWidthForTex));
219
+ //student: wrong derivative of cos: cos'=sin
220
+ {
221
+ function funcDerivativeCos(node, varName) {
222
+ const nodeCos = node;
223
+ return multiply(nodeCos.child.derivative(varName), sin(nodeCos.child));
224
+ }
225
+ function funcDerivativeSin(node, varName) {
226
+ const nodeSin = node;
227
+ return trueNodify(nodeSin).derivative(varName);
228
+ }
229
+ function funcDerivativePower(node, varName) {
230
+ const nodePower = node;
231
+ return trueNodify(nodePower).derivative(varName);
232
+ }
233
+ const [nodeUWronged, nodeVWronged] = [nodeU, nodeV].map((node) => wrongifyViaOverriding(node, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
234
+ const nodeWrong = add(nodeUWronged.derivative(), nodeVWronged.derivative()).simplify();
235
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeWrong, maxWidthForTex));
236
+ }
237
+ //student: wrong derivative of composition: sin(x²)' = cos(x²), etc.
238
+ {
239
+ function funcDerivativeCos(node, _varName) {
240
+ const nodeCos = node;
241
+ return opposite(sin(nodeCos.child));
242
+ }
243
+ function funcDerivativeSin(node, _varName) {
244
+ const nodeSin = node;
245
+ return cos(nodeSin.child);
246
+ }
247
+ function funcDerivativePower(node, varName) {
248
+ const nodePower = node;
249
+ return trueNodify(nodePower).derivative(varName);
250
+ }
251
+ const [nodeUWronged, nodeVWronged] = [nodeU, nodeV].map((node) => wrongifyViaOverriding(node, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
252
+ const nodeWrong = add(nodeUWronged.derivative(), nodeVWronged.derivative()).simplify();
253
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeWrong, maxWidthForTex));
254
+ }
255
+ //student: wrong derivative of composition: sin(x²)' = cos(2x), etc.
256
+ {
257
+ function funcDerivativeCos(node, varName) {
258
+ const nodeCos = node;
259
+ if (isPowerNode(nodeCos.child)) {
260
+ const nodePower = nodeCos.child;
261
+ return opposite(sin(nodePower.derivative(varName)));
262
+ }
263
+ else {
264
+ return trueNodify(nodeCos).derivative(varName);
265
+ }
266
+ }
267
+ function funcDerivativeSin(node, varName) {
268
+ const nodeSin = node;
269
+ if (isPowerNode(nodeSin.child)) {
270
+ const nodePower = nodeSin.child;
271
+ return cos(nodePower.derivative(varName));
272
+ }
273
+ else {
274
+ return trueNodify(nodeSin).derivative(varName);
275
+ }
276
+ }
277
+ function funcDerivativePower(node, varName) {
278
+ const nodePower = node;
279
+ return trueNodify(nodePower).derivative(varName);
280
+ }
281
+ const [nodeUWronged, nodeVWronged] = [nodeU, nodeV].map((node) => wrongifyViaOverriding(node, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
282
+ const nodeWrong = add(nodeUWronged.derivative(), nodeVWronged.derivative()).simplify();
283
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeWrong, maxWidthForTex));
284
+ }
285
+ //student: wrong derivative of power: (u^n)' = n u^(n-1)
286
+ {
287
+ function funcDerivativeCos(node, varName) {
288
+ const nodeCos = node;
289
+ return trueNodify(nodeCos).derivative(varName);
290
+ }
291
+ function funcDerivativeSin(node, varName) {
292
+ const nodeSin = node;
293
+ return trueNodify(nodeSin).derivative(varName);
294
+ }
295
+ function funcDerivativePower(node, _varName) {
296
+ const nodePower = node;
297
+ return multiply(nodePower.rightChild, power(nodePower.leftChild, substract(nodePower.rightChild, 1)));
298
+ }
299
+ const [nodeUWronged, nodeVWronged] = [nodeU, nodeV].map((node) => wrongifyViaOverriding(node, funcDerivativeCos, funcDerivativeSin, funcDerivativePower));
300
+ const nodeWrong = add(nodeUWronged.derivative(), nodeVWronged.derivative()).simplify();
301
+ tryToAddWrongProp(propositions, NodePrinter.toTexWithMaxWidth(nodeWrong, maxWidthForTex));
302
+ }
303
+ return shuffleProps(propositions, n);
304
+ };
305
+ const isAnswerValid = (ans, { answer, ...identifiers }) => {
306
+ try {
307
+ const nodeAns = parseAlgebraic(ans);
308
+ const nodeAnswer = getAnswerNode(identifiers);
309
+ return NodeComparator.isEqualViaRandomEvaluations(nodeAns, nodeAnswer, 3);
310
+ }
311
+ catch (e) {
312
+ handleVEAError(e);
313
+ return false;
314
+ }
315
+ };
316
+ const getSinAndCosMixedWithPowDerivativeQuestion = () => {
317
+ const nodeVarX = new VariableNode("x");
318
+ const createRandomFactorNode = () => ((coinFlip() ? +1 : -1) * randint(1, 7)).toTree();
319
+ const nodeLambda = createRandomFactorNode();
320
+ const func1 = random([sin, cos]);
321
+ const node1 = multiply(nodeLambda, square(func1(nodeVarX)));
322
+ const nodeMu = createRandomFactorNode();
323
+ const func2 = random([sin, cos]);
324
+ const node2 = multiply(nodeMu, func2(square(nodeVarX)));
325
+ const [nodeU, nodeV] = shuffle([node1, node2]);
326
+ const identifiers = {
327
+ nodeIdsU: nodeU.toIdentifiers(),
328
+ nodeIdsV: nodeV.toIdentifiers(),
329
+ };
330
+ return getQuestionFromIdentifiers(identifiers);
331
+ };
332
+ const getQuestionFromIdentifiers = (identifiers) => {
333
+ const question = {
334
+ answer: getAnswer(identifiers),
335
+ instruction: getInstruction(identifiers),
336
+ keys: ["x", "sin", "cos", "tan"],
337
+ answerFormat: "tex",
338
+ identifiers,
339
+ hint: getHint(identifiers),
340
+ correction: getCorrection(identifiers),
341
+ };
342
+ return question;
343
+ };
344
+ export const sinAndCosMixedWithPowDerivative = {
345
+ id: "sinAndCosMixedWithPowDerivative",
346
+ connector: "=",
347
+ label: "Dérivée de $f(x)= cos^2(x)$ ou $sin^2(x)$ ou $cos(x^2)$ ou $sin(x^2)$",
348
+ isSingleStep: true,
349
+ generator: (nb) => getDistinctQuestions(getSinAndCosMixedWithPowDerivativeQuestion, nb),
350
+ qcmTimer: 60,
351
+ freeTimer: 60,
352
+ getPropositions,
353
+ isAnswerValid,
354
+ subject: "Mathématiques",
355
+ getInstruction,
356
+ getAnswer,
357
+ getQuestionFromIdentifiers,
358
+ hasHintAndCorrection: true,
359
+ };
@@ -0,0 +1,11 @@
1
+ import { Exercise } from "../../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../../tree/nodes/nodeConstructor.js";
3
+ type Identifiers = {
4
+ nodeIdsLambda: NodeIdentifiers;
5
+ nodeIdsU: NodeIdentifiers;
6
+ nodeIdsV: NodeIdentifiers;
7
+ nodeIdsRewriteUsing: NodeIdentifiers;
8
+ };
9
+ export declare const sinCosDerivativeRewriteUsingCos2PlusSin2Equals1: Exercise<Identifiers>;
10
+ export {};
11
+ //# sourceMappingURL=sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AASrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAoH7C,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,eAAe,CAAC;IAC/B,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B,mBAAmB,EAAE,eAAe,CAAC;CACtC,CAAC;AAkaF,eAAO,MAAM,+CAA+C,EAAE,QAAQ,CAAC,WAAW,CAqB/E,CAAC"}