math-exercises 3.0.3 → 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 (30) 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 +14 -9
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/math/geometry/parabola.d.ts +11 -0
  25. package/lib/math/geometry/parabola.d.ts.map +1 -0
  26. package/lib/math/geometry/parabola.js +32 -0
  27. package/lib/math/polynomials/generalPolynomial.d.ts +19 -0
  28. package/lib/math/polynomials/generalPolynomial.d.ts.map +1 -0
  29. package/lib/math/polynomials/generalPolynomial.js +44 -0
  30. 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"}
@@ -1,84 +1,225 @@
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
3
  import { numberVEA } from "../../../../exercises/vea/numberVEA.js";
4
+ import { randomColor } from "../../../../geogebra/colors.js";
4
5
  import { GeogebraConstructor } from "../../../../geogebra/geogebraConstructor.js";
5
6
  import { Lagrange } from "../../../../geogebra/lagrange.js";
6
7
  import { Spline } from "../../../../geogebra/spline.js";
8
+ import { Line } from "../../../../math/geometry/line.js";
9
+ import { Parabola } from "../../../../math/geometry/parabola.js";
7
10
  import { Point } from "../../../../math/geometry/point.js";
11
+ import { Polynomial } from "../../../../math/polynomials/polynomial.js";
8
12
  import { randint } from "../../../../math/utils/random/randint.js";
9
- import { round } from "../../../../math/utils/round.js";
10
13
  import { ClosureType } from "../../../../tree/nodes/sets/closure.js";
11
14
  import { IntervalNode } from "../../../../tree/nodes/sets/intervalNode.js";
12
- import { coinFlip } from "../../../../utils/alea/coinFlip.js";
15
+ import { random } from "../../../../utils/alea/random.js";
13
16
  import { shuffle } from "../../../../utils/alea/shuffle.js";
