@@ -35,10 +35,8 @@ open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_]′)
35
35
open import Data.Sum.Function.Propositional using (_⊎-cong_)
36
36
open import Effect.Monad
37
37
open import Function.Base
38
- open import Function.Equality using (_⟨$⟩_)
39
- open import Function.Equivalence using (_⇔_; equivalence; Equivalence)
40
- open import Function.Inverse as Inv using (_↔_; inverse; Inverse)
41
- open import Function.Related as Related using (Kind; Related; SK-sym)
38
+ open import Function.Bundles
39
+ open import Function.Related.Propositional as Related using (Kind; Related)
42
40
open import Level using (Level)
43
41
open import Relation.Binary as B hiding (_⇔_)
44
42
open import Relation.Binary.PropositionalEquality as P
@@ -55,9 +53,7 @@ private
55
53
private
56
54
variable
57
55
a b c p q r ℓ : Level
58
- A : Set a
59
- B : Set b
60
- C : Set c
56
+ A B C : Set a
61
57
P Q R : Pred A p
62
58
x y : A
63
59
xs ys : List A
@@ -89,8 +85,8 @@ Any-cong : ∀ {k : Kind} → (∀ x → Related k (P x) (Q x)) →
89
85
(∀ {z} → Related k (z ∈ xs) (z ∈ ys)) →
90
86
Related k (Any P xs) (Any Q ys)
91
87
Any-cong {P = P} {Q = Q} {xs = xs} {ys} P↔Q xs≈ys =
92
- Any P xs ↔⟨ SK-sym Any↔ ⟩
93
- (∃ λ x → x ∈ xs × P x) ∼⟨ Σ.cong Inv.id (xs≈ys ×-cong P↔Q _) ⟩
88
+ Any P xs ↔⟨ Related. SK-sym Any↔ ⟩
89
+ (∃ λ x → x ∈ xs × P x) ∼⟨ {!!} ⟩ -- Σ.cong ? ? ⟩ -- (xs≈ys ×-cong P↔Q _) ⟩ -- Inv.id
94
90
(∃ λ x → x ∈ ys × Q x) ↔⟨ Any↔ ⟩
95
91
Any Q ys ∎
96
92
where open Related.EquationalReasoning
@@ -146,38 +142,38 @@ swap-invol (there pxys) =
146
142
147
143
swap↔ : ∀ {P : A → B → Set ℓ} →
148
144
Any (λ x → Any (P x) ys) xs ↔ Any (λ y → Any (flip P y) xs) ys
149
- swap↔ = inverse swap swap swap-invol swap-invol
145
+ swap↔ = mk↔′ swap swap swap-invol swap-invol
150
146
151
147
------------------------------------------------------------------------
152
148
-- Lemmas relating Any to ⊥
153
149
154
150
⊥↔Any⊥ : ⊥ ↔ Any (const ⊥) xs
155
- ⊥↔Any⊥ = inverse (λ ()) (λ p → from p) (λ ()) ( λ p → from p)
151
+ ⊥↔Any⊥ = mk↔′ (λ ()) (λ p → from p) (λ p → from p) ( λ () )
156
152
where
157
153
from : Any (const ⊥) xs → B
158
154
from (there p) = from p
159
155
160
156
⊥↔Any[] : ⊥ ↔ Any P []
161
- ⊥↔Any[] = inverse (λ ()) (λ ()) (λ ()) (λ ())
157
+ ⊥↔Any[] = mk↔′ (λ ()) (λ ()) (λ ()) (λ ())
162
158
163
159
------------------------------------------------------------------------
164
160
-- Lemmas relating Any to ⊤
165
161
166
162
-- These introduction and elimination rules are not inverses, though.
167
163
168
164
any⁺ : ∀ (p : A → Bool) → Any (T ∘ p) xs → T (any p xs)
169
- any⁺ p (here px) = Equivalence.from T-∨ ⟨$⟩ inj₁ px
165
+ any⁺ p (here px) = Equivalence.from T-∨ ( inj₁ px)
170
166
any⁺ p (there {x = x} pxs) with p x
171
167
... | true = _
172
168
... | false = any⁺ p pxs
173
169
174
170
any⁻ : ∀ (p : A → Bool) xs → T (any p xs) → Any (T ∘ p) xs
175
171
any⁻ p (x ∷ xs) px∷xs with p x | inspect p x
176
- ... | true | P.[ eq ] = here (Equivalence.from T-≡ ⟨$⟩ eq)
172
+ ... | true | P.[ eq ] = here (Equivalence.from T-≡ eq)
177
173
... | false | _ = there (any⁻ p xs px∷xs)
178
174
179
175
any⇔ : ∀ {p : A → Bool} → Any (T ∘ p) xs ⇔ T (any p xs)
180
- any⇔ = equivalence (any⁺ _) (any⁻ _ _)
176
+ any⇔ = mk⇔ (any⁺ _) (any⁻ _ _)
181
177
182
178
------------------------------------------------------------------------
183
179
-- Sums commute with Any
@@ -191,7 +187,7 @@ Any-⊎⁻ (here (inj₂ q)) = inj₂ (here q)
191
187
Any-⊎⁻ (there p) = Sum.map there there (Any-⊎⁻ p)
192
188
193
189
⊎↔ : (Any P xs ⊎ Any Q xs) ↔ Any (λ x → P x ⊎ Q x) xs
194
- ⊎↔ {P = P} {Q = Q} = inverse Any-⊎⁺ Any-⊎⁻ from∘to to ∘from
190
+ ⊎↔ {P = P} {Q = Q} = mk↔′ Any-⊎⁺ Any-⊎⁻ to ∘from from∘to
195
191
where
196
192
from∘to : (p : Any P xs ⊎ Any Q xs) → Any-⊎⁻ (Any-⊎⁺ p) ≡ p
197
193
from∘to (inj₁ (here p)) = refl
@@ -203,8 +199,8 @@ Any-⊎⁻ (there p) = Sum.map there there (Any-⊎⁻ p)
203
199
to∘from (here (inj₁ p)) = refl
204
200
to∘from (here (inj₂ q)) = refl
205
201
to∘from (there p) with Any-⊎⁻ p | to∘from p
206
- to∘from (there .(Any.map inj₁ p)) | inj₁ p | refl = refl
207
- to∘from (there .(Any.map inj₂ q)) | inj₂ q | refl = refl
202
+ ... | inj₁ p | refl = refl
203
+ ... | inj₂ q | refl = refl
208
204
209
205
------------------------------------------------------------------------
210
206
-- Products "commute" with Any.
@@ -219,7 +215,7 @@ Any-×⁻ pq with Prod.map₂ (Prod.map₂ find) (find pq)
219
215
220
216
×↔ : ∀ {xs ys} →
221
217
(Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs
222
- ×↔ {P = P} {Q = Q} {xs} {ys} = inverse Any-×⁺ Any-×⁻ from∘to to ∘from
218
+ ×↔ {P = P} {Q = Q} {xs} {ys} = mk↔′ Any-×⁺ Any-×⁻ to ∘from from∘to
223
219
where
224
220
open P.≡-Reasoning
225
221
@@ -258,8 +254,7 @@ Any-×⁻ pq with Prod.map₂ (Prod.map₂ find) (find pq)
258
254
259
255
260
256
to∘from : ∀ pq → Any-×⁺ {xs = xs} (Any-×⁻ pq) ≡ pq
261
- to∘from pq
262
- with find pq
257
+ to∘from pq with find pq
263
258
| (λ (f : (proj₁ (find pq) ≡_) ⋐ _) → map∘find pq {f})
264
259
... | (x , x∈xs , pq′) | lem₁
265
260
with find pq′
@@ -327,7 +322,7 @@ module _ {f : A → B} where
327
322
map⁻∘map⁺ P (there p) = P.cong there (map⁻∘map⁺ P p)
328
323
329
324
map↔ : Any (P ∘ f) xs ↔ Any P (List.map f xs)
330
- map↔ = inverse map⁺ map⁻ (map⁻∘map⁺ _) map⁺∘map⁻
325
+ map↔ = mk↔′ map⁺ map⁻ map⁺∘map⁻ (map⁻∘map⁺ _)
331
326
332
327
gmap : P ⋐ Q ∘ f → Any P ⋐ Any Q ∘ map f
333
328
gmap g = map⁺ ∘ Any.map g
@@ -376,7 +371,7 @@ module _ {P : A → Set p} where
376
371
++⁻∘++⁺ (x ∷ xs) (inj₂ p) rewrite ++⁻∘++⁺ xs (inj₂ p) = refl
377
372
378
373
++↔ : ∀ {xs ys} → (Any P xs ⊎ Any P ys) ↔ Any P (xs ++ ys)
379
- ++↔ {xs = xs} = inverse [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs) (++⁻ ∘++⁺ xs) (++⁺ ∘++⁻ xs)
374
+ ++↔ {xs = xs} = mk↔′ [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs) (++⁺ ∘++⁻ xs) (++⁻ ∘++⁺ xs)
380
375
381
376
++-comm : ∀ xs ys → Any P (xs ++ ys) → Any P (ys ++ xs)
382
377
++-comm xs ys = [ ++⁺ʳ ys , ++⁺ˡ ]′ ∘ ++⁻ xs
@@ -398,8 +393,8 @@ module _ {P : A → Set p} where
398
393
| ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₁ p) = refl
399
394
400
395
++↔++ : ∀ xs ys → Any P (xs ++ ys) ↔ Any P (ys ++ xs)
401
- ++↔++ xs ys = inverse (++-comm xs ys) (++-comm ys xs)
402
- (++-comm∘++-comm xs ) (++-comm∘++-comm ys)
396
+ ++↔++ xs ys = mk↔′ (++-comm xs ys) (++-comm ys xs)
397
+ (++-comm∘++-comm ys ) (++-comm∘++-comm xs)
403
398
404
399
++-insert : ∀ xs {ys} → P x → Any P (xs ++ [ x ] ++ ys)
405
400
++-insert xs Px = ++⁺ʳ xs (++⁺ˡ (singleton⁺ Px))
@@ -446,7 +441,7 @@ module _ {P : A → Set p} where
446
441
P.cong there $ concat⁻∘concat⁺ p
447
442
448
443
concat↔ : ∀ {xss} → Any (Any P) xss ↔ Any P (concat xss)
449
- concat↔ {xss} = inverse concat⁺ (concat⁻ xss) concat⁻∘concat⁺ (concat⁺∘concat⁻ xss)
444
+ concat↔ {xss} = mk↔′ concat⁺ (concat⁻ xss) (concat⁺∘concat⁻ xss) concat⁻∘concat⁺
450
445
451
446
------------------------------------------------------------------------
452
447
-- cartesianProductWith
@@ -496,18 +491,16 @@ applyUpTo⁻ f {suc n} (there p) with applyUpTo⁻ (f ∘ suc) p
496
491
------------------------------------------------------------------------
497
492
-- applyDownFrom
498
493
499
- module _ {P : A → Set p} where
500
-
501
- applyDownFrom⁺ : ∀ f {i n} → P (f i) → i < n → Any P (applyDownFrom f n)
502
- applyDownFrom⁺ f {i} {suc n} p (s≤s i≤n) with i ≟ n
503
- ... | yes P.refl = here p
504
- ... | no i≢n = there (applyDownFrom⁺ f p (≤∧≢⇒< i≤n i≢n))
494
+ applyDownFrom⁺ : ∀ f {i n} → P (f i) → i < n → Any P (applyDownFrom f n)
495
+ applyDownFrom⁺ f {i} {suc n} p (s≤s i≤n) with i ≟ n
496
+ ... | yes P.refl = here p
497
+ ... | no i≢n = there (applyDownFrom⁺ f p (≤∧≢⇒< i≤n i≢n))
505
498
506
- applyDownFrom⁻ : ∀ f {n} → Any P (applyDownFrom f n) →
507
- ∃ λ i → i < n × P (f i)
508
- applyDownFrom⁻ f {suc n} (here p) = n , ≤-refl , p
509
- applyDownFrom⁻ f {suc n} (there p) with applyDownFrom⁻ f p
510
- ... | i , i<n , pf = i , m<n⇒m<1+n i<n , pf
499
+ applyDownFrom⁻ : ∀ f {n} → Any P (applyDownFrom f n) →
500
+ ∃ λ i → i < n × P (f i)
501
+ applyDownFrom⁻ f {suc n} (here p) = n , ≤-refl , p
502
+ applyDownFrom⁻ f {suc n} (there p) with applyDownFrom⁻ f p
503
+ ... | i , i<n , pf = i , m<n⇒m<1+n i<n , pf
511
504
512
505
------------------------------------------------------------------------
513
506
-- tabulate
@@ -601,7 +594,7 @@ module _ {P : B → Set p} where
601
594
602
595
mapWith∈↔ : ∀ {xs : List A} {f : ∀ {x} → x ∈ xs → B} →
603
596
(∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) ↔ Any P (mapWith∈ xs f)
604
- mapWith∈↔ = inverse (mapWith∈⁺ _) (mapWith∈⁻ _ _) (from∘to _ ) (to∘ from _ _)
597
+ mapWith∈↔ = mk↔′ (mapWith∈⁺ _) (mapWith∈⁻ _ _) (to∘from _ _ ) (from∘to _)
605
598
where
606
599
from∘to : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B)
607
600
(p : ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) →
@@ -644,34 +637,30 @@ reverse⁻ ps with reverseAcc⁻ [] _ ps
644
637
------------------------------------------------------------------------
645
638
-- pure
646
639
647
- module _ {P : A → Set p} where
648
-
649
- pure⁺ : P x → Any P (pure x)
650
- pure⁺ = here
640
+ pure⁺ : P x → Any P (pure x)
641
+ pure⁺ = here
651
642
652
- pure⁻ : Any P (pure x) → P x
653
- pure⁻ (here p) = p
643
+ pure⁻ : Any P (pure x) → P x
644
+ pure⁻ (here p) = p
654
645
655
- pure⁺∘pure⁻ : (p : Any P (pure x)) → pure⁺ (pure⁻ p) ≡ p
656
- pure⁺∘pure⁻ (here p) = refl
646
+ pure⁺∘pure⁻ : (p : Any P (pure x)) → pure⁺ (pure⁻ p) ≡ p
647
+ pure⁺∘pure⁻ (here p) = refl
657
648
658
- pure⁻∘pure⁺ : (p : P x) → pure⁻ (pure⁺ p) ≡ p
659
- pure⁻∘pure⁺ p = refl
649
+ pure⁻∘pure⁺ : (p : P x) → pure⁻ {P = P} (pure⁺ p) ≡ p
650
+ pure⁻∘pure⁺ p = refl
660
651
661
- pure↔ : P x ↔ Any P (pure x)
662
- pure↔ = inverse pure⁺ pure⁻ pure⁻ ∘pure⁺ pure⁺ ∘pure⁻
652
+ pure↔ : P x ↔ Any P (pure x)
653
+ pure↔ {P = P} = mk↔′ pure⁺ pure⁻ pure⁺ ∘pure⁻ ( pure⁻ ∘pure⁺ {P = P})
663
654
664
655
------------------------------------------------------------------------
665
656
-- _∷_
666
657
667
- module _ (P : Pred A p) where
668
-
669
- ∷↔ : (P x ⊎ Any P xs) ↔ Any P (x ∷ xs)
670
- ∷↔ {x = x} {xs} =
671
- (P x ⊎ Any P xs) ↔⟨ pure↔ {P = P} ⊎-cong (Any P xs ∎) ⟩
672
- (Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩
673
- Any P (x ∷ xs) ∎
674
- where open Related.EquationalReasoning
658
+ ∷↔ : (P : Pred A p) → (P x ⊎ Any P xs) ↔ Any P (x ∷ xs)
659
+ ∷↔ {x = x} {xs} P =
660
+ (P x ⊎ Any P xs) ↔⟨ pure↔ ⊎-cong (Any P xs ∎) ⟩
661
+ (Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ ⟩
662
+ Any P (x ∷ xs) ∎
663
+ where open Related.EquationalReasoning
675
664
676
665
------------------------------------------------------------------------
677
666
-- _>>=_
@@ -695,16 +684,15 @@ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
695
684
Any (λ f → Any (Any P ∘ pure ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ ) (_ ∎) ⟩
696
685
Any (λ f → Any P (xs >>= pure ∘ f)) fs ↔⟨ >>=↔ ⟩
697
686
Any P (fs >>= λ f → xs >>= λ x → pure (f x)) ≡˘⟨ P.cong (Any P) (Listₑ.Applicative.unfold-⊛ fs xs) ⟩
698
- Any P (fs ⊛ xs) ∎
687
+ Any P (fs ⊛ xs) ∎
699
688
where open Related.EquationalReasoning
700
689
690
+
701
691
-- An alternative introduction rule for _⊛_
702
692
703
- ⊛⁺′ : ∀ {P : A → Set ℓ} {Q : B → Set ℓ} {fs : List (A → B)} {xs} →
693
+ ⊛⁺′ : ∀ {P : Pred A ℓ} {Q : Pred B ℓ} {fs : List (A → B)} {xs} →
704
694
Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs)
705
- ⊛⁺′ pq p =
706
- Inverse.to ⊛↔ ⟨$⟩
707
- Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq
695
+ ⊛⁺′ pq p = Inverse.to ⊛↔ (Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq)
708
696
709
697
------------------------------------------------------------------------
710
698
-- _⊗_
0 commit comments