I'm used to writing human proofs in mathematics, but I'm very new to writing Agda. The following is a toy example of something that I can't figure out how to prove with Agda.
Informally, I want to write a function f which takes a natural number x and a pair of naturals. If the first element in the pair equals x, return the second element of the pair. Otherwise, return 0.
Here are my definitions for natural number equality:
data N : Set where
zero : N
s : N → N
data _≡_ {X : Set} : X → X → Set where
refl : (x : X) → (x ≡ x)
data _≢_ : N → N → Set where
< : {n : N} → (zero ≢ (s n))
> : {n : N} → ((s n) ≢ zero)
rec : {n m : N} → (n ≢ m) → ((s n) ≢ (s m))
data _=?_ (n m : N) : Set where
true : (n ≡ m) → (n =? m)
false : (n ≢ m) → (n =? m)
equal? : (n m : N) → (n =? m)
equal? zero zero = true (refl zero)
equal? zero (s _) = false <
equal? (s _) zero = false >
equal? (s n) (s m) with (equal? n m)
... | (true (refl a)) = (true (refl (s a)))
... | (false p) = (false (rec p))
and here is the function.
data Npair : Set where
pair : (n m : N) → Npair
f : N → Npair → N
f a (pair b c) with equal? a b
... | (true (refl _)) = c
... | (false _) = zero
I cannot prove
lemma : (x y : N) → (y ≡ (f x (pair x y)))
because when I try to introduce the refl
constructor in the definition, it complains that
y != f x (pair x y) | equal? x x of type N
What do I have to change in order to prove this lemma?