Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import order.basic
  2.  
  3. open tactic interactive (parse) interactive (loc.ns)
  4. interactive.types (texpr location) lean.parser (tk)
  5.  
  6. local postfix `?`:9001 := optional
  7.  
  8. meta def apply_fun_name (e : expr) (h : name) (M : option pexpr) : tactic unit :=
  9. do {
  10. H ← get_local h,
  11. t ← infer_type H,
  12. match t with
  13. | `(%%l = %%r) := do
  14. tactic.interactive.«have» h ``(%%e %%l = %%e %%r) ``(congr_arg %%e %%H),
  15. tactic.clear H
  16. | `(%%l ≤ %%r) := do
  17. if M.is_some then do
  18. Hmono ← M >>= tactic.i_to_expr,
  19. tactic.interactive.«have» h ``(%%e %%l ≤ %%e %%r) ``(%%Hmono %%H)
  20. else do {
  21. n ← get_unused_name `mono,
  22. tactic.interactive.«have» n ``(monotone %%e) none,
  23. swap,
  24. Hmono ← get_local n,
  25. tactic.interactive.«have» h ``(%%e %%l ≤ %%e %%r) ``(%%Hmono %%H) },
  26. tactic.clear H
  27. | _ := skip
  28. end } <|> fail ("failed to apply " ++ to_string e ++ " at " ++ to_string h)
  29.  
  30. namespace tactic.interactive
  31. /-- Apply a function to some local assumptions which are either equalities or
  32. inequalities. For instance, if the context contains `h : a = b` and
  33. some function `f` then `apply_fun f at h` turns `h` into `h : f a = f b`.
  34. When the assumption is an inequality `h : a ≤ b`, a side goal `monotone f`
  35. is created, unless this condition is provided using
  36. `apply_fun f at h using P` where `P : monotone f`. -/
  37. meta def apply_fun (q : parse texpr) (locs : parse location)
  38. (lem : parse (tk "using" *> texpr)?) : tactic unit :=
  39. do e ← tactic.i_to_expr q,
  40. match locs with
  41. | (loc.ns l) := do
  42. l.mmap' (λ l, match l with
  43. | some h := apply_fun_name e h lem
  44. | none := skip
  45. end)
  46. | wildcard := do ctx ← local_context,
  47. ctx.mmap' (λ h, apply_fun_name e h.local_pp_name lem)
  48. end
  49. end tactic.interactive
  50.  
  51. open function
  52.  
  53. example (X Y Z : Type) (f : X → Y) (g : Y → Z) (H : injective $ g ∘ f) :
  54. injective f :=
  55. begin
  56. intros x x' h,
  57. apply_fun g at h,
  58. exact H h
  59. end
  60.  
  61. example (f : ℕ → ℕ) (a b : ℕ) (monof : monotone f) (h : a ≤ b) : f a ≤ f b :=
  62. begin
  63. apply_fun f at h,
  64. assumption,
  65. assumption
  66. end
  67.  
  68. example (f : ℕ → ℕ) (a b : ℕ) (monof : monotone f) (h : a ≤ b) : f a ≤ f b :=
  69. begin
  70. apply_fun f at h using monof,
  71. assumption
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement