TL;DR: in Agda, given a : A and proof : A == B, can I obtain an element a : B?
In my ongoing attempt to learn Agda, I've created the following Prime : nat -> Set datatype, which is a witness to the primality of a natural.
Prime zero = False
Prime (succ zero) = False
Prime (succ (succ n)) = forall {i : nat} -> divides i p -> i <N p -> zero <N i -> i == (succ zero)
where
p = succ (succ n)
Here:
Falseis a data type with no constructors;divides a bis a data type that contains a witnesskto the fact thata * k = b;a <N bis a data type that contains a witnesskto the fact thata + k = b;==is the equality type, with just one constructorrefl;- the natural numbers are defined in the obvious way with
zero : natandsucc : nat -> nat.
I've successfully exhibited a member of Prime (succ (succ zero)), and proved that the statement Prime (succ (succ (succ (succ zero))))) implies False.
Now I'm trying to prove that primes are greater than one:
primesAreGreaterThanOne : (p : Sg nat Prime) -> (succ zero <N value p)
where
Sg A predis the dependent pair(p, pred(p))wherep : A;value : Sg A pred -> Aextracts the value and discards the proof.
I've already proved trichotomy of the order: for all a, b it is true either that a <N b, or a == b, or b <N a. (This lemma, I hope, should help us avoid any excluded-middle problems.) So by working casewise on the ordering relation between succ zero and value p, I've reduced to the case that I have a proof of p == zero and a proof of Prime p and the statement that Prime zero is defined to be False.
Now, of course, these statements are contradictory: since I have a proof that p == zero, I can exhibit an inhabitant of the type Prime p == Prime zero, and hence I have an inhabitant of Prime p == False.
But how can I take my element proof : Prime p (the proof which is the second component of p : Sg nat Prime) and "cast" it to an element of False? The types are propositionally equal, but not judgementally equal.