fact
stringlengths
5
7.21k
type
stringclasses
9 values
library
stringclasses
2 values
imports
listlengths
0
3
filename
stringclasses
204 values
symbolic_name
stringlengths
1
41
docstring
stringclasses
245 values
optNormRuleResultToNormSeqResult : Option (DisplayRuleName × NormRuleResult) → NormSeqResult | some (ruleName, r) => r.toNormSeqResult ruleName | none => .unchanged
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
optNormRuleResultToNormSeqResult
null
NormStep := MVarId → Array (IndexMatchResult NormRule) → Array (IndexMatchResult NormRule) → NormM NormSeqResult
abbrev
Aesop
[]
Aesop/Search/Expansion/Norm.lean
NormStep
null
runNormSteps (goal : MVarId) (steps : Array NormStep) (stepsNe : 0 < steps.size) : NormM NormSeqResult := do let ctx ← readThe NormM.Context let maxIterations := ctx.options.maxNormIterations let mut iteration := 0 let mut step : Fin steps.size := ⟨0, stepsNe⟩ let mut goal := goal let mut scriptSteps := #[] let mut preSimpRules := ∅ let mut postSimpRules := ∅ let mut anySuccess := false while iteration < maxIterations do if step.val == 0 then updateForwardState goal let rules ← selectNormRules ctx.ruleSet (← getThe NormM.State).forwardRuleMatches goal let (preSimpRules', postSimpRules') := rules.partition λ r => r.rule.extra.penalty < (0 : Int) preSimpRules := preSimpRules' postSimpRules := postSimpRules' match ← steps[step] goal preSimpRules postSimpRules with | .changed newGoal scriptSteps' => anySuccess := true goal := newGoal scriptSteps := scriptSteps ++ scriptSteps' iteration := iteration + 1 step := ⟨0, stepsNe⟩ | .proved scriptSteps' => scriptSteps := scriptSteps ++ scriptSteps' return .proved scriptSteps | .unchanged => if h : step.val + 1 < steps.size then step := ⟨step.val + 1, h⟩ else if anySuccess then return .changed goal scriptSteps else return .unchanged throwError "aesop: exceeded maximum number of normalisation iterations ({maxIterations}). This means normalisation probably got stuck in an infinite loop." namespace NormStep
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
runNormSteps
null
runPreSimpRules (mvars : UnorderedArraySet MVarId) : NormStep | goal, preSimpRules, _ => do optNormRuleResultToNormSeqResult <$> runFirstNormRule goal mvars preSimpRules
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
runPreSimpRules
null
runPostSimpRules (mvars : UnorderedArraySet MVarId) : NormStep | goal, _, postSimpRules => optNormRuleResultToNormSeqResult <$> runFirstNormRule goal mvars postSimpRules
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
runPostSimpRules
null
unfold : NormStep | goal, _, _ => do if ! (← readThe NormM.Context).options.enableUnfold then aesop_trace[steps] "norm unfold is disabled (options := \{ ..., enableUnfold := false })" return .unchanged let r := (← normUnfold goal).map (.normUnfold, ·) return optNormRuleResultToNormSeqResult r
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
unfold
null
simp (mvars : Std.HashSet MVarId) : NormStep | goal, _, _ => do if ! (← readThe NormM.Context).normSimpContext.enabled then aesop_trace[steps] "norm simp is disabled (simp_options := \{ ..., enabled := false })" return .unchanged let r := (← normSimp goal mvars).map (.normSimp, ·) return optNormRuleResultToNormSeqResult r
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
simp
null
normalizeGoalMVar (goal : MVarId) (mvars : UnorderedArraySet MVarId) : NormM NormSeqResult := do let mvarsHashSet := .ofArray mvars.toArray let mut normSteps := #[ NormStep.runPreSimpRules mvars, NormStep.unfold, NormStep.simp mvarsHashSet, NormStep.runPostSimpRules mvars ] runNormSteps goal normSteps (by simp (config := { decide := true }) [normSteps]) -- Returns true if the goal was solved by normalisation.
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
normalizeGoalMVar
null
normalizeGoalIfNecessary (gref : GoalRef) [Aesop.Queue Q] : SearchM Q Bool := do let g ← gref.get let preGoal := g.preNormGoal if ← g.isRoot then -- For the root goal, we skip normalization. let rootState ← getRootMetaState gref.modify (·.setNormalizationState (.normal preGoal rootState #[])) return false match g.normalizationState with | .provenByNormalization .. => return true | .normal .. => return false | .notNormal => pure () let normCtx := { (← read) with } let normState := { forwardState := g.forwardState forwardRuleMatches := g.forwardRuleMatches } let ((normResult, { forwardState, forwardRuleMatches }), postState) ← g.runMetaMInParentState do normalizeGoalMVar preGoal g.mvars |>.run normCtx |>.run normState match normResult with | .changed postGoal script? => gref.modify λ g => g.setNormalizationState (.normal postGoal postState script?) |>.setForwardState forwardState |>.setForwardRuleMatches forwardRuleMatches return false | .unchanged => gref.modify (·.setNormalizationState (.normal preGoal postState #[])) return false | .proved script? => gref.modify (·.setNormalizationState (.provenByNormalization postState script?)) gref.markProvenByNormalization return true
def
Aesop
[]
Aesop/Search/Expansion/Norm.lean
normalizeGoalIfNecessary
null
SimpResult | solved (usedTheorems : Simp.UsedSimps) | unchanged | simplified (newGoal : MVarId) (usedTheorems : UsedSimps) namespace SimpResult
inductive
Aesop
[]
Aesop/Search/Expansion/Simp.lean
SimpResult
null
newGoal ? : SimpResult → Option MVarId | solved .. => none | unchanged => none | simplified g .. => some g
def
Aesop
[]
Aesop/Search/Expansion/Simp.lean
newGoal
null
addLetDeclsToSimpTheorems (ctx : Simp.Context) : MetaM Simp.Context := do let mut simpTheoremsArray := ctx.simpTheorems if simpTheoremsArray.isEmpty then simpTheoremsArray := #[{}] for ldecl in ← getLCtx do if ldecl.hasValue && ! ldecl.isImplementationDetail then simpTheoremsArray := simpTheoremsArray.modify 0 λ simpTheorems => simpTheorems.addLetDeclToUnfold ldecl.fvarId return ctx.setSimpTheorems simpTheoremsArray
def
Aesop
[]
Aesop/Search/Expansion/Simp.lean
addLetDeclsToSimpTheorems
null
addLetDeclsToSimpTheoremsUnlessZetaDelta (ctx : Simp.Context) : MetaM Simp.Context := do if ctx.config.zetaDelta then return ctx else addLetDeclsToSimpTheorems ctx
def
Aesop
[]
Aesop/Search/Expansion/Simp.lean
addLetDeclsToSimpTheoremsUnlessZetaDelta
null
simpGoal (mvarId : MVarId) (ctx : Simp.Context) (simprocs : Simp.SimprocsArray) (discharge? : Option Simp.Discharge := none) (simplifyTarget : Bool := true) (fvarIdsToSimp : Array FVarId := #[]) (stats : Simp.Stats := {}) : MetaM SimpResult := do let mvarIdOld := mvarId let ctx := ctx.setFailIfUnchanged false let (result, { usedTheorems := usedSimps, .. }) ← Meta.simpGoal mvarId ctx simprocs discharge? simplifyTarget fvarIdsToSimp stats if let some (_, mvarId) := result then if mvarId == mvarIdOld then return .unchanged else return .simplified mvarId usedSimps else return .solved usedSimps
def
Aesop
[]
Aesop/Search/Expansion/Simp.lean
simpGoal
null
simpGoalWithAllHypotheses (mvarId : MVarId) (ctx : Simp.Context) (simprocs : Simp.SimprocsArray) (discharge? : Option Simp.Discharge := none) (simplifyTarget : Bool := true) (stats : Simp.Stats := {}) : MetaM SimpResult := mvarId.withContext do let lctx ← getLCtx let mut fvarIdsToSimp := Array.mkEmpty lctx.decls.size for ldecl in lctx do if ldecl.isImplementationDetail then continue fvarIdsToSimp := fvarIdsToSimp.push ldecl.fvarId let ctx ← addLetDeclsToSimpTheoremsUnlessZetaDelta ctx Aesop.simpGoal mvarId ctx simprocs discharge? simplifyTarget fvarIdsToSimp stats
def
Aesop
[]
Aesop/Search/Expansion/Simp.lean
simpGoalWithAllHypotheses
null
simpAll (mvarId : MVarId) (ctx : Simp.Context) (simprocs : Simp.SimprocsArray) (stats : Simp.Stats := {}) : MetaM SimpResult := mvarId.withContext do let ctx := ctx.setFailIfUnchanged false let ctx ← addLetDeclsToSimpTheoremsUnlessZetaDelta ctx match ← Lean.Meta.simpAll mvarId ctx simprocs stats with | (none, stats) => return .solved stats.usedTheorems | (some mvarIdNew, stats) => if mvarIdNew == mvarId then return .unchanged else return .simplified mvarIdNew stats.usedTheorems
def
Aesop
[]
Aesop/Search/Expansion/Simp.lean
simpAll
null
Queue (Q : Type) where init : BaseIO Q addGoals : Q → Array GoalRef → BaseIO Q popGoal : Q → BaseIO (Option GoalRef × Q) namespace Queue
class
Aesop
[]
Aesop/Search/Queue/Class.lean
Queue
null
init' [Queue Q] (grefs : Array GoalRef) : BaseIO Q := do addGoals (← init) grefs
def
Aesop
[]
Aesop/Search/Queue/Class.lean
init'
null
ForwardRuleMatches where /-- Complete matches of norm rules. -/ normMatches : PHashSet ForwardRuleMatch /-- Complete matches of safe rules. -/ safeMatches : PHashSet ForwardRuleMatch /-- Complete matches of unsafe rules. -/ unsafeMatches : PHashSet ForwardRuleMatch deriving Inhabited namespace ForwardRuleMatches /-- Empty `ForwardRuleMatches`. -/
structure
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
ForwardRuleMatches
/-- Sets of complete matches for norm/safe/unsafe rules. -/
empty : ForwardRuleMatches where normMatches := ∅ safeMatches := ∅ unsafeMatches := ∅
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
empty
/-- Empty `ForwardRuleMatches`. -/
insert (m : ForwardRuleMatch) (ms : ForwardRuleMatches) : ForwardRuleMatches := match m.rule.name.phase with | .norm => { ms with normMatches := ms.normMatches.insert m } | .safe => { ms with safeMatches := ms.safeMatches.insert m } | .unsafe => { ms with unsafeMatches := ms.unsafeMatches.insert m } /-- Add several complete matches. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
insert
/-- Add a complete match. -/
insertMany (ms : Array ForwardRuleMatch) (ms' : ForwardRuleMatches) : ForwardRuleMatches := ms.foldl (init := ms') λ ms' m => ms'.insert m /-- Erase a complete match. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
insertMany
/-- Add several complete matches. -/
erase (m : ForwardRuleMatch) (ms : ForwardRuleMatches) : ForwardRuleMatches := match m.rule.name.phase with | .norm => { ms with normMatches := ms.normMatches.erase m } | .safe => { ms with safeMatches := ms.safeMatches.erase m } | .unsafe => { ms with unsafeMatches := ms.unsafeMatches.erase m } /-- Erase several complete matches. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
erase
/-- Erase a complete match. -/
eraseMany (ms : Array ForwardRuleMatch) (ms' : ForwardRuleMatches) : ForwardRuleMatches := ms.foldl (init := ms') λ ms' m => ms'.erase m /-- Build a `ForwardRuleMatches` structure containing the matches from `ms`. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
eraseMany
/-- Erase several complete matches. -/
ofArray (ms : Array ForwardRuleMatch) : ForwardRuleMatches := (∅ : ForwardRuleMatches).insertMany ms /-- Erase matches containing any of the hypotheses `hs` from `ms`. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
ofArray
/-- Build a `ForwardRuleMatches` structure containing the matches from `ms`. -/
eraseHyps (hs : Std.HashSet FVarId) (ms : ForwardRuleMatches) : ForwardRuleMatches where normMatches := go ms.normMatches safeMatches := go ms.safeMatches unsafeMatches := go ms.unsafeMatches where go (ms : PHashSet ForwardRuleMatch) : PHashSet ForwardRuleMatch := let toErase := ms.fold (init := #[]) λ toErase m => if m.anyHyp hs.contains then toErase.push m else toErase toErase.foldl (init := ms) λ ms m => ms.erase m /-- Erase matches containing the hypothesis `h` from `ms`. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
eraseHyps
/-- Erase matches containing any of the hypotheses `hs` from `ms`. -/
eraseHyp (h : FVarId) (ms : ForwardRuleMatches) : ForwardRuleMatches := ms.eraseHyps {h} /-- Update the `ForwardRuleMatches` of a goal so that they are suitable for a child goal. `newMatches` are new forward rule matches obtained by updating the old goal's `ForwardState` with new hypotheses from the new goal. `erasedHyps` are the hypotheses from the old goal that no longer appear in the new goal. `consumedForwardRuleMatches` contains forward rule matches that were applied as rules to transform the old goal into the new goal. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
eraseHyp
/-- Erase matches containing the hypothesis `h` from `ms`. -/
update (newMatches : Array ForwardRuleMatch) (erasedHyps : Std.HashSet FVarId) (consumedForwardRuleMatches : Array ForwardRuleMatch) (forwardRuleMatches : ForwardRuleMatches) : ForwardRuleMatches := Id.run do let mut ms := forwardRuleMatches for m in consumedForwardRuleMatches do ms := ms.erase m return ms.eraseHyps erasedHyps |>.insertMany newMatches
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
update
/-- Update the `ForwardRuleMatches` of a goal so that they are suitable for a child goal. `newMatches` are new forward rule matches obtained by updating the old goal's `ForwardState` with new hypotheses from the new goal. `erasedHyps` are the hypotheses from the old goal that no longer appear in the new goal. `consumedForwardRuleMatches` contains forward rule matches that were applied as rules to transform the old goal into the new goal. -/
pHashSetToArray [BEq α] [Hashable α] (s : PHashSet α) : Array α := s.fold (init := #[]) λ acc x => acc.push x /-- Get the norm rules corresponding to the norm rule matches. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
pHashSetToArray
null
normRules (ms : ForwardRuleMatches) : Array NormRule := forwardRuleMatchesToNormRules? (pHashSetToArray ms.normMatches) |>.get! /-- Get the safe rules corresponding to the safe rule matches. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
normRules
/-- Get the norm rules corresponding to the norm rule matches. -/
safeRules (ms : ForwardRuleMatches) : Array SafeRule := forwardRuleMatchesToSafeRules? (pHashSetToArray ms.safeMatches) |>.get! /-- Get the unsafe rules corresponding to the unsafe rule matches. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
safeRules
/-- Get the safe rules corresponding to the safe rule matches. -/
unsafeRules (ms : ForwardRuleMatches) : Array UnsafeRule := forwardRuleMatchesToUnsafeRules? (pHashSetToArray ms.unsafeMatches) |>.get! /-- `O(n)` Number of matches in `ms`. -/
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
unsafeRules
/-- Get the unsafe rules corresponding to the unsafe rule matches. -/
size (ms : ForwardRuleMatches) : Nat := ms.normMatches.fold (init := 0) (λ n _ => n + 1) + ms.safeMatches.fold (init := 0) (λ n _ => n + 1) + ms.unsafeMatches.fold (init := 0) (λ n _ => n + 1)
def
Aesop
[]
Aesop/Tree/Data/ForwardRuleMatches.lean
size
/-- `O(n)` Number of matches in `ms`. -/
ExtResult where depth : Nat commonFVarIds : Array FVarId goals : Array (MVarId × Array FVarId)
structure
Aesop
[]
Aesop/Util/Tactic/Ext.lean
ExtResult
null
straightLineExt (goal : MVarId) : MetaM ExtResult := go goal 0 #[] where go (goal : MVarId) (depth : Nat) (commonFVarIds : Array FVarId) : MetaM ExtResult:= do withConstAesopTraceNode .debug (return m!"straightLineExt") do aesop_trace[debug] "goal:{indentD goal}" let goals? ← show MetaM _ from observing? $ applyExtTheoremAt goal if let some goals := goals? then aesop_trace[debug] "ext lemma applied; new goals:{indentD $ Elab.goalsToMessageData goals}" let goals := goals.toArray if goals.isEmpty then return { depth := depth + 1, goals := #[], commonFVarIds := #[] } let goals ← goals.mapM λ goal => do let (fvarIds, goal) ← goal.intros return (goal, fvarIds) if h : goals.size = 1 then let (goal, fvarIds) := goals[0] go goal (depth + 1) (commonFVarIds ++ fvarIds) else return { depth := depth + 1, goals, commonFVarIds } else aesop_trace[debug] "no applicable ext lemma" return { depth, goals := #[(goal, #[])], commonFVarIds }
def
Aesop
[]
Aesop/Util/Tactic/Ext.lean
straightLineExt
null
straightLineExtProgress (goal : MVarId) : MetaM ExtResult := do let result ← straightLineExt goal if result.depth == 0 then throwError "no applicable extensionality theorem found" return result
def
Aesop
[]
Aesop/Util/Tactic/Ext.lean
straightLineExtProgress
null