math-exercises 3.0.182 → 3.0.184

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.
Files changed (85) hide show
  1. package/lib/exercises/math/functions/composition/functionComposition.d.ts.map +1 -1
  2. package/lib/exercises/math/functions/composition/functionComposition.js +11 -22
  3. package/lib/exercises/math/functions/exponential/algebraic/index.d.ts +1 -0
  4. package/lib/exercises/math/functions/exponential/algebraic/index.d.ts.map +1 -1
  5. package/lib/exercises/math/functions/exponential/algebraic/index.js +1 -1
  6. package/lib/exercises/math/functions/exponential/algebraic/rewriteExpUsingExpA.d.ts.map +1 -1
  7. package/lib/exercises/math/functions/exponential/algebraic/rewriteExpUsingExpA.js +18 -3
  8. package/lib/exercises/math/functions/exponential/expKT/derivativeOfAExpKT.d.ts +8 -0
  9. package/lib/exercises/math/functions/exponential/expKT/derivativeOfAExpKT.d.ts.map +1 -0
  10. package/lib/exercises/math/functions/exponential/expKT/derivativeOfAExpKT.js +108 -0
  11. package/lib/exercises/math/functions/exponential/expKT/drugConcentrationMaximum.d.ts +8 -0
  12. package/lib/exercises/math/functions/exponential/expKT/drugConcentrationMaximum.d.ts.map +1 -0
  13. package/lib/exercises/math/functions/exponential/expKT/drugConcentrationMaximum.js +144 -0
  14. package/lib/exercises/math/functions/exponential/expKT/index.d.ts +3 -0
  15. package/lib/exercises/math/functions/exponential/expKT/index.d.ts.map +1 -0
  16. package/lib/exercises/math/functions/exponential/expKT/index.js +2 -0
  17. package/lib/exercises/math/functions/exponential/expSimplifiying.d.ts.map +1 -1
  18. package/lib/exercises/math/functions/exponential/expSimplifiying.js +94 -4
  19. package/lib/exercises/math/functions/exponential/index.d.ts +3 -0
  20. package/lib/exercises/math/functions/exponential/index.d.ts.map +1 -1
  21. package/lib/exercises/math/functions/exponential/index.js +3 -0
  22. package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.d.ts +9 -0
  23. package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.d.ts.map +1 -0
  24. package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.js +101 -0
  25. package/lib/exercises/math/functions/exponential/sign/index.d.ts +2 -0
  26. package/lib/exercises/math/functions/exponential/sign/index.d.ts.map +1 -0
  27. package/lib/exercises/math/functions/exponential/sign/index.js +1 -0
  28. package/lib/exercises/math/functions/exponential/variations/index.d.ts +3 -0
  29. package/lib/exercises/math/functions/exponential/variations/index.d.ts.map +1 -0
  30. package/lib/exercises/math/functions/exponential/variations/index.js +2 -0
  31. package/lib/exercises/math/functions/exponential/variations/varSignTableOfAffineTimesExp.d.ts +7 -0
  32. package/lib/exercises/math/functions/exponential/variations/varSignTableOfAffineTimesExp.d.ts.map +1 -0
  33. package/lib/exercises/math/functions/exponential/variations/varSignTableOfAffineTimesExp.js +144 -0
  34. package/lib/exercises/math/functions/exponential/variations/varSignTableOfExpMinusX.d.ts +7 -0
  35. package/lib/exercises/math/functions/exponential/variations/varSignTableOfExpMinusX.d.ts.map +1 -0
  36. package/lib/exercises/math/functions/exponential/variations/varSignTableOfExpMinusX.js +139 -0
  37. package/lib/exercises/math/probaStat/independancy/independantSuccessiveEventsComputeTwoSuccess.d.ts +7 -0
  38. package/lib/exercises/math/probaStat/independancy/independantSuccessiveEventsComputeTwoSuccess.d.ts.map +1 -0
  39. package/lib/exercises/math/probaStat/independancy/independantSuccessiveEventsComputeTwoSuccess.js +100 -0
  40. package/lib/exercises/math/probaStat/independancy/index.d.ts +1 -0
  41. package/lib/exercises/math/probaStat/independancy/index.d.ts.map +1 -1
  42. package/lib/exercises/math/probaStat/independancy/index.js +1 -0
  43. package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoConsecutiveTerms.d.ts.map +1 -1
  44. package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoConsecutiveTerms.js +37 -39
  45. package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoTerms.d.ts.map +1 -1
  46. package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormulaFromTwoTerms.js +14 -4
  47. package/lib/exercises/math/sequences/geometric/index.d.ts +3 -0
  48. package/lib/exercises/math/sequences/geometric/index.d.ts.map +1 -1
  49. package/lib/exercises/math/sequences/geometric/index.js +3 -3
  50. package/lib/exercises/math/sequences/geometric/situations/geometricFindExplicitFormulaFromSituation.d.ts.map +1 -1
  51. package/lib/exercises/math/sequences/geometric/situations/geometricFindExplicitFormulaFromSituation.js +12 -3
  52. package/lib/exercises/math/sequences/geometric/situations/index.d.ts +1 -0
  53. package/lib/exercises/math/sequences/geometric/situations/index.d.ts.map +1 -1
  54. package/lib/exercises/math/sequences/geometric/situations/index.js +1 -1
  55. package/lib/exercises/vea/treeTableVEA.d.ts.map +1 -1
  56. package/lib/exercises/vea/treeTableVEA.js +3 -0
  57. package/lib/index.d.ts +50 -0
  58. package/lib/index.d.ts.map +1 -1
  59. package/lib/latexTester.js +1 -1
  60. package/lib/tests/singleExo.test.js +2 -2
  61. package/lib/tree/nodes/functions/expNode.d.ts +1 -1
  62. package/lib/tree/nodes/functions/expNode.d.ts.map +1 -1
  63. package/lib/tree/nodes/functions/expNode.js +3 -6
  64. package/lib/tree/nodes/operators/addNode.d.ts +1 -1
  65. package/lib/tree/nodes/operators/addNode.d.ts.map +1 -1
  66. package/lib/tree/nodes/operators/addNode.js +2 -2
  67. package/lib/tree/nodes/operators/substractNode.d.ts +1 -1
  68. package/lib/tree/nodes/operators/substractNode.d.ts.map +1 -1
  69. package/lib/tree/nodes/operators/substractNode.js +2 -2
  70. package/lib/tree/utilities/nodeComparator.d.ts +7 -0
  71. package/lib/tree/utilities/nodeComparator.d.ts.map +1 -0
  72. package/lib/tree/utilities/nodeComparator.js +88 -0
  73. package/lib/tree/utilities/nodeInspector.d.ts +5 -0
  74. package/lib/tree/utilities/nodeInspector.d.ts.map +1 -0
  75. package/lib/tree/utilities/nodeInspector.js +15 -0
  76. package/lib/tree/utilities/nodeRewriter.d.ts +9 -0
  77. package/lib/tree/utilities/nodeRewriter.d.ts.map +1 -0
  78. package/lib/tree/utilities/nodeRewriter.js +172 -0
  79. package/lib/tree/utilities/nodeShuffler.d.ts +2 -4
  80. package/lib/tree/utilities/nodeShuffler.d.ts.map +1 -1
  81. package/lib/tree/utilities/nodeShuffler.js +13 -104
  82. package/lib/tree/utilities/nodeSimplifier.d.ts +1 -2
  83. package/lib/tree/utilities/nodeSimplifier.d.ts.map +1 -1
  84. package/lib/tree/utilities/nodeSimplifier.js +14 -88
  85. package/package.json +1 -1
