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):
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):
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):
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...
edklencl (Oct 16 2024 at 07:10):
import Mathlib.Data.Nat.Notation
example (P : ℕ → Prop)(h:∀ n, P n ↔ ¬(P (n+1)↔P (n+2))):∀ n, P n → P (n+3):=by
intro n pn
specialize h n
edklencl (Oct 16 2024 at 07:16):
help
Timo Carlin-Burns (Oct 16 2024 at 07:19):
(You may be looking for #backticks)
```
your lean code here
```
edklencl (Oct 16 2024 at 09:07):
(deleted)
Daniel Weber (Oct 16 2024 at 09:22):
You need to import Mathlib.Data.Nat.Notation
for the ℕ
notation
BANGJI HU (Oct 16 2024 at 12:49):
Perhaps you could tell me where to find relevant information?
BANGJI HU (Oct 16 2024 at 12:50):
@Daniel Weber
Daniel Weber (Oct 16 2024 at 12:58):
https://leanprover-community.github.io/mathlib4_docs/Mathlib/Data/Nat/Notation.html#term%E2%84%95
BANGJI HU (Oct 16 2024 at 13:06):
import Mathlib.Data.Nat.Notation
import Mathlib.Data.Nat.Notation
theorem problem (P : ℕ → Prop) (h : ∀ n, P n ↔ ¬(P (n+1) ↔ P (n+2))) : ∀ n, P n → P (n+3) := by
intro n hn
have h1 := h n
have h2 := h (n+1)
have h3 := h (n+2)
apply Classical.byContradiction
intro hnot
-- Assume that P(n+1) ↔ P(n+2)
have h4 : P (n+1) ↔ P (n+2) := by
apply Iff.intro
· intro h5
apply Classical.byContradiction
intro h6
have h7 : ¬(P (n+2) ↔ P (n+3)) := h2.mp h5
have h8 : P (n+2) ↔ P (n+3) := by
apply Iff.intro
· intro h9
apply False.elim
exact h6 h9
· intro h9
exact False.elim (hnot h9)
exact h7 h8
· intro h5
apply Classical.byContradiction
intro h6
have h7 : ¬(P (n+1) ↔ P (n+2)) := h1.mp hn
have h8 : P (n+1) ↔ P (n+2) := by
apply Iff.intro
· intro _
exact h5
· intro _
apply False.elim
exact h6
exact h7 h8
-- Now we need to show ¬(P(n+1) ↔ P(n+2)) holds
have h5 : ¬(P (n+1) ↔ P (n+2)) := h1.mp hn
exact h5 h4
BANGJI HU (Oct 16 2024 at 13:18):
type mismatch
h6
has type
¬P (n + 1) : Prop
but is expected to have type
False : Prop
BANGJI HU (Oct 16 2024 at 13:18):
@Daniel Weber
BANGJI HU (Oct 16 2024 at 13:27):
import Mathlib.Data.Nat.Notation
import Mathlib.Data.Nat.Notation
theorem problem (P : ℕ → Prop) (h : ∀ n, P n ↔ ¬(P (n+1) ↔ P (n+2))) : ∀ n, P n → P (n+3) := by
intro n hn
have h1 := h n
have h2 := h (n+1)
have h3 := h (n+2)
apply Classical.byContradiction
intro hnot
-- Assume that P(n+1) ↔ P(n+2)
have h4 : P (n+1) ↔ P (n+2) := by
apply Iff.intro
· intro h5
apply Classical.byContradiction
intro h6
have h7 : ¬(P (n+2) ↔ P (n+3)) := h2.mp h5
have h8 : P (n+2) ↔ P (n+3) := by
apply Iff.intro
· intro h9
apply False.elim
exact h6 h9
· intro h9
exact False.elim (hnot h9)
exact h7 h8
· intro h5
apply Classical.byContradiction
intro h6
have h7 : ¬(P (n+1) ↔ P (n+2)) := h1.mp hn
have h8 : P (n+1) ↔ P (n+2) := by
apply Iff.intro
· intro _
exact h5
· intro _
apply False.elim
exact h6
exact h7 h8
-- Now we need to show ¬(P(n+1) ↔ P(n+2)) holds
have h5 : ¬(P (n+1) ↔ P (n+2)) := h1.mp hn
exact h5 h4
BANGJI HU (Oct 16 2024 at 13:27):
type mismatch
h6
has type
¬P (n + 1) : Prop
but is expected to have type
False : Prop
BANGJI HU (Oct 16 2024 at 14:14):
@Johan Commelin
Johan Commelin (Oct 16 2024 at 14:31):
@hand bob Please ask a proper question.
edklencl (Oct 16 2024 at 14:46):
seem to be some issue at exact h6
Kevin Buzzard (Oct 16 2024 at 14:49):
Perhaps you could tell me where to find relevant information?
Where did this question come from? Did it also come with links to relevant information?
Kevin Buzzard (Oct 16 2024 at 14:49):
The error is pretty self-explanatory, right? You've given a proof of the wrong theorem.
edklencl (Oct 16 2024 at 14:50):
@Johan Commelin
Yaël Dillies (Oct 16 2024 at 14:53):
Please don't mention people for no reason. Also please don't use several Zulip accounts.
Andrew Yang (Oct 16 2024 at 14:53):
Also please do not cross-post (c.f. https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/help/near/477210998) this is just splitting up the help you will get.
Yaël Dillies (Oct 16 2024 at 14:54):
Is this again homework from Heather's course?
edklencl (Oct 16 2024 at 15:10):
maybe i just want some proposition
Kevin Buzzard (Oct 16 2024 at 15:12):
Sorry, are you (vvbb) equal to hand bob? Can you please delete one of these accounts? This is adding to the confusion.
Andrew Yang (Oct 16 2024 at 15:16):
If you can ask a proper question such as where did you get this snippet, what have you tried, what help you need (do you understand the maths and just need lean help?) etc, then people would be in a better position to help you.
If you are not a native english speaker then asking in your native language then google translate would work too.
Kevin in the other thread also gave you some preliminary advices (can someone merge these two threads?) but without more context we can only give these vague hints.
Notification Bot (Oct 16 2024 at 15:22):
12 messages were moved here from #mathlib4 > induction by Johan Commelin.
Last updated: May 02 2025 at 03:31 UTC