math-exercises 3.0.183 → 3.0.185
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/lib/exercises/math/functions/composition/functionComposition.d.ts.map +1 -1
- package/lib/exercises/math/functions/composition/functionComposition.js +11 -22
- package/lib/exercises/math/functions/exponential/algebraic/approxExpAPlusB.d.ts.map +1 -1
- package/lib/exercises/math/functions/exponential/algebraic/approxExpAPlusB.js +91 -38
- package/lib/exercises/math/functions/exponential/algebraic/rewriteExpUsingExpA.d.ts.map +1 -1
- package/lib/exercises/math/functions/exponential/algebraic/rewriteExpUsingExpA.js +18 -3
- package/lib/exercises/math/functions/exponential/expKT/derivativeOfAExpKT.d.ts +8 -0
- package/lib/exercises/math/functions/exponential/expKT/derivativeOfAExpKT.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/expKT/derivativeOfAExpKT.js +108 -0
- package/lib/exercises/math/functions/exponential/expKT/drugConcentrationMaximum.d.ts +8 -0
- package/lib/exercises/math/functions/exponential/expKT/drugConcentrationMaximum.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/expKT/drugConcentrationMaximum.js +144 -0
- package/lib/exercises/math/functions/exponential/expKT/index.d.ts +3 -0
- package/lib/exercises/math/functions/exponential/expKT/index.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/expKT/index.js +2 -0
- package/lib/exercises/math/functions/exponential/expSimplifiying.d.ts.map +1 -1
- package/lib/exercises/math/functions/exponential/expSimplifiying.js +94 -4
- package/lib/exercises/math/functions/exponential/index.d.ts +3 -0
- package/lib/exercises/math/functions/exponential/index.d.ts.map +1 -1
- package/lib/exercises/math/functions/exponential/index.js +3 -0
- package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.d.ts +9 -0
- package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.js +101 -0
- package/lib/exercises/math/functions/exponential/sign/index.d.ts +2 -0
- package/lib/exercises/math/functions/exponential/sign/index.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/sign/index.js +1 -0
- package/lib/exercises/math/functions/exponential/variations/index.d.ts +3 -0
- package/lib/exercises/math/functions/exponential/variations/index.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/variations/index.js +2 -0
- package/lib/exercises/math/functions/exponential/variations/varSignTableOfAffineTimesExp.d.ts +7 -0
- package/lib/exercises/math/functions/exponential/variations/varSignTableOfAffineTimesExp.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/variations/varSignTableOfAffineTimesExp.js +144 -0
- package/lib/exercises/math/functions/exponential/variations/varSignTableOfExpMinusX.d.ts +7 -0
- package/lib/exercises/math/functions/exponential/variations/varSignTableOfExpMinusX.d.ts.map +1 -0
- package/lib/exercises/math/functions/exponential/variations/varSignTableOfExpMinusX.js +139 -0
- package/lib/exercises/math/probaStat/independancy/independantSuccessiveEventsComputeTwoSuccess.d.ts +7 -0
- package/lib/exercises/math/probaStat/independancy/independantSuccessiveEventsComputeTwoSuccess.d.ts.map +1 -0
- package/lib/exercises/math/probaStat/independancy/independantSuccessiveEventsComputeTwoSuccess.js +100 -0
- package/lib/exercises/math/probaStat/independancy/index.d.ts +1 -0
- package/lib/exercises/math/probaStat/independancy/index.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/independancy/index.js +1 -0
- package/lib/exercises/math/probaStat/trees/index.d.ts +4 -1
- package/lib/exercises/math/probaStat/trees/index.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/trees/index.js +4 -11
- package/lib/exercises/math/probaStat/trees/probabilityTree.d.ts +9 -3
- package/lib/exercises/math/probaStat/trees/probabilityTree.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/trees/probabilityTree.js +419 -45
- package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindRankFromSituation.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindRankFromSituation.js +3 -3
- package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindThresholdFromSituation.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/situations/arithmeticFindThresholdFromSituation.js +2 -2
- package/lib/exercises/math/sequences/arithmetic/situations/index.d.ts +2 -0
- package/lib/exercises/math/sequences/arithmetic/situations/index.d.ts.map +1 -1
- package/lib/exercises/math/sequences/arithmetic/situations/index.js +2 -2
- package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoConsecutiveTerms.d.ts.map +1 -1
- package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoConsecutiveTerms.js +37 -39
- package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoTerms.d.ts.map +1 -1
- package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoTerms.js +14 -4
- package/lib/exercises/math/sequences/geometric/situations/geometricFindExplicitFormulaFromSituation.d.ts.map +1 -1
- package/lib/exercises/math/sequences/geometric/situations/geometricFindExplicitFormulaFromSituation.js +12 -3
- package/lib/exercises/vea/treeTableVEA.d.ts.map +1 -1
- package/lib/exercises/vea/treeTableVEA.js +3 -0
- package/lib/index.d.ts +46 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/latexTester.js +1 -1
- package/lib/math/utils/sequences/situations/seqArithmeticSituations.d.ts +2 -0
- package/lib/math/utils/sequences/situations/seqArithmeticSituations.d.ts.map +1 -1
- package/lib/math/utils/sequences/situations/seqArithmeticSituations.js +150 -128
- package/lib/math/utils/sequences/situations/seqArithmeticUtils.d.ts +1 -1
- package/lib/math/utils/sequences/situations/seqArithmeticUtils.d.ts.map +1 -1
- package/lib/math/utils/sequences/situations/seqArithmeticUtils.js +4 -1
- package/lib/tests/questionTest.d.ts.map +1 -1
- package/lib/tests/questionTest.js +1 -0
- package/lib/tests/singleExo.test.js +2 -2
- package/lib/tree/nodes/functions/expNode.d.ts +1 -1
- package/lib/tree/nodes/functions/expNode.d.ts.map +1 -1
- package/lib/tree/nodes/functions/expNode.js +3 -6
- package/lib/tree/nodes/operators/addNode.d.ts +1 -1
- package/lib/tree/nodes/operators/addNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/addNode.js +2 -2
- package/lib/tree/nodes/operators/substractNode.d.ts +1 -1
- package/lib/tree/nodes/operators/substractNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/substractNode.js +2 -2
- package/lib/tree/utilities/nodeComparator.d.ts +7 -0
- package/lib/tree/utilities/nodeComparator.d.ts.map +1 -0
- package/lib/tree/utilities/nodeComparator.js +88 -0
- package/lib/tree/utilities/nodeInspector.d.ts +5 -0
- package/lib/tree/utilities/nodeInspector.d.ts.map +1 -0
- package/lib/tree/utilities/nodeInspector.js +15 -0
- package/lib/tree/utilities/nodeRewriter.d.ts +9 -0
- package/lib/tree/utilities/nodeRewriter.d.ts.map +1 -0
- package/lib/tree/utilities/nodeRewriter.js +172 -0
- package/lib/tree/utilities/nodeShuffler.d.ts +2 -4
- package/lib/tree/utilities/nodeShuffler.d.ts.map +1 -1
- package/lib/tree/utilities/nodeShuffler.js +13 -104
- package/lib/tree/utilities/nodeSimplifier.d.ts +1 -2
- package/lib/tree/utilities/nodeSimplifier.d.ts.map +1 -1
- package/lib/tree/utilities/nodeSimplifier.js +14 -88
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ export declare const seqArithmeticUtils: {
|
|
|
6
6
|
getAnswerNodeExplicitFormula: (initial: number, reason: number, firstRank: number) => EqualNode;
|
|
7
7
|
getAnswerNodeRecurrenceFormula: (_initial: number, reason: number, _firstRank: number) => EqualNode;
|
|
8
8
|
getAnswerNodeRandomTerm: (initial: number, reason: number, firstRank: number, rankAsked: number) => import("../../../../tree/nodes/operators/addNode.js").AddNode;
|
|
9
|
-
getAnswerNodeRandomRank: (initial: number, reason: number, _firstRank: number, valueAsked: number) => import("../../../../tree/nodes/
|
|
9
|
+
getAnswerNodeRandomRank: (initial: number, reason: number, _firstRank: number, valueAsked: number) => import("../../../../tree/nodes/numbers/constantNode.js").ConstantNode | import("../../../../tree/nodes/numbers/numberNode.js").NumberNode;
|
|
10
10
|
getAnswerNodeThresholdRank: (initial: number, reason: number, firstRank: number, valueThreshold: number, inequationSymbol: InequationSymbol) => import("../../../../tree/nodes/numbers/constantNode.js").ConstantNode | import("../../../../tree/nodes/numbers/numberNode.js").NumberNode;
|
|
11
11
|
getAnswerNodeSumThresholdRank: (initial: number, reason: number, firstRank: number, valueThreshold: number, inequationSymbol: InequationSymbol) => import("../../../../tree/nodes/numbers/constantNode.js").ConstantNode | import("../../../../tree/nodes/numbers/numberNode.js").NumberNode;
|
|
12
12
|
randThreshold: (initial: number, reason: number, firstRank: number, roundTo: number) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seqArithmeticUtils.d.ts","sourceRoot":"","sources":["../../../../../src/math/utils/sequences/situations/seqArithmeticUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"seqArithmeticUtils.d.ts","sourceRoot":"","sources":["../../../../../src/math/utils/sequences/situations/seqArithmeticUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAiNpE,eAAO,MAAM,kBAAkB;4BAvMA,MAAM,UAAU,MAAM,QAAQ,MAAM;+BAIjC,MAAM,UAAU,MAAM,QAAQ,MAAM;4CAK3D,MAAM,UACP,MAAM,aACH,MAAM;+CAaP,MAAM,UACR,MAAM,cACF,MAAM;uCAWT,MAAM,UACP,MAAM,aACH,MAAM,aACN,MAAM;uCAUR,MAAM,UACP,MAAM,cACF,MAAM,cACN,MAAM;0CAUT,MAAM,UACP,MAAM,aACH,MAAM,kBACD,MAAM,oBACJ,gBAAgB;6CAwBzB,MAAM,UACP,MAAM,aACH,MAAM,kBACD,MAAM,oBACJ,gBAAgB;6BAmEzB,MAAM,UACP,MAAM,aACH,MAAM,WACR,MAAM;gCAgBN,MAAM,UACP,MAAM,aACH,MAAM,WACR,MAAM;CA0BhB,CAAC"}
|
|
@@ -7,6 +7,7 @@ import { substract } from "../../../../tree/nodes/operators/substractNode.js";
|
|
|
7
7
|
import { probaFlip } from "../../../../utils/alea/probaFlip.js";
|
|
8
8
|
import { random, randomMany } from "../../../../utils/alea/random.js";
|
|
9
9
|
import { randfloat } from "../../random/randfloat.js";
|
|
10
|
+
import { round } from "../../round.js";
|
|
10
11
|
const valueForRank = (initial, reason, rank) => {
|
|
11
12
|
return initial + reason * rank;
|
|
12
13
|
};
|
|
@@ -33,7 +34,9 @@ const getAnswerNodeRandomTerm = (initial, reason, firstRank, rankAsked) => {
|
|
|
33
34
|
const getAnswerNodeRandomRank = (initial, reason, _firstRank, valueAsked) => {
|
|
34
35
|
//u_n = u_0 + r * n
|
|
35
36
|
//n = (u_n - u_0) / r
|
|
36
|
-
|
|
37
|
+
const nodeRaw = frac(substract(valueAsked, initial), reason);
|
|
38
|
+
const valueRounded = round(nodeRaw.evaluate(), 0);
|
|
39
|
+
return valueRounded.toTree();
|
|
37
40
|
};
|
|
38
41
|
const getAnswerNodeThresholdRank = (initial, reason, firstRank, valueThreshold, inequationSymbol) => {
|
|
39
42
|
//u_n = u_0 + r * n >= t
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"questionTest.d.ts","sourceRoot":"","sources":["../../src/tests/questionTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAKjE,eAAO,MAAM,YAAY,GACvB,KAAK,QAAQ,CAAC,MAAM,CAAC,EACrB,UAAU,QAAQ,CAAC,MAAM,CAAC;;;
|
|
1
|
+
{"version":3,"file":"questionTest.d.ts","sourceRoot":"","sources":["../../src/tests/questionTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAKjE,eAAO,MAAM,YAAY,GACvB,KAAK,QAAQ,CAAC,MAAM,CAAC,EACrB,UAAU,QAAQ,CAAC,MAAM,CAAC;;;CAwS3B,CAAC"}
|
|
@@ -36,6 +36,7 @@ export const questionTest = (exo, question) => {
|
|
|
36
36
|
assertJsonStringifiable(question.identifiers);
|
|
37
37
|
}
|
|
38
38
|
catch (err) {
|
|
39
|
+
console.log("question.identifiers", question.identifiers);
|
|
39
40
|
throw new Error(`exo ${exo.id} : ${err}`);
|
|
40
41
|
}
|
|
41
42
|
const dotDecimalPattern = /\d+\.\d+/;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../prototypesEnhancement.js";
|
|
2
2
|
import { exoTest } from "./exoTest.js";
|
|
3
|
-
import {
|
|
3
|
+
import { geometricFindExplicitFormulaFromSituation, } from "../exercises/math/index.js";
|
|
4
4
|
try {
|
|
5
5
|
for (let i = 0; i < 1000; i++)
|
|
6
|
-
exoTest(
|
|
6
|
+
exoTest(geometricFindExplicitFormulaFromSituation);
|
|
7
7
|
}
|
|
8
8
|
catch (err) {
|
|
9
9
|
throw err;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Node, NodeIds, NodeOptions, NodeType } from "../node.js";
|
|
2
2
|
import { FunctionNode, FunctionsIds } from "./functionNode.js";
|
|
3
3
|
import { AlgebraicNode, SimplifyOptions } from "../algebraicNode.js";
|
|
4
|
-
export declare const exp: (a: AlgebraicNode | number | string) => ExpNode;
|
|
4
|
+
export declare const exp: (a: AlgebraicNode | number | string, opts?: NodeOptions) => ExpNode;
|
|
5
5
|
export declare function isExpNode(a: Node): a is ExpNode;
|
|
6
6
|
export declare class ExpNode implements FunctionNode {
|
|
7
7
|
opts?: NodeOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/n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AI,CAAC,EAAE,eAAe,EAAE,IAAI,UAAQ,GAAG,aAAa;IAO7D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAGtC,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAGpC,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IAGxD,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa;CAGxD"}
|
|
@@ -4,9 +4,9 @@ import { FunctionsIds, isFunctionNode } from "./functionNode.js";
|
|
|
4
4
|
import { isNumberNode } from "../numbers/numberNode.js";
|
|
5
5
|
import { isLogNode } from "./logNode.js";
|
|
6
6
|
import { multiply } from "../operators/multiplyNode.js";
|
|
7
|
-
export const exp = (a) => {
|
|
7
|
+
export const exp = (a, opts) => {
|
|
8
8
|
const nodeA = typeof a === "number" ? a.toTree() : typeof a === "string" ? a.toTree() : a;
|
|
9
|
-
return new ExpNode(nodeA);
|
|
9
|
+
return new ExpNode(nodeA, opts);
|
|
10
10
|
};
|
|
11
11
|
export function isExpNode(a) {
|
|
12
12
|
return isFunctionNode(a) && a.id === FunctionsIds.exp;
|
|
@@ -54,10 +54,7 @@ export class ExpNode {
|
|
|
54
54
|
if (this.opts?.useExpNotation) {
|
|
55
55
|
return `\\exp\\left(${tex}\\right)`;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
if (needBraces)
|
|
59
|
-
return `e^{${tex}}`;
|
|
60
|
-
return `e^${tex}`;
|
|
57
|
+
return `e^{${tex}}`;
|
|
61
58
|
}
|
|
62
59
|
// toMathjs() {
|
|
63
60
|
// return exp(this.child.toMathjs());
|
|
@@ -2,7 +2,7 @@ import { Node, NodeIds, NodeOptions, NodeType, ToTexOptions } from "../node.js";
|
|
|
2
2
|
import { CommutativeOperatorNode, OperatorIds } from "./operatorNode.js";
|
|
3
3
|
import { AlgebraicNode, SimplifyOptions } from "../algebraicNode.js";
|
|
4
4
|
export declare function isAddNode(a: Node): a is AddNode;
|
|
5
|
-
export declare const add: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string) => AddNode;
|
|
5
|
+
export declare const add: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string, opts?: NodeOptions) => AddNode;
|
|
6
6
|
export declare class AddNode implements CommutativeOperatorNode {
|
|
7
7
|
id: OperatorIds;
|
|
8
8
|
leftChild: AlgebraicNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/operators/addNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,uBAAuB,EACvB,WAAW,EAEZ,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAerE,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,OAAO,CAE/C;AAED,eAAO,MAAM,GAAG,GACd,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,EAClC,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"addNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/operators/addNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,uBAAuB,EACvB,WAAW,EAEZ,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAerE,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,OAAO,CAE/C;AAED,eAAO,MAAM,GAAG,GACd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orIds.add;
|
|
18
18
|
}
|
|
19
|
-
export const add = (a, b) => {
|
|
19
|
+
export const add = (a, b, opts) => {
|
|
20
20
|
const nodeA = typeof a === "number" ? a.toTree() : typeof a === "string" ? a.toTree() : a;
|
|
21
21
|
const nodeB = typeof b === "number" ? b.toTree() : typeof b === "string" ? b.toTree() : b;
|
|
22
|
-
return new AddNode(nodeA, nodeB);
|
|
22
|
+
return new AddNode(nodeA, nodeB, opts);
|
|
23
23
|
};
|
|
24
24
|
export class AddNode {
|
|
25
25
|
id;
|
|
@@ -3,7 +3,7 @@ import { OperatorIds, OperatorNode } from "./operatorNode.js";
|
|
|
3
3
|
import { AddNode } from "./addNode.js";
|
|
4
4
|
import { AlgebraicNode, SimplifyOptions } from "../algebraicNode.js";
|
|
5
5
|
export declare function isSubstractNode(a: Node): a is SubstractNode;
|
|
6
|
-
export declare const substract: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string) => SubstractNode;
|
|
6
|
+
export declare const substract: (a: AlgebraicNode | number | string, b: AlgebraicNode | number | string, opts?: NodeOptions) => SubstractNode;
|
|
7
7
|
export declare class SubstractNode implements OperatorNode {
|
|
8
8
|
id: OperatorIds;
|
|
9
9
|
leftChild: AlgebraicNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"substractNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/operators/substractNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkB,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAO,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAIrE,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,aAAa,CAE3D;AAED,e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K1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAStC,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe;IAM/B,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAOpC,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IAMxD,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa;IAMvD,OAAO,uBAGL;CACH"}
|
|
@@ -9,10 +9,10 @@ import { round } from "../../../math/utils/round.js";
|
|
|
9
9
|
export function isSubstractNode(a) {
|
|
10
10
|
return isOperatorNode(a) && a.id === OperatorIds.substract;
|
|
11
11
|
}
|
|
12
|
-
export const substract = (a, b) => {
|
|
12
|
+
export const substract = (a, b, opts) => {
|
|
13
13
|
const nodeA = typeof a === "number" ? a.toTree() : typeof a === "string" ? a.toTree() : a;
|
|
14
14
|
const nodeB = typeof b === "number" ? b.toTree() : typeof b === "string" ? b.toTree() : b;
|
|
15
|
-
return new SubstractNode(nodeA, nodeB);
|
|
15
|
+
return new SubstractNode(nodeA, nodeB, opts);
|
|
16
16
|
};
|
|
17
17
|
export class SubstractNode {
|
|
18
18
|
id;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AlgebraicNode } from "../nodes/algebraicNode.js";
|
|
2
|
+
export declare abstract class NodeComparator {
|
|
3
|
+
static compareViaSub: <T extends AlgebraicNode>(node1: T, node2: T) => -1 | 0 | 1;
|
|
4
|
+
static isEqualViaSub: (node1: AlgebraicNode, node2: AlgebraicNode) => boolean;
|
|
5
|
+
static isEqualViaFrac: (node1: AlgebraicNode, node2: AlgebraicNode) => boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=nodeComparator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeComparator.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeComparator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM1D,8BAAsB,cAAc;IAGlC,MAAM,CAAC,aAAa,GAAI,CAAC,SAAS,aAAa,EAC7C,OAAO,CAAC,EACR,OAAO,CAAC,KACP,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CA4DX;IAEF,MAAM,CAAC,aAAa,GAClB,OAAO,aAAa,EACpB,OAAO,aAAa,KACnB,OAAO,CAER;IAIF,MAAM,CAAC,cAAc,GACnB,OAAO,aAAa,EACpB,OAAO,aAAa,KACnB,OAAO,CAgBR;CACH"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { frac } from "../nodes/operators/fractionNode.js";
|
|
2
|
+
import { substract } from "../nodes/operators/substractNode.js";
|
|
3
|
+
import { NodeRewriter } from "./nodeRewriter.js";
|
|
4
|
+
import { NodeSimplifier } from "./nodeSimplifier.js";
|
|
5
|
+
export class NodeComparator {
|
|
6
|
+
//via sub
|
|
7
|
+
static compareViaSub = (node1, node2) => {
|
|
8
|
+
const isSameTex = () => {
|
|
9
|
+
return node1.toTex() === node2.toTex();
|
|
10
|
+
};
|
|
11
|
+
function compareValueSub(valueSub) {
|
|
12
|
+
if (isNaN(valueSub)) {
|
|
13
|
+
throw new Error("valueSub is NaN");
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (valueSub === 0) {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
else if (valueSub > 0) {
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return -1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const compareUsingEvaluate = () => {
|
|
28
|
+
const valueSub = substract(node1, node2).evaluate();
|
|
29
|
+
return compareValueSub(valueSub);
|
|
30
|
+
};
|
|
31
|
+
const isEquivalent = () => {
|
|
32
|
+
const [arrNode1, arrNode2] = [node1, node2].map((node) => NodeRewriter.getArrNodeEquivalent(node));
|
|
33
|
+
return arrNode1.some((node1Equivalent) => {
|
|
34
|
+
return arrNode2.some((node2Equivalent) => {
|
|
35
|
+
try {
|
|
36
|
+
const nodeSub = substract(node1Equivalent, node2Equivalent);
|
|
37
|
+
const nodeSubSimplified = NodeSimplifier.simplifyByVibrating(nodeSub);
|
|
38
|
+
const valueSub = nodeSubSimplified.evaluate();
|
|
39
|
+
return compareValueSub(valueSub);
|
|
40
|
+
}
|
|
41
|
+
catch (_) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
if (isSameTex()) {
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return compareUsingEvaluate();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (_) {
|
|
56
|
+
try {
|
|
57
|
+
if (isEquivalent()) {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (_) {
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
static isEqualViaSub = (node1, node2) => {
|
|
70
|
+
return this.compareViaSub(node1, node2) === 0;
|
|
71
|
+
};
|
|
72
|
+
//via frac
|
|
73
|
+
static isEqualViaFrac = (node1, node2) => {
|
|
74
|
+
const [arrNode1, arrNode2] = [node1, node2].map((node) => NodeRewriter.getArrNodeEquivalent(node));
|
|
75
|
+
return arrNode1.some((node1Equivalent) => {
|
|
76
|
+
return arrNode2.some((node2Equivalent) => {
|
|
77
|
+
try {
|
|
78
|
+
const nodeFrac = frac(node1Equivalent, node2Equivalent);
|
|
79
|
+
const nodeFracSimplified = NodeSimplifier.simplifyByVibrating(nodeFrac);
|
|
80
|
+
return this.isEqualViaSub(nodeFracSimplified, (1).toTree());
|
|
81
|
+
}
|
|
82
|
+
catch (_) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeInspector.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeInspector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D,8BAAsB,aAAa;IACjC,MAAM,CAAC,WAAW,CAAC,aAAa,EAAE,aAAa;CAShD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isFunctionNode } from "../nodes/functions/functionNode.js";
|
|
2
|
+
import { isOperatorNode } from "../nodes/operators/operatorNode.js";
|
|
3
|
+
export class NodeInspector {
|
|
4
|
+
static getChildren(algebraicNode) {
|
|
5
|
+
if (isOperatorNode(algebraicNode)) {
|
|
6
|
+
return [algebraicNode.leftChild, algebraicNode.rightChild];
|
|
7
|
+
}
|
|
8
|
+
else if (isFunctionNode(algebraicNode)) {
|
|
9
|
+
return [algebraicNode.child];
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AlgebraicNode } from "../nodes/algebraicNode.js";
|
|
2
|
+
export declare abstract class NodeRewriter {
|
|
3
|
+
static rewriteTopLevel: <T extends AlgebraicNode>(algebraicNode: T, indexIn?: number, shuffleArrayIn?: number[]) => AlgebraicNode;
|
|
4
|
+
static getCreateNodeFromChildrenFunction: <T extends AlgebraicNode>(algebraicNode: T, indexIn?: number) => (children: AlgebraicNode[]) => AlgebraicNode;
|
|
5
|
+
static getArrCreateNodeFromChildrenFunction: (algebraicNode: AlgebraicNode) => ((children: AlgebraicNode[]) => AlgebraicNode)[];
|
|
6
|
+
static getArrRewriteTopLevel(algebraicNode: AlgebraicNode): AlgebraicNode[];
|
|
7
|
+
static getArrNodeEquivalent(algebraicNode: AlgebraicNode, isDistinctTex?: boolean): AlgebraicNode[];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=nodeRewriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeRewriter.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeRewriter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAkC1D,8BAAsB,YAAY;IAChC,MAAM,CAAC,eAAe,GAAI,CAAC,SAAS,aAAa,EAC/C,eAAe,CAAC,EAChB,UAAU,MAAM,EAChB,iBAAiB,MAAM,EAAE,KACxB,aAAa,CAUd;IAEF,MAAM,CAAC,iCAAiC,GAAI,CAAC,SAAS,aAAa,EACjE,eAAe,CAAC,EAChB,UAAU,MAAM,gBAgBH,aAAa,EAAE,KAAK,aAAa,CAP9C;IAKF,MAAM,CAAC,oCAAoC,GACzC,eAAe,aAAa,KAC3B,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,aAAa,CAAC,EAAE,CA2HjD;IAEF,MAAM,CAAC,qBAAqB,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,EAAE;IAW3E,MAAM,CAAC,oBAAoB,CACzB,aAAa,EAAE,aAAa,EAC5B,aAAa,GAAE,OAAc,GAC5B,aAAa,EAAE;CAwCnB"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { abs } from "../nodes/functions/absNode.js";
|
|
2
|
+
import { arccos } from "../nodes/functions/arccosNode.js";
|
|
3
|
+
import { CosNode } from "../nodes/functions/cosNode.js";
|
|
4
|
+
import { FunctionsIds, isFunctionNode, } from "../nodes/functions/functionNode.js";
|
|
5
|
+
import { AddNode } from "../nodes/operators/addNode.js";
|
|
6
|
+
import { BinomialCoefficientNode } from "../nodes/operators/binomialCoefficientNode.js";
|
|
7
|
+
import { DivideNode } from "../nodes/operators/divideNode.js";
|
|
8
|
+
import { frac } from "../nodes/operators/fractionNode.js";
|
|
9
|
+
import { multiply } from "../nodes/operators/multiplyNode.js";
|
|
10
|
+
import { power } from "../nodes/operators/powerNode.js";
|
|
11
|
+
import { substract } from "../nodes/operators/substractNode.js";
|
|
12
|
+
import { sin } from "../nodes/functions/sinNode.js";
|
|
13
|
+
import { sqrt } from "../nodes/functions/sqrtNode.js";
|
|
14
|
+
import { tan } from "../nodes/functions/tanNode.js";
|
|
15
|
+
import { ArcsinNode } from "../nodes/functions/arcSinNode.js";
|
|
16
|
+
import { ArctanNode } from "../nodes/functions/arctanNode.js";
|
|
17
|
+
import { exp } from "../nodes/functions/expNode.js";
|
|
18
|
+
import { LogNode } from "../nodes/functions/logNode.js";
|
|
19
|
+
import { Log10Node } from "../nodes/functions/log10Node.js";
|
|
20
|
+
import { NodeConstructor } from "../nodes/nodeConstructor.js";
|
|
21
|
+
import { isOperatorNode, OperatorIds, } from "../nodes/operators/operatorNode.js";
|
|
22
|
+
import { opposite } from "../nodes/functions/oppositeNode.js";
|
|
23
|
+
import { facto } from "../nodes/functions/factorialNode.js";
|
|
24
|
+
import { getCartesiansProducts } from "../../utils/arrays/cartesianProducts.js";
|
|
25
|
+
import { randint } from "../../math/utils/random/randint.js";
|
|
26
|
+
import { NodeInspector } from "./nodeInspector.js";
|
|
27
|
+
export class NodeRewriter {
|
|
28
|
+
static rewriteTopLevel = (algebraicNode, indexIn, shuffleArrayIn) => {
|
|
29
|
+
const children = NodeInspector.getChildren(algebraicNode);
|
|
30
|
+
const shuffleArray = shuffleArrayIn ?? [...Array(children.length).keys()];
|
|
31
|
+
const shuffledChildren = shuffleArray.map((iTo) => children[iTo]);
|
|
32
|
+
const funcCreateNodeFromChildren = this.getCreateNodeFromChildrenFunction(algebraicNode, indexIn);
|
|
33
|
+
return funcCreateNodeFromChildren(shuffledChildren);
|
|
34
|
+
};
|
|
35
|
+
static getCreateNodeFromChildrenFunction = (algebraicNode, indexIn) => {
|
|
36
|
+
const arrFuncCreateNodeFromChildren = this.getArrCreateNodeFromChildrenFunction(algebraicNode);
|
|
37
|
+
const nbRewritings = arrFuncCreateNodeFromChildren.length;
|
|
38
|
+
const index = indexIn
|
|
39
|
+
? Math.max(nbRewritings - 1, indexIn)
|
|
40
|
+
: randint(0, nbRewritings);
|
|
41
|
+
return arrFuncCreateNodeFromChildren[index];
|
|
42
|
+
};
|
|
43
|
+
/*
|
|
44
|
+
commutation is managed as any other rewriting
|
|
45
|
+
*/
|
|
46
|
+
static getArrCreateNodeFromChildrenFunction = (algebraicNode) => {
|
|
47
|
+
if (isOperatorNode(algebraicNode)) {
|
|
48
|
+
switch (algebraicNode.id) {
|
|
49
|
+
case OperatorIds.binomialCoefficient:
|
|
50
|
+
return [
|
|
51
|
+
(children) => new BinomialCoefficientNode(children[0], children[1], algebraicNode.opts),
|
|
52
|
+
];
|
|
53
|
+
case OperatorIds.divide:
|
|
54
|
+
return [
|
|
55
|
+
(children) => new DivideNode(children[0], children[1]),
|
|
56
|
+
];
|
|
57
|
+
case OperatorIds.fraction: {
|
|
58
|
+
return [
|
|
59
|
+
(children) => frac(children[0], children[1], algebraicNode.opts),
|
|
60
|
+
(children) => multiply(children[0], frac((1).toTree(), children[1], algebraicNode.opts), algebraicNode.opts),
|
|
61
|
+
(children) => multiply(frac((1).toTree(), children[1], algebraicNode.opts), children[0], algebraicNode.opts),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
case OperatorIds.integral:
|
|
65
|
+
return [
|
|
66
|
+
() => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers()),
|
|
67
|
+
];
|
|
68
|
+
case OperatorIds.limit:
|
|
69
|
+
return [
|
|
70
|
+
() => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers()),
|
|
71
|
+
];
|
|
72
|
+
case OperatorIds.multiply:
|
|
73
|
+
return [
|
|
74
|
+
(children) => multiply(children[0], children[1], algebraicNode.opts),
|
|
75
|
+
(children) => multiply(children[1], children[0], algebraicNode.opts),
|
|
76
|
+
];
|
|
77
|
+
case OperatorIds.power:
|
|
78
|
+
case OperatorIds.square: //this is so nice
|
|
79
|
+
return [
|
|
80
|
+
(children) => power(children[0], children[1], algebraicNode.opts),
|
|
81
|
+
];
|
|
82
|
+
case OperatorIds.substract:
|
|
83
|
+
return [
|
|
84
|
+
(children) => substract(children[0], children[1], algebraicNode.opts),
|
|
85
|
+
];
|
|
86
|
+
case OperatorIds.add:
|
|
87
|
+
return [
|
|
88
|
+
(children) => new AddNode(children[0], children[1], algebraicNode.opts),
|
|
89
|
+
(children) => new AddNode(children[1], children[0], algebraicNode.opts),
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (isFunctionNode(algebraicNode)) {
|
|
94
|
+
switch (algebraicNode.id) {
|
|
95
|
+
case FunctionsIds.arccos:
|
|
96
|
+
return [(children) => arccos(children[0])];
|
|
97
|
+
case FunctionsIds.arcsin:
|
|
98
|
+
return [(children) => new ArcsinNode(children[0])];
|
|
99
|
+
case FunctionsIds.arctan:
|
|
100
|
+
return [(children) => new ArctanNode(children[0])];
|
|
101
|
+
case FunctionsIds.cos:
|
|
102
|
+
return [(children) => new CosNode(children[0])];
|
|
103
|
+
case FunctionsIds.exp:
|
|
104
|
+
return [
|
|
105
|
+
(children) => exp(children[0], algebraicNode.opts),
|
|
106
|
+
];
|
|
107
|
+
case FunctionsIds.log:
|
|
108
|
+
return [
|
|
109
|
+
(children) => new LogNode(children[0], algebraicNode.opts),
|
|
110
|
+
];
|
|
111
|
+
case FunctionsIds.log10:
|
|
112
|
+
return [
|
|
113
|
+
(children) => new Log10Node(children[0], algebraicNode.opts),
|
|
114
|
+
];
|
|
115
|
+
case FunctionsIds.opposite:
|
|
116
|
+
return [(children) => opposite(children[0])];
|
|
117
|
+
case FunctionsIds.sin:
|
|
118
|
+
return [(children) => sin(children[0])];
|
|
119
|
+
case FunctionsIds.sqrt:
|
|
120
|
+
return [
|
|
121
|
+
(children) => sqrt(children[0]),
|
|
122
|
+
(children) => power(children[0], frac(1, 2)),
|
|
123
|
+
];
|
|
124
|
+
case FunctionsIds.tan:
|
|
125
|
+
return [(children) => tan(children[0])];
|
|
126
|
+
case FunctionsIds.abs:
|
|
127
|
+
return [(children) => abs(children[0])];
|
|
128
|
+
case FunctionsIds.factorial:
|
|
129
|
+
return [(children) => facto(children[0])];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
return [
|
|
134
|
+
() => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers()),
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
static getArrRewriteTopLevel(algebraicNode) {
|
|
139
|
+
const children = NodeInspector.getChildren(algebraicNode);
|
|
140
|
+
if (children.length === 0) {
|
|
141
|
+
return [algebraicNode];
|
|
142
|
+
}
|
|
143
|
+
const arrFunc = this.getArrCreateNodeFromChildrenFunction(algebraicNode);
|
|
144
|
+
return arrFunc.map((funcCreateNodeFromChildren) => funcCreateNodeFromChildren(children));
|
|
145
|
+
}
|
|
146
|
+
static getArrNodeEquivalent(algebraicNode, isDistinctTex = true) {
|
|
147
|
+
const children = NodeInspector.getChildren(algebraicNode);
|
|
148
|
+
if (children.length === 0) {
|
|
149
|
+
return [algebraicNode];
|
|
150
|
+
}
|
|
151
|
+
//get all valid combinations of topLevel-equivalent children
|
|
152
|
+
const arrChildrenRefined = getCartesiansProducts(children.map((nodeChild) => this.getArrNodeEquivalent(nodeChild).flatMap((nodeChild) => this.getArrRewriteTopLevel(nodeChild))));
|
|
153
|
+
const arrNodeEquivalentRaw = arrChildrenRefined.flatMap((childrenRefined) => {
|
|
154
|
+
const arrFuncCreateNodeFromChildren = this.getArrCreateNodeFromChildrenFunction(algebraicNode);
|
|
155
|
+
return arrFuncCreateNodeFromChildren.map((funcCreateNodeFromChildren) => funcCreateNodeFromChildren(childrenRefined));
|
|
156
|
+
});
|
|
157
|
+
if (isDistinctTex) {
|
|
158
|
+
return arrNodeEquivalentRaw
|
|
159
|
+
.reduce((acc, node) => {
|
|
160
|
+
const tex = node.toTex();
|
|
161
|
+
if (!acc.some(({ tex: texExisting }) => tex === texExisting)) {
|
|
162
|
+
acc.push({ node, tex });
|
|
163
|
+
}
|
|
164
|
+
return acc;
|
|
165
|
+
}, [])
|
|
166
|
+
.map(({ node }) => node);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return arrNodeEquivalentRaw;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -4,9 +4,7 @@ export type DeepShuffleOpts = {
|
|
|
4
4
|
nodeTypesNoFurther: string[];
|
|
5
5
|
};
|
|
6
6
|
export declare abstract class NodeShuffler {
|
|
7
|
-
static shuffle: <T extends AlgebraicNode>(algebraicNode: T, shuffleArrayIn?: number[]) => AlgebraicNode;
|
|
8
|
-
static deepShuffle: <T extends AlgebraicNode>(algebraicNode: T, deepShuffleOpts?: DeepShuffleOpts, shuffleArrayIn?: number[]) => AlgebraicNode;
|
|
9
|
-
private static getCreateNodeFromChildrenFunction;
|
|
10
|
-
static getChildren(algebraicNode: AlgebraicNode): AlgebraicNode[];
|
|
7
|
+
static shuffle: <T extends AlgebraicNode>(algebraicNode: T, shuffleArrayIn?: number[], indexIn?: number) => AlgebraicNode;
|
|
8
|
+
static deepShuffle: <T extends AlgebraicNode>(algebraicNode: T, deepShuffleOpts?: DeepShuffleOpts, shuffleArrayIn?: number[], indexIn?: number) => AlgebraicNode;
|
|
11
9
|
}
|
|
12
10
|
//# sourceMappingURL=nodeShuffler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeShuffler.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeShuffler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"nodeShuffler.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeShuffler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B,CAAC;AAEF,8BAAsB,YAAY;IAChC,MAAM,CAAC,OAAO,GAAI,CAAC,SAAS,aAAa,EACvC,eAAe,CAAC,EAChB,iBAAiB,MAAM,EAAE,EACzB,UAAU,MAAM,KACf,aAAa,CAUd;IAGF,MAAM,CAAC,WAAW,GAAI,CAAC,SAAS,aAAa,EAC3C,eAAe,CAAC,EAChB,kBAAiB,eAGhB,EACD,iBAAiB,MAAM,EAAE,EACzB,UAAS,MAAU,KAClB,aAAa,CA0Bd;CACH"}
|