pimath 0.1.39 → 0.2.0
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 +3127 -2865
- package/dist/pimath.js.map +1 -1
- package/package.json +16 -12
- package/src/algebra/equation.ts +558 -0
- package/src/algebra/equationSolver.ts +488 -0
- package/src/algebra/factor.ts +338 -0
- package/src/algebra/index.ts +11 -0
- package/src/algebra/linearSystem.ts +439 -0
- package/src/algebra/logicalset.ts +255 -0
- package/src/algebra/matrix.ts +474 -0
- package/src/algebra/monom.ts +977 -0
- package/src/algebra/operations.ts +23 -0
- package/src/algebra/polyFactor.ts +668 -0
- package/src/algebra/polynom.ts +1247 -0
- package/src/analyze/index.ts +4 -0
- package/src/analyze/solution.ts +178 -0
- package/src/analyze/tableOfSigns.ts +30 -0
- package/src/coefficients/fraction.ts +718 -0
- package/src/coefficients/index.ts +4 -0
- package/src/coefficients/root.ts +346 -0
- package/src/geometry/TupleN.ts +128 -0
- package/src/geometry/circle.ts +456 -0
- package/src/geometry/geomMath.ts +71 -0
- package/src/geometry/index.ts +11 -0
- package/src/geometry/line.ts +653 -0
- package/src/geometry/line3.ts +211 -0
- package/src/geometry/plane3.ts +179 -0
- package/src/geometry/point.ts +104 -0
- package/src/geometry/sphere3.ts +214 -0
- package/src/geometry/triangle.ts +482 -0
- package/src/geometry/vector.ts +225 -0
- package/src/helpers.ts +35 -0
- package/src/index.ts +61 -0
- package/src/numeric.ts +196 -0
- package/src/pimath.interface.ts +162 -0
- package/src/randomization/algebra/rndEquation.ts +41 -0
- package/src/randomization/algebra/rndMonom.ts +39 -0
- package/src/randomization/algebra/rndPolynom.ts +100 -0
- package/src/randomization/coefficient/rndFraction.ts +38 -0
- package/src/randomization/geometry/rndCircle.ts +27 -0
- package/src/randomization/geometry/rndLine.ts +35 -0
- package/src/randomization/geometry/rndLine3.ts +27 -0
- package/src/randomization/geometry/rndVector.ts +63 -0
- package/src/randomization/random.ts +89 -0
- package/src/randomization/rndHelpers.ts +102 -0
- package/src/randomization/rndTypes.ts +67 -0
- package/types/algebra/equation.d.ts +18 -17
- package/types/algebra/equation.d.ts.map +1 -1
- package/types/algebra/equationSolver.d.ts +7 -3
- 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 +9 -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 +27 -0
- package/types/analyze/solution.d.ts.map +1 -0
- package/types/analyze/tableOfSigns.d.ts +9 -0
- package/types/analyze/tableOfSigns.d.ts.map +1 -0
- 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 +41 -0
- package/types/coefficients/root.d.ts.map +1 -0
- 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 +9 -9
- package/types/geometry/plane3.d.ts.map +1 -1
- package/types/geometry/point.d.ts +12 -7
- 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/helpers.d.ts +1 -0
- package/types/helpers.d.ts.map +1 -1
- package/types/index.d.ts +6 -4
- package/types/index.d.ts.map +1 -1
- package/types/numeric.d.ts +2 -0
- package/types/numeric.d.ts.map +1 -1
- package/types/pimath.interface.d.ts +38 -44
- 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
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type {InputValue} from "../pimath.interface"
|
|
2
|
+
import {Fraction} from "../coefficients"
|
|
3
|
+
import {Root} from "../coefficients/root"
|
|
4
|
+
|
|
5
|
+
export class Solution {
|
|
6
|
+
#count: number
|
|
7
|
+
#display: string | null
|
|
8
|
+
#exact: boolean
|
|
9
|
+
#fraction: Fraction
|
|
10
|
+
#root: Root
|
|
11
|
+
#tex: string | null
|
|
12
|
+
#variable: string
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
this.#variable = 'x'
|
|
16
|
+
this.#exact = false
|
|
17
|
+
|
|
18
|
+
this.#display = null
|
|
19
|
+
this.#tex = null
|
|
20
|
+
|
|
21
|
+
this.#fraction = new Fraction().zero()
|
|
22
|
+
this.#root = new Root()
|
|
23
|
+
this.#count = 1
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get tex(): string {
|
|
27
|
+
if (this.#tex) return this.#tex
|
|
28
|
+
|
|
29
|
+
if (this.#root.isZero()) return this.#fraction.tex
|
|
30
|
+
|
|
31
|
+
if (this.#fraction.isZero()) return this.#root.tex
|
|
32
|
+
|
|
33
|
+
const [f] = Fraction.toSameDenominateur(this.#fraction, this.#root.factor)
|
|
34
|
+
|
|
35
|
+
const R = this.#root.clone().multiply(f.denominator).reduce()
|
|
36
|
+
const num = `${f.numerator} ${R.withSign.tex}`
|
|
37
|
+
|
|
38
|
+
if (f.denominator === 1) return num
|
|
39
|
+
|
|
40
|
+
return `\\frac{ ${num} }{ ${f.denominator} }`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set tex(value: string | null) {
|
|
44
|
+
this.#tex = value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get display(): string | null {
|
|
48
|
+
if(this.#display) return this.#display
|
|
49
|
+
|
|
50
|
+
if (this.#root.isZero()) return this.#fraction.display
|
|
51
|
+
|
|
52
|
+
if (this.#fraction.isZero()) return this.#root.display
|
|
53
|
+
|
|
54
|
+
const [f] = Fraction.toSameDenominateur(this.#fraction, this.#root.factor)
|
|
55
|
+
|
|
56
|
+
const R = this.#root.clone().multiply(f.denominator).reduce()
|
|
57
|
+
const num = `${f.numerator}${R.withSign.display}`
|
|
58
|
+
|
|
59
|
+
if (f.denominator === 1) return num
|
|
60
|
+
|
|
61
|
+
return `(${num})/${f.denominator}`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
set display(value: string | null) {
|
|
65
|
+
this.#display = value
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static fromFraction(value: InputValue<Fraction>): Solution {
|
|
69
|
+
const sol = new Solution()
|
|
70
|
+
sol.setExact()
|
|
71
|
+
|
|
72
|
+
const F = new Fraction(value)
|
|
73
|
+
sol.display = F.display
|
|
74
|
+
sol.tex = F.tex
|
|
75
|
+
|
|
76
|
+
sol.fraction = F
|
|
77
|
+
sol.root = new Root()
|
|
78
|
+
|
|
79
|
+
return sol
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static fromQuadratic(A: InputValue<Fraction>, B: InputValue<Fraction>, C: InputValue<Fraction>): Solution[] {
|
|
83
|
+
const [a, b, c] = [A, B, C].map(x => new Fraction(x))
|
|
84
|
+
|
|
85
|
+
// D = b^2-4ac
|
|
86
|
+
const delta2 = b.clone().pow(2).subtract(a.clone().multiply(c).multiply(4))
|
|
87
|
+
if (delta2.isNegative()) {
|
|
88
|
+
return []
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (delta2.isSquare()) {
|
|
92
|
+
const delta = delta2.sqrt()
|
|
93
|
+
const root1 = b.clone().opposite().subtract(delta).divide(a.clone().multiply(2))
|
|
94
|
+
const root2 = b.clone().opposite().add(delta).divide(a.clone().multiply(2))
|
|
95
|
+
|
|
96
|
+
return delta.isZero()
|
|
97
|
+
? [Solution.fromFraction(root1)]
|
|
98
|
+
: [Solution.fromFraction(root1), Solution.fromFraction(root2)]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const sol1 = new Solution()
|
|
102
|
+
sol1.fraction = b.clone().opposite().divide(a).divide(2)
|
|
103
|
+
sol1.root = new Root().from(2, delta2, a.clone().multiply(2).inverse().opposite())
|
|
104
|
+
sol1.setExact(false)
|
|
105
|
+
|
|
106
|
+
const sol2 = new Solution()
|
|
107
|
+
sol2.fraction = b.clone().opposite().divide(a).divide(2)
|
|
108
|
+
sol2.root = new Root().from(2, delta2, a.clone().multiply(2).inverse())
|
|
109
|
+
sol2.setExact(false)
|
|
110
|
+
|
|
111
|
+
return [sol1, sol2]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get count(): number {
|
|
115
|
+
return this.#count
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
set count(value: number) {
|
|
119
|
+
this.#count = value
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get exact(): boolean {
|
|
123
|
+
return this.#exact
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
set exact(value: boolean) {
|
|
127
|
+
this.#exact = value
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get fraction(): Fraction {
|
|
131
|
+
return this.#fraction
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
set fraction(value: Fraction) {
|
|
135
|
+
this.#fraction = value
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
isZero(): boolean {
|
|
139
|
+
return this.#fraction.isZero() && this.#root.isZero()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
reduce(): this {
|
|
143
|
+
// Reduce the root
|
|
144
|
+
this.#root.reduce()
|
|
145
|
+
this.#fraction.reduce()
|
|
146
|
+
|
|
147
|
+
return this
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get root(): Root {
|
|
151
|
+
return this.#root
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
set root(value: Root) {
|
|
155
|
+
this.#root = value
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setExact(value = true): this {
|
|
159
|
+
this.#exact = value
|
|
160
|
+
return this
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
get value(): number {
|
|
164
|
+
return this.fraction.value + this.root.value
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get variable(): string {
|
|
168
|
+
return this.#variable
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
set variable(value: string | undefined) {
|
|
172
|
+
if (value === undefined) {
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this.#variable = value
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
// TODO: move the TableOfSigns asSystem to a custom class.
|
|
3
|
+
|
|
4
|
+
import {Factor, PolyFactor, Polynom} from "../algebra"
|
|
5
|
+
import type {InputAlgebra} from "../pimath.interface"
|
|
6
|
+
import type {Solution} from "./solution"
|
|
7
|
+
|
|
8
|
+
export class TableOfSigns {
|
|
9
|
+
#fx: PolyFactor
|
|
10
|
+
#roots: Solution[]
|
|
11
|
+
constructor(value: InputAlgebra<PolyFactor | Factor | Polynom >) {
|
|
12
|
+
if(value instanceof PolyFactor || value instanceof Factor) {
|
|
13
|
+
this.#fx = new PolyFactor(value)
|
|
14
|
+
}else{
|
|
15
|
+
this.#fx = new PolyFactor().fromPolynom(value)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Factorize de PolyFactor.
|
|
19
|
+
this.#roots = this.#fx.getRoots()
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get fx() {
|
|
24
|
+
return this.#fx
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get roots() {
|
|
28
|
+
return this.#roots
|
|
29
|
+
}
|
|
30
|
+
}
|