{-# OPTIONS --without-K #-}

module sets.nat.core where

open import level
  using (lzero)
open import equality.core
  using (_≡_; refl; cong)
open import function.core
  using (_$_; _∘_)
open import decidable
  using (Dec; yes; no)

infixl 7 _*_
infixl 6 _+_

data  : Set where
  zero : 
  suc  :   

{-# BUILTIN NATURAL     #-}
{-# BUILTIN ZERO    zero #-}
{-# BUILTIN SUC     suc  #-}

pred :   
pred zero    = zero
pred (suc n) = n

_+_ :     
zero  + n = n
suc m + n = suc (m + n)

_*_ :     
zero  * n = zero
suc m * n = n + m * n

_≟_ : (a b : )  Dec (a  b)
zero   zero  = yes refl
zero   suc _ = no  ())
suc _  zero  = no  ())
suc a  suc b with a  b
suc a  suc b | yes a≡b = yes $ cong {lzero} {lzero} suc a≡b
suc a  suc b | no ¬a≡b = no $  sa≡sb  ¬a≡b (cong {lzero} {lzero} pred sa≡sb))

data _≤_ :     Set where
  z≤n :  {n}  zero  n
  s≤s :  {m n} (p : m  n)  suc m  suc n

cong-pred-≤ :  {n m}  suc n  suc m  n  m
cong-pred-≤ (s≤s p) = p

refl-≤ : {n : }  n  n
refl-≤ {0} = z≤n
refl-≤ {suc n} = s≤s refl-≤

_≤?_ : (n m : )  Dec (n  m)
0 ≤? n = yes z≤n
suc _ ≤? 0 = no  ())
suc n ≤? suc m with n ≤? m
... | yes p = yes (s≤s p)
... | no f = no (f  cong-pred-≤)