math-exercises 2.2.95 → 2.2.97

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 (62) hide show
  1. package/lib/exercises/math/calcul/index.js +1 -0
  2. package/lib/exercises/math/calculLitteral/distributivity/doubleDistributivity.d.ts.map +1 -1
  3. package/lib/exercises/math/calculLitteral/distributivity/doubleDistributivity.js +85 -32
  4. package/lib/exercises/math/calculLitteral/distributivity/firstIdentity.d.ts.map +1 -1
  5. package/lib/exercises/math/calculLitteral/distributivity/firstIdentity.js +82 -34
  6. package/lib/exercises/math/calculLitteral/distributivity/secondIdentity.d.ts.map +1 -1
  7. package/lib/exercises/math/calculLitteral/distributivity/secondIdentity.js +86 -36
  8. package/lib/exercises/math/calculLitteral/distributivity/simpleDistributivity.d.ts.map +1 -1
  9. package/lib/exercises/math/calculLitteral/distributivity/simpleDistributivity.js +17 -6
  10. package/lib/exercises/math/calculLitteral/distributivity/thirdIdentity.d.ts.map +1 -1
  11. package/lib/exercises/math/calculLitteral/distributivity/thirdIdentity.js +82 -32
  12. package/lib/exercises/math/calculLitteral/factorisation/factoType1Exercise.d.ts.map +1 -1
  13. package/lib/exercises/math/calculLitteral/factorisation/factoType1Exercise.js +1 -0
  14. package/lib/exercises/math/calculLitteral/simplifying/distributeAndSimplify.d.ts.map +1 -1
  15. package/lib/exercises/math/calculLitteral/simplifying/distributeAndSimplify.js +38 -16
  16. package/lib/exercises/math/calculLitteral/simplifying/reduceExpression.d.ts +3 -3
  17. package/lib/exercises/math/calculLitteral/simplifying/reduceExpression.d.ts.map +1 -1
  18. package/lib/exercises/math/calculLitteral/simplifying/reduceExpression.js +171 -75
  19. package/lib/exercises/math/dataReading/index.d.ts +2 -0
  20. package/lib/exercises/math/dataReading/index.d.ts.map +1 -0
  21. package/lib/exercises/math/dataReading/index.js +17 -0
  22. package/lib/exercises/math/dataReading/tableReading.d.ts +8 -0
  23. package/lib/exercises/math/dataReading/tableReading.d.ts.map +1 -0
  24. package/lib/exercises/math/dataReading/tableReading.js +105 -0
  25. package/lib/exercises/math/derivation/derivative/powerCompositionDerivation.d.ts.map +1 -1
  26. package/lib/exercises/math/derivation/derivative/powerCompositionDerivation.js +75 -11
  27. package/lib/exercises/math/functions/affines/affineExpressionFromTwoImages.d.ts.map +1 -1
  28. package/lib/exercises/math/functions/affines/affineExpressionFromTwoImages.js +0 -1
  29. package/lib/exercises/math/functions/affines/affineExpressionReading.d.ts.map +1 -1
  30. package/lib/exercises/math/index.d.ts +1 -0
  31. package/lib/exercises/math/index.d.ts.map +1 -1
  32. package/lib/exercises/math/index.js +1 -0
  33. package/lib/exercises/math/probaStat/diceBasicProbas.d.ts.map +1 -1
  34. package/lib/exercises/math/probaStat/diceBasicProbas.js +72 -20
  35. package/lib/exercises/vea/rationalVEA.js +1 -1
  36. package/lib/index.d.ts +6 -3
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/tree/nodes/algebraicNode.d.ts +1 -0
  39. package/lib/tree/nodes/algebraicNode.d.ts.map +1 -1
  40. package/lib/tree/nodes/operators/addNode.d.ts +2 -1
  41. package/lib/tree/nodes/operators/addNode.d.ts.map +1 -1
  42. package/lib/tree/nodes/operators/addNode.js +21 -3
  43. package/lib/tree/nodes/operators/fractionNode.d.ts.map +1 -1
  44. package/lib/tree/nodes/operators/multiplyNode.d.ts +2 -1
  45. package/lib/tree/nodes/operators/multiplyNode.d.ts.map +1 -1
  46. package/lib/tree/nodes/operators/multiplyNode.js +12 -0
  47. package/lib/tree/nodes/operators/operatorNode.d.ts +5 -0
  48. package/lib/tree/nodes/operators/operatorNode.d.ts.map +1 -1
  49. package/lib/tree/nodes/operators/operatorNode.js +5 -1
  50. package/lib/tree/nodes/polynomials/monomNode.d.ts +2 -6
  51. package/lib/tree/nodes/polynomials/monomNode.d.ts.map +1 -1
  52. package/lib/tree/nodes/polynomials/monomNode.js +102 -94
  53. package/lib/tree/parsers/affineParser.d.ts +1 -1
  54. package/lib/tree/parsers/affineParser.d.ts.map +1 -1
  55. package/lib/tree/parsers/affineParser.js +16 -21
  56. package/lib/tree/parsers/polynomialParser.d.ts +5 -1
  57. package/lib/tree/parsers/polynomialParser.d.ts.map +1 -1
  58. package/lib/tree/parsers/polynomialParser.js +4 -3
  59. package/lib/tree/parsers/purifyLatex.d.ts +1 -1
  60. package/lib/tree/parsers/purifyLatex.js +1 -1
  61. package/lib/utils/alea/shuffle.js +1 -1
  62. package/package.json +1 -1
