Zulip Chat Archive
Stream: new members
Topic: Anonymous `apply` or `specialize`
nrs (Sep 03 2024 at 15:44):
If I have these inaccessible hypotheses,
a✝ : ∀ (x : α), p x ∧ q x
x✝ : α
is there a way to either use apply
anonymously or specialize
anonymously?
Kyle Miller (Sep 03 2024 at 15:56):
No, you are either supposed to name the hypotheses at the place where they were introduced (this is usually possible) or name them with rename_i
or next ... =>
Kyle Miller (Sep 03 2024 at 15:56):
(Please give a #mwe for more specific advice)
nrs (Sep 03 2024 at 16:08):
Kyle Miller said:
No, you are either supposed to name the hypotheses at the place where they were introduced (this is usually possible) or name them with
rename_i
ornext ... =>
example : (∀ x, p x) ∧ (∀ x, q x) -> (∀ x, p x ∧ q x) := by
intro h x
cases h
rename_i a b
specialize a x
specialize b x
apply And.intro <;> assumption
For example, it seems to me natural in the above proof to abstract away this part:
rename_i a b
specialize a x
specialize b x
by directly specializing all possible statements
Kyle Miller (Sep 03 2024 at 16:11):
An example of using a tactic that can name the new hypotheses:
example : (∀ x, p x) ∧ (∀ x, q x) -> (∀ x, p x ∧ q x) := by
intro h x
obtain ⟨a, b⟩ := h
specialize a x
specialize b x
apply And.intro <;> assumption
Kyle Miller (Sep 03 2024 at 16:11):
This can be combined with intro
:
example : (∀ x, p x) ∧ (∀ x, q x) -> (∀ x, p x ∧ q x) := by
intro ⟨a, b⟩ x
specialize a x
specialize b x
apply And.intro <;> assumption
Kyle Miller (Sep 03 2024 at 16:12):
(You can use constructor
instead of apply And.intro
. It does the same thing, but you don't need to know the name And.intro
)
nrs (Sep 03 2024 at 16:12):
Kyle Miller said:
(You can use
constructor
instead ofapply And.intro
. It does the same thing, but you don't need to know the nameAnd.intro
)
ah very cool tips! thanks a lot, way sleeker looking
Jireh Loreaux (Sep 03 2024 at 16:18):
I know this isn't directly the content of the question, but I wouldn't use specialize
here, as I don't think it's contributing anything. Of course, you can golf this all the way down to:
universe u
variable {X : Type u} {p q : X → Prop}
example : (∀ x, p x) ∧ (∀ x, q x) -> (∀ x, p x ∧ q x) :=
fun ⟨a, b⟩ x ↦ ⟨a x, b x⟩
Jireh Loreaux (Sep 03 2024 at 16:20):
Or, if you have allow a very small import:
import Init.PropLemmas
universe u
variable {X : Type u} {p q : X → Prop}
example : (∀ x, p x) ∧ (∀ x, q x) -> (∀ x, p x ∧ q x) :=
forall_and.mpr
nrs (Sep 03 2024 at 16:24):
Jireh Loreaux said:
I know this isn't directly the content of the question, but I wouldn't use
specialize
here, as I don't think it's contributing anything. Of course, you can golf this all the way down to:universe u variable {X : Type u} {p q : X → Prop} example : (∀ x, p x) ∧ (∀ x, q x) -> (∀ x, p x ∧ q x) := fun ⟨a, b⟩ x ↦ ⟨a x, b x⟩
woah! that is probably the most optimized version possible and nevertheless very clear in what it does. thanks!!
Kyle Miller (Sep 03 2024 at 16:53):
And of course, this is a basic logical tautology, so the tauto
tactic works too :smile:
example : (∀ x, p x) ∧ (∀ x, q x) -> (∀ x, p x ∧ q x) := by tauto
Jireh Loreaux (Sep 03 2024 at 17:36):
I didn't remember that tauto
handles ∀
. And in fact, it doesn't according to #help tactic tauto
. @Kyle Miller what exactly is in scope for tauto
?
Kyle Miller (Sep 03 2024 at 18:08):
@Jireh Loreaux Oh, it seems that I've misunderstood the scope of tauto, and it accidentally works here.
This is a tautology, but tauto
fails for it:
example : (∀ x, p x) ∧ (∀ x, q x) ↔ (∀ x, p x ∧ q x) := by tauto
Last updated: May 02 2025 at 03:31 UTC