math-exercises 2.2.51 → 2.2.53

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 (66) hide show
  1. package/lib/exercises/math/calcul/fractions/simplifyFraction.d.ts.map +1 -1
  2. package/lib/exercises/math/calcul/fractions/simplifyFraction.js +12 -2
  3. package/lib/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.d.ts +10 -0
  4. package/lib/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.d.ts.map +1 -0
  5. package/lib/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.js +122 -0
  6. package/lib/exercises/math/calcul/proportionality/index.d.ts +2 -0
  7. package/lib/exercises/math/calcul/proportionality/index.d.ts.map +1 -1
  8. package/lib/exercises/math/calcul/proportionality/index.js +2 -0
  9. package/lib/exercises/math/calcul/proportionality/isTableProportionalNonInteger.d.ts +11 -0
  10. package/lib/exercises/math/calcul/proportionality/isTableProportionalNonInteger.d.ts.map +1 -0
  11. package/lib/exercises/math/calcul/proportionality/isTableProportionalNonInteger.js +113 -0
  12. package/lib/exercises/math/calculLitteral/equation/equationWithDistributivity.d.ts +16 -0
  13. package/lib/exercises/math/calculLitteral/equation/equationWithDistributivity.d.ts.map +1 -0
  14. package/lib/exercises/math/calculLitteral/equation/equationWithDistributivity.js +128 -0
  15. package/lib/exercises/math/calculLitteral/equation/index.d.ts +1 -0
  16. package/lib/exercises/math/calculLitteral/equation/index.d.ts.map +1 -1
  17. package/lib/exercises/math/calculLitteral/equation/index.js +1 -0
  18. package/lib/exercises/math/calculLitteral/factorisation/factoType1Exercise.d.ts.map +1 -1
  19. package/lib/exercises/math/calculLitteral/factorisation/factoType1Exercise.js +5 -1
  20. package/lib/exercises/math/functions/basics/imageFunctionGeogebra.d.ts +5 -4
  21. package/lib/exercises/math/functions/basics/imageFunctionGeogebra.d.ts.map +1 -1
  22. package/lib/exercises/math/functions/basics/imageFunctionGeogebra.js +44 -42
  23. package/lib/exercises/math/functions/parity/parityFromGraph.js +1 -1
  24. package/lib/exercises/math/functions/trinoms/secondDegreeInequation.d.ts.map +1 -1
  25. package/lib/exercises/math/probaStat/probaFromTableWithContext.d.ts +4 -1
  26. package/lib/exercises/math/probaStat/probaFromTableWithContext.d.ts.map +1 -1
  27. package/lib/exercises/math/probaStat/probaFromTableWithContext.js +18 -6
  28. package/lib/exercises/math/probaStat/probabilityTree.d.ts +4 -1
  29. package/lib/exercises/math/probaStat/probabilityTree.d.ts.map +1 -1
  30. package/lib/exercises/math/probaStat/probabilityTree.js +52 -21
  31. package/lib/exercises/math/probaStat/stats1var/averageWithTable.d.ts.map +1 -1
  32. package/lib/exercises/math/probaStat/stats1var/averageWithTable.js +2 -1
  33. package/lib/exercises/math/squareRoots/index.d.ts +1 -0
  34. package/lib/exercises/math/squareRoots/index.d.ts.map +1 -1
  35. package/lib/exercises/math/squareRoots/index.js +1 -0
  36. package/lib/exercises/math/squareRoots/squareRootsProducts.d.ts +10 -0
  37. package/lib/exercises/math/squareRoots/squareRootsProducts.d.ts.map +1 -0
  38. package/lib/exercises/math/squareRoots/squareRootsProducts.js +83 -0
  39. package/lib/exercises/options/allowNonIrreductibleFractions.d.ts +3 -0
  40. package/lib/exercises/options/allowNonIrreductibleFractions.d.ts.map +1 -0
  41. package/lib/exercises/options/allowNonIrreductibleFractions.js +10 -0
  42. package/lib/geogebra/geogebraConstructor.js +11 -10
  43. package/lib/geogebra/lagrange.d.ts +8 -0
  44. package/lib/geogebra/lagrange.d.ts.map +1 -0
  45. package/lib/geogebra/lagrange.js +73 -0
  46. package/lib/geogebra/spline.d.ts +11 -0
  47. package/lib/geogebra/spline.d.ts.map +1 -0
  48. package/lib/geogebra/spline.js +74 -0
  49. package/lib/index.d.ts +36 -6
  50. package/lib/index.d.ts.map +1 -1
  51. package/lib/playground.d.ts.map +1 -1
  52. package/lib/playground.js +2 -5
  53. package/lib/tree/nodes/algebraicNode.d.ts +1 -0
  54. package/lib/tree/nodes/algebraicNode.d.ts.map +1 -1
  55. package/lib/tree/nodes/equations/equalNode.d.ts +2 -0
  56. package/lib/tree/nodes/equations/equalNode.d.ts.map +1 -1
  57. package/lib/tree/nodes/equations/equalNode.js +7 -1
  58. package/lib/tree/nodes/inequations/inequationNode.d.ts +3 -2
  59. package/lib/tree/nodes/inequations/inequationNode.d.ts.map +1 -1
  60. package/lib/tree/nodes/nodeConstructor.d.ts.map +1 -1
  61. package/lib/tree/nodes/operators/multiplyNode.d.ts +1 -1
  62. package/lib/tree/nodes/operators/multiplyNode.d.ts.map +1 -1
  63. package/lib/tree/nodes/operators/multiplyNode.js +46 -26
  64. package/lib/tree/nodes/sets/intervalNode.d.ts +5 -4
  65. package/lib/tree/nodes/sets/intervalNode.d.ts.map +1 -1
  66. package/package.json +1 -1
