ziko 0.53.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.js +5582 -5450
- package/dist/ziko.mjs +939 -807
- package/package.json +1 -1
- package/src/math/complex/index.js +76 -82
- package/src/math/functions/arithmetic/index.js +82 -0
- package/src/math/functions/index.js +39 -153
- package/src/math/{mapfun → functions/mapfun}/index.js +1 -1
- package/src/math/functions/{primitives → nested}/index.js +37 -21
- package/src/math/functions/utils/index.js +65 -0
- package/src/math/matrix/helpers/det.js +1 -1
- package/src/math/matrix/matrix.js +9 -14
- package/src/math/signal/functions.js +9 -69
- package/src/math/stats/accum/index.js +39 -0
- package/src/math/stats/average/index.js +75 -0
- package/src/math/stats/index.js +17 -0
- package/src/math/stats/position/index.js +21 -0
- package/src/math/stats/rolling/index.js +34 -0
- package/src/math/stats/variability/index.js +37 -0
- package/src/math/utils/arithmetic.js +1 -1
- package/src/math/utils/index.js +39 -39
- package/src/time/animation/index.js +1 -1
- package/types/math/complex/index.d.ts +2 -1
package/dist/ziko.mjs
CHANGED
|
@@ -2,696 +2,38 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Sun Dec 07 2025 00:00:39 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$
|
|
11
|
+
const { PI: PI$1, E } = Math;
|
|
12
12
|
const EPSILON=Number.EPSILON;
|
|
13
13
|
|
|
14
|
-
const
|
|
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
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
geomspace,
|
|
679
|
-
|
|
680
|
-
sum,
|
|
681
|
-
prod,
|
|
682
|
-
accum,
|
|
683
|
-
|
|
684
|
-
cartesianProduct,
|
|
685
|
-
ppcm,
|
|
686
|
-
pgcd,
|
|
687
|
-
|
|
688
|
-
deg2rad,
|
|
689
|
-
rad2deg,
|
|
690
|
-
|
|
691
|
-
inRange,
|
|
692
|
-
isApproximatlyEqual
|
|
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;
|
|
693
33
|
};
|
|
694
34
|
|
|
35
|
+
// import {sum,prod,deg2rad} from "../utils/index.js";
|
|
36
|
+
// Should avoid CD
|
|
695
37
|
class Complex{
|
|
696
38
|
constructor(a = 0, b = 0) {
|
|
697
39
|
if(a instanceof Complex){
|
|
@@ -700,33 +42,33 @@ class Complex{
|
|
|
700
42
|
}
|
|
701
43
|
else if(typeof(a)==="object"){
|
|
702
44
|
if(("a" in a && "b" in a)){
|
|
703
|
-
this.a=a.a;
|
|
704
|
-
this.b=a.b;
|
|
45
|
+
this.a = a.a;
|
|
46
|
+
this.b = a.b;
|
|
705
47
|
}
|
|
706
48
|
else if(("a" in a && "z" in a)){
|
|
707
|
-
this.a=a.a;
|
|
708
|
-
this.b=sqrt
|
|
49
|
+
this.a = a.a;
|
|
50
|
+
this.b = Math.sqrt((a.z**2)-(a.a**2));
|
|
709
51
|
}
|
|
710
52
|
else if(("a" in a && "phi" in a)){
|
|
711
|
-
this.a=a.a;
|
|
712
|
-
this.b=a.a*tan(a.phi);
|
|
53
|
+
this.a = a.a;
|
|
54
|
+
this.b = a.a * Math.tan(a.phi);
|
|
713
55
|
}
|
|
714
56
|
else if(("b" in a && "z" in a)){
|
|
715
|
-
this.b=a.b;
|
|
716
|
-
this.a=sqrt
|
|
57
|
+
this.b = a.b;
|
|
58
|
+
this.a = Math.sqrt((a.z**2)-(a.b**2));
|
|
717
59
|
}
|
|
718
60
|
else if(("b" in a && "phi" in a)){
|
|
719
|
-
this.b=b;
|
|
720
|
-
this.a=a.b/tan(a.phi);
|
|
61
|
+
this.b = b;
|
|
62
|
+
this.a = a.b / Math.tan(a.phi);
|
|
721
63
|
}
|
|
722
64
|
else if(("z" in a && "phi" in a)){
|
|
723
|
-
this.a = +a.z*cos
|
|
724
|
-
this.b = +a.z*sin
|
|
65
|
+
this.a = + a.z * Math.cos(a.phi).toFixed(15);
|
|
66
|
+
this.b = + a.z * Math.sin(a.phi).toFixed(15);
|
|
725
67
|
}
|
|
726
68
|
}
|
|
727
|
-
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
728
|
-
this.a = +a.toFixed(32);
|
|
729
|
-
this.b = +b.toFixed(32);
|
|
69
|
+
else if(typeof(a)==="number" && typeof(b)==="number"){
|
|
70
|
+
this.a = + a.toFixed(32);
|
|
71
|
+
this.b = + b.toFixed(32);
|
|
730
72
|
}
|
|
731
73
|
}
|
|
732
74
|
get __mapfun__(){
|
|
@@ -748,14 +90,14 @@ class Complex{
|
|
|
748
90
|
return str;
|
|
749
91
|
}
|
|
750
92
|
|
|
751
|
-
|
|
93
|
+
clone() {
|
|
752
94
|
return new Complex(this.a, this.b);
|
|
753
95
|
}
|
|
754
96
|
get z(){
|
|
755
|
-
return hypot(this.a,this.b);
|
|
97
|
+
return Math.hypot(this.a,this.b);
|
|
756
98
|
}
|
|
757
99
|
get phi(){
|
|
758
|
-
return atan2(this.b , this.a);
|
|
100
|
+
return Math.atan2(this.b , this.a);
|
|
759
101
|
}
|
|
760
102
|
static Zero() {
|
|
761
103
|
return new Complex(0, 0);
|
|
@@ -764,102 +106,109 @@ class Complex{
|
|
|
764
106
|
return new Complex(this.a, -this.b);
|
|
765
107
|
}
|
|
766
108
|
get inv() {
|
|
767
|
-
return new Complex(
|
|
109
|
+
return new Complex(
|
|
110
|
+
this.a / Math.hypot(this.a, this.b),
|
|
111
|
+
-this.b / Math.hypot(this.a, this.b)
|
|
112
|
+
);
|
|
768
113
|
}
|
|
769
|
-
add(...
|
|
770
|
-
for (let i = 0; i <
|
|
771
|
-
if (typeof
|
|
114
|
+
add(...c) {
|
|
115
|
+
for (let i = 0; i < c.length; i++) {
|
|
116
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
117
|
+
this.a += c[i].a;
|
|
118
|
+
this.b += c[i].b;
|
|
772
119
|
}
|
|
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
120
|
return this;
|
|
778
121
|
}
|
|
779
|
-
sub(...
|
|
780
|
-
for (let i = 0; i <
|
|
781
|
-
if (typeof
|
|
122
|
+
sub(...c) {
|
|
123
|
+
for (let i = 0; i < c.length; i++) {
|
|
124
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
125
|
+
this.a -= c[i].a;
|
|
126
|
+
this.b -= c[i].b;
|
|
782
127
|
}
|
|
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
128
|
return this;
|
|
788
129
|
}
|
|
789
|
-
mul(...
|
|
790
|
-
|
|
791
|
-
|
|
130
|
+
mul(...c){
|
|
131
|
+
let {z, phi} = this;
|
|
132
|
+
for (let i = 0; i < c.length; i++) {
|
|
133
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
134
|
+
z *= c[i].z;
|
|
135
|
+
phi += c[i].z;
|
|
792
136
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
|
|
796
|
-
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
|
|
137
|
+
this.a = z*Math.cos(phi);
|
|
138
|
+
this.b = z*Math.sin(phi);
|
|
797
139
|
return this;
|
|
798
140
|
}
|
|
799
|
-
div(...
|
|
800
|
-
|
|
801
|
-
|
|
141
|
+
div(...c){
|
|
142
|
+
let {z, phi} = this;
|
|
143
|
+
for (let i = 0; i < c.length; i++) {
|
|
144
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
145
|
+
z /= c[i].z;
|
|
146
|
+
phi -= c[i].z;
|
|
802
147
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
806
|
-
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
148
|
+
this.a = z*Math.cos(phi);
|
|
149
|
+
this.b = z*Math.sin(phi);
|
|
807
150
|
return this;
|
|
808
151
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
this.
|
|
814
|
-
this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
152
|
+
modulo(...c) {
|
|
153
|
+
for (let i = 0; i < c.length; i++) {
|
|
154
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
155
|
+
this.a %= c[i].a;
|
|
156
|
+
this.b %= c[i].b;
|
|
815
157
|
}
|
|
816
158
|
return this;
|
|
817
159
|
}
|
|
818
160
|
static fromExpo(z, phi) {
|
|
819
161
|
return new Complex(
|
|
820
|
-
+(z * cos
|
|
821
|
-
+(z * sin
|
|
162
|
+
+(z * cos(phi)).toFixed(13),
|
|
163
|
+
+(z * sin(phi)).toFixed(13)
|
|
822
164
|
);
|
|
823
165
|
}
|
|
824
166
|
get expo() {
|
|
825
167
|
return [this.z, this.phi];
|
|
826
168
|
}
|
|
827
169
|
static add(c,...z) {
|
|
828
|
-
return c.clone.add(...z);
|
|
170
|
+
return c.clone().add(...z);
|
|
829
171
|
}
|
|
830
172
|
static sub(c,...z) {
|
|
831
|
-
return c.clone.sub(...z);
|
|
173
|
+
return c.clone().sub(...z);
|
|
832
174
|
}
|
|
833
175
|
static mul(c,...z) {
|
|
834
|
-
return c.clone.mul(...z);
|
|
176
|
+
return c.clone().mul(...z);
|
|
835
177
|
}
|
|
836
178
|
static div(c,...z) {
|
|
837
|
-
return c.clone.div(...z);
|
|
838
|
-
}
|
|
839
|
-
static pow(z,n){
|
|
840
|
-
return z.clone.pow(n);
|
|
179
|
+
return c.clone().div(...z);
|
|
841
180
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
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));
|
|
181
|
+
|
|
182
|
+
nthr(n=2){
|
|
183
|
+
return complex({z: this.z ** (1/n), phi: this.phi / n});
|
|
847
184
|
}
|
|
848
185
|
get sqrt(){
|
|
849
|
-
return this.
|
|
186
|
+
return this.nrth(2);
|
|
187
|
+
}
|
|
188
|
+
get cbrt(){
|
|
189
|
+
return this.nrth(3);
|
|
850
190
|
}
|
|
851
191
|
get log(){
|
|
852
|
-
return complex(this.z,this.phi);
|
|
192
|
+
return complex(this.z, this.phi);
|
|
853
193
|
}
|
|
854
194
|
get cos(){
|
|
855
|
-
return complex(
|
|
195
|
+
return complex(
|
|
196
|
+
Math.cos(this.a) * Math.cosh(this.b),
|
|
197
|
+
Math.sin(this.a) * Math.sinh(this.b)
|
|
198
|
+
)
|
|
856
199
|
}
|
|
857
200
|
get sin(){
|
|
858
|
-
return complex(
|
|
201
|
+
return complex(
|
|
202
|
+
Math.sin(this.a) * Math.cosh(this.b),
|
|
203
|
+
Math.cos(this.a) * Math.sinh(this.b)
|
|
204
|
+
)
|
|
859
205
|
}
|
|
860
206
|
get tan(){
|
|
861
|
-
const
|
|
862
|
-
return complex(
|
|
207
|
+
const D=cos(this.a*2)+cosh(this.b*2);
|
|
208
|
+
return complex(
|
|
209
|
+
Math.sin(2 * this.a) / D,
|
|
210
|
+
Math.sinh(2 * this.b) / D
|
|
211
|
+
);
|
|
863
212
|
}
|
|
864
213
|
}
|
|
865
214
|
const complex=(a,b)=>{
|
|
@@ -872,6 +221,518 @@ const complex=(a,b)=>{
|
|
|
872
221
|
return new Complex(a,b)
|
|
873
222
|
};
|
|
874
223
|
|
|
224
|
+
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
225
|
+
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
226
|
+
|
|
227
|
+
const abs = (...x) => mapfun(
|
|
228
|
+
x =>{
|
|
229
|
+
if(x.isComplex?.()) return x.z;
|
|
230
|
+
return Math.abs(x)
|
|
231
|
+
},
|
|
232
|
+
...x
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const pow$1 = (...x) => {
|
|
236
|
+
const n = x.pop();
|
|
237
|
+
return mapfun(
|
|
238
|
+
x => {
|
|
239
|
+
if(x.isComplex?.()) {
|
|
240
|
+
if(n.isComplex?.()) return new x.constructor({
|
|
241
|
+
z: Math.exp(n.a * Math.log(x.z) - n.b * x.phi),
|
|
242
|
+
phi: n.b * Math.log(x.z) + n.a * x.phi
|
|
243
|
+
})
|
|
244
|
+
return new x.constructor({z: x.z ** n, phi: x.phi * n});
|
|
245
|
+
}
|
|
246
|
+
if(n.isComplex?.()) return new x.constructor({
|
|
247
|
+
z: Math.exp(n.a * Math.log(x)),
|
|
248
|
+
phi: n.b * Math.log(x)
|
|
249
|
+
})
|
|
250
|
+
return Math.pow(x, n)
|
|
251
|
+
},
|
|
252
|
+
...x
|
|
253
|
+
)
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const sqrt$2 = (...x) => mapfun(
|
|
257
|
+
x=>{
|
|
258
|
+
if(x.isComplex?.())
|
|
259
|
+
return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
|
|
260
|
+
if(x < 0) return complex(0, Math.sqrt(-x))
|
|
261
|
+
return Math.sqrt(x);
|
|
262
|
+
},
|
|
263
|
+
...x
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const cbrt = (...x) => mapfun(
|
|
267
|
+
x=>{
|
|
268
|
+
if(x.isComplex?.())
|
|
269
|
+
return new x.constructor({z: x.z**(1/3), phi: x.phi/3})
|
|
270
|
+
return Math.cbrt(x);
|
|
271
|
+
},
|
|
272
|
+
...x
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const nthr = (...x) => {
|
|
276
|
+
const n = x.pop();
|
|
277
|
+
if(typeof n !== 'number') throw Error('nthr expects a real number n');
|
|
278
|
+
return mapfun(
|
|
279
|
+
x => {
|
|
280
|
+
if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
|
|
281
|
+
if(x<0) return n%2===2 ? complex(0, (-x)**(1/n)) : -1 * (-x)**(1/n)
|
|
282
|
+
return x**(1/n)
|
|
283
|
+
},
|
|
284
|
+
...x
|
|
285
|
+
)
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const croot = (...x) =>{
|
|
289
|
+
const c = x.pop();
|
|
290
|
+
if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
|
|
291
|
+
return mapfun(
|
|
292
|
+
x => {
|
|
293
|
+
if(typeof x === 'number') x = new c.constructor(x, 0);
|
|
294
|
+
const {a : c_a, b : c_b} = c;
|
|
295
|
+
const {z, phi} = x;
|
|
296
|
+
const D = Math.hypot(c_a, c_b);
|
|
297
|
+
const A = Math.exp((Math.log(z)*c_a + phi*c_b)/D);
|
|
298
|
+
const B = (phi*c_a - Math.log(z)*c_b)/D;
|
|
299
|
+
return new c.constructor(
|
|
300
|
+
A * Math.cos(B),
|
|
301
|
+
A * Math.sin(B)
|
|
302
|
+
)
|
|
303
|
+
},
|
|
304
|
+
...x
|
|
305
|
+
)
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const exp$1 = (...x) => mapfun(
|
|
309
|
+
x => {
|
|
310
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
311
|
+
Math.exp(x.a) * Math.cos(x.b),
|
|
312
|
+
Math.exp(x.a) * Math.sin(x.b)
|
|
313
|
+
);
|
|
314
|
+
return Math.exp(x)
|
|
315
|
+
}
|
|
316
|
+
,...x
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const ln = (...x) => mapfun(
|
|
320
|
+
x => {
|
|
321
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
322
|
+
Math.log(x.z),
|
|
323
|
+
x.phi
|
|
324
|
+
);
|
|
325
|
+
return Math.log(x)
|
|
326
|
+
}
|
|
327
|
+
,...x
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
const sign = (...x) => mapfun(
|
|
331
|
+
x => {
|
|
332
|
+
if(x.isComplex?.()){
|
|
333
|
+
const {z, phi} = x;
|
|
334
|
+
if(z===0) return new x.constructor(0, 0);
|
|
335
|
+
return new x.constructor({z:1, phi})
|
|
336
|
+
}
|
|
337
|
+
return Math.sign(x)
|
|
338
|
+
}
|
|
339
|
+
,...x
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
const floor = (...x) => mapfun(
|
|
343
|
+
x => {
|
|
344
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
345
|
+
Math.floor(x.a),
|
|
346
|
+
Math.floor(x.b)
|
|
347
|
+
)
|
|
348
|
+
return Math.floor(x)
|
|
349
|
+
},
|
|
350
|
+
...x
|
|
351
|
+
);
|
|
352
|
+
const ceil = (...x) => mapfun(
|
|
353
|
+
x => {
|
|
354
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
355
|
+
Math.ceil(x.a),
|
|
356
|
+
Math.ceil(x.b)
|
|
357
|
+
)
|
|
358
|
+
return Math.ceil(x)
|
|
359
|
+
},
|
|
360
|
+
...x
|
|
361
|
+
);
|
|
362
|
+
const round = (...x) => mapfun(
|
|
363
|
+
x => {
|
|
364
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
365
|
+
Math.round(x.a),
|
|
366
|
+
Math.round(x.b)
|
|
367
|
+
)
|
|
368
|
+
return Math.round(x)
|
|
369
|
+
},
|
|
370
|
+
...x
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
const trunc = (...x) => mapfun(
|
|
374
|
+
x => {
|
|
375
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
376
|
+
Math.trunc(x.a),
|
|
377
|
+
Math.trunc(x.b)
|
|
378
|
+
)
|
|
379
|
+
return Math.trunc(x)
|
|
380
|
+
},
|
|
381
|
+
...x
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const fract = (...x) => mapfun(
|
|
385
|
+
x => {
|
|
386
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
387
|
+
x.a - Math.trunc(x.a),
|
|
388
|
+
x.b - Math.trunc(x.b)
|
|
389
|
+
)
|
|
390
|
+
return x - Math.trunc(x)
|
|
391
|
+
},
|
|
392
|
+
...x
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
const cos$3 = (...x) => mapfun(
|
|
396
|
+
x => {
|
|
397
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
398
|
+
Math.cos(x.a) * Math.cosh(x.b),
|
|
399
|
+
-Math.sin(x.a) * Math.sinh(x.b)
|
|
400
|
+
);
|
|
401
|
+
return Math.cos(x)
|
|
402
|
+
}
|
|
403
|
+
,...x
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
const sin$3 = (...x) => mapfun(
|
|
407
|
+
x =>{
|
|
408
|
+
if(x?.isComplex) return new x.constructor(
|
|
409
|
+
Math.sin(x.a) * Math.cosh(x.b),
|
|
410
|
+
Math.cos(x.a) * Math.sinh(x.b)
|
|
411
|
+
);
|
|
412
|
+
return Math.sin(x)
|
|
413
|
+
}
|
|
414
|
+
, ...x
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
const tan = (...x) => mapfun(
|
|
418
|
+
x =>{
|
|
419
|
+
if(x?.isComplex){
|
|
420
|
+
const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
|
|
421
|
+
return new x.constructor(
|
|
422
|
+
Math.sin(2*x.a) / D,
|
|
423
|
+
Math.sinh(2*x.b) / D
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
return Math.tan(x)
|
|
427
|
+
},
|
|
428
|
+
...x
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
const sec = (...x) => mapfun(
|
|
432
|
+
x => {
|
|
433
|
+
if(x.isComplex?.()) ;
|
|
434
|
+
return 1 / Math.cos(x)
|
|
435
|
+
}
|
|
436
|
+
,...x
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
const acos$1 = (...x) => mapfun(
|
|
440
|
+
x =>{
|
|
441
|
+
if(x?.isComplex){
|
|
442
|
+
const { a, b } = x;
|
|
443
|
+
const Rp = Math.hypot(a + 1, b);
|
|
444
|
+
const Rm = Math.hypot(a - 1, b);
|
|
445
|
+
globalThis.Rp = Rp;
|
|
446
|
+
globalThis.Rm = Rm;
|
|
447
|
+
return new x.constructor(
|
|
448
|
+
Math.acos((Rp - Rm) / 2),
|
|
449
|
+
-Math.acosh((Rp + Rm) / 2),
|
|
450
|
+
)
|
|
451
|
+
}
|
|
452
|
+
return Math.acos(x)
|
|
453
|
+
},
|
|
454
|
+
...x
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
const asin = (...x) => mapfun(
|
|
458
|
+
x => {
|
|
459
|
+
if(x?.isComplex){
|
|
460
|
+
const { a, b } = x;
|
|
461
|
+
const Rp = Math.hypot(a + 1, b);
|
|
462
|
+
const Rm = Math.hypot(a - 1, b);
|
|
463
|
+
return new x.constructor(
|
|
464
|
+
Math.asin((Rp - Rm) / 2),
|
|
465
|
+
Math.acosh((Rp + Rm) / 2)
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
return Math.asin(x);
|
|
469
|
+
},
|
|
470
|
+
...x
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
const atan = (...x) => mapfun(
|
|
474
|
+
x => {
|
|
475
|
+
if(x?.isComplex){
|
|
476
|
+
const { a, b } = x;
|
|
477
|
+
return new x.constructor(
|
|
478
|
+
Math.atan((a*2/(1-a**2-b**2)))/2,
|
|
479
|
+
Math.log((a**2 + (1+b)**2)/(a**2 + (1-b)**2))/4
|
|
480
|
+
)
|
|
481
|
+
}
|
|
482
|
+
return Math.atan(x);
|
|
483
|
+
},
|
|
484
|
+
...x
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
const acot = (...x) => mapfun(
|
|
488
|
+
x => {
|
|
489
|
+
if(x?.isComplex){
|
|
490
|
+
const { a, b } = x;
|
|
491
|
+
return new x.constructor(
|
|
492
|
+
Math.atan(2*a/(a**2+(b-1)*(b+1)))/2,
|
|
493
|
+
Math.log((a**2 + (b-1)**2)/(a**2 + (b+1)**2))/4
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
return Math.PI/2 - Math.atan(x);
|
|
497
|
+
},
|
|
498
|
+
...x
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
const cosh$2 = (...x) => mapfun(
|
|
503
|
+
x =>{
|
|
504
|
+
if(x?.isComplex) return new x.constructor(
|
|
505
|
+
Math.cosh(x.a) * Math.cos(x.b),
|
|
506
|
+
Math.sinh(x.a) * Math.sin(x.b)
|
|
507
|
+
);
|
|
508
|
+
return Math.cosh(x)
|
|
509
|
+
},
|
|
510
|
+
...x
|
|
511
|
+
);
|
|
512
|
+
const sinh$1 = (...x) => mapfun(
|
|
513
|
+
x =>{
|
|
514
|
+
if(x?.isComplex) return new x.constructor(
|
|
515
|
+
Math.sinh(x.a) * Math.cos(x.b),
|
|
516
|
+
Math.cosh(x.a) * Math.sin(x.b)
|
|
517
|
+
);
|
|
518
|
+
return Math.sinh(x)
|
|
519
|
+
},
|
|
520
|
+
...x
|
|
521
|
+
);
|
|
522
|
+
const tanh = (...x) => mapfun(
|
|
523
|
+
x =>{
|
|
524
|
+
if(x?.isComplex){
|
|
525
|
+
const D = Math.cosh(2*a) + Math.cos(2*b);
|
|
526
|
+
return new x.constructor(
|
|
527
|
+
Math.sinh(2*a) / D,
|
|
528
|
+
Math.sin(2*b) / D
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
return Math.tanh(x)
|
|
532
|
+
},
|
|
533
|
+
...x
|
|
534
|
+
);
|
|
535
|
+
|
|
536
|
+
const coth = (...x) => mapfun(
|
|
537
|
+
x =>{
|
|
538
|
+
if(x?.isComplex){
|
|
539
|
+
const {a, b} = x;
|
|
540
|
+
const D = (Math.sinh(a)**2)*(Math.cos(b)**2) + (Math.cosh(a)**2)*(Math.sin(b)**2);
|
|
541
|
+
return new x.constructor(
|
|
542
|
+
Math.cosh(a) * Math.sinh(a) / D,
|
|
543
|
+
- Math.sin(b) * Math.cos(b) / D
|
|
544
|
+
)
|
|
545
|
+
}
|
|
546
|
+
return 1/Math.tanh(x)
|
|
547
|
+
},
|
|
548
|
+
...x
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
const acosh = (...x) => mapfun(
|
|
552
|
+
x =>{
|
|
553
|
+
if(x?.isComplex){
|
|
554
|
+
return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).sub(1))))
|
|
555
|
+
}
|
|
556
|
+
return Math.acosh(x)
|
|
557
|
+
},
|
|
558
|
+
...x
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
const asinh = (...x) => mapfun(
|
|
562
|
+
x =>{
|
|
563
|
+
if(x?.isComplex){
|
|
564
|
+
return ln(x.clone().add(sqrt$2(x.clone().mul(x.clone()).add(1))))
|
|
565
|
+
}
|
|
566
|
+
return Math.asinh(x)
|
|
567
|
+
},
|
|
568
|
+
...x
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const atanh = (...x) => mapfun(
|
|
572
|
+
x =>{
|
|
573
|
+
if(x?.isComplex);
|
|
574
|
+
return Math.atanh(x)
|
|
575
|
+
},
|
|
576
|
+
...x
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
const sig = (...x) => mapfun(
|
|
580
|
+
x =>{
|
|
581
|
+
if(x?.isComplex);
|
|
582
|
+
return 1/(1+Math.exp(-x))
|
|
583
|
+
},
|
|
584
|
+
...x
|
|
585
|
+
);
|
|
586
|
+
|
|
587
|
+
const _add = (x, y) =>{
|
|
588
|
+
if(typeof x === 'number'){
|
|
589
|
+
if(typeof y === 'number') return x + y;
|
|
590
|
+
if(y.isComplex?.()) {
|
|
591
|
+
return y.clone().add(x);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if(x.isComplex?.()){
|
|
595
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().add(y);
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
const _sub = (x, y) =>{
|
|
600
|
+
if(typeof x === 'number'){
|
|
601
|
+
if(typeof y === 'number') return x - y;
|
|
602
|
+
if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
|
|
603
|
+
}
|
|
604
|
+
if(x.isComplex?.()){
|
|
605
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().sub(y);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const _mul = (x, y) =>{
|
|
610
|
+
if(typeof x === 'number'){
|
|
611
|
+
if(typeof y === 'number') return x * y;
|
|
612
|
+
if(y.isComplex?.()) return y.clone().mul(x);
|
|
613
|
+
}
|
|
614
|
+
if(x.isComplex?.()){
|
|
615
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
const _div = (x, y) =>{
|
|
620
|
+
if(typeof x === 'number'){
|
|
621
|
+
if(typeof y === 'number') return x / y;
|
|
622
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
|
|
623
|
+
}
|
|
624
|
+
if(x.isComplex?.()){
|
|
625
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
const _modulo = (x, y) =>{
|
|
630
|
+
if(typeof x === 'number'){
|
|
631
|
+
if(typeof y === 'number') return x % y;
|
|
632
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
|
|
633
|
+
}
|
|
634
|
+
if(x.isComplex?.()){
|
|
635
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().modulo(y);
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
const add=(a,...b)=>{
|
|
640
|
+
let res = a;
|
|
641
|
+
for(let i=0; i<b.length; i++)
|
|
642
|
+
res = _add(res, b[i]);
|
|
643
|
+
return res;
|
|
644
|
+
};
|
|
645
|
+
const sub=(a,...b)=>{
|
|
646
|
+
let res = a;
|
|
647
|
+
for(let i=0; i<b.length; i++)
|
|
648
|
+
res = _sub(res, b[i]);
|
|
649
|
+
return res;
|
|
650
|
+
};
|
|
651
|
+
const mul=(a,...b)=>{
|
|
652
|
+
let res = a;
|
|
653
|
+
for(let i=0; i<b.length; i++)
|
|
654
|
+
res = _mul(res, b[i]);
|
|
655
|
+
return res;
|
|
656
|
+
};
|
|
657
|
+
const div=(a,...b)=>{
|
|
658
|
+
let res = a;
|
|
659
|
+
for(let i=0; i<b.length; i++)
|
|
660
|
+
res = _div(res, b[i]);
|
|
661
|
+
return res;
|
|
662
|
+
};
|
|
663
|
+
const modulo=(a,...b)=>{
|
|
664
|
+
let res = a;
|
|
665
|
+
for(let i=0; i<b.length; i++)
|
|
666
|
+
res = _modulo(res, b[i]);
|
|
667
|
+
return res;
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
const norm = (x, min, max) => {
|
|
671
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
672
|
+
norm(x.a, min, max),
|
|
673
|
+
norm(x.b, min, max)
|
|
674
|
+
)
|
|
675
|
+
if(x.isMatrix?.()) return new x.constructor(
|
|
676
|
+
x.rows,
|
|
677
|
+
x.cols,
|
|
678
|
+
norm(x.arr.flat(1), min, max)
|
|
679
|
+
);
|
|
680
|
+
return min !== max ? (value - min) / (max - min) : 0;
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
const lerp = (x, min, max) => {
|
|
684
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
685
|
+
lerp(x.a, min, max),
|
|
686
|
+
lerp(x.b, min, max)
|
|
687
|
+
)
|
|
688
|
+
if(x.isMatrix?.()) return new x.constructor(
|
|
689
|
+
x.rows,
|
|
690
|
+
x.cols,
|
|
691
|
+
lerp(x.arr.flat(1), min, max)
|
|
692
|
+
);
|
|
693
|
+
return (max - min) * value + min;
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const map$1 = (x, min, max) => {
|
|
697
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
698
|
+
map$1(x.a),
|
|
699
|
+
map$1(x.b)
|
|
700
|
+
)
|
|
701
|
+
if(x.isMatrix?.()) return new x.constructor(
|
|
702
|
+
x.rows,
|
|
703
|
+
x.cols,
|
|
704
|
+
map$1(x.arr.flat(1))
|
|
705
|
+
);
|
|
706
|
+
return lerp(norm(x, a, b), c, d);
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
const clamp = (x, min, max) => {
|
|
710
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
711
|
+
clamp(x.a, min, max),
|
|
712
|
+
clamp(x.b, min, max)
|
|
713
|
+
)
|
|
714
|
+
if(x.isMatrix?.()) return new x.constructor(
|
|
715
|
+
x.rows,
|
|
716
|
+
x.cols,
|
|
717
|
+
clamp(x.arr.flat(1), min, max)
|
|
718
|
+
);
|
|
719
|
+
return Math.min(Math.max(c, min), max)
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
const hypot = (...x) => {
|
|
723
|
+
const c0 = x.find(a => a.isComplex?.());
|
|
724
|
+
if (c0) {
|
|
725
|
+
const W = x.map(n => n.isComplex?.() ? n : new c0.constructor(n, 0));
|
|
726
|
+
return Math.hypot(...W.map(c => c.z));
|
|
727
|
+
}
|
|
728
|
+
return Math.hypot(...x);
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
const atan2 = (x, y, rad = true) =>{
|
|
733
|
+
|
|
734
|
+
};
|
|
735
|
+
|
|
875
736
|
const preload=(url)=>{
|
|
876
737
|
const xhr = new XMLHttpRequest();
|
|
877
738
|
xhr.open("GET", url, false);
|
|
@@ -1501,9 +1362,9 @@ function unmount(delay = 0) {
|
|
|
1501
1362
|
}
|
|
1502
1363
|
|
|
1503
1364
|
var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1365
|
+
__proto__: null,
|
|
1366
|
+
mount: mount,
|
|
1367
|
+
unmount: unmount
|
|
1507
1368
|
});
|
|
1508
1369
|
|
|
1509
1370
|
if(!globalThis.__Ziko__) __init__global__();
|
|
@@ -1670,11 +1531,11 @@ function setContentEditable(bool = true) {
|
|
|
1670
1531
|
}
|
|
1671
1532
|
|
|
1672
1533
|
var AttrsMethods = /*#__PURE__*/Object.freeze({
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1534
|
+
__proto__: null,
|
|
1535
|
+
getAttr: getAttr,
|
|
1536
|
+
removeAttr: removeAttr,
|
|
1537
|
+
setAttr: setAttr,
|
|
1538
|
+
setContentEditable: setContentEditable
|
|
1678
1539
|
});
|
|
1679
1540
|
|
|
1680
1541
|
function append(...ele) {
|
|
@@ -1731,15 +1592,15 @@ function before(ui){
|
|
|
1731
1592
|
}
|
|
1732
1593
|
|
|
1733
1594
|
var DomMethods = /*#__PURE__*/Object.freeze({
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1595
|
+
__proto__: null,
|
|
1596
|
+
after: after,
|
|
1597
|
+
append: append,
|
|
1598
|
+
before: before,
|
|
1599
|
+
clear: clear,
|
|
1600
|
+
insertAt: insertAt,
|
|
1601
|
+
prepend: prepend,
|
|
1602
|
+
remove: remove,
|
|
1603
|
+
replaceElementWith: replaceElementWith
|
|
1743
1604
|
});
|
|
1744
1605
|
|
|
1745
1606
|
const EventsMap = {
|
|
@@ -2453,11 +2314,11 @@ function find(condition) {
|
|
|
2453
2314
|
}
|
|
2454
2315
|
|
|
2455
2316
|
var IndexingMethods = /*#__PURE__*/Object.freeze({
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2317
|
+
__proto__: null,
|
|
2318
|
+
at: at,
|
|
2319
|
+
find: find,
|
|
2320
|
+
forEach: forEach,
|
|
2321
|
+
map: map
|
|
2461
2322
|
});
|
|
2462
2323
|
|
|
2463
2324
|
function style(styles){
|
|
@@ -2494,12 +2355,12 @@ function animate(keyframe, {duration=1000, iterations=1, easing="ease"}={}){
|
|
|
2494
2355
|
}
|
|
2495
2356
|
|
|
2496
2357
|
var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2358
|
+
__proto__: null,
|
|
2359
|
+
animate: animate,
|
|
2360
|
+
hide: hide,
|
|
2361
|
+
show: show,
|
|
2362
|
+
size: size,
|
|
2363
|
+
style: style
|
|
2503
2364
|
});
|
|
2504
2365
|
|
|
2505
2366
|
// import {
|
|
@@ -3173,7 +3034,7 @@ const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).mount(render);
|
|
|
3173
3034
|
// };
|
|
3174
3035
|
|
|
3175
3036
|
const obj2str=(obj)=>JSON.stringify(
|
|
3176
|
-
mapfun
|
|
3037
|
+
mapfun(n=>{
|
|
3177
3038
|
if(["number","string","boolean","bigint"].includes(typeof n)) return String(n);
|
|
3178
3039
|
if(n instanceof Complex || n instanceof Matrix) return n.toString();
|
|
3179
3040
|
if(n instanceof Array) return arr2str(n)
|
|
@@ -3659,7 +3520,7 @@ class Matrix{
|
|
|
3659
3520
|
// return result;
|
|
3660
3521
|
// }
|
|
3661
3522
|
map(Imin, Imax, Fmin, Fmax) {
|
|
3662
|
-
this.arr = map$1(this.arr
|
|
3523
|
+
this.arr = map$1(this.arr);
|
|
3663
3524
|
return this;
|
|
3664
3525
|
}
|
|
3665
3526
|
lerp(min, max) {
|
|
@@ -3959,6 +3820,277 @@ const powerSet=originalSet=>{
|
|
|
3959
3820
|
return subSets;
|
|
3960
3821
|
};
|
|
3961
3822
|
|
|
3823
|
+
const zeros=(n)=>new Array(n).fill(0);
|
|
3824
|
+
const ones=(n)=>new Array(n).fill(1);
|
|
3825
|
+
const nums=(num,n)=>new Array(n).fill(num);
|
|
3826
|
+
|
|
3827
|
+
const arange=(a, b, step , include = false)=>{
|
|
3828
|
+
let tab = [];
|
|
3829
|
+
if(a<b){
|
|
3830
|
+
for (let i = a; include?i<=b:i<b; i += step) tab.push((i * 10) / 10);
|
|
3831
|
+
}
|
|
3832
|
+
else {
|
|
3833
|
+
for(let i = a; include?i>=b:i>b; i -= step) tab.push((i * 10) / 10);
|
|
3834
|
+
}
|
|
3835
|
+
return tab;
|
|
3836
|
+
};
|
|
3837
|
+
const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
3838
|
+
if(Math.floor(n)!==n)return;
|
|
3839
|
+
if([a,b].every(n=>typeof n==="number")){
|
|
3840
|
+
const [max,min]=[a,b].sort((a,b)=>b-a);
|
|
3841
|
+
var Y = [];
|
|
3842
|
+
let step ;
|
|
3843
|
+
endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
|
|
3844
|
+
for (var i = 0; i < n; i++) {
|
|
3845
|
+
a<b?Y.push(min+step*i):Y.push(max-step*i);
|
|
3846
|
+
}
|
|
3847
|
+
return Y
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3850
|
+
if([a,b].some(n=>n.isComplex?.())){
|
|
3851
|
+
const z1 = new n.constructor(a);
|
|
3852
|
+
const z2 = new n.constructor(b);
|
|
3853
|
+
n=n||Math.abs(z1.a-z2.a)+1;
|
|
3854
|
+
const X=linspace(z1.a,z2.a,n,endpoint);
|
|
3855
|
+
const Y=linspace(z1.b,z2.b,n,endpoint);
|
|
3856
|
+
let Z=new Array(n).fill(null);
|
|
3857
|
+
Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
|
|
3858
|
+
return Z;
|
|
3859
|
+
}
|
|
3860
|
+
};
|
|
3861
|
+
const logspace=(a,b,n=b-a+1,base=E,endpoint=true)=>{
|
|
3862
|
+
return linspace(a,b,n,endpoint).map(n=>pow$1(base,n))
|
|
3863
|
+
};
|
|
3864
|
+
const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
3865
|
+
if(Math.floor(n)!==n)return;
|
|
3866
|
+
if([a,b].every(n=>typeof n==="number")){
|
|
3867
|
+
const [max,min]=[a,b].sort((a,b)=>b-a);
|
|
3868
|
+
let base;
|
|
3869
|
+
endpoint ? base = nthr(max/min,n-1) : base = nthr(max/min,n) ;
|
|
3870
|
+
const Y = [min];
|
|
3871
|
+
for (let i = 1; i < n; i++) {
|
|
3872
|
+
Y.push(Y[i-1]*base);
|
|
3873
|
+
}
|
|
3874
|
+
return a<b?Y:Y.reverse()
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3877
|
+
if([a,b].some(n=>n.isComplex?.())){
|
|
3878
|
+
const z1 = new n.constructor(a);
|
|
3879
|
+
const z2 = new n.constructor(b);
|
|
3880
|
+
n=n||Math.abs(z1.a-z2.a)+1;
|
|
3881
|
+
let base;
|
|
3882
|
+
endpoint ? base = nthr(z2.div(z1),n-1) : base = nthr(z2.div(z1),n) ;
|
|
3883
|
+
const Y = [z1];
|
|
3884
|
+
for (let i = 1; i < n; i++) {
|
|
3885
|
+
Y.push(mul(Y[i-1],base));
|
|
3886
|
+
}
|
|
3887
|
+
return Y;
|
|
3888
|
+
}
|
|
3889
|
+
};
|
|
3890
|
+
|
|
3891
|
+
// Mixed calcul
|
|
3892
|
+
const sum=(...x)=>{
|
|
3893
|
+
if(x.every(n=>typeof n==="number")){
|
|
3894
|
+
let s = x[0];
|
|
3895
|
+
for (let i = 1; i < x.length; i++) s += x[i];
|
|
3896
|
+
return s;
|
|
3897
|
+
}
|
|
3898
|
+
const Y=[];
|
|
3899
|
+
for(let i=0;i<x.length;i++){
|
|
3900
|
+
if(x[i] instanceof Array)Y.push(sum(...x[i]));
|
|
3901
|
+
else if(x[i] instanceof Object){
|
|
3902
|
+
Y.push(sum(...Object.values(x[i])));
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
return Y.length===1?Y[0]:Y;
|
|
3906
|
+
};
|
|
3907
|
+
const prod=(...x)=>{
|
|
3908
|
+
if(x.every(n=>typeof n==="number")){
|
|
3909
|
+
let p = x[0];
|
|
3910
|
+
for (let i = 1; i < x.length; i++) p *= x[i];
|
|
3911
|
+
return p;
|
|
3912
|
+
}
|
|
3913
|
+
const Y=[];
|
|
3914
|
+
for(let i=0;i<x.length;i++){
|
|
3915
|
+
if(x[i] instanceof Array)Y.push(prod(...x[i]));
|
|
3916
|
+
else if(x[i] instanceof Object){
|
|
3917
|
+
Y.push(prod(...Object.values(x[i])));
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
return Y.length===1?Y[0]:Y;
|
|
3921
|
+
};
|
|
3922
|
+
const min$1=(...num)=>{
|
|
3923
|
+
if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
3924
|
+
const Y=[];
|
|
3925
|
+
for(let i=0;i<num.length;i++){
|
|
3926
|
+
if(num[i] instanceof Array)Y.push(min$1(...num[i]));
|
|
3927
|
+
else if(num[i] instanceof Object){
|
|
3928
|
+
Y.push(
|
|
3929
|
+
Object.fromEntries(
|
|
3930
|
+
[Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
3931
|
+
)
|
|
3932
|
+
);
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
return Y.length===1?Y[0]:Y;
|
|
3936
|
+
};
|
|
3937
|
+
const max$1=(...num)=>{
|
|
3938
|
+
if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
3939
|
+
const Y=[];
|
|
3940
|
+
for(let i=0;i<num.length;i++){
|
|
3941
|
+
if(num[i] instanceof Array)Y.push(min$1(...num[i]));
|
|
3942
|
+
else if(num[i] instanceof Object){
|
|
3943
|
+
Y.push(
|
|
3944
|
+
Object.fromEntries(
|
|
3945
|
+
[Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
3946
|
+
)
|
|
3947
|
+
);
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3950
|
+
return Y.length===1?Y[0]:Y;
|
|
3951
|
+
};
|
|
3952
|
+
const accum=(...num)=>{
|
|
3953
|
+
if(num.every(n=>typeof n==="number")){
|
|
3954
|
+
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
3955
|
+
acc.shift();
|
|
3956
|
+
return acc;
|
|
3957
|
+
}
|
|
3958
|
+
const Y=[];
|
|
3959
|
+
for(let i=0;i<num.length;i++){
|
|
3960
|
+
if(num[i] instanceof Array)Y.push(accum(...num[i]));
|
|
3961
|
+
else if(num[i] instanceof Object){
|
|
3962
|
+
Y.push(null
|
|
3963
|
+
// Object.fromEntries(
|
|
3964
|
+
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
3965
|
+
// )
|
|
3966
|
+
);
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
return Y.length===1?Y[0]:Y;
|
|
3970
|
+
};
|
|
3971
|
+
|
|
3972
|
+
//moy
|
|
3973
|
+
//med
|
|
3974
|
+
//variance
|
|
3975
|
+
//std
|
|
3976
|
+
//mode
|
|
3977
|
+
//acccum
|
|
3978
|
+
//min2max
|
|
3979
|
+
//max2min
|
|
3980
|
+
//percentile
|
|
3981
|
+
|
|
3982
|
+
/** @module Math */
|
|
3983
|
+
/**
|
|
3984
|
+
* Checks if a value is within the specified range.
|
|
3985
|
+
* @function
|
|
3986
|
+
* @param {number} x - The value to check.
|
|
3987
|
+
* @param {number} a - The start of the range.
|
|
3988
|
+
* @param {number} b - The end of the range.
|
|
3989
|
+
* @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
|
|
3990
|
+
*/
|
|
3991
|
+
const inRange = (x, a, b) => {
|
|
3992
|
+
const [min, max] = [Math.min(a, b), Math.max(a, b)];
|
|
3993
|
+
return x >= min && x <= max;
|
|
3994
|
+
};
|
|
3995
|
+
|
|
3996
|
+
/**
|
|
3997
|
+
* Checks if two numbers are approximately equal within a given error margin.
|
|
3998
|
+
* @param {number} a - The first number.
|
|
3999
|
+
* @param {number} b - The second number.
|
|
4000
|
+
* @param {number} [Err=0.0001] - The maximum acceptable difference between the two numbers.
|
|
4001
|
+
* @returns {boolean} Returns true if the two numbers are approximately equal within the specified error margin, otherwise false.
|
|
4002
|
+
*/
|
|
4003
|
+
const isApproximatlyEqual = (a, b, Err = 0.0001) => {
|
|
4004
|
+
return Math.abs(a - b) <= Err;
|
|
4005
|
+
};
|
|
4006
|
+
|
|
4007
|
+
/** @module Math */
|
|
4008
|
+
|
|
4009
|
+
/**
|
|
4010
|
+
* Computes the cartesian product of two arrays.
|
|
4011
|
+
* @param {Array} a - The first array.
|
|
4012
|
+
* @param {Array} b - The second array.
|
|
4013
|
+
* @returns {Array} Returns an array representing the cartesian product of the input arrays.
|
|
4014
|
+
*/
|
|
4015
|
+
const cartesianProduct = (a, b) => a.reduce((p, x) => [...p, ...b.map((y) => [x, y])], []);
|
|
4016
|
+
|
|
4017
|
+
/**
|
|
4018
|
+
* Computes the greatest common divisor (GCD) of two numbers.
|
|
4019
|
+
* @param {number} n1 - The first number.
|
|
4020
|
+
* @param {number} n2 - The second number.
|
|
4021
|
+
* @returns {number} Returns the greatest common divisor of the two input numbers.
|
|
4022
|
+
*/
|
|
4023
|
+
const pgcd = (n1, n2) => {
|
|
4024
|
+
let i,
|
|
4025
|
+
pgcd = 1;
|
|
4026
|
+
if (n1 == floor(n1) && n2 == floor(n2)) {
|
|
4027
|
+
for (i = 2; i <= n1 && i <= n2; ++i) {
|
|
4028
|
+
if (n1 % i == 0 && n2 % i == 0) pgcd = i;
|
|
4029
|
+
}
|
|
4030
|
+
return pgcd;
|
|
4031
|
+
} else console.log("error");
|
|
4032
|
+
};
|
|
4033
|
+
|
|
4034
|
+
/**
|
|
4035
|
+
* Computes the least common multiple (LCM) of two numbers.
|
|
4036
|
+
* @param {number} n1 - The first number.
|
|
4037
|
+
* @param {number} n2 - The second number.
|
|
4038
|
+
* @returns {number} Returns the least common multiple of the two input numbers.
|
|
4039
|
+
*/
|
|
4040
|
+
const ppcm = (n1, n2) => {
|
|
4041
|
+
let ppcm;
|
|
4042
|
+
if (n1 == floor(n1) && n2 == floor(n2)) {
|
|
4043
|
+
ppcm = n1 > n2 ? n1 : n2;
|
|
4044
|
+
while (true) {
|
|
4045
|
+
if (ppcm % n1 == 0 && ppcm % n2 == 0) break;
|
|
4046
|
+
++ppcm;
|
|
4047
|
+
}
|
|
4048
|
+
return ppcm;
|
|
4049
|
+
} else console.log("error");
|
|
4050
|
+
};
|
|
4051
|
+
|
|
4052
|
+
// import { mapfun } from "../mapfun/index.js";
|
|
4053
|
+
// import {
|
|
4054
|
+
// add,
|
|
4055
|
+
// sub,
|
|
4056
|
+
// mul,
|
|
4057
|
+
// div,
|
|
4058
|
+
// modulo
|
|
4059
|
+
// } from "./arithmetic.js";
|
|
4060
|
+
const Utils={
|
|
4061
|
+
// add,
|
|
4062
|
+
// sub,
|
|
4063
|
+
// mul,
|
|
4064
|
+
// div,
|
|
4065
|
+
// modulo,
|
|
4066
|
+
|
|
4067
|
+
zeros,
|
|
4068
|
+
ones,
|
|
4069
|
+
nums,
|
|
4070
|
+
// norm,
|
|
4071
|
+
// lerp,
|
|
4072
|
+
// map,
|
|
4073
|
+
// clamp,
|
|
4074
|
+
arange,
|
|
4075
|
+
linspace,
|
|
4076
|
+
logspace,
|
|
4077
|
+
geomspace,
|
|
4078
|
+
|
|
4079
|
+
sum,
|
|
4080
|
+
prod,
|
|
4081
|
+
accum,
|
|
4082
|
+
|
|
4083
|
+
cartesianProduct,
|
|
4084
|
+
ppcm,
|
|
4085
|
+
pgcd,
|
|
4086
|
+
|
|
4087
|
+
// deg2rad,
|
|
4088
|
+
// rad2deg,
|
|
4089
|
+
|
|
4090
|
+
inRange,
|
|
4091
|
+
isApproximatlyEqual
|
|
4092
|
+
};
|
|
4093
|
+
|
|
3962
4094
|
// const subSet = (...arr) => {
|
|
3963
4095
|
// let list = arange(0, 2 ** arr.length, 1);
|
|
3964
4096
|
// let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
|
|
@@ -4322,14 +4454,14 @@ class Random {
|
|
|
4322
4454
|
// }
|
|
4323
4455
|
}
|
|
4324
4456
|
|
|
4325
|
-
const { PI, sqrt: sqrt$1, cos: cos$
|
|
4457
|
+
const { PI, sqrt: sqrt$1, cos: cos$2, sin: sin$2, acos, pow } = Math;
|
|
4326
4458
|
|
|
4327
4459
|
const linear = t => t;
|
|
4328
4460
|
|
|
4329
4461
|
// --- Sin ---
|
|
4330
|
-
const in_sin = t => 1 - cos$
|
|
4331
|
-
const out_sin = t => sin$
|
|
4332
|
-
const in_out_sin = t => -(cos$
|
|
4462
|
+
const in_sin = t => 1 - cos$2((t * PI) / 2);
|
|
4463
|
+
const out_sin = t => sin$2((t * PI) / 2);
|
|
4464
|
+
const in_out_sin = t => -(cos$2(PI * t) - 1) / 2;
|
|
4333
4465
|
|
|
4334
4466
|
// --- Quad ---
|
|
4335
4467
|
const in_quad = t => t ** 2;
|
|
@@ -4376,14 +4508,14 @@ const in_out_circ = t =>
|
|
|
4376
4508
|
: (sqrt$1(1 - (-2 * t + 2) ** 2) + 1) / 2;
|
|
4377
4509
|
|
|
4378
4510
|
// --- Arc ---
|
|
4379
|
-
const arc = t => 1 - sin$
|
|
4511
|
+
const arc = t => 1 - sin$2(acos(t));
|
|
4380
4512
|
|
|
4381
4513
|
// --- Back ---
|
|
4382
4514
|
const back = (t, x = 1) => (t ** 2) * ((x + 1) * t - x);
|
|
4383
4515
|
|
|
4384
4516
|
// --- Elastic ---
|
|
4385
4517
|
const elastic = t =>
|
|
4386
|
-
-2 * pow(2, 10 * (t - 1)) * cos$
|
|
4518
|
+
-2 * pow(2, 10 * (t - 1)) * cos$2((20 * PI * t) / 3 * t);
|
|
4387
4519
|
|
|
4388
4520
|
// --- Back variations ---
|
|
4389
4521
|
const in_back = (t, c1 = 1.70158, c3 = c1 + 1) =>
|
|
@@ -4403,14 +4535,14 @@ const in_elastic = (t, c4 = (2 * PI) / 3) =>
|
|
|
4403
4535
|
? 0
|
|
4404
4536
|
: t === 1
|
|
4405
4537
|
? 1
|
|
4406
|
-
: -pow(2, 10 * t - 10) * sin$
|
|
4538
|
+
: -pow(2, 10 * t - 10) * sin$2((t * 10 - 10.75) * c4);
|
|
4407
4539
|
|
|
4408
4540
|
const out_elastic = (t, c4 = (2 * PI) / 3) =>
|
|
4409
4541
|
t === 0
|
|
4410
4542
|
? 0
|
|
4411
4543
|
: t === 1
|
|
4412
4544
|
? 1
|
|
4413
|
-
: pow(2, -10 * t) * sin$
|
|
4545
|
+
: pow(2, -10 * t) * sin$2((t * 10 - 0.75) * c4) + 1;
|
|
4414
4546
|
|
|
4415
4547
|
const in_out_elastic = (t, c5 = (2 * PI) / 4.5) =>
|
|
4416
4548
|
t === 0
|
|
@@ -4418,8 +4550,8 @@ const in_out_elastic = (t, c5 = (2 * PI) / 4.5) =>
|
|
|
4418
4550
|
: t === 1
|
|
4419
4551
|
? 1
|
|
4420
4552
|
: t < 0.5
|
|
4421
|
-
? -(pow(2, 20 * t - 10) * sin$
|
|
4422
|
-
: (pow(2, -20 * t + 10) * sin$
|
|
4553
|
+
? -(pow(2, 20 * t - 10) * sin$2((20 * t - 11.125) * c5)) / 2
|
|
4554
|
+
: (pow(2, -20 * t + 10) * sin$2((20 * t - 11.125) * c5)) / 2 + 1;
|
|
4423
4555
|
|
|
4424
4556
|
// --- Bounce ---
|
|
4425
4557
|
const in_bounce = (t, n1 = 7.5625, d1 = 2.75) =>
|
|
@@ -4470,7 +4602,7 @@ class TimeAnimation {
|
|
|
4470
4602
|
this.t += this.state.step;
|
|
4471
4603
|
this.i++;
|
|
4472
4604
|
|
|
4473
|
-
this.tx = map$1(this.t, 0, this.state.duration
|
|
4605
|
+
this.tx = map$1(this.t, 0, this.state.duration);
|
|
4474
4606
|
this.ty = this.state.ease(this.tx);
|
|
4475
4607
|
|
|
4476
4608
|
this.callback(this);
|
|
@@ -5116,7 +5248,7 @@ function useDerived(deriveFn, sources) {
|
|
|
5116
5248
|
})
|
|
5117
5249
|
}
|
|
5118
5250
|
|
|
5119
|
-
const useReactive = (nested_value) => mapfun
|
|
5251
|
+
const useReactive = (nested_value) => mapfun(
|
|
5120
5252
|
n => {
|
|
5121
5253
|
const state = useState(n);
|
|
5122
5254
|
return {
|
|
@@ -5415,7 +5547,7 @@ tags.p("Test useRoot ").style({
|
|
|
5415
5547
|
|
|
5416
5548
|
*/
|
|
5417
5549
|
|
|
5418
|
-
let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
|
|
5550
|
+
let {sqrt, cos: cos$1, sin: sin$1, exp, log, cosh: cosh$1, sinh} = Math;
|
|
5419
5551
|
// Math.abs = new Proxy(Math.abs, {
|
|
5420
5552
|
// apply(target, thisArg, args) {
|
|
5421
5553
|
// const x = args[0]
|
|
@@ -5446,20 +5578,20 @@ for (const key of Object.getOwnPropertyNames(Math)) {
|
|
|
5446
5578
|
const complex = (a, b) => new x.constructor(a, b);
|
|
5447
5579
|
switch(target.name){
|
|
5448
5580
|
case 'abs' : return x.z;
|
|
5449
|
-
case 'sqrt' : return complex(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2));
|
|
5581
|
+
case 'sqrt' : return complex(sqrt(z)*cos$1(phi/2),sqrt(z)*sin$1(phi/2));
|
|
5450
5582
|
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));
|
|
5583
|
+
case 'exp' : return complex(exp(a)*cos$1(b),exp(a)*sin$1(b));
|
|
5584
|
+
case 'cos' : return complex(cos$1(a)*cosh$1(b),-(sin$1(a)*sinh(b)));
|
|
5585
|
+
case 'sin' : return complex(sin$1(a)*cosh$1(b),cos$1(a)*sinh(b));
|
|
5454
5586
|
case 'tan' : {
|
|
5455
|
-
const DEN = cos(2*a)+cosh(2*b);
|
|
5456
|
-
return complex(sin(2*a) /DEN, sinh(2*b)/DEN);
|
|
5587
|
+
const DEN = cos$1(2*a)+cosh$1(2*b);
|
|
5588
|
+
return complex(sin$1(2*a) /DEN, sinh(2*b)/DEN);
|
|
5457
5589
|
}
|
|
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));
|
|
5590
|
+
case 'cosh' : return complex(cosh$1(a)*cos$1(b),sinh(a)*sin$1(b));
|
|
5591
|
+
case 'sinh' : return complex(sinh(a)*cos$1(b),cosh$1(a)*sin$1(b));
|
|
5460
5592
|
case 'tanh' : {
|
|
5461
|
-
const DEN=cosh(2*a)+cos(2*b);
|
|
5462
|
-
return complex(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
5593
|
+
const DEN=cosh$1(2*a)+cos$1(2*b);
|
|
5594
|
+
return complex(sinh(2*a)/DEN,sin$1(2*b)/DEN)
|
|
5463
5595
|
}
|
|
5464
5596
|
default : return target.apply(thisArg, args)
|
|
5465
5597
|
}
|
|
@@ -5478,4 +5610,4 @@ if(globalThis?.document){
|
|
|
5478
5610
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
5479
5611
|
}
|
|
5480
5612
|
|
|
5481
|
-
export { App, Base, Clock, Combinaison, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Logic$1 as Logic, Matrix, PI$
|
|
5613
|
+
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, 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, 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, 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, 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, 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, wait, waitForUIElm, waitForUIElmSync, zeros };
|