ziko 0.54.0 → 0.54.2

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.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Fri Dec 05 2025 11:33:57 GMT+0100 (UTC+01:00)
5
+ Date : Sun Dec 07 2025 10:51:21 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
@@ -10,712 +10,46 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const { PI: PI$2, E } = Math;
13
+ const { PI: PI$1, E } = Math;
14
14
  const EPSILON=Number.EPSILON;
15
15
 
16
- 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;
17
- let Fixed={
18
- cos : x=> {
19
- if(x.isComplex?.()) return new x.constructor(
20
- cos$3(x.a)*cosh$2(x.b),
21
- -(sin$3(x.a)*sinh$2(x.b))
22
- );
23
- return cos$3(x)
24
- },
25
- sin : x=>{
26
- if(x?.isComplex) return new x.constructor(
27
- sin$3(x.a)*cosh$2(x.b),
28
- cos$3(x.a)*sinh$2(x.b)
29
- );
30
- return sin$3(x)
31
- },
32
- tan : x=>{
33
- if(x?.isComplex){
34
- const DEN = cos$3(2*x.a)+cosh$2(2*x.b);
35
- return new x.constructor(
36
- sin$3(2*x.a)/DEN,
37
- sinh$2(2*x.b)/DEN
38
- );
39
- }
40
- return tan$1(x)
41
- },
42
- sinc: x => sin$3(PI$1*x)/(PI$1*x),
43
- sec: x => 1/cos$3(x),
44
- csc: x => 1/sin$3(x),
45
- cot: x => 1/tan$1(x),
46
- acos: x=>{
47
- if(x?.isComplex) return
48
- return sin$3(x)
49
- },
50
- asin: x=>{
51
- if(x?.isComplex) return
52
- return sin$3(x)
53
- },
54
- atan: x=>{
55
- if(x?.isComplex) return
56
- return sin$3(x)
57
- },
58
- acot: x => PI$1/2-atan$1(x),
59
- cosh: x=>{
60
- if(x?.isComplex) return new x.constructor(
61
- cosh$2(x.a)*cos$3(x.b),
62
- sinh$2(x.a)*sin$3(x.b)
63
- );
64
- return cosh$2(x)
65
- },
66
- sinh: x=>{
67
- if(x?.isComplex) return new x.constructor(
68
- sinh$2(x.a)*cos$3(x.b),
69
- cosh$2(x.a)*sin$3(x.b)
70
- );
71
- return sinh$2(x)
72
- },
73
- tanh: x=>{
74
- if(x?.isComplex){
75
- const DEN=cosh$2(2*a)+cos$3(2*b);
76
- return new x.constructor(
77
- sinh$2(2*a)/DEN,
78
- sin$3(2*b)/DEN
79
- )
80
- }
81
- return tanh$1(x)
82
- },
83
- coth: n => (1/2*log$1((1+n)/(1-n))),
84
- acosh: acosh$1,
85
- asinh: asinh$1,
86
- atanh: atanh$1,
87
- };
88
-
89
- // Fixed = new Proxy(Fixed, {
90
- // get(target, prop) {
91
- // if(prop in target){
92
- // return x => + target[prop](x).toFixed(15);
93
- // }
94
- // return undefined;
95
- // }
96
- // })
97
-
98
- const mapfun$1=(fun,...X)=>{
99
- const Y=X.map(x=>{
100
- if(
101
- x===null||
102
- ["number","string","boolean","bigint","undefined"].includes(typeof x)||
103
- x?.__mapfun__
104
- ) return fun(x)
105
- if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
106
- if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
107
- if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
108
- if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun$1(fun,n[1])]));
109
- if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun$1(x.arr.flat(1)))
110
- // if(x.isComplex?.()){
111
- // const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
112
- // switch(fun){
113
- // // Moved to Fixed to avoid Circular Dep
114
- // // case Math.log: return new x.constructor(ln(z),phi); // Done
115
- // // case Math.exp: return new x.constructor(e(a)*cos(b),e(a)*sin(b)); // Done
116
- // // case Math.abs: return z; // Done
117
- // // case Math.sqrt: return new x.constructor(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
118
- // // case Fixed.cos: return new x.constructor(cos(a)*cosh(b),-(sin(a)*sinh(b)));
119
- // // case Fixed.sin: return new x.constructor(sin(a)*cosh(b),cos(a)*sinh(b));
120
- // // case Fixed.tan:{
121
- // // const DEN = cos(2*a)+cosh(2*b);
122
- // // return new x.constructor(sin(2*a)/DEN,sinh(2*b)/DEN);
123
- // // }
124
- // // case Fixed.cosh:return new x.constructor(cosh(a)*cos(b),sinh(a)*sin(b));
125
- // // case Fixed.sinh:return new x.constructor(sinh(a)*cos(b),cosh(a)*sin(b));
126
- // // case Fixed.tanh:{
127
- // // const DEN=cosh(2*a)+cos(2*b);
128
- // // return new x.constructor(sinh(2*a)/DEN,sin(2*b)/DEN)
129
- // // }
130
- // default : return fun(x)
131
- // }
132
- // }
133
- else if(x instanceof Object){
134
- return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun$1(fun,n[1])]))
135
- // return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
136
- }
137
- });
138
- return Y.length==1? Y[0]: Y;
139
- };
140
-
141
- // Mixed calcul
142
- const sum=(...x)=>{
143
- if(x.every(n=>typeof n==="number")){
144
- let s = x[0];
145
- for (let i = 1; i < x.length; i++) s += x[i];
146
- return s;
147
- }
148
- const Y=[];
149
- for(let i=0;i<x.length;i++){
150
- if(x[i] instanceof Array)Y.push(sum(...x[i]));
151
- else if(x[i] instanceof Object){
152
- Y.push(sum(...Object.values(x[i])));
153
- }
154
- }
155
- return Y.length===1?Y[0]:Y;
156
- };
157
- const prod=(...x)=>{
158
- if(x.every(n=>typeof n==="number")){
159
- let p = x[0];
160
- for (let i = 1; i < x.length; i++) p *= x[i];
161
- return p;
162
- }
163
- const Y=[];
164
- for(let i=0;i<x.length;i++){
165
- if(x[i] instanceof Array)Y.push(prod(...x[i]));
166
- else if(x[i] instanceof Object){
167
- Y.push(prod(...Object.values(x[i])));
168
- }
169
- }
170
- return Y.length===1?Y[0]:Y;
171
- };
172
- const min=(...num)=>{
173
- if(num.every(n=>typeof n==="number"))return Math.min(...num);
174
- const Y=[];
175
- for(let i=0;i<num.length;i++){
176
- if(num[i] instanceof Array)Y.push(min(...num[i]));
177
- else if(num[i] instanceof Object){
178
- Y.push(
179
- Object.fromEntries(
180
- [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
181
- )
182
- );
183
- }
184
- }
185
- return Y.length===1?Y[0]:Y;
186
- };
187
- const max=(...num)=>{
188
- if(num.every(n=>typeof n==="number"))return Math.max(...num);
189
- const Y=[];
190
- for(let i=0;i<num.length;i++){
191
- if(num[i] instanceof Array)Y.push(min(...num[i]));
192
- else if(num[i] instanceof Object){
193
- Y.push(
194
- Object.fromEntries(
195
- [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
196
- )
197
- );
198
- }
199
- }
200
- return Y.length===1?Y[0]:Y;
201
- };
202
- const accum=(...num)=>{
203
- if(num.every(n=>typeof n==="number")){
204
- let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
205
- acc.shift();
206
- return acc;
207
- }
208
- const Y=[];
209
- for(let i=0;i<num.length;i++){
210
- if(num[i] instanceof Array)Y.push(accum(...num[i]));
211
- else if(num[i] instanceof Object){
212
- Y.push(null
213
- // Object.fromEntries(
214
- // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
215
- // )
216
- );
217
- }
218
- }
219
- return Y.length===1?Y[0]:Y;
220
- };
221
-
222
- //moy
223
- //med
224
- //variance
225
- //std
226
- //mode
227
- //acccum
228
- //min2max
229
- //max2min
230
- //percentile
231
-
232
- const abs=(...x)=>mapfun$1(Math.abs,...x);
233
- const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
234
- const pow$1=(x,n)=>{
235
- if(typeof x === "number"){
236
- if(typeof n === "number")return Math.pow(x,n);
237
- else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
238
- else return mapfun$1(a=>pow$1(x,a),...n);
239
- }
240
- else if(x.isComplex?.()){
241
- if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
242
- else if(n.isComplex?.())return x.constructor.fromExpo(
243
- x.z**n.a*e(-x.phi*n.b),
244
- ln(x.z)*n.b+n.a*x.phi
245
- )
246
- else return mapfun$1(a=>pow$1(x,a),...n);
247
- }
248
- else if(x instanceof Array){
249
- if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
250
- else if(n instanceof Array){
251
- const Y=[];
252
- for(let i=0;i<x.length;i++){
253
- Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
254
- }
255
- return Y;
256
- }
257
- }
258
- };
259
- const sqrtn=(x,n)=>{
260
- if(typeof x === "number"){
261
- if(typeof n === "number")return Math.pow(x,1/n);
262
- else return mapfun$1(a=>sqrtn(x,a),...n);
263
- }
264
- else if(x.isComplex?.()){
265
- if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
266
- else return mapfun$1(a=>sqrtn(x,a),...n);
267
- }
268
- else if(x instanceof Array){
269
- if(typeof n === "number") return mapfun$1(a=>sqrtn(a,n),...x);
270
- else if(n instanceof Array){
271
- const Y=[];
272
- for(let i=0;i<x.length;i++){
273
- Y.push(mapfun$1(a=>sqrtn(x[i],a),...n));
274
- }
275
- return Y;
276
- }
277
- }
278
- };
279
- const e=(...x) => mapfun$1(Math.exp,...x);
280
- const ln=(...x) => mapfun$1(Math.log,...x);
281
- const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
282
- const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
283
- const tan=(...x) => mapfun$1(Fixed.tan,...x);
284
- const sec=(...x) => mapfun$1(Fixed.sec,...x);
285
- const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
286
- const csc=(...x) => mapfun$1(Fixed.csc,...x);
287
- const cot=(...x) => mapfun$1(Fixed.cot,...x);
288
- const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
289
- const asin=(...x) => mapfun$1(Fixed.asin,...x);
290
- const atan=(...x) => mapfun$1(Fixed.atan,...x);
291
- const acot=(...x) => mapfun$1(Fixed.acot,...x);
292
- const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
293
- const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
294
- const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
295
- const coth=(...x) => mapfun$1(Fixed.coth,...x);
296
- const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
297
- const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
298
- const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
299
- const ceil=(...x) => mapfun$1(Math.ceil,...x);
300
- const floor=(...x) => mapfun$1(Math.floor,...x);
301
- const round=(...x) => mapfun$1(Math.round,...x);
302
- const atan2=(x,y,rad=true)=>{
303
- if(typeof x === "number"){
304
- if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
305
- else return mapfun$1(a=>atan2(x,a,rad),...y);
306
- }
307
- // else if(x.isComplex?.()){
308
- // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
309
- // else return mapfun(a=>pow(x,a),...n);
310
- // }
311
- else if(x instanceof Array){
312
- if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
313
- else if(y instanceof Array){
314
- const Y=[];
315
- for(let i=0;i<x.length;i++){
316
- Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
317
- }
318
- return Y;
319
- }
320
- }
321
- };
322
- const fact=(...x)=>mapfun$1(n=> {
323
- let i,
324
- y = 1;
325
- if (n == 0) y = 1;
326
- else if (n > 0) for (i = 1; i <= n; i++) y *= i;
327
- else y = NaN;
328
- return y;
329
- },...x);
330
- const sign=(...x)=>mapfun$1(Math.sign,...x);
331
-
332
- const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
333
-
334
- const hypot=(...x)=>{
335
- if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
336
- if(x.every(n=>n instanceof Array))return mapfun$1(
337
- Math.hypot,
338
- ...x
339
- )
340
- };
341
-
342
- const _add=(a,b)=>{
343
- if(typeof(a)==="number"){
344
- if (typeof b == "number") return a + b;
345
- else if (b.isComplex?.())return new b.constructor(a + b.a, b.b);
346
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).add(b);
347
- else if (b instanceof Array)return b.map(n=>add(n,a));
348
- }
349
- else if(a.isComplex?.()||a.isMatrix?.()){
350
- if(b instanceof Array)return b.map(n=>a.clone.add(n));
351
- return a.clone.add(b);
352
- }
353
- else if(a instanceof Array){
354
- if(b instanceof Array){
355
- if(a.length === b.length)return a.map((n,i)=>add(n,b[i]))
356
- }
357
- else {
358
- return a.map(n=>add(n,b));
359
- }
360
- }
361
- };
362
- const _sub=(a,b)=>{
363
- if(typeof(a)==="number"){
364
- if (typeof b == "number") return a - b;
365
- else if (b.isComplex?.())return new b.constructor(a - b.a, -b.b);
366
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).sub(b);
367
- else if (b instanceof Array)return b.map(n=>sub(n,a));
368
- }
369
- else if(a.isComplex?.()||a.isMatrix?.()){
370
- if(b instanceof Array)return b.map(n=>a.clone.sub(n));
371
- return a.clone.sub(b);
372
- }
373
- else if(a instanceof Array){
374
- if(b instanceof Array){
375
- if(b instanceof Array){
376
- if(a.length === b.length)return a.map((n,i)=>sub(n,b[i]))
377
- }
378
- }
379
- else {
380
- return a.map(n=>sub(n,b));
381
- }
382
- }
383
- };
384
- const _mul=(a,b)=>{
385
- if(typeof(a)==="number"){
386
- if (typeof b == "number") return a * b;
387
- else if (b.isComplex?.())return new b.constructor(a * b.a,a * b.b);
388
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).mul(b);
389
- else if (b instanceof Array)return b.map(n=>mul(a,n));
390
- }
391
- else if(a.isComplex?.()||a.isMatrix?.()){
392
- if(b instanceof Array)return b.map(n=>a.clone.mul(n));
393
- return a.clone.mul(b);
394
- }
395
- else if(a instanceof Array){
396
- if(b instanceof Array){
397
- if(b instanceof Array){
398
- if(a.length === b.length)return a.map((n,i)=>mul(n,b[i]))
399
- }
400
- }
401
- else {
402
- return a.map(n=>mul(n,b));
403
- }
404
- }
405
- };
406
- const _div=(a,b)=>{
407
- if(typeof(a)==="number"){
408
- if (typeof b == "number") return a / b;
409
- else if (b.isComplex?.())return new b.constructor(a / b.a,a / b.b);
410
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).div(b);
411
- else if (b instanceof Array)return b.map(n=>div(a,n));
412
- }
413
- else if(a.isComplex?.()||a.isMatrix?.()){
414
- if(b instanceof Array)return b.map(n=>a.clone.div(n));
415
- return a.clone.div(b);
416
- }
417
- else if(a instanceof Array){
418
- if(b instanceof Array){
419
- if(b instanceof Array){
420
- if(a.length === b.length)return a.map((n,i)=>div(n,b[i]))
421
- }
422
- }
423
- else {
424
- return a.map(n=>div(n,b));
425
- }
426
- }
427
- };
428
- const _modulo=(a,b)=>{
429
- if(typeof(a)==="number"){
430
- if (typeof b == "number") return a % b;
431
- else if (b.isComplex?.())return new b.constructor(a % b.a,a % b.b);
432
- else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).modulo(b);
433
- else if (b instanceof Array)return b.map(n=>div(a,n));
434
- }
435
- else if(a.isComplex?.()||a.isMatrix?.()){
436
- if(b instanceof Array)return b.map(n=>a.clone.div(n));
437
- return a.clone.div(b);
438
- }
439
- else if(a instanceof Array){
440
- if(b instanceof Array);
441
- else {
442
- return a.map(n=>add(n,b));
443
- }
444
- }
445
- };
446
- const add=(a,...b)=>{
447
- var res=a;
448
- for(let i=0;i<b.length;i++)res=_add(res,b[i]);
449
- return res;
450
- };
451
- const sub=(a,...b)=>{
452
- var res=a;
453
- for(let i=0;i<b.length;i++)res=_sub(res,b[i]);
454
- return res;
455
- };
456
- const mul=(a,...b)=>{
457
- var res=a;
458
- for(let i=0;i<b.length;i++)res=_mul(res,b[i]);
459
- return res;
460
- };
461
- const div=(a,...b)=>{
462
- var res=a;
463
- for(let i=0;i<b.length;i++)res=_div(res,b[i]);
464
- return res;
465
- };
466
- const modulo=(a,...b)=>{
467
- var res=a;
468
- for(let i=0;i<b.length;i++)res=_modulo(res,b[i]);
469
- return res;
470
- };
471
-
472
- const zeros=(n)=>new Array(n).fill(0);
473
- const ones=(n)=>new Array(n).fill(1);
474
- const nums=(num,n)=>new Array(n).fill(num);
475
- const norm=(value, min, max)=>{
476
- if (typeof value === "number") return min !== max ? (value - min) / (max - min) : 0;
477
- else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, norm(value.arr.flat(1), min, max));
478
- else if (value.isComplex?.()) return new value.constructor(norm(value.a, min, max), norm(value.b, min, max));
479
- else if (value instanceof Array) {
480
- if (value.every((n) => typeof (n === "number"))) {
481
- return value.map((n) => norm(n, min, max));
482
- } else {
483
- let y = new Array(value.length);
484
- for (let i = 0; i < value.length; i++) {
485
- y[i] = norm(value[i]);
486
- }
487
- }
488
- }
489
- };
490
- const lerp=(value, min, max)=>{
491
- if (typeof value === "number") return (max - min) * value + min;
492
- else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, lerp(value.arr.flat(1), min, max));
493
- else if (value.isComplex?.()) return new value.constructor(lerp(value.a, min, max), lerp(value.b, min, max));
494
- else if (value instanceof Array) {
495
- if (value.every((n) => typeof (n === "number"))) {
496
- return value.map((n) => lerp(n, min, max));
497
- } else {
498
- let y = new Array(value.length);
499
- for (let i = 0; i < value.length; i++) {
500
- y[i] = lerp(value[i]);
501
- }
502
- }
503
- }
504
- };
505
- const map$1=(x, a, b, c, d)=>{
506
- if (typeof x === "number") return lerp(norm(x, a, b), c, d);
507
- else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, map$1(x.arr.flat(1), a, b, c, d));
508
- else if (x.isComplex?.()) return new x.constructor(map$1(x.a, b, c, d), map$1(x.b, a, b, c, d));
509
- else if (x instanceof Array) {
510
- if (x.every((n) => typeof (n === "number"))) {
511
- return x.map((n) => map$1(n, a, b, c, d));
512
- } else {
513
- let y = new Array(x.length);
514
- for (let i = 0; i < x.length; i++) {
515
- y[i] = map$1(x[i], a, b, c, d);
516
- }
517
- }
518
- }
519
- };
520
- const clamp=(x, a , b)=>{
521
- const [min_value,max_value]=[min(a,b),max(a,b)];
522
- if (typeof x === "number") return min(max(x, min_value), max_value);
523
- else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, clamp(x.arr.flat(1), min_value, max_value));
524
- else if (x.isComplex?.()) return new x.constructor(clamp(x.a, min_value, max_value), clamp(x.b, min_value, max_value));
525
- else if (x instanceof Array) {
526
- if (x.every((n) => typeof (n === "number"))) {
527
- return x.map((n) => clamp(n, min_value, max_value));
528
- } else {
529
- let y = new Array(x.length);
530
- for (let i = 0; i < x.length; i++) {
531
- y[i] = clamp(x[i], min_value, max_value);
532
- }
533
- }
534
- }
535
- };
536
- const arange=(a, b, step , include = false)=>{
537
- let tab = [];
538
- if(a<b){
539
- for (let i = a; include?i<=b:i<b; i += step) tab.push((i * 10) / 10);
540
- }
541
- else {
542
- for(let i = a; include?i>=b:i>b; i -= step) tab.push((i * 10) / 10);
543
- }
544
- return tab;
545
- };
546
- const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
547
- if(Math.floor(n)!==n)return;
548
- if([a,b].every(n=>typeof n==="number")){
549
- const [max,min]=[a,b].sort((a,b)=>b-a);
550
- var Y = [];
551
- let step ;
552
- endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
553
- for (var i = 0; i < n; i++) {
554
- a<b?Y.push(min+step*i):Y.push(max-step*i);
555
- }
556
- return Y
557
- }
558
-
559
- if([a,b].some(n=>n.isComplex?.())){
560
- const z1 = new n.constructor(a);
561
- const z2 = new n.constructor(b);
562
- n=n||Math.abs(z1.a-z2.a)+1;
563
- const X=linspace(z1.a,z2.a,n,endpoint);
564
- const Y=linspace(z1.b,z2.b,n,endpoint);
565
- let Z=new Array(n).fill(null);
566
- Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
567
- return Z;
568
- }
569
- };
570
- const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
571
- return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
572
- };
573
- const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
574
- if(Math.floor(n)!==n)return;
575
- if([a,b].every(n=>typeof n==="number")){
576
- const [max,min]=[a,b].sort((a,b)=>b-a);
577
- let base;
578
- endpoint ? base = sqrtn(max/min,n-1) : base = sqrtn(max/min,n) ;
579
- const Y = [min];
580
- for (let i = 1; i < n; i++) {
581
- Y.push(Y[i-1]*base);
582
- }
583
- return a<b?Y:Y.reverse()
584
- }
585
-
586
- if([a,b].some(n=>n.isComplex?.())){
587
- const z1 = new n.constructor(a);
588
- const z2 = new n.constructor(b);
589
- n=n||Math.abs(z1.a-z2.a)+1;
590
- let base;
591
- endpoint ? base = sqrtn(z2.div(z1),n-1) : base = sqrtn(z2.div(z1),n) ;
592
- const Y = [z1];
593
- for (let i = 1; i < n; i++) {
594
- Y.push(mul(Y[i-1],base));
595
- }
596
- return Y;
597
- }
598
- };
599
-
600
- /** @module Math */
601
- /**
602
- * Converts degrees to radians.
603
- * @param {...number} deg - Degrees to convert.
604
- * @returns {number|number[]} Returns an array of radians corresponding to the input degrees.
605
- */
606
- const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
607
-
608
- /**
609
- * Converts radians to degrees.
610
- * @param {...number} rad - Radians to convert.
611
- * @returns {number|number[]} Returns an array of degrees corresponding to the input radians.
612
- */
613
- const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
614
-
615
- /** @module Math */
616
- /**
617
- * Checks if a value is within the specified range.
618
- * @function
619
- * @param {number} x - The value to check.
620
- * @param {number} a - The start of the range.
621
- * @param {number} b - The end of the range.
622
- * @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
623
- */
624
- const inRange = (x, a, b) => {
625
- const [min, max] = [Math.min(a, b), Math.max(a, b)];
626
- return x >= min && x <= max;
627
- };
628
-
629
- /**
630
- * Checks if two numbers are approximately equal within a given error margin.
631
- * @param {number} a - The first number.
632
- * @param {number} b - The second number.
633
- * @param {number} [Err=0.0001] - The maximum acceptable difference between the two numbers.
634
- * @returns {boolean} Returns true if the two numbers are approximately equal within the specified error margin, otherwise false.
635
- */
636
- const isApproximatlyEqual = (a, b, Err = 0.0001) => {
637
- return Math.abs(a - b) <= Err;
638
- };
639
-
640
- /** @module Math */
641
-
642
- /**
643
- * Computes the cartesian product of two arrays.
644
- * @param {Array} a - The first array.
645
- * @param {Array} b - The second array.
646
- * @returns {Array} Returns an array representing the cartesian product of the input arrays.
647
- */
648
- const cartesianProduct = (a, b) => a.reduce((p, x) => [...p, ...b.map((y) => [x, y])], []);
649
-
650
- /**
651
- * Computes the greatest common divisor (GCD) of two numbers.
652
- * @param {number} n1 - The first number.
653
- * @param {number} n2 - The second number.
654
- * @returns {number} Returns the greatest common divisor of the two input numbers.
655
- */
656
- const pgcd = (n1, n2) => {
657
- let i,
658
- pgcd = 1;
659
- if (n1 == floor(n1) && n2 == floor(n2)) {
660
- for (i = 2; i <= n1 && i <= n2; ++i) {
661
- if (n1 % i == 0 && n2 % i == 0) pgcd = i;
16
+ const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
17
+
18
+ const mapfun=(fun,...X)=>{
19
+ const Y=X.map(x=>{
20
+ if(is_primitive(x) || x?.__mapfun__) return fun(x)
21
+ if(x instanceof Array) return x.map(n=>mapfun(fun,n));
22
+ if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
23
+ if(x instanceof Set) return new Set(mapfun(fun,...[...x]));
24
+ if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun(fun,n[1])]));
25
+ if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun(x.arr.flat(1)))
26
+ else if(x instanceof Object){
27
+ return Object.fromEntries(
28
+ Object.entries(x).map(
29
+ n=>n=[n[0],mapfun(fun,n[1])]
30
+ )
31
+ )
662
32
  }
663
- return pgcd;
664
- } else console.log("error");
33
+ });
34
+ return Y.length==1? Y[0]: Y;
665
35
  };
666
36
 
667
- /**
668
- * Computes the least common multiple (LCM) of two numbers.
669
- * @param {number} n1 - The first number.
670
- * @param {number} n2 - The second number.
671
- * @returns {number} Returns the least common multiple of the two input numbers.
672
- */
673
- const ppcm = (n1, n2) => {
674
- let ppcm;
675
- if (n1 == floor(n1) && n2 == floor(n2)) {
676
- ppcm = n1 > n2 ? n1 : n2;
677
- while (true) {
678
- if (ppcm % n1 == 0 && ppcm % n2 == 0) break;
679
- ++ppcm;
680
- }
681
- return ppcm;
682
- } else console.log("error");
683
- };
684
-
685
- const Utils={
686
- add,
687
- sub,
688
- mul,
689
- div,
690
- modulo,
691
-
692
- zeros,
693
- ones,
694
- nums,
695
- norm,
696
- lerp,
697
- map: map$1,
698
- clamp,
699
- arange,
700
- linspace,
701
- logspace,
702
- geomspace,
703
-
704
- sum,
705
- prod,
706
- accum,
707
-
708
- cartesianProduct,
709
- ppcm,
710
- pgcd,
711
-
712
- deg2rad,
713
- rad2deg,
714
-
715
- inRange,
716
- isApproximatlyEqual
37
+ const apply_fun = (x, fn) => {
38
+ if (x.isComplex?.()) return new x.constructor(
39
+ fn(x.a),
40
+ fn(x.b)
41
+ )
42
+ if (x.isMatrix?.()) return new x.constructor(
43
+ x.rows,
44
+ x.cols,
45
+ x.arr.flat(1).map(fn)
46
+ )
47
+ if (x instanceof Array) mapfun(fn, ...x);
48
+ return fn(x)
717
49
  };
718
50
 
51
+ // import {sum,prod,deg2rad} from "../utils/index.js";
52
+ // Should avoid CD
719
53
  class Complex{
720
54
  constructor(a = 0, b = 0) {
721
55
  if(a instanceof Complex){
@@ -724,33 +58,33 @@ class Complex{
724
58
  }
725
59
  else if(typeof(a)==="object"){
726
60
  if(("a" in a && "b" in a)){
727
- this.a=a.a;
728
- this.b=a.b;
61
+ this.a = a.a;
62
+ this.b = a.b;
729
63
  }
730
64
  else if(("a" in a && "z" in a)){
731
- this.a=a.a;
732
- this.b=sqrt$2((a.z**2)-(a.a**2));
65
+ this.a = a.a;
66
+ this.b = Math.sqrt((a.z**2)-(a.a**2));
733
67
  }
734
68
  else if(("a" in a && "phi" in a)){
735
- this.a=a.a;
736
- this.b=a.a*tan(a.phi);
69
+ this.a = a.a;
70
+ this.b = a.a * Math.tan(a.phi);
737
71
  }
738
72
  else if(("b" in a && "z" in a)){
739
- this.b=a.b;
740
- this.a=sqrt$2((a.z**2)-(a.b**2));
73
+ this.b = a.b;
74
+ this.a = Math.sqrt((a.z**2)-(a.b**2));
741
75
  }
742
76
  else if(("b" in a && "phi" in a)){
743
- this.b=b;
744
- this.a=a.b/tan(a.phi);
77
+ this.b = b;
78
+ this.a = a.b / Math.tan(a.phi);
745
79
  }
746
80
  else if(("z" in a && "phi" in a)){
747
- this.a=a.z*cos$2(a.phi);
748
- this.a=a.z*sin$2(a.phi);
81
+ this.a = + a.z * Math.cos(a.phi).toFixed(15);
82
+ this.b = + a.z * Math.sin(a.phi).toFixed(15);
749
83
  }
750
84
  }
751
- else if(typeof(a)==="number"&&typeof(b)==="number"){
752
- this.a = +a.toFixed(32);
753
- this.b = +b.toFixed(32);
85
+ else if(typeof(a)==="number" && typeof(b)==="number"){
86
+ this.a = + a.toFixed(32);
87
+ this.b = + b.toFixed(32);
754
88
  }
755
89
  }
756
90
  get __mapfun__(){
@@ -772,14 +106,14 @@ class Complex{
772
106
  return str;
773
107
  }
774
108
 
775
- get clone() {
109
+ clone() {
776
110
  return new Complex(this.a, this.b);
777
111
  }
778
112
  get z(){
779
- return hypot(this.a,this.b);
113
+ return Math.hypot(this.a,this.b);
780
114
  }
781
115
  get phi(){
782
- return atan2(this.b , this.a);
116
+ return Math.atan2(this.b , this.a);
783
117
  }
784
118
  static Zero() {
785
119
  return new Complex(0, 0);
@@ -788,102 +122,109 @@ class Complex{
788
122
  return new Complex(this.a, -this.b);
789
123
  }
790
124
  get inv() {
791
- 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)));
125
+ return new Complex(
126
+ this.a / Math.hypot(this.a, this.b),
127
+ -this.b / Math.hypot(this.a, this.b)
128
+ );
792
129
  }
793
- add(...z) {
794
- for (let i = 0; i < z.length; i++) {
795
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
130
+ add(...c) {
131
+ for (let i = 0; i < c.length; i++) {
132
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
133
+ this.a += c[i].a;
134
+ this.b += c[i].b;
796
135
  }
797
- let re = z.map((n) => n.a);
798
- let im = z.map((n) => n.b);
799
- this.a+=+sum(...re).toFixed(15);
800
- this.b+=+sum(...im).toFixed(15);
801
136
  return this;
802
137
  }
803
- sub(...z) {
804
- for (let i = 0; i < z.length; i++) {
805
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
138
+ sub(...c) {
139
+ for (let i = 0; i < c.length; i++) {
140
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
141
+ this.a -= c[i].a;
142
+ this.b -= c[i].b;
806
143
  }
807
- let re = z.map((n) => n.a);
808
- let im = z.map((n) => n.b);
809
- this.a-=+sum(...re).toFixed(15);
810
- this.b-=+sum(...im).toFixed(15);
811
144
  return this;
812
145
  }
813
- mul(...z){
814
- for (let i = 0; i < z.length; i++) {
815
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
146
+ mul(...c){
147
+ let {z, phi} = this;
148
+ for (let i = 0; i < c.length; i++) {
149
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
150
+ z *= c[i].z;
151
+ phi += c[i].z;
816
152
  }
817
- let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
818
- let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
819
- this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
820
- this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
153
+ this.a = z*Math.cos(phi);
154
+ this.b = z*Math.sin(phi);
821
155
  return this;
822
156
  }
823
- div(...z) {
824
- for (let i = 0; i < z.length; i++) {
825
- if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
157
+ div(...c){
158
+ let {z, phi} = this;
159
+ for (let i = 0; i < c.length; i++) {
160
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
161
+ z /= c[i].z;
162
+ phi -= c[i].z;
826
163
  }
827
- let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
828
- let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
829
- this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
830
- this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
164
+ this.a = z*Math.cos(phi);
165
+ this.b = z*Math.sin(phi);
831
166
  return this;
832
167
  }
833
- pow(n) {
834
- if (floor(n) === n && n > 0) {
835
- let z=+(this.z**n).toFixed(15);
836
- let phi=+(this.phi*n).toFixed(15);
837
- this.a=+(z*cos$2(phi).toFixed(15)).toFixed(15);
838
- this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
168
+ modulo(...c) {
169
+ for (let i = 0; i < c.length; i++) {
170
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
171
+ this.a %= c[i].a;
172
+ this.b %= c[i].b;
839
173
  }
840
174
  return this;
841
175
  }
842
176
  static fromExpo(z, phi) {
843
177
  return new Complex(
844
- +(z * cos$2(phi)).toFixed(13),
845
- +(z * sin$2(phi)).toFixed(13)
178
+ +(z * cos(phi)).toFixed(13),
179
+ +(z * sin(phi)).toFixed(13)
846
180
  );
847
181
  }
848
182
  get expo() {
849
183
  return [this.z, this.phi];
850
184
  }
851
185
  static add(c,...z) {
852
- return c.clone.add(...z);
186
+ return c.clone().add(...z);
853
187
  }
854
188
  static sub(c,...z) {
855
- return c.clone.sub(...z);
189
+ return c.clone().sub(...z);
856
190
  }
857
191
  static mul(c,...z) {
858
- return c.clone.mul(...z);
192
+ return c.clone().mul(...z);
859
193
  }
860
194
  static div(c,...z) {
861
- return c.clone.div(...z);
862
- }
863
- static pow(z,n){
864
- return z.clone.pow(n);
195
+ return c.clone().div(...z);
865
196
  }
866
- static xpowZ(x){
867
- return complex((x**this.a)*cos$2(this.b*ln(x)),(x**this.a)*sin$2(this.b*ln(x)));
868
- }
869
- sqrtn(n=2){
870
- return complex(sqrtn(this.z,n)*cos$2(this.phi/n),sqrtn(this.z,n)*sin$2(this.phi/n));
197
+
198
+ nthr(n=2){
199
+ return complex({z: this.z ** (1/n), phi: this.phi / n});
871
200
  }
872
201
  get sqrt(){
873
- return this.sqrtn(2);
202
+ return this.nrth(2);
203
+ }
204
+ get cbrt(){
205
+ return this.nrth(3);
874
206
  }
875
207
  get log(){
876
- return complex(this.z,this.phi);
208
+ return complex(this.z, this.phi);
877
209
  }
878
210
  get cos(){
879
- return complex(cos$2(this.a)*cosh$1(this.b),sin$2(this.a)*sinh$1(this.b))
211
+ return complex(
212
+ Math.cos(this.a) * Math.cosh(this.b),
213
+ Math.sin(this.a) * Math.sinh(this.b)
214
+ )
880
215
  }
881
216
  get sin(){
882
- return complex(sin$2(this.a)*cosh$1(this.b),cos$2(this.a)*sinh$1(this.b))
217
+ return complex(
218
+ Math.sin(this.a) * Math.cosh(this.b),
219
+ Math.cos(this.a) * Math.sinh(this.b)
220
+ )
883
221
  }
884
222
  get tan(){
885
- const de=cos$2(this.a*2)+cosh$1(this.b*2);
886
- return complex(sin$2(2*this.a)/de,sinh$1(2*this.b)/de);
223
+ const D=cos(this.a*2)+cosh(this.b*2);
224
+ return complex(
225
+ Math.sin(2 * this.a) / D,
226
+ Math.sinh(2 * this.b) / D
227
+ );
887
228
  }
888
229
  }
889
230
  const complex=(a,b)=>{
@@ -896,6 +237,554 @@ const complex=(a,b)=>{
896
237
  return new Complex(a,b)
897
238
  };
898
239
 
240
+ const abs = (...x) => mapfun(
241
+ x =>{
242
+ if(x.isComplex?.()) return x.z;
243
+ return Math.abs(x)
244
+ },
245
+ ...x
246
+ );
247
+
248
+ const pow$1 = (...x) => {
249
+ const n = x.pop();
250
+ return mapfun(
251
+ x => {
252
+ if(x.isComplex?.()) {
253
+ if(n.isComplex?.()) return new x.constructor({
254
+ z: Math.exp(n.a * Math.log(x.z) - n.b * x.phi),
255
+ phi: n.b * Math.log(x.z) + n.a * x.phi
256
+ })
257
+ return new x.constructor({z: x.z ** n, phi: x.phi * n});
258
+ }
259
+ if(n.isComplex?.()) return new x.constructor({
260
+ z: Math.exp(n.a * Math.log(x)),
261
+ phi: n.b * Math.log(x)
262
+ })
263
+ return Math.pow(x, n)
264
+ },
265
+ ...x
266
+ )
267
+ };
268
+
269
+ const sqrt$2 = (...x) => mapfun(
270
+ x=>{
271
+ if(x.isComplex?.())
272
+ return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
273
+ if(x < 0) return complex(0, Math.sqrt(-x))
274
+ return Math.sqrt(x);
275
+ },
276
+ ...x
277
+ );
278
+
279
+ const cbrt = (...x) => mapfun(
280
+ x=>{
281
+ if(x.isComplex?.())
282
+ return new x.constructor({z: x.z**(1/3), phi: x.phi/3})
283
+ return Math.cbrt(x);
284
+ },
285
+ ...x
286
+ );
287
+
288
+ const nthr = (...x) => {
289
+ const n = x.pop();
290
+ if(typeof n !== 'number') throw Error('nthr expects a real number n');
291
+ return mapfun(
292
+ x => {
293
+ if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
294
+ if(x<0) return n%2===2 ? complex(0, (-x)**(1/n)) : -1 * (-x)**(1/n)
295
+ return x**(1/n)
296
+ },
297
+ ...x
298
+ )
299
+ };
300
+
301
+ const croot = (...x) =>{
302
+ const c = x.pop();
303
+ if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
304
+ return mapfun(
305
+ x => {
306
+ if(typeof x === 'number') x = new c.constructor(x, 0);
307
+ const {a : c_a, b : c_b} = c;
308
+ const {z, phi} = x;
309
+ const D = Math.hypot(c_a, c_b);
310
+ const A = Math.exp((Math.log(z)*c_a + phi*c_b)/D);
311
+ const B = (phi*c_a - Math.log(z)*c_b)/D;
312
+ return new c.constructor(
313
+ A * Math.cos(B),
314
+ A * Math.sin(B)
315
+ )
316
+ },
317
+ ...x
318
+ )
319
+ };
320
+
321
+ const exp$1 = (...x) => mapfun(
322
+ x => {
323
+ if(x.isComplex?.()) return new x.constructor(
324
+ Math.exp(x.a) * Math.cos(x.b),
325
+ Math.exp(x.a) * Math.sin(x.b)
326
+ );
327
+ return Math.exp(x)
328
+ }
329
+ ,...x
330
+ );
331
+
332
+ const ln = (...x) => mapfun(
333
+ x => {
334
+ if(x.isComplex?.()) return new x.constructor(
335
+ Math.log(x.z),
336
+ x.phi
337
+ );
338
+ return Math.log(x)
339
+ }
340
+ ,...x
341
+ );
342
+
343
+ const sign = (...x) => mapfun(
344
+ x => {
345
+ if(x.isComplex?.()){
346
+ const {z, phi} = x;
347
+ if(z===0) return new x.constructor(0, 0);
348
+ return new x.constructor({z:1, phi})
349
+ }
350
+ return Math.sign(x)
351
+ }
352
+ ,...x
353
+ );
354
+
355
+ const floor = (...x) => mapfun(
356
+ x => {
357
+ if(x.isComplex?.()) return new x.constructor(
358
+ Math.floor(x.a),
359
+ Math.floor(x.b)
360
+ )
361
+ return Math.floor(x)
362
+ },
363
+ ...x
364
+ );
365
+ const ceil = (...x) => mapfun(
366
+ x => {
367
+ if(x.isComplex?.()) return new x.constructor(
368
+ Math.ceil(x.a),
369
+ Math.ceil(x.b)
370
+ )
371
+ return Math.ceil(x)
372
+ },
373
+ ...x
374
+ );
375
+ const round = (...x) => mapfun(
376
+ x => {
377
+ if(x.isComplex?.()) return new x.constructor(
378
+ Math.round(x.a),
379
+ Math.round(x.b)
380
+ )
381
+ return Math.round(x)
382
+ },
383
+ ...x
384
+ );
385
+
386
+ const trunc = (...x) => mapfun(
387
+ x => {
388
+ if(x.isComplex?.()) return new x.constructor(
389
+ Math.trunc(x.a),
390
+ Math.trunc(x.b)
391
+ )
392
+ return Math.trunc(x)
393
+ },
394
+ ...x
395
+ );
396
+
397
+ const fract = (...x) => mapfun(
398
+ x => {
399
+ if(x.isComplex?.()) return new x.constructor(
400
+ x.a - Math.trunc(x.a),
401
+ x.b - Math.trunc(x.b)
402
+ )
403
+ return x - Math.trunc(x)
404
+ },
405
+ ...x
406
+ );
407
+
408
+ const cos$3 = (...x) => mapfun(
409
+ x => {
410
+ if(x.isComplex?.()) return new x.constructor(
411
+ Math.cos(x.a) * Math.cosh(x.b),
412
+ -Math.sin(x.a) * Math.sinh(x.b)
413
+ );
414
+ return Math.cos(x)
415
+ }
416
+ ,...x
417
+ );
418
+
419
+ const sin$3 = (...x) => mapfun(
420
+ x =>{
421
+ if(x?.isComplex) return new x.constructor(
422
+ Math.sin(x.a) * Math.cosh(x.b),
423
+ Math.cos(x.a) * Math.sinh(x.b)
424
+ );
425
+ return Math.sin(x)
426
+ }
427
+ , ...x
428
+ );
429
+
430
+ const tan = (...x) => mapfun(
431
+ x =>{
432
+ if(x?.isComplex){
433
+ const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
434
+ return new x.constructor(
435
+ Math.sin(2*x.a) / D,
436
+ Math.sinh(2*x.b) / D
437
+ );
438
+ }
439
+ return Math.tan(x)
440
+ },
441
+ ...x
442
+ );
443
+
444
+ const sec = (...x) => mapfun(
445
+ x => {
446
+ if(x.isComplex?.()) ;
447
+ return 1 / Math.cos(x)
448
+ }
449
+ ,...x
450
+ );
451
+
452
+ const acos$1 = (...x) => mapfun(
453
+ x =>{
454
+ if(x?.isComplex){
455
+ const { a, b } = x;
456
+ const Rp = Math.hypot(a + 1, b);
457
+ const Rm = Math.hypot(a - 1, b);
458
+ globalThis.Rp = Rp;
459
+ globalThis.Rm = Rm;
460
+ return new x.constructor(
461
+ Math.acos((Rp - Rm) / 2),
462
+ -Math.acosh((Rp + Rm) / 2),
463
+ )
464
+ }
465
+ return Math.acos(x)
466
+ },
467
+ ...x
468
+ );
469
+
470
+ const asin = (...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
+ return new x.constructor(
477
+ Math.asin((Rp - Rm) / 2),
478
+ Math.acosh((Rp + Rm) / 2)
479
+ );
480
+ }
481
+ return Math.asin(x);
482
+ },
483
+ ...x
484
+ );
485
+
486
+ const atan = (...x) => mapfun(
487
+ x => {
488
+ if(x?.isComplex){
489
+ const { a, b } = x;
490
+ return new x.constructor(
491
+ Math.atan((a*2/(1-a**2-b**2)))/2,
492
+ Math.log((a**2 + (1+b)**2)/(a**2 + (1-b)**2))/4
493
+ )
494
+ }
495
+ return Math.atan(x);
496
+ },
497
+ ...x
498
+ );
499
+
500
+ const acot = (...x) => mapfun(
501
+ x => {
502
+ if(x?.isComplex){
503
+ const { a, b } = x;
504
+ return new x.constructor(
505
+ Math.atan(2*a/(a**2+(b-1)*(b+1)))/2,
506
+ Math.log((a**2 + (b-1)**2)/(a**2 + (b+1)**2))/4
507
+ )
508
+ }
509
+ return Math.PI/2 - Math.atan(x);
510
+ },
511
+ ...x
512
+ );
513
+
514
+
515
+ const cosh$2 = (...x) => mapfun(
516
+ x =>{
517
+ if(x?.isComplex) return new x.constructor(
518
+ Math.cosh(x.a) * Math.cos(x.b),
519
+ Math.sinh(x.a) * Math.sin(x.b)
520
+ );
521
+ return Math.cosh(x)
522
+ },
523
+ ...x
524
+ );
525
+ const sinh$1 = (...x) => mapfun(
526
+ x =>{
527
+ if(x?.isComplex) return new x.constructor(
528
+ Math.sinh(x.a) * Math.cos(x.b),
529
+ Math.cosh(x.a) * Math.sin(x.b)
530
+ );
531
+ return Math.sinh(x)
532
+ },
533
+ ...x
534
+ );
535
+ const tanh = (...x) => mapfun(
536
+ x =>{
537
+ if(x?.isComplex){
538
+ const D = Math.cosh(2*a) + Math.cos(2*b);
539
+ return new x.constructor(
540
+ Math.sinh(2*a) / D,
541
+ Math.sin(2*b) / D
542
+ )
543
+ }
544
+ return Math.tanh(x)
545
+ },
546
+ ...x
547
+ );
548
+
549
+ const coth = (...x) => mapfun(
550
+ x =>{
551
+ if(x?.isComplex){
552
+ const {a, b} = x;
553
+ const D = (Math.sinh(a)**2)*(Math.cos(b)**2) + (Math.cosh(a)**2)*(Math.sin(b)**2);
554
+ return new x.constructor(
555
+ Math.cosh(a) * Math.sinh(a) / D,
556
+ - Math.sin(b) * Math.cos(b) / D
557
+ )
558
+ }
559
+ return 1/Math.tanh(x)
560
+ },
561
+ ...x
562
+ );
563
+
564
+ const acosh = (...x) => mapfun(
565
+ x =>{
566
+ if(x?.isComplex){
567
+ return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).sub(1))))
568
+ }
569
+ return Math.acosh(x)
570
+ },
571
+ ...x
572
+ );
573
+
574
+ const asinh = (...x) => mapfun(
575
+ x =>{
576
+ if(x?.isComplex){
577
+ return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).add(1))))
578
+ }
579
+ return Math.asinh(x)
580
+ },
581
+ ...x
582
+ );
583
+
584
+ const atanh = (...x) => mapfun(
585
+ x =>{
586
+ if(x?.isComplex);
587
+ return Math.atanh(x)
588
+ },
589
+ ...x
590
+ );
591
+
592
+ const sig = (...x) => mapfun(
593
+ x =>{
594
+ if(x?.isComplex);
595
+ return 1/(1+Math.exp(-x))
596
+ },
597
+ ...x
598
+ );
599
+
600
+ const _add = (x, y) =>{
601
+ if(typeof x === 'number'){
602
+ if(typeof y === 'number') return x + y;
603
+ if(y.isComplex?.()) {
604
+ return y.clone().add(x);
605
+ }
606
+ }
607
+ if(x.isComplex?.()){
608
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().add(y);
609
+ }
610
+ };
611
+
612
+ const _sub = (x, y) =>{
613
+ if(typeof x === 'number'){
614
+ if(typeof y === 'number') return x - y;
615
+ if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
616
+ }
617
+ if(x.isComplex?.()){
618
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().sub(y);
619
+ }
620
+ };
621
+
622
+ const _mul = (x, y) =>{
623
+ if(typeof x === 'number'){
624
+ if(typeof y === 'number') return x * y;
625
+ if(y.isComplex?.()) return y.clone().mul(x);
626
+ }
627
+ if(x.isComplex?.()){
628
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
629
+ }
630
+ };
631
+
632
+ const _div = (x, y) =>{
633
+ if(typeof x === 'number'){
634
+ if(typeof y === 'number') return x / y;
635
+ if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
636
+ }
637
+ if(x.isComplex?.()){
638
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
639
+ }
640
+ };
641
+
642
+ const _modulo = (x, y) =>{
643
+ if(typeof x === 'number'){
644
+ if(typeof y === 'number') return x % y;
645
+ if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
646
+ }
647
+ if(x.isComplex?.()){
648
+ if(typeof y === 'number' || y.isComplex?.()) return new x.clone().modulo(y);
649
+ }
650
+ };
651
+
652
+ const add=(a,...b)=>{
653
+ let res = a;
654
+ for(let i=0; i<b.length; i++)
655
+ res = _add(res, b[i]);
656
+ return res;
657
+ };
658
+ const sub=(a,...b)=>{
659
+ let res = a;
660
+ for(let i=0; i<b.length; i++)
661
+ res = _sub(res, b[i]);
662
+ return res;
663
+ };
664
+ const mul=(a,...b)=>{
665
+ let res = a;
666
+ for(let i=0; i<b.length; i++)
667
+ res = _mul(res, b[i]);
668
+ return res;
669
+ };
670
+ const div=(a,...b)=>{
671
+ let res = a;
672
+ for(let i=0; i<b.length; i++)
673
+ res = _div(res, b[i]);
674
+ return res;
675
+ };
676
+ const modulo=(a,...b)=>{
677
+ let res = a;
678
+ for(let i=0; i<b.length; i++)
679
+ res = _modulo(res, b[i]);
680
+ return res;
681
+ };
682
+
683
+ const min$1 = (...x) => Math.min(...x);
684
+ const max$1 = (...x) => Math.max(...x);
685
+
686
+ const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
687
+ const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
688
+
689
+ const norm = (x, min, max) => apply_fun(
690
+ x,
691
+ v => min !== max ? (v - min) / (max - min) : 0
692
+ );
693
+ const lerp = (x, min, max) => apply_fun(
694
+ x,
695
+ v => (max - min) * v + min
696
+ );
697
+ const clamp = (x, min, max) => apply_fun(
698
+ x,
699
+ v => Math.min(Math.max(v, min), max)
700
+ );
701
+ const map$1 = (x, a, b, c, d) => apply_fun(
702
+ x,
703
+ v => lerp(norm(v, a, b), c, d)
704
+ );
705
+
706
+
707
+ // export const norm = (x, min, max) => {
708
+ // if(x.isComplex?.()) return new x.constructor(
709
+ // norm(x.a, min, max),
710
+ // norm(x.b, min, max)
711
+ // )
712
+ // if(x.isMatrix?.()) return new x.constructor(
713
+ // x.rows,
714
+ // x.cols,
715
+ // norm(x.arr.flat(1), min, max)
716
+ // );
717
+ // if(x instanceof Array) return mapfun(n => norm(n, min, max), ...x);
718
+ // return min !== max ? (x - min) / (max - min) : 0;
719
+ // }
720
+
721
+
722
+ // export const lerp = (x, min, max) => {
723
+ // if(x.isComplex?.()) return new x.constructor(
724
+ // lerp(x.a, min, max),
725
+ // lerp(x.b, min, max)
726
+ // )
727
+ // if(x.isMatrix?.()) return new x.constructor(
728
+ // x.rows,
729
+ // x.cols,
730
+ // lerp(x.arr.flat(1), min, max)
731
+ // );
732
+ // if(x instanceof Array) return mapfun(n => lerp(n, min, max), ...x);
733
+ // return (max - min) * x + min;
734
+ // }
735
+
736
+ // export const map = (x, a, b, c, d) => {
737
+ // if(x.isComplex?.()) return new x.constructor(
738
+ // map(x.a, a, b, c, d),
739
+ // map(x.b, a, b, c, d)
740
+ // )
741
+ // if(x.isMatrix?.()) return new x.constructor(
742
+ // x.rows,
743
+ // x.cols,
744
+ // map(x.arr.flat(1), a, b, c, d)
745
+ // );
746
+ // if(x instanceof Array) return mapfun(n => map(n, a, b, c, d), ...x);
747
+ // return lerp(norm(x, a, b), c, d);
748
+ // }
749
+
750
+ // export const clamp = (x, min, max) => {
751
+ // if(x.isComplex?.()) return new x.constructor(
752
+ // clamp(x.a, min, max),
753
+ // clamp(x.b, min, max)
754
+ // )
755
+ // if(x.isMatrix?.()) return new x.constructor(
756
+ // x.rows,
757
+ // x.cols,
758
+ // clamp(x.arr.flat(1), min, max)
759
+ // );
760
+ // if(x instanceof Array) return mapfun(n => clamp(n, min, max), ...x);
761
+ // return Math.min(Math.max(x, min), max)
762
+ // }
763
+
764
+ const hypot = (...x) => {
765
+ const c0 = x.find(a => a.isComplex?.());
766
+ if (c0) {
767
+ const W = x.map(n => n.isComplex?.() ? n : new c0.constructor(n, 0));
768
+ return Math.hypot(...W.map(c => c.z));
769
+ }
770
+ return Math.hypot(...x);
771
+ };
772
+
773
+
774
+ const atan2 = (y, x, rad = true) => {
775
+ if (y instanceof Array && !(x instanceof Array))
776
+ return mapfun(n => atan2(n, x, rad), ...y);
777
+
778
+ if (x instanceof Array && !(y instanceof Array))
779
+ return mapfun(n => atan2(y, n, rad), ...x);
780
+
781
+ if (y instanceof Array && x instanceof Array)
782
+ return y.map((v, i) => atan2(v, x[i], rad));
783
+
784
+ const phi = Math.atan2(y, x);
785
+ return rad ? phi : phi * 180 / Math.PI;
786
+ };
787
+
899
788
  const preload=(url)=>{
900
789
  const xhr = new XMLHttpRequest();
901
790
  xhr.open("GET", url, false);
@@ -1525,9 +1414,9 @@ function unmount(delay = 0) {
1525
1414
  }
1526
1415
 
1527
1416
  var LifecycleMethods = /*#__PURE__*/Object.freeze({
1528
- __proto__: null,
1529
- mount: mount,
1530
- unmount: unmount
1417
+ __proto__: null,
1418
+ mount: mount,
1419
+ unmount: unmount
1531
1420
  });
1532
1421
 
1533
1422
  if(!globalThis.__Ziko__) __init__global__();
@@ -1694,11 +1583,11 @@ function setContentEditable(bool = true) {
1694
1583
  }
1695
1584
 
1696
1585
  var AttrsMethods = /*#__PURE__*/Object.freeze({
1697
- __proto__: null,
1698
- getAttr: getAttr,
1699
- removeAttr: removeAttr,
1700
- setAttr: setAttr,
1701
- setContentEditable: setContentEditable
1586
+ __proto__: null,
1587
+ getAttr: getAttr,
1588
+ removeAttr: removeAttr,
1589
+ setAttr: setAttr,
1590
+ setContentEditable: setContentEditable
1702
1591
  });
1703
1592
 
1704
1593
  function append(...ele) {
@@ -1755,15 +1644,15 @@ function before(ui){
1755
1644
  }
1756
1645
 
1757
1646
  var DomMethods = /*#__PURE__*/Object.freeze({
1758
- __proto__: null,
1759
- after: after,
1760
- append: append,
1761
- before: before,
1762
- clear: clear,
1763
- insertAt: insertAt,
1764
- prepend: prepend,
1765
- remove: remove,
1766
- replaceElementWith: replaceElementWith
1647
+ __proto__: null,
1648
+ after: after,
1649
+ append: append,
1650
+ before: before,
1651
+ clear: clear,
1652
+ insertAt: insertAt,
1653
+ prepend: prepend,
1654
+ remove: remove,
1655
+ replaceElementWith: replaceElementWith
1767
1656
  });
1768
1657
 
1769
1658
  const EventsMap = {
@@ -2477,11 +2366,11 @@ function find(condition) {
2477
2366
  }
2478
2367
 
2479
2368
  var IndexingMethods = /*#__PURE__*/Object.freeze({
2480
- __proto__: null,
2481
- at: at,
2482
- find: find,
2483
- forEach: forEach,
2484
- map: map
2369
+ __proto__: null,
2370
+ at: at,
2371
+ find: find,
2372
+ forEach: forEach,
2373
+ map: map
2485
2374
  });
2486
2375
 
2487
2376
  function style(styles){
@@ -2518,12 +2407,12 @@ function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
2518
2407
  }
2519
2408
 
2520
2409
  var StyleMethods = /*#__PURE__*/Object.freeze({
2521
- __proto__: null,
2522
- animate: animate,
2523
- hide: hide,
2524
- show: show,
2525
- size: size,
2526
- style: style
2410
+ __proto__: null,
2411
+ animate: animate,
2412
+ hide: hide,
2413
+ show: show,
2414
+ size: size,
2415
+ style: style
2527
2416
  });
2528
2417
 
2529
2418
  // import {
@@ -3197,7 +3086,7 @@ const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).mount(render);
3197
3086
  // };
3198
3087
 
3199
3088
  const obj2str=(obj)=>JSON.stringify(
3200
- mapfun$1(n=>{
3089
+ mapfun(n=>{
3201
3090
  if(["number","string","boolean","bigint"].includes(typeof n)) return String(n);
3202
3091
  if(n instanceof Complex || n instanceof Matrix) return n.toString();
3203
3092
  if(n instanceof Array) return arr2str(n)
@@ -3983,6 +3872,277 @@ const powerSet=originalSet=>{
3983
3872
  return subSets;
3984
3873
  };
3985
3874
 
3875
+ const zeros=(n)=>new Array(n).fill(0);
3876
+ const ones=(n)=>new Array(n).fill(1);
3877
+ const nums=(num,n)=>new Array(n).fill(num);
3878
+
3879
+ const arange=(a, b, step , include = false)=>{
3880
+ let tab = [];
3881
+ if(a<b){
3882
+ for (let i = a; include?i<=b:i<b; i += step) tab.push((i * 10) / 10);
3883
+ }
3884
+ else {
3885
+ for(let i = a; include?i>=b:i>b; i -= step) tab.push((i * 10) / 10);
3886
+ }
3887
+ return tab;
3888
+ };
3889
+ const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
3890
+ if(Math.floor(n)!==n)return;
3891
+ if([a,b].every(n=>typeof n==="number")){
3892
+ const [max,min]=[a,b].sort((a,b)=>b-a);
3893
+ var Y = [];
3894
+ let step ;
3895
+ endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
3896
+ for (var i = 0; i < n; i++) {
3897
+ a<b?Y.push(min+step*i):Y.push(max-step*i);
3898
+ }
3899
+ return Y
3900
+ }
3901
+
3902
+ if([a,b].some(n=>n.isComplex?.())){
3903
+ const z1 = new n.constructor(a);
3904
+ const z2 = new n.constructor(b);
3905
+ n=n||Math.abs(z1.a-z2.a)+1;
3906
+ const X=linspace(z1.a,z2.a,n,endpoint);
3907
+ const Y=linspace(z1.b,z2.b,n,endpoint);
3908
+ let Z=new Array(n).fill(null);
3909
+ Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
3910
+ return Z;
3911
+ }
3912
+ };
3913
+ const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
3914
+ return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
3915
+ };
3916
+ const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
3917
+ if(Math.floor(n)!==n)return;
3918
+ if([a,b].every(n=>typeof n==="number")){
3919
+ const [max,min]=[a,b].sort((a,b)=>b-a);
3920
+ let base;
3921
+ endpoint ? base = nthr(max/min,n-1) : base = nthr(max/min,n) ;
3922
+ const Y = [min];
3923
+ for (let i = 1; i < n; i++) {
3924
+ Y.push(Y[i-1]*base);
3925
+ }
3926
+ return a<b?Y:Y.reverse()
3927
+ }
3928
+
3929
+ if([a,b].some(n=>n.isComplex?.())){
3930
+ const z1 = new n.constructor(a);
3931
+ const z2 = new n.constructor(b);
3932
+ n=n||Math.abs(z1.a-z2.a)+1;
3933
+ let base;
3934
+ endpoint ? base = nthr(z2.div(z1),n-1) : base = nthr(z2.div(z1),n) ;
3935
+ const Y = [z1];
3936
+ for (let i = 1; i < n; i++) {
3937
+ Y.push(mul(Y[i-1],base));
3938
+ }
3939
+ return Y;
3940
+ }
3941
+ };
3942
+
3943
+ // Mixed calcul
3944
+ const sum=(...x)=>{
3945
+ if(x.every(n=>typeof n==="number")){
3946
+ let s = x[0];
3947
+ for (let i = 1; i < x.length; i++) s += x[i];
3948
+ return s;
3949
+ }
3950
+ const Y=[];
3951
+ for(let i=0;i<x.length;i++){
3952
+ if(x[i] instanceof Array)Y.push(sum(...x[i]));
3953
+ else if(x[i] instanceof Object){
3954
+ Y.push(sum(...Object.values(x[i])));
3955
+ }
3956
+ }
3957
+ return Y.length===1?Y[0]:Y;
3958
+ };
3959
+ const prod=(...x)=>{
3960
+ if(x.every(n=>typeof n==="number")){
3961
+ let p = x[0];
3962
+ for (let i = 1; i < x.length; i++) p *= x[i];
3963
+ return p;
3964
+ }
3965
+ const Y=[];
3966
+ for(let i=0;i<x.length;i++){
3967
+ if(x[i] instanceof Array)Y.push(prod(...x[i]));
3968
+ else if(x[i] instanceof Object){
3969
+ Y.push(prod(...Object.values(x[i])));
3970
+ }
3971
+ }
3972
+ return Y.length===1?Y[0]:Y;
3973
+ };
3974
+ // const min=(...num)=>{
3975
+ // if(num.every(n=>typeof n==="number"))return Math.min(...num);
3976
+ // const Y=[];
3977
+ // for(let i=0;i<num.length;i++){
3978
+ // if(num[i] instanceof Array)Y.push(min(...num[i]));
3979
+ // else if(num[i] instanceof Object){
3980
+ // Y.push(
3981
+ // Object.fromEntries(
3982
+ // [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
3983
+ // )
3984
+ // )
3985
+ // }
3986
+ // }
3987
+ // return Y.length===1?Y[0]:Y;
3988
+ // }
3989
+ // const max=(...num)=>{
3990
+ // if(num.every(n=>typeof n==="number"))return Math.max(...num);
3991
+ // const Y=[];
3992
+ // for(let i=0;i<num.length;i++){
3993
+ // if(num[i] instanceof Array)Y.push(min(...num[i]));
3994
+ // else if(num[i] instanceof Object){
3995
+ // Y.push(
3996
+ // Object.fromEntries(
3997
+ // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
3998
+ // )
3999
+ // )
4000
+ // }
4001
+ // }
4002
+ // return Y.length===1?Y[0]:Y;
4003
+ // }
4004
+ const accum=(...num)=>{
4005
+ if(num.every(n=>typeof n==="number")){
4006
+ let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
4007
+ acc.shift();
4008
+ return acc;
4009
+ }
4010
+ const Y=[];
4011
+ for(let i=0;i<num.length;i++){
4012
+ if(num[i] instanceof Array)Y.push(accum(...num[i]));
4013
+ else if(num[i] instanceof Object){
4014
+ Y.push(null
4015
+ // Object.fromEntries(
4016
+ // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
4017
+ // )
4018
+ );
4019
+ }
4020
+ }
4021
+ return Y.length===1?Y[0]:Y;
4022
+ };
4023
+
4024
+ //moy
4025
+ //med
4026
+ //variance
4027
+ //std
4028
+ //mode
4029
+ //acccum
4030
+ //min2max
4031
+ //max2min
4032
+ //percentile
4033
+
4034
+ /** @module Math */
4035
+ /**
4036
+ * Checks if a value is within the specified range.
4037
+ * @function
4038
+ * @param {number} x - The value to check.
4039
+ * @param {number} a - The start of the range.
4040
+ * @param {number} b - The end of the range.
4041
+ * @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
4042
+ */
4043
+ const inRange = (x, a, b) => {
4044
+ const [min, max] = [Math.min(a, b), Math.max(a, b)];
4045
+ return x >= min && x <= max;
4046
+ };
4047
+
4048
+ /**
4049
+ * Checks if two numbers are approximately equal within a given error margin.
4050
+ * @param {number} a - The first number.
4051
+ * @param {number} b - The second number.
4052
+ * @param {number} [Err=0.0001] - The maximum acceptable difference between the two numbers.
4053
+ * @returns {boolean} Returns true if the two numbers are approximately equal within the specified error margin, otherwise false.
4054
+ */
4055
+ const isApproximatlyEqual = (a, b, Err = 0.0001) => {
4056
+ return Math.abs(a - b) <= Err;
4057
+ };
4058
+
4059
+ /** @module Math */
4060
+
4061
+ /**
4062
+ * Computes the cartesian product of two arrays.
4063
+ * @param {Array} a - The first array.
4064
+ * @param {Array} b - The second array.
4065
+ * @returns {Array} Returns an array representing the cartesian product of the input arrays.
4066
+ */
4067
+ const cartesianProduct = (a, b) => a.reduce((p, x) => [...p, ...b.map((y) => [x, y])], []);
4068
+
4069
+ /**
4070
+ * Computes the greatest common divisor (GCD) of two numbers.
4071
+ * @param {number} n1 - The first number.
4072
+ * @param {number} n2 - The second number.
4073
+ * @returns {number} Returns the greatest common divisor of the two input numbers.
4074
+ */
4075
+ const pgcd = (n1, n2) => {
4076
+ let i,
4077
+ pgcd = 1;
4078
+ if (n1 == floor(n1) && n2 == floor(n2)) {
4079
+ for (i = 2; i <= n1 && i <= n2; ++i) {
4080
+ if (n1 % i == 0 && n2 % i == 0) pgcd = i;
4081
+ }
4082
+ return pgcd;
4083
+ } else console.log("error");
4084
+ };
4085
+
4086
+ /**
4087
+ * Computes the least common multiple (LCM) of two numbers.
4088
+ * @param {number} n1 - The first number.
4089
+ * @param {number} n2 - The second number.
4090
+ * @returns {number} Returns the least common multiple of the two input numbers.
4091
+ */
4092
+ const ppcm = (n1, n2) => {
4093
+ let ppcm;
4094
+ if (n1 == floor(n1) && n2 == floor(n2)) {
4095
+ ppcm = n1 > n2 ? n1 : n2;
4096
+ while (true) {
4097
+ if (ppcm % n1 == 0 && ppcm % n2 == 0) break;
4098
+ ++ppcm;
4099
+ }
4100
+ return ppcm;
4101
+ } else console.log("error");
4102
+ };
4103
+
4104
+ // import { mapfun } from "../mapfun/index.js";
4105
+ // import {
4106
+ // add,
4107
+ // sub,
4108
+ // mul,
4109
+ // div,
4110
+ // modulo
4111
+ // } from "./arithmetic.js";
4112
+ const Utils={
4113
+ // add,
4114
+ // sub,
4115
+ // mul,
4116
+ // div,
4117
+ // modulo,
4118
+
4119
+ zeros,
4120
+ ones,
4121
+ nums,
4122
+ // norm,
4123
+ // lerp,
4124
+ // map,
4125
+ // clamp,
4126
+ arange,
4127
+ linspace,
4128
+ logspace,
4129
+ geomspace,
4130
+
4131
+ sum,
4132
+ prod,
4133
+ accum,
4134
+
4135
+ cartesianProduct,
4136
+ ppcm,
4137
+ pgcd,
4138
+
4139
+ // deg2rad,
4140
+ // rad2deg,
4141
+
4142
+ inRange,
4143
+ isApproximatlyEqual
4144
+ };
4145
+
3986
4146
  // const subSet = (...arr) => {
3987
4147
  // let list = arange(0, 2 ** arr.length, 1);
3988
4148
  // let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
@@ -4346,14 +4506,14 @@ class Random {
4346
4506
  // }
4347
4507
  }
4348
4508
 
4349
- const { PI, sqrt: sqrt$1, cos: cos$1, sin: sin$1, acos, pow } = Math;
4509
+ const { PI, sqrt: sqrt$1, cos: cos$2, sin: sin$2, acos, pow } = Math;
4350
4510
 
4351
4511
  const linear = t => t;
4352
4512
 
4353
4513
  // --- Sin ---
4354
- const in_sin = t => 1 - cos$1((t * PI) / 2);
4355
- const out_sin = t => sin$1((t * PI) / 2);
4356
- const in_out_sin = t => -(cos$1(PI * t) - 1) / 2;
4514
+ const in_sin = t => 1 - cos$2((t * PI) / 2);
4515
+ const out_sin = t => sin$2((t * PI) / 2);
4516
+ const in_out_sin = t => -(cos$2(PI * t) - 1) / 2;
4357
4517
 
4358
4518
  // --- Quad ---
4359
4519
  const in_quad = t => t ** 2;
@@ -4400,14 +4560,14 @@ const in_out_circ = t =>
4400
4560
  : (sqrt$1(1 - (-2 * t + 2) ** 2) + 1) / 2;
4401
4561
 
4402
4562
  // --- Arc ---
4403
- const arc = t => 1 - sin$1(acos(t));
4563
+ const arc = t => 1 - sin$2(acos(t));
4404
4564
 
4405
4565
  // --- Back ---
4406
4566
  const back = (t, x = 1) => (t ** 2) * ((x + 1) * t - x);
4407
4567
 
4408
4568
  // --- Elastic ---
4409
4569
  const elastic = t =>
4410
- -2 * pow(2, 10 * (t - 1)) * cos$1((20 * PI * t) / 3 * t);
4570
+ -2 * pow(2, 10 * (t - 1)) * cos$2((20 * PI * t) / 3 * t);
4411
4571
 
4412
4572
  // --- Back variations ---
4413
4573
  const in_back = (t, c1 = 1.70158, c3 = c1 + 1) =>
@@ -4427,14 +4587,14 @@ const in_elastic = (t, c4 = (2 * PI) / 3) =>
4427
4587
  ? 0
4428
4588
  : t === 1
4429
4589
  ? 1
4430
- : -pow(2, 10 * t - 10) * sin$1((t * 10 - 10.75) * c4);
4590
+ : -pow(2, 10 * t - 10) * sin$2((t * 10 - 10.75) * c4);
4431
4591
 
4432
4592
  const out_elastic = (t, c4 = (2 * PI) / 3) =>
4433
4593
  t === 0
4434
4594
  ? 0
4435
4595
  : t === 1
4436
4596
  ? 1
4437
- : pow(2, -10 * t) * sin$1((t * 10 - 0.75) * c4) + 1;
4597
+ : pow(2, -10 * t) * sin$2((t * 10 - 0.75) * c4) + 1;
4438
4598
 
4439
4599
  const in_out_elastic = (t, c5 = (2 * PI) / 4.5) =>
4440
4600
  t === 0
@@ -4442,8 +4602,8 @@ const in_out_elastic = (t, c5 = (2 * PI) / 4.5) =>
4442
4602
  : t === 1
4443
4603
  ? 1
4444
4604
  : t < 0.5
4445
- ? -(pow(2, 20 * t - 10) * sin$1((20 * t - 11.125) * c5)) / 2
4446
- : (pow(2, -20 * t + 10) * sin$1((20 * t - 11.125) * c5)) / 2 + 1;
4605
+ ? -(pow(2, 20 * t - 10) * sin$2((20 * t - 11.125) * c5)) / 2
4606
+ : (pow(2, -20 * t + 10) * sin$2((20 * t - 11.125) * c5)) / 2 + 1;
4447
4607
 
4448
4608
  // --- Bounce ---
4449
4609
  const in_bounce = (t, n1 = 7.5625, d1 = 2.75) =>
@@ -5140,7 +5300,7 @@ function useDerived(deriveFn, sources) {
5140
5300
  })
5141
5301
  }
5142
5302
 
5143
- const useReactive = (nested_value) => mapfun$1(
5303
+ const useReactive = (nested_value) => mapfun(
5144
5304
  n => {
5145
5305
  const state = useState(n);
5146
5306
  return {
@@ -5439,7 +5599,7 @@ tags.p("Test useRoot ").style({
5439
5599
 
5440
5600
  */
5441
5601
 
5442
- let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
5602
+ let {sqrt, cos: cos$1, sin: sin$1, exp, log, cosh: cosh$1, sinh} = Math;
5443
5603
  // Math.abs = new Proxy(Math.abs, {
5444
5604
  // apply(target, thisArg, args) {
5445
5605
  // const x = args[0]
@@ -5470,20 +5630,20 @@ for (const key of Object.getOwnPropertyNames(Math)) {
5470
5630
  const complex = (a, b) => new x.constructor(a, b);
5471
5631
  switch(target.name){
5472
5632
  case 'abs' : return x.z;
5473
- case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
5633
+ case 'sqrt' : return complex(sqrt(z)*cos$1(phi/2),sqrt(z)*sin$1(phi/2));
5474
5634
  case 'log' : return complex(log(z), phi);
5475
- case 'exp' : return complex(exp(a)*cos(b),exp(a)*sin(b));
5476
- case 'cos' : return complex(cos(a)*cosh(b),-(sin(a)*sinh(b)));
5477
- case 'sin' : return complex(sin(a)*cosh(b),cos(a)*sinh(b));
5635
+ case 'exp' : return complex(exp(a)*cos$1(b),exp(a)*sin$1(b));
5636
+ case 'cos' : return complex(cos$1(a)*cosh$1(b),-(sin$1(a)*sinh(b)));
5637
+ case 'sin' : return complex(sin$1(a)*cosh$1(b),cos$1(a)*sinh(b));
5478
5638
  case 'tan' : {
5479
- const DEN = cos(2*a)+cosh(2*b);
5480
- return complex(sin(2*a) /DEN, sinh(2*b)/DEN);
5639
+ const DEN = cos$1(2*a)+cosh$1(2*b);
5640
+ return complex(sin$1(2*a) /DEN, sinh(2*b)/DEN);
5481
5641
  }
5482
- case 'cosh' : return complex(cosh(a)*cos(b),sinh(a)*sin(b));
5483
- case 'sinh' : return complex(sinh(a)*cos(b),cosh(a)*sin(b));
5642
+ case 'cosh' : return complex(cosh$1(a)*cos$1(b),sinh(a)*sin$1(b));
5643
+ case 'sinh' : return complex(sinh(a)*cos$1(b),cosh$1(a)*sin$1(b));
5484
5644
  case 'tanh' : {
5485
- const DEN=cosh(2*a)+cos(2*b);
5486
- return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
5645
+ const DEN=cosh$1(2*a)+cos$1(2*b);
5646
+ return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
5487
5647
  }
5488
5648
  default : return target.apply(thisArg, args)
5489
5649
  }
@@ -5514,7 +5674,7 @@ exports.Flex = Flex;
5514
5674
  exports.HTMLWrapper = HTMLWrapper;
5515
5675
  exports.Logic = Logic$1;
5516
5676
  exports.Matrix = Matrix;
5517
- exports.PI = PI$2;
5677
+ exports.PI = PI$1;
5518
5678
  exports.Permutation = Permutation;
5519
5679
  exports.Random = Random;
5520
5680
  exports.SPA = SPA;
@@ -5549,6 +5709,7 @@ exports.acosh = acosh;
5549
5709
  exports.acot = acot;
5550
5710
  exports.add = add;
5551
5711
  exports.animation = animation;
5712
+ exports.apply_fun = apply_fun;
5552
5713
  exports.arange = arange;
5553
5714
  exports.arc = arc;
5554
5715
  exports.arr2str = arr2str;
@@ -5570,16 +5731,16 @@ exports.bind_touch_event = bind_touch_event;
5570
5731
  exports.bind_view_event = bind_view_event;
5571
5732
  exports.bind_wheel_event = bind_wheel_event;
5572
5733
  exports.cartesianProduct = cartesianProduct;
5734
+ exports.cbrt = cbrt;
5573
5735
  exports.ceil = ceil;
5574
5736
  exports.clamp = clamp;
5575
5737
  exports.clock = clock;
5576
5738
  exports.combinaison = combinaison;
5577
5739
  exports.complex = complex;
5578
- exports.cos = cos$2;
5579
- exports.cosh = cosh$1;
5580
- exports.cot = cot;
5740
+ exports.cos = cos$3;
5741
+ exports.cosh = cosh$2;
5581
5742
  exports.coth = coth;
5582
- exports.csc = csc;
5743
+ exports.croot = croot;
5583
5744
  exports.csv2arr = csv2arr;
5584
5745
  exports.csv2json = csv2json;
5585
5746
  exports.csv2matrix = csv2matrix;
@@ -5591,11 +5752,11 @@ exports.define_wc = define_wc;
5591
5752
  exports.deg2rad = deg2rad;
5592
5753
  exports.discret = discret;
5593
5754
  exports.div = div;
5594
- exports.e = e;
5595
5755
  exports.elastic = elastic;
5596
5756
  exports.event_controller = event_controller;
5597
- exports.fact = fact;
5757
+ exports.exp = exp$1;
5598
5758
  exports.floor = floor;
5759
+ exports.fract = fract;
5599
5760
  exports.geomspace = geomspace;
5600
5761
  exports.getEvent = getEvent;
5601
5762
  exports.hypot = hypot;
@@ -5637,16 +5798,17 @@ exports.ln = ln;
5637
5798
  exports.logspace = logspace;
5638
5799
  exports.loop = loop;
5639
5800
  exports.map = map$1;
5640
- exports.mapfun = mapfun$1;
5801
+ exports.mapfun = mapfun;
5641
5802
  exports.matrix = matrix;
5642
5803
  exports.matrix2 = matrix2;
5643
5804
  exports.matrix3 = matrix3;
5644
5805
  exports.matrix4 = matrix4;
5645
- exports.max = max;
5646
- exports.min = min;
5806
+ exports.max = max$1;
5807
+ exports.min = min$1;
5647
5808
  exports.modulo = modulo;
5648
5809
  exports.mul = mul;
5649
5810
  exports.norm = norm;
5811
+ exports.nthr = nthr;
5650
5812
  exports.nums = nums;
5651
5813
  exports.obj2str = obj2str;
5652
5814
  exports.ones = ones;
@@ -5671,12 +5833,10 @@ exports.round = round;
5671
5833
  exports.sec = sec;
5672
5834
  exports.sig = sig;
5673
5835
  exports.sign = sign;
5674
- exports.sin = sin$2;
5675
- exports.sinc = sinc;
5836
+ exports.sin = sin$3;
5676
5837
  exports.sinh = sinh$1;
5677
5838
  exports.sleep = sleep;
5678
5839
  exports.sqrt = sqrt$2;
5679
- exports.sqrtn = sqrtn;
5680
5840
  exports.step = step;
5681
5841
  exports.step_fps = step_fps;
5682
5842
  exports.sub = sub;
@@ -5696,6 +5856,7 @@ exports.timeTaken = timeTaken;
5696
5856
  exports.time_memory_Taken = time_memory_Taken;
5697
5857
  exports.timeout = timeout;
5698
5858
  exports.toggle_event_listener = toggle_event_listener;
5859
+ exports.trunc = trunc;
5699
5860
  exports.useDerived = useDerived;
5700
5861
  exports.useEventEmitter = useEventEmitter;
5701
5862
  exports.useIPC = useIPC;