caelq-the-unfinished-light / docs /MATHEMATICAL_API.md
PureOne's picture
Publish CAELQ research release
fb02577 verified
|
Raw History Blame Contribute Delete
11.8 kB
# CAELQ mathematical API
This reference describes the public functions in `caelq.phase`, `caelq.signature`, `caelq.illumination`, and `caelq.dynamics`. They use Python's standard library. Run the examples from the project root with `src` on `PYTHONPATH`, or install the local package first. The executed walkthrough is `notebooks/CAELQ_Walkthrough.ipynb`.
Use integers and `fractions.Fraction` for exact numerical inputs. The signature and illumination modules reject floating-point coefficients. `phase.parity_law` currently converts its argument through `Fraction(s)`; an accidentally supplied float consequently represents its exact binary value, which can differ from the intended rational. Prefer `Fraction(1, 10)` to `0.1`.
These are finite reference implementations. Explicit phase laws, spans, tensor words, and leaf partitions can grow exponentially. Nothing here evaluates the ideal semantic horizon or certifies a limiting theorem by computation.
## 1. Phase algebra
Binary vectors are nonnegative integer bitmasks. Bit `j` is coordinate `j`; addition is XOR. A port subset uses the same encoding, but its bits index **ports**, not phase coordinates. `charges[i]` is column `i` of the binary matrix `W`. A constraint `h` imposes binary dot product `h·phase=0`. Width arguments prohibit out-of-range bits.
| Function | Result and contract |
|---|---|
| `gf2_basis(vectors)` | Canonical reduced basis as an integer tuple, with decreasing pivot positions. |
| `gf2_rank(vectors)` | Integer dimension of the span. |
| `gf2_contains(basis, vector)` | Boolean membership; the supplied basis need not be reduced. |
| `gf2_span(basis)` | All span elements in numerical order; exponential in rank. |
| `gf2_nullspace(rows, ncols)` | Basis of vectors orthogonal to all rows, within `ncols` bits. |
| `charge_sum(charges, subset)` | The phase charge `W(subset)`, as a bitmask. |
| `relation_basis(charges, phase_dimension=None)` | Basis of `ker(W)` in port coordinates. Omitted dimension is inferred from charge widths. |
| `seam_relation_basis(charges, phase_dimension, constraints=())` | Port relations surviving uniform phase on the constrained subspace `H`; equivalently `W(subset)` belongs to the constraint span. |
| `seam_increment(charges, phase_dimension, constraints=())` | Increase in relation-space dimension. |
| `program_seam(charges, phase_dimension, target_relations)` | Minimum-rank constraint basis realizing the supplied target span. Raises `ValueError` unless that span contains `ker(W)`. |
| `phase_moment(charges, subset, phase_dimension, constraints=(), shift=0)` | Exact product moment on the affine seam `shift+H`: `-1`, `0`, or `1`. |
| `parity_law(k, s)` | Dictionary of all sign tuples and their `Fraction` probabilities, `2**(-k)*(1+s*product(signs))`; requires `k>=1`, `-1<=s<=1`. |
The phase functions describe specified finite distributions. They do not automatically construct the manuscript's disjoint-block history coupling.
## 2. Tensor and curve algebra
`Word = tuple[int, ...]` uses zero-based axis indices. `Tensor = dict[Word, Fraction]` is sparse; missing coefficients mean zero. `()` is the scalar word, `(0,)` is axis `E`, and `(0,1)` is the ordered tensor `E⊗M`. Thus `{(0,1): Fraction(1), (1,0): Fraction(-1)}` encodes `[E,M]`. Word length is degree; the tensor unit is `{(): Fraction(1)}`. A `Vector` is a tuple of rational increments.
Multiplication concatenates words **chronologically**: increments `a` then `b` give `exp(a)*exp(b)`. The group commutator is `g*h*g^-1*h^-1`; the Lie bracket is `A*B-B*A`. All requested degrees are nonnegative integers. Operations assume correctly encoded word keys; scalar normalization alone does not certify that an arbitrary supplied tensor is a path signature.
| Function | Result and contract |
|---|---|
| `tensor_unit()` | Scalar unit tensor. |
| `tensor_add(*tensors)` | Exact sum, omitting zero coefficients. |
| `tensor_scale(tensor, scale)` | Exact scalar multiple. |
| `tensor_multiply(left, right, degree)` | Product truncated above `degree`. |
| `tensor_exp(tensor, degree)` | Truncated exponential; scalar component must be zero. |
| `tensor_log(group, degree)` | Truncated logarithm; scalar component must be one. |
| `tensor_inverse(group, degree)` | Truncated inverse; scalar component must be one. |
| `vector_tensor(increment)` | Degree-one tensor of a vector. |
| `straight_signature(increment, degree)` | Exponential of its degree-one tensor. |
| `path_signature(increments, degree)` | Product of straight signatures. Vectors share one positive dimension; the empty path returns the unit. |
| `group_commutator(left, right, degree)` | Group commutator with the convention above. |
| `lie_bracket(left, right, degree)` | Truncated tensor Lie bracket. |
| `nested_commutator(increments, degree=None)` | Right-nested commutator of generator exponentials. |
| `nested_lie(increments, degree=None)` | Right-nested bracket of degree-one generators. |
| `commutator_word(increments)` | Expanded chronological increment list; reversing a subword reverses order and negates increments. |
| `commutator_segment_count(order)` | Unsimplified word length `3*2**(order-1)-2`, for `order>=1`. |
| `circuit_signs(bits, orientation=1)` | Signs with total product `orientation`, which is `+1` or `-1`. Nonempty bits map to `1-2*bit`; the final sign closes the circuit. |
| `two_axis_generators(order, scale=1, shape=1, signs=None)` | For `k=order>=2`, first `k-1` vectors are signed `scale*shape*E`; last is signed `scale*shape**(1-k)*M`. Requires positive shape; signs default positive. |
| `coefficient(tensor, word)` | Exact coefficient, including zero for missing words. |
| `tensor_l1_norm(tensor)` | Sum of absolute coefficients, including the scalar. |
| `word_variation_l1(increments)` | Sum of coordinatewise absolute increments; equals Euclidean path length for axis segments. |
| `path_vertices(increments)` | Cumulative vertices including the origin; returns `[]` for empty input. |
Both nested functions require at least one generator and default to degree equal to generator count. At step `k`, the nested group commutator equals the exponential of the nested Lie bracket. Higher truncations generally expose additional terms. Generator deletion applies throughout its expanded word, not just to one occurrence.
## 3. Masses, probabilities, and expected light
Here `weights` means a nonempty iterable of strictly positive exact masses summing **exactly** to one. `signal=s` lies in `[-1,1]`; `epsilon` lies strictly between zero and one. Orders `k` are at least two. Invalid domains raise errors.
| Function | Result and contract |
|---|---|
| `bernoulli_masses(p, depth)` | Exact tuple of `2**depth` masses, lexicographic binary order; bit zero contributes `p`, bit one `1-p`. Requires `0<p<1`, integer `depth>=0`. |
| `central_mean_variance(weights, signal)` | Exact pair `(s, (1-s*s)*sum(w*w))` for independent leaf signs. |
| `effective_samples(weights)` | Exact `1/sum(w*w)`. |
| `prescribed_variation(weights, k)` | Numerical `c_k*sum(w**(1/k))`. |
| `sharp_variation_lower(weights, k)` | Numerical expression `c_k*N_eff**(1-1/k)`. |
| `sampling_lower_bound(epsilon)` | Exact necessary sample-count expression `(1-epsilon**2)/(4*epsilon**2)`, without integer rounding. |
| `parity_total_variation(epsilon)` | Exact distance `epsilon` between opposite parity laws. |
| `parity_relative_entropy(epsilon)` | Numerical natural-log divergence `epsilon*log((1+epsilon)/(1-epsilon))`. |
| `sample_parity(k, signal, rng)` | Complete sign tuple from the parity law using integer probability decisions. |
| `sample_weighted_anchor(weights, signal, rng)` | Exact rational weighted sum of independently drawn signs. |
| `mixed_germ_expected(k, degree, signal, mode)` | Exact truncated evaluation of a theoretical limiting expected germ; `mode` is `"common"` or `"independent"`. |
`rng` is an explicit `random.Random` instance. The probability protocol uses integer decisions; the generator remains pseudorandom. Numerical root and entropy outputs are floats, not interval certificates. In particular, `sharp_variation_lower` is not guaranteed to round downward.
The sampling bound assumes a fixed number of independent complete-vector samples, equal priors, and average error at most `1/4`. Common leaf signs instead have anchor variance `1-s*s`. For `L=[E,[E,...,M]]`, the two limiting expected germs are `(1+s)/2*exp(L)+(1-s)/2*exp(-L)` and `exp(s*L)`. These formulas do not give full finite-partition signatures. Their expected degree-`k` summaries agree; degree `2*k` distinguishes them when `|s|<1`.
## 4. Finite cusp dynamics and the semantic boundary
`Seam(depth, sign)` requires integer depth at least three and sign `±1`. Its exact properties are `epsilon=4**(-depth)`, `defect=sign*epsilon`, and `parameter=1/4+defect`. `analytic_classification` is `"bounded"` for negative sign and `"escaping"` for positive sign, by the stated real-seam theorem.
| Function | Result and contract |
|---|---|
| `seam_product(left, right)` | `Seam(left.depth+right.depth, -left.sign*right.sign)`; defects multiply with a minus sign. |
| `escape_bounds(depth)` | `EscapeBounds` for `(pi/4)*2**depth <= N < 2*pi*2**depth+3`. |
| `finite_prefix_gap_bound(depth, steps)` | Exact `2*steps*4**(-depth)`; requires `0<=steps<=2**(depth-2)`. |
| `observe_escape(depth, *, sign=1, precision=80, max_steps=1_000_000)` | Capped `Decimal` orbit observation. |
| `iterate_seam(depth, sign, steps, *, precision=80)` | Tuple of `Decimal` values including `z_0=0`, stopping early at `z>2`. |
| `toy_horizon(budget)` | Exact finite grammar maximum plus one for `E=1\|E+E\|E*E`, with at most `budget>=1` syntax nodes. |
| `semantic_horizon(budget)` | Always raises `SemanticOracleRequired` for valid nonnegative budgets. |
The recurrence is `z[n+1]=z[n]**2+parameter`. Indices start at zero: `crossing_index` first records `z>=1`; `escape_index` first records `z>2`. `EscapeObservation` also exposes `depth`, `sign`, `steps`, `last_value`, `precision`, `escaped`, and `status`. Missing crossings are `None`. Status is `"observed_escape"` or `"unresolved"`; reaching the cap never proves boundedness.
`EscapeBounds` stores `depth`, exact `lower_pi_factor`, `upper_pi_factor`, and `upper_offset`; `as_floats()` returns numerical endpoints. Orbit precision must be at least `max(30, ceil(2*depth*log10(2))+12)`. This guard preserves the defect, without providing interval certification. The finite grammar is a separate definition, with no claimed approximation theorem for the ideal semantic horizon.
## 5. Three tiny examples
### Exact circuit and orientation
```python
from caelq.phase import relation_basis, phase_moment
charges = (1, 2, 3)
assert relation_basis(charges, 2) == (7,)
assert phase_moment(charges, 3, 2) == 0
assert phase_moment(charges, 7, 2) == 1
```
### Conserved area and synchronization
```python
from fractions import Fraction
from caelq.signature import two_axis_generators, nested_commutator, coefficient
from caelq.illumination import mixed_germ_expected
area = nested_commutator(two_axis_generators(2, shape=3), degree=2)
assert coefficient(area, (0, 1)) == 1
common = mixed_germ_expected(2, 4, Fraction(1, 3), "common")
independent = mixed_germ_expected(2, 4, Fraction(1, 3), "independent")
assert coefficient(common, (0, 1, 0, 1)) == Fraction(1, 2)
assert coefficient(independent, (0, 1, 0, 1)) == Fraction(1, 18)
```
### Capped observation and explicit refusal
```python
from caelq.dynamics import observe_escape, semantic_horizon, SemanticOracleRequired
assert observe_escape(8, max_steps=64).status == "unresolved"
assert observe_escape(8, max_steps=2048).escape_index == 802 # Numerical observation.
try:
semantic_horizon(8)
except SemanticOracleRequired as error:
print(error)
```