math-exercises 1.3.11 → 1.3.13
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 +73 -73
- package/lib/exercises/calcul/addAndSub.d.ts +6 -6
- package/lib/exercises/calcul/addAndSub.js +39 -39
- package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.d.ts +3 -3
- package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -35
- package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.d.ts +3 -3
- package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +32 -32
- package/lib/exercises/calcul/fractions/fractionAndIntegerSum.d.ts +3 -3
- package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -32
- package/lib/exercises/calcul/fractions/fractionsDivision.d.ts +3 -3
- package/lib/exercises/calcul/fractions/fractionsDivision.js +29 -29
- package/lib/exercises/calcul/fractions/fractionsProduct.d.ts +3 -3
- package/lib/exercises/calcul/fractions/fractionsProduct.js +28 -28
- package/lib/exercises/calcul/fractions/fractionsSum.d.ts +3 -3
- package/lib/exercises/calcul/fractions/fractionsSum.js +28 -28
- package/lib/exercises/calcul/fractions/simplifyFraction.d.ts +3 -3
- package/lib/exercises/calcul/fractions/simplifyFraction.js +24 -24
- package/lib/exercises/calcul/operations/operationsPriorities.d.ts +10 -10
- package/lib/exercises/calcul/operations/operationsPriorities.js +98 -98
- package/lib/exercises/calcul/operations/operationsPrioritiesWithoutRelative.js +111 -111
- package/lib/exercises/calcul/operationsPriorities.js +88 -88
- package/lib/exercises/calcul/rounding/rounding.d.ts +19 -19
- package/lib/exercises/calcul/rounding/rounding.js +85 -85
- package/lib/exercises/calculLitteral/distributivity/allIdentities.d.ts +3 -3
- package/lib/exercises/calculLitteral/distributivity/allIdentities.js +27 -27
- package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.d.ts +3 -3
- package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +30 -30
- package/lib/exercises/calculLitteral/distributivity/firstIdentity.d.ts +3 -3
- package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +31 -31
- package/lib/exercises/calculLitteral/distributivity/secondIdentity.d.ts +3 -3
- package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +32 -32
- package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.d.ts +3 -3
- package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +32 -32
- package/lib/exercises/calculLitteral/distributivity/thirdIdentity.d.ts +3 -3
- package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +31 -31
- package/lib/exercises/calculLitteral/equation/equationType1Exercise.d.ts +6 -6
- package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +37 -37
- package/lib/exercises/calculLitteral/equation/equationType2Exercise.d.ts +6 -6
- package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +40 -40
- package/lib/exercises/calculLitteral/equation/equationType3Exercise.d.ts +6 -6
- package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +41 -41
- package/lib/exercises/calculLitteral/equation/equationType4Exercise.d.ts +6 -6
- package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +43 -43
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq1.d.ts +4 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq1.d.ts.map +1 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq1.js +32 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq2.d.ts +4 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq2.d.ts.map +1 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq2.js +33 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq3.d.ts +4 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq3.d.ts.map +1 -0
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq3.js +32 -0
- package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.d.ts +6 -6
- package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +38 -38
- package/lib/exercises/derivation/derivative/affineDerivative.d.ts +4 -0
- package/lib/exercises/derivation/derivative/affineDerivative.d.ts.map +1 -0
- package/lib/exercises/derivation/derivative/affineDerivative.js +27 -0
- package/lib/exercises/derivation/derivative/secondDegreeDerivative.d.ts +1 -0
- package/lib/exercises/derivation/derivative/secondDegreeDerivative.d.ts.map +1 -0
- package/lib/exercises/derivation/derivative/secondDegreeDerivative.js +28 -0
- package/lib/exercises/derivation/derivative/thridDegreeDerivative.d.ts +1 -0
- package/lib/exercises/derivation/derivative/thridDegreeDerivative.d.ts.map +1 -0
- package/lib/exercises/derivation/derivative/thridDegreeDerivative.js +1 -0
- package/lib/exercises/exercise.d.ts +16 -16
- package/lib/exercises/exercise.d.ts.map +1 -1
- package/lib/exercises/exercise.js +7 -7
- package/lib/exercises/exercises.d.ts +1 -1
- package/lib/exercises/exercises.d.ts.map +1 -1
- package/lib/exercises/exercises.js +113 -107
- package/lib/exercises/geometry/cartesian/midpoint.d.ts +3 -3
- package/lib/exercises/geometry/cartesian/midpoint.js +29 -29
- package/lib/exercises/geometry/vectors/scalarProductViaCoords.d.ts +3 -3
- package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +28 -28
- package/lib/exercises/geometry/vectors/scalarProductViaNorms.js +27 -27
- package/lib/exercises/powers/powersDivision.d.ts +7 -7
- package/lib/exercises/powers/powersDivision.js +44 -44
- package/lib/exercises/powers/powersOfTenToDecimal.d.ts +6 -6
- package/lib/exercises/powers/powersOfTenToDecimal.js +32 -32
- package/lib/exercises/powers/powersPower.d.ts +7 -7
- package/lib/exercises/powers/powersPower.js +43 -43
- package/lib/exercises/powers/powersProduct.d.ts +7 -7
- package/lib/exercises/powers/powersProduct.js +44 -44
- package/lib/exercises/powers/scientificToDecimal.d.ts +6 -6
- package/lib/exercises/powers/scientificToDecimal.js +37 -37
- package/lib/exercises/sequences/geometric/geometricExplicitFormulaUsage.d.ts +3 -3
- package/lib/exercises/sequences/geometric/geometricExplicitFormulaUsage.js +34 -34
- package/lib/exercises/sequences/geometric/geometricFindExplicitFormula.d.ts +3 -3
- package/lib/exercises/sequences/geometric/geometricFindExplicitFormula.js +33 -33
- package/lib/exercises/sequences/geometric/geometricFindReason.d.ts +3 -3
- package/lib/exercises/sequences/geometric/geometricFindReason.js +29 -29
- package/lib/exercises/sequences/geometric/geometricReasonUsage.d.ts +3 -3
- package/lib/exercises/sequences/geometric/geometricReasonUsage.js +28 -28
- package/lib/exercises/sequences/geometric/geometricRecurrenceFormulaUsage.d.ts +7 -7
- package/lib/exercises/sequences/geometric/geometricRecurrenceFormulaUsage.js +28 -28
- package/lib/exercises/squareRoots/simpifySquareRoot.d.ts +3 -3
- package/lib/exercises/squareRoots/simpifySquareRoot.js +27 -27
- package/lib/exercises/trigonometry/mainRemarkableValues.d.ts +3 -3
- package/lib/exercises/trigonometry/mainRemarkableValues.js +28 -28
- package/lib/exercises/trigonometry/remarkableValues.d.ts +3 -3
- package/lib/exercises/trigonometry/remarkableValues.js +28 -28
- package/lib/exercises/utils/getDistinctQuestions.d.ts +2 -2
- package/lib/exercises/utils/getDistinctQuestions.js +15 -15
- package/lib/geometry/point.js +27 -27
- package/lib/geometry/vector.js +31 -31
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +39 -6
- package/lib/math/geometry/point.d.ts +12 -12
- package/lib/math/geometry/point.js +27 -27
- package/lib/math/geometry/vector.d.ts +15 -15
- package/lib/math/geometry/vector.js +31 -31
- package/lib/math/numbers/decimals/decimal.d.ts +24 -24
- package/lib/math/numbers/decimals/decimal.js +140 -140
- package/lib/math/numbers/epsilon.d.ts +1 -1
- package/lib/math/numbers/epsilon.js +10 -10
- package/lib/math/numbers/integer/integer.d.ts +14 -14
- package/lib/math/numbers/integer/integer.js +68 -68
- package/lib/math/numbers/integer/power.d.ts +13 -13
- package/lib/math/numbers/integer/power.js +52 -52
- package/lib/math/numbers/nombre.d.ts +13 -13
- package/lib/math/numbers/nombre.js +10 -10
- package/lib/math/numbers/rationals/rational.d.ts +25 -25
- package/lib/math/numbers/rationals/rational.js +113 -113
- package/lib/math/numbers/reals/real.d.ts +9 -9
- package/lib/math/numbers/reals/real.js +16 -16
- package/lib/math/numbers/reals/squareRoot.d.ts +18 -18
- package/lib/math/numbers/reals/squareRoot.js +63 -63
- package/lib/math/polynomials/affine.d.ts +15 -15
- package/lib/math/polynomials/affine.js +42 -42
- package/lib/math/polynomials/polynomial.d.ts +25 -24
- package/lib/math/polynomials/polynomial.d.ts.map +1 -1
- package/lib/math/polynomials/polynomial.js +129 -125
- package/lib/math/sequences/arithmeticSequence.js +1 -1
- package/lib/math/sequences/geometricSequence.d.ts +3 -3
- package/lib/math/sequences/geometricSequence.js +8 -8
- package/lib/math/sequences/sequence.d.ts +22 -22
- package/lib/math/sequences/sequence.js +21 -21
- package/lib/math/sets/discreteSet.d.ts +10 -10
- package/lib/math/sets/discreteSet.js +28 -28
- package/lib/math/sets/emptySet.js +6 -6
- package/lib/math/sets/intervals/intervals.d.ts +26 -26
- package/lib/math/sets/intervals/intervals.js +104 -104
- package/lib/math/sets/mathSet.d.ts +7 -7
- package/lib/math/sets/mathSet.js +10 -10
- package/lib/math/sets/mathSetInterface.d.ts +5 -5
- package/lib/math/sets/mathSetInterface.js +2 -2
- package/lib/math/trigonometry/remarkableValue.d.ts +10 -10
- package/lib/math/trigonometry/remarkableValue.js +29 -29
- package/lib/math/trigonometry/remarkableValues.d.ts +2 -2
- package/lib/math/trigonometry/remarkableValues.js +51 -51
- package/lib/math/utils/arithmetic/coprimesOf.d.ts +1 -1
- package/lib/math/utils/arithmetic/coprimesOf.js +13 -13
- package/lib/math/utils/arithmetic/dividersOf.d.ts +1 -1
- package/lib/math/utils/arithmetic/dividersOf.js +12 -12
- package/lib/math/utils/arithmetic/gcd.d.ts +1 -1
- package/lib/math/utils/arithmetic/gcd.js +7 -7
- package/lib/math/utils/arithmetic/isSquare.d.ts +1 -1
- package/lib/math/utils/arithmetic/isSquare.js +7 -7
- package/lib/math/utils/arithmetic/lcd.d.ts +1 -1
- package/lib/math/utils/arithmetic/lcd.js +12 -12
- package/lib/math/utils/arithmetic/nonCoprimesOf.d.ts +1 -1
- package/lib/math/utils/arithmetic/nonCoprimesOf.js +13 -13
- package/lib/math/utils/arithmetic/nonDividersOf.d.ts +1 -1
- package/lib/math/utils/arithmetic/nonDividersOf.js +14 -14
- package/lib/math/utils/arithmetic/primeFactors.d.ts +5 -5
- package/lib/math/utils/arithmetic/primeFactors.js +22 -22
- package/lib/math/utils/decimals/decimalPartLengthOf.d.ts +1 -1
- package/lib/math/utils/decimals/decimalPartLengthOf.js +14 -14
- package/lib/math/utils/random/randTupleInt.d.ts +13 -13
- package/lib/math/utils/random/randTupleInt.js +30 -30
- package/lib/math/utils/random/randint.d.ts +4 -4
- package/lib/math/utils/random/randint.js +18 -18
- package/lib/math/utils/round.d.ts +1 -1
- package/lib/math/utils/round.js +8 -8
- 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/randTupleInt.js +30 -30
- 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/server.d.ts +2 -0
- package/lib/server.d.ts.map +1 -0
- package/lib/server.js +33 -0
- package/lib/sets/discreteSet.js +28 -28
- package/lib/sets/emptySet.js +6 -6
- package/lib/sets/intervals/intervals.js +108 -104
- 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/cosNode.d.ts +9 -9
- package/lib/tree/nodes/functions/cosNode.js +21 -21
- package/lib/tree/nodes/functions/functionNode.d.ts +14 -14
- package/lib/tree/nodes/functions/functionNode.js +20 -20
- package/lib/tree/nodes/functions/oppositeNode.d.ts +7 -7
- package/lib/tree/nodes/functions/oppositeNode.js +26 -26
- package/lib/tree/nodes/functions/sinNode.js +1 -1
- package/lib/tree/nodes/functions/sqrtNode.d.ts +8 -8
- package/lib/tree/nodes/functions/sqrtNode.js +18 -18
- package/lib/tree/nodes/node.d.ts +12 -12
- package/lib/tree/nodes/node.js +11 -11
- package/lib/tree/nodes/numbers/constantNode.d.ts +9 -9
- package/lib/tree/nodes/numbers/constantNode.js +18 -18
- package/lib/tree/nodes/numbers/numberNode.d.ts +10 -10
- package/lib/tree/nodes/numbers/numberNode.js +19 -19
- package/lib/tree/nodes/numbers/piNode.d.ts +2 -2
- package/lib/tree/nodes/numbers/piNode.js +5 -5
- package/lib/tree/nodes/operators/addNode.d.ts +7 -7
- package/lib/tree/nodes/operators/addNode.js +19 -19
- package/lib/tree/nodes/operators/divideNode.d.ts +11 -11
- package/lib/tree/nodes/operators/divideNode.js +34 -34
- package/lib/tree/nodes/operators/equalNode.d.ts +7 -7
- package/lib/tree/nodes/operators/equalNode.js +16 -16
- package/lib/tree/nodes/operators/fractionNode.d.ts +11 -11
- package/lib/tree/nodes/operators/fractionNode.js +20 -20
- package/lib/tree/nodes/operators/multiplyNode.d.ts +7 -7
- package/lib/tree/nodes/operators/multiplyNode.js +43 -43
- package/lib/tree/nodes/operators/operatorNode.d.ts +21 -21
- package/lib/tree/nodes/operators/operatorNode.js +35 -35
- package/lib/tree/nodes/operators/powerNode.d.ts +7 -7
- package/lib/tree/nodes/operators/powerNode.js +33 -33
- package/lib/tree/nodes/operators/substractNode.d.ts +7 -7
- package/lib/tree/nodes/operators/substractNode.js +24 -24
- package/lib/tree/nodes/variables/variableNode.d.ts +8 -8
- package/lib/tree/nodes/variables/variableNode.js +19 -19
- package/lib/tree/parsers/derivateParser.js +62 -62
- package/lib/tree/parsers/latexParser.js +110 -110
- package/lib/tree/parsers/simplify.d.ts +2 -2
- package/lib/tree/parsers/simplify.js +52 -52
- package/lib/utils/arrayEqual.d.ts +1 -1
- package/lib/utils/arrayEqual.js +13 -13
- package/lib/utils/coin.js +7 -7
- package/lib/utils/coinFlip.d.ts +1 -1
- package/lib/utils/coinFlip.js +7 -7
- package/lib/utils/random.d.ts +1 -1
- package/lib/utils/random.js +7 -7
- package/lib/utils/shuffle.d.ts +1 -1
- package/lib/utils/shuffle.js +15 -15
- package/package.json +50 -45
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq.d.ts +0 -7
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq.d.ts.map +0 -1
- package/lib/exercises/calculLitteral/factorisation/factoIdRmq.js +0 -38
- package/lib/trigonometry/remarkableValue.js +0 -29
- package/lib/trigonometry/remarkableValues.js +0 -51
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Node } from '../node';
|
|
2
|
-
import { OperatorNode } from './operatorNode';
|
|
3
|
-
export declare class FractionNode extends OperatorNode implements Node {
|
|
4
|
-
/**
|
|
5
|
-
* @param leftChild num
|
|
6
|
-
* @param rightChild denum
|
|
7
|
-
*/
|
|
8
|
-
constructor(leftChild: Node, rightChild: Node);
|
|
9
|
-
toMathString(): string;
|
|
10
|
-
toTex(): string;
|
|
11
|
-
}
|
|
1
|
+
import { Node } from '../node';
|
|
2
|
+
import { OperatorNode } from './operatorNode';
|
|
3
|
+
export declare class FractionNode extends OperatorNode implements Node {
|
|
4
|
+
/**
|
|
5
|
+
* @param leftChild num
|
|
6
|
+
* @param rightChild denum
|
|
7
|
+
*/
|
|
8
|
+
constructor(leftChild: Node, rightChild: Node);
|
|
9
|
+
toMathString(): string;
|
|
10
|
+
toTex(): string;
|
|
11
|
+
}
|
|
12
12
|
//# sourceMappingURL=fractionNode.d.ts.map
|
|
@@ -1,20 +1,20 @@
|
|
|
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
|
-
toMathString() {
|
|
14
|
-
return `(${this.leftChild.toMathString()}) / (${this.rightChild.toMathString()})`;
|
|
15
|
-
}
|
|
16
|
-
toTex() {
|
|
17
|
-
return `\\frac{${this.leftChild.toTex()}}{${this.rightChild.toTex()}}`;
|
|
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
|
+
toMathString() {
|
|
14
|
+
return `(${this.leftChild.toMathString()}) / (${this.rightChild.toMathString()})`;
|
|
15
|
+
}
|
|
16
|
+
toTex() {
|
|
17
|
+
return `\\frac{${this.leftChild.toTex()}}{${this.rightChild.toTex()}}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.FractionNode = FractionNode;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Node } from '../node';
|
|
2
|
-
import { OperatorNode } from './operatorNode';
|
|
3
|
-
export declare class MultiplyNode extends OperatorNode implements Node {
|
|
4
|
-
constructor(leftChild: Node, rightChild: Node);
|
|
5
|
-
toMathString(): string;
|
|
6
|
-
toTex(): string;
|
|
7
|
-
}
|
|
1
|
+
import { Node } from '../node';
|
|
2
|
+
import { OperatorNode } from './operatorNode';
|
|
3
|
+
export declare class MultiplyNode extends OperatorNode implements Node {
|
|
4
|
+
constructor(leftChild: Node, rightChild: Node);
|
|
5
|
+
toMathString(): string;
|
|
6
|
+
toTex(): string;
|
|
7
|
+
}
|
|
8
8
|
//# sourceMappingURL=multiplyNode.d.ts.map
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MultiplyNode = void 0;
|
|
4
|
-
const functionNode_1 = require("../functions/functionNode");
|
|
5
|
-
const node_1 = require("../node");
|
|
6
|
-
const operatorNode_1 = require("./operatorNode");
|
|
7
|
-
class MultiplyNode extends operatorNode_1.OperatorNode {
|
|
8
|
-
constructor(leftChild, rightChild) {
|
|
9
|
-
let [left, right] = [leftChild, rightChild];
|
|
10
|
-
const shouldSwitch = (rightChild.type === node_1.NodeType.function && rightChild.id === functionNode_1.FunctionsIds.opposite) ||
|
|
11
|
-
(leftChild.type === node_1.NodeType.constant && rightChild.type === node_1.NodeType.number);
|
|
12
|
-
if (shouldSwitch) {
|
|
13
|
-
[left, right] = [rightChild, leftChild];
|
|
14
|
-
}
|
|
15
|
-
super(operatorNode_1.OperatorIds.multiply, left, right, true, '\\times');
|
|
16
|
-
}
|
|
17
|
-
toMathString() {
|
|
18
|
-
return `(${this.leftChild.toMathString()})*(${this.rightChild.toMathString()})`;
|
|
19
|
-
}
|
|
20
|
-
toTex() {
|
|
21
|
-
let leftTex = this.leftChild.toTex();
|
|
22
|
-
let rightTex = this.rightChild.toTex();
|
|
23
|
-
if (this.leftChild.type === node_1.NodeType.operator) {
|
|
24
|
-
if ([operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract, operatorNode_1.OperatorIds.divide].includes(this.leftChild.id))
|
|
25
|
-
leftTex = `(${leftTex})`;
|
|
26
|
-
}
|
|
27
|
-
let needBrackets = rightTex[0] === '-';
|
|
28
|
-
if (this.rightChild.type === node_1.NodeType.operator) {
|
|
29
|
-
const operatorRightChild = this.rightChild;
|
|
30
|
-
needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorRightChild.id));
|
|
31
|
-
}
|
|
32
|
-
if (needBrackets)
|
|
33
|
-
rightTex = `(${rightTex})`;
|
|
34
|
-
// permet de gérer le cas 3*2^x par ex
|
|
35
|
-
let showTimesSign = !isNaN(+rightTex[0]) || this.rightChild.type === node_1.NodeType.number;
|
|
36
|
-
if (this.rightChild.type === node_1.NodeType.operator) {
|
|
37
|
-
const operatorRightChild = this.rightChild;
|
|
38
|
-
showTimesSign || (showTimesSign = [operatorNode_1.OperatorIds.fraction].includes(operatorRightChild.id));
|
|
39
|
-
}
|
|
40
|
-
return `${leftTex}${showTimesSign ? '\\times ' : ''}${rightTex}`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.MultiplyNode = MultiplyNode;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultiplyNode = void 0;
|
|
4
|
+
const functionNode_1 = require("../functions/functionNode");
|
|
5
|
+
const node_1 = require("../node");
|
|
6
|
+
const operatorNode_1 = require("./operatorNode");
|
|
7
|
+
class MultiplyNode extends operatorNode_1.OperatorNode {
|
|
8
|
+
constructor(leftChild, rightChild) {
|
|
9
|
+
let [left, right] = [leftChild, rightChild];
|
|
10
|
+
const shouldSwitch = (rightChild.type === node_1.NodeType.function && rightChild.id === functionNode_1.FunctionsIds.opposite) ||
|
|
11
|
+
(leftChild.type === node_1.NodeType.constant && rightChild.type === node_1.NodeType.number);
|
|
12
|
+
if (shouldSwitch) {
|
|
13
|
+
[left, right] = [rightChild, leftChild];
|
|
14
|
+
}
|
|
15
|
+
super(operatorNode_1.OperatorIds.multiply, left, right, true, '\\times');
|
|
16
|
+
}
|
|
17
|
+
toMathString() {
|
|
18
|
+
return `(${this.leftChild.toMathString()})*(${this.rightChild.toMathString()})`;
|
|
19
|
+
}
|
|
20
|
+
toTex() {
|
|
21
|
+
let leftTex = this.leftChild.toTex();
|
|
22
|
+
let rightTex = this.rightChild.toTex();
|
|
23
|
+
if (this.leftChild.type === node_1.NodeType.operator) {
|
|
24
|
+
if ([operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract, operatorNode_1.OperatorIds.divide].includes(this.leftChild.id))
|
|
25
|
+
leftTex = `(${leftTex})`;
|
|
26
|
+
}
|
|
27
|
+
let needBrackets = rightTex[0] === '-';
|
|
28
|
+
if (this.rightChild.type === node_1.NodeType.operator) {
|
|
29
|
+
const operatorRightChild = this.rightChild;
|
|
30
|
+
needBrackets || (needBrackets = [operatorNode_1.OperatorIds.add, operatorNode_1.OperatorIds.substract].includes(operatorRightChild.id));
|
|
31
|
+
}
|
|
32
|
+
if (needBrackets)
|
|
33
|
+
rightTex = `(${rightTex})`;
|
|
34
|
+
// permet de gérer le cas 3*2^x par ex
|
|
35
|
+
let showTimesSign = !isNaN(+rightTex[0]) || this.rightChild.type === node_1.NodeType.number;
|
|
36
|
+
if (this.rightChild.type === node_1.NodeType.operator) {
|
|
37
|
+
const operatorRightChild = this.rightChild;
|
|
38
|
+
showTimesSign || (showTimesSign = [operatorNode_1.OperatorIds.fraction].includes(operatorRightChild.id));
|
|
39
|
+
}
|
|
40
|
+
return `${leftTex}${showTimesSign ? '\\times ' : ''}${rightTex}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.MultiplyNode = MultiplyNode;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Node, NodeType } from '../node';
|
|
2
|
-
export declare enum OperatorIds {
|
|
3
|
-
add = 0,
|
|
4
|
-
substract = 1,
|
|
5
|
-
multiply = 2,
|
|
6
|
-
fraction = 3,
|
|
7
|
-
divide = 4,
|
|
8
|
-
power = 5,
|
|
9
|
-
equal = 6
|
|
10
|
-
}
|
|
11
|
-
export declare abstract class OperatorNode {
|
|
12
|
-
id: OperatorIds;
|
|
13
|
-
leftChild: Node;
|
|
14
|
-
rightChild: Node;
|
|
15
|
-
isCommutative: boolean;
|
|
16
|
-
type: NodeType;
|
|
17
|
-
tex: string;
|
|
18
|
-
constructor(id: OperatorIds, leftChild: Node, rightChild: Node, isCommutative: boolean, tex: string);
|
|
19
|
-
/**shuffles in place */
|
|
20
|
-
shuffle(): void;
|
|
21
|
-
}
|
|
1
|
+
import { Node, NodeType } from '../node';
|
|
2
|
+
export declare enum OperatorIds {
|
|
3
|
+
add = 0,
|
|
4
|
+
substract = 1,
|
|
5
|
+
multiply = 2,
|
|
6
|
+
fraction = 3,
|
|
7
|
+
divide = 4,
|
|
8
|
+
power = 5,
|
|
9
|
+
equal = 6
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class OperatorNode {
|
|
12
|
+
id: OperatorIds;
|
|
13
|
+
leftChild: Node;
|
|
14
|
+
rightChild: Node;
|
|
15
|
+
isCommutative: boolean;
|
|
16
|
+
type: NodeType;
|
|
17
|
+
tex: string;
|
|
18
|
+
constructor(id: OperatorIds, leftChild: Node, rightChild: Node, isCommutative: boolean, tex: string);
|
|
19
|
+
/**shuffles in place */
|
|
20
|
+
shuffle(): void;
|
|
21
|
+
}
|
|
22
22
|
//# sourceMappingURL=operatorNode.d.ts.map
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OperatorNode = exports.OperatorIds = void 0;
|
|
4
|
-
const coinFlip_1 = require("../../../utils/coinFlip");
|
|
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, coinFlip_1.coinFlip)())
|
|
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 coinFlip_1 = require("../../../utils/coinFlip");
|
|
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, coinFlip_1.coinFlip)())
|
|
30
|
+
return;
|
|
31
|
+
[this.leftChild, this.rightChild] = [this.rightChild, this.leftChild];
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.OperatorNode = OperatorNode;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Node } from '../node';
|
|
2
|
-
import { OperatorNode } from './operatorNode';
|
|
3
|
-
export declare class PowerNode extends OperatorNode implements Node {
|
|
4
|
-
constructor(leftChild: Node, rightChild: Node);
|
|
5
|
-
toMathString(): string;
|
|
6
|
-
toTex(): string;
|
|
7
|
-
}
|
|
1
|
+
import { Node } from '../node';
|
|
2
|
+
import { OperatorNode } from './operatorNode';
|
|
3
|
+
export declare class PowerNode extends OperatorNode implements Node {
|
|
4
|
+
constructor(leftChild: Node, rightChild: Node);
|
|
5
|
+
toMathString(): string;
|
|
6
|
+
toTex(): string;
|
|
7
|
+
}
|
|
8
8
|
//# sourceMappingURL=powerNode.d.ts.map
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PowerNode = void 0;
|
|
4
|
-
const node_1 = require("../node");
|
|
5
|
-
const operatorNode_1 = require("./operatorNode");
|
|
6
|
-
class PowerNode extends operatorNode_1.OperatorNode {
|
|
7
|
-
constructor(leftChild, rightChild) {
|
|
8
|
-
super(operatorNode_1.OperatorIds.power, leftChild, rightChild, false, '^');
|
|
9
|
-
}
|
|
10
|
-
toMathString() {
|
|
11
|
-
return `(${this.leftChild.toMathString()})^(${this.rightChild.toMathString()})`;
|
|
12
|
-
}
|
|
13
|
-
toTex() {
|
|
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 node_1 = require("../node");
|
|
5
|
+
const operatorNode_1 = require("./operatorNode");
|
|
6
|
+
class PowerNode extends operatorNode_1.OperatorNode {
|
|
7
|
+
constructor(leftChild, rightChild) {
|
|
8
|
+
super(operatorNode_1.OperatorIds.power, leftChild, rightChild, false, '^');
|
|
9
|
+
}
|
|
10
|
+
toMathString() {
|
|
11
|
+
return `(${this.leftChild.toMathString()})^(${this.rightChild.toMathString()})`;
|
|
12
|
+
}
|
|
13
|
+
toTex() {
|
|
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,8 +1,8 @@
|
|
|
1
|
-
import { Node } from '../node';
|
|
2
|
-
import { OperatorNode } from './operatorNode';
|
|
3
|
-
export declare class SubstractNode extends OperatorNode implements Node {
|
|
4
|
-
constructor(leftChild: Node, rightChild: Node);
|
|
5
|
-
toMathString(): string;
|
|
6
|
-
toTex(): string;
|
|
7
|
-
}
|
|
1
|
+
import { Node } from '../node';
|
|
2
|
+
import { OperatorNode } from './operatorNode';
|
|
3
|
+
export declare class SubstractNode extends OperatorNode implements Node {
|
|
4
|
+
constructor(leftChild: Node, rightChild: Node);
|
|
5
|
+
toMathString(): string;
|
|
6
|
+
toTex(): string;
|
|
7
|
+
}
|
|
8
8
|
//# sourceMappingURL=substractNode.d.ts.map
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubstractNode = void 0;
|
|
4
|
-
const node_1 = require("../node");
|
|
5
|
-
const operatorNode_1 = require("./operatorNode");
|
|
6
|
-
class SubstractNode extends operatorNode_1.OperatorNode {
|
|
7
|
-
constructor(leftChild, rightChild) {
|
|
8
|
-
super(operatorNode_1.OperatorIds.substract, leftChild, rightChild, false, '-');
|
|
9
|
-
}
|
|
10
|
-
toMathString() {
|
|
11
|
-
return `${this.leftChild.toMathString()}-(${this.rightChild.toMathString()})`;
|
|
12
|
-
}
|
|
13
|
-
toTex() {
|
|
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 node_1 = require("../node");
|
|
5
|
+
const operatorNode_1 = require("./operatorNode");
|
|
6
|
+
class SubstractNode extends operatorNode_1.OperatorNode {
|
|
7
|
+
constructor(leftChild, rightChild) {
|
|
8
|
+
super(operatorNode_1.OperatorIds.substract, leftChild, rightChild, false, '-');
|
|
9
|
+
}
|
|
10
|
+
toMathString() {
|
|
11
|
+
return `${this.leftChild.toMathString()}-(${this.rightChild.toMathString()})`;
|
|
12
|
+
}
|
|
13
|
+
toTex() {
|
|
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,9 +1,9 @@
|
|
|
1
|
-
import { Node, NodeType } from '../node';
|
|
2
|
-
export declare class VariableNode implements Node {
|
|
3
|
-
name: string;
|
|
4
|
-
type: NodeType;
|
|
5
|
-
constructor(name: string);
|
|
6
|
-
toTex(): string;
|
|
7
|
-
toMathString(): string;
|
|
8
|
-
}
|
|
1
|
+
import { Node, NodeType } from '../node';
|
|
2
|
+
export declare class VariableNode implements Node {
|
|
3
|
+
name: string;
|
|
4
|
+
type: NodeType;
|
|
5
|
+
constructor(name: string);
|
|
6
|
+
toTex(): string;
|
|
7
|
+
toMathString(): string;
|
|
8
|
+
}
|
|
9
9
|
//# sourceMappingURL=variableNode.d.ts.map
|
|
@@ -1,19 +1,19 @@
|
|
|
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(name) {
|
|
7
|
-
this.type = node_1.NodeType.variable;
|
|
8
|
-
if (name.length !== 1 || !name.match('[a-zA-Z]'))
|
|
9
|
-
throw Error('variable must be a letter');
|
|
10
|
-
this.name = name;
|
|
11
|
-
}
|
|
12
|
-
toTex() {
|
|
13
|
-
return `${this.name}`;
|
|
14
|
-
}
|
|
15
|
-
toMathString() {
|
|
16
|
-
return `${this.name}`;
|
|
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(name) {
|
|
7
|
+
this.type = node_1.NodeType.variable;
|
|
8
|
+
if (name.length !== 1 || !name.match('[a-zA-Z]'))
|
|
9
|
+
throw Error('variable must be a letter');
|
|
10
|
+
this.name = name;
|
|
11
|
+
}
|
|
12
|
+
toTex() {
|
|
13
|
+
return `${this.name}`;
|
|
14
|
+
}
|
|
15
|
+
toMathString() {
|
|
16
|
+
return `${this.name}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.VariableNode = VariableNode;
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { Node, NodeType } from "../nodes/node";
|
|
3
|
-
// import { NumberNode } from "../nodes/numbers/numberNode";
|
|
4
|
-
// import { PowerNode } from "../nodes/operators/powerNode";
|
|
5
|
-
// import { AddNode } from "../nodes/operators/addNode";
|
|
6
|
-
// import { FractionNode } from "../nodes/operators/fractionNode";
|
|
7
|
-
// import { MultiplyNode } from "../nodes/operators/multiplyNode";
|
|
8
|
-
// import { OperatorIds, OperatorNode } from "../nodes/operators/operatorNode";
|
|
9
|
-
// import { SubstractNode } from "../nodes/operators/substractNode";
|
|
10
|
-
// import { FunctionNode, FunctionsIds } from "../nodes/functions/functionNode";
|
|
11
|
-
// import { SqrtNode } from "../nodes/functions/sqrtNode";
|
|
12
|
-
// import { OppositeNode } from "../nodes/functions/oppositeNode";
|
|
13
|
-
// export function derivateParser(node: Node): Node {
|
|
14
|
-
// if (!node) throw Error("encountered a null node ??");
|
|
15
|
-
// switch (node.type) {
|
|
16
|
-
// case NodeType.variable:
|
|
17
|
-
// return new NumberNode(1);
|
|
18
|
-
// case NodeType.number:
|
|
19
|
-
// return new NumberNode(0);
|
|
20
|
-
// case NodeType.operator:
|
|
21
|
-
// const operatorNode = node as OperatorNode;
|
|
22
|
-
// const u = operatorNode.leftChild;
|
|
23
|
-
// const v = operatorNode.rightChild;
|
|
24
|
-
// switch (operatorNode.id) {
|
|
25
|
-
// case OperatorIds.add:
|
|
26
|
-
// return new AddNode(derivateParser(u), derivateParser(v));
|
|
27
|
-
// case OperatorIds.substract: {
|
|
28
|
-
// return new SubstractNode(derivateParser(u), derivateParser(v));
|
|
29
|
-
// }
|
|
30
|
-
// case OperatorIds.multiply: {
|
|
31
|
-
// return new AddNode(new MultiplyNode(derivateParser(u), v), new MultiplyNode(u, derivateParser(v)));
|
|
32
|
-
// }
|
|
33
|
-
// case OperatorIds.divide:
|
|
34
|
-
// case OperatorIds.fraction:
|
|
35
|
-
// return new FractionNode(
|
|
36
|
-
// new SubstractNode(new MultiplyNode(derivateParser(u), v), new MultiplyNode(u, derivateParser(v))),
|
|
37
|
-
// new PowerNode(v, new NumberNode(2))
|
|
38
|
-
// );
|
|
39
|
-
// case OperatorIds.power: {
|
|
40
|
-
// const operatorNode = node as OperatorNode;
|
|
41
|
-
// const n = operatorNode.rightChild as NumberNode;
|
|
42
|
-
// const u = operatorNode.leftChild;
|
|
43
|
-
// return new MultiplyNode(
|
|
44
|
-
// n,
|
|
45
|
-
// new MultiplyNode(derivateParser(u), new PowerNode(u, new NumberNode(n.value - 1)))
|
|
46
|
-
// );
|
|
47
|
-
// }
|
|
48
|
-
// }
|
|
49
|
-
// case NodeType.function: {
|
|
50
|
-
// const functionNode = node as FunctionNode;
|
|
51
|
-
// const child = functionNode.child;
|
|
52
|
-
// switch (functionNode.id) {
|
|
53
|
-
// case FunctionsIds.sqrt: {
|
|
54
|
-
// return new FractionNode(derivateParser(child), new MultiplyNode(new NumberNode(2), new SqrtNode(child)));
|
|
55
|
-
// }
|
|
56
|
-
// case FunctionsIds.opposite: {
|
|
57
|
-
// return new OppositeNode(derivateParser(child));
|
|
58
|
-
// }
|
|
59
|
-
// }
|
|
60
|
-
// }
|
|
61
|
-
// }
|
|
62
|
-
// }
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { Node, NodeType } from "../nodes/node";
|
|
3
|
+
// import { NumberNode } from "../nodes/numbers/numberNode";
|
|
4
|
+
// import { PowerNode } from "../nodes/operators/powerNode";
|
|
5
|
+
// import { AddNode } from "../nodes/operators/addNode";
|
|
6
|
+
// import { FractionNode } from "../nodes/operators/fractionNode";
|
|
7
|
+
// import { MultiplyNode } from "../nodes/operators/multiplyNode";
|
|
8
|
+
// import { OperatorIds, OperatorNode } from "../nodes/operators/operatorNode";
|
|
9
|
+
// import { SubstractNode } from "../nodes/operators/substractNode";
|
|
10
|
+
// import { FunctionNode, FunctionsIds } from "../nodes/functions/functionNode";
|
|
11
|
+
// import { SqrtNode } from "../nodes/functions/sqrtNode";
|
|
12
|
+
// import { OppositeNode } from "../nodes/functions/oppositeNode";
|
|
13
|
+
// export function derivateParser(node: Node): Node {
|
|
14
|
+
// if (!node) throw Error("encountered a null node ??");
|
|
15
|
+
// switch (node.type) {
|
|
16
|
+
// case NodeType.variable:
|
|
17
|
+
// return new NumberNode(1);
|
|
18
|
+
// case NodeType.number:
|
|
19
|
+
// return new NumberNode(0);
|
|
20
|
+
// case NodeType.operator:
|
|
21
|
+
// const operatorNode = node as OperatorNode;
|
|
22
|
+
// const u = operatorNode.leftChild;
|
|
23
|
+
// const v = operatorNode.rightChild;
|
|
24
|
+
// switch (operatorNode.id) {
|
|
25
|
+
// case OperatorIds.add:
|
|
26
|
+
// return new AddNode(derivateParser(u), derivateParser(v));
|
|
27
|
+
// case OperatorIds.substract: {
|
|
28
|
+
// return new SubstractNode(derivateParser(u), derivateParser(v));
|
|
29
|
+
// }
|
|
30
|
+
// case OperatorIds.multiply: {
|
|
31
|
+
// return new AddNode(new MultiplyNode(derivateParser(u), v), new MultiplyNode(u, derivateParser(v)));
|
|
32
|
+
// }
|
|
33
|
+
// case OperatorIds.divide:
|
|
34
|
+
// case OperatorIds.fraction:
|
|
35
|
+
// return new FractionNode(
|
|
36
|
+
// new SubstractNode(new MultiplyNode(derivateParser(u), v), new MultiplyNode(u, derivateParser(v))),
|
|
37
|
+
// new PowerNode(v, new NumberNode(2))
|
|
38
|
+
// );
|
|
39
|
+
// case OperatorIds.power: {
|
|
40
|
+
// const operatorNode = node as OperatorNode;
|
|
41
|
+
// const n = operatorNode.rightChild as NumberNode;
|
|
42
|
+
// const u = operatorNode.leftChild;
|
|
43
|
+
// return new MultiplyNode(
|
|
44
|
+
// n,
|
|
45
|
+
// new MultiplyNode(derivateParser(u), new PowerNode(u, new NumberNode(n.value - 1)))
|
|
46
|
+
// );
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
// case NodeType.function: {
|
|
50
|
+
// const functionNode = node as FunctionNode;
|
|
51
|
+
// const child = functionNode.child;
|
|
52
|
+
// switch (functionNode.id) {
|
|
53
|
+
// case FunctionsIds.sqrt: {
|
|
54
|
+
// return new FractionNode(derivateParser(child), new MultiplyNode(new NumberNode(2), new SqrtNode(child)));
|
|
55
|
+
// }
|
|
56
|
+
// case FunctionsIds.opposite: {
|
|
57
|
+
// return new OppositeNode(derivateParser(child));
|
|
58
|
+
// }
|
|
59
|
+
// }
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
// }
|