@@ -45,7 +45,6 @@ open import Relation.Unary as U
45
45
using (Pred; _⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_)
46
46
open import Relation.Nullary using (¬_; _because_; does; ofʸ; ofⁿ)
47
47
open import Relation.Nullary.Negation using (contradiction; ¬?; decidable-stable)
48
- open Related.EquationalReasoning
49
48
50
49
private
51
50
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
@@ -98,6 +97,7 @@ module _ {k : Kind} {P : Pred A p} {Q : Pred A q} where
98
97
(∃ λ x → x ∈ xs × P x) ∼⟨ Σ.cong Inv.id (xs≈ys ×-cong P↔Q _) ⟩
99
98
(∃ λ x → x ∈ ys × Q x) ↔⟨ Any↔ ⟩
100
99
Any Q ys ∎
100
+ where open Related.EquationalReasoning
101
101
102
102
------------------------------------------------------------------------
103
103
-- map
@@ -230,13 +230,40 @@ module _ {P : Pred A p} {Q : Pred B q} where
230
230
(Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs
231
231
×↔ {xs} {ys} = inverse Any-×⁺ Any-×⁻ from∘to to∘from
232
232
where
233
+ open P.≡-Reasoning
234
+
233
235
from∘to : ∀ pq → Any-×⁻ (Any-×⁺ pq) ≡ pq
234
- from∘to (p , q) rewrite
235
- find∘map p (λ p → Any.map (λ q → (p , q)) q)
236
- | find∘map q (λ q → proj₂ (proj₂ (find p)) , q)
237
- | lose∘find p
238
- | lose∘find q
239
- = refl
236
+ from∘to (p , q) =
237
+
238
+ Any-×⁻ (Any-×⁺ (p , q))
239
+
240
+ ≡⟨⟩
241
+
242
+ (let (x , x∈xs , pq) = find (Any-×⁺ (p , q))
243
+ (y , y∈ys , p , q) = find pq
244
+ in lose x∈xs p , lose y∈ys q)
245
+
246
+ ≡⟨ P.cong (λ • → let (x , x∈xs , pq) = •
247
+ (y , y∈ys , p , q) = find pq
248
+ in lose x∈xs p , lose y∈ys q)
249
+ (find∘map p (λ p → Any.map (p ,_) q)) ⟩
250
+
251
+ (let (x , x∈xs , p) = find p
252
+ (y , y∈ys , p , q) = find (Any.map (p ,_) q)
253
+ in lose x∈xs p , lose y∈ys q)
254
+
255
+ ≡⟨ P.cong (λ • → let (x , x∈xs , p) = find p
256
+ (y , y∈ys , p , q) = •
257
+ in lose x∈xs p , lose y∈ys q)
258
+ (find∘map q (proj₂ (proj₂ (find p)) ,_)) ⟩
259
+
260
+ (let (x , x∈xs , p) = find p
261
+ (y , y∈ys , q) = find q
262
+ in lose x∈xs p , lose y∈ys q)
263
+
264
+ ≡⟨ P.cong₂ _,_ (lose∘find p) (lose∘find q) ⟩
265
+
266
+ (p , q) ∎
240
267
241
268
to∘from : ∀ pq → Any-×⁺ {xs} (Any-×⁻ pq) ≡ pq
242
269
to∘from pq
@@ -593,6 +620,7 @@ module _ (P : Pred A p) where
593
620
(P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩
594
621
(Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩
595
622
Any P (x ∷ xs) ∎
623
+ where open Related.EquationalReasoning
596
624
597
625
------------------------------------------------------------------------
598
626
-- _>>=_
@@ -604,6 +632,7 @@ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
604
632
Any (Any P ∘ f) xs ↔⟨ map↔ ⟩
605
633
Any (Any P) (List.map f xs) ↔⟨ concat↔ ⟩
606
634
Any P (xs >>= f) ∎
635
+ where open Related.EquationalReasoning
607
636
608
637
------------------------------------------------------------------------
609
638
-- _⊛_
@@ -615,6 +644,7 @@ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
615
644
Any (λ f → Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ ) (_ ∎) ⟩
616
645
Any (λ f → Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ ⟩
617
646
Any P (fs ⊛ xs) ∎
647
+ where open Related.EquationalReasoning
618
648
619
649
-- An alternative introduction rule for _⊛_
620
650
@@ -634,10 +664,12 @@ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
634
664
Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩
635
665
Any (λ x, → Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩
636
666
Any P (xs ⊗ ys) ∎
667
+ where open Related.EquationalReasoning
637
668
638
669
⊗↔′ : {P : A → Set ℓ} {Q : B → Set ℓ} {xs : List A} {ys : List B} →
639
670
(Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys)
640
671
⊗↔′ {P = P} {Q} {xs} {ys} =
641
672
(Any P xs × Any Q ys) ↔⟨ ×↔ ⟩
642
673
Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩
643
674
Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎
675
+ where open Related.EquationalReasoning
0 commit comments