Documentation

Strata.DL.SMT.Denote

Denotation of SMT terms for the Strata DSL #

This module interprets the shallowly embedded SMT term language into Lean types. The interpretation is partial because not every SMT feature is currently supported. The core entry point is denoteTerm, which builds a TermDenoteResult describing both the type of a term and a semantic interpreter for it. The surrounding infrastructure tracks the well-formedness of term and uninterpreted-function contexts so that evaluation is safe.

The denotation uses propositional extensionality (propext) and Classical.propDecidable (excluded middle) to make if-then-else over Prop-valued conditions definable. Downstream correctness proofs (see FactoryCorrect.lean) inherit these dependencies.

theorem List.getElem_of_findIdx?_eq_some {α : Type u_1} {xs : List α} {mkTypeFunType : αBool} {i : Nat} (h : findIdx? mkTypeFunType xs = some i) :
mkTypeFunType xs[i] = true
def mkTypeFunType (n : Nat) :
Equations
Instances For
    def applyTypeArg {n : Nat} (tf : mkTypeFunType (n + 1)) (α : Type) :
    Equations
    Instances For
      def applyTypeArgs {n : Nat} (tf : mkTypeFunType n) (αs : List Type) (h : αs.length = n) :
      Equations
      Instances For
        def mkNonemptyPred {n : Nat} (us : mkTypeFunType n) :
        Equations
        Instances For
          @[reducible]
          def applyNonemptyPred {n : Nat} { : mkTypeFunType n} (hfα : mkNonemptyPred ) (αs : List Type) (h : αs.length = n) :
          Equations
          • =
          Instances For
            structure USDenote :
            Instances For
              @[reducible, inline]
              abbrev USContext :
              Equations
              Instances For
                @[reducible, inline]
                Equations
                Instances For
                  structure USEnvironment.WF (uss : USContext) (Γ : USEnvironment) :
                  Instances For
                    @[reducible, inline]
                    abbrev ISContext :

                    Context for type synonyms. Maps a sort name to its type, which is assumed to not contain other type synonyms. Denotation fails if this is violated

                    Equations
                    Instances For
                      structure SortContext :
                      Instances For
                        @[reducible, inline]
                        Equations
                        Instances For
                          @[reducible, inline]
                          Equations
                          Instances For
                            structure SortDenoteInput (sctx : SortContext) :
                            Instances For
                              @[reducible, inline]
                              abbrev SortDenoteResult (sctx : SortContext) :
                              Equations
                              Instances For
                                Equations
                                Instances For
                                  Equations
                                  Instances For
                                    Equations
                                    Instances For
                                      Equations
                                      Instances For

                                        Interpret an SMT TermType as a Lean Type, when supported.

                                        Returns none when we lack an interpretation (e.g. for reals).

                                        Note: similar to denoteSort, but does not attempt to look up type synonyms.

                                        Equations
                                        Instances For
                                          Equations
                                          Instances For

                                            Interpret an SMT TermType as a Lean Type, when supported.

                                            Returns none when we lack an interpretation (e.g. for reals).

                                            Equations
                                            Instances For
                                              Equations
                                              Instances For

                                                Interpret a function type described by SMT term variables and a return type.

                                                The result is an arrow type a₁ → … → out when every argument and the result type can be interpreted.

                                                Equations
                                                Instances For
                                                  theorem denoteSortOption_Some {sctx : SortContext} {ty : Strata.SMT.TermType} {h : (denoteSort sctx ty.option).isSome = true} { : SortDenoteInput sctx} :
                                                  (denoteSort sctx ty.option).get h = Option ((denoteSort sctx ty).get )
                                                  theorem arrow_of_denoteFunSortCons_isSome {sctx : SortContext} {a : Strata.SMT.TermVar} {as : List Strata.SMT.TermVar} {out : Strata.SMT.TermType} { : SortDenoteInput sctx} (h : (denoteFunSort sctx (a :: as) out).isSome = true) :
                                                  have has := ; (denoteFunSort sctx (a :: as) out).get h = ((denoteSort sctx a.ty).get (denoteFunSort sctx as out).get )
                                                  structure TermVarDenote {sctx : SortContext} ( : SortDenoteInput sctx) :

                                                  Runtime value paired with a term-variable declaration and a proof that the type can be interpreted.

                                                  Instances For
                                                    @[reducible, inline]
                                                    Equations
                                                    Instances For
                                                      @[reducible, inline]
                                                      abbrev TermVarEnvironment {sctx : SortContext} ( : SortDenoteInput sctx) :
                                                      Equations
                                                      Instances For

                                                        Forget semantic values, keeping only the declared term variables.

                                                        Equations
                                                        Instances For
                                                          structure TermVarEnvironment.WF {x✝ : SortContext} { : SortDenoteInput x✝} (vs : TermVarContext) ( : TermVarEnvironment ) :

                                                          Well-formedness predicate ensuring that an interpreted term-variable environment matches its syntactic context.

                                                          Instances For
                                                            structure UFDenote {sctx : SortContext} ( : SortDenoteInput sctx) :

                                                            Runtime function paired with the corresponding uninterpreted-function declaration and interpretation witness.

                                                            Instances For
                                                              @[reducible, inline]
                                                              abbrev UFContext :
                                                              Equations
                                                              Instances For
                                                                @[reducible, inline]
                                                                abbrev UFEnvironment {sctx : SortContext} ( : SortDenoteInput sctx) :
                                                                Equations
                                                                Instances For
                                                                  def UFEnvironment.toContext {sctx✝ : SortContext} { : SortDenoteInput sctx✝} (Γ : UFEnvironment ) :

                                                                  Forget semantic values, keeping only UF declarations.

                                                                  Equations
                                                                  Instances For
                                                                    structure UFEnvironment.WF {x✝ : SortContext} { : SortDenoteInput x✝} (ufs : UFContext) (Γ : UFEnvironment ) :

                                                                    Well-formedness predicate ensuring that an interpreted uninterpreted-function environment aligns with the syntactic declarations.

                                                                    Instances For
                                                                      structure TermContext :

                                                                      Syntactic context tracking the declared term variables and uninterpreted functions that may appear in a term.

                                                                      This is intentionally separate from TermEnvironment: an environment contains strictly more information (semantic values), but denotation judgments are formulated against syntax-level declarations and then related to environments via TermEnvironment.WF.

                                                                      Instances For
                                                                        structure TermEnvironment {sctx : SortContext} ( : SortDenoteInput sctx) :

                                                                        Semantic environment providing Lean values for the elements stored in a TermContext.

                                                                        Although this could project back to a context (toContext), we keep an explicit TermContext parameter in denotation APIs so binder-extension and lookup steps can be stated over declarations first, with realizability tracked separately via WF.

                                                                        Instances For
                                                                          structure TermEnvironment.WF {x✝ : SortContext} { : SortDenoteInput x✝} (tctx : TermContext) (Γ : TermEnvironment ) :

                                                                          Well-formedness predicate linking a semantic Environment with the corresponding syntactic Context.

                                                                          Instances For
                                                                            structure Context :
                                                                            Instances For
                                                                              structure TermDenoteInput (ctx : Context) :

                                                                              Bundle pairing an environment with a proof that it realises a particular context. This is the argument given to semantic interpreters.

                                                                              Instances For
                                                                                structure TermDenoteResult (ctx : Context) :

                                                                                Result of attempting to interpret a term: carries its type, a proof that the type is supported, and a semantic interpreter.

                                                                                Instances For
                                                                                  noncomputable def argTypesAlign {ctx : Context} (as : List (TermDenoteResult ctx)) (vs : List Strata.SMT.TermVar) :

                                                                                  Check that denoted argument types match declared variable types.

                                                                                  If lengths differ, this returns false.

                                                                                  Equations
                                                                                  Instances For
                                                                                    theorem argTypesAlign_true {ctx : Context} {as : List (TermDenoteResult ctx)} {vs : List Strata.SMT.TermVar} (h : argTypesAlign as vs = true) (i : Nat) (hi : i < as.length) :
                                                                                    as[i].ty = vs[i].ty
                                                                                    theorem argTypesAlign_arg_types {ctx : Context} {as : List (TermDenoteResult ctx)} {vs : List Strata.SMT.TermVar} (h : argTypesAlign as vs = true) (i : Nat) (hi : i < as.length) :
                                                                                    as[i].ty = vs[i].ty
                                                                                    noncomputable def applyUFAux {ctx : Context} {args : List Strata.SMT.TermVar} {out : Strata.SMT.TermType} {h : (denoteFunSort ctx.sctx args out).isSome = true} (tdi : TermDenoteInput ctx) (uf : (denoteFunSort ctx.sctx args out).get h { := tdi., hsΓ := }) (as : List (TermDenoteResult ctx)) (hl : args.length = as.length) (has : ∀ (i : Nat) (hi : i < as.length), as[i].ty = args[i].ty) :
                                                                                    (denoteSort ctx.sctx out).get { := tdi., hsΓ := }

                                                                                    Apply the semantic interpretation of a UF symbol to denoted arguments.

                                                                                    Equations
                                                                                    Instances For
                                                                                      noncomputable def applyUF {ctx : Context} {args : List Strata.SMT.TermVar} {out : Strata.SMT.TermType} {h : (denoteFunSort ctx.sctx args out).isSome = true} (tdi : TermDenoteInput ctx) (uf : (denoteFunSort ctx.sctx args out).get h { := tdi., hsΓ := }) (as : List (TermDenoteResult ctx)) (hAlign : argTypesAlign as args = true) :
                                                                                      (denoteSort ctx.sctx out).get { := tdi., hsΓ := }

                                                                                      Apply the semantic interpretation of a UF symbol to denoted arguments.

                                                                                      Equations
                                                                                      Instances For
                                                                                        @[reducible, inline]

                                                                                        Shape of a one-variable quantifier binder combinator ( or ).

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

                                                                                          Semantics helper for universal quantification.

                                                                                          Given a body interpretation over the context extended with one bound variable (n : ty), produce the interpretation in the original context by universally quantifying over all Lean values of the denoted sort ty. This also extends the term environment with the chosen value and carries the corresponding WF proof for the extended context.

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

                                                                                            Semantics helper for existential quantification.

                                                                                            Given a body interpretation over the context extended with one bound variable (n : ty), produce the interpretation in the original context by existentially quantifying over Lean values of the denoted sort ty. This also extends the term environment with the chosen witness and carries the corresponding WF proof for the extended context.

                                                                                            Equations
                                                                                            • One or more equations did not get rendered due to their size.
                                                                                            Instances For
                                                                                              def buildQuant (bindVar : QuantVarBinder) (ctx : Context) (vs : List Strata.SMT.TermVar) (hTys : (denoteFunSort ctx.sctx vs (Strata.SMT.TermType.prim Strata.SMT.TermPrimType.bool)).isSome = true) (bodyFt : TermDenoteInput { sctx := ctx.sctx, tctx := { vs := vs.reverse ++ ctx.tctx.vs, ufs := ctx.tctx.ufs } }Prop) (tdi : TermDenoteInput ctx) :
                                                                                              Equations
                                                                                              • One or more equations did not get rendered due to their size.
                                                                                              • buildQuant bindVar ctx [] hTys_2 bodyFt_2 tdi = bodyFt_2 tdi
                                                                                              Instances For
                                                                                                def buildExists (ctx : Context) (vs : List Strata.SMT.TermVar) (hTys : (denoteFunSort ctx.sctx vs (Strata.SMT.TermType.prim Strata.SMT.TermPrimType.bool)).isSome = true) (bodyFt : TermDenoteInput { sctx := ctx.sctx, tctx := { vs := vs.reverse ++ ctx.tctx.vs, ufs := ctx.tctx.ufs } }Prop) (tdi : TermDenoteInput ctx) :
                                                                                                Equations
                                                                                                Instances For
                                                                                                  def buildForall (ctx : Context) (vs : List Strata.SMT.TermVar) (hTys : (denoteFunSort ctx.sctx vs (Strata.SMT.TermType.prim Strata.SMT.TermPrimType.bool)).isSome = true) (bodyFt : TermDenoteInput { sctx := ctx.sctx, tctx := { vs := vs.reverse ++ ctx.tctx.vs, ufs := ctx.tctx.ufs } }Prop) (tdi : TermDenoteInput ctx) :
                                                                                                  Equations
                                                                                                  Instances For
                                                                                                    noncomputable def denoteTerm (ctx : Context) (t : Strata.SMT.Term) :

                                                                                                    Attempt to interpret a single SMT term under ctx, returning its Lean type and semantics when successful.

                                                                                                    Instances For
                                                                                                      noncomputable def denoteTerms (ctx : Context) (ts : List Strata.SMT.Term) :

                                                                                                      Interpret every term in a list, short-circuiting if any sub-term fails.

                                                                                                      Equations
                                                                                                      Instances For
                                                                                                        noncomputable def leftAssoc (ctx : Context) (ty : Strata.SMT.TermType) (h : (denoteSort ctx.sctx ty).isSome = true) (op : (sdi : SortDenoteInput ctx.sctx) → (denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi) (ts : List (TermDenoteResult ctx)) :
                                                                                                        Equations
                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                        • leftAssoc ctx ty h op ts = none
                                                                                                        Instances For
                                                                                                          noncomputable def leftAssoc.go (ctx : Context) (ty : Strata.SMT.TermType) (h : (denoteSort ctx.sctx ty).isSome = true) (op : (sdi : SortDenoteInput ctx.sctx) → (denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi) (ft : (tdi : TermDenoteInput ctx) → (denoteSort ctx.sctx ty).get h { := tdi., hsΓ := }) (ts : List (TermDenoteResult ctx)) :
                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          • leftAssoc.go ctx ty h op ft [] = pure { ty := ty, h := h, res := ft }
                                                                                                          Instances For
                                                                                                            noncomputable def rightAssoc (ctx : Context) (ty : Strata.SMT.TermType) (h : (denoteSort ctx.sctx ty).isSome = true) (op : (sdi : SortDenoteInput ctx.sctx) → (denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi) (ts : List (TermDenoteResult ctx)) :
                                                                                                            Equations
                                                                                                            Instances For
                                                                                                              noncomputable def rightAssoc.go (ctx : Context) (ty : Strata.SMT.TermType) (h : (denoteSort ctx.sctx ty).isSome = true) (op : (sdi : SortDenoteInput ctx.sctx) → (denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdi) (ts : List (TermDenoteResult ctx)) :
                                                                                                              Option ((tdi : TermDenoteInput ctx) → (denoteSort ctx.sctx ty).get h { := tdi., hsΓ := })
                                                                                                              Equations
                                                                                                              Instances For
                                                                                                                noncomputable def chainable (ctx : Context) (ty : Strata.SMT.TermType) (h : (denoteSort ctx.sctx ty).isSome = true) (op : (sdi : SortDenoteInput ctx.sctx) → (denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdiProp) (ts : List (TermDenoteResult ctx)) :
                                                                                                                Equations
                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                • chainable ctx ty h op ts = none
                                                                                                                Instances For
                                                                                                                  noncomputable def chainable.go (ctx : Context) (ty : Strata.SMT.TermType) (h : (denoteSort ctx.sctx ty).isSome = true) (op : (sdi : SortDenoteInput ctx.sctx) → (denoteSort ctx.sctx ty).get h sdi(denoteSort ctx.sctx ty).get h sdiProp) (ft : TermDenoteInput ctxProp) (ft₁ : (tdi : TermDenoteInput ctx) → (denoteSort ctx.sctx ty).get h { := tdi., hsΓ := }) (ts : List (TermDenoteResult ctx)) :
                                                                                                                  Equations
                                                                                                                  Instances For
                                                                                                                    noncomputable def denoteBoolTermAux (t : Strata.SMT.Term) :

                                                                                                                    Interpret a ground boolean term in the empty context.

                                                                                                                    Equations
                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                    Instances For
                                                                                                                      noncomputable def denoteIntTermAux (t : Strata.SMT.Term) :

                                                                                                                      Interpret a ground integer term in the empty context.

                                                                                                                      Equations
                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                      Instances For
                                                                                                                        noncomputable def denoteBVTermAux (n : Nat) (t : Strata.SMT.Term) :

                                                                                                                        Interpret a ground bitvector term in the empty context.

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

                                                                                                                          Interpret a ground string term in the empty context.

                                                                                                                          Equations
                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                          Instances For
                                                                                                                            noncomputable def bindUS (uss : List Core.SMT.Sort) (iss : ISContext) {us' : Core.SMT.Sort} (ft' : SortDenoteInput { uss := us' :: uss, iss := iss }Prop) :
                                                                                                                            Option (SortDenoteInput { uss := uss, iss := iss }Prop)

                                                                                                                            Eliminate one uninterpreted sort binder by quantifying over all of its semantic realizations and extending the sort environment accordingly.

                                                                                                                            Equations
                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                            Instances For
                                                                                                                              noncomputable def bindUF {n : String} {args : List Strata.SMT.TermVar} {out : Strata.SMT.TermType} (ctx : Context) (ft' : have uf' := { id := n, args := args, out := out }; have ufs' := uf' :: ctx.tctx.ufs; have tctx' := { vs := ctx.tctx.vs, ufs := ufs' }; TermDenoteInput { sctx := ctx.sctx, tctx := tctx' }Prop) :

                                                                                                                              Extend the context with an uninterpreted function and push its realisation into the denotation.

                                                                                                                              Equations
                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                              Instances For
                                                                                                                                noncomputable def bindIFVar {vs : List Strata.SMT.TermVar} {out : Strata.SMT.TermType} {n : String} {ty : Strata.SMT.TermType} (ctx : Context) {hTys : (denoteFunSort ctx.sctx vs out).isSome = true} {hTyTys : (denoteFunSort ctx.sctx ({ id := n, ty := ty } :: vs) out).isSome = true} :
                                                                                                                                have tctx := ctx.tctx; let v' := { id := n, ty := ty }; have vs' := v' :: ctx.tctx.vs; have tctx' := { vs := vs', ufs := ctx.tctx.ufs }; ((tdi : TermDenoteInput { sctx := ctx.sctx, tctx := tctx' }) → (denoteFunSort ctx.sctx vs out).get hTys { := tdi., hsΓ := })(tdi : TermDenoteInput { sctx := ctx.sctx, tctx := tctx }) → (denoteFunSort ctx.sctx (v' :: vs) out).get hTyTys { := tdi., hsΓ := }

                                                                                                                                Lambda-lift one IF-body argument binder into an arrow in the resulting function.

                                                                                                                                Equations
                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                Instances For
                                                                                                                                  noncomputable def buildIFBody {out : Strata.SMT.TermType} {vs : List Strata.SMT.TermVar} (ctx : Context) {hTys : (denoteFunSort ctx.sctx vs out).isSome = true} {hTy : (denoteSort ctx.sctx out).isSome = true} (bodyFt : (tdi : TermDenoteInput { sctx := ctx.sctx, tctx := { vs := vs.reverse ++ ctx.tctx.vs, ufs := ctx.tctx.ufs } }) → (denoteSort ctx.sctx out).get hTy { := tdi., hsΓ := }) (tdi : TermDenoteInput ctx) :
                                                                                                                                  (denoteFunSort ctx.sctx vs out).get hTys { := tdi., hsΓ := }

                                                                                                                                  Turn a denoted IF body (under its argument binders) into a denoted function.

                                                                                                                                  Equations
                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                  • buildIFBody ctx bodyFt_2 tdi = bodyFt_2 tdi
                                                                                                                                  Instances For
                                                                                                                                    noncomputable def bindIF {n : String} {args : List Strata.SMT.TermVar} {out : Strata.SMT.TermType} (body : Strata.SMT.Term) (ctx : Context) (ft' : have uf' := { id := n, args := args, out := out }; have ufs' := uf' :: ctx.tctx.ufs; have tctx' := { vs := ctx.tctx.vs, ufs := ufs' }; TermDenoteInput { sctx := ctx.sctx, tctx := tctx' }Prop) :

                                                                                                                                    Eliminate one interpreted-function declaration from the term context.

                                                                                                                                    ft' expects a context where the function symbol (n : args -> out) is available in tctx.ufs. This combinator constructs the semantic function by denoting body, pushes that interpretation into the environment, and returns a proposition over the original (smaller) context.

                                                                                                                                    Equations
                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                    Instances For
                                                                                                                                      noncomputable def denoteBoolTermFromContext (uss : USContext) (iss : ISContext) (ufs : UFContext) (ifs : List Core.SMT.IF) (t : Strata.SMT.Term) :

                                                                                                                                      Interpret a closed boolean term under SMT declarations.

                                                                                                                                      denoteTerm is context-parametric: it interprets a term relative to explicit sort/term contexts and semantic environments. This function "closes" that interpretation by successively eliminating context binders (IF, UF, sort aliases, uninterpreted sorts) and then evaluating in the empty environment.

                                                                                                                                      It is boolean-specific because SMT queries denote propositions.

                                                                                                                                      Equations
                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                      Instances For
                                                                                                                                        noncomputable def denoteQuery (ctx : Core.SMT.Context) (assums : List Strata.SMT.Term) (conc : Strata.SMT.Term) :

                                                                                                                                        Interpret an SMT query by universally quantifying assumptions and returning the semantic proposition.

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