Documentation

SeedKernel.Packed

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.

def SeedKernel.lane (w i x : Nat) :

Radix is 2^w; lane zero is least significant.

Equations
Instances For

    Every one of the d lanes equal to one.

    Equations
    Instances For
      def SeedKernel.pack (w : Nat) (xs : List Nat) :
      Equations
      Instances For
        def SeedKernel.move (w a b x : Nat) :

        Select and translate a set of source lanes by a fixed index displacement.

        Equations
        Instances For

          A signed packed vector as a difference of two unsigned ones.

          Instances For
            def SeedKernel.instDecidableEqSigned.decEq (x✝ x✝¹ : Signed) :
            Decidable (x✝ = x✝¹)
            Equations
            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                Equations
                Instances For
                  Equations
                  Instances For
                    Equations
                    Instances For
                      Equations
                      Instances For
                        Equations
                        Instances For

                          Per-lane floor(x/2^s), for s <= w; masks inter-lane contamination.

                          Equations
                          Instances For
                            def SeedKernel.floorSigned (w d s biasBits : Nat) (x : Signed) :

                            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
                                def SeedKernel.dot (w d x y : Nat) :

                                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
                                Instances For
                                  def SeedKernel.signedDot (w d : Nat) (x y : Signed) :
                                  Equations
                                  Instances For
                                    def SeedKernel.gram (w d : Nat) (vs : List Nat) :
                                    Equations
                                    Instances For

                                      Hoist reversal once per vector; k^2 dot products then use k^2 big multiplications.

                                      Equations
                                      Instances For
                                        def SeedKernel.reversalMask (w levels level : Nat) :

                                        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
                                            def SeedKernel.dotFast (w d x y : Nat) :
                                            Equations
                                            Instances For