@@ -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;AA+B1D,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,KACxB,aAAa,CAQd;IAGF,MAAM,CAAC,WAAW,GAAI,CAAC,SAAS,aAAa,EAC3C,eAAe,CAAC,EAChB,kBAAiB,eAGhB,EACD,iBAAiB,MAAM,EAAE,KACxB,aAAa,CAyBd;IAEF,OAAO,CAAC,MAAM,CAAC,iCAAiC,CAkF9C;IAEF,MAAM,CAAC,WAAW,CAAC,aAAa,EAAE,aAAa;CAShD"}
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"}
@@ -1,126 +1,35 @@
1
1
  import { shuffle } from "../../utils/alea/shuffle.js";
2
- import { abs } from "../nodes/functions/absNode.js";
3
- import { arccos } from "../nodes/functions/arccosNode.js";
4
- import { CosNode } from "../nodes/functions/cosNode.js";
5
- import { FunctionsIds, isFunctionNode, } from "../nodes/functions/functionNode.js";
6
- import { AddNode } from "../nodes/operators/addNode.js";
7
- import { BinomialCoefficientNode } from "../nodes/operators/binomialCoefficientNode.js";
8
- import { DivideNode } from "../nodes/operators/divideNode.js";
9
- import { FractionNode } from "../nodes/operators/fractionNode.js";
10
- import { MultiplyNode } from "../nodes/operators/multiplyNode.js";
11
- import { PowerNode } from "../nodes/operators/powerNode.js";
12
- import { SubstractNode } from "../nodes/operators/substractNode.js";
13
- import { sin } from "../nodes/functions/sinNode.js";
14
- import { sqrt } from "../nodes/functions/sqrtNode.js";
15
- import { tan } from "../nodes/functions/tanNode.js";
16
- import { ArcsinNode } from "../nodes/functions/arcSinNode.js";
17
- import { ArctanNode } from "../nodes/functions/arctanNode.js";
18
- import { ExpNode } from "../nodes/functions/expNode.js";
19
- import { LogNode } from "../nodes/functions/logNode.js";
20
- import { Log10Node } from "../nodes/functions/log10Node.js";
21
- import { NodeConstructor } from "../nodes/nodeConstructor.js";
22
- import { isOperatorNode, OperatorIds, } from "../nodes/operators/operatorNode.js";
23
- import { opposite } from "../nodes/functions/oppositeNode.js";
24
- import { facto } from "../nodes/functions/factorialNode.js";
2
+ import { NodeInspector } from "./nodeInspector.js";
3
+ import { NodeRewriter } from "./nodeRewriter.js";
25
4
  export class NodeShuffler {
26
- static shuffle = (algebraicNode, shuffleArrayIn) => {
27
- const children = this.getChildren(algebraicNode);
5
+ static shuffle = (algebraicNode, shuffleArrayIn, indexIn) => {
6
+ const children = NodeInspector.getChildren(algebraicNode);
28
7
  const shuffleArray = shuffleArrayIn ?? shuffle([...Array(children.length).keys()]);
29
8
  const shuffledChildren = shuffleArray.map((iTo) => children[iTo]);
30
- return this.getCreateNodeFromChildrenFunction(algebraicNode)(shuffledChildren);
9
+ const funcCreateNodeFromChildren = NodeRewriter.getCreateNodeFromChildrenFunction(algebraicNode, indexIn);
10
+ return funcCreateNodeFromChildren(shuffledChildren);
31
11
  };
32
12
  //commutative by default
33
13
  static deepShuffle = (algebraicNode, deepShuffleOpts = {
34
14
  nodeTypesToShuffle: ["AddNode", "MultiplyNode"],
35
15
  nodeTypesNoFurther: [],
36
- }, shuffleArrayIn) => {
16
+ }, shuffleArrayIn, indexIn = 0) => {
37
17
  const isCanBeTraversed = !deepShuffleOpts.nodeTypesNoFurther.includes(algebraicNode.constructor.name);
38
- const children = this.getChildren(algebraicNode).map((childNode) => isCanBeTraversed
18
+ const children = NodeInspector.getChildren(algebraicNode).map((childNode) => isCanBeTraversed
39
19
  ? this.deepShuffle(childNode, deepShuffleOpts, shuffleArrayIn)
40
20
  : childNode);
41
- const createNodeFromChildren = this.getCreateNodeFromChildrenFunction(algebraicNode);
42
- if (children.length > 0) {
21
+ const funcCreateNodeFromChildren = NodeRewriter.getCreateNodeFromChildrenFunction(algebraicNode, indexIn);
22
+ if (children.length > 1) {
43
23
  const isCanBeShuffled = (deepShuffleOpts?.nodeTypesToShuffle ?? []).includes(algebraicNode.constructor.name);
44
24
  if (isCanBeShuffled) {
45
25
  const shuffleArray = shuffleArrayIn ?? shuffle([...Array(children.length).keys()]);
46
26
  const shuffledChildren = shuffleArray.map((iTo) => children[iTo]);
47
- return createNodeFromChildren(shuffledChildren);
27
+ return funcCreateNodeFromChildren(shuffledChildren);
48
28
  }
49
29
  else {
50
- createNodeFromChildren(children);
30
+ funcCreateNodeFromChildren(children);
51
31
  }
52
32
  }
53
- return createNodeFromChildren(children);
33
+ return funcCreateNodeFromChildren(children);
54
34
  };
55
- static getCreateNodeFromChildrenFunction = (algebraicNode) => {
56
- if (isOperatorNode(algebraicNode)) {
57
- switch (algebraicNode.id) {
58
- case OperatorIds.binomialCoefficient:
59
- return (children) => new BinomialCoefficientNode(children[0], children[1], algebraicNode.opts);
60
- case OperatorIds.divide:
61
- return (children) => new DivideNode(children[0], children[1]);
62
- case OperatorIds.fraction:
63
- return (children) => new FractionNode(children[0], children[1], algebraicNode.opts);
64
- case OperatorIds.integral:
65
- // throw new Error("unsupported node type: integral"); //need to do intelligent shuffle here
66
- return () => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers());
67
- case OperatorIds.limit:
68
- // throw new Error("unsupported node type: limit"); //need to do intelligent shuffle here
69
- return () => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers());
70
- case OperatorIds.multiply:
71
- return (children) => new MultiplyNode(children[0], children[1], algebraicNode.opts);
72
- case OperatorIds.power:
73
- case OperatorIds.square: //this is so nice
74
- return (children) => new PowerNode(children[0], children[1], algebraicNode.opts);
75
- case OperatorIds.substract:
76
- return (children) => new SubstractNode(children[0], children[1], algebraicNode.opts);
77
- case OperatorIds.add:
78
- return (children) => new AddNode(children[0], children[1], algebraicNode.opts);
79
- }
80
- }
81
- else if (isFunctionNode(algebraicNode)) {
82
- switch (algebraicNode.id) {
83
- case FunctionsIds.arccos:
84
- return (children) => arccos(children[0]);
85
- case FunctionsIds.arcsin:
86
- return (children) => new ArcsinNode(children[0]);
87
- case FunctionsIds.arctan:
88
- return (children) => new ArctanNode(children[0]);
89
- case FunctionsIds.cos:
90
- return (children) => new CosNode(children[0]);
91
- case FunctionsIds.exp:
92
- return (children) => new ExpNode(children[0], algebraicNode.opts);
93
- case FunctionsIds.log:
94
- return (children) => new LogNode(children[0], algebraicNode.opts);
95
- case FunctionsIds.log10:
96
- return (children) => new Log10Node(children[0], algebraicNode.opts);
97
- case FunctionsIds.opposite:
98
- return (children) => opposite(children[0]);
99
- case FunctionsIds.sin:
100
- return (children) => sin(children[0]);
101
- case FunctionsIds.sqrt:
102
- return (children) => sqrt(children[0]);
103
- case FunctionsIds.tan:
104
- return (children) => tan(children[0]);
105
- case FunctionsIds.abs:
106
- return (children) => abs(children[0]);
107
- case FunctionsIds.factorial:
108
- return (children) => facto(children[0]);
109
- }
110
- }
111
- else {
112
- return () => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers());
113
- }
114
- };
115
- static getChildren(algebraicNode) {
116
- if (isOperatorNode(algebraicNode)) {
117
- return [algebraicNode.leftChild, algebraicNode.rightChild];
118
- }
119
- else if (isFunctionNode(algebraicNode)) {
120
- return [algebraicNode.child];
121
- }
122
- else {
123
- return [];
124
- }
125
- }
126
35
  }
