Documentation

SSA.Projects.Scf.ScfFunctor

class ScfFunctor.HasTy (d : Dialect) (DenotedTy : Type) [TyDenote d.Ty] [DialectSignature d] :

Describes that the dialect Op' has a type whose denotation is 'DenotedTy

Instances
    theorem ScfFunctor.HasTy.denote_eq {d : Dialect} {DenotedTy : Type} :
    ∀ {inst : TyDenote d.Ty} {inst_1 : DialectSignature d} [self : ScfFunctor.HasTy d DenotedTy], ScfFunctor.HasTy.ty DenotedTy = DenotedTy
    @[reducible, inline]
    Equations
    Instances For
      @[reducible, inline]
      Equations
      Instances For
        @[reducible, inline]
        Equations
        Instances For
          inductive ScfFunctor.Scf.Op (Op' : Type) (Ty' : Type) (m' : TypeType) [TyDenote Ty'] [DialectSignature { Op := Op', Ty := Ty', m := m' }] [DialectDenote { Op := Op', Ty := Ty', m := m' }] :

          only flow operations, parametric over arithmetic from another dialect Op'

          Instances For
            instance ScfFunctor.Scf.instDecidableEqOp :
            {Op' Ty' : Type} → {m' : TypeType} → {inst : TyDenote Ty'} → {inst_1 : DialectSignature { Op := Op', Ty := Ty', m := m' }} → {inst_2 : DialectDenote { Op := Op', Ty := Ty', m := m' }} → [inst_3 : DecidableEq Op'] → [inst_4 : DecidableEq Ty'] → DecidableEq (ScfFunctor.Scf.Op Op' Ty' m')
            Equations
            • ScfFunctor.Scf.instDecidableEqOp = ScfFunctor.Scf.decEqOp✝
            instance ScfFunctor.Scf.instReprOp :
            {Op' Ty' : Type} → {m' : TypeType} → {inst : TyDenote Ty'} → {inst_1 : DialectSignature { Op := Op', Ty := Ty', m := m' }} → {inst_2 : DialectDenote { Op := Op', Ty := Ty', m := m' }} → [inst_3 : Repr Op'] → [inst_4 : Repr Ty'] → Repr (ScfFunctor.Scf.Op Op' Ty' m')
            Equations
            • ScfFunctor.Scf.instReprOp = { reprPrec := ScfFunctor.Scf.reprOp✝ }
            Equations
            Instances For
              Equations
              Equations
              Equations
              @[reducible]
              Equations
              • One or more equations did not get rendered due to their size.
              @[reducible, inline]

              A loop body receives the current value of the loop induction variable, and the current loop carried value. The loop body produces the value of this loop iteration.

              Consider the loop: for(int i = 0; i >= -10; i -= 2). In this case, the value i will be the sequence of values [0, -2, -4, -6, -8, -10]. The value i is the loop induction variable.

              This value is distinct from the trip count, which is the number of times the loop body has been executed so far, which is [0, 1, 2, 3, 4].

              The LoopBody does not provide access to the trip count, only to the loop induction variable.

              Equations
              Instances For

                Convert a function f which is a single loop iteration into a function that iterates and updates the loop counter.

                Equations
                Instances For

                  A loop body is invariant if it does not depend on the index.

                  Equations
                  • f.IndexInvariant = ∀ (i j : ) (v : t), f i v = f j v
                  Instances For
                    theorem ScfFunctor.Scf.LoopBody.eval {t : Type} (f : ScfFunctor.Scf.LoopBody t) (hf : f.IndexInvariant) (i : ) (v : t) :
                    f i v = f 0 v

                    Evaluating a loop index invariant function is the same as evaluating it at 0

                    Loop invariant functions can be simulated by a simpler function

                    Equations
                    • f.atZero v = f 0 v
                    Instances For
                      theorem ScfFunctor.Scf.LoopBody.eq_invariant_fn {t : Type} (f : ScfFunctor.Scf.LoopBody t) (g : tt) (hf : ∀ (i : ) (v : t), f i v = g v) :
                      f.IndexInvariant f.atZero = g

                      If there exists a function g : t → t which agrees with f, then f is loop index invariant.

                      @[simp]
                      theorem ScfFunctor.Scf.LoopBody.IndexInvariant.eval' {t : Type} {f : ScfFunctor.Scf.LoopBody t} (hf : f.IndexInvariant) (i : ) (v : t) :
                      f i v = f.atZero v

                      Evaluating a loop index invariant function is the same as evaluating it at atZero

                      @[simp]
                      theorem ScfFunctor.Scf.LoopBody.IndexInvariant.iterate {t : Type} {f : ScfFunctor.Scf.LoopBody t} (hf : f.IndexInvariant) (δ : ) (i₀ : ) (v₀ : t) (k : ) :
                      (ScfFunctor.Scf.LoopBody.counterDecorator δ f)^[k] (i₀, v₀) = (i₀ + δ * k, f.atZero^[k] v₀)

                      iterating a loop invariant function gives a well understood answer: the iterates of the function.

                      @[simp]
                      theorem ScfFunctor.Scf.LoopBody.IndexInvariant.iterate_fst {t : Type} {f : ScfFunctor.Scf.LoopBody t} (δ : ) (hf : f.IndexInvariant) (i₀ : ) (v₀ : t) (k : ) :
                      ((ScfFunctor.Scf.LoopBody.counterDecorator δ f)^[k] (i₀, v₀)).1 = i₀ + δ * k

                      the first component of iterating a loop invariant function

                      @[simp]
                      theorem ScfFunctor.Scf.LoopBody.IndexInvariant.iterate_snd {t : Type} {f : ScfFunctor.Scf.LoopBody t} (δ : ) (hf : f.IndexInvariant) (i₀ : ) (v₀ : t) (k : ) :
                      ((ScfFunctor.Scf.LoopBody.counterDecorator δ f)^[k] (i₀, v₀)).2 = f.atZero^[k] v₀

                      the second component of iterating a loop invariant function

                      @[simp]
                      theorem ScfFunctor.Scf.LoopBody.counterDecorator.iterate_fst_val {α : Type} (δ : ) (f : ScfFunctor.Scf.LoopBody α) (i₀ : ) (v₀ : α) (k : ) :
                      ((ScfFunctor.Scf.LoopBody.counterDecorator δ f)^[k] (i₀, v₀)).1 = i₀ + k * δ

                      iterated value of the fst of the tuple of counterDecorator (ie, the loop counter)

                      theorem ScfFunctor.Scf.LoopBody.counterDecorator.const_index_fn_eval {α : Type} (δ : ) (i : ) (vstart : α) (f : ScfFunctor.Scf.LoopBody α) (f' : αα) (hf : f = fun (x : ) (a : α) => f' a) :
                      ScfFunctor.Scf.LoopBody.counterDecorator δ f (i, vstart) = (i + δ, f' vstart)

                      evaluating a function that does not access the index (const_index_fn)

                      theorem ScfFunctor.Scf.LoopBody.counterDecorator.const_index_fn_iterate {α : Type} (δ : ) (i : ) (vstart : α) (f : ScfFunctor.Scf.LoopBody α) (f' : αα) (hf : f = fun (x : ) (a : α) => f' a) (k : ) :
                      (ScfFunctor.Scf.LoopBody.counterDecorator δ f)^[k] (i, vstart) = (i + k * δ, f'^[k] vstart)

                      iterating a function that does not access the index (const_index_fn)

                      @[simp]
                      theorem ScfFunctor.Scf.LoopBody.counterDecorator.constant {α : Type} (δ : ) (i : ) (vstart : α) :
                      ScfFunctor.Scf.LoopBody.counterDecorator δ (fun (_i : ) (v : α) => v) (i, vstart) = (i + δ, vstart)

                      counterDecorator on a constant function

                      theorem ScfFunctor.Scf.LoopBody.counterDecorator.constant_iterate {α : Type} (k : ) (δ : ) :
                      (ScfFunctor.Scf.LoopBody.counterDecorator δ fun (x : ) (v : α) => v)^[k] = fun (args : × α) => (args.1 + k * δ, args.2)

                      iterate the counterDecorator of a constant function.

                      def ScfFunctor.Scf.LoopBody.counterDecorator.to_loop_run {α : Type} (δ : ) (f : ScfFunctor.Scf.LoopBody α) (niters : ) (val : α) :
                      α
                      Equations
                      Instances For
                        @[reducible]
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Equations
                        • One or more equations did not get rendered due to their size.
                        @[reducible, inline]
                        Equations
                        Instances For
                          @[reducible]
                          Equations
                          • One or more equations did not get rendered due to their size.
                          @[reducible]
                          Equations
                          • One or more equations did not get rendered due to their size.
                          @[reducible, inline]

                          Compose Scf on top of Arith

                          Equations
                          Instances For
                            Equations
                            Instances For
                              Equations
                              Instances For
                                Equations
                                Instances For
                                  theorem ScfFunctor.if_true' {Γ : Ctxt ScfFunctor.Arith.Ty} {Γv : Γ.Valuation} {t : ScfFunctor.Arith.Ty} (cond : Γ.Var ScfFunctor.Arith.Ty.bool) (hcond : Γv cond = true) (v : Γ.Var t) (then_ : Com ScfFunctor.ScfArith [t] EffectKind.impure t) (else_ : Com ScfFunctor.ScfArith [t] EffectKind.impure t) :
                                  (ScfFunctor.if_ cond v then_ else_).denote Γv = (ScfFunctor.run v then_).denote Γv

                                  'if' condition of a true variable evaluates to the then region body.

                                  theorem ScfFunctor.if_false' {Γ : Ctxt ScfFunctor.Arith.Ty} {Γv : Γ.Valuation} {t : ScfFunctor.Arith.Ty} (cond : Γ.Var ScfFunctor.Arith.Ty.bool) (hcond : Γv cond = false) (v : Γ.Var t) (then_ : Com ScfFunctor.ScfArith [t] EffectKind.impure t) (else_ : Com ScfFunctor.ScfArith [t] EffectKind.impure t) :
                                  (ScfFunctor.if_ cond v then_ else_).denote Γv = (ScfFunctor.run v else_).denote Γv

                                  'if' condition of a false variable evaluates to the else region body.

                                  @[reducible, inline]

                                  a region that returns the value immediately

                                  Equations
                                  Instances For
                                    theorem ScfFunctor.for_return {Γ : Ctxt ScfFunctor.Arith.Ty} {Γv : Γ.Valuation} {t : ScfFunctor.Arith.Ty} (istart : Γ.Var ScfFunctor.Arith.Ty.int) (istep : Γ.Var ScfFunctor.Arith.Ty.int) (niters : Γ.Var ScfFunctor.Arith.Ty.nat) (v : Γ.Var t) :
                                    (ScfFunctor.for_ istart istep niters v (ScfFunctor.RegionRet t 1, )).denote Γv = Γv v

                                    a for loop whose body immediately returns the loop variable is the same as just fetching the loop variable.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem ScfFunctor.ForReversal.Ctxt.Var.toSnoc (ty : ScfFunctor.Arith.Ty) (snocty : ScfFunctor.Arith.Ty) (Γ : Ctxt ScfFunctor.Arith.Ty) (V : Γ.Valuation) {snocval : snocty} {v : } {hvproof : Γ.get? v = some ty} {var : Γ.Var ty} (hvar : var = v, hvproof) :
                                        V var = (V::ᵥsnocval) v + 1,

                                        rewrite a variable whose index is '> 0' to a new variable which is the 'snoc' of a smaller variable. this enables rewriting with Ctxt.Valuation.snoc_toSnoc.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            theorem ScfFunctor.ForFusion.correct {t : ScfFunctor.ScfArith.Ty} (rgn : Com ScfFunctor.ScfArith [ScfFunctor.Arith.Ty.int, t] EffectKind.impure t) (niters1 : ) (niters2 : ) (start1 : ) {Γv : Ctxt.Valuation [t]} :
                                            (ScfFunctor.ForFusion.lhs rgn niters1 niters2 start1).denote Γv = (ScfFunctor.ForFusion.rhs rgn niters1 niters2 start1).denote Γv

                                            running f(x) = x + x 0 times is the identity.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For