ziko 0.53.0 → 0.54.0
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/ziko.js +5582 -5450
- package/dist/ziko.mjs +939 -807
- package/package.json +1 -1
- package/src/math/complex/index.js +76 -82
- package/src/math/functions/arithmetic/index.js +82 -0
- package/src/math/functions/index.js +39 -153
- package/src/math/{mapfun → functions/mapfun}/index.js +1 -1
- package/src/math/functions/{primitives → nested}/index.js +37 -21
- package/src/math/functions/utils/index.js +65 -0
- package/src/math/matrix/helpers/det.js +1 -1
- package/src/math/matrix/matrix.js +9 -14
- package/src/math/signal/functions.js +9 -69
- package/src/math/stats/accum/index.js +39 -0
- package/src/math/stats/average/index.js +75 -0
- package/src/math/stats/index.js +17 -0
- package/src/math/stats/position/index.js +21 -0
- package/src/math/stats/rolling/index.js +34 -0
- package/src/math/stats/variability/index.js +37 -0
- package/src/math/utils/arithmetic.js +1 -1
- package/src/math/utils/index.js +39 -39
- package/src/time/animation/index.js +1 -1
- package/types/math/complex/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
sin,
|
|
4
|
-
tan,
|
|
5
|
-
pow,
|
|
6
|
-
floor,
|
|
7
|
-
hypot,
|
|
8
|
-
cosh,
|
|
9
|
-
sinh,
|
|
10
|
-
sqrtn,
|
|
11
|
-
atan2,
|
|
12
|
-
sqrt,
|
|
13
|
-
ln
|
|
14
|
-
}from "../functions/index.js"
|
|
15
|
-
import {sum,prod,deg2rad} from "../utils/index.js";
|
|
1
|
+
// import {sum,prod,deg2rad} from "../utils/index.js";
|
|
2
|
+
// Should avoid CD
|
|
16
3
|
class Complex{
|
|
17
4
|
constructor(a = 0, b = 0) {
|
|
18
5
|
if(a instanceof Complex){
|
|
@@ -21,33 +8,33 @@ class Complex{
|
|
|
21
8
|
}
|
|
22
9
|
else if(typeof(a)==="object"){
|
|
23
10
|
if(("a" in a && "b" in a)){
|
|
24
|
-
this.a=a.a;
|
|
25
|
-
this.b=a.b;
|
|
11
|
+
this.a = a.a;
|
|
12
|
+
this.b = a.b;
|
|
26
13
|
}
|
|
27
14
|
else if(("a" in a && "z" in a)){
|
|
28
|
-
this.a=a.a;
|
|
29
|
-
this.b=sqrt((a.z**2)-(a.a**2));
|
|
15
|
+
this.a = a.a;
|
|
16
|
+
this.b = Math.sqrt((a.z**2)-(a.a**2));
|
|
30
17
|
}
|
|
31
18
|
else if(("a" in a && "phi" in a)){
|
|
32
|
-
this.a=a.a;
|
|
33
|
-
this.b=a.a*tan(a.phi);
|
|
19
|
+
this.a = a.a;
|
|
20
|
+
this.b = a.a * Math.tan(a.phi);
|
|
34
21
|
}
|
|
35
22
|
else if(("b" in a && "z" in a)){
|
|
36
|
-
this.b=a.b;
|
|
37
|
-
this.a=sqrt((a.z**2)-(a.b**2));
|
|
23
|
+
this.b = a.b;
|
|
24
|
+
this.a = Math.sqrt((a.z**2)-(a.b**2));
|
|
38
25
|
}
|
|
39
26
|
else if(("b" in a && "phi" in a)){
|
|
40
|
-
this.b=b;
|
|
41
|
-
this.a=a.b/tan(a.phi);
|
|
27
|
+
this.b = b;
|
|
28
|
+
this.a = a.b / Math.tan(a.phi);
|
|
42
29
|
}
|
|
43
30
|
else if(("z" in a && "phi" in a)){
|
|
44
|
-
this.a = +a.z*cos(a.phi).toFixed(15);
|
|
45
|
-
this.b = +a.z*sin(a.phi).toFixed(15);
|
|
31
|
+
this.a = + a.z * Math.cos(a.phi).toFixed(15);
|
|
32
|
+
this.b = + a.z * Math.sin(a.phi).toFixed(15);
|
|
46
33
|
}
|
|
47
34
|
}
|
|
48
|
-
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
49
|
-
this.a = +a.toFixed(32);
|
|
50
|
-
this.b = +b.toFixed(32);
|
|
35
|
+
else if(typeof(a)==="number" && typeof(b)==="number"){
|
|
36
|
+
this.a = + a.toFixed(32);
|
|
37
|
+
this.b = + b.toFixed(32);
|
|
51
38
|
}
|
|
52
39
|
}
|
|
53
40
|
get __mapfun__(){
|
|
@@ -73,10 +60,10 @@ class Complex{
|
|
|
73
60
|
return new Complex(this.a, this.b);
|
|
74
61
|
}
|
|
75
62
|
get z(){
|
|
76
|
-
return hypot(this.a,this.b);
|
|
63
|
+
return Math.hypot(this.a,this.b);
|
|
77
64
|
}
|
|
78
65
|
get phi(){
|
|
79
|
-
return atan2(this.b , this.a);
|
|
66
|
+
return Math.atan2(this.b , this.a);
|
|
80
67
|
}
|
|
81
68
|
static Zero() {
|
|
82
69
|
return new Complex(0, 0);
|
|
@@ -85,54 +72,54 @@ class Complex{
|
|
|
85
72
|
return new Complex(this.a, -this.b);
|
|
86
73
|
}
|
|
87
74
|
get inv() {
|
|
88
|
-
return new Complex(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
return new Complex(
|
|
76
|
+
this.a / Math.hypot(this.a, this.b),
|
|
77
|
+
-this.b / Math.hypot(this.a, this.b)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
add(...c) {
|
|
81
|
+
for (let i = 0; i < c.length; i++) {
|
|
82
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
83
|
+
this.a += c[i].a;
|
|
84
|
+
this.b += c[i].b;
|
|
93
85
|
}
|
|
94
|
-
let re = z.map((n) => n.a);
|
|
95
|
-
let im = z.map((n) => n.b);
|
|
96
|
-
this.a+=+sum(...re).toFixed(15);
|
|
97
|
-
this.b+=+sum(...im).toFixed(15);
|
|
98
86
|
return this;
|
|
99
87
|
}
|
|
100
|
-
sub(...
|
|
101
|
-
for (let i = 0; i <
|
|
102
|
-
if (typeof
|
|
88
|
+
sub(...c) {
|
|
89
|
+
for (let i = 0; i < c.length; i++) {
|
|
90
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
91
|
+
this.a -= c[i].a;
|
|
92
|
+
this.b -= c[i].b;
|
|
103
93
|
}
|
|
104
|
-
let re = z.map((n) => n.a);
|
|
105
|
-
let im = z.map((n) => n.b);
|
|
106
|
-
this.a-=+sum(...re).toFixed(15);
|
|
107
|
-
this.b-=+sum(...im).toFixed(15);
|
|
108
94
|
return this;
|
|
109
95
|
}
|
|
110
|
-
mul(...
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
mul(...c){
|
|
97
|
+
let {z, phi} = this;
|
|
98
|
+
for (let i = 0; i < c.length; i++) {
|
|
99
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
100
|
+
z *= c[i].z;
|
|
101
|
+
phi += c[i].z;
|
|
113
102
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
|
|
117
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
|
|
103
|
+
this.a = z*Math.cos(phi)
|
|
104
|
+
this.b = z*Math.sin(phi)
|
|
118
105
|
return this;
|
|
119
106
|
}
|
|
120
|
-
div(...
|
|
121
|
-
|
|
122
|
-
|
|
107
|
+
div(...c){
|
|
108
|
+
let {z, phi} = this;
|
|
109
|
+
for (let i = 0; i < c.length; i++) {
|
|
110
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
111
|
+
z /= c[i].z;
|
|
112
|
+
phi -= c[i].z;
|
|
123
113
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
|
|
127
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
|
|
114
|
+
this.a = z*Math.cos(phi)
|
|
115
|
+
this.b = z*Math.sin(phi)
|
|
128
116
|
return this;
|
|
129
117
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.
|
|
135
|
-
this.b=+(z*sin(phi).toFixed(15)).toFixed(15);
|
|
118
|
+
modulo(...c) {
|
|
119
|
+
for (let i = 0; i < c.length; i++) {
|
|
120
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
121
|
+
this.a %= c[i].a;
|
|
122
|
+
this.b %= c[i].b;
|
|
136
123
|
}
|
|
137
124
|
return this;
|
|
138
125
|
}
|
|
@@ -157,30 +144,37 @@ class Complex{
|
|
|
157
144
|
static div(c,...z) {
|
|
158
145
|
return c.clone().div(...z);
|
|
159
146
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
static xpowZ(x){
|
|
164
|
-
return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
|
|
165
|
-
}
|
|
166
|
-
sqrtn(n=2){
|
|
167
|
-
return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
|
|
147
|
+
|
|
148
|
+
nthr(n=2){
|
|
149
|
+
return complex({z: this.z ** (1/n), phi: this.phi / n});
|
|
168
150
|
}
|
|
169
151
|
get sqrt(){
|
|
170
|
-
return this.
|
|
152
|
+
return this.nrth(2);
|
|
153
|
+
}
|
|
154
|
+
get cbrt(){
|
|
155
|
+
return this.nrth(3);
|
|
171
156
|
}
|
|
172
157
|
get log(){
|
|
173
|
-
return complex(this.z,this.phi);
|
|
158
|
+
return complex(this.z, this.phi);
|
|
174
159
|
}
|
|
175
160
|
get cos(){
|
|
176
|
-
return complex(
|
|
161
|
+
return complex(
|
|
162
|
+
Math.cos(this.a) * Math.cosh(this.b),
|
|
163
|
+
Math.sin(this.a) * Math.sinh(this.b)
|
|
164
|
+
)
|
|
177
165
|
}
|
|
178
166
|
get sin(){
|
|
179
|
-
return complex(
|
|
167
|
+
return complex(
|
|
168
|
+
Math.sin(this.a) * Math.cosh(this.b),
|
|
169
|
+
Math.cos(this.a) * Math.sinh(this.b)
|
|
170
|
+
)
|
|
180
171
|
}
|
|
181
172
|
get tan(){
|
|
182
|
-
const
|
|
183
|
-
return complex(
|
|
173
|
+
const D=cos(this.a*2)+cosh(this.b*2);
|
|
174
|
+
return complex(
|
|
175
|
+
Math.sin(2 * this.a) / D,
|
|
176
|
+
Math.sinh(2 * this.b) / D
|
|
177
|
+
);
|
|
184
178
|
}
|
|
185
179
|
}
|
|
186
180
|
const complex=(a,b)=>{
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const _add = (x, y) =>{
|
|
2
|
+
if(typeof x === 'number'){
|
|
3
|
+
if(typeof y === 'number') return x + y;
|
|
4
|
+
if(y.isComplex?.()) {
|
|
5
|
+
return y.clone().add(x);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
if(x.isComplex?.()){
|
|
9
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().add(y);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const _sub = (x, y) =>{
|
|
14
|
+
if(typeof x === 'number'){
|
|
15
|
+
if(typeof y === 'number') return x - y;
|
|
16
|
+
if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
|
|
17
|
+
}
|
|
18
|
+
if(x.isComplex?.()){
|
|
19
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().sub(y);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const _mul = (x, y) =>{
|
|
24
|
+
if(typeof x === 'number'){
|
|
25
|
+
if(typeof y === 'number') return x * y;
|
|
26
|
+
if(y.isComplex?.()) return y.clone().mul(x);
|
|
27
|
+
}
|
|
28
|
+
if(x.isComplex?.()){
|
|
29
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const _div = (x, y) =>{
|
|
34
|
+
if(typeof x === 'number'){
|
|
35
|
+
if(typeof y === 'number') return x / y;
|
|
36
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
|
|
37
|
+
}
|
|
38
|
+
if(x.isComplex?.()){
|
|
39
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const _modulo = (x, y) =>{
|
|
44
|
+
if(typeof x === 'number'){
|
|
45
|
+
if(typeof y === 'number') return x % y;
|
|
46
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
|
|
47
|
+
}
|
|
48
|
+
if(x.isComplex?.()){
|
|
49
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().modulo(y);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const add=(a,...b)=>{
|
|
54
|
+
let res = a;
|
|
55
|
+
for(let i=0; i<b.length; i++)
|
|
56
|
+
res = _add(res, b[i])
|
|
57
|
+
return res;
|
|
58
|
+
}
|
|
59
|
+
export const sub=(a,...b)=>{
|
|
60
|
+
let res = a;
|
|
61
|
+
for(let i=0; i<b.length; i++)
|
|
62
|
+
res = _sub(res, b[i])
|
|
63
|
+
return res;
|
|
64
|
+
}
|
|
65
|
+
export const mul=(a,...b)=>{
|
|
66
|
+
let res = a;
|
|
67
|
+
for(let i=0; i<b.length; i++)
|
|
68
|
+
res = _mul(res, b[i])
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
export const div=(a,...b)=>{
|
|
72
|
+
let res = a;
|
|
73
|
+
for(let i=0; i<b.length; i++)
|
|
74
|
+
res = _div(res, b[i])
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
export const modulo=(a,...b)=>{
|
|
78
|
+
let res = a;
|
|
79
|
+
for(let i=0; i<b.length; i++)
|
|
80
|
+
res = _modulo(res, b[i])
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
@@ -1,155 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export * from './mapfun/index.js'
|
|
2
|
+
export * from './nested/index.js'
|
|
3
|
+
export * from './arithmetic/index.js'
|
|
4
|
+
export * from './utils/index.js'
|
|
5
|
+
// export const atan2=(x,y,rad=true)=>{
|
|
6
|
+
// if(typeof x === "number"){
|
|
7
|
+
// if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
8
|
+
// else return mapfun(a=>atan2(x,a,rad),...y);
|
|
9
|
+
// }
|
|
10
|
+
// // else if(x.isComplex?.()){
|
|
11
|
+
// // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
12
|
+
// // else return mapfun(a=>pow(x,a),...n);
|
|
13
|
+
// // }
|
|
14
|
+
// else if(x instanceof Array){
|
|
15
|
+
// if(typeof y === "number") return mapfun(a=>atan2(a,y,rad),...x);
|
|
16
|
+
// else if(y instanceof Array){
|
|
17
|
+
// const Y=[];
|
|
18
|
+
// for(let i=0;i<x.length;i++){
|
|
19
|
+
// Y.push(mapfun(a=>pow(x[i],a,rad),...y))
|
|
20
|
+
// }
|
|
21
|
+
// return Y;
|
|
22
|
+
// }
|
|
23
|
+
// }
|
|
24
|
+
// }
|
|
25
|
+
// export const fact=(...x)=>mapfun(n=> {
|
|
26
|
+
// let i,
|
|
27
|
+
// y = 1;
|
|
28
|
+
// if (n == 0) y = 1;
|
|
29
|
+
// else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
30
|
+
// else y = NaN;
|
|
31
|
+
// return y;
|
|
32
|
+
// },...x);
|
|
8
33
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
else if(x.isComplex?.()){
|
|
18
|
-
if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
19
|
-
else if(n.isComplex?.())return x.constructor.fromExpo(
|
|
20
|
-
x.z**n.a*e(-x.phi*n.b),
|
|
21
|
-
ln(x.z)*n.b+n.a*x.phi
|
|
22
|
-
)
|
|
23
|
-
else return mapfun(a=>pow(x,a),...n);
|
|
24
|
-
}
|
|
25
|
-
else if(x instanceof Array){
|
|
26
|
-
if(typeof n === "number") return mapfun(a=>pow(a,n),...x);
|
|
27
|
-
else if(n instanceof Array){
|
|
28
|
-
const Y=[];
|
|
29
|
-
for(let i=0;i<x.length;i++){
|
|
30
|
-
Y.push(mapfun(a=>pow(x[i],a),...n))
|
|
31
|
-
}
|
|
32
|
-
return Y;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const sqrtn=(x,n)=>{
|
|
37
|
-
if(typeof x === "number"){
|
|
38
|
-
if(typeof n === "number")return Math.pow(x,1/n);
|
|
39
|
-
else return mapfun(a=>sqrtn(x,a),...n);
|
|
40
|
-
}
|
|
41
|
-
else if(x.isComplex?.()){
|
|
42
|
-
if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
|
|
43
|
-
else return mapfun(a=>sqrtn(x,a),...n);
|
|
44
|
-
}
|
|
45
|
-
else if(x instanceof Array){
|
|
46
|
-
if(typeof n === "number") return mapfun(a=>sqrtn(a,n),...x);
|
|
47
|
-
else if(n instanceof Array){
|
|
48
|
-
const Y=[];
|
|
49
|
-
for(let i=0;i<x.length;i++){
|
|
50
|
-
Y.push(mapfun(a=>sqrtn(x[i],a),...n))
|
|
51
|
-
}
|
|
52
|
-
return Y;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const e=(...x) => mapfun(Math.exp,...x);
|
|
57
|
-
const ln=(...x) => mapfun(Math.log,...x);
|
|
58
|
-
const cos=(...x) => mapfun(Fixed.cos,...x);
|
|
59
|
-
const sin=(...x) => mapfun(Fixed.sin,...x);
|
|
60
|
-
const tan=(...x) => mapfun(Fixed.tan,...x);
|
|
61
|
-
const sec=(...x) => mapfun(Fixed.sec,...x);
|
|
62
|
-
const sinc=(...x) => mapfun(Fixed.sinc,...x)
|
|
63
|
-
const csc=(...x) => mapfun(Fixed.csc,...x);
|
|
64
|
-
const cot=(...x) => mapfun(Fixed.cot,...x);
|
|
65
|
-
const acos=(...x) => mapfun(Fixed.acos,...x);
|
|
66
|
-
const asin=(...x) => mapfun(Fixed.asin,...x);
|
|
67
|
-
const atan=(...x) => mapfun(Fixed.atan,...x);
|
|
68
|
-
const acot=(...x) => mapfun(Fixed.acot,...x);
|
|
69
|
-
const cosh=(...x) => mapfun(Fixed.cosh,...x);
|
|
70
|
-
const sinh=(...x) => mapfun(Fixed.sinh,...x);
|
|
71
|
-
const tanh=(...x) => mapfun(Fixed.tanh,...x);
|
|
72
|
-
const coth=(...x) => mapfun(Fixed.coth,...x);
|
|
73
|
-
const acosh=(...x) => mapfun(Fixed.acosh,...x);
|
|
74
|
-
const asinh=(...x) => mapfun(Fixed.asinh,...x);
|
|
75
|
-
const atanh=(...x) => mapfun(Fixed.atanh,...x);
|
|
76
|
-
const ceil=(...x) => mapfun(Math.ceil,...x);
|
|
77
|
-
const floor=(...x) => mapfun(Math.floor,...x);
|
|
78
|
-
const round=(...x) => mapfun(Math.round,...x);
|
|
79
|
-
const atan2=(x,y,rad=true)=>{
|
|
80
|
-
if(typeof x === "number"){
|
|
81
|
-
if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
82
|
-
else return mapfun(a=>atan2(x,a,rad),...y);
|
|
83
|
-
}
|
|
84
|
-
// else if(x.isComplex?.()){
|
|
85
|
-
// if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
86
|
-
// else return mapfun(a=>pow(x,a),...n);
|
|
87
|
-
// }
|
|
88
|
-
else if(x instanceof Array){
|
|
89
|
-
if(typeof y === "number") return mapfun(a=>atan2(a,y,rad),...x);
|
|
90
|
-
else if(y instanceof Array){
|
|
91
|
-
const Y=[];
|
|
92
|
-
for(let i=0;i<x.length;i++){
|
|
93
|
-
Y.push(mapfun(a=>pow(x[i],a,rad),...y))
|
|
94
|
-
}
|
|
95
|
-
return Y;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const fact=(...x)=>mapfun(n=> {
|
|
100
|
-
let i,
|
|
101
|
-
y = 1;
|
|
102
|
-
if (n == 0) y = 1;
|
|
103
|
-
else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
104
|
-
else y = NaN;
|
|
105
|
-
return y;
|
|
106
|
-
},...x);
|
|
107
|
-
const sign=(...x)=>mapfun(Math.sign,...x);
|
|
34
|
+
// export const hypot=(...x)=>{
|
|
35
|
+
// if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
|
|
36
|
+
// if(x.every(n=>n instanceof Array))return mapfun(
|
|
37
|
+
// Math.hypot,
|
|
38
|
+
// ...x
|
|
39
|
+
// )
|
|
40
|
+
// }
|
|
108
41
|
|
|
109
|
-
const sig=(...x)=>mapfun(n=>1/(1+e(-n)),...x);
|
|
110
|
-
|
|
111
|
-
const hypot=(...x)=>{
|
|
112
|
-
if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
|
|
113
|
-
if(x.every(n=>n instanceof Array))return mapfun(
|
|
114
|
-
Math.hypot,
|
|
115
|
-
...x
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export{
|
|
120
|
-
cos,
|
|
121
|
-
sin,
|
|
122
|
-
tan,
|
|
123
|
-
sinc,
|
|
124
|
-
cot,
|
|
125
|
-
sec,
|
|
126
|
-
csc,
|
|
127
|
-
abs,
|
|
128
|
-
sqrt,
|
|
129
|
-
pow,
|
|
130
|
-
sqrtn,
|
|
131
|
-
e,
|
|
132
|
-
ln,
|
|
133
|
-
acos,
|
|
134
|
-
asin,
|
|
135
|
-
atan,
|
|
136
|
-
acot,
|
|
137
|
-
cosh,
|
|
138
|
-
sinh,
|
|
139
|
-
tanh,
|
|
140
|
-
coth,
|
|
141
|
-
acosh,
|
|
142
|
-
asinh,
|
|
143
|
-
atanh,
|
|
144
|
-
min,
|
|
145
|
-
max,
|
|
146
|
-
sign,
|
|
147
|
-
floor,
|
|
148
|
-
ceil,
|
|
149
|
-
round,
|
|
150
|
-
fact,
|
|
151
|
-
hypot,
|
|
152
|
-
sig,
|
|
153
|
-
atan2
|
|
154
|
-
};
|
|
155
|
-
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { mapfun } from '
|
|
1
|
+
import { mapfun } from '../mapfun/index.js';
|
|
2
|
+
import { complex } from '../../complex/index.js'
|
|
3
|
+
|
|
4
|
+
export const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
5
|
+
export const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
2
6
|
|
|
3
7
|
export const abs = (...x) => mapfun(
|
|
4
8
|
x =>{
|
|
@@ -22,7 +26,7 @@ export const pow = (...x) => {
|
|
|
22
26
|
if(n.isComplex?.()) return new x.constructor({
|
|
23
27
|
z: Math.exp(n.a * Math.log(x)),
|
|
24
28
|
phi: n.b * Math.log(x)
|
|
25
|
-
|
|
29
|
+
})
|
|
26
30
|
return Math.pow(x, n)
|
|
27
31
|
},
|
|
28
32
|
...x
|
|
@@ -32,7 +36,8 @@ export const pow = (...x) => {
|
|
|
32
36
|
export const sqrt = (...x) => mapfun(
|
|
33
37
|
x=>{
|
|
34
38
|
if(x.isComplex?.())
|
|
35
|
-
return new x.constructor({z: x.z**(1/2), phi: x.phi/2})
|
|
39
|
+
return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
|
|
40
|
+
if(x < 0) return complex(0, Math.sqrt(-x))
|
|
36
41
|
return Math.sqrt(x);
|
|
37
42
|
},
|
|
38
43
|
...x
|
|
@@ -42,16 +47,18 @@ export const cbrt = (...x) => mapfun(
|
|
|
42
47
|
x=>{
|
|
43
48
|
if(x.isComplex?.())
|
|
44
49
|
return new x.constructor({z: x.z**(1/3), phi: x.phi/3})
|
|
45
|
-
return Math.
|
|
50
|
+
return Math.cbrt(x);
|
|
46
51
|
},
|
|
47
52
|
...x
|
|
48
53
|
);
|
|
49
54
|
|
|
50
55
|
export const nthr = (...x) => {
|
|
51
56
|
const n = x.pop();
|
|
57
|
+
if(typeof n !== 'number') throw Error('nthr expects a real number n');
|
|
52
58
|
return mapfun(
|
|
53
59
|
x => {
|
|
54
|
-
if(x.isComplex?.()) return new x.constructor({z: x.z ** 1/n, phi: x.phi / n});
|
|
60
|
+
if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
|
|
61
|
+
if(x<0) return n%2===2 ? complex(0, (-x)**(1/n)) : -1 * (-x)**(1/n)
|
|
55
62
|
return x**(1/n)
|
|
56
63
|
},
|
|
57
64
|
...x
|
|
@@ -59,11 +66,20 @@ export const nthr = (...x) => {
|
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
export const croot = (...x) =>{
|
|
62
|
-
const
|
|
69
|
+
const c = x.pop()
|
|
70
|
+
if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
|
|
63
71
|
return mapfun(
|
|
64
72
|
x => {
|
|
65
|
-
if(x.
|
|
66
|
-
|
|
73
|
+
if(typeof x === 'number') x = new c.constructor(x, 0);
|
|
74
|
+
const {a : c_a, b : c_b} = c;
|
|
75
|
+
const {z, phi} = x;
|
|
76
|
+
const D = Math.hypot(c_a, c_b);
|
|
77
|
+
const A = Math.exp((Math.log(z)*c_a + phi*c_b)/D);
|
|
78
|
+
const B = (phi*c_a - Math.log(z)*c_b)/D
|
|
79
|
+
return new c.constructor(
|
|
80
|
+
A * Math.cos(B),
|
|
81
|
+
A * Math.sin(B)
|
|
82
|
+
)
|
|
67
83
|
},
|
|
68
84
|
...x
|
|
69
85
|
)
|
|
@@ -75,7 +91,7 @@ export const exp = (...x) => mapfun(
|
|
|
75
91
|
Math.exp(x.a) * Math.cos(x.b),
|
|
76
92
|
Math.exp(x.a) * Math.sin(x.b)
|
|
77
93
|
);
|
|
78
|
-
return Math.
|
|
94
|
+
return Math.exp(x)
|
|
79
95
|
}
|
|
80
96
|
,...x
|
|
81
97
|
);
|
|
@@ -86,7 +102,7 @@ export const ln = (...x) => mapfun(
|
|
|
86
102
|
Math.log(x.z),
|
|
87
103
|
x.phi
|
|
88
104
|
);
|
|
89
|
-
return Math.
|
|
105
|
+
return Math.log(x)
|
|
90
106
|
}
|
|
91
107
|
,...x
|
|
92
108
|
);
|
|
@@ -268,33 +284,33 @@ export const acot = (...x) => mapfun(
|
|
|
268
284
|
export const cosh = (...x) => mapfun(
|
|
269
285
|
x =>{
|
|
270
286
|
if(x?.isComplex) return new x.constructor(
|
|
271
|
-
cosh(x.a)*cos(x.b),
|
|
272
|
-
sinh(x.a)*sin(x.b)
|
|
287
|
+
Math.cosh(x.a) * Math.cos(x.b),
|
|
288
|
+
Math.sinh(x.a) * Math.sin(x.b)
|
|
273
289
|
);
|
|
274
|
-
return cosh(x)
|
|
290
|
+
return Math.cosh(x)
|
|
275
291
|
},
|
|
276
292
|
...x
|
|
277
293
|
)
|
|
278
294
|
export const sinh = (...x) => mapfun(
|
|
279
295
|
x =>{
|
|
280
296
|
if(x?.isComplex) return new x.constructor(
|
|
281
|
-
sinh(x.a)*cos(x.b),
|
|
282
|
-
cosh(x.a)*sin(x.b)
|
|
297
|
+
Math.sinh(x.a) * Math.cos(x.b),
|
|
298
|
+
Math.cosh(x.a) * Math.sin(x.b)
|
|
283
299
|
);
|
|
284
|
-
return sinh(x)
|
|
300
|
+
return Math.sinh(x)
|
|
285
301
|
},
|
|
286
302
|
...x
|
|
287
303
|
)
|
|
288
304
|
export const tanh = (...x) => mapfun(
|
|
289
305
|
x =>{
|
|
290
306
|
if(x?.isComplex){
|
|
291
|
-
const D=cosh(2*a)+cos(2*b);
|
|
307
|
+
const D = Math.cosh(2*a) + Math.cos(2*b);
|
|
292
308
|
return new x.constructor(
|
|
293
|
-
sinh(2*a)/D,
|
|
294
|
-
sin(2*b)/D
|
|
309
|
+
Math.sinh(2*a) / D,
|
|
310
|
+
Math.sin(2*b) / D
|
|
295
311
|
)
|
|
296
312
|
}
|
|
297
|
-
return tanh(x)
|
|
313
|
+
return Math.tanh(x)
|
|
298
314
|
},
|
|
299
315
|
...x
|
|
300
316
|
)
|
|
@@ -349,7 +365,7 @@ export const sig = (...x) => mapfun(
|
|
|
349
365
|
if(x?.isComplex){
|
|
350
366
|
|
|
351
367
|
}
|
|
352
|
-
return 1/(1+Math.
|
|
368
|
+
return 1/(1+Math.exp(-x))
|
|
353
369
|
},
|
|
354
370
|
...x
|
|
355
371
|
)
|