14
- const getImageFunctionGeogebra = () => {
17
+ const rebuildIdentifiers = (oldIds) => {
18
+ if (oldIds.splinePoints?.length) {
19
+ const x = oldIds.x;
20
+ const wrongY = oldIds.splinePoints.find((p) => p[1] === x && Math.floor(p[0]) === p[0]);
21
+ if (!wrongY && wrongY !== 0)
22
+ throw new Error("no wrong y");
23
+ const otherPoints = oldIds.splinePoints.filter((p) => p[0] !== x && p[0] !== wrongY);
24
+ return {
25
+ functionType: oldIds.isSpline ? "Tracés" : "Polynômes",
26
+ x: oldIds.x,
27
+ y: oldIds.y,
28
+ wrongY,
29
+ otherPoints,
30
+ };
31
+ }
32
+ else if (oldIds.poly1?.length || oldIds.poly2?.length) {
33
+ const x = oldIds.xValue;
34
+ const polynome = new Polynomial(oldIds.rand ? oldIds.poly1 : oldIds.poly2);
35
+ const y = polynome.calculate(x);
36
+ const wrongY = oldIds.rand
37
+ ? Math.floor((x - oldIds.poly1[0]) / oldIds.poly1[1])
38
+ : polynome.calculate(x + 2);
39
+ return {
40
+ functionType: oldIds.rand ? "Droites" : "Paraboles",
41
+ x: oldIds.x,
42
+ y: oldIds.y,
43
+ wrongY,
44
+ otherPoints: oldIds.rand ? [] : [[x + 1, polynome.calculate(x + 1)]],
45
+ };
46
+ }
47
+ else
48
+ return oldIds;
49
+ };
50
+ const getInstruction = (identifiers) => {
51
+ const { x } = identifiers;
52
+ return `Quelle est l'image de $${x}$ par la fonction $f$ représentée ci dessous ?`;
53
+ };
54
+ const getAnswer = (identifiers) => {
55
+ const { y } = identifiers;
56
+ return y.frenchify();
57
+ };
58
+ const getGGBOptions = (identifiers) => {
59
+ const { functionType, otherPoints, wrongY, x, y } = identifiers;
60
+ const allPoints = [...otherPoints, [x, y], [wrongY, x]].sort((a, b) => a[0] - b[0]);
61
+ console.log(allPoints);
62
+ let commands = [];
63
+ switch (functionType) {
64
+ case "Droites":
65
+ const line = new Line(new Point("A", allPoints[0][0], allPoints[0][1]), new Point("B", allPoints[1][0], allPoints[1][1]));
66
+ commands = line.toGGBCommands(false);
67
+ break;
68
+ case "Tracés":
69
+ //! on devrait plutôt build a spline et renvoyer toGgbCommand
70
+ commands = [
71
+ `S = Spline(${allPoints
72
+ .map((point) => `(${point[0]},${point[1]})`)
73
+ .join(",")})`,
74
+ "SetFixed(S, true)",
75
+ `SetColor(S, "${randomColor()}")`,
76
+ ];
77
+ break;
78
+ case "Paraboles":
79
+ const parabola = new Parabola([
80
+ new Point("A", allPoints[0][0], allPoints[0][1]),
81
+ new Point("B", allPoints[1][0], allPoints[1][1]),
82
+ new Point("C", allPoints[2][0], allPoints[2][1]),
83
+ ]);
84
+ commands = parabola.toGGBCommands(false);
85
+ break;
86
+ case "Polynômes":
87
+ default:
88
+ //! on devrait plutôt build a lagrange et renvoyer toGgbCommand
89
+ commands = [
90
+ `P = Polynomial(${allPoints
91
+ .map((point) => `(${point[0]},${point[1]})`)
92
+ .join(",")})`,
93
+ "SetFixed(P, true)",
94
+ `SetColor(P, "${randomColor()}")`,
95
+ ];
96
+ break;
97
+ }
98
+ // const spline = new (isSpline ? Spline : Lagrange)(
99
+ // new IntervalNode((-10).toTree(), (10).toTree(), ClosureType.FF),
100
+ // splinePoints.map((e, i) => new Point(`A_${i}`, e[0], e[1])),
101
+ // );
102
+ const ggb = new GeogebraConstructor({
103
+ // commands: spline.getCommands()
104
+ commands,
105
+ });
106
+ const xMin = allPoints[0][0];
107
+ const xMax = allPoints[allPoints.length - 1][0];
108
+ const yMin = Math.min(...allPoints.map((p) => p[1])) - 1;
109
+ const yMax = Math.max(...allPoints.map((p) => p[1])) + 1;
110
+ return ggb.getOptions({
111
+ coords: ggb.getAdaptedCoords({
112
+ forceShowAxes: true,
113
+ xMax,
114
+ xMin,
115
+ yMax,
116
+ yMin,
117
+ }),
118
+ });
119
+ };
120
+ const getStartStatement = (identifiers) => {
121
+ const { x } = identifiers;
122
+ return `f(${x})`;
123
+ };
124
+ const getImageFunctionGeogebra = (opts) => {
15
125
  const x = randint(-8, 9);
16
126
  const y = randint(-8, 9);
17
- const isSpline = coinFlip();
18
- const spline = new (isSpline ? Spline : Lagrange)(new IntervalNode((-10).toTree(), (10).toTree(), ClosureType.FF), [
19
- new Point("A", x.toTree(), y.toTree()),
20
- //distractor point with ordonnée = x
21
- new Point("B", (y + randint(-3, 4, [0, x - y, 10 - y, -10 - y])).toTree(), x.toTree()),
22
- ]);
23
- const ggb = new GeogebraConstructor({ commands: spline.getCommands() });
24
- const xMin = spline.points[0][0];
25
- const xMax = spline.points[spline.points.length - 1][0];
26
- const yMin = Math.min(...spline.points.map((p) => p[1])) - 1;
27
- const yMax = Math.max(...spline.points.map((p) => p[1])) + 1;
28
- const instruction = `Quelle est l'image de $${x}$ par la fonction $f$ représentée ci dessous ?`;
127
+ const wrongY = y + randint(-3, 4, [0, x - y, 10 - y, -10 - y]);
128
+ const functionType = random(opts?.curveTypes ?? ["Tracés", "Polynômes", "Droites", "Paraboles"]);
129
+ let otherPoints = [];
130
+ switch (functionType) {
131
+ case "Droites":
132
+ //nothing to add
133
+ break;
134
+ case "Tracés":
135
+ const spline = new Spline(new IntervalNode((-10).toTree(), (10).toTree(), ClosureType.FF), [
136
+ new Point("A", x.toTree(), y.toTree()),
137
+ //distractor point with ordonnée = x
138
+ new Point("B", wrongY.toTree(), x.toTree()),
139
+ ]);
140
+ otherPoints = spline.points.filter((p) => p[0] !== x && p[0] !== wrongY);
141
+ break;
142
+ case "Paraboles":
143
+ //3e point au milieu de AB
144
+ otherPoints.push([(x + wrongY) / 2, y + randint(-3, 4, [0])]);
145
+ break;
146
+ case "Polynômes":
147
+ const lagrange = new Lagrange(new IntervalNode((-10).toTree(), (10).toTree(), ClosureType.FF), [
148
+ new Point("A", x.toTree(), y.toTree()),
149
+ //distractor point with ordonnée = x
150
+ new Point("B", wrongY.toTree(), x.toTree()),
151
+ ]);
152
+ otherPoints = lagrange.points.filter((p) => p[0] !== x && p[0] !== wrongY);
153
+ default:
154
+ break;
155
+ }
156
+ // const spline = new (isSpline ? Spline : Lagrange)(
157
+ // new IntervalNode((-10).toTree(), (10).toTree(), ClosureType.FF),
158
+ // [
159
+ // new Point("A", x.toTree(), y.toTree()),
160
+ // //distractor point with ordonnée = x
161
+ // new Point("B", wrongY.toTree(), x.toTree()),
162
+ // ],
163
+ // );
164
+ const identifiers = {
165
+ // isSpline,
166
+ // splinePoints: spline.points,
167
+ x,
168
+ y,
169
+ functionType,
170
+ wrongY,
171
+ otherPoints,
172
+ };
29
173
  const question = {
30
- instruction,
31
- startStatement: `f(${x})`,
32
- answer: y.frenchify(),
174
+ instruction: getInstruction(identifiers),
175
+ startStatement: getStartStatement(identifiers),
176
+ answer: getAnswer(identifiers),
33
177
  keys: [],
34
- ggbOptions: ggb.getOptions({
35
- coords: ggb.getAdaptedCoords({
36
- forceShowAxes: true,
37
- xMax,
38
- xMin,
39
- yMax,
40
- yMin,
41
- }),
42
- }),
178
+ ggbOptions: getGGBOptions(identifiers),
43
179
  answerFormat: "tex",
44
- identifiers: {
45
- splinePoints: spline.points,
46
- x,
47
- y,
48
- isSpline,
49
- },
180
+ identifiers,
50
181
  };
51
182
  return question;
52
183
  };
53
- const getPropositions = (n, { answer, splinePoints, x, y }) => {
184
+ const getPropositions = (n, { answer, x, y, wrongY }, opts) => {
54
185
  const propositions = [];
55
186
  addValidProp(propositions, answer);
56
187
  //old questions have spline POint undefined
57
- (splinePoints ?? [])
58
- .filter((p) => p[1] === x)
59
- .map((e) => round(e[0], 0))
60
- .forEach((y) => tryToAddWrongProp(propositions, y.frenchify()));
188
+ tryToAddWrongProp(propositions, wrongY + "");
61
189
  while (propositions.length < n) {
62
190
  const wrongAnswer = Number(answer) + randint(-10, 11, [0]);
63
191
  tryToAddWrongProp(propositions, wrongAnswer + "");
64
192
  }
65
193
  return shuffle(propositions);
66
194
  };
67
- const isAnswerValid = (ans, { answer }) => {
195
+ const isAnswerValid = (ans, { answer }, opts) => {
68
196
  return numberVEA(ans, answer);
69
197
  };
198
+ const options = [
199
+ {
200
+ id: "curveTypes",
201
+ label: "Types de courbes",
202
+ target: GeneratorOptionTarget.generation,
203
+ type: GeneratorOptionType.multiselect,
204
+ defaultValue: ["Tracés", "Polynômes", "Droites", "Paraboles"],
205
+ values: ["Tracés", "Polynômes", "Droites", "Paraboles"],
206
+ },
207
+ ];
70
208
  export const imageFunctionGeogebra = {
71
209
  id: "imageFunctionGeogebra",
72
210
  connector: "=",
73
211
  label: "Lecture d'une image",
74
- levels: ["3ème", "2nde", "CAP", "2ndPro", "1rePro", "1reTech"],
75
- sections: ["Fonctions"],
76
212
  isSingleStep: true,
77
- generator: (nb) => getDistinctQuestions(getImageFunctionGeogebra, nb),
213
+ generator: (nb, opts) => getDistinctQuestions(() => getImageFunctionGeogebra(opts), nb),
78
214
  qcmTimer: 60,
79
215
  freeTimer: 60,
80
216
  getPropositions,
81
217
  isAnswerValid,
82
218
  hasGeogebra: true,
83
219
  subject: "Mathématiques",
220
+ options,
221
+ getAnswer,
222
+ getInstruction,
223
+ getGGBOptions,
224
+ rebuildIdentifiers,
84
225
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cubicEquation.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/cube/cubicEquation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAQT,MAAM,6BAA6B,CAAC;AASrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAyCF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,WAAW,CAe/C,CAAC"}
1
+ {"version":3,"file":"cubicEquation.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/cube/cubicEquation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA4DF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,WAAW,CAkB/C,CAAC"}
@@ -1,21 +1,41 @@
1
1
  import { addValidProp, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
3
  import { equationKeys } from "../../../../exercises/utils/keys/equationKeys.js";
4
+ import { equationVEA } from "../../../../exercises/vea/equationVEA.js";
4
5
  import { randint } from "../../../../math/utils/random/randint.js";
5
- import { EquationSolutionNode } from "../../../../tree/nodes/equations/equationSolutionNode.js";
6
- import { NumberNode } from "../../../../tree/nodes/numbers/numberNode.js";
7
- import { DiscreteSetNode } from "../../../../tree/nodes/sets/discreteSetNode.js";
8
6
  import { shuffle } from "../../../../utils/alea/shuffle.js";
7
+ const getInstruction = (identifiers) => {
8
+ const k = identifiers.k;
9
+ return `Résoudre l'équation suivante :
10
+
11
+ $$
12
+ x^3 = ${k}
13
+ $$`;
14
+ };
15
+ const getAnswer = (identifiers) => {
16
+ const k = identifiers.k;
17
+ const x = Math.cbrt(k);
18
+ const answer = `S=\\left\\{${x}\\right\\}`;
19
+ return answer;
20
+ };
21
+ // const getHint: GetHint<Identifiers> = (identifiers) => {
22
+ // return "";
23
+ // };
24
+ // const getCorrection: GetCorrection<Identifiers> = (identifiers) => {
25
+ // return "";
26
+ // };
9
27
  const getCubicEquationQuestion = () => {
10
28
  const x = randint(-10, 11);
11
29
  const k = x ** 3;
12
- const answer = `S=\\left\\{${x}\\right\\}`;
30
+ const identifiers = { k };
13
31
  const question = {
14
- answer: answer,
15
- instruction: `Résoudre l'équation suivante : $x^3 = ${k}$`,
32
+ answer: getAnswer(identifiers),
33
+ instruction: getInstruction(identifiers),
16
34
  keys: equationKeys,
17
35
  answerFormat: "tex",
18
- identifiers: { k },
36
+ identifiers,
37
+ // hint: getHint(identifiers),
38
+ // correction: getCorrection(identifiers),
19
39
  };
20
40
  return question;
21
41
  };
@@ -30,18 +50,13 @@ const getPropositions = (n, { answer, k }) => {
30
50
  return shuffle(propositions);
31
51
  };
32
52
  const isAnswerValid = (ans, { k }) => {
33
- const sol = Math.cbrt(k);
34
- const answerTree = new EquationSolutionNode(new DiscreteSetNode([new NumberNode(sol)]));
35
- const texs = answerTree.toAllValidTexs();
36
- return texs.includes(ans);
53
+ return equationVEA(ans, Math.cbrt(k).frenchify());
37
54
  };
38
55
  export const cubicEquation = {
39
56
  id: "cubicEquation",
40
57
  connector: "\\iff",
41
58
  label: "Résoudre une équation du type $x^3 = k$",
42
- levels: ["2nde", "1reESM", "1reSpé", "1reTech"],
43
59
  isSingleStep: true,
44
- sections: ["Fonctions de référence", "Fonction cube", "Équations"],
45
60
  generator: (nb) => getDistinctQuestions(getCubicEquationQuestion, nb, 20),
46
61
  isAnswerValid,
47
62
  qcmTimer: 60,
@@ -49,4 +64,9 @@ export const cubicEquation = {
49
64
  maxAllowedQuestions: 20,
50
65
  getPropositions,
51
66
  subject: "Mathématiques",
67
+ getInstruction,
68
+ getAnswer,
69
+ // getCorrection,
70
+ // getHint,
71
+ // hasHintAndCorrection: true,
52
72
  };
@@ -37,7 +37,7 @@ const getInstruction = (identifiers) => {
37
37
  };
38
38
  const getHint = (identifiers) => {
39
39
  const { type, k, nbEssais, caracType } = identifiers;
40
- return `La fréquence est le nombre de fois qu'on a obtenu ${caracType} divisée par le nombre total d'essais.`;
40
+ return `La fréquence est le nombre de fois qu'on a obtenu ${caracType} divisé par le nombre total d'essais.`;
41
41
  };
42
42
  const getCorrection = (identifiers) => {
43
43
  const { type, k, nbEssais, caracType } = identifiers;
@@ -1 +1 @@
1
- {"version":3,"file":"arithmeticFindExplicitFormula.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sequences/arithmetic/arithmeticFindExplicitFormula.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AASrC,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAiIF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,CAoB/D,CAAC"}
1
+ {"version":3,"file":"arithmeticFindExplicitFormula.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sequences/arithmetic/arithmeticFindExplicitFormula.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAWrC,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA8IF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,CAoB/D,CAAC"}
@@ -2,9 +2,9 @@ import { GeneratorOptionTarget, GeneratorOptionType, addValidProp, tryToAddWrong
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
3
  import { Polynomial } from "../../../../math/polynomials/polynomial.js";
4
4
  import { randint } from "../../../../math/utils/random/randint.js";
5
- import { EqualNode } from "../../../../tree/nodes/equations/equalNode.js";
6
- import { VariableNode } from "../../../../tree/nodes/variables/variableNode.js";
5
+ import { parseAlgebraic } from "../../../../tree/parsers/latexParser.js";
7
6
  import { shuffle } from "../../../../utils/alea/shuffle.js";
7
+ import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
8
8
  const getInstruction = (identifiers, opts) => {
9
9
  const firstRank = opts?.firstTermRankOne ? 1 : 0;
10
10
  return `$(u_n)$ est une suite arithmétique de premier terme $u_{${firstRank}} = ${identifiers.firstValue}$ et de raison $r = ${identifiers.reason}$.
@@ -74,15 +74,28 @@ const getPropositions = (n, { answer, firstValue, reason }) => {
74
74
  }
75
75
  return shuffle(propositions);
76
76
  };
77
- const isAnswerValid = (ans, { reason, firstValue }, opts) => {
78
- const formula = opts?.firstTermRankOne
79
- ? new Polynomial([firstValue - reason, reason], "n")
80
- : new Polynomial([firstValue, reason], "n");
81
- const equal = new EqualNode(new VariableNode("u_n"), formula.toTree(), {
82
- allowRawRightChildAsSolution: true,
83
- });
84
- const texs = equal.toAllValidTexs();
85
- return texs.includes(ans);
77
+ const isAnswerValid = (ans, { answer, reason, firstValue }, opts) => {
78
+ try {
79
+ const formated = ans.replaceAll("u_n", "").replaceAll("=", "");
80
+ const parsed = parseAlgebraic(formated);
81
+ if (!parsed)
82
+ return false;
83
+ console.log(parsed
84
+ .simplify({
85
+ towardsDistribute: true,
86
+ forbidFactorize: true,
87
+ })
88
+ .toTex());
89
+ return (parsed
90
+ .simplify({
91
+ towardsDistribute: true,
92
+ forbidFactorize: true,
93
+ })
94
+ .toTex() === answer.split("=")[1]);
95
+ }
96
+ catch (err) {
97
+ return handleVEAError(err);
98
+ }
86
99
  };
87
100
  const options = [
88
101
  {
@@ -1 +1 @@
1
- {"version":3,"file":"associatePoint.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/trigonometry/associatePoint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAItE,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,eAAe,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAyDF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAchD,CAAC"}
1
+ {"version":3,"file":"associatePoint.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/trigonometry/associatePoint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAItE,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,eAAe,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AA0DF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAchD,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import { Point } from "../math/geometry/point.js";
2
2
  import { IntervalNode } from "../tree/nodes/sets/intervalNode.js";
3
+ export declare abstract class LagrangeConstructor {
4
+ }
3
5
  export declare class Lagrange {
4
6
  points: number[][];
5
7
  constructor(interval: IntervalNode, points?: Point[]);
@@ -1 +1 @@
1
- {"version":3,"file":"lagrange.d.ts","sourceRoot":"","sources":["../../src/geogebra/lagrange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIrD,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAerE,qBAAa,QAAQ;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;gBAEP,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE;IAuDpD,WAAW;CAUZ"}
1
+ {"version":3,"file":"lagrange.d.ts","sourceRoot":"","sources":["../../src/geogebra/lagrange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIrD,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAKrE,8BAAsB,mBAAmB;CASxC;AACD,qBAAa,QAAQ;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;gBAEP,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE;IAuDpD,WAAW;CAUZ"}
@@ -1,16 +1,8 @@
1
1
  import { randfloat } from "../math/utils/random/randfloat.js";
2
2
  import { randint } from "../math/utils/random/randint.js";
3
3
  import { randomColor } from "./colors.js";
4
- // export abstract class LagrangeConstructor {
5
- // random() {
6
- // const a = randint(-10, 0);
7
- // const b = doWhile(
8
- // () => randint(0, 10),
9
- // (x) => Math.abs(x - a) < 5,
10
- // );
11
- // return new Spline(new IntervalNode(a.toTree(), b.toTree(), ClosureType.FF));
12
- // }
13
- // }
4
+ export class LagrangeConstructor {
5
+ }
14
6
  export class Lagrange {
15
7
  points;
16
8
  constructor(interval, points) {
package/lib/index.d.ts CHANGED
@@ -674,17 +674,22 @@ declare const mathExercises: (Exercise<{
674
674
  y: number;
675
675
  isOnLine: boolean;
676
676
  }, {}> | Exercise<{
677
- rand: boolean;
678
- poly1: number[];
679
- poly2: number[];
680
- xValue: number;
681
- flip: boolean;
682
- }, {}> | Exercise<{
683
- isSpline: boolean;
684
- splinePoints: number[][];
677
+ xValue: import("./tree/nodes/nodeConstructor.js").NodeIdentifiers;
678
+ polynomeCoeffs: import("./tree/nodes/nodeConstructor.js").NodeIdentifiers[];
679
+ imageSyntaxText: boolean;
680
+ }, {
681
+ functionType: string[];
682
+ coeffsType: string[];
683
+ xType: string[];
684
+ }> | Exercise<{
685
+ functionType: string;
685
686
  x: number;
686
687
  y: number;
687
- }, {}> | Exercise<{
688
+ wrongY: number;
689
+ otherPoints: number[][];
690
+ }, {
691
+ curveTypes: string[];
692
+ }> | Exercise<{
688
693
  poly1: number[];
689
694
  xValue: number;
690
695
  }, {}> | Exercise<{
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,QAAA,MAAM,aAAa;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA+B,CAAC;AACnD,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA6B,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { ToGGBCommandsProps } from "../../exercises/utils/geogebra/toGGBCommandsProps.js";
2
+ import { Point } from "./point.js";
3
+ export declare class Parabola {
4
+ points: Point[];
5
+ name: string;
6
+ unformatedName: string;
7
+ ggbName: string;
8
+ constructor(points: Point[], name?: string);
9
+ toGGBCommands(shouldBuildPoints: boolean, { isFixed, showLabel, showUnderlyingPointsLabel, showUnderlyingPoints, }?: ToGGBCommandsProps): string[];
10
+ }
11
+ //# sourceMappingURL=parabola.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parabola.d.ts","sourceRoot":"","sources":["../../../src/math/geometry/parabola.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sDAAsD,CAAC;AAC1F,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,qBAAa,QAAQ;IACnB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;gBACJ,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM;IAS1C,aAAa,CACX,iBAAiB,EAAE,OAAO,EAC1B,EACE,OAAc,EACd,SAAiB,EACjB,yBAAgC,EAChC,oBAA2B,GAC5B,GAAE,kBAAuB;CA+B7B"}
@@ -0,0 +1,32 @@
1
+ export class Parabola {
2
+ points;
3
+ name;
4
+ unformatedName;
5
+ ggbName;
6
+ constructor(points, name) {
7
+ if (points.length !== 3)
8
+ throw new Error(`Parabola needs 3 points but received ${points.length}`);
9
+ this.points = points;
10
+ this.unformatedName = name ?? `${points.map((p) => p.name)}`;
11
+ this.name = name ?? `\\mathcal{P}_${points.map((p) => p.name)}`;
12
+ this.ggbName = name ?? `parabola_{${points.map((p) => p.name)}}`;
13
+ }
14
+ toGGBCommands(shouldBuildPoints, { isFixed = true, showLabel = false, showUnderlyingPointsLabel = true, showUnderlyingPoints = true, } = {}) {
15
+ const commands = [];
16
+ if (shouldBuildPoints) {
17
+ const pointsCommands = this.points.map((p) => p.toGGBCommand({
18
+ isFixed,
19
+ showLabel: showUnderlyingPointsLabel,
20
+ }));
21
+ commands.push(...pointsCommands.flat(), `${this.ggbName}=Polynomial(${this.points[0].name},${this.points[1].name},${this.points[2].name})`);
22
+ }
23
+ else {
24
+ commands.push(`${this.ggbName}=Polynomial(${this.points[0].toMathString()},${this.points[1].toMathString()},${this.points[2].toMathString()})`);
25
+ }
26
+ commands.push(...[
27
+ `SetFixed(${this.ggbName},${isFixed ? "true" : "false"})`,
28
+ `ShowLabel(${this.ggbName},${showLabel ? "true" : "false"})`,
29
+ ]);
30
+ return commands;
31
+ }
32
+ }
@@ -0,0 +1,19 @@
1
+ import { AlgebraicNode } from "../../tree/nodes/algebraicNode.js";
2
+ import { NodeIdentifiers } from "../../tree/nodes/nodeConstructor.js";
3
+ import { AddNode } from "../../tree/nodes/operators/addNode.js";
4
+ export declare abstract class GeneralPolynomialConstructor {
5
+ static fromIdentifiers(identifiers: GeneralPolynomialIdentifiers): GeneralPolynomial;
6
+ }
7
+ export type GeneralPolynomialIdentifiers = {
8
+ id: "polynomial";
9
+ coeffs: NodeIdentifiers[];
10
+ variable?: string;
11
+ };
12
+ export declare class GeneralPolynomial {
13
+ coeffs: AlgebraicNode[];
14
+ variable: string;
15
+ constructor(coeffs: (number | AlgebraicNode)[], variable?: string);
16
+ toIdentifiers(): GeneralPolynomialIdentifiers;
17
+ toTree(): AddNode;
18
+ }
19
+ //# sourceMappingURL=generalPolynomial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generalPolynomial.d.ts","sourceRoot":"","sources":["../../../src/math/polynomials/generalPolynomial.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAGlE,OAAO,EAEL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAK7C,OAAO,EAAO,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAYrE,8BAAsB,4BAA4B;IAChD,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,4BAA4B;CAMjE;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,EAAE,EAAE,YAAY,CAAC;IACjB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,qBAAa,iBAAiB;IAC5B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;gBAEL,MAAM,EAAE,CAAC,MAAM,GAAG,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAE,MAAY;IAUtE,aAAa,IAAI,4BAA4B;IAO7C,MAAM;CAWP"}
@@ -0,0 +1,44 @@
1
+ import { reifyAlgebraic, } from "../../tree/nodes/nodeConstructor.js";
2
+ import { AddNode } from "../../tree/nodes/operators/addNode.js";
3
+ import { multiply } from "../../tree/nodes/operators/multiplyNode.js";
4
+ import { power } from "../../tree/nodes/operators/powerNode.js";
5
+ import { operatorComposition } from "../../tree/utilities/operatorComposition.js";
6
+ export class GeneralPolynomialConstructor {
7
+ static fromIdentifiers(identifiers) {
8
+ return new GeneralPolynomial(identifiers.coeffs.map((c) => reifyAlgebraic(c)), identifiers.variable);
9
+ }
10
+ }
11
+ export class GeneralPolynomial {
12
+ coeffs;
13
+ variable;
14
+ constructor(coeffs, variable = "x") {
15
+ const nodedCoeffs = coeffs.map((c) => {
16
+ if (typeof c === "number")
17
+ return c.toTree();
18
+ return c;
19
+ });
20
+ this.coeffs = nodedCoeffs;
21
+ if (nodedCoeffs[coeffs.length - 1].evaluate() === 0)
22
+ throw new Error("n-th coeff is null");
23
+ this.variable = variable;
24
+ }
25
+ toIdentifiers() {
26
+ return {
27
+ id: "polynomial",
28
+ coeffs: this.coeffs.map((c) => c.toIdentifiers()),
29
+ variable: this.variable !== "x" ? this.variable : undefined,
30
+ };
31
+ }
32
+ toTree() {
33
+ const monoms = this.coeffs
34
+ .map((c, i) => {
35
+ if (i === 0)
36
+ return c;
37
+ if (i === 1)
38
+ return multiply(c, this.variable);
39
+ return multiply(c, power(this.variable, i));
40
+ })
41
+ .filter((n, i) => this.coeffs[i].evaluate() !== 0);
42
+ return operatorComposition(AddNode, monoms.reverse());
43
+ }
44
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.3",
4
+ "version": "3.0.4",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [