hypercomplex-engine 0.0.4.1__tar.gz → 0.4.1__tar.gz

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.
Files changed (38) hide show
  1. {hypercomplex_engine-0.0.4.1/hypercomplex_engine.egg-info → hypercomplex_engine-0.4.1}/PKG-INFO +1 -1
  2. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_dual.py +12 -6
  3. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_split.py +2 -2
  4. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_standard.py +2 -2
  5. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/dual.py +4 -3
  6. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/validation.py +1 -0
  7. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/facade.py +14 -9
  8. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1/hypercomplex_engine.egg-info}/PKG-INFO +1 -1
  9. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/SOURCES.txt +3 -1
  10. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/pyproject.toml +1 -1
  11. hypercomplex_engine-0.4.1/tests/test_dual_tuple_regression.py +90 -0
  12. hypercomplex_engine-0.4.1/tests/test_split_dim.py +33 -0
  13. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/LICENSE +0 -0
  14. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/README.md +0 -0
  15. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/__init__.py +0 -0
  16. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/__init__.py +0 -0
  17. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/basis_element.py +0 -0
  18. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/basis_notation.py +0 -0
  19. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/__init__.py +0 -0
  20. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/bit_utils.py +0 -0
  21. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/__init__.py +0 -0
  22. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/split.py +0 -0
  23. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/standard.py +0 -0
  24. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/__init__.py +0 -0
  25. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/common.py +0 -0
  26. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/dual.py +0 -0
  27. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/split.py +0 -0
  28. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/standard.py +0 -0
  29. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/printer/__init__.py +0 -0
  30. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/printer/cd_format.py +0 -0
  31. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex/printer/cd_table_printer.py +0 -0
  32. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/dependency_links.txt +0 -0
  33. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/requires.txt +0 -0
  34. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/top_level.txt +0 -0
  35. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/setup.cfg +0 -0
  36. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/tests/test_fast_mode.py +0 -0
  37. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/tests/test_fixes_0_4.py +0 -0
  38. {hypercomplex_engine-0.0.4.1 → hypercomplex_engine-0.4.1}/tests/test_mega_mother.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypercomplex-engine
3
- Version: 0.0.4.1
3
+ Version: 0.4.1
4
4
  Summary: Fast O(1)/O(n) multiplication engine and table generator for ordinary, split, and dual Cayley-Dickson algebras.
5
5
  Author-email: Maher Ben Abdessalem <ba.maher94@gmail.com>
6
6
  License: MIT License
@@ -125,18 +125,24 @@ class FastDual:
125
125
  (final_sign, local_index, eps_flag)
126
126
  """
127
127
  dim = Validation.dimension(dim)
128
+ Validation.basis_tuple(t1, allow_zero=True, allow_eps=True)
129
+ Validation.basis_tuple(t2, allow_zero=True, allow_eps=True)
128
130
 
129
- s1, i = self._extract_global(t1, dim)
130
- s2, j = self._extract_global(t2, dim)
131
+
132
+
133
+ s1, i = int(t1[0]), int(t1[1])
134
+ s2, j = int(t2[0]), int(t2[1])
135
+ i_eps_flag = int(t1[2]) if len(t1) == 3 else 0
136
+ j_eps_flag = int(t2[2]) if len(t2) == 3 else 0
131
137
 
132
138
  if s1 == 0 or s2 == 0:
133
139
  return (0, 0, 0)
134
140
 
135
- sign, idx, eps = self.multiply_indices(i, j, dim)
141
+ sign, idx, eps = self.multiply_indices(i, j,dim,i_eps_flag,j_eps_flag)
136
142
 
137
143
  return (s1 * s2 * sign, idx, eps)
138
144
 
139
- def multiply_indices(self, i: int, j: int, dim: int) -> tuple:
145
+ def multiply_indices(self, i: int, j: int,dim:int, i_eps_flag=0 ,j_eps_flag=0) -> tuple:
140
146
  """
141
147
  Core dual O(1) multiplication using global indices.
142
148
 
@@ -156,8 +162,8 @@ class FastDual:
156
162
  if j < 0 or j >= total:
157
163
  raise ValueError(f"index must be in [0, {total - 1}] for dual dim={dim}, got {j}")
158
164
 
159
- i_eps = i >= half
160
- j_eps = j >= half
165
+ i_eps = i >= half or i_eps_flag
166
+ j_eps = j >= half or j_eps_flag
161
167
 
162
168
  i_loc = i & (half - 1)
163
169
  j_loc = j & (half - 1)
@@ -31,8 +31,8 @@ class FastSplit:
31
31
  t2 = (sign2, index2)
32
32
 
33
33
  dim:
34
- Algebra exponent.
35
- If None, it is inferred from the indices.
34
+ Algebra exponent (required; the result depends on it,
35
+ e.g. e2*e2 is +1 at dim=2 but -1 at dim>=3).
36
36
 
37
37
  Returns:
38
38
  (final_sign, index1 XOR index2)
@@ -28,8 +28,8 @@ class FastStandard:
28
28
  Returns:
29
29
  (final_sign, index1 XOR index2)
30
30
  """
31
- Validation.basis_tuple(t1, allow_zero=True, allow_eps=False)
32
- Validation.basis_tuple(t2, allow_zero=True, allow_eps=False)
31
+ Validation.basis_tuple(t1, allow_zero=False, allow_eps=False)
32
+ Validation.basis_tuple(t2, allow_zero=False, allow_eps=False)
33
33
 
34
34
  s1, i = int(t1[0]), int(t1[1])
35
35
  s2, j = int(t2[0]), int(t2[1])
@@ -48,7 +48,8 @@ class DualHolographic:
48
48
 
49
49
  s1, i = int(t1[0]), int(t1[1])
50
50
  s2, j = int(t2[0]), int(t2[1])
51
-
51
+ i_eps_flag = int(t1[2]) if len(t1) == 3 else 0
52
+ j_eps_flag = int(t2[2]) if len(t2) == 3 else 0
52
53
  # Zero propagates.
53
54
  if s1 == 0 or s2 == 0:
54
55
  return (0, 0, 0)
@@ -63,8 +64,8 @@ class DualHolographic:
63
64
 
64
65
  half = 1 << dim
65
66
 
66
- i_eps = i >= half
67
- j_eps = j >= half
67
+ i_eps = i >= half or i_eps_flag
68
+ j_eps = j >= half or j_eps_flag
68
69
 
69
70
  i_loc = i & (half - 1)
70
71
  j_loc = j & (half - 1)
@@ -59,6 +59,7 @@ class Validation:
59
59
 
60
60
  if len(data) == 3 and not allow_eps:
61
61
  raise ValueError("3-tuple epsilon form is not allowed here")
62
+
62
63
 
63
64
  sign = data[0]
64
65
  index = data[1]
@@ -89,7 +89,6 @@ def _normalize_engine(engine: str) -> str:
89
89
  aliases = {
90
90
  "fast": "fast",
91
91
  "constant": "fast",
92
- "fast": "fast",
93
92
  "bitwise": "fast",
94
93
  "o1":"fast",
95
94
 
@@ -254,12 +253,23 @@ def multiply(
254
253
  "holographic" O(n) descent, useful for verification
255
254
 
256
255
  dim:
257
- Required for dual and dual_split.
258
- Optional for split.
256
+ Required for split, dual and dual_split.
257
+ Not used for standard.
259
258
  """
260
259
  kind = _normalize_kind(kind)
261
260
  engine = _normalize_engine(engine)
262
261
 
262
+ # dim is part of the algebra's identity for split/dual kinds (e.g. e2*e2 is
263
+ # +e0 in split dim=2 but -e0 for every larger split algebra), so it is
264
+ # required, never inferred. Validate before anything else.
265
+ if kind in ("split", "dual", "dual_split") and dim is None:
266
+ raise ValueError(f"dim is required for {kind} multiplication")
267
+ # Validate inputs before any early return, so malformed data always
268
+ # raises ValidationError instead of leaking TypeError/IndexError.
269
+ allow_eps = kind in ("dual", "dual_split")
270
+ Validation.basis_tuple(a, allow_zero=True, allow_eps=allow_eps)
271
+ Validation.basis_tuple(b, allow_zero=True, allow_eps=allow_eps)
272
+
263
273
  # Zero propagation
264
274
  if int(a[0]) == 0 or int(b[0]) == 0:
265
275
  if kind in ("dual", "dual_split"):
