Packed Nat lanes #
A vector of d small naturals is stored as one big Nat in radix 2^w (lane zero least
significant), so that the Lean kernel, which evaluates Nat arithmetic through GMP, performs a
whole vector operation in a few big-integer steps. This module holds the lane primitives shared
by the spin-1 (SeedKernel.Spin1) and Ising (SeedKernel.Ising) checkers.
Everything here is executable arithmetic, checked by decide +kernel only (never
native_decide). Correctness of the primitives against a lane-by-lane specification is an open
obligation (SeedKernel/Obligations.lean); checked examples do not replace it.
Radix is 2^w; lane zero is least significant.
Instances For
Equations
- SeedKernel.pack w xs = List.foldr (fun (x acc : Nat) => x + acc <<< w) 0 xs
Instances For
A signed packed vector as a difference of two unsigned ones.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- SeedKernel.instReprSigned = { reprPrec := SeedKernel.instReprSigned.repr }
Equations
- SeedKernel.Signed.value w i x = ↑(SeedKernel.lane w i x.pos) - ↑(SeedKernel.lane w i x.neg)
Instances For
Equations
- SeedKernel.Signed.move w a b x = { pos := SeedKernel.move w a b x.pos, neg := SeedKernel.move w a b x.neg }
Instances For
Per-lane floor(x/2^s), for s <= w; masks inter-lane contamination.
Equations
- SeedKernel.floorUnsigned w d s x = x >>> s &&& (1 <<< (w - s) - 1) * SeedKernel.repunit w d
Instances For
Signed floor with a 2^biasBits offset. Preconditions: s<=biasBits<w, each negative limb <=2^biasBits and each positive limb+2^biasBits < 2^w.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reverse d lanes via ceil(log2 d) butterfly swaps, padded to a power of two.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One multiplication, provided every convolution coefficient is below the radix. For lanes <=M, d*M^2 < 2^w suffices. Reversal is O(log d) bitwise operations.
Equations
- SeedKernel.dot w d x y = SeedKernel.lane w (d - 1) (x * SeedKernel.reverseLanes w d y)
Instances For
Equations
- SeedKernel.signedDot w d x y = ↑(SeedKernel.dot w d x.pos y.pos) + ↑(SeedKernel.dot w d x.neg y.neg) - ↑(SeedKernel.dot w d x.pos y.neg) - ↑(SeedKernel.dot w d x.neg y.pos)
Instances For
Equations
- SeedKernel.gram w d vs = List.map (fun (x : Nat) => List.map (fun (y : Nat) => SeedKernel.dot w d x y) vs) vs
Instances For
Hoist reversal once per vector; k^2 dot products then use k^2 big multiplications.
Equations
- SeedKernel.gramPrepared w d vs = List.map (fun (x : Nat) => List.map (fun (y : Nat) => SeedKernel.lane w (d - 1) (x * y)) (List.map (SeedKernel.reverseLanes w d) vs)) vs
Instances For
Repeat a mask by doubling. This avoids huge integer divisions in reversal masks.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- SeedKernel.dotFast w d x y = SeedKernel.lane w (d - 1) (x * SeedKernel.reverseFast w d y)