Documentation

ScalarArray.UInt64.Program

In-place programs on UInt64Array #

UInt64Array.InPlace n α is a program that reads and writes an array of size n in place and returns a value of type α. It is a monad, and programs are built from:

A program runs on an array with a.runInPlace m or m.run a h, which make the array exclusive once, before the program runs. runForInThen, runForInRevThen and runForIn2Then run a single loop and hand its last accumulators and the new array to a continuation, without a result pair.

A tail program InPlace.Tail n γ is a program that ends by handing its result and the new array to a continuation k, which returns a γ, where run would return the pair of them: Tail.done x k ends it, Tail.bind m t runs an in-place program m before it, and Tail.readThen, Tail.writeThen, Tail.ite, Tail.dite and the loops Tail.forInBind, … are those of InPlace. The continuation runs inside the program's last loop, so its last accumulators reach k unboxed, and no result pair is built. A tail program runs with a.runInPlaceThen t, a.runInPlaceThenOf n h t or t.run a h, and on the window of a slice s in its array with s.runInPlaceThenOf n h t.

InPlace.zipForInFrom, for internal use, is the loop of the two-array updates zipModifyStride: it threads two states, one for each array.

Tail programs also have loops in continuation-passing style, Tail.forIn lo hi init body k and Tail.forInRev, with up to four variables in Tail.forIn2, Tail.forIn3, Tail.forIn4, and so on. Their body is itself a tail program, which ends by calling a continuation next on the next variables, and the loop ends with k. Each variable is an argument of the loop, so scalars stay unboxed, and a nested loop, whose k calls the outer next, compiles to mutually recursive loops with no allocation. They are specified by their one-step equations (Tail.forInFrom_eq, …).

The array is never visible to a program: InPlace and its state have private constructors, so the only code that touches the state is the code in this module, which passes it on linearly. That is what lets write store without checking that the array is exclusive. The in-place folds of ScalarArray.UInt64.InPlace are programs of this kind, and the notation inplace a do … of ScalarArray.Notation writes programs of this kind.

The loops must be the loops of this module. A program that calls itself recursively compiles to a closure for each step, and for in do notation boxes its mutable variables at each step, so both are much slower than forIn, whose step is inlined into one loop with unboxed accumulators. Likewise, if c then t else e on programs builds both branches as closures, where InPlace.ite branches inside the program.

Programs are specified by InPlace.run, whose behavior the run_* lemmas give. Each loop has a one-step equation (forInFrom_eq, forInRevFrom_eq, …), and each Bind loop and runFor*Then an _eq lemma in terms of the plain loop. bind_eq and pure_eq turn InPlace.bind and InPlace.pure, which the notation writes, into >>= and pure.

The state of an in-place program on arrays of size n: the array itself. Its constructor is private, so that no code outside this module can hold a state, or run a program on one.

Instances For
    structure ScalarArray.UInt64Array.InPlace (n : Nat) (α : Type u) :

    A program that reads and writes an array of size n in place and returns a value of type α. See the module documentation.

    Instances For
      @[inline]
      def ScalarArray.UInt64Array.InPlace.pure {n : Nat} {α : Type u} (x : α) :
      InPlace n α

      The program that returns x and leaves the array alone. Use pure.

      Instances For
        @[inline]
        def ScalarArray.UInt64Array.InPlace.bind {n : Nat} {α β : Type u} (m : InPlace n α) (f : α → InPlace n β) :
        InPlace n β

        Runs m, then f on its result. Use >>=.

        Instances For
          @[instance_reducible, inline]
          @[inline]

          The element at index i.

          Instances For
            @[inline]
            def ScalarArray.UInt64Array.InPlace.readThen {n : Nat} {α : Type u} (i : USize) (h : i.toNat < n) (k : UInt64 → InPlace n α) :
            InPlace n α

            read i h followed by k on the element, for a program k in any universe: read itself returns a UInt64, so in do notation it binds only in programs whose results are in Type.

            Instances For
              theorem ScalarArray.UInt64Array.InPlace.toNat_add_lt_of_window {n : Nat} {off len j : USize} (hw : off.toNat + len.toNat ≤ n) (hj : j.toNat < len.toNat) :
              (off + j).toNat < n

              The index off + j of the window of len elements at off is in bounds, for j < len. This is the bound that read and write need in a loop over a window.

              @[implemented_by _private.ScalarArray.UInt64.Program.0.ScalarArray.UInt64Array.InPlace.writeImpl]

              Stores v at index i. It compiles to one store, without checking that the array is exclusive: run made it exclusive, and only this module's code holds it since.

              Instances For
                @[inline]
                def ScalarArray.UInt64Array.InPlace.writeThen {n : Nat} {α : Type u} (i : USize) (h : i.toNat < n) (v : UInt64) (k : InPlace n α) :
                InPlace n α

                write i h v followed by k, for a program k in any universe: in write i h v >>= fun _ => k, the universe of write's PUnit is that of k.

                Instances For
                  @[inline]
                  def ScalarArray.UInt64Array.InPlace.ite {n : Nat} {α : Type u} (c : Prop) [Decidable c] (t e : InPlace n α) :
                  InPlace n α

                  Runs t if c holds and e otherwise. Unlike if c then t else e, which chooses a program and then runs it, it compiles to a branch inside one program, without building the programs of the two branches as closures.

                  Instances For
                    @[inline]
                    def ScalarArray.UInt64Array.InPlace.dite {n : Nat} {α : Type u} (c : Prop) [Decidable c] (t : c → InPlace n α) (e : ¬c → InPlace n α) :
                    InPlace n α

                    InPlace.ite where each branch takes the proof of its condition.

                    Instances For
                      @[inline]
                      def ScalarArray.UInt64Array.InPlace.run {n : Nat} {α : Type u} (m : InPlace n α) (a : UInt64Array) (h : a.size = n) :

                      Runs the program m on the array a, and returns its result and the new array. The array is made exclusive first, so it is copied once if it is shared, and updated in place otherwise.

                      Instances For

                        Loops #

                        theorem ScalarArray.UInt64Array.InPlace.forIn_le_succ {lo j hi : USize} (h : lo.toNat ≤ j.toNat) (hj : j < hi) :
                        lo.toNat ≤ (j + 1).toNat

                        The index of a step of forIn: lo ≤ j + 1 when lo ≤ j < hi.

                        @[inline]
                        def ScalarArray.UInt64Array.InPlace.forInFrom {n : Nat} {β : Type u} (lo hi j₀ : USize) (h : lo.toNat ≤ j₀.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                        InPlace n β

                        Runs body j hlo hj b for each j from j₀ up to hi - 1, threading the accumulator b from init. forIn is the case j₀ = lo. It is specified by forInFrom_eq.

                        Instances For
                          @[inline]
                          def ScalarArray.UInt64Array.InPlace.forIn {n : Nat} {β : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                          InPlace n β

                          Runs body j hlo hj b for each j from lo up to hi - 1, threading the accumulator b from init, and returns the last accumulator. The body gets both bounds of j. It runs no step when hi ≤ lo.

                          Instances For
                            @[inline]
                            def ScalarArray.UInt64Array.InPlace.forIn2From {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi j₀ : USize) (h : lo.toNat ≤ j₀.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                            InPlace n (β₁ × β₂)

                            forInFrom with two accumulators. It is specified by forIn2From_eq.

                            Instances For
                              @[inline]
                              def ScalarArray.UInt64Array.InPlace.forIn2 {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                              InPlace n (β₁ × β₂)

                              forIn with two accumulators, which the loop keeps as two arguments, so that each one stays unboxed when its type is a scalar, such as a carry and a borrow. A pair accumulator in forIn would be allocated at every step.

                              Instances For
                                theorem ScalarArray.UInt64Array.InPlace.forInRev_pred_lt {lo hi j : USize} (hj : j.toNat ≤ hi.toNat) (h : lo < j) :
                                (j - 1).toNat < hi.toNat

                                The index of a step of forInRev: j - 1 < hi when lo < j ≤ hi.

                                The index of a step of forInRev: lo ≤ j - 1 when lo < j.

                                @[inline]
                                def ScalarArray.UInt64Array.InPlace.forInRevFrom {n : Nat} {β : Type u} (lo hi j₀ : USize) (h : j₀.toNat ≤ hi.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                                InPlace n β

                                Runs body j hlo hj b for each j from j₀ - 1 down to lo, threading the accumulator b from init. forInRev is the case j₀ = hi. It is specified by forInRevFrom_eq.

                                Instances For
                                  @[inline]
                                  def ScalarArray.UInt64Array.InPlace.forInRev {n : Nat} {β : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                                  InPlace n β

                                  Runs body j hlo hj b for each j from hi - 1 down to lo, threading the accumulator b from init, and returns the last accumulator. The body gets both bounds of j. It runs no step when hi ≤ lo.

                                  Instances For
                                    @[inline]
                                    def ScalarArray.UInt64Array.InPlace.forInRev2From {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi j₀ : USize) (h : j₀.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                    InPlace n (β₁ × β₂)

                                    forInRevFrom with two accumulators. It is specified by forInRev2From_eq.

                                    Instances For
                                      @[inline]
                                      def ScalarArray.UInt64Array.InPlace.forInRev2 {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                      InPlace n (β₁ × β₂)

                                      forInRev with two accumulators, kept as two loop arguments like those of forIn2.

                                      Instances For

                                        Specification #

                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.size_run {n : Nat} {α : Type u} (m : InPlace n α) (a : UInt64Array) (h : a.size = n) :
                                        (m.run a h).snd.size = n

                                        run leaves the size unchanged.

                                        theorem ScalarArray.UInt64Array.InPlace.ext {n : Nat} {α : Type u} {m m' : InPlace n α} (h : ∀ (a : UInt64Array) (h : a.size = n), m.run a h = m'.run a h) :
                                        m = m'

                                        Two programs are equal when they run the same on every array.

                                        theorem ScalarArray.UInt64Array.InPlace.ext_iff {n : Nat} {α : Type u} {m m' : InPlace n α} :
                                        m = m' ↔ ∀ (a : UInt64Array) (h : a.size = n), m.run a h = m'.run a h
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.run_pure {n : Nat} {α : Type u} (x : α) (a : UInt64Array) (h : a.size = n) :
                                        (pure x).run a h = (x, a)
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.run_bind {n : Nat} {α β : Type u} (m : InPlace n α) (f : α → InPlace n β) (a : UInt64Array) (h : a.size = n) :
                                        (m >>= f).run a h = (f (m.run a h).fst).run (m.run a h).snd ⋯
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.run_read {n : Nat} (i : USize) (hi : i.toNat < n) (a : UInt64Array) (h : a.size = n) :
                                        (read i hi).run a h = (a[i.toNat], a)
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.run_readThen {n : Nat} {α : Type u} (i : USize) (hi : i.toNat < n) (k : UInt64 → InPlace n α) (a : UInt64Array) (h : a.size = n) :
                                        (readThen i hi k).run a h = (k a[i.toNat]).run a h
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.run_write {n : Nat} (i : USize) (hi : i.toNat < n) (v : UInt64) (a : UInt64Array) (h : a.size = n) :
                                        (write i hi v).run a h = (PUnit.unit, a.set i.toNat v ⋯)
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.run_writeThen {n : Nat} {α : Type u} (i : USize) (hi : i.toNat < n) (v : UInt64) (k : InPlace n α) (a : UInt64Array) (h : a.size = n) :
                                        (writeThen i hi v k).run a h = k.run (a.set i.toNat v ⋯) ⋯
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.ite_eq {n : Nat} {α : Type u} (c : Prop) [Decidable c] (t e : InPlace n α) :
                                        InPlace.ite c t e = if c then t else e
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.dite_eq {n : Nat} {α : Type u} (c : Prop) [Decidable c] (t : c → InPlace n α) (e : ¬c → InPlace n α) :
                                        InPlace.dite c t e = if h : c then t h else e h
                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.bind_eq {n : Nat} {α β : Type u} (m : InPlace n α) (f : α → InPlace n β) :
                                        m.bind f = m >>= f

                                        InPlace.bind is >>=, so that the lemmas about >>=, such as run_bind, apply to programs written with it, as the inplace notation writes them.

                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.pure_eq {n : Nat} {α : Type u} (x : α) :

                                        InPlace.pure is pure, so that run_pure applies to programs written with it.

                                        theorem ScalarArray.UInt64Array.InPlace.forInFrom_eq {n : Nat} {β : Type u} (lo hi j : USize) (hlo : lo.toNat ≤ j.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                                        forInFrom lo hi j hlo init body = if hj : j < hi then do let b ← body j hlo hj init forInFrom lo hi (j + 1) ⋯ b body else pure init

                                        One step of forInFrom.

                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.forIn_eq {n : Nat} {β : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                                        forIn lo hi init body = forInFrom lo hi lo ⋯ init body
                                        theorem ScalarArray.UInt64Array.InPlace.forIn2From_eq {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi j : USize) (hlo : lo.toNat ≤ j.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forIn2From lo hi j hlo init₁ init₂ body = if hj : j < hi then do let b ← body j hlo hj init₁ init₂ forIn2From lo hi (j + 1) ⋯ b.fst b.snd body else pure (init₁, init₂)

                                        One step of forIn2From.

                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.forIn2_eq {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forIn2 lo hi init₁ init₂ body = forIn2From lo hi lo ⋯ init₁ init₂ body
                                        theorem ScalarArray.UInt64Array.InPlace.forIn2From_eq_forInFrom {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi j : USize) (hlo : lo.toNat ≤ j.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forIn2From lo hi j hlo init₁ init₂ body = forInFrom lo hi j hlo (init₁, init₂) fun (j : USize) (hlo : lo.toNat ≤ j.toNat) (hj : j.toNat < hi.toNat) (b : β₁ × β₂) => body j hlo hj b.fst b.snd

                                        forIn2From is forInFrom on the pair of accumulators.

                                        theorem ScalarArray.UInt64Array.InPlace.forIn2_eq_forIn {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forIn2 lo hi init₁ init₂ body = forIn lo hi (init₁, init₂) fun (j : USize) (hlo : lo.toNat ≤ j.toNat) (hj : j.toNat < hi.toNat) (b : β₁ × β₂) => body j hlo hj b.fst b.snd

                                        forIn2 is forIn on the pair of accumulators.

                                        theorem ScalarArray.UInt64Array.InPlace.forInRevFrom_eq {n : Nat} {β : Type u} (lo hi j : USize) (hj : j.toNat ≤ hi.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                                        forInRevFrom lo hi j hj init body = if h : lo < j then do let b ← body (j - 1) ⋯ ⋯ init forInRevFrom lo hi (j - 1) ⋯ b body else pure init

                                        One step of forInRevFrom.

                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.forInRev_eq {n : Nat} {β : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) :
                                        forInRev lo hi init body = forInRevFrom lo hi hi ⋯ init body
                                        theorem ScalarArray.UInt64Array.InPlace.forInRev2From_eq {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi j : USize) (hj : j.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forInRev2From lo hi j hj init₁ init₂ body = if h : lo < j then do let b ← body (j - 1) ⋯ ⋯ init₁ init₂ forInRev2From lo hi (j - 1) ⋯ b.fst b.snd body else pure (init₁, init₂)

                                        One step of forInRev2From.

                                        @[simp]
                                        theorem ScalarArray.UInt64Array.InPlace.forInRev2_eq {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forInRev2 lo hi init₁ init₂ body = forInRev2From lo hi hi ⋯ init₁ init₂ body
                                        theorem ScalarArray.UInt64Array.InPlace.forInRev2From_eq_forInRevFrom {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi j : USize) (hj : j.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forInRev2From lo hi j hj init₁ init₂ body = forInRevFrom lo hi j hj (init₁, init₂) fun (j : USize) (hlo : lo.toNat ≤ j.toNat) (hj : j.toNat < hi.toNat) (b : β₁ × β₂) => body j hlo hj b.fst b.snd

                                        forInRev2From is forInRevFrom on the pair of accumulators.

                                        theorem ScalarArray.UInt64Array.InPlace.forInRev2_eq_forInRev {n : Nat} {β₁ : Type v} {β₂ : Type w} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) :
                                        forInRev2 lo hi init₁ init₂ body = forInRev lo hi (init₁, init₂) fun (j : USize) (hlo : lo.toNat ≤ j.toNat) (hj : j.toNat < hi.toNat) (b : β₁ × β₂) => body j hlo hj b.fst b.snd

                                        forInRev2 is forInRev on the pair of accumulators.

                                        Running a loop straight into a continuation #

                                        @[inline]
                                        def ScalarArray.UInt64Array.InPlace.runForInThen {n : Nat} {β : Type u} {γ : Type w} (a : UInt64Array) (h : a.size = n) (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (g : β → (a' : UInt64Array) → a'.size = n → γ) :
                                        γ

                                        Runs forIn lo hi init body on a, then g on the last accumulator and the new array, which the loop calls itself: unlike g on the result of run, it builds no pair.

                                        Instances For
                                          theorem ScalarArray.UInt64Array.InPlace.runForInThen_eq {n : Nat} {β : Type u} {γ : Type w} (a : UInt64Array) (h : a.size = n) (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (g : β → (a' : UInt64Array) → a'.size = n → γ) :
                                          runForInThen a h lo hi init body g = g ((forIn lo hi init body).run a h).fst ((forIn lo hi init body).run a h).snd ⋯
                                          @[inline]
                                          def ScalarArray.UInt64Array.InPlace.runForInRevThen {n : Nat} {β : Type u} {γ : Type w} (a : UInt64Array) (h : a.size = n) (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (g : β → (a' : UInt64Array) → a'.size = n → γ) :
                                          γ

                                          runForInThen for forInRev.

                                          Instances For
                                            theorem ScalarArray.UInt64Array.InPlace.runForInRevThen_eq {n : Nat} {β : Type u} {γ : Type w} (a : UInt64Array) (h : a.size = n) (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (g : β → (a' : UInt64Array) → a'.size = n → γ) :
                                            runForInRevThen a h lo hi init body g = g ((forInRev lo hi init body).run a h).fst ((forInRev lo hi init body).run a h).snd ⋯
                                            @[inline]
                                            def ScalarArray.UInt64Array.InPlace.runForIn2Then {n : Nat} {β₁ : Type v} {β₂ : Type w} {γ : Type u} (a : UInt64Array) (h : a.size = n) (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (g : β₁ → β₂ → (a' : UInt64Array) → a'.size = n → γ) :
                                            γ

                                            runForInThen for forIn2, with the two accumulators handed to g apart.

                                            Instances For
                                              theorem ScalarArray.UInt64Array.InPlace.runForIn2Then_eq {n : Nat} {β₁ : Type v} {β₂ : Type w} {γ : Type u} (a : UInt64Array) (h : a.size = n) (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (g : β₁ → β₂ → (a' : UInt64Array) → a'.size = n → γ) :
                                              runForIn2Then a h lo hi init₁ init₂ body g = g ((forIn2 lo hi init₁ init₂ body).run a h).fst.fst ((forIn2 lo hi init₁ init₂ body).run a h).fst.snd ((forIn2 lo hi init₁ init₂ body).run a h).snd ⋯

                                              Loops that run straight into the rest of a program #

                                              @[inline]
                                              def ScalarArray.UInt64Array.InPlace.forInBind {n : Nat} {β γ : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → InPlace n γ) :
                                              InPlace n γ

                                              forIn lo hi init body >>= k, with the loop calling k itself on its last accumulator: the loop returns no pair, so a scalar accumulator stays unboxed into k. It is specified by forInBind_eq.

                                              Instances For
                                                theorem ScalarArray.UInt64Array.InPlace.forInBind_eq {n : Nat} {β γ : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → InPlace n γ) :
                                                forInBind lo hi init body k = forIn lo hi init body >>= k
                                                @[inline]
                                                def ScalarArray.UInt64Array.InPlace.forIn2Bind {n : Nat} {β₁ : Type v} {β₂ : Type w} {γ : Type u} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → InPlace n γ) :
                                                InPlace n γ

                                                forInBind for forIn2, with the two last accumulators handed to k apart.

                                                Instances For
                                                  theorem ScalarArray.UInt64Array.InPlace.forIn2Bind_eq {n : Nat} {β₁ : Type v} {β₂ : Type w} {γ : Type (max v w)} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → InPlace n γ) :
                                                  forIn2Bind lo hi init₁ init₂ body k = do let b ← forIn2 lo hi init₁ init₂ body k b.fst b.snd
                                                  @[inline]
                                                  def ScalarArray.UInt64Array.InPlace.forInRevBind {n : Nat} {β γ : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → InPlace n γ) :
                                                  InPlace n γ

                                                  forInBind for forInRev.

                                                  Instances For
                                                    theorem ScalarArray.UInt64Array.InPlace.forInRevBind_eq {n : Nat} {β γ : Type u} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → InPlace n γ) :
                                                    forInRevBind lo hi init body k = forInRev lo hi init body >>= k
                                                    @[inline]
                                                    def ScalarArray.UInt64Array.InPlace.forInRev2Bind {n : Nat} {β₁ : Type v} {β₂ : Type w} {γ : Type u} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → InPlace n γ) :
                                                    InPlace n γ

                                                    forIn2Bind for forInRev2.

                                                    Instances For
                                                      theorem ScalarArray.UInt64Array.InPlace.forInRev2Bind_eq {n : Nat} {β₁ : Type v} {β₂ : Type w} {γ : Type (max v w)} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → InPlace n γ) :
                                                      forInRev2Bind lo hi init₁ init₂ body k = do let b ← forInRev2 lo hi init₁ init₂ body k b.fst b.snd

                                                      Tail programs #

                                                      A tail program on arrays of size n, which returns a γ: an in-place program that ends by handing the new array to a continuation, instead of returning it with a result. The continuation runs where the program ends, inside its last loop if it ends with one, so the program's last values reach it unboxed, and no result pair is built. A tail program is built from in-place programs with Tail.bind, Tail.readThen, Tail.ite, Tail.dite, the loops Tail.forInBind, Tail.forIn2Bind, Tail.forInRevBind and Tail.forInRev2Bind, and ends with Tail.done x k. It runs with Tail.run or runInPlaceThen, and inplace a do … then k writes one.

                                                      Instances For
                                                        @[inline]
                                                        def ScalarArray.UInt64Array.InPlace.Tail.done {n : Nat} {α : Type u} {γ : Type w} (x : α) (k : α → (a : UInt64Array) → a.size = n → γ) :
                                                        Tail n γ

                                                        Ends the program with the result x: hands x, the array and its size to k.

                                                        Instances For
                                                          @[inline]
                                                          def ScalarArray.UInt64Array.InPlace.Tail.bind {n : Nat} {α : Type u} {γ : Type w} (m : InPlace n α) (k : α → Tail n γ) :
                                                          Tail n γ

                                                          Runs the in-place program m, then the tail program k on its result.

                                                          Instances For
                                                            @[inline]
                                                            def ScalarArray.UInt64Array.InPlace.Tail.readThen {n : Nat} {γ : Type w} (i : USize) (h : i.toNat < n) (k : UInt64 → Tail n γ) :
                                                            Tail n γ

                                                            read i h followed by k on the element.

                                                            Instances For
                                                              @[inline]
                                                              def ScalarArray.UInt64Array.InPlace.Tail.writeThen {n : Nat} {γ : Type w} (i : USize) (h : i.toNat < n) (v : UInt64) (k : Tail n γ) :
                                                              Tail n γ

                                                              write i h v followed by k.

                                                              Instances For
                                                                @[inline]
                                                                def ScalarArray.UInt64Array.InPlace.Tail.ite {n : Nat} {γ : Type w} (c : Prop) [Decidable c] (t e : Tail n γ) :
                                                                Tail n γ

                                                                Runs t if c holds and e otherwise, as a branch inside one program, like InPlace.ite.

                                                                Instances For
                                                                  @[inline]
                                                                  def ScalarArray.UInt64Array.InPlace.Tail.dite {n : Nat} {γ : Type w} (c : Prop) [Decidable c] (t : c → Tail n γ) (e : ¬c → Tail n γ) :
                                                                  Tail n γ

                                                                  Tail.ite where each branch takes the proof of its condition.

                                                                  Instances For
                                                                    @[inline]
                                                                    def ScalarArray.UInt64Array.InPlace.Tail.forInBind {n : Nat} {β : Type u} {γ : Type w} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → Tail n γ) :
                                                                    Tail n γ

                                                                    forIn lo hi init body followed by the tail program k on its last accumulator, which the loop calls itself. It is specified by forInBind_eq.

                                                                    Instances For
                                                                      @[inline]
                                                                      def ScalarArray.UInt64Array.InPlace.Tail.forIn2Bind {n : Nat} {γ : Type w} {β₁ : Type v} {β₂ : Type w'} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → Tail n γ) :
                                                                      Tail n γ

                                                                      Tail.forInBind for forIn2, with the two last accumulators handed to k apart.

                                                                      Instances For
                                                                        @[inline]
                                                                        def ScalarArray.UInt64Array.InPlace.Tail.forInRevBind {n : Nat} {β : Type u} {γ : Type w} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → Tail n γ) :
                                                                        Tail n γ

                                                                        Tail.forInBind for forInRev.

                                                                        Instances For
                                                                          @[inline]
                                                                          def ScalarArray.UInt64Array.InPlace.Tail.forInRev2Bind {n : Nat} {γ : Type w} {β₁ : Type v} {β₂ : Type w'} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → Tail n γ) :
                                                                          Tail n γ

                                                                          Tail.forInBind for forInRev2, with the two last accumulators handed to k apart.

                                                                          Instances For

                                                                            Loops in continuation-passing style #

                                                                            @[inline]
                                                                            def ScalarArray.UInt64Array.InPlace.Tail.forInFrom {n : Nat} {γ : Type w} {β : Type v} (lo hi j₀ : USize) (h : lo.toNat ≤ j₀.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                            Tail n γ

                                                                            Tail.forIn from j₀ instead of lo. It is specified by Tail.forInFrom_eq.

                                                                            Instances For
                                                                              @[inline]
                                                                              def ScalarArray.UInt64Array.InPlace.Tail.forIn {n : Nat} {γ : Type w} {β : Type v} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                              Tail n γ

                                                                              A loop in continuation-passing style, for each j from lo up to hi - 1, followed by the rest k of the program. The body gets j, both its bounds, the continuation next and the current variables, and ends by calling next on the next variables, which runs the next step, or k after the last one. So the variables are arguments of the loop, and a scalar stays unboxed, and a nested loop, whose k calls the outer next, allocates nothing either. A body that doesn't call next leaves the loop early. Tail.forIn2, Tail.forIn3 and Tail.forIn4 take two, three and four variables, each its own argument.

                                                                              Instances For
                                                                                @[inline]
                                                                                def ScalarArray.UInt64Array.InPlace.Tail.forInRevFrom {n : Nat} {γ : Type w} {β : Type v} (lo hi j₀ : USize) (h : j₀.toNat ≤ hi.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                                Tail n γ

                                                                                Tail.forInRev from j₀ - 1 down to lo instead of from hi - 1. It is specified by Tail.forInRevFrom_eq.

                                                                                Instances For
                                                                                  @[inline]
                                                                                  def ScalarArray.UInt64Array.InPlace.Tail.forInRev {n : Nat} {γ : Type w} {β : Type v} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                                  Tail n γ

                                                                                  Tail.forIn from hi - 1 down to lo.

                                                                                  Instances For
                                                                                    @[inline]
                                                                                    def ScalarArray.UInt64Array.InPlace.Tail.forIn2From {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi j₀ : USize) (h : lo.toNat ≤ j₀.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                    Tail n γ

                                                                                    Tail.forIn2 from j₀ instead of lo. It is specified by Tail.forIn2From_eq.

                                                                                    Instances For
                                                                                      @[inline]
                                                                                      def ScalarArray.UInt64Array.InPlace.Tail.forIn2 {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                      Tail n γ

                                                                                      Tail.forIn with two variables, which the loop keeps as 2 arguments.

                                                                                      Instances For
                                                                                        @[inline]
                                                                                        def ScalarArray.UInt64Array.InPlace.Tail.forInRev2From {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi j₀ : USize) (h : j₀.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                        Tail n γ

                                                                                        Tail.forInRev2 from j₀ - 1 down to lo instead of from hi - 1. It is specified by Tail.forInRev2From_eq.

                                                                                        Instances For
                                                                                          @[inline]
                                                                                          def ScalarArray.UInt64Array.InPlace.Tail.forInRev2 {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                          Tail n γ

                                                                                          Tail.forIn2 from hi - 1 down to lo.

                                                                                          Instances For
                                                                                            @[inline]
                                                                                            def ScalarArray.UInt64Array.InPlace.Tail.forIn3From {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi j₀ : USize) (h : lo.toNat ≤ j₀.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                            Tail n γ

                                                                                            Tail.forIn3 from j₀ instead of lo. It is specified by Tail.forIn3From_eq.

                                                                                            Instances For
                                                                                              @[inline]
                                                                                              def ScalarArray.UInt64Array.InPlace.Tail.forIn3 {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                              Tail n γ

                                                                                              Tail.forIn with three variables, which the loop keeps as 3 arguments.

                                                                                              Instances For
                                                                                                @[inline]
                                                                                                def ScalarArray.UInt64Array.InPlace.Tail.forInRev3From {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi j₀ : USize) (h : j₀.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                                Tail n γ

                                                                                                Tail.forInRev3 from j₀ - 1 down to lo instead of from hi - 1. It is specified by Tail.forInRev3From_eq.

                                                                                                Instances For
                                                                                                  @[inline]
                                                                                                  def ScalarArray.UInt64Array.InPlace.Tail.forInRev3 {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                                  Tail n γ

                                                                                                  Tail.forIn3 from hi - 1 down to lo.

                                                                                                  Instances For
                                                                                                    @[inline]
                                                                                                    def ScalarArray.UInt64Array.InPlace.Tail.forIn4From {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi j₀ : USize) (h : lo.toNat ≤ j₀.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                    Tail n γ

                                                                                                    Tail.forIn4 from j₀ instead of lo. It is specified by Tail.forIn4From_eq.

                                                                                                    Instances For
                                                                                                      @[inline]
                                                                                                      def ScalarArray.UInt64Array.InPlace.Tail.forIn4 {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                      Tail n γ

                                                                                                      Tail.forIn with four variables, which the loop keeps as 4 arguments.

                                                                                                      Instances For
                                                                                                        @[inline]
                                                                                                        def ScalarArray.UInt64Array.InPlace.Tail.forInRev4From {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi j₀ : USize) (h : j₀.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                        Tail n γ

                                                                                                        Tail.forInRev4 from j₀ - 1 down to lo instead of from hi - 1. It is specified by Tail.forInRev4From_eq.

                                                                                                        Instances For
                                                                                                          @[inline]
                                                                                                          def ScalarArray.UInt64Array.InPlace.Tail.forInRev4 {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                          Tail n γ

                                                                                                          Tail.forIn4 from hi - 1 down to lo.

                                                                                                          Instances For
                                                                                                            @[inline]
                                                                                                            def ScalarArray.UInt64Array.InPlace.Tail.run {n : Nat} {γ : Type w} (t : Tail n γ) (a : UInt64Array) (h : a.size = n) :
                                                                                                            γ

                                                                                                            Runs the tail program t on the array a, and returns what its continuation returns. The array is made exclusive first, so it is copied once if it is shared, and updated in place otherwise.

                                                                                                            Instances For
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.ext {n : Nat} {γ : Type w} {t t' : Tail n γ} (h : ∀ (a : UInt64Array) (h : a.size = n), t.run a h = t'.run a h) :
                                                                                                              t = t'

                                                                                                              Two tail programs are equal when they run the same on every array.

                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.ext_iff {n : Nat} {γ : Type w} {t t' : Tail n γ} :
                                                                                                              t = t' ↔ ∀ (a : UInt64Array) (h : a.size = n), t.run a h = t'.run a h
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.run_done {n : Nat} {α : Type u} {γ : Type w} (x : α) (k : α → (a : UInt64Array) → a.size = n → γ) (a : UInt64Array) (h : a.size = n) :
                                                                                                              (done x k).run a h = k x a h
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.run_bind {n : Nat} {α : Type u} {γ : Type w} (m : InPlace n α) (k : α → Tail n γ) (a : UInt64Array) (h : a.size = n) :
                                                                                                              (Tail.bind m k).run a h = (k (m.run a h).fst).run (m.run a h).snd ⋯
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.run_readThen {n : Nat} {γ : Type w} (i : USize) (hi : i.toNat < n) (k : UInt64 → Tail n γ) (a : UInt64Array) (h : a.size = n) :
                                                                                                              (readThen i hi k).run a h = (k a[i.toNat]).run a h
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.run_writeThen {n : Nat} {γ : Type w} (i : USize) (hi : i.toNat < n) (v : UInt64) (k : Tail n γ) (a : UInt64Array) (h : a.size = n) :
                                                                                                              (writeThen i hi v k).run a h = k.run (a.set i.toNat v ⋯) ⋯
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.ite_eq {n : Nat} {γ : Type w} (c : Prop) [Decidable c] (t e : Tail n γ) :
                                                                                                              Tail.ite c t e = if c then t else e
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.dite_eq {n : Nat} {γ : Type w} (c : Prop) [Decidable c] (t : c → Tail n γ) (e : ¬c → Tail n γ) :
                                                                                                              Tail.dite c t e = if h : c then t h else e h
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInBind_eq {n : Nat} {β : Type u} {γ : Type w} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → Tail n γ) :
                                                                                                              forInBind lo hi init body k = Tail.bind (InPlace.forIn lo hi init body) k
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn2Bind_eq {n : Nat} {γ : Type w} {β₁ : Type v} {β₂ : Type w'} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → Tail n γ) :
                                                                                                              forIn2Bind lo hi init₁ init₂ body k = Tail.bind (InPlace.forIn2 lo hi init₁ init₂ body) fun (b : β₁ × β₂) => k b.fst b.snd
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRevBind_eq {n : Nat} {β : Type u} {γ : Type w} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β → InPlace n β) (k : β → Tail n γ) :
                                                                                                              forInRevBind lo hi init body k = Tail.bind (InPlace.forInRev lo hi init body) k
                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev2Bind_eq {n : Nat} {γ : Type w} {β₁ : Type v} {β₂ : Type w'} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → β₁ → β₂ → InPlace n (β₁ × β₂)) (k : β₁ → β₂ → Tail n γ) :
                                                                                                              forInRev2Bind lo hi init₁ init₂ body k = Tail.bind (InPlace.forInRev2 lo hi init₁ init₂ body) fun (b : β₁ × β₂) => k b.fst b.snd

                                                                                                              Loops in continuation-passing style #

                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInFrom_eq {n : Nat} {γ : Type w} {β : Type v} (lo hi j : USize) (hlo : lo.toNat ≤ j.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                                                              forInFrom lo hi j hlo init body k = if hj : j < hi then body j hlo hj (fun (b : β) => forInFrom lo hi (j + 1) ⋯ b body k) init else k init

                                                                                                              One step of Tail.forInFrom.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn_eq {n : Nat} {γ : Type w} {β : Type v} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                                                              forIn lo hi init body k = forInFrom lo hi lo ⋯ init body k
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRevFrom_eq {n : Nat} {γ : Type w} {β : Type v} (lo hi j : USize) (hj : j.toNat ≤ hi.toNat) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                                                              forInRevFrom lo hi j hj init body k = if h : lo < j then body (j - 1) ⋯ ⋯ (fun (b : β) => forInRevFrom lo hi (j - 1) ⋯ b body k) init else k init

                                                                                                              One step of Tail.forInRevFrom.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev_eq {n : Nat} {γ : Type w} {β : Type v} (lo hi : USize) (init : β) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β → Tail n γ) → β → Tail n γ) (k : β → Tail n γ) :
                                                                                                              forInRev lo hi init body k = forInRevFrom lo hi hi ⋯ init body k
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn2From_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi j : USize) (hlo : lo.toNat ≤ j.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                                              forIn2From lo hi j hlo init₁ init₂ body k = if hj : j < hi then body j hlo hj (fun (b₁ : β₁) (b₂ : β₂) => forIn2From lo hi (j + 1) ⋯ b₁ b₂ body k) init₁ init₂ else k init₁ init₂

                                                                                                              One step of Tail.forIn2From.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn2_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                                              forIn2 lo hi init₁ init₂ body k = forIn2From lo hi lo ⋯ init₁ init₂ body k
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev2From_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi j : USize) (hj : j.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                                              forInRev2From lo hi j hj init₁ init₂ body k = if h : lo < j then body (j - 1) ⋯ ⋯ (fun (b₁ : β₁) (b₂ : β₂) => forInRev2From lo hi (j - 1) ⋯ b₁ b₂ body k) init₁ init₂ else k init₁ init₂

                                                                                                              One step of Tail.forInRev2From.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev2_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → Tail n γ) → β₁ → β₂ → Tail n γ) (k : β₁ → β₂ → Tail n γ) :
                                                                                                              forInRev2 lo hi init₁ init₂ body k = forInRev2From lo hi hi ⋯ init₁ init₂ body k
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn3From_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi j : USize) (hlo : lo.toNat ≤ j.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                                              forIn3From lo hi j hlo init₁ init₂ init₃ body k = if hj : j < hi then body j hlo hj (fun (b₁ : β₁) (b₂ : β₂) (b₃ : β₃) => forIn3From lo hi (j + 1) ⋯ b₁ b₂ b₃ body k) init₁ init₂ init₃ else k init₁ init₂ init₃

                                                                                                              One step of Tail.forIn3From.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn3_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                                              forIn3 lo hi init₁ init₂ init₃ body k = forIn3From lo hi lo ⋯ init₁ init₂ init₃ body k
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev3From_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi j : USize) (hj : j.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                                              forInRev3From lo hi j hj init₁ init₂ init₃ body k = if h : lo < j then body (j - 1) ⋯ ⋯ (fun (b₁ : β₁) (b₂ : β₂) (b₃ : β₃) => forInRev3From lo hi (j - 1) ⋯ b₁ b₂ b₃ body k) init₁ init₂ init₃ else k init₁ init₂ init₃

                                                                                                              One step of Tail.forInRev3From.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev3_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → Tail n γ) → β₁ → β₂ → β₃ → Tail n γ) (k : β₁ → β₂ → β₃ → Tail n γ) :
                                                                                                              forInRev3 lo hi init₁ init₂ init₃ body k = forInRev3From lo hi hi ⋯ init₁ init₂ init₃ body k
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn4From_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi j : USize) (hlo : lo.toNat ≤ j.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                              forIn4From lo hi j hlo init₁ init₂ init₃ init₄ body k = if hj : j < hi then body j hlo hj (fun (b₁ : β₁) (b₂ : β₂) (b₃ : β₃) (b₄ : β₄) => forIn4From lo hi (j + 1) ⋯ b₁ b₂ b₃ b₄ body k) init₁ init₂ init₃ init₄ else k init₁ init₂ init₃ init₄

                                                                                                              One step of Tail.forIn4From.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forIn4_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                              forIn4 lo hi init₁ init₂ init₃ init₄ body k = forIn4From lo hi lo ⋯ init₁ init₂ init₃ init₄ body k
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev4From_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi j : USize) (hj : j.toNat ≤ hi.toNat) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                              forInRev4From lo hi j hj init₁ init₂ init₃ init₄ body k = if h : lo < j then body (j - 1) ⋯ ⋯ (fun (b₁ : β₁) (b₂ : β₂) (b₃ : β₃) (b₄ : β₄) => forInRev4From lo hi (j - 1) ⋯ b₁ b₂ b₃ b₄ body k) init₁ init₂ init₃ init₄ else k init₁ init₂ init₃ init₄

                                                                                                              One step of Tail.forInRev4From.

                                                                                                              @[simp]
                                                                                                              theorem ScalarArray.UInt64Array.InPlace.Tail.forInRev4_eq {n : Nat} {γ : Type w} {β₁ : Type v₁} {β₂ : Type v₂} {β₃ : Type v₃} {β₄ : Type v₄} (lo hi : USize) (init₁ : β₁) (init₂ : β₂) (init₃ : β₃) (init₄ : β₄) (body : (j : USize) → lo.toNat ≤ j.toNat → j.toNat < hi.toNat → (β₁ → β₂ → β₃ → β₄ → Tail n γ) → β₁ → β₂ → β₃ → β₄ → Tail n γ) (k : β₁ → β₂ → β₃ → β₄ → Tail n γ) :
                                                                                                              forInRev4 lo hi init₁ init₂ init₃ init₄ body k = forInRev4From lo hi hi ⋯ init₁ init₂ init₃ init₄ body k

                                                                                                              Two arrays #

                                                                                                              @[inline]
                                                                                                              def ScalarArray.UInt64Array.InPlace.zipForInFrom {n m : Nat} (hi : USize) (ea eb : USize → USize) (hea : ∀ (j : USize), j.toNat < hi.toNat → (ea j).toNat < n) (heb : ∀ (j : USize), j.toNat < hi.toNat → (eb j).toNat < m) (f g : UInt64 → UInt64 → UInt64) (j₀ : USize) (a b : UInt64Array) (ha : a.size = n) (hb : b.size = m) :

                                                                                                              For internal use only: the loop of the two-array updates zipModifyStride. For each j from j₀ up to hi - 1, it reads u := a[ea j] and v := b[eb j], then writes f u v at ea j in a and g u v at eb j in b. Each array is made exclusive once, before the loop, and then updated in place without checks. It is specified by zipForInFrom_eq.

                                                                                                              Instances For
                                                                                                                theorem ScalarArray.UInt64Array.InPlace.zipForInFrom_eq {n m : Nat} (hi : USize) (ea eb : USize → USize) (hea : ∀ (j : USize), j.toNat < hi.toNat → (ea j).toNat < n) (heb : ∀ (j : USize), j.toNat < hi.toNat → (eb j).toNat < m) (f g : UInt64 → UInt64 → UInt64) (j : USize) (a b : UInt64Array) (ha : a.size = n) (hb : b.size = m) :
                                                                                                                zipForInFrom hi ea eb hea heb f g j a b ha hb = if hj : j < hi then zipForInFrom hi ea eb hea heb f g (j + 1) (a.uset (ea j) (f (a.uget (ea j) ⋯) (b.uget (eb j) ⋯)) ⋯) (b.uset (eb j) (g (a.uget (ea j) ⋯) (b.uget (eb j) ⋯)) ⋯) ⋯ ⋯ else (a, b)

                                                                                                                The steps of zipForInFrom, one at a time.

                                                                                                                @[inline]

                                                                                                                Runs the program m on a, and returns its result and the new array: m.run a rfl. The array is made exclusive first, so it is copied once if it is shared, and updated in place otherwise.

                                                                                                                Instances For
                                                                                                                  @[simp]
                                                                                                                  theorem ScalarArray.UInt64Array.runInPlace_eq {α : Type u} (a : UInt64Array) (m : InPlace a.size α) :
                                                                                                                  a.runInPlace m = m.run a ⋯
                                                                                                                  @[inline]

                                                                                                                  Runs the tail program t on a, and returns what its continuation returns: t.run a rfl. The array is made exclusive first, so it is copied once if it is shared, and updated in place otherwise.

                                                                                                                  Instances For
                                                                                                                    @[inline]
                                                                                                                    def ScalarArray.UInt64Array.runInPlaceThenOf {γ : Type u} (a : UInt64Array) (n : Nat) (h : a.size = n) (t : InPlace.Tail n γ) :
                                                                                                                    γ

                                                                                                                    Runs the tail program t on a, for a size n of a: t.run a h. When n is a variable bound to a.size before the program, the program's types don't mention a, so that the compiler doesn't keep a alive through the program: if it did, the array would no longer be exclusive when the program makes it so, and it would be copied. inplace a do … runs its programs this way.

                                                                                                                    Instances For
                                                                                                                      @[simp]
                                                                                                                      theorem ScalarArray.UInt64Array.runInPlaceThenOf_eq {γ : Type u} (a : UInt64Array) (n : Nat) (h : a.size = n) (t : InPlace.Tail n γ) :
                                                                                                                      a.runInPlaceThenOf n h t = t.run a h

                                                                                                                      The window of the slice at s.start.toUSize fits in its array.

                                                                                                                      @[inline]
                                                                                                                      def ScalarArray.UInt64Array.Slice.runInPlaceThenOf {γ : Type u} (s : UInt64Array.Slice) (n : Nat) (h : Std.Slice.size s = n) (t : (N : Nat) → (off : USize) → off.toNat + n ≤ N → (mk : (a : UInt64Array) → a.size = N → UInt64Array.Slice) → (∀ (a : UInt64Array) (h : a.size = N), Std.Slice.size (mk a h) = n) → InPlace.Tail N γ) :
                                                                                                                      γ

                                                                                                                      Runs a tail program on the elements of the slice s, for a size n of s, in place in the slice's array. t N off hw mk hmk is a program on the array, of size N, that works on the window of n elements at off, where hw bounds the window; its continuation builds the new slice with mk a' h, on the new array a', of size n by hmk. When the array's size is less than USize.size, off is the slice's start. inplace s do … runs its programs on slices this way.

                                                                                                                      Instances For
                                                                                                                        @[simp]
                                                                                                                        theorem ScalarArray.UInt64Array.Slice.runInPlaceThenOf_eq {γ : Type u} (s : UInt64Array.Slice) (n : Nat) (h : Std.Slice.size s = n) (t : (N : Nat) → (off : USize) → off.toNat + n ≤ N → (mk : (a : UInt64Array) → a.size = N → UInt64Array.Slice) → (∀ (a : UInt64Array) (h : a.size = N), Std.Slice.size (mk a h) = n) → InPlace.Tail N γ) :
                                                                                                                        s.runInPlaceThenOf n h t = (t s.array.size s.start.toUSize ⋯ (fun (a' : UInt64Array) (ha : a'.size = s.array.size) => { internalRepresentation := { array := a', start := s.start, stop := s.stop, start_le_stop := ⋯, stop_le_array_size := ⋯ } }) ⋯).run s.array ⋯