| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Properties satisfied by Heyting Algebra |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Relation.Binary.Lattice |
| 10 |
|
| 11 |
module Relation.Binary.Lattice.Properties.HeytingAlgebra |
| 12 |
{c ℓ₁ ℓ₂} (L : HeytingAlgebra c ℓ₁ ℓ₂) where |
| 13 |
|
| 14 |
open import Algebra.Core using (Op₁) |
| 15 |
open import Data.Product.Base using (_,_) |
| 16 |
open import Function.Base using (_$_; flip; _∘_) |
| 17 |
open import Level using (_⊔_) |
| 18 |
open import Relation.Binary.Core using (_Preserves_⟶_; _Preserves₂_⟶_⟶_) |
| 19 |
import Relation.Binary.Reasoning.PartialOrder as ≤-Reasoning |
| 20 |
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning |
| 21 |
|
| 22 |
open HeytingAlgebra L |
| 23 |
|
| 24 |
open import Algebra.Definitions _≈_ using (_DistributesOverˡ_; _DistributesOverʳ_) |
| 25 |
open import Relation.Binary.Lattice.Properties.MeetSemilattice meetSemilattice |
| 26 |
using (∧-comm; ∧-idempotent; ∧-assoc; ∧-monotonic; ∧-cong) |
| 27 |
open import Relation.Binary.Lattice.Properties.JoinSemilattice joinSemilattice |
| 28 |
using (∨-idempotent; ∨-monotonic) |
| 29 |
import Relation.Binary.Lattice.Properties.BoundedMeetSemilattice boundedMeetSemilattice as BM |
| 30 |
using (identityˡ) |
| 31 |
open import Relation.Binary.Lattice.Properties.BoundedLattice boundedLattice |
| 32 |
using ( ∧-zeroˡ; ∧-zeroʳ; ∨-zeroˡ; ∨-zeroʳ ) |
| 33 |
|
| 34 |
------------------------------------------------------------------------ |
| 35 |
-- Useful lemmas |
| 36 |
|
| 37 |
⇨-eval : ∀ {x y} → (x ⇨ y) ∧ x ≤ y |
| 38 |
⇨-eval {x} {y} = transpose-∧ refl |
| 39 |
|
| 40 |
swap-transpose-⇨ : ∀ {x y w} → x ∧ w ≤ y → w ≤ x ⇨ y |
| 41 |
swap-transpose-⇨ x∧w≤y = transpose-⇨ $ trans (reflexive $ ∧-comm _ _) x∧w≤y |
| 42 |
|
| 43 |
------------------------------------------------------------------------ |
| 44 |
-- Properties of exponential |
| 45 |
|
| 46 |
⇨-unit : ∀ {x} → x ⇨ x ≈ ⊤ |
| 47 |
⇨-unit = antisym (maximum _) (transpose-⇨ $ reflexive $ BM.identityˡ _) |
| 48 |
|
| 49 |
y≤x⇨y : ∀ {x y} → y ≤ x ⇨ y |
| 50 |
y≤x⇨y = transpose-⇨ (x∧y≤x _ _) |
| 51 |
|
| 52 |
⇨-drop : ∀ {x y} → (x ⇨ y) ∧ y ≈ y |
| 53 |
⇨-drop = antisym (x∧y≤y _ _) (∧-greatest y≤x⇨y refl) |
| 54 |
|
| 55 |
⇨-app : ∀ {x y} → (x ⇨ y) ∧ x ≈ y ∧ x |
| 56 |
⇨-app = antisym (∧-greatest ⇨-eval (x∧y≤y _ _)) (∧-monotonic y≤x⇨y refl) |
| 57 |
|
| 58 |
⇨ʳ-covariant : ∀ {x} → (x ⇨_) Preserves _≤_ ⟶ _≤_ |
| 59 |
⇨ʳ-covariant y≤z = transpose-⇨ (trans ⇨-eval y≤z) |
| 60 |
|
| 61 |
⇨ˡ-contravariant : ∀ {x} → (_⇨ x) Preserves (flip _≤_) ⟶ _≤_ |
| 62 |
⇨ˡ-contravariant z≤y = transpose-⇨ (trans (∧-monotonic refl z≤y) ⇨-eval) |
| 63 |
|
| 64 |
⇨-relax : _⇨_ Preserves₂ (flip _≤_) ⟶ _≤_ ⟶ _≤_ |
| 65 |
⇨-relax {x} {y} {u} {v} y≤x u≤v = begin |
| 66 |
x ⇨ u ≤⟨ ⇨ʳ-covariant u≤v ⟩ |
| 67 |
x ⇨ v ≤⟨ ⇨ˡ-contravariant y≤x ⟩ |
| 68 |
y ⇨ v ∎ |
| 69 |
where open ≤-Reasoning poset |
| 70 |
|
| 71 |
⇨-cong : _⇨_ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_ |
| 72 |
⇨-cong x≈y u≈v = antisym (⇨-relax (reflexive $ Eq.sym x≈y) (reflexive u≈v)) |
| 73 |
(⇨-relax (reflexive x≈y) (reflexive $ Eq.sym u≈v)) |
| 74 |
|
| 75 |
⇨-applyˡ : ∀ {w x y} → w ≤ x → (x ⇨ y) ∧ w ≤ y |
| 76 |
⇨-applyˡ = transpose-∧ ∘ ⇨ˡ-contravariant |
| 77 |
|
| 78 |
⇨-applyʳ : ∀ {w x y} → w ≤ x → w ∧ (x ⇨ y) ≤ y |
| 79 |
⇨-applyʳ w≤x = trans (reflexive (∧-comm _ _)) (⇨-applyˡ w≤x) |
| 80 |
|
| 81 |
⇨-curry : ∀ {x y z} → x ∧ y ⇨ z ≈ x ⇨ y ⇨ z |
| 82 |
⇨-curry = antisym (transpose-⇨ $ transpose-⇨ $ trans (reflexive $ ∧-assoc _ _ _) ⇨-eval) |
| 83 |
(transpose-⇨ $ trans (reflexive $ Eq.sym $ ∧-assoc _ _ _) |
| 84 |
(transpose-∧ $ ⇨-applyˡ refl)) |
| 85 |
|
| 86 |
------------------------------------------------------------------------ |
| 87 |
-- Various proofs of distributivity |
| 88 |
|
| 89 |
∧-distribˡ-∨-≤ : ∀ x y z → x ∧ (y ∨ z) ≤ x ∧ y ∨ x ∧ z |
| 90 |
∧-distribˡ-∨-≤ x y z = trans (reflexive $ ∧-comm _ _) |
| 91 |
(transpose-∧ $ ∨-least (swap-transpose-⇨ (x≤x∨y _ _)) $ swap-transpose-⇨ (y≤x∨y _ _)) |
| 92 |
|
| 93 |
∧-distribˡ-∨-≥ : ∀ x y z → x ∧ y ∨ x ∧ z ≤ x ∧ (y ∨ z) |
| 94 |
∧-distribˡ-∨-≥ x y z = let |
| 95 |
x∧y≤x , x∧y≤y , _ = infimum x y |
| 96 |
x∧z≤x , x∧z≤z , _ = infimum x z |
| 97 |
y≤y∨z , z≤y∨z , _ = supremum y z |
| 98 |
in ∧-greatest (∨-least x∧y≤x x∧z≤x) |
| 99 |
(∨-least (trans x∧y≤y y≤y∨z) (trans x∧z≤z z≤y∨z)) |
| 100 |
|
| 101 |
∧-distribˡ-∨ : _∧_ DistributesOverˡ _∨_ |
| 102 |
∧-distribˡ-∨ x y z = antisym (∧-distribˡ-∨-≤ x y z) (∧-distribˡ-∨-≥ x y z) |
| 103 |
|
| 104 |
⇨-distribˡ-∧-≤ : ∀ x y z → x ⇨ y ∧ z ≤ (x ⇨ y) ∧ (x ⇨ z) |
| 105 |
⇨-distribˡ-∧-≤ x y z = let |
| 106 |
y∧z≤y , y∧z≤z , _ = infimum y z |
| 107 |
in ∧-greatest (transpose-⇨ $ trans ⇨-eval y∧z≤y) |
| 108 |
(transpose-⇨ $ trans ⇨-eval y∧z≤z) |
| 109 |
|
| 110 |
⇨-distribˡ-∧-≥ : ∀ x y z → (x ⇨ y) ∧ (x ⇨ z) ≤ x ⇨ y ∧ z |
| 111 |
⇨-distribˡ-∧-≥ x y z = transpose-⇨ (begin |
| 112 |
(((x ⇨ y) ∧ (x ⇨ z)) ∧ x) ≈⟨ ∧-cong Eq.refl $ Eq.sym $ ∧-idempotent _ ⟩ |
| 113 |
(((x ⇨ y) ∧ (x ⇨ z)) ∧ x ∧ x) ≈⟨ Eq.sym $ ∧-assoc _ _ _ ⟩ |
| 114 |
(((x ⇨ y) ∧ (x ⇨ z)) ∧ x) ∧ x ≈⟨ ∧-cong (∧-assoc _ _ _) Eq.refl ⟩ |
| 115 |
(((x ⇨ y) ∧ (x ⇨ z) ∧ x) ∧ x) ≈⟨ ∧-cong (∧-cong Eq.refl $ ∧-comm _ _) Eq.refl ⟩ |
| 116 |
(((x ⇨ y) ∧ x ∧ (x ⇨ z)) ∧ x) ≈⟨ ∧-cong (Eq.sym $ ∧-assoc _ _ _) Eq.refl ⟩ |
| 117 |
(((x ⇨ y) ∧ x) ∧ (x ⇨ z)) ∧ x ≈⟨ ∧-assoc _ _ _ ⟩ |
| 118 |
(((x ⇨ y) ∧ x) ∧ (x ⇨ z) ∧ x) ≤⟨ ∧-monotonic ⇨-eval ⇨-eval ⟩ |
| 119 |
y ∧ z ∎) |
| 120 |
where open ≤-Reasoning poset |
| 121 |
|
| 122 |
⇨-distribˡ-∧ : _⇨_ DistributesOverˡ _∧_ |
| 123 |
⇨-distribˡ-∧ x y z = antisym (⇨-distribˡ-∧-≤ x y z) (⇨-distribˡ-∧-≥ x y z) |
| 124 |
|
| 125 |
⇨-distribˡ-∨-∧-≤ : ∀ x y z → x ∨ y ⇨ z ≤ (x ⇨ z) ∧ (y ⇨ z) |
| 126 |
⇨-distribˡ-∨-∧-≤ x y z = let x≤x∨y , y≤x∨y , _ = supremum x y |
| 127 |
in ∧-greatest (transpose-⇨ $ trans (∧-monotonic refl x≤x∨y) ⇨-eval) |
| 128 |
(transpose-⇨ $ trans (∧-monotonic refl y≤x∨y) ⇨-eval) |
| 129 |
|
| 130 |
⇨-distribˡ-∨-∧-≥ : ∀ x y z → (x ⇨ z) ∧ (y ⇨ z) ≤ x ∨ y ⇨ z |
| 131 |
⇨-distribˡ-∨-∧-≥ x y z = transpose-⇨ (trans (reflexive $ ∧-distribˡ-∨ _ _ _) |
| 132 |
(∨-least (trans (transpose-∧ (x∧y≤x _ _)) refl) |
| 133 |
(trans (transpose-∧ (x∧y≤y _ _)) refl))) |
| 134 |
|
| 135 |
⇨-distribˡ-∨-∧ : ∀ x y z → x ∨ y ⇨ z ≈ (x ⇨ z) ∧ (y ⇨ z) |
| 136 |
⇨-distribˡ-∨-∧ x y z = antisym (⇨-distribˡ-∨-∧-≤ x y z) (⇨-distribˡ-∨-∧-≥ x y z) |
| 137 |
|
| 138 |
------------------------------------------------------------------------ |
| 139 |
-- Heyting algebras are distributive lattices |
| 140 |
|
| 141 |
isDistributiveLattice : IsDistributiveLattice _≈_ _≤_ _∨_ _∧_ |
| 142 |
isDistributiveLattice = record |
| 143 |
{ isLattice = isLattice |
| 144 |
; ∧-distribˡ-∨ = ∧-distribˡ-∨ |
| 145 |
} |
| 146 |
|
| 147 |
distributiveLattice : DistributiveLattice _ _ _ |
| 148 |
distributiveLattice = record |
| 149 |
{ isDistributiveLattice = isDistributiveLattice |
| 150 |
} |
| 151 |
|
| 152 |
------------------------------------------------------------------------ |
| 153 |
-- Heyting algebras can define pseudo-complement |
| 154 |
|
| 155 |
infix 8 ¬_ |
| 156 |
|
| 157 |
¬_ : Op₁ Carrier |
| 158 |
¬ x = x ⇨ ⊥ |
| 159 |
|
| 160 |
x≤¬¬x : ∀ x → x ≤ ¬ ¬ x |
| 161 |
x≤¬¬x x = transpose-⇨ (trans (reflexive (∧-comm _ _)) ⇨-eval) |
| 162 |
|
| 163 |
------------------------------------------------------------------------ |
| 164 |
-- De-Morgan laws |
| 165 |
|
| 166 |
de-morgan₁ : ∀ x y → ¬ (x ∨ y) ≈ ¬ x ∧ ¬ y |
| 167 |
de-morgan₁ x y = ⇨-distribˡ-∨-∧ _ _ _ |
| 168 |
|
| 169 |
de-morgan₂-≤ : ∀ x y → ¬ (x ∧ y) ≤ ¬ ¬ (¬ x ∨ ¬ y) |
| 170 |
de-morgan₂-≤ x y = transpose-⇨ $ begin |
| 171 |
¬ (x ∧ y) ∧ ¬ (¬ x ∨ ¬ y) ≈⟨ ∧-cong ⇨-curry (de-morgan₁ _ _) ⟩ |
| 172 |
(x ⇨ ¬ y) ∧ ¬ ¬ x ∧ ¬ ¬ y ≈⟨ ∧-cong Eq.refl (∧-comm _ _) ⟩ |
| 173 |
(x ⇨ ¬ y) ∧ ¬ ¬ y ∧ ¬ ¬ x ≈⟨ Eq.sym $ ∧-assoc _ _ _ ⟩ |
| 174 |
((x ⇨ ¬ y) ∧ ¬ ¬ y) ∧ ¬ ¬ x ≤⟨ ⇨-applyʳ $ transpose-⇨ $ |
| 175 |
begin |
| 176 |
((x ⇨ ¬ y) ∧ ¬ ¬ y) ∧ x ≈⟨ ∧-cong (∧-comm _ _) Eq.refl ⟩ |
| 177 |
((¬ ¬ y) ∧ (x ⇨ ¬ y)) ∧ x ≈⟨ ∧-assoc _ _ _ ⟩ |
| 178 |
(¬ ¬ y) ∧ (x ⇨ ¬ y) ∧ x ≤⟨ ∧-monotonic refl ⇨-eval ⟩ |
| 179 |
¬ ¬ y ∧ ¬ y ≤⟨ ⇨-eval ⟩ |
| 180 |
⊥ ∎ ⟩ |
| 181 |
⊥ ∎ |
| 182 |
where open ≤-Reasoning poset |
| 183 |
|
| 184 |
de-morgan₂-≥ : ∀ x y → ¬ ¬ (¬ x ∨ ¬ y) ≤ ¬ (x ∧ y) |
| 185 |
de-morgan₂-≥ x y = transpose-⇨ $ ⇨-applyˡ $ transpose-⇨ $ begin |
| 186 |
(x ∧ y) ∧ (¬ x ∨ ¬ y) ≈⟨ ∧-distribˡ-∨ _ _ _ ⟩ |
| 187 |
(x ∧ y) ∧ ¬ x ∨ (x ∧ y) ∧ ¬ y ≤⟨ ∨-monotonic (⇨-applyʳ (x∧y≤x _ _)) |
| 188 |
(⇨-applyʳ (x∧y≤y _ _)) ⟩ |
| 189 |
⊥ ∨ ⊥ ≈⟨ ∨-idempotent _ ⟩ |
| 190 |
⊥ ∎ |
| 191 |
where open ≤-Reasoning poset |
| 192 |
|
| 193 |
de-morgan₂ : ∀ x y → ¬ (x ∧ y) ≈ ¬ ¬ (¬ x ∨ ¬ y) |
| 194 |
de-morgan₂ x y = antisym (de-morgan₂-≤ x y) (de-morgan₂-≥ x y) |
| 195 |
|
| 196 |
weak-lem : ∀ {x} → ¬ ¬ (¬ x ∨ x) ≈ ⊤ |
| 197 |
weak-lem {x} = begin |
| 198 |
¬ ¬ (¬ x ∨ x) ≈⟨ ⇨-cong (de-morgan₁ _ _) Eq.refl ⟩ |
| 199 |
¬ (¬ ¬ x ∧ ¬ x) ≈⟨ ⇨-cong ⇨-app Eq.refl ⟩ |
| 200 |
⊥ ∧ (x ⇨ ⊥) ⇨ ⊥ ≈⟨ ⇨-cong (∧-zeroˡ _) Eq.refl ⟩ |
| 201 |
⊥ ⇨ ⊥ ≈⟨ ⇨-unit ⟩ |
| 202 |
⊤ ∎ |
| 203 |
where open ≈-Reasoning setoid |