math-exercises 3.0.2 → 3.0.4

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/calculLitteral/factorisation/factorizeCanonicalForm.d.ts.map +1 -1
  2. package/lib/exercises/math/calculLitteral/factorisation/factorizeCanonicalForm.js +85 -35
  3. package/lib/exercises/math/functions/affines/affineExpressionFromTwoImages.d.ts.map +1 -1
  4. package/lib/exercises/math/functions/affines/affineExpressionFromTwoImages.js +3 -17
  5. package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.d.ts.map +1 -1
  6. package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.js +54 -20
  7. package/lib/exercises/math/functions/basics/imageFunction.d.ts +10 -6
  8. package/lib/exercises/math/functions/basics/imageFunction.d.ts.map +1 -1
  9. package/lib/exercises/math/functions/basics/imageFunction.js +137 -54
  10. package/lib/exercises/math/functions/basics/imageFunctionGeogebra.d.ts +10 -4
  11. package/lib/exercises/math/functions/basics/imageFunctionGeogebra.d.ts.map +1 -1
  12. package/lib/exercises/math/functions/basics/imageFunctionGeogebra.js +184 -43
  13. package/lib/exercises/math/functions/cube/cubicEquation.d.ts.map +1 -1
  14. package/lib/exercises/math/functions/cube/cubicEquation.js +33 -13
  15. package/lib/exercises/math/probaStat/basicStats/calculateFrequency.js +1 -1
  16. package/lib/exercises/math/sequences/arithmetic/arithmeticFindExplicitFormula.d.ts.map +1 -1
  17. package/lib/exercises/math/sequences/arithmetic/arithmeticFindExplicitFormula.js +24 -11
  18. package/lib/exercises/math/trigonometry/associatePoint.d.ts.map +1 -1
  19. package/lib/geogebra/lagrange.d.ts +2 -0
  20. package/lib/geogebra/lagrange.d.ts.map +1 -1
  21. package/lib/geogebra/lagrange.js +2 -10
  22. package/lib/index.d.ts +16 -10
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +3 -1
  25. package/lib/math/geometry/parabola.d.ts +11 -0
  26. package/lib/math/geometry/parabola.d.ts.map +1 -0
  27. package/lib/math/geometry/parabola.js +32 -0
  28. package/lib/math/polynomials/generalPolynomial.d.ts +19 -0
  29. package/lib/math/polynomials/generalPolynomial.d.ts.map +1 -0
  30. package/lib/math/polynomials/generalPolynomial.js +44 -0
  31. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"factorizeCanonicalForm.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/factorisation/factorizeCanonicalForm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAUT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAiGF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAexD,CAAC"}
1
+ {"version":3,"file":"factorizeCanonicalForm.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/factorisation/factorizeCanonicalForm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAerC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA2IF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAmBxD,CAAC"}
@@ -3,31 +3,40 @@ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQue
3
3
  import { Affine } from "../../../../math/polynomials/affine.js";
4
4
  import { randint } from "../../../../math/utils/random/randint.js";
5
5
  import { AddNode } from "../../../../tree/nodes/operators/addNode.js";
6
- import { MultiplyNode } from "../../../../tree/nodes/operators/multiplyNode.js";
6
+ import { isMultiplyNode, MultiplyNode, } from "../../../../tree/nodes/operators/multiplyNode.js";
7
7
  import { SquareNode } from "../../../../tree/nodes/operators/powerNode.js";
8
8
  import { SubstractNode } from "../../../../tree/nodes/operators/substractNode.js";
9
+ import { parseAlgebraic } from "../../../../tree/parsers/latexParser.js";
10
+ import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
9
11
  import { alignTex } from "../../../../utils/latex/alignTex.js";
