pimath 0.1.40 → 0.2.1
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/pimath.js +3106 -2873
- package/dist/pimath.js.map +1 -1
- package/package.json +13 -11
- package/src/algebra/equation.ts +113 -111
- package/src/algebra/equationSolver.ts +69 -120
- package/src/algebra/factor.ts +6 -7
- package/src/algebra/linearSystem.ts +97 -46
- package/src/algebra/logicalset.ts +51 -52
- package/src/algebra/monom.ts +23 -61
- package/src/algebra/operations.ts +0 -1
- package/src/algebra/polyFactor.ts +5 -5
- package/src/algebra/polynom.ts +69 -216
- package/src/analyze/index.ts +4 -0
- package/src/analyze/solution.ts +92 -29
- package/src/analyze/tableOfSigns.ts +1 -1
- package/src/coefficients/fraction.ts +189 -149
- package/src/coefficients/index.ts +1 -1
- package/src/coefficients/root.ts +66 -19
- package/src/geometry/TupleN.ts +128 -0
- package/src/geometry/circle.ts +308 -238
- package/src/geometry/geomMath.ts +4 -3
- package/src/geometry/index.ts +1 -0
- package/src/geometry/line.ts +221 -245
- package/src/geometry/line3.ts +78 -73
- package/src/geometry/plane3.ts +64 -55
- package/src/geometry/point.ts +57 -19
- package/src/geometry/triangle.ts +376 -248
- package/src/geometry/vector.ts +113 -229
- package/src/index.ts +13 -12
- package/src/numeric.ts +6 -9
- package/src/pimath.interface.ts +30 -28
- package/src/randomization/algebra/rndPolynom.ts +29 -15
- package/src/randomization/coefficient/rndFraction.ts +3 -3
- package/src/randomization/geometry/rndLine.ts +8 -10
- package/src/randomization/random.ts +11 -13
- package/src/randomization/rndTypes.ts +16 -12
- package/types/algebra/equation.d.ts +18 -17
- package/types/algebra/equation.d.ts.map +1 -1
- package/types/algebra/equationSolver.d.ts +5 -4
- package/types/algebra/equationSolver.d.ts.map +1 -1
- package/types/algebra/factor.d.ts +1 -1
- package/types/algebra/factor.d.ts.map +1 -1
- package/types/algebra/linearSystem.d.ts +23 -6
- package/types/algebra/linearSystem.d.ts.map +1 -1
- package/types/algebra/logicalset.d.ts +1 -1
- package/types/algebra/logicalset.d.ts.map +1 -1
- package/types/algebra/monom.d.ts +1 -6
- package/types/algebra/monom.d.ts.map +1 -1
- package/types/algebra/operations.d.ts.map +1 -1
- package/types/algebra/polyFactor.d.ts +4 -4
- package/types/algebra/polyFactor.d.ts.map +1 -1
- package/types/algebra/polynom.d.ts +10 -7
- package/types/algebra/polynom.d.ts.map +1 -1
- package/types/analyze/index.d.ts +2 -0
- package/types/analyze/index.d.ts.map +1 -0
- package/types/analyze/solution.d.ts +14 -8
- package/types/analyze/solution.d.ts.map +1 -1
- package/types/coefficients/fraction.d.ts +14 -12
- package/types/coefficients/fraction.d.ts.map +1 -1
- package/types/coefficients/index.d.ts +1 -1
- package/types/coefficients/index.d.ts.map +1 -1
- package/types/coefficients/root.d.ts +3 -0
- package/types/coefficients/root.d.ts.map +1 -1
- package/types/geometry/TupleAbstract.d.ts +22 -0
- package/types/geometry/TupleAbstract.d.ts.map +1 -0
- package/types/geometry/TupleN.d.ts +24 -0
- package/types/geometry/TupleN.d.ts.map +1 -0
- package/types/geometry/circle.d.ts +26 -17
- package/types/geometry/circle.d.ts.map +1 -1
- package/types/geometry/geomMath.d.ts +2 -1
- package/types/geometry/geomMath.d.ts.map +1 -1
- package/types/geometry/index.d.ts.map +1 -1
- package/types/geometry/line.d.ts +21 -30
- package/types/geometry/line.d.ts.map +1 -1
- package/types/geometry/line3.d.ts +19 -19
- package/types/geometry/line3.d.ts.map +1 -1
- package/types/geometry/matrix.d.ts +11 -11
- package/types/geometry/plane3.d.ts +10 -10
- package/types/geometry/plane3.d.ts.map +1 -1
- package/types/geometry/point.d.ts +11 -6
- package/types/geometry/point.d.ts.map +1 -1
- package/types/geometry/triangle.d.ts +68 -23
- package/types/geometry/triangle.d.ts.map +1 -1
- package/types/geometry/vector.d.ts +24 -44
- package/types/geometry/vector.d.ts.map +1 -1
- package/types/index.d.ts +5 -4
- package/types/index.d.ts.map +1 -1
- package/types/numeric.d.ts.map +1 -1
- package/types/pimath.interface.d.ts +18 -24
- package/types/pimath.interface.d.ts.map +1 -1
- package/types/randomization/algebra/rndPolynom.d.ts.map +1 -1
- package/types/randomization/coefficient/rndFraction.d.ts +1 -1
- package/types/randomization/coefficient/rndFraction.d.ts.map +1 -1
- package/types/randomization/geometry/rndLine.d.ts.map +1 -1
- package/types/randomization/random.d.ts +3 -2
- package/types/randomization/random.d.ts.map +1 -1
- package/types/randomization/rndTypes.d.ts +15 -10
- package/types/randomization/rndTypes.d.ts.map +1 -1
- package/src/coefficients/nthRoot.ts +0 -149
package/src/coefficients/root.ts
CHANGED
|
@@ -7,10 +7,11 @@ export class Root implements IPiMathObject<Root>, IExpression<Root> {
|
|
|
7
7
|
#factor: Fraction
|
|
8
8
|
#index: number
|
|
9
9
|
#radical: Fraction
|
|
10
|
+
#withSign = false
|
|
10
11
|
|
|
11
12
|
constructor(value?: InputValue<Root | Fraction>) {
|
|
12
13
|
this.#index = 2
|
|
13
|
-
this.#factor = new Fraction().
|
|
14
|
+
this.#factor = new Fraction().zero()
|
|
14
15
|
this.#radical = new Fraction().zero()
|
|
15
16
|
|
|
16
17
|
if (value) {
|
|
@@ -35,6 +36,7 @@ export class Root implements IPiMathObject<Root>, IExpression<Root> {
|
|
|
35
36
|
|
|
36
37
|
return this
|
|
37
38
|
}
|
|
39
|
+
|
|
38
40
|
if (value instanceof Fraction) {
|
|
39
41
|
this.index = 2
|
|
40
42
|
this.factor = value.clone()
|
|
@@ -65,35 +67,60 @@ export class Root implements IPiMathObject<Root>, IExpression<Root> {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
get tex(): string {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
? '-'
|
|
73
|
-
: this.factor.tex
|
|
70
|
+
// b \sqrt{}
|
|
71
|
+
// b
|
|
72
|
+
// \sqrt{}
|
|
73
|
+
// -\sqrt{}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
// Force the plus sign.
|
|
76
|
+
const plus = this.#withSign && this.factor.isPositive() ? '+' : ''
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
}
|
|
78
|
+
// There is no radical - output the factor
|
|
79
|
+
if (this.#radical.isZero()) return `${plus}${this.#factor.tex}`
|
|
80
|
+
|
|
81
|
+
// The radical has an index of 1 - no radical.
|
|
82
|
+
if (this.index === 1) return `${plus}${this.factor.clone().multiply(this.radical).tex}`
|
|
79
83
|
|
|
80
|
-
|
|
84
|
+
// Make the root part
|
|
85
|
+
const rad = this.index === 2
|
|
86
|
+
? `\\sqrt{ ${this.#radical.tex} }`
|
|
87
|
+
: `\\sqrt[ ${this.index} ]{ ${this.#radical.tex} }`
|
|
81
88
|
|
|
82
|
-
|
|
89
|
+
if (this.#factor.isUnit()) {
|
|
90
|
+
return this.#withSign
|
|
91
|
+
? `${this.#factor.isOne() ? plus : '-'} ${rad}`
|
|
92
|
+
: `${this.#factor.isOne() ? '' : '-'}${rad}`
|
|
83
93
|
}
|
|
84
94
|
|
|
85
|
-
return
|
|
95
|
+
return `${plus}${this.#factor.tex} ${rad}`
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
get display(): string {
|
|
89
|
-
|
|
99
|
+
const plus = this.#withSign && this.factor.isPositive() ? '+' : ''
|
|
100
|
+
|
|
101
|
+
// There is no radical - output the factor
|
|
102
|
+
if (this.#radical.isZero()) return `${plus}${this.#factor.display}`
|
|
103
|
+
|
|
104
|
+
// The radical has an index of 1 - no radical.
|
|
105
|
+
if (this.index === 1) return `${plus}${this.factor.clone().multiply(this.radical).display}`
|
|
106
|
+
|
|
107
|
+
// Make the root part
|
|
108
|
+
const rad = this.index === 2
|
|
109
|
+
? `sqrt(${this.#radical.tex})`
|
|
110
|
+
: `root(${this.index})(${this.#radical.display})`
|
|
111
|
+
|
|
112
|
+
if (this.#factor.isUnit()) return `${this.#factor.isOne() ? plus : '-'}${rad}`
|
|
113
|
+
|
|
114
|
+
return `${plus}${this.#factor.display}${rad}`
|
|
90
115
|
}
|
|
91
116
|
|
|
92
117
|
add(value: InputValue<Root>): this {
|
|
93
|
-
|
|
118
|
+
// start by reducing
|
|
119
|
+
this.reduce()
|
|
120
|
+
const rt = new Root(value).reduce()
|
|
94
121
|
|
|
95
122
|
if (
|
|
96
|
-
this.index !== rt.index
|
|
123
|
+
this.index !== rt.index ||
|
|
97
124
|
!this.radical.isEqual(rt.radical)
|
|
98
125
|
) {
|
|
99
126
|
throw new Error("Add can only be done with two same index and radical")
|
|
@@ -133,7 +160,6 @@ export class Root implements IPiMathObject<Root>, IExpression<Root> {
|
|
|
133
160
|
* convert to root(index)(radical), without factor
|
|
134
161
|
*/
|
|
135
162
|
group(): this {
|
|
136
|
-
|
|
137
163
|
this.radical.multiply(this.factor.pow(this.index))
|
|
138
164
|
this.factor.one()
|
|
139
165
|
|
|
@@ -169,6 +195,16 @@ export class Root implements IPiMathObject<Root>, IExpression<Root> {
|
|
|
169
195
|
return this.factor.isOne() && this.radical.isOne()
|
|
170
196
|
}
|
|
171
197
|
|
|
198
|
+
isRational(): boolean {
|
|
199
|
+
const reduced = this.clone().reduce()
|
|
200
|
+
|
|
201
|
+
if(reduced.radical.isOne()) return reduced.factor.exact
|
|
202
|
+
|
|
203
|
+
if(reduced.index===1) return reduced.factor.exact && reduced.radical.exact
|
|
204
|
+
|
|
205
|
+
return false
|
|
206
|
+
}
|
|
207
|
+
|
|
172
208
|
isZero(): boolean {
|
|
173
209
|
return this.factor.isZero() || this.radical.isZero()
|
|
174
210
|
}
|
|
@@ -238,8 +274,9 @@ export class Root implements IPiMathObject<Root>, IExpression<Root> {
|
|
|
238
274
|
|
|
239
275
|
// Extract the greatest root from.
|
|
240
276
|
const greatest = Numeric.greatestPower(this.radical.value, this.index)
|
|
241
|
-
|
|
242
|
-
this.
|
|
277
|
+
|
|
278
|
+
this.factor.multiply(Math.pow(greatest, 1 / this.index))
|
|
279
|
+
this.radical.divide(greatest)
|
|
243
280
|
|
|
244
281
|
return this
|
|
245
282
|
}
|
|
@@ -264,6 +301,16 @@ export class Root implements IPiMathObject<Root>, IExpression<Root> {
|
|
|
264
301
|
return Numeric.numberCorrection(this.factor.value * Math.pow(this.radical.value, 1 / this.index))
|
|
265
302
|
}
|
|
266
303
|
|
|
304
|
+
get withSign(): this {
|
|
305
|
+
this.#withSign = true
|
|
306
|
+
return this
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
get withoutSign(): this {
|
|
310
|
+
this.#withSign = false
|
|
311
|
+
return this
|
|
312
|
+
}
|
|
313
|
+
|
|
267
314
|
zero(): this {
|
|
268
315
|
this.radical.zero()
|
|
269
316
|
this.factor.zero()
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POint module contains everything necessary to handle 2d Points
|
|
3
|
+
* It's a "wrapper" of the Vector class.
|
|
4
|
+
* @module Point
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {Fraction} from "../coefficients"
|
|
8
|
+
import type {InputValue} from "../pimath.interface"
|
|
9
|
+
|
|
10
|
+
export abstract class TupleN {
|
|
11
|
+
#array: Fraction[] = []
|
|
12
|
+
#onChange?: () => void
|
|
13
|
+
|
|
14
|
+
constructor(...values: InputValue<Fraction>[]) {
|
|
15
|
+
this.#array = values.map(x => new Fraction(x))
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
public abstract clone(): void
|
|
19
|
+
|
|
20
|
+
public copy(): Fraction[] {
|
|
21
|
+
return this.#array.map(x => x.clone())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
abstract get tex(): string
|
|
25
|
+
|
|
26
|
+
abstract get display(): string
|
|
27
|
+
|
|
28
|
+
get array(): Fraction[] {
|
|
29
|
+
return this.#array
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
set array(value: Fraction[]) {
|
|
33
|
+
this.#array = value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get dimension(): number {
|
|
37
|
+
return this.array.length
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public fromString(value: string): this {
|
|
41
|
+
// Remove the first letter if it's a parenthesis.
|
|
42
|
+
if (value.startsWith('(')) {
|
|
43
|
+
value = value.substring(1)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Remove the last letter if it's a parenthesis.
|
|
47
|
+
if (value.endsWith(')')) {
|
|
48
|
+
value = value.substring(0, value.length - 1)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Split comma, semi colon or single space.
|
|
52
|
+
const components = value.split(/[,;\s]/g)
|
|
53
|
+
.filter((v) => v.trim() !== '')
|
|
54
|
+
|
|
55
|
+
// there must be at least two Pages.
|
|
56
|
+
if (components.length < 2) {
|
|
57
|
+
return this
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Validate the fraction values.
|
|
61
|
+
this.#array = components.map(x => new Fraction(x))
|
|
62
|
+
return this
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get onChange(): undefined | (() => void) {
|
|
66
|
+
return this.#onChange
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
set onChange(value: undefined | (() => void)) {
|
|
70
|
+
this.#onChange = value
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setDimension(value = 2): this {
|
|
74
|
+
if (value < 2) {
|
|
75
|
+
throw new Error('Dimension must be at least 2')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (value < this.dimension) {
|
|
79
|
+
this.#array = this.#array.slice(0, value)
|
|
80
|
+
} else if (value > this.dimension) {
|
|
81
|
+
for (let i = this.dimension; i < value; i++) {
|
|
82
|
+
this.#array.push(new Fraction(0))
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return this
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get x(): Fraction {
|
|
90
|
+
return this.#array[0]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
set x(value: Fraction | number | string) {
|
|
94
|
+
this.#array[0] = new Fraction(value)
|
|
95
|
+
this.#onChange?.()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get y(): Fraction {
|
|
99
|
+
return this.#array[1]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
set y(value: Fraction | number | string) {
|
|
103
|
+
this.#array[1] = new Fraction(value)
|
|
104
|
+
this.#onChange?.()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get z(): Fraction {
|
|
108
|
+
if (this.dimension < 3) {
|
|
109
|
+
throw new Error('Vector is not 3D')
|
|
110
|
+
}
|
|
111
|
+
return this.#array[2]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
set z(value: Fraction | number | string) {
|
|
115
|
+
if (this.dimension < 3) {
|
|
116
|
+
throw new Error('Vector is not 3D')
|
|
117
|
+
}
|
|
118
|
+
this.#array[2] = new Fraction(value)
|
|
119
|
+
this.#onChange?.()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
zero = (): this => {
|
|
123
|
+
this.#array.forEach(x => x.zero())
|
|
124
|
+
this.#onChange?.()
|
|
125
|
+
return this
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|