foundations.Nat.md.

Version of Sunday, January 22, 2023, 10:42 PM

Powered by agda version 2.6.2.2-442c76b and pandoc 2.14.0.3


Investigations on graph-theoretical constructions in Homotopy type theory

Jonathan Prieto-Cubides j.w.w. Håkon Robbestad Gylterud

Department of Informatics

University of Bergen, Norway

{-# OPTIONS --without-K --exact-split #-}

open import foundations.BasicTypes using (Level)

module foundations.Nat ( : Level)
  where
  open import foundations.Core
  open import foundations.NaturalsType
Ordering
  module dec-< where
    open ℕ-ordering 
    _?<_ : (Decidable {A = }{B = } _<_)
    zero ?< zero     = no  z  z)
    zero ?< succ b   = yes 
    succ a ?< zero   = no  z  z)
    succ a ?< succ b = a ?< b

  open ℕ-ordering  public
  <-succ
    : (k : )
     k < succ k

  <-succ zero     = unit
  <-succ (succ k) = <-succ k

  <-inj
    :  {n m : }
     (succ m < n)
     m < n
  <-inj {zero} {zero} p = p
  <-inj {zero} {succ m} p = p
  <-inj {succ n} {zero} p = 
  <-inj {succ n} {succ m} p = <-inj {n}{m} p
  positive-is-suc-of
    :  (n : )
     n > 0
     ∑[ k   ] (succ k  n)
  positive-is-suc-of zero ()
  positive-is-suc-of (succ k)  = k , idp
  mono-succ
    :  {n m : }
     n < m
     succ n < succ m
  mono-succ {n}{m} x = x
  succ-<-remove
    :  {n m}
     succ n < succ m
     n < m
  succ-<-remove {0} {succ m}  = 
  succ-<-remove {succ n} {succ m} p
   = mono-succ {n}{m} (succ-<-remove {n}{m} p)
  <-trans
    :  {x y z : }
     x < y  y < z
     x < z
  <-trans {zero} {succ y} {succ z} x<y y<z = 
  <-trans {succ x} {succ y} {succ z} x<y y<z
    = mono-succ {x}{z} (<-trans {x}{y}{z} (succ-<-remove {x}{y} x<y) (succ-<-remove {y}{z} y<z))
  +>0
    :  {x y : }
     0 < x
     0 < (x +ₙ y)
  +>0 {succ x} {zero} 0<x = 
  +>0 {succ x} {succ y} 0<x = 
  n⁺<k→n<k
    :  {n k : }
     succ n < k
     n < k
  n⁺<k→n<k {zero} {zero} m = m
  n⁺<k→n<k {zero} {succ k} m = 
  n⁺<k→n<k {succ n} {zero} ()
  n⁺<k→n<k {succ n} {succ k} m = n⁺<k→n<k {n}{k} m
  <-prop
    : {n m : }
     (p1 p2 : m < n)
     p1  p2
  <-prop {zero} {zero} () p2
  <-prop {zero} {succ m} () p2
  <-prop {succ n} {zero} unit unit = idp
  <-prop {succ n} {succ m} p1 p2 = <-prop {n}{m} p1 p2
  n=m-is-prop
    : {n m : }
     isProp (n  m)
  n=m-is-prop {n}{m} p q = nat-is-set n m p q
  n=m-is-set
    : {n m : }
     isSet (n  m)
  n=m-is-set = prop-is-set n=m-is-prop
  pre :   
  pre zero     = zero
  pre (succ n) = n
  <and=→⊥
    :  {m : }
     zero < m
     (zero  m)
      
  <and=→⊥ {zero} ()
  <and=→⊥ {succ m} x ()
  succ-n>0
    : {n : }
     0 < succ n
  succ-n>0 {0}     = unit
  succ-n>0 {succ n} = unit
  n<0
    :  {}  {n : }
     (n < 0)   
  n<0 { = } {zero} ()
  n<0 { = } {succ n} ()
  n≠0
    :  {n : }
     ¬ (n  0)
     0 < n
  n≠0 {zero} p = ⊥-elim (p idp)
  n≠0 {succ n} p = unit
  trichotomy
    : (x y : )
     ((x  y) + (x < y)) + (y < x)
  trichotomy zero zero = inl (inl idp)
  trichotomy zero (succ y) = inl (inr unit)
  trichotomy (succ x) zero = inr unit
  trichotomy (succ x) (succ y) with trichotomy x y
  ... | inl (inl p) = inl (inl (ap succ p))
  ... | inl (inr p) = inl (inr (mono-succ {x}{y} p))
  ... | inr p = inr $ mono-succ {y}{x} p
  n<n→⊥
    :  {n : }
     ¬ (n < n)
  n<n→⊥ {succ n} p = n<n→⊥ {n} (succ-<-remove {n}{n} p)
  k<1→k≡0
    :  {k : }
     k < 1
     k  0
  k<1→k≡0 {0} p = idp
  k<1→k≡0 {succ 0} p = ⊥-elim $ n<n→⊥ {n = 1} p
  k<1→k≡0 {succ (succ k)} p = ⊥-elim (n<0 {lzero} {n = 0} (succ-<-remove {n = succ k}{m = 0} p))
  <s-to-<=
    :  p q  p < succ q
     (p  q) + (p < q)
  <s-to-<= zero zero  = inl idp
  <s-to-<= zero (succ q)  = inr 
  <s-to-<= (succ p) zero p<q+ = inl (k<1→k≡0 p<q+)
  <s-to-<= (succ p) (succ q) p<q+
    with <s-to-<= p q (succ-<-remove {n = p} p<q+)
  ... | inl idp = inl idp
  ... | inr x = inr x
  <-=-→⊥
    :  {k n : }
     k < n
     k  n
      
  <-=-→⊥ {0} {.0} () idp
  <-=-→⊥ {succ k} {.(succ k)} p idp = <-=-→⊥ {k = k}{n = k} p idp

  module NatDecidable where
    nat-succ-inj
      :  {n m : }
       succ n  succ m
       n  m
    nat-succ-inj {zero} {zero} = λ _  idp
    nat-succ-inj {0} {succ m} ()
    nat-succ-inj {succ n} {zero} ()
    nat-succ-inj {succ n} {succ .n} idp = idp
    _≟nat_ : Decidable {A = } _≡_
    zero ≟nat zero = yes idp
    zero ≟nat succ b = no  ())
    succ a ≟nat zero = no  ())
    succ a ≟nat succ b with a ≟nat b
    (succ a ≟nat succ b) | yes p = yes (ap succ p)
    (succ a ≟nat succ b) | no ¬p = no λ r  (¬p (nat-succ-inj r))
  open NatDecidable public
  <-suc-suc<
    :  {}{n k : }
     n < k
     ((k  succ n)   )
     succ n < k
  <-suc-suc<  { = } {zero} {succ zero}  ¬p = ⊥-elim (¬p idp)
  <-suc-suc<  { = }{zero} {succ (succ k)}  ¬p = 
  <-suc-suc< { = } {succ n} {succ k} n<k ¬p = <-suc-suc< {}{n}{k} n<k λ q  ¬p (ap succ q)
  k≠0-k>0
      :  {}{k : }
        ((k  0)   )
       0 < k
  k≠0-k>0 { = }{zero} ¬p = ⊥-elim (¬p idp)
  k≠0-k>0 { = } {succ p} ¬p = 
  the-obvious
    : {n : }
     succ n  n   
  the-obvious {0} ()
  the-obvious {succ n} ()
  n⁺⁺≠n
    : {n : }
     succ (succ n)  n   
  n⁺⁺≠n {0} ()
  n⁺⁺≠n {succ n} ()
  n+1≡n⁺
    : {n : }
     n +ₙ 1  succ n
  n+1≡n⁺ {0} = idp
  n+1≡n⁺ {succ n} = ap succ (n+1≡n⁺{n})
  n+1≡m→m=n⁺
    : {n m : }
     (n +ₙ 1)  m
     m  succ n
  n+1≡m→m=n⁺ {n} {.(plus n 1)} idp = n+1≡n⁺{n}
  n+1+1≡n→⊥
    : {n : }
     ((n +ₙ 1) +ₙ 1  n)   
  n+1+1≡n→⊥ {succ n} q rewrite n+1≡n⁺{n} | ! (n+1≡n⁺ {n}) = n⁺⁺≠n {plus n 1} q
  n+1≡mANDn≡m+1→⊥
    : {n m : }
     (n +ₙ 1  m)
     (n  m +ₙ 1)
      
  n+1≡mANDn≡m+1→⊥ {n} {.(plus n 1)} idp q = n+1+1≡n→⊥ {n} (sym q)
  _≠ℕ_ :  (n m : )  Type 
  n ≠ℕ m = (n  m)   
  <k→<k⁺
    :  {n k : }
     n < k
     n < succ k
  <k→<k⁺ {zero} {succ k} x = 
  <k→<k⁺ {succ n} {succ k} x = <k→<k⁺ {n}{k} x

  ≤-to-<
    : {p q : }
     p  q
     p < succ q
  ≤-to-< {p = p} (inl p<q) = <k→<k⁺ {n = p} p<q
  ≤-to-< {p = p} (inr idp) = <-succ p
  minus : (n k : )  (k < n)  
  minus 0 0 ()
  minus 0 (succ k) ()
  minus (succ n) 0 k< = succ n
  minus (succ n) (succ k) k< = succ (minus n k k<)
  +≡-to-<
    :  {k n : }
     (sol :   (\x  k +ₙ x  n))
     (0 < π₁ sol)  k < n
  +≡-to-< {0} {succ n} (succ x , p)  = 
  +≡-to-< {succ k} {succ n} (succ x , p)  = mono-succ {k}{n} IH
    where
    IH : k < n
    IH = +≡-to-< {k}{n} (succ x , succ-inj p) 
  to-reach>0
    :  {k x n : }
     k < n
     k +ₙ x  n
     0 < x
  to-reach>0 {zero} {succ x} {succ n} k<n k+x≡n = 
  to-reach>0 {succ k} {zero} {succ n} k<n k+x≡n
    = ⊥-elim (<-=-→⊥ k<n (! plus-runit (succ k) · k+x≡n))
  to-reach>0 {succ k} {succ x} {succ n} k<n k+x≡n = 
  find-x-to-<
    :  {k n : }
     k < n
       (\x  (k +ₙ x  n) × (0 < x))
  find-x-to-< {0} {succ n}  = succ n , (idp , )
  find-x-to-< {succ k} {succ n} k<
    with find-x-to-< {k = k}{n = succ n} (<-inj {n = succ n}{m = k} k<)
  ... | 0 , p , 0<sol    rewrite plus-runit k
      = ⊥-elim (<-=-→⊥ (<k→<k⁺ {n = k} k<)  p)
  ... | succ x , p , 0<sol rewrite ! p | plus-comm k (succ x)
      = x , (ap succ (plus-comm k x) , to-reach>0 {k}{x}{n}  k< (succ-inj (ap succ (plus-comm k x) · p)))
  unique-solution-find-x-to-<
    :  {k n : }
     k < n
     (x : )  (k +ₙ x  n)
     (x' : )  (k +ₙ x'  n)
     x  x'
  unique-solution-find-x-to-< {k = k} k< x p1 x' p2 = +-inj k (p1 · ! p2)
  {-
  _^-ℕ_ : ℕ → ℕ → ℕ
  0 ^-ℕ 0      = 1
  succ a ^-ℕ 0 = 1
  zero ^-ℕ succ b = 0
  succ a ^-ℕ succ b = {!!}
  -}

Latest changes

(2022-12-28)(57c278b4) Last updated: 2021-09-16 15:00:00 by jonathan.cubides
(2022-07-06)(d3a4a8cf) minors by jonathan.cubides
(2022-01-26)(4aef326b) [ reports ] added some revisions by jonathan.cubides
(2021-12-20)(049db6a8) Added code of cubical experiments. by jonathan.cubides
(2021-12-20)(961730c9) [ html ] regular update by jonathan.cubides
(2021-12-20)(e0ef9faa) Fixed compilation and format, remove hidden parts by jonathan.cubides
(2021-12-20)(5120e5d1) Added cubical experiment to the master by jonathan.cubides
(2021-12-17)(828fdd0a) More revisions added for CPP by jonathan.cubides
(2021-12-15)(0d6a99d8) Fixed some broken links and descriptions by jonathan.cubides
(2021-12-15)(662a1f2d) [ .gitignore ] add by jonathan.cubides
(2021-12-15)(0630ce66) Minor fixes by jonathan.cubides
(2021-12-13)(04f10eba) Fixed a lot of details by jonathan.cubides
(2021-12-10)(24195c9f) [ .gitignore ] ignore .zip and arxiv related files by jonathan.cubides
(2021-12-09)(538d2859) minor fixes before dinner by jonathan.cubides
(2021-12-09)(36a1a69f) [ planar.pdf ] w.i.p revisions to share on arxiv first by jonathan.cubides