math-exercises 3.0.184 → 3.0.185

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 (26) hide show
  1. package/lib/exercises/math/functions/exponential/algebraic/approxExpAPlusB.d.ts.map +1 -1
  2. package/lib/exercises/math/functions/exponential/algebraic/approxExpAPlusB.js +91 -38
  3. package/lib/exercises/math/probaStat/trees/index.d.ts +1 -1
  4. package/lib/exercises/math/probaStat/trees/index.d.ts.map +1 -1
  5. package/lib/exercises/math/probaStat/trees/index.js +1 -3
  6. package/lib/exercises/math/probaStat/trees/probabilityTree.d.ts +9 -3
  7. package/lib/exercises/math/probaStat/trees/probabilityTree.d.ts.map +1 -1
  8. package/lib/exercises/math/probaStat/trees/probabilityTree.js +419 -45
  9. package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindRankFromSituation.d.ts.map +1 -1
  10. package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindRankFromSituation.js +3 -3
  11. package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindThresholdFromSituation.d.ts.map +1 -1
  12. package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindThresholdFromSituation.js +2 -2
  13. package/lib/exercises/math/sequences/arithmetic/situations/index.d.ts +2 -0
  14. package/lib/exercises/math/sequences/arithmetic/situations/index.d.ts.map +1 -1
  15. package/lib/exercises/math/sequences/arithmetic/situations/index.js +2 -2
  16. package/lib/index.d.ts +13 -0
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/math/utils/sequences/situations/seqArithmeticSituations.d.ts +2 -0
  19. package/lib/math/utils/sequences/situations/seqArithmeticSituations.d.ts.map +1 -1
  20. package/lib/math/utils/sequences/situations/seqArithmeticSituations.js +150 -128
  21. package/lib/math/utils/sequences/situations/seqArithmeticUtils.d.ts +1 -1
  22. package/lib/math/utils/sequences/situations/seqArithmeticUtils.d.ts.map +1 -1
  23. package/lib/math/utils/sequences/situations/seqArithmeticUtils.js +4 -1
  24. package/lib/tests/questionTest.d.ts.map +1 -1
  25. package/lib/tests/questionTest.js +1 -0
  26. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"approxExpAPlusB.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/functions/exponential/algebraic/approxExpAPlusB.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAQrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAY7C,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B,WAAW,EAAE,eAAe,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAmXF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,CAmBjD,CAAC"}
1
+ {"version":3,"file":"approxExpAPlusB.d.ts","sourceRoot":"","sources":["../../../../../../src/exercises/math/functions/exponential/algebraic/approxExpAPlusB.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAOrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAa7C,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B,WAAW,EAAE,eAAe,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AA8cF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,CAmBjD,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../../../exercises/utils/getDistinctQuestions.js";
3
3
  import { nodeBySubstitutingVar } from "../../../../../math/utils/functions/functionComposition.js";
4
- import { randfloat } from "../../../../../math/utils/random/randfloat.js";
5
4
  import { randint } from "../../../../../math/utils/random/randint.js";
6
5
  import { round } from "../../../../../math/utils/round.js";
7
6
  import { exp } from "../../../../../tree/nodes/functions/expNode.js";
@@ -13,7 +12,8 @@ import { power } from "../../../../../tree/nodes/operators/powerNode.js";
13
12
  import { substract } from "../../../../../tree/nodes/operators/substractNode.js";
14
13
  import { VariableNode } from "../../../../../tree/nodes/variables/variableNode.js";
15
14
  import { parseAlgebraic } from "../../../../../tree/parsers/latexParser.js";
16
- import { coinFlip } from "../../../../../utils/alea/coinFlip.js";
15
+ import { NodeComparator } from "../../../../../tree/utilities/nodeComparator.js";
16
+ import { probaFlip } from "../../../../../utils/alea/probaFlip.js";
17
17
  import { random } from "../../../../../utils/alea/random.js";
18
18
  import { shuffle } from "../../../../../utils/alea/shuffle.js";
19
19
  const getInstruction = (identifiers) => {
@@ -152,8 +152,8 @@ $$
152
152
  }
153
153
  };
154
154
  const getPropositions = (n, { answer, ...identifiers }) => {
155
- const { nodeIdsA, nodeIdsB, expARounded, expBRounded, precision } = identifiers;
156
- const [nodeA, nodeB] = [nodeIdsA, nodeIdsB].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
155
+ const { nodeIdsA, nodeIdsB, nodeIdsAOpB, expARounded, expBRounded, precision, } = identifiers;
156
+ const [nodeA, nodeB, nodeAOpB] = [nodeIdsA, nodeIdsB, nodeIdsAOpB].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
157
157
  const propositions = [];
158
158
  addValidProp(propositions, answer);
159
159
  //exp(a)+exp(b)
@@ -188,6 +188,22 @@ const getPropositions = (n, { answer, ...identifiers }) => {
188
188
  }
189
189
  });
