math-exercises 1.3.1 → 1.3.3
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/README.md +71 -71
- package/lib/exercises/calcul/addAndSub.js +40 -39
- package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -34
- package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +31 -31
- package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -31
- package/lib/exercises/calcul/fractions/fractionsDivision.js +29 -28
- package/lib/exercises/calcul/fractions/fractionsProduct.js +29 -28
- package/lib/exercises/calcul/fractions/fractionsSum.js +29 -28
- package/lib/exercises/calcul/fractions/simplifyFraction.js +25 -24
- package/lib/exercises/calcul/operationsPriorities.js +88 -88
- package/lib/exercises/calcul/rounding/rounding.js +86 -85
- package/lib/exercises/calculLitteral/distributivity/allIdentities.js +27 -27
- package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +31 -30
- package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +32 -31
- package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +33 -32
- package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +33 -32
- package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +32 -31
- package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +38 -37
- package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +41 -40
- package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +42 -41
- package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +44 -43
- package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +39 -38
- package/lib/exercises/exercise.js +7 -7
- package/lib/exercises/exercises.js +85 -95
- package/lib/exercises/powers/powersDivision.js +45 -44
- package/lib/exercises/powers/powersOfTenToDecimal.js +33 -32
- package/lib/exercises/powers/powersPower.js +44 -43
- package/lib/exercises/powers/powersProduct.js +45 -44
- package/lib/exercises/powers/scientificToDecimal.js +38 -37
- package/lib/exercises/squareRoots/simpifySquareRoot.js +28 -27
- package/lib/exercises/utils/getDistinctQuestions.js +15 -15
- package/lib/geometry/point.js +1 -27
- package/lib/index.js +5 -9
- package/lib/mathutils/arithmetic/coprimesOf.js +13 -13
- package/lib/mathutils/arithmetic/dividersOf.js +12 -12
- package/lib/mathutils/arithmetic/gcd.js +7 -7
- package/lib/mathutils/arithmetic/isSquare.js +7 -7
- package/lib/mathutils/arithmetic/lcd.js +12 -12
- package/lib/mathutils/arithmetic/nonCoprimesOf.js +13 -13
- package/lib/mathutils/arithmetic/nonDividersOf.js +14 -14
- package/lib/mathutils/arithmetic/primeFactors.js +22 -22
- package/lib/mathutils/decimals/decimalPartLengthOf.js +14 -14
- package/lib/mathutils/random/randint.js +18 -18
- package/lib/mathutils/round.js +8 -8
- package/lib/numbers/decimals/decimal.js +140 -140
- package/lib/numbers/epsilon.js +10 -10
- package/lib/numbers/integer/integer.js +68 -68
- package/lib/numbers/integer/power.js +52 -52
- package/lib/numbers/nombre.js +10 -10
- package/lib/numbers/rationals/rational.js +113 -113
- package/lib/numbers/reals/real.js +16 -16
- package/lib/numbers/reals/squareRoot.js +63 -63
- package/lib/polynomials/affine.js +42 -42
- package/lib/polynomials/polynomial.js +125 -125
- package/lib/sets/discreteSet.js +28 -28
- package/lib/sets/emptySet.js +6 -6
- package/lib/sets/intervals/intervals.js +108 -108
- package/lib/sets/intervals/union.js +1 -1
- package/lib/sets/mathSet.js +10 -10
- package/lib/sets/mathSetInterface.js +2 -2
- package/lib/tree/nodes/functions/functionNode.js +18 -18
- package/lib/tree/nodes/functions/oppositeNode.js +13 -26
- package/lib/tree/nodes/functions/sqrtNode.js +15 -18
- package/lib/tree/nodes/node.js +10 -10
- package/lib/tree/nodes/numbers/numberNode.js +15 -18
- package/lib/tree/nodes/operators/addNode.js +15 -19
- package/lib/tree/nodes/operators/divideNode.js +17 -34
- package/lib/tree/nodes/operators/equalNode.js +13 -16
- package/lib/tree/nodes/operators/fractionNode.js +17 -20
- package/lib/tree/nodes/operators/multiplyNode.js +13 -36
- package/lib/tree/nodes/operators/operatorNode.js +35 -35
- package/lib/tree/nodes/operators/powerNode.js +13 -33
- package/lib/tree/nodes/operators/substractNode.js +13 -24
- package/lib/tree/nodes/variables/variableNode.js +16 -19
- package/lib/tree/parsers/derivateParser.js +60 -62
- package/lib/tree/parsers/latexParser.js +117 -110
- package/lib/utils/coin.js +7 -7
- package/lib/utils/random.js +7 -7
- package/lib/utils/shuffle.js +15 -15
- package/package.json +41 -38
- package/lib/exercises/calcul/operations/operationsPriorities.js +0 -98
- package/lib/exercises/calcul/operations/operationsPrioritiesWithoutRelative.js +0 -111
- package/lib/exercises/geometry/cartesian/midpoint.js +0 -29
- package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +0 -28
- package/lib/exercises/geometry/vectors/scalarProductViaNorms.js +0 -27
- package/lib/geometry/vector.js +0 -31
- package/lib/mathutils/random/randTupleInt.js +0 -30
- package/lib/tree/parsers/simplify.js +0 -51
- package/lib/utils/arrayEqual.js +0 -13
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Polynomial = void 0;
|
|
4
|
-
const numberNode_1 = require("../tree/nodes/numbers/numberNode");
|
|
5
|
-
const addNode_1 = require("../tree/nodes/operators/addNode");
|
|
6
|
-
const multiplyNode_1 = require("../tree/nodes/operators/multiplyNode");
|
|
7
|
-
const oppositeNode_1 = require("../tree/nodes/functions/oppositeNode");
|
|
8
|
-
const powerNode_1 = require("../tree/nodes/operators/powerNode");
|
|
9
|
-
const variableNode_1 = require("../tree/nodes/variables/variableNode");
|
|
10
|
-
class Polynomial {
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param coefficients coefficients[i] est le coeff de x^i
|
|
14
|
-
* @param variable
|
|
15
|
-
*/
|
|
16
|
-
constructor(coefficients, variable = "x") {
|
|
17
|
-
if (coefficients.length === 0)
|
|
18
|
-
throw Error("coeffs must be not null");
|
|
19
|
-
if (coefficients[coefficients.length - 1] === 0) {
|
|
20
|
-
throw Error("n-th coeff must be not null");
|
|
21
|
-
}
|
|
22
|
-
this.coefficients = coefficients;
|
|
23
|
-
this.variable = variable;
|
|
24
|
-
this.degree = coefficients.length - 1;
|
|
25
|
-
}
|
|
26
|
-
equals(P) {
|
|
27
|
-
return P.degree === this.degree && this.coefficients.every((coeff, i) => coeff === P.coefficients[i]);
|
|
28
|
-
}
|
|
29
|
-
getRoots() { }
|
|
30
|
-
add(P) {
|
|
31
|
-
if (P.variable !== this.variable)
|
|
32
|
-
throw Error("Can't add two polynomials with different variables");
|
|
33
|
-
const newDegree = P.degree === this.degree && P.coefficients[P.degree] === -this.coefficients[this.degree]
|
|
34
|
-
? P.degree - 1
|
|
35
|
-
: Math.max(P.degree, this.degree);
|
|
36
|
-
const res = [];
|
|
37
|
-
for (let i = 0; i < newDegree + 1; i++) {
|
|
38
|
-
res[i] = P.coefficients[i] + this.coefficients[i];
|
|
39
|
-
}
|
|
40
|
-
return new Polynomial(res, this.variable);
|
|
41
|
-
}
|
|
42
|
-
times(nb) {
|
|
43
|
-
return new Polynomial(this.coefficients.map((coeff) => coeff * nb), this.variable);
|
|
44
|
-
}
|
|
45
|
-
multiply(Q) {
|
|
46
|
-
if (Q.variable !== this.variable)
|
|
47
|
-
throw Error("Can't multiply two polynomials with different variables");
|
|
48
|
-
const p = this.degree;
|
|
49
|
-
const q = Q.degree;
|
|
50
|
-
const res = Array.apply(0, new Array(this.degree)).map((i) => 0);
|
|
51
|
-
for (let k = 0; k <= p + q; k++) {
|
|
52
|
-
let sum = 0;
|
|
53
|
-
for (let m = 0; m <= k; m++) {
|
|
54
|
-
sum += (this.coefficients[m] || 0) * (Q.coefficients[k - m] || 0);
|
|
55
|
-
}
|
|
56
|
-
res[k] = sum;
|
|
57
|
-
}
|
|
58
|
-
return new Polynomial(res, this.variable);
|
|
59
|
-
}
|
|
60
|
-
opposite() {
|
|
61
|
-
return new Polynomial(this.coefficients.map((coeff) => -coeff), this.variable);
|
|
62
|
-
}
|
|
63
|
-
toTree() {
|
|
64
|
-
const recursive = (cursor) => {
|
|
65
|
-
const coeff = this.coefficients[cursor];
|
|
66
|
-
if (coeff === 0)
|
|
67
|
-
return recursive(cursor - 1);
|
|
68
|
-
if (cursor === 0) {
|
|
69
|
-
return new numberNode_1.NumberNode(coeff);
|
|
70
|
-
}
|
|
71
|
-
const monome = cursor > 1
|
|
72
|
-
? new powerNode_1.PowerNode(new variableNode_1.VariableNode(this.variable), new numberNode_1.NumberNode(cursor))
|
|
73
|
-
: new variableNode_1.VariableNode(this.variable);
|
|
74
|
-
let res;
|
|
75
|
-
if (coeff === 1)
|
|
76
|
-
res = monome;
|
|
77
|
-
else if (coeff === -1)
|
|
78
|
-
res = new oppositeNode_1.OppositeNode(monome);
|
|
79
|
-
else
|
|
80
|
-
res = new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(coeff), monome);
|
|
81
|
-
let nextCoeff;
|
|
82
|
-
for (let i = cursor - 1; i > -1; i--) {
|
|
83
|
-
if (this.coefficients[i]) {
|
|
84
|
-
nextCoeff = this.coefficients[i];
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (nextCoeff) {
|
|
89
|
-
return new addNode_1.AddNode(res, recursive(cursor - 1));
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return res;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
return recursive(this.degree);
|
|
96
|
-
}
|
|
97
|
-
toTex() {
|
|
98
|
-
let s = "";
|
|
99
|
-
for (let i = this.degree; i > -1; i--) {
|
|
100
|
-
const coeff = this.coefficients[i];
|
|
101
|
-
if (coeff === 0)
|
|
102
|
-
continue;
|
|
103
|
-
if (i === 0)
|
|
104
|
-
s += coeff > 0 ? `+${coeff}` : coeff;
|
|
105
|
-
else if (i === this.degree) {
|
|
106
|
-
s += coeff === 1 ? "" : coeff === -1 ? "-" : coeff;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
s += coeff === 1 ? "+" : coeff === -1 ? "-" : coeff > 0 ? `+${coeff}` : coeff;
|
|
110
|
-
}
|
|
111
|
-
//x^n
|
|
112
|
-
if (i === 0)
|
|
113
|
-
continue;
|
|
114
|
-
if (i === 1)
|
|
115
|
-
s += this.variable;
|
|
116
|
-
else
|
|
117
|
-
s += `${this.variable}^{${i}}`;
|
|
118
|
-
}
|
|
119
|
-
return s;
|
|
120
|
-
}
|
|
121
|
-
toString() {
|
|
122
|
-
return this.toTex();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
exports.Polynomial = Polynomial;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Polynomial = void 0;
|
|
4
|
+
const numberNode_1 = require("../tree/nodes/numbers/numberNode");
|
|
5
|
+
const addNode_1 = require("../tree/nodes/operators/addNode");
|
|
6
|
+
const multiplyNode_1 = require("../tree/nodes/operators/multiplyNode");
|
|
7
|
+
const oppositeNode_1 = require("../tree/nodes/functions/oppositeNode");
|
|
8
|
+
const powerNode_1 = require("../tree/nodes/operators/powerNode");
|
|
9
|
+
const variableNode_1 = require("../tree/nodes/variables/variableNode");
|
|
10
|
+
class Polynomial {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param coefficients coefficients[i] est le coeff de x^i
|
|
14
|
+
* @param variable
|
|
15
|
+
*/
|
|
16
|
+
constructor(coefficients, variable = "x") {
|
|
17
|
+
if (coefficients.length === 0)
|
|
18
|
+
throw Error("coeffs must be not null");
|
|
19
|
+
if (coefficients[coefficients.length - 1] === 0) {
|
|
20
|
+
throw Error("n-th coeff must be not null");
|
|
21
|
+
}
|
|
22
|
+
this.coefficients = coefficients;
|
|
23
|
+
this.variable = variable;
|
|
24
|
+
this.degree = coefficients.length - 1;
|
|
25
|
+
}
|
|
26
|
+
equals(P) {
|
|
27
|
+
return P.degree === this.degree && this.coefficients.every((coeff, i) => coeff === P.coefficients[i]);
|
|
28
|
+
}
|
|
29
|
+
getRoots() { }
|
|
30
|
+
add(P) {
|
|
31
|
+
if (P.variable !== this.variable)
|
|
32
|
+
throw Error("Can't add two polynomials with different variables");
|
|
33
|
+
const newDegree = P.degree === this.degree && P.coefficients[P.degree] === -this.coefficients[this.degree]
|
|
34
|
+
? P.degree - 1
|
|
35
|
+
: Math.max(P.degree, this.degree);
|
|
36
|
+
const res = [];
|
|
37
|
+
for (let i = 0; i < newDegree + 1; i++) {
|
|
38
|
+
res[i] = P.coefficients[i] + this.coefficients[i];
|
|
39
|
+
}
|
|
40
|
+
return new Polynomial(res, this.variable);
|
|
41
|
+
}
|
|
42
|
+
times(nb) {
|
|
43
|
+
return new Polynomial(this.coefficients.map((coeff) => coeff * nb), this.variable);
|
|
44
|
+
}
|
|
45
|
+
multiply(Q) {
|
|
46
|
+
if (Q.variable !== this.variable)
|
|
47
|
+
throw Error("Can't multiply two polynomials with different variables");
|
|
48
|
+
const p = this.degree;
|
|
49
|
+
const q = Q.degree;
|
|
50
|
+
const res = Array.apply(0, new Array(this.degree)).map((i) => 0);
|
|
51
|
+
for (let k = 0; k <= p + q; k++) {
|
|
52
|
+
let sum = 0;
|
|
53
|
+
for (let m = 0; m <= k; m++) {
|
|
54
|
+
sum += (this.coefficients[m] || 0) * (Q.coefficients[k - m] || 0);
|
|
55
|
+
}
|
|
56
|
+
res[k] = sum;
|
|
57
|
+
}
|
|
58
|
+
return new Polynomial(res, this.variable);
|
|
59
|
+
}
|
|
60
|
+
opposite() {
|
|
61
|
+
return new Polynomial(this.coefficients.map((coeff) => -coeff), this.variable);
|
|
62
|
+
}
|
|
63
|
+
toTree() {
|
|
64
|
+
const recursive = (cursor) => {
|
|
65
|
+
const coeff = this.coefficients[cursor];
|
|
66
|
+
if (coeff === 0)
|
|
67
|
+
return recursive(cursor - 1);
|
|
68
|
+
if (cursor === 0) {
|
|
69
|
+
return new numberNode_1.NumberNode(coeff);
|
|
70
|
+
}
|
|
71
|
+
const monome = cursor > 1
|
|
72
|
+
? new powerNode_1.PowerNode(new variableNode_1.VariableNode(this.variable), new numberNode_1.NumberNode(cursor))
|
|
73
|
+
: new variableNode_1.VariableNode(this.variable);
|
|
74
|
+
let res;
|
|
75
|
+
if (coeff === 1)
|
|
76
|
+
res = monome;
|
|
77
|
+
else if (coeff === -1)
|
|
78
|
+
res = new oppositeNode_1.OppositeNode(monome);
|
|
79
|
+
else
|
|
80
|
+
res = new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(coeff), monome);
|
|
81
|
+
let nextCoeff;
|
|
82
|
+
for (let i = cursor - 1; i > -1; i--) {
|
|
83
|
+
if (this.coefficients[i]) {
|
|
84
|
+
nextCoeff = this.coefficients[i];
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (nextCoeff) {
|
|
89
|
+
return new addNode_1.AddNode(res, recursive(cursor - 1));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return recursive(this.degree);
|
|
96
|
+
}
|
|
97
|
+
toTex() {
|
|
98
|
+
let s = "";
|
|
99
|
+
for (let i = this.degree; i > -1; i--) {
|
|
100
|
+
const coeff = this.coefficients[i];
|
|
101
|
+
if (coeff === 0)
|
|
102
|
+
continue;
|
|
103
|
+
if (i === 0)
|
|
104
|
+
s += coeff > 0 ? `+${coeff}` : coeff;
|
|
105
|
+
else if (i === this.degree) {
|
|
106
|
+
s += coeff === 1 ? "" : coeff === -1 ? "-" : coeff;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
s += coeff === 1 ? "+" : coeff === -1 ? "-" : coeff > 0 ? `+${coeff}` : coeff;
|
|
110
|
+
}
|
|
111
|
+
//x^n
|
|
112
|
+
if (i === 0)
|
|
113
|
+
continue;
|
|
114
|
+
if (i === 1)
|
|
115
|
+
s += this.variable;
|
|
116
|
+
else
|
|
117
|
+
s += `${this.variable}^{${i}}`;
|
|
118
|
+
}
|
|
119
|
+
return s;
|
|
120
|
+
}
|
|
121
|
+
toString() {
|
|
122
|
+
return this.toTex();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.Polynomial = Polynomial;
|
package/lib/sets/discreteSet.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DiscreteSet = void 0;
|
|
4
|
-
const random_1 = require("../utils/random");
|
|
5
|
-
class DiscreteSet {
|
|
6
|
-
constructor(elements) {
|
|
7
|
-
this.elements = Array.from(new Set(elements));
|
|
8
|
-
let tex = "\\{";
|
|
9
|
-
this.elements.forEach((el, index) => {
|
|
10
|
-
tex += el.tex;
|
|
11
|
-
if (index < this.elements.length - 1)
|
|
12
|
-
tex += ";";
|
|
13
|
-
else
|
|
14
|
-
tex += "\\}";
|
|
15
|
-
});
|
|
16
|
-
this.tex = tex;
|
|
17
|
-
}
|
|
18
|
-
toTex() {
|
|
19
|
-
return this.tex;
|
|
20
|
-
}
|
|
21
|
-
includes(el) {
|
|
22
|
-
return this.elements.some((nb) => nb.value === el.value && nb.tex === el.tex);
|
|
23
|
-
}
|
|
24
|
-
getRandomElement() {
|
|
25
|
-
return (0, random_1.random)(this.elements);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.DiscreteSet = DiscreteSet;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiscreteSet = void 0;
|
|
4
|
+
const random_1 = require("../utils/random");
|
|
5
|
+
class DiscreteSet {
|
|
6
|
+
constructor(elements) {
|
|
7
|
+
this.elements = Array.from(new Set(elements));
|
|
8
|
+
let tex = "\\{";
|
|
9
|
+
this.elements.forEach((el, index) => {
|
|
10
|
+
tex += el.tex;
|
|
11
|
+
if (index < this.elements.length - 1)
|
|
12
|
+
tex += ";";
|
|
13
|
+
else
|
|
14
|
+
tex += "\\}";
|
|
15
|
+
});
|
|
16
|
+
this.tex = tex;
|
|
17
|
+
}
|
|
18
|
+
toTex() {
|
|
19
|
+
return this.tex;
|
|
20
|
+
}
|
|
21
|
+
includes(el) {
|
|
22
|
+
return this.elements.some((nb) => nb.value === el.value && nb.tex === el.tex);
|
|
23
|
+
}
|
|
24
|
+
getRandomElement() {
|
|
25
|
+
return (0, random_1.random)(this.elements);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.DiscreteSet = DiscreteSet;
|
package/lib/sets/emptySet.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { MathSetInterface } from "./mathSetInterface";
|
|
3
|
-
// export abstract class EmptySet implements MathSetInterface {
|
|
4
|
-
// tex: string = "\\emptyset";
|
|
5
|
-
// getRandomElement = () => null;
|
|
6
|
-
// }
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { MathSetInterface } from "./mathSetInterface";
|
|
3
|
+
// export abstract class EmptySet implements MathSetInterface {
|
|
4
|
+
// tex: string = "\\emptyset";
|
|
5
|
+
// getRandomElement = () => null;
|
|
6
|
+
// }
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Interval = void 0;
|
|
4
|
-
const epsilon_1 = require("../../numbers/epsilon");
|
|
5
|
-
const nombre_1 = require("../../numbers/nombre");
|
|
6
|
-
const round_1 = require("../../mathutils/round");
|
|
7
|
-
const mathSet_1 = require("../mathSet");
|
|
8
|
-
const integer_1 = require("../../numbers/integer/integer");
|
|
9
|
-
const real_1 = require("../../numbers/reals/real");
|
|
10
|
-
var BoundType;
|
|
11
|
-
(function (BoundType) {
|
|
12
|
-
BoundType["OO"] = "]a;b[";
|
|
13
|
-
BoundType["OF"] = "]a;b]";
|
|
14
|
-
BoundType["FO"] = "[a;b[";
|
|
15
|
-
BoundType["FF"] = "[a;b]";
|
|
16
|
-
})(BoundType || (BoundType = {}));
|
|
17
|
-
class Interval {
|
|
18
|
-
/**
|
|
19
|
-
* [[a; b]] pour un interval d'integer; [a;b] pour des réels
|
|
20
|
-
*/
|
|
21
|
-
constructor(tex = "[-10; 10]") {
|
|
22
|
-
this.tex = tex;
|
|
23
|
-
const isInt = tex[1] === "[" || tex[1] === "]";
|
|
24
|
-
this.type = isInt ? nombre_1.NumberType.Integer : nombre_1.NumberType.Real;
|
|
25
|
-
const left = tex[0];
|
|
26
|
-
const right = tex[tex.length - 1];
|
|
27
|
-
const [a, b] = tex
|
|
28
|
-
.slice(isInt ? 2 : 1, isInt ? tex.length - 2 : tex.length - 1)
|
|
29
|
-
.split(";");
|
|
30
|
-
switch (`${left}a;b${right}`) {
|
|
31
|
-
case "[a;b]":
|
|
32
|
-
this.boundType = BoundType.FF;
|
|
33
|
-
break;
|
|
34
|
-
case "]a;b[":
|
|
35
|
-
this.boundType = BoundType.OO;
|
|
36
|
-
break;
|
|
37
|
-
case "[a;b[":
|
|
38
|
-
this.boundType = BoundType.FO;
|
|
39
|
-
break;
|
|
40
|
-
case "]a;b]":
|
|
41
|
-
this.boundType = BoundType.OF;
|
|
42
|
-
break;
|
|
43
|
-
default:
|
|
44
|
-
throw console.error("wrong interval");
|
|
45
|
-
}
|
|
46
|
-
function getBound(bound) {
|
|
47
|
-
return bound === "-\\infty"
|
|
48
|
-
? Number.NEGATIVE_INFINITY
|
|
49
|
-
: bound === "+\\infty"
|
|
50
|
-
? Number.POSITIVE_INFINITY
|
|
51
|
-
: Number(bound);
|
|
52
|
-
}
|
|
53
|
-
this.min = getBound(a);
|
|
54
|
-
this.max = getBound(b);
|
|
55
|
-
}
|
|
56
|
-
// union(interval: Interval): MathSet {
|
|
57
|
-
//[a,b] [c,d]
|
|
58
|
-
//si a=c return a, max(b,d)
|
|
59
|
-
//si si b = d return min(a,c), b
|
|
60
|
-
//si a=d return c,b sauf si OXXO
|
|
61
|
-
//si b=c return a,d sauf si XOOX
|
|
62
|
-
//si c > b ou d < a alors union disjointe avec plus petit en 1er
|
|
63
|
-
//sinon return min(a,c), max(b,d)
|
|
64
|
-
//res = a
|
|
65
|
-
// return new MathSet();
|
|
66
|
-
// }
|
|
67
|
-
exclude(nb) {
|
|
68
|
-
const rand = () => {
|
|
69
|
-
let x;
|
|
70
|
-
do {
|
|
71
|
-
x = this.getRandomElement();
|
|
72
|
-
} while (x.value === nb);
|
|
73
|
-
return x;
|
|
74
|
-
};
|
|
75
|
-
return new mathSet_1.MathSet(this.toTex() + `\\{${nb}\\}`, rand);
|
|
76
|
-
}
|
|
77
|
-
difference(set) {
|
|
78
|
-
const rand = () => {
|
|
79
|
-
let x;
|
|
80
|
-
do {
|
|
81
|
-
x = this.getRandomElement();
|
|
82
|
-
} while (set.includes(x));
|
|
83
|
-
return x;
|
|
84
|
-
};
|
|
85
|
-
return new mathSet_1.MathSet(this.toTex() + `\\ ${set.toTex()}`, rand);
|
|
86
|
-
}
|
|
87
|
-
toTex() {
|
|
88
|
-
return this.tex;
|
|
89
|
-
}
|
|
90
|
-
getRandomElement(precision = this.type === nombre_1.NumberType.Integer ? 0 : 2) {
|
|
91
|
-
if (this.min === -Infinity || this.max === Infinity)
|
|
92
|
-
throw Error("Can't chose amongst infinity");
|
|
93
|
-
let min = this.boundType === BoundType.OO || this.boundType === BoundType.OF
|
|
94
|
-
? this.min + epsilon_1.EPSILON
|
|
95
|
-
: this.min;
|
|
96
|
-
let max = this.boundType === BoundType.OO || this.boundType === BoundType.FO
|
|
97
|
-
? this.max - epsilon_1.EPSILON
|
|
98
|
-
: this.max;
|
|
99
|
-
const value = (0, round_1.round)(min + Math.random() * (max - this.min), precision);
|
|
100
|
-
switch (this.type) {
|
|
101
|
-
case nombre_1.NumberType.Integer:
|
|
102
|
-
return new integer_1.Integer(value);
|
|
103
|
-
default:
|
|
104
|
-
return new real_1.Real(value, value.toString());
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.Interval = Interval;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Interval = void 0;
|
|
4
|
+
const epsilon_1 = require("../../numbers/epsilon");
|
|
5
|
+
const nombre_1 = require("../../numbers/nombre");
|
|
6
|
+
const round_1 = require("../../mathutils/round");
|
|
7
|
+
const mathSet_1 = require("../mathSet");
|
|
8
|
+
const integer_1 = require("../../numbers/integer/integer");
|
|
9
|
+
const real_1 = require("../../numbers/reals/real");
|
|
10
|
+
var BoundType;
|
|
11
|
+
(function (BoundType) {
|
|
12
|
+
BoundType["OO"] = "]a;b[";
|
|
13
|
+
BoundType["OF"] = "]a;b]";
|
|
14
|
+
BoundType["FO"] = "[a;b[";
|
|
15
|
+
BoundType["FF"] = "[a;b]";
|
|
16
|
+
})(BoundType || (BoundType = {}));
|
|
17
|
+
class Interval {
|
|
18
|
+
/**
|
|
19
|
+
* [[a; b]] pour un interval d'integer; [a;b] pour des réels
|
|
20
|
+
*/
|
|
21
|
+
constructor(tex = "[-10; 10]") {
|
|
22
|
+
this.tex = tex;
|
|
23
|
+
const isInt = tex[1] === "[" || tex[1] === "]";
|
|
24
|
+
this.type = isInt ? nombre_1.NumberType.Integer : nombre_1.NumberType.Real;
|
|
25
|
+
const left = tex[0];
|
|
26
|
+
const right = tex[tex.length - 1];
|
|
27
|
+
const [a, b] = tex
|
|
28
|
+
.slice(isInt ? 2 : 1, isInt ? tex.length - 2 : tex.length - 1)
|
|
29
|
+
.split(";");
|
|
30
|
+
switch (`${left}a;b${right}`) {
|
|
31
|
+
case "[a;b]":
|
|
32
|
+
this.boundType = BoundType.FF;
|
|
33
|
+
break;
|
|
34
|
+
case "]a;b[":
|
|
35
|
+
this.boundType = BoundType.OO;
|
|
36
|
+
break;
|
|
37
|
+
case "[a;b[":
|
|
38
|
+
this.boundType = BoundType.FO;
|
|
39
|
+
break;
|
|
40
|
+
case "]a;b]":
|
|
41
|
+
this.boundType = BoundType.OF;
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
throw console.error("wrong interval");
|
|
45
|
+
}
|
|
46
|
+
function getBound(bound) {
|
|
47
|
+
return bound === "-\\infty"
|
|
48
|
+
? Number.NEGATIVE_INFINITY
|
|
49
|
+
: bound === "+\\infty"
|
|
50
|
+
? Number.POSITIVE_INFINITY
|
|
51
|
+
: Number(bound);
|
|
52
|
+
}
|
|
53
|
+
this.min = getBound(a);
|
|
54
|
+
this.max = getBound(b);
|
|
55
|
+
}
|
|
56
|
+
// union(interval: Interval): MathSet {
|
|
57
|
+
//[a,b] [c,d]
|
|
58
|
+
//si a=c return a, max(b,d)
|
|
59
|
+
//si si b = d return min(a,c), b
|
|
60
|
+
//si a=d return c,b sauf si OXXO
|
|
61
|
+
//si b=c return a,d sauf si XOOX
|
|
62
|
+
//si c > b ou d < a alors union disjointe avec plus petit en 1er
|
|
63
|
+
//sinon return min(a,c), max(b,d)
|
|
64
|
+
//res = a
|
|
65
|
+
// return new MathSet();
|
|
66
|
+
// }
|
|
67
|
+
exclude(nb) {
|
|
68
|
+
const rand = () => {
|
|
69
|
+
let x;
|
|
70
|
+
do {
|
|
71
|
+
x = this.getRandomElement();
|
|
72
|
+
} while (x.value === nb);
|
|
73
|
+
return x;
|
|
74
|
+
};
|
|
75
|
+
return new mathSet_1.MathSet(this.toTex() + `\\{${nb}\\}`, rand);
|
|
76
|
+
}
|
|
77
|
+
difference(set) {
|
|
78
|
+
const rand = () => {
|
|
79
|
+
let x;
|
|
80
|
+
do {
|
|
81
|
+
x = this.getRandomElement();
|
|
82
|
+
} while (set.includes(x));
|
|
83
|
+
return x;
|
|
84
|
+
};
|
|
85
|
+
return new mathSet_1.MathSet(this.toTex() + `\\ ${set.toTex()}`, rand);
|
|
86
|
+
}
|
|
87
|
+
toTex() {
|
|
88
|
+
return this.tex;
|
|
89
|
+
}
|
|
90
|
+
getRandomElement(precision = this.type === nombre_1.NumberType.Integer ? 0 : 2) {
|
|
91
|
+
if (this.min === -Infinity || this.max === Infinity)
|
|
92
|
+
throw Error("Can't chose amongst infinity");
|
|
93
|
+
let min = this.boundType === BoundType.OO || this.boundType === BoundType.OF
|
|
94
|
+
? this.min + epsilon_1.EPSILON
|
|
95
|
+
: this.min;
|
|
96
|
+
let max = this.boundType === BoundType.OO || this.boundType === BoundType.FO
|
|
97
|
+
? this.max - epsilon_1.EPSILON
|
|
98
|
+
: this.max;
|
|
99
|
+
const value = (0, round_1.round)(min + Math.random() * (max - this.min), precision);
|
|
100
|
+
switch (this.type) {
|
|
101
|
+
case nombre_1.NumberType.Integer:
|
|
102
|
+
return new integer_1.Integer(value);
|
|
103
|
+
default:
|
|
104
|
+
return new real_1.Real(value, value.toString());
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.Interval = Interval;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
package/lib/sets/mathSet.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MathSet = void 0;
|
|
4
|
-
class MathSet {
|
|
5
|
-
constructor(tex, getRandomElement) {
|
|
6
|
-
this.tex = tex;
|
|
7
|
-
this.getRandomElement = getRandomElement;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.MathSet = MathSet;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MathSet = void 0;
|
|
4
|
+
class MathSet {
|
|
5
|
+
constructor(tex, getRandomElement) {
|
|
6
|
+
this.tex = tex;
|
|
7
|
+
this.getRandomElement = getRandomElement;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.MathSet = MathSet;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FunctionNode = exports.FunctionsIds = void 0;
|
|
4
|
-
const node_1 = require("../node");
|
|
5
|
-
var FunctionsIds;
|
|
6
|
-
(function (FunctionsIds) {
|
|
7
|
-
FunctionsIds[FunctionsIds["opposite"] = 0] = "opposite";
|
|
8
|
-
FunctionsIds[FunctionsIds["sqrt"] = 1] = "sqrt";
|
|
9
|
-
})(FunctionsIds = exports.FunctionsIds || (exports.FunctionsIds = {}));
|
|
10
|
-
class FunctionNode {
|
|
11
|
-
constructor(id, child, tex) {
|
|
12
|
-
this.type = node_1.NodeType.function;
|
|
13
|
-
this.id = id;
|
|
14
|
-
this.child = child;
|
|
15
|
-
this.tex = tex;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.FunctionNode = FunctionNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionNode = exports.FunctionsIds = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
5
|
+
var FunctionsIds;
|
|
6
|
+
(function (FunctionsIds) {
|
|
7
|
+
FunctionsIds[FunctionsIds["opposite"] = 0] = "opposite";
|
|
8
|
+
FunctionsIds[FunctionsIds["sqrt"] = 1] = "sqrt";
|
|
9
|
+
})(FunctionsIds = exports.FunctionsIds || (exports.FunctionsIds = {}));
|
|
10
|
+
class FunctionNode {
|
|
11
|
+
constructor(id, child, tex) {
|
|
12
|
+
this.type = node_1.NodeType.function;
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.child = child;
|
|
15
|
+
this.tex = tex;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.FunctionNode = FunctionNode;
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OppositeNode = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
toTex() {
|
|
15
|
-
let childTex = this.child.toTex();
|
|
16
|
-
let needBrackets = childTex[0] === '-';
|
|
17
|
-
if (this.child.type === node_1.NodeType.operator) {
|
|
18
|
-
const operatorChild = this.child;
|
|
19
|
-
needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorChild.id));
|
|
20
|
-
}
|
|
21
|
-
if (needBrackets)
|
|
22
|
-
childTex = `(${childTex})`;
|
|
23
|
-
return `-${childTex}`;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.OppositeNode = OppositeNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OppositeNode = void 0;
|
|
4
|
+
const functionNode_1 = require("./functionNode");
|
|
5
|
+
class OppositeNode extends functionNode_1.FunctionNode {
|
|
6
|
+
constructor(child) {
|
|
7
|
+
super(functionNode_1.FunctionsIds.opposite, child, "-");
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return `-(${this.child})`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.OppositeNode = OppositeNode;
|