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.
Files changed (99) hide show
  1. package/dist/pimath.js +3106 -2873
  2. package/dist/pimath.js.map +1 -1
  3. package/package.json +13 -11
  4. package/src/algebra/equation.ts +113 -111
  5. package/src/algebra/equationSolver.ts +69 -120
  6. package/src/algebra/factor.ts +6 -7
  7. package/src/algebra/linearSystem.ts +97 -46
  8. package/src/algebra/logicalset.ts +51 -52
  9. package/src/algebra/monom.ts +23 -61
  10. package/src/algebra/operations.ts +0 -1
  11. package/src/algebra/polyFactor.ts +5 -5
  12. package/src/algebra/polynom.ts +69 -216
  13. package/src/analyze/index.ts +4 -0
  14. package/src/analyze/solution.ts +92 -29
  15. package/src/analyze/tableOfSigns.ts +1 -1
  16. package/src/coefficients/fraction.ts +189 -149
  17. package/src/coefficients/index.ts +1 -1
  18. package/src/coefficients/root.ts +66 -19
  19. package/src/geometry/TupleN.ts +128 -0
  20. package/src/geometry/circle.ts +308 -238
  21. package/src/geometry/geomMath.ts +4 -3
  22. package/src/geometry/index.ts +1 -0
  23. package/src/geometry/line.ts +221 -245
  24. package/src/geometry/line3.ts +78 -73
  25. package/src/geometry/plane3.ts +64 -55
  26. package/src/geometry/point.ts +57 -19
  27. package/src/geometry/triangle.ts +376 -248
  28. package/src/geometry/vector.ts +113 -229
  29. package/src/index.ts +13 -12
  30. package/src/numeric.ts +6 -9
  31. package/src/pimath.interface.ts +30 -28
  32. package/src/randomization/algebra/rndPolynom.ts +29 -15
  33. package/src/randomization/coefficient/rndFraction.ts +3 -3
  34. package/src/randomization/geometry/rndLine.ts +8 -10
  35. package/src/randomization/random.ts +11 -13
  36. package/src/randomization/rndTypes.ts +16 -12
  37. package/types/algebra/equation.d.ts +18 -17
  38. package/types/algebra/equation.d.ts.map +1 -1
  39. package/types/algebra/equationSolver.d.ts +5 -4
  40. package/types/algebra/equationSolver.d.ts.map +1 -1
  41. package/types/algebra/factor.d.ts +1 -1
  42. package/types/algebra/factor.d.ts.map +1 -1
  43. package/types/algebra/linearSystem.d.ts +23 -6
  44. package/types/algebra/linearSystem.d.ts.map +1 -1
  45. package/types/algebra/logicalset.d.ts +1 -1
  46. package/types/algebra/logicalset.d.ts.map +1 -1
  47. package/types/algebra/monom.d.ts +1 -6
  48. package/types/algebra/monom.d.ts.map +1 -1
  49. package/types/algebra/operations.d.ts.map +1 -1
  50. package/types/algebra/polyFactor.d.ts +4 -4
  51. package/types/algebra/polyFactor.d.ts.map +1 -1
  52. package/types/algebra/polynom.d.ts +10 -7
  53. package/types/algebra/polynom.d.ts.map +1 -1
  54. package/types/analyze/index.d.ts +2 -0
  55. package/types/analyze/index.d.ts.map +1 -0
  56. package/types/analyze/solution.d.ts +14 -8
  57. package/types/analyze/solution.d.ts.map +1 -1
  58. package/types/coefficients/fraction.d.ts +14 -12
  59. package/types/coefficients/fraction.d.ts.map +1 -1
  60. package/types/coefficients/index.d.ts +1 -1
  61. package/types/coefficients/index.d.ts.map +1 -1
  62. package/types/coefficients/root.d.ts +3 -0
  63. package/types/coefficients/root.d.ts.map +1 -1
  64. package/types/geometry/TupleAbstract.d.ts +22 -0
  65. package/types/geometry/TupleAbstract.d.ts.map +1 -0
  66. package/types/geometry/TupleN.d.ts +24 -0
  67. package/types/geometry/TupleN.d.ts.map +1 -0
  68. package/types/geometry/circle.d.ts +26 -17
  69. package/types/geometry/circle.d.ts.map +1 -1
  70. package/types/geometry/geomMath.d.ts +2 -1
  71. package/types/geometry/geomMath.d.ts.map +1 -1
  72. package/types/geometry/index.d.ts.map +1 -1
  73. package/types/geometry/line.d.ts +21 -30
  74. package/types/geometry/line.d.ts.map +1 -1
  75. package/types/geometry/line3.d.ts +19 -19
  76. package/types/geometry/line3.d.ts.map +1 -1
  77. package/types/geometry/matrix.d.ts +11 -11
  78. package/types/geometry/plane3.d.ts +10 -10
  79. package/types/geometry/plane3.d.ts.map +1 -1
  80. package/types/geometry/point.d.ts +11 -6
  81. package/types/geometry/point.d.ts.map +1 -1
  82. package/types/geometry/triangle.d.ts +68 -23
  83. package/types/geometry/triangle.d.ts.map +1 -1
  84. package/types/geometry/vector.d.ts +24 -44
  85. package/types/geometry/vector.d.ts.map +1 -1
  86. package/types/index.d.ts +5 -4
  87. package/types/index.d.ts.map +1 -1
  88. package/types/numeric.d.ts.map +1 -1
  89. package/types/pimath.interface.d.ts +18 -24
  90. package/types/pimath.interface.d.ts.map +1 -1
  91. package/types/randomization/algebra/rndPolynom.d.ts.map +1 -1
  92. package/types/randomization/coefficient/rndFraction.d.ts +1 -1
  93. package/types/randomization/coefficient/rndFraction.d.ts.map +1 -1
  94. package/types/randomization/geometry/rndLine.d.ts.map +1 -1
  95. package/types/randomization/random.d.ts +3 -2
  96. package/types/randomization/random.d.ts.map +1 -1
  97. package/types/randomization/rndTypes.d.ts +15 -10
  98. package/types/randomization/rndTypes.d.ts.map +1 -1
  99. 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.40",
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
- "autoprefixer": "^10.4.22",
42
- "dependency-cruiser": "^17.3.2",
43
- "eslint": "^9.39.1",
44
- "globals": "^16.5.0",
45
- "postcss": "^8.5.6",
46
- "tailwindcss": "^3.4.18",
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.15",
50
+ "typedoc": "^0.28.16",
50
51
  "typescript": "^5.9.3",
51
- "typescript-eslint": "^8.49.0",
52
- "vite": "^7.2.7",
52
+ "typescript-eslint": "^8.54.0",
53
+ "vite": "^7.3.1",
53
54
  "vite-plugin-dts": "^4.5.4",
54
- "vitest": "^4.0.15"
55
+ "vitest": "^4.0.18",
56
+ "vue-router": "^5.0.2"
55
57
  },
56
58
  "dependencies": {
57
59
  "piexpression": "^0.1.3"
@@ -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 { Fraction } from "../coefficients/fraction"
12
- import { Numeric } from "../numeric"
13
- import { EquationSolver } from "./equationSolver"
14
- import { Monom } from "./monom"
15
- import { Polynom } from "./polynom"
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
- // Equations operations
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 pow(value: number): this {
293
- this.#left.pow(value)
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 = (): ISolution[] => {
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
  }