Skip to content

Commit

Permalink
chore: move to v4.6.0-rc1, merging adaptations (#100)
Browse files Browse the repository at this point in the history
Co-authored-by: Jannis Limperg <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>
Co-authored-by: Leonardo de Moura <[email protected]>
  • Loading branch information
4 people authored Feb 2, 2024
1 parent cebd10b commit 6beed82
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 29 deletions.
1 change: 0 additions & 1 deletion Aesop/Builder/Forward.lean
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def getImmediatePremises (name : Name) (type : Expr) (md : TransparencyMode) :
let mut unseen := immediate.sortAndDeduplicate (ord := ⟨Name.quickCmp⟩)
let mut result := #[]
for h : i in [:args.size] do
have h : i < args.size := by simp_all [Membership.mem]
let argName := (← args[i].fvarId!.getDecl).userName
if immediate.contains argName then
result := result.push i
Expand Down
8 changes: 4 additions & 4 deletions Aesop/Index.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ open Lean.Meta
namespace Aesop

structure Index (α : Type) [BEq α] [Hashable α] where
byTarget : DiscrTree α
byHyp : DiscrTree α
byTarget : DiscrTree α
byHyp : DiscrTree α
unindexed : PHashSet α
deriving Inhabited

Expand Down Expand Up @@ -56,9 +56,9 @@ partial def add (r : α) (imode : IndexingMode) (ri : Index α) :
| IndexingMode.unindexed =>
{ ri with unindexed := ri.unindexed.insert r }
| IndexingMode.target keys =>
{ ri with byTarget := ri.byTarget.insertCore keys r discrTreeConfig }
{ ri with byTarget := ri.byTarget.insertCore keys r }
| IndexingMode.hyps keys =>
{ ri with byHyp := ri.byHyp.insertCore keys r discrTreeConfig }
{ ri with byHyp := ri.byHyp.insertCore keys r }
| IndexingMode.or imodes =>
imodes.foldl (init := ri) λ ri imode =>
ri.add r imode
Expand Down
12 changes: 9 additions & 3 deletions Aesop/Search/Expansion/Simp.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Aesop.Script
import Aesop.RuleSet

open Lean Lean.Meta
open Lean.Elab.Tactic (mkSimpOnly)
open Simp (UsedSimps)

namespace Aesop
Expand Down Expand Up @@ -49,13 +50,15 @@ def mkNormSimpOnlySyntax (inGoal : MVarId) (normSimpUseHyps : Bool)
return ⟨stx⟩

def simpGoal (mvarId : MVarId) (ctx : Simp.Context)
(simprocs : Simp.SimprocsArray)
(discharge? : Option Simp.Discharge := none)
(simplifyTarget : Bool := true) (fvarIdsToSimp : Array FVarId := #[])
(usedSimps : UsedSimps := {}) : MetaM SimpResult := do
let mvarIdOld := mvarId
let ctx := { ctx with config.failIfUnchanged := false }
let (result, usedSimps) ←
Meta.simpGoal mvarId ctx discharge? simplifyTarget fvarIdsToSimp usedSimps
Meta.simpGoal mvarId ctx simprocs discharge? simplifyTarget fvarIdsToSimp
usedSimps
if let some (_, mvarId) := result then
if mvarId == mvarIdOld then
return .unchanged mvarId
Expand All @@ -65,6 +68,7 @@ def simpGoal (mvarId : MVarId) (ctx : Simp.Context)
return .solved usedSimps

def simpGoalWithAllHypotheses (mvarId : MVarId) (ctx : Simp.Context)
(simprocs : Simp.SimprocsArray := {})
(discharge? : Option Simp.Discharge := none)
(simplifyTarget : Bool := true) (usedSimps : UsedSimps := {}) :
MetaM SimpResult :=
Expand All @@ -75,12 +79,14 @@ def simpGoalWithAllHypotheses (mvarId : MVarId) (ctx : Simp.Context)
if ldecl.isImplementationDetail then
continue
fvarIdsToSimp := fvarIdsToSimp.push ldecl.fvarId
Aesop.simpGoal mvarId ctx discharge? simplifyTarget fvarIdsToSimp usedSimps
Aesop.simpGoal mvarId ctx simprocs discharge? simplifyTarget fvarIdsToSimp
usedSimps

def simpAll (mvarId : MVarId) (ctx : Simp.Context)
(simprocs : Simp.SimprocsArray := {})
(usedSimps : UsedSimps := {}) : MetaM SimpResult := do
let ctx := { ctx with config.failIfUnchanged := false }
match ← Lean.Meta.simpAll mvarId ctx usedSimps with
match ← Lean.Meta.simpAll mvarId ctx simprocs usedSimps with
| (none, usedSimps) => return .solved usedSimps
| (some mvarIdNew, usedSimps) =>
if mvarIdNew == mvarId then
Expand Down
3 changes: 2 additions & 1 deletion Aesop/Search/SearchM.lean
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ protected def run (ruleSet : RuleSet) (options : Aesop.Options')
MetaM (α × State Q × Tree × Profile) := do
let t ← mkInitialTree goal
let normSimpContext := {
(← Simp.Context.mkDefault) with
config := simpConfig
maxDischargeDepth := UInt32.ofNatTruncate simpConfig.maxDischargeDepth
simpTheorems := ruleSet.globalNormSimpTheorems
congrTheorems := ← getSimpCongrTheorems
configStx? := simpConfigStx?
enabled := options.enableSimp
useHyps := options.useSimpAll
Expand Down
9 changes: 4 additions & 5 deletions Aesop/Util/Tactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,24 @@ where
-- is slow but correct.
pre (e : Expr) : StateRefT (HashSet Name) SimpM Simp.Step := do
let some decl := e.getAppFn'.constName?
| return .visit { expr := e }
| return .continue
match unfold? decl with
| none =>
return .visit { expr := e }
return .continue
| some none =>
if let some e' ← delta? e (λ n => n == decl) then
modify (·.insert decl)
return .done { expr := e' }
else
return .visit { expr := e }
return .continue
| some (some unfoldThm) =>
let result? ← withReducible <|
Simp.tryTheorem? e
{ origin := .decl unfoldThm
proof := mkConst unfoldThm
rfl := ← isRflTheorem unfoldThm }
(fun _ => return none)
match result? with
| none => return .visit { expr := e }
| none => return .continue
| some r =>
modify (·.insert decl)
match (← reduceMatcher? r.expr) with
Expand Down
1 change: 0 additions & 1 deletion AesopTest/List.lean
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ set_option aesop.check.script true
-- use `sorry` because it generates lots of warnings.
axiom ADMIT : ∀ {α : Sort _}, α

@[aesop safe cases]
class IsEmpty (α : Sort _) where
false : α → False

Expand Down
15 changes: 12 additions & 3 deletions AesopTest/NormSimp.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ example (h : (α ∧ β) ∨ γ) : α ∨ γ := by

-- This test checks that the norm simp config is passed around properly.
example {α β : Prop} (ha : α) (h : α → β) : β := by
fail_if_success aesop (rule_sets [-builtin,-default])
(simp_config := { maxDischargeDepth := 0 })
(config := { terminal := true })
fail_if_success
aesop (rule_sets [-builtin,-default])
(simp_config := { maxDischargeDepth := 0 })
(config := { terminal := true })
aesop (rule_sets [-builtin,-default])

-- Ditto.
example : true && false = false := by
fail_if_success aesop
(rule_sets [-default,-builtin])
(config := { terminal := true })
(simp_config := { decide := false })
aesop (rule_sets [-default,-builtin]) (simp_config := { decide := true })

-- We can use the `useHyps` config option to switch between `simp_all` and
-- `simp at *`.
example {α : Prop} (ha : α) : α := by
Expand Down
17 changes: 8 additions & 9 deletions AesopTest/SeqCalcProver.lean
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ theorem mem (P : α → Prop) (xs : List α)
case mpr =>
intro ⟨a, Pa, Ea⟩
induction Ea <;> aesop
termination_by _ => List.length xs

theorem map (P : β → Prop) (f : α → β) (xs : List α)
: Any P (xs.map f) ↔ Any (fun x => P (f x)) xs := by
Expand Down Expand Up @@ -241,8 +240,8 @@ def Cal (l r : List Φ) : (Γ Δ : List (Form Φ)) → Prop
| Γ, ♩n :: Δ => Cal l (n :: r) Γ Δ
| φ ⇒ ψ :: Γ, [] => Cal l r Γ [φ] ∧ Cal l r (ψ :: Γ) []
| Γ, φ ⇒ ψ :: Δ => Cal l r (φ :: Γ) (ψ :: Δ)
termination_by _ Γ Δ => sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by simp_wf <;> simp_arith
termination_by Γ Δ => sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by all_goals simp_wf <;> simp_arith

instance Cal.instDecidable [DecidableEq Φ] (l r : List Φ) (Γ Δ : List (Form Φ))
: Decidable (Cal l r Γ Δ) := by
Expand All @@ -265,8 +264,8 @@ instance Cal.instDecidable [DecidableEq Φ] (l r : List Φ) (Γ Δ : List (Form
| Γ, φ ⇒ ψ :: Δ =>
have ih : Decidable (Cal l r (φ :: Γ) (ψ :: Δ)) := instDecidable l r (φ :: Γ) (ψ :: Δ)
aesop
termination_by _ => sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by simp_wf <;> simp_arith
termination_by sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by all_goals simp_wf <;> simp_arith

abbrev Prove (φ : Form Φ) : Prop := Cal [] [] [] [φ]

Expand Down Expand Up @@ -385,8 +384,8 @@ theorem Cal_sound_complete [DecidableEq Φ]
have AllΓ : All (Val i) (Γ ++ l.map (♩·)) := by simp_all
have AnyφψΔ : Any (Val i) (φ ⇒ ψ :: Δ ++ r.map (♩·)) := h i dec AllΓ
simp_all
termination_by _ => sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by simp_wf <;> simp_arith
termination_by sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by all_goals simp_wf <;> simp_arith

theorem Prove_sound_complete [DecidableEq Φ] (φ : Form Φ)
: Prove φ ↔ Valid φ := by
Expand Down Expand Up @@ -477,8 +476,8 @@ theorem Cal_Proof [DecidableEq Φ]
simp at h
have ih : Proof' l r (φ :: Γ) (ψ :: Δ) := Cal_Proof l r (φ :: Γ) (ψ :: Δ) h
aesop
termination_by _ => sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by simp_wf <;> simp_arith
termination_by sum (Γ.map sizeOf) + sum (Δ.map sizeOf)
decreasing_by all_goals simp_wf <;> simp_arith

theorem Proof_sound_complete [DecidableEq Φ] (φ : Form Φ)
: Proof [] [φ] ↔ Valid φ := by
Expand Down
2 changes: 1 addition & 1 deletion lake-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[{"url": "https://github.com/leanprover/std4",
"type": "git",
"subDir": null,
"rev": "08ec2584b1892869e3a5f4122b029989bcb4ca79",
"rev": "276953b13323ca151939eafaaec9129bf7970306",
"name": "std",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
Expand Down
2 changes: 1 addition & 1 deletion lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.5.0
leanprover/lean4:v4.6.0-rc1

0 comments on commit 6beed82

Please sign in to comment.