pimath 0.0.121 → 0.0.123

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 (73) hide show
  1. package/.eslintrc.js +23 -23
  2. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +90 -0
  3. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +4 -0
  4. package/LICENSE.md +1 -1
  5. package/dev/pimath.js +27 -21
  6. package/dev/pimath.js.map +1 -1
  7. package/dist/pimath.js +27 -21
  8. package/dist/pimath.js.map +1 -1
  9. package/dist/pimath.min.js +1 -1
  10. package/dist/pimath.min.js.map +1 -1
  11. package/docs/assets/main.js +58 -58
  12. package/docs/assets/style.css +1367 -1367
  13. package/docs/classes/Logicalset.Logicalset.html +220 -220
  14. package/docs/classes/Polynom.Rational.html +390 -390
  15. package/docs/classes/Vector-1.Vector.html +493 -493
  16. package/docs/classes/Vector.Point.html +340 -340
  17. package/docs/classes/algebra_equation.Equation.html +795 -795
  18. package/docs/classes/algebra_linearSystem.LinearSystem.html +407 -407
  19. package/docs/classes/algebra_monom.Monom.html +966 -966
  20. package/docs/classes/algebra_polynom.Polynom.html +1280 -1280
  21. package/docs/classes/coefficients_fraction.Fraction.html +938 -938
  22. package/docs/classes/geometry_circle.Circle.html +475 -475
  23. package/docs/classes/geometry_line.Line.html +778 -778
  24. package/docs/classes/geometry_triangle.Triangle.html +428 -428
  25. package/docs/classes/numeric.Numeric.html +268 -268
  26. package/docs/classes/shutingyard.Shutingyard.html +258 -258
  27. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +88 -88
  28. package/docs/enums/geometry_line.LinePropriety.html +101 -101
  29. package/docs/enums/shutingyard.ShutingyardMode.html +105 -105
  30. package/docs/enums/shutingyard.ShutingyardType.html +119 -119
  31. package/docs/index.html +62 -62
  32. package/docs/interfaces/algebra_equation.ISolution.html +110 -110
  33. package/docs/interfaces/algebra_polynom.IEuclidian.html +92 -92
  34. package/docs/interfaces/geometry_triangle.remarquableLines.html +149 -149
  35. package/docs/modules/Logicalset.html +68 -68
  36. package/docs/modules/Polynom.html +68 -68
  37. package/docs/modules/Vector-1.html +68 -68
  38. package/docs/modules/Vector.html +68 -68
  39. package/docs/modules/algebra_equation.html +74 -74
  40. package/docs/modules/algebra_linearSystem.html +64 -64
  41. package/docs/modules/algebra_monom.html +69 -69
  42. package/docs/modules/algebra_polynom.html +74 -74
  43. package/docs/modules/coefficients_fraction.html +69 -69
  44. package/docs/modules/geometry_circle.html +64 -64
  45. package/docs/modules/geometry_line.html +69 -69
  46. package/docs/modules/geometry_triangle.html +69 -69
  47. package/docs/modules/numeric.html +64 -64
  48. package/docs/modules/shutingyard.html +83 -83
  49. package/docs/types/algebra_monom.literalType.html +65 -65
  50. package/docs/types/algebra_polynom.PolynomParsingType.html +61 -61
  51. package/docs/types/coefficients_fraction.FractionParsingType.html +60 -60
  52. package/docs/types/shutingyard.Token.html +71 -71
  53. package/docs/types/shutingyard.tokenType.html +76 -76
  54. package/docs/variables/shutingyard.tokenConstant.html +69 -69
  55. package/esm/index.js +1 -1
  56. package/esm/index.js.map +1 -1
  57. package/esm/maths/algebra/polynom.js +13 -8
  58. package/esm/maths/algebra/polynom.js.map +1 -1
  59. package/esm/maths/algebra/study.d.ts +1 -0
  60. package/esm/maths/algebra/study.js +9 -8
  61. package/esm/maths/algebra/study.js.map +1 -1
  62. package/esm/maths/numexp.d.ts +1 -1
  63. package/esm/maths/numexp.js.map +1 -1
  64. package/esm/maths/shutingyard.js +4 -4
  65. package/esm/maths/shutingyard.js.map +1 -1
  66. package/package.json +5 -5
  67. package/src/index.ts +1 -1
  68. package/src/maths/algebra/polynom.ts +16 -11
  69. package/src/maths/algebra/study.ts +11 -9
  70. package/src/maths/numexp.ts +1 -1
  71. package/src/maths/shutingyard.ts +6 -4
  72. package/tests/algebra/polynom.test.ts +8 -0
  73. package/tests/numexp.test.ts +12 -0
package/.eslintrc.js CHANGED
@@ -1,24 +1,24 @@
1
- module.exports = {
2
- "env": {
3
- "browser": true,
4
- "es6": true
5
- },
6
- "extends": [
7
- "eslint:recommended",
8
- "plugin:@typescript-eslint/eslint-recommended"
9
- ],
10
- "globals": {
11
- "Atomics": "readonly",
12
- "SharedArrayBuffer": "readonly"
13
- },
14
- "parser": "@typescript-eslint/parser",
15
- "parserOptions": {
16
- "ecmaVersion": 2018,
17
- "sourceType": "module"
18
- },
19
- "plugins": [
20
- "@typescript-eslint"
21
- ],
22
- "rules": {
23
- }
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true
5
+ },
6
+ "extends": [
7
+ "eslint:recommended",
8
+ "plugin:@typescript-eslint/eslint-recommended"
9
+ ],
10
+ "globals": {
11
+ "Atomics": "readonly",
12
+ "SharedArrayBuffer": "readonly"
13
+ },
14
+ "parser": "@typescript-eslint/parser",
15
+ "parserOptions": {
16
+ "ecmaVersion": 2018,
17
+ "sourceType": "module"
18
+ },
19
+ "plugins": [
20
+ "@typescript-eslint"
21
+ ],
22
+ "rules": {
23
+ }
24
24
  };
@@ -0,0 +1,90 @@
1
+ Index: src/maths/expressions/numexp.ts
2
+ IDEA additional info:
3
+ Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
4
+ <+>import {Shutingyard, ShutingyardMode, ShutingyardType, tokenConstant} from \"../shutingyard\";\r\nimport {Fraction} from \"../coefficients/fraction\";\r\n\r\nexport class NumExp {\r\n private _rpn: { token: string, tokenType: string }[]\r\n private _expression: string\r\n private _isValid: boolean\r\n\r\n constructor(value: string, uniformize?:boolean) {\r\n this._expression = value\r\n try {\r\n this._rpn = new Shutingyard(ShutingyardMode.NUMERIC).parse(value, uniformize || uniformize===undefined).rpn\r\n }catch(e){\r\n this._rpn = null\r\n this._isValid = false\r\n }\r\n }\r\n\r\n get rpn(): { token: string; tokenType: string }[] {\r\n return this._rpn;\r\n }\r\n\r\n get isValid(): boolean {\r\n if(this._isValid===undefined){\r\n try {\r\n const v = this.evaluate({x: 0})\r\n }catch{\r\n this._isValid = false\r\n }\r\n }\r\n return this._isValid\r\n }\r\n\r\n set isValid(value: boolean){\r\n this._isValid = value\r\n }\r\n\r\n get expression(): string {\r\n return this._expression;\r\n }\r\n\r\n private _extractDecimalPart(value: number): string {\r\n let decimal = value.toString()\r\n\r\n if (!decimal.includes('.')) {\r\n return ''\r\n }\r\n\r\n decimal = decimal.split('.')[1]\r\n\r\n return decimal.substring(0, decimal.length - 2)\r\n }\r\n\r\n private _numberCorrection(value: number): number {\r\n // Must modify the number if it's like:\r\n // a: 3.0000000000000003\r\n // b: 3.9999999999999994\r\n // remove the last character\r\n // check if around n last characters are either 0 or 9\r\n // if it is, 'round' the number.\r\n\r\n const epsilon = 0.00000000000001,\r\n number_of_digits = 6\r\n\r\n const decimal = this._extractDecimalPart(value)\r\n if(decimal===''){return value}\r\n\r\n const n9 = decimal.match(/9+$/g)\r\n const n0 = decimal.match(/0+$/g)\r\n\r\n if (n9 && n9[0].length >= number_of_digits) {\r\n // New tested values.\r\n const mod = this._extractDecimalPart(value + epsilon),\r\n mod0 = mod.match(/0+$/g)\r\n\r\n if(mod0 && mod0[0].length>= number_of_digits){\r\n // The value can be changed. Remove all zeros!\r\n return +((value+epsilon).toString().split(mod0[0])[0])\r\n }\r\n }\r\n\r\n if (n0 && n0[0].length >= number_of_digits) {\r\n // New tested values.\r\n const mod = this._extractDecimalPart(value - epsilon),\r\n mod9 = mod.match(/9+$/g)\r\n\r\n if(mod9 && mod9[0].length>= number_of_digits){\r\n // The value can be changed. Remove all nines!\r\n return +(value.toString().split(n0[0])[0])\r\n }\r\n }\r\n\r\n return value\r\n }\r\n\r\n private _addToStack(stack:number[], value: number): void {\r\n stack.push(this._numberCorrection(value))\r\n }\r\n\r\n evaluate(values: { [Key: string]: number }): number {\r\n const stack: number[] = []\r\n\r\n if(this._rpn===null){\r\n this._isValid = false\r\n return 0\r\n }\r\n\r\n this.isValid = true\r\n\r\n for (const element of this._rpn) {\r\n if (element.tokenType === ShutingyardType.COEFFICIENT) {\r\n // May be a numeric value or a Fraction.\r\n if (!isNaN(+element.token)) {\r\n this._addToStack(stack, +element.token)\r\n } else {\r\n this._addToStack(stack, new Fraction(element.token).value)\r\n }\r\n } else if (element.tokenType === ShutingyardType.VARIABLE) {\r\n if (values[element.token] !== undefined) {\r\n this._addToStack(stack, +values[element.token])\r\n }\r\n } else if (element.tokenType === ShutingyardType.CONSTANT) {\r\n this._addToStack(stack, tokenConstant[element.token])\r\n } else if (element.tokenType === ShutingyardType.OPERATION) {\r\n if (element.token === '*') {\r\n const b = stack.pop(),\r\n a = stack.pop()\r\n if(a === undefined || b === undefined){this.isValid = false}\r\n this._addToStack(stack, a * b)\r\n } else if (element.token === '/') {\r\n const b = stack.pop(),\r\n a = stack.pop()\r\n if(a === undefined || b === undefined){this.isValid = false}\r\n this._addToStack(stack, a / b)\r\n } else if (element.token === '+') {\r\n const b = stack.pop(),\r\n a = stack.pop()\r\n if(a === undefined || b === undefined){this.isValid = false}\r\n this._addToStack(stack, (+a) + (+b))\r\n } else if (element.token === '-') {\r\n const b = stack.pop(),\r\n a = stack.pop() || 0\r\n if(b === undefined){this.isValid = false}\r\n this._addToStack(stack, a - b)\r\n } else if (element.token === '^') {\r\n const b = stack.pop(),\r\n a = stack.pop()\r\n if(a === undefined || b === undefined){this.isValid = false}\r\n this._addToStack(stack, Math.pow(a, b))\r\n }\r\n } else if (element.tokenType === ShutingyardType.FUNCTION) {\r\n const a = stack.pop()\r\n if(a === undefined){this.isValid = false}\r\n if (element.token === 'sin') {\r\n this._addToStack(stack, Math.sin(a))\r\n } else if (element.token === 'cos') {\r\n this._addToStack(stack, Math.cos(a))\r\n } else if (element.token === 'tan') {\r\n this._addToStack(stack, Math.tan(a))\r\n } else if(element.token === 'sqrt') {\r\n this._addToStack(stack, Math.sqrt(a))\r\n }else if(element.token ==='nthrt') {\r\n // TODO: support nthrt in num. exp.\r\n let b = stack.pop()\r\n if(a%2===0 && b<0){\r\n this._addToStack(stack, NaN)\r\n }else {\r\n this._addToStack(stack, (b < 0 ? -1 : 1) * Math.pow(Math.abs(b), 1 / a))\r\n }\r\n } else if(element.token === 'ln'){\r\n this._addToStack(stack, Math.log(a))\r\n } else if(element.token === 'log') {\r\n this._addToStack(stack, Math.log10(a))\r\n }\r\n }\r\n }\r\n\r\n if (stack.length === 1) {\r\n return stack[0]\r\n } else {\r\n throw `There was a problem parsing: ${this._expression}`\r\n }\r\n }\r\n}\r\n
5
+ ===================================================================
6
+ diff --git a/src/maths/expressions/numexp.ts b/src/maths/expressions/numexp.ts
7
+ --- a/src/maths/expressions/numexp.ts
8
+ +++ b/src/maths/expressions/numexp.ts
9
+ @@ -51,46 +51,47 @@
10
+ return decimal.substring(0, decimal.length - 2)
11
+ }
12
+
13
+ - private _numberCorrection(value: number): number {
14
+ + private _numberCorrection(value: number, number_of_digits=6): number {
15
+ + return +value.toFixed(number_of_digits);
16
+ // Must modify the number if it's like:
17
+ // a: 3.0000000000000003
18
+ // b: 3.9999999999999994
19
+ // remove the last character
20
+ // check if around n last characters are either 0 or 9
21
+ // if it is, 'round' the number.
22
+ -
23
+ - const epsilon = 0.00000000000001,
24
+ - number_of_digits = 6
25
+ -
26
+ - const decimal = this._extractDecimalPart(value)
27
+ - if(decimal===''){return value}
28
+ -
29
+ - const n9 = decimal.match(/9+$/g)
30
+ - const n0 = decimal.match(/0+$/g)
31
+ -
32
+ - if (n9 && n9[0].length >= number_of_digits) {
33
+ - // New tested values.
34
+ - const mod = this._extractDecimalPart(value + epsilon),
35
+ - mod0 = mod.match(/0+$/g)
36
+ -
37
+ - if(mod0 && mod0[0].length>= number_of_digits){
38
+ - // The value can be changed. Remove all zeros!
39
+ - return +((value+epsilon).toString().split(mod0[0])[0])
40
+ - }
41
+ - }
42
+ -
43
+ - if (n0 && n0[0].length >= number_of_digits) {
44
+ - // New tested values.
45
+ - const mod = this._extractDecimalPart(value - epsilon),
46
+ - mod9 = mod.match(/9+$/g)
47
+ -
48
+ - if(mod9 && mod9[0].length>= number_of_digits){
49
+ - // The value can be changed. Remove all nines!
50
+ - return +(value.toString().split(n0[0])[0])
51
+ - }
52
+ - }
53
+ -
54
+ - return value
55
+ + //
56
+ + // const epsilon = 0.00000000000001,
57
+ + // number_of_digits = 6
58
+ + //
59
+ + // const decimal = this._extractDecimalPart(value)
60
+ + // if(decimal===''){return value}
61
+ + //
62
+ + // const n9 = decimal.match(/9+$/g)
63
+ + // const n0 = decimal.match(/0+$/g)
64
+ + //
65
+ + // if (n9 && n9[0].length >= number_of_digits) {
66
+ + // // New tested values.
67
+ + // const mod = this._extractDecimalPart(value + epsilon),
68
+ + // mod0 = mod.match(/0+$/g)
69
+ + //
70
+ + // if(mod0 && mod0[0].length>= number_of_digits){
71
+ + // // The value can be changed. Remove all zeros!
72
+ + // return +((value+epsilon).toString().split(mod0[0])[0])
73
+ + // }
74
+ + // }
75
+ + //
76
+ + // if (n0 && n0[0].length >= number_of_digits) {
77
+ + // // New tested values.
78
+ + // const mod = this._extractDecimalPart(value - epsilon),
79
+ + // mod9 = mod.match(/9+$/g)
80
+ + //
81
+ + // if(mod9 && mod9[0].length>= number_of_digits){
82
+ + // // The value can be changed. Remove all nines!
83
+ + // return +(value.toString().split(n0[0])[0])
84
+ + // }
85
+ + // }
86
+ + //
87
+ + // return value
88
+ }
89
+
90
+ private _addToStack(stack:number[], value: number): void {
@@ -0,0 +1,4 @@
1
+ <changelist name="Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]" date="1690205520775" recycled="false" toDelete="true">
2
+ <option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch" />
3
+ <option name="DESCRIPTION" value="Uncommitted changes before Update at 24.07.2023 15:31 [Default Changelist]" />
4
+ </changelist>
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Basil Gass
3
+ Copyright (c) 2023 Basil Gass
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dev/pimath.js CHANGED
@@ -50,7 +50,7 @@ exports.PiMath = {
50
50
  Circle: circle_1.Circle
51
51
  }
52
52
  };
53
- window.PiMath = exports.PiMath;
53
+ window.Pi = exports.PiMath;
54
54
 
55
55
 
56
56
  /***/ }),
@@ -2719,8 +2719,10 @@ class Polynom {
2719
2719
  };
2720
2720
  this.isDeveloped = (polynomString) => {
2721
2721
  let P;
2722
+ // Start by removing the parenthis after a "power"
2723
+ let pString = polynomString.replaceAll(/\^\(([-0-9/]+)\)/g, '$1');
2722
2724
  // There is at least one parenthese - it is not developed.
2723
- if (polynomString.split('(').length + polynomString.split(')').length > 0) {
2725
+ if (pString.includes('(') || pString.includes(')')) {
2724
2726
  return false;
2725
2727
  }
2726
2728
  // Try to build the polynom
@@ -2736,13 +2738,16 @@ class Polynom {
2736
2738
  return false;
2737
2739
  }
2738
2740
  // Check that everything is completely developed. Actually, there are no parentheses... so it is fully developed
2739
- // maybe it wasn't reduced and not ordered...
2740
- // compare polynom string.
2741
- // normalize the string
2742
- let polynomStringNormalized = polynomString.replaceAll('[*\s]', '');
2743
- // Determine if it's the exact same string.
2744
- // TODO: Maybe it's enough to just make this test !
2745
- return polynomStringNormalized === P.reduce().reorder().display;
2741
+ return true;
2742
+ // // maybe it wasn't reduced and not ordered...
2743
+ // // compare polynom string.
2744
+ //
2745
+ // // normalize the string
2746
+ // let polynomStringNormalized = polynomString.replaceAll('[*\s]', '')
2747
+ //
2748
+ // // Determine if it's the exact same string.
2749
+ // // TODO: Maybe it's enough to just make this test !a
2750
+ // return polynomStringNormalized === P.reduce().reorder().display
2746
2751
  };
2747
2752
  // -------------------------------------
2748
2753
  this.reduce = () => {
@@ -3960,13 +3965,13 @@ class Study {
3960
3965
  return code;
3961
3966
  };
3962
3967
  this._makeTexFromTableOfSigns = (tos) => {
3963
- let factors = tos.factors.map(x => `\\(${x.tex}\\)/1`), factorsFx = `\\(${this._name}(x)\\)/1.2`, zeroes = tos.zeroes;
3968
+ let factors = tos.factors.map(x => `\\(${x.tex}\\)/1`), factorsFx = `\\(${this._config.name}(${this._config.variable})\\)/1.2`, zeroes = tos.zeroes;
3964
3969
  // Add the last lines "label"
3965
3970
  if (tos.type === TABLE_OF_SIGNS.GROWS) {
3966
- factorsFx = `\\(${this._name}'(x)\\)/1.2,\\(f(x)\\)/2`;
3971
+ factorsFx = `\\(${this._config.name}'(${this._config.variable})\\)/1.2,\\(f(x${this._config.variable})\\)/2`;
3967
3972
  }
3968
3973
  else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
3969
- factorsFx = `\\(${this._name}''(x)\\)/1.2,\\(f(x)\\)/2`;
3974
+ factorsFx = `\\(${this._config.name}''(${this._config.variable})\\)/1.2,\\(f(${this._config.variable})\\)/2`;
3970
3975
  }
3971
3976
  // Create the tikzPicture header
3972
3977
  let tex = `\\begin{tikzpicture}
@@ -3991,6 +3996,7 @@ class Study {
3991
3996
  this.fx = fx;
3992
3997
  this._config = {
3993
3998
  name: 'f',
3999
+ variable: 'x',
3994
4000
  domain: true,
3995
4001
  asymptotes: true,
3996
4002
  signs: true,
@@ -4001,9 +4007,10 @@ class Study {
4001
4007
  if (typeof config === 'string') {
4002
4008
  const d = config.split(',');
4003
4009
  this._config = {};
4004
- let n = d.filter(x => x.includes('(x)'));
4010
+ let n = d.filter(x => x.includes('(') && x.includes(')'));
4005
4011
  if (n.length === 1) {
4006
- this._config.name = n[0].split('(x)')[0];
4012
+ this._config.name = n[0].split('(')[0];
4013
+ this._config.variable = n[0].split('(')[1].split(')')[0];
4007
4014
  }
4008
4015
  this._config.domain = d.includes('d');
4009
4016
  this._config.asymptotes = d.includes('a');
@@ -4015,15 +4022,14 @@ class Study {
4015
4022
  this._config = config;
4016
4023
  }
4017
4024
  }
4018
- this._name = this._config?.name ?? 'f';
4019
4025
  this.makeStudy();
4020
4026
  return this;
4021
4027
  }
4022
4028
  get name() {
4023
- return this._name;
4029
+ return this._config.name;
4024
4030
  }
4025
4031
  set name(value) {
4026
- this._name = value;
4032
+ this._config.name = value;
4027
4033
  }
4028
4034
  get config() {
4029
4035
  return this._config;
@@ -7677,21 +7683,21 @@ class Shutingyard {
7677
7683
  if (crtToken.match(/[a-zA-Z]/g)) {
7678
7684
  // Current element is a letter.
7679
7685
  // if the next element is a letter, a number or an opening parentheses, add the multiplication sign.
7680
- if (nextToken.match(/[a-zA-Z\d(]/)) {
7686
+ if (nextToken?.match(/[a-zA-Z\d(]/)) {
7681
7687
  normalizedExpr += '*';
7682
7688
  }
7683
7689
  }
7684
7690
  else if (crtToken.match(/\d/)) {
7685
7691
  // Current element is a number.
7686
7692
  // if the next element is a letter or a parentheses, add the multiplication sign.
7687
- if (nextToken.match(/[a-zA-Z(]/)) {
7693
+ if (nextToken?.match(/[a-zA-Z(]/)) {
7688
7694
  normalizedExpr += '*';
7689
7695
  }
7690
7696
  }
7691
7697
  else if (crtToken === ')') {
7692
7698
  // Current element is a closing parentheses.
7693
7699
  // if the next element is a letter, a number or an opening parentheses, add the multiplication sign
7694
- if (nextToken.match(/[a-zA-Z\d(]/)) {
7700
+ if (nextToken?.match(/[a-zA-Z\d(]/)) {
7695
7701
  normalizedExpr += '*';
7696
7702
  }
7697
7703
  }
@@ -7699,7 +7705,7 @@ class Shutingyard {
7699
7705
  i++;
7700
7706
  }
7701
7707
  // add the last token
7702
- return normalizedExpr + nextToken;
7708
+ return normalizedExpr + (nextToken === undefined ? '' : nextToken);
7703
7709
  }
7704
7710
  // /**
7705
7711
  // * Sanitize an expression by adding missing common operation (multiplication between parentheseses)