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
|
@@ -33,58 +33,6 @@ export class LogicalSet {
|
|
|
33
33
|
return this
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
evaluate(values: Record<string, boolean>): boolean {
|
|
37
|
-
// Add missing key(s) and set them as false by default.
|
|
38
|
-
this.variables.forEach(key => {
|
|
39
|
-
if (!Object.hasOwn(values, key)) {
|
|
40
|
-
values[key] = false
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const stack: boolean[] = []
|
|
45
|
-
for (const token of this.#rpn) {
|
|
46
|
-
console.log(token)
|
|
47
|
-
if (token.tokenType === 'variable') {
|
|
48
|
-
stack.push(values[token.token])
|
|
49
|
-
} else if (token.tokenType === 'operation') {
|
|
50
|
-
if (token.token === '!') {
|
|
51
|
-
// need only one item from stack
|
|
52
|
-
if (stack.length >= 1) {
|
|
53
|
-
const a = stack.pop()
|
|
54
|
-
stack.push(!a)
|
|
55
|
-
} else {
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
// All other operations needs two items from stack
|
|
60
|
-
const a = stack.pop()
|
|
61
|
-
const b = stack.pop()
|
|
62
|
-
if (a !== undefined && b !== undefined) {
|
|
63
|
-
switch (token.token) {
|
|
64
|
-
case "&":
|
|
65
|
-
stack.push(a && b)
|
|
66
|
-
break
|
|
67
|
-
case "|":
|
|
68
|
-
stack.push(a || b)
|
|
69
|
-
break
|
|
70
|
-
case "-":
|
|
71
|
-
return false
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
} else {
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return stack.length === 1 && stack[0]
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get rpn(): { token: string, tokenType: string }[] {
|
|
85
|
-
return this.#rpn
|
|
86
|
-
}
|
|
87
|
-
|
|
88
36
|
get tex(): string {
|
|
89
37
|
const varStack: { token: string, tokenType: string }[] = []
|
|
90
38
|
|
|
@@ -157,6 +105,57 @@ export class LogicalSet {
|
|
|
157
105
|
return varStack[0].token
|
|
158
106
|
}
|
|
159
107
|
|
|
108
|
+
evaluate(values: Record<string, boolean>): boolean {
|
|
109
|
+
// Add missing key(s) and set them as false by default.
|
|
110
|
+
this.variables.forEach(key => {
|
|
111
|
+
if (!Object.hasOwn(values, key)) {
|
|
112
|
+
values[key] = false
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const stack: boolean[] = []
|
|
117
|
+
for (const token of this.#rpn) {
|
|
118
|
+
if (token.tokenType === 'variable') {
|
|
119
|
+
stack.push(values[token.token])
|
|
120
|
+
} else if (token.tokenType === 'operation') {
|
|
121
|
+
if (token.token === '!') {
|
|
122
|
+
// need only one item from stack
|
|
123
|
+
if (stack.length >= 1) {
|
|
124
|
+
const a = stack.pop()
|
|
125
|
+
stack.push(!a)
|
|
126
|
+
} else {
|
|
127
|
+
return false
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
// All other operations needs two items from stack
|
|
131
|
+
const a = stack.pop()
|
|
132
|
+
const b = stack.pop()
|
|
133
|
+
if (a !== undefined && b !== undefined) {
|
|
134
|
+
switch (token.token) {
|
|
135
|
+
case "&":
|
|
136
|
+
stack.push(a && b)
|
|
137
|
+
break
|
|
138
|
+
case "|":
|
|
139
|
+
stack.push(a || b)
|
|
140
|
+
break
|
|
141
|
+
case "-":
|
|
142
|
+
return false
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
} else {
|
|
146
|
+
return false
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return stack.length === 1 && stack[0]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
get rpn(): { token: string, tokenType: string }[] {
|
|
156
|
+
return this.#rpn
|
|
157
|
+
}
|
|
158
|
+
|
|
160
159
|
get variables(): string[] {
|
|
161
160
|
return this.#rpn
|
|
162
161
|
.filter(value => value.tokenType === 'variable')
|
package/src/algebra/monom.ts
CHANGED
|
@@ -10,8 +10,7 @@ import type {
|
|
|
10
10
|
IPiMathObject,
|
|
11
11
|
literalType
|
|
12
12
|
} from "../pimath.interface"
|
|
13
|
-
import {Fraction} from "../coefficients
|
|
14
|
-
import {NthRoot} from "../coefficients/nthRoot"
|
|
13
|
+
import {Fraction} from "../coefficients"
|
|
15
14
|
import {Numeric} from "../numeric"
|
|
16
15
|
|
|
17
16
|
import {ShutingYard, ShutingyardType, type Token} from "piexpression"
|
|
@@ -44,23 +43,30 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
44
43
|
this.#coefficient = new Fraction()
|
|
45
44
|
this.#literal = {}
|
|
46
45
|
|
|
47
|
-
if (
|
|
48
|
-
if(!isNaN(Number(inputStr))){
|
|
49
|
-
this.#coefficient = new Fraction(Number(inputStr))
|
|
50
|
-
}else {
|
|
51
|
-
this.#shutingYardToReducedMonom(inputStr)
|
|
52
|
-
}
|
|
53
|
-
} else if (typeof inputStr === 'number') {
|
|
54
|
-
this.#coefficient = new Fraction(inputStr)
|
|
55
|
-
} else if (inputStr instanceof Fraction) {
|
|
56
|
-
this.#coefficient = inputStr.clone()
|
|
57
|
-
} else if (inputStr instanceof Monom) {
|
|
46
|
+
if (inputStr instanceof Monom) {
|
|
58
47
|
this.#coefficient = inputStr.#coefficient.clone()
|
|
59
48
|
|
|
60
49
|
// Copy the literal parts
|
|
61
50
|
this.#cloneLiteral(inputStr)
|
|
51
|
+
return this
|
|
62
52
|
}
|
|
63
53
|
|
|
54
|
+
if (inputStr instanceof Fraction) {
|
|
55
|
+
this.#coefficient = inputStr.clone()
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (typeof inputStr === 'number') {
|
|
60
|
+
this.#coefficient = new Fraction(inputStr)
|
|
61
|
+
return this
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if (!isNaN(Number(inputStr))) {
|
|
66
|
+
this.#coefficient = new Fraction(Number(inputStr))
|
|
67
|
+
} else {
|
|
68
|
+
this.#shutingYardToReducedMonom(inputStr)
|
|
69
|
+
}
|
|
64
70
|
return this
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -83,8 +89,6 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
83
89
|
* Get the tex output of the monom
|
|
84
90
|
*/
|
|
85
91
|
public get tex(): string {
|
|
86
|
-
// TODO: display with square root !
|
|
87
|
-
// TODO: Refactor to make it more readable
|
|
88
92
|
let L = ''
|
|
89
93
|
const letters = Object.keys(this.#literal).sort()
|
|
90
94
|
|
|
@@ -92,7 +96,7 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
92
96
|
if (this.#literal[letter].isNotZero()) {
|
|
93
97
|
L += letter
|
|
94
98
|
if (this.#literal[letter].isNotEqual(1)) {
|
|
95
|
-
L += `^{ ${this.#literal[letter].tfrac.tex
|
|
99
|
+
L += `^{ ${this.#literal[letter].tfrac.tex} }`
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
102
|
}
|
|
@@ -265,12 +269,8 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
265
269
|
* Derivative the monom
|
|
266
270
|
* @param letter
|
|
267
271
|
*/
|
|
268
|
-
public derivative = (letter
|
|
272
|
+
public derivative = (letter = 'x'): Monom => {
|
|
269
273
|
// No setLetter given - assume it's the setLetter 'x'
|
|
270
|
-
if (letter === undefined) {
|
|
271
|
-
letter = 'x'
|
|
272
|
-
}
|
|
273
|
-
|
|
274
274
|
if (this.hasVariable(letter)) {
|
|
275
275
|
const d = this.#literal[letter].clone(),
|
|
276
276
|
dM = this.clone()
|
|
@@ -383,11 +383,6 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
383
383
|
return this.#evaluateAsNumeric(values.value)
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
-
// If the value is a NthRoot, return undefined
|
|
387
|
-
if (values instanceof NthRoot) {
|
|
388
|
-
return new Fraction().invalid()
|
|
389
|
-
}
|
|
390
|
-
|
|
391
386
|
// If the value is a number, return the numeric value
|
|
392
387
|
if (typeof values === 'number') {
|
|
393
388
|
return this.#evaluateAsNumeric(values)
|
|
@@ -414,10 +409,6 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
414
409
|
return this.evaluate(tmpValues)
|
|
415
410
|
}
|
|
416
411
|
|
|
417
|
-
if (values instanceof NthRoot) {
|
|
418
|
-
return new Fraction().invalid()
|
|
419
|
-
}
|
|
420
|
-
|
|
421
412
|
if (typeof values === 'object') {
|
|
422
413
|
if (this.variables.length === 0) {
|
|
423
414
|
return this.coefficient
|
|
@@ -443,7 +434,7 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
443
434
|
return Object.hasOwn(this.#literal, letter ?? 'x')
|
|
444
435
|
}
|
|
445
436
|
|
|
446
|
-
public integrate(a: InputValue<Fraction>, b: InputValue<Fraction>, letter?: string
|
|
437
|
+
public integrate(a: InputValue<Fraction>, b: InputValue<Fraction>, letter?: string): Fraction {
|
|
447
438
|
const primitive = this.primitive(letter)
|
|
448
439
|
|
|
449
440
|
return (primitive.evaluate(b) as Fraction)
|
|
@@ -583,30 +574,11 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
583
574
|
this.#literal = L
|
|
584
575
|
}
|
|
585
576
|
|
|
586
|
-
/**
|
|
587
|
-
* Get the literal square roots of the Monom.
|
|
588
|
-
* @returns {literalType<Fraction>}
|
|
589
|
-
*/
|
|
590
|
-
public get literalSqrt(): literalType<Fraction> {
|
|
591
|
-
// TODO: used in Polynom._factorize2ndDegree : remove it from here ?
|
|
592
|
-
if (this.isLiteralSquare()) {
|
|
593
|
-
const L: literalType<Fraction> = {}
|
|
594
|
-
for (const key in this.#literal) {
|
|
595
|
-
L[key] = this.#literal[key].clone().sqrt()
|
|
596
|
-
}
|
|
597
|
-
return L
|
|
598
|
-
} else {
|
|
599
|
-
return this.#literal
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
577
|
/**
|
|
604
578
|
* Set the literal part of the monom from a string
|
|
605
579
|
* @param inputStr String like x^2y^3
|
|
606
580
|
*/
|
|
607
581
|
public set literalStr(inputStr: string) {
|
|
608
|
-
// TODO : parse using ShutingYard tree !
|
|
609
|
-
|
|
610
582
|
// Match all x^n
|
|
611
583
|
for (const v of [...inputStr.matchAll(/([a-z])\^([+-]?[0-9]+)/g)]) {
|
|
612
584
|
// Create the default letter entry if necessary.
|
|
@@ -615,7 +587,6 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
615
587
|
}
|
|
616
588
|
|
|
617
589
|
// Add the new value.
|
|
618
|
-
// TODO: actually, it adds only numeric value
|
|
619
590
|
this.#literal[v[1]].add(+v[2])
|
|
620
591
|
}
|
|
621
592
|
|
|
@@ -719,12 +690,7 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
719
690
|
return this
|
|
720
691
|
}
|
|
721
692
|
|
|
722
|
-
public primitive = (letter
|
|
723
|
-
// TODO: derivative including the ln value => implies creating different monom system ?
|
|
724
|
-
if (letter === undefined) {
|
|
725
|
-
letter = 'x'
|
|
726
|
-
}
|
|
727
|
-
|
|
693
|
+
public primitive = (letter = 'x'): Monom => {
|
|
728
694
|
// Zero monom
|
|
729
695
|
const M = this.clone()
|
|
730
696
|
let degree: Fraction
|
|
@@ -880,10 +846,6 @@ export class Monom implements IPiMathObject<Monom>, IExpression<Monom>, IAnalyse
|
|
|
880
846
|
return this.#evaluateAsNumeric(tmpValues)
|
|
881
847
|
}
|
|
882
848
|
|
|
883
|
-
if (values instanceof NthRoot) {
|
|
884
|
-
return NaN
|
|
885
|
-
}
|
|
886
|
-
|
|
887
849
|
if (typeof values === 'object') {
|
|
888
850
|
if (this.variables.length === 0) {
|
|
889
851
|
return this.coefficient.value
|
|
@@ -2,7 +2,6 @@ import type {IExpressionMultiply, IPiMathObject} from "../pimath.interface"
|
|
|
2
2
|
|
|
3
3
|
// TODO: create other operation_** to make things more generic !
|
|
4
4
|
export function operation_pow<T extends IPiMathObject<T> & IExpressionMultiply<T>>(item: T, value: number): T {
|
|
5
|
-
// TODO: Implement the operation_pow to other classes
|
|
6
5
|
if (!Number.isSafeInteger(value)) {
|
|
7
6
|
throw new Error('Can only raise item by an integer')
|
|
8
7
|
}
|
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
InputAlgebra,
|
|
6
6
|
InputValue,
|
|
7
7
|
IPiMathObject,
|
|
8
|
-
ISolution,
|
|
9
8
|
literalType,
|
|
10
9
|
POLYFACTOR_TABLE_OF_SIGNS,
|
|
11
10
|
TABLE_OF_SIGNS_VALUES
|
|
@@ -24,12 +23,12 @@ export class PolyFactor implements IPiMathObject<PolyFactor>,
|
|
|
24
23
|
#displayMode: FACTOR_DISPLAY = FACTOR_DISPLAY.POWER
|
|
25
24
|
#factors: Factor[] = []
|
|
26
25
|
|
|
27
|
-
constructor(...values: (Factor | PolyFactor)[]) {
|
|
26
|
+
constructor(...values: (InputAlgebra<Polynom> | Factor | PolyFactor)[]) {
|
|
28
27
|
this.parse(...values)
|
|
29
28
|
return this
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
public parse(...values: (Factor | PolyFactor)[]): this {
|
|
31
|
+
public parse(...values: (InputAlgebra<Polynom> | Factor | PolyFactor)[]): this {
|
|
33
32
|
// Init the factors list
|
|
34
33
|
this.#factors = []
|
|
35
34
|
|
|
@@ -363,9 +362,9 @@ export class PolyFactor implements IPiMathObject<PolyFactor>,
|
|
|
363
362
|
return []
|
|
364
363
|
}
|
|
365
364
|
|
|
366
|
-
public getZeroes():
|
|
365
|
+
public getZeroes(): Solution[] {
|
|
367
366
|
// Calculate the list of roots (ordered, unique)
|
|
368
|
-
const roots:
|
|
367
|
+
const roots: Solution[] = ([] as Solution[])
|
|
369
368
|
.concat(...this.#factors.map(x => x.polynom.getZeroes()))
|
|
370
369
|
// .concat(...tos.map(x => x.roots))
|
|
371
370
|
|
|
@@ -530,6 +529,7 @@ export class PolyFactor implements IPiMathObject<PolyFactor>,
|
|
|
530
529
|
return {factor: new Factor(factor), ...factor.tableOfSigns()}
|
|
531
530
|
})
|
|
532
531
|
|
|
532
|
+
|
|
533
533
|
// Build the table of signs with extra roots for each factors.
|
|
534
534
|
factors.forEach(item => {
|
|
535
535
|
// Create the new signs row
|