Documentation

Blaster.Smt.Translate.Application

Generate an smt symbol from a given function name.

Equations
Instances For

    list of Lean operators expected to be fully applied at translation phase.

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

      Return true when e corresponds to one of the following:

      • e := Prop; or
      • e := α₁ → ... → αₙ → Prop; Assume that e does not contain any let expression.
      Equations
      Instances For

        Return true when indName corresponds to an inductive predicate.

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

          Given f x₁ ... xₙ a function instance and sid a unique smt identifier for f x₁ ... xₙ, add entry f x₁ ... xₙ := sid to funInstCache.

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

            Same as updateFunInstCacheBase but accepts an SmtSymbol as argument and returns the SmtQualifiedIdent instance added to funInstCache.

            Equations
            Instances For

              Perform the following actions:

              • Return SimpleIdent "Nat.sub" when entry n := SimpleIdent "Nat.sub" exists in funInstCache
              • Otherwise:
                • define Nat sort (if necessary)
                • define Nat.sub Smt function (i.e., see defineNatSub)
                • add entry n := SimpleIdent "Nat.sub" to funInstCache
                • return SimpleIdent "Nat.sub" Assume that n := Expr.const ``Nat.sub [].
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                Perform the following actions:

                • Return SimpleIdent "@Int.ediv" when entry f := SimpleIdent "@Int.ediv" exists in funInstCache
                • Otherwise:
                  • define @Int.ediv Smt function (i.e., see defineIntEDiv)
                  • add entry f := SimpleIdent "@Int.ediv" to funInstCache
                  • add entry f' := SimpleIdent "@Int.ediv" to funInstCache with: - f' := Expr.const Nat.div _ if f := Expr.const ``Int.ediv _- f' := Expr.const@Int.ediv _ otherwise
                  • return SimpleIdent "@Int.ediv" Assume that f := Expr.const ``Int.ediv [] or f := Expr.const ``Nat.div [].
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  Perform the following actions:

                  • Return SimpleIdent "@Int.emod" when entry f := SimpleIdent "@Int.emod" exists in funInstCache
                  • Otherwise:
                    • define @Int.emod Smt function (i.e., see defineIntEMod)
                    • add entry f := SimpleIdent "@Int.emod" to funInstCache
                    • add entry f' := SimpleIdent "@Int.emod" to funInstCache with: - f' := Expr.const Nat.mod _ if f := Expr.const ``Int.emod _- f' := Expr.const@Int.emod _ otherwise
                    • return SimpleIdent "@Int.emod" Assume that f := Expr.const ``Int.emod [] or f := Expr.const ``Nat.mod []
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Perform the following actions:

                    • Return SimpleIdent "@Int.tdiv" when entry n := SimpleIdent "@Int.tdiv" exists in funInstCache
                    • Otherwise:
                      • define @Int.tdiv Smt function (i.e., see defineIntTDiv)
                      • add entry n := SimpleIdent "@Int.tdiv" to funInstCache
                      • return SimpleIdent "@Int.tdiv" Assume that n := Expr.const ``Int.tdiv [].
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Perform the following actions:

                      • Return SimpleIdent "@Int.tmod" when entry n := SimpleIdent "@Int.tmod" exists in funInstCache
                      • Otherwise:
                        • define @Int.tmod Smt function (i.e., see defineIntTMod)
                        • add entry n := SimpleIdent "@Int.tmod" to funInstCache
                        • return SimpleIdent "@Int.tmod" Assume that n := Expr.const ``Int.tmod [].
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Perform the following actions:

                        • Return SimpleIdent "@Int.fdiv" when entry n := SimpleIdent "@Int.fdiv" exists in funInstCache
                        • Otherwise:
                          • define @Int.fdiv Smt function (i.e., see defineIntFDiv)
                          • add entry n := SimpleIdent "@Int.fdiv" to funInstCache
                          • return SimpleIdent "@Int.fdiv" Assume that n := Expr.const ``Int.fdiv [].
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Perform the following actions:

                          • Return SimpleIdent "@Int.fmod" when entry n := SimpleIdent "@Int.fmod" exists in funInstCache
                          • Otherwise:
                            • define @Int.fmod Smt function (i.e., see defineIntFMod)
                            • add entry n := SimpleIdent "@Int.fmod" to funInstCache
                            • return SimpleIdent "@Int.fmod" Assume that n := Expr.const ``Int.fmod [].
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Perform the following actions:

                            • Return SimpleIdent "@Int.pow" when entry f := SimpleIdent "@Int.pow" exists in funInstCache
                            • Otherwise:
                              • define Nat.sub function (if necessary)
                              • define @Int.pow Smt function (i.e., see defineIntPow)
                              • add entry f := SimpleIdent "@Int.pow" to funInstCache
                              • return SimpleIdent "@Int.pow" Assume that f := Expr.const ``Int.pow []
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              Perform the following actions:

                              • Return SimpleIdent "@Nat.pow" when entry f := SimpleIdent "@Nat.pow" exists in funInstCache
                              • Otherwise:
                                • define Nat.sub function (if necessary)
                                • define @Nat.pow Smt function (i.e., see defineNatPow)
                                • add entry f := SimpleIdent "@Nat.pow" to funInstCache
                                • return SimpleIdent "@Nat.pow" Assume that f := Expr.const ``Nat.pow []`
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                Perform the following actions:

                                • Return SimpleIdent "@Int.toNat" when entry n := SimpleIdent "@Int.toNat" exists in funInstCache
                                • Otherwise:
                                  • define Nat sort (if necessary)
                                  • define @Int.toNat Smt function (i.e., see defineInttoNat)
                                  • add entry n := SimpleIdent "@Int.toNat" to funInstCache
                                  • return SimpleIdent "@Int.toNat" Assume that n := Expr.const ``Int.toNat [].
                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  Return stₙ when entry f := stₙ exists in funInstCache. Otherwise:

                                  • add entry f := SimpleIdent s to funInstCache
                                  • return SimpleIdent s
                                  Equations
                                  Instances For

                                    Given f a name expression for which a corresponding smt operator exists and n its corresponding name, and args the effective parameters for f, perform the following actions:

                                    • When f := stₙ exists in funInstCache
                                      • return stₙ
                                    • When no entry for f exists in funInstCache
                                      • add entry f := SimpleIdent (smtSymbolFor f) to funInstCache
                                      • define corresponding smt function only when hasSmtDefinedOperator f
                                      • return SimpleIdent (smtSymbolFor f)

                                    An error is triggered

                                    • when n corresponds to one of the opaque functions:
                                      • Exists
                                      • Blaster.decide'
                                      • Iff
                                      • Int.le
                                      • Nat.beq
                                      • Nat.ble
                                      • Nat.pred
                                      • Nat.le
                                    • when args.size == 0 for Lt.lt
                                    Equations
                                    Instances For

                                      Helper function for createAppN

                                      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
                                          @[inline]

                                          Given a function application f x₀ ... xₙ and s the corresponding generated smt identifier/term for f, perform the following:

                                          • When n = 0 ∨ ∀ i ∈ [0..n], ¬ isExplicit xᵢ (i.e., instantiated polymorphic function passed as argument):
                                            • When isHOF:
                                              • When isSmtQualifiedIdent s
                                                • return .SmtIdent s
                                              • Otherwise (i.e., s is an Smt term, case when f corresponds to a function in a ctor argument)
                                                • return s
                                            • Otherwise:
                                              • When isSmtQualifiedIdent s
                                                • return asArraySmt s
                                              • Otherwise (i.e., only a defined function expected)
                                                • return ⊥
                                          • When ∃ i ∈ [0..n], isExplicit xᵢ, let A := [x₀,..., xₙ] let B := [termTranslator A[i] | i ∈ [0..n] ∧ isExplicit A[i]]
                                            • When isHOF:
                                              • When isSmtQualifiedIdent s
                                                • return selectSmt (.SmtIdent s) B
                                              • Otherwise (i;e., case when f corresponds to a function in a ctor argument)
                                                • return selectSmt s B
                                            • Otherwise:
                                              • When isSmtQualifiedIdent s
                                                • return mkSmtAppN s B
                                              • Otherwise (i.e., only a defined function expected)
                                                • return ⊥
                                          Equations
                                          Instances For

                                            Given t corresponding the type of a function/lambda parameter:

                                            • return translateType termTranslator t optionsForFunLambdaParam An error is triggered if t corresponds to the type of an implicit argument.
                                            Equations
                                            Instances For
                                              Instances For
                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For

                                                  Given f := Expr.const n _ corresponding to a function name and params its implicit parameter infos, perform the following actions: let instanceArgs := Array.filter (λ p => p.isInstance) params

                                                  • When instanceArgs.isEmpty:
                                                    • instName := funNameToSmtSymbol n
                                                    • add entry f := SimpleIdent instName to funInstCache
                                                    • return SimpleIdent instName
                                                  • When ¬ instanceArgs.isEmpty:
                                                    • instName := funNameToSmtSymbol (n ++ (← mkFreshId))
                                                    • instApp ← getInstApp f params
                                                    • add entry instApp := SimpleIdent instName to funInstCache
                                                    • return SimpleIdent instName An error is triggered when f is not a named expression.
                                                  Equations
                                                  Instances For

                                                    Given a recursive function application f x₁ ... xₙ, perform the following: let insApp := getInstApp f (← getImplicitParameters f x₁ ... xₙ)

                                                    • When ∃ instApp := smtId ∈ funInstCache
                                                      • return createApp f smtId #[x₁ ... xₙ] termTranslator
                                                    • Otherwise,
                                                      • generate function definition for f at the Smt level
                                                      • smtId ← generateFunInst f (← getImplicitParameters f x₁ ... xₙ)
                                                      • return createApp f smtId #[x₁ ... xₙ] termTranslator

                                                    Assume that f is a recursive function not tagged as opaque.

                                                    An error is triggered when

                                                    • f is not a name expression.
                                                    • No entry in recFunInstCache exists for f
                                                    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
                                                        Equations
                                                        Instances For
                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For
                                                            @[inline]
                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              Given t := ∀ α₀ → ∀ α₁ ... → αₙ, infer the instanitated type w.r.t. params such that:

                                                              • let S := [ αᵢ | i ∈ [0..n] ∧ ¬ params[i].isInstance ]
                                                              • let R := [ params[i].effectiveArg | i ∈ [0..n] ∧ ¬ params[i].isInstance ]
                                                              • let k := S.size-1
                                                              • let [α'₀, ..., α'ₚ] := [ αᵢ [S[0]/R[0]] ... [S[k]/R[k]] | i ∈ [0..n] ∧ params[i].isInstance ]
                                                              • return ∀ α'₀ → ∀ α'₁ ... → α'ₚ TODO: change function to pure tail rec call using stack-based approach
                                                              Equations
                                                              Instances For

                                                                Given f corresponding to either an undeclared class function, an axiom function or an opaque function params its corresponding implicit/explicit parameters and s its corresponding smt symbol, perform the following:

                                                                • Let ∀ α₀ → ∀ α₁ ... → αₙ := inferUndecFunType (← getFunEnvInfo f).type params
                                                                • declare smt function declare-fun s ((st₀) .. (stₙ₋₁)) stₙ)
                                                                • assert the following proposition to constraint the codomain value:
                                                                  • (assert (forall ((@x₀ st₀) ... (@xₙ₋₁ stₙ₋₁)) (! (@isTypeₙ (s @x₁ ... @xₙ₋₁)) :pattern ((s @x₁ ... @xₙ₋₁))) :qid s_cstr)

                                                                where ∀ i ∈ [0..n], αᵢ translates to Smt type stᵢ

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

                                                                  Given e := Expr.const n l,

                                                                  • When n := false
                                                                    • return BoolTerm false
                                                                  • When n := False
                                                                    • return BoolTerm false
                                                                  • When n := true
                                                                    • return BoolTerm true
                                                                  • When n := True
                                                                    • return BoolTerm true
                                                                  • When n := Int.ofNat
                                                                    • return termTranslator (← etaExpand e)
                                                                  • When isInductiveTypeExpr e
                                                                    • return ⊥
                                                                  • When isForbiddenUnappliedConst n
                                                                    • return ⊥
                                                                  • When isMatchExpr e
                                                                    • return ⊥
                                                                  • When n is a constructor with implicit arguments
                                                                    • return ⊥
                                                                  • When n is a nullary constructor
                                                                    • return SmtIdent (.QualifiedIdent n (translateType termTranslator Type(n)))
                                                                  • When n is a parameterized constructor
                                                                    • return termTranslator (← etaExpand e)
                                                                  • When hasImplicitArgs e
                                                                    • return ⊥
                                                                  • When n ∈ opaqueFuns ∨ isRecursiveFun n
                                                                    • return termTranslator (← etaExpand e)
                                                                  • When isTheorem n ∧ ¬ hasSorryTheorem e ∧ ¬ Type(e).isForAll
                                                                    • return termTranslator (← optimizeExpr' Type(e))
                                                                  • When isAxiom n ∨ some ConstantInfo.opaqueInfo _ ← getConstEnvInfo n
                                                                    • When n := s ∈ axiomMap:
                                                                      • return smtSimpleVarId s
                                                                    • Otherwise:
                                                                      • When isFunType Type(e)
                                                                        • return termTranslator (← etaExpand e)
                                                                      • Otherwise:
                                                                        • Let s = nameToSmtSymbol n
                                                                        • add n := s to axiomMap
                                                                        • Let t' ← removeTypeAbbrev Type(e)
                                                                        • Let st ← translateTypeAux termTranslator t'
                                                                        • declare smt symbol (declare-const s st)
                                                                        • Let pterm ← createPredQualifierApp s t'
                                                                        • assert term (assert pterm)
                                                                        • return smtSimpleVarId s
                                                                  • Otherwise
                                                                    • return ⊥ An error is triggered when e is not a name expression.

                                                                  NOTE: This function cannot be called on fun name expression (i.e., f x₁ ... xₙ, where e := f and f is a partially or totally applied function). It can only be applied on functions passed as arguments.

                                                                  Equations
                                                                  Instances For
                                                                    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
                                                                        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
                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For

                                                                              Translate Application TODO: UPDATE

                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.
                                                                              Instances For
                                                                                Equations
                                                                                Instances For
                                                                                  Equations
                                                                                  Instances For
                                                                                    Equations
                                                                                    Instances For
                                                                                      Equations
                                                                                      Instances For
                                                                                        Equations
                                                                                        Instances For
                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For
                                                                                            Equations
                                                                                            Instances For
                                                                                              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
                                                                                                  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
                                                                                                      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
                                                                                                          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

                                                                                                              Given e := λ (x₁ : t₁) → λ (xₙ : tₙ) => b, perform the following:

                                                                                                              • let V := [ v | v ∈ getFVarsInExpr b ∧ ¬ isType v.type ∧ ¬ isClassConstraintExpr v.type ∧ ¬ isTopLevelFVar v ]
                                                                                                              • let A := [x₁, ..., xₙ]
                                                                                                              • let (x₁, st₁) ... (xₘ, stₘ) := [(A[i], translateFunLambdaParamType tᵢ termTranslator) | i ∈ [0..n] ∧ isExplicit A[i]]
                                                                                                              • let rt ← translateFunLambdaParamType (← inferTypEnv b) termTranslator
                                                                                                              • let n ← mkFreshId
                                                                                                              • let FunArrowType := ArrowTN st₁ ... stₘ rt
                                                                                                              • let decl ← generateFunInstDeclAux (← inferTypeEnv e) FunArrowType
                                                                                                              • let some @apply{k} := decl.applyInstName
                                                                                                              • let sb := termTranslator b
                                                                                                              • When V = ∅
                                                                                                                • declare smt function (declare-const @lambda{n} FunArrowType)
                                                                                                                • assert the following proposition to properly constrain @lambda{n}: (assert (forall ((x₁ st₁) ... (xₘ stₘ)) (! (= (@apply{k} @lambda{n} x₁ ... xₘ) sb) :pattern ((@apply{k} @lambda{n} x₁ ... xₘ)) :qid @lambda{n]_def_cstr)))
                                                                                                                • return smtSimpleVarId @lambda{n}
                                                                                                              • When V ≠ ∅
                                                                                                                • let (y₁, yt₁) ... (yₖ, ytₖ) := [(V[i], translateFunLambdaParamType V[i].type termTranslator) | i ∈ [0..V.size-1]]
                                                                                                                • let GlobalArrowType := ArrowTN yt₁ ... ytₖ FunArrowType
                                                                                                                • let [v₁, ..., vₖ] = V
                                                                                                                • let globalType ← ∀ v₁ → ... ∀ vₖ → outParam (← inferTypeEnv e)
                                                                                                                • let globalDecl ← generateFunInstDeclAux globalType GlobalArrowType
                                                                                                                • let some @apply{n} := globalDecl.applyInstName
                                                                                                                • declare smt function (declare-const @global_lambda{n} GlobalArrowType)
                                                                                                                • assert the following proposition to properly constrain @global_lambda{n}!
                                                                                                                  • (assert (forall ((y₁, yt₁) ... (yₖ, ytₖ) (x₁, st₁) ... (xₘ, stₘ)) (! (= (@apply{k} (@apply{n} @global_lambda{n} y₁ ... yₖ) x₁ ... xₘ) sb) :pattern ((@apply{k} (@apply{n} @global_lambda{n} y₁ ... yₖ) x₁ ... xₘ)) :qid @global_lambda{n}_def_cstr)))
                                                                                                                • return (@apply{n} @global_lambda{n} y₁ ... yₖ)
                                                                                                              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

                                                                                                                  Given n a projection name, idx a projection and p the projection application term, perform the following:

                                                                                                                  • When n is not an inductive datatype (i.e., structure definition)
                                                                                                                    • return ⊥
                                                                                                                  • When n has more than one ctor c (i.e., structure only has one defined ctor with each field as arguments)
                                                                                                                    • return ⊥
                                                                                                                  • Otherwise:
                                                                                                                    • return smt term application (c.idx+1 p)
                                                                                                                  Equations
                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                  Instances For