exact_scalar
Exact scalar arithmetic for ZX-calculus phase computations.
Implements exact arithmetic for complex numbers of the form
(a + be^(ipi/4) + ci + de^(-i*pi/4)) * 2^power
This representation enables exact computation of phases in ZX-calculus graphs without floating-point errors.
ExactScalarArray
ExactScalarArray(coeffs: Array, power: Array | None = None)
Bases: Module
flowchart TD
tsim.core.exact_scalar.ExactScalarArray[ExactScalarArray]
click tsim.core.exact_scalar.ExactScalarArray href "" "tsim.core.exact_scalar.ExactScalarArray"
Exact scalar array for ZX-calculus phase arithmetic using dyadic representation.
Represents values of the form (c_0 + c_1·ω + c_2·ω² + c_3·ω³) × 2^power where ω = e^(iπ/4). This enables exact computation without floating-point errors.
Attributes:
| Name | Type | Description |
|---|---|---|
coeffs | Array | Array of shape (..., 4) containing dyadic coefficients. |
power | Array | Array of powers of 2 for scaling. |
The value represented is (c_0 + c_1omega + c_2omega^2 + c_3omega^3) * 2^power where omega = e^{ipi/4}.
Source code in src/tsim/core/exact_scalar.py
163 164 165 166 167 168 169 170 171 172 173 | |
__mul__
__mul__(other: ExactScalarArray) -> ExactScalarArray
Element-wise multiplication.
Source code in src/tsim/core/exact_scalar.py
175 176 177 178 179 | |
prod
prod(axis: int = -1) -> ExactScalarArray
Compute product along the specified axis using associative scan.
Returns identity (1+0i with power 0) for empty reductions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis | int | The axis along which to compute the product. | -1 |
Returns:
| Type | Description |
|---|---|
ExactScalarArray | ExactScalarArray with the product computed along the axis. |
Source code in src/tsim/core/exact_scalar.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
sum
sum(axis: int = -1) -> ExactScalarArray
Sum elements along the specified axis using normalized pairwise adds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis | int | The axis along which to sum. | -1 |
Returns:
| Type | Description |
|---|---|
ExactScalarArray | ExactScalarArray with the sum computed along the axis. |
Source code in src/tsim/core/exact_scalar.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
to_complex
to_complex() -> jax.Array
Convert to complex number.
Source code in src/tsim/core/exact_scalar.py
232 233 234 235 236 | |