math-exercises 1.2.8 → 1.2.10

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 (216) hide show
  1. package/lib/exercises/calcul/addAndSub.js +40 -0
  2. package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -0
  3. package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +31 -0
  4. package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -0
  5. package/lib/exercises/calcul/fractions/fractionsDivision.js +29 -0
  6. package/lib/exercises/calcul/fractions/fractionsProduct.js +29 -0
  7. package/lib/exercises/calcul/fractions/fractionsSum.js +29 -0
  8. package/lib/exercises/calcul/fractions/simplifyFraction.js +25 -0
  9. package/lib/exercises/calcul/operations/operationsPriorities.js +88 -0
  10. package/lib/exercises/calcul/operations/operationsPrioritiesWithoutRelative.js +111 -0
  11. package/{src → lib}/exercises/calcul/operationsPriorities.js +88 -89
  12. package/{src → lib}/exercises/calcul/rounding/rounding.js +86 -87
  13. package/{src → lib}/exercises/calculLitteral/distributivity/allIdentities.js +27 -27
  14. package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +31 -0
  15. package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +32 -0
  16. package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +33 -0
  17. package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +33 -0
  18. package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +32 -0
  19. package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +38 -0
  20. package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +41 -0
  21. package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +42 -0
  22. package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +44 -0
  23. package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +39 -0
  24. package/{src → lib}/exercises/exercise.js +7 -7
  25. package/lib/exercises/exercises.js +95 -0
  26. package/lib/exercises/geometry/cartesian/midpoint.js +29 -0
  27. package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +29 -0
  28. package/lib/exercises/geometry/vectors/scalarProductViaNorms.js +27 -0
  29. package/lib/exercises/powers/powersDivision.js +45 -0
  30. package/lib/exercises/powers/powersOfTenToDecimal.js +33 -0
  31. package/lib/exercises/powers/powersPower.js +44 -0
  32. package/lib/exercises/powers/powersProduct.js +45 -0
  33. package/lib/exercises/powers/scientificToDecimal.js +38 -0
  34. package/{src → lib}/exercises/squareRoots/simpifySquareRoot.js +28 -28
  35. package/lib/exercises/utils/getDistinctQuestions.js +16 -0
  36. package/lib/geometry/point.js +27 -0
  37. package/lib/geometry/vector.js +31 -0
  38. package/lib/index.js +10 -0
  39. package/lib/mathutils/arithmetic/coprimesOf.js +13 -0
  40. package/lib/mathutils/arithmetic/dividersOf.js +12 -0
  41. package/{src → lib}/mathutils/arithmetic/gcd.js +7 -7
  42. package/{src → lib}/mathutils/arithmetic/isSquare.js +7 -7
  43. package/{src → lib}/mathutils/arithmetic/lcd.js +12 -12
  44. package/lib/mathutils/arithmetic/nonCoprimesOf.js +13 -0
  45. package/lib/mathutils/arithmetic/nonDividersOf.js +14 -0
  46. package/{src → lib}/mathutils/arithmetic/primeFactors.js +22 -22
  47. package/lib/mathutils/decimals/decimalPartLengthOf.js +14 -0
  48. package/lib/mathutils/random/randTupleInt.js +30 -0
  49. package/{src → lib}/mathutils/random/randint.js +18 -18
  50. package/{src → lib}/mathutils/round.js +8 -8
  51. package/{src → lib}/numbers/decimals/decimal.js +140 -144
  52. package/{src → lib}/numbers/epsilon.js +10 -10
  53. package/{src → lib}/numbers/integer/integer.js +68 -72
  54. package/{src → lib}/numbers/integer/power.js +52 -53
  55. package/{src → lib}/numbers/nombre.js +10 -10
  56. package/lib/numbers/rationals/rational.js +113 -0
  57. package/lib/numbers/reals/real.js +16 -0
  58. package/lib/numbers/reals/squareRoot.js +63 -0
  59. package/lib/polynomials/affine.js +42 -0
  60. package/lib/polynomials/polynomial.js +125 -0
  61. package/lib/sets/discreteSet.js +28 -0
  62. package/{src/sets/emptySet.ts → lib/sets/emptySet.js} +6 -6
  63. package/{src → lib}/sets/intervals/intervals.js +108 -113
  64. package/lib/sets/intervals/union.js +1 -0
  65. package/lib/sets/mathSet.js +10 -0
  66. package/lib/sets/mathSetInterface.js +2 -0
  67. package/{src → lib}/tree/nodes/functions/functionNode.js +18 -19
  68. package/lib/tree/nodes/functions/oppositeNode.js +13 -0
  69. package/lib/tree/nodes/functions/sqrtNode.js +15 -0
  70. package/{src → lib}/tree/nodes/node.js +10 -10
  71. package/lib/tree/nodes/numbers/numberNode.js +18 -0
  72. package/lib/tree/nodes/operators/addNode.js +15 -0
  73. package/lib/tree/nodes/operators/divideNode.js +17 -0
  74. package/lib/tree/nodes/operators/equalNode.js +13 -0
  75. package/lib/tree/nodes/operators/fractionNode.js +17 -0
  76. package/lib/tree/nodes/operators/multiplyNode.js +13 -0
  77. package/{src → lib}/tree/nodes/operators/operatorNode.js +35 -37
  78. package/lib/tree/nodes/operators/powerNode.js +13 -0
  79. package/lib/tree/nodes/operators/substractNode.js +13 -0
  80. package/lib/tree/nodes/variables/variableNode.js +16 -0
  81. package/{src → lib}/tree/parsers/derivateParser.js +60 -60
  82. package/{src → lib}/tree/parsers/latexParser.js +117 -117
  83. package/lib/utils/arrayEqual.js +13 -0
  84. package/{src → lib}/utils/coin.js +7 -7
  85. package/{src → lib}/utils/random.js +7 -7
  86. package/lib/utils/shuffle.js +15 -0
  87. package/package.json +35 -28
  88. package/nodemon.json +0 -5
  89. package/src/exercises/calcul/addAndSub.js +0 -40
  90. package/src/exercises/calcul/addAndSub.ts +0 -39
  91. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.js +0 -35
  92. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.ts +0 -36
  93. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.js +0 -31
  94. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.ts +0 -32
  95. package/src/exercises/calcul/fractions/fractionAndIntegerSum.js +0 -32
  96. package/src/exercises/calcul/fractions/fractionAndIntegerSum.ts +0 -31
  97. package/src/exercises/calcul/fractions/fractionsDivision.js +0 -29
  98. package/src/exercises/calcul/fractions/fractionsDivision.ts +0 -30
  99. package/src/exercises/calcul/fractions/fractionsProduct.js +0 -29
  100. package/src/exercises/calcul/fractions/fractionsProduct.ts +0 -29
  101. package/src/exercises/calcul/fractions/fractionsSum.js +0 -29
  102. package/src/exercises/calcul/fractions/fractionsSum.ts +0 -28
  103. package/src/exercises/calcul/fractions/simplifyFraction.js +0 -25
  104. package/src/exercises/calcul/fractions/simplifyFraction.ts +0 -24
  105. package/src/exercises/calcul/operationsPriorities.ts +0 -115
  106. package/src/exercises/calcul/rounding/rounding.ts +0 -87
  107. package/src/exercises/calculLitteral/distributivity/allIdentities.ts +0 -26
  108. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.js +0 -31
  109. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.ts +0 -33
  110. package/src/exercises/calculLitteral/distributivity/firstIdentity.js +0 -32
  111. package/src/exercises/calculLitteral/distributivity/firstIdentity.ts +0 -33
  112. package/src/exercises/calculLitteral/distributivity/secondIdentity.js +0 -33
  113. package/src/exercises/calculLitteral/distributivity/secondIdentity.ts +0 -35
  114. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.js +0 -33
  115. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.ts +0 -33
  116. package/src/exercises/calculLitteral/distributivity/thirdIdentity.js +0 -32
  117. package/src/exercises/calculLitteral/distributivity/thirdIdentity.ts +0 -34
  118. package/src/exercises/calculLitteral/equation/equationType1Exercise.js +0 -38
  119. package/src/exercises/calculLitteral/equation/equationType1Exercise.ts +0 -38
  120. package/src/exercises/calculLitteral/equation/equationType2Exercise.js +0 -41
  121. package/src/exercises/calculLitteral/equation/equationType2Exercise.ts +0 -41
  122. package/src/exercises/calculLitteral/equation/equationType3Exercise.js +0 -42
  123. package/src/exercises/calculLitteral/equation/equationType3Exercise.ts +0 -43
  124. package/src/exercises/calculLitteral/equation/equationType4Exercise.js +0 -44
  125. package/src/exercises/calculLitteral/equation/equationType4Exercise.ts +0 -46
  126. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.js +0 -39
  127. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.ts +0 -54
  128. package/src/exercises/exercise.ts +0 -22
  129. package/src/exercises/exercises.js +0 -85
  130. package/src/exercises/exercises.ts +0 -94
  131. package/src/exercises/powers/powersDivision.js +0 -46
  132. package/src/exercises/powers/powersDivision.ts +0 -51
  133. package/src/exercises/powers/powersOfTenToDecimal.js +0 -33
  134. package/src/exercises/powers/powersOfTenToDecimal.ts +0 -37
  135. package/src/exercises/powers/powersPower.js +0 -45
  136. package/src/exercises/powers/powersPower.ts +0 -55
  137. package/src/exercises/powers/powersProduct.js +0 -46
  138. package/src/exercises/powers/powersProduct.ts +0 -51
  139. package/src/exercises/powers/scientificToDecimal.js +0 -38
  140. package/src/exercises/powers/scientificToDecimal.ts +0 -44
  141. package/src/exercises/squareRoots/simpifySquareRoot.ts +0 -27
  142. package/src/exercises/utils/getDistinctQuestions.js +0 -18
  143. package/src/exercises/utils/getDistinctQuestions.ts +0 -14
  144. package/src/index.js +0 -5
  145. package/src/index.ts +0 -13
  146. package/src/mathutils/arithmetic/coprimesOf.js +0 -13
  147. package/src/mathutils/arithmetic/coprimesOf.ts +0 -9
  148. package/src/mathutils/arithmetic/dividersOf.ts +0 -7
  149. package/src/mathutils/arithmetic/gcd.ts +0 -3
  150. package/src/mathutils/arithmetic/isSquare.ts +0 -3
  151. package/src/mathutils/arithmetic/lcd.ts +0 -7
  152. package/src/mathutils/arithmetic/nonCoprimesOf.ts +0 -9
  153. package/src/mathutils/arithmetic/nonDividersOf.ts +0 -12
  154. package/src/mathutils/arithmetic/primeFactors.ts +0 -18
  155. package/src/mathutils/decimals/decimalPartLengthOf.ts +0 -10
  156. package/src/mathutils/random/randint.ts +0 -12
  157. package/src/mathutils/round.ts +0 -5
  158. package/src/numbers/decimals/decimal.ts +0 -140
  159. package/src/numbers/epsilon.ts +0 -7
  160. package/src/numbers/integer/integer.ts +0 -72
  161. package/src/numbers/integer/power.ts +0 -49
  162. package/src/numbers/nombre.ts +0 -15
  163. package/src/numbers/number.js +0 -8
  164. package/src/numbers/rationals/rational.js +0 -128
  165. package/src/numbers/rationals/rational.ts +0 -122
  166. package/src/numbers/reals/real.js +0 -17
  167. package/src/numbers/reals/real.ts +0 -17
  168. package/src/numbers/reals/squareRoot.js +0 -85
  169. package/src/numbers/reals/squareRoot.ts +0 -70
  170. package/src/polynomials/affine.js +0 -71
  171. package/src/polynomials/affine.ts +0 -60
  172. package/src/polynomials/polynomial.js +0 -128
  173. package/src/polynomials/polynomial.ts +0 -137
  174. package/src/sets/discreteSet.js +0 -30
  175. package/src/sets/discreteSet.ts +0 -30
  176. package/src/sets/intervals/intervals.ts +0 -122
  177. package/src/sets/intervals/union.ts +0 -0
  178. package/src/sets/mathSet.js +0 -11
  179. package/src/sets/mathSet.ts +0 -12
  180. package/src/sets/mathSetInterface.js +0 -2
  181. package/src/sets/mathSetInterface.ts +0 -10
  182. package/src/tree/latexParser/latexParse.js +0 -117
  183. package/src/tree/nodes/functions/functionNode.ts +0 -18
  184. package/src/tree/nodes/functions/oppositeNode.js +0 -30
  185. package/src/tree/nodes/functions/oppositeNode.ts +0 -12
  186. package/src/tree/nodes/functions/sqrtNode.js +0 -33
  187. package/src/tree/nodes/functions/sqrtNode.ts +0 -12
  188. package/src/tree/nodes/node.ts +0 -12
  189. package/src/tree/nodes/numbers/numberNode.js +0 -16
  190. package/src/tree/nodes/numbers/numberNode.ts +0 -16
  191. package/src/tree/nodes/operators/addNode.js +0 -33
  192. package/src/tree/nodes/operators/addNode.ts +0 -13
  193. package/src/tree/nodes/operators/divideNode.js +0 -34
  194. package/src/tree/nodes/operators/divideNode.ts +0 -16
  195. package/src/tree/nodes/operators/equalNode.js +0 -30
  196. package/src/tree/nodes/operators/equalNode.ts +0 -11
  197. package/src/tree/nodes/operators/fractionNode.js +0 -34
  198. package/src/tree/nodes/operators/fractionNode.ts +0 -16
  199. package/src/tree/nodes/operators/multiplyNode.js +0 -30
  200. package/src/tree/nodes/operators/multiplyNode.ts +0 -12
  201. package/src/tree/nodes/operators/operatorNode.ts +0 -36
  202. package/src/tree/nodes/operators/oppositeNode.js +0 -18
  203. package/src/tree/nodes/operators/powerNode.js +0 -30
  204. package/src/tree/nodes/operators/powerNode.ts +0 -12
  205. package/src/tree/nodes/operators/substractNode.js +0 -30
  206. package/src/tree/nodes/operators/substractNode.ts +0 -11
  207. package/src/tree/nodes/variables/variableNode.js +0 -17
  208. package/src/tree/nodes/variables/variableNode.ts +0 -15
  209. package/src/tree/parsers/derivateParser.ts +0 -66
  210. package/src/tree/parsers/latexParser.ts +0 -122
  211. package/src/utils/coin.ts +0 -3
  212. package/src/utils/random.ts +0 -3
  213. package/src/utils/randomIn.js +0 -7
  214. package/src/utils/shuffle.js +0 -24
  215. package/src/utils/shuffle.ts +0 -11
  216. package/tsconfig.json +0 -110
@@ -1,128 +0,0 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- exports.__esModule = true;
12
- exports.Rational = exports.RationalConstructor = void 0;
13
- var coprimesOf_1 = require("../../mathutils/arithmetic/coprimesOf");
14
- var gcd_1 = require("../../mathutils/arithmetic/gcd");
15
- var lcd_1 = require("../../mathutils/arithmetic/lcd");
16
- var randint_1 = require("../../mathutils/random/randint");
17
- var numberNode_1 = require("../../tree/nodes/numbers/numberNode");
18
- var fractionNode_1 = require("../../tree/nodes/operators/fractionNode");
19
- var random_1 = require("../../utils/random");
20
- var shuffle_1 = require("../../utils/shuffle");
21
- var integer_1 = require("../integer/integer");
22
- var nombre_1 = require("../nombre");
23
- var RationalConstructor = /** @class */ (function () {
24
- function RationalConstructor() {
25
- }
26
- /**
27
- * @param maxGcd max number by which the fraction is simplifiable
28
- */
29
- RationalConstructor.randomSimplifiable = function (maxGcd) {
30
- if (maxGcd === void 0) { maxGcd = 10; }
31
- var gcd = (0, randint_1.randint)(2, maxGcd);
32
- var max = (0, randint_1.randint)(3, 11);
33
- var min = (0, random_1.random)((0, coprimesOf_1.coprimesOf)(max));
34
- var _a = (0, shuffle_1.shuffle)([gcd * min, gcd * max]), num = _a[0], denum = _a[1];
35
- if (denum === gcd) {
36
- //si 10/2 on transforme en 2/10
37
- return new Rational(denum, num);
38
- }
39
- return new Rational(num, denum);
40
- };
41
- RationalConstructor.randomIrreductible = function (max) {
42
- if (max === void 0) { max = 11; }
43
- var a = (0, randint_1.randint)(2, max);
44
- var b = (0, random_1.random)(__spreadArray(__spreadArray([], (0, coprimesOf_1.coprimesOf)(a), true), [1], false));
45
- if (b === 1)
46
- return new Rational(b, a);
47
- var _a = (0, shuffle_1.shuffle)([a, b]), num = _a[0], denum = _a[1];
48
- return new Rational(num, denum);
49
- };
50
- return RationalConstructor;
51
- }());
52
- exports.RationalConstructor = RationalConstructor;
53
- var Rational = /** @class */ (function () {
54
- function Rational(numerator, denumerator) {
55
- if (denumerator === 0)
56
- throw Error("division by zero");
57
- this.num = numerator;
58
- this.denum = denumerator;
59
- this.value = numerator / denumerator;
60
- this.isSimplified = Math.abs((0, gcd_1.gcd)(numerator, denumerator)) === 1;
61
- this.tex = "\\frac{".concat(this.num, "}{").concat(this.denum, "}");
62
- this.type = nombre_1.NumberType.Rational;
63
- }
64
- Rational.prototype.toTex = function () {
65
- return "\\frac{".concat(this.num, "}{").concat(this.denum, "}");
66
- };
67
- Rational.prototype.add = function (nb) {
68
- switch (nb.type) {
69
- case nombre_1.NumberType.Integer: {
70
- var num = this.num + this.denum * nb.value;
71
- return new Rational(num, this.denum).simplify();
72
- }
73
- case nombre_1.NumberType.Rational: {
74
- var rational = nb;
75
- var ppcm = (0, lcd_1.lcd)(rational.denum, this.denum);
76
- var num = this.num * (ppcm / this.denum) + rational.num * (ppcm / rational.denum);
77
- return new Rational(num, ppcm).simplify();
78
- }
79
- }
80
- throw Error("not implemented yet");
81
- };
82
- Rational.prototype.multiply = function (nb) {
83
- switch (nb.type) {
84
- case nombre_1.NumberType.Integer: {
85
- var num = this.num * nb.value;
86
- var denum = this.denum;
87
- return new Rational(num, denum).simplify();
88
- }
89
- case nombre_1.NumberType.Rational: {
90
- var rational = nb;
91
- var num = this.num * rational.num;
92
- var denum = this.denum * rational.denum;
93
- return new Rational(num, denum).simplify();
94
- }
95
- }
96
- throw Error("not implemented yet");
97
- };
98
- Rational.prototype.divide = function (nb) {
99
- switch (nb.type) {
100
- case nombre_1.NumberType.Integer: {
101
- var denum = this.denum * nb.value;
102
- return new Rational(this.num, denum).simplify();
103
- }
104
- case nombre_1.NumberType.Rational: {
105
- var rational = nb;
106
- var num = this.num * rational.denum;
107
- var denum = this.denum * rational.num;
108
- return new Rational(num, denum).simplify();
109
- }
110
- }
111
- throw Error("not implemented yet");
112
- };
113
- Rational.prototype.opposite = function () {
114
- return new Rational(-this.num, this.denum);
115
- };
116
- Rational.prototype.toTree = function () {
117
- return new fractionNode_1.FractionNode(new numberNode_1.NumberNode(this.num), new numberNode_1.NumberNode(this.denum));
118
- };
119
- Rational.prototype.simplify = function () {
120
- var sign = (this.num > 0 && this.denum > 0) || (this.num < 0 && this.denum < 0) ? 1 : -1;
121
- var div = Math.abs((0, gcd_1.gcd)(this.num, this.denum));
122
- if (Math.abs(this.denum) === div)
123
- return new integer_1.Integer(this.num / this.denum);
124
- return new Rational((sign * Math.abs(this.num)) / div, Math.abs(this.denum) / div);
125
- };
126
- return Rational;
127
- }());
128
- exports.Rational = Rational;
@@ -1,122 +0,0 @@
1
- import { coprimesOf } from "../../mathutils/arithmetic/coprimesOf";
2
- import { gcd } from "../../mathutils/arithmetic/gcd";
3
- import { lcd } from "../../mathutils/arithmetic/lcd";
4
- import { randint } from "../../mathutils/random/randint";
5
- import { Node } from "../../tree/nodes/node";
6
- import { NumberNode } from "../../tree/nodes/numbers/numberNode";
7
- import { DivideNode } from "../../tree/nodes/operators/divideNode";
8
- import { FractionNode } from "../../tree/nodes/operators/fractionNode";
9
- import { random } from "../../utils/random";
10
- import { shuffle } from "../../utils/shuffle";
11
- import { Integer } from "../integer/integer";
12
- import { Nombre, NumberType } from "../nombre";
13
-
14
- export abstract class RationalConstructor {
15
- /**
16
- * @param maxGcd max number by which the fraction is simplifiable
17
- */
18
- static randomSimplifiable(maxGcd: number = 10) {
19
- const gcd = randint(2, maxGcd);
20
- const max = randint(3, 11);
21
- const min = random(coprimesOf(max));
22
- let [num, denum]: number[] = shuffle([gcd * min, gcd * max]);
23
- if (denum === gcd) {
24
- //si 10/2 on transforme en 2/10
25
- return new Rational(denum, num);
26
- }
27
- return new Rational(num, denum);
28
- }
29
- static randomIrreductible(max: number = 11) {
30
- const a = randint(2, max);
31
- const b = random([...coprimesOf(a), 1]);
32
- if (b === 1) return new Rational(b, a);
33
- const [num, denum] = shuffle([a, b]);
34
- return new Rational(num, denum);
35
- }
36
- }
37
-
38
- export class Rational implements Nombre {
39
- num: number;
40
- denum: number;
41
- tex: string;
42
- value: number;
43
- isSimplified: boolean;
44
- type: NumberType;
45
-
46
- constructor(numerator: number, denumerator: number) {
47
- if (denumerator === 0) throw Error("division by zero");
48
- this.num = numerator;
49
- this.denum = denumerator;
50
- this.value = numerator / denumerator;
51
- this.isSimplified = Math.abs(gcd(numerator, denumerator)) === 1;
52
- this.tex = `\\frac{${this.num}}{${this.denum}}`;
53
- this.type = NumberType.Rational;
54
- }
55
-
56
- toTex() {
57
- return `\\frac{${this.num}}{${this.denum}}`;
58
- }
59
-
60
- add(nb: Nombre): Nombre {
61
- switch (nb.type) {
62
- case NumberType.Integer: {
63
- const num = this.num + this.denum * nb.value;
64
- return new Rational(num, this.denum).simplify();
65
- }
66
- case NumberType.Rational: {
67
- const rational = nb as Rational;
68
- const ppcm = lcd(rational.denum, this.denum);
69
- const num = this.num * (ppcm / this.denum) + rational.num * (ppcm / rational.denum);
70
- return new Rational(num, ppcm).simplify();
71
- }
72
- }
73
- throw Error("not implemented yet");
74
- }
75
-
76
- multiply(nb: Nombre): Nombre {
77
- switch (nb.type) {
78
- case NumberType.Integer: {
79
- const num = this.num * nb.value;
80
- const denum = this.denum;
81
- return new Rational(num, denum).simplify();
82
- }
83
- case NumberType.Rational: {
84
- const rational = nb as Rational;
85
- const num = this.num * rational.num;
86
- const denum = this.denum * rational.denum;
87
- return new Rational(num, denum).simplify();
88
- }
89
- }
90
- throw Error("not implemented yet");
91
- }
92
- divide(nb: Nombre): Nombre {
93
- switch (nb.type) {
94
- case NumberType.Integer: {
95
- const denum = this.denum * nb.value;
96
- return new Rational(this.num, denum).simplify();
97
- }
98
- case NumberType.Rational: {
99
- const rational = nb as Rational;
100
- const num = this.num * rational.denum;
101
- const denum = this.denum * rational.num;
102
- return new Rational(num, denum).simplify();
103
- }
104
- }
105
- throw Error("not implemented yet");
106
- }
107
-
108
- opposite(): Rational {
109
- return new Rational(-this.num, this.denum);
110
- }
111
-
112
- toTree(): Node {
113
- return new FractionNode(new NumberNode(this.num), new NumberNode(this.denum));
114
- }
115
-
116
- simplify(): Nombre {
117
- const sign = (this.num > 0 && this.denum > 0) || (this.num < 0 && this.denum < 0) ? 1 : -1;
118
- const div = Math.abs(gcd(this.num, this.denum));
119
- if (Math.abs(this.denum) === div) return new Integer(this.num / this.denum);
120
- return new Rational((sign * Math.abs(this.num)) / div, Math.abs(this.denum) / div);
121
- }
122
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.Real = void 0;
4
- var numberNode_1 = require("../../tree/nodes/numbers/numberNode");
5
- var nombre_1 = require("../nombre");
6
- var Real = /** @class */ (function () {
7
- function Real(value, tex) {
8
- this.value = value;
9
- this.tex = tex;
10
- this.type = nombre_1.NumberType.Real;
11
- }
12
- Real.prototype.toTree = function () {
13
- return new numberNode_1.NumberNode(this.value);
14
- };
15
- return Real;
16
- }());
17
- exports.Real = Real;
@@ -1,17 +0,0 @@
1
- import { Node } from "../../tree/nodes/node";
2
- import { NumberNode } from "../../tree/nodes/numbers/numberNode";
3
- import { Nombre, NumberType } from "../nombre";
4
-
5
- export class Real implements Nombre {
6
- value: number;
7
- tex: string;
8
- type: NumberType;
9
- constructor(value: number, tex: string) {
10
- this.value = value;
11
- this.tex = tex;
12
- this.type = NumberType.Real;
13
- }
14
- toTree(): Node {
15
- return new NumberNode(this.value);
16
- }
17
- }
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- exports.__esModule = true;
18
- exports.SquareRoot = exports.SquareRootConstructor = void 0;
19
- var isSquare_1 = require("../../mathutils/arithmetic/isSquare");
20
- var primeFactors_1 = require("../../mathutils/arithmetic/primeFactors");
21
- var randint_1 = require("../../mathutils/random/randint");
22
- var numberNode_1 = require("../../tree/nodes/numbers/numberNode");
23
- var multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
24
- var real_1 = require("./real");
25
- var sqrtNode_1 = require("../../tree/nodes/functions/sqrtNode");
26
- var SquareRootConstructor = /** @class */ (function () {
27
- function SquareRootConstructor() {
28
- }
29
- /**
30
- * @returns simplifiable square root type sqrt(c)=a*sqrt(b)
31
- */
32
- SquareRootConstructor.randomSimplifiable = function (_a) {
33
- var _b = _a.allowPerfectSquare, allowPerfectSquare = _b === void 0 ? false : _b, _c = _a.maxSquare, maxSquare = _c === void 0 ? 11 : _c;
34
- var a = (0, randint_1.randint)(2, maxSquare);
35
- var b;
36
- var bMin = allowPerfectSquare ? 1 : 2;
37
- do {
38
- b = (0, randint_1.randint)(bMin, maxSquare);
39
- } while (b % (a * a) === 0 || (0, isSquare_1.isSquare)(b));
40
- return new SquareRoot(a * a * b);
41
- };
42
- return SquareRootConstructor;
43
- }());
44
- exports.SquareRootConstructor = SquareRootConstructor;
45
- var SquareRoot = /** @class */ (function (_super) {
46
- __extends(SquareRoot, _super);
47
- function SquareRoot(operand) {
48
- var _this = _super.call(this, Math.sqrt(operand), "\\sqrt{".concat(operand, "}")) || this;
49
- _this.operand = operand;
50
- return _this;
51
- }
52
- SquareRoot.prototype.simplify = function () {
53
- var factors = (0, primeFactors_1.primeFactors)(this.operand);
54
- // finds primes with even exponents
55
- var multiples = [1];
56
- for (var i = 0; i < factors.length - 1; i++) {
57
- if (factors[i] === factors[i + 1]) {
58
- multiples.push(factors[i]);
59
- factors.splice(i, 2);
60
- i--;
61
- }
62
- }
63
- var outsideSqrt = multiples.reduce(function (x, y) { return x * y; });
64
- var insideSqrt = factors.length === 0 ? 1 : factors.reduce(function (x, y) { return x * y; });
65
- var simplified = insideSqrt !== 1
66
- ? new real_1.Real(outsideSqrt * Math.sqrt(insideSqrt), "".concat(outsideSqrt === 1 ? "" : "".concat(outsideSqrt), "\\sqrt{").concat(insideSqrt, "}"))
67
- : new real_1.Real(outsideSqrt, outsideSqrt + "");
68
- simplified.toTree = function () {
69
- return insideSqrt !== 1
70
- ? outsideSqrt === 1
71
- ? new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(insideSqrt))
72
- : new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(outsideSqrt), new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(insideSqrt)))
73
- : new numberNode_1.NumberNode(outsideSqrt);
74
- };
75
- return simplified;
76
- };
77
- SquareRoot.prototype.toTex = function () {
78
- return this.tex;
79
- };
80
- SquareRoot.prototype.toTree = function () {
81
- return new sqrtNode_1.SqrtNode(new numberNode_1.NumberNode(this.operand));
82
- };
83
- return SquareRoot;
84
- }(real_1.Real));
85
- exports.SquareRoot = SquareRoot;
@@ -1,70 +0,0 @@
1
- import { isSquare } from "../../mathutils/arithmetic/isSquare";
2
- import { primeFactors } from "../../mathutils/arithmetic/primeFactors";
3
- import { randint } from "../../mathutils/random/randint";
4
- import { Node } from "../../tree/nodes/node";
5
- import { NumberNode } from "../../tree/nodes/numbers/numberNode";
6
- import { MultiplyNode } from "../../tree/nodes/operators/multiplyNode";
7
- import { Real } from "./real";
8
- import { SqrtNode } from "../../tree/nodes/functions/sqrtNode";
9
-
10
- export abstract class SquareRootConstructor {
11
- /**
12
- * @returns simplifiable square root type sqrt(c)=a*sqrt(b)
13
- */
14
- static randomSimplifiable({ allowPerfectSquare = false, maxSquare = 11 }): SquareRoot {
15
- const a = randint(2, maxSquare);
16
- let b;
17
- let bMin = allowPerfectSquare ? 1 : 2;
18
- do {
19
- b = randint(bMin, maxSquare);
20
- } while (b % (a * a) === 0 || isSquare(b));
21
- return new SquareRoot(a * a * b);
22
- }
23
- }
24
-
25
- export class SquareRoot extends Real {
26
- operand: number;
27
- constructor(operand: number) {
28
- super(Math.sqrt(operand), `\\sqrt{${operand}}`);
29
- this.operand = operand;
30
- }
31
-
32
- simplify(): Real {
33
- const factors = primeFactors(this.operand);
34
- // finds primes with even exponents
35
- const multiples = [1];
36
- for (let i = 0; i < factors.length - 1; i++) {
37
- if (factors[i] === factors[i + 1]) {
38
- multiples.push(factors[i]);
39
- factors.splice(i, 2);
40
- i--;
41
- }
42
- }
43
- const outsideSqrt = multiples.reduce((x, y) => x * y);
44
- const insideSqrt = factors.length === 0 ? 1 : factors.reduce((x, y) => x * y);
45
-
46
- const simplified =
47
- insideSqrt !== 1
48
- ? new Real(
49
- outsideSqrt * Math.sqrt(insideSqrt),
50
- `${outsideSqrt === 1 ? "" : `${outsideSqrt}`}\\sqrt{${insideSqrt}}`
51
- )
52
- : new Real(outsideSqrt, outsideSqrt + "");
53
- simplified.toTree = (): Node => {
54
- return insideSqrt !== 1
55
- ? outsideSqrt === 1
56
- ? new SqrtNode(new NumberNode(insideSqrt))
57
- : new MultiplyNode(new NumberNode(outsideSqrt), new SqrtNode(new NumberNode(insideSqrt)))
58
- : new NumberNode(outsideSqrt);
59
- };
60
- return simplified;
61
- }
62
-
63
- toTex(): string {
64
- return this.tex;
65
- }
66
-
67
- toTree(): Node {
68
- return new SqrtNode(new NumberNode(this.operand));
69
- }
70
- }
@@ -1,71 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- exports.__esModule = true;
18
- exports.Affine = exports.AffineConstructor = void 0;
19
- var rational_1 = require("../numbers/rationals/rational");
20
- var intervals_1 = require("../sets/intervals/intervals");
21
- var polynomial_1 = require("./polynomial");
22
- var discreteSet_1 = require("../sets/discreteSet");
23
- var integer_1 = require("../numbers/integer/integer");
24
- var AffineConstructor = /** @class */ (function () {
25
- function AffineConstructor() {
26
- }
27
- AffineConstructor.random = function (domainA, domainB) {
28
- if (domainA === void 0) { domainA = new intervals_1.Interval("[[-10; 10]]").difference(new discreteSet_1.DiscreteSet([new integer_1.Integer(0)])); }
29
- if (domainB === void 0) { domainB = new intervals_1.Interval("[[-10; 10]]"); }
30
- var a = domainA.getRandomElement();
31
- var b = domainB.getRandomElement();
32
- return new Affine(a.value, b.value);
33
- };
34
- AffineConstructor.differentRandoms = function (nb, domainA, domainB) {
35
- if (domainA === void 0) { domainA = new intervals_1.Interval("[[-10; 10]]").difference(new discreteSet_1.DiscreteSet([new integer_1.Integer(0)])); }
36
- if (domainB === void 0) { domainB = new intervals_1.Interval("[[-10; 10]]"); }
37
- var res = [];
38
- var _loop_1 = function (i) {
39
- var aff;
40
- do {
41
- aff = AffineConstructor.random(domainA, domainB);
42
- } while (res.some(function (affine) { return affine.equals(aff); }));
43
- res.push(aff);
44
- };
45
- for (var i = 0; i < nb; i++) {
46
- _loop_1(i);
47
- }
48
- return res;
49
- };
50
- return AffineConstructor;
51
- }());
52
- exports.AffineConstructor = AffineConstructor;
53
- var Affine = /** @class */ (function (_super) {
54
- __extends(Affine, _super);
55
- function Affine(a, b, variable) {
56
- if (variable === void 0) { variable = "x"; }
57
- var _this = _super.call(this, [b, a], variable) || this;
58
- _this.a = a;
59
- _this.b = b;
60
- _this.variable = variable;
61
- return _this;
62
- }
63
- Affine.prototype.getRoot = function () {
64
- return new rational_1.Rational(-this.b, this.a).simplify();
65
- };
66
- Affine.prototype.toString = function () {
67
- return _super.prototype.toTex.call(this);
68
- };
69
- return Affine;
70
- }(polynomial_1.Polynomial));
71
- exports.Affine = Affine;
@@ -1,60 +0,0 @@
1
- import { Rational } from "../numbers/rationals/rational";
2
- import { Interval } from "../sets/intervals/intervals";
3
- import { Polynomial } from "./polynomial";
4
- import { DiscreteSet } from "../sets/discreteSet";
5
- import { MathSet } from "../sets/mathSet";
6
- import { Integer } from "../numbers/integer/integer";
7
- import { Node, NodeType } from "../tree/nodes/node";
8
- import { MultiplyNode } from "../tree/nodes/operators/multiplyNode";
9
- import { NumberNode } from "../tree/nodes/numbers/numberNode";
10
- import { VariableNode } from "../tree/nodes/variables/variableNode";
11
- import { AddNode } from "../tree/nodes/operators/addNode";
12
- import { Nombre } from "../numbers/nombre";
13
-
14
- export abstract class AffineConstructor {
15
- static random(
16
- domainA: MathSet = new Interval("[[-10; 10]]").difference(new DiscreteSet([new Integer(0)])),
17
- domainB: MathSet = new Interval("[[-10; 10]]")
18
- ): Affine {
19
- const a = domainA.getRandomElement();
20
- const b = domainB.getRandomElement();
21
- return new Affine(a.value, b.value);
22
- }
23
-
24
- static differentRandoms(
25
- nb: number,
26
- domainA: MathSet = new Interval("[[-10; 10]]").difference(new DiscreteSet([new Integer(0)])),
27
- domainB: MathSet = new Interval("[[-10; 10]]")
28
- ): Affine[] {
29
- const res: Affine[] = [];
30
- for (let i = 0; i < nb; i++) {
31
- let aff: Affine;
32
- do {
33
- aff = AffineConstructor.random(domainA, domainB);
34
- } while (res.some((affine) => affine.equals(aff)));
35
- res.push(aff);
36
- }
37
- return res;
38
- }
39
- }
40
-
41
- export class Affine extends Polynomial {
42
- a: number;
43
- b: number;
44
- variable: string;
45
-
46
- constructor(a: number, b: number, variable: string = "x") {
47
- super([b, a], variable);
48
- this.a = a;
49
- this.b = b;
50
- this.variable = variable;
51
- }
52
-
53
- getRoot(): Nombre {
54
- return new Rational(-this.b, this.a).simplify();
55
- }
56
-
57
- toString(): string {
58
- return super.toTex();
59
- }
60
- }