math-exercises 1.3.4 → 1.3.5

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 (102) hide show
  1. package/lib/exercises/calcul/addAndSub.js +11 -12
  2. package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +15 -15
  3. package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +15 -14
  4. package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +13 -13
  5. package/lib/exercises/calcul/fractions/fractionsDivision.js +12 -12
  6. package/lib/exercises/calcul/fractions/fractionsProduct.js +11 -12
  7. package/lib/exercises/calcul/fractions/fractionsSum.js +11 -12
  8. package/lib/exercises/calcul/fractions/simplifyFraction.js +10 -11
  9. package/lib/exercises/calcul/operations/operationsPriorities.js +98 -0
  10. package/lib/exercises/calcul/operations/operationsPrioritiesWithoutRelative.js +111 -0
  11. package/lib/exercises/calcul/rounding/rounding.js +36 -37
  12. package/lib/exercises/calculLitteral/distributivity/allIdentities.js +8 -8
  13. package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +15 -16
  14. package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +10 -11
  15. package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +17 -18
  16. package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +16 -17
  17. package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +15 -16
  18. package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +15 -16
  19. package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +19 -20
  20. package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +19 -20
  21. package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +20 -21
  22. package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +20 -21
  23. package/lib/exercises/exercises.js +11 -1
  24. package/lib/exercises/geometry/cartesian/midpoint.js +29 -0
  25. package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +28 -0
  26. package/lib/exercises/geometry/vectors/scalarProductViaNorms.js +27 -0
  27. package/lib/exercises/powers/powersDivision.js +23 -24
  28. package/lib/exercises/powers/powersOfTenToDecimal.js +13 -14
  29. package/lib/exercises/powers/powersPower.js +19 -20
  30. package/lib/exercises/powers/powersProduct.js +22 -23
  31. package/lib/exercises/powers/scientificToDecimal.js +17 -18
  32. package/lib/exercises/sequences/geometric/geometricExplicitFormulaUsage.js +24 -0
  33. package/lib/exercises/sequences/geometric/geometricFindReason.js +23 -0
  34. package/lib/exercises/squareRoots/simpifySquareRoot.js +9 -10
  35. package/lib/exercises/trigonometry/mainRemarkableValues.js +28 -0
  36. package/lib/exercises/trigonometry/remarkableValues.js +28 -0
  37. package/lib/exercises/utils/getDistinctQuestions.js +1 -1
  38. package/lib/geometry/point.js +26 -0
  39. package/lib/geometry/vector.js +31 -0
  40. package/lib/index.js +1 -0
  41. package/lib/math/geometry/point.js +27 -0
  42. package/lib/math/geometry/vector.js +31 -0
  43. package/lib/math/numbers/decimals/decimal.js +140 -0
  44. package/lib/math/numbers/epsilon.js +10 -0
  45. package/lib/math/numbers/integer/integer.js +68 -0
  46. package/lib/math/numbers/integer/power.js +52 -0
  47. package/lib/math/numbers/nombre.js +10 -0
  48. package/lib/math/numbers/rationals/rational.js +113 -0
  49. package/lib/math/numbers/reals/real.js +16 -0
  50. package/lib/math/numbers/reals/squareRoot.js +63 -0
  51. package/lib/math/polynomials/affine.js +42 -0
  52. package/lib/math/polynomials/polynomial.js +125 -0
  53. package/lib/math/sequences/arithmeticSequence.js +1 -0
  54. package/lib/math/sequences/geometricSequence.js +8 -0
  55. package/lib/math/sequences/sequence.js +18 -0
  56. package/lib/math/sets/discreteSet.js +28 -0
  57. package/lib/math/sets/emptySet.js +6 -0
  58. package/lib/math/sets/intervals/intervals.js +104 -0
  59. package/lib/math/sets/mathSet.js +10 -0
  60. package/lib/math/sets/mathSetInterface.js +2 -0
  61. package/lib/math/trigonometry/remarkableValue.js +29 -0
  62. package/lib/math/trigonometry/remarkableValues.js +51 -0
  63. package/lib/math/utils/arithmetic/coprimesOf.js +13 -0
  64. package/lib/math/utils/arithmetic/dividersOf.js +12 -0
  65. package/lib/math/utils/arithmetic/gcd.js +7 -0
  66. package/lib/math/utils/arithmetic/isSquare.js +7 -0
  67. package/lib/math/utils/arithmetic/lcd.js +12 -0
  68. package/lib/math/utils/arithmetic/nonCoprimesOf.js +13 -0
  69. package/lib/math/utils/arithmetic/nonDividersOf.js +14 -0
  70. package/lib/math/utils/arithmetic/primeFactors.js +22 -0
  71. package/lib/math/utils/decimals/decimalPartLengthOf.js +14 -0
  72. package/lib/math/utils/random/randTupleInt.js +30 -0
  73. package/lib/math/utils/random/randint.js +18 -0
  74. package/lib/math/utils/round.js +8 -0
  75. package/lib/mathutils/random/randTupleInt.js +30 -0
  76. package/lib/sets/intervals/intervals.js +14 -18
  77. package/lib/tree/nodes/functions/cosNode.js +21 -0
  78. package/lib/tree/nodes/functions/functionNode.js +2 -0
  79. package/lib/tree/nodes/functions/oppositeNode.js +16 -3
  80. package/lib/tree/nodes/functions/sinNode.js +1 -0
  81. package/lib/tree/nodes/functions/sqrtNode.js +6 -3
  82. package/lib/tree/nodes/node.js +4 -3
  83. package/lib/tree/nodes/numbers/constantNode.js +18 -0
  84. package/lib/tree/nodes/numbers/numberNode.js +7 -3
  85. package/lib/tree/nodes/numbers/piNode.js +5 -0
  86. package/lib/tree/nodes/operators/addNode.js +7 -3
  87. package/lib/tree/nodes/operators/divideNode.js +20 -3
  88. package/lib/tree/nodes/operators/equalNode.js +6 -3
  89. package/lib/tree/nodes/operators/fractionNode.js +6 -3
  90. package/lib/tree/nodes/operators/multiplyNode.js +33 -3
  91. package/lib/tree/nodes/operators/operatorNode.js +5 -5
  92. package/lib/tree/nodes/operators/powerNode.js +23 -3
  93. package/lib/tree/nodes/operators/substractNode.js +14 -3
  94. package/lib/tree/nodes/variables/variableNode.js +9 -6
  95. package/lib/tree/parsers/derivateParser.js +61 -59
  96. package/lib/tree/parsers/latexParser.js +109 -116
  97. package/lib/tree/parsers/simplify.js +52 -0
  98. package/lib/trigonometry/remarkableValue.js +29 -0
  99. package/lib/trigonometry/remarkableValues.js +51 -0
  100. package/lib/utils/arrayEqual.js +13 -0
  101. package/lib/utils/coinFlip.js +7 -0
  102. package/package.json +1 -1
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Affine = exports.AffineConstructor = void 0;
4
+ const rational_1 = require("../../numbers/rationals/rational");
5
+ const intervals_1 = require("../../sets/intervals/intervals");
6
+ const polynomial_1 = require("./polynomial");
7
+ const discreteSet_1 = require("../../sets/discreteSet");
8
+ const integer_1 = require("../../numbers/integer/integer");
9
+ class AffineConstructor {
10
+ static random(domainA = new intervals_1.Interval('[[-10; 10]]').difference(new discreteSet_1.DiscreteSet([new integer_1.Integer(0)])), domainB = new intervals_1.Interval('[[-10; 10]]')) {
11
+ const a = domainA.getRandomElement();
12
+ const b = domainB.getRandomElement();
13
+ return new Affine(a.value, b.value);
14
+ }
15
+ static differentRandoms(nb, domainA = new intervals_1.Interval('[[-10; 10]]').difference(new discreteSet_1.DiscreteSet([new integer_1.Integer(0)])), domainB = new intervals_1.Interval('[[-10; 10]]')) {
16
+ const res = [];
17
+ for (let i = 0; i < nb; i++) {
18
+ let aff;
19
+ do {
20
+ aff = AffineConstructor.random(domainA, domainB);
21
+ } while (res.some((affine) => affine.equals(aff)));
22
+ res.push(aff);
23
+ }
24
+ return res;
25
+ }
26
+ }
27
+ exports.AffineConstructor = AffineConstructor;
28
+ class Affine extends polynomial_1.Polynomial {
29
+ constructor(a, b, variable = 'x') {
30
+ super([b, a], variable);
31
+ this.a = a;
32
+ this.b = b;
33
+ this.variable = variable;
34
+ }
35
+ getRoot() {
36
+ return new rational_1.Rational(-this.b, this.a).simplify();
37
+ }
38
+ toString() {
39
+ return super.toTex();
40
+ }
41
+ }
42
+ exports.Affine = Affine;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Polynomial = void 0;
4
+ const numberNode_1 = require("../../tree/nodes/numbers/numberNode");
5
+ const addNode_1 = require("../../tree/nodes/operators/addNode");
6
+ const multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
7
+ const oppositeNode_1 = require("../../tree/nodes/functions/oppositeNode");
8
+ const powerNode_1 = require("../../tree/nodes/operators/powerNode");
9
+ const variableNode_1 = require("../../tree/nodes/variables/variableNode");
10
+ class Polynomial {
11
+ /**
12
+ *
13
+ * @param coefficients coefficients[i] est le coeff de x^i
14
+ * @param variable
15
+ */
16
+ constructor(coefficients, variable = 'x') {
17
+ if (coefficients.length === 0)
18
+ throw Error('coeffs must be not null');
19
+ if (coefficients[coefficients.length - 1] === 0) {
20
+ throw Error('n-th coeff must be not null');
21
+ }
22
+ this.coefficients = coefficients;
23
+ this.variable = variable;
24
+ this.degree = coefficients.length - 1;
25
+ }
26
+ equals(P) {
27
+ return P.degree === this.degree && this.coefficients.every((coeff, i) => coeff === P.coefficients[i]);
28
+ }
29
+ getRoots() { }
30
+ add(P) {
31
+ if (P.variable !== this.variable)
32
+ throw Error("Can't add two polynomials with different variables");
33
+ const newDegree = P.degree === this.degree && P.coefficients[P.degree] === -this.coefficients[this.degree]
34
+ ? P.degree - 1
35
+ : Math.max(P.degree, this.degree);
36
+ const res = [];
37
+ for (let i = 0; i < newDegree + 1; i++) {
38
+ res[i] = P.coefficients[i] + this.coefficients[i];
39
+ }
40
+ return new Polynomial(res, this.variable);
41
+ }
42
+ times(nb) {
43
+ return new Polynomial(this.coefficients.map((coeff) => coeff * nb), this.variable);
44
+ }
45
+ multiply(Q) {
46
+ if (Q.variable !== this.variable)
47
+ throw Error("Can't multiply two polynomials with different variables");
48
+ const p = this.degree;
49
+ const q = Q.degree;
50
+ const res = Array.apply(0, new Array(this.degree)).map((i) => 0);
51
+ for (let k = 0; k <= p + q; k++) {
52
+ let sum = 0;
53
+ for (let m = 0; m <= k; m++) {
54
+ sum += (this.coefficients[m] || 0) * (Q.coefficients[k - m] || 0);
55
+ }
56
+ res[k] = sum;
57
+ }
58
+ return new Polynomial(res, this.variable);
59
+ }
60
+ opposite() {
61
+ return new Polynomial(this.coefficients.map((coeff) => -coeff), this.variable);
62
+ }
63
+ toTree() {
64
+ const recursive = (cursor) => {
65
+ const coeff = this.coefficients[cursor];
66
+ if (coeff === 0)
67
+ return recursive(cursor - 1);
68
+ if (cursor === 0) {
69
+ return new numberNode_1.NumberNode(coeff);
70
+ }
71
+ const monome = cursor > 1
72
+ ? new powerNode_1.PowerNode(new variableNode_1.VariableNode(this.variable), new numberNode_1.NumberNode(cursor))
73
+ : new variableNode_1.VariableNode(this.variable);
74
+ let res;
75
+ if (coeff === 1)
76
+ res = monome;
77
+ else if (coeff === -1)
78
+ res = new oppositeNode_1.OppositeNode(monome);
79
+ else
80
+ res = new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(coeff), monome);
81
+ let nextCoeff;
82
+ for (let i = cursor - 1; i > -1; i--) {
83
+ if (this.coefficients[i]) {
84
+ nextCoeff = this.coefficients[i];
85
+ break;
86
+ }
87
+ }
88
+ if (nextCoeff) {
89
+ return new addNode_1.AddNode(res, recursive(cursor - 1));
90
+ }
91
+ else {
92
+ return res;
93
+ }
94
+ };
95
+ return recursive(this.degree);
96
+ }
97
+ toTex() {
98
+ let s = '';
99
+ for (let i = this.degree; i > -1; i--) {
100
+ const coeff = this.coefficients[i];
101
+ if (coeff === 0)
102
+ continue;
103
+ if (i === 0)
104
+ s += coeff > 0 ? `+${coeff}` : coeff;
105
+ else if (i === this.degree) {
106
+ s += coeff === 1 ? '' : coeff === -1 ? '-' : coeff;
107
+ }
108
+ else {
109
+ s += coeff === 1 ? '+' : coeff === -1 ? '-' : coeff > 0 ? `+${coeff}` : coeff;
110
+ }
111
+ //x^n
112
+ if (i === 0)
113
+ continue;
114
+ if (i === 1)
115
+ s += this.variable;
116
+ else
117
+ s += `${this.variable}^{${i}}`;
118
+ }
119
+ return s;
120
+ }
121
+ toString() {
122
+ return this.toTex();
123
+ }
124
+ }
125
+ exports.Polynomial = Polynomial;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometricSequenceConstructor = void 0;
4
+ class GeometricSequenceConstructor {
5
+ static random() {
6
+ }
7
+ }
8
+ exports.GeometricSequenceConstructor = GeometricSequenceConstructor;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sequence = void 0;
4
+ var SequenceType;
5
+ (function (SequenceType) {
6
+ SequenceType[SequenceType["arithmetic"] = 0] = "arithmetic";
7
+ SequenceType[SequenceType["geometric"] = 1] = "geometric";
8
+ })(SequenceType || (SequenceType = {}));
9
+ class Sequence {
10
+ constructor(type, firstTerm, reason) {
11
+ this.type = type;
12
+ this.firstTerm = firstTerm;
13
+ this.reason = reason;
14
+ this.
15
+ ;
16
+ }
17
+ }
18
+ exports.Sequence = Sequence;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiscreteSet = void 0;
4
+ const random_1 = require("../utils/random");
5
+ class DiscreteSet {
6
+ constructor(elements) {
7
+ this.elements = Array.from(new Set(elements));
8
+ let tex = "\\{";
9
+ this.elements.forEach((el, index) => {
10
+ tex += el.tex;
11
+ if (index < this.elements.length - 1)
12
+ tex += ";";
13
+ else
14
+ tex += "\\}";
15
+ });
16
+ this.tex = tex;
17
+ }
18
+ toTex() {
19
+ return this.tex;
20
+ }
21
+ includes(el) {
22
+ return this.elements.some((nb) => nb.value === el.value && nb.tex === el.tex);
23
+ }
24
+ getRandomElement() {
25
+ return (0, random_1.random)(this.elements);
26
+ }
27
+ }
28
+ exports.DiscreteSet = DiscreteSet;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ // import { MathSetInterface } from "./mathSetInterface";
3
+ // export abstract class EmptySet implements MathSetInterface {
4
+ // tex: string = "\\emptyset";
5
+ // getRandomElement = () => null;
6
+ // }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Interval = void 0;
4
+ const epsilon_1 = require("../../numbers/epsilon");
5
+ const nombre_1 = require("../../numbers/nombre");
6
+ const round_1 = require("../../mathutils/round");
7
+ const mathSet_1 = require("../mathSet");
8
+ const integer_1 = require("../../numbers/integer/integer");
9
+ const real_1 = require("../../numbers/reals/real");
10
+ var BoundType;
11
+ (function (BoundType) {
12
+ BoundType["OO"] = "]a;b[";
13
+ BoundType["OF"] = "]a;b]";
14
+ BoundType["FO"] = "[a;b[";
15
+ BoundType["FF"] = "[a;b]";
16
+ })(BoundType || (BoundType = {}));
17
+ class Interval {
18
+ /**
19
+ * [[a; b]] pour un interval d'integer; [a;b] pour des réels
20
+ */
21
+ constructor(tex = '[-10; 10]') {
22
+ if (!tex.includes(';'))
23
+ throw Error('wrong interval format');
24
+ this.tex = tex;
25
+ const isInt = tex[1] === '[' || tex[1] === ']';
26
+ this.type = isInt ? nombre_1.NumberType.Integer : nombre_1.NumberType.Real;
27
+ const left = tex[0];
28
+ const right = tex[tex.length - 1];
29
+ const [a, b] = tex.slice(isInt ? 2 : 1, isInt ? tex.length - 2 : tex.length - 1).split(';');
30
+ switch (`${left}a;b${right}`) {
31
+ case '[a;b]':
32
+ this.boundType = BoundType.FF;
33
+ break;
34
+ case ']a;b[':
35
+ this.boundType = BoundType.OO;
36
+ break;
37
+ case '[a;b[':
38
+ this.boundType = BoundType.FO;
39
+ break;
40
+ case ']a;b]':
41
+ this.boundType = BoundType.OF;
42
+ break;
43
+ default:
44
+ throw console.error('wrong interval format');
45
+ }
46
+ function getBound(bound) {
47
+ return bound === '-\\infty'
48
+ ? Number.NEGATIVE_INFINITY
49
+ : bound === '+\\infty'
50
+ ? Number.POSITIVE_INFINITY
51
+ : Number(bound);
52
+ }
53
+ this.min = getBound(a);
54
+ this.max = getBound(b);
55
+ }
56
+ // union(interval: Interval): MathSet {
57
+ //[a,b] [c,d]
58
+ //si a=c return a, max(b,d)
59
+ //si si b = d return min(a,c), b
60
+ //si a=d return c,b sauf si OXXO
61
+ //si b=c return a,d sauf si XOOX
62
+ //si c > b ou d < a alors union disjointe avec plus petit en 1er
63
+ //sinon return min(a,c), max(b,d)
64
+ //res = a
65
+ // return new MathSet();
66
+ // }
67
+ exclude(nb) {
68
+ const rand = () => {
69
+ let x;
70
+ do {
71
+ x = this.getRandomElement();
72
+ } while (x.value === nb);
73
+ return x;
74
+ };
75
+ return new mathSet_1.MathSet(this.toTex() + `\\{${nb}\\}`, rand);
76
+ }
77
+ difference(set) {
78
+ const rand = () => {
79
+ let x;
80
+ do {
81
+ x = this.getRandomElement();
82
+ } while (set.includes(x));
83
+ return x;
84
+ };
85
+ return new mathSet_1.MathSet(this.toTex() + `\\ ${set.toTex()}`, rand);
86
+ }
87
+ toTex() {
88
+ return this.tex;
89
+ }
90
+ getRandomElement(precision = this.type === nombre_1.NumberType.Integer ? 0 : 2) {
91
+ if (this.min === -Infinity || this.max === Infinity)
92
+ throw Error("Can't chose amongst infinity");
93
+ let min = this.boundType === BoundType.OO || this.boundType === BoundType.OF ? this.min + epsilon_1.EPSILON : this.min;
94
+ let max = this.boundType === BoundType.OO || this.boundType === BoundType.FO ? this.max - epsilon_1.EPSILON : this.max;
95
+ const value = (0, round_1.round)(min + Math.random() * (max - this.min), precision);
96
+ switch (this.type) {
97
+ case nombre_1.NumberType.Integer:
98
+ return new integer_1.Integer(value);
99
+ default:
100
+ return new real_1.Real(value, value.toString());
101
+ }
102
+ }
103
+ }
104
+ exports.Interval = Interval;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MathSet = void 0;
4
+ class MathSet {
5
+ constructor(tex, getRandomElement) {
6
+ this.tex = tex;
7
+ this.getRandomElement = getRandomElement;
8
+ }
9
+ }
10
+ exports.MathSet = MathSet;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemarkableValueConstructor = void 0;
4
+ const randint_1 = require("../mathutils/random/randint");
5
+ const numberNode_1 = require("../tree/nodes/numbers/numberNode");
6
+ const piNode_1 = require("../tree/nodes/numbers/piNode");
7
+ const addNode_1 = require("../tree/nodes/operators/addNode");
8
+ const multiplyNode_1 = require("../tree/nodes/operators/multiplyNode");
9
+ const simplify_1 = require("../tree/parsers/simplify");
10
+ const random_1 = require("../utils/random");
11
+ const remarkableValues_1 = require("./remarkableValues");
12
+ class RemarkableValueConstructor {
13
+ }
14
+ exports.RemarkableValueConstructor = RemarkableValueConstructor;
15
+ RemarkableValueConstructor.mainInterval = () => {
16
+ const randValue = (0, random_1.random)(remarkableValues_1.remarkableTrigoValues);
17
+ return randValue;
18
+ // return new RemarkableValue(randValue.angle, randValue.cos, randValue.sin);
19
+ };
20
+ RemarkableValueConstructor.simplifiable = () => {
21
+ const randValue = (0, random_1.random)(remarkableValues_1.remarkableTrigoValues);
22
+ const toAdd = new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode((0, randint_1.randint)(-3, 4) * 2), piNode_1.PiNode);
23
+ const newAngle = (0, simplify_1.simplifyNode)(new addNode_1.AddNode(randValue.angle, toAdd));
24
+ return {
25
+ angle: newAngle,
26
+ cos: randValue.cos,
27
+ sin: randValue.sin,
28
+ };
29
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remarkableTrigoValues = void 0;
4
+ const oppositeNode_1 = require("../tree/nodes/functions/oppositeNode");
5
+ const sqrtNode_1 = require("../tree/nodes/functions/sqrtNode");
6
+ const numberNode_1 = require("../tree/nodes/numbers/numberNode");
7
+ const piNode_1 = require("../tree/nodes/numbers/piNode");
8
+ const fractionNode_1 = require("../tree/nodes/operators/fractionNode");
9
+ const multiplyNode_1 = require("../tree/nodes/operators/multiplyNode");
10
+ exports.remarkableTrigoValues = [
11
+ {
12
+ angle: new numberNode_1.NumberNode(0),
13
+ cos: new numberNode_1.NumberNode(1),
14
+ sin: new numberNode_1.NumberNode(0),
15
+ },
16
+ {
17
+ angle: new fractionNode_1.FractionNode(piNode_1.PiNode, new numberNode_1.NumberNode(6)),
18
+ cos: new fractionNode_1.FractionNode(new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(3)), new numberNode_1.NumberNode(2)),
19
+ sin: new fractionNode_1.FractionNode(new numberNode_1.NumberNode(1), new numberNode_1.NumberNode(2)),
20
+ },
21
+ {
22
+ angle: new fractionNode_1.FractionNode(piNode_1.PiNode, new numberNode_1.NumberNode(4)),
23
+ cos: new fractionNode_1.FractionNode(new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(2)), new numberNode_1.NumberNode(2)),
24
+ sin: new fractionNode_1.FractionNode(new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(2)), new numberNode_1.NumberNode(2)),
25
+ },
26
+ {
27
+ angle: new fractionNode_1.FractionNode(piNode_1.PiNode, new numberNode_1.NumberNode(3)),
28
+ cos: new fractionNode_1.FractionNode(new numberNode_1.NumberNode(1), new numberNode_1.NumberNode(2)),
29
+ sin: new fractionNode_1.FractionNode(new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(3)), new numberNode_1.NumberNode(2)),
30
+ },
31
+ {
32
+ angle: new fractionNode_1.FractionNode(piNode_1.PiNode, new numberNode_1.NumberNode(2)),
33
+ cos: new numberNode_1.NumberNode(0),
34
+ sin: new numberNode_1.NumberNode(1),
35
+ },
36
+ {
37
+ angle: new fractionNode_1.FractionNode(new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(2), piNode_1.PiNode), new numberNode_1.NumberNode(3)),
38
+ cos: new oppositeNode_1.OppositeNode(new fractionNode_1.FractionNode(new numberNode_1.NumberNode(1), new numberNode_1.NumberNode(2))),
39
+ sin: new fractionNode_1.FractionNode(new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(3)), new numberNode_1.NumberNode(2)),
40
+ },
41
+ {
42
+ angle: new fractionNode_1.FractionNode(new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(3), piNode_1.PiNode), new numberNode_1.NumberNode(4)),
43
+ cos: new oppositeNode_1.OppositeNode(new fractionNode_1.FractionNode(new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(2)), new numberNode_1.NumberNode(2))),
44
+ sin: new fractionNode_1.FractionNode(new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(2)), new numberNode_1.NumberNode(2)),
45
+ },
46
+ {
47
+ angle: piNode_1.PiNode,
48
+ cos: new numberNode_1.NumberNode(-1),
49
+ sin: new numberNode_1.NumberNode(0),
50
+ },
51
+ ];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coprimesOf = void 0;
4
+ const gcd_1 = require("./gcd");
5
+ const coprimesOf = (nb) => {
6
+ let coprimes = [];
7
+ for (let i = 2; i <= nb; i++) {
8
+ if ((0, gcd_1.gcd)(nb, i) === 1)
9
+ coprimes.push(i);
10
+ }
11
+ return coprimes;
12
+ };
13
+ exports.coprimesOf = coprimesOf;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dividersOf = void 0;
4
+ const dividersOf = (nb) => {
5
+ let divisors = [];
6
+ for (let i = 1; i <= nb; i++) {
7
+ if (nb % i === 0)
8
+ divisors.push(i);
9
+ }
10
+ return divisors;
11
+ };
12
+ exports.dividersOf = dividersOf;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gcd = void 0;
4
+ function gcd(a, b) {
5
+ return b ? gcd(b, a % b) : a;
6
+ }
7
+ exports.gcd = gcd;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSquare = void 0;
4
+ const isSquare = (a) => {
5
+ return a > 0 && Math.sqrt(a) % 1 === 0;
6
+ };
7
+ exports.isSquare = isSquare;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lcd = void 0;
4
+ function lcd(a, b) {
5
+ const max = Math.max(a, b);
6
+ for (let i = max; i < a * b; i++) {
7
+ if (i % a === 0 && i % b === 0)
8
+ return i;
9
+ }
10
+ return a * b;
11
+ }
12
+ exports.lcd = lcd;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonCoprimesOf = void 0;
4
+ const gcd_1 = require("./gcd");
5
+ const nonCoprimesOf = (nb) => {
6
+ let nonCoprimes = [];
7
+ for (let i = 1; i <= nb; i++) {
8
+ if ((0, gcd_1.gcd)(nb, i) !== 1)
9
+ nonCoprimes.push(i);
10
+ }
11
+ return nonCoprimes;
12
+ };
13
+ exports.nonCoprimesOf = nonCoprimesOf;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonDivisorOf = void 0;
4
+ const dividersOf_1 = require("./dividersOf");
5
+ const nonDivisorOf = (nb) => {
6
+ let nonDividers = [];
7
+ let dividers = (0, dividersOf_1.dividersOf)(nb);
8
+ for (let i = 2; i < nb; i++) {
9
+ if (nb % i !== 0)
10
+ nonDividers.push(i);
11
+ }
12
+ return nonDividers;
13
+ };
14
+ exports.nonDivisorOf = nonDivisorOf;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.primeFactors = void 0;
4
+ /***
5
+ * returns array of prime factors
6
+ * e.g 12 -> [2, 2, 3]
7
+ */
8
+ const primeFactors = (a) => {
9
+ const factors = [];
10
+ let divisor = 2;
11
+ while (a >= 2) {
12
+ if (a % divisor === 0) {
13
+ factors.push(divisor);
14
+ a = a / divisor;
15
+ }
16
+ else {
17
+ divisor++;
18
+ }
19
+ }
20
+ return factors;
21
+ };
22
+ exports.primeFactors = primeFactors;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decimalPartLengthOf = void 0;
4
+ const decimalPartLengthOf = (x) => {
5
+ function hasFraction(x) {
6
+ return Math.abs(Math.round(x) - x) > 1e-10;
7
+ }
8
+ let count = 0;
9
+ // multiply by increasing powers of 10 until the fractional part is ~ 0
10
+ while (hasFraction(x * 10 ** count) && isFinite(10 ** count))
11
+ count++;
12
+ return count;
13
+ };
14
+ exports.decimalPartLengthOf = decimalPartLengthOf;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.distinctRandTupleInt = exports.randTupleInt = void 0;
4
+ const arrayEqual_1 = require("../../utils/arrayEqual");
5
+ const randint_1 = require("./randint");
6
+ /**
7
+ * @param size tuple length
8
+ * @param options
9
+ * @returns array of size nb with contents = randint(from, to, exxcludes)
10
+ */
11
+ const randTupleInt = (size, options) => {
12
+ const res = [];
13
+ for (let i = 0; i < size; i++) {
14
+ res.push((0, randint_1.randint)(options.from, options.to, options.excludes));
15
+ }
16
+ return res;
17
+ };
18
+ exports.randTupleInt = randTupleInt;
19
+ const distinctRandTupleInt = (nb, size, options) => {
20
+ const res = [];
21
+ for (let i = 0; i < nb; i++) {
22
+ let newTuple;
23
+ do {
24
+ newTuple = (0, exports.randTupleInt)(size, options);
25
+ } while (res.some(tuple => (0, arrayEqual_1.arrayEqual)(tuple, newTuple)));
26
+ res.push(newTuple);
27
+ }
28
+ return res;
29
+ };
30
+ exports.distinctRandTupleInt = distinctRandTupleInt;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randint = void 0;
4
+ /**
5
+ * @returns random [[a, b[[
6
+ */
7
+ const randint = (a, b, excludes) => {
8
+ if (b === undefined)
9
+ return Math.floor(Math.random() * a);
10
+ if (!excludes)
11
+ return a + Math.floor(Math.random() * (b - a));
12
+ let res;
13
+ do {
14
+ res = a + Math.floor(Math.random() * (b - a));
15
+ } while (excludes.includes(res));
16
+ return res;
17
+ };
18
+ exports.randint = randint;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.round = void 0;
4
+ const epsilon_1 = require("../numbers/epsilon");
5
+ function round(x, precision) {
6
+ return Math.round((x + epsilon_1.EPSILON) * Math.pow(10, precision)) / Math.pow(10, precision);
7
+ }
8
+ exports.round = round;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.distinctRandTupleInt = exports.randTupleInt = void 0;
4
+ const arrayEqual_1 = require("../../utils/arrayEqual");
5
+ const randint_1 = require("./randint");
6
+ /**
7
+ * @param size tuple length
8
+ * @param options
9
+ * @returns array of size nb with contents = randint(from, to, exxcludes)
10
+ */
11
+ const randTupleInt = (size, options) => {
12
+ const res = [];
13
+ for (let i = 0; i < size; i++) {
14
+ res.push((0, randint_1.randint)(options.from, options.to, options.excludes));
15
+ }
16
+ return res;
17
+ };
18
+ exports.randTupleInt = randTupleInt;
19
+ const distinctRandTupleInt = (nb, size, options) => {
20
+ const res = [];
21
+ for (let i = 0; i < nb; i++) {
22
+ let newTuple;
23
+ do {
24
+ newTuple = (0, exports.randTupleInt)(size, options);
25
+ } while (res.some(tuple => (0, arrayEqual_1.arrayEqual)(tuple, newTuple)));
26
+ res.push(newTuple);
27
+ }
28
+ return res;
29
+ };
30
+ exports.distinctRandTupleInt = distinctRandTupleInt;