lean4-htt/tests/elab/binderNameHint.lean
Garmelon 08eb78a5b2
chore: switch to new test/bench suite (#12590)
This PR sets up the new integrated test/bench suite. It then migrates
all benchmarks and some related tests to the new suite. There's also
some documentation and some linting.

For now, a lot of the old tests are left alone so this PR doesn't become
even larger than it already is. Eventually, all tests should be migrated
to the new suite though so there isn't a confusing mix of two systems.
2026-02-25 13:51:53 +00:00

95 lines
2.9 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

theorem all_eq_not_any_not (l : List α) (p : α → Bool) :
l.all p = !l.any fun x => binderNameHint x p (!p x)
:= List.all_eq_not_any_not
/--
error: Failed: `fail` tactic was invoked
names : List String
⊢ (!names.any fun name => !"Waldo".isPrefixOf name) = true
-/
#guard_msgs in
example (names : List String) : names.all (fun name => "Waldo".isPrefixOf name) = true := by
rw [all_eq_not_any_not]
fail
/--
error: Failed: `fail` tactic was invoked
names : List String
⊢ (names.any fun name => !"Waldo".isPrefixOf name) = false
-/
#guard_msgs in
example (names : List String) : names.all (fun name => "Waldo".isPrefixOf name) = true := by
simp [all_eq_not_any_not, -List.any_eq_false]
fail
def List.myAll (p : α → Bool) (xs : List α) : Bool := !(xs.any fun x => !p x)
theorem myAll_eq_not_any_not (l : List α) (p : α → Bool) :
l.myAll p = !l.any fun x => binderNameHint x p (!p x)
:= rfl
/--
error: Failed: `fail` tactic was invoked
names : List String
⊢ (!names.any fun name => !"Waldo".isPrefixOf name) = true
-/
#guard_msgs in
example (names : List String) : names.myAll (fun name => "Waldo".isPrefixOf name) = true := by
dsimp [myAll_eq_not_any_not]
fail
-- Check if we can pick the second binder by providing arguments to `f` in `binderNameHint`
-- (It will beta-reduce it)
-- Why this not in standard lib (maybe with the more complex form of recognizing lambdas that
-- ignore arguments?)
@[simp]
theorem List.mapIdx_eq_map (l : List α) (f : α → β) : (l.mapIdx fun _ x => f x) = l.map f := by
induction l <;> simp_all
set_option linter.unusedVariables false in
theorem zipWith_eq_map_idx_zipWith (l1 : List α) (l2 : List β) (f : α → β → γ) :
List.zipWith f l1 l2 = (List.zip l1 l2).mapIdx
(fun i ⟨a, b⟩ => binderNameHint a f <| binderNameHint b (f a) <| f a b)
:= by simp [List.zip_eq_zipWith, List.map_zipWith]
/--
error: Failed: `fail` tactic was invoked
l1 l2 : List Nat
⊢ (List.mapIdx
(fun i x =>
match x with
| (x, y) => x + y)
(l1.zip l2)).isEmpty =
true
-/
#guard_msgs in
example (l1 l2 : List Nat) :
(List.zipWith (fun x y => x + y) l1 l2).isEmpty := by
rw [zipWith_eq_map_idx_zipWith]
fail
-- For now, binder name hints do not work in other tactics, like `apply`
-- (but at least `simp` or `dsimp` removes them)
theorem myAll_eq_not_any_not_iff {l : List α} {p : α → Bool} :
l.myAll p ↔ !l.any fun x => binderNameHint x p (!p x)
:= by simp [myAll_eq_not_any_not]
/--
error: unsolved goals
names : List String
⊢ (!names.any fun x => !"Waldo".isPrefixOf x) = true
---
trace: names : List String
⊢ (!names.any fun x => binderNameHint x (fun name => "Waldo".isPrefixOf name) !"Waldo".isPrefixOf x) = true
-/
#guard_msgs in
example (names : List String) : names.myAll (fun name => "Waldo".isPrefixOf name) = true := by
apply myAll_eq_not_any_not_iff.mpr
trace_state
dsimp
done