@@ -9,32 +9,54 @@ const powerNode_1 = require("../../../../tree/nodes/operators/powerNode");
9
9
  const substractNode_1 = require("../../../../tree/nodes/operators/substractNode");
10
10
  const alignTex_1 = require("../../../../utils/latex/alignTex");
11
11
  const shuffle_1 = require("../../../../utils/alea/shuffle");
12
- const getThirdIdentityQuestion = () => {
13
- const affine = affine_1.AffineConstructor.random(undefined, { excludes: [0] });
14
- const affine2 = new affine_1.Affine(affine.a, -affine.b);
12
+ const latexParser_1 = require("../../../../tree/parsers/latexParser");
13
+ const addNode_1 = require("../../../../tree/nodes/operators/addNode");
14
+ const handleVEAError_1 = require("../../../../utils/errors/handleVEAError");
15
+ const getStatementNode = (identifiers) => {
16
+ const { affine1Coeffs, affine2Coeffs } = identifiers;
17
+ const affine = new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]);
18
+ const affine2 = new affine_1.Affine(affine2Coeffs[1], affine2Coeffs[0]);
15
19
  const statementTree = new multiplyNode_1.MultiplyNode(affine.toTree(), affine2.toTree());
20
+ return statementTree;
21
+ };
22
+ const getStartStatement = (identifiers) => {
23
+ return getStatementNode(identifiers).toTex();
24
+ };
25
+ const getInstruction = (identifiers) => {
26
+ return `Développer et réduire :
27
+
28
+ $$
29
+ ${getStartStatement(identifiers)}
30
+ $$`;
31
+ };
32
+ const getAnswer = (identifiers) => {
33
+ const { affine1Coeffs, affine2Coeffs } = identifiers;
34
+ const affine = new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]);
35
+ const affine2 = new affine_1.Affine(affine2Coeffs[1], affine2Coeffs[0]);
16
36
  const answer = affine.multiply(affine2).toTree().toTex();
37
+ return answer;
38
+ };
39
+ const getHint = (identifiers) => {
40
+ const { affine1Coeffs, affine2Coeffs } = identifiers;
41
+ const affine = new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]);
17
42
  const aMonom = new multiplyNode_1.MultiplyNode(affine.a.toTree(), "x".toTree());
18
43
  const bPositive = Math.abs(affine.b);
