Zulip Chat Archive
Stream: new members
Topic: (type theory) - feedback on first exercise using definitions
rzeta0 (Nov 07 2025 at 02:38):
To get a better insight into how proof assistants like Lean work, I've been working through Nederpelt's Type Theory & Formal proof, doing all the exercises. I'm now on Chapter 8 which introduces definitions.
The very first exercise at the end of the chapter is supposed to be easy, but the introduction to definitions was a little rapid so I'm unsure if the ideas really settled.
I'd welcome your feedback on my solution below.
I've intentionally been verbose with my thinking to expose any flaws in my understanding.
Exercise 8.1
In Section 8.7, we gave the name to a proof of the proposition
in the context .
Assume that we have constructed, in context , a proof (i.e. an inhabitant) of the proposition
Find an inhabitant of
in context .
My Solution
We start with which is the name given to the proof of the proposition
The name also carries with it the ordered list of arguments . The first two arguments are the positive natural numbers and expected by the proof. The third argument is a proof that the first two arguments, and (in that order), are co-prime.
That is
Note that we don't need to know the details of , we can assume it exists, and refer to it by its name .
We want to prove the proposition
The order of and is different to (i), and this means is not a proof of (ii). Is this correct?
We are given a proof of the proposition , that is
So the proof applied to , the proof , gives us a proof .
We also need to check that the context of allows it to be used in the context in which we apply it to , that is, . The context of us a subset of so can be used, and it can be used with because is defined in . Is this right?
If we are to use as a proof of , the order of the variables and require the proof to be of the form and not . The a proof that and (in that order) are co-prime. We have that from above.
And so is a proof of the proposition (ii). That is
And we can choose to give this proof a name , but that is optional.
Variable Order and Renaming
Assuming the above is ok, one question I am not happy about is why we can't just ignore the order of variables and and just use the fact that they have the correct type to be the first and second arguments of . That is,
Aaron Liu (Nov 07 2025 at 03:07):
you can try your idea out in Lean and see what happens
import Mathlib
-- we give this proof a name
theorem p (m n : ℕ+) (u : Nat.Coprime m n) : ∃ x y : ℤ, m * x + n * y = 1 :=
-- don't worry about the contents of the proof
⟨Nat.gcdA m n, Nat.gcdB m n,
(Nat.gcd_eq_gcd_ab m n).symm.trans (congrArg Nat.cast (Nat.Coprime.gcd_eq_one u))⟩
-- we also give this other proof a name
theorem q (m n : ℕ+) : Nat.Coprime m n → Nat.Coprime n m :=
-- don't worry about the contents
Nat.Coprime.symm
-- in this context, inhabit this type
example (m n : ℕ+) (u : Nat.Coprime m n) : ∃ x y : ℤ, n * x + m * y = 1 :=
sorry
Aaron Liu (Nov 07 2025 at 03:12):
rzeta0 said:
Variable Order and Renaming
Assuming the above is ok, one question I am not happy about is why we can't just ignore the order of variables and and just use the fact that they have the correct type to be the first and second arguments of . That is,
I am confused, what do you mean "by variable rewriting"? You can't just identify all the variables that have the same type.
rzeta0 (Nov 07 2025 at 03:26):
At school, in pen and paper maths (no lean, no type theory), if I were asked to prove the statement
using a given proof of
I would say is sufficient, and is a proof of (1) because only the names of the variables have changed.
I think this is where my question comes from.
Thanks for the code. I tried it.
I tried p m n u and it gave the following which challenges my intuition about "renaming"
Type mismatch
p m n u
has type
∃ x y, ↑↑m * x + ↑↑n * y = 1
but is expected to have type
∃ x y, ↑↑n * x + ↑↑m * y = 1
the correct answer is of course
example (m n : ℕ+) (u : Nat.Coprime m n) : ∃ x y : ℤ, n * x + m * y = 1 :=
p n m (q m n u)
Aaron Liu (Nov 07 2025 at 03:31):
but it's not just
Aaron Liu (Nov 07 2025 at 03:31):
the takes three arguments
Aaron Liu (Nov 07 2025 at 03:35):
do you mean renaming like this?
import Mathlib
-- we give this proof a name
theorem p (m n : ℕ+) (u : Nat.Coprime m n) : ∃ x y : ℤ, m * x + n * y = 1 :=
-- don't worry about the contents of the proof
⟨Nat.gcdA m n, Nat.gcdB m n,
(Nat.gcd_eq_gcd_ab m n).symm.trans (congrArg Nat.cast (Nat.Coprime.gcd_eq_one u))⟩
-- we also give this other proof a name
theorem q (m n : ℕ+) : Nat.Coprime m n → Nat.Coprime n m :=
-- don't worry about the contents
Nat.Coprime.symm
-- in this context, inhabit this type
example (m n : ℕ+) (u : Nat.Coprime m n) : ∃ x y : ℤ, n * x + m * y = 1 := by
-- we have p(m,n,u)
have pmnu := p m n u
-- swap some names around
rename' m => n, n => m
-- so now the goal is `∃ x y : ℤ, m * x + n * y = 1`
-- but of course renaming didn't just affect the goal
-- we've also renamed occurrences of `m` and `n` in the types of `u` and `pmnu`
-- so it didn't really help (it's just kind of shuffling names around)
sorry
rzeta0 (Nov 07 2025 at 12:43):
Aaron Liu said:
but it's not just
I did mean with two arguments. I was trying to simplify the scenario to see if I could explain my thinking about variable renaming.
Let me think of a different school exercise example.
Imagine there is a proof (a theorem) that the product of two odd numbers is odd. That is is odd. Let's call this proof . It takes two arguments and .
Now imagine we're asked to prove that for two odd numbers and , the product is odd. Then I can use with .
So I don't understand why we need to develop a new proof that uses the idea of commutativity of products, when we have .
Apologies if I'm being stupid. Doing for "formal" maths has exposed things that I have only weakly understood previously.
Vlad Tsyrklevich (Nov 07 2025 at 15:25):
Your idea works when is a proof of universally quantified statement over that are both of the same type. The reason it doesn't work in your original example is that it's not a a priori clear that . Of course we know that coprime is a symmetric relation on two numbers, but in formal math you have to actually prove that. Indeed, in the exercise they tell you that coprime is symmetric and that you can use that fact. You can't just "re-write variables" though, if takes two numbers and a proof that and returns a proof that then you cannot just rewrite it to --the relation is no longer symmetric and the statement is false.
rzeta0 (Nov 07 2025 at 17:31):
Thanks Aaron and Vlad, you have both given me something to think about.
Your example of not being symmetric is helpful.
Again I apologise for the lack of precision in my question.
I think doing the rest of the exercises will help this issue resolve itself in my brain.
Vlad Tsyrklevich (Nov 08 2025 at 07:55):
No need for apology, on the contrary I think you stated your context and idea with enough precision to make it immediately clear what the counterexample is.
Last updated: Dec 20 2025 at 21:32 UTC