@@ -0,0 +1,11 @@
1
+ import { Point } from "../math/geometry/point";
2
+ import { IntervalNode } from "../tree/nodes/sets/intervalNode";
3
+ export declare abstract class SplineConstructor {
4
+ random(): Spline;
5
+ }
6
+ export declare class Spline {
7
+ points: number[][];
8
+ constructor(interval: IntervalNode, points?: Point[]);
9
+ getCommands(): string[];
10
+ }
11
+ //# sourceMappingURL=spline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline.d.ts","sourceRoot":"","sources":["../../src/geogebra/spline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAKlD,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAKlE,8BAAsB,iBAAiB;IACrC,MAAM;CAQP;AACD,qBAAa,MAAM;IACjB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;gBAEP,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE;IAuDpD,WAAW;CAUZ"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Spline = exports.SplineConstructor = void 0;
4
+ const randfloat_1 = require("../math/utils/random/randfloat");
5
+ const randint_1 = require("../math/utils/random/randint");
6
+ const closure_1 = require("../tree/nodes/sets/closure");
7
+ const intervalNode_1 = require("../tree/nodes/sets/intervalNode");
8
+ const doWhile_1 = require("../utils/doWhile");
9
+ const colors_1 = require("./colors");
10
+ class SplineConstructor {
11
+ random() {
12
+ const a = (0, randint_1.randint)(-10, 0);
13
+ const b = (0, doWhile_1.doWhile)(() => (0, randint_1.randint)(0, 10), (x) => Math.abs(x - a) < 5);
14
+ return new Spline(new intervalNode_1.IntervalNode(a.toTree(), b.toTree(), closure_1.ClosureType.FF));
15
+ }
16
+ }
17
+ exports.SplineConstructor = SplineConstructor;
18
+ class Spline {
19
+ constructor(interval, points) {
20
+ const a = interval.a.evaluate({});
21
+ const b = interval.b.evaluate();
22
+ this.points = [];
23
+ const sortedPoints = points
24
+ ?.map((a) => [a.x.evaluate({}), a.y.evaluate({})])
25
+ .sort((a, b) => a[0] - b[0]);
26
+ if (!Number.isFinite(a) || !Number.isFinite(b))
27
+ throw Error("unimplement infinity spline");
28
+ const length = Math.abs(b - a);
29
+ const nbOfSlices = sortedPoints?.length
30
+ ? sortedPoints.length + 3
31
+ : (0, randint_1.randint)(4, 8);
32
+ const step = length / nbOfSlices;
33
+ const yCoeff = 1 / nbOfSlices;
34
+ for (let i = 0; i < nbOfSlices; i++) {
35
+ const xMin = a + i * step;
36
+ const xMax = xMin + step;
37
+ if (i === 0) {
38
+ const pointInSlice = sortedPoints?.length && sortedPoints[0][0] < xMax;
39
+ this.points.push([
40
+ a,
41
+ pointInSlice
42
+ ? sortedPoints[0][1] + yCoeff * (0, randfloat_1.randfloat)(-2, 3)
43
+ : (0, randfloat_1.randfloat)(-10, 10),
44
+ ]);
45
+ }
46
+ const fittedPoints = sortedPoints?.filter((point) => point[0] >= xMin && point[0] < xMax);
47
+ this.points.push(...(fittedPoints ?? []));
48
+ if (!fittedPoints?.length && i > 0 && i < nbOfSlices - 1) {
49
+ const nextYInSlice = sortedPoints?.find((p) => p[0] >= xMax && p[0] < xMax + step)?.[1];
50
+ const x = (0, randfloat_1.randfloat)(xMin + step / 4, xMax - step / 4, 6);
51
+ const prevy = this.points[this.points.length - 1][1];
52
+ const y = nextYInSlice !== undefined
53
+ ? prevy + (nextYInSlice - prevy) / 2
54
+ : prevy + yCoeff * (0, randfloat_1.randfloat)(-3, 4, 5);
55
+ this.points.push([x, y]);
56
+ }
57
+ if (i === nbOfSlices - 1) {
58
+ const prevY = this.points[this.points.length - 1][1];
59
+ this.points.push([b, prevY + yCoeff * (0, randfloat_1.randfloat)(-2, 3)]);
60
+ }
61
+ }
62
+ }
63
+ getCommands() {
64
+ const commands = [
65
+ `S = Spline(${this.points
66
+ .map((point) => `(${point[0]},${point[1]})`)
67
+ .join(",")})`,
68
+ "SetFixed(S, true)",
69
+ `SetColor(S, "${(0, colors_1.randomColor)()}")`,
70
+ ];
71
+ return commands;
72
+ }
73
+ }
74
+ exports.Spline = Spline;
package/lib/index.d.ts CHANGED
@@ -126,6 +126,17 @@ declare const mathExercises: (import("./exercises/exercise").Exercise<{
126
126
  scale: number;
127
127
  isSmallScale: boolean;
128
128
  fakeDistance: number;
129
+ }, {}> | import("./exercises/exercise").Exercise<{
130
+ coeffIds: any;
131
+ xValues: any[];
132
+ yValues: any[];
133
+ isProportionnal: boolean;
134
+ type: number;
135
+ }, {}> | import("./exercises/exercise").Exercise<{
136
+ coeffIds: any;
137
+ xValues: any[];
138
+ yValues: any[];
139
+ type: number;
129
140
  }, {}> | import("./exercises/exercise").Exercise<{
130
141
  precisionAsked: number;
131
142
  decimal: number;
@@ -254,6 +265,16 @@ declare const mathExercises: (import("./exercises/exercise").Exercise<{
254
265
  solutionNodeIds: any;
255
266
  equationNodeIds: any;
256
267
  }, {}> | import("./exercises/exercise").Exercise<{
268
+ type: number;
269
+ a: number;
270
+ b: number;
271
+ c: number;
272
+ d: number;
273
+ e: number;
274
+ f: number;
275
+ }, {
276
+ integerSolutions: boolean;
277
+ }> | import("./exercises/exercise").Exercise<{
257
278
  a: number;
258
279
  b: number;
259
280
  }, {}> | import("./exercises/exercise").Exercise<{
@@ -603,10 +624,10 @@ declare const mathExercises: (import("./exercises/exercise").Exercise<{
603
624
  poly2: number[];
604
625
  xValue: number;
605
626
  }, {}> | import("./exercises/exercise").Exercise<{
606
- rand: boolean;
607
- poly1: number[];
608
- poly2: number[];
609
- xValue: number;
627
+ isSpline: boolean;
628
+ splinePoints: number[][];
629
+ x: number;
630
+ y: number;
610
631
  }, {}> | import("./exercises/exercise").Exercise<{
611
632
  poly1: number[];
612
633
  xValue: number;
@@ -1247,7 +1268,9 @@ declare const mathExercises: (import("./exercises/exercise").Exercise<{
1247
1268
  AD: number;
1248
1269
  BC: number;
1249
1270
  BD: number;
1250
- }, {}> | import("./exercises/exercise").Exercise<{
1271
+ }, {
1272
+ allowApproximate: string;
1273
+ }> | import("./exercises/exercise").Exercise<{
1251
1274
  randomValues: number[];
1252
1275
  randomEffectives: number[];
1253
1276
  }, {}> | import("./exercises/exercise").Exercise<{
@@ -1299,7 +1322,9 @@ declare const mathExercises: (import("./exercises/exercise").Exercise<{
1299
1322
  event: string;
1300
1323
  type: string;
1301
1324
  probaFrac: number[];
1302
- }, {}> | import("./exercises/exercise").Exercise<{
1325
+ }, {
1326
+ allowNonIrreductible?: boolean | undefined;
1327
+ }> | import("./exercises/exercise").Exercise<{
1303
1328
  nX: number;
1304
1329
  a: number;
1305
1330
  b: number;
@@ -1485,6 +1510,11 @@ declare const mathExercises: (import("./exercises/exercise").Exercise<{
1485
1510
  x: number;
1486
1511
  y: number;
1487
1512
  z: number | undefined;
1513
+ }, {}> | import("./exercises/exercise").Exercise<{
1514
+ a: number;
1515
+ b: number;
1516
+ c: number;
1517
+ d: number;
1488
1518
  }, {}> | import("./exercises/exercise").Exercise<{
1489
1519
  valueIndex: number;
1490
1520
  isCos: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA6B,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,UAAU,YAMtB,CAAC"}
1
+ {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,UAAU,YAGtB,CAAC"}
package/lib/playground.js CHANGED
@@ -2,10 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.playground = void 0;
4
4
  const playground = () => {
5
- // const mul = new MultiplyNode(
6
- // new SqrtNode((2).toTree()),
7
- // (-1).toTree(),
8
- // ).simplify();
9
- // console.log(mul.toTex());
5
+ // const node = multiply(sqrt(3), sqrt(8)).simplify();
6
+ // console.log(node.toTex());
10
7
  };
11
8
  exports.playground = playground;
@@ -5,6 +5,7 @@ export type SimplifyOptions = {
5
5
  keepPowers?: boolean;
6
6
  scientific?: number;
7
7
  isDegree?: boolean;
8
+ towardsDistribute?: boolean;
8
9
  };
9
10
  export interface AlgebraicNode extends Node {
10
11
  evaluate: (vars?: Record<string, number>) => number;
@@ -1 +1 @@
1
- {"version":3,"file":"algebraicNode.d.ts","sourceRoot":"","sources":["../../../src/tree/nodes/algebraicNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,wBAAwB,CAAC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AC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,aAAa,CAAC;IAC7E,iBAAiB,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,KAAK,aAAa,EAAE,CAAC;IAC3D,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,eAAe,KAAK,aAAa,CAAC;IACpD,MAAM,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC;IACzC,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,eAAe,SAAU,IAAI,0BACA,CAAC"}
@@ -1,4 +1,6 @@
1
+ import { AlgebraicNode } from "../algebraicNode";
1
2
  import { Node, NodeIds, NodeOptions, NodeType } from "../node";
3
+ export declare const equal: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string) => EqualNode;
2
4
  export declare const isEqualNode: (node: Node) => node is EqualNode;
3
5
  export declare class EqualNode implements Node {
4
6
  leftChild: Node;
@@ -1 +1 @@
1
- {"version":3,"file":"equalNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/equations/equalNode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,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;;;;;;;;;IAOb,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;CAUT"}
1
+ {"version":3,"file":"equalNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/equations/equalNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,KAAK,MACb,aAAa,GAAG,MAAM,GAAG,MAAM,KAC/B,aAAa,GAAG,MAAM,GAAG,MAAM,cAOnC,CAAC;AAEF,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;;;;;;;;;IAOb,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;CAUT"}
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EqualNode = exports.isEqualNode = void 0;
3
+ exports.EqualNode = exports.isEqualNode = exports.equal = void 0;
4
4
  const node_1 = require("../node");
5
+ const equal = (a, b) => {
6
+ const nodeA = typeof a === "number" ? a.toTree() : typeof a === "string" ? a.toTree() : a;
7
+ const nodeB = typeof b === "number" ? b.toTree() : typeof b === "string" ? b.toTree() : b;
8
+ return new EqualNode(nodeA, nodeB);
9
+ };
10
+ exports.equal = equal;
5
11
  const isEqualNode = (node) => node.type === node_1.NodeType.equality;
6
12
  exports.isEqualNode = isEqualNode;
7
13
  class EqualNode {
@@ -1,13 +1,14 @@
1
1
  import { InegalitySymbols } from "../../../math/inequations/inequation";
2
2
  import { Node, NodeIds, NodeOptions, NodeType } from "../node";
3
3
  import { IntervalNode } from "../sets/intervalNode";
4
+ import { AlgebraicNode } from "../algebraicNode";
4
5
  export declare class InequationNode implements Node {
5
6
  opts?: NodeOptions | undefined;
6
7
  type: NodeType;
7
8
  tex: string;
8
- children: Node[];
9
+ children: AlgebraicNode[];
9
10
  symbols: InegalitySymbols[];
10
- constructor(children: Node[], symbols: InegalitySymbols[] | InegalitySymbols);
11
+ constructor(children: AlgebraicNode[], symbols: InegalitySymbols[] | InegalitySymbols);
11
12
  toIdentifiers(): {
12
13
  id: NodeIds;
13
14
  children: ({
@@ -1 +1 @@
1
- {"version":3,"file":"inequationNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/inequations/inequationNode.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEjB,MAAM,mCAAmC,CAAC;AAK3C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,qBAAa,cAAe,YAAW,IAAI;IACzC,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,OAAO,EAAE,gBAAgB,EAAE,CAAC;gBAE1B,QAAQ,EAAE,IAAI,EAAE,EAChB,OAAO,EAAE,gBAAgB,EAAE,GAAG,gBAAgB;IAuBhD,aAAa;;;;;;;IAOb,UAAU;IA6CV,UAAU;IAQV,cAAc;IAGd,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS;IAYhD,YAAY;IAGZ,QAAQ;IAGR,SAAS;IAGT,KAAK;IAGL,QAAQ;CAGT"}
1
+ {"version":3,"file":"inequationNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/inequations/inequationNode.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEjB,MAAM,mCAAmC,CAAC;AAK3C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,cAAe,YAAW,IAAI;IACzC,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,OAAO,EAAE,gBAAgB,EAAE,CAAC;gBAE1B,QAAQ,EAAE,aAAa,EAAE,EACzB,OAAO,EAAE,gBAAgB,EAAE,GAAG,gBAAgB;IAuBhD,aAAa;;;;;;;IAOb,UAAU;IA6CV,UAAU;IAQV,cAAc;IAGd,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS;IAYhD,YAAY;IAGZ,QAAQ;IAGR,SAAS;IAGT,KAAK;IAGL,QAAQ;CAGT"}
@@ -1 +1 @@
1
- {"version":3,"file":"nodeConstructor.d.ts","sourceRoot":"","sources":["../../../src/tree/nodes/nodeConstructor.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAkBvC,8BAAsB,eAAe;IACnC,MAAM,CAAC,eAAe,CACpB,WAAW,EAAE;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjD,IAAI;CAwQR"}
1
+ {"version":3,"file":"nodeConstructor.d.ts","sourceRoot":"","sources":["../../../src/tree/nodes/nodeConstructor.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAkBvC,8BAAsB,eAAe;IACnC,MAAM,CAAC,eAAe,CACpB,WAAW,EAAE;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjD,IAAI;CA4QR"}
@@ -2,7 +2,7 @@ import { Node, NodeIds, NodeOptions, NodeType, ToTexOptions } from "../node";
2
2
  import { CommutativeOperatorNode, OperatorIds } from "./operatorNode";
3
3
  import { AlgebraicNode, SimplifyOptions } from "../algebraicNode";
4
4
  export declare function isMultiplyNode(a: Node): a is MultiplyNode;
5
- export declare const multiply: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string) => MultiplyNode;
5
+ export declare const multiply: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string, opts?: NodeOptions) => MultiplyNode;
6
6
  export declare const sortMultiplyNodes: (arr: AlgebraicNode[]) => void;
7
7
  export declare class MultiplyNode implements CommutativeOperatorNode {
8
8
  opts?: NodeOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"multiplyNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/operators/multiplyNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EACL,uBAAuB,EACvB,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAYxB,OAAO,EACL,aAAa,EACb,eAAe,EAEhB,MAAM,kBAAkB,CAAC;AAQ1B,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,YAAY,CAEzD;AAED,eAAO,MAAM,QAAQ,MAChB,aAAa,GAAG,MAAM,GAAG,MAAM,KAC/B,aAAa,GAAG,MAAM,GAAG,MAAM,iBA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,cAAc,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,YAAY,CAEzD;AAED,eAAO,MAAM,QAAQ,MAChB,aAAa,GAAG,MAAM,GAAG,MAAM,KAC/B,aAAa,GAAG,MAAM,GAAG,MAAM,SAC3B,WAAW,iBAOnB,CAAC;AACF,eAAO,MAAM,iBAAiB,QAAS,aAAa,EAAE,SAWrD,CAAC;AACF,qBAAa,YAAa,YAAW,uBAAuB;IAC1D,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,EAAE,EAAE,WAAW,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,aAAa,CAAC;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;gBAEjB,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,aAAa,EACzB,IAAI,CAAC,EAAE,WAAW;IAUpB,OAAO,aAGL;IAEF,YAAY,IAAI,MAAM;IAItB,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM;IAqErC,SAAS;IAkDT,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,YAAY,EAAE;IAyFrD,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE;IAG5C,aAAa;;;;;;;;;IAYb,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAItC,IAAI;IAGJ,cAAc;IACd,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,aAAa;IAoJ/C,MAAM,CAAC,IAAI,EAAE,aAAa;IAU1B,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;CAMzD"}
@@ -19,14 +19,15 @@ const functionNode_1 = require("../functions/functionNode");
19
19
  const addNode_1 = require("./addNode");
20
20
  const round_1 = require("../../../math/utils/round");
21
21
  const colorize_1 = require("../../../utils/latex/colorize");
22
+ const substractNode_1 = require("./substractNode");
22
23
  function isMultiplyNode(a) {
23
24
  return (0, operatorNode_1.isOperatorNode)(a) && a.id === operatorNode_1.OperatorIds.multiply;
24
25
  }
25
26
  exports.isMultiplyNode = isMultiplyNode;
26
- const multiply = (a, b) => {
27
+ const multiply = (a, b, opts) => {
27
28
  const nodeA = typeof a === "number" ? a.toTree() : typeof a === "string" ? a.toTree() : a;
28
29
  const nodeB = typeof b === "number" ? b.toTree() : typeof b === "string" ? b.toTree() : b;
29
- return new MultiplyNode(nodeA, nodeB);
30
+ return new MultiplyNode(nodeA, nodeB, opts);
30
31
  };
31
32
  exports.multiply = multiply;
32
33
  const sortMultiplyNodes = (arr) => {
@@ -92,7 +93,8 @@ class MultiplyNode {
92
93
  (0, numberNode_1.isNumberNode)(this.rightChild) ||
93
94
  ((0, variableNode_1.isVariableNode)(this.leftChild) &&
94
95
  (0, variableNode_1.isVariableNode)(this.rightChild) &&
95
- this.leftChild.name === this.rightChild.name));
96
+ this.leftChild.name === this.rightChild.name) ||
97
+ ((0, sqrtNode_1.isSqrtNode)(this.leftChild) && (0, sqrtNode_1.isSqrtNode)(this.rightChild)));
96
98
  if ((0, operatorNode_1.isOperatorNode)(this.rightChild)) {
97
99
  showTimesSign ||= [operatorNode_1.OperatorIds.fraction].includes(this.rightChild.id);
98
100
  }
@@ -235,36 +237,40 @@ class MultiplyNode {
235
237
  const leftSimplified = this.leftChild.simplify(opts);
236
238
  const rightSimplified = this.rightChild.simplify(opts);
237
239
  const copy = new MultiplyNode(leftSimplified, rightSimplified, this.opts);
238
- /**get externals nodes
240
+ /**get externals nodes (= extremités du sous arbre non multiplicatif)
239
241
  * les opposites sont supprimés et on ajoute *-1 à la fin si leur nb est impair
240
242
  */
241
- let externals = [];
242
- let oppositesCount = 0;
243
- const recursive = (node) => {
244
- if (isMultiplyNode(node)) {
245
- recursive(node.leftChild);
246
- recursive(node.rightChild);
247
- }
248
- else if ((0, oppositeNode_1.isOppositeNode)(node)) {
249
- oppositesCount++;
250
- recursive(node.child);
251
- }
252
- else if ((0, numberNode_1.isNumberNode)(node) && node.value < 0) {
253
- oppositesCount++;
254
- externals.push(new numberNode_1.NumberNode(Math.abs(node.value)));
255
- }
256
- else {
257
- externals.push(node);
243
+ const getExternalNodes = (root) => {
244
+ let oppositesCount = 0;
245
+ const res = [];
246
+ const recursive = (node) => {
247
+ if (isMultiplyNode(node)) {
248
+ recursive(node.leftChild);
249
+ recursive(node.rightChild);
250
+ }
251
+ else if ((0, oppositeNode_1.isOppositeNode)(node)) {
252
+ oppositesCount++;
253
+ recursive(node.child);
254
+ }
255
+ else if ((0, numberNode_1.isNumberNode)(node) && node.value < 0) {
256
+ oppositesCount++;
257
+ res.push(new numberNode_1.NumberNode(Math.abs(node.value)));
258
+ }
259
+ else {
260
+ res.push(node);
261
+ }
262
+ };
263
+ recursive(root);
264
+ if (oppositesCount % 2 === 1) {
265
+ res.unshift(new numberNode_1.NumberNode(-1));
258
266
  }
267
+ return res;
259
268
  };
260
- recursive(copy);
269
+ let externals = getExternalNodes(copy);
261
270
  //si 0 on s'arrete
262
271
  if (externals.some((node) => (0, numberNode_1.isNumberNode)(node) && node.value === 0)) {
263
272
  return new numberNode_1.NumberNode(0);
264
273
  }
265
- if (oppositesCount % 2 === 1) {
266
- externals.unshift(new numberNode_1.NumberNode(-1));
267
- }
268
274
  //suppression des 1
269
275
  externals = externals.filter((node) => !(0, numberNode_1.isNumberNode)(node) || node.value !== 1);
270
276
  if (!externals.length)
@@ -319,6 +325,13 @@ class MultiplyNode {
319
325
  powerSimplified = powerSimplify(b, a, opts);
320
326
  if (powerSimplified)
321
327
  return powerSimplified;
328
+ if (opts?.towardsDistribute && ((0, addNode_1.isAddNode)(a) || (0, substractNode_1.isSubstractNode)(a))) {
329
+ return (0, addNode_1.add)((0, exports.multiply)(a.leftChild, b), (0, exports.multiply)(a.rightChild, b)).simplify();
330
+ }
331
+ else if (opts?.towardsDistribute &&
332
+ ((0, addNode_1.isAddNode)(b) || (0, substractNode_1.isSubstractNode)(b))) {
333
+ return (0, addNode_1.add)((0, exports.multiply)(a, b.leftChild), (0, exports.multiply)(a, b.rightChild)).simplify();
334
+ }
322
335
  //TODo continue
323
336
  return null;
324
337
  };
@@ -331,8 +344,14 @@ class MultiplyNode {
331
344
  const right = externals[j];
332
345
  const simplified = simplifyExternalNodes(left, right);
333
346
  if (simplified) {
334
- externals[i] = simplified;
335
347
  externals.splice(j, 1);
348
+ if (isMultiplyNode(simplified)) {
349
+ const subExternals = getExternalNodes(simplified);
350
+ externals.splice(i, 1, ...subExternals);
351
+ }
352
+ else {
353
+ externals[i] = simplified;
354
+ }
336
355
  if ((0, numberNode_1.isNumberNode)(simplified) && simplified.value === 1) {
337
356
  externals.splice(i, 1);
338
357
  }
@@ -347,6 +366,7 @@ class MultiplyNode {
347
366
  return new numberNode_1.NumberNode(1);
348
367
  if (externals.length === 1)
349
368
  return externals[0];
369
+ (0, exports.sortMultiplyNodes)(externals);
350
370
  return (0, operatorComposition_1.operatorComposition)(MultiplyNode, externals);
351
371
  }
352
372
  equals(node) {
@@ -1,3 +1,4 @@
1
+ import { AlgebraicNode } from "../algebraicNode";
1
2
  import { InequationNode } from "../inequations/inequationNode";
2
3
  import { Node, NodeIds, NodeOptions, NodeType } from "../node";
3
4
  import { ClosureType } from "./closure";
@@ -9,13 +10,13 @@ export declare class IntervalNode implements SetNode {
9
10
  id: SetIds;
10
11
  opts?: NodeOptions | undefined;
11
12
  closure: ClosureType;
12
- a: Node;
13
- b: Node;
13
+ a: AlgebraicNode;
14
+ b: AlgebraicNode;
14
15
  isEmpty: boolean;
15
- constructor(a: Node, b: Node, closure: ClosureType, opts?: NodeOptions);
16
+ constructor(a: AlgebraicNode, b: AlgebraicNode, closure: ClosureType, opts?: NodeOptions);
16
17
  toAllValidTexs(opts?: NodeOptions): string[];
17
18
  toEquivalentNodes(opts?: NodeOptions): IntervalNode[];
18
- toInequality(middleChild?: Node): InequationNode;
19
+ toInequality(middleChild?: AlgebraicNode): InequationNode;
19
20
  toMathString(): string;
20
21
  toMathjs(): string;
21
22
  toReversedClosure(): IntervalNode;
@@ -1 +1 @@
1
- {"version":3,"file":"intervalNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/sets/intervalNode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ/D,OAAO,EAAW,WAAW,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAa,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,YAAY,CAEzD;AACD,qBAAa,YAAa,YAAW,OAAO;IAC1C,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,OAAO,EAAE,WAAW,CAAC;IACrB,CAAC,EAAE,IAAI,CAAC;IACR,CAAC,EAAE,IAAI,CAAC;IACR,OAAO,EAAE,OAAO,CAAC;gBACL,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW;IAUtE,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW;IAMjC,iBAAiB,CAAC,IAAI,CAAC,EAAE,WAAW;IAoBpC,YAAY,CAAC,WAAW,CAAC,EAAE,IAAI;IA4B/B,YAAY;IAIZ,QAAQ;IAIR,iBAAiB;IAGjB,qBAAqB;IAGrB,sBAAsB;IAGtB,wBAAwB;IAWxB,YAAY;IAkCZ,KAAK;IAWL,aAAa;;;;;;;;;;IASb,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OA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AAE,OAAO;IAiB7C,QAAQ;CAGT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "math-exercises",
3
- "version": "2.2.51",
3
+ "version": "2.2.53",
4
4
  "description": "Math exercises generator for middle school and high school",
5
5
  "main": "lib/index.js",
6
6
  "files": [