← phi · docs

The register model

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.

Add two numbers in both registers

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.

The rules

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:

RegisterRuleIdentifierFires whenRewriteIdentity
Zeckendorfadjacent 1s rulemerged[k] and d[k+1] are at least 1d[k]−1, d[k+1]−1, d[k+2]+1F(k) + F(k+1) = F(k+2)
Zeckendorfremoval of 2 digitssplitd[k] is at least 2d[k]−2, d[k+1]+1, d[k−2]+12F(k) = F(k+1) + F(k−2)
binarycarrycarryd[k] is at least 2d[k]−2, d[k+1]+12 · 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.

Confluence

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.

How many digits a register needs

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:

LevelsBinary digitsZeckendorf digitsExtra
8341
16462
55682
1448102
2568124
102410155
819213196

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.

Work per sum

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:

ValuesZeckendorf meanZeckendorf worstBinary meanBinary worst
below 212.2091.335
below 553.18162.136
below 1444.17252.808

Normalization rounds

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:

ValuesZeckendorf widthmeanworstBinary widthmeanworst
below 2161.82651.205
below 5582.32761.726
below 144102.73882.088
below 610133.2011102.5110

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.

Single-bit errors

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:

DigitsZeckendorf valuesdetectedcorrectableBinary valuesdetected
480.3750.062160.000
6210.3970.079640.000
8550.4090.0862560.000
101440.4170.09010240.000
136100.4240.09481920.000

Multiply–accumulate in a register

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:

DigitsLevelsZeckendorf additionsBinary additionsZeckendorf self-timedBinary self-timedBinary lookaheadBinary ripple
621218425187,1476,19612,58957,911
855282635139,5518,63417,56384,304
101443464400712,0659,85320,035104,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.

A pre-registered check on a small transformer

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.

Pruning masks

MaskDensityOne-shotFine-tunedFine-tuned, minus the comparison, by seed
φ-pruning, neuron order0.4942.65332.0689− 2 of every 4: +0.0166, +0.0131, +0.0179
φ-pruning after reordering0.5002.72362.0527− heaviest half: +0.0000, +0.0000, +0.0000
2 of every 40.5002.62542.0530
heaviest half0.5002.72362.0527
random half0.5002.68852.0770
φ-pruning at a density of 0.250.2503.57142.1801− 1 of every 4: +0.0009, +0.0005, +0.0003
1 of every 40.2503.49602.1795
heaviest quarter0.2503.60582.1796
φ-pruning on the pruned neurons0.7502.16911.9986− 3 of every 4: −0.0009, +0.0007, −0.0003
3 of every 40.7502.16451.9988
heaviest three quarters0.7502.19981.9982
random three quarters0.7502.22862.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.

Hamming weight of the quantized weights

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.

LevelsBitsBits per characterUniform affine: ZeckendorfCSDbinarySign-magnitude: ZeckendorfCSDbinary
164.002.02791.6951.8322.0001.0181.1341.154
214.392.01321.8622.0002.2201.1391.2581.296
325.002.00552.0982.1932.5001.3401.4701.566
555.782.00022.4112.4382.8821.6211.7491.911
1447.171.99872.9632.9383.5842.1332.2012.542
3778.561.99863.5143.3724.2812.6642.6683.221
9879.951.99854.0663.8454.9483.2133.1433.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.

The delta of a fine-tuned model

--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:

BinaryZeckendorfCSDZeckendorf saving against CSD
weights, 21 levels1.22801.08181.20000.0984
delta, 21 levels1.22111.07701.19370.0978
weights, 55 levels1.82721.55401.68340.0769
delta, 55 levels1.81861.54811.67700.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.

The verdicts

Criterion, as registeredResult fileVerdict
K1: φ-pruning at 50% within σ of 2 of every 4difference 0.0159, σ 0.0247survives 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.0239killed
K3: φ-pruning after reordering within σ of the heaviest halfdifference 0.0000, σ 0.0234survives; the two masks are the same mask
K4: Zeckendorf Hamming weight below CSD's at 21 uniform affine levelsdifference −0.1383survives
K5: φ-pruning on the pruned neurons below 3 of every 4 in every seeddifference −0.0002killed
K6: Zeckendorf Hamming weight below CSD's at 144 uniform affine levelsdifference +0.0241killed
K7: a larger saving against CSD on the delta than on the weights, 21 levelsdifference −0.0007killed
K8: Fibonacci-coded gaps below Elias gamma and a fixed-length code at 10% keptdifference −0.3689 bitssurvives, in every seed

What the measurements show

Run it

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.