ziko 0.53.0 → 0.54.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.53.0",
3
+ "version": "0.54.1",
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
- cos,
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__(){
@@ -68,15 +55,24 @@ class Complex{
68
55
  : (str = `-${Math.abs(this.b)}*i`);
69
56
  return str;
70
57
  }
71
-
58
+ toFixed(n){
59
+ this.a = + this.a.toFixed(n);
60
+ this.b = + this.b.toFixed(n);
61
+ return this;
62
+ }
63
+ toPrecision(n){
64
+ this.a = + this.a.toPrecision(n);
65
+ this.b = + this.b.toPrecision(n);
66
+ return this;
67
+ }
72
68
  clone() {
73
69
  return new Complex(this.a, this.b);
74
70
  }
75
71
  get z(){
76
- return hypot(this.a,this.b);
72
+ return Math.hypot(this.a,this.b);
77
73
  }
78
74
  get phi(){
79
- return atan2(this.b , this.a);
75
+ return Math.atan2(this.b , this.a);
80
76
  }
81
77
  static Zero() {
82
78
  return new Complex(0, 0);
@@ -85,55 +81,66 @@ class Complex{
85
81
  return new Complex(this.a, -this.b);
86
82
  }
87
83
  get inv() {
88
- return new Complex(this.a / (pow(this.a, 2) + pow(this.b, 2)), -this.b / (pow(this.a, 2) + pow(this.b, 2)));
84
+ return new Complex(
85
+ this.a / Math.hypot(this.a, this.b),
86
+ -this.b / Math.hypot(this.a, this.b)
87
+ );
88
+ }
89
+ add(...c) {
90
+ for (let i = 0; i < c.length; i++) {
91
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
92
+ this.a += c[i].a;
93
+ this.b += c[i].b;
94
+ }
95
+ return this;
89
96
  }
90
- add(...z) {
91
- for (let i = 0; i < z.length; i++) {
92
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
97
+ sub(...c) {
98
+ for (let i = 0; i < c.length; i++) {
99
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
100
+ this.a -= c[i].a;
101
+ this.b -= c[i].b;
93
102
  }
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
103
  return this;
99
104
  }
100
- sub(...z) {
101
- for (let i = 0; i < z.length; i++) {
102
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
105
+ mul(...c){
106
+ let {z, phi} = this;
107
+ for (let i = 0; i < c.length; i++) {
108
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
109
+ z *= c[i].z;
110
+ phi += c[i].phi;
103
111
  }
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);
112
+ this.a = z * Math.cos(phi)
113
+ this.b = z * Math.sin(phi)
108
114
  return this;
109
115
  }
110
- mul(...z){
111
- for (let i = 0; i < z.length; i++) {
112
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
116
+ div(...c){
117
+ let {z, phi} = this;
118
+ for (let i = 0; i < c.length; i++) {
119
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
120
+ z /= c[i].z;
121
+ phi -= c[i].phi;
113
122
  }
114
- let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
115
- let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
116
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
117
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
123
+ this.a = z*Math.cos(phi)
124
+ this.b = z*Math.sin(phi)
118
125
  return this;
119
126
  }
120
- div(...z) {
121
- for (let i = 0; i < z.length; i++) {
122
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
127
+ modulo(...c) {
128
+ for (let i = 0; i < c.length; i++) {
129
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
130
+ this.a %= c[i].a;
131
+ this.b %= c[i].b;
123
132
  }
124
- let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
125
- let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
126
- this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
127
- this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
128
133
  return this;
129
134
  }
130
- pow(n) {
131
- if (floor(n) === n && n > 0) {
132
- let z=+(this.z**n).toFixed(15);
133
- let phi=+(this.phi*n).toFixed(15);
134
- this.a=+(z*cos(phi).toFixed(15)).toFixed(15);
135
- this.b=+(z*sin(phi).toFixed(15)).toFixed(15);
135
+ pow(...c){
136
+ let {z, phi} = this;
137
+ for (let i = 0; i < c.length; i++) {
138
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
139
+ z *= Math.exp(c[i].a * Math.log(z) - c[i].b * phi);
140
+ phi += c[i].b * Math.log(z) + c[i].a * phi;
136
141
  }
142
+ this.a = z * Math.cos(phi)
143
+ this.b = z * Math.sin(phi)
137
144
  return this;
138
145
  }
139
146
  static fromExpo(z, phi) {
@@ -157,30 +164,37 @@ class Complex{
157
164
  static div(c,...z) {
158
165
  return c.clone().div(...z);
159
166
  }
160
- static pow(z,n){
161
- return z.clone().pow(n);
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));
167
+
168
+ nthr(n=2){
169
+ return complex({z: this.z ** (1/n), phi: this.phi / n});
168
170
  }
169
171
  get sqrt(){
170
- return this.sqrtn(2);
172
+ return this.nrth(2);
173
+ }
174
+ get cbrt(){
175
+ return this.nrth(3);
171
176
  }
172
177
  get log(){
173
- return complex(this.z,this.phi);
178
+ return complex(this.z, this.phi);
174
179
  }
175
180
  get cos(){
176
- return complex(cos(this.a)*cosh(this.b),sin(this.a)*sinh(this.b))
181
+ return complex(
182
+ Math.cos(this.a) * Math.cosh(this.b),
183
+ Math.sin(this.a) * Math.sinh(this.b)
184
+ )
177
185
  }
178
186
  get sin(){
179
- return complex(sin(this.a)*cosh(this.b),cos(this.a)*sinh(this.b))
187
+ return complex(
188
+ Math.sin(this.a) * Math.cosh(this.b),
189
+ Math.cos(this.a) * Math.sinh(this.b)
190
+ )
180
191
  }
181
192
  get tan(){
182
- const de=cos(this.a*2)+cosh(this.b*2);
183
- return complex(sin(2*this.a)/de,sinh(2*this.b)/de);
193
+ const D=cos(this.a*2)+cosh(this.b*2);
194
+ return complex(
195
+ Math.sin(2 * this.a) / D,
196
+ Math.sinh(2 * this.b) / D
197
+ );
184
198
  }
185
199
  }
186
200
  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 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,42 @@
1
- import { Fixed } from "./helper.js";
2
- import { mapfun } from "../mapfun/index.js";
3
- import {
4
- min,
5
- max
6
- }
7
- from "../statistics/index.js";
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 * from './stats/index.js'
6
+ // export const atan2=(x,y,rad=true)=>{
7
+ // if(typeof x === "number"){
8
+ // if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
9
+ // else return mapfun(a=>atan2(x,a,rad),...y);
10
+ // }
11
+ // // else if(x.isComplex?.()){
12
+ // // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
13
+ // // else return mapfun(a=>pow(x,a),...n);
14
+ // // }
15
+ // else if(x instanceof Array){
16
+ // if(typeof y === "number") return mapfun(a=>atan2(a,y,rad),...x);
17
+ // else if(y instanceof Array){
18
+ // const Y=[];
19
+ // for(let i=0;i<x.length;i++){
20
+ // Y.push(mapfun(a=>pow(x[i],a,rad),...y))
21
+ // }
22
+ // return Y;
23
+ // }
24
+ // }
25
+ // }
26
+ // export const fact=(...x)=>mapfun(n=> {
27
+ // let i,
28
+ // y = 1;
29
+ // if (n == 0) y = 1;
30
+ // else if (n > 0) for (i = 1; i <= n; i++) y *= i;
31
+ // else y = NaN;
32
+ // return y;
33
+ // },...x);
8
34
 
9
- const abs=(...x)=>mapfun(Math.abs,...x);
10
- const sqrt=(...x)=>mapfun(Math.sqrt,...x);
11
- const pow=(x,n)=>{
12
- if(typeof x === "number"){
13
- if(typeof n === "number")return Math.pow(x,n);
14
- else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
15
- else return mapfun(a=>pow(x,a),...n);
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);
35
+ // export const hypot=(...x)=>{
36
+ // if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
37
+ // if(x.every(n=>n instanceof Array))return mapfun(
38
+ // Math.hypot,
39
+ // ...x
40
+ // )
41
+ // }
108
42
 
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,4 @@
1
- import { is_primitive } from "../../helpers/checkers/index.js";
1
+ import { is_primitive } from "../../../helpers/checkers/index.js";
2
2
  export const mapfun=(fun,...X)=>{
3
3
  const Y=X.map(x=>{
4
4
  if(is_primitive(x) || x?.__mapfun__) return fun(x)
@@ -17,3 +17,17 @@ export const mapfun=(fun,...X)=>{
17
17
  });
18
18
  return Y.length==1? Y[0]: Y;
19
19
  }
20
+
21
+ export const apply_fun = (x, fn) => {
22
+ if (x.isComplex?.()) return new x.constructor(
23
+ fn(x.a),
24
+ fn(x.b)
25
+ )
26
+ if (x.isMatrix?.()) return new x.constructor(
27
+ x.rows,
28
+ x.cols,
29
+ x.arr.flat(1).map(fn)
30
+ )
31
+ if (x instanceof Array) mapfun(fn, ...x)
32
+ return fn(x)
33
+ }