Skip to content

Commit 1e48171

Browse files
authored
Get rid of slow 'rewrite' in Data.List.Relation.Unary.Any.Properties (#1101)
1 parent 7e1d1eb commit 1e48171

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

src/Data/List/Relation/Unary/Any/Properties.agda

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ open import Relation.Unary as U
4545
using (Pred; _⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_)
4646
open import Relation.Nullary using (¬_; _because_; does; ofʸ; ofⁿ)
4747
open import Relation.Nullary.Negation using (contradiction; ¬?; decidable-stable)
48-
open Related.EquationalReasoning
4948

5049
private
5150
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
@@ -98,6 +97,7 @@ module _ {k : Kind} {P : Pred A p} {Q : Pred A q} where
9897
(∃ λ x x ∈ xs × P x) ∼⟨ Σ.cong Inv.id (xs≈ys ×-cong P↔Q _) ⟩
9998
(∃ λ x x ∈ ys × Q x) ↔⟨ Any↔ ⟩
10099
Any Q ys ∎
100+
where open Related.EquationalReasoning
101101

102102
------------------------------------------------------------------------
103103
-- map
@@ -230,13 +230,40 @@ module _ {P : Pred A p} {Q : Pred B q} where
230230
(Any P xs × Any Q ys) ↔ Any (λ x Any (λ y P x × Q y) ys) xs
231231
×↔ {xs} {ys} = inverse Any-×⁺ Any-×⁻ from∘to to∘from
232232
where
233+
open P.≡-Reasoning
234+
233235
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) ∎
240267

241268
to∘from : pq Any-×⁺ {xs} (Any-×⁻ pq) ≡ pq
242269
to∘from pq
@@ -593,6 +620,7 @@ module _ (P : Pred A p) where
593620
(P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩
594621
(Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩
595622
Any P (x ∷ xs) ∎
623+
where open Related.EquationalReasoning
596624

597625
------------------------------------------------------------------------
598626
-- _>>=_
@@ -604,6 +632,7 @@ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
604632
Any (Any P ∘ f) xs ↔⟨ map↔ ⟩
605633
Any (Any P) (List.map f xs) ↔⟨ concat↔ ⟩
606634
Any P (xs >>= f) ∎
635+
where open Related.EquationalReasoning
607636

608637
------------------------------------------------------------------------
609638
-- _⊛_
@@ -615,6 +644,7 @@ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
615644
Any (λ f Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ >>=↔ ) (_ ∎) ⟩
616645
Any (λ f Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ ⟩
617646
Any P (fs ⊛ xs) ∎
647+
where open Related.EquationalReasoning
618648

619649
-- An alternative introduction rule for _⊛_
620650

@@ -634,10 +664,12 @@ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
634664
Any (λ _,_ Any (λ x Any (λ y P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩
635665
Any (λ x, Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩
636666
Any P (xs ⊗ ys) ∎
667+
where open Related.EquationalReasoning
637668

638669
⊗↔′ : {P : A Set ℓ} {Q : B Set ℓ} {xs : List A} {ys : List B}
639670
(Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys)
640671
⊗↔′ {P = P} {Q} {xs} {ys} =
641672
(Any P xs × Any Q ys) ↔⟨ ×↔ ⟩
642673
Any (λ x Any (λ y P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩
643674
Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎
675+
where open Related.EquationalReasoning

0 commit comments

Comments
 (0)