File: .lake/packages/lean4/src/lean/Lean/Meta/Tactic/Rewrites.lean

full_name: Lean.Meta.Rewrites.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites._hyg.6
code: builtin_initialize registerTraceClass `Tactic.rewrites
goal: IO Unit

full_name: Lean.Meta.Rewrites.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites._hyg.59
code: builtin_initialize registerTraceClass `Tactic.rewrites.lemmas
goal: IO Unit

full_name: Lean.Meta.Rewrites.rewriteResultLemma
code: /-- Extract the lemma, with arguments, that was used to produce a `RewriteResult`. -/
-- This assumes that `r.eqProof` was constructed as:
-- `mkApp6 (.const ``congrArg _) α eType lhs rhs motive heq`
-- in `Lean.Meta.Tactic.Rewrite` and we want `heq`.
def rewriteResultLemma (r : RewriteResult) : Option Expr 
goal: Option Lean.Expr

full_name: Lean.Meta.Rewrites.forwardWeight
code: /-- Weight to multiply the "specificity" of a rewrite lemma by when rewriting forwards. -/
def forwardWeight 
goal: Nat

full_name: Lean.Meta.Rewrites.backwardWeight
code: /-- Weight to multiply the "specificity" of a rewrite lemma by when rewriting backwards. -/
def backwardWeight 
goal: Nat

full_name: Lean.Meta.Rewrites.RwDirection.forward
code: inductive RwDirection : Type where
  | forward : RwDirection
  | backward : RwDirection
goal: Lean.Meta.Rewrites.RwDirection

full_name: Lean.Meta.Rewrites.RwDirection.backward
code: inductive RwDirection : Type where
  | forward : RwDirection
  | backward : RwDirection
goal: Lean.Meta.Rewrites.RwDirection

full_name: Lean.Meta.Rewrites.RwDirection
code: inductive RwDirection : Type where
  | forward : RwDirection
  | backward : RwDirection
goal: Type

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites.0.Lean.Meta.Rewrites.addImport
code: private def addImport (name : Name) (constInfo : ConstantInfo) :
    MetaM (Array (InitEntry (Name × RwDirection))) 
goal: Lean.MetaM (Array (Lean.Meta.LazyDiscrTree.InitEntry (Lean.Name × Lean.Meta.Rewrites.RwDirection)))

full_name: Lean.Meta.Rewrites.discrTreeConfig
code: /-- Configuration for `DiscrTree`. -/
def discrTreeConfig : WhnfCoreConfig 
goal: Lean.Meta.WhnfCoreConfig

full_name: Lean.Meta.Rewrites.localHypotheses
code: /-- Select `=` and `↔` local hypotheses. -/
def localHypotheses (except : List FVarId := []) : MetaM (Array (Expr × Bool × Nat)) 
goal: Lean.MetaM (Array (Lean.Expr × Bool × Nat))

full_name: Lean.Meta.Rewrites.droppedKeys
code: /--
We drop `.star` and `Eq * * *` from the discriminator trees because
they match too much.
-/
def droppedKeys : List (List LazyDiscrTree.Key) 
goal: List (List Lean.Meta.LazyDiscrTree.Key)

full_name: Lean.Meta.Rewrites.createModuleTreeRef
code: def createModuleTreeRef : MetaM (LazyDiscrTree.ModuleDiscrTreeRef (Name × RwDirection)) 
goal: Lean.MetaM (Lean.Meta.LazyDiscrTree.ModuleDiscrTreeRef (Lean.Name × Lean.Meta.Rewrites.RwDirection))

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites.0.Lean.Meta.Rewrites.ExtState
code: private def ExtState 
goal: Type

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites.0.Lean.Meta.Rewrites.ExtState.default
code: private builtin_initialize ExtState.default : IO.Ref (Option (LazyDiscrTree (Name × RwDirection))) ← do
  IO.mkRef .none
goal: IO.Ref (Option (Lean.Meta.LazyDiscrTree (Lean.Name × Lean.Meta.Rewrites.RwDirection)))

full_name: Lean.Meta.Rewrites.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites._hyg.1308
code: private builtin_initialize ExtState.default : IO.Ref (Option (LazyDiscrTree (Name × RwDirection))) ← do
  IO.mkRef .none
goal: IO (IO.Ref (Option (Lean.Meta.LazyDiscrTree (Lean.Name × Lean.Meta.Rewrites.RwDirection))))

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites.0.Lean.Meta.Rewrites.instInhabitedExtState
code: private instance : Inhabited ExtState 
goal: Inhabited Lean.Meta.Rewrites.ExtState

