Theory CZH_ECAT_Order

(* Copyright 2020 (C) Mihails Milehins *)

section‹Orders›
theory CZH_ECAT_Order
  imports 
    CZH_ECAT_Functor
begin



subsection‹Background›

named_theorems cat_order_cs_simps
named_theorems cat_order_cs_intros



subsection‹Preorder category›


text‹See Chapter I-2 in cite"mac_lane_categories_2010".›

locale cat_preorder = category α  for α  +
  assumes cat_peo: 
    " a  Obj; b  Obj  
      (f. Hom  a b = set {f})  (Hom  a b = 0)"


text‹Rules.›

lemma (in cat_preorder) cat_preorder_axioms'[cat_order_cs_intros]:
  assumes "α' = α"
  shows "cat_preorder α' "
  unfolding assms by (rule cat_preorder_axioms)

mk_ide rf cat_preorder_def[unfolded cat_preorder_axioms_def]
  |intro cat_preorderI|
  |dest cat_preorderD[dest]|
  |elim cat_preorderE[elim]|

lemmas [cat_order_cs_intros] = cat_preorderD(1)


text‹Elementary properties.›

lemma (in cat_preorder) cat_peo_HomE:
  assumes "a  Obj" and "b  Obj"
  obtains f where Hom  a b = set {f} | Hom  a b = 0
  using cat_peo[OF assms] by auto

