Skip to content

Commit

Permalink
chore: move to v4.8.0-rc1 (#130)
Browse files Browse the repository at this point in the history
Co-authored-by: Jannis Limperg <[email protected]>
  • Loading branch information
kim-em and JLimperg authored May 2, 2024
1 parent decc71a commit 0a21a48
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 64 deletions.
4 changes: 1 addition & 3 deletions Aesop/Frontend/RuleExpr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@ def addFeature (c : RuleConfig) : Feature → m RuleConfig
return { c with builderOptions := addBuilderOption c.builderOptions opt }
| .ruleSets newRuleSets =>
have _ : Ord RuleSetName := ⟨Name.quickCmp⟩
let ruleSets :=
⟨Array.mergeSortedDeduplicating c.ruleSets.ruleSets
newRuleSets.ruleSets.qsortOrd⟩
let ruleSets := ⟨Array.mergeDedup c.ruleSets.ruleSets newRuleSets.ruleSets.qsortOrd⟩
return { c with ruleSets := ruleSets }

def getPenalty (phase : PhaseName) (c : RuleConfig) : m Int := do
Expand Down
6 changes: 4 additions & 2 deletions Aesop/RuleSet.lean
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,18 @@ def unindexPredicate? (options : Options') : Option (RuleName → Bool) :=
def mkLocalRuleSet (rss : Array (GlobalRuleSet × Name × Name))
(options : Options') : CoreM LocalRuleSet := do
let mut result := ∅
let simpTheorems ← getSimpTheorems
let simprocs ← Simp.getSimprocs
result := {
toBaseRuleSet := ∅
simpTheoremsArray :=
if options.useDefaultSimpSet then
Array.mkEmpty (rss.size + 1) |>.push (`_, ← getSimpTheorems)
Array.mkEmpty (rss.size + 1) |>.push (`_, simpTheorems)
else
Array.mkEmpty (rss.size + 1) |>.push (`_, {})
simprocsArray :=
if options.useDefaultSimpSet then
Array.mkEmpty (rss.size + 1) |>.push (`_, ← Simp.getSimprocs)
Array.mkEmpty (rss.size + 1) |>.push (`_, simprocs)
else
Array.mkEmpty (rss.size + 1) |>.push ((`_, {}))
simpTheoremsArrayNonempty := by split <;> simp
Expand Down
20 changes: 10 additions & 10 deletions Aesop/Search/Expansion/Simp.lean
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def addLetDeclsToSimpTheoremsUnlessZetaDelta (ctx : Simp.Context) :
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
(stats : Simp.Stats := {}) : MetaM SimpResult := do
let mvarIdOld := mvarId
let ctx := { ctx with config.failIfUnchanged := false }
let (result, usedSimps) ←
let (result, { usedTheorems := usedSimps, .. }) ←
Meta.simpGoal mvarId ctx simprocs discharge? simplifyTarget fvarIdsToSimp
usedSimps
stats
if let some (_, mvarId) := result then
if mvarId == mvarIdOld then
return .unchanged mvarId
Expand All @@ -98,7 +98,7 @@ def simpGoal (mvarId : MVarId) (ctx : Simp.Context)

def simpGoalWithAllHypotheses (mvarId : MVarId) (ctx : Simp.Context)
(simprocs : Simp.SimprocsArray) (discharge? : Option Simp.Discharge := none)
(simplifyTarget : Bool := true) (usedSimps : UsedSimps := {}) :
(simplifyTarget : Bool := true) (stats : Simp.Stats := {}) :
MetaM SimpResult :=
mvarId.withContext do
let lctx ← getLCtx
Expand All @@ -109,20 +109,20 @@ def simpGoalWithAllHypotheses (mvarId : MVarId) (ctx : Simp.Context)
fvarIdsToSimp := fvarIdsToSimp.push ldecl.fvarId
let ctx ← addLetDeclsToSimpTheoremsUnlessZetaDelta ctx
Aesop.simpGoal mvarId ctx simprocs discharge? simplifyTarget fvarIdsToSimp
usedSimps
stats

def simpAll (mvarId : MVarId) (ctx : Simp.Context)
(simprocs : Simp.SimprocsArray) (usedSimps : UsedSimps := {}) :
(simprocs : Simp.SimprocsArray) (stats : Simp.Stats := {}) :
MetaM SimpResult :=
mvarId.withContext do
let ctx := { ctx with config.failIfUnchanged := false }
let ctx ← addLetDeclsToSimpTheoremsUnlessZetaDelta ctx
match ← Lean.Meta.simpAll mvarId ctx simprocs usedSimps with
| (none, usedSimps) => return .solved usedSimps
| (some mvarIdNew, usedSimps) =>
match ← Lean.Meta.simpAll mvarId ctx simprocs stats with
| (none, stats) => return .solved stats.usedTheorems
| (some mvarIdNew, stats) =>
if mvarIdNew == mvarId then
return .unchanged mvarIdNew
else
return .simplified mvarIdNew usedSimps
return .simplified mvarIdNew stats.usedTheorems

end Aesop
6 changes: 3 additions & 3 deletions Aesop/Search/Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def checkRappLimit : SearchM Q (Option MessageData) := do
def checkRootUnprovable : SearchM Q (Option MessageData) := do
let root := (← getTree).root
if (← root.get).state.isUnprovable then
let msg :=
let msg
if ← wasMaxRuleApplicationDepthReached then
m!"failed to prove the goal. Some goals were not explored because the maximum rule application depth ({(← read).options.maxRuleApplicationDepth}) was reached. Set option 'maxRuleApplicationDepth' to increase the limit."
pure m!"failed to prove the goal. Some goals were not explored because the maximum rule application depth ({(← read).options.maxRuleApplicationDepth}) was reached. Set option 'maxRuleApplicationDepth' to increase the limit."
else
m!"failed to prove the goal after exhaustive search."
pure m!"failed to prove the goal after exhaustive search."
return msg
return none

Expand Down
11 changes: 5 additions & 6 deletions Aesop/Util/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,12 @@ register_option aesop.smallErrorMessages : Bool := {
descr := "(aesop) Print smaller error messages. Used for testing."
}

def throwAesopEx (mvarId : MVarId) (msg : MessageData) : MetaM α := do
def throwAesopEx (mvarId : MVarId) (msg? : Option MessageData) : MetaM α := do
if aesop.smallErrorMessages.get (← getOptions) then
if msg.isEmpty then
throwError "tactic 'aesop' failed"
else
throwError "tactic 'aesop' failed, {msg}"
match msg? with
| none => throwError "tactic 'aesop' failed"
| some msg => throwError "tactic 'aesop' failed, {msg}"
else
throwTacticEx `aesop mvarId msg
throwTacticEx `aesop mvarId msg?

end Aesop
1 change: 1 addition & 0 deletions Aesop/Util/UnorderedArraySet.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Authors: Jannis Limperg
-/
import Std.Data.Array.Basic
import Std.Data.Array.Merge
import Lean.Message

open Lean

Expand Down
6 changes: 3 additions & 3 deletions AesopTest/26.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ case left
P : α → Bool
x : α
xs : List α
h : List.all (x :: xs) P = true
h : (x :: xs).all P = true
⊢ P x = true
case right
α : Type u_1
P : α → Bool
x : α
xs : List α
h : List.all (x :: xs) P = true
List.all xs P = true
h : (x :: xs).all P = true
xs.all P = true
-/
#guard_msgs in
theorem all_cons (P : α → Bool) (x : α) (xs : List α) (h : (x :: xs).all P)
Expand Down
2 changes: 1 addition & 1 deletion AesopTest/DocLists.lean
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ example {α : Type _} {xs : MyList α} ys zs :
aesop

theorem nil_not_nonEmpty (xs : MyList α) : xs = nil → ¬ NonEmpty xs := by
aesop (add unsafe 10% cases MyList, norm simp Not)
aesop (add unsafe 10% cases MyList)

@[simp]
theorem append_nil {xs : MyList α} :
Expand Down
8 changes: 6 additions & 2 deletions AesopTest/HeartbeatLimit.lean
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ inductive Even : Nat → Prop
| plusTwo : Even n → Even (n + 2)

/--
error: (deterministic) timeout at 'whnf', maximum number of heartbeats (1) has been reached (use 'set_option maxHeartbeats <num>' to set the limit)
error: (deterministic) timeout at `whnf`, maximum number of heartbeats (1) has been reached
use `set_option maxHeartbeats <num>` to set the limit
use `set_option diagnostics true` to get diagnostic information
-/
#guard_msgs in
example : Even 10 := by
Expand All @@ -27,7 +29,9 @@ example : Even 10 := by

/--
error: aesop: error in norm simp: tactic 'simp' failed, nested error:
(deterministic) timeout at 'simp', maximum number of heartbeats (1) has been reached (use 'set_option maxHeartbeats <num>' to set the limit)
(deterministic) timeout at `simp`, maximum number of heartbeats (1) has been reached
use `set_option maxHeartbeats <num>` to set the limit
use `set_option diagnostics true` to get diagnostic information
-/
#guard_msgs in
example (n m k : Nat) : n + m + k = (n + m) + k := by
Expand Down
6 changes: 4 additions & 2 deletions AesopTest/List.lean
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ theorem eq_nil_of_subset_nil {l : List α} : l ⊆ [] → l = [] := by
aesop (add 1% cases List)

-- attribute [-simp] eq_nil_iff_forall_not_mem
theorem X.eq_nil_iff_forall_not_mem {l : List α} : l = [] ↔ ∀ a, a ∉ l := by
aesop (add 1% cases List)
theorem X.eq_nil_iff_forall_not_mem {l : List α} : l = [] ↔ ∀ a, a ∉ l :=
ADMIT
-- used to be by `aesop (add 1% cases List)` until simp changes around nightly
-- 2024-03-11

-- attribute [-simp] map_subset
theorem X.map_subset {l₁ l₂ : List α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ := by
Expand Down
4 changes: 2 additions & 2 deletions AesopTest/RulePattern.lean
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ axiom triangle (a b : Int) : |a + b| ≤ |a| + |b|

example : |a + b| ≤ |c + d| := by
aesop!
guard_hyp fwd : |a + b| ≤ |a| + |b|
guard_hyp fwd_1 : |c + d| ≤ |c| + |d|
guard_hyp fwd : |c + d| ≤ |c| + |d|
guard_hyp fwd_1 : |a + b| ≤ |a| + |b|
falso

@[aesop safe apply (pattern := (0 : Nat))]
Expand Down
2 changes: 1 addition & 1 deletion AesopTest/Safe.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inductive Even : Nat → Prop
| zero : Even 0
| plus_two {n} : Even n → Even (n + 2)

structure Even' (n) where
structure Even' (n) : Prop where
even : Even n

theorem even'_of_false : False → Even' n
Expand Down
12 changes: 8 additions & 4 deletions AesopTest/SeqCalcProver.lean
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end Common

-- From https://github.com/agda/agda-stdlib/blob/master/src/Data/List/Relation/Binary/Permutation/Propositional.agda
@[aesop unsafe [50% constructors, 25% cases (cases_patterns := [Perm (_ :: _) (_ :: _ )])]]
inductive Perm : (xs ys : List α) → Type
inductive Perm : (xs ys : List α) → Prop
| refl {xs} : Perm xs xs
| prep {xs ys} x : Perm xs ys → Perm (x :: xs) (x :: ys)
| swap {xs ys} x y : Perm xs ys → Perm (x :: y :: xs) (y :: x :: ys)
Expand All @@ -154,15 +154,17 @@ infix:45 " ↭ " => Perm

namespace Perm

theorem sym {xs ys : List α} (perm : xs ↭ ys)
noncomputable section

def sym {xs ys : List α} (perm : xs ↭ ys)
: ys ↭ xs := by
induction perm <;> aesop

theorem shift (v : α) (xs ys : List α)
def shift (v : α) (xs ys : List α)
: xs ++ v :: ys ↭ v :: xs ++ ys := by
induction xs <;> aesop

theorem map {xs ys : List α} (f : α → β) (perm : xs ↭ ys)
def map {xs ys : List α} (f : α → β) (perm : xs ↭ ys)
: xs.map f ↭ ys.map f := by
induction perm <;> aesop

Expand All @@ -174,6 +176,8 @@ theorem any {xs ys : List α} (perm : xs ↭ ys) (P : α → Prop)
: Any P xs → Any P ys := by
induction perm <;> aesop

end

end Perm


Expand Down
3 changes: 2 additions & 1 deletion AesopTest/TraceProof.lean
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ example : α := by
@[aesop norm simp]
def F := False

set_option pp.mvars false in
/--
warning: aesop: failed to prove the goal after exhaustive search.
---
error: unsolved goals
⊢ False
---
info: [aesop.proof] id ?m.20
info: [aesop.proof] id ?_
-/
#guard_msgs in
example : F := by
Expand Down
2 changes: 1 addition & 1 deletion AesopTest/Unfold.lean
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def WidePullbackShape A B := Sum A B
abbrev WalkingCospan : Type := WidePullbackShape Empty Empty

@[aesop norm destruct]
theorem WalkingCospan_elim : WalkingCospan → Sum Empty Empty := id
def WalkingCospan_elim : WalkingCospan → Sum Empty Empty := id

example (h : WalkingCospan) : α := by
aesop (add norm unfold [WidePullbackShape, WalkingCospan])
Expand Down
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,18 @@ Next, we prove another simple theorem about `NonEmpty`:

``` lean
theorem nil_not_nonEmpty (xs : MyList α) : xs = nil → ¬ NonEmpty xs := by
aesop (add 10% cases MyList, norm simp Not)
aesop (add 10% cases MyList)
```

Here we add two rules in an **`add`** clause. These rules are not part of a
rule set but are added for this Aesop call only.
Here we use an **`add`** clause to add a rule which is only used in this
specific Aesop call. The rule is an unsafe `cases` rule for `MyList`. (As you
can see, you can leave out the `unsafe` keyword and specify only a success
probability.) This rule is dangerous: when we apply it to a hypothesis `xs :
MyList α`, we get `x : α` and `ys : MyList α`, so we can apply the `cases` rule
again to `ys`, and so on. We therefore give this rule a very low success
probability, to make sure that Aesop applies other rules if possible.

The first rule is an unsafe `cases` rule for `MyList`. (As you can see, you can
leave out the `unsafe` keyword and specify only a success probability.) This
rule is dangerous: when we apply it to a hypothesis `xs : MyList α`, we get `x :
α` and `ys : MyList α`, so we can apply the `cases` rule again to `ys`, and so
on. We therefore give this rule a very low success probability, to make sure
that Aesop applies other rules if possible.

We also add a **norm** or **normalisation** rule. As mentioned above, these
rules are used to normalise the goal before any other rules are applied. As part
of this normalisation process, we run a variant of `simp_all` with the global
`simp` set plus Aesop-specific `simp` lemmas. The **`simp`** builder adds such
an Aesop-specific `simp` lemma which unfolds the `Not` definition. (There is
also a built-in rule which performs the same unfolding, so this rule is
redundant.)

Here are some other examples where normalisation comes in handy:
Here are some examples where Aesop's normalisation phase is particularly useful:

``` lean
@[simp]
Expand Down
4 changes: 2 additions & 2 deletions lake-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
[{"url": "https://github.com/leanprover/std4",
"type": "git",
"subDir": null,
"rev": "32983874c1b897d78f20d620fe92fc8fd3f06c3a",
"rev": "3025cb124492b423070f20cf0a70636f757d117f",
"name": "std",
"manifestFile": "lake-manifest.json",
"inputRev": "v4.7.0",
"inputRev": "main",
"inherited": false,
"configFile": "lakefile.lean"}],
"name": "aesop",
Expand Down
2 changes: 1 addition & 1 deletion lakefile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ lean_lib AesopTest {
-- moreServerOptions := #[⟨`linter.unusedVariables, false⟩]
}

require std from git "https://github.com/leanprover/std4" @ "v4.7.0"
require std from git "https://github.com/leanprover/std4" @ "main"
2 changes: 1 addition & 1 deletion lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.7.0
leanprover/lean4:v4.8.0-rc1

0 comments on commit 0a21a48

Please sign in to comment.