full_name: Lean.Meta.Rewrites.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites._hyg.1369
code: private builtin_initialize ext : EnvExtension ExtState ←
  registerEnvExtension (IO.mkRef .none)
goal: IO (Lean.EnvExtension Lean.Meta.Rewrites.ExtState)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites.0.Lean.Meta.Rewrites.ext
code: private builtin_initialize ext : EnvExtension ExtState ←
  registerEnvExtension (IO.mkRef .none)
goal: Lean.EnvExtension Lean.Meta.Rewrites.ExtState

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites.0.Lean.Meta.Rewrites.constantsPerImportTask
code: /--
The maximum number of constants an individual task may perform.

The value was picked because it roughly correponded to 50ms of work on the
machine this was developed on.  Smaller numbers did not seem to improve
performance when importing Std and larger numbers (<10k) seemed to degrade
initialization performance.
-/
private def constantsPerImportTask : Nat 
goal: Nat

full_name: Lean.Meta.Rewrites.incPrio
code: def incPrio : Nat → Name × RwDirection → Name × Bool × Nat

goal: Nat → Lean.Name × Lean.Meta.Rewrites.RwDirection → Lean.Name × Bool × Nat

full_name: Lean.Meta.Rewrites.rwFindDecls
code: /-- Create function for finding relevant declarations. -/
def rwFindDecls (moduleRef : LazyDiscrTree.ModuleDiscrTreeRef (Name × RwDirection)) : Expr → MetaM (Array (Name × Bool × Nat)) 
goal: Lean.Expr → Lean.MetaM (Array (Lean.Name × Bool × Nat))

full_name: Lean.Meta.Rewrites.RewriteResult.rfl?
code: /-- Data structure recording a potential rewrite to report from the `rw?` tactic. -/
structure RewriteResult where
  /-- The lemma we rewrote by.
  This is `Expr`, not just a `Name`, as it may be a local hypothesis. -/
  expr : Expr
  /-- `True` if we rewrote backwards (i.e. with `rw [← h]`). -/
  symm : Bool
  /-- The "weight" of the rewrite. This is calculated based on how specific the rewrite rule was. -/
  weight : Nat
  /-- The result from the `rw` tactic. -/
  result : Meta.RewriteResult
  /-- The metavariable context after the rewrite.
  This needs to be stored as part of the result so we can backtrack the state. -/
  mctx : MetavarContext
  rfl? : Bool
goal: Bool

full_name: Lean.Meta.Rewrites.RewriteResult
code: /-- Data structure recording a potential rewrite to report from the `rw?` tactic. -/
structure RewriteResult where
  /-- The lemma we rewrote by.
  This is `Expr`, not just a `Name`, as it may be a local hypothesis. -/
  expr : Expr
  /-- `True` if we rewrote backwards (i.e. with `rw [← h]`). -/
  symm : Bool
  /-- The "weight" of the rewrite. This is calculated based on how specific the rewrite rule was. -/
  weight : Nat
  /-- The result from the `rw` tactic. -/
  result : Meta.RewriteResult
  /-- The metavariable context after the rewrite.
  This needs to be stored as part of the result so we can backtrack the state. -/
  mctx : MetavarContext
  rfl? : Bool
goal: Type

full_name: Lean.Meta.Rewrites.RewriteResult.weight
code: /-- Data structure recording a potential rewrite to report from the `rw?` tactic. -/
structure RewriteResult where
  /-- The lemma we rewrote by.
  This is `Expr`, not just a `Name`, as it may be a local hypothesis. -/
  expr : Expr
  /-- `True` if we rewrote backwards (i.e. with `rw [← h]`). -/
  symm : Bool
  /-- The "weight" of the rewrite. This is calculated based on how specific the rewrite rule was. -/
  weight : Nat
  /-- The result from the `rw` tactic. -/
  result : Meta.RewriteResult
  /-- The metavariable context after the rewrite.
  This needs to be stored as part of the result so we can backtrack the state. -/
  mctx : MetavarContext
  rfl? : Bool
goal: Nat

