pimath 0.0.75 → 0.0.78
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.
- package/dist/pi.js +137 -84
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/docs/assets/highlight.css +78 -78
- package/docs/assets/main.js +52 -52
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1413 -1413
- package/docs/classes/Logicalset.Logicalset-1.html +5 -5
- package/docs/classes/Polynom.Rational.html +4 -4
- package/docs/classes/Vector.Point.html +1 -1
- package/docs/classes/Vector.Vector-1.html +1 -1
- package/docs/classes/algebra_equation.Equation.html +26 -26
- package/docs/classes/algebra_linearSystem.LinearSystem.html +1 -1
- package/docs/classes/algebra_monom.Monom.html +114 -114
- package/docs/classes/algebra_polynom.Polynom.html +30 -30
- package/docs/classes/coefficients_fraction.Fraction.html +19 -19
- package/docs/classes/coefficients_nthroot.NthRoot.html +3 -3
- package/docs/classes/expressions_numexp.NumExp.html +1 -1
- package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +1 -1
- package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +1 -1
- package/docs/classes/geometry_circle.Circle.html +3 -3
- package/docs/classes/geometry_line.Line.html +3 -3
- package/docs/classes/geometry_triangle.Triangle.html +16 -16
- package/docs/classes/numeric.Numeric.html +14 -14
- package/docs/classes/shutingyard.Shutingyard.html +18 -18
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +1 -1
- package/docs/enums/geometry_line.LinePropriety.html +1 -1
- package/docs/enums/shutingyard.ShutingyardMode.html +1 -1
- package/docs/enums/shutingyard.ShutingyardType.html +1 -1
- package/docs/index.html +10 -10
- package/docs/interfaces/algebra_equation.ISolution.html +3 -3
- package/docs/interfaces/algebra_polynom.IEuclidian.html +1 -0
- package/docs/interfaces/geometry_triangle.remarquableLines.html +1 -1
- package/docs/modules/Logicalset.html +2 -2
- package/docs/modules/Polynom.html +2 -2
- package/docs/modules/Vector.html +2 -2
- package/docs/modules/algebra_monom.html +1 -1
- package/docs/modules/algebra_polynom.html +1 -1
- package/docs/modules/coefficients_fraction.html +1 -1
- package/docs/modules/shutingyard.html +1 -1
- package/esm/maths/algebra/polynom.js +81 -82
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/coefficients/fraction.js +3 -1
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/expressions/ExpressionTree.d.ts +17 -0
- package/esm/maths/expressions/ExpressionTree.js +150 -0
- package/esm/maths/expressions/ExpressionTree.js.map +1 -0
- package/esm/maths/numeric.d.ts +2 -0
- package/esm/maths/numeric.js +52 -0
- package/esm/maths/numeric.js.map +1 -1
- package/esm/maths/randomization/random.d.ts +1 -1
- package/esm/maths/randomization/random.js +1 -1
- package/esm/maths/randomization/random.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/polynom.ts +98 -92
- package/src/maths/coefficients/fraction.ts +6 -2
- package/src/maths/expressions/ExpressionTree.ts +172 -0
- package/src/maths/numeric.ts +67 -0
- package/src/maths/randomization/random.ts +2 -2
- package/tests/algebra/polynom.test.ts +6 -2
- package/tests/coefficients/fraction.test.ts +11 -3
- package/tests/expressions/expressiontree.test.ts +11 -0
- package/tests/numexp.test.ts +5 -4
package/src/maths/numeric.ts
CHANGED
|
@@ -104,4 +104,71 @@ export class Numeric{
|
|
|
104
104
|
|
|
105
105
|
return triplets
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
static numberCorrection(value: number){
|
|
109
|
+
// Must modify the number if it's like:
|
|
110
|
+
// a: 3.0000000000000003
|
|
111
|
+
// b: 3.9999999999999994
|
|
112
|
+
// remove the last character
|
|
113
|
+
// check if around n last characters are either 0 or 9
|
|
114
|
+
// if it is, 'round' the number.
|
|
115
|
+
|
|
116
|
+
function extractDecimalPart(valueToExtract: number){
|
|
117
|
+
let decimal = valueToExtract.toString()
|
|
118
|
+
|
|
119
|
+
if (!decimal.includes('.')) {
|
|
120
|
+
return ''
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
decimal = decimal.split('.')[1]
|
|
124
|
+
|
|
125
|
+
return decimal.substring(0, decimal.length - 2)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
const epsilon = 0.00000000000001,
|
|
130
|
+
number_of_digits = 6
|
|
131
|
+
|
|
132
|
+
const decimal = extractDecimalPart(value)
|
|
133
|
+
if(decimal===''){return value}
|
|
134
|
+
|
|
135
|
+
const n9 = decimal.match(/9+$/g)
|
|
136
|
+
const n0 = decimal.match(/0+$/g)
|
|
137
|
+
|
|
138
|
+
if (n9 && n9[0].length >= number_of_digits) {
|
|
139
|
+
// New tested values.
|
|
140
|
+
const mod = extractDecimalPart(value + epsilon),
|
|
141
|
+
mod0 = mod.match(/0+$/g)
|
|
142
|
+
|
|
143
|
+
if(mod0 && mod0[0].length>= number_of_digits){
|
|
144
|
+
// The value can be changed. Remove all zeros!
|
|
145
|
+
return +((value+epsilon).toString().split(mod0[0])[0])
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (n0 && n0[0].length >= number_of_digits) {
|
|
150
|
+
// New tested values.
|
|
151
|
+
const mod = extractDecimalPart(value - epsilon),
|
|
152
|
+
mod9 = mod.match(/9+$/g)
|
|
153
|
+
|
|
154
|
+
if(mod9 && mod9[0].length>= number_of_digits){
|
|
155
|
+
// The value can be changed. Remove all nines!
|
|
156
|
+
return +(value.toString().split(n0[0])[0])
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return value
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static periodic(value: number):number{
|
|
164
|
+
if(Number.isSafeInteger(value)){return 0}
|
|
165
|
+
|
|
166
|
+
// Assume it's with decimal.
|
|
167
|
+
let decimal = (value.toString()).split('.')[0]
|
|
168
|
+
|
|
169
|
+
// The decimal part is limited
|
|
170
|
+
if(decimal.length<10){return 0}
|
|
171
|
+
|
|
172
|
+
// Find the periodic if it exists.
|
|
173
|
+
}
|
|
107
174
|
}
|
|
@@ -3,6 +3,7 @@ import {Random} from "../../src/maths/randomization/random";
|
|
|
3
3
|
import {describe} from "mocha";
|
|
4
4
|
import {Polynom} from "../../src/maths/algebra/polynom";
|
|
5
5
|
import {Fraction} from "../../src/maths/coefficients/fraction";
|
|
6
|
+
import exp = require("constants");
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
describe('Polynom tests', () => {
|
|
@@ -89,17 +90,20 @@ describe('Polynom tests', () => {
|
|
|
89
90
|
expect(P.factors.map(x => x.tex)).to.have.all.members(['x-4', 'x-4', 'x+7', 'x+7', 'x-11', 'x-11'])
|
|
90
91
|
});
|
|
91
92
|
|
|
92
|
-
it('should factorize and
|
|
93
|
+
it('should factorize and regroup', function () {
|
|
93
94
|
let P = new Polynom('7x(x-3)(x+5)(x^2-9)3x')
|
|
94
95
|
P.factorize()
|
|
95
96
|
expect(P.texFactors).to.be.equal('21x^{2}\\left( x+3 \\right)\\left( x-3 \\right)^{ 2 }\\left( x+5 \\right)')
|
|
97
|
+
|
|
98
|
+
const P2 = new Polynom('-2x^3+18x')
|
|
99
|
+
P2.factorize()
|
|
100
|
+
expect(P2.texFactors).to.be.equal('-2x\\left( x+3 \\right)\\left( x-3 \\right)')
|
|
96
101
|
});
|
|
97
102
|
})
|
|
98
103
|
|
|
99
104
|
describe('Polynom parsing with rational power', () => {
|
|
100
105
|
it('should parse with rational powers', () => {
|
|
101
106
|
const P = new Polynom('3x^(2/3)-5x+5/3');
|
|
102
|
-
|
|
103
107
|
expect(P.tex).to.be.equal('3x^{\\tfrac{ 2 }{ 3 }}-5x+\\frac{ 5 }{ 3 }')
|
|
104
108
|
})
|
|
105
109
|
})
|
|
@@ -35,7 +35,17 @@ describe('Fraction tests', () => { // the tests container
|
|
|
35
35
|
expect(Q.isReduced()).to.be.false
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
+
it('Should parse a number with lots of decimals', ()=>{
|
|
39
|
+
let A = 3.45,
|
|
40
|
+
B = 3.333333333333322,
|
|
41
|
+
C = 5.314171717171717
|
|
38
42
|
|
|
43
|
+
let FA = new Fraction(A),
|
|
44
|
+
FB = new Fraction(B),
|
|
45
|
+
FC = new Fraction(C)
|
|
46
|
+
|
|
47
|
+
console.log(FA.tex, FB.tex, FC.tex)
|
|
48
|
+
})
|
|
39
49
|
})
|
|
40
50
|
|
|
41
51
|
describe("Fraction static functions", ()=>{
|
|
@@ -76,7 +86,7 @@ describe("Fraction static functions", ()=>{
|
|
|
76
86
|
expect(Fraction.average(...list).tex).to.be.equal('\\frac{ 19 }{ 10 }')
|
|
77
87
|
})
|
|
78
88
|
|
|
79
|
-
it('should multiply and
|
|
89
|
+
it('should multiply and not reduce', function () {
|
|
80
90
|
let list = [
|
|
81
91
|
new Fraction('1/2'),
|
|
82
92
|
new Fraction('4/3'),
|
|
@@ -100,7 +110,5 @@ describe("Evaluate fraction", () => {
|
|
|
100
110
|
let G = new Fraction('1/7')
|
|
101
111
|
expect(G.isApproximative()).to.be.false
|
|
102
112
|
expect(G.isExact()).to.be.true
|
|
103
|
-
|
|
104
|
-
console.log(G.tex, G.value)
|
|
105
113
|
});
|
|
106
114
|
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {ExpressionTree} from "../../src/maths/expressions/ExpressionTree";
|
|
2
|
+
|
|
3
|
+
describe('Expressions test', () => { // the tests container
|
|
4
|
+
it('Parsing tree', () => {
|
|
5
|
+
// let ET = new ExpressionTree('3(x-4)^2')
|
|
6
|
+
let ET = new ExpressionTree('3(x-7)^2-5sqrt(5x-3)')
|
|
7
|
+
|
|
8
|
+
console.log(ET.tex)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
});
|
package/tests/numexp.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
2
|
import {NumExp} from "../src/maths/expressions/numexp";
|
|
3
|
-
import
|
|
3
|
+
import {Numeric} from "../src/maths/numeric";
|
|
4
4
|
|
|
5
5
|
describe('Numerical expression', () => { // the tests container
|
|
6
6
|
it('RPN for numerical expression', () => {
|
|
@@ -8,7 +8,7 @@ describe('Numerical expression', () => { // the tests container
|
|
|
8
8
|
expect(RPN.map(x => x.token)).to.have.all.members(['3', 'x', '*', '5', '+'])
|
|
9
9
|
|
|
10
10
|
const RPN2 = new NumExp('-3*x^2-5').rpn
|
|
11
|
-
expect(RPN2.map(x=>x.token)).to.have.all.members(['3', 'x', '2', '^', '*', '-', '5', '-'])
|
|
11
|
+
expect(RPN2.map(x => x.token)).to.have.all.members(['3', 'x', '2', '^', '*', '-', '5', '-'])
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
it('Evaluate for numerical expression', () => {
|
|
@@ -34,9 +34,10 @@ describe('Numerical expression', () => { // the tests container
|
|
|
34
34
|
|
|
35
35
|
it('should parse without mult sign', function () {
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
let a = 1 / 5
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
console.log(a, Numeric.numberCorrection(a))
|
|
40
40
|
|
|
41
|
+
// console.log(expr.rpn)
|
|
41
42
|
});
|
|
42
43
|
});
|