Debian Codegraph @

src/Algebra/Construct/NaturalChoice/MinMaxOp.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of min and max operators specified over a total
5 -- preorder.
6 ------------------------------------------------------------------------
7
8 {-# OPTIONS --cubical-compatible --safe #-}
9
10 open import Algebra.Construct.NaturalChoice.Base using (MinOperator; MaxOperator)
11 open import Relation.Binary.Bundles using (TotalPreorder)
12
13 module Algebra.Construct.NaturalChoice.MinMaxOp
14 {a ℓ₁ ℓ₂} {O : TotalPreorder a ℓ₁ ℓ₂}
15 (minOp : MinOperator O)
16 (maxOp : MaxOperator O)
17 where
18
19 open import Data.Sum.Base as Sum using (inj₁; inj₂; [_,_])
20 open import Data.Product.Base using (_,_)
21 open import Function.Base using (id; _∘_; flip)
22 open import Relation.Binary.Core using (_Preserves_⟶_)
23
24 open TotalPreorder O renaming
25 ( Carrier to A
26 ; _≲_ to _≤_
27 ; ≲-resp-≈ to ≤-resp-≈
28 ; ≲-respʳ-≈ to ≤-respʳ-≈
29 ; ≲-respˡ-≈ to ≤-respˡ-≈
30 )
31 open MinOperator minOp
32 open MaxOperator maxOp
33
34 open import Algebra.Definitions _≈_
35 open import Algebra.Structures _≈_
36 open import Algebra.Consequences.Setoid Eq.setoid
37 open import Relation.Binary.Reasoning.Preorder preorder
38
39 ------------------------------------------------------------------------
40 -- Re-export properties of individual operators
41
42 open import Algebra.Construct.NaturalChoice.MinOp minOp public
43 open import Algebra.Construct.NaturalChoice.MaxOp maxOp public
44
45 ------------------------------------------------------------------------
46 -- Joint algebraic structures
47
48 ⊓-distribˡ-⊔ : _⊓_ DistributesOverˡ _⊔_
49 ⊓-distribˡ-⊔ x y z with total y z
50 ... | inj₁ y≤z = begin-equality
51 x ⊓ (y ⊔ z) ≈⟨ ⊓-congˡ x (x≤y⇒x⊔y≈y y≤z) ⟩
52 x ⊓ z ≈⟨ x≤y⇒x⊔y≈y (⊓-monoʳ-≤ x y≤z) ⟨
53 (x ⊓ y) ⊔ (x ⊓ z) ∎
54 ... | inj₂ y≥z = begin-equality
55 x ⊓ (y ⊔ z) ≈⟨ ⊓-congˡ x (x≥y⇒x⊔y≈x y≥z) ⟩
56 x ⊓ y ≈⟨ x≥y⇒x⊔y≈x (⊓-monoʳ-≤ x y≥z) ⟨
57 (x ⊓ y) ⊔ (x ⊓ z) ∎
58
59 ⊓-distribʳ-⊔ : _⊓_ DistributesOverʳ _⊔_
60 ⊓-distribʳ-⊔ = comm∧distrˡ⇒distrʳ ⊔-cong ⊓-comm ⊓-distribˡ-⊔
61
62 ⊓-distrib-⊔ : _⊓_ DistributesOver _⊔_
63 ⊓-distrib-⊔ = ⊓-distribˡ-⊔ , ⊓-distribʳ-⊔
64
65 ⊔-distribˡ-⊓ : _⊔_ DistributesOverˡ _⊓_
66 ⊔-distribˡ-⊓ x y z with total y z
67 ... | inj₁ y≤z = begin-equality
68 x ⊔ (y ⊓ z) ≈⟨ ⊔-congˡ x (x≤y⇒x⊓y≈x y≤z) ⟩
69 x ⊔ y ≈⟨ x≤y⇒x⊓y≈x (⊔-monoʳ-≤ x y≤z) ⟨
70 (x ⊔ y) ⊓ (x ⊔ z) ∎
71 ... | inj₂ y≥z = begin-equality
72 x ⊔ (y ⊓ z) ≈⟨ ⊔-congˡ x (x≥y⇒x⊓y≈y y≥z) ⟩
73 x ⊔ z ≈⟨ x≥y⇒x⊓y≈y (⊔-monoʳ-≤ x y≥z) ⟨
74 (x ⊔ y) ⊓ (x ⊔ z) ∎
75
76 ⊔-distribʳ-⊓ : _⊔_ DistributesOverʳ _⊓_
77 ⊔-distribʳ-⊓ = comm∧distrˡ⇒distrʳ ⊓-cong ⊔-comm ⊔-distribˡ-⊓
78
79 ⊔-distrib-⊓ : _⊔_ DistributesOver _⊓_
80 ⊔-distrib-⊓ = ⊔-distribˡ-⊓ , ⊔-distribʳ-⊓
81
82 ⊓-absorbs-⊔ : _⊓_ Absorbs _⊔_
83 ⊓-absorbs-⊔ x y with total x y
84 ... | inj₁ x≤y = begin-equality
85 x ⊓ (x ⊔ y) ≈⟨ ⊓-congˡ x (x≤y⇒x⊔y≈y x≤y) ⟩
86 x ⊓ y ≈⟨ x≤y⇒x⊓y≈x x≤y ⟩
87 x ∎
88 ... | inj₂ y≤x = begin-equality
89 x ⊓ (x ⊔ y) ≈⟨ ⊓-congˡ x (x≥y⇒x⊔y≈x y≤x) ⟩
90 x ⊓ x ≈⟨ ⊓-idem x ⟩
91 x ∎
92
93 ⊔-absorbs-⊓ : _⊔_ Absorbs _⊓_
94 ⊔-absorbs-⊓ x y with total x y
95 ... | inj₁ x≤y = begin-equality
96 x ⊔ (x ⊓ y) ≈⟨ ⊔-congˡ x (x≤y⇒x⊓y≈x x≤y) ⟩
97 x ⊔ x ≈⟨ ⊔-idem x ⟩
98 x ∎
99 ... | inj₂ y≤x = begin-equality
100 x ⊔ (x ⊓ y) ≈⟨ ⊔-congˡ x (x≥y⇒x⊓y≈y y≤x) ⟩
101 x ⊔ y ≈⟨ x≥y⇒x⊔y≈x y≤x ⟩
102 x ∎
103
104 ⊔-⊓-absorptive : Absorptive _⊔_ _⊓_
105 ⊔-⊓-absorptive = ⊔-absorbs-⊓ , ⊓-absorbs-⊔
106
107 ⊓-⊔-absorptive : Absorptive _⊓_ _⊔_
108 ⊓-⊔-absorptive = ⊓-absorbs-⊔ , ⊔-absorbs-⊓
109
110 ------------------------------------------------------------------------
111 -- Other joint properties
112
113 private _≥_ = flip _≤_
114
115 antimono-≤-distrib-⊓ : ∀ {f} → f Preserves _≈_ ⟶ _≈_ → f Preserves _≤_ ⟶ _≥_ →
116 ∀ x y → f (x ⊓ y) ≈ f x ⊔ f y
117 antimono-≤-distrib-⊓ {f} cong antimono x y with total x y
118 ... | inj₁ x≤y = begin-equality
119 f (x ⊓ y) ≈⟨ cong (x≤y⇒x⊓y≈x x≤y) ⟩
120 f x ≈⟨ x≥y⇒x⊔y≈x (antimono x≤y) ⟨
121 f x ⊔ f y ∎
122 ... | inj₂ y≤x = begin-equality
123 f (x ⊓ y) ≈⟨ cong (x≥y⇒x⊓y≈y y≤x) ⟩
124 f y ≈⟨ x≤y⇒x⊔y≈y (antimono y≤x) ⟨
125 f x ⊔ f y ∎
126
127 antimono-≤-distrib-⊔ : ∀ {f} → f Preserves _≈_ ⟶ _≈_ → f Preserves _≤_ ⟶ _≥_ →
128 ∀ x y → f (x ⊔ y) ≈ f x ⊓ f y
129 antimono-≤-distrib-⊔ {f} cong antimono x y with total x y
130 ... | inj₁ x≤y = begin-equality
131 f (x ⊔ y) ≈⟨ cong (x≤y⇒x⊔y≈y x≤y) ⟩
132 f y ≈⟨ x≥y⇒x⊓y≈y (antimono x≤y) ⟨
133 f x ⊓ f y ∎
134 ... | inj₂ y≤x = begin-equality
135 f (x ⊔ y) ≈⟨ cong (x≥y⇒x⊔y≈x y≤x) ⟩
136 f x ≈⟨ x≤y⇒x⊓y≈x (antimono y≤x) ⟨
137 f x ⊓ f y ∎
138
139 x⊓y≤x⊔y : ∀ x y → x ⊓ y ≤ x ⊔ y
140 x⊓y≤x⊔y x y = begin
141 x ⊓ y ∼⟨ x⊓y≤x x y ⟩
142 x ∼⟨ x≤x⊔y x y ⟩
143 x ⊔ y ∎