19
- const statementTex = statementTree.toTex();
20
- const question = {
21
- instruction: `Développer et réduire : $${statementTex}$`,
22
- startStatement: statementTex,
23
- answer,
24
- keys: ["x"],
25
- answerFormat: "tex",
26
- identifiers: {
27
- affine1Coeffs: affine.coefficients,
28
- affine2Coeffs: affine2.coefficients,
29
- },
30
- hint: `Utilise l'identité remarquable
44
+ return `Utilise l'identité remarquable
31
45
 
32
46
  $$
33
47
  (a-b)(a+b) = a^2 - b^2
34
48
  $$
35
49
 
36
- en prenant $a=${aMonom.toTex()}$ et $b=${bPositive}$`,
37
- correction: `
50
+ en prenant $a=${aMonom.toTex()}$ et $b=${bPositive}$`;
51
+ };
52
+ const getCorrection = (identifiers) => {
53
+ const { affine1Coeffs, affine2Coeffs } = identifiers;
54
+ const affine = new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]);
55
+ const aMonom = new multiplyNode_1.MultiplyNode(affine.a.toTree(), "x".toTree());
56
+ const bPositive = Math.abs(affine.b);
57
+ const statementTex = getStartStatement(identifiers);
58
+ const answer = getAnswer(identifiers);
59
+ return `
38
60
  On utilise l'identité remarquable
39
61
 
40
62
  $$
@@ -44,13 +66,30 @@ $$
44
66
  en prenant $a=${aMonom.toTex()}$ et $b=${bPositive}$.
45
67
 
46
68
  ${(0, alignTex_1.alignTex)([
47
- [
48
- statementTex,
49
- "=",
50
- new substractNode_1.SubstractNode(new powerNode_1.SquareNode(aMonom), new powerNode_1.SquareNode(bPositive.toTree())).toTex(),
51
- ],
52
- ["", "=", answer],
53
- ])}`,
69
+ [
70
+ statementTex,
71
+ "=",
72
+ new substractNode_1.SubstractNode(new powerNode_1.SquareNode(aMonom), new powerNode_1.SquareNode(bPositive.toTree())).toTex(),
73
+ ],
74
+ ["", "=", answer],
75
+ ])}`;
76
+ };
77
+ const getThirdIdentityQuestion = () => {
78
+ const affine = affine_1.AffineConstructor.random(undefined, { excludes: [0] });
79
+ const affine2 = new affine_1.Affine(affine.a, -affine.b);
80
+ const identifiers = {
81
+ affine1Coeffs: affine.coefficients,
82
+ affine2Coeffs: affine2.coefficients,
83
+ };
84
+ const question = {
85
+ instruction: getInstruction(identifiers),
86
+ startStatement: getStartStatement(identifiers),
87
+ answer: getAnswer(identifiers),
88
+ keys: ["x"],
89
+ answerFormat: "tex",
90
+ identifiers,
91
+ hint: getHint(identifiers),
92
+ correction: getCorrection(identifiers),
54
93
  };
55
94
  return question;
56
95
  };
@@ -74,20 +113,26 @@ const getThirdIdentityPropositions = (n, { answer, affine1Coeffs, affine2Coeffs
74
113
  return (0, shuffle_1.shuffle)(propositions);
75
114
  };
76
115
  exports.getThirdIdentityPropositions = getThirdIdentityPropositions;
77
- const isThirdIdentityAnswerValid = (ans, { affine1Coeffs, affine2Coeffs }) => {
78
- const affine = new affine_1.Affine(affine1Coeffs[1], affine1Coeffs[0]);
79
- const affine2 = new affine_1.Affine(affine2Coeffs[1], affine2Coeffs[0]);
80
- const answer = affine.multiply(affine2).toTree();
81
- const texs = answer.toAllValidTexs();
82
- return texs.includes(ans);
116
+ const isThirdIdentityAnswerValid = (ans, { answer, affine1Coeffs, affine2Coeffs }) => {
117
+ try {
118
+ const parsed = (0, latexParser_1.parseAlgebraic)(ans);
119
+ if (!parsed)
120
+ return false;
121
+ if (!(0, addNode_1.isAddNode)(parsed) && !(0, substractNode_1.isSubstractNode)(parsed))
122
+ return false;
123
+ return (parsed
124
+ .simplify({ forbidFactorize: true, towardsDistribute: true })
125
+ .toTex() === answer);
126
+ }
127
+ catch (err) {
128
+ return (0, handleVEAError_1.handleVEAError)(err);
129
+ }
83
130
  };
84
131
  exports.isThirdIdentityAnswerValid = isThirdIdentityAnswerValid;
85
132
  exports.thirdIdentity = {
86
133
  id: "idRmq3",
87
134
  connector: "=",
88
135
  label: "Identité remarquable $(a+b)(a-b)$",
89
- levels: ["3ème", "2nde"],
90
- sections: ["Calcul littéral"],
91
136
  isSingleStep: false,
92
137
  generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(exports.getThirdIdentityQuestion, nb),
93
138
  getPropositions: exports.getThirdIdentityPropositions,
@@ -96,4 +141,9 @@ exports.thirdIdentity = {
96
141
  freeTimer: 60,
97
142
  subject: "Mathématiques",
98
143
  hasHintAndCorrection: true,
144
+ getInstruction,
145
+ getCorrection,
146
+ getHint,
147
+ getAnswer,
148
+ getStartStatement,
99
149
  };
@@ -1 +1 @@
1
- {"version":3,"file":"factoType1Exercise.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/factorisation/factoType1Exercise.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,QAAQ,EAUT,MAAM,0BAA0B,CAAC;AAmBlC;;;GAGG;AACH,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,MAAM,EAAE,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAgKF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,CAepD,CAAC"}
1
+ {"version":3,"file":"factoType1Exercise.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/factorisation/factoType1Exercise.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,QAAQ,EAUT,MAAM,0BAA0B,CAAC;AAmBlC;;;GAGG;AACH,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,MAAM,EAAE,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAiKF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,CAepD,CAAC"}
@@ -103,6 +103,7 @@ const getPropositions = (n, { answer, affinesCoeffs, operation }) => {
103
103
  };
104
104
  const isAnswerValid = (ans, { answer, ...identifiers }) => {
105
105
  try {
106
+ console.log(ans, answer);
106
107
  const parsed = (0, latexParser_1.parseAlgebraic)(ans);
107
108
  if (!parsed)
108
109
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"distributeAndSimplify.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/simplifying/distributeAndSimplify.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,0BAA0B,CAAC;AAQlC,KAAK,WAAW,GAAG;IACjB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA2DF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,CAcvD,CAAC"}
1
+ {"version":3,"file":"distributeAndSimplify.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/simplifying/distributeAndSimplify.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,0BAA0B,CAAC;AAUlC,KAAK,WAAW,GAAG;IACjB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA+EF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,CAcvD,CAAC"}
@@ -7,9 +7,32 @@ const affine_1 = require("../../../../math/polynomials/affine");
7
7
  const randint_1 = require("../../../../math/utils/random/randint");
8
8
  const addNode_1 = require("../../../../tree/nodes/operators/addNode");
9
9
  const multiplyNode_1 = require("../../../../tree/nodes/operators/multiplyNode");
10
+ const polynomialParser_1 = require("../../../../tree/parsers/polynomialParser");
10
11
  const coinFlip_1 = require("../../../../utils/alea/coinFlip");
12
+ const handleVEAError_1 = require("../../../../utils/errors/handleVEAError");
11
13
  //[a]|[b*(cx+d)] +- e*(fx+g)]
12
14
  // c & f > 0
15
+ const getStatementNode = (identifiers) => {
16
+ const { firstTermIsAffine, a, b, c, d, e, f, g } = identifiers;
17
+ const statement = new addNode_1.AddNode(firstTermIsAffine
18
+ ? new multiplyNode_1.MultiplyNode(b.toTree(), new affine_1.Affine(c, d).toTree())
19
+ : a.toTree(), new multiplyNode_1.MultiplyNode(e.toTree(), new affine_1.Affine(f, g).toTree()));
20
+ return statement;
21
+ };
22
+ const getInstruction = (identifiers) => {
23
+ return `Développer et réduire :
24
+
25
+ $$
26
+ ${getStatementNode(identifiers).toTex()}
27
+ $$`;
28
+ };
29
+ const getAnswer = (identifiers) => {
30
+ const { firstTermIsAffine, a, b, c, d, e, f, g } = identifiers;
31
+ const answer = firstTermIsAffine
32
+ ? new affine_1.Affine(b * c + e * f, b * d + e * g).toTree().toTex()
33
+ : new affine_1.Affine(e * f, a + e * g).toTree().toTex();
34
+ return answer;
35
+ };
13
36
  const getDistributeAndSimplifyQuestion = () => {
14
37
  const firstTermIsAffine = (0, coinFlip_1.coinFlip)();
15
38
  const a = (0, randint_1.randint)(-5, 6, [0]);
@@ -22,18 +45,13 @@ const getDistributeAndSimplifyQuestion = () => {
22
45
  f = (0, randint_1.randint)(1, 6);
23
46
  } while (b * c + e * f === 0);
24
47
  const g = (0, randint_1.randint)(-5, 6, [0]);
25
- const statement = new addNode_1.AddNode(firstTermIsAffine
26
- ? new multiplyNode_1.MultiplyNode(b.toTree(), new affine_1.Affine(c, d).toTree())
27
- : a.toTree(), new multiplyNode_1.MultiplyNode(e.toTree(), new affine_1.Affine(f, g).toTree())).simplify();
28
- const answer = firstTermIsAffine
29
- ? new affine_1.Affine(b * c + e * f, b * d + e * g).toTree().toTex()
30
- : new affine_1.Affine(e * f, a + e * g).toTree().toTex();
48
+ const identifiers = { firstTermIsAffine, a, b, c, d, e, f, g };
31
49
  const question = {
32
- answer,
33
- instruction: `Développer et réduire : $${statement.toTex()}$`,
50
+ answer: getAnswer(identifiers),
51
+ instruction: getInstruction(identifiers),
34
52
  keys: ["x"],
35
53
  answerFormat: "tex",
36
- identifiers: { firstTermIsAffine, a, b, c, d, e, f, g },
54
+ identifiers,
37
55
  };
38
56
  return question;
39
57
  };
@@ -46,23 +64,27 @@ const getPropositions = (n, { answer }) => {
46
64
  return (0, exercise_1.shuffleProps)(propositions, n);
47
65
  };
48
66
  const isAnswerValid = (ans, { answer, firstTermIsAffine, a, b, c, d, e, f, g }) => {
49
- const answerNode = firstTermIsAffine
50
- ? new affine_1.Affine(b * c + e * f, b * d + e * g).toTree()
51
- : new affine_1.Affine(e * f, a + e * g).toTree();
52
- const texs = answerNode.toAllValidTexs();
53
- return texs.includes(ans);
67
+ try {
68
+ const parsed = (0, polynomialParser_1.polynomialParser)(ans);
69
+ if (!parsed)
70
+ return false;
71
+ return parsed.simplify().toTex() === answer;
72
+ }
73
+ catch (err) {
74
+ return (0, handleVEAError_1.handleVEAError)(err);
75
+ }
54
76
  };
55
77
  exports.distributeAndSimplify = {
56
78
  id: "distributeAndSimplify",
57
79
  connector: "=",
58
80
  label: "Développer et réduire une expression",
59
- levels: ["4ème", "3ème", "2nde"],
60
81
  isSingleStep: true,
61
- sections: ["Calcul littéral"],
62
82
  generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getDistributeAndSimplifyQuestion, nb),
63
83
  qcmTimer: 60,
64
84
  freeTimer: 60,
65
85
  getPropositions,
66
86
  isAnswerValid,
67
87
  subject: "Mathématiques",
88
+ getAnswer,
89
+ getInstruction,
68
90
  };
@@ -1,8 +1,8 @@
1
1
  import { Exercise } from "../../../../exercises/exercise";
2
2
  type Identifiers = {
3
- rand: number;
4
- polynome1Coeffs: number[];
5
- polynome2Coeffs: number[];
3
+ variable: string;
4
+ coeffs: number[][];
5
+ order: number[];
6
6
  };
7
7
  export declare const reduceExpression: Exercise<Identifiers>;
8
8
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"reduceExpression.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/simplifying/reduceExpression.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAQT,MAAM,0BAA0B,CAAC;AAQlC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAiHF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAalD,CAAC"}
1
+ {"version":3,"file":"reduceExpression.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/simplifying/reduceExpression.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,0BAA0B,CAAC;AAkBlC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IAOjB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IAGnB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AA+MF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAgBlD,CAAC"}
@@ -3,100 +3,193 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reduceExpression = void 0;
4
4
  const exercise_1 = require("../../../../exercises/exercise");
5
5
  const getDistinctQuestions_1 = require("../../../../exercises/utils/getDistinctQuestions");
6
- const polynomial_1 = require("../../../../math/polynomials/polynomial");
6
+ const affine_1 = require("../../../../math/polynomials/affine");
7
+ const trinom_1 = require("../../../../math/polynomials/trinom");
7
8
  const randint_1 = require("../../../../math/utils/random/randint");
8
9
  const addNode_1 = require("../../../../tree/nodes/operators/addNode");
10
+ const multiplyNode_1 = require("../../../../tree/nodes/operators/multiplyNode");
11
+ const powerNode_1 = require("../../../../tree/nodes/operators/powerNode");
12
+ const polynomialParser_1 = require("../../../../tree/parsers/polynomialParser");
13
+ const operatorComposition_1 = require("../../../../tree/utilities/operatorComposition");
14
+ const random_1 = require("../../../../utils/alea/random");
9
15
  const shuffle_1 = require("../../../../utils/alea/shuffle");
16
+ const handleVEAError_1 = require("../../../../utils/errors/handleVEAError");
17
+ const rebuildIdentifiers = (oldids) => {
18
+ if (oldids.variable)
19
+ return oldids;
20
+ const { polynome1Coeffs, polynome2Coeffs } = oldids;
21
+ const nbTerms = polynome1Coeffs.filter((e) => e === 0 || !!e).length +
22
+ polynome2Coeffs.filter((e) => e === 0 || !!e).length;
23
+ return {
24
+ variable: "x",
25
+ coeffs: [
26
+ [polynome1Coeffs[0], polynome2Coeffs[0]].filter((e) => e === 0 || !!e),
27
+ [polynome1Coeffs[1], polynome2Coeffs[1]].filter((e) => e === 0 || !!e),
28
+ [polynome1Coeffs[2], polynome2Coeffs[2]].filter((e) => e === 0 || !!e),
29
+ ],
30
+ order: (0, shuffle_1.shuffle)(Array.from({ length: nbTerms }, (_, i) => i)),
31
+ };
32
+ };
33
+ const getStatementNode = (identifiers) => {
34
+ const { variable, coeffs, order } = identifiers;
35
+ const nodes = coeffs.flatMap((coeff, i) => coeff.map((c) => {
36
+ if (i === 0)
37
+ return c.toTree();
38
+ if (i === 1)
39
+ return (0, multiplyNode_1.multiply)(c, variable);
40
+ else
41
+ return (0, multiplyNode_1.multiply)(c, (0, powerNode_1.square)(variable));
42
+ }));
43
+ const shuffled = order.map((i) => nodes[i]);
44
+ // const polynome1 = new Polynomial(polynome1Coeffs, variable);
45
+ // const polynome2 = new Polynomial(polynome2Coeffs, variable);
46
+ return (0, operatorComposition_1.operatorComposition)(addNode_1.AddNode, shuffled);
47
+ // const statement = new AddNode(polynome1.toTree(), polynome2.toTree());
48
+ // return statement.deepShuffle({ nodeIdsToShuffle: [OperatorIds.add] });
49
+ };
50
+ const getStartStatement = (identifiers) => {
51
+ return getStatementNode(identifiers).toTex();
52
+ };
53
+ const getAnswer = (identifiers) => {
54
+ const answer = getStatementNode(identifiers)
55
+ .simplify({
56
+ forbidFactorize: true,
57
+ towardsDistribute: true,
58
+ })
59
+ .toTex();
60
+ return answer;
61
+ };
62
+ const getInstruction = (identifiers) => {
63
+ return `Réduire l'expression suivante :
64
+
65
+ $$
66
+ ${getStartStatement(identifiers)}
67
+ $$`;
68
+ };
10
69
  const getReduceExpression = () => {
11
70
  const rand = (0, randint_1.randint)(0, 7);
12
71
  let polynome1;
13
72
  let polynome2;
14
- switch (rand) {
15
- case 0: // ax + b + cx + d
16
- polynome1 = new polynomial_1.Polynomial([(0, randint_1.randint)(-9, 10), (0, randint_1.randint)(-9, 10, [0])]);
17
- polynome2 = new polynomial_1.Polynomial([(0, randint_1.randint)(-5, 6), (0, randint_1.randint)(-5, 6, [0])]);
18
- break;
19
- case 1:
20
- polynome1 = new polynomial_1.Polynomial([(0, randint_1.randint)(-9, 10), (0, randint_1.randint)(-9, 10, [0])]);
21
- polynome2 = new polynomial_1.Polynomial([0, (0, randint_1.randint)(-5, 6, [0])]);
22
- break;
23
- case 2:
24
- polynome1 = new polynomial_1.Polynomial([(0, randint_1.randint)(-9, 10), (0, randint_1.randint)(-9, 10, [0])]);
25
- polynome2 = new polynomial_1.Polynomial([(0, randint_1.randint)(-5, 6, [0])]);
26
- break;
27
- case 3:
28
- polynome1 = new polynomial_1.Polynomial([
29
- (0, randint_1.randint)(-9, 10),
30
- (0, randint_1.randint)(-9, 10),
31
- (0, randint_1.randint)(-9, 10, [0]),
32
- ]);
33
- polynome2 = new polynomial_1.Polynomial([0, (0, randint_1.randint)(-5, 6), (0, randint_1.randint)(-5, 6, [0])]);
34
- break;
35
- case 4:
36
- polynome1 = new polynomial_1.Polynomial([
37
- (0, randint_1.randint)(-9, 10),
38
- (0, randint_1.randint)(-9, 10),
39
- (0, randint_1.randint)(-9, 10, [0]),
40
- ]);
41
- polynome2 = new polynomial_1.Polynomial([0, 0, (0, randint_1.randint)(-5, 6, [0])]);
42
- break;
43
- case 5:
44
- polynome1 = new polynomial_1.Polynomial([
45
- (0, randint_1.randint)(-9, 10),
46
- (0, randint_1.randint)(-9, 10),
47
- (0, randint_1.randint)(-9, 10, [0]),
48
- ]);
49
- polynome2 = new polynomial_1.Polynomial([0, (0, randint_1.randint)(-5, 6, [0])]);
50
- break;
51
- case 6:
52
- polynome1 = new polynomial_1.Polynomial([
53
- (0, randint_1.randint)(-9, 10),
54
- (0, randint_1.randint)(-9, 10),
55
- (0, randint_1.randint)(-9, 10, [0]),
56
- ]);
57
- polynome2 = new polynomial_1.Polynomial([(0, randint_1.randint)(-5, 6, [0])]);
58
- break;
59
- default:
60
- throw Error("something went wrong");
73
+ //coeffs[0] est degré 0, coeffs[1] est degré 1, coeffs[2] degré 2
74
+ const coeffs = [[], [], []];
75
+ const nbTerms = (0, randint_1.randint)(4, 6);
76
+ for (let i = 0; i < nbTerms; i++) {
77
+ if (i === nbTerms - 1) {
78
+ let availableDegree = coeffs.findIndex((coeff) => coeff.length === 0);
79
+ if (availableDegree === -1)
80
+ availableDegree = (0, randint_1.randint)(0, 3);
81
+ coeffs[availableDegree].push((0, randint_1.randint)(-9, 10, [0]));
82
+ }
83
+ else {
84
+ const degree = (0, randint_1.randint)(0, 3);
85
+ coeffs[degree].push((0, randint_1.randint)(-9, 10, [0]));
86
+ }
61
87
  }
62
- const statement = new addNode_1.AddNode(polynome1.toTree(), polynome2.toTree());
63
- statement.shuffle();
64
- const statementTex = statement.toTex();
65
- const answer = polynome1.add(polynome2).toTree().toTex();
88
+ const order = (0, shuffle_1.shuffle)(Array.from({ length: nbTerms }, (_, i) => i));
89
+ // switch (rand) {
90
+ // case 0: // ax + b + cx + d
91
+ // polynome1 = new Polynomial([randint(-9, 10, [0]), randint(-9, 10, [0])]);
92
+ // polynome2 = new Polynomial([randint(-5, 6, [0]), randint(-5, 6, [0])]);
93
+ // break;
94
+ // case 1: //ax+b + cx
95
+ // polynome1 = new Polynomial([randint(-9, 10, [0]), randint(-9, 10, [0])]);
96
+ // polynome2 = new Polynomial([0, randint(-5, 6, [0])]);
97
+ // break;
98
+ // case 2: //ax+b+c
99
+ // polynome1 = new Polynomial([randint(-9, 10, [0]), randint(-9, 10, [0])]);
100
+ // polynome2 = new Polynomial([randint(-5, 6, [0])]);
101
+ // break;
102
+ // case 3: //ax^2+bx+c + ax^2+bx
103
+ // polynome1 = new Polynomial([
104
+ // randint(-9, 10),
105
+ // randint(-9, 10),
106
+ // randint(-9, 10, [0]),
107
+ // ]);
108
+ // polynome2 = new Polynomial([0, randint(-5, 6), randint(-5, 6, [0])]);
109
+ // break;
110
+ // case 4: //ax^2+bx+c + ax^2
111
+ // polynome1 = new Polynomial([
112
+ // randint(-9, 10),
113
+ // randint(-9, 10),
114
+ // randint(-9, 10, [0]),
115
+ // ]);
116
+ // polynome2 = new Polynomial([0, 0, randint(-5, 6, [0])]);
117
+ // break;
118
+ // case 5: //ax^2+bx+c + ax
119
+ // polynome1 = new Polynomial([
120
+ // randint(-9, 10),
121
+ // randint(-9, 10),
122
+ // randint(-9, 10, [0]),
123
+ // ]);
124
+ // polynome2 = new Polynomial([0, randint(-5, 6, [0])]);
125
+ // break;
126
+ // case 6: //ax^2 +bx+c + c
127
+ // polynome1 = new Polynomial([
128
+ // randint(-9, 10),
129
+ // randint(-9, 10),
130
+ // randint(-9, 10, [0]),
131
+ // ]);
132
+ // polynome2 = new Polynomial([randint(-5, 6, [0])]);
133
+ // break;
134
+ // default:
135
+ // throw Error("something went wrong");
136
+ // }
137
+ const variable = (0, random_1.random)(["x", "n", "a", "y", "t"]);
138
+ const identifiers = {
139
+ // rand,
140
+ // polynome1Coeffs: polynome1.coefficients,
141
+ // polynome2Coeffs: polynome2.coefficients,
142
+ coeffs,
143
+ variable,
144
+ order,
145
+ };
66
146
  const question = {
67
- instruction: `Réduire l'expression suivante : $${statementTex}$`,
68
- startStatement: statementTex,
69
- answer,
70
- keys: ["x"],
147
+ instruction: getInstruction(identifiers),
148
+ startStatement: getStartStatement(identifiers),
149
+ answer: getAnswer(identifiers),
150
+ keys: [variable],
71
151
  answerFormat: "tex",
72
- identifiers: {
73
- rand,
74
- polynome1Coeffs: polynome1.coefficients,
75
- polynome2Coeffs: polynome2.coefficients,
76
- },
152
+ identifiers,
77
153
  };
78
154
  return question;
79
155
  };
80
- const getPropositions = (n, { answer, rand, polynome1Coeffs }) => {
156
+ const getPropositions = (n, { answer, coeffs, variable }) => {
81
157
  const propositions = [];
82
158
  (0, exercise_1.addValidProp)(propositions, answer);
83
- const polynome1 = new polynomial_1.Polynomial(polynome1Coeffs);
159
+ (0, exercise_1.tryToAddWrongProp)(propositions, coeffs
160
+ .flatMap((e) => e)
161
+ .reduce((acc, curr) => acc + curr, 0)
162
+ .frenchify());
84
163
  while (propositions.length < n) {
85
- const polynome2 = new polynomial_1.Polynomial(rand < 3
86
- ? [(0, randint_1.randint)(-5, 6, [0]), (0, randint_1.randint)(-5, 6, [0])]
87
- : [(0, randint_1.randint)(-5, 6, [0]), (0, randint_1.randint)(-5, 6, [0]), (0, randint_1.randint)(-5, 6, [0])]);
88
- (0, exercise_1.tryToAddWrongProp)(propositions, polynome1.add(polynome2).toTree().toTex());
164
+ if (coeffs[2].length) {
165
+ (0, exercise_1.tryToAddWrongProp)(propositions, new trinom_1.Trinom((0, randint_1.randint)(-9, 10, [0]), (0, randint_1.randint)(-9, 10), (0, randint_1.randint)(-9, 10), {
166
+ variable,
167
+ })
168
+ .toTree()
169
+ .toTex());
170
+ }
171
+ else {
172
+ (0, exercise_1.tryToAddWrongProp)(propositions, new affine_1.Affine((0, randint_1.randint)(-9, 10, [0]), (0, randint_1.randint)(-9, 10)).toTree().toTex());
173
+ }
89
174
  }
90
175
  return (0, shuffle_1.shuffle)(propositions);
91
176
  };
92
- const isAnswerValid = (ans, { polynome1Coeffs, polynome2Coeffs, rand }) => {
93
- const polynome1 = new polynomial_1.Polynomial(polynome1Coeffs);
94
- const polynome2 = new polynomial_1.Polynomial(polynome2Coeffs);
95
- const answer = polynome1
96
- .add(polynome2)
97
- .toTree({ forbidPowerToProduct: true });
98
- const texs = answer.toAllValidTexs();
99
- return texs.includes(ans);
177
+ const isAnswerValid = (ans, { variable, answer }) => {
178
+ try {
179
+ const parsed = (0, polynomialParser_1.polynomialParser)(ans, { variable });
180
+ if (!parsed)
181
+ return false;
182
+ return (parsed
183
+ .simplify({
184
+ forbidFactorize: true,
185
+ towardsDistribute: true,
186
+ forbidAdditions: true,
187
+ })
188
+ .toTex() === answer);
189
+ }
190
+ catch (err) {
191
+ return (0, handleVEAError_1.handleVEAError)(err);
192
+ }
100
193
  };
101
194
  exports.reduceExpression = {
102
195
  id: "reduceExpression",
@@ -111,4 +204,7 @@ exports.reduceExpression = {
111
204
  getPropositions,
112
205
  isAnswerValid,
113
206
  subject: "Mathématiques",
207
+ rebuildIdentifiers,
208
+ getAnswer,
209
+ getInstruction,
114
210
  };
@@ -0,0 +1,2 @@
1
+ export * from "./tableReading";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/dataReading/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./tableReading"), exports);
@@ -0,0 +1,8 @@
1
+ import { Exercise } from "../../../exercises/exercise";
2
+ type Identifiers = {
3
+ values: number[][];
4
+ caseAsked: number;
5
+ };
6
+ export declare const tableReading: Exercise<Identifiers>;
7
+ export {};
8
+ //# sourceMappingURL=tableReading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableReading.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/dataReading/tableReading.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,0BAA0B,CAAC;AASlC,KAAK,WAAW,GAAG;IAIjB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AA4FF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,WAAW,CAgB9C,CAAC"}