math-exercises 3.0.202 → 3.0.203

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 (100) hide show
  1. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.js +1 -1
  2. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.js +1 -1
  3. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts.map +1 -1
  4. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.js +1 -1
  5. package/lib/exercises/math/geometry/angles/anglesUsingIsParallel.d.ts.map +1 -1
  6. package/lib/exercises/math/geometry/angles/anglesUsingIsParallel.js +172 -51
  7. package/lib/exercises/math/geometry/angles/index.d.ts +1 -0
  8. package/lib/exercises/math/geometry/angles/index.d.ts.map +1 -1
  9. package/lib/exercises/math/geometry/angles/index.js +1 -1
  10. package/lib/exercises/math/limits/index.d.ts +1 -5
  11. package/lib/exercises/math/limits/index.d.ts.map +1 -1
  12. package/lib/exercises/math/limits/index.js +1 -5
  13. package/lib/exercises/math/limits/limitReading.d.ts.map +1 -1
  14. package/lib/exercises/math/limits/limitReading.js +70 -0
  15. package/lib/exercises/math/limits/polynomLimit.d.ts.map +1 -1
  16. package/lib/exercises/math/limits/polynomLimit.js +55 -4
  17. package/lib/exercises/math/limits/polynomLimitNoFI.d.ts.map +1 -1
  18. package/lib/exercises/math/limits/polynomLimitNoFI.js +35 -2
  19. package/lib/exercises/math/limits/sequenceGeometricLimit.d.ts.map +1 -1
  20. package/lib/exercises/math/limits/sequenceGeometricLimit.js +45 -9
  21. package/lib/exercises/math/limits/sequencePolynomLimit.d.ts.map +1 -1
  22. package/lib/exercises/math/limits/sequencePolynomLimit.js +56 -3
  23. package/lib/exercises/math/limits/sequencePolynomNoFILimit.d.ts.map +1 -1
  24. package/lib/exercises/math/limits/sequencePolynomNoFILimit.js +32 -0
  25. package/lib/exercises/math/limits/sequencePolynomProductLimit.d.ts.map +1 -1
  26. package/lib/exercises/math/limits/sequencePolynomProductLimit.js +33 -3
  27. package/lib/exercises/math/limits/sequenceRationalFracLimit.d.ts.map +1 -1
  28. package/lib/exercises/math/limits/sequenceRationalFracLimit.js +2 -2
  29. package/lib/exercises/math/limits/sequences/index.d.ts +6 -0
  30. package/lib/exercises/math/limits/sequences/index.d.ts.map +1 -0
  31. package/lib/exercises/math/limits/sequences/index.js +5 -0
  32. package/lib/exercises/math/limits/sequences/sequenceGeometricLimit.d.ts +9 -0
  33. package/lib/exercises/math/limits/sequences/sequenceGeometricLimit.d.ts.map +1 -0
  34. package/lib/exercises/math/limits/sequences/sequenceGeometricLimit.js +110 -0
  35. package/lib/exercises/math/limits/sequences/sequencePolynomLimit.d.ts +7 -0
  36. package/lib/exercises/math/limits/sequences/sequencePolynomLimit.d.ts.map +1 -0
  37. package/lib/exercises/math/limits/sequences/sequencePolynomLimit.js +116 -0
  38. package/lib/exercises/math/limits/sequences/sequencePolynomNoFILimit.d.ts +7 -0
  39. package/lib/exercises/math/limits/sequences/sequencePolynomNoFILimit.d.ts.map +1 -0
  40. package/lib/exercises/math/limits/sequences/sequencePolynomNoFILimit.js +95 -0
  41. package/lib/exercises/math/limits/sequences/sequencePolynomProductLimit.d.ts +8 -0
  42. package/lib/exercises/math/limits/sequences/sequencePolynomProductLimit.d.ts.map +1 -0
  43. package/lib/exercises/math/limits/sequences/sequencePolynomProductLimit.js +111 -0
  44. package/lib/exercises/math/limits/sequences/sequenceRationalFracLimit.d.ts +8 -0
  45. package/lib/exercises/math/limits/sequences/sequenceRationalFracLimit.d.ts.map +1 -0
  46. package/lib/exercises/math/limits/sequences/sequenceRationalFracLimit.js +114 -0
  47. package/lib/exercises/math/sequences/index.d.ts +1 -0
  48. package/lib/exercises/math/sequences/index.d.ts.map +1 -1
  49. package/lib/exercises/math/sequences/index.js +1 -0
  50. package/lib/exercises/math/sequences/proofByInduction/index.d.ts +5 -0
  51. package/lib/exercises/math/sequences/proofByInduction/index.d.ts.map +1 -0
  52. package/lib/exercises/math/sequences/proofByInduction/index.js +4 -0
  53. package/lib/exercises/math/sequences/proofByInduction/proofByInductionCheckInitialization.d.ts +10 -0
  54. package/lib/exercises/math/sequences/proofByInduction/proofByInductionCheckInitialization.d.ts.map +1 -0
  55. package/lib/exercises/math/sequences/proofByInduction/proofByInductionCheckInitialization.js +236 -0
  56. package/lib/exercises/math/sequences/proofByInduction/proofByInductionReorderProof.d.ts +13 -0
  57. package/lib/exercises/math/sequences/proofByInduction/proofByInductionReorderProof.d.ts.map +1 -0
  58. package/lib/exercises/math/sequences/proofByInduction/proofByInductionReorderProof.js +244 -0
  59. package/lib/exercises/math/sequences/proofByInduction/proofByInductionSituations.d.ts +98 -0
  60. package/lib/exercises/math/sequences/proofByInduction/proofByInductionSituations.d.ts.map +1 -0
  61. package/lib/exercises/math/sequences/proofByInduction/proofByInductionSituations.js +175 -0
  62. package/lib/exercises/math/sequences/proofByInduction/proofByInductionWriteMissingStep.d.ts +13 -0
  63. package/lib/exercises/math/sequences/proofByInduction/proofByInductionWriteMissingStep.d.ts.map +1 -0
  64. package/lib/exercises/math/sequences/proofByInduction/proofByInductionWriteMissingStep.js +317 -0
  65. package/lib/exercises/math/sequences/proofByInduction/proofByInductionWritePropAtRankKPlus1.d.ts +13 -0
  66. package/lib/exercises/math/sequences/proofByInduction/proofByInductionWritePropAtRankKPlus1.d.ts.map +1 -0
  67. package/lib/exercises/math/sequences/proofByInduction/proofByInductionWritePropAtRankKPlus1.js +265 -0
  68. package/lib/exercises/vea/polynomialVEA.d.ts.map +1 -1
  69. package/lib/exercises/vea/polynomialVEA.js +4 -0
  70. package/lib/index.d.ts +49 -13
  71. package/lib/index.d.ts.map +1 -1
  72. package/lib/math/geometry/point.d.ts.map +1 -1
  73. package/lib/math/geometry/point.js +1 -1
  74. package/lib/math/utils/functions/functionDecomposition.d.ts +2 -2
  75. package/lib/math/utils/functions/functionDecomposition.d.ts.map +1 -1
  76. package/lib/tests/exoTest.d.ts.map +1 -1
  77. package/lib/tests/exoTest.js +7 -11
  78. package/lib/tests/questionTest.d.ts.map +1 -1
  79. package/lib/tests/questionTest.js +7 -3
  80. package/lib/tests/singleExo.test.d.ts.map +1 -1
  81. package/lib/tests/singleExo.test.js +2 -2
  82. package/lib/tree/nodes/node.d.ts +2 -1
  83. package/lib/tree/nodes/node.d.ts.map +1 -1
  84. package/lib/tree/nodes/node.js +1 -0
  85. package/lib/tree/nodes/student/iDontKnowNode.d.ts +26 -0
  86. package/lib/tree/nodes/student/iDontKnowNode.d.ts.map +1 -0
  87. package/lib/tree/nodes/student/iDontKnowNode.js +63 -0
  88. package/lib/tree/parsers/latexParser.d.ts +3 -2
  89. package/lib/tree/parsers/latexParser.d.ts.map +1 -1
  90. package/lib/tree/parsers/latexParser.js +7 -0
  91. package/lib/tree/parsers/monomParser.d.ts +1 -1
  92. package/lib/tree/parsers/monomParser.d.ts.map +1 -1
  93. package/lib/tree/parsers/polynomialParser.d.ts +1 -1
  94. package/lib/tree/parsers/polynomialParser.d.ts.map +1 -1
  95. package/lib/tree/parsers/trinomParser.d.ts +1 -1
  96. package/lib/tree/parsers/trinomParser.d.ts.map +1 -1
  97. package/lib/tree/utilities/nodeComparator.d.ts +3 -1
  98. package/lib/tree/utilities/nodeComparator.d.ts.map +1 -1
  99. package/lib/tree/utilities/nodeComparator.js +63 -5
  100. package/package.json +1 -1
@@ -0,0 +1,63 @@
1
+ import { NodeIds, NodeType } from "../node.js";
2
+ export function isIDontKnowNode(a) {
3
+ return a.type === NodeType.iDontKnow;
4
+ }
5
+ export class IDontKnowNode {
6
+ tex;
7
+ type;
8
+ isNumeric;
9
+ constructor(tex) {
10
+ this.tex = tex;
11
+ this.isNumeric = false;
12
+ this.type = NodeType.iDontKnow;
13
+ }
14
+ static keyword() {
15
+ return "N.S.P";
16
+ }
17
+ toMathString() {
18
+ throw new Error("can't create mathString from IDontKnowNode");
19
+ }
20
+ toTex() {
21
+ return `${this.tex}`;
22
+ }
23
+ // toMathjs() {
24
+ // return parse(this.mathString);
25
+ // }
26
+ toAllValidTexs() {
27
+ return this.toEquivalentNodes().map((node) => node.toTex());
28
+ }
29
+ toIdentifiers() {
30
+ return {
31
+ id: NodeIds.constant,
32
+ tex: this.tex,
33
+ };
34
+ }
35
+ toEquivalentNodes() {
36
+ return [this];
37
+ }
38
+ evaluate() {
39
+ return NaN;
40
+ }
41
+ simplify(_opts) {
42
+ return this;
43
+ }
44
+ toSimplificationTex(opts) {
45
+ const simp = this.simplify(opts);
46
+ if (simp.toTex() !== this.toTex())
47
+ return this.toTex() + "=" + simp.toTex();
48
+ return this.toTex();
49
+ }
50
+ equals(node) {
51
+ return isIDontKnowNode(node) && node.tex === this.tex;
52
+ }
53
+ toDetailedEvaluation(vars) {
54
+ //?utile pour des trucs genre 3Pi+4 --> 3*3.14+4
55
+ return vars[this.tex] ?? this;
56
+ }
57
+ derivative() {
58
+ return this;
59
+ }
60
+ toSignInequationTex() {
61
+ return "";
62
+ }
63
+ }
@@ -1,11 +1,12 @@
1
1
  import { AlgebraicNode } from "../nodes/algebraicNode.js";
2
2
  import { EqualNode } from "../nodes/equations/equalNode.js";
3
3
  import { InequationNode } from "../nodes/inequations/inequationNode.js";
4
+ import { IDontKnowNode } from "../nodes/student/iDontKnowNode.js";
4
5
  export declare const tokenize: (latex: string) => string[];
5
6
  type ParserOptions = {
6
7
  allowStartingPower?: boolean;
7
8
  };
8
- export declare const parseAlgebraic: (latex: string, opts?: ParserOptions) => AlgebraicNode;
9
- export declare const parseLatex: (latex: string) => AlgebraicNode | EqualNode | InequationNode;
9
+ export declare const parseAlgebraic: (latex: string, opts?: ParserOptions) => AlgebraicNode | IDontKnowNode;
10
+ export declare const parseLatex: (latex: string) => AlgebraicNode | EqualNode | InequationNode | IDontKnowNode;
10
11
  export {};
11
12
  //# sourceMappingURL=latexParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"latexParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/latexParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAQ5D,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AA0ExE,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,aAwDrC,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AACF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,OAAO,aAAa,kBAuBjE,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,+CAyCvC,CAAC"}
1
+ {"version":3,"file":"latexParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/latexParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAQ5D,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAgBxE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AA2DlE,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,aAwDrC,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AACF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,OAAO,aAAa,kCA4BjE,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,+DA6CvC,CAAC"}
@@ -16,6 +16,7 @@ import { FractionNode } from "../nodes/operators/fractionNode.js";
16
16
  import { MultiplyNode, isMultiplyNode, } from "../nodes/operators/multiplyNode.js";
17
17
  import { PowerNode } from "../nodes/operators/powerNode.js";
18
18
  import { SubstractNode } from "../nodes/operators/substractNode.js";
19
+ import { IDontKnowNode } from "../nodes/student/iDontKnowNode.js";
19
20
  import { VariableNode } from "../nodes/variables/variableNode.js";
20
21
  //cmds that needs a child, like \exp{3}
21
22
  const functions = [
@@ -125,6 +126,9 @@ export const tokenize = (latex) => {
125
126
  };
126
127
  export const parseAlgebraic = (latex, opts) => {
127
128
  // console.log("parsingAlg ", latex);
129
+ if (latex.includes(IDontKnowNode.keyword())) {
130
+ return new IDontKnowNode(latex);
131
+ }
128
132
  let formatedLatex = latex;
129
133
  if (!opts?.allowStartingPower && latex.startsWith("^")) {
130
134
  if (latex[1] === "{") {
@@ -151,6 +155,9 @@ export const parseAlgebraic = (latex, opts) => {
151
155
  };
152
156
  export const parseLatex = (latex) => {
153
157
  // console.log("parsingLatex ", latex);
158
+ if (latex.includes(IDontKnowNode.keyword())) {
159
+ return new IDontKnowNode(latex);
160
+ }
154
161
  const formattedLatex = latex
155
162
  .replaceAll("\\left", "")
156
163
  .replaceAll("\\right", "");
@@ -3,6 +3,6 @@ type Opts = {
3
3
  maxDegree?: number;
4
4
  minDegree?: number;
5
5
  };
6
- export declare const monomParser: (str: string, { variable, maxDegree, minDegree }?: Opts) => false | import("../nodes/algebraicNode.js").AlgebraicNode;
6
+ export declare const monomParser: (str: string, { variable, maxDegree, minDegree }?: Opts) => false | import("../nodes/algebraicNode.js").AlgebraicNode | import("../nodes/student/iDontKnowNode.js").IDontKnowNode;
7
7
  export {};
8
8
  //# sourceMappingURL=monomParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"monomParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/monomParser.ts"],"names":[],"mappings":"AAIA,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,eAAO,MAAM,WAAW,GACtB,KAAK,MAAM,EACX,qCAAoC,IAInC,8DAaF,CAAC"}
1
+ {"version":3,"file":"monomParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/monomParser.ts"],"names":[],"mappings":"AAIA,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,eAAO,MAAM,WAAW,GACtB,KAAK,MAAM,EACX,qCAAoC,IAInC,0HAaF,CAAC"}
@@ -2,6 +2,6 @@ import { AlgebraicNode } from "../nodes/algebraicNode.js";
2
2
  type Opts = {
3
3
  variable?: string;
4
4
  };
5
- export declare const polynomialParser: (ans: string, opts?: Opts) => false | AlgebraicNode | import("../nodes/numbers/constantNode.js").ConstantNode | import("../nodes/numbers/numberNode.js").NumberNode | import("../nodes/operators/substractNode.js").SubstractNode | import("../nodes/operators/addNode.js").AddNode;
5
+ export declare const polynomialParser: (ans: string, opts?: Opts) => false | AlgebraicNode | import("../nodes/numbers/constantNode.js").ConstantNode | import("../nodes/numbers/numberNode.js").NumberNode | import("../nodes/operators/substractNode.js").SubstractNode | import("../nodes/operators/addNode.js").AddNode | import("../nodes/student/iDontKnowNode.js").IDontKnowNode;
6
6
  export {};
7
7
  //# sourceMappingURL=polynomialParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"polynomialParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/polynomialParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAS1D,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,OAAO,IAAI,0PAkCxD,CAAC"}
1
+ {"version":3,"file":"polynomialParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/polynomialParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAS1D,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,OAAO,IAAI,sTAkCxD,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const trinomParser: (ans: string, variable?: string) => false | import("../nodes/algebraicNode.js").AlgebraicNode | undefined;
1
+ export declare const trinomParser: (ans: string, variable?: string) => false | import("../nodes/algebraicNode.js").AlgebraicNode | import("../nodes/student/iDontKnowNode.js").IDontKnowNode | undefined;
2
2
  //# sourceMappingURL=trinomParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trinomParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/trinomParser.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,WAAU,MAAY,0EAgC/D,CAAC"}
1
+ {"version":3,"file":"trinomParser.d.ts","sourceRoot":"","sources":["../../../src/tree/parsers/trinomParser.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,WAAU,MAAY,sIAgC/D,CAAC"}
@@ -1,11 +1,13 @@
1
1
  import { Tuple } from "../../math/sets/tuple.js";
2
2
  import { AlgebraicNode } from "../nodes/algebraicNode.js";
3
3
  import { DiscreteSetNode } from "../nodes/sets/discreteSetNode.js";
4
+ import { VariableNode } from "../nodes/variables/variableNode.js";
4
5
  export declare abstract class NodeComparator {
5
6
  static compareViaSub: <T extends AlgebraicNode>(node1: T, node2: T) => -1 | 0 | 1;
6
7
  static isEqualViaSub: (node1: AlgebraicNode, node2: AlgebraicNode) => boolean;
7
8
  static isEqualViaFrac: (node1: AlgebraicNode, node2: AlgebraicNode) => boolean;
8
- static isEqualViaRandomEvaluations(node1: AlgebraicNode, node2: AlgebraicNode, nbRandomEvaluations: number, precision?: number): boolean;
9
+ static isEqualViaRandomEvaluations(node1: AlgebraicNode, node2: AlgebraicNode, nbRandomEvaluations: number, precision?: number, nodeVar?: VariableNode, randFunc?: () => number): boolean;
10
+ static isEqualViaRandomSubstitutions(node1: AlgebraicNode, node2: AlgebraicNode, nbRandomEvaluations: number, nodeVar?: VariableNode): boolean;
9
11
  static isNodeInDiscreteSet: (node: AlgebraicNode, nodeDiscreteSet: DiscreteSetNode) => boolean;
10
12
  static isTupleInCartesianProductOfDiscreteSets: (tuple: Tuple, arrDiscreteSet: DiscreteSetNode[]) => boolean;
11
13
  static isEqualTuple: (tuple1: Tuple, tuple2: Tuple) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"nodeComparator.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeComparator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAKnE,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;IAIF,MAAM,CAAC,2BAA2B,CAChC,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,aAAa,EACpB,mBAAmB,EAAE,MAAM,EAC3B,SAAS,GAAE,MAAU;IAiEvB,MAAM,CAAC,mBAAmB,GACxB,MAAM,aAAa,EACnB,iBAAiB,eAAe,aAI9B;IAEJ,MAAM,CAAC,uCAAuC,GAC5C,OAAO,KAAK,EACZ,gBAAgB,eAAe,EAAE,aAQjC;IAIF,MAAM,CAAC,YAAY,GAAI,QAAQ,KAAK,EAAE,QAAQ,KAAK,aAIjD;IAEF,MAAM,CAAC,iBAAiB,GAAI,OAAO,KAAK,EAAE,UAAU,KAAK,EAAE,aAMzD;CACH"}
1
+ {"version":3,"file":"nodeComparator.d.ts","sourceRoot":"","sources":["../../../src/tree/utilities/nodeComparator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAIjD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAMlE,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,CAMR;IAIF,MAAM,CAAC,cAAc,GACnB,OAAO,aAAa,EACpB,OAAO,aAAa,KACnB,OAAO,CAoBR;IASF,MAAM,CAAC,2BAA2B,CAChC,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,aAAa,EACpB,mBAAmB,EAAE,MAAM,EAC3B,SAAS,GAAE,MAAU,EACrB,OAAO,GAAE,YAAoC,EAC7C,QAAQ,GAAE,MAAM,MAAqC;IA2EvD,MAAM,CAAC,6BAA6B,CAClC,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,aAAa,EACpB,mBAAmB,EAAE,MAAM,EAC3B,OAAO,GAAE,YAAoC;IAmE/C,MAAM,CAAC,mBAAmB,GACxB,MAAM,aAAa,EACnB,iBAAiB,eAAe,aAI9B;IAEJ,MAAM,CAAC,uCAAuC,GAC5C,OAAO,KAAK,EACZ,gBAAgB,eAAe,EAAE,aAQjC;IAIF,MAAM,CAAC,YAAY,GAAI,QAAQ,KAAK,EAAE,QAAQ,KAAK,aAIjD;IAEF,MAAM,CAAC,iBAAiB,GAAI,OAAO,KAAK,EAAE,UAAU,KAAK,EAAE,aAMzD;CACH"}
@@ -1,11 +1,14 @@
1
+ import { nodeBySubstitutingVar } from "../../math/utils/functions/functionComposition.js";
1
2
  import { randfloat } from "../../math/utils/random/randfloat.js";
2
3
  import { zip } from "../../utils/arrays/arrayZip.js";
3
4
  import { isInfiniteNode } from "../nodes/numbers/constantNode.js";
4
5
  import { frac } from "../nodes/operators/fractionNode.js";
5
6
  import { substract } from "../nodes/operators/substractNode.js";
7
+ import { VariableNode } from "../nodes/variables/variableNode.js";
6
8
  import { NodeRewriter } from "./nodeRewriter.js";
7
9
  import { NodeSimplifier } from "./nodeSimplifier.js";
8
10
  import { round } from "../../math/utils/round.js";
11
+ import { isIDontKnowNode } from "../nodes/student/iDontKnowNode.js";
9
12
  export class NodeComparator {
10
13
  //via sub
11
14
  static compareViaSub = (node1, node2) => {
@@ -71,10 +74,16 @@ export class NodeComparator {
71
74
  }
72
75
  };
73
76
  static isEqualViaSub = (node1, node2) => {
77
+ if (isIDontKnowNode(node1) || isIDontKnowNode(node2)) {
78
+ return false;
79
+ }
74
80
  return this.compareViaSub(node1, node2) === 0;
75
81
  };
76
82
  //via frac
77
83
  static isEqualViaFrac = (node1, node2) => {
84
+ if (isIDontKnowNode(node1) || isIDontKnowNode(node2)) {
85
+ return false;
86
+ }
78
87
  const [arrNode1, arrNode2] = [node1, node2].map((node) => NodeRewriter.getArrNodeEquivalent(node));
79
88
  return arrNode1.some((node1Equivalent) => {
80
89
  return arrNode2.some((node2Equivalent) => {
@@ -90,27 +99,37 @@ export class NodeComparator {
90
99
  });
91
100
  };
92
101
  //via random evaluations
93
- static isEqualViaRandomEvaluations(node1, node2, nbRandomEvaluations, precision = 8) {
94
- const getSafeEvaluationDictForEqualityCheck = (node1, node2, nbSafeX = 4) => {
102
+ /*
103
+ Spoiler alert: (-2)^1.96 = NaN
104
+ Be sure to always use positive integer exponents when dealing with negative numbers
105
+ */
106
+ static isEqualViaRandomEvaluations(node1, node2, nbRandomEvaluations, precision = 8, nodeVar = new VariableNode("x"), randFunc = () => randfloat(-20, 100, 3)) {
107
+ if (isIDontKnowNode(node1) || isIDontKnowNode(node2)) {
108
+ return false;
109
+ }
110
+ const getSafeEvaluationDictForEqualityCheck = (node1, node2, nbSafeX = nbRandomEvaluations) => {
95
111
  const dict = {};
96
112
  let counter = -1;
97
113
  while (Object.keys(dict).length < nbSafeX && counter < 1000) {
98
114
  counter++;
99
- const x = randfloat(-20, 100, 3);
115
+ const x = randFunc();
100
116
  let value1;
101
117
  let value2;
102
118
  try {
103
- value1 = node1.evaluate({ x });
119
+ value1 = node1.evaluate({ [nodeVar.name]: x });
104
120
  }
105
121
  catch (_) {
106
122
  continue;
107
123
  }
108
124
  try {
109
- value2 = node2.evaluate({ x });
125
+ value2 = node2.evaluate({ [nodeVar.name]: x });
110
126
  }
111
127
  catch (_) {
112
128
  continue;
113
129
  }
130
+ // console.log("x", x);
131
+ // console.log("value1", value1);
132
+ // console.log("value2", value2);
114
133
  const [isValidValue1, isValidValue2] = [value1, value2].map((value) => value !== undefined &&
115
134
  !isNaN(value) &&
116
135
  !isInfiniteNode(value.toTree()));
@@ -128,10 +147,49 @@ export class NodeComparator {
128
147
  return Object.values(getSafeEvaluationDictForEqualityCheck(node1, node2, nbRandomEvaluations)).every((arrSafeEval) => {
129
148
  return arrSafeEval.slice(1).every((safeEval) => {
130
149
  const valueSubRounded = round(substract(arrSafeEval[0].value, safeEval.value).evaluate(), precision);
150
+ // console.log("valueSubRounded", valueSubRounded);
131
151
  return valueSubRounded === 0;
132
152
  });
133
153
  });
134
154
  }
155
+ //via random substitutions
156
+ static isEqualViaRandomSubstitutions(node1, node2, nbRandomEvaluations, nodeVar = new VariableNode("x")) {
157
+ if (isIDontKnowNode(node1) || isIDontKnowNode(node2)) {
158
+ return false;
159
+ }
160
+ const getSafeEvaluationDictForEqualityCheck = (node1, node2, nbSafeX = nbRandomEvaluations) => {
161
+ const dict = {};
162
+ let counter = -1;
163
+ while (Object.keys(dict).length < nbSafeX && counter < 1000) {
164
+ counter++;
165
+ const x = randfloat(-20, 100, 3);
166
+ const [nodeSubstituted1, nodeSubstituted2] = [node1, node2].map((node) => nodeBySubstitutingVar(node, x.toTree(), nodeVar));
167
+ const [isValidValue1, isValidValue2] = [
168
+ nodeSubstituted1,
169
+ nodeSubstituted2,
170
+ ].map((nodeSubstituted) => {
171
+ const value = nodeSubstituted.evaluate();
172
+ return value !== undefined && !isInfiniteNode(value.toTree());
173
+ });
174
+ const isValidEvaluation = isValidValue1 && isValidValue2;
175
+ if (isValidEvaluation) {
176
+ dict[x] = [nodeSubstituted1, nodeSubstituted2].map((nodeSubstituted) => {
177
+ return {
178
+ x,
179
+ nodeSubstituted,
180
+ };
181
+ });
182
+ }
183
+ }
184
+ return dict;
185
+ };
186
+ return Object.values(getSafeEvaluationDictForEqualityCheck(node1, node2, nbRandomEvaluations)).every((arrSafeEval) => {
187
+ return arrSafeEval.slice(1).every((safeEval) => {
188
+ const isEqualNodes = NodeComparator.isEqualViaSub(arrSafeEval[0].nodeSubstituted, safeEval.nodeSubstituted);
189
+ return isEqualNodes;
190
+ });
191
+ });
192
+ }
135
193
  //discreteSets, etc.
136
194
  static isNodeInDiscreteSet = (node, nodeDiscreteSet) => nodeDiscreteSet.elements.some((nodeInSet) => NodeComparator.isEqualViaSub(node, nodeInSet));
137
195
  static isTupleInCartesianProductOfDiscreteSets = (tuple, arrDiscreteSet) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.202",
4
+ "version": "3.0.203",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [