math-exercises 3.0.11 → 3.0.12

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 (27) hide show
  1. package/lib/exercises/math/calculLitteral/equation/equationType4Exercise.d.ts.map +1 -1
  2. package/lib/exercises/math/calculLitteral/equation/equationType4Exercise.js +17 -15
  3. package/lib/exercises/math/calculLitteral/equation/firstDegreeEquationIntType3.d.ts.map +1 -1
  4. package/lib/exercises/math/calculLitteral/equation/firstDegreeEquationIntType3.js +17 -3
  5. package/lib/exercises/math/functions/basics/inverseImageFunction.d.ts +2 -2
  6. package/lib/exercises/math/functions/basics/inverseImageFunction.d.ts.map +1 -1
  7. package/lib/exercises/math/functions/basics/inverseImageFunction.js +81 -14
  8. package/lib/exercises/math/trigonometry/equationCosOnRandomInterval.js +10 -10
  9. package/lib/exercises/math/trigonometry/equationSinOnRandomInterval.js +10 -10
  10. package/lib/exercises/math/trigonometry/mainAngleMeasure.d.ts.map +1 -1
  11. package/lib/exercises/math/trigonometry/mainAngleMeasure.js +1 -0
  12. package/lib/exercises/math/trigonometry/trigonometrySideCalcul.d.ts.map +1 -1
  13. package/lib/exercises/math/trigonometry/trigonometrySideCalcul.js +170 -106
  14. package/lib/exercises/vea/numberVEA.d.ts +1 -1
  15. package/lib/exercises/vea/numberVEA.d.ts.map +1 -1
  16. package/lib/exercises/vea/numberVEA.js +2 -2
  17. package/lib/index.d.ts +2 -2
  18. package/lib/math/polynomials/affine.d.ts +2 -0
  19. package/lib/math/polynomials/affine.d.ts.map +1 -1
  20. package/lib/math/polynomials/affine.js +5 -0
  21. package/lib/tree/nodes/equations/equalNode.d.ts +1 -2
  22. package/lib/tree/nodes/equations/equalNode.d.ts.map +1 -1
  23. package/lib/tree/nodes/equations/equalNode.js +47 -22
  24. package/lib/tree/parsers/numberParser.d.ts +1 -1
  25. package/lib/tree/parsers/numberParser.d.ts.map +1 -1
  26. package/lib/tree/parsers/numberParser.js +4 -1
  27. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"equationType4Exercise.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/equation/equationType4Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAerC;;GAEG;AAEH,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAsGF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,CAiBvD,CAAC"}
1
+ {"version":3,"file":"equationType4Exercise.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/equation/equationType4Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAkBrC;;GAEG;AAEH,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAkGF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,CAoBvD,CAAC"}
@@ -4,7 +4,7 @@ import { equationKeys } from "../../../../exercises/utils/keys/equationKeys.js";
4
4
  import { Rational } from "../../../../math/numbers/rationals/rational.js";
5
5
  import { Affine } from "../../../../math/polynomials/affine.js";
6
6
  import { randint } from "../../../../math/utils/random/randint.js";
7
- import { EqualNode } from "../../../../tree/nodes/equations/equalNode.js";
7
+ import { EqualNode, equationResolutionTex, } from "../../../../tree/nodes/equations/equalNode.js";
8
8
  import { VariableNode } from "../../../../tree/nodes/variables/variableNode.js";
9
9
  import { shuffle } from "../../../../utils/alea/shuffle.js";
10
10
  import { equationVEA } from "../../../../exercises/vea/equationVEA.js";
@@ -53,23 +53,22 @@ const getQuestionFromIdentifiers = (identifiers) => {
53
53
  keys: equationKeys,
54
54
  answerFormat: "tex",
55
55
  identifiers,
56
+ hint: getHint(identifiers),
57
+ correction: getCorrection(identifiers),
56
58
  };
57
59
  return question;
58
60
  };
