Skip to content

Commit

Permalink
prove nat is a set with hedberg
Browse files Browse the repository at this point in the history
  • Loading branch information
ecavallo committed Aug 17, 2018
1 parent f506dff commit f11441c
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion nat.red
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path

import void
import unit
import hedberg

data nat where
| zero
Expand Down Expand Up @@ -50,3 +52,50 @@ let plus/comm (m : nat) : (n : nat) → Path nat (plus n m) (plus m n) =
| suc (m ⇒ plus/comm/m) ⇒ λ n → trans _ (plus/suc/r n m) (λ i → suc (plus/comm/m n i))
]

let NatPathCode (m : nat) : nat → type =
elim m [
| zero ⇒ λ n →
elim n [
| zero ⇒ unit
| suc _ ⇒ void
]
| suc (m' ⇒ Code/m') ⇒ λ n →
elim n [
| zero ⇒ void
| suc n' ⇒ Code/m' n'
]
]

let nat-refl (m : nat) : NatPathCode m m =
elim m [
| zero ⇒ triv
| suc (m' ⇒ nat-refl/m') ⇒ nat-refl/m'
]

let nat-path/encode (m : nat) (n : nat) (p : Path nat m n)
: NatPathCode m n
=
coe 0 1 (nat-refl m) in λ i → NatPathCode m (p i)

let nat/discrete : discrete nat =
λ m →
elim m [
| zero ⇒ λ n →
elim n [
| zero ⇒ <tt, λ _ zero>
| suc n' ⇒ <ff, nat-path/encode zero (suc n')>
]
| suc (m' nat/discrete/m') ⇒ λ n →
elim n [
| zero ⇒ <ff, nat-path/encode (suc m') zero>
| suc n' ⇒
or/elim (Path nat m' n') (neg (Path nat m' n'))
(or (Path nat (suc m') (suc n')) (neg (Path nat (suc m') (suc n'))))
(nat/discrete/m' n')
(λ l → <tt, λ i suc (l i)>)
(λ r → <ff, λ p r i nat-pred (p i))>)
]
]

let nat/set : IsSet nat =
discrete/to/set nat nat/discrete

1 comment on commit f11441c

@jonsterling
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So cool! Nice job

Please sign in to comment.