phi_prune.register holds two registers side by side, a Zeckendorf register and a binary register. Each is a list of digits, least significant first, that local rewrite rules bring to its normal form. The module runs phi-prune's own multiply–accumulate step in each, so the two can be measured on the same sums.
FibonacciEncoder uses. The binary register weighs them 1, 2, 4, 8, ….This runs the module's rules in the page: from_int writes each number in normal form, digit-wise addition adds the two registers digit by digit with no carries, and each press of Next round fires one normalization round as normalize_rounds does, every rule that can fire with no two rules on the same digit, from the lowest position up. Digits read most significant on the left. Once a register is in normal form, click one of its digits to flip it.
A digit may exceed 1 for a while, as it does right after two registers are added digit by digit. These rules bring it back, and each keeps the value:
| Register | Rule | Identifier | Fires when | Rewrite | Identity |
|---|---|---|---|---|---|
| Zeckendorf | adjacent 1s rule | merge | d[k] and d[k+1] are at least 1 | d[k]−1, d[k+1]−1, d[k+2]+1 | F(k) + F(k+1) = F(k+2) |
| Zeckendorf | removal of 2 digits | split | d[k] is at least 2 | d[k]−2, d[k+1]+1, d[k−2]+1 | 2F(k) = F(k+1) + F(k−2) |
| binary | carry | carry | d[k] is at least 2 | d[k]−2, d[k+1]+1 | 2 · 2k = 2k+1 |
Here F(k) is the place value of digit k, so F(0) = 1 and F(1) = 2. At the bottom of the register the removal of 2 digits has nowhere two places down to go: at k = 1 it is 2 + 2 = 3 + 1, into d[2] and d[0], and at k = 0 it is 1 + 1 = 2, into d[1] alone.
A Zeckendorf carry also moves down, two places, while a binary carry only moves up. test_phi_carry_runs_down_binary_does_not holds both: apply([0, 0, 2], "split", 2) gives [1, 0, 0, 1], which is 2 · 3 = 5 + 1, and the binary carry gives [0, 0, 0, 1].
apply refuses a rule that cannot fire, at a position outside the register or on a digit too small to take from, so no digit ever goes below 0. rewrites lists every rule that can fire, and normalize fires them until none can, the lowest position first, or one at random with an rng, which stands in for self-timed hardware where any local rewrite may happen first.
Both rule sets are confluent: every order of firing reaches the same normal form, because each rule keeps the value and each value has one normal form. Neither register needs a clock to decide the order. tests/test_register.py checks this on 200 random registers, each brought to normal form in 10 random orders, and checks that every rule keeps the value on 500 random registers with digits from 0 to 3. test_add_exhaustive adds every pair of 6-digit registers in normal form of each kind and checks the sum and its normal form.
An n-digit string with no two adjacent 1s ends either in 0, after any such string of n − 1 digits, or in 01, after any such string of n − 2 digits. So the count Z(n) of such strings is Z(n − 1) + Z(n − 2), with Z(0) = 1 and Z(1) = 2, which gives 1, 2, 3, 5, 8, 13, 21, …, the register's own place values. In the standard numbering of the Fibonacci numbers, F(1) = F(2) = 1, Z(n) is F(n + 2), and by Binet's formula F(n + 2) is the nearest integer to φn+2/√5, which is about 1.171 · φn, with φ = 1.618…. Each Zeckendorf digit therefore carries log2 φ, about 0.694 bits, so holding a given number of levels takes about 1.44 times as many digits as binary.
From results/register/growth_rates.txt, printed by scripts/growth_rates.py in ezexe/p4-phi-experiments:
| Levels | Binary digits | Zeckendorf digits | Extra |
|---|---|---|---|
| 8 | 3 | 4 | 1 |
| 16 | 4 | 6 | 2 |
| 55 | 6 | 8 | 2 |
| 144 | 8 | 10 | 2 |
| 256 | 8 | 12 | 4 |
| 1024 | 10 | 15 | 5 |
| 8192 | 13 | 19 | 6 |
FibonacciEncoder(n_digits) quantizes to exactly these level counts: 6 digits give 21 levels, 8 give 55 and 10 give 144, since every integer from 0 to F(n + 2) − 1 has a Zeckendorf representation in n digits. test_phi_normal_form_matches_encoder checks that from_int and FibonacciEncoder.to_codeword agree on all 144 levels of 10 digits.
The Zeckendorf register fires more rules per sum than the binary register, and its carries spread both ways. test_phi_needs_more_rewrites_than_binary_for_the_same_values holds that over every sum of two values below 55, on average and in the worst case.
Rewrite steps per sum, lowest position first, from results/register/register_measure.txt, printed by scripts/register_measure.py:
| Values | Zeckendorf mean | Zeckendorf worst | Binary mean | Binary worst |
|---|---|---|---|---|
| below 21 | 2.20 | 9 | 1.33 | 5 |
| below 55 | 3.18 | 16 | 2.13 | 6 |
| below 144 | 4.17 | 25 | 2.80 | 8 |
normalize_rounds counts time instead of work. Each normalization round fires at once every rule it can without two rules touching the same digit, picked from the lowest position up, and the count of rounds stands in for the time a register takes to reach normal form when every cell rewrites itself in parallel. A self-timed register stops after the rounds a sum needs. A clocked register waits the worst case on every sum. The register's completion signal is a local scan: a register still on its way holds a digit above 1 or, in the Zeckendorf register, two adjacent 1s, and one in normal form holds neither.
Normalization rounds per sum, from the same file:
| Values | Zeckendorf width | mean | worst | Binary width | mean | worst |
|---|---|---|---|---|---|---|
| below 21 | 6 | 1.82 | 6 | 5 | 1.20 | 5 |
| below 55 | 8 | 2.32 | 7 | 6 | 1.72 | 6 |
| below 144 | 10 | 2.73 | 8 | 8 | 2.08 | 8 |
| below 610 | 13 | 3.20 | 11 | 10 | 2.51 | 10 |
test_normalization_rounds_self_timed_phi_against_clocked_binary fixes the row below 144: the Zeckendorf mean lies between 2.6 and 2.8 rounds, the binary mean between 2.0 and 2.2, both worst cases are 8, and binary's worst case over the Zeckendorf mean is above 2.9. That ratio compares a clocked binary register with a self-timed Zeckendorf one. A self-timed binary register reaches normal form sooner than the Zeckendorf register on every row.
Every binary digit pattern is a valid number, so a flipped bit in a binary register cannot be seen. A Zeckendorf register in normal form holds no two adjacent 1s, so a flip from 0 to 1 beside a 1 leaves a pattern that cannot be in normal form, and flip_detected reads it as corrupt. A flip from 1 to 0 always leaves a valid pattern and goes unseen.
correction_candidates lists the registers in normal form one change from 1 to 0 away from a corrupt one. A flip that lands between two 1s, 101 to 111, has one candidate and can be corrected. A lone 11 could have come from either cell, so it has two and can only be detected.
Zeckendorf normalization does not undo a flip. The rules keep the corrupted value and bring it to normal form, so a register brought to normal form after a flip is worth the original plus the flipped place value. test_normalizing_keeps_the_corrupted_value checks this for every detected flip of every 8-digit register, so the scan has to run before normalization.
Every single-bit flip of every register in normal form of each width, from results/register/register_measure.txt:
| Digits | Zeckendorf values | detected | correctable | Binary values | detected |
|---|---|---|---|---|---|
| 4 | 8 | 0.375 | 0.062 | 16 | 0.000 |
| 6 | 21 | 0.397 | 0.079 | 64 | 0.000 |
| 8 | 55 | 0.409 | 0.086 | 256 | 0.000 |
| 10 | 144 | 0.417 | 0.090 | 1024 | 0.000 |
| 13 | 610 | 0.424 | 0.094 | 8192 | 0.000 |
dot(levels, xs, kind) takes non-negative integer weight levels and activations and accumulates their dot product in one register. Each weight level is written in the register's own digits, and each of its digits that is 1 adds a partial product, the activation times that place value, to the accumulator by digit-wise addition, after which normalize_rounds brings the accumulator to normal form. A level's Hamming weight is therefore its number of additions. In binary a partial product x · 2k is a shift, wiring only. In a Zeckendorf register x · F(k) is a Fibonacci multiple of x, which dot takes as given and writes with from_int. Built in hardware, the multiples take additions, x · F(k) = x · F(k − 1) + x · F(k − 2), once per activation and shared by every weight it meets, and the notebook below counts their rounds with ladder_rounds. test_dot checks the exact sum and one addition for each digit that is 1 in each weight whose activation is not zero.
The Jupyter notebook notebooks/register_settling.ipynb in ezexe/p4-phi-experiments runs dot on one φ-pruned convolution layer, ResNet-18's layer3.0.conv1 with 256 output channels, 128 kept, and a fan-in of 1152, quantized per output channel. Its saved run used its fallback, Laplace-distributed synthetic weights of that shape and half-normal activations, since torchvision was not installed where it ran. It took 32 dot products, 8 kept channels by 4 patches, and counts rounds per dot product four ways: the Zeckendorf register self-timed, with the rounds of its Fibonacci multiples spread over the kept channels; a self-timed binary register; a clocked binary ripple-carry adder, which waits the accumulator's width on every addition, the bits of the largest sum the layer's fan-in can reach: 23 at 6 digits, 24 at 8 and 26 at 10; and a clocked carry-lookahead adder, which waits the base-2 logarithm of that width rounded up, 5 at each of the three.
Rounds per dot product, from the notebook's saved sections 4 and 5:
| Digits | Levels | Zeckendorf additions | Binary additions | Zeckendorf self-timed | Binary self-timed | Binary lookahead | Binary ripple |
|---|---|---|---|---|---|---|---|
| 6 | 21 | 2184 | 2518 | 7,147 | 6,196 | 12,589 | 57,911 |
| 8 | 55 | 2826 | 3513 | 9,551 | 8,634 | 17,563 | 84,304 |
| 10 | 144 | 3464 | 4007 | 12,065 | 9,853 | 20,035 | 104,183 |
At 10 digits the notebook reads: 3,464 additions per dot product against 4,007, which is 14% fewer; the self-timed Zeckendorf accumulator needs 8.64× fewer rounds than the clocked ripple adder and 1.66× fewer than the clocked lookahead adder; and the self-timed binary accumulator needs 0.82× the Zeckendorf rounds, since its additions reach normal form in 2.46 rounds on average against 3.41. Its section 6 flips each bit of each accumulator in normal form: 43.3% of 1030 single-bit flips are detected on the Zeckendorf side, and 0.0% of 730 on the binary side. These are rounds of the rewrite rules, not gate delays or a silicon measurement.
scripts/transformer_check.py in ezexe/p4-phi-experiments tests φ-pruning and the Zeckendorf representation of quantized weights on a character-level GPT with 4 layers, width 128 and MLP width 512, which learns the source of the standard library of the Python that runs it, on CPU. Per seed it trains dense for 1500 steps, prunes MLP hidden neurons one-shot and fine-tunes 300 steps with each mask fixed, and quantizes every Linear weight per output channel. The metric is bits per character on held-out files, lower being better. Its kill criteria are in its docstring, written before any run. Each result file is the record of one three-seed run, and a run on another Python trains on other text and gives other figures.
Means over the three seeds of low.json, high.json and delta.json, rounded as shown. The dense model reads 1.9985 bits per character, 2.0225, 1.9706 and 2.0025 by seed.
| Mask | Density | One-shot | Fine-tuned | Fine-tuned, minus the comparison, by seed |
|---|---|---|---|---|
| φ-pruning, neuron order | 0.494 | 2.6533 | 2.0689 | − 2 of every 4: +0.0166, +0.0131, +0.0179 |
| φ-pruning after reordering | 0.500 | 2.7236 | 2.0527 | − heaviest half: +0.0000, +0.0000, +0.0000 |
| 2 of every 4 | 0.500 | 2.6254 | 2.0530 | |
| heaviest half | 0.500 | 2.7236 | 2.0527 | |
| random half | 0.500 | 2.6885 | 2.0770 | |
| φ-pruning at a density of 0.25 | 0.250 | 3.5714 | 2.1801 | − 1 of every 4: +0.0009, +0.0005, +0.0003 |
| 1 of every 4 | 0.250 | 3.4960 | 2.1795 | |
| heaviest quarter | 0.250 | 3.6058 | 2.1796 | |
| φ-pruning on the pruned neurons | 0.750 | 2.1691 | 1.9986 | − 3 of every 4: −0.0009, +0.0007, −0.0003 |
| 3 of every 4 | 0.750 | 2.1645 | 1.9988 | |
| heaviest three quarters | 0.750 | 2.1998 | 1.9982 | |
| random three quarters | 0.750 | 2.2286 | 2.0115 | − heaviest three quarters: +0.0144, +0.0132, +0.0123 |
Reordering hidden neurons so ranks interleave does not change what the model computes, and for distinct scores of even count the φ-pruning mask it keeps is exactly the heaviest half. At 75% the (1,∞)-RLL constraint sits on the pruned neurons, so no two neighbouring neurons are both pruned.
Each count is the mean Hamming weight of a weight level, which is the number of partial products a multiplier adds per weight. Uniform affine levels are round((w − min) · scale) per output channel, computed by the script's own quantize_levels on the formula of the package's encode_tensor, except that its torch.round rounds ties to even where encode_tensor rounds them up. Sign-magnitude form writes the magnitude of a symmetric level. CSD is canonical signed digit form.
| Levels | Bits | Bits per character | Uniform affine: Zeckendorf | CSD | binary | Sign-magnitude: Zeckendorf | CSD | binary |
|---|---|---|---|---|---|---|---|---|
| 16 | 4.00 | 2.0279 | 1.695 | 1.832 | 2.000 | 1.018 | 1.134 | 1.154 |
| 21 | 4.39 | 2.0132 | 1.862 | 2.000 | 2.220 | 1.139 | 1.258 | 1.296 |
| 32 | 5.00 | 2.0055 | 2.098 | 2.193 | 2.500 | 1.340 | 1.470 | 1.566 |
| 55 | 5.78 | 2.0002 | 2.411 | 2.438 | 2.882 | 1.621 | 1.749 | 1.911 |
| 144 | 7.17 | 1.9987 | 2.963 | 2.938 | 3.584 | 2.133 | 2.201 | 2.542 |
| 377 | 8.56 | 1.9986 | 3.514 | 3.372 | 4.281 | 2.664 | 2.668 | 3.221 |
| 987 | 9.95 | 1.9985 | 4.066 | 3.845 | 4.948 | 3.213 | 3.143 | 3.924 |
The bits per character depend only on the level count: 6 Zeckendorf digits are 21 uniform levels, and the representations differ only in how many additions they cost. With uniform affine levels CSD takes the lead between 55 and 144 levels, where results/register/digit_counts_uniform.txt puts it for evenly spread levels. In sign-magnitude form the Zeckendorf representation holds through 377 levels, 2.664 against 2.668, and loses at 987.
--part delta trains a base model per seed on most of the training files, fine-tunes a copy for 300 steps on another tenth of them, and takes the delta of every Linear layer, the fine-tuned minus the base weights. Over the three seeds the general validation went from 2.1163 to 2.0165 bits per character, the held-out part of the fine-tuning files went from 1.6445 to 1.7124, and the delta's norm is 0.1459 of the weights' norm, so the fine-tune behaved as continued training of an undertrained base. Weights and deltas are both quantized symmetrically per output channel:
| Binary | Zeckendorf | CSD | Zeckendorf saving against CSD | |
|---|---|---|---|---|
| weights, 21 levels | 1.2280 | 1.0818 | 1.2000 | 0.0984 |
| delta, 21 levels | 1.2211 | 1.0770 | 1.1937 | 0.0978 |
| weights, 55 levels | 1.8272 | 1.5540 | 1.6834 | 0.0769 |
| delta, 55 levels | 1.8186 | 1.5481 | 1.6770 | 0.0768 |
Per seed the delta's saving minus the weights' saving is −0.021, −0.100 and −0.077 points at 21 levels, and +0.032, −0.053 and +0.010 points at 55 levels. Per-channel quantization divides each channel by its own largest value, so it sees only the shape of a spread, and the delta's spread has the shape of the weights'.
The same run codes the positions of the delta's largest entries with Fibonacci-coded gaps, Elias gamma, Elias delta and a fixed-length code. That part is on the Fibonacci codes page, beside phi_prune.delta, which writes a delta's kept positions as the same Fibonacci-coded gaps in a .phid file.
| Criterion, as registered | Result file | Verdict |
|---|---|---|
| K1: φ-pruning at 50% within σ of 2 of every 4 | difference 0.0159, σ 0.0247 | survives as registered; the paired reading is worse in every seed |
| K2: φ-pruning at 25% beats 1 of every 4 by more than σ | difference −0.0006, σ 0.0239 | killed |
| K3: φ-pruning after reordering within σ of the heaviest half | difference 0.0000, σ 0.0234 | survives; the two masks are the same mask |
| K4: Zeckendorf Hamming weight below CSD's at 21 uniform affine levels | difference −0.1383 | survives |
| K5: φ-pruning on the pruned neurons below 3 of every 4 in every seed | difference −0.0002 | killed |
| K6: Zeckendorf Hamming weight below CSD's at 144 uniform affine levels | difference +0.0241 | killed |
| K7: a larger saving against CSD on the delta than on the weights, 21 levels | difference −0.0007 | killed |
| K8: Fibonacci-coded gaps below Elias gamma and a fixed-length code at 10% kept | difference −0.3689 bits | survives, in every seed |
The module's tests run with the package's own suite, from lbiza/ in a checkout of ezexe/phi:
python -m pytest tests/test_register.py
The measurements, the notebook and the transformer check are in ezexe/p4-phi-experiments under experiments/phi-register/, whose README gives the command that writes each result file.