pimath 0.0.96 → 0.0.98
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/.eslintrc.js +23 -23
- package/dist/pi.js +77 -42
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/docs/assets/main.js +52 -52
- package/docs/classes/Logicalset.Logicalset-1.html +4 -4
- package/docs/classes/Polynom.Rational.html +3 -3
- package/docs/classes/algebra_equation.Equation.html +25 -25
- package/docs/classes/algebra_monom.Monom.html +113 -113
- package/docs/classes/algebra_polynom.Polynom.html +29 -29
- package/docs/classes/coefficients_fraction.Fraction.html +18 -18
- package/docs/classes/coefficients_nthroot.NthRoot.html +2 -2
- package/docs/classes/geometry_circle.Circle.html +2 -2
- package/docs/classes/geometry_line.Line.html +2 -2
- package/docs/classes/geometry_triangle.Triangle.html +16 -16
- package/docs/classes/numeric.Numeric.html +13 -13
- package/docs/classes/shutingyard.Shutingyard.html +17 -17
- package/docs/index.html +10 -10
- package/docs/interfaces/algebra_equation.ISolution.html +2 -2
- package/esm/maths/algebra/equation.d.ts +3 -5
- package/esm/maths/algebra/equation.js +67 -69
- package/esm/maths/algebra/monom.d.ts +2 -5
- package/esm/maths/algebra/polynom.d.ts +4 -7
- package/esm/maths/algebra/rational.d.ts +6 -7
- package/esm/maths/algebra/rational.js +2 -2
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/algebra/study/rationalStudy.d.ts +3 -11
- package/esm/maths/algebra/study/rationalStudy.js +33 -35
- package/esm/maths/algebra/study/rationalStudy.js.map +1 -1
- package/esm/maths/algebra/study.d.ts +21 -14
- package/esm/maths/algebra/study.js +74 -39
- package/esm/maths/algebra/study.js.map +1 -1
- package/esm/maths/coefficients/nthRoot.js +16 -8
- package/package.json +7 -7
- package/src/maths/algebra/rational.ts +3 -2
- package/src/maths/algebra/study/rationalStudy.ts +3 -3
- package/src/maths/algebra/study.ts +93 -51
|
@@ -87,17 +87,21 @@ class NthRoot {
|
|
|
87
87
|
let C;
|
|
88
88
|
if (this._coefficient === 1) {
|
|
89
89
|
C = '';
|
|
90
|
-
}
|
|
90
|
+
}
|
|
91
|
+
else if (this._coefficient === -1) {
|
|
91
92
|
C = '-';
|
|
92
|
-
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
93
95
|
C = this._coefficient.toString();
|
|
94
96
|
}
|
|
95
97
|
if (this._radical === 1) {
|
|
96
98
|
return `${this._coefficient}`;
|
|
97
|
-
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
98
101
|
if (this._nth === 2) {
|
|
99
102
|
return `${C}\\sqrt{${this._radical}}`;
|
|
100
|
-
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
101
105
|
return `${C}\\sqrt[${this._nth}]{${this._radical}}`;
|
|
102
106
|
}
|
|
103
107
|
}
|
|
@@ -106,17 +110,21 @@ class NthRoot {
|
|
|
106
110
|
let C;
|
|
107
111
|
if (this._coefficient === 1) {
|
|
108
112
|
C = '';
|
|
109
|
-
}
|
|
113
|
+
}
|
|
114
|
+
else if (this._coefficient === -1) {
|
|
110
115
|
C = '-';
|
|
111
|
-
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
112
118
|
C = this._coefficient.toString();
|
|
113
119
|
}
|
|
114
120
|
if (this._radical === 1) {
|
|
115
121
|
return `${this._coefficient}`;
|
|
116
|
-
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
117
124
|
if (this._nth === 2) {
|
|
118
125
|
return `${C}sqrt{${this._radical}}`;
|
|
119
|
-
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
120
128
|
return `${C}root(${this._nth}){${this._radical}}`;
|
|
121
129
|
}
|
|
122
130
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pimath",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.98",
|
|
4
4
|
"description": "A math library for teacher :)",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "mocha -r ts-node/register 'tests/**/*.test.ts'",
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/chai": "*",
|
|
19
19
|
"@types/mocha": "*",
|
|
20
|
-
"@types/node": "^18.11.
|
|
21
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
22
|
-
"@typescript-eslint/parser": "^5.
|
|
20
|
+
"@types/node": "^18.11.9",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
22
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
23
23
|
"chai": "*",
|
|
24
24
|
"mocha": "*",
|
|
25
|
-
"eslint": "^8.
|
|
25
|
+
"eslint": "^8.27.0",
|
|
26
26
|
"ts-loader": "^9.4.1",
|
|
27
27
|
"ts-node": "^10.9.1",
|
|
28
|
-
"typedoc": "^0.23.
|
|
28
|
+
"typedoc": "^0.23.20",
|
|
29
29
|
"typescript": "^4.8.4",
|
|
30
30
|
"webpack": "^5.74.0",
|
|
31
|
-
"webpack-bundle-analyzer": "^4.
|
|
31
|
+
"webpack-bundle-analyzer": "^4.7.0",
|
|
32
32
|
"webpack-cli": "^4.10.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -8,6 +8,7 @@ import {Fraction} from "../coefficients/fraction";
|
|
|
8
8
|
import {literalType} from "./monom";
|
|
9
9
|
import {PARTICULAR_SOLUTION} from "./equation";
|
|
10
10
|
import {RationalStudy} from "./study/rationalStudy";
|
|
11
|
+
import {StudyConfig} from "./study";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Rational class can handle rational polynoms
|
|
@@ -221,7 +222,7 @@ export class Rational {
|
|
|
221
222
|
return this._numerator.evaluateAsNumeric(values) / this._denominator.evaluateAsNumeric(values)
|
|
222
223
|
}
|
|
223
224
|
|
|
224
|
-
study = (): RationalStudy => {
|
|
225
|
-
return new RationalStudy(this)
|
|
225
|
+
study = (config?:StudyConfig|string): RationalStudy => {
|
|
226
|
+
return new RationalStudy(this, config)
|
|
226
227
|
}
|
|
227
228
|
}
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
ITableOfSigns,
|
|
22
22
|
IZero,
|
|
23
23
|
Study,
|
|
24
|
-
StudyableFunction,
|
|
24
|
+
StudyableFunction, StudyConfig,
|
|
25
25
|
TABLE_OF_SIGNS,
|
|
26
26
|
ZEROTYPE
|
|
27
27
|
} from "../study";
|
|
@@ -30,8 +30,8 @@ import {Fraction} from "../../coefficients/fraction";
|
|
|
30
30
|
import {Polynom} from "../polynom";
|
|
31
31
|
|
|
32
32
|
export class RationalStudy extends Study {
|
|
33
|
-
constructor(fx: StudyableFunction) {
|
|
34
|
-
super(fx)
|
|
33
|
+
constructor(fx: StudyableFunction, config?: StudyConfig|string) {
|
|
34
|
+
super(fx, config)
|
|
35
35
|
|
|
36
36
|
return this
|
|
37
37
|
}
|
|
@@ -37,16 +37,17 @@ export enum ASYMPTOTE_POSITION {
|
|
|
37
37
|
"LB" = "LB",
|
|
38
38
|
"RB" = "RB"
|
|
39
39
|
}
|
|
40
|
+
|
|
40
41
|
export interface IAsymptote {
|
|
41
|
-
fx: Polynom,
|
|
42
42
|
deltaX: StudyableFunction
|
|
43
|
+
display: string,
|
|
44
|
+
fx: Polynom,
|
|
43
45
|
limits: string,
|
|
46
|
+
position: ASYMPTOTE_POSITION[]
|
|
47
|
+
tableOfSign: ITableOfSigns,
|
|
44
48
|
tex: string,
|
|
45
|
-
display: string,
|
|
46
49
|
type: ASYMPTOTE,
|
|
47
50
|
zero: IZero,
|
|
48
|
-
position: ASYMPTOTE_POSITION[]
|
|
49
|
-
tableOfSign: ITableOfSigns,
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export enum FUNCTION_EXTREMA {
|
|
@@ -74,15 +75,24 @@ export interface ITableOfSigns {
|
|
|
74
75
|
factors: Polynom[],
|
|
75
76
|
fx: StudyableFunction,
|
|
76
77
|
signs: (string[])[],
|
|
78
|
+
tex: string
|
|
77
79
|
type: TABLE_OF_SIGNS
|
|
78
80
|
zeroes: IZero[],
|
|
79
|
-
tex: string
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
export enum TABLE_OF_SIGNS {
|
|
83
84
|
SIGNS = "signs",
|
|
84
85
|
GROWS = "grows",
|
|
85
|
-
VARIATIONS = "
|
|
86
|
+
VARIATIONS = "variatins"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface StudyConfig {
|
|
90
|
+
asymptotes?: boolean,
|
|
91
|
+
derivative?: boolean,
|
|
92
|
+
domain?: boolean,
|
|
93
|
+
name?: string,
|
|
94
|
+
signs?: boolean,
|
|
95
|
+
variations?: boolean
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
/**
|
|
@@ -107,9 +117,41 @@ export class Study {
|
|
|
107
117
|
private _signs: ITableOfSigns
|
|
108
118
|
private _variations: ITableOfSigns
|
|
109
119
|
private _zeroes: IZero[]
|
|
120
|
+
private config: StudyConfig
|
|
121
|
+
private name: string
|
|
110
122
|
|
|
111
|
-
constructor(fx: StudyableFunction) {
|
|
123
|
+
constructor(fx: StudyableFunction, config?: StudyConfig | string) {
|
|
112
124
|
this.fx = fx
|
|
125
|
+
|
|
126
|
+
this.config = {
|
|
127
|
+
name :'f',
|
|
128
|
+
domain :true,
|
|
129
|
+
asymptotes :true,
|
|
130
|
+
signs :true,
|
|
131
|
+
derivative :true,
|
|
132
|
+
variations :true,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (config) {
|
|
136
|
+
if (typeof config === 'string') {
|
|
137
|
+
const d = config.split(',')
|
|
138
|
+
this.config = {}
|
|
139
|
+
let n = d.filter(x=>x.includes('(x)'))
|
|
140
|
+
if(n.length===1){
|
|
141
|
+
this.config.name = n[0].split('(x)')[0]
|
|
142
|
+
}
|
|
143
|
+
this.config.domain = d.includes('d')
|
|
144
|
+
this.config.asymptotes = d.includes('a')
|
|
145
|
+
this.config.signs = d.includes('signs')
|
|
146
|
+
this.config.derivative = d.includes('dx')
|
|
147
|
+
this.config.variations = d.includes('ddx')
|
|
148
|
+
} else {
|
|
149
|
+
this.config = config
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this.name = this.config?.name ?? 'f'
|
|
154
|
+
|
|
113
155
|
this.makeStudy()
|
|
114
156
|
return this
|
|
115
157
|
}
|
|
@@ -149,20 +191,20 @@ export class Study {
|
|
|
149
191
|
makeStudy = (): void => {
|
|
150
192
|
this._zeroes = this.makeZeroes()
|
|
151
193
|
|
|
152
|
-
this._signs = this.makeSigns()
|
|
153
|
-
|
|
154
|
-
this._asymptotes = this.makeAsymptotes()
|
|
194
|
+
if (this.config.signs) this._signs = this.makeSigns()
|
|
155
195
|
|
|
156
|
-
this.
|
|
196
|
+
if (this.config.asymptotes) this._asymptotes = this.makeAsymptotes()
|
|
157
197
|
|
|
158
|
-
this.
|
|
198
|
+
if (this.config.derivative) this._derivative = this.makeDerivative()
|
|
159
199
|
|
|
160
|
-
this.
|
|
200
|
+
if (this.config.variations) this._variations = this.makeVariation()
|
|
161
201
|
|
|
162
|
-
|
|
202
|
+
// Table of signs / derivative / variation
|
|
203
|
+
if (this.config.signs) this._signs.tex = this.texSigns
|
|
163
204
|
|
|
164
|
-
this.
|
|
205
|
+
if (this.config.derivative) this._derivative.tex = this.texGrows
|
|
165
206
|
|
|
207
|
+
if (this.config.variations) this._variations.tex = this.texVariations
|
|
166
208
|
};
|
|
167
209
|
|
|
168
210
|
indexOfZero = (zeroes: IZero[], zero: IZero | ISolution): number => {
|
|
@@ -371,42 +413,6 @@ export class Study {
|
|
|
371
413
|
}
|
|
372
414
|
}
|
|
373
415
|
|
|
374
|
-
private _makeTexFromTableOfSigns = (tos: ITableOfSigns): string => {
|
|
375
|
-
let factors = tos.factors.map(x => `\\(${x.tex}\\)/1`),
|
|
376
|
-
factorsFx = "\\(fx\\)/1.2",
|
|
377
|
-
zeroes = tos.zeroes
|
|
378
|
-
|
|
379
|
-
// Add the last lines "label"
|
|
380
|
-
if (tos.type === TABLE_OF_SIGNS.GROWS) {
|
|
381
|
-
factorsFx = "\\(f'(x)\\)/1.2,\\(f(x)\\)/2"
|
|
382
|
-
} else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
|
|
383
|
-
factorsFx = "\\(f''(x)\\)/1.2,\\(f(x)\\)/2"
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// Create the tikzPicture header
|
|
387
|
-
let tex = `\\begin{tikzpicture}
|
|
388
|
-
\\tkzTabInit[lgt=3,espcl=2,deltacl=0]{/1.2,${factors.join(',')},/.1,${factorsFx} }{{\\scriptsize \\hspace{1cm} \\(-\\infty\\)},\\(${zeroes.map(x => x.tex).join('\\),\\(')}\\),{\\scriptsize \\hspace{-1cm} \\(+\\infty\\)}}`
|
|
389
|
-
|
|
390
|
-
let pos
|
|
391
|
-
for (pos = 0; pos < tos.factors.length; pos++) {
|
|
392
|
-
tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Add the result line
|
|
396
|
-
tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`)
|
|
397
|
-
// Add the grows / vars line
|
|
398
|
-
if (tos.type === TABLE_OF_SIGNS.GROWS) {
|
|
399
|
-
tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`)
|
|
400
|
-
} else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
|
|
401
|
-
// TODO: Check variations table for as tex
|
|
402
|
-
tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`)
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
tex += `\n\\end{tikzpicture}`
|
|
406
|
-
|
|
407
|
-
return tex
|
|
408
|
-
}
|
|
409
|
-
|
|
410
416
|
drawCode = (): string => {
|
|
411
417
|
// Function as string
|
|
412
418
|
let code = `f(x)=${this.fx.plotFunction}`
|
|
@@ -443,4 +449,40 @@ export class Study {
|
|
|
443
449
|
|
|
444
450
|
return code
|
|
445
451
|
}
|
|
452
|
+
|
|
453
|
+
private _makeTexFromTableOfSigns = (tos: ITableOfSigns): string => {
|
|
454
|
+
let factors = tos.factors.map(x => `\\(${x.tex}\\)/1`),
|
|
455
|
+
factorsFx = `\\(${this.name}(x)\\)/1.2`,
|
|
456
|
+
zeroes = tos.zeroes
|
|
457
|
+
|
|
458
|
+
// Add the last lines "label"
|
|
459
|
+
if (tos.type === TABLE_OF_SIGNS.GROWS) {
|
|
460
|
+
factorsFx = `\\(${this.name}'(x)\\)/1.2,\\(f(x)\\)/2`
|
|
461
|
+
} else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
|
|
462
|
+
factorsFx = `\\(${this.name}''(x)\\)/1.2,\\(f(x)\\)/2`
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Create the tikzPicture header
|
|
466
|
+
let tex = `\\begin{tikzpicture}
|
|
467
|
+
\\tkzTabInit[lgt=3,espcl=2,deltacl=0]{/1.2,${factors.join(',')},/.1,${factorsFx} }{{\\scriptsize \\hspace{1cm} \\(-\\infty\\)},\\(${zeroes.map(x => x.tex).join('\\),\\(')}\\),{\\scriptsize \\hspace{-1cm} \\(+\\infty\\)}}`
|
|
468
|
+
|
|
469
|
+
let pos
|
|
470
|
+
for (pos = 0; pos < tos.factors.length; pos++) {
|
|
471
|
+
tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Add the result line
|
|
475
|
+
tex += (`\n\\tkzTabLine{${tos.signs[pos].join(',')}}`)
|
|
476
|
+
// Add the grows / vars line
|
|
477
|
+
if (tos.type === TABLE_OF_SIGNS.GROWS) {
|
|
478
|
+
tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`)
|
|
479
|
+
} else if (tos.type === TABLE_OF_SIGNS.VARIATIONS) {
|
|
480
|
+
// TODO: Check variations table for as tex
|
|
481
|
+
tex += (`\n\\tkzTabVar{${tos.signs[pos + 1].join(',')}}`)
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
tex += `\n\\end{tikzpicture}`
|
|
485
|
+
|
|
486
|
+
return tex
|
|
487
|
+
}
|
|
446
488
|
}
|