59
- // hint: `Commence par regrouper les termes en $x$ d'un même côté de l'équation. Puis, isole $x$ en effectuant les bonnes opérations.`,
60
- // correction: `On isole $x$ à gauche en soustrayant par $${b}$ puis en divisant par $${a}$ :
61
- // ${alignTex([
62
- // [
63
- // statementTex,
64
- // "\\iff",
65
- // new EqualNode(
66
- // new Affine(a, 0).toTree(),
67
- // affines[1].add(-b).toTree(),
68
- // ).toTex(),
69
- // ],
70
- // ["", "\\iff", answer],
71
- // ])}
72
- // `,
61
+ const getHint = (identifiers) => {
62
+ return `Commence par regrouper les termes en $x$ d'un même côté de l'équation. Puis, isole $x$ en effectuant les bonnes opérations.`;
63
+ };
64
+ const getCorrection = (identifiers) => {
65
+ const { a, b, c, d } = identifiers;
66
+ return `On regroupe les nombres d'un côté, et les termes en $x$ de l'autre :
67
+
68
+ $$
69
+ ${equationResolutionTex(a.toTree(), b.toTree(), c.toTree(), d.toTree())}
70
+ $$`;
71
+ };
73
72
  const getPropositions = (n, { answer, a, b, c, d }) => {
74
73
  const propositions = [];
75
74
  addValidProp(propositions, answer);
@@ -101,4 +100,7 @@ export const equationType4Exercise = {
101
100
  getInstruction,
102
101
  getAnswer,
103
102
  getQuestionFromIdentifiers,
103
+ getHint,
104
+ getCorrection,
105
+ hasHintAndCorrection: true,
104
106
  };
@@ -1 +1 @@
1
- {"version":3,"file":"firstDegreeEquationIntType3.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/equation/firstDegreeEquationIntType3.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAWT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,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;AAmGF,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAAC,WAAW,CAe7D,CAAC"}
1
+ {"version":3,"file":"firstDegreeEquationIntType3.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/equation/firstDegreeEquationIntType3.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAarC,KAAK,WAAW,GAAG;IACjB,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;AAkHF,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAAC,WAAW,CAgB7D,CAAC"}
@@ -2,7 +2,7 @@ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../exer
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
3
  import { equationVEA } from "../../../../exercises/vea/equationVEA.js";
4
4
  import { randint } from "../../../../math/utils/random/randint.js";
5
- import { EqualNode } from "../../../../tree/nodes/equations/equalNode.js";
5
+ import { EqualNode, equationResolutionTex, } from "../../../../tree/nodes/equations/equalNode.js";
6
6
  import { AddNode } from "../../../../tree/nodes/operators/addNode.js";
7
7
  import { FractionNode } from "../../../../tree/nodes/operators/fractionNode.js";
8
8
  import { MultiplyNode } from "../../../../tree/nodes/operators/multiplyNode.js";
@@ -21,6 +21,17 @@ const getAnswer = (identifiers) => {
21
21
  const answer = new EqualNode(new VariableNode("x"), x.toTree()).toTex();
22
22
  return answer;
23
23
  };
24
+ const getHint = (identifiers) => {
25
+ return `Commence par regrouper les termes en $x$ d'un même côté de l'équation. Puis, isole $x$ en effectuant les bonnes opérations.`;
26
+ };
27
+ const getCorrection = (identifiers) => {
28
+ const { a, b, c, d } = identifiers;
29
+ return `On regroupe les nombres d'un côté, et les termes en $x$ de l'autre :
30
+
31
+ $$
32
+ ${equationResolutionTex(a.toTree(), b.toTree(), c.toTree(), d.toTree())}
33
+ $$`;
34
+ };
24
35
  const getFirstDegreeEquationIntQuestion = () => {
25
36
  const a = randint(-15, 15, [0]);
26
37
  const x = randint(-15, 15, [0]);
@@ -34,6 +45,8 @@ const getFirstDegreeEquationIntQuestion = () => {
34
45
  keys: ["x", "equal"],
35
46
  answerFormat: "tex",
36
47
  identifiers,
48
+ hint: getHint(identifiers),
49
+ correction: getCorrection(identifiers),
37
50
  };
38
51
  return question;
39
52
  };
@@ -75,9 +88,7 @@ const isAnswerValid = (ans, { answer, x }) => {
75
88
  export const firstDegreeEquationIntType3 = {
76
89
  id: "firstDegreeEquationIntType3",
77
90
  label: "Résoudre une équation du type $ax + b = cx + d$ (solution entière)",
78
- levels: ["2nde"],
79
91
  isSingleStep: true,
80
- sections: ["Équations"],
81
92
  generator: (nb) => getDistinctQuestions(getFirstDegreeEquationIntQuestion, nb),
82
93
  qcmTimer: 60,
83
94
  freeTimer: 60,
@@ -86,4 +97,7 @@ export const firstDegreeEquationIntType3 = {
86
97
  subject: "Mathématiques",
87
98
  getInstruction,
88
99
  getAnswer,
100
+ getHint,
101
+ getCorrection,
102
+ hasHintAndCorrection: true,
89
103
  };
@@ -1,7 +1,7 @@
1
1
  import { Exercise } from "../../../../exercises/exercise.js";
2
2
  type Identifiers = {
3
- poly1: number[];
4
- xValue: number;
3
+ coeffs: number[];
4
+ yValue: number;
5
5
  };
6
6
  export declare const inverseImageFunction: Exercise<Identifiers>;
7
7
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"inverseImageFunction.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/basics/inverseImageFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAQT,MAAM,6BAA6B,CAAC;AAKrC,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAyCF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAatD,CAAC"}
1
+ {"version":3,"file":"inverseImageFunction.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/basics/inverseImageFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAQrC,KAAK,WAAW,GAAG;IAIjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA4GF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAoBtD,CAAC"}
@@ -1,34 +1,94 @@
1
1
  import { addValidProp, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { AffineConstructor } from "../../../../math/polynomials/affine.js";
3
4
  import { Polynomial } from "../../../../math/polynomials/polynomial.js";
4
5
  import { randint } from "../../../../math/utils/random/randint.js";
6
+ import { equationResolutionTex } from "../../../../tree/nodes/equations/equalNode.js";
7
+ import { add } from "../../../../tree/nodes/operators/addNode.js";
5
8
  import { shuffle } from "../../../../utils/alea/shuffle.js";
9
+ const rebuildIdentifiers = (oldIds) => {
10
+ if (oldIds.coeffs?.length)
11
+ return oldIds;
12
+ const polynome = new Polynomial(oldIds.poly1);
13
+ const yValue = polynome.calculate(oldIds.xValue);
14
+ return {
15
+ coeffs: oldIds.poly1,
16
+ yValue,
17
+ };
18
+ };
19
+ const getStartStatement = (identifiers) => {
20
+ const { yValue } = identifiers;
21
+ return `f(x) = ${yValue}`;
22
+ };
23
+ const getInstruction = (identifiers) => {
24
+ const { yValue, coeffs } = identifiers;
25
+ const polynome = new Polynomial(coeffs);
26
+ const statement = `Soit $f$ la fonction définie sur $\\mathbb{R}$ par :
27
+
28
+ $$
29
+ f(x) = ${polynome.toTree().toTex()}
30
+ $$
31
+
32
+ Déterminer le ou les antécédents de $${yValue}$ par $f$.`;
33
+ return statement;
34
+ };
35
+ const getAnswer = (identifiers) => {
36
+ const { yValue, coeffs } = identifiers;
37
+ const polynome = AffineConstructor.fromCoeffs(coeffs);
38
+ const xValue = polynome.solve(yValue);
39
+ const answer = "x=" + xValue.toTex();
40
+ return answer;
41
+ };
6
42
  const getInverseImageFunction = () => {
7
43
  const polynome1 = new Polynomial([randint(-9, 10), randint(-5, 6, [0])]);
8
44
  const xValue = randint(-9, 10);
9
- let image = polynome1.calculate(xValue) + "";
10
- const statement = `Soit $f(x) = ${polynome1
11
- .toTree()
12
- .toTex()}$. Déterminer le ou les antécédents de $${image}$ par $f$.`;
13
- const answer = "x=" + xValue;
45
+ const y = polynome1.calculate(xValue);
46
+ const identifiers = { coeffs: polynome1.coefficients, yValue: y };
14
47
  const question = {
15
- instruction: statement,
16
- startStatement: `f(x) = ${image}`,
17
- answer,
48
+ instruction: getInstruction(identifiers),
49
+ startStatement: getStartStatement(identifiers),
50
+ answer: getAnswer(identifiers),
18
51
  keys: ["x", "equal"],
19
52
  answerFormat: "tex",
20
- identifiers: { poly1: polynome1.coefficients, xValue },
53
+ identifiers,
54
+ hint: getHint(identifiers),
55
+ correction: getCorrection(identifiers),
21
56
  };
22
57
  return question;
23
58
  };
24
- const getPropositions = (n, { answer, poly1, xValue }) => {
59
+ const getHint = (identifiers) => {
60
+ const { yValue, coeffs } = identifiers;
61
+ return `On doit résoudre l'équation :
62
+
63
+ $$
64
+ f(x) = ${yValue}
65
+ $$`;
66
+ };
67
+ const getCorrection = (identifiers) => {
68
+ const { yValue, coeffs } = identifiers;
69
+ const polynome = AffineConstructor.fromCoeffs(coeffs);
70
+ const xValue = polynome.solve(yValue);
71
+ const answer = "x=" + xValue.toTex();
72
+ return `On résout l'équation :
73
+
74
+ $$
75
+ f(x) = ${yValue}
76
+ $$
77
+
78
+ On obtient :
79
+
80
+ $$
81
+ ${equationResolutionTex(coeffs[1].toTree(), coeffs[0].toTree(), (0).toTree(), yValue.toTree())}
82
+ $$`;
83
+ };
84
+ const getPropositions = (n, { answer, coeffs, yValue }) => {
25
85
  const propositions = [];
26
86
  addValidProp(propositions, answer);
27
- const poly = new Polynomial(poly1);
28
- const image = poly.calculate(xValue);
29
- tryToAddWrongProp(propositions, "x=" + image);
87
+ const poly = AffineConstructor.fromCoeffs(coeffs);
88
+ const x = poly.solve(yValue);
89
+ tryToAddWrongProp(propositions, "x=" + yValue);
30
90
  while (propositions.length < n) {
31
- const wrongAnswer = xValue + randint(-10, 11, [0]);
91
+ const wrongAnswer = add(x, randint(-10, 11, [0])).simplify();
32
92
  tryToAddWrongProp(propositions, "x=" + wrongAnswer);
33
93
  }
34
94
  return shuffle(propositions);
@@ -49,4 +109,11 @@ export const inverseImageFunction = {
49
109
  freeTimer: 60,
50
110
  isAnswerValid,
51
111
  subject: "Mathématiques",
112
+ getInstruction,
113
+ getAnswer,
114
+ getStartStatement,
115
+ rebuildIdentifiers,
116
+ getCorrection,
117
+ getHint,
118
+ hasHintAndCorrection: true,
52
119
  };
@@ -64,12 +64,12 @@ $$
64
64
  ${new CosNode("x".toTree()).toTex()}=${value.cos.toTex()}
65
65
  $$`;
66
66
  };
67
- const getHint = (identifiers) => {
68
- return "";
69
- };
70
- const getCorrection = (identifiers) => {
71
- return "";
72
- };
67
+ // const getHint: GetHint<Identifiers> = (identifiers) => {
68
+ // return "";
69
+ // };
70
+ // const getCorrection: GetCorrection<Identifiers> = (identifiers) => {
71
+ // return "";
72
+ // };
73
73
  const getKeys = (identifiers) => {
74
74
  return ["x", "S", "equal", "lbrace", "semicolon", "rbrace", "pi"];
75
75
  };
@@ -88,8 +88,8 @@ const getEquationCosOnRandomIntervalQuestion = () => {
88
88
  keys: getKeys(identifiers),
89
89
  answerFormat: "tex",
90
90
  identifiers,
91
- hint: getHint(identifiers),
92
- correction: getCorrection(identifiers),
91
+ // hint: getHint(identifiers),
92
+ // correction: getCorrection(identifiers),
93
93
  };
94
94
  return question;
95
95
  };
@@ -104,7 +104,7 @@ export const equationCosOnRandomInterval = {
104
104
  getPropositions,
105
105
  isAnswerValid,
106
106
  subject: "Mathématiques",
107
- getHint,
108
- getCorrection,
107
+ // getHint,
108
+ // getCorrection,
109
109
  getAnswer,
110
110
  };
@@ -56,12 +56,12 @@ const getInstruction = ({ degree, leftBoundPiMultiple, }) => {
56
56
  ${new SinNode("x".toTree()).toTex()}=${value.sin.toTex()}
57
57
  $$`;
58
58
  };
59
- const getHint = (identifiers) => {
60
- return "";
61
- };
62
- const getCorrection = (identifiers) => {
63
- return "";
64
- };
59
+ // const getHint: GetHint<Identifiers> = (identifiers) => {
60
+ // return "";
61
+ // };
62
+ // const getCorrection: GetCorrection<Identifiers> = (identifiers) => {
63
+ // return "";
64
+ // };
65
65
  const getKeys = (identifiers) => {
66
66
  return ["pi"];
67
67
  };
@@ -79,8 +79,8 @@ const getEquationSinOnRandomIntervalQuestion = () => {
79
79
  keys: getKeys(identifiers),
80
80
  answerFormat: "tex",
81
81
  identifiers,
82
- hint: getHint(identifiers),
83
- correction: getCorrection(identifiers),
82
+ // hint: getHint(identifiers),
83
+ // correction: getCorrection(identifiers),
84
84
  };
85
85
  return question;
86
86
  };
@@ -95,7 +95,7 @@ export const equationSinOnRandomInterval = {
95
95
  getPropositions,
96
96
  isAnswerValid,
97
97
  subject: "Mathématiques",
98
- getHint,
99
- getCorrection,
98
+ // getHint,
99
+ // getCorrection,
100
100
  getAnswer,
101
101
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mainAngleMeasure.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/trigonometry/mainAngleMeasure.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAkBT,MAAM,6BAA6B,CAAC;AAgBrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AA4FF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAiBlD,CAAC"}
1
+ {"version":3,"file":"mainAngleMeasure.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/trigonometry/mainAngleMeasure.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAkBT,MAAM,6BAA6B,CAAC;AAgBrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AA4FF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAkBlD,CAAC"}
@@ -98,5 +98,6 @@ export const mainAngleMeasure = {
98
98
  // getHint,
99
99
  // getCorrection,
100
100
  getAnswer,
101
+ getInstruction,
101
102
  // hasHintAndCorrection: false,
102
103
  };
@@ -1 +1 @@
1
- {"version":3,"file":"trigonometrySideCalcul.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/trigonometry/trigonometrySideCalcul.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAUT,MAAM,6BAA6B,CAAC;AAQrC,OAAO,EAEL,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAMzC,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AA4KF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAexD,CAAC"}
1
+ {"version":3,"file":"trigonometrySideCalcul.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/trigonometry/trigonometrySideCalcul.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AASrC,OAAO,EAEL,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAMzC,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AA8OF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAmBxD,CAAC"}
@@ -1,12 +1,42 @@
1
1
  import { addValidProp, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { numberVEA } from "../../../exercises/vea/numberVEA.js";
3
4
  import { greenDark } from "../../../geogebra/colors.js";
4
5
  import { GeogebraConstructor } from "../../../geogebra/geogebraConstructor.js";
5
6
  import { RightTriangleConstructor, } from "../../../math/geometry/rightTriangle.js";
7
+ import { TriangleConstructor, } from "../../../math/geometry/triangle.js";
6
8
  import { randint } from "../../../math/utils/random/randint.js";
7
9
  import { round } from "../../../math/utils/round.js";
8
- import { NumberNode } from "../../../tree/nodes/numbers/numberNode.js";
9
10
  import { shuffle } from "../../../utils/alea/shuffle.js";
11
+ const getInstruction = (identifiers) => {
12
+ const { givenAngle, givenSide, sideAsked, triangleIdentifiers } = identifiers;
13
+ const triangle = TriangleConstructor.fromIdentifiers(triangleIdentifiers);
14
+ const angleValue = triangle.angles[givenAngle].evaluate().frenchify();
15
+ return `Le triangle $${triangle.name}$ rectangle en $${triangle.points[0].name}$ est tel que $${triangle.sides[givenSide].toLengthTex()}$ cm et $\\widehat{${triangle.points[givenAngle].name}} = ${angleValue}^\\circ$.
16
+
17
+ Calculer $${triangle.sides[sideAsked].toInsideName()}$ à $0,1$ cm près.`;
18
+ };
19
+ const getAnswer = (identifiers) => {
20
+ const { givenAngle, givenSide, sideAsked, triangleIdentifiers } = identifiers;
21
+ const triangle = TriangleConstructor.fromIdentifiers(triangleIdentifiers);
22
+ const answer = round(triangle.sides[sideAsked].getLength(), 1).frenchify();
23
+ return answer;
24
+ };
25
+ const getGGBOptions = (identifiers) => {
26
+ const { givenAngle, givenSide, sideAsked, triangleIdentifiers } = identifiers;
27
+ const triangle = RightTriangleConstructor.fromIdentifiers(triangleIdentifiers);
28
+ // triangle.showSidesLength([0, 1, 2].filter((i) => i !== givenSide));
29
+ triangle.highlightAngle(givenAngle, { color: greenDark, showValue: false });
30
+ // triangle.highlightSide(sideAsked, { color: "red", caption: "?" });
31
+ const ggb = new GeogebraConstructor({
32
+ commands: triangle.commands,
33
+ hideAxes: true,
34
+ hideGrid: true,
35
+ });
36
+ return ggb.getOptions({
37
+ coords: triangle.generateCoords(),
38
+ });
39
+ };
10
40
  const getTrigonometrySideCalcul = () => {
11
41
  const givenAngle = randint(1, 3);
12
42
  const givenSide = randint(0, 3);
@@ -15,16 +45,6 @@ const getTrigonometrySideCalcul = () => {
15
45
  randomName: true,
16
46
  niceSideIndex: givenSide,
17
47
  });
18
- triangle.showSidesLength([0, 1, 2].filter((i) => i !== givenSide));
19
- triangle.highlightAngle(givenAngle, { color: greenDark, showValue: true });
20
- triangle.highlightSide(sideAsked, { color: "red", caption: "?" });
21
- const angleValue = triangle.angles[givenAngle].evaluate().frenchify();
22
- const ggb = new GeogebraConstructor({
23
- commands: triangle.commands,
24
- hideAxes: true,
25
- hideGrid: true,
26
- });
27
- const answer = round(triangle.sides[sideAsked].getLength(), 1).frenchify();
28
48
  const identifiers = {
29
49
  givenAngle,
30
50
  givenSide,
@@ -32,16 +52,12 @@ const getTrigonometrySideCalcul = () => {
32
52
  triangleIdentifiers: triangle.toIdentifiers(),
33
53
  };
34
54
  const question = {
35
- instruction: `Le triangle $${triangle.name}$ rectangle en $${triangle.points[0].name}$ est tel que $${triangle.sides[givenSide].toLengthTex()}$ cm et $\\widehat{${triangle.points[givenAngle].name}} = ${angleValue}^\\circ$.
36
-
37
- Calculer $${triangle.sides[sideAsked].toInsideName()}$ à $0,1$ cm près.`,
38
- answer,
39
- // hint: getHint(identifiers),
40
- // correction: getCorrection(identifiers),
55
+ instruction: getInstruction(identifiers),
56
+ answer: getAnswer(identifiers),
57
+ hint: getHint(identifiers),
58
+ correction: getCorrection(identifiers),
41
59
  keys: [],
42
- ggbOptions: ggb.getOptions({
43
- coords: triangle.generateCoords(),
44
- }),
60
+ ggbOptions: getGGBOptions(identifiers),
45
61
  answerFormat: "tex",
46
62
  identifiers,
47
63
  };
@@ -56,102 +72,144 @@ const getPropositions = (n, { answer }) => {
56
72
  return shuffle(propositions);
57
73
  };
58
74
  const getHint = (identifiers) => {
59
- return `Identifier le côté opposé, le côté adjacent et l'hypoténuse, puis utiliser la bonne formule de trigonométrie.`;
75
+ return `Identifie le côté opposé, le côté adjacent et l'hypoténuse du triangle. Puis, utilise la bonne formule de trigonométrie, en te rappelant de :
76
+
77
+ $$
78
+ \\text{SOH-CAH-TOA}
79
+ $$`;
60
80
  };
61
- // const getCorrection: GetCorrection<Identifiers> = (identifiers) => {
62
- // const hypothenus = { name: sides[2], length: sideLengths[2] };
63
- // const sidesWithLentgh = sides.map((value, index) => {
64
- // return { name: value, length: sideLengths[index] };
65
- // });
66
- // const adjacent = sidesWithLentgh.filter(
67
- // (value) =>
68
- // value.name !== hypothenus.name &&
69
- // [value.name.charAt(0), value.name.charAt(1)].includes(angle),
70
- // )[0];
71
- // const opposite = sidesWithLentgh.filter(
72
- // (value) => value.name !== hypothenus.name && value.name !== adjacent.name,
73
- // )[0];
74
- // const correctEquations = getCorrectEquations(
75
- // { name: sides[randSideQuestion], length: sideLengths[randSideQuestion] },
76
- // { name: sides[randSide], length: sideLengths[randSide] },
77
- // hypothenus,
78
- // { name: angle, value: angleValue },
79
- // adjacent,
80
- // opposite,
81
- // answer,
82
- // );
83
- // return `On utilise la relation :
84
- // $$
85
- // ${correctEquations[0]}
86
- // $$
87
- // On a donc :
88
- // $$
89
- // ${correctEquations[1]}
90
- // $$
91
- // donc
92
- // $$${correctEquations[2]}$$. Ainsi $${correctEquations[3]}$ `;
93
- // };
94
- const getCorrectEquations = (randSideQuestion, randSide, hypothenus, angle, adjacent, opposite, answer) => {
95
- let result;
96
- switch (randSideQuestion.name) {
97
- case adjacent.name:
98
- result =
99
- randSide.name === opposite.name
100
- ? [
101
- `\\tan(\\widehat{${angle.name}})=\\frac{${opposite.name}}{${adjacent.name}}`,
102
- `\\tan(\\widehat{${angle.value}})=\\frac{${opposite.length}}{${adjacent.name}}`,
103
- `${adjacent.name}=\\frac{${opposite.length}}{\\tan(\\widehat{${angle.value}})}`,
104
- ]
105
- : [
106
- `\\cos(\\widehat{${angle.name}})=\\frac{${adjacent.name}}{${hypothenus.name}}`,
107
- `\\cos(\\widehat{${angle.value}})=\\frac{${adjacent.name}}{${hypothenus.length}}`,
108
- `${adjacent.name}=\\cos(\\widehat{${angle.value}})\\times${hypothenus.length}`,
109
- ];
110
- return result.concat(`${answer}=${adjacent.name}`);
111
- case opposite.name:
112
- result =
113
- randSide.name === adjacent.name
114
- ? [
115
- `\\tan(\\widehat{${angle.name}})=\\frac{${opposite.name}}{${adjacent.name}}`,
116
- `\\tan(\\widehat{${angle.value}})=\\frac{${opposite.name}}{${adjacent.length}}`,
117
- `${opposite.name}=\\tan(\\widehat{${angle.value}})*${adjacent.length}`,
118
- ]
119
- : [
120
- `\\sin(\\widehat{${angle.name}})=\\frac{${opposite.name}}{${hypothenus.name}}`,
121
- `\\sin(\\widehat{${angle.value}})=\\frac{${opposite.name}}{${hypothenus.length}}`,
122
- `${opposite.name}=\\sin(\\widehat{${angle.value}})\\times${hypothenus.length}`,
123
- ];
124
- return result.concat(`${answer}=${opposite.name}`);
125
- case hypothenus.name:
126
- result =
127
- randSide.name === adjacent.name
128
- ? [
129
- `\\cos(\\widehat{${angle.name}})=\\frac{${adjacent.name}}{${hypothenus.name}}`,
130
- `\\cos(\\widehat{${angle.value}})=\\frac{${adjacent.length}}{${hypothenus.name}}`,
131
- `${hypothenus.name}=\\frac{${adjacent.length}}{\\cos(${angle.value})}`,
132
- ]
133
- : [
134
- `\\sin(\\widehat{${angle.name}})=\\frac{${opposite.name}}{${hypothenus.name}}`,
135
- `\\sin(\\widehat{${angle.value}})=\\frac{${opposite.length}}{${hypothenus.name}}`,
136
- `${hypothenus.name}=\\frac{${opposite.length}}{\\sin(${angle.value})}`,
137
- ];
138
- return result.concat(`${hypothenus.name}=${answer}`);
139
- default:
140
- return [];
81
+ const getCorrection = (identifiers) => {
82
+ const { givenAngle, givenSide, sideAsked, triangleIdentifiers } = identifiers;
83
+ //sohcahtoa
84
+ //
85
+ const triangle = RightTriangleConstructor.fromIdentifiers(triangleIdentifiers);
86
+ const angle = triangle.angles[givenAngle];
87
+ const hypoSegment = triangle.sides[0];
88
+ const adjacentSegment = triangle.sides[3 - givenAngle];
89
+ const oppositeSegment = triangle.sides[givenAngle];
90
+ const angleValue = angle.evaluate().frenchify();
91
+ const sideAskedType = sideAsked === 0
92
+ ? "hypoténuse"
93
+ : sideAsked === givenAngle
94
+ ? "opposé"
95
+ : "adjacent";
96
+ const sideGivenType = givenSide === 0
97
+ ? "hypoténuse"
98
+ : givenSide === givenAngle
99
+ ? "opposé"
100
+ : "adjacent";
101
+ const fcts = [
102
+ {
103
+ id: "cos",
104
+ name: "le cosinus",
105
+ frac: "\\frac{\\text{adjacent}}{\\text{hypoténuse}}",
106
+ },
107
+ {
108
+ id: "sin",
109
+ name: "le sinus",
110
+ frac: "\\frac{\\text{opposé}}{\\text{hypoténuse}}",
111
+ },
112
+ {
113
+ id: "tan",
114
+ name: "la tangente",
115
+ frac: "\\frac{\\text{opposé}}{\\text{adjacent}}",
116
+ },
117
+ ];
118
+ const sidesProps = [
119
+ {
120
+ id: "adjacent",
121
+ name: "le côté adjacent",
122
+ tex: adjacentSegment.toTex(),
123
+ insideTex: adjacentSegment.toInsideName(),
124
+ value: sideGivenType === "adjacent"
125
+ ? adjacentSegment.getLength().frenchify()
126
+ : adjacentSegment.toInsideName(),
127
+ },
128
+ {
129
+ id: "opposé",
130
+ name: "le côté opposé",
131
+ tex: oppositeSegment.toTex(),
132
+ insideTex: oppositeSegment.toInsideName(),
133
+ value: sideGivenType === "opposé"
134
+ ? oppositeSegment.getLength().frenchify()
135
+ : oppositeSegment.toInsideName(),
136
+ },
137
+ {
138
+ id: "hypoténuse",
139
+ name: "l'hypoténuse",
140
+ tex: hypoSegment.toTex(),
141
+ insideTex: hypoSegment.toInsideName(),
142
+ value: sideGivenType === "hypoténuse"
143
+ ? hypoSegment.getLength().frenchify()
144
+ : hypoSegment.toInsideName(),
145
+ },
146
+ ];
147
+ let fct;
148
+ let sides;
149
+ switch (sideAskedType) {
150
+ case "hypoténuse":
151
+ if (sideGivenType === "adjacent") {
152
+ fct = fcts[0];
153
+ sides = [sidesProps[2], sidesProps[0]];
154
+ }
155
+ else {
156
+ fct = fcts[1];
157
+ sides = [sidesProps[2], sidesProps[1]];
158
+ }
159
+ break;
160
+ case "adjacent":
161
+ if (sideGivenType === "opposé") {
162
+ fct = fcts[2];
163
+ sides = [sidesProps[0], sidesProps[1]];
164
+ }
165
+ else {
166
+ fct = fcts[0];
167
+ sides = [sidesProps[0], sidesProps[2]];
168
+ }
169
+ break;
170
+ case "opposé":
171
+ if (sideGivenType === "adjacent") {
172
+ fct = fcts[2];
173
+ sides = [sidesProps[1], sidesProps[0]];
174
+ }
175
+ else {
176
+ fct = fcts[1];
177
+ sides = [sidesProps[1], sidesProps[2]];
178
+ }
179
+ break;
141
180
  }
181
+ let isDenumeratorAsked = sideAskedType === "hypoténuse" ||
182
+ (sideAskedType === "adjacent" && sideGivenType === "opposé");
183
+ return `Dans le triangle $${triangle.name}$ rectangle en $${triangle.points[0].name}$, par rapport à l'angle $${angle.toTex()}$, $${sides[0].tex}$ est ${sides[0].name} et $${sides[1].tex}$ est ${sides[1].name}.
184
+
185
+ Pour trouver $${sides[0].insideTex}$, on peut donc utiliser ${fct.name} de l'angle $${angle.toTex()}$. En effet, on a :
186
+
187
+ $$
188
+ \\${fct.id}(${angle.toTex()}) = ${fct.frac}
189
+ $$
190
+
191
+ donc
192
+
193
+ $$
194
+ \\${fct.id}(${angleValue}) = \\frac{${sides[isDenumeratorAsked ? 1 : 0].insideTex}}{${sides[isDenumeratorAsked ? 0 : 1].insideTex}} = \\frac{${sides[isDenumeratorAsked ? 1 : 0].value}}{${sides[isDenumeratorAsked ? 0 : 1].value}}
195
+ $$
196
+
197
+ Ainsi,
198
+
199
+ $$
200
+ ${isDenumeratorAsked
201
+ ? `${sides[0].insideTex} = \\frac{${sides[1].value}}{\\${fct.id}(${angleValue})}`
202
+ : `${sides[0].insideTex} = \\${fct.id}(${angleValue}) \\times ${sides[1].value}`} \\approx ${getAnswer(identifiers)}\\text{ cm}
203
+ $$`;
142
204
  };
143
205
  const isAnswerValid = (ans, { answer }) => {
144
- const answerTree = new NumberNode(Number(answer.replace(",", ".")));
145
- const texs = answerTree.toAllValidTexs();
146
- return texs.includes(ans);
206
+ return numberVEA(ans, answer, 1);
147
207
  };
148
208
  export const trigonometrySideCalcul = {
149
209
  id: "trigonometrySideCalcul",
150
210
  connector: "=",
151
211
  label: "Utiliser la trigonométrie pour calculer un côté",
152
- levels: ["4ème", "3ème", "2nde"],
153
212
  isSingleStep: false,
154
- sections: ["Trigonométrie", "Géométrie euclidienne"],
155
213
  generator: (nb) => getDistinctQuestions(getTrigonometrySideCalcul, nb),
156
214
  qcmTimer: 60,
157
215
  freeTimer: 60,
@@ -159,4 +217,10 @@ export const trigonometrySideCalcul = {
159
217
  isAnswerValid,
160
218
  hasGeogebra: true,
161
219
  subject: "Mathématiques",
220
+ getInstruction,
221
+ getAnswer,
222
+ getHint,
223
+ getGGBOptions,
224
+ getCorrection,
225
+ hasHintAndCorrection: true,
162
226
  };
@@ -1,2 +1,2 @@
1
- export declare const numberVEA: (studentAns: string, answer: string) => boolean;
1
+ export declare const numberVEA: (studentAns: string, answer: string, roundTo?: number) => boolean;
2
2
  //# sourceMappingURL=numberVEA.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"numberVEA.d.ts","sourceRoot":"","sources":["../../../src/exercises/vea/numberVEA.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,eAAgB,MAAM,UAAU,MAAM,YAI3D,CAAC"}
1
+ {"version":3,"file":"numberVEA.d.ts","sourceRoot":"","sources":["../../../src/exercises/vea/numberVEA.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,eACR,MAAM,UACV,MAAM,YACJ,MAAM,YAKjB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { numberParser } from "../../tree/parsers/numberParser.js";
2
- export const numberVEA = (studentAns, answer) => {
3
- const parsed = numberParser(studentAns);
2
+ export const numberVEA = (studentAns, answer, roundTo) => {
3
+ const parsed = numberParser(studentAns, roundTo);
4
4
  if (!parsed)
5
5
  return false;
6
6
  return parsed === answer;
package/lib/index.d.ts CHANGED
@@ -691,8 +691,8 @@ declare const mathExercises: (Exercise<{
691
691
  }, {
692
692
  curveTypes: string[];
693
693
  }> | Exercise<{
694
- poly1: number[];
695
- xValue: number;
694
+ coeffs: number[];
695
+ yValue: number;
696
696
  }, {}> | Exercise<{
697
697
  yValue: number;
698
698
  points: number[][];
@@ -1,3 +1,4 @@
1
+ import { AlgebraicNode } from "../../tree/nodes/algebraicNode.js";
1
2
  import { Nombre } from "../numbers/nombre.js";
2
3
  import { Polynomial } from "./polynomial.js";
3
4
  import { Trinom } from "./trinom.js";
@@ -28,6 +29,7 @@ export declare class Affine extends Polynomial {
28
29
  variable: string;
29
30
  constructor(a: number, b: number, variable?: string);
30
31
  getRoot(): Nombre;
32
+ solve(y: AlgebraicNode | number): AlgebraicNode;
31
33
  square(): Trinom;
32
34
  times(n: number): Affine;
33
35
  toString(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"affine.d.ts","sourceRoot":"","sources":["../../../src/math/polynomials/affine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM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CAAC,EAAE,aAAa,GAAG,MAAM;IAG/B,MAAM,IAAI,MAAM;IAMhB,KAAK,CAAC,CAAC,EAAE,MAAM;IAIf,QAAQ,IAAI,MAAM;IAIlB,iBAAiB,IAAI,MAAM;IAI3B,aAAa;CAGd"}
@@ -1,4 +1,6 @@
1
1
  import { randomColor } from "../../geogebra/colors.js";
2
+ import { frac } from "../../tree/nodes/operators/fractionNode.js";
3
+ import { substract } from "../../tree/nodes/operators/substractNode.js";
2
4
  import { Rational } from "../numbers/rationals/rational.js";
3
5
  import { randint } from "../utils/random/randint.js";
4
6
  import { Polynomial } from "./polynomial.js";
@@ -37,6 +39,9 @@ export class Affine extends Polynomial {
37
39
  getRoot() {
38
40
  return new Rational(-this.b, this.a).simplify();
39
41
  }
42
+ solve(y) {
43
+ return frac(substract(y, this.b), this.a).simplify();
44
+ }
40
45
  square() {
41
46
  return new Trinom(this.a ** 2, 2 * this.a * this.b, this.b ** 2, {
42
47
  variable: this.variable,
@@ -1,4 +1,3 @@
1
- import { Affine } from "../../../math/polynomials/affine.js";
2
1
  import { AlgebraicNode } from "../algebraicNode.js";
3
2
  import { Node, NodeIds, NodeOptions, NodeType } from "../node.js";
4
3
  import { NodeIdentifiers } from "../nodeConstructor.js";
@@ -28,5 +27,5 @@ export declare class EqualNode implements Node {
28
27
  shuffle(): EqualNode;
29
28
  reverse(): EqualNode;
30
29
  }
31
- export declare const firstDegreeEquationResolutionTex: (affineLeft: Affine, affineRight: Affine) => void;
30
+ export declare const equationResolutionTex: (a: AlgebraicNode, b: AlgebraicNode, c: AlgebraicNode, d: AlgebraicNode) => string | string[];
32
31
  //# sourceMappingURL=equalNode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"equalNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/equations/equalNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CA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lip.js";
2
+ import { alignTex } from "../../../utils/latex/alignTex.js";
2
3
  import { NodeIds, NodeType } from "../node.js";
3
4
  import { NodeConstructor } from "../nodeConstructor.js";
5
+ import { add } from "../operators/addNode.js";
6
+ import { frac } from "../operators/fractionNode.js";
7
+ import { multiply } from "../operators/multiplyNode.js";
8
+ import { substract } from "../operators/substractNode.js";
9
+ import { monom } from "../polynomials/monomNode.js";
4
10
  export const equal = (a, b) => {
5
11
  const nodeA = typeof a === "number" ? a.toTree() : typeof a === "string" ? a.toTree() : a;
6
12
  const nodeB = typeof b === "number" ? b.toTree() : typeof b === "string" ? b.toTree() : b;
@@ -67,26 +73,45 @@ export class EqualNode {
67
73
  return new EqualNode(this.rightChild, this.leftChild, this.opts);
68
74
  }
69
75
  }
70
- export const firstDegreeEquationResolutionTex = (affineLeft, affineRight) => {
71
- //ax(+-b) = (+-c)(x)(+-d)
72
- // const b = affine.b;
73
- // const a = affine.a;
74
- // if (a === 1 && b === 0)
75
- // return new InequationNode([affine.toTree(), right], [order]).toTex();
76
- // const steps: string[][] = [[affine.toTex(), order, right.toTex()]];
77
- // if (b !== 0)
78
- // steps.push([
79
- // affine.add(-b).toTex(),
80
- // order,
81
- // substract(right, b).simplify().toTex(),
82
- // ]);
83
- // if (a !== 1) {
84
- // if (a < 0) order = new InequationSymbol(order).reversed();
85
- // steps.push([
86
- // affine.variable,
87
- // order,
88
- // frac(substract(right, b), a).simplify().toTex(),
89
- // ]);
90
- // }
91
- // return alignTex(steps, true);
76
+ export const equationResolutionTex = (a, b, c, d) => {
77
+ //(+-a)x(+-b) = (+-c)x(+-d)
78
+ const steps = [];
79
+ const iteration = (a, b, c, d) => {
80
+ const aEv = a.evaluate();
81
+ const bEv = b.evaluate();
82
+ const cEv = c.evaluate();
83
+ if (bEv === 0) {
84
+ if (cEv === 0) {
85
+ //ax = d
86
+ if (aEv === 1) {
87
+ //x = d
88
+ steps.push(`x=${d.toTex()}`);
89
+ return;
90
+ }
91
+ else {
92
+ //ax = d
93
+ steps.push(`${multiply(a, "x").toTex()}=${d.toTex()}`);
94
+ iteration((1).toTree(), (0).toTree(), (0).toTree(), frac(d, a).simplify());
95
+ }
96
+ }
97
+ else {
98
+ steps.push(`${monom(a, 1).toTex()}=${add(monom(c, 1), d).toTex()}`);
99
+ //ax = c!x + d
100
+ iteration(substract(a, c).simplify(), (0).toTree(), (0).toTree(), d);
101
+ }
102
+ }
103
+ else {
104
+ //ax + b! = cx + d
105
+ steps.push(`${add(multiply(a, "x"), b).simplify().toTex()}=${add(multiply(c, "x"), d)
106
+ .simplify()
107
+ .toTex()}`);
108
+ iteration(a, (0).toTree(), c, substract(d, b).simplify());
109
+ }
110
+ };
111
+ iteration(a, b, c, d);
112
+ if (steps.length === 1) {
113
+ return steps[0];
114
+ }
115
+ return alignTex(steps.map((e) => [e.split("=")[0], "=", e.split("=")[1]]), true);
116
+ return steps;
92
117
  };
@@ -1,2 +1,2 @@
1
- export declare const numberParser: (ans: string) => string | false;
1
+ export declare const numberParser: (ans: string, roundTo?: number) => string | false;
2
2
  //# sourceMappingURL=numberParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"numberParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/numberParser.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,QAAS,MAAM,mBAIvC,CAAC"}
1
+ {"version":3,"file":"numberParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/numberParser.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,QAAS,MAAM,YAAY,MAAM,mBAKzD,CAAC"}
@@ -1,7 +1,10 @@
1
+ import { round } from "../../math/utils/round.js";
1
2
  //returns false if ans is NaN (even in french form) and returns the frenchified form otherwise
2
- export const numberParser = (ans) => {
3
+ export const numberParser = (ans, roundTo) => {
3
4
  const nb = ans.unfrenchify();
4
5
  if (isNaN(nb))
5
6
  return false;
7
+ if (roundTo !== undefined)
8
+ return round(nb, roundTo).frenchify();
6
9
  return nb.frenchify();
7
10
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.11",
4
+ "version": "3.0.12",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [