foundations.BasicFunctions.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 #-}
module foundations.BasicFunctions where
open import foundations.BasicTypes public
_·_
  :  { : Level} {A : Type }  {x y z : A}
   (p : x  y)
   (q : y  z)
  --------------
   x  z

_·_ idp q = q

infixl 50 _·_
_⁻¹
  :  { : Level} {A : Type }  {a b : A}
   a  b
  --------
   b  a

idp ⁻¹ = idp
inv = _⁻¹
!_  = inv
infixl 60 _⁻¹ !_
id
  :  { : Level} {A : Type }
  ----------------
   A  A

id = λ x  x

identity = id
id-on
  :  { : Level} (A : Type )
  ---------------
   (A  A)

id-on A = λ x  x
constant-function
  :  {ℓ₁ ℓ₂ : Level} {A : Type ℓ₁}{B : Type ℓ₂}
   (b : B)
  ---------
   (A  B)

constant-function b = λ _  b
¬¬ ¬¬¬
  :  { : Level}
   Type 
   Type 

¬¬ A  = ¬(¬ A)
¬¬¬ A = ¬(¬¬ A)
neg¬
  : Bool
   Bool

neg¬ tt = ff
contrapositive
  :  {ℓ₁ ℓ₂ ℓ₃ : Level}{A : Type ℓ₁}{B : Type ℓ₂}
   (A  B)
   ((B   ℓ₃)  (A   ℓ₃))

contrapositive f v a = v (f a)
_∘_
  :  {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Type ℓ₁} {B : A  Type ℓ₂} {C : (a : A)  (B a  Type ℓ₃)}
   (g : {a : A}   (B a) (C a))
   (f :  A B)
  -------------------------------
    A  a  C a (f a))

g  f = λ x  g (f x)

infixr 80 _∘_

Synonym for composition (diagrammatic version)

_:>_ _︔_
   :  {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Type ℓ₁} {B : A  Type ℓ₂} {C : (a : A)  (B a  Type ℓ₃)}
   (f : Π A B)
   (g : {a : A}  Π (B a) (C a))
  -------------------------------
   Π A  a  C a (f a))

f :> g = g  f

_︔_ = _:>_

infixr 90 _:>_
infixr 90 _︔_
domain
  :  {ℓ₁ ℓ₂ : Level}{A : Type ℓ₁}{B : Type ℓ₂}
   (A  B)
   Type ℓ₁

domain {A = A} _ = A
codomain
  :  {ℓ₁ ℓ₂ : Level}{A : Type ℓ₁}{B : Type ℓ₂}
   (A  B)
   Type ℓ₂

codomain {B = B} _ = B
type-of
  :  { : Level}{X : Type }
   X  Type 

type-of {X = X} _ = X
level-of
  :  { : Level}
   (A : Type )
   Level

level-of {} A = 
∘-lassoc
  :  { : Level} {A B C D : Type }
   (h : C  D)  (g : B  C)  (f : A  B)
  -----------------------------------------
   (h  (g  f))  ((h  g)  f)

∘-lassoc h g f = refl  x  h (g (f x)))
∘-rassoc
  :  { : Level} {A B C D : Type }
   (h : C  D)  (g : B  C)  (f : A  B)
  -----------------------------------------
   ((h  g)  f)  (h  (g  f))

∘-rassoc h g f = sym (∘-lassoc h g f)
:>-lassoc
  :  {ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Type ℓ₁}{B : Type ℓ₂}{C : Type ℓ₃}{D : Type ℓ₄}
   (f : A  B)  (g : B  C)  (h : C  D)
  -----------------------------------------
   (f :> (g :> h))  ((f :> g) :> h)

:>-lassoc f g h = idp
:>-rassoc
  :  {ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Type ℓ₁}{B : Type ℓ₂}{C : Type ℓ₃}{D : Type ℓ₄}
   (f : A  B)  (g : B  C)  (h : C  D)
  -----------------------------------------
   ((f :> g) :>  h)  (f :> (g :> h))

