Zulip Chat Archive

Stream: general

Topic: Functions and Propositions


Olonbayar Temuulen (Apr 15 2022 at 05:31):

Sorry for a noob question, but is there any difference between the have and apply tactics when used on functions and propositions? (The first thought would be that its the same since they are both understood by Lean as types, but my intuition is telling me that maybe it is not exactly the case)?

Mario Carneiro (Apr 15 2022 at 05:59):

have and apply are actually fairly different, and they do not ever have the same behavior

Mario Carneiro (Apr 15 2022 at 06:00):

apply changes the goal by applying a lemma and giving you subgoals for the hypotheses ("backward reasoning")

Mario Carneiro (Apr 15 2022 at 06:00):

have adds a hypothesis to your context given a proof term ("forward reasoning")

Mario Carneiro (Apr 15 2022 at 06:06):

Rereading your question, perhaps I misread and you meant to compare functions to propositions when used in have and apply. In this case, the answer is that there is no difference: you can use apply to apply a function and get subgoals for the arguments of the function, in just the same way as with lemmas:

def foo : nat :=
begin
  let x : nat,
  { apply nat.succ,
    exact 2 },
  apply nat.add,
  { exact 2 },
  { exact x },
end

#print foo
-- def foo : ℕ :=
-- let x : ℕ := 2.succ in 2.add x

Olonbayar Temuulen (Apr 15 2022 at 08:24):

Mario Carneiro said:

Rereading your question, perhaps I misread and you meant to compare functions to propositions when used in have and apply. In this case, the answer is that there is no difference: you can use apply to apply a function and get subgoals for the arguments of the function, in just the same way as with lemmas:

def foo : nat :=
begin
  let x : nat,
  { apply nat.succ,
    exact 2 },
  apply nat.add,
  { exact 2 },
  { exact x },
end

#print foo
-- def foo : ℕ :=
-- let x : ℕ := 2.succ in 2.add x

Another noob question -> if A->B is a function, is A->B->C a function as well?

Arthur Paulino (Apr 15 2022 at 08:28):

I'd say that both A->B and A->B->C are types

Olonbayar Temuulen (Apr 15 2022 at 08:29):

If I may ask another dumb question -> what is the mathematical difference between functions and types?

Arthur Paulino (Apr 15 2022 at 08:31):

What do you mean by "mathematical difference"?

Eric Wieser (Apr 15 2022 at 08:31):

Functions are an example of a type

Olonbayar Temuulen (Apr 15 2022 at 08:31):

Arthur Paulino said:

What do you mean by "mathematical difference"?

are these same objects?

Arthur Paulino (Apr 15 2022 at 08:33):

Ah, no. You can have many functions from Nat to Nat, but Nat -> Nat is one type

Olonbayar Temuulen (Apr 15 2022 at 08:34):

Arthur Paulino said:

Ah, no. You can have many functions from Nat to Nat, but Nat -> Nat is one type

what do you mean by "one type"?

Arthur Paulino (Apr 15 2022 at 08:35):

I mean that all functions from nat to Nat have that same type

Arthur Paulino (Apr 15 2022 at 08:39):

What's your background? Computer science, mathematics or some other?

Olonbayar Temuulen (Apr 15 2022 at 11:32):

Arthur Paulino said:

What's your background? Computer science, mathematics or some other?

Theoretical Economics, Game Theory

Kevin Buzzard (Apr 15 2022 at 13:33):

A type is what a mathematician calls a set. A term is what they call an element. You can look at the set of all functions from X to Y and that's a type in Lean. Or you can look at one function from X to Y and that's a term

Jireh Loreaux (Apr 15 2022 at 14:23):

Related to what Kevin is saying, I think this might be part of the confusion: ℕ → ℕ is the type of (all) functions from ℕ to itself. A term f of this type (denoted f : ℕ → ℕ) is a specific function from ℕ to itself.

Kevin Buzzard (Apr 15 2022 at 14:28):

Yeah, X -> Y is what I'd call Hom(X,Y)

Olonbayar Temuulen (Apr 15 2022 at 21:47):

thank you, everybody, I'm looking forward to asking more dumb questions, but hopefully each time a bit more meaningful than the last one.

Olonbayar Temuulen (Apr 18 2022 at 01:27):

Why does the "cc" tactic work on "and" logical operations (and many others) but not for "OR"?

Mario Carneiro (Apr 18 2022 at 05:46):

cc is for congruence closure, which is to say it proves that some number of equalities implies another equality. It can do some basic preprocessing of the hypotheses which includes breaking up ANDs in the hypotheses and conclusion, but it is not a generic propositional or SMT solver and you should generally use other tactics to perform this kind of preprocessing


Last updated: Dec 20 2023 at 11:08 UTC