hypercomplex-engine 0.4.0__py3-none-any.whl → 0.4.2__py3-none-any.whl

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.
@@ -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)
@@ -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]
hypercomplex/facade.py CHANGED
@@ -264,6 +264,11 @@ def multiply(
264
264
  # required, never inferred. Validate before anything else.
265
265
  if kind in ("split", "dual", "dual_split") and dim is None:
266
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)
267
272
 
268
273
  # Zero propagation
269
274
  if int(a[0]) == 0 or int(b[0]) == 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypercomplex-engine
3
- Version: 0.4.0
3
+ Version: 0.4.2
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
@@ -50,7 +50,6 @@ Dynamic: license-file
50
50
 
51
51
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
52
52
  [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
53
- [![Tests](https://img.shields.io/badge/tests-62%20passed-success)](#)
54
53
  [![GitHub Repo](https://img.shields.io/badge/GitHub-maher1719%2Fhypercomplex--engine-black?logo=github)](https://github.com/maher1719/hypercomplex-engine)
55
54
  [![PyPI version](https://badge.fury.io/py/hypercomplex-engine.svg)](https://pypi.org/project/hypercomplex-engine/)
56
55
  [![Downloads](https://static.pepy.tech/badge/hypercomplex-engine)](https://pepy.tech/project/hypercomplex-engine)
@@ -69,6 +68,11 @@ This library provides the computational substrate for high-dimensional hypercomp
69
68
 
70
69
  ---
71
70
 
71
+ ## Scope and limitations
72
+
73
+ If you build upon this package, please read fully [Go to Scope, Strengths, and Limitations](#scope-strengths-and-limitations) below for more information or check [Scope, Strengths, and Limitations file](README_scope_and_limitations.md#scope-strengths-and-limitations)
74
+
75
+
72
76
  ## 📄 Publications & Preprints
73
77
 
74
78
  This library serves as the formal verification substrate and computational engine for the following mathematical preprints:
@@ -1037,6 +1041,87 @@ hypercomplex-engine/
1037
1041
  └── pyproject.toml
1038
1042
  ```
1039
1043
 
1044
+ # Scope, strengths and limitations
1045
+
1046
+ > **Status: 0.4.x, pre-1.0.** The API can still change. Read this section before building on the package.
1047
+
1048
+ ## What this package is
1049
+
1050
+ It computes the product of two **signed basis elements** of a Cayley–Dickson algebra: `±e_i × ±e_j → ±e_k` (or zero in dual algebras). It is a low-level component, a sign and index calculator, not a number type. There are no coefficients, no sums, and no vectors.
1051
+
1052
+ ## Advantages
1053
+
1054
+ - **One job, small surface.** About 2,000 lines, one dependency (NumPy), and multipliers that keep no per-call state.
1055
+ - **Two interchangeable engines.**
1056
+ - `fast` is a closed-form bitwise evaluator. It does constant work per call for word-sized indices, and cost grows only with bit length for arbitrary-precision indices.
1057
+ - `holographic` is an O(n) recursive descent, useful as a cross-check.
1058
+ - **Works where tables cannot.** Only the two indices are needed, so indices hundreds of bits long are fine. Full tables need 4^n entries.
1059
+ - **Cross-validated.** The test suite checks the table builders, the `fast` engine and the `holographic` engine against each other.
1060
+ - **Strict about types.** `bool`, `float`, `str` and `list` inputs are rejected. Results are plain Python `int`s.
1061
+ - **Tested on Python 3.10–3.14** and with NumPy 1.22 and newer.
1062
+
1063
+ ## Input rules (0.4.x behavior)
1064
+
1065
+ | Kind | Element form | `dim` | Index range |
1066
+ |---|---|---|---|
1067
+ | `standard` | `(sign, index)` | not used | any integer ≥ 0 (no upper bound, since there is no `dim` to check against) |
1068
+ | `split` | `(sign, index)` | **required** | `0 ≤ index < 2**dim` |
1069
+ | `dual`, `dual_split` | `(sign, global_index)` or `(sign, local_index, eps)` | **required** | global: `0 ≤ i < 2**(dim+1)`; local: `0 ≤ i < 2**dim` |
1070
+
1071
+ - Elements must be **tuples**. Integers only, and NumPy integers are accepted.
1072
+ - `sign` should be `-1` or `+1`. Note: `multiply` currently also accepts `0` as a formal zero and returns zero. **Do not rely on this**; it may be removed.
1073
+ - Dual elements have two spellings of the same thing. At `dim=3`, `(1, 9)` and `(1, 1, 1)` both mean `+ε·e1` (global index `8 + 1`).
1074
+ - **Known looseness:** at `dim=3`, `(1, 9, 1)` and even `(1, 9, 0)` are also accepted and read as `+ε·e1`. The second one contradicts itself, so don't rely on it.
1075
+ - The dual result is always `(sign, local_index, eps)`, and `ε·ε` gives `(0, 0, 0)`.
1076
+
1077
+ ## What the package cannot detect (your responsibility)
1078
+
1079
+ Elements are plain tuples, so they do not remember which algebra produced them.
1080
+
1081
+ - Feeding a result from one `dim` into an algebra of a different `dim` is not detected if the index happens to be in range.
1082
+ - Mixing `standard` and `split` elements is not detected. The same tuple means different things: `e2·e2` is `-1` in the standard algebra, `+1` in `split` with `dim=2`, and `-1` in `split` with `dim>=3`.
1083
+ - For `standard`, nothing tells you an index is "too big for the octonions".
1084
+
1085
+ ## Not supported
1086
+
1087
+ - **No chain multiplication and no expressions.** `multiply` is strictly binary. You can pass a result into the next call yourself, but you choose the bracketing. From `n=3` (octonions) upward multiplication is **not associative**, so `(ab)c` and `a(bc)` can differ in sign.
1088
+ - **No coefficients, sums, vectors, arrays, or parsing** of expressions like `e1+e2+e12`. This is planned for a separate package built on top of this one.
1089
+ - **No addition, conjugation, norm, inverse, or division.**
1090
+ - **`split` means one split doubling on top of a standard parent.** Other sign patterns are not offered.
1091
+ - **`dual` and `dual_split`** extend a standard or split parent with a central `ε`, where `ε² = 0`.
1092
+
1093
+ ## Algebra facts to keep in mind
1094
+
1095
+ | n | Standard | Split |
1096
+ |---|---|---|
1097
+ | 1 | complex, commutative | split-complex, commutative, has zero divisors |
1098
+ | 2 | quaternions, associative, **not commutative** | split-quaternions, associative, not commutative |
1099
+ | 3 | octonions, alternative, **not associative** | split-octonions, alternative, not associative, has zero divisors |
1100
+ | ≥ 4 | sedenions and beyond: **zero divisors**, no longer alternative | no longer alternative |
1101
+
1102
+ ## Convention
1103
+
1104
+ Products follow the standard doubling `(a, b)(c, d) = (ac − d*b, da + bc*)` (split algebras flip the sign of the `d*b` term at the top level). Other conventions give isomorphic algebras with **different tables**, so comparing against another source may show sign differences after relabeling. For example, here `e1·e2 = e3` and `e1·e6 = −e7`.
1105
+
1106
+ ## Direct low-level classes
1107
+
1108
+ `FastStandard`, `FastSplit`, `FastDual`, `StandardHolographic`, `SplitHolographic` and `DualHolographic` are exported, but they validate **differently** from each other and from `multiply`. For example, `FastSplit` accepts a zero element while the other three reject it. Their `multiply_indices` methods do only minimal checks. **Prefer `multiply`.** These classes are not a stable API and are expected to become internal.
1109
+
1110
+ ## Tables and memory
1111
+
1112
+ Full tables have `4**n` entries. `build_table` refuses requests above a default memory budget (`max_bytes`, 256 MiB):
1113
+
1114
+ - `standard` and `split` are allowed up to `n = 13`.
1115
+ - `dual` and `dual_split` are allowed up to `n = 12`, since they are one doubling larger.
1116
+
1117
+ Use `estimate_table_bytes(kind, n)` to check a size, and pass a larger `max_bytes` (or `None`) if you really mean it. In dual tables, `sign == 0` marks `ε·ε`.
1118
+
1119
+ ## Stability and planned changes
1120
+
1121
+ - Pin your dependency, for example `hypercomplex-engine>=0.4.1,<0.5`.
1122
+ - *Planned for 0.5.0, subject to change:* stricter inputs (no zero elements, one dual form), and low-level classes made internal. Breaking changes will be listed in the release notes.
1123
+ - Do not treat the package as 1.0-stable until it has been used by futur a palnned package the vector-and-expression package.
1124
+
1040
1125
  ---
1041
1126
 
1042
1127
  # Citation
@@ -1,16 +1,16 @@
1
1
  hypercomplex/__init__.py,sha256=DM_jeWSzhDkdz8KboGrVQVqVaj6xkr8k22C_uNRRxr8,1010
2
- hypercomplex/facade.py,sha256=qneXgwLehlvec4f18jFQ_VnsTYmSiUoyswLqlE0nOes,9195
2
+ hypercomplex/facade.py,sha256=zuG5HnbDxBCn6V7OroaAhYYb4HzL-6QVaUQprhdDNwg,9528
3
3
  hypercomplex/core/__init__.py,sha256=7cD5SJFbAewuVMIvKnQ6tb7JwcmpGQktSvGbN5n8dIM,668
4
4
  hypercomplex/core/basis_element.py,sha256=TnPb1xLICv0TK0AfTW_I8_8T2TavktKTq4MEPLWnyU8,1402
5
5
  hypercomplex/core/basis_notation.py,sha256=K17IUXEio7KmY3pvpFdDFI2MsLs11-E5Z5Cp10CS84Y,4887
6
- hypercomplex/core/validation.py,sha256=_W23VmbWZh0OB7pIG4Pbm--N75Vdomh3hbHCRVXTTek,3165
6
+ hypercomplex/core/validation.py,sha256=1ehTiV2fuV9ahGaGcDswWqUJMBzmGcYQ-3wY8lbrd7k,3174
7
7
  hypercomplex/core/fast/__init__.py,sha256=6KsWo1dhNlT69jT_Bi8-khOrNFX9cDs98987TGTXo4w,173
8
8
  hypercomplex/core/fast/bit_utils.py,sha256=aqBjPX2srWym6AjxZqTzt998-in_-5VAxNUiQXUFAVw,385
9
- hypercomplex/core/fast/fast_dual.py,sha256=8y7U5pV2JIhMYtsiuLAaei977VUPo6DVx48kGH6DPoE,5223
9
+ hypercomplex/core/fast/fast_dual.py,sha256=Y5JFtGunb9p9qezogqPBWJfjNdiijtXV1LsKJXEENqY,5540
10
10
  hypercomplex/core/fast/fast_split.py,sha256=Wdr9pd9zXA_mFzlMxVv8LpPwDZJFP-XPVa0uQIEs3jA,3037
11
- hypercomplex/core/fast/fast_standard.py,sha256=S4ujHlp0Q_Z07jFKbpmFzrqYvf-zZTrIGm_LLwTwQUE,3306
11
+ hypercomplex/core/fast/fast_standard.py,sha256=KRZk7HPfV2J364p5x22kgveJa7ztucbsTla7emix_Kk,3308
12
12
  hypercomplex/core/holographic/__init__.py,sha256=TGMyPs6dyeaQ9I--rFooBOrKzkex73IbwzQtL7Q0i04,200
13
- hypercomplex/core/holographic/dual.py,sha256=6ntw2Uwz6hI18ogHrsC3e2XmZrkTb2qQy8hbMWqoV4E,2761
13
+ hypercomplex/core/holographic/dual.py,sha256=1JdYDPpFk7u0yMswDOxRhhEUcg4CDxCu3Rk-a1rDImA,2898
14
14
  hypercomplex/core/holographic/split.py,sha256=kJXPXvw3rT8YieENor0hNTko4qBoXaKKb9n07UWhfQY,2864
15
15
  hypercomplex/core/holographic/standard.py,sha256=nNgM0QxvWXVMlTenHdxKd63RvLOkF_xu1cB0f00EumA,3935
16
16
  hypercomplex/core/table_builder/__init__.py,sha256=qkKJQ1S44hlSeNdW-Cc9REvbCeU2K646pkCalV9Sft4,206
@@ -21,8 +21,8 @@ hypercomplex/core/table_builder/standard.py,sha256=3kyg4TLCG_LKhC8lT95hZBFmOee0W
21
21
  hypercomplex/printer/__init__.py,sha256=6EZOUBYb9TDgfqrFpnIfPS1bbPFZ0dMX6RCPDZepL6M,129
22
22
  hypercomplex/printer/cd_format.py,sha256=X_cotGumJlRMuJO5cbsnI8FA9Py12TGYftPlUdx-9xg,5731
23
23
  hypercomplex/printer/cd_table_printer.py,sha256=uQlSmiTYiJkLZ4wC0ezXm7RSCYlldva0YCF2reNfKq4,4882
24
- hypercomplex_engine-0.4.0.dist-info/licenses/LICENSE,sha256=guj-B90dY9uDtG1POm34JUQQ0HU3YE47dq8RmVY4znI,1066
25
- hypercomplex_engine-0.4.0.dist-info/METADATA,sha256=D1LIPbrrZ5azxrhQVngsB3Rhx0W6MCLzzMpkqosMx5A,19938
26
- hypercomplex_engine-0.4.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
27
- hypercomplex_engine-0.4.0.dist-info/top_level.txt,sha256=WTtGtCnGtWsHvFBLdcsO6VRbm4wa1kU3yV-HrypIdwE,13
28
- hypercomplex_engine-0.4.0.dist-info/RECORD,,
24
+ hypercomplex_engine-0.4.2.dist-info/licenses/LICENSE,sha256=guj-B90dY9uDtG1POm34JUQQ0HU3YE47dq8RmVY4znI,1066
25
+ hypercomplex_engine-0.4.2.dist-info/METADATA,sha256=22P_CHFCrXEM1oHqigTv-pZnT0L6sLTHOxi3pmPyUBc,25955
26
+ hypercomplex_engine-0.4.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
27
+ hypercomplex_engine-0.4.2.dist-info/top_level.txt,sha256=WTtGtCnGtWsHvFBLdcsO6VRbm4wa1kU3yV-HrypIdwE,13
28
+ hypercomplex_engine-0.4.2.dist-info/RECORD,,