pimath 0.1.39 → 0.1.40
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 +188 -159
- package/dist/pimath.js.map +1 -1
- package/package.json +4 -2
- package/src/algebra/equation.ts +556 -0
- package/src/algebra/equationSolver.ts +539 -0
- package/src/algebra/factor.ts +339 -0
- package/src/algebra/index.ts +11 -0
- package/src/algebra/linearSystem.ts +388 -0
- package/src/algebra/logicalset.ts +256 -0
- package/src/algebra/matrix.ts +474 -0
- package/src/algebra/monom.ts +1015 -0
- package/src/algebra/operations.ts +24 -0
- package/src/algebra/polyFactor.ts +668 -0
- package/src/algebra/polynom.ts +1394 -0
- package/src/analyze/solution.ts +115 -0
- package/src/analyze/tableOfSigns.ts +30 -0
- package/src/coefficients/fraction.ts +678 -0
- package/src/coefficients/index.ts +4 -0
- package/src/coefficients/nthRoot.ts +149 -0
- package/src/coefficients/root.ts +299 -0
- package/src/geometry/circle.ts +386 -0
- package/src/geometry/geomMath.ts +70 -0
- package/src/geometry/index.ts +10 -0
- package/src/geometry/line.ts +677 -0
- package/src/geometry/line3.ts +206 -0
- package/src/geometry/plane3.ts +170 -0
- package/src/geometry/point.ts +66 -0
- package/src/geometry/sphere3.ts +214 -0
- package/src/geometry/triangle.ts +354 -0
- package/src/geometry/vector.ts +341 -0
- package/src/helpers.ts +35 -0
- package/src/index.ts +60 -0
- package/src/numeric.ts +199 -0
- package/src/pimath.interface.ts +160 -0
- package/src/randomization/algebra/rndEquation.ts +41 -0
- package/src/randomization/algebra/rndMonom.ts +39 -0
- package/src/randomization/algebra/rndPolynom.ts +86 -0
- package/src/randomization/coefficient/rndFraction.ts +38 -0
- package/src/randomization/geometry/rndCircle.ts +27 -0
- package/src/randomization/geometry/rndLine.ts +37 -0
- package/src/randomization/geometry/rndLine3.ts +27 -0
- package/src/randomization/geometry/rndVector.ts +63 -0
- package/src/randomization/random.ts +91 -0
- package/src/randomization/rndHelpers.ts +102 -0
- package/src/randomization/rndTypes.ts +63 -0
- package/types/algebra/equationSolver.d.ts +3 -0
- package/types/algebra/equationSolver.d.ts.map +1 -1
- package/types/algebra/polyFactor.d.ts +5 -0
- package/types/algebra/polyFactor.d.ts.map +1 -1
- package/types/analyze/solution.d.ts +21 -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/root.d.ts +38 -0
- package/types/coefficients/root.d.ts.map +1 -0
- package/types/geometry/point.d.ts +1 -1
- package/types/geometry/point.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 +1 -0
- 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 +26 -26
- package/types/pimath.interface.d.ts.map +1 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// TODO: remplacer ISolution par Solution, qui sera plus robuste et extensible
|
|
2
|
+
|
|
3
|
+
import type {InputValue} from "../pimath.interface"
|
|
4
|
+
import {Fraction} from "../coefficients"
|
|
5
|
+
|
|
6
|
+
export class Solution {
|
|
7
|
+
#display: string
|
|
8
|
+
#exact: boolean
|
|
9
|
+
#isZero: boolean
|
|
10
|
+
#tex: string
|
|
11
|
+
#variable: string
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this.#variable = 'x'
|
|
15
|
+
this.#exact = false
|
|
16
|
+
this.#isZero = true
|
|
17
|
+
|
|
18
|
+
this.#display = '?'
|
|
19
|
+
this.#tex = '?'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get tex(): string {
|
|
23
|
+
return this.#tex
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set tex(value: string) {
|
|
27
|
+
this.#tex = value
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get display(): string {
|
|
31
|
+
return this.#display
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
set display(value: string) {
|
|
35
|
+
this.#display = value
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static fromFraction(value: InputValue<Fraction>): Solution {
|
|
39
|
+
const sol = new Solution()
|
|
40
|
+
sol.isExact()
|
|
41
|
+
|
|
42
|
+
const F = new Fraction(value)
|
|
43
|
+
sol.display = F.display
|
|
44
|
+
sol.tex = F.tex
|
|
45
|
+
|
|
46
|
+
return sol
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static fromQuadratic(values: [InputValue<Fraction>, InputValue<Fraction>, InputValue<Fraction>]): Solution[] {
|
|
50
|
+
const [a, b, c] = values.map(x => new Fraction(x))
|
|
51
|
+
|
|
52
|
+
// D = b^2-4ac
|
|
53
|
+
const delta2 = b.clone().pow(2).subtract(a.clone().multiply(c).multiply(4))
|
|
54
|
+
if (delta2.isNegative()) {
|
|
55
|
+
return []
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (delta2.isSquare()) {
|
|
59
|
+
const delta = delta2.sqrt()
|
|
60
|
+
const root1 = b.clone().opposite().subtract(delta).divide(a.clone().multiply(2))
|
|
61
|
+
const root2 = b.clone().opposite().add(delta).divide(a.clone().multiply(2))
|
|
62
|
+
|
|
63
|
+
return delta.isZero()
|
|
64
|
+
? [Solution.fromFraction(root1)]
|
|
65
|
+
: [Solution.fromFraction(root1), Solution.fromFraction(root2)]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const solutions = [new Solution(), new Solution()]
|
|
69
|
+
solutions.forEach(sol=> sol.isExact(false))
|
|
70
|
+
|
|
71
|
+
return solutions
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get exact(): boolean {
|
|
75
|
+
return this.#exact
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
set exact(value: boolean) {
|
|
79
|
+
this.#exact = value
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
isAZero(value = true): this {
|
|
83
|
+
this.#isZero = value
|
|
84
|
+
return this
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
isExact(value = true): this {
|
|
88
|
+
this.#exact = value
|
|
89
|
+
return this
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get isZero(): boolean {
|
|
93
|
+
return this.#isZero
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
set isZero(value: boolean) {
|
|
97
|
+
this.#isZero = value
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get value(): number {
|
|
101
|
+
throw new Error("To be implemented")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get variable(): string {
|
|
105
|
+
return this.#variable
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
set variable(value: string | undefined) {
|
|
109
|
+
if (value === undefined) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.#variable = value
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
// TODO: move the TableOfSigns system 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
|
+
}
|