full_name: Lean.Meta.Rewrites.RewriteResult.symm
code: /-- Data structure recording a potential rewrite to report from the `rw?` tactic. -/
structure RewriteResult where
  /-- The lemma we rewrote by.
  This is `Expr`, not just a `Name`, as it may be a local hypothesis. -/
  expr : Expr
  /-- `True` if we rewrote backwards (i.e. with `rw [← h]`). -/
  symm : Bool
  /-- The "weight" of the rewrite. This is calculated based on how specific the rewrite rule was. -/
  weight : Nat
  /-- The result from the `rw` tactic. -/
  result : Meta.RewriteResult
  /-- The metavariable context after the rewrite.
  This needs to be stored as part of the result so we can backtrack the state. -/
  mctx : MetavarContext
  rfl? : Bool
goal: Bool

full_name: Lean.Meta.Rewrites.RewriteResult.result
code: /-- Data structure recording a potential rewrite to report from the `rw?` tactic. -/
structure RewriteResult where
  /-- The lemma we rewrote by.
  This is `Expr`, not just a `Name`, as it may be a local hypothesis. -/
  expr : Expr
  /-- `True` if we rewrote backwards (i.e. with `rw [← h]`). -/
  symm : Bool
  /-- The "weight" of the rewrite. This is calculated based on how specific the rewrite rule was. -/
  weight : Nat
  /-- The result from the `rw` tactic. -/
  result : Meta.RewriteResult
  /-- The metavariable context after the rewrite.
  This needs to be stored as part of the result so we can backtrack the state. -/
  mctx : MetavarContext
  rfl? : Bool
goal: Lean.Meta.RewriteResult

full_name: Lean.Meta.Rewrites.RewriteResult.expr
code: /-- Data structure recording a potential rewrite to report from the `rw?` tactic. -/
structure RewriteResult where
  /-- The lemma we rewrote by.
  This is `Expr`, not just a `Name`, as it may be a local hypothesis. -/
  expr : Expr
  /-- `True` if we rewrote backwards (i.e. with `rw [← h]`). -/
  symm : Bool
  /-- The "weight" of the rewrite. This is calculated based on how specific the rewrite rule was. -/
  weight : Nat
  /-- The result from the `rw` tactic. -/
  result : Meta.RewriteResult
  /-- The metavariable context after the rewrite.
  This needs to be stored as part of the result so we can backtrack the state. -/
  mctx : MetavarContext
  rfl? : Bool
goal: Lean.Expr

full_name: Lean.Meta.Rewrites.RewriteResult.mctx
code: /-- Data structure recording a potential rewrite to report from the `rw?` tactic. -/
structure RewriteResult where
  /-- The lemma we rewrote by.
  This is `Expr`, not just a `Name`, as it may be a local hypothesis. -/
  expr : Expr
  /-- `True` if we rewrote backwards (i.e. with `rw [← h]`). -/
  symm : Bool
  /-- The "weight" of the rewrite. This is calculated based on how specific the rewrite rule was. -/
  weight : Nat
  /-- The result from the `rw` tactic. -/
  result : Meta.RewriteResult
  /-- The metavariable context after the rewrite.
  This needs to be stored as part of the result so we can backtrack the state. -/
  mctx : MetavarContext
  rfl? : Bool
goal: Lean.MetavarContext

full_name: Lean.Meta.Rewrites.dischargableWithRfl?
code: /-- Check to see if this expression (which must be a type) can be closed by `with_reducible rfl`. -/
def dischargableWithRfl? (mctx : MetavarContext) (e : Expr) : MetaM Bool 
goal: Lean.MetaM Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Rewrites.0.Lean.Meta.Rewrites.RewriteResult.ppResult
code: /--
Pretty print the result of the rewrite.
-/
private def RewriteResult.ppResult (r : RewriteResult) : MetaM String 
goal: Lean.MetaM String

full_name: Lean.Meta.Rewrites.SideConditions.assumption
code: /-- Should we try discharging side conditions? If so, using `assumption`, or `solve_by_elim`? -/
inductive SideConditions
| none
| assumption
| solveByElim
goal: Lean.Meta.Rewrites.SideConditions

full_name: Lean.Meta.Rewrites.SideConditions
code: /-- Should we try discharging side conditions? If so, using `assumption`, or `solve_by_elim`? -/
inductive SideConditions
| none
| assumption
| solveByElim
goal: Type

full_name: Lean.Meta.Rewrites.SideConditions.solveByElim
code: /-- Should we try discharging side conditions? If so, using `assumption`, or `solve_by_elim`? -/
inductive SideConditions
| none
| assumption
| solveByElim
goal: Lean.Meta.Rewrites.SideConditions

full_name: Lean.Meta.Rewrites.SideConditions.none
code: /-- Should we try discharging side conditions? If so, using `assumption`, or `solve_by_elim`? -/
inductive SideConditions
| none
| assumption
| solveByElim
goal: Lean.Meta.Rewrites.SideConditions

