Zulip Chat Archive

Stream: new members

Topic: help


Steven (Jul 21 2021 at 11:16):

Can anybody help me with setting up lean?

Steven (Jul 21 2021 at 11:18):

I run ubuntu, and have everything working, except that I cannot import anything out of the mathlib library

Kevin Buzzard (Jul 21 2021 at 11:19):

we could start by you giving a more precise description of what you have done so far and what is not working, including perhaps screenshots

Kevin Buzzard (Jul 21 2021 at 11:20):

but here is some generic advice: make sure you have made a project with leanproject and you are opening the project folder with VS Code's "open folder" functionality. PS if you are getting an error in VS Code which contains a link to a web page, read that web page.

Steven (Jul 21 2021 at 11:24):

damn, you just gave the solution: I hadn't opened the folder using vscode, but it's parent folder
Thank you!!

kctron sub (Mar 01 2022 at 01:01):

image.png

kctron sub (Mar 01 2022 at 01:01):

how to prove C y now?

kctron sub (Mar 01 2022 at 01:01):

i understand it logically, if a or b has to be true, then c is always true, but how to do it in lean

Mario Carneiro (Mar 01 2022 at 01:04):

The cases h4 with ha hb tactic will split the goal into two goals, one where ha : A y and one with hb : B y

Mario Carneiro (Mar 01 2022 at 01:10):

If you are using lean 4 (it is hard to tell from your examples whether this is lean 3 or 4), this is written

cases h4 with
| inl ha => ...
| inr hb => ...

kctron sub (Mar 01 2022 at 01:12):

so what am i writing (im using lean 4)

kctron sub (Mar 01 2022 at 01:12):

image.png

Mario Carneiro (Mar 01 2022 at 01:14):

If that code isn't giving you errors, then that's lean 3 code not lean 4

kctron sub (Mar 01 2022 at 01:14):

i have the sorry in there so its not complete

Notification Bot (Mar 01 2022 at 01:16):

This topic was moved here from #lean4 > help by Mario Carneiro.

kctron sub (Mar 01 2022 at 01:17):

oh yeah thanks

Mario Carneiro (Mar 01 2022 at 01:18):

If you want to do it using term mode, then it would be or.elim h4 (assume ha : A y, ...) (assume hb : B y, ...)

kctron sub (Mar 01 2022 at 01:19):

whats the ellipsis

Mario Carneiro (Mar 01 2022 at 01:19):

you can put _ there and lean will tell you what remains to fill in, or sorry like you've been doing

Mario Carneiro (Mar 01 2022 at 01:19):

this is not the complete proof

Mario Carneiro (Mar 01 2022 at 01:20):

but you can use it to replace your sorry and make some progress

kctron sub (Mar 01 2022 at 01:21):

what is supposed to go there though if im just using or.elim

Mario Carneiro (Mar 01 2022 at 01:22):

Also you should post code as text not images

Mario Carneiro (Mar 01 2022 at 01:22):

if you replace sorry with or.elim h4 (assume ha : A y, sorry) (assume hb : B y, sorry) it should still work modulo sorry

kctron sub (Mar 01 2022 at 01:23):

yeah but what am i supposed to put instead of sorry whenever im done with the proof

kctron sub (Mar 01 2022 at 01:24):

what does or.elim do is what im asking

Mario Carneiro (Mar 01 2022 at 01:24):

well, if you put _ there instead of sorry, what is the goal state? Do you see how to deduce the goal from there?

Mario Carneiro (Mar 01 2022 at 01:25):

When you are done with the proof, there will still be or.elim in the proof

kctron sub (Mar 01 2022 at 01:25):

and do i need to have two assume or cant i just use A y

Mario Carneiro (Mar 01 2022 at 01:25):

you need two assume, it is a case analysis and there are two cases so you have to handle both

Mario Carneiro (Mar 01 2022 at 01:26):

that whole line that I wrote should go in the proof

Mario Carneiro (Mar 01 2022 at 01:27):

What this proof is saying is: "We know A y \/ B y, so either A y or B y is true. Suppose that A y is true. Then ... . So C y is true. Otherwise, B y is true. Then ... , thus C y is true. Hence C y is true in either case."

Mario Carneiro (Mar 01 2022 at 01:28):

the ... in this proof correspond to the two sorry

kctron sub (Mar 01 2022 at 01:28):

and what i put in the sorry spot is how im proving C y in both cases

kctron sub (Mar 01 2022 at 01:28):

??

kctron sub (Mar 01 2022 at 01:29):

i tried this but both shows are underlined in red

kctron sub (Mar 01 2022 at 01:29):

section
variable U : Type
variables A B C : U → Prop

variable h1 : ∀x, A x ∨ B x
variable h2 : ∀x, A x → C x
variable h3 : ∀x, B x → C x

example : ∀x, C x :=
assume y,
have h4 : A y ∨ B y, from h1 y,
have h5 : A y → C y, from h2 y,
have h6 : B y → C y, from h3 y,
or.elim h4 (assume ha : A y, show C y, from or.inl h4)
(assume hb : B y, show C y, from or.inr h4)
end

Thomas Browning (Mar 01 2022 at 01:30):

#backticks

Mario Carneiro (Mar 01 2022 at 01:30):

^ that's a link btw

kctron sub (Mar 01 2022 at 01:30):

section
  variable U : Type
  variables A B C : U  Prop

  variable h1 : x, A x  B x
  variable h2 : x, A x  C x
  variable h3 : x, B x  C x

  example : x, C x :=
  assume y,
  have h4 : A y  B y, from h1 y,
  have h5 : A y  C y, from h2 y,
  have h6 : B y  C y, from h3 y,
  or.elim h4 (assume ha : A y, show C y, from or.inl h4)
  (assume hb : B y, show C y, from or.inr h4)