:>-rassoc f g h = sym (:>-lassoc f g h)
_←_ :  {ℓ₁ ℓ₂ : Level} (A : Type ℓ₁) (B : Type ℓ₂)  Type (ℓ₁  ℓ₂)
B  A = A  B
_$_
  :  {ℓ₁ ℓ₂ : Level} {A : Type ℓ₁}{B : A  Type ℓ₂}
   (∀ (x : A)  B x)
  -------------
   (∀ (x : A)  B x)

f $ x = f x

infixr 0 _$_
plus _+ₙ_ :     
plus zero     y = y
plus (succ x) y = succ (plus x y)
infixl 60 _+ₙ_
_+ₙ_ = plus

plus' _+ℕ_ :     
plus' x zero = x
plus' x (succ y) = succ (plus' x y)
_+ℕ_ = plus'
max :     
max 0        n = n
max (succ n) 0 = succ n
max (succ n) (succ m) = succ (max n m)
min :     
min 0        n = 0
min (succ n) 0 = 0
min (succ n) (succ m) = succ (min n m)

Now, we prove some lemmas about natural number addition are the following. Notice in the proofs, the extensive usage of rewriting, because at this point we have not showed that the equality type is a congruent relation.

plus-lunit
  :  (n : )
  ----------------
   zero +ₙ n  n

plus-lunit n = refl n
plus-runit
  : (n : )
  ----------------
   n +ₙ zero  n

plus-runit zero     = refl zero
plus-runit (succ n) rewrite (plus-runit n) = idp
plus-succ
  :  (n m : )
  ----------------------------------
   succ (n +ₙ m)  (n +ₙ (succ m))

plus-succ zero     m = refl (succ m)
plus-succ (succ n) m rewrite (plus-succ n m) = idp
plus-succ-rs
  : (n m o p : )
          n +ₙ m  o +ₙ p
  --------------------------------
   n +ₙ (succ m)  o +ₙ (succ p)

plus-succ-rs 0 m 0 p α rewrite α = idp
plus-succ-rs 0 m (succ o) p α rewrite α | plus-succ o p = idp
plus-succ-rs (succ n) m 0 p α rewrite α | ! (plus-succ n m) | α = idp
plus-succ-rs (succ n) m (succ o) p α rewrite ! α | ! (plus-succ n m) | plus-succ o p | α = idp
-- other solution, just : ! (plus-succ n m) · ap succ α · (plus-succ o p)

Commutativity

plus-comm
  : (n m : )
  -----------------
   n +ₙ m  m +ₙ n

plus-comm zero     m = inv (plus-runit m)
plus-comm (succ n) m rewrite (plus-comm n m)  = plus-succ m n

Associativity

plus-assoc
  : (n m p : )
  ---------------------------------
   n +ₙ (m +ₙ p)  (n +ₙ m) +ₙ p

plus-assoc zero     m p = refl (m +ₙ p)
plus-assoc (succ n) m p  rewrite (plus-assoc n m p) = idp

Coproduct manipulation

+-map
  :  {i j k l : Level} {A : Type i} {B : Type j} {A' : Type k} {B' : Type l}
   (A  A')
   (B  B')
   A + B  A' + B'

+-map f g = cases (f :> inl) (g :> inr)

syntax +-map f g =  f  g 
parallell
  :  {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Type ℓ₁} {B : A  Type ℓ₂} {C : (a : A)  (B a  Type ℓ₃)}
   (f : (a : A)  B a)
   ((a : A)  C a (f a))
  -------------------------
   (a : A)   (B a) (C a)

parallell f g a = (f a , g a)
syntax parallell f g =  f × g 

Curryfication

curry
  :  {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Type ℓ₁}{B : A  Type ℓ₂}  {C : Σ A B  Type ℓ₃}
   ((s :  A B)  C s)
  -------------------------------
   ((x : A)(y : B x)  C (x , y))

curry f x y = f (x , y)

Uncurryfication

unCurry
  :  {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Type ℓ₁}{B : A  Type ℓ₂} {C : Type ℓ₃}
   (D : (a : A)  B a  C)
  ------------------------
   (p :  A B)  C

unCurry D p = D (proj₁ p) (proj₂ p)
uncurry
  :  {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Type ℓ₁} {B : A  Type ℓ₂} {C : (a : A)  (B a  Type ℓ₃)}
   (f : (a : A) (b : B a)  C a b)
  ---------------------------------
   (p :  A B)  C (π₁ p) (π₂ p)

uncurry f (x , y) = f x y

Coproducts functions

inr-is-injective
  :  {ℓ₁ ℓ₂ : Level}{A : Type ℓ₁}{B : Type ℓ₂} {b₁ b₂ : B}
   inr {A = A}{B} b₁  inr b₂
  ----------------------------
   b₁  b₂

inr-is-injective idp = idp
inl-is-injective
  :  {ℓ₁ ℓ₂ : Level}{A : Type ℓ₁}{B : Type ℓ₂} {a₁ a₂ : A}
   inl {A = A}{B} a₁  inl a₂
  ----------------------------
   a₁  a₂

inl-is-injective idp = idp

Equational reasoning

Equational reasoning is a way to write readable chains of equalities.

module _ { : Level} {A : Type } where
  _≡⟨⟩_
    :  (x {y} : A)
    -----------------
     x  y  x  y

  _ ≡⟨⟩ p = p

  infixr 2 _≡⟨⟩_
  _≡⟨_⟩_
    : (x : A) {y z : A}
     x  y
     y  z
    --------
     x  z

  _ ≡⟨ thm  q = thm · q
  infixr 2 _≡⟨_⟩_ _≡⟨_⟩_

Q.E.D:

  _∎
    : (x : A)
     x  x

  _∎ = λ x  idp

  infix 3 _∎
  begin_
    : {x y : A}
     x  y
     x  y

  begin_ p = p

  infix 1 begin_

Finite iteration of a function

For any endo-function in (A), (f: A A), the following function iterates (n) times (f)

[ f^{n+1}(x) = f (f^{n} (x)) ]

infixl 50 _^_
_^_
  :  { : Level} {A : Type }
   (f : A  A)  (n : )
  -----------------------
   (A  A)

f ^ 0 = id
f ^ succ n = λ x  f ((f ^ n) x)
ap
  :  {ℓ₁ ℓ₂ : Level} {A : Type ℓ₁}{B : Type ℓ₂}
   (f : A  B) {a₁ a₂ : A}
   a₁  a₂
  --------------
   f a₁  f a₂

ap f idp = idp

More syntax:

cong  = ap
app-≡ = ap

syntax app-≡ f p = f [[ p ]]

We can define a convenient syntax sugar for ap in equational reasoning.

infixl 40 ap
syntax ap f p = p |in-ctx f
app-comm
  :  { : Level}{A : Type }
   (f : A  A)  (n : )
   (x : A)
  ---------------------------------
   (f ((f ^ n) x)  ((f ^ n) (f x)))

app-comm f 0 x = idp
app-comm f (succ n) x rewrite app-comm f n x = idp
app-comm₂
  :  { : Level}{A : Type }
   (f : A  A)
   (n k : )
   (x : A)
  ------------------------------------------
   ((f ^ (n +ₙ k)) x)  (f ^ n) ((f ^ k) x)

app-comm₂ f 0 0 x = idp
app-comm₂ f 0 (succ k) x = idp
app-comm₂ f (succ n) 0 x rewrite plus-runit n  = idp
app-comm₂ f (succ n) (succ k) x rewrite app-comm₂ f n (succ k) x = idp
app-comm₃
  :  { : Level}{A : Type }
   (f : A  A)
   (k n : )
   (x : A)
  ------------------------------------------
   (f ^ k) ((f ^ n) x)  (f ^ n) ((f ^ k) x)

app-comm₃ f k 0 x          = idp
app-comm₃ f k n@(succ _) x =
   begin
      (f ^ k) ((f ^ n) x)
      ≡⟨ ! (app-comm₂ f k n x) 
      (f ^ (k +ₙ n)) x
      ≡⟨ ap  p  (f ^ p) x) (plus-comm k n) 
      (f ^ (n +ₙ k)) x
      ≡⟨ app-comm₂ f n k x 
      (f ^ n) ((f ^ k) x)
      

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