math-exercises 3.0.51 → 3.0.52

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.
@@ -1 +1 @@
1
- {"version":3,"file":"proportionalityTableCoefficient.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/proportionality/proportionalityTableCoefficient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAWrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAiFF,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,WAAW,CAgBjE,CAAC"}
1
+ {"version":3,"file":"proportionalityTableCoefficient.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/proportionality/proportionalityTableCoefficient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAWrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAsFF,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,WAAW,CAiBjE,CAAC"}
@@ -35,7 +35,7 @@ const getCorrection = (identifiers) => {
35
35
  Pour l'obtenir, on divise une valeur de la deuxième ligne par la valeur correspondante dans la première ligne, par exemple :
36
36
 
37
37
  $$
38
- ${frac(xValues[0], yValues[0]).toSimplificationTex()}
38
+ ${frac(yValues[0], xValues[0]).toSimplificationTex()}
39
39
  $$`;
40
40
  };
41
41
  const getProportionalityTableCoefficient = () => {
@@ -43,6 +43,9 @@ const getProportionalityTableCoefficient = () => {
43
43
  const xValues = IntegerConstructor.randomDifferents(1, 100 / factor, 3).sort((a, b) => a - b);
44
44
  const yValues = xValues.map((x) => x * factor);
45
45
  const identifiers = { xValues, yValues };
46
+ return getQuestionFromIdentifiers(identifiers);
47
+ };
48
+ const getQuestionFromIdentifiers = (identifiers) => {
46
49
  const question = {
47
50
  instruction: getInstruction(identifiers),
48
51
  answer: getAnswer(identifiers),
@@ -87,4 +90,5 @@ export const proportionalityTableCoefficient = {
87
90
  subject: "Mathématiques",
88
91
  getInstruction,
89
92
  hasHintAndCorrection: true,
93
+ getQuestionFromIdentifiers,
90
94
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cartesianEquationOfLine.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/cartesian/cartesianEquationOfLine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,6BAA6B,CAAC;AAcrC,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAqOF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,WAAW,CAczD,CAAC"}
1
+ {"version":3,"file":"cartesianEquationOfLine.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/cartesian/cartesianEquationOfLine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAqBrC,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AA0KF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,WAAW,CAazD,CAAC"}
@@ -8,43 +8,79 @@ import { randint } from "../../../../math/utils/random/randint.js";
8
8
  import { EqualNode } from "../../../../tree/nodes/equations/equalNode.js";
9
9
  import { NumberNode } from "../../../../tree/nodes/numbers/numberNode.js";
10
10
  import { AddNode } from "../../../../tree/nodes/operators/addNode.js";
11
- import { MultiplyNode } from "../../../../tree/nodes/operators/multiplyNode.js";
11
+ import { MultiplyNode, } from "../../../../tree/nodes/operators/multiplyNode.js";
12
12
  import { VariableNode } from "../../../../tree/nodes/variables/variableNode.js";
13
- const zero = new NumberNode(0);
14
- const getCartesianEquationOfLineQuestion = () => {
15
- const a = new Point("A", new NumberNode(randint(-5, 6)), new NumberNode(randint(-5, 6)));
16
- const b = new Point("B", new NumberNode(randint(-5, 6, [a.getXnumber()])), new NumberNode(randint(-5, 6, [a.getXnumber()])));
13
+ import { parseAlgebraic } from "../../../../tree/parsers/latexParser.js";
14
+ import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
15
+ const getInstruction = (identifiers) => {
16
+ const instruction = `Déterminer une équation cartésienne de la droite $d$ représentée ci-dessous :`;
17
+ return instruction;
18
+ };
19
+ const getAnswer = (identifiers) => {
20
+ const { aX, aY, bX, bY } = identifiers;
21
+ const a = new Point("a", aX, aY);
22
+ const b = new Point("b", bX, bY);
17
23
  const line = new Line(a, b);
24
+ const correctAnswer = line.getCartesianEquation();
25
+ return correctAnswer.toTex();
26
+ };
27
+ const getGGBOptions = (identifiers) => {
28
+ const { aX, aY, bX, bY } = identifiers;
29
+ const a = new Point("a", aX, aY);
30
+ const b = new Point("b", bX, bY);
18
31
  const commands = [
19
- `d = Line((${a.getXnumber()},${a.getYnumber()}),(${b.getXnumber()},${b.getYnumber()}))`,
32
+ `d = Line((${aX},${aY}),(${bX},${bY}))`,
20
33
  `SetCaption(d, "$d$")`,
21
34
  `ShowLabel(d,true)`,
22
35
  `SetFixed(d,true)`,
23
36
  ];
24
37
  const ggb = new GeogebraConstructor({ commands });
25
- const correctAnswer = line.getCartesianEquation();
26
- const instruction = `Déterminer une équation cartesienne de la droite $d$ représentée ci-dessous :`;
27
- const aX = a.getXnumber();
28
- const aY = a.getYnumber();
29
- const bX = b.getXnumber();
30
- const bY = b.getYnumber();
38
+ return ggb.getOptions({
39
+ coords: ggb.getCoordsForPoints([a, b]),
40
+ });
41
+ };
42
+ const getCartesianEquationOfLineQuestion = () => {
43
+ const aX = randint(-5, 6);
44
+ const aY = randint(-5, 6);
45
+ const bX = randint(-5, 6, [aX]);
46
+ const bY = randint(-5, 6, [aY]);
47
+ const identifiers = { aX, aY, bX, bY };
48
+ return getQuestionFromIdentifiers(identifiers);
49
+ };
50
+ const getQuestionFromIdentifiers = (identifiers) => {
31
51
  const question = {
32
- answer: correctAnswer.toTex(),
33
- ggbOptions: ggb.getOptions({
34
- coords: ggb.getAdaptedCoords({
35
- xMin: Math.min(aX, bX) - 5,
36
- xMax: Math.max(bX, aX) + 5,
37
- yMin: Math.min(aY, bY) - 5,
38
- yMax: Math.max(bY, aY) + 5,
39
- }),
40
- }),
41
- instruction: instruction,
52
+ answer: getAnswer(identifiers),
53
+ ggbOptions: getGGBOptions(identifiers),
54
+ instruction: getInstruction(identifiers),
42
55
  keys: ["x", "y", "equal"],
43
56
  answerFormat: "tex",
44
- identifiers: { aX, aY, bX, bY },
57
+ identifiers,
45
58
  };
46
59
  return question;
47
60
  };
61
+ const isAnswerValid = (ans, { aX, aY, bX, bY }) => {
62
+ try {
63
+ const splitted = ans.split("=");
64
+ if (splitted[1] !== "0" || splitted.length !== 2)
65
+ return false;
66
+ const parsed = parseAlgebraic(splitted[0]);
67
+ const validpoints = [
68
+ [aX.toTree(), aY.toTree()],
69
+ [bX.toTree(), bY.toTree()],
70
+ ];
71
+ return (parsed
72
+ .toDetailedEvaluation({ x: validpoints[0][0], y: validpoints[0][1] })
73
+ .simplify()
74
+ .toTex() === "0" &&
75
+ parsed
76
+ .toDetailedEvaluation({ x: validpoints[1][0], y: validpoints[1][1] })
77
+ .simplify()
78
+ .toTex() === "0");
79
+ }
80
+ catch (err) {
81
+ return handleVEAError(err);
82
+ }
83
+ };
48
84
  const getPropositions = (n, { answer, aX, aY, bX, bY }) => {
49
85
  const propositions = [];
50
86
  addValidProp(propositions, answer);
@@ -69,7 +105,7 @@ const generateRandomWrongProp = (aX, aY, bX, bY, x, y) => {
69
105
  b = randint(-10, 11, [0]);
70
106
  c = randint(-10, 11);
71
107
  } while (a * aX + b * aY + c === 0 && a * bX + b * bY + c === 0);
72
- return new EqualNode(new AddNode(new AddNode(new MultiplyNode(a.toTree(), x).simplify(), new MultiplyNode(b.toTree(), y).simplify()), c.toTree()), zero);
108
+ return new EqualNode(new AddNode(new AddNode(new MultiplyNode(a.toTree(), x).simplify(), new MultiplyNode(b.toTree(), y).simplify()), c.toTree()), (0).toTree());
73
109
  };
74
110
  const generateProposition = (aX, aY, bX, bY) => {
75
111
  const x = new VariableNode("x");
@@ -86,84 +122,12 @@ const getFirstProposition = (x, y, aX, aY, bX, bY) => {
86
122
  const b = -u.getXAsNumber();
87
123
  const a = u.getYAsNumber();
88
124
  const c = a * aX + b * aY;
89
- return new EqualNode(new AddNode(new AddNode(new MultiplyNode(new NumberNode(b), x).simplify(), new MultiplyNode(new NumberNode(a), y).simplify()), new NumberNode(c)), zero);
90
- };
91
- const isAnswerValid = (ans, { aX, aY, bX, bY }) => {
92
- let userAns = getEquationNodeFromString(ans);
93
- if (userAns === undefined)
94
- return false;
95
- userAns = userAns;
96
- if (userAns.evaluate({ x: aX, y: aY }) !== 0)
97
- return false;
98
- if (userAns.evaluate({ x: bX, y: bY }) !== 0)
99
- return false;
100
- return true;
101
- };
102
- const getEquationNodeFromString = (ans) => {
103
- if (!isValidFormat(ans))
104
- return undefined;
105
- const leftSide = ans.split("=")[0];
106
- let op = leftSide.charAt(0) === "-" ? leftSide.replace("-", "minus") : leftSide;
107
- op = op.includes("+") ? op : op.replaceAll("-", "+minus");
108
- return getNodeFromString(op.split("+"));
109
- };
110
- const isValidFormat = (ans) => {
111
- if (!ans.includes("="))
112
- return false;
113
- const splitted = ans.split("=");
114
- if (splitted.length !== 2 ||
115
- splitted[1] !== "0" ||
116
- (!splitted[0].includes("x") && !splitted[0].includes("y")))
117
- return false;
118
- return true;
119
- };
120
- const getNodeFromString = (tab) => {
121
- if (tab.length === 1) {
122
- let varStr = tab[0];
123
- const operator = findOpInSimpleOpString(varStr);
124
- if (operator !== undefined) {
125
- const modified = operator === "-" ? varStr.replaceAll("-", "+minus") : varStr;
126
- const separated = modified.split("+");
127
- return getNodeFromString(separated).simplify();
128
- }
129
- varStr = varStr.replace("minus", "-");
130
- if (varStr.includes("x")) {
131
- return getNodeFromVariableString(varStr, "x");
132
- }
133
- if (varStr.includes("y")) {
134
- return getNodeFromVariableString(varStr, "y");
135
- }
136
- return isNaN(+varStr) ? new NumberNode(0) : new NumberNode(+varStr);
137
- }
138
- else {
139
- const middle = Math.floor(tab.length / 2);
140
- const leftSide = tab.slice(0, middle);
141
- const rightSide = tab.slice(middle);
142
- return new AddNode(getNodeFromString(leftSide).simplify(), getNodeFromString(rightSide).simplify()).simplify();
143
- }
144
- };
145
- const findOpInSimpleOpString = (str) => {
146
- if (str.includes("+"))
147
- return "+";
148
- if (str.includes("-"))
149
- return "-";
150
- return undefined;
151
- };
152
- const getNodeFromVariableString = (str, splitter) => {
153
- if (str === splitter)
154
- return new VariableNode(splitter);
155
- const splitted = str.split(splitter);
156
- if (splitted[0] === "-") {
157
- return new MultiplyNode(new NumberNode(-1), new VariableNode(splitter)).simplify();
158
- }
159
- return new MultiplyNode(new NumberNode(+splitted[0]), new VariableNode(splitter)).simplify();
125
+ return new EqualNode(new AddNode(new AddNode(new MultiplyNode(new NumberNode(b), x).simplify(), new MultiplyNode(new NumberNode(a), y).simplify()), new NumberNode(c)), (0).toTree());
160
126
  };
161
127
  export const cartesianEquationOfLine = {
162
128
  id: "cartesianEquationOfLine",
163
129
  label: "Déterminer une équation cartesienne de droite par lecture graphique",
164
- levels: ["2nde"],
165
130
  isSingleStep: true,
166
- sections: ["Droites"],
167
131
  generator: (nb) => getDistinctQuestions(getCartesianEquationOfLineQuestion, nb),
168
132
  qcmTimer: 60,
169
133
  freeTimer: 60,
@@ -171,4 +135,5 @@ export const cartesianEquationOfLine = {
171
135
  isAnswerValid,
172
136
  hasGeogebra: true,
173
137
  subject: "Mathématiques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;IAIhB,aAAa,CACX,iBAAiB,EAAE,OAAO,EAC1B,EACE,OAAc,EACd,SAAiB,EACjB,yBAAgC,EAChC,oBAA2B,EAC3B,KAAiB,EACjB,KAAiB,GAClB,GAAE,kBAAuB;IA2C5B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,MAAM;CAW7C"}
@@ -1,6 +1,6 @@
1
1
  import { randomSegmentName } from "../../exercises/utils/geometry/randomSegmentName.js";
2
2
  import { randomColor } from "../../geogebra/colors.js";
3
- import { EqualNode } from "../../tree/nodes/equations/equalNode.js";
3
+ import { equal, EqualNode } from "../../tree/nodes/equations/equalNode.js";
4
4
  import { opposite } from "../../tree/nodes/functions/oppositeNode.js";
5
5
  import { NumberNode } from "../../tree/nodes/numbers/numberNode.js";
6
6
  import { AddNode, add } from "../../tree/nodes/operators/addNode.js";
@@ -11,7 +11,7 @@ import { VariableNode } from "../../tree/nodes/variables/variableNode.js";
11
11
  import { GeneralSystem } from "../systems/generalSystem.js";
12
12
  import { randint } from "../utils/random/randint.js";
13
13
  import { Point, PointConstructor } from "./point.js";
14
- import { Vector, VectorConstructor } from "./vector.js";
14
+ import { VectorConstructor } from "./vector.js";
15
15
  export class LineConstructor {
16
16
  static random(name) {
17
17
  const names = randomSegmentName();
@@ -148,13 +148,13 @@ export class Line {
148
148
  return equation;
149
149
  };
150
150
  getCartesianEquation() {
151
- const u = new Vector("u", new NumberNode(this.pointB.getXnumber() - this.pointA.getXnumber()), new NumberNode(this.pointB.getYnumber() - this.pointA.getYnumber()));
152
- const b = -u.getXAsNumber();
153
- const a = u.getYAsNumber();
154
- const c = -a * this.pointA.getXnumber() - b * this.pointA.getYnumber();
155
- const x = new VariableNode("x");
156
- const y = new VariableNode("y");
157
- return new EqualNode(new AddNode(new AddNode(new MultiplyNode(new NumberNode(a), x).simplify(), new MultiplyNode(new NumberNode(b), y).simplify()), new NumberNode(c)).simplify({ forbidFactorize: true }), new NumberNode(0));
151
+ const u = VectorConstructor.fromPoints(this.pointA, this.pointB);
152
+ const b = opposite(u.x);
153
+ const a = u.y;
154
+ const c = add(opposite(multiply(a, this.pointA.x)), opposite(multiply(b, this.pointA.y)));
155
+ return equal(add(add(multiply(a, "x"), multiply(b, "y")), c).simplify({
156
+ forbidFactorize: true,
157
+ }), 0);
158
158
  }
159
159
  toCartesian() {
160
160
  const { a, b, c } = this.toCartesianCoeffs();
package/lib/playground.js CHANGED
@@ -1,11 +1,10 @@
1
- import { EqualNode } from "./tree/nodes/equations/equalNode.js";
2
- import { add } from "./tree/nodes/operators/addNode.js";
3
- import { multiply } from "./tree/nodes/operators/multiplyNode.js";
4
- import { parseAlgebraic } from "./tree/parsers/latexParser.js";
5
1
  export const playground = () => {
6
2
  // console.log(x.equals(x.simplify()));
7
- const eq = new EqualNode(parseAlgebraic("\\frac{3x+2}{4}"), parseAlgebraic("3x"));
8
- console.log(eq.isolate("x").toTex());
3
+ // const eq = new EqualNode(
4
+ // parseAlgebraic("\\frac{3x+2}{4}"),
5
+ // parseAlgebraic("3x"),
6
+ // );
7
+ // console.log(eq.isolate("x").toTex());
9
8
  // console.log(parseAlgebraic("\\left|x^2\\right|").toTex());
10
- console.log(add(multiply(3, "x"), multiply(4, "x")).simplify().toTex());
9
+ // console.log(add(multiply(3, "x"), multiply(4, "x")).simplify().toTex());
11
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"equalNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/equations/equalNode.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,aAAa,EACb,eAAe,EAEhB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAQ/B,eAAO,MAAM,KAAK,MACb,aAAa,GAAG,MAAM,GAAG,MAAM,KAC/B,aAAa,GAAG,MAAM,GAAG,MAAM,cAOnC,CAA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AIf,QAAQ;IAIR,OAAO;IAIP,OAAO;IAIP,OAAO,CAAC,OAAO,EAAE,MAAM;IAiGvB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,aAAa;IAG3C,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAGpC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,MAAM;IAGvE,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,aAAa;CAGzE;AAED,eAAO,MAAM,qBAAqB,MAC7B,aAAa,KACb,aAAa,KACb,aAAa,KACb,aAAa,sBA2DjB,CAAC"}
@@ -104,7 +104,6 @@ export class EqualNode {
104
104
  i++;
105
105
  if (i > 100)
106
106
  throw new Error("too many iterations in isolate");
107
- console.log(left.toTex(), ".......", right.toTex());
108
107
  if (isVariableNode(left) && left.name === varName) {
109
108
  return;
110
109
  }
@@ -166,7 +165,6 @@ export class EqualNode {
166
165
  right = opposite(right).simplify();
167
166
  }
168
167
  else {
169
- console.log(left);
170
168
  throw new Error("Isolation only implemented for basic operations yet");
171
169
  }
172
170
  recur();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.51",
4
+ "version": "3.0.52",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [