pimath 0.0.131 → 0.0.133

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 (33) hide show
  1. package/dist/main.d.ts +39 -1
  2. package/package.json +2 -3
  3. package/dist/maths/pimath.d.ts +0 -39
  4. package/lib/main.ts +0 -1
  5. package/lib/maths/algebra/equation.ts +0 -891
  6. package/lib/maths/algebra/linearSystem.ts +0 -369
  7. package/lib/maths/algebra/logicalset.ts +0 -183
  8. package/lib/maths/algebra/monom.ts +0 -1027
  9. package/lib/maths/algebra/polynom.ts +0 -1537
  10. package/lib/maths/algebra/rational.ts +0 -244
  11. package/lib/maths/algebra/study/rationalStudy.ts +0 -287
  12. package/lib/maths/algebra/study.ts +0 -506
  13. package/lib/maths/coefficients/fraction.ts +0 -593
  14. package/lib/maths/coefficients/nthRoot.ts +0 -148
  15. package/lib/maths/geometry/circle.ts +0 -379
  16. package/lib/maths/geometry/line.ts +0 -604
  17. package/lib/maths/geometry/point.ts +0 -215
  18. package/lib/maths/geometry/triangle.ts +0 -368
  19. package/lib/maths/geometry/vector.ts +0 -243
  20. package/lib/maths/numeric.ts +0 -162
  21. package/lib/maths/numexp.ts +0 -198
  22. package/lib/maths/pimath.ts +0 -40
  23. package/lib/maths/randomization/random.ts +0 -80
  24. package/lib/maths/randomization/randomCore.ts +0 -19
  25. package/lib/maths/randomization/rndFraction.ts +0 -47
  26. package/lib/maths/randomization/rndGeometryCircle.ts +0 -50
  27. package/lib/maths/randomization/rndGeometryLine.ts +0 -53
  28. package/lib/maths/randomization/rndGeometryPoint.ts +0 -69
  29. package/lib/maths/randomization/rndHelpers.ts +0 -107
  30. package/lib/maths/randomization/rndMonom.ts +0 -57
  31. package/lib/maths/randomization/rndPolynom.ts +0 -90
  32. package/lib/maths/randomization/rndTypes.ts +0 -43
  33. package/lib/maths/shutingyard.ts +0 -496
@@ -1,80 +0,0 @@
1
- import {rndPolynom} from "./rndPolynom";
2
- import {rndMonom} from "./rndMonom";
3
- import {rndHelpers} from "./rndHelpers";
4
- import {
5
- randomCoefficientConfig,
6
- randomGeometryCircleConfig,
7
- randomGeometryLineConfig,
8
- randomGeometryPointConfig,
9
- randomMonomConfig,
10
- randomPolynomConfig
11
- } from "./rndTypes";
12
- import {rndFraction} from "./rndFraction";
13
- import {Polynom} from "../algebra/polynom";
14
- import {Monom} from "../algebra/monom";
15
- import {Fraction} from "../coefficients/fraction";
16
- import {Line} from "../geometry/line";
17
- import {rndGeometryLine} from "./rndGeometryLine";
18
- import {Point} from "../geometry/point";
19
- import {rndGeometryPoint} from "./rndGeometryPoint";
20
- import {Circle} from "../geometry/circle";
21
- import {rndGeometryCircle} from "./rndGeometryCircle";
22
-
23
- export * from "./rndTypes"
24
-
25
- export namespace Random {
26
- export function polynom(config?: randomPolynomConfig): Polynom {
27
- return (new rndPolynom(config)).generate()
28
- }
29
-
30
- export function monom(config?: randomMonomConfig): Monom {
31
- return (new rndMonom(config)).generate()
32
- }
33
-
34
- export function fraction(config?: randomCoefficientConfig): Fraction {
35
- return (new rndFraction(config)).generate()
36
- }
37
-
38
- export function number(from: number, to: number, exclude?: number[]): number {
39
- return rndHelpers.randomInt(from, to, exclude)
40
- }
41
-
42
- export function numberSym(max: number, allowZero?: boolean): number {
43
- return rndHelpers.randomIntSym(max, allowZero)
44
- }
45
-
46
- export function prime(max: number): number {
47
- return rndHelpers.randomPrime(max)
48
- }
49
-
50
- export function bool(percent?: number): boolean {
51
- return rndHelpers.randomBool(percent)
52
- }
53
-
54
- export function array(arr: any[], number?: number): any[] {
55
- return rndHelpers.randomArray(arr, number)
56
- }
57
-
58
- export function item(arr: any[]): any {
59
- return rndHelpers.randomItem(arr)
60
- }
61
-
62
- export function shuffle(arr: any[]): any[] {
63
- return rndHelpers.shuffleArray(arr)
64
- }
65
-
66
- export namespace Geometry {
67
- export function line(config?: randomGeometryLineConfig): Line {
68
- return (new rndGeometryLine(config).generate())
69
- }
70
-
71
- export function point(config?: randomGeometryPointConfig): Point {
72
- return (new rndGeometryPoint(config).generate())
73
- }
74
-
75
- export function circle(config?: randomGeometryCircleConfig): Circle {
76
- return (new rndGeometryCircle(config).generate())
77
- }
78
-
79
- }
80
- }
@@ -1,19 +0,0 @@
1
- export class randomCore {
2
- protected _config: Object
3
- protected _defaultConfig: Object
4
- mergeConfig = (config: Object, defaultConfig: Object): Object => {
5
- if (config !== undefined) {
6
- return {...defaultConfig, ...config}
7
- }
8
- return defaultConfig
9
- }
10
-
11
- generate = (): unknown => {
12
- return undefined
13
- }
14
-
15
- config = (config: Object): randomCore => {
16
- this._config = this.mergeConfig(config, this._defaultConfig)
17
- return this
18
- }
19
- }
@@ -1,47 +0,0 @@
1
- import {randomCore} from "./randomCore";
2
- import {randomCoefficientConfig, randomMonomConfig, randomPolynomConfig} from "./rndTypes";
3
- import {Random} from "./random";
4
- import {Fraction} from "../coefficients/fraction";
5
-
6
- /**
7
- * Create a random monom based on a based configuration
8
- */
9
- export class rndFraction extends randomCore {
10
- declare protected _config: randomCoefficientConfig
11
- declare protected _defaultConfig: randomCoefficientConfig
12
-
13
- constructor(userConfig?: randomCoefficientConfig) {
14
- super();
15
-
16
- this._defaultConfig = {
17
- negative: true,
18
- max: 10,
19
- reduced: true,
20
- zero: true,
21
- natural: false
22
- }
23
-
24
- this._config = this.mergeConfig(userConfig, this._defaultConfig)
25
- }
26
-
27
- generate = (): Fraction => {
28
- let Q = new Fraction()
29
-
30
- if(this._config.negative){
31
- Q.numerator = Random.numberSym(this._config.max, this._config.zero)
32
- }else {
33
- Q.numerator = Random.number(this._config.zero ? 0 : 1, this._config.max)
34
- }
35
- if(this._config.natural){
36
- Q.denominator = 1
37
- }else {
38
- let securityCount = 0
39
- while(Q.isRelative() && securityCount<10) {
40
- Q.denominator = Random.number(1, this._config.max)
41
- securityCount++
42
- }
43
- }
44
-
45
- return this._config.reduced?Q.reduce():Q
46
- }
47
- }
@@ -1,50 +0,0 @@
1
- import {randomCore} from "./randomCore";
2
- import {Random, randomGeometryCircleConfig} from "./random";
3
- import {Circle} from "../geometry/circle";
4
-
5
- /**
6
- * Create a random monom based on a based configuration
7
- */
8
- export class rndGeometryCircle extends randomCore {
9
- declare protected _config: randomGeometryCircleConfig
10
- declare protected _defaultConfig: randomGeometryCircleConfig
11
-
12
- generate = (): Circle => {
13
- const center = Random.Geometry.point(this._config.center)
14
-
15
- let rv, r
16
- if (this._config.pointsOnCircle === 8) {
17
- rv = Random.number(1, 3),
18
- r = rv ** 2 + (rv + 1) ** 2
19
- } else {
20
- r = Random.number(1, 20)
21
- }
22
-
23
- const c = new Circle(center, r, true)
24
-
25
-
26
- // let pts = c.getPointsOnCircle(true)
27
- //
28
- // pts = Random.shuffle(pts)
29
- // let ptt = pts.shift(),
30
- // pt1 = pts.shift(),
31
- // pt2
32
- //
33
- // for (let pt of pts) {
34
- // if (!pt1.x.isEqual(pt.x) && !pt1.y.isEqual(pt.y) && !A.isEqual(new Point().middleOf(pt1, pt))) {
35
- // pt2 = pt.clone()
36
- // break
37
- // }
38
- // }
39
-
40
- return c
41
-
42
- }
43
-
44
- constructor(userConfig?: randomGeometryCircleConfig) {
45
- super();
46
-
47
- this._defaultConfig = {}
48
- this._config = this.mergeConfig(userConfig, this._defaultConfig)
49
- }
50
- }
@@ -1,53 +0,0 @@
1
- import {randomCore} from "./randomCore";
2
- import {Random, randomGeometryLineConfig} from "./random";
3
- import {Line} from "../geometry/line";
4
- import {Vector} from "../geometry/vector";
5
- import {Point} from "../geometry/point";
6
-
7
- /**
8
- * Create a random monom based on a based configuration
9
- */
10
- export class rndGeometryLine extends randomCore {
11
- declare protected _config: randomGeometryLineConfig
12
- declare protected _defaultConfig: randomGeometryLineConfig
13
-
14
- constructor(userConfig?: randomGeometryLineConfig) {
15
- super();
16
-
17
- this._defaultConfig = {
18
- A: {
19
- x: Random.numberSym(10),
20
- y: Random.numberSym(10)
21
- },
22
- }
23
-
24
- // TODO: Strange that it raise an error
25
- // @ts-ignore
26
- this._config = this.mergeConfig(userConfig, this._defaultConfig)
27
- }
28
-
29
- generate = (): Line => {
30
- // The A point exists.
31
- const d = new Vector(
32
- Random.numberSym(10),
33
- Random.numberSym(10)
34
- )
35
-
36
- while (d.isNull) {
37
- d.x = Random.numberSym(10)
38
- d.y = Random.numberSym(10)
39
- }
40
-
41
- if (this._config.slope === 1) {
42
- if (d.x.sign() !== d.y.sign()) {
43
- d.y.opposed()
44
- }
45
- } else if (this._config.slope === -1) {
46
- if (d.x.sign() !== d.y.sign()) {
47
- d.y.opposed()
48
- }
49
- }
50
-
51
- return new Line(new Point(this._config.A.x, this._config.A.y), d)
52
- }
53
- }
@@ -1,69 +0,0 @@
1
- import {randomCore} from "./randomCore";
2
- import {Random, randomGeometryPointConfig} from "./random";
3
- import {Point} from "../geometry/point";
4
- import {Fraction} from "../coefficients/fraction";
5
-
6
- /**
7
- * Create a random monom based on a based configuration
8
- */
9
- export class rndGeometryPoint extends randomCore {
10
- declare protected _config: randomGeometryPointConfig
11
- declare protected _defaultConfig: randomGeometryPointConfig
12
-
13
- constructor(userConfig?: randomGeometryPointConfig) {
14
- super();
15
-
16
- this._defaultConfig = {
17
- axis: true,
18
- fraction: false,
19
- max: 10
20
- }
21
-
22
- this._config = this.mergeConfig(userConfig, this._defaultConfig)
23
- }
24
-
25
- generate = (): Point => {
26
- let x: Fraction, y: Fraction,
27
- zeroX = this._config.axis === true || this._config.axis === 'x',
28
- zeroY = this._config.axis === true || this._config.axis === 'y'
29
-
30
- x = this._config.fraction ?
31
- Random.fraction({max: this._config.max, zero: zeroX}) :
32
- new Fraction(Random.numberSym(this._config.max, zeroX))
33
-
34
- y = this._config.fraction ?
35
- Random.fraction({max: this._config.max, zero: zeroY}) :
36
- new Fraction(Random.numberSym(this._config.max, zeroY))
37
-
38
- if (+this._config.quadrant === 1) {
39
- x.abs()
40
- y.abs()
41
- }
42
- if (+this._config.quadrant === 2) {
43
- if (x.isPositive()) {
44
- x.opposed()
45
- }
46
- if (y.isNegative()) {
47
- y.opposed()
48
- }
49
- }
50
- if (+this._config.quadrant === 3) {
51
- if (x.isPositive()) {
52
- x.opposed()
53
- }
54
- if (y.isPositive()) {
55
- y.opposed()
56
- }
57
- }
58
- if (+this._config.quadrant === 4) {
59
- if (x.isNegative()) {
60
- x.opposed()
61
- }
62
- if (y.isPositive()) {
63
- y.opposed()
64
- }
65
- }
66
-
67
- return new Point(x, y)
68
- }
69
- }
@@ -1,107 +0,0 @@
1
- /**
2
- * Random helpers
3
- */
4
- import {Numeric} from "../numeric.ts";
5
-
6
- export class rndHelpers {
7
-
8
- /**
9
- * Random boolean with a percent ratio
10
- * @param percent
11
- */
12
- static randomBool(percent: number = 0.5): boolean {
13
- return Math.random() < percent;
14
- }
15
-
16
- /**
17
- * Random integer between two values.
18
- * @param a (number) : From this value to the second value. If the second is ommited, this value is the max value.
19
- * @param b (number) : To this value. If this is ommited.
20
- */
21
- static randomInt(a: number, b?: number, exclude?: number[]): number {
22
- if (b === undefined) {
23
- if (a >= 0) {
24
- return this.randomInt(0, a);
25
- } else {
26
- return this.randomInt(a, 0);
27
- }
28
- }
29
-
30
- // Same start and end values
31
- if (a === b) {
32
- return a
33
- }
34
-
35
- // No exclusion
36
- if (exclude === undefined) {
37
- return Math.floor(Math.random() * (b - a + 1) + a);
38
- }
39
-
40
- // With exclusion
41
- if (Math.abs(b - a) <= exclude.length) {
42
- throw new Error('The number of excluded values is too high.')
43
- }
44
-
45
- let r = this.randomInt(a, b)
46
- while (exclude.includes(r)) {
47
- r = this.randomInt(a, b)
48
- }
49
- return r
50
- }
51
-
52
- /**
53
- * Random integer between -max and max value.
54
- * @param max (number) : determine the limits.
55
- * @param zero (bool) : determine if zero is allowed or not.
56
- */
57
- static randomIntSym(max: number, zero?: boolean): number {
58
- if (zero === false) {
59
- return this.randomBool() ? this.randomInt(1, max) : -this.randomInt(1, max);
60
- } else {
61
- return this.randomInt(-max, max);
62
- }
63
- }
64
-
65
- static randomPrime(max: number): number {
66
- let primes = Numeric.primes()
67
- if (max !== undefined) {
68
- primes = primes.filter(x => x < max)
69
- }
70
- return this.randomItem(primes)
71
- }
72
-
73
- static randomArray(arr: any[], number?: number): any[] {
74
- if (number === undefined) {
75
- number = 1
76
- }
77
-
78
- // Return a clone array
79
- if (arr.length <= 0) {
80
- return Object.values(arr)
81
- }
82
-
83
- // Randomize the array and return the n first elements.
84
- return rndHelpers.shuffleArray(arr).slice(0, number);
85
- }
86
-
87
- static randomItem(arr: any[]): any {
88
- if (arr.length === 0) {
89
- return ''
90
- }
91
- return arr[this.randomInt(0, arr.length - 1)]
92
- }
93
-
94
- static shuffleArray(arr: any[]): any[] {
95
- // The Fisher-Yates algorithm
96
- let shuffleArray = Object.values(arr)
97
- for (let i = shuffleArray.length - 1; i > 0; i--) {
98
- const j = Math.floor(Math.random() * (i + 1));
99
- const temp = shuffleArray[i];
100
- shuffleArray[i] = shuffleArray[j];
101
- shuffleArray[j] = temp;
102
- }
103
-
104
- return shuffleArray;
105
- }
106
-
107
- }
@@ -1,57 +0,0 @@
1
- import {randomCore} from "./randomCore";
2
- import {randomMonomConfig} from "./rndTypes";
3
- import {Random} from "./random";
4
- import {Monom} from "../algebra/monom";
5
-
6
- /**
7
- * Create a random monom based on a based configuration
8
- */
9
- export class rndMonom extends randomCore {
10
- declare protected _config: randomMonomConfig
11
- declare protected _defaultConfig: randomMonomConfig
12
-
13
- generate = (): Monom => {
14
- // Create a monom instance
15
- let M = new Monom()
16
-
17
- // Generate the coefficient
18
- if (typeof this._config.fraction === "boolean") {
19
- M.coefficient = Random.fraction({
20
- zero: this._config.zero,
21
- reduced: true,
22
- natural: !this._config.fraction
23
- })
24
- } else {
25
- M.coefficient = Random.fraction(this._config.fraction)
26
- }
27
-
28
- // Calculate the degree of the monom
29
- if (this._config.letters.length > 1) {
30
- // Initialise each items...
31
- for (let L of this._config.letters.split('')) {
32
- M.setLetter(L, 0);
33
- }
34
- for (let i = 0; i < this._config.degree; i++) {
35
- const L = Random.item(this._config.letters.split(""))
36
- M.setLetter(L, M.degree(L).clone().add(1))
37
- }
38
- } else {
39
- M.setLetter(this._config.letters, this._config.degree)
40
- }
41
-
42
- return M
43
- }
44
-
45
- constructor(userConfig?: randomMonomConfig) {
46
- super();
47
-
48
- this._defaultConfig = {
49
- letters: 'x',
50
- degree: 2,
51
- fraction: true,
52
- zero: false
53
- }
54
-
55
- this._config = this.mergeConfig(userConfig, this._defaultConfig)
56
- }
57
- }
@@ -1,90 +0,0 @@
1
- import {randomCore} from "./randomCore";
2
- import {randomPolynomConfig} from "./rndTypes";
3
- import {rndMonom} from "./rndMonom";
4
- import {Random} from "./random";
5
- import {Polynom} from "../algebra/polynom";
6
- import {Monom} from "../algebra/monom";
7
-
8
- /**
9
- * Random polynoms
10
- */
11
- export class rndPolynom extends randomCore {
12
- declare protected _config: randomPolynomConfig
13
- declare protected _defaultConfig: randomPolynomConfig
14
-
15
- generate = (): Polynom => {
16
- if (this._config.factorable && this._config.degree > 1) {
17
- return this.factorable()
18
- }
19
-
20
- // Create the polynom
21
- let P = new Polynom().empty(),
22
- M: Monom
23
-
24
- for (let i = this._config.degree; i >= 0; i--) {
25
- // Create monom of corresponding degree.
26
- M = new rndMonom({
27
- letters: this._config.letters,
28
- degree: i,
29
- fraction: this._config.fraction,
30
- zero: (i === this._config.degree) ? false : this._config.allowNullMonom
31
- }).generate()
32
-
33
- // If degree is the greatest and unit is true, set the monom value to one.
34
- if (this._config.unit && this._config.degree === i) {
35
- M.coefficient.one()
36
- }
37
-
38
- // Add to the polynom
39
- P.add(M)
40
- }
41
-
42
- // Make sure the first monom is positive.
43
- if (this._config.positive && P.monomByDegree().coefficient.isNegative()) {
44
- P.monomByDegree().coefficient.opposed()
45
- }
46
-
47
- // If the number of monoms is greater than the allowed value, remove some of them... except the first one !
48
- if (this._config.numberOfMonoms > 0 && this._config.numberOfMonoms < P.length) {
49
- // Get the greatest degree monom
50
- let M = P.monomByDegree().clone()
51
- P.monoms = Random.array(P.monoms.slice(1), this._config.numberOfMonoms - 1)
52
- P.add(M).reorder().reduce()
53
- }
54
- return P
55
- }
56
-
57
- constructor(userConfig?: randomPolynomConfig) {
58
- super();
59
-
60
- // Default config for a random polynom
61
- this._defaultConfig = {
62
- letters: 'x',
63
- degree: 2,
64
- fraction: false,
65
- zero: false,
66
- unit: false,
67
- factorable: false,
68
- allowNullMonom: true,
69
- numberOfMonoms: 0,
70
- positive: true
71
- }
72
-
73
- // Merge config with initialiser
74
- this._config = this.mergeConfig(userConfig, this._defaultConfig)
75
- }
76
-
77
- factorable = (): Polynom => {
78
- let P = new Polynom().one()
79
-
80
- let _factorableConfig = {...this._config}
81
- _factorableConfig.degree = 1
82
- _factorableConfig.factorable = false
83
-
84
- for (let i = 0; i < this._config.degree; i++) {
85
- P.multiply(Random.polynom(_factorableConfig))
86
- }
87
-
88
- return P
89
- }
90
- }
@@ -1,43 +0,0 @@
1
- import {Fraction} from "../coefficients/fraction";
2
-
3
- export type randomCoefficientConfig = {
4
- negative?: boolean,
5
- max?: number,
6
- reduced?: boolean,
7
- zero?: boolean,
8
- natural?: boolean
9
- }
10
-
11
- export type randomMonomConfig = {
12
- letters?: string,
13
- degree?: number,
14
- fraction?: boolean | randomCoefficientConfig,
15
- zero?: boolean
16
- }
17
-
18
- export type randomPolynomConfig = randomMonomConfig & {
19
- unit?: boolean,
20
- factorable?: boolean,
21
- allowNullMonom?: boolean,
22
- numberOfMonoms?: number,
23
- positive?: boolean
24
- }
25
-
26
- export type randomGeometryLineConfig = {
27
- A: { x: number | Fraction, y: number | Fraction },
28
- slope?: Fraction | string | number,
29
- }
30
-
31
-
32
- export type randomGeometryPointConfig = {
33
- quadrant?: number,
34
- axis?: string | boolean,
35
- fraction?: boolean,
36
- max?: number
37
- }
38
-
39
- export type randomGeometryCircleConfig = {
40
- center?: randomGeometryPointConfig,
41
- radius?: number,
42
- pointsOnCircle?: number
43
- }