open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; sym; trans; module ≡-Reasoning) open ≡-Reasoning -- The set of booleans is the smallest set which satisfies those conditions: -- - true is in that set -- - false is in that set data Bool : Set where true : Bool false : Bool _∧_ : Bool → Bool → Bool true ∧ true = true true ∧ false = false false ∧ y = false ∧-comm : ∀ (x y : Bool) → (x ∧ y) ≡ (y ∧ x) ∧-comm true true = refl ∧-comm true false = refl ∧-comm false true = refl ∧-comm false false = refl -- The set of natural numbers is the smallest set which satisfies those conditions: -- - 0 is in that set -- - for every n in that set, also suc n in that set data ℕ : Set where zero : ℕ suc : ℕ → ℕ _+_ : ℕ → ℕ → ℕ zero + y = y (suc x) + y = suc (x + y) +-assoc : ∀ (x y z : ℕ) → (x + y) + z ≡ x + (y + z) +-assoc zero y z = refl +-assoc (suc x) y z = cong suc (+-assoc x y z) +-identity-r : ∀ (x : ℕ) → zero + x ≡ x +-identity-r x = refl +-identity-l : ∀ (x : ℕ) → x ≡ x + zero +-identity-l zero = refl +-identity-l (suc x) = cong suc (+-identity-l x) +-identity-l' : ∀ (x : ℕ) → x ≡ x + zero +-identity-l' zero = refl +-identity-l' (suc x) rewrite sym (+-identity-l' x) = refl +-suc : ∀ (x y : ℕ) → suc (x + y) ≡ (x + suc y) +-suc zero y = refl +-suc (suc x) y = cong suc (+-suc x y) +-comm : ∀ (x y : ℕ) → x + y ≡ y + x +-comm zero y = +-identity-l y +-comm (suc x) y = begin (suc x) + y ≡⟨⟩ suc (x + y) ≡⟨ cong suc (+-comm x y) ⟩ suc (y + x) ≡⟨ +-suc y x ⟩ y + suc x ∎ +-comm' : ∀ (x y : ℕ) → x + y ≡ y + x +-comm' zero y = +-identity-l y +-comm' (suc x) y rewrite +-comm x y | +-suc y x = refl