end

kctron sub (Mar 01 2022 at 01:31):

there you go is it easier for you to read now

Mario Carneiro (Mar 01 2022 at 01:31):

If you use

or.elim h4 (assume ha : A y, show C y, from _)
(assume hb : B y, show C y, from _)

then the errors on the show go away, so the issue is not the show but the proof you put in for them

Mario Carneiro (Mar 01 2022 at 01:32):

you correctly said that you wanted to show C y there, but the proof is not showing that

kctron sub (Mar 01 2022 at 01:32):

section
  variable U : Type
  variables A B C : U  Prop

  variable h1 : x, A x  B x
  variable h2 : x, A x  C x
  variable h3 : x, B x  C x

  example : x, C x :=
  assume y,
  have h4 : A y  B y, from h1 y,
  have h5 : A y  C y, from h2 y,
  have h6 : B y  C y, from h3 y,
  or.elim h4 (assume ha : A y, show C y, from h5 ha)
  (assume hb : B y, show C y, from h6 hb)
end

Mario Carneiro (Mar 01 2022 at 01:32):

the error message says as much too

type mismatch at application
  (λ (this : C y), this) (or.inl h4)
term
  or.inl h4
has type
  (A y  B y)  ?m_1
but is expected to have type
  C y

It says that or.inl h4 is proving (A y ∨ B y) ∨ something which is not C y

kctron sub (Mar 01 2022 at 01:32):

no errors

kctron sub (Mar 01 2022 at 01:33):

im sorry but i think this damn theorem prover is so annoying but thanks for your help

Mario Carneiro (Mar 01 2022 at 01:33):

what is your background? What got you interested?

kctron sub (Mar 01 2022 at 01:34):

we have to learn it for school

Mario Carneiro (Mar 01 2022 at 01:35):

what level are you at? Math or CS oriented?

kctron sub (Mar 01 2022 at 01:35):

i am doing comp sci B.S.

kctron sub (Mar 01 2022 at 01:35):

still only on year 2.5

kctron sub (Mar 01 2022 at 01:37):

wanna do another one

Mario Carneiro (Mar 01 2022 at 01:37):

I will stick with my earlier suggestion of #tpil then. Once you have the idea of using types for doing logic then it won't be so bad. It helps if you have or get some functional programming experience too

Mario Carneiro (Mar 01 2022 at 01:38):

and it's actually pretty game-like once you get into it

Mario Carneiro (Mar 01 2022 at 01:41):

by the way, another fun thing you can do with completed problems is find ways to write them shorter (aka "proof golf"). Here's a short version of your proof:

example : x, C x := λ y, (h1 y).elim (h2 y) (h3 y)

kctron sub (Mar 01 2022 at 03:07):

section
  variable A : Type
  variable f : A  A
  variable P : A  Prop
  variable  h : x, P x  P (f x)

  example : y, P y  P (f (f y)) :=
  assume y,
  assume f,
  sorry
end

kctron sub (Mar 01 2022 at 03:07):

where to go from here

Mario Carneiro (Mar 01 2022 at 03:30):

Hint: h (f y) is a proof of P (f y) -> P (f (f y))

chensc (Mar 04 2022 at 16:54):

Is there any walking-through videos for the tutorial?

Kevin Buzzard (Mar 04 2022 at 16:56):

I don't think so, but there is a 24/7 helpline if you're stuck on something (i.e., here)

chensc (Mar 04 2022 at 17:16):

So I have just started to dive into the tutorial, and got confused, maybe because lack of knowledge in type thorey . There is the following definition:
def is_max (a : ℝ) (A : set ℝ) := a ∈ A ∧ a ∈ up_bounds A

and above it, explanation "/-- Predicate is_max a A means a is a maximum of A -/"

So basically, in Lean, a logical predicate has a type? we can define predicates?
Maybe there is some more detailed explanation which is supposed to be a prerequisite for the tutorial?

and another question: maybe I'm just used to first order set-theoretic logic, but are there any syntax-semantics distinctions in LEAN? I mean, sure Lean deduction system is supposed to be sound, but is it supposed to be complete, in the sense of Godel's Completeness?

Kevin Buzzard (Mar 04 2022 at 17:23):

a ∈ A ∧ a ∈ up_bounds A is an example of a type in Lean. And a proof of that assertion is a term of that type. Maybe you want to read my witterings on the matter.

Kevin Buzzard (Mar 04 2022 at 17:24):

Lean is just supposed to be maths, so within Lean, just like within maths, there are things which are true but not provable and things which are undecidable.

chensc (Mar 04 2022 at 17:36):

But is there a way to prove that Lean is complete as a deduction system? That every true sentence (true in any model) is provable?

Kevin Buzzard (Mar 04 2022 at 18:33):

you can't prove these things within Lean, you'd have to be reasoning outside the system to do that, and IANAL(ogician).

Jakub Kądziołka (Mar 05 2022 at 04:35):

the standard foundations are split into two layers, first order logic and ZFC as a theory in this logic. In Lean, the roles of both of these are fulfilled by the same layer, so I don't see any good way to state something similar to Godel's completeness. I also ANAL though

Kevin Buzzard (Mar 05 2022 at 07:48):

Well all I know is that they proved independence of CH in Lean so some people around here will be able to answer your questions...


Last updated: Dec 20 2023 at 11:08 UTC