Zulip Chat Archive

Stream: new members

Topic: How to use proofs from Lean's standard library.


newptcai (Jul 05 2023 at 08:20):

I read in Theorem Proving in Lean 4 that

Lean's standard library contains proofs of many valid statements of propositional logic, all of which you are free to use in proofs of your own.

But I could not find anywhere of how to use any of the proofs listed in the document. Can anyone help me find how to use, say something like
p ∧ q ↔ q ∧ p?

Martin Dvořák (Jul 05 2023 at 08:29):

If you have a lemma foo : bar ↔ baz you will typically use it as rw [foo] or similar.

Kyle Miller (Jul 05 2023 at 08:34):

docs#and_comm is a ∧ b ↔ b ∧ a

Kyle Miller (Jul 05 2023 at 08:36):

(I guess this one is in the std4 library rather than Lean 4 itself. If you are using mathlib, then you definitely have and_comm.)

newptcai (Jul 05 2023 at 08:36):

Kyle Miller said:

docs#and_comm is a ∧ b ↔ b ∧ a

Thanks. But how can I load it in my .lean file?

Kyle Miller (Jul 05 2023 at 08:37):

Have you done any exercises yet? (Do you have a working Lean environment?)

Martin Dvořák (Jul 05 2023 at 08:37):

First, show us your lakefile.lean.

Sebastian Ullrich (Jul 05 2023 at 08:39):

And.comm does not have to be imported

Patrick Massot (Jul 05 2023 at 08:40):

Kyle, you're referring to Lean 3 here.

Patrick Massot (Jul 05 2023 at 08:40):

The question is explicitly about Lean 4.

newptcai (Jul 05 2023 at 08:40):

I am doing the exercise at the end of this page
Here's my code.

variable (p q r : Prop)

theorem and_comm : p  q  q  p :=
  (fun h: p  q =>
      have hp : p := h.left
      have hq : q := h.right
      hq, hp⟩)

-- commutativity of ∧ and ∨
example : p  q  q  p :=
  Iff.intro
    (and_comm p q)
    (and_comm q p)

I was just wonder if this has already been implemented in Lean so I can use directly.

Kyle Miller (Jul 05 2023 at 08:41):

(@Patrick Massot the docs linkifier is for the mathlib4 docs now)

Patrick Massot (Jul 05 2023 at 08:42):

Oh right, I need to get used to this.

Kyle Miller (Jul 05 2023 at 08:42):

@newptcai Sebastian pointed out that docs#And.comm should be available to you

newptcai (Jul 05 2023 at 08:45):

Thank you all. This seems to work

example : p  q  q  p := And.comm

Alexander Lucas (Aug 15 2023 at 04:50):

[redacted] (sorry about that)


Last updated: Dec 20 2023 at 11:08 UTC