math-exercises 1.3.2 → 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,18 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SqrtNode = void 0;
|
|
4
|
-
const node_1 = require("../node");
|
|
5
|
-
const functionNode_1 = require("./functionNode");
|
|
6
|
-
class SqrtNode extends functionNode_1.FunctionNode {
|
|
7
|
-
constructor(child) {
|
|
8
|
-
super(functionNode_1.FunctionsIds.sqrt, child,
|
|
9
|
-
this.type = node_1.NodeType.function;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return `sqrt(${this.child
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.SqrtNode = SqrtNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqrtNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
5
|
+
const functionNode_1 = require("./functionNode");
|
|
6
|
+
class SqrtNode extends functionNode_1.FunctionNode {
|
|
7
|
+
constructor(child) {
|
|
8
|
+
super(functionNode_1.FunctionsIds.sqrt, child, "\\sqrt");
|
|
9
|
+
this.type = node_1.NodeType.function;
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return `sqrt(${this.child})`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.SqrtNode = SqrtNode;
|
package/lib/tree/nodes/node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeType = void 0;
|
|
4
|
-
var NodeType;
|
|
5
|
-
(function (NodeType) {
|
|
6
|
-
NodeType[NodeType["number"] = 0] = "number";
|
|
7
|
-
NodeType[NodeType["variable"] = 1] = "variable";
|
|
8
|
-
NodeType[NodeType["operator"] = 2] = "operator";
|
|
9
|
-
NodeType[NodeType["function"] = 3] = "function";
|
|
10
|
-
})(NodeType = exports.NodeType || (exports.NodeType = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeType = void 0;
|
|
4
|
+
var NodeType;
|
|
5
|
+
(function (NodeType) {
|
|
6
|
+
NodeType[NodeType["number"] = 0] = "number";
|
|
7
|
+
NodeType[NodeType["variable"] = 1] = "variable";
|
|
8
|
+
NodeType[NodeType["operator"] = 2] = "operator";
|
|
9
|
+
NodeType[NodeType["function"] = 3] = "function";
|
|
10
|
+
})(NodeType = exports.NodeType || (exports.NodeType = {}));
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NumberNode = void 0;
|
|
4
|
-
const node_1 = require("../node");
|
|
5
|
-
class NumberNode {
|
|
6
|
-
constructor(value, tex) {
|
|
7
|
-
this.type = node_1.NodeType.number;
|
|
8
|
-
this.value = value;
|
|
9
|
-
this.tex = tex || value +
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return `${this.tex}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.NumberNode = NumberNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
5
|
+
class NumberNode {
|
|
6
|
+
constructor(value, tex) {
|
|
7
|
+
this.type = node_1.NodeType.number;
|
|
8
|
+
this.value = value;
|
|
9
|
+
this.tex = tex || value + "";
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return `${this.tex}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NumberNode = NumberNode;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AddNode = void 0;
|
|
4
|
-
const operatorNode_1 = require("./operatorNode");
|
|
5
|
-
class AddNode extends operatorNode_1.OperatorNode {
|
|
6
|
-
constructor(leftChild, rightChild) {
|
|
7
|
-
super(operatorNode_1.OperatorIds.add, leftChild, rightChild, true,
|
|
8
|
-
this.leftChild = leftChild;
|
|
9
|
-
this.rightChild = rightChild;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return `${this.leftChild
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return `${this.leftChild.toTex()} ${rightTex[0] === '-' ? '' : '+ '}${rightTex}`;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.AddNode = AddNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddNode = void 0;
|
|
4
|
+
const operatorNode_1 = require("./operatorNode");
|
|
5
|
+
class AddNode extends operatorNode_1.OperatorNode {
|
|
6
|
+
constructor(leftChild, rightChild) {
|
|
7
|
+
super(operatorNode_1.OperatorIds.add, leftChild, rightChild, true, "+");
|
|
8
|
+
this.leftChild = leftChild;
|
|
9
|
+
this.rightChild = rightChild;
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return `${this.leftChild} + ${this.rightChild}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.AddNode = AddNode;
|
|
@@ -1,34 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DivideNode = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @param
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let rightTex = this.rightChild.toTex();
|
|
19
|
-
let leftTex = this.leftChild.toTex();
|
|
20
|
-
if (this.leftChild.type === node_1.NodeType.operator) {
|
|
21
|
-
if ([operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract, operatorNode_1.OperatorIds.multiply].includes(this.leftChild.id))
|
|
22
|
-
leftTex = `(${leftTex})`;
|
|
23
|
-
}
|
|
24
|
-
let needBrackets = rightTex[0] === '-';
|
|
25
|
-
if (this.rightChild.type === node_1.NodeType.operator) {
|
|
26
|
-
const operatorRightChild = this.rightChild;
|
|
27
|
-
needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorRightChild.id));
|
|
28
|
-
}
|
|
29
|
-
if (needBrackets)
|
|
30
|
-
rightTex = `(${rightTex})`;
|
|
31
|
-
return `${leftTex} \\div ${rightTex}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.DivideNode = DivideNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DivideNode = void 0;
|
|
4
|
+
const operatorNode_1 = require("./operatorNode");
|
|
5
|
+
class DivideNode extends operatorNode_1.OperatorNode {
|
|
6
|
+
/**
|
|
7
|
+
* @param leftChild num
|
|
8
|
+
* @param rightChild denum
|
|
9
|
+
*/
|
|
10
|
+
constructor(leftChild, rightChild) {
|
|
11
|
+
super(operatorNode_1.OperatorIds.divide, leftChild, rightChild, false, "\\div");
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
return `(${this.leftChild}) \\div (${this.rightChild})`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.DivideNode = DivideNode;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EqualNode = void 0;
|
|
4
|
-
const operatorNode_1 = require("./operatorNode");
|
|
5
|
-
class EqualNode extends operatorNode_1.OperatorNode {
|
|
6
|
-
constructor(leftChild, rightChild) {
|
|
7
|
-
super(operatorNode_1.OperatorIds.equal, leftChild, rightChild, true,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return `${this.leftChild
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.EqualNode = EqualNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EqualNode = void 0;
|
|
4
|
+
const operatorNode_1 = require("./operatorNode");
|
|
5
|
+
class EqualNode extends operatorNode_1.OperatorNode {
|
|
6
|
+
constructor(leftChild, rightChild) {
|
|
7
|
+
super(operatorNode_1.OperatorIds.equal, leftChild, rightChild, true, "=");
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return `${this.leftChild} = ${this.rightChild}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.EqualNode = EqualNode;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FractionNode = void 0;
|
|
4
|
-
const operatorNode_1 = require("./operatorNode");
|
|
5
|
-
class FractionNode extends operatorNode_1.OperatorNode {
|
|
6
|
-
/**
|
|
7
|
-
* @param leftChild num
|
|
8
|
-
* @param rightChild denum
|
|
9
|
-
*/
|
|
10
|
-
constructor(leftChild, rightChild) {
|
|
11
|
-
super(operatorNode_1.OperatorIds.fraction, leftChild, rightChild, false,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.FractionNode = FractionNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FractionNode = void 0;
|
|
4
|
+
const operatorNode_1 = require("./operatorNode");
|
|
5
|
+
class FractionNode extends operatorNode_1.OperatorNode {
|
|
6
|
+
/**
|
|
7
|
+
* @param leftChild num
|
|
8
|
+
* @param rightChild denum
|
|
9
|
+
*/
|
|
10
|
+
constructor(leftChild, rightChild) {
|
|
11
|
+
super(operatorNode_1.OperatorIds.fraction, leftChild, rightChild, false, "\\frac");
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
return `\\frac{${this.leftChild}}{${this.rightChild}}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.FractionNode = FractionNode;
|
|
@@ -1,36 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MultiplyNode = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let leftTex = this.leftChild.toTex();
|
|
15
|
-
let rightTex = this.rightChild.toTex();
|
|
16
|
-
if (this.leftChild.type === node_1.NodeType.operator) {
|
|
17
|
-
if ([operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract, operatorNode_1.OperatorIds.divide].includes(this.leftChild.id))
|
|
18
|
-
leftTex = `(${leftTex})`;
|
|
19
|
-
}
|
|
20
|
-
let needBrackets = rightTex[0] === '-';
|
|
21
|
-
if (this.rightChild.type === node_1.NodeType.operator) {
|
|
22
|
-
const operatorRightChild = this.rightChild;
|
|
23
|
-
needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorRightChild.id));
|
|
24
|
-
}
|
|
25
|
-
if (needBrackets)
|
|
26
|
-
rightTex = `(${rightTex})`;
|
|
27
|
-
// permet de gérer le cas 3*2^x par ex
|
|
28
|
-
let showTimesSign = !isNaN(+rightTex[0]) || this.rightChild.type === node_1.NodeType.number;
|
|
29
|
-
if (this.rightChild.type === node_1.NodeType.operator) {
|
|
30
|
-
const operatorRightChild = this.rightChild;
|
|
31
|
-
showTimesSign || (showTimesSign = [operatorNode_1.OperatorIds.fraction].includes(operatorRightChild.id));
|
|
32
|
-
}
|
|
33
|
-
return `${leftTex}${showTimesSign ? '\\times ' : ''}${rightTex}`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.MultiplyNode = MultiplyNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultiplyNode = void 0;
|
|
4
|
+
const operatorNode_1 = require("./operatorNode");
|
|
5
|
+
class MultiplyNode extends operatorNode_1.OperatorNode {
|
|
6
|
+
constructor(leftChild, rightChild) {
|
|
7
|
+
super(operatorNode_1.OperatorIds.multiply, leftChild, rightChild, true, "\\times");
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return `(${this.leftChild})*(${this.rightChild})`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.MultiplyNode = MultiplyNode;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OperatorNode = exports.OperatorIds = void 0;
|
|
4
|
-
const coin_1 = require("../../../utils/coin");
|
|
5
|
-
const node_1 = require("../node");
|
|
6
|
-
var OperatorIds;
|
|
7
|
-
(function (OperatorIds) {
|
|
8
|
-
OperatorIds[OperatorIds["add"] = 0] = "add";
|
|
9
|
-
OperatorIds[OperatorIds["substract"] = 1] = "substract";
|
|
10
|
-
OperatorIds[OperatorIds["multiply"] = 2] = "multiply";
|
|
11
|
-
OperatorIds[OperatorIds["fraction"] = 3] = "fraction";
|
|
12
|
-
OperatorIds[OperatorIds["divide"] = 4] = "divide";
|
|
13
|
-
OperatorIds[OperatorIds["power"] = 5] = "power";
|
|
14
|
-
OperatorIds[OperatorIds["equal"] = 6] = "equal";
|
|
15
|
-
})(OperatorIds = exports.OperatorIds || (exports.OperatorIds = {}));
|
|
16
|
-
class OperatorNode {
|
|
17
|
-
constructor(id, leftChild, rightChild, isCommutative, tex) {
|
|
18
|
-
this.type = node_1.NodeType.operator;
|
|
19
|
-
this.id = id;
|
|
20
|
-
this.leftChild = leftChild;
|
|
21
|
-
this.rightChild = rightChild;
|
|
22
|
-
this.isCommutative = isCommutative;
|
|
23
|
-
this.tex = tex;
|
|
24
|
-
}
|
|
25
|
-
/**shuffles in place */
|
|
26
|
-
shuffle() {
|
|
27
|
-
if (!this.isCommutative)
|
|
28
|
-
return;
|
|
29
|
-
if ((0, coin_1.coin)())
|
|
30
|
-
return;
|
|
31
|
-
[this.leftChild, this.rightChild] = [this.rightChild, this.leftChild];
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.OperatorNode = OperatorNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperatorNode = exports.OperatorIds = void 0;
|
|
4
|
+
const coin_1 = require("../../../utils/coin");
|
|
5
|
+
const node_1 = require("../node");
|
|
6
|
+
var OperatorIds;
|
|
7
|
+
(function (OperatorIds) {
|
|
8
|
+
OperatorIds[OperatorIds["add"] = 0] = "add";
|
|
9
|
+
OperatorIds[OperatorIds["substract"] = 1] = "substract";
|
|
10
|
+
OperatorIds[OperatorIds["multiply"] = 2] = "multiply";
|
|
11
|
+
OperatorIds[OperatorIds["fraction"] = 3] = "fraction";
|
|
12
|
+
OperatorIds[OperatorIds["divide"] = 4] = "divide";
|
|
13
|
+
OperatorIds[OperatorIds["power"] = 5] = "power";
|
|
14
|
+
OperatorIds[OperatorIds["equal"] = 6] = "equal";
|
|
15
|
+
})(OperatorIds = exports.OperatorIds || (exports.OperatorIds = {}));
|
|
16
|
+
class OperatorNode {
|
|
17
|
+
constructor(id, leftChild, rightChild, isCommutative, tex) {
|
|
18
|
+
this.type = node_1.NodeType.operator;
|
|
19
|
+
this.id = id;
|
|
20
|
+
this.leftChild = leftChild;
|
|
21
|
+
this.rightChild = rightChild;
|
|
22
|
+
this.isCommutative = isCommutative;
|
|
23
|
+
this.tex = tex;
|
|
24
|
+
}
|
|
25
|
+
/**shuffles in place */
|
|
26
|
+
shuffle() {
|
|
27
|
+
if (!this.isCommutative)
|
|
28
|
+
return this;
|
|
29
|
+
if ((0, coin_1.coin)())
|
|
30
|
+
return this;
|
|
31
|
+
[this.leftChild, this.rightChild] = [this.rightChild, this.leftChild];
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.OperatorNode = OperatorNode;
|
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PowerNode = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let rightTex = this.rightChild.toTex();
|
|
15
|
-
let leftTex = this.leftChild.toTex();
|
|
16
|
-
let needBrackets = leftTex[0] === '-';
|
|
17
|
-
if (this.leftChild.type === node_1.NodeType.operator) {
|
|
18
|
-
const childOperator = this.leftChild;
|
|
19
|
-
needBrackets || (needBrackets = [
|
|
20
|
-
operatorNode_1.OperatorIds.add,
|
|
21
|
-
operatorNode_1.OperatorIds.substract,
|
|
22
|
-
operatorNode_1.OperatorIds.multiply,
|
|
23
|
-
operatorNode_1.OperatorIds.divide,
|
|
24
|
-
operatorNode_1.OperatorIds.fraction,
|
|
25
|
-
operatorNode_1.OperatorIds.power,
|
|
26
|
-
].includes(childOperator.id));
|
|
27
|
-
}
|
|
28
|
-
if (needBrackets)
|
|
29
|
-
leftTex = `(${leftTex})`;
|
|
30
|
-
return `${leftTex}^{${rightTex}}`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.PowerNode = PowerNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PowerNode = void 0;
|
|
4
|
+
const operatorNode_1 = require("./operatorNode");
|
|
5
|
+
class PowerNode extends operatorNode_1.OperatorNode {
|
|
6
|
+
constructor(leftChild, rightChild) {
|
|
7
|
+
super(operatorNode_1.OperatorIds.power, leftChild, rightChild, false, "^");
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return `(${this.leftChild})^{${this.rightChild}}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.PowerNode = PowerNode;
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubstractNode = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let rightTex = this.rightChild.toTex();
|
|
15
|
-
let leftTex = this.leftChild.toTex();
|
|
16
|
-
const needBrackets = (this.rightChild.type === node_1.NodeType.operator &&
|
|
17
|
-
[operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(this.rightChild.id)) ||
|
|
18
|
-
rightTex[0] === '-';
|
|
19
|
-
if (needBrackets)
|
|
20
|
-
rightTex = `(${rightTex})`;
|
|
21
|
-
return `${leftTex} - ${rightTex}`;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.SubstractNode = SubstractNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubstractNode = void 0;
|
|
4
|
+
const operatorNode_1 = require("./operatorNode");
|
|
5
|
+
class SubstractNode extends operatorNode_1.OperatorNode {
|
|
6
|
+
constructor(leftChild, rightChild) {
|
|
7
|
+
super(operatorNode_1.OperatorIds.substract, leftChild, rightChild, false, "-");
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return `${this.leftChild}-(${this.rightChild})`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.SubstractNode = SubstractNode;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VariableNode = void 0;
|
|
4
|
-
const node_1 = require("../node");
|
|
5
|
-
class VariableNode {
|
|
6
|
-
constructor(
|
|
7
|
-
this.type = node_1.NodeType.variable;
|
|
8
|
-
if (
|
|
9
|
-
throw Error(
|
|
10
|
-
this.
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return `${this.
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.VariableNode = VariableNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VariableNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
5
|
+
class VariableNode {
|
|
6
|
+
constructor(tex) {
|
|
7
|
+
this.type = node_1.NodeType.variable;
|
|
8
|
+
if (tex.length !== 1 || !tex.match("[a-zA-Z]"))
|
|
9
|
+
throw Error("variable must be a letter");
|
|
10
|
+
this.tex = tex;
|
|
11
|
+
}
|
|
12
|
+
toString() {
|
|
13
|
+
return `${this.tex}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.VariableNode = VariableNode;
|
|
@@ -1,62 +1,60 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// }
|
|
62
|
-
// }
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.derivateParser = void 0;
|
|
4
|
+
const node_1 = require("../nodes/node");
|
|
5
|
+
const numberNode_1 = require("../nodes/numbers/numberNode");
|
|
6
|
+
const powerNode_1 = require("../nodes/operators/powerNode");
|
|
7
|
+
const addNode_1 = require("../nodes/operators/addNode");
|
|
8
|
+
const fractionNode_1 = require("../nodes/operators/fractionNode");
|
|
9
|
+
const multiplyNode_1 = require("../nodes/operators/multiplyNode");
|
|
10
|
+
const operatorNode_1 = require("../nodes/operators/operatorNode");
|
|
11
|
+
const substractNode_1 = require("../nodes/operators/substractNode");
|
|
12
|
+
const functionNode_1 = require("../nodes/functions/functionNode");
|
|
13
|
+
const sqrtNode_1 = require("../nodes/functions/sqrtNode");
|
|
14
|
+
const oppositeNode_1 = require("../nodes/functions/oppositeNode");
|
|
15
|
+
function derivateParser(node) {
|
|
16
|
+
if (!node)
|
|
17
|
+
throw Error("encountered a null node ??");
|
|
18
|
+
switch (node.type) {
|
|
19
|
+
case node_1.NodeType.variable:
|
|
20
|
+
return new numberNode_1.NumberNode(1);
|
|
21
|
+
case node_1.NodeType.number:
|
|
22
|
+
return new numberNode_1.NumberNode(0);
|
|
23
|
+
case node_1.NodeType.operator:
|
|
24
|
+
const operatorNode = node;
|
|
25
|
+
const u = operatorNode.leftChild;
|
|
26
|
+
const v = operatorNode.rightChild;
|
|
27
|
+
switch (operatorNode.id) {
|
|
28
|
+
case operatorNode_1.OperatorIds.add:
|
|
29
|
+
return new addNode_1.AddNode(derivateParser(u), derivateParser(v));
|
|
30
|
+
case operatorNode_1.OperatorIds.substract: {
|
|
31
|
+
return new substractNode_1.SubstractNode(derivateParser(u), derivateParser(v));
|
|
32
|
+
}
|
|
33
|
+
case operatorNode_1.OperatorIds.multiply: {
|
|
34
|
+
return new addNode_1.AddNode(new multiplyNode_1.MultiplyNode(derivateParser(u), v), new multiplyNode_1.MultiplyNode(u, derivateParser(v)));
|
|
35
|
+
}
|
|
36
|
+
case operatorNode_1.OperatorIds.divide:
|
|
37
|
+
case operatorNode_1.OperatorIds.fraction:
|
|
38
|
+
return new fractionNode_1.FractionNode(new substractNode_1.SubstractNode(new multiplyNode_1.MultiplyNode(derivateParser(u), v), new multiplyNode_1.MultiplyNode(u, derivateParser(v))), new powerNode_1.PowerNode(v, new numberNode_1.NumberNode(2)));
|
|
39
|
+
case operatorNode_1.OperatorIds.power: {
|
|
40
|
+
const operatorNode = node;
|
|
41
|
+
const n = operatorNode.rightChild;
|
|
42
|
+
const u = operatorNode.leftChild;
|
|
43
|
+
return new multiplyNode_1.MultiplyNode(n, new multiplyNode_1.MultiplyNode(derivateParser(u), new powerNode_1.PowerNode(u, new numberNode_1.NumberNode(n.value - 1))));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
case node_1.NodeType.function: {
|
|
47
|
+
const functionNode = node;
|
|
48
|
+
const child = functionNode.child;
|
|
49
|
+
switch (functionNode.id) {
|
|
50
|
+
case functionNode_1.FunctionsIds.sqrt: {
|
|
51
|
+
return new fractionNode_1.FractionNode(derivateParser(child), new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(2), new sqrtNode_1.SqrtNode(child)));
|
|
52
|
+
}
|
|
53
|
+
case functionNode_1.FunctionsIds.opposite: {
|
|
54
|
+
return new oppositeNode_1.OppositeNode(derivateParser(child));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.derivateParser = derivateParser;
|