@@ -10,7 +10,6 @@ export declare abstract class NodeSimplifier {
10
10
  static arrTexStepByStep: (node: AlgebraicNode, simplifyOpts?: SimplifyOptions, simplifierOpts?: {
11
11
  isMultiTopLevel: boolean;
12
12
  }, toTexOpts?: ToTexOptions) => string[];
13
- private static getCreateNodeFromChildrenFunction;
14
- static getChildren(algebraicNode: AlgebraicNode): AlgebraicNode[];
13
+ static simplifyByVibrating(algebraicNode: AlgebraicNode, nbVibrations?: number, isTowardsDistribute?: boolean): AlgebraicNode;
15
14
  }
16
15
  //# sourceMappingURL=nodeSimplifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodeSimplifier.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeSimplifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAmC3E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,8BAAsB,cAAc;IAClC,MAAM,CAAC,QAAQ,GAAI,CAAC,SAAS,aAAa,EACxC,eAAe,CAAC,EAChB,cAAc,eAAe,EAC7B,eAAc,YAIb,KACA,MAAM,CAsBP;IAEF,MAAM,CAAC,iBAAiB,GAAI,eAAe,aAAa,sCAmCtD;IAEF,MAAM,CAAC,8BAA8B,GAAI,OAAO,aAAa,EAAE,qBAK7D;IAEF,MAAM,CAAC,eAAe,GAAI,CAAC,SAAS,aAAa,EAC/C,eAAe,CAAC,EAChB,cAAc,eAAe,EAC7B,iBAAgB;QACd,eAAe,EAAE,OAAO,CAAC;KAG1B,EACD,YAAW,YAIV,KACA,aAAa,EAAE,CA4JhB;IAEF,MAAM,CAAC,gBAAgB,GACrB,MAAM,aAAa,EACnB,eAAc,eAAoB,EAClC,iBAAgB;QACd,eAAe,EAAE,OAAO,CAAC;KAG1B,EACD,YAAW,YAIV,cAQD;IAEF,OAAO,CAAC,MAAM,CAAC,iCAAiC,CAkF9C;IAEF,MAAM,CAAC,WAAW,CAAC,aAAa,EAAE,aAAa;CAShD"}
1
+ {"version":3,"file":"nodeSimplifier.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeSimplifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAiB3E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKhD,8BAAsB,cAAc;IAClC,MAAM,CAAC,QAAQ,GAAI,CAAC,SAAS,aAAa,EACxC,eAAe,CAAC,EAChB,cAAc,eAAe,EAC7B,eAAc,YAIb,KACA,MAAM,CAsBP;IAEF,MAAM,CAAC,iBAAiB,GAAI,eAAe,aAAa,sCAmCtD;IAEF,MAAM,CAAC,8BAA8B,GAAI,OAAO,aAAa,EAAE,qBAK7D;IAEF,MAAM,CAAC,eAAe,GAAI,CAAC,SAAS,aAAa,EAC/C,eAAe,CAAC,EAChB,cAAc,eAAe,EAC7B,iBAAgB;QACd,eAAe,EAAE,OAAO,CAAC;KAG1B,EACD,YAAW,YAIV,KACA,aAAa,EAAE,CA4JhB;IAEF,MAAM,CAAC,gBAAgB,GACrB,MAAM,aAAa,EACnB,eAAc,eAAoB,EAClC,iBAAgB;QACd,eAAe,EAAE,OAAO,CAAC;KAG1B,EACD,YAAW,YAIV,cAQD;IAEF,MAAM,CAAC,mBAAmB,CACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,GAAE,MAAU,EACxB,mBAAmB,GAAE,OAAc,GAClC,aAAa;CAcjB"}
@@ -1,34 +1,20 @@
1
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";
2
+ import { isFunctionNode } from "../nodes/functions/functionNode.js";
5
3
  import { AddNode, isAddNode } from "../nodes/operators/addNode.js";
