math-exercises 1.1.1 → 1.2.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/package.json +1 -1
- package/src/exercises/calcul/addAndSub.js +19 -13
- package/src/exercises/calcul/addAndSub.ts +31 -23
- package/src/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -0
- package/src/exercises/calcul/fractions/fractionAndIntegerDivision.ts +38 -0
- package/src/exercises/calcul/fractions/fractionAndIntegerProduct.js +31 -0
- package/src/exercises/calcul/fractions/fractionAndIntegerProduct.ts +32 -0
- package/src/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -0
- package/src/exercises/calcul/fractions/fractionAndIntegerSum.ts +31 -0
- package/src/exercises/calcul/fractions/fractionsDivision.js +29 -0
- package/src/exercises/calcul/fractions/fractionsDivision.ts +30 -0
- package/src/exercises/calcul/fractions/fractionsProduct.js +29 -0
- package/src/exercises/calcul/fractions/fractionsProduct.ts +29 -0
- package/src/exercises/calcul/fractions/fractionsSum.js +29 -0
- package/src/exercises/calcul/fractions/fractionsSum.ts +28 -0
- package/src/exercises/calcul/fractions/simplifyFraction.js +25 -0
- package/src/exercises/calcul/fractions/simplifyFraction.ts +24 -0
- package/src/exercises/calcul/operationsPriorities.js +89 -0
- package/src/exercises/calcul/operationsPriorities.ts +118 -0
- package/src/exercises/calcul/rounding/roundToUnit.js +70 -0
- package/src/exercises/calcul/rounding/roundToUnit.ts +68 -0
- package/src/exercises/calculLitteral/distributivity/allIdentities.js +1 -0
- package/src/exercises/calculLitteral/distributivity/allIdentities.ts +1 -0
- package/src/exercises/calculLitteral/distributivity/doubleDistributivity.js +1 -0
- package/src/exercises/calculLitteral/distributivity/doubleDistributivity.ts +1 -0
- package/src/exercises/calculLitteral/distributivity/firstIdentity.js +1 -0
- package/src/exercises/calculLitteral/distributivity/firstIdentity.ts +1 -0
- package/src/exercises/calculLitteral/distributivity/secondIdentity.js +1 -0
- package/src/exercises/calculLitteral/distributivity/secondIdentity.ts +1 -0
- package/src/exercises/calculLitteral/distributivity/simpleDistributivity.js +1 -0
- package/src/exercises/calculLitteral/distributivity/simpleDistributivity.ts +1 -0
- package/src/exercises/calculLitteral/distributivity/thirdIdentity.js +1 -0
- package/src/exercises/calculLitteral/distributivity/thirdIdentity.ts +1 -0
- package/src/exercises/calculLitteral/equation/equationType1Exercise.js +1 -0
- package/src/exercises/calculLitteral/equation/equationType1Exercise.ts +1 -0
- package/src/exercises/calculLitteral/equation/equationType2Exercise.js +1 -0
- package/src/exercises/calculLitteral/equation/equationType2Exercise.ts +1 -0
- package/src/exercises/calculLitteral/equation/equationType3Exercise.js +1 -0
- package/src/exercises/calculLitteral/equation/equationType3Exercise.ts +1 -0
- package/src/exercises/calculLitteral/equation/equationType4Exercise.js +1 -0
- package/src/exercises/calculLitteral/equation/equationType4Exercise.ts +1 -0
- package/src/exercises/calculLitteral/factorisation/factoType1Exercise.js +2 -6
- package/src/exercises/calculLitteral/factorisation/factoType1Exercise.ts +2 -6
- package/src/exercises/calculLitteral/reduction.ts +27 -0
- package/src/exercises/exercise.ts +1 -0
- package/src/exercises/exercises.js +54 -0
- package/src/exercises/exercises.ts +58 -0
- package/src/exercises/powers/powersDivision.js +46 -0
- package/src/exercises/powers/powersDivision.ts +51 -0
- package/src/exercises/powers/powersOfTenToDecimal.js +33 -0
- package/src/exercises/powers/powersOfTenToDecimal.ts +37 -0
- package/src/exercises/powers/powersPower.js +45 -0
- package/src/exercises/powers/powersPower.ts +55 -0
- package/src/exercises/powers/powersProduct.js +46 -0
- package/src/exercises/powers/powersProduct.ts +51 -0
- package/src/exercises/powers/scientificToDecimal.js +38 -0
- package/src/exercises/powers/scientificToDecimal.ts +44 -0
- package/src/exercises/squareRoots/simpifySquareRoot.js +1 -0
- package/src/exercises/squareRoots/simpifySquareRoot.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.ts +5 -16
- package/src/mathutils/arithmetic/coprimesOf.js +13 -0
- package/src/mathutils/arithmetic/coprimesOf.ts +9 -0
- package/src/mathutils/arithmetic/dividersOf.ts +7 -0
- package/src/mathutils/arithmetic/lcd.js +12 -0
- package/src/mathutils/arithmetic/lcd.ts +7 -0
- package/src/mathutils/arithmetic/nonCoprimesOf.ts +9 -0
- package/src/mathutils/arithmetic/nonDividersOf.ts +12 -0
- package/src/mathutils/decimals/decimalPartLengthOf.ts +10 -0
- package/src/mathutils/random/randint.js +11 -2
- package/src/mathutils/random/randint.ts +10 -2
- package/src/numbers/decimals/decimal.js +144 -0
- package/src/numbers/decimals/decimal.ts +140 -0
- package/src/numbers/integer/integer.js +61 -4
- package/src/numbers/integer/integer.ts +58 -7
- package/src/numbers/integer/power.js +53 -0
- package/src/numbers/integer/power.ts +49 -0
- package/src/numbers/nombre.js +3 -2
- package/src/numbers/nombre.ts +2 -0
- package/src/numbers/rationals/rational.js +96 -10
- package/src/numbers/rationals/rational.ts +81 -15
- package/src/numbers/reals/real.js +2 -0
- package/src/numbers/reals/real.ts +3 -1
- package/src/numbers/reals/squareRoot.ts +3 -10
- package/src/polynomials/affine.ts +2 -6
- package/src/polynomials/polynomial.js +4 -13
- package/src/polynomials/polynomial.ts +8 -25
- package/src/tree/latexParser/latexParse.js +81 -34
- package/src/tree/latexParser/latexParse.ts +85 -39
- package/src/tree/nodes/functions/functionNode.js +19 -0
- package/src/tree/nodes/functions/functionNode.ts +18 -0
- package/src/tree/nodes/functions/oppositeNode.js +30 -0
- package/src/tree/nodes/functions/oppositeNode.ts +12 -0
- package/src/tree/nodes/functions/sqrtNode.js +24 -9
- package/src/tree/nodes/functions/sqrtNode.ts +5 -9
- package/src/tree/nodes/node.ts +1 -3
- package/src/tree/nodes/numbers/numberNode.js +3 -6
- package/src/tree/nodes/numbers/numberNode.ts +4 -7
- package/src/tree/nodes/operators/addNode.js +23 -8
- package/src/tree/nodes/operators/addNode.ts +3 -7
- package/src/tree/nodes/operators/divideNode.js +21 -9
- package/src/tree/nodes/operators/divideNode.ts +4 -11
- package/src/tree/nodes/operators/equalNode.js +20 -8
- package/src/tree/nodes/operators/equalNode.ts +3 -9
- package/src/tree/nodes/operators/fractionNode.js +34 -0
- package/src/tree/nodes/operators/fractionNode.ts +16 -0
- package/src/tree/nodes/operators/multiplyNode.js +20 -8
- package/src/tree/nodes/operators/multiplyNode.ts +3 -9
- package/src/tree/nodes/operators/operatorNode.js +35 -0
- package/src/tree/nodes/operators/operatorNode.ts +35 -2
- package/src/tree/nodes/operators/powerNode.js +20 -8
- package/src/tree/nodes/operators/powerNode.ts +3 -8
- package/src/tree/nodes/operators/substractNode.js +20 -8
- package/src/tree/nodes/operators/substractNode.ts +3 -9
- package/src/tree/nodes/variables/variableNode.js +1 -4
- package/src/tree/nodes/variables/variableNode.ts +4 -7
- package/src/utils/coin.js +7 -0
- package/src/utils/coin.ts +3 -0
- package/src/utils/shuffle.js +15 -4
- package/src/utils/shuffle.ts +7 -5
- package/src/exercises/calcul/priority.ts +0 -33
- package/src/expression/expression.js +0 -9
- package/src/expression/expression.ts +0 -13
- package/src/numbers/rationals/division.ts +0 -0
- package/src/tree/nodes/operators/oppositeNode.ts +0 -17
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { FunctionNode, FunctionsIds } from "../nodes/functions/functionNode";
|
|
1
2
|
import { Node, NodeType } from "../nodes/node";
|
|
2
|
-
import { OperatorNode } from "../nodes/operators/operatorNode";
|
|
3
|
+
import { OperatorIds, OperatorNode } from "../nodes/operators/operatorNode";
|
|
3
4
|
|
|
4
|
-
export function latexParse(node: Node
|
|
5
|
+
export function latexParse(node: Node): string {
|
|
5
6
|
if (!node) {
|
|
6
7
|
console.log("parsing a null node ???");
|
|
7
8
|
return "";
|
|
@@ -12,67 +13,112 @@ export function latexParse(node: Node | null): string {
|
|
|
12
13
|
case NodeType.number:
|
|
13
14
|
return node.tex;
|
|
14
15
|
case NodeType.operator:
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const operatorNode = node as OperatorNode;
|
|
17
|
+
let rightTex = latexParse(operatorNode.rightChild);
|
|
18
|
+
let leftTex = latexParse(operatorNode.leftChild);
|
|
19
|
+
const { leftChild, rightChild } = operatorNode;
|
|
20
|
+
switch (operatorNode.id) {
|
|
21
|
+
case OperatorIds.add:
|
|
20
22
|
return `${leftTex} ${rightTex[0] === "-" ? "" : "+ "}${rightTex}`;
|
|
21
23
|
|
|
22
|
-
case
|
|
24
|
+
case OperatorIds.substract: {
|
|
23
25
|
const needBrackets =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
leftTex[0] === "-";
|
|
27
|
-
if (needBrackets) leftTex = `(${leftTex})`;
|
|
28
|
-
return `-${leftTex}`;
|
|
29
|
-
|
|
30
|
-
case "substract": {
|
|
31
|
-
const needBrackets =
|
|
32
|
-
rightChild!.id === "add" ||
|
|
33
|
-
rightChild!.id === "substract" ||
|
|
26
|
+
(rightChild.type === NodeType.operator &&
|
|
27
|
+
[OperatorIds.add, OperatorIds.substract].includes((rightChild as OperatorNode).id)) ||
|
|
34
28
|
rightTex[0] === "-";
|
|
29
|
+
|
|
35
30
|
if (needBrackets) rightTex = `(${rightTex})`;
|
|
31
|
+
|
|
36
32
|
return `${leftTex} - ${rightTex}`;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
case
|
|
40
|
-
if (leftChild
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
case OperatorIds.multiply: {
|
|
36
|
+
if (leftChild.type === NodeType.operator) {
|
|
37
|
+
if ([OperatorIds.add, OperatorIds.substract, OperatorIds.divide].includes((leftChild as OperatorNode).id))
|
|
38
|
+
leftTex = `(${leftTex})`;
|
|
39
|
+
}
|
|
40
|
+
let needBrackets = rightTex[0] === "-";
|
|
41
|
+
if (rightChild.type === NodeType.operator) {
|
|
42
|
+
const operatorRightChild = rightChild as OperatorNode;
|
|
43
|
+
needBrackets ||= [OperatorIds.add, OperatorIds.substract].includes(operatorRightChild.id);
|
|
44
|
+
}
|
|
46
45
|
if (needBrackets) rightTex = `(${rightTex})`;
|
|
47
|
-
|
|
46
|
+
|
|
47
|
+
// permet de gérer le cas 3*2^x
|
|
48
|
+
let showTimesSign = !isNaN(+rightTex[0]) || rightChild.type === NodeType.number;
|
|
49
|
+
if (rightChild.type === NodeType.operator) {
|
|
50
|
+
const operatorRightChild = rightChild as OperatorNode;
|
|
51
|
+
showTimesSign ||= [OperatorIds.fraction].includes(operatorRightChild.id);
|
|
52
|
+
}
|
|
48
53
|
return `${leftTex}${showTimesSign ? "\\times " : ""}${rightTex}`;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
case
|
|
56
|
+
case OperatorIds.divide: {
|
|
57
|
+
if (leftChild.type === NodeType.operator) {
|
|
58
|
+
if ([OperatorIds.add, OperatorIds.substract, OperatorIds.multiply].includes((leftChild as OperatorNode).id))
|
|
59
|
+
leftTex = `(${leftTex})`;
|
|
60
|
+
}
|
|
61
|
+
let needBrackets = rightTex[0] === "-";
|
|
62
|
+
if (rightChild.type === NodeType.operator) {
|
|
63
|
+
const operatorRightChild = rightChild as OperatorNode;
|
|
64
|
+
needBrackets ||= [OperatorIds.add, OperatorIds.substract].includes(operatorRightChild.id);
|
|
65
|
+
}
|
|
66
|
+
if (needBrackets) rightTex = `(${rightTex})`;
|
|
67
|
+
|
|
68
|
+
// permet de gérer le cas 3*2^x
|
|
69
|
+
let showTimesSign = !isNaN(+rightTex[0]);
|
|
70
|
+
if (rightChild.type === NodeType.operator) {
|
|
71
|
+
const operatorRightChild = rightChild as OperatorNode;
|
|
72
|
+
showTimesSign ||= [OperatorIds.fraction].includes(operatorRightChild.id);
|
|
73
|
+
}
|
|
74
|
+
return `${leftTex}${showTimesSign ? "\\div " : ""}${rightTex}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
case OperatorIds.fraction: {
|
|
52
78
|
return `\\frac{${leftTex}}{${rightTex}}`;
|
|
53
79
|
}
|
|
54
80
|
|
|
55
|
-
case
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
leftChild
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
case OperatorIds.power: {
|
|
82
|
+
let needBrackets = leftTex[0] === "-";
|
|
83
|
+
if (leftChild.type === NodeType.operator) {
|
|
84
|
+
const childOperator = leftChild as OperatorNode;
|
|
85
|
+
needBrackets ||= [
|
|
86
|
+
OperatorIds.add,
|
|
87
|
+
OperatorIds.substract,
|
|
88
|
+
OperatorIds.multiply,
|
|
89
|
+
OperatorIds.divide,
|
|
90
|
+
OperatorIds.fraction,
|
|
91
|
+
OperatorIds.power,
|
|
92
|
+
].includes(childOperator.id);
|
|
93
|
+
}
|
|
94
|
+
if (needBrackets) leftTex = `(${leftTex})`;
|
|
62
95
|
return `${leftTex}^{${rightTex}}`;
|
|
63
96
|
}
|
|
64
97
|
|
|
65
|
-
case
|
|
98
|
+
case OperatorIds.equal: {
|
|
66
99
|
return `${leftTex} = ${rightTex}`;
|
|
67
100
|
}
|
|
68
101
|
default:
|
|
69
102
|
return node.tex;
|
|
70
103
|
}
|
|
104
|
+
|
|
71
105
|
case NodeType.function: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
const functionNode = node as FunctionNode;
|
|
107
|
+
const child = functionNode.child;
|
|
108
|
+
let childTex = latexParse(functionNode.child);
|
|
109
|
+
switch (functionNode.id) {
|
|
110
|
+
case FunctionsIds.sqrt: {
|
|
111
|
+
return `\\sqrt{${childTex}}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
case FunctionsIds.opposite: {
|
|
115
|
+
let needBrackets = childTex[0] === "-";
|
|
116
|
+
if (child.type === NodeType.operator) {
|
|
117
|
+
const operatorChild = child as OperatorNode;
|
|
118
|
+
needBrackets ||= [OperatorIds.add, OperatorIds.substract].includes(operatorChild.id);
|
|
119
|
+
}
|
|
120
|
+
if (needBrackets) childTex = `(${childTex})`;
|
|
121
|
+
return `-${childTex}`;
|
|
76
122
|
}
|
|
77
123
|
}
|
|
78
124
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.FunctionNode = exports.FunctionsIds = void 0;
|
|
4
|
+
var node_1 = require("../node");
|
|
5
|
+
var FunctionsIds;
|
|
6
|
+
(function (FunctionsIds) {
|
|
7
|
+
FunctionsIds[FunctionsIds["opposite"] = 0] = "opposite";
|
|
8
|
+
FunctionsIds[FunctionsIds["sqrt"] = 1] = "sqrt";
|
|
9
|
+
})(FunctionsIds = exports.FunctionsIds || (exports.FunctionsIds = {}));
|
|
10
|
+
var FunctionNode = /** @class */ (function () {
|
|
11
|
+
function FunctionNode(id, child, tex) {
|
|
12
|
+
this.type = node_1.NodeType["function"];
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.child = child;
|
|
15
|
+
this.tex = tex;
|
|
16
|
+
}
|
|
17
|
+
return FunctionNode;
|
|
18
|
+
}());
|
|
19
|
+
exports.FunctionNode = FunctionNode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Node, NodeType } from "../node";
|
|
2
|
+
|
|
3
|
+
export enum FunctionsIds {
|
|
4
|
+
opposite,
|
|
5
|
+
sqrt,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export abstract class FunctionNode implements Node {
|
|
9
|
+
id: FunctionsIds;
|
|
10
|
+
child: Node;
|
|
11
|
+
type = NodeType.function;
|
|
12
|
+
tex: string;
|
|
13
|
+
constructor(id: FunctionsIds, child: Node, tex: string) {
|
|
14
|
+
this.id = id;
|
|
15
|
+
this.child = child;
|
|
16
|
+
this.tex = tex;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.OppositeNode = void 0;
|
|
19
|
+
var functionNode_1 = require("./functionNode");
|
|
20
|
+
var OppositeNode = /** @class */ (function (_super) {
|
|
21
|
+
__extends(OppositeNode, _super);
|
|
22
|
+
function OppositeNode(child) {
|
|
23
|
+
return _super.call(this, functionNode_1.FunctionsIds.opposite, child, "-") || this;
|
|
24
|
+
}
|
|
25
|
+
OppositeNode.prototype.toString = function () {
|
|
26
|
+
return "-(".concat(this.child, ")");
|
|
27
|
+
};
|
|
28
|
+
return OppositeNode;
|
|
29
|
+
}(functionNode_1.FunctionNode));
|
|
30
|
+
exports.OppositeNode = OppositeNode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Node, NodeType } from "../node";
|
|
2
|
+
import { OperatorNode } from "../operators/operatorNode";
|
|
3
|
+
import { FunctionNode, FunctionsIds } from "./functionNode";
|
|
4
|
+
|
|
5
|
+
export class OppositeNode extends FunctionNode {
|
|
6
|
+
constructor(child: Node) {
|
|
7
|
+
super(FunctionsIds.opposite, child, "-");
|
|
8
|
+
}
|
|
9
|
+
toString(): string {
|
|
10
|
+
return `-(${this.child})`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
exports.__esModule = true;
|
|
3
18
|
exports.SqrtNode = void 0;
|
|
4
19
|
var node_1 = require("../node");
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
var functionNode_1 = require("./functionNode");
|
|
21
|
+
var SqrtNode = /** @class */ (function (_super) {
|
|
22
|
+
__extends(SqrtNode, _super);
|
|
23
|
+
function SqrtNode(child) {
|
|
24
|
+
var _this = _super.call(this, functionNode_1.FunctionsIds.sqrt, child, "\\sqrt") || this;
|
|
25
|
+
_this.type = node_1.NodeType["function"];
|
|
26
|
+
return _this;
|
|
12
27
|
}
|
|
13
28
|
SqrtNode.prototype.toString = function () {
|
|
14
|
-
return "sqrt(".concat(this.
|
|
29
|
+
return "sqrt(".concat(this.child, ")");
|
|
15
30
|
};
|
|
16
31
|
return SqrtNode;
|
|
17
|
-
}());
|
|
32
|
+
}(functionNode_1.FunctionNode));
|
|
18
33
|
exports.SqrtNode = SqrtNode;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { Node, NodeType } from "../node";
|
|
2
|
+
import { FunctionNode, FunctionsIds } from "./functionNode";
|
|
2
3
|
|
|
3
|
-
export class SqrtNode
|
|
4
|
-
leftChild: Node;
|
|
5
|
-
rightChild: null;
|
|
4
|
+
export class SqrtNode extends FunctionNode {
|
|
6
5
|
type: NodeType = NodeType.function;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(leftChild: Node) {
|
|
10
|
-
this.leftChild = leftChild;
|
|
11
|
-
this.rightChild = null;
|
|
6
|
+
constructor(child: Node) {
|
|
7
|
+
super(FunctionsIds.sqrt, child, "\\sqrt");
|
|
12
8
|
}
|
|
13
9
|
toString(): string {
|
|
14
|
-
return `sqrt(${this.
|
|
10
|
+
return `sqrt(${this.child})`;
|
|
15
11
|
}
|
|
16
12
|
}
|
package/src/tree/nodes/node.ts
CHANGED
|
@@ -3,13 +3,10 @@ exports.__esModule = true;
|
|
|
3
3
|
exports.NumberNode = void 0;
|
|
4
4
|
var node_1 = require("../node");
|
|
5
5
|
var NumberNode = /** @class */ (function () {
|
|
6
|
-
function NumberNode(value) {
|
|
7
|
-
this.id = "number";
|
|
8
|
-
this.leftChild = null;
|
|
9
|
-
this.rightChild = null;
|
|
10
|
-
this.value = value;
|
|
11
|
-
this.tex = value + "";
|
|
6
|
+
function NumberNode(value, tex) {
|
|
12
7
|
this.type = node_1.NodeType.number;
|
|
8
|
+
this.value = value;
|
|
9
|
+
this.tex = tex || value + "";
|
|
13
10
|
}
|
|
14
11
|
NumberNode.prototype.toString = function () {
|
|
15
12
|
return "".concat(this.tex);
|
|
@@ -3,14 +3,11 @@ import { Node, NodeType } from "../node";
|
|
|
3
3
|
export class NumberNode implements Node {
|
|
4
4
|
tex: string;
|
|
5
5
|
value: number;
|
|
6
|
-
type: NodeType;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
rightChild = null;
|
|
10
|
-
constructor(value: number) {
|
|
6
|
+
type: NodeType = NodeType.number;
|
|
7
|
+
|
|
8
|
+
constructor(value: number, tex?: string) {
|
|
11
9
|
this.value = value;
|
|
12
|
-
this.tex = value + "";
|
|
13
|
-
this.type = NodeType.number;
|
|
10
|
+
this.tex = tex || value + "";
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
toString(): string {
|
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
exports.__esModule = true;
|
|
3
18
|
exports.AddNode = void 0;
|
|
4
|
-
var
|
|
5
|
-
var AddNode = /** @class */ (function () {
|
|
19
|
+
var operatorNode_1 = require("./operatorNode");
|
|
20
|
+
var AddNode = /** @class */ (function (_super) {
|
|
21
|
+
__extends(AddNode, _super);
|
|
6
22
|
function AddNode(leftChild, rightChild) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.rightChild = rightChild;
|
|
23
|
+
var _this = _super.call(this, operatorNode_1.OperatorIds.add, leftChild, rightChild, true, "+") || this;
|
|
24
|
+
_this.leftChild = leftChild;
|
|
25
|
+
_this.rightChild = rightChild;
|
|
26
|
+
return _this;
|
|
12
27
|
}
|
|
13
28
|
AddNode.prototype.toString = function () {
|
|
14
29
|
return "".concat(this.leftChild, " + ").concat(this.rightChild);
|
|
15
30
|
};
|
|
16
31
|
return AddNode;
|
|
17
|
-
}());
|
|
32
|
+
}(operatorNode_1.OperatorNode));
|
|
18
33
|
exports.AddNode = AddNode;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { Node, NodeType } from "../node";
|
|
2
|
-
import { OperatorNode } from "./operatorNode";
|
|
2
|
+
import { OperatorIds, OperatorNode } from "./operatorNode";
|
|
3
3
|
|
|
4
|
-
export class AddNode
|
|
5
|
-
leftChild: Node;
|
|
6
|
-
rightChild: Node;
|
|
7
|
-
type: NodeType = NodeType.operator;
|
|
8
|
-
id: string = "add";
|
|
9
|
-
tex = "+";
|
|
4
|
+
export class AddNode extends OperatorNode {
|
|
10
5
|
constructor(leftChild: Node, rightChild: Node) {
|
|
6
|
+
super(OperatorIds.add, leftChild, rightChild, true, "+");
|
|
11
7
|
this.leftChild = leftChild;
|
|
12
8
|
this.rightChild = rightChild;
|
|
13
9
|
}
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
exports.__esModule = true;
|
|
3
18
|
exports.DivideNode = void 0;
|
|
4
|
-
var
|
|
5
|
-
var DivideNode = /** @class */ (function () {
|
|
19
|
+
var operatorNode_1 = require("./operatorNode");
|
|
20
|
+
var DivideNode = /** @class */ (function (_super) {
|
|
21
|
+
__extends(DivideNode, _super);
|
|
6
22
|
/**
|
|
7
23
|
* @param leftChild num
|
|
8
24
|
* @param rightChild denum
|
|
9
25
|
*/
|
|
10
26
|
function DivideNode(leftChild, rightChild) {
|
|
11
|
-
this.
|
|
12
|
-
this.id = "divide";
|
|
13
|
-
this.tex = "\\frac";
|
|
14
|
-
this.leftChild = leftChild;
|
|
15
|
-
this.rightChild = rightChild;
|
|
27
|
+
return _super.call(this, operatorNode_1.OperatorIds.divide, leftChild, rightChild, false, "\\div") || this;
|
|
16
28
|
}
|
|
17
29
|
DivideNode.prototype.toString = function () {
|
|
18
|
-
return "
|
|
30
|
+
return "(".concat(this.leftChild, ") \\div (").concat(this.rightChild, ")");
|
|
19
31
|
};
|
|
20
32
|
return DivideNode;
|
|
21
|
-
}());
|
|
33
|
+
}(operatorNode_1.OperatorNode));
|
|
22
34
|
exports.DivideNode = DivideNode;
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { Node, NodeType } from "../node";
|
|
2
|
-
import { OperatorNode } from "./operatorNode";
|
|
3
|
-
|
|
4
|
-
export class DivideNode implements Node, OperatorNode {
|
|
5
|
-
leftChild: Node;
|
|
6
|
-
rightChild: Node;
|
|
7
|
-
type: NodeType = NodeType.operator;
|
|
8
|
-
id: string = "divide";
|
|
9
|
-
tex = "\\frac";
|
|
2
|
+
import { OperatorIds, OperatorNode } from "./operatorNode";
|
|
10
3
|
|
|
4
|
+
export class DivideNode extends OperatorNode {
|
|
11
5
|
/**
|
|
12
6
|
* @param leftChild num
|
|
13
7
|
* @param rightChild denum
|
|
14
8
|
*/
|
|
15
9
|
constructor(leftChild: Node, rightChild: Node) {
|
|
16
|
-
|
|
17
|
-
this.rightChild = rightChild;
|
|
10
|
+
super(OperatorIds.divide, leftChild, rightChild, false, "\\div");
|
|
18
11
|
}
|
|
19
12
|
|
|
20
13
|
toString(): string {
|
|
21
|
-
return
|
|
14
|
+
return `(${this.leftChild}) \\div (${this.rightChild})`;
|
|
22
15
|
}
|
|
23
16
|
}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
exports.__esModule = true;
|
|
3
18
|
exports.EqualNode = void 0;
|
|
4
|
-
var
|
|
5
|
-
var EqualNode = /** @class */ (function () {
|
|
19
|
+
var operatorNode_1 = require("./operatorNode");
|
|
20
|
+
var EqualNode = /** @class */ (function (_super) {
|
|
21
|
+
__extends(EqualNode, _super);
|
|
6
22
|
function EqualNode(leftChild, rightChild) {
|
|
7
|
-
this.
|
|
8
|
-
this.id = "equal";
|
|
9
|
-
this.tex = "=";
|
|
10
|
-
this.leftChild = leftChild;
|
|
11
|
-
this.rightChild = rightChild;
|
|
23
|
+
return _super.call(this, operatorNode_1.OperatorIds.equal, leftChild, rightChild, true, "=") || this;
|
|
12
24
|
}
|
|
13
25
|
EqualNode.prototype.toString = function () {
|
|
14
26
|
return "".concat(this.leftChild, " = ").concat(this.rightChild);
|
|
15
27
|
};
|
|
16
28
|
return EqualNode;
|
|
17
|
-
}());
|
|
29
|
+
}(operatorNode_1.OperatorNode));
|
|
18
30
|
exports.EqualNode = EqualNode;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { Node, NodeType } from "../node";
|
|
2
|
-
import { OperatorNode } from "./operatorNode";
|
|
2
|
+
import { OperatorIds, OperatorNode } from "./operatorNode";
|
|
3
3
|
|
|
4
|
-
export class EqualNode
|
|
5
|
-
leftChild: Node;
|
|
6
|
-
rightChild: Node;
|
|
7
|
-
type: NodeType = NodeType.operator;
|
|
8
|
-
id: string = "equal";
|
|
9
|
-
tex = "=";
|
|
4
|
+
export class EqualNode extends OperatorNode {
|
|
10
5
|
constructor(leftChild: Node, rightChild: Node) {
|
|
11
|
-
|
|
12
|
-
this.rightChild = rightChild;
|
|
6
|
+
super(OperatorIds.equal, leftChild, rightChild, true, "=");
|
|
13
7
|
}
|
|
14
8
|
toString(): string {
|
|
15
9
|
return `${this.leftChild} = ${this.rightChild}`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.FractionNode = void 0;
|
|
19
|
+
var operatorNode_1 = require("./operatorNode");
|
|
20
|
+
var FractionNode = /** @class */ (function (_super) {
|
|
21
|
+
__extends(FractionNode, _super);
|
|
22
|
+
/**
|
|
23
|
+
* @param leftChild num
|
|
24
|
+
* @param rightChild denum
|
|
25
|
+
*/
|
|
26
|
+
function FractionNode(leftChild, rightChild) {
|
|
27
|
+
return _super.call(this, operatorNode_1.OperatorIds.fraction, leftChild, rightChild, false, "\\frac") || this;
|
|
28
|
+
}
|
|
29
|
+
FractionNode.prototype.toString = function () {
|
|
30
|
+
return "\\frac{".concat(this.leftChild, "}{").concat(this.rightChild, "}");
|
|
31
|
+
};
|
|
32
|
+
return FractionNode;
|
|
33
|
+
}(operatorNode_1.OperatorNode));
|
|
34
|
+
exports.FractionNode = FractionNode;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Node, NodeType } from "../node";
|
|
2
|
+
import { OperatorIds, OperatorNode } from "./operatorNode";
|
|
3
|
+
|
|
4
|
+
export class FractionNode extends OperatorNode {
|
|
5
|
+
/**
|
|
6
|
+
* @param leftChild num
|
|
7
|
+
* @param rightChild denum
|
|
8
|
+
*/
|
|
9
|
+
constructor(leftChild: Node, rightChild: Node) {
|
|
10
|
+
super(OperatorIds.fraction, leftChild, rightChild, false, "\\frac");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
toString(): string {
|
|
14
|
+
return `\\frac{${this.leftChild}}{${this.rightChild}}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
exports.__esModule = true;
|
|
3
18
|
exports.MultiplyNode = void 0;
|
|
4
|
-
var
|
|
5
|
-
var MultiplyNode = /** @class */ (function () {
|
|
19
|
+
var operatorNode_1 = require("./operatorNode");
|
|
20
|
+
var MultiplyNode = /** @class */ (function (_super) {
|
|
21
|
+
__extends(MultiplyNode, _super);
|
|
6
22
|
function MultiplyNode(leftChild, rightChild) {
|
|
7
|
-
this.
|
|
8
|
-
this.id = "multiply";
|
|
9
|
-
this.tex = "\\times";
|
|
10
|
-
this.leftChild = leftChild;
|
|
11
|
-
this.rightChild = rightChild;
|
|
23
|
+
return _super.call(this, operatorNode_1.OperatorIds.multiply, leftChild, rightChild, true, "\\times") || this;
|
|
12
24
|
}
|
|
13
25
|
MultiplyNode.prototype.toString = function () {
|
|
14
26
|
return "(".concat(this.leftChild, ")*(").concat(this.rightChild, ")");
|
|
15
27
|
};
|
|
16
28
|
return MultiplyNode;
|
|
17
|
-
}());
|
|
29
|
+
}(operatorNode_1.OperatorNode));
|
|
18
30
|
exports.MultiplyNode = MultiplyNode;
|