Skip to content

Commit

Permalink
feat(apply_fun): handle implicit arguments (#6091)
Browse files Browse the repository at this point in the history
I've modified the way `apply_fun` handles inequalities, by building an intermediate expression before calling `mono` to discharge the `monotone f` subgoal. This has the effect of sometimes filling in implicit arguments successfully, so that `mono` works.

In `tests/apply_fun.lean` I've added an example showing this in action 


Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
  • Loading branch information
semorrison and semorrison committed Feb 16, 2021
1 parent d3c5667 commit 3cec1cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/tactic/apply_fun.lean
Expand Up @@ -22,14 +22,20 @@ do {
to_expr ``(congr_arg (%%e : %%ltp → %%mv) %%hyp)
| `(%%l ≤ %%r) := do
Hmono ← match mono_lem with
| some mono_lem :=
tactic.i_to_expr mono_lem
| none := do
n ← get_unused_name `mono,
to_expr ``(monotone %%e) >>= assert n,
do { intro_lst [`x, `y, `h], `[dsimp, mono], skip } <|> swap,
get_local n
end,
| some mono_lem :=
tactic.i_to_expr mono_lem
| none := do
n ← get_unused_name `mono,
to_expr ``(monotone %%e) >>= assert n,
-- In order to resolve implicit arguments in `%%e`,
-- we build (and discard) the expression `%%n %%hyp` before calling the `mono` tactic.
swap,
n ← get_local n,
to_expr ``(%%n %%hyp),
swap,
do { intro_lst [`x, `y, `h], `[try { dsimp }, mono] } <|> swap,
return n
end,
to_expr ``(%%Hmono %%hyp)
| _ := fail ("failed to apply " ++ to_string e ++ " at " ++ to_string hyp.local_pp_name)
end,
Expand Down
2 changes: 1 addition & 1 deletion src/tactic/monotonicity/lemmas.lean
Expand Up @@ -71,7 +71,7 @@ open set
attribute [mono] inter_subset_inter union_subset_union
sUnion_mono bUnion_mono sInter_subset_sInter bInter_mono
image_subset preimage_mono prod_mono monotone_prod seq_mono
image2_subset
image2_subset order_embedding.monotone
attribute [mono] upper_bounds_mono_set lower_bounds_mono_set
upper_bounds_mono_mem lower_bounds_mono_mem
upper_bounds_mono lower_bounds_mono
Expand Down
7 changes: 7 additions & 0 deletions test/apply_fun.lean
Expand Up @@ -47,3 +47,10 @@ begin
guard_hyp' h : f (A * B) = f 0,
exact h,
end

-- Verify that `apply_fun` works with `fin.cast_succ`, even though it has an implicit argument.
example (n : ℕ) (a b : fin n) (H : a ≤ b) : a.cast_succ ≤ b.cast_succ :=
begin
apply_fun fin.cast_succ at H,
exact H,
end

0 comments on commit 3cec1cf

Please sign in to comment.