6
- import { BinomialCoefficientNode } from "../nodes/operators/binomialCoefficientNode.js";
7
4
  import { DivideNode, isDivideNode } from "../nodes/operators/divideNode.js";
8
- import { FractionNode } from "../nodes/operators/fractionNode.js";
9
5
  import { isMultiplyNode, MultiplyNode, } from "../nodes/operators/multiplyNode.js";
10
- import { PowerNode } from "../nodes/operators/powerNode.js";
11
6
  import { isSubstractNode, SubstractNode, } 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 { ExpNode } 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
7
  import { isOperatorNode, OperatorIds, } from "../nodes/operators/operatorNode.js";
22
- import { opposite } from "../nodes/functions/oppositeNode.js";
23
8
  import { isNumberNode } from "../nodes/numbers/numberNode.js";
24
- import { facto } from "../nodes/functions/factorialNode.js";
9
+ import { NodeInspector } from "./nodeInspector.js";
10
+ import { NodeRewriter } from "./nodeRewriter.js";
25
11
  export class NodeSimplifier {
26
12
  static getDepth = (algebraicNode, simplifyOpts, toTexOptions = {
27
13
  forceTimesSign: true,
28
14
  forceParenthesis: true,
29
15
  forceNoSimplification: true,
30
16
  }) => {
31
- const children = this.getChildren(algebraicNode);
17
+ const children = NodeInspector.getChildren(algebraicNode);
32
18
  if (children.length === 0) {
33
19
  return 0;
34
20
  }
@@ -98,7 +84,7 @@ export class NodeSimplifier {
98
84
  default:
99
85
  return [
100
86
  ...(() => {
101
- const arrArrChild = this.getChildren(algebraicNode).map((nodeChild) => this.nodesStepByStep(nodeChild, simplifyOpts, simplifierOpts));
87
+ const arrArrChild = NodeInspector.getChildren(algebraicNode).map((nodeChild) => this.nodesStepByStep(nodeChild, simplifyOpts, simplifierOpts));
102
88
  const maxLength = Math.max(...arrArrChild.map((nodesSByS) => nodesSByS.length));
103
89
  //multi or single here
104
90
  let arrChildren;
@@ -191,11 +177,11 @@ export class NodeSimplifier {
191
177
  return new DivideNode(new MultiplyNode(childrenRefined[0], divNode.leftChild), divNode.rightChild);
192
178
  }
193
179
  else {
194
- return this.getCreateNodeFromChildrenFunction(algebraicNode)(childrenRefined);
180
+ return NodeRewriter.getCreateNodeFromChildrenFunction(algebraicNode)(childrenRefined);
195
181
  }
196
182
  }
197
183
  else {
198
- return this.getCreateNodeFromChildrenFunction(algebraicNode)(childrenRefined);
184
+ return NodeRewriter.getCreateNodeFromChildrenFunction(algebraicNode)(childrenRefined);
199
185
  }
200
186
  });
201
187
  })(),
@@ -212,75 +198,15 @@ export class NodeSimplifier {
212
198
  }) => {
213
199
  return this.nodesStepByStep(node, simplifyOpts, simplifierOpts, toTexOpts).map((node) => node.toTex(toTexOpts));
214
200
  };
