math-exercises 1.2.7 → 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 (218) 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/lib/exercises/calcul/rounding/rounding.js +86 -0
  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 -38
  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/roundToUnit.js +0 -70
  107. package/src/exercises/calcul/rounding/roundToUnit.ts +0 -68
  108. package/src/exercises/calculLitteral/distributivity/allIdentities.ts +0 -26
  109. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.js +0 -31
  110. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.ts +0 -33
  111. package/src/exercises/calculLitteral/distributivity/firstIdentity.js +0 -32
  112. package/src/exercises/calculLitteral/distributivity/firstIdentity.ts +0 -33
  113. package/src/exercises/calculLitteral/distributivity/secondIdentity.js +0 -33
  114. package/src/exercises/calculLitteral/distributivity/secondIdentity.ts +0 -35
  115. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.js +0 -33
  116. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.ts +0 -33
  117. package/src/exercises/calculLitteral/distributivity/thirdIdentity.js +0 -32
  118. package/src/exercises/calculLitteral/distributivity/thirdIdentity.ts +0 -34
  119. package/src/exercises/calculLitteral/equation/equationType1Exercise.js +0 -38
  120. package/src/exercises/calculLitteral/equation/equationType1Exercise.ts +0 -38
  121. package/src/exercises/calculLitteral/equation/equationType2Exercise.js +0 -41
  122. package/src/exercises/calculLitteral/equation/equationType2Exercise.ts +0 -41
  123. package/src/exercises/calculLitteral/equation/equationType3Exercise.js +0 -42
  124. package/src/exercises/calculLitteral/equation/equationType3Exercise.ts +0 -43
  125. package/src/exercises/calculLitteral/equation/equationType4Exercise.js +0 -44
  126. package/src/exercises/calculLitteral/equation/equationType4Exercise.ts +0 -46
  127. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.js +0 -39
  128. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.ts +0 -54
  129. package/src/exercises/calculLitteral/reduction.ts +0 -27
  130. package/src/exercises/exercise.ts +0 -25
  131. package/src/exercises/exercises.js +0 -86
  132. package/src/exercises/exercises.ts +0 -91
  133. package/src/exercises/powers/powersDivision.js +0 -46
  134. package/src/exercises/powers/powersDivision.ts +0 -51
  135. package/src/exercises/powers/powersOfTenToDecimal.js +0 -33
  136. package/src/exercises/powers/powersOfTenToDecimal.ts +0 -37
  137. package/src/exercises/powers/powersPower.js +0 -45
  138. package/src/exercises/powers/powersPower.ts +0 -55
  139. package/src/exercises/powers/powersProduct.js +0 -46
  140. package/src/exercises/powers/powersProduct.ts +0 -51
  141. package/src/exercises/powers/scientificToDecimal.js +0 -38
  142. package/src/exercises/powers/scientificToDecimal.ts +0 -44
  143. package/src/exercises/squareRoots/simpifySquareRoot.ts +0 -27
  144. package/src/exercises/utils/getDistinctQuestions.js +0 -18
  145. package/src/exercises/utils/getDistinctQuestions.ts +0 -14
  146. package/src/index.js +0 -10
  147. package/src/index.ts +0 -14
  148. package/src/mathutils/arithmetic/coprimesOf.js +0 -13
  149. package/src/mathutils/arithmetic/coprimesOf.ts +0 -9
  150. package/src/mathutils/arithmetic/dividersOf.ts +0 -7
  151. package/src/mathutils/arithmetic/gcd.ts +0 -3
  152. package/src/mathutils/arithmetic/isSquare.ts +0 -3
  153. package/src/mathutils/arithmetic/lcd.ts +0 -7
  154. package/src/mathutils/arithmetic/nonCoprimesOf.ts +0 -9
  155. package/src/mathutils/arithmetic/nonDividersOf.ts +0 -12
  156. package/src/mathutils/arithmetic/primeFactors.ts +0 -18
  157. package/src/mathutils/decimals/decimalPartLengthOf.ts +0 -10
  158. package/src/mathutils/random/randint.ts +0 -12
  159. package/src/mathutils/round.ts +0 -5
  160. package/src/numbers/decimals/decimal.ts +0 -140
  161. package/src/numbers/epsilon.ts +0 -7
  162. package/src/numbers/integer/integer.ts +0 -72
  163. package/src/numbers/integer/power.ts +0 -49
  164. package/src/numbers/nombre.ts +0 -15
  165. package/src/numbers/number.js +0 -8
  166. package/src/numbers/rationals/rational.js +0 -128
  167. package/src/numbers/rationals/rational.ts +0 -122
  168. package/src/numbers/reals/real.js +0 -17
  169. package/src/numbers/reals/real.ts +0 -17
  170. package/src/numbers/reals/squareRoot.js +0 -85
  171. package/src/numbers/reals/squareRoot.ts +0 -70
  172. package/src/polynomials/affine.js +0 -71
  173. package/src/polynomials/affine.ts +0 -60
  174. package/src/polynomials/polynomial.js +0 -128
  175. package/src/polynomials/polynomial.ts +0 -137
  176. package/src/sets/discreteSet.js +0 -30
  177. package/src/sets/discreteSet.ts +0 -30
  178. package/src/sets/intervals/intervals.ts +0 -122
  179. package/src/sets/intervals/union.ts +0 -0
  180. package/src/sets/mathSet.js +0 -11
  181. package/src/sets/mathSet.ts +0 -12
  182. package/src/sets/mathSetInterface.js +0 -2
  183. package/src/sets/mathSetInterface.ts +0 -10
  184. package/src/tree/latexParser/latexParse.js +0 -117
  185. package/src/tree/nodes/functions/functionNode.ts +0 -18
  186. package/src/tree/nodes/functions/oppositeNode.js +0 -30
  187. package/src/tree/nodes/functions/oppositeNode.ts +0 -12
  188. package/src/tree/nodes/functions/sqrtNode.js +0 -33
  189. package/src/tree/nodes/functions/sqrtNode.ts +0 -12
  190. package/src/tree/nodes/node.ts +0 -12
  191. package/src/tree/nodes/numbers/numberNode.js +0 -16
  192. package/src/tree/nodes/numbers/numberNode.ts +0 -16
  193. package/src/tree/nodes/operators/addNode.js +0 -33
  194. package/src/tree/nodes/operators/addNode.ts +0 -13
  195. package/src/tree/nodes/operators/divideNode.js +0 -34
  196. package/src/tree/nodes/operators/divideNode.ts +0 -16
  197. package/src/tree/nodes/operators/equalNode.js +0 -30
  198. package/src/tree/nodes/operators/equalNode.ts +0 -11
  199. package/src/tree/nodes/operators/fractionNode.js +0 -34
  200. package/src/tree/nodes/operators/fractionNode.ts +0 -16
  201. package/src/tree/nodes/operators/multiplyNode.js +0 -30
  202. package/src/tree/nodes/operators/multiplyNode.ts +0 -12
  203. package/src/tree/nodes/operators/operatorNode.ts +0 -36
  204. package/src/tree/nodes/operators/oppositeNode.js +0 -18
  205. package/src/tree/nodes/operators/powerNode.js +0 -30
  206. package/src/tree/nodes/operators/powerNode.ts +0 -12
  207. package/src/tree/nodes/operators/substractNode.js +0 -30
  208. package/src/tree/nodes/operators/substractNode.ts +0 -11
  209. package/src/tree/nodes/variables/variableNode.js +0 -17
  210. package/src/tree/nodes/variables/variableNode.ts +0 -15
  211. package/src/tree/parsers/derivateParser.ts +0 -66
  212. package/src/tree/parsers/latexParser.ts +0 -122
  213. package/src/utils/coin.ts +0 -3
  214. package/src/utils/random.ts +0 -3
  215. package/src/utils/randomIn.js +0 -7
  216. package/src/utils/shuffle.js +0 -24
  217. package/src/utils/shuffle.ts +0 -11
  218. package/tsconfig.json +0 -110
@@ -1,72 +0,0 @@
1
- import { randint } from "../../mathutils/random/randint";
2
- import { Node } from "../../tree/nodes/node";
3
- import { NumberNode } from "../../tree/nodes/numbers/numberNode";
4
- import { Nombre, NumberType } from "../nombre";
5
- import { Rational } from "../rationals/rational";
6
-
7
- export abstract class IntegerConstructor {
8
- static random(nbOfDigits: number) {
9
- return randint(0, 10 ** nbOfDigits);
10
- }
11
- }
12
-
13
- export class Integer implements Nombre {
14
- value: number;
15
- tex: string;
16
- type: NumberType;
17
-
18
- constructor(value: number, tex?: string) {
19
- this.value = value;
20
- this.tex = tex || value + "";
21
- this.type = NumberType.Integer;
22
- }
23
-
24
- toTree(): Node {
25
- return new NumberNode(this.value, this.tex);
26
- }
27
-
28
- round(precision: number) {
29
- const intString = this.value + "";
30
-
31
- if (precision >= intString.length || precision < 1) throw Error("can't round to higher precision");
32
-
33
- let newInt = "";
34
- const shouldRoundUp = Number(intString[intString.length - precision]) > 4;
35
- if (shouldRoundUp) {
36
- for (let i = 0; i < precision; i++) {
37
- newInt += "0";
38
- }
39
- let retenue = true;
40
- let i = intString.length - precision - 1;
41
-
42
- while (retenue) {
43
- const nb = (Number(intString[i]) + 1) % 10;
44
- newInt = "" + nb + newInt;
45
- if (nb === 0) {
46
- i--;
47
- } else {
48
- retenue = false;
49
- for (let j = i - 1; j > -1; j--) {
50
- newInt = intString[j] + newInt;
51
- }
52
- }
53
- }
54
- } else {
55
- for (let i = 0; i < intString.length; i++) {
56
- newInt += i < intString.length - precision ? intString[i] : "0";
57
- }
58
- }
59
- return new Integer(Number(newInt));
60
- }
61
- divide(nb: Nombre): Nombre {
62
- switch (nb.type) {
63
- case NumberType.Integer:
64
- return new Rational(this.value, nb.value).simplify();
65
- case NumberType.Rational:
66
- const rational = nb as Rational;
67
- return new Rational(this.value * rational.denum, rational.num).simplify();
68
- default:
69
- throw Error("not implemented");
70
- }
71
- }
72
- }
@@ -1,49 +0,0 @@
1
- import { Node } from "../../tree/nodes/node";
2
- import { NumberNode } from "../../tree/nodes/numbers/numberNode";
3
- import { PowerNode } from "../../tree/nodes/operators/powerNode";
4
- import { Nombre, NumberType } from "../nombre";
5
- import { Integer } from "./integer";
6
-
7
- export class Power implements Nombre {
8
- value: number;
9
- tex: string;
10
- type: NumberType;
11
- operand: number;
12
- power: number;
13
- constructor(a: number, b: number) {
14
- this.operand = a;
15
- this.power = b;
16
- this.value = Math.pow(a, b);
17
- this.tex = `${a}^{${b}}`;
18
- this.type = b < 0 ? NumberType.Rational : NumberType.Integer;
19
- }
20
- simplify(): Node {
21
- if (this.power === 0) return new NumberNode(1);
22
- if (this.power === 1) return new NumberNode(this.operand);
23
- if (this.operand === 1) return new NumberNode(1);
24
- if (this.operand === 0) return new NumberNode(0);
25
- if (this.operand === -1) return new NumberNode(this.power % 2 === 0 ? 1 : -1);
26
- return this.toTree();
27
- }
28
- toDecimalWriting(): Nombre {
29
- if (this.operand !== 10) throw Error("only implemented for powers of ten so far");
30
- let s = "";
31
- if (this.power > -1) {
32
- s += "1";
33
- for (let i = 0; i < this.power; i++) {
34
- s += 0;
35
- }
36
- } else {
37
- s += "1";
38
- for (let i = 1; i < Math.abs(this.power); i++) {
39
- s = "0" + s;
40
- }
41
- s = "0." + s;
42
- }
43
-
44
- return new Integer(Number(s), s);
45
- }
46
- toTree(): Node {
47
- return new PowerNode(new NumberNode(this.operand), new NumberNode(this.power));
48
- }
49
- }
@@ -1,15 +0,0 @@
1
- import { Node } from "../tree/nodes/node";
2
- import { NumberNode } from "../tree/nodes/numbers/numberNode";
3
-
4
- export enum NumberType {
5
- Integer,
6
- Decimal,
7
- Rational,
8
- Real,
9
- }
10
- export interface Nombre {
11
- value: number;
12
- tex: string;
13
- type: NumberType;
14
- toTree: () => Node;
15
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.NumberType = void 0;
4
- var NumberType;
5
- (function (NumberType) {
6
- NumberType[NumberType["Integer"] = 0] = "Integer";
7
- NumberType[NumberType["Real"] = 1] = "Real";
8
- })(NumberType = exports.NumberType || (exports.NumberType = {}));
@@ -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;