CW.examples.Nat
(*** Natural numbers as CW types ***)
From Coq Require Import Utf8 Lia.
From Equations Require Import Equations.
From CW Require Import CW.
Set Equations Transparent.
Section Nat.
From Coq Require Import Utf8 Lia.
From Equations Require Import Equations.
From CW Require Import CW.
Set Equations Transparent.
Section Nat.
No index
Two constructors
No non-recursive arguments
Only one recursive argument for the second constructor
Return index is trivial
Now we are ready to define Nat!
We also define the constructor zer:
And the constructor suc:
Finally we define the eliminator.
Equations Nat_rect_gen (P : ∀ u, PreNat u → Type)
(hz : P tt zer)
(hs : ∀ n, P tt n → P tt (suc n))
u (n : PreNat u) : P u n :=
Nat_rect_gen P hz hs ?(tt) (con true tt (args_nil CW.I)) := hz ;
Nat_rect_gen P hz hs ?(tt) (con false tt (args_oind CW.I n (args_nil CW.I))) :=
hs n (Nat_rect_gen P hz hs tt n).
Definition Nat_rect (P : Nat → Type)
(hz : P zer)
(hs : ∀ n, P n → P (suc n))
(n : Nat) : P n :=
Nat_rect_gen (λ u, match u with tt ⇒ P end) hz hs tt n.
(hz : P tt zer)
(hs : ∀ n, P tt n → P tt (suc n))
u (n : PreNat u) : P u n :=
Nat_rect_gen P hz hs ?(tt) (con true tt (args_nil CW.I)) := hz ;
Nat_rect_gen P hz hs ?(tt) (con false tt (args_oind CW.I n (args_nil CW.I))) :=
hs n (Nat_rect_gen P hz hs tt n).
Definition Nat_rect (P : Nat → Type)
(hz : P zer)
(hs : ∀ n, P n → P (suc n))
(n : Nat) : P n :=
Nat_rect_gen (λ u, match u with tt ⇒ P end) hz hs tt n.
We verify that the computation rules are indeed verified.