math-exercises 2.0.3 → 2.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.
@@ -2,8 +2,8 @@ import { MathExercise } from "../../../exercises/exercise";
2
2
  type Identifiers = {
3
3
  xValue: number;
4
4
  yValue: number;
5
- affineCoeffs: number[];
6
- trinomCoeffs: number[];
5
+ affineCoeffs?: number[];
6
+ trinomCoeffs?: number[];
7
7
  isAffine: boolean;
8
8
  };
9
9
  export declare const inverseImageFunctionGeogebra: MathExercise<Identifiers>;
@@ -1 +1 @@
1
- {"version":3,"file":"inverseImageFunctionGeogebra.d.ts","sourceRoot":"","sources":["../../../../src/exercises/functions/basics/inverseImageFunctionGeogebra.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAQb,MAAM,0BAA0B,CAAC;AAQlC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AA8LF,eAAO,MAAM,4BAA4B,EAAE,YAAY,CAAC,WAAW,CAalE,CAAC"}
1
+ {"version":3,"file":"inverseImageFunctionGeogebra.d.ts","sourceRoot":"","sources":["../../../../src/exercises/functions/basics/inverseImageFunctionGeogebra.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAQb,MAAM,0BAA0B,CAAC;AAQlC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAgLF,eAAO,MAAM,4BAA4B,EAAE,YAAY,CAAC,WAAW,CAalE,CAAC"}
@@ -11,56 +11,30 @@ const shuffle_1 = require("../../../utils/shuffle");
11
11
  const getInverseImageFunctionGeogebra = () => {
12
12
  const isAffine = (0, coinFlip_1.coinFlip)();
13
13
  const xValue = (0, randint_1.randint)(-5, 6);
14
- const yValue = (0, randint_1.randint)(-5, 6);
14
+ // const yValue = randint(-5, 6);
15
+ let yValue;
15
16
  let affine;
16
- do {
17
- affine = new polynomial_1.Polynomial([(0, randint_1.randint)(-9, 10), (0, randint_1.randint)(-5, 6, [0])]);
18
- } while (affine.calculate(xValue) > 10 || affine.calculate(xValue) < -10);
19
- let trinom = new polynomial_1.Polynomial([
20
- (0, randint_1.randint)(-9, 10) - yValue,
21
- (0, randint_1.randint)(-9, 10),
22
- (0, randint_1.randint)(-4, 5, [0]),
23
- ]);
24
- let roots = trinom.getRoots();
25
- if (roots.length === 2)
26
- while (roots[0] > 10 || roots[0] < -10 || roots[1] > 10 || roots[1] < -10) {
27
- trinom = new polynomial_1.Polynomial([
28
- (0, randint_1.randint)(-9, 10) - yValue,
29
- (0, randint_1.randint)(-9, 10),
30
- (0, randint_1.randint)(-4, 5, [0]),
31
- ]);
32
- roots = trinom.getRoots();
33
- }
34
- else if (roots.length === 1)
35
- while (roots[0] < -10 || roots[0] > 10) {
36
- trinom = new polynomial_1.Polynomial([
37
- (0, randint_1.randint)(-9, 10) - yValue,
38
- (0, randint_1.randint)(-9, 10),
39
- (0, randint_1.randint)(-4, 5, [0]),
40
- ]);
41
- roots = trinom.getRoots();
42
- }
43
- const statement = isAffine
44
- ? `Déterminer le ou les antécédents de $${affine.calculate(xValue)}$ par la fonction $f$ représentée ci dessous.`
45
- : `Déterminer le ou les antécédents de $${yValue}$ par la fonction $f$ représentée ci dessous.`;
46
- let answer = isAffine
47
- ? xValue
48
- : roots.length === 2
49
- ? `${(0, round_1.round)(roots[0], 1).toString().replace(".", ",")}\\text{ et }${(0, round_1.round)(roots[1], 1)
50
- .toString()
51
- .replace(".", ",")}`
52
- : roots.length === 1
53
- ? roots[0].toString().replace(".", ",")
54
- : `\\text{Aucun}`;
55
- const optimum = trinom.derivate().getRoots()[0];
56
- let xmin = 0, xmax = 0, ymin = 0, ymax = 0;
17
+ let trinom;
18
+ let statement = "";
19
+ let answer = "";
20
+ let xmin = -1;
21
+ let xmax = 1;
22
+ let ymin = -1;
23
+ let ymax = 1;
24
+ let commands;
57
25
  if (isAffine) {
58
- if (affine.calculate(xValue) > 0) {
59
- ymax = affine.calculate(xValue) + 1;
26
+ do {
27
+ affine = new polynomial_1.Polynomial([(0, randint_1.randint)(-9, 10), (0, randint_1.randint)(-5, 6, [0])]);
28
+ yValue = affine.calculate(xValue);
29
+ } while (Math.abs(yValue) > 10);
30
+ statement = `Déterminer le ou les antécédents de $${yValue}$ par la fonction $f$ représentée ci dessous.`;
31
+ answer = xValue.toString().replace(".", ",");
32
+ if (yValue > 0) {
33
+ ymax = yValue + 1;
60
34
  ymin = -1;
61
35
  }
62
36
  else {
63
- ymin = affine.calculate(xValue) - 1;
37
+ ymin = yValue - 1;
64
38
  ymax = 1;
65
39
  }
66
40
  if (xValue > 0) {
@@ -71,16 +45,35 @@ const getInverseImageFunctionGeogebra = () => {
71
45
  xmin = xValue - 1;
72
46
  xmax = 1;
73
47
  }
48
+ commands = [affine.toString()];
74
49
  }
75
50
  else {
51
+ let roots;
52
+ yValue = (0, randint_1.randint)(-5, 6);
53
+ do {
54
+ trinom = new polynomial_1.Polynomial([
55
+ (0, randint_1.randint)(-9, 10) - yValue,
56
+ (0, randint_1.randint)(-9, 10),
57
+ (0, randint_1.randint)(-4, 5, [0]),
58
+ ]);
59
+ roots = trinom.getRoots();
60
+ } while (roots.some((root) => Math.abs(root) > 10));
61
+ statement = `Déterminer le ou les antécédents de $${yValue}$ par la fonction $f$ représentée ci dessous.`;
62
+ answer = !roots.length
63
+ ? "\\text{Aucun}"
64
+ : roots
65
+ .map((r) => (0, round_1.round)(r, 1).toString().replace(".", ","))
66
+ .join("\\text{ et }");
67
+ const alpha = trinom.derivate().getRoots()[0];
68
+ const beta = trinom.calculate(alpha);
76
69
  if (roots.length === 2) {
77
- if (yValue > trinom.calculate(optimum) + yValue) {
70
+ if (yValue > beta + yValue) {
78
71
  ymax = yValue + 2;
79
- ymin = trinom.calculate(optimum) + yValue - 2;
72
+ ymin = beta + yValue - 2;
80
73
  }
81
74
  else {
82
75
  ymin = yValue - 2;
83
- ymax = trinom.calculate(optimum) + yValue + 2;
76
+ ymax = beta + yValue + 2;
84
77
  }
85
78
  xmax = Math.max(roots[0], roots[1]) + 1;
86
79
  xmin = Math.min(roots[0], roots[1]) - 1;
@@ -94,30 +87,27 @@ const getInverseImageFunctionGeogebra = () => {
94
87
  ymin = yValue - 5;
95
88
  ymax = yValue + 1;
96
89
  }
97
- xmax = optimum + 5;
98
- xmin = optimum - 5;
90
+ xmax = alpha + 5;
91
+ xmin = alpha - 5;
99
92
  }
100
93
  if (roots.length === 0) {
101
- if (yValue > trinom.calculate(optimum) + yValue) {
94
+ if (yValue > beta + yValue) {
102
95
  ymax = yValue + 1;
103
- ymin = trinom.calculate(optimum) + yValue - 3;
96
+ ymin = beta + yValue - 3;
104
97
  }
105
98
  else {
106
99
  ymin = yValue - 1;
107
- ymax = trinom.calculate(optimum) + yValue + 3;
100
+ ymax = beta + yValue + 3;
108
101
  }
109
- xmax = optimum + 5;
110
- xmin = optimum - 5;
102
+ xmax = alpha + 5;
103
+ xmin = alpha - 5;
111
104
  }
112
- }
113
- const commands = [
114
- isAffine
115
- ? affine.toString()
116
- : yValue !== 0
105
+ commands = [
106
+ yValue !== 0
117
107
  ? trinom.add(new polynomial_1.Polynomial([yValue])).toString()
118
108
  : trinom.toString(),
119
- ];
120
- answer = (answer + "").replaceAll(".", ",");
109
+ ];
110
+ }
121
111
  const question = {
122
112
  instruction: statement,
123
113
  answer,
@@ -127,8 +117,8 @@ const getInverseImageFunctionGeogebra = () => {
127
117
  answerFormat: "tex",
128
118
  identifiers: {
129
119
  xValue,
130
- affineCoeffs: affine.coefficients,
131
- trinomCoeffs: trinom.coefficients,
120
+ affineCoeffs: isAffine ? affine.coefficients : undefined,
121
+ trinomCoeffs: isAffine ? undefined : trinom.coefficients,
132
122
  yValue,
133
123
  isAffine,
134
124
  },
@@ -138,17 +128,20 @@ const getInverseImageFunctionGeogebra = () => {
138
128
  const getPropositions = (n, { answer, xValue, affineCoeffs, trinomCoeffs, yValue, isAffine }) => {
139
129
  const propositions = [];
140
130
  (0, exercise_1.addValidProp)(propositions, answer);
141
- const polynome1 = new polynomial_1.Polynomial(affineCoeffs);
142
- const roots = new polynomial_1.Polynomial(trinomCoeffs).getRoots();
131
+ (0, exercise_1.tryToAddWrongProp)(propositions, "\\text{Aucun}");
132
+ if (isAffine) {
133
+ const affine = new polynomial_1.Polynomial(affineCoeffs);
134
+ (0, exercise_1.tryToAddWrongProp)(propositions, affine.calculate(yValue).toString().replace(".", ","));
135
+ }
136
+ else {
137
+ const trinom = new polynomial_1.Polynomial(trinomCoeffs);
138
+ (0, exercise_1.tryToAddWrongProp)(propositions, trinom.calculate(yValue).toString().replace(".", ","));
139
+ }
143
140
  while (propositions.length < n) {
144
- const wrongAnswer = isAffine
145
- ? (0, randint_1.randint)(-9, 10, [polynome1.calculate(xValue)])
146
- : roots.length === 2
147
- ? `${(0, randint_1.randint)(-9, 10)}\\text{ et }${(0, randint_1.randint)(-9, 10)}`.replaceAll(".", ",")
148
- : roots.length === 1
149
- ? (0, randint_1.randint)(-9, 10, [roots[0]]).toString().replace(".", ",")
150
- : `\\text{Aucun}`;
151
- (0, exercise_1.tryToAddWrongProp)(propositions, wrongAnswer + "");
141
+ const wrongAnswer = (0, coinFlip_1.coinFlip)()
142
+ ? `${(0, randint_1.randint)(-9, 10)}`
143
+ : `${(0, randint_1.randint)(-9, 10)}\\text{ et }${(0, randint_1.randint)(-9, 10)}`;
144
+ (0, exercise_1.tryToAddWrongProp)(propositions, wrongAnswer);
152
145
  }
153
146
  return (0, shuffle_1.shuffle)(propositions);
154
147
  };
@@ -4,5 +4,6 @@ export { exponentialPrimitive } from "./exponentialPrimitive";
4
4
  export { logarithmePrimitive } from "./logarithmePrimitive";
5
5
  export { polynomialPrimitive } from "./polynomialPrimitive";
6
6
  export { sinCosPrimitive } from "./sinCosPrimitive";
7
+ export { sinUCosUPrimitive } from "./sinUCosUPrimitive";
7
8
  export * from "./usualPrimitives";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exercises/primitive/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exercises/primitive/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,cAAc,mBAAmB,CAAC"}
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.sinCosPrimitive = exports.polynomialPrimitive = exports.logarithmePrimitive = exports.exponentialPrimitive = exports.expUPrimitive = exports.constantPrimitive = void 0;
17
+ exports.sinUCosUPrimitive = exports.sinCosPrimitive = exports.polynomialPrimitive = exports.logarithmePrimitive = exports.exponentialPrimitive = exports.expUPrimitive = exports.constantPrimitive = void 0;
18
18
  var constantPrimitive_1 = require("./constantPrimitive");
19
19
  Object.defineProperty(exports, "constantPrimitive", { enumerable: true, get: function () { return constantPrimitive_1.constantPrimitive; } });
20
20
  var expUPrimitive_1 = require("./expUPrimitive");
@@ -27,5 +27,6 @@ var polynomialPrimitive_1 = require("./polynomialPrimitive");
27
27
  Object.defineProperty(exports, "polynomialPrimitive", { enumerable: true, get: function () { return polynomialPrimitive_1.polynomialPrimitive; } });
28
28
  var sinCosPrimitive_1 = require("./sinCosPrimitive");
29
29
  Object.defineProperty(exports, "sinCosPrimitive", { enumerable: true, get: function () { return sinCosPrimitive_1.sinCosPrimitive; } });
30
- // export { sinUCosUPrimitive } from "./sinUCosUPrimitive";
30
+ var sinUCosUPrimitive_1 = require("./sinUCosUPrimitive");
31
+ Object.defineProperty(exports, "sinUCosUPrimitive", { enumerable: true, get: function () { return sinUCosUPrimitive_1.sinUCosUPrimitive; } });
31
32
  __exportStar(require("./usualPrimitives"), exports);
package/lib/index.d.ts CHANGED
@@ -352,8 +352,8 @@ declare const mathExercises: (import("./exercises/exercise").MathExercise<{
352
352
  }> | import("./exercises/exercise").MathExercise<{
353
353
  xValue: number;
354
354
  yValue: number;
355
- affineCoeffs: number[];
356
- trinomCoeffs: number[];
355
+ affineCoeffs?: number[] | undefined;
356
+ trinomCoeffs?: number[] | undefined;
357
357
  isAffine: boolean;
358
358
  }> | import("./exercises/exercise").MathExercise<{
359
359
  k: number;
@@ -546,6 +546,9 @@ declare const mathExercises: (import("./exercises/exercise").MathExercise<{
546
546
  }> | import("./exercises/exercise").MathExercise<{
547
547
  a: number;
548
548
  isCos: boolean;
549
+ }> | import("./exercises/exercise").MathExercise<{
550
+ coeffs: number[];
551
+ isCos: boolean;
549
552
  }> | import("./exercises/exercise").MathExercise<{
550
553
  type: number;
551
554
  a?: number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqCA,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAA2B,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqCA,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAA2B,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -233,23 +233,25 @@ class Polynomial {
233
233
  // }
234
234
  integrateToNode(opts) {
235
235
  let integralPolynomial = new variableNode_1.VariableNode("C");
236
+ const varNode = new variableNode_1.VariableNode(this.variable);
236
237
  for (let i = 0; i < this.degree + 1; i++) {
237
238
  const coeff = this.coefficients[i];
238
239
  if (coeff === 0)
239
240
  continue;
240
241
  const nodeCoeff = new rational_1.Rational(coeff, i + 1).simplify().toTree();
241
242
  const powerNode = i + 1 === 1
242
- ? new variableNode_1.VariableNode("x")
243
- : new powerNode_1.PowerNode(new variableNode_1.VariableNode("x"), new numberNode_1.NumberNode(i + 1), opts);
243
+ ? varNode
244
+ : new powerNode_1.PowerNode(varNode, new numberNode_1.NumberNode(i + 1), opts);
244
245
  let terme;
245
- if (nodeCoeff.toTex() === "1")
246
+ const coeffTex = nodeCoeff.toTex();
247
+ if (coeffTex === "1")
246
248
  terme = powerNode;
247
- else if (nodeCoeff.toTex() === "-1")
249
+ else if (coeffTex === "-1")
248
250
  terme = new oppositeNode_1.OppositeNode(powerNode, opts);
249
251
  else {
250
252
  terme = new multiplyNode_1.MultiplyNode(nodeCoeff, i + 1 === 1
251
- ? new variableNode_1.VariableNode("x")
252
- : new powerNode_1.PowerNode(new variableNode_1.VariableNode("x"), new numberNode_1.NumberNode(i + 1), opts), opts);
253
+ ? varNode
254
+ : new powerNode_1.PowerNode(varNode, new numberNode_1.NumberNode(i + 1), opts), opts);
253
255
  }
254
256
  integralPolynomial = new addNode_1.AddNode(terme, integralPolynomial, opts);
255
257
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rationalFrac.d.ts","sourceRoot":"","sources":["../../../src/math/polynomials/rationalFrac.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAGrD,qBAAa,YAAY;IACvB,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,EAAE,UAAU,CAAC;gBACN,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;IAI9C,MAAM;IAGN,QAAQ;CAwCT"}
1
+ {"version":3,"file":"rationalFrac.d.ts","sourceRoot":"","sources":["../../../src/math/polynomials/rationalFrac.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAGrD,qBAAa,YAAY;IACvB,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,EAAE,UAAU,CAAC;gBACN,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;IAI9C,MAAM;IAGN,QAAQ;CAuCT"}
@@ -18,9 +18,9 @@ class RationalFrac {
18
18
  if (this.num.coefficients.length === 1 && this.num.coefficients[0] === 0)
19
19
  return new integer_1.Integer(0);
20
20
  const numCoeffs = this.num.coefficients.filter((c) => c !== 0);
21
- const numPGCD = numCoeffs.length > 1 ? (0, gcd_1.multigcd)(...numCoeffs) : numCoeffs[0];
21
+ const numPGCD = numCoeffs.length > 1 ? (0, gcd_1.gcd)(...numCoeffs) : numCoeffs[0];
22
22
  const denumCoeffs = this.denum.coefficients.filter((c) => c !== 0);
23
- const denumPGCD = denumCoeffs.length > 1 ? (0, gcd_1.multigcd)(...denumCoeffs) : denumCoeffs[0];
23
+ const denumPGCD = denumCoeffs.length > 1 ? (0, gcd_1.gcd)(...denumCoeffs) : denumCoeffs[0];
24
24
  const rational = new rational_1.Rational(numPGCD, denumPGCD);
25
25
  if (rational.isIrreductible()) {
26
26
  return this;
@@ -92,7 +92,7 @@ class Trinom extends polynomial_1.Polynomial {
92
92
  let [sqrtA, sqrtB] = new real_1.SquareRoot(delta).getSimplifiedCoeffs();
93
93
  let denum = 2 * this.a;
94
94
  let trueB = this.b;
95
- const pgcd = (0, gcd_1.multigcd)(sqrtA, trueB, denum);
95
+ const pgcd = (0, gcd_1.gcd)(sqrtA, trueB, denum);
96
96
  [sqrtA, trueB, denum] = [sqrtA, trueB, denum].map((n) => n / pgcd);
97
97
  const sqrtNode = sqrtA === 1
98
98
  ? new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(sqrtB))
@@ -1,3 +1,2 @@
1
- export declare function gcd(a: number, b: number): number;
2
- export declare function multigcd(...args: number[]): number;
1
+ export declare function gcd(...args: number[]): number;
3
2
  //# sourceMappingURL=gcd.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gcd.d.ts","sourceRoot":"","sources":["../../../../src/math/utils/arithmetic/gcd.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAGlD"}
1
+ {"version":3,"file":"gcd.d.ts","sourceRoot":"","sources":["../../../../src/math/utils/arithmetic/gcd.ts"],"names":[],"mappings":"AAIA,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAG7C"}
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.multigcd = exports.gcd = void 0;
4
- function gcd(a, b) {
3
+ exports.gcd = void 0;
4
+ function pgcd(a, b) {
5
5
  return b ? gcd(b, a % b) : a;
6
6
  }
7
- exports.gcd = gcd;
8
- function multigcd(...args) {
7
+ function gcd(...args) {
9
8
  if (args.length === 2)
10
- return gcd(args[0], args[1]);
9
+ return pgcd(args[0], args[1]);
11
10
  else
12
- return gcd(args[0], multigcd(...args.slice(1)));
11
+ return gcd(args[0], gcd(...args.slice(1)));
13
12
  }
14
- exports.multigcd = multigcd;
13
+ exports.gcd = gcd;
package/lib/server.js CHANGED
@@ -35,22 +35,12 @@ const express_1 = __importDefault(require("express"));
35
35
  const body_parser_1 = __importDefault(require("body-parser"));
36
36
  const dotenv_1 = __importDefault(require("dotenv"));
37
37
  const cors_1 = __importDefault(require("cors"));
38
- const rational_1 = require("./math/numbers/rationals/rational");
39
- const multiplyNode_1 = require("./tree/nodes/operators/multiplyNode");
40
- const numberNode_1 = require("./tree/nodes/numbers/numberNode");
41
- const oppositeNode_1 = require("./tree/nodes/functions/oppositeNode");
42
- const gcd_1 = require("./math/utils/arithmetic/gcd");
43
38
  const jsonParser = body_parser_1.default.json();
44
39
  const allExercises = [...exercises];
45
40
  const runServer = () => {
46
41
  dotenv_1.default.config();
47
42
  const app = (0, express_1.default)();
48
43
  app.use((0, cors_1.default)());
49
- console.log((0, gcd_1.multigcd)(5, 11, 15, 25, 55));
50
- const frac = new rational_1.Rational(-2, 3).simplify().toTree();
51
- console.log(frac.toAllValidTexs());
52
- const prod = new oppositeNode_1.OppositeNode(new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(2), new numberNode_1.NumberNode(3)));
53
- console.log(prod.toAllValidTexs());
54
44
  console.log(exercises.length);
55
45
  app.get("/", (req, res) => {
56
46
  res.json(allExercises);
@@ -1 +1 @@
1
- {"version":3,"file":"oppositeNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/functions/oppositeNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMtD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAkB,MAAM,gBAAgB,CAAC;AAE5E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMjD,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,YAAY,CAEzD;AAGD,qBAAa,YAAa,YAAW,YAAY;IAC/C,EAAE,EAAE,YAAY,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,CAAC,EAAE,WAAW,CAAC;gBACP,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,WAAW;IAMpD,YAAY,IAAI,MAAM;IAGtB,KAAK,IAAI,MAAM;IAef,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,EAAE;IAqCtD;;;;OAIG;IACH,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE;CAQ7C"}
1
+ {"version":3,"file":"oppositeNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/functions/oppositeNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMtD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAkB,MAAM,gBAAgB,CAAC;AAE5E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMjD,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,YAAY,CAEzD;AAGD,qBAAa,YAAa,YAAW,YAAY;IAC/C,EAAE,EAAE,YAAY,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,CAAC,EAAE,WAAW,CAAC;gBACP,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,WAAW;IAMpD,YAAY,IAAI,MAAM;IAGtB,KAAK,IAAI,MAAM;IAef,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,EAAE;IAgCtD;;;;OAIG;IACH,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE;CAQ7C"}
@@ -6,6 +6,7 @@ const node_1 = require("../node");
6
6
  const operatorNode_1 = require("../operators/operatorNode");
7
7
  const functionNode_1 = require("./functionNode");
8
8
  const numberNode_1 = require("../numbers/numberNode");
9
+ const fractionNode_1 = require("../operators/fractionNode");
9
10
  function isOppositeNode(a) {
10
11
  return (0, functionNode_1.isFunctionNode)(a) && a.id === functionNode_1.FunctionsIds.opposite;
11
12
  }
@@ -40,31 +41,14 @@ class OppositeNode {
40
41
  const externalNodes = [];
41
42
  //! est ce qu'il faut faire ici des simplifications du type -ln(2) => 1/ln(2)
42
43
  //! ou meme -(a+b) => -a - b
43
- // if (isMultiplyNode(this.child))
44
- // res.push(
45
- // ...new MultiplyNode(
46
- // new OppositeNode(this.child.leftChild),
47
- // this.child.rightChild,
48
- // ).toEquivalentNodes(options),
49
- // );
50
- // else if (isDivideNode(this.child))
51
- // res.push(
52
- // ...new DivideNode(
53
- // new OppositeNode(this.child.leftChild),
54
- // this.child.rightChild,
55
- // ).toEquivalentNodes(options),
56
- // );
57
- // else if (isFractionNode(this.child))
58
- // res.push(
59
- // ...new FractionNode(
60
- // new OppositeNode(this.child.leftChild),
61
- // this.child.rightChild,
62
- // ).toEquivalentNodes(options),
63
- // );
64
- // else {
44
+ //!version simplifiée pour juste gérer les fractions
45
+ //!la bonne solution serait de parse l'arbre et déplacer l'opposite sur chaque child d'un sous arbre multiplicatif
65
46
  const childNodes = this.child.toEquivalentNodes(options);
66
47
  childNodes.forEach((childNode) => {
67
48
  res.push(new OppositeNode(childNode));
49
+ if ((0, fractionNode_1.isFractionNode)(childNode)) {
50
+ res.push(new fractionNode_1.FractionNode(new OppositeNode(childNode.leftChild), childNode.rightChild, { allowMinusAnywhereInFraction: true }), new fractionNode_1.FractionNode(childNode.leftChild, new OppositeNode(childNode.rightChild), { allowMinusAnywhereInFraction: true }));
51
+ }
68
52
  });
69
53
  // }
70
54
  return res;
@@ -44,9 +44,9 @@ class MultiplyNode {
44
44
  let leftTex = this.leftChild.toTex();
45
45
  let rightTex = this.rightChild.toTex();
46
46
  if (leftTex === "1") {
47
- if ((0, numberNode_1.isNumberNode)(this.rightChild)) {
48
- return rightTex;
49
- }
47
+ // if (isNumberNode(this.rightChild) || isVariableNode(this.rightChild)) {
48
+ return rightTex;
49
+ // }
50
50
  }
51
51
  if ((0, operatorNode_1.isOperatorNode)(this.leftChild)) {
52
52
  if ([operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract, operatorNode_1.OperatorIds.divide].includes(this.leftChild.id))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "math-exercises",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Math exercises generator for middle school and high school",
5
5
  "main": "lib/index.js",
6
6
  "files": [