Search is not available for this dataset
text
string
meta
dict
------------------------------------------------------------------------ -- The Agda standard library -- -- List-related properties ------------------------------------------------------------------------ -- Note that the lemmas below could be generalised to work with other -- equalities than _≡_. {-# OPTIONS --without-K --safe #-} module Data.List.Properties where open import Algebra import Algebra.Structures as Structures import Algebra.FunctionProperties as FunctionProperties open import Data.Bool.Base using (Bool; false; true; not; if_then_else_) open import Data.Fin using (Fin; zero; suc; cast; toℕ) open import Data.List as List open import Data.List.Relation.Unary.All using (All; []; _∷_) open import Data.List.Relation.Unary.Any using (Any; here; there) open import Data.Maybe.Base using (Maybe; just; nothing) open import Data.Nat open import Data.Nat.Properties open import Data.Product as Prod hiding (map; zip) open import Data.These as These using (These; this; that; these) open import Function import Relation.Binary as B import Relation.Binary.Reasoning.Setoid as EqR open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; _≗_; refl ; sym ; cong) open import Relation.Nullary using (¬_; yes; no) open import Relation.Nullary.Negation using (contradiction) open import Relation.Nullary.Decidable using (⌊_⌋) open import Relation.Unary using (Pred; Decidable; ∁) open import Relation.Unary.Properties using (∁?) ------------------------------------------------------------------------ -- _∷_ module _ {a} {A : Set a} {x y : A} {xs ys : List A} where ∷-injective : x ∷ xs ≡ y List.∷ ys → x ≡ y × xs ≡ ys ∷-injective refl = (refl , refl) ∷-injectiveˡ : x ∷ xs ≡ y List.∷ ys → x ≡ y ∷-injectiveˡ refl = refl ∷-injectiveʳ : x ∷ xs ≡ y List.∷ ys → xs ≡ ys ∷-injectiveʳ refl = refl module _ {a} {A : Set a} where ≡-dec : B.Decidable _≡_ → B.Decidable {A = List A} _≡_ ≡-dec _≟_ [] [] = yes refl ≡-dec _≟_ (x ∷ xs) [] = no λ() ≡-dec _≟_ [] (y ∷ ys) = no λ() ≡-dec _≟_ (x ∷ xs) (y ∷ ys) with x ≟ y | ≡-dec _≟_ xs ys ... | no x≢y | _ = no (x≢y ∘ ∷-injectiveˡ) ... | yes _ | no xs≢ys = no (xs≢ys ∘ ∷-injectiveʳ) ... | yes refl | yes refl = yes refl ------------------------------------------------------------------------ -- map module _ {a} {A : Set a} where map-id : map id ≗ id {A = List A} map-id [] = refl map-id (x ∷ xs) = P.cong (x ∷_) (map-id xs) map-id₂ : ∀ {f : A → A} {xs} → All (λ x → f x ≡ x) xs → map f xs ≡ xs map-id₂ [] = refl map-id₂ (fx≡x ∷ pxs) = P.cong₂ _∷_ fx≡x (map-id₂ pxs) module _ {a b} {A : Set a} {B : Set b} where map-++-commute : ∀ (f : A → B) xs ys → map f (xs ++ ys) ≡ map f xs ++ map f ys map-++-commute f [] ys = refl map-++-commute f (x ∷ xs) ys = P.cong (f x ∷_) (map-++-commute f xs ys) map-cong : ∀ {f g : A → B} → f ≗ g → map f ≗ map g map-cong f≗g [] = refl map-cong f≗g (x ∷ xs) = P.cong₂ _∷_ (f≗g x) (map-cong f≗g xs) map-cong₂ : ∀ {f g : A → B} {xs} → All (λ x → f x ≡ g x) xs → map f xs ≡ map g xs map-cong₂ [] = refl map-cong₂ (fx≡gx ∷ fxs≡gxs) = P.cong₂ _∷_ fx≡gx (map-cong₂ fxs≡gxs) length-map : ∀ (f : A → B) xs → length (map f xs) ≡ length xs length-map f [] = refl length-map f (x ∷ xs) = P.cong suc (length-map f xs) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where map-compose : {g : B → C} {f : A → B} → map (g ∘ f) ≗ map g ∘ map f map-compose [] = refl map-compose (x ∷ xs) = P.cong (_ ∷_) (map-compose xs) ------------------------------------------------------------------------ -- mapMaybe module _ {a} {A : Set a} where mapMaybe-just : (xs : List A) → mapMaybe just xs ≡ xs mapMaybe-just [] = refl mapMaybe-just (x ∷ xs) = P.cong (x ∷_) (mapMaybe-just xs) mapMaybe-nothing : (xs : List A) → mapMaybe {B = A} (λ _ → nothing) xs ≡ [] mapMaybe-nothing [] = refl mapMaybe-nothing (x ∷ xs) = mapMaybe-nothing xs module _ {a b} {A : Set a} {B : Set b} (f : A → Maybe B) where mapMaybe-concatMap : mapMaybe f ≗ concatMap (fromMaybe ∘ f) mapMaybe-concatMap [] = refl mapMaybe-concatMap (x ∷ xs) with f x ... | just y = P.cong (y ∷_) (mapMaybe-concatMap xs) ... | nothing = mapMaybe-concatMap xs length-mapMaybe : ∀ xs → length (mapMaybe f xs) ≤ length xs length-mapMaybe [] = z≤n length-mapMaybe (x ∷ xs) with f x ... | just y = s≤s (length-mapMaybe xs) ... | nothing = ≤-step (length-mapMaybe xs) ------------------------------------------------------------------------ -- _++_ module _ {a} {A : Set a} where length-++ : ∀ (xs : List A) {ys} → length (xs ++ ys) ≡ length xs + length ys length-++ [] = refl length-++ (x ∷ xs) = P.cong suc (length-++ xs) open FunctionProperties {A = List A} _≡_ ++-assoc : Associative _++_ ++-assoc [] ys zs = refl ++-assoc (x ∷ xs) ys zs = P.cong (x ∷_) (++-assoc xs ys zs) ++-identityˡ : LeftIdentity [] _++_ ++-identityˡ xs = refl ++-identityʳ : RightIdentity [] _++_ ++-identityʳ [] = refl ++-identityʳ (x ∷ xs) = P.cong (x ∷_) (++-identityʳ xs) ++-identity : Identity [] _++_ ++-identity = ++-identityˡ , ++-identityʳ ++-identityʳ-unique : ∀ (xs : List A) {ys} → xs ≡ xs ++ ys → ys ≡ [] ++-identityʳ-unique [] refl = refl ++-identityʳ-unique (x ∷ xs) eq = ++-identityʳ-unique xs (proj₂ (∷-injective eq)) ++-identityˡ-unique : ∀ {xs} (ys : List A) → xs ≡ ys ++ xs → ys ≡ [] ++-identityˡ-unique [] _ = refl ++-identityˡ-unique {xs = []} (y ∷ ys) () ++-identityˡ-unique {xs = x ∷ xs} (y ∷ ys) eq with ++-identityˡ-unique (ys ++ [ x ]) (begin xs ≡⟨ proj₂ (∷-injective eq) ⟩ ys ++ x ∷ xs ≡⟨ P.sym (++-assoc ys [ x ] xs) ⟩ (ys ++ [ x ]) ++ xs ∎) where open P.≡-Reasoning ++-identityˡ-unique {xs = x ∷ xs} (y ∷ [] ) eq | () ++-identityˡ-unique {xs = x ∷ xs} (y ∷ _ ∷ _) eq | () ++-cancelˡ : ∀ xs {ys zs : List A} → xs ++ ys ≡ xs ++ zs → ys ≡ zs ++-cancelˡ [] ys≡zs = ys≡zs ++-cancelˡ (x ∷ xs) x∷xs++ys≡x∷xs++zs = ++-cancelˡ xs (∷-injectiveʳ x∷xs++ys≡x∷xs++zs) ++-cancelʳ : ∀ {xs} ys zs → ys ++ xs ≡ zs ++ xs → ys ≡ zs ++-cancelʳ [] [] _ = refl ++-cancelʳ {xs} [] (z ∷ zs) eq = contradiction (P.trans (cong length eq) (length-++ (z ∷ zs))) (m≢1+n+m (length xs)) ++-cancelʳ {xs} (y ∷ ys) [] eq = contradiction (P.trans (P.sym (length-++ (y ∷ ys))) (cong length eq)) (m≢1+n+m (length xs) ∘ sym) ++-cancelʳ (y ∷ ys) (z ∷ zs) eq = P.cong₂ _∷_ (∷-injectiveˡ eq) (++-cancelʳ ys zs (∷-injectiveʳ eq)) ++-cancel : Cancellative _++_ ++-cancel = ++-cancelˡ , ++-cancelʳ ++-conicalˡ : ∀ (xs ys : List A) → xs ++ ys ≡ [] → xs ≡ [] ++-conicalˡ [] _ refl = refl ++-conicalˡ (x ∷ xs) _ () ++-conicalʳ : ∀ (xs ys : List A) → xs ++ ys ≡ [] → ys ≡ [] ++-conicalʳ [] _ refl = refl ++-conicalʳ (x ∷ xs) _ () ++-conical : Conical [] _++_ ++-conical = ++-conicalˡ , ++-conicalʳ module _ {a} {A : Set a} where open Structures {A = List A} _≡_ ++-isMagma : IsMagma _++_ ++-isMagma = record { isEquivalence = P.isEquivalence ; ∙-cong = P.cong₂ _++_ } ++-isSemigroup : IsSemigroup _++_ ++-isSemigroup = record { isMagma = ++-isMagma ; assoc = ++-assoc } ++-isMonoid : IsMonoid _++_ [] ++-isMonoid = record { isSemigroup = ++-isSemigroup ; identity = ++-identity } module _ {a} (A : Set a) where ++-semigroup : Semigroup a a ++-semigroup = record { Carrier = List A ; isSemigroup = ++-isSemigroup } ++-monoid : Monoid a a ++-monoid = record { Carrier = List A ; isMonoid = ++-isMonoid } ------------------------------------------------------------------------ -- alignWith module _ {a b c} {A : Set a} {B : Set b} {C : Set c} {f g : These A B → C} where alignWith-cong : f ≗ g → ∀ as → alignWith f as ≗ alignWith g as alignWith-cong f≗g [] bs = map-cong (f≗g ∘ that) bs alignWith-cong f≗g as@(_ ∷ _) [] = map-cong (f≗g ∘ this) as alignWith-cong f≗g (a ∷ as) (b ∷ bs) = P.cong₂ _∷_ (f≗g (these a b)) (alignWith-cong f≗g as bs) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : These A B → C) where length-alignWith : ∀ xs ys → length (alignWith f xs ys) ≡ length xs ⊔ length ys length-alignWith [] ys = length-map (f ∘′ that) ys length-alignWith xs@(_ ∷ _) [] = length-map (f ∘′ this) xs length-alignWith (x ∷ xs) (y ∷ ys) = P.cong suc (length-alignWith xs ys) alignWith-map : ∀ {d e} {D : Set d} {E : Set e} (g : D → A) (h : E → B) → ∀ xs ys → alignWith f (map g xs) (map h ys) ≡ alignWith (f ∘′ These.map g h) xs ys alignWith-map g h [] ys = sym (map-compose ys) alignWith-map g h xs@(_ ∷ _) [] = sym (map-compose xs) alignWith-map g h (x ∷ xs) (y ∷ ys) = P.cong₂ _∷_ refl (alignWith-map g h xs ys) map-alignWith : ∀ {d} {D : Set d} (g : C → D) → ∀ xs ys → map g (alignWith f xs ys) ≡ alignWith (g ∘′ f) xs ys map-alignWith g [] ys = sym (map-compose ys) map-alignWith g xs@(_ ∷ _) [] = sym (map-compose xs) map-alignWith g (x ∷ xs) (y ∷ ys) = P.cong₂ _∷_ refl (map-alignWith g xs ys) ------------------------------------------------------------------------ -- zipWith module _ {a b} {A : Set a} {B : Set b} (f : A → A → B) where zipWith-comm : (∀ x y → f x y ≡ f y x) → ∀ xs ys → zipWith f xs ys ≡ zipWith f ys xs zipWith-comm f-comm [] [] = refl zipWith-comm f-comm [] (x ∷ ys) = refl zipWith-comm f-comm (x ∷ xs) [] = refl zipWith-comm f-comm (x ∷ xs) (y ∷ ys) = P.cong₂ _∷_ (f-comm x y) (zipWith-comm f-comm xs ys) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B → C) where zipWith-identityˡ : ∀ xs → zipWith f [] xs ≡ [] zipWith-identityˡ [] = refl zipWith-identityˡ (x ∷ xs) = refl zipWith-identityʳ : ∀ xs → zipWith f xs [] ≡ [] zipWith-identityʳ [] = refl zipWith-identityʳ (x ∷ xs) = refl length-zipWith : ∀ xs ys → length (zipWith f xs ys) ≡ length xs ⊓ length ys length-zipWith [] [] = refl length-zipWith [] (y ∷ ys) = refl length-zipWith (x ∷ xs) [] = refl length-zipWith (x ∷ xs) (y ∷ ys) = P.cong suc (length-zipWith xs ys) zipWith-map : ∀ {d e} {D : Set d} {E : Set e} (g : D → A) (h : E → B) → ∀ xs ys → zipWith f (map g xs) (map h ys) ≡ zipWith (λ x y → f (g x) (h y)) xs ys zipWith-map g h [] [] = refl zipWith-map g h [] (y ∷ ys) = refl zipWith-map g h (x ∷ xs) [] = refl zipWith-map g h (x ∷ xs) (y ∷ ys) = P.cong₂ _∷_ refl (zipWith-map g h xs ys) map-zipWith : ∀ {d} {D : Set d} (g : C → D) → ∀ xs ys → map g (zipWith f xs ys) ≡ zipWith (λ x y → g (f x y)) xs ys map-zipWith g [] [] = refl map-zipWith g [] (y ∷ ys) = refl map-zipWith g (x ∷ xs) [] = refl map-zipWith g (x ∷ xs) (y ∷ ys) = P.cong₂ _∷_ refl (map-zipWith g xs ys) ------------------------------------------------------------------------ -- unalignWith module _ {a b} {A : Set a} {B : Set b} where unalignWith-this : unalignWith ((A → These A B) ∋ this) ≗ (_, []) unalignWith-this [] = refl unalignWith-this (a ∷ as) = P.cong (Prod.map₁ (a ∷_)) (unalignWith-this as) unalignWith-that : unalignWith ((B → These A B) ∋ that) ≗ ([] ,_) unalignWith-that [] = refl unalignWith-that (b ∷ bs) = P.cong (Prod.map₂ (b ∷_)) (unalignWith-that bs) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} {f g : C → These A B} where unalignWith-cong : f ≗ g → unalignWith f ≗ unalignWith g unalignWith-cong f≗g [] = refl unalignWith-cong f≗g (c ∷ cs) with f c | g c | f≗g c ... | this a | ._ | refl = P.cong (Prod.map₁ (a ∷_)) (unalignWith-cong f≗g cs) ... | that b | ._ | refl = P.cong (Prod.map₂ (b ∷_)) (unalignWith-cong f≗g cs) ... | these a b | ._ | refl = P.cong (Prod.map (a ∷_) (b ∷_)) (unalignWith-cong f≗g cs) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : C → These A B) where unalignWith-map : ∀ {d} {D : Set d} (g : D → C) → ∀ ds → unalignWith f (map g ds) ≡ unalignWith (f ∘′ g) ds unalignWith-map g [] = refl unalignWith-map g (d ∷ ds) with f (g d) ... | this a = P.cong (Prod.map₁ (a ∷_)) (unalignWith-map g ds) ... | that b = P.cong (Prod.map₂ (b ∷_)) (unalignWith-map g ds) ... | these a b = P.cong (Prod.map (a ∷_) (b ∷_)) (unalignWith-map g ds) map-unalignWith : ∀ {d e} {D : Set d} {E : Set e} (g : A → D) (h : B → E) → Prod.map (map g) (map h) ∘′ unalignWith f ≗ unalignWith (These.map g h ∘′ f) map-unalignWith g h [] = refl map-unalignWith g h (c ∷ cs) with f c ... | this a = P.cong (Prod.map₁ (g a ∷_)) (map-unalignWith g h cs) ... | that b = P.cong (Prod.map₂ (h b ∷_)) (map-unalignWith g h cs) ... | these a b = P.cong (Prod.map (g a ∷_) (h b ∷_)) (map-unalignWith g h cs) unalignWith-alignWith : (g : These A B → C) → f ∘′ g ≗ id → ∀ as bs → unalignWith f (alignWith g as bs) ≡ (as , bs) unalignWith-alignWith g g∘f≗id [] bs = begin unalignWith f (map (g ∘′ that) bs) ≡⟨ unalignWith-map (g ∘′ that) bs ⟩ unalignWith (f ∘′ g ∘′ that) bs ≡⟨ unalignWith-cong (g∘f≗id ∘ that) bs ⟩ unalignWith that bs ≡⟨ unalignWith-that bs ⟩ [] , bs ∎ where open P.≡-Reasoning unalignWith-alignWith g g∘f≗id as@(_ ∷ _) [] = begin unalignWith f (map (g ∘′ this) as) ≡⟨ unalignWith-map (g ∘′ this) as ⟩ unalignWith (f ∘′ g ∘′ this) as ≡⟨ unalignWith-cong (g∘f≗id ∘ this) as ⟩ unalignWith this as ≡⟨ unalignWith-this as ⟩ as , [] ∎ where open P.≡-Reasoning unalignWith-alignWith g g∘f≗id (a ∷ as) (b ∷ bs) rewrite g∘f≗id (these a b) = let ih = unalignWith-alignWith g g∘f≗id as bs in P.cong (Prod.map (a ∷_) (b ∷_)) ih ------------------------------------------------------------------------ -- unzipWith module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B × C) where length-unzipWith₁ : ∀ xys → length (proj₁ (unzipWith f xys)) ≡ length xys length-unzipWith₁ [] = refl length-unzipWith₁ (x ∷ xys) = P.cong suc (length-unzipWith₁ xys) length-unzipWith₂ : ∀ xys → length (proj₂ (unzipWith f xys)) ≡ length xys length-unzipWith₂ [] = refl length-unzipWith₂ (x ∷ xys) = P.cong suc (length-unzipWith₂ xys) zipWith-unzipWith : (g : B → C → A) → uncurry′ g ∘ f ≗ id → uncurry′ (zipWith g) ∘ (unzipWith f) ≗ id zipWith-unzipWith g f∘g≗id [] = refl zipWith-unzipWith g f∘g≗id (x ∷ xs) = P.cong₂ _∷_ (f∘g≗id x) (zipWith-unzipWith g f∘g≗id xs) ------------------------------------------------------------------------ -- foldr foldr-universal : ∀ {a b} {A : Set a} {B : Set b} (h : List A → B) f e → (h [] ≡ e) → (∀ x xs → h (x ∷ xs) ≡ f x (h xs)) → h ≗ foldr f e foldr-universal h f e base step [] = base foldr-universal h f e base step (x ∷ xs) = begin h (x ∷ xs) ≡⟨ step x xs ⟩ f x (h xs) ≡⟨ P.cong (f x) (foldr-universal h f e base step xs) ⟩ f x (foldr f e xs) ∎ where open P.≡-Reasoning foldr-cong : ∀ {a b} {A : Set a} {B : Set b} {f g : A → B → B} {d e : B} → (∀ x y → f x y ≡ g x y) → d ≡ e → foldr f d ≗ foldr g e foldr-cong f≗g refl [] = refl foldr-cong f≗g d≡e (x ∷ xs) rewrite foldr-cong f≗g d≡e xs = f≗g x _ foldr-fusion : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} (h : B → C) {f : A → B → B} {g : A → C → C} (e : B) → (∀ x y → h (f x y) ≡ g x (h y)) → h ∘ foldr f e ≗ foldr g (h e) foldr-fusion h {f} {g} e fuse = foldr-universal (h ∘ foldr f e) g (h e) refl (λ x xs → fuse x (foldr f e xs)) id-is-foldr : ∀ {a} {A : Set a} → id {A = List A} ≗ foldr _∷_ [] id-is-foldr = foldr-universal id _∷_ [] refl (λ _ _ → refl) ++-is-foldr : ∀ {a} {A : Set a} (xs ys : List A) → xs ++ ys ≡ foldr _∷_ ys xs ++-is-foldr xs ys = begin xs ++ ys ≡⟨ P.cong (_++ ys) (id-is-foldr xs) ⟩ foldr _∷_ [] xs ++ ys ≡⟨ foldr-fusion (_++ ys) [] (λ _ _ → refl) xs ⟩ foldr _∷_ ([] ++ ys) xs ≡⟨⟩ foldr _∷_ ys xs ∎ where open P.≡-Reasoning module _ {a b} {A : Set a} {B : Set b} where foldr-++ : ∀ (f : A → B → B) x ys zs → foldr f x (ys ++ zs) ≡ foldr f (foldr f x zs) ys foldr-++ f x [] zs = refl foldr-++ f x (y ∷ ys) zs = P.cong (f y) (foldr-++ f x ys zs) map-is-foldr : {f : A → B} → map f ≗ foldr (λ x ys → f x ∷ ys) [] map-is-foldr {f = f} = begin map f ≈⟨ P.cong (map f) ∘ id-is-foldr ⟩ map f ∘ foldr _∷_ [] ≈⟨ foldr-fusion (map f) [] (λ _ _ → refl) ⟩ foldr (λ x ys → f x ∷ ys) [] ∎ where open EqR (P._→-setoid_ _ _) foldr-∷ʳ : ∀ (f : A → B → B) x y ys → foldr f x (ys ∷ʳ y) ≡ foldr f (f y x) ys foldr-∷ʳ f x y [] = refl foldr-∷ʳ f x y (z ∷ ys) = P.cong (f z) (foldr-∷ʳ f x y ys) ------------------------------------------------------------------------ -- foldl module _ {a b} {A : Set a} {B : Set b} where foldl-++ : ∀ (f : A → B → A) x ys zs → foldl f x (ys ++ zs) ≡ foldl f (foldl f x ys) zs foldl-++ f x [] zs = refl foldl-++ f x (y ∷ ys) zs = foldl-++ f (f x y) ys zs foldl-∷ʳ : ∀ (f : A → B → A) x y ys → foldl f x (ys ∷ʳ y) ≡ f (foldl f x ys) y foldl-∷ʳ f x y [] = refl foldl-∷ʳ f x y (z ∷ ys) = foldl-∷ʳ f (f x z) y ys ------------------------------------------------------------------------ -- concat module _ {a b} {A : Set a} {B : Set b} where concat-map : ∀ {f : A → B} → concat ∘ map (map f) ≗ map f ∘ concat concat-map {f = f} = begin concat ∘ map (map f) ≈⟨ P.cong concat ∘ map-is-foldr ⟩ concat ∘ foldr (λ xs → map f xs ∷_) [] ≈⟨ foldr-fusion concat [] (λ _ _ → refl) ⟩ foldr (λ ys → map f ys ++_) [] ≈⟨ P.sym ∘ foldr-fusion (map f) [] (map-++-commute f) ⟩ map f ∘ concat ∎ where open EqR (P._→-setoid_ _ _) ------------------------------------------------------------------------ -- sum sum-++-commute : ∀ xs ys → sum (xs ++ ys) ≡ sum xs + sum ys sum-++-commute [] ys = refl sum-++-commute (x ∷ xs) ys = begin x + sum (xs ++ ys) ≡⟨ P.cong (x +_) (sum-++-commute xs ys) ⟩ x + (sum xs + sum ys) ≡⟨ P.sym (+-assoc x _ _) ⟩ (x + sum xs) + sum ys ∎ where open P.≡-Reasoning ------------------------------------------------------------------------ -- replicate module _ {a} {A : Set a} where length-replicate : ∀ n {x : A} → length (replicate n x) ≡ n length-replicate zero = refl length-replicate (suc n) = P.cong suc (length-replicate n) ------------------------------------------------------------------------ -- scanr module _ {a b} {A : Set a} {B : Set b} where scanr-defn : ∀ (f : A → B → B) (e : B) → scanr f e ≗ map (foldr f e) ∘ tails scanr-defn f e [] = refl scanr-defn f e (x ∷ []) = refl scanr-defn f e (x ∷ y ∷ xs) with scanr f e (y ∷ xs) | scanr-defn f e (y ∷ xs) ... | [] | () ... | z ∷ zs | eq with ∷-injective eq ... | z≡fy⦇f⦈xs , _ = P.cong₂ (λ z → f x z ∷_) z≡fy⦇f⦈xs eq ------------------------------------------------------------------------ -- scanl module _ {a b} {A : Set a} {B : Set b} where scanl-defn : ∀ (f : A → B → A) (e : A) → scanl f e ≗ map (foldl f e) ∘ inits scanl-defn f e [] = refl scanl-defn f e (x ∷ xs) = P.cong (e ∷_) (begin scanl f (f e x) xs ≡⟨ scanl-defn f (f e x) xs ⟩ map (foldl f (f e x)) (inits xs) ≡⟨ refl ⟩ map (foldl f e ∘ (x ∷_)) (inits xs) ≡⟨ map-compose (inits xs) ⟩ map (foldl f e) (map (x ∷_) (inits xs)) ∎) where open P.≡-Reasoning ------------------------------------------------------------------------ -- applyUpTo module _ {a} {A : Set a} where length-applyUpTo : ∀ (f : ℕ → A) n → length (applyUpTo f n) ≡ n length-applyUpTo f zero = refl length-applyUpTo f (suc n) = P.cong suc (length-applyUpTo (f ∘ suc) n) lookup-applyUpTo : ∀ (f : ℕ → A) n i → lookup (applyUpTo f n) i ≡ f (toℕ i) lookup-applyUpTo f zero () lookup-applyUpTo f (suc n) zero = refl lookup-applyUpTo f (suc n) (suc i) = lookup-applyUpTo (f ∘ suc) n i ------------------------------------------------------------------------ -- applyUpTo module _ {a} {A : Set a} (f : ℕ → A) where length-applyDownFrom : ∀ n → length (applyDownFrom f n) ≡ n length-applyDownFrom zero = refl length-applyDownFrom (suc n) = P.cong suc (length-applyDownFrom n) lookup-applyDownFrom : ∀ n i → lookup (applyDownFrom f n) i ≡ f (n ∸ (suc (toℕ i))) lookup-applyDownFrom zero () lookup-applyDownFrom (suc n) zero = refl lookup-applyDownFrom (suc n) (suc i) = lookup-applyDownFrom n i ------------------------------------------------------------------------ -- upTo length-upTo : ∀ n → length (upTo n) ≡ n length-upTo = length-applyUpTo id lookup-upTo : ∀ n i → lookup (upTo n) i ≡ toℕ i lookup-upTo = lookup-applyUpTo id ------------------------------------------------------------------------ -- downFrom length-downFrom : ∀ n → length (downFrom n) ≡ n length-downFrom = length-applyDownFrom id lookup-downFrom : ∀ n i → lookup (downFrom n) i ≡ n ∸ (suc (toℕ i)) lookup-downFrom = lookup-applyDownFrom id ------------------------------------------------------------------------ -- tabulate module _ {a} {A : Set a} where tabulate-cong : ∀ {n} {f g : Fin n → A} → f ≗ g → tabulate f ≡ tabulate g tabulate-cong {zero} p = P.refl tabulate-cong {suc n} p = P.cong₂ _∷_ (p zero) (tabulate-cong (p ∘ suc)) tabulate-lookup : ∀ (xs : List A) → tabulate (lookup xs) ≡ xs tabulate-lookup [] = refl tabulate-lookup (x ∷ xs) = P.cong (_ ∷_) (tabulate-lookup xs) length-tabulate : ∀ {n} → (f : Fin n → A) → length (tabulate f) ≡ n length-tabulate {zero} f = refl length-tabulate {suc n} f = P.cong suc (length-tabulate (λ z → f (suc z))) lookup-tabulate : ∀{n} → (f : Fin n → A) → ∀ i → let i′ = cast (sym (length-tabulate f)) i in lookup (tabulate f) i′ ≡ f i lookup-tabulate f zero = refl lookup-tabulate f (suc i) = lookup-tabulate (f ∘ suc) i module _ {a b} {A : Set a} {B : Set b} where map-tabulate : ∀ {n} (g : Fin n → A) (f : A → B) → map f (tabulate g) ≡ tabulate (f ∘ g) map-tabulate {zero} g f = refl map-tabulate {suc n} g f = P.cong (_ ∷_) (map-tabulate (g ∘ suc) f) ------------------------------------------------------------------------ -- _[_]%=_ module _ {a} {A : Set a} where length-%= : ∀ xs k (f : A → A) → length (xs [ k ]%= f) ≡ length xs length-%= [] () f length-%= (x ∷ xs) zero f = refl length-%= (x ∷ xs) (suc k) f = P.cong suc (length-%= xs k f) ------------------------------------------------------------------------ -- _[_]∷=_ module _ {a} {A : Set a} where length-∷= : ∀ xs k (v : A) → length (xs [ k ]∷= v) ≡ length xs length-∷= xs k v = length-%= xs k (const v) map-∷= : ∀ {b} {B : Set b} xs k (v : A) (f : A → B) → let eq = P.sym (length-map f xs) in map f (xs [ k ]∷= v) ≡ map f xs [ cast eq k ]∷= f v map-∷= [] () v f map-∷= (x ∷ xs) zero v f = refl map-∷= (x ∷ xs) (suc k) v f = P.cong (f x ∷_) (map-∷= xs k v f) ------------------------------------------------------------------------ -- _─_ module _ {a} {A : Set a} where length-─ : ∀ (xs : List A) k → length (xs ─ k) ≡ pred (length xs) length-─ [] () length-─ (x ∷ xs) zero = refl length-─ (x ∷ []) (suc ()) length-─ (x ∷ y ∷ xs) (suc k) = P.cong suc (length-─ (y ∷ xs) k) map-─ : ∀ {b} {B : Set b} xs k (f : A → B) → let eq = P.sym (length-map f xs) in map f (xs ─ k) ≡ map f xs ─ cast eq k map-─ [] () f map-─ (x ∷ xs) zero f = refl map-─ (x ∷ xs) (suc k) f = P.cong (f x ∷_) (map-─ xs k f) ------------------------------------------------------------------------ -- take module _ {a} {A : Set a} where length-take : ∀ n (xs : List A) → length (take n xs) ≡ n ⊓ (length xs) length-take zero xs = refl length-take (suc n) [] = refl length-take (suc n) (x ∷ xs) = P.cong suc (length-take n xs) ------------------------------------------------------------------------ -- drop module _ {a} {A : Set a} where length-drop : ∀ n (xs : List A) → length (drop n xs) ≡ length xs ∸ n length-drop zero xs = refl length-drop (suc n) [] = refl length-drop (suc n) (x ∷ xs) = length-drop n xs take++drop : ∀ n (xs : List A) → take n xs ++ drop n xs ≡ xs take++drop zero xs = refl take++drop (suc n) [] = refl take++drop (suc n) (x ∷ xs) = P.cong (x ∷_) (take++drop n xs) ------------------------------------------------------------------------ -- splitAt module _ {a} {A : Set a} where splitAt-defn : ∀ n → splitAt {A = A} n ≗ < take n , drop n > splitAt-defn zero xs = refl splitAt-defn (suc n) [] = refl splitAt-defn (suc n) (x ∷ xs) with splitAt n xs | splitAt-defn n xs ... | (ys , zs) | ih = P.cong (Prod.map (x ∷_) id) ih ------------------------------------------------------------------------ -- takeWhile, dropWhile, and span module _ {a p} {A : Set a} {P : Pred A p} (P? : Decidable P) where takeWhile++dropWhile : ∀ xs → takeWhile P? xs ++ dropWhile P? xs ≡ xs takeWhile++dropWhile [] = refl takeWhile++dropWhile (x ∷ xs) with P? x ... | yes _ = P.cong (x ∷_) (takeWhile++dropWhile xs) ... | no _ = refl span-defn : span P? ≗ < takeWhile P? , dropWhile P? > span-defn [] = refl span-defn (x ∷ xs) with P? x ... | yes _ = P.cong (Prod.map (x ∷_) id) (span-defn xs) ... | no _ = refl ------------------------------------------------------------------------ -- filter module _ {a p} {A : Set a} {P : A → Set p} (P? : Decidable P) where length-filter : ∀ xs → length (filter P? xs) ≤ length xs length-filter [] = z≤n length-filter (x ∷ xs) with P? x ... | no _ = ≤-step (length-filter xs) ... | yes _ = s≤s (length-filter xs) filter-all : ∀ {xs} → All P xs → filter P? xs ≡ xs filter-all {[]} [] = refl filter-all {x ∷ xs} (px ∷ pxs) with P? x ... | no ¬px = contradiction px ¬px ... | yes _ = P.cong (x ∷_) (filter-all pxs) filter-notAll : ∀ xs → Any (∁ P) xs → length (filter P? xs) < length xs filter-notAll [] () filter-notAll (x ∷ xs) (here ¬px) with P? x ... | no _ = s≤s (length-filter xs) ... | yes px = contradiction px ¬px filter-notAll (x ∷ xs) (there any) with P? x ... | no _ = ≤-step (filter-notAll xs any) ... | yes _ = s≤s (filter-notAll xs any) filter-some : ∀ {xs} → Any P xs → 0 < length (filter P? xs) filter-some {x ∷ xs} (here px) with P? x ... | yes _ = s≤s z≤n ... | no ¬px = contradiction px ¬px filter-some {x ∷ xs} (there pxs) with P? x ... | yes _ = ≤-step (filter-some pxs) ... | no _ = filter-some pxs filter-none : ∀ {xs} → All (∁ P) xs → filter P? xs ≡ [] filter-none {[]} [] = refl filter-none {x ∷ xs} (¬px ∷ ¬pxs) with P? x ... | no _ = filter-none ¬pxs ... | yes px = contradiction px ¬px filter-complete : ∀ {xs} → length (filter P? xs) ≡ length xs → filter P? xs ≡ xs filter-complete {[]} eq = refl filter-complete {x ∷ xs} eq with P? x ... | no ¬px = contradiction eq (<⇒≢ (s≤s (length-filter xs))) ... | yes px = P.cong (x ∷_) (filter-complete (suc-injective eq)) ------------------------------------------------------------------------ -- partition module _ {a p} {A : Set a} {P : A → Set p} (P? : Decidable P) where partition-defn : partition P? ≗ < filter P? , filter (∁? P?) > partition-defn [] = refl partition-defn (x ∷ xs) with P? x ... | yes Px = P.cong (Prod.map (x ∷_) id) (partition-defn xs) ... | no ¬Px = P.cong (Prod.map id (x ∷_)) (partition-defn xs) ------------------------------------------------------------------------ -- reverse module _ {a} {A : Set a} where open FunctionProperties {A = List A} _≡_ unfold-reverse : ∀ (x : A) xs → reverse (x ∷ xs) ≡ reverse xs ∷ʳ x unfold-reverse x xs = helper [ x ] xs where open P.≡-Reasoning helper : (xs ys : List A) → foldl (flip _∷_) xs ys ≡ reverse ys ++ xs helper xs [] = refl helper xs (y ∷ ys) = begin foldl (flip _∷_) (y ∷ xs) ys ≡⟨ helper (y ∷ xs) ys ⟩ reverse ys ++ y ∷ xs ≡⟨ P.sym (++-assoc (reverse ys) _ _) ⟩ (reverse ys ∷ʳ y) ++ xs ≡⟨ P.sym $ P.cong (_++ xs) (unfold-reverse y ys) ⟩ reverse (y ∷ ys) ++ xs ∎ reverse-++-commute : (xs ys : List A) → reverse (xs ++ ys) ≡ reverse ys ++ reverse xs reverse-++-commute [] ys = P.sym (++-identityʳ _) reverse-++-commute (x ∷ xs) ys = begin reverse (x ∷ xs ++ ys) ≡⟨ unfold-reverse x (xs ++ ys) ⟩ reverse (xs ++ ys) ++ [ x ] ≡⟨ P.cong (_++ [ x ]) (reverse-++-commute xs ys) ⟩ (reverse ys ++ reverse xs) ++ [ x ] ≡⟨ ++-assoc (reverse ys) _ _ ⟩ reverse ys ++ (reverse xs ++ [ x ]) ≡⟨ P.sym $ P.cong (reverse ys ++_) (unfold-reverse x xs) ⟩ reverse ys ++ reverse (x ∷ xs) ∎ where open P.≡-Reasoning reverse-involutive : Involutive reverse reverse-involutive [] = refl reverse-involutive (x ∷ xs) = begin reverse (reverse (x ∷ xs)) ≡⟨ P.cong reverse $ unfold-reverse x xs ⟩ reverse (reverse xs ∷ʳ x) ≡⟨ reverse-++-commute (reverse xs) ([ x ]) ⟩ x ∷ reverse (reverse (xs)) ≡⟨ P.cong (x ∷_) $ reverse-involutive xs ⟩ x ∷ xs ∎ where open P.≡-Reasoning length-reverse : (xs : List A) → length (reverse xs) ≡ length xs length-reverse [] = refl length-reverse (x ∷ xs) = begin length (reverse (x ∷ xs)) ≡⟨ P.cong length $ unfold-reverse x xs ⟩ length (reverse xs ∷ʳ x) ≡⟨ length-++ (reverse xs) ⟩ length (reverse xs) + 1 ≡⟨ P.cong (_+ 1) (length-reverse xs) ⟩ length xs + 1 ≡⟨ +-comm _ 1 ⟩ suc (length xs) ∎ where open P.≡-Reasoning module _ {a b} {A : Set a} {B : Set b} where reverse-map-commute : (f : A → B) (xs : List A) → map f (reverse xs) ≡ reverse (map f xs) reverse-map-commute f [] = refl reverse-map-commute f (x ∷ xs) = begin map f (reverse (x ∷ xs)) ≡⟨ P.cong (map f) $ unfold-reverse x xs ⟩ map f (reverse xs ∷ʳ x) ≡⟨ map-++-commute f (reverse xs) ([ x ]) ⟩ map f (reverse xs) ∷ʳ f x ≡⟨ P.cong (_∷ʳ f x) $ reverse-map-commute f xs ⟩ reverse (map f xs) ∷ʳ f x ≡⟨ P.sym $ unfold-reverse (f x) (map f xs) ⟩ reverse (map f (x ∷ xs)) ∎ where open P.≡-Reasoning reverse-foldr : ∀ (f : A → B → B) x ys → foldr f x (reverse ys) ≡ foldl (flip f) x ys reverse-foldr f x [] = refl reverse-foldr f x (y ∷ ys) = begin foldr f x (reverse (y ∷ ys)) ≡⟨ P.cong (foldr f x) (unfold-reverse y ys) ⟩ foldr f x ((reverse ys) ∷ʳ y) ≡⟨ foldr-∷ʳ f x y (reverse ys) ⟩ foldr f (f y x) (reverse ys) ≡⟨ reverse-foldr f (f y x) ys ⟩ foldl (flip f) (f y x) ys ∎ where open P.≡-Reasoning reverse-foldl : ∀ (f : A → B → A) x ys → foldl f x (reverse ys) ≡ foldr (flip f) x ys reverse-foldl f x [] = refl reverse-foldl f x (y ∷ ys) = begin foldl f x (reverse (y ∷ ys)) ≡⟨ P.cong (foldl f x) (unfold-reverse y ys) ⟩ foldl f x ((reverse ys) ∷ʳ y) ≡⟨ foldl-∷ʳ f x y (reverse ys) ⟩ f (foldl f x (reverse ys)) y ≡⟨ P.cong (flip f y) (reverse-foldl f x ys) ⟩ f (foldr (flip f) x ys) y ∎ where open P.≡-Reasoning ------------------------------------------------------------------------ -- _∷ʳ_ module _ {a} {A : Set a} where ∷ʳ-injective : ∀ {x y : A} xs ys → xs ∷ʳ x ≡ ys ∷ʳ y → xs ≡ ys × x ≡ y ∷ʳ-injective [] [] refl = (refl , refl) ∷ʳ-injective (x ∷ xs) (y ∷ ys) eq with ∷-injective eq ... | refl , eq′ = Prod.map (P.cong (x ∷_)) id (∷ʳ-injective xs ys eq′) ∷ʳ-injective [] (_ ∷ []) () ∷ʳ-injective [] (_ ∷ _ ∷ _) () ∷ʳ-injective (_ ∷ []) [] () ∷ʳ-injective (_ ∷ _ ∷ _) [] () ∷ʳ-injectiveˡ : ∀ {x y : A} (xs ys : List A) → xs ∷ʳ x ≡ ys ∷ʳ y → xs ≡ ys ∷ʳ-injectiveˡ xs ys eq = proj₁ (∷ʳ-injective xs ys eq) ∷ʳ-injectiveʳ : ∀ {x y : A} (xs ys : List A) → xs ∷ʳ x ≡ ys ∷ʳ y → x ≡ y ∷ʳ-injectiveʳ xs ys eq = proj₂ (∷ʳ-injective xs ys eq) ------------------------------------------------------------------------ -- DEPRECATED ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.15 gfilter-just = mapMaybe-just {-# WARNING_ON_USAGE gfilter-just "Warning: gfilter-just was deprecated in v0.15. Please use mapMaybe-just instead." #-} gfilter-nothing = mapMaybe-nothing {-# WARNING_ON_USAGE gfilter-nothing "Warning: gfilter-nothing was deprecated in v0.15. Please use mapMaybe-nothing instead." #-} gfilter-concatMap = mapMaybe-concatMap {-# WARNING_ON_USAGE gfilter-concatMap "Warning: gfilter-concatMap was deprecated in v0.15. Please use mapMaybe-concatMap instead." #-} length-gfilter = length-mapMaybe {-# WARNING_ON_USAGE length-gfilter "Warning: length-gfilter was deprecated in v0.15. Please use length-mapMaybe instead." #-} right-identity-unique = ++-identityʳ-unique {-# WARNING_ON_USAGE right-identity-unique "Warning: right-identity-unique was deprecated in v0.15. Please use ++-identityʳ-unique instead." #-} left-identity-unique = ++-identityˡ-unique {-# WARNING_ON_USAGE left-identity-unique "Warning: left-identity-unique was deprecated in v0.15. Please use ++-identityˡ-unique instead." #-} -- Version 0.16 module _ {a} {A : Set a} (p : A → Bool) where boolTakeWhile++boolDropWhile : ∀ xs → boolTakeWhile p xs ++ boolDropWhile p xs ≡ xs boolTakeWhile++boolDropWhile [] = refl boolTakeWhile++boolDropWhile (x ∷ xs) with p x ... | true = P.cong (x ∷_) (boolTakeWhile++boolDropWhile xs) ... | false = refl {-# WARNING_ON_USAGE boolTakeWhile++boolDropWhile "Warning: boolTakeWhile and boolDropWhile were deprecated in v0.16. Please use takeWhile and dropWhile instead." #-} boolSpan-defn : boolSpan p ≗ < boolTakeWhile p , boolDropWhile p > boolSpan-defn [] = refl boolSpan-defn (x ∷ xs) with p x ... | true = P.cong (Prod.map (x ∷_) id) (boolSpan-defn xs) ... | false = refl {-# WARNING_ON_USAGE boolSpan-defn "Warning: boolSpan, boolTakeWhile and boolDropWhile were deprecated in v0.16. Please use span, takeWhile and dropWhile instead." #-} length-boolFilter : ∀ xs → length (boolFilter p xs) ≤ length xs length-boolFilter xs = length-mapMaybe (λ x → if p x then just x else nothing) xs {-# WARNING_ON_USAGE length-boolFilter "Warning: boolFilter was deprecated in v0.16. Please use filter instead." #-} boolPartition-defn : boolPartition p ≗ < boolFilter p , boolFilter (not ∘ p) > boolPartition-defn [] = refl boolPartition-defn (x ∷ xs) with p x ... | true = P.cong (Prod.map (x ∷_) id) (boolPartition-defn xs) ... | false = P.cong (Prod.map id (x ∷_)) (boolPartition-defn xs) {-# WARNING_ON_USAGE boolPartition-defn "Warning: boolPartition and boolFilter were deprecated in v0.16. Please use partition and filter instead." #-} module _ {a p} {A : Set a} (P : A → Set p) (P? : Decidable P) where boolFilter-filters : ∀ xs → All P (boolFilter (⌊_⌋ ∘ P?) xs) boolFilter-filters [] = [] boolFilter-filters (x ∷ xs) with P? x ... | yes px = px ∷ boolFilter-filters xs ... | no ¬px = boolFilter-filters xs {-# WARNING_ON_USAGE boolFilter-filters "Warning: boolFilter was deprecated in v0.16. Please use filter instead." #-} -- Version 0.17 idIsFold = id-is-foldr {-# WARNING_ON_USAGE idIsFold "Warning: idIsFold was deprecated in v0.17. Please use id-is-foldr instead." #-} ++IsFold = ++-is-foldr {-# WARNING_ON_USAGE ++IsFold "Warning: ++IsFold was deprecated in v0.17. Please use ++-is-foldr instead." #-} mapIsFold = map-is-foldr {-# WARNING_ON_USAGE mapIsFold "Warning: mapIsFold was deprecated in v0.17. Please use map-is-foldr instead." #-}
{ "alphanum_fraction": 0.4987402812, "avg_line_length": 36.8761238761, "ext": "agda", "hexsha": "b7bbc50301409478484cd884f87f06fd6db362f7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Properties.agda", "max_line_length": 101, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 13554, "size": 36913 }
-- Andreas, 2018-09-03, issue #3200 reported by gallais -- -- Record let pattern bindings trigger spurious irrelevance -- marker, probably due to confusion of Prop with dummy type. -- {-# OPTIONS -v tc.term.let.pattern:100 #-} -- {-# OPTIONS -v tc.lhs.top:30 #-} open import Agda.Builtin.Bool open import Agda.Builtin.Unit record R : Set where field fld : Bool data Maybe (A : Set) : Set where just : A → Maybe A nothing : Maybe A case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B case x of f = f x solve2 : Maybe (Bool → Bool) solve2 = let record { fld = bla } = record { fld = true } in case true of λ where true → just (λ x → true) false → nothing From-just : {A : Set} → Maybe A → Set From-just {A} (just _) = A From-just nothing = ⊤ from-just : {A : Set} (x : Maybe A) → From-just x from-just (just x) = x from-just nothing = _ test : Bool test = from-just solve2 true -- Error was: -- -- From-just .((just (λ x → true))) should be a function type, but it isn't -- when checking that true is a valid argument to a function of type -- From-just solve2
{ "alphanum_fraction": 0.633969119, "avg_line_length": 23.9347826087, "ext": "agda", "hexsha": "f283a9df04ce2896fcadc13f1f471eb72895355e", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue3200.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue3200.agda", "max_line_length": 75, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue3200.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 356, "size": 1101 }
{-# OPTIONS --cubical --cumulativity #-} open import leibniz public open import equalities public open import leibniz-equality public
{ "alphanum_fraction": 0.7851851852, "avg_line_length": 22.5, "ext": "agda", "hexsha": "1483060a245f294efdf80d345c16b468f5315e19", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "e1104012d85d2072318656f6c6d31acff75c9460", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guilhermehas/Equality", "max_forks_repo_path": "README.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e1104012d85d2072318656f6c6d31acff75c9460", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guilhermehas/Equality", "max_issues_repo_path": "README.agda", "max_line_length": 40, "max_stars_count": 1, "max_stars_repo_head_hexsha": "e1104012d85d2072318656f6c6d31acff75c9460", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guilhermehas/Equality", "max_stars_repo_path": "README.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-01T06:04:21.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-01T06:04:21.000Z", "num_tokens": 35, "size": 135 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Group open import lib.types.Lift open import lib.groups.Homomorphisms module lib.groups.Lift where Lift-group-structure : ∀ {i j} {A : Type i} → GroupStructure A → GroupStructure (Lift {j = j} A) Lift-group-structure GS = record { ident = lift ident ; inv = λ {(lift x) → lift (inv x)} ; comp = λ {(lift x) (lift y) → lift (comp x y)} ; unitl = λ {(lift y) → ap lift (unitl y)} ; unitr = λ {(lift x) → ap lift (unitr x)} ; assoc = λ {(lift x) (lift y) (lift z) → ap lift (assoc x y z)} ; invr = λ {(lift x) → ap lift (invr x)} ; invl = λ {(lift x) → ap lift (invl x)} } where open GroupStructure GS Lift-group : ∀ {i j} → Group i → Group (lmax i j) Lift-group {j = j} G = group (Lift {j = j} El) (Lift-level El-level) (Lift-group-structure group-struct) where open Group G lift-hom : ∀ {i j} {G : Group i} → (G →ᴳ Lift-group {j = j} G) lift-hom = record {f = lift; pres-comp = λ _ _ → idp} lower-hom : ∀ {i j} {G : Group i} → (Lift-group {j = j} G →ᴳ G) lower-hom = record {f = lower; pres-comp = λ _ _ → idp} lift-iso : ∀ {i j} {G : Group i} → (G ≃ᴳ Lift-group {j = j} G) lift-iso = (lift-hom , snd lift-equiv) lower-iso : ∀ {i j} {G : Group i} → (Lift-group {j = j} G ≃ᴳ G) lower-iso = (lower-hom , snd lower-equiv)
{ "alphanum_fraction": 0.5791420118, "avg_line_length": 33.8, "ext": "agda", "hexsha": "8037dc830b6dd82157fce2ae1b60f97c66530f2c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "core/lib/groups/Lift.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_path": "core/lib/groups/Lift.agda", "max_line_length": 68, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "core/lib/groups/Lift.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 494, "size": 1352 }
{-# OPTIONS --show-implicit #-} open import Relation.Binary.PropositionalEquality module Experiments.Ref (funext : ∀ {a b} → Extensionality a b) where open import Level open import Data.Nat import Data.Unit as Unit open import Data.List open import Data.List.Most open import Data.Product hiding (swap) open import Data.Maybe as Maybe hiding (All) open import Function as Fun using (case_of_) import Relation.Binary.PropositionalEquality as PEq open PEq.≡-Reasoning data Ty : Set where unit : Ty ref : Ty → Ty open import Experiments.Category (⊑-preorder {A = Ty}) open Product data Expr : Ty → Set where unit : Expr unit ref : ∀ {t} → Expr t → Expr (ref t) !_ : ∀ {t} → Expr (ref t) → Expr t _≔_ : ∀ {t} → Expr (ref t) → Expr t → Expr unit Val : Ty → MP₀ Val t = mp (Val' t) (record { monotone = λ{ c~c' unit → unit ; c~c' (ref x) → ref (∈-⊒ x c~c') }; monotone-refl = λ{ unit → refl ; (ref x) → cong ref ∈-⊒-refl }; monotone-trans = λ p c~c' c'~c'' → {!!} }) module Values where data Val' : Ty → List Ty → Set where unit : ∀ {Σ} → Val' unit Σ ref : ∀ {Σ t} → t ∈ Σ → Val' (ref t) Σ open import Experiments.StrongMonad Ty Val funext open Strong mkunit : ⊤ ⇒ Val unit mkunit = mk⇒ (λ _ → Values.unit) λ c~c' → refl alloc : ∀ {a} → Val a ⇒ M (Val (ref a)) alloc {a} = mk⇒ (λ v Σ₁ ext μ₁ → let ext' = ∷ʳ-⊒ a Σ₁ in (Σ₁ ∷ʳ a) , ext' , ((map-all (MP.monotone (Val _) ext') μ₁) all-∷ʳ MP.monotone (Val _) (⊑-trans ext ext') v) , Values.ref (∈-∷ʳ Σ₁ a)) (λ c~c' → {!!}) load : ∀ {a} → Val (ref a) ⇒ M (Val a) load {a} = mk⇒ (λ v Σ₁ ext μ₁ → case v of λ{ (Values.ref x) → Σ₁ , ⊑-refl , μ₁ , (∈-all (∈-⊒ x ext) μ₁) }) (λ c~c' → {!!}) store : ∀ {a} → (Val (ref a) ⊗ Val a) ⇒ M ⊤ store = mk⇒ (λ x Σ₁ ext μ₁ → case x of λ{ (Values.ref l , v) → Σ₁ , ⊑-refl , (μ₁ All[ ∈-⊒ l ext ]≔' MP.monotone (Val _) ext v) , Unit.tt }) (λ c~c' → {!!}) eval : ∀ {a} → Expr a → ⊤ ⇒ M (Val a) eval unit = η (Val _) ∘ mkunit eval (ref e) = μ (Val _) ∘ fmap alloc ∘ eval e eval (! e) = μ (Val _) ∘ fmap load ∘ eval e eval (e₁ ≔ e₂) = fmap mkunit ∘ μ ⊤ ∘ fmap store ∘ μ ((Val _) ⊗ (Val _)) ∘ fmap (ts' (Val _)(Val _)) ∘ ts (M (Val _))(Val _) ∘ ⟨ eval e₁ , eval e₂ ⟩
{ "alphanum_fraction": 0.5512538495, "avg_line_length": 27.0595238095, "ext": "agda", "hexsha": "151b8ddb200dbe14fd046151e477fae2138f126a", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/Experiments/Ref.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/Experiments/Ref.agda", "max_line_length": 98, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/Experiments/Ref.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 927, "size": 2273 }
------------------------------------------------------------------------ -- Strings ------------------------------------------------------------------------ {-# OPTIONS --without-K #-} module String where open import Prelude ------------------------------------------------------------------------ -- Helper code used below private -- A variant of Maybe that matches the Haskell Maybe type. data HMaybe (A : Type) : Type where Nothing : HMaybe A Just : A → HMaybe A {-# COMPILE GHC HMaybe = data Maybe (Nothing | Just) #-} -- A conversion function. hmaybe-to-maybe : ∀ {A} → HMaybe A → Maybe A hmaybe-to-maybe Nothing = nothing hmaybe-to-maybe (Just x) = just x ------------------------------------------------------------------------ -- Operations on strings -- Implemented using the FFI. These operations do not compute at -- compile-time, and are only supported by the GHC backend. {-# FOREIGN GHC import qualified Data.Text #-} mutual -- Tries to parse the given string as a natural number. Accepts -- whatever the Haskell Read instance for Integer accepts, except -- for negative numbers. parseℕ : String → Maybe ℕ parseℕ = hmaybe-to-maybe ∘ parseℕ′ private postulate parseℕ′ : String → HMaybe ℕ {-# COMPILE GHC parseℕ′ = \s -> case reads (Data.Text.unpack s) of { [(x, "")] | x >= 0 -> Just (x :: Integer) ; _ -> Nothing } #-} -- Turns natural numbers into strings. postulate prettyℕ : ℕ → String {-# COMPILE GHC prettyℕ = \n -> Data.Text.pack (show (n :: Integer)) #-}
{ "alphanum_fraction": 0.5118306351, "avg_line_length": 23.6176470588, "ext": "agda", "hexsha": "13557fef88543a3af042b8fd7d8fe85d4b14159c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/String.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/equality", "max_issues_repo_path": "src/String.agda", "max_line_length": 72, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/String.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 368, "size": 1606 }
-- {-# OPTIONS --show-implicit --show-irrelevant #-} module Data.QuadTree.FunctorProofs.Valid-QuadTreeFunctor where open import Haskell.Prelude renaming (zero to Z; suc to S) open import Data.Logic open import Data.QuadTree.InternalAgda open import Agda.Primitive open import Data.QuadTree.FunctorProofs.FunctorLaws open import Data.QuadTree.FunctorProofs.Valid-QuadrantFunctor open import Data.QuadTree.Implementation.Definition open import Data.QuadTree.Implementation.ValidTypes open import Data.QuadTree.Implementation.Functors open import Data.QuadTree.Implementation.QuadrantLenses ValidFunctor-QuadTree-IdentityLaw : (dep : Nat) -> IdentityLaw (λ y -> VQuadTree y {dep}) {{quadtreeFunctor dep}} ValidFunctor-QuadTree-IdentityLaw dep (CVQuadTree (Wrapper (w , h) qd) {p}) = begin toQt dep w h _ (fmapₑ (quadrantFunctor dep) id (CVQuadrant qd)) =⟨ cong (toQt dep w h _) (ValidFunctor-Quadrant-IdentityLaw dep (CVQuadrant qd)) ⟩ toQt dep w h _ (CVQuadrant qd) end toQt-fmap : {a b : Set} {{eqA : Eq a}} {{eqB : Eq b}} (dep w h : Nat) (g : a -> b) (v : VQuadrant a {dep}) .(q : IsTrue (dep == log2up (if w < h then h else w))) -> toQt dep w h q (fmapₑ (quadrantFunctor dep) g v) ≡ fmapₑ (quadtreeFunctor dep) g (toQt dep w h q v) toQt-fmap dep w h g (CVQuadrant (Leaf x)) q = refl toQt-fmap dep w h g (CVQuadrant (Node qd qd₁ qd₂ qd₃)) q = refl ValidFunctor-QuadTree-CompositionLaw : (dep : Nat) -> CompositionLaw (λ y -> VQuadTree y {dep}) {{quadtreeFunctor dep}} ValidFunctor-QuadTree-CompositionLaw dep (CVQuadTree (Wrapper (w , h) qd) {p} {q}) f g = begin toQt dep w h _ (fmapₑ (quadrantFunctor dep) (g ∘ f) (CVQuadrant qd)) =⟨ cong (toQt dep w h _) (ValidFunctor-Quadrant-CompositionLaw dep (CVQuadrant qd) f g) ⟩ toQt dep w h _ (fmapₑ (quadrantFunctor dep) g (fmapₑ (quadrantFunctor dep) f (CVQuadrant qd))) =⟨ toQt-fmap dep w h g (fmapₑ (quadrantFunctor dep) f (CVQuadrant qd)) q ⟩ fmapₑ (quadtreeFunctor dep) g (toQt dep w h _ (fmapₑ (quadrantFunctor dep) f (CVQuadrant qd))) end where
{ "alphanum_fraction": 0.7014853857, "avg_line_length": 53.5128205128, "ext": "agda", "hexsha": "4158eb7435fa73af60363bf3314cfc238ed15369", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "JonathanBrouwer/research-project", "max_forks_repo_path": "src/Data/QuadTree/FunctorProofs/Valid-QuadTreeFunctor.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "JonathanBrouwer/research-project", "max_issues_repo_path": "src/Data/QuadTree/FunctorProofs/Valid-QuadTreeFunctor.agda", "max_line_length": 161, "max_stars_count": 1, "max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "JonathanBrouwer/research-project", "max_stars_repo_path": "src/Data/QuadTree/FunctorProofs/Valid-QuadTreeFunctor.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z", "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z", "num_tokens": 737, "size": 2087 }
------------------------------------------------------------------------ -- Asymmetric choice ------------------------------------------------------------------------ {-# OPTIONS --universe-polymorphism #-} module TotalParserCombinators.AsymmetricChoice where open import Data.Empty open import Data.List open import Data.List.Any using (here) open import Data.List.Any.Membership.Propositional using (_∈_) renaming (_∼[_]_ to _List-∼[_]_) open import Data.Product open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence using (module Equivalence) open import Function.Inverse as Inv using (_↔_) open import Function.Related as Related open import Function.Related.TypeIsomorphisms import Relation.Binary.PropositionalEquality as P import Relation.Binary.Sigma.Pointwise as Σ open import TotalParserCombinators.Congruence using (_∼[_]P_; _≅P_) open import TotalParserCombinators.Derivative using (D) open import TotalParserCombinators.Parser import TotalParserCombinators.Pointwise as Pointwise open import TotalParserCombinators.Semantics using (_∈_·_) ------------------------------------------------------------------------ -- An initial bag operator -- first-nonempty returns the left-most non-empty initial bag, if any. first-nonempty : {R : Set} → List R → List R → List R first-nonempty [] ys = ys first-nonempty xs ys = xs -- first-nonempty preserves equality. first-nonempty-cong : ∀ {k R} {xs₁ xs₁′ xs₂ xs₂′ : List R} → xs₁ List-∼[ ⌊ k ⌋⇔ ] xs₁′ → xs₂ List-∼[ ⌊ k ⌋⇔ ] xs₂′ → first-nonempty xs₁ xs₂ List-∼[ ⌊ k ⌋⇔ ] first-nonempty xs₁′ xs₂′ first-nonempty-cong {xs₁ = []} {[]} eq₁ eq₂ = eq₂ first-nonempty-cong {xs₁ = _ ∷ _} {_ ∷ _} eq₁ eq₂ = eq₁ first-nonempty-cong {xs₁ = []} {_ ∷ _} eq₁ eq₂ with Equivalence.from (⇒⇔ eq₁) ⟨$⟩ here P.refl ... | () first-nonempty-cong {xs₁ = _ ∷ _} {[]} eq₁ eq₂ with Equivalence.to (⇒⇔ eq₁) ⟨$⟩ here P.refl ... | () -- first-nonempty is correct. first-nonempty-left : ∀ {k R} {xs₁ xs₂ : List R} → (∃ λ y → y ∈ xs₁) → first-nonempty xs₁ xs₂ List-∼[ k ] xs₁ first-nonempty-left {xs₁ = []} (_ , ()) first-nonempty-left {xs₁ = _ ∷ _} _ = _ ∎ where open Related.EquationalReasoning first-nonempty-right : ∀ {k R} {xs₁ xs₂ : List R} → (∄ λ y → y ∈ xs₁) → first-nonempty xs₁ xs₂ List-∼[ k ] xs₂ first-nonempty-right {xs₁ = x ∷ _} ∉x∷ = ⊥-elim $ ∉x∷ (x , here P.refl) first-nonempty-right {xs₁ = []} _ = _ ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- Asymmetric choice -- _◃_ is defined as a pointwise lifting of first-nonempty. Note that -- _◃_ preserves parser and language equality, but not the -- sub-/superparser and sub-/superlanguage relations. private module AC {R} = Pointwise R R ⌊_⌋⇔ first-nonempty first-nonempty-cong -- p₁ ◃ p₂ returns a result if either p₁ or p₂ does. For a given -- string results are returned either from p₁ or from p₂, not both. infixl 5 _◃_ _◃-cong_ _◃_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Parser Tok R (first-nonempty xs₁ xs₂) _◃_ = AC.lift -- D distributes over _◃_. D-◃ : ∀ {Tok R xs₁ xs₂ t} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → D t (p₁ ◃ p₂) ≅P D t p₁ ◃ D t p₂ D-◃ = AC.D-lift -- _◃_ preserves equality. _◃-cong_ : ∀ {k Tok R xs₁ xs₁′ xs₂ xs₂′} {p₁ : Parser Tok R xs₁} {p₁′ : Parser Tok R xs₁′} {p₂ : Parser Tok R xs₂} {p₂′ : Parser Tok R xs₂′} → p₁ ∼[ ⌊ k ⌋⇔ ]P p₁′ → p₂ ∼[ ⌊ k ⌋⇔ ]P p₂′ → p₁ ◃ p₂ ∼[ ⌊ k ⌋⇔ ]P p₁′ ◃ p₂′ _◃-cong_ = AC.lift-cong -- If p₁ accepts s, then p₁ ◃ p₂ behaves as p₁ when applied to s. left : ∀ {Tok R xs₁ xs₂ x s} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → (∃ λ y → y ∈ p₁ · s) → x ∈ p₁ ◃ p₂ · s ↔ x ∈ p₁ · s left {x = x} = AC.lift-property (λ F _ H → ∃ F → H x ↔ F x) (λ F↔F′ _ H↔H′ → Σ.cong Inv.id (λ {x} → ↔⇒ (F↔F′ x)) →-cong-⇔ Related-cong (H↔H′ x) (F↔F′ x)) (λ ∈xs₁ → first-nonempty-left ∈xs₁) -- If p₁ does not accept s, then p₁ ◃ p₂ behaves as p₂ when applied to -- s. right : ∀ {Tok R xs₁ xs₂ x s} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → (∄ λ y → y ∈ p₁ · s) → x ∈ p₁ ◃ p₂ · s ↔ x ∈ p₂ · s right {x = x} = AC.lift-property (λ F G H → ∄ F → H x ↔ G x) (λ F↔F′ G↔G′ H↔H′ → ¬-cong-⇔ (Σ.cong Inv.id λ {x} → ↔⇒ (F↔F′ x)) →-cong-⇔ Related-cong (H↔H′ x) (G↔G′ x)) (λ ∉xs₁ → first-nonempty-right ∉xs₁)
{ "alphanum_fraction": 0.574933687, "avg_line_length": 33.7611940299, "ext": "agda", "hexsha": "cdc3989a2203d59fe089e25a819813cb3ae692e4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yurrriq/parser-combinators", "max_forks_repo_path": "TotalParserCombinators/AsymmetricChoice.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yurrriq/parser-combinators", "max_issues_repo_path": "TotalParserCombinators/AsymmetricChoice.agda", "max_line_length": 72, "max_stars_count": 7, "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_path": "TotalParserCombinators/AsymmetricChoice.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "num_tokens": 1661, "size": 4524 }
{- Agda Implementors' Meeting VI Göteborg May 24 - 30, 2007 Hello Agda! Ulf Norell -} {- Getting your hands on Agda http://www.cs.chalmers.se/~ulfn/Agda darcs get --partial http://www.cs.chalmers.se/~ulfn/darcs/Agda2 -} -- Each Agda file contains a top-level module, whose -- name corresponds to the file name. module Basics where {- Expressions (types and terms) -} -- The expression language of Agda is your favorite dependently -- typed λ-calculus. -- For instance: id₁ : (A : Set) -> A -> A id₁ = \ A x -> x id₂ : (A : Set) -> A -> A id₂ = \ A x -> id₁ A (id₁ A x) -- Note: Agda likes white space. This is not correct: -- id:(A:Set)->A->A -- Why not? In Agda the following strings are valid identifiers: -- id: -- A:Set -- ->A->A -- Another useful function, featuring telescopes -- and typed λs. compose : (A B C : Set)(f : B -> C)(g : A -> B) -> A -> C compose = \(A B C : Set) -> \ f g x -> f (g x) {- Implicit arguments -} -- Writing down type arguments explicitly soon gets old. -- Enter implicit arguments. -- Note the curlies in the telescope. And A mysteriously disappeared -- in the definition. id₃ : {A : Set} -> A -> A id₃ = \ x -> x -- And it's not there when applying the function. id₄ : {A : Set} -> A -> A id₄ = \ x -> (id₃ (id₃ x)) -- You can give implicit arguments explicitly. id₅ : {A : Set} -> A -> A id₅ {A} x = id₄ {A} x -- If you want to give a particular implicit argument, you can refer -- to it by name. const : {A B : Set} -> A -> B -> A const = \ x y -> x const' : (A : Set) -> A -> A -> A const' = \ A -> const {B = A} -- It also works the other way around. If you think the type checker -- should figure out the value of something explicit, you write _. id₆ : {A : Set} -> A -> A id₆ x = id₁ _ x -- Interesting though it is, eventually you'll get bored -- with the λ-calculus... -- Move on to: Datatypes.agda
{ "alphanum_fraction": 0.5948144382, "avg_line_length": 20.2783505155, "ext": "agda", "hexsha": "34ca2514ca0168f9cd4cfe8fa7da4cd71698856f", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "examples/AIM6/HelloAgda/Basics.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "examples/AIM6/HelloAgda/Basics.agda", "max_line_length": 68, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "examples/AIM6/HelloAgda/Basics.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 621, "size": 1967 }
open import Agda.Builtin.List open import Agda.Builtin.Reflection open import Agda.Builtin.Unit postulate F : Set → Set module M₀ where macro go-tactic₀ : Term → TC ⊤ go-tactic₀ hole = unify hole (def (quote F) []) test₀ : Set test₀ = go-tactic₀ ⊤ module M₁ (A : Set) where macro go-tactic₁ : Term → TC ⊤ go-tactic₁ hole = unify hole (def (quote F) []) test-inside-M₁ : Set test-inside-M₁ = go-tactic₁ ⊤ test-outside-M₁ : Set test-outside-M₁ = M₁.go-tactic₁ ⊤ ⊤
{ "alphanum_fraction": 0.6553106212, "avg_line_length": 18.4814814815, "ext": "agda", "hexsha": "2479fac9df8c4c40c1aa0b53238dd75b900ecedc", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue1363.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue1363.agda", "max_line_length": 51, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1363.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 177, "size": 499 }
{-# OPTIONS --safe --cubical --postfix-projections #-} module Relation.Binary where open import Level open import Function using (_∘_; flip; id) open import Inspect using (inspect;〖_〗) open import HLevels using (isSet) open import Path as ≡ hiding (sym; refl) open import Data.Bool using (Bool; true; false; bool) open import Data.Bool.Properties using (false≢true) open import Data.Empty using (⊥; ⊥-elim; ¬_) open import Data.Sum using (either; inl; inr; _⊎_; is-l) open import Relation.Nullary.Decidable using (Dec; yes; no; does) open import Relation.Nullary.Decidable.Properties using (Dec→Stable) open import Relation.Nullary.Discrete using (Discrete) open import Relation.Nullary.Discrete.Properties using (Discrete→isSet) open import Relation.Nullary.Stable using (Stable) module _ (_~_ : A → A → Type b) where Reflexive : Type _ Reflexive = ∀ {x} → x ~ x Transitive : Type _ Transitive = ∀ {x y z} → x ~ y → y ~ z → x ~ z Symmetric : Type _ Symmetric = ∀ {x y} → x ~ y → y ~ x Decidable : Type _ Decidable = ∀ x y → Dec (x ~ y) Antisymmetric : Type _ Antisymmetric = ∀ {x y} → x ~ y → y ~ x → x ≡ y Connected : Type _ Connected = ∀ {x y} → ¬ (x ~ y) → ¬ (y ~ x) → x ≡ y Asymmetric : Type _ Asymmetric = ∀ {x y} → x ~ y → ¬ (y ~ x) Irreflexive : Type _ Irreflexive = ∀ {x} → ¬ (x ~ x) Total : Type _ Total = ∀ x y → (x ~ y) ⊎ (y ~ x) record Preorder {ℓ₁} (𝑆 : Type ℓ₁) ℓ₂ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂) where infix 4 _≤_ field _≤_ : 𝑆 → 𝑆 → Type ℓ₂ refl : Reflexive _≤_ trans : Transitive _≤_ infix 4 _≰_ _≥_ _≱_ _≰_ _≥_ _≱_ : 𝑆 → 𝑆 → Type ℓ₂ x ≰ y = ¬ (x ≤ y) x ≥ y = y ≤ x x ≱ y = ¬ (y ≤ x) record StrictPreorder {ℓ₁} (𝑆 : Type ℓ₁) ℓ₂ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂) where infix 4 _<_ field _<_ : 𝑆 → 𝑆 → Type ℓ₂ trans : Transitive _<_ irrefl : Irreflexive _<_ asym : Asymmetric _<_ asym x<y y<x = irrefl (trans x<y y<x) infix 4 _≮_ _>_ _≯_ _≮_ _>_ _≯_ : 𝑆 → 𝑆 → Type ℓ₂ x ≮ y = ¬ (x < y) x > y = y < x x ≯ y = ¬ (y < x) record StrictPartialOrder {ℓ₁} (𝑆 : Type ℓ₁) ℓ₂ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂) where field strictPreorder : StrictPreorder 𝑆 ℓ₂ open StrictPreorder strictPreorder public field conn : Connected _<_ record PartialOrder {ℓ₁} (𝑆 : Type ℓ₁) ℓ₂ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂) where field preorder : Preorder 𝑆 ℓ₂ open Preorder preorder public field antisym : Antisymmetric _≤_ data Tri (A : Type a) (B : Type b) (C : Type c) : Type (a ℓ⊔ b ℓ⊔ c) where lt : (x<y : A) → Tri A B C eq : (x≡y : B) → Tri A B C gt : (x>y : C) → Tri A B C record TotalOrder {ℓ₁} (𝑆 : Type ℓ₁) ℓ₂ ℓ₃ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂ ℓ⊔ ℓsuc ℓ₃) where field strictPartialOrder : StrictPartialOrder 𝑆 ℓ₂ partialOrder : PartialOrder 𝑆 ℓ₃ open PartialOrder partialOrder renaming (trans to ≤-trans) public open StrictPartialOrder strictPartialOrder renaming (trans to <-trans) public infix 4 _<?_ field _<?_ : Decidable _<_ ≰⇒> : ∀ {x y} → x ≰ y → x > y ≮⇒≥ : ∀ {x y} → x ≮ y → x ≥ y <⇒≤ : ∀ {x y} → x < y → x ≤ y <⇒≤ = ≮⇒≥ ∘ asym _<ᵇ_ : 𝑆 → 𝑆 → Bool x <ᵇ y = does (x <? y) <⇒≱ : ∀ {x y} → x < y → x ≱ y <⇒≱ {x} {y} x<y x≥y = irrefl (subst (_< _) (antisym (<⇒≤ x<y) x≥y) x<y) ≤⇒≯ : ∀ {x y} → x ≤ y → x ≯ y ≤⇒≯ {x} {y} x≤y x>y = irrefl (subst (_< _) (antisym (≮⇒≥ (asym x>y)) x≤y) x>y) infix 4 _≤ᵇ_ _≤?_ _≤|≥_ _≟_ _≤?_ : Decidable _≤_ x ≤? y with y <? x ... | yes y<x = no (<⇒≱ y<x) ... | no y≮x = yes (≮⇒≥ y≮x) _≤ᵇ_ : 𝑆 → 𝑆 → Bool x ≤ᵇ y = does (x ≤? y) _≤|≥_ : Total _≤_ x ≤|≥ y with x <? y ... | yes x<y = inl (<⇒≤ x<y) ... | no x≮y = inr (≮⇒≥ x≮y) _≟_ : Discrete 𝑆 x ≟ y with x <? y | y <? x ... | yes x<y | _ = no (λ x≡y → irrefl (subst (_< _) x≡y x<y)) ... | _ | yes y<x = no (λ x≡y → irrefl (subst (_ <_) x≡y y<x)) ... | no x≮y | no y≮x = yes (conn x≮y y≮x) Ordering : (x y : 𝑆) → Type (ℓ₁ ℓ⊔ ℓ₂) Ordering x y = Tri (x < y) (x ≡ y) (x > y) compare : ∀ x y → Ordering x y compare x y with x <? y | y <? x ... | yes x<y | _ = lt x<y ... | no x≮y | yes y<x = gt y<x ... | no x≮y | no y≮x = eq (conn x≮y y≮x) total⇒isSet : isSet 𝑆 total⇒isSet = Discrete→isSet _≟_ module FromPartialOrder {ℓ₁} {𝑆 : Type ℓ₁} {ℓ₂} (po : PartialOrder 𝑆 ℓ₂) (_≤|≥_ : Total (PartialOrder._≤_ po)) where open PartialOrder po partialOrder = po ≤-side : 𝑆 → 𝑆 → Bool ≤-side x y = is-l (x ≤|≥ y) ≤-dec : Decidable _≤_ ≤-dec x y with x ≤|≥ y | y ≤|≥ x | inspect (≤-side x) y | inspect (≤-side y) x ≤-dec x y | inl x≤y | _ | _ | _ = yes x≤y ≤-dec x y | inr x≥y | inr y≥x | _ | _ = yes y≥x ≤-dec x y | inr x≥y | inl y≤x | 〖 x≥yᵇ 〗 | 〖 y≤xᵇ 〗 = no (x≢y ∘ flip antisym x≥y) where x≢y : x ≢ y x≢y x≡y = false≢true (≡.sym x≥yᵇ ; cong₂ ≤-side x≡y (≡.sym x≡y) ; y≤xᵇ) ≮⇒≥ : ∀ {x y} → Stable (x ≤ y) ≮⇒≥ {x} {y} = Dec→Stable _ (≤-dec x y) strictPartialOrder : StrictPartialOrder 𝑆 ℓ₂ strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder._<_ x y = ¬ (y ≤ x) strictPartialOrder .StrictPartialOrder.conn x<y y<x = antisym (≮⇒≥ y<x) (≮⇒≥ x<y) strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder.irrefl y≰x = y≰x refl strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder.trans {x} {y} {z} y≰x z≰y z≤x with ≤-dec y z ... | yes y≤z = y≰x (trans y≤z z≤x) ... | no y≰z = either z≰y y≰z (z ≤|≥ y) ≰⇒> = id _<?_ : Decidable _≱_ _<?_ x y with ≤-dec y x ... | yes y≤x = no λ y≰x → y≰x y≤x ... | no y≰x = yes y≰x fromPartialOrder : (po : PartialOrder A b) (_≤|≥_ : Total (PartialOrder._≤_ po)) → TotalOrder _ _ _ fromPartialOrder po tot = record { FromPartialOrder po tot } module FromStrictPartialOrder {ℓ₁} {𝑆 : Type ℓ₁} {ℓ₂} (spo : StrictPartialOrder 𝑆 ℓ₂) (<-dec : Decidable (StrictPartialOrder._<_ spo)) where open StrictPartialOrder spo strictPartialOrder = spo _<?_ = <-dec partialOrder : PartialOrder _ _ partialOrder .PartialOrder.preorder .Preorder._≤_ x y = ¬ (y < x) partialOrder .PartialOrder.preorder .Preorder.refl x<x = asym x<x x<x partialOrder .PartialOrder.preorder .Preorder.trans {x} {y} {z} y≮x z≮y z<x with x <? y ... | yes x<y = z≮y (trans z<x x<y) ... | no x≮y = z≮y (subst (z <_) (conn x≮y y≮x) z<x) partialOrder .PartialOrder.antisym = flip conn ≰⇒> : ∀ {x y} → Stable (x < y) ≰⇒> {x} {y} = Dec→Stable (x < y) (x <? y) ≮⇒≥ = id fromStrictPartialOrder : (spo : StrictPartialOrder A b) (_<?_ : Decidable (StrictPartialOrder._<_ spo)) → TotalOrder _ _ _ fromStrictPartialOrder spo _<?_ = record { FromStrictPartialOrder spo _<?_ } record Equivalence {ℓ₁} (𝑆 : Type ℓ₁) ℓ₂ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂) where infix 4 _≋_ field _≋_ : 𝑆 → 𝑆 → Type ℓ₂ sym : ∀ {x y} → x ≋ y → y ≋ x refl : ∀ {x} → x ≋ x trans : ∀ {x y z} → x ≋ y → y ≋ z → x ≋ z ≡-equivalence : ∀ {a} {A : Set a} → Equivalence A a ≡-equivalence = record { _≋_ = _≡_ ; sym = ≡.sym ; refl = ≡.refl ; trans = _;_ }
{ "alphanum_fraction": 0.5617961511, "avg_line_length": 30.5, "ext": "agda", "hexsha": "7a69e47efe7efb5e88ac52385215ab33515fecdf", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Relation/Binary.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Relation/Binary.agda", "max_line_length": 140, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Relation/Binary.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 3210, "size": 7015 }
{-# OPTIONS --safe #-} data ⊥ : Set where private {-# TERMINATING #-} f : ⊥ f = f mutual {-# TERMINATING #-} g : ⊥ g = f abstract {-# TERMINATING #-} h : ⊥ h = f record I : Set where {-# TERMINATING #-} i : ⊥ i = f instance {-# TERMINATING #-} j : I j = j
{ "alphanum_fraction": 0.4662162162, "avg_line_length": 8.9696969697, "ext": "agda", "hexsha": "4b167b0d77092a2185aee36e588538835443a8c0", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue3983.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue3983.agda", "max_line_length": 22, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue3983.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 111, "size": 296 }
module Duploid where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; sym; cong) open Eq.≡-Reasoning open import Level open import Preduploid private variable p q r s : Polarity record Duploid o ℓ : Set (suc (o ⊔ ℓ)) where field 𝒟 : Preduploid o ℓ open Preduploid.Preduploid 𝒟 public field ⇓ : Ob ⊝ -> Ob + ⇑ : Ob + -> Ob ⊝ delay : forall {P : Ob +} -> P ⇒ ⇑ P force : forall {P : Ob +} -> ⇑ P ⇒ P wrap : forall {N : Ob ⊝} -> N ⇒ ⇓ N unwrap : forall {N : Ob ⊝} -> ⇓ N ⇒ N force∘delay∙ : forall {A : Ob p} {P : Ob +} {f : A ⇒ P} -> force ∘ (delay ∙ f) ≡ f ∘unwrap∙wrap : forall {N : Ob ⊝} {A : Ob p} {f : N ⇒ A} -> (f ∘ unwrap) ∙ wrap ≡ f delay∙force : forall {P : Ob +} -> delay ∙ force ≡ id {A = ⇑ P} wrap∘unwrap : forall {N : Ob ⊝} -> wrap ∘ unwrap ≡ id {A = ⇓ N} ∙force∘delay : forall {P : Ob +} {A : Ob p} {g : P ⇒ A} -> (g ∙ force) ∘ delay ≡ g ∙force∘delay {g = g} = begin (g ∙ force) ∘ delay ≡⟨ assoc∙∘ ⟩ g ∙ (force ∘ delay) ≡˘⟨ cong (g ∙_) (cong (force ∘_) identity∙ʳ) ⟩ g ∙ (force ∘ (delay ∙ id)) ≡⟨ cong (g ∙_) force∘delay∙ ⟩ g ∙ id ≡⟨ identity∙ʳ ⟩ g ∎ unwrap∙wrap∘ : forall {A : Ob p} {N : Ob ⊝} {g : A ⇒ N} -> unwrap ∙ (wrap ∘ g) ≡ g unwrap∙wrap∘ {g = g} = begin unwrap ∙ (wrap ∘ g) ≡˘⟨ assoc∙∘ ⟩ (unwrap ∙ wrap) ∘ g ≡˘⟨ cong (_∘ g) (cong (_∙ wrap) identity∘ˡ) ⟩ ((id ∘ unwrap) ∙ wrap) ∘ g ≡⟨ cong (_∘ g) ∘unwrap∙wrap ⟩ id ∘ g ≡⟨ identity∘ˡ ⟩ g ∎ wrap-Thunkable : forall {N : Ob ⊝} -> Thunkable (wrap {N = N}) wrap-Thunkable {r = +} = sym assoc∙∙ wrap-Thunkable {r = ⊝} {g = g} {h = h} = begin h ∘ (g ∙ wrap) ≡˘⟨ ∘unwrap∙wrap ⟩ ((h ∘ (g ∙ wrap)) ∘ unwrap) ∙ wrap ≡⟨ cong (_∙ wrap) assoc∘∘ ⟩ (h ∘ ((g ∙ wrap) ∘ unwrap)) ∙ wrap ≡⟨ cong (_∙ wrap) (cong (h ∘_) assoc∙∘) ⟩ (h ∘ (g ∙ (wrap ∘ unwrap))) ∙ wrap ≡⟨ cong (_∙ wrap) (cong (h ∘_) (cong (g ∙_) wrap∘unwrap)) ⟩ (h ∘ (g ∙ id)) ∙ wrap ≡⟨ cong (_∙ wrap) (cong (h ∘_) identity∙ʳ) ⟩ (h ∘ g) ∙ wrap ∎ force-Linear : forall {P : Ob +} -> Linear (force {P = P}) force-Linear {q = +} {g = g} {h = h} = sym ( begin (force ∘ g) ∙ h ≡˘⟨ force∘delay∙ ⟩ force ∘ (delay ∙ ((force ∘ g) ∙ h)) ≡˘⟨ cong (force ∘_) assoc∙∙ ⟩ force ∘ ((delay ∙ (force ∘ g)) ∙ h) ≡˘⟨ cong (force ∘_) (cong (_∙ h) assoc∙∘) ⟩ force ∘ (((delay ∙ force) ∘ g) ∙ h) ≡⟨ cong (force ∘_) (cong (_∙ h) (cong (_∘ g) delay∙force)) ⟩ force ∘ ((id ∘ g) ∙ h) ≡⟨ cong (force ∘_) (cong (_∙ h) identity∘ˡ) ⟩ force ∘ (g ∙ h) ∎) force-Linear {q = ⊝} = sym assoc∘∘ helper1 : forall {A : Ob p} {P : Ob +} {f : A ⇒ P} -> (wrap ∘ delay) ∙ f ≡ wrap ∘ (delay ∙ f) -> forall {B : Ob q} {h : ⇑ P ⇒ B} -> (h ∘ delay) ∙ f ≡ h ∘ (delay ∙ f) helper1 {f = f} e {h = h} = begin (h ∘ delay) ∙ f ≡˘⟨ cong (_∙ f) (cong (_∘ delay) ∘unwrap∙wrap) ⟩ (((h ∘ unwrap) ∙ wrap) ∘ delay) ∙ f ≡⟨ cong (_∙ f) assoc∙∘ ⟩ ((h ∘ unwrap) ∙ (wrap ∘ delay)) ∙ f ≡⟨ assoc∙∙ ⟩ (h ∘ unwrap) ∙ ((wrap ∘ delay) ∙ f) ≡⟨ cong ((h ∘ unwrap) ∙_) e ⟩ (h ∘ unwrap) ∙ (wrap ∘ (delay ∙ f)) ≡˘⟨ assoc∙∘ ⟩ ((h ∘ unwrap) ∙ wrap) ∘ (delay ∙ f) ≡⟨ cong (_∘ _) ∘unwrap∙wrap ⟩ h ∘ (delay ∙ f) ∎ assoc-wrap∘delay∙→Thunkable : forall {A : Ob p} {P : Ob +} {f : A ⇒ P} -> (wrap ∘ delay) ∙ f ≡ wrap ∘ (delay ∙ f) -> Thunkable f assoc-wrap∘delay∙→Thunkable e {r = +} = sym assoc∙∙ assoc-wrap∘delay∙→Thunkable {f = f} e {r = ⊝} {g = g} {h = h} = begin h ∘ (g ∙ f) ≡˘⟨ cong (h ∘_) (cong (_∙ f) ∙force∘delay) ⟩ h ∘ (((g ∙ force) ∘ delay) ∙ f) ≡⟨ cong (h ∘_) (helper1 e) ⟩ h ∘ ((g ∙ force) ∘ (delay ∙ f)) ≡˘⟨ assoc∘∘ ⟩ (h ∘ (g ∙ force)) ∘ (delay ∙ f) ≡˘⟨ helper1 e ⟩ ((h ∘ (g ∙ force)) ∘ delay) ∙ f ≡⟨ cong (_∙ f) assoc∘∘ ⟩ (h ∘ ((g ∙ force) ∘ delay)) ∙ f ≡⟨ cong (_∙ f) (cong (h ∘_) ∙force∘delay) ⟩ (h ∘ g) ∙ f ∎ helper2 : forall {N : Ob ⊝} {A : Ob p} {f : N ⇒ A} -> f ∘ (unwrap ∙ force) ≡ (f ∘ unwrap) ∙ force -> forall {B : Ob q} {h : B ⇒ ⇓ N} -> f ∘ (unwrap ∙ h) ≡ (f ∘ unwrap) ∙ h helper2 {f = f} e {h = h} = begin f ∘ (unwrap ∙ h) ≡˘⟨ cong (f ∘_) (cong (unwrap ∙_) force∘delay∙) ⟩ f ∘ (unwrap ∙ (force ∘ (delay ∙ h))) ≡˘⟨ cong (f ∘_) assoc∙∘ ⟩ f ∘ ((unwrap ∙ force) ∘ (delay ∙ h)) ≡˘⟨ assoc∘∘ ⟩ (f ∘ (unwrap ∙ force)) ∘ (delay ∙ h) ≡⟨ cong (_∘ (delay ∙ h)) e ⟩ ((f ∘ unwrap) ∙ force) ∘ (delay ∙ h) ≡⟨ assoc∙∘ ⟩ (f ∘ unwrap) ∙ (force ∘ (delay ∙ h)) ≡⟨ cong ((f ∘ unwrap) ∙_) force∘delay∙ ⟩ (f ∘ unwrap) ∙ h ∎ assoc-∘unwrap∙force→Linear : forall {N : Ob ⊝} {A : Ob p} {f : N ⇒ A} -> f ∘ (unwrap ∙ force) ≡ (f ∘ unwrap) ∙ force -> Linear f assoc-∘unwrap∙force→Linear {f = f} e {q = +} {g = g} {h = h} = begin f ∘ (g ∙ h) ≡˘⟨ cong (f ∘_) (cong (_∙ h) unwrap∙wrap∘) ⟩ f ∘ ((unwrap ∙ (wrap ∘ g)) ∙ h) ≡⟨ cong (f ∘_) assoc∙∙ ⟩ f ∘ (unwrap ∙ ((wrap ∘ g) ∙ h)) ≡⟨ helper2 e ⟩ (f ∘ unwrap) ∙ ((wrap ∘ g) ∙ h) ≡˘⟨ assoc∙∙ ⟩ ((f ∘ unwrap) ∙ (wrap ∘ g)) ∙ h ≡˘⟨ cong (_∙ h) assoc∙∘ ⟩ (((f ∘ unwrap) ∙ wrap) ∘ g) ∙ h ≡⟨ cong (_∙ h) (cong (_∘ g) ∘unwrap∙wrap) ⟩ (f ∘ g) ∙ h ∎ assoc-∘unwrap∙force→Linear e {q = ⊝} = sym assoc∘∘
{ "alphanum_fraction": 0.4359772852, "avg_line_length": 30.6685393258, "ext": "agda", "hexsha": "5b74c816e1007c6bbeeeea66af6346e156c9413a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "16def03e15bb8d71680bea60ae758ab37f4b2df9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "elpinal/duploids", "max_forks_repo_path": "Duploid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "16def03e15bb8d71680bea60ae758ab37f4b2df9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "elpinal/duploids", "max_issues_repo_path": "Duploid.agda", "max_line_length": 86, "max_stars_count": 5, "max_stars_repo_head_hexsha": "16def03e15bb8d71680bea60ae758ab37f4b2df9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "elpinal/duploids", "max_stars_repo_path": "Duploid.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-13T22:35:15.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-09T01:39:36.000Z", "num_tokens": 2710, "size": 5459 }
{- Kleisli category for a monad. -} module CategoryTheory.Instances.Kleisli where open import CategoryTheory.Categories open import CategoryTheory.Functor open import CategoryTheory.NatTrans open import CategoryTheory.Monad open Category -- Kleisli category from a category ℂ and a monad on ℂ Kleisli : ∀{n} -> (ℂ : Category n) -> Monad ℂ -> Category n Kleisli ℂ M = record { obj = ℂ.obj ; _~>_ = λ A B → A ℂ.~> T B ; id = λ {A} → η.at A ; _∘_ = λ {A}{B}{C} g f → (μ.at C ℂ.∘ fmap g) ℂ.∘ f ; _≈_ = ℂ._≈_ ; id-left = λ {A} {B} {f} → ℂ.≈-cong-left (η-unit2 {B}) ℂ.≈> ℂ.id-left ; id-right = id-right-K ; ∘-assoc = ∘-assoc-K ; ≈-equiv = ℂ.≈-equiv ; ≈-cong = λ p1 p2 → ℂ.≈-cong-right p1 ℂ.≈> ℂ.≈-cong-left (ℂ.≈-cong-right (fmap-cong p2)) } where private module ℂ = Category ℂ open Monad M renaming (T to F) open Functor F renaming (omap to T) id-right-K : {A B : ℂ.obj} {f : A ℂ.~> T B} → (μ.at B ℂ.∘ fmap f) ℂ.∘ η.at A ℂ.≈ f id-right-K {A}{B}{f}= ℂ.begin (μ.at B ℂ.∘ fmap f) ℂ.∘ η.at A ℂ.≈⟨ ℂ.∘-assoc ⟩ μ.at B ℂ.∘ (fmap f ℂ.∘ η.at A) ℂ.≈⟨ ℂ.≈-cong-right η.nat-cond ℂ.≈> ℂ.∘-assoc ℂ.[sym] ⟩ (μ.at B ℂ.∘ η.at (T B)) ℂ.∘ f ℂ.≈⟨ ℂ.≈-cong-left (η-unit1) ℂ.≈> ℂ.id-left ⟩ f ℂ.∎ ∘-assoc-K : {A B C D : ℂ.obj} {f : C ℂ.~> T D} {g : B ℂ.~> T C} {h : A ℂ.~> T B} → (μ.at D ℂ.∘ fmap ((μ.at D ℂ.∘ fmap f) ℂ.∘ g)) ℂ.∘ h ℂ.≈ (μ.at D ℂ.∘ fmap f) ℂ.∘ ((μ.at C ℂ.∘ fmap g) ℂ.∘ h) ∘-assoc-K {A}{B}{C}{D}{f}{g}{h} = ℂ.begin (μ.at D ℂ.∘ fmap ((μ.at D ℂ.∘ fmap f) ℂ.∘ g)) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.≈-cong-right fmap-∘) ⟩ (μ.at D ℂ.∘ (fmap (μ.at D ℂ.∘ fmap f) ℂ.∘ fmap g)) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.≈-cong-right (ℂ.≈-cong-left fmap-∘)) ⟩ (μ.at D ℂ.∘ ((fmap (μ.at D) ℂ.∘ fmap (fmap f)) ℂ.∘ fmap g)) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.∘-assoc ℂ.[sym]) ℂ.≈> ℂ.≈-cong-left (ℂ.≈-cong-left (ℂ.∘-assoc ℂ.[sym])) ⟩ (((μ.at D ℂ.∘ fmap (μ.at D)) ℂ.∘ fmap (fmap f)) ℂ.∘ fmap g) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.≈-cong-left (ℂ.≈-cong-left (μ-assoc ℂ.[sym]))) ⟩ (((μ.at D ℂ.∘ μ.at (T D)) ℂ.∘ fmap (fmap f)) ℂ.∘ fmap g) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.≈-cong-left (ℂ.∘-assoc)) ⟩ ((μ.at D ℂ.∘ (μ.at (T D) ℂ.∘ fmap (fmap f))) ℂ.∘ fmap g) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.≈-cong-left (ℂ.≈-cong-right (μ.nat-cond ℂ.[sym]))) ⟩ ((μ.at D ℂ.∘ (fmap f ℂ.∘ μ.at C)) ℂ.∘ fmap g) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.≈-cong-left (ℂ.∘-assoc ℂ.[sym])) ⟩ (((μ.at D ℂ.∘ fmap f) ℂ.∘ μ.at C) ℂ.∘ fmap g) ℂ.∘ h ℂ.≈⟨ ℂ.≈-cong-left (ℂ.∘-assoc) ℂ.≈> ℂ.∘-assoc ⟩ (μ.at D ℂ.∘ fmap f) ℂ.∘ ((μ.at C ℂ.∘ fmap g) ℂ.∘ h) ℂ.∎
{ "alphanum_fraction": 0.4599786553, "avg_line_length": 43.2461538462, "ext": "agda", "hexsha": "7d38a7e63fe443f8f5dd0b992f1a6d5214a9eda6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DimaSamoz/temporal-type-systems", "max_forks_repo_path": "src/CategoryTheory/Instances/Kleisli.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DimaSamoz/temporal-type-systems", "max_issues_repo_path": "src/CategoryTheory/Instances/Kleisli.agda", "max_line_length": 103, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DimaSamoz/temporal-type-systems", "max_stars_repo_path": "src/CategoryTheory/Instances/Kleisli.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z", "num_tokens": 1522, "size": 2811 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Argument visibility used in the reflection machinery ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Reflection.Argument.Visibility where open import Data.String as String using (String) open import Relation.Nullary open import Relation.Binary open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- Re-exporting the builtins publically open import Agda.Builtin.Reflection public using (Visibility) open Visibility public ------------------------------------------------------------------------ -- Decidable equality _≟_ : DecidableEquality Visibility visible ≟ visible = yes refl hidden ≟ hidden = yes refl instance′ ≟ instance′ = yes refl visible ≟ hidden = no λ() visible ≟ instance′ = no λ() hidden ≟ visible = no λ() hidden ≟ instance′ = no λ() instance′ ≟ visible = no λ() instance′ ≟ hidden = no λ()
{ "alphanum_fraction": 0.5270890725, "avg_line_length": 31.1142857143, "ext": "agda", "hexsha": "e6b51d8dcbe8ac185ef015183aed059e79ff2715", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Reflection/Argument/Visibility.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Reflection/Argument/Visibility.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Reflection/Argument/Visibility.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 200, "size": 1089 }
module NotNot where data ⊥ : Set where Not : Set → Set Not A = ⊥ Whoa : ∀ {A : Set} → Not (Not A) → A Whoa () postulate -- Law of excluded middle. LEM : ∀ {A : Set} → Not (Not A) → A Alright : ∀ {A : Set} → Not (Not A) → A Alright p = LEM p -- Constructive LEM requires hProp, hSet, Discrete, etc.
{ "alphanum_fraction": 0.5811688312, "avg_line_length": 16.2105263158, "ext": "agda", "hexsha": "899cde87a8395665251a72a46b1d4932aa63e42a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "anqurvanillapy/fpl", "max_forks_repo_path": "agda/NotNot.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "anqurvanillapy/fpl", "max_issues_repo_path": "agda/NotNot.agda", "max_line_length": 56, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "anqurvanillapy/fpl", "max_stars_repo_path": "agda/NotNot.agda", "max_stars_repo_stars_event_max_datetime": "2019-08-24T22:47:47.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-24T22:47:47.000Z", "num_tokens": 115, "size": 308 }
{-# OPTIONS --cubical --safe #-} module Cubical.Structures.AbGroup where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Data.Sigma open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS) open import Cubical.Structures.NAryOp open import Cubical.Structures.Group hiding (⟨_⟩) private variable ℓ : Level abelian-group-axioms : (X : Type ℓ) → raw-group-structure X → Type ℓ abelian-group-axioms X _·_ = group-axioms X _·_ × ((x y : X) → x · y ≡ y · x) abelian-group-structure : Type ℓ → Type ℓ abelian-group-structure = add-to-structure raw-group-structure abelian-group-axioms AbGroup : Type (ℓ-suc ℓ) AbGroup {ℓ} = TypeWithStr ℓ abelian-group-structure abelian-group-iso : StrIso abelian-group-structure ℓ abelian-group-iso = add-to-iso (nAryFunIso 2) abelian-group-axioms abelian-group-axioms-isProp : (X : Type ℓ) → (s : raw-group-structure X) → isProp (abelian-group-axioms X s) abelian-group-axioms-isProp X _·_ = isPropΣ (group-axioms-isProp X _·_) λ { ((isSetX , _) , _) → isPropΠ2 λ _ _ → isSetX _ _} abelian-group-is-SNS : SNS {ℓ} abelian-group-structure abelian-group-iso abelian-group-is-SNS = add-axioms-SNS _ abelian-group-axioms-isProp raw-group-is-SNS AbGroupPath : (M N : AbGroup {ℓ}) → (M ≃[ abelian-group-iso ] N) ≃ (M ≡ N) AbGroupPath = SIP abelian-group-is-SNS -- Abelian group is group AbGroup→Group : AbGroup {ℓ} → Group AbGroup→Group (G , _·_ , isGroup , ·comm) = G , _·_ , isGroup -- Abelian group extractors ⟨_⟩ : AbGroup {ℓ} → Type ℓ ⟨ G , _ ⟩ = G module _ (G : AbGroup {ℓ}) where abgroup-operation = group-operation (AbGroup→Group G) abgroup-is-set = group-is-set (AbGroup→Group G) abgroup-assoc = group-assoc (AbGroup→Group G) abgroup-id = group-id (AbGroup→Group G) abgroup-rid = group-rid (AbGroup→Group G) abgroup-lid = group-lid (AbGroup→Group G) abgroup-inv = group-inv (AbGroup→Group G) abgroup-rinv = group-rinv (AbGroup→Group G) abgroup-linv = group-linv (AbGroup→Group G) module abgroup-operation-syntax where abgroup-operation-syntax : (G : AbGroup {ℓ}) → ⟨ G ⟩ → ⟨ G ⟩ → ⟨ G ⟩ abgroup-operation-syntax G = abgroup-operation G infixr 20 abgroup-operation-syntax syntax abgroup-operation-syntax G x y = x ·⟨ G ⟩ y open abgroup-operation-syntax abgroup-comm : (G : AbGroup {ℓ}) (x y : ⟨ G ⟩) → x ·⟨ G ⟩ y ≡ y ·⟨ G ⟩ x abgroup-comm (_ , _ , _ , P) = P -- AbGroup ·syntax module abgroup-·syntax (G : AbGroup {ℓ}) where open group-·syntax (AbGroup→Group G) public
{ "alphanum_fraction": 0.6664176317, "avg_line_length": 30.4204545455, "ext": "agda", "hexsha": "4618dd97e3d0f79a29172ab731d07d5b13fa0c91", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmester0/cubical", "max_forks_repo_path": "Cubical/Structures/AbGroup.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cmester0/cubical", "max_issues_repo_path": "Cubical/Structures/AbGroup.agda", "max_line_length": 89, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmester0/cubical", "max_stars_repo_path": "Cubical/Structures/AbGroup.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z", "max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z", "num_tokens": 889, "size": 2677 }
-- Andreas, 2015-11-18, issue 1692 reported by m0davis -- {-# OPTIONS -v tc.with.top:20 #-} open import Common.Level open import Common.Equality open import Common.Product postulate Key : Set Value : Key → Set anyOf : ∀{A : Set} → A → A → A data Tree : Set where node : (k : Key) (v : Value k) → Tree data _∼_∈_ ( k : Key ) ( v : Value k ) : Tree → Set where here : k ∼ v ∈ node k v postulate k₁≡k₂ : ∀ ( k₁ k₂ : Key ) → k₁ ≡ k₂ ∈→v₁≡v₂ : ∀ { k } { v₁ v₂ : Value k } → k ∼ v₁ ∈ node k v₂ → v₁ ≡ v₂ lem : ( t₁ t₂ : Tree ) ( t₁→t₂ : ∀ {k} {v : Value k} → k ∼ v ∈ t₁ → k ∼ v ∈ t₂ ) ( t₂→t₁ : ∀ {k} {v : Value k} → k ∼ v ∈ t₂ → k ∼ v ∈ t₁ ) → ∃ λ t → ∀ {k} {v : Value k} → k ∼ v ∈ t → k ∼ v ∈ t lem (node k₁ v₁) (node k₂ v₂) t₁→t₂ t₂→t₁ rewrite k₁≡k₂ k₁ k₂ | ∈→v₁≡v₂ (t₁→t₂ here) -- equivalent to v₂ ≡ v₁ = _ , anyOf t₁→t₂ t₂→t₁ -- PROBLEM WAS: -- When the second rewrite expression is commented-out, then we get the following types: {- t₂→t₁ : {k : Key} {v : Value k} → k ∼ v ∈ node k₂ v₂ → k ∼ v ∈ node k₂ v₁ t₁→t₂ : {k : Key} {v : Value k} → k ∼ v ∈ node k₂ v₁ → k ∼ v ∈ node k₂ v₂ -} -- With both rewrite expressions, we get: {- t₂→t₁ : {k : Key} {v : Value k} → k ∼ v ∈ node k₂ v₂ → k ∼ v ∈ node k₂ v₂ t₁→t₂ : {k : Key} {v : Value k} → k ∼ v ∈ node k₂ v₁ → k ∼ v ∈ node k₂ v₂ -} -- The unexpected behavior here is that v₁ has been rewritten to v₂ in t₂→t₁ but not in t₁→t₂. -- Should be symmetric now, test case passes. -- Dual case: lem′ : ( t₁ t₂ : Tree ) ( t₁→t₂ : ∀ {k} {v : Value k} → k ∼ v ∈ t₁ → k ∼ v ∈ t₂ ) ( t₂→t₁ : ∀ {k} {v : Value k} → k ∼ v ∈ t₂ → k ∼ v ∈ t₁ ) → ∃ λ t → ∀ {k} {v : Value k} → k ∼ v ∈ t → k ∼ v ∈ t lem′ (node k₁ v₁) (node k₂ v₂) t₁→t₂ t₂→t₁ rewrite k₁≡k₂ k₁ k₂ | ∈→v₁≡v₂ (t₂→t₁ here) -- equivalent to v₁ ≡ v₂ = _ , anyOf t₁→t₂ t₂→t₁
{ "alphanum_fraction": 0.4915687276, "avg_line_length": 32.0819672131, "ext": "agda", "hexsha": "7829c769c63f468394011aa0affc71291ea86e2d", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue1692.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue1692.agda", "max_line_length": 94, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue1692.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 869, "size": 1957 }
------------------------------------------------------------------------ -- The rec construction can be encoded using λ-terms ------------------------------------------------------------------------ module Recursion-without-rec where open import Equality.Propositional.Cubical open import Prelude hiding (id; swap) import Finite-subset.Listed equality-with-paths as S -- To simplify the development, let's work with actual natural numbers -- as variables and constants (see -- Atom.one-can-restrict-attention-to-χ-ℕ-atoms). open import Atom open import Alpha-equivalence χ-ℕ-atoms open import Chi χ-ℕ-atoms open import Compatibility χ-ℕ-atoms open import Constants χ-ℕ-atoms open import Free-variables χ-ℕ-atoms open import Reasoning χ-ℕ-atoms open import Substitution χ-ℕ-atoms open import Values χ-ℕ-atoms open χ-atoms χ-ℕ-atoms open import Combinators using (id; id-closed) private variable A : Type R : A → A → Type x y z z₁ z₂ : Var e e′ v : Exp ------------------------------------------------------------------------ -- "Plain" lambda terms -- A predicate that holds for plain lambda terms, i.e. terms that are -- built up using only var, lambda and apply. Plain : Exp → Type Plain (var _) = ⊤ Plain (lambda _ e) = Plain e Plain (apply e₁ e₂) = Plain e₁ × Plain e₂ Plain (case _ _) = ⊥ Plain (rec _ _) = ⊥ Plain (const _ _) = ⊥ -- Plain is preserved by substitutions. plain-subst : ∀ e → Plain e → Plain e′ → Plain (e [ x ← e′ ]) plain-subst (apply e₁ e₂) (e₁-ok , e₂-ok) e′-ok = plain-subst e₁ e₁-ok e′-ok , plain-subst e₂ e₂-ok e′-ok plain-subst {x = x} (lambda y e) e-ok e′-ok with x V.≟ y … | yes _ = e-ok … | no _ = plain-subst e e-ok e′-ok plain-subst {x = x} (var y) _ e′-ok with x V.≟ y … | yes _ = e′-ok … | no _ = _ ------------------------------------------------------------------------ -- A variant of a fixpoint combinator -- A variant of the call-by-value fixpoint combinator Θᵥ that (at the -- time of writing) is presented on the Wikipedia page about -- fixed-point combinators -- (https://en.wikipedia.org/wiki/Fixed-point_combinator). There Θᵥ is -- defined to be the application of λxy.y(λz.xxyz) to itself. I have -- dropped the final z, and made the choice of variable name for z -- customisable. mutual F : Var → Exp F z = apply (f z) (f z) f : Var → Exp f z = lambda v-x (lambda v-y ( apply (var v-y) ( lambda z ( apply (apply (var v-x) (var v-x)) (var v-y))))) -- The expressions f z, F z and id are closed. f-closed : Closed (f z) f-closed = Closed′-closed-under-lambda $ Closed′-closed-under-lambda $ Closed′-closed-under-apply (from-⊎ (closed′? (var v-y) (v-y ∷ v-x ∷ []))) (Closed′-closed-under-lambda $ Closed′-closed-under-apply (Closed′-closed-under-apply (Closed′-closed-under-var (inj₂ (inj₂ (inj₁ refl)))) (Closed′-closed-under-var (inj₂ (inj₂ (inj₁ refl))))) (Closed′-closed-under-var (inj₂ (inj₁ refl)))) F-closed : Closed (F z) F-closed = Closed′-closed-under-apply f-closed f-closed -- F z₁ and f z₁ are α-equivalent to F z₂ and f z₂, respectively, -- assuming that z₁ and z₂ are distinct from v-x and v-y. f≈αf : z₁ ≢ v-x → z₁ ≢ v-y → z₂ ≢ v-x → z₂ ≢ v-y → Alpha R (f z₁) (f z₂) f≈αf {z₁ = z₁} {z₂ = z₂} {R = R} z₁≢x z₁≢y z₂≢x z₂≢y = lambda ( lambda ( apply (var y∼y₁) ( lambda ( apply ( apply (var x∼x) (var x∼x)) ( var y∼y₂))))) where x∼x : (R [ v-x ∼ v-x ] [ v-y ∼ v-y ] [ z₁ ∼ z₂ ]) v-x v-x x∼x = inj₂ (z₁≢x , z₂≢x , inj₂ ((λ ()) , (λ ()) , inj₁ (refl , refl))) y∼y₁ : (R [ v-x ∼ v-x ] [ v-y ∼ v-y ]) v-y v-y y∼y₁ = inj₁ (refl , refl) y∼y₂ : (R [ v-x ∼ v-x ] [ v-y ∼ v-y ] [ z₁ ∼ z₂ ]) v-y v-y y∼y₂ = inj₂ (z₁≢y , z₂≢y , y∼y₁) F≈αF : z₁ ≢ v-x → z₁ ≢ v-y → z₂ ≢ v-x → z₂ ≢ v-y → Alpha R (F z₁) (F z₂) F≈αF z₁≢x z₁≢y z₂≢x z₂≢y = apply (f≈αf z₁≢x z₁≢y z₂≢x z₂≢y) (f≈αf z₁≢x z₁≢y z₂≢x z₂≢y) ------------------------------------------------------------------------ -- A plain alternative to rec -- An expression former that has the same semantics as rec, but that -- takes plain expressions to plain expressions. -- -- Note that substitution does not necessarily behave in the same way -- for plain-rec as for rec (see below). plain-rec : Var → Exp → Exp plain-rec x e = let z , _ = fresh′ (S.from-List (v-x ∷ v-y ∷ [])) e in apply (lambda z (apply (F z) (lambda x (e [ x ← apply (var x) id ])))) id -- If e is a plain lambda term, then plain-rec x e is a plain -- lambda term. plain-rec-plain : ∀ e → Plain e → Plain (plain-rec x e) plain-rec-plain e ok = (_ , plain-subst e ok _) , _ -- The semantic rule given for rec is admissible for plain-rec. plain-rec-⇓ : ∀ e → e [ x ← plain-rec x e ] ⇓ v → plain-rec x e ⇓ v plain-rec-⇓ {x = x} {v = v} e ⇓v = plain-rec x e ⟶⟨⟩ apply (lambda z′ (apply (F z′) (lambda x (e [ x ← apply (var x) id ])))) id ⟶⟨ apply lambda lambda ⟩ apply (F z′) (lambda x (e [ x ← apply (var x) id ])) [ z′ ← id ] ≡⟨ subst-∉ z′ _ z∉apply ⟩⟶ apply (F z′) (lambda x (e [ x ← apply (var x) id ])) ⟶⟨ []⇓ (apply← ∙) F⇓ ⟩ apply (lambda v-y (apply (var v-y) (lambda z′ (apply (F z′) (var v-y))))) (lambda x (e [ x ← apply (var x) id ])) ⟶⟨ apply lambda lambda ⟩ apply (var v-y) (lambda z′ (apply (F z′) (var v-y))) [ v-y ← lambda x (e [ x ← apply (var x) id ]) ] ≡⟨ cong (apply _) (lambda-step-≢ y≢z) ⟩⟶ apply (lambda x (e [ x ← apply (var x) id ])) (lambda z′ (apply (F z′) (lambda x (e [ x ← apply (var x) id ])))) ⟶⟨ apply lambda lambda ⟩ e [ x ← apply (var x) id ] [ x ← lambda z′ (apply (F z′) (lambda x (e [ x ← apply (var x) id ]))) ] ≡⟨ fusion e ⟩⟶ e [ x ← apply (var x) id [ x ← lambda z′ (apply (F z′) (lambda x (e [ x ← apply (var x) id ]))) ] ] ≡⟨ cong₂ (λ e₁ e₂ → e [ x ← apply e₁ e₂ ]) (var-step-≡ (refl {x = x})) (subst-closed x _ id-closed) ⟩⟶ e [ x ← plain-rec x e ] ⇓⟨ ⇓v ⟩■ v where z,f = fresh′ (S.from-List (v-x ∷ v-y ∷ [])) e z′ : Var z′ = proj₁ z,f z∉e : ¬ z′ ∈FV e z∉e = proj₁ (proj₂ z,f) x≢z : v-x ≢ z′ x≢z x≡z = proj₂ (proj₂ z,f) (S.≡→∈∷ (sym x≡z)) y≢z : v-y ≢ z′ y≢z y≡z = proj₂ (proj₂ z,f) (S.∈→∈∷ (S.≡→∈∷ (sym y≡z))) F⇓ : F z′ ⇓ lambda v-y (apply (var v-y) (lambda z′ (apply (F z′) (var v-y)))) F⇓ = apply lambda lambda (lambda v-y (apply (var v-y) (lambda z′ (apply (apply (var v-x) (var v-x)) (var v-y)))) [ v-x ← f z′ ] ⟶⟨⟩ lambda v-y (apply (var v-y) (lambda z′ (apply (apply (var v-x) (var v-x)) (var v-y)) [ v-x ← f z′ ])) ≡⟨ cong (lambda _) $ cong (apply _) $ lambda-step-≢ x≢z ⟩⟶ lambda v-y (apply (var v-y) (lambda z′ (apply (F z′) (var v-y)))) ■⟨ lambda _ _ ⟩) z∉apply : ¬ z′ ∈FV apply (F z′) (lambda x (e [ x ← apply (var x) id ])) z∉apply (apply-left z∈Fz) = F-closed z′ (λ ()) z∈Fz z∉apply (apply-right (lambda z≢x z∈)) with subst-∈FV x e z∈ … | inj₁ (z∈e , _) = z∉e z∈e … | inj₂ (apply-left (var z≡x)) = z≢x z≡x … | inj₂ (apply-right z∈id) = id-closed z′ (λ ()) z∈id -- Substitution of closed expressions is not in general defined in the -- same way for plain-rec as for rec. ¬-plain-rec-subst : ¬ (∀ y e x e′ → Closed e′ → plain-rec y e [ x ← e′ ] ≡ plain-rec y (if x V.≟ y then e else e [ x ← e′ ])) ¬-plain-rec-subst plain-rec-subst = not-equal (plain-rec-subst y′ e₁ x′ e₂ id-closed) where y′ = v-y x′ = v-z e₂ = id e₁ = var x′ not-equal : plain-rec y′ e₁ [ x′ ← e₂ ] ≢ plain-rec y′ (if x′ V.≟ y′ then e₁ else e₁ [ x′ ← e₂ ]) not-equal () -- However, it is defined in the same way /up to α-equivalence/. plain-rec-subst : ∀ x → Closed e′ → plain-rec y e [ x ← e′ ] ≈α plain-rec y (if x V.≟ y then e else e [ x ← e′ ]) plain-rec-subst {e′ = e′} {y = y} {e = e} x cl-e′ = apply (lambda z¹ (apply (F z¹) (lambda y (e [ y ← apply (var y) id ])))) id [ x ← e′ ] ≡⟨ cong (apply _) $ subst-closed x _ id-closed ⟩α apply (lambda z¹ (apply (F z¹) (lambda y (e [ y ← apply (var y) id ]))) [ x ← e′ ]) id ≡⟨ cong (λ e → apply (lambda z¹ e) id) $ lemma₁ (x V.≟ z¹) (x V.≟ y) ⟩α apply (lambda z¹ (apply (F z¹) (lambda y ((if x V.≟ y then e else e [ x ← e′ ]) [ y ← apply (var y) id ])))) id ≈⟨ apply (lambda (apply (F≈αF z¹≢x z¹≢y z²≢x z²≢y) (refl-Alpha _ lemma₂))) refl-α ⟩α∎ apply (lambda z² (apply (F z²) (lambda y ((if x V.≟ y then e else e [ x ← e′ ]) [ y ← apply (var y) id ])))) id ∎ where z¹,f₁ = fresh′ (S.from-List (v-x ∷ v-y ∷ [])) e z¹ : Var z¹ = proj₁ z¹,f₁ z¹∉e : ¬ z¹ ∈FV e z¹∉e = proj₁ (proj₂ z¹,f₁) z¹≢x : z¹ ≢ v-x z¹≢x z¹≡x = proj₂ (proj₂ z¹,f₁) (S.≡→∈∷ z¹≡x) z¹≢y : z¹ ≢ v-y z¹≢y z¹≡y = proj₂ (proj₂ z¹,f₁) (S.∈→∈∷ (S.≡→∈∷ z¹≡y)) z²,f₂ = fresh′ (S.from-List (v-x ∷ v-y ∷ [])) (if x V.≟ y then e else e [ x ← e′ ]) z² : Var z² = proj₁ z²,f₂ z²∉ : ¬ z² ∈FV if x V.≟ y then e else e [ x ← e′ ] z²∉ = proj₁ (proj₂ z²,f₂) z²≢x : z² ≢ v-x z²≢x z²≡x = proj₂ (proj₂ z²,f₂) (S.≡→∈∷ z²≡x) z²≢y : z² ≢ v-y z²≢y z²≡y = proj₂ (proj₂ z²,f₂) (S.∈→∈∷ (S.≡→∈∷ z²≡y)) x∉y-id : x ≢ y → ¬ x ∈FV apply (var y) id x∉y-id x≢y (apply-left (var x≡y)) = x≢y x≡y x∉y-id _ (apply-right x∈id) = id-closed x (λ ()) x∈id lemma₁ : (x≟z¹ : Dec (x ≡ z¹)) (x≟y : Dec (x ≡ y)) → if x≟z¹ then apply (F z¹) (lambda y (e [ y ← apply (var y) id ])) else apply (F z¹) (lambda y (e [ y ← apply (var y) id ])) [ x ← e′ ] ≡ apply (F z¹) (lambda y ((if x≟y then e else e [ x ← e′ ]) [ y ← apply (var y) id ])) lemma₁ (yes _) (yes _) = refl lemma₁ (yes x≡z¹) (no _) = apply (F z¹) (lambda y (e [ y ← apply (var y) id ])) ≡⟨ cong (apply _) $ cong (lambda _) $ cong (_[ _ ← _ ]) $ sym $ subst-∉ x e (z¹∉e ∘ subst (_∈FV _) x≡z¹) ⟩∎ apply (F z¹) (lambda y (e [ x ← e′ ] [ y ← apply (var y) id ])) ∎ lemma₁ (no _) (yes x≡y) = apply (F z¹ [ x ← e′ ]) (lambda y (e [ y ← apply (var y) id ]) [ x ← e′ ]) ≡⟨ cong (λ e″ → apply e″ (lambda y (e [ y ← apply (var y) id ]) [ x ← e′ ])) $ subst-closed x e′ F-closed ⟩ apply (F z¹) (lambda y (e [ y ← apply (var y) id ]) [ x ← e′ ]) ≡⟨ cong (apply (F z¹)) $ lambda-step-≡ x≡y ⟩∎ apply (F z¹) (lambda y (e [ y ← apply (var y) id ])) ∎ lemma₁ (no _) (no x≢y) = apply (F z¹ [ x ← e′ ]) (lambda y (e [ y ← apply (var y) id ]) [ x ← e′ ]) ≡⟨ cong (λ e″ → apply e″ (lambda y (e [ y ← apply (var y) id ]) [ x ← e′ ])) $ subst-closed x e′ F-closed ⟩ apply (F z¹) (lambda y (e [ y ← apply (var y) id ]) [ x ← e′ ]) ≡⟨ cong (apply (F z¹)) $ lambda-step-≢ x≢y ⟩ apply (F z¹) (lambda y (e [ y ← apply (var y) id ] [ x ← e′ ])) ≡⟨ cong (apply _) $ cong (lambda _) $ sym $ swap x≢y (x∉y-id x≢y) (cl-e′ _ (λ ())) e ⟩∎ apply (F z¹) (lambda y (e [ x ← e′ ] [ y ← apply (var y) id ])) ∎ lemma₂ : ∀ z → z ∈FV lambda y ((if x V.≟ y then e else e [ x ← e′ ]) [ y ← apply (var y) id ]) → (_≡_ [ z¹ ∼ z² ]) z z lemma₂ z (lambda z≢y z∈) = case subst-∈FV y _ z∈ of λ where (inj₁ (z∈ , _)) → inj₂ ( z¹≢ (x V.≟ y) z∈ , z²∉ ∘ flip (subst (_∈FV _)) z∈ ∘ sym , refl ) (inj₂ (apply-left (var z≡y))) → ⊥-elim $ z≢y z≡y (inj₂ (apply-right ∈id)) → ⊥-elim $ id-closed _ (λ ()) ∈id where z¹≢ : ∀ x≟y → z ∈FV if x≟y then e else e [ x ← e′ ] → z¹ ≢ z z¹≢ (yes _) z∈ = z¹∉e ∘ flip (subst (_∈FV _)) z∈ ∘ sym z¹≢ (no _) z∈ = case subst-∈FV x e z∈ of λ where (inj₁ (z∈ , _)) → z¹∉e ∘ flip (subst (_∈FV _)) z∈ ∘ sym (inj₂ z∈e′) → ⊥-elim $ cl-e′ _ (λ ()) z∈e′
{ "alphanum_fraction": 0.431491953, "avg_line_length": 35.3692307692, "ext": "agda", "hexsha": "dd7baa0a367ca4c363e0842fd44f7a4ea1c32ec5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/chi", "max_forks_repo_path": "src/Recursion-without-rec.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z", "max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/chi", "max_issues_repo_path": "src/Recursion-without-rec.agda", "max_line_length": 132, "max_stars_count": 2, "max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/chi", "max_stars_repo_path": "src/Recursion-without-rec.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z", "num_tokens": 5029, "size": 13794 }
-- TODO -- Basic Tarski-style semantics, for soundness only. module BasicT.Semantics.BasicTarski where open import BasicT.Syntax.Common public -- Tarski models. record Model : Set₁ where infix 3 ⊩ᵅ_ field -- Forcing for atomic propositions. ⊩ᵅ_ : Atom → Set open Model {{…}} public -- Forcing in a particular model. module _ {{_ : Model}} where infix 3 ⊩_ ⊩_ : Ty → Set ⊩ α P = ⊩ᵅ P ⊩ A ▻ B = ⊩ A → ⊩ B ⊩ A ∧ B = ⊩ A × ⊩ B ⊩ ⊤ = 𝟙 ⊩ BOOL = 𝔹 ⊩ NAT = ℕ infix 3 ⊩⋆_ ⊩⋆_ : Cx Ty → Set ⊩⋆ ∅ = 𝟙 ⊩⋆ Ξ , A = ⊩⋆ Ξ × ⊩ A -- Entailment, or forcing in all models. infix 3 ⊨_ ⊨_ : Ty → Set₁ ⊨ A = ∀ {{_ : Model}} → ⊩ A -- Forcing in a particular model, for sequents. module _ {{_ : Model}} where infix 3 ⊩_⇒_ ⊩_⇒_ : Cx Ty → Ty → Set ⊩ Γ ⇒ A = ⊩⋆ Γ → ⊩ A infix 3 ⊩_⇒⋆_ ⊩_⇒⋆_ : Cx Ty → Cx Ty → Set ⊩ Γ ⇒⋆ Ξ = ⊩⋆ Γ → ⊩⋆ Ξ -- Entailment, or forcing in all models, for sequents. infix 3 _⊨_ _⊨_ : Cx Ty → Ty → Set₁ Γ ⊨ A = ∀ {{_ : Model}} → ⊩ Γ ⇒ A infix 3 _⊨⋆_ _⊨⋆_ : Cx Ty → Cx Ty → Set₁ Γ ⊨⋆ Ξ = ∀ {{_ : Model}} → ⊩ Γ ⇒⋆ Ξ -- Additional useful equipment, for sequents. module _ {{_ : Model}} where lookup : ∀ {A Γ} → A ∈ Γ → ⊩ Γ ⇒ A lookup top (γ , a) = a lookup (pop i) (γ , b) = lookup i γ ⟦λ⟧ : ∀ {A B Γ} → ⊩ Γ , A ⇒ B → ⊩ Γ ⇒ A ▻ B ⟦λ⟧ f γ = λ a → f (γ , a) _⟦$⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ A ▻ B → ⊩ Γ ⇒ A → ⊩ Γ ⇒ B (f ⟦$⟧ g) γ = f γ $ g γ ⟦S⟧ : ∀ {A B C Γ} → ⊩ Γ ⇒ A ▻ B ▻ C → ⊩ Γ ⇒ A ▻ B → ⊩ Γ ⇒ A → ⊩ Γ ⇒ C ⟦S⟧ f g a γ = S (f γ) (g γ) (a γ) _⟦,⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ A → ⊩ Γ ⇒ B → ⊩ Γ ⇒ A ∧ B (a ⟦,⟧ b) γ = a γ , b γ ⟦π₁⟧ : ∀ {A B Γ} → ⊩ Γ ⇒ A ∧ B → ⊩ Γ ⇒ A ⟦π₁⟧ s γ = π₁ (s γ) ⟦π₂⟧ : ∀ {A B Γ} → ⊩ Γ ⇒ A ∧ B → ⊩ Γ ⇒ B ⟦π₂⟧ s γ = π₂ (s γ)
{ "alphanum_fraction": 0.4488863507, "avg_line_length": 19.0326086957, "ext": "agda", "hexsha": "8f23302adcb9525b086a167761e6037299d0cd8b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/hilbert-gentzen", "max_forks_repo_path": "BasicT/Semantics/BasicTarski.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/hilbert-gentzen", "max_issues_repo_path": "BasicT/Semantics/BasicTarski.agda", "max_line_length": 71, "max_stars_count": 29, "max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/hilbert-gentzen", "max_stars_repo_path": "BasicT/Semantics/BasicTarski.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z", "num_tokens": 934, "size": 1751 }
open import Agda.Primitive record Setoid (a : Level) : Set₁ where constructor mk field carrier : Set record HeytingAlgebra {a} (setoid : Setoid a) (A : Set) : Set a where constructor laws open Setoid setoid field ∧-cong : carrier
{ "alphanum_fraction": 0.6963562753, "avg_line_length": 19, "ext": "agda", "hexsha": "fe594bee10c1faca2f513b31c5d2ea065de4e5e3", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue3123.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue3123.agda", "max_line_length": 69, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue3123.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 79, "size": 247 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module Bottom where open import Common.FOL.FOL-Eq postulate bot : ⊥ postulate zero : D succ : D → D postulate false : zero ≡ succ zero {-# ATP prove false bot #-} -- $ apia -isrc -inotes/papers/FoSSaCS-2012/ notes/papers/FoSSaCS-2012/Bottom.agda -- Proving the conjecture in /tmp/Bottom/16-false.tptp ... -- Vampire 0.6 (revision 903) proved the conjecture in /tmp/Bottom/16-false.tptp
{ "alphanum_fraction": 0.6344463972, "avg_line_length": 25.8636363636, "ext": "agda", "hexsha": "ea6fb9c93e31af502a592d6e504ffad0edcea485", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/papers/fossacs-2012/Bottom.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/papers/fossacs-2012/Bottom.agda", "max_line_length": 83, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/papers/fossacs-2012/Bottom.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 169, "size": 569 }
------------------------------------------------------------------------ -- Unit tests for Tactic.By.Parametrised ------------------------------------------------------------------------ -- Nothing is exported from this module. {-# OPTIONS --without-K --safe #-} open import Equality module Tactic.By.Parametrised.Tests {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where open Derived-definitions-and-properties eq open import Prelude open import Maybe eq open import Monad eq open import TC-monad eq hiding (Type) open import Tactic.By.Parametrised eq ------------------------------------------------------------------------ -- Some unit tests private module Tests (assumption : 48 ≡ 42) (lemma : ∀ n → n + 8 ≡ n + 2) (f : ℕ → ℕ → ℕ → ℕ) where g : ℕ → ℕ → ℕ → ℕ g zero _ _ = 12 g (suc _) _ _ = 12 fst : ∀ {a b} {A : Type a} {B : A → Type b} → Σ A B → A fst = proj₁ {-# NOINLINE fst #-} record R (F : Type → Type) : Type₁ where field p : {A : Type} {x : F A} → x ≡ x open R ⦃ … ⦄ public test₁ : ⟨ 40 + 2 ⟩ ≡ 42 test₁ = ⟨by⟩ refl test₂ : 48 ≡ 42 → ⟨ 42 ⟩ ≡ 48 test₂ eq = ⟨by⟩ eq test₃ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₃ f = ⟨by⟩ assumption test₄ : (f : ℕ → ℕ) → f ⟨ 48 ⟩ ≡ f 42 test₄ f = ⟨by⟩ assumption test₅ : (f : ℕ → ℕ → ℕ) → f ⟨ 42 ⟩ ⟨ 42 ⟩ ≡ f 48 48 test₅ f = ⟨by⟩ assumption test₆ : (f : ℕ → ℕ → ℕ → ℕ) → f ⟨ 48 ⟩ 45 ⟨ 48 ⟩ ≡ f 42 45 42 test₆ f = ⟨by⟩ assumption test₇ : f ⟨ 48 ⟩ (f ⟨ 48 ⟩ 45 ⟨ 48 ⟩) ⟨ 48 ⟩ ≡ f 42 (f 42 45 42) 42 test₇ = ⟨by⟩ assumption test₈ : ∀ n → g n (g n 45 ⟨ 48 ⟩) ⟨ 48 ⟩ ≡ g n (g n 45 42) 42 test₈ n = ⟨by⟩ assumption test₉ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₉ f = ⟨by⟩ (lemma 40) test₁₀ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₁₀ f = ⟨by⟩ (λ (_ : ⊤) → assumption) test₁₁ : (f : ℕ × ℕ → ℕ × ℕ) → (∀ x → ⟨ _≡_ ⟩ (f x) x) → fst ⟨ f (12 , 73) ⟩ ≡ fst {B = λ _ → ℕ} (12 , 73) test₁₁ _ hyp = ⟨by⟩ hyp test₁₂ : (h : ℕ → Maybe ℕ) → ((xs : ℕ) → h xs ≡ just xs) → (xs : ℕ) → suc ⟨$⟩ h xs ≡ suc ⟨$⟩ return xs test₁₂ h hyp xs = suc ⟨$⟩ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ suc ⟨$⟩ return xs ∎ test₁₃ : (h : List ⊤ → Maybe (List ⊤)) → ((xs : List ⊤) → h xs ≡ just xs) → (x : ⊤) (xs : List ⊤) → _ test₁₃ h hyp x xs = _∷_ ⟨$⟩ return x ⊛ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ _∷_ ⟨$⟩ return x ⊛ return xs ∎ test₁₄ : (h : List ℕ → Maybe (List ℕ)) → ((xs : List ℕ) → h xs ≡ just xs) → (x : ℕ) (xs : List ℕ) → _ test₁₄ h hyp x xs = _∷_ ⟨$⟩ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ _∷_ ⟨$⟩ return xs ∎ test₁₅ : (F : Type → Type → Type) (G : Bool → Type → Type) → ((A : Type) → F (G false A) A ≡ G false (F A A)) → (A : Type) → G false (F (G false A) A) ≡ G false (G false (F A A)) test₁₅ F G hyp A = G false ⟨ F (G false A) A ⟩ ≡⟨ ⟨by⟩ hyp ⟩∎ G false (G false (F A A)) ∎ test₁₆ : 48 ≡ 42 → _≡_ {A = ℕ → ℕ} (λ x → x + ⟨ 42 ⟩) (λ x → x + 48) test₁₆ hyp = ⟨by⟩ hyp test₁₇ : (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f ⟨ subst P (refl _) p ⟩ ≡ f p test₁₇ _ _ _ = ⟨by⟩ subst-refl test₁₈ : (subst′ : ∀ {a p} {A : Type a} {x y : A} (P : A → Type p) → x ≡ y → P x → P y) → (∀ {a p} {A : Type a} {x : A} (P : A → Type p) (p : P x) → subst′ P (refl x) p ≡ p) → (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f ⟨ subst′ P (refl 0) p ⟩ ≡ f p test₁₈ _ subst′-refl _ _ _ = ⟨by⟩ subst′-refl -- test₁₉ : -- {F : Type → Type} ⦃ r : R F ⦄ {A : Type} {x₁ x₂ : F A} -- (p₁ p₂ : x₁ ≡ x₂) (assumption : p₁ ≡ p₂) → -- trans p p₁ ≡ trans p p₂ -- test₁₉ p₁ p₂ assumption = -- trans p p₁ ≡⟨⟩ -- trans p ⟨ p₁ ⟩ ≡⟨ ⟨by⟩ assumption ⟩∎ -- trans p p₂ ∎
{ "alphanum_fraction": 0.4024813896, "avg_line_length": 27.2297297297, "ext": "agda", "hexsha": "4648826708ff4b31f31866ecf038bf1bad33e0e9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Tactic/By/Parametrised/Tests.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/equality", "max_issues_repo_path": "src/Tactic/By/Parametrised/Tests.agda", "max_line_length": 72, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Tactic/By/Parametrised/Tests.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 1709, "size": 4030 }
------------------------------------------------------------------------ -- A parametrised coinductive definition that can be used to define -- strong and weak bisimilarity as well as expansion ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Prelude open import Labelled-transition-system module Bisimilarity.General {ℓ} (lts : LTS ℓ) (open LTS lts) (_[_]↝₁_ _[_]↝₂_ : Proc → Label → Proc → Type ℓ) (⟶→↝₁ : ∀ {p μ q} → p [ μ ]⟶ q → p [ μ ]↝₁ q) (⟶→↝₂ : ∀ {p μ q} → p [ μ ]⟶ q → p [ μ ]↝₂ q) where open import Equality.Propositional as Eq hiding (Extensionality) open import Logical-equivalence using (_⇔_) open import Prelude.Size open import Bijection equality-with-J as Bijection using (_↔_) open import Function-universe equality-with-J hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import Bisimilarity.Step lts _[_]↝₁_ _[_]↝₂_ as Step public using (StepC) open import Indexed-container hiding (⟨_⟩; Bisimilarity) open import Indexed-container.Combinators hiding (id; _∘_) open import Relation import Similarity.Step lts _[_]↝₁_ as Step₁ import Similarity.Step lts _[_]↝₂_ as Step₂ open Indexed-container public using (force) ------------------------------------------------------------------------ -- Bisimilarity -- Bisimilarity. Note that this definition is small. infix 4 _∼_ _∼′_ [_]_∼_ [_]_∼′_ Bisimilarity : Size → Rel₂ ℓ Proc Bisimilarity = ν StepC Bisimilarity′ : Size → Rel₂ ℓ Proc Bisimilarity′ = ν′ StepC [_]_∼_ : Size → Proc → Proc → Type ℓ [_]_∼_ i = curry (Bisimilarity i) [_]_∼′_ : Size → Proc → Proc → Type ℓ [_]_∼′_ i = curry (Bisimilarity′ i) _∼_ : Proc → Proc → Type ℓ _∼_ = [ ∞ ]_∼_ _∼′_ : Proc → Proc → Type ℓ _∼′_ = [ ∞ ]_∼′_ -- Bisimilarity is reflexive. mutual reflexive-∼ : ∀ {p i} → [ i ] p ∼ p reflexive-∼ = StepC.⟨ (λ p⟶p′ → _ , ⟶→↝₁ p⟶p′ , reflexive-∼′) , (λ q⟶q′ → _ , ⟶→↝₂ q⟶q′ , reflexive-∼′) ⟩ reflexive-∼′ : ∀ {p i} → [ i ] p ∼′ p force reflexive-∼′ = reflexive-∼ ≡⇒∼ : ∀ {p q} → p ≡ q → p ∼ q ≡⇒∼ refl = reflexive-∼ -- Functions that can be used to aid the instance resolution -- mechanism. infix -2 ∼:_ ∼′:_ ∼:_ : ∀ {i p q} → [ i ] p ∼ q → [ i ] p ∼ q ∼:_ = id ∼′:_ : ∀ {i p q} → [ i ] p ∼′ q → [ i ] p ∼′ q ∼′:_ = id ------------------------------------------------------------------------ -- Bisimilarity for bisimilarity -- Bisimilarity of bisimilarity proofs. infix 4 [_]_≡_ [_]_≡′_ [_]_≡_ : ∀ {p q} → Size → (_ _ : ν StepC ∞ (p , q)) → Type ℓ [_]_≡_ i = curry (ν-bisimilar i) [_]_≡′_ : ∀ {p q} → Size → (_ _ : ν′ StepC ∞ (p , q)) → Type ℓ [_]_≡′_ i = curry (ν′-bisimilar i) -- An alternative characterisation of bisimilarity of bisimilarity -- proofs. []≡↔ : Eq.Extensionality ℓ ℓ → ∀ {p q} {i : Size} (p∼q₁ p∼q₂ : ν StepC ∞ (p , q)) → [ i ] p∼q₁ ≡ p∼q₂ ↔ (∀ {p′ μ} (p⟶p′ : p [ μ ]⟶ p′) → let q′₁ , q⟶q′₁ , p′∼q′₁ = StepC.left-to-right p∼q₁ p⟶p′ q′₂ , q⟶q′₂ , p′∼q′₂ = StepC.left-to-right p∼q₂ p⟶p′ in ∃ λ (q′₁≡q′₂ : q′₁ ≡ q′₂) → subst (q [ μ ]↝₁_) q′₁≡q′₂ q⟶q′₁ ≡ q⟶q′₂ × [ i ] subst (ν′ StepC ∞ ∘ (p′ ,_)) q′₁≡q′₂ p′∼q′₁ ≡′ p′∼q′₂) × (∀ {q′ μ} (q⟶q′ : q [ μ ]⟶ q′) → let p′₁ , p⟶p′₁ , p′∼q′₁ = StepC.right-to-left p∼q₁ q⟶q′ p′₂ , p⟶p′₂ , p′∼q′₂ = StepC.right-to-left p∼q₂ q⟶q′ in ∃ λ (p′₁≡p′₂ : p′₁ ≡ p′₂) → subst (p [ μ ]↝₂_) p′₁≡p′₂ p⟶p′₁ ≡ p⟶p′₂ × [ i ] subst (ν′ StepC ∞ ∘ (_, q′)) p′₁≡p′₂ p′∼q′₁ ≡′ p′∼q′₂) []≡↔ ext {p} {q} {i} p∼q₁@(s₁ , f₁) p∼q₂@(s₂ , f₂) = [ i ] p∼q₁ ≡ p∼q₂ ↝⟨ ν-bisimilar↔ ext p∼q₁ p∼q₂ ⟩ ⟦ StepC₁ ⟷ StepC₂ ⟧₂ (ν′-bisimilar i) (p∼q₁ , p∼q₂) ↝⟨ ⟦⟷⟧₂↔ ext StepC₁ StepC₂ (ν′-bisimilar i) p∼q₁ p∼q₂ ⟩ ⟦ StepC₁ ⟧₂ (ν′-bisimilar i) ((proj₁ s₁ , f₁ ∘ inj₁) , (proj₁ s₂ , f₂ ∘ inj₁)) × ⟦ StepC₂ ⟧₂ (ν′-bisimilar i) ( (proj₂ s₁ , λ p → f₁ (inj₂ (_ , refl , p))) , (proj₂ s₂ , λ p → f₂ (inj₂ (_ , refl , p))) ) ↝⟨ Step₁.⟦StepC⟧₂↔ ext (ν′-bisimilar i) (proj₁ s₁ , f₁ ∘ inj₁) (proj₁ s₂ , f₂ ∘ inj₁) ×-cong Step₂.⟦StepC⟧₂↔ ext (ν′-bisimilar i) (proj₂ s₁ , λ p → f₁ (inj₂ (_ , refl , p))) (proj₂ s₂ , λ p → f₂ (inj₂ (_ , refl , p))) ⟩ (∀ {p′ μ} (p⟶p′ : p [ μ ]⟶ p′) → let q′₁ , q⟶q′₁ , p′∼q′₁ = Step₁.StepC.challenge (proj₁ s₁ , f₁ ∘ inj₁) p⟶p′ q′₂ , q⟶q′₂ , p′∼q′₂ = Step₁.StepC.challenge (proj₁ s₂ , f₂ ∘ inj₁) p⟶p′ in ∃ λ (q′₁≡q′₂ : q′₁ ≡ q′₂) → subst (q [ μ ]↝₁_) q′₁≡q′₂ q⟶q′₁ ≡ q⟶q′₂ × [ i ] subst (ν′ StepC ∞ ∘ (p′ ,_)) q′₁≡q′₂ p′∼q′₁ ≡′ p′∼q′₂) × ((∀ {q′ μ} (q⟶q′ : q [ μ ]⟶ q′) → let p′₁ , p⟶p′₁ , p′∼q′₁ = Step₂.StepC.challenge (proj₂ s₁ , λ p → f₁ (inj₂ (_ , refl , p))) q⟶q′ p′₂ , p⟶p′₂ , p′∼q′₂ = Step₂.StepC.challenge (proj₂ s₂ , λ p → f₂ (inj₂ (_ , refl , p))) q⟶q′ in ∃ λ (p′₁≡p′₂ : p′₁ ≡ p′₂) → subst (p [ μ ]↝₂_) p′₁≡p′₂ p⟶p′₁ ≡ p⟶p′₂ × [ i ] subst (ν′ StepC ∞ ∘ (_, q′)) p′₁≡p′₂ p′∼q′₁ ≡′ p′∼q′₂)) ↔⟨⟩ (∀ {p′ μ} (p⟶p′ : p [ μ ]⟶ p′) → let q′₁ , q⟶q′₁ , p′∼q′₁ = StepC.left-to-right p∼q₁ p⟶p′ q′₂ , q⟶q′₂ , p′∼q′₂ = StepC.left-to-right p∼q₂ p⟶p′ in ∃ λ (q′₁≡q′₂ : q′₁ ≡ q′₂) → subst (q [ μ ]↝₁_) q′₁≡q′₂ q⟶q′₁ ≡ q⟶q′₂ × [ i ] subst (ν′ StepC ∞ ∘ (p′ ,_)) q′₁≡q′₂ p′∼q′₁ ≡′ p′∼q′₂) × (∀ {q′ μ} (q⟶q′ : q [ μ ]⟶ q′) → let p′₁ , p⟶p′₁ , p′∼q′₁ = StepC.right-to-left p∼q₁ q⟶q′ p′₂ , p⟶p′₂ , p′∼q′₂ = StepC.right-to-left p∼q₂ q⟶q′ in ∃ λ (p′₁≡p′₂ : p′₁ ≡ p′₂) → subst (p [ μ ]↝₂_) p′₁≡p′₂ p⟶p′₁ ≡ p⟶p′₂ × [ i ] subst (ν′ StepC ∞ ∘ (_, q′)) p′₁≡p′₂ p′∼q′₁ ≡′ p′∼q′₂) □ where open Container StepC₁ = Step₁.StepC StepC₂ = Step₂.StepC module Bisimilarity-of-∼ (ext : Eq.Extensionality ℓ ℓ) {p q} {i : Size} (p∼q₁ p∼q₂ : ν StepC ∞ (p , q)) where -- A "constructor". ⟨_,_,_,_,_⟩ : (∀ {p′ μ} (p⟶p′ : p [ μ ]⟶ p′) → let q′₁ , q⟶q′₁ , p′∼q′₁ = StepC.left-to-right p∼q₁ p⟶p′ q′₂ , q⟶q′₂ , p′∼q′₂ = StepC.left-to-right p∼q₂ p⟶p′ in ∃ λ (q′₁≡q′₂ : q′₁ ≡ q′₂) → subst (q [ μ ]↝₁_) q′₁≡q′₂ q⟶q′₁ ≡ q⟶q′₂ × [ i ] subst (ν′ StepC ∞ ∘ (p′ ,_)) q′₁≡q′₂ p′∼q′₁ ≡′ p′∼q′₂) → (∀ {q′ μ} (q⟶q′ : q [ μ ]⟶ q′) → let p′₁ , p⟶p′₁ , p′∼q′₁ = StepC.right-to-left p∼q₁ q⟶q′ p′₂ , p⟶p′₂ , p′∼q′₂ = StepC.right-to-left p∼q₂ q⟶q′ in ∃ λ (p′₁≡p′₂ : p′₁ ≡ p′₂) → subst (p [ μ ]↝₂_) p′₁≡p′₂ p⟶p′₁ ≡ p⟶p′₂ × [ i ] subst (ν′ StepC ∞ ∘ (_, q′)) p′₁≡p′₂ p′∼q′₁ ≡′ p′∼q′₂) → [ i ] p∼q₁ ≡ p∼q₂ ⟨_,_,_,_,_⟩ = curry (_↔_.from ([]≡↔ ext p∼q₁ p∼q₂)) -- Some "projections". left-to-right : [ i ] p∼q₁ ≡ p∼q₂ → ∀ {p′ μ} (p⟶p′ : p [ μ ]⟶ p′) → let q′₁ , q⟶q′₁ , p′∼q′₁ = StepC.left-to-right p∼q₁ p⟶p′ q′₂ , q⟶q′₂ , p′∼q′₂ = StepC.left-to-right p∼q₂ p⟶p′ in ∃ λ (q′₁≡q′₂ : q′₁ ≡ q′₂) → subst (q [ μ ]↝₁_) q′₁≡q′₂ q⟶q′₁ ≡ q⟶q′₂ × [ i ] subst (ν′ StepC ∞ ∘ (p′ ,_)) q′₁≡q′₂ p′∼q′₁ ≡′ p′∼q′₂ left-to-right = proj₁ ∘ _↔_.to ([]≡↔ ext p∼q₁ p∼q₂) right-to-left : [ i ] p∼q₁ ≡ p∼q₂ → ∀ {q′ μ} (q⟶q′ : q [ μ ]⟶ q′) → let p′₁ , p⟶p′₁ , p′∼q′₁ = StepC.right-to-left p∼q₁ q⟶q′ p′₂ , p⟶p′₂ , p′∼q′₂ = StepC.right-to-left p∼q₂ q⟶q′ in ∃ λ (p′₁≡p′₂ : p′₁ ≡ p′₂) → subst (p [ μ ]↝₂_) p′₁≡p′₂ p⟶p′₁ ≡ p⟶p′₂ × [ i ] subst (ν′ StepC ∞ ∘ (_, q′)) p′₁≡p′₂ p′∼q′₁ ≡′ p′∼q′₂ right-to-left = proj₂ ∘ _↔_.to ([]≡↔ ext p∼q₁ p∼q₂) -- A statement of extensionality for bisimilarity. Extensionality : Type ℓ Extensionality = ν′-extensionality StepC -- This form of extensionality can be used to derive another form -- (in the presence of extensionality for functions). extensionality : Eq.Extensionality ℓ ℓ → Extensionality → ∀ {p q} {p∼q₁ p∼q₂ : ν StepC ∞ (p , q)} → [ ∞ ] p∼q₁ ≡ p∼q₂ → p∼q₁ ≡ p∼q₂ extensionality ext ν-ext = ν-extensionality ext ν-ext open StepC public using (⟨_,_⟩; left-to-right; right-to-left)
{ "alphanum_fraction": 0.441782794, "avg_line_length": 33.3961538462, "ext": "agda", "hexsha": "a25f2fa396a068d829cebb7ac522bf09601ce934", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "src/Bisimilarity/General.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "src/Bisimilarity/General.agda", "max_line_length": 133, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "src/Bisimilarity/General.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4066, "size": 8683 }
------------------------------------------------------------------------ -- Some theory of Erased, developed using Cubical Agda ------------------------------------------------------------------------ -- This module instantiates and reexports code from Erased. {-# OPTIONS --erased-cubical --safe #-} import Equality.Path as P module Erased.Cubical {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Prelude open import Bijection equality-with-J using (_↔_) import Bijection P.equality-with-J as PB open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) import Equivalence P.equality-with-J as PEq import Erased.Basics as EB import Erased.Level-1 P.equality-with-J as EP import Erased.Level-1 equality-with-J as E open import Function-universe equality-with-J private variable a p : Level A : Type a x y : A ------------------------------------------------------------------------ -- []-cong -- Given an erased path from x to y there is a path from [ x ] to -- [ y ]. []-cong-Path : {@0 A : Type a} {@0 x y : A} → EB.Erased (x P.≡ y) → EB.[ x ] P.≡ EB.[ y ] []-cong-Path EB.[ eq ] = λ i → EB.[ eq i ] -- []-cong-Path is an equivalence. []-cong-Path-equivalence : {@0 A : Type a} {@0 x y : A} → PEq.Is-equivalence ([]-cong-Path {x = x} {y = y}) []-cong-Path-equivalence = PEq._≃_.is-equivalence $ PEq.↔⇒≃ (record { surjection = record { logical-equivalence = record { from = λ eq → EB.[ P.cong EB.erased eq ] } ; right-inverse-of = λ _ → P.refl } ; left-inverse-of = λ _ → P.refl }) -- A rearrangement lemma for []-cong-Path (which holds by definition). []-cong-Path-[refl] : {@0 A : Type a} {@0 x : A} → []-cong-Path EB.[ P.refl {x = x} ] P.≡ P.refl {x = EB.[ x ]} []-cong-Path-[refl] = P.refl -- The []-cong axioms can be instantiated. instance-of-[]-cong-axiomatisation-for-Path : EP.[]-cong-axiomatisation a instance-of-[]-cong-axiomatisation-for-Path = λ where .EP.[]-cong-axiomatisation.[]-cong → []-cong-Path .EP.[]-cong-axiomatisation.[]-cong-equivalence → []-cong-Path-equivalence .EP.[]-cong-axiomatisation.[]-cong-[refl] → []-cong-Path-[refl] -- Given an erased proof of equality of x and y one can show that -- EB.[ x ] is equal to EB.[ y ]. []-cong : {@0 A : Type a} {@0 x y : A} → EB.Erased (x ≡ y) → EB.[ x ] ≡ EB.[ y ] []-cong {x = x} {y = y} = EB.Erased (x ≡ y) ↝⟨ (λ (EB.[ eq ]) → EB.[ _↔_.to ≡↔≡ eq ]) ⟩ EB.Erased (x P.≡ y) ↝⟨ []-cong-Path ⟩ EB.[ x ] P.≡ EB.[ y ] ↔⟨ inverse ≡↔≡ ⟩□ EB.[ x ] ≡ EB.[ y ] □ -- []-cong is an equivalence. []-cong-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong {x = x} {y = y}) []-cong-equivalence {x = x} {y = y} = _≃_.is-equivalence ( EB.Erased (x ≡ y) ↔⟨ _≃_.from ↔≃↔ $ EP.[]-cong.Erased-cong-↔ instance-of-[]-cong-axiomatisation-for-Path (_≃_.to ↔≃↔ ≡↔≡) ⟩ EB.Erased (x P.≡ y) ↝⟨ _↔_.from ≃↔≃ PEq.⟨ _ , []-cong-Path-equivalence ⟩ ⟩ EB.[ x ] P.≡ EB.[ y ] ↔⟨ inverse ≡↔≡ ⟩□ EB.[ x ] ≡ EB.[ y ] □) -- A rearrangement lemma for []-cong. []-cong-[refl] : {@0 A : Type a} {@0 x : A} → []-cong EB.[ refl x ] ≡ refl EB.[ x ] []-cong-[refl] {x = x} = sym $ _↔_.to (from≡↔≡to Eq.⟨ _ , []-cong-equivalence ⟩) ( EB.[ _↔_.from ≡↔≡ (P.cong EB.erased (_↔_.to ≡↔≡ (refl EB.[ x ]))) ] ≡⟨ []-cong EB.[ sym cong≡cong ] ⟩ EB.[ cong EB.erased (_↔_.from ≡↔≡ (_↔_.to ≡↔≡ (refl EB.[ x ]))) ] ≡⟨ []-cong EB.[ cong (cong EB.erased) (_↔_.left-inverse-of ≡↔≡ _) ] ⟩ EB.[ cong EB.erased (refl EB.[ x ]) ] ≡⟨ []-cong EB.[ cong-refl _ ] ⟩∎ EB.[ refl x ] ∎) -- The []-cong axioms can be instantiated. instance-of-[]-cong-axiomatisation : E.[]-cong-axiomatisation a instance-of-[]-cong-axiomatisation = λ where .E.[]-cong-axiomatisation.[]-cong → []-cong .E.[]-cong-axiomatisation.[]-cong-equivalence → []-cong-equivalence .E.[]-cong-axiomatisation.[]-cong-[refl] → []-cong-[refl] -- Some reexported definitions. open import Erased equality-with-J instance-of-[]-cong-axiomatisation public hiding ([]-cong; []-cong-equivalence; []-cong-[refl]; Π-Erased≃Π0[]; Π-Erased≃Π0) ------------------------------------------------------------------------ -- Variants of some of the reexported definitions private -- The lemma push-subst-[], which is reexported above, can be proved -- very easily when path equality is used. push-subst-[]-Path : {@0 P : A → Type p} {@0 p : P x} {x≡y : x P.≡ y} → P.subst (λ x → Erased (P x)) x≡y [ p ] ≡ [ P.subst P x≡y p ] push-subst-[]-Path = refl _ -- Above a lemma H-level-Erased is reexported. That lemma is proved -- in a certain way. The following two lemmas are included to -- illustrate a somewhat different proof technique that works for -- individual h-levels (given by closed natural numbers). -- Is-proposition is closed under Erased. Is-proposition-Erased : {@0 A : Type a} → @0 Is-proposition A → Is-proposition (Erased A) Is-proposition-Erased {A = A} prop = _↔_.from (H-level↔H-level 1) (Is-proposition-Erased′ (_↔_.to (H-level↔H-level 1) prop)) where Is-proposition-Erased′ : @0 P.Is-proposition A → P.Is-proposition (Erased A) Is-proposition-Erased′ prop x y = λ i → [ prop (erased x) (erased y) i ] -- Is-set is closed under Erased. Is-set-Erased : {@0 A : Type a} → @0 Is-set A → Is-set (Erased A) Is-set-Erased {A = A} set = _↔_.from (H-level↔H-level 2) (Is-set-Erased′ (_↔_.to (H-level↔H-level 2) set)) where Is-set-Erased′ : @0 P.Is-set A → P.Is-set (Erased A) Is-set-Erased′ set p q = λ i j → [ set (P.cong erased p) (P.cong erased q) i j ] ------------------------------------------------------------------------ -- Some isomorphisms/equivalences -- The following four results are inspired by a result in -- Mishra-Linger's PhD thesis (see Section 5.4.1). -- There is a bijection (with paths for equality, not _≡_) between -- (x : Erased A) → P x and (@0 x : A) → P [ x ]. Π-Erased↔Π0[] : {@0 A : Type a} {@0 P : Erased A → Type p} → ((x : Erased A) → P x) PB.↔ ((@0 x : A) → P [ x ]) Π-Erased↔Π0[] = record { surjection = record { logical-equivalence = Π-Erased⇔Π0 ; right-inverse-of = λ f _ → f } ; left-inverse-of = λ f _ → f } -- There is an equivalence (with paths for equality, not _≡_) between -- (x : Erased A) → P x and (@0 x : A) → P [ x ]. -- -- This is not proved by converting Π-Erased↔Π0[] to an equivalence, -- because the type arguments of the conversion function in -- Equivalence are not erased, and P can only be used in erased -- contexts. -- -- This is a strengthening of E.Π-Erased≃Π0[]. Π-Erased≃Π0[] : {@0 A : Type a} {@0 P : Erased A → Type p} → ((x : Erased A) → P x) PEq.≃ ((@0 x : A) → P [ x ]) Π-Erased≃Π0[] = record { to = λ f x → f [ x ] ; is-equivalence = (λ f ([ x ]) → f x) , (λ f _ → f) , (λ f _ → f) , (λ f _ _ x → f [ x ]) } -- There is a bijection (with paths for equality, not _≡_) between -- (x : Erased A) → P (erased x) and (@0 x : A) → P x. Π-Erased↔Π0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) PB.↔ ((@0 x : A) → P x) Π-Erased↔Π0 = Π-Erased↔Π0[] -- There is an equivalence (with paths for equality, not _≡_) between -- (x : Erased A) → P (erased x) and (@0 x : A) → P x. -- -- This is a strengthening of E.Π-Erased≃Π0. Π-Erased≃Π0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) PEq.≃ ((@0 x : A) → P x) Π-Erased≃Π0 = Π-Erased≃Π0[]
{ "alphanum_fraction": 0.5347776511, "avg_line_length": 33.5872340426, "ext": "agda", "hexsha": "daeedb022c08968eed7bf45e3764e41bf5588527", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Erased/Cubical.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/equality", "max_issues_repo_path": "src/Erased/Cubical.agda", "max_line_length": 142, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Erased/Cubical.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 2980, "size": 7893 }
-- Andreas, 2019-07-11, issue #3843, reported by shinji-kono -- recordExpressionToCopattern translation invalidates projection-likeness. -- {-# OPTIONS -v tc.proj.like:100 -v impossible:10 #-} data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x postulate ANY : ∀{a} {A : Set a} → A Nat : Set suc : Nat → Nat diag : (x : Nat) → x ≡ x P : Nat → Set Foo : {x : Nat} (px : P x) → Set record Pack (n : Nat) : Set where constructor pack field lv : Nat ord : P lv open Pack -- Projection-like, because eta-contracted to pidproj x = x pidproj : ∀ {n} (x : Pack n) → Pack n pidproj x = record { lv = lv x; ord = ord x } -- Not considered projection-like, since -- `pidpc (pack l o)` is stuck, but the `n` cannot be inferred. pidpc : ∀ {n} (x : Pack n) → Pack n pidpc x .lv = lv x pidpc x .ord = ord x -- Not considered projection-like, since -- `pidcop (pack l o)` is stuck, but the `n` cannot be inferred. pidcop : ∀ {n} (x : Pack n) → Pack n pidcop (pack lx ox) .lv = lx pidcop (pack lx ox) .ord = ox -- WAS: Projection-like function, -- but since is translated to pidcop by recordExpressionsToCopatterns -- projection-likeness is unsound here. pid : ∀ {n} (x : Pack n) → Pack n pid (pack lx ox) = record { lv = lx ; ord = ox } -- pid record { lv = lx ; ord = ox } = record { lv = lx ; ord = ox } -- pid (pack lx ox) = pack lx ox -- no error -- pid x = x -- Error disappears with record pattern matching test : ∀ {n} (x : Pack (suc n)) → x ≡ pid x test {n} x@(pack lx ox) with diag (lv x) -- The @-pattern is needed for 2.5.2 and 2.5.3 ... | refl with Foo (ord x) -- with needed ... | _ = ANY -- WAS: internal error -- Should succeed.
{ "alphanum_fraction": 0.6071005917, "avg_line_length": 29.649122807, "ext": "agda", "hexsha": "f3d84d0189ecca63a0e96945ad8214a9e8c13726", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue3843.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue3843.agda", "max_line_length": 88, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue3843.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 588, "size": 1690 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Costrings ------------------------------------------------------------------------ {-# OPTIONS --without-K #-} module Codata.Musical.Costring where open import Codata.Musical.Colist as Colist using (Colist) open import Data.Char using (Char) open import Data.String as String using (String) open import Function using (_∘_) -- Possibly infinite strings. Costring : Set Costring = Colist Char -- Methods toCostring : String → Costring toCostring = Colist.fromList ∘ String.toList
{ "alphanum_fraction": 0.5656565657, "avg_line_length": 23.76, "ext": "agda", "hexsha": "a6405f23fe955ee99a11a8b21b5aa909b88d01af", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Costring.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Costring.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Costring.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 118, "size": 594 }
-- Andreas, AIM XXIII, 2016-04-25 -- Parameter arguments of overloaded projection applications -- should not be skipped! record R A : Set where field f : {x y : A} → A open R record S A : Set where field f : {x y : A} → A open S r : ∀{A} → R A f r {x} = x test : ∀{A B : Set} (a : A) (b : B) → A test {A} a b = f (r {A}) {x = a} {y = b}
{ "alphanum_fraction": 0.5520231214, "avg_line_length": 18.2105263158, "ext": "agda", "hexsha": "d3ff9b017667fcf283e1f46498854b33020bb330", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue1944-checkHidden.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue1944-checkHidden.agda", "max_line_length": 60, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue1944-checkHidden.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 138, "size": 346 }
module README where ------------------------------------------------------------------------ -- Core definitions ------------------------------------------------------------------------ import Generics.Prelude -- Generics.Telescope introduces an encoding for telescopes, -- along with functions to manipulate indexed functions and families. import Generics.Telescope -- Generics.Desc introduces the core universe of descriptions for datatypes. import Generics.Desc -- Generics.HasDesc defines the HasDesc record, -- bridging the gap between descriptions of datatypes -- and their concrete Agda counterpart. import Generics.HasDesc -- Generics.Reflection implements the deriveDesc macro -- to automatically derive an instance of HasDesc for most datatypes. import Generics.Reflection ------------------------------------------------------------------------ -- Generic constructions ------------------------------------------------------------------------ -- Generic show implemetation import Generics.Constructions.Show -- Datatype-generic case analysis principle import Generics.Constructions.Case -- Datatype-generic decidable equality import Generics.Constructions.DecEq -- Datatype-generic induction principle, -- on described datatypes only import Generics.Constructions.Induction -- Datatype-generic elimination principle import Generics.Constructions.Elim -- WIP Datatype-generic injectivity of constructors import Generics.Constructions.NoConfusion
{ "alphanum_fraction": 0.6603131382, "avg_line_length": 31.2553191489, "ext": "agda", "hexsha": "d373142731065eb06b588ca7fe51cb7f4eceab95", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "flupe/generics", "max_forks_repo_path": "README.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "flupe/generics", "max_issues_repo_path": "README.agda", "max_line_length": 76, "max_stars_count": 11, "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "flupe/generics", "max_stars_repo_path": "README.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "num_tokens": 244, "size": 1469 }
open import Formalization.PredicateLogic.Signature module Formalization.PredicateLogic.Classical.Semantics.Satisfaction (𝔏 : Signature) {ℓₘ} where open Signature(𝔏) import Lvl open import Data open import Data.Boolean open import Data.Boolean.Stmt open import Data.ListSized import Data.ListSized.Functions as List open import Formalization.PredicateLogic.Classical.Semantics(𝔏){ℓₘ} open import Formalization.PredicateLogic.Syntax(𝔏) open import Functional using (_∘_ ; _∘₂_) import Logic.Propositional as Logic import Logic.Predicate as Logic open import Numeral.Finite open import Numeral.Finite.Bound open import Numeral.Natural open import Relator.Equals open import Sets.PredicateSet using (PredSet) open Sets.PredicateSet.BoundedQuantifiers open import Syntax.Function open import Type.Dependent renaming (intro to _,_) open import Type.Properties.Decidable open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable P : Type{ℓₚ} private variable args n vars : ℕ private variable 𝔐 : Model -- A `VarMapping(vars)(𝔐)` maps `vars` number of variables to objects in the domain of the model `𝔐`. -- Also called: Variable assignment. VarMapping : ℕ → Model → Type VarMapping(vars)(𝔐) = 𝕟(vars) → Model.Domain(𝔐) module VarMapping where -- Adds a mapping to an object in the domain of the model `𝔐`. add0 : VarMapping(vars)(𝔐) → Model.Domain(𝔐) → VarMapping(𝐒(vars))(𝔐) add0 𝔰 t 𝟎 = t add0 𝔰 t (𝐒(v)) = 𝔰(v) private variable 𝔰 : VarMapping(vars)(𝔐) module _ ((𝔐 , 𝔰) : Σ Model (VarMapping(vars))) where -- Maps terms to objects in the domain given a model and a variable mapping. val : Term(vars) → Model.Domain(𝔐) val₊ : List(Term(vars))(n) → List(Model.Domain(𝔐))(n) val(var v) = 𝔰(v) val(func f x) = Model.function 𝔐 f (val₊ x) val₊ {0} ∅ = ∅ val₊ {𝐒(n)} (t ⊰ ts) = (val t ⊰ val₊ {n} ts) --val₊ = List.map val -- Satisfication relation. -- ((𝔐 , 𝔰) ⊧ φ) means that the formula φ is satisfied in the model 𝔐 with the variable mapping. -- Or in other words: A formula is true in the model 𝔐. _⊧_ : (Σ Model (VarMapping(vars))) → Formula(vars) → Type{ℓₘ} (𝔐 , 𝔰) ⊧ (f $ x) = Lvl.Up(IsTrue(Model.relation 𝔐 f (val₊(𝔐 , 𝔰) x))) -- A model decides whether a relation is satisfied. (𝔐 , 𝔰) ⊧ ⊤ = Unit -- All models satisfy top. (𝔐 , 𝔰) ⊧ ⊥ = Empty -- No model satisfies bottom. (𝔐 , 𝔰) ⊧ (φ ∧ ψ) = ((𝔐 , 𝔰) ⊧ φ) Logic.∧ ((𝔐 , 𝔰) ⊧ ψ) -- A model satisfies a conjunction when it satisfies both of the propositions. (𝔐 , 𝔰) ⊧ (φ ∨ ψ) = ((𝔐 , 𝔰) ⊧ φ) Logic.∨ ((𝔐 , 𝔰) ⊧ ψ) -- A model satisfies a disjunction when it satisfies any one of the propositions. (𝔐 , 𝔰) ⊧ (φ ⟶ ψ) = Logic.¬((𝔐 , 𝔰) ⊧ φ) Logic.∨ ((𝔐 , 𝔰) ⊧ ψ) (𝔐 , 𝔰) ⊧ (Ɐ φ) = Logic.∀ₗ(t ↦ (𝔐 , VarMapping.add0{𝔐 = 𝔐} 𝔰 t) ⊧ φ) (𝔐 , 𝔰) ⊧ (∃ φ) = Logic.∃(t ↦ (𝔐 , VarMapping.add0{𝔐 = 𝔐} 𝔰 t) ⊧ φ) -- Satisfication of a set of formulas. -- This means that a model satisfies all formulas at the same time. _⊧₊_ : (Σ Model (VarMapping(vars))) → PredSet{ℓ}(Formula(vars)) → Type 𝔐 ⊧₊ Γ = ∀ₛ(Γ) (𝔐 ⊧_) -- Validity of a formula. -- A formula is valid when it is true independent of any model (is satisfied by all models). -- Examples: -- Valid(⊤) -- Valid(⊥ ⟶ ⊥) -- ¬ Valid(⊥) -- ¬ Valid(P) where P : Prop(0) Valid : Formula(vars) → Type Valid(φ) = Logic.∀ₗ(_⊧ φ) -- Satisfiability of sets of formulas. -- A set of formulas is satisfiable when there is a model that satisfies all of them at the same time. Satisfiable : PredSet{ℓ}(Formula(vars)) → Type Satisfiable(Γ) = Logic.∃(_⊧₊ Γ) -- Unsatisfiability of sets of formulas. Unsatisfiable : PredSet{ℓ}(Formula(vars)) → Type Unsatisfiable{ℓ} = Logic.¬_ ∘ Satisfiable{ℓ} -- Semantic entailment of a formula. -- A hypothetical statement. If a model would satisfy all formulas in Γ, then this same model satisifes the formula φ. _⊨_ : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type Γ ⊨ φ = ∀{𝔐} → (𝔐 ⊧₊ Γ) → (𝔐 ⊧ φ) _⊭_ : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type _⊭_ = (Logic.¬_) ∘₂ (_⊨_) -- Axiomatization of a theory by a set of axioms. -- A set of axioms is a set of formulas. -- A theory is the closure of a set of axioms. -- An axiomatization is a subset of formulas of the theory which entails all formulas in the axiomatized theory. _axiomatizes_ : PredSet{ℓ₁}(Formula(vars)) → PredSet{ℓ₂}(Formula(vars)) → Type Γ₁ axiomatizes Γ₂ = ∀{φ} → (Γ₁ ⊨ φ) → Γ₂(φ) -- A set of formulas is closed when it includes all formulas that it entails. Closed : PredSet{ℓ}(Formula(vars)) → Type Closed(Γ) = Γ axiomatizes Γ _⊨₊_ : PredSet{ℓ₁}(Formula(vars)) → PredSet{ℓ₂}(Formula(vars)) → Type Γ₁ ⊨₊ Γ₂ = ∀{𝔐} → (𝔐 ⊧₊ Γ₁) → (𝔐 ⊧₊ Γ₂) _⊭₊_ : PredSet{ℓ₁}(Formula(vars)) → PredSet{ℓ₂}(Formula(vars)) → Type _⊭₊_ = (Logic.¬_) ∘₂ (_⊨₊_)
{ "alphanum_fraction": 0.6472273378, "avg_line_length": 41.7692307692, "ext": "agda", "hexsha": "39c687a2828d48664b21a5e696a382df91f2da90", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Formalization/PredicateLogic/Classical/Semantics/Satisfaction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Formalization/PredicateLogic/Classical/Semantics/Satisfaction.agda", "max_line_length": 155, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Formalization/PredicateLogic/Classical/Semantics/Satisfaction.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 1791, "size": 4887 }
-- Andreas, 2017-10-04, issue #2765, reported by nad -- Problem: inferred level expressions are often "reversed" open import Agda.Primitive postulate F : (ℓ : Level) → Set ℓ G : (a b c : Level) → Set {!!} -- C-c C-= G a b c = F a → F b → F c -- WAS: -- ?0 := c ⊔ (b ⊔ a) -- Expected: Inferred level should be -- ?0 := a ⊔ (b ⊔ c)
{ "alphanum_fraction": 0.5680473373, "avg_line_length": 19.8823529412, "ext": "agda", "hexsha": "5ae1ae6559f4cd7125bc80d2d9f638c86bc88657", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Issue2765.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Issue2765.agda", "max_line_length": 59, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Issue2765.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 128, "size": 338 }
{-# OPTIONS --without-K --safe #-} module Categories.GlobularSet where -- Globular sets are defined in a Categorical context, but -- should they be inside the Categories hierarchy? open import Level open import Data.Unit using (⊤) open import Relation.Binary.PropositionalEquality using (refl) open import Categories.Category open import Categories.Category.Instance.Globe open import Categories.Category.Instance.Sets open import Categories.Functor open import Categories.Functor.Presheaf private variable o ℓ e : Level GlobularSet : (o : Level) → Set (suc o) GlobularSet o = Presheaf Globe (Sets o) -- TODO? make universe polymorphic with polymorphic ⊤ Trivial : GlobularSet zero Trivial = record { F₀ = λ _ → ⊤ ; F₁ = λ _ x → x ; identity = refl ; homomorphism = refl ; F-resp-≈ = λ _ → refl } GlobularObject : Category o ℓ e → Set _ GlobularObject C = Functor (Category.op Globe) C
{ "alphanum_fraction": 0.7354555434, "avg_line_length": 25.3055555556, "ext": "agda", "hexsha": "dcc3cd44ed240b70fd1b6d3e93def929b31c49d3", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/GlobularSet.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/GlobularSet.agda", "max_line_length": 62, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/GlobularSet.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 254, "size": 911 }
module Data.QuadTree.InternalAgda where open import Data.QuadTree.Implementation.Definition open import Data.QuadTree.Implementation.PublicFunctions open import Data.QuadTree.Implementation.Functors open import Data.QuadTree.Implementation.ValidTypes open import Data.QuadTree.Implementation.QuadrantLenses open import Data.QuadTree.Implementation.Foldable
{ "alphanum_fraction": 0.8851540616, "avg_line_length": 44.625, "ext": "agda", "hexsha": "aacf653b387f95536d5a25c0126d4e5c2164b1ac", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "JonathanBrouwer/research-project", "max_forks_repo_path": "src/Data/QuadTree/InternalAgda.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "JonathanBrouwer/research-project", "max_issues_repo_path": "src/Data/QuadTree/InternalAgda.agda", "max_line_length": 56, "max_stars_count": 1, "max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "JonathanBrouwer/research-project", "max_stars_repo_path": "src/Data/QuadTree/InternalAgda.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z", "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z", "num_tokens": 73, "size": 357 }
module _ where module M where postulate A : Set module N = M -- This alias introduces a display form M.A --> N.A open M postulate a : A {-# DISPLAY N.A = A #-} -- Makes Agda loop test : Set test = a
{ "alphanum_fraction": 0.6208530806, "avg_line_length": 11.7222222222, "ext": "agda", "hexsha": "c0775ffe94214af0f1b27d5ed45928fe79024b56", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue1644b.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue1644b.agda", "max_line_length": 65, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue1644b.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 67, "size": 211 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import cw.CW open import cw.FinCW open import cw.FinBoundary open import cohomology.Theory module cw.cohomology.cochainequiv.DualizedHigherBoundary (OT : OrdinaryTheory lzero) {n} (⊙fin-skel : ⊙FinSkeleton (S (S n))) where open OrdinaryTheory OT private fin-skel = ⊙FinSkeleton.skel ⊙fin-skel I = AttachedFinSkeleton.numCells fin-skel fin-skel₋₁ = AttachedFinSkeleton.skel fin-skel I₋₁ = AttachedFinSkeleton.numCells fin-skel₋₁ abstract rephrase-dualized-higher-boundary-in-degree : ∀ g <I → GroupIso.g (FreeAbGroup-extend-iso (C2-abgroup 0)) (GroupIso.f (FreeAbGroup-extend-iso (C2-abgroup 0)) g ∘ᴳ fboundary-last fin-skel) <I == Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (fdegree-last fin-skel <I <I₋₁)) rephrase-dualized-higher-boundary-in-degree g <I = FormalSum-extend (C2-abgroup 0) g (GroupHom.f (fboundary-last fin-skel) fs[ inl <I :: nil ]) =⟨ ap (FormalSum-extend (C2-abgroup 0) g) $ app= (is-equiv.g-f (FreeAbGroup-extend-is-equiv (FreeAbGroup (Fin I₋₁))) (fboundary'-last fin-skel)) <I ⟩ FormalSum-extend (C2-abgroup 0) g (Group.sum (FreeAbGroup.grp (Fin I₋₁)) (λ <I₋₁ → Group.exp (FreeAbGroup.grp (Fin I₋₁)) fs[ inl <I₋₁ :: nil ] (fdegree-last fin-skel <I <I₋₁))) =⟨ GroupHom.pres-sum (FreeAbGroup-extend (C2-abgroup 0) g) (λ <I₋₁ → Group.exp (FreeAbGroup.grp (Fin I₋₁)) fs[ inl <I₋₁ :: nil ] (fdegree-last fin-skel <I <I₋₁)) ⟩ Group.sum (C2 0) (λ <I₋₁ → (FormalSum-extend (C2-abgroup 0) g (Group.exp (FreeAbGroup.grp (Fin I₋₁)) fs[ inl <I₋₁ :: nil ] (fdegree-last fin-skel <I <I₋₁)))) =⟨ ap (Group.sum (C2 0)) (λ= λ <I₋₁ → GroupHom.pres-exp (FreeAbGroup-extend (C2-abgroup 0) g) fs[ inl <I₋₁ :: nil ] (fdegree-last fin-skel <I <I₋₁)) ⟩ Group.sum (C2 0) (λ <I₋₁ → (Group.exp (C2 0) (FormalSum-extend (C2-abgroup 0) g fs[ inl <I₋₁ :: nil ]) (fdegree-last fin-skel <I <I₋₁))) =⟨ ap (Group.sum (C2 0)) (λ= λ <I₋₁ → ap (λ g → Group.exp (C2 0) g (fdegree-last fin-skel <I <I₋₁)) $ app= (is-equiv.g-f (FreeAbGroup-extend-is-equiv (C2-abgroup 0)) g) <I₋₁) ⟩ Group.sum (C2 0) (λ <I₋₁ → (Group.exp (C2 0) (g <I₋₁) (fdegree-last fin-skel <I <I₋₁))) =∎
{ "alphanum_fraction": 0.5994962217, "avg_line_length": 44.1111111111, "ext": "agda", "hexsha": "16f5a676be2dee693ea0cbbd31f52c0f0bc7903f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "theorems/cw/cohomology/cochainequiv/DualizedHigherBoundary.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_path": "theorems/cw/cohomology/cochainequiv/DualizedHigherBoundary.agda", "max_line_length": 115, "max_stars_count": null, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "theorems/cw/cohomology/cochainequiv/DualizedHigherBoundary.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 934, "size": 2382 }
------------------------------------------------------------------------------ -- A partial function: iter₀ ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.Iter0.Iter0 where open import FOTC.Base open import FOTC.Base.List ------------------------------------------------------------------------------ postulate iter₀ : D → D → D iter₀-eq : ∀ f n → iter₀ f n ≡ (if (iszero₁ n) then [] else (n ∷ iter₀ f (f · n))) {-# ATP axiom iter₀-eq #-}
{ "alphanum_fraction": 0.3604651163, "avg_line_length": 31.2727272727, "ext": "agda", "hexsha": "8719d2f0882923462d8227911c4dbd0b935f361f", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/Iter0/Iter0.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/Iter0/Iter0.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/Iter0/Iter0.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 135, "size": 688 }
{-# OPTIONS --sized-types #-} open import Relation.Binary.Core module BubbleSort.Correctness.Permutation {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import BubbleSort _≤_ tot≤ open import Data.Product open import Data.List open import Data.Sum open import List.Permutation.Base A open import List.Permutation.Base.Equivalence A open import Size open import SList open import SList.Properties A open import SList.Concatenation A lemma-swap*∼ : {ι : Size}(x : A) → (xs : SList A {ι}) → unsize A (x ∙ xs) ∼ unsize A (proj₂ (swap* x xs) ∙ proj₁ (swap* x xs)) lemma-swap*∼ x snil = ∼x /head /head ∼[] lemma-swap*∼ x (y ∙ ys) with tot≤ x y ... | inj₁ x≤y = ∼x /head (/tail /head) (lemma-swap*∼ y ys) ... | inj₂ y≤x = ∼x (/tail /head) (/tail /head) (lemma-swap*∼ x ys) lemma-bubbleSort∼ : {ι : Size}(xs : SList A {ι}) → unsize A xs ∼ unsize A (bubbleSort xs) lemma-bubbleSort∼ snil = ∼[] lemma-bubbleSort∼ (x ∙ xs) = trans∼ (lemma-swap*∼ x xs) (trans∼ (lemma-⊕∼ y (lemma-bubbleSort∼ ys)) (lemma-size-unsize y (bubbleSort ys))) where sxxs = swap* x xs ys = proj₁ sxxs y = proj₂ sxxs theorem-bubbleSort∼ : (xs : List A) → xs ∼ unsize A (bubbleSort (size A xs)) theorem-bubbleSort∼ xs = trans∼ (lemma-unsize-size xs) (lemma-bubbleSort∼ (size A xs))
{ "alphanum_fraction": 0.6128560993, "avg_line_length": 37, "ext": "agda", "hexsha": "72d99f16ad8a6a0335dcfc32cd725eb4c1a0618b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/BubbleSort/Correctness/Permutation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_path": "agda/BubbleSort/Correctness/Permutation.agda", "max_line_length": 138, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/BubbleSort/Correctness/Permutation.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 481, "size": 1369 }
--------------------------------------------------------------------------- -- The rec definition using the fixed-point combinator --------------------------------------------------------------------------- {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module LTC-PCF.Data.Nat.Rec where open import LTC-PCF.Base --------------------------------------------------------------------------- -- Let T = D → D → (D → D → D) → D be a type. Instead of defining -- rec : T → T, we use the LTC-PCF λ-abstraction and application to -- avoid use a polymorphic fixed-point operator. rech : D → D rech r = lam (λ n → lam (λ a → lam (λ f → if (iszero₁ n) then a else f · pred₁ n · (r · pred₁ n · a · f)))) rec : D → D → D → D rec n a f = fix rech · n · a · f
{ "alphanum_fraction": 0.4087431694, "avg_line_length": 32.6785714286, "ext": "agda", "hexsha": "61d0df214690b9b3e9dab95691aa0d629411733f", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/LTC-PCF/Data/Nat/Rec.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/LTC-PCF/Data/Nat/Rec.agda", "max_line_length": 75, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/LTC-PCF/Data/Nat/Rec.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 211, "size": 915 }
open import Prelude open import Nat open import Agda.Primitive using (Level; lzero; lsuc) renaming (_⊔_ to lmax) module List where -- definitions data List (A : Set) : Set where [] : List A _::_ : A → List A → List A _++_ : {A : Set} → List A → List A → List A [] ++ l₂ = l₂ (h :: l₁) ++ l₂ = h :: (l₁ ++ l₂) infixl 50 _++_ ∥_∥ : {A : Set} → List A → Nat ∥ [] ∥ = Z ∥ a :: as ∥ = 1+ ∥ as ∥ _⟦_⟧ : {A : Set} → List A → Nat → Maybe A [] ⟦ i ⟧ = None (a :: as) ⟦ Z ⟧ = Some a (a :: as) ⟦ 1+ i ⟧ = as ⟦ i ⟧ data _In_ : {A : Set} → A → List A → Set where LInH : ∀{A} {a : A} {l : List A} → a In (a :: l) LInT : ∀{A} {a a' : A} {l : List A} → a In l → a In (a' :: l) _⫇_ : {A : Set} → List A → List A → Set _⫇_ {A} l1 l2 = (i1 : Nat) (a : A) → l1 ⟦ i1 ⟧ == Some a → Σ[ i2 ∈ Nat ] (l2 ⟦ i2 ⟧ == Some a) _≈_ : {A : Set} → List A → List A → Set _≈_ {A} l1 l2 = l1 ⫇ l2 ∧ l2 ⫇ l1 reverse : {A : Set} → List A → List A reverse [] = [] reverse (a :: as) = reverse as ++ (a :: []) map : {A B : Set} → (A → B) → List A → List B map f [] = [] map f (a :: as) = f a :: map f as foldl : {A B : Set} → (B → A → B) → B → List A → B foldl f b [] = b foldl f b (a :: as) = foldl f (f b a) as foldr : {A B : Set} → (B → A → B) → B → List A → B foldr f b = foldl f b ⊙ reverse concat : {A : Set} → List (List A) → List A concat [] = [] concat (l1 :: rest) = l1 ++ (concat rest) -- if the lists aren't the same length, -- the extra elements of the longer list are ignored zip : {A B : Set} → List A → List B → List (A ∧ B) zip [] _ = [] zip (a :: as) [] = [] zip (a :: as) (b :: bs) = (a , b) :: zip as bs unzip : {A B : Set} → List (A ∧ B) → (List A ∧ List B) unzip [] = ([] , []) unzip ((a , b) :: rest) with unzip rest ... | (as , bs) = (a :: as , b :: bs) -- theorems list-==-dec : {A : Set} → (l1 l2 : List A) → ((a1 a2 : A) → a1 == a2 ∨ a1 ≠ a2) → l1 == l2 ∨ l1 ≠ l2 list-==-dec [] [] A-==-dec = Inl refl list-==-dec [] (_ :: _) A-==-dec = Inr (λ ()) list-==-dec (_ :: _) [] A-==-dec = Inr (λ ()) list-==-dec (h1 :: t1) (h2 :: t2) A-==-dec with A-==-dec h1 h2 ... | Inr ne = Inr (λ where refl → ne refl) ... | Inl refl with list-==-dec t1 t2 A-==-dec ... | Inr ne = Inr (λ where refl → ne refl) ... | Inl refl = Inl refl -- if the items of two lists are equal, then the lists are equal ==-per-elem : {A : Set} → {l1 l2 : List A} → ((i : Nat) → l1 ⟦ i ⟧ == l2 ⟦ i ⟧) → l1 == l2 ==-per-elem {l1 = []} {[]} items== = refl ==-per-elem {l1 = []} {h2 :: t2} items== = abort (somenotnone (! (items== Z))) ==-per-elem {l1 = h1 :: t1} {[]} items== = abort (somenotnone (items== Z)) ==-per-elem {l1 = h1 :: t1} {h2 :: t2} items== rewrite someinj (items== Z) | ==-per-elem {l1 = t1} {t2} (λ i → items== (1+ i)) = refl -- _++_ theorems ++assc : ∀{A a1 a2 a3} → (_++_ {A} a1 a2) ++ a3 == a1 ++ (a2 ++ a3) ++assc {A} {[]} {a2} {a3} = refl ++assc {A} {x :: a1} {a2} {a3} with a1 ++ a2 ++ a3 | ++assc {A} {a1} {a2} {a3} ++assc {A} {x :: a1} {a2} {a3} | _ | refl = refl l++[]==l : {A : Set} (l : List A) → l ++ [] == l l++[]==l [] = refl l++[]==l (a :: as) rewrite l++[]==l as = refl -- ∥_∥ theorem ∥-++-comm : ∀{A a1 a2} → ∥ a1 ∥ + (∥_∥ {A} a2) == ∥ a1 ++ a2 ∥ ∥-++-comm {A} {[]} {a2} = refl ∥-++-comm {A} {a :: a1} {a2} = 1+ap (∥-++-comm {A} {a1}) -- _⟦_⟧ and ++ theorem ⦇l1++[a]++l2⦈⟦∥l1∥⟧==a : {A : Set} {l1 l2 : List A} {a : A} → (l1 ++ (a :: []) ++ l2) ⟦ ∥ l1 ∥ ⟧ == Some a ⦇l1++[a]++l2⦈⟦∥l1∥⟧==a {l1 = []} = refl ⦇l1++[a]++l2⦈⟦∥l1∥⟧==a {l1 = a1 :: l1rest} {l2} {a} = ⦇l1++[a]++l2⦈⟦∥l1∥⟧==a {l1 = l1rest} {l2} -- packaging of list indexing results list-index-dec : {A : Set} (l : List A) (i : Nat) → l ⟦ i ⟧ == None ∨ Σ[ a ∈ A ] (l ⟦ i ⟧ == Some a) list-index-dec l i with l ⟦ i ⟧ ... | None = Inl refl ... | Some a = Inr (a , refl) -- theorems characterizing the partiality of list indexing list-index-some : {A : Set} {l : List A} {i : Nat} → i < ∥ l ∥ → Σ[ a ∈ A ] (l ⟦ i ⟧ == Some a) list-index-some {l = []} {Z} i<∥l∥ = abort (n≮0 i<∥l∥) list-index-some {l = a :: as} {Z} i<∥l∥ = _ , refl list-index-some {l = a :: as} {1+ i} i<∥l∥ = list-index-some (1+n<1+m→n<m i<∥l∥) list-index-none : {A : Set} {l : List A} {i : Nat} → ∥ l ∥ ≤ i → l ⟦ i ⟧ == None list-index-none {l = []} i≥∥l∥ = refl list-index-none {l = a :: as} {1+ i} i≥∥l∥ = list-index-none (1+n≤1+m→n≤m i≥∥l∥) list-index-some-conv : {A : Set} {l : List A} {i : Nat} {a : A} → l ⟦ i ⟧ == Some a → i < ∥ l ∥ list-index-some-conv {l = l} {i} i≥∥l∥ with <dec ∥ l ∥ i ... | Inr (Inr i<∥l∥) = i<∥l∥ ... | Inr (Inl refl) rewrite list-index-none {l = l} {∥ l ∥} ≤refl = abort (somenotnone (! i≥∥l∥)) ... | Inl ∥l∥<i rewrite list-index-none (n<m→n≤m ∥l∥<i) = abort (somenotnone (! i≥∥l∥)) list-index-none-conv : {A : Set} {l : List A} {i : Nat} → l ⟦ i ⟧ == None → ∥ l ∥ ≤ i list-index-none-conv {l = l} {i} i≥∥l∥ with <dec ∥ l ∥ i ... | Inl ∥l∥<i = n<m→n≤m ∥l∥<i ... | Inr (Inl refl) = ≤refl ... | Inr (Inr i<∥l∥) with list-index-some i<∥l∥ ... | _ , i≱∥l∥ rewrite i≥∥l∥ = abort (somenotnone (! i≱∥l∥)) ∥l1∥==∥l2∥→l1[i]→l2[i] : {A B : Set} {la : List A} {lb : List B} {i : Nat} {a : A} → ∥ la ∥ == ∥ lb ∥ → la ⟦ i ⟧ == Some a → Σ[ b ∈ B ] (lb ⟦ i ⟧ == Some b) ∥l1∥==∥l2∥→l1[i]→l2[i] {i = i} ∥la∥==∥lb∥ la[i]==a = list-index-some (tr (λ y → i < y) ∥la∥==∥lb∥ (list-index-some-conv la[i]==a)) ∥l1∥==∥l2∥→¬l1[i]→¬l2[i] : {A B : Set} {la : List A} {lb : List B} {i : Nat} → ∥ la ∥ == ∥ lb ∥ → la ⟦ i ⟧ == None → lb ⟦ i ⟧ == None ∥l1∥==∥l2∥→¬l1[i]→¬l2[i] {i = i} ∥la∥==∥lb∥ la[i]==None = list-index-none (tr (λ y → y ≤ i) ∥la∥==∥lb∥ (list-index-none-conv la[i]==None)) -- more list indexing theorems i∈l2→|l1|+i∈l1++l2 : {A : Set} {l1 l2 : List A} {i : Nat} {a : A} → l2 ⟦ i ⟧ == Some a → (l1 ++ l2) ⟦ ∥ l1 ∥ + i ⟧ == Some a i∈l2→|l1|+i∈l1++l2 {l1 = []} i∈l2 = i∈l2 i∈l2→|l1|+i∈l1++l2 {l1 = a1 :: l1} i∈l2 = i∈l2→|l1|+i∈l1++l2 {l1 = l1} i∈l2 i∈l1→i∈l1++l2 : {A : Set} {l1 l2 : List A} {i : Nat} {a : A} → l1 ⟦ i ⟧ == Some a → (l1 ++ l2) ⟦ i ⟧ == Some a i∈l1→i∈l1++l2 {l1 = a1 :: l1} {i = Z} i∈l1 = i∈l1 i∈l1→i∈l1++l2 {l1 = a1 :: l1} {i = 1+ i} i∈l1 = i∈l1→i∈l1++l2 {l1 = l1} i∈l1 append-index-split : {A : Set} {l1 l2 : List A} {i : Nat} {a : A} → (l1 ++ l2) ⟦ i ⟧ == Some a → l1 ⟦ i ⟧ == Some a ∨ (Σ[ j ∈ Nat ] (∥ l1 ∥ + j == i ∧ l2 ⟦ j ⟧ == Some a)) append-index-split {l1 = []} i∈l1==l2 = Inr (_ , refl , i∈l1==l2) append-index-split {l1 = a1 :: l1} {i = Z} i∈l1==l2 = Inl i∈l1==l2 append-index-split {l1 = a1 :: l1} {i = 1+ i} i∈l1==l2 with append-index-split {l1 = l1} i∈l1==l2 ... | Inl i∈l1 = Inl i∈l1 ... | Inr (j , |l1|+j=i , j∈l2) = Inr (_ , 1+ap |l1|+j=i , j∈l2) -- reverse theorems reverse-single : {A : Set} {a : A} → reverse (a :: []) == a :: [] reverse-single = refl reverse-++ : {A : Set} {l1 l2 : List A} → reverse (l1 ++ l2) == reverse l2 ++ reverse l1 reverse-++ {l1 = []} {l2} rewrite l++[]==l (reverse l2) = refl reverse-++ {l1 = a1 :: as1} {l2} rewrite reverse-++ {l1 = as1} {l2} = ++assc {a1 = reverse l2} reverse-inv : {A : Set} {l : List A} → reverse (reverse l) == l reverse-inv {l = []} = refl reverse-inv {l = a :: as} rewrite reverse-++ {l1 = reverse as} {a :: []} | reverse-inv {l = as} = refl -- map theorems map-ext : ∀{A B : Set} {f g : A → B} {l : List A} → ((a : A) → f a == g a) → map f l == map g l map-ext {l = []} ext = refl map-ext {l = a :: l} ext rewrite ext a | map-ext {l = l} ext = refl map-id : ∀{A : Set} {l : List A} → map (λ a → a) l == l map-id {l = []} = refl map-id {l = a :: l} rewrite map-id {l = l} = refl map-len : ∀{A B : Set} {f : A → B} {l : List A} → ∥ map f l ∥ == ∥ l ∥ map-len {l = []} = refl map-len {l = _ :: l} = 1+ap map-len map-In : ∀{A B : Set} {f : A → B} {l : List A} {a : A} → a In l → f a In map f l map-In LInH = LInH map-In (LInT aInL) = LInT (map-In aInL) map-++-comm : ∀{A B f a b} → map f a ++ map f b == map {A} {B} f (a ++ b) map-++-comm {a = []} = refl map-++-comm {A} {B} {f} {h :: t} {b} with map f (t ++ b) | map-++-comm {A} {B} {f} {t} {b} map-++-comm {A} {B} {f} {h :: t} {b} | _ | refl = refl map^2 : ∀{A B C f g l} → map {B} {C} f (map {A} {B} g l) == map (f ⊙ g) l map^2 {l = []} = refl map^2 {f = f} {g} {h :: t} rewrite map^2 {f = f} {g} {t} = refl reverse-map : {A B : Set} {f : A → B} {l : List A} → reverse (map f l) == map f (reverse l) reverse-map {l = []} = refl reverse-map {f = f} {a' :: l} rewrite reverse-map {f = f} {l} = map-++-comm {a = reverse l} -- foldl theorem foldl-++ : {A B : Set} {l1 l2 : List A} {f : B → A → B} {b0 : B} → foldl f b0 (l1 ++ l2) == foldl f (foldl f b0 l1) l2 foldl-++ {l1 = []} = refl foldl-++ {l1 = a1 :: l1rest} = foldl-++ {l1 = l1rest} -- fold+map theorem foldl-map : {A' A B : Set} {l : List A'} {f-fold : B → A → B} {f-map : A' → A} {b0 : B} → foldl f-fold b0 (map f-map l) == foldl (λ b a' → f-fold b (f-map a')) b0 l foldl-map {l = []} = refl foldl-map {l = a' :: l} {f-fold} {f-map} {b0} = foldl-map {l = l} foldr-map : {A' A B : Set} {l : List A'} {f-fold : B → A → B} {f-map : A' → A} {b0 : B} → foldr f-fold b0 (map f-map l) == foldr (λ b a' → f-fold b (f-map a')) b0 l foldr-map {l = l} {_} {f} rewrite reverse-map {f = f} {l} = foldl-map {l = reverse l} -- zip/unzip theorems unzip-inv : {A B : Set} {l : List (A ∧ B)} {la : List A} {lb : List B} → unzip l == (la , lb) → l == zip la lb unzip-inv {l = []} form with form ... | refl = refl unzip-inv {l = (a' , b') :: rest} {a :: as} {b :: bs} form with unzip rest | unzip-inv {l = rest} refl | form ... | (as' , bs') | refl | refl = refl zip-inv : {A B : Set} {la : List A} {lb : List B} → ∥ la ∥ == ∥ lb ∥ → unzip (zip la lb) == (la , lb) zip-inv {la = []} {[]} len-eq = refl zip-inv {la = a :: as} {b :: bs} len-eq with unzip (zip as bs) | zip-inv (1+inj len-eq) ... | (as' , bs') | refl = refl -- _≈_ theorems ≈-++-comm-lem' : (A : Set) (l1 l2 : List A) (i : Nat) (a : A) → (l1 ++ l2) ⟦ i ⟧ == Some a → Σ[ i' ∈ Nat ] ((l2 ++ l1) ⟦ i' ⟧ == Some a) ≈-++-comm-lem' A l1 l2 i a i∈l1++l2 with append-index-split {l1 = l1} i∈l1++l2 ... | Inl i∈l1 = _ , i∈l2→|l1|+i∈l1++l2 {l1 = l2} i∈l1 ... | Inr (j , |l1|+j=i , j∈l2) = _ , i∈l1→i∈l1++l2 {l1 = l2} j∈l2 ≈-++-comm : {A : Set} {l1 l2 : List A} → l1 ++ l2 ≈ l2 ++ l1 ≈-++-comm {A} {l1} {l2} = ≈-++-comm-lem' A l1 l2 , ≈-++-comm-lem' A l2 l1 ≈-++-dup : {A : Set} {l : List A} → l ++ l ≈ l ≈-++-dup {l = []} = (λ i a ()) , (λ i a ()) ≈-++-dup {A} {a :: l} = ≈-++-dup'1 , ≈-++-dup'2 where ≈-++-dup'1 : (i : Nat) (a' : A) → (a :: (l ++ (a :: l))) ⟦ i ⟧ == Some a' → Σ[ i' ∈ Nat ] ((a :: l) ⟦ i' ⟧ == Some a') ≈-++-dup'1 Z a' i∈alal = Z , i∈alal ≈-++-dup'1 (1+ i) a' i∈alal with append-index-split {l1 = l} i∈alal ... | Inl i∈l = (1+ i) , i∈l ... | Inr (j , |l1|+j=i , j∈al) = j , j∈al ≈-++-dup'2 : (i : Nat) (a' : A) → (a :: l) ⟦ i ⟧ == Some a' → Σ[ i' ∈ Nat ] ((a :: (l ++ (a :: l))) ⟦ i' ⟧ == Some a') ≈-++-dup'2 i a' i∈al = (1 + ∥ l ∥ + i) , i∈l2→|l1|+i∈l1++l2 {l1 = l} i∈al
{ "alphanum_fraction": 0.4027755495, "avg_line_length": 37.8905775076, "ext": "agda", "hexsha": "ff61728d150be42241d546aa983d1a13d641e1fd", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "db857f3e7dc9a4793f68504e6365d93ed75d7f88", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nickcollins/dependent-dicts-agda", "max_forks_repo_path": "List.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "db857f3e7dc9a4793f68504e6365d93ed75d7f88", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nickcollins/dependent-dicts-agda", "max_issues_repo_path": "List.agda", "max_line_length": 99, "max_stars_count": null, "max_stars_repo_head_hexsha": "db857f3e7dc9a4793f68504e6365d93ed75d7f88", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nickcollins/dependent-dicts-agda", "max_stars_repo_path": "List.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5817, "size": 12466 }
{-# OPTIONS --safe #-} module Definition.Conversion.Soundness where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Conversion open import Definition.Conversion.Whnf open import Definition.Typed.Consequences.Syntactic open import Definition.Typed.Consequences.NeTypeEq open import Tools.Product import Tools.PropositionalEquality as PE mutual -- Algorithmic equality of neutrals is well-formed. soundness~↑! : ∀ {k l A lA Γ} → Γ ⊢ k ~ l ↑! A ^ lA → Γ ⊢ k ≡ l ∷ A ^ [ ! , lA ] soundness~↑! (var-refl x x≡y) = PE.subst (λ y → _ ⊢ _ ≡ var y ∷ _ ^ _) x≡y (refl x) soundness~↑! (app-cong {rF = !} k~l x₁) = app-cong (soundness~↓! k~l) (soundnessConv↑Term x₁) soundness~↑! (app-cong {rF = %} k~l x₁) = app-cong (soundness~↓! k~l) (let _ , _ , y = soundness~↑% x₁ in y) soundness~↑! (natrec-cong x₁ x₂ x₃ k~l) = natrec-cong (soundnessConv↑ x₁) (soundnessConv↑Term x₂) (soundnessConv↑Term x₃) (soundness~↓! k~l) soundness~↑! (Emptyrec-cong x₁ k~l) = let ⊢k , ⊢l , _ = soundness~↑% k~l in Emptyrec-cong (soundnessConv↑ x₁) ⊢k ⊢l soundness~↑! (Id-cong X x x₁) = Id-cong (soundness~↓! X) (soundnessConv↑Term x) (soundnessConv↑Term x₁) soundness~↑! (Id-ℕ X x) = Id-cong (refl (ℕⱼ (wfEqTerm (soundness~↓! X)))) (soundness~↓! X) (soundnessConv↑Term x) soundness~↑! (Id-ℕ0 X) = let XX = soundness~↓! X in Id-cong (refl (ℕⱼ (wfEqTerm XX))) (refl (zeroⱼ (wfEqTerm XX))) XX soundness~↑! (Id-ℕS x X) = let XX = soundness~↓! X in Id-cong (refl (ℕⱼ (wfEqTerm XX))) (suc-cong (soundnessConv↑Term x)) XX soundness~↑! (Id-U X x) = Id-cong (refl (univ 0<1 (wfEqTerm (soundness~↓! X)))) (soundness~↓! X) (soundnessConv↑Term x) soundness~↑! (Id-Uℕ X) = let XX = soundness~↓! X in Id-cong (refl (univ 0<1 (wfEqTerm XX))) (refl (ℕⱼ (wfEqTerm XX))) XX soundness~↑! (Id-UΠ x X) = let XX = soundness~↓! X xx = soundnessConv↑Term x in Id-cong (refl (univ 0<1 (wfEqTerm XX))) xx XX soundness~↑! (cast-cong X x x₁ x₂ x₃) = cast-cong (soundness~↓! X) (soundnessConv↑Term x) (soundnessConv↑Term x₁) x₂ x₃ soundness~↑! (cast-ℕ X x x₁ x₂) = let XX = soundness~↓! X in cast-cong (refl (ℕⱼ (wfEqTerm XX))) XX (soundnessConv↑Term x) x₁ x₂ soundness~↑! (cast-ℕℕ X x x₁) = let XX = soundness~↓! X in cast-cong (refl (ℕⱼ (wfEqTerm XX))) (refl (ℕⱼ (wfEqTerm XX))) XX x x₁ soundness~↑! (cast-Π x X x₁ x₂ x₃) = cast-cong (soundnessConv↑Term x) (soundness~↓! X) (soundnessConv↑Term x₁) x₂ x₃ soundness~↑! (cast-Πℕ x x₁ x₂ x₃) = let XX = (soundnessConv↑Term x) in cast-cong XX (refl (ℕⱼ (wfEqTerm XX))) (soundnessConv↑Term x₁) x₂ x₃ soundness~↑! (cast-ℕΠ x x₁ x₂ x₃) = let XX = (soundnessConv↑Term x) in cast-cong (refl (ℕⱼ (wfEqTerm XX))) XX (soundnessConv↑Term x₁) x₂ x₃ soundness~↑! (cast-ΠΠ%! x x₁ x₂ x₃ x₄) = cast-cong (soundnessConv↑Term x) (soundnessConv↑Term x₁) (soundnessConv↑Term x₂) x₃ x₄ soundness~↑! (cast-ΠΠ!% x x₁ x₂ x₃ x₄) = cast-cong (soundnessConv↑Term x) (soundnessConv↑Term x₁) (soundnessConv↑Term x₂) x₃ x₄ soundness~↑% : ∀ {k l A lA Γ} → Γ ⊢ k ~ l ↑% A ^ lA → Γ ⊢ k ∷ A ^ [ % , lA ] × Γ ⊢ l ∷ A ^ [ % , lA ] × Γ ⊢ k ≡ l ∷ A ^ [ % , lA ] soundness~↑% (%~↑ ⊢k ⊢l) = ⊢k , ⊢l , proof-irrelevance ⊢k ⊢l soundness~↑ : ∀ {k l A rA lA Γ} → Γ ⊢ k ~ l ↑ A ^ [ rA , lA ] → Γ ⊢ k ≡ l ∷ A ^ [ rA , lA ] soundness~↑ (~↑! x) = soundness~↑! x soundness~↑ (~↑% x) = let _ , _ , y = soundness~↑% x in y -- Algorithmic equality of neutrals in WHNF is well-formed. soundness~↓! : ∀ {k l A lA Γ} → Γ ⊢ k ~ l ↓! A ^ lA → Γ ⊢ k ≡ l ∷ A ^ [ ! , lA ] soundness~↓! ([~] A₁ D whnfA k~l) = conv (soundness~↑! k~l) (subset* D) -- Algorithmic equality of types is well-formed. soundnessConv↑ : ∀ {A B rA Γ} → Γ ⊢ A [conv↑] B ^ rA → Γ ⊢ A ≡ B ^ rA soundnessConv↑ ([↑] A′ B′ D D′ whnfA′ whnfB′ A′<>B′) = trans (subset* D) (trans (soundnessConv↓ A′<>B′) (sym (subset* D′))) -- Algorithmic equality of types in WHNF is well-formed. soundnessConv↓ : ∀ {A B rA Γ} → Γ ⊢ A [conv↓] B ^ rA → Γ ⊢ A ≡ B ^ rA soundnessConv↓ (U-refl PE.refl ⊢Γ) = refl (Uⱼ ⊢Γ) soundnessConv↓ (univ x₂) = univ (soundnessConv↓Term x₂) -- Algorithmic equality of terms is well-formed. soundnessConv↑Term : ∀ {a b A lA Γ} → Γ ⊢ a [conv↑] b ∷ A ^ lA → Γ ⊢ a ≡ b ∷ A ^ [ ! , lA ] soundnessConv↑Term ([↑]ₜ B t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u) = conv (trans (subset*Term d) (trans (soundnessConv↓Term t<>u) (sym (subset*Term d′)))) (sym (subset* D)) -- Algorithmic equality of terms in WHNF is well-formed. soundnessConv↓Term : ∀ {a b A lA Γ} → Γ ⊢ a [conv↓] b ∷ A ^ lA → Γ ⊢ a ≡ b ∷ A ^ [ ! , lA ] soundnessConv↓Term (ne x) = soundness~↓! x soundnessConv↓Term (ℕ-refl ⊢Γ) = refl (ℕⱼ ⊢Γ) soundnessConv↓Term (Empty-refl PE.refl ⊢Γ) = refl (Emptyⱼ ⊢Γ) soundnessConv↓Term (Π-cong PE.refl PE.refl PE.refl PE.refl l< l<' F c c₁) = Π-cong l< l<' F (soundnessConv↑Term c) (soundnessConv↑Term c₁) soundnessConv↓Term (∃-cong PE.refl F c c₁) = ∃-cong F (soundnessConv↑Term c) (soundnessConv↑Term c₁) soundnessConv↓Term (ℕ-ins x) = soundness~↓! x -- soundnessConv↓Term (Empty-ins x) = soundness~↓% x soundnessConv↓Term (ne-ins t u x x₁) = let whnfM , neA , neB = ne~↓! x₁ X = soundness~↓! x₁ _ , t∷M , _ = syntacticEqTerm X _ , M≡A' = neTypeEq neA t∷M t -- soundnessConv↑ M≡A in conv X M≡A' soundnessConv↓Term (zero-refl ⊢Γ) = refl (zeroⱼ ⊢Γ) soundnessConv↓Term (suc-cong c) = suc-cong (soundnessConv↑Term c) soundnessConv↓Term (η-eq l< l<' F x x₁ y y₁ c) = η-eq l< l<' F x x₁ (soundnessConv↑Term c) soundnessConv↓Term (U-refl PE.refl ⊢Γ) = refl (univ 0<1 ⊢Γ) app-cong′ : ∀ {Γ k l t v F rF lF G lG lΠ} → Γ ⊢ k ~ l ↓! Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ ι lΠ → Γ ⊢ t [genconv↑] v ∷ F ^ [ rF , ι lF ] → Γ ⊢ k ∘ t ^ lΠ ~ l ∘ v ^ lΠ ↑ G [ t ] ^ [ ! , ι lG ] app-cong′ k~l t=v = ~↑! (app-cong k~l t=v) natrec-cong′ : ∀ {Γ k l h g a b F lF G} → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F [conv↑] G ^ [ ! , ι lF ] → Γ ⊢ a [conv↑] b ∷ F [ zero ] ^ ι lF → Γ ⊢ h [conv↑] g ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF) ° lF ° lF ^ ι lF → Γ ⊢ k ~ l ↓! ℕ ^ ι ⁰ → Γ ⊢ natrec lF F a h k ~ natrec lF G b g l ↑ F [ k ] ^ [ ! , ι lF ] natrec-cong′ F=G a=b h=g k~l = ~↑! (natrec-cong F=G a=b h=g k~l) Emptyrec-cong′ : ∀ {Γ k l F lF lEmpty G} → Γ ⊢ F [conv↑] G ^ [ ! , ι lF ] → Γ ⊢ k ~ l ↑% Empty lEmpty ^ ι lEmpty → Γ ⊢ Emptyrec lF lEmpty F k ~ Emptyrec lF lEmpty G l ↑ F ^ [ ! , ι lF ] Emptyrec-cong′ F=G k~l = ~↑! (Emptyrec-cong F=G k~l)
{ "alphanum_fraction": 0.570135075, "avg_line_length": 57.093220339, "ext": "agda", "hexsha": "c2ec181c4d8ee00e6e45df7a1cebf0c74ded4126", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_path": "Definition/Conversion/Soundness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CoqHott/logrel-mltt", "max_issues_repo_path": "Definition/Conversion/Soundness.agda", "max_line_length": 141, "max_stars_count": 2, "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_path": "Definition/Conversion/Soundness.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z", "num_tokens": 2974, "size": 6737 }
{- This second-order term syntax was created from the following second-order syntax description: syntax Empty | E type 𝟘 : 0-ary term abort : 𝟘 -> α theory (𝟘η) e : 𝟘 c : α |> abort(e) = c -} module Empty.Syntax where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Families.Core open import SOAS.Construction.Structure open import SOAS.ContextMaps.Inductive open import SOAS.Metatheory.Syntax open import Empty.Signature private variable Γ Δ Π : Ctx α : ET 𝔛 : Familyₛ -- Inductive term declaration module E:Terms (𝔛 : Familyₛ) where data E : Familyₛ where var : ℐ ⇾̣ E mvar : 𝔛 α Π → Sub E Π Γ → E α Γ abort : E 𝟘 Γ → E α Γ open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛 Eᵃ : MetaAlg E Eᵃ = record { 𝑎𝑙𝑔 = λ where (abortₒ ⋮ a) → abort a ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) } module Eᵃ = MetaAlg Eᵃ module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where open MetaAlg 𝒜ᵃ 𝕤𝕖𝕞 : E ⇾̣ 𝒜 𝕊 : Sub E Π Γ → Π ~[ 𝒜 ]↝ Γ 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t 𝕊 (t ◂ σ) (old v) = 𝕊 σ v 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε) 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v 𝕤𝕖𝕞 (abort a) = 𝑎𝑙𝑔 (abortₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Eᵃ 𝒜ᵃ 𝕤𝕖𝕞 𝕤𝕖𝕞ᵃ⇒ = record { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t } ; ⟨𝑣𝑎𝑟⟩ = refl ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } } where open ≡-Reasoning ⟨𝑎𝑙𝑔⟩ : (t : ⅀ E α Γ) → 𝕤𝕖𝕞 (Eᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t) ⟨𝑎𝑙𝑔⟩ (abortₒ ⋮ _) = refl 𝕊-tab : (mε : Π ~[ E ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v) 𝕊-tab mε new = refl 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v module _ (g : E ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Eᵃ 𝒜ᵃ g) where open MetaAlg⇒ gᵃ⇒ 𝕤𝕖𝕞! : (t : E α Γ) → 𝕤𝕖𝕞 t ≡ g t 𝕊-ix : (mε : Sub E Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v) 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε)) = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε)) 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩ 𝕤𝕖𝕞! (abort a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ -- Syntax instance for the signature E:Syn : Syntax E:Syn = record { ⅀F = ⅀F ; ⅀:CS = ⅀:CompatStr ; mvarᵢ = E:Terms.mvar ; 𝕋:Init = λ 𝔛 → let open E:Terms 𝔛 in record { ⊥ = E ⋉ Eᵃ ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ } ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } } -- Instantiation of the syntax and metatheory open Syntax E:Syn public open E:Terms public open import SOAS.Families.Build public open import SOAS.Syntax.Shorthands Eᵃ public open import SOAS.Metatheory E:Syn public
{ "alphanum_fraction": 0.5562987737, "avg_line_length": 23.1982758621, "ext": "agda", "hexsha": "ef0a4aef30d62a7e58bdf190d92b8af8002856d1", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_path": "out/Empty/Syntax.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_path": "out/Empty/Syntax.agda", "max_line_length": 93, "max_stars_count": 39, "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_path": "out/Empty/Syntax.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "num_tokens": 1636, "size": 2691 }
postulate A : Set f : {{_ : A}} → A f = {!!}
{ "alphanum_fraction": 0.375, "avg_line_length": 8, "ext": "agda", "hexsha": "108c056e4f4b59c43500ba453a541ee6935246fb", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Issue4307.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Issue4307.agda", "max_line_length": 17, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Issue4307.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 22, "size": 48 }
open import Oscar.Prelude open import Oscar.Class open import Oscar.Class.Surjection open import Oscar.Class.Smap open import Oscar.Data.Constraint module Oscar.Class.Surjextensionality where module Surjextensionality {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁) (_∼̇₁_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁) (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂) (_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂) (surjection : Surjection.type 𝔒₁ 𝔒₂) (smap : Smap.type _∼₁_ _∼₂_ surjection surjection) where open ℭLASS (_∼₁_ ,, {- FIXME including `(λ {x y} → _∼̇₁_ {x} {y}) ,, ` leads to instance search depth exhausted in Oscar.Data.Surjextenscollation -} _∼₂_ ,, (λ {x y} → _∼̇₂_ {x} {y}) ,, surjection ,, (λ {x y} → smap {x} {y})) (∀ x y (f₁ f₂ : x ∼₁ y) → f₁ ∼̇₁ f₂ → smap f₁ ∼̇₂ smap f₂) public TYPE = ∀ {x y} {f₁ f₂ : x ∼₁ y} → f₁ ∼̇₁ f₂ → smap f₁ ∼̇₂ smap f₂ module Surjextensionality! {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁) (_∼̇₁_ : ∀ {x y} → _∼₁_ x y → _∼₁_ x y → Ø ℓ₁) (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂) (_∼̇₂_ : ∀ {x y} → _∼₂_ x y → _∼₂_ x y → Ø ℓ₂) ⦃ _ : Surjection.class 𝔒₁ 𝔒₂ ⦄ ⦃ _ : Smap.class _∼₁_ _∼₂_ surjection surjection ⦄ = Surjextensionality (_∼₁_) (λ {x y} → _∼̇₁_ {x} {y}) (_∼₂_) (λ {x y} → _∼̇₂_ {x} {y}) surjection (λ {x y} → smap {x = x} {y}) module _ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} {∼₁ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁} {∼̇₁ : ∀ {x y} → ∼₁ x y → ∼₁ x y → Ø ℓ₁} {∼₂ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂} {∼̇₂ : ∀ {x y} → ∼₂ x y → ∼₂ x y → Ø ℓ₂} {surjection : Surjection.type 𝔒₁ 𝔒₂} {smap : Smap.type ∼₁ ∼₂ surjection surjection} where open Surjextensionality ∼₁ (λ {x y} → ∼̇₁ {x} {y}) ∼₂ (λ {x y} → ∼̇₂ {x} {y}) surjection (λ {x y} → smap {x = x} {y}) surjextensionality : ⦃ _ : class ⦄ → TYPE surjextensionality = method _ _ _ _ module _ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} {∼₁ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁} {∼̇₁ : ∀ {x y} → ∼₁ x y → ∼₁ x y → Ø ℓ₁} {∼₂ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂} (∼̇₂ : ∀ {x y} → ∼₂ x y → ∼₂ x y → Ø ℓ₂) {surjection : Surjection.type 𝔒₁ 𝔒₂} {smap : Smap.type ∼₁ ∼₂ surjection surjection} where open Surjextensionality ∼₁ (λ {x y} → ∼̇₁ {x} {y}) ∼₂ (λ {x y} → ∼̇₂ {x} {y}) surjection (λ {x y} → smap {x = x} {y}) surjextensionality[_] : ⦃ _ : class ⦄ → TYPE surjextensionality[_] = surjextensionality ⟪⟫-surjextensionality[]-syntax = surjextensionality[_] syntax ⟪⟫-surjextensionality[]-syntax t x = ⟪ x ⟫[ t ]
{ "alphanum_fraction": 0.5382424736, "avg_line_length": 34.6197183099, "ext": "agda", "hexsha": "302360e23a57db2cd2ad1bd2ca6c74fc31a2073d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Surjextensionality.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Surjextensionality.agda", "max_line_length": 293, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Surjextensionality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1387, "size": 2458 }
{-# OPTIONS --exact-split #-} -- {-# OPTIONS -v tc.cover.splittree:10 #-} open import Common.Prelude open import Common.Equality test : {m n : Nat} → m ≡ n → Nat test {zero} refl = zero test {suc m} refl = suc m
{ "alphanum_fraction": 0.6325581395, "avg_line_length": 21.5, "ext": "agda", "hexsha": "d95589f68ca91e145c538a1356bb0103ee9e81a5", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue1333.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue1333.agda", "max_line_length": 43, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue1333.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 69, "size": 215 }
open import Data.Nat using (ℕ; suc) open import Data.Fin using (Fin; zero; suc) infix 9 #_ infixl 7 _·_ infix 6 ƛ_ data Term : ℕ → Set where #_ : ∀ {n : ℕ} → Fin n → Term n ƛ_ : ∀ {n : ℕ} → Term (suc n) → Term n _·_ : ∀ {n : ℕ} → Term n → Term n → Term n Rename : ℕ → ℕ → Set Rename n m = Fin n → Fin m Subst : ℕ → ℕ → Set Subst n m = Fin n → Term m ext : ∀ {n m} → Rename n m → Rename (suc n) (suc m) ext ρ zero = zero ext ρ (suc x) = suc (ρ x) rename : ∀ {n m} → Rename n m → (Term n → Term m) rename ρ (# x) = # (ρ x) rename ρ (ƛ M) = ƛ (rename (ext ρ) M) rename ρ (M · N) = rename ρ M · rename ρ N exts : ∀ {n m} → Subst n m → Subst (suc n) (suc m) exts σ zero = # zero exts σ (suc x) = rename suc (σ x) subst : ∀ {n m} → Subst n m → (Term n → Term m) subst σ (# x) = σ x subst σ (ƛ M) = ƛ (subst (exts σ) M) subst σ (M · N) = subst σ M · subst σ N subst-zero : ∀ {n} → Term n → Subst (suc n) n subst-zero M zero = M subst-zero M (suc x) = # x infix 8 _[_] _[_] : ∀ {n} → Term (suc n) → Term n → Term n M [ N ] = subst (subst-zero N) M
{ "alphanum_fraction": 0.5195989061, "avg_line_length": 22.8541666667, "ext": "agda", "hexsha": "e209ed8c789f5ffb5bed8bb851625b7bf2f27d63", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "iwilare/church-rosser", "max_forks_repo_path": "DeBruijn.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "iwilare/church-rosser", "max_issues_repo_path": "DeBruijn.agda", "max_line_length": 51, "max_stars_count": 5, "max_stars_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "iwilare/church-rosser", "max_stars_repo_path": "DeBruijn.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-22T01:43:09.000Z", "max_stars_repo_stars_event_min_datetime": "2020-06-02T07:27:54.000Z", "num_tokens": 479, "size": 1097 }
module Formalization.PrimitiveRecursion where import Lvl open import Data open import Data.ListSized open import Numeral.Finite open import Numeral.Natural open import Syntax.Number open import Type{Lvl.𝟎} -- Function(n) is a syntactic representation of primitive recursive functions of type (ℕⁿ → ℕ). -- The syntax data Function : ℕ → Type where -- Base cases Base : Function(0) Successor : Function(1) Projection : ∀{n : ℕ} → (i : 𝕟(n)) → Function(n) -- Inductive cases Composition : ∀{m n : ℕ} → Function(n) → List(Function(m))(n) → Function(m) Recursion : ∀{n : ℕ} → Function(n) → Function(𝐒(𝐒(n))) → Function(𝐒(n)) Primitive : Type Primitive = ℕ module _ where open import Data.ListSized.Functions open import Functional private variable m n : ℕ private variable i : 𝕟(n) private variable x v : Primitive private variable xs vs : List(Primitive)(n) private variable f g : Function(m) private variable fs gs : List(Function(m))(n) -- The operational semantics. data _$_⟹_ : ∀{m n} → List(Function(m))(n) → List(Primitive)(m) → List(Primitive)(n) → Type data _$_⟶_ : ∀{n} → Function(n) → List(Primitive)(n) → ℕ → Type where zero : (Base $ ∅ ⟶ 𝟎) succ : (Successor $ singleton(n) ⟶ 𝐒(n)) proj : (Projection{n}(i) $ xs ⟶ index(i)(xs)) comp : (f $ vs ⟶ v) → (gs $ xs ⟹ vs) → (Composition{m}{n} f gs $ xs ⟶ v) rec𝟎 : (f $ xs ⟶ v) → (Recursion f g $ (𝟎 ⊰ xs) ⟶ v) rec𝐒 : (Recursion f g $ (n ⊰ xs) ⟶ x) → (g $ (n ⊰ x ⊰ xs) ⟶ v) → (Recursion f g $ (𝐒(n) ⊰ xs) ⟶ v) data _$_⟹_ where base : (∅ $ xs ⟹ ∅) step : (f $ xs ⟶ v) → (fs $ xs ⟹ vs) → ((f ⊰ fs) $ xs ⟹ (v ⊰ vs)) -- Functionally equivalent to `evaluate f (map(g ↦ evaluate g xs)(gs))`, but the termination checker does not accept that form. mapEvaluate : ∀{m n} → List(Function(m))(n) → List(Primitive)(m) → List(Primitive)(n) -- The denotational semantics. -- This is possible to encode into an Agda function because: Primitive recursive functions ⊆ Agda functions. -- `Base` is interpreted as the constant 0. -- `Successor` is interpreted as the successor function of ℕ. -- `Projection{n}(i)` is interpreted as the projection of the i:th element of ℕⁿ. -- `Composition(f)(gs)` is interpreted as generalized composition by using map on the arguments of a function. -- Specifically (f ∘ (map gs)). -- `Recursion(f)(g)` is interpreted as a "recursion constructor". -- This is used to construct a function `r` in which the following holds: -- • r(0 ,..xs) = f(..xs) -- • r(𝐒(n),..xs) = g(n,r(n,..xs),..xs) {-# TERMINATING #-} -- TODO: Terminated before but the termination checker in Agda version 2.6.2-9bed10c denies this (or in some random cases it gives an internal error at src/full/Agda/TypeChecking/Reduce/Fast.hs:1358) evaluate : ∀{n} → Function(n) → (List(Primitive)(n) → Primitive) evaluate {.𝟎} (Base) ∅ = 𝟎 evaluate {.𝐒(𝟎)}(Successor) (singleton x) = 𝐒(x) evaluate {_} (Projection(i)) xs = index(i)(xs) evaluate {m} (Composition{m}{n}(f)(gs)) xs = evaluate{n} f (mapEvaluate{m}{n} gs xs) evaluate {𝐒(_)} (Recursion(f)(g)) (𝟎 ⊰ xs) = evaluate f xs evaluate {𝐒(m)} (Recursion(f)(g)) (𝐒(n) ⊰ xs) = evaluate{𝐒(𝐒(m))} g (n ⊰ (evaluate{𝐒 m} (Recursion(f)(g)) (n ⊰ xs) ⊰ xs)) mapEvaluate ∅ xs = ∅ mapEvaluate{m}{𝐒(n)} (g ⊰ gs) xs = (evaluate{m} g xs) ⊰ (mapEvaluate{m}{n} gs xs) ------------------------------------------------------ -- This section proves the equivalence between the operational and the denotational semantics. Or it can be interpreted as the correctness of one of the definitions by the other one. -- This equivalence should be obvious from the definitions. -- open import Relator.Equals open import Relator.Equals.Proofs open import Syntax.Transitivity [⟹]-to-eval : (fs $ xs ⟹ vs) → (mapEvaluate fs xs ≡ vs) [⟶]-to-eval : (f $ xs ⟶ v) → (evaluate f xs ≡ v) [⟶]-to-eval zero = [≡]-intro [⟶]-to-eval succ = [≡]-intro [⟶]-to-eval {xs = _⊰_ {𝟎} x xs} (proj {i = 𝟎}) = [≡]-intro [⟶]-to-eval {xs = _⊰_ {𝐒 n} x xs} (proj {i = 𝟎}) = [≡]-intro [⟶]-to-eval {xs = _⊰_ {𝐒 n} x xs} (proj {i = 𝐒 i}) = [≡]-intro [⟶]-to-eval (comp p q) with [⟶]-to-eval p | [⟹]-to-eval q ... | [≡]-intro | [≡]-intro = [≡]-intro [⟶]-to-eval (rec𝟎 p) with [⟶]-to-eval p ... | [≡]-intro = [≡]-intro [⟶]-to-eval (rec𝐒 p q) with [⟶]-to-eval p | [⟶]-to-eval q ... | [≡]-intro | [≡]-intro = [≡]-intro [⟹]-to-eval {fs = ∅} {vs = ∅} _ = [≡]-intro [⟹]-to-eval {fs = f ⊰ fs} {vs = v ⊰ vs} (step p ps) with [⟶]-to-eval p | [⟹]-to-eval {fs = fs} {vs = vs} ps ... | [≡]-intro | [≡]-intro = [≡]-intro eval-to-[⟹] : (mapEvaluate fs xs ≡ vs) → (fs $ xs ⟹ vs) {-# TERMINATING #-} -- TODO: See TODO above in eval eval-to-[⟶] : (evaluate f xs ≡ v) → (f $ xs ⟶ v) eval-to-[⟶] {f = Base} {∅} [≡]-intro = zero eval-to-[⟶] {f = Successor} {singleton x} [≡]-intro = succ eval-to-[⟶] {f = Projection _} [≡]-intro = proj eval-to-[⟶] {f = Composition f gs} {xs} p = comp (eval-to-[⟶] p) (eval-to-[⟹] [≡]-intro) eval-to-[⟶] {f = Recursion f g} {𝟎 ⊰ xs} p = rec𝟎(eval-to-[⟶] {f = f}{xs = xs} p) eval-to-[⟶] {f = Recursion f g} {𝐒(n) ⊰ xs} p = rec𝐒 (eval-to-[⟶] [≡]-intro) (eval-to-[⟶] p) eval-to-[⟹] {fs = ∅} [≡]-intro = base eval-to-[⟹] {fs = f ⊰ fs} [≡]-intro = step (eval-to-[⟶] [≡]-intro) (eval-to-[⟹] [≡]-intro) -- TODO: Is it possible to prove that _⟶_ terminates and normalizes by using [⟶]-to-eval (total and deterministic)? open import Function.Equals open import Logic open import Logic.Predicate -- When a function on lists of primitives are primitive recursive. PrimitiveRecursive : (List(Primitive)(n) → Primitive) → Stmt PrimitiveRecursive(f) = ∃(e ↦ evaluate e ⊜ f) Const : Function(0) → ∀{n} → Function(n) Const(c) = Composition(c) ∅ -- TODO: Would encoding pairs make this easier to implement (e.g. the Cantor Pairing Function? -- This is used to construct a function `r` in which the following holds for its evaluation: -- • r(0 ,..xs) = f(..xs) -- • r(1 ,..xs) = g(..xs) -- • r(𝐒(𝐒(n)),..xs) = h(n,r(𝐒(n),..xs),r(n,..xs),..xs) -- Recursion₂ : ∀{n : ℕ} → Function(n) → Function(n) → Function(𝐒(𝐒(𝐒(n)))) → Function(𝐒(n)) -- Recursion₂{n} (f)(g)(h) = Composition(Projection(0)) (Helper ⊰ ∅) where -- Recursion -- -- Helper : Function(2) -- Helper = -- module Arithmetic where -- TODO: Prove that these are correct by `evaluate` Zero = Base Number : ℕ → Function(0) Number(𝟎) = Zero Number(𝐒(n)) = Composition(Successor) (Number(n) ⊰ ∅) Swap₂ : Function(2) → Function(2) Swap₂(f) = Composition(f) (Projection(1) ⊰ Projection(0) ⊰ ∅) -- Addition (+) in ℕ. -- It describes the following function: -- evaluate(Addition)[𝟎 ,b] = 𝟎 -- evaluate(Addition)[𝐒(a),b] = 𝐒(b) Addition : Function(2) Addition = Recursion(Projection(0)) (Composition Successor (Projection(1) ⊰ ∅)) -- Multiplication (⋅) in ℕ. -- It describes the following function: -- evaluate(Multiplication)[𝟎 ,b] = 𝟎 -- evaluate(Multiplication)[𝐒(a),b] = evaluate(Multiplication)[a,b] + b Multiplication : Function(2) Multiplication = Recursion (Const(Zero)) (Composition Addition (Projection(1) ⊰ Projection(2) ⊰ ∅)) -- Exponentiation (^) in ℕ. -- It describes the following function: -- evaluate(Exponentiation)[a ,0 ] = 1 -- evaluate(Exponentiation)[a ,𝐒(b)] = evaluate(Exponentiation)[a,b] ⋅ a Exponentiation : Function(2) Exponentiation = Swap₂(Recursion (Composition Successor (Const Zero ⊰ ∅)) (Composition Multiplication (Projection(1) ⊰ Projection(2) ⊰ ∅))) -- Factorial (!) in ℕ. -- It describes the following function: -- evaluate(Factorial)[𝟎 ] = 1 -- evaluate(Factorial)[𝐒(a)] = 𝐒(a) ⋅ evaluate(Factorial)[a,b] Factorial : Function(1) Factorial = Recursion(Number(1)) (Composition Multiplication ((Composition Successor (Projection(0) ⊰ ∅)) ⊰ Projection(1) ⊰ ∅)) -- Predecessor (𝐏) in ℕ. -- It describes the following function: -- evaluate(Predecessor)[𝟎 ] = 𝟎 -- evaluate(Predecessor)[𝐒(a)] = a Predecessor : Function(1) Predecessor = Recursion(Zero) (Projection(0)) -- Monus/Cut-off minus (−₀) in ℕ. -- It describes the following function: -- evaluate(Monus)[b,𝟎 ] = b -- evaluate(Monus)[b,𝐒(a)] = 𝐏(evaluate(Monus)[b,a]) Monus : Function(2) Monus = Swap₂(Recursion(Projection(0)) (Composition Predecessor (Projection(1) ⊰ ∅))) -- Maximum (max) of ℕ² in ℕ. -- It describes the following function: -- evaluate(Max)[a,b] = a + (b −₀ a) Max : Function(2) Max = Composition(Addition) (Projection(0) ⊰ Swap₂(Monus) ⊰ ∅) -- Minimum (min) of ℕ² in ℕ. -- It describes the following function: -- evaluate(Min)[a,b] = (a + b) −₀ max(a,b) Min : Function(2) Min = Composition(Monus) (Addition ⊰ Max ⊰ ∅) -- It describes the following function: -- evaluate(Distance)[a,b] = max(x −₀ y , y −₀ x) Distance : Function(2) Distance = Composition(Addition) (Monus ⊰ Swap₂(Monus) ⊰ ∅) -- It describes the following function: -- evaluate(IsZero)[𝟎] = 1 -- evaluate(IsZero)[𝐒(_)] = 0 IsZero : Function(1) IsZero = Recursion(Number(1)) (Const(Zero)) -- It describes the following function: -- evaluate(IsZero)[𝟎] = 0 -- evaluate(IsZero)[𝐒(_)] = 1 IsNonZero : Function(1) IsNonZero = Composition(IsZero) (IsZero ⊰ ∅) Eq : Function(2) Eq = Composition(IsZero) (Distance ⊰ ∅) -- It describes the following function: -- evaluate(Fibonacci)[𝟎] = 0 -- evaluate(Fibonacci)[𝐒(_)] = 1 -- Fibonacci : Function(1) -- Fibonacci = Composition(Projection(0)) (Fib ⊰ ∅) where -- Fib : Function(2) -- Fib = -- TODO: http://www.reluctantm.com/gcruttw/teaching/cpsc513.W2010/A3Solutions.pdf -- TODO: http://ii.fmph.uniba.sk/cl/courses/1-AIN-625-lpp/0910zs/ln/doc/ch_p_gd.pdf module Proofs where open import Functional open import Logic.Propositional open import Numeral.Natural.Oper open import Numeral.Natural.Oper.Comparisons open import Numeral.Natural.Oper.Proofs open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Operator.Properties open import Structure.Relator.Properties open import Syntax.Transitivity addition-correctness : ∀{a b} → (evaluate Arithmetic.Addition (a ⊰ b ⊰ ∅) ≡ a + b) addition-correctness {𝟎} {b} = [≡]-intro addition-correctness {𝐒 a} {b} = [≡]-with(𝐒) (addition-correctness {a}{b}) multiplication-correctness : ∀{a b} → (evaluate Arithmetic.Multiplication (a ⊰ b ⊰ ∅) ≡ a ⋅ b) multiplication-correctness {𝟎} {b} = [≡]-intro multiplication-correctness {𝐒 a} {b} = addition-correctness {evaluate Arithmetic.Multiplication (a ⊰ b ⊰ ∅)}{b} 🝖 [≡]-with(_+ b) (multiplication-correctness {a}{b}) 🝖 symmetry(_≡_) ([⋅]-with-[𝐒]ₗ {a}{b}) exponentiation-correctness : ∀{a b} → (evaluate Arithmetic.Exponentiation (a ⊰ b ⊰ ∅) ≡ a ^ b) exponentiation-correctness {a} {𝟎} = [≡]-intro exponentiation-correctness {a} {𝐒 b} = multiplication-correctness {evaluate Arithmetic.Exponentiation (a ⊰ b ⊰ ∅)}{a} 🝖 [≡]-with(_⋅ a) (exponentiation-correctness {a}{b}) 🝖 commutativity(_⋅_) {a ^ b}{a} factorial-correctness : ∀{a} → (evaluate Arithmetic.Factorial (a ⊰ ∅) ≡ a !) factorial-correctness {𝟎} = [≡]-intro factorial-correctness {𝐒 a} = multiplication-correctness {𝐒 a} 🝖 [≡]-with(𝐒(a) ⋅_) (factorial-correctness {a}) predecessor-correctness : ∀{a} → (evaluate Arithmetic.Predecessor (a ⊰ ∅) ≡ 𝐏(a)) predecessor-correctness {𝟎} = [≡]-intro predecessor-correctness {𝐒 a} = [≡]-intro monus-correctness : ∀{a b} → (evaluate Arithmetic.Monus (a ⊰ b ⊰ ∅) ≡ a −₀ b) monus-correctness {a} {𝟎} = [≡]-intro monus-correctness {𝟎} {𝐒 b} = predecessor-correctness{evaluate Arithmetic.Monus (𝟎 ⊰ b ⊰ ∅)} 🝖 [≡]-with(𝐏) (monus-correctness {𝟎}{b}) monus-correctness {𝐒 a} {𝐒 b} = predecessor-correctness{evaluate Arithmetic.Monus (𝐒(a) ⊰ b ⊰ ∅)} 🝖 [≡]-with(𝐏) (monus-correctness {𝐒 a}{b}) 🝖 symmetry(_≡_) ([−₀]-with-[𝐒]ᵣ {𝐒(a)}{b}) isnonzero-correctness : ∀{a} → (evaluate Arithmetic.IsNonZero (a ⊰ ∅) ≡ ℕbool(a ≢? 𝟎)) isnonzero-correctness {𝟎} = [≡]-intro isnonzero-correctness {𝐒 a} = [≡]-intro iszero-correctness : ∀{a} → (evaluate Arithmetic.IsZero (a ⊰ ∅) ≡ ℕbool(a ≡? 𝟎)) iszero-correctness {𝟎} = [≡]-intro iszero-correctness {𝐒 a} = [≡]-intro -- TODO: Formalize "Function(1) is countably infinite". Maybe take some inspiration from https://proofwiki.org/wiki/Not_All_URM_Computable_Functions_are_Primitive_Recursive . Then prove that (ℕ → ℕ) is not countably infinite, and therefore not all computable functions are expressible primitive recursively (is this argument constructive?) open import Data.Tuple open import Function.Inverse open import Logic.Predicate open import Logic.Propositional open import Type.Size.Countable open import Structure.Function.Domain.Proofs open import Structure.Function using (congruence₁) open import Syntax.Function open import Syntax.Transitivity postulate Function-countablyInfinite : CountablyInfinite(Function(1)) encodeFunction : Function(1) → ℕ encodeFunction = inv _ ⦃ bijective-to-invertible ⦃ bij = [∃]-proof Function-countablyInfinite ⦄ ⦄ -- TODO: Use a lifted Numeral.Natural.Sequence.pairIndexing as a witness directly (instead of encodePair). Another alternative is (a ↦ b ↦ 2ᵃ⋅3ᵇ) if it is easier to construct f that way. postulate Function-value-pair-countablyInfinite : CountablyInfinite(Function(1) ⨯ ℕ) encodePair : (Function(1) ⨯ ℕ) → ℕ encodePair = inv _ ⦃ bijective-to-invertible ⦃ bij = [∃]-proof Function-value-pair-countablyInfinite ⦄ ⦄ -- TODO: Is it possible to use Logic.DiagonalMethod for this proof? no-self-interpreter : ¬ ∃(interpret ↦ ∀{f}{n} → evaluate interpret (singleton (encodePair(f , n))) ≡ evaluate f (singleton n)) no-self-interpreter ([∃]-intro interpret ⦃ p ⦄) = 𝐒-not-self(symmetry(_≡_) x) where postulate f : Function(1) postulate f-correctness : ∀{g} → (evaluate f (singleton(encodeFunction g)) ≡ encodePair(g , encodeFunction g)) g : Function(1) g = Composition Successor (singleton (Composition interpret (singleton f))) x : evaluate g (singleton (encodeFunction g)) ≡ 𝐒(evaluate g (singleton (encodeFunction g))) x = evaluate g (singleton (encodeFunction g)) 🝖[ _≡_ ]-[] 𝐒(evaluate interpret (singleton(evaluate f (singleton(encodeFunction g))))) 🝖[ _≡_ ]-[ congruence₁(𝐒) (congruence₁(evaluate interpret) (congruence₁(singleton) f-correctness)) ] 𝐒(evaluate interpret (singleton(encodePair(g , encodeFunction g)))) 🝖[ _≡_ ]-[ congruence₁(𝐒) p ] 𝐒(evaluate g (singleton(encodeFunction g))) 🝖-end
{ "alphanum_fraction": 0.6193732572, "avg_line_length": 45.6424242424, "ext": "agda", "hexsha": "6ba45dae0015924a77da5a2f56417fb557018879", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Formalization/PrimitiveRecursion.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Formalization/PrimitiveRecursion.agda", "max_line_length": 341, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Formalization/PrimitiveRecursion.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 5345, "size": 15062 }
{-# OPTIONS --type-in-type #-} -- {-# OPTIONS -v tc.pos:10 -v tc.polarity:10 #-} -- Andreas, 2012-09-06, message on Agda list "Forget Hurken's paradox..." module Issue690 where infix 4 _≡_ data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x data ⊥ : Set where data D : Set where abs : ∀ {E : Set} → D ≡ E → (E → ⊥) → D lam : (D → ⊥) → D lam f = abs refl f app : D → D → ⊥ app (abs refl f) d = f d omega : D omega = lam (λ x → app x x) Omega : ⊥ Omega = app omega omega
{ "alphanum_fraction": 0.5482546201, "avg_line_length": 16.7931034483, "ext": "agda", "hexsha": "8cafb758d6499acef1335bb0adc114d5be5c103c", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue690.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue690.agda", "max_line_length": 73, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue690.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 191, "size": 487 }
module Prelude.Empty where open import Prelude.Erased data ⊥ : Set where ⊥-elim : ∀ {a} {A : Set a} → ⊥ → A ⊥-elim () {-# INLINE ⊥-elim #-} private postulate erasedBottom : ⊥ {-# DISPLAY erasedBottom = [erased] #-} erase-⊥ : ⊥ → ⊥ erase-⊥ _ = erasedBottom infix 4 ¬_ ¬_ : ∀ {a} (A : Set a) → Set a ¬ A = A → ⊥ eraseNegation : ∀ {a} {A : Set a} → ¬ A → ¬ A eraseNegation !a a = erase-⊥ (!a a) data ⊥′ {a} : Set a where ⊥′-elim : ∀ {a b} {A : Set a} → ⊥′ {b} → A ⊥′-elim () {-# INLINE ⊥′-elim #-}
{ "alphanum_fraction": 0.5197628458, "avg_line_length": 16.3225806452, "ext": "agda", "hexsha": "c94bbf248fe92ca21172544162257ddb5ba6e11f", "lang": "Agda", "max_forks_count": 24, "max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z", "max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z", "max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "t-more/agda-prelude", "max_forks_repo_path": "src/Prelude/Empty.agda", "max_issues_count": 59, "max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z", "max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "t-more/agda-prelude", "max_issues_repo_path": "src/Prelude/Empty.agda", "max_line_length": 45, "max_stars_count": 111, "max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "t-more/agda-prelude", "max_stars_repo_path": "src/Prelude/Empty.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z", "num_tokens": 219, "size": 506 }
------------------------------------------------------------------------ -- Dependent lenses ------------------------------------------------------------------------ -- Some code below depends on UIP for Set ℓ (for some ℓ). This kind of -- assumption is inconsistent in Cubical Agda. However, Andrea Vezzosi -- and I have discussed whether UIP, the propositional truncation, and -- extensionality are mutually consistent, and it seems plausible that -- some form of extensional type theory with squash types would -- provide a model for these things. -- -- Note that the code that depends on UIP does not make use of -- univalence, or at least it did not use to do this, library code may -- have changed after the code was written. This development tracks -- usage of univalence in types, but at the time of writing there is -- some library code that does not do this. {-# OPTIONS --cubical --safe #-} module Lens.Dependent where open import Equality.Propositional.Cubical open import Logical-equivalence using (module _⇔_) open import Prelude as P hiding (id; swap; Unit) renaming (_∘_ to _⊚_) open import Bijection equality-with-J as Bij using (_↔_; module _↔_) open import Bool equality-with-J open import Equality.Decidable-UIP equality-with-J using (Constant) open import Equality.Decision-procedures equality-with-J import Equality.Groupoid equality-with-J as EG open import Equality.Tactic equality-with-J as Tactic hiding (module Eq) open import Equivalence equality-with-J as Eq using (_≃_; module _≃_) open import Function-universe equality-with-J as F hiding (id; _∘_) open import Groupoid equality-with-J open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional equality-with-paths as Trunc open import Surjection equality-with-J using (module _↠_) open import Univalence-axiom equality-with-J import Lens.Non-dependent.Higher equality-with-paths as ND private variable a b b₁ b₂ b₃ c r r₁ r₂ r₃ : Level A : Set a ------------------------------------------------------------------------ -- Dependent lenses with "remainder types" visible in the type -- If Lens₃ A R B is inhabited, then a value of type A can be split up -- into a "remainder" r of type R and a value of type B r. Lens₃ : Set a → (R : Set r) → (R → Set b) → Set _ Lens₃ A R B = A ≃ Σ R B module Lens₃ {R : Set r} {B : R → Set b} (lens : Lens₃ A R B) where open _≃_ -- The remainder. remainder : A → R remainder a = proj₁ (to lens a) -- Getter. get : (a : A) → B (remainder a) get a = proj₂ (to lens a) -- Setter. set : (a : A) → B (remainder a) → A set a b = from lens (remainder a , b) -- Modifier. modify : (a : A) → (B (remainder a) → B (remainder a)) → A modify a f = set a (f (get a)) -- Setting leaves the remainder unchanged. remainder-set : ∀ a b → remainder (set a b) ≡ remainder a remainder-set a b = proj₁ (to lens (from lens (remainder a , b))) ≡⟨ cong proj₁ (right-inverse-of lens _) ⟩∎ remainder a ∎ -- A related isomorphism. codomain-set-≃ : ∀ {a b} → B (remainder (set a b)) ≃ B (remainder a) codomain-set-≃ = ≡⇒≃ (cong B (remainder-set _ _)) -- Some lens laws. set-get : ∀ a → set a (get a) ≡ a set-get a = from lens (proj₁ (to lens a) , proj₂ (to lens a)) ≡⟨⟩ from lens (to lens a) ≡⟨ left-inverse-of lens _ ⟩∎ a ∎ get-set₁ : ∀ a b → get (set a b) ≡ subst B (sym (remainder-set a b)) b get-set₁ a b = proj₂ (to lens (from lens (remainder a , b))) ≡⟨ sym $ dcong proj₂ (sym lemma) ⟩ subst (B ⊚ proj₁) (sym lemma) (proj₂ {B = B} (remainder a , b)) ≡⟨⟩ subst (B ⊚ proj₁) (sym lemma) b ≡⟨ subst-∘ _ _ (sym lemma) ⟩ subst B (cong proj₁ (sym lemma)) b ≡⟨ cong (λ x → subst B x b) (cong-sym _ lemma) ⟩∎ subst B (sym (cong proj₁ lemma)) b ∎ where lemma = right-inverse-of lens _ get-set₂ : ∀ a b → get (set a b) ≡ from codomain-set-≃ b get-set₂ a b = proj₂ (to lens (from lens (remainder a , b))) ≡⟨ get-set₁ _ _ ⟩ subst B (sym (cong proj₁ lemma)) b ≡⟨ subst-in-terms-of-inverse∘≡⇒↝ equivalence (cong proj₁ lemma) _ _ ⟩∎ ≡⇒← (cong B (cong proj₁ lemma)) b ∎ where lemma = right-inverse-of lens _ set-set₁ : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a (subst B (remainder-set a b₁) b₂) set-set₁ a b₁ b₂ = from lens (remainder (set a b₁) , b₂) ≡⟨ cong (from lens) (Σ-≡,≡→≡ eq refl) ⟩∎ from lens (remainder a , subst B eq b₂) ∎ where eq = remainder-set a b₁ set-set₂ : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a (to codomain-set-≃ b₂) set-set₂ a b₁ b₂ = set (set a b₁) b₂ ≡⟨ set-set₁ _ _ _ ⟩ set a (subst B eq b₂) ≡⟨ cong (set a) (subst-in-terms-of-≡⇒↝ equivalence eq _ _) ⟩∎ set a (≡⇒→ (cong B eq) b₂) ∎ where eq = remainder-set a b₁ ------------------------------------------------------------------------ -- Lens₃ combinators -- Identity lens. id₃ : Lens₃ A ⊤ (λ _ → A) id₃ {A = A} = A ↔⟨ inverse ×-left-identity ⟩□ ⊤ × A □ -- Composition of lenses. infixr 9 _₃∘₃_ _₃∘₃_ : {R₁ : Set r₁} {B₁ : R₁ → Set b₁} {R₂ : R₁ → Set r₂} {B₂ : (r : R₁) → R₂ r → Set b₂} → (∀ {r} → Lens₃ (B₁ r) (R₂ r) (B₂ r)) → Lens₃ A R₁ B₁ → Lens₃ A (Σ R₁ R₂) (uncurry B₂) _₃∘₃_ {A = A} {R₁ = R₁} {B₁ = B₁} {R₂ = R₂} {B₂ = B₂} l₁ l₂ = A ↔⟨ l₂ ⟩ Σ R₁ B₁ ↔⟨ ∃-cong (λ _ → l₁) ⟩ Σ R₁ (λ r → Σ (R₂ r) (B₂ r)) ↔⟨ Σ-assoc ⟩□ Σ (Σ R₁ R₂) (uncurry B₂) □ ------------------------------------------------------------------------ -- Some Lens₃ properties -- id₃ and _₃∘₃_ form a kind of precategory. left-identity₃ : {R : Set r} {B : R → Set b} → (l : Lens₃ A R B) → id₃ ₃∘₃ l ≡ (A ↝⟨ l ⟩ Σ R B ↝⟨ Σ-cong (inverse ×-right-identity) (λ _ → F.id) ⟩□ Σ (R × ⊤) (B ⊚ proj₁) □) left-identity₃ _ = Eq.lift-equality ext refl right-identity₃ : {R : Set r} {B : R → Set b} → (l : Lens₃ A R B) → l ₃∘₃ id₃ ≡ (A ↝⟨ l ⟩ Σ R B ↝⟨ Σ-cong (inverse ×-left-identity) (λ _ → F.id) ⟩□ Σ (⊤ × R) (B ⊚ proj₂) □) right-identity₃ _ = Eq.lift-equality ext refl associativity₃ : {R₁ : Set r₁} {B₁ : R₁ → Set b₁} {R₂ : R₁ → Set r₂} {B₂ : (r₁ : R₁) → R₂ r₁ → Set b₂} {R₃ : (r₁ : R₁) → R₂ r₁ → Set r₃} {B₃ : (r₁ : R₁) (r₂ : R₂ r₁) → R₃ r₁ r₂ → Set b₃} → (l₁ : ∀ {r₁ r₂} → Lens₃ (B₂ r₁ r₂) (R₃ r₁ r₂) (B₃ r₁ r₂)) (l₂ : ∀ {r} → Lens₃ (B₁ r) (R₂ r) (B₂ r)) (l₃ : Lens₃ A R₁ B₁) → l₁ ₃∘₃ (l₂ ₃∘₃ l₃) ≡ (A ↝⟨ (l₁ ₃∘₃ l₂) ₃∘₃ l₃ ⟩ Σ (Σ R₁ (λ r₁ → Σ (R₂ r₁) (R₃ r₁))) (uncurry (uncurry ⊚ B₃)) ↝⟨ Σ-cong Σ-assoc (λ _ → F.id) ⟩□ Σ (Σ (Σ R₁ R₂) (uncurry R₃)) (uncurry (uncurry B₃)) □) associativity₃ _ _ _ = Eq.lift-equality ext refl ------------------------------------------------------------------------ -- Dependent lenses without "remainder types" visible in the type -- One definition. Lens : (A : Set a) → (A → Set b) → Set (lsuc (a ⊔ b)) Lens {a = a} {b = b} A B = ∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (lens : Lens₃ A R B′) → ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (Lens₃.remainder lens a) ≡ B a) -- An alternative definition. This definition is pointwise isomorphic -- to the previous one, see Lens↔Lens′ below. Lens′ : (A : Set a) → (A → Set b) → Set (lsuc (a ⊔ b)) Lens′ {a = a} {b = b} A B = ∃ λ (get : (a : A) → B a) → ∃ λ (R : Set (a ⊔ b)) → ∃ λ (remainder : A → R) → Surjective remainder × ∃ λ (B′ : R → Set b) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a)) module Lens {A : Set a} {B : A → Set b} (l : Lens A B) where -- The remainder type: what remains of A when B is removed -- (roughly). R : Set (a ⊔ b) R = proj₁ l -- A variant of B, indexed by Rs instead of As. B′ : R → Set b B′ = proj₁ (proj₂ l) -- The main lens isomorphism. lens : Lens₃ A R B′ lens = proj₁ (proj₂ (proj₂ l)) -- If the remainder type is inhabited, then the corresponding view -- should also be (merely) inhabited. inhabited : (r : R) → ∥ B′ r ∥ inhabited = proj₁ (proj₂ (proj₂ (proj₂ l))) private module L = Lens₃ lens open _≃_ -- The "non-B" part of the A value. remainder : A → R remainder = L.remainder -- An equality that specifies in what sense B′ is a variant of B. -- -- (This used to be a bijection, but it was turned into an -- equality in order to make it obvious that, if the K rule is -- enabled, then variant cannot do anything strange.) variant : ∀ a → B′ (remainder a) ≡ B a variant = proj₂ (proj₂ (proj₂ (proj₂ l))) -- A corresponding isomorphism. variant≃ : ∀ {a} → B′ (remainder a) ≃ B a variant≃ = ≡⇒≃ (variant _) -- A variant of variant. other-variant : ∀ r (b′ : B′ r) → B′ r ≡ B (from lens (r , b′)) other-variant r b′ = B′ r ≡⟨⟩ B′ (proj₁ {B = B′} (r , b′)) ≡⟨ cong (B′ ⊚ proj₁) (sym $ right-inverse-of lens (r , b′)) ⟩ B′ (proj₁ (to lens (from lens (r , b′)))) ≡⟨⟩ B′ (remainder (from lens (r , b′))) ≡⟨ variant (_≃_.from lens (r , b′)) ⟩∎ B (from lens (r , b′)) ∎ -- Note that B ⊚ _≃_.from lens only depends on the "R part" of the -- argument. independent-of-B′ : (r : R) → Constant (B ⊚ _≃_.from lens ⊚ (r ,_)) independent-of-B′ r b₁ b₂ = B (_≃_.from lens (r , b₁)) ≡⟨ sym $ other-variant _ _ ⟩ B′ r ≡⟨ other-variant _ _ ⟩∎ B (_≃_.from lens (r , b₂)) ∎ -- Thus we can, assuming that Set b is a set, define a variant of B -- that only depends on R. module First-variant-of-B (uip : Is-set (Set b)) where private B̲′ : (r : R) → ∥ B′ r ∥ → Set b B̲′ r = to (constant-function≃∥inhabited∥⇒inhabited uip) (B ⊚ _≃_.from lens ⊚ (r ,_) , independent-of-B′ r) B̲ : R → Set b B̲ r = B̲′ r (inhabited r) -- This type family is pointwise equal to B′ (given the same -- assumptions). B′≡B̲ : ∀ r → B′ r ≡ B̲ r B′≡B̲ r = Trunc.elim (λ ∥b′∥ → B′ r ≡ B̲′ r ∥b′∥) (λ _ → uip) (other-variant r) (inhabited r) -- We can also use other assumptions: -- -- * Univalence. -- * B should be a family of sets. module Second-variant-of-B (univ : Univalence b) (B-set : ∀ a → Is-set (B a)) where private abstract B̲-triple : (r : R) → ∃ λ (X : SET b) → B′ r ≡ proj₁ X B̲-triple r = to (coherently-constant-function≃∥inhabited∥⇒inhabited (Σ-closure 3 (∃-H-level-H-level-1+ ext univ 2) (λ { (_ , X-set) → mono₁ 2 $ H-level-H-level-≡ʳ ext univ 1 X-set }))) ( (λ b′ → (B (_≃_.from lens (r , b′)) , B-set _) , other-variant r b′) , (λ b′₁ b′₂ → Σ-≡,≡→≡ (Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) (Is-set-is-propositional _ _)) (subst (λ X → B′ r ≡ proj₁ X) (Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _) (other-variant r b′₁) ≡⟨ subst-∘ (B′ r ≡_) proj₁ (Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _) ⟩ subst (B′ r ≡_) (cong proj₁ $ Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _) (other-variant r b′₁) ≡⟨⟩ trans (other-variant r b′₁) (cong proj₁ $ Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _) ≡⟨ cong (trans (other-variant r b′₁)) $ proj₁-Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _ ⟩ trans (other-variant r b′₁) (independent-of-B′ r b′₁ b′₂) ≡⟨⟩ trans (other-variant r b′₁) (trans (sym $ other-variant r b′₁) (other-variant r b′₂)) ≡⟨ sym $ trans-assoc _ _ (other-variant r b′₂) ⟩ trans (trans (other-variant r b′₁) (sym $ other-variant r b′₁)) (other-variant r b′₂) ≡⟨ cong (flip trans (other-variant r b′₂)) $ trans-symʳ (other-variant r b′₁) ⟩ trans refl (other-variant r b′₂) ≡⟨ trans-reflˡ _ ⟩∎ other-variant r b′₂ ∎)) , (λ b′₁ b′₂ b′₃ → let lemma = trans (independent-of-B′ r b′₁ b′₂) (independent-of-B′ r b′₂ b′₃) ≡⟨⟩ trans (trans (sym $ other-variant r b′₁) (other-variant r b′₂)) (trans (sym $ other-variant r b′₂) (other-variant r b′₃)) ≡⟨ sym $ trans-assoc (independent-of-B′ r b′₁ b′₂) (sym $ other-variant r b′₂) (other-variant r b′₃) ⟩ trans (trans (trans (sym $ other-variant r b′₁) (other-variant r b′₂)) (sym $ other-variant r b′₂)) (other-variant r b′₃) ≡⟨ cong (flip trans (other-variant r b′₃)) $ trans-[trans]-sym (sym $ other-variant r b′₁) (other-variant r b′₂) ⟩ trans (sym $ other-variant r b′₁) (other-variant r b′₃) ≡⟨ refl ⟩∎ independent-of-B′ r b′₁ b′₃ ∎ in trans (Σ-≡,≡→≡ (Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _) _) (Σ-≡,≡→≡ (Σ-≡,≡→≡ (independent-of-B′ r b′₂ b′₃) _) _) ≡⟨ trans-Σ-≡,≡→≡ (Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _) (Σ-≡,≡→≡ (independent-of-B′ r b′₂ b′₃) _) _ _ ⟩ Σ-≡,≡→≡ (trans (Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) _) (Σ-≡,≡→≡ (independent-of-B′ r b′₂ b′₃) _)) _ ≡⟨ Σ-≡,≡→≡-cong (trans-Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₂) (independent-of-B′ r b′₂ b′₃) _ _) refl ⟩ Σ-≡,≡→≡ (Σ-≡,≡→≡ (trans (independent-of-B′ r b′₁ b′₂) (independent-of-B′ r b′₂ b′₃)) _) _ ≡⟨ Σ-≡,≡→≡-cong (Σ-≡,≡→≡-cong lemma (mono₁ 0 (+⇒≡ Is-set-is-propositional) _ _)) (H-level-H-level-≡ʳ ext univ 1 (B-set _) _ _) ⟩∎ Σ-≡,≡→≡ (Σ-≡,≡→≡ (independent-of-B′ r b′₁ b′₃) _) _ ∎)) (inhabited r) where Is-set-is-propositional : {B : Set b} → Is-proposition (Is-set B) Is-set-is-propositional = H-level-propositional ext 2 B̲ : R → Set b B̲ r = proj₁ (proj₁ (B̲-triple r)) B̲-set : ∀ r → Is-set (B̲ r) B̲-set r = proj₂ (proj₁ (B̲-triple r)) B′≡B̲ : ∀ r → B′ r ≡ B̲ r B′≡B̲ r = proj₂ (B̲-triple r) -- Getter. get : (a : A) → B a get a = to variant≃ (L.get a) -- Setter. set : (a : A) → B a → A set a b = L.set a (from variant≃ b) -- Modifier. modify : (a : A) → (B a → B a) → A modify a f = set a (f (get a)) -- Setting leaves the remainder unchanged. remainder-set : ∀ a b → remainder (set a b) ≡ remainder a remainder-set a b = L.remainder-set a (from variant≃ b) -- Hence the type of the gettable part stays unchanged after a set. codomain-set : ∀ {a b} → B (set a b) ≡ B a codomain-set {a} {b} = B (set a b) ≡⟨ sym (variant _) ⟩ B′ (remainder (set a b)) ≡⟨ cong B′ (remainder-set a b) ⟩ B′ (remainder a) ≡⟨ variant _ ⟩∎ B a ∎ -- A corresponding isomorphism. codomain-set-≃ : ∀ {a b} → B (set a b) ≃ B a codomain-set-≃ = ≡⇒≃ codomain-set -- Unfolding lemmas for codomain-set-≃. to-codomain-set-≃ : ∀ {a b} → to (codomain-set-≃ {a = a} {b = b}) ≡ to variant≃ ⊚ to L.codomain-set-≃ ⊚ from variant≃ to-codomain-set-≃ = ≡⇒→ (trans (sym (variant _)) (trans eq (variant _))) ≡⟨ ≡⇒↝-trans equivalence {B≡C = trans eq (variant _)} ⟩ ≡⇒→ (trans eq (variant _)) ⊚ ≡⇒→ (sym (variant _)) ≡⟨ cong (≡⇒→ (trans eq (variant _)) ⊚_) (≡⇒↝-sym equivalence {eq = variant _}) ⟩ ≡⇒→ (trans eq (variant _)) ⊚ from variant≃ ≡⟨ cong (_⊚ from variant≃) (≡⇒↝-trans equivalence {B≡C = variant _}) ⟩∎ to variant≃ ⊚ ≡⇒→ eq ⊚ from variant≃ ∎ where eq = cong B′ (remainder-set _ _) from-codomain-set-≃ : ∀ {a b} → from (codomain-set-≃ {a = a} {b = b}) ≡ to variant≃ ⊚ from L.codomain-set-≃ ⊚ from variant≃ from-codomain-set-≃ = ≡⇒← (trans (sym (variant _)) (trans eq (variant _))) ≡⟨ sym $ ≡⇒↝-sym equivalence {eq = trans (sym (variant _)) (trans eq (variant _))} ⟩ ≡⇒→ (sym (trans (sym (variant _)) (trans eq (variant _)))) ≡⟨ cong ≡⇒→ (Tactic.prove (Sym (Trans (Sym (Lift (variant _))) (Trans (Lift eq) (Lift (variant _))))) (Trans (Trans (Sym (Lift (variant _))) (Sym (Lift eq))) (Lift (variant _))) refl) ⟩ ≡⇒→ (trans (trans (sym (variant _)) (sym eq)) (variant _)) ≡⟨ ≡⇒↝-trans equivalence {B≡C = variant _} ⟩ to variant≃ ⊚ ≡⇒→ (trans (sym (variant _)) (sym eq)) ≡⟨ cong (to variant≃ ⊚_) (≡⇒↝-trans equivalence {B≡C = sym eq}) ⟩ to variant≃ ⊚ ≡⇒→ (sym eq) ⊚ ≡⇒→ (sym (variant _)) ≡⟨ cong₂ (λ f g → to variant≃ ⊚ f ⊚ g) (≡⇒↝-sym equivalence {eq = eq}) (≡⇒↝-sym equivalence {eq = variant _}) ⟩∎ to variant≃ ⊚ ≡⇒← eq ⊚ from variant≃ ∎ where eq = cong B′ (remainder-set _ _) -- Some lens laws. set-get : ∀ a → set a (get a) ≡ a set-get a = L.set a (from variant≃ (to variant≃ (L.get a))) ≡⟨ cong (L.set a) (left-inverse-of variant≃ _) ⟩ L.set a (L.get a) ≡⟨ L.set-get a ⟩∎ a ∎ get-set : ∀ a b → get (set a b) ≡ from codomain-set-≃ b get-set a b = to variant≃ (L.get (L.set a (from variant≃ b))) ≡⟨ cong (to variant≃) $ L.get-set₂ _ _ ⟩ to variant≃ (≡⇒← eq (from variant≃ b)) ≡⟨ cong (_$ b) (sym from-codomain-set-≃) ⟩∎ from codomain-set-≃ b ∎ where eq = cong B′ (remainder-set a b) set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a (to codomain-set-≃ b₂) set-set a b₁ b₂ = L.set (L.set a (from variant≃ b₁)) (from variant≃ b₂) ≡⟨ L.set-set₂ a (from variant≃ b₁) (from variant≃ b₂) ⟩ L.set a (to L.codomain-set-≃ (from variant≃ b₂)) ≡⟨ cong (L.set a) lemma ⟩∎ L.set a (from variant≃ (to codomain-set-≃ b₂)) ∎ where lemma = to L.codomain-set-≃ (from variant≃ b₂) ≡⟨ sym $ left-inverse-of variant≃ _ ⟩ from variant≃ (to variant≃ (to L.codomain-set-≃ (from variant≃ b₂))) ≡⟨ cong (from variant≃ ⊚ (_$ b₂)) $ sym to-codomain-set-≃ ⟩∎ from variant≃ (to codomain-set-≃ b₂) ∎ -- For a non-dependent dependent lens, for which UIP holds for the -- codomain's universe, codomain-set-≃ is equal to the identity. codomain-set-≃≡id : {B : Set b} → Is-set (Set b) → (l : Lens A (λ _ → B)) → ∀ {a b} → Lens.codomain-set-≃ l {a = a} {b = b} ≡ Eq.id codomain-set-≃≡id uip l = codomain-set-≃ ≡⟨⟩ ≡⇒≃ codomain-set ≡⟨ cong ≡⇒≃ (uip codomain-set refl) ⟩ ≡⇒≃ refl ≡⟨ refl ⟩∎ Eq.id ∎ where open Lens l ------------------------------------------------------------------------ -- Some lens isomorphisms -- Lens preserves level-preserving equivalences (assuming univalence). Lens-cong : {A₁ A₂ : Set a} {B₁ : A₁ → Set b} {B₂ : A₂ → Set b} → Univalence b → (A₁≃A₂ : A₁ ≃ A₂) → (∀ a → B₁ a ≃ B₂ (_≃_.to A₁≃A₂ a)) → Lens A₁ B₁ ≃ Lens A₂ B₂ Lens-cong {A₁ = A₁} {A₂} {B₁} {B₂} univ A₁≃A₂ B₁≃B₂ = (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : Lens₃ A₁ R B′) → ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (remainder lens a) ≡ B₁ a)) ↝⟨ (∃-cong λ R → ∃-cong λ B′ → Σ-cong (Eq.≃-preserves ext A₁≃A₂ F.id) λ lens → ∃-cong λ _ → Π-cong ext A₁≃A₂ λ a → ≡-preserves-≃ ext univ univ (≡⇒≃ ( B′ (proj₁ (to lens a)) ≡⟨ cong (λ a → B′ (proj₁ (to lens a))) $ sym $ left-inverse-of A₁≃A₂ _ ⟩∎ B′ (proj₁ (to lens (from A₁≃A₂ (to A₁≃A₂ a)))) ∎)) (B₁≃B₂ a)) ⟩□ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : Lens₃ A₂ R B′) → ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (remainder lens a) ≡ B₂ a)) □ where open Lens₃ open _≃_ -- If B x is a proposition for all x, then Lens A B is isomorphic to -- (x : A) → B x (assuming univalence). lens-to-proposition↔get : {A : Set a} {B : A → Set b} → Univalence (a ⊔ b) → Univalence b → (∀ x → Is-proposition (B x)) → Lens A B ↔ ((x : A) → B x) lens-to-proposition↔get {b = b} {A = A} {B = B} univ₁ univ₂ B-prop = (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ Σ R B′) → ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (Lens₃.remainder lens a) ≡ B a)) ↝⟨ (∃-cong λ _ → ∃-cong λ B′ → ∃-cong λ l → ∃-cong λ _ → Π-cong ext l λ _ → ≡⇒↝ _ $ cong (λ x → B′ _ ≡ B x) $ sym $ _≃_.left-inverse-of l _) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ Σ R B′) → ((r : R) → ∥ B′ r ∥) × (∀ p → B′ (proj₁ p) ≡ B (_≃_.from lens p))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → currying) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ Σ R B′) → ((r : R) → ∥ B′ r ∥) × ((r : R) (b : B′ r) → B′ r ≡ B (_≃_.from lens (r , b)))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → inverse ΠΣ-comm) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ Σ R B′) → ((r : R) → ∥ B′ r ∥ × ((b : B′ r) → B′ r ≡ B (_≃_.from lens (r , b))))) ↔⟨ (∃-cong λ _ → ∃-cong λ B′ → ∃-cong λ lens → ∀-cong ext $ lemma₁ B′ lens) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ Σ R B′) → ((r : R) → ∃ λ (⊤≃B′ : ⊤ ≃ B′ r) → B (_≃_.from lens (r , _≃_.to ⊤≃B′ _)))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ΠΣ-comm) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ Σ R B′) → ∃ λ (⊤≃B′ : ∀ r → ⊤ ≃ B′ r) → ∀ r → B (_≃_.from lens (r , _≃_.to (⊤≃B′ r) _))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (⊤≃B′ : ∀ r → ⊤ ≃ B′ r) → ∃ λ (lens : A ≃ Σ R B′) → ∀ r → B (_≃_.from lens (r , _≃_.to (⊤≃B′ r) _))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ ⊤≃B′ → Σ-cong (Eq.≃-preserves ext F.id (drop-⊤-right (λ r → inverse (⊤≃B′ r)))) λ _ → F.id) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → (∀ r → ⊤ ≃ B′ r) × ∃ λ (lens : A ≃ R) → ∀ r → B (_≃_.from lens r)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set _) → ∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ R) → (∀ r → ⊤ ≃ B′ r) × ∀ r → B (_≃_.from lens r)) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set _) → ∃ λ (lens : A ≃ R) → ∃ λ (B′ : R → Set _) → (∀ r → ⊤ ≃ B′ r) × ∀ r → B (_≃_.from lens r)) ↝⟨ Σ-assoc ⟩ (Σ (∃ λ (R : Set _) → A ≃ R) λ { (R , lens) → ∃ λ (B′ : R → Set _) → (∀ r → ⊤ ≃ B′ r) × ∀ r → B (_≃_.from lens r) }) ↝⟨ drop-⊤-left-Σ (other-singleton-with-≃-↔-⊤ {b = b} ext univ₁) ⟩ (∃ λ (B′ : ↑ _ A → Set _) → (∀ a → ⊤ ≃ B′ a) × (∀ a → B (lower a))) ↝⟨ Σ-assoc ⟩ (∃ λ (B′ : ↑ _ A → Set _) → ∀ a → ⊤ ≃ B′ a) × (∀ a → B (lower a)) ↔⟨ ((∃-cong λ _ → ∀-cong ext λ _ → Eq.≃-preserves ext (inverse $ Eq.↔⇒≃ Bij.↑↔) F.id) ×-cong Π-cong ext (Eq.↔⇒≃ Bij.↑↔) (λ _ → F.id)) ⟩ (∃ λ (B′ : ↑ _ A → Set _) → ∀ a → ↑ _ ⊤ ≃ B′ a) × (∀ a → B a) ↔⟨ (∃-cong λ B′ → ∀-cong ext λ _ → inverse $ ≡≃≃ univ₂) ×-cong F.id ⟩ (∃ λ (B′ : ↑ _ A → Set _) → ∀ a → ↑ _ ⊤ ≡ B′ a) × (∀ a → B a) ↔⟨ (∃-cong λ _ → Eq.extensionality-isomorphism ext) ×-cong F.id ⟩ (∃ λ (B′ : ↑ _ A → Set _) → const (↑ _ ⊤) ≡ B′) × (∀ a → B a) ↝⟨ drop-⊤-left-× (λ _ → _⇔_.to contractible⇔↔⊤ (other-singleton-contractible _)) ⟩□ (∀ a → B a) □ where lemma₂ : {R : Set _} (B′ : R → Set _) (r : R) → _ lemma₂ B′ r = (∥ B′ r ∥ × Is-proposition (B′ r)) ↝⟨ ×-comm ⟩ (Is-proposition (B′ r) × ∥ B′ r ∥) ↝⟨ (∃-cong λ B′-prop → ∥∥↔ B′-prop) ⟩ (Is-proposition (B′ r) × B′ r) ↔⟨ _↠_.from (Eq.≃↠⇔ (Σ-closure 1 (H-level-propositional ext 1) λ B′-prop → B′-prop) (H-level-propositional ext 0)) (record { to = uncurry propositional⇒inhabited⇒contractible ; from = λ B′-contr → mono₁ 0 B′-contr , proj₁ B′-contr }) ⟩ Contractible (B′ r) ↝⟨ contractible↔≃⊤ ext ⟩ B′ r ≃ ⊤ ↝⟨ Eq.inverse-isomorphism ext ⟩□ ⊤ ≃ B′ r □ lemma₁ : {R : Set _} (B′ : R → Set _) (lens : A ≃ Σ R B′) (r : R) → _ lemma₁ B′ lens r = ∥ B′ r ∥ × ((b′ : B′ r) → B′ r ≡ B (_≃_.from lens (r , b′))) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → ≡≃≃ univ₂) ⟩ ∥ B′ r ∥ × ((b′ : B′ r) → B′ r ≃ B (_≃_.from lens (r , b′))) ↝⟨ (∃-cong λ _ → ∀-cong ext λ b′ → _↠_.from (Eq.≃↠⇔ (Eq.right-closure ext 0 (B-prop _)) (×-closure 1 (H-level-propositional ext 1) (B-prop _))) (record { to = λ eq → H-level.respects-surjection (_≃_.surjection (inverse eq)) 1 (B-prop _) , _≃_.to eq b′ ; from = λ { (B′-prop , b) → _↠_.from (Eq.≃↠⇔ B′-prop (B-prop _)) (record { to = const b ; from = const b′ }) } })) ⟩ ∥ B′ r ∥ × ((b′ : B′ r) → Is-proposition (B′ r) × B (_≃_.from lens (r , b′))) ↔⟨ (∃-cong λ _ → ΠΣ-comm) ⟩ ∥ B′ r ∥ × (B′ r → Is-proposition (B′ r)) × ((b′ : B′ r) → B (_≃_.from lens (r , b′))) ↝⟨ (∃-cong λ _ → _↠_.from (Eq.≃↠⇔ (Π-closure ext 1 λ _ → H-level-propositional ext 1) (H-level-propositional ext 1)) (record { to = λ B′-prop → [inhabited⇒+]⇒+ 0 B′-prop ; from = λ B′-prop _ → B′-prop }) ×-cong F.id) ⟩ ∥ B′ r ∥ × Is-proposition (B′ r) × ((b′ : B′ r) → B (_≃_.from lens (r , b′))) ↔⟨ ×-assoc ⟩ (∥ B′ r ∥ × Is-proposition (B′ r)) × ((b′ : B′ r) → B (_≃_.from lens (r , b′))) ↔⟨ lemma₂ B′ r ×-cong F.id ⟩ (⊤ ≃ B′ r) × ((b′ : B′ r) → B (_≃_.from lens (r , b′))) ↝⟨ (∃-cong λ ⊤≃B′ → drop-⊤-left-Π ext (_≃_.bijection $ inverse ⊤≃B′)) ⟩□ (∃ λ (⊤≃B′ : ⊤ ≃ B′ r) → B (_≃_.from lens (r , _≃_.to ⊤≃B′ _))) □ -- If B x is contractible for all x, then Lens A B is isomorphic to ⊤ -- (assuming univalence). lens-to-contractible↔⊤ : {A : Set a} {B : A → Set b} → Univalence (a ⊔ b) → Univalence b → (∀ x → Contractible (B x)) → Lens A B ↔ ⊤ lens-to-contractible↔⊤ {A = A} {B} univ₁ univ₂ cB = Lens A B ↝⟨ lens-to-proposition↔get univ₁ univ₂ (mono₁ 0 ⊚ cB) ⟩ ((x : A) → B x) ↝⟨ (∀-cong ext λ _ → _⇔_.to contractible⇔↔⊤ (cB _)) ⟩ (A → ⊤) ↝⟨ →-right-zero ⟩□ ⊤ □ -- Lens A (const ⊥) is isomorphic to ¬ A (assuming univalence). lens-to-⊥↔¬ : {A : Set a} → Univalence (a ⊔ b) → Univalence b → Lens A (const (⊥ {ℓ = b})) ↔ ¬ A lens-to-⊥↔¬ {A = A} univ₁ univ₂ = Lens A (const ⊥) ↝⟨ lens-to-proposition↔get univ₁ univ₂ (λ _ → ⊥-propositional) ⟩ (A → ⊥) ↝⟨ inverse $ ¬↔→⊥ ext ⟩□ ¬ A □ ------------------------------------------------------------------------ -- Results relating different kinds of lenses -- If we assume that equality with the codomain type is propositional, -- then non-dependent dependent lenses are isomorphic to non-dependent -- lenses. -- -- TODO: Can this be proved without assuming that equality with the -- codomain type is propositional? If not, can the definition of Lens -- be changed so that it can be proved? non-dependent-lenses-isomorphic : {B : Set b} → (∀ {B′} → Is-proposition (B′ ≡ B)) → ∃ λ (iso : Lens A (const B) ↔ ND.Lens A B) → ∀ {l a} → Lens.get l a ≡ ND.Lens.get (_↔_.to iso l) a non-dependent-lenses-isomorphic {A = A} {B = B} ≡B-prop = (Lens A (const B) ↝⟨ inverse ND.Lens-as-Σ F.∘ ∃-cong lemma ⟩□ ND.Lens A B □) , λ {l a} → let p = variant l a q = Trunc.rec ≡B-prop (λ b → subst (λ { (r , _) → B′ l r ≡ B }) (_≃_.right-inverse-of (lens l) (remainder l a , b)) (variant l (Lens₃.set (lens l) a b))) (inhabited l (remainder l a)) in ≡⇒→ p (proj₂ (_≃_.to (lens l) a)) ≡⟨ cong (λ eq → ≡⇒→ eq (proj₂ (_≃_.to (lens l) a))) (≡B-prop p q) ⟩∎ ≡⇒→ q (proj₂ (_≃_.to (lens l) a)) ∎ where open Lens lemma = λ R → (∃ λ (B′ : R → Set _) → ∃ λ (lens : A ≃ Σ R B′) → ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (Lens₃.remainder lens a) ≡ B)) ↝⟨ (∃-cong λ _ → ∃-cong λ l → ∃-cong λ _ → Π-cong ext l (λ _ → F.id)) ⟩ (∃ λ (B′ : R → Set _) → (A ≃ Σ R B′) × ((r : R) → ∥ B′ r ∥) × (∀ p → B′ (proj₁ p) ≡ B)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → currying) ⟩ (∃ λ (B′ : R → Set _) → (A ≃ Σ R B′) × ((r : R) → ∥ B′ r ∥) × ((r : R) → B′ r → B′ r ≡ B)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ inh → ∀-cong ext λ r → _↠_.from (Eq.≃↠⇔ (Π-closure ext 1 λ _ → ≡B-prop) ≡B-prop) (record { from = λ B′r≡B → const B′r≡B ; to = λ B′r→B′r≡B → Trunc.rec ≡B-prop B′r→B′r≡B (inh r) })) ⟩ (∃ λ (B′ : R → Set _) → (A ≃ Σ R B′) × ((r : R) → ∥ B′ r ∥) × ((r : R) → B′ r ≡ B)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩ (∃ λ (B′ : R → Set _) → (A ≃ Σ R B′) × ((r : R) → B′ r ≡ B) × ((r : R) → ∥ B′ r ∥)) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩ (∃ λ (B′ : R → Set _) → ((r : R) → B′ r ≡ B) × (A ≃ Σ R B′) × ((r : R) → ∥ B′ r ∥)) ↔⟨ (∃-cong λ _ → Σ-cong (Eq.extensionality-isomorphism ext) λ B′≡B → Eq.≃-preserves ext F.id (∃-cong λ _ → ≡⇒↝ _ (B′≡B _)) ×-cong ∀-cong ext (λ _ → Eq.↔⇒≃ $ ∥∥-cong (≡⇒↝ _ (B′≡B _)))) ⟩ (∃ λ (B′ : R → Set _) → B′ ≡ const B × (A ≃ (R × B)) × (R → ∥ B ∥)) ↝⟨ Σ-assoc ⟩ ((∃ λ (B′ : R → Set _) → B′ ≡ const B) × (A ≃ (R × B)) × (R → ∥ B ∥)) ↝⟨ drop-⊤-left-× (λ _ → _⇔_.to contractible⇔↔⊤ (singleton-contractible _)) ⟩□ ((A ≃ (R × B)) × (R → ∥ B ∥)) □ -- The type of non-dependent dependent lenses from A to B is -- isomorphic to the type of non-dependent lenses from A to B if UIP -- holds for B. non-dependent-lenses-isomorphic-UIP : {B : Set b} → Is-set (Set b) → ∃ λ (iso : Lens A (const B) ↔ ND.Lens A B) → ∀ {l a} → Lens.get l a ≡ ND.Lens.get (_↔_.to iso l) a non-dependent-lenses-isomorphic-UIP uip = non-dependent-lenses-isomorphic uip -- Lens and Lens′ are pointwise isomorphic. Lens↔Lens′ : {A : Set a} {B : A → Set b} → Lens A B ↔ Lens′ A B Lens↔Lens′ {a = a} {b = b} {A = A} {B = B} = (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (lens : Lens₃ A R B′) → ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (Lens₃.remainder lens a) ≡ B a)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Σ-cong (Eq.≃-as-Σ) λ _ → F.id) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (lens : ∃ λ (rg : A → Σ R B′) → Eq.Is-equivalence rg) → ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (proj₁ (proj₁ lens a)) ≡ B a)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse Σ-assoc) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (rg : A → Σ R B′) → Eq.Is-equivalence rg × ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (proj₁ (rg a)) ≡ B a)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Σ-cong ΠΣ-comm λ _ → F.id) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (rg : ∃ λ (remainder : A → R) → (a : A) → B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → proj₁ rg a , proj₂ rg a) × ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (proj₁ rg a) ≡ B a)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse Σ-assoc) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (get′ : (a : A) → B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , get′ a) × ((r : R) → ∥ B′ r ∥) × (∀ a → B′ (remainder a) ≡ B a)) ↝⟨ (∃-cong λ R → ∃-cong λ B′ → ∃-cong λ rem → ∃-cong λ get′ → ∃-cong λ eq → ∀-cong ext (λ r → ∥∥-cong (lemma R B′ rem get′ eq r)) ×-cong F.id) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (get′ : (a : A) → B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , get′ a) × Surjective remainder × (∀ a → B′ (remainder a) ≡ B a)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (get′ : (a : A) → B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , get′ a) × (∀ a → B′ (remainder a) ≡ B a) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (get′ : (a : A) → B′ (remainder a)) → (∀ a → B′ (remainder a) ≡ B a) × Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , get′ a) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → (∀ a → B′ (remainder a) ≡ B a) × ∃ λ (get′ : (a : A) → B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , get′ a) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-cong₁ λ _ → ∀-cong ext λ _ → Groupoid.⁻¹-bijection (EG.groupoid _)) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → (∀ a → B a ≡ B′ (remainder a)) × ∃ λ (get′ : (a : A) → B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , get′ a) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-cong₁ λ _ → inverse Bij.implicit-Π↔Π) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → (∀ {a} → B a ≡ B′ (remainder a)) × ∃ λ (get′ : (a : A) → B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , get′ a) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ variant → inverse $ Σ-cong (∀-cong ext λ _ → Eq.subst-as-equivalence P.id (variant {_})) λ _ → F.id) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → ∃ λ (get : (a : A) → B a) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a)) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (get : (a : A) → B a) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a)) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (get : (a : A) → B a) → ∃ λ (remainder : A → R) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a)) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩ (∃ λ (R : Set (a ⊔ b)) → ∃ λ (get : (a : A) → B a) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a)) × Surjective remainder) ↝⟨ ∃-comm ⟩ (∃ λ (get : (a : A) → B a) → ∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a)) × Surjective remainder) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩ (∃ λ (get : (a : A) → B a) → ∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Surjective remainder × Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (get : (a : A) → B a) → ∃ λ (R : Set (a ⊔ b)) → ∃ λ (B′ : R → Set b) → ∃ λ (remainder : A → R) → Surjective remainder × ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (get : (a : A) → B a) → ∃ λ (R : Set (a ⊔ b)) → ∃ λ (remainder : A → R) → ∃ λ (B′ : R → Set b) → Surjective remainder × ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩□ (∃ λ (get : (a : A) → B a) → ∃ λ (R : Set (a ⊔ b)) → ∃ λ (remainder : A → R) → Surjective remainder × ∃ λ (B′ : R → Set b) → ∃ λ (variant : ∀ {a} → B a ≡ B′ (remainder a)) → Eq.Is-equivalence {B = ∃ B′} (λ a → remainder a , subst P.id variant (get a))) □ where lemma : ∀ _ _ _ _ _ _ → _ lemma = λ _ B′ remainder _ eq r → B′ r ↝⟨ (inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ⟩ B′ r × Singleton r ↝⟨ ∃-comm ⟩ (∃ λ r′ → B′ r × r′ ≡ r) ↝⟨ ∃-cong (λ _ → ×-cong₁ λ r′≡r → ≡⇒↝ _ (cong B′ (sym r′≡r))) ⟩ (∃ λ r′ → B′ r′ × r′ ≡ r) ↝⟨ Σ-assoc ⟩ (∃ λ (p : ∃ B′) → proj₁ p ≡ r) ↝⟨ inverse $ Σ-cong Eq.⟨ _ , eq ⟩ (λ _ → F.id) ⟩□ (∃ λ a → remainder a ≡ r) □ ------------------------------------------------------------------------ -- Lens combinators -- Conversion from Lens₃ to Lens. Lens₃-to-Lens : {A : Set a} {R : Set (a ⊔ b)} {B : R → Set b} → (l : Lens₃ A R B) → Lens A (B ⊚ Lens₃.remainder l) Lens₃-to-Lens {A = A} {R} {B} l = _ , _ , (A ↝⟨ l ⟩ Σ R B ↔⟨ ∃-cong (λ _ → inverse ∥∥×↔) ⟩ Σ R (λ r → ∥ B r ∥ × B r) ↔⟨ Σ-assoc ⟩□ Σ (Σ R (λ r → ∥ B r ∥)) (λ { (r , _) → B r }) □) , proj₂ , λ _ → refl -- A variant of Lens₃-to-Lens. Lens₃-to-Lens′ : {A : Set (a ⊔ r)} {R : Set r} {B : R → Set b} → (l : Lens₃ A R B) → Lens A (B ⊚ Lens₃.remainder l) Lens₃-to-Lens′ {a = a} {b = b} {A = A} {R = R} {B = B} l = Lens₃-to-Lens (A ↝⟨ l ⟩ Σ R B ↝⟨ Σ-cong (inverse Bij.↑↔) (λ _ → F.id) ⟩□ Σ (↑ (a ⊔ b) R) (λ { (lift r) → B r }) □) -- Identity lens. id : Lens A (λ _ → A) id {A = A} = Lens₃-to-Lens′ (A ↔⟨ inverse ×-left-identity ⟩□ ⊤ × A □) -- Composition of lenses. -- -- Note that this function combines a family of Lenses and a Lens₃. infixr 9 _∘₃_ _∘₃_ : {A : Set (a ⊔ b ⊔ c)} {R : Set (a ⊔ b ⊔ c)} {B : R → Set (b ⊔ c)} {C : {r : R} → B r → Set c} → (∀ {r} → Lens (B r) C) → (l₂ : Lens₃ A R B) → Lens A (C ⊚ Lens₃.get l₂) _∘₃_ {R = R} l₁ l₂ = (∃ λ (r : R) → Lens.R (l₁ {r = r})) , (λ { (r₁ , r₂) → Lens.B′ (l₁ {r = r₁}) r₂ }) , Lens.lens l₁ ₃∘₃ l₂ , Lens.inhabited l₁ ⊚ proj₂ , Lens.variant l₁ ⊚ Lens₃.get l₂ -- /Forward/ composition of lenses. -- -- This function combines /Lens/es, but has a type which is arguably -- more complicated. The type is also somewhat restricted: C is only -- indexed by As, not Bs. infixr 9 _⨾_ _⨾_ : {A : Set (a ⊔ b ⊔ c)} {B : A → Set (b ⊔ c)} {C : A → Set c} → (l₁ : Lens A B) → let open Lens l₁; open _≃_ lens in (∀ {r} → Lens (B′ r) (λ b′ → C (from (r , b′)))) → Lens A C _⨾_ {C = C} l₁ l₂ = (∃ λ (r₁ : R l₁) → Lens.R (l₂ {r = r₁})) , (λ { (r₁ , r₂) → B′ (l₂ {r = r₁}) r₂ }) , lens l₂ ₃∘₃ lens l₁ , (λ { (_ , r₂) → inhabited l₂ r₂ }) , λ a → B′ l₂ (remainder l₂ (Lens₃.get (lens l₁) a)) ≡⟨ variant l₂ _ ⟩ C (from (lens l₁) (to (lens l₁) a)) ≡⟨ cong C (left-inverse-of (lens l₁) a) ⟩∎ C a ∎ where open _≃_ open Lens -- Can the composition operation be generalised? -- The argument below does not depend on the details of the -- implementation of Lens. module No-fully-general-composition-operator (Lens′ : (A : Set) → (A → Set) → Set₁) (get′ : ∀ {A B} → Lens′ A B → (a : A) → B a) where -- The following type signature—and partial specification—might seem -- like a reasonable goal (if we restrict attention to Set₀). Type-of-composition : Set₁ Type-of-composition = {A : Set} {B : A → Set} {C : (a : A) → B a → Set} (l₁ : Lens′ A B) (l₂ : ∀ a → Lens′ (B a) (C a)) → ∃ λ (l₃ : Lens′ A (λ a → C a (get′ l₁ a))) → ∀ a → get′ l₃ a ≡ get′ (l₂ a) (get′ l₁ a) -- However, this specification is unsatisfiable in the non-dependent -- case (for ND.Lens). no-corresponding-non-dependent-composition-operator : let open ND.Lens in ¬ ({A B C : Set} (l₁ : ND.Lens A B) (l₂ : A → ND.Lens B C) → ∃ λ (l₃ : ND.Lens A C) → ∀ a → get l₃ a ≡ get (l₂ a) (get l₁ a)) no-corresponding-non-dependent-composition-operator comp = contradiction where open ND.Lens open _≃_ idL : ND.Lens Bool Bool idL = ND.Lens-combinators.id ⊠ swapL : ND.Lens Bool Bool swapL = ND.isomorphism-to-lens (Bool ↔⟨ swap ⟩ Bool ↔⟨ inverse ×-left-identity ⟩□ ⊤ × Bool □) l₁ : ND.Lens Bool Bool l₁ = idL l₂ : Bool → ND.Lens Bool Bool l₂ = if_then idL else swapL l₃ : ND.Lens Bool Bool l₃ = proj₁ (comp l₁ l₂) get-constant : ∀ b → get l₃ b ≡ true get-constant true = proj₂ (comp l₁ l₂) _ get-constant false = proj₂ (comp l₁ l₂) _ contradiction : ⊥ contradiction = Bool.true≢false ( true ≡⟨ sym $ get-constant (set l₃ true false) ⟩ get l₃ (set l₃ true false) ≡⟨ get-set l₃ true false ⟩∎ false ∎) -- Thus it is also unsatisfiable if non-dependent dependent lenses -- are isomorphic (in a certain sense) to the corresponding -- non-dependent lenses. no-composition-operator : ({A B : Set} → ∃ λ (iso : Lens′ A (λ _ → B) ↔ ND.Lens A B) → ∀ {l a} → get′ l a ≡ ND.Lens.get (_↔_.to iso l) a) → ¬ Type-of-composition no-composition-operator Lens↔Lens comp = no-corresponding-non-dependent-composition-operator (λ l₁ l₂ → let l₃ , get-l₃ = comp (from l₁) (λ a → from (l₂ a)) in to l₃ , λ a → get (to l₃) a ≡⟨ sym $ proj₂ Lens↔Lens ⟩ get′ l₃ a ≡⟨ get-l₃ a ⟩ get′ (from (l₂ a)) (get′ (from l₁) a) ≡⟨ cong (get′ (from (l₂ a))) (proj₂ Lens↔Lens) ⟩ get′ (from (l₂ a)) (get (to (from l₁)) a) ≡⟨ proj₂ Lens↔Lens ⟩ get (to (from (l₂ a))) (get (to (from l₁)) a) ≡⟨ cong₂ (λ l₁ l₂ → get l₁ (get l₂ a)) (right-inverse-of _) (right-inverse-of _) ⟩∎ get (l₂ a) (get l₁ a) ∎) where open ND.Lens open module Lens↔Lens {A B : Set} = _↔_ (proj₁ (Lens↔Lens {A = A} {B = B})) -- In the presence of UIP for Set it is impossible to define a fully -- general composition operator. no-fully-general-composition-operator-UIP : let open Lens in Is-set Set → ¬ ({A : Set} {B : A → Set} {C : (a : A) → B a → Set} (l₁ : Lens A B) (l₂ : ∀ a → Lens (B a) (C a)) → ∃ λ (l₃ : Lens A (λ a → C a (Lens.get l₁ a))) → ∀ a → get l₃ a ≡ get (l₂ a) (get l₁ a)) no-fully-general-composition-operator-UIP uip = No-fully-general-composition-operator.no-composition-operator Lens Lens.get (non-dependent-lenses-isomorphic-UIP uip) ------------------------------------------------------------------------ -- An observation -- Lens₃ lenses cannot (easily) be used to replace ordinary -- projections: one cannot, in general, define lenses with the type of -- the first projection from a Σ-type. For Lens lenses the situation -- is unclear. module Observation where -- A Σ-type which is isomorphic to the unit type. Unit = Σ Bool λ b → b ≡ true -- All its inhabitants are equal. equal : (u₁ u₂ : Unit) → u₁ ≡ u₂ equal (.true , refl) (.true , refl) = refl -- Its only inhabitant. u : Unit u = (true , refl) -- The first projection Lens₃ cannot be defined for Unit. not-proj₁₃ : ∀ {r} {R : Set r} → ¬ Lens₃ Unit R (λ _ → Bool) not-proj₁₃ l = Bool.true≢false ( true ≡⟨ sym $ subst-const (sym $ remainder-set u true) ⟩ subst (λ _ → Bool) (sym $ remainder-set u true) true ≡⟨ sym $ get-set₁ u true ⟩ get (set u true) ≡⟨ cong get (equal (set u true) (set u false)) ⟩ get (set u false) ≡⟨ get-set₁ u false ⟩ subst (λ _ → Bool) (sym $ remainder-set u false) false ≡⟨ subst-const (sym $ remainder-set u false) ⟩∎ false ∎) where open Lens₃ l -- The first projection Lens cannot be defined for Unit /if/ we -- assume that UIP holds for Set. not-proj₁ : Is-set Set → ¬ Lens Unit (λ _ → Bool) not-proj₁ uip l = Bool.true≢false ( true ≡⟨ sym $ cong (λ eq → from eq true) $ codomain-set-≃≡id uip l ⟩ from codomain-set-≃ true ≡⟨ sym $ get-set u true ⟩ get (set u true) ≡⟨ cong get (equal (set u true) (set u false)) ⟩ get (set u false) ≡⟨ get-set u false ⟩ from codomain-set-≃ false ≡⟨ cong (λ eq → from eq false) $ codomain-set-≃≡id uip l ⟩∎ false ∎) where open _≃_ open Lens l -- TODO: What is the situation in the presence of univalence?
{ "alphanum_fraction": 0.3803100748, "avg_line_length": 40.7837058399, "ext": "agda", "hexsha": "338026e988c44e05c56c20cc0f2d95e2642739a5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Saizan/dependent-lenses", "max_forks_repo_path": "src/Lens/Dependent.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Saizan/dependent-lenses", "max_issues_repo_path": "src/Lens/Dependent.agda", "max_line_length": 147, "max_stars_count": null, "max_stars_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Saizan/dependent-lenses", "max_stars_repo_path": "src/Lens/Dependent.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 19673, "size": 56567 }
{-# OPTIONS --without-K --exact-split --safe #-} module Fragment.Extensions.CSemigroup where open import Fragment.Extensions.CSemigroup.Base using (CSemigroupFrex) public
{ "alphanum_fraction": 0.7803468208, "avg_line_length": 28.8333333333, "ext": "agda", "hexsha": "bc474a64fef7fb7bafeb36e9b380307ee7733ed0", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Extensions/CSemigroup.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Extensions/CSemigroup.agda", "max_line_length": 77, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Extensions/CSemigroup.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 37, "size": 173 }
{-# OPTIONS --without-K #-} module BimonoidalCategory where open import Level open import Categories.Category open import Categories.Monoidal open import Categories.Monoidal.Braided open import Categories.NaturalIsomorphism open import Categories.NaturalTransformation using (id; _∘₁_; _≡_) ------------------------------------------------------------------------------ -- Definition record SymmetricMonoidalCategory {o ℓ e} {ℂ : Category o ℓ e} {Mℂ : Monoidal ℂ} (BMℂ : Braided Mℂ) : Set (suc (o ⊔ ℓ ⊔ e)) where open Braided BMℂ using (braid) open NaturalIsomorphism braid using () renaming (F⇒G to x⊗y⇒y⊗x; F⇐G to y⊗x⇒x⊗y) field symmetry : x⊗y⇒y⊗x ∘₁ y⊗x⇒x⊗y ≡ id {-- record BimonoidalCategory o ℓ e (C : Category o ℓ e) : Set (suc (o ⊔ ℓ ⊔ e)) where infixr 9 _∘_ infixl 7 _+_ _⊕_ infixl 6 _*_ _⊗_ infix 4 _⇒_ infix 1 _≈_ field -- objects, morphisms, equality on morphisms Obj : Set o _⇒_ : Rel Obj ℓ _≈_ : ∀ {A B} → Rel (A ⇒ B) e -- plain category id : ∀ {A} → A ⇒ A _∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C) -- additive monoid 0# : Obj _+_ : Op₂ Obj _⊕_ : ∀ {A B C D} → (A ⇒ C) → (B ⇒ D) → (A + B ⇒ C + D) -- multiplicative monoid 1# : Obj _*_ : Op₂ Obj _⊗_ : ∀ {A B C D} → (A ⇒ C) → (B ⇒ D) → (A * B ⇒ C * D) -- axioms isBimonoidalCategory : IsBimonoidalCategory _⇒_ _≈_ id _∘_ 0# _+_ _⊕_ 1# _*_ _⊗_ record Iso {o ℓ e} {Obj : Set o} (_⇒_ : Rel Obj ℓ) (_≈_ : ∀ {A B} → Rel (A ⇒ B) e) (id : ∀ {A} → A ⇒ A) (_∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C)) (A B : Obj) : Set (o ⊔ ℓ ⊔ e) where field fwd : A ⇒ B bwd : B ⇒ A fwd∘bwd : (_∘_ {B} {A} {B} fwd bwd) ≈ id {B} bwd∘fwd : (_∘_ {A} {B} {A} bwd fwd) ≈ id {A} record IsMonoid {o ℓ e} {Obj : Set o} (_⇒_ : Rel Obj ℓ) (_≈_ : ∀ {A B} → Rel (A ⇒ B) e) (id : ∀ {A} → A ⇒ A) (_∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C)) (u : Obj) (_op_ : Op₂ Obj) (_opf_ : ∀ {A B C D} → (A ⇒ C) → (B ⇒ D) → (_⇒_ (A op B) (C op D))) : Set (o ⊔ ℓ ⊔ e) where field assoc : {A B C : Obj} → Iso _⇒_ _≈_ id _∘_ ((A op B) op C) (A op (B op C)) unite : {A : Obj} → Iso _⇒_ _≈_ id _∘_ (u op A) A uniti : {A : Obj} → Iso _⇒_ _≈_ id _∘_ (A op u) A funcObj : {A B : Obj} → ((id {A}) opf (id {B})) ≈ id {A op B} -- funcMor : {A B C D E F G H : Obj} {f : A ⇒ B} {g : C ⇒ D} {k : E ⇒ F} {h : G ⇒ H} → -- ((k opf h) ∘ (g opf f)) ≈ ((k opf g) ∘ (h opf f)) -- assoc; unite; uniti are natural transformations -- triangle -- pentagon record IsBimonoidalCategory {o ℓ e} {Obj : Set o} (_⇒_ : Rel Obj ℓ) (_≈_ : ∀ {A B} → Rel (A ⇒ B) e) (id : ∀ {A} → A ⇒ A) (_∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C)) (0# : Obj) (_+_ : Op₂ Obj) (_⊕_ : ∀ {A B C D} → (A ⇒ C) → (B ⇒ D) → (_⇒_ (A + B) (C + D))) (1# : Obj) (_*_ : Op₂ Obj) (_⊗_ : ∀ {A B C D} → (A ⇒ C) → (B ⇒ D) → (_⇒_ (A * B) (C * D))) : Set (o ⊔ ℓ ⊔ e) where field cat : Category o ℓ e +-isMonoid : IsMonoid _⇒_ _≈_ id _∘_ 0# _+_ _⊕_ *-isMonoid : IsMonoid _⇒_ _≈_ id _∘_ 1# _*_ _⊗_ -- ⊕ is a bifunctor -- units and assoc are natural transformations -- pentangon and triangle axioms -- multiplicative monoid -- distributivity --} ------------------------------------------------------------------------------
{ "alphanum_fraction": 0.4665871122, "avg_line_length": 31.3271028037, "ext": "agda", "hexsha": "d974e1466fbae093b51028a041f7e35ca215cd58", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "Univalence/Obsolete/BimonoidalCategory.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "Univalence/Obsolete/BimonoidalCategory.agda", "max_line_length": 89, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "Univalence/Obsolete/BimonoidalCategory.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 1541, "size": 3352 }
module Main where import Automaton.DeterministicFinite import Automaton.NonDeterministicFinite import Automaton.Pushdown import Automaton.TuringMachine import Cardinal import Cardinal.Finite.Count import Cardinal.Proofs import Data import Data.Any import Data.Boolean import Data.Boolean.Stmt import Data.Boolean.Operators import Data.Boolean.Proofs import Data.Either import Data.List import Data.List.Computability import Data.List.Proofs import Data.List.Relation.Membership.Proofs import Data.List.Relation.Sublist.Proofs import Data.List.Relation import Data.List.Relation.Membership import Data.List.Relation.Sublist import Data.ListNonEmpty import Data.Option import Data.Proofs import Data.Tuple import Data.Tuple.Function import Data.Tuple.List import Data.Tuple.Proofs import Data.Tuple.Raise import Data.Tuple.Raiseᵣ import Data.Tuple.Raiseₗ import FFI.IO as FFI import FormalLanguage import FormalLanguage.ContextFreeGrammar import FormalLanguage.Proofs import FormalLanguage.RegularExpression import Functional import Function.DomainRaise import Function.Domains import Function.Domains.Proofs import Function.Equals import Function.Names import Function.PrimitiveRecursion import Function.Proofs import Function.Iteration import Function.Iteration.Proofs -- import Geometry.Test -- import Geometry.Test2 import Geometry.Test3 import Graph import Lang.Instance import Lang.Irrelevance import Logic.Classical import Logic.Classical.DoubleNegated import Logic.Classical.Mere import Logic.Computability import Logic.Computability.Binary import Logic.Convenience import Logic.DiagonalProof import Logic.LambdaCalculus import Logic.Predicate import Logic.Predicate.Theorems import Logic.Propositional import Logic.Propositional.Names import Logic.Propositional.Theorems import Lvl import Metalogic.Classical.Propositional.ProofSystem import Metalogic.Classical.Propositional.Syntax import Metalogic.Classical.Propositional.TruthSemanticsModel import Metalogic.Constructive.NaturalDeduction.TreeModel -- import Metalogic.Constructive.Provability import Metalogic.Linear.SequentCalculus import Metalogic.Linear.Syntax import Numeral.CoordinateVector import Numeral.FiniteInclusive import Numeral.Finite import Numeral.Finite.Bound import Numeral.Finite.Functions import Numeral.Finite.Oper import Numeral.Finite.Oper.Comparisons import Numeral.Finite.Proofs import Numeral.Integer import Numeral.Integer.Function import Numeral.Integer.Oper import Numeral.Integer.Proofs import Numeral.Integer.Relation import Numeral.Integer.Sign import Numeral.Matrix import Numeral.Natural import Numeral.Natural.Coprime import Numeral.Natural.Function import Numeral.Natural.Function.Proofs -- import Numeral.Natural.GreatestCommonDivisor import Numeral.Natural.Induction import Numeral.Natural.Inductions import Numeral.Natural.Oper import Numeral.Natural.Oper.Comparisons import Numeral.Natural.Oper.Comparisons.Proofs import Numeral.Natural.Oper.Divisibility import Numeral.Natural.Oper.Modulo import Numeral.Natural.Oper.Modulo.Proofs import Numeral.Natural.Oper.Proofs import Numeral.Natural.Order import Numeral.Natural.Prime import Numeral.Natural.Relation import Numeral.Natural.Relation.Computability import Numeral.Natural.Relation.Countable import Numeral.Natural.Relation.Divisibility import Numeral.Natural.Relation.Order import Numeral.Natural.Relation.Order.Computability import Numeral.Natural.Relation.Order.Existence import Numeral.Natural.Relation.Order.Existence.Proofs import Numeral.Natural.Relation.Order.Proofs import Numeral.Natural.Relation.Properties import Numeral.Natural.TotalOper import Numeral.Natural.UnclosedOper import Numeral.PositiveInteger import Numeral.PositiveInteger.Oper import Numeral.Rational.AlterAdd -- import Numeral.Rational.SternBrocot import Numeral.Real import Numeral.Real.Properties import Numeral.Sign import Numeral.Sign.Oper import Numeral.Sign.Oper0 import Operator.Equals import Relator.Bijection import Relator.Congruence import Relator.Congruence.Proofs import Relator.Countable import Relator.Equals import Relator.Equals.Proofs import Relator.Equals.Proofs.Uniqueness import Structure.Setoid.Uniqueness import Relator.Finite import Sets.BoolSet import Sets.BoolSet.Proofs import Sets.ETCS import Sets.IZF import Sets.PredicateSet import Sets.PredicateSet.Filter import Sets.PredicateSet.Finite import Sets.PredicateSet.Proofs import Sets.PredicateSet.Relations import Structure.Setoid import Structure.Setoid.Proofs import Stream import String import Structure.Arithmetic -- import Structure.Category import Structure.Function.Domain import Structure.Function.Linear import Structure.Function.Ordering import Structure.LinearAlgebra import Structure.Logic.Classical.PredicateBoundedQuantification import Structure.Logic.Classical.NaturalDeduction import Structure.Logic.Classical.NaturalDeduction.Proofs import Structure.Logic.Classical.SetTheory import Structure.Logic.Classical.SetTheory.SetBoundedQuantification import Structure.Logic.Classical.SetTheory.Function import Structure.Logic.Classical.SetTheory.Relation import Structure.Logic.Classical.SetTheory.ZFC import Structure.Logic.Classical.SetTheory.ZFC.BinaryRelatorSet -- import Structure.Logic.Classical.SetTheory.ZFC.Finite import Structure.Logic.Classical.SetTheory.ZFC.FunctionSet import Structure.Logic.Classical.SetTheory.ZFC.Proofs import Structure.Logic.Constructive.Functions.Properties import Structure.Logic.Constructive.NaturalDeduction import Structure.Operator.Field import Structure.Operator.Functions import Structure.Operator.Group import Structure.Operator.Group.Proofs import Structure.Operator.Monoid import Structure.Operator.Proofs import Structure.Operator.Properties import Structure.Operator.SetAlgebra import Structure.Operator.Vector import Structure.Real import Structure.Relator.Equivalence as Eq import Structure.Relator.Function import Structure.Relator.Ordering import Structure.Relator.Ordering.Subsets import Structure.Relator.Properties import Structure.Relator.Properties.Proofs import Syntax.Function import Syntax.Method import Syntax.Number import Type import Type.Cardinality import Type.Cardinality.Proofs import Type.Dependent import Type.Properties.Empty import Type.Properties.Empty.Proofs import Type.Functions import Type.Functions.Inverse import Type.Functions.Inverse.Proofs import Type.Functions.Proofs import Type.Singleton import Type.Singleton.Proofs import Type.Properties.Singleton import Type.Properties.Singleton.Proofs import Type.Univalence main : FFI.IO Data.Unit main = FFI.printStrLn("Okay")
{ "alphanum_fraction": 0.8717675692, "avg_line_length": 31.4545454545, "ext": "agda", "hexsha": "a0781e180265bdc46ce8c52f29e4c42375bef743", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "old/Main.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "old/Main.agda", "max_line_length": 67, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "old/Main.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 1485, "size": 6574 }
open import Function using (_$_) open import Relation.Binary using (Setoid) open import Data.Product using (_,_) open import Algebra.Bundles using (RawGroup; RawRing) open import Algebra.Structures using (IsGroup; IsAbelianGroup; IsRing; IsCommutativeRing) open import AKS.Algebra.Structures using (IsNonZeroCommutativeRing; IsIntegralDomain) open import AKS.Algebra.Morphism.Structures using (IsGroupHomomorphism; IsGroupMonomorphism; IsRingHomomorphism; IsRingMonomorphism) module AKS.Algebra.Morphism.Consequences where module GroupConsequences {c₁ c₂ ℓ₁ ℓ₂} {G₁ : RawGroup c₁ ℓ₁} {G₂ : RawGroup c₂ ℓ₂} {⟦_⟧} (isGroupMonomorphism : IsGroupMonomorphism G₁ G₂ ⟦_⟧) where open RawGroup G₁ using () renaming (Carrier to C₁; _∙_ to _+₁_; _⁻¹ to -₁_; ε to ε₁; _≈_ to _≈₁_; rawMonoid to +₁-rawMonoid) open RawGroup G₂ using () renaming (Carrier to C₂; _∙_ to _+₂_; _⁻¹ to -₂_; ε to ε₂; _≈_ to _≈₂_; rawMonoid to +₂-rawMonoid) open IsGroupMonomorphism isGroupMonomorphism using (injective; +-homo; -‿homo; ε-homo; +-isMonoidMonomorphism; ⟦⟧-cong) open import Algebra.Morphism.MonoidMonomorphism +-isMonoidMonomorphism using () renaming (isMonoid to +₂-isMonoid→+₁-isMonoid; comm to +₂-comm→+₁-comm) module _ (G₂-isGroup : IsGroup _≈₂_ _+₂_ ε₂ -₂_) where open IsGroup G₂-isGroup using (setoid) renaming (isMonoid to +₂-isMonoid; ⁻¹-cong to -‿cong₂; inverseˡ to -‿inverseˡ₂; inverseʳ to -‿inverseʳ₂; ∙-congˡ to +-congˡ; ∙-congʳ to +-congʳ) open Setoid setoid using (sym) open import Relation.Binary.Reasoning.Setoid setoid open import Algebra.Definitions _≈₁_ using (LeftInverse; RightInverse; Inverse; Congruent₁) -‿inverseˡ₁ : LeftInverse ε₁ -₁_ _+₁_ -‿inverseˡ₁ x = injective $ begin ⟦ -₁ x +₁ x ⟧ ≈⟨ +-homo (-₁ x) x ⟩ ⟦ -₁ x ⟧ +₂ ⟦ x ⟧ ≈⟨ +-congʳ (-‿homo x) ⟩ -₂ ⟦ x ⟧ +₂ ⟦ x ⟧ ≈⟨ -‿inverseˡ₂ ⟦ x ⟧ ⟩ ε₂ ≈⟨ sym ε-homo ⟩ ⟦ ε₁ ⟧ ∎ -‿inverseʳ₁ : RightInverse ε₁ -₁_ _+₁_ -‿inverseʳ₁ x = injective $ begin ⟦ x +₁ -₁ x ⟧ ≈⟨ +-homo x (-₁ x) ⟩ ⟦ x ⟧ +₂ ⟦ -₁ x ⟧ ≈⟨ +-congˡ (-‿homo x) ⟩ ⟦ x ⟧ +₂ -₂ ⟦ x ⟧ ≈⟨ -‿inverseʳ₂ ⟦ x ⟧ ⟩ ε₂ ≈⟨ sym ε-homo ⟩ ⟦ ε₁ ⟧ ∎ -‿inverse₁ : Inverse ε₁ -₁_ _+₁_ -‿inverse₁ = -‿inverseˡ₁ , -‿inverseʳ₁ -‿cong₁ : Congruent₁ -₁_ -‿cong₁ {x} {y} x≈y = injective $ begin ⟦ -₁ x ⟧ ≈⟨ -‿homo x ⟩ -₂ ⟦ x ⟧ ≈⟨ -‿cong₂ (⟦⟧-cong x≈y) ⟩ -₂ ⟦ y ⟧ ≈⟨ sym (-‿homo y) ⟩ ⟦ -₁ y ⟧ ∎ G₂-isGroup→G₁-isGroup : IsGroup _≈₁_ _+₁_ ε₁ -₁_ G₂-isGroup→G₁-isGroup = record { isMonoid = +₂-isMonoid→+₁-isMonoid +₂-isMonoid ; inverse = -‿inverse₁ ; ⁻¹-cong = -‿cong₁ } module _ (G₂-isAbelianGroup : IsAbelianGroup _≈₂_ _+₂_ ε₂ -₂_) where open IsAbelianGroup G₂-isAbelianGroup using () renaming (isGroup to G₂-isGroup; isMagma to +₂-isMagma; comm to +₂-comm) G₂-isAbelianGroup→G₁-isAbelianGroup : IsAbelianGroup _≈₁_ _+₁_ ε₁ -₁_ G₂-isAbelianGroup→G₁-isAbelianGroup = record { isGroup = G₂-isGroup→G₁-isGroup G₂-isGroup ; comm = +₂-comm→+₁-comm +₂-isMagma +₂-comm } module RingConsequences {c₁ c₂ ℓ₁ ℓ₂} {R₁ : RawRing c₁ ℓ₁} {R₂ : RawRing c₂ ℓ₂} {⟦_⟧} (isRingMonomorphism : IsRingMonomorphism R₁ R₂ ⟦_⟧) where open RawRing R₁ using () renaming (Carrier to C₁; _+_ to _+₁_; _*_ to _*₁_; -_ to -₁_; 0# to 0#₁; 1# to 1#₁; _≈_ to _≈₁_) open RawRing R₂ using () renaming (Carrier to C₂; _+_ to _+₂_; _*_ to _*₂_; -_ to -₂_; 0# to 0#₂; 1# to 1#₂; _≈_ to _≈₂_) open IsRingMonomorphism isRingMonomorphism using (injective; +-homo; *-homo; 0#-homo; 1#-homo; ⟦⟧-cong; *-isMonoidMonomorphism; +-isGroupMonomorphism) open import Algebra.Morphism.MonoidMonomorphism *-isMonoidMonomorphism using () renaming (isMonoid to *₂-isMonoid→*₁-isMonoid; comm to *₂-comm→*₁-comm) module _ (R₂-isRing : IsRing _≈₂_ _+₂_ _*₂_ -₂_ 0#₂ 1#₂) where open IsRing R₂-isRing using (setoid; +-cong; *-congˡ; *-congʳ) renaming (distribʳ to distribʳ₁; distribˡ to distribˡ₁; *-isMonoid to *₂-isMonoid; +-isAbelianGroup to +₂-isAbelianGroup) open Setoid setoid using (sym) open import Relation.Binary.Reasoning.Setoid setoid open import Algebra.Definitions _≈₁_ using (_DistributesOverʳ_; _DistributesOverˡ_; _DistributesOver_) distribʳ : _*₁_ DistributesOverʳ _+₁_ distribʳ r x y = injective $ begin ⟦ (x +₁ y) *₁ r ⟧ ≈⟨ *-homo (x +₁ y) r ⟩ ⟦ x +₁ y ⟧ *₂ ⟦ r ⟧ ≈⟨ *-congʳ (+-homo x y) ⟩ (⟦ x ⟧ +₂ ⟦ y ⟧) *₂ ⟦ r ⟧ ≈⟨ distribʳ₁ ⟦ r ⟧ ⟦ x ⟧ ⟦ y ⟧ ⟩ ⟦ x ⟧ *₂ ⟦ r ⟧ +₂ ⟦ y ⟧ *₂ ⟦ r ⟧ ≈⟨ +-cong (sym (*-homo x r )) (sym (*-homo y r)) ⟩ ⟦ x *₁ r ⟧ +₂ ⟦ y *₁ r ⟧ ≈⟨ sym (+-homo (x *₁ r) (y *₁ r)) ⟩ ⟦ x *₁ r +₁ y *₁ r ⟧ ∎ distribˡ : _*₁_ DistributesOverˡ _+₁_ distribˡ r x y = injective $ begin ⟦ r *₁ (x +₁ y) ⟧ ≈⟨ *-homo r (x +₁ y) ⟩ ⟦ r ⟧ *₂ ⟦ x +₁ y ⟧ ≈⟨ *-congˡ (+-homo x y) ⟩ ⟦ r ⟧ *₂ (⟦ x ⟧ +₂ ⟦ y ⟧) ≈⟨ distribˡ₁ ⟦ r ⟧ ⟦ x ⟧ ⟦ y ⟧ ⟩ ⟦ r ⟧ *₂ ⟦ x ⟧ +₂ ⟦ r ⟧ *₂ ⟦ y ⟧ ≈⟨ +-cong (sym (*-homo r x)) (sym (*-homo r y)) ⟩ ⟦ r *₁ x ⟧ +₂ ⟦ r *₁ y ⟧ ≈⟨ sym (+-homo (r *₁ x) (r *₁ y)) ⟩ ⟦ r *₁ x +₁ r *₁ y ⟧ ∎ distrib : _*₁_ DistributesOver _+₁_ distrib = distribˡ , distribʳ open GroupConsequences +-isGroupMonomorphism R₂-isRing→R₁-isRing : IsRing _≈₁_ _+₁_ _*₁_ -₁_ 0#₁ 1#₁ R₂-isRing→R₁-isRing = record { +-isAbelianGroup = G₂-isAbelianGroup→G₁-isAbelianGroup +₂-isAbelianGroup ; *-isMonoid = *₂-isMonoid→*₁-isMonoid *₂-isMonoid ; distrib = distrib } module _ (R₂-isCommutativeRing : IsCommutativeRing _≈₂_ _+₂_ _*₂_ -₂_ 0#₂ 1#₂) where open IsCommutativeRing R₂-isCommutativeRing using () renaming (isRing to R₂-isRing; *-comm to *₂-comm; *-isMagma to *₂-isMagma) R₂-isCommutativeRing→R₁-isCommutativeRing : IsCommutativeRing _≈₁_ _+₁_ _*₁_ -₁_ 0#₁ 1#₁ R₂-isCommutativeRing→R₁-isCommutativeRing = record { isRing = R₂-isRing→R₁-isRing R₂-isRing ; *-comm = *₂-comm→*₁-comm *₂-isMagma *₂-comm } module _ (R₂-isNonZeroCommutativeRing : IsNonZeroCommutativeRing C₂ _≈₂_ _+₂_ _*₂_ -₂_ 0#₂ 1#₂) where open IsNonZeroCommutativeRing R₂-isNonZeroCommutativeRing using (setoid) renaming (isCommutativeRing to R₂-isCommutativeRing; 0#≉1# to 0#₂≉1#₂) open Setoid setoid using (sym) open import Relation.Binary.Reasoning.Setoid setoid open import AKS.Algebra.Structures C₁ _≈₁_ using () renaming (_≉_ to _≉₁_) 0#₁≉1#₁ : 0#₁ ≉₁ 1#₁ 0#₁≉1#₁ 0#₁≈1#₁ = 0#₂≉1#₂ $ begin 0#₂ ≈⟨ sym 0#-homo ⟩ ⟦ 0#₁ ⟧ ≈⟨ ⟦⟧-cong 0#₁≈1#₁ ⟩ ⟦ 1#₁ ⟧ ≈⟨ 1#-homo ⟩ 1#₂ ∎ R₂-isNonZeroCommutativeRing→R₁-isNonZeroCommutativeRing : IsNonZeroCommutativeRing C₁ _≈₁_ _+₁_ _*₁_ -₁_ 0#₁ 1#₁ R₂-isNonZeroCommutativeRing→R₁-isNonZeroCommutativeRing = record { isCommutativeRing = R₂-isCommutativeRing→R₁-isCommutativeRing R₂-isCommutativeRing ; 0#≉1# = 0#₁≉1#₁ } module _ (R₂-isIntegralDomain : IsIntegralDomain C₂ _≈₂_ _+₂_ _*₂_ -₂_ 0#₂ 1#₂) where open IsIntegralDomain R₂-isIntegralDomain using (setoid) renaming (isNonZeroCommutativeRing to R₂-isNonZeroCommutativeRing; *-cancelˡ to *₂-cancelˡ) open Setoid setoid using (sym) open import Relation.Binary.Reasoning.Setoid setoid open import AKS.Algebra.Structures C₁ _≈₁_ using () renaming (_≉_ to _≉₁_) open import AKS.Algebra.Structures C₂ _≈₂_ using () renaming (_≉_ to _≉₂_) *-cancelˡ : ∀ x {y z} → x ≉₁ 0#₁ → x *₁ y ≈₁ x *₁ z → y ≈₁ z *-cancelˡ x {y} {z} x≉0 x*y≈x*z = injective $ *₂-cancelˡ ⟦ x ⟧ ⟦x⟧≉0 $ begin ⟦ x ⟧ *₂ ⟦ y ⟧ ≈⟨ sym (*-homo x y) ⟩ ⟦ x *₁ y ⟧ ≈⟨ ⟦⟧-cong x*y≈x*z ⟩ ⟦ x *₁ z ⟧ ≈⟨ *-homo x z ⟩ ⟦ x ⟧ *₂ ⟦ z ⟧ ∎ where ⟦x⟧≉0 : ⟦ x ⟧ ≉₂ 0#₂ ⟦x⟧≉0 ⟦x⟧≈0 = x≉0 $ injective $ begin ⟦ x ⟧ ≈⟨ ⟦x⟧≈0 ⟩ 0#₂ ≈⟨ sym 0#-homo ⟩ ⟦ 0#₁ ⟧ ∎ R₂-isIntegralDomain→R₁-isIntegralDomain : IsIntegralDomain C₁ _≈₁_ _+₁_ _*₁_ -₁_ 0#₁ 1#₁ R₂-isIntegralDomain→R₁-isIntegralDomain = record { isNonZeroCommutativeRing = R₂-isNonZeroCommutativeRing→R₁-isNonZeroCommutativeRing R₂-isNonZeroCommutativeRing ; *-cancelˡ = *-cancelˡ }
{ "alphanum_fraction": 0.6138649861, "avg_line_length": 49.7048192771, "ext": "agda", "hexsha": "28e1a6210509fc79b1595dc0c23e3b2671392bb2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/thesis", "max_forks_repo_path": "proofs/AKS/Algebra/Morphism/Consequences.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mckeankylej/thesis", "max_issues_repo_path": "proofs/AKS/Algebra/Morphism/Consequences.agda", "max_line_length": 188, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/thesis", "max_stars_repo_path": "proofs/AKS/Algebra/Morphism/Consequences.agda", "max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z", "num_tokens": 3684, "size": 8251 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Cospan open import lib.types.Pullback open import lib.types.Group open import lib.groups.Homomorphisms module lib.groups.PullbackGroup where -- φ ψ -- H → G ← K record Group-Cospan {i j k : ULevel} : Type (lsucc (lmax (lmax i j) k)) where constructor group-cospan field H : Group i K : Group j G : Group k φ : H →ᴳ G ψ : K →ᴳ G group-cospan-out : ∀ {i j k} → Group-Cospan {i} {j} {k} → Cospan {i} {j} {k} group-cospan-out (group-cospan H K G φ ψ) = cospan (Group.El H) (Group.El K) (Group.El G) (GroupHom.f φ) (GroupHom.f ψ) module _ {i j k} (D : Group-Cospan {i} {j} {k}) where private open Group-Cospan D module H = Group H module K = Group K module G = Group G module φ = GroupHom φ module ψ = GroupHom ψ d : Cospan d = cospan H.El K.El G.El φ.f ψ.f Pullback-group-struct : GroupStructure (Pullback d) Pullback-group-struct = record { ident = pullback H.ident K.ident (φ.pres-ident ∙ ! (ψ.pres-ident)); inv = λ {(pullback h k p) → pullback (H.inv h) (K.inv k) (φ.pres-inv h ∙ ap G.inv p ∙ ! (ψ.pres-inv k))}; comp = λ {(pullback h₁ k₁ p₁) (pullback h₂ k₂ p₂) → pullback (H.comp h₁ h₂) (K.comp k₁ k₂) (φ.pres-comp h₁ h₂ ∙ ap2 G.comp p₁ p₂ ∙ ! (ψ.pres-comp k₁ k₂))}; unitl = λ {(pullback h k p) → pullback= d (H.unitl h) (K.unitl k) (prop-has-all-paths (G.El-level _ _) _ _)}; unitr = λ {(pullback h k p) → pullback= d (H.unitr h) (K.unitr k) (prop-has-all-paths (G.El-level _ _) _ _)}; assoc = λ {(pullback h₁ k₁ p₁) (pullback h₂ k₂ p₂) (pullback h₃ k₃ p₃) → pullback= d (H.assoc h₁ h₂ h₃) (K.assoc k₁ k₂ k₃) (prop-has-all-paths (G.El-level _ _) _ _)}; invl = λ {(pullback h k p) → pullback= d (H.invl h) (K.invl k) (prop-has-all-paths (G.El-level _ _) _ _)}; invr = λ {(pullback h k p) → pullback= d (H.invr h) (K.invr k) (prop-has-all-paths (G.El-level _ _) _ _)}} Pullback-group : Group (lmax i (lmax j k)) Pullback-group = record { El = Pullback d; El-level = pullback-level 0 H.El-level K.El-level G.El-level; group-struct = Pullback-group-struct} pfst-hom : Pullback-group →ᴳ H pfst-hom = record { f = Pullback.a; pres-comp = λ _ _ → idp} psnd-hom : Pullback-group →ᴳ K psnd-hom = record { f = Pullback.b; pres-comp = λ _ _ → idp} module _ {l} {J : Group l} (χ : J →ᴳ H) (θ : J →ᴳ K) where private module χ = GroupHom χ module θ = GroupHom θ pullback-hom : ((j : Group.El J) → φ.f (χ.f j) == ψ.f (θ.f j)) → J →ᴳ Pullback-group pullback-hom p = record { f = λ j → pullback (χ.f j) (θ.f j) (p j); pres-comp = λ j₁ j₂ → pullback= (group-cospan-out D) (χ.pres-comp j₁ j₂) (θ.pres-comp j₁ j₂) (prop-has-all-paths (Group.El-level G _ _) _ _)}
{ "alphanum_fraction": 0.5738095238, "avg_line_length": 30.625, "ext": "agda", "hexsha": "5c026b08e528a62c0ce37b95f036e476ea494cfb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "core/lib/groups/PullbackGroup.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_path": "core/lib/groups/PullbackGroup.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "core/lib/groups/PullbackGroup.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1105, "size": 2940 }
------------------------------------------------------------------------ -- Lemmas related to bisimilarity and CCS, implemented using the -- classical definition of bisimilarity ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Prelude module Bisimilarity.CCS.Classical {ℓ} {Name : Type ℓ} where open import Equality.Propositional open import Logical-equivalence using (_⇔_) open import Prelude.Size import Bisimilarity.CCS.General import Bisimilarity.Classical.Equational-reasoning-instances open import Equational-reasoning open import Labelled-transition-system.CCS Name open import Relation open import Bisimilarity.Classical CCS ------------------------------------------------------------------------ -- Various lemmas related to _∣_ -- _∣_ is commutative. ∣-comm : ∀ {P Q} → P ∣ Q ∼ Q ∣ P ∣-comm = ⟨ R , R-is-a-bisimulation , base ⟩ where data R : Rel₂ ℓ (Proc ∞) where base : ∀ {P Q} → R (P ∣ Q , Q ∣ P) R-is-symmetric : ∀ {P Q} → R (P , Q) → R (Q , P) R-is-symmetric base = base R-is-a-bisimulation : Bisimulation R R-is-a-bisimulation = ⟪ lr , (λ PRQ tr → Σ-map id (Σ-map id R-is-symmetric) (lr (R-is-symmetric PRQ) tr)) ⟫ where lr : ∀ {P P′ Q μ} → R (P , Q) → P [ μ ]⟶ P′ → ∃ λ Q′ → Q [ μ ]⟶ Q′ × R (P′ , Q′) lr base (par-left tr) = _ , par-right tr , base lr base (par-right tr) = _ , par-left tr , base lr base (par-τ tr₁ tr₂) = _ , par-τ tr₂ (subst (λ a → _ [ name a ]⟶ _) (sym $ co-involutive _) tr₁) , base -- _∣_ is associative. ∣-assoc : ∀ {P Q R} → P ∣ (Q ∣ R) ∼ (P ∣ Q) ∣ R ∣-assoc = ⟨ S , S-is-a-bisimulation , base ⟩ where data S : Rel₂ ℓ (Proc ∞) where base : ∀ {P Q R} → S (P ∣ (Q ∣ R) , (P ∣ Q) ∣ R) S-is-a-bisimulation : Bisimulation S S-is-a-bisimulation = ⟪ lr , rl ⟫ where lr : ∀ {P P′ Q μ} → S (P , Q) → P [ μ ]⟶ P′ → ∃ λ Q′ → Q [ μ ]⟶ Q′ × S (P′ , Q′) lr base (par-left tr) = _ , par-left (par-left tr) , base lr base (par-right (par-left tr)) = _ , par-left (par-right tr) , base lr base (par-right (par-right tr)) = _ , par-right tr , base lr base (par-right (par-τ tr₁ tr₂)) = _ , par-τ (par-right tr₁) tr₂ , base lr base (par-τ tr₁ (par-left tr₂)) = _ , par-left (par-τ tr₁ tr₂) , base lr base (par-τ tr₁ (par-right tr₂)) = _ , par-τ (par-left tr₁) tr₂ , base rl : ∀ {P Q Q′ μ} → S (P , Q) → Q [ μ ]⟶ Q′ → ∃ λ P′ → P [ μ ]⟶ P′ × S (P′ , Q′) rl base (par-left (par-left tr)) = _ , par-left tr , base rl base (par-left (par-right tr)) = _ , par-right (par-left tr) , base rl base (par-left (par-τ tr₁ tr₂)) = _ , par-τ tr₁ (par-left tr₂) , base rl base (par-right tr) = _ , par-right (par-right tr) , base rl base (par-τ (par-left tr₁) tr₂) = _ , par-τ tr₁ (par-right tr₂) , base rl base (par-τ (par-right tr₁) tr₂) = _ , par-right (par-τ tr₁ tr₂) , base -- ∅ is a left identity of _∣_. ∣-left-identity : ∀ {P} → ∅ ∣ P ∼ P ∣-left-identity = ⟨ R , R-is-a-bisimulation , base ⟩ where data R : Rel₂ ℓ (Proc ∞) where base : ∀ {P} → R (∅ ∣ P , P) R-is-a-bisimulation : Bisimulation R R-is-a-bisimulation = ⟪ lr , rl ⟫ where lr : ∀ {P P′ Q μ} → R (P , Q) → P [ μ ]⟶ P′ → ∃ λ Q′ → Q [ μ ]⟶ Q′ × R (P′ , Q′) lr base (par-right tr) = _ , tr , base lr base (par-left ()) lr base (par-τ () _) rl : ∀ {P Q Q′ μ} → R (P , Q) → Q [ μ ]⟶ Q′ → ∃ λ P′ → P [ μ ]⟶ P′ × R (P′ , Q′) rl base tr = _ , par-right tr , base -- ∅ is a right identity of _∣_. ∣-right-identity : ∀ {P} → P ∣ ∅ ∼ P ∣-right-identity {P} = P ∣ ∅ ∼⟨ ∣-comm ⟩ ∅ ∣ P ∼⟨ ∣-left-identity ⟩■ P -- _∣_ preserves bisimilarity. _∣-cong_ : ∀ {P P′ Q Q′} → P ∼ P′ → Q ∼ Q′ → P ∣ Q ∼ P′ ∣ Q′ P∼P′ ∣-cong Q∼Q′ with _⇔_.to (Bisimilarity↔ _) P∼P′ | _⇔_.to (Bisimilarity↔ _) Q∼Q′ ... | L , L-bisim , PLP′ | R , R-bisim , QRQ′ = ⟨ LR , ⟪ lr , rl ⟫ , base PLP′ QRQ′ ⟩ where data LR : Rel₂ ℓ (Proc ∞) where base : ∀ {P P′ Q Q′} → L (P , P′) → R (Q , Q′) → LR (P ∣ Q , P′ ∣ Q′) lr : ∀ {P P′ Q μ} → LR (P , Q) → P [ μ ]⟶ P′ → ∃ λ Q′ → Q [ μ ]⟶ Q′ × LR (P′ , Q′) lr (base PLP′ QRQ′) (par-left tr) = Σ-map (_∣ _) (Σ-map par-left (flip base QRQ′)) (left-to-right L-bisim PLP′ tr) lr (base PLP′ QRQ′) (par-right tr) = Σ-map (_ ∣_) (Σ-map par-right (base PLP′)) (left-to-right R-bisim QRQ′ tr) lr (base PLP′ QRQ′) (par-τ tr₁ tr₂) = Σ-zip _∣_ (Σ-zip par-τ base) (left-to-right L-bisim PLP′ tr₁) (left-to-right R-bisim QRQ′ tr₂) rl : ∀ {P Q Q′ μ} → LR (P , Q) → Q [ μ ]⟶ Q′ → ∃ λ P′ → P [ μ ]⟶ P′ × LR (P′ , Q′) rl (base PLP′ QRQ′) (par-left tr) = Σ-map (_∣ _) (Σ-map par-left (flip base QRQ′)) (right-to-left L-bisim PLP′ tr) rl (base PLP′ QRQ′) (par-right tr) = Σ-map (_ ∣_) (Σ-map par-right (base PLP′)) (right-to-left R-bisim QRQ′ tr) rl (base PLP′ QRQ′) (par-τ tr₁ tr₂) = Σ-zip _∣_ (Σ-zip par-τ base) (right-to-left L-bisim PLP′ tr₁) (right-to-left R-bisim QRQ′ tr₂) ------------------------------------------------------------------------ -- Exercise 6.1.2 from "Enhancements of the bisimulation proof method" -- by Pous and Sangiorgi 6-1-2 : ∀ {P} → ! P ∣ P ∼ ! P 6-1-2 {P} = ⟨ R , R-is-a-bisimulation , base ⟩ where data R : Rel₂ ℓ (Proc ∞) where base : R (! P ∣ P , ! P) refl : ∀ {P} → R (P , P) R-is-a-bisimulation : Bisimulation R R-is-a-bisimulation = ⟪ lr , rl ⟫ where lr : ∀ {P P′ Q μ} → R (P , Q) → P [ μ ]⟶ P′ → ∃ λ Q′ → Q [ μ ]⟶ Q′ × R (P′ , Q′) lr base tr = _ , replication tr , refl lr refl tr = _ , tr , refl rl : ∀ {P Q Q′ μ} → R (P , Q) → Q [ μ ]⟶ Q′ → ∃ λ P′ → P [ μ ]⟶ P′ × R (P′ , Q′) rl base (replication tr) = _ , tr , refl rl refl tr = _ , tr , refl ------------------------------------------------------------------------ -- Exercise 6.1.3 (2) from "Enhancements of the bisimulation proof -- method" by Pous and Sangiorgi open Bisimilarity.CCS.General.6-1-3-2 (record { _∼_ = _∼_ ; step-∼ = step-∼ ; finally-∼ = Equational-reasoning.finally₂ ; reflexive = reflexive ; symmetric = symmetric ; ∣-comm = ∣-comm ; ∣-assoc = ∣-assoc ; _∣-cong_ = _∣-cong_ ; 6-1-2 = 6-1-2 }) public using (swap-rightmost; 6-1-3-2)
{ "alphanum_fraction": 0.4676936883, "avg_line_length": 32.7745098039, "ext": "agda", "hexsha": "b2db630196651b2b180842a6cf947ae3c050f9e1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "src/Bisimilarity/CCS/Classical.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "src/Bisimilarity/CCS/Classical.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "src/Bisimilarity/CCS/Classical.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2619, "size": 6686 }
{-# OPTIONS --safe #-} module Cubical.Categories.Functors.HomFunctor where open import Cubical.Foundations.Prelude open import Cubical.Categories.Category open import Cubical.Categories.Functor.Base open import Cubical.Categories.Instances.Sets open import Cubical.Categories.Constructions.BinProduct renaming (_×_ to _×C_) private variable ℓC ℓC' : Level module _ (C : Category ℓC ℓC') where open Functor open Category C HomFunctor : Functor (C ^op ×C C) (SET ℓC') F-ob HomFunctor (x , y) = Hom[ x , y ] , isSetHom F-hom HomFunctor {x , y} {x' , y'} (φ , ψ) θ = ψ ∘ (θ ∘ φ) F-id HomFunctor = funExt λ θ → ⋆IdR (id ⋆ θ) ∙ ⋆IdL θ F-seq HomFunctor {x , y} {x' , y'} {x'' , y''} (φ , ψ) (φ' , ψ') = funExt λ θ → ((φ' ⋆ φ) ⋆ θ) ⋆ (ψ ⋆ ψ') ≡⟨ sym (⋆Assoc ((φ' ⋆ φ) ⋆ θ) ψ ψ') ⟩ (((φ' ⋆ φ) ⋆ θ) ⋆ ψ) ⋆ ψ' ≡⟨ cong (_⋆ ψ') ( ((φ' ⋆ φ) ⋆ θ) ⋆ ψ ≡⟨ cong (_⋆ ψ) (⋆Assoc φ' φ θ) ⟩ (φ' ⋆ (φ ⋆ θ)) ⋆ ψ ≡⟨ ⋆Assoc φ' (φ ⋆ θ) ψ ⟩ φ' ⋆ ((φ ⋆ θ) ⋆ ψ) ∎ ) ⟩ (φ' ⋆ ((φ ⋆ θ) ⋆ ψ)) ⋆ ψ' ∎
{ "alphanum_fraction": 0.5196998124, "avg_line_length": 29.6111111111, "ext": "agda", "hexsha": "5b37eea00926f67d2f3337e256ef62265b781ec1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Categories/Functors/HomFunctor.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Categories/Functors/HomFunctor.agda", "max_line_length": 81, "max_stars_count": 1, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Categories/Functors/HomFunctor.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 529, "size": 1066 }
{-# OPTIONS --allow-exec #-} module ExecAgda where open import Agda.Builtin.Equality open import Agda.Builtin.List open import Agda.Builtin.Nat open import Agda.Builtin.Unit open import Agda.Builtin.Sigma open import Agda.Builtin.String open import Agda.Builtin.Reflection renaming (bindTC to _>>=_) postulate execTC : String → List String → String → TC (Σ Nat (λ _ → Σ String (λ _ → String))) {-# BUILTIN AGDATCMEXEC execTC #-} macro test : Term → TC ⊤ test hole = execTC "agda" ("-v0" ∷ "-i" ∷ "test/Succeed" ∷ "test/Succeed/exec-tc/empty.agda" ∷ []) "" >>= λ{(exitCode , (stdOut , stdErr)) → unify hole (lit (string stdOut))} _ : test ≡ "" _ = refl
{ "alphanum_fraction": 0.6706231454, "avg_line_length": 26.96, "ext": "agda", "hexsha": "9b4982083651f53f496b75c0a20a9e1536fbe9b6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f7772e5515cd896fc9bf458fa19d18847ac56742", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Saizan/agda", "max_forks_repo_path": "test/Succeed/ExecAgda.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f7772e5515cd896fc9bf458fa19d18847ac56742", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "Saizan/agda", "max_issues_repo_path": "test/Succeed/ExecAgda.agda", "max_line_length": 103, "max_stars_count": null, "max_stars_repo_head_hexsha": "f7772e5515cd896fc9bf458fa19d18847ac56742", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "Saizan/agda", "max_stars_repo_path": "test/Succeed/ExecAgda.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 211, "size": 674 }
module Nat where data Nat : Set where zero : Nat suc : Nat -> Nat infixl 60 _+_ infixl 70 _*_ _+_ : Nat -> Nat -> Nat n + zero = n n + suc m = suc (n + m) _*_ : Nat -> Nat -> Nat n * zero = zero n * suc m = n * m + n {-# BUILTIN NATURAL Nat #-} {-# BUILTIN ZERO zero #-} {-# BUILTIN SUC suc #-} {-# BUILTIN NATPLUS _+_ #-} {-# BUILTIN NATTIMES _*_ #-}
{ "alphanum_fraction": 0.5409836066, "avg_line_length": 14.64, "ext": "agda", "hexsha": "394e2db5441f0949210c19f84c81268cdb42dfc1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "examples/SummerSchool07/Lecture/Nat.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "examples/SummerSchool07/Lecture/Nat.agda", "max_line_length": 28, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/SummerSchool07/Lecture/Nat.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 131, "size": 366 }
open import Prelude module Implicits.Resolution.Termination.Lemmas.SizeMeasures where open import Induction.WellFounded open import Induction.Nat open import Data.Vec open import Data.Fin.Substitution open import Extensions.Vec open import Implicits.Syntax open import Implicits.Syntax.Type.Unification open import Implicits.Substitutions open import Implicits.Substitutions.Lemmas open import Data.Nat hiding (_<_) open import Data.Nat.Properties open import Relation.Binary using (module DecTotalOrder) open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl) open import Extensions.Nat open import Implicits.Resolution.Termination.SizeMeasures -- we can show that our size measure a ρ< b is well founded -- by relating it to the well-foundedness proof of _<'_ open import Induction.WellFounded ρ<-well-founded : Well-founded _ρ<_ ρ<-well-founded = sub.well-founded (image.well-founded <-well-founded) where open import Induction.Nat open import Data.Nat open import Data.Nat.Properties module sub = Inverse-image (λ{ (_ , a ) → || a ||}) module image = Subrelation {A = ℕ} {_<_} {_<′_} ≤⇒≤′ open import Induction.WellFounded hρ<-well-founded : Well-founded _hρ<_ hρ<-well-founded = sub.well-founded (image.well-founded <-well-founded) where open import Induction.Nat open import Data.Nat open import Data.Nat.Properties module sub = Inverse-image (λ{ (_ , a ) → h|| a ||}) module image = Subrelation {A = ℕ} {_<_} {_<′_} ≤⇒≤′ m<-well-founded : Well-founded _m<_ m<-well-founded = sub.well-founded (image.well-founded <-well-founded) where module sub = Inverse-image (λ{ (_ , _ , a) → m|| a ||}) module image = Subrelation {A = ℕ} {_<_} {_<′_} ≤⇒≤′ module TypeSubstSizeLemmas where open MetaTypeTypeSubst mutual ||a/Var|| : ∀ {m ν μ} (a : MetaType m ν) (s : Sub Fin ν μ) → m|| a /Var s || ≡ m|| a || ||a/Var|| (a ⇒ b) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s) ||a/Var|| (∀' a) s = cong (λ u → 1 + u) (||a/Var|| a (s VarSubst.↑)) ||a/Var|| (simpl (tvar x)) s = refl ||a/Var|| (simpl (mvar x)) s = refl ||a/Var|| (simpl (a →' b)) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s) ||a/Var|| (simpl (tc c)) s = refl ||weaken-a|| : ∀ {m ν} (a : MetaType m ν) → m|| weaken a || ≡ m|| a || ||weaken-a|| {m} {ν} a = begin m|| weaken a || ≡⟨ refl ⟩ m|| a /Var VarSubst.wk || ≡⟨ ||a/Var|| a VarSubst.wk ⟩ m|| a || ∎ ||s↑|| : ∀ {m ν μ} (s : Sub (MetaType m) ν μ) → (∀ (x : Fin ν) → m|| lookup x s || ≡ 1) → ∀ y → m|| lookup y (s ↑) || ≡ 1 ||s↑|| s p zero = refl ||s↑|| s p (suc y) = begin m|| lookup y (map weaken s) || ≡⟨ cong m||_|| (sym $ lookup⋆map s weaken y) ⟩ m|| weaken (lookup y s) || ≡⟨ ||weaken-a|| (lookup y s) ⟩ m|| (lookup y s) || ≡⟨ p y ⟩ 1 ∎ ||a/s|| : ∀ {m ν μ} (a : MetaType m ν) (s : Sub (MetaType m) ν μ) → (∀ x → m|| lookup x s || ≡ 1) → m|| a / s || ≡ m|| a || ||a/s|| (a ⇒ b) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p) ||a/s|| (∀' a) s p = cong (λ u → 1 + u) (||a/s|| a (s ↑) (||s↑|| s p)) ||a/s|| {m} {ν} (simpl (tvar x)) s p = begin m|| (simpl (tvar x)) / s || ≡⟨ cong m||_|| (MetaTypeTypeLemmas.var-/ {x = x}) ⟩ m|| lookup x s || ≡⟨ p x ⟩ 1 ∎ ||a/s|| (simpl (mvar x)) s p = refl ||a/s|| (simpl (a →' b)) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p) ||a/s|| (simpl (tc c)) s p = refl module MetaSubstSizeLemmas where open MetaTypeMetaSubst hiding (open-meta) mutual ||a/Var|| : ∀ {ν m n} (a : MetaType m ν) (s : Sub Fin m n) → m|| a /Var s || ≡ m|| a || ||a/Var|| (a ⇒ b) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s) ||a/Var|| {ν = ν} (∀' a) s = cong (λ u → 1 + u) (||a/Var|| a ((varLift MetaLift.↑tp) {ν = ν} s)) ||a/Var|| (simpl (tvar x)) s = refl ||a/Var|| (simpl (mvar x)) s = refl ||a/Var|| (simpl (a →' b)) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s) ||a/Var|| (simpl (tc c)) s = refl ||weaken-a|| : ∀ {m ν} (a : MetaType m ν) → m|| weaken a || ≡ m|| a || ||weaken-a|| {m} {ν} a = begin m|| weaken a || ≡⟨ refl ⟩ m|| a /Var VarSubst.wk || ≡⟨ ||a/Var|| a VarSubst.wk ⟩ m|| a || ∎ ||s↑|| : ∀ {m ν μ} (s : Sub (MetaType m) ν μ) → (∀ (x : Fin ν) → m|| lookup x s || ≡ 1) → ∀ y → m|| lookup y (s ↑) || ≡ 1 ||s↑|| s p zero = refl ||s↑|| s p (suc y) = begin m|| lookup y (map weaken s) || ≡⟨ cong m||_|| (sym $ lookup⋆map s weaken y) ⟩ m|| weaken (lookup y s) || ≡⟨ ||weaken-a|| (lookup y s) ⟩ m|| (lookup y s) || ≡⟨ p y ⟩ 1 ∎ ||a/s|| : ∀ {m ν n} (a : MetaType m ν) (s : Sub (flip MetaType ν) m n) → (∀ x → m|| lookup x s || ≡ 1) → m|| a / s || ≡ m|| a || ||a/s|| (a ⇒ b) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p) ||a/s|| (∀' a) s p = cong (λ u → 1 + u) (||a/s|| a (map MetaTypeTypeSubst.weaken s) lem) where lem : ∀ x → m|| lookup x (map MetaTypeTypeSubst.weaken s) || ≡ 1 lem x = begin m|| lookup x (map MetaTypeTypeSubst.weaken s) || ≡⟨ cong m||_|| (sym $ lookup⋆map s _ x) ⟩ m|| MetaTypeTypeSubst.weaken (lookup x s) || ≡⟨ TypeSubstSizeLemmas.||weaken-a|| (lookup x s) ⟩ m|| lookup x s || ≡⟨ p x ⟩ 1 ∎ ||a/s|| {m} {ν} (simpl (mvar x)) s p = begin m|| (simpl (mvar x)) / s || ≡⟨ cong m||_|| (MetaTypeTypeLemmas.var-/ {x = x}) ⟩ m|| lookup x s || ≡⟨ p x ⟩ 1 ∎ ||a/s|| (simpl (tvar x)) s p = refl ||a/s|| (simpl (a →' b)) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p) ||a/s|| (simpl (tc c)) s p = refl ||open-meta-a||≡a : ∀ {m ν} (a : MetaType m (suc ν)) → m|| open-meta a || ≡ m|| a || ||open-meta-a||≡a {m} {ν} a = begin m|| open-meta a || ≡⟨ TypeSubstSizeLemmas.||a/s|| (MMS.weaken a) (MTS.sub (simpl (mvar zero))) lem ⟩ m|| (MMS.weaken a) || ≡⟨ ||weaken-a|| a ⟩ m|| a || ∎ where module MMS = MetaTypeMetaSubst module MTS = MetaTypeTypeSubst lem : ∀ (x : Fin (suc ν)) → m|| lookup x (MetaTypeTypeSubst.sub (simpl (mvar zero))) || ≡ 1 lem zero = refl lem (suc x) = cong m||_|| (MetaTypeTypeLemmas.lookup-sub-↑⋆ {t = (simpl (mvar zero))} zero x) module SubstSizeLemmas where open TypeLemmas mutual ||a|| : ∀ {ν} (a : Type ν) → || a || ≥ 1 ||a|| (simpl (tc x)) = s≤s z≤n ||a|| (simpl (tvar n)) = s≤s z≤n ||a|| (simpl (a →' b)) = s≤s z≤n ||a|| (a ⇒ b) = s≤s z≤n ||a|| (∀' a) = s≤s z≤n ||a/Var|| : ∀ {ν μ} (a : Type ν) (s : Sub Fin ν μ) → || a /Var s || ≡ || a || ||a/Var|| (a ⇒ b) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s) ||a/Var|| (∀' a) s = cong (λ u → 1 + u) (||a/Var|| a (s VarSubst.↑)) ||a/Var|| (simpl (tvar x)) s = refl ||a/Var|| (simpl (a →' b)) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s) ||a/Var|| (simpl (tc c)) s = refl ||weaken-a|| : ∀ {ν} (a : Type ν) → || weaken a || ≡ || a || ||weaken-a|| {ν} a = begin || weaken a || ≡⟨ refl ⟩ || a /Var VarSubst.wk || ≡⟨ ||a/Var|| a VarSubst.wk ⟩ || a || ∎ ||s↑|| : ∀ {ν μ} (s : Sub Type ν μ) → (∀ (x : Fin ν) → || lookup x s || ≡ 1) → ∀ y → || lookup y (s ↑) || ≡ 1 ||s↑|| s p zero = refl ||s↑|| s p (suc y) = begin || lookup y (map weaken s) || ≡⟨ cong ||_|| (sym $ lookup⋆map s weaken y) ⟩ || weaken (lookup y s) || ≡⟨ ||weaken-a|| (lookup y s) ⟩ || (lookup y s) || ≡⟨ p y ⟩ 1 ∎ ||a/s|| : ∀ {ν μ} (a : Type ν) (s : Sub Type ν μ) → (∀ x → || lookup x s || ≡ 1) → || a / s || ≡ || a || ||a/s|| (a ⇒ b) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p) ||a/s|| (∀' a) s p = cong (λ u → 1 + u) (||a/s|| a (s ↑) (||s↑|| s p)) ||a/s|| {m} {ν} (simpl (tvar x)) s p = begin || (simpl (tvar x)) / s || ≡⟨ cong ||_|| (var-/ {x = x}) ⟩ || lookup x s || ≡⟨ p x ⟩ 1 ∎ ||a/s|| (simpl (a →' b)) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p) ||a/s|| (simpl (tc c)) s p = refl ||a/wk↑k|| : ∀ {ν} k (a : Type (k + ν)) → || a / wk ↑⋆ k || ≡ || a || ||a/wk↑k|| k a = ||a/s|| a (wk ↑⋆ k) (λ x → cong ||_|| (lookup-wk-↑⋆ k x)) ||a/s||' : ∀ {ν μ} (a : Type ν) (s : Sub Type ν μ) → || a || ≤ || a / s || ||a/s||' (simpl (tc x)) s = s≤s z≤n ||a/s||' (simpl (tvar n)) s = ||a|| (lookup n s) ||a/s||' (simpl (a →' b)) s = s≤s (<-+ (||a/s||' a s) (||a/s||' b s)) ||a/s||' (a ⇒ b) s = s≤s (<-+ (||a/s||' a s) (||a/s||' b s)) ||a/s||' (∀' b) s = s≤s (||a/s||' b (s TypeSubst.↑)) h||a/s|| : ∀ {ν μ} (a : Type ν) (s : Sub Type ν μ) → (, a) hρ≤ (, a / s) h||a/s|| (simpl (tc x)) s = s≤s z≤n h||a/s|| (simpl (tvar n)) s = ||a|| (proj₂ (lookup n s ◁)) h||a/s|| (simpl (a →' b)) s = s≤s (<-+ (||a/s||' a s) (||a/s||' b s)) h||a/s|| (a ⇒ b) s = h||a/s|| b s h||a/s|| (∀' b) s = h||a/s|| b (s TypeSubst.↑) a-ρ<-∀a : ∀ {n} a → (suc n , a) ρ< (, ∀' a) a-ρ<-∀a _ = ≤-refl b-ρ<-a⇒b : ∀ {ν} (a b : Type ν) → (_ , b) ρ< (_ , a ⇒ b) b-ρ<-a⇒b a b = s≤s (≤-steps || a || ≤-refl) b-hρ≤-a⇒b : ∀ {ν} (a b : Type ν) → (_ , b) hρ≤ (_ , a ⇒ b) b-hρ≤-a⇒b a b = subst (λ u → u ≤ h|| a ⇒ b ||) refl ≤-refl a-m<-∀a : ∀ {m ν} a → (m , suc ν , a) m< (m , ν , ∀' a) a-m<-∀a a = ≤-refl b-m<-a⇒b : ∀ {m ν} a b → (m , ν , b) m< (m , ν , a ⇒ b) b-m<-a⇒b a b = s≤s (≤-steps m|| a || ≤-refl) open-meta-a-m<-∀'a : ∀ {m ν} a → (suc m , ν , open-meta a) m< (m , ν , ∀' a) open-meta-a-m<-∀'a a = subst (λ x → x < m|| ∀' a ||) (sym $ MetaSubstSizeLemmas.||open-meta-a||≡a a) (a-m<-∀a a)
{ "alphanum_fraction": 0.4380905512, "avg_line_length": 38.7786259542, "ext": "agda", "hexsha": "b06c1a6af3c7f6fc8230055b4301c292fbf2af54", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/Implicits/Resolution/Termination/Lemmas/SizeMeasures.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/Implicits/Resolution/Termination/Lemmas/SizeMeasures.agda", "max_line_length": 101, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Implicits/Resolution/Termination/Lemmas/SizeMeasures.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "num_tokens": 4374, "size": 10160 }
module Thesis.ANormalCTerm where open import Thesis.ANormalDTerm -- OK, this is all cool, but let's drop all this typing. data CType : Set where cache : CType input : Type → CType open import Data.Product ⟦_⟧CType : CType → Set -- This is a lie, since we might need to store more complex values in there, -- including caches... ⟦ cache ⟧CType = Σ[ τ ∈ Type ] ⟦ τ ⟧Type -- However, this is more correct but is not recognized as terminating. -- ⟦ cache ⟧CType = Σ[ τ ∈ CType ] ⟦ τ ⟧CType -- Finally, this definition is too impredicative for Agda to accept it. If -- ⟦_⟧CType lived in Set₁, it could still not contain values of itself. -- ⟦ cache ⟧CType = Σ[ S ∈ Set ] S ⟦ input τ ⟧CType = ⟦ τ ⟧Type -- Maybe step-indexing to the rescue. Really not sure how to step-index the theorems? -- Maybe compute the needed index while running the base program? open import Data.Nat ⟦_⟧CTypeN : CType → ℕ → Set ⟦ input τ ⟧CTypeN n = ⟦ τ ⟧Type ⟦ cache ⟧CTypeN 0 = ⊤ ⟦ cache ⟧CTypeN (suc n) = Σ[ τ ∈ CType ] ⟦ τ ⟧CTypeN n -- To top it off, maybe add constructor tcache : CType × ℕ → Type t? Hm, guess -- that would loop. Just use big-step semantics then. open import Base.Syntax.Context CType using () renaming (Context to CCtx) open import Base.Denotation.Environment CType ⟦_⟧CType using () renaming (⟦_⟧Context to ⟦_⟧CCtx) -- I must merge caches and normal types. So I must step-index types? data CTerm : (C CFin : CCtx) (Δ : Context) (τ : Type) → Set where cvar : ∀ {CFin Δ τ} (x : Var Δ τ) → CTerm CFin CFin Δ τ clett : ∀ {C CFin Δ τ σ τ₁} → (f : Var Δ (σ ⇒ τ₁)) → -- XXX: (f : Var Δ (σ ⇒ (pair τ₁ cache))) → (x : Var Δ σ) → -- XXX pretend we only store integers. We should instead use a separate type of caches. (ct : CTerm (cache • C) CFin (τ₁ • Δ) τ) → CTerm C CFin Δ τ -- Rather bogus: the contexts are unchanged. Our functions have a different type here! ⟦_⟧CTerm : ∀ {C CFin Δ τ} → CTerm C CFin Δ τ → ⟦ Δ ⟧Context → ⟦ C ⟧CCtx → (⟦ τ ⟧Type × ⟦ CFin ⟧CCtx) ⟦ cvar x ⟧CTerm ρ c = ⟦ x ⟧Var ρ , c ⟦ clett f x ct ⟧CTerm ρ c = let v = ⟦ f ⟧Var ρ (⟦ x ⟧Var ρ) in ⟦ ct ⟧CTerm (v • ρ) ((_ , v) • c) cache-term-cps : ∀ {Δ σ} {Z : Set} → (t : Term Δ σ) → ∀ C → (∀ CFin → CTerm C CFin Δ σ → Z) → Z cache-term-cps (var x) C k = k C (cvar x) cache-term-cps (lett f x t) C k = cache-term-cps t (cache • C) (λ CFin ct → k CFin (clett f x ct)) cache-term-Σ : ∀ {Δ σ} → (t : Term Δ σ) → ∀ C → Σ[ CFin ∈ CCtx ] CTerm C CFin Δ σ cache-term-Σ (var x) CFin = CFin , cvar x cache-term-Σ (lett f x t) C = let CFin , ct = cache-term-Σ t (cache • C) in CFin , clett f x ct -- clett f x (cache-term t) -- -- ⟦_⟧CType : Type → Context → Set -- -- ⟦ σ ⇒ τ ⟧CType C = {!!} -- -- ⟦ pair σ τ ⟧CType C = {!!} -- -- ⟦ sum σ τ ⟧CType C = {!!} -- -- ⟦ unit ⟧CType C = ⟦ unit ⟧Type × ⟦ C ⟧Context -- -- ⟦ int ⟧CType C = {!!} -- data CFun (C CFin : Context) : (Δ : Context) (τ : Type) → Set where -- cabs : ∀ {σ τ Δ} → CFun (σ • C) CFin (σ • Δ) τ → CFun C CFin Δ (σ ⇒ τ) -- cterm : ∀ {τ Δ} → CTerm C CFin Δ τ → CFun C CFin Δ τ -- -- Ouch, this is a lie.... We'd need a different type structure. -- ⟦_⟧CFun : ∀ {C CFin Δ τ} → CFun C CFin Δ τ → ⟦ Δ ⟧Context → ⟦ C ⟧Context → (⟦ τ ⟧Type × ⟦ CFin ⟧Context) -- ⟦ cabs cf ⟧CFun ρ c = (λ v → proj₁ (⟦ cf ⟧CFun (v • ρ) (v • c))) , {!!} -- ⟦ cterm ct ⟧CFun ρ c = ⟦ ct ⟧CTerm ρ c -- ⟦_⟧CFun2 : ∀ {C CFin Δ σ τ} → CFun C CFin Δ (σ ⇒ τ) → ⟦ Δ ⟧Context → ⟦ C ⟧Context → ⟦ σ ⟧Type → (⟦ τ ⟧Type × ⟦ CFin ⟧Context) -- ⟦ cabs cf ⟧CFun2 ρ c = λ v → (⟦ cf ⟧CFun (v • ρ) (v • c)) -- -- (λ v → proj₁ (⟦ cf ⟧CFun (v • ρ) (v • c))) , {!!} -- ⟦ cterm ct ⟧CFun2 ρ c = {! ⟦ ct ⟧CTerm ρ c!} -- Above we run into the usual problems with nested caching. data CFunR (C CFin : CCtx) : (Δ : Context) (τ : Type) → Set where cabsterm : ∀ {σ τ Δ} → CTerm (input σ • C) CFin (σ • Δ) τ → CFunR C CFin Δ (σ ⇒ τ) ⟦_⟧CFunR : ∀ {C CFin Δ σ τ} → CFunR C CFin Δ (σ ⇒ τ) → ⟦ Δ ⟧Context → ⟦ C ⟧CCtx → ⟦ σ ⟧Type → (⟦ τ ⟧Type × ⟦ CFin ⟧CCtx) ⟦ cabsterm ct ⟧CFunR ρ c v = ⟦ ct ⟧CTerm (v • ρ) (v • c) -- IMPORTANT: Here we need different change types: ΔτC : Type → Type ΔτC (σ ⇒ τ) = ΔτC σ ⇒ ΔτC τ ΔτC unit = unit ΔτC int = int ΔτC (pair σ τ) = pair (ΔτC σ) (ΔτC τ) ΔτC (sum σ τ) = sum (sum (ΔτC σ) (ΔτC τ)) (sum σ τ) ΔΔC : Context → Context ΔΔC ∅ = ∅ ΔΔC (τ • Γ) = ΔτC τ • ΔΔC Γ derive-dcvar : ∀ {Δ σ} → (x : Var Δ σ) → Var (ΔΔC Δ) (ΔτC σ) derive-dcvar this = this derive-dcvar (that x) = that (derive-dcvar x) -- REAL BULLSHIT -- XXX Not accounted for: derivatives also take caches! -- C: accumulated caches. CFin: the ones we have at the end. data CDTerm : (C CFin : CCtx) (Δ : Context) (τ : Type) → Set where cdvar : ∀ {CFin Δ τ} (x : Var (ΔΔC Δ) (ΔτC τ)) → CDTerm CFin CFin Δ τ cdlett : ∀ {C CFin Δ τ σ τ₁} → -- Here, we also need to pass (and update) the RIGHT cache. Otherwise -- there's no point. (df : Var (ΔΔC Δ) (ΔτC (σ ⇒ τ₁))) → (dx : Var (ΔΔC Δ) (ΔτC σ)) → (dt : CDTerm (cache • C) CFin (τ₁ • Δ) τ) → CDTerm C CFin Δ τ der-cache-term-Σ : ∀ {Δ σ} → (t : Term Δ σ) → ∀ C → Σ[ CFin ∈ CCtx ] CDTerm C CFin Δ σ der-cache-term-Σ (var x) CFin = CFin , cdvar (derive-dcvar x) der-cache-term-Σ (lett f x t) C = let CFin , cdt = der-cache-term-Σ t (cache • C) in CFin , cdlett (derive-dcvar f) (derive-dcvar x) cdt --⟦_⟧DTerm : ∀ {Δ τ} → DTerm Δ τ → ⟦ Δ ⟧Context → ⟦ ΔΔ Δ ⟧Context → ⟦ Δt τ ⟧Type ⟦_⟧CDTerm : ∀ {C CFin Δ τ} → CDTerm C CFin Δ τ → ⟦ ΔΔC Δ ⟧Context → ⟦ C ⟧CCtx → (⟦ ΔτC τ ⟧Type × ⟦ CFin ⟧CCtx) ⟦ cdvar x ⟧CDTerm dρ c = ⟦ x ⟧Var dρ , c ⟦ cdlett df dx cdt ⟧CDTerm dρ c = let dv = ⟦ df ⟧Var dρ (⟦ dx ⟧Var dρ) in ⟦ cdt ⟧CDTerm (dv • dρ) ((_ , dv) • c) -- ⟦ cvar x ⟧CTerm ρ c = ⟦ x ⟧Var ρ , c -- ⟦ clett f x ct ⟧CTerm ρ c = -- let v = ⟦ f ⟧Var ρ (⟦ x ⟧Var ρ) -- in ⟦ ct ⟧CTerm (v • ρ) ((_ , v) • c) -- At the top, C is empty. data CDFun (C CFin : CCtx) : (Δ : Context) (τ : Type) → Set where cdabs : ∀ {σ τ Δ} → CDFun (input σ • C) CFin (σ • Δ) τ → CDFun C CFin Δ (σ ⇒ τ) cdterm : ∀ {τ Δ} → CDTerm C CFin Δ τ → CDFun C CFin Δ τ data CDFunR (C CFin : CCtx) : (Δ : Context) (τ : Type) → Set where cdabsterm : ∀ {σ τ Δ} → CDTerm (input σ • C) CFin (σ • Δ) τ → CDFunR C CFin Δ (σ ⇒ τ)
{ "alphanum_fraction": 0.5712898527, "avg_line_length": 41.4697986577, "ext": "agda", "hexsha": "73f045b587dfae650715bd5820afbba8f6efa08b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Thesis/ANormalCTerm.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Thesis/ANormalCTerm.agda", "max_line_length": 128, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Thesis/ANormalCTerm.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 2706, "size": 6179 }
module Int where open import Data.Product open import Data.Sum as S open import Relation.Binary.PropositionalEquality as Eq open import Relation.Binary.Core open import Relation.Binary open import Function.Equality hiding (cong) open import Data.Empty import Level open import Nat open Eq.≡-Reasoning ℤb : Set ℤb = ℕ × ℕ _≡ℤ_ : ℤb → ℤb → Set (a , b) ≡ℤ (c , d) = a + d ≡ b + c reflexive : {x : ℤb} → x ≡ℤ x reflexive {a , b} = +-comm a b symmetric : (x y : ℤb) → x ≡ℤ y → y ≡ℤ x symmetric (a , b) (c , d) a+d≡b+c = begin c + b ≡⟨ +-comm c b ⟩ b + c ≡⟨ sym a+d≡b+c ⟩ a + d ≡⟨ +-comm a d ⟩ d + a ∎ transitive : ∀ {x y z : ℤb} → x ≡ℤ y → y ≡ℤ z → x ≡ℤ z transitive {a , b} {c , d} {e , f} a+d≡b+c c+f≡d+e = lem (begin a + ((d + c) + f) ≡⟨ cong (λ x → a + x) (sym (+-assoc d c f)) ⟩ a + (d + (c + f)) ≡⟨ +-assoc a d (c + f) ⟩ (a + d) + (c + f) ≡⟨ cong (λ x → x + (c + f)) a+d≡b+c ⟩ (b + c) + (c + f) ≡⟨ cong (λ x → (b + c) + x) c+f≡d+e ⟩ (b + c) + (d + e) ≡⟨ sym (+-assoc b c (d + e)) ⟩ b + (c + (d + e)) ≡⟨ cong (λ x → b + x) (+-assoc c d e) ⟩ b + ((c + d) + e) ∎) where lem : (a + ((d + c) + f)) ≡ (b + ((c + d) + e)) → (a + f) ≡ (b + e) lem p = +-rCancel (a + f) (b + e) (d + c) (begin (a + f) + (d + c) ≡⟨ sym (+-assoc a f (d + c)) ⟩ a + (f + (d + c)) ≡⟨ cong (λ x → a + x) (+-comm f (d + c)) ⟩ a + ((d + c) + f) ≡⟨ p ⟩ b + ((c + d) + e) ≡⟨ cong (λ x → b + x) (cong (λ x → x + e) (+-comm c d)) ⟩ b + ((d + c) + e) ≡⟨ cong (λ x → b + x) (+-comm (d + c) e) ⟩ b + (e + (d + c)) ≡⟨ +-assoc b e (d + c) ⟩ (b + e) + (d + c) ∎) ≡ℤ-eq : IsEquivalence _≡ℤ_ ≡ℤ-eq = record { refl = λ {x} → reflexive {x} ; sym = λ {x y} → symmetric x y ; trans = λ {x y z} → transitive {x} {y} {z} } ℤ : Setoid (Level.zero) (Level.zero) ℤ = record { Carrier = ℤb ; _≈_ = _≡ℤ_ ; isEquivalence = ≡ℤ-eq } ≡ℤ-≡ : {a b : ℤb} → a ≡ b → a ≡ℤ b ≡ℤ-≡ {x , y} {.(x , y)} refl = +-comm x y import Relation.Binary.EqReasoning as EqR open EqR ℤ renaming ( begin_ to beginℤ_ ; _≡⟨_⟩_ to _≡ℤ⟨_⟩_ ; _∎ to _ℤ∎ ) _+ℤ_ : ℤb → ℤb → ℤb (a , b) +ℤ (c , d) = (a + c , b + d) _*ℤ_ : ℤb → ℤb → ℤb (a , b) *ℤ (c , d) = ((a * c) + (b * d) , (a * d) + (b * c)) +ℤ-lUniv : (a b c : ℤb) → a ≡ℤ b → (a +ℤ c) ≡ℤ (b +ℤ c) +ℤ-lUniv (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) a₁+b₂≡a₂+b₁ = lem where lem : (a₁ + c₁) + (b₂ + c₂) ≡ (a₂ + c₂) + (b₁ + c₁) lem = begin (a₁ + c₁) + (b₂ + c₂) ≡⟨ sym (+-assoc a₁ c₁ (b₂ + c₂)) ⟩ a₁ + (c₁ + (b₂ + c₂)) ≡⟨ cong (λ x → a₁ + x) (+-assoc c₁ b₂ c₂) ⟩ a₁ + ((c₁ + b₂) + c₂) ≡⟨ cong (λ x → a₁ + x) (cong (λ x → x + c₂) (+-comm c₁ b₂)) ⟩ a₁ + ((b₂ + c₁) + c₂) ≡⟨ cong (λ x → a₁ + x) (sym (+-assoc b₂ c₁ c₂)) ⟩ a₁ + (b₂ + (c₁ + c₂)) ≡⟨ +-assoc a₁ b₂ (c₁ + c₂) ⟩ (a₁ + b₂) + (c₁ + c₂) ≡⟨ cong (λ x → x + (c₁ + c₂)) a₁+b₂≡a₂+b₁ ⟩ (a₂ + b₁) + (c₁ + c₂) ≡⟨ sym (+-assoc a₂ b₁ (c₁ + c₂)) ⟩ a₂ + (b₁ + (c₁ + c₂)) ≡⟨ cong (λ x → a₂ + x) (+-assoc b₁ c₁ c₂) ⟩ a₂ + ((b₁ + c₁) + c₂) ≡⟨ cong (λ x → a₂ + x) (+-comm (b₁ + c₁) c₂) ⟩ a₂ + (c₂ + (b₁ + c₁)) ≡⟨ +-assoc a₂ c₂ (b₁ + c₁) ⟩ (a₂ + c₂) + (b₁ + c₁) ∎ -- c +ℤ a = (c₁ + a₁ , c₂ + a₂) -- c +ℤ b = (c₁ + b₁ , c₂ + b₂) -- (c₁ + a₁) + (c₂ + b₂) ≡ (c₂ + a₂) + (c₁ + b₁) +ℤ-rUniv : (a b c : ℤb) → a ≡ℤ b → (c +ℤ a) ≡ℤ (c +ℤ b) +ℤ-rUniv (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) a₁+b₂≡a₂+b₁ = begin (c₁ + a₁) + (c₂ + b₂) ≡⟨ cong (λ x → (c₁ + a₁) + x) (+-comm c₂ b₂) ⟩ (c₁ + a₁) + (b₂ + c₂) ≡⟨ sym (+-assoc c₁ a₁ (b₂ + c₂)) ⟩ c₁ + (a₁ + (b₂ + c₂)) ≡⟨ cong (λ x → c₁ + x) (+-assoc a₁ b₂ c₂) ⟩ c₁ + ((a₁ + b₂) + c₂) ≡⟨ cong (λ x → c₁ + (x + c₂)) a₁+b₂≡a₂+b₁ ⟩ c₁ + ((a₂ + b₁) + c₂) ≡⟨ +-comm c₁ ((a₂ + b₁) + c₂) ⟩ ((a₂ + b₁) + c₂) + c₁ ≡⟨ cong (λ x → x + c₁) (+-comm (a₂ + b₁) c₂) ⟩ (c₂ + (a₂ + b₁)) + c₁ ≡⟨ sym (+-assoc c₂ (a₂ + b₁) c₁) ⟩ c₂ + ((a₂ + b₁) + c₁) ≡⟨ cong (λ x → c₂ + x) (sym (+-assoc a₂ b₁ c₁)) ⟩ c₂ + (a₂ + (b₁ + c₁)) ≡⟨ cong (λ x → c₂ + (a₂ + x)) (+-comm b₁ c₁) ⟩ c₂ + (a₂ + (c₁ + b₁)) ≡⟨ +-assoc c₂ a₂ (c₁ + b₁) ⟩ (c₂ + a₂) + (c₁ + b₁) ∎ *ℤ-lUniv : (a b c : ℤb) → a ≡ℤ b → (a *ℤ c) ≡ℤ (b *ℤ c) *ℤ-lUniv (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) a₁+b₂≡a₂+b₁ = lem where -- a *ℤ c = (a₁ * c₁ + a₂ * c₂ , a₁ * c₂ + a₂ * c₁) -- b *ℤ c = (b₁ * c₁ + b₂ * c₂ , b₁ * c₂ + b₂ * c₁) lem : ((a₁ * c₁) + (a₂ * c₂)) + ((b₁ * c₂) + (b₂ * c₁)) ≡ ((a₁ * c₂) + (a₂ * c₁)) + ((b₁ * c₁) + (b₂ * c₂)) lem = begin ((a₁ * c₁) + (a₂ * c₂)) + ((b₁ * c₂) + (b₂ * c₁)) ≡⟨ cong (λ x → ((a₁ * c₁) + (a₂ * c₂)) + x) (+-comm (b₁ * c₂) (b₂ * c₁)) ⟩ ((a₁ * c₁) + (a₂ * c₂)) + ((b₂ * c₁) + (b₁ * c₂)) ≡⟨ sym (+-assoc (a₁ * c₁) (a₂ * c₂) ((b₂ * c₁) + (b₁ * c₂))) ⟩ (a₁ * c₁) + ((a₂ * c₂) + ((b₂ * c₁) + (b₁ * c₂))) ≡⟨ cong (λ x → (a₁ * c₁) + x) (+-assoc (a₂ * c₂) (b₂ * c₁) (b₁ * c₂)) ⟩ (a₁ * c₁) + (((a₂ * c₂) + (b₂ * c₁)) + (b₁ * c₂)) ≡⟨ cong (λ x → (a₁ * c₁) + x) (cong (λ x → x + (b₁ * c₂)) (+-comm (a₂ * c₂) (b₂ * c₁))) ⟩ (a₁ * c₁) + (((b₂ * c₁) + (a₂ * c₂)) + (b₁ * c₂)) ≡⟨ cong (λ x → (a₁ * c₁) + x) (sym (+-assoc (b₂ * c₁) (a₂ * c₂) (b₁ * c₂))) ⟩ (a₁ * c₁) + ((b₂ * c₁) + ((a₂ * c₂) + (b₁ * c₂))) ≡⟨ +-assoc (a₁ * c₁) (b₂ * c₁) ((a₂ * c₂) + (b₁ * c₂)) ⟩ ((a₁ * c₁) + (b₂ * c₁)) + ((a₂ * c₂) + (b₁ * c₂)) ≡⟨ cong (λ x → x + ((a₂ * c₂) + (b₁ * c₂))) (sym (+*-rDist a₁ b₂ c₁)) ⟩ ((a₁ + b₂) * c₁) + ((a₂ * c₂) + (b₁ * c₂)) ≡⟨ cong (λ x → ((a₁ + b₂) * c₁) + x) (sym (+*-rDist a₂ b₁ c₂)) ⟩ ((a₁ + b₂) * c₁) + ((a₂ + b₁) * c₂) ≡⟨ cong (λ x → x + ((a₂ + b₁) * c₂)) (cong (λ x → x * c₁) a₁+b₂≡a₂+b₁) ⟩ ((a₂ + b₁) * c₁) + ((a₂ + b₁) * c₂) ≡⟨ cong (λ x → ((a₂ + b₁) * c₁) + x) (cong (λ x → x * c₂) (sym a₁+b₂≡a₂+b₁)) ⟩ ((a₂ + b₁) * c₁) + ((a₁ + b₂) * c₂) ≡⟨ cong (λ x → x + ((a₁ + b₂) * c₂)) (+*-rDist a₂ b₁ c₁) ⟩ ((a₂ * c₁) + (b₁ * c₁)) + ((a₁ + b₂) * c₂) ≡⟨ cong (λ x → ((a₂ * c₁) + (b₁ * c₁)) + x) (+*-rDist a₁ b₂ c₂) ⟩ ((a₂ * c₁) + (b₁ * c₁)) + ((a₁ * c₂) + (b₂ * c₂)) ≡⟨ sym (+-assoc (a₂ * c₁) (b₁ * c₁) ((a₁ * c₂) + (b₂ * c₂))) ⟩ (a₂ * c₁) + ((b₁ * c₁) + ((a₁ * c₂) + (b₂ * c₂))) ≡⟨ cong (λ x → (a₂ * c₁) + x) (+-assoc (b₁ * c₁) (a₁ * c₂) (b₂ * c₂)) ⟩ (a₂ * c₁) + (((b₁ * c₁) + (a₁ * c₂)) + (b₂ * c₂)) ≡⟨ cong (λ x → (a₂ * c₁) + x) (cong (λ x → x + (b₂ * c₂)) (+-comm (b₁ * c₁) (a₁ * c₂))) ⟩ (a₂ * c₁) + (((a₁ * c₂) + (b₁ * c₁)) + (b₂ * c₂)) ≡⟨ cong (λ x → (a₂ * c₁) + x) (sym (+-assoc (a₁ * c₂) (b₁ * c₁) (b₂ * c₂))) ⟩ (a₂ * c₁) + ((a₁ * c₂) + ((b₁ * c₁) + (b₂ * c₂))) ≡⟨ +-assoc (a₂ * c₁) (a₁ * c₂) ((b₁ * c₁) + (b₂ * c₂)) ⟩ ((a₂ * c₁) + (a₁ * c₂)) + ((b₁ * c₁) + (b₂ * c₂)) ≡⟨ cong (λ x → x + ((b₁ * c₁) + (b₂ * c₂))) (+-comm (a₂ * c₁) (a₁ * c₂)) ⟩ ((a₁ * c₂) + (a₂ * c₁)) + ((b₁ * c₁) + (b₂ * c₂)) ∎ -- c *ℤ a = (c₁ * a₁) + (c₂ * a₂) , (c₁ * a₂) + (c₂ * a₁) -- c *ℤ b = (c₁ * b₁) + (c₂ * b₂) , (c₁ * b₂) + (c₂ * b₁) *ℤ-rUniv : (a b c : ℤb) → a ≡ℤ b → (c *ℤ a) ≡ℤ (c *ℤ b) *ℤ-rUniv (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) a₁+b₂≡a₂+b₁ = begin ((c₁ * a₁) + (c₂ * a₂)) + ((c₁ * b₂) + (c₂ * b₁)) ≡⟨ +-assoc ((c₁ * a₁) + (c₂ * a₂)) (c₁ * b₂) (c₂ * b₁) ⟩ (((c₁ * a₁) + (c₂ * a₂)) + (c₁ * b₂)) + (c₂ * b₁) ≡⟨ cong (λ x → x + (c₂ * b₁)) (sym (+-assoc (c₁ * a₁) (c₂ * a₂) (c₁ * b₂))) ⟩ ((c₁ * a₁) + ((c₂ * a₂) + (c₁ * b₂))) + (c₂ * b₁) ≡⟨ cong (λ z → ((c₁ * a₁) + z) + (c₂ * b₁)) (+-comm (c₂ * a₂) (c₁ * b₂)) ⟩ ((c₁ * a₁) + ((c₁ * b₂) + (c₂ * a₂))) + (c₂ * b₁) ≡⟨ cong (λ z → z + (c₂ * b₁)) (+-assoc (c₁ * a₁) (c₁ * b₂) (c₂ * a₂)) ⟩ (((c₁ * a₁) + (c₁ * b₂)) + (c₂ * a₂)) + (c₂ * b₁) ≡⟨ sym (+-assoc ((c₁ * a₁) + (c₁ * b₂)) (c₂ * a₂) (c₂ * b₁)) ⟩ ((c₁ * a₁) + (c₁ * b₂)) + ((c₂ * a₂) + (c₂ * b₁)) ≡⟨ cong (λ z → z + ((c₂ * a₂) + (c₂ * b₁))) (sym (+*-lDist a₁ b₂ c₁)) ⟩ (c₁ * (a₁ + b₂)) + ((c₂ * a₂) + (c₂ * b₁)) ≡⟨ cong (λ z → (c₁ * (a₁ + b₂)) + z) (sym (+*-lDist a₂ b₁ c₂)) ⟩ (c₁ * (a₁ + b₂)) + (c₂ * (a₂ + b₁)) ≡⟨ cong (λ z → (c₁ * z) + (c₂ * (a₂ + b₁))) a₁+b₂≡a₂+b₁ ⟩ (c₁ * (a₂ + b₁)) + (c₂ * (a₂ + b₁)) ≡⟨ cong (λ z → (c₁ * (a₂ + b₁)) + (c₂ * z)) (sym a₁+b₂≡a₂+b₁) ⟩ (c₁ * (a₂ + b₁)) + (c₂ * (a₁ + b₂)) ≡⟨ cong (λ z → z + (c₂ * (a₁ + b₂))) (+*-lDist a₂ b₁ c₁) ⟩ ((c₁ * a₂) + (c₁ * b₁)) + (c₂ * (a₁ + b₂)) ≡⟨ cong (λ z → ((c₁ * a₂) + (c₁ * b₁)) + z) (+*-lDist a₁ b₂ c₂) ⟩ ((c₁ * a₂) + (c₁ * b₁)) + ((c₂ * a₁) + (c₂ * b₂)) ≡⟨ sym (+-assoc (c₁ * a₂) (c₁ * b₁) ((c₂ * a₁) + (c₂ * b₂))) ⟩ (c₁ * a₂) + ((c₁ * b₁) + ((c₂ * a₁) + (c₂ * b₂))) ≡⟨ cong (λ z → (c₁ * a₂) + z) (+-assoc (c₁ * b₁) (c₂ * a₁) (c₂ * b₂)) ⟩ (c₁ * a₂) + (((c₁ * b₁) + (c₂ * a₁)) + (c₂ * b₂)) ≡⟨ cong (λ z → (c₁ * a₂) + (z + (c₂ * b₂))) (+-comm (c₁ * b₁) (c₂ * a₁)) ⟩ (c₁ * a₂) + (((c₂ * a₁) + (c₁ * b₁)) + (c₂ * b₂)) ≡⟨ cong (λ z → (c₁ * a₂) + z) (sym (+-assoc (c₂ * a₁) (c₁ * b₁) (c₂ * b₂))) ⟩ (c₁ * a₂) + ((c₂ * a₁) + ((c₁ * b₁) + (c₂ * b₂))) ≡⟨ +-assoc (c₁ * a₂) (c₂ * a₁) ((c₁ * b₁) + (c₂ * b₂)) ⟩ ((c₁ * a₂) + (c₂ * a₁)) + ((c₁ * b₁) + (c₂ * b₂)) ∎ +ℤ-rUnit : (a b : ℕ) → ((a , b) +ℤ (zero , zero)) ≡ (a , b) +ℤ-rUnit a b = begin (a , b) +ℤ (zero , zero) ≡⟨ refl ⟩ (a + zero , b + zero) ≡⟨ cong (λ x → x , (b + zero)) (+-rUnit a) ⟩ (a , b + zero) ≡⟨ cong (λ x → a , x) (+-rUnit b) ⟩ (a , b) ∎ +ℤ-lUnit : (a b : ℕ) → ((zero , zero) +ℤ (a , b)) ≡ (a , b) +ℤ-lUnit a b = begin (zero , zero) +ℤ (a , b) ≡⟨ refl ⟩ (zero + a , zero + b) ≡⟨ refl ⟩ (a , b) ∎ -- (a , b) *ℤ (succ zero , zero) = (a * succ zero + b * zero , a * zero + b * succ zero) -- a + (a * zero + b * succ zero) = b + (a * succ zero + b * zero) *ℤ-rUnit : (a b : ℕ) → ((a , b) *ℤ (succ zero , zero)) ≡ (a , b) *ℤ-rUnit a b = begin ((a * succ zero) + (b * zero) , ((a * zero) + (b * succ zero))) ≡⟨ cong (λ x → x , ((a * zero) + (b * succ zero))) lem1 ⟩ (a , ((a * zero) + (b * succ zero))) ≡⟨ cong (λ x → a , x) lem2 ⟩ (a , b) ∎ where lem1 : (a * succ zero) + (b * zero) ≡ a lem1 = begin (a * succ zero) + (b * zero) ≡⟨ cong (λ x → x + (b * zero)) (*-rUnit a) ⟩ a + (b * zero) ≡⟨ cong (λ x → a + x) (*-rAbsorp b) ⟩ a + zero ≡⟨ +-rUnit a ⟩ a ∎ lem2 : (a * zero) + (b * succ zero) ≡ b lem2 = begin (a * zero) + (b * succ zero) ≡⟨ cong (λ x → (a * zero) + x) (*-rUnit b) ⟩ (a * zero) + b ≡⟨ cong (λ x → x + b) (*-rAbsorp a) ⟩ zero + b ≡⟨ refl ⟩ b ∎ -- ((succ zero * a) + (zero * b) , (succ zero * b) + (zero * a)) *ℤ-lUnit : (a b : ℕ) → ((succ zero , zero) *ℤ (a , b)) ≡ (a , b) *ℤ-lUnit a b = begin ((succ zero * a) + (zero * b) , (succ zero * b) + (zero * a)) ≡⟨ cong (λ x → x , ((succ zero * b) + (zero * a))) lem1 ⟩ (a , (succ zero * b) + (zero * a)) ≡⟨ cong (λ x → a , x) lem2 ⟩ (a , b) ∎ where lem1 : (succ zero * a) + (zero * b) ≡ a lem1 = begin (succ zero * a) + (zero * b) ≡⟨ cong (λ x → x + (zero * b)) (*-lUnit a) ⟩ a + (zero * b) ≡⟨ cong (λ x → a + x) refl ⟩ a + zero ≡⟨ +-rUnit a ⟩ a ∎ lem2 : (succ zero * b) + (zero * a) ≡ b lem2 = begin (succ zero * b) + (zero * a) ≡⟨ cong (λ x → x + (zero * a)) (*-lUnit b) ⟩ b + (zero * a) ≡⟨ cong (λ x → b + x) refl ⟩ b + zero ≡⟨ +-rUnit b ⟩ b ∎ -- (b +ℤ c) = (b₁ + c₁) , (b₂ + c₂) -- a +ℤ (b +ℤ c) = a₁ + (b₁ + c₁) , a₂ + (b₂ + c₂) -- (a +ℤ b) = a₁ + b₁ , a₂ + b₂ -- (a +ℤ b) + c = (a₁ + b₁) + c₁ , (a₂ + b₂) + c₂ -- (a₁ + (b₁ + c₁)) + ((a₂ + b₂) + c₂) ≡ (a₂ + (b₂ + c₂)) + ((a₁ + b₁) + c₁) +ℤ-assoc : (a b c : ℤb) → (a +ℤ (b +ℤ c)) ≡ℤ ((a +ℤ b) +ℤ c) +ℤ-assoc (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) = begin (a₁ + (b₁ + c₁)) + ((a₂ + b₂) + c₂) ≡⟨ +-comm (a₁ + (b₁ + c₁)) ((a₂ + b₂) + c₂) ⟩ ((a₂ + b₂) + c₂) + (a₁ + (b₁ + c₁)) ≡⟨ cong (λ x → x + (a₁ + (b₁ + c₁))) (sym (+-assoc a₂ b₂ c₂)) ⟩ (a₂ + (b₂ + c₂)) + (a₁ + (b₁ + c₁)) ≡⟨ cong (λ x → (a₂ + (b₂ + c₂)) + x) (+-assoc a₁ b₁ c₁) ⟩ (a₂ + (b₂ + c₂)) + ((a₁ + b₁) + c₁) ∎ -- a +ℤ b = a + c , b + d -- b +ℤ a = c + a , d + b -- (a + c) + (d + b) = (b + d) + (c + a) +ℤ-comm : (a b : ℤb) → (a +ℤ b) ≡ℤ (b +ℤ a) +ℤ-comm (a , b) (c , d) = begin (a + c) + (d + b) ≡⟨ +-comm (a + c) (d + b) ⟩ (d + b) + (a + c) ≡⟨ cong (λ x → x + (a + c)) (+-comm d b) ⟩ (b + d) + (a + c) ≡⟨ cong (λ x → (b + d) + x) (+-comm a c) ⟩ (b + d) + (c + a) ∎ -- b *ℤ c = (b₁ * c₁) + (b₂ * c₂) , (b₁ * c₂) + (b₂ * c₁) -- a *ℤ (b *ℤ c) = (a₁ * ((b₁ * c₁) + (b₂ * c₂))) + (a₂ * ((b₁ * c₂) + (b₂ * c₁))) -- , (a₁ * ((b₁ * c₂) + (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂))) -- a *ℤ b = (a₁ * b₁) + (a₂ * b₂) , (a₁ * b₂) + (a₂ * b₁) -- (a *ℤ b) *ℤ c = (((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) + (a₂ * b₁)) * c₂) -- , (((a₁ * b₂) + (a₂ * b₁)) * c₁) + (((a₁ * b₁) + (a₂ * b₂)) * c₂) -- (a₁ * ((b₁ * c₁) + (b₂ * c₂))) + (a₂ * ((b₁ * c₂) + (b₂ * c₁))) -- + (((a₁ * b₂) + (a₂ * b₁)) * c₁) + (((a₁ * b₁) + (a₂ * b₂)) * c₂) -- ≡ -- (a₁ * ((b₁ * c₂) + (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂))) -- + (((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) + (a₂ * b₁)) * c₂) *ℤ-assoc : (a b c : ℤb) → (a *ℤ (b *ℤ c)) ≡ℤ ((a *ℤ b) *ℤ c) *ℤ-assoc a@(a₁ , a₂) b@(b₁ , b₂) c@(c₁ , c₂) = ≡ℤ-≡ (begin a *ℤ (b *ℤ c) ≡⟨ cong (λ x → a *ℤ x) refl ⟩ a *ℤ ((b₁ * c₁) + (b₂ * c₂) , (b₁ * c₂) + (b₂ * c₁)) ≡⟨ refl ⟩ ((a₁ * ((b₁ * c₁) + (b₂ * c₂))) + (a₂ * ((b₁ * c₂) + (b₂ * c₁))) , ((a₁ * ((b₁ * c₂) + (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂))))) ≡⟨ cong (λ z → z , (((a₁ * ((b₁ * c₂) + (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂)))))) lem1 ⟩ ((((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) + (a₂ * b₁)) * c₂)) , ((a₁ * ((b₁ * c₂) + (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂)))) ≡⟨ cong (λ z → (((((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) + (a₂ * b₁)) * c₂))) , z) lem2 ⟩ ((((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) + (a₂ * b₁)) * c₂)) , ((((a₁ * b₁) + (a₂ * b₂)) * c₂) + (((a₁ * b₂) + (a₂ * b₁)) * c₁)) ≡⟨ refl ⟩ ((a₁ * b₁) + (a₂ * b₂) , (a₁ * b₂) + (a₂ * b₁)) *ℤ c ≡⟨ cong (λ z → z *ℤ c) t-lem ⟩ (a *ℤ b) *ℤ c ∎) where t-lem : ((a₁ * b₁) + (a₂ * b₂) , (a₁ * b₂) + (a₂ * b₁)) ≡ (a *ℤ b) t-lem = refl lem1 : ((a₁ * ((b₁ * c₁) + (b₂ * c₂))) + (a₂ * ((b₁ * c₂) + (b₂ * c₁)))) ≡ ((((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) + (a₂ * b₁)) * c₂)) lem1 = begin ((a₁ * ((b₁ * c₁) + (b₂ * c₂))) + (a₂ * ((b₁ * c₂) + (b₂ * c₁)))) ≡⟨ cong (λ z → z + (a₂ * ((b₁ * c₂) + (b₂ * c₁)))) (+*-lDist (b₁ * c₁) (b₂ * c₂) a₁) ⟩ ((a₁ * (b₁ * c₁)) + (a₁ * (b₂ * c₂))) + (a₂ * ((b₁ * c₂) + (b₂ * c₁))) ≡⟨ cong (λ z → (((a₁ * (b₁ * c₁)) + (a₁ * (b₂ * c₂)))) + z) (+*-lDist (b₁ * c₂) (b₂ * c₁) a₂) ⟩ ((a₁ * (b₁ * c₁)) + (a₁ * (b₂ * c₂))) + ((a₂ * (b₁ * c₂)) + (a₂ * (b₂ * c₁))) ≡⟨ cong (λ z → (((a₁ * (b₁ * c₁)) + (a₁ * (b₂ * c₂)))) + z) (+-comm (a₂ * (b₁ * c₂)) (a₂ * (b₂ * c₁))) ⟩ ((a₁ * (b₁ * c₁)) + (a₁ * (b₂ * c₂))) + ((a₂ * (b₂ * c₁)) + (a₂ * (b₁ * c₂))) ≡⟨ sym (+-assoc (a₁ * (b₁ * c₁)) (a₁ * (b₂ * c₂)) ((a₂ * (b₂ * c₁)) + (a₂ * (b₁ * c₂)))) ⟩ (a₁ * (b₁ * c₁)) + ((a₁ * (b₂ * c₂)) + (((a₂ * (b₂ * c₁)) + (a₂ * (b₁ * c₂))))) ≡⟨ cong (λ z → (a₁ * (b₁ * c₁)) + z) (+-assoc (a₁ * (b₂ * c₂)) (a₂ * (b₂ * c₁)) (a₂ * (b₁ * c₂))) ⟩ (a₁ * (b₁ * c₁)) + (((a₁ * (b₂ * c₂)) + (a₂ * (b₂ * c₁))) + (a₂ * (b₁ * c₂))) ≡⟨ cong (λ z → (a₁ * (b₁ * c₁)) + (z + (a₂ * (b₁ * c₂)))) (+-comm (a₁ * (b₂ * c₂)) (a₂ * (b₂ * c₁))) ⟩ (a₁ * (b₁ * c₁)) + (((a₂ * (b₂ * c₁)) + (a₁ * (b₂ * c₂))) + (a₂ * (b₁ * c₂))) ≡⟨ cong (λ z → (a₁ * (b₁ * c₁)) + z) (sym (+-assoc (a₂ * (b₂ * c₁)) (a₁ * (b₂ * c₂)) (a₂ * (b₁ * c₂)))) ⟩ (a₁ * (b₁ * c₁)) + ((a₂ * (b₂ * c₁)) + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂)))) ≡⟨ +-assoc (a₁ * (b₁ * c₁)) (a₂ * (b₂ * c₁)) ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂))) ⟩ ((a₁ * (b₁ * c₁)) + (a₂ * (b₂ * c₁))) + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂))) ≡⟨ cong (λ z → (z + (a₂ * (b₂ * c₁))) + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂)))) (*-assoc a₁ b₁ c₁) ⟩ (((a₁ * b₁) * c₁) + (a₂ * (b₂ * c₁))) + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂))) ≡⟨ cong (λ z → (((a₁ * b₁) * c₁) + z) + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂)))) (*-assoc a₂ b₂ c₁) ⟩ (((a₁ * b₁) * c₁) + ((a₂ * b₂) * c₁)) + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂))) ≡⟨ cong (λ z → z + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂)))) (sym (+*-rDist (a₁ * b₁) (a₂ * b₂) c₁)) ⟩ (((a₁ * b₁) + (a₂ * b₂)) * c₁) + ((a₁ * (b₂ * c₂)) + (a₂ * (b₁ * c₂))) ≡⟨ cong (λ z → ((((a₁ * b₁) + (a₂ * b₂)) * c₁)) + (z + (a₂ * (b₁ * c₂)))) (*-assoc a₁ b₂ c₂) ⟩ (((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) * c₂) + (a₂ * (b₁ * c₂))) ≡⟨ cong (λ z → (((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) * c₂) + z)) (*-assoc a₂ b₁ c₂) ⟩ (((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) * c₂) + ((a₂ * b₁) * c₂)) ≡⟨ cong (λ z → ((((a₁ * b₁) + (a₂ * b₂)) * c₁)) + z) (sym (+*-rDist (a₁ * b₂) (a₂ * b₁) c₂)) ⟩ (((a₁ * b₁) + (a₂ * b₂)) * c₁) + (((a₁ * b₂) + (a₂ * b₁)) * c₂) ∎ lem2 : ((a₁ * ((b₁ * c₂) + (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂)))) ≡ ((((a₁ * b₁) + (a₂ * b₂)) * c₂) + (((a₁ * b₂) + (a₂ * b₁)) * c₁)) lem2 = begin (a₁ * ((b₁ * c₂) + (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂))) ≡⟨ cong (λ x → x + (a₂ * ((b₁ * c₁) + (b₂ * c₂)))) (+*-lDist (b₁ * c₂) (b₂ * c₁) a₁) ⟩ ((a₁ * (b₁ * c₂)) + (a₁ * (b₂ * c₁))) + (a₂ * ((b₁ * c₁) + (b₂ * c₂))) ≡⟨ cong (λ x → (((a₁ * (b₁ * c₂)) + (a₁ * (b₂ * c₁)))) + x) (+*-lDist (b₁ * c₁) (b₂ * c₂) a₂) ⟩ ((a₁ * (b₁ * c₂)) + (a₁ * (b₂ * c₁))) + ((a₂ * (b₁ * c₁)) + (a₂ * (b₂ * c₂))) ≡⟨ cong (λ x → (x + ((a₁ * (b₂ * c₁)))) + (((a₂ * (b₁ * c₁)) + (a₂ * (b₂ * c₂))))) (*-assoc a₁ b₁ c₂) ⟩ (((a₁ * b₁) * c₂) + (a₁ * (b₂ * c₁))) + ((a₂ * (b₁ * c₁)) + (a₂ * (b₂ * c₂))) ≡⟨ cong (λ x → ((((a₁ * b₁) * c₂)) + x) + (((a₂ * (b₁ * c₁)) + (a₂ * (b₂ * c₂))))) (*-assoc a₁ b₂ c₁) ⟩ (((a₁ * b₁) * c₂) + ((a₁ * b₂) * c₁)) + ((a₂ * (b₁ * c₁)) + (a₂ * (b₂ * c₂))) ≡⟨ cong (λ x → ((((a₁ * b₁) * c₂) + ((a₁ * b₂) * c₁))) + (x + (a₂ * (b₂ * c₂)))) (*-assoc a₂ b₁ c₁) ⟩ (((a₁ * b₁) * c₂) + ((a₁ * b₂) * c₁)) + (((a₂ * b₁) * c₁) + (a₂ * (b₂ * c₂))) ≡⟨ cong (λ x → ((((a₁ * b₁) * c₂) + ((a₁ * b₂) * c₁))) + (((a₂ * b₁) * c₁) + x)) (*-assoc a₂ b₂ c₂) ⟩ (((a₁ * b₁) * c₂) + ((a₁ * b₂) * c₁)) + (((a₂ * b₁) * c₁) + ((a₂ * b₂) * c₂)) ≡⟨ sym (+-assoc ((a₁ * b₁) * c₂) ((a₁ * b₂) * c₁) (((a₂ * b₁) * c₁) + ((a₂ * b₂) * c₂))) ⟩ ((a₁ * b₁) * c₂) + (((a₁ * b₂) * c₁) + (((a₂ * b₁) * c₁) + ((a₂ * b₂) * c₂))) ≡⟨ cong (λ x → (((a₁ * b₁) * c₂)) + x) (+-assoc ((a₁ * b₂) * c₁) ((a₂ * b₁) * c₁) ((a₂ * b₂) * c₂)) ⟩ ((a₁ * b₁) * c₂) + ((((a₁ * b₂) * c₁) + ((a₂ * b₁) * c₁)) + ((a₂ * b₂) * c₂)) ≡⟨ cong (λ x → (((a₁ * b₁) * c₂)) + x) (+-comm (((a₁ * b₂) * c₁) + ((a₂ * b₁) * c₁)) ((a₂ * b₂) * c₂)) ⟩ ((a₁ * b₁) * c₂) + (((a₂ * b₂) * c₂) + (((a₁ * b₂) * c₁) + ((a₂ * b₁) * c₁))) ≡⟨ +-assoc ((a₁ * b₁) * c₂) ((a₂ * b₂) * c₂) (((a₁ * b₂) * c₁) + ((a₂ * b₁) * c₁)) ⟩ (((a₁ * b₁) * c₂) + ((a₂ * b₂) * c₂)) + (((a₁ * b₂) * c₁) + ((a₂ * b₁) * c₁)) ≡⟨ cong (λ x → x + (((a₁ * b₂) * c₁) + ((a₂ * b₁) * c₁))) (sym (+*-rDist (a₁ * b₁) (a₂ * b₂) c₂)) ⟩ (((a₁ * b₁) + (a₂ * b₂)) * c₂) + (((a₁ * b₂) * c₁) + ((a₂ * b₁) * c₁)) ≡⟨ cong (λ x → ((((a₁ * b₁) + (a₂ * b₂)) * c₂)) + x) (sym (+*-rDist (a₁ * b₂) (a₂ * b₁) c₁)) ⟩ (((a₁ * b₁) + (a₂ * b₂)) * c₂) + (((a₁ * b₂) + (a₂ * b₁)) * c₁) ∎ -- a *ℤ b = a₁ * b₁ + a₂ * b₂ , a₁ * b₂ + a₂ * b₁ -- b *ℤ a = b₁ * a₁ + b₂ * a₂ , b₁ * a₂ + b₂ * a₁ *ℤ-comm : (a b : ℤb) → (a *ℤ b) ≡ℤ (b *ℤ a) *ℤ-comm (a₁ , a₂) (b₁ , b₂) = begin ((a₁ * b₁) + (a₂ * b₂)) + ((b₁ * a₂) + (b₂ * a₁)) ≡⟨ +-comm ((a₁ * b₁) + (a₂ * b₂)) ((b₁ * a₂) + (b₂ * a₁)) ⟩ ((b₁ * a₂) + (b₂ * a₁)) + ((a₁ * b₁) + (a₂ * b₂)) ≡⟨ cong (λ z → z + ((a₁ * b₁) + (a₂ * b₂))) (+-comm (b₁ * a₂) (b₂ * a₁)) ⟩ ((b₂ * a₁) + (b₁ * a₂)) + ((a₁ * b₁) + (a₂ * b₂)) ≡⟨ cong (λ z → (z + (b₁ * a₂)) + ((a₁ * b₁) + (a₂ * b₂))) (*-comm b₂ a₁) ⟩ ((a₁ * b₂) + (b₁ * a₂)) + ((a₁ * b₁) + (a₂ * b₂)) ≡⟨ cong (λ z → ((a₁ * b₂) + z) + ((a₁ * b₁) + (a₂ * b₂))) (*-comm b₁ a₂) ⟩ ((a₁ * b₂) + (a₂ * b₁)) + ((a₁ * b₁) + (a₂ * b₂)) ≡⟨ cong (λ z → ((a₁ * b₂) + (a₂ * b₁)) + (z + (a₂ * b₂))) (*-comm a₁ b₁) ⟩ ((a₁ * b₂) + (a₂ * b₁)) + ((b₁ * a₁) + (a₂ * b₂)) ≡⟨ cong (λ z → ((a₁ * b₂) + (a₂ * b₁)) + ((b₁ * a₁) + z)) (*-comm a₂ b₂) ⟩ ((a₁ * b₂) + (a₂ * b₁)) + ((b₁ * a₁) + (b₂ * a₂)) ∎ ℕ-ℤ : ℕ → ℤb ℕ-ℤ n = (n , zero) ℕ-ℤ-monic : (m n : ℕ) → ℕ-ℤ m ≡ℤ ℕ-ℤ n → m ≡ n ℕ-ℤ-monic m n m+0≡0+n = begin m ≡⟨ sym (+-rUnit m) ⟩ m + zero ≡⟨ m+0≡0+n ⟩ zero + n ≡⟨ refl ⟩ n ∎ -- (n , zero) +ℤ (zero , n) = n + zero , zero + n -- (n + zero) + zero = (zero + n) + zero +ℤ-invℕ : (n : ℕ) → ((n , zero) +ℤ (zero , n)) ≡ℤ (zero , zero) +ℤ-invℕ n = begin (n + zero) + zero ≡⟨ cong (λ x → x + zero) (+-comm n zero) ⟩ (zero + n) + zero ∎ -- (a , b) +ℤ (b , a) = a + b , b + a -- (a + b) + zero = (b + a) + zero +ℤ-inv : (a : ℤb) → ∃ λ b → (a +ℤ b) ≡ℤ (zero , zero) +ℤ-inv (a , b) = (b , a) , (begin (a + b) + zero ≡⟨ cong (λ x → x + zero) (+-comm a b) ⟩ (b + a) + zero ∎) -ℤ_ : ℤb → ℤb -ℤ (a , b) = (b , a) _-ℤ_ : ℤb → ℤb → ℤb a -ℤ b = a +ℤ (-ℤ b) -ℤ-inv : (a : ℤb) → (a -ℤ a) ≡ℤ (zero , zero) -ℤ-inv (a , b) = begin (a + b) + zero ≡⟨ cong (λ x → x + zero) (+-comm a b) ⟩ (b + a) + zero ∎ _≤ℤ_ : ℤb → ℤb → Set a ≤ℤ b = ∃ λ l → (a +ℤ (l , zero)) ≡ℤ b ≤ℤ-refl : (a : ℤb) → a ≤ℤ a ≤ℤ-refl (a , b) = zero , ≡ℤ-≡ (+ℤ-rUnit a b) -- p : (a₁ , a₂) +ℤ (x , zero) ≡ℤ (b₁ , b₂) -- (a₁ + x , a₂ + zero) ≡ℤ (b₁ , b₂) -- (a₁ + x) + b₂ = (a₂ + zero) + b₁ -- q : (b₁ , b₂) +ℤ (x , zero) ≡ℤ (c₁ , c₂) -- (b₁ + y , b₂ + zero) ≡ℤ (c₁ , c₂) -- (b₁ + y) + c₂ = (b₂ + zero) + c₁ -- goal : (a₁ , a₂) +ℤ (z , zero) ≡ℤ (c₁ , c₂) -- (a₁ + z , a₂ + zero) ≡ℤ (c₁ , c₂) -- (a₁ + z) + c₂ ≡ (a₂ + zero) + c₁ ≤ℤ-trans : (a b c : ℤb) → a ≤ℤ b → b ≤ℤ c → a ≤ℤ c ≤ℤ-trans (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) (x , p) (y , q) = (x + y) , +-rCancel ((a₁ + (x + y)) + c₂) ((a₂ + zero) + c₁) b₂ (begin ((a₁ + (x + y)) + c₂) + b₂ ≡⟨ cong (λ z → z + b₂) (sym (+-assoc a₁ (x + y) c₂)) ⟩ (a₁ + ((x + y) + c₂)) + b₂ ≡⟨ sym (+-assoc a₁ ((x + y) + c₂) b₂) ⟩ a₁ + (((x + y) + c₂) + b₂) ≡⟨ cong (λ z → a₁ + z) (sym (+-assoc (x + y) c₂ b₂)) ⟩ a₁ + ((x + y) + (c₂ + b₂)) ≡⟨ cong (λ z → a₁ + ((x + y) + z)) (+-comm c₂ b₂) ⟩ a₁ + ((x + y) + (b₂ + c₂)) ≡⟨ cong (λ z → a₁ + z) (sym (+-assoc x y (b₂ + c₂))) ⟩ a₁ + (x + (y + (b₂ + c₂))) ≡⟨ cong (λ z → a₁ + (x + z)) (+-assoc y b₂ c₂) ⟩ a₁ + (x + ((y + b₂) + c₂)) ≡⟨ cong (λ z → a₁ + (x + (z + c₂))) (+-comm y b₂) ⟩ a₁ + (x + ((b₂ + y) + c₂)) ≡⟨ cong (λ z → a₁ + (x + z)) (sym (+-assoc b₂ y c₂)) ⟩ a₁ + (x + (b₂ + (y + c₂))) ≡⟨ +-assoc a₁ x (b₂ + (y + c₂)) ⟩ ((a₁ + x) + (b₂ + (y + c₂))) ≡⟨ +-assoc (a₁ + x) b₂ (y + c₂) ⟩ ((a₁ + x) + b₂) + (y + c₂) ≡⟨ cong (λ z → z + (y + c₂)) p ⟩ ((a₂ + zero) + b₁) + (y + c₂) ≡⟨ sym (+-assoc (a₂ + zero) b₁ (y + c₂)) ⟩ (a₂ + zero) + (b₁ + (y + c₂)) ≡⟨ cong (λ z → (a₂ + zero) + z) (+-assoc b₁ y c₂) ⟩ (a₂ + zero) + ((b₁ + y) + c₂) ≡⟨ cong (λ z → (a₂ + zero) + z) q ⟩ (a₂ + zero) + ((b₂ + zero) + c₁) ≡⟨ cong (λ z → (a₂ + zero) + z) (+-comm (b₂ + zero) c₁) ⟩ (a₂ + zero) + (c₁ + (b₂ + zero)) ≡⟨ cong (λ z → (a₂ + zero) + (c₁ + z)) (+-rUnit b₂) ⟩ (a₂ + zero) + (c₁ + b₂) ≡⟨ +-assoc (a₂ + zero) c₁ b₂ ⟩ ((a₂ + zero) + c₁) + b₂ ∎) -- p : (a₁ + x , a₂ + zero) ≡ℤ (b₁ , b₂) -- (a₁ + x) + b₂ ≡ (a₂ + zero) + b₁ -- q : (b₁ + y , b₂ + zero) ≡ℤ (a₁ , a₂) -- (b₁ + y) + a₂ ≡ (b₂ + zero) + a₁ ≤ℤ-antisym : (a b : ℤb) → a ≤ℤ b → b ≤ℤ a → a ≡ℤ b ≤ℤ-antisym (a₁ , a₂) (b₁ , b₂) (x , p) (y , q) = begin a₁ + b₂ ≡⟨ sym (+-rUnit (a₁ + b₂)) ⟩ (a₁ + b₂) + zero ≡⟨ cong (λ z → (a₁ + b₂) + z) (sym x≡0) ⟩ (a₁ + b₂) + x ≡⟨ sym (+-assoc a₁ b₂ x) ⟩ a₁ + (b₂ + x) ≡⟨ cong (λ z → a₁ + z) (+-comm b₂ x) ⟩ a₁ + (x + b₂) ≡⟨ +-assoc a₁ x b₂ ⟩ (a₁ + x) + b₂ ≡⟨ p ⟩ (a₂ + zero) + b₁ ≡⟨ cong (λ z → z + b₁) (+-rUnit a₂) ⟩ a₂ + b₁ ∎ where x≡0 : x ≡ zero x≡0 = +-lZero x y (+-lCancel (x + y) zero ((a₁ + b₂) + a₂) (begin ((a₁ + b₂) + a₂) + (x + y) ≡⟨ sym (+-assoc (a₁ + b₂) a₂ (x + y)) ⟩ (a₁ + b₂) + (a₂ + (x + y)) ≡⟨ cong (λ x₁ → (a₁ + b₂) + x₁) (+-assoc a₂ x y) ⟩ (a₁ + b₂) + ((a₂ + x) + y) ≡⟨ cong (λ z → (a₁ + b₂) + (z + y)) (+-comm a₂ x) ⟩ (a₁ + b₂) + ((x + a₂) + y) ≡⟨ cong (λ z → (a₁ + b₂) + z) (sym (+-assoc x a₂ y)) ⟩ (a₁ + b₂) + (x + (a₂ + y)) ≡⟨ +-assoc (a₁ + b₂) x (a₂ + y) ⟩ ((a₁ + b₂) + x) + (a₂ + y) ≡⟨ cong (λ z → z + (a₂ + y)) (sym (+-assoc a₁ b₂ x)) ⟩ (a₁ + (b₂ + x)) + (a₂ + y) ≡⟨ cong (λ z → (a₁ + z) + (a₂ + y)) (+-comm b₂ x) ⟩ (a₁ + (x + b₂)) + (a₂ + y) ≡⟨ cong (λ z → z + (a₂ + y)) (+-assoc a₁ x b₂) ⟩ ((a₁ + x) + b₂) + (a₂ + y) ≡⟨ cong (λ z → z + (a₂ + y)) p ⟩ ((a₂ + zero) + b₁) + (a₂ + y) ≡⟨ sym (+-assoc (a₂ + zero) b₁ (a₂ + y)) ⟩ (a₂ + zero) + (b₁ + (a₂ + y)) ≡⟨ cong (λ z → (a₂ + zero) + (b₁ + z)) (+-comm a₂ y) ⟩ (a₂ + zero) + (b₁ + (y + a₂)) ≡⟨ cong (λ z → (a₂ + zero) + z) (+-assoc b₁ y a₂) ⟩ (a₂ + zero) + ((b₁ + y) + a₂) ≡⟨ cong (λ z → (a₂ + zero) + z) q ⟩ (a₂ + zero) + ((b₂ + zero) + a₁) ≡⟨ +-comm (a₂ + zero) ((b₂ + zero) + a₁) ⟩ ((b₂ + zero) + a₁) + (a₂ + zero) ≡⟨ cong (λ z → z + (a₂ + zero)) (+-comm (b₂ + zero) a₁) ⟩ (a₁ + (b₂ + zero)) + (a₂ + zero) ≡⟨ cong (λ z → (a₁ + z) + (a₂ + zero)) (+-rUnit b₂) ⟩ (a₁ + b₂) + (a₂ + zero) ≡⟨ +-assoc (a₁ + b₂) a₂ zero ⟩ ((a₁ + b₂) + a₂) + zero ∎)) -- (a₁ , a₂) ≤ℤ (b₁ , b₂) -- (a₁ + l , a₂ + zero) ≡ℤ (b₁ , b₂) -- (a₁ + l) + b₂ ≡ (a₂ + zero) + b₁ ≤ℤ-all : (a b : ℤb) → a ≤ℤ b ⊎ b ≤ℤ a ≤ℤ-all a@(a₁ , a₂) b@(b₁ , b₂) = S.map lem1 lem2 (≤-all (a₁ + b₂) (a₂ + b₁)) where lem1 : (a₁ + b₂) ≤ (a₂ + b₁) → a ≤ℤ b lem1 (x , p) = x , (begin (a₁ + x) + b₂ ≡⟨ sym (+-assoc a₁ x b₂) ⟩ a₁ + (x + b₂) ≡⟨ cong (λ z → a₁ + z) (+-comm x b₂) ⟩ a₁ + (b₂ + x) ≡⟨ +-assoc a₁ b₂ x ⟩ (a₁ + b₂) + x ≡⟨ p ⟩ a₂ + b₁ ≡⟨ cong (λ z → z + b₁) (sym (+-rUnit a₂)) ⟩ (a₂ + zero) + b₁ ∎) lem2 : (a₂ + b₁) ≤ (a₁ + b₂) → b ≤ℤ a lem2 (x , p) = x , (begin (b₁ + x) + a₂ ≡⟨ sym (+-assoc b₁ x a₂) ⟩ b₁ + (x + a₂) ≡⟨ cong (λ z → b₁ + z) (+-comm x a₂) ⟩ b₁ + (a₂ + x) ≡⟨ +-assoc b₁ a₂ x ⟩ (b₁ + a₂) + x ≡⟨ cong (λ z → z + x) (+-comm b₁ a₂) ⟩ (a₂ + b₁) + x ≡⟨ p ⟩ a₁ + b₂ ≡⟨ +-comm a₁ b₂ ⟩ b₂ + a₁ ≡⟨ cong (λ z → z + a₁) (sym (+-rUnit b₂)) ⟩ (b₂ + zero) + a₁ ∎)
{ "alphanum_fraction": 0.3154308348, "avg_line_length": 44.9336349925, "ext": "agda", "hexsha": "d9174fcbf20c9a7331a4f5ee207fe0caf36194f5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bf1f5ed013ea7072055c061b8458c4f1259b54f5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "karrym/NatToReal", "max_forks_repo_path": "Int.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bf1f5ed013ea7072055c061b8458c4f1259b54f5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "karrym/NatToReal", "max_issues_repo_path": "Int.agda", "max_line_length": 117, "max_stars_count": null, "max_stars_repo_head_hexsha": "bf1f5ed013ea7072055c061b8458c4f1259b54f5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "karrym/NatToReal", "max_stars_repo_path": "Int.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 15465, "size": 29791 }
module Issue215 where open import Imports.Bool {-# COMPILE GHC Bool = data Bool (True | False) #-}
{ "alphanum_fraction": 0.6960784314, "avg_line_length": 14.5714285714, "ext": "agda", "hexsha": "6247c6b804a96535dd0befd2f5e573fd59360adb", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue215.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue215.agda", "max_line_length": 51, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue215.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 25, "size": 102 }
------------------------------------------------------------------------------ -- Example of lambda-lifting ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --universal-quantified-functions #-} {-# OPTIONS --without-K #-} module LambdaLifting where infixl 9 _·_ infix 8 if_then_else_ infix 7 _≡_ infixl 10 _*_ infixl 9 _+_ ------------------------------------------------------------------------------ postulate D : Set zero true false : D succ iszero pred : D → D _·_ : D → D → D if_then_else_ : D → D → D → D lam fix : (D → D) → D data _≡_ (x : D) : D → Set where refl : x ≡ x -- Conversion rules -- Conversion rules for Booleans. postulate if-true : ∀ d₁ {d₂} → if true then d₁ else d₂ ≡ d₁ if-false : ∀ {d₁} d₂ → if false then d₁ else d₂ ≡ d₂ {-# ATP axioms if-true if-false #-} -- Conversion rules for pred. postulate -- N.B. We don't need this equation. -- pred-0 : pred zero ≡ zero pred-S : ∀ d → pred (succ d) ≡ d {-# ATP axiom pred-S #-} -- Conversion rules for iszero. postulate iszero-0 : iszero zero ≡ true iszero-S : ∀ d → iszero (succ d) ≡ false {-# ATP axioms iszero-0 iszero-S #-} -- Conversion rule for the λ-abstraction and the application. postulate beta : ∀ f a → lam f · a ≡ f a {-# ATP axiom beta #-} -- Conversion rule for the fixed-pointed operator. postulate fix-eq : ∀ f → fix f ≡ f (fix f) {-# ATP axiom fix-eq #-} postulate _+_ : D → D → D +-0x : ∀ d → zero + d ≡ d +-Sx : ∀ d e → succ d + e ≡ succ (d + e) {-# ATP axioms +-0x +-Sx #-} postulate _*_ : D → D → D *-0x : ∀ d → zero * d ≡ zero *-Sx : ∀ d e → succ d * e ≡ e + d * e {-# ATP axioms *-0x *-Sx #-} ------------------------------------------------------------------------------ -- The original fach -- fach : D → D -- fach f = lam (λ n → if (iszero n) then (succ zero) else n * (f · (pred n))) -- Lambda-lifting via super-combinators (Hughes. Super-combinators. 1982). α : D → D → D α f n = if (iszero n) then (succ zero) else n * (f · (pred n)) {-# ATP definition α #-} fach : D → D fach f = lam (α f) {-# ATP definition fach #-} fac : D → D fac n = fix fach · n {-# ATP definition fac #-} postulate fac0 : fac zero ≡ succ zero {-# ATP prove fac0 #-} postulate fac1 : fac (succ zero) ≡ succ zero {-# ATP prove fac1 #-} postulate fac2 : fac (succ (succ zero)) ≡ succ (succ zero) {-# ATP prove fac2 #-} ------------------------------------------------------------------------------ -- Ouput: -- -- $ apia -inotes --non-fol-function notes/LambdaLifting.agda -- Proving the conjecture in /tmp/LambdaLifting/95-fac1.tptp ... -- E 1.6 Tiger Hill proved the conjecture in /tmp/LambdaLifting/95-fac1.tptp -- Proving the conjecture in /tmp/LambdaLifting/99-fac2.tptp ... -- E 1.6 Tiger Hill proved the conjecture in /tmp/LambdaLifting/99-fac2.tptp -- Proving the conjecture in /tmp/LambdaLifting/91-fac0.tptp ... -- Vampire 0.6 (revision 903) proved the conjecture in /tmp/LambdaLifting/91-fac0.tptp
{ "alphanum_fraction": 0.5193578848, "avg_line_length": 28.6216216216, "ext": "agda", "hexsha": "884f3c17f515d29f4fb9626c1006ff200783ed4b", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "issues/universal-quantified-functions-option/LambdaLifting.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "issues/universal-quantified-functions-option/LambdaLifting.agda", "max_line_length": 86, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "issues/universal-quantified-functions-option/LambdaLifting.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 969, "size": 3177 }
{-# OPTIONS --without-K #-} module Ch2 where -- open import lib.Base open import Base module Ex2-1 where {- Lemma 2.1.2. For every type A and every x, y, z : A there is a function (x = y) → (y = z) → (x = z) written p → q → p ∙ q, such that reflx ∙ reflx ≡ reflx for any x : A. We call p ∙ q the concatenation or composite of p and q. -} {- Exercise 2.1 Show that the three obvious proofs of Lemma 2.1.2 are pairwise equal. -} -- (proof(s) of 2.1.2 are the inhabitants of the type corresponding to the -- statement of the lemma) {- The versions of concat below WITHOUT the primes 's are proved using Agda's 'internal J rule', whatever that might be. (And there is no --without-J option to turn it off!) In the HoTT-Agda lib, there is a comment that: concat1' and concat3' are proved using ind== which is the closest I could get to free path induction (as in the book), but unfortunately this didn't work out for concat2' which had to use left-based path induction, ie ind=' (J in the HoTT-Agda libs) -} concat1 : ∀ {i} {A : Type i} {x y z : A} → x == y → y == z → x == z concat1 idp q = q concat1' : ∀ {i} {A : Type i} {x y z : A} → x == y → y == z → x == z concat1' {i} {A} {_} {_} {z} = ind== D d where D : (x y : A) → (p : x == y) → Type i D x y _ = y == z → x == z d : (x₁ : A) → D x₁ x₁ idp d _ = λ q → q concat2 : ∀ {i} {A : Type i} {x y z : A} → x == y → y == z → x == z concat2 p idp = p -- uses based path induction, because I couldn't get free path induction to work -- at first concat2' : ∀ {i} {A : Type i} {x y z : A} → x == y → y == z → x == z concat2' {i} {A} {x} {y} {_} p = ind=' D d where D : (z : A) → y == z → Type i D z _ = x == z d : D _ idp d = p -- here is the free path induction version which relies upon a 'twist' of -- the paths p and q in order to 'line up the end points' of the idp base -- case of q (Dustin Mulcahey of HoTT-NYC group noticed this trick) concat2'' : ∀ {i} {A : Type i} {x y z : A} → x == y → y == z → x == z concat2'' {i} {A} {x} {_} {_} p q = ind== D d q p where D : (y z : A) → (q : y == z) → Type i D y z _ = x == y → x == z d : (y : A) → D y y idp d _ = λ p → p concat3 : ∀ {i} {A : Type i} {x y z : A} → x == y → y == z → x == z concat3 idp idp = idp concat3' : ∀ {i} {A : Type i} {x y z : A} → x == y → y == z → x == z concat3' {i} {A} {_} {_} {z} = ind== D d where D : (x y : A) → (p : x == y) → Type i D x y _ = y == z → x == z d : (x₁ : A) → D x₁ x₁ idp d _ = ind== E e where E : (y z : A) (q : y == z) → Type i E y z _ = y == z e : (x : A) → E x x idp e _ = idp concat1=concat2 : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat1 p q == concat2 p q concat1=concat2 idp idp = idp concat1'=concat2' : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat1' p q == concat2' p q concat1'=concat2' {i} {A} {_} {_} {z} = ind== D d where D : (x y : A) → x == y → Type i D _ y p = (q : y == z) → concat1' p q == concat2' p q d : (x : A) → D x x idp d _ = ind== E e where E : (y₁ z₁ : A) → y₁ == z₁ → Type i E _ _ q = concat1' idp q == concat2' idp q e : (x₁ : A) → E x₁ x₁ idp e _ = idp -- : concat1' idp idp == concat2' idp idp ⇓'p' -- > (ind== D1 d1) idp idp == (ind== D2 d2) idp idp -- > (d1 q) idp == (d2 x) idp -- > (λ q → q) idp == 'p' (aka idp) -- > idp == idp -- (this being the type of the inhabitant value idp of e x) concat2=concat3 : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat2 p q == concat3 p q concat2=concat3 idp idp = idp concat2'=concat3' : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat2' p q == concat3' p q concat2'=concat3' {i} {A} {x} {y} {z} = ind== D d where D : (x y : A) → x == y → Type i D _ y p = (q : y == z) → concat2' p q == concat3' p q d : (x : A) → D x x idp d x = ind== E e where E : (y₁ z₁ : A) → y₁ == z₁ → Type i E _ _ q = concat2' idp q == concat3' idp q e : (x₁ : A) → E x₁ x₁ idp e _ = idp -- : concat2' idp idp == concat3' idp idp concat1=concat3 : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat1 p q == concat3 p q concat1=concat3 idp idp = idp concat1'=concat3' : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat1' p q == concat3' p q concat1'=concat3' {i} {A} {_} {_} {z} = ind== D d where D : (x y : A) → x == y → Type i D x y p = (q : y == z) → concat1' p q == concat3' p q d : (x : A) → D x x idp d _ = ind== E e where E : (y z : A) → (q : y == z) → Type i E _ _ q = concat1' idp q == concat3' idp q e : (y : A) → E y y idp e _ = idp -- : concat1' idp idp == concat3' idp idp module Ex2-2 where open Ex2-1 {- Show that the three equalities of proofs constructed in the previous exercise form a commutative triangle. In other words, if the three definitions of concatenation are denoted by (p 􏰂1 q), (p 􏰂2 q), and (p 􏰂3 q), then the concatenated equality (p 􏰂1 q) = (p 􏰂2 q) = (p 􏰂3 q) is equal to the equality (p 􏰂1 q) = (p 􏰂3 q). -} -- Choice of which 'concat' we use for the statement of the proof type; we use the book one concat = concat3 concat-commutative-triangle : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat (concat1=concat2 p q) (concat2=concat3 p q) == concat1=concat3 p q concat-commutative-triangle idp idp = idp -- likewise, the ind== version of the book concat operator concat' = concat3' concat-commutative-triangle' : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → concat' (concat1'=concat2' p q) (concat2'=concat3' p q) == concat1'=concat3' p q concat-commutative-triangle' {i} {A} {_} {_} {z} = ind== D d where D : (x y : A) → x == y → Type i D _ y p = (q : y == z) → concat' (concat1'=concat2' p q) (concat2'=concat3' p q) == concat1'=concat3' p q d : (x : A) → D x x idp d _ = ind== E e where E : (y z : A) → (q : y == z) → Type i E _ _ q = concat' (concat1'=concat2' idp q) (concat2'=concat3' idp q) == concat1'=concat3' idp q e : (y : A) → E y y idp e _ = idp -- : concat' (concat1'=concat2' idp idp) (concat2'=concat3' idp idp) == concat1'=concat3' idp idp module Ex2-3 where -- use another of the based path inductions module Ex2-4 where {- Define, by induction on n, a general notion of n-dimensional path in a type A, simultaneously with the type of boundaries for such paths. -}
{ "alphanum_fraction": 0.4888006805, "avg_line_length": 36.7395833333, "ext": "agda", "hexsha": "869e9eb43a92fa8c88a06cc8f2eaecd4bd573576", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "aerskine/hott-ex", "max_forks_repo_path": "Ch2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "aerskine/hott-ex", "max_issues_repo_path": "Ch2.agda", "max_line_length": 113, "max_stars_count": null, "max_stars_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "aerskine/hott-ex", "max_stars_repo_path": "Ch2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2726, "size": 7054 }
{-# OPTIONS --cubical --safe #-} module Algebra.Construct.Free.Semilattice.Relation.Unary.All.Dec where open import Prelude hiding (⊥; ⊤) open import Algebra.Construct.Free.Semilattice.Eliminators open import Algebra.Construct.Free.Semilattice.Definition open import Cubical.Foundations.HLevels open import Data.Empty.UniversePolymorphic open import HITs.PropositionalTruncation.Sugar open import HITs.PropositionalTruncation.Properties open import HITs.PropositionalTruncation open import Data.Unit.UniversePolymorphic open import Algebra.Construct.Free.Semilattice.Relation.Unary.All.Def open import Relation.Nullary open import Relation.Nullary.Decidable open import Relation.Nullary.Decidable.Properties open import Relation.Nullary.Decidable.Logic private variable p : Level ◻′? : ∀ {P : A → Type p} → (∀ x → Dec (P x)) → xs ∈𝒦 A ⇒∥ Dec (◻ P xs) ∥ ∥ ◻′? {P = P} P? ∥-prop {xs} = isPropDec (isProp-◻ {P = P} {xs = xs}) ∥ ◻′? P? ∥[] = yes tt ∥ ◻′? P? ∥ x ∷ xs ⟨ Pxs ⟩ = map-dec ∣_∣ refute-trunc (P? x) && Pxs ◻? : ∀ {P : A → Type p} → (∀ x → Dec (P x)) → ∀ xs → Dec (◻ P xs) ◻? P? = ∥ ◻′? P? ∥⇓
{ "alphanum_fraction": 0.7022624434, "avg_line_length": 36.8333333333, "ext": "agda", "hexsha": "cbd1a50e554eb67b80cd328aaf3c8a506cdaad33", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Dec.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Dec.agda", "max_line_length": 72, "max_stars_count": 6, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Dec.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 382, "size": 1105 }
{-# OPTIONS --cubical #-} open import Agda.Builtin.Cubical.Path -- Works: data Truncate (A : Set) : Set where [_] : A → Truncate A sq : ∀{x y} (p q : PathP (λ _ → Truncate A) x y) → PathP (λ _ → PathP (λ _ → Truncate A) x y) p q data Truncat (A : Set) : Set where [_] : A → Truncat A sq : ∀{x y : Truncat A} (p q : x ≡ y) → p ≡ q -- Fails: data Trunc (A : Set) : Set where [_] : A → Trunc A sq : ∀{x y} (p q : PathP (λ _ → Trunc A) x y) → PathP _ p q -- The failure is expected, but it shouldn't give a non-obligated -- equality constraint as the reason for the failure.
{ "alphanum_fraction": 0.55954323, "avg_line_length": 24.52, "ext": "agda", "hexsha": "5f2d839a16e9a969f4f0d99fee6ffe45ad926f7b", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue3537.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue3537.agda", "max_line_length": 65, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue3537.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 235, "size": 613 }
{- This file contains: - Definition of groupoid truncations -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.GroupoidTruncation.Base where open import Cubical.Core.Primitives -- groupoid truncation as a higher inductive type: data ∥_∥₃ {ℓ} (A : Type ℓ) : Type ℓ where ∣_∣₃ : A → ∥ A ∥₃ squash₃ : ∀ (x y : ∥ A ∥₃) (p q : x ≡ y) (r s : p ≡ q) → r ≡ s
{ "alphanum_fraction": 0.6302083333, "avg_line_length": 21.3333333333, "ext": "agda", "hexsha": "1aaf63dc1f2a696279bc1a16cfdc3e22b8b71a4d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/HITs/GroupoidTruncation/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/HITs/GroupoidTruncation/Base.agda", "max_line_length": 64, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/HITs/GroupoidTruncation/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 150, "size": 384 }
open import Oscar.Prelude open import Oscar.Class open import Oscar.Class.Congruity open import Oscar.Class.Transextensionality open import Oscar.Class.Transitivity open import Oscar.Data.Proposequality import Oscar.Class.Congruity.Proposequality module Oscar.Class.Transextensionality.Proposequality where instance 𝓣ransextensionalityProposequality : ∀ {a} {A : Ø a} {m} {_⊸_ : A → A → Ø m} ⦃ _ : Transitivity.class _⊸_ ⦄ → Transextensionality.class _⊸_ Proposequality transitivity 𝓣ransextensionalityProposequality .⋆ = congruity₂ _
{ "alphanum_fraction": 0.7799642218, "avg_line_length": 27.95, "ext": "agda", "hexsha": "12012a76bb321269dad751cb3db5efe0eaa69529", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Transextensionality/Proposequality.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Transextensionality/Proposequality.agda", "max_line_length": 63, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Transextensionality/Proposequality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 174, "size": 559 }
------------------------------------------------------------------------------ -- Note on the equality type class using instance arguments ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- Adapted from: On the Bright Side of Type Classes: Instances -- Arguments in Agda (ICFP'11). module FOT.FOTC.TypeClasses.EqualityInstanceArguments where open import FOTC.Base open import FOTC.Data.Bool open import FOTC.Data.Bool.Type open import FOTC.Data.Nat.Type ------------------------------------------------------------------------------ ∃-proj₁ : ∀ {A} → ∃ A → D ∃-proj₁ (x , _) = x record Eq (P : D → Set) : Set₁ where field equal : ∀ {t₁ t₂} → P t₁ → P t₂ → Set equal : {P : D → Set}{t₁ t₂ : D} → {{eqT : Eq P}} → P t₁ → P t₂ → Set equal {{eqT}} = Eq.equal eqT boolEq : ∀ {b₁ b₂} → Bool b₁ → Bool b₂ → Set boolEq btrue btrue = Bool true boolEq bfalse bfalse = Bool true {-# CATCHALL #-} boolEq _ _ = Bool false nEq : ∀ {m n} → N m → N n → Set nEq nzero nzero = Bool true nEq (nsucc Nm) (nsucc Nn) = Bool true {-# CATCHALL #-} nEq _ _ = Bool false instance eqInstanceBool : Eq Bool eqInstanceBool = record { equal = boolEq } eqInstanceN : Eq N eqInstanceN = record { equal = nEq } test₁ : Set test₁ = equal nzero (nsucc nzero) test₂ : Set test₂ = equal bfalse bfalse eqN-sym : ∀ {m n} → (Nm : N m) → (Nn : N n) → equal Nm Nn → equal Nn Nm eqN-sym nzero nzero h = h eqN-sym nzero (nsucc Nn) h = h eqN-sym (nsucc Nm) nzero h = h eqN-sym (nsucc Nm) (nsucc Nn) h = h postulate eqN-sym' : ∀ {m n} → (Nm : N m) → (Nn : N n) → equal Nm Nn → equal Nn Nm -- {-# ATP prove eqN-sym' #-}
{ "alphanum_fraction": 0.5171858217, "avg_line_length": 29.09375, "ext": "agda", "hexsha": "93da270b64eb8c81dbfe4949ffd46d8d1ff3ffa6", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/FOT/FOTC/TypeClasses/EqualityInstanceArguments.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/FOT/FOTC/TypeClasses/EqualityInstanceArguments.agda", "max_line_length": 82, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/FOT/FOTC/TypeClasses/EqualityInstanceArguments.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 585, "size": 1862 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Categories.Limits.Terminal where open import Cubical.Foundations.Prelude open import Cubical.Data.Sigma -- open import Cubical.Categories.Limits.Base open import Cubical.Categories.Category open import Cubical.Categories.Functor private variable ℓ ℓ' : Level module _ (C : Precategory ℓ ℓ') where open Precategory C isInitial : (x : ob) → Type (ℓ-max ℓ ℓ') isInitial x = ∀ (y : ob) → isContr (C [ x , y ]) isFinal : (x : ob) → Type (ℓ-max ℓ ℓ') isFinal x = ∀ (y : ob) → isContr (C [ y , x ]) hasFinalOb : Type (ℓ-max ℓ ℓ') hasFinalOb = Σ[ x ∈ ob ] isFinal x
{ "alphanum_fraction": 0.66359447, "avg_line_length": 25.0384615385, "ext": "agda", "hexsha": "2ec414a915d402bb92f8c52659213f24b803e273", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Categories/Limits/Terminal.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Categories/Limits/Terminal.agda", "max_line_length": 50, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Categories/Limits/Terminal.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 215, "size": 651 }
module MLib.Semirings where open import MLib.Prelude open Algebra using (Semiring) module _ {ℓ p} (semiring : Semiring ℓ p) where open Semiring semiring renaming (Carrier to S) pow : ℕ → S → S pow Nat.zero x = 1# pow (Nat.suc n) x = x * pow n x powsum : ℕ → S → S powsum Nat.zero x = 1# powsum (Nat.suc n) x = pow (Nat.suc n) x + powsum n x Q-stable : ℕ → S → Set p Q-stable q x = powsum (1 Nat.+ q) x ≈ powsum q x
{ "alphanum_fraction": 0.6232876712, "avg_line_length": 23.0526315789, "ext": "agda", "hexsha": "042290023855f036d3002f5dade79a0d07b6d6d1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bch29/agda-matrices", "max_forks_repo_path": "src/MLib/Semirings.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bch29/agda-matrices", "max_issues_repo_path": "src/MLib/Semirings.agda", "max_line_length": 55, "max_stars_count": null, "max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bch29/agda-matrices", "max_stars_repo_path": "src/MLib/Semirings.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 168, "size": 438 }
-- Andreas, 2016-12-30, issue #2368 reported by m0davis -- {-# OPTIONS -v interaction.give:100 -v tc.constr:30 #-} open import Agda.Builtin.Reflection macro mac : Term → Term → TC _ mac = {!!} foo : Set → Set → Set foo = mac (foo {!Term!} {!Term!}) -- give both solutions -- WAS: internal error after giving the second `Term` -- Expected: yellow
{ "alphanum_fraction": 0.6470588235, "avg_line_length": 21, "ext": "agda", "hexsha": "b5cd4f9aef577709bcb3359bd07411af2e5013ed", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/interaction/Issue2368.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/interaction/Issue2368.agda", "max_line_length": 58, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue2368.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 109, "size": 357 }
{-# OPTIONS --no-termination-check #-} module Pi-reasoning where open import Data.Empty open import Data.Unit hiding (_≟_) open import Data.Bool hiding (_≟_) open import Data.Nat open import Data.List open import Data.Sum hiding (map) open import Data.Product hiding (map) open import Level hiding (suc) open import Relation.Nullary open import Relation.Binary open import Algebra open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Relation.Binary.PropositionalEquality as PropEq using(sym; trans) import Algebra.FunctionProperties as FunctionProperties -- open import Algebra.FunctionProperties open import Algebra.Structures open import Pi-abstract-machine ------------------------------------------------------------------------------ -- Decidable equality -- normalize a type to a natural number size : B → ℕ size ZERO = 0 size ONE = 1 size (PLUS b₁ b₂) = size b₁ + size b₂ size (TIMES b₁ b₂) = size b₁ * size b₂ -- normalize a value to a number normalize : {b : B} → VB b → ℕ normalize {ZERO} () normalize {ONE} unitB = 0 normalize {PLUS b₁ b₂} (inlB v) = normalize {b₁} v normalize {PLUS b₁ b₂} (inrB v) = size b₁ + normalize {b₂} v normalize {TIMES b₁ b₂} (pairB v₁ v₂) = size b₂ * normalize {b₁} v₁ + normalize {b₂} v₂ -- decidable equality of our values: normalize and compare the -- underlying natural numbers. This is justified by the fact that the -- natural numbers are a model of commutative semirings. -- Note that we can't compare at different types so easily, they have -- to have the same size, something not worth dealing with right now vb= : {b : B} → (v₁ : VB b) → (v₂ : VB b) → Set vb= {b} v₁ v₂ = (normalize {b} v₁) ≡ (normalize {b} v₂) vb-Equivalence : {b : B} → IsEquivalence (vb= {b}) vb-Equivalence = record { refl = refl ; sym = PropEq.sym ; trans = PropEq.trans } vb== : {b : B} → Decidable {A = VB b} vb= vb== {b} x y = (normalize {b} x) ≟ (normalize {b} y) -- generate all values of a type values : (b : B) → List (VB b) values ZERO = [] values ONE = [ unitB ] values (PLUS b₁ b₂) = map inlB (values b₁) ++ map inrB (values b₂) values (TIMES b₁ b₂) = concatMap (λ v₁ → map (pairB v₁) (values b₂)) (values b₁) -- B is a Setoid VB-is-Setoid : {b : B} → Setoid Level.zero Level.zero VB-is-Setoid {b} = record { Carrier = VB b ; _≈_ = vb= ; isEquivalence = vb-Equivalence } -- equality of combinators: -- two combinators are equal if they map equal values to equal values -- best do this via proving that vb= generates a decidable equivalence {- ⟺=bool : {b₁ b₂ : B} → (b₁ ⟺ b₂) → (b₁ ⟺ b₂) → Bool ⟺=bool {b₁} {b₂} f g = and (zipWith vb= (map (eval f) vs) (map (eval g) vs)) where vs = values b₁ data _⟺=_ : {b₁ b₂ : B} → (b₁ ⟺ b₂) → (b₁ ⟺ b₂) → Set where id⟺= : {b₁ b₂ : B} → (f : b₁ ⟺ b₂) → (f ⟺= f) sym⟺= : {b₁ b₂ : B} → (f : b₁ ⟺ b₂) → (g : b₁ ⟺ b₂) → ( f ⟺= g ) → (g ⟺= f) -- verifies that the given combinators relates the given values data _s⟷_ : B → B → Set where sid⟷ : {b : B} {v₁ : VB b} {v₂ : VB b} {p : T (vb= (eval (iso id⟷) v₁) v₂)} → (b s⟷ b) ⟺=IsEquivalence : IsEquivalence _s⟷_ ⟺=IsEquivalence = record { refl = srefl ; sym = {!!} ; trans = {!!} } where srefl : {b : B} {v : VB b} → b s⟷ b srefl {b} {v} = sid⟷ {b} {v} {v} {{!!}} -- <-> : B -> B -> Set with constructors id : {b : B} -> (b <-> b) -- IsEquivalence <-> -- refl = id -- R= : B -> B -> Set with constructos -} ------------------------------------------------------------------------------ {-- testT = PLUS ONE (PLUS ONE ONE) test1 = normalize {testT} (inlB unitB) test2 = normalize {testT} (inrB (inlB unitB)) test3 = normalize {testT} (inrB (inrB unitB)) testT = PLUS ZERO (PLUS ONE ONE) test1 = normalize {testT} (inrB (inlB unitB)) test2 = normalize {testT} (inrB (inrB unitB)) testT = TIMES (PLUS ONE ONE) ZERO test1 = size testT testT = TIMES (PLUS ONE ONE) (PLUS ONE (PLUS ONE ONE)) test1 = normalize {testT} (pairB (inlB unitB) (inlB unitB)) test2 = normalize {testT} (pairB (inrB unitB) (inlB unitB)) test3 = normalize {testT} (pairB (inlB unitB) (inrB (inlB unitB))) test4 = normalize {testT} (pairB (inrB unitB) (inrB (inlB unitB))) test5 = normalize {testT} (pairB (inlB unitB) (inrB (inrB unitB))) test6 = normalize {testT} (pairB (inrB unitB) (inrB (inrB unitB))) BOOL = PLUS ONE ONE test = ⟺= {BOOL} {BOOL} (iso swap₊ ◎ iso swap₊) (iso id⟷) test1 : (iso swap₊) ⟺= (iso swap₊) test1 = check {PLUS ONE ONE} {PLUS ONE ONE} (iso swap₊) (iso swap₊) tt The following does NOT typecheck which is good. Agda rejected my nonsense claim that id is equivalent to swap+ test2 : (iso swap₊) ⟺= (iso id⟷) test2 = check {PLUS ONE ONE} {PLUS ONE ONE} (iso swap₊) (iso id⟷) tt --}
{ "alphanum_fraction": 0.5941558442, "avg_line_length": 31.7935483871, "ext": "agda", "hexsha": "4df9ae47093d4905aac8766f384f17833a9bf6cf", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "agda/Pi-reasoning.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "agda/Pi-reasoning.agda", "max_line_length": 89, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "agda/Pi-reasoning.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 1675, "size": 4928 }
----------------------------------------------------------------------- -- This file formalizes the proof that Dial₂(Sets) is indeed a model -- -- of Full Tensorial Logic. See Lemma 16 and Lemma 17 of the paper. -- ----------------------------------------------------------------------- module Tensorial where open import prelude open import Dial2Sets -- We first must prove that Dial₂(Sets) is a dialogue category. The -- defining feature is that we use primarily implication for this. -- This defines the negation functor: ¬ : Dial₂(Sets) → Dial₂ᵒᵖ(Sets) ¬ₒ : Obj → Obj ¬ₒ A = A ⊸ₒ J ¬ₐ-aux : ∀{U V Y X : Set}{f : U → V}{F : Y → X} → Σ (V → ⊤) (λ x → ⊤ → Y) → Σ (U → ⊤) (λ x → ⊤ → X) ¬ₐ-aux {f = f}{F}(j₁ , j₂) = (λ u → j₁ (f u)) , (λ t → F (j₂ t)) ¬ₐ-aux' : ∀{U V : Set}{f : U → V} → Σ U (λ x → ⊤) → Σ V (λ x → ⊤) ¬ₐ-aux' {f = f} (u , triv) = f u , triv ¬ₐ : {A B : Obj} → Hom A B → Hom (¬ₒ B) (¬ₒ A) ¬ₐ {(U , X , α)}{(V , Y , β)} (f , F , p) = ¬ₐ-aux , ¬ₐ-aux' , ¬ₐ-cond where ¬ₐ-cond : {u : Σ (V → ⊤) (λ x → ⊤ → Y)} {y : Σ U (λ x → ⊤)} → ⊸-cond β (λ x y₁ → ⊥) u (¬ₐ-aux' y) → ⊸-cond α (λ x y₁ → ⊥) (¬ₐ-aux {f = f}{F} u) y ¬ₐ-cond {j₁ , j₂}{u , triv} p₁ p₂ = p₁ (p p₂) -- At this point we must show that the required family of bijections -- exist. -- -- The bijection φ turns out to be a simple use of the combination of -- currying and associativity: -- -- Hom(A ⊗ B,¬ C) = Hom(A ⊗ B,C ⊸ ⊥) -- ≅ Hom((A ⊗ B) ⊗ C, ⊥) -- ≅ Hom(A ⊗ (B ⊗ C), ⊥) -- ≅ Hom(A, (B ⊗ C) ⊸ ⊥) -- = Hom(A, ¬ (B ⊗ C)) -- -- Note that the previous string of isomorphisms do not depend on the -- fact that ⊥ is the intial object. In fact, we can replace ⊥ with -- any object at all, and the result still holds. φ : {A B C : Obj} → Hom (A ⊗ₒ B) (¬ₒ C) → Hom A (¬ₒ (B ⊗ₒ C)) φ {A}{B}{C} f = cur ((α⊗-inv {A}{B}{C}) ○ (uncur f)) φ-inv : {A B C : Obj} → Hom A (¬ₒ (B ⊗ₒ C)) → Hom (A ⊗ₒ B) (¬ₒ C) φ-inv {A}{B}{C} g = cur ((α⊗ {A}{B}{C}) ○ (uncur g)) φ-bij₁ : ∀{A B C : Obj}{f : Hom (A ⊗ₒ B) (¬ₒ C)} → φ-inv (φ f) ≡h f φ-bij₁ {A}{B}{C}{f} with (cur-uncur-bij₁ {A}{B ⊗ₒ C}{J}{comp (α⊗-inv {A}{B}{C}) (uncur {A ⊗ₒ B}{C}{J} f)}) ... | eq₁ with cur-≡h (≡h-subst-○ {(A ⊗ₒ B) ⊗ₒ C}{A ⊗ₒ (B ⊗ₒ C)}{J}{α⊗}{α⊗} {j = uncur f} (≡h-refl {(A ⊗ₒ B) ⊗ₒ C}{A ⊗ₒ (B ⊗ₒ C)} {f = α⊗}) eq₁ (≡h-trans (○-assoc {f = α⊗ {A} {B} {C}} {α⊗-inv} {uncur f}) (≡h-subst-○ {f₁ = α⊗ {A} {B} {C} ○ α⊗-inv} {id} {uncur f} {uncur f} {uncur f} α⊗-id₁ ≡h-refl ○-idl))) ... | eq₂ = ≡h-trans eq₂ cur-uncur-bij₂ φ-bij₂ : ∀{A B C : Obj}{f : Hom A (¬ₒ (B ⊗ₒ C))} → φ (φ-inv f) ≡h f φ-bij₂ {A}{B}{C}{f} with cur-uncur-bij₁ {f = comp (α⊗ {A}{B}{C}) (uncur f)} ... | eq₁ with cur-cong (≡h-subst-○ {f₁ = α⊗-inv {A}{B}{C}}{α⊗-inv {A}{B}{C}} {j = comp α⊗-inv (comp α⊗ (uncur f))} ≡h-refl eq₁ ≡h-refl) ... | eq₂ with (cur-cong (○-assoc {f = α⊗-inv {A} {B} {C}} {α⊗} {uncur f})) ... | eq₃ with cur-cong (≡h-subst-○ {f₁ = comp (α⊗-inv {A}{B}{C}) α⊗}{id} {uncur f}{uncur f}{comp id (uncur f)} α⊗-id₂ ≡h-refl ≡h-refl) ... | eq₄ = ≡h-trans eq₂ (≡h-trans eq₃ (≡h-trans eq₄ (≡h-trans (cur-cong (○-idl {f = uncur f})) (cur-uncur-bij₂ {g = f})))) -- The following shows that Dial₂(Sets)! is cartesian. Jₒ = !ₒ -- First, we define the cartesian product in Dial₂(Sets), and then use -- Jₒ to put us inside of Dial₂(Sets)!. _&ᵣ_ : {U X V Y : Set} → (α : U → X → Set) → (β : V → Y → Set) → Σ U (λ x → V) → X ⊎ Y → Set _&ᵣ_ α β (u , v) (inj₁ x) = α u x _&ᵣ_ α β (u , v) (inj₂ y) = β v y _&ₒ_ : (A B : Obj) → Obj (U , X , α) &ₒ (V , Y , β) = (U × V) , (X ⊎ Y) , α &ᵣ β -- The remainder of this file will work under the Jₒ functor which -- will put us inside of Dial₂(Sets)!. -- This defines the projection morphism: π₁ : F(A & B) → F(A). π₁ : {A B : Obj} → Hom (Jₒ (A &ₒ B)) (Jₒ A) π₁ {U , X , α}{V , Y , β} = fst , (λ (f : U → (X *)) (p : U × V) → map inj₁ (f (fst p))) , λ {u}{y} p → π₁-cond {u}{y} p where π₁-cond : {u : Σ U (λ x → V)} {y : U → 𝕃 X} → all-pred ((α &ᵣ β) u) (map inj₁ (y (fst u))) → all-pred (α (fst u)) (y (fst u)) π₁-cond {u , v} y = aux y where aux : {l : X *} → all-pred ((α &ᵣ β) (u , v)) (map inj₁ l) → all-pred (α u) l aux {[]} triv = triv aux {x :: l} (j₁ , j₂) = j₁ , aux j₂ -- This defines the projection morphism: π₂ : A & B → B. π₂ : {A B : Obj} → Hom (Jₒ (A &ₒ B)) (Jₒ B) π₂ {U , X , α}{V , Y , β} = snd , (λ f p → map inj₂ (f (snd p))) , λ {u}{y} p → π₂-cond {u}{y} p where π₂-cond : {u : Σ U (λ x → V)} {y : V → 𝕃 Y} → all-pred ((α &ᵣ β) u) (map inj₂ (y (snd u))) → all-pred (β (snd u)) (y (snd u)) π₂-cond {u , v} y = aux y where aux : {l : Y *} → all-pred ((α &ᵣ β) (u , v)) (map inj₂ l) → all-pred (β v) l aux {[]} triv = triv aux {x :: l} (j₁ , j₂) = j₁ , aux j₂ cart-ar-crt : {U X V Y W Z : Set} → {α : U → X → Set} → {β : V → Y → Set} → {γ : W → Z → Set} → Hom (Jₒ (W , Z , γ)) (Jₒ (U , X , α)) → Hom (Jₒ (W , Z , γ)) (Jₒ (V , Y , β)) → (Σ U (λ x → V) → 𝕃 (X ⊎ Y)) → W → 𝕃 Z cart-ar-crt (f , F , p₁) (g , G , p₂) j w with (λ u → (proj-⊎₁ (j (u , g w)))) | (λ v → (proj-⊎₂ (j (f w , v)))) ... | j₁ | j₂ = F j₁ w ++ G j₂ w -- This takes two morphisms f : C → A and g : C → B, and constructs -- a morphism (f,g) : C → A & B. cart-ar : {C A B : Obj} → Hom (Jₒ C) (Jₒ A) → Hom (Jₒ C) (Jₒ B) → Hom (Jₒ C) (Jₒ (A &ₒ B)) cart-ar {W , Z , γ}{U , X , α}{V , Y , β} (f , F , p₁) (g , G , p₂) = (λ w → (f w , g w)) , cart-ar-crt {α = α}{β}{γ} (f , F , p₁) (g , G , p₂) , (λ {u}{y} p → cart-ar-cond {u}{y} p) where cart-ar-cond : {u : W} {y : Σ U (λ x → V) → 𝕃 (X ⊎ Y)} → all-pred (γ u) (F (λ u₁ → proj-⊎₁ (y (u₁ , g u))) u ++ G (λ v → proj-⊎₂ (y (f u , v))) u) → all-pred ((α &ᵣ β) (f u , g u)) (y (f u , g u)) cart-ar-cond {u}{j} p rewrite all-pred-append {f = γ u} {F (λ u₁ → (proj-⊎₁ (j (u₁ , g u)))) u} {G (λ v → (proj-⊎₂ (j (f u , v)))) u} ∧-unit ∧-assoc with p ... | (r₁ , r₂) = aux (p₁ r₁) (p₂ r₂) where aux : ∀{l} → all-pred (α (f u)) ((proj-⊎₁ l)) → all-pred (β (g u)) ((proj-⊎₂ l)) → all-pred ((α &ᵣ β) (f u , g u)) l aux {[]} _ _ = triv aux {inj₁ x :: l} (s₁ , s₂) x₂ = s₁ , aux {l} s₂ x₂ aux {inj₂ y :: l} x₁ (s₁ , s₂) = s₁ , aux {l} x₁ s₂ -- This shows that f ≡ (f,g);π₁. cart-diag₁ : {A B C : Obj} → {f : Hom C A} → {g : Hom C B} → _≡h_ { Jₒ C}{ Jₒ A} (!ₐ {C}{A} f) (comp { Jₒ C} {(Jₒ (A &ₒ B))} { Jₒ A} (cart-ar (!ₐ {C}{A} f) (!ₐ {C}{B} g)) π₁) cart-diag₁ {U , X , α}{V , Y , β}{W , Z , γ}{f = f , F , p₁}{g , G , p₂} = refl , ext-set (λ {j₁} → ext-set (λ {w} → aux)) where aux : ∀{l : X *} → map F l ≡ map F (proj-⊎₁ {_}{_}{X}{Y} (map inj₁ l)) ++ map G (proj-⊎₂ (map inj₁ l)) aux {l} rewrite map-proj-⊎₁ {_}{_}{X}{Y} l | map-proj-⊎₂-[] {_}{_}{X}{Y} l = sym (++[] (map F l)) -- This shows that g ≡ (f,g);π₂. cart-diag₂ : {A B C : Obj} → {f : Hom C A} → {g : Hom C B} → _≡h_ { Jₒ C}{ Jₒ B} (!ₐ {C}{B} g) (comp { Jₒ C} {(Jₒ (A &ₒ B))} { Jₒ B} (cart-ar (!ₐ {C}{A} f) (!ₐ {C}{B} g)) π₂) cart-diag₂ {U , X , α}{V , Y , β}{W , Z , γ}{f = f , F , p₁}{g , G , p₂} = refl , ext-set (λ {j₁} → ext-set (λ {w} → aux)) where aux : ∀{l : Y *} → map G l ≡ map F (proj-⊎₁ {_}{_}{X}{Y} (map inj₂ l)) ++ map G (proj-⊎₂ {_}{_}{X}{Y} (map inj₂ l)) aux {l} rewrite map-proj-⊎₂ {_}{_}{X}{Y} l | map-proj-⊎₁-[] {_}{_}{X}{Y} l = refl term-diag : ∀{A : Obj} → Hom (Jₒ A) (Jₒ (⊤ , ⊥ , λ x y → ⊤)) term-diag {U , X , α} = (λ x → triv) , (λ f u → aux (f triv) u) , (λ {u}{y} → aux' {u}{y triv}) where aux : 𝕃 ⊥ → U → 𝕃 X aux [] u = [] aux (x :: l) u = ⊥-elim x :: aux l u aux' : {u : U} {l : 𝕃 ⊥} → all-pred (α u) (aux l u) → all-pred (λ y₁ → ⊤) l aux' {u}{l = []} p = p aux' {u}{l = x :: l} (p , p') = triv , aux' {u}{l} p' term-cart-crt₁ : {X : Set} → 𝕃 (X ⊎ ⊥) → 𝕃 X term-cart-crt₁ [] = [] term-cart-crt₁ (inj₁ x :: l) = x :: term-cart-crt₁ l term-cart-crt₁ (inj₂ y :: l) = ⊥-elim y :: term-cart-crt₁ l term-cart₁ : ∀{A : Obj} → Hom (Jₒ A) (Jₒ (A &ₒ (⊤ , ⊥ , λ x y → ⊤))) term-cart₁ {U , X , α} = (λ x → x , triv) , (λ f u → term-cart-crt₁ (f (u , triv))) , cond where cond : {u : U} {l : 𝕃 (X ⊎ ⊥)} → all-pred (α u) (term-cart-crt₁ l) → all-pred ((α &ᵣ (λ x y₁ → ⊤)) (u , triv)) l cond {u}{[]} p = triv cond {u}{inj₁ x :: l} (p , p') = p , cond p' cond {u}{inj₂ y :: l} (p , p') = triv , cond p' term-cart₂ : ∀{A : Obj} → Hom (Jₒ (A &ₒ (⊤ , ⊥ , λ x y → ⊤))) (Jₒ A) term-cart₂ {U , X , α} = π₁ term-cart-iso₁ : ∀{A : Obj} → _≡h_ {Jₒ A} {Jₒ A} (comp {Jₒ A}{Jₒ (A &ₒ (⊤ , ⊥ , λ x y → ⊤))} {Jₒ A} term-cart₁ term-cart₂) id term-cart-iso₁ {U , X , α} = refl , ext-set (λ {f} → ext-set (λ {u} → aux)) where aux : ∀{l : X *} → term-cart-crt₁ (map inj₁ l) ≡ l aux {[]} = refl aux {x :: l} rewrite aux {l} = refl term-cart-iso₂ : ∀{A : Obj} → _≡h_ {Jₒ (A &ₒ (⊤ , ⊥ , λ x y → ⊤))} {Jₒ (A &ₒ (⊤ , ⊥ , λ x y → ⊤))} (comp {Jₒ (A &ₒ (⊤ , ⊥ , λ x y → ⊤))}{Jₒ A} {Jₒ (A &ₒ (⊤ , ⊥ , λ x y → ⊤))} term-cart₂ term-cart₁) id term-cart-iso₂ {U , X , α} = ext-set aux , ext-set (λ {f} → ext-set (aux' {f})) where aux : {a : Σ U (λ x → ⊤)} → (fst a , triv) ≡ a aux {u , triv} = refl aux' : {f : Σ U (λ x → ⊤) → 𝕃 (X ⊎ ⊥)}{a : Σ U (λ x → ⊤)} → map inj₁ (term-cart-crt₁ (f (fst a , triv))) ≡ f a aux' {f}{u , triv} = aux'' where aux'' : ∀{l : (X ⊎ ⊥) *} → map inj₁ (term-cart-crt₁ l) ≡ l aux'' {[]} = refl aux'' {inj₁ x :: l} rewrite aux'' {l} = refl aux'' {inj₂ y :: l} = ⊥-elim y twist-cart : ∀{A B : Obj} → Hom (Jₒ (A &ₒ B)) (Jₒ (B &ₒ A)) twist-cart {A}{B} = cart-ar {A &ₒ B} {B} {A} π₂ π₁
{ "alphanum_fraction": 0.420212766, "avg_line_length": 34.1818181818, "ext": "agda", "hexsha": "f4e8f06846fa0fab46b114f6aa2d0ed760c50e49", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heades/AUGL", "max_forks_repo_path": "dialectica-cats/Tensorial.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "heades/AUGL", "max_issues_repo_path": "dialectica-cats/Tensorial.agda", "max_line_length": 86, "max_stars_count": null, "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heades/AUGL", "max_stars_repo_path": "dialectica-cats/Tensorial.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4931, "size": 10152 }
module Grove where open import Axiom.Extensionality.Propositional open import Data.Bool hiding (_<_; _≟_) open import Function.Equivalence hiding (_∘_) open import Function hiding (_⇔_) open import Function.Equality using (_⟨$⟩_) open import Level using (Level) open import Relation.Binary.PropositionalEquality hiding (Extensionality) open import Relation.Nullary postulate extensionality : {ℓ₁ ℓ₂ : Level} → Extensionality ℓ₁ ℓ₂ ---------------- -- Constructors ---------------- postulate Ctor : Set _≟ℂ_ : (c₁ c₂ : Ctor) → Dec (c₁ ≡ c₂) ---------------- -- Positions ---------------- postulate Pos : Set _≟ℙ_ : (p₁ p₂ : Pos) → Dec (p₁ ≡ p₂) _∈ℙ_ : Pos → Ctor → Set ---------------- -- Identifiers ---------------- postulate Ident : Set _≟𝕀_ : (i₁ i₂ : Ident) → Dec (i₁ ≡ i₂) ---------------- -- The Root Vertex ---------------- -- Note actually used in the proofs, but here it is anyway postulate ctorRoot : Ctor posRoot : Pos posRoot∈ctorRoot : posRoot ∈ℙ ctorRoot identRoot : Ident ---------------- -- Vertex ---------------- record Vertex : Set where constructor V field ctor : Ctor ident : Ident _≟Vertex_ : (v₁ v₂ : Vertex) → Dec (v₁ ≡ v₂) V c₁ i₁ ≟Vertex V c₂ i₂ with c₁ ≟ℂ c₂ | i₁ ≟𝕀 i₂ ... | yes refl | yes refl = yes refl ... | _ | no p = no (λ { refl → p refl }) ... | no p | _ = no (λ { refl → p refl }) ---------------- -- Edge ---------------- record Edge : Set where constructor E field parent : Vertex child : Vertex position : Pos ident : Ident .isValid : position ∈ℙ Vertex.ctor parent _≟Edge_ : (e₁ e₂ : Edge) → Dec (e₁ ≡ e₂) E parent₁ child₁ position₁ ident₁ _ ≟Edge E parent₂ child₂ position₂ ident₂ _ with parent₁ ≟Vertex parent₂ | child₁ ≟Vertex child₂ | position₁ ≟ℙ position₂ | ident₁ ≟𝕀 ident₂ ... | yes refl | yes refl | yes refl | yes refl = yes refl ... | no p | _ | _ | _ = no (λ { refl → p refl }) ... | _ | no p | _ | _ = no (λ { refl → p refl }) ... | _ | _ | no p | _ = no (λ { refl → p refl }) ... | _ | _ | _ | no p = no (λ { refl → p refl }) ---------------- -- EdgeState ---------------- data EdgeState : Set where ⊥ : EdgeState -- smallest + : EdgeState -- middle - : EdgeState -- largest _⊔_ : EdgeState → EdgeState → EdgeState - ⊔ _ = - _ ⊔ - = - + ⊔ _ = + _ ⊔ + = + _ ⊔ _ = ⊥ ⊔-assoc : (s₁ s₂ s₃ : EdgeState) → (s₁ ⊔ (s₂ ⊔ s₃)) ≡ ((s₁ ⊔ s₂) ⊔ s₃) ⊔-assoc ⊥ ⊥ ⊥ = refl ⊔-assoc ⊥ ⊥ + = refl ⊔-assoc ⊥ ⊥ - = refl ⊔-assoc ⊥ + ⊥ = refl ⊔-assoc ⊥ + + = refl ⊔-assoc ⊥ + - = refl ⊔-assoc ⊥ - ⊥ = refl ⊔-assoc ⊥ - + = refl ⊔-assoc ⊥ - - = refl ⊔-assoc + ⊥ ⊥ = refl ⊔-assoc + ⊥ + = refl ⊔-assoc + ⊥ - = refl ⊔-assoc + + ⊥ = refl ⊔-assoc + + + = refl ⊔-assoc + + - = refl ⊔-assoc + - ⊥ = refl ⊔-assoc + - + = refl ⊔-assoc + - - = refl ⊔-assoc - ⊥ ⊥ = refl ⊔-assoc - ⊥ + = refl ⊔-assoc - ⊥ - = refl ⊔-assoc - + ⊥ = refl ⊔-assoc - + + = refl ⊔-assoc - + - = refl ⊔-assoc - - ⊥ = refl ⊔-assoc - - + = refl ⊔-assoc - - - = refl ⊔-comm : (s₁ s₂ : EdgeState) → s₁ ⊔ s₂ ≡ s₂ ⊔ s₁ ⊔-comm ⊥ ⊥ = refl ⊔-comm ⊥ + = refl ⊔-comm ⊥ - = refl ⊔-comm + ⊥ = refl ⊔-comm + + = refl ⊔-comm + - = refl ⊔-comm - ⊥ = refl ⊔-comm - + = refl ⊔-comm - - = refl ⊔-idem : (s : EdgeState) → s ⊔ s ≡ s ⊔-idem ⊥ = refl ⊔-idem + = refl ⊔-idem - = refl ---------------- -- Graph ---------------- Graph : Set Graph = Edge → EdgeState _[_↦_] : Graph → Edge → EdgeState → Graph _[_↦_] f k v = λ { x → if does (x ≟Edge k) then v ⊔ f x else f x } [↦]-comm : (s₁ s₂ : EdgeState) (e₁ e₂ : Edge) (g : Graph) → (g [ e₁ ↦ s₁ ]) [ e₂ ↦ s₂ ] ≡ (g [ e₂ ↦ s₂ ]) [ e₁ ↦ s₁ ] [↦]-comm s₁ s₂ e₁ e₂ g = extensionality go where go : (e : Edge) → ((g [ e₁ ↦ s₁ ]) [ e₂ ↦ s₂ ]) e ≡ ((g [ e₂ ↦ s₂ ]) [ e₁ ↦ s₁ ]) e go e with e ≟Edge e₁ | e ≟Edge e₂ ... | yes refl | yes refl rewrite ⊔-assoc s₁ s₂ (g e) | ⊔-assoc s₂ s₁ (g e) | ⊔-comm s₁ s₂ = refl ... | no _ | yes refl = refl ... | yes refl | no _ = refl ... | no _ | no _ = refl [↦]-join : (s₁ s₂ : EdgeState) (e : Edge) (g : Graph) → (g [ e ↦ s₁ ]) [ e ↦ s₂ ] ≡ g [ e ↦ s₁ ⊔ s₂ ] [↦]-join s₁ s₂ e g = extensionality go where go : (e' : Edge) → ((g [ e ↦ s₁ ]) [ e ↦ s₂ ]) e' ≡ (g [ e ↦ s₁ ⊔ s₂ ]) e' go e' with e' ≟Edge e ... | yes refl rewrite ⊔-assoc s₂ s₁ (g e) | ⊔-comm s₁ s₂ = refl ... | no _ = refl ---------------- -- Action ---------------- data Action : Set where A : Edge → EdgeState → Action ⟦_⟧ : Action → Graph → Graph ⟦ (A e s) ⟧ g = g [ e ↦ s ] ⟦⟧-comm' : (a₁ a₂ : Action) (g : Graph) → ⟦ a₁ ⟧ (⟦ a₂ ⟧ g) ≡ ⟦ a₂ ⟧ (⟦ a₁ ⟧ g) ⟦⟧-comm' (A e₁ s₁) (A e₂ s₂) g = [↦]-comm s₂ s₁ e₂ e₁ g ⟦⟧-comm : (a₁ a₂ : Action) → ⟦ a₁ ⟧ ∘′ ⟦ a₂ ⟧ ≡ ⟦ a₂ ⟧ ∘′ ⟦ a₁ ⟧ ⟦⟧-comm a₁ a₂ = extensionality (⟦⟧-comm' a₁ a₂) ⟦⟧-idem' : (a : Action) (g : Graph) → ⟦ a ⟧ (⟦ a ⟧ g) ≡ ⟦ a ⟧ g ⟦⟧-idem' (A e s) g rewrite [↦]-join s s e g with s ... | ⊥ = refl ... | + = refl ... | - = refl ⟦⟧-idem : (a : Action) → ⟦ a ⟧ ∘′ ⟦ a ⟧ ≡ ⟦ a ⟧ ⟦⟧-idem a = extensionality (⟦⟧-idem' a) ---------------- -- Action Relation Between Graphs ---------------- data ActionRel : Graph → Action → Graph → Set where AR : (a : Action) → (g : Graph) → ActionRel g a (⟦ a ⟧ g) ActionRel-eqv : {g g' : Graph} {a : Action} → ActionRel g a g' ⇔ g' ≡ ⟦ a ⟧ g ActionRel-eqv {g} {g'} {a} = equivalence to from where to : ActionRel g a g' → g' ≡ ⟦ a ⟧ g to (AR .a .g) = refl from : g' ≡ ⟦ a ⟧ g → ActionRel g a g' from refl = AR a g ActionRel-comm : {a₁ a₂ : Action} {g₁ g₂₁ g₃₁ g₂₂ g₃₂ : Graph} → ActionRel g₁ a₁ g₂₁ → ActionRel g₂₁ a₂ g₃₁ → ActionRel g₁ a₂ g₂₂ → ActionRel g₂₂ a₁ g₃₂ → g₃₁ ≡ g₃₂ ActionRel-comm {a₁} {a₂} {g₁} {g₂₁} {g₃₁} {g₂₂} {g₃₂} ar₁ ar₂ ar₂₂ ar₁' = eqgg where eqg₂ : g₂₁ ≡ ⟦ a₁ ⟧ g₁ eqg₂ = Equivalence.to ActionRel-eqv ⟨$⟩ ar₁ eqg₃ : g₃₁ ≡ ⟦ a₂ ⟧ (⟦ a₁ ⟧ g₁) eqg₃ with eqg₂ ... | refl = Equivalence.to ActionRel-eqv ⟨$⟩ ar₂ eqg₂₂ : g₂₂ ≡ ⟦ a₂ ⟧ g₁ eqg₂₂ = Equivalence.to ActionRel-eqv ⟨$⟩ ar₂₂ eqg₃₂ : g₃₂ ≡ ⟦ a₁ ⟧ (⟦ a₂ ⟧ g₁) eqg₃₂ with eqg₂₂ ... | refl = Equivalence.to ActionRel-eqv ⟨$⟩ ar₁' eqgg : g₃₁ ≡ g₃₂ eqgg with eqg₃ | eqg₃₂ ... | refl | refl = ⟦⟧-comm' a₂ a₁ g₁
{ "alphanum_fraction": 0.4977462975, "avg_line_length": 24.9477911647, "ext": "agda", "hexsha": "d66da25fa4143baa60fdfb0d435002d00f49f18b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2ca7001f22587e354c776bed39e70ba8d022aae9", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "fplab/grove-agda", "max_forks_repo_path": "Grove.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2ca7001f22587e354c776bed39e70ba8d022aae9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "fplab/grove-agda", "max_issues_repo_path": "Grove.agda", "max_line_length": 99, "max_stars_count": null, "max_stars_repo_head_hexsha": "2ca7001f22587e354c776bed39e70ba8d022aae9", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "fplab/grove-agda", "max_stars_repo_path": "Grove.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2750, "size": 6212 }
open import Agda.Builtin.Equality open import Agda.Builtin.Sigma data Unit : Set where unit : Unit record _∼_ (From To : Set) : Set where field to : From → To from : To → From to-from : ∀ {x} → to (from x) ≡ x postulate P : {A : Set} → A → Set f : {A B : Set} (A∼B : A ∼ B) (x : A) → P (_∼_.to A∼B x) ∼ P x record R : Set where field p : {x y : Unit} → P x → P y u v : Unit g : (r : R) → _ ∼ P r g = f lemma where lemma : R ∼ Σ _ λ _ → Σ _ λ (_ : ∀ {x y} → _ → _) → _ lemma = record { to = λ x → R.u x , R.p x , R.v x ; from = λ { (u , p , v) → record { u = u ; p = λ {x y} → p {x = x} {y = y} ; v = v } } ; to-from = refl }
{ "alphanum_fraction": 0.4043367347, "avg_line_length": 21.7777777778, "ext": "agda", "hexsha": "d2609558ce3e408a9e63aa2c420be77509559dcf", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue3960b.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue3960b.agda", "max_line_length": 64, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue3960b.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 314, "size": 784 }
module CompilingCoinduction where open import Common.Coinduction open import Common.Char open import Common.String data Unit : Set where unit : Unit {-# COMPILE GHC Unit = data () (()) #-} postulate IO : Set → Set {-# COMPILE GHC IO = type IO #-} {-# BUILTIN IO IO #-} {-# FOREIGN GHC import qualified Data.Text.IO #-} postulate putStrLn : ∞ String → IO Unit {-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn . MAlonzo.RTE.flat #-} {-# COMPILE JS putStrLn = function(x) { return function(cb) { process.stdout.write(x.flat() + "\n"); cb(0); }; } #-} main = putStrLn (♯ "a")
{ "alphanum_fraction": 0.6519524618, "avg_line_length": 21.0357142857, "ext": "agda", "hexsha": "03464bc76054e624d4b5f5c52794e797380ca246", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Compiler/simple/CompilingCoinduction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Compiler/simple/CompilingCoinduction.agda", "max_line_length": 117, "max_stars_count": null, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Compiler/simple/CompilingCoinduction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 157, "size": 589 }
module Fail.BadBuiltinImport where import Agda.Builtin.Nat {-# FOREIGN AGDA2HS import RandomModule (Natural) import AlsoNotRight (foo, Natural(..)) import AsConstructor (D(Natural)) #-}
{ "alphanum_fraction": 0.7712765957, "avg_line_length": 18.8, "ext": "agda", "hexsha": "8ffd5157bc055e1f335edaaf7ec87de68ac43618", "lang": "Agda", "max_forks_count": 18, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z", "max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z", "max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "seanpm2001/agda2hs", "max_forks_repo_path": "test/Fail/BadBuiltinImport.agda", "max_issues_count": 63, "max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6", "max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z", "max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "seanpm2001/agda2hs", "max_issues_repo_path": "test/Fail/BadBuiltinImport.agda", "max_line_length": 38, "max_stars_count": 55, "max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dxts/agda2hs", "max_stars_repo_path": "test/Fail/BadBuiltinImport.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z", "num_tokens": 50, "size": 188 }
module Functional.Dependent where import Lvl open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level -- Function type as a function _→ᶠ_ : (X : Type{ℓ₁}) → (Type{ℓ₁} → Type{ℓ₂}) → Type{ℓ₁ Lvl.⊔ ℓ₂} X →ᶠ Y = X → Y(X) infixl 30 _→ᶠ_ module _ where private variable X : Type{ℓ} private variable Y : X → Type{ℓ} private variable Z : ∀{x : X} → Y(x) → Type{ℓ} apply : (x : X) → ((x : X) → Y(x)) → Y(x) apply(x)(f) = f(x) {-# INLINE apply #-} const : (∀{x : X} → Y(x)) → ((x : X) → Y(x)) const y _ = y {-# INLINE const #-} _$_ : ((x : X) → Y(x)) → (x : X) → Y(x) f $ x = f(x) {-# INLINE _$_ #-} infixr 0 _$_ _⩺_ : (x : X) → ((x : X) → Y(x)) → Y(x) x ⩺ f = f(x) {-# INLINE _⩺_ #-} infixl 10000 _⩺_ _⩹_ : ((x : X) → Y(x)) → (x : X) → Y(x) f ⩹ x = f(x) {-# INLINE _⩹_ #-} infixl 10000 _⩹_ _∘ᵢₘₚₗ_ : (∀{x : X}{y : Y(x)} → Z{x}(y)) → (g : ∀{x : X} → Y(x)) → (∀{x : X} → Z(g{x})) (f ∘ᵢₘₚₗ g){x} = f{x}{g{x}} infixl 10000 _∘ᵢₘₚₗ_ _∘ᵢₙₛₜ_ : (⦃ x : X ⦄ ⦃ y : Y(x) ⦄ → Z{x}(y)) → (g : ⦃ x : X ⦄ → Y(x)) → (⦃ x : X ⦄ → Z(g ⦃ x ⦄)) (f ∘ᵢₙₛₜ g) ⦃ x ⦄ = f ⦃ x ⦄ ⦃ g ⦃ x ⦄ ⦄ infixl 10000 _∘ᵢₙₛₜ_ _∘ₛ_ : ((x : X) → (y : Y(x)) → Z{x}(y)) → (g : (x : X) → Y(x)) → ((x : X) → Z(g(x))) (f ∘ₛ g)(x) = f(x)(g(x)) {-# INLINE _∘ₛ_ #-} infixl 10000 _∘ₛ_ _∘_ : (∀{x : X} → (y : Y(x)) → Z{x}(y)) → (g : (x : X) → Y(x)) → ((x : X) → Z(g(x))) _∘_ f = (const f) ∘ₛ_ {-# INLINE _∘_ #-} infixl 10000 _∘_ module _ where private variable X : Type{ℓ} private variable Y : X → Type{ℓ} private variable Z : ∀{x₁ x₂ : X} → Y(x₁) → Y(x₂) → Type{ℓ} _on₂_ : (f : ∀{x₁ x₂ : X} → (y₁ : Y(x₁)) → (y₂ : Y(x₂)) → Z{x₁}{x₂}(y₁)(y₂)) → (g : (x : X) → Y(x)) → ((x₁ : X) → (x₂ : X) → Z(g(x₁))(g(x₂))) ((_▫_) on₂ f)(y₁)(y₂) = f(y₁) ▫ f(y₂) module _ where private variable X Y : Type{ℓ} private variable Z : X → Y → Type{ℓ} swap : ((x : X) → (y : Y) → Z(x)(y)) → ((y : Y) → (x : X) → Z(x)(y)) swap f(y)(x) = f(x)(y) {-# INLINE swap #-} {- TODO: Agda errors module _ where private variable X₁ : Type{ℓ} private variable X₂ : X₁ → Type{ℓ} private variable Y₁ : ∀{x₁ : X₁} → X₂(x₁) → Type{ℓ} private variable Y₂ : ∀{x₁ : X₁}{x₂ : X₂(x₁)} → Y₁{x₁}(x₂) → Type{ℓ} private variable Z : ∀{x₁ : X₁}{x₂ : X₂(x₁)}{y₁ : Y₁{x₁}(x₂)} → (Y₂{x₁}{x₂}(y₁)) → Type{ℓ} pointwise₂,₁' : (∀{x₁ : X₁} → (x₂ : X₂(x₁)) → {y₁ : Y₁(x₂)} → (y₂ : Y₂(y₁)) → Z{x₁}{x₂}{y₁}(y₂)) → (f : (x₁ : X₁) → X₂(x₁)) → (g : ∀{x₁}{x₂} → (y₁ : Y₁{x₁}(x₂)) → Y₂{x₁}{x₂}(y₁)) → ((x₁ : X₁) → (y₁ : Y₁{x₁}(f(x₁))) → Z{x₁}{f(x₁)}{y₁}(g(y₁))) -} {- module _ where private variable X₁ : Type{ℓ} private variable X₂ : X₁ → Type{ℓ} private variable Y₁ : ∀{x₁ : X₁} → X₂(x₁) → Type{ℓ} private variable Y₂ : ∀{x₁ : X₁}{x₂ : X₂(x₁)} → Y₁{x₁}(x₂) → Type{ℓ} private variable Z : ∀{x₁ : X₁}{x₂ : X₂(x₁)}{y₁ : Y₁{x₁}(x₂)} → Type{ℓ} pointwise₂,₁' : ∀{x₁ : X₁} → (x₂ : X₂(x₁)) → {y₁ : Y₁(x₂)} → (y₂ : Y₂(y₁)) → Z{x₁}{x₂}{y₁} -} module _ where private variable A : Type{ℓ} private variable B : A → Type{ℓ} private variable C : ∀{a : A} → B(a) → Type{ℓ} private variable D : ∀{a : A}{b : B(a)} → (C{a}(b)) → Type{ℓ} private variable E : ∀{a : A}{b : B(a)}{c : C{a}(b)} → D{a}{b}(c) → Type{ℓ} private variable F : ∀{a : A}{b : B(a)}{c : C{a}(b)}{d : D{a}{b}(c)} → E{a}{b}{c}(d) → Type{ℓ} -- Alternative definition: (f ∘₂ g) a b = f(g a b) _∘₂_ : (∀{a : A}{b : B(a)} → (c : C{a}(b)) → D{a}{b}(c)) → (g : ∀(a)(b) → C{a}(b)) → (∀(a)(b) → D(g a b)) _∘₂_ f = (f ∘_) ∘_ {-# INLINE _∘₂_ #-} -- Alternative definition: (f ∘₂ₛ g) x y = f a b (g a b) _∘₂ₛ_ : ((a : A) → (b : B(a)) → (c : C{a}(b)) → D{a}{b}(c)) → (g : ∀(a)(b) → C{a}(b)) → (∀(a)(b) → D(g a b)) _∘₂ₛ_ f = ((_∘ₛ_) ∘ f) ∘ₛ_ {-# INLINE _∘₂ₛ_ #-} -- Alternative definition: (f ∘₂ g) a b c = f(g a b c) _∘₃_ : (∀{a : A}{b : B(a)}{c : C{a}(b)} → (d : D{a}{b}(c)) → E{a}{b}{c}(d)) → (g : ∀(a)(b)(c) → D{a}{b}(c)) → (∀(a)(b)(c) → E(g a b c)) _∘₃_ f = (f ∘₂_) ∘_ {-# INLINE _∘₃_ #-} -- Alternative definition: (f ∘₃ₛ g) a b c = f a b c (g a b c) _∘₃ₛ_ : (∀(a : A)(b : B(a))(c : C{a}(b)) → (d : D{a}{b}(c)) → E{a}{b}{c}(d)) → (g : ∀(a)(b)(c) → D{a}{b}(c)) → (∀(a)(b)(c) → E(g a b c)) _∘₃ₛ_ f = ((_∘₂ₛ_) ∘ f) ∘ₛ_ {-# INLINE _∘₃ₛ_ #-} -- Alternative definition: (f ∘₄ g) a b c d = f(g a b c d) _∘₄_ : (∀{a : A}{b : B(a)}{c : C{a}(b)}{d : D{a}{b}(c)} → (e : E{a}{b}{c}(d)) → F{a}{b}{c}{d}(e)) → (g : ∀(a)(b)(c)(d) → E{a}{b}{c}(d)) → (∀(a)(b)(c)(d) → F(g a b c d)) _∘₄_ f = (f ∘₃_) ∘_ {-# INLINE _∘₄_ #-} -- Alternative definition: (f ∘₄ₛ g) a b c d = f a b c d (g a b c d) _∘₄ₛ_ : (∀(a : A)(b : B(a))(c : C{a}(b))(d : D{a}{b}(c)) → (e : E{a}{b}{c}(d)) → F{a}{b}{c}{d}(e)) → (g : ∀(a)(b)(c)(d) → E{a}{b}{c}(d)) → (∀(a)(b)(c)(d) → F(g a b c d)) _∘₄ₛ_ f = ((_∘₃ₛ_) ∘ f) ∘ₛ_ {-# INLINE _∘₄ₛ_ #-} -- Alternative definition: pointwise₂,₁(_▫_) f g a = f(a) ▫ g(a) pointwise₂,₁ : (∀{a : A} → (b : B(a)) → (c : C{a}(b)) → D{a}{b}(c)) → (f : (a : A) → B(a)) → (g : (a : A) → C{a}(f(a))) → (a : A) → D{a}{f(a)}(g(a)) pointwise₂,₁(_▫_) = ((_∘ₛ_) ∘ ((_▫_) ∘_)) {-# INLINE pointwise₂,₁ #-} -- Alternative definition: pointwise₂,₂(_▫_) f g a b = (f a b) ▫ (g a b) pointwise₂,₂ : (∀{a : A}{b : B(a)} → (c : C{a}(b)) → (d : D{a}{b}(c)) → E{a}{b}{c}(d)) → (f : (a : A) → (b : B(a)) → C{a}(b)) → (g : (a : A) → (b : B(a)) → D{a}{b}(f a b)) → (a : A) → (b : B(a)) → E{a}{b}{f a b}(g a b) pointwise₂,₂(_▫_) = pointwise₂,₁(pointwise₂,₁(_▫_)) {-# INLINE pointwise₂,₂ #-} -- Alternative definition: pointwise₂,₃(_▫_) f g a b c = (f a b c) ▫ (g a b c) pointwise₂,₃ : (∀{a : A}{b : B(a)}{c : C{a}(b)} → (d : D{a}{b}(c)) → (e : E{a}{b}{c}(d)) → F{a}{b}{c}{d}(e)) → (f : (a : A) → (b : B(a)) → (c : C{a}(b)) → D{a}{b}(c)) → (g : (a : A) → (b : B(a)) → (c : C{a}(b)) → E{a}{b}(f a b c)) → (a : A) → (b : B(a)) → (c : C{a}(b)) → F{a}{b}{c}{f a b c}(g a b c) pointwise₂,₃(_▫_) = pointwise₂,₁(pointwise₂,₂(_▫_)) {-# INLINE pointwise₂,₃ #-}
{ "alphanum_fraction": 0.428307589, "avg_line_length": 40.2432432432, "ext": "agda", "hexsha": "e0f2886c5410d714386a4f879ccb7e64592c02bf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Functional/Dependent.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Functional/Dependent.agda", "max_line_length": 302, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Functional/Dependent.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 3246, "size": 5956 }
{-# OPTIONS --omega-in-omega #-} open import Agda.Primitive test : Setω test = Setω record R : Setω where field A : ∀ {ℓ} → Set ℓ data Type : Setω where el : ∀ {ℓ} → Set ℓ → Type
{ "alphanum_fraction": 0.5885416667, "avg_line_length": 13.7142857143, "ext": "agda", "hexsha": "120f2fb7fd3f587c6f832fea032f6584a074d72e", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/OmegaInOmega.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/OmegaInOmega.agda", "max_line_length": 32, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/OmegaInOmega.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 70, "size": 192 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category -- Properties relating Initial and Terminal Objects, -- and Product / Coproduct via op module Categories.Object.Duality {o ℓ e} (C : Category o ℓ e) where open Category C open import Level open import Relation.Binary.PropositionalEquality as ≡ using (_≡_) open import Categories.Morphism C open import Categories.Object.Terminal op open import Categories.Object.Initial C open import Categories.Object.Product op open import Categories.Object.Coproduct C IsInitial⇒coIsTerminal : ∀ {X} → IsInitial X → IsTerminal X IsInitial⇒coIsTerminal is⊥ = record { ! = ! ; !-unique = !-unique } where open IsInitial is⊥ ⊥⇒op⊤ : Initial → Terminal ⊥⇒op⊤ i = record { ⊤ = ⊥ ; ⊤-is-terminal = IsInitial⇒coIsTerminal ⊥-is-initial } where open Initial i coIsTerminal⇒IsInitial : ∀ {X} → IsTerminal X → IsInitial X coIsTerminal⇒IsInitial is⊤ = record { ! = ! ; !-unique = !-unique } where open IsTerminal is⊤ op⊤⇒⊥ : Terminal → Initial op⊤⇒⊥ t = record { ⊥ = ⊤ ; ⊥-is-initial = coIsTerminal⇒IsInitial ⊤-is-terminal } where open Terminal t Coproduct⇒coProduct : ∀ {A B} → Coproduct A B → Product A B Coproduct⇒coProduct A+B = record { A×B = A+B.A+B ; π₁ = A+B.i₁ ; π₂ = A+B.i₂ ; ⟨_,_⟩ = A+B.[_,_] ; project₁ = A+B.inject₁ ; project₂ = A+B.inject₂ ; unique = A+B.unique } where module A+B = Coproduct A+B coProduct⇒Coproduct : ∀ {A B} → Product A B → Coproduct A B coProduct⇒Coproduct A×B = record { A+B = A×B.A×B ; i₁ = A×B.π₁ ; i₂ = A×B.π₂ ; [_,_] = A×B.⟨_,_⟩ ; inject₁ = A×B.project₁ ; inject₂ = A×B.project₂ ; unique = A×B.unique } where module A×B = Product A×B private coIsTerminal⟺IsInitial : ∀ {X} (⊥ : IsInitial X) → coIsTerminal⇒IsInitial (IsInitial⇒coIsTerminal ⊥) ≡ ⊥ coIsTerminal⟺IsInitial _ = ≡.refl IsInitial⟺coIsTerminal : ∀ {X} (⊤ : IsTerminal X) → IsInitial⇒coIsTerminal (coIsTerminal⇒IsInitial ⊤) ≡ ⊤ IsInitial⟺coIsTerminal _ = ≡.refl ⊥⟺op⊤ : (⊤ : Terminal) → ⊥⇒op⊤ (op⊤⇒⊥ ⊤) ≡ ⊤ ⊥⟺op⊤ _ = ≡.refl op⊤⟺⊥ : (⊥ : Initial) → op⊤⇒⊥ (⊥⇒op⊤ ⊥) ≡ ⊥ op⊤⟺⊥ _ = ≡.refl Coproduct⟺coProduct : ∀ {A B} (p : Product A B) → Coproduct⇒coProduct (coProduct⇒Coproduct p) ≡ p Coproduct⟺coProduct _ = ≡.refl coProduct⟺Coproduct : ∀ {A B} (p : Coproduct A B) → coProduct⇒Coproduct (Coproduct⇒coProduct p) ≡ p coProduct⟺Coproduct _ = ≡.refl
{ "alphanum_fraction": 0.6228847703, "avg_line_length": 26.1263157895, "ext": "agda", "hexsha": "c5ff4733926626f30baed18a671612fefd6eaf2f", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-categories", "max_forks_repo_path": "src/Categories/Object/Duality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-categories", "max_issues_repo_path": "src/Categories/Object/Duality.agda", "max_line_length": 101, "max_stars_count": 5, "max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bblfish/agda-categories", "max_stars_repo_path": "src/Categories/Object/Duality.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 1043, "size": 2482 }
module Impure.LFRef.Eval where open import Prelude open import Data.Fin using (fromℕ≤) open import Data.List hiding ([_]) open import Data.List.All open import Data.List.Any open import Data.Vec hiding (map; _∷ʳ_) open import Data.Maybe hiding (All; Any) open import Extensions.List as L open import Impure.LFRef.Syntax hiding (subst) open import Impure.LFRef.Welltyped -- machine configuration: expression to reduce and a store Config : Set Config = Exp 0 × Store !load : ∀ {i} → (μ : Store) → i < length μ → Term 0 !load {i = i} [] () !load {i = zero} (x ∷ μ) (s≤s p) = proj₁ x !load {i = suc i} (x ∷ μ) (s≤s p) = !load μ p !store : ∀ {i e} → (μ : Store) → i < length μ → Val e → Store !store [] () v !store {i = zero} (x ∷ μ) (s≤s p) v = (, v) ∷ μ !store {i = suc i} (x ∷ μ) (s≤s p) v = (, v) ∷ (!store μ p v) !call : ∀ {n m} → Exp m → (l : List (Term n)) → length l ≡ m → Exp n !call e ts p = e exp/ subst (Vec _) p (fromList ts) -- small steps for expressions infix 1 _⊢_≻_ data _⊢_≻_ (𝕊 : Sig) : (t t' : Config) → Set where funapp-β : ∀ {fn ts μ φ} → (Sig.funs 𝕊) L.[ fn ]= φ → (p : length ts ≡ Fun.m φ) → ------------------------- 𝕊 ⊢ fn ·★ ts , μ ≻ (!call (Fun.body φ) ts p) , μ ref-val : ∀ {t μ} → (v : Val t) → ---------------------------------------------------- 𝕊 ⊢ ref (tm t) , μ ≻ (tm (loc (length μ))) , (μ ∷ʳ (, v)) ≔-val : ∀ {i e μ} → (p : i < length μ) → (v : Val e) → -------------------------------------------- 𝕊 ⊢ (tm (loc i)) ≔ (tm e) , μ ≻ (tm unit) , (μ L.[ fromℕ≤ p ]≔ (, v)) !-val : ∀ {i μ} → (p : i < length μ) → ----------------------------------------- 𝕊 ⊢ ! (tm (loc i)) , μ ≻ tm (!load μ p) , μ ref-clos : ∀ {e e' μ μ'} → 𝕊 ⊢ e , μ ≻ e' , μ' → --------------------------- 𝕊 ⊢ ref e , μ ≻ ref e' , μ' !-clos : ∀ {e e' μ μ'} → 𝕊 ⊢ e , μ ≻ e' , μ' → ----------------------- 𝕊 ⊢ ! e , μ ≻ ! e' , μ' ≔-clos₁ : ∀ {x x' e μ μ'} → 𝕊 ⊢ x , μ ≻ x' , μ' → -------------------------- 𝕊 ⊢ x ≔ e , μ ≻ x' ≔ e , μ' ≔-clos₂ : ∀ {x e e' μ μ'} → ExpVal x → 𝕊 ⊢ e , μ ≻ e' , μ' → -------------------------- 𝕊 ⊢ x ≔ e , μ ≻ x ≔ e' , μ' infix 1 _⊢_≻ₛ_ data _⊢_≻ₛ_ (𝕊 : Sig) : (t t' : SeqExp 0 × Store) → Set where -- reductions lett-β : ∀ {t e μ} → ---------------------------------------------- 𝕊 ⊢ (lett (tm t) e) , μ ≻ₛ (e seq/ (sub t)) , μ -- contextual closure ret-clos : ∀ {e μ e' μ'} → 𝕊 ⊢ e , μ ≻ e' , μ' → ------------------------------------- 𝕊 ⊢ (ret e) , μ ≻ₛ (ret e') , μ' lett-clos : ∀ {x e x' μ μ'} → 𝕊 ⊢ x , μ ≻ x' , μ' → ------------------------------------- 𝕊 ⊢ (lett x e) , μ ≻ₛ (lett x' e) , μ' -- reflexive-transitive closure of ≻ open import Data.Star infix 1 _⊢_≻⋆_ _⊢_≻⋆_ : (Sig) → (c c' : SeqExp 0 × Store) → Set 𝕊 ⊢ c ≻⋆ c' = Star (_⊢_≻ₛ_ 𝕊) c c'
{ "alphanum_fraction": 0.3653846154, "avg_line_length": 30.5, "ext": "agda", "hexsha": "2fd9458b0f60fe475fe6857c0ec27dd12f08e07c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/Impure/LFRef/Eval.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/Impure/LFRef/Eval.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Impure/LFRef/Eval.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1231, "size": 3172 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.RingSolver.Examples where open import Cubical.Foundations.Prelude open import Cubical.Algebra.CommRing open import Cubical.Algebra.RingSolver.ReflectionSolving private variable ℓ : Level module Test (R : CommRing {ℓ}) where open CommRingStr (snd R) _ : 1r · (1r + 0r) ≡ (1r · 0r) + 1r _ = solve R _ : 1r · 0r + (1r - 1r) ≡ 0r - 0r _ = solve R _ : (x : fst R) → x ≡ x _ = solve R _ : (x y : fst R) → x ≡ x _ = solve R _ : (x y : fst R) → x + y ≡ y + x _ = solve R _ : (x y : fst R) → (x + y) · (x - y) ≡ x · x - y · y _ = solve R {- A bigger example, copied from the other example files: -} _ : (x y z : (fst R)) → (x + y) · (x + y) · (x + y) · (x + y) ≡ x · x · x · x + (fromℤ R 4) · x · x · x · y + (fromℤ R 6) · x · x · y · y + (fromℤ R 4) · x · y · y · y + y · y · y · y _ = solve R {- Keep in mind, that the solver can lead to wrong error locations. For example, the commented code below tries to solve an equation that does not hold, with the result of an error at the wrong location. _ : (x y : (fst R)) → x ≡ y _ = solve R -}
{ "alphanum_fraction": 0.5275526742, "avg_line_length": 23.7307692308, "ext": "agda", "hexsha": "60478cd49939e8c9d85b3f20a5609da0367c8613", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Algebra/RingSolver/Examples.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Algebra/RingSolver/Examples.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Algebra/RingSolver/Examples.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 479, "size": 1234 }
module Luau.RuntimeType.ToString where open import FFI.Data.String using (String) open import Luau.RuntimeType using (RuntimeType; function; number; nil) runtimeTypeToString : RuntimeType → String runtimeTypeToString function = "function" runtimeTypeToString number = "number" runtimeTypeToString nil = "nil"
{ "alphanum_fraction": 0.8135048232, "avg_line_length": 31.1, "ext": "agda", "hexsha": "be67ee0c61fc4b43bd7630474b87701ebaeb8baa", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Tr4shh/Roblox-Luau", "max_forks_repo_path": "prototyping/Luau/RuntimeType/ToString.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Tr4shh/Roblox-Luau", "max_issues_repo_path": "prototyping/Luau/RuntimeType/ToString.agda", "max_line_length": 71, "max_stars_count": null, "max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Tr4shh/Roblox-Luau", "max_stars_repo_path": "prototyping/Luau/RuntimeType/ToString.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 68, "size": 311 }
{-# OPTIONS --without-K --safe #-} module Categories.Category.Inverse where open import Level using (Level; suc; _⊔_) open import Categories.Category import Categories.Morphism record Inverse {o ℓ e} (C : Category o ℓ e) : Set (o ⊔ ℓ ⊔ e) where open Category C public open Definitions C public open Categories.Morphism C infix 10 _⁻¹ field _⁻¹ : ∀ {A B} → A ⇒ B → B ⇒ A pseudo-iso₁ : ∀ {A B} {f : A ⇒ B} → f ∘ f ⁻¹ ∘ f ≈ f pseudo-iso₂ : ∀ {A B} {f : A ⇒ B} → f ⁻¹ ∘ f ∘ f ⁻¹ ≈ f ⁻¹
{ "alphanum_fraction": 0.5949119374, "avg_line_length": 25.55, "ext": "agda", "hexsha": "acc10ed064723e971a4c7046bc4be2b8bd15e17f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-categories", "max_forks_repo_path": "src/Categories/Category/Inverse.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-categories", "max_issues_repo_path": "src/Categories/Category/Inverse.agda", "max_line_length": 67, "max_stars_count": null, "max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bblfish/agda-categories", "max_stars_repo_path": "src/Categories/Category/Inverse.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 197, "size": 511 }
{-# OPTIONS --without-K --safe #-} open import Level open import Categories.Category module Categories.Functor.Power.NaturalTransformation {o ℓ e : Level} (C : Category o ℓ e) where open import Data.Nat using (ℕ) open import Data.Fin using (Fin; inject+; raise) open import Data.Sum using (_⊎_; [_,_]′; inj₁; inj₂) open import Function using () renaming (_∘_ to _∙_) open import Function using () renaming (_∘_ to _∙_) open import Data.Product using (_,_) import Categories.Functor.Power as Power module Pow = Power C open Pow open import Categories.Functor.Bifunctor using (Bifunctor) -- open import Categories.Functor.Bifunctor.NaturalTransformation renaming (id to idⁿ; _≡_ to _≡ⁿ_) open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper; _∘ˡ_) open import Categories.Category.Product using (_※ⁿ_) open import Categories.Functor using (Functor; module Functor) flattenPⁿ : {D : Category o ℓ e} {m n : ℕ} {F G : Powerfunctor′ D (Fin m ⊎ Fin n)} (η : NaturalTransformation F G) → NaturalTransformation (flattenP F) (flattenP G) flattenPⁿ {m = m} {n} η = record { η = λ Xs → η.η (Xs ∙ pack) ; commute = λ fs → η.commute (fs ∙ pack) ; sym-commute = λ fs → η.sym-commute (fs ∙ pack) } where private module η = NaturalTransformation η pack = [ inject+ n , raise m ]′ reduceN′ : ∀ {i j : Level} {I : Set i} {J : Set j} {F F′ : Powerendo′ I} {G G′ : Powerendo′ J} (H : Bifunctor C C C) (φ : NaturalTransformation F F′) (γ : NaturalTransformation G G′) → NaturalTransformation (reduce′ H F G) (reduce′ H F′ G′) reduceN′ {I = I} {J} {F} {F′} {G} {G′} H φ γ = ntHelper record { η = my-η ; commute = λ {Xs Ys} → my-commute Xs Ys } where module C = Category C module F = Functor F module F′ = Functor F′ module G = Functor G module G′ = Functor G′ module φ = NaturalTransformation φ module γ = NaturalTransformation γ module H = Functor H module L = Functor (reduce′ H F G) module R = Functor (reduce′ H F′ G′) my-η : ∀ Xs → C [ L.F₀ Xs , R.F₀ Xs ] my-η Xs = H.F₁ ((φ.η (Xs ∙ inj₁)) , (γ.η (Xs ∙ inj₂))) my-commute : ∀ Xs Ys fs → C.CommutativeSquare (L.F₁ fs) (my-η Xs) (my-η Ys) (R.F₁ fs) my-commute Xs Ys fs = begin my-η Ys ∘ L.F₁ fs ≈˘⟨ H.homomorphism ⟩ H.F₁ ((φ.η _ ∘ F.F₁ _) , (γ.η _ ∘ G.F₁ _)) ≈⟨ H.F-resp-≈ ((φ.commute _) , (γ.commute _)) ⟩ H.F₁ ((F′.F₁ _ ∘ φ.η _) , (G′.F₁ _ ∘ γ.η _)) ≈⟨ H.homomorphism ⟩ R.F₁ fs ∘ my-η Xs ∎ where open C using (_∘_) open C.HomReasoning -- Giving the implicits below is not necessary, but makes typechecking faster reduceN : {m n : ℕ} {F F′ : Powerendo m} {G G′ : Powerendo n} (H : Bifunctor C C C) (φ : NaturalTransformation F F′) (γ : NaturalTransformation G G′) → NaturalTransformation (reduce H F G) (reduce H F′ G′) reduceN {F = f} {f′} {g} {g′} H φ γ = flattenPⁿ {F = reduce′ H f g} {G = reduce′ H f′ g′} (reduceN′ H φ γ) overlapN : {n : ℕ} {F F′ : Powerendo n} {G G′ : Powerendo n} (H : Bifunctor C C C) (φ : NaturalTransformation F F′) (γ : NaturalTransformation G G′) → NaturalTransformation (overlaps H F G) (overlaps H F′ G′) overlapN H φ γ = H ∘ˡ (φ ※ⁿ γ)
{ "alphanum_fraction": 0.6234855545, "avg_line_length": 42.3552631579, "ext": "agda", "hexsha": "3099ee79ec04251a1268f41bcea382b0b9923c01", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "MirceaS/agda-categories", "max_forks_repo_path": "src/Categories/Functor/Power/NaturalTransformation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "MirceaS/agda-categories", "max_issues_repo_path": "src/Categories/Functor/Power/NaturalTransformation.agda", "max_line_length": 126, "max_stars_count": null, "max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "MirceaS/agda-categories", "max_stars_repo_path": "src/Categories/Functor/Power/NaturalTransformation.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1174, "size": 3219 }
-- Record declarations can now contain arbitrary declarations. -- These are included in the projection module. module FancyRecordModule where data Nat : Set where zero : Nat suc : Nat -> Nat record Exist {A : Set}(P : A -> Set) : Set where field witness : A x = witness field proof : P x silly : Nat -> Nat silly zero = zero silly (suc n) = silly n postulate P : Nat -> Set e : Exist P data _==_ {A : Set}(x : A) : A -> Set where refl : x == x test : Exist.silly e (suc zero) == zero test = refl
{ "alphanum_fraction": 0.6287878788, "avg_line_length": 18.8571428571, "ext": "agda", "hexsha": "44d24285e498254af1f94e71cac576412caf99a7", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/FancyRecordModule.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/FancyRecordModule.agda", "max_line_length": 62, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/FancyRecordModule.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 164, "size": 528 }
module ExtendedLambdaCase where data Bool : Set where true false : Bool data Void : Set where foo : Bool -> Bool -> Bool -> Bool foo = λ { x → λ { y z → {!!} } } module parameterised {A : Set}(B : A -> Set) where data Bar : (Bool -> Bool) -> Set where baz : (t : Void) -> Bar λ { x → {!!} } -- with hidden argument data Bar' : (Bool -> Bool) -> Set where baz' : {t : Void} -> (t' : Void) -> Bar' λ { x' → {!!} } baz : Bool -> {w : Bool} -> Bool baz = λ { z {w} → {!!} } another-short-name : {A : Set} -> (A -> {x : A} -> A -> A) another-short-name = {! λ { a {x} b → a } !} f : Set f = (y : Bool) -> parameterised.Bar {Bool}(λ _ → Void) (λ { true → true ; false → false })
{ "alphanum_fraction": 0.5021398003, "avg_line_length": 23.3666666667, "ext": "agda", "hexsha": "8c9795ed77546ae6fc7bcf602965876c8e029384", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/interaction/ExtendedLambdaCase.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_path": "test/interaction/ExtendedLambdaCase.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/interaction/ExtendedLambdaCase.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 241, "size": 701 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Conversion of < to ≤, along with a number of properties ------------------------------------------------------------------------ -- Possible TODO: Prove that a conversion ≤ → < → ≤ returns a -- relation equivalent to the original one (and similarly for -- < → ≤ → <). {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Construct.StrictToNonStrict {a ℓ₁ ℓ₂} {A : Set a} (_≈_ : Rel A ℓ₁) (_<_ : Rel A ℓ₂) where open import Relation.Nullary open import Relation.Binary.Consequences open import Function open import Data.Product open import Data.Sum open import Data.Empty ------------------------------------------------------------------------ -- Conversion -- _<_ can be turned into _≤_ as follows: _≤_ : Rel A _ x ≤ y = (x < y) ⊎ (x ≈ y) ------------------------------------------------------------------------ -- The converted relations have certain properties -- (if the original relations have certain other properties) <⇒≤ : _<_ ⇒ _≤_ <⇒≤ = inj₁ reflexive : _≈_ ⇒ _≤_ reflexive = inj₂ antisym : IsEquivalence _≈_ → Transitive _<_ → Irreflexive _≈_ _<_ → Antisymmetric _≈_ _≤_ antisym eq trans irrefl = as where module Eq = IsEquivalence eq as : Antisymmetric _≈_ _≤_ as (inj₂ x≈y) _ = x≈y as (inj₁ _) (inj₂ y≈x) = Eq.sym y≈x as (inj₁ x<y) (inj₁ y<x) = ⊥-elim (trans∧irr⟶asym {_≈_ = _≈_} Eq.refl trans irrefl x<y y<x) trans : IsEquivalence _≈_ → _<_ Respects₂ _≈_ → Transitive _<_ → Transitive _≤_ trans eq (respʳ , respˡ) <-trans = tr where module Eq = IsEquivalence eq tr : Transitive _≤_ tr (inj₁ x<y) (inj₁ y<z) = inj₁ $ <-trans x<y y<z tr (inj₁ x<y) (inj₂ y≈z) = inj₁ $ respʳ y≈z x<y tr (inj₂ x≈y) (inj₁ y<z) = inj₁ $ respˡ (Eq.sym x≈y) y<z tr (inj₂ x≈y) (inj₂ y≈z) = inj₂ $ Eq.trans x≈y y≈z <-≤-trans : Transitive _<_ → _<_ Respectsʳ _≈_ → Trans _<_ _≤_ _<_ <-≤-trans trans respʳ x<y (inj₁ y<z) = trans x<y y<z <-≤-trans trans respʳ x<y (inj₂ y≈z) = respʳ y≈z x<y ≤-<-trans : Symmetric _≈_ → Transitive _<_ → _<_ Respectsˡ _≈_ → Trans _≤_ _<_ _<_ ≤-<-trans sym trans respˡ (inj₁ x<y) y<z = trans x<y y<z ≤-<-trans sym trans respˡ (inj₂ x≈y) y<z = respˡ (sym x≈y) y<z ≤-respʳ-≈ : Transitive _≈_ → _<_ Respectsʳ _≈_ → _≤_ Respectsʳ _≈_ ≤-respʳ-≈ trans respʳ y'≈y (inj₁ x<y') = inj₁ (respʳ y'≈y x<y') ≤-respʳ-≈ trans respʳ y'≈y (inj₂ x≈y') = inj₂ (trans x≈y' y'≈y) ≤-respˡ-≈ : Symmetric _≈_ → Transitive _≈_ → _<_ Respectsˡ _≈_ → _≤_ Respectsˡ _≈_ ≤-respˡ-≈ sym trans respˡ x'≈x (inj₁ x'<y) = inj₁ (respˡ x'≈x x'<y) ≤-respˡ-≈ sym trans respˡ x'≈x (inj₂ x'≈y) = inj₂ (trans (sym x'≈x) x'≈y) ≤-resp-≈ : IsEquivalence _≈_ → _<_ Respects₂ _≈_ → _≤_ Respects₂ _≈_ ≤-resp-≈ eq (respʳ , respˡ) = ≤-respʳ-≈ Eq.trans respʳ , ≤-respˡ-≈ Eq.sym Eq.trans respˡ where module Eq = IsEquivalence eq total : Trichotomous _≈_ _<_ → Total _≤_ total <-tri x y with <-tri x y ... | tri< x<y x≉y x≯y = inj₁ (inj₁ x<y) ... | tri≈ x≮y x≈y x≯y = inj₁ (inj₂ x≈y) ... | tri> x≮y x≉y x>y = inj₂ (inj₁ x>y) decidable : Decidable _≈_ → Decidable _<_ → Decidable _≤_ decidable ≈-dec <-dec x y with ≈-dec x y | <-dec x y ... | yes x≈y | _ = yes (inj₂ x≈y) ... | no x≉y | yes x<y = yes (inj₁ x<y) ... | no x≉y | no x≮y = no [ x≮y , x≉y ]′ decidable' : Trichotomous _≈_ _<_ → Decidable _≤_ decidable' compare x y with compare x y ... | tri< x<y _ _ = yes (inj₁ x<y) ... | tri≈ _ x≈y _ = yes (inj₂ x≈y) ... | tri> x≮y x≉y _ = no [ x≮y , x≉y ]′ ------------------------------------------------------------------------ -- Converting structures isPreorder₁ : IsPreorder _≈_ _<_ → IsPreorder _≈_ _≤_ isPreorder₁ PO = record { isEquivalence = S.isEquivalence ; reflexive = reflexive ; trans = trans S.isEquivalence S.∼-resp-≈ S.trans } where module S = IsPreorder PO isPreorder₂ : IsStrictPartialOrder _≈_ _<_ → IsPreorder _≈_ _≤_ isPreorder₂ SPO = record { isEquivalence = S.isEquivalence ; reflexive = reflexive ; trans = trans S.isEquivalence S.<-resp-≈ S.trans } where module S = IsStrictPartialOrder SPO isPartialOrder : IsStrictPartialOrder _≈_ _<_ → IsPartialOrder _≈_ _≤_ isPartialOrder SPO = record { isPreorder = isPreorder₂ SPO ; antisym = antisym S.isEquivalence S.trans S.irrefl } where module S = IsStrictPartialOrder SPO isTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsTotalOrder _≈_ _≤_ isTotalOrder STO = record { isPartialOrder = isPartialOrder S.isStrictPartialOrder ; total = total S.compare } where module S = IsStrictTotalOrder STO isDecTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsDecTotalOrder _≈_ _≤_ isDecTotalOrder STO = record { isTotalOrder = isTotalOrder STO ; _≟_ = S._≟_ ; _≤?_ = decidable' S.compare } where module S = IsStrictTotalOrder STO
{ "alphanum_fraction": 0.5866230313, "avg_line_length": 33.2585034014, "ext": "agda", "hexsha": "3815980be349b86c2fb4d628b8584cf57c463c6e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/StrictToNonStrict.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/StrictToNonStrict.agda", "max_line_length": 88, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/StrictToNonStrict.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1952, "size": 4889 }
record R : Set₂ where field f : Set₁ f : Set → R f .R.f = Set
{ "alphanum_fraction": 0.5362318841, "avg_line_length": 9.8571428571, "ext": "agda", "hexsha": "b4c7d64728a8c673e6a56f1cbfa8ab3449a1a928", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue2928.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue2928.agda", "max_line_length": 21, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue2928.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 29, "size": 69 }
------------------------------------------------------------------------ -- The Agda standard library -- -- An explanation about how to use the solver in Tactic.MonoidSolver. ------------------------------------------------------------------------ open import Algebra module README.Tactic.MonoidSolver {a ℓ} (M : Monoid a ℓ) where open Monoid M open import Data.Nat as Nat using (ℕ; suc; zero; _+_) open import Data.Nat.Properties as Properties using (+-0-monoid; +-comm) open import Relation.Binary.Reasoning.Setoid setoid open import Tactic.MonoidSolver using (solve; solve-macro) -- The monoid solver is capable to of solving equations without having -- to specify the equation itself in the proof. example₁ : ∀ x y z → (x ∙ y) ∙ z ≈ x ∙ (y ∙ z) ∙ ε example₁ x y z = solve M -- The solver can also be used in equational reasoning. example₂ : ∀ w x y z → w ≈ x → (w ∙ y) ∙ z ≈ x ∙ (y ∙ z) ∙ ε example₂ w x y z w≈x = begin (w ∙ y) ∙ z ≈⟨ ∙-congʳ (∙-congʳ w≈x) ⟩ (x ∙ y) ∙ z ≈⟨ solve M ⟩ x ∙ (y ∙ z) ∙ ε ∎
{ "alphanum_fraction": 0.5571705426, "avg_line_length": 32.25, "ext": "agda", "hexsha": "530091bc97a85a9a89d7ea42e5b5aa52ffa5ca10", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/README/Tactic/MonoidSolver.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/README/Tactic/MonoidSolver.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/README/Tactic/MonoidSolver.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 326, "size": 1032 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Optics.All open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Base.KVMap open import LibraBFT.Base.PKCS open import LibraBFT.Impl.Base.Types open import LibraBFT.Impl.NetworkMsg open import LibraBFT.Impl.Consensus.Types open import LibraBFT.Impl.Util.Crypto open import LibraBFT.Impl.Handle open import LibraBFT.Impl.Handle.Properties open import LibraBFT.Concrete.System.Parameters open import LibraBFT.Concrete.System open EpochConfig open import LibraBFT.Yasm.Types open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms PeerCanSignForPK (λ {st} {part} {pk} → PeerCanSignForPK-stable {st} {part} {pk}) -- In this module, we define two "implementation obligations" -- (ImplObligationᵢ for i ∈ {1 , 2}), which are predicates over -- reachable states of a system defined by -- 'LibraBFT.Concrete.System.Parameters'. These two properties relate -- votes sent by the same sender, ensuring that if they are for the -- same epoch and round, then they vote for the same blockID; the -- first relates a vote output by the handler to a vote sent -- previously, and the second relates two votes both sent by the -- handler. -- -- We then prove that, if an implementation satisfies these two -- semantic obligations, along with a structural one about messages -- sent by honest peers in the implementation, then the implemenation -- satisfies the LibraBFT.Abstract.Properties.VotesOnce invariant. module LibraBFT.Concrete.Properties.VotesOnce where -- TODO-3: This may not be the best way to state the implementation obligation. Why not reduce -- this as much as possible before giving the obligation to the implementation? For example, this -- will still require the implementation to deal with hash collisons (v and v' could be different, -- but yield the same bytestring and therefore same signature). Also, avoid the need for the -- implementation to reason about messages sent by step-cheat, or give it something to make this -- case easy to eliminate. ImplObligation₁ : Set (ℓ+1 ℓ-RoundManager) ImplObligation₁ = ∀{pid pid' s' outs pk}{pre : SystemState} → ReachableSystemState pre -- For any honest call to /handle/ or /init/, → (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs)) → ∀{v m v' m'} → Meta-Honest-PK pk -- For signed every vote v of every outputted message → v ⊂Msg m → send m ∈ outs → (sig : WithVerSig pk v) → ¬ (∈GenInfo (ver-signature sig)) -- If v is really new and valid → ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v pid pk -- And if there exists another v' that has been sent before → v' ⊂Msg m' → (pid' , m') ∈ (msgPool pre) → (sig' : WithVerSig pk v') → ¬ (∈GenInfo (ver-signature sig')) -- If v and v' share the same epoch and round → v ^∙ vEpoch ≡ v' ^∙ vEpoch → v ^∙ vRound ≡ v' ^∙ vRound ---------------------------------------------------------- -- Then an honest implemenation promises v and v' vote for the same blockId. → v ^∙ vProposedId ≡ v' ^∙ vProposedId ImplObligation₂ : Set (ℓ+1 ℓ-RoundManager) ImplObligation₂ = ∀{pid s' outs pk}{pre : SystemState} → ReachableSystemState pre -- For any honest call to /handle/ or /init/, → (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs)) → ∀{v m v' m'} → Meta-Honest-PK pk -- For every vote v represented in a message output by the call → v ⊂Msg m → send m ∈ outs → (sig : WithVerSig pk v) → ¬ (∈GenInfo (ver-signature sig)) -- If v is really new and valid → ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v pid pk -- And if there exists another v' that is also new and valid → v' ⊂Msg m' → send m' ∈ outs → (sig' : WithVerSig pk v') → ¬ (∈GenInfo (ver-signature sig')) → ¬ (MsgWithSig∈ pk (ver-signature sig') (msgPool pre)) → PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v' pid pk -- If v and v' share the same epoch and round → v ^∙ vEpoch ≡ v' ^∙ vEpoch → v ^∙ vRound ≡ v' ^∙ vRound ---------------------------------------------------------- -- Then, an honest implemenation promises v and v' vote for the same blockId. → v ^∙ vProposedId ≡ v' ^∙ vProposedId -- Next, we prove that, given the necessary obligations, module Proof (sps-corr : StepPeerState-AllValidParts) (Impl-VO1 : ImplObligation₁) (Impl-VO2 : ImplObligation₂) where -- Any reachable state satisfies the VO rule for any epoch in the system. module _ (st : SystemState)(r : ReachableSystemState st)(𝓔 : EpochConfig) where open Structural sps-corr -- Bring in IntSystemState open WithSPS sps-corr open PerState st r open PerEpoch 𝓔 open import LibraBFT.Concrete.Obligations.VotesOnce 𝓔 (ConcreteVoteEvidence 𝓔) as VO -- The VO proof is done by induction on the execution trace leading to 'st'. In -- Agda, this is 'r : RechableSystemState st' above. private -- From this point onwards, it might be easier to read this proof starting at 'voo' -- at the end of the file. Next, we provide an overview the proof. -- -- We wish to prove that, for any two votes v and v' cast by an honest α in the message -- pool of a state st, if v and v' have equal rounds and epochs, then they vote for the -- same block. -- -- The base case and the case for a new epoch in the system are trivial. For the base case -- we get to a contradiction because it's not possible to have any message in the msgpool. -- -- Regarding the PeerStep case. The induction hypothesis tells us that the property holds -- in the pre-state. Next, we reason about the post-state. We start by analyzing whether -- v and v' have been sent as outputs of the PeerStep under scrutiny or were already in -- the pool before. -- -- There are four possibilities: -- -- i) v and v' were aleady present in the msgPool before: use induction hypothesis. -- ii) v and v' are both in the output produced by the PeerStep under scrutiny. -- iii) v was present before, but v' is new. -- iv) v' was present before, but v is new. -- -- In order to obtain this four possiblities we invoke newMsg⊎msgSent4 lemma, which -- receives proof that some vote is in a message that is in the msgPool of the post state -- and returns evidence that either the vote is new or that some message with the same -- signature was sent before. -- -- Case (i) is trivial; cases (iii) and (iv) are symmetric and reduce to an implementation -- obligation (Impl-VO1) and case (ii) reduces to a different implementation obligation -- (Impl-VO2). VotesOnceProof : ∀ {v v' pk} {st : SystemState} → ReachableSystemState st → Meta-Honest-PK pk → (vv : WithVerSig pk v) → MsgWithSig∈ pk (ver-signature vv) (msgPool st) → (vv' : WithVerSig pk v') → MsgWithSig∈ pk (ver-signature vv') (msgPool st) → v ^∙ vEpoch ≡ v' ^∙ vEpoch → v ^∙ vRound ≡ v' ^∙ vRound → v ^∙ vProposedId ≡ v' ^∙ vProposedId VotesOnceProof step-0 _ _ msv _ _ _ _ = ⊥-elim (¬Any[] (msg∈pool msv)) VotesOnceProof {v} {v'} (step-s r theStep) pkH vv msv vv' msv' eid≡ r≡ with msgSameSig msv | msgSameSig msv' ...| refl | refl with sameSig⇒sameVoteDataNoCol (msgSigned msv) vv (msgSameSig msv ) | sameSig⇒sameVoteDataNoCol (msgSigned msv') vv' (msgSameSig msv') ...| refl | refl with ∈GenInfo? (₋vSignature (msgPart msv)) | ∈GenInfo? (₋vSignature (msgPart msv')) ...| yes init | yes init' = genVotesConsistent (msgPart msv) (msgPart msv') init init' -- A signature in GenInfo is for a vote with round 0, and a signature for which we have a -- MsgWithSig∈ that is not in GenInfo and is for an honest PK is for a round ≢ 0, so we can -- derive a contradiction using r≡. ...| yes init | no ¬init = ⊥-elim (¬genVotesRound≢0 (step-s r theStep) pkH msv' ¬init ((trans (sym r≡) (genVotesRound≡0 vv init)))) ...| no ¬init | yes init = ⊥-elim (¬genVotesRound≢0 (step-s r theStep) pkH msv ¬init ((trans r≡ (genVotesRound≡0 vv' init)))) ...| no ¬init | no ¬init' with theStep ...| step-peer cheat@(step-cheat c) with ¬cheatForgeNew cheat refl unit pkH msv ¬init | ¬cheatForgeNew cheat refl unit pkH msv' ¬init' ...| msb4 | m'sb4 with msgSameSig msb4 | msgSameSig m'sb4 ...| refl | refl = VotesOnceProof r pkH vv msb4 vv' m'sb4 eid≡ r≡ VotesOnceProof (step-s r theStep) pkH vv msv vv' msv' eid≡ r≡ | refl | refl | refl | refl | no ¬init | no ¬init' | step-peer (step-honest stPeer) with newMsg⊎msgSentB4 r stPeer pkH (msgSigned msv) ¬init (msg⊆ msv) (msg∈pool msv) | newMsg⊎msgSentB4 r stPeer pkH (msgSigned msv') ¬init' (msg⊆ msv') (msg∈pool msv') ...| inj₂ msb4 | inj₂ m'sb4 = VotesOnceProof r pkH vv msb4 vv' m'sb4 eid≡ r≡ ...| inj₁ (m∈outs , vspk , newV) | inj₁ (m'∈outs , v'spk , newV') = Impl-VO2 r stPeer pkH (msg⊆ msv) m∈outs (msgSigned msv) ¬init newV vspk (msg⊆ msv') m'∈outs (msgSigned msv') ¬init' newV' v'spk eid≡ r≡ ...| inj₁ (m∈outs , vspk , newV) | inj₂ m'sb4 with sameSig⇒sameVoteData (msgSigned m'sb4) vv' (msgSameSig m'sb4) ...| inj₁ hb = ⊥-elim (meta-sha256-cr hb) ...| inj₂ refl rewrite sym (msgSameSig msv') = Impl-VO1 r stPeer pkH (msg⊆ msv) m∈outs (msgSigned msv) ¬init newV vspk (msg⊆ m'sb4) (msg∈pool m'sb4) (msgSigned m'sb4) (¬subst ¬init' (msgSameSig m'sb4)) eid≡ r≡ VotesOnceProof (step-s r theStep) pkH vv msv vv' msv' eid≡ r≡ | refl | refl | refl | refl | no ¬init | no ¬init' | step-peer (step-honest stPeer) | inj₂ msb4 | inj₁ (m'∈outs , v'spk , newV') with sameSig⇒sameVoteData (msgSigned msb4) vv (msgSameSig msb4) ...| inj₁ hb = ⊥-elim (meta-sha256-cr hb) ...| inj₂ refl = sym (Impl-VO1 r stPeer pkH (msg⊆ msv') m'∈outs (msgSigned msv') ¬init' newV' v'spk (msg⊆ msb4) (msg∈pool msb4) (msgSigned msb4) (¬subst ¬init (msgSameSig msb4)) (sym eid≡) (sym r≡)) voo : VO.Type IntSystemState voo hpk refl sv refl sv' round≡ with vmsg≈v (vmFor sv) | vmsg≈v (vmFor sv') ...| refl | refl = let ver = vmsgSigned (vmFor sv) mswsv = mkMsgWithSig∈ (nm (vmFor sv)) (cv (vmFor sv)) (cv∈nm (vmFor sv)) _ (nmSentByAuth sv) (vmsgSigned (vmFor sv)) refl ver' = vmsgSigned (vmFor sv') mswsv' = mkMsgWithSig∈ (nm (vmFor sv')) (cv (vmFor sv')) (cv∈nm (vmFor sv')) _ (nmSentByAuth sv') (vmsgSigned (vmFor sv')) refl epoch≡ = trans (vmsgEpoch (vmFor sv)) (sym (vmsgEpoch (vmFor sv'))) in VotesOnceProof r hpk ver mswsv ver' mswsv' epoch≡ round≡
{ "alphanum_fraction": 0.644561867, "avg_line_length": 50.4666666667, "ext": "agda", "hexsha": "5903026568cb11255c60d117dc35ff26299aea13", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "cwjnkins/bft-consensus-agda", "max_forks_repo_path": "LibraBFT/Concrete/Properties/VotesOnce.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "cwjnkins/bft-consensus-agda", "max_issues_repo_path": "LibraBFT/Concrete/Properties/VotesOnce.agda", "max_line_length": 146, "max_stars_count": null, "max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "cwjnkins/bft-consensus-agda", "max_stars_repo_path": "LibraBFT/Concrete/Properties/VotesOnce.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3645, "size": 11355 }
-- exercises-04-thursday.agda open import mylib -- 1. Coinduction {- Now your task is to define multiplication _*∞_ for conatural numbers. This is harder then it sounds. Why? Because to check termination of corecursive programs agda needs to make sure that if you want to find out a finite amout of information about the result of the function it only needs a finite amount of information about its inputs. Such a function is called productive. And agda isn't very clever in figuring this out, it has to be obvious from the program (similar as structural recursion has to be obviously structural). You should *not* use the TERMINATING pragma in your solution. But it may be useful for experiments. _*_ : ℕ → ℕ → ℕ zero * n = zero suc m * n = n + m * n -} {- _*∞_ : ℕ∞ → ℕ∞ → ℕ∞ m *∞ n = {!!} -} aux : ℕ∞ → ℕ∞ → ℕ∞ → ℕ∞ -- aux l m n = l +∞ (m *∞ n) pred∞ (aux l m n) with pred∞ l pred∞ (aux l m n) | nothing with pred∞ m pred∞ (aux l m n) | nothing | nothing = nothing pred∞ (aux l m n) | nothing | just m' with pred∞ n pred∞ (aux l m n) | nothing | just m' | nothing = nothing pred∞ (aux l m n) | nothing | just m' | just n' = just (aux n' m' n) pred∞ (aux l m n) | just l' = just (aux l' m n) {-# TERMINATING #-} _*∞_ : ℕ∞ → ℕ∞ → ℕ∞ m *∞ n = aux zero∞ m n {- pred∞ (m *∞ n) with pred∞ m ... | nothing = nothing ... | just m' with pred∞ n ... | nothing = nothing ... | just n' = just (n' +∞ (m' *∞ n)) -} {- with pred∞ m ...| nothing = zero∞ ...| just m' with pred∞ n ...| nothing = zero∞ ...| just n' = n' +∞ (m' *∞ n) -} -- pred∞ (∞ *∞ zero∞) = nothing -- here are some testing tools ℕ→ℕ∞ : ℕ → ℕ∞ ℕ→ℕ∞ zero = zero∞ ℕ→ℕ∞ (suc n) = suc∞ (ℕ→ℕ∞ n) {-# TERMINATING #-} -- a lie -- this function is a cheat - it doesn't terminate for ∞ ℕ∞→ℕ : ℕ∞ → ℕ ℕ∞→ℕ n with pred∞ n ℕ∞→ℕ n | nothing = 0 ℕ∞→ℕ n | just n' = suc (ℕ∞→ℕ n') -- My unit-test x3*5 = ℕ∞→ℕ (ℕ→ℕ∞ 3 *∞ ℕ→ℕ∞ 5) -- 2. Dependent types Fin {- Define the following operations on Fin - max returns the largest element in Fin (suc n) - emb embeds Fin n into Fin (suc n) without changing its values - inv inverts the order of elements in Fin n -} max : (n : ℕ) → Fin (suc n) max zero = zero max (suc n) = suc (max n) emb : {n : ℕ} → Fin n → Fin (suc n) emb zero = zero emb (suc m) = suc (emb m) inv : {n : ℕ} → Fin n → Fin n inv zero = max _ inv (suc i) = emb (inv i) -- 2. Dependent types : Vec Vector : ℕ → Set {- Vec n is an n-dimensional vector -} Vector m = Vec ℕ m Matrix : ℕ → ℕ → Set {- Matrix m n is an m x n Matrix -} Matrix m n = Vec (Vector n) m m3 : Matrix 3 3 m3 = (1 ∷ 2 ∷ 3 ∷ []) ∷ (4 ∷ 5 ∷ 6 ∷ []) ∷ (7 ∷ 8 ∷ 9 ∷ []) ∷ [] m4 : Matrix 3 2 m4 = (1 ∷ 2 ∷ []) ∷ (4 ∷ 5 ∷ []) ∷ (7 ∷ 8 ∷ []) ∷ [] -- Define the operation transpose which switches columns and rows. -- Applicative functor, Vec _ n is an applicative functor -- mapVec : (A → B) → Vec A n → Vec B n -- return : A → Vec A n -- app : Vec (A → B) n → Vec A n → Vec B n -- mapVec f as = app (return f) as return : {A : Set}{n : ℕ} → A → Vec A n return {n = zero} a = [] return {n = suc m} a = a ∷ return {n = m} a app : {A B : Set}{n : ℕ} → Vec (A → B) n → Vec A n → Vec B n app [] [] = [] app (a2b ∷ a2bs) (a ∷ as) = a2b a ∷ app a2bs as transpose : {m n : ℕ} → Matrix m n → Matrix n m transpose [] = return [] transpose (ns ∷ mns) = app (app (return _∷_) ns) (transpose mns) {- transpose : {m n : ℕ} → Matrix m n → Matrix n m transpose [] = {!!} -- [ [] , [] , [] ] m empty rows transpose (ns ∷ mns) = {!transpose mns!} -} -- if ns = [1 , 2 , 3] -- transpose mns = [ns1 , ns2 , ns3] => [1 ∷ ns1 , 2 ∷ ns2 , 3 ∷ ns3] test8 : Matrix 2 3 test8 = transpose m4 test9 : Matrix 3 3 test9 = transpose m3
{ "alphanum_fraction": 0.5603402446, "avg_line_length": 25.5918367347, "ext": "agda", "hexsha": "bc856e22366d175a99d9f5e8e00ac46eca63957e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "FoxySeta/mgs-2021", "max_forks_repo_path": "Type Theory/exercises-04-thursday.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534", "max_issues_repo_issues_event_max_datetime": "2021-07-14T20:35:48.000Z", "max_issues_repo_issues_event_min_datetime": "2021-07-14T20:34:53.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "FoxySeta/mgs-2021", "max_issues_repo_path": "Type Theory/exercises-04-thursday.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FoxySeta/mgs-2021", "max_stars_repo_path": "Type Theory/exercises-04-thursday.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1492, "size": 3762 }
module Async where open import Data.Fin open import Data.List hiding (drop) open import Data.List.All open import Typing renaming (send to ssend ; recv to srecv) open import Syntax open import Values -- an asynchronous channel is a promise for a channel ASession DSession : STypeF SType → STypeF SType ASession s = srecv (TChan s) (delay send!) DSession s = dualF (ASession s) AChan DChan : STypeF SType → Type AChan s = TChan (ASession s) DChan s = TChan (DSession s) Promise : (s : SType) → Type Promise s = TPair (AChan (SType.force s)) (DChan (SType.force s)) new-promise : ∀ {Φ} → All Unr Φ → (s : SType) → Expr Φ (Promise s) new-promise unr-Φ s = new unr-Φ (delay (ASession (SType.force s))) -- create an async channel anew : ∀ {Φ} → (unr-Φ : All Unr Φ) → (s : SType) → Expr Φ (TPair (AChan (SType.force s)) (AChan (SType.force (dual s)))) anew unr-Φ s = letbind (split-all-unr unr-Φ) (new unr-Φ s) (letpair (left (split-all-unr unr-Φ)) (here unr-Φ) (letbind (rght (rght (split-all-unr unr-Φ))) (new-promise unr-Φ s) (letpair (left (rght (rght (split-all-unr unr-Φ)))) (here unr-Φ) (letbind (rght (rght (rght (rght (split-all-unr unr-Φ))))) (new-promise unr-Φ (dual s)) (letpair (left (rght (rght (rght (rght (split-all-unr unr-Φ)))))) (here unr-Φ) (letbind (rght (rght (rght (left (left (rght (split-all-unr unr-Φ))))))) (fork (letbind (left (left (split-all-unr unr-Φ))) (send (left (rght (split-all-unr unr-Φ))) (here unr-Φ) (here unr-Φ)) (wait (here unr-Φ)))) (letbind (drop UUnit (rght (left (rght (left (split-all-unr unr-Φ)))))) (fork (letbind (left (left (split-all-unr unr-Φ))) (send (left (rght (split-all-unr unr-Φ))) (here unr-Φ) (here unr-Φ)) (wait (here unr-Φ)))) (pair (drop UUnit (rght (left (split-all-unr unr-Φ)))) (here unr-Φ) (here unr-Φ))))))))) asend : ∀ {Φ Φ₁ Φ₂ s t} → (sp : Split Φ Φ₁ Φ₂) → (ch : (AChan (ssend t s)) ∈ Φ₁) → (vt : t ∈ Φ₂) → Expr Φ (AChan (SType.force s)) asend {Φ} {s = s} sp ch vt = letbind (split-all-right Φ) (new-promise [] s) (letpair (left (split-all-right Φ)) (here []) (letbind (rght (left (split-all-left Φ))) -- read actual channel & actual send & send depleted channel & close (fork (letbind (rght sp) (recv ch) (letpair (left (split-all-right _)) (here []) (letbind (left (split-all-right _)) (close (here [])) (letbind (drop UUnit (left (rght (split-all-left _)))) (send (left (split-all-right _)) (here []) vt) (letbind (left (left [])) (send (rght (left [])) (here []) (here [])) (letbind (left []) (wait (here [])) (var (here []))))))))) (var (there UUnit (here []))))) -- receive is a blocking operation! arecv : ∀ {Φ s t} → (ch : (AChan (srecv t s)) ∈ Φ) → Expr Φ (TPair (AChan (SType.force s)) t) arecv {s = s} ch = letbind (split-all-right _) (new-promise [] s) (letpair (left (split-all-right _)) (here []) (letbind (rght (rght (split-all-left _))) (recv ch) (letpair (left (rght (rght (split-all-right _)))) (here []) (letbind (left (rght (rght (rght [])))) (close (here [])) (letbind (drop UUnit (left (rght (rght [])))) (recv (here [])) (letpair (left (rght (rght []))) (here []) (letbind (left (rght (rght (left [])))) (fork (letbind (left (left [])) (send (rght (left [])) (here []) (here [])) (wait (here [])))) (pair (drop UUnit (rght (left []))) (here []) (here []))))))))) aclose : ∀ {Φ} → (ch : AChan send! ∈ Φ) → Expr Φ TUnit aclose ch = fork (letbind (split-all-left _) (recv ch) (letpair (left []) (here []) (letbind (left (rght [])) (close (here [])) (close (there UUnit (here [])))))) await : ∀ {Φ} → (ch : AChan send? ∈ Φ) → Expr Φ TUnit await ch = fork (letbind (split-all-left _) (recv ch) (letpair (left []) (here []) (letbind (left (rght [])) (close (here [])) (wait (there UUnit (here [])))))) anselect : ∀ {Φ m alt} → (lab : Fin m) → (ch : AChan (sintN m alt) ∈ Φ) → Expr Φ (AChan (SType.force (alt lab))) anselect {alt = alt} lab ch = letbind (split-all-right _) (new-promise [] (alt lab)) (letpair (left (split-all-right _)) (here []) (letbind (rght (left (split-all-left _))) (fork (letbind (rght (split-all-left _)) (recv ch) (letpair (left (rght [])) (here []) (letbind (left (rght (rght []))) (close (here [])) (letbind (drop UUnit (left (rght []))) (nselect lab (here [])) (letbind (left (left [])) (send (rght (left [])) (here []) (here [])) (wait (here [])))))))) (var (there UUnit (here []))))) -- branching is a blocking operation! anbranch : ∀ {Φ m alt Φ₁ Φ₂ t} → (sp : Split Φ Φ₁ Φ₂) → (ch : AChan (sextN m alt) ∈ Φ₁) → (ealts : (i : Fin m) → Expr (AChan (SType.force (alt i)) ∷ Φ₂) t) → Expr Φ t anbranch{alt = alt} sp ch ealts = letbind sp (recv ch) (letpair (left (split-all-right _)) (here []) (letbind (left (split-all-right _)) (close (here [])) (nbranch (drop UUnit (left (split-all-right _))) (here []) (λ i → letbind (split-all-right _) (new-promise [] (alt i)) (letpair (left (split-all-right _)) (here []) (letbind (rght (left (left (split-all-right _)))) (fork (letbind (left (left [])) (send (left (rght [])) (here []) (here [])) (wait (here [])))) (letbind (drop UUnit (left (split-all-right _))) (var (here [])) (ealts i))))))))
{ "alphanum_fraction": 0.5411558669, "avg_line_length": 41.3768115942, "ext": "agda", "hexsha": "8fc9e8f7868d8efff6a5ffb3ce03d7230bfb5c40", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "peterthiemann/definitional-session", "max_forks_repo_path": "src/Async.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "peterthiemann/definitional-session", "max_issues_repo_path": "src/Async.agda", "max_line_length": 130, "max_stars_count": 9, "max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "peterthiemann/definitional-session", "max_stars_repo_path": "src/Async.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z", "num_tokens": 1979, "size": 5710 }
module Sessions.Semantics where
{ "alphanum_fraction": 0.875, "avg_line_length": 16, "ext": "agda", "hexsha": "a807776e63d21292fbe13445fd399d1c061e064c", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Sessions/Semantics.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_path": "src/Sessions/Semantics.agda", "max_line_length": 31, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Sessions/Semantics.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 7, "size": 32 }
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Monoidal.Properties where open import Level open import Data.Product using (_,_) open import Categories.Category open import Categories.Category.Monoidal open import Categories.Category.Cartesian.Structure open import Categories.Functor renaming (id to idF) open import Categories.Functor.Properties open import Categories.Functor.Cartesian open import Categories.Functor.Monoidal open import Categories.Functor.Monoidal.Braided as Braided open import Categories.Functor.Monoidal.Symmetric as Symmetric open import Categories.NaturalTransformation import Categories.Object.Terminal as ⊤ import Categories.Object.Product as P import Categories.Morphism as M import Categories.Morphism.Reasoning as MR private variable o o′ o″ ℓ ℓ′ ℓ″ e e′ e″ : Level -- The identity functor is monoidal module _ (C : MonoidalCategory o ℓ e) where private module C = MonoidalCategory C open C.HomReasoning open M C.U open MR C.U idF-IsStrongMonoidal : IsStrongMonoidalFunctor C C idF idF-IsStrongMonoidal = record { ε = ≅.refl ; ⊗-homo = record { F⇒G = record { η = λ _ → C.id ; commute = λ _ → id-comm-sym ; sym-commute = λ _ → id-comm } ; F⇐G = record { η = λ _ → C.id ; commute = λ _ → id-comm-sym ; sym-commute = λ _ → id-comm } ; iso = λ _ → record { isoˡ = C.identity² ; isoʳ = C.identity² } } ; associativity = begin C.associator.from C.∘ C.id C.∘ Functor.F₁ C.⊗ (C.id , C.id) ≈⟨ refl⟩∘⟨ elimʳ C.⊗.identity ⟩ C.associator.from C.∘ C.id ≈⟨ id-comm ⟩ C.id C.∘ C.associator.from ≈⟨ refl⟩∘⟨ introˡ C.⊗.identity ⟩ C.id C.∘ Functor.F₁ C.⊗ (C.id , C.id) C.∘ C.associator.from ∎ ; unitaryˡ = elimʳ (elimʳ C.⊗.identity) ; unitaryʳ = elimʳ (elimʳ C.⊗.identity) } idF-IsMonoidal : IsMonoidalFunctor C C idF idF-IsMonoidal = IsStrongMonoidalFunctor.isMonoidal idF-IsStrongMonoidal idF-StrongMonoidal : StrongMonoidalFunctor C C idF-StrongMonoidal = record { isStrongMonoidal = idF-IsStrongMonoidal } idF-Monoidal : MonoidalFunctor C C idF-Monoidal = record { isMonoidal = idF-IsMonoidal } -- The identity functor is braided monoidal module _ (C : BraidedMonoidalCategory o ℓ e) where open Braided idF-IsStrongBraidedMonoidal : Strong.IsBraidedMonoidalFunctor C C idF idF-IsStrongBraidedMonoidal = record { isStrongMonoidal = idF-IsStrongMonoidal monoidalCategory ; braiding-compat = MR.id-comm U } where open BraidedMonoidalCategory C idF-IsBraidedMonoidal : Lax.IsBraidedMonoidalFunctor C C idF idF-IsBraidedMonoidal = Strong.IsBraidedMonoidalFunctor.isLaxBraidedMonoidal idF-IsStrongBraidedMonoidal idF-StrongBraidedMonoidal : Strong.BraidedMonoidalFunctor C C idF-StrongBraidedMonoidal = record { isBraidedMonoidal = idF-IsStrongBraidedMonoidal } idF-BraidedMonoidal : Lax.BraidedMonoidalFunctor C C idF-BraidedMonoidal = record { isBraidedMonoidal = idF-IsBraidedMonoidal } -- The identity functor is symmetric monoidal module _ (C : SymmetricMonoidalCategory o ℓ e) where open Symmetric open SymmetricMonoidalCategory C using (braidedMonoidalCategory) idF-StrongSymmetricMonoidal : Strong.SymmetricMonoidalFunctor C C idF-StrongSymmetricMonoidal = record { isBraidedMonoidal = idF-IsStrongBraidedMonoidal braidedMonoidalCategory } idF-SymmetricMonoidal : Lax.SymmetricMonoidalFunctor C C idF-SymmetricMonoidal = record { isBraidedMonoidal = idF-IsBraidedMonoidal braidedMonoidalCategory } -- Functor composition preserves monoidality module _ (A : MonoidalCategory o ℓ e) (B : MonoidalCategory o′ ℓ′ e′) (C : MonoidalCategory o″ ℓ″ e″) where private module A = MonoidalCategory A module B = MonoidalCategory B module C = MonoidalCategory C open P C.U open M C.U open C.HomReasoning open MR C.U ∘-IsMonoidal : ∀ {F : Functor A.U B.U} {G : Functor B.U C.U} → IsMonoidalFunctor B C G → IsMonoidalFunctor A B F → IsMonoidalFunctor A C (G ∘F F) ∘-IsMonoidal {F} {G} CG CF = record { ε = G.₁ CF.ε C.∘ CG.ε ; ⊗-homo = ntHelper record { η = λ { (X , Y) → G.₁ (CF.⊗-homo.η (X , Y)) C.∘ CG.⊗-homo.η (F.F₀ X , F.F₀ Y) } ; commute = λ { (f , g) → begin (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ (G.₁ (F.₁ f) C.⊗₁ G.₁ (F.₁ g)) ≈⟨ C.assoc ⟩ G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _ C.∘ (G.₁ (F.₁ f) C.⊗₁ G.₁ (F.₁ g)) ≈⟨ pushʳ (CG.⊗-homo.commute _) ⟩ (G.₁ (CF.⊗-homo.η _) C.∘ G.₁ (F.₁ f B.⊗₁ F.₁ g)) C.∘ CG.⊗-homo.η _ ≈⟨ pushˡ ([ G ]-resp-square (CF.⊗-homo.commute _)) ⟩ G.₁ (F.₁ (f A.⊗₁ g)) C.∘ G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _ ∎ } } ; associativity = begin G.₁ (F.₁ A.associator.from) C.∘ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ ((G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.⊗₁ C.id) ≈⟨ refl⟩∘⟨ refl⟩∘⟨ (Functor.homomorphism (C.-⊗ _) ○ C.∘-resp-≈ˡ (C.⊗.F-resp-≈ (C.Equiv.refl , ⟺ G.identity))) ⟩ G.₁ (F.₁ A.associator.from) C.∘ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ (G.₁ (CF.⊗-homo.η _) C.⊗₁ G.₁ B.id) C.∘ (CG.⊗-homo.η _ C.⊗₁ C.id) ≈⟨ refl⟩∘⟨ center (CG.⊗-homo.commute _) ⟩ G.₁ (F.₁ A.associator.from) C.∘ G.₁ (CF.⊗-homo.η _) C.∘ (G.₁ (CF.⊗-homo.η _ B.⊗₁ B.id) C.∘ CG.⊗-homo.η _) C.∘ (CG.⊗-homo.η _ C.⊗₁ C.id) ≈⟨ C.∘-resp-≈ʳ (center⁻¹ C.Equiv.refl C.Equiv.refl) ○ C.sym-assoc ⟩ (G.₁ (F.₁ A.associator.from) C.∘ G.₁ (CF.⊗-homo.η _) C.∘ G.₁ (CF.⊗-homo.η _ B.⊗₁ B.id)) C.∘ CG.⊗-homo.η _ C.∘ (CG.⊗-homo.η _ C.⊗₁ C.id) ≈⟨ C.∘-resp-≈ʳ (⟺ G.homomorphism) ⟩∘⟨refl ⟩ (G.₁ (F.₁ A.associator.from) C.∘ G.₁ (CF.⊗-homo.η _ B.∘ CF.⊗-homo.η _ B.⊗₁ B.id)) C.∘ CG.⊗-homo.η _ C.∘ (CG.⊗-homo.η _ C.⊗₁ C.id) ≈⟨ [ G ]-resp-square CF.associativity ⟩∘⟨refl ⟩ (G.₁ (CF.⊗-homo.η _) C.∘ G.₁ ((B.id B.⊗₁ CF.⊗-homo.η _) B.∘ B.associator.from)) C.∘ CG.⊗-homo.η _ C.∘ (CG.⊗-homo.η _ C.⊗₁ C.id) ≈⟨ C.∘-resp-≈ʳ G.homomorphism ⟩∘⟨refl ⟩ (G.₁ (CF.⊗-homo.η _) C.∘ G.₁ (B.id B.⊗₁ CF.⊗-homo.η _) C.∘ G.₁ B.associator.from) C.∘ CG.⊗-homo.η _ C.∘ (CG.⊗-homo.η _ C.⊗₁ C.id) ≈⟨ C.∘-resp-≈ˡ C.sym-assoc ○ C.assoc ⟩ (G.₁ (CF.⊗-homo.η _) C.∘ G.₁ (B.id B.⊗₁ CF.⊗-homo.η _)) C.∘ G.₁ B.associator.from C.∘ CG.⊗-homo.η _ C.∘ (CG.⊗-homo.η _ C.⊗₁ C.id) ≈⟨ refl⟩∘⟨ CG.associativity ⟩ (G.₁ (CF.⊗-homo.η _) C.∘ G.₁ (B.id B.⊗₁ CF.⊗-homo.η _)) C.∘ CG.⊗-homo.η _ C.∘ (C.id C.⊗₁ CG.⊗-homo.η _) C.∘ C.associator.from ≈⟨ center (CG.⊗-homo.sym-commute _) ⟩ G.₁ (CF.⊗-homo.η _) C.∘ (CG.⊗-homo.η _ C.∘ (G.₁ B.id C.⊗₁ G.₁ (CF.⊗-homo.η _))) C.∘ (C.id C.⊗₁ CG.⊗-homo.η _) C.∘ C.associator.from ≈⟨ pull-first C.Equiv.refl ○ C.∘-resp-≈ʳ (C.∘-resp-≈ˡ (C.⊗.F-resp-≈ (G.identity , C.Equiv.refl))) ⟩ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ (C.id C.⊗₁ G.₁ (CF.⊗-homo.η _)) C.∘ (C.id C.⊗₁ CG.⊗-homo.η _) C.∘ C.associator.from ≈˘⟨ refl⟩∘⟨ pushˡ (Functor.homomorphism (_ C.⊗-)) ⟩ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ (C.id C.⊗₁ (G.F₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _)) C.∘ C.associator.from ∎ ; unitaryˡ = begin G.₁ (F.₁ A.unitorˡ.from) C.∘ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ ((G.₁ CF.ε C.∘ CG.ε) C.⊗₁ C.id) ≈⟨ refl⟩∘⟨ refl⟩∘⟨ (Functor.homomorphism (C.-⊗ _) ○ C.∘-resp-≈ˡ (C.⊗.F-resp-≈ (C.Equiv.refl , ⟺ G.identity))) ⟩ G.₁ (F.₁ A.unitorˡ.from) C.∘ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ (G.₁ CF.ε C.⊗₁ G.₁ B.id) C.∘ (CG.ε C.⊗₁ C.id) ≈⟨ refl⟩∘⟨ center (CG.⊗-homo.commute _) ⟩ G.₁ (F.₁ A.unitorˡ.from) C.∘ G.₁ (CF.⊗-homo.η _) C.∘ (G.₁ (CF.ε B.⊗₁ B.id) C.∘ CG.⊗-homo.η _) C.∘ (CG.ε C.⊗₁ C.id) ≈⟨ C.∘-resp-≈ʳ (center⁻¹ C.Equiv.refl C.Equiv.refl) ○ C.sym-assoc ⟩ (G.₁ (F.₁ A.unitorˡ.from) C.∘ G.₁ (CF.⊗-homo.η _) C.∘ G.₁ (CF.ε B.⊗₁ B.id)) C.∘ CG.⊗-homo.η _ C.∘ (CG.ε C.⊗₁ C.id) ≈⟨ C.∘-resp-≈ʳ (⟺ G.homomorphism) ⟩∘⟨refl ⟩ (G.₁ (F.₁ A.unitorˡ.from) C.∘ G.₁ (CF.⊗-homo.η _ B.∘ CF.ε B.⊗₁ B.id)) C.∘ CG.⊗-homo.η _ C.∘ (CG.ε C.⊗₁ C.id) ≈⟨ [ G ]-resp-∘ CF.unitaryˡ ⟩∘⟨refl ⟩ G.₁ B.unitorˡ.from C.∘ CG.⊗-homo.η _ C.∘ (CG.ε C.⊗₁ C.id) ≈⟨ CG.unitaryˡ ⟩ C.unitorˡ.from ∎ ; unitaryʳ = begin G.₁ (F.₁ A.unitorʳ.from) C.∘ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ (C.id C.⊗₁ (G.₁ CF.ε C.∘ CG.ε)) ≈⟨ (refl⟩∘⟨ refl⟩∘⟨ (Functor.homomorphism (_ C.⊗-) ○ C.∘-resp-≈ˡ (C.⊗.F-resp-≈ (⟺ G.identity , C.Equiv.refl)))) ⟩ G.₁ (F.₁ A.unitorʳ.from) C.∘ (G.₁ (CF.⊗-homo.η _) C.∘ CG.⊗-homo.η _) C.∘ (G.₁ B.id C.⊗₁ G.₁ CF.ε) C.∘ (C.id C.⊗₁ CG.ε) ≈⟨ refl⟩∘⟨ center (CG.⊗-homo.commute _) ⟩ G.₁ (F.₁ A.unitorʳ.from) C.∘ G.₁ (CF.⊗-homo.η _) C.∘ (G.₁ (B.id B.⊗₁ CF.ε) C.∘ CG.⊗-homo.η _) C.∘ (C.id C.⊗₁ CG.ε) ≈⟨ C.∘-resp-≈ʳ (center⁻¹ C.Equiv.refl C.Equiv.refl) ○ C.sym-assoc ⟩ (G.₁ (F.₁ A.unitorʳ.from) C.∘ G.₁ (CF.⊗-homo.η _) C.∘ G.₁ (B.id B.⊗₁ CF.ε)) C.∘ CG.⊗-homo.η _ C.∘ (C.id C.⊗₁ CG.ε) ≈⟨ C.∘-resp-≈ʳ (⟺ G.homomorphism) ⟩∘⟨refl ⟩ (G.₁ (F.₁ A.unitorʳ.from) C.∘ G.F₁ (CF.⊗-homo.η _ B.∘ (B.id B.⊗₁ CF.ε))) C.∘ CG.⊗-homo.η _ C.∘ (C.id C.⊗₁ CG.ε) ≈⟨ [ G ]-resp-∘ CF.unitaryʳ ⟩∘⟨refl ⟩ G.F₁ B.unitorʳ.from C.∘ CG.⊗-homo.η _ C.∘ C.id C.⊗₁ CG.ε ≈⟨ CG.unitaryʳ ⟩ C.unitorʳ.from ∎ } where module F = Functor F module G = Functor G module CF = IsMonoidalFunctor CF module CG = IsMonoidalFunctor CG ∘-IsStrongMonoidal : ∀ {F : Functor A.U B.U} {G : Functor B.U C.U} → IsStrongMonoidalFunctor B C G → IsStrongMonoidalFunctor A B F → IsStrongMonoidalFunctor A C (G ∘F F) ∘-IsStrongMonoidal {F} {G} CG CF = record { ε = ≅.trans CG.ε ([ G ]-resp-≅ CF.ε) ; ⊗-homo = record { F⇒G = ∘.⊗-homo ; F⇐G = ntHelper record { η = λ { (X , Y) → CG.⊗-homo.⇐.η (F.F₀ X , F.F₀ Y) C.∘ G.₁ (CF.⊗-homo.⇐.η (X , Y)) } ; commute = λ _ → pullʳ ([ G ]-resp-square (CF.⊗-homo.⇐.commute _)) ○ pullˡ (CG.⊗-homo.⇐.commute _) ○ C.assoc } ; iso = λ _ → record { isoˡ = cancelInner ([ G ]-resp-∘ (CF.⊗-homo.iso.isoˡ _) ○ G.identity) ○ CG.⊗-homo.iso.isoˡ _ ; isoʳ = cancelInner (CG.⊗-homo.iso.isoʳ _) ○ [ G ]-resp-∘ (CF.⊗-homo.iso.isoʳ _) ○ G.identity } } ; associativity = ∘.associativity ; unitaryˡ = ∘.unitaryˡ ; unitaryʳ = ∘.unitaryʳ } where module F = Functor F module G = Functor G module CF = IsStrongMonoidalFunctor CF module CG = IsStrongMonoidalFunctor CG module ∘ = IsMonoidalFunctor (∘-IsMonoidal CG.isMonoidal CF.isMonoidal) module _ {A : MonoidalCategory o ℓ e} {B : MonoidalCategory o′ ℓ′ e′} {C : MonoidalCategory o″ ℓ″ e″} where ∘-StrongMonoidal : StrongMonoidalFunctor B C → StrongMonoidalFunctor A B → StrongMonoidalFunctor A C ∘-StrongMonoidal G F = record { isStrongMonoidal = ∘-IsStrongMonoidal _ _ _ (StrongMonoidalFunctor.isStrongMonoidal G) (StrongMonoidalFunctor.isStrongMonoidal F) } ∘-Monoidal : MonoidalFunctor B C → MonoidalFunctor A B → MonoidalFunctor A C ∘-Monoidal G F = record { isMonoidal = ∘-IsMonoidal _ _ _ (MonoidalFunctor.isMonoidal G) (MonoidalFunctor.isMonoidal F) } -- Functor composition preserves braided monoidality module _ {A : BraidedMonoidalCategory o ℓ e} {B : BraidedMonoidalCategory o′ ℓ′ e′} {C : BraidedMonoidalCategory o″ ℓ″ e″} where private module A = BraidedMonoidalCategory A module B = BraidedMonoidalCategory B module C = BraidedMonoidalCategory C open Braided ∘-IsBraidedMonoidal : ∀ {G : Functor B.U C.U} {F : Functor A.U B.U} → Lax.IsBraidedMonoidalFunctor B C G → Lax.IsBraidedMonoidalFunctor A B F → Lax.IsBraidedMonoidalFunctor A C (G ∘F F) ∘-IsBraidedMonoidal {G} {F} GB FB = record { isMonoidal = ∘-IsMonoidal _ _ _ (isMonoidal GB) (isMonoidal FB) ; braiding-compat = begin G₁ (F₁ AB) ∘ G₁ FH ∘ GH ≈˘⟨ pushˡ (homomorphism G) ⟩ G₁ (F₁ AB B.∘ FH) ∘ GH ≈⟨ F-resp-≈ G (braiding-compat FB) ⟩∘⟨refl ⟩ G₁ (FH B.∘ BB) ∘ GH ≈⟨ pushˡ (homomorphism G) ⟩ G₁ FH ∘ G₁ BB ∘ GH ≈⟨ pushʳ (braiding-compat GB) ⟩ (G₁ FH ∘ GH) ∘ CB ∎ } where open C open HomReasoning open MR C.U open Functor hiding (F₁) open Functor F using (F₁) open Functor G using () renaming (F₁ to G₁) open Lax.IsBraidedMonoidalFunctor FH = λ {X Y} → ⊗-homo.η FB (X , Y) GH = λ {X Y} → ⊗-homo.η GB (X , Y) AB = λ {X Y} → A.braiding.⇒.η (X , Y) BB = λ {X Y} → B.braiding.⇒.η (X , Y) CB = λ {X Y} → C.braiding.⇒.η (X , Y) ∘-IsStrongBraidedMonoidal : ∀ {G : Functor B.U C.U} {F : Functor A.U B.U} → Strong.IsBraidedMonoidalFunctor B C G → Strong.IsBraidedMonoidalFunctor A B F → Strong.IsBraidedMonoidalFunctor A C (G ∘F F) ∘-IsStrongBraidedMonoidal {G} {F} GB FB = record { isStrongMonoidal = ∘-IsStrongMonoidal _ _ _ (isStrongMonoidal GB) (isStrongMonoidal FB) ; braiding-compat = Lax.IsBraidedMonoidalFunctor.braiding-compat (∘-IsBraidedMonoidal (isLaxBraidedMonoidal GB) (isLaxBraidedMonoidal FB)) } where open Strong.IsBraidedMonoidalFunctor ∘-BraidedMonoidal : Lax.BraidedMonoidalFunctor B C → Lax.BraidedMonoidalFunctor A B → Lax.BraidedMonoidalFunctor A C ∘-BraidedMonoidal G F = record { isBraidedMonoidal = ∘-IsBraidedMonoidal (isBraidedMonoidal G) (isBraidedMonoidal F) } where open Lax.BraidedMonoidalFunctor hiding (F) ∘-StrongBraidedMonoidal : Strong.BraidedMonoidalFunctor B C → Strong.BraidedMonoidalFunctor A B → Strong.BraidedMonoidalFunctor A C ∘-StrongBraidedMonoidal G F = record { isBraidedMonoidal = ∘-IsStrongBraidedMonoidal (isBraidedMonoidal G) (isBraidedMonoidal F) } where open Strong.BraidedMonoidalFunctor hiding (F) -- Functor composition preserves symmetric monoidality module _ {A : SymmetricMonoidalCategory o ℓ e} {B : SymmetricMonoidalCategory o′ ℓ′ e′} {C : SymmetricMonoidalCategory o″ ℓ″ e″} where open Symmetric ∘-SymmetricMonoidal : Lax.SymmetricMonoidalFunctor B C → Lax.SymmetricMonoidalFunctor A B → Lax.SymmetricMonoidalFunctor A C ∘-SymmetricMonoidal G F = record { isBraidedMonoidal = ∘-IsBraidedMonoidal (isBraidedMonoidal G) (isBraidedMonoidal F) } where open Lax.SymmetricMonoidalFunctor hiding (F) ∘-StrongSymmetricMonoidal : Strong.SymmetricMonoidalFunctor B C → Strong.SymmetricMonoidalFunctor A B → Strong.SymmetricMonoidalFunctor A C ∘-StrongSymmetricMonoidal G F = record { isBraidedMonoidal = ∘-IsStrongBraidedMonoidal (isBraidedMonoidal G) (isBraidedMonoidal F) } where open Strong.SymmetricMonoidalFunctor hiding (F) module _ (C : CartesianCategory o ℓ e) (D : CartesianCategory o′ ℓ′ e′) where private module C = CartesianCategory C module D = CartesianCategory D open D.HomReasoning open MR D.U module _ (F : StrongMonoidalFunctor C.monoidalCategory D.monoidalCategory) where private module F = StrongMonoidalFunctor F F-resp-⊤ : ⊤.IsTerminal D.U (F.F₀ C.⊤) F-resp-⊤ = ⊤.Terminal.⊤-is-terminal (⊤.transport-by-iso D.U D.terminal F.ε) module F-resp-⊤ = ⊤.IsTerminal F-resp-⊤ lemma₁ : ∀ {X} → F.ε.from D.∘ D.! {F.₀ X} D.≈ F.₁ (C.! {X}) lemma₁ = F-resp-⊤.!-unique _ π₁-comm : ∀ {X Y} → F.F₁ C.π₁ D.∘ F.⊗-homo.⇒.η (X , Y) D.≈ D.π₁ π₁-comm {X} {Y} = begin F.F₁ C.π₁ D.∘ F.⊗-homo.⇒.η (X , Y) ≈˘⟨ [ F.F ]-resp-∘ (C.Equiv.trans C.project₁ C.identityˡ) ⟩∘⟨refl ⟩ (F.F₁ C.π₁ D.∘ F.F₁ (C.id C.⁂ C.!)) D.∘ F.⊗-homo.⇒.η (X , Y) ≈⟨ pullʳ (F.⊗-homo.⇒.sym-commute _) ⟩ F.F₁ C.π₁ D.∘ F.⊗-homo.⇒.η (X , C.⊤) D.∘ (F.F₁ C.id D.⁂ F.F₁ C.!) ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ ([ F.₀ X D.×- ]-resp-∘ lemma₁ ○ Functor.F-resp-≈ D.-×- (⟺ F.identity , D.Equiv.refl)) ⟩ F.F₁ C.π₁ D.∘ F.⊗-homo.⇒.η (X , C.⊤) D.∘ (D.id D.⁂ F.ε.from) D.∘ (D.id D.⁂ D.!) ≈⟨ D.∘-resp-≈ʳ D.sym-assoc ○ D.sym-assoc ⟩ (F.F₁ C.π₁ D.∘ F.⊗-homo.⇒.η (X , C.⊤) D.∘ (D.id D.⁂ F.ε.from)) D.∘ (D.id D.⁂ D.!) ≈⟨ F.unitaryʳ ⟩∘⟨refl ⟩ D.π₁ D.∘ (D.id D.⁂ D.!) ≈⟨ D.project₁ ○ D.identityˡ ⟩ D.π₁ ∎ π₂-comm : ∀ {X Y} → F.F₁ C.π₂ D.∘ F.⊗-homo.⇒.η (X , Y) D.≈ D.π₂ π₂-comm {X} {Y} = begin F.F₁ C.π₂ D.∘ F.⊗-homo.⇒.η (X , Y) ≈˘⟨ [ F.F ]-resp-∘ (C.Equiv.trans C.project₂ C.identityˡ) ⟩∘⟨refl ⟩ (F.F₁ C.π₂ D.∘ F.F₁ (C.! C.⁂ C.id)) D.∘ F.⊗-homo.⇒.η (X , Y) ≈⟨ pullʳ (F.⊗-homo.⇒.sym-commute _) ⟩ F.F₁ C.π₂ D.∘ F.⊗-homo.⇒.η (C.⊤ , Y) D.∘ (F.F₁ C.! D.⁂ F.F₁ C.id) ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ ([ D.-× F.₀ Y ]-resp-∘ lemma₁ ○ Functor.F-resp-≈ D.-×- (D.Equiv.refl , ⟺ F.identity)) ⟩ F.F₁ C.π₂ D.∘ F.⊗-homo.⇒.η (C.⊤ , Y) D.∘ (F.ε.from D.⁂ D.id) D.∘ (D.! D.⁂ D.id) ≈⟨ D.∘-resp-≈ʳ D.sym-assoc ○ D.sym-assoc ⟩ (F.F₁ C.π₂ D.∘ F.⊗-homo.⇒.η (C.⊤ , Y) D.∘ (F.ε.from D.⁂ D.id)) D.∘ (D.! D.⁂ D.id) ≈⟨ F.unitaryˡ ⟩∘⟨refl ⟩ D.π₂ D.∘ (D.! D.⁂ D.id) ≈⟨ D.project₂ ○ D.identityˡ ⟩ D.π₂ ∎ unique : ∀ {X A B} {h : X D.⇒ F.₀ (A C.× B)} {i : X D.⇒ F.₀ A} {j : X D.⇒ F.₀ B} → F.₁ C.π₁ D.∘ h D.≈ i → F.₁ C.π₂ D.∘ h D.≈ j → F.⊗-homo.⇒.η (A , B) D.∘ D.product.⟨ i , j ⟩ D.≈ h unique eq₁ eq₂ = ⟺ (switch-tofromˡ F.⊗-homo.FX≅GX (⟺ (D.unique (pullˡ (⟺ (switch-fromtoʳ F.⊗-homo.FX≅GX π₁-comm)) ○ eq₁) (pullˡ (⟺ (switch-fromtoʳ F.⊗-homo.FX≅GX π₂-comm)) ○ eq₂)))) StrongMonoidal⇒Cartesian : CartesianF C D StrongMonoidal⇒Cartesian = record { F = F.F ; isCartesian = record { F-resp-⊤ = F-resp-⊤ ; F-resp-× = λ {A B} → record { ⟨_,_⟩ = λ f g → F.⊗-homo.⇒.η _ D.∘ D.⟨ f , g ⟩ ; project₁ = λ {_ h i} → begin F.₁ C.π₁ D.∘ F.⊗-homo.⇒.η _ D.∘ D.⟨ h , i ⟩ ≈⟨ pullˡ π₁-comm ⟩ D.π₁ D.∘ D.product.⟨ h , i ⟩ ≈⟨ D.project₁ ⟩ h ∎ ; project₂ = λ {_ h i} → begin F.₁ C.π₂ D.∘ F.⊗-homo.⇒.η _ D.∘ D.⟨ h , i ⟩ ≈⟨ pullˡ π₂-comm ⟩ D.π₂ D.∘ D.⟨ h , i ⟩ ≈⟨ D.project₂ ⟩ i ∎ ; unique = unique } } }
{ "alphanum_fraction": 0.5404152285, "avg_line_length": 49.6445012788, "ext": "agda", "hexsha": "6f02e4cb3630c2acbd6ca210b4328c9a2e2b54d0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f8a33de12956c729c7fb00a302f166a643eb6052", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "TOTBWF/agda-categories", "max_forks_repo_path": "src/Categories/Functor/Monoidal/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f8a33de12956c729c7fb00a302f166a643eb6052", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "TOTBWF/agda-categories", "max_issues_repo_path": "src/Categories/Functor/Monoidal/Properties.agda", "max_line_length": 197, "max_stars_count": null, "max_stars_repo_head_hexsha": "f8a33de12956c729c7fb00a302f166a643eb6052", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "TOTBWF/agda-categories", "max_stars_repo_path": "src/Categories/Functor/Monoidal/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 8750, "size": 19411 }
------------------------------------------------------------------------------ -- Mirror example ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.Mirror.Example where open import FOTC.Base open import FOTC.Data.Nat.UnaryNumbers open import FOTC.Base.List open import FOTC.Data.List open import FOTC.Program.Mirror.Mirror open import FOTC.Program.Mirror.Type open import FOTC.Program.Mirror.PropertiesI ------------------------------------------------------------------------------ -- Example -- 1 -- / / \ \ -- 2 3 4 5 -- / \ -- 6 7 t : D t = node 1' (node 2' (node 6' [] ∷ node 7' [] ∷ []) ∷ node 3' [] ∷ node 4' [] ∷ node 5' [] ∷ [] ) tTree : Tree t tTree = tree 1' (fcons (tree 2' (fcons (tree 6' fnil) (fcons (tree 7' fnil) fnil))) (fcons (tree 3' fnil) (fcons (tree 4' fnil) (fcons (tree 5' fnil) fnil)))) test : t ≡ mirror · (mirror · t) test = sym (mirror-involutive tTree)
{ "alphanum_fraction": 0.4028831563, "avg_line_length": 28.0425531915, "ext": "agda", "hexsha": "f6c00740335d9f0540f558a6389c782cfbda4f79", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/Mirror/Example.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/Mirror/Example.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/Mirror/Example.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 333, "size": 1318 }
{-# OPTIONS --safe --without-K #-} module Generics.Telescope.Equality where -- freely inspired by jespercockx/telescopic -- note that our telescopes extend to the right -- while in telescopic they extend to the left -- a byproduct is that the following defs are overly mutual open import Generics.Prelude open import Generics.Telescope private variable l : Level A : Set l a x y : A ----------- -- Helpers private J⁻¹ : ∀ {a b} {A : Set a} {x : A} (B : (y : A) → x ≡ y → Set b) → {y : A} (p : x ≡ y) → B y p → B x refl J⁻¹ B p = J (λ y e → B y e → B _ refl) p id Jω : ∀ {a} {A : Set a} {x : A} (B : (y : A) → x ≡ y → Setω) → {y : A} (p : x ≡ y) → B x refl → B y p Jω B refl x = x Jω⁻¹ : ∀ {a} {A : Set a} {x : A} (B : (y : A) → x ≡ y → Setω) → {y : A} (p : x ≡ y) → B y p → B x refl Jω⁻¹ B p = Jω (λ y e → B y e → B _ refl) p λ x → x JJ⁻¹ : ∀ {a b} {A : Set a} {x : A} (B : (y : A) → x ≡ y → Set b) → {y : A} {p : x ≡ y} → (z : B y p) → J B p (J⁻¹ B p z) ≡ z JJ⁻¹ B {p = refl} z = refl JJω⁻¹ : ∀ {a} {A : Set a} {x : A} (B : (y : A) → x ≡ y → Setω) → {y : A} {p : x ≡ y} → (z : B y p) → Jω B p (Jω⁻¹ B p z) ≡ω z JJω⁻¹ B {p = refl} z = refl substω : ∀ {a} {A : Set a} (P : A → Setω) {x y : A} → x ≡ y → P x → P y substω P refl x = x substω-substω-sym : ∀ {a} {A : Set a} {P : A → Setω} {x y : A} (x≡y : x ≡ y) {p : P y} → substω P x≡y (substω P (sym x≡y) p) ≡ω p substω-substω-sym refl = reflω ---------------------- -- Telescope Equality _≡ⁿ_ : {T : Telescope A} → ⟦ T ⟧tel a → ⟦ T ⟧tel a → Telescope ⊤ substⁿ : {T : Telescope A} (f : ∀ {x} → ⟦ T ⟧tel x → Set l) {xs ys : ⟦ T ⟧tel a} → ⟦ xs ≡ⁿ ys ⟧tel tt → f xs → f ys reflⁿ : {T : Telescope A} {xs : ⟦ T ⟧tel a} → ⟦ xs ≡ⁿ xs ⟧tel tt substⁿ-refl : {T : Telescope A} (f : ∀ {x} → ⟦ T ⟧tel x → Set l) {xs : ⟦ T ⟧tel a} {x : f xs} → substⁿ f reflⁿ x ≡ x Jⁿ : {T : Telescope A} {xs : ⟦ T ⟧tel a} (ϕ : ∀ ss → ⟦ xs ≡ⁿ ss ⟧tel tt → Set l) → ∀ {ss} (es : ⟦ xs ≡ⁿ ss ⟧tel tt) → ϕ xs reflⁿ → ϕ ss es Jⁿ-refl : {T : Telescope A} {xs : ⟦ T ⟧tel a} (ϕ : ∀ ss → ⟦ xs ≡ⁿ ss ⟧tel tt → Set l) (φ : ϕ xs reflⁿ) → Jⁿ ϕ reflⁿ φ ≡ φ -- TODO: discard equality between irrelevant values _≡ⁿ_ {T = ε} tt tt = ε _≡ⁿ_ {T = T ⊢< n , ai > f} (xs , x) (ys , y) = e ∶ xs ≡ⁿ ys , substⁿ (< relevance ai >_ ∘ f ∘ (_ ,_)) e x ≡ y reflⁿ {T = ε} = tt reflⁿ {T = T ⊢< n , ai > f} {xs , x} = reflⁿ , substⁿ-refl (< relevance ai >_ ∘ f ∘ (_ ,_)) Jⁿ {T = ε} ϕ _ φ = φ Jⁿ {T = T ⊢< n , ai > f} {xs , x} ϕ {ss , s} (es , e) φ = J (λ y ey → ϕ (ss , y) (es , ey)) e $ Jⁿ (λ ss′ es′ → ϕ (ss′ , substⁿ (< relevance ai >_ ∘ f ∘ (_ ,_)) es′ x) (es′ , refl)) es d where d : ϕ (xs , substⁿ (< relevance ai >_ ∘ f ∘ (_ ,_)) reflⁿ x) (reflⁿ , refl) d = J⁻¹ (λ y ey → ϕ (xs , y) (reflⁿ , ey)) (substⁿ-refl _) φ substⁿ {T = ε} f tt z = z substⁿ {T = T ⊢< n , ai > g} f {xs , x} {ys , y} (es , e) z = subst (f ∘ (ys ,_)) e $ Jⁿ (λ rs er → f (rs , substⁿ (< relevance ai >_ ∘ g ∘ (_ ,_)) er x)) es (subst (f ∘ (xs ,_)) (sym (substⁿ-refl (< relevance ai >_ ∘ g ∘ (_ ,_)))) z) substⁿ-refl {T = ε} f = refl substⁿ-refl {T = T ⊢< n , ai > g} f {xs , x} {z} rewrite Jⁿ-refl (λ rs er → f (rs , substⁿ (< relevance ai >_ ∘ g ∘ (_ ,_)) er x)) (subst (f ∘ (xs ,_)) (sym (substⁿ-refl (< relevance ai >_ ∘ g ∘ (_ ,_)))) z) = subst-subst-sym (substⁿ-refl (< relevance ai >_ ∘ g ∘ (_ ,_))) Jⁿ-refl {T = ε} ϕ φ = refl Jⁿ-refl {T = T ⊢< n , ai > f} {xs , x} ϕ φ rewrite Jⁿ-refl (λ ss′ es′ → ϕ (ss′ , substⁿ (< relevance ai >_ ∘ f ∘ (_ ,_)) es′ x) (es′ , refl)) (J⁻¹ (λ y ey → ϕ (xs , y) (reflⁿ , ey)) _ φ) = JJ⁻¹ (λ y ey → ϕ (xs , y) (reflⁿ , ey)) φ ------------------------------ -- Telescope Equality in Setω substωⁿ : {T : Telescope A} (f : ∀ {x} → ⟦ T ⟧tel x → Setω) {xs ys : ⟦ T ⟧tel a} → ⟦ xs ≡ⁿ ys ⟧tel tt → f xs → f ys substωⁿ-refl : {T : Telescope A} (f : ∀ {x} → ⟦ T ⟧tel x → Setω) {xs : ⟦ T ⟧tel a} {x : f xs} → substωⁿ f reflⁿ x ≡ω x Jωⁿ : {T : Telescope A} {xs : ⟦ T ⟧tel a} (ϕ : ∀ ss → ⟦ xs ≡ⁿ ss ⟧tel tt → Setω) → ∀ {ss} (es : ⟦ xs ≡ⁿ ss ⟧tel tt) → ϕ xs reflⁿ → ϕ ss es Jωⁿ-refl : {T : Telescope A} {xs : ⟦ T ⟧tel a} (ϕ : ∀ ss → ⟦ xs ≡ⁿ ss ⟧tel tt → Setω) (φ : ϕ xs reflⁿ) → Jωⁿ ϕ reflⁿ φ ≡ω φ Jωⁿ {T = ε} ϕ _ φ = φ Jωⁿ {T = T ⊢< n , ai > f} {xs , x} ϕ {ss , s} (es , e) φ = Jω (λ y ey → ϕ (ss , y) (es , ey)) e (Jωⁿ (λ ss′ es′ → ϕ (ss′ , substⁿ (< relevance ai >_ ∘ f ∘ (_ ,_)) es′ x) (es′ , refl)) es d) where d : ϕ (xs , substⁿ (< relevance ai >_ ∘ f ∘ (_ ,_)) reflⁿ x) (reflⁿ , refl) d = Jω⁻¹ (λ y ey → ϕ (xs , y) (reflⁿ , ey)) (substⁿ-refl (< relevance ai >_ ∘ f ∘ (_ ,_))) φ substωⁿ {T = ε} f tt z = z substωⁿ {T = T ⊢< n , ai > g} f {xs , x} {ys , y} (es , e) z = substω (λ x → f (ys , x)) e (Jωⁿ (λ rs er → f (rs , substⁿ (< relevance ai >_ ∘ g ∘ (_ ,_)) er x)) es (substω (λ x → f (xs , x)) (sym (substⁿ-refl (< relevance ai >_ ∘ g ∘ (_ ,_)))) z)) substωⁿ-refl {T = ε} f = refl substωⁿ-refl {T = T ⊢< n , ai > g} f {xs , x} {z} = transω (cong≡ωω (λ x → substω (λ x → f (_ , x)) ((substⁿ-refl (< relevance ai >_ ∘ g ∘ (_ ,_)))) x) p) (substω-substω-sym (substⁿ-refl (< relevance ai >_ ∘ g ∘ (_ ,_)))) where p = Jωⁿ-refl (λ rs er → f (rs , substⁿ (< relevance ai >_ ∘ g ∘ (_ ,_)) er x)) (substω (λ x → f (xs , x)) (sym (substⁿ-refl (< relevance ai >_ ∘ g ∘ (_ ,_)))) z) Jωⁿ-refl {T = ε} ϕ φ = refl Jωⁿ-refl {T = T ⊢< n , ai > f} {xs , x} ϕ φ = transω (cong≡ωω (λ x → Jω (λ y ey → ϕ (xs , y) (reflⁿ , ey)) (substⁿ-refl (< relevance ai >_ ∘ f ∘ (_ ,_))) x) p) (JJω⁻¹ (λ y ey → ϕ (xs , y) (reflⁿ , ey)) φ) where p = Jωⁿ-refl (λ ss′ es′ → ϕ (ss′ , substⁿ (< relevance ai >_ ∘ f ∘ (_ ,_)) es′ x) (es′ , refl)) (Jω⁻¹ (λ y ey → ϕ (xs , y) (reflⁿ , ey)) _ φ)
{ "alphanum_fraction": 0.4277998411, "avg_line_length": 34.3989071038, "ext": "agda", "hexsha": "4cafc8f2938037e940777923f20f83dbf5da9a40", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "flupe/generics", "max_forks_repo_path": "src/Generics/Telescope/Equality.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "flupe/generics", "max_issues_repo_path": "src/Generics/Telescope/Equality.agda", "max_line_length": 101, "max_stars_count": 11, "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "flupe/generics", "max_stars_repo_path": "src/Generics/Telescope/Equality.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "num_tokens": 2905, "size": 6295 }
module ShouldBePi where postulate X : Set
{ "alphanum_fraction": 0.7555555556, "avg_line_length": 7.5, "ext": "agda", "hexsha": "b050eee87063fcab7417648075f534f616e55cfe", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Imports/ShouldBePi.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Imports/ShouldBePi.agda", "max_line_length": 23, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Imports/ShouldBePi.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 13, "size": 45 }
{-# OPTIONS --no-flat-split #-} module _ where postulate A : Set data Id (A : Set) : Set where id : A → Id A -- --no-flat-split disables matching on the @♭ x agument. test2 : (@♭ x : Id A) → A test2 (id x) = x
{ "alphanum_fraction": 0.5806451613, "avg_line_length": 16.6923076923, "ext": "agda", "hexsha": "6e30951b8b77d68933956e9e7aebf3472f744400", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/NoFlatSplit.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/NoFlatSplit.agda", "max_line_length": 57, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/NoFlatSplit.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 77, "size": 217 }