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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pimath",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A math library for teacher :)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/pimath.js",
|
|
@@ -38,20 +38,22 @@
|
|
|
38
38
|
"url": "git+https://github.com/basilgass/PiMath.git"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
41
|
+
"@tailwindcss/vite": "^4.1.18",
|
|
42
|
+
"@vitejs/plugin-vue": "^6.0.4",
|
|
43
|
+
"autoprefixer": "^10.4.24",
|
|
44
|
+
"dependency-cruiser": "^17.3.8",
|
|
45
|
+
"eslint": "^9.39.2",
|
|
46
|
+
"globals": "^17.3.0",
|
|
47
|
+
"tailwindcss": "^4.1.18",
|
|
47
48
|
"ts-loader": "^9.5.4",
|
|
48
49
|
"ts-node": "^10.9.2",
|
|
49
|
-
"typedoc": "^0.28.
|
|
50
|
+
"typedoc": "^0.28.16",
|
|
50
51
|
"typescript": "^5.9.3",
|
|
51
|
-
"typescript-eslint": "^8.
|
|
52
|
-
"vite": "^7.
|
|
52
|
+
"typescript-eslint": "^8.54.0",
|
|
53
|
+
"vite": "^7.3.1",
|
|
53
54
|
"vite-plugin-dts": "^4.5.4",
|
|
54
|
-
"vitest": "^4.0.
|
|
55
|
+
"vitest": "^4.0.18",
|
|
56
|
+
"vue-router": "^5.0.2"
|
|
55
57
|
},
|
|
56
58
|
"dependencies": {
|
|
57
59
|
"piexpression": "^0.1.3"
|
package/src/algebra/equation.ts
CHANGED
|
@@ -5,14 +5,14 @@ import type {
|
|
|
5
5
|
InputAlgebra,
|
|
6
6
|
InputValue,
|
|
7
7
|
IPiMathObject,
|
|
8
|
-
ISolution,
|
|
9
8
|
literalType
|
|
10
9
|
} from "../pimath.interface"
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
10
|
+
import {Fraction} from "../coefficients/fraction"
|
|
11
|
+
import {Numeric} from "../numeric"
|
|
12
|
+
import {EquationSolver} from "./equationSolver"
|
|
13
|
+
import {Monom} from "./monom"
|
|
14
|
+
import {Polynom} from "./polynom"
|
|
15
|
+
import type {Solution} from "../analyze/solution"
|
|
16
16
|
|
|
17
17
|
export class Equation implements
|
|
18
18
|
IPiMathObject<Equation>,
|
|
@@ -72,17 +72,47 @@ export class Equation implements
|
|
|
72
72
|
return this.create(new Polynom(pStr[0]), new Polynom(pStr[1]), this.#formatSign(strSign))
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
public create = (left: Polynom, right: Polynom, sign?: string): this => {
|
|
76
|
-
this.#left = left
|
|
77
|
-
this.#right = right
|
|
78
|
-
this.#sign = this.#formatSign(sign ?? "=")
|
|
79
|
-
return this
|
|
80
|
-
}
|
|
81
|
-
|
|
82
75
|
public clone = (): Equation => {
|
|
83
76
|
return new Equation(this.#left.clone(), this.#right.clone(), this.#sign)
|
|
84
77
|
}
|
|
85
78
|
|
|
79
|
+
public get tex(): string {
|
|
80
|
+
return `${this.#left.tex}${this.signAsTex}${this.#right.tex}`
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public get display(): string {
|
|
84
|
+
return `${this.#left.display}${this.signAsTex}${this.#right.display}`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public static isEquationString(equationString: string): boolean {
|
|
88
|
+
// The equation sign can be one of the following:
|
|
89
|
+
// =, <, >, <=, >=
|
|
90
|
+
|
|
91
|
+
return equationString.includes('=') ||
|
|
92
|
+
equationString.includes('<') ||
|
|
93
|
+
equationString.includes('>') ||
|
|
94
|
+
equationString.includes('<=') ||
|
|
95
|
+
equationString.includes('>=')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public static makeSolutionsUnique(solutions: Solution[], sorted?: boolean): Solution[] {
|
|
99
|
+
const solutionAsTex: string[] = [],
|
|
100
|
+
uniqueSolutions = solutions.filter(sol => {
|
|
101
|
+
if (!solutionAsTex.includes(sol.tex)) {
|
|
102
|
+
solutionAsTex.push(sol.tex)
|
|
103
|
+
return true
|
|
104
|
+
} else {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
if (sorted === true) {
|
|
110
|
+
uniqueSolutions.sort((a, b) => a.value - b.value)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return uniqueSolutions
|
|
114
|
+
}
|
|
115
|
+
|
|
86
116
|
/**
|
|
87
117
|
* Add a value to the equation
|
|
88
118
|
* if value is an equation, add the left part to the left part of the equation
|
|
@@ -92,6 +122,7 @@ export class Equation implements
|
|
|
92
122
|
* @param value | Polynom | Monom | Fraction | string | monom
|
|
93
123
|
*/
|
|
94
124
|
public add(value: InputValue<Equation | Polynom>): this {
|
|
125
|
+
|
|
95
126
|
if (value instanceof Equation) {
|
|
96
127
|
// add the left part of the equation
|
|
97
128
|
this.#left.add(value.left)
|
|
@@ -114,6 +145,13 @@ export class Equation implements
|
|
|
114
145
|
return this
|
|
115
146
|
}
|
|
116
147
|
|
|
148
|
+
public create = (left: Polynom, right: Polynom, sign?: string): this => {
|
|
149
|
+
this.#left = left
|
|
150
|
+
this.#right = right
|
|
151
|
+
this.#sign = this.#formatSign(sign ?? "=")
|
|
152
|
+
return this
|
|
153
|
+
}
|
|
154
|
+
|
|
117
155
|
/**
|
|
118
156
|
* Get the degree of the equation
|
|
119
157
|
* @param letter
|
|
@@ -169,6 +207,8 @@ export class Equation implements
|
|
|
169
207
|
return (left as Fraction).isEqual(right as Fraction)
|
|
170
208
|
}
|
|
171
209
|
|
|
210
|
+
// -----------------------------------------------
|
|
211
|
+
|
|
172
212
|
/**
|
|
173
213
|
* Determine if the equation contains a variable.
|
|
174
214
|
* @param letter
|
|
@@ -177,12 +217,23 @@ export class Equation implements
|
|
|
177
217
|
return this.variables.includes(letter)
|
|
178
218
|
}
|
|
179
219
|
|
|
180
|
-
|
|
181
220
|
public isEqual(value: InputValue<Equation>): boolean {
|
|
182
221
|
const equ = new Equation(value)
|
|
183
222
|
return equ.left.isEqual(this.#left) && equ.right.isEqual(this.#right)
|
|
184
223
|
}
|
|
185
224
|
|
|
225
|
+
// -----------------------------------------------
|
|
226
|
+
// Equations operations
|
|
227
|
+
|
|
228
|
+
// Equations helpers
|
|
229
|
+
public isEqualTo = (equ: Equation): boolean => {
|
|
230
|
+
const p1 = equ.clone().moveLeft().left,
|
|
231
|
+
p2 = this.clone().moveLeft().left
|
|
232
|
+
|
|
233
|
+
// They are the same.
|
|
234
|
+
return p1.isEqual(p2) || p1.isOppositeAt(p2)
|
|
235
|
+
}
|
|
236
|
+
|
|
186
237
|
public isLinearTo = (equ: Equation): boolean => {
|
|
187
238
|
// Move all left.
|
|
188
239
|
const p1 = equ.clone().moveLeft().simplify().left,
|
|
@@ -199,16 +250,6 @@ export class Equation implements
|
|
|
199
250
|
return this.#left.isMultiVariable || this.#right.isMultiVariable
|
|
200
251
|
}
|
|
201
252
|
|
|
202
|
-
// -----------------------------------------------
|
|
203
|
-
// Equations helpers
|
|
204
|
-
public isEqualTo = (equ: Equation): boolean => {
|
|
205
|
-
const p1 = equ.clone().moveLeft().left,
|
|
206
|
-
p2 = this.clone().moveLeft().left
|
|
207
|
-
|
|
208
|
-
// They are the same.
|
|
209
|
-
return p1.isEqual(p2) || p1.isOppositeAt(p2)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
253
|
/**
|
|
213
254
|
* Reorder the polynom to have only one letter on the left, the rest on the right.
|
|
214
255
|
* @param letter
|
|
@@ -251,8 +292,14 @@ export class Equation implements
|
|
|
251
292
|
return this
|
|
252
293
|
}
|
|
253
294
|
|
|
254
|
-
//
|
|
255
|
-
|
|
295
|
+
// Getter and setter
|
|
296
|
+
public get left(): Polynom {
|
|
297
|
+
return this.#left
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public set left(value: Polynom) {
|
|
301
|
+
this.#left = value
|
|
302
|
+
}
|
|
256
303
|
|
|
257
304
|
// -----------------------------------------------
|
|
258
305
|
public letters = (): string[] => {
|
|
@@ -289,17 +336,22 @@ export class Equation implements
|
|
|
289
336
|
return this
|
|
290
337
|
}
|
|
291
338
|
|
|
292
|
-
public
|
|
293
|
-
this
|
|
294
|
-
this.#right.pow(value)
|
|
295
|
-
return this
|
|
339
|
+
public get numberOfVars(): number {
|
|
340
|
+
return this.variables.length
|
|
296
341
|
}
|
|
342
|
+
|
|
297
343
|
public opposite = (): this => {
|
|
298
344
|
this.#left = this.#left.opposite()
|
|
299
345
|
this.#right = this.#right.opposite()
|
|
300
346
|
return this
|
|
301
347
|
}
|
|
302
348
|
|
|
349
|
+
public pow(value: number): this {
|
|
350
|
+
this.#left.pow(value)
|
|
351
|
+
this.#right.pow(value)
|
|
352
|
+
return this
|
|
353
|
+
}
|
|
354
|
+
|
|
303
355
|
public reduce(): this {
|
|
304
356
|
// reduce means moving everything to the left
|
|
305
357
|
// remove the fractions
|
|
@@ -358,6 +410,36 @@ export class Equation implements
|
|
|
358
410
|
return this
|
|
359
411
|
}
|
|
360
412
|
|
|
413
|
+
public get right(): Polynom {
|
|
414
|
+
return this.#right
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
public set right(value: Polynom) {
|
|
418
|
+
this.#right = value
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ------------------------------------------
|
|
422
|
+
public get sign(): string {
|
|
423
|
+
return this.#sign
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
public set sign(value: string) {
|
|
427
|
+
// Set the sign value as formatted.
|
|
428
|
+
this.#sign = this.#formatSign(value)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
public get signAsTex(): string {
|
|
432
|
+
if (this.#sign === '>=') {
|
|
433
|
+
return '\\geq'
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (this.#sign === '<=') {
|
|
437
|
+
return '\\leq'
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return this.#sign
|
|
441
|
+
}
|
|
442
|
+
|
|
361
443
|
/**
|
|
362
444
|
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
363
445
|
*/
|
|
@@ -368,7 +450,7 @@ export class Equation implements
|
|
|
368
450
|
}
|
|
369
451
|
|
|
370
452
|
// -----------------------------------------------
|
|
371
|
-
public solve = ():
|
|
453
|
+
public solve = (): Solution[] => {
|
|
372
454
|
const solver = new EquationSolver(this.clone())
|
|
373
455
|
return solver.solve()
|
|
374
456
|
}
|
|
@@ -401,86 +483,6 @@ export class Equation implements
|
|
|
401
483
|
return (this.left.evaluate(values) as Fraction).isEqual(this.right.evaluate(values))
|
|
402
484
|
}
|
|
403
485
|
|
|
404
|
-
public static isEquationString(equationString: string): boolean {
|
|
405
|
-
// The equation sign can be one of the following:
|
|
406
|
-
// =, <, >, <=, >=
|
|
407
|
-
|
|
408
|
-
return equationString.includes('=') ||
|
|
409
|
-
equationString.includes('<') ||
|
|
410
|
-
equationString.includes('>') ||
|
|
411
|
-
equationString.includes('<=') ||
|
|
412
|
-
equationString.includes('>=')
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
public static makeSolutionsUnique(solutions: ISolution[], sorted?: boolean): ISolution[] {
|
|
416
|
-
const solutionAsTex: string[] = [],
|
|
417
|
-
uniqueSolutions = solutions.filter(sol => {
|
|
418
|
-
if (!solutionAsTex.includes(sol.tex)) {
|
|
419
|
-
solutionAsTex.push(sol.tex)
|
|
420
|
-
return true
|
|
421
|
-
} else {
|
|
422
|
-
return false
|
|
423
|
-
}
|
|
424
|
-
})
|
|
425
|
-
|
|
426
|
-
if (sorted === true) {
|
|
427
|
-
uniqueSolutions.sort((a, b) => a.value - b.value)
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
return uniqueSolutions
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
public get display(): string {
|
|
434
|
-
return `${this.#left.display}${this.signAsTex}${this.#right.display}`
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// Getter and setter
|
|
438
|
-
public get left(): Polynom {
|
|
439
|
-
return this.#left
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
public set left(value: Polynom) {
|
|
443
|
-
this.#left = value
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
public get numberOfVars(): number {
|
|
447
|
-
return this.variables.length
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
public get right(): Polynom {
|
|
451
|
-
return this.#right
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
public set right(value: Polynom) {
|
|
455
|
-
this.#right = value
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// ------------------------------------------
|
|
459
|
-
public get sign(): string {
|
|
460
|
-
return this.#sign
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
public set sign(value: string) {
|
|
464
|
-
// Set the sign value as formatted.
|
|
465
|
-
this.#sign = this.#formatSign(value)
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
public get signAsTex(): string {
|
|
469
|
-
if (this.#sign === '>=') {
|
|
470
|
-
return '\\geq'
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (this.#sign === '<=') {
|
|
474
|
-
return '\\leq'
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
return this.#sign
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
public get tex(): string {
|
|
481
|
-
return `${this.#left.tex}${this.signAsTex}${this.#right.tex}`
|
|
482
|
-
}
|
|
483
|
-
|
|
484
486
|
public get variables(): string[] {
|
|
485
487
|
return [...new Set(this.#right.variables.concat(this.#left.variables))]
|
|
486
488
|
}
|