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