full_name: Lean.Meta.Rewrites.solveByElim
code: /-- Shortcut for calling `solveByElim`. -/
def solveByElim (goals : List MVarId) (depth : Nat := 6) : MetaM PUnit 
goal: Lean.MetaM PUnit

full_name: Lean.Meta.Rewrites.rwLemma
code: def rwLemma (ctx : MetavarContext) (goal : MVarId) (target : Expr) (side : SideConditions := .solveByElim)
    (lem : Expr ⊕ Name) (symm : Bool) (weight : Nat) : MetaM (Option RewriteResult) 
goal: Lean.MetaM (Option Lean.Meta.Rewrites.RewriteResult)

full_name: Lean.Meta.Rewrites.getSubexpressionMatches
code: /--
Find keys which match the expression, or some subexpression.

Note that repeated subexpressions will be visited each time they appear,
making this operation potentially very expensive.
It would be good to solve this problem!

Implementation: we reverse the results from `getMatch`,
so that we return lemmas matching larger subexpressions first,
and amongst those we return more specific lemmas first.
-/
partial def getSubexpressionMatches (op : Expr → MetaM (Array α)) (e : Expr) : MetaM (Array α) 
goal: Lean.MetaM (Array α)

full_name: Lean.Meta.Rewrites.rewriteCandidates
code: /--
Find lemmas which can rewrite the goal.

See also `rewrites` for a more convenient interface.
-/
def rewriteCandidates (hyps : Array (Expr × Bool × Nat))
    (moduleRef : LazyDiscrTree.ModuleDiscrTreeRef (Name × RwDirection))
    (target : Expr)
    (forbidden : NameSet := ∅) :
    MetaM (Array ((Expr ⊕ Name) × Bool × Nat)) 
goal: Lean.MetaM (Array ((Lean.Expr ⊕ Lean.Name) × Bool × Nat))

full_name: Lean.Meta.Rewrites.RewriteResult.newGoal
code: def RewriteResult.newGoal (r : RewriteResult) : Option Expr 
goal: Option Lean.Expr

full_name: Lean.Meta.Rewrites.RewriteResult.addSuggestion
code: def RewriteResult.addSuggestion (ref : Syntax) (r : RewriteResult) : Elab.TermElabM Unit 
goal: Lean.Elab.TermElabM Unit

full_name: Lean.Meta.Rewrites.RewriteResultConfig.mctx
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Lean.MetavarContext

full_name: Lean.Meta.Rewrites.RewriteResultConfig.stopAtRfl
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Bool

full_name: Lean.Meta.Rewrites.RewriteResultConfig.minHeartbeats
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Nat

full_name: Lean.Meta.Rewrites.RewriteResultConfig.goal
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Lean.MVarId

full_name: Lean.Meta.Rewrites.RewriteResultConfig
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Type

full_name: Lean.Meta.Rewrites.RewriteResultConfig.target
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Lean.Expr

full_name: Lean.Meta.Rewrites.RewriteResultConfig.max
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Nat

full_name: Lean.Meta.Rewrites.RewriteResultConfig.side
code: structure RewriteResultConfig where
  stopAtRfl : Bool
  max : Nat
  minHeartbeats : Nat
  goal : MVarId
  target : Expr
  side : SideConditions := .solveByElim
  mctx : MetavarContext
goal: Lean.Meta.Rewrites.SideConditions

full_name: Lean.Meta.Rewrites.takeListAux
code: def takeListAux (cfg : RewriteResultConfig) (seen : HashMap String Unit) (acc : Array RewriteResult)
    (xs : List ((Expr ⊕ Name) × Bool × Nat)) : MetaM (Array RewriteResult) 
goal: Lean.MetaM (Array Lean.Meta.Rewrites.RewriteResult)

full_name: Lean.Meta.Rewrites.findRewrites
code: /-- Find lemmas which can rewrite the goal. -/
def findRewrites (hyps : Array (Expr × Bool × Nat))
    (moduleRef : LazyDiscrTree.ModuleDiscrTreeRef (Name × RwDirection))
    (goal : MVarId) (target : Expr)
    (forbidden : NameSet := ∅) (side : SideConditions := .solveByElim)
    (stopAtRfl : Bool) (max : Nat := 20)
    (leavePercentHeartbeats : Nat := 10) : MetaM (List RewriteResult) 
goal: Lean.MetaM (List Lean.Meta.Rewrites.RewriteResult)