Documentation

Blaster.Optimize.Env

Type to cache inductive datatype instances and quantified functions that have already been translated.

  • instName : Smt.SmtSymbol

    Unique name generated for datatype instance/quantified functions.

    • E.g., Given datatype instances List T1 and List T2, names List_<id1> and List_<id2> will respectively be generated,

    • E.g., Given two quantified functions f1 : Int → Bool and f2 : Nat -> Bool, names Fun_<id1> and Fun_<id2> will respectively be generated. where <idX> is a Nat literal.

    This unique name is mainly used when generating the corresponding smt predicate qualifier for the datatype instance/quantified functions, that is required to specify the expected domain values for quantified variables.

    NOTE: Two (or more) polymorphic instances for an inductive datatype will generate the same name (see function getIndInst in Translate.Qualifier).

    • E.g., List α and List β will both have the same predicate qualifier name.

    NOTE: Two (or more) polymorphic quantified function will generate the same name (see function getFunInstDecl in Translate.Qualifier).

    • E.g., f1 : α → Nat and f2 : β → Nat will both have the same predicate qualifier name.

    NOTE: Polymorphic instances are detected transitively,

    • E.g., List (Option α) and List (Option β) will both generate the same predicate qualifier name.
    • E.g., f1 : Term (List α) → Nat and f2 : Term (List β) → Nat will both generate the same predicate qualifier name.
  • instSort : Smt.SortExpr

    Corresponding Smt instantiated sort for the inductive datatype instance, E.g., (List Int) for instance List Int.

  • applyInstName : Option Smt.SmtSymbol

    unique @apply function generated for each HOF/quantified function or lambda term.

Instances For
    • normalizeFunCall : Bool

      Flag to activate function normalization, e.g., Nat.beq x y to BEq.beq Nat instBEqNat x y. This flag is set to false when optimizing the recursive function body.

    • inFunApp : Bool

      Flag set to true only when optimizing function name f in expression f x₁ ... xₙ. This is to avoid applying optimization twice on the body of non-recursive functions.

    • mcDepth : Nat

      Keep track of the analysis Step reached for bmc and k-induction.

    • solverOptions : Options.BlasterOptions

      Options passed to the #solve command.

    Instances For
      • EqPattern (altArgs : Array Lean.Expr) : MatchEntry

        instanitated alternative arguments for current match pattern when discriminator matches pattern

      • NotEqPattern : MatchEntry

        Constructor used when discriminator does not match current pattern in match context

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

          Type to keep hypothesis context

          • hypothesisMap : HypothesisMap

            Map keeping track of hypotheses introduced by implications/ite. Given an implication of the form h : a → b, the following entries are introduced in this map:

            • a := h ∈ hypothesisMap
            • When a := e₁ ∧ e₂
              • e₁ := Blaster.and_left e₁ e₂ h ∈ hypothesisMap
              • e₂ := Blaster.and_right e₁ e₂ h ∈ hypothesisMap The Map is populated only when Type(a) = Prop. The updated Map is considered only when optimizing b, which may also be an implication. (see addHypotheses function and optimizeForall rule).
          • equalityMap : EqualityMap

            Map keeping track of equality introduced by implications/ite. An entry in this map is expected to be one of the following forms:

            • fv := Expr
            • Expr := C
            • Expr := C x₁ ... xₙ Any occurrence of the key for a given context is replaced by the rhs value.
          Instances For
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Type to keep parameter info for a given function

              • binderInfo : Lean.BinderInfo

                The binder annotation for the parameter.

              • isProp : Bool

                Flag set to true when parameter type is a Prop

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

                      Type defining the memoization cache for internally demanding functions.

                      Instances For
                        Equations
                        • One or more equations did not get rendered due to their size.
                        • local lean context updated when optimizing lambda and forall expression

                        • localInsts : Lean.LocalInstances

                          local instances updated when optimizing lambda and forall expression

                        Instances For

                          Type defining the environment used when optimizing a lean theorem.

                          • globalRewriteCache : RewriteCacheMap

                            Cache memoizing the normalization and rewriting performed on the lean theorem according to a given context.

                          • localRewriteCache : RewriteCacheMap
                          • synthInstanceCache : Std.HashMap Lean.Expr (Option Lean.Expr)

                            Cache memoizing synthesized instances for Inhabited/LawfulBEq constraint.

                          • Cache memoizing the whnf result.

                          • Cache memoizing type for a match application of the form f.match.n [p₁, ..., pₙ, d₁, ..., dₖ,, pa₍₁₎₍₁₎ → .. → pa₍₁₎₍ₖ₎ → rhs₁, ..., pa₍ₘ₎₍₁₎ → .. → pa₍ₘ₎₍ₖ₎ → rhsₘ], s.t.: An entry in this map is expected to be of the form Type(f.match.n [p₁, ..., pₙ]) := fun.match.n p₁ ... pₙwhere,p₁, ..., pₙcorrespond to the arguments instantiating polymorphic params. This is used to determine equivalence between match functions (see functionstructEqMatch?`).

                          • recFunInstCache : Std.HashMap Lean.Expr Lean.Expr

                            Cache memoizing instances of recursive functions. An entry in this map is expected to be of the form f x₁ ... xₙ := fdef, where:

                            • x₁ .. xₙ: correspond to the arguments instantiating the polymorphic parameters of f (if any).
                            • fdef: correspond to the recursive function body. TODO: UPDATE SPEC
                          • recFunCache : Std.HashSet Lean.Expr

                            Cache keeping track of visited recursive function. Note that we here keep track of each instantiated polymorphic function.

                          • Map to keep the normalized definition for each recursive function, which is also used to determine structural equivalence between functions (see function storeRecFunDef).

                          • hypothesisContext : HypothesisContext

                            Hypothesis context that is populated whether an implication or ite is encountered. The context is used only when optimization the implication's body or the then/else term of an ite.

                          • matchInContext : MatchContextMap

                            Map keeping track of match patterns when optimizing a match rhs. Given a match expression of the form: match₁ e₁, ..., eₙ with | p₍₁₎₍₁₎, ..., p₍₁₎₍ₙ₎ => t₁ x₁ ... xₙ ... | p₍ₘ₎₍₁₎, ..., p₍ₘ₎₍ₙ₎ => tₘ x₁ ... xₙ The following entries are introduced in this map context for each tᵢ:

                            • ∀ j ∈ [1..n], p₍ᵢ₎₍ⱼ₎ = eⱼ := (← retrieveAltsArgs #[p₍ᵢ₎₍ⱼ₎]).altArgs ∈ matchInContext (see optimizeMatchAlt function).

                            NOTE: The updated Map context is considered only when optimizing each tᵢ.

                          • memCache : MemoizeEnv

                            Memoization maps (see not on MemoizeEnv)

                          • options : OptimizeOptions

                            Optimization options (see note on OptimizeOptions)

                          • restart : Bool

                            Flag to be set to true when there is a need to apply optimization again on a given expression.

                          • local declaration context

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

                              Flag set when universe @@Type has already been declared in Smt instance.

                            • arrowTypeArities : Std.HashMap Nat Smt.SmtSymbol

                              Cache keeping track of ArrowTN already declared in Smt instance, with N corresponding to the function arity.

                            • inPatternMatching : Std.HashSet Lean.FVarId

                              Set keeping track of all variables in matched terms, including named patterns. This set is provided only when translating matched terms and match rhs.

                            • Map keeping track of axioms not of type Prop or opaque variables, encountered during translation. This set is used mainly to avoid multiple global declaration in the Smt instance.

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

                              Type defining the environment used when translating to Smt-Lib.

                              • Cache memoizing the translation to Smt-Lib term.

                              • smtCommands : Array Smt.SmtCommand

                                Smt-Lib commands emitted to the backend solver.

                              • Backend solver process.

                              • indTypeVisited : Std.HashSet Lean.Name

                                Cache keeping track of visited inductive datatype during translation.

                              • Map to keep inductive datatype instances and quantified functions that has already been translated. An entry in this map may correspond to one of the following:

                                • Given d the name of an inductive data type and x₀ ... xₙ its corresponding arguments (if any):

                                  • When ∀ i ∈ [0..n], ¬ isGenericParam xᵢ, d x₁ ... xₙ := {instName := n, instSort := (sd sx₀ .. sxₙ)} ∈ indTypeInstCache
                                  • when ∃ i ∈ [0..n], isGenericParam xᵢ, λ b₀ → .. → bₘ → t x₀ ... xₙ := {instName := n, instSort := (sd sx₀ .. sxₙ)}` ∈ indTypeInstCache with
                                    • b₀ .. bₘ corresponding to the polymorphic arguments (see getIndInst).
                                • Given f : α₀ → α₁ ... → αₙ a quantified function:

                                  • When ∀ i ∈ [0..n], ¬ isGenericParam αᵢ, α₀ → α₁ ... → αₙ := {instName := n, instSort := (Array sα₀ sα₁ ... sαₙ)} ∈ indTypeInstCache
                                  • When ∃ i ∈ [0..n], isGenericParam αᵢ, λ b₀ → .. → bₘ → α₀ → ... → α := {instName := n, instSort := (Array sα₀ ... sαₙ)} ∈ indTypeInstCache with
                                    • b₀ .. bₘ corresponding to the polymorphic arguments (see getFunInstDecl). See note on IndTypeDeclaration.
                              • Cache keeping track of opaque functions, recursive function instances as well as undefined class functions that have already been translated. An entry in this map is expected to be of the form f x₁ ... xₙ := n, where:

                                • x₁ .. xₙ: correspond to the arguments instantiating the polymorphic parameters of f (if any).
                                • n corresponds an smt qualified identifier that is expected to be unique for each recursive function or undefined class function instances. TODO: UPDATE SPEC
                              • Cache keeping track of sort that have already been declared.

                              • Hash keeping track of all translated fvars. (see function fvarIdToSmtSymbol)

                              • quantifiedFVars : Std.HashMap Lean.FVarId Bool

                                Hash keeping track of quantified fvars. This is essential to detect globally declared variables. The bool flag is set to true for globally declared variables or for top level forall quantifiers.

                              • topLevelVars : TopLevelVars

                                Array list keeping track of globally declared variables and the ones in the top level forall quantifier. This list is used exclusively when retrieving counterexample after a sat result is obtained from the backend smt solver. The Array index indicates the analysis step at which the variables where introduced.

                              • Cache memoizing the string representation for an Smt Symbol

                              • Hash Map keeping the FunEnvInfo for functions defined as Ctor arguments An entry in this Map will correspond to {ctor}.{idx} := f ∈ funCtorCache Where ctor is the name of the ctor and idx the index label generated at the smt level. Example, Given structure Ratio where numerator : Int denominator : Int The corresponding smt datatype declaration will be:

                                • (declare-datatype @Tests.Uplc.Onchain.Ratio ( (Tests.Uplc.Onchain.Ratio.mk (Tests.Uplc.Onchain.Ratio.mk.1 Int) (Tests.Uplc.Onchain.Ratio.mk.2 Int)) ) ) where
                                • {ctor} = Tests.Uplc.Onchain.Ratio.mk
                                • {idx} ∈ [1, 2]
                              • Translation options (see note on TranslateOptions)

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

                                Type defining the environment used when optimizing a lean theorem and translating to Smt-lib.

                                • smtEnv : SmtEnv

                                  Environment used when translating to Smt-ling.

                                • optEnv : OptimizeEnv

                                  Environment used when optimization a lean expression.

                                Instances For
                                  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.
                                  Instances For

                                    macro throwEnvError to avoid applying format on msg before throwEnvError is called

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

                                      Return the current analysis Step

                                      Equations
                                      Instances For
                                        @[inline]

                                        set restart flag to true.

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

                                          reset restart flag to false.

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

                                            Return the restart flag.

                                            Equations
                                            Instances For

                                              set optimize option normalizeFunCall to b.

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

                                                set optimize option inFunApp to b.

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

                                                            Same as the default getConstInfo but cache result.

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

                                                              Return true if c corresponds to a constructor.

                                                              Equations
                                                              Instances For
                                                                @[inline]

                                                                Return true if e corresponds to a constructor expression.

                                                                Equations
                                                                Instances For

                                                                  Same as the default isProp but cache result.

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

                                                                    set optimize option inPatternMatchin to h.

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

                                                                      Perform the following actions:

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

                                                                        Return true if optimize option normalizeFunCall is set to true.

                                                                        Equations
                                                                        Instances For

                                                                          Return true if optimize option inFunApp is set to true.

                                                                          Equations
                                                                          Instances For

                                                                            Update global rewrite cache with a := b.

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

                                                                              Update local rewrite cache with a := b.

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

                                                                                Update synthesize decidable instance cache with a := b.

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

                                                                                  Return b if a := b is already in the synthesize cache Otherwise, the following actions are performed:

                                                                                  • execute b ← f ()
                                                                                  • update cache with a := b
                                                                                  • return b
                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For
                                                                                    @[inline]

                                                                                    Return a' if a := a' is already in optimization cache. Otherwise, the following actions are performed:

                                                                                    • add a := a in cache only when cacheResult is set to true
                                                                                    • return a
                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For
                                                                                      @[inline]

                                                                                      Return true only when both hypothesisMap and matchInContext are empty and isRefHyp flag is not set

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

                                                                                        Perform the following:

                                                                                        Equations
                                                                                        Instances For
                                                                                          @[inline]

                                                                                          Perform the following:

                                                                                          Equations
                                                                                          Instances For

                                                                                            Add an instance recursive application (see function getInstApp) to the visited recursive function cache.

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

                                                                                              Remove an instance recursive application (see function getInstApp) from the visited recursive function cache.

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

                                                                                                Internal generalized rec fun const to be used for in normalized recursive definition kept in recFunMap.

                                                                                                Equations
                                                                                                Instances For
                                                                                                  @[inline]

                                                                                                  Tag expression as recursive call. This metadata is used when replacing a recursive call function with internalRecfun.

                                                                                                  Equations
                                                                                                  Instances For

                                                                                                    Return some b if e := mkAnnotation _solver.recursivecall b'`.

                                                                                                    Equations
                                                                                                    Instances For

                                                                                                      Return true if e := mkAnnotation _solver.recursivecall b'`.

                                                                                                      Equations
                                                                                                      Instances For

                                                                                                        Return true if f is already in the recursive function cache.

                                                                                                        Equations
                                                                                                        Instances For

                                                                                                          Return true if f corresponds to a theorem name.

                                                                                                          Equations
                                                                                                          Instances For

                                                                                                            Return true boolean constructor and cache result.

                                                                                                            Equations
                                                                                                            Instances For

                                                                                                              Return false boolean constructor and cache result.

                                                                                                              Equations
                                                                                                              Instances For

                                                                                                                Given b a boolean value return the corresponding boolean constructor expression and cache result.

                                                                                                                Equations
                                                                                                                Instances For

                                                                                                                  Return not boolean operator and cache result.

                                                                                                                  Equations
                                                                                                                  Instances For

                                                                                                                    Return or boolean operator and cache result.

                                                                                                                    Equations
                                                                                                                    Instances For

                                                                                                                      Return and boolean operator and cache result.

                                                                                                                      Equations
                                                                                                                      Instances For

                                                                                                                        Given b a boolean value return the corresponding propositional expression and cache result.

                                                                                                                        Equations
                                                                                                                        Instances For

                                                                                                                          Return decide const expression and cache result.

                                                                                                                          Equations
                                                                                                                          Instances For

                                                                                                                            Return True.intro const expression and cache result.

                                                                                                                            Equations
                                                                                                                            Instances For

                                                                                                                              Return not_false const expression and cache result.

                                                                                                                              Equations
                                                                                                                              Instances For

                                                                                                                                Return Nat.add operator

                                                                                                                                Equations
                                                                                                                                Instances For

                                                                                                                                  Return Nat.sub operator

                                                                                                                                  Equations
                                                                                                                                  Instances For

                                                                                                                                    Return Nat.mul operator

                                                                                                                                    Equations
                                                                                                                                    Instances For

                                                                                                                                      Return Nat.div operator

                                                                                                                                      Equations
                                                                                                                                      Instances For

                                                                                                                                        Return Nat.mod operator

                                                                                                                                        Equations
                                                                                                                                        Instances For

                                                                                                                                          Return Nat.pow operator

                                                                                                                                          Equations
                                                                                                                                          Instances For

                                                                                                                                            Return Nat.beq operator

                                                                                                                                            Equations
                                                                                                                                            Instances For

                                                                                                                                              Return Nat.ble operator

                                                                                                                                              Equations
                                                                                                                                              Instances For

                                                                                                                                                Return Int.pow operator

                                                                                                                                                Equations
                                                                                                                                                Instances For

                                                                                                                                                  Return Int.ediv operator

                                                                                                                                                  Equations
                                                                                                                                                  Instances For

                                                                                                                                                    Return Int.emod operator

                                                                                                                                                    Equations
                                                                                                                                                    Instances For

                                                                                                                                                      mkAppExpr f #[a₀, ..., aₙ] constructs the application f a₀ ... aₙ and cache the result.

                                                                                                                                                      Equations
                                                                                                                                                      Instances For

                                                                                                                                                        Return "==" Nat operator and cache result.

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

                                                                                                                                                          Return the ≤ Nat operator and cache result.

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

                                                                                                                                                            Return the < Nat operator and cache result.

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

                                                                                                                                                              Return the ≤ Int operator and cache result.

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

                                                                                                                                                                Return the < Int operator and cache result.

                                                                                                                                                                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]

                                                                                                                                                                    mkForallExpr n b constructs ∀ n, b and cache result.

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

                                                                                                                                                                        mkLambdaExpr n b constructs fun n => b and cache result.

                                                                                                                                                                        Equations
                                                                                                                                                                        Instances For

                                                                                                                                                                          mkNatLitExpr n constructs Expr.lit (Literal.natVal n) and cache result.

                                                                                                                                                                          Equations
                                                                                                                                                                          Instances For

                                                                                                                                                                            Return Nat a = b but don't cache result.

                                                                                                                                                                            Equations
                                                                                                                                                                            Instances For

                                                                                                                                                                              Return Nat a < b and don't cache result.

                                                                                                                                                                              Equations
                                                                                                                                                                              Instances For

                                                                                                                                                                                Return Nat a ≤ b and don't cache result.

                                                                                                                                                                                Equations
                                                                                                                                                                                Instances For

                                                                                                                                                                                  `evalBinNatOp f n1 n2 perform the following:

                                                                                                                                                                                  • let r := f n1 n2
                                                                                                                                                                                  • construct nat literal for r
                                                                                                                                                                                  • cache result and return r
                                                                                                                                                                                  Equations
                                                                                                                                                                                  Instances For

                                                                                                                                                                                    mkIntLitExpr n constructs and cache an Int literal expression, i.e., either Int.ofNat (Expr.lit (Literal.natVal n) or Int.negSucc (Expr.lit (Literal.natVal n).

                                                                                                                                                                                    Equations
                                                                                                                                                                                    Instances For

                                                                                                                                                                                      Return Int a = b and don't cache result.

                                                                                                                                                                                      Equations
                                                                                                                                                                                      Instances For

                                                                                                                                                                                        Returns Int a < b and don't cache result.

                                                                                                                                                                                        Equations
                                                                                                                                                                                        Instances For

                                                                                                                                                                                          Return Int a ≤ b and don't cache result.

                                                                                                                                                                                          Equations
                                                                                                                                                                                          Instances For

                                                                                                                                                                                            mkNatNegExpr n constructs and cache the negation of a Nat literal expression, i.e., Int.negSucc (Expr.lit (Literal.natVal (n - 1))`.

                                                                                                                                                                                            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]

                                                                                                                                                                                                `evalBinIntOp f n1 n2 perform the following:

                                                                                                                                                                                                • let r := f n1 n2
                                                                                                                                                                                                • construct int literal for r
                                                                                                                                                                                                • cache result and return r
                                                                                                                                                                                                Equations
                                                                                                                                                                                                Instances For

                                                                                                                                                                                                  mkStrLitExpr s constructs Expr.lit (Literal.strVal s) and cache result.

                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                    mkDecidableConstraint e constructs constraint [Decidable e] and cache the result.

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

                                                                                                                                                                                                      Return d if there is already a synthesize instance for cstr in the synthesize cache. Otherwise, the following actions are performed:

                                                                                                                                                                                                      • When LOption.some d ← trySynthInstance cstr
                                                                                                                                                                                                        • add cstr := some d to synthesize cache
                                                                                                                                                                                                        • return some d
                                                                                                                                                                                                      • When trySynthInstance does not return LOption.some:
                                                                                                                                                                                                        • add cstr := none to synthesize cache
                                                                                                                                                                                                        • return none
                                                                                                                                                                                                      Equations
                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                      Instances For

                                                                                                                                                                                                        Try to find an instance for [Decidable e].

                                                                                                                                                                                                        Equations
                                                                                                                                                                                                        Instances For

                                                                                                                                                                                                          Same as trySynthDecidableInstance but throws an error when a decidable instance cannot be found.

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

                                                                                                                                                                                                            Same as trySynthDecidableInstance but cache and return the queried decidable constraint when no decidable instance cannot be found. In fact, after definitions have been unfolded, it can sometimes be the case that Lean can't infer the proper Decidable instance. In this case, we return the queried decidable instance.

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

                                                                                                                                                                                                              Return true only when an instance for [Inhabited n] can be found. Assume that n is a name expression for an inductive datatype.

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

                                                                                                                                                                                                                Return true only when an instance for [LawfulBEq t beqInst] can be found.

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

                                                                                                                                                                                                                  Given an expression c and a boolean value b, perform the following: let d ← synthDecidableWithNotFound! c

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

                                                                                                                                                                                                                    Given f x₁ ... xₙ, return true only when one of the following conditions is satisfied: - f := BEq.beq with sort parameter that has a LawfulBEq instance - f := LT.lt with sort parameter in relationalCompatibleTypes - f : LE.le with sort parameter in relationalCompatibleTypes

                                                                                                                                                                                                                    In fact, we can't assume that BEq.beq, LT.lt and LE.le will properly be defined for any user-defined types or parametric inductive types (e.g., List, Option, etc).

                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                                      Return true if function name f is tagged as an opaque definition.

                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                        Return true only when f is a class instance.

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

                                                                                                                                                                                                                          Return true when f is neither a theorem nor a class instance and is tagged as a well-founded recursive definition.

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

                                                                                                                                                                                                                              Return true if n corresponds to a class or is transitively an abbrevation to a class definition (e.g., DecidableEq, DecidableLT, DecidableRel, etc).

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

                                                                                                                                                                                                                                Same as the default getMatcherInfo in the Lean library but also handles casesOn recursor application.

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

                                                                                                                                                                                                                                  Add n := mInfo to isMatcherCache

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

                                                                                                                                                                                                                                    Return some mInfo when f := Expr.const n l ∧ n := mInfo ∈ isMatcherCache. Otherwise none.

                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                      Determine if n corresponds to a partial definition and cache result.

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

                                                                                                                                                                                                                                        Same as the default inferType in the Lean codebase but caches the result.

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

                                                                                                                                                                                                                                          Return true if e corresponds to a class constraint expression (see function isClassConstraint).

                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                                                            Return true if f corresponds to an inductive type or is an abbrevation to an inductive type.

                                                                                                                                                                                                                                            @[inline]

                                                                                                                                                                                                                                            Return true if f corresponds to an inductive type or is an abbrevation to an inductive type.

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

                                                                                                                                                                                                                                              Return true if e corresponds to an inductive type or is an abbreviation to an inductive type.

                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                Instances For

                                                                                                                                                                                                                                                  Same as the default isType but cache result.

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

                                                                                                                                                                                                                                                    Return true is t is a potential resolvable type

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

                                                                                                                                                                                                                                                      Return all fvar expressions in e. The return array preserved dependencies between fvars, i.e., child fvars appear first. TODO: change function to pure tail rec call using stack-based approach

                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                      Instances For

                                                                                                                                                                                                                                                        Return true whenever e satisfies one of the following:

                                                                                                                                                                                                                                                        • e is a sort type;
                                                                                                                                                                                                                                                        • e is a const or variable of sort type;
                                                                                                                                                                                                                                                        • e is an application that transitively has at least one argument of sort type.

                                                                                                                                                                                                                                                        Type to represent the parameters instantiating the implicit arguments for a given function. (see function getImplicitParameters)

                                                                                                                                                                                                                                                        • effectiveArg : Lean.Expr

                                                                                                                                                                                                                                                          Corresponds to an effective parameter for a given function (implicit or not).

                                                                                                                                                                                                                                                        • isInstance : Bool

                                                                                                                                                                                                                                                          Flag set to true when the effective parameter instantiates an implicit parameter.

                                                                                                                                                                                                                                                        • isGeneric : Bool

                                                                                                                                                                                                                                                          Flag set to true when the effective parameter instantiates an implicit parameter but is still polymorphic, i.e., predicate isGenericParam is satisfied.

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

                                                                                                                                                                                                                                                            Helper function for retrieveGenericFVars and retrieveGenericArgs -

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

                                                                                                                                                                                                                                                              Given arguments params obtained from getImplicitParameters, perform the following: let V := #[α | i ∈ [0..n] ∧ α ∈ getFVarsInExpr params[i] ∧ params[i].isGeneric] return V

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

                                                                                                                                                                                                                                                                Given params an implicit parameters perform the following: let genArgs ← retrieveGenericFVars let P := #[ params[i].effectiveArgs | i ∈ [0..params.size-1] ∧ ¬ params[i].isInstance ] return genArgs ++ P

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

                                                                                                                                                                                                                                                                  Given a fun body λ α₀ → ... λ αₙ → body and params the implicit parameters info for the corresponding function, perform the following actions:

                                                                                                                                                                                                                                                                  • let A := [α₀, ..., αₙ]
                                                                                                                                                                                                                                                                  • let B := [ A[i] | i ∈ [0..n] ∧ ¬ params[i].isInstance ]
                                                                                                                                                                                                                                                                  • let S := [ A[i] | i ∈ [0..n] ∧ params[i].isInstance ]
                                                                                                                                                                                                                                                                  • let R := [ params[i].effectiveArg | i ∈ [0..n] ∧ params[i].isInstance ]
                                                                                                                                                                                                                                                                  • let β₀, .., βₘ = B
                                                                                                                                                                                                                                                                  • return λ β₀ → ... λ βₘ → body [S[0]/R[0]] ... [S[k]/R[k]] with k = S.size-1

                                                                                                                                                                                                                                                                  Assume that params.size ≤ n TODO: change function to pure tail rec call using stack-based approach

                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                                                                                    Given f a function name expression, params its implicit parameters info (see getImplicitParameters), and fbody corresponding the recursive definition for f, perform the following actions:

                                                                                                                                                                                                                                                                    • let fbody' be fbody in which the recurisve call is annotated with _solver.recursivecall
                                                                                                                                                                                                                                                                    • When ∀ i ∈ [0..params.size-1], ¬ params[i].isInstance:
                                                                                                                                                                                                                                                                      • return fbody'
                                                                                                                                                                                                                                                                    • Otherwise:
                                                                                                                                                                                                                                                                      • let genFVars ← retrieveGenericFVars params
                                                                                                                                                                                                                                                                      • return mkLambdaFVars genFVars (specializeLambda fbody' params) (usedOnly := true) An error is triggered when f is not a name expression.
                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                                                                                      Given f which is either a function name expression or a fully/partially instantiated polymorphic function (see getInstApp), and fbody corresponding to f's definition, update the recursive instance cache (i.e., recFunInstCache),

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

                                                                                                                                                                                                                                                                        Return fₙ if body[mkAnnotation _solver.recursivecall _'/_recFun α₁ ... αₖ x₁ ... xₙ] := fₙ` is already in the recursive function map. Otherwise,

                                                                                                                                                                                                                                                                        • update recursive function map with body[mkAnnotation _solver.recursivecall _'/_recFun α₁ ... αₖ x₁ ... xₙ] := f`
                                                                                                                                                                                                                                                                        • return f. where:
                                                                                                                                                                                                                                                                        • α₁ ... αₖcorrespond to the implicit arguments off` that are still polymorphic (if any).
                                                                                                                                                                                                                                                                        • x₁ ... xₙ correspond to the effective parameters of the recursive call (excluding implicit arguments). NOTE:
                                                                                                                                                                                                                                                                        • f is also removed from the visiting cache.
                                                                                                                                                                                                                                                                        • The polymorphic instance cache is updated with f := body[mkAnnotation _solver.recursivecall _'/_recFun α₁ ... αₖ x₁ ... xₙ]` (if required) for all cases. This is essential to avoid performing structural equivalence check again on an already handled recursive function. Assumes that:
                                                                                                                                                                                                                                                                        • f is either a function name expression or a fully/partially instantiated polymorphic function (see getInstApp)
                                                                                                                                                                                                                                                                        • an entry exists for each opaque recursive function in recFunMap before optimization is performed (see function cacheOpaqueRecFun).
                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                        Instances For

                                                                                                                                                                                                                                                                          Given instApp corresponding either to a function name expression or to a fully/partially instantiated polymorphic function (see function getInstApp), determine if instApp has already a mapping in recFunInstCache. If so then retrieve the corresponding function application in recFunMap. Otherwise return none. An error is triggered if no corresponding entry can be found in recFunMap.

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

                                                                                                                                                                                                                                                                            Returns all axioms only defined in current module.

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