10
- //(x-a)^2-b^2 avec b entier
11
- const getFactorizeCanonicalFormQuestion = () => {
12
- const affine = new Affine(1, randint(-10, 10, [0]));
13
- const b = randint(-10, 10, [0]);
12
+ const getStatementNode = (identifiers) => {
13
+ const { a, b } = identifiers;
14
+ const affine = new Affine(1, a);
14
15
  const statement = new SubstractNode(new SquareNode(affine.toTree()), (b ** 2).toTree());
15
- const bPositive = Math.abs(b);
16
- const answer = new MultiplyNode(affine.add(-bPositive).toTree(), affine.add(bPositive).toTree()).toTex();
17
- const statementTex = statement.toTex();
18
- const question = {
19
- answer,
20
- instruction: `Factoriser : $${statementTex}$`,
21
- keys: ["x"],
22
- answerFormat: "tex",
23
- identifiers: { a: affine.b, b },
24
- hint: `Utilise l'identité remarquable
16
+ return statement;
17
+ };
18
+ const getInstruction = (identifiers) => {
19
+ const statementTex = getStatementNode(identifiers).toTex();
20
+ return `Factoriser :
21
+
22
+ $$
23
+ ${statementTex}
24
+ $$`;
25
+ };
26
+ const getHint = (identifiers) => {
27
+ return `Utilise l'identité remarquable
25
28
 
26
29
  $$
27
30
  a^2 - b^2 = (a-b)(a+b)
28
- $$`,
29
- correction: `
30
- On utilise l'identité remarquable
31
+ $$`;
32
+ };
33
+ const getCorrection = (identifiers) => {
34
+ const { a, b } = identifiers;
35
+ const affine = new Affine(1, a);
36
+ const bPositive = Math.abs(b);
37
+ const statementTex = getStatementNode(identifiers).toTex();
38
+ const answer = getAnswer(identifiers);
39
+ return `On utilise l'identité remarquable
31
40
 
32
41
  $$
33
42
  a^2 - b^2=(a-b)(a+b)
@@ -36,18 +45,39 @@ $$
36
45
  en prenant $a=${affine.toTex()}$ et $b=${bPositive}$ :
37
46
 
38
47
  ${alignTex([
39
- [
40
- statementTex,
41
- "=",
42
- new SubstractNode(new SquareNode(affine.toTree()), new SquareNode(bPositive.toTree())).toTex(),
43
- ],
44
- [
45
- "",
46
- "=",
47
- new MultiplyNode(new AddNode(affine.toTree(), (-bPositive).toTree()), new AddNode(affine.toTree(), bPositive.toTree())).toTex(),
48
- ],
49
- ["", "=", answer],
50
- ])}`,
48
+ [
49
+ statementTex,
50
+ "=",
51
+ new SubstractNode(new SquareNode(affine.toTree()), new SquareNode(bPositive.toTree())).toTex(),
52
+ ],
53
+ [
54
+ "",
55
+ "=",
56
+ new MultiplyNode(new AddNode(affine.toTree(), (-bPositive).toTree()), new AddNode(affine.toTree(), bPositive.toTree())).toTex(),
57
+ ],
58
+ ["", "=", answer],
59
+ ])}`;
60
+ };
61
+ const getAnswer = (identifiers) => {
62
+ const { a, b } = identifiers;
63
+ const affine = new Affine(1, a);
64
+ const bPositive = Math.abs(b);
65
+ const answer = new MultiplyNode(affine.add(-bPositive).toTree(), affine.add(bPositive).toTree()).toTex();
66
+ return answer;
67
+ };
68
+ //(x-a)^2-b^2 avec b entier
69
+ const getFactorizeCanonicalFormQuestion = () => {
70
+ const affine = new Affine(1, randint(-10, 10, [0]));
71
+ const b = randint(-10, 10, [0]);
72
+ const identifiers = { a: affine.b, b };
73
+ const question = {
74
+ answer: getAnswer(identifiers),
75
+ instruction: getInstruction(identifiers),
76
+ keys: ["x"],
77
+ answerFormat: "tex",
78
+ identifiers,
79
+ hint: getHint(identifiers),
80
+ correction: getCorrection(identifiers),
51
81
  };
52
82
  return question;
53
83
  };
@@ -61,11 +91,27 @@ const getPropositions = (n, { answer, a, b }) => {
61
91
  }
62
92
  return shuffleProps(propositions, n);
63
93
  };
64
- const isAnswerValid = (ans, { answer, a, b }) => {
65
- const affine = new Affine(1, a);
66
- const bPositive = Math.abs(b);
67
- const answerTree = new MultiplyNode(affine.add(-bPositive).toTree(), affine.add(bPositive).toTree());
68
- return answerTree.toAllValidTexs().includes(ans);
94
+ const isAnswerValid = (ans, { answer, ...identifiers }) => {
95
+ try {
96
+ const parsed = parseAlgebraic(ans);
97
+ if (!parsed)
98
+ return false;
99
+ if (!isMultiplyNode(parsed))
100
+ return false;
101
+ const simp = parsed.simplify({
102
+ forbidFactorize: true,
103
+ towardsDistribute: true,
104
+ });
105
+ const answerSimp = getStatementNode(identifiers).simplify({
106
+ towardsDistribute: true,
107
+ forbidFactorize: true,
108
+ });
109
+ // const simp = parsed.simplify({});
110
+ return simp.toTex() === answerSimp.toTex();
111
+ }
112
+ catch (err) {
113
+ return handleVEAError(err);
114
+ }
69
115
  };
70
116
  export const factorizeCanonicalForm = {
71
117
  id: "factorizeCanonicalForm",
@@ -81,4 +127,8 @@ export const factorizeCanonicalForm = {
81
127
  isAnswerValid,
82
128
  subject: "Mathématiques",
83
129
  hasHintAndCorrection: true,
130
+ getAnswer,
131
+ getInstruction,
132
+ getCorrection,
133
+ getHint,
84
134
  };
@@ -1 +1 @@
1
- {"version":3,"file":"affineExpressionFromTwoImages.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/affines/affineExpressionFromTwoImages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAerC,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AA+IF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,CAgB/D,CAAC"}
1
+ {"version":3,"file":"affineExpressionFromTwoImages.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/affines/affineExpressionFromTwoImages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAerC,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAgIF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,CAgB/D,CAAC"}
@@ -91,7 +91,7 @@ const getPropositions = (n, { answer, xA, xB, yA, yB }) => {
91
91
  }
92
92
  return shuffle(propositions);
93
93
  };
94
- const isAnswerValid = (ans, { xA, xB, yA, yB }) => {
94
+ const isAnswerValid = (ans, { answer, xA, xB, yA, yB }) => {
95
95
  try {
96
96
  const parsed = parseAlgebraic(ans);
97
97
  if (!parsed)
@@ -101,27 +101,13 @@ const isAnswerValid = (ans, { xA, xB, yA, yB }) => {
101
101
  towardsDistribute: true,
102
102
  forbidFactorize: true,
103
103
  forceDistributeFractions: true,
104
+ decimalToFractions: true,
104
105
  })
105
- .toTex() === ans);
106
+ .toTex() === answer);
106
107
  }
107
108
  catch (err) {
108
109
  return handleVEAError(err);
109
110
  }
110
- // const a = new Rational(yB - yA, xB - xA).simplify().toTree();
111
- // //yA = axA+b donc b = yA-axA
112
- // const b = new SubstractNode(
113
- // yA.toTree(),
114
- // new MultiplyNode(a, xA.toTree()),
115
- // ).simplify();
116
- // const answer = new AddNode(new MultiplyNode(a, new VariableNode("x")), b, {
117
- // allowFractionToDecimal: true,
118
- // }).simplify({
119
- // forceDistributeFractions: true,
120
- // towardsDistribute: true,
121
- // forbidFactorize: true,
122
- // });
123
- // const texs = answer.toAllValidTexs();
124
- // return texs.includes(ans);
125
111
  };