lemma (in cat_preorder) cat_peo_is_thin_category:
  ―‹
  The statement of the lemma appears in
  nLab \cite{noauthor_nlab_nodate}\footnote{
  \url{https://ncatlab.org/nlab/show/preorder}
  }.›
  assumes "f : a b" and "g : a b"
  shows "f = g"
proof-
  note f = cat_is_arrD[OF assms(1)]
  from assms have "Hom  a b  0" by (metis HomI eq0_iff)
  with cat_peo_HomE[OF f(2,3)] obtain h where "Hom  a b = set {h}" by auto
  moreover from assms have "f  Hom  a b" and "g  Hom  a b" by auto
  ultimately have "h = f" and "h = g" by auto
  then show ?thesis by auto
qed



subsection‹Order relation›


subsubsection‹Definition and elementary properties›

definition is_le :: "V  V  V  bool" (infix Oı› 50)
  where "a Ob  Hom  a b  0"


text‹Rules.›

mk_ide is_le_def
  |intro is_leI|
  |dest is_leD[dest]|
  |elim is_leE[elim]|


text‹Elementary properties.›

lemma (in cat_preorder) cat_peo_is_le[cat_order_cs_intros]: 
  assumes "f : a b"
  shows "a Ob"
  using assms by (force intro: is_leI)

lemmas [cat_order_cs_intros] = cat_preorder.cat_peo_is_le

lemma (in cat_preorder) cat_peo_is_le_ex1:
  assumes "a Ob" and "a  Obj" and "b  Obj"
  shows "∃!f. f : a b"
proof-
  from assms have "Hom  a b  0" by auto
  with assms cat_peo obtain f where Hom_ab: "Hom  a b = set {f}" by meson
  show "∃!f. f : a b"
  proof(intro ex1I)
    from Hom_ab show "f : a b" by auto
    fix g assume "g : a b"
    with Hom_ab show "g = f" by auto
  qed
qed

lemma (in cat_preorder) cat_peo_is_le_ex[elim]:
  assumes "a Ob" and "a  Obj" and "b  Obj"
  obtains f where "f : a b"
  using cat_peo_is_le_ex1[OF assms] that by clarsimp


subsubsection‹Order relation on a preorder category is a preorder›

lemma (in cat_preorder) is_le_refl: 
  assumes "a  Obj"
  shows "a Oa"
proof(intro is_leI)
  from assms have "CIda  Hom  a a" 
    by (cs_concl cs_shallow cs_intro: cat_cs_intros)
  then show "Hom  a a  0" by force
qed

lemma (in cat_preorder) is_le_trans: 
  assumes "a  Obj"
    and "b  Obj"
    and "c  Obj"
    and "a Ob"
    and "b Oc"
  shows "a Oc"
proof(intro is_leI)
  from assms obtain f where f: "f : a b" by auto
  from assms obtain g where g: "g : b c" by auto
  from f g have "g Af : a c"
    by (cs_concl cs_shallow cs_intro: cat_cs_intros)
  then show "Hom  a c  0" by force
qed



subsection‹Partial order category›


text‹See Chapter I-2 in cite"mac_lane_categories_2010".›

locale cat_partial_order = cat_preorder α  for α  +
  assumes cat_po: " a  Obj; b  Obj; a Ob; b Oa   a = b"


text‹Rules.›

lemma (in cat_partial_order) cat_partial_order_axioms'[cat_order_cs_intros]:
  assumes "α' = α"
  shows "cat_partial_order α' "
  unfolding assms by (rule cat_partial_order_axioms)

mk_ide rf cat_partial_order_def[unfolded cat_partial_order_axioms_def]
  |intro cat_partial_orderI|
  |dest cat_partial_orderD[dest]|
  |elim cat_partial_orderE[elim]|

lemmas [cat_order_cs_intros] = cat_partial_orderD(1)



subsection‹Linear order category›


text‹See Chapter I-2 in cite"mac_lane_categories_2010".›

locale cat_linear_order = cat_partial_order α  for α  +
  assumes cat_lo: " a  Obj; b  Obj   a Ob  b Oa"


text‹Rules.›

lemma (in cat_linear_order) cat_linear_order_axioms'[cat_order_cs_intros]:
  assumes "α' = α"
  shows "cat_linear_order α' "
  unfolding assms by (rule cat_linear_order_axioms)

mk_ide rf cat_linear_order_def[unfolded cat_linear_order_axioms_def]
  |intro cat_linear_orderI|
  |dest cat_linear_orderD[dest]|
  |elim cat_linear_orderE[elim]|

lemmas [cat_order_cs_intros] = cat_linear_orderD(1)



subsection‹Preorder functor›


subsubsection‹Definition and elementary properties›


text‹
See cite"noauthor_nlab_nodate"\footnote{
\url{https://ncatlab.org/nlab/show/monotone+function}
}.
›

locale is_preorder_functor = 
  is_functor α 𝔄 𝔅 𝔉 + HomDom: cat_preorder α 𝔄 + HomCod: cat_preorder α 𝔅
  for α 𝔄 𝔅 𝔉 

syntax "_is_preorder_functor" :: "V  V  V  V  bool"
  ((_ :/ _ C.PEOı _) [51, 51, 51] 51)
translations "𝔉 : 𝔄 C.PEOα𝔅"  "CONST is_preorder_functor α 𝔄 𝔅 𝔉"


text‹Rules.›

lemma (in is_preorder_functor) is_preorder_functor_axioms'[cat_order_cs_intros]:
  assumes "α' = α" and "𝔄' = 𝔄" and "𝔅' = 𝔅"
  shows "𝔉 : 𝔄' C.PEOα'𝔅'"
  unfolding assms by (rule is_preorder_functor_axioms)
 
mk_ide rf is_preorder_functor_def
  |intro is_preorder_functorI|
  |dest is_preorder_functorD[dest]|
  |elim is_preorder_functorE[elim]|

lemmas [cat_order_cs_intros] = is_preorder_functorD


subsubsection‹A preorder functor is a faithful functor›

sublocale is_preorder_functor  is_ft_functor
proof(intro is_ft_functorI')
  fix a b assume "a  𝔄Obj" "b  𝔄Obj"
  show "v11 (𝔉ArrMap l Hom 𝔄 a b)"
  proof
    (
      intro vsv.vsv_valeq_v11I, 
      unfold vdomain_vlrestriction cat_cs_simps vintersection_iff; 
      (elim conjE)?
    )
    fix g f assume "g : a 𝔄b" "f : a 𝔄b"  
    then show "g = f" by (auto simp: HomDom.cat_peo_is_thin_category)
  qed simp
qed (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)


lemmas (in is_preorder_functor) is_preorder_functor_is_ft_functor = 
  is_ft_functor_axioms

lemmas [cat_order_cs_intros] = 
  is_preorder_functor.is_preorder_functor_is_ft_functor


subsubsection‹A preorder functor is a monotone function›

lemma (in is_preorder_functor) cat_peo:
  ―‹
  Based on \cite{noauthor_nlab_nodate}\footnote{
  \url{https://ncatlab.org/nlab/show/monotone+function}
  }›
  assumes "a  𝔄Obj" and "b  𝔄Obj" and "a O𝔄b"
  shows "𝔉ObjMapa O𝔅𝔉ObjMapb"
proof-
  from assms obtain f where "f : a 𝔄b" by auto
  then have "𝔉ArrMapf : 𝔉ObjMapa 𝔅𝔉ObjMapb"
    by (simp add: cf_ArrMap_is_arr)
  then show "𝔉ObjMapa O𝔅𝔉ObjMapb"
    by (cs_concl cs_shallow cs_intro: cat_order_cs_intros)
qed


subsubsection‹Composition of preorder functors›

lemma cf_comp_is_preorder_functor[cat_order_cs_intros]:
  assumes "𝔊 : 𝔅 C.PEOα" and "𝔉 : 𝔄 C.PEOα𝔅"
  shows "𝔊 CF 𝔉 : 𝔄 C.PEOα"
proof-
  interpret 𝔊: is_preorder_functor α 𝔅  𝔊 by (rule assms(1))
  interpret 𝔉: is_preorder_functor α 𝔄 𝔅 𝔉 by (rule assms(2))
  show ?thesis
    by (intro is_preorder_functorI)
      (cs_concl cs_intro: cat_cs_intros cat_order_cs_intros)+
qed

lemma (in cat_preorder) cat_peo_cf_is_preorder_functor: 
  "cf_id  :  C.PEOα"
  by (intro is_preorder_functorI)
    (cs_concl cs_intro: cat_cs_intros cat_order_cs_intros)+

lemma (in cat_preorder) cat_peo_cf_is_preorder_functor'[cat_order_cs_intros]:
  assumes "𝔄' = " and "𝔅' = "
  shows "cf_id  : 𝔄' C.PEOα𝔅'"
  unfolding assms by (rule cat_peo_cf_is_preorder_functor)

lemmas [cat_order_cs_intros] = cat_preorder.cat_peo_cf_is_preorder_functor'

end