math-exercises 1.2.10 → 1.3.0
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 +63 -0
- package/lib/exercises/calcul/addAndSub.js +8 -9
- package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +7 -8
- package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +9 -9
- package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +7 -8
- package/lib/exercises/calcul/fractions/fractionsDivision.js +8 -9
- package/lib/exercises/calcul/fractions/fractionsProduct.js +8 -9
- package/lib/exercises/calcul/fractions/fractionsSum.js +8 -9
- package/lib/exercises/calcul/fractions/simplifyFraction.js +2 -3
- package/lib/exercises/calcul/operations/operationsPriorities.js +25 -15
- package/lib/exercises/calcul/rounding/rounding.js +33 -34
- package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +9 -10
- package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +9 -10
- package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +10 -11
- package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +9 -10
- package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +9 -10
- package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +9 -10
- package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +11 -12
- package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +11 -12
- package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +12 -13
- package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +11 -12
- package/lib/exercises/geometry/cartesian/midpoint.js +1 -1
- package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +9 -10
- package/lib/exercises/powers/powersDivision.js +14 -15
- package/lib/exercises/powers/powersOfTenToDecimal.js +6 -7
- package/lib/exercises/powers/powersPower.js +12 -13
- package/lib/exercises/powers/powersProduct.js +14 -15
- package/lib/exercises/powers/scientificToDecimal.js +8 -9
- package/lib/exercises/squareRoots/simpifySquareRoot.js +8 -9
- package/lib/exercises/utils/getDistinctQuestions.js +1 -2
- package/lib/geometry/point.js +4 -4
- package/lib/geometry/vector.js +3 -3
- package/lib/index.js +4 -5
- package/lib/tree/nodes/functions/oppositeNode.js +16 -3
- package/lib/tree/nodes/functions/sqrtNode.js +6 -3
- package/lib/tree/nodes/numbers/numberNode.js +1 -1
- package/lib/tree/nodes/operators/addNode.js +7 -3
- package/lib/tree/nodes/operators/divideNode.js +20 -3
- package/lib/tree/nodes/operators/equalNode.js +6 -3
- package/lib/tree/nodes/operators/fractionNode.js +6 -3
- package/lib/tree/nodes/operators/multiplyNode.js +26 -3
- package/lib/tree/nodes/operators/operatorNode.js +3 -3
- package/lib/tree/nodes/operators/powerNode.js +23 -3
- package/lib/tree/nodes/operators/substractNode.js +14 -3
- package/lib/tree/nodes/variables/variableNode.js +9 -6
- package/lib/tree/parsers/derivateParser.js +61 -59
- package/lib/tree/parsers/latexParser.js +109 -116
- package/lib/tree/parsers/simplify.js +51 -0
- package/package.json +5 -2
|
@@ -4,7 +4,6 @@ exports.getScientificToDecimalQuestion = exports.scientificToDecimal = void 0;
|
|
|
4
4
|
const randint_1 = require("../../mathutils/random/randint");
|
|
5
5
|
const decimal_1 = require("../../numbers/decimals/decimal");
|
|
6
6
|
const integer_1 = require("../../numbers/integer/integer");
|
|
7
|
-
const latexParser_1 = require("../../tree/parsers/latexParser");
|
|
8
7
|
const numberNode_1 = require("../../tree/nodes/numbers/numberNode");
|
|
9
8
|
const multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
|
|
10
9
|
const powerNode_1 = require("../../tree/nodes/operators/powerNode");
|
|
@@ -13,12 +12,12 @@ const getDistinctQuestions_1 = require("../utils/getDistinctQuestions");
|
|
|
13
12
|
* a*10^x vers décimal
|
|
14
13
|
* */
|
|
15
14
|
exports.scientificToDecimal = {
|
|
16
|
-
id:
|
|
17
|
-
connector:
|
|
15
|
+
id: 'scientificToDecimal',
|
|
16
|
+
connector: '=',
|
|
18
17
|
instruction: "Donner l'écriture décimale de :",
|
|
19
|
-
label:
|
|
20
|
-
levels: [
|
|
21
|
-
section:
|
|
18
|
+
label: 'Ecriture décimale de $a\\times 10^x$',
|
|
19
|
+
levels: ['5', '4', '3', '2'],
|
|
20
|
+
section: 'Puissances',
|
|
22
21
|
isSingleStep: true,
|
|
23
22
|
generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getScientificToDecimalQuestion, nb),
|
|
24
23
|
};
|
|
@@ -26,12 +25,12 @@ function getScientificToDecimalQuestion() {
|
|
|
26
25
|
const randPower = (0, randint_1.randint)(-6, 8);
|
|
27
26
|
const int = integer_1.IntegerConstructor.random((0, randint_1.randint)(1, 4));
|
|
28
27
|
const fracPart = decimal_1.DecimalConstructor.randomFracPart((0, randint_1.randint)(0, 4));
|
|
29
|
-
const randDecimal = decimal_1.DecimalConstructor.fromParts(int +
|
|
28
|
+
const randDecimal = decimal_1.DecimalConstructor.fromParts(int + '', fracPart);
|
|
30
29
|
const statement = new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(randDecimal.value), new powerNode_1.PowerNode(new numberNode_1.NumberNode(10), new numberNode_1.NumberNode(randPower)));
|
|
31
30
|
const answerTree = randDecimal.multiplyByPowerOfTen(randPower).toTree();
|
|
32
31
|
const question = {
|
|
33
|
-
startStatement:
|
|
34
|
-
answer:
|
|
32
|
+
startStatement: statement.toTex(),
|
|
33
|
+
answer: answerTree.toTex(),
|
|
35
34
|
};
|
|
36
35
|
return question;
|
|
37
36
|
}
|
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSimplifySquareRoot = exports.simplifySquareRoot = void 0;
|
|
4
4
|
const squareRoot_1 = require("../../numbers/reals/squareRoot");
|
|
5
|
-
const latexParser_1 = require("../../tree/parsers/latexParser");
|
|
6
5
|
const getDistinctQuestions_1 = require("../utils/getDistinctQuestions");
|
|
7
6
|
exports.simplifySquareRoot = {
|
|
8
|
-
id:
|
|
9
|
-
connector:
|
|
10
|
-
instruction:
|
|
11
|
-
label:
|
|
12
|
-
levels: [
|
|
7
|
+
id: 'simplifySqrt',
|
|
8
|
+
connector: '=',
|
|
9
|
+
instruction: 'Simplifier :',
|
|
10
|
+
label: 'Simplification de racines carrées',
|
|
11
|
+
levels: ['3', '2', '1'],
|
|
13
12
|
isSingleStep: false,
|
|
14
|
-
section:
|
|
13
|
+
section: 'Racines carrées',
|
|
15
14
|
generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getSimplifySquareRoot, nb),
|
|
16
15
|
};
|
|
17
16
|
function getSimplifySquareRoot() {
|
|
@@ -20,8 +19,8 @@ function getSimplifySquareRoot() {
|
|
|
20
19
|
maxSquare: 11,
|
|
21
20
|
});
|
|
22
21
|
const question = {
|
|
23
|
-
startStatement:
|
|
24
|
-
answer:
|
|
22
|
+
startStatement: squareRoot.toTree().toTex(),
|
|
23
|
+
answer: squareRoot.simplify().toTree().toTex(),
|
|
25
24
|
};
|
|
26
25
|
return question;
|
|
27
26
|
}
|
|
@@ -7,8 +7,7 @@ const getDistinctQuestions = (generator, nb) => {
|
|
|
7
7
|
let question;
|
|
8
8
|
do {
|
|
9
9
|
question = generator();
|
|
10
|
-
} while (res.some((q) => q.instruction
|
|
11
|
-
q.startStatement === question.startStatement));
|
|
10
|
+
} while (res.some((q) => q.instruction === question.instruction && q.startStatement === question.startStatement));
|
|
12
11
|
res.push(question);
|
|
13
12
|
}
|
|
14
13
|
return res;
|
package/lib/geometry/point.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.Point = exports.PointConstructor = void 0;
|
|
|
4
4
|
const numberNode_1 = require("../tree/nodes/numbers/numberNode");
|
|
5
5
|
const addNode_1 = require("../tree/nodes/operators/addNode");
|
|
6
6
|
const fractionNode_1 = require("../tree/nodes/operators/fractionNode");
|
|
7
|
-
const
|
|
7
|
+
const simplify_1 = require("../tree/parsers/simplify");
|
|
8
8
|
class PointConstructor {
|
|
9
9
|
}
|
|
10
10
|
exports.PointConstructor = PointConstructor;
|
|
@@ -18,10 +18,10 @@ class Point {
|
|
|
18
18
|
return `${this.name}`;
|
|
19
19
|
}
|
|
20
20
|
toTexWithCoords() {
|
|
21
|
-
return `${this.name}\\left(${
|
|
21
|
+
return `${this.name}\\left(${this.x.toTex()}; ${this.y.toTex()}\\right)`;
|
|
22
22
|
}
|
|
23
|
-
midpoint(B, name =
|
|
24
|
-
return new Point(name, new fractionNode_1.FractionNode(new addNode_1.AddNode(this.x, B.x), new numberNode_1.NumberNode(2)), new fractionNode_1.FractionNode(new addNode_1.AddNode(this.y, B.y), new numberNode_1.NumberNode(2)));
|
|
23
|
+
midpoint(B, name = 'I') {
|
|
24
|
+
return new Point(name, (0, simplify_1.simplifyNode)(new fractionNode_1.FractionNode(new addNode_1.AddNode(this.x, B.x), new numberNode_1.NumberNode(2))), (0, simplify_1.simplifyNode)(new fractionNode_1.FractionNode(new addNode_1.AddNode(this.y, B.y), new numberNode_1.NumberNode(2))));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.Point = Point;
|
package/lib/geometry/vector.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.Vector = exports.VectorConstructor = void 0;
|
|
|
4
4
|
const addNode_1 = require("../tree/nodes/operators/addNode");
|
|
5
5
|
const multiplyNode_1 = require("../tree/nodes/operators/multiplyNode");
|
|
6
6
|
const substractNode_1 = require("../tree/nodes/operators/substractNode");
|
|
7
|
-
const
|
|
7
|
+
const simplify_1 = require("../tree/parsers/simplify");
|
|
8
8
|
class VectorConstructor {
|
|
9
9
|
static fromPoints(origin, end) {
|
|
10
10
|
return new Vector(`${origin.name}${end.name}`, new substractNode_1.SubstractNode(end.x, origin.x), new substractNode_1.SubstractNode(end.y, origin.y));
|
|
@@ -22,10 +22,10 @@ class Vector {
|
|
|
22
22
|
return `\\overrightarrow{${this.name}}`;
|
|
23
23
|
}
|
|
24
24
|
toTexWithCoords() {
|
|
25
|
-
return `\\overrightarrow{${this.name}}\\begin{pmatrix}${
|
|
25
|
+
return `\\overrightarrow{${this.name}}\\begin{pmatrix}${this.x.toTex()} \\\\ ${this.y.toTex()} \\end{pmatrix}`;
|
|
26
26
|
}
|
|
27
27
|
scalarProduct(v) {
|
|
28
|
-
return new addNode_1.AddNode(new multiplyNode_1.MultiplyNode(this.x, v.x), new multiplyNode_1.MultiplyNode(this.y, v.y));
|
|
28
|
+
return (0, simplify_1.simplifyNode)(new addNode_1.AddNode(new multiplyNode_1.MultiplyNode(this.x, v.x), new multiplyNode_1.MultiplyNode(this.y, v.y)));
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
exports.Vector = Vector;
|
package/lib/index.js
CHANGED
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.exercises = void 0;
|
|
4
4
|
const exercises_1 = require("./exercises/exercises");
|
|
5
5
|
Object.defineProperty(exports, "exercises", { enumerable: true, get: function () { return exercises_1.exercises; } });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
console.log(scalarProductViaCoords_1.scalarProductViaCoords.generator(10));
|
|
6
|
+
// import { simplify } from './tree/parsers/simplify';
|
|
7
|
+
exercises_1.exercises.forEach((exo) => {
|
|
8
|
+
console.log(exo.instruction, exo.generator(10));
|
|
9
|
+
});
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OppositeNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
5
|
+
const operatorNode_1 = require("../operators/operatorNode");
|
|
4
6
|
const functionNode_1 = require("./functionNode");
|
|
5
7
|
class OppositeNode extends functionNode_1.FunctionNode {
|
|
6
8
|
constructor(child) {
|
|
7
|
-
super(functionNode_1.FunctionsIds.opposite, child,
|
|
9
|
+
super(functionNode_1.FunctionsIds.opposite, child, '-');
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
return `-(${this.child})`;
|
|
11
|
+
toMathString() {
|
|
12
|
+
return `-(${this.child.toMathString()})`;
|
|
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}`;
|
|
11
24
|
}
|
|
12
25
|
}
|
|
13
26
|
exports.OppositeNode = OppositeNode;
|
|
@@ -5,11 +5,14 @@ const node_1 = require("../node");
|
|
|
5
5
|
const functionNode_1 = require("./functionNode");
|
|
6
6
|
class SqrtNode extends functionNode_1.FunctionNode {
|
|
7
7
|
constructor(child) {
|
|
8
|
-
super(functionNode_1.FunctionsIds.sqrt, child,
|
|
8
|
+
super(functionNode_1.FunctionsIds.sqrt, child, '\\sqrt');
|
|
9
9
|
this.type = node_1.NodeType.function;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
return `sqrt(${this.child})`;
|
|
11
|
+
toMathString() {
|
|
12
|
+
return `sqrt(${this.child.toMathString()})`;
|
|
13
|
+
}
|
|
14
|
+
toTex() {
|
|
15
|
+
return `\\sqrt{${this.child.toTex()}}`;
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
exports.SqrtNode = SqrtNode;
|
|
@@ -4,12 +4,16 @@ exports.AddNode = void 0;
|
|
|
4
4
|
const operatorNode_1 = require("./operatorNode");
|
|
5
5
|
class AddNode extends operatorNode_1.OperatorNode {
|
|
6
6
|
constructor(leftChild, rightChild) {
|
|
7
|
-
super(operatorNode_1.OperatorIds.add, leftChild, rightChild, true,
|
|
7
|
+
super(operatorNode_1.OperatorIds.add, leftChild, rightChild, true, '+');
|
|
8
8
|
this.leftChild = leftChild;
|
|
9
9
|
this.rightChild = rightChild;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
return `${this.leftChild} + ${this.rightChild}`;
|
|
11
|
+
toMathString() {
|
|
12
|
+
return `${this.leftChild.toMathString()} + (${this.rightChild.toMathString()})`;
|
|
13
|
+
}
|
|
14
|
+
toTex() {
|
|
15
|
+
const rightTex = this.rightChild.toTex();
|
|
16
|
+
return `${this.leftChild.toTex()} ${rightTex[0] === '-' ? '' : '+ '}${rightTex}`;
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
exports.AddNode = AddNode;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DivideNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
4
5
|
const operatorNode_1 = require("./operatorNode");
|
|
5
6
|
class DivideNode extends operatorNode_1.OperatorNode {
|
|
6
7
|
/**
|
|
@@ -8,10 +9,26 @@ class DivideNode extends operatorNode_1.OperatorNode {
|
|
|
8
9
|
* @param rightChild denum
|
|
9
10
|
*/
|
|
10
11
|
constructor(leftChild, rightChild) {
|
|
11
|
-
super(operatorNode_1.OperatorIds.divide, leftChild, rightChild, false,
|
|
12
|
+
super(operatorNode_1.OperatorIds.divide, leftChild, rightChild, false, '\\div');
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
return `(${this.leftChild})
|
|
14
|
+
toMathString() {
|
|
15
|
+
return `(${this.leftChild.toMathString()}) / (${this.rightChild.toMathString()})`;
|
|
16
|
+
}
|
|
17
|
+
toTex() {
|
|
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}`;
|
|
15
32
|
}
|
|
16
33
|
}
|
|
17
34
|
exports.DivideNode = DivideNode;
|
|
@@ -4,10 +4,13 @@ exports.EqualNode = void 0;
|
|
|
4
4
|
const operatorNode_1 = require("./operatorNode");
|
|
5
5
|
class EqualNode extends operatorNode_1.OperatorNode {
|
|
6
6
|
constructor(leftChild, rightChild) {
|
|
7
|
-
super(operatorNode_1.OperatorIds.equal, leftChild, rightChild, true,
|
|
7
|
+
super(operatorNode_1.OperatorIds.equal, leftChild, rightChild, true, '=');
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
return `${this.leftChild} = ${this.rightChild}`;
|
|
9
|
+
toMathString() {
|
|
10
|
+
return `${this.leftChild.toMathString()} = ${this.rightChild.toMathString()}`;
|
|
11
|
+
}
|
|
12
|
+
toTex() {
|
|
13
|
+
return `${this.leftChild.toTex()} = ${this.rightChild.toTex()}`;
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
16
|
exports.EqualNode = EqualNode;
|
|
@@ -8,10 +8,13 @@ class FractionNode extends operatorNode_1.OperatorNode {
|
|
|
8
8
|
* @param rightChild denum
|
|
9
9
|
*/
|
|
10
10
|
constructor(leftChild, rightChild) {
|
|
11
|
-
super(operatorNode_1.OperatorIds.fraction, leftChild, rightChild, false,
|
|
11
|
+
super(operatorNode_1.OperatorIds.fraction, leftChild, rightChild, false, '\\frac');
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
return
|
|
13
|
+
toMathString() {
|
|
14
|
+
return `(${this.leftChild.toMathString()}) / (${this.rightChild.toMathString()})`;
|
|
15
|
+
}
|
|
16
|
+
toTex() {
|
|
17
|
+
return `\\frac{${this.leftChild.toTex()}}{${this.rightChild.toTex()}}`;
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
exports.FractionNode = FractionNode;
|
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MultiplyNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
4
5
|
const operatorNode_1 = require("./operatorNode");
|
|
5
6
|
class MultiplyNode extends operatorNode_1.OperatorNode {
|
|
6
7
|
constructor(leftChild, rightChild) {
|
|
7
|
-
super(operatorNode_1.OperatorIds.multiply, leftChild, rightChild, true,
|
|
8
|
+
super(operatorNode_1.OperatorIds.multiply, leftChild, rightChild, true, '\\times');
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
return `(${this.leftChild})*(${this.rightChild})`;
|
|
10
|
+
toMathString() {
|
|
11
|
+
return `(${this.leftChild.toMathString()})*(${this.rightChild.toMathString()})`;
|
|
12
|
+
}
|
|
13
|
+
toTex() {
|
|
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}`;
|
|
11
34
|
}
|
|
12
35
|
}
|
|
13
36
|
exports.MultiplyNode = MultiplyNode;
|
|
@@ -25,11 +25,11 @@ class OperatorNode {
|
|
|
25
25
|
/**shuffles in place */
|
|
26
26
|
shuffle() {
|
|
27
27
|
if (!this.isCommutative)
|
|
28
|
-
return
|
|
28
|
+
return;
|
|
29
29
|
if ((0, coin_1.coin)())
|
|
30
|
-
return
|
|
30
|
+
return;
|
|
31
31
|
[this.leftChild, this.rightChild] = [this.rightChild, this.leftChild];
|
|
32
|
-
return
|
|
32
|
+
return;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
exports.OperatorNode = OperatorNode;
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PowerNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
4
5
|
const operatorNode_1 = require("./operatorNode");
|
|
5
6
|
class PowerNode extends operatorNode_1.OperatorNode {
|
|
6
7
|
constructor(leftChild, rightChild) {
|
|
7
|
-
super(operatorNode_1.OperatorIds.power, leftChild, rightChild, false,
|
|
8
|
+
super(operatorNode_1.OperatorIds.power, leftChild, rightChild, false, '^');
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
return `(${this.leftChild})^
|
|
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}}`;
|
|
11
31
|
}
|
|
12
32
|
}
|
|
13
33
|
exports.PowerNode = PowerNode;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SubstractNode = void 0;
|
|
4
|
+
const node_1 = require("../node");
|
|
4
5
|
const operatorNode_1 = require("./operatorNode");
|
|
5
6
|
class SubstractNode extends operatorNode_1.OperatorNode {
|
|
6
7
|
constructor(leftChild, rightChild) {
|
|
7
|
-
super(operatorNode_1.OperatorIds.substract, leftChild, rightChild, false,
|
|
8
|
+
super(operatorNode_1.OperatorIds.substract, leftChild, rightChild, false, '-');
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
return `${this.leftChild}-(${this.rightChild})`;
|
|
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}`;
|
|
11
22
|
}
|
|
12
23
|
}
|
|
13
24
|
exports.SubstractNode = SubstractNode;
|
|
@@ -3,14 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VariableNode = void 0;
|
|
4
4
|
const node_1 = require("../node");
|
|
5
5
|
class VariableNode {
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(name) {
|
|
7
7
|
this.type = node_1.NodeType.variable;
|
|
8
|
-
if (
|
|
9
|
-
throw Error(
|
|
10
|
-
this.
|
|
8
|
+
if (name.length !== 1 || !name.match('[a-zA-Z]'))
|
|
9
|
+
throw Error('variable must be a letter');
|
|
10
|
+
this.name = name;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
return `${this.
|
|
12
|
+
toTex() {
|
|
13
|
+
return `${this.name}`;
|
|
14
|
+
}
|
|
15
|
+
toMathString() {
|
|
16
|
+
return `${this.name}`;
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
exports.VariableNode = VariableNode;
|
|
@@ -1,60 +1,62 @@
|
|
|
1
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
|
-
|
|
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
|
+
// }
|