215
- static getCreateNodeFromChildrenFunction = (algebraicNode) => {
216
- if (isOperatorNode(algebraicNode)) {
217
- switch (algebraicNode.id) {
218
- case OperatorIds.binomialCoefficient:
219
- return (children) => new BinomialCoefficientNode(children[0], children[1], algebraicNode.opts);
220
- case OperatorIds.divide:
221
- return (children) => new DivideNode(children[0], children[1]);
222
- case OperatorIds.fraction:
223
- return (children) => new FractionNode(children[0], children[1], algebraicNode.opts);
224
- case OperatorIds.integral:
225
- // throw new Error("unsupported node type: integral"); //need to do intelligent shuffle here
226
- return () => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers());
227
- case OperatorIds.limit:
228
- // throw new Error("unsupported node type: limit"); //need to do intelligent shuffle here
229
- return () => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers());
230
- case OperatorIds.multiply:
231
- return (children) => new MultiplyNode(children[0], children[1], algebraicNode.opts);
232
- case OperatorIds.power:
233
- case OperatorIds.square: //this is so nice
234
- return (children) => new PowerNode(children[0], children[1], algebraicNode.opts);
235
- case OperatorIds.substract:
236
- return (children) => new SubstractNode(children[0], children[1], algebraicNode.opts);
237
- case OperatorIds.add:
238
- return (children) => new AddNode(children[0], children[1], algebraicNode.opts);
239
- }
240
- }
241
- else if (isFunctionNode(algebraicNode)) {
242
- switch (algebraicNode.id) {
243
- case FunctionsIds.arccos:
244
- return (children) => arccos(children[0]);
245
- case FunctionsIds.arcsin:
246
- return (children) => new ArcsinNode(children[0]);
247
- case FunctionsIds.arctan:
248
- return (children) => new ArctanNode(children[0]);
249
- case FunctionsIds.cos:
250
- return (children) => new CosNode(children[0]);
251
- case FunctionsIds.exp:
252
- return (children) => new ExpNode(children[0], algebraicNode.opts);
253
- case FunctionsIds.log:
254
- return (children) => new LogNode(children[0], algebraicNode.opts);
255
- case FunctionsIds.log10:
256
- return (children) => new Log10Node(children[0], algebraicNode.opts);
257
- case FunctionsIds.opposite:
258
- return (children) => opposite(children[0]);
259
- case FunctionsIds.sin:
260
- return (children) => sin(children[0]);
261
- case FunctionsIds.sqrt:
262
- return (children) => sqrt(children[0]);
263
- case FunctionsIds.tan:
264
- return (children) => tan(children[0]);
265
- case FunctionsIds.abs:
266
- return (children) => abs(children[0]);
267
- case FunctionsIds.factorial:
268
- return (children) => facto(children[0]);
269
- }
270
- }
271
- else {
272
- return () => NodeConstructor.fromIdentifiers(algebraicNode.toIdentifiers());
273
- }
274
- };
275
- static getChildren(algebraicNode) {
276
- if (isOperatorNode(algebraicNode)) {
277
- return [algebraicNode.leftChild, algebraicNode.rightChild];
278
- }
279
- else if (isFunctionNode(algebraicNode)) {
280
- return [algebraicNode.child];
201
+ static simplifyByVibrating(algebraicNode, nbVibrations = 5, isTowardsDistribute = true) {
202
+ if (nbVibrations === 0) {
203
+ return algebraicNode;
281
204
  }
282
205
  else {
283
- return [];
206
+ const nodeSimplified = algebraicNode.simplify({
207
+ towardsDistribute: isTowardsDistribute,
208
+ });
209
+ return this.simplifyByVibrating(nodeSimplified, nbVibrations - 1, !isTowardsDistribute);
284
210
  }
285
211
  }
286
212
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.182",
4
+ "version": "3.0.184",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [