math-exercises 2.2.65 → 2.2.66

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 (47) hide show
  1. package/lib/exercises/math/calcul/fractions/fractionsSum.d.ts.map +1 -1
  2. package/lib/exercises/math/calcul/fractions/fractionsSumsMultiplesDenominators.d.ts.map +1 -1
  3. package/lib/exercises/math/calcul/fractions/fractionsSumsPrimeDenominators.d.ts.map +1 -1
  4. package/lib/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.d.ts.map +1 -1
  5. package/lib/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.js +8 -3
  6. package/lib/exercises/math/calculLitteral/distributivity/firstIdentity.js +1 -1
  7. package/lib/exercises/math/calculLitteral/equation/choseOperationToSolveEquation.d.ts +1 -0
  8. package/lib/exercises/math/calculLitteral/equation/choseOperationToSolveEquation.d.ts.map +1 -0
  9. package/lib/exercises/math/calculLitteral/equation/choseOperationToSolveEquation.js +122 -0
  10. package/lib/exercises/math/calculLitteral/equation/equationType2Exercise.d.ts +9 -3
  11. package/lib/exercises/math/calculLitteral/equation/equationType2Exercise.d.ts.map +1 -1
  12. package/lib/exercises/math/calculLitteral/equation/equationType2Exercise.js +64 -17
  13. package/lib/exercises/math/functions/affines/algebricExpressionOfAffine.js +1 -1
  14. package/lib/exercises/math/functions/trinoms/coefficientsIdentification.d.ts.map +1 -1
  15. package/lib/exercises/math/functions/trinoms/coefficientsIdentification.js +8 -3
  16. package/lib/exercises/math/geometry/cartesian/drawAlineInGGB.d.ts.map +1 -1
  17. package/lib/exercises/math/geometry/cartesian/drawAlineInGGB.js +1 -2
  18. package/lib/exercises/math/geometry/cartesian/placeAPoint.d.ts.map +1 -1
  19. package/lib/exercises/math/geometry/cartesian/placeAPoint.js +1 -2
  20. package/lib/exercises/math/geometry/euclidianConstructions/buildMediatriceWithCompass.d.ts.map +1 -1
  21. package/lib/exercises/math/geometry/euclidianConstructions/buildMediatriceWithCompass.js +1 -2
  22. package/lib/exercises/math/geometry/vectors/drawAVectorInGGB.d.ts.map +1 -1
  23. package/lib/exercises/math/geometry/vectors/drawAVectorInGGB.js +1 -2
  24. package/lib/exercises/math/squareRoots/squareRootIdentities.d.ts.map +1 -1
  25. package/lib/exercises/math/squareRoots/squareRootIdentities.js +5 -1
  26. package/lib/exercises/math/squareRoots/squareRootsDistributivity.d.ts.map +1 -1
  27. package/lib/exercises/math/squareRoots/squareRootsDistributivity.js +5 -1
  28. package/lib/exercises/pc/calibrationCurveOfSolution.d.ts.map +1 -1
  29. package/lib/exercises/pc/calibrationCurveOfSolution.js +1 -2
  30. package/lib/exercises/vea/rationalVEA.d.ts.map +1 -1
  31. package/lib/exercises/vea/rationalVEA.js +7 -2
  32. package/lib/index.d.ts +14 -6
  33. package/lib/index.d.ts.map +1 -1
  34. package/lib/math/polynomials/generalAffine.d.ts +10 -0
  35. package/lib/math/polynomials/generalAffine.d.ts.map +1 -0
  36. package/lib/math/polynomials/generalAffine.js +32 -0
  37. package/lib/playground.js +1 -1
  38. package/lib/tree/nodes/equations/equalNode.d.ts +13 -9
  39. package/lib/tree/nodes/equations/equalNode.d.ts.map +1 -1
  40. package/lib/tree/nodes/equations/equalNode.js +17 -1
  41. package/lib/tree/nodes/inequations/inequationSolutionNode.d.ts +1 -1
  42. package/lib/tree/parsers/affineParser.d.ts.map +1 -1
  43. package/lib/tree/parsers/affineParser.js +17 -12
  44. package/lib/tree/parsers/latexParser.d.ts +1 -1
  45. package/lib/tree/parsers/latexParser.d.ts.map +1 -1
  46. package/lib/tree/parsers/latexParser.js +34 -9
  47. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"fractionsSum.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/fractions/fractionsSum.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,0BAA0B,CAAC;AAWlC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAyGF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAgBvD,CAAC"}
1
+ {"version":3,"file":"fractionsSum.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/fractions/fractionsSum.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,0BAA0B,CAAC;AAUlC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAyGF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAgBvD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fractionsSumsMultiplesDenominators.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/fractions/fractionsSumsMultiplesDenominators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,0BAA0B,CAAC;AAYlC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA2FF,eAAO,MAAM,kCAAkC,EAAE,QAAQ,CAAC,WAAW,CAkBpE,CAAC"}
1
+ {"version":3,"file":"fractionsSumsMultiplesDenominators.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/fractions/fractionsSumsMultiplesDenominators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,0BAA0B,CAAC;AAWlC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA2FF,eAAO,MAAM,kCAAkC,EAAE,QAAQ,CAAC,WAAW,CAkBpE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fractionsSumsPrimeDenominators.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/fractions/fractionsSumsPrimeDenominators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,0BAA0B,CAAC;AAYlC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA6FF,eAAO,MAAM,8BAA8B,EAAE,QAAQ,CAAC,WAAW,CAkBhE,CAAC"}
1
+ {"version":3,"file":"fractionsSumsPrimeDenominators.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/fractions/fractionsSumsPrimeDenominators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,0BAA0B,CAAC;AAWlC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA6FF,eAAO,MAAM,8BAA8B,EAAE,QAAQ,CAAC,WAAW,CAkBhE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findCoeffInProportionalTableNonIntegers.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAiBT,MAAM,0BAA0B,CAAC;AAiBlC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAqHF,KAAK,OAAO,GAAG;IACb,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B,CAAC;AAoBF,eAAO,MAAM,uCAAuC,EAAE,QAAQ,CAC5D,WAAW,EACX,OAAO,CAsBR,CAAC"}
1
+ {"version":3,"file":"findCoeffInProportionalTableNonIntegers.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAiBT,MAAM,0BAA0B,CAAC;AAiBlC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAyHF,KAAK,OAAO,GAAG;IACb,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B,CAAC;AAoBF,eAAO,MAAM,uCAAuC,EAAE,QAAQ,CAC5D,WAAW,EACX,OAAO,CAsBR,CAAC"}
@@ -51,10 +51,15 @@ const getKeys = (identifiers) => {
51
51
  return [];
52
52
  };