@@ -267,10 +277,7 @@ def multiply(
267
277
  return (0, 0)
268
278
 
269
279
  # Dual inputs may be local 3-tuples: (sign, local_index, eps)
270
- if kind in ("split","dual", "dual_split"):
271
- if dim is None:
272
- raise ValueError("dim is required for dual multiplication")
273
-
280
+ if kind in ("dual", "dual_split"):
274
281
  a = _as_dual_global(a, dim)
275
282
  b = _as_dual_global(b, dim)
276
283
 
@@ -298,8 +305,6 @@ def multiply(
298
305
  return _standard_holo.multiply(a, b)
299
306
 
300
307
  if kind == "split":
301
- if dim is None:
302
- dim = max(int(a[1]), int(b[1])).bit_length()
303
308
  return _split_holo.multiply(a, b, dim)
304
309
 
305
310
  if kind == "dual":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypercomplex-engine
3
- Version: 0.0.4.1
3
+ Version: 0.4.1
4
4
  Summary: Fast O(1)/O(n) multiplication engine and table generator for ordinary, split, and dual Cayley-Dickson algebras.
5
5
  Author-email: Maher Ben Abdessalem <ba.maher94@gmail.com>
6
6
  License: MIT License
@@ -29,6 +29,8 @@ hypercomplex_engine.egg-info/SOURCES.txt
29
29
  hypercomplex_engine.egg-info/dependency_links.txt
30
30
  hypercomplex_engine.egg-info/requires.txt
31
31
  hypercomplex_engine.egg-info/top_level.txt
32
+ tests/test_dual_tuple_regression.py
32
33
  tests/test_fast_mode.py
33
34
  tests/test_fixes_0_4.py
34
- tests/test_mega_mother.py
35
+ tests/test_mega_mother.py
36
+ tests/test_split_dim.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hypercomplex-engine"
7
- version = "0.0.4.1"
7
+ version = "0.4.1"
8
8
  authors = [
9
9
  { name="Maher Ben Abdessalem", email="ba.maher94@gmail.com" },
10
10
  ]
@@ -0,0 +1,90 @@
1
+ """Regression tests for dual-engine tuple normalization and facade zero handling.
2
+
3
+ History:
4
+ - 0.4.0: DualHolographic ignored the eps flag while FastDual promoted it
5
+ (engines diverged on identical 3-tuple input).
6
+ - 0.4.0 hotfix attempt: DualHolographic read t[2] unconditionally, crashing
7
+ with IndexError on documented 2-tuple input and breaking the facade's
8
+ engine="holographic" dual path (which normalizes to 2-tuples).
9
+ - 0.4.1: both fixed; facade validates before zero-propagation.
10
+ """
11
+
12
+ import pytest
13
+
14
+ # Adjust these imports to whatever hypercomplex/__init__.py exports.
15
+ from hypercomplex import multiply, FastDual, DualHolographic
16
+ from hypercomplex.core.validation import Validation
17
+
18
+
19
+ # ---------- tuple normalization: engines must agree on identical input ----------
20
+
21
+ def _all_global_pairs(dim):
22
+ half = 1 << dim
23
+ for i in range(half << 1):
24
+ for j in range(half << 1):
25
+ yield (1, i, 1 if i >= half else 0), (1, j, 1 if j >= half else 0)
26
+
27
+
28
+ @pytest.mark.parametrize("dim", [0, 1, 2, 3])
29
+ def test_engines_agree_global_3tuples(dim):
30
+ fast, holo = FastDual(), DualHolographic()
31
+ for a, b in _all_global_pairs(dim):
32
+ assert fast.multiply(a, b, dim) == holo.multiply(a, b, dim)
33
+
34
+
35
+ @pytest.mark.parametrize("dim", [1, 2, 3])
36
+ def test_engines_agree_on_2tuples(dim):
37
+ """2-tuples are documented input; must not raise (the 0.4.0 regression)."""
38
+ fast, holo = FastDual(), DualHolographic()
39
+ for a, b in _all_global_pairs(dim):
40
+ a2, b2 = a[:2], b[:2] # strip the eps flag
41
+ assert fast.multiply(a2, b2, dim) == holo.multiply(a2, b2, dim)
42
+
43
+
44
+ @pytest.mark.parametrize("dim", [1, 2, 3])
45
+ def test_local_3tuple_matches_promoted_global(dim):
46
+ """(sign, local_index, eps=1) must equal (sign, local_index + half)."""
47
+ fast, holo = FastDual(), DualHolographic()
48
+ half = 1 << dim
49
+ for loc in range(half):
50
+ for j in range(half << 1):
51
+ for engine in (fast, holo):
52
+ assert engine.multiply((1, loc, 1), (1, j), dim) == \
53
+ engine.multiply((1, loc + half), (1, j), dim)
54
+
55
+
56
+ # ---------- facade routes, including the path that crashed ----------
57
+
58
+ @pytest.mark.parametrize("engine", ["fast", "holographic"])
59
+ def test_facade_dual_both_engines(engine):
60
+ assert multiply("dual", (1, 3), (1, 5), dim=3, engine=engine) == \
61
+ multiply("dual", (1, 3), (1, 5), dim=3, engine="fast")
62
+
63
+
64
+ def test_facade_dual_3tuple_promotion():
65
+ half = 1 << 3
66
+ for engine in ("fast", "holographic"):
67
+ assert multiply("dual", (1, 2, 1), (1, 1), dim=3, engine=engine) == \
68
+ multiply("dual", (1, 2 + half), (1, 1), dim=3, engine=engine)
69
+
70
+
71
+ # ---------- zero handling: validated, shape-correct, convention documented ----------
72
+
73
+ def test_facade_zero_shapes():
74
+ assert multiply("dual", (0, 2), (1, 3), dim=2) == (0, 0, 0)
75
+ assert multiply("dual_split", (1, 2), (0, 3), dim=2) == (0, 0, 0)
76
+ assert multiply("standard", (0, 2), (1, 3), dim=2) == (0, 0) # formal zero
77
+ assert multiply("split", (0, 2), (1, 3), dim=2) == (0, 0)
78
+
79
+
80
+ def test_facade_malformed_raises_validation_error():
81
+ with pytest.raises((TypeError, ValueError)):
82
+ multiply("dual", 5, (1, 1), dim=2) # not a tuple
83
+ with pytest.raises((TypeError, ValueError)):
84
+ multiply("standard", (1, 2, 3, 4), (1, 1)) # wrong arity
85
+
86
+ # ---------- nilpotency still intact ----------
87
+
88
+ @pytest.mark.parametrize("engine", ["fast", "holographic"])
89
+ def test_nilpotency(engine):
90
+ assert multiply("dual", (1, 1), (1, 1), dim=0, engine=engine) == (0, 0, 0)
@@ -0,0 +1,33 @@
1
+ """split/dual require an explicit dim; split rejects epsilon 3-tuples."""
2
+ import pytest
3
+ from hypercomplex import multiply
4
+
5
+
6
+ @pytest.mark.parametrize("engine", ["fast", "holographic"])
7
+ @pytest.mark.parametrize("kind", ["split", "dual", "dual_split"])
8
+ def test_dim_is_required_and_message_names_the_kind(kind, engine):
9
+ with pytest.raises(ValueError, match=f"dim is required for {kind}"):
10
+ multiply(kind, (1, 1), (1, 1), engine=engine)
11
+
12
+
13
+ @pytest.mark.parametrize("kind", ["split", "dual", "dual_split"])
14
+ def test_missing_dim_is_reported_even_for_zero_elements(kind):
15
+ with pytest.raises(ValueError, match="dim is required"):
16
+ multiply(kind, (0, 1), (1, 2))
17
+
18
+
19
+ @pytest.mark.parametrize("engine", ["fast", "holographic"])
20
+ def test_split_result_depends_on_dim(engine):
21
+ assert multiply("split", (1, 2), (1, 2), dim=2, engine=engine) == (1, 0)
22
+ for dim in (3, 4, 8):
23
+ assert multiply("split", (1, 2), (1, 2), dim=dim, engine=engine) == (-1, 0)
24
+
25
+
26
+ @pytest.mark.parametrize("eps", [0, 1])
27
+ def test_split_rejects_epsilon_three_tuples_with_clear_message(eps):
28
+ with pytest.raises(ValueError, match="3-tuple"):
29
+ multiply("split", (1, 1, eps), (1, 2), dim=2)
30
+
31
+
32
+ def test_standard_needs_no_dim():
33
+ assert multiply("standard", (1, 1), (1, 2)) == (1, 3)