ziko 0.54.4 → 0.55.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 CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Fri Dec 12 2025 14:53:26 GMT+0100 (UTC+01:00)
5
+ Date : Sat Dec 13 2025 01:41:10 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
@@ -52,8 +52,280 @@
52
52
  return fn(x)
53
53
  };
54
54
 
55
- // import {sum,prod,deg2rad} from "../utils/index.js";
56
- // Should avoid CD
55
+ const base2base = (value, fromBase, toBase) => {
56
+
57
+ const dec = parseInt(value, fromBase);
58
+ if (Number.isNaN(dec)) throw new TypeError('Invalid value for the given base');
59
+
60
+ return dec.toString(toBase);
61
+ };
62
+
63
+ const _add = (x, y) =>{
64
+ if(typeof x === 'number'){
65
+ if(typeof y === 'number') return x + y;
66
+ if(y.isComplex?.()) {
67
+ return y.clone().add(x);
68
+ }
69
+ }
70
+ if(x.isComplex?.()){
71
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().add(y);
72
+ }
73
+ };
74
+
75
+ const _sub = (x, y) =>{
76
+ if(typeof x === 'number'){
77
+ if(typeof y === 'number') return x - y;
78
+ if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
79
+ }
80
+ if(x.isComplex?.()){
81
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().sub(y);
82
+ }
83
+ };
84
+
85
+ const _mul = (x, y) =>{
86
+ if(typeof x === 'number'){
87
+ if(typeof y === 'number') return x * y;
88
+ if(y.isComplex?.()) return y.clone().mul(x);
89
+ }
90
+ if(x.isComplex?.()){
91
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
92
+ }
93
+ };
94
+
95
+ const _div = (x, y) =>{
96
+ if(typeof x === 'number'){
97
+ if(typeof y === 'number') return x / y;
98
+ if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
99
+ }
100
+ if(x.isComplex?.()){
101
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
102
+ }
103
+ };
104
+
105
+ const _modulo = (x, y) =>{
106
+ if(typeof x === 'number'){
107
+ if(typeof y === 'number') return x % y;
108
+ if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
109
+ }
110
+ if(x.isComplex?.()){
111
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().modulo(y);
112
+ }
113
+ };
114
+
115
+ const add=(a,...b)=>{
116
+ let res = a;
117
+ for(let i=0; i<b.length; i++)
118
+ res = _add(res, b[i]);
119
+ return res;
120
+ };
121
+ const sub=(a,...b)=>{
122
+ let res = a;
123
+ for(let i=0; i<b.length; i++)
124
+ res = _sub(res, b[i]);
125
+ return res;
126
+ };
127
+ const mul=(a,...b)=>{
128
+ let res = a;
129
+ for(let i=0; i<b.length; i++)
130
+ res = _mul(res, b[i]);
131
+ return res;
132
+ };
133
+ const div=(a,...b)=>{
134
+ let res = a;
135
+ for(let i=0; i<b.length; i++)
136
+ res = _div(res, b[i]);
137
+ return res;
138
+ };
139
+ const modulo=(a,...b)=>{
140
+ let res = a;
141
+ for(let i=0; i<b.length; i++)
142
+ res = _modulo(res, b[i]);
143
+ return res;
144
+ };
145
+
146
+ const min$1 = (...x) => Math.min(...x);
147
+ const max$1 = (...x) => Math.max(...x);
148
+
149
+ const binomial = (n, k) =>{
150
+ if(n !== Math.floor(n)) return TypeError('n must be an integer');
151
+ if(k !== Math.floor(k)) return TypeError('k must be an integer');
152
+ if (n < 0) return TypeError('n must be non-negative');
153
+ if (k < 0 || n < 0 || k > n) return 0;
154
+ if (k > n - k) k = n - k;
155
+ let c = 1, i;
156
+ for (i = 0; i < k; i++)
157
+ c = c * (n - i) / (i + 1);
158
+ return c;
159
+ };
160
+
161
+ const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
162
+
163
+ const variance = (...x) => {
164
+ const n = x.length;
165
+ if (n === 0) return NaN;
166
+ const x_mean = mean(...x);
167
+ return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
168
+ };
169
+
170
+ const std = (...x) => Math.sqrt(variance(...x));
171
+
172
+ const accum_sum = (...x) => {
173
+ let result = [];
174
+ let total = 0, i, n = x.length;
175
+ for(i = 0; i < n ; i++){
176
+ total = add(total, x[i]);
177
+ result.push(total);
178
+ }
179
+ return result;
180
+ };
181
+
182
+ const accum_prod = (...x) => {
183
+ let result = [];
184
+ let prod = 1, i, n = x.length;
185
+ for(i = 0; i < n ; i++){
186
+ prod = mul(prod, x[i]);
187
+ result.push(prod);
188
+ }
189
+ return result;
190
+ };
191
+
192
+ const percentile = (X, p) => {
193
+ if (X.length === 0)
194
+ return NaN;
195
+ let a = [...X].sort((x, y) => x - y);
196
+ let index = (p / 100) * (a.length - 1);
197
+ let i = Math.floor(index);
198
+ let f = index - i;
199
+ if (i === a.length - 1)
200
+ return a[i];
201
+ return a[i] * (1 - f) + a[i + 1] * f;
202
+ };
203
+
204
+ const median = X => percentile(X, 50);
205
+
206
+ class Random {
207
+ static int(a, b){
208
+ return Math.floor(this.float(a, b));
209
+ }
210
+ static float(a, b){
211
+ return b !== undefined
212
+ ? Math.random() * (b - a) + a
213
+ : Math.random() * a;
214
+ }
215
+ static bin(){
216
+ return this.int(2);
217
+ }
218
+ static oct(){
219
+ return this.int(8);
220
+ }
221
+ static dec(){
222
+ return this.int(10);
223
+ }
224
+ static hex(){
225
+ return base2base(this.int(16), 10, 16);
226
+ }
227
+ static char(upperCase = false){
228
+ const i = upperCase
229
+ ? this.int(65, 91)
230
+ : this.int(97, 123);
231
+ return String.fromCharCode(i);
232
+ }
233
+ static bool(){
234
+ return Boolean(this.int(2));
235
+ }
236
+ static get color(){
237
+ return {
238
+ hex : () =>
239
+ `#${this.int(0xffffff).toString(16).padStart(6, '0')}`,
240
+
241
+ hexa : () => {
242
+ const [r,g,b,a] = Array.from(
243
+ {length:4},
244
+ () => this.int(0xff).toString(16).padStart(2,'0')
245
+ );
246
+ return `#${r}${g}${b}${a}`;
247
+ },
248
+ rgb : () => {
249
+ const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
250
+ return `rgb(${r}, ${g}, ${b})`;
251
+ },
252
+ rgba : () => {
253
+ const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
254
+ const a = Math.random().toFixed(2);
255
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
256
+ },
257
+ hsl : () => {
258
+ const h = this.int(360);
259
+ const s = this.int(100);
260
+ const l = this.int(100);
261
+ return `hsl(${h}, ${s}%, ${l}%)`;
262
+ },
263
+ hsla : () => {
264
+ const h = this.int(360);
265
+ const s = this.int(100);
266
+ const l = this.int(100);
267
+ const a = Math.random().toFixed(2);
268
+ return `hsla(${h}, ${s}%, ${l}%, ${a})`;
269
+ },
270
+ gray : () => {
271
+ const g = this.int(0xff);
272
+ return `rgb(${g}, ${g}, ${g})`;
273
+ }
274
+ };
275
+ }
276
+ static get sample(){
277
+ const R = this;
278
+ return {
279
+ int : (n,a,b) => Array.from({length:n}, () => R.int(a,b)),
280
+ float : (n,a,b) => Array.from({length:n}, () => R.float(a,b)),
281
+ char : (n,upper=false) => Array.from({length:n}, () => R.char(upper)),
282
+ bool : n => Array.from({length:n}, () => R.bool()),
283
+ bin : n => Array.from({length:n}, () => R.bin()),
284
+ oct : n => Array.from({length:n}, () => R.oct()),
285
+ dec : n => Array.from({length:n}, () => R.dec()),
286
+ hex : n => Array.from({length:n}, () => R.hex()),
287
+ get color(){
288
+ return {
289
+ hex : n => Array.from({length:n}, () => R.color.hex()),
290
+ hexa : n => Array.from({length:n}, () => R.color.hexa()),
291
+ rgb : n => Array.from({length:n}, () => R.color.rgb()),
292
+ rgba : n => Array.from({length:n}, () => R.color.rgba()),
293
+ hsl : n => Array.from({length:n}, () => R.color.hsl()),
294
+ hsla : n => Array.from({length:n}, () => R.color.hsla()),
295
+ gray : n => Array.from({length:n}, () => R.color.gray())
296
+ };
297
+ },
298
+ choice : (n, choices, p) =>
299
+ Array.from({length:n}, () => R.choice(choices, p))
300
+ };
301
+ }
302
+ static shuffle(arr){
303
+ return [...arr].sort(() => 0.5 - Math.random());
304
+ }
305
+ static choice(choices = [1,2,3], p = new Array(choices.length).fill(1 / choices.length)){
306
+ const acc = accum_sum(...p).map(v => v * 100);
307
+ const pool = new Array(100);
308
+ pool.fill(choices[0], 0, acc[0]);
309
+ for(let i=1;i<choices.length;i++)
310
+ pool.fill(choices[i], acc[i-1], acc[i]);
311
+ return pool[this.int(pool.length)];
312
+ }
313
+ }
314
+
315
+
316
+ globalThis.Random = Random;
317
+
318
+ // // (upperCase) => upperCase ? : String.fromCharCode(rand_int(97,120))
319
+ // class Random {
320
+ // static string(length,upperCase){
321
+ // return length instanceof Array?
322
+ // new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
323
+ // new Array(length).fill(0).map(() => this.char(upperCase)).join("");
324
+ // }
325
+
326
+ // }
327
+ // export{Random}
328
+
57
329
  class Complex{
58
330
  constructor(a = 0, b = 0) {
59
331
  if(a instanceof Complex){
@@ -131,7 +403,13 @@
131
403
  static Zero() {
132
404
  return new Complex(0, 0);
133
405
  }
134
- static Twidlle(N, K){
406
+ static get Random(){
407
+ return {
408
+ int : (a, b)=> new Complex(...Random.sample.int(2, a, b) ),
409
+ float : (a, b)=> new Complex(...Random.sample.float(2, a, b) ),
410
+ }
411
+ }
412
+ static Twiddle(N, K){
135
413
  const phi = -2 * Math.PI * K / N;
136
414
  return new Complex(
137
415
  Math.cos(phi),
@@ -631,89 +909,6 @@
631
909
  ...x
632
910
  );
633
911
 
634
- const _add = (x, y) =>{
635
- if(typeof x === 'number'){
636
- if(typeof y === 'number') return x + y;
637
- if(y.isComplex?.()) {
638
- return y.clone().add(x);
639
- }
640
- }
641
- if(x.isComplex?.()){
642
- if(typeof y === 'number' || y.isComplex?.()) return x.clone().add(y);
643
- }
644
- };
645
-
646
- const _sub = (x, y) =>{
647
- if(typeof x === 'number'){
648
- if(typeof y === 'number') return x - y;
649
- if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
650
- }
651
- if(x.isComplex?.()){
652
- if(typeof y === 'number' || y.isComplex?.()) return x.clone().sub(y);
653
- }
654
- };
655
-
656
- const _mul = (x, y) =>{
657
- if(typeof x === 'number'){
658
- if(typeof y === 'number') return x * y;
659
- if(y.isComplex?.()) return y.clone().mul(x);
660
- }
661
- if(x.isComplex?.()){
662
- if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
663
- }
664
- };
665
-
666
- const _div = (x, y) =>{
667
- if(typeof x === 'number'){
668
- if(typeof y === 'number') return x / y;
669
- if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
670
- }
671
- if(x.isComplex?.()){
672
- if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
673
- }
674
- };
675
-
676
- const _modulo = (x, y) =>{
677
- if(typeof x === 'number'){
678
- if(typeof y === 'number') return x % y;
679
- if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
680
- }
681
- if(x.isComplex?.()){
682
- if(typeof y === 'number' || y.isComplex?.()) return x.clone().modulo(y);
683
- }
684
- };
685
-
686
- const add=(a,...b)=>{
687
- let res = a;
688
- for(let i=0; i<b.length; i++)
689
- res = _add(res, b[i]);
690
- return res;
691
- };
692
- const sub=(a,...b)=>{
693
- let res = a;
694
- for(let i=0; i<b.length; i++)
695
- res = _sub(res, b[i]);
696
- return res;
697
- };
698
- const mul=(a,...b)=>{
699
- let res = a;
700
- for(let i=0; i<b.length; i++)
701
- res = _mul(res, b[i]);
702
- return res;
703
- };
704
- const div=(a,...b)=>{
705
- let res = a;
706
- for(let i=0; i<b.length; i++)
707
- res = _div(res, b[i]);
708
- return res;
709
- };
710
- const modulo=(a,...b)=>{
711
- let res = a;
712
- for(let i=0; i<b.length; i++)
713
- res = _modulo(res, b[i]);
714
- return res;
715
- };
716
-
717
912
  const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
718
913
  const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
719
914
 
@@ -734,64 +929,6 @@
734
929
  v => lerp(norm(v, a, b), c, d)
735
930
  );
736
931
 
737
-
738
- // export const norm = (x, min, max) => {
739
- // if(x.isComplex?.()) return new x.constructor(
740
- // norm(x.a, min, max),
741
- // norm(x.b, min, max)
742
- // )
743
- // if(x.isMatrix?.()) return new x.constructor(
744
- // x.rows,
745
- // x.cols,
746
- // norm(x.arr.flat(1), min, max)
747
- // );
748
- // if(x instanceof Array) return mapfun(n => norm(n, min, max), ...x);
749
- // return min !== max ? (x - min) / (max - min) : 0;
750
- // }
751
-
752
-
753
- // export const lerp = (x, min, max) => {
754
- // if(x.isComplex?.()) return new x.constructor(
755
- // lerp(x.a, min, max),
756
- // lerp(x.b, min, max)
757
- // )
758
- // if(x.isMatrix?.()) return new x.constructor(
759
- // x.rows,
760
- // x.cols,
761
- // lerp(x.arr.flat(1), min, max)
762
- // );
763
- // if(x instanceof Array) return mapfun(n => lerp(n, min, max), ...x);
764
- // return (max - min) * x + min;
765
- // }
766
-
767
- // export const map = (x, a, b, c, d) => {
768
- // if(x.isComplex?.()) return new x.constructor(
769
- // map(x.a, a, b, c, d),
770
- // map(x.b, a, b, c, d)
771
- // )
772
- // if(x.isMatrix?.()) return new x.constructor(
773
- // x.rows,
774
- // x.cols,
775
- // map(x.arr.flat(1), a, b, c, d)
776
- // );
777
- // if(x instanceof Array) return mapfun(n => map(n, a, b, c, d), ...x);
778
- // return lerp(norm(x, a, b), c, d);
779
- // }
780
-
781
- // export const clamp = (x, min, max) => {
782
- // if(x.isComplex?.()) return new x.constructor(
783
- // clamp(x.a, min, max),
784
- // clamp(x.b, min, max)
785
- // )
786
- // if(x.isMatrix?.()) return new x.constructor(
787
- // x.rows,
788
- // x.cols,
789
- // clamp(x.arr.flat(1), min, max)
790
- // );
791
- // if(x instanceof Array) return mapfun(n => clamp(n, min, max), ...x);
792
- // return Math.min(Math.max(x, min), max)
793
- // }
794
-
795
932
  const hypot = (...x) => {
796
933
  const c0 = x.find(a => a.isComplex?.());
797
934
  if (c0) {
@@ -816,53 +953,59 @@
816
953
  return rad ? phi : phi * 180 / Math.PI;
817
954
  };
818
955
 
819
- const min$1 = (...x) => Math.min(...x);
820
- const max$1 = (...x) => Math.max(...x);
956
+ const not = x => {
957
+ if(x.isComplex?.()) return new x.constructor(not(x.a), not(x.b))
958
+ if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, x.arr.flat(1).map(not))
959
+ return + !x;
960
+ };
961
+ const handle_complex_and_matrix = (x, operation) => {
962
+ if (x.every(n => n.isComplex?.())) {
963
+ const Re = x.map(n => n.a);
964
+ const Im = x.map(n => n.b);
965
+ return new x[0].constructor(
966
+ operation(...Re),
967
+ operation(...Im)
968
+ );
969
+ }
821
970
 
822
- const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
971
+ if (x.every(n => n.isMatrix?.())) {
972
+ if (!x.every(mat => mat.rows === x[0].rows && mat.cols === x[0].cols)) {
973
+ return TypeError('All matrices must have the same shape');
974
+ }
823
975
 
824
- const variance = (...x) => {
825
- const n = x.length;
826
- if (n === 0) return NaN;
827
- const x_mean = mean(...x);
828
- return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
829
- };
976
+ const { rows, cols } = x[0];
977
+ const Y = Array.from({ length: rows }, (_, i) =>
978
+ Array.from({ length: cols }, (_, j) =>
979
+ operation(...x.map(mat => mat.arr[i][j]))
980
+ )
981
+ );
982
+ return new x[0].constructor(Y);
983
+ }
830
984
 
831
- const std = (...x) => Math.sqrt(variance(...x));
985
+ return null; // Return null if no Complex or Matrix found
986
+ };
832
987
 
833
- const accum_sum = (...x) => {
834
- let result = [];
835
- let total = 0, i; n = x.length;
836
- for(i = 0; i < n ; i++){
837
- total = add(total, x[i]);
838
- result.push(total);
839
- }
840
- return result;
988
+ const and = (...x) => {
989
+ const result = handle_complex_and_matrix(x, and);
990
+ if (result !== null) return result;
991
+ return x.reduce((n, m) => (n &= m), 1);
841
992
  };
842
993
 
843
- const accum_prod = (...x) => {
844
- let result = [];
845
- let prod = 1, i; n = x.length;
846
- for(i = 0; i < n ; i++){
847
- prod = mul(prod, x[i]);
848
- result.push(prod);
849
- }
850
- return result;
994
+ const or = (...x) => {
995
+ const result = handle_complex_and_matrix(x, or);
996
+ if (result !== null) return result;
997
+ return x.reduce((n, m) => (n |= m), 0);
851
998
  };
852
999
 
853
- const percentile = (X, p) => {
854
- if (X.length === 0)
855
- return NaN;
856
- let a = [...X].sort((x, y) => x - y);
857
- let index = (p / 100) * (a.length - 1);
858
- let i = Math.floor(index);
859
- let f = index - i;
860
- if (i === a.length - 1)
861
- return a[i];
862
- return a[i] * (1 - f) + a[i + 1] * f;
1000
+ const xor = (...x) => {
1001
+ const result = handle_complex_and_matrix(x, xor);
1002
+ if (result !== null) return result;
1003
+ return x.reduce((n, m) => (n ^= m), 0);
863
1004
  };
864
1005
 
865
- const median = X => percentile(X, 50);
1006
+ const nand = (...x) => not(and(...x));
1007
+ const nor = (...x) => not(or(...x));
1008
+ const xnor = (...x) => not(xor(...x));
866
1009
 
867
1010
  const preload=(url)=>{
868
1011
  const xhr = new XMLHttpRequest();
@@ -3466,6 +3609,7 @@
3466
3609
  get inv() {
3467
3610
  return matrix_inverse(this)
3468
3611
  }
3612
+ // normalize names
3469
3613
  static eye(size) {
3470
3614
  let result = new Matrix(size, size);
3471
3615
  for (let i = 0; i < size; i++)
@@ -3490,6 +3634,20 @@
3490
3634
  for (let j = 0; j < cols; j++) result.arr[i][j] = number;
3491
3635
  return result;
3492
3636
  }
3637
+ static get Random(){
3638
+ return {
3639
+ int : (r, c, a, b)=> new Matrix(
3640
+ r,
3641
+ c,
3642
+ Random.sample.int(r*c, a, b)
3643
+ ),
3644
+ float : (r, c, a,)=> new Matrix(
3645
+ r,
3646
+ c,
3647
+ Random.sample.float(r*c, a, b)
3648
+ ),
3649
+ }
3650
+ }
3493
3651
  hstack(...matrices) {
3494
3652
  const M=[this, ...matrices].reduce((a,b)=>hstack(a, b));
3495
3653
  Object.assign(this, M);
@@ -3944,21 +4102,6 @@
3944
4102
  const matrix3=(...element)=>new Matrix(3, 3, element);
3945
4103
  const matrix4=(...element)=>new Matrix(4, 4, element);
3946
4104
 
3947
- const powerSet=originalSet=>{
3948
- const subSets = [];
3949
- const NUMBER_OF_COMBINATIONS = 2 ** originalSet.length;
3950
- for (let i = 0; i < NUMBER_OF_COMBINATIONS; i += 1) {
3951
- const subSet = [];
3952
- for (let j = 0; j < originalSet.length; j += 1) {
3953
- if (i & (1 << j)) {
3954
- subSet.push(originalSet[j]);
3955
- }
3956
- }
3957
- subSets.push(subSet);
3958
- }
3959
- return subSets;
3960
- };
3961
-
3962
4105
  const zeros=(n)=>new Array(n).fill(0);
3963
4106
  const ones=(n)=>new Array(n).fill(1);
3964
4107
  const nums=(num,n)=>new Array(n).fill(num);
@@ -4027,97 +4170,6 @@
4027
4170
  }
4028
4171
  };
4029
4172
 
4030
- // Mixed calcul
4031
- const sum=(...x)=>{
4032
- if(x.every(n=>typeof n==="number")){
4033
- let s = x[0];
4034
- for (let i = 1; i < x.length; i++) s += x[i];
4035
- return s;
4036
- }
4037
- const Y=[];
4038
- for(let i=0;i<x.length;i++){
4039
- if(x[i] instanceof Array)Y.push(sum(...x[i]));
4040
- else if(x[i] instanceof Object){
4041
- Y.push(sum(...Object.values(x[i])));
4042
- }
4043
- }
4044
- return Y.length===1?Y[0]:Y;
4045
- };
4046
- const prod=(...x)=>{
4047
- if(x.every(n=>typeof n==="number")){
4048
- let p = x[0];
4049
- for (let i = 1; i < x.length; i++) p *= x[i];
4050
- return p;
4051
- }
4052
- const Y=[];
4053
- for(let i=0;i<x.length;i++){
4054
- if(x[i] instanceof Array)Y.push(prod(...x[i]));
4055
- else if(x[i] instanceof Object){
4056
- Y.push(prod(...Object.values(x[i])));
4057
- }
4058
- }
4059
- return Y.length===1?Y[0]:Y;
4060
- };
4061
- // const min=(...num)=>{
4062
- // if(num.every(n=>typeof n==="number"))return Math.min(...num);
4063
- // const Y=[];
4064
- // for(let i=0;i<num.length;i++){
4065
- // if(num[i] instanceof Array)Y.push(min(...num[i]));
4066
- // else if(num[i] instanceof Object){
4067
- // Y.push(
4068
- // Object.fromEntries(
4069
- // [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
4070
- // )
4071
- // )
4072
- // }
4073
- // }
4074
- // return Y.length===1?Y[0]:Y;
4075
- // }
4076
- // const max=(...num)=>{
4077
- // if(num.every(n=>typeof n==="number"))return Math.max(...num);
4078
- // const Y=[];
4079
- // for(let i=0;i<num.length;i++){
4080
- // if(num[i] instanceof Array)Y.push(min(...num[i]));
4081
- // else if(num[i] instanceof Object){
4082
- // Y.push(
4083
- // Object.fromEntries(
4084
- // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
4085
- // )
4086
- // )
4087
- // }
4088
- // }
4089
- // return Y.length===1?Y[0]:Y;
4090
- // }
4091
- const accum=(...num)=>{
4092
- if(num.every(n=>typeof n==="number")){
4093
- let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
4094
- acc.shift();
4095
- return acc;
4096
- }
4097
- const Y=[];
4098
- for(let i=0;i<num.length;i++){
4099
- if(num[i] instanceof Array)Y.push(accum(...num[i]));
4100
- else if(num[i] instanceof Object){
4101
- Y.push(null
4102
- // Object.fromEntries(
4103
- // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
4104
- // )
4105
- );
4106
- }
4107
- }
4108
- return Y.length===1?Y[0]:Y;
4109
- };
4110
-
4111
- //moy
4112
- //med
4113
- //variance
4114
- //std
4115
- //mode
4116
- //acccum
4117
- //min2max
4118
- //max2min
4119
- //percentile
4120
-
4121
4173
  /** @module Math */
4122
4174
  /**
4123
4175
  * Checks if a value is within the specified range.
@@ -4230,369 +4282,6 @@
4230
4282
  isApproximatlyEqual
4231
4283
  };
4232
4284
 
4233
- // const subSet = (...arr) => {
4234
- // let list = arange(0, 2 ** arr.length, 1);
4235
- // let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
4236
- // let sub = bin.map((n) => n.map((m, i) => (m === 1 ? arr[i] : null))).map((n) => n.filter((x) => x !== null));
4237
- // return sub;
4238
- // };
4239
- const subSet = null;
4240
-
4241
- const Base={
4242
- _mode:Number,
4243
- _map:function(func,number,toBase){
4244
- if (number instanceof Matrix)
4245
- return new Matrix(
4246
- number.rows,
4247
- number.cols,
4248
- number.arr.flat(1).map(n=>func(n,toBase))
4249
- );
4250
- else if (number instanceof Complex) return new Complex(func(number.a,toBase),func(number.b,toBase));
4251
- else if (number instanceof Array) return number.map((n) =>func(n,toBase));
4252
- },
4253
- dec2base(dec,base){
4254
- base<=10?this._mode=Number:this._mode=String;
4255
- //this._mode=String
4256
- if (typeof dec === "number") return this._mode((dec >>> 0).toString(base));
4257
- return this._map(this.dec2base,dec,base)
4258
- },
4259
- dec2bin(dec){
4260
- return this.dec2base(dec,2);
4261
- },
4262
- dec2oct(dec){
4263
- return this.dec2base(dec,8);
4264
- },
4265
- dec2hex(dec){
4266
- return this.dec2base(dec,16);
4267
- },
4268
- bin2base(bin, base) {
4269
- return this.dec2base(this.bin2dec(bin),base)
4270
- },
4271
- bin2dec(bin){
4272
- return this._mode("0b"+bin);
4273
- },
4274
- bin2oct(bin){
4275
- return this.bin2base(bin,8);
4276
- },
4277
- bin2hex(bin){
4278
- return this.bin2base(bin,16);
4279
- },
4280
- oct2dec(oct){
4281
- return this._mode("0o"+oct);
4282
- },
4283
- oct2bin(oct){
4284
- return this.dec2bin(this.oct2dec(oct))
4285
- },
4286
- oct2hex(oct){
4287
- return this.dec2hex(this.oct2dec(oct))
4288
- },
4289
- oct2base(oct, base) {
4290
- return this.dec2base(this.oct2dec(oct),base)
4291
- },
4292
- hex2dec(hex){
4293
- return this._mode("0x"+hex);
4294
- },
4295
- hex2bin(hex){
4296
- return this.dec2bin(this.hex2dec(hex))
4297
- },
4298
- hex2oct(hex){
4299
- return this.dec2oct(this.hex2dec(hex))
4300
- },
4301
- hex2base(hex, base) {
4302
- return this.dec2base(this.hex2dec(hex),base)
4303
- },
4304
- IEEE32toDec(Bin){
4305
- let IEEE32=Bin.split(" ").join("").padEnd(32,"0");
4306
- let s=IEEE32[0];
4307
- let e=2**(+("0b"+IEEE32.slice(1,9))-127);
4308
- let m=IEEE32.slice(9,32).split("").map(n=>+n);
4309
- let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
4310
- let dec=(-1)**s*(1+M)*e;
4311
- return dec
4312
- },
4313
- IEEE64toDec(Bin){
4314
- let IEEE64=Bin.split(" ").join("").padEnd(64,"0");
4315
- let s=IEEE64[0];
4316
- let e=2**(+("0b"+IEEE64.slice(1,12))-1023);
4317
- let m=IEEE64.slice(13,64).split("").map(n=>+n);
4318
- let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
4319
- let dec=(-1)**s*(1+M)*e;
4320
- return dec;
4321
- }
4322
- };
4323
-
4324
- const Logic$1={
4325
- _mode:Number,
4326
- _map:function(func,a,b){
4327
- if (a instanceof Matrix)
4328
- return new Matrix(
4329
- a.rows,
4330
- a.cols,
4331
- a.arr.flat(1).map((n) => func(n, b))
4332
- );
4333
- else if (a instanceof Complex) return new Complex(func(a.a, b), func(a.b, b));
4334
- else if (a instanceof Array) return a.map((n) => func(n, b));
4335
- },
4336
- not:function(input){
4337
- if(["number","boolean"].includes(typeof input)) return Logic$1._mode(!input);
4338
- else return this._map(this.not,input)
4339
- },
4340
- and:function(a, ...b){
4341
- if(["number","boolean"].includes(typeof a))return Logic$1._mode(b.reduce((n, m) => (n &= m), a));
4342
- else return this._map(this.and,a,b)
4343
- },
4344
- or:function(a, ...b) {
4345
- if(["number","boolean"].includes(typeof a)) return Logic$1._mode(b.reduce((n, m) => (n |= m), a));
4346
- else return this._map(this.or,a,b);
4347
- },
4348
- nand:function(a, ...b) {
4349
- return this.not(this.and(a, b));
4350
- },
4351
- nor:function(a, ...b) {
4352
- return this.not(this.or(a, b));
4353
- },
4354
- xor:function(a,...b){
4355
- let arr=[a,...b];
4356
- if(["number","boolean"].includes(typeof a))return this._mode(arr.reduce((length,cur)=>{
4357
- if(+cur===1)length+=1;
4358
- return length;
4359
- },0)===1);
4360
- else return this._map(this.xor,a,b);
4361
- },
4362
- xnor:function(a,...b){
4363
- return Logic$1.not(Logic$1.xor(a,b))
4364
- }
4365
-
4366
- };
4367
-
4368
- class Permutation {
4369
- static withDiscount(arr, l = arr.length) {
4370
- if (l === 1) return arr.map((n) => [n]);
4371
- const permutations = [];
4372
- let smallerPermutations;
4373
- smallerPermutations = this.withDiscount(arr, l - 1);
4374
- arr.forEach((currentOption) => {
4375
- smallerPermutations.forEach((smallerPermutation) => {
4376
- permutations.push([currentOption].concat(smallerPermutation));
4377
- });
4378
- });
4379
- return permutations;
4380
- }
4381
- static withoutDiscount(arr) {
4382
- const l = arr.length;
4383
- if (l === 1) return arr.map((n) => [n]);
4384
- const permutations = [];
4385
- const smallerPermutations = this.withoutDiscount(arr.slice(1));
4386
- const firstOption = arr[0];
4387
- for (let i = 0; i < smallerPermutations.length; i++) {
4388
- const smallerPermutation = smallerPermutations[i];
4389
- for (let j = 0; j <= smallerPermutation.length; j++) {
4390
- const permutationPrefix = smallerPermutation.slice(0, j);
4391
- const permutationSuffix = smallerPermutation.slice(j);
4392
- permutations.push(permutationPrefix.concat([firstOption], permutationSuffix));
4393
- }
4394
- }
4395
- return permutations;
4396
- }
4397
- }
4398
-
4399
- class Combinaison {
4400
- static withDiscount(comboOptions, comboLength) {
4401
- if (comboLength === 1) {
4402
- return comboOptions.map((comboOption) => [comboOption]);
4403
- }
4404
- const combos = [];
4405
- comboOptions.forEach((currentOption, optionIndex) => {
4406
- const smallerCombos = this.withDiscount(comboOptions.slice(optionIndex), comboLength - 1);
4407
- smallerCombos.forEach((smallerCombo) => {
4408
- combos.push([currentOption].concat(smallerCombo));
4409
- });
4410
- });
4411
- return combos;
4412
- }
4413
- static withoutDiscount(comboOptions, comboLength) {
4414
- if (comboLength === 1) {
4415
- return comboOptions.map((comboOption) => [comboOption]);
4416
- }
4417
- const combos = [];
4418
- comboOptions.forEach((currentOption, optionIndex) => {
4419
- const smallerCombos = this.withoutDiscount(comboOptions.slice(optionIndex + 1), comboLength - 1);
4420
- smallerCombos.forEach((smallerCombo) => {
4421
- combos.push([currentOption].concat(smallerCombo));
4422
- });
4423
- });
4424
-
4425
- return combos;
4426
- }
4427
- }
4428
- const combinaison=(comboOptions, comboLength, discount=false)=>Combinaison[discount?"withDiscount":"withoutDiscount"](comboOptions, comboLength);
4429
-
4430
- class Random {
4431
- static float(a = 1, b) {
4432
- return b ? Math.random() * (b - a) + a : a * Math.random();
4433
- }
4434
- static int(a, b) {
4435
- return Math.floor(this.float(a, b));
4436
- }
4437
- static char(upperCase){
4438
- upperCase=upperCase??this.bool();
4439
- const Char=String.fromCharCode(this.int(97,120));
4440
- return upperCase?Char.toUpperCase():Char;
4441
- }
4442
- static bool(){
4443
- return [false,true][Math.floor(Math.random()*2)];
4444
- }
4445
- static string(length,upperCase){
4446
- return length instanceof Array?
4447
- new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
4448
- new Array(length).fill(0).map(() => this.char(upperCase)).join("");
4449
- }
4450
- static bin() {
4451
- return this.int(2);
4452
- }
4453
- static oct() {
4454
- return this.int(8);
4455
- }
4456
- static dec() {
4457
- return this.int(8);
4458
- }
4459
- static hex() {
4460
- return this.int(16);
4461
- }
4462
- static choice(choices = [1, 2, 3], p = new Array(choices.length).fill(1 / choices.length)) {
4463
- let newchoice = new Array(100);
4464
- p=Utils.accum(...p).map(n=>n*100);
4465
- newchoice.fill(choices[0], 0, p[0]);
4466
- for (let i = 1; i < choices.length; i++) newchoice.fill(choices[i], p[i - 1], p[i]);
4467
- return newchoice[this.int(newchoice.length - 1)];
4468
- }
4469
- static shuffleArr(arr){
4470
- return arr.sort(()=>0.5-Math.random())
4471
- }
4472
- static floats(n, a, b) {
4473
- return new Array(n).fill(0).map(() => this.float(a, b));
4474
- }
4475
- static ints(n, a, b) {
4476
- return new Array(n).fill(0).map(() => this.int(a, b));
4477
- }
4478
- static bools(n){
4479
- return new Array(n).fill(0).map(() => this.bool());
4480
- }
4481
- static bins(n) {
4482
- return new Array(n).fill(0).map(() => this.int(2));
4483
- }
4484
- static octs(n) {
4485
- return new Array(n).fill(0).map(() => this.int(8));
4486
- }
4487
- static decs(n) {
4488
- return new Array(n).fill(0).map(() => this.int(10));
4489
- }
4490
- static hexs(n) {
4491
- return new Array(n).fill(0).map(() => this.int(16));
4492
- }
4493
- static choices(n, choices, p) {
4494
- return new Array(n).fill(0).map(() => this.choice(choices, p));
4495
- }
4496
- static perm(...arr) {
4497
- // permutation
4498
- return arr.permS[this.int(arr.length)];
4499
- }
4500
- static color() {
4501
- return "#" + Base.dec2hex(this.float(16777216)).padStart(6,0);
4502
- }
4503
- static colors(n) {
4504
- return new Array(n).fill(null).map(()=>this.color());
4505
- }
4506
-
4507
- // Should be Moved to Matrix and Complex to avoid Circular dependencies
4508
- // static complex(a = [0,1], b = [0,1]) {
4509
- // return a instanceof Array?
4510
- // new Complex(
4511
- // this.float(a[0], a[1]),
4512
- // this.float(b[0], b[1])
4513
- // ):
4514
- // new Complex(
4515
- // ...this.floats(2,a,b)
4516
- // )
4517
-
4518
- // }
4519
- // static complexInt(a = [0,1], b = [0,1]) {
4520
- // return new Complex(
4521
- // this.int(a[0], a[1]),
4522
- // this.int(b[0], b[1])
4523
- // );
4524
- // }
4525
- // static complexBin() {
4526
- // return new Complex(...this.bins(2));
4527
- // }
4528
- // static complexOct() {
4529
- // return new Complex(...this.octs(2));
4530
- // }
4531
- // static complexDec() {
4532
- // return new Complex(...this.decs(10));
4533
- // }
4534
- // static complexHex() {
4535
- // return new Complex(...this.octs(2));
4536
- // }
4537
- // static complexes(n, a = 0, b = 1) {
4538
- // return new Array(n).fill(0).map(() => this.complex(a, b));
4539
- // }
4540
- // static complexesInt(n, a = 0, b = 1) {
4541
- // return new Array(n).fill(0).map(() => this.complexInt(a, b));
4542
- // }
4543
- // static complexesBin(n) {
4544
- // return new Array(n).fill(0).map(() => this.complexBin());
4545
- // }
4546
- // static complexesOct(n) {
4547
- // return new Array(n).fill(0).map(() => this.complexOct());
4548
- // }
4549
- // static complexesDec(n) {
4550
- // return new Array(n).fill(0).map(() => this.complexDec());
4551
- // }
4552
- // static complexesHex(n) {
4553
- // return new Array(n).fill(0).map(() => this.complexHex());
4554
- // }
4555
- // static matrix(r,c,min,max){
4556
- // return matrix(r,c,this.floats(r*c,min,max))
4557
- // }
4558
- // static matrixInt(r,c,min,max){
4559
- // return matrix(r,c,this.ints(r*c,min,max))
4560
- // }
4561
- // static matrixBin(r,c){
4562
- // return matrix(r,c,this.bins(r*c))
4563
- // }
4564
- // static matrixOct(r,c){
4565
- // return matrix(r,c,this.octs(r*c))
4566
- // }
4567
- // static matrixDec(r,c){
4568
- // return matrix(r,c,this.decs(r*c))
4569
- // }
4570
- // static matrixHex(r,c){
4571
- // return matrix(r,c,this.hex(r*c))
4572
- // }
4573
- // static matrixColor(r,c){
4574
- // return matrix(r,c,this.colors(r*c))
4575
- // }
4576
- // static matrixComplex(r,c,a,b){
4577
- // return matrix(r,c,this.complexes(r*c,a,b))
4578
- // }
4579
- // static matrixComplexInt(r,c,a,b){
4580
- // return matrix(r,c,this.complexesInt(r*c,a,b))
4581
- // }
4582
- // static matrixComplexBin(r,c){
4583
- // return matrix(r,c,this.complexesBin(r*c))
4584
- // }
4585
- // static matrixComplexOct(r,c){
4586
- // return matrix(r,c,this.complexesBin(r*c))
4587
- // }
4588
- // static matrixComplexDec(r,c){
4589
- // return matrix(r,c,this.complexesBin(r*c))
4590
- // }
4591
- // static matrixComplexHex(r,c){
4592
- // return matrix(r,c,this.complexesBin(r*c))
4593
- // }
4594
- }
4595
-
4596
4285
  const { PI, sqrt: sqrt$1, cos: cos$2, sin: sin$2, acos, pow } = Math;
4597
4286
 
4598
4287
  const linear = t => t;
@@ -5750,19 +5439,15 @@
5750
5439
  }
5751
5440
 
5752
5441
  exports.App = App;
5753
- exports.Base = Base;
5754
5442
  exports.Clock = Clock;
5755
- exports.Combinaison = Combinaison;
5756
5443
  exports.Complex = Complex;
5757
5444
  exports.E = E;
5758
5445
  exports.EPSILON = EPSILON;
5759
5446
  exports.FileBasedRouting = FileBasedRouting;
5760
5447
  exports.Flex = Flex;
5761
5448
  exports.HTMLWrapper = HTMLWrapper;
5762
- exports.Logic = Logic$1;
5763
5449
  exports.Matrix = Matrix;
5764
5450
  exports.PI = PI$1;
5765
- exports.Permutation = Permutation;
5766
5451
  exports.Random = Random;
5767
5452
  exports.SPA = SPA;
5768
5453
  exports.SVGWrapper = SVGWrapper;
@@ -5790,13 +5475,13 @@
5790
5475
  exports.ZikoUISuspense = ZikoUISuspense;
5791
5476
  exports.ZikoUIText = ZikoUIText;
5792
5477
  exports.abs = abs;
5793
- exports.accum = accum;
5794
5478
  exports.accum_prod = accum_prod;
5795
5479
  exports.accum_sum = accum_sum;
5796
5480
  exports.acos = acos$1;
5797
5481
  exports.acosh = acosh;
5798
5482
  exports.acot = acot;
5799
5483
  exports.add = add;
5484
+ exports.and = and;
5800
5485
  exports.animation = animation;
5801
5486
  exports.apply_fun = apply_fun;
5802
5487
  exports.arange = arange;
@@ -5819,12 +5504,12 @@
5819
5504
  exports.bind_touch_event = bind_touch_event;
5820
5505
  exports.bind_view_event = bind_view_event;
5821
5506
  exports.bind_wheel_event = bind_wheel_event;
5507
+ exports.binomial = binomial;
5822
5508
  exports.cartesianProduct = cartesianProduct;
5823
5509
  exports.cbrt = cbrt;
5824
5510
  exports.ceil = ceil;
5825
5511
  exports.clamp = clamp;
5826
5512
  exports.clock = clock;
5827
- exports.combinaison = combinaison;
5828
5513
  exports.complex = complex;
5829
5514
  exports.cos = cos$3;
5830
5515
  exports.cosh = cosh$2;
@@ -5898,11 +5583,14 @@
5898
5583
  exports.min = min$1;
5899
5584
  exports.modulo = modulo;
5900
5585
  exports.mul = mul;
5586
+ exports.nand = nand;
5587
+ exports.nor = nor;
5901
5588
  exports.norm = norm;
5902
5589
  exports.nthr = nthr;
5903
5590
  exports.nums = nums;
5904
5591
  exports.obj2str = obj2str;
5905
5592
  exports.ones = ones;
5593
+ exports.or = or;
5906
5594
  exports.out_back = out_back;
5907
5595
  exports.out_bounce = out_bounce;
5908
5596
  exports.out_circ = out_circ;
@@ -5916,10 +5604,8 @@
5916
5604
  exports.percentile = percentile;
5917
5605
  exports.pgcd = pgcd;
5918
5606
  exports.pow = pow$1;
5919
- exports.powerSet = powerSet;
5920
5607
  exports.ppcm = ppcm;
5921
5608
  exports.preload = preload;
5922
- exports.prod = prod;
5923
5609
  exports.rad2deg = rad2deg;
5924
5610
  exports.round = round;
5925
5611
  exports.sec = sec;
@@ -5933,8 +5619,6 @@
5933
5619
  exports.step = step;
5934
5620
  exports.step_fps = step_fps;
5935
5621
  exports.sub = sub;
5936
- exports.subSet = subSet;
5937
- exports.sum = sum;
5938
5622
  exports.svg2ascii = svg2ascii;
5939
5623
  exports.svg2img = svg2img;
5940
5624
  exports.svg2imgUrl = svg2imgUrl;
@@ -5965,6 +5649,8 @@
5965
5649
  exports.wait = wait;
5966
5650
  exports.waitForUIElm = waitForUIElm;
5967
5651
  exports.waitForUIElmSync = waitForUIElmSync;
5652
+ exports.xnor = xnor;
5653
+ exports.xor = xor;
5968
5654
  exports.zeros = zeros;
5969
5655
 
5970
5656
  }));