Skip to content

Commit

Permalink
fix: array_get_dec etc. tactics to solve more cases
Browse files Browse the repository at this point in the history
Using `Nat.lt_trans` is too restrictive, and using `Nat.lt_of_lt_of_le`
should make this tactic prove more goals.

Fixes #5027
  • Loading branch information
nomeata committed Aug 14, 2024
1 parent 5f31e93 commit c4325e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Init/Data/Array/Mem.lean
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ macro "array_get_dec" : tactic =>
-- subsumed by simp
-- | with_reducible apply sizeOf_get
-- | with_reducible apply sizeOf_getElem
| (with_reducible apply Nat.lt_trans (sizeOf_get ..)); simp_arith
| (with_reducible apply Nat.lt_trans (sizeOf_getElem ..)); simp_arith
| (with_reducible apply Nat.lt_of_lt_of_le (sizeOf_get ..)); simp_arith
| (with_reducible apply Nat.lt_of_lt_of_le (sizeOf_getElem ..)); simp_arith
)

macro_rules | `(tactic| decreasing_trivial) => `(tactic| array_get_dec)
Expand All @@ -52,7 +52,7 @@ macro "array_mem_dec" : tactic =>
`(tactic| first
| with_reducible apply Array.sizeOf_lt_of_mem; assumption; done
| with_reducible
apply Nat.lt_trans (Array.sizeOf_lt_of_mem ?h)
apply Nat.lt_of_lt_of_le (Array.sizeOf_lt_of_mem ?h)
case' h => assumption
simp_arith)

Expand Down
2 changes: 1 addition & 1 deletion src/Init/Data/List/BasicAux.lean
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ macro "sizeOf_list_dec" : tactic =>
`(tactic| first
| with_reducible apply sizeOf_lt_of_mem; assumption; done
| with_reducible
apply Nat.lt_trans (sizeOf_lt_of_mem ?h)
apply Nat.lt_of_lt_of_le (sizeOf_lt_of_mem ?h)
case' h => assumption
simp_arith)

Expand Down
16 changes: 16 additions & 0 deletions tests/lean/run/issue5027.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
inductive Term (α: Type): Type where
| Composite : Array (Term α) → Term α
| Atom: α → Term α

-- height of a term
def height (f: Term α): Nat :=
let rec max_height (a: Array (Term α)) (i: Nat) (m: Nat): Nat :=
if h: i < a.size then
-- The recusive call to height used to fail because of a too weak
-- array_get_dec
max_height a (i + 1) (max (height a[i]) m)
else
m
match f with
| .Composite a => 1 + max_height a 0 0
| .Atom _ => 1

0 comments on commit c4325e7

Please sign in to comment.