Documentation

GaudisCrypt.Lib.EC.IterProc

EasyCrypt's iteration of a procedure over a list (theories/looping/IterProc.eca) #

The abstract type t is a section variable, so a clone is an application. Only what ported developments use is here.

Iter(O).iter l is denotationally the calls of O.f on the elements of l, in order (Iter.iter_denotation, through iterDen). From that:

noncomputable def GaudisCrypt.EC.IterProc.Orcl.structure (t : Type) [_gaudiParam0 : Inhabited t] :
Orcl t → Structure t

The record of a module's fields: Orcl.structure m is Orcl.Structure.mk applied to Orcl.f of m.

Inverse of Orcl.mk (Orcl.mk_destruct, Orcl.destruct_mk).

Equations
Instances For
    @[simp]
    theorem GaudisCrypt.EC.IterProc.Orcl.destruct_mk (t : Type) [_gaudiParam0 : Inhabited t] (theModule✝ : Orcl t) :
    mk t («structure» t theModule✝) = theModule✝

    @[simp]: Orcl.mk (Orcl.structure m) = m — rebuilding a module from its own fields gives that module back.

    The ModuleTypeRep underlying Orcl, the module type declared by moduletype Orcl: the right-nested product of its 1 field types, in declaration order.

    Orcl is by definition Module Orcl.typeRep.

    Equations
    Instances For
      @[reducible]
      noncomputable def GaudisCrypt.EC.IterProc.Orcl.mk (t : Type) [_gaudiParam0 : Inhabited t] :
      Structure t → Orcl t

      Builds a module of type Orcl from the record Orcl.Structure of its fields, as a right-nested Module.pair'. @[reducible].

      Inverse of Orcl.structure (Orcl.mk_destruct, Orcl.destruct_mk); a single field of a module built this way is read back by the @[simp] lemmas Orcl.f.mk_simp.

      Equations
      Instances For
        @[implicit_reducible]

        The IsModule Orcl instance: Orcl is a module type, with representation Orcl.typeRep.

        It is what lets the name Orcl stand where a module type is expected — in Module.Arr/Module.Prod (→ₘ/×ₘ), say — which the underlying Module Orcl.typeRep would do on its own but Orcl, a plain (non-reducible) def, would not.

        Equations
        def GaudisCrypt.EC.IterProc.Orcl (t : Type) [_gaudiParam0 : Inhabited t] :

        The module type declared by moduletype Orcl, with fields f: the type Module Orcl.typeRep of modules that are a right-nested tuple of the field types.

        Build one from a record of its fields with Orcl.mk, read a single field off one with the accessors Orcl.f, and get the whole record back with Orcl.structure.

        Equations
        Instances For
          @[simp]
          theorem GaudisCrypt.EC.IterProc.Orcl.mk_destruct (t : Type) [_gaudiParam0 : Inhabited t] (theRecord✝ : Structure t) :
          «structure» t (mk t theRecord✝) = theRecord✝

          @[simp]: Orcl.structure (Orcl.mk r) = r — destructing a module built from a record gives that record back.

          structure GaudisCrypt.EC.IterProc.Orcl.Structure (t : Type) [_gaudiParam0 : Inhabited t] :

          The record of the fields of a module of type Orcl: the fields f, one per moduletype field, each of that field's own module type.

          Orcl.mk turns such a record into a Orcl, Orcl.structure turns a Orcl back into one.

          Instances For
            noncomputable def GaudisCrypt.EC.IterProc.Orcl.f.utilities (t : Type) [_gaudiParam0 : Inhabited t] :

            What is derivable about the accessor Orcl.f, bundled into one ModuleTypeUtilities (one name per field in the namespace, rather than one per fact):

            • Orcl.f.utilities.accessorModule : Orcl →ₘ … — the accessor as a module, a projection being a module morphism;
            • Orcl.f.utilities.apply_simp — Module.app Orcl.f.utilities.accessorModule m = Orcl.f m: applying that module is the accessor;
            • Orcl.f.utilities.expression_eq — the same at the level of expressions: (Orcl.f m).expression = (Orcl.f.utilities.proj m.expression).reduce.
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              @[simp]
              theorem GaudisCrypt.EC.IterProc.Orcl.f.mk_simp (t : Type) [_gaudiParam0 : Inhabited t] (theRecord✝ : Structure t) :
              f t (mk t theRecord✝) = theRecord✝.f

              @[simp]: reading the field f back off a module built from a record — Orcl.f (Orcl.mk r) = r.f.

              It is what carries the right-hand side of an X.apply_simp (which is an Orcl.mk) on to the field the caller actually asked for, so that simp chains X.apply_simp into X.f.apply_simp.

              noncomputable def GaudisCrypt.EC.IterProc.Orcl.f (t : Type) [_gaudiParam0 : Inhabited t] :

              The field f of a module of type Orcl: the projection onto component 0 of the right-nested tuple Orcl.typeRep, as a chain of Module.fst'/Module.snd'. Tagged @[module_accessor].

              Orcl.f.mk_simp reads this field back off a module built by Orcl.mk; Orcl.f.utilities has the accessor as a module, and the lemmas about it.

              Its parameters are named x, in that order (recorded in @[gaudiProcParamNames], a ProcedureSignature holding only their types).

              Equations
              Instances For
                @[simp]
                theorem GaudisCrypt.EC.IterProc.Iter.apply_simp (t : Type) [_gaudiParam0 : Inhabited t] (O : Orcl t) :
                Iter(t, O).iter = Module.app (iter t) O

                @[simp]: applying Iter to a tuple of its single parameter O — the record of its procedures Iter.iter, each applied to the parameters it uses.

                This is the lemma that unfolds a module use: simp rewrites with it, then with the field lemmas of the module type (N.f.mk_simp) to get at the one procedure the goal is about, and then with Iter.iter.apply_simp to fill that procedure's holes.

                theorem GaudisCrypt.EC.IterProc.Iter.iter.procedure.apply_simp (t : Type) [_gaudiParam0 : Inhabited t] (holeArgs✝ : (HoleSigs.cons (procsig (t) → Unit) HoleSigs.empty).Instantiation) :
                (procedure t).instantiate holeArgs✝ = proc (l : List t) : Unit { while (!(§l).isEmpty) { call (holeArgs✝.lookup HoleIndex.zero) (head default §l); l <- drop 1 §l; } return () }

                Instantiating the holes of Iter.iter.procedure with a tuple holeArgs of procedures: the body of proc iter as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.

                Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [Iter.iter.procedure.apply_simp]).

                @[simp]

                @[simp]: applying Iter.iter to the parameters proc iter uses (O) is Module.proc (Iter.iter.procedure.instantiate …) — the procedure with its holes filled by the callees they were made from, each written as it was in the body (with the arguments in place of the module parameters) and turned into a Procedure by Module.Proc.procedure.

                The body of proc iter of module Iter, as a procedure of its own: the one call it makes to a module parameter (O) is its single hole.

                A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see Iter.iter.procedure.apply_simp) rather than run. Use Iter.iter for this procedure as a module.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  noncomputable def GaudisCrypt.EC.IterProc.Iter.iter (t : Type) [_gaudiParam0 : Inhabited t] :

                  proc iter of module Iter as a module, abstracted over the module parameters it uses (O, in declaration order): Module.Arr … (Module.Proc (procsig …)).

                  Apply it with the @[simp] lemma Iter.iter.apply_simp, which fills the holes of Iter.iter.procedure with the callees the body called.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    noncomputable def GaudisCrypt.EC.IterProc.Iter (t : Type) [_gaudiParam0 : Inhabited t] :

                    The module declared by module Iter, abstracted over its single parameter O, which it takes as one right-nested tuple: Module.Arr (T₁ ×ₘ (… ×ₘ Tₙ)) M, with M the anonymous product of the procedures' own types, the declaration naming no module type.

                    Applied to such a tuple it is the record of its procedures Iter.iter, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma Iter.apply_simp says.

                    Equations
                    Instances For

                      The lemmas #

                      The calls of f on the elements of a list, in order: what Iter(O).iter computes.

                      Equations
                      Instances For
                        theorem GaudisCrypt.EC.IterProc.iter_loop {t : Type} [Inhabited t] (lv : VariableName) (hlv : lv.type = List t) (c : Getter Bool ProgramState) (f : proctype (t) → Unit) (args : Getter t ProgramState) (y : Setter (List t) ProgramState) (e : Getter (List t) ProgramState) (get : VariableAssignment → List t) (set : List t → VariableAssignment → VariableAssignment) (hset_get : ∀ (v : List t) (m : VariableAssignment), get (set v m) = v) (hset_set : ∀ (v w : List t) (m : VariableAssignment), set w (set v m) = set w m) (hget_set : ∀ (m : VariableAssignment), set (get m) m = m) (hc : ∀ (σ : ProgramState), c.get σ = !(get σ.locals).isEmpty) (ha : ∀ (σ : ProgramState), args.get σ = head default (get σ.locals)) (hy : ∀ (v : List t) (σ : ProgramState), y.set v σ = { globals := σ.globals, locals := set v σ.locals }) (he : ∀ (σ : ProgramState), e.get σ = drop 1 (get σ.locals)) (xs : List t) (τ : ProgramState) :
                        get τ.locals = xs → programDenotation (GaudiProg[ while (§c) { call f (§args); y <- §e; } ]) τ = (iterDen (fun (x : (procsig (t) → Unit).ParamType) => procedureDenotation f x) xs τ.globals).hbind fun (r : Unit × VariableAssignment) => pure ((), { globals := r.2, locals := set [] τ.locals })

                        A loop calling f on the head of the list in slot lv and dropping it, from a state whose slot holds xs: the calls of f on xs, the slot emptied.

                        theorem GaudisCrypt.EC.IterProc.iterDen_append {t : Type} (f : t → ProgramDenotation VariableAssignment Unit) (l₁ l₂ : List t) :
                        iterDen f (l₁ ++ l₂) = do iterDen f l₁ iterDen f l₂
                        theorem GaudisCrypt.EC.IterProc.iterDen_perm {t : Type} (f : t → ProgramDenotation VariableAssignment Unit) (hcomm : ∀ (x y : t), (do f x f y) = do f y f x) {l₁ l₂ : List t} :
                        l₁.Perm l₂ → iterDen f l₁ = iterDen f l₂

                        Calls of f that commute can be iterated in any order.

                        theorem GaudisCrypt.EC.IterProc.iter_inv {t : Type} [Inhabited t] (O : Orcl t) (P : t → Prop) (Inv : VariableAssignment → VariableAssignment → Prop) (hf : prhlProc (fun (a₁ : (procsig (t) → Unit).ParamType) (g₁ : VariableAssignment) (a₂ : (procsig (t) → Unit).ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ P a₁ ∧ Inv g₁ g₂) (Orcl.f t O).procedure (Orcl.f t O).procedure fun (x : (procsig (t) → Unit).ret) (g₁ : VariableAssignment) (x_1 : (procsig (t) → Unit).ret) (g₂ : VariableAssignment) => Inv g₁ g₂) :
                        prhlProc (fun (l₁ : (procsig (List t) → Unit).ParamType) (g₁ : VariableAssignment) (l₂ : (procsig (List t) → Unit).ParamType) (g₂ : VariableAssignment) => l₁ = l₂ ∧ (∀ x ∈ have this := l₁; this, P x) ∧ Inv g₁ g₂) (Module.app (Iter.iter t) O).procedure (Module.app (Iter.iter t) O).procedure fun (x : (procsig (List t) → Unit).ret) (g₁ : VariableAssignment) (x_1 : (procsig (List t) → Unit).ret) (g₂ : VariableAssignment) => Inv g₁ g₂

                        EC's iter_inv.

                        EC's iter_cat, denotationally: iterating over l₁ ++ l₂ is iterating over l₁, then l₂ (EC's Iter(O).iters).

                        theorem GaudisCrypt.EC.IterProc.iter_perm {t : Type} [Inhabited t] (O : Orcl t) (iter2_eq : ∀ (t₁ t₂ : t), (do let _ ← procedureDenotation (Orcl.f t O).procedure t₁ procedureDenotation (Orcl.f t O).procedure t₂) = do let _ ← procedureDenotation (Orcl.f t O).procedure t₂ procedureDenotation (Orcl.f t O).procedure t₁) {l₁ l₂ : List t} (h : l₁.Perm l₂) :

                        EC's iter_perm, denotationally, under EC's iter2_eq (two calls of O.f commute): the iteration does not depend on the order of the list.

                        theorem GaudisCrypt.EC.IterProc.iter1_perm {t : Type} [Inhabited t] (O : Orcl t) (iter2_eq : ∀ (t₁ t₂ : t), (do let _ ← procedureDenotation (Orcl.f t O).procedure t₁ procedureDenotation (Orcl.f t O).procedure t₂) = do let _ ← procedureDenotation (Orcl.f t O).procedure t₂ procedureDenotation (Orcl.f t O).procedure t₁) {x : t} {l l₂ : List t} (h : (x :: l).Perm l₂) :

                        EC's iter1_perm, denotationally (EC's Iter(O).iter_1s(t, l) is O.f(t); iter(l)).