126
112
  export const affineExpressionFromTwoImages = {
127
113
  id: "affineExpressionFromTwoImages",
@@ -1 +1 @@
1
- {"version":3,"file":"leadingCoeffAndOriginOrdinate.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,6BAA6B,CAAC;AAMrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AA4DF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,CAc/D,CAAC"}
1
+ {"version":3,"file":"leadingCoeffAndOriginOrdinate.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAMrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAyFF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,CAiB/D,CAAC"}
@@ -1,17 +1,60 @@
1
1
  import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
- import { AffineConstructor } from "../../../../math/polynomials/affine.js";
3
+ import { Affine, AffineConstructor } from "../../../../math/polynomials/affine.js";
4
4
  import { randint } from "../../../../math/utils/random/randint.js";
5
5
  import { coinFlip } from "../../../../utils/alea/coinFlip.js";
6
+ const getHint = (identifiers) => {
7
+ return `Dans l'expression algébrique d'une fonction affine :
8
+
9
+ $$
10
+ f(x) = ax+b
11
+ $$
12
+
13
+ le coefficient directeur est $a$ et l'ordonnée à l'origine est $b$.`;
14
+ };
15
+ const getCorrection = (identifiers) => {
16
+ const { a, b, isAskingA } = identifiers;
17
+ return `Dans l'expression algébrique d'une fonction affine :
18
+
19
+ $$
20
+ f(x) = ax+b
21
+ $$
22
+
23
+ le coefficient directeur est $a$ et l'ordonnée à l'origine est $b$.
24
+
25
+ Ici, on a $a = ${a}$ et $b = ${b}$.
26
+
27
+ ${isAskingA
28
+ ? `Le coefficient directeur est donc $${a}$.`
29
+ : `L'ordonnée à l'origine est donc $${b}$.`}
30
+ `;
31
+ };
32
+ const getInstruction = (identifiers) => {
33
+ const { a, b, isAskingA } = identifiers;
34
+ const f = new Affine(a, b);
35
+ return `Soit la fonction affine $f(x)=${f.toTex()}$.
36
+
37
+ ${isAskingA
38
+ ? `Déterminer la valeur du coefficient directeur.`
39
+ : `Déterminer la valeur de l'ordonnée à l'origine.`}`;
40
+ };
41
+ const getAnswer = (identifiers) => {
42
+ const { a, b, isAskingA } = identifiers;
43
+ const correctAnwer = isAskingA ? a : b;
44
+ return correctAnwer.frenchify();
45
+ };
6
46
  const getLeadingCoeffAndOriginOrdinateQuestion = () => {
7
- const exercise = generateExercise();
8
- const isAskingA = +exercise.correctAnwer === exercise.f.a ? true : false;
47
+ const isAskingA = coinFlip();
48
+ const f = AffineConstructor.random();
49
+ const identifiers = { a: f.a, b: f.b, isAskingA };
9
50
  const question = {
10
- answer: exercise.correctAnwer,
11
- instruction: exercise.instruction,
51
+ answer: getAnswer(identifiers),
52
+ instruction: getInstruction(identifiers),
12
53
  keys: [],
13
54
  answerFormat: "tex",
14
- identifiers: { a: exercise.f.a, b: exercise.f.b, isAskingA },
55
+ identifiers,
56
+ hint: getHint(identifiers),
57
+ correction: getCorrection(identifiers),
15
58
  };
16
59
  return question;
17
60
  };
@@ -31,28 +74,19 @@ const getPropositions = (n, { answer, a, b, isAskingA }) => {
31
74
  const isAnswerValid = (ans, { answer }) => {
32
75
  return ans === answer;
33
76
  };
34
- const generateExercise = () => {
35
- const flip = coinFlip();
36
- const f = AffineConstructor.random();
37
- const instruction = `Soit la fonction affine $f(x)=${f.toTex()}$. ${flip
38
- ? `Déterminer la valeur du coefficient directeur.`
39
- : `Déterminer la valeur de l'ordonnée à l'origine.`}`;
40
- return {
41
- instruction,
42
- correctAnwer: flip ? f.a + "" : f.b + "",
43
- f,
44
- };
45
- };
46
77
  export const leadingCoeffAndOriginOrdinate = {
47
78
  id: "leadingCoeffAndOriginOrdinate",
48
79
  label: "Identifier le coefficient directeur ou l'ordonnée à l'origine d'une fonction affine",
49
- levels: ["2nde"],
50
80
  isSingleStep: true,
51
- sections: ["Fonctions affines"],
52
81
  generator: (nb) => getDistinctQuestions(getLeadingCoeffAndOriginOrdinateQuestion, nb),
53
82
  qcmTimer: 60,
54
83
  freeTimer: 60,
55
84
  getPropositions,
56
85
  isAnswerValid,
57
86
  subject: "Mathématiques",
87
+ getInstruction,
88
+ getAnswer,
89
+ getHint,
90
+ getCorrection,
91
+ hasHintAndCorrection: true,
58
92
  };
@@ -1,11 +1,15 @@
1
1
  import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
2
3
  type Identifiers = {
3
- rand: boolean;
4
- poly1: number[];
5
- poly2: number[];
6
- xValue: number;
7
- flip: boolean;
4
+ xValue: NodeIdentifiers;
5
+ polynomeCoeffs: NodeIdentifiers[];
6
+ imageSyntaxText: boolean;
8
7
  };
9
- export declare const imageFunction: Exercise<Identifiers>;
8
+ type Options = {
9
+ functionType: string[];
10
+ coeffsType: string[];
11
+ xType: string[];
12
+ };
13
+ export declare const imageFunction: Exercise<Identifiers, Options>;
10
14
  export {};
11
15
  //# sourceMappingURL=imageFunction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageFunction.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/basics/imageFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAqGF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,WAAW,CAkB/C,CAAC"}
1
+ {"version":3,"file":"imageFunction.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/basics/imageFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAiBT,MAAM,6BAA6B,CAAC;AAWrC,OAAO,EACL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAW7C,KAAK,WAAW,GAAG;IAOjB,MAAM,EAAE,eAAe,CAAC;IACxB,cAAc,EAAE,eAAe,EAAE,CAAC;IAClC,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AAoLF,KAAK,OAAO,GAAG;IACb,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AA4BF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAmBxD,CAAC"}
@@ -1,92 +1,149 @@
1
- import { addValidProp, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
1
+ import { GeneratorOptionTarget, GeneratorOptionType, addValidProp, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
- import { Polynomial } from "../../../../math/polynomials/polynomial.js";
3
+ import { RationalConstructor } from "../../../../math/numbers/rationals/rational.js";
4
+ import { GeneralPolynomial, } from "../../../../math/polynomials/generalPolynomial.js";
5
+ import { randfloat } from "../../../../math/utils/random/randfloat.js";
4
6
  import { randint } from "../../../../math/utils/random/randint.js";
7
+ import { reifyAlgebraic, } from "../../../../tree/nodes/nodeConstructor.js";
8
+ import { add } from "../../../../tree/nodes/operators/addNode.js";
5
9
  import { parseAlgebraic } from "../../../../tree/parsers/latexParser.js";
6
10
  import { coinFlip } from "../../../../utils/alea/coinFlip.js";
11
+ import { random } from "../../../../utils/alea/random.js";
7
12
  import { shuffle } from "../../../../utils/alea/shuffle.js";
8
13
  import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
9
14
  import { alignTex } from "../../../../utils/latex/alignTex.js";
10
- const getInstruction = (identifiers) => {
11
- const { rand, poly1, poly2, xValue, flip } = identifiers;
12
- const polynome1 = new Polynomial(poly1);
13
- const polynome2 = new Polynomial(poly2);
14
- const statement = `Soit $f(x) = ${(rand ? polynome1 : polynome2)
15
- .toTree()
16
- .toTex()}$.
15
+ const rebuildIdentifiers = (oldIdentifiers) => {
16
+ const polynomeCoeffsNumbers = oldIdentifiers.rand
17
+ ? oldIdentifiers.poly1
18
+ : oldIdentifiers.poly2;
19
+ const polynomeCoeffs = polynomeCoeffsNumbers.map((n) => n.toTree().toIdentifiers());
20
+ return {
21
+ imageSyntaxText: oldIdentifiers.flip ?? true,
22
+ xValue: oldIdentifiers.xValue.toTree().toIdentifiers(),
23
+ polynomeCoeffs,
24
+ };
25
+ };
26
+ const getInstruction = (identifiers, opts) => {
27
+ // const { rand, poly1, poly2, xValue, flip } = identifiers;
28
+ // const polynome1 = new Polynomial(poly1);
29
+ // const polynome2 = new Polynomial(poly2);
30
+ const { xValue, polynomeCoeffs, imageSyntaxText } = identifiers;
31
+ const xValueTex = reifyAlgebraic(xValue).toTex();
32
+ const coeffsNode = polynomeCoeffs.map((coeff) => reifyAlgebraic(coeff));
33
+ const polynome = new GeneralPolynomial(coeffsNode);
34
+ const statement = `Soit $f(x) = ${polynome.toTree().toTex()}$.
17
35
 
18
- Calculer ${flip ? `l'image de $${xValue}$ par $f$.` : `$f(${xValue})$.`}`;
36
+ Calculer ${imageSyntaxText
37
+ ? `l'image de $${xValueTex}$ par $f$.`
38
+ : `$f\\left(${xValueTex}\\right)$.`}`;
19
39
  return statement;
20
40
  };
21
- const getAnswer = (identifiers) => {
22
- const { rand, poly1, poly2, xValue } = identifiers;
23
- const polynome1 = new Polynomial(poly1);
24
- const polynome2 = new Polynomial(poly2);
25
- const answer = rand
26
- ? polynome1.calculate(xValue) + ""
27
- : polynome2.calculate(xValue) + "";
41
+ const getAnswer = (identifiers, opts) => {
42
+ const { xValue, polynomeCoeffs, imageSyntaxText } = identifiers;
43
+ const xValueNode = reifyAlgebraic(xValue);
44
+ const coeffsNode = polynomeCoeffs.map((coeff) => reifyAlgebraic(coeff));
45
+ const polynome = new GeneralPolynomial(coeffsNode);
46
+ const answer = polynome
47
+ .toTree()
48
+ .toDetailedEvaluation({ x: xValueNode })
49
+ .simplify()
50
+ .toTex();
28
51
  return answer;
29
52
  };
30
- const getHint = (identifiers) => {
31
- return `Remplace $x$ par $${identifiers.xValue}$ dans l'expression de $f$.`;
53
+ const getHint = (identifiers, opts) => {
54
+ const { xValue, polynomeCoeffs, imageSyntaxText } = identifiers;
55
+ const xValueTex = reifyAlgebraic(xValue).toTex();
56
+ return `Remplace $x$ par $${xValueTex}$ dans l'expression de $f$.`;
32
57
  };
33
- const getCorrection = (identifiers) => {
58
+ const getCorrection = (identifiers, opts) => {
59
+ const { xValue, polynomeCoeffs, imageSyntaxText } = identifiers;
60
+ const xValueNode = reifyAlgebraic(xValue);
61
+ const xValueTex = xValueNode.toTex();
62
+ const coeffsNode = polynomeCoeffs.map((coeff) => reifyAlgebraic(coeff));
63
+ const polynome = new GeneralPolynomial(coeffsNode).toTree();
34
64
  const answer = getAnswer(identifiers);
35
- const { rand, poly1, poly2, xValue, flip } = identifiers;
36
- const polynome1 = new Polynomial(poly1).toTree();
37
- const polynome2 = new Polynomial(poly2).toTree();
38
- return `On remplace $x$ par $${identifiers.xValue}$ dans l'expression de $f$ :
65
+ return `On remplace $x$ par $${xValueTex}$ dans l'expression de $f$ :
39
66
 
40
67
  ${alignTex([
41
68
  [
42
- `f\\left(${identifiers.xValue}\\right)`,
69
+ `f\\left(${xValueTex}\\right)`,
43
70
  "=",
44
- rand
45
- ? polynome1.toDetailedEvaluation({ x: xValue.toTree() }).toTex()
46
- : polynome2.toDetailedEvaluation({ x: xValue.toTree() }).toTex(),
71
+ polynome.toDetailedEvaluation({ x: xValueNode }).toTex(),
47
72
  ],
48
73
  ["", "=", answer],
49
74
  ])}`;
50
75
  };
51
- const getImageFunction = () => {
52
- const rand = coinFlip();
53
- const polynome1 = new Polynomial([randint(-9, 10), randint(-5, 6, [0])]);
54
- const polynome2 = new Polynomial([
55
- randint(-9, 10),
56
- randint(-9, 10),
57
- randint(-4, 5, [0]),
58
- ]);
59
- const xValue = randint(-9, 10);
60
- const flip = coinFlip();
76
+ const getStartStatement = (identifiers) => {
77
+ const { xValue, polynomeCoeffs, imageSyntaxText } = identifiers;
78
+ const xValueTex = reifyAlgebraic(xValue).toTex();
79
+ return `f\\left(${xValueTex}\\right)`;
80
+ };
81
+ const getImageFunction = (opts) => {
82
+ // xValue: NodeIdentifiers;
83
+ // polynomeCoeffs: NodeIdentifiers[]; // [0] is the constant term
84
+ // imageSyntaxText: boolean;
85
+ const functionType = opts?.functionType ?? ["Affine", "Trinôme"];
86
+ const allowTrinom = functionType.includes("Trinôme");
87
+ const allowAffine = functionType.includes("Affine");
88
+ const isTrinom = !allowTrinom ? false : allowAffine ? coinFlip() : true;
89
+ const imageSyntaxText = coinFlip();
90
+ const xType = random(opts?.xType ?? ["Entier"]);
91
+ const coeffsTypes = opts?.coeffsType ?? ["Entiers"];
92
+ const buildNb = (type, excludes = []) => {
93
+ switch (type) {
94
+ case "Entier":
95
+ case "Entiers":
96
+ return randint(-9, 10, excludes).toTree().toIdentifiers();
97
+ case "Décimal":
98
+ case "Décimaux":
99
+ return randfloat(-9, 10, 1, excludes).toTree().toIdentifiers();
100
+ case "Rationnel":
101
+ case "Rationnels":
102
+ default:
103
+ return RationalConstructor.randomIrreductible()
104
+ .toTree()
105
+ .toIdentifiers();
106
+ }
107
+ };
108
+ const xValue = buildNb(xType);
109
+ const coeffs = isTrinom
110
+ ? [
111
+ buildNb(random(coeffsTypes)),
112
+ buildNb(random(coeffsTypes)),
113
+ buildNb(random(coeffsTypes), [0]),
114
+ ]
115
+ : [buildNb(random(coeffsTypes)), buildNb(random(coeffsTypes), [0])];
61
116
  const identifiers = {
62
- poly1: polynome1.coefficients,
63
- poly2: polynome2.coefficients,
64
- rand,
117
+ polynomeCoeffs: coeffs,
118
+ imageSyntaxText,
65
119
  xValue,
66
- flip,
67
120
  };
68
121
  const question = {
69
- instruction: getInstruction(identifiers),
70
- startStatement: `f(${xValue})`,
71
- answer: getAnswer(identifiers),
122
+ instruction: getInstruction(identifiers, opts),
123
+ startStatement: getStartStatement(identifiers),
124
+ answer: getAnswer(identifiers, opts),
72
125
  keys: [],
73
- hint: getHint(identifiers),
74
- correction: getCorrection(identifiers),
126
+ hint: getHint(identifiers, opts),
127
+ correction: getCorrection(identifiers, opts),
75
128
  answerFormat: "tex",
76
129
  identifiers,
77
130
  };
78
131
  return question;
79
132
  };
80
- const getPropositions = (n, { answer }) => {
133
+ const getPropositions = (n, { answer, ...identifiers }, opts) => {
81
134
  const propositions = [];
82
135
  addValidProp(propositions, answer);
136
+ const { xValue, polynomeCoeffs } = identifiers;
137
+ const xValueNode = reifyAlgebraic(xValue);
138
+ const coeffsNode = polynomeCoeffs.map((coeff) => reifyAlgebraic(coeff));
139
+ const polynome = new GeneralPolynomial(coeffsNode).toTree();
83
140
  while (propositions.length < n) {
84
- const wrongAnswer = Number(answer) + randint(-10, 11, [0]);
85
- tryToAddWrongProp(propositions, wrongAnswer + "");
141
+ const wrongX = add(xValueNode, randint(-3, 4, [0]).toTree()).simplify();
142
+ tryToAddWrongProp(propositions, polynome.toDetailedEvaluation({ x: wrongX }).simplify().toTex());
86
143
  }
87
144
  return shuffle(propositions);
88
145
  };
89
- const isAnswerValid = (ans, { answer }) => {
146
+ const isAnswerValid = (ans, { answer }, opts) => {
90
147
  try {
91
148
  const parsed = parseAlgebraic(ans);
92
149
  if (!parsed)
@@ -97,14 +154,38 @@ const isAnswerValid = (ans, { answer }) => {
97
154
  return handleVEAError(err);
98
155
  }
99
156
  };
157
+ const options = [
158
+ {
159
+ id: "functionType",
160
+ label: "Type de fonction",
161
+ target: GeneratorOptionTarget.generation,
162
+ type: GeneratorOptionType.multiselect,
163
+ defaultValue: ["Affine", "Trinôme"],
164
+ values: ["Affine", "Trinôme"],
165
+ },
166
+ {
167
+ id: "coeffsType",
168
+ label: "Type des coefficients",
169
+ target: GeneratorOptionTarget.generation,
170
+ type: GeneratorOptionType.multiselect,
171
+ defaultValue: ["Entiers"],
172
+ values: ["Entiers", "Décimaux", "Rationnels"],
173
+ },
174
+ {
175
+ id: "xType",
176
+ label: "Type du nombre $x$",
177
+ target: GeneratorOptionTarget.generation,
178
+ type: GeneratorOptionType.multiselect,
179
+ defaultValue: ["Entier"],
180
+ values: ["Entier", "Décimal", "Rationnel"],
181
+ },
182
+ ];
100
183
  export const imageFunction = {
101
184
  id: "imageFunction",
102
185
  connector: "=",
103
186
  label: "Calcul d'image par une fonction",
104
- levels: ["3ème", "2nde", "CAP", "2ndPro", "1rePro", "1reTech"],
105
- sections: ["Fonctions"],
106
187
  isSingleStep: true,
107
- generator: (nb) => getDistinctQuestions(getImageFunction, nb),
188
+ generator: (nb, opts) => getDistinctQuestions(() => getImageFunction(opts), nb),
108
189
  qcmTimer: 60,
109
190
  freeTimer: 60,
110
191
  getPropositions,
@@ -115,4 +196,6 @@ export const imageFunction = {
115
196
  getHint,
116
197
  hasHintAndCorrection: true,
117
198
  getInstruction,
199
+ options,
200
+ rebuildIdentifiers,
118
201
  };
@@ -1,11 +1,17 @@
1
1
  import { Exercise } from "../../../../exercises/exercise.js";
2
2
  type Identifiers = {
3
- /**old */
4
- isSpline: boolean;
5
- splinePoints: number[][];
3
+ /**very old */
4
+ /** old */
5
+ /** new */
6
+ functionType: string;
6
7
  x: number;
7
8
  y: number;
9
+ wrongY: number;
10
+ otherPoints: number[][];
8
11
  };
9
- export declare const imageFunctionGeogebra: Exercise<Identifiers>;
12
+ type Options = {
13
+ curveTypes: string[];
14
+ };
15
+ export declare const imageFunctionGeogebra: Exercise<Identifiers, Options>;
10
16
  export {};
11
17
  //# sourceMappingURL=imageFunctionGeogebra.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageFunctionGeogebra.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/basics/imageFunctionGeogebra.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,6BAA6B,CAAC;AAiBrC,KAAK,WAAW,GAAG;IACjB,SAAS;IAIT,QAAQ,EAAE,OAAO,CAAC;IAElB,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAwEF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,CAcvD,CAAC"}
1
+ {"version":3,"file":"imageFunctionGeogebra.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/basics/imageFunctionGeogebra.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAgBT,MAAM,6BAA6B,CAAC;AAsBrC,KAAK,WAAW,GAAG;IACjB,cAAc;IAMd,UAAU;IAMV,UAAU;IACV,YAAY,EAAE,MAAM,CAAC;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;CACzB,CAAC;AAwOF,KAAK,OAAO,GAAG;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAkBhE,CAAC"}