53
53
  const isAnswerValid = (ans, { answer }) => {
54
- const parsed = (0, latexParser_1.parseAlgebraic)(ans);
55
- if (!parsed)
54
+ try {
55
+ const parsed = (0, latexParser_1.parseAlgebraic)(ans);
56
+ if (!parsed)
57
+ return false;
58
+ return parsed.simplify().toTex() === answer;
59
+ }
60
+ catch (err) {
56
61
  return false;
57
- return parsed.simplify().toTex() === answer;
62
+ }
58
63
  };
59
64
  const getFindCoeffInProportionalTableNonIntegersQuestion = (opts) => {
60
65
  let coeff;
@@ -30,7 +30,7 @@ const getFirstIdentityQuestion = () => {
30
30
  keys: ["x"],
31
31
  answerFormat: "tex",
32
32
  identifiers: { a: affine.a, b: affine.b },
33
- hint: `Utilise l'identité remarquable
33
+ hint: `Utilise l'identité remarquable :
34
34
 
35
35
  $$
36
36
  (a+b)^2 = a^2 + 2ab+b^2
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=choseOperationToSolveEquation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choseOperationToSolveEquation.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/equation/choseOperationToSolveEquation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ // import {
3
+ // Exercise,
4
+ // Proposition,
5
+ // QCMGenerator,
6
+ // Question,
7
+ // QuestionGenerator,
8
+ // VEA,
9
+ // addValidProp,
10
+ // shuffleProps,
11
+ // GetAnswer,
12
+ // GetHint,
13
+ // GetCorrection,
14
+ // GetInstruction,
15
+ // GetKeys,
16
+ // tryToAddWrongProp,
17
+ // } from "../../../../exercises/exercise";
18
+ // import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions";
19
+ // import { randint } from "../../../../math/utils/random/randint";
20
+ // import {
21
+ // EqualNode,
22
+ // EqualNodeConstructor,
23
+ // EqualNodeIdentifiers,
24
+ // } from "../../../../tree/nodes/equations/equalNode";
25
+ // import {
26
+ // NodeConstructor,
27
+ // NodeIdentifiers,
28
+ // } from "../../../../tree/nodes/nodeConstructor";
29
+ // type Identifiers = {
30
+ // equaIdentifiers: EqualNodeIdentifiers;
31
+ // };
32
+ // const getPropositions: QCMGenerator<Identifiers> = (n, { answer }) => {
33
+ // const propositions: Proposition[] = [];
34
+ // addValidProp(propositions, answer);
35
+ // tryToAddWrongProp(propositions, "une soustraction", "raw");
36
+ // tryToAddWrongProp(propositions, "une addition", "raw");
37
+ // tryToAddWrongProp(propositions, "une division", "raw");
38
+ // tryToAddWrongProp(propositions, "une multiplication", "raw");
39
+ // return shuffleProps(propositions, n);
40
+ // };
41
+ // const getAnswer: GetAnswer<Identifiers> = (identifiers) => {
42
+ // return;
43
+ // };
44
+ // const getInstruction: GetInstruction<Identifiers> = (identifiers) => {
45
+ // const equation = EqualNodeConstructor.fromIdentifiers(
46
+ // identifiers.equaIdentifiers,
47
+ // );
48
+ // return `Pour résoudre l'équation :
49
+ // $$
50
+ // ${equation.toTex()}
51
+ // $$
52
+ // il faut d'abord effectuer :
53
+ // `;
54
+ // };
55
+ // // const getHint: GetHint<Identifiers> = (identifiers) => {};
56
+ // // const getCorrection: GetCorrection<Identifiers> = (identifiers) => {};
57
+ // const getKeys: GetKeys<Identifiers> = (identifiers) => {
58
+ // return [];
59
+ // };
60
+ // const isAnswerValid: VEA<Identifiers> = (ans, { answer }) => {
61
+ // throw Error("VEA not implemented");
62
+ // };
63
+ // const getChoseOperationToSolveEquationQuestion: QuestionGenerator<
64
+ // Identifiers
65
+ // > = (ops) => {
66
+ // //ax=b avec a entier, ax+b = c tout entier, x/a = b tout entier, x+-a = b entiers ,
67
+ // let a: number;
68
+ // let b: number;
69
+ // let c: number | undefined;
70
+ // const type = randint(1, 7);
71
+ // switch (type) {
72
+ // case 1:
73
+ // //ax = b tous entiers
74
+ // a = randint(-10);
75
+ // break;
76
+ // case 2:
77
+ // break;
78
+ // case 3:
79
+ // break;
80
+ // case 4:
81
+ // break;
82
+ // case 5:
83
+ // break;
84
+ // case 6:
85
+ // break;
86
+ // case 7:
87
+ // break;
88
+ // }
89
+ // const identifiers: Identifiers = {};
90
+ // const question: Question<Identifiers> = {
91
+ // answer: getAnswer(identifiers),
92
+ // instruction: getInstruction(identifiers),
93
+ // keys: getKeys(identifiers),
94
+ // answerFormat: "tex",
95
+ // identifiers,
96
+ // // hint: getHint(identifiers),
97
+ // // correction: getCorrection(identifiers),
98
+ // };
99
+ // return question;
100
+ // };
101
+ // export const choseOperationToSolveEquation: Exercise<Identifiers> = {
102
+ // id: "choseOperationToSolveEquation",
103
+ // connector: "=",
104
+ // label:
105
+ // "Choisir la bonne opération pour résoudre une équation du premier degré",
106
+ // isSingleStep: true,
107
+ // generator: (nb, opts) =>
108
+ // getDistinctQuestions(
109
+ // () => getChoseOperationToSolveEquationQuestion(opts),
110
+ // nb,
111
+ // ),
112
+ // qcmTimer: 60,
113
+ // freeTimer: 60,
114
+ // getPropositions,
115
+ // isAnswerValid,
116
+ // subject: "Mathématiques",
117
+ // getInstruction,
118
+ // // getHint,
119
+ // // getCorrection,
120
+ // getAnswer,
121
+ // answerType: "QCU",
122
+ // };
@@ -1,11 +1,17 @@
1
1
  import { Exercise } from "../../../../exercises/exercise";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor";
2
3
  /**
3
4
  * type ax=b
4
5
  */
5
6
  type Identifiers = {
6
- a: number;
7
- b: number;
7
+ a: NodeIdentifiers;
8
+ b: NodeIdentifiers;
9
+ isXRight: boolean;
10
+ aNumberType: string;
8
11
  };
9
- export declare const equationType2Exercise: Exercise<Identifiers>;
12
+ type Options = {
13
+ aNumberType: string[];
14
+ };
15
+ export declare const equationType2Exercise: Exercise<Identifiers, Options>;
10
16
  export {};
11
17
  //# sourceMappingURL=equationType2Exercise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"equationType2Exercise.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/equation/equationType2Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAQT,MAAM,0BAA0B,CAAC;AAiBlC;;GAEG;AACH,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAoEF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,CAevD,CAAC"}
1
+ {"version":3,"file":"equationType2Exercise.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/equation/equationType2Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,0BAA0B,CAAC;AAsBlC,OAAO,EAEL,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAK1C;;GAEG;AAGH,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,eAAe,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AA+GF,KAAK,OAAO,GAAG;IACb,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAaF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAiBhE,CAAC"}
@@ -5,7 +5,6 @@ const exercise_1 = require("../../../../exercises/exercise");
5
5
  const getDistinctQuestions_1 = require("../../../../exercises/utils/getDistinctQuestions");
6
6
  const equationKeys_1 = require("../../../../exercises/utils/keys/equationKeys");
7
7
  const rational_1 = require("../../../../math/numbers/rationals/rational");
8
- const affine_1 = require("../../../../math/polynomials/affine");
9
8
  const randint_1 = require("../../../../math/utils/random/randint");
10
9
  const equationSolutionNode_1 = require("../../../../tree/nodes/equations/equationSolutionNode");
11
10
  const equalNode_1 = require("../../../../tree/nodes/equations/equalNode");
@@ -14,30 +13,59 @@ const variableNode_1 = require("../../../../tree/nodes/variables/variableNode");
14
13
  const shuffle_1 = require("../../../../utils/alea/shuffle");
15
14
  const alignTex_1 = require("../../../../utils/latex/alignTex");
16
15
  const fractionNode_1 = require("../../../../tree/nodes/operators/fractionNode");
17
- const numberNode_1 = require("../../../../tree/nodes/numbers/numberNode");
18
- const getEquationType2ExerciseQuestion = () => {
19
- const b = (0, randint_1.randint)(-10, 11);
20
- const a = (0, randint_1.randint)(-9, 10, [0, 1]);
21
- const solution = new rational_1.Rational(b, a).simplify();
22
- const affine = new affine_1.Affine(a, 0).toTree();
23
- const tree = new equalNode_1.EqualNode(affine, b.toTree());
24
- const answer = new equalNode_1.EqualNode(new variableNode_1.VariableNode("x"), solution.toTree()).toTex();
16
+ const coinFlip_1 = require("../../../../utils/alea/coinFlip");
17
+ const random_1 = require("../../../../utils/alea/random");
18
+ const generalAffine_1 = require("../../../../math/polynomials/generalAffine");
19
+ const nodeConstructor_1 = require("../../../../tree/nodes/nodeConstructor");
20
+ const substractNode_1 = require("../../../../tree/nodes/operators/substractNode");
21
+ const addNode_1 = require("../../../../tree/nodes/operators/addNode");
22
+ const rebuildIdentifiers = (oldIdentifiers) => {
23
+ if (!!oldIdentifiers.numberType)
24
+ return oldIdentifiers;
25
+ return {
26
+ a: oldIdentifiers.a.toTree().toIdentifiers(),
27
+ b: oldIdentifiers.b.toTree().toIdentifiers(),
28
+ isXRight: false,
29
+ aNumberType: "Entier",
30
+ };
31
+ };
32
+ const getEquationType2ExerciseQuestion = (opts) => {
33
+ const types = opts?.aNumberType ?? ["Entier"];
34
+ const b = (0, randint_1.randint)(-10, 11).toTree();
35
+ const type = (0, random_1.random)(types);
36
+ const a = type === "Entier"
37
+ ? (0, randint_1.randint)(-9, 10, [0, 1]).toTree()
38
+ : rational_1.RationalConstructor.randomIrreductibleWithSign().toTree();
39
+ const solution = (0, fractionNode_1.frac)(b, a).simplify();
40
+ const affine = new generalAffine_1.GeneralAffine(a, 0).toTree();
41
+ const isXRight = (0, coinFlip_1.coinFlip)();
42
+ const equalTree = new equalNode_1.EqualNode(affine, b);
43
+ const tree = isXRight ? equalTree.reverse() : equalTree;
44
+ const answer = new equalNode_1.EqualNode(new variableNode_1.VariableNode("x"), solution).toTex();
25
45
  const statementTex = tree.toTex();
46
+ const identifiers = {
47
+ a: a.toIdentifiers(),
48
+ b: b.toIdentifiers(),
49
+ isXRight,
50
+ aNumberType: type,
51
+ };
26
52
  const question = {
27
53
  instruction: `Résoudre : $${statementTex}$`,
28
54
  startStatement: statementTex,
29
55
  answer,
30
56
  keys: equationKeys_1.equationKeys,
31
57
  answerFormat: "tex",
32
- identifiers: { a, b: b },
33
- hint: `Il faut isoler $x$ à gauche. Pour cela, effectue l'opération des deux côtés de l'équation qui permet de supprimer la multiplication par $${a}$.`,
34
- correction: `Pour isoler $x$ à gauche, on divise les deux côtés de l'équation par $${a}$:
58
+ identifiers: identifiers,
59
+ hint: `Il faut isoler $x$ à ${isXRight ? "droite" : "gauche"}. Pour cela, effectue l'opération des deux côtés de l'équation qui permet de supprimer la multiplication par $${a.toTex()}$.`,
60
+ correction: `Pour isoler $x$ à ${isXRight ? "droite" : "gauche"}, on divise les deux côtés de l'équation par $${a.toTex()}$ :
35
61
 
36
62
  ${(0, alignTex_1.alignTex)([
37
63
  [
38
64
  `${statementTex}`,
39
65
  "\\iff",
40
- new equalNode_1.EqualNode(new fractionNode_1.FractionNode(affine, new numberNode_1.NumberNode(a)), new fractionNode_1.FractionNode(b.toTree(), new numberNode_1.NumberNode(a))).toTex(),
66
+ isXRight
67
+ ? (0, equalNode_1.equal)((0, fractionNode_1.frac)(b, a), (0, fractionNode_1.frac)(affine, a)).toTex()
68
+ : (0, equalNode_1.equal)((0, fractionNode_1.frac)(affine, a), (0, fractionNode_1.frac)(b, a)).toTex(),
41
69
  ],
42
70
  ["", "\\iff", answer],
43
71
  ])}
@@ -46,22 +74,39 @@ ${(0, alignTex_1.alignTex)([
46
74
  return question;
47
75
  };
48
76
  const getPropositions = (n, { answer, a, b }) => {
77
+ const aNode = nodeConstructor_1.NodeConstructor.fromIdentifiers(a);
78
+ const bNode = nodeConstructor_1.NodeConstructor.fromIdentifiers(b);
49
79
  const propositions = [];
50
80
  (0, exercise_1.addValidProp)(propositions, answer);
81
+ (0, exercise_1.tryToAddWrongProp)(propositions, (0, substractNode_1.substract)(bNode, aNode).simplify().toTex());
51
82
  while (propositions.length < n) {
52
- const wrongAnswer = new rational_1.Rational(b + (0, randint_1.randint)(-7, 8, [0, -b]), a + (0, randint_1.randint)(-7, 8, [-a, 0])).simplify();
53
- (0, exercise_1.tryToAddWrongProp)(propositions, new equalNode_1.EqualNode(new variableNode_1.VariableNode("x"), wrongAnswer.toTree()).toTex());
83
+ const bEv = (0, randint_1.randint)(-7, 8, [0, -bNode.evaluate()]);
84
+ const a = (0, addNode_1.add)(aNode, (0, randint_1.randint)(-7, 8, [-aNode.evaluate(), 0]));
85
+ const wrongAnswer = (0, fractionNode_1.frac)(bEv, a).simplify();
86
+ (0, exercise_1.tryToAddWrongProp)(propositions, new equalNode_1.EqualNode(new variableNode_1.VariableNode("x"), wrongAnswer).toTex());
54
87
  }
55
88
  return (0, shuffle_1.shuffle)(propositions);
56
89
  };
57
90
  const isAnswerValid = (ans, { a, b }) => {
58
- const solution = new rational_1.Rational(b, a).simplify().toTree();
91
+ const aNode = nodeConstructor_1.NodeConstructor.fromIdentifiers(a);
92
+ const bNode = nodeConstructor_1.NodeConstructor.fromIdentifiers(b);
93
+ const solution = (0, fractionNode_1.frac)(bNode, aNode).simplify();
59
94
  const answerTree = new equationSolutionNode_1.EquationSolutionNode(new discreteSetNode_1.DiscreteSetNode([solution]), {
60
95
  opts: { allowFractionToDecimal: true, allowRawRightChildAsSolution: true },
61
96
  });
62
97
  const validLatexs = answerTree.toAllValidTexs();
63
98
  return validLatexs.includes(ans);
64
99
  };
100
+ const options = [
101
+ {
102
+ id: "aNumberType",
103
+ label: "Autoriser des fractions pour $a$",
104
+ target: exercise_1.GeneratorOptionTarget.generation,
105
+ type: exercise_1.GeneratorOptionType.multiselect,
106
+ defaultValue: ["Entier"],
107
+ values: ["Entier", "Rationnel"],
108
+ },
109
+ ];
65
110
  exports.equationType2Exercise = {
66
111
  id: "equa2",
67
112
  connector: "\\iff",
@@ -69,11 +114,13 @@ exports.equationType2Exercise = {
69
114
  levels: ["4ème", "3ème", "2nde", "CAP", "2ndPro", "1rePro", "1reTech"],
70
115
  sections: ["Équations"],
71
116
  isSingleStep: true,
72
- generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getEquationType2ExerciseQuestion, nb),
117
+ generator: (nb, opts) => (0, getDistinctQuestions_1.getDistinctQuestions)(() => getEquationType2ExerciseQuestion(opts), nb),
73
118
  qcmTimer: 60,
74
119
  freeTimer: 60,
75
120
  getPropositions,
76
121
  isAnswerValid,
77
122
  subject: "Mathématiques",
78
123
  hasHintAndCorrection: true,
124
+ options,
125
+ rebuildIdentifiers,
79
126
  };
@@ -12,7 +12,7 @@ const getAlgebricExpressionOfAffineQuestion = () => {
12
12
  const question = {
13
13
  answer: f.toTex(),
14
14
  instruction: `Soit une fonction affine $f$ dont le coefficient directeur vaut $${a}$ et l'ordonnée à l'origine vaut $${b}$. Écrire l'expression algébrique de $f(x)$.`,
15
- keys: ["x", "equal"],
15
+ keys: ["x"],
16
16
  answerFormat: "tex",
17
17
  identifiers: { a, b },
18
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"coefficientsIdentification.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/trinoms/coefficientsIdentification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAEL,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAO1C,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,eAAe,CAAC;IAC9B,YAAY,EAAE,eAAe,CAAC;IAC9B,YAAY,EAAE,eAAe,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAmIF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAgB5D,CAAC"}
1
+ {"version":3,"file":"coefficientsIdentification.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/functions/trinoms/coefficientsIdentification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAEL,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAO1C,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,eAAe,CAAC;IAC9B,YAAY,EAAE,eAAe,CAAC;IAC9B,YAAY,EAAE,eAAe,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAuIF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAgB5D,CAAC"}
@@ -72,10 +72,15 @@ const getKeys = (identifiers) => {
72
72
  return [];
73
73
  };
74
74
  const isAnswerValid = (ans, { answer }) => {
75
- const parsed = (0, latexParser_1.parseAlgebraic)(ans);
76
- if (!parsed)
75
+ try {
76
+ const parsed = (0, latexParser_1.parseAlgebraic)(ans);
77
+ if (!parsed)
78
+ return false;
79
+ return parsed.simplify().toTex() === answer;
80
+ }
81
+ catch (err) {
77
82
  return false;
78
- return parsed.simplify().toTex() === answer;
83
+ }
79
84
  };
80
85
  const getCoefficientsIdentificationQuestion = () => {
81
86
  const a = (0, random_1.random)([
@@ -1 +1 @@
1
- {"version":3,"file":"drawAlineInGGB.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/cartesian/drawAlineInGGB.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIT,MAAM,0BAA0B,CAAC;AAWlC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA2DF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAahD,CAAC"}
1
+ {"version":3,"file":"drawAlineInGGB.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/cartesian/drawAlineInGGB.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIT,MAAM,0BAA0B,CAAC;AAWlC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA2DF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAYhD,CAAC"}
@@ -64,8 +64,7 @@ exports.drawAlineInGGB = {
64
64
  answerType: "GGB",
65
65
  sections: ["Géométrie cartésienne"],
66
66
  generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getDrawAlineInGgbQuestion, nb),
67
- qcmTimer: 60,
68
- freeTimer: 60,
67
+ ggbTimer: 60,
69
68
  isGGBAnswerValid,
70
69
  subject: "Mathématiques",
71
70
  };
@@ -1 +1 @@
1
- {"version":3,"file":"placeAPoint.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/cartesian/placeAPoint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIT,MAAM,0BAA0B,CAAC;AAUlC,KAAK,WAAW,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA+B5C,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,WAAW,CAY/C,CAAC"}
1
+ {"version":3,"file":"placeAPoint.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/cartesian/placeAPoint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIT,MAAM,0BAA0B,CAAC;AAUlC,KAAK,WAAW,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA+B5C,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,WAAW,CAW/C,CAAC"}
@@ -40,8 +40,7 @@ exports.testGGBAnswer = {
40
40
  sections: ["Géométrie euclidienne"],
41
41
  generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getPlaceAPointQuestion, nb),
42
42
  answerType: "GGB",
43
- qcmTimer: 60,
44
- freeTimer: 60,
43
+ ggbTimer: 60,
45
44
  isGGBAnswerValid,
46
45
  subject: "Mathématiques",
47
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"buildMediatriceWithCompass.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/euclidianConstructions/buildMediatriceWithCompass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAUT,MAAM,0BAA0B,CAAC;AAalC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,CAAC,EAAE,MAAM,EAAE,CAAC;CACb,CAAC;AAsGF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAe5D,CAAC"}
1
+ {"version":3,"file":"buildMediatriceWithCompass.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/euclidianConstructions/buildMediatriceWithCompass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAUT,MAAM,0BAA0B,CAAC;AAalC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,CAAC,EAAE,MAAM,EAAE,CAAC;CACb,CAAC;AAsGF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAc5D,CAAC"}
@@ -108,8 +108,7 @@ exports.buildMediatriceWithCompass = {
108
108
  isSingleStep: true,
109
109
  sections: [],
110
110
  generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getBuildMediatriceWithCompassQuestion, nb),
111
- qcmTimer: 60,
112
- freeTimer: 60,
111
+ ggbTimer: 60,
113
112
  getPropositions,
114
113
  isGGBAnswerValid,
115
114
  subject: "Mathématiques",
@@ -1 +1 @@
1
- {"version":3,"file":"drawAVectorInGGB.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/vectors/drawAVectorInGGB.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIT,MAAM,0BAA0B,CAAC;AASlC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAkCF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAalD,CAAC"}
1
+ {"version":3,"file":"drawAVectorInGGB.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/vectors/drawAVectorInGGB.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIT,MAAM,0BAA0B,CAAC;AASlC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAkCF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAYlD,CAAC"}
@@ -45,8 +45,7 @@ exports.drawAVectorInGGB = {
45
45
  isSingleStep: true,
46
46
  sections: ["Géométrie cartésienne"],
47
47
  generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getDrawAVectorInGgbQuestion, nb),
48
- qcmTimer: 60,
49
- freeTimer: 60,
48
+ ggbTimer: 60,
50
49
  answerType: "GGB",
51
50
  isGGBAnswerValid,
52
51
  subject: "Mathématiques",
@@ -1 +1 @@
1
- {"version":3,"file":"squareRootIdentities.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/squareRoots/squareRootIdentities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,0BAA0B,CAAC;AAmBlC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtB,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA2KF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CActD,CAAC"}
1
+ {"version":3,"file":"squareRootIdentities.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/squareRoots/squareRootIdentities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,0BAA0B,CAAC;AAmBlC,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtB,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA+KF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CActD,CAAC"}
@@ -57,7 +57,11 @@ const getSquareRootIdentitiesQuestion = () => {
57
57
  const answer = getAnswer(type, firstTerm, secondTerm).toTex();
58
58
  const question = {
59
59
  answer,
60
- instruction: `Développer et simplifier : $${statement.toTex()}$`,
60
+ instruction: `Développer et simplifier :
61
+
62
+ $$
63
+ ${statement.toTex()}
64
+ $$`,
61
65
  keys: [],
62
66
  answerFormat: "tex",
63
67
  identifiers: { type, a: a.operand, b: b?.operand, x, y },
@@ -1 +1 @@
1
- {"version":3,"file":"squareRootsDistributivity.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/squareRoots/squareRootsDistributivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,0BAA0B,CAAC;AAYlC,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;AAiEF,eAAO,MAAM,yBAAyB,EAAE,QAAQ,CAAC,WAAW,CAc3D,CAAC"}
1
+ {"version":3,"file":"squareRootsDistributivity.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/squareRoots/squareRootsDistributivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,0BAA0B,CAAC;AAYlC,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;AAqEF,eAAO,MAAM,yBAAyB,EAAE,QAAQ,CAAC,WAAW,CAc3D,CAAC"}
@@ -27,7 +27,11 @@ const getSquareRootsDistributivityQuestion = () => {
27
27
  .toTex();
28
28
  const question = {
29
29
  answer,
30
- instruction: `Développer et simplifier : $${statement.toTex()}$`,
30
+ instruction: `Développer et simplifier :
31
+
32
+ $$
33
+ ${statement.toTex()}
34
+ $$`,
31
35
  keys: [],
32
36
  answerFormat: "tex",
33
37
  identifiers: { a, b: b.operand, c, d },
@@ -1 +1 @@
1
- {"version":3,"file":"calibrationCurveOfSolution.d.ts","sourceRoot":"","sources":["../../../src/exercises/pc/calibrationCurveOfSolution.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAUT,MAAM,0BAA0B,CAAC;AAYlC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA0FF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAc5D,CAAC"}
1
+ {"version":3,"file":"calibrationCurveOfSolution.d.ts","sourceRoot":"","sources":["../../../src/exercises/pc/calibrationCurveOfSolution.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAUT,MAAM,0BAA0B,CAAC;AAYlC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA0FF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAa5D,CAAC"}
@@ -89,8 +89,7 @@ exports.calibrationCurveOfSolution = {
89
89
  isSingleStep: true,
90
90
  sections: ["Spectrophotométrie"],
91
91
  generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getCalibrationCurveOfSolutionQuestion, nb),
92
- qcmTimer: 60,
93
- freeTimer: 60,
92
+ ggbTimer: 60,
94
93
  isGGBAnswerValid,
95
94
  answerType: "GGB",
96
95
  subject: "Physique",
@@ -1 +1 @@
1
- {"version":3,"file":"rationalVEA.d.ts","sourceRoot":"","sources":["../../../src/exercises/vea/rationalVEA.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,eAAgB,MAAM,UAAU,MAAM,YAK7D,CAAC"}
1
+ {"version":3,"file":"rationalVEA.d.ts","sourceRoot":"","sources":["../../../src/exercises/vea/rationalVEA.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,eAAgB,MAAM,UAAU,MAAM,YAS7D,CAAC"}
@@ -8,7 +8,12 @@ const rationalVEA = (studentAns, answer) => {
8
8
  const parsed = (0, rationalParser_1.rationalParser)(studentAns);
9
9
  if (!parsed)
10
10
  return false;
11
- const parsedAnswer = (0, latexParser_1.parseAlgebraic)(answer);
12
- return Math.abs(parsed.evaluate() - parsedAnswer.evaluate()) < 0.0000001;
11
+ try {
12
+ const parsedAnswer = (0, latexParser_1.parseAlgebraic)(answer);
13
+ return Math.abs(parsed.evaluate() - parsedAnswer.evaluate()) < 0.0000001;
14
+ }
15
+ catch (err) {
16
+ return false;
17
+ }
13
18
  };
14
19
  exports.rationalVEA = rationalVEA;
package/lib/index.d.ts CHANGED
@@ -233,9 +233,13 @@ declare const mathExercises: (Exercise<{
233
233
  a: number;
234
234
  b: number;
235
235
  }, {}> | Exercise<{
236
- a: number;
237
- b: number;
238
- }, {}> | Exercise<{
236
+ a: import("./tree/nodes/nodeConstructor").NodeIdentifiers;
237
+ b: import("./tree/nodes/nodeConstructor").NodeIdentifiers;
238
+ isXRight: boolean;
239
+ aNumberType: string;
240
+ }, {
241
+ aNumberType: string[];
242
+ }> | Exercise<{
239
243
  a: number;
240
244
  b: number;
241
245
  c: number;
@@ -1711,9 +1715,13 @@ declare const pcExercises: (Exercise<{
1711
1715
  a: number;
1712
1716
  b: number;
1713
1717
  }, {}> | Exercise<{
1714
- a: number;
1715
- b: number;
1716
- }, {}> | Exercise<{
1718
+ a: import("./tree/nodes/nodeConstructor").NodeIdentifiers;
1719
+ b: import("./tree/nodes/nodeConstructor").NodeIdentifiers;
1720
+ isXRight: boolean;
1721
+ aNumberType: string;
1722
+ }, {
1723
+ aNumberType: string[];
1724
+ }> | Exercise<{
1717
1725
  a: number;
1718
1726
  b: number;
1719
1727
  c: number;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,yBAAyB,CAAC;AAEjC,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"}
@@ -0,0 +1,10 @@
1
+ import { AlgebraicNode } from "../../tree/nodes/algebraicNode";
2
+ export declare class GeneralAffine {
3
+ a: AlgebraicNode;
4
+ b: AlgebraicNode;
5
+ variable: string;
6
+ constructor(a: number | AlgebraicNode, b: number | AlgebraicNode, variable?: string);
7
+ getRoot(): AlgebraicNode;
8
+ toTree(): import("../../tree/nodes/operators/multiplyNode").MultiplyNode | import("../../tree/nodes/operators/addNode").AddNode;
9
+ }
10
+ //# sourceMappingURL=generalAffine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generalAffine.d.ts","sourceRoot":"","sources":["../../../src/math/polynomials/generalAffine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAO/D,qBAAa,aAAa;IACxB,CAAC,EAAE,aAAa,CAAC;IACjB,CAAC,EAAE,aAAa,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;gBAGf,CAAC,EAAE,MAAM,GAAG,aAAa,EACzB,CAAC,EAAE,MAAM,GAAG,aAAa,EACzB,QAAQ,GAAE,MAAY;IAWxB,OAAO,IAAI,aAAa;IAIxB,MAAM;CAKP"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneralAffine = void 0;
4
+ const oppositeNode_1 = require("../../tree/nodes/functions/oppositeNode");
5
+ const addNode_1 = require("../../tree/nodes/operators/addNode");
6
+ const fractionNode_1 = require("../../tree/nodes/operators/fractionNode");
7
+ const multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
8
+ class GeneralAffine {
9
+ constructor(a, b, variable = "x") {
10
+ if (typeof a === "number")
11
+ this.a = a.toTree();
12
+ else
13
+ this.a = a;
14
+ if (this.a.evaluate() === 0)
15
+ throw new Error("Forbidden division by zero");
16
+ if (typeof b === "number")
17
+ this.b = b.toTree();
18
+ else
19
+ this.b = b;
20
+ this.variable = variable;
21
+ }
22
+ getRoot() {
23
+ return (0, fractionNode_1.frac)((0, oppositeNode_1.opposite)(this.b), this.a).simplify();
24
+ }
25
+ toTree() {
26
+ const monom = (0, multiplyNode_1.multiply)(this.a, this.variable);
27
+ if (this.b.evaluate() === 0)
28
+ return monom;
29
+ return (0, addNode_1.add)(monom, this.b);
30
+ }
31
+ }
32
+ exports.GeneralAffine = GeneralAffine;
package/lib/playground.js CHANGED
@@ -4,7 +4,7 @@ exports.playground = void 0;
4
4
  const nodeConstructor_1 = require("./tree/nodes/nodeConstructor");
5
5
  const playground = () => {
6
6
  // logIdentifiers();
7
- // const parsed = parseLatex("^{^3}");
7
+ // const parsed = parseLatex("x\\times +3");
8
8
  // console.log(parsed.toTex());
9
9
  };
10
10
  exports.playground = playground;
@@ -1,6 +1,16 @@
1
1
  import { AlgebraicNode } from "../algebraicNode";
2
2
  import { Node, NodeIds, NodeOptions, NodeType } from "../node";
3
+ import { NodeIdentifiers } from "../nodeConstructor";
3
4
  export declare const equal: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string) => EqualNode;
5
+ export type EqualNodeIdentifiers = {
6
+ id: NodeIds.equal;
7
+ leftChild: NodeIdentifiers;
8
+ rightChild: NodeIdentifiers;
9
+ opts?: NodeOptions;
10
+ };
11
+ export declare abstract class EqualNodeConstructor {
12
+ static fromIdentifiers(identifiers: EqualNodeIdentifiers): EqualNode;
13
+ }
4
14
  export declare const isEqualNode: (node: Node) => node is EqualNode;
5
15
  export declare class EqualNode implements Node {
6
16
  leftChild: Node;
@@ -8,19 +18,13 @@ export declare class EqualNode implements Node {
8
18
  opts?: NodeOptions;
9
19
  type: NodeType;
10
20
  constructor(leftChild: Node, rightChild: Node, opts?: NodeOptions);
11
- toIdentifiers(): {
12
- id: NodeIds;
13
- leftChild: {
14
- id: NodeIds;
15
- } & Record<string, any>;
16
- rightChild: {
17
- id: NodeIds;
18
- } & Record<string, any>;
19
- };
21
+ toIdentifiers(): EqualNodeIdentifiers;
20
22
  toEquivalentNodes(opts?: NodeOptions): Node[];
21
23
  toAllValidTexs(opts?: NodeOptions): string[];
22
24
  toMathString(): string;
23
25
  toTex(): string;
24
26
  simplify(): this;
27
+ shuffle(): EqualNode;
28
+ reverse(): EqualNode;
25
29
  }
26
30
  //# 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,aAAa,EAAE,MAAM,kBAAkB,C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AAE,WAAW,CAAC;CACpB,CAAC;AAEF,8BAAsB,oBAAoB;IACxC,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,oBAAoB,GAAG,SAAS;CAOrE;AAED,eAAO,MAAM,WAAW,SAAU,IAAI,sBACL,CAAC;AAElC,qBAAa,SAAU,YAAW,IAAI;IACpC,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,EAAE,IAAI,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,QAAQ,CAAC;gBACH,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,WAAW;IAOjE,aAAa,IAAI,oBAAoB;IAQrC,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW;IAmBpC,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE;IAM5C,YAAY,IAAI,MAAM;IAGtB,KAAK,IAAI,MAAM;IAIf,QAAQ;IAIR,OAAO;IAIP,OAAO;CAUR"}
@@ -1,13 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EqualNode = exports.isEqualNode = exports.equal = void 0;
3
+ exports.EqualNode = exports.isEqualNode = exports.EqualNodeConstructor = exports.equal = void 0;
4
+ // import { equal } from "mathjs";
5
+ const coinFlip_1 = require("../../../utils/alea/coinFlip");
4
6
  const node_1 = require("../node");
7
+ const nodeConstructor_1 = require("../nodeConstructor");
5
8
  const equal = (a, b) => {
6
9
  const nodeA = typeof a === "number" ? a.toTree() : typeof a === "string" ? a.toTree() : a;
7
10
  const nodeB = typeof b === "number" ? b.toTree() : typeof b === "string" ? b.toTree() : b;
8
11
  return new EqualNode(nodeA, nodeB);
9
12
  };
10
13
  exports.equal = equal;
14
+ class EqualNodeConstructor {
15
+ static fromIdentifiers(identifiers) {
16
+ return new EqualNode(nodeConstructor_1.NodeConstructor.fromIdentifiers(identifiers.leftChild), nodeConstructor_1.NodeConstructor.fromIdentifiers(identifiers.rightChild), identifiers.opts);
17
+ }
18
+ }
19
+ exports.EqualNodeConstructor = EqualNodeConstructor;
11
20
  const isEqualNode = (node) => node.type === node_1.NodeType.equality;
12
21
  exports.isEqualNode = isEqualNode;
13
22
  class EqualNode {
@@ -22,6 +31,7 @@ class EqualNode {
22
31
  id: node_1.NodeIds.equal,
23
32
  leftChild: this.leftChild.toIdentifiers(),
24
33
  rightChild: this.rightChild.toIdentifiers(),
34
+ opts: this.opts,
25
35
  };
26
36
  }
27
37
  toEquivalentNodes(opts) {
@@ -53,5 +63,11 @@ class EqualNode {
53
63
  simplify() {
54
64
  return this;
55
65
  }
66
+ shuffle() {
67
+ return (0, coinFlip_1.coinFlip)() ? this : this.reverse();
68
+ }
69
+ reverse() {
70
+ return new EqualNode(this.rightChild, this.leftChild, this.opts);
71
+ }
56
72
  }
57
73
  exports.EqualNode = EqualNode;
@@ -22,7 +22,7 @@ export declare class InequationSolutionNode implements Node {
22
22
  };
23
23
  toAllTexs(): string[];
24
24
  toAllValidTexs(): string[];
25
- toEquivalentNodes(opts?: NodeOptions): (InequationSolutionNode | import("./inequationNode").InequationNode)[];
25
+ toEquivalentNodes(opts?: NodeOptions): (import("./inequationNode").InequationNode | InequationSolutionNode)[];
26
26
  toMathString(): string;
27
27
  toMathjs(): string;
28
28
  toTex(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"affineParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/affineParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAOvD,eAAO,MAAM,YAAY,QAAS,MAAM,aAAY,MAAM,wFAiBzD,CAAC"}
1
+ {"version":3,"file":"affineParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/affineParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAOvD,eAAO,MAAM,YAAY,QAAS,MAAM,aAAY,MAAM,wFAqBzD,CAAC"}
@@ -7,20 +7,25 @@ const multiplyNode_1 = require("../nodes/operators/multiplyNode");
7
7
  const variableNode_1 = require("../nodes/variables/variableNode");
8
8
  const latexParser_1 = require("./latexParser");
9
9
  const affineParser = (ans, variable = "x") => {
10
- const parsed = (0, latexParser_1.parseAlgebraic)(ans);
11
- if ((0, variableNode_1.isVariableNode)(parsed)) {
12
- if (parsed.name !== variable)
13
- return false;
14
- return parsed;
15
- }
16
- //!won't handle Affines à coefficients non entiers
17
- if ((0, multiplyNode_1.isMultiplyNode)(parsed)) {
18
- if ((0, variableNode_1.isVariableNode)(parsed.rightChild) &&
19
- parsed.rightChild.name === variable &&
20
- (0, numberNode_1.isNumberNode)(parsed.leftChild)) {
21
- return new affine_1.Affine(parsed.leftChild.value, 0, variable);
10
+ try {
11
+ const parsed = (0, latexParser_1.parseAlgebraic)(ans);
12
+ if ((0, variableNode_1.isVariableNode)(parsed)) {
13
+ if (parsed.name !== variable)
14
+ return false;
15
+ return parsed;
16
+ }
17
+ //!won't handle Affines à coefficients non entiers
18
+ if ((0, multiplyNode_1.isMultiplyNode)(parsed)) {
19
+ if ((0, variableNode_1.isVariableNode)(parsed.rightChild) &&
20
+ parsed.rightChild.name === variable &&
21
+ (0, numberNode_1.isNumberNode)(parsed.leftChild)) {
22
+ return new affine_1.Affine(parsed.leftChild.value, 0, variable);
23
+ }
22
24
  }
23
25
  }
26
+ catch (err) {
27
+ return false;
28
+ }
24
29
  //"x" ou a*x ou a*x+b ou x+b
25
30
  };
26
31
  exports.affineParser = affineParser;
@@ -3,5 +3,5 @@ import { EqualNode } from "../nodes/equations/equalNode";
3
3
  import { InequationNode } from "../nodes/inequations/inequationNode";
4
4
  export declare const tokenize: (latex: string) => string[];
5
5
  export declare const parseAlgebraic: (latex: string) => AlgebraicNode;
6
- export declare const parseLatex: (latex: string) => AlgebraicNode | EqualNode | InequationNode;
6
+ export declare const parseLatex: (latex: string) => AlgebraicNode | InequationNode | EqualNode;
7
7
  //# sourceMappingURL=latexParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"latexParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/latexParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AA8CrE,eAAO,MAAM,QAAQ,UAAW,MAAM,aA4BrC,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,MAAM,kBAa3C,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,MAAM,+CA2CvC,CAAC"}
1
+ {"version":3,"file":"latexParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/latexParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAkDrE,eAAO,MAAM,QAAQ,UAAW,MAAM,aA4BrC,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,MAAM,kBAa3C,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,MAAM,+CA2CvC,CAAC"}
@@ -26,7 +26,9 @@ const functions = [
26
26
  const operators = ["+", "-", "\\div", "\\times", "^"];
27
27
  //cmds childless, like \\pi
28
28
  const symbols = [{ tex: "\\pi", node: piNode_1.PiNode }];
29
+ //separators between trees
29
30
  const separators = ["=", "<", ">", "\\leq", "\\geq"];
31
+ //le nombre de parentheses est il respecté
30
32
  const isDyck = (tokens) => {
31
33
  const brackets = tokens.filter((el) => el === "(" || el === ")");
32
34
  while (brackets.length) {
@@ -47,6 +49,8 @@ const isDyck = (tokens) => {
47
49
  }
48
50
  return true;
49
51
  };
52
+ //?on push les nb, commands, variables, symboles dans un array de token
53
+ //?ex [3 ; + ; \\pi ; \\frac ; { ; 2 ; x ; } ; { 3 ; x ; }]
50
54
  const tokenize = (latex) => {
51
55
  const tokens = [];
52
56
  for (let i = 0; i < latex.length; i++) {
@@ -136,6 +140,9 @@ const parseLatex = (latex) => {
136
140
  }
137
141
  };
138
142
  exports.parseLatex = parseLatex;
143
+ //? parcours en profondeur dans le sens où profondeur = ouverture d'un sous arbre math
144
+ //? genre dans 3exp(x^2) , x^2 est à la profondeur 2 et ^2 est pronfondeur 3
145
+ //
139
146
  const buildTree = (tokens) => {
140
147
  let currentDepth = 0;
141
148
  let maxDepth = 0;
@@ -152,7 +159,14 @@ const buildTree = (tokens) => {
152
159
  if (token === ")" || token === "}")
153
160
  currentDepth--;
154
161
  }
155
- // console.log("depthed: ", depthedTokens);
162
+ //? on parcours en partant de profondeur max, pour chaque profondeur on build le tree de l'expression
163
+ //? ce tree remplace les tokens de cette profondeur
164
+ //? donc 3exp(x^2)
165
+ //? -> via tokenize : [3, exp, x, ^, 2]
166
+ //? -> to depthed: [{3, 0}, {exp, 0}, {x, 1}, {^, 1}, {2, 2}]
167
+ //? -> itération 1 : [{3, 0}, {exp, 0}, {x, 1}, {^, 1}, {NumberNode(2), 1}]
168
+ //? -> itération 2 : [{3, 0}, {exp, 0}, {SquareNode(x), 1}]
169
+ //? -> itération 3 : Multiply(3, ExpNode(SquareNode(x)))
156
170
  while (true) {
157
171
  if (maxDepth === 0) {
158
172
  const tree = buildTreeForSameDepthTokens(depthedTokens.map((el) => el.token));
@@ -160,30 +174,33 @@ const buildTree = (tokens) => {
160
174
  }
161
175
  for (let i = 0; i < depthedTokens.length; i++) {
162
176
  const token = depthedTokens[i];
177
+ //? on commence par les tokens de depth max
163
178
  if (token.depth < maxDepth)
164
179
  continue;
165
- //le token est forcément ici ( ou {
166
- //et on est sur qu'il n'y a aucun autre nestage à l'intérieur
180
+ //? le token est forcément ici ( ou {
181
+ //? et on est sur qu'il n'y a aucun autre nestage à l'intérieur
167
182
  const endIndex = depthedTokens.findIndex((el, index) => index > i && (el.token === ")" || el.token === "}"));
168
183
  const tree = buildTreeForSameDepthTokens(depthedTokens.slice(i + 1, endIndex).map((el) => el.token));
169
184
  depthedTokens.splice(i, endIndex - i + 1, {
170
185
  token: tree,
171
186
  depth: token.depth - 1,
172
187
  });
173
- // console.log(`depthed after iter ${i}`, depthedTokens);
174
188
  }
175
189
  maxDepth--;
176
190
  }
177
191
  };
178
192
  const buildTreeForSameDepthTokens = (tokens) => {
179
- // console.log("start: ", tokens);
193
+ //? à ce stade les tokens sont soit des charactères soit des nodes déjà build (par buildTree)
194
+ //? ici on n'est dans une profondeur unique
180
195
  let tempTokens = [];
181
196
  for (let i = 0; i < tokens.length; i++) {
182
197
  const token = tokens[i];
198
+ //?buildTree a déjà pu build des expressions de profondeur plus grande
183
199
  if (typeof token !== "string") {
184
200
  tempTokens[i] = token;
185
201
  continue;
186
202
  }
203
+ //? les nombres, variables et symboles (pi) sont direct push en node
187
204
  if (token[0].match(/[0-9]/)) {
188
205
  tempTokens[i] = new numberNode_1.NumberNode(Number(token));
189
206
  }
@@ -203,8 +220,7 @@ const buildTreeForSameDepthTokens = (tokens) => {
203
220
  else
204
221
  throw Error(`token not implemented: ${token}`);
205
222
  }
206
- // console.log("after parses : ", tempTokens);
207
- //1 build les fct
223
+ //?1 build les fct
208
224
  for (let i = 0; i < tempTokens.length; i++) {
209
225
  if (typeof tempTokens[i] !== "string")
210
226
  continue;
@@ -223,7 +239,6 @@ const buildTreeForSameDepthTokens = (tokens) => {
223
239
  }
224
240
  }
225
241
  if (token === "^") {
226
- console.log(tempTokens[i - 1]);
227
242
  if (!tempTokens[i - 1] ||
228
243
  typeof tempTokens[i - 1] === "string" ||
229
244
  !tempTokens[i + 1] ||
@@ -312,7 +327,17 @@ const buildTreeForSameDepthTokens = (tokens) => {
312
327
  const token = tempTokens[i];
313
328
  if (!currentAdd) {
314
329
  if (typeof token === "string") {
315
- if (token === "+" || token === "-") {
330
+ //ici on accepte +3 (mais seulement en début de tree)
331
+ //donc +3 + X est ok
332
+ //mais pas x \\times +3
333
+ if (token === "+" &&
334
+ !!tempTokens[i + 1] &&
335
+ typeof tempTokens[i + 1] !== "string" &&
336
+ (0, numberNode_1.isNumberNode)(tempTokens[i + 1])) {
337
+ currentAdd = tempTokens[i + 1];
338
+ i++;
339
+ }
340
+ else if (token === "+" || token === "-") {
316
341
  throw Error("Addition with no first term");
317
342
  }
318
343
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "math-exercises",
3
- "version": "2.2.65",
3
+ "version": "2.2.66",
4
4
  "description": "Math exercises generator for middle school and high school",
5
5
  "main": "lib/index.js",
6
6
  "files": [