190
190
  }
191
+ //terror: student computes round(exp(aOpB),precision) with their calculator
192
+ {
193
+ const nodeAOpBSubstituted = [
194
+ ["a", nodeA],
195
+ ["b", nodeB],
196
+ ]
197
+ .reduce((acc, [varName, nodeInjected]) => {
198
+ return nodeBySubstitutingVar(acc, nodeInjected, new VariableNode(varName));
199
+ }, nodeAOpB)
200
+ .simplify({ fractionsToDecimal: true });
201
+ const nodeWrong = round(nodeAOpBSubstituted.evaluate(), 0).toTree();
202
+ const tex = nodeWrong.toTex();
203
+ if (tex !== "NaN") {
204
+ tryToAddWrongProp(propositions, tex);
205
+ }
206
+ }
191
207
  //filler
192
208
  if (propositions.length < n) {
193
209
  //exp(b)-exp(a)
@@ -220,33 +236,35 @@ const getPropositions = (n, { answer, ...identifiers }) => {
220
236
  const isAnswerValid = (ans, { answer }) => {
221
237
  return ans === answer;
222
238
  };
239
+ const createRandomIdentifiers = () => {
240
+ const precision = randint(0);
241
+ const a = randint(0, 6);
242
+ const nodeA = a.toTree();
243
+ const expARounded = round(exp(nodeA).evaluate(), precision);
244
+ const nodeB = random([
245
+ // //-1
246
+ // (-1).toTree(),
247
+ //1/2
248
+ frac(1, 2),
249
+ //int
250
+ (() => randint(a, a + 5, [nodeA.evaluate()]).toTree())(),
251
+ ]);
252
+ const expBRounded = round(exp(nodeB).evaluate(), precision);
253
+ const nodeAOpB = parseAlgebraic(probaFlip(0.8) ? "a+b" : "a-b");
254
+ const identifiers = {
255
+ nodeIdsA: nodeA.toIdentifiers(),
256
+ nodeIdsB: nodeB.toIdentifiers(),
257
+ nodeIdsAOpB: nodeAOpB.toIdentifiers(),
258
+ expARounded,
259
+ expBRounded,
260
+ precision,
261
+ nodeA,
262
+ nodeB,
263
+ nodeAOpB,
264
+ };
265
+ return identifiers;
266
+ };
223
267
  const getApproxExpAPlusBQuestion = () => {
224
- function createRandomIdentifiers() {
225
- const precision = randint(1, 6);
226
- const nodeA = randfloat(0, 3, 2, [0]).toTree();
227
- const expARounded = round(exp(nodeA).evaluate(), precision);
228
- const nodeB = random([
229
- //-1
230
- (-1).toTree(),
231
- //1/2
232
- frac(1, 2),
233
- //int
234
- (() => randint(2, 11).toTree())(),
235
- ]);
236
- const expBRounded = round(exp(nodeB).evaluate(), precision);
237
- const nodeAOpB = parseAlgebraic(coinFlip() ? "a+b" : "a-b");
238
- const identifiers = {
239
- nodeIdsA: nodeA.toIdentifiers(),
240
- nodeIdsB: nodeB.toIdentifiers(),
241
- nodeIdsAOpB: nodeAOpB.toIdentifiers(),
242
- expARounded,
243
- expBRounded,
244
- precision,
245
- nodeA,
246
- nodeB,
247
- };
248
- return identifiers;
249
- }
250
268
  let identifiers;
251
269
  let counter = -1;
252
270
  let isValid = false;
@@ -254,21 +272,56 @@ const getApproxExpAPlusBQuestion = () => {
254
272
  counter++;
255
273
  const identifiersCandidate = createRandomIdentifiers();
256
274
  isValid = (() => {
257
- const { nodeA, nodeB } = identifiersCandidate;
258
- return multiply(nodeA, nodeB).evaluate() < 15;
275
+ const { nodeA, nodeB, nodeAOpB, expARounded, expBRounded } = identifiersCandidate;
276
+ const nodeAOpBSubstituted = [
277
+ ["a", nodeA],
278
+ ["b", nodeB],
279
+ ]
280
+ .reduce((acc, [varName, nodeInjected]) => {
281
+ return nodeBySubstitutingVar(acc, nodeInjected, new VariableNode(varName));
282
+ }, nodeAOpB)
283
+ .simplify({ fractionsToDecimal: true });
284
+ const isAOpBEqualToAorB = () => {
285
+ return (NodeComparator.isEqualViaSub(nodeB, nodeAOpBSubstituted) ||
286
+ NodeComparator.isEqualViaSub(nodeA, nodeAOpBSubstituted));
287
+ };
288
+ const isMentallyCalculable = () => {
289
+ function countDigits(num) {
290
+ if (!Number.isFinite(num)) {
291
+ throw new Error("Input must be a finite number.");
292
+ }
293
+ // Remove sign and decimal part
294
+ const integerPart = Math.abs(Math.trunc(num));
295
+ // Special case for 0
296
+ if (integerPart === 0)
297
+ return 1;
298
+ return integerPart.toString().length;
299
+ }
300
+ const product = expARounded * expBRounded;
301
+ return countDigits(product) <= 4 && product < 5555;
302
+ };
303
+ return !isAOpBEqualToAorB() && isMentallyCalculable();
259
304
  })();
260
305
  if (isValid) {
261
- identifiers = identifiersCandidate;
306
+ const { nodeIdsA, nodeIdsB, nodeIdsAOpB, expARounded, expBRounded, precision, } = identifiersCandidate;
307
+ identifiers = {
308
+ nodeIdsA,
309
+ nodeIdsB,
310
+ nodeIdsAOpB,
311
+ expARounded,
312
+ expBRounded,
313
+ precision,
314
+ };
262
315
  }
263
316
  }
264
317
  if (!isValid) {
265
318
  const identifiersDefault = {
266
319
  nodeIdsA: (2).toTree().toIdentifiers(),
267
- nodeIdsB: frac(1, 3).toIdentifiers(),
320
+ nodeIdsB: (3).toTree().toIdentifiers(),
268
321
  nodeIdsAOpB: parseAlgebraic("a+b").toIdentifiers(),
269
- precision: 2,
270
- expARounded: round(exp(2).evaluate(), 2),
271
- expBRounded: round(exp(frac(1, 3)).evaluate(), 2),
322
+ precision: 0,
323
+ expARounded: round(exp(2).evaluate(), 0),
324
+ expBRounded: round(exp(3).evaluate(), 0),
272
325
  };
273
326
  identifiers = identifiersDefault;
274
327
  }
@@ -287,7 +340,7 @@ const getQuestionFromIdentifiers = (identifiers, opts) => {
287
340
  };
288
341
  export const approxExpAPlusB = {
289
342
  id: "approxExpAPlusB",
290
- label: "Déterminer une valeur approchée de $\\exp⁡(a \\pm b)$ à partir de $\\exp(a)$ et $\\exp(b)$",
343
+ label: "Déterminer une valeur approchée de $\\exp⁡(a \\pm b)$ à partir de valeurs approchées de $\\exp(a)$ et de $\\exp(b)$",
291
344
  isSingleStep: true,
292
345
  generator: (nb, opts) => getDistinctQuestions(() => getApproxExpAPlusBQuestion(opts), nb),
293
346
  qcmTimer: 60,
@@ -1,4 +1,4 @@
1
- export { probabilityTree, probabilityTreeIntersection, probabilityTreeTotalProbability, probabilityTreeReadProbability, probabilityTreeInversionProbability, } from "./probabilityTreeV2.js";
1
+ export { probabilityTree, probabilityTreeIntersection, probabilityTreeTotalProbability, probabilityTreeReadProbability, probabilityTreeInversionProbability, } from "./probabilityTree.js";
2
2
  export * from "./fillProbaTreeWithComplementaryProbabilities.js";
3
3
  export * from "./buildTreeFromSituation.js";
4
4
  export * from "./probaTreeSituationTotalProbaFormula.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/trees/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,2BAA2B,EAC3B,+BAA+B,EAC/B,8BAA8B,EAC9B,mCAAmC,GACpC,MAAM,wBAAwB,CAAC;AAChC,cAAc,kDAAkD,CAAC;AACjE,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/trees/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,2BAA2B,EAC3B,+BAA+B,EAC/B,8BAA8B,EAC9B,mCAAmC,GACpC,MAAM,sBAAsB,CAAC;AAC9B,cAAc,kDAAkD,CAAC;AACjE,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC"}
@@ -1,6 +1,4 @@
1
- // export * from "./treeInInstruction.js";
2
- // export * from "./treeInAnswer.js";
3
- export { probabilityTree, probabilityTreeIntersection, probabilityTreeTotalProbability, probabilityTreeReadProbability, probabilityTreeInversionProbability, } from "./probabilityTreeV2.js";
1
+ export { probabilityTree, probabilityTreeIntersection, probabilityTreeTotalProbability, probabilityTreeReadProbability, probabilityTreeInversionProbability, } from "./probabilityTree.js";
4
2
  export * from "./fillProbaTreeWithComplementaryProbabilities.js";
5
3
  export * from "./buildTreeFromSituation.js";
6
4
  export * from "./probaTreeSituationTotalProbaFormula.js";
@@ -8,12 +8,18 @@ type Identifiers = {
8
8
  BC: NodeIdentifiers;
9
9
  BD: NodeIdentifiers;
10
10
  probaName: string;
11
+ useContraryNames?: boolean;
11
12
  };
12
13
  type Options = {
13
- allowApproximate: string;
14
- eventTypes: string[];
15
- probaType: string;
14
+ allowApproximate?: string;
15
+ eventTypes?: string[];
16
+ probaType?: string;
17
+ eventsNames?: string;
16
18
  };
17
19
  export declare const probabilityTree: Exercise<Identifiers, Options>;
20
+ export declare const probabilityTreeIntersection: Exercise<Identifiers, Options>;
21
+ export declare const probabilityTreeTotalProbability: Exercise<Identifiers, Options>;
22
+ export declare const probabilityTreeReadProbability: Exercise<Identifiers, Options>;
23
+ export declare const probabilityTreeInversionProbability: Exercise<Identifiers, Options>;
18
24
  export {};
19
25
  //# sourceMappingURL=probabilityTree.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"probabilityTree.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/trees/probabilityTree.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAQ7C,OAAO,EACL,QAAQ,EAiBT,MAAM,sBAAsB,CAAC;AAG9B,KAAK,WAAW,GAAG;IAIjB,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,eAAe,CAAC;IACnB,EAAE,EAAE,eAAe,CAAC;IACpB,EAAE,EAAE,eAAe,CAAC;IACpB,EAAE,EAAE,eAAe,CAAC;IACpB,EAAE,EAAE,eAAe,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAkNF,KAAK,OAAO,GAAG;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AA2CF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAe1D,CAAC"}
1
+ {"version":3,"file":"probabilityTree.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/probaStat/trees/probabilityTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAQ7C,OAAO,EACL,QAAQ,EAkBT,MAAM,sBAAsB,CAAC;AAG9B,KAAK,WAAW,GAAG;IAIjB,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,eAAe,CAAC;IACnB,EAAE,EAAE,eAAe,CAAC;IACpB,EAAE,EAAE,eAAe,CAAC;IACpB,EAAE,EAAE,eAAe,CAAC;IACpB,EAAE,EAAE,eAAe,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAuhBF,KAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAwDF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAe1D,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAwBtE,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAwB1E,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CA2BzE,CAAC;AAEF,eAAO,MAAM,mCAAmC,EAAE,QAAQ,CACxD,WAAW,EACX,OAAO,CA0BR,CAAC"}