Zulip Chat Archive
Stream: general
Topic: can you help me make it clear
Truong Nguyen (Sep 10 2018 at 14:41):
I read the book about lean prover. There is some code like this:
def nat.dvd (m n: ℕ ): Prop := ∃ k, n = m * k instance : has_dvd nat := ⟨nat.dvd ⟩ theorem nat.dvd_refl (n: ℕ ) : n ∣ n := ⟨1, by simp ⟩
I don't know why this theorem can be proved by <1, simp>. What does number 1 mean?
Thank you for making it clear,
Johan Commelin (Sep 10 2018 at 14:42):
You see the k
on the first line?
Johan Commelin (Sep 10 2018 at 14:42):
To prove n | n
, you have to provide a k
. And this proof provides 1
.
Johan Commelin (Sep 10 2018 at 14:43):
Afterwards, you have to prove n = m * k
. And in your theorem m
is n
, and you just provided k
is 1
.
Johan Commelin (Sep 10 2018 at 14:43):
The proof is then by simp
.
Truong Nguyen (Sep 10 2018 at 14:44):
Ok, thanks. I see it is trivial now.
Truong Nguyen (Sep 10 2018 at 14:46):
By the way, is there any other way. I mean how can we write the code clearer.
Johan Commelin (Sep 10 2018 at 14:46):
Yes. This is called tactic mode.
Johan Commelin (Sep 10 2018 at 14:47):
def nat.dvd (m n: ℕ ): Prop := ∃ k, n = m * k instance : has_dvd nat := ⟨nat.dvd ⟩ theorem nat.dvd_refl (n: ℕ ) : n ∣ n := begin existsi 1, simp end
Truong Nguyen (Sep 10 2018 at 14:49):
Oh, ok. How can we unfold the definition of "|", to make it appear like:
\exists k, n = m * k
Truong Nguyen (Sep 10 2018 at 14:52):
I mean, to make it look like this:
example (n: ℕ ): ∃ k, n = n * k := _
Reid Barton (Sep 10 2018 at 14:53):
Do you mean you want to change what the goal looks like, inside the tactic block?
Truong Nguyen (Sep 10 2018 at 14:53):
Oh, yes
Reid Barton (Sep 10 2018 at 14:54):
Two ways. One is that you can use change
to change the goal to something definitionally equivalent, like
change ∃ k, n = n * k,
Of course, that depends on knowing what the unfolded form should be
Truong Nguyen (Sep 10 2018 at 14:56):
WHat is the second way
Reid Barton (Sep 10 2018 at 14:56):
The other way is to use unfold
or dsimp
or related tactics to unfold the ∣
operation, but because it is notation in this case, you need to know the actual name of the operator, which is has_dvd.dvd
Reid Barton (Sep 10 2018 at 14:58):
Then has_dvd
is a class, so you also need to unfold the actual instance for nat
. If you start with
unfold has_dvd.dvd,
then you'll see what the actual operation is in the goal window -- it's nat.dvd
Truong Nguyen (Sep 10 2018 at 14:58):
I tried this:
theorem nat.dvd_refl (n: ℕ ) : n ∣ n := begin unfold nat.dvd, end
But, I got error
Reid Barton (Sep 10 2018 at 14:58):
So then you can unfold both at once with
unfold has_dvd.dvd nat.dvd,
Reid Barton (Sep 10 2018 at 14:59):
Yep, because you have to unfold has_dvd.dvd
first.
If you write set_option pp.notation false
before your theorem, you can see what the notation really represents.
Truong Nguyen (Sep 10 2018 at 15:00):
Oh, I made it works now.
It run fine
theorem nat.dvd_refl (n: ℕ ) : n ∣ n := begin unfold has_dvd.dvd nat.dvd, end
Mario Carneiro (Sep 10 2018 at 15:32):
you can write dsimp [(∣)]
too
Last updated: Dec 20 2023 at 11:08 UTC