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/dist/ziko.mjs CHANGED
@@ -2,696 +2,52 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Fri Dec 05 2025 17:08:57 GMT+0100 (UTC+01:00)
5
+ Date : Wed Dec 10 2025 13:44:02 GMT+0100 (UTC+01:00)
6
6
  Git-Repo : https://github.com/zakarialaoui10/ziko.js
7
7
  Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
8
8
  Released under MIT License
9
9
  */
10
10
 
11
- const { PI: PI$2, E } = Math;
11
+ const { PI: PI$1, E } = Math;
12
12
  const EPSILON=Number.EPSILON;
13
13
 
14
- const {PI: PI$1, cos: cos$3, sin: sin$3, tan: tan$1, atan: atan$1, cosh: cosh$2, sinh: sinh$2, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log: log$1} = Math;
15
- let Fixed={
16
- cos : x=> {
17
- if(x.isComplex?.()) return new x.constructor(
18
- cos$3(x.a)*cosh$2(x.b),
19
- -(sin$3(x.a)*sinh$2(x.b))
20
- );
21
- return cos$3(x)
22
- },
23
- sin : x=>{
24
- if(x?.isComplex) return new x.constructor(
25
- sin$3(x.a)*cosh$2(x.b),
26
- cos$3(x.a)*sinh$2(x.b)
27
- );
28
- return sin$3(x)
29
- },
30
- tan : x=>{
31
- if(x?.isComplex){
32
- const DEN = cos$3(2*x.a)+cosh$2(2*x.b);
33
- return new x.constructor(
34
- sin$3(2*x.a)/DEN,
35
- sinh$2(2*x.b)/DEN
36
- );
37
- }
38
- return tan$1(x)
39
- },
40
- sinc: x => sin$3(PI$1*x)/(PI$1*x),
41
- sec: x => 1/cos$3(x),
42
- csc: x => 1/sin$3(x),
43
- cot: x => 1/tan$1(x),
44
- acos: x=>{
45
- if(x?.isComplex) return
46
- return sin$3(x)
47
- },
48
- asin: x=>{
49
- if(x?.isComplex) return
50
- return sin$3(x)
51
- },
52
- atan: x=>{
53
- if(x?.isComplex) return
54
- return sin$3(x)
55
- },
56
- acot: x => PI$1/2-atan$1(x),
57
- cosh: x=>{
58
- if(x?.isComplex) return new x.constructor(
59
- cosh$2(x.a)*cos$3(x.b),
60
- sinh$2(x.a)*sin$3(x.b)
61
- );
62
- return cosh$2(x)
63
- },
64
- sinh: x=>{
65
- if(x?.isComplex) return new x.constructor(
66
- sinh$2(x.a)*cos$3(x.b),
67
- cosh$2(x.a)*sin$3(x.b)
68
- );
69
- return sinh$2(x)
70
- },
71
- tanh: x=>{
72
- if(x?.isComplex){
73
- const DEN=cosh$2(2*a)+cos$3(2*b);
74
- return new x.constructor(
75
- sinh$2(2*a)/DEN,
76
- sin$3(2*b)/DEN
77
- )
78
- }
79
- return tanh$1(x)
80
- },
81
- coth: n => (1/2*log$1((1+n)/(1-n))),
82
- acosh: acosh$1,
83
- asinh: asinh$1,
84
- atanh: atanh$1,
85
- };
86
-
87
- // Fixed = new Proxy(Fixed, {
88
- // get(target, prop) {
89
- // if(prop in target){
90
- // return x => + target[prop](x).toFixed(15);
91
- // }
92
- // return undefined;
93
- // }
94
- // })
95
-
96
- const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
97
-
98
- const mapfun$1=(fun,...X)=>{
99
- const Y=X.map(x=>{
100
- if(is_primitive(x) || x?.__mapfun__) return fun(x)
101
- if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
102
- if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
103
- if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
104
- if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun$1(fun,n[1])]));
105
- if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun$1(x.arr.flat(1)))
106
- else if(x instanceof Object){
107
- return Object.fromEntries(
108
- Object.entries(x).map(
109
- n=>n=[n[0],mapfun$1(fun,n[1])]
110
- )
111
- )
112
- }
113
- });
114
- return Y.length==1? Y[0]: Y;
115
- };
116
-
117
- // Mixed calcul
118
- const sum=(...x)=>{
119
- if(x.every(n=>typeof n==="number")){
120
- let s = x[0];
121
- for (let i = 1; i < x.length; i++) s += x[i];
122
- return s;
123
- }
124
- const Y=[];
125
- for(let i=0;i<x.length;i++){
126
- if(x[i] instanceof Array)Y.push(sum(...x[i]));
127
- else if(x[i] instanceof Object){
128
- Y.push(sum(...Object.values(x[i])));
129
- }
130
- }
131
- return Y.length===1?Y[0]:Y;
132
- };
133
- const prod=(...x)=>{
134
- if(x.every(n=>typeof n==="number")){
135
- let p = x[0];
136
- for (let i = 1; i < x.length; i++) p *= x[i];
137
- return p;
138
- }
139
- const Y=[];
140
- for(let i=0;i<x.length;i++){
141
- if(x[i] instanceof Array)Y.push(prod(...x[i]));
142
- else if(x[i] instanceof Object){
143
- Y.push(prod(...Object.values(x[i])));
144
- }
145
- }
146
- return Y.length===1?Y[0]:Y;
147
- };
148
- const min=(...num)=>{
149
- if(num.every(n=>typeof n==="number"))return Math.min(...num);
150
- const Y=[];
151
- for(let i=0;i<num.length;i++){
152
- if(num[i] instanceof Array)Y.push(min(...num[i]));
153
- else if(num[i] instanceof Object){
154
- Y.push(
155
- Object.fromEntries(
156
- [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
157
- )
158
- );
159
- }
160
- }
161
- return Y.length===1?Y[0]:Y;
162
- };
163
- const max=(...num)=>{
164
- if(num.every(n=>typeof n==="number"))return Math.max(...num);
165
- const Y=[];
166
- for(let i=0;i<num.length;i++){
167
- if(num[i] instanceof Array)Y.push(min(...num[i]));
168
- else if(num[i] instanceof Object){
169
- Y.push(
170
- Object.fromEntries(
171
- [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
172
- )
173
- );
174
- }
175
- }
176
- return Y.length===1?Y[0]:Y;
177
- };
178
- const accum=(...num)=>{
179
- if(num.every(n=>typeof n==="number")){
180
- let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
181
- acc.shift();
182
- return acc;
183
- }
184
- const Y=[];
185
- for(let i=0;i<num.length;i++){
186
- if(num[i] instanceof Array)Y.push(accum(...num[i]));
187
- else if(num[i] instanceof Object){
188
- Y.push(null
189
- // Object.fromEntries(
190
- // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
191
- // )
192
- );
193
- }
194
- }
195
- return Y.length===1?Y[0]:Y;
196
- };
197
-
198
- //moy
199
- //med
200
- //variance
201
- //std
202
- //mode
203
- //acccum
204
- //min2max
205
- //max2min
206
- //percentile
207
-
208
- const abs=(...x)=>mapfun$1(Math.abs,...x);
209
- const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
210
- const pow$1=(x,n)=>{
211
- if(typeof x === "number"){
212
- if(typeof n === "number")return Math.pow(x,n);
213
- else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
214
- else return mapfun$1(a=>pow$1(x,a),...n);
215
- }
216
- else if(x.isComplex?.()){
217
- if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
218
- else if(n.isComplex?.())return x.constructor.fromExpo(
219
- x.z**n.a*e(-x.phi*n.b),
220
- ln(x.z)*n.b+n.a*x.phi
221
- )
222
- else return mapfun$1(a=>pow$1(x,a),...n);
223
- }
224
- else if(x instanceof Array){
225
- if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
226
- else if(n instanceof Array){
227
- const Y=[];
228
- for(let i=0;i<x.length;i++){
229
- Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
230
- }
231
- return Y;
232
- }
233
- }
234
- };
235
- const sqrtn=(x,n)=>{
236
- if(typeof x === "number"){
237
- if(typeof n === "number")return Math.pow(x,1/n);
238
- else return mapfun$1(a=>sqrtn(x,a),...n);
239
- }
240
- else if(x.isComplex?.()){
241
- if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
242
- else return mapfun$1(a=>sqrtn(x,a),...n);
243
- }
244
- else if(x instanceof Array){
245
- if(typeof n === "number") return mapfun$1(a=>sqrtn(a,n),...x);
246
- else if(n instanceof Array){
247
- const Y=[];
248
- for(let i=0;i<x.length;i++){
249
- Y.push(mapfun$1(a=>sqrtn(x[i],a),...n));
250
- }
251
- return Y;
252
- }
253
- }
254
- };
255
- const e=(...x) => mapfun$1(Math.exp,...x);
256
- const ln=(...x) => mapfun$1(Math.log,...x);
257
- const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
258
- const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
259
- const tan=(...x) => mapfun$1(Fixed.tan,...x);
260
- const sec=(...x) => mapfun$1(Fixed.sec,...x);
261
- const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
262
- const csc=(...x) => mapfun$1(Fixed.csc,...x);
263
- const cot=(...x) => mapfun$1(Fixed.cot,...x);
264
- const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
265
- const asin=(...x) => mapfun$1(Fixed.asin,...x);
266
- const atan=(...x) => mapfun$1(Fixed.atan,...x);
267
- const acot=(...x) => mapfun$1(Fixed.acot,...x);
268
- const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
269
- const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
270
- const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
271
- const coth=(...x) => mapfun$1(Fixed.coth,...x);
272
- const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
273
- const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
274
- const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
275
- const ceil=(...x) => mapfun$1(Math.ceil,...x);
276
- const floor=(...x) => mapfun$1(Math.floor,...x);
277
- const round=(...x) => mapfun$1(Math.round,...x);
278
- const atan2=(x,y,rad=true)=>{
279
- if(typeof x === "number"){
280
- if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
281
- else return mapfun$1(a=>atan2(x,a,rad),...y);
282
- }
283
- // else if(x.isComplex?.()){
284
- // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
285
- // else return mapfun(a=>pow(x,a),...n);
286
- // }
287
- else if(x instanceof Array){
288
- if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
289
- else if(y instanceof Array){
290
- const Y=[];
291
- for(let i=0;i<x.length;i++){
292
- Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
293
- }
294
- return Y;
295
- }
296
- }
297
- };
298
- const fact=(...x)=>mapfun$1(n=> {
299
- let i,
300
- y = 1;
301
- if (n == 0) y = 1;
302
- else if (n > 0) for (i = 1; i <= n; i++) y *= i;
303
- else y = NaN;
304
- return y;
305
- },...x);
306
- const sign=(...x)=>mapfun$1(Math.sign,...x);
307
-
308
- const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
309
-
310
- const hypot=(...x)=>{
311
- if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
312
- if(x.every(n=>n instanceof Array))return mapfun$1(
313
- Math.hypot,
314
- ...x
315
- )
316
- };
317
-
318
- const _add=(a,b)=>{
319
- if(typeof(a)==="number"){
320
- if (typeof b == "number") return a + b;
321
- else if (b.isComplex?.())return new b.constructor(a + b.a, b.b);
322
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).add(b);
323
- else if (b instanceof Array)return b.map(n=>add(n,a));
324
- }
325
- else if(a.isComplex?.()||a.isMatrix?.()){
326
- if(b instanceof Array)return b.map(n=>a.clone.add(n));
327
- return a.clone.add(b);
328
- }
329
- else if(a instanceof Array){
330
- if(b instanceof Array){
331
- if(a.length === b.length)return a.map((n,i)=>add(n,b[i]))
332
- }
333
- else {
334
- return a.map(n=>add(n,b));
335
- }
336
- }
337
- };
338
- const _sub=(a,b)=>{
339
- if(typeof(a)==="number"){
340
- if (typeof b == "number") return a - b;
341
- else if (b.isComplex?.())return new b.constructor(a - b.a, -b.b);
342
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).sub(b);
343
- else if (b instanceof Array)return b.map(n=>sub(n,a));
344
- }
345
- else if(a.isComplex?.()||a.isMatrix?.()){
346
- if(b instanceof Array)return b.map(n=>a.clone.sub(n));
347
- return a.clone.sub(b);
348
- }
349
- else if(a instanceof Array){
350
- if(b instanceof Array){
351
- if(b instanceof Array){
352
- if(a.length === b.length)return a.map((n,i)=>sub(n,b[i]))
353
- }
354
- }
355
- else {
356
- return a.map(n=>sub(n,b));
357
- }
358
- }
359
- };
360
- const _mul=(a,b)=>{
361
- if(typeof(a)==="number"){
362
- if (typeof b == "number") return a * b;
363
- else if (b.isComplex?.())return new b.constructor(a * b.a,a * b.b);
364
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).mul(b);
365
- else if (b instanceof Array)return b.map(n=>mul(a,n));
366
- }
367
- else if(a.isComplex?.()||a.isMatrix?.()){
368
- if(b instanceof Array)return b.map(n=>a.clone.mul(n));
369
- return a.clone.mul(b);
370
- }
371
- else if(a instanceof Array){
372
- if(b instanceof Array){
373
- if(b instanceof Array){
374
- if(a.length === b.length)return a.map((n,i)=>mul(n,b[i]))
375
- }
376
- }
377
- else {
378
- return a.map(n=>mul(n,b));
379
- }
380
- }
381
- };
382
- const _div=(a,b)=>{
383
- if(typeof(a)==="number"){
384
- if (typeof b == "number") return a / b;
385
- else if (b.isComplex?.())return new b.constructor(a / b.a,a / b.b);
386
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).div(b);
387
- else if (b instanceof Array)return b.map(n=>div(a,n));
388
- }
389
- else if(a.isComplex?.()||a.isMatrix?.()){
390
- if(b instanceof Array)return b.map(n=>a.clone.div(n));
391
- return a.clone.div(b);
392
- }
393
- else if(a instanceof Array){
394
- if(b instanceof Array){
395
- if(b instanceof Array){
396
- if(a.length === b.length)return a.map((n,i)=>div(n,b[i]))
397
- }
398
- }
399
- else {
400
- return a.map(n=>div(n,b));
401
- }
402
- }
403
- };
404
- const _modulo=(a,b)=>{
405
- if(typeof(a)==="number"){
406
- if (typeof b == "number") return a % b;
407
- else if (b.isComplex?.())return new b.constructor(a % b.a,a % b.b);
408
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).modulo(b);
409
- else if (b instanceof Array)return b.map(n=>div(a,n));
410
- }
411
- else if(a.isComplex?.()||a.isMatrix?.()){
412
- if(b instanceof Array)return b.map(n=>a.clone.div(n));
413
- return a.clone.div(b);
414
- }
415
- else if(a instanceof Array){
416
- if(b instanceof Array);
417
- else {
418
- return a.map(n=>add(n,b));
419
- }
420
- }
421
- };
422
- const add=(a,...b)=>{
423
- var res=a;
424
- for(let i=0;i<b.length;i++)res=_add(res,b[i]);
425
- return res;
426
- };
427
- const sub=(a,...b)=>{
428
- var res=a;
429
- for(let i=0;i<b.length;i++)res=_sub(res,b[i]);
430
- return res;
431
- };
432
- const mul=(a,...b)=>{
433
- var res=a;
434
- for(let i=0;i<b.length;i++)res=_mul(res,b[i]);
435
- return res;
436
- };
437
- const div=(a,...b)=>{
438
- var res=a;
439
- for(let i=0;i<b.length;i++)res=_div(res,b[i]);
440
- return res;
441
- };
442
- const modulo=(a,...b)=>{
443
- var res=a;
444
- for(let i=0;i<b.length;i++)res=_modulo(res,b[i]);
445
- return res;
446
- };
447
-
448
- const zeros=(n)=>new Array(n).fill(0);
449
- const ones=(n)=>new Array(n).fill(1);
450
- const nums=(num,n)=>new Array(n).fill(num);
451
- const norm=(value, min, max)=>{
452
- if (typeof value === "number") return min !== max ? (value - min) / (max - min) : 0;
453
- else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, norm(value.arr.flat(1), min, max));
454
- else if (value.isComplex?.()) return new value.constructor(norm(value.a, min, max), norm(value.b, min, max));
455
- else if (value instanceof Array) {
456
- if (value.every((n) => typeof (n === "number"))) {
457
- return value.map((n) => norm(n, min, max));
458
- } else {
459
- let y = new Array(value.length);
460
- for (let i = 0; i < value.length; i++) {
461
- y[i] = norm(value[i]);
462
- }
463
- }
464
- }
465
- };
466
- const lerp=(value, min, max)=>{
467
- if (typeof value === "number") return (max - min) * value + min;
468
- else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, lerp(value.arr.flat(1), min, max));
469
- else if (value.isComplex?.()) return new value.constructor(lerp(value.a, min, max), lerp(value.b, min, max));
470
- else if (value instanceof Array) {
471
- if (value.every((n) => typeof (n === "number"))) {
472
- return value.map((n) => lerp(n, min, max));
473
- } else {
474
- let y = new Array(value.length);
475
- for (let i = 0; i < value.length; i++) {
476
- y[i] = lerp(value[i]);
477
- }
478
- }
479
- }
480
- };
481
- const map$1=(x, a, b, c, d)=>{
482
- if (typeof x === "number") return lerp(norm(x, a, b), c, d);
483
- else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, map$1(x.arr.flat(1), a, b, c, d));
484
- else if (x.isComplex?.()) return new x.constructor(map$1(x.a, b, c, d), map$1(x.b, a, b, c, d));
485
- else if (x instanceof Array) {
486
- if (x.every((n) => typeof (n === "number"))) {
487
- return x.map((n) => map$1(n, a, b, c, d));
488
- } else {
489
- let y = new Array(x.length);
490
- for (let i = 0; i < x.length; i++) {
491
- y[i] = map$1(x[i], a, b, c, d);
492
- }
493
- }
494
- }
495
- };
496
- const clamp=(x, a , b)=>{
497
- const [min_value,max_value]=[min(a,b),max(a,b)];
498
- if (typeof x === "number") return min(max(x, min_value), max_value);
499
- else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, clamp(x.arr.flat(1), min_value, max_value));
500
- else if (x.isComplex?.()) return new x.constructor(clamp(x.a, min_value, max_value), clamp(x.b, min_value, max_value));
501
- else if (x instanceof Array) {
502
- if (x.every((n) => typeof (n === "number"))) {
503
- return x.map((n) => clamp(n, min_value, max_value));
504
- } else {
505
- let y = new Array(x.length);
506
- for (let i = 0; i < x.length; i++) {
507
- y[i] = clamp(x[i], min_value, max_value);
508
- }
509
- }
510
- }
511
- };
512
- const arange=(a, b, step , include = false)=>{
513
- let tab = [];
514
- if(a<b){
515
- for (let i = a; include?i<=b:i<b; i += step) tab.push((i * 10) / 10);
516
- }
517
- else {
518
- for(let i = a; include?i>=b:i>b; i -= step) tab.push((i * 10) / 10);
519
- }
520
- return tab;
521
- };
522
- const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
523
- if(Math.floor(n)!==n)return;
524
- if([a,b].every(n=>typeof n==="number")){
525
- const [max,min]=[a,b].sort((a,b)=>b-a);
526
- var Y = [];
527
- let step ;
528
- endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
529
- for (var i = 0; i < n; i++) {
530
- a<b?Y.push(min+step*i):Y.push(max-step*i);
531
- }
532
- return Y
533
- }
534
-
535
- if([a,b].some(n=>n.isComplex?.())){
536
- const z1 = new n.constructor(a);
537
- const z2 = new n.constructor(b);
538
- n=n||Math.abs(z1.a-z2.a)+1;
539
- const X=linspace(z1.a,z2.a,n,endpoint);
540
- const Y=linspace(z1.b,z2.b,n,endpoint);
541
- let Z=new Array(n).fill(null);
542
- Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
543
- return Z;
544
- }
545
- };
546
- const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
547
- return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
548
- };
549
- const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
550
- if(Math.floor(n)!==n)return;
551
- if([a,b].every(n=>typeof n==="number")){
552
- const [max,min]=[a,b].sort((a,b)=>b-a);
553
- let base;
554
- endpoint ? base = sqrtn(max/min,n-1) : base = sqrtn(max/min,n) ;
555
- const Y = [min];
556
- for (let i = 1; i < n; i++) {
557
- Y.push(Y[i-1]*base);
558
- }
559
- return a<b?Y:Y.reverse()
560
- }
561
-
562
- if([a,b].some(n=>n.isComplex?.())){
563
- const z1 = new n.constructor(a);
564
- const z2 = new n.constructor(b);
565
- n=n||Math.abs(z1.a-z2.a)+1;
566
- let base;
567
- endpoint ? base = sqrtn(z2.div(z1),n-1) : base = sqrtn(z2.div(z1),n) ;
568
- const Y = [z1];
569
- for (let i = 1; i < n; i++) {
570
- Y.push(mul(Y[i-1],base));
571
- }
572
- return Y;
573
- }
574
- };
575
-
576
- /** @module Math */
577
- /**
578
- * Converts degrees to radians.
579
- * @param {...number} deg - Degrees to convert.
580
- * @returns {number|number[]} Returns an array of radians corresponding to the input degrees.
581
- */
582
- const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
583
-
584
- /**
585
- * Converts radians to degrees.
586
- * @param {...number} rad - Radians to convert.
587
- * @returns {number|number[]} Returns an array of degrees corresponding to the input radians.
588
- */
589
- const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
590
-
591
- /** @module Math */
592
- /**
593
- * Checks if a value is within the specified range.
594
- * @function
595
- * @param {number} x - The value to check.
596
- * @param {number} a - The start of the range.
597
- * @param {number} b - The end of the range.
598
- * @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
599
- */
600
- const inRange = (x, a, b) => {
601
- const [min, max] = [Math.min(a, b), Math.max(a, b)];
602
- return x >= min && x <= max;
603
- };
604
-
605
- /**
606
- * Checks if two numbers are approximately equal within a given error margin.
607
- * @param {number} a - The first number.
608
- * @param {number} b - The second number.
609
- * @param {number} [Err=0.0001] - The maximum acceptable difference between the two numbers.
610
- * @returns {boolean} Returns true if the two numbers are approximately equal within the specified error margin, otherwise false.
611
- */
612
- const isApproximatlyEqual = (a, b, Err = 0.0001) => {
613
- return Math.abs(a - b) <= Err;
614
- };
615
-
616
- /** @module Math */
617
-
618
- /**
619
- * Computes the cartesian product of two arrays.
620
- * @param {Array} a - The first array.
621
- * @param {Array} b - The second array.
622
- * @returns {Array} Returns an array representing the cartesian product of the input arrays.
623
- */
624
- const cartesianProduct = (a, b) => a.reduce((p, x) => [...p, ...b.map((y) => [x, y])], []);
625
-
626
- /**
627
- * Computes the greatest common divisor (GCD) of two numbers.
628
- * @param {number} n1 - The first number.
629
- * @param {number} n2 - The second number.
630
- * @returns {number} Returns the greatest common divisor of the two input numbers.
631
- */
632
- const pgcd = (n1, n2) => {
633
- let i,
634
- pgcd = 1;
635
- if (n1 == floor(n1) && n2 == floor(n2)) {
636
- for (i = 2; i <= n1 && i <= n2; ++i) {
637
- if (n1 % i == 0 && n2 % i == 0) pgcd = i;
638
- }
639
- return pgcd;
640
- } else console.log("error");
641
- };
642
-
643
- /**
644
- * Computes the least common multiple (LCM) of two numbers.
645
- * @param {number} n1 - The first number.
646
- * @param {number} n2 - The second number.
647
- * @returns {number} Returns the least common multiple of the two input numbers.
648
- */
649
- const ppcm = (n1, n2) => {
650
- let ppcm;
651
- if (n1 == floor(n1) && n2 == floor(n2)) {
652
- ppcm = n1 > n2 ? n1 : n2;
653
- while (true) {
654
- if (ppcm % n1 == 0 && ppcm % n2 == 0) break;
655
- ++ppcm;
656
- }
657
- return ppcm;
658
- } else console.log("error");
659
- };
14
+ const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
660
15
 
661
- const Utils={
662
- add,
663
- sub,
664
- mul,
665
- div,
666
- modulo,
667
-
668
- zeros,
669
- ones,
670
- nums,
671
- norm,
672
- lerp,
673
- map: map$1,
674
- clamp,
675
- arange,
676
- linspace,
677
- logspace,
678
- geomspace,
679
-
680
- sum,
681
- prod,
682
- accum,
683
-
684
- cartesianProduct,
685
- ppcm,
686
- pgcd,
687
-
688
- deg2rad,
689
- rad2deg,
16
+ const mapfun=(fun,...X)=>{
17
+ const Y=X.map(x=>{
18
+ if(is_primitive(x) || x?.__mapfun__) return fun(x)
19
+ if(x instanceof Array) return x.map(n=>mapfun(fun,n));
20
+ if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
21
+ if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
22
+ if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
23
+ if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
24
+ else if(x instanceof Object){
25
+ return Object.fromEntries(
26
+ Object.entries(x).map(
27
+ n=>n=[n[0],mapfun(fun,n[1])]
28
+ )
29
+ )
30
+ }
31
+ });
32
+ return Y.length==1? Y[0]: Y;
33
+ };
690
34
 
691
- inRange,
692
- isApproximatlyEqual
35
+ const apply_fun = (x, fn) => {
36
+ if (x.isComplex?.()) return new x.constructor(
37
+ fn(x.a),
38
+ fn(x.b)
39
+ )
40
+ if (x.isMatrix?.()) return new x.constructor(
41
+ x.rows,
42
+ x.cols,
43
+ x.arr.flat(1).map(fn)
44
+ )
45
+ if (x instanceof Array) mapfun(fn, ...x);
46
+ return fn(x)
693
47
  };
694
48
 
49
+ // import {sum,prod,deg2rad} from "../utils/index.js";
50
+ // Should avoid CD
695
51
  class Complex{
696
52
  constructor(a = 0, b = 0) {
697
53
  if(a instanceof Complex){
@@ -700,33 +56,33 @@ class Complex{
700
56
  }
701
57
  else if(typeof(a)==="object"){
702
58
  if(("a" in a && "b" in a)){
703
- this.a=a.a;
704
- this.b=a.b;
59
+ this.a = a.a;
60
+ this.b = a.b;
705
61
  }
706
62
  else if(("a" in a && "z" in a)){
707
- this.a=a.a;
708
- this.b=sqrt$2((a.z**2)-(a.a**2));
63
+ this.a = a.a;
64
+ this.b = Math.sqrt((a.z**2)-(a.a**2));
709
65
  }
710
66
  else if(("a" in a && "phi" in a)){
711
- this.a=a.a;
712
- this.b=a.a*tan(a.phi);
67
+ this.a = a.a;
68
+ this.b = a.a * Math.tan(a.phi);
713
69
  }
714
70
  else if(("b" in a && "z" in a)){
715
- this.b=a.b;
716
- this.a=sqrt$2((a.z**2)-(a.b**2));
71
+ this.b = a.b;
72
+ this.a = Math.sqrt((a.z**2)-(a.b**2));
717
73
  }
718
74
  else if(("b" in a && "phi" in a)){
719
- this.b=b;
720
- this.a=a.b/tan(a.phi);
75
+ this.b = b;
76
+ this.a = a.b / Math.tan(a.phi);
721
77
  }
722
78
  else if(("z" in a && "phi" in a)){
723
- this.a = +a.z*cos$2(a.phi).toFixed(15);
724
- this.b = +a.z*sin$2(a.phi).toFixed(15);
79
+ this.a = + a.z * Math.cos(a.phi).toFixed(15);
80
+ this.b = + a.z * Math.sin(a.phi).toFixed(15);
725
81
  }
726
82
  }
727
- else if(typeof(a)==="number"&&typeof(b)==="number"){
728
- this.a = +a.toFixed(32);
729
- this.b = +b.toFixed(32);
83
+ else if(typeof(a)==="number" && typeof(b)==="number"){
84
+ this.a = + a.toFixed(32);
85
+ this.b = + b.toFixed(32);
730
86
  }
731
87
  }
732
88
  get __mapfun__(){
@@ -747,15 +103,24 @@ class Complex{
747
103
  : (str = `-${Math.abs(this.b)}*i`);
748
104
  return str;
749
105
  }
750
-
751
- get clone() {
106
+ toFixed(n){
107
+ this.a = + this.a.toFixed(n);
108
+ this.b = + this.b.toFixed(n);
109
+ return this;
110
+ }
111
+ toPrecision(n){
112
+ this.a = + this.a.toPrecision(n);
113
+ this.b = + this.b.toPrecision(n);
114
+ return this;
115
+ }
116
+ clone() {
752
117
  return new Complex(this.a, this.b);
753
118
  }
754
119
  get z(){
755
- return hypot(this.a,this.b);
120
+ return Math.hypot(this.a,this.b);
756
121
  }
757
122
  get phi(){
758
- return atan2(this.b , this.a);
123
+ return Math.atan2(this.b , this.a);
759
124
  }
760
125
  static Zero() {
761
126
  return new Complex(0, 0);
@@ -764,102 +129,120 @@ class Complex{
764
129
  return new Complex(this.a, -this.b);
765
130
  }
766
131
  get inv() {
767
- return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
132
+ return new Complex(
133
+ this.a / Math.hypot(this.a, this.b),
134
+ -this.b / Math.hypot(this.a, this.b)
135
+ );
768
136
  }
769
- add(...z) {
770
- for (let i = 0; i < z.length; i++) {
771
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
137
+ add(...c) {
138
+ for (let i = 0; i < c.length; i++) {
139
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
140
+ this.a += c[i].a;
141
+ this.b += c[i].b;
772
142
  }
773
- let re = z.map((n) => n.a);
774
- let im = z.map((n) => n.b);
775
- this.a+=+sum(...re).toFixed(15);
776
- this.b+=+sum(...im).toFixed(15);
777
143
  return this;
778
144
  }
779
- sub(...z) {
780
- for (let i = 0; i < z.length; i++) {
781
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
145
+ sub(...c) {
146
+ for (let i = 0; i < c.length; i++) {
147
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
148
+ this.a -= c[i].a;
149
+ this.b -= c[i].b;
782
150
  }
783
- let re = z.map((n) => n.a);
784
- let im = z.map((n) => n.b);
785
- this.a-=+sum(...re).toFixed(15);
786
- this.b-=+sum(...im).toFixed(15);
787
151
  return this;
788
152
  }
789
- mul(...z){
790
- for (let i = 0; i < z.length; i++) {
791
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
153
+ mul(...c){
154
+ let {z, phi} = this;
155
+ for (let i = 0; i < c.length; i++) {
156
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
157
+ z *= c[i].z;
158
+ phi += c[i].phi;
792
159
  }
793
- let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
794
- let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
795
- this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
796
- this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
160
+ this.a = z * Math.cos(phi);
161
+ this.b = z * Math.sin(phi);
797
162
  return this;
798
163
  }
799
- div(...z) {
800
- for (let i = 0; i < z.length; i++) {
801
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
164
+ div(...c){
165
+ let {z, phi} = this;
166
+ for (let i = 0; i < c.length; i++) {
167
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
168
+ z /= c[i].z;
169
+ phi -= c[i].phi;
802
170
  }
803
- let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
804
- let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
805
- this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
806
- this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
171
+ this.a = z*Math.cos(phi);
172
+ this.b = z*Math.sin(phi);
807
173
  return this;
808
174
  }
809
- pow(n) {
810
- if (floor(n) === n && n > 0) {
811
- let z=+(this.z**n).toFixed(15);
812
- let phi=+(this.phi*n).toFixed(15);
813
- this.a=+(z*cos$2(phi).toFixed(15)).toFixed(15);
814
- this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
175
+ modulo(...c) {
176
+ for (let i = 0; i < c.length; i++) {
177
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
178
+ this.a %= c[i].a;
179
+ this.b %= c[i].b;
180
+ }
181
+ return this;
182
+ }
183
+ pow(...c){
184
+ let {z, phi} = this;
185
+ for (let i = 0; i < c.length; i++) {
186
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
187
+ z *= Math.exp(c[i].a * Math.log(z) - c[i].b * phi);
188
+ phi += c[i].b * Math.log(z) + c[i].a * phi;
815
189
  }
190
+ this.a = z * Math.cos(phi);
191
+ this.b = z * Math.sin(phi);
816
192
  return this;
817
193
  }
818
194
  static fromExpo(z, phi) {
819
195
  return new Complex(
820
- +(z * cos$2(phi)).toFixed(13),
821
- +(z * sin$2(phi)).toFixed(13)
196
+ +(z * cos(phi)).toFixed(13),
197
+ +(z * sin(phi)).toFixed(13)
822
198
  );
823
199
  }
824
200
  get expo() {
825
201
  return [this.z, this.phi];
826
202
  }
827
203
  static add(c,...z) {
828
- return c.clone.add(...z);
204
+ return c.clone().add(...z);
829
205
  }
830
206
  static sub(c,...z) {
831
- return c.clone.sub(...z);
207
+ return c.clone().sub(...z);
832
208
  }
833
209
  static mul(c,...z) {
834
- return c.clone.mul(...z);
210
+ return c.clone().mul(...z);
835
211
  }
836
212
  static div(c,...z) {
837
- return c.clone.div(...z);
838
- }
839
- static pow(z,n){
840
- return z.clone.pow(n);
841
- }
842
- static xpowZ(x){
843
- return complex((x**this.a)*cos$2(this.b*ln(x)),(x**this.a)*sin$2(this.b*ln(x)));
213
+ return c.clone().div(...z);
844
214
  }
845
- sqrtn(n=2){
846
- return complex(sqrtn(this.z,n)*cos$2(this.phi/n),sqrtn(this.z,n)*sin$2(this.phi/n));
215
+
216
+ nthr(n=2){
217
+ return complex({z: this.z ** (1/n), phi: this.phi / n});
847
218
  }
848
219
  get sqrt(){
849
- return this.sqrtn(2);
220
+ return this.nrth(2);
221
+ }
222
+ get cbrt(){
223
+ return this.nrth(3);
850
224
  }
851
225
  get log(){
852
- return complex(this.z,this.phi);
226
+ return complex(this.z, this.phi);
853
227
  }
854
228
  get cos(){
855
- return complex(cos$2(this.a)*cosh$1(this.b),sin$2(this.a)*sinh$1(this.b))
229
+ return complex(
230
+ Math.cos(this.a) * Math.cosh(this.b),
231
+ Math.sin(this.a) * Math.sinh(this.b)
232
+ )
856
233
  }
857
234
  get sin(){
858
- return complex(sin$2(this.a)*cosh$1(this.b),cos$2(this.a)*sinh$1(this.b))
235
+ return complex(
236
+ Math.sin(this.a) * Math.cosh(this.b),
237
+ Math.cos(this.a) * Math.sinh(this.b)
238
+ )
859
239
  }
860
240
  get tan(){
861
- const de=cos$2(this.a*2)+cosh$1(this.b*2);
862
- return complex(sin$2(2*this.a)/de,sinh$1(2*this.b)/de);
241
+ const D=cos(this.a*2)+cosh(this.b*2);
242
+ return complex(
243
+ Math.sin(2 * this.a) / D,
244
+ Math.sinh(2 * this.b) / D
245
+ );
863
246
  }
864
247
  }
865
248
  const complex=(a,b)=>{
@@ -872,6 +255,599 @@ const complex=(a,b)=>{
872
255
  return new Complex(a,b)
873
256
  };
874
257
 
258
+ const abs = (...x) => mapfun(
259
+ x =>{
260
+ if(x.isComplex?.()) return x.z;
261
+ return Math.abs(x)
262
+ },
263
+ ...x
264
+ );
265
+
266
+ const pow$1 = (...x) => {
267
+ const n = x.pop();
268
+ return mapfun(
269
+ x => {
270
+ if(x.isComplex?.()) {
271
+ if(n.isComplex?.()) return new x.constructor({
272
+ z: Math.exp(n.a * Math.log(x.z) - n.b * x.phi),
273
+ phi: n.b * Math.log(x.z) + n.a * x.phi
274
+ })
275
+ return new x.constructor({z: x.z ** n, phi: x.phi * n});
276
+ }
277
+ if(n.isComplex?.()) return new x.constructor({
278
+ z: Math.exp(n.a * Math.log(x)),
279
+ phi: n.b * Math.log(x)
280
+ })
281
+ return Math.pow(x, n)
282
+ },
283
+ ...x
284
+ )
285
+ };
286
+
287
+ const sqrt$2 = (...x) => mapfun(
288
+ x=>{
289
+ if(x.isComplex?.())
290
+ return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
291
+ if(x < 0) return complex(0, Math.sqrt(-x))
292
+ return Math.sqrt(x);
293
+ },
294
+ ...x
295
+ );
296
+
297
+ const cbrt = (...x) => mapfun(
298
+ x=>{
299
+ if(x.isComplex?.())
300
+ return new x.constructor({z: x.z**(1/3), phi: x.phi/3})
301
+ return Math.cbrt(x);
302
+ },
303
+ ...x
304
+ );
305
+
306
+ const nthr = (...x) => {
307
+ const n = x.pop();
308
+ if(typeof n !== 'number') throw Error('nthr expects a real number n');
309
+ return mapfun(
310
+ x => {
311
+ if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
312
+ if(x<0) return n%2===2 ? complex(0, (-x)**(1/n)) : -1 * (-x)**(1/n)
313
+ return x**(1/n)
314
+ },
315
+ ...x
316
+ )
317
+ };
318
+
319
+ const croot = (...x) =>{
320
+ const c = x.pop();
321
+ if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
322
+ return mapfun(
323
+ x => {
324
+ if(typeof x === 'number') x = new c.constructor(x, 0);
325
+ const {a : c_a, b : c_b} = c;
326
+ const {z, phi} = x;
327
+ const D = Math.hypot(c_a, c_b);
328
+ const A = Math.exp((Math.log(z)*c_a + phi*c_b)/D);
329
+ const B = (phi*c_a - Math.log(z)*c_b)/D;
330
+ return new c.constructor(
331
+ A * Math.cos(B),
332
+ A * Math.sin(B)
333
+ )
334
+ },
335
+ ...x
336
+ )
337
+ };
338
+
339
+ const exp$1 = (...x) => mapfun(
340
+ x => {
341
+ if(x.isComplex?.()) return new x.constructor(
342
+ Math.exp(x.a) * Math.cos(x.b),
343
+ Math.exp(x.a) * Math.sin(x.b)
344
+ );
345
+ return Math.exp(x)
346
+ }
347
+ ,...x
348
+ );
349
+
350
+ const ln = (...x) => mapfun(
351
+ x => {
352
+ if(x.isComplex?.()) return new x.constructor(
353
+ Math.log(x.z),
354
+ x.phi
355
+ );
356
+ return Math.log(x)
357
+ }
358
+ ,...x
359
+ );
360
+
361
+ const sign = (...x) => mapfun(
362
+ x => {
363
+ if(x.isComplex?.()){
364
+ const {z, phi} = x;
365
+ if(z===0) return new x.constructor(0, 0);
366
+ return new x.constructor({z:1, phi})
367
+ }
368
+ return Math.sign(x)
369
+ }
370
+ ,...x
371
+ );
372
+
373
+ const floor = (...x) => mapfun(
374
+ x => {
375
+ if(x.isComplex?.()) return new x.constructor(
376
+ Math.floor(x.a),
377
+ Math.floor(x.b)
378
+ )
379
+ return Math.floor(x)
380
+ },
381
+ ...x
382
+ );
383
+ const ceil = (...x) => mapfun(
384
+ x => {
385
+ if(x.isComplex?.()) return new x.constructor(
386
+ Math.ceil(x.a),
387
+ Math.ceil(x.b)
388
+ )
389
+ return Math.ceil(x)
390
+ },
391
+ ...x
392
+ );
393
+ const round = (...x) => mapfun(
394
+ x => {
395
+ if(x.isComplex?.()) return new x.constructor(
396
+ Math.round(x.a),
397
+ Math.round(x.b)
398
+ )
399
+ return Math.round(x)
400
+ },
401
+ ...x
402
+ );
403
+
404
+ const trunc = (...x) => mapfun(
405
+ x => {
406
+ if(x.isComplex?.()) return new x.constructor(
407
+ Math.trunc(x.a),
408
+ Math.trunc(x.b)
409
+ )
410
+ return Math.trunc(x)
411
+ },
412
+ ...x
413
+ );
414
+
415
+ const fract = (...x) => mapfun(
416
+ x => {
417
+ if(x.isComplex?.()) return new x.constructor(
418
+ x.a - Math.trunc(x.a),
419
+ x.b - Math.trunc(x.b)
420
+ )
421
+ return x - Math.trunc(x)
422
+ },
423
+ ...x
424
+ );
425
+
426
+ const cos$3 = (...x) => mapfun(
427
+ x => {
428
+ if(x.isComplex?.()) return new x.constructor(
429
+ Math.cos(x.a) * Math.cosh(x.b),
430
+ -Math.sin(x.a) * Math.sinh(x.b)
431
+ );
432
+ return Math.cos(x)
433
+ }
434
+ ,...x
435
+ );
436
+
437
+ const sin$3 = (...x) => mapfun(
438
+ x =>{
439
+ if(x?.isComplex) return new x.constructor(
440
+ Math.sin(x.a) * Math.cosh(x.b),
441
+ Math.cos(x.a) * Math.sinh(x.b)
442
+ );
443
+ return Math.sin(x)
444
+ }
445
+ , ...x
446
+ );
447
+
448
+ const tan = (...x) => mapfun(
449
+ x =>{
450
+ if(x?.isComplex){
451
+ const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
452
+ return new x.constructor(
453
+ Math.sin(2*x.a) / D,
454
+ Math.sinh(2*x.b) / D
455
+ );
456
+ }
457
+ return Math.tan(x)
458
+ },
459
+ ...x
460
+ );
461
+
462
+ const sec = (...x) => mapfun(
463
+ x => {
464
+ if(x.isComplex?.()) ;
465
+ return 1 / Math.cos(x)
466
+ }
467
+ ,...x
468
+ );
469
+
470
+ const acos$1 = (...x) => mapfun(
471
+ x =>{
472
+ if(x?.isComplex){
473
+ const { a, b } = x;
474
+ const Rp = Math.hypot(a + 1, b);
475
+ const Rm = Math.hypot(a - 1, b);
476
+ globalThis.Rp = Rp;
477
+ globalThis.Rm = Rm;
478
+ return new x.constructor(
479
+ Math.acos((Rp - Rm) / 2),
480
+ -Math.acosh((Rp + Rm) / 2),
481
+ )
482
+ }
483
+ return Math.acos(x)
484
+ },
485
+ ...x
486
+ );
487
+
488
+ const asin = (...x) => mapfun(
489
+ x => {
490
+ if(x?.isComplex){
491
+ const { a, b } = x;
492
+ const Rp = Math.hypot(a + 1, b);
493
+ const Rm = Math.hypot(a - 1, b);
494
+ return new x.constructor(
495
+ Math.asin((Rp - Rm) / 2),
496
+ Math.acosh((Rp + Rm) / 2)
497
+ );
498
+ }
499
+ return Math.asin(x);
500
+ },
501
+ ...x
502
+ );
503
+
504
+ const atan = (...x) => mapfun(
505
+ x => {
506
+ if(x?.isComplex){
507
+ const { a, b } = x;
508
+ return new x.constructor(
509
+ Math.atan((a*2/(1-a**2-b**2)))/2,
510
+ Math.log((a**2 + (1+b)**2)/(a**2 + (1-b)**2))/4
511
+ )
512
+ }
513
+ return Math.atan(x);
514
+ },
515
+ ...x
516
+ );
517
+
518
+ const acot = (...x) => mapfun(
519
+ x => {
520
+ if(x?.isComplex){
521
+ const { a, b } = x;
522
+ return new x.constructor(
523
+ Math.atan(2*a/(a**2+(b-1)*(b+1)))/2,
524
+ Math.log((a**2 + (b-1)**2)/(a**2 + (b+1)**2))/4
525
+ )
526
+ }
527
+ return Math.PI/2 - Math.atan(x);
528
+ },
529
+ ...x
530
+ );
531
+
532
+
533
+ const cosh$2 = (...x) => mapfun(
534
+ x =>{
535
+ if(x?.isComplex) return new x.constructor(
536
+ Math.cosh(x.a) * Math.cos(x.b),
537
+ Math.sinh(x.a) * Math.sin(x.b)
538
+ );
539
+ return Math.cosh(x)
540
+ },
541
+ ...x
542
+ );
543
+ const sinh$1 = (...x) => mapfun(
544
+ x =>{
545
+ if(x?.isComplex) return new x.constructor(
546
+ Math.sinh(x.a) * Math.cos(x.b),
547
+ Math.cosh(x.a) * Math.sin(x.b)
548
+ );
549
+ return Math.sinh(x)
550
+ },
551
+ ...x
552
+ );
553
+ const tanh = (...x) => mapfun(
554
+ x =>{
555
+ if(x?.isComplex){
556
+ const D = Math.cosh(2*a) + Math.cos(2*b);
557
+ return new x.constructor(
558
+ Math.sinh(2*a) / D,
559
+ Math.sin(2*b) / D
560
+ )
561
+ }
562
+ return Math.tanh(x)
563
+ },
564
+ ...x
565
+ );
566
+
567
+ const coth = (...x) => mapfun(
568
+ x =>{
569
+ if(x?.isComplex){
570
+ const {a, b} = x;
571
+ const D = (Math.sinh(a)**2)*(Math.cos(b)**2) + (Math.cosh(a)**2)*(Math.sin(b)**2);
572
+ return new x.constructor(
573
+ Math.cosh(a) * Math.sinh(a) / D,
574
+ - Math.sin(b) * Math.cos(b) / D
575
+ )
576
+ }
577
+ return 1/Math.tanh(x)
578
+ },
579
+ ...x
580
+ );
581
+
582
+ const acosh = (...x) => mapfun(
583
+ x =>{
584
+ if(x?.isComplex){
585
+ return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).sub(1))))
586
+ }
587
+ return Math.acosh(x)
588
+ },
589
+ ...x
590
+ );
591
+
592
+ const asinh = (...x) => mapfun(
593
+ x =>{
594
+ if(x?.isComplex){
595
+ return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).add(1))))
596
+ }
597
+ return Math.asinh(x)
598
+ },
599
+ ...x
600
+ );
601
+
602
+ const atanh = (...x) => mapfun(
603
+ x =>{
604
+ if(x?.isComplex);
605
+ return Math.atanh(x)
606
+ },
607
+ ...x
608
+ );
609
+
610
+ const sig = (...x) => mapfun(
611
+ x =>{
612
+ if(x?.isComplex);
613
+ return 1/(1+Math.exp(-x))
614
+ },
615
+ ...x
616
+ );
617
+
618
+ const _add = (x, y) =>{
619
+ if(typeof x === 'number'){
620
+ if(typeof y === 'number') return x + y;
621
+ if(y.isComplex?.()) {
622
+ return y.clone().add(x);
623
+ }
624
+ }
625
+ if(x.isComplex?.()){
626
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().add(y);
627
+ }
628
+ };
629
+
630
+ const _sub = (x, y) =>{
631
+ if(typeof x === 'number'){
632
+ if(typeof y === 'number') return x - y;
633
+ if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
634
+ }
635
+ if(x.isComplex?.()){
636
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().sub(y);
637
+ }
638
+ };
639
+
640
+ const _mul = (x, y) =>{
641
+ if(typeof x === 'number'){
642
+ if(typeof y === 'number') return x * y;
643
+ if(y.isComplex?.()) return y.clone().mul(x);
644
+ }
645
+ if(x.isComplex?.()){
646
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
647
+ }
648
+ };
649
+
650
+ const _div = (x, y) =>{
651
+ if(typeof x === 'number'){
652
+ if(typeof y === 'number') return x / y;
653
+ if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
654
+ }
655
+ if(x.isComplex?.()){
656
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
657
+ }
658
+ };
659
+
660
+ const _modulo = (x, y) =>{
661
+ if(typeof x === 'number'){
662
+ if(typeof y === 'number') return x % y;
663
+ if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
664
+ }
665
+ if(x.isComplex?.()){
666
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().modulo(y);
667
+ }
668
+ };
669
+
670
+ const add=(a,...b)=>{
671
+ let res = a;
672
+ for(let i=0; i<b.length; i++)
673
+ res = _add(res, b[i]);
674
+ return res;
675
+ };
676
+ const sub=(a,...b)=>{
677
+ let res = a;
678
+ for(let i=0; i<b.length; i++)
679
+ res = _sub(res, b[i]);
680
+ return res;
681
+ };
682
+ const mul=(a,...b)=>{
683
+ let res = a;
684
+ for(let i=0; i<b.length; i++)
685
+ res = _mul(res, b[i]);
686
+ return res;
687
+ };
688
+ const div=(a,...b)=>{
689
+ let res = a;
690
+ for(let i=0; i<b.length; i++)
691
+ res = _div(res, b[i]);
692
+ return res;
693
+ };
694
+ const modulo=(a,...b)=>{
695
+ let res = a;
696
+ for(let i=0; i<b.length; i++)
697
+ res = _modulo(res, b[i]);
698
+ return res;
699
+ };
700
+
701
+ const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
702
+ const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
703
+
704
+ const norm = (x, min, max) => apply_fun(
705
+ x,
706
+ v => min !== max ? (v - min) / (max - min) : 0
707
+ );
708
+ const lerp = (x, min, max) => apply_fun(
709
+ x,
710
+ v => (max - min) * v + min
711
+ );
712
+ const clamp = (x, min, max) => apply_fun(
713
+ x,
714
+ v => Math.min(Math.max(v, min), max)
715
+ );
716
+ const map$1 = (x, a, b, c, d) => apply_fun(
717
+ x,
718
+ v => lerp(norm(v, a, b), c, d)
719
+ );
720
+
721
+
722
+ // export const norm = (x, min, max) => {
723
+ // if(x.isComplex?.()) return new x.constructor(
724
+ // norm(x.a, min, max),
725
+ // norm(x.b, min, max)
726
+ // )
727
+ // if(x.isMatrix?.()) return new x.constructor(
728
+ // x.rows,
729
+ // x.cols,
730
+ // norm(x.arr.flat(1), min, max)
731
+ // );
732
+ // if(x instanceof Array) return mapfun(n => norm(n, min, max), ...x);
733
+ // return min !== max ? (x - min) / (max - min) : 0;
734
+ // }
735
+
736
+
737
+ // export const lerp = (x, min, max) => {
738
+ // if(x.isComplex?.()) return new x.constructor(
739
+ // lerp(x.a, min, max),
740
+ // lerp(x.b, min, max)
741
+ // )
742
+ // if(x.isMatrix?.()) return new x.constructor(
743
+ // x.rows,
744
+ // x.cols,
745
+ // lerp(x.arr.flat(1), min, max)
746
+ // );
747
+ // if(x instanceof Array) return mapfun(n => lerp(n, min, max), ...x);
748
+ // return (max - min) * x + min;
749
+ // }
750
+
751
+ // export const map = (x, a, b, c, d) => {
752
+ // if(x.isComplex?.()) return new x.constructor(
753
+ // map(x.a, a, b, c, d),
754
+ // map(x.b, a, b, c, d)
755
+ // )
756
+ // if(x.isMatrix?.()) return new x.constructor(
757
+ // x.rows,
758
+ // x.cols,
759
+ // map(x.arr.flat(1), a, b, c, d)
760
+ // );
761
+ // if(x instanceof Array) return mapfun(n => map(n, a, b, c, d), ...x);
762
+ // return lerp(norm(x, a, b), c, d);
763
+ // }
764
+
765
+ // export const clamp = (x, min, max) => {
766
+ // if(x.isComplex?.()) return new x.constructor(
767
+ // clamp(x.a, min, max),
768
+ // clamp(x.b, min, max)
769
+ // )
770
+ // if(x.isMatrix?.()) return new x.constructor(
771
+ // x.rows,
772
+ // x.cols,
773
+ // clamp(x.arr.flat(1), min, max)
774
+ // );
775
+ // if(x instanceof Array) return mapfun(n => clamp(n, min, max), ...x);
776
+ // return Math.min(Math.max(x, min), max)
777
+ // }
778
+
779
+ const hypot = (...x) => {
780
+ const c0 = x.find(a => a.isComplex?.());
781
+ if (c0) {
782
+ const W = x.map(n => n.isComplex?.() ? n : new c0.constructor(n, 0));
783
+ return Math.hypot(...W.map(c => c.z));
784
+ }
785
+ return Math.hypot(...x);
786
+ };
787
+
788
+
789
+ const atan2 = (y, x, rad = true) => {
790
+ if (y instanceof Array && !(x instanceof Array))
791
+ return mapfun(n => atan2(n, x, rad), ...y);
792
+
793
+ if (x instanceof Array && !(y instanceof Array))
794
+ return mapfun(n => atan2(y, n, rad), ...x);
795
+
796
+ if (y instanceof Array && x instanceof Array)
797
+ return y.map((v, i) => atan2(v, x[i], rad));
798
+
799
+ const phi = Math.atan2(y, x);
800
+ return rad ? phi : phi * 180 / Math.PI;
801
+ };
802
+
803
+ const min$1 = (...x) => Math.min(...x);
804
+ const max$1 = (...x) => Math.max(...x);
805
+
806
+ const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
807
+
808
+ const variance = (...x) => {
809
+ const n = x.length;
810
+ if (n === 0) return NaN;
811
+ const x_mean = mean(...x);
812
+ return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
813
+ };
814
+
815
+ const std = (...x) => Math.sqrt(variance(...x));
816
+
817
+ const accum_sum = (...x) => {
818
+ let result = [];
819
+ let total = 0, i; n = x.length;
820
+ for(i = 0; i < n ; i++){
821
+ total = add(total, x[i]);
822
+ result.push(total);
823
+ }
824
+ return result;
825
+ };
826
+
827
+ const accum_prod = (...x) => {
828
+ let result = [];
829
+ let prod = 1, i; n = x.length;
830
+ for(i = 0; i < n ; i++){
831
+ prod = mul(prod, x[i]);
832
+ result.push(prod);
833
+ }
834
+ return result;
835
+ };
836
+
837
+ const percentile = (X, p) => {
838
+ if (X.length === 0)
839
+ return NaN;
840
+ let a = [...X].sort((x, y) => x - y);
841
+ let index = (p / 100) * (a.length - 1);
842
+ let i = Math.floor(index);
843
+ let f = index - i;
844
+ if (i === a.length - 1)
845
+ return a[i];
846
+ return a[i] * (1 - f) + a[i + 1] * f;
847
+ };
848
+
849
+ const median = X => percentile(X, 50);
850
+
875
851
  const preload=(url)=>{
876
852
  const xhr = new XMLHttpRequest();
877
853
  xhr.open("GET", url, false);
@@ -1501,9 +1477,9 @@ function unmount(delay = 0) {
1501
1477
  }
1502
1478
 
1503
1479
  var LifecycleMethods = /*#__PURE__*/Object.freeze({
1504
- __proto__: null,
1505
- mount: mount,
1506
- unmount: unmount
1480
+ __proto__: null,
1481
+ mount: mount,
1482
+ unmount: unmount
1507
1483
  });
1508
1484
 
1509
1485
  if(!globalThis.__Ziko__) __init__global__();
@@ -1670,11 +1646,11 @@ function setContentEditable(bool = true) {
1670
1646
  }
1671
1647
 
1672
1648
  var AttrsMethods = /*#__PURE__*/Object.freeze({
1673
- __proto__: null,
1674
- getAttr: getAttr,
1675
- removeAttr: removeAttr,
1676
- setAttr: setAttr,
1677
- setContentEditable: setContentEditable
1649
+ __proto__: null,
1650
+ getAttr: getAttr,
1651
+ removeAttr: removeAttr,
1652
+ setAttr: setAttr,
1653
+ setContentEditable: setContentEditable
1678
1654
  });
1679
1655
 
1680
1656
  function append(...ele) {
@@ -1731,15 +1707,15 @@ function before(ui){
1731
1707
  }
1732
1708
 
1733
1709
  var DomMethods = /*#__PURE__*/Object.freeze({
1734
- __proto__: null,
1735
- after: after,
1736
- append: append,
1737
- before: before,
1738
- clear: clear,
1739
- insertAt: insertAt,
1740
- prepend: prepend,
1741
- remove: remove,
1742
- replaceElementWith: replaceElementWith
1710
+ __proto__: null,
1711
+ after: after,
1712
+ append: append,
1713
+ before: before,
1714
+ clear: clear,
1715
+ insertAt: insertAt,
1716
+ prepend: prepend,
1717
+ remove: remove,
1718
+ replaceElementWith: replaceElementWith
1743
1719
  });
1744
1720
 
1745
1721
  const EventsMap = {
@@ -2453,11 +2429,11 @@ function find(condition) {
2453
2429
  }
2454
2430
 
2455
2431
  var IndexingMethods = /*#__PURE__*/Object.freeze({
2456
- __proto__: null,
2457
- at: at,
2458
- find: find,
2459
- forEach: forEach,
2460
- map: map
2432
+ __proto__: null,
2433
+ at: at,
2434
+ find: find,
2435
+ forEach: forEach,
2436
+ map: map
2461
2437
  });
2462
2438
 
2463
2439
  function style(styles){
@@ -2494,12 +2470,12 @@ function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
2494
2470
  }
2495
2471
 
2496
2472
  var StyleMethods = /*#__PURE__*/Object.freeze({
2497
- __proto__: null,
2498
- animate: animate,
2499
- hide: hide,
2500
- show: show,
2501
- size: size,
2502
- style: style
2473
+ __proto__: null,
2474
+ animate: animate,
2475
+ hide: hide,
2476
+ show: show,
2477
+ size: size,
2478
+ style: style
2503
2479
  });
2504
2480
 
2505
2481
  // import {
@@ -3173,7 +3149,7 @@ const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).mount(render);
3173
3149
  // };
3174
3150
 
3175
3151
  const obj2str=(obj)=>JSON.stringify(
3176
- mapfun$1(n=>{
3152
+ mapfun(n=>{
3177
3153
  if(["number","string","boolean","bigint"].includes(typeof n)) return String(n);
3178
3154
  if(n instanceof Complex || n instanceof Matrix) return n.toString();
3179
3155
  if(n instanceof Array) return arr2str(n)
@@ -3959,6 +3935,277 @@ const powerSet=originalSet=>{
3959
3935
  return subSets;
3960
3936
  };
3961
3937
 
3938
+ const zeros=(n)=>new Array(n).fill(0);
3939
+ const ones=(n)=>new Array(n).fill(1);
3940
+ const nums=(num,n)=>new Array(n).fill(num);
3941
+
3942
+ const arange=(a, b, step , include = false)=>{
3943
+ let tab = [];
3944
+ if(a<b){
3945
+ for (let i = a; include?i<=b:i<b; i += step) tab.push((i * 10) / 10);
3946
+ }
3947
+ else {
3948
+ for(let i = a; include?i>=b:i>b; i -= step) tab.push((i * 10) / 10);
3949
+ }
3950
+ return tab;
3951
+ };
3952
+ const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
3953
+ if(Math.floor(n)!==n)return;
3954
+ if([a,b].every(n=>typeof n==="number")){
3955
+ const [max,min]=[a,b].sort((a,b)=>b-a);
3956
+ var Y = [];
3957
+ let step ;
3958
+ endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
3959
+ for (var i = 0; i < n; i++) {
3960
+ a<b?Y.push(min+step*i):Y.push(max-step*i);
3961
+ }
3962
+ return Y
3963
+ }
3964
+
3965
+ if([a,b].some(n=>n.isComplex?.())){
3966
+ const z1 = new n.constructor(a);
3967
+ const z2 = new n.constructor(b);
3968
+ n=n||Math.abs(z1.a-z2.a)+1;
3969
+ const X=linspace(z1.a,z2.a,n,endpoint);
3970
+ const Y=linspace(z1.b,z2.b,n,endpoint);
3971
+ let Z=new Array(n).fill(null);
3972
+ Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
3973
+ return Z;
3974
+ }
3975
+ };
3976
+ const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
3977
+ return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
3978
+ };
3979
+ const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
3980
+ if(Math.floor(n)!==n)return;
3981
+ if([a,b].every(n=>typeof n==="number")){
3982
+ const [max,min]=[a,b].sort((a,b)=>b-a);
3983
+ let base;
3984
+ endpoint ? base = nthr(max/min,n-1) : base = nthr(max/min,n) ;
3985
+ const Y = [min];
3986
+ for (let i = 1; i < n; i++) {
3987
+ Y.push(Y[i-1]*base);
3988
+ }
3989
+ return a<b?Y:Y.reverse()
3990
+ }
3991
+
3992
+ if([a,b].some(n=>n.isComplex?.())){
3993
+ const z1 = new n.constructor(a);
3994
+ const z2 = new n.constructor(b);
3995
+ n=n||Math.abs(z1.a-z2.a)+1;
3996
+ let base;
3997
+ endpoint ? base = nthr(z2.div(z1),n-1) : base = nthr(z2.div(z1),n) ;
3998
+ const Y = [z1];
3999
+ for (let i = 1; i < n; i++) {
4000
+ Y.push(mul(Y[i-1],base));
4001
+ }
4002
+ return Y;
4003
+ }
4004
+ };
4005
+
4006
+ // Mixed calcul
4007
+ const sum=(...x)=>{
4008
+ if(x.every(n=>typeof n==="number")){
4009
+ let s = x[0];
4010
+ for (let i = 1; i < x.length; i++) s += x[i];
4011
+ return s;
4012
+ }
4013
+ const Y=[];
4014
+ for(let i=0;i<x.length;i++){
4015
+ if(x[i] instanceof Array)Y.push(sum(...x[i]));
4016
+ else if(x[i] instanceof Object){
4017
+ Y.push(sum(...Object.values(x[i])));
4018
+ }
4019
+ }
4020
+ return Y.length===1?Y[0]:Y;
4021
+ };
4022
+ const prod=(...x)=>{
4023
+ if(x.every(n=>typeof n==="number")){
4024
+ let p = x[0];
4025
+ for (let i = 1; i < x.length; i++) p *= x[i];
4026
+ return p;
4027
+ }
4028
+ const Y=[];
4029
+ for(let i=0;i<x.length;i++){
4030
+ if(x[i] instanceof Array)Y.push(prod(...x[i]));
4031
+ else if(x[i] instanceof Object){
4032
+ Y.push(prod(...Object.values(x[i])));
4033
+ }
4034
+ }
4035
+ return Y.length===1?Y[0]:Y;
4036
+ };
4037
+ // const min=(...num)=>{
4038
+ // if(num.every(n=>typeof n==="number"))return Math.min(...num);
4039
+ // const Y=[];
4040
+ // for(let i=0;i<num.length;i++){
4041
+ // if(num[i] instanceof Array)Y.push(min(...num[i]));
4042
+ // else if(num[i] instanceof Object){
4043
+ // Y.push(
4044
+ // Object.fromEntries(
4045
+ // [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
4046
+ // )
4047
+ // )
4048
+ // }
4049
+ // }
4050
+ // return Y.length===1?Y[0]:Y;
4051
+ // }
4052
+ // const max=(...num)=>{
4053
+ // if(num.every(n=>typeof n==="number"))return Math.max(...num);
4054
+ // const Y=[];
4055
+ // for(let i=0;i<num.length;i++){
4056
+ // if(num[i] instanceof Array)Y.push(min(...num[i]));
4057
+ // else if(num[i] instanceof Object){
4058
+ // Y.push(
4059
+ // Object.fromEntries(
4060
+ // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
4061
+ // )
4062
+ // )
4063
+ // }
4064
+ // }
4065
+ // return Y.length===1?Y[0]:Y;
4066
+ // }
4067
+ const accum=(...num)=>{
4068
+ if(num.every(n=>typeof n==="number")){
4069
+ let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
4070
+ acc.shift();
4071
+ return acc;
4072
+ }
4073
+ const Y=[];
4074
+ for(let i=0;i<num.length;i++){
4075
+ if(num[i] instanceof Array)Y.push(accum(...num[i]));
4076
+ else if(num[i] instanceof Object){
4077
+ Y.push(null
4078
+ // Object.fromEntries(
4079
+ // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
4080
+ // )
4081
+ );
4082
+ }
4083
+ }
4084
+ return Y.length===1?Y[0]:Y;
4085
+ };
4086
+
4087
+ //moy
4088
+ //med
4089
+ //variance
4090
+ //std
4091
+ //mode
4092
+ //acccum
4093
+ //min2max
4094
+ //max2min
4095
+ //percentile
4096
+
4097
+ /** @module Math */
4098
+ /**
4099
+ * Checks if a value is within the specified range.
4100
+ * @function
4101
+ * @param {number} x - The value to check.
4102
+ * @param {number} a - The start of the range.
4103
+ * @param {number} b - The end of the range.
4104
+ * @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
4105
+ */
4106
+ const inRange = (x, a, b) => {
4107
+ const [min, max] = [Math.min(a, b), Math.max(a, b)];
4108
+ return x >= min && x <= max;
4109
+ };
4110
+
4111
+ /**
4112
+ * Checks if two numbers are approximately equal within a given error margin.
4113
+ * @param {number} a - The first number.
4114
+ * @param {number} b - The second number.
4115
+ * @param {number} [Err=0.0001] - The maximum acceptable difference between the two numbers.
4116
+ * @returns {boolean} Returns true if the two numbers are approximately equal within the specified error margin, otherwise false.
4117
+ */
4118
+ const isApproximatlyEqual = (a, b, Err = 0.0001) => {
4119
+ return Math.abs(a - b) <= Err;
4120
+ };
4121
+
4122
+ /** @module Math */
4123
+
4124
+ /**
4125
+ * Computes the cartesian product of two arrays.
4126
+ * @param {Array} a - The first array.
4127
+ * @param {Array} b - The second array.
4128
+ * @returns {Array} Returns an array representing the cartesian product of the input arrays.
4129
+ */
4130
+ const cartesianProduct = (a, b) => a.reduce((p, x) => [...p, ...b.map((y) => [x, y])], []);
4131
+
4132
+ /**
4133
+ * Computes the greatest common divisor (GCD) of two numbers.
4134
+ * @param {number} n1 - The first number.
4135
+ * @param {number} n2 - The second number.
4136
+ * @returns {number} Returns the greatest common divisor of the two input numbers.
4137
+ */
4138
+ const pgcd = (n1, n2) => {
4139
+ let i,
4140
+ pgcd = 1;
4141
+ if (n1 == floor(n1) && n2 == floor(n2)) {
4142
+ for (i = 2; i <= n1 && i <= n2; ++i) {
4143
+ if (n1 % i == 0 && n2 % i == 0) pgcd = i;
4144
+ }
4145
+ return pgcd;
4146
+ } else console.log("error");
4147
+ };
4148
+
4149
+ /**
4150
+ * Computes the least common multiple (LCM) of two numbers.
4151
+ * @param {number} n1 - The first number.
4152
+ * @param {number} n2 - The second number.
4153
+ * @returns {number} Returns the least common multiple of the two input numbers.
4154
+ */
4155
+ const ppcm = (n1, n2) => {
4156
+ let ppcm;
4157
+ if (n1 == floor(n1) && n2 == floor(n2)) {
4158
+ ppcm = n1 > n2 ? n1 : n2;
4159
+ while (true) {
4160
+ if (ppcm % n1 == 0 && ppcm % n2 == 0) break;
4161
+ ++ppcm;
4162
+ }
4163
+ return ppcm;
4164
+ } else console.log("error");
4165
+ };
4166
+
4167
+ // import { mapfun } from "../mapfun/index.js";
4168
+ // import {
4169
+ // add,
4170
+ // sub,
4171
+ // mul,
4172
+ // div,
4173
+ // modulo
4174
+ // } from "./arithmetic.js";
4175
+ const Utils={
4176
+ // add,
4177
+ // sub,
4178
+ // mul,
4179
+ // div,
4180
+ // modulo,
4181
+
4182
+ zeros,
4183
+ ones,
4184
+ nums,
4185
+ // norm,
4186
+ // lerp,
4187
+ // map,
4188
+ // clamp,
4189
+ arange,
4190
+ linspace,
4191
+ logspace,
4192
+ geomspace,
4193
+
4194
+ sum,
4195
+ prod,
4196
+ accum,
4197
+
4198
+ cartesianProduct,
4199
+ ppcm,
4200
+ pgcd,
4201
+
4202
+ // deg2rad,
4203
+ // rad2deg,
4204
+
4205
+ inRange,
4206
+ isApproximatlyEqual
4207
+ };
4208
+
3962
4209
  // const subSet = (...arr) => {
3963
4210
  // let list = arange(0, 2 ** arr.length, 1);
3964
4211
  // let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
@@ -4322,14 +4569,14 @@ class Random {
4322
4569
  // }
4323
4570
  }
4324
4571
 
4325
- const { PI, sqrt: sqrt$1, cos: cos$1, sin: sin$1, acos, pow } = Math;
4572
+ const { PI, sqrt: sqrt$1, cos: cos$2, sin: sin$2, acos, pow } = Math;
4326
4573
 
4327
4574
  const linear = t => t;
4328
4575
 
4329
4576
  // --- Sin ---
4330
- const in_sin = t => 1 - cos$1((t * PI) / 2);
4331
- const out_sin = t => sin$1((t * PI) / 2);
4332
- const in_out_sin = t => -(cos$1(PI * t) - 1) / 2;
4577
+ const in_sin = t => 1 - cos$2((t * PI) / 2);
4578
+ const out_sin = t => sin$2((t * PI) / 2);
4579
+ const in_out_sin = t => -(cos$2(PI * t) - 1) / 2;
4333
4580
 
4334
4581
  // --- Quad ---
4335
4582
  const in_quad = t => t ** 2;
@@ -4376,14 +4623,14 @@ const in_out_circ = t =>
4376
4623
  : (sqrt$1(1 - (-2 * t + 2) ** 2) + 1) / 2;
4377
4624
 
4378
4625
  // --- Arc ---
4379
- const arc = t => 1 - sin$1(acos(t));
4626
+ const arc = t => 1 - sin$2(acos(t));
4380
4627
 
4381
4628
  // --- Back ---
4382
4629
  const back = (t, x = 1) => (t ** 2) * ((x + 1) * t - x);
4383
4630
 
4384
4631
  // --- Elastic ---
4385
4632
  const elastic = t =>
4386
- -2 * pow(2, 10 * (t - 1)) * cos$1((20 * PI * t) / 3 * t);
4633
+ -2 * pow(2, 10 * (t - 1)) * cos$2((20 * PI * t) / 3 * t);
4387
4634
 
4388
4635
  // --- Back variations ---
4389
4636
  const in_back = (t, c1 = 1.70158, c3 = c1 + 1) =>
@@ -4403,14 +4650,14 @@ const in_elastic = (t, c4 = (2 * PI) / 3) =>
4403
4650
  ? 0
4404
4651
  : t === 1
4405
4652
  ? 1
4406
- : -pow(2, 10 * t - 10) * sin$1((t * 10 - 10.75) * c4);
4653
+ : -pow(2, 10 * t - 10) * sin$2((t * 10 - 10.75) * c4);
4407
4654
 
4408
4655
  const out_elastic = (t, c4 = (2 * PI) / 3) =>
4409
4656
  t === 0
4410
4657
  ? 0
4411
4658
  : t === 1
4412
4659
  ? 1
4413
- : pow(2, -10 * t) * sin$1((t * 10 - 0.75) * c4) + 1;
4660
+ : pow(2, -10 * t) * sin$2((t * 10 - 0.75) * c4) + 1;
4414
4661
 
4415
4662
  const in_out_elastic = (t, c5 = (2 * PI) / 4.5) =>
4416
4663
  t === 0
@@ -4418,8 +4665,8 @@ const in_out_elastic = (t, c5 = (2 * PI) / 4.5) =>
4418
4665
  : t === 1
4419
4666
  ? 1
4420
4667
  : t < 0.5
4421
- ? -(pow(2, 20 * t - 10) * sin$1((20 * t - 11.125) * c5)) / 2
4422
- : (pow(2, -20 * t + 10) * sin$1((20 * t - 11.125) * c5)) / 2 + 1;
4668
+ ? -(pow(2, 20 * t - 10) * sin$2((20 * t - 11.125) * c5)) / 2
4669
+ : (pow(2, -20 * t + 10) * sin$2((20 * t - 11.125) * c5)) / 2 + 1;
4423
4670
 
4424
4671
  // --- Bounce ---
4425
4672
  const in_bounce = (t, n1 = 7.5625, d1 = 2.75) =>
@@ -5116,7 +5363,7 @@ function useDerived(deriveFn, sources) {
5116
5363
  })
5117
5364
  }
5118
5365
 
5119
- const useReactive = (nested_value) => mapfun$1(
5366
+ const useReactive = (nested_value) => mapfun(
5120
5367
  n => {
5121
5368
  const state = useState(n);
5122
5369
  return {
@@ -5415,7 +5662,7 @@ tags.p("Test useRoot ").style({
5415
5662
 
5416
5663
  */
5417
5664
 
5418
- let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
5665
+ let {sqrt, cos: cos$1, sin: sin$1, exp, log, cosh: cosh$1, sinh} = Math;
5419
5666
  // Math.abs = new Proxy(Math.abs, {
5420
5667
  // apply(target, thisArg, args) {
5421
5668
  // const x = args[0]
@@ -5446,20 +5693,20 @@ for (const key of Object.getOwnPropertyNames(Math)) {
5446
5693
  const complex = (a, b) => new x.constructor(a, b);
5447
5694
  switch(target.name){
5448
5695
  case 'abs' : return x.z;
5449
- case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
5696
+ case 'sqrt' : return complex(sqrt(z)*cos$1(phi/2),sqrt(z)*sin$1(phi/2));
5450
5697
  case 'log' : return complex(log(z), phi);
5451
- case 'exp' : return complex(exp(a)*cos(b),exp(a)*sin(b));
5452
- case 'cos' : return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
5453
- case 'sin' : return complex(sin(a)*cosh(b),cos(a)*sinh(b));
5698
+ case 'exp' : return complex(exp(a)*cos$1(b),exp(a)*sin$1(b));
5699
+ case 'cos' : return complex(cos$1(a)*cosh$1(b),-(sin$1(a)*sinh(b)));
5700
+ case 'sin' : return complex(sin$1(a)*cosh$1(b),cos$1(a)*sinh(b));
5454
5701
  case 'tan' : {
5455
- const DEN = cos(2*a)+cosh(2*b);
5456
- return complex(sin(2*a) /DEN, sinh(2*b)/DEN);
5702
+ const DEN = cos$1(2*a)+cosh$1(2*b);
5703
+ return complex(sin$1(2*a) /DEN, sinh(2*b)/DEN);
5457
5704
  }
5458
- case 'cosh' : return complex(cosh(a)*cos(b),sinh(a)*sin(b));
5459
- case 'sinh' : return complex(sinh(a)*cos(b),cosh(a)*sin(b));
5705
+ case 'cosh' : return complex(cosh$1(a)*cos$1(b),sinh(a)*sin$1(b));
5706
+ case 'sinh' : return complex(sinh(a)*cos$1(b),cosh$1(a)*sin$1(b));
5460
5707
  case 'tanh' : {
5461
- const DEN=cosh(2*a)+cos(2*b);
5462
- return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
5708
+ const DEN=cosh$1(2*a)+cos$1(2*b);
5709
+ return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
5463
5710
  }
5464
5711
  default : return target.apply(thisArg, args)
5465
5712
  }
@@ -5478,4 +5725,4 @@ if(globalThis?.document){
5478
5725
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
5479
5726
  }
5480
5727
 
5481
- export { App, Base, Clock, Combinaison, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Logic$1 as Logic, Matrix, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ZikoApp, ZikoEvent, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_swipe_event, bind_touch_event, bind_view_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, e, elastic, event_controller, fact, floor, geomspace, getEvent, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, toggle_event_listener, useDerived, useEventEmitter, useIPC, useLocaleStorage, useMediaQuery, useReactive, useRoot, useSessionStorage, useState, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, zeros };
5728
+ export { App, Base, Clock, Combinaison, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Logic$1 as Logic, Matrix, PI$1 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ZikoApp, ZikoEvent, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, abs, accum, accum_prod, accum_sum, acos$1 as acos, acosh, acot, add, animation, apply_fun, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_swipe_event, bind_touch_event, bind_view_event, bind_wheel_event, cartesianProduct, cbrt, ceil, clamp, clock, combinaison, complex, cos$3 as cos, cosh$2 as cosh, coth, croot, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, elastic, event_controller, exp$1 as exp, floor, fract, geomspace, getEvent, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linspace, ln, logspace, loop, map$1 as map, mapfun, matrix, matrix2, matrix3, matrix4, max$1 as max, mean, median, min$1 as min, modulo, mul, norm, nthr, nums, obj2str, ones, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, percentile, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$3 as sin, sinh$1 as sinh, sleep, sqrt$2 as sqrt, std, step, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, toggle_event_listener, trunc, useDerived, useEventEmitter, useIPC, useLocaleStorage, useMediaQuery, useReactive, useRoot, useSessionStorage, useState, useThread, useTitle, variance, wait, waitForUIElm, waitForUIElmSync, zeros };