pimath 0.0.128 → 0.0.130

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 (162) hide show
  1. package/dist/main.d.ts +39 -0
  2. package/dist/maths/algebra/equation.d.ts +120 -0
  3. package/dist/maths/algebra/linearSystem.d.ts +40 -0
  4. package/dist/maths/algebra/logicalset.d.ts +28 -0
  5. package/dist/maths/algebra/monom.d.ts +207 -0
  6. package/dist/maths/algebra/polynom.d.ts +155 -0
  7. package/dist/maths/algebra/rational.d.ts +44 -0
  8. package/dist/maths/algebra/study/rationalStudy.d.ts +14 -0
  9. package/dist/maths/algebra/study.d.ts +140 -0
  10. package/dist/maths/coefficients/fraction.d.ts +90 -0
  11. package/dist/maths/coefficients/nthRoot.d.ts +23 -0
  12. package/dist/maths/geometry/circle.d.ts +46 -0
  13. package/dist/maths/geometry/line.d.ts +102 -0
  14. package/dist/maths/geometry/point.d.ts +36 -0
  15. package/dist/maths/geometry/triangle.d.ts +92 -0
  16. package/dist/maths/geometry/vector.d.ts +38 -0
  17. package/dist/maths/numeric.d.ts +28 -0
  18. package/dist/maths/numexp.d.ts +19 -0
  19. package/dist/maths/randomization/random.d.ts +26 -0
  20. package/dist/maths/randomization/randomCore.d.ts +7 -0
  21. package/dist/maths/randomization/rndFraction.d.ts +13 -0
  22. package/dist/maths/randomization/rndGeometryCircle.d.ts +13 -0
  23. package/dist/maths/randomization/rndGeometryLine.d.ts +13 -0
  24. package/dist/maths/randomization/rndGeometryPoint.d.ts +13 -0
  25. package/dist/maths/randomization/rndHelpers.d.ts +23 -0
  26. package/dist/maths/randomization/rndMonom.d.ts +13 -0
  27. package/dist/maths/randomization/rndPolynom.d.ts +14 -0
  28. package/dist/maths/randomization/rndTypes.d.ts +40 -0
  29. package/dist/maths/shutingyard.d.ts +59 -0
  30. package/dist/pimath.js +85 -85
  31. package/lib/main.ts +42 -0
  32. package/{src → lib}/maths/algebra/equation.ts +52 -58
  33. package/{src → lib}/maths/algebra/linearSystem.ts +5 -6
  34. package/lib/maths/algebra/logicalset.ts +183 -0
  35. package/{src → lib}/maths/algebra/monom.ts +7 -8
  36. package/{src → lib}/maths/algebra/polynom.ts +2 -2
  37. package/{src → lib}/maths/algebra/study.ts +9 -9
  38. package/{src → lib}/maths/coefficients/fraction.ts +4 -4
  39. package/{src → lib}/maths/geometry/circle.ts +6 -9
  40. package/{src → lib}/maths/geometry/line.ts +1 -1
  41. package/{src → lib}/maths/geometry/vector.ts +35 -34
  42. package/{src → lib}/maths/numexp.ts +91 -77
  43. package/{src → lib}/maths/randomization/rndHelpers.ts +1 -1
  44. package/{src → lib}/maths/randomization/rndMonom.ts +13 -13
  45. package/{src → lib}/maths/randomization/rndPolynom.ts +24 -24
  46. package/package.json +11 -12
  47. package/.eslintrc.js +0 -24
  48. package/.idea/$CACHE_FILE$ +0 -6
  49. package/.idea/PI.iml +0 -14
  50. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  51. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  52. package/.idea/jsLibraryMappings.xml +0 -6
  53. package/.idea/misc.xml +0 -6
  54. package/.idea/modules.xml +0 -8
  55. package/.idea/php.xml +0 -19
  56. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +0 -192
  57. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
  58. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +0 -4
  59. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +0 -2404
  60. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +0 -4
  61. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +0 -1362
  62. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +0 -4
  63. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +0 -90
  64. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +0 -4
  65. package/.idea/vcs.xml +0 -6
  66. package/dist/demo/exercises.html +0 -283
  67. package/dist/demo/matrices.html +0 -39
  68. package/dist/demo/playground.html +0 -20
  69. package/dist/demo.css +0 -3
  70. package/dist/pimath.umd.cjs +0 -15
  71. package/docs/.nojekyll +0 -1
  72. package/docs/assets/highlight.css +0 -78
  73. package/docs/assets/main.js +0 -59
  74. package/docs/assets/navigation.js +0 -1
  75. package/docs/assets/search.js +0 -1
  76. package/docs/assets/style.css +0 -1383
  77. package/docs/classes/Logicalset.Logicalset.html +0 -217
  78. package/docs/classes/Polynom.Rational.html +0 -397
  79. package/docs/classes/Vector-1.Vector.html +0 -490
  80. package/docs/classes/Vector.Point.html +0 -337
  81. package/docs/classes/algebra_equation.Equation.html +0 -790
  82. package/docs/classes/algebra_linearSystem.LinearSystem.html +0 -404
  83. package/docs/classes/algebra_monom.Monom.html +0 -962
  84. package/docs/classes/algebra_polynom.Polynom.html +0 -1275
  85. package/docs/classes/coefficients_fraction.Fraction.html +0 -934
  86. package/docs/classes/geometry_circle.Circle.html +0 -472
  87. package/docs/classes/geometry_line.Line.html +0 -774
  88. package/docs/classes/geometry_triangle.Triangle.html +0 -429
  89. package/docs/classes/numeric.Numeric.html +0 -265
  90. package/docs/classes/shutingyard.Shutingyard.html +0 -250
  91. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +0 -83
  92. package/docs/enums/geometry_line.LinePropriety.html +0 -97
  93. package/docs/enums/shutingyard.ShutingyardMode.html +0 -97
  94. package/docs/enums/shutingyard.ShutingyardType.html +0 -111
  95. package/docs/index.html +0 -63
  96. package/docs/interfaces/algebra_equation.ISolution.html +0 -105
  97. package/docs/interfaces/algebra_polynom.IEuclidian.html +0 -87
  98. package/docs/interfaces/geometry_triangle.remarquableLines.html +0 -163
  99. package/docs/modules/Logicalset.html +0 -65
  100. package/docs/modules/Polynom.html +0 -65
  101. package/docs/modules/Vector-1.html +0 -65
  102. package/docs/modules/Vector.html +0 -65
  103. package/docs/modules/algebra_equation.html +0 -69
  104. package/docs/modules/algebra_linearSystem.html +0 -61
  105. package/docs/modules/algebra_monom.html +0 -65
  106. package/docs/modules/algebra_polynom.html +0 -69
  107. package/docs/modules/coefficients_fraction.html +0 -65
  108. package/docs/modules/geometry_circle.html +0 -61
  109. package/docs/modules/geometry_line.html +0 -65
  110. package/docs/modules/geometry_triangle.html +0 -65
  111. package/docs/modules/numeric.html +0 -61
  112. package/docs/modules/shutingyard.html +0 -75
  113. package/docs/types/algebra_monom.literalType.html +0 -61
  114. package/docs/types/algebra_polynom.PolynomParsingType.html +0 -56
  115. package/docs/types/coefficients_fraction.FractionParsingType.html +0 -56
  116. package/docs/types/shutingyard.Token.html +0 -63
  117. package/docs/types/shutingyard.tokenType.html +0 -68
  118. package/docs/variables/shutingyard.tokenConstant.html +0 -61
  119. package/index.html +0 -15
  120. package/public/demo/exercises.html +0 -283
  121. package/public/demo/matrices.html +0 -39
  122. package/public/demo/playground.html +0 -20
  123. package/public/demo.css +0 -3
  124. package/src/demo/exercises.ts +0 -0
  125. package/src/demo/matrices.ts +0 -61
  126. package/src/demo/playground.ts +0 -153
  127. package/src/main.ts +0 -42
  128. package/src/maths/algebra/logicalset.ts +0 -183
  129. package/tests/algebra/equation.test.ts +0 -64
  130. package/tests/algebra/linear.test.ts +0 -58
  131. package/tests/algebra/monom.test.ts +0 -78
  132. package/tests/algebra/polynom.test.ts +0 -343
  133. package/tests/algebra/rationnal.test.ts +0 -64
  134. package/tests/algebra/study.test.ts +0 -48
  135. package/tests/coefficients/fraction.test.ts +0 -131
  136. package/tests/custom.test.ts +0 -33
  137. package/tests/geometry/circle.test.ts +0 -404
  138. package/tests/geometry/line.test.ts +0 -36
  139. package/tests/numeric.test.ts +0 -43
  140. package/tests/numexp.test.ts +0 -89
  141. package/tests/shutingyard.test.ts +0 -58
  142. package/tsconfig.json +0 -52
  143. package/tsconfig.testing.json +0 -28
  144. package/typedoc.katex.js +0 -11
  145. package/vite.config.js +0 -23
  146. package/webpack-production-min.config.js +0 -26
  147. package/webpack-production.config.js +0 -26
  148. package/webpack.config.js +0 -26
  149. /package/{src → lib}/maths/algebra/rational.ts +0 -0
  150. /package/{src → lib}/maths/algebra/study/rationalStudy.ts +0 -0
  151. /package/{src → lib}/maths/coefficients/nthRoot.ts +0 -0
  152. /package/{src → lib}/maths/geometry/point.ts +0 -0
  153. /package/{src → lib}/maths/geometry/triangle.ts +0 -0
  154. /package/{src → lib}/maths/numeric.ts +0 -0
  155. /package/{src → lib}/maths/randomization/random.ts +0 -0
  156. /package/{src → lib}/maths/randomization/randomCore.ts +0 -0
  157. /package/{src → lib}/maths/randomization/rndFraction.ts +0 -0
  158. /package/{src → lib}/maths/randomization/rndGeometryCircle.ts +0 -0
  159. /package/{src → lib}/maths/randomization/rndGeometryLine.ts +0 -0
  160. /package/{src → lib}/maths/randomization/rndGeometryPoint.ts +0 -0
  161. /package/{src → lib}/maths/randomization/rndTypes.ts +0 -0
  162. /package/{src → lib}/maths/shutingyard.ts +0 -0
@@ -1,61 +0,0 @@
1
- function detMatrice(M: number[][]): { matrix: number[][], determinant: number } {
2
- return {
3
- matrix: M,
4
- determinant: detnxn(M)
5
- }
6
- }
7
-
8
- function det2x2(M: number[][]): number {
9
- return M[0][0] * M[1][1] - M[1][0] * M[0][1]
10
- }
11
-
12
- function subMatrix(M: number[][], row: number, col: number) {
13
- let subM = []
14
-
15
- for (let r = 0; r < M.length; r++) {
16
- if (r === row) {
17
- continue
18
- }
19
-
20
- let subMrow = []
21
- for (let c = 0; c < M[r].length; c++) {
22
- if (c === col) {
23
- continue
24
- }
25
- subMrow.push(M[r][c])
26
- }
27
- subM.push(subMrow)
28
- }
29
- return subM
30
- }
31
-
32
- function detnxn(M: number[][]) {
33
- let result = 0
34
-
35
- if (M.length === 2) {
36
- result = det2x2(M)
37
- } else {
38
- for (let i = 0; i < M.length; i++) {
39
- if (M[i][0] !== 0) {
40
- result += M[i][0] * Math.pow(-1, i) * detnxn(subMatrix(M, i, 0))
41
-
42
-
43
- }
44
- }
45
- }
46
-
47
- return result
48
- }
49
-
50
- const M = detMatrice([
51
- [0, 2, -1, 4, 0],
52
- [3, 5, 0, 0, -2],
53
- [0, -3, 1, 0, 0],
54
- [0, 0, -4, 3, -3],
55
- [-1, 0, 0, 1, 2]
56
- ])
57
-
58
- document.getElementById('app').innerHTML = `<p>\\[${M.matrix} = ${M.determinant}\\]</p>`;
59
-
60
- // @ts-ignore
61
- renderMathInElement(document.getElementById('app'))
@@ -1,153 +0,0 @@
1
- import {Point} from "../maths/geometry/point.ts";
2
- import {Line} from "../maths/geometry/line.ts";
3
-
4
- let A = new Point(0, 2),
5
- B = new Point(2, 3),
6
- C = new Point(1 / 2, 4),
7
- D = new Point(2, -1 / 2);
8
-
9
- let L1 = new Line(A, B).simplifyDirection(),
10
- L2 = new Line(C, D).simplifyDirection();
11
-
12
- document.getElementById('app').innerHTML = `<p>\\( ${L1.tex.parametric} \\)</p>`;
13
- document.getElementById('app').innerHTML += `<p>\\( ${L2.tex.parametric} \\)</p>`;
14
-
15
- let I = L1.intersection(L2);
16
- if (I.hasIntersection) {
17
- document.getElementById('app').innerHTML += `<p>\\[ ${L1.intersection(L2).point.tex} \\]</p>`
18
- } else if (I.isParallel) {
19
- document.getElementById('app').innerHTML += `<p>Elles sont parallèles</p>`
20
- } else if (I.isSame) {
21
- document.getElementById('app').innerHTML += `<p>Elles sont confondues</p>`
22
- }
23
-
24
-
25
- // @ts-ignore
26
- renderMathInElement(document.getElementById('app'), {fleqn: true});
27
- /*let p;
28
- p = new Pi.Polynom('3x(6x+9)+6(6x+9)');
29
- document.getElementById('app').innerHTML = `<p>${p.raw}</p>`;
30
- document.getElementById('app').innerHTML += `<p>${p.display}</p>`;
31
-
32
- let v1 = new Pi.Vector('3 4'),
33
- v2 = new Pi.Vector('-2 5');
34
-
35
- console.log(v1);
36
- console.log(v2);
37
- console.log(Pi.Vector.scalarProduct(v1, v2));
38
-
39
-
40
- let P = new Pi.Polynom('(x+5)(x-17)(37x+35)');
41
- let Q = new Pi.Polynom('1');
42
- P.factorize(100)
43
-
44
- P.factors.forEach(n=> {
45
- console.log(n.tex)
46
- Q.multiply(n);
47
- })
48
-
49
- // Check that we have the same polynom.
50
- console.log(P.tex);
51
- console.log(Q.tex);
52
-
53
-
54
-
55
-
56
-
57
- /*let n = new Pi.Polynom(),
58
- d = new Pi.Polynom();
59
- n.parse('(x+3)(x+4)');
60
- d.parse('(x+3)(x-2)')
61
-
62
- let r = new Pi.Rational(n, d);
63
- document.getElementById('app').innerHTML = `<p>${r.tex}</p>`*/
64
-
65
-
66
- /*
67
- let M = new Pi.Monom().random('x', 2, false, false);
68
- console.log(M.displayWithSign);
69
-
70
- let S = new Pi.LinearSystem().parse(
71
- 'x-3y=-2',
72
- '4x+7x=1'
73
- );
74
- S.solve();
75
- document.getElementById('app').innerHTML = `<p>${S.tex}</p>`;
76
- document.getElementById('app').innerHTML += `<p>${S.texSolution}</p>`;
77
- let S = new Pi.LinearSystem().generate(3,-5,2);
78
- document.getElementById('app').innerHTML = `<p>${S.tex}</p>`;
79
- S.solve();
80
- S.log;
81
- S.tex;
82
-
83
- S = new Pi.LinearSystem().generate(-1,8,-2);
84
- document.getElementById('app').innerHTML += `<p>${S.tex}</p>`;
85
- S.solve();
86
- S.log;
87
-
88
- let P = new Pi.Polynom('3x^2+5yx-2');
89
- console.log(P.tex);
90
- console.log(P.numberOfVars);
91
- P.replaceBy('y', new Pi.Polynom('2x+1'));
92
- console.log(P.tex);
93
-
94
- let A = new Pi.Equation('2x+3y=5');
95
- console.log(A.tex);
96
-
97
- A.isolate('x');
98
- console.log(A.tex);
99
-
100
- A.isolate('y');
101
- console.log(A.tex);
102
-
103
- let P = new Pi.Polynom().rndSimple(2).makeItComplicate();
104
- console.log(P.tex);
105
- console.log(P.texString);
106
-
107
- let A = new Pi.Fraction().parse('2/5');
108
- console.log(A.frac);
109
-
110
- let F = new Pi.Fraction().parse('18/5');
111
- let N = new Pi.Root().parse(F).reduce();
112
- console.log(N.tex);
113
-
114
- let E = new Pi.Equation().create(new Pi.Polynom().parse('x^2+6x-8'), new Pi.Polynom().zero());
115
- E.solve();
116
- console.log(E.solutions);
117
-
118
- let D = 42;
119
- console.log(Pi.Numeric.dividers(D));
120
-
121
- let X = new Pi.Polynom().rndFactorable(2, false);
122
- console.log(X.tex);
123
- X.factors.forEach(function(P, i){
124
- console.log(P.tex);
125
- });
126
-
127
- let EQ = new Pi.Equation('2x+3>=5x-2');
128
- EQ.solve();
129
- console.log(EQ.solution);
130
-
131
- EQ.parseString('2x+3<5x-2');
132
- EQ.solve();
133
- console.log(EQ.solution);
134
-
135
- EQ.parseString('7x+3>5x-2');
136
- EQ.solve();
137
- console.log(EQ.solution);
138
-
139
- EQ.parseString('7x+3=<5x-2');
140
- EQ.solve();
141
- console.log(EQ.solution);
142
-
143
- EQ.parseString('7x+3=<7x-2');
144
- EQ.solve();
145
- console.log(EQ.solution);
146
-
147
- EQ.parseString('7x+3>7x-2');
148
- EQ.solve();
149
- console.log(EQ.solution);
150
-
151
- EQ.parseString('x^2+6x+9>=0');
152
- EQ.solve();
153
- console.log(EQ.solution);*/
package/src/main.ts DELETED
@@ -1,42 +0,0 @@
1
- import {Numeric} from "./maths/numeric";
2
- import {NumExp} from "./maths/numexp";
3
- import {Shutingyard} from "./maths/shutingyard";
4
- import {Random} from "./maths/randomization/random";
5
- import {Fraction} from "./maths/coefficients/fraction";
6
- import {NthRoot} from "./maths/coefficients/nthRoot";
7
- import {Monom} from "./maths/algebra/monom";
8
- import {Polynom} from "./maths/algebra/polynom";
9
- import {Equation} from "./maths/algebra/equation";
10
- import {LinearSystem} from "./maths/algebra/linearSystem";
11
- import {Rational} from "./maths/algebra/rational";
12
- import {Logicalset} from "./maths/algebra/logicalset";
13
- import {Vector} from "./maths/geometry/vector";
14
- import {Line} from "./maths/geometry/line";
15
- import {Triangle} from "./maths/geometry/triangle";
16
- import {Circle} from "./maths/geometry/circle";
17
- import {Point} from "./maths/geometry/point";
18
-
19
- // Expose as global
20
- export const PiMath = {
21
- ShutingYard: Shutingyard,
22
- Numeric: Numeric,
23
- NumExp: NumExp,
24
- Fraction: Fraction,
25
- Root: NthRoot,
26
- Monom: Monom,
27
- Polynom: Polynom,
28
- Equation: Equation,
29
- LinearSystem: LinearSystem,
30
- Rational: Rational,
31
- Logicalset: Logicalset,
32
- Random: Random,
33
- Geometry: {
34
- Vector: Vector,
35
- Point: Point,
36
- Line: Line,
37
- Triangle: Triangle,
38
- Circle: Circle
39
- }
40
- };
41
-
42
- // (<any>window).PiMath = PiMath
@@ -1,183 +0,0 @@
1
- /**
2
- * Polynom module contains everything necessary to handle polynoms.
3
- * @module Logicalset
4
- */
5
-
6
- import {Shutingyard, ShutingyardMode} from '../shutingyard';
7
-
8
- /**
9
- * Polynom class can handle polynoms, reorder, resolve, ...
10
- */
11
- export class Logicalset {
12
- private _rawString: string;
13
- private _rpn: { token: string, tokenType: string }[]
14
-
15
- /**
16
- *
17
- * @param {string} value (optional) Default polynom to parse on class creation
18
- */
19
- constructor(value: string) {
20
- this._rawString = value
21
- this.parse(value)
22
- return this;
23
- }
24
-
25
- get isLogicalset() {
26
- return true;
27
- };
28
-
29
- private parse = (value: string): Logicalset => {
30
- // TODO: Must format the value string to convert some items...
31
-
32
- // Parse the updated value to the shutingyard algorithm
33
- this._rpn = new Shutingyard(ShutingyardMode.SET).parse(value).rpn;
34
-
35
- return this;
36
- }
37
-
38
- evaluate(tokenSets: { [key: string]: unknown[] }, reference?: unknown[]): unknown[] {
39
- let varStack: (Set<unknown>)[] = []
40
-
41
- let referenceSet: Set<unknown>
42
- if (reference === undefined) {
43
- referenceSet = new Set()
44
- for (let key in tokenSets) {
45
- referenceSet = new Set([...referenceSet, ...tokenSets[key]])
46
- }
47
- } else {
48
- referenceSet = new Set(reference)
49
- }
50
-
51
- for (let token of this._rpn) {
52
- if (token.tokenType === 'variable') {
53
- // The variable has no token - assume it's empty.
54
- if (tokenSets[token.token] === undefined) {
55
- varStack.push(new Set())
56
- } else {
57
- varStack.push(new Set(tokenSets[token.token]));
58
- }
59
-
60
- } else {
61
- switch (token.token) {
62
- case '&':
63
- if (varStack.length >= 2) {
64
- let second = varStack.pop(),
65
- first = varStack.pop()
66
-
67
- varStack.push(new Set([...first].filter(x => second.has(x))))
68
- }
69
- break
70
- case '|':
71
- if (varStack.length >= 2) {
72
- let second = varStack.pop(),
73
- first = varStack.pop()
74
- varStack.push(new Set([...first, ...second]))
75
- }
76
- break
77
- case '-':
78
- if (varStack.length >= 2) {
79
- let second = varStack.pop(),
80
- first = varStack.pop()
81
- varStack.push(new Set([...first].filter(x => !second.has(x))))
82
- }
83
- break
84
- case '!':
85
- if (varStack.length >= 1) {
86
- let first = varStack.pop()
87
-
88
- varStack.push(new Set([...referenceSet].filter(x => !first.has(x))))
89
- }
90
- break
91
- }
92
- }
93
- }
94
-
95
- return [...varStack[0]].sort();
96
- }
97
-
98
- vennAB(): any[] {
99
- return this.evaluate({
100
- A: ['A', 'AB'],
101
- B: ['B', 'AB']
102
- },
103
- ['A', 'B', 'AB', 'E']
104
- )
105
- }
106
-
107
- vennABC(): any[] {
108
- return this.evaluate({
109
- A: ['A', 'AB', 'AC', 'ABC'],
110
- B: ['B', 'AB', 'BC', 'ABC'],
111
- C: ['C', 'AC', 'BC', 'ABC']
112
- },
113
- ['A', 'B', 'C', 'AB', 'AC', 'BC', 'E']
114
- )
115
- }
116
-
117
- get rpn(): { token: string, tokenType: string }[] {
118
- return this._rpn
119
- }
120
-
121
- get tex(): string {
122
- let varStack: { token: string, tokenType: string } [] = []
123
-
124
- for (let token of this._rpn) {
125
- if (token.tokenType === 'variable') {
126
- varStack.push(token);
127
- } else {
128
- switch (token.token) {
129
- case '&':
130
- if (varStack.length >= 2) {
131
- let second = varStack.pop(),
132
- first = varStack.pop()
133
-
134
- if (first.tokenType === 'mix') {
135
- first.token = `( ${first.token} )`
136
- }
137
- if (second.tokenType === 'mix') {
138
- second.token = `( ${second.token} )`
139
- }
140
- varStack.push({token: `${first.token} \\cap ${second.token}`, tokenType: 'mix'})
141
- }
142
- break
143
- case '|':
144
- if (varStack.length >= 2) {
145
- let second = varStack.pop(),
146
- first = varStack.pop()
147
-
148
- if (first.tokenType === 'mix') {
149
- first.token = `( ${first.token} )`
150
- }
151
- if (second.tokenType === 'mix') {
152
- second.token = `( ${second.token} )`
153
- }
154
- varStack.push({token: `${first.token} \\cup ${second.token}`, tokenType: 'mix'})
155
- }
156
- break
157
- case '-':
158
- if (varStack.length >= 2) {
159
- let second = varStack.pop(),
160
- first = varStack.pop()
161
-
162
- if (first.tokenType === 'mix') {
163
- first.token = `( ${first.token} )`
164
- }
165
- if (second.tokenType === 'mix') {
166
- second.token = `( ${second.token} )`
167
- }
168
- varStack.push({token: `${first.token} \\setminus ${second.token}`, tokenType: 'mix'})
169
- }
170
- break
171
- case '!':
172
- if (varStack.length >= 1) {
173
- let first = varStack.pop()
174
- varStack.push({token: `\\overline{ ${first.token} }`, tokenType: 'variable'})
175
- }
176
- break
177
- }
178
- }
179
- }
180
-
181
- return varStack[0].token
182
- }
183
- }
@@ -1,64 +0,0 @@
1
- import {describe} from "mocha";
2
- import {expect} from "chai";
3
- import {Equation} from "../../src/maths/algebra/equation";
4
-
5
-
6
- describe('Equations tests', () => {
7
- it('should get the solutions', () => {
8
-
9
- let E1 = new Equation('3x+8', '0')
10
- E1.solve()
11
- expect(E1.solutions[0].tex).to.be.equal('-\\frac{ 8 }{ 3 }')
12
-
13
- let E2 = new Equation('x^2+5x+6', '0')
14
- E2.solve()
15
- expect(E2.solutions.map(x=>x.tex)).to.have.all.members(['-3', '-2'])
16
-
17
- let E3 = new Equation('(x-3)(x+2)(3x-5)', '0')
18
- E3.solve()
19
- expect(E3.solutions.map(x=>x.tex)).to.have.all.members([ '-2', '3', '\\frac{ 5 }{ 3 }' ])
20
-
21
- let E4 = new Equation('x^2+x+10', '0')
22
- E4.solve()
23
- expect(E4.solutions.map(x=>x.tex)).to.have.all.members([ '\\varnothing' ])
24
-
25
- let E5 = new Equation('(x-3)(x+2)(x-5)(x-7)(x+2)', 0)
26
- E5.solve()
27
- expect(E5.solutions.map(x=>x.tex)).to.have.all.members([ '-2', '3', '5', '7' ] )
28
-
29
-
30
- let E6 = new Equation('5x^2+7x-31', 0)
31
- E6.solve()
32
- expect(E6.solutions.map(x=>x.tex)).to.have.all.members([
33
- '\\frac{ -7 - \\sqrt{669} }{ 10 }',
34
- '\\frac{ -7 + \\sqrt{669} }{ 10 }'
35
- ] )
36
- })
37
-
38
- it('should resolve an equation of second degree', ()=>{
39
- let P = new Equation('-10x^2-8x+8=0')
40
- P.solve()
41
- expect(P.solutions[0].tex).to.have.oneOf(['\\frac{ -2 - 2\\sqrt{6} }{ 5 }', '\\frac{ -2 + 2\\sqrt{6} }{ 5 }'])
42
- })
43
-
44
- it('should solve this equation please', function () {
45
- let P = new Equation("2/7(3x+5)=9-(3-x)/7")
46
- P.solve()
47
-
48
- const sols = P.solutions.map(x => x.display)
49
- expect(sols).to.be.length(1)
50
- expect(sols[0]).to.be.equal('10')
51
- });
52
-
53
- it('should detect if two equations are equal or linear', function () {
54
- let P = new Equation('3x+2y=5'),
55
- Q = new Equation('5-3x=2y'),
56
- R = new Equation('6x+4y-10=0')
57
-
58
- expect(P.isSameAs(P)).to.be.true
59
- expect(P.isSameAs(Q)).to.be.true
60
- expect(P.isSameAs(R)).to.be.false
61
- expect(P.isLinearTo(Q)).to.be.true
62
- expect(P.isLinearTo(R)).to.be.true
63
- })
64
- })
@@ -1,58 +0,0 @@
1
- import {describe} from "mocha";
2
- import {expect} from "chai";
3
- import {LinearSystem} from "../../src/maths/algebra/linearSystem";
4
- import {Polynom} from "../../src/maths/algebra/polynom";
5
-
6
-
7
- describe('Linear systems tests', () => {
8
- it('should solve a 2x2 equations', () => {
9
- let LS = new LinearSystem(
10
- '4x+5y=11',
11
- '7y-24=3x'
12
- )
13
- LS.solve(true)
14
-
15
- expect(LS.solution).to.be.equal('\\left(-1;3\\right)')
16
- })
17
- it('should solve a 3x3 equations', () => {
18
- let LS = new LinearSystem(
19
- '2x+7y-z=-3',
20
- '-3x+2y+3z=12',
21
- '-5x-3y+2z=5'
22
- )
23
-
24
- LS.solve()
25
- expect(LS.solutionAsDisplay).to.be.equal("(1;0;5)")
26
- })
27
-
28
- it('should solve a 3x3 equations II ', () => {
29
- let LS = new LinearSystem(
30
- '-x+y-z=-6',
31
- '3x+2y+z=14',
32
- '5x+y+3z=7'
33
- )
34
-
35
- LS.solve()
36
- })
37
-
38
- it('should calculate the reduction', function () {
39
- let E1 = new Polynom('6x+21y-3z'),
40
- E2 = new Polynom('-6x+21y-3z')
41
-
42
- E1.add(E2);
43
- expect(E1.reduce().display).to.be.equal('42y-6z')
44
- });
45
-
46
- it('should use a reduced linear reducation', function () {
47
- let LS = new LinearSystem(
48
- '3x-6y+3=0',
49
- 'x+12y-6=0'
50
- )
51
- LS.solve(true)
52
-
53
- const tex = LS.stepTex('x')
54
-
55
- expect(+LS.resolutionSteps['x'][0].operations[0][0]).to.be.equal(2)
56
- expect(+LS.resolutionSteps['x'][0].operations[1][0]).to.be.equal(1)
57
- });
58
- })
@@ -1,78 +0,0 @@
1
- import {expect} from 'chai';
2
- import {Random} from "../../src/maths/randomization/random";
3
- import {describe} from "mocha";
4
- import {Monom} from "../../src/maths/algebra/monom";
5
-
6
- describe('Monom with integer power', () => {
7
- it('parsing', () => {
8
- const M0a = new Monom('3');
9
- expect(M0a.tex).to.be.equal('3')
10
-
11
- const M0b = new Monom('x');
12
- expect(M0b.tex).to.be.equal('x')
13
-
14
- const M0c = new Monom('3x');
15
- expect(M0c.tex).to.be.equal('3x')
16
-
17
- const M1 = new Monom('3x^5');
18
- expect(M1.tex).to.be.equal('3x^{5}')
19
-
20
- const M2 = new Monom('2/3x^2yz^3y^4')
21
- expect(M2.display).to.be.equal('2/3x^(2)y^(5)z^(3)')
22
-
23
- const M3 = new Monom('-3x^(-2)')
24
- expect(M3.tex).to.be.equal('-3x^{-2}')
25
-
26
- const M4 = new Monom('3x^(2/3)')
27
- expect(M4.tex).to.be.equal('3x^{\\tfrac{ 2 }{ 3 }}')
28
-
29
- const M5 = new Monom('-3x^(-2/3)y^(-5)8x^3')
30
- expect(M5.tex).to.be.equal('-24x^{\\tfrac{ 7 }{ 3 }}y^{-5}')
31
- })
32
-
33
- it('basic operations', () => {
34
- const M1 = new Monom('3x'),
35
- M2 = new Monom('2x')
36
-
37
- expect(M1.clone().add(M2).isEqual(new Monom('5x'))).to.be.true
38
- expect(M1.clone().subtract(M2).isEqual(new Monom('x'))).to.be.true
39
- expect(M1.clone().multiply(M2).isEqual(new Monom('6x^2'))).to.be.true
40
- expect(M1.clone().divide(M2).isEqual(new Monom('3/2'))).to.be.true
41
- })
42
-
43
- it('derivative', () => { // the single test
44
- const options = new Monom('7x^3'); // this will be your class
45
-
46
- expect(options.tex).to.be.equal('7x^{3}')
47
- expect(options.derivative().tex).to.be.equal('21x^{2}');
48
- });
49
-
50
- it('integrate', () => { // the single test
51
- const options = new Monom('7x^3'); // this will be your class
52
- expect(options.primitive().display).to.be.equal('7/4x^(4)');
53
- });
54
-
55
- it('randomize', function () {
56
- const M = Random.monom({
57
- letters: 'xyz',
58
- degree: 5,
59
- fraction: false,
60
- zero: false
61
- });
62
-
63
- expect(M.coefficient.isZero()).to.be.false
64
- expect(M.degree().value).to.be.greaterThan(0)
65
- });
66
- })
67
-
68
- describe('Monom with fraction power', () => {
69
- it('should create a numerical expression', () => {
70
- const inputStr: string = '-1/5x^(2/3)'
71
- const M = new Monom(inputStr),
72
- N = new Monom('7x^(4/5)')
73
-
74
- M.multiply(N.clone())
75
-
76
- expect(M.tex).to.be.equal('-\\frac{ 7 }{ 5 }x^{\\tfrac{ 22 }{ 15 }}')
77
- })
78
- })