definition example

The booleans form a Preorder (indeed a Total Order) with : ” iff implies “.

truefalsetruefalse

Sources: 7 Sketches Example 1.34, 1.54, 1.88, Exercise 1.7, Proposition 1.78; Kittenlab Lecture 14; DaoFP §4.1 (“Bool”); CTfS Definition 2.7.4.9, Proposition 2.7.4.10, §4.2.4.1 (the category of propositions)

Docs: ThThinCategory (GATlab) · Theories & presentations — Kittenlab Lecture 14

# Bool is a preorder in Julia already: false <= true
false <= true            # true
min(true, false)         # meet = AND
max(true, false)         # join = OR

Catlab version (run in a fresh Julia session — Catlab exports its own compose, id, FinFunction, …):

# Catlab: Bool as a thin category / the base of enrichment
using Catlab
@present BoolPreorder(FreePreorder) begin
  (f, t)::El
  f_le_t::Leq(f, t)
end
example : false ≤ true := by decide
example : LinearOrder Bool := inferInstance    -- total order
example : BooleanAlgebra Bool := inferInstance -- ∧ = meet, ∨ = join
-- Bool as a sum type: Bool ≃ Unit ⊕ Unit
example : Bool ≃ Unit ⊕ Unit := ⟨fun b => if b then .inl () else .inr (),
  fun s => s.elim (fun _ => true) (fun _ => false), by intro b; cases b <;> rfl,
  by intro s; rcases s with ⟨⟩ | ⟨⟩ <;> rfl⟩
-- DaoFP §4.1: Bool is a sum of two units
data Bool' = True' | False'
-- Bool is a preorder with False <= True (Ord instance), meet = (&&), join = (||)
meetB, joinB :: Bool -> Bool -> Bool
meetB = (&&)
joinB = (||)
-- a function out of Bool is a pair of elements (the universal property of 1 + 1)
ifThenElse :: a -> a -> Bool -> a
ifThenElse t f b = if b then t else f