numz 0.8.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numz",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "scientific computing with zikojs",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,9 +26,9 @@
26
26
  "@rollup/plugin-node-resolve": "^16.0.3",
27
27
  "@rollup/plugin-terser": "^1.0.0",
28
28
  "cross-env": "^10.1.0",
29
- "rollup": "^4.63.0"
29
+ "rollup": "^4.63.1"
30
30
  },
31
31
  "dependencies": {
32
- "ziko": "^1.10.0"
32
+ "ziko": "^2.0.0-alpha.0"
33
33
  }
34
34
  }
@@ -0,0 +1,34 @@
1
+
2
+
3
+ export const bitmasks = (n) => {
4
+ const res = [];
5
+ for (let i = 0; i < 1 << n; i++) {
6
+ const mask = [];
7
+ for (let j = 0; j < n; j++) mask.push((i >> j) & 1);
8
+ res.push(mask);
9
+ }
10
+ return res;
11
+ };
12
+ export const subsets_by_mask = (arr) => {
13
+ const n = arr.length,
14
+ res = [];
15
+ for (let i = 0; i < 1 << n; i++) {
16
+ const subset = [];
17
+ for (let j = 0; j < n; j++) if ((i >> j) & 1) subset.push(arr[j]);
18
+ res.push(subset);
19
+ }
20
+ return res;
21
+ };
22
+ export const gray_code = (n) => {
23
+ if (n === 0) return [0];
24
+ const prev = gray_code(n - 1);
25
+ return [...prev, ...prev.map((x) => x | (1 << (n - 1)))];
26
+ };
27
+ export const hamming_weight = (x) => {
28
+ let count = 0;
29
+ while (x) {
30
+ x &= x - 1;
31
+ count++;
32
+ }
33
+ return count;
34
+ };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Converts a value from one numerical base to another.
3
+ *
4
+ * Supported bases are between 2 and 36.
5
+ *
6
+ * @param value Value to convert.
7
+ * @param fromBase Source base.
8
+ * @param toBase Target base.
9
+ *
10
+ * @example
11
+ * base2base("1010", 2, 10) // "10"
12
+ */
13
+ export declare function base2base(
14
+ value: string | number,
15
+ fromBase: number,
16
+ toBase: number
17
+ ): string;
18
+
19
+ /**
20
+ * Converts binary values to octal.
21
+ */
22
+ export declare function bin2oct(
23
+ ...x: (string | number)[]
24
+ ): string[];
25
+
26
+ /**
27
+ * Converts binary values to decimal.
28
+ */
29
+ export declare function bin2dec(
30
+ ...x: (string | number)[]
31
+ ): string[];
32
+
33
+ /**
34
+ * Converts binary values to hexadecimal.
35
+ */
36
+ export declare function bin2hex(
37
+ ...x: (string | number)[]
38
+ ): string[];
39
+
40
+ /**
41
+ * Converts octal values to binary.
42
+ */
43
+ export declare function oct2bin(
44
+ ...x: (string | number)[]
45
+ ): string[];
46
+
47
+ /**
48
+ * Converts octal values to decimal.
49
+ */
50
+ export declare function oct2dec(
51
+ ...x: (string | number)[]
52
+ ): string[];
53
+
54
+ /**
55
+ * Converts octal values to hexadecimal.
56
+ */
57
+ export declare function oct2hex(
58
+ ...x: (string | number)[]
59
+ ): string[];
60
+
61
+ /**
62
+ * Converts decimal values to binary.
63
+ */
64
+ export declare function dec2bin(
65
+ ...x: (string | number)[]
66
+ ): string[];
67
+
68
+ /**
69
+ * Converts decimal values to octal.
70
+ */
71
+ export declare function dec2oct(
72
+ ...x: (string | number)[]
73
+ ): string[];
74
+
75
+ /**
76
+ * Converts decimal values to hexadecimal.
77
+ */
78
+ export declare function dec2hex(
79
+ ...x: (string | number)[]
80
+ ): string[];
81
+
82
+ /**
83
+ * Converts hexadecimal values to binary.
84
+ */
85
+ export declare function hex2bin(
86
+ ...x: (string | number)[]
87
+ ): string[];
88
+
89
+ /**
90
+ * Converts hexadecimal values to octal.
91
+ */
92
+ export declare function hex2oct(
93
+ ...x: (string | number)[]
94
+ ): string[];
95
+
96
+ /**
97
+ * Converts hexadecimal values to decimal.
98
+ */
99
+ export declare function hex2dec(
100
+ ...x: (string | number)[]
101
+ ): string[];
@@ -0,0 +1,61 @@
1
+ export const base2base = (value, fromBase, toBase) => {
2
+ if (fromBase < 2 || fromBase > 36 || toBase < 2 || toBase > 36)
3
+ throw new TypeError('Base must be between 2 and 36');
4
+
5
+ const dec = parseInt(value, fromBase);
6
+ if (Number.isNaN(dec)) throw new TypeError('Invalid value for the given base');
7
+
8
+ return dec.toString(toBase);
9
+ };
10
+
11
+ export const bin2oct = (...x) => mapfun(
12
+ n => base2base(n, 2, 8),
13
+ ...x
14
+ )
15
+ export const bin2dec = (...x) => mapfun(
16
+ n => base2base(n, 2, 10),
17
+ ...x
18
+ )
19
+ export const bin2hex = (...x) => mapfun(
20
+ n => base2base(n, 2, 16),
21
+ ...x
22
+ )
23
+
24
+ export const oct2bin = (...x) => mapfun(
25
+ n => base2base(n, 8, 2),
26
+ ...x
27
+ )
28
+ export const oct2dec = (...x) => mapfun(
29
+ n => base2base(n, 8, 10),
30
+ ...x
31
+ )
32
+ export const oct2hex = (...x) => mapfun(
33
+ n => base2base(n, 8, 16),
34
+ ...x
35
+ )
36
+
37
+ export const dec2bin = (...x) => mapfun(
38
+ n => base2base(n, 10, 2),
39
+ ...x
40
+ )
41
+ export const dec2oct = (...x) => mapfun(
42
+ n => base2base(n, 10, 8),
43
+ ...x
44
+ )
45
+ export const dec2hex = (...x) => mapfun(
46
+ n => base2base(n, 10, 16),
47
+ ...x
48
+ )
49
+
50
+ export const hex2bin = (...x) => mapfun(
51
+ n => base2base(n, 16, 2),
52
+ ...x
53
+ )
54
+ export const hex2oct = (...x) => mapfun(
55
+ n => base2base(n, 16, 8),
56
+ ...x
57
+ )
58
+ export const hex2dec = (...x) => mapfun(
59
+ n => base2base(n, 16, 10),
60
+ ...x
61
+ )
@@ -1,34 +1,3 @@
1
-
2
-
3
- export const bitmasks = (n) => {
4
- const res = [];
5
- for (let i = 0; i < 1 << n; i++) {
6
- const mask = [];
7
- for (let j = 0; j < n; j++) mask.push((i >> j) & 1);
8
- res.push(mask);
9
- }
10
- return res;
11
- };
12
- export const subsets_by_mask = (arr) => {
13
- const n = arr.length,
14
- res = [];
15
- for (let i = 0; i < 1 << n; i++) {
16
- const subset = [];
17
- for (let j = 0; j < n; j++) if ((i >> j) & 1) subset.push(arr[j]);
18
- res.push(subset);
19
- }
20
- return res;
21
- };
22
- export const gray_code = (n) => {
23
- if (n === 0) return [0];
24
- const prev = gray_code(n - 1);
25
- return [...prev, ...prev.map((x) => x | (1 << (n - 1)))];
26
- };
27
- export const hamming_weight = (x) => {
28
- let count = 0;
29
- while (x) {
30
- x &= x - 1;
31
- count++;
32
- }
33
- return count;
34
- };
1
+ export * from './operations/index.js'
2
+ export * from './conversions/index.js'
3
+ export * from './algorithms/index.js'
@@ -0,0 +1,53 @@
1
+ import type { Complex } from "../../complex/indexxx
2
+ import { Matrix } from '../../matrix/index.jsssss
3
+
4
+ export type LogicValue = 0 | 1 | Complex | Matrix;
5
+
6
+ /**
7
+ * Logical NOT operation.
8
+ */
9
+ export declare const not: (
10
+ x: LogicValue
11
+ ) => LogicValue;
12
+
13
+ /**
14
+ * Logical AND operation.
15
+ */
16
+ export declare const and: (
17
+ ...x: LogicValue[]
18
+ ) => LogicValue;
19
+
20
+ /**
21
+ * Logical OR operation.
22
+ */
23
+ export declare const or: (
24
+ ...x: LogicValue[]
25
+ ) => LogicValue;
26
+
27
+ /**
28
+ * Logical XOR operation.
29
+ */
30
+ export declare const xor: (
31
+ ...x: LogicValue[]
32
+ ) => LogicValue;
33
+
34
+ /**
35
+ * Logical NAND operation.
36
+ */
37
+ export declare const nand: (
38
+ ...x: LogicValue[]
39
+ ) => LogicValue;
40
+
41
+ /**
42
+ * Logical NOR operation.
43
+ */
44
+ export declare const nor: (
45
+ ...x: LogicValue[]
46
+ ) => LogicValue;
47
+
48
+ /**
49
+ * Logical XNOR operation.
50
+ */
51
+ export declare const xnor: (
52
+ ...x: LogicValue[]
53
+ ) => LogicValue;
@@ -0,0 +1,54 @@
1
+ export const not = x => {
2
+ if(x.isComplex?.()) return new x.constructor(not(x.a), not(x.b))
3
+ if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, x.arr.flat(1).map(not))
4
+ return + !x;
5
+ }
6
+ const handle_complex_and_matrix = (x, operation) => {
7
+ if (x.every(n => n.isComplex?.())) {
8
+ const Re = x.map(n => n.a);
9
+ const Im = x.map(n => n.b);
10
+ return new x[0].constructor(
11
+ operation(...Re),
12
+ operation(...Im)
13
+ );
14
+ }
15
+
16
+ if (x.every(n => n.isMatrix?.())) {
17
+ if (!x.every(mat => mat.rows === x[0].rows && mat.cols === x[0].cols)) {
18
+ return TypeError('All matrices must have the same shape');
19
+ }
20
+
21
+ const { rows, cols } = x[0];
22
+ const Y = Array.from({ length: rows }, (_, i) =>
23
+ Array.from({ length: cols }, (_, j) =>
24
+ operation(...x.map(mat => mat.arr[i][j]))
25
+ )
26
+ );
27
+ return new x[0].constructor(Y);
28
+ }
29
+
30
+ return null; // Return null if no Complex or Matrix found
31
+ };
32
+
33
+ export const and = (...x) => {
34
+ const result = handle_complex_and_matrix(x, and);
35
+ if (result !== null) return result;
36
+ return x.reduce((n, m) => (n &= m), 1);
37
+ };
38
+
39
+ export const or = (...x) => {
40
+ const result = handle_complex_and_matrix(x, or);
41
+ if (result !== null) return result;
42
+ return x.reduce((n, m) => (n |= m), 0);
43
+ };
44
+
45
+ export const xor = (...x) => {
46
+ const result = handle_complex_and_matrix(x, xor);
47
+ if (result !== null) return result;
48
+ return x.reduce((n, m) => (n ^= m), 0);
49
+ };
50
+
51
+ export const nand = (...x) => not(and(...x));
52
+ export const nor = (...x) => not(or(...x));
53
+ export const xnor = (...x) => not(xor(...x));
54
+
@@ -1,4 +1,4 @@
1
+ export * from './bitwise/index.js'
1
2
  export * from './combination/index.js'
2
3
  export * from './permutation/index.js'
3
- export * from './sequences'
4
- export * from './bitwise'
4
+ export * from './sequences/index.js'
package/src/index.js CHANGED
@@ -3,6 +3,8 @@ export * from './random/index.js'
3
3
  export * from './complex/index.js'
4
4
  export * from './matrix/index.js'
5
5
  export * from './typed-matrix/index.js'
6
+ export * from './discret/bitwise/index.js'
6
7
  export * from './calculus/index.js'
7
8
  export * from './signal/index.js'
8
9
  export * from './stats/index.js'
10
+
@@ -1,4 +1,4 @@
1
- // import { base2base } from "../../../dep/--from-ziko/functions/conversions/index.js";
1
+ import { base2base } from "../discret/bitwise/conversions/index.js";
2
2
  import { accum_sum } from "../stats";
3
3
 
4
4
  export class Random {