hexsha
stringlengths
40
40
size
int64
3
1.05M
ext
stringclasses
163 values
lang
stringclasses
53 values
max_stars_repo_path
stringlengths
3
945
max_stars_repo_name
stringlengths
4
112
max_stars_repo_head_hexsha
stringlengths
40
78
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
945
max_issues_repo_name
stringlengths
4
113
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
116k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
945
max_forks_repo_name
stringlengths
4
113
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
3
1.05M
avg_line_length
float64
1
966k
max_line_length
int64
1
977k
alphanum_fraction
float64
0
1
2280e04d6be5d149e5888abcf167674878d56ddc
20,280
agda
Agda
agda-stdlib-0.9/src/Data/List/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/List/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/List/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- List-related properties ------------------------------------------------------------------------ -- Note that the lemmas below could be generalised to work with other -- equalities than _≡_. module Data.List.Properties where open import Algebra import Algebra.Monoid-solver open import Category.Monad open import Data.Bool open import Data.List as List open import Data.List.All using (All; []; _∷_) open import Data.Maybe using (Maybe; just; nothing) open import Data.Nat open import Data.Nat.Properties open import Data.Product as Prod hiding (map) open import Function import Algebra.FunctionProperties import Relation.Binary.EqReasoning as EqR open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; _≗_; refl) open import Relation.Nullary using (yes; no) open import Relation.Nullary.Decidable using (⌊_⌋) open import Relation.Unary using (Decidable) private open module FP {a} {A : Set a} = Algebra.FunctionProperties (_≡_ {A = A}) open module LMP {ℓ} = RawMonadPlus (List.monadPlus {ℓ = ℓ}) module LM {a} {A : Set a} = Monoid (List.monoid A) module List-solver {a} {A : Set a} = Algebra.Monoid-solver (monoid A) renaming (id to nil) ∷-injective : ∀ {a} {A : Set a} {x y : A} {xs ys} → x ∷ xs ≡ y List.∷ ys → x ≡ y × xs ≡ ys ∷-injective refl = (refl , refl) ∷ʳ-injective : ∀ {a} {A : Set a} {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 ∷ʳ-injective (x ∷ xs) (.x ∷ ys) eq | (refl , eq′) = Prod.map (P.cong (_∷_ x)) id $ ∷ʳ-injective xs ys eq′ ∷ʳ-injective [] (_ ∷ []) () ∷ʳ-injective [] (_ ∷ _ ∷ _) () ∷ʳ-injective (_ ∷ []) [] () ∷ʳ-injective (_ ∷ _ ∷ _) [] () right-identity-unique : ∀ {a} {A : Set a} (xs : List A) {ys} → xs ≡ xs ++ ys → ys ≡ [] right-identity-unique [] refl = refl right-identity-unique (x ∷ xs) eq = right-identity-unique xs (proj₂ (∷-injective eq)) left-identity-unique : ∀ {a} {A : Set a} {xs} (ys : List A) → xs ≡ ys ++ xs → ys ≡ [] left-identity-unique [] _ = refl left-identity-unique {xs = []} (y ∷ ys) () left-identity-unique {xs = x ∷ xs} (y ∷ ys) eq with left-identity-unique (ys ++ [ x ]) (begin xs ≡⟨ proj₂ (∷-injective eq) ⟩ ys ++ x ∷ xs ≡⟨ P.sym (LM.assoc ys [ x ] xs) ⟩ (ys ++ [ x ]) ++ xs ∎) where open P.≡-Reasoning left-identity-unique {xs = x ∷ xs} (y ∷ [] ) eq | () left-identity-unique {xs = x ∷ xs} (y ∷ _ ∷ _) eq | () -- Map, sum, and append. map-++-commute : ∀ {a b} {A : Set a} {B : Set b} (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) 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 CommutativeSemiring commutativeSemiring hiding (_+_) open P.≡-Reasoning -- Various properties about folds. 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-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)) idIsFold : ∀ {a} {A : Set a} → id {A = List A} ≗ foldr _∷_ [] idIsFold = foldr-universal id _∷_ [] refl (λ _ _ → refl) ++IsFold : ∀ {a} {A : Set a} (xs ys : List A) → xs ++ ys ≡ foldr _∷_ ys xs ++IsFold xs ys = begin xs ++ ys ≡⟨ P.cong (λ xs → xs ++ ys) (idIsFold xs) ⟩ foldr _∷_ [] xs ++ ys ≡⟨ foldr-fusion (λ xs → xs ++ ys) [] (λ _ _ → refl) xs ⟩ foldr _∷_ ([] ++ ys) xs ≡⟨ refl ⟩ foldr _∷_ ys xs ∎ where open P.≡-Reasoning mapIsFold : ∀ {a b} {A : Set a} {B : Set b} {f : A → B} → map f ≗ foldr (λ x ys → f x ∷ ys) [] mapIsFold {f = f} = begin map f ≈⟨ P.cong (map f) ∘ idIsFold ⟩ map f ∘ foldr _∷_ [] ≈⟨ foldr-fusion (map f) [] (λ _ _ → refl) ⟩ foldr (λ x ys → f x ∷ ys) [] ∎ where open EqR (P._→-setoid_ _ _) concat-map : ∀ {a b} {A : Set a} {B : Set b} {f : A → B} → concat ∘ map (map f) ≗ map f ∘ concat concat-map {b = b} {f = f} = begin concat ∘ map (map f) ≈⟨ P.cong concat ∘ mapIsFold {b = b} ⟩ concat ∘ foldr (λ xs ys → map f xs ∷ ys) [] ≈⟨ foldr-fusion {b = b} concat [] (λ _ _ → refl) ⟩ foldr (λ ys zs → map f ys ++ zs) [] ≈⟨ P.sym ∘ foldr-fusion (map f) [] (λ ys zs → map-++-commute f ys zs) ⟩ map f ∘ concat ∎ where open EqR (P._→-setoid_ _ _) map-id : ∀ {a} {A : Set a} → map id ≗ id {A = List A} map-id {A = A} = begin map id ≈⟨ mapIsFold ⟩ foldr _∷_ [] ≈⟨ P.sym ∘ idIsFold {A = A} ⟩ id ∎ where open EqR (P._→-setoid_ _ _) map-compose : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} {g : B → C} {f : A → B} → map (g ∘ f) ≗ map g ∘ map f map-compose {A = A} {B} {g = g} {f} = begin map (g ∘ f) ≈⟨ P.cong (map (g ∘ f)) ∘ idIsFold ⟩ map (g ∘ f) ∘ foldr _∷_ [] ≈⟨ foldr-fusion (map (g ∘ f)) [] (λ _ _ → refl) ⟩ foldr (λ a y → g (f a) ∷ y) [] ≈⟨ P.sym ∘ foldr-fusion (map g) [] (λ _ _ → refl) ⟩ map g ∘ foldr (λ a y → f a ∷ y) [] ≈⟨ P.cong (map g) ∘ P.sym ∘ mapIsFold {A = A} {B = B} ⟩ map g ∘ map f ∎ where open EqR (P._→-setoid_ _ _) foldr-cong : ∀ {a b} {A : Set a} {B : Set b} {f₁ f₂ : A → B → B} {e₁ e₂ : B} → (∀ x y → f₁ x y ≡ f₂ x y) → e₁ ≡ e₂ → foldr f₁ e₁ ≗ foldr f₂ e₂ foldr-cong {f₁ = f₁} {f₂} {e} f₁≗₂f₂ refl = begin foldr f₁ e ≈⟨ P.cong (foldr f₁ e) ∘ idIsFold ⟩ foldr f₁ e ∘ foldr _∷_ [] ≈⟨ foldr-fusion (foldr f₁ e) [] (λ x xs → f₁≗₂f₂ x (foldr f₁ e xs)) ⟩ foldr f₂ e ∎ where open EqR (P._→-setoid_ _ _) map-cong : ∀ {a b} {A : Set a} {B : Set b} {f g : A → B} → f ≗ g → map f ≗ map g map-cong {A = A} {B} {f} {g} f≗g = begin map f ≈⟨ mapIsFold ⟩ foldr (λ x ys → f x ∷ ys) [] ≈⟨ foldr-cong (λ x ys → P.cong₂ _∷_ (f≗g x) refl) refl ⟩ foldr (λ x ys → g x ∷ ys) [] ≈⟨ P.sym ∘ mapIsFold {A = A} {B = B} ⟩ map g ∎ where open EqR (P._→-setoid_ _ _) -- Take, drop, and splitAt. take++drop : ∀ {a} {A : Set a} 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 (λ xs → x ∷ xs) (take++drop n xs) splitAt-defn : ∀ {a} {A : Set a} 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. takeWhile++dropWhile : ∀ {a} {A : Set a} (p : A → Bool) (xs : List A) → takeWhile p xs ++ dropWhile p xs ≡ xs takeWhile++dropWhile p [] = refl takeWhile++dropWhile p (x ∷ xs) with p x ... | true = P.cong (_∷_ x) (takeWhile++dropWhile p xs) ... | false = refl span-defn : ∀ {a} {A : Set a} (p : A → Bool) → span p ≗ < takeWhile p , dropWhile p > span-defn p [] = refl span-defn p (x ∷ xs) with p x ... | true = P.cong (Prod.map (_∷_ x) id) (span-defn p xs) ... | false = refl -- Partition, filter. partition-defn : ∀ {a} {A : Set a} (p : A → Bool) → partition p ≗ < filter p , filter (not ∘ p) > partition-defn p [] = refl partition-defn p (x ∷ xs) with p x | partition p xs | partition-defn p xs ... | true | (ys , zs) | eq = P.cong (Prod.map (_∷_ x) id) eq ... | false | (ys , zs) | eq = P.cong (Prod.map id (_∷_ x)) eq filter-filters : ∀ {a p} {A : Set a} → (P : A → Set p) (dec : Decidable P) (xs : List A) → All P (filter (⌊_⌋ ∘ dec) xs) filter-filters P dec [] = [] filter-filters P dec (x ∷ xs) with dec x filter-filters P dec (x ∷ xs) | yes px = px ∷ filter-filters P dec xs filter-filters P dec (x ∷ xs) | no ¬px = filter-filters P dec xs -- Inits, tails, and scanr. scanr-defn : ∀ {a b} {A : Set a} {B : Set b} (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₁ ∷ x₂ ∷ xs) with scanr f e (x₂ ∷ xs) | scanr-defn f e (x₂ ∷ xs) ... | [] | () ... | y ∷ ys | eq with ∷-injective eq ... | y≡fx₂⦇f⦈xs , _ = P.cong₂ (λ z zs → f x₁ z ∷ zs) y≡fx₂⦇f⦈xs eq scanl-defn : ∀ {a b} {A : Set a} {B : Set b} (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 -- Length. length-map : ∀ {a b} {A : Set a} {B : Set b} (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) length-++ : ∀ {a} {A : Set a} (xs : List A) {ys} → length (xs ++ ys) ≡ length xs + length ys length-++ [] = refl length-++ (x ∷ xs) = P.cong suc (length-++ xs) length-replicate : ∀ {a} {A : Set a} n {x : A} → length (replicate n x) ≡ n length-replicate zero = refl length-replicate (suc n) = P.cong suc (length-replicate n) length-gfilter : ∀ {a b} {A : Set a} {B : Set b} (p : A → Maybe B) xs → length (gfilter p xs) ≤ length xs length-gfilter p [] = z≤n length-gfilter p (x ∷ xs) with p x length-gfilter p (x ∷ xs) | just y = s≤s (length-gfilter p xs) length-gfilter p (x ∷ xs) | nothing = ≤-step (length-gfilter p xs) -- Reverse. unfold-reverse : ∀ {a} {A : Set a} (x : A) (xs : List A) → reverse (x ∷ xs) ≡ reverse xs ∷ʳ x unfold-reverse x xs = begin foldl (flip _∷_) [ x ] xs ≡⟨ helper [ x ] xs ⟩ reverse xs ∷ʳ x ∎ where open P.≡-Reasoning helper : ∀ {a} {A : Set a} (xs ys : List A) → foldl (flip _∷_) xs ys ≡ reverse ys ++ xs helper xs [] = P.refl helper xs (y ∷ ys) = begin foldl (flip _∷_) (y ∷ xs) ys ≡⟨ helper (y ∷ xs) ys ⟩ reverse ys ++ y ∷ xs ≡⟨ P.sym $ LM.assoc (reverse ys) _ _ ⟩ (reverse ys ∷ʳ y) ++ xs ≡⟨ P.sym $ P.cong (λ zs → zs ++ xs) (unfold-reverse y ys) ⟩ reverse (y ∷ ys) ++ xs ∎ reverse-++-commute : ∀ {a} {A : Set a} (xs ys : List A) → reverse (xs ++ ys) ≡ reverse ys ++ reverse xs reverse-++-commute {a} [] ys = begin reverse ys ≡⟨ P.sym $ proj₂ {a = a} {b = a} LM.identity _ ⟩ reverse ys ++ [] ≡⟨ P.refl ⟩ reverse ys ++ reverse [] ∎ where open P.≡-Reasoning reverse-++-commute (x ∷ xs) ys = begin reverse (x ∷ xs ++ ys) ≡⟨ unfold-reverse x (xs ++ ys) ⟩ reverse (xs ++ ys) ++ [ x ] ≡⟨ P.cong (λ zs → zs ++ [ x ]) (reverse-++-commute xs ys) ⟩ (reverse ys ++ reverse xs) ++ [ x ] ≡⟨ LM.assoc (reverse ys) _ _ ⟩ reverse ys ++ (reverse xs ++ [ x ]) ≡⟨ P.sym $ P.cong (λ zs → reverse ys ++ zs) (unfold-reverse x xs) ⟩ reverse ys ++ reverse (x ∷ xs) ∎ where open P.≡-Reasoning reverse-map-commute : ∀ {a b} {A : Set a} {B : Set b} (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 (λ y → y ∷ʳ 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-involutive : ∀ {a} {A : Set a} → Involutive (reverse {A = A}) 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 (λ y → x ∷ y) $ reverse-involutive xs ⟩ x ∷ xs ∎ where open P.≡-Reasoning -- The list monad. module Monad where left-zero : ∀ {ℓ} {A B : Set ℓ} (f : A → List B) → (∅ >>= f) ≡ ∅ left-zero f = refl right-zero : ∀ {ℓ} {A B : Set ℓ} (xs : List A) → (xs >>= const ∅) ≡ ∅ {A = B} right-zero [] = refl right-zero (x ∷ xs) = right-zero xs private not-left-distributive : let xs = true ∷ false ∷ []; f = return; g = return in (xs >>= λ x → f x ∣ g x) ≢ ((xs >>= f) ∣ (xs >>= g)) not-left-distributive () right-distributive : ∀ {ℓ} {A B : Set ℓ} (xs ys : List A) (f : A → List B) → (xs ∣ ys >>= f) ≡ ((xs >>= f) ∣ (ys >>= f)) right-distributive [] ys f = refl right-distributive (x ∷ xs) ys f = begin f x ∣ (xs ∣ ys >>= f) ≡⟨ P.cong (_∣_ (f x)) $ right-distributive xs ys f ⟩ f x ∣ ((xs >>= f) ∣ (ys >>= f)) ≡⟨ P.sym $ LM.assoc (f x) _ _ ⟩ (f x ∣ (xs >>= f)) ∣ (ys >>= f) ∎ where open P.≡-Reasoning left-identity : ∀ {ℓ} {A B : Set ℓ} (x : A) (f : A → List B) → (return x >>= f) ≡ f x left-identity {ℓ} x f = proj₂ (LM.identity {a = ℓ}) (f x) right-identity : ∀ {a} {A : Set a} (xs : List A) → (xs >>= return) ≡ xs right-identity [] = refl right-identity (x ∷ xs) = P.cong (_∷_ x) (right-identity xs) associative : ∀ {ℓ} {A B C : Set ℓ} (xs : List A) (f : A → List B) (g : B → List C) → (xs >>= λ x → f x >>= g) ≡ (xs >>= f >>= g) associative [] f g = refl associative (x ∷ xs) f g = begin (f x >>= g) ∣ (xs >>= λ x → f x >>= g) ≡⟨ P.cong (_∣_ (f x >>= g)) $ associative xs f g ⟩ (f x >>= g) ∣ (xs >>= f >>= g) ≡⟨ P.sym $ right-distributive (f x) (xs >>= f) g ⟩ (f x ∣ (xs >>= f) >>= g) ∎ where open P.≡-Reasoning cong : ∀ {ℓ} {A B : Set ℓ} {xs₁ xs₂} {f₁ f₂ : A → List B} → xs₁ ≡ xs₂ → f₁ ≗ f₂ → (xs₁ >>= f₁) ≡ (xs₂ >>= f₂) cong {xs₁ = xs} refl f₁≗f₂ = P.cong concat (map-cong f₁≗f₂ xs) -- The applicative functor derived from the list monad. -- Note that these proofs (almost) show that RawIMonad.rawIApplicative -- is correctly defined. The proofs can be reused if proof components -- are ever added to RawIMonad and RawIApplicative. module Applicative where open P.≡-Reasoning private -- A variant of flip map. pam : ∀ {ℓ} {A B : Set ℓ} → List A → (A → B) → List B pam xs f = xs >>= return ∘ f -- ∅ is a left zero for _⊛_. left-zero : ∀ {ℓ} {A B : Set ℓ} (xs : List A) → ∅ ⊛ xs ≡ ∅ {A = B} left-zero xs = begin ∅ ⊛ xs ≡⟨ refl ⟩ (∅ >>= pam xs) ≡⟨ Monad.left-zero (pam xs) ⟩ ∅ ∎ -- ∅ is a right zero for _⊛_. right-zero : ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) → fs ⊛ ∅ ≡ ∅ right-zero {ℓ} fs = begin fs ⊛ ∅ ≡⟨ refl ⟩ (fs >>= pam ∅) ≡⟨ (Monad.cong (refl {x = fs}) λ f → Monad.left-zero (return {ℓ = ℓ} ∘ f)) ⟩ (fs >>= λ _ → ∅) ≡⟨ Monad.right-zero fs ⟩ ∅ ∎ -- _⊛_ distributes over _∣_ from the right. right-distributive : ∀ {ℓ} {A B : Set ℓ} (fs₁ fs₂ : List (A → B)) xs → (fs₁ ∣ fs₂) ⊛ xs ≡ (fs₁ ⊛ xs ∣ fs₂ ⊛ xs) right-distributive fs₁ fs₂ xs = begin (fs₁ ∣ fs₂) ⊛ xs ≡⟨ refl ⟩ (fs₁ ∣ fs₂ >>= pam xs) ≡⟨ Monad.right-distributive fs₁ fs₂ (pam xs) ⟩ (fs₁ >>= pam xs) ∣ (fs₂ >>= pam xs) ≡⟨ refl ⟩ fs₁ ⊛ xs ∣ fs₂ ⊛ xs ∎ -- _⊛_ does not distribute over _∣_ from the left. private not-left-distributive : let fs = id ∷ id ∷ []; xs₁ = true ∷ []; xs₂ = true ∷ false ∷ [] in fs ⊛ (xs₁ ∣ xs₂) ≢ (fs ⊛ xs₁ ∣ fs ⊛ xs₂) not-left-distributive () -- Applicative functor laws. identity : ∀ {a} {A : Set a} (xs : List A) → return id ⊛ xs ≡ xs identity xs = begin return id ⊛ xs ≡⟨ refl ⟩ (return id >>= pam xs) ≡⟨ Monad.left-identity id (pam xs) ⟩ (xs >>= return) ≡⟨ Monad.right-identity xs ⟩ xs ∎ private pam-lemma : ∀ {ℓ} {A B C : Set ℓ} (xs : List A) (f : A → B) (fs : B → List C) → (pam xs f >>= fs) ≡ (xs >>= λ x → fs (f x)) pam-lemma xs f fs = begin (pam xs f >>= fs) ≡⟨ P.sym $ Monad.associative xs (return ∘ f) fs ⟩ (xs >>= λ x → return (f x) >>= fs) ≡⟨ Monad.cong (refl {x = xs}) (λ x → Monad.left-identity (f x) fs) ⟩ (xs >>= λ x → fs (f x)) ∎ composition : ∀ {ℓ} {A B C : Set ℓ} (fs : List (B → C)) (gs : List (A → B)) xs → return _∘′_ ⊛ fs ⊛ gs ⊛ xs ≡ fs ⊛ (gs ⊛ xs) composition {ℓ} fs gs xs = begin return _∘′_ ⊛ fs ⊛ gs ⊛ xs ≡⟨ refl ⟩ (return _∘′_ >>= pam fs >>= pam gs >>= pam xs) ≡⟨ Monad.cong (Monad.cong (Monad.left-identity _∘′_ (pam fs)) (λ f → refl {x = pam gs f})) (λ fg → refl {x = pam xs fg}) ⟩ (pam fs _∘′_ >>= pam gs >>= pam xs) ≡⟨ Monad.cong (pam-lemma fs _∘′_ (pam gs)) (λ _ → refl) ⟩ ((fs >>= λ f → pam gs (_∘′_ f)) >>= pam xs) ≡⟨ P.sym $ Monad.associative fs (λ f → pam gs (_∘′_ f)) (pam xs) ⟩ (fs >>= λ f → pam gs (_∘′_ f) >>= pam xs) ≡⟨ (Monad.cong (refl {x = fs}) λ f → pam-lemma gs (_∘′_ f) (pam xs)) ⟩ (fs >>= λ f → gs >>= λ g → pam xs (f ∘′ g)) ≡⟨ (Monad.cong (refl {x = fs}) λ f → Monad.cong (refl {x = gs}) λ g → P.sym $ pam-lemma xs g (return ∘ f)) ⟩ (fs >>= λ f → gs >>= λ g → pam (pam xs g) f) ≡⟨ (Monad.cong (refl {x = fs}) λ f → Monad.associative gs (pam xs) (return ∘ f)) ⟩ (fs >>= pam (gs >>= pam xs)) ≡⟨ refl ⟩ fs ⊛ (gs ⊛ xs) ∎ homomorphism : ∀ {ℓ} {A B : Set ℓ} (f : A → B) x → return f ⊛ return x ≡ return (f x) homomorphism f x = begin return f ⊛ return x ≡⟨ refl ⟩ (return f >>= pam (return x)) ≡⟨ Monad.left-identity f (pam (return x)) ⟩ pam (return x) f ≡⟨ Monad.left-identity x (return ∘ f) ⟩ return (f x) ∎ interchange : ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) {x} → fs ⊛ return x ≡ return (λ f → f x) ⊛ fs interchange fs {x} = begin fs ⊛ return x ≡⟨ refl ⟩ (fs >>= pam (return x)) ≡⟨ (Monad.cong (refl {x = fs}) λ f → Monad.left-identity x (return ∘ f)) ⟩ (fs >>= λ f → return (f x)) ≡⟨ refl ⟩ (pam fs (λ f → f x)) ≡⟨ P.sym $ Monad.left-identity (λ f → f x) (pam fs) ⟩ (return (λ f → f x) >>= pam fs) ≡⟨ refl ⟩ return (λ f → f x) ⊛ fs ∎
37.555556
118
0.470118
4eb6f6edfe1ea4f4b0ef948913d389983179fd77
321
agda
Agda
Utils.agda
JoeyEremondi/agda-parikh
1e28103ff7dd1d4f3351ef21397833aa4490b7ea
[ "BSD-3-Clause" ]
null
null
null
Utils.agda
JoeyEremondi/agda-parikh
1e28103ff7dd1d4f3351ef21397833aa4490b7ea
[ "BSD-3-Clause" ]
null
null
null
Utils.agda
JoeyEremondi/agda-parikh
1e28103ff7dd1d4f3351ef21397833aa4490b7ea
[ "BSD-3-Clause" ]
null
null
null
module Utils where open import Relation.Binary.PropositionalEquality open import Data.List listHeadEq : ∀ {α} {A : Set α} {x y : A} -> {xt yt : List A} -> x ∷ xt ≡ y ∷ yt -> x ≡ y listHeadEq refl = refl listTailEq : ∀ {α} {A : Set α} {x y : A} -> {xt yt : List A} -> x ∷ xt ≡ y ∷ yt -> xt ≡ yt listTailEq refl = refl
26.75
90
0.588785
1b753f6172df47b3e7eac373c5ef818b2dd74c49
2,664
agda
Agda
Definition/LogicalRelation/Fundamental/Variable.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2018-06-21T08:39:01.000Z
2022-01-17T16:13:53.000Z
Definition/LogicalRelation/Fundamental/Variable.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
null
null
null
Definition/LogicalRelation/Fundamental/Variable.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2022-01-26T14:55:51.000Z
2022-02-15T19:42:19.000Z
{-# OPTIONS --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Fundamental.Variable {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.Typed.Properties open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Substitution open import Tools.Product import Tools.PropositionalEquality as PE -- Fundamental theorem for variables. fundamentalVar : ∀ {Γ A rA x} → x ∷ A ^ rA ∈ Γ → ([Γ] : ⊩ᵛ Γ) → ∃ λ ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ rA / [Γ]) → Γ ⊩ᵛ⟨ ∞ ⟩ var x ∷ A ^ rA / [Γ] / [A] fundamentalVar here (_∙_ {A = A} {rA = rA} {l = l} [Γ] [A]) = (λ ⊢Δ [σ] → let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ])) [σA′] = maybeEmb (irrelevance′ (PE.sym (subst-wk A)) [σA]) in [σA′] , (λ [σ′] [σ≡σ′] → irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₂ ([A] ⊢Δ (proj₁ [σ])) (proj₁ [σ′]) (proj₁ [σ≡σ′])))) , (λ ⊢Δ [σ] → let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ])) [σA′] = maybeEmb (irrelevance′ (PE.sym (subst-wk A)) [σA]) in irrelevanceTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₂ [σ]) , (λ [σ′] [σ≡σ′] → irrelevanceEqTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₂ [σ≡σ′]))) fundamentalVar (there {A = A} h) ([Γ] ∙ [B]) = (λ ⊢Δ [σ] → let [h] = proj₁ (fundamentalVar h [Γ]) ⊢Δ (proj₁ [σ]) [σA] = proj₁ [h] [σA′] = irrelevance′ (PE.sym (subst-wk A)) [σA] in [σA′] , (λ [σ′] [σ≡σ′] → irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₂ [h] (proj₁ [σ′]) (proj₁ [σ≡σ′])))) , (λ ⊢Δ [σ] → let [h] = (proj₁ (fundamentalVar h [Γ])) ⊢Δ (proj₁ [σ]) [σA] = proj₁ [h] [σA′] = irrelevance′ (PE.sym (subst-wk A)) [σA] [h′] = (proj₂ (fundamentalVar h [Γ])) ⊢Δ (proj₁ [σ]) in irrelevanceTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₁ [h′]) , (λ [σ′] [σ≡σ′] → irrelevanceEqTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₂ [h′] (proj₁ [σ′]) (proj₁ [σ≡σ′]))))
42.967742
91
0.489114
fde3fe6e5988ce0da208d696e7f3be7929ef76ab
7,216
agda
Agda
test/asset/agda-stdlib-1.0/Relation/Binary/Indexed/Homogeneous.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Indexed/Homogeneous.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Indexed/Homogeneous.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Homogeneously-indexed binary relations -- -- Indexed structures are laid out in a similar manner as to those -- in Relation.Binary. The main difference is each structure also -- contains proofs for the lifted version of the relation. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Relation.Binary.Indexed.Homogeneous where open import Function using (_⟨_⟩_) open import Level using (Level; _⊔_; suc) open import Relation.Binary as B using (_⇒_) open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Relation.Nullary using (¬_) open import Data.Product using (_,_) ------------------------------------------------------------------------ -- Publically export core definitions open import Relation.Binary.Indexed.Homogeneous.Core public ------------------------------------------------------------------------ -- Equivalences record IsIndexedEquivalence {i a ℓ} {I : Set i} (A : I → Set a) (_≈ᵢ_ : IRel A ℓ) : Set (i ⊔ a ⊔ ℓ) where field reflᵢ : Reflexive A _≈ᵢ_ symᵢ : Symmetric A _≈ᵢ_ transᵢ : Transitive A _≈ᵢ_ reflexiveᵢ : ∀ {i} → _≡_ ⟨ _⇒_ ⟩ _≈ᵢ_ {i} reflexiveᵢ P.refl = reflᵢ -- Lift properties reflexive : _≡_ ⇒ (Lift A _≈ᵢ_) reflexive P.refl i = reflᵢ refl : B.Reflexive (Lift A _≈ᵢ_) refl i = reflᵢ sym : B.Symmetric (Lift A _≈ᵢ_) sym x≈y i = symᵢ (x≈y i) trans : B.Transitive (Lift A _≈ᵢ_) trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i) isEquivalence : B.IsEquivalence (Lift A _≈ᵢ_) isEquivalence = record { refl = refl ; sym = sym ; trans = trans } record IndexedSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where infix 4 _≈ᵢ_ _≈_ field Carrierᵢ : I → Set c _≈ᵢ_ : IRel Carrierᵢ ℓ isEquivalenceᵢ : IsIndexedEquivalence Carrierᵢ _≈ᵢ_ open IsIndexedEquivalence isEquivalenceᵢ public Carrier : Set _ Carrier = ∀ i → Carrierᵢ i _≈_ : B.Rel Carrier _ _≈_ = Lift Carrierᵢ _≈ᵢ_ _≉_ : B.Rel Carrier _ x ≉ y = ¬ (x ≈ y) setoid : B.Setoid _ _ setoid = record { isEquivalence = isEquivalence } ------------------------------------------------------------------------ -- Decidable equivalences record IsIndexedDecEquivalence {i a ℓ} {I : Set i} (A : I → Set a) (_≈ᵢ_ : IRel A ℓ) : Set (i ⊔ a ⊔ ℓ) where infix 4 _≟ᵢ_ field _≟ᵢ_ : Decidable A _≈ᵢ_ isEquivalenceᵢ : IsIndexedEquivalence A _≈ᵢ_ open IsIndexedEquivalence isEquivalenceᵢ public record IndexedDecSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where infix 4 _≈ᵢ_ field Carrierᵢ : I → Set c _≈ᵢ_ : IRel Carrierᵢ ℓ isDecEquivalenceᵢ : IsIndexedDecEquivalence Carrierᵢ _≈ᵢ_ open IsIndexedDecEquivalence isDecEquivalenceᵢ public indexedSetoid : IndexedSetoid I c ℓ indexedSetoid = record { isEquivalenceᵢ = isEquivalenceᵢ } open IndexedSetoid indexedSetoid public using (Carrier; _≈_; _≉_; setoid) ------------------------------------------------------------------------ -- Preorders record IsIndexedPreorder {i a ℓ₁ ℓ₂} {I : Set i} (A : I → Set a) (_≈ᵢ_ : IRel A ℓ₁) (_∼ᵢ_ : IRel A ℓ₂) : Set (i ⊔ a ⊔ ℓ₁ ⊔ ℓ₂) where field isEquivalenceᵢ : IsIndexedEquivalence A _≈ᵢ_ reflexiveᵢ : _≈ᵢ_ ⇒[ A ] _∼ᵢ_ transᵢ : Transitive A _∼ᵢ_ module Eq = IsIndexedEquivalence isEquivalenceᵢ reflᵢ : Reflexive A _∼ᵢ_ reflᵢ = reflexiveᵢ Eq.reflᵢ ∼ᵢ-respˡ-≈ᵢ : Respectsˡ A _∼ᵢ_ _≈ᵢ_ ∼ᵢ-respˡ-≈ᵢ x≈y x∼z = transᵢ (reflexiveᵢ (Eq.symᵢ x≈y)) x∼z ∼ᵢ-respʳ-≈ᵢ : Respectsʳ A _∼ᵢ_ _≈ᵢ_ ∼ᵢ-respʳ-≈ᵢ x≈y z∼x = transᵢ z∼x (reflexiveᵢ x≈y) ∼ᵢ-resp-≈ᵢ : Respects₂ A _∼ᵢ_ _≈ᵢ_ ∼ᵢ-resp-≈ᵢ = ∼ᵢ-respʳ-≈ᵢ , ∼ᵢ-respˡ-≈ᵢ -- Lifted properties reflexive : Lift A _≈ᵢ_ B.⇒ Lift A _∼ᵢ_ reflexive x≈y i = reflexiveᵢ (x≈y i) refl : B.Reflexive (Lift A _∼ᵢ_) refl i = reflᵢ trans : B.Transitive (Lift A _∼ᵢ_) trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i) ∼-respˡ-≈ : (Lift A _∼ᵢ_) B.Respectsˡ (Lift A _≈ᵢ_) ∼-respˡ-≈ x≈y x∼z i = ∼ᵢ-respˡ-≈ᵢ (x≈y i) (x∼z i) ∼-respʳ-≈ : (Lift A _∼ᵢ_) B.Respectsʳ (Lift A _≈ᵢ_) ∼-respʳ-≈ x≈y z∼x i = ∼ᵢ-respʳ-≈ᵢ (x≈y i) (z∼x i) ∼-resp-≈ : (Lift A _∼ᵢ_) B.Respects₂ (Lift A _≈ᵢ_) ∼-resp-≈ = ∼-respʳ-≈ , ∼-respˡ-≈ isPreorder : B.IsPreorder (Lift A _≈ᵢ_) (Lift A _∼ᵢ_) isPreorder = record { isEquivalence = Eq.isEquivalence ; reflexive = reflexive ; trans = trans } record IndexedPreorder {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈ᵢ_ _∼ᵢ_ _≈_ _∼_ field Carrierᵢ : I → Set c _≈ᵢ_ : IRel Carrierᵢ ℓ₁ _∼ᵢ_ : IRel Carrierᵢ ℓ₂ isPreorderᵢ : IsIndexedPreorder Carrierᵢ _≈ᵢ_ _∼ᵢ_ open IsIndexedPreorder isPreorderᵢ public Carrier : Set _ Carrier = ∀ i → Carrierᵢ i _≈_ : B.Rel Carrier _ x ≈ y = ∀ i → x i ≈ᵢ y i _∼_ : B.Rel Carrier _ x ∼ y = ∀ i → x i ∼ᵢ y i preorder : B.Preorder _ _ _ preorder = record { isPreorder = isPreorder } ------------------------------------------------------------------------ -- Partial orders record IsIndexedPartialOrder {i a ℓ₁ ℓ₂} {I : Set i} (A : I → Set a) (_≈ᵢ_ : IRel A ℓ₁) (_≤ᵢ_ : IRel A ℓ₂) : Set (i ⊔ a ⊔ ℓ₁ ⊔ ℓ₂) where field isPreorderᵢ : IsIndexedPreorder A _≈ᵢ_ _≤ᵢ_ antisymᵢ : Antisymmetric A _≈ᵢ_ _≤ᵢ_ open IsIndexedPreorder isPreorderᵢ public renaming ( ∼ᵢ-respˡ-≈ᵢ to ≤ᵢ-respˡ-≈ᵢ ; ∼ᵢ-respʳ-≈ᵢ to ≤ᵢ-respʳ-≈ᵢ ; ∼ᵢ-resp-≈ᵢ to ≤ᵢ-resp-≈ᵢ ; ∼-respˡ-≈ to ≤-respˡ-≈ ; ∼-respʳ-≈ to ≤-respʳ-≈ ; ∼-resp-≈ to ≤-resp-≈ ) antisym : B.Antisymmetric (Lift A _≈ᵢ_) (Lift A _≤ᵢ_) antisym x≤y y≤x i = antisymᵢ (x≤y i) (y≤x i) isPartialOrder : B.IsPartialOrder (Lift A _≈ᵢ_) (Lift A _≤ᵢ_) isPartialOrder = record { isPreorder = isPreorder ; antisym = antisym } record IndexedPoset {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where field Carrierᵢ : I → Set c _≈ᵢ_ : IRel Carrierᵢ ℓ₁ _≤ᵢ_ : IRel Carrierᵢ ℓ₂ isPartialOrderᵢ : IsIndexedPartialOrder Carrierᵢ _≈ᵢ_ _≤ᵢ_ open IsIndexedPartialOrder isPartialOrderᵢ public preorderᵢ : IndexedPreorder I c ℓ₁ ℓ₂ preorderᵢ = record { isPreorderᵢ = isPreorderᵢ } open IndexedPreorder preorderᵢ public using (Carrier; _≈_; preorder) renaming (_∼_ to _≤_) poset : B.Poset _ _ _ poset = record { isPartialOrder = isPartialOrder } ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.17 REL = IREL {-# WARNING_ON_USAGE REL "Warning: REL was deprecated in v0.17. Please use IREL instead." #-} Rel = IRel {-# WARNING_ON_USAGE Rel "Warning: Rel was deprecated in v0.17. Please use IRel instead." #-}
28.1875
73
0.553908
fd3ba5169e450b0aa6c0824332c37d9f2135ec8a
4,318
agda
Agda
notes/defns.agda
cbrewster/ServoNavigation
cea700aea1488df1d27092c8f3d79d5d99f7e09a
[ "CC-BY-4.0" ]
1
2017-04-22T01:51:07.000Z
2017-04-22T01:51:07.000Z
notes/defns.agda
cbrewster/ServoNavigation
cea700aea1488df1d27092c8f3d79d5d99f7e09a
[ "CC-BY-4.0" ]
null
null
null
notes/defns.agda
cbrewster/ServoNavigation
cea700aea1488df1d27092c8f3d79d5d99f7e09a
[ "CC-BY-4.0" ]
null
null
null
module defns where open import prelude record NavigationHistory(D : Set) : Set₁ where field A : Subset(D) field Fo : Forest(D) field FTO : FiniteTotalOrder(D) field Eq : Equivalence(D) open FiniteTotalOrder FTO public open Forest Fo public open Equivalence Eq public field active : D → D field active-A : ∀ d → A(active d) field active-~ : ∀ d → (active d ~ d) field active-uniq : ∀ d e → A(e) → (d ~ e) → (e ≡ active d) field ⇒-impl-≤ : ∀ d e → (d ⇒ e) → (d ≤ e) _≲_ : Rel(D) (d ≲ e) = (d < e) ∧ (d ~ e) ≲-trans : ∀ {d e f} → (d ≲ e) → (e ≲ f) → (d ≲ f) ≲-trans (d<e , d~e) (e<f , e~f) = ((<-trans d<e e<f) , (~-trans d~e e~f)) ≲-impl-< : ∀ {d e} → (d ≲ e) → (d < e) ≲-impl-< (d<e , d~e) = d<e ≲-impl-~ : ∀ {d e} → (d ≲ e) → (d ~ e) ≲-impl-~ (d<e , d~e) = d~e active-~-impl-≡ : ∀ {d e} → (d ∈ A) → (e ∈ A) → (d ~ e) → (d ≡ e) active-~-impl-≡ {d} {e} d∈A e∈A d~e = trans (active-uniq d d d∈A ~-refl) (sym (active-uniq d e e∈A d~e)) SessionPast : D → Subset(D) SessionPast(d) e = (e ≲ d) SessionFuture : D → Subset(D) SessionFuture(d) e = (d ≲ e) JointSessionPast : Subset(D) JointSessionPast d = Inhabited (A ∩ SessionFuture(d)) JointSessionFuture : Subset(D) JointSessionFuture d = Inhabited (A ∩ SessionPast(d)) CanGoBack : Subset(D) CanGoBack d = Inhabited(SessionPast(d)) FwdTarget : Subset(D) FwdTarget = Min(JointSessionFuture) BackTarget : Subset(D) BackTarget = Max(A ∩ CanGoBack) FwdTarget* : ∀ {n} → Subset(D ^ n) FwdTarget* = Min*(Increasing ∩ All(JointSessionFuture)) BackTarget* : ∀ {n} → Subset(D ^ n) BackTarget* = Max*(Decreasing ∩ All((A ∪ JointSessionPast) ∩ CanGoBack)) open NavigationHistory public using (FwdTarget ; BackTarget ; FwdTarget* ; BackTarget*) _traverse-to_ : ∀ {D} → NavigationHistory(D) → D → NavigationHistory(D) H traverse-to d = H′ where D = _ open NavigationHistory H A′ : Subset(D) A′(e) = (¬(d ~ e) ∧ A(e)) ∨ (d ≡ e) active′ : D → D active′ e with (d ~? e) active′ e | in₁ d~e = d active′ e | in₂ ¬d~e = active e active′-A′ : ∀ d → A′(active′ d) active′-A′ e with (d ~? e) active′-A′ e | in₁ d~e = in₂ refl active′-A′ e | in₂ ¬d~e = in₁ ((λ d~ae → ¬d~e (~-trans d~ae (active-~ e))) , active-A e) active′-~ : ∀ d → (active′ d ~ d) active′-~ e with (d ~? e) active′-~ e | in₁ d~e = d~e active′-~ e | in₂ ¬d~e = active-~ e active′-uniq : ∀ d e → A′ e → (d ~ e) → (e ≡ active′ d) active′-uniq e f (in₁ (¬d~f , f∈A)) e~f with (d ~? e) active′-uniq e f (in₁ (¬d~f , f∈A)) e~f | in₁ d~e = contradiction (¬d~f (~-trans d~e e~f)) active′-uniq e f (in₁ (¬d~f , f∈A)) e~f | in₂ ¬d~e = active-uniq e f f∈A e~f active′-uniq e .d (in₂ refl) e~d with (d ~? e) active′-uniq e .d (in₂ refl) e~d | in₁ d~e = refl active′-uniq e .d (in₂ refl) e~d | in₂ ¬d~e = contradiction (¬d~e (~-sym e~d)) H′ = record { A = A′ ; Fo = Fo ; FTO = FTO ; Eq = Eq ; active = active′ ; active-A = active′-A′ ; active-~ = active′-~ ; active-uniq = active′-uniq ; ⇒-impl-≤ = ⇒-impl-≤ } WellFormed : ∀ {D} → (NavigationHistory(D)) → Set WellFormed H = ∀ {a b c d} → (a ≲ b) → (c ≲ d) → (a ∈ A) → (d ∈ A) → (d ≤ b) where open NavigationHistory H _traverses-to_ : ∀ {D n} → NavigationHistory(D) → (D ^ n) → NavigationHistory(D) (H traverses-to nil) = H (H traverses-to (d ∷ ds)) = (H traverse-to d) traverses-to ds _traverse-from_∵_ : ∀ {D} (H : NavigationHistory(D)) d → let open NavigationHistory H in (d ∈ CanGoBack) → NavigationHistory(D) (H traverse-from d ∵ d∈CGB) with max(SessionPast(d)) ∵ d∈CGB where open NavigationHistory H (H traverse-from d ∵ d∈CGB) | (c , _) = (H traverse-to c) _traverses-from_∵_ : ∀ {D n} (H : NavigationHistory(D)) (ds : D ^ n) → let open NavigationHistory H in (ds ∈ All(CanGoBack)) → NavigationHistory(D) (H traverses-from nil ∵ tt) = H (H traverses-from (d ∷ ds) ∵ (d∈CGB , ds∈CGB)) = (H traverse-from d ∵ d∈CGB) traverses-from ds ∵ ds∈CGB data _traverses-by_to_ {D} (H : NavigationHistory(D)) : ℤ → (H : NavigationHistory(D)) → Set where fwd : ∀ {δ} (ds : D ^ (succ δ)) → (ds ∈ FwdTarget*(H)) → (H traverses-by (succ δ) to (H traverses-to ds)) back : ∀ {δ} (ds : D ^ δ) ds∈CGB → (ds ∈ BackTarget*(H)) → (H traverses-by (-ve δ) to (H traverses-from ds ∵ ds∈CGB))
34
119
0.563224
cc2c1f2d72e0b55b045dd01ef6e614329dfa3f05
4,021
agda
Agda
src/Categories/Category/Construction/Properties/Presheaves/Cartesian.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Construction/Properties/Presheaves/Cartesian.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Construction/Properties/Presheaves/Cartesian.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Category.Construction.Properties.Presheaves.Cartesian {o ℓ e} (C : Category o ℓ e) where open import Level open import Data.Unit open import Data.Product using (_,_) open import Data.Product.Relation.Binary.Pointwise.NonDependent open import Function.Equality using (Π) renaming (_∘_ to _∙_) open import Relation.Binary open import Categories.Category.Cartesian open import Categories.Category.Construction.Presheaves open import Categories.Category.Instance.Setoids open import Categories.Functor open import Categories.Functor.Properties open import Categories.Functor.Presheaf open import Categories.NaturalTransformation import Categories.Object.Product as Prod import Categories.Morphism.Reasoning as MR open Π using (_⟨$⟩_) module _ {o′ ℓ′ o″ ℓ″} where Presheaves× : ∀ (A : Presheaf C (Setoids o′ ℓ′)) (A : Presheaf C (Setoids o″ ℓ″)) → Presheaf C (Setoids (o′ ⊔ o″) (ℓ′ ⊔ ℓ″)) Presheaves× A B = record { F₀ = λ X → ×-setoid (A.₀ X) (B.₀ X) ; F₁ = λ f → record { _⟨$⟩_ = λ { (a , b) → A.₁ f ⟨$⟩ a , B.₁ f ⟨$⟩ b } ; cong = λ { (eq₁ , eq₂) → Π.cong (A.₁ f) eq₁ , Π.cong (B.₁ f) eq₂ } } ; identity = λ { (eq₁ , eq₂) → A.identity eq₁ , B.identity eq₂ } ; homomorphism = λ { (eq₁ , eq₂) → A.homomorphism eq₁ , B.homomorphism eq₂ } ; F-resp-≈ = λ { eq (eq₁ , eq₂) → A.F-resp-≈ eq eq₁ , B.F-resp-≈ eq eq₂ } } where module A = Functor A module B = Functor B module IsCartesian o′ ℓ′ where private module C = Category C open C P = Presheaves′ o′ ℓ′ C module P = Category P S = Setoids o′ ℓ′ module S = Category S Presheaves-Cartesian : Cartesian P Presheaves-Cartesian = record { terminal = record { ⊤ = record { F₀ = λ x → record { Carrier = Lift o′ ⊤ ; _≈_ = λ _ _ → Lift ℓ′ ⊤ ; isEquivalence = _ } } ; ! = _ ; !-unique = _ } ; products = record { product = λ {A B} → let module A = Functor A module B = Functor B in record { A×B = Presheaves× A B ; π₁ = ntHelper record { η = λ X → record { _⟨$⟩_ = λ { (fst , _) → fst } ; cong = λ { (eq , _) → eq } } ; commute = λ { f (eq , _) → Π.cong (A.F₁ f) eq } } ; π₂ = ntHelper record { η = λ X → record { _⟨$⟩_ = λ { (_ , snd) → snd } ; cong = λ { (_ , eq) → eq } } ; commute = λ { f (_ , eq) → Π.cong (B.F₁ f) eq } } ; ⟨_,_⟩ = λ {F} α β → let module F = Functor F module α = NaturalTransformation α module β = NaturalTransformation β in ntHelper record { η = λ Y → record { _⟨$⟩_ = λ S → α.η Y ⟨$⟩ S , β.η Y ⟨$⟩ S ; cong = λ eq → Π.cong (α.η Y) eq , Π.cong (β.η Y) eq } ; commute = λ f eq → α.commute f eq , β.commute f eq } ; project₁ = λ {F α β x} eq → let module F = Functor F module α = NaturalTransformation α module β = NaturalTransformation β in Π.cong (α.η x) eq ; project₂ = λ {F α β x} eq → let module F = Functor F module α = NaturalTransformation α module β = NaturalTransformation β in Π.cong (β.η x) eq ; unique = λ {F α β δ} eq₁ eq₂ {x} eq → let module F = Functor F module α = NaturalTransformation α module β = NaturalTransformation β module δ = NaturalTransformation δ in Setoid.sym (A.₀ x) (eq₁ (Setoid.sym (F.₀ x) eq)) , Setoid.sym (B.₀ x) (eq₂ (Setoid.sym (F.₀ x) eq)) } } } module Presheaves-Cartesian = Cartesian Presheaves-Cartesian
33.789916
126
0.517782
36e00605e28c220318f37bf56529b5336a1afb8b
2,294
agda
Agda
LibraBFT/Impl/IO/OBM/InputOutputHandlers.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
4
2020-12-16T19:43:41.000Z
2021-12-18T19:24:05.000Z
LibraBFT/Impl/IO/OBM/InputOutputHandlers.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
72
2021-02-04T05:04:33.000Z
2022-03-25T05:36:11.000Z
LibraBFT/Impl/IO/OBM/InputOutputHandlers.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
6
2020-12-16T19:43:52.000Z
2022-02-18T01:04:32.000Z
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 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 LibraBFT.Base.Types import LibraBFT.Impl.Consensus.Network as Network import LibraBFT.Impl.Consensus.RoundManager as RoundManager open import LibraBFT.Impl.OBM.Logging.Logging open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Util.Util open import LibraBFT.Prelude open import Optics.All -- This module defines the handler for our implementation. For most message types, it does some -- initial validation before passing the message on to the proper handlers. module LibraBFT.Impl.IO.OBM.InputOutputHandlers where epvv : LBFT (Epoch × ValidatorVerifier) epvv = _,_ <$> gets (_^∙ rmSafetyRules ∙ srPersistentStorage ∙ pssSafetyData ∙ sdEpoch) <*> gets (_^∙ rmEpochState ∙ esVerifier) module handleProposal (now : Instant) (pm : ProposalMsg) where step₀ : LBFT Unit step₁ : Epoch → ValidatorVerifier → LBFT Unit step₀ = do (myEpoch , vv) ← epvv step₁ myEpoch vv step₁ myEpoch vv = do case⊎D Network.processProposal {- {!!} -} pm myEpoch vv of λ where (Left (Left e)) → logErr e (Left (Right i)) → logInfo i (Right _) → RoundManager.processProposalMsgM now pm handleProposal : Instant → ProposalMsg → LBFT Unit handleProposal = handleProposal.step₀ module handleVote (now : Instant) (vm : VoteMsg) where step₀ : LBFT Unit step₁ : Epoch → ValidatorVerifier → LBFT Unit step₀ = do (myEpoch , vv) ← epvv step₁ myEpoch vv step₁ myEpoch vv = do case Network.processVote vm myEpoch vv of λ where (Left (Left e)) → logErr e (Left (Right i)) → logInfo i (Right _) → RoundManager.processVoteMsgM now vm abstract handleVote = handleVote.step₀ handleVote≡ : handleVote ≡ handleVote.step₀ handleVote≡ = refl handle : NodeId → NetworkMsg → Instant → LBFT Unit handle _self msg now = case msg of λ where (P pm) → handleProposal now pm (V vm) → handleVote now vm (C cm) → pure unit -- We don't do anything with commit messages, they are just for defining Correctness.
33.735294
111
0.712293
8b8339cdcde0328529c8151707502c427d9069e5
51
agda
Agda
test/interaction/Issue1232/List.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1232/List.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1232/List.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue1232.List where import Issue1232.Nat
10.2
27
0.823529
5e18c95deca5430452347d8324b160a0d818b2f1
218
agda
Agda
test/Succeed/WithOfFunctionType.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/WithOfFunctionType.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/WithOfFunctionType.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2013-10-20 'with' only abstracts at base type module WithOfFunctionType where postulate A B : Set P : B → Set mkP : (x : B) → P x f : A → B a : A test : P (f a) test with f ... | g = mkP (g a)
14.533333
57
0.568807
11fd9c81a65ef76477315d111655400b305c4aba
47
agda
Agda
test/Fail/Relevance-subtyping-4.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Relevance-subtyping-4.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Relevance-subtyping-4.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
f : {A B : Set} → (A → B) → .A → B f g x = g x
15.666667
34
0.319149
a0b38ffa553981b6d9a156b6cf5ebebea9722de3
381
agda
Agda
test/Succeed/Issue1322.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1322.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1322.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where data _==_ {A : Set} (a : A) : A → Set where refl : a == a data ⊥ : Set where data ℕ : Set where zero : ℕ suc : ℕ → ℕ it : ∀ {a} {A : Set a} ⦃ x : A ⦄ → A it ⦃ x ⦄ = x f : (n : ℕ) ⦃ p : ⦃ _ : n == zero ⦄ → ⊥ ⦄ → ℕ f n = n g : (n : ℕ) ⦃ q : ⦃ _ : n == zero ⦄ → ⊥ ⦄ → ℕ g n ⦃ q ⦄ = f n h : (n : ℕ) ⦃ q : ⦃ _ : n == zero ⦄ → ⊥ ⦄ → ℕ h n ⦃ q ⦄ = f n ⦃ it ⦄
15.875
45
0.35958
cc3d0adc2dafa303652653962e216d9f94657c6f
5,031
agda
Agda
src/Properties/StepBeta.agda
peterthiemann/definitional-session
c2213909c8a308fb1c1c1e4e789d65ba36f6042c
[ "BSD-3-Clause" ]
9
2019-01-19T16:33:27.000Z
2021-01-18T08:10:14.000Z
src/Properties/StepBeta.agda
peterthiemann/definitional-session
c2213909c8a308fb1c1c1e4e789d65ba36f6042c
[ "BSD-3-Clause" ]
null
null
null
src/Properties/StepBeta.agda
peterthiemann/definitional-session
c2213909c8a308fb1c1c1e4e789d65ba36f6042c
[ "BSD-3-Clause" ]
null
null
null
module Properties.StepBeta where open import Data.List open import Data.List.All open import Data.Product open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Typing open import Syntax open import Global open import Channel open import Values open import Session open import Schedule open import ProcessSyntax open import ProcessRun open import Properties.Base -- V: (λx.e)v = e[v/x] -- let f = λx.e in let r = f v in E --> [let x = v in] let r = e in E mklhs : ∀ {Φ tin tout} (e : Expr (tin ∷ []) tout) (E : Expr (tout ∷ Φ) TUnit) → Expr (tin ∷ Φ) TUnit mklhs {Φ} e E = letbind (rght (split-all-right Φ)) (ulambda [] [] [] e) (letbind (left (left (split-all-right Φ))) (app (left (rght [])) (here []) (here [])) E) mkrhs : ∀ {Φ tin tout} (e : Expr (tin ∷ []) tout) (E : Expr (tout ∷ Φ) TUnit) → Expr (tin ∷ Φ) TUnit mkrhs {Φ} e E = letbind (left (split-all-right Φ)) e E reductionT : Set reductionT = ∀ {tin tout} (e : Expr (tin ∷ []) tout) (E : Expr (tout ∷ []) TUnit) (v : Val [] tin) → let ϱ = vcons ss-[] v (vnil []-inactive) in let lhs = run (left []) ss-[] (mklhs e E) ϱ (halt []-inactive UUnit) in let rhs = run (left []) ss-[] (mkrhs e E) ϱ (halt []-inactive UUnit) in restart (restart lhs) ≡ rhs reduction : reductionT reduction e E v with split-env (rght []) (vcons ss-[] v (vnil []-inactive)) ... | sperght = refl -- open reduction reduction-open-type : Set reduction-open-type = ∀ {Φ tin tout} (e : Expr (tin ∷ []) tout) (E : Expr (tout ∷ Φ) TUnit) (ϱ : VEnv [] (tin ∷ Φ)) → let lhs = run (left (split-all-left Φ)) ss-[] (mklhs e E) ϱ (halt []-inactive UUnit) in let rhs = run (left (split-all-left Φ)) ss-[] (mkrhs e E) ϱ (halt []-inactive UUnit) in restart (restart lhs) ≡ rhs reduction-open : reduction-open-type reduction-open {Φ} e E (vcons ss-[] v ϱ) rewrite split-rotate-lemma {Φ} | split-env-right-lemma0 ϱ with ssplit-compose3 ss-[] ss-[] ... | ssc3 rewrite split-env-right-lemma0 ϱ | split-rotate-lemma {Φ} = refl -- open reduction with split between closure and context mktype' : Set mktype' = ∀ {Φ Φ₁ Φ₂ tin tout} (sp : Split Φ Φ₁ Φ₂) (un-Φ₁ : All Unr Φ₁) (e : Expr (tin ∷ Φ₁) tout) (E : Expr (tout ∷ Φ₂) TUnit) → Expr (tin ∷ Φ) TUnit mklhs' : mktype' mklhs' {Φ} {Φ₁} {Φ₂} sp un-Φ₁ e E = letbind (rght sp) (ulambda (split-all-left Φ₁) un-Φ₁ [] e) (letbind (left (left (split-all-right Φ₂))) (app (left (rght [])) (here []) (here [])) E) mkrhs' : mktype' mkrhs' {Φ} {Φ₁} {Φ₂} sp un-Φ₁ e E = letbind (left sp) e E reduction-open-type' : Set reduction-open-type' = ∀ {Φ Φ₁ Φ₂ tin tout} (sp : Split Φ Φ₁ Φ₂) (un-Φ₁ : All Unr Φ₁) (e : Expr (tin ∷ Φ₁) tout) (E : Expr (tout ∷ Φ₂) TUnit) (ϱ : VEnv [] (tin ∷ Φ)) → let lhs = run (left (split-all-left Φ)) ss-[] (mklhs' sp un-Φ₁ e E) ϱ (halt []-inactive UUnit) in let rhs = run (left (split-all-left Φ)) ss-[] (mkrhs' sp un-Φ₁ e E) ϱ (halt []-inactive UUnit) in restart (restart lhs) ≡ rhs -- this runs into the split-from-disjoint, which was hacked into function application -- it's not clear if there's a way round -- hence the proposition needs to be proved with a more specific assumption {- reduction-open' : reduction-open-type' reduction-open' {Φ} {Φ₁} {Φ₂} sp un-Φ₁ e E (vcons ss-[] v ϱ) rewrite split-rotate-lemma' sp with split-env sp ϱ ... | ([] , []) , ss-[] , ϱ₁ , ϱ₂ rewrite split-env-left-lemma0 ϱ₁ with ssplit-compose3 ss-[] ss-[] ... | ssc3 rewrite split-env-right-lemma0 ϱ₂ with ssplit-compose3 ss-[] ss-[] ... | ssc3' rewrite split-rotate-lemma {Φ₂} = {!!} -} -- straightforward generalization of the inspect pattern record Reveal2_·_·_is_ {A B : Set} {C : A → B → Set} (f : (x : A) (y : B) → C x y) (x : A) (y : B) (z : C x y) : Set₁ where constructor [[_]] field eq : f x y ≡ z inspect2 : ∀ {A B : Set} {C : A → B → Set} (f : (x : A) (y : B) → C x y) (x : A) (y : B) → Reveal2 f · x · y is f x y inspect2 f x y = [[ refl ]] reduction-open-type'' : Set reduction-open-type'' = ∀ {Φ₁ Φ₂ tin tout} → let Φ,sp = split-from-disjoint Φ₁ Φ₂ in let Φ = proj₁ Φ,sp in let sp = proj₂ Φ,sp in (un-Φ₁ : All Unr Φ₁) (e : Expr (tin ∷ Φ₁) tout) (E : Expr (tout ∷ Φ₂) TUnit) (ϱ : VEnv [] (tin ∷ Φ)) → let lhs = run (left (split-all-left Φ)) ss-[] (mklhs' sp un-Φ₁ e E) ϱ (halt []-inactive UUnit) in let rhs = run (left (split-all-left Φ)) ss-[] (mkrhs' sp un-Φ₁ e E) ϱ (halt []-inactive UUnit) in restart (restart lhs) ≡ rhs reduction-open'' : reduction-open-type'' reduction-open'' {Φ₁} {Φ₂} un-Φ₁ e E (vcons ss-[] v ϱ) with split-from-disjoint Φ₁ Φ₂ | inspect2 split-from-disjoint Φ₁ Φ₂ ... | Φ , sp | [[ eq ]] rewrite split-rotate-lemma' sp with split-env sp ϱ ... | ([] , []) , ss-[] , ϱ₁ , ϱ₂ rewrite split-env-left-lemma0 ϱ₁ with ssplit-compose3 ss-[] ss-[] ... | ssc3 rewrite split-env-right-lemma0 ϱ₂ with ssplit-compose3 ss-[] ss-[] ... | ssc3' rewrite split-rotate-lemma {Φ₂} | eq = refl
32.458065
101
0.602266
39d23e071b3ab94ba057e5a887445e54af795219
1,754
agda
Agda
src/Categories/Diagram/Coend.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
src/Categories/Diagram/Coend.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
null
null
null
src/Categories/Diagram/Coend.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category open import Categories.Functor.Bifunctor module Categories.Diagram.Coend {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (F : Bifunctor (Category.op C) C D) where private module C = Category C module D = Category D open D open HomReasoning open Equiv variable A B : Obj f g : A ⇒ B open import Level open import Data.Product using (Σ; _,_) open import Categories.Functor open import Categories.Functor.Construction.Constant open import Categories.NaturalTransformation.Dinatural open import Categories.Morphism.Reasoning D open Functor F record Cowedge : Set (levelOfTerm F) where field E : Obj dinatural : DinaturalTransformation F (const E) module dinatural = DinaturalTransformation dinatural Cowedge-∘ : (W : Cowedge) → Cowedge.E W ⇒ A → Cowedge Cowedge-∘ {A = A} W f = record { E = A ; dinatural = extranaturalˡ (λ X → f ∘ dinatural.α X) (assoc ○ ∘-resp-≈ʳ (extranatural-commˡ dinatural) ○ sym-assoc) } where open Cowedge W record Coend : Set (levelOfTerm F) where field cowedge : Cowedge module cowedge = Cowedge cowedge open cowedge public open Cowedge field factor : (W : Cowedge) → cowedge.E ⇒ E W universal : ∀ {W : Cowedge} {A} → factor W ∘ cowedge.dinatural.α A ≈ dinatural.α W A unique : ∀ {W : Cowedge} {g : cowedge.E ⇒ E W} → (∀ {A} → g ∘ cowedge.dinatural.α A ≈ dinatural.α W A) → factor W ≈ g η-id : factor cowedge ≈ D.id η-id = unique identityˡ unique′ :(∀ {A} → f ∘ cowedge.dinatural.α A ≈ g ∘ cowedge.dinatural.α A) → f ≈ g unique′ {f = f} {g = g} eq = ⟺ (unique {W = Cowedge-∘ cowedge f} refl) ○ unique (⟺ eq)
28.290323
124
0.645952
0d1ea08467d38b3bd7ccf7c878af590f4688ca00
8,620
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Lex/Strict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Lex/Strict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Lex/Strict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Lexicographic ordering of lists ------------------------------------------------------------------------ -- The definitions of lexicographic ordering used here are suitable if -- the argument order is a strict partial order. {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Lex.Strict where open import Data.Empty using (⊥) open import Data.Unit.Base using (⊤; tt) open import Function using (_∘_; id) open import Data.Product using (_,_) open import Data.Sum using (inj₁; inj₂) open import Data.List.Base using (List; []; _∷_) open import Level using (_⊔_) open import Relation.Nullary using (yes; no; ¬_) open import Relation.Binary open import Relation.Binary.Consequences open import Data.List.Relation.Binary.Pointwise as Pointwise using (Pointwise; []; _∷_; head; tail) open import Data.List.Relation.Binary.Lex.Core as Core public using (base; halt; this; next; ¬≤-this; ¬≤-next) ---------------------------------------------------------------------- -- Strict lexicographic ordering. module _ {a ℓ₁ ℓ₂} {A : Set a} where Lex-< : (_≈_ : Rel A ℓ₁) (_≺_ : Rel A ℓ₂) → Rel (List A) (a ⊔ ℓ₁ ⊔ ℓ₂) Lex-< = Core.Lex ⊥ -- Properties module _ {_≈_ : Rel A ℓ₁} {_≺_ : Rel A ℓ₂} where private _≋_ = Pointwise _≈_ _<_ = Lex-< _≈_ _≺_ ¬[]<[] : ¬ [] < [] ¬[]<[] (base ()) <-irreflexive : Irreflexive _≈_ _≺_ → Irreflexive _≋_ _<_ <-irreflexive irr [] (base ()) <-irreflexive irr (x≈y ∷ xs≋ys) (this x<y) = irr x≈y x<y <-irreflexive irr (x≈y ∷ xs≋ys) (next _ xs⊴ys) = <-irreflexive irr xs≋ys xs⊴ys <-asymmetric : Symmetric _≈_ → _≺_ Respects₂ _≈_ → Asymmetric _≺_ → Asymmetric _<_ <-asymmetric sym resp as = asym where irrefl : Irreflexive _≈_ _≺_ irrefl = asym⟶irr resp sym as asym : Asymmetric _<_ asym (halt) () asym (base bot) _ = bot asym (this x<y) (this y<x) = as x<y y<x asym (this x<y) (next y≈x ys⊴xs) = irrefl (sym y≈x) x<y asym (next x≈y xs⊴ys) (this y<x) = irrefl (sym x≈y) y<x asym (next x≈y xs⊴ys) (next y≈x ys⊴xs) = asym xs⊴ys ys⊴xs <-antisymmetric : Symmetric _≈_ → Irreflexive _≈_ _≺_ → Asymmetric _≺_ → Antisymmetric _≋_ _<_ <-antisymmetric = Core.antisymmetric <-transitive : IsEquivalence _≈_ → _≺_ Respects₂ _≈_ → Transitive _≺_ → Transitive _<_ <-transitive = Core.transitive <-compare : Symmetric _≈_ → Trichotomous _≈_ _≺_ → Trichotomous _≋_ _<_ <-compare sym tri [] [] = tri≈ ¬[]<[] [] ¬[]<[] <-compare sym tri [] (y ∷ ys) = tri< halt (λ()) (λ()) <-compare sym tri (x ∷ xs) [] = tri> (λ()) (λ()) halt <-compare sym tri (x ∷ xs) (y ∷ ys) with tri x y ... | tri< x<y x≉y y≮x = tri< (this x<y) (x≉y ∘ head) (¬≤-this (x≉y ∘ sym) y≮x) ... | tri> x≮y x≉y y<x = tri> (¬≤-this x≉y x≮y) (x≉y ∘ head) (this y<x) ... | tri≈ x≮y x≈y y≮x with <-compare sym tri xs ys ... | tri< xs<ys xs≉ys ys≮xs = tri< (next x≈y xs<ys) (xs≉ys ∘ tail) (¬≤-next y≮x ys≮xs) ... | tri≈ xs≮ys xs≈ys ys≮xs = tri≈ (¬≤-next x≮y xs≮ys) (x≈y ∷ xs≈ys) (¬≤-next y≮x ys≮xs) ... | tri> xs≮ys xs≉ys ys<xs = tri> (¬≤-next x≮y xs≮ys) (xs≉ys ∘ tail) (next (sym x≈y) ys<xs) <-decidable : Decidable _≈_ → Decidable _≺_ → Decidable _<_ <-decidable = Core.decidable (no id) <-respects₂ : IsEquivalence _≈_ → _≺_ Respects₂ _≈_ → _<_ Respects₂ _≋_ <-respects₂ = Core.respects₂ <-isStrictPartialOrder : IsStrictPartialOrder _≈_ _≺_ → IsStrictPartialOrder _≋_ _<_ <-isStrictPartialOrder spo = record { isEquivalence = Pointwise.isEquivalence isEquivalence ; irrefl = <-irreflexive irrefl ; trans = Core.transitive isEquivalence <-resp-≈ trans ; <-resp-≈ = Core.respects₂ isEquivalence <-resp-≈ } where open IsStrictPartialOrder spo <-isStrictTotalOrder : IsStrictTotalOrder _≈_ _≺_ → IsStrictTotalOrder _≋_ _<_ <-isStrictTotalOrder sto = record { isEquivalence = Pointwise.isEquivalence isEquivalence ; trans = <-transitive isEquivalence <-resp-≈ trans ; compare = <-compare Eq.sym compare } where open IsStrictTotalOrder sto <-strictPartialOrder : ∀ {a ℓ₁ ℓ₂} → StrictPartialOrder a ℓ₁ ℓ₂ → StrictPartialOrder _ _ _ <-strictPartialOrder spo = record { isStrictPartialOrder = <-isStrictPartialOrder isStrictPartialOrder } where open StrictPartialOrder spo <-strictTotalOrder : ∀ {a ℓ₁ ℓ₂} → StrictTotalOrder a ℓ₁ ℓ₂ → StrictTotalOrder _ _ _ <-strictTotalOrder sto = record { isStrictTotalOrder = <-isStrictTotalOrder isStrictTotalOrder } where open StrictTotalOrder sto ---------------------------------------------------------------------- -- Non-strict lexicographic ordering. module _ {a ℓ₁ ℓ₂} {A : Set a} where Lex-≤ : (_≈_ : Rel A ℓ₁) (_≺_ : Rel A ℓ₂) → Rel (List A) (a ⊔ ℓ₁ ⊔ ℓ₂) Lex-≤ = Core.Lex ⊤ -- Properties ≤-reflexive : (_≈_ : Rel A ℓ₁) (_≺_ : Rel A ℓ₂) → Pointwise _≈_ ⇒ Lex-≤ _≈_ _≺_ ≤-reflexive _≈_ _≺_ [] = base tt ≤-reflexive _≈_ _≺_ (x≈y ∷ xs≈ys) = next x≈y (≤-reflexive _≈_ _≺_ xs≈ys) module _ {_≈_ : Rel A ℓ₁} {_≺_ : Rel A ℓ₂} where private _≋_ = Pointwise _≈_ _≤_ = Lex-≤ _≈_ _≺_ ≤-antisymmetric : Symmetric _≈_ → Irreflexive _≈_ _≺_ → Asymmetric _≺_ → Antisymmetric _≋_ _≤_ ≤-antisymmetric = Core.antisymmetric ≤-transitive : IsEquivalence _≈_ → _≺_ Respects₂ _≈_ → Transitive _≺_ → Transitive _≤_ ≤-transitive = Core.transitive -- Note that trichotomy is an unnecessarily strong precondition for -- the following lemma. ≤-total : Symmetric _≈_ → Trichotomous _≈_ _≺_ → Total _≤_ ≤-total _ _ [] [] = inj₁ (base tt) ≤-total _ _ [] (x ∷ xs) = inj₁ halt ≤-total _ _ (x ∷ xs) [] = inj₂ halt ≤-total sym tri (x ∷ xs) (y ∷ ys) with tri x y ... | tri< x<y _ _ = inj₁ (this x<y) ... | tri> _ _ y<x = inj₂ (this y<x) ... | tri≈ _ x≈y _ with ≤-total sym tri xs ys ... | inj₁ xs≲ys = inj₁ (next x≈y xs≲ys) ... | inj₂ ys≲xs = inj₂ (next (sym x≈y) ys≲xs) ≤-decidable : Decidable _≈_ → Decidable _≺_ → Decidable _≤_ ≤-decidable = Core.decidable (yes tt) ≤-respects₂ : IsEquivalence _≈_ → _≺_ Respects₂ _≈_ → _≤_ Respects₂ _≋_ ≤-respects₂ = Core.respects₂ ≤-isPreorder : IsEquivalence _≈_ → Transitive _≺_ → _≺_ Respects₂ _≈_ → IsPreorder _≋_ _≤_ ≤-isPreorder eq tr resp = record { isEquivalence = Pointwise.isEquivalence eq ; reflexive = ≤-reflexive _≈_ _≺_ ; trans = Core.transitive eq resp tr } ≤-isPartialOrder : IsStrictPartialOrder _≈_ _≺_ → IsPartialOrder _≋_ _≤_ ≤-isPartialOrder spo = record { isPreorder = ≤-isPreorder isEquivalence trans <-resp-≈ ; antisym = Core.antisymmetric Eq.sym irrefl asym } where open IsStrictPartialOrder spo ≤-isTotalOrder : IsStrictTotalOrder _≈_ _≺_ → IsTotalOrder _≋_ _≤_ ≤-isTotalOrder sto = record { isPartialOrder = ≤-isPartialOrder isStrictPartialOrder ; total = ≤-total Eq.sym compare } where open IsStrictTotalOrder sto ≤-isDecTotalOrder : IsStrictTotalOrder _≈_ _≺_ → IsDecTotalOrder _≋_ _≤_ ≤-isDecTotalOrder sto = record { isTotalOrder = ≤-isTotalOrder sto ; _≟_ = Pointwise.decidable _≟_ ; _≤?_ = ≤-decidable _≟_ _<?_ } where open IsStrictTotalOrder sto ≤-preorder : ∀ {a ℓ₁ ℓ₂} → Preorder a ℓ₁ ℓ₂ → Preorder _ _ _ ≤-preorder pre = record { isPreorder = ≤-isPreorder isEquivalence trans ∼-resp-≈ } where open Preorder pre ≤-partialOrder : ∀ {a ℓ₁ ℓ₂} → StrictPartialOrder a ℓ₁ ℓ₂ → Poset _ _ _ ≤-partialOrder spo = record { isPartialOrder = ≤-isPartialOrder isStrictPartialOrder } where open StrictPartialOrder spo ≤-decTotalOrder : ∀ {a ℓ₁ ℓ₂} → StrictTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder _ _ _ ≤-decTotalOrder sto = record { isDecTotalOrder = ≤-isDecTotalOrder isStrictTotalOrder } where open StrictTotalOrder sto
37.155172
74
0.559629
11a8ae0e03811266c41282bc6e273aeadaf599a8
11,939
agda
Agda
EH.agda
andmkent/misc-HoTT
b05c58ffdaed99932ca2acc632deca8d14742b04
[ "MIT" ]
1
2016-01-26T18:17:16.000Z
2016-01-26T18:17:16.000Z
EH.agda
andmkent/misc-HoTT
b05c58ffdaed99932ca2acc632deca8d14742b04
[ "MIT" ]
null
null
null
EH.agda
andmkent/misc-HoTT
b05c58ffdaed99932ca2acc632deca8d14742b04
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} -- Finished 6pm Th, March 24! yay! -- Bit thanks to tzaikin for posting his work online (some of his macros -- were essential for this proof for me) and to the code we saw in class today. module EH where open import Level using (_⊔_) open import Data.Product using (Σ; _,_) open import Function renaming (_∘_ to _○_) infixr 8 _∘_ -- path composition infixr 8 _⋆_ -- horizontal path composition infix 4 _≡_ -- propositional equality infix 4 _∼_ -- homotopy between two functions infix 4 _≃_ -- type of equivalences -- macros from tzaikin for equational rewriting over non-standard ≡ infixr 4 _≡⟨_⟩_ infix 4 _∎ ------------------------------------------------------------------------------ -- A few HoTT primitives data _≡_ {ℓ} {A : Set ℓ} : (a b : A) → Set ℓ where refl : (a : A) → (a ≡ a) pathInd : ∀ {u ℓ} → {A : Set u} → (C : {x y : A} → x ≡ y → Set ℓ) → (c : (x : A) → C (refl x)) → ({x y : A} (p : x ≡ y) → C p) pathInd C c (refl x) = c x -- ! : ∀ {u} → {A : Set u} {x y : A} → (x ≡ y) → (y ≡ x) ! = pathInd (λ {x} {y} _ → y ≡ x) refl _∘_ : ∀ {u} → {A : Set u} → {x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) _∘_ {u} {A} {x} {y} {z} p q = pathInd {u} (λ {x} {y} p → ((z : A) → (q : y ≡ z) → (x ≡ z))) (λ x z q → pathInd (λ {x} {z} _ → x ≡ z) refl {x} {z} q) {x} {y} p z q -- Handy "macros" (from tzaikin) _∎ : {A : Set} → (p : A) → p ≡ p p ∎ = refl p _≡⟨_⟩_ : {A : Set} → {q r : A} → (p : A) → p ≡ q → q ≡ r → p ≡ r p ≡⟨ α ⟩ β = α ∘ β -- RU : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ p ∘ refl y) RU {A} {x} {y} p = pathInd (λ {x} {y} p → p ≡ p ∘ (refl y)) (λ x → refl (refl x)) {x} {y} p LU : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ refl x ∘ p) LU {A} {x} {y} p = pathInd (λ {x} {y} p → p ≡ (refl x) ∘ p) (λ x → refl (refl x)) {x} {y} p invTransL : {A : Set} {x y : A} → (p : x ≡ y) → (! p ∘ p ≡ refl y) invTransL {A} {x} {y} p = pathInd (λ {x} {y} p → ! p ∘ p ≡ refl y) (λ x → refl (refl x)) {x} {y} p invTransR : ∀ {ℓ} {A : Set ℓ} {x y : A} → (p : x ≡ y) → (p ∘ ! p ≡ refl x) invTransR {ℓ} {A} {x} {y} p = pathInd (λ {x} {y} p → p ∘ ! p ≡ refl x) (λ x → refl (refl x)) {x} {y} p invId : {A : Set} {x y : A} → (p : x ≡ y) → (! (! p) ≡ p) invId {A} {x} {y} p = pathInd (λ {x} {y} p → ! (! p) ≡ p) (λ x → refl (refl x)) {x} {y} p assocP : {A : Set} {x y z w : A} → (p : x ≡ y) → (q : y ≡ z) → (r : z ≡ w) → (p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r) assocP {A} {x} {y} {z} {w} p q r = pathInd (λ {x} {y} p → (z : A) → (w : A) → (q : y ≡ z) → (r : z ≡ w) → p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r) (λ x z w q r → pathInd (λ {x} {z} q → (w : A) → (r : z ≡ w) → (refl x) ∘ (q ∘ r) ≡ ((refl x) ∘ q) ∘ r) (λ x w r → pathInd (λ {x} {w} r → (refl x) ∘ ((refl x) ∘ r) ≡ ((refl x) ∘ (refl x)) ∘ r) (λ x → (refl (refl x))) {x} {w} r) {x} {z} q w r) {x} {y} p z w q r invComp : {A : Set} {x y z : A} → (p : x ≡ y) → (q : y ≡ z) → ! (p ∘ q) ≡ ! q ∘ ! p invComp {A} {x} {y} {z} p q = pathInd (λ {x} {y} p → (z : A) → (q : y ≡ z) → ! (p ∘ q) ≡ ! q ∘ ! p) (λ x z q → pathInd (λ {x} {z} q → ! (refl x ∘ q) ≡ ! q ∘ ! (refl x)) (λ x → refl (refl x)) {x} {z} q) {x} {y} p z q -- ap : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {x y : A} → (f : A → B) → (x ≡ y) → (f x ≡ f y) ap {ℓ} {ℓ'} {A} {B} {x} {y} f p = pathInd -- on p (λ {x} {y} p → f x ≡ f y) (λ x → refl (f x)) {x} {y} p apfTrans : ∀ {u} → {A B : Set u} {x y z : A} → (f : A → B) → (p : x ≡ y) → (q : y ≡ z) → ap f (p ∘ q) ≡ (ap f p) ∘ (ap f q) apfTrans {u} {A} {B} {x} {y} {z} f p q = pathInd {u} (λ {x} {y} p → (z : A) → (q : y ≡ z) → ap f (p ∘ q) ≡ (ap f p) ∘ (ap f q)) (λ x z q → pathInd {u} (λ {x} {z} q → ap f (refl x ∘ q) ≡ (ap f (refl x)) ∘ (ap f q)) (λ x → refl (refl (f x))) {x} {z} q) {x} {y} p z q apfInv : ∀ {u} → {A B : Set u} {x y : A} → (f : A → B) → (p : x ≡ y) → ap f (! p) ≡ ! (ap f p) apfInv {u} {A} {B} {x} {y} f p = pathInd {u} (λ {x} {y} p → ap f (! p) ≡ ! (ap f p)) (λ x → refl (ap f (refl x))) {x} {y} p apfComp : {A B C : Set} {x y : A} → (f : A → B) → (g : B → C) → (p : x ≡ y) → ap g (ap f p) ≡ ap (g ○ f) p apfComp {A} {B} {C} {x} {y} f g p = pathInd (λ {x} {y} p → ap g (ap f p) ≡ ap (g ○ f) p) (λ x → refl (ap g (ap f (refl x)))) {x} {y} p apfId : {A : Set} {x y : A} → (p : x ≡ y) → ap id p ≡ p apfId {A} {x} {y} p = pathInd (λ {x} {y} p → ap id p ≡ p) (λ x → refl (refl x)) {x} {y} p -- transport : ∀ {ℓ ℓ'} → {A : Set ℓ} {x y : A} → (P : A → Set ℓ') → (p : x ≡ y) → P x → P y transport {ℓ} {ℓ'} {A} {x} {y} P p = pathInd -- on p (λ {x} {y} p → (P x → P y)) (λ _ → id) {x} {y} p apd : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : A → Set ℓ'} {x y : A} → (f : (a : A) → B a) → (p : x ≡ y) → (transport B p (f x) ≡ f y) apd {ℓ} {ℓ'} {A} {B} {x} {y} f p = pathInd (λ {x} {y} p → transport B p (f x) ≡ f y) (λ x → refl (f x)) {x} {y} p -- Homotopies and equivalences _∼_ : ∀ {ℓ ℓ'} → {A : Set ℓ} {P : A → Set ℓ'} → (f g : (x : A) → P x) → Set (ℓ ⊔ ℓ') _∼_ {ℓ} {ℓ'} {A} {P} f g = (x : A) → f x ≡ g x record qinv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkqinv field g : B → A α : (f ○ g) ∼ id β : (g ○ f) ∼ id record isequiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkisequiv field g : B → A α : (f ○ g) ∼ id h : B → A β : (h ○ f) ∼ id equiv₁ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → qinv f → isequiv f equiv₁ (mkqinv qg qα qβ) = mkisequiv qg qα qg qβ _≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ') A ≃ B = Σ (A → B) isequiv postulate univalence : {A B : Set} → (A ≡ B) ≃ (A ≃ B) ------------------------------------------------------------------------------ -- Path and loop spaces 1-Path : {A : Set} → (a b : A) → Set 1-Path {A} a b = (a ≡ b) 2-Path : {A : Set} → (a b : A) (p q : 1-Path {A} a b) → Set 2-Path {A} a b p q = (p ≡ q) Ω : (A : Set) → {a : A} → Set Ω A {a} = 1-Path {A} a a Ω² : (A : Set) → {a : A} → Set Ω² A {a} = 2-Path {A} a a (refl a) (refl a) -- Whiskering Lemmas -- ___ p ___ ___ r ___ -- / \ / \ -- a α⇓ b β⇓ c -- \ / \ / -- --- q --- --- s --- wskR : {A : Set} {a b c : A} {p q : 1-Path {A} a b} → (α : 2-Path {A} a b p q) → (r : 1-Path {A} b c) → (p ∘ r) ≡ (q ∘ r) wskR {A} {a} {b} {c} {p} {q} α r = (pathInd (λ {b} {c} r → {p q : a ≡ b} → (α : p ≡ q) → 2-Path {A} a c (p ∘ r) (q ∘ r)) (λ b {p} {q} α → (p ∘ refl b) ≡⟨ ! (RU p) ⟩ p ≡⟨ α ⟩ q ≡⟨ RU q ⟩ (q ∘ refl b) ∎) r) α wskL : {A : Set} {a b c : A} {r s : 1-Path {A} b c} → (q : 1-Path {A} a b) → (β : 2-Path {A} b c r s) → (q ∘ r) ≡ (q ∘ s) wskL {A} {a} {b} {c} {r} {s} q β = (pathInd (λ {a} {b} q → {r s : b ≡ c} → (α : r ≡ s) → 2-Path {A} a c (q ∘ r) (q ∘ s)) ((λ b {p} {q} β → (refl b ∘ p) ≡⟨ ! (LU p) ⟩ p ≡⟨ β ⟩ q ≡⟨ LU q ⟩ (refl b ∘ q) ∎)) q) β _⋆_ : {A : Set} {a b c : A} {p q : 1-Path {A} a b} {r s : 1-Path {A} b c} (α : 2-Path {A} a b p q) → (β : 2-Path {A} b c r s) → (p ∘ r) ≡ (q ∘ s) _⋆_ {A} {a} {b} {c} {p} {q} {r} {s} α β = (wskR α r) ∘ (wskL q β) Hcomp→compR1 : {A : Set} {a : A} (α : 2-Path {A} a a (refl a) (refl a)) → (wskR α (refl a)) ≡ (! (RU (refl a))) ∘ α ∘ (RU (refl a)) Hcomp→compR1 {A} {a} α = refl (pathInd (λ {x} {y} _ → x ≡ y) refl (pathInd (λ {x} {y} _ → (x₁ : a ≡ a) (x₂ : y ≡ x₁) → x ≡ x₁) (λ x x₁ → pathInd (λ {x₂} {y} _ → x₂ ≡ y) refl) α (refl a) (refl (refl a)))) Hcomp→compL1 : {A : Set} {a : A} (β : 2-Path {A} a a (refl a) (refl a)) → (wskL (refl a) β) ≡ (! (LU (refl a))) ∘ β ∘ (LU (refl a)) Hcomp→compL1 {A} {a} β = refl (pathInd (λ {x} {y} _ → x ≡ y) refl (pathInd (λ {x} {y} _ → (x₁ : a ≡ a) (x₂ : y ≡ x₁) → x ≡ x₁) (λ x x₁ → pathInd (λ {x₂} {y} _ → x₂ ≡ y) refl) β (refl a) (refl (refl a)))) -- proof from pg 81 α⋆β≡α∘β : {A : Set} {a : A} (α : 2-Path {A} a a (refl a) (refl a)) → (β : 2-Path {A} a a (refl a) (refl a)) → α ⋆ β ≡ α ∘ β α⋆β≡α∘β {A} {a} α β = α ⋆ β ≡⟨ refl (α ⋆ β) ⟩ (wskR α ra) ∘ (wskL ra β) ≡⟨ refl ((!(refl ra) ∘ α ∘ (refl ra)) ∘ (wskL ra β)) ⟩ (!(refl ra) ∘ (α ∘ (refl ra))) ∘ (wskL ra β) ≡⟨ ap (λ p → ((!(refl ra) ∘ p) ∘ (wskL ra β))) (! (RU α)) ⟩ ((!(refl ra) ∘ α) ∘ (wskL ra β)) ≡⟨ ap (λ p → (p ∘ (wskL ra β))) (! (LU α)) ⟩ (α ∘ (wskL ra β)) ≡⟨ refl (α ∘ (wskL ra β)) ⟩ (α ∘ (!(refl ra) ∘ β ∘ (refl ra))) ≡⟨ ap (λ p → (α ∘ (!(refl ra) ∘ p))) (! (RU β)) ⟩ (α ∘ (!(refl ra) ∘ β)) ≡⟨ ap (λ p → (α ∘ p)) (! (LU β)) ⟩ α ∘ β ∎ where ra = (refl a) _⋆'_ : {A : Set} {a b c : A} {p q : 1-Path {A} a b} {r s : 1-Path {A} b c} (α : 2-Path {A} a b p q) → (β : 2-Path {A} b c r s) → (p ∘ r) ≡ (q ∘ s) _⋆'_ {A} {a} {b} {c} {p} {q} {r} {s} α β = (wskL p β) ∘ (wskR α s) α⋆'β≡β∘α : {A : Set} {a : A} (α : 2-Path {A} a a (refl a) (refl a)) → (β : 2-Path {A} a a (refl a) (refl a)) → α ⋆' β ≡ β ∘ α α⋆'β≡β∘α {A} {a} α β = α ⋆' β ≡⟨ refl (α ⋆' β) ⟩ (wskL ra β) ∘ (!(refl ra) ∘ (α ∘ (refl ra))) ≡⟨ ap (λ p → ((wskL ra β) ∘ (!(refl ra) ∘ p))) (! (RU α)) ⟩ ((wskL ra β) ∘ (!(refl ra) ∘ α)) ≡⟨ ap (λ p → ((wskL ra β) ∘ p)) (! (LU α)) ⟩ ((wskL ra β) ∘ α) ≡⟨ refl ((wskL ra β) ∘ α) ⟩ ((!(refl ra) ∘ β ∘ (refl ra)) ∘ α) ≡⟨ ap (λ p → ((!(refl ra) ∘ p) ∘ α)) (! (RU β)) ⟩ ((!(refl ra) ∘ β) ∘ α) ≡⟨ ap (λ p → (p ∘ α)) (! (LU β)) ⟩ β ∘ α ∎ where ra = (refl a) -- yuck lots of nested induction α⋆β≡α⋆'β : {A : Set} {a : A} (α : 2-Path {A} a a (refl a) (refl a)) → (β : 2-Path {A} a a (refl a) (refl a)) → α ⋆ β ≡ α ⋆' β α⋆β≡α⋆'β {A} {a} α β = -- induction on α pathInd (λ α → α ⋆ β ≡ α ⋆' β) (λ p → -- induction on β pathInd (λ β → refl p ⋆ β ≡ refl p ⋆' β) (λ q → -- induction on p (pathInd (λ {a} {b} p → (c : A) → (q : b ≡ c) → ((refl p ⋆ refl q) ≡ (refl p ⋆' refl q))) (λ a d q → -- induction on q pathInd (λ {a} {d} r → ((refl (refl a) ⋆ refl r) ≡ (refl (refl a) ⋆' refl r))) (λ a → refl (refl (refl a))) q) p a q)) β) α eckmann-hilton : {A : Set} {a : A} (α β : Ω² A {a}) → α ∘ β ≡ β ∘ α eckmann-hilton {A} {a} α β = α ∘ β ≡⟨ ! (α⋆β≡α∘β α β) ⟩ α ⋆ β ≡⟨ α⋆β≡α⋆'β α β ⟩ α ⋆' β ≡⟨ α⋆'β≡β∘α α β ⟩ β ∘ α ∎ ------------------------------------------------------------------------------
27.320366
88
0.333613
8b5f80b19be30dbe921cfbfbdeda461429544dbf
154
agda
Agda
test/fail/NotInScope.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/fail/NotInScope.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/NotInScope.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
-- Also works for parts of operators. module NotInScope where postulate X : Set if_then_else_ : X -> X -> X -> X x : X bad = if x thenn x else x
14
37
0.636364
11f0ab4c9565d60d129de2307484c9e1c79fa8d9
603
agda
Agda
homotopy/S1SuspensionS0.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
homotopy/S1SuspensionS0.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/S1SuspensionS0.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT module homotopy.S1SuspensionS0 where {- To -} module To = S¹Rec (north Bool) (merid _ false ∙ ! (merid _ true)) to : S¹ → Suspension Bool to = To.f {- From -} from-merid : Bool → base == base from-merid true = loop from-merid false = idp module From = SuspensionRec Bool base base from-merid from : Suspension Bool → S¹ from = From.f {- ToFrom and FromTo -} postulate -- TODO, easy and boring to-from : (x : Suspension Bool) → to (from x) == x from-to : (x : S¹) → from (to x) == x e : S¹ ≃ Suspension Bool e = equiv to from to-from from-to
18.272727
65
0.646766
5ef6211a17f6acfb60f3209468a30f68478dd41f
2,836
agda
Agda
Control/Monad/HeapT/Sized.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Control/Monad/HeapT/Sized.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Control/Monad/HeapT/Sized.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --no-positivity-check --no-termination-check --allow-unsolved-metas #-} open import Prelude open import Algebra open import Algebra.Monus open import Relation.Binary open import Data.Maybe open import Data.List using (List; _∷_; []; foldr) module Control.Monad.HeapT.Sized {ℓ} (mon : CTMAPOM ℓ) (gmon : GradedMonad (CTMAPOM.monoid mon) ℓ ℓ) where open CTMAPOM mon open GradedMonad gmon private variable w i j : 𝑆 infixr 5 _∷_ infixr 6 _⋊_ mutual data Root′ (A : Type ℓ) (i : 𝑆) : Type ℓ where _⋊_ : ∀ w → (w < i → 𝐹 w (Branch A (i ∸ w))) → Root′ A i data Node (A : Type ℓ) (i : 𝑆) : Type ℓ where ⌊_⌋ : A → Node A i ⌈_⌉ : Root′ A i → Node A i data Branch (A : Type ℓ) (i : 𝑆) : Type ℓ where [] : Branch A i _∷_ : Node A i → 𝐹 ε (Branch A i) → Branch A i Heap : Type ℓ → Type ℓ Heap A = ∀ {i} → 𝐹 ε (Branch A i) infixr 5 _++_ _++_ : 𝐹 w (Branch A i) → 𝐹 ε (Branch A i) → 𝐹 w (Branch A i) xs ++ ys = xs >>=ε λ { [] → ys ; (x ∷ xs) → pure (x ∷ xs ++ ys) } infixr 1 _>>=ᴺ_ _>>=ᴴ_ mutual _>>=ᴺ_ : Node A i → (A → Heap B) → 𝐹 ε (Branch B i) ⌊ x ⌋ >>=ᴺ f = f x ⌈ w ⋊ s ⌉ >>=ᴺ f = pure (⌈ w ⋊ (λ w<i → s w<i >>=ᴴ f) ⌉ ∷ pure []) _>>=ᴴ_ : 𝐹 w (Branch A i) → (A → Heap B) → 𝐹 w (Branch B i) xs >>=ᴴ f = xs >>=ε λ { [] → pure [] ; (x ∷ xs) → (x >>=ᴺ f) ++ (xs >>=ᴴ f) } pureᴴ : A → Heap A pureᴴ x = pure (⌊ x ⌋ ∷ pure []) liftᴴ : 𝐹 w A → Heap A liftᴴ xs = pure (⌈ _ ⋊ const (map (λ x → ⌊ x ⌋ ∷ pure []) xs) ⌉ ∷ pure []) flatten : 𝐹 w (Branch A i) → 𝐹 w (List A × List (Root′ A i)) flatten xs = xs >>=ε λ { [] → pure ([] , []) ; (⌊ x ⌋ ∷ xs) → map (map₁ (x ∷_)) (flatten xs) ; (⌈ x ⌉ ∷ xs) → map (map₂ (x ∷_)) (flatten xs) } module PopMin (decomp : ∀ {A B w₁ w₂ w₃} → 𝐹 (w₁ ∙ w₂) A → 𝐹 (w₁ ∙ w₃) B → 𝐹 w₁ (𝐹 w₂ A × 𝐹 w₃ B)) (choice : {w : 𝑆} → {A B : Type ℓ} → (A → 𝐹 w B) → 𝐹 w (A → B)) where _∪_ : Root′ A i → Root′ A i → Root′ A i _∪_ {i = i} (wˣ ⋊ xs) (wʸ ⋊ ys) with wˣ ≤|≥ wʸ ... | inr (k , wˣ≡wʸ∙k) = {!!} ... | inl (k , wʸ≡wˣ∙k) = wˣ ⋊ λ wˣ<i → map (λ { (xs , ys) → ⌈ k ⋊ (λ k<i∸wˣ → subst (𝐹 _ ∘ Branch _) (cong (_ ∸_) wʸ≡wˣ∙k ; sym (∸‿assoc _ wˣ k)) (map (_$ subst (_< i) (sym wʸ≡wˣ∙k) {!!}) ys)) ⌉ ∷ xs }) (decomp (subst (flip 𝐹 _) (sym (∙ε _)) (xs wˣ<i)) (subst (flip 𝐹 _) wʸ≡wˣ∙k (choice ys))) where lemma : ∀ x y z → x < z → y < z ∸ x → x ∙ y < z lemma = {!!} -- ⋃⁺ : Root A → List (Root A) → Root A -- ⋃⁺ x₁ [] = x₁ -- ⋃⁺ x₁ (x₂ ∷ []) = x₁ ∪ x₂ -- ⋃⁺ x₁ (x₂ ∷ x₃ ∷ xs) = (x₁ ∪ x₂) ∪ ⋃⁺ x₃ xs -- ⋃ : List (Root A) → Maybe (Root A) -- ⋃ [] = nothing -- ⋃ (x ∷ xs) = just (⋃⁺ x xs) -- popMin : 𝐹 w (Branch A) → 𝐹 w (List A × Maybe (Root A)) -- popMin = map (map₂ ⋃) ∘ flatten
30.170213
296
0.464386
4ec7f3b73bef12b373d687882a96fd76861dc20d
2,291
agda
Agda
agda-stdlib/src/Data/AVL/Map.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/AVL/Map.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/AVL/Map.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Maps from keys to values, based on AVL trees -- This modules provides a simpler map interface, without a dependency -- between the key and value types. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (StrictTotalOrder) module Data.AVL.Map {a ℓ₁ ℓ₂} (strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂) where open import Data.Bool.Base using (Bool) open import Data.List.Base using (List) open import Data.Maybe.Base using (Maybe) open import Data.Product using (_×_) open import Level using (_⊔_) import Data.AVL strictTotalOrder as AVL open StrictTotalOrder strictTotalOrder renaming (Carrier to Key) ------------------------------------------------------------------------ -- The map type Map : ∀ {v} → (V : Set v) → Set (a ⊔ v ⊔ ℓ₂) Map v = AVL.Tree (AVL.const v) ------------------------------------------------------------------------ -- Repackaged functions module _ {v} {V : Set v} where empty : Map V empty = AVL.empty singleton : Key → V → Map V singleton = AVL.singleton insert : Key → V → Map V → Map V insert = AVL.insert insertWith : Key → (Maybe V → V) → Map V → Map V insertWith = AVL.insertWith delete : Key → Map V → Map V delete = AVL.delete lookup : Key → Map V → Maybe V lookup = AVL.lookup module _ {v w} {V : Set v} {W : Set w} where map : (V → W) → Map V → Map W map f = AVL.map f module _ {v} {V : Set v} where infix 4 _∈?_ _∈?_ : Key → Map V → Bool _∈?_ = AVL._∈?_ headTail : Map V → Maybe ((Key × V) × Map V) headTail = AVL.headTail initLast : Map V → Maybe (Map V × (Key × V)) initLast = AVL.initLast fromList : List (Key × V) → Map V fromList = AVL.fromList toList : Map V → List (Key × V) toList = AVL.toList module _ {v w} {V : Set v} {W : Set w} where unionWith : (V → Maybe W → W) → Map V → Map W → Map W unionWith f = AVL.unionWith f module _ {v} {V : Set v} where union : Map V → Map V → Map V union = AVL.union unionsWith : (V → Maybe V → V) → List (Map V) → Map V unionsWith f = AVL.unionsWith f unions : List (Map V) → Map V unions = AVL.unions
24.115789
72
0.550415
30d62f28be82b86a086fe6b2b241259b6075a714
864
agda
Agda
test/Fail/FrozenMVar2.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/FrozenMVar2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/FrozenMVar2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2011-04-11 adapted from Data.Nat.Properties module FrozenMVar2 where open import Common.Level open import Common.Equality Rel : ∀ {a} → Set a → (ℓ : Level) → Set (a ⊔ lsuc ℓ) Rel A ℓ = A → A → Set ℓ Op₂ : ∀ {ℓ} → Set ℓ → Set ℓ Op₂ A = A → A → A module FunctionProperties {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where Associative : Op₂ A → Set _ Associative _∙_ = ∀ x y z → ((x ∙ y) ∙ z) ≈ (x ∙ (y ∙ z)) open FunctionProperties _≡_ -- THIS produces frozen metas data ℕ : Set where zℕ : ℕ sℕ : (n : ℕ) → ℕ infixl 6 _+_ _+_ : ℕ → ℕ → ℕ zℕ + n = n sℕ m + n = sℕ (m + n) +-assoc : Associative _+_ -- +-assoc : ∀ x y z -> ((x + y) + z) ≡ (x + (y + z)) -- this works +-assoc zℕ _ _ = refl +-assoc (sℕ m) n o = cong sℕ (+-assoc m n o) -- Due to a frozen meta we get: -- Type mismatch when checking that the pattern zℕ has type _95
22.736842
67
0.56713
1ed307c4aef127d6b44ec6e283e925f65cd08886
840
agda
Agda
agda/Relation/Binary/Equivalence/Reasoning.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
agda/Relation/Binary/Equivalence/Reasoning.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Relation/Binary/Equivalence/Reasoning.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} open import Relation.Binary module Relation.Binary.Equivalence.Reasoning {a} {𝑆 : Set a} {b} (equivalence : Equivalence 𝑆 b) where open Equivalence equivalence open import Function import Path infixr 2 ≋˘⟨⟩-syntax _≋⟨⟩_ ≋⟨∙⟩-syntax ≡⟨∙⟩-syntax ≋˘⟨⟩-syntax : ∀ (x : 𝑆) {y z} → y ≋ z → y ≋ x → x ≋ z ≋˘⟨⟩-syntax _ y≋z y≋x = sym y≋x ⟨ trans ⟩ y≋z syntax ≋˘⟨⟩-syntax x y≋z y≋x = x ≋˘⟨ y≋x ⟩ y≋z ≋⟨∙⟩-syntax : ∀ (x : 𝑆) {y z} → y ≋ z → x ≋ y → x ≋ z ≋⟨∙⟩-syntax _ y≋z x≋y = x≋y ⟨ trans ⟩ y≋z syntax ≋⟨∙⟩-syntax x y≋z x≋y = x ≋⟨ x≋y ⟩ y≋z _≋⟨⟩_ : ∀ (x : 𝑆) {y} → x ≋ y → x ≋ y _ ≋⟨⟩ x≋y = x≋y ≡⟨∙⟩-syntax : ∀ (x : 𝑆) {y z} → y ≋ z → x Path.≡ y → x ≋ z ≡⟨∙⟩-syntax _ y≋z x≡y = Path.subst (_≋ _) (Path.sym x≡y) y≋z syntax ≡⟨∙⟩-syntax x y≋z x≡y = x ≡⟨ x≡y ⟩ y≋z infix 2.5 _∎ _∎ : ∀ x → x ≋ x x ∎ = refl
24
102
0.504762
37d5842b12393648b800af3a2f2139f083449675
4,969
agda
Agda
benchmark/cwf/CwF.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
benchmark/cwf/CwF.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
benchmark/cwf/CwF.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module CwF where open import Setoid open EqChain infixr 30 _⇒_ infixl 50 _/_ _/ˢ_ infixr 45 _◄_ infixl 45 _▷_ Cxt : Set Cxt = Setoid _⇒_ : Cxt -> Cxt -> Set Γ ⇒ Δ = El (Γ ==> Δ) Type : Cxt -> Set Type Γ = Fam Γ _/_ : {Γ Δ : Cxt} -> Type Γ -> (Δ ⇒ Γ) -> Type Δ A / σ = A ○ σ lem-/id : {Γ : Cxt}{A : Type Γ} -> A / id == A lem-/id = lem-○-id Term : (Γ : Cxt) -> Type Γ -> Set Term Γ A = El (Π Γ A) _◄_ : {Γ : Cxt}{A B : Type Γ} -> B == A -> Term Γ A -> Term Γ B B=A ◄ u = eqΠ refl B=A << u _/ˢ_ : {Γ Δ : Cxt}{A : Type Γ} -> Term Γ A -> (σ : Δ ⇒ Γ) -> Term Δ (A / σ) u /ˢ σ = u ∘ σ _▷_ : (Γ : Cxt) -> Type Γ -> Cxt Γ ▷ A = Σ Γ A wk : {Γ : Cxt}(A : Type Γ) -> Γ ▷ A ⇒ Γ wk A = ƛ fst \ x y x=y -> fst-eq x=y vz : {Γ : Cxt}(A : Type Γ) -> Term (Γ ▷ A) (A / wk A) vz A = ƛ snd \ x y x=y -> snd-eq x=y ext : {Γ Δ : Cxt}(A : Type Γ)(σ : Δ ⇒ Γ)(u : Term Δ (A / σ)) -> Δ ⇒ Γ ▷ A ext A σ u = ƛ (\x -> (σ # x , u # x)) \x y x=y -> eqInΣ refl (#-cong-R σ x=y) (#-cong-R u x=y) lem-/-· : {Γ Δ Θ : Cxt}(A : Type Γ)(σ : Δ ⇒ Γ)(δ : Θ ⇒ Δ) -> A / σ · δ == A / σ / δ lem-/-· A σ δ = eqFam refl \x y x=y -> !-cong-R A (sym (cast-id' _ (#-cong-R σ (#-cong-R δ (cast-id' _ (sym x=y)))))) lem-wk-∘-ext : {Γ Δ : Cxt}(A : Type Δ)(σ : Γ ⇒ Δ)(u : Term Γ (A / σ)) -> wk A ∘ ext A σ u == σ lem-wk-∘-ext A (ƛ σ pσ) u = eqInΠ refl pσ lem-vz-/-ext : {Γ Δ : Cxt}(A : Type Δ)(σ : Γ ⇒ Δ)(u : Term Γ (A / σ)) -> vz A /ˢ (ext A σ u) == u lem-vz-/-ext A σ (ƛ u pu) = eqInΠ refl pu -- (σ , u) ∘ δ == (σ ∘ δ , u / δ) lem-ext-∘ : {Γ Δ Θ : Cxt}{A : Type Γ}(σ : Δ ⇒ Γ)(δ : Θ ⇒ Δ)(u : Term Δ (A / σ)) -> ext A σ u · δ == ext A (σ · δ) (lem-/-· A σ δ ◄ u /ˢ δ) lem-ext-∘ σ δ u = eqInΠ refl \x y x=y -> eqInΣ refl (cast-irr _ _ (#-cong-R σ (#-cong-R δ (cast-irr _ _ x=y)))) (cast-irr _ _ (#-cong-R u (#-cong-R δ (cast-irr _ _ x=y)))) <_> : {Γ : Cxt}{A : Type Γ} -> Term Γ A -> Γ ⇒ Γ ▷ A < u > = ext _ id (lem-○-id ◄ u) lift : {Γ Δ : Cxt}(A : Type Γ)(σ : Δ ⇒ Γ) -> Δ ▷ (A / σ) ⇒ Γ ▷ A lift A σ = ƛ (\x -> σ # fst x , snd x) \x y x=y -> eqInΣ refl (#-cong-R σ (fst-eq x=y)) (snd-eq x=y) curryFam : {A : Setoid}{F : Fam A} -> Fam (Σ A F) -> (x : El A) -> Fam (F ! x) curryFam G x = fam (\y -> G ! (x , y)) \z w z=w -> !-cong-R G (eqInΣ refl refl z=w) Pi : {Γ : Cxt}(A : Type Γ)(B : Type (Γ ▷ A)) -> Type Γ Pi A B = fam (\x -> Π (A ! x) (curryFam B x)) \x y x=y -> eqΠ (!-cong-R A (sym x=y)) (eqFam (!-cong-R A (sym x=y)) \z w z=w -> !-cong-R B (eqInΣ refl x=y z=w) ) lem-Pi-/ : {Γ Δ : Cxt}(A : Type Γ)(B : Type (Γ ▷ A))(σ : Δ ⇒ Γ) -> Pi A B / σ == Pi (A / σ) (B / lift A σ) lem-Pi-/ A B σ = eqFam refl \x y x=y -> eqΠ (Aσ-eq x=y) (eqFam (Aσ-eq x=y) \z w z=w -> !-cong-R B (eqInΣ refl (#-cong-R σ x=y) z=w) ) where Aσ-eq : forall {x y} -> x == y -> A ! σ # y == A ! σ # x Aσ-eq x=y = !-cong-R A (#-cong-R σ (sym x=y)) lam : {Γ : Cxt}{A : Type Γ}{B : Type (Γ ▷ A)} -> Term (Γ ▷ A) B -> Term Γ (Pi A B) lam {A = A} f = ƛ (\γ -> ƛ (\x -> f # (γ , x)) (prf₁ γ)) prf₂ where prf₁ : forall γ x y x=y -> _ prf₁ = \γ x y x=y -> #-cong-R f (eqInΣ refl refl x=y) prf₂ = \x y x=y -> eqInΠ (!-cong-R A (sym x=y)) \z w z=w -> #-cong-R f (eqInΣ refl x=y z=w) app : {Γ : Cxt}(A : Type Γ)(B : Type (Γ ▷ A)) (v : Term Γ (Pi A B))(u : Term Γ A) -> Term Γ (B / < u >) app A B v u = ƛ (\γ -> prf₁ γ << v # γ # (u # γ)) prf₂ where lem : forall γ -> < u > # γ == (γ , u # γ) lem γ = eqInΣ refl refl (#-cong (lem-○-id ◄ u) u (sym (cast-id _)) refl) prf₁ : forall γ -> (B / < u >) ! γ == B ! (γ , u # γ) prf₁ γ = !-cong-R B (lem γ) prf₂ = \x y x=y -> cast-irr _ _ (#-cong (v # x) (v # y) (#-cong-R v x=y) (#-cong-R u x=y) ) lem-β : {Γ : Cxt}(A : Type Γ)(B : Type (Γ ▷ A)) (v : Term (Γ ▷ A) B)(u : Term Γ A) -> app A B (lam v) u == v /ˢ < u > lem-β A B v u = eqInΠ refl \x y x=y -> sym (cast-id' _ (#-cong-R v (eqInΣ refl (sym x=y) (#-cong (lem-○-id ◄ u) u (sym (cast-id _)) (sym x=y))) ) ) -- The stack blows when trying to prove η. -- I'm not sure it does anymore, but I have no idea how to prove η, -- I struggled just giving the type. -- lem-η : {Γ : Cxt}(A : Type Γ)(B : Type (Γ ▷ A)) -- (v : Term Γ (Pi A B)) → -- v == lam (app (A / wk A) (B / lift A (wk A)) (sym (lem-Pi-/ A B (wk A)) ◄ v /ˢ wk A) (vz A)) -- lem-η {Γ} A B (ƛ f pf) = -- eqInΠ =S=-refl λ γ δ γ=δ → -- proof f γ ≡ ƛ (_#_ (f γ)) (λ _ _ → #-cong-R (f γ)) by η (f γ) -- ≡ _ by eqInΠ (!-cong-R A (sym γ=δ)) (λ x y x=y → -- proof f γ # x -- ≡ (_ << (_ << f (_ << δ))) # y by {!!} -- qed) -- qed
32.907285
103
0.40813
21734ec91c594dfee3b3a4ac0bbdbfe3ec96dd08
905
agda
Agda
agda-stdlib/src/Relation/Binary/Properties/StrictTotalOrder.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Relation/Binary/Properties/StrictTotalOrder.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Relation/Binary/Properties/StrictTotalOrder.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by strict partial orders ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Properties.StrictTotalOrder {s₁ s₂ s₃} (STO : StrictTotalOrder s₁ s₂ s₃) where open Relation.Binary.StrictTotalOrder STO open import Relation.Binary.Construct.StrictToNonStrict _≈_ _<_ import Relation.Binary.Properties.StrictPartialOrder as SPO open import Relation.Binary.Consequences ------------------------------------------------------------------------ -- _<_ - the strict version is a strict total order decTotalOrder : DecTotalOrder _ _ _ decTotalOrder = record { isDecTotalOrder = isDecTotalOrder isStrictTotalOrder } open DecTotalOrder decTotalOrder public
31.206897
72
0.592265
7c1fea9aabf445bcf5a708b5644777a4dd67865f
6,125
agda
Agda
TypeTheory/Container/DepM.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/Container/DepM.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/Container/DepM.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
{-# OPTIONS --sized-types --without-K #-} module DepM where open import Level using (Level) open import Data.Product open import Data.Nat open import Data.Fin open import Data.Unit open import Data.Empty open import Data.Vec hiding (_∈_; [_]) open import Relation.Binary.PropositionalEquality open import Function open import Data.Sum open import Size Fam : Set → Set₁ Fam I = I → Set Fam₂ : {I : Set} → (I → Set) → Set₁ Fam₂ {I} J = (i : I) → J i → Set -- | Morphisms between families MorFam : {I : Set} (P₁ P₂ : Fam I) → Set MorFam {I} P₁ P₂ = (x : I) → P₁ x → P₂ x _⇒_ = MorFam compMorFam : {I : Set} {P₁ P₂ P₃ : Fam I} → MorFam P₁ P₂ → MorFam P₂ P₃ → MorFam P₁ P₃ compMorFam f₁ f₂ a = f₂ a ∘ f₁ a _⊚_ = compMorFam -- | Reindexing of families _* : {I J : Set} → (I → J) → Fam J → Fam I (u *) P = P ∘ u -- | Reindexing on morphisms of families _*₁ : {I J : Set} → (u : I → J) → {P₁ P₂ : Fam J} → (P₁ ⇒ P₂) → (u *) P₁ ⇒ (u *) P₂ (u *₁) f i = f (u i) -- | This notation for Π-types is more useful for our purposes here. Π : (A : Set) (P : Fam A) → Set Π A P = (x : A) → P x -- | Fully general Σ-type, which we need to interpret the interpretation -- of families of containers as functors for inductive types. data Σ' {A B : Set} (f : A → B) (P : Fam A) : B → Set where ins : (a : A) → P a → Σ' f P (f a) p₁' : {A B : Set} {u : A → B} {P : Fam A} {b : B} → Σ' u P b → A p₁' (ins a _) = a p₂' : {A B : Set} {u : A → B} {P : Fam A} {b : B} → (x : Σ' u P b) → P (p₁' x) p₂' (ins _ x) = x p₌' : {A B : Set} {u : A → B} {P : Fam A} {b : B} → (x : Σ' u P b) → u (p₁' x) ≡ b p₌' (ins _ _) = refl ins' : {A B : Set} {u : A → B} {P : Fam A} → (a : A) → (b : B) → u a ≡ b → P a → Σ' u P b ins' a ._ refl x = ins a x Σ'-eq : {A B : Set} {f : A → B} {P : Fam A} → (a a' : A) (x : P a) (x' : P a') (a≡a' : a ≡ a') (x≡x' : subst P a≡a' x ≡ x') → subst (Σ' f P) (cong f a≡a') (ins a x) ≡ ins a' x' Σ'-eq a .a x .x refl refl = refl Σ-eq : {a b : Level} {A : Set a} {B : A → Set b} → (a a' : A) (x : B a) (x' : B a') (a≡a' : a ≡ a') (x≡x' : subst B a≡a' x ≡ x') → (a , x) ≡ (a' , x') Σ-eq a .a x .x refl refl = refl ×-eq : {ℓ : Level} {A : Set ℓ} {B : Set ℓ} → (a a' : A) (b b' : B) → a ≡ a' → b ≡ b' → (a , b) ≡ (a' , b') ×-eq a .a b .b refl refl = refl ×-eqˡ : {A B : Set} {a a' : A} {b b' : B} → (a , b) ≡ (a' , b') → a ≡ a' ×-eqˡ refl = refl ×-eqʳ : {A B : Set} {a a' : A} {b b' : B} → (a , b) ≡ (a' , b') → b ≡ b' ×-eqʳ refl = refl -- | Comprehension ⟪_⟫ : {I : Set} → Fam I → Set ⟪_⟫ {I} B = Σ I B ⟪_⟫² : {I J : Set} → (J → Fam I) → Fam J ⟪_⟫² {I} B j = Σ I (B j) π : {I : Set} → (B : Fam I) → ⟪ B ⟫ → I π B = proj₁ _⊢₁_ : {I : Set} {A : Fam I} → (i : I) → A i → ⟪ A ⟫ i ⊢₁ a = (i , a) _,_⊢₂_ : {I : Set} {A : Fam I} {B : Fam ⟪ A ⟫} → (i : I) → (a : A i) → B (i , a) → ⟪ B ⟫ i , a ⊢₂ b = ((i , a) , b) -- Not directly definable... -- record Π' {A B : Set} (u : A → B) (P : A → Set) : B → Set where -- field -- app : (a : A) → Π' u P (u a) → P a -- | ... but this does the job. Π' : {I J : Set} (u : I → J) (P : Fam I) → Fam J Π' {I} u P j = Π (∃ λ i → u i ≡ j) (λ { (i , _) → P i}) Π'' : {I J : Set} (u : I → J) (j : J) (P : Fam (∃ λ i → u i ≡ j)) → Set Π'' {I} u j P = Π (∃ λ i → u i ≡ j) P -- | Application for fully general Π-types. app : {I J : Set} {u : I → J} {P : Fam I} → (u *) (Π' u P) ⇒ P app i f = f (i , refl) -- | Abstraction for fully general Π-types. abs : {I J : Set} {u : I → J} {P : Fam I} → ((i : I) → P i) → ((j : J) → Π' u P j) abs {u = u} f .(u i) (i , refl) = f i -- | Abstraction for fully general Π-types. abs' : {I J : Set} {u : I → J} {P : Fam I} {X : Fam J} → ((u *) X ⇒ P) → (X ⇒ Π' u P) abs' {u = u} f .(u i) x (i , refl) = f i x -- | Abstraction for fully general Π-types. abs'' : {I J : Set} {u : I → J} {P : Fam I} → (j : J) → ((i : I) → u i ≡ j → P i) → Π' u P j abs'' j f (i , p) = f i p abs₃ : {I J : Set} {u : I → J} (j : J) {P : Fam (Σ I (λ i → u i ≡ j))} → ((i : I) → (p : u i ≡ j) → P (i , p)) → Π'' u j P abs₃ j f (i , p) = f i p -- | Functorial action of Π' Π'₁ : {I J : Set} {u : I → J} {P Q : Fam I} → (f : P ⇒ Q) → (Π' u P ⇒ Π' u Q) Π'₁ {u = u} f .(u i) g (i , refl) = f i (app i g) -- | Dependent polynomials record DPoly {I : Set} -- ^ Outer index {J : Set} -- ^ Inner index : Set₁ where constructor dpoly field -- J ←t- E -p→ A -s→ I A : Set -- ^ Labels s : A → I E : Set p : E → A t : E → J -- | Interpretation of polynomial as functor ⟦_⟧ : {I : Set} {J : Set} → DPoly {I} {J} → (X : Fam J) → -- ^ Parameter (Fam I) ⟦_⟧ {I} {N} (dpoly A s E p t) X = Σ' s (λ a → Π' p (λ e → X (t e) ) a ) -- | Functorial action of T ⟦_⟧₁ : {I : Set} {J : Set} → (P : DPoly {I} {J}) → {X Y : J → Set} → (f : (j : J) → X j → Y j) (i : I) → ⟦ P ⟧ X i → ⟦ P ⟧ Y i ⟦_⟧₁ {I} {J} (dpoly A s E p t) {X} {Y} f .(s a) (ins a v) = ins a (Π'₁ ((t *₁) f) a v) -- | Final coalgebras for dependent polynomials record M {a : Size} {I} (P : DPoly {I} {I}) (i : I) : Set where coinductive field ξ : ∀ {b : Size< a} → ⟦ P ⟧ (M {b} P) i open M ξ' : ∀ {I P} → {i : I} → M P i → ⟦ P ⟧ (M P) i ξ' x = ξ x Rel₂ : {I : Set} → (X Y : I → Set) → Set₁ Rel₂ {I} X Y = (i : I) → X i → Y i → Set -- | Lifting to relations ⟦_⟧'' : ∀ {I} (P : DPoly {I} {I}) {X Y} → Rel₂ X Y → Rel₂ (⟦ P ⟧ X) (⟦ P ⟧ Y) ⟦ dpoly A s E p t ⟧'' {X} {Y} R i x y = ∃ λ a → ∃ λ α → ∃ λ β → Σ[ q ∈ (i ≡ s a) ] (subst (⟦ dpoly A s E p t ⟧ X) q x ≡ ins a α × (subst (⟦ dpoly A s E p t ⟧ Y) q y) ≡ ins a β × ∀ u → R (t (proj₁ u)) (α u) (β u)) [_]_≡₂_ : ∀{I} {X : I → Set} → Rel₂ X X [ i ] x ≡₂ y = x ≡ y eq-preserving : ∀ {I P X} (i : I) (x y : ⟦ P ⟧ X i) → x ≡ y → ⟦ P ⟧'' (λ i → _≡_) i x y eq-preserving i x y x≡y = {!!} mutual -- | Equality for M types is given by bisimilarity record Bisim {I} {P : DPoly {I} {I}} (i : I) (x y : M P i) : Set where coinductive field ~pr : ⟦ P ⟧'' Bisim i (ξ' x) (ξ' y) open Bisim public
27.968037
77
0.437224
4e692057e67da953b174b08c146f63d2beb95885
351
agda
Agda
HyperFalse.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
HyperFalse.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
HyperFalse.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical #-} module HyperFalse where open import Prelude hiding (false) {-# NO_POSITIVITY_CHECK #-} record _↬_ (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where inductive; constructor hyp field invoke : (B ↬ A) → B open _↬_ yes? : ⊥ ↬ ⊥ yes? .invoke h = h .invoke h no! : (⊥ ↬ ⊥) → ⊥ no! h = h .invoke h boom : ⊥ boom = no! yes?
15.954545
58
0.581197
4e948ef27402dea805b28223d1925235cd550860
10,545
agda
Agda
agda-stdlib-0.9/src/Data/List/Any/Membership.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/List/Any/Membership.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/List/Any/Membership.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties related to list membership ------------------------------------------------------------------------ -- List membership is defined in Data.List.Any. This module does not -- treat the general variant of list membership, parametrised on a -- setoid, only the variant where the equality is fixed to be -- propositional equality. module Data.List.Any.Membership where open import Algebra open import Category.Monad open import Data.Bool open import Data.Empty open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence using (module Equivalence) import Function.Injection as Inj open import Function.Inverse as Inv using (_↔_; module Inverse) import Function.Related as Related open import Function.Related.TypeIsomorphisms open import Data.List as List open import Data.List.Any as Any using (Any; here; there) open import Data.List.Any.Properties open import Data.Nat as Nat import Data.Nat.Properties as NatProp open import Data.Product as Prod open import Data.Sum as Sum open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; _≗_) import Relation.Binary.Properties.DecTotalOrder as DTOProperties import Relation.Binary.Sigma.Pointwise as Σ open import Relation.Unary using (_⟨×⟩_) open import Relation.Nullary open import Relation.Nullary.Negation open Any.Membership-≡ private module ×⊎ {k ℓ} = CommutativeSemiring (×⊎-CommutativeSemiring k ℓ) open module ListMonad {ℓ} = RawMonad (List.monad {ℓ = ℓ}) ------------------------------------------------------------------------ -- Properties relating _∈_ to various list functions -- Isomorphisms. map-∈↔ : ∀ {a b} {A : Set a} {B : Set b} {f : A → B} {y xs} → (∃ λ x → x ∈ xs × y ≡ f x) ↔ y ∈ List.map f xs map-∈↔ {a} {b} {f = f} {y} {xs} = (∃ λ x → x ∈ xs × y ≡ f x) ↔⟨ Any↔ {a = a} {p = b} ⟩ Any (λ x → y ≡ f x) xs ↔⟨ map↔ {a = a} {b = b} {p = b} ⟩ y ∈ List.map f xs ∎ where open Related.EquationalReasoning concat-∈↔ : ∀ {a} {A : Set a} {x : A} {xss} → (∃ λ xs → x ∈ xs × xs ∈ xss) ↔ x ∈ concat xss concat-∈↔ {a} {x = x} {xss} = (∃ λ xs → x ∈ xs × xs ∈ xss) ↔⟨ Σ.cong {a₁ = a} {b₁ = a} {b₂ = a} Inv.id $ ×⊎.*-comm _ _ ⟩ (∃ λ xs → xs ∈ xss × x ∈ xs) ↔⟨ Any↔ {a = a} {p = a} ⟩ Any (Any (_≡_ x)) xss ↔⟨ concat↔ {a = a} {p = a} ⟩ x ∈ concat xss ∎ where open Related.EquationalReasoning >>=-∈↔ : ∀ {ℓ} {A B : Set ℓ} {xs} {f : A → List B} {y} → (∃ λ x → x ∈ xs × y ∈ f x) ↔ y ∈ (xs >>= f) >>=-∈↔ {ℓ} {xs = xs} {f} {y} = (∃ λ x → x ∈ xs × y ∈ f x) ↔⟨ Any↔ {a = ℓ} {p = ℓ} ⟩ Any (Any (_≡_ y) ∘ f) xs ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩ y ∈ (xs >>= f) ∎ where open Related.EquationalReasoning ⊛-∈↔ : ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) {xs y} → (∃₂ λ f x → f ∈ fs × x ∈ xs × y ≡ f x) ↔ y ∈ fs ⊛ xs ⊛-∈↔ {ℓ} fs {xs} {y} = (∃₂ λ f x → f ∈ fs × x ∈ xs × y ≡ f x) ↔⟨ Σ.cong {a₁ = ℓ} {b₁ = ℓ} {b₂ = ℓ} Inv.id (∃∃↔∃∃ {a = ℓ} {b = ℓ} {p = ℓ} _) ⟩ (∃ λ f → f ∈ fs × ∃ λ x → x ∈ xs × y ≡ f x) ↔⟨ Σ.cong {a₁ = ℓ} {b₁ = ℓ} {b₂ = ℓ} Inv.id ((_ ∎) ⟨ ×⊎.*-cong {ℓ = ℓ} ⟩ Any↔ {a = ℓ} {p = ℓ}) ⟩ (∃ λ f → f ∈ fs × Any (_≡_ y ∘ f) xs) ↔⟨ Any↔ {a = ℓ} {p = ℓ} ⟩ Any (λ f → Any (_≡_ y ∘ f) xs) fs ↔⟨ ⊛↔ ⟩ y ∈ fs ⊛ xs ∎ where open Related.EquationalReasoning ⊗-∈↔ : ∀ {A B : Set} {xs ys} {x : A} {y : B} → (x ∈ xs × y ∈ ys) ↔ (x , y) ∈ (xs ⊗ ys) ⊗-∈↔ {A} {B} {xs} {ys} {x} {y} = (x ∈ xs × y ∈ ys) ↔⟨ ⊗↔′ ⟩ Any (_≡_ x ⟨×⟩ _≡_ y) (xs ⊗ ys) ↔⟨ Any-cong helper (_ ∎) ⟩ (x , y) ∈ (xs ⊗ ys) ∎ where open Related.EquationalReasoning helper : (p : A × B) → (x ≡ proj₁ p × y ≡ proj₂ p) ↔ (x , y) ≡ p helper (x′ , y′) = record { to = P.→-to-⟶ (uncurry $ P.cong₂ _,_) ; from = P.→-to-⟶ < P.cong proj₁ , P.cong proj₂ > ; inverse-of = record { left-inverse-of = λ _ → P.cong₂ _,_ (P.proof-irrelevance _ _) (P.proof-irrelevance _ _) ; right-inverse-of = λ _ → P.proof-irrelevance _ _ } } -- Other properties. filter-∈ : ∀ {a} {A : Set a} (p : A → Bool) (xs : List A) {x} → x ∈ xs → p x ≡ true → x ∈ filter p xs filter-∈ p [] () _ filter-∈ p (x ∷ xs) (here refl) px≡true rewrite px≡true = here refl filter-∈ p (y ∷ xs) (there pxs) px≡true with p y ... | true = there (filter-∈ p xs pxs px≡true) ... | false = filter-∈ p xs pxs px≡true ------------------------------------------------------------------------ -- Properties relating _∈_ to various list functions -- Various functions are monotone. mono : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} → xs ⊆ ys → Any P xs → Any P ys mono xs⊆ys = _⟨$⟩_ (Inverse.to Any↔) ∘′ Prod.map id (Prod.map xs⊆ys id) ∘ _⟨$⟩_ (Inverse.from Any↔) map-mono : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {xs ys} → xs ⊆ ys → List.map f xs ⊆ List.map f ys map-mono f xs⊆ys = _⟨$⟩_ (Inverse.to map-∈↔) ∘ Prod.map id (Prod.map xs⊆ys id) ∘ _⟨$⟩_ (Inverse.from map-∈↔) _++-mono_ : ∀ {a} {A : Set a} {xs₁ xs₂ ys₁ ys₂ : List A} → xs₁ ⊆ ys₁ → xs₂ ⊆ ys₂ → xs₁ ++ xs₂ ⊆ ys₁ ++ ys₂ _++-mono_ xs₁⊆ys₁ xs₂⊆ys₂ = _⟨$⟩_ (Inverse.to ++↔) ∘ Sum.map xs₁⊆ys₁ xs₂⊆ys₂ ∘ _⟨$⟩_ (Inverse.from ++↔) concat-mono : ∀ {a} {A : Set a} {xss yss : List (List A)} → xss ⊆ yss → concat xss ⊆ concat yss concat-mono {a} xss⊆yss = _⟨$⟩_ (Inverse.to $ concat-∈↔ {a = a}) ∘ Prod.map id (Prod.map id xss⊆yss) ∘ _⟨$⟩_ (Inverse.from $ concat-∈↔ {a = a}) >>=-mono : ∀ {ℓ} {A B : Set ℓ} (f g : A → List B) {xs ys} → xs ⊆ ys → (∀ {x} → f x ⊆ g x) → (xs >>= f) ⊆ (ys >>= g) >>=-mono {ℓ} f g xs⊆ys f⊆g = _⟨$⟩_ (Inverse.to $ >>=-∈↔ {ℓ = ℓ}) ∘ Prod.map id (Prod.map xs⊆ys f⊆g) ∘ _⟨$⟩_ (Inverse.from $ >>=-∈↔ {ℓ = ℓ}) _⊛-mono_ : ∀ {ℓ} {A B : Set ℓ} {fs gs : List (A → B)} {xs ys : List A} → fs ⊆ gs → xs ⊆ ys → (fs ⊛ xs) ⊆ (gs ⊛ ys) _⊛-mono_ {fs = fs} {gs} fs⊆gs xs⊆ys = _⟨$⟩_ (Inverse.to $ ⊛-∈↔ gs) ∘ Prod.map id (Prod.map id (Prod.map fs⊆gs (Prod.map xs⊆ys id))) ∘ _⟨$⟩_ (Inverse.from $ ⊛-∈↔ fs) _⊗-mono_ : {A B : Set} {xs₁ ys₁ : List A} {xs₂ ys₂ : List B} → xs₁ ⊆ ys₁ → xs₂ ⊆ ys₂ → (xs₁ ⊗ xs₂) ⊆ (ys₁ ⊗ ys₂) xs₁⊆ys₁ ⊗-mono xs₂⊆ys₂ = _⟨$⟩_ (Inverse.to ⊗-∈↔) ∘ Prod.map xs₁⊆ys₁ xs₂⊆ys₂ ∘ _⟨$⟩_ (Inverse.from ⊗-∈↔) any-mono : ∀ {a} {A : Set a} (p : A → Bool) → ∀ {xs ys} → xs ⊆ ys → T (any p xs) → T (any p ys) any-mono {a} p xs⊆ys = _⟨$⟩_ (Equivalence.to $ any⇔ {a = a}) ∘ mono xs⊆ys ∘ _⟨$⟩_ (Equivalence.from $ any⇔ {a = a}) map-with-∈-mono : ∀ {a b} {A : Set a} {B : Set b} {xs : List A} {f : ∀ {x} → x ∈ xs → B} {ys : List A} {g : ∀ {x} → x ∈ ys → B} (xs⊆ys : xs ⊆ ys) → (∀ {x} → f {x} ≗ g ∘ xs⊆ys) → map-with-∈ xs f ⊆ map-with-∈ ys g map-with-∈-mono {f = f} {g = g} xs⊆ys f≈g {x} = _⟨$⟩_ (Inverse.to map-with-∈↔) ∘ Prod.map id (Prod.map xs⊆ys (λ {x∈xs} x≡fx∈xs → begin x ≡⟨ x≡fx∈xs ⟩ f x∈xs ≡⟨ f≈g x∈xs ⟩ g (xs⊆ys x∈xs) ∎)) ∘ _⟨$⟩_ (Inverse.from map-with-∈↔) where open P.≡-Reasoning -- Other properties. filter-⊆ : ∀ {a} {A : Set a} (p : A → Bool) → (xs : List A) → filter p xs ⊆ xs filter-⊆ _ [] = λ () filter-⊆ p (x ∷ xs) with p x | filter-⊆ p xs ... | false | hyp = there ∘ hyp ... | true | hyp = λ { (here eq) → here eq ; (there ∈filter) → there (hyp ∈filter) } ------------------------------------------------------------------------ -- Other properties -- Only a finite number of distinct elements can be members of a -- given list. finite : ∀ {a} {A : Set a} (f : Inj.Injection (P.setoid ℕ) (P.setoid A)) → ∀ xs → ¬ (∀ i → Inj.Injection.to f ⟨$⟩ i ∈ xs) finite inj [] ∈[] with ∈[] zero ... | () finite {A = A} inj (x ∷ xs) ∈x∷xs = excluded-middle helper where open Inj.Injection inj module DTO = DecTotalOrder Nat.decTotalOrder module STO = StrictTotalOrder (DTOProperties.strictTotalOrder Nat.decTotalOrder) module CS = CommutativeSemiring NatProp.commutativeSemiring not-x : ∀ {i} → ¬ (to ⟨$⟩ i ≡ x) → to ⟨$⟩ i ∈ xs not-x {i} ≢x with ∈x∷xs i ... | here ≡x = ⊥-elim (≢x ≡x) ... | there ∈xs = ∈xs helper : ¬ Dec (∃ λ i → to ⟨$⟩ i ≡ x) helper (no ≢x) = finite inj xs (λ i → not-x (≢x ∘ _,_ i)) helper (yes (i , ≡x)) = finite inj′ xs ∈xs where open P f : ℕ → A f j with STO.compare i j f j | tri< _ _ _ = to ⟨$⟩ suc j f j | tri≈ _ _ _ = to ⟨$⟩ suc j f j | tri> _ _ _ = to ⟨$⟩ j ∈-if-not-i : ∀ {j} → i ≢ j → to ⟨$⟩ j ∈ xs ∈-if-not-i i≢j = not-x (i≢j ∘ injective ∘ trans ≡x ∘ sym) lemma : ∀ {k j} → k ≤ j → suc j ≢ k lemma 1+j≤j refl = NatProp.1+n≰n 1+j≤j ∈xs : ∀ j → f j ∈ xs ∈xs j with STO.compare i j ∈xs j | tri< (i≤j , _) _ _ = ∈-if-not-i (lemma i≤j ∘ sym) ∈xs j | tri> _ i≢j _ = ∈-if-not-i i≢j ∈xs .i | tri≈ _ refl _ = ∈-if-not-i (NatProp.m≢1+m+n i ∘ subst (_≡_ i ∘ suc) (sym $ proj₂ CS.+-identity i)) injective′ : Inj.Injective {B = P.setoid A} (→-to-⟶ f) injective′ {j} {k} eq with STO.compare i j | STO.compare i k ... | tri< _ _ _ | tri< _ _ _ = cong pred $ injective eq ... | tri< _ _ _ | tri≈ _ _ _ = cong pred $ injective eq ... | tri< (i≤j , _) _ _ | tri> _ _ (k≤i , _) = ⊥-elim (lemma (DTO.trans k≤i i≤j) $ injective eq) ... | tri≈ _ _ _ | tri< _ _ _ = cong pred $ injective eq ... | tri≈ _ _ _ | tri≈ _ _ _ = cong pred $ injective eq ... | tri≈ _ i≡j _ | tri> _ _ (k≤i , _) = ⊥-elim (lemma (subst (_≤_ k) i≡j k≤i) $ injective eq) ... | tri> _ _ (j≤i , _) | tri< (i≤k , _) _ _ = ⊥-elim (lemma (DTO.trans j≤i i≤k) $ sym $ injective eq) ... | tri> _ _ (j≤i , _) | tri≈ _ i≡k _ = ⊥-elim (lemma (subst (_≤_ j) i≡k j≤i) $ sym $ injective eq) ... | tri> _ _ (j≤i , _) | tri> _ _ (k≤i , _) = injective eq inj′ = record { to = →-to-⟶ {B = P.setoid A} f ; injective = injective′ }
38.485401
126
0.467141
29e17f5ae4fe56e4186e23a0f37673465d99f18c
3,199
agda
Agda
proglangs-learning/Agda/plfa-exercises/weird.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
proglangs-learning/Agda/plfa-exercises/weird.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
4
2020-03-10T19:20:21.000Z
2021-06-07T15:39:48.000Z
proglangs-learning/Agda/plfa-exercises/weird.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
module plfa-exercises.weird where open import Data.Nat using (ℕ; zero; suc; _+_; _*_) open import Data.Bool.Base using (Bool; true; false; _∧_; _∨_; not) import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; sym; trans; cong; subst) data ℕ∨Bool : Set where N B : ℕ∨Bool -- Idea taken from paper: Fractional Types by Chao-Hong Chen et al. ⟦_⟧ : ℕ∨Bool → Set ⟦ N ⟧ = ℕ ⟦ B ⟧ = Bool manyinputs : {a : ℕ∨Bool} → ⟦ a ⟧ → ⟦ a ⟧ manyinputs {N} n = suc n manyinputs {B} b = not b _ : manyinputs 6 ≡ 7 _ = refl _ : manyinputs true ≡ false -- WOW!! _ = refl open import Relation.Nullary using (¬_) open import Data.Unit using (⊤; tt) open import Data.Empty using (⊥; ⊥-elim) -- Actually this should use "isomorphisms" not mere 'iff' between propositions. -- https://agda.github.io/agda-stdlib/v1.1/Function.Inverse.html#2229 open import plfa.part1.Isomorphism using (_⇔_) lemma₁ : ¬ ⊤ → ⊥ lemma₁ ¬⊤ = ¬⊤ tt lemma₂ : ⊥ → ¬ ⊤ lemma₂ () -- I can easily prove this!! Which is not the same as ¬ ⊤ same as ⊥, -- but ¬ ⊤ iff ⊥, where ⊤ and ⊥ are predicates prf₀ : (¬ ⊤) ⇔ ⊥ prf₀ = record { to = lemma₁ ; from = lemma₂ } -- But how to prove the following? --prf : ¬ ⊤ ≡ ⊥ --prf = ? -- seems to require extensionality and iso-is-≡, or cubical, see https://stackoverflow.com/a/58912530 open import Level using (0ℓ) open import Agda.Primitive using (lsuc) open import Relation.Binary.Definitions using (Substitutive; _Respects_; _⟶_Respects_) prf₂ : ¬ (⊤ ≡ ⊥) -- same as: ⊤ ≢ ⊥ prf₂ ⊤≡⊥ = subst (λ x → x) ⊤≡⊥ tt -- We don't need to give the implicit parameters but doing so lets us look -- inside of the definitions and how they get reduced to other terms --prf₂ ⊤≡⊥ = subst {A = Set} {ℓ = 0ℓ} (λ x → x) ⊤≡⊥ tt -- `subst` has type: {a : Level} {A : Set a} {ℓ : Level} → Substitutive _≡_ ℓ -- `subst {A = Set}` has type: {ℓ : Level} → Substitutive _≡_ ℓ -- `subst {A = Set} {ℓ = 0ℓ}` has type: Substitutive _≡_ 0ℓ -- actually it has type: Substitutive {A = Set} _≡_ 0ℓ -- `Substitutive {A = Set} _≡_ 0ℓ` which reduces to (P : Set → Set) {x y : Set} → x ≡ y → P x → P y -- which means that the type of -- `subst {A = Set} {ℓ = 0ℓ}` -- is -- (P : Set → Set) {x y : Set} → x ≡ y → P x → P y -- thus, the type of -- `subst {A = Set} {ℓ = 0ℓ} (λ x → x)` (*) -- is -- {x y : Set} → x ≡ y → P x → P y -- Note: careful, Agda tells us that the type of (*) is: -- (λ x → x) Respects _≡_ -- but it is actually: -- _Respects_ {A = Set} (λ x → x) _≡_ -- -- From reading the code: -- _Respects_ {A = Set} (λ x → x) _≡_ (**) -- reduces first to: -- _⟶_Respects_ {A = Set} (λ x → x) (λ x → x) _≡_ -- -- There is even more. (**) actually has some implicit parameters, here they are -- _Respects_ {A = Set} {ℓ₁ = 0ℓ} {ℓ₂ = lsuc 0ℓ} (λ x → x) _≡_ -- -- LESSON LEARNT: Implicit arguments are cool because you don't need to give -- them, Agda can generally infer them from context which makes code to look -- prettier but excesively harder to read -- -- Other stuff: -- `Substitutive {A = Set} _≡_ 0ℓ` reduces to (P : Set → Set) {x y : Set} → x ≡ y → P x → P y -- `Substitutive {A = Set} _≡_ (lsuc 0ℓ)` reduces to (P : Set → Set₁) {x y : Set} → x ≡ y → P x → P y
33.673684
112
0.60769
37e496d5e9e3f219fd062bb1799b8a860ec1daef
429
agda
Agda
test/Fail/Issue1216a.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1216a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1216a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2014-06-27 -- {-# OPTIONS -v tc.lhs:40 #-} {-# OPTIONS --copatterns #-} record Coind : Set where coinductive field ind : Coind open Coind loop : Set -> Coind ind A (loop B) = ind (loop A) -- WAS: Internal error. -- NOW: Proper error. -- Cannot eliminate type Coind with pattern ind A (did you supply too many arguments?) -- when checking that the clause ind A (loop B) = ind (loop A) has -- type Set → Coind
21.45
86
0.657343
36399405c4cdd6357f1f2955a8f9fc209df1e40a
8,102
agda
Agda
Cubical/Algebra/CommRing/Properties.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Properties.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Properties.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.CommRing.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Foundations.Powerset open import Cubical.Data.Sigma open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Macro open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing.Base private variable ℓ : Level module Units (R' : CommRing {ℓ}) where open CommRingStr (snd R') open Theory (CommRing→Ring R') private R = R' .fst inverseUniqueness : (r : R) → isProp (Σ[ r' ∈ R ] r · r' ≡ 1r) inverseUniqueness r (r' , rr'≡1) (r'' , rr''≡1) = Σ≡Prop (λ _ → is-set _ _) path where path : r' ≡ r'' path = r' ≡⟨ sym (·-rid _) ⟩ r' · 1r ≡⟨ cong (r' ·_) (sym rr''≡1) ⟩ r' · (r · r'') ≡⟨ ·-assoc _ _ _ ⟩ (r' · r) · r'' ≡⟨ cong (_· r'') (·-comm _ _) ⟩ (r · r') · r'' ≡⟨ cong (_· r'') rr'≡1 ⟩ 1r · r'' ≡⟨ ·-lid _ ⟩ r'' ∎ Rˣ : ℙ R Rˣ r = (Σ[ r' ∈ R ] r · r' ≡ 1r) , inverseUniqueness r -- some notation using instance arguments _⁻¹ : (r : R) → ⦃ r ∈ Rˣ ⦄ → R _⁻¹ r ⦃ r∈Rˣ ⦄ = r∈Rˣ .fst infix 9 _⁻¹ -- some results about inverses ·-rinv : (r : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r · r ⁻¹ ≡ 1r ·-rinv r ⦃ r∈Rˣ ⦄ = r∈Rˣ .snd ·-linv : (r : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r ⁻¹ · r ≡ 1r ·-linv r ⦃ r∈Rˣ ⦄ = ·-comm _ _ ∙ r∈Rˣ .snd RˣMultClosed : (r r' : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ → (r · r') ∈ Rˣ RˣMultClosed r r' = (r ⁻¹ · r' ⁻¹) , path where path : r · r' · (r ⁻¹ · r' ⁻¹) ≡ 1r path = r · r' · (r ⁻¹ · r' ⁻¹) ≡⟨ cong (_· (r ⁻¹ · r' ⁻¹)) (·-comm _ _) ⟩ r' · r · (r ⁻¹ · r' ⁻¹) ≡⟨ ·-assoc _ _ _ ⟩ r' · r · r ⁻¹ · r' ⁻¹ ≡⟨ cong (_· r' ⁻¹) (sym (·-assoc _ _ _)) ⟩ r' · (r · r ⁻¹) · r' ⁻¹ ≡⟨ cong (λ x → r' · x · r' ⁻¹) (·-rinv _) ⟩ r' · 1r · r' ⁻¹ ≡⟨ cong (_· r' ⁻¹) (·-rid _) ⟩ r' · r' ⁻¹ ≡⟨ ·-rinv _ ⟩ 1r ∎ RˣContainsOne : 1r ∈ Rˣ RˣContainsOne = 1r , ·-lid _ RˣInvClosed : (r : R) ⦃ _ : r ∈ Rˣ ⦄ → r ⁻¹ ∈ Rˣ RˣInvClosed r = r , ·-linv _ UnitsAreNotZeroDivisors : (r : R) ⦃ _ : r ∈ Rˣ ⦄ → ∀ r' → r' · r ≡ 0r → r' ≡ 0r UnitsAreNotZeroDivisors r r' p = r' ≡⟨ sym (·-rid _) ⟩ r' · 1r ≡⟨ cong (r' ·_) (sym (·-rinv _)) ⟩ r' · (r · r ⁻¹) ≡⟨ ·-assoc _ _ _ ⟩ r' · r · r ⁻¹ ≡⟨ cong (_· r ⁻¹) p ⟩ 0r · r ⁻¹ ≡⟨ 0-leftNullifies _ ⟩ 0r ∎ -- laws keeping the instance arguments 1⁻¹≡1 : ⦃ 1∈Rˣ' : 1r ∈ Rˣ ⦄ → 1r ⁻¹ ≡ 1r 1⁻¹≡1 ⦃ 1∈Rˣ' ⦄ = (sym (·-lid _)) ∙ 1∈Rˣ' .snd ⁻¹-dist-· : (r r' : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ ⦃ rr'∈Rˣ : (r · r') ∈ Rˣ ⦄ → (r · r') ⁻¹ ≡ r ⁻¹ · r' ⁻¹ ⁻¹-dist-· r r' ⦃ r∈Rˣ ⦄ ⦃ r'∈Rˣ ⦄ ⦃ rr'∈Rˣ ⦄ = sym path ∙∙ cong (r ⁻¹ · r' ⁻¹ ·_) (rr'∈Rˣ .snd) ∙∙ (·-rid _) where path : r ⁻¹ · r' ⁻¹ · (r · r' · (r · r') ⁻¹) ≡ (r · r') ⁻¹ path = r ⁻¹ · r' ⁻¹ · (r · r' · (r · r') ⁻¹) ≡⟨ ·-assoc _ _ _ ⟩ r ⁻¹ · r' ⁻¹ · (r · r') · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · r' ⁻¹ · x · (r · r') ⁻¹) (·-comm _ _) ⟩ r ⁻¹ · r' ⁻¹ · (r' · r) · (r · r') ⁻¹ ≡⟨ cong (_· (r · r') ⁻¹) (sym (·-assoc _ _ _)) ⟩ r ⁻¹ · (r' ⁻¹ · (r' · r)) · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · x · (r · r') ⁻¹) (·-assoc _ _ _) ⟩ r ⁻¹ · (r' ⁻¹ · r' · r) · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · (x · r) · (r · r') ⁻¹) (·-linv _) ⟩ r ⁻¹ · (1r · r) · (r · r') ⁻¹ ≡⟨ cong (λ x → r ⁻¹ · x · (r · r') ⁻¹) (·-lid _) ⟩ r ⁻¹ · r · (r · r') ⁻¹ ≡⟨ cong (_· (r · r') ⁻¹) (·-linv _) ⟩ 1r · (r · r') ⁻¹ ≡⟨ ·-lid _ ⟩ (r · r') ⁻¹ ∎ unitCong : {r r' : R} → r ≡ r' → ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ → r ⁻¹ ≡ r' ⁻¹ unitCong {r = r} {r' = r'} p ⦃ r∈Rˣ ⦄ ⦃ r'∈Rˣ ⦄ = PathPΣ (inverseUniqueness r' (r ⁻¹ , subst (λ x → x · r ⁻¹ ≡ 1r) p (r∈Rˣ .snd)) r'∈Rˣ) .fst -- some convenient notation _ˣ : (R' : CommRing {ℓ}) → ℙ (R' .fst) R' ˣ = Units.Rˣ R' module RingHomRespUnits {A' B' : CommRing {ℓ}} (φ : CommRingHom A' B') where open Units A' renaming (Rˣ to Aˣ ; _⁻¹ to _⁻¹ᵃ ; ·-rinv to ·A-rinv ; ·-linv to ·A-linv) private A = A' .fst open CommRingStr (A' .snd) renaming (_·_ to _·A_ ; 1r to 1a) open Units B' renaming (Rˣ to Bˣ ; _⁻¹ to _⁻¹ᵇ ; ·-rinv to ·B-rinv) open CommRingStr (B' .snd) renaming ( _·_ to _·B_ ; 1r to 1b ; ·-lid to ·B-lid ; ·-rid to ·B-rid ; ·-assoc to ·B-assoc) open RingHom RingHomRespInv : (r : A) ⦃ r∈Aˣ : r ∈ Aˣ ⦄ → f φ r ∈ Bˣ RingHomRespInv r = f φ (r ⁻¹ᵃ) , (sym (isHom· φ r (r ⁻¹ᵃ)) ∙∙ cong (f φ) (·A-rinv r) ∙∙ pres1 φ) φ[x⁻¹]≡φ[x]⁻¹ : (r : A) ⦃ r∈Aˣ : r ∈ Aˣ ⦄ ⦃ φr∈Bˣ : f φ r ∈ Bˣ ⦄ → f φ (r ⁻¹ᵃ) ≡ (f φ r) ⁻¹ᵇ φ[x⁻¹]≡φ[x]⁻¹ r ⦃ r∈Aˣ ⦄ ⦃ φr∈Bˣ ⦄ = f φ (r ⁻¹ᵃ) ≡⟨ sym (·B-rid _) ⟩ f φ (r ⁻¹ᵃ) ·B 1b ≡⟨ cong (f φ (r ⁻¹ᵃ) ·B_) (sym (·B-rinv _)) ⟩ f φ (r ⁻¹ᵃ) ·B ((f φ r) ·B (f φ r) ⁻¹ᵇ) ≡⟨ ·B-assoc _ _ _ ⟩ f φ (r ⁻¹ᵃ) ·B (f φ r) ·B (f φ r) ⁻¹ᵇ ≡⟨ cong (_·B (f φ r) ⁻¹ᵇ) (sym (isHom· φ _ _)) ⟩ f φ (r ⁻¹ᵃ ·A r) ·B (f φ r) ⁻¹ᵇ ≡⟨ cong (λ x → f φ x ·B (f φ r) ⁻¹ᵇ) (·A-linv _) ⟩ f φ 1a ·B (f φ r) ⁻¹ᵇ ≡⟨ cong (_·B (f φ r) ⁻¹ᵇ) (pres1 φ) ⟩ 1b ·B (f φ r) ⁻¹ᵇ ≡⟨ ·B-lid _ ⟩ (f φ r) ⁻¹ᵇ ∎ module Exponentiation (R' : CommRing {ℓ}) where open CommRingStr (snd R') private R = R' .fst -- introduce exponentiation _^_ : R → ℕ → R f ^ zero = 1r f ^ suc n = f · (f ^ n) infix 9 _^_ -- and prove some laws ·-of-^-is-^-of-+ : (f : R) (m n : ℕ) → (f ^ m) · (f ^ n) ≡ f ^ (m +ℕ n) ·-of-^-is-^-of-+ f zero n = ·-lid _ ·-of-^-is-^-of-+ f (suc m) n = sym (·-assoc _ _ _) ∙ cong (f ·_) (·-of-^-is-^-of-+ f m n) ^-ldist-· : (f g : R) (n : ℕ) → (f · g) ^ n ≡ (f ^ n) · (g ^ n) ^-ldist-· f g zero = sym (·-lid 1r) ^-ldist-· f g (suc n) = path where path : f · g · ((f · g) ^ n) ≡ f · (f ^ n) · (g · (g ^ n)) path = f · g · ((f · g) ^ n) ≡⟨ cong (f · g ·_) (^-ldist-· f g n) ⟩ f · g · ((f ^ n) · (g ^ n)) ≡⟨ ·-assoc _ _ _ ⟩ f · g · (f ^ n) · (g ^ n) ≡⟨ cong (_· (g ^ n)) (sym (·-assoc _ _ _)) ⟩ f · (g · (f ^ n)) · (g ^ n) ≡⟨ cong (λ r → (f · r) · (g ^ n)) (·-comm _ _) ⟩ f · ((f ^ n) · g) · (g ^ n) ≡⟨ cong (_· (g ^ n)) (·-assoc _ _ _) ⟩ f · (f ^ n) · g · (g ^ n) ≡⟨ sym (·-assoc _ _ _) ⟩ f · (f ^ n) · (g · (g ^ n)) ∎ -- like in Ring.Properties we provide helpful lemmas here module CommTheory (R' : CommRing {ℓ}) where open CommRingStr (snd R') private R = R' .fst ·-commAssocl : (x y z : R) → x · (y · z) ≡ y · (x · z) ·-commAssocl x y z = ·-assoc x y z ∙∙ cong (_· z) (·-comm x y) ∙∙ sym (·-assoc y x z) ·-commAssocr : (x y z : R) → x · y · z ≡ x · z · y ·-commAssocr x y z = sym (·-assoc x y z) ∙∙ cong (x ·_) (·-comm y z) ∙∙ ·-assoc x z y ·-commAssocr2 : (x y z : R) → x · y · z ≡ z · y · x ·-commAssocr2 x y z = ·-commAssocr _ _ _ ∙∙ cong (_· y) (·-comm _ _) ∙∙ ·-commAssocr _ _ _ ·-commAssocSwap : (x y z w : R) → (x · y) · (z · w) ≡ (x · z) · (y · w) ·-commAssocSwap x y z w = ·-assoc (x · y) z w ∙∙ cong (_· w) (·-commAssocr x y z) ∙∙ sym (·-assoc (x · z) y w)
39.521951
101
0.42866
cc5a686078ee84b0e9b177e99ae38157b8b9e3ad
1,198
agda
Agda
test/Fail/IndexInference.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/IndexInference.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/IndexInference.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Jesper, 2017-08-13: This test case now fails since instantiation -- of metavariables during case splitting was disabled (see #2621). {-# OPTIONS -v tc.conv.irr:50 #-} -- {-# OPTIONS -v tc.lhs.unify:50 #-} module IndexInference where data Nat : Set where zero : Nat suc : Nat -> Nat data Vec (A : Set) : Nat -> Set where [] : Vec A zero _::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n) infixr 40 _::_ -- The length of the vector can be inferred from the pattern. foo : Vec Nat _ -> Nat foo (a :: b :: c :: []) = c -- Andreas, 2012-09-13 an example with irrelevant components in index pred : Nat → Nat pred (zero ) = zero pred (suc n) = n data ⊥ : Set where record ⊤ : Set where NonZero : Nat → Set NonZero zero = ⊥ NonZero (suc n) = ⊤ data Fin (n : Nat) : Set where zero : .(NonZero n) → Fin n suc : .(NonZero n) → Fin (pred n) → Fin n data SubVec (A : Set)(n : Nat) : Fin n → Set where [] : .{p : NonZero n} → SubVec A n (zero p) _::_ : .{p : NonZero n}{k : Fin (pred n)} → A → SubVec A (pred n) k → SubVec A n (suc p k) -- The length of the vector can be inferred from the pattern. bar : {A : Set} → SubVec A (suc (suc (suc zero))) _ → A bar (a :: []) = a
26.043478
92
0.593489
cc3f8836dfd9ca9db4cbfcbf5ec42c96897a2ee7
398
agda
Agda
agda/Data/Sum/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Data/Sum/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Data/Sum/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe --postfix-projections #-} module Data.Sum.Properties where open import Prelude open import Data.Sum open import Data.Bool sumAsSigma : A ⊎ B ≃ Σ[ x ⦂ Bool ] (if x then A else B) sumAsSigma = isoToEquiv $ iso (either (true ,_) (false ,_)) (uncurry (bool inr inl)) (λ { (false , _) → refl ; (true , _) → refl}) (λ { (inl _) → refl ; (inr _) → refl})
24.875
55
0.605528
d106c9461b698f8012c7212b354d18612b3d7150
359
agda
Agda
test/Fail/Issue4482.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue4482.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue4482.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2020-03-20, issue #4482, reported by gallai -- Precise range for unexpected implicit argument. _ : Set → {A : Set} → {B : Set} → {C : Set} → Set _ = λ { _ {B = B} {A = A} → {!!} } -- Unexpected implicit argument -- when checking the clause left hand side -- .extendedlambda0 _ {B = B} {A = A} -- ^ highlight this
32.636364
55
0.554318
114ef7506122692682fd743b314f1ba51fca84bc
4,086
agda
Agda
src/PiCalculus/LinearTypeSystem/Algebras.agda
guilhermehas/typing-linear-pi
0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a
[ "MIT" ]
26
2020-05-02T23:32:11.000Z
2022-03-14T15:18:23.000Z
src/PiCalculus/LinearTypeSystem/Algebras.agda
guilhermehas/typing-linear-pi
0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a
[ "MIT" ]
1
2022-03-15T09:16:14.000Z
2022-03-15T09:16:14.000Z
src/PiCalculus/LinearTypeSystem/Algebras.agda
guilhermehas/typing-linear-pi
0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a
[ "MIT" ]
3
2021-01-25T13:57:13.000Z
2022-03-14T16:24:07.000Z
{-# OPTIONS --safe --without-K #-} open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; sym) open import Relation.Nullary using (Dec; yes; no) open import Relation.Nullary.Decidable using (fromWitness; toWitness) open import Function using (_∘_) open import Data.Empty using (⊥-elim) import Data.Fin as Fin import Data.Unit as Unit import Data.Product as Product import Data.Vec as Vec import Data.Vec.Relation.Unary.All as All import Data.Nat as ℕ open Fin using (Fin; zero; suc) open Unit using (⊤; tt) open ℕ using (ℕ) open Product using (Σ-syntax; ∃-syntax; _,_; _×_; proj₁; proj₂) open Vec using (Vec; []; _∷_) open All using (All; []; _∷_) module PiCalculus.LinearTypeSystem.Algebras where private variable n : ℕ infixr 100 _² _² : ∀ {a} → Set a → Set a A ² = A × A record Algebra (Q : Set) : Set₁ where field 0∙ 1∙ : Q _≔_∙_ : Q → Q → Q → Set -- Given two operands, we can decide whether a third one exists ∙-computeʳ : ∀ x y → Dec (∃[ z ] (x ≔ y ∙ z)) -- If a third operand exists, it must be unique ∙-unique : ∀ {x x' y z} → x' ≔ y ∙ z → x ≔ y ∙ z → x' ≡ x ∙-uniqueˡ : ∀ {x y y' z} → x ≔ y' ∙ z → x ≔ y ∙ z → y' ≡ y -- 0 is the minimum 0∙-minˡ : ∀ {y z} → 0∙ ≔ y ∙ z → y ≡ 0∙ -- Neutral element, commutativity, associativity ∙-idˡ : ∀ {x} → x ≔ 0∙ ∙ x ∙-comm : ∀ {x y z} → x ≔ y ∙ z → x ≔ z ∙ y -- no need for right rules ∙-assoc : ∀ {x y z u v} → x ≔ y ∙ z → y ≔ u ∙ v → ∃[ w ] (x ≔ u ∙ w × w ≔ v ∙ z) ℓ∅ : Q ² ℓ∅ = 0∙ , 0∙ ℓᵢ : Q ² ℓᵢ = 1∙ , 0∙ ℓₒ : Q ² ℓₒ = 0∙ , 1∙ ℓ# : Q ² ℓ# = 1∙ , 1∙ _≔_∙²_ : Q ² → Q ² → Q ² → Set (lx , rx) ≔ (ly , ry) ∙² (lz , rz) = (lx ≔ ly ∙ lz) × (rx ≔ ry ∙ rz) ∙-idʳ : ∀ {x} → x ≔ x ∙ 0∙ ∙-idʳ = ∙-comm ∙-idˡ ∙-assoc⁻¹ : ∀ {x y z u v} → x ≔ y ∙ z → z ≔ u ∙ v → ∃[ ; ] (x ≔ ; ∙ v × ; ≔ y ∙ u) ∙-assoc⁻¹ a b = let _ , a' , b' = ∙-assoc (∙-comm a) (∙-comm b) in _ , ∙-comm a' , ∙-comm b' ∙-mut-cancel : ∀ {x y y' z} → x ≔ y ∙ z → z ≔ y' ∙ x → x ≡ z ∙-mut-cancel x≔y∙z z≔y'∙x with ∙-assoc⁻¹ x≔y∙z z≔y'∙x ∙-mut-cancel x≔y∙z z≔y'∙x | e , x≔e∙x , e≔y∙y' rewrite ∙-uniqueˡ x≔e∙x ∙-idˡ | 0∙-minˡ e≔y∙y' = ∙-unique x≔y∙z ∙-idˡ ∙²-computeʳ : ∀ x y → Dec (∃[ z ] (x ≔ y ∙² z)) ∙²-computeʳ (lx , rx) (ly , ry) with ∙-computeʳ lx ly | ∙-computeʳ rx ry ∙²-computeʳ (lx , rx) (ly , ry) | yes (_ , p) | yes (_ , q) = yes (_ , p , q) ∙²-computeʳ (lx , rx) (ly , ry) | yes p | no ¬q = no λ {(_ , _ , r) → ¬q (_ , r)} ∙²-computeʳ (lx , rx) (ly , ry) | no ¬p | _ = no λ {(_ , l , _) → ¬p (_ , l)} ∙²-unique : ∀ {x x' y z} → x' ≔ y ∙² z → x ≔ y ∙² z → x' ≡ x ∙²-unique {x = _ , _} {x' = _ , _} (ll , rl) (lr , rr) rewrite ∙-unique ll lr | ∙-unique rl rr = refl ∙²-uniqueˡ : ∀ {x y y' z} → x ≔ y' ∙² z → x ≔ y ∙² z → y' ≡ y ∙²-uniqueˡ {y = _ , _} {y' = _ , _} (ll , lr) (rl , rr) rewrite ∙-uniqueˡ ll rl | ∙-uniqueˡ lr rr = refl ∙²-idˡ : ∀ {x} → x ≔ (0∙ , 0∙) ∙² x ∙²-idˡ = ∙-idˡ , ∙-idˡ ∙²-comm : ∀ {x y z} → x ≔ y ∙² z → x ≔ z ∙² y ∙²-comm (lx , rx) = ∙-comm lx , ∙-comm rx ∙²-idʳ : ∀ {x} → x ≔ x ∙² (0∙ , 0∙) ∙²-idʳ = ∙²-comm ∙²-idˡ ∙²-assoc : ∀ {x y z u v} → x ≔ y ∙² z → y ≔ u ∙² v → ∃[ w ] (x ≔ u ∙² w × w ≔ v ∙² z) ∙²-assoc (lx , rx) (ly , ry) with ∙-assoc lx ly | ∙-assoc rx ry ∙²-assoc (lx , rx) (ly , ry) | _ , ll , rl | _ , lr , rr = _ , ((ll , lr) , (rl , rr)) ∙²-assoc⁻¹ : ∀ {x y z u v} → x ≔ y ∙² z → z ≔ u ∙² v → ∃[ ; ] (x ≔ ; ∙² v × ; ≔ y ∙² u) ∙²-assoc⁻¹ a b = let _ , a' , b' = ∙²-assoc (∙²-comm a) (∙²-comm b) in _ , ∙²-comm a' , ∙²-comm b' ∙²-mut-cancel : ∀ {x y y' z} → x ≔ y ∙² z → z ≔ y' ∙² x → x ≡ z ∙²-mut-cancel {_ , _} (lx , rx) (ly , ry) rewrite ∙-mut-cancel lx ly | ∙-mut-cancel rx ry = refl record Algebras : Set₁ where field Idx : Set ∃Idx : Idx Usage : Idx → Set UsageAlgebra : ∀ idx → Algebra (Usage idx) infixl 40 _-,_ pattern _-,_ xs x = _∷_ x xs module _ {idx : Idx} where open Algebra (UsageAlgebra idx) public
32.428571
118
0.476016
1b67f79d584854eb6ec06aee32d6220b67abf47c
386
agda
Agda
test/Succeed/Issue1550.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1550.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1550.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-08-27 Allow rewrite rules for symbols defined in other file {-# OPTIONS --rewriting --local-confluence-check #-} open import Common.Nat open import Common.Equality {-# BUILTIN REWRITE _≡_ #-} x+0 : ∀ x → x + 0 ≡ x x+0 zero = refl x+0 (suc x) rewrite x+0 x = refl {-# REWRITE x+0 #-} -- adding rewrite rule for + is ok x+0+0 : ∀{x} → (x + 0) + 0 ≡ x x+0+0 = refl
21.444444
76
0.619171
3fdd37d56fa097e5721bf61ad466514b9b1b239f
803
agda
Agda
prototyping/Examples/Type.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
1
2022-03-18T04:10:20.000Z
2022-03-18T04:10:20.000Z
prototyping/Examples/Type.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
prototyping/Examples/Type.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
module Examples.Type where open import Agda.Builtin.Equality using (_≡_; refl) open import FFI.Data.String using (_++_) open import Luau.Type using (nil; _∪_; _∩_; _⇒_) open import Luau.Type.ToString using (typeToString) ex1 : typeToString(nil) ≡ "nil" ex1 = refl ex2 : typeToString(nil ⇒ nil) ≡ "(nil) -> nil" ex2 = refl ex3 : typeToString(nil ⇒ (nil ⇒ nil)) ≡ "(nil) -> (nil) -> nil" ex3 = refl ex4 : typeToString(nil ∪ (nil ⇒ (nil ⇒ nil))) ≡ "((nil) -> (nil) -> nil)?" ex4 = refl ex5 : typeToString(nil ⇒ ((nil ⇒ nil) ∪ nil)) ≡ "(nil) -> ((nil) -> nil)?" ex5 = refl ex6 : typeToString((nil ⇒ nil) ∪ (nil ⇒ (nil ⇒ nil))) ≡ "((nil) -> nil | (nil) -> (nil) -> nil)" ex6 = refl ex7 : typeToString((nil ⇒ nil) ∪ ((nil ⇒ (nil ⇒ nil)) ∪ nil)) ≡ "((nil) -> nil | (nil) -> (nil) -> nil)?" ex7 = refl
27.689655
105
0.576588
141081047b2e566d741bb4c96cda4c9d6ff0760c
504
agda
Agda
agda/examples-that-run/xxx/src-agda/xxx.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
36
2015-01-29T14:37:15.000Z
2021-07-30T06:55:03.000Z
agda/examples-that-run/xxx/src-agda/xxx.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
null
null
null
agda/examples-that-run/xxx/src-agda/xxx.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
8
2015-04-13T21:40:15.000Z
2021-09-21T15:58:10.000Z
module xxx where open import Agda.Builtin.Unit using (⊤) open import IO as IO hiding (_>>=_; _>>_) import IO.Primitive as Primitive open import hcio as HCIO main : Primitive.IO ⊤ main = run do IO.putStrLn "enter file name:" f ← HCIO.getLine IO.putStrLn "enter file contents" c ← HCIO.getLine IO.writeFile f c c' ← IO.readFiniteFile f IO.putStrLn c' std ← IO.readFiniteFile "spacetrack-data-2021-05-31.txt" IO.putStrLn std IO.putStrLn "Bye"
21
58
0.650794
14c4b02a1d159e73fad1d18d11421a61eb02f604
875
agda
Agda
test/Succeed/Issue175b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/Issue175b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/Issue175b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
module Issue175b where data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x data Bool : Set where true : Bool false : Bool {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-} postulate ℝ : Set {-# BUILTIN FLOAT ℝ #-} primitive -- ℝ functions primFloatMinus : ℝ -> ℝ -> ℝ primFloatNumericalLess : ℝ -> ℝ -> Bool _<_ : ℝ -> ℝ -> Bool a < b = primFloatNumericalLess a b data _≤_ : ℝ -> ℝ -> Set where ≤_ : {x y : ℝ} -> (x < y) ≡ true -> x ≤ y --absolute value [|_|] : ℝ -> ℝ [| a |] with (a < 0.0) [| a |] | true = primFloatMinus 0.0 a [| a |] | false = a --error variable ε : ℝ ε = 1.0e-5 -- two floating point numbers can be said to be equal if their -- difference is less than the given error variable postulate reflℝ : {a b : ℝ} -> [| primFloatMinus a b |] ≤ ε -> a ≡ b test : 1.0 ≡ 1.0000001 test = reflℝ (≤ refl)
19.444444
62
0.576
d1b49b7dde0c2e2908c1430c819d52bc0fca3e27
2,094
agda
Agda
Obsolete/Wow-FV-zh/Wow-It-is-FV.agda
ice1000/Books
a875d10f9a25d28e8e4f77e6ca32625a1e389227
[ "MIT" ]
133
2018-10-08T16:02:07.000Z
2022-01-05T10:37:03.000Z
Wow-FV-zh/Wow-It-is-FV.agda
ice1000/Books
a875d10f9a25d28e8e4f77e6ca32625a1e389227
[ "MIT" ]
3
2018-10-09T22:48:45.000Z
2018-10-16T19:29:15.000Z
Wow-FV-zh/Wow-It-is-FV.agda
ice1000/Books
a875d10f9a25d28e8e4f77e6ca32625a1e389227
[ "MIT" ]
7
2018-10-09T03:41:20.000Z
2021-09-24T16:49:13.000Z
{-# OPTIONS --without-K #-} module Wow-It-is-FV where open import Agda.Builtin.Nat open import Agda.Builtin.Equality open import Agda.Primitive levelEq : lzero ≡ lzero levelEq = refl levelEq′ : lsuc lzero ≡ lsuc lzero levelEq′ = refl trans : {l : Level} {Q : Set l} {a b c : Q} → a ≡ b → b ≡ c → a ≡ c trans refl refl = refl J : {A : Set} (P : (x y : A) → x ≡ y → Set) → ((x : A) → P x x refl) → (x y : A) (xy : x ≡ y) → P x y xy J P p x .x refl = p x cong : {A B : Set} (f : A → B) → {m n : A} → m ≡ n → f m ≡ f n cong f refl = refl sym : {A : Set} {m n : A} → m ≡ n → n ≡ m sym refl = refl theorem : suc zero + suc zero ≡ _ theorem = refl theorem′ : 1 + 1 ≡ 2 theorem′ = refl trivialEq : {a : _} {A : Set a} → A ≡ A trivialEq = refl trivialEq′ : ∀ {a} {A : Set a} → A ≡ A trivialEq′ = refl trivialEq′′ : ∀ a b → a + b ≡ a + b trivialEq′′ a b = refl trans′ : ∀ {a} {A : Set a} (a b c : A) → a ≡ b → b ≡ c → a ≡ c trans′ a .a c refl bc = bc data _<=_ : (a b : Nat) → Set where 0ltn : ∀ {n} → 0 <= n nltm : ∀ {n m} → n <= m → suc n <= suc m 7lt13 : 7 <= 13 7lt13 = nltm (nltm (nltm (nltm (nltm (nltm (nltm 0ltn)))))) abc : ∀ {a b c} → a <= b → b <= c → a <= c abc 0ltn bc = 0ltn abc (nltm ab) (nltm bc) = nltm (abc ab bc) data ⊥ : Set where ridiculous : ⊥ → ⊥ ridiculous a = a ridiculous′ : 1 ≡ 0 → ⊥ ridiculous′ () ⊥-elim : ∀ {a} {A : Set a} → ⊥ → A ⊥-elim () 4lt3 : 4 <= 3 → ⊥ 4lt3 (nltm (nltm (nltm ()))) infix 3 ¬_ ¬_ : ∀ {a} → Set a → Set a ¬ P = P → ⊥ _!=_ : ∀ {a} {A : Set a} → A → A → Set a x != y = ¬ x ≡ y _≡⟨_⟩_ : ∀ {A : Set} (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z _ ≡⟨ refl ⟩ c = c _QED : ∀ {A : Set} (x : A) → x ≡ x _ QED = refl lemma₀ : ∀ n → n + 0 ≡ n lemma₀ zero = refl lemma₀ (suc n) = cong suc (lemma₀ n) lemma₁ : ∀ n m → suc (n + m) ≡ n + suc m lemma₁ zero _ = refl lemma₁ (suc n) m = cong suc (lemma₁ n m) comm : ∀ n m → n + m ≡ m + n comm zero n = sym (lemma₀ n) comm (suc n) m = suc n + m ≡⟨ refl ⟩ suc (n + m) ≡⟨ cong suc (comm n m) ⟩ suc (m + n) ≡⟨ lemma₁ m n ⟩ m + suc n QED infixr 2 _≡⟨_⟩_ infix 3 _QED
20.134615
62
0.492359
34126154aff085ee8d6fc4a66e5164b58dfa22ac
3,798
agda
Agda
homotopy/SuspSmash.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/SuspSmash.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/SuspSmash.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT open import lib.cubical.elims.CofWedge open import lib.cubical.elims.SuspSmash {- Σ(X∧Y) ≃ X * Y -} module homotopy.SuspSmash {i j} (X : Ptd i) (Y : Ptd j) where private {- path lemmas -} private reduce-x : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : z == y) → p ∙ ! q ∙ q ∙ ! p ∙ p == p reduce-x idp idp = idp reduce-y : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : x == z) → p ∙ ! p ∙ q ∙ ! q ∙ p == p reduce-y idp idp = idp module Into = SuspensionRec (Smash X Y) {C = fst (X ⊙* Y)} (left (snd X)) (right (snd Y)) (cof-wedge-path-rec (glue (snd X , snd Y)) (λ {(x , y) → glue (snd X , snd Y) ∙ ! (glue (x , snd Y)) ∙ glue (x , y) ∙ ! (glue (snd X , y)) ∙ glue (snd X , snd Y)}) (λ x → ! (reduce-x (glue (snd X , snd Y)) (glue (x , snd Y)))) (λ y → ! (reduce-y (glue (snd X , snd Y)) (glue (snd X , y))))) into = Into.f module Out = PushoutRec {d = ⊙span-out (*-⊙span X Y)} {D = Suspension (Smash X Y)} (λ _ → north _) (λ _ → south _) (λ {(x , y) → merid _ (cfcod _ (x , y))}) out = Out.f into-out : (j : fst (X ⊙* Y)) → into (out j) == j into-out = Pushout-elim (λ x → glue (snd X , snd Y) ∙ ! (glue (x , snd Y))) (λ y → ! (glue (snd X , snd Y)) ∙ glue (snd X , y)) (↓-∘=idf-from-square into out ∘ λ {(x , y) → (ap (ap into) (Out.glue-β (x , y)) ∙ Into.glue-β (cfcod _ (x , y))) ∙v⊡ lemma (glue (snd X , snd Y)) (glue (x , snd Y)) (glue (snd X , y)) (glue (x , y))}) where lemma : ∀ {i} {A : Type i} {x y z w : A} (p : x == y) (q : z == y) (r : x == w) (s : z == w) → Square (p ∙ ! q) (p ∙ ! q ∙ s ∙ ! r ∙ p) s (! p ∙ r) lemma idp idp idp s = vert-degen-square (∙-unit-r s) out-into : (σ : Suspension (Smash X Y)) → out (into σ) == σ out-into = susp-smash-path-elim (out ∘ into) (idf _) idp idp (λ {(x , y) → vert-degen-square $ ap-∘ out into (merid _ (cfcod _ (x , y))) ∙ ap (ap out) (Into.glue-β (cfcod _ (x , y))) ∙ lemma₁ out (Out.glue-β (snd X , snd Y)) (Out.glue-β (x , snd Y)) (Out.glue-β (x , y)) (Out.glue-β (snd X , y)) (Out.glue-β (snd X , snd Y)) ∙ lemma₂ {p = merid _ (cfcod _ (snd X , snd Y))} {q = merid _ (cfcod _ (x , snd Y))} {r = merid _ (cfcod _ (x , y))} {s = merid _ (cfcod _ (snd X , y))} {t = merid _ (cfcod _ (snd X , snd Y))} (ap (merid _) (! (cfglue _ (winl (snd X))) ∙ cfglue _ (winl x))) (ap (merid _) (! (cfglue _ (winr y)) ∙ cfglue _ (winr (snd Y)))) ∙ ! (ap-idf (merid _ (cfcod _ (x , y))))}) where lemma₁ : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y z u v w : A} {p : x == y} {q : z == y} {r : z == u} {s : v == u} {t : v == w} {p' : f x == f y} {q' : f z == f y} {r' : f z == f u} {s' : f v == f u} {t' : f v == f w} (α : ap f p == p') (β : ap f q == q') (γ : ap f r == r') (δ : ap f s == s') (ε : ap f t == t') → ap f (p ∙ ! q ∙ r ∙ ! s ∙ t) == p' ∙ ! q' ∙ r' ∙ ! s' ∙ t' lemma₁ f {p = idp} {q = idp} {r = idp} {s = idp} {t = idp} idp idp idp idp idp = idp lemma₂ : ∀ {i} {A : Type i} {x y z u : A} {p q : x == y} {r : x == z} {s t : u == z} (α : p == q) (β : s == t) → p ∙ ! q ∙ r ∙ ! s ∙ t == r lemma₂ {p = idp} {r = idp} {s = idp} idp idp = idp module SuspSmash where eq : Suspension (Smash X Y) ≃ fst (X ⊙* Y) eq = equiv into out into-out out-into path : Suspension (Smash X Y) == fst (X ⊙* Y) path = ua eq ⊙path : ⊙Susp (⊙Smash X Y) == X ⊙* Y ⊙path = ⊙ua eq idp
33.910714
74
0.418641
cc65a4438b8f93ef3392d01f5d356ff5ff42d22c
1,501
agda
Agda
legacy/LinkedList.agda
banacorn/numeral
aae093cc9bf21f11064e7f7b12049448cd6449f1
[ "MIT" ]
1
2015-04-23T15:58:28.000Z
2015-04-23T15:58:28.000Z
legacy/LinkedList.agda
banacorn/numeral
aae093cc9bf21f11064e7f7b12049448cd6449f1
[ "MIT" ]
null
null
null
legacy/LinkedList.agda
banacorn/numeral
aae093cc9bf21f11064e7f7b12049448cd6449f1
[ "MIT" ]
1
2015-05-30T05:50:50.000Z
2015-05-30T05:50:50.000Z
module LinkedList where open import Data.Unit using (⊤; tt) open import Data.Empty using (⊥) open import Data.Nat import Data.Fin as Fin open import Data.Fin using (Fin) renaming (zero to Fzero; suc to Fsuc) open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; cong) open import Relation.Nullary using (¬_) open import Relation.Nullary using (Dec; yes; no; ¬_) open import Relation.Nullary.Decidable using (False) data LinkedList (A : Set) : Set where [] : LinkedList A _∷_ : A → LinkedList A → LinkedList A -------------------------------------------------------------------------------- -- to ℕ ⟦_⟧ : ∀ {A} → LinkedList A → ℕ ⟦ [] ⟧ = zero ⟦ x ∷ xs ⟧ = suc ⟦ xs ⟧ -------------------------------------------------------------------------------- -- predicates null : ∀ {A} → LinkedList A → Set null [] = ⊤ null (_ ∷ _) = ⊥ null? : ∀ {A} → (xs : LinkedList A) → Dec (null xs) null? [] = yes tt null? (x ∷ xs) = no (λ z → z) -------------------------------------------------------------------------------- -- operations incr : ∀ {A} → A → LinkedList A → LinkedList A incr = _∷_ decr : ∀ {A} → (xs : LinkedList A) → False (null? xs) → LinkedList A decr [] () decr (x ∷ xs) p = xs _++_ : ∀ {A} → LinkedList A → LinkedList A → LinkedList A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) elemAt : ∀ {A} → (xs : LinkedList A) → Fin ⟦ xs ⟧ → A elemAt [] () elemAt (x ∷ xs) Fzero = x elemAt (x ∷ xs) (Fsuc i) = elemAt xs i
26.333333
80
0.49034
14cf5d1e6e264b23875099253cc44e915cabfef1
3,002
agda
Agda
theorems/cohomology/LongExactSequence.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/cohomology/LongExactSequence.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/cohomology/LongExactSequence.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import cohomology.Theory open import groups.ExactSequence open import groups.HomSequence open import homotopy.CofiberSequence module cohomology.LongExactSequence {i} (CT : CohomologyTheory i) {X Y : Ptd i} (n : ℤ) (f : X ⊙→ Y) where open CohomologyTheory CT open import cohomology.PtdMapSequence CT co∂ : C n X →ᴳ C (succ n) (⊙Cofiber f) co∂ = record {f = CEl-fmap (succ n) ⊙extract-glue ∘ GroupIso.g (C-Susp n X); pres-comp = lemma} where abstract lemma = ∘ᴳ-pres-comp (C-fmap (succ n) ⊙extract-glue) (GroupIso.g-hom (C-Susp n X)) ⊙∂-before-Susp : ⊙Cofiber f ⊙→ ⊙Susp (de⊙ X) ⊙∂-before-Susp = ⊙extract-glue ∂-before-Susp : Cofiber (fst f) → Susp (de⊙ X) ∂-before-Susp = extract-glue abstract ∂-before-Susp-glue-β : ∀ x → ap ∂-before-Susp (cfglue x) == merid x ∂-before-Susp-glue-β = ExtractGlue.glue-β C-cofiber-seq : HomSequence (C n Y) (C (succ n) X) C-cofiber-seq = C n Y →⟨ C-fmap n f ⟩ᴳ C n X →⟨ co∂ ⟩ᴳ C (succ n) (⊙Cofiber f) →⟨ C-fmap (succ n) (⊙cfcod' f) ⟩ᴳ C (succ n) Y →⟨ C-fmap (succ n) f ⟩ᴳ C (succ n) X ⊣|ᴳ private C-iterated-cofiber-seq = C-seq (succ n) (iterated-cofiber-seq f) C-iterated-cofiber-seq-is-exact : is-exact-seq C-iterated-cofiber-seq C-iterated-cofiber-seq-is-exact = C-exact (succ n) (⊙cfcod²' f) , C-exact (succ n) (⊙cfcod' f) , C-exact (succ n) f , lift tt -- An intermediate sequence for proving exactness of [C-cofiber-seq]. C-cofiber-seq' = C-seq (succ n) (cyclic-cofiber-seq f) C-cofiber-seq'-is-exact : is-exact-seq C-cofiber-seq' C-cofiber-seq'-is-exact = seq-equiv-preserves'-exact (C-seq-emap (succ n) (iterated-equiv-cyclic f)) C-iterated-cofiber-seq-is-exact -- Now the final sequence C-cofiber-seq'-to-C-cofiber-seq : HomSeqMap C-cofiber-seq' C-cofiber-seq (GroupIso.f-hom (C-Susp n Y)) (idhom _) C-cofiber-seq'-to-C-cofiber-seq = GroupIso.f-hom (C-Susp n Y) ↓⟨ C-Susp-fmap n f ⟩ᴳ GroupIso.f-hom (C-Susp n X) ↓⟨ comm-sqrᴳ (λ x → ap (CEl-fmap (succ n) ⊙extract-glue) (! $ GroupIso.g-f (C-Susp n X) x)) ⟩ᴳ idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ idhom _ ↓|ᴳ C-cofiber-seq'-equiv-C-cofiber-seq : HomSeqEquiv C-cofiber-seq' C-cofiber-seq (GroupIso.f-hom (C-Susp n Y)) (idhom _) C-cofiber-seq'-equiv-C-cofiber-seq = C-cofiber-seq'-to-C-cofiber-seq , (GroupIso.f-is-equiv (C-Susp n Y) , GroupIso.f-is-equiv (C-Susp n X) , idf-is-equiv _ , idf-is-equiv _ , idf-is-equiv _) abstract C-cofiber-seq-is-exact : is-exact-seq C-cofiber-seq C-cofiber-seq-is-exact = seq-equiv-preserves-exact C-cofiber-seq'-equiv-C-cofiber-seq C-cofiber-seq'-is-exact C-cofiber-exact-seq : ExactSequence (C n Y) (C (succ n) X) C-cofiber-exact-seq = C-cofiber-seq , C-cofiber-seq-is-exact
38
126
0.613924
193575727fdad34b4b2885adb10305a1a8334162
1,313
agda
Agda
Experiment/ListConstruction.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
3
2020-04-07T17:49:42.000Z
2020-04-21T00:03:43.000Z
Experiment/ListConstruction.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
null
null
null
Experiment/ListConstruction.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Experiment.ListConstruction where open import Level renaming (zero to lzero; suc to lsuc) data ⊥ : Set where record ⊤ : Set where constructor tt data ℕ : Set where zero : ℕ suc : ℕ → ℕ module Inductive where data List (A : Set) : Set where [] : List A _∷_ : A → List A → List A data Bool : Set where true false : Bool record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where constructor _,_ field fst : A snd : B fst ∃ : ∀ {a b} {A : Set a} (B : A → Set b) → Set (a ⊔ b) ∃ {a} {b} {A} B = Σ A B if : ∀ {p} {P : Bool → Set p} → ∀ b → P true → P false → P b if true t e = t if false t e = e _⊎_ : (A B : Set) → Set A ⊎ B = ∃ λ b → if b A B inj₁ : {A B : Set} → A → A ⊎ B inj₁ x = true , x inj₂ : {A B : Set} → B → A ⊎ B inj₂ x = false , x ⊎-elim : ∀ {p} {A B : Set} {P : A ⊎ B → Set p} → (∀ x → P (inj₁ x)) → (∀ y → P (inj₂ y)) → ∀ s → P s ⊎-elim x y (true , snd) = x snd ⊎-elim x y (false , snd) = y snd _×_ : (A B : Set) → Set A × B = ∀ b → if b A B proj₁ : {A B : Set} → A × B → A proj₁ x = x true proj₂ : {A B : Set} → A × B → B proj₂ x = x false Fin : ℕ → Set Fin zero = ⊥ Fin (suc n) = ⊤ ⊎ Fin n Vec : Set → ℕ → Set Vec A n = Fin n → A module VecList where List : Set → Set List A = ∃ λ n → Vec A n
18.757143
62
0.504189
1356adc24632fa66bdc30fd91e6f1c13f5fa65be
803
agda
Agda
archive/agda-3/src/Oscar/Class/Quadricity.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-3/src/Oscar/Class/Quadricity.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-3/src/Oscar/Class/Quadricity.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
open import Oscar.Prelude open import Oscar.Class module Oscar.Class.Quadricity where module Quadricity {𝔞} {𝔄 : Ø 𝔞} {𝔟} {𝔅 : Ø 𝔟} {ℓ} (_↦_ : 𝔅 → 𝔅 → Ø ℓ) (let infix 4 _↦_; _↦_ = _↦_) (_∧_ : 𝔅 → 𝔅 → 𝔅) (let infixr 15 _∧_; _∧_ = _∧_) (_∼_ : 𝔄 → 𝔄 → 𝔅) (let infix 18 _∼_; _∼_ = _∼_) (_⊛_ : 𝔄 → 𝔄 → 𝔄) = ℭLASS (_↦_ , _∼_ , _∧_ , _⊛_) (∀ s1 s2 t1 t2 → s1 ⊛ s2 ∼ t1 ⊛ t2 ↦ s1 ∼ t1 ∧ s2 ∼ t2) module _ {𝔞} {𝔄 : Ø 𝔞} {𝔟} {𝔅 : Ø 𝔟} {ℓ} {_↦_ : 𝔅 → 𝔅 → Ø ℓ} {_∧_ : 𝔅 → 𝔅 → 𝔅} {_∼_ : 𝔄 → 𝔄 → 𝔅} {_⊛_ : 𝔄 → 𝔄 → 𝔄} where quadricity = Quadricity.method _↦_ _∧_ _∼_ _⊛_ open import Oscar.Class.Properthing open import Oscar.Class.HasEquivalence module Properfact1 {𝔞} {𝔄 : Ø 𝔞} {𝔟} {𝔅 : Ø 𝔟} (∼ : 𝔄 → 𝔄 → 𝔅) {ℓ} ⦃ _ : Properthing ℓ 𝔅 ⦄ (⊛ : 𝔄 → 𝔄 → 𝔄) = Quadricity _≈_ _∧_ ∼ ⊛
25.09375
89
0.504359
4373c719edc7bb6c4879305ad5bc06260045f169
1,834
agda
Agda
Numeral/Integer/Oper.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Numeral/Integer/Oper.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Numeral/Integer/Oper.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Numeral.Integer.Oper where open import Numeral.Natural as ℕ using (ℕ) import Numeral.Natural.Oper as ℕ open import Numeral.Integer open import Numeral.Integer.Sign import Numeral.Sign as Sign import Numeral.Sign.Oper0 as Sign -- Unclosed total subtraction from natural numbers to integers _−ₙ_ : ℕ → ℕ → ℤ x −ₙ ℕ.𝟎 = ℤ.+ₙ x ℕ.𝟎 −ₙ ℕ.𝐒(x) = ℤ.−𝐒ₙ(x) ℕ.𝐒(x) −ₙ ℕ.𝐒(y) = x −ₙ y -- Construction of an integer with the sign and numeral components signed : (Sign.+|−) → ℕ → ℤ signed (Sign.➕) (n) = +ₙ n signed (Sign.➖) (n) = −ₙ n signed0 : (Sign.+|0|−) → ℕ → ℤ signed0(Sign.➕) (ℕ.𝐒(n)) = +𝐒ₙ(n) signed0(Sign.➖) (ℕ.𝐒(n)) = −𝐒ₙ(n) {-# CATCHALL #-} signed0(_) (_) = 𝟎 ------------------------------------------ -- Unary operations -- Predecessor 𝐏 : ℤ → ℤ 𝐏(+𝐒ₙ(n)) = +ₙ n 𝐏(𝟎) = −𝐒ₙ(ℕ.𝟎) 𝐏(−𝐒ₙ(n)) = −𝐒ₙ(ℕ.𝐒(n)) -- Successor 𝐒 : ℤ → ℤ 𝐒(+ₙ n) = +ₙ ℕ.𝐒(n) 𝐒(−𝐒ₙ(ℕ.𝟎)) = +ₙ ℕ.𝟎 𝐒(−𝐒ₙ(ℕ.𝐒(n))) = −𝐒ₙ(n) -- Identity +_ : ℤ → ℤ + n = n -- Negation −_ : ℤ → ℤ − 𝟎 = 𝟎 − (+𝐒ₙ(n)) = −𝐒ₙ(n) − (−𝐒ₙ(n)) = +𝐒ₙ(n) -- Absolute value abs : ℤ → ℤ abs(+ₙ x) = +ₙ x abs(−𝐒ₙ x) = +𝐒ₙ x ------------------------------------------ -- Binary operations infixl 10010 _+_ infixl 10020 _⋅_ -- Addition _+_ : ℤ → ℤ → ℤ (+ₙ x) + (+ₙ y) = +ₙ (x ℕ.+ y) (−𝐒ₙ x) + (−𝐒ₙ y) = −𝐒ₙ(ℕ.𝐒(x ℕ.+ y)) (+ₙ x) + (−𝐒ₙ y) = x −ₙ ℕ.𝐒(y) (−𝐒ₙ x) + (+ₙ y) = (+ₙ y) + (−𝐒ₙ x) -- Subtraction _−_ : ℤ → ℤ → ℤ x − y = x + (− y) -- Multiplication _⋅_ : ℤ → ℤ → ℤ x ⋅ y = signed0 ((sign0 x) Sign.⨯ (sign0 y)) ((absₙ x) ℕ.⋅ (absₙ y)) -- Distance _𝄩_ : ℤ → ℤ → ℕ (+ₙ x) 𝄩 (+ₙ y) = x ℕ.𝄩 y (−𝐒ₙ x) 𝄩 (−𝐒ₙ y) = x ℕ.𝄩 y (+ₙ(ℕ.𝟎)) 𝄩 (−𝐒ₙ y) = ℕ.𝐒(y) (+ₙ(ℕ.𝐒 x)) 𝄩 (−𝐒ₙ y) = ℕ.𝐒((+ₙ x) 𝄩 (−𝐒ₙ y)) (−𝐒ₙ x) 𝄩 (+ₙ(ℕ.𝟎)) = ℕ.𝐒(x) (−𝐒ₙ x) 𝄩 (+ₙ(ℕ.𝐒 y)) = ℕ.𝐒((−𝐒ₙ x) 𝄩 (+ₙ y))
21.325581
68
0.45747
140d2cdfb76a9553f1db7e209b17a85762026c02
7,359
agda
Agda
src/Data/Context/Properties.agda
Blaisorblade/f-omega-int-agda
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
[ "MIT" ]
null
null
null
src/Data/Context/Properties.agda
Blaisorblade/f-omega-int-agda
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
[ "MIT" ]
null
null
null
src/Data/Context/Properties.agda
Blaisorblade/f-omega-int-agda
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Propierties of abstract typing contexts ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module Data.Context.Properties where open import Data.Fin using (Fin; zero; suc; lift; raise) open import Data.Fin.Substitution.ExtraLemmas open import Data.Nat using (ℕ; zero; suc; _+_) open import Data.Product using (_×_; _,_) open import Data.Vec as Vec using (Vec; []; _∷_) import Data.Vec.Properties as VecProps open import Function as Fun using (_∘_; flip) open import Relation.Binary.PropositionalEquality hiding (subst-∘) open ≡-Reasoning open import Relation.Unary using (Pred) open import Data.Context open import Data.Context.WellFormed ------------------------------------------------------------------------ -- Properties of abstract contexts and context extensions. -- Properties of the `map' functions. module _ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} where -- pointwise equality is a congruence w.r.t. map and mapExt. map-cong : ∀ {n} {f g : ∀ {k} → T₁ k → T₂ k} → (∀ {k} → f {k} ≗ g {k}) → _≗_ {A = Ctx T₁ n} (map f) (map g) map-cong f≗g [] = refl map-cong f≗g (_∷_ t Γ) = cong₂ _∷_ (f≗g t) (map-cong f≗g Γ) mapExt-cong : ∀ {k m n} {f g : ∀ i → T₁ (i + m) → T₂ (i + n)} → (∀ {i} → f i ≗ g i) → _≗_ {A = CtxExt T₁ m k} (mapExt {T₂ = T₂} f) (mapExt g) mapExt-cong f≗g [] = refl mapExt-cong f≗g (_∷_ {l} t Γ) = cong₂ _∷_ (f≗g {l} t) (mapExt-cong f≗g Γ) module _ {ℓ} {T : Pred ℕ ℓ} where -- map and mapExt are functorial. map-id : ∀ {n} → _≗_ {A = Ctx T n} (map Fun.id) Fun.id map-id [] = refl map-id (t ∷ Γ) = cong (t ∷_) (map-id Γ) mapExt-id : ∀ {m n} → _≗_ {A = CtxExt T m n} (mapExt λ _ t → t) Fun.id mapExt-id [] = refl mapExt-id (t ∷ Γ) = cong (t ∷_) (mapExt-id Γ) module _ {ℓ₁ ℓ₂ ℓ₃} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {T₃ : Pred ℕ ℓ₃} where map-∘ : ∀ {n} (f : ∀ {k} → T₂ k → T₃ k) (g : ∀ {k} → T₁ k → T₂ k) (Γ : Ctx T₁ n) → map {T₂ = T₃} (f ∘ g) Γ ≡ map {T₁ = T₂} f (map g Γ) map-∘ f g [] = refl map-∘ f g (t ∷ Γ) = cong (_ ∷_) (map-∘ f g Γ) mapExt-∘ : ∀ {k l m n} (f : ∀ i → T₂ (i + m) → T₃ (i + n)) (g : ∀ i → T₁ (i + l) → T₂ (i + m)) → (Γ : CtxExt T₁ l k) → mapExt {T₂ = T₃} (λ i t → f i (g i t)) Γ ≡ mapExt {T₁ = T₂} f (mapExt g Γ) mapExt-∘ f g [] = refl mapExt-∘ f g (t ∷ Γ) = cong (_ ∷_) (mapExt-∘ f g Γ) -- Lemmas about operations on contexts that require weakening of -- types. module WeakenOpsLemmas {ℓ} {T : Pred ℕ ℓ} (extension : Extension T) where -- The underlyig operations. open WeakenOps extension -- Conversion to vector representation commutes with -- concatenation. toVec-++ : ∀ {m n} (Δ : CtxExt T m n) (Γ : Ctx T m) → toVec (Δ ++ Γ) ≡ extToVec Δ (toVec Γ) toVec-++ [] Γ = refl toVec-++ (t ∷ Δ) Γ = cong ((_ ∷_) ∘ Vec.map weaken) (toVec-++ Δ Γ) -- Lookup commutes with concatenation. lookup-++ : ∀ {m n} (Δ : CtxExt T m n) (Γ : Ctx T m) x → lookup (Δ ++ Γ) x ≡ extLookup Δ (toVec Γ) x lookup-++ Δ Γ x = cong (flip Vec.lookup x) (toVec-++ Δ Γ) -- We can skip the first element when looking up others. lookup-suc : ∀ {n} t (Γ : Ctx T n) x → lookup (t ∷ Γ) (suc x) ≡ weaken (lookup Γ x) lookup-suc t Γ x = VecProps.lookup-map x weaken (toVec Γ) extLookup-suc : ∀ {k m n} t (Γ : CtxExt T m n) (ts : Vec (T m) k) x → extLookup (t ∷ Γ) ts (suc x) ≡ weaken (extLookup Γ ts x) extLookup-suc t Γ ts x = VecProps.lookup-map x weaken (extToVec Γ ts) -- We can skip a spliced-in element when looking up others. lookup-lift : ∀ {k m n} (Γ : CtxExt T m n) t (ts : Vec (T m) k) x → extLookup Γ ts x ≡ extLookup Γ (t ∷ ts) (lift n suc x) lookup-lift [] t ts x = refl lookup-lift (u ∷ Δ) t ts zero = refl lookup-lift {n = suc n} (u ∷ Δ) t ts (suc x) = begin extLookup (u ∷ Δ) ts (suc x) ≡⟨ extLookup-suc u Δ ts x ⟩ weaken (extLookup Δ ts x) ≡⟨ cong weaken (lookup-lift Δ t ts x) ⟩ weaken (extLookup Δ (t ∷ ts) (lift n suc x)) ≡⟨ sym (extLookup-suc u Δ (t ∷ ts) (lift n suc x)) ⟩ extLookup (u ∷ Δ) (t ∷ ts) (suc (lift n suc x)) ∎ -- Lookup in the prefix of a concatenation results in weakening. lookup-weaken⋆ : ∀ {m} n (Δ : CtxExt T m n) (Γ : Ctx T m) x → lookup (Δ ++ Γ) (raise n x) ≡ weaken⋆ n (lookup Γ x) lookup-weaken⋆ zero [] Γ x = refl lookup-weaken⋆ (suc n) (t ∷ Δ) Γ x = begin lookup (t ∷ Δ ++ Γ) (suc (raise n x)) ≡⟨ VecProps.lookup-map (raise n x) weaken (toVec (Δ ++ Γ)) ⟩ weaken (lookup (Δ ++ Γ) (raise n x)) ≡⟨ cong weaken (lookup-weaken⋆ n Δ Γ x) ⟩ weaken (weaken⋆ n (lookup Γ x)) ∎ -- Lemmas relating conversions of context extensions to vector -- representation with conversions of the underling entries. module ConversionLemmas {T₁ T₂ : ℕ → Set} (extension₁ : Extension T₁) (extension₂ : Extension T₂) where private module W₁ = WeakenOps extension₁ module W₂ = WeakenOps extension₂ toVec-map : ∀ {n} (f : ∀ {k} → T₁ k → T₂ k) (Γ : Ctx T₁ n) → (∀ {k} (t : T₁ k) → W₂.weaken (f t) ≡ f (W₁.weaken t)) → W₂.toVec (map f Γ) ≡ Vec.map f (W₁.toVec Γ) toVec-map f [] _ = refl toVec-map f (_∷_ t Γ) hyp = cong₂ _∷_ (hyp t) (begin Vec.map W₂.weaken (W₂.toVec (map f Γ)) ≡⟨ cong (Vec.map W₂.weaken) (toVec-map f Γ hyp) ⟩ (Vec.map W₂.weaken (Vec.map f (W₁.toVec Γ))) ≡⟨ sym (VecProps.map-∘ W₂.weaken f (W₁.toVec Γ)) ⟩ (Vec.map (W₂.weaken ∘ f) (W₁.toVec Γ)) ≡⟨ VecProps.map-cong hyp (W₁.toVec Γ) ⟩ (Vec.map (f ∘ W₁.weaken) (W₁.toVec Γ)) ≡⟨ VecProps.map-∘ f W₁.weaken (W₁.toVec Γ) ⟩ (Vec.map f (Vec.map W₁.weaken (W₁.toVec Γ))) ∎) -- Lookup commutes with re-indexing, provided that the reindexing -- function commutes with weakening. lookup-map : ∀ {n} (f : ∀ {k} → T₁ k → T₂ k) (Γ : Ctx T₁ n) x → (∀ {k} (t : T₁ k) → W₂.weaken (f t) ≡ f (W₁.weaken t)) → W₂.lookup (map f Γ) x ≡ f (W₁.lookup Γ x) lookup-map f Γ x hyp = begin W₂.lookup (map f Γ) x ≡⟨ cong (flip Vec.lookup x) (toVec-map f Γ hyp) ⟩ Vec.lookup (Vec.map f (W₁.toVec Γ)) x ≡⟨ VecProps.lookup-map x f (W₁.toVec Γ) ⟩ f (W₁.lookup Γ x) ∎ -- Lemmas about well-formed contexts and context extensions. module ContextFormationLemmas {t ℓ} {T : Pred ℕ t} (_⊢_wf : Wf T T ℓ) where open ContextFormation _⊢_wf -- Concatenation preserves well-formedness of contexts. wf-++-wfExt : ∀ {m n} {Δ : CtxExt T m n} {Γ : Ctx T m} → Γ ⊢ Δ wfExt → Γ wf → Δ ++ Γ wf wf-++-wfExt [] Γ-wf = Γ-wf wf-++-wfExt (t-wf ∷ Δ-wfExt) Γ-wf = t-wf ∷ wf-++-wfExt Δ-wfExt Γ-wf -- Splitting of well-formed contexts. wf-split : ∀ {m n} {Δ : CtxExt T m n} {Γ : Ctx T m} → Δ ++ Γ wf → Γ ⊢ Δ wfExt × Γ wf wf-split {Δ = []} Γ-wf = [] , Γ-wf wf-split {Δ = t ∷ Δ} (t-wf ∷ Δ++Γ-wf) = let Δ-wfExt , Γ-wf = wf-split Δ++Γ-wf in t-wf ∷ Δ-wfExt , Γ-wf
37.93299
78
0.521131
0d204bd50d478eca4bc1da84c69c40a419171464
7,127
agda
Agda
examples/outdated-and-incorrect/IORef.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/IORef.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/IORef.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module IORef where data Unit : Set where unit : Unit data Pair (A B : Set) : Set where pair : A -> B -> Pair A B fst : {A B : Set} -> Pair A B -> A fst (pair a b) = a snd : {A B : Set} -> Pair A B -> B snd (pair a b) = b data Nat : Set where zero : Nat suc : Nat -> Nat data Fin : Nat -> Set where fz : {n : Nat} -> Fin (suc n) fs : {n : Nat} -> Fin n -> Fin (suc n) infixr 40 _::_ infixl 20 _!_ data Vec (A : Set) : Nat -> Set where [] : Vec A zero _::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n) _!_ : {A : Set}{n : Nat} -> Vec A n -> Fin n -> A [] ! () x :: _ ! fz = x _ :: xs ! (fs i) = xs ! i Loc : Nat -> Set Loc = Fin -- A universe. IORefs can store data of type el(u), for some u : U postulate U : Set el : U -> Set -- Shapes tell you what types live on the heap. Shape : Nat -> Set Shape n = Vec U n -- Fin n -> U -- Shapes can grow as you allocate new memory _||_ : {n : Nat} -> Shape n -> U -> Shape (suc n) xs || u = u :: xs infixl 40 _▻_ infixl 60 _[_:=_] _[_] -- The heap maps locations to elements of the right type. data Heap : {n : Nat}(s : Shape n) -> Set where ε : Heap [] _▻_ : {n : Nat}{s : Shape n}{a : U} -> Heap s -> el a -> Heap (s || a) -- Heap : {n : Nat} -> Shape n -> Set -- Heap {n} shape = (k : Fin n) -> el (shape ! k) _[_:=_] : {n : Nat}{s : Shape n} -> Heap s -> (l : Loc n) -> el (s ! l) -> Heap s ε [ () := _ ] (h ▻ _) [ fz := x ] = h ▻ x (h ▻ y) [ fs i := x ] = h [ i := x ] ▻ y _[_] : {n : Nat}{s : Shape n} -> Heap s -> (l : Loc n) -> el (s ! l) ε [ () ] (h ▻ x) [ fz ] = x (h ▻ _) [ fs i ] = h [ i ] -- (h [ fz := x ]) fz = x -- (h [ fz := x ]) (fs i) = h (fs i) -- (h [ fs i := x ]) fz = h fz -- _[_:=_] {._}{_ :: s} h (fs i) x (fs j) = _[_:=_] {s = s} (\z -> h (fs z)) i x j -- Well-scoped, well-typed IORefs data IO (A : Set) : {n m : Nat} -> Shape n -> Shape m -> Set where Return : {n : Nat}{s : Shape n} -> A -> IO A s s WriteIORef : {n m : Nat}{s : Shape n}{t : Shape m} -> (loc : Loc n) -> el (s ! loc) -> IO A s t -> IO A s t ReadIORef : {n m : Nat}{s : Shape n}{t : Shape m} -> (loc : Loc n) -> (el (s ! loc) -> IO A s t) -> IO A s t NewIORef : {n m : Nat}{s : Shape n}{t : Shape m}{u : U} -> el u -> IO A (s || u) t -> IO A s t -- Running IO programs run : {A : Set} -> {n m : Nat} -> {s : Shape n} -> {t : Shape m} -> Heap s -> IO A s t -> Pair A (Heap t) run heap (Return x) = pair x heap run heap (WriteIORef l x io) = run (heap [ l := x ]) io run heap (ReadIORef l k) = run heap (k (heap [ l ])) run heap (NewIORef x k) = run (heap ▻ x) k infixr 10 _>>=_ _>>_ _>>=_ : {A B : Set}{n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃} -> IO A s₁ s₂ -> (A -> IO B s₂ s₃) -> IO B s₁ s₃ Return x >>= f = f x WriteIORef r x k >>= f = WriteIORef r x (k >>= f) ReadIORef r k >>= f = ReadIORef r (\x -> k x >>= f) NewIORef x k >>= f = NewIORef x (k >>= f) _>>_ : {A B : Set}{n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃} -> IO A s₁ s₂ -> IO B s₂ s₃ -> IO B s₁ s₃ a >> b = a >>= \_ -> b -- The operations without CPS data IORef : {n : Nat}(s : Shape n) -> U -> Set where ioRef : {n : Nat}{s : Shape n}(r : Loc n) -> IORef s (s ! r) return : {A : Set}{n : Nat}{s : Shape n} -> A -> IO A s s return = Return writeIORef : {n : Nat}{s : Shape n}{a : U} -> IORef s a -> el a -> IO Unit s s writeIORef (ioRef r) x = WriteIORef r x (Return unit) readIORef : {n : Nat}{s : Shape n}{a : U} -> IORef s a -> IO (el a) s s readIORef (ioRef r) = ReadIORef r Return newIORef : {n : Nat}{s : Shape n}{a : U} -> el a -> IO (IORef (s || a) a) s (s || a) newIORef x = NewIORef x (Return (ioRef fz)) -- Some nice properties infix 10 _==_ _≡_ data _==_ {A : Set}(x : A) : A -> Set where refl : x == x subst : {A : Set}(P : A -> Set){x y : A} -> x == y -> P y -> P x subst {A} P refl Px = Px cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y cong {A} f refl = refl trans : {A : Set}{x y z : A} -> x == y -> y == z -> x == z trans {A} refl p = p fsteq : {A B : Set}{x y : A}{z w : B} -> pair x z == pair y w -> x == y fsteq {A}{B} refl = refl -- Lemmas update-lookup : {n : Nat}{s : Shape n}(h : Heap s)(r : Loc n)(x : el (s ! r)) -> h [ r := x ] [ r ] == x update-lookup ε () _ update-lookup (h ▻ _) fz x = refl update-lookup (h ▻ _) (fs i) x = update-lookup h i x update-update : {n : Nat}{s : Shape n}(h : Heap s)(r : Loc n)(x y : el (s ! r)) -> h [ r := x ] [ r := y ] == h [ r := y ] update-update ε () _ _ update-update (h ▻ _) fz x y = refl update-update (h ▻ z) (fs i) x y = cong (\ ∙ -> ∙ ▻ z) (update-update h i x y) -- Equality of monadic computations data _≡_ {A : Set}{n m : Nat}{s : Shape n}{t : Shape m}(io₁ io₂ : IO A s t) : Set where eqIO : ((h : Heap s) -> run h io₁ == run h io₂) -> io₁ ≡ io₂ uneqIO : {A : Set}{n m : Nat}{s : Shape n}{t : Shape m}{io₁ io₂ : IO A s t} -> io₁ ≡ io₂ -> (h : Heap s) -> run h io₁ == run h io₂ uneqIO (eqIO e) = e -- Congruence properties cong->> : {A B : Set}{n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃} {io₁₁ io₁₂ : IO A s₁ s₂}{io₂₁ io₂₂ : A -> IO B s₂ s₃} -> io₁₁ ≡ io₁₂ -> ((x : A) -> io₂₁ x ≡ io₂₂ x) -> io₁₁ >>= io₂₁ ≡ io₁₂ >>= io₂₂ cong->> {A}{B}{s₁ = s₁}{s₂}{s₃}{io₁₁}{io₁₂}{io₂₁}{io₂₂}(eqIO eq₁) eq₂ = eqIO (prf io₁₁ io₁₂ io₂₁ io₂₂ eq₁ eq₂) where prf : {n₁ n₂ n₃ : Nat}{s₁ : Shape n₁}{s₂ : Shape n₂}{s₃ : Shape n₃} (io₁₁ io₁₂ : IO A s₁ s₂)(io₂₁ io₂₂ : A -> IO B s₂ s₃) -> ((h : Heap s₁) -> run h io₁₁ == run h io₁₂) -> ((x : A) -> io₂₁ x ≡ io₂₂ x) -> (h : Heap s₁) -> run h (io₁₁ >>= io₂₁) == run h (io₁₂ >>= io₂₂) prf (Return x) (Return y) k₁ k₂ eq₁ eq₂ h = subst (\ ∙ -> run h (k₁ ∙) == run h (k₂ y)) x=y (uneqIO (eq₂ y) h) where x=y : x == y x=y = fsteq (eq₁ h) prf (WriteIORef r₁ x₁ k₁) (Return y) k₂ k₃ eq₁ eq₂ h = ? -- ... boring proofs -- Monad laws -- boring... -- IO laws new-read : {n : Nat}{s : Shape n}{a : U}(x : el a) -> newIORef {s = s} x >>= readIORef ≡ newIORef x >> return x new-read x = eqIO \h -> refl write-read : {n : Nat}{s : Shape n}{a : U}(r : IORef s a)(x : el a) -> writeIORef r x >> readIORef r ≡ writeIORef r x >> return x write-read (ioRef r) x = eqIO \h -> cong (\ ∙ -> pair ∙ (h [ r := x ])) (update-lookup h r x) write-write : {n : Nat}{s : Shape n}{a : U}(r : IORef s a)(x y : el a) -> writeIORef r x >> writeIORef r y ≡ writeIORef r y write-write (ioRef r) x y = eqIO \h -> cong (\ ∙ -> pair unit ∙) (update-update h r x y) -- Some separation properties would be nice
32.99537
89
0.459801
11113ee846883c17648137c2fd932f5c6276ca6a
225
agda
Agda
test/Succeed/Issue2629.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2629.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2629.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --exact-split #-} open import Agda.Builtin.Nat data IsZero : Nat → Set where isZero : IsZero 0 test : (n m : Nat) → IsZero n → IsZero m → Nat test zero zero _ _ = zero test (suc _) _ () _ test _ (suc _) _ ()
18.75
46
0.617778
7c5af67176f88afd8eb1909e2f79eb536e437592
1,627
agda
Agda
Relation/Binary/Equivalence/PropTruncated.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Relation/Binary/Equivalence/PropTruncated.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Relation/Binary/Equivalence/PropTruncated.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe --prop #-} module Relation.Binary.Equivalence.PropTruncated where open import Prelude open import Relation.Nullary.Stable infix 4 _≐_ data _≐_ {a} {A : Type a} (x y : A) : Prop a where ∣_∣ : x ≡ y → x ≐ y data ∙⊥ : Prop where private variable x y z : A rerel : ∙⊥ → ⊥ rerel () ∙refute : x ≐ y → (x ≡ y → ⊥) → ∙⊥ ∙refute ∣ x≡y ∣ x≢y with x≢y x≡y ∙refute ∣ x≡y ∣ x≢y | () refute : x ≐ y → ¬ (¬ (x ≡ y)) refute x≐y x≢y = rerel (∙refute x≐y x≢y) unsquash : Stable (x ≡ y) → x ≐ y → x ≡ y unsquash st x≐y = st (refute x≐y) ∙refl : x ≐ x ∙refl = ∣ refl ∣ ∙trans : x ≐ y → y ≐ z → x ≐ z ∙trans ∣ xy ∣ (∣_∣ yz) = ∣_∣ (xy ; yz) ∙sym : x ≐ y → y ≐ x ∙sym (∣_∣ p) = ∣_∣ (sym p) ∙cong : (f : A → B) → x ≐ y → f x ≐ f y ∙cong f ∣ x≡y ∣ = ∣ cong f x≡y ∣ module Reasoning where infixr 2 ≐˘⟨⟩-syntax ≐⟨∙⟩-syntax ≐˘⟨⟩-syntax : ∀ (x : A) {y z} → y ≐ z → y ≐ x → x ≐ z ≐˘⟨⟩-syntax _ y≡z y≡x = ∙trans (∙sym y≡x) y≡z syntax ≐˘⟨⟩-syntax x y≡z y≡x = x ≐˘⟨ y≡x ⟩ y≡z ≐⟨∙⟩-syntax : ∀ (x : A) {y z} → y ≐ z → x ≐ y → x ≐ z ≐⟨∙⟩-syntax _ y≡z x≡y = ∙trans x≡y y≡z syntax ≐⟨∙⟩-syntax x y≡z x≡y = x ≐⟨ x≡y ⟩ y≡z _≐⟨⟩_ : ∀ (x : A) {y} → x ≐ y → x ≐ y _ ≐⟨⟩ x≡y = x≡y infix 2.5 _∎ _∎ : ∀ {A : Type a} (x : A) → x ≐ x _∎ x = ∙refl infixr 2 ≡˘⟨⟩-syntax ≡⟨∙⟩-syntax ≡˘⟨⟩-syntax : ∀ (x : A) {y z} → y ≐ z → y ≡ x → x ≐ z ≡˘⟨⟩-syntax _ y≡z y≡x = ∙trans (∣_∣ (sym y≡x)) y≡z syntax ≡˘⟨⟩-syntax x y≡z y≡x = x ≡˘⟨ y≡x ⟩ y≡z ≡⟨∙⟩-syntax : ∀ (x : A) {y z} → y ≐ z → x ≡ y → x ≐ z ≡⟨∙⟩-syntax _ y≡z x≡y = ∙trans ∣ x≡y ∣ y≡z syntax ≡⟨∙⟩-syntax x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z
21.693333
55
0.451752
0d476b138830272ac95d524c889a8b74621e8089
5,325
agda
Agda
src/Dodo/Binary/Domain.agda
sourcedennis/agda-dodo
376f0ccee1e1aa31470890e494bcb534324f598a
[ "BSD-3-Clause" ]
null
null
null
src/Dodo/Binary/Domain.agda
sourcedennis/agda-dodo
376f0ccee1e1aa31470890e494bcb534324f598a
[ "BSD-3-Clause" ]
null
null
null
src/Dodo/Binary/Domain.agda
sourcedennis/agda-dodo
376f0ccee1e1aa31470890e494bcb534324f598a
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Dodo.Binary.Domain where -- Stdlib imports open import Level using (Level; _⊔_) open import Function.Base using (flip; _∘_) open import Data.Product using (_×_; _,_; ∃; ∃-syntax; proj₁; proj₂) open import Data.Sum using (_⊎_; inj₁; inj₂; swap) open import Relation.Unary using (Pred; _∈_; _∉_) open import Relation.Binary using (Rel; REL) -- Local imports open import Dodo.Unary.Equality open import Dodo.Unary.Union open import Dodo.Binary.Equality open import Dodo.Binary.Composition -- # Definitions -- | The domain of the binary relation dom : ∀ {a b ℓ : Level} {A : Set a} {B : Set b} → REL A B ℓ -------------- → Pred A (b ⊔ ℓ) dom R x = ∃[ y ] (R x y) -- | The co-domain (or range) of the binary relation -- -- -- # Design decision: Not range -- -- It is somewhat arbitrary what constitutes the /co-domain/ of a binary relation, -- and how it differs from its /range/. Usually, the /co-domain/ denotes the set of -- /possible/ outputs of a function, while the /range/ denotes the set of /actual/ -- outputs. When considering functions, the /domain/ is a set of /independent/ variables, -- while the /co-domain/ is the set variables that are /dependent/ on the domain. -- -- However, when considering /relations/ (as opposed to mere functions), this dependency -- is (usually) absent; Or could be inverted, where the domain "depends on" the codomain. -- Under such interpretation, distinguishing co-domain from range is rather arbitrary. codom : ∀ {a b ℓ : Level} {A : Set a} {B : Set b} → REL A B ℓ -------------- → Pred B (a ⊔ ℓ) codom R y = ∃[ x ] (R x y) -- | The domain and co-domain of the binary relation -- -- Conventionally named after: Union (of) Domain (and) Range udr : ∀ {a ℓ : Level} {A : Set a} → Rel A ℓ -------------- → Pred A (a ⊔ ℓ) udr R = dom R ∪₁ codom R -- # Operations -- ## Operations: dom / codom / udr -- | Weakens an element of a relation's domain to an element of its udr. -- -- Note that Agda is unable to infer `R` from `x ∈ dom R`. -- (As `R` may be beta-reduced inside the latter, I think) dom⇒udr : ∀ {a ℓ : Level} {A : Set a} (R : Rel A ℓ) {x : A} → x ∈ dom R → x ∈ udr R dom⇒udr _ = inj₁ -- | Weakens an element of a relation's co-domain to an element of its udr. -- -- Note that Agda is unable to infer `R` from `x ∈ dom R`. -- (As `R` may be beta-reduced inside the latter, I think) codom⇒udr : ∀ {a ℓ : Level} {A : Set a} (R : Rel A ℓ) {x : A} → x ∈ codom R → x ∈ udr R codom⇒udr _ = inj₂ module _ {a b ℓ : Level} {A : Set a} {B : Set b} where -- | Takes an inhabitant of `R x y` as proof that `x` is in the domain of `R`. -- -- Note that `R` must be provided /explicitly/, as it may not always be inferred -- from its applied type. take-dom : (R : REL A B ℓ) → {x : A} {y : B} → R x y → x ∈ dom R take-dom R {x} {y} Rxy = (y , Rxy) -- | Takes an inhabitant of `R x y` as proof that `y` is in the co-domain of `R`. -- -- Note that `R` must be provided /explicitly/, as it may not always be inferred -- from its applied type. take-codom : (R : REL A B ℓ) → {x : A} {y : B} → R x y → y ∈ codom R take-codom R {x} {y} Rxy = (x , Rxy) module _ {a ℓ : Level} {A : Set a} where -- | Takes an inhabitant of `R x y` as proof that `x` is in the udr of `R`. -- -- Note that `R` must be provided /explicitly/, as it may not always be inferred -- from its applied type. take-udrˡ : (R : Rel A ℓ) → {x y : A} → R x y → x ∈ udr R take-udrˡ R Rxy = dom⇒udr R (take-dom R Rxy) -- | Takes an inhabitant of `R x y` as proof that `y` is in the udr of `R`. -- -- Note that `R` must be provided /explicitly/, as it may not always be inferred -- from its applied type. take-udrʳ : (R : Rel A ℓ) → {x y : A} → R x y → y ∈ udr R take-udrʳ R Rxy = codom⇒udr R (take-codom R Rxy) module _ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} where dom-preserves-⊆ : P ⊆₂ Q → dom P ⊆₁ dom Q dom-preserves-⊆ P⊆Q = ⊆: λ{x (y , Pxy) → (y , un-⊆₂ P⊆Q x y Pxy)} codom-preserves-⊆ : P ⊆₂ Q → codom P ⊆₁ codom Q codom-preserves-⊆ P⊆Q = ⊆: λ{y (x , Pxy) → (x , un-⊆₂ P⊆Q x y Pxy)} module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where udr-preserves-⊆ : P ⊆₂ Q → udr P ⊆₁ udr Q udr-preserves-⊆ P⊆Q = ⊆: lemma where lemma : udr P ⊆₁' udr Q lemma x (inj₁ x∈dom) = dom⇒udr Q (⊆₁-apply (dom-preserves-⊆ P⊆Q) x∈dom) lemma y (inj₂ y∈codom) = codom⇒udr Q (⊆₁-apply (codom-preserves-⊆ P⊆Q) y∈codom) module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where udr-combine-⨾ : udr (P ⨾ Q) ⊆₁ udr P ∪₁ udr Q udr-combine-⨾ = ⊆: lemma where lemma : udr (P ⨾ Q) ⊆₁' (udr P ∪₁ udr Q) lemma _ (inj₁ (a , (Pxb ⨾[ b ]⨾ Qba))) = inj₁ (inj₁ (b , Pxb)) lemma _ (inj₂ (a , (Pab ⨾[ b ]⨾ Qbx))) = inj₂ (inj₂ (b , Qbx)) module _ {a ℓ : Level} {A : Set a} {P : Rel A ℓ} where udr-flip : udr P ⇔₁ udr (flip P) udr-flip = ⇔: (λ _ → swap) (λ _ → swap) dom-flip : dom P ⇔₁ codom (flip P) dom-flip = ⇔: (λ _ z → z) (λ _ z → z) codom-flip : codom P ⇔₁ dom (flip P) codom-flip = ⇔: (λ _ z → z) (λ _ z → z)
34.577922
90
0.575399
3fbfedbd76f58be4957ab2978274bdbe5990994a
16,338
agda
Agda
Categories/Square.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Square.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Square.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
{-# OPTIONS --universe-polymorphism --irrelevant-projections #-} module Categories.Square where open import Level open import Function renaming (id to idᶠ; _∘_ to _©_) open import Categories.Support.PropositionalEquality open import Categories.Category import Categories.Morphisms as Mor open import Relation.Binary hiding (_⇒_) module GlueSquares {o ℓ e} (C : Category o ℓ e) where private module C = Category C open C open Mor C module Pulls {X Y Z} {a : Y ⇒ Z} {b : X ⇒ Y} {c : X ⇒ Z} (ab≡c : a ∘ b ≡ c) where .pullʳ : ∀ {W} {f : Z ⇒ W} → (f ∘ a) ∘ b ≡ f ∘ c pullʳ {f = f} = begin (f ∘ a) ∘ b ↓⟨ assoc ⟩ f ∘ (a ∘ b) ↓⟨ ∘-resp-≡ʳ ab≡c ⟩ f ∘ c ∎ where open HomReasoning .pullˡ : ∀ {W} {f : W ⇒ X} → a ∘ (b ∘ f) ≡ c ∘ f pullˡ {f = f} = begin a ∘ (b ∘ f) ↑⟨ assoc ⟩ (a ∘ b) ∘ f ↓⟨ ∘-resp-≡ˡ ab≡c ⟩ c ∘ f ∎ where open HomReasoning open Pulls public module Pushes {X Y Z} {a : Y ⇒ Z} {b : X ⇒ Y} {c : X ⇒ Z} (c≡ab : c ≡ a ∘ b) where .pushʳ : ∀ {W} {f : Z ⇒ W} → f ∘ c ≡ (f ∘ a) ∘ b pushʳ {f = f} = begin f ∘ c ↓⟨ ∘-resp-≡ʳ c≡ab ⟩ f ∘ (a ∘ b) ↑⟨ assoc ⟩ (f ∘ a) ∘ b ∎ where open HomReasoning .pushˡ : ∀ {W} {f : W ⇒ X} → c ∘ f ≡ a ∘ (b ∘ f) pushˡ {f = f} = begin c ∘ f ↓⟨ ∘-resp-≡ˡ c≡ab ⟩ (a ∘ b) ∘ f ↓⟨ assoc ⟩ a ∘ (b ∘ f) ∎ where open HomReasoning open Pushes public module IntroElim {X} {a : X ⇒ X} (a≡id : a ≡ id) where .elimʳ : ∀ {W} {f : X ⇒ W} → (f ∘ a) ≡ f elimʳ {f = f} = begin f ∘ a ↓⟨ ∘-resp-≡ʳ a≡id ⟩ f ∘ id ↓⟨ identityʳ ⟩ f ∎ where open HomReasoning .introʳ : ∀ {W} {f : X ⇒ W} → f ≡ f ∘ a introʳ = Equiv.sym elimʳ .elimˡ : ∀ {W} {f : W ⇒ X} → (a ∘ f) ≡ f elimˡ {f = f} = begin a ∘ f ↓⟨ ∘-resp-≡ˡ a≡id ⟩ id ∘ f ↓⟨ identityˡ ⟩ f ∎ where open HomReasoning .introˡ : ∀ {W} {f : W ⇒ X} → f ≡ a ∘ f introˡ = Equiv.sym elimˡ open IntroElim public module Extends {X Y Z W} {f : X ⇒ Y} {g : X ⇒ Z} {h : Y ⇒ W} {i : Z ⇒ W} (s : CommutativeSquare f g h i) where .extendˡ : ∀ {A} {a : W ⇒ A} → CommutativeSquare f g (a ∘ h) (a ∘ i) extendˡ {a = a} = begin (a ∘ h) ∘ f ↓⟨ pullʳ s ⟩ a ∘ i ∘ g ↑⟨ assoc ⟩ (a ∘ i) ∘ g ∎ where open HomReasoning .extendʳ : ∀ {A} {a : A ⇒ X} → CommutativeSquare (f ∘ a) (g ∘ a) h i extendʳ {a = a} = begin h ∘ (f ∘ a) ↓⟨ pullˡ s ⟩ (i ∘ g) ∘ a ↓⟨ assoc ⟩ i ∘ (g ∘ a) ∎ where open HomReasoning .extend² : ∀ {A B} {a : W ⇒ A} {b : B ⇒ X} → CommutativeSquare (f ∘ b) (g ∘ b) (a ∘ h) (a ∘ i) extend² {a = a} {b} = begin (a ∘ h) ∘ (f ∘ b) ↓⟨ pullʳ extendʳ ⟩ a ∘ (i ∘ (g ∘ b)) ↑⟨ assoc ⟩ (a ∘ i) ∘ (g ∘ b) ∎ where open HomReasoning open Extends public -- essentially composition in the arrow category .glue : {X Y Y′ Z Z′ W : Obj} {a : Z ⇒ W} {a′ : Y′ ⇒ Z′} {b : Y ⇒ Z} {b′ : X ⇒ Y′} {c : X ⇒ Y} {c′ : Y′ ⇒ Z} {c″ : Z′ ⇒ W} → CommutativeSquare c′ a′ a c″ → CommutativeSquare c b′ b c′ → CommutativeSquare c (a′ ∘ b′) (a ∘ b) c″ glue {a = a} {a′} {b} {b′} {c} {c′} {c″} sq-a sq-b = begin (a ∘ b) ∘ c ↓⟨ pullʳ sq-b ⟩ a ∘ (c′ ∘ b′) ↓⟨ pullˡ sq-a ⟩ (c″ ∘ a′) ∘ b′ ↓⟨ assoc ⟩ c″ ∘ (a′ ∘ b′) ∎ where open HomReasoning .glue◃◽ : {X Y Y′ Z W : Obj} {a : Z ⇒ W} {b : Y ⇒ Z} {b′ : X ⇒ Y′} {c : X ⇒ Y} {c′ : Y′ ⇒ Z} {c″ : Y′ ⇒ W} → a ∘ c′ ≡ c″ → CommutativeSquare c b′ b c′ → CommutativeSquare c b′ (a ∘ b) c″ glue◃◽ {a = a} {b} {b′} {c} {c′} {c″} tri-a sq-b = begin (a ∘ b) ∘ c ↓⟨ pullʳ sq-b ⟩ a ∘ (c′ ∘ b′) ↓⟨ pullˡ tri-a ⟩ c″ ∘ b′ ∎ where open HomReasoning -- essentially composition in the over category .glueTrianglesʳ : ∀ {X X′ X″ Y} {a : X ⇒ Y} {b : X′ ⇒ X} {a′ : X′ ⇒ Y} {b′ : X″ ⇒ X′} {a″ : X″ ⇒ Y} → a ∘ b ≡ a′ → a′ ∘ b′ ≡ a″ → a ∘ (b ∘ b′) ≡ a″ glueTrianglesʳ {a = a} {b} {a′} {b′} {a″} a∘b≡a′ a′∘b′≡a″ = begin a ∘ (b ∘ b′) ↓⟨ pullˡ a∘b≡a′ ⟩ a′ ∘ b′ ↓⟨ a′∘b′≡a″ ⟩ a″ ∎ where open HomReasoning -- essentially composition in the under category .glueTrianglesˡ : ∀ {X Y Y′ Y″} {b : X ⇒ Y} {a : Y ⇒ Y′} {b′ : X ⇒ Y′} {a′ : Y′ ⇒ Y″} {b″ : X ⇒ Y″} → a′ ∘ b′ ≡ b″ → a ∘ b ≡ b′ → (a′ ∘ a) ∘ b ≡ b″ glueTrianglesˡ {b = b} {a} {b′} {a′} {b″} a′∘b′≡b″ a∘b≡b′ = begin (a′ ∘ a) ∘ b ↓⟨ pullʳ a∘b≡b′ ⟩ a′ ∘ b′ ↓⟨ a′∘b′≡b″ ⟩ b″ ∎ where open HomReasoning module Cancellers {Y Y′ : Obj} {h : Y′ ⇒ Y} {i : Y ⇒ Y′} (inv : h ∘ i ≡ id) where .cancelRight : ∀ {Z} {f : Y ⇒ Z} → (f ∘ h) ∘ i ≡ f cancelRight {f = f} = begin (f ∘ h) ∘ i ↓⟨ pullʳ inv ⟩ f ∘ id ↓⟨ identityʳ ⟩ f ∎ where open HomReasoning .cancelLeft : ∀ {X} {f : X ⇒ Y} → h ∘ (i ∘ f) ≡ f cancelLeft {f = f} = begin h ∘ (i ∘ f) ↓⟨ pullˡ inv ⟩ id ∘ f ↓⟨ identityˡ ⟩ f ∎ where open HomReasoning .cancelInner : ∀ {X Z} {f : Y ⇒ Z} {g : X ⇒ Y} → (f ∘ h) ∘ (i ∘ g) ≡ f ∘ g cancelInner {f = f} {g} = begin (f ∘ h) ∘ (i ∘ g) ↓⟨ pullˡ cancelRight ⟩ f ∘ g ∎ where open HomReasoning open Cancellers public module Switch {X Y} (i : X ≅ Y) where open _≅_ i .switch-fgˡ : ∀ {W} {h : W ⇒ X} {k : W ⇒ Y} → (f ∘ h ≡ k) → (h ≡ g ∘ k) switch-fgˡ {h = h} {k} pf = begin h ↑⟨ cancelLeft isoˡ ⟩ g ∘ (f ∘ h) ↓⟨ ∘-resp-≡ʳ pf ⟩ g ∘ k ∎ where open HomReasoning .switch-gfˡ : ∀ {W} {h : W ⇒ Y} {k : W ⇒ X} → (g ∘ h ≡ k) → (h ≡ f ∘ k) switch-gfˡ {h = h} {k} pf = begin h ↑⟨ cancelLeft isoʳ ⟩ f ∘ (g ∘ h) ↓⟨ ∘-resp-≡ʳ pf ⟩ f ∘ k ∎ where open HomReasoning .switch-fgʳ : ∀ {W} {h : Y ⇒ W} {k : X ⇒ W} → (h ∘ f ≡ k) → (h ≡ k ∘ g) switch-fgʳ {h = h} {k} pf = begin h ↑⟨ cancelRight isoʳ ⟩ (h ∘ f) ∘ g ↓⟨ ∘-resp-≡ˡ pf ⟩ k ∘ g ∎ where open HomReasoning .switch-gfʳ : ∀ {W} {h : X ⇒ W} {k : Y ⇒ W} → (h ∘ g ≡ k) → (h ≡ k ∘ f) switch-gfʳ {h = h} {k} pf = begin h ↑⟨ cancelRight isoˡ ⟩ (h ∘ g) ∘ f ↓⟨ ∘-resp-≡ˡ pf ⟩ k ∘ f ∎ where open HomReasoning open Switch public module Yon-Eda {o ℓ e} (C : Category o ℓ e) where private module C = Category C open C open Equiv record Yon (X Y : Obj) : Set (o ⊔ ℓ ⊔ e) where field arr : X ⇒ Y fun : ∀ {W} (f : W ⇒ X) → (W ⇒ Y) .ok : ∀ {W} (f : W ⇒ X) → fun f ≡ arr ∘ f norm : X ⇒ Y norm = fun id .norm≡arr : norm ≡ arr norm≡arr = trans (ok id) identityʳ record _≡′_ {X Y : Obj} (f g : Yon X Y) : Set (o ⊔ ℓ ⊔ e) where constructor yeq field arr-≡ : Yon.arr f ≡ Yon.arr g open _≡′_ public using (arr-≡) module _ {X Y} where .Yon-refl : Reflexive (_≡′_ {X} {Y}) Yon-refl = yeq refl .Yon-sym : Symmetric (_≡′_ {X} {Y}) Yon-sym = yeq © sym © arr-≡ .Yon-trans : Transitive (_≡′_ {X} {Y}) Yon-trans eq eq′ = yeq (trans (arr-≡ eq) (arr-≡ eq′)) Yon-id : ∀ {X} → Yon X X Yon-id = record { arr = id ; fun = idᶠ ; ok = λ _ → sym identityˡ } Yon-inject : ∀ {X Y} → (X ⇒ Y) → Yon X Y Yon-inject f = record { arr = f; fun = _∘_ f; ok = λ _ → refl } Yon-compose : ∀ {X Y Z} → (Yon Y Z) → (Yon X Y) → (Yon X Z) Yon-compose g f = record { arr = g.fun f.arr ; fun = g.fun © f.fun ; ok = λ h → trans (g.ok (f.fun h)) (trans (∘-resp-≡ʳ (f.ok h)) (trans (sym assoc) (sym (∘-resp-≡ˡ (g.ok f.arr))))) } where module g = Yon g module f = Yon f .Yon-assoc : ∀ {X Y Z W} (f : Yon Z W) (g : Yon Y Z) (h : Yon X Y) → Yon-compose f (Yon-compose g h) ≣ Yon-compose (Yon-compose f g) h Yon-assoc f g h = ≣-refl .Yon-identityˡ : ∀ {X Y} (f : Yon X Y) → Yon-compose Yon-id f ≣ f Yon-identityˡ f = ≣-refl .Yon-identityʳ : ∀ {X Y} (f : Yon X Y) → Yon-compose f Yon-id ≡′ f Yon-identityʳ f = yeq (Yon.norm≡arr f) .Yon-compose-resp-≡′ : ∀ {X Y Z} {f f′ : Yon Y Z} {g g′ : Yon X Y} → f ≡′ f′ → g ≡′ g′ → Yon-compose f g ≡′ Yon-compose f′ g′ Yon-compose-resp-≡′ {f = f} {f′} {g} {g′} f≡′f′ g≡′g′ = yeq (trans (Yon.ok f (Yon.arr g)) (trans (∘-resp-≡ (arr-≡ f≡′f′) (arr-≡ g≡′g′)) (sym (Yon.ok f′ (Yon.arr g′))))) record Eda (X Y : Obj) : Set (o ⊔ ℓ ⊔ e) where field yon : Yon X Y fun : ∀ {Z} (f : Yon Y Z) → Yon X Z .ok : ∀ {Z} (f : Yon Y Z) → fun f ≡′ Yon-compose f yon norm : Yon X Y norm = fun Yon-id open Yon yon public using (arr) Eda-id : ∀ {X} → Eda X X Eda-id = record { yon = Yon-id ; fun = idᶠ ; ok = yeq © sym © arr-≡ © Yon-identityʳ } Eda-inject : ∀ {X Y} → Yon X Y → Eda X Y Eda-inject f = record { yon = f; fun = flip Yon-compose f; ok = λ _ → yeq refl } Eda-compose : ∀ {X Y Z} → (Eda Y Z) → (Eda X Y) → (Eda X Z) Eda-compose {X} {Y} {Z} g f = record { yon = f.fun g.yon ; fun = f.fun © g.fun ; ok = λ {W} h → Yon-trans {X} {W} {f.fun (g.fun h)} (f.ok (g.fun h)) (Yon-trans (Yon-compose-resp-≡′ (g.ok h) (Yon-refl {x = f.yon})) (Yon-sym (Yon-compose-resp-≡′ (Yon-refl {x = h}) (f.ok g.yon)))) } where module g = Eda g module f = Eda f .Eda-assoc : ∀ {X Y Z W} (f : Eda Z W) (g : Eda Y Z) (h : Eda X Y) → Eda-compose f (Eda-compose g h) ≣ Eda-compose (Eda-compose f g) h Eda-assoc f g h = ≣-refl -- .Eda-identityˡ : ∀ {X Y} (f : Eda X Y) → Eda-compose Eda-id f ≣ f -- Eda-identityˡ f = {!!} .Eda-identityʳ : ∀ {X Y} (f : Eda X Y) → Eda-compose f Eda-id ≣ f Eda-identityʳ f = ≣-refl record NormReasoning {o ℓ e} (C : Category o ℓ e) (o′ ℓ′ : _) : Set (suc o′ ⊔ o ⊔ ℓ ⊔ e ⊔ suc ℓ′) where private module C = Category C field U : Set o′ T : U -> C.Obj _#⇒_ : U -> U -> Set ℓ′ eval : ∀ {A B} -> A #⇒ B -> T A C.⇒ T B norm : ∀ {A B} -> A #⇒ B -> T A C.⇒ T B .norm≡eval : ∀ {A B} (f : A #⇒ B) -> norm f C.≡ eval f open C.Equiv open C infix 4 _IsRelatedTo_ infix 1 begin_ infixr 2 _≈⟨_⟩_ _↓⟨_⟩_ _↑⟨_⟩_ _↓≡⟨_⟩_ _↑≡⟨_⟩_ _↕_ infix 3 _∎ data _IsRelatedTo_ {X Y} (f g : _#⇒_ X Y) : Set e where relTo : (f∼g : norm f ≡ norm g) → f IsRelatedTo g .begin_ : ∀ {X Y} {f g : _#⇒_ X Y} → f IsRelatedTo g → eval f ≡ eval g begin_ {f = f} {g} (relTo f∼g) = trans (sym (norm≡eval f)) (trans f∼g (norm≡eval g)) ._↓⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → (norm f ≡ norm g) → g IsRelatedTo h → f IsRelatedTo h _ ↓⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h) ._↑⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → (norm g ≡ norm f) → g IsRelatedTo h → f IsRelatedTo h _ ↑⟨ g∼f ⟩ relTo g∼h = relTo (trans (sym g∼f) g∼h) -- the syntax of the ancients, for compatibility ._≈⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → (norm f ≡ norm g) → g IsRelatedTo h → f IsRelatedTo h _ ≈⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h) ._↓≡⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → eval f ≡ eval g → g IsRelatedTo h → f IsRelatedTo h _↓≡⟨_⟩_ f {g} f∼g (relTo g∼h) = relTo (trans (norm≡eval f) (trans f∼g (trans (sym (norm≡eval g)) g∼h))) ._↑≡⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → eval g ≡ eval f → g IsRelatedTo h → f IsRelatedTo h _↑≡⟨_⟩_ f {g} g∼f (relTo g∼h) = relTo (trans (norm≡eval f) (trans (sym g∼f) (trans (sym (norm≡eval g)) g∼h))) ._↕_ : ∀ {X Y} (f : _#⇒_ X Y) {h} → f IsRelatedTo h → f IsRelatedTo h _ ↕ f∼h = f∼h ._∎ : ∀ {X Y} (f : _#⇒_ X Y) → f IsRelatedTo f _∎ _ = relTo refl .by_ : ∀ {X Y} {f g h : X ⇒ Y} -> ((h ≡ h) -> f ≡ g) -> f ≡ g by eq = eq refl .computation : ∀ {X Y} (f g : X #⇒ Y) -> norm f ≡ norm g → eval f ≡ eval g computation f g eq = begin f ↓⟨ eq ⟩ g ∎ module AUReasoning {o ℓ e} (C : Category o ℓ e) where private module C = Category C open C open Equiv {- infix 4 _IsRelatedTo_ infix 2 _∎ infixr 2 _≈⟨_⟩_ infixr 2 _↓⟨_⟩_ infixr 2 _↑⟨_⟩_ infixr 2 _↓≡⟨_⟩_ infixr 2 _↑≡⟨_⟩_ infixr 2 _↕_ infix 1 begin_ -} infixr 8 _∙_ open Yon-Eda C public data Climb : Rel Obj (o ⊔ ℓ) where ID : ∀ {X} → Climb X X leaf : ∀ {X Y} → (X ⇒ Y) → Climb X Y _branch_ : ∀ {X Y Z} (l : Climb Y Z) (r : Climb X Y) → Climb X Z interp : ∀ {p} (P : Rel Obj p) (f-id : ∀ {X} → P X X) (f-leaf : ∀ {X Y} → X ⇒ Y → P X Y) (f-branch : ∀ {X Y Z} → P Y Z → P X Y → P X Z) → ∀ {X Y} → Climb X Y → P X Y interp P f-id f-leaf f-branch ID = f-id interp P f-id f-leaf f-branch (leaf y) = f-leaf y interp P f-id f-leaf f-branch (l branch r) = f-branch (interp P f-id f-leaf f-branch l) (interp P f-id f-leaf f-branch r) eval : ∀ {X Y} → Climb X Y → X ⇒ Y eval = interp _⇒_ id idᶠ _∘_ yeval : ∀ {X Y} → Climb X Y → Yon X Y yeval = interp Yon Yon-id Yon-inject Yon-compose .yarr : ∀ {X Y} → (t : Climb X Y) → Yon.arr (yeval t) ≡ eval t yarr ID = refl yarr (leaf y) = refl yarr (t branch t1) = trans (Yon.ok (yeval t) (Yon.arr (yeval t1))) (∘-resp-≡ (yarr t) (yarr t1)) eeval : ∀ {X Y} → Climb X Y → Eda X Y eeval = interp Eda Eda-id (Eda-inject © Yon-inject) Eda-compose .eyon : ∀ {X Y} → (t : Climb X Y) → Eda.yon (eeval t) ≡′ yeval t eyon ID = Yon-refl eyon (leaf y) = Yon-refl eyon (t branch t1) = Yon-trans (Eda.ok (eeval t1) (Eda.yon (eeval t))) (Yon-compose-resp-≡′ (eyon t) (eyon t1)) .earr : ∀ {X Y} → (t : Climb X Y) → Eda.arr (eeval t) ≡ eval t earr t = trans (arr-≡ (eyon t)) (yarr t) yyeval : ∀ {X Y} → (t : Climb X Y) → (X ⇒ Y) yyeval = Eda.arr © eeval record ClimbBuilder (X Y : Obj) {t} (T : Set t) : Set (o ⊔ ℓ ⊔ t) where field build : T → Climb X Y instance leafBuilder : ∀ {X Y} → ClimbBuilder X Y (X ⇒ Y) leafBuilder = record { build = leaf } idBuilder : ∀ {X Y} → ClimbBuilder X Y (Climb X Y) idBuilder = record { build = idᶠ } _∙_ : ∀ {X Y Z} {s} {S : Set s} {{Sb : ClimbBuilder Y Z S}} (f : S) {t} {T : Set t} {{Tb : ClimbBuilder X Y T}} (g : T) → Climb X Z _∙_ {{Sb}} f {{Tb}} g = ClimbBuilder.build Sb f branch ClimbBuilder.build Tb g aureasoning : NormReasoning C o (ℓ ⊔ o) aureasoning = record { U = Obj ; T = λ A → A ; _#⇒_ = Climb ; eval = eval ; norm = yyeval ; norm≡eval = earr } open NormReasoning aureasoning public hiding (eval) {- data _IsRelatedTo_ {X Y} (f g : Climb X Y) : Set e where relTo : (f∼g : yyeval f ≡ yyeval g) → f IsRelatedTo g .begin_ : ∀ {X Y} {f g : Climb X Y} → f IsRelatedTo g → eval f ≡ eval g begin_ {f = f} {g} (relTo f∼g) = trans (sym (earr f)) (trans f∼g (earr g)) ._↓⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → (yyeval f ≡ yyeval g) → g IsRelatedTo h → f IsRelatedTo h _ ↓⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h) ._↑⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → (yyeval g ≡ yyeval f) → g IsRelatedTo h → f IsRelatedTo h _ ↑⟨ g∼f ⟩ relTo g∼h = relTo (trans (sym g∼f) g∼h) -- the syntax of the ancients, for compatibility ._≈⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → (yyeval f ≡ yyeval g) → g IsRelatedTo h → f IsRelatedTo h _ ≈⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h) ._↓≡⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → eval f ≡ eval g → g IsRelatedTo h → f IsRelatedTo h _↓≡⟨_⟩_ f {g} f∼g (relTo g∼h) = relTo (trans (earr f) (trans f∼g (trans (sym (earr g)) g∼h))) ._↑≡⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → eval g ≡ eval f → g IsRelatedTo h → f IsRelatedTo h _↑≡⟨_⟩_ f {g} g∼f (relTo g∼h) = relTo (trans (earr f) (trans (sym g∼f) (trans (sym (earr g)) g∼h))) {- -- XXX i want this to work whenever the Edas are equal -- but that probably -- requires Climb to be indexed by yyeval! oh, for cheap ornamentation. ._↕_ : ∀ {X Y} (f : Climb X Y) {h} → f IsRelatedTo h → f IsRelatedTo h _ ↕ f∼h = f∼h -} ._∎ : ∀ {X Y} (f : Climb X Y) → f IsRelatedTo f _∎ _ = relTo refl -}
29.384892
228
0.464561
7ce23621f54753a491c719b9d935132bc9ed6f55
2,513
agda
Agda
examples/outdated-and-incorrect/Alonzo/PrintFloat.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/Alonzo/PrintFloat.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/Alonzo/PrintFloat.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module PrintFloat where import AlonzoPrelude import PreludeShow import PreludeList import PreludeString import PreludeNat open AlonzoPrelude open PreludeShow open PreludeList, hiding(_++_) open PreludeString open PreludeNat typeS : Char -> Set typeS 'f' = Float show : (c : Char) -> (typeS c) -> String show 'f' f = showFloat f data Unit : Set where unit : Unit data Format : Set where stringArg : Format natArg : Format intArg : Format floatArg : Format charArg : Format litChar : Char -> Format badFormat : Char -> Format data BadFormat (c:Char) : Set where format' : List Char -> List Format format' ('%' :: 's' :: fmt) = stringArg :: format' fmt format' ('%' :: 'n' :: fmt) = natArg :: format' fmt -- format' ('%' :: 'd' :: fmt) = intArg :: format' fmt format' ('%' :: 'f' :: fmt) = floatArg :: format' fmt format' ('%' :: 'c' :: fmt) = charArg :: format' fmt format' ('%' :: '%' :: fmt) = litChar '%' :: format' fmt format' ('%' :: c :: fmt) = badFormat c :: format' fmt format' (c :: fmt) = litChar c :: format' fmt format' [] = [] format : String -> List Format format s = format' (toList s) -- Printf1 : Format -> Set -- Printf1 floatArg = Float Printf' : List Format -> Set Printf' (stringArg :: fmt) = String × Printf' fmt Printf' (natArg :: fmt) = Nat × Printf' fmt Printf' (intArg :: fmt) = Int × Printf' fmt Printf' (floatArg :: fmt) = Float × Printf' fmt Printf' (charArg :: fmt) = Char × Printf' fmt Printf' (badFormat c :: fmt) = BadFormat c Printf' (litChar _ :: fmt) = Printf' fmt Printf' [] = Unit × Unit Printf : String -> Set Printf fmt = Printf' (format fmt) printf' : (fmt : List Format) -> Printf' fmt -> String printf' (stringArg :: fmt) < s | args > = s ++ printf' fmt args printf' (natArg :: fmt) < n | args > = showNat n ++ printf' fmt args printf' (intArg :: fmt) < n | args > = showInt n ++ printf' fmt args printf' (floatArg :: fmt) < x | args > = showFloat x ++ printf' fmt args printf' (charArg :: fmt) < c | args > = showChar c ++ printf' fmt args printf' (litChar c :: fmt) args = fromList (c :: []) ++ printf' fmt args printf' (badFormat _ :: fmt) () printf' [] < unit | unit > = "" printf : (fmt : String) -> Printf fmt -> String printf fmt = printf' (format fmt) -- mainS = show 'f' 3.14 -- mainS = printf' (format "%f") < 3.14 | < unit | unit > > mainS = printf "pi = %f" < 3.14159 | < unit | unit > > -- mainS = fromList ( 'p' :: [] )
30.646341
75
0.58655
fd4e874e5aa54c60922e729f5fee5844697c4be2
25,190
agda
Agda
Cubical/Algebra/CommRing/Localisation/InvertingElements.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/InvertingElements.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/InvertingElements.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
-- In this file we consider the special of localising at a single -- element f : R (or rather the set of powers of f). This is also -- known as inverting f. -- We then prove that localising first at an element f and at an element -- g (or rather the image g/1) is the same as localising at the product f·g -- This fact has an important application in algebraic geometry where it's -- used to define the structure sheaf of a commutative ring. {-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-} module Cubical.Algebra.CommRing.Localisation.InvertingElements where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset open import Cubical.Foundations.Transport open import Cubical.Functions.FunExtEquiv import Cubical.Data.Empty as ⊥ open import Cubical.Data.Bool open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Data.Nat.Order open import Cubical.Data.Vec open import Cubical.Data.Sigma.Base open import Cubical.Data.Sigma.Properties open import Cubical.Data.FinData open import Cubical.Relation.Nullary open import Cubical.Relation.Binary open import Cubical.Algebra.Group open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Localisation.Base open import Cubical.Algebra.CommRing.Localisation.UniversalProperty open import Cubical.Algebra.RingSolver.ReflectionSolving open import Cubical.HITs.SetQuotients as SQ open import Cubical.HITs.PropositionalTruncation as PT open Iso private variable ℓ ℓ' : Level A : Type ℓ module _(R' : CommRing {ℓ}) where open isMultClosedSubset private R = fst R' open CommRingStr (snd R') open Exponentiation R' [_ⁿ|n≥0] : R → ℙ R [ f ⁿ|n≥0] g = (∃[ n ∈ ℕ ] g ≡ f ^ n) , propTruncIsProp -- Σ[ n ∈ ℕ ] (s ≡ f ^ n) × (∀ m → s ≡ f ^ m → n ≤ m) maybe better, this isProp: -- (n,s≡fⁿ,p) (m,s≡fᵐ,q) then n≤m by p and m≤n by q => n≡m powersFormMultClosedSubset : (f : R) → isMultClosedSubset R' [ f ⁿ|n≥0] powersFormMultClosedSubset f .containsOne = PT.∣ zero , refl ∣ powersFormMultClosedSubset f .multClosed = PT.map2 λ (m , p) (n , q) → (m +ℕ n) , (λ i → (p i) · (q i)) ∙ ·-of-^-is-^-of-+ f m n R[1/_] : R → Type ℓ R[1/ f ] = Loc.S⁻¹R R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f) R[1/_]AsCommRing : R → CommRing {ℓ} R[1/ f ]AsCommRing = Loc.S⁻¹RAsCommRing R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f) -- A useful lemma: (gⁿ/1)≡(g/1)ⁿ in R[1/f] ^-respects-/1 : {f g : R} (n : ℕ) → [ (g ^ n) , 1r , PT.∣ 0 , (λ _ → 1r) ∣ ] ≡ Exponentiation._^_ R[1/ f ]AsCommRing [ g , 1r , powersFormMultClosedSubset _ .containsOne ] n ^-respects-/1 zero = refl ^-respects-/1 {f} {g} (suc n) = eq/ _ _ ( (1r , powersFormMultClosedSubset f .containsOne) , cong (1r · (g · (g ^ n)) ·_) (·Lid 1r)) ∙ cong (CommRingStr._·_ (R[1/ f ]AsCommRing .snd) [ g , 1r , powersFormMultClosedSubset f .containsOne ]) (^-respects-/1 n) -- A slight improvement for eliminating into propositions InvElPropElim : {f : R} {P : R[1/ f ] → Type ℓ'} → (∀ x → isProp (P x)) → (∀ (r : R) (n : ℕ) → P [ r , (f ^ n) , PT.∣ n , refl ∣ ]) -- ∀ r n → P (r/fⁿ) ---------------------------------------------------------- → (∀ x → P x) InvElPropElim {f = f} {P = P} PisProp base = elimProp (λ _ → PisProp _) []-case where S[f] = Loc.S R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f) []-case : (a : R × S[f]) → P [ a ] []-case (r , s , s∈S[f]) = PT.rec (PisProp _) Σhelper s∈S[f] where Σhelper : Σ[ n ∈ ℕ ] s ≡ f ^ n → P [ r , s , s∈S[f] ] Σhelper (n , p) = subst P (cong [_] (≡-× refl (Σ≡Prop (λ _ → propTruncIsProp) (sym p)))) (base r n) -- For predicates over the set of powers powersPropElim : {f : R} {P : R → Type ℓ'} → (∀ x → isProp (P x)) → (∀ n → P (f ^ n)) ------------------------------ → ∀ s → s ∈ [ f ⁿ|n≥0] → P s powersPropElim {f = f} {P = P} PisProp base s = PT.rec (PisProp s) λ (n , p) → subst P (sym p) (base n) module DoubleLoc (R' : CommRing {ℓ}) (f g : (fst R')) where open isMultClosedSubset open CommRingStr (snd R') open CommTheory R' open Exponentiation R' open Theory (CommRing→Ring R') open CommRingStr (snd (R[1/_]AsCommRing R' f)) renaming ( _·_ to _·ᶠ_ ; 1r to 1ᶠ ; _+_ to _+ᶠ_ ; 0r to 0ᶠ ; ·Lid to ·ᶠ-lid ; ·Rid to ·ᶠ-rid ; ·Assoc to ·ᶠ-assoc ; ·-comm to ·ᶠ-comm) private R = fst R' R[1/f] = R[1/_] R' f R[1/f]AsCommRing = R[1/_]AsCommRing R' f R[1/fg] = R[1/_] R' (f · g) R[1/fg]AsCommRing = R[1/_]AsCommRing R' (f · g) R[1/f][1/g] = R[1/_] (R[1/_]AsCommRing R' f) [ g , 1r , powersFormMultClosedSubset R' f .containsOne ] R[1/f][1/g]AsCommRing = R[1/_]AsCommRing (R[1/_]AsCommRing R' f) [ g , 1r , powersFormMultClosedSubset R' f .containsOne ] R[1/f][1/g]ˣ = R[1/f][1/g]AsCommRing ˣ _/1/1 : R → R[1/f][1/g] r /1/1 = [ [ r , 1r , PT.∣ 0 , refl ∣ ] , 1ᶠ , PT.∣ 0 , refl ∣ ] /1/1AsCommRingHom : CommRingHom R' R[1/f][1/g]AsCommRing RingHom.f /1/1AsCommRingHom = _/1/1 RingHom.pres1 /1/1AsCommRingHom = refl RingHom.isHom+ /1/1AsCommRingHom r r' = cong [_] (≡-× (cong [_] (≡-× (cong₂ _+_ (sym (·Rid _) ∙ (λ i → (·Rid r (~ i)) · (·Rid 1r (~ i)))) (sym (·Rid _) ∙ (λ i → (·Rid r' (~ i)) · (·Rid 1r (~ i))))) (Σ≡Prop (λ _ → propTruncIsProp) (sym (·Lid _) ∙ (λ i → (·Lid 1r (~ i)) · (·Lid 1r (~ i))))))) (Σ≡Prop (λ _ → propTruncIsProp) (sym (·ᶠ-lid 1ᶠ)))) RingHom.isHom· /1/1AsCommRingHom r r' = cong [_] (≡-× (cong [_] (≡-× refl (Σ≡Prop (λ _ → propTruncIsProp) (sym (·Lid _))))) (Σ≡Prop (λ _ → propTruncIsProp) (sym (·ᶠ-lid 1ᶠ)))) -- this will give us a map R[1/fg] → R[1/f][1/g] by the universal property of localisation fⁿgⁿ/1/1∈R[1/f][1/g]ˣ : (s : R) → s ∈ ([_ⁿ|n≥0] R' (f · g)) → s /1/1 ∈ R[1/f][1/g]ˣ fⁿgⁿ/1/1∈R[1/f][1/g]ˣ = powersPropElim R' (λ s → R[1/f][1/g]ˣ (s /1/1) .snd) ℕcase where ℕcase : (n : ℕ) → ((f · g) ^ n) /1/1 ∈ R[1/f][1/g]ˣ ℕcase n = [ [ 1r , (f ^ n) , PT.∣ n , refl ∣ ] , [ (g ^ n) , 1r , PT.∣ 0 , refl ∣ ] --denominator , PT.∣ n , ^-respects-/1 _ n ∣ ] , eq/ _ _ ((1ᶠ , powersFormMultClosedSubset _ _ .containsOne) , eq/ _ _ ((1r , powersFormMultClosedSubset _ _ .containsOne) , path)) where eq1 : ∀ x → 1r · (1r · (x · 1r) · 1r) · (1r · 1r · (1r · 1r)) ≡ x eq1 = solve R' eq2 : ∀ x y → x · y ≡ 1r · (1r · 1r · (1r · y)) · (1r · (1r · x) · 1r) eq2 = solve R' path : 1r · (1r · ((f · g) ^ n · 1r) · 1r) · (1r · 1r · (1r · 1r)) ≡ 1r · (1r · 1r · (1r · g ^ n)) · (1r · (1r · f ^ n) · 1r) path = 1r · (1r · ((f · g) ^ n · 1r) · 1r) · (1r · 1r · (1r · 1r)) ≡⟨ eq1 ((f · g) ^ n) ⟩ (f · g) ^ n ≡⟨ ^-ldist-· _ _ _ ⟩ f ^ n · g ^ n ≡⟨ eq2 (f ^ n) (g ^ n) ⟩ 1r · (1r · 1r · (1r · g ^ n)) · (1r · (1r · f ^ n) · 1r) ∎ -- the main result: localising at one element and then at another is -- the same as localising at the product. -- takes forever to compute without experimental lossy unification R[1/fg]≡R[1/f][1/g] : R[1/fg]AsCommRing ≡ R[1/f][1/g]AsCommRing R[1/fg]≡R[1/f][1/g] = S⁻¹RChar R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) _ /1/1AsCommRingHom pathtoR[1/fg] where open PathToS⁻¹R pathtoR[1/fg] : PathToS⁻¹R R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) R[1/f][1/g]AsCommRing /1/1AsCommRingHom φS⊆Aˣ pathtoR[1/fg] = fⁿgⁿ/1/1∈R[1/f][1/g]ˣ kerφ⊆annS pathtoR[1/fg] r p = toGoal helperR[1/f] where open Theory (CommRing→Ring R[1/f]AsCommRing) renaming ( 0RightAnnihilates to 0ᶠRightAnnihilates ; 0LeftAnnihilates to 0ᶠ-leftNullifies) open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^ᶠ_) hiding (·-of-^-is-^-of-+ ; ^-ldist-·) S[f] = Loc.S R' ([_ⁿ|n≥0] R' f) (powersFormMultClosedSubset R' f) S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) g/1 : R[1/_] R' f g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ] S[g/1] = Loc.S R[1/f]AsCommRing ([_ⁿ|n≥0] R[1/f]AsCommRing g/1) (powersFormMultClosedSubset R[1/f]AsCommRing g/1) r/1 : R[1/_] R' f r/1 = [ r , 1r , powersFormMultClosedSubset R' f .containsOne ] -- this is the crucial step, modulo truncation we can take p to be generated -- by the quotienting relation of localisation. Note that we wouldn't be able -- to prove our goal if kerφ⊆annS was formulated with a Σ instead of a ∃ ∥r/1,1/1≈0/1,1/1∥ : ∃[ u ∈ S[g/1] ] fst u ·ᶠ r/1 ·ᶠ 1ᶠ ≡ fst u ·ᶠ 0ᶠ ·ᶠ 1ᶠ ∥r/1,1/1≈0/1,1/1∥ = Iso.fun (SQ.isEquivRel→TruncIso (Loc.locIsEquivRel _ _ _) _ _) p helperR[1/f] : ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ helperR[1/f] = PT.rec propTruncIsProp (uncurry (uncurry (powersPropElim R[1/f]AsCommRing (λ _ → isPropΠ (λ _ → propTruncIsProp)) baseCase))) ∥r/1,1/1≈0/1,1/1∥ where baseCase : ∀ n → g/1 ^ᶠ n ·ᶠ r/1 ·ᶠ 1ᶠ ≡ g/1 ^ᶠ n ·ᶠ 0ᶠ ·ᶠ 1ᶠ → ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ baseCase n q = PT.∣ n , path ∣ where path : [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ path = [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡⟨ cong [_] (≡-× refl (Σ≡Prop (λ _ → propTruncIsProp) (sym (·Rid _)))) ⟩ [ g ^ n , 1r , PT.∣ 0 , refl ∣ ] ·ᶠ r/1 ≡⟨ cong (_·ᶠ r/1) (^-respects-/1 _ n) ⟩ g/1 ^ᶠ n ·ᶠ r/1 ≡⟨ sym (·ᶠ-rid _) ⟩ g/1 ^ᶠ n ·ᶠ r/1 ·ᶠ 1ᶠ ≡⟨ q ⟩ g/1 ^ᶠ n ·ᶠ 0ᶠ ·ᶠ 1ᶠ ≡⟨ cong (_·ᶠ 1ᶠ) (0ᶠRightAnnihilates _) ∙ 0ᶠ-leftNullifies 1ᶠ ⟩ 0ᶠ ∎ toGoal : ∃[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ → ∃[ u ∈ S[fg] ] fst u · r ≡ 0r toGoal = PT.rec propTruncIsProp Σhelper where Σhelper : Σ[ n ∈ ℕ ] [ g ^ n · r , 1r , PT.∣ 0 , refl ∣ ] ≡ 0ᶠ → ∃[ u ∈ S[fg] ] fst u · r ≡ 0r Σhelper (n , q) = PT.map Σhelper2 helperR where -- now, repeat the above strategy with q ∥gⁿr≈0∥ : ∃[ u ∈ S[f] ] fst u · (g ^ n · r) · 1r ≡ fst u · 0r · 1r ∥gⁿr≈0∥ = Iso.fun (SQ.isEquivRel→TruncIso (Loc.locIsEquivRel _ _ _) _ _) q helperR : ∃[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r helperR = PT.rec propTruncIsProp (uncurry (uncurry (powersPropElim R' (λ _ → isPropΠ (λ _ → propTruncIsProp)) baseCase))) ∥gⁿr≈0∥ where baseCase : (m : ℕ) → f ^ m · (g ^ n · r) · 1r ≡ f ^ m · 0r · 1r → ∃[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r baseCase m q' = PT.∣ m , path ∣ where path : f ^ m · g ^ n · r ≡ 0r path = (λ i → ·Rid (·Assoc (f ^ m) (g ^ n) r (~ i)) (~ i)) ∙∙ q' ∙∙ (λ i → ·Rid (0RightAnnihilates (f ^ m) i) i) Σhelper2 : Σ[ m ∈ ℕ ] f ^ m · g ^ n · r ≡ 0r → Σ[ u ∈ S[fg] ] fst u · r ≡ 0r Σhelper2 (m , q') = (((f · g) ^ l) , PT.∣ l , refl ∣) , path where l = max m n path : (f · g) ^ l · r ≡ 0r path = (f · g) ^ l · r ≡⟨ cong (_· r) (^-ldist-· _ _ _) ⟩ f ^ l · g ^ l · r ≡⟨ cong₂ (λ x y → f ^ x · g ^ y · r) (sym (≤-∸-+-cancel {m = m} left-≤-max)) (sym (≤-∸-+-cancel {m = n} right-≤-max)) ⟩ f ^ (l ∸ m +ℕ m) · g ^ (l ∸ n +ℕ n) · r ≡⟨ cong₂ (λ x y → x · y · r) (sym (·-of-^-is-^-of-+ _ _ _)) (sym (·-of-^-is-^-of-+ _ _ _)) ⟩ f ^ (l ∸ m) · f ^ m · (g ^ (l ∸ n) · g ^ n) · r ≡⟨ cong (_· r) (·-commAssocSwap _ _ _ _) ⟩ f ^ (l ∸ m) · g ^ (l ∸ n) · (f ^ m · g ^ n) · r ≡⟨ sym (·Assoc _ _ _) ⟩ f ^ (l ∸ m) · g ^ (l ∸ n) · (f ^ m · g ^ n · r) ≡⟨ cong (f ^ (l ∸ m) · g ^ (l ∸ n) ·_) q' ⟩ f ^ (l ∸ m) · g ^ (l ∸ n) · 0r ≡⟨ 0RightAnnihilates _ ⟩ 0r ∎ surχ pathtoR[1/fg] = InvElPropElim _ (λ _ → propTruncIsProp) toGoal where open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^ᶠ_) hiding (·-of-^-is-^-of-+ ; ^-ldist-·) open CommRingStr (snd R[1/f][1/g]AsCommRing) renaming (_·_ to _·R[1/f][1/g]_) hiding (1r ; ·Lid ; ·Rid ; ·Assoc) open Units R[1/f][1/g]AsCommRing g/1 : R[1/_] R' f g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ] S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) baseCase : (r : R) (m n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1) ≡ [ [ r , f ^ m , PT.∣ m , refl ∣ ] , [ g ^ n , 1r , PT.∣ 0 , refl ∣ ] , PT.∣ n , ^-respects-/1 _ n ∣ ] ·R[1/f][1/g] (x .snd .fst /1/1) baseCase r m n = PT.∣ ((r · f ^ (l ∸ m) · g ^ (l ∸ n)) -- x .fst , (f · g) ^ l , PT.∣ l , refl ∣) -- x .snd , eq/ _ _ ((1ᶠ , PT.∣ 0 , refl ∣) , eq/ _ _ ((1r , PT.∣ 0 , refl ∣) , path)) ∣ -- reduce equality of double fractions into equality in R where eq1 : ∀ r flm gln gn fm → 1r · (1r · (r · flm · gln) · (gn · 1r)) · (1r · (fm · 1r) · 1r) ≡ r · flm · (gln · gn) · fm eq1 = solve R' eq2 : ∀ r flm gl fm → r · flm · gl · fm ≡ r · (flm · fm ) · gl eq2 = solve R' eq3 : ∀ r fgl → r · fgl ≡ 1r · (1r · (r · fgl) · 1r) · (1r · 1r · (1r · 1r)) eq3 = solve R' l = max m n path : 1r · (1r · (r · f ^ (l ∸ m) · g ^ (l ∸ n)) · (g ^ n · 1r)) · (1r · (f ^ m · 1r) · 1r) ≡ 1r · (1r · (r · (f · g) ^ l) · 1r) · (1r · 1r · (1r · 1r)) path = 1r · (1r · (r · f ^ (l ∸ m) · g ^ (l ∸ n)) · (g ^ n · 1r)) · (1r · (f ^ m · 1r) · 1r) ≡⟨ eq1 r (f ^ (l ∸ m)) (g ^ (l ∸ n)) (g ^ n) (f ^ m) ⟩ r · f ^ (l ∸ m) · (g ^ (l ∸ n) · g ^ n) · f ^ m ≡⟨ cong (λ x → r · f ^ (l ∸ m) · x · f ^ m) (·-of-^-is-^-of-+ _ _ _) ⟩ r · f ^ (l ∸ m) · g ^ (l ∸ n +ℕ n) · f ^ m ≡⟨ cong (λ x → r · f ^ (l ∸ m) · g ^ x · f ^ m) (≤-∸-+-cancel right-≤-max) ⟩ r · f ^ (l ∸ m) · g ^ l · f ^ m ≡⟨ eq2 r (f ^ (l ∸ m)) (g ^ l) (f ^ m) ⟩ r · (f ^ (l ∸ m) · f ^ m) · g ^ l ≡⟨ cong (λ x → r · x · g ^ l) (·-of-^-is-^-of-+ _ _ _) ⟩ r · f ^ (l ∸ m +ℕ m) · g ^ l ≡⟨ cong (λ x → r · f ^ x · g ^ l) (≤-∸-+-cancel left-≤-max) ⟩ r · f ^ l · g ^ l ≡⟨ sym (·Assoc _ _ _) ⟩ r · (f ^ l · g ^ l) ≡⟨ cong (r ·_) (sym (^-ldist-· _ _ _)) ⟩ r · (f · g) ^ l ≡⟨ eq3 r ((f · g) ^ l) ⟩ 1r · (1r · (r · (f · g) ^ l) · 1r) · (1r · 1r · (1r · 1r)) ∎ base-^ᶠ-helper : (r : R) (m n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1) ≡ [ [ r , f ^ m , PT.∣ m , refl ∣ ] , g/1 ^ᶠ n , PT.∣ n , refl ∣ ] ·R[1/f][1/g] (x .snd .fst /1/1) base-^ᶠ-helper r m n = subst (λ y → ∃[ x ∈ R × S[fg] ] (x .fst /1/1) ≡ [ [ r , f ^ m , PT.∣ m , refl ∣ ] , y ] ·R[1/f][1/g] (x .snd .fst /1/1)) (Σ≡Prop (λ _ → propTruncIsProp) (^-respects-/1 _ n)) (baseCase r m n) indStep : (r : R[1/_] R' f) (n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1) ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ] ·R[1/f][1/g] (x .snd .fst /1/1) indStep = InvElPropElim _ (λ _ → isPropΠ λ _ → propTruncIsProp) base-^ᶠ-helper toGoal : (r : R[1/_] R' f) (n : ℕ) → ∃[ x ∈ R × S[fg] ] (x .fst /1/1) ·R[1/f][1/g] ((x .snd .fst /1/1) ⁻¹) ⦃ φS⊆Aˣ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) ⦄ ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ] toGoal r n = PT.map Σhelper (indStep r n) where Σhelper : Σ[ x ∈ R × S[fg] ] (x .fst /1/1) ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ] ·R[1/f][1/g] (x .snd .fst /1/1) → Σ[ x ∈ R × S[fg] ] (x .fst /1/1) ·R[1/f][1/g] ((x .snd .fst /1/1) ⁻¹) ⦃ φS⊆Aˣ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) ⦄ ≡ [ r , g/1 ^ᶠ n , PT.∣ n , refl ∣ ] Σhelper ((r' , s , s∈S[fg]) , p) = (r' , s , s∈S[fg]) , ⁻¹-eq-elim ⦃ φS⊆Aˣ pathtoR[1/fg] s s∈S[fg] ⦄ p -- In this module we construct the map R[1/fg]→R[1/f][1/g] directly -- and show that it is equal (although not judgementally) to the map induced -- by the universal property of localisation, i.e. transporting along the path -- constructed above. Given that this is the easier direction, we can see that -- it is pretty cumbersome to prove R[1/fg]≡R[1/f][1/g] directly, -- which illustrates the usefulness of S⁻¹RChar quite well. private module check where φ : R[1/fg] → R[1/f][1/g] φ = SQ.rec squash/ ϕ ϕcoh where S[fg] = Loc.S R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) curriedϕΣ : (r s : R) → Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n → R[1/f][1/g] curriedϕΣ r s (n , s≡fg^n) = [ [ r , (f ^ n) , PT.∣ n , refl ∣ ] , [ (g ^ n) , 1r , PT.∣ 0 , refl ∣ ] --denominator , PT.∣ n , ^-respects-/1 R' n ∣ ] curriedϕ : (r s : R) → ∃[ n ∈ ℕ ] s ≡ (f · g) ^ n → R[1/f][1/g] curriedϕ r s = elim→Set (λ _ → squash/) (curriedϕΣ r s) coh where coh : (x y : Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n) → curriedϕΣ r s x ≡ curriedϕΣ r s y coh (n , s≡fg^n) (m , s≡fg^m) = eq/ _ _ ((1ᶠ , PT.∣ 0 , refl ∣) , eq/ _ _ ( (1r , powersFormMultClosedSubset R' f .containsOne) , path)) where eq1 : ∀ r gm fm → 1r · (1r · r · gm) · (1r · fm · 1r) ≡ r · (gm · fm) eq1 = solve R' path : 1r · (1r · r · (g ^ m)) · (1r · (f ^ m) · 1r) ≡ 1r · (1r · r · (g ^ n)) · (1r · (f ^ n) · 1r) path = 1r · (1r · r · (g ^ m)) · (1r · (f ^ m) · 1r) ≡⟨ eq1 r (g ^ m) (f ^ m) ⟩ r · (g ^ m · f ^ m) ≡⟨ cong (r ·_) (sym (^-ldist-· g f m)) ⟩ r · ((g · f) ^ m) ≡⟨ cong (λ x → r · (x ^ m)) (·-comm _ _) ⟩ r · ((f · g) ^ m) ≡⟨ cong (r ·_) ((sym s≡fg^m) ∙ s≡fg^n) ⟩ r · ((f · g) ^ n) ≡⟨ cong (λ x → r · (x ^ n)) (·-comm _ _) ⟩ r · ((g · f) ^ n) ≡⟨ cong (r ·_) (^-ldist-· g f n) ⟩ r · (g ^ n · f ^ n) ≡⟨ sym (eq1 r (g ^ n) (f ^ n)) ⟩ 1r · (1r · r · (g ^ n)) · (1r · (f ^ n) · 1r) ∎ ϕ : R × S[fg] → R[1/f][1/g] ϕ (r , s , |n,s≡fg^n|) = curriedϕ r s |n,s≡fg^n| -- λ (r / (fg)ⁿ) → ((r / fⁿ) / gⁿ) curriedϕcohΣ : (r s r' s' u : R) → (p : u · r · s' ≡ u · r' · s) → (α : Σ[ n ∈ ℕ ] s ≡ (f · g) ^ n) → (β : Σ[ m ∈ ℕ ] s' ≡ (f · g) ^ m) → (γ : Σ[ l ∈ ℕ ] u ≡ (f · g) ^ l) → ϕ (r , s , PT.∣ α ∣) ≡ ϕ (r' , s' , PT.∣ β ∣) curriedϕcohΣ r s r' s' u p (n , s≡fgⁿ) (m , s'≡fgᵐ) (l , u≡fgˡ) = eq/ _ _ ( ( [ (g ^ l) , 1r , powersFormMultClosedSubset R' f .containsOne ] , PT.∣ l , ^-respects-/1 R' l ∣) , eq/ _ _ ((f ^ l , PT.∣ l , refl ∣) , path)) where eq1 : ∀ fl gl r gm fm → fl · (gl · r · gm) · (1r · fm · 1r) ≡ fl · gl · r · (gm · fm) eq1 = solve R' path : f ^ l · (g ^ l · transp (λ i → R) i0 r · transp (λ i → R) i0 (g ^ m)) · (1r · transp (λ i → R) i0 (f ^ m) · transp (λ i → R) i0 1r) ≡ f ^ l · (g ^ l · transp (λ i → R) i0 r' · transp (λ i → R) i0 (g ^ n)) · (1r · transp (λ i → R) i0 (f ^ n) · transp (λ i → R) i0 1r) path = f ^ l · (g ^ l · transp (λ i → R) i0 r · transp (λ i → R) i0 (g ^ m)) · (1r · transp (λ i → R) i0 (f ^ m) · transp (λ i → R) i0 1r) ≡⟨ (λ i → f ^ l · (g ^ l · transportRefl r i · transportRefl (g ^ m) i) · (1r · transportRefl (f ^ m) i · transportRefl 1r i)) ⟩ f ^ l · (g ^ l · r · g ^ m) · (1r · f ^ m · 1r) ≡⟨ eq1 (f ^ l) (g ^ l) r (g ^ m) (f ^ m) ⟩ f ^ l · g ^ l · r · (g ^ m · f ^ m) ≡⟨ (λ i → ^-ldist-· f g l (~ i) · r · ^-ldist-· g f m (~ i)) ⟩ (f · g) ^ l · r · (g · f) ^ m ≡⟨ cong (λ x → (f · g) ^ l · r · x ^ m) (·-comm _ _) ⟩ (f · g) ^ l · r · (f · g) ^ m ≡⟨ (λ i → u≡fgˡ (~ i) · r · s'≡fgᵐ (~ i)) ⟩ u · r · s' ≡⟨ p ⟩ u · r' · s ≡⟨ (λ i → u≡fgˡ i · r' · s≡fgⁿ i) ⟩ (f · g) ^ l · r' · (f · g) ^ n ≡⟨ cong (λ x → (f · g) ^ l · r' · x ^ n) (·-comm _ _) ⟩ (f · g) ^ l · r' · (g · f) ^ n ≡⟨ (λ i → ^-ldist-· f g l i · r' · ^-ldist-· g f n i) ⟩ f ^ l · g ^ l · r' · (g ^ n · f ^ n) ≡⟨ sym (eq1 (f ^ l) (g ^ l) r' (g ^ n) (f ^ n)) ⟩ f ^ l · (g ^ l · r' · g ^ n) · (1r · f ^ n · 1r) ≡⟨ (λ i → f ^ l · (g ^ l · transportRefl r' (~ i) · transportRefl (g ^ n) (~ i)) · (1r · transportRefl (f ^ n) (~ i) · transportRefl 1r (~ i))) ⟩ f ^ l · (g ^ l · transp (λ i → R) i0 r' · transp (λ i → R) i0 (g ^ n)) · (1r · transp (λ i → R) i0 (f ^ n) · transp (λ i → R) i0 1r) ∎ curriedϕcoh : (r s r' s' u : R) → (p : u · r · s' ≡ u · r' · s) → (α : ∃[ n ∈ ℕ ] s ≡ (f · g) ^ n) → (β : ∃[ m ∈ ℕ ] s' ≡ (f · g) ^ m) → (γ : ∃[ l ∈ ℕ ] u ≡ (f · g) ^ l) → ϕ (r , s , α) ≡ ϕ (r' , s' , β) curriedϕcoh r s r' s' u p = PT.elim (λ _ → isPropΠ2 (λ _ _ → squash/ _ _)) λ α → PT.elim (λ _ → isPropΠ (λ _ → squash/ _ _)) λ β → PT.rec (squash/ _ _) λ γ → curriedϕcohΣ r s r' s' u p α β γ ϕcoh : (a b : R × S[fg]) → Loc._≈_ R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) a b → ϕ a ≡ ϕ b ϕcoh (r , s , α) (r' , s' , β) ((u , γ) , p) = curriedϕcoh r s r' s' u p α β γ -- the map induced by the universal property open S⁻¹RUniversalProp R' ([_ⁿ|n≥0] R' (f · g)) (powersFormMultClosedSubset R' (f · g)) χ : R[1/fg] → R[1/f][1/g] χ = RingHom.f ( S⁻¹RHasUniversalProp R[1/f][1/g]AsCommRing /1/1AsCommRingHom fⁿgⁿ/1/1∈R[1/f][1/g]ˣ .fst .fst) -- the sanity check: -- both maps send a fraction r/(fg)ⁿ to a double fraction, -- where numerator and denominator are almost the same fraction respectively. -- unfortunately the proofs that the denominators are powers are quite different for -- the two maps, but of course we can ignore them. -- The definition of χ introduces a lot of (1r ·_). Perhaps most surprisingly, -- we have to give the path eq1 for the equality of the numerator of the numerator. φ≡χ : ∀ r → φ r ≡ χ r φ≡χ = InvElPropElim _ (λ _ → squash/ _ _) ℕcase where ℕcase : (r : R) (n : ℕ) → φ [ r , (f · g) ^ n , PT.∣ n , refl ∣ ] ≡ χ [ r , (f · g) ^ n , PT.∣ n , refl ∣ ] ℕcase r n = cong [_] (ΣPathP --look into the components of the double-fractions ( cong [_] (ΣPathP (eq1 , Σ≡Prop (λ x → S'[f] x .snd) (sym (·Lid _)))) , Σ≡Prop (λ x → S'[f][g] x .snd) --ignore proof that denominator is power of g/1 ( cong [_] (ΣPathP (sym (·Lid _) , Σ≡Prop (λ x → S'[f] x .snd) (sym (·Lid _))))))) where S'[f] = ([_ⁿ|n≥0] R' f) S'[f][g] = ([_ⁿ|n≥0] R[1/f]AsCommRing [ g , 1r , powersFormMultClosedSubset R' f .containsOne ]) eq1 : transp (λ i → fst R') i0 r ≡ r · transp (λ i → fst R') i0 1r eq1 = transportRefl r ∙∙ sym (·Rid r) ∙∙ cong (r ·_) (sym (transportRefl 1r))
42.123746
102
0.433624
5e3a285a40abf5b3d2dbde0a58b5c51dd994c9a6
8,664
agda
Agda
Cubical/Experiments/EscardoSIP.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Experiments/EscardoSIP.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Experiments/EscardoSIP.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
{- This is a rather literal translation of Martin Hötzel-Escardó's structure identity principle into cubical Agda. See https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns All the needed preliminary results from the lecture notes are stated and proven in this file. It would be interesting to compare the proves with the one in Cubical.Foundations.SIP -} {-# OPTIONS --safe #-} module Cubical.Experiments.EscardoSIP where open import Cubical.Core.Everything open import Cubical.Foundations.Everything open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Data.Sigma.Properties private variable ℓ ℓ' ℓ'' : Level S : Type ℓ → Type ℓ' -- We prove several useful equalities and equivalences between Σ-types all the proofs are taken from -- Martin Hötzel-Escardó's lecture notes. -- The next result is just a reformulation of pathSigma≡sigmaPath from Sigma.Properties. Σ-≡-≃ : {X : Type ℓ} {A : X → Type ℓ'} → (σ τ : Σ X A) → ((σ ≡ τ) ≃ (Σ[ p ∈ (σ .fst) ≡ (τ .fst) ] (subst A p (σ .snd) ≡ (τ .snd)))) Σ-≡-≃ {A = A} σ τ = invEquiv (ΣPathTransport≃PathΣ σ τ) -- This cubical proof is much shorter than in HoTT but requires that A, B live in the same universe. Σ-cong : {X : Type ℓ} {A B : X → Type ℓ'} → ((x : X) → (A x ≡ B x)) → (Σ X A ≡ Σ X B) Σ-cong {X = X} p i = Σ[ x ∈ X ] (p x i) -- Two lemmas for the more general formulation using equivalences NatΣ : {X : Type ℓ} {A : X → Type ℓ'} {B : X → Type ℓ''} → ((x : X) → (A x) → (B x)) → (Σ X A) → (Σ X B) NatΣ τ (x , a) = (x , τ x a) Σ-to-PathP : {X : Type ℓ} {A : X → Type ℓ'} {x : X} {a b : A x} → (a ≡ b) → PathP (λ i → Σ X A) (x , a) (x , b) Σ-to-PathP {x = x} p i = (x , p i) Σ-cong-≃ : {X : Type ℓ} {A : X → Type ℓ'} {B : X → Type ℓ''} → ((x : X) → (A x ≃ B x)) → (Σ X A ≃ Σ X B) Σ-cong-≃ {X = X} {A = A} {B = B} φ = isoToEquiv (iso (NatΣ f) (NatΣ g) NatΣ-ε NatΣ-η) where f : (x : X) → (A x) → (B x) f x = equivFun (φ x) g : (x : X) → (B x) → (A x) g x = equivFun (invEquiv (φ x)) η : (x : X) → (a : A x) → (g x) ((f x) a) ≡ a η x = retEq (invEquiv (φ x)) ε : (x : X) → (b : B x) → f x (g x b) ≡ b ε x = secEq (invEquiv (φ x)) NatΣ-η : (w : Σ X A) → NatΣ g (NatΣ f w) ≡ w NatΣ-η (x , a) = (x , g x (f x a)) ≡⟨ Σ-to-PathP (η x a) ⟩ (x , a) ∎ NatΣ-ε : (u : Σ X B) → NatΣ f (NatΣ g u) ≡ u NatΣ-ε (x , b) = (x , f x (g x b)) ≡⟨ Σ-to-PathP (ε x b) ⟩ (x , b) ∎ -- The next result is stated a bit awkwardly but is rather straightforward to prove. Σ-change-of-variable-Iso : {X : Type ℓ} {Y : Type ℓ'} {A : Y → Type ℓ''} (f : X → Y) → (isHAEquiv f) → (Iso (Σ X (A ∘ f)) (Σ Y A)) Σ-change-of-variable-Iso {ℓ = ℓ} {ℓ' = ℓ'} {X = X} {Y = Y} {A = A} f isHAEquivf = iso φ ψ φψ ψφ where g : Y → X g = isHAEquiv.g isHAEquivf ε : (x : X) → (g (f x)) ≡ x ε = isHAEquiv.linv isHAEquivf η : (y : Y) → f (g y) ≡ y η = isHAEquiv.rinv isHAEquivf τ : (x : X) → cong f (ε x) ≡ η (f x) τ = isHAEquiv.com isHAEquivf φ : (Σ X (A ∘ f)) → (Σ Y A) φ (x , a) = (f x , a) ψ : (Σ Y A) → (Σ X (A ∘ f)) ψ (y , a) = (g y , subst A (sym (η y)) a) φψ : (z : (Σ Y A)) → φ (ψ z) ≡ z φψ (y , a) = ΣPathTransport→PathΣ _ _ (η y , transportTransport⁻ (λ i → A (η y i)) a) -- last term proves transp (λ i → A (η y i)) i0 (transp (λ i → A (η y (~ i))) i0 a) ≡ a ψφ : (z : (Σ X (A ∘ f))) → ψ (φ z) ≡ z ψφ (x , a) = ΣPathTransport→PathΣ _ _ (ε x , q) where b : A (f (g (f x))) b = (transp (λ i → A (η (f x) (~ i))) i0 a) q : transp (λ i → A (f (ε x i))) i0 (transp (λ i → A (η (f x) (~ i))) i0 a) ≡ a q = transp (λ i → A (f (ε x i))) i0 b ≡⟨ i ⟩ transp (λ i → A (η (f x) i)) i0 b ≡⟨ transportTransport⁻ (λ i → A (η (f x) i)) a ⟩ a ∎ where i : (transp (λ i → A (f (ε x i))) i0 b) ≡ (transp (λ i → A (η (f x) i)) i0 b) i = subst (λ p → (transp (λ i → A (f (ε x i))) i0 b) ≡ (transp (λ i → A (p i)) i0 b)) (τ x) refl -- Using the result above we can prove the following quite useful result. Σ-change-of-variable-≃ : {X : Type ℓ} {Y : Type ℓ'} {A : Y → Type ℓ''} (f : X → Y) → (isEquiv f) → ((Σ X (A ∘ f)) ≃ (Σ Y A)) Σ-change-of-variable-≃ f isEquivf = isoToEquiv (Σ-change-of-variable-Iso f (equiv→HAEquiv (f , isEquivf) .snd)) -- A structure is a type-family S : Type ℓ → Type ℓ', i.e. for X : Type ℓ and s : S X, the pair (X , s) -- means that X is equipped with a S-structure, which is witnessed by s. -- An S-structure should have a notion of S-homomorphism, or rather S-isomorphism. -- This will be implemented by a function ι -- that gives us for any two types with S-structure (X , s) and (Y , t) a family: -- ι (X , s) (Y , t) : (X ≃ Y) → Type ℓ'' -- Note that for any equivalence (f , e) : X ≃ Y the type ι (X , s) (Y , t) (f , e) need not to be -- a proposition. Indeed this type should correspond to the ways s and t can be identified -- as S-structures. This we call a standard notion of structure. SNS : (S : Type ℓ → Type ℓ') (ι : StrEquiv S ℓ'') → Type (ℓ-max (ℓ-max (ℓ-suc ℓ) ℓ') ℓ'') SNS {ℓ = ℓ} S ι = ∀ {X : (Type ℓ)} (s t : S X) → ((s ≡ t) ≃ ι (X , s) (X , t) (idEquiv X)) -- Escardo's ρ can actually be defined from this: ρ : {ι : StrEquiv S ℓ''} (θ : SNS S ι) (A : TypeWithStr ℓ S) → (ι A A (idEquiv (typ A))) ρ θ A = equivFun (θ (str A) (str A)) refl -- We introduce the notation a bit differently: _≃[_]_ : (A : TypeWithStr ℓ S) (ι : StrEquiv S ℓ'') (B : TypeWithStr ℓ S) → (Type (ℓ-max ℓ ℓ'')) A ≃[ ι ] B = Σ[ f ∈ ((typ A) ≃ (typ B)) ] (ι A B f) Id→homEq : (S : Type ℓ → Type ℓ') (ι : StrEquiv S ℓ'') → (ρ : (A : TypeWithStr ℓ S) → ι A A (idEquiv (typ A))) → (A B : TypeWithStr ℓ S) → A ≡ B → (A ≃[ ι ] B) Id→homEq S ι ρ A B p = J (λ y x → A ≃[ ι ] y) (idEquiv (typ A) , ρ A) p -- Use a PathP version of Escardó's homomorphism-lemma hom-lemma-dep : (S : Type ℓ → Type ℓ') (ι : StrEquiv S ℓ'') (θ : SNS S ι) → (A B : TypeWithStr ℓ S) → (p : (typ A) ≡ (typ B)) → (PathP (λ i → S (p i)) (str A) (str B)) ≃ (ι A B (pathToEquiv p)) hom-lemma-dep S ι θ A B p = (J P (λ s → γ s) p) (str B) where P = (λ y x → (s : S y) → PathP (λ i → S (x i)) (str A) s ≃ ι A (y , s) (pathToEquiv x)) γ : (s : S (typ A)) → ((str A) ≡ s) ≃ ι A ((typ A) , s) (pathToEquiv refl) γ s = subst (λ f → ((str A) ≡ s) ≃ ι A ((typ A) , s) f) (sym pathToEquivRefl) (θ (str A) s) -- Define the inverse of Id→homEq directly. ua-lemma : (A B : Type ℓ) (e : A ≃ B) → (pathToEquiv (ua e)) ≡ e ua-lemma A B e = EquivJ (λ A f → (pathToEquiv (ua f)) ≡ f) (subst (λ r → pathToEquiv r ≡ idEquiv B) (sym uaIdEquiv) pathToEquivRefl) e homEq→Id : (S : Type ℓ → Type ℓ') (ι : StrEquiv S ℓ'') (θ : SNS S ι) → (A B : TypeWithStr ℓ S) → (A ≃[ ι ] B) → A ≡ B homEq→Id S ι θ A B (f , φ) = ΣPathP (p , q) where p = ua f ψ : ι A B (pathToEquiv p) ψ = subst (λ g → ι A B g) (sym (ua-lemma (typ A) (typ B) f)) φ q : PathP (λ i → S (p i)) (str A) (str B) q = equivFun (invEquiv (hom-lemma-dep S ι θ A B p)) ψ -- Proof of the SIP: SIP : (S : Type ℓ → Type ℓ') (ι : StrEquiv S ℓ'') (θ : SNS S ι) → (A B : TypeWithStr ℓ S) → ((A ≡ B) ≃ (A ≃[ ι ] B)) SIP S ι θ A B = (A ≡ B) ≃⟨ i ⟩ (Σ[ p ∈ (typ A) ≡ (typ B) ] PathP (λ i → S (p i)) (str A) (str B)) ≃⟨ ii ⟩ (Σ[ p ∈ (typ A) ≡ (typ B) ] (ι A B (pathToEquiv p))) ≃⟨ iii ⟩ (A ≃[ ι ] B) ■ where i = invEquiv ΣPath≃PathΣ ii = Σ-cong-≃ (hom-lemma-dep S ι θ A B) iii = Σ-change-of-variable-≃ pathToEquiv (equivIsEquiv univalence) -- A simple example: pointed types pointed-structure : Type ℓ → Type ℓ pointed-structure X = X Pointed-Type : Type (ℓ-suc ℓ) Pointed-Type {ℓ = ℓ} = Σ (Type ℓ) pointed-structure pointed-ι : (A B : Pointed-Type) → (A .fst) ≃ (B. fst) → Type ℓ pointed-ι (X , x) (Y , y) f = (equivFun f) x ≡ y pointed-is-sns : SNS {ℓ = ℓ} pointed-structure pointed-ι pointed-is-sns s t = idEquiv (s ≡ t) pointed-type-sip : (X Y : Type ℓ) (x : X) (y : Y) → (Σ[ f ∈ X ≃ Y ] (f .fst) x ≡ y) ≃ ((X , x) ≡ (Y , y)) pointed-type-sip X Y x y = invEquiv (SIP pointed-structure pointed-ι pointed-is-sns (X , x) (Y , y))
39.561644
115
0.500231
37423864d848ff876c2abf613b6840c3a695a06c
12,740
agda
Agda
cohesion/david_jaz_261/Flat.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
6
2021-10-06T17:39:22.000Z
2022-02-13T05:51:12.000Z
cohesion/david_jaz_261/Flat.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
cohesion/david_jaz_261/Flat.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} module Flat where open import lib.Basics open import Basics open import Bool open import lib.types.Bool open import lib.NType2 open import lib.Equivalence2 open import lib.types.Suspension open import lib.types.IteratedSuspension open import lib.types.Pushout as Pushout open import lib.types.Truncation -- The type of points of A, ♭ A, is inductively generated by the crisp elements of A data ♭ {@♭ l : ULevel} (@♭ A : Type l) : Type l where _^♭ : A ::→ ♭ A -- The deduced mapping principle of ♭ A: it represents crisp functions. ♭-elim : {c : ULevel} {@♭ l : ULevel}{@♭ A : Type l} → (C : ♭ A → Type c) → ((@♭ u : A) → C (u ^♭)) → (x : ♭ A) → C x ♭-elim C f (x ^♭) = f x syntax ♭-elim C (λ u → t) a = let♭ u ^♭:= a in♭ t in-family C {- Mike's "let" notation (following Felix) -} -- An implicit version of ♭-elim let♭ : {@♭ i j : ULevel} {@♭ A : Type i} {B : ♭ A → Type j} (a : ♭ A) (f : (@♭ u : A) → B (u ^♭)) → B a let♭ (u ^♭) f = f u syntax let♭ a (λ u → t) = let♭ u ^♭:= a in♭ t ♭-rec : {@♭ i : ULevel} {j : ULevel} {@♭ A : Type i} {B : Type j} → (A ::→ B) → (♭ A) → B ♭-rec f (a ^♭) = f a ♭-rec-eq : {@♭ i : ULevel} {j : ULevel} {@♭ A : Type i} {B : Type j} → (A ::→ B) ≃ (♭ A → B) ♭-rec-eq {A = A} {B = B} = equiv ♭-rec (λ f → λ (@♭ a : A) → f (a ^♭)) -- fro (λ f → λ= (λ { (a ^♭) → refl })) -- to-fro (λ f → refl) -- fro-to -- Crisp function types, but from A : ♭ Type _♭:→_ : {@♭ i : ULevel} {j : ULevel} (A : ♭ (Type i)) (B : Type j) → Type (lmax i j) (A ^♭) ♭:→ B = A ::→ B -- The inclusion of the points of A into A _↓♭ : {@♭ i : ULevel} {@♭ A : Type i} → (♭ A → A) _↓♭ (x ^♭) = x -- The (judgemental) computation rule for mapping out of points ♭-β : {@♭ i : ULevel} {@♭ A : Type i} (@♭ a : ♭ A) → ((a ↓♭) ^♭) == a ♭-β (a ^♭) = refl -- Application of crisp functions to crisp equalities -- Used mostly to apply _^♭. ♭-ap : {@♭ i j : ULevel} {@♭ A : Type i} {B : Type j} (f : (@♭ a : A) → B) {@♭ x y : A} (@♭ p : x == y) → (f x) == (f y) ♭-ap f refl = refl -- ♭ is a functor ♭→ : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} → (@♭ f : A → B) → (♭ A → ♭ B) ♭→ f (x ^♭) = (f x) ^♭ -- The naturality square of the inclusion of points (judgemental!) ♭→-nat : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} (@♭ f : A → B) → (a : ♭ A) → (f ∘ _↓♭) a == (_↓♭ ∘ (♭→ f)) a ♭→-nat f (a ^♭) = refl -- Proof of functoriality ♭→∘ : {@♭ i j k : ULevel} {@♭ A : Type i} {@♭ B : Type j} {@♭ C : Type k} {@♭ f : A → B} {@♭ g : B → C} → ♭→ (g ∘ f) == (♭→ g) ∘ (♭→ f) ♭→∘ {f = f} {g = g} = λ= (λ a → -- We test on elements, but let♭ u ^♭:= a in♭ -- might as well assume those elements are crisp refl -- where it follows by definition. in-family (λ a → (♭→ (g ∘ f)) a == ((♭→ g) ∘ (♭→ f)) a) ) -- ♭→ preserves crisp equivalences ♭→e : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} → (@♭ e : A ≃ B) → (♭ A) ≃ (♭ B) ♭→e e = equiv (♭→ (–> e)) (♭→ (<– e)) (λ { (a ^♭) → ♭-ap _^♭ (<–-inv-r e a) }) (λ { (a ^♭) → ♭-ap _^♭ (<–-inv-l e a) }) -- A type is discrete if the inclusion of its point is an equivalence. _is-discrete : {@♭ l : ULevel} → (@♭ A : Type l) → Type l _is-discrete {l} A = is-equiv {l} {l} {♭ A} {A} _↓♭ -- The equivalence between the points of a discrete type and itself discrete-eq : {@♭ l : ULevel} {@♭ A : Type l} → A is-discrete → (♭ A) ≃ A discrete-eq = _↓♭ ,_ _is-discrete-is-a-prop : {@♭ l : ULevel} (@♭ A : Type l) → (A is-discrete) is-a-prop A is-discrete-is-a-prop = is-equiv-is-prop is-discrete-prop : {@♭ l : ULevel} → SubtypeProp (♭ (Type l)) l is-discrete-prop = (λ { (A ^♭) → A is-discrete }) , (λ { (A ^♭) → A is-discrete-is-a-prop }) -- The subtype of discrete types Discrete : (@♭ l : ULevel) → Type (lsucc l) Discrete l = Subtype is-discrete-prop Discrete-_-Type_ : (@♭ n : ℕ₋₂) (@♭ i : ULevel) → Type (lsucc i) Discrete- n -Type i = Subtype prop where prop : SubtypeProp (♭ (n -Type i)) i prop = (λ { (A ^♭) → (fst A) is-discrete }) , (λ { (A ^♭) → (fst A) is-discrete-is-a-prop }) DiscSet : (@♭ i : ULevel) → Type (lsucc i) DiscSet i = Discrete- ⟨ S (S O) ⟩₋₂ -Type i DiscSet₀ = DiscSet lzero ∈Disc : {@♭ i : ULevel} (A : DiscSet i) → Type i ∈Disc A = ((♭→ ∈) (fst A)) ↓♭ DiscSet-to-Set : {@♭ i : ULevel} → DiscSet i → hSet i DiscSet-to-Set A = (fst A) ↓♭ -- DiscSet_is-discrete : {@♭ i : ULevel} → (@♭ A : DiscSet i) → (∈Disc A) is-discrete -- DiscSet A is-discrete = {!(snd A)!} -- Just in case, we apply univalence to the discrete-eq discrete-id : {@♭ l : ULevel} {@♭ A : Type l} → A is-discrete → (♭ A) == A discrete-id p = ua (discrete-eq p) -- Obviously, the points of a type are discrete ♭-is-discrete : {@♭ l : ULevel} {@♭ A : Type l} → (♭ A) is-discrete ♭-is-discrete {_} {A} = _↓♭ is-an-equivalence-because fro is-inverse-by to-fro and fro-to where fro : ♭ A → ♭ (♭ A) fro (a ^♭) = (a ^♭) ^♭ to-fro : (a : ♭ A) → ((fro a) ↓♭) == a to-fro (a ^♭) = refl fro-to : (a : ♭ (♭ A)) → fro (a ↓♭) == a fro-to ((a ^♭) ^♭) = refl -- To prove the ♭i is an equivalence, it suffices to give a section of it. _is-discrete-because_is-section-by_ : {@♭ l : ULevel} (@♭ A : Type l) (@♭ s : A → ♭ A) (@♭ p : (a : A) → ((s a) ↓♭)== a) → A is-discrete A is-discrete-because s is-section-by p = _↓♭ is-an-equivalence-because s is-inverse-by p and (λ { (a ^♭) → ! (♭-β (s a)) ∙ (♭-ap _^♭ (p a))}) -- ♭ commutes with identity types in the following sense module _ {@♭ i : ULevel} {@♭ A : Type i} where ♭-identity-eq : (@♭ x y : A) → ♭ (x == y) ≃ ((x ^♭) == (y ^♭)) ♭-identity-eq _ _ = equiv to fro to-fro fro-to where to : {@♭ x y : A} → ♭ (x == y) → ((x ^♭) == (y ^♭)) to (refl ^♭) = refl fro : {@♭ x y : A} → ((x ^♭) == (y ^♭)) → ♭ (x == y) fro refl = refl ^♭ to-fro : {@♭ x y : A} → (p : (x ^♭) == (y ^♭)) → (to (fro p) == p) to-fro refl = refl fro-to : {@♭ x y : A} → (p : ♭ (x == y)) → fro (to p) == p fro-to (refl ^♭) = refl {- From Tslil: There once was a Bear in a Zoo Who didn't know quite what to do It bored him so To walk to and fro So he flipped it and walked fro and to -} -- ♭ preserves crisp level. ♭-preserves-level : {@♭ i : ULevel} {@♭ A : Type i} {@♭ n : ℕ₋₂} (@♭ p : has-level n A) → has-level n (♭ A) ♭-preserves-level {_}{A}{⟨-2⟩} p = has-level-in ((a ^♭) , (λ {(y ^♭) → (–> (♭-identity-eq a y)) ((contr-path p y )^♭)})) where -- If A contracts onto a, then ♭ A contracts onto a ^♭ a = contr-center p ♭-preserves-level {_}{A}{S n} p = has-level-in (λ {(x ^♭) (y ^♭) → equiv-preserves-level (♭-identity-eq x y) {{♭-preserves-level {_}{(x == y)}{n} (has-level-apply p x y)}}}) {- Because the equality types of ♭ A are themselves ♭ (x == y) for x y : A, and because we know that x == y has level n if A has level (S n), we can recurse to show that ♭ (x == y) has level n and therefore ♭ A has level (S n). -} -- A version of ♭ that acts on n-types. ♭ₙ : {@♭ i : ULevel} {@♭ n : ℕ₋₂} → (@♭ A : n -Type i) → (n -Type i) ♭ₙ A = (♭ (fst A)) , ♭-preserves-level (snd A) ♭-Trunc-map : {@♭ i : ULevel} {@♭ n : ℕ₋₂} (@♭ X : Type i) → (Trunc n (♭ X)) → ♭ (Trunc n X) ♭-Trunc-map X = Trunc-elim {{p = ♭-preserves-level Trunc-level}} (λ { (a ^♭) → [ a ] ^♭ }) -- Until ♯ works we have to postulate this. ♭-Trunc-eq : {@♭ i : ULevel} {@♭ n : ℕ₋₂} (@♭ X : Type i) → (Trunc n (♭ X)) ≃ ♭ (Trunc n X) ♭-Trunc-eq X = (♭-Trunc-map X) , unproven where postulate unproven : (♭-Trunc-map X) is-an-equiv ⊤-is-discrete : ⊤ is-discrete ⊤-is-discrete = _↓♭ is-an-equivalence-because (λ {unit → unit ^♭}) is-inverse-by (λ {unit → refl}) and (λ {(unit ^♭) → refl}) -- ♭ commutes with coproducts. ♭-commutes-with-⊔ : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} → ♭ (A ⊔ B) ≃ (♭ A) ⊔ (♭ B) ♭-commutes-with-⊔ = to , (to is-an-equivalence-because fro is-inverse-by (λ { (inl (a ^♭)) → refl ; (inr (b ^♭)) → refl }) and (λ { ((inl a) ^♭) → refl ; ((inr b) ^♭) → refl })) where to : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} → ♭ (A ⊔ B) → (♭ A) ⊔ (♭ B) to ((inl a) ^♭) = inl (a ^♭) to ((inr b) ^♭) = inr (b ^♭) fro : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} → (♭ A) ⊔ (♭ B) → ♭ (A ⊔ B) fro (inl (a ^♭)) = (inl a) ^♭ fro (inr (b ^♭)) = (inr b) ^♭ -- ♭ commutes with Σ types for crisp families. module _ {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : A → Type j} where ♭-commutes-with-Σ : ♭ (Σ A B) ≃ Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u)) ♭-commutes-with-Σ = equiv to fro ((λ { ((a ^♭) , (b ^♭)) → refl })) ((λ { ((a , b) ^♭) → refl })) where to : ♭ (Σ A B) → Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u)) to ((a , b) ^♭) = ((a ^♭) , (b ^♭)) fro : Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u)) → ♭ (Σ A B) fro ((a ^♭) , (b ^♭)) = (a , b) ^♭ ℕ-is-discrete : ℕ is-discrete ℕ-is-discrete = ℕ is-discrete-because fro is-section-by to-fro where fro : ℕ → ♭ ℕ fro O = O ^♭ fro (S n) = (♭→ S) (fro n) to-fro : (n : ℕ) → ((fro n) ↓♭) == n to-fro O = refl to-fro (S n) = (fro (S n)) ↓♭ =⟨ ! ((♭→-nat S) (fro n)) ⟩ (S ∘ _↓♭) (fro n) =⟨ ap S (to-fro n) ⟩ S n =∎ {- When proving this equality by induction on n, the case of 0 presents no problem, but when we work with (S n), we have to deal with the fact that n is not crisp. However, as a constructor (and therefore defined in the empty context), S is crisp. Therefore, we can use the naturality sqaure of ♭ to commute it past fro, and then recurse. -} -- We copy the proof for ULevel (or would but we can't pattern match on lsucc?) {- ULevel-is-discrete : ULevel is-discrete ULevel-is-discrete = ULevel is-discrete-because fro is-section-by to-fro where fro : ULevel → ♭ ULevel fro lzero = lzero ^♭ fro (lsucc n) = (♭→ lsucc) (fro n) to-fro : (n : ULevel) → ♭i (fro n) == n to-fro lzero = refl to-fro (lsucc n) = ♭i (fro (lsucc n)) =⟨ ! ((♭→-nat lsucc) (fro n)) ⟩ (lsucc ∘ ♭i) (fro n) =⟨ ap lsucc (to-fro n) ⟩ lsucc n =∎ -} Bool-is-discrete : Bool is-discrete Bool-is-discrete = Bool is-discrete-because fro is-section-by to-fro where fro : Bool → ♭ Bool fro true = true ^♭ fro false = false ^♭ to-fro : (b : Bool) → ((fro b) ↓♭)== b to-fro true = refl to-fro false = refl Bool-to-♭PropT₀ : Bool → ♭ PropT₀ Bool-to-♭PropT₀ true = True ^♭ Bool-to-♭PropT₀ false = False ^♭ Bool-to-♭PropT₀∘↓♭=♭→Bool-to-PropT₀ : Bool-to-♭PropT₀ ∘ _↓♭ == (♭→ Bool-to-PropT₀) Bool-to-♭PropT₀∘↓♭=♭→Bool-to-PropT₀ = λ= (λ { (true ^♭) → refl ; (false ^♭) → refl }) {- _-Sphere-is-discrete : (@♭ n : ℕ) → (Sphere n) is-discrete n -Sphere-is-discrete = (Sphere n) is-discrete-because (fro n) is-section-by {!!} where ♭-north : {@♭ n : ℕ} → ♭ (Sphere n) ♭-north {O} = true ^♭ ♭-north {S n} = {!north!} ♭-south : {@♭ n : ℕ} → ♭ (Sphere n) ♭-south = {!!} fro : (@♭ n : ℕ) → (Sphere n) → ♭ (Sphere n) fro O = λ { true → true ^♭ ; false → false ^♭ } fro (S n) = {!Susp-rec {A = Sphere n} {C = ♭ (Sphere (S n))} ♭-north ♭-south!} -}
35.686275
102
0.437834
c78376d7f8313ea856a07cf7ec0ab9e223341862
2,551
agda
Agda
Cubical/Algebra/Ideal.agda
knrafto/cubical
f6771617374bfe65a7043d00731fed5a673aa729
[ "MIT" ]
null
null
null
Cubical/Algebra/Ideal.agda
knrafto/cubical
f6771617374bfe65a7043d00731fed5a673aa729
[ "MIT" ]
null
null
null
Cubical/Algebra/Ideal.agda
knrafto/cubical
f6771617374bfe65a7043d00731fed5a673aa729
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Ideal where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Logic using ([_]; _∈_) open import Cubical.Algebra.Ring private variable ℓ : Level module _ (R' : Ring {ℓ}) where open Ring R' renaming (Carrier to R) {- by default, 'ideal' means two-sided ideal -} record isIdeal (I : R → hProp ℓ) : Type ℓ where field +-closed : {x y : R} → x ∈ I → y ∈ I → (x + y) ∈ I -closed : {x : R} → x ∈ I → - x ∈ I 0r-closed : 0r ∈ I ·-closedLeft : {x : R} → (r : R) → x ∈ I → r · x ∈ I ·-closedRight : {x : R} → (r : R) → x ∈ I → x · r ∈ I Ideal : Type _ Ideal = Σ[ I ∈ (R → hProp ℓ) ] isIdeal I record isLeftIdeal (I : R → hProp ℓ) : Type ℓ where field +-closed : {x y : R} → x ∈ I → y ∈ I → (x + y) ∈ I -closed : {x : R} → x ∈ I → - x ∈ I 0r-closed : 0r ∈ I ·-closedLeft : {x : R} → (r : R) → x ∈ I → r · x ∈ I record isRightIdeal (I : R → hProp ℓ) : Type ℓ where field +-closed : {x y : R} → x ∈ I → y ∈ I → (x + y) ∈ I -closed : {x : R} → x ∈ I → - x ∈ I 0r-closed : 0r ∈ I ·-closedRight : {x : R} → (r : R) → x ∈ I → x · r ∈ I {- Examples of ideals -} zeroSubset : (x : R) → hProp ℓ zeroSubset x = (x ≡ 0r) , isSetRing R' _ _ open Theory R' isIdealZeroIdeal : isIdeal zeroSubset isIdealZeroIdeal = record { +-closed = λ x≡0 y≡0 → _ + _ ≡⟨ cong (λ u → u + _) x≡0 ⟩ 0r + _ ≡⟨ +-lid _ ⟩ _ ≡⟨ y≡0 ⟩ 0r ∎ ; -closed = λ x≡0 → - _ ≡⟨ cong (λ u → - u) x≡0 ⟩ - 0r ≡⟨ 0-selfinverse ⟩ 0r ∎ ; 0r-closed = refl ; ·-closedLeft = λ r x≡0 → r · _ ≡⟨ cong (λ u → r · u) x≡0 ⟩ r · 0r ≡⟨ 0-rightNullifies r ⟩ 0r ∎ ; ·-closedRight = λ r x≡0 → _ · r ≡⟨ cong (λ u → u · r) x≡0 ⟩ 0r · r ≡⟨ 0-leftNullifies r ⟩ 0r ∎ } zeroIdeal : Ideal zeroIdeal = zeroSubset , isIdealZeroIdeal
35.430556
84
0.402195
367e01d9d88e3c7e5ad63091a7f536c8fb0a3828
201
agda
Agda
Cubical/HITs/Ints/BiInvInt.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/HITs/Ints/BiInvInt.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/HITs/Ints/BiInvInt.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Ints.BiInvInt where open import Cubical.HITs.Ints.BiInvInt.Base public open import Cubical.HITs.Ints.BiInvInt.Properties public
28.714286
56
0.781095
03220a37c9ba8e8cb16e8a2ad2688365256ad822
2,525
agda
Agda
src/LibraBFT/Impl/Consensus/Liveness/ProposalGenerator.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/Liveness/ProposalGenerator.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/Liveness/ProposalGenerator.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 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 LibraBFT.Base.Types import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block import LibraBFT.Impl.Consensus.ConsensusTypes.BlockData as BlockData import LibraBFT.Impl.Types.BlockInfo as BlockInfo open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Util.Dijkstra.All open import Optics.All open import Util.Encode as Encode open import Util.Prelude module LibraBFT.Impl.Consensus.Liveness.ProposalGenerator where ensureHighestQuorumCertM : Round → LBFT (Either ErrLog QuorumCert) generateNilBlockM : Round → LBFT (Either ErrLog Block) generateNilBlockM round = ensureHighestQuorumCertM round ∙?∙ (ok ∘ Block.newNil round) generateProposalM : Instant → Round → LBFT (Either ErrLog BlockData) generateProposalM _now round = do lrg ← use (lProposalGenerator ∙ pgLastRoundGenerated) ifD lrg <?ℕ round then (do lProposalGenerator ∙ pgLastRoundGenerated ∙= round ensureHighestQuorumCertM round ∙?∙ λ hqc -> do payload ← ifD BlockInfo.hasReconfiguration (hqc ^∙ qcCertifiedBlock) -- IMPL-DIFF : create a fake TX then pure (Encode.encode 0) -- (Payload []) else pure (Encode.encode 0) -- use pgTxnManager <*> use (rmEpochState ∙ esEpoch) <*> pure round use (lRoundManager ∙ pgAuthor) >>= λ where nothing → bail fakeErr -- ErrL (here ["lRoundManager.pgAuthor", "Nothing"]) (just author) → ok (BlockData.newProposal payload author round {-pure blockTimestamp <*>-} hqc)) else bail fakeErr -- where -- here t = "ProposalGenerator" ∷ "generateProposal" ∷ t ensureHighestQuorumCertM round = do hqc ← use (lBlockStore ∙ bsHighestQuorumCert) ifD‖ (hqc ^∙ qcCertifiedBlock ∙ biRound) ≥?ℕ round ≔ bail fakeErr {- ErrL (here [ "given round is lower than hqc round" , show (hqc^.qcCertifiedBlock.biRound) ]) -} ‖ hqc ^∙ qcEndsEpoch ≔ bail fakeErr {-ErrEpochEndedNoProposals (here ["further proposals not allowed"])-} ‖ otherwise≔ ok hqc -- where -- here t = "ProposalGenerator":"ensureHighestQuorumCertM":lsR round:t
44.298246
117
0.682772
11d8ac2d58427f9ad07f1085742f42296663bcac
13,067
agda
Agda
Cubical/Algebra/CommAlgebra/Localisation.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/CommAlgebra/Localisation.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/CommAlgebra/Localisation.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.CommAlgebra.Localisation where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Powerset open import Cubical.Data.Sigma open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; _^_ to _^ℕ_ ; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Data.FinData open import Cubical.Reflection.StrictEquiv open import Cubical.Structures.Axioms open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.CommRing.Base open import Cubical.Algebra.CommRing.Properties open import Cubical.Algebra.CommRing.Ideal open import Cubical.Algebra.CommRing.FGIdeal open import Cubical.Algebra.CommRing.RadicalIdeal open import Cubical.Algebra.CommRing.Localisation.Base open import Cubical.Algebra.CommRing.Localisation.UniversalProperty open import Cubical.Algebra.CommRing.Localisation.InvertingElements open import Cubical.Algebra.Ring open import Cubical.Algebra.Algebra open import Cubical.Algebra.CommAlgebra.Base open import Cubical.Algebra.CommAlgebra.Properties open import Cubical.Algebra.CommRingSolver.Reflection open import Cubical.HITs.SetQuotients as SQ open import Cubical.HITs.PropositionalTruncation as PT private variable ℓ ℓ′ : Level module AlgLoc (R' : CommRing ℓ) (S' : ℙ (fst R')) (SMultClosedSubset : isMultClosedSubset R' S') where open isMultClosedSubset private R = fst R' open CommAlgebraStr open IsAlgebraHom open CommRingStr (snd R') renaming (_+_ to _+r_ ; _·_ to _·r_ ; ·Rid to ·rRid) open RingTheory (CommRing→Ring R') open CommRingTheory R' open Loc R' S' SMultClosedSubset open S⁻¹RUniversalProp R' S' SMultClosedSubset open CommAlgChar R' S⁻¹RAsCommAlg : CommAlgebra R' ℓ S⁻¹RAsCommAlg = toCommAlg (S⁻¹RAsCommRing , /1AsCommRingHom) hasLocAlgUniversalProp : (A : CommAlgebra R' ℓ) → (∀ s → s ∈ S' → _⋆_ (snd A) s (1a (snd A)) ∈ (CommAlgebra→CommRing A) ˣ) → Type (ℓ-suc ℓ) hasLocAlgUniversalProp A _ = (B : CommAlgebra R' ℓ) → (∀ s → s ∈ S' → _⋆_ (snd B) s (1a (snd B)) ∈ (CommAlgebra→CommRing B) ˣ) → isContr (CommAlgebraHom A B) S⋆1⊆S⁻¹Rˣ : ∀ s → s ∈ S' → _⋆_ (snd S⁻¹RAsCommAlg) s (1a (snd S⁻¹RAsCommAlg)) ∈ S⁻¹Rˣ S⋆1⊆S⁻¹Rˣ s s∈S' = subst-∈ S⁻¹Rˣ (cong [_] (≡-× (sym (·rRid s)) (Σ≡Prop (λ x → S' x .snd) (sym (·rRid _))))) (S/1⊆S⁻¹Rˣ s s∈S') S⁻¹RHasAlgUniversalProp : hasLocAlgUniversalProp S⁻¹RAsCommAlg S⋆1⊆S⁻¹Rˣ S⁻¹RHasAlgUniversalProp B' S⋆1⊆Bˣ = χᴬ , χᴬuniqueness where B = fromCommAlg B' .fst φ = fromCommAlg B' .snd open CommRingStr (snd B) renaming (_·_ to _·b_ ; 1r to 1b ; ·Lid to ·bLid) χ : CommRingHom S⁻¹RAsCommRing B χ = S⁻¹RHasUniversalProp B φ S⋆1⊆Bˣ .fst .fst χcomp : ∀ r → fst χ (r /1) ≡ fst φ r χcomp = funExt⁻ (S⁻¹RHasUniversalProp B φ S⋆1⊆Bˣ .fst .snd) χᴬ : CommAlgebraHom S⁻¹RAsCommAlg B' fst χᴬ = fst χ pres0 (snd χᴬ) = IsRingHom.pres0 (snd χ) pres1 (snd χᴬ) = IsRingHom.pres1 (snd χ) pres+ (snd χᴬ) = IsRingHom.pres+ (snd χ) pres· (snd χᴬ) = IsRingHom.pres· (snd χ) pres- (snd χᴬ) = IsRingHom.pres- (snd χ) pres⋆ (snd χᴬ) r x = path where path : fst χ ((r /1) ·ₗ x) ≡ _⋆_ (snd B') r (fst χ x) path = fst χ ((r /1) ·ₗ x) ≡⟨ IsRingHom.pres· (snd χ) _ _ ⟩ fst χ (r /1) ·b fst χ x ≡⟨ cong (_·b fst χ x) (χcomp r) ⟩ fst φ r ·b fst χ x ≡⟨ refl ⟩ _⋆_ (snd B') r 1b ·b fst χ x ≡⟨ ⋆-lassoc (snd B') _ _ _ ⟩ _⋆_ (snd B') r (1b ·b fst χ x) ≡⟨ cong (_⋆_ (snd B') r) (·bLid _) ⟩ _⋆_ (snd B') r (fst χ x) ∎ χᴬuniqueness : (ψ : CommAlgebraHom S⁻¹RAsCommAlg B') → χᴬ ≡ ψ χᴬuniqueness ψ = Σ≡Prop (λ _ → isPropIsAlgebraHom _ _ _ _) (cong (fst ∘ fst) (χuniqueness (ψ' , funExt ψ'r/1≡φr))) where χuniqueness = S⁻¹RHasUniversalProp B φ S⋆1⊆Bˣ .snd ψ' : CommRingHom S⁻¹RAsCommRing B fst ψ' = fst ψ IsRingHom.pres0 (snd ψ') = pres0 (snd ψ) IsRingHom.pres1 (snd ψ') = pres1 (snd ψ) IsRingHom.pres+ (snd ψ') = pres+ (snd ψ) IsRingHom.pres· (snd ψ') = pres· (snd ψ) IsRingHom.pres- (snd ψ') = pres- (snd ψ) ψ'r/1≡φr : ∀ r → fst ψ (r /1) ≡ fst φ r ψ'r/1≡φr r = fst ψ (r /1) ≡⟨ cong (fst ψ) (sym (·ₗ-rid _)) ⟩ fst ψ (_⋆_ (snd S⁻¹RAsCommAlg) r (1a (snd S⁻¹RAsCommAlg))) ≡⟨ pres⋆ (snd ψ) _ _ ⟩ _⋆_ (snd B') r (fst ψ (1a (snd S⁻¹RAsCommAlg))) ≡⟨ cong (_⋆_ (snd B') r) (pres1 (snd ψ)) ⟩ _⋆_ (snd B') r 1b ∎ -- an immediate corollary: isContrHomS⁻¹RS⁻¹R : isContr (CommAlgebraHom S⁻¹RAsCommAlg S⁻¹RAsCommAlg) isContrHomS⁻¹RS⁻¹R = S⁻¹RHasAlgUniversalProp S⁻¹RAsCommAlg S⋆1⊆S⁻¹Rˣ S⁻¹RAlgCharEquiv : (A' : CommRing ℓ) (φ : CommRingHom R' A') → PathToS⁻¹R R' S' SMultClosedSubset A' φ → CommAlgebraEquiv S⁻¹RAsCommAlg (toCommAlg (A' , φ)) S⁻¹RAlgCharEquiv A' φ cond = toCommAlgebraEquiv _ _ (S⁻¹RCharEquiv R' S' SMultClosedSubset A' φ cond) (RingHom≡ (S⁻¹RHasUniversalProp A' φ (cond .φS⊆Aˣ) .fst .snd)) where open PathToS⁻¹R -- the special case of localizing at a single element R[1/_]AsCommAlgebra : {R : CommRing ℓ} → fst R → CommAlgebra R ℓ R[1/_]AsCommAlgebra {R = R} f = S⁻¹RAsCommAlg [ f ⁿ|n≥0] (powersFormMultClosedSubset f) where open AlgLoc R open InvertingElementsBase R module AlgLocTwoSubsets (R' : CommRing ℓ) (S₁ : ℙ (fst R')) (S₁MultClosedSubset : isMultClosedSubset R' S₁) (S₂ : ℙ (fst R')) (S₂MultClosedSubset : isMultClosedSubset R' S₂) where open isMultClosedSubset open CommRingStr (snd R') hiding (is-set) open RingTheory (CommRing→Ring R') open Loc R' S₁ S₁MultClosedSubset renaming (S⁻¹R to S₁⁻¹R ; S⁻¹RAsCommRing to S₁⁻¹RAsCommRing) open Loc R' S₂ S₂MultClosedSubset renaming (S⁻¹R to S₂⁻¹R ; S⁻¹RAsCommRing to S₂⁻¹RAsCommRing) open AlgLoc R' S₁ S₁MultClosedSubset renaming ( S⁻¹RAsCommAlg to S₁⁻¹RAsCommAlg ; S⋆1⊆S⁻¹Rˣ to S₁⋆1⊆S₁⁻¹Rˣ ; S⁻¹RHasAlgUniversalProp to S₁⁻¹RHasAlgUniversalProp ; isContrHomS⁻¹RS⁻¹R to isContrHomS₁⁻¹RS₁⁻¹R) open AlgLoc R' S₂ S₂MultClosedSubset renaming ( S⁻¹RAsCommAlg to S₂⁻¹RAsCommAlg ; S⋆1⊆S⁻¹Rˣ to S₂⋆1⊆S₂⁻¹Rˣ ; S⁻¹RHasAlgUniversalProp to S₂⁻¹RHasAlgUniversalProp ; isContrHomS⁻¹RS⁻¹R to isContrHomS₂⁻¹RS₂⁻¹R) open IsAlgebraHom open AlgebraHoms open CommAlgebraHoms open CommAlgebraStr ⦃...⦄ private R = fst R' S₁⁻¹Rˣ = S₁⁻¹RAsCommRing ˣ S₂⁻¹Rˣ = S₂⁻¹RAsCommRing ˣ instance _ = snd S₁⁻¹RAsCommAlg _ = snd S₂⁻¹RAsCommAlg isContrS₁⁻¹R≡S₂⁻¹R : (∀ s₁ → s₁ ∈ S₁ → s₁ ⋆ 1a ∈ S₂⁻¹Rˣ) → (∀ s₂ → s₂ ∈ S₂ → s₂ ⋆ 1a ∈ S₁⁻¹Rˣ) → isContr (S₁⁻¹RAsCommAlg ≡ S₂⁻¹RAsCommAlg) isContrS₁⁻¹R≡S₂⁻¹R S₁⊆S₂⁻¹Rˣ S₂⊆S₁⁻¹Rˣ = isOfHLevelRetractFromIso 0 (equivToIso (invEquiv (CommAlgebraPath _ _ _))) isContrS₁⁻¹R≅S₂⁻¹R where χ₁ : CommAlgebraHom S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg χ₁ = S₁⁻¹RHasAlgUniversalProp S₂⁻¹RAsCommAlg S₁⊆S₂⁻¹Rˣ .fst χ₂ : CommAlgebraHom S₂⁻¹RAsCommAlg S₁⁻¹RAsCommAlg χ₂ = S₂⁻¹RHasAlgUniversalProp S₁⁻¹RAsCommAlg S₂⊆S₁⁻¹Rˣ .fst χ₁∘χ₂≡id : χ₁ ∘a χ₂ ≡ idCommAlgebraHom _ χ₁∘χ₂≡id = isContr→isProp isContrHomS₂⁻¹RS₂⁻¹R _ _ χ₂∘χ₁≡id : χ₂ ∘a χ₁ ≡ idCommAlgebraHom _ χ₂∘χ₁≡id = isContr→isProp isContrHomS₁⁻¹RS₁⁻¹R _ _ IsoS₁⁻¹RS₂⁻¹R : Iso S₁⁻¹R S₂⁻¹R Iso.fun IsoS₁⁻¹RS₂⁻¹R = fst χ₁ Iso.inv IsoS₁⁻¹RS₂⁻¹R = fst χ₂ Iso.rightInv IsoS₁⁻¹RS₂⁻¹R = funExt⁻ (cong fst χ₁∘χ₂≡id) Iso.leftInv IsoS₁⁻¹RS₂⁻¹R = funExt⁻ (cong fst χ₂∘χ₁≡id) isContrS₁⁻¹R≅S₂⁻¹R : isContr (CommAlgebraEquiv S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg) isContrS₁⁻¹R≅S₂⁻¹R = center , uniqueness where center : CommAlgebraEquiv S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg fst center = isoToEquiv IsoS₁⁻¹RS₂⁻¹R pres0 (snd center) = pres0 (snd χ₁) pres1 (snd center) = pres1 (snd χ₁) pres+ (snd center) = pres+ (snd χ₁) pres· (snd center) = pres· (snd χ₁) pres- (snd center) = pres- (snd χ₁) pres⋆ (snd center) = pres⋆ (snd χ₁) uniqueness : (φ : CommAlgebraEquiv S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg) → center ≡ φ uniqueness φ = Σ≡Prop (λ _ → isPropIsAlgebraHom _ _ _ _) (equivEq (cong fst (S₁⁻¹RHasAlgUniversalProp S₂⁻¹RAsCommAlg S₁⊆S₂⁻¹Rˣ .snd (AlgebraEquiv→AlgebraHom φ)))) isPropS₁⁻¹R≡S₂⁻¹R : isProp (S₁⁻¹RAsCommAlg ≡ S₂⁻¹RAsCommAlg) isPropS₁⁻¹R≡S₂⁻¹R S₁⁻¹R≡S₂⁻¹R = isContr→isProp (isContrS₁⁻¹R≡S₂⁻¹R S₁⊆S₂⁻¹Rˣ S₂⊆S₁⁻¹Rˣ) S₁⁻¹R≡S₂⁻¹R where S₁⊆S₂⁻¹Rˣ : ∀ s₁ → s₁ ∈ S₁ → s₁ ⋆ 1a ∈ S₂⁻¹Rˣ S₁⊆S₂⁻¹Rˣ s₁ s₁∈S₁ = transport (λ i → _⋆_ ⦃ S₁⁻¹R≡S₂⁻¹R i .snd ⦄ s₁ (1a ⦃ S₁⁻¹R≡S₂⁻¹R i .snd ⦄) ∈ (CommAlgebra→CommRing (S₁⁻¹R≡S₂⁻¹R i)) ˣ) (S₁⋆1⊆S₁⁻¹Rˣ s₁ s₁∈S₁) S₂⊆S₁⁻¹Rˣ : ∀ s₂ → s₂ ∈ S₂ → s₂ ⋆ 1a ∈ S₁⁻¹Rˣ S₂⊆S₁⁻¹Rˣ s₂ s₂∈S₂ = transport (λ i → _⋆_ ⦃ (sym S₁⁻¹R≡S₂⁻¹R) i .snd ⦄ s₂ (1a ⦃ (sym S₁⁻¹R≡S₂⁻¹R) i .snd ⦄) ∈ (CommAlgebra→CommRing ((sym S₁⁻¹R≡S₂⁻¹R) i)) ˣ) (S₂⋆1⊆S₂⁻¹Rˣ s₂ s₂∈S₂) -- A crucial result for the construction of the structure sheaf module DoubleAlgLoc (R : CommRing ℓ) (f g : (fst R)) where open Exponentiation R open InvertingElementsBase open CommRingStr (snd R) hiding (·Rid) open isMultClosedSubset open DoubleLoc R f g hiding (R[1/fg]≡R[1/f][1/g]) open CommAlgChar R open AlgLoc R ([_ⁿ|n≥0] R (f · g)) (powersFormMultClosedSubset R (f · g)) renaming (S⁻¹RAlgCharEquiv to R[1/fg]AlgCharEquiv) open CommIdeal R hiding (subst-∈) renaming (_∈_ to _∈ᵢ_) open isCommIdeal open RadicalIdeal R private ⟨_⟩ : (fst R) → CommIdeal ⟨ f ⟩ = ⟨ replicateFinVec 1 f ⟩[ R ] R[1/fg]AsCommAlgebra = R[1/_]AsCommAlgebra {R = R} (f · g) R[1/fg]ˣ = R[1/_]AsCommRing R (f · g) ˣ R[1/g]AsCommAlgebra = R[1/_]AsCommAlgebra {R = R} g R[1/g]ˣ = R[1/_]AsCommRing R g ˣ R[1/f][1/g]AsCommRing = R[1/_]AsCommRing (R[1/_]AsCommRing R f) [ g , 1r , powersFormMultClosedSubset R f .containsOne ] R[1/f][1/g]AsCommAlgebra = toCommAlg (R[1/f][1/g]AsCommRing , /1/1AsCommRingHom) R[1/fg]≡R[1/f][1/g] : R[1/fg]AsCommAlgebra ≡ R[1/f][1/g]AsCommAlgebra R[1/fg]≡R[1/f][1/g] = uaCommAlgebra (R[1/fg]AlgCharEquiv _ _ pathtoR[1/fg]) doubleLocCancel : g ∈ᵢ √ ⟨ f ⟩ → R[1/f][1/g]AsCommAlgebra ≡ R[1/g]AsCommAlgebra doubleLocCancel g∈√⟨f⟩ = sym R[1/fg]≡R[1/f][1/g] ∙ isContrR[1/fg]≡R[1/g] toUnit1 toUnit2 .fst where open S⁻¹RUniversalProp R ([_ⁿ|n≥0] R g) (powersFormMultClosedSubset R g) renaming (_/1 to _/1ᵍ) open S⁻¹RUniversalProp R ([_ⁿ|n≥0] R (f · g)) (powersFormMultClosedSubset R (f · g)) renaming (_/1 to _/1ᶠᵍ) open AlgLocTwoSubsets R ([_ⁿ|n≥0] R (f · g)) (powersFormMultClosedSubset R (f · g)) ([_ⁿ|n≥0] R g) (powersFormMultClosedSubset R g) renaming (isContrS₁⁻¹R≡S₂⁻¹R to isContrR[1/fg]≡R[1/g]) open CommAlgebraStr ⦃...⦄ hiding (_·_ ; _+_) instance _ = snd R[1/fg]AsCommAlgebra _ = snd R[1/g]AsCommAlgebra toUnit1 : ∀ s → s ∈ [_ⁿ|n≥0] R (f · g) → s ⋆ 1a ∈ R[1/g]ˣ toUnit1 s s∈[fgⁿ|n≥0] = subst-∈ R[1/g]ˣ (sym (·Rid (s /1ᵍ))) (RadicalLemma.toUnit R g (f · g) (radHelper _ _ g∈√⟨f⟩) s s∈[fgⁿ|n≥0]) where radHelper : ∀ x y → x ∈ᵢ √ ⟨ y ⟩ → x ∈ᵢ √ ⟨ y · x ⟩ radHelper x y = PT.rec ((√ ⟨ y · x ⟩) .fst x .snd) (uncurry helper1) where helper1 : (n : ℕ) → x ^ n ∈ᵢ ⟨ y ⟩ → x ∈ᵢ √ ⟨ y · x ⟩ helper1 n = PT.rec ((√ ⟨ y · x ⟩) .fst x .snd) (uncurry helper2) where helper2 : (α : FinVec (fst R) 1) → x ^ n ≡ linearCombination R α (replicateFinVec 1 y) → x ∈ᵢ √ ⟨ y · x ⟩ helper2 α p = ∣ (suc n) , ∣ α , cong (x ·_) p ∙ useSolver x y (α zero) ∣₁ ∣₁ where useSolver : ∀ x y a → x · (a · y + 0r) ≡ a · (y · x) + 0r useSolver = solve R toUnit2 : ∀ s → s ∈ [_ⁿ|n≥0] R g → s ⋆ 1a ∈ R[1/fg]ˣ toUnit2 s s∈[gⁿ|n≥0] = subst-∈ R[1/fg]ˣ (sym (·Rid (s /1ᶠᵍ))) (RadicalLemma.toUnit R (f · g) g radHelper s s∈[gⁿ|n≥0]) where radHelper : (f · g) ∈ᵢ √ ⟨ g ⟩ radHelper = ·Closed (snd (√ ⟨ g ⟩)) f (∈→∈√ _ _ (indInIdeal R _ zero))
41.351266
100
0.598225
d0a41a9ca2e8056c03805efcffb27bbd01939c20
633
agda
Agda
test/Succeed/ProjectionLikeFunctions.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/ProjectionLikeFunctions.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/ProjectionLikeFunctions.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Getting projection like functions right was a little tricky. -- Here are the cases that didn't work and weren't caught by -- existing test cases. module ProjectionLikeFunctions where record Wrap (A : Set) : Set where constructor [_] field unwrap : A postulate Nat : Set n : Nat Thm : Nat → Set prf : ∀ n → Thm n module M x (p : Thm x) (w : Wrap Nat) where module W = Wrap w module M′ = M n (prf n) ([ n ]) test₁ : Thm M′.W.unwrap test₁ = prf n eq! : ∀ x (S : Thm x) → Wrap Nat → Nat eq! s S [n] = W.unwrap module Local where module W = Wrap [n] test₂ : Thm (eq! n (prf n) [ n ]) test₂ = prf n
20.419355
63
0.614534
c760824c8197c9b39d46235b6a7d0b86c4d39a69
123
agda
Agda
test/Succeed/SafeFlagSafePragmas.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Succeed/SafeFlagSafePragmas.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Succeed/SafeFlagSafePragmas.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --universe-polymorphism --no-irrelevant-projections --cubical-compatible #-} module SafeFlagSafePragmas where
30.75
88
0.788618
14d178e916e787e6dadd9cc869074151e54239c1
504
agda
Agda
src/agda/FRP/JS/Geolocation.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
63
2015-04-20T21:47:00.000Z
2022-02-28T09:46:14.000Z
src/agda/FRP/JS/Geolocation.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
null
null
null
src/agda/FRP/JS/Geolocation.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
7
2016-11-07T21:50:58.000Z
2022-03-12T11:39:38.000Z
-- Partial Agda bindings for the W3C Geolocation API -- http://dev.w3.org/geo/api/spec-source.html -- Not supporting the "read once" API or any of the options yet. open import FRP.JS.Behaviour using ( Beh ; map ) open import FRP.JS.Geolocation.Coords using ( Coords ) open import FRP.JS.Maybe using ( Maybe ) open import FRP.JS.RSet using ( ⟦_⟧ ; ⟨_⟩ ) module FRP.JS.Geolocation where postulate geolocation : ⟦ Beh ⟨ Maybe Coords ⟩ ⟧ {-# COMPILED_JS geolocation require("agda.frp").geolocation #-}
31.5
64
0.720238
37d43470a0ea791917cfb8da8d4d86a3745d12f0
1,151
agda
Agda
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/Poset.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/Poset.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/Poset.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by posets ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Properties.Poset {p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where open Relation.Binary.Poset P hiding (trans) open import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_ open import Relation.Binary.Properties.Preorder preorder open import Function using (flip) -- The inverse relation is also a poset. invIsPartialOrder : IsPartialOrder _≈_ (flip _≤_) invIsPartialOrder = record { isPreorder = invIsPreorder ; antisym = flip antisym } invPoset : Poset p₁ p₂ p₃ invPoset = record { isPartialOrder = invIsPartialOrder } ------------------------------------------------------------------------ -- Posets can be turned into strict partial orders strictPartialOrder : StrictPartialOrder _ _ _ strictPartialOrder = record { isStrictPartialOrder = <-isStrictPartialOrder isPartialOrder } open StrictPartialOrder strictPartialOrder
29.512821
72
0.616855
cc0a71b7039ab92459af8727129df83e806e623e
1,701
agda
Agda
Cats/Category/Constructions/Equalizer.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
24
2017-11-03T15:18:57.000Z
2021-08-06T05:00:46.000Z
Cats/Category/Constructions/Equalizer.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
null
null
null
Cats/Category/Constructions/Equalizer.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
1
2019-03-18T15:35:07.000Z
2019-03-18T15:35:07.000Z
{-# OPTIONS --without-K --safe #-} module Cats.Category.Constructions.Equalizer where open import Level open import Cats.Category.Base open import Cats.Util.Conv import Cats.Category.Constructions.Mono as Mono import Cats.Category.Constructions.Unique as Unique module Build {lo la l≈} (Cat : Category lo la l≈) where private open module Cat = Category Cat open Cat.≈-Reasoning open Mono.Build Cat open Unique.Build Cat record IsEqualizer {A B} (f g : A ⇒ B) {E} (e : E ⇒ A) : Set (lo ⊔ la ⊔ l≈) where field equalizes : f ∘ e ≈ g ∘ e universal : ∀ {Z} (z : Z ⇒ A) → f ∘ z ≈ g ∘ z → ∃![ u ] (e ∘ u ≈ z) record Equalizer {A B} (f g : A ⇒ B) : Set (lo ⊔ la ⊔ l≈) where field {E} : Obj e : E ⇒ A isEqualizer : IsEqualizer f g e open IsEqualizer isEqualizer public instance HasObj-Equalizer : ∀ {A B} {f g : A ⇒ B} → HasObj (Equalizer f g) lo la l≈ HasObj-Equalizer = record { Cat = Cat ; _ᴼ = Equalizer.E } HasArrow-Equalizer : ∀ {A B} {f g : A ⇒ B} → HasArrow (Equalizer f g) lo la l≈ HasArrow-Equalizer = record { Cat = Cat ; _⃗ = Equalizer.e } equalizer→mono : ∀ {A B} {f g : A ⇒ B} {E} {e : E ⇒ A} → IsEqualizer f g e → IsMono e equalizer→mono {f = f} {g} {E} {e} eql {Z} {i} {j} e∘i≈e∘j = ∃!→≈ (universal (e ∘ j) lemma) e∘i≈e∘j ≈.refl where open IsEqualizer eql lemma : f ∘ e ∘ j ≈ g ∘ e ∘ j lemma = begin f ∘ e ∘ j ≈⟨ unassoc ⟩ (f ∘ e) ∘ j ≈⟨ ∘-resp-l equalizes ⟩ (g ∘ e) ∘ j ≈⟨ assoc ⟩ g ∘ e ∘ j ∎ open Build public
23.30137
65
0.519106
8bdd09752ddc9853aad58ccf12721d9551572f9a
604
agda
Agda
examples/lib/Logic/Structure/Applicative.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/lib/Logic/Structure/Applicative.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/lib/Logic/Structure/Applicative.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Logic.Structure.Applicative where data Applicative (f : Set -> Set) : Set1 where applicative : (pure : {a : Set} -> a -> f a) (_<*>_ : {a b : Set} -> f (a -> b) -> f a -> f b) -> Applicative f module ApplicativeM {f : Set -> Set}(App : Applicative f) where private pure' : Applicative f -> {a : Set} -> a -> f a pure' (applicative p _) = p app' : Applicative f -> {a b : Set} -> f (a -> b) -> f a -> f b app' (applicative _ a) = a pure : {a : Set} -> a -> f a pure = pure' App _<*>_ : {a b : Set} -> f (a -> b) -> f a -> f b _<*>_ = app' App
24.16
67
0.490066
fdd8e1856cf05cb3faf5f444f63ec7a07ecb3c33
2,237
agda
Agda
LibraBFT/Impl/OBM/Logging/Logging.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
4
2020-12-16T19:43:41.000Z
2021-12-18T19:24:05.000Z
LibraBFT/Impl/OBM/Logging/Logging.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
72
2021-02-04T05:04:33.000Z
2022-03-25T05:36:11.000Z
LibraBFT/Impl/OBM/Logging/Logging.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
6
2020-12-16T19:43:52.000Z
2022-02-18T01:04:32.000Z
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 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 LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Interface.Output open import LibraBFT.ImplShared.Util.Util open import LibraBFT.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) module LibraBFT.Impl.OBM.Logging.Logging where -- NOTE: Logging operations change the structure of the program, and proofs about peer -- operations are sensitive to this structure. Therefore, we add a "skeleton" of -- logging operations so that future refinements do not break existing proofs. -- In the future, we may wish to model and reason about errors and logging in more detail. postulate -- TODO-1 : errText : Note, the existing Agda ErrLog constructors do not contain text. errText : ErrLog → List String errText' : ErrLog → String logErr : ErrLog → LBFT Unit logErr x = tell1 (LogErr x) logInfo : InfoLog → LBFT Unit logInfo x = tell1 (LogInfo x) logEE : ∀ {A} → List String → LBFT A → LBFT A logEE _ f = logInfo fakeInfo >> f >>= λ r → logInfo fakeInfo >> pure r withErrCtx : List String → ErrLog → ErrLog withErrCtx _ = id withErrCtx' : ∀ {A} → List String → Either ErrLog A → Either ErrLog A withErrCtx' ctx = λ where (Left e) → Left (withErrCtx ctx e) (Right b) → pure b withErrCtxD' : ∀ {ℓ} {E : Set → Set → Set ℓ} ⦃ _ : EitherLike E ⦄ → ∀ {A : Set} → List String → E ErrLog A → EitherD ErrLog A withErrCtxD' ctx e = case toEither e of λ where (Left e) → fromEither $ Left (withErrCtx ctx e) (Right b) → fromEither $ Right b lcheck : ∀ {ℓ} {B : Set ℓ} ⦃ _ : ToBool B ⦄ → B → List String → Either ErrLog Unit lcheck b t = case check (toBool b) t of λ where (Left e) → Left fakeErr -- (ErrL [e]) (Right r) → Right r lcheckInfo : ∀ {ℓ} {B : Set ℓ} ⦃ _ : ToBool B ⦄ → B → List String → Either ErrLog Unit lcheckInfo b t = case check (toBool b) t of λ where (Left _) → Left (ErrInfo fakeInfo {-InfoL [e]-}) (Right r) → Right r
37.915254
111
0.663835
5224f53b4e5f7c485569e497119e3295bf5f8c5a
2,809
agda
Agda
src/Tactic/Deriving/Quotable.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Deriving/Quotable.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Deriving/Quotable.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
module Tactic.Deriving.Quotable where open import Prelude open import Container.Traversable open import Tactic.Reflection open import Tactic.Reflection.Quote.Class open import Tactic.Deriving private -- Bootstrapping qVis : Visibility → Term qVis visible = con (quote visible) [] qVis hidden = con (quote hidden) [] qVis instance′ = con (quote instance′) [] qRel : Relevance → Term qRel relevant = con (quote relevant) [] qRel irrelevant = con (quote irrelevant) [] qArgInfo : ArgInfo → Term qArgInfo (arg-info v r) = con₂ (quote arg-info) (qVis v) (qRel r) qArg : Arg Term → Term qArg (arg i x) = con₂ (quote arg) (qArgInfo i) x qList : List Term → Term qList = foldr (λ x xs → con₂ (quote List._∷_) x xs) (con₀ (quote List.[])) -- Could compute this from the type of the dictionary constructor quoteType : Name → TC Type quoteType d = caseM instanceTelescope d (quote Quotable) of λ { (tel , vs) → pure $ telPi tel $ def d vs `→ def (quote Term) [] } dictConstructor : TC Name dictConstructor = caseM getConstructors (quote Quotable) of λ { (c ∷ []) → pure c ; _ → typeErrorS "impossible" } patArgs : Telescope → List (Arg Pattern) patArgs tel = zipWith (λ x (_ , a) → var x <$ a) (reverse (from 0 for (length tel))) tel quoteArgs′ : Nat → Telescope → List Term quoteArgs′ 0 _ = [] quoteArgs′ _ [] = [] quoteArgs′ (suc n) ((x , a) ∷ tel) = qArg (def₁ (quote `) (var n []) <$ a) ∷ quoteArgs′ n tel quoteArgs : Nat → Telescope → Term quoteArgs pars tel = qList $ replicate pars (qArg $ hArg (con₀ (quote Term.unknown))) ++ quoteArgs′ (length tel) tel constructorClause : Nat → Name → TC Clause constructorClause pars c = do tel ← drop pars ∘ fst ∘ telView <$> getType c pure (clause tel (vArg (con c (patArgs tel)) ∷ []) (con₂ (quote Term.con) (lit (name c)) (quoteArgs pars tel))) quoteClauses : Name → TC (List Clause) quoteClauses d = do n ← getParameters d caseM getConstructors d of λ where [] → pure [ absurd-clause (("()" , vArg unknown) ∷ []) (vArg absurd ∷ []) ] cs → mapM (constructorClause n) cs declareQuotableInstance : Name → Name → TC ⊤ declareQuotableInstance iname d = declareDef (iArg iname) =<< instanceType d (quote Quotable) defineQuotableInstance : Name → Name → TC ⊤ defineQuotableInstance iname d = do fname ← freshName ("quote[" & show d & "]") declareDef (vArg fname) =<< quoteType d dictCon ← dictConstructor defineFun iname (clause [] [] (con₁ dictCon (def₀ fname)) ∷ []) defineFun fname =<< quoteClauses d return _ deriveQuotable : Name → Name → TC ⊤ deriveQuotable iname d = declareQuotableInstance iname d >> defineQuotableInstance iname d
31.920455
90
0.640441
cccb315ebad54a56a9a7f841b23e92d477522578
440
agda
Agda
bool-test.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
29
2019-02-06T13:09:31.000Z
2022-03-04T15:05:12.000Z
bool-test.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
8
2018-07-09T22:53:38.000Z
2022-03-22T03:43:34.000Z
bool-test.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
17
2018-12-03T22:38:15.000Z
2021-11-28T20:13:21.000Z
module bool-test where open import bool open import eq open import level ~~tt : ~ ~ tt ≡ tt ~~tt = refl ~~ff : ~ ~ ff ≡ ff ~~ff = refl ~~-elim2 : ∀ (b : 𝔹) → ~ ~ b ≡ b ~~-elim2 tt = ~~tt ~~-elim2 ff = ~~ff ~~tt' : ~ ~ tt ≡ tt ~~tt' = refl{lzero}{𝔹}{tt} ~~ff' : ~ ~ ff ≡ ff ~~ff' = refl{lzero}{𝔹}{ff} test1 : 𝔹 test1 = tt && ff test2 : 𝔹 test2 = tt && tt test1-ff : test1 ≡ ff test1-ff = refl test2-tt : test2 ≡ tt test2-tt = refl
12.941176
32
0.525
cc02bf734213fdd740c9ba2fcc8ab09c8a289a45
93
agda
Agda
test/Fail/Issue215.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/fail/Issue215.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/Issue215.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Issue215 where open import Imports.Bool {-# COMPILED_DATA Bool Bool True False #-}
13.285714
42
0.752688
36b8802cc2e0436d5cb67c5b0083ed861b9286e6
3,750
agda
Agda
src/Data/Finitude/Permutation.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
src/Data/Finitude/Permutation.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
src/Data/Finitude/Permutation.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
module Data.Finitary.Permutation where open import Data.Nat open import Data.Fin open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_) open import Function.Inverse as Inv using (Inverse) import Function.Equality as F open import Function.LeftInverse using (_LeftInverseOf_) open import Data.Finitary open import Data.Vec as Vec using (Vec) open import Data.Vec.Distinct as Distinct using (Distinct) open import Data.Product hiding (swap) Permutation : ℕ → Set Permutation n = Finitary (P.setoid (Fin n)) n identity : ∀ {n} → Permutation n identity = Inv.id swap : ∀ {n} → Fin n → Fin n → Permutation n swap {n} i j = record { to = P.→-to-⟶ swap′ ; from = P.→-to-⟶ swap′ ; inverse-of = record { left-inverse-of = swap′-involutive ; right-inverse-of = swap′-involutive } } where open import Data.Fin.Properties as FinP open import Relation.Nullary open import Data.Empty using (⊥-elim) swap′ : Fin n → Fin n swap′ k with k FinP.≟ i swap′ k | yes k≡i = j swap′ k | no ¬p with k FinP.≟ j swap′ k | no ¬p | yes k≡j = i swap′ k | no ¬p | no ¬p₁ = k swap′-involutive : ∀ k → swap′ (swap′ k) ≡ k swap′-involutive k with k FinP.≟ i swap′-involutive k | yes k≡i with k≡i | j FinP.≟ i swap′-involutive _ | yes k≡i | P.refl | yes j≡i = j≡i swap′-involutive _ | yes k≡i | P.refl | no j≢i with j FinP.≟ j swap′-involutive _ | yes k≡i | P.refl | no j≢i | yes j≡j = P.refl swap′-involutive _ | yes k≡i | P.refl | no j≢i | no j≢j = ⊥-elim (j≢j P.refl) swap′-involutive k | no k≢i with k FinP.≟ j swap′-involutive k | no k≢i | yes k≡j with k≡j | i FinP.≟ i swap′-involutive k | no k≢i | yes k≡j | P.refl | yes P.refl = P.refl swap′-involutive k | no k≢i | yes k≡j | P.refl | no i≢i = ⊥-elim (i≢i P.refl) swap′-involutive k | no k≢i | no k≢j = lemma k≢i k≢j where open P.≡-Reasoning lemma : ∀ {k} → k ≢ i → k ≢ j → swap′ k ≡ k lemma {k} k≢i k≢j with k FinP.≟ i lemma k≢i k≢j | yes k≡i = ⊥-elim (k≢i k≡i) lemma {k} k≢i k≢j | no ¬k≡i with k FinP.≟ j lemma {k} k≢i k≢j | no ¬k≡i | yes k≡j = ⊥-elim (k≢j k≡j) lemma {k} k≢i k≢j | no ¬k≡i | no ¬p = P.refl shift : ∀ {n} → Permutation n → Permutation (ℕ.suc n) shift {n} p = record { to = P.→-to-⟶ (shift′ Perm.to) ; from = P.→-to-⟶ (shift′ Perm.from) ; inverse-of = record { left-inverse-of = shift′-inverse-of Perm.left-inverse-of ; right-inverse-of = shift′-inverse-of Perm.right-inverse-of } } where module Perm = Inverse p shift′ : P.setoid (Fin n) F.⟶ P.setoid (Fin n) → Fin (ℕ.suc n) → Fin (ℕ.suc n) shift′ f Fin.zero = Fin.zero shift′ f (Fin.suc i) = Fin.suc (f F.⟨$⟩ i) shift′-inverse-of : ∀ {from : P.setoid (Fin n) F.⟶ P.setoid (Fin n)}{to : P.setoid (Fin n) F.⟶ P.setoid (Fin n)} → from LeftInverseOf to → (P.→-to-⟶ (shift′ from)) LeftInverseOf (P.→-to-⟶ (shift′ to)) shift′-inverse-of inv Fin.zero = P.refl shift′-inverse-of inv (Fin.suc i) = P.cong Fin.suc (inv i) Perm→Distinct : ∀ {n} → Permutation n → ∃ λ (xs : Vec (Fin n) n) → Distinct xs Perm→Distinct {n} p = , xs-distinct where open Inverse p renaming (to to f) open import Data.Vec.Properties xs-distinct : Distinct (Vec.tabulate (f F.⟨$⟩_)) xs-distinct = P.subst Distinct (P.sym (tabulate-allFin _)) (Distinct.map injection (Distinct.allFin n))
41.666667
206
0.5456
0d55825f0121970649e1051364ee2871d2d06eaa
1,105
agda
Agda
Data/Fin/Indexed/Properties.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Fin/Indexed/Properties.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Fin/Indexed/Properties.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --without-K --safe #-} module Data.Fin.Indexed.Properties where open import Agda.Builtin.Nat using (_<_) open import Data.Nat.Base open import Data.Fin.Indexed.Base open import Data.Bool open import Data.Maybe.Base private variable n m k : ℕ weaken : ∀ {n} → Fin n → Fin (suc n) weaken {suc n} f0 = f0 weaken {suc n} (fs x) = fs (weaken x) -- x \\ y | x < y = just x -- | x ≡ y = nothing -- | x > y = just (x - 1) _\\_ : Fin (suc n) → Fin (suc n) → Maybe (Fin n) f0 \\ f0 = nothing fs i \\ f0 = just i _\\_ {suc n} (fs i) (fs j) = mapMaybe fs (i \\ j) _\\_ {suc n} (f0 ) (fs j) = just f0 insert : Fin (suc n) → Fin n → Fin (suc n) insert f0 j = fs j insert (fs i) f0 = f0 insert (fs i) (fs j) = fs (insert i j) weakens : ∀ n → Fin m → Fin (n + m) weakens zero x = x weakens (suc n) x = weaken (weakens n x) _∔_ : Fin n → Fin m → Fin (n + m) f0 ∔ m = weakens _ m fs n ∔ m = fs (n ∔ m) under : (Fin m → Fin k) → Fin (n + m) → Fin (n + k) under {n = zero } f x = f x under {n = suc n} f (fs x) = fs (under f x) under {n = suc n} f f0 = f0
25.697674
51
0.542081
4e60fbf127487434dca6be4c3933c9b906a6b1fe
5,152
agda
Agda
BasicIS4/Semantics/BasicKripkeBozicDosen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIS4/Semantics/BasicKripkeBozicDosen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIS4/Semantics/BasicKripkeBozicDosen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇. -- Basic Kripke-style semantics with abstract worlds, for soundness only. -- Božić-Došen-style conditions. module BasicIS4.Semantics.BasicKripkeBozicDosen where open import BasicIS4.Syntax.Common public -- Intuitionistic modal Kripke models, with frame conditions given by Božić-Došen. record Model : Set₁ where infix 3 _⊩ᵅ_ field World : Set -- Intuitionistic accessibility; preorder. _≤_ : World → World → Set refl≤ : ∀ {w} → w ≤ w trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″ -- Modal accessibility; preorder. _R_ : World → World → Set reflR : ∀ {w} → w R w transR : ∀ {w w′ w″} → w R w′ → w′ R w″ → w R w″ -- Forcing for atomic propositions; monotonic. _⊩ᵅ_ : World → Atom → Set mono⊩ᵅ : ∀ {P w w′} → w ≤ w′ → w ⊩ᵅ P → w′ ⊩ᵅ P -- Composition of accessibility. _≤⨾R_ : World → World → Set _≤⨾R_ = _≤_ ⨾ _R_ _R⨾≤_ : World → World → Set _R⨾≤_ = _R_ ⨾ _≤_ -- Minor persistence condition. -- -- w′ v′ → v′ -- ◌───R───● → ● -- │ → │ -- ≤ ξ,ζ → ≤ -- │ → │ -- ● → ●───R───◌ -- w → w v -- -- w″ → w″ -- ● → ● -- │ → │ -- ξ′,ζ′ ≤ → │ -- │ → │ -- ●───R───◌ → ≤ -- │ v′ → │ -- ξ,ζ ≤ → │ -- │ → │ -- ●───R───◌ → ●───────R───────◌ -- w v → w v″ field ≤⨾R→R⨾≤ : ∀ {v′ w} → w ≤⨾R v′ → w R⨾≤ v′ reflR⨾≤ : ∀ {w} → w R⨾≤ w reflR⨾≤ {w} = w , (reflR , refl≤) transR⨾≤ : ∀ {w′ w w″} → w R⨾≤ w′ → w′ R⨾≤ w″ → w R⨾≤ w″ transR⨾≤ {w′} (v , (ζ , ξ)) (v′ , (ζ′ , ξ′)) = let v″ , (ζ″ , ξ″) = ≤⨾R→R⨾≤ (w′ , (ξ , ζ′)) in v″ , (transR ζ ζ″ , trans≤ ξ″ ξ′) open Model {{…}} public -- Forcing in a particular world of a particular model. module _ {{_ : Model}} where infix 3 _⊩_ _⊩_ : World → Ty → Set w ⊩ α P = w ⊩ᵅ P w ⊩ A ▻ B = ∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B w ⊩ □ A = ∀ {v′} → w R v′ → v′ ⊩ A w ⊩ A ∧ B = w ⊩ A × w ⊩ B w ⊩ ⊤ = 𝟙 infix 3 _⊩⋆_ _⊩⋆_ : World → Cx Ty → Set w ⊩⋆ ∅ = 𝟙 w ⊩⋆ Ξ , A = w ⊩⋆ Ξ × w ⊩ A -- Monotonicity with respect to intuitionistic accessibility. module _ {{_ : Model}} where mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A mono⊩ {α P} ξ s = mono⊩ᵅ ξ s mono⊩ {A ▻ B} ξ s = λ ξ′ a → s (trans≤ ξ ξ′) a mono⊩ {□ A} ξ s = λ ζ → let v , (ζ′ , ξ′) = ≤⨾R→R⨾≤ (_ , (ξ , ζ)) in mono⊩ {A} ξ′ (s ζ′) mono⊩ {A ∧ B} ξ s = mono⊩ {A} ξ (π₁ s) , mono⊩ {B} ξ (π₂ s) mono⊩ {⊤} ξ s = ∙ mono⊩⋆ : ∀ {Γ w w′} → w ≤ w′ → w ⊩⋆ Γ → w′ ⊩⋆ Γ mono⊩⋆ {∅} ξ ∙ = ∙ mono⊩⋆ {Γ , A} ξ (γ , a) = mono⊩⋆ {Γ} ξ γ , mono⊩ {A} ξ a -- Additional useful equipment. module _ {{_ : Model}} where _⟪$⟫_ : ∀ {A B w} → w ⊩ A ▻ B → w ⊩ A → w ⊩ B s ⟪$⟫ a = s refl≤ a ⟪K⟫ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ⟪K⟫ {A} a ξ = K (mono⊩ {A} ξ a) ⟪S⟫ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ A ▻ B → w ⊩ A → w ⊩ C ⟪S⟫ {A} {B} {C} s₁ s₂ a = _⟪$⟫_ {B} {C} (_⟪$⟫_ {A} {B ▻ C} s₁ a) (_⟪$⟫_ {A} {B} s₂ a) ⟪S⟫′ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ (A ▻ B) ▻ A ▻ C ⟪S⟫′ {A} {B} {C} s₁ ξ s₂ ξ′ a = let s₁′ = mono⊩ {A ▻ B ▻ C} (trans≤ ξ ξ′) s₁ s₂′ = mono⊩ {A ▻ B} ξ′ s₂ in ⟪S⟫ {A} {B} {C} s₁′ s₂′ a _⟪D⟫_ : ∀ {A B w} → w ⊩ □ (A ▻ B) → w ⊩ □ A → w ⊩ □ B _⟪D⟫_ {A} {B} s₁ s₂ ζ = let s₁′ = s₁ ζ s₂′ = s₂ ζ in _⟪$⟫_ {A} {B} s₁′ s₂′ _⟪D⟫′_ : ∀ {A B w} → w ⊩ □ (A ▻ B) → w ⊩ □ A ▻ □ B _⟪D⟫′_ {A} {B} s₁ ξ = _⟪D⟫_ {A} {B} (mono⊩ {□ (A ▻ B)} ξ s₁) ⟪↑⟫ : ∀ {A w} → w ⊩ □ A → w ⊩ □ □ A ⟪↑⟫ s ζ ζ′ = s (transR ζ ζ′) ⟪↓⟫ : ∀ {A w} → w ⊩ □ A → w ⊩ A ⟪↓⟫ s = s reflR _⟪,⟫′_ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ∧ B _⟪,⟫′_ {A} {B} a ξ = _,_ (mono⊩ {A} ξ a) -- Forcing in a particular world of a particular model, for sequents. module _ {{_ : Model}} where infix 3 _⊩_⇒_ _⊩_⇒_ : World → Cx Ty → Ty → Set w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A infix 3 _⊩_⇒⋆_ _⊩_⇒⋆_ : World → Cx Ty → Cx Ty → Set w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ -- Entailment, or forcing in all worlds of all models, for sequents. infix 3 _⊨_ _⊨_ : Cx Ty → Ty → Set₁ Γ ⊨ A = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒ A infix 3 _⊨⋆_ _⊨⋆_ : Cx Ty → Cx Ty → Set₁ Γ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒⋆ Ξ infix 3 _⁏_⊨_ _⁏_⊨_ : Cx Ty → Cx Ty → Ty → Set₁ Γ ⁏ Δ ⊨ A = ∀ {{_ : Model}} {w : World} → w ⊩⋆ Γ → (∀ {v′} → w R v′ → v′ ⊩⋆ Δ) → w ⊩ A -- Additional useful equipment, for sequents. module _ {{_ : Model}} where lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A lookup top (γ , a) = a lookup (pop i) (γ , b) = lookup i γ
28.94382
93
0.365295
4e48c0a07b1123fd546631f177b491d01366c48c
2,413
agda
Agda
Cubical/HITs/Susp/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/HITs/Susp/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/HITs/Susp/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Susp.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Data.Bool open import Cubical.HITs.Join open import Cubical.HITs.Susp.Base open Iso Susp-iso-joinBool : ∀ {ℓ} {A : Type ℓ} → Iso (Susp A) (join A Bool) fun Susp-iso-joinBool north = inr true fun Susp-iso-joinBool south = inr false fun Susp-iso-joinBool (merid a i) = (sym (push a true) ∙ push a false) i inv Susp-iso-joinBool (inr true ) = north inv Susp-iso-joinBool (inr false) = south inv Susp-iso-joinBool (inl _) = north inv Susp-iso-joinBool (push a true i) = north inv Susp-iso-joinBool (push a false i) = merid a i rightInv Susp-iso-joinBool (inr true ) = refl rightInv Susp-iso-joinBool (inr false) = refl rightInv Susp-iso-joinBool (inl a) = sym (push a true) rightInv Susp-iso-joinBool (push a true i) j = push a true (i ∨ ~ j) rightInv Susp-iso-joinBool (push a false i) j = hcomp (λ k → λ { (i = i0) → push a true (~ j) ; (i = i1) → push a false k ; (j = i1) → push a false (i ∧ k) }) (push a true (~ i ∧ ~ j)) leftInv Susp-iso-joinBool north = refl leftInv Susp-iso-joinBool south = refl leftInv (Susp-iso-joinBool {A = A}) (merid a i) j = hcomp (λ k → λ { (i = i0) → transp (λ _ → Susp A) (k ∨ j) north ; (i = i1) → transp (λ _ → Susp A) (k ∨ j) (merid a k) ; (j = i1) → merid a (i ∧ k) }) (transp (λ _ → Susp A) j north) Susp≃joinBool : ∀ {ℓ} {A : Type ℓ} → Susp A ≃ join A Bool Susp≃joinBool = isoToEquiv Susp-iso-joinBool Susp≡joinBool : ∀ {ℓ} {A : Type ℓ} → Susp A ≡ join A Bool Susp≡joinBool = isoToPath Susp-iso-joinBool congSuspEquiv : ∀ {ℓ} {A B : Type ℓ} → A ≃ B → Susp A ≃ Susp B congSuspEquiv {ℓ} {A} {B} h = isoToEquiv isom where isom : Iso (Susp A) (Susp B) fun isom north = north fun isom south = south fun isom (merid a i) = merid (fst h a) i inv isom north = north inv isom south = south inv isom (merid a i) = merid (invEq h a) i rightInv isom north = refl rightInv isom south = refl rightInv isom (merid a i) j = merid (retEq h a j) i leftInv isom north = refl leftInv isom south = refl leftInv isom (merid a i) j = merid (secEq h a j) i
39.557377
73
0.61666
d17b1f0b66b9479fa486cb5f7b5261afc2461209
10,387
agda
Agda
Univalence/Obsolete/VectorLemmas.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
Univalence/Obsolete/VectorLemmas.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
Univalence/Obsolete/VectorLemmas.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
3
2016-05-29T01:56:33.000Z
2019-09-10T09:47:13.000Z
{-# OPTIONS --without-K #-} module VectorLemmas where open import Level using (Level) open import Data.Vec using (Vec; tabulate; []; _∷_; lookup; allFin) renaming (_++_ to _++V_; map to mapV; concat to concatV) open import Data.Vec.Properties using (lookup-++-≥; lookup∘tabulate; tabulate-∘; tabulate∘lookup; tabulate-allFin) open import Function using (id;_∘_;flip) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong; cong₂; subst; trans; proof-irrelevance; module ≡-Reasoning) open import Data.Nat using (ℕ; zero; suc; _+_; z≤n; _*_) open import Data.Nat.Properties.Simple using (+-comm; +-right-identity) open import Data.Fin using (Fin; zero; suc; inject+; raise; reduce≥) open import Data.Fin.Properties using (toℕ-injective) open import Data.Sum using (_⊎_; [_,_]′; inj₁; inj₂) renaming (map to map⊎) open import SubstLemmas open import FinNatLemmas open import FiniteFunctions ------------------------------------------------------------------------------ -- Lemmas about map and tabulate -- to make things look nicer _!!_ : ∀ {m} {A : Set} → Vec A m → Fin m → A v !! i = lookup i v -- this is actually in Data.Vec.Properties, but over an arbitrary -- Setoid. Specialize map-id : ∀ {a n} {A : Set a} (xs : Vec A n) → mapV id xs ≡ xs map-id [] = refl map-id (x ∷ xs) = cong (_∷_ x) (map-id xs) map-++-commute : ∀ {a b m n} {A : Set a} {B : Set b} (f : B → A) (xs : Vec B m) {ys : Vec B n} → mapV f (xs ++V ys) ≡ mapV f xs ++V mapV f ys map-++-commute f [] = refl map-++-commute f (x ∷ xs) = cong (λ z → f x ∷ z) (map-++-commute f xs) -- this is too, but is done "point free", this version is more convenient map-∘ : ∀ {a b c n} {A : Set a} {B : Set b} {C : Set c} (f : B → C) (g : A → B) → (xs : Vec A n) → mapV (f ∘ g) xs ≡ (mapV f ∘ mapV g) xs map-∘ f g [] = refl map-∘ f g (x ∷ xs) = cong (_∷_ (f (g x))) (map-∘ f g xs) -- this looks trivial, why can't I find it? lookup-map : ∀ {a b} {n : ℕ} {A : Set a} {B : Set b} → (i : Fin n) → (f : A → B) → (v : Vec A n) → lookup i (mapV f v) ≡ f (lookup i v) lookup-map {n = 0} () _ _ lookup-map {n = suc n} zero f (x ∷ v) = refl lookup-map {n = suc n} (suc i) f (x ∷ v) = lookup-map i f v -- These are 'generalized' lookup into left/right parts of a Vector which -- does not depend on the values in the Vector at all. look-left : ∀ {m n} {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → (i : Fin m) → (f : A → C) → (g : B → C) → (vm : Vec A m) → (vn : Vec B n) → lookup (inject+ n i) (mapV f vm ++V mapV g vn) ≡ f (lookup i vm) look-left {0} () _ _ _ _ look-left {suc _} zero f g (x ∷ vm) vn = refl look-left {suc _} (suc i) f g (x ∷ vm) vn = look-left i f g vm vn look-right : ∀ {m n} {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → (i : Fin n) → (f : A → C) → (g : B → C) → (vm : Vec A m) → (vn : Vec B n) → lookup (raise m i) (mapV f vm ++V mapV g vn) ≡ g (lookup i vn) look-right {0} i f g vn vm = lookup-map i g vm look-right {suc m} {0} () _ _ _ _ look-right {suc m} {suc n} i f g (x ∷ vn) vm = look-right i f g vn vm -- variant left!! : ∀ {m n} {C : Set} → (i : Fin m) → (f : Fin m → C) → {g : Fin n → C} → (tabulate f ++V tabulate g) !! (inject+ n i) ≡ f i left!! {zero} () _ left!! {suc _} zero f = refl left!! {suc _} (suc i) f = left!! i (f ∘ suc) right!! : ∀ {m n} {C : Set} → (i : Fin n) → {f : Fin m → C} → (g : Fin n → C) → (tabulate f ++V tabulate g) !! (raise m i) ≡ g i right!! {zero} i g = lookup∘tabulate g i right!! {suc _} {0} () _ right!! {suc m} {suc _} i g = right!! {m} i g -- similar to lookup-++-inject+ from library lookup-++-raise : ∀ {m n} {a : Level} {A : Set a} → (vm : Vec A m) (vn : Vec A n) (i : Fin n) → lookup (raise m i) (vm ++V vn) ≡ lookup i vn lookup-++-raise {0} vn vm i = begin (lookup i (vn ++V vm) ≡⟨ lookup-++-≥ vn vm i z≤n ⟩ lookup (reduce≥ i z≤n) vm ≡⟨ refl ⟩ lookup i vm ∎) where open ≡-Reasoning -- lookup-++-raise {suc m} {0} _ _ () lookup-++-raise {suc m} {suc n} (x ∷ vn) vm i = lookup-++-raise vn vm i -- concat (map (map f) xs) = map f (concat xs) concat-map : ∀ {a b m n} {A : Set a} {B : Set b} → (xs : Vec (Vec A n) m) → (f : A → B) → concatV (mapV (mapV f) xs) ≡ mapV f (concatV xs) concat-map [] f = refl concat-map (xs ∷ xss) f = begin (concatV (mapV (mapV f) (xs ∷ xss)) ≡⟨ refl ⟩ concatV (mapV f xs ∷ mapV (mapV f) xss) ≡⟨ refl ⟩ mapV f xs ++V concatV (mapV (mapV f) xss) ≡⟨ cong (_++V_ (mapV f xs)) (concat-map xss f) ⟩ mapV f xs ++V mapV f (concatV xss) ≡⟨ sym (map-++-commute f xs) ⟩ mapV f (xs ++V concatV xss) ≡⟨ refl ⟩ mapV f (concatV (xs ∷ xss)) ∎) where open ≡-Reasoning map-map-map : ∀ {a b c m n} {A : Set a} {B : Set b} {C : Set c} → (f : B → C) → (g : A → Vec B n) → (xs : Vec A m) → mapV (mapV f) (mapV g xs) ≡ mapV (mapV f ∘ g) xs map-map-map f g xss = sym (map-∘ (mapV f) g xss) splitV+ : ∀ {m n} {a : Level} {A : Set a} {f : Fin (m + n) → A} → Vec A (m + n) splitV+ {m} {n} {f = f} = tabulate {m} (f ∘ inject+ n) ++V tabulate {n} (f ∘ raise m) splitVOp+ : ∀ {m} {n} {a : Level} {A : Set a} {f : Fin (n + m) → A} → Vec A (m + n) splitVOp+ {m} {n} {f = f} = tabulate {m} (f ∘ raise n) ++V tabulate {n} (f ∘ inject+ m) -- f can be implicit since this is mostly used in equational reasoning, where it can be inferred! tabulate-split : ∀ {m n} {a : Level} {A : Set a} → {f : Fin (m + n) → A} → tabulate {m + n} f ≡ splitV+ {m} {n} {f = f} tabulate-split {0} = refl tabulate-split {suc m} {f = f} = cong (_∷_ (f zero)) (tabulate-split {m} {f = f ∘ suc}) lookup-subst : ∀ {m m' n} (i : Fin n) (xs : Vec (Fin m) n) (eq : m ≡ m') → lookup i (subst (λ s → Vec (Fin s) n) eq xs) ≡ subst Fin eq (lookup i xs) lookup-subst i xs refl = refl -- lookup is associative on Fin vectors lookupassoc : ∀ {m₁ m₂ m₃ m₄} → (π₁ : Vec (Fin m₂) m₁) (π₂ : Vec (Fin m₃) m₂) (π₃ : Vec (Fin m₄) m₃) → (i : Fin m₁) → lookup (lookup i π₁) (tabulate (λ j → lookup (lookup j π₂) π₃)) ≡ lookup (lookup i (tabulate (λ j → lookup (lookup j π₁) π₂))) π₃ lookupassoc π₁ π₂ π₃ i = begin (lookup (lookup i π₁) (tabulate (λ j → lookup (lookup j π₂) π₃)) ≡⟨ lookup∘tabulate (λ j → lookup (lookup j π₂) π₃) (lookup i π₁) ⟩ lookup (lookup (lookup i π₁) π₂) π₃ ≡⟨ cong (λ x → lookup x π₃) (sym (lookup∘tabulate (λ j → lookup (lookup j π₁) π₂) i)) ⟩ lookup (lookup i (tabulate (λ j → lookup (lookup j π₁) π₂))) π₃ ∎) where open ≡-Reasoning -- This should generalize a lot, but that can be done later subst-lookup-tabulate-raise : ∀ {m n : ℕ} → (z : Fin n) → subst Fin (+-comm n m) (lookup z (tabulate (λ i → subst Fin (+-comm m n) (raise m i)))) ≡ raise m z subst-lookup-tabulate-raise {m} {n} z = begin (subst Fin (+-comm n m) (lookup z (tabulate (λ i → subst Fin (+-comm m n) (raise m i)))) ≡⟨ cong (subst Fin (+-comm n m)) (lookup∘tabulate (λ i → subst Fin (+-comm m n) (raise m i)) z) ⟩ subst Fin (+-comm n m) (subst Fin (+-comm m n) (raise m z)) ≡⟨ subst-subst (+-comm n m) (+-comm m n) (proof-irrelevance (sym (+-comm n m)) (+-comm m n)) (raise m z) ⟩ raise m z ∎) where open ≡-Reasoning subst-lookup-tabulate-inject+ : ∀ {m n : ℕ} → (z : Fin m) → subst Fin (+-comm n m) (lookup z (tabulate (λ i → subst Fin (+-comm m n) (inject+ n i)))) ≡ inject+ n z subst-lookup-tabulate-inject+ {m} {n} z = begin (subst Fin (+-comm n m) (lookup z (tabulate (λ i → subst Fin (+-comm m n) (inject+ n i)))) ≡⟨ cong (subst Fin (+-comm n m)) (lookup∘tabulate (λ i → subst Fin (+-comm m n) (inject+ n i)) z) ⟩ subst Fin (+-comm n m) (subst Fin (+-comm m n) (inject+ n z)) ≡⟨ subst-subst (+-comm n m) (+-comm m n) (proof-irrelevance (sym (+-comm n m)) (+-comm m n)) (inject+ n z) ⟩ inject+ n z ∎) where open ≡-Reasoning -- a kind of inverse for splitAt unSplit : {m n : ℕ} {A : Set} → (f : Fin (m + n) → A) → tabulate {m} (f ∘ (inject+ n)) ++V tabulate {n} (f ∘ (raise m)) ≡ tabulate f unSplit {0} {n} f = refl unSplit {suc m} f = cong (λ x → (f zero) ∷ x) (unSplit {m} (f ∘ suc)) -- nested tabulate-lookup denest-tab-!! : {A B C : Set} {k : ℕ} → (f : B → C) → (g : A → B) → (v : Vec A k) → tabulate (λ i → f (tabulate (λ j → g (v !! j)) !! i)) ≡ mapV (f ∘ g) v denest-tab-!! f g v = begin ( tabulate (λ i → f (tabulate (λ j → g (v !! j)) !! i)) ≡⟨ tabulate-∘ f (λ i → tabulate (λ j → g (v !! j)) !! i) ⟩ mapV f (tabulate (λ i → tabulate (λ j → g (v !! j)) !! i) ) ≡⟨ cong (mapV f) (tabulate∘lookup (tabulate (λ j → g (v !! j)))) ⟩ mapV f (tabulate (λ j → g (v !! j))) ≡⟨ cong (mapV f) (tabulate-∘ g (flip lookup v)) ⟩ mapV f (mapV g (tabulate (flip lookup v))) ≡⟨ sym (map-∘ f g _) ⟩ mapV (f ∘ g) (tabulate (flip lookup v)) ≡⟨ cong (mapV (f ∘ g)) (tabulate∘lookup v) ⟩ mapV (f ∘ g) v ∎) where open ≡-Reasoning tab++[]≡tab∘̂unite+ : ∀ {m} {A : Set} (f : Fin m → A) (eq : m + 0 ≡ m) → tabulate f ++V [] ≡ tabulate (λ j → f (subst Fin eq j)) tab++[]≡tab∘̂unite+ {zero} f eq = refl tab++[]≡tab∘̂unite+ {suc m} f eq = cong₂ _∷_ (cong f pf₁) pf₂ where pf₁ : zero ≡ subst Fin eq zero pf₁ = toℕ-injective (sym (toℕ-invariance zero eq)) pf₃ : ∀ j → suc (subst Fin (+-right-identity m) j) ≡ subst Fin eq (suc j) pf₃ j = toℕ-injective (trans (cong suc (toℕ-invariance j (+-right-identity m))) (sym (toℕ-invariance (suc j) eq))) pf₂ : tabulate (f ∘ suc) ++V [] ≡ tabulate (λ j → f (subst Fin eq (suc j))) pf₂ = trans (tab++[]≡tab∘̂unite+ (f ∘ suc) (+-right-identity m)) (finext (λ j → cong f (pf₃ j))) -- Move to its own spot later merge-[,] : {A B C D E : Set} → {h : A → C} → {i : B → D} → {f : C → E} → {g : D → E} → (x : A ⊎ B) → [ f , g ]′ ( map⊎ h i x ) ≡ [ (f ∘ h) , (g ∘ i) ]′ x merge-[,] (inj₁ x) = refl merge-[,] (inj₂ y) = refl
43.099585
98
0.510735
0d6893383c697469f9dcd04cb3b243c18e97045a
2,667
agda
Agda
src/Categories/Functor/Cartesian/Properties.agda
bond15/agda-categories
6cbfdf3f1be15ef513435e3b85faae92cb1ac36f
[ "MIT" ]
null
null
null
src/Categories/Functor/Cartesian/Properties.agda
bond15/agda-categories
6cbfdf3f1be15ef513435e3b85faae92cb1ac36f
[ "MIT" ]
null
null
null
src/Categories/Functor/Cartesian/Properties.agda
bond15/agda-categories
6cbfdf3f1be15ef513435e3b85faae92cb1ac36f
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- Some of the obvious properties of cartesian functors module Categories.Functor.Cartesian.Properties where open import Data.Product using (_,_; proj₁; proj₂) open import Level open import Categories.Category.Core using (Category) open import Categories.Category.Cartesian open import Categories.Category.Product using (Product; _⁂_) open import Categories.Functor using (Functor; _∘F_) renaming (id to idF) open import Categories.Functor.Cartesian open import Categories.Morphism.Reasoning open import Categories.NaturalTransformation hiding (id) import Categories.Object.Product as OP private variable o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ : Level idF-Cartesian : {A : Category o ℓ e} {CA : Cartesian A} → CartesianF CA CA idF idF-Cartesian {A = A} {CA} = record { ε = id ; ⊗-homo = ntHelper record { η = λ _ → id ; commute = λ _ → id-comm-sym A } } where open Category A ∘-Cartesian : {A : Category o ℓ e} {B : Category o′ ℓ′ e′} {C : Category o″ ℓ″ e″} {CA : Cartesian A} {CB : Cartesian B} {CC : Cartesian C} {F : Functor B C} {G : Functor A B} (CF : CartesianF CB CC F) (CG : CartesianF CA CB G) → CartesianF CA CC (F ∘F G) ∘-Cartesian {B = B} {C} {CA} {CB} {CC} {F} {G} CF CG = record { ε = F.₁ CG.ε ∘ CF.ε ; ⊗-homo = ntHelper record { η = λ X → F.₁ (NTG.η X) ∘ NTF.η (Functor.F₀ (G ⁂ G) X) ; commute = λ { {A} {B} f → let GGA = F₀ (G ⁂ G) A in let GGB = F₀ (G ⁂ G) B in let GGf = F₁ (G ⁂ G) f in begin (F.₁ (NTG.η B) ∘ NTF.η GGB) ∘ F₁ (⊗ CC ∘F ((F ∘F G) ⁂ (F ∘F G))) f ≈⟨ C.assoc ⟩ F.₁ (NTG.η B) ∘ NTF.η GGB ∘ F₁ (⊗ CC ∘F ((F ∘F G) ⁂ (F ∘F G))) f ≈⟨ (refl⟩∘⟨ NTF.commute GGf) ⟩ F.₁ (NTG.η B) ∘ (F.₁ (F₁ (⊗ CB) GGf) ∘ NTF.η GGA) ≈⟨ C.sym-assoc ⟩ (F.₁ (NTG.η B) ∘ F.₁ (F₁ (⊗ CB) GGf)) ∘ NTF.η GGA ≈˘⟨ (F.homomorphism ⟩∘⟨refl) ⟩ (F.₁ (NTG.η B B.∘ F₁ (⊗ CB) GGf)) ∘ NTF.η GGA ≈⟨ (F.F-resp-≈ (NTG.commute f) ⟩∘⟨refl) ⟩ F.F₁ (F₁ G (F₁ (⊗ CA) f) B.∘ NTG.η A) ∘ NTF.η GGA ≈⟨ (F.homomorphism ⟩∘⟨refl) ⟩ (F₁ ((F ∘F G) ∘F ⊗ CA) f ∘ F.₁ (NTG.η A)) ∘ NTF.η GGA ≈⟨ C.assoc ⟩ F₁ ((F ∘F G) ∘F ⊗ CA) f ∘ F.₁ (NTG.η A) ∘ NTF.η GGA ∎} } } where module CF = CartesianF CF module CG = CartesianF CG module NTF = NaturalTransformation CF.⊗-homo module NTG = NaturalTransformation CG.⊗-homo module F = Functor F module B = Category B module C = Category C open C using (_≈_; _∘_) open C.HomReasoning open Cartesian CC using (products) open Functor open OP C using (Product) open Product open Cartesian using (⊗)
38.652174
117
0.573303
580a8a75b3ad8f1c23aba6a665a48d1b075ee02b
4,037
agda
Agda
src/data/lib/prim/Agda/Builtin/Nat.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2021-06-14T11:08:59.000Z
2021-06-14T11:08:59.000Z
src/data/lib/prim/Agda/Builtin/Nat.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T15:49:15.000Z
2015-09-15T15:49:15.000Z
src/data/lib/prim/Agda/Builtin/Nat.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2020-05-16T20:10:05.000Z
2020-05-16T20:10:05.000Z
{-# OPTIONS --without-K --safe --no-universe-polymorphism --no-sized-types --no-guardedness --no-subtyping #-} module Agda.Builtin.Nat where open import Agda.Builtin.Bool data Nat : Set where zero : Nat suc : (n : Nat) → Nat {-# BUILTIN NATURAL Nat #-} infix 4 _==_ _<_ infixl 6 _+_ _-_ infixl 7 _*_ _+_ : Nat → Nat → Nat zero + m = m suc n + m = suc (n + m) {-# BUILTIN NATPLUS _+_ #-} _-_ : Nat → Nat → Nat n - zero = n zero - suc m = zero suc n - suc m = n - m {-# BUILTIN NATMINUS _-_ #-} _*_ : Nat → Nat → Nat zero * m = zero suc n * m = m + n * m {-# BUILTIN NATTIMES _*_ #-} _==_ : Nat → Nat → Bool zero == zero = true suc n == suc m = n == m _ == _ = false {-# BUILTIN NATEQUALS _==_ #-} _<_ : Nat → Nat → Bool _ < zero = false zero < suc _ = true suc n < suc m = n < m {-# BUILTIN NATLESS _<_ #-} -- Helper function div-helper for Euclidean division. --------------------------------------------------------------------------- -- -- div-helper computes n / 1+m via iteration on n. -- -- n div (suc m) = div-helper 0 m n m -- -- The state of the iterator has two accumulator variables: -- -- k: The quotient, returned once n=0. Initialized to 0. -- -- j: A counter, initialized to the divisor m, decreased on each iteration step. -- Once it reaches 0, the quotient k is increased and j reset to m, -- starting the next countdown. -- -- Under the precondition j ≤ m, the invariant is -- -- div-helper k m n j = k + (n + m - j) div (1 + m) div-helper : (k m n j : Nat) → Nat div-helper k m zero j = k div-helper k m (suc n) zero = div-helper (suc k) m n m div-helper k m (suc n) (suc j) = div-helper k m n j {-# BUILTIN NATDIVSUCAUX div-helper #-} -- Proof of the invariant by induction on n. -- -- clause 1: div-helper k m 0 j -- = k by definition -- = k + (0 + m - j) div (1 + m) since m - j < 1 + m -- -- clause 2: div-helper k m (1 + n) 0 -- = div-helper (1 + k) m n m by definition -- = 1 + k + (n + m - m) div (1 + m) by induction hypothesis -- = 1 + k + n div (1 + m) by simplification -- = k + (n + (1 + m)) div (1 + m) by expansion -- = k + (1 + n + m - 0) div (1 + m) by expansion -- -- clause 3: div-helper k m (1 + n) (1 + j) -- = div-helper k m n j by definition -- = k + (n + m - j) div (1 + m) by induction hypothesis -- = k + ((1 + n) + m - (1 + j)) div (1 + m) by expansion -- -- Q.e.d. -- Helper function mod-helper for the remainder computation. --------------------------------------------------------------------------- -- -- (Analogous to div-helper.) -- -- mod-helper computes n % 1+m via iteration on n. -- -- n mod (suc m) = mod-helper 0 m n m -- -- The invariant is: -- -- m = k + j ==> mod-helper k m n j = (n + k) mod (1 + m). mod-helper : (k m n j : Nat) → Nat mod-helper k m zero j = k mod-helper k m (suc n) zero = mod-helper 0 m n m mod-helper k m (suc n) (suc j) = mod-helper (suc k) m n j {-# BUILTIN NATMODSUCAUX mod-helper #-} -- Proof of the invariant by induction on n. -- -- clause 1: mod-helper k m 0 j -- = k by definition -- = (0 + k) mod (1 + m) since m = k + j, thus k < m -- -- clause 2: mod-helper k m (1 + n) 0 -- = mod-helper 0 m n m by definition -- = (n + 0) mod (1 + m) by induction hypothesis -- = (n + (1 + m)) mod (1 + m) by expansion -- = (1 + n) + k) mod (1 + m) since k = m (as l = 0) -- -- clause 3: mod-helper k m (1 + n) (1 + j) -- = mod-helper (1 + k) m n j by definition -- = (n + (1 + k)) mod (1 + m) by induction hypothesis -- = ((1 + n) + k) mod (1 + m) by commutativity -- -- Q.e.d.
29.903704
82
0.471142
7c2f901e2d24053187f73df3626fbb64c4d08b8e
1,240
agda
Agda
theorems/groups/KernelCstImage.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/groups/KernelCstImage.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/groups/KernelCstImage.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT module groups.KernelCstImage {i j k} {G : Group i} {H : Group j} (K : Group k) (φ : G →ᴳ H) (H-ab : is-abelian H) where open import groups.KernelImage {K = K} cst-hom φ H-ab open import groups.Cokernel φ H-ab Ker-cst-quot-Im : Ker/Im ≃ᴳ Coker Ker-cst-quot-Im = ≃-to-≃ᴳ (equiv to from to-from from-to) to-pres-comp where to : Ker/Im.El → Coker.El to = SetQuot-rec to' quot-rel where to' : Ker.El (cst-hom {G = H} {H = K}) → Coker.El to' ker = q[ fst ker ] from : Coker.El → Ker/Im.El from = SetQuot-rec from' quot-rel where from' : Group.El H → Ker/Im.El from' h = q[ h , idp ] abstract to-from : ∀ cok → to (from cok) == cok to-from = SetQuot-elim (λ _ → idp) (λ _ → prop-has-all-paths-↓) from-to : ∀ ker → from (to ker) == ker from-to = SetQuot-elim (λ _ → ap q[_] $ Ker.El=-out (cst-hom {G = H} {H = K}) idp) (λ _ → prop-has-all-paths-↓) to-pres-comp : preserves-comp Ker/Im.comp Coker.comp to to-pres-comp = SetQuot-elim (λ _ → SetQuot-elim (λ _ → idp) (λ _ → prop-has-all-paths-↓)) (λ _ → prop-has-all-paths-↓)
30.243902
78
0.543548
4b6950fa34f7f76686b03ab9433bb315b4900b5f
2,827
agda
Agda
src/Prelude/IO.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Prelude/IO.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Prelude/IO.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Prelude.IO where open import Prelude.Function open import Prelude.Functor open import Prelude.Applicative open import Prelude.Monad open import Prelude.List open import Prelude.String open import Prelude.Char open import Prelude.Unit open import Prelude.Show open import Prelude.Nat open import Agda.Builtin.IO public postulate ioReturn : ∀ {a} {A : Set a} → A → IO A ioBind : ∀ {a b} {A : Set a} {B : Set b} → IO A → (A → IO B) → IO B {-# COMPILE GHC ioReturn = (\ _ _ -> return) #-} {-# COMPILE GHC ioBind = (\ _ _ _ _ -> (>>=)) #-} {-# COMPILE UHC ioReturn = (\ _ _ x -> UHC.Agda.Builtins.primReturn x) #-} {-# COMPILE UHC ioBind = (\ _ _ _ _ x y -> UHC.Agda.Builtins.primBind x y) #-} ioMap : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → IO A → IO B ioMap f m = ioBind m λ x → ioReturn (f x) instance FunctorIO : ∀ {a} → Functor {a} IO fmap {{FunctorIO}} = ioMap ApplicativeIO : ∀ {a} → Applicative {a} IO pure {{ApplicativeIO}} = ioReturn _<*>_ {{ApplicativeIO}} = monadAp ioBind MonadIO : ∀ {a} → Monad {a} IO _>>=_ {{MonadIO}} = ioBind FunctorIO′ : ∀ {a b} → Functor′ {a} {b} IO fmap′ {{FunctorIO′}} = ioMap ApplicativeIO′ : ∀ {a b} → Applicative′ {a} {b} IO _<*>′_ {{ApplicativeIO′}} = monadAp′ ioBind MonadIO′ : ∀ {a b} → Monad′ {a} {b} IO _>>=′_ {{MonadIO′}} = ioBind --- Terminal IO --- postulate getChar : IO Char putChar : Char → IO Unit putStr : String → IO Unit putStrLn : String → IO Unit {-# FOREIGN GHC import qualified Data.Text as Text #-} {-# FOREIGN GHC import qualified Data.Text.IO as Text #-} {-# COMPILE GHC getChar = getChar #-} {-# COMPILE GHC putChar = putChar #-} {-# COMPILE GHC putStr = Text.putStr #-} {-# COMPILE GHC putStrLn = Text.putStrLn #-} {-# COMPILE UHC putStr = (UHC.Agda.Builtins.primPutStr) #-} {-# COMPILE UHC putStrLn = (UHC.Agda.Builtins.primPutStrLn) #-} print : ∀ {a} {A : Set a} {{ShowA : Show A}} → A → IO Unit print = putStrLn ∘ show --- Command line arguments --- {-# FOREIGN GHC import System.Environment (getArgs, getProgName) #-} postulate getArgs : IO (List String) getProgName : IO String {-# COMPILE GHC getArgs = fmap (map Text.pack) getArgs #-} {-# COMPILE GHC getProgName = fmap Text.pack getProgName #-} --- Misc --- {-# FOREIGN GHC import System.Exit #-} data ExitCode : Set where Success : ExitCode -- TODO we probably should also enforce an upper limit? Failure : (n : Nat) → {p : NonZero n} → ExitCode private {-# FOREIGN GHC exitWith' x = exitWith (if x == 0 then ExitSuccess else ExitFailure $ fromInteger x) #-} postulate exitWith' : ∀ {a} {A : Set a} → Nat → IO A {-# COMPILE GHC exitWith' = \ _ _ -> exitWith' #-} exitWith : ∀ {a} {A : Set a} → ExitCode → IO A exitWith Success = exitWith' 0 exitWith (Failure i) = exitWith' i
27.715686
106
0.622568
1bcdde20205ceafbcfc62c9537988f47d2de6403
523
agda
Agda
src/Nats/Add/Assoc.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
1
2020-04-15T15:28:03.000Z
2020-04-15T15:28:03.000Z
src/Nats/Add/Assoc.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
null
null
null
src/Nats/Add/Assoc.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
null
null
null
module Nats.Add.Assoc where open import Equality open import Nats open import Function ------------------------------------------------------------------------ -- internal stuffs private a+/b+c/=/a+b/+c : ∀ a b c → a + b + c ≡ a + (b + c) a+/b+c/=/a+b/+c zero b c = refl a+/b+c/=/a+b/+c (suc a) b c = cong suc $ a+/b+c/=/a+b/+c a b c ------------------------------------------------------------------------ -- public aliases nat-add-assoc : ∀ a b c → a + b + c ≡ a + (b + c) nat-add-assoc = a+/b+c/=/a+b/+c
23.772727
72
0.388145
3748ed6d4c6858ea4bbe42c3939f826bca8edf79
14,831
agda
Agda
Chapter2/Formalization.agda
CodaFi/HoTT-Exercises
3411b253b0a49a5f9c3301df175ae8ecdc563b12
[ "MIT" ]
null
null
null
Chapter2/Formalization.agda
CodaFi/HoTT-Exercises
3411b253b0a49a5f9c3301df175ae8ecdc563b12
[ "MIT" ]
null
null
null
Chapter2/Formalization.agda
CodaFi/HoTT-Exercises
3411b253b0a49a5f9c3301df175ae8ecdc563b12
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} module Formalization where open import Agda.Primitive using (lsuc) open import Relation.Binary.PropositionalEquality open Relation.Binary.PropositionalEquality.≡-Reasoning open import Level -- Recall Lemma 1.12 ind₌ : ∀{a b}{A : Set a} → (C : (x y : A) → (x ≡ y) → Set b) → ((x : A) → C x x refl) → {x y : A} → (p : x ≡ y) → C x y p ind₌ C c {x}{y} p rewrite p = c y -- Types are higher groupoids -- -------------------------- -- This is the *central* idea of HoTT. A Type isn't just an atomic entity, it's a homotopic space. -- An ∞-groupoid consists of -- ∘ a collection of objects -- ∘ a collection of morphisms between objects, and then morphisms between morphisms, and so on -- ∘ equipped with some complex algebraic structure -- -- a morphism at level k is called a k- morphism. Morphisms at each level have -- ∘ identity -- ∘ composition -- ∘ inverse operations -- -- which are weak in the sense that they satisfy the groupoid laws (associativity -- of composition, identity is a unit for composition, inverses cancel) only up -- to morphisms at the next level, and this weakness gives rise to further structure. -- Example -- -- Because associativity of composition of morphisms p (q r) = (p q) r is itself a higher-dimensional morphism -- we need additional operators to talk about them. For example: {- Mac Lane's Pentagon --------------------- All the various ways to reassociate p (q (r s)) /- ((p q) r) s -\ / \ (p (q r)) s (p q) (r s) | | | | p ((q r) s) ----------------- p (q (r s)) -} -- Moreover, all of this higher groupoid structure comes automagically from the induction principle -- on Id. -- "Informally, the induction principle for identity types says that if we -- construct an object (or prove a statement) which depends on an inhabitant -- p : x == y of an identity type, data _==_ {i} {A : Set i} (a : A) : A → Set (lsuc i) where idp : a == a -- then it suffices to perform the construction (or the proof) in -- the special case when x and y are the same (judgmentally) -- and p is the reflexivity element reflx : x = x (judgmentally) -- Lemma 2.1.1 "Paths can be reversed" -- first proof _⁻¹ : ∀ {i} {A : Set i}{x y : A} → (x ≡ y) → (y ≡ x) _⁻¹ {i} {A} = λ p → ind₌ D d p where D : (x y : A) → x ≡ y → Set i D = λ x y p → (y ≡ x) d : (x : A) → D x x refl d = λ x → refl -- second proof inv-sym : ∀ {i} {A : Set i}{x y : A} → (x ≡ y) → (y ≡ x) inv-sym refl = refl -- Lemma 2.1.2 & 2.1.3 "paths can be concatenated (strung together)" -- First proof. We need the type family D : Π (x, y : A) Π (p : x ≡ y) → Type. From that we -- produce an element d : D x x reflₓ (simply identity) then apply the induction -- principle above to D and d. composite : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) composite {i} {A} {_}{_}{z} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y _ = y ≡ z → x ≡ z d : (x₁ : A) → D x₁ x₁ refl d _ = λ x → x -- Second proof. We need the type family D : Π (x, y : A) Π (p : x ≡ y) → Type again. From that -- we produce an element d (x) : D x x reflₓ again, but rather than the identity we go a -- step further and define E : Π (x z : A) Π (q : x ≡ z) → Type. We then produce an -- element e (x) : E x x reflₓ. Induction on D d then unfolds to induction on D then E e. composite' : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) composite' {i} {A} {_}{_}{z} = ind₌ D d where D : (x y : A) → (p : x ≡ y) → Set i D x y _ = y ≡ z → x ≡ z d : (x : A) → D x x refl d x = ind₌ E e where E : (x z : A) → (q : x ≡ z) → Set i E x z _ = x ≡ z e : (x : A) → E x x refl e x = refl -- Third proof. Everything is reflexivity you fool. The hell did you do all that work for before? composite'' : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) composite'' refl refl = refl -- Equality | Homotopy | ∞-Groupoid -- reflexivity | constant path | identity morphism -- symmetry | inversion of paths | inverse morphism -- transitivity | concatenation of paths | composition of morphisms open import Function -- Lemma 2.1.4 -- These are all propositional equalities living in the type of identity types. -- Topologically they are paths of paths, and we can form a homotopy between them. -- For my next trick, I will need composition of paths -- Reflexivity right lem-1-r : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → p ≡ (composite p refl) lem-1-r {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = p ≡ composite p refl d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl -- Reflexivity left lem-1-l : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → p ≡ (composite refl p) lem-1-l {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = p ≡ composite refl p d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl lem-2-l : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → composite ((p)⁻¹) p ≡ refl lem-2-l {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y p = composite ((p)⁻¹) p ≡ refl d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl lem-2-r : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → composite p ((p)⁻¹) ≡ refl lem-2-r {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = composite p ((p)⁻¹) ≡ refl d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl -- Inversion of identity lem-3 : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → ((p)⁻¹)⁻¹ ≡ p lem-3 {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = ((p)⁻¹)⁻¹ ≡ p d : (x₁ : A) → D x₁ x₁ refl d = λ _ → refl {- -- Transitivity of identity lem-4 : ∀ {i} {A : Set i}{x y z w : A}{p : x ≡ y}{q : y ≡ z}{r : z ≡ w} → composite p (composite q r) ≡ composite (composite p q) r lem-4 {i} {A} {_}{_}{z} = ind₌ D₁ d₁ where D₁ : (x y : A) → (x ≡ y) → Set i D₁ x y p = (z w : A)(q : y ≡ z)(r : z ≡ w) → composite p (composite q r) ≡ composite (composite p q) r d₁ : (x₁ : A) → D₁ x₁ x₁ refl d₁ _ = ind₌ D₂ d₂ where D₂ : (x z : A) → (q : x ≡ z) → Set i D₂ x z q = (w : A)(r : z ≡ w) → composite refl (composite q r) ≡ composite (composite refl q) r d₂ : (x₂ : A) → D₂ x₂ x₂ refl d₂ _ = ind₌ D₃ d₃ where D₃ : (x w : A) → (r : x ≡ w) → Set i D₃ x w r = (composite refl (composite refl r)) ≡ (composite (composite refl refl) r) d₃ : (x₃ : A) → D₃ x₃ x₃ refl d₃ _ = composite refl (composite refl refl) ≡ composite (composite refl refl) refl -} -- Lemma 2.1.6 open import Data.Product using (Σ ; _,_ ; proj₁ ; proj₂) open import Data.Nat using (ℕ ; suc) -- We need pointed sets for this part Set• : ∀ i → Set _ Set• i = Σ (Set i) λ X → X -- The loop space of a type is -- - A base point -- - A loop (reflexivity) about that point Ω₁ : ∀ {i} → Set• i → Set• i Ω₁ (X , x) = ((x ≡ x) , refl) -- Construct arbitrary n-dimensional loop spaces Ωⁿ : ∀ {i} → ℕ → Set• i → Set• _ Ωⁿ 0 x = x Ωⁿ (suc n) x = Ωⁿ n (Ω₁ x) -- Projects the type from an n-dimensional loop space Ω : ∀ {i} → ℕ → {X : Set i} → X → Set i Ω n {X} x = proj₁ (Ωⁿ n (X , x)) -- Projects the loop from an n-dimensional loop space loop : ∀ {i} n {X : Set i}(x : X) → Ω n x loop n {X} x = proj₂ (Ωⁿ n (X , x)) -- Composition operation on n-dimensional loop spaces _×_ : ∀ {i} n {A : Set i}{x : A} → Ω n x → Ω n x → Ω n x _×_ n {A} {x} x₁ x₂ = loop n x -- 2.2.1 -- We're type theorists, so we like functor-looking things. -- Paths are functor looking things. -- We like paths -- They respect equality and are all continuous-like ap : ∀ {i j} {A : Set i}{B : Set j}{x y : A}{f : A → B} → (x ≡ y) → (f x ≡ f y) ap {i}{j} {A}{B} {x}{y}{f} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set j D x y p = f x ≡ f y d : (x : A) → D x x refl d = λ x → refl ap₂ : ∀ {i j k} {A : Set i}{B : Set j}{C : Set k}{x x′ : A}{y y′ : B}(f : A → B → C) → (x ≡ x′) → (y ≡ y′) → (f x y ≡ f x′ y′) ap₂ f p q = composite (ap {f = λ _ → f _ _} p) (ap {f = f _} q) ap' : ∀ {i j} {A : Set i}{B : Set j}{x y : A} → (f : A → B) → ((x ≡ y) → (f x ≡ f y)) ap' f refl = refl -- 2.3 -- The dependently typed version of `ap` takes a type family and relates its instantiations with p transport : ∀ {i} {A : Set i}{P : A → Set i}{x y : A} → (p : x ≡ y) → (P x → P y) transport {i} {A}{P} {x}{y} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y p = P x → P y d : (x : A) → D x x refl d = λ x → id -- Topologically, we can view transport as a "path lifting" operation -- That is, we lift the path p to a path in the space ∑[ x ∈ A ] P(x) provided we have a -- base point u in the lifted space. -- -- Basically, P respects equality path-lifting : ∀ {a p}{A : Set a}{x y : A}{P : A → Set p} → (u : P x) → (p : x ≡ y) → (x , u) ≡ (y , u) path-lifting = λ {a} {p} {A} {x} {y} {P} u → cong (λ z → z , u) -- Look, transport works in the "upper" space too! apd : ∀ {i} {A : Set i}{P : A → Set i}{f : (x : A) → P x}{x y : A} → (p : x ≡ y) → (transport p (f x) ≡ f y) apd {i} {A}{P} {f}{x}{y} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y p = transport p (f x) ≡ f y d : (x : A) → D x x refl d = λ x → refl -- By induction, it suffices to assume p is refl. Because of course it does. apd' : ∀ {i} {A : Set i}{P : A → Set i}{f : (x : A) → P x}{x y : A} → (p : x ≡ y) → (transport p (f x) ≡ f y) apd' refl = refl -- We can also fix B and make transport work like fmap with equalities. transportconst : ∀ {i} {A : Set i}{B : Set i}{P : A → B}{x y : A} → (p : x ≡ y) → (b : B) → transport p b ≡ b transportconst {i} {A}{B}{P} {x}{y} p b = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = transport p b ≡ b d : (x : A) → D x x refl d = λ x → refl {- lem-2-3-8 : ∀ {i} {A : Set i}{B : Set i}{f : A → B}{x y : A} → (p : x ≡ y) → apd p ≡ transportconst (ap p) (f x) lem-2-3-8 {i} {A}{B}{f} {x}{y} p = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = apd p ≡ transportconst (f x) ∘ ap p d : (x : A) → D x x refl d = refl -} {- lem-2-3-9 : ∀ {i} {A : Set i}{P : A → Set i}{x y z : A} → (p : x ≡ y) → (q : y ≡ z) → (u : P x) → transport q (transport p u) ≡ transport (p ∘ q) u lem-2-3-9 = ? -} -- Homotopies -- Under Propositions-as-Types two functions are the same if they give the same outputs on the -- same inputs. Which looks like this: a type whose terms are proofs of that^ _∼_ : ∀ {a b} {A : Set a}{P : A → Set b} → (f g : (x : A) → P x) → Set (a ⊔ b) _∼_ {a}{b} {A}{P} f g = (x : A) → f x ≡ g x -- 2.4.2 lem-2-4-2 : ∀ {a} {A : Set a}{B : Set a} → (f : A → B) → f ∼ f lem-2-4-2 f = λ _ → refl lem-2-4-2' : ∀ {a} {A : Set a}{B : Set a} → (f g : A → B) → (f ∼ g) → (g ∼ f) lem-2-4-2' f g x x₁ = sym (x x₁) -- For any A and B, a quasi-inverse of f is a triple with -- ∘ A way back (an inverse for the homomorphism) -- ∘ Homotopies: -- ⊚ α : f ∘ g ∼ id -- ⊚ β : g ∘ f ∼ id -- For now, because I am lazy, the presence of a quasi-inverse will count -- as our definition of equivalence for now. Sorry. record IsEquiv {i j}{A : Set i}{B : Set j}(to : A → B) : Set (i ⊔ j) where field from : B → A iso₁ : (x : A) → from (to x) ≡ x iso₂ : (y : B) → to (from y) ≡ y -- Example 2.4.7: Identity is an equivalence. id-is-equiv : ∀ {i} (A : Set i) → IsEquiv (id {i}{A}) id-is-equiv {i} A = record { from = id {i}{A} ; iso₁ = λ _ → refl ; iso₂ = λ _ → refl } -- Type equivalence is also an equivalence, just on the Universe because: -- ∘ id-is-equiv works for it, therefore A ≃ A -- ∘ With A ≃ B, we can always make B ≃ A -- ∘ With A ≃ B and B ≃ C we have A ≃ C _≃_ : ∀ {i j} (A : Set i) (B : Set j) → Set (i ⊔ j) A ≃ B = Σ (A → B) IsEquiv open import Data.Product renaming (_×_ to _×p_) split-path : ∀ {i j}{A : Set i}{B : Set j}{x y : A ×p B} → x ≡ y → (proj₁ x ≡ proj₁ y) ×p (proj₂ x ≡ proj₂ y) split-path p = ap {f = proj₁} p , ap {f = proj₂} p pair₌ : ∀ {i j}{A : Set i}{B : Set j}{x y : A ×p B} → (proj₁ x ≡ proj₁ y) ×p (proj₂ x ≡ proj₂ y) → x ≡ y pair₌ (p , q) = ap₂ _,_ p q instance split-is-equiv : ∀ {i j}{A : Set i}{B : Set j}{x y : A ×p B} → IsEquiv (pair₌ {x = x}{y = y}) split-is-equiv {x = x}{y = y} = record { from = split-path ; iso₁ = λ pq → ind₌ (λ _ _ p → ∀ {b₁ b₂} (q : b₁ ≡ b₂) → split-path (pair₌ (p , q)) ≡ (p , q)) (λ _ q → ind₌ (λ _ _ q → split-path (pair₌ (refl , q)) ≡ (refl , q)) (λ _ → refl) q) (proj₁ pq) (proj₂ pq) ; iso₂ = ind₌ (λ _ _ p → pair₌ (split-path p) ≡ p) (λ _ → refl) } {- happly : ∀ {i}{A : Set i}{f g : A → Set i} → (f ≡ g) → ((x : A) → f x ≡ g x) happly p x = ap' (λ u → u x) -} -- 2.10 -- This says, when you get down to it, id on universes is a -- type family with a total space of pointed types. Turns out -- Ω isn't just for horses. idtoeqv : ∀ {i} {A : Set i}{B : Set i} → (A ≡ B) → (A ≃ B) idtoeqv {_}{A} refl = (id , id-is-equiv A) -- With idtoeqv in hand, we have to ask Agda nicely to make idtoeqv an equivalence. postulate -- Just kidding ua : ∀ {i} {A : Set i}{B : Set i} → (A ≃ B) ≃ (A ≡ B) -- ^This says "equivalent types may be identified" -- 2.12 {- data _⊎_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where inl : (x : A) → A ⊎ B inr : (y : B) → A ⊎ B code : ∀ {a b}{{A : Set a}}{{B : Set b}} → A ⊎ B → Set (a ⊔ b) code (inl a) = ? code (inr b) = ⊥ code-lem : ∀ {a b}{{A : Set a}}{{B : Set b}} → (x : A ⊎ B) → (a₀ : A) → ((inl a₀ ≡ x) ≃ code x) code-lem {{A}} {{B}} x a₀ = ? where encode : (x : A ⊎ B) → (p : inl a₀ ≡ x) → code x encode x p = transport p refl decode : (x : A ⊎ B) → (c : code x) → inl a₀ ≡ x decode x c = ? -} open import Data.Nat open import Data.Unit open import Data.Empty code : ℕ → ℕ → Set code ℕ.zero ℕ.zero = ⊤ code ℕ.zero (ℕ.suc m) = ⊥ code (ℕ.suc n) ℕ.zero = ⊥ code (ℕ.suc n) (ℕ.suc m) = code n m -- 2.13 natcode-lem : ∀ {m n : ℕ} → (m ≡ n) → code m n natcode-lem {x}{y} p = encode {x}{y} p where encode : ∀ {m n : ℕ} → (m ≡ n) → code m n encode {m}{n} p = transport p (r m) where r : (n : ℕ) → code n n r ℕ.zero = tt r (ℕ.suc n) = r n decode : ∀ {m n : ℕ} → code m n → (m ≡ n) decode {ℕ.zero} {ℕ.zero} tt = refl decode {ℕ.zero} {ℕ.suc _} () decode {ℕ.suc _} {ℕ.zero} () decode {ℕ.suc m} {ℕ.suc n} c = cong ℕ.suc (decode c) enc-dec-quasi : ∀ {n : ℕ} → decode {n}{n} (encode {n}{n} refl) ≡ refl enc-dec-quasi {ℕ.zero} = refl enc-dec-quasi {ℕ.suc n₁} = {! !}
34.016055
147
0.513924
2ece1a28a6a9bb3c73d74caf5f3d91cbea890943
1,275
agda
Agda
vendor/stdlib/src/Algebra/Props/Lattice.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
vendor/stdlib/src/Algebra/Props/Lattice.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
vendor/stdlib/src/Algebra/Props/Lattice.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
------------------------------------------------------------------------ -- Some derivable properties ------------------------------------------------------------------------ open import Algebra module Algebra.Props.Lattice (l : Lattice) where open Lattice l open import Algebra.Structures import Algebra.FunctionProperties as P; open P _≈_ import Relation.Binary.EqReasoning as EqR; open EqR setoid open import Data.Function open import Data.Product ∧-idempotent : Idempotent _∧_ ∧-idempotent x = begin x ∧ x ≈⟨ refl ⟨ ∧-pres-≈ ⟩ sym (proj₁ absorptive _ _) ⟩ x ∧ (x ∨ x ∧ x) ≈⟨ proj₂ absorptive _ _ ⟩ x ∎ ∨-idempotent : Idempotent _∨_ ∨-idempotent x = begin x ∨ x ≈⟨ refl ⟨ ∨-pres-≈ ⟩ sym (∧-idempotent _) ⟩ x ∨ x ∧ x ≈⟨ proj₁ absorptive _ _ ⟩ x ∎ -- The dual construction is also a lattice. ∧-∨-isLattice : IsLattice _≈_ _∧_ _∨_ ∧-∨-isLattice = record { isEquivalence = isEquivalence ; ∨-comm = ∧-comm ; ∨-assoc = ∧-assoc ; ∨-pres-≈ = ∧-pres-≈ ; ∧-comm = ∨-comm ; ∧-assoc = ∨-assoc ; ∧-pres-≈ = ∨-pres-≈ ; absorptive = swap absorptive } ∧-∨-lattice : Lattice ∧-∨-lattice = record { _∧_ = _∨_ ; _∨_ = _∧_ ; isLattice = ∧-∨-isLattice }
26.5625
72
0.509804
4ebe23f9b5e55544f59f879d02d967b2266f505c
876
agda
Agda
Cubical/Data/Int/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Data/Int/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Data/Int/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Int.Base where open import Cubical.Core.Everything open import Cubical.Data.Nat data Int : Type₀ where pos : (n : ℕ) → Int negsuc : (n : ℕ) → Int neg : (n : ℕ) → Int neg zero = pos zero neg (suc n) = negsuc n sucInt : Int → Int sucInt (pos n) = pos (suc n) sucInt (negsuc zero) = pos zero sucInt (negsuc (suc n)) = negsuc n predInt : Int → Int predInt (pos zero) = negsuc zero predInt (pos (suc n)) = pos n predInt (negsuc n) = negsuc (suc n) -- Natural number and negative integer literals for Int open import Cubical.Data.Nat.Literals public instance fromNatInt : HasFromNat Int fromNatInt = record { Constraint = λ _ → Unit ; fromNat = λ n → pos n } instance fromNegInt : HasFromNeg Int fromNegInt = record { Constraint = λ _ → Unit ; fromNeg = λ n → neg n }
23.675676
73
0.657534
4e8c8ccd60689a760b08caa6f5488900176ec756
1,211
agda
Agda
overloading/level.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
27
2015-04-14T15:47:03.000Z
2022-01-09T07:26:57.000Z
src/overloading/level.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
overloading/level.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
4
2015-04-11T17:19:12.000Z
2019-02-26T06:17:38.000Z
{-# OPTIONS --without-K #-} module overloading.level where open import sum open import equality.core open import overloading.bundle open import function.isomorphism open import hott.level.core open import sets.unit open Bundle bundle-structure-iso : ∀ {i j}{Base : Set i} (Struct : Base → Set j) → Σ Base Struct ≅ Bundle Struct bundle-structure-iso Struct = record { to = λ { (X , s) → bundle X s } ; from = λ { (bundle X s) → X , s } ; iso₁ = λ _ → refl ; iso₂ = λ _ → refl } bundle-equality-iso : ∀ {i j}{Base : Set i} (Struct : Base → Set j) → ((B : Base) → h 1 (Struct B)) → {X Y : Bundle Struct} → (parent X ≡ parent Y) ≅ (X ≡ Y) bundle-equality-iso Struct hS {X}{Y} = begin parent X ≡ parent Y ≅⟨ sym≅ ×-right-unit ⟩ ((parent X ≡ parent Y) × ⊤) ≅⟨ Σ-ap-iso refl≅ (λ p → sym≅ (contr-⊤-iso (hS _ _ _))) ⟩ ( Σ (parent X ≡ parent Y) λ p → (subst Struct p (struct X) ≡ struct Y) ) ≅⟨ Σ-split-iso ⟩ (parent X , struct X) ≡ (parent Y , struct Y) ≅⟨ iso≡ (bundle-structure-iso Struct) ⟩ X ≡ Y ∎ where open ≅-Reasoning
28.833333
59
0.527663
1b7c45ea99bb885839a4b038f70dd7df056384ed
1,251
agda
Agda
test/Succeed/NonvariantPolarity.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/NonvariantPolarity.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/NonvariantPolarity.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas, 2012-09-15 -- Positive effects of making Agda recognize constant functions. -- Arguments to constant functions are ignored in definitional equality. {-# OPTIONS --copatterns #-} module NonvariantPolarity where open import Common.Equality data ⊥ : Set where record ⊤ : Set where constructor trivial data Bool : Set where true false : Bool True : Bool → Set True true = ⊤ True false = ⊥ module IgnoreArg where -- A function ignoring its first argument knot : Bool → Bool → Bool knot x true = false knot x false = true test : (y : Bool) → knot true y ≡ knot false y test y = refl module UnusedModulePar where -- An unused module parameter module M (x : Bool) where not : Bool → Bool not true = false not false = true open M true open M false renaming (not to not′) test : (y : Bool) → not y ≡ not′ y test y = refl module CoinductiveUnit where record Unit : Set where coinductive constructor delay field force : Unit open Unit -- The identity on Unit does not match on its argument, so it is constant. id : Unit → Unit force (id x) = id (force x) idConst : (x y : Unit) → id x ≡ id y idConst x y = refl -- That does not imply x ≡ y (needs bisimulation).
20.177419
76
0.669065
1490fdd99db01017b56b751dcbc9d5b6e0869d38
1,944
agda
Agda
agda-stdlib/src/Data/Unit.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Unit.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Unit.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- The unit type ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Unit where import Relation.Binary.PropositionalEquality as PropEq ------------------------------------------------------------------------ -- Re-export contents of base module open import Data.Unit.Base public ------------------------------------------------------------------------ -- Re-export query operations open import Data.Unit.Properties public using (_≟_; _≤?_) ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 1.1 setoid = Data.Unit.Properties.≡-setoid {-# WARNING_ON_USAGE setoid "Warning: setoid was deprecated in v1.1. Please use ≡-setoid from Data.Unit.Properties instead." #-} decSetoid = Data.Unit.Properties.≡-decSetoid {-# WARNING_ON_USAGE decSetoid "Warning: decSetoid was deprecated in v1.1. Please use ≡-decSetoid from Data.Unit.Properties instead." #-} total = Data.Unit.Properties.≡-total {-# WARNING_ON_USAGE total "Warning: total was deprecated in v1.1. Please use ≡-total from Data.Unit.Properties instead" #-} poset = Data.Unit.Properties.≡-poset {-# WARNING_ON_USAGE poset "Warning: poset was deprecated in v1.1. Please use ≡-poset from Data.Unit.Properties instead." #-} decTotalOrder = Data.Unit.Properties.≡-decTotalOrder {-# WARNING_ON_USAGE decTotalOrder "Warning: decTotalOrder was deprecated in v1.1. Please use ≡-decTotalOrder from Data.Unit.Properties instead." #-} preorder = PropEq.preorder ⊤ {-# WARNING_ON_USAGE decTotalOrder "Warning: preorder was deprecated in v1.1. Please use ≡-preorder from Data.Unit.Properties instead." #-}
31.354839
72
0.585905
73139e4461ab02c621e7eb5710982177a628dd41
3,778
agda
Agda
Cubical/Data/Nat/GCD.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Data/Nat/GCD.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
Cubical/Data/Nat/GCD.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Nat.GCD where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Induction.WellFounded open import Cubical.Data.Fin open import Cubical.Data.Sigma as Σ open import Cubical.Data.NatPlusOne open import Cubical.HITs.PropositionalTruncation as PropTrunc open import Cubical.Data.Nat.Base open import Cubical.Data.Nat.Properties open import Cubical.Data.Nat.Order open import Cubical.Data.Nat.Divisibility private variable m n d : ℕ -- common divisors isCD : ℕ → ℕ → ℕ → Type₀ isCD m n d = (d ∣ m) × (d ∣ n) isPropIsCD : isProp (isCD m n d) isPropIsCD = isProp× isProp∣ isProp∣ symCD : isCD m n d → isCD n m d symCD (d∣m , d∣n) = (d∣n , d∣m) -- greatest common divisors isGCD : ℕ → ℕ → ℕ → Type₀ isGCD m n d = (isCD m n d) × (∀ d' → isCD m n d' → d' ∣ d) GCD : ℕ → ℕ → Type₀ GCD m n = Σ ℕ (isGCD m n) isPropIsGCD : isProp (isGCD m n d) isPropIsGCD = isProp× isPropIsCD (isPropΠ2 (λ _ _ → isProp∣)) isPropGCD : isProp (GCD m n) isPropGCD (d , dCD , gr) (d' , d'CD , gr') = ΣProp≡ (λ _ → isPropIsGCD) (antisym∣ (gr' d dCD) (gr d' d'CD)) symGCD : isGCD m n d → isGCD n m d symGCD (dCD , gr) = symCD dCD , λ { d' d'CD → gr d' (symCD d'CD) } divsGCD : m ∣ n → isGCD m n m divsGCD p = (∣-refl refl , p) , λ { d (d∣m , _) → d∣m } -- The base case of the Euclidean algorithm zeroGCD : ∀ m → isGCD m 0 m zeroGCD m = divsGCD (∣-zeroʳ m) private lem₁ : prediv d (suc n) → prediv d (m % suc n) → prediv d m lem₁ {d} {n} {m} (c₁ , p₁) (c₂ , p₂) = (q * c₁ + c₂) , p where r = m % suc n; q = n%k≡n[modk] m (suc n) .fst p = (q * c₁ + c₂) * d ≡⟨ sym (*-distribʳ (q * c₁) c₂ d) ⟩ (q * c₁) * d + c₂ * d ≡⟨ cong (_+ c₂ * d) (sym (*-assoc q c₁ d)) ⟩ q * (c₁ * d) + c₂ * d ≡[ i ]⟨ q * (p₁ i) + (p₂ i) ⟩ q * (suc n) + r ≡⟨ n%k≡n[modk] m (suc n) .snd ⟩ m ∎ lem₂ : prediv d (suc n) → prediv d m → prediv d (m % suc n) lem₂ {d} {n} {m} (c₁ , p₁) (c₂ , p₂) = c₂ ∸ q * c₁ , p where r = m % suc n; q = n%k≡n[modk] m (suc n) .fst p = (c₂ ∸ q * c₁) * d ≡⟨ ∸-distribʳ c₂ (q * c₁) d ⟩ c₂ * d ∸ (q * c₁) * d ≡⟨ cong (c₂ * d ∸_) (sym (*-assoc q c₁ d)) ⟩ c₂ * d ∸ q * (c₁ * d) ≡[ i ]⟨ p₂ i ∸ q * (p₁ i) ⟩ m ∸ q * (suc n) ≡⟨ cong (_∸ q * (suc n)) (sym (n%k≡n[modk] m (suc n) .snd)) ⟩ (q * (suc n) + r) ∸ q * (suc n) ≡⟨ cong (_∸ q * (suc n)) (+-comm (q * (suc n)) r) ⟩ (r + q * (suc n)) ∸ q * (suc n) ≡⟨ ∸-cancelʳ r zero (q * (suc n)) ⟩ r ∎ -- The inductive step of the Euclidean algorithm stepGCD : isGCD (suc n) (m % suc n) d → isGCD m (suc n) d fst (stepGCD ((d∣n , d∣m%n) , gr)) = PropTrunc.map2 lem₁ d∣n d∣m%n , d∣n snd (stepGCD ((d∣n , d∣m%n) , gr)) d' (d'∣m , d'∣n) = gr d' (d'∣n , PropTrunc.map2 lem₂ d'∣n d'∣m) -- putting it all together using well-founded induction euclid< : ∀ m n → n < m → GCD m n euclid< = WFI.induction <-wellfounded λ { m rec zero p → m , zeroGCD m ; m rec (suc n) p → let d , dGCD = rec (suc n) p (m % suc n) (n%sk<sk m n) in d , stepGCD dGCD } euclid : ∀ m n → GCD m n euclid m n with n ≟ m ... | lt p = euclid< m n p ... | gt p = Σ.mapʳ symGCD (euclid< n m p) ... | eq p = m , divsGCD (∣-refl (sym p)) isContrGCD : ∀ m n → isContr (GCD m n) isContrGCD m n = euclid m n , isPropGCD _ -- the gcd operator on ℕ gcd : ℕ → ℕ → ℕ gcd m n = euclid m n .fst gcdIsGCD : ∀ m n → isGCD m n (gcd m n) gcdIsGCD m n = euclid m n .snd
32.568966
107
0.534939
735756bbe4e9f76e1969e0b0ee2592cf5bcdb0fd
417
agda
Agda
Data/Binary.agda
oisdk/agda-binary
92af4d620febd47a9791d466d747278dc4a417aa
[ "MIT" ]
1
2019-03-21T21:30:10.000Z
2019-03-21T21:30:10.000Z
Data/Binary.agda
oisdk/agda-binary
92af4d620febd47a9791d466d747278dc4a417aa
[ "MIT" ]
null
null
null
Data/Binary.agda
oisdk/agda-binary
92af4d620febd47a9791d466d747278dc4a417aa
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Data.Binary where open import Data.Binary.Definitions using (𝔹) public open import Data.Binary.Operations.Semantics using (⟦_⇑⟧; ⟦_⇓⟧) public open import Data.Binary.Operations.Addition using (_+_) public open import Data.Binary.Operations.Multiplication using (_*_) public open import Data.Binary.Operations.Unary using (inc; dec) public
41.7
75
0.707434
1101be5536ed582f1e38f73878682d2fca89fe8d
562
agda
Agda
test/Succeed/Issue180.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue180.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue180.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue180 where module Example₁ where data C : Set where c : C → C data Indexed : (C → C) → Set where i : Indexed c foo : Indexed c → Set foo i = C module Example₂ where data List (A : Set) : Set where nil : List A cons : A → List A → List A postulate A : Set x : A T : Set T = List A → List A data P : List T → Set where p : (f : T) → P (cons f nil) data S : (xs : List T) → P xs → Set where s : (f : T) → S (cons f nil) (p f) foo : S (cons (cons x) nil) (p (cons x)) → A foo (s ._) = x
16.057143
46
0.517794
350814524508fa3bb8525d4307be46263dbc1cbf
11,591
agda
Agda
AdmissibleButNotPostulable.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
1
2021-02-13T14:48:45.000Z
2021-02-13T14:48:45.000Z
AdmissibleButNotPostulable.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
AdmissibleButNotPostulable.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Admissible rules are sometimes not "postulable" ------------------------------------------------------------------------ -- Even though a rule is admissible it may not be sound to postulate -- it, i.e. add it as an inductive constructor. This was observed by -- Edsko de Vries in a message to the Coq-club mailing list (Re: -- [Coq-Club] Adding (inductive) transitivity to weak bisimilarity not -- sound? (was: Need help with coinductive proof), 2009-08-28). module AdmissibleButNotPostulable where open import Codata.Musical.Notation using (∞; ♯_; ♭) open import Data.Nat open import Data.Product as Prod open import Function open import Relation.Binary.PropositionalEquality as P using (_≡_; [_]) open import Relation.Nullary using (¬_) ------------------------------------------------------------------------ -- The partiality monad data _⊥ (A : Set) : Set where now : (v : A) → A ⊥ later : (x : ∞ (A ⊥)) → A ⊥ ------------------------------------------------------------------------ -- Weak equality of computations in the partiality monad module WeakEquality where infix 4 _≈_ data _≈_ {A : Set} : A ⊥ → A ⊥ → Set where now : ∀ {v} → now v ≈ now v later : ∀ {x y} (x≈y : ∞ (♭ x ≈ ♭ y)) → later x ≈ later y laterʳ : ∀ {x y} (x≈y : x ≈ ♭ y ) → x ≈ later y laterˡ : ∀ {x y} (x≈y : ♭ x ≈ y ) → later x ≈ y -- Some lemmas. laterʳ⁻¹ : ∀ {A : Set} {x : A ⊥} {y} → x ≈ later y → x ≈ ♭ y laterʳ⁻¹ (later x≈y) = laterˡ (♭ x≈y) laterʳ⁻¹ (laterʳ x≈y) = x≈y laterʳ⁻¹ (laterˡ x≈ly) = laterˡ (laterʳ⁻¹ x≈ly) laterˡ⁻¹ : ∀ {A : Set} {x} {y : A ⊥} → later x ≈ y → ♭ x ≈ y laterˡ⁻¹ (later x≈y) = laterʳ (♭ x≈y) laterˡ⁻¹ (laterʳ lx≈y) = laterʳ (laterˡ⁻¹ lx≈y) laterˡ⁻¹ (laterˡ x≈y) = x≈y -- Weak equality is an equivalence relation. refl : {A : Set} (x : A ⊥) → x ≈ x refl (now v) = now refl (later x) = later (♯ refl (♭ x)) sym : {A : Set} {x y : A ⊥} → x ≈ y → y ≈ x sym now = now sym (later x≈y) = later (♯ sym (♭ x≈y)) sym (laterʳ x≈y) = laterˡ (sym x≈y) sym (laterˡ x≈y) = laterʳ (sym x≈y) trans : {A : Set} {x y z : A ⊥} → x ≈ y → y ≈ z → x ≈ z trans {x = now v} {z = z} p q = tr p q where tr : ∀ {y} → now v ≈ y → y ≈ z → now v ≈ z tr now y≈z = y≈z tr (laterʳ v≈y) ly≈z = tr v≈y (laterˡ⁻¹ ly≈z) trans {x = later x} lx≈y y≈z = tr lx≈y y≈z where tr : ∀ {y z} → later x ≈ y → y ≈ z → later x ≈ z tr lx≈ly (later y≈z) = later (♯ trans (laterˡ⁻¹ lx≈ly) (laterˡ (♭ y≈z))) tr lx≈y (laterʳ y≈z) = later (♯ trans (laterˡ⁻¹ lx≈y) y≈z ) tr lx≈ly (laterˡ y≈z) = tr (laterʳ⁻¹ lx≈ly) y≈z tr (laterˡ x≈y) y≈z = laterˡ ( trans x≈y y≈z ) -- Non-termination. never : {A : Set} → A ⊥ never = later (♯ never) -- Weak equality is not trivial (assuming that the argument to _⊥ is -- non-empty). non-trivial : {A : Set} {v : A} → ¬ now v ≈ never non-trivial (laterʳ v≈⊥) = non-trivial v≈⊥ ------------------------------------------------------------------------ -- Extended weak equality module ExtendedWeakEquality where infix 4 _≈_ infix 3 _∎ infixr 2 _≈⟨_⟩_ -- Let us try to postulate transitivity using an inductive rule. data _≈_ {A : Set} : A ⊥ → A ⊥ → Set where now : ∀ {v} → now v ≈ now v later : ∀ {x y} (x≈y : ∞ (♭ x ≈ ♭ y)) → later x ≈ later y laterʳ : ∀ {x y} (x≈y : x ≈ ♭ y ) → x ≈ later y laterˡ : ∀ {x y} (x≈y : ♭ x ≈ y ) → later x ≈ y -- Transitivity. _≈⟨_⟩_ : ∀ x {y z} (x≈y : x ≈ y) (y≈z : y ≈ z) → x ≈ z -- Reflexivity. _∎ : {A : Set} (x : A ⊥) → x ≈ x now v ∎ = now later x ∎ = later (♯ (♭ x ∎)) -- Extended weak equality is trivial. trivial : {A : Set} (x y : A ⊥) → x ≈ y trivial x y = x ≈⟨ laterʳ (x ∎) ⟩ later (♯ x) ≈⟨ later (♯ trivial x y) ⟩ later (♯ y) ≈⟨ laterˡ (y ∎) ⟩ y ∎ -- The problem is that there is no "contractive" proof of -- transitivity; the proof given above consumes the input -- certificate "faster" than it produces the output certificate. ------------------------------------------------------------------------ -- Capretta's definition of equality coincides with weak equality -- This is not really related to the problem discussed above, I just -- want to ensure that the definition of weak equality is not too -- strange. module Capretta'sEquality where infix 4 _⇓_ _≈_ -- x ⇓ v means that x terminates with the value v. data _⇓_ {A : Set} : A ⊥ → A → Set where now : ∀ {v} → now v ⇓ v later : ∀ {x v} (x⇓v : ♭ x ⇓ v) → later x ⇓ v -- Equality as defined by Capretta in "General Recursion via -- Coinductive Types". data _≈_ {A : Set} : A ⊥ → A ⊥ → Set where now : ∀ {x y v} (x⇓v : x ⇓ v) (y⇓v : y ⇓ v) → x ≈ y later : ∀ {x y} (x≈y : ∞ (♭ x ≈ ♭ y)) → later x ≈ later y -- Soundness. open WeakEquality using () renaming (_≈_ to _≋_) sound : {A : Set} {x y : A ⊥} → x ≈ y → x ≋ y sound (later x≈y) = WeakEquality.later (♯ sound (♭ x≈y)) sound (now x⇓v y⇓v) = nw x⇓v y⇓v where nw : ∀ {A : Set} {x y : A ⊥} {v} → x ⇓ v → y ⇓ v → x ≋ y nw now now = WeakEquality.now nw x⇓v (later y⇓v) = WeakEquality.laterʳ (nw x⇓v y⇓v) nw (later x⇓v) y⇓v = WeakEquality.laterˡ (nw x⇓v y⇓v) -- Completeness. data _≈P_ {A : Set} : A ⊥ → A ⊥ → Set where now : ∀ {x y v} (x⇓v : x ⇓ v) (y⇓v : y ⇓ v) → x ≈P y later : ∀ {x y} (x≈y : ∞ (♭ x ≈P ♭ y)) → later x ≈P later y laterʳ : ∀ {x y} (x≈y : x ≈P ♭ y ) → x ≈P later y laterˡ : ∀ {x y} (x≈y : ♭ x ≈P y ) → later x ≈P y data _≈W_ {A : Set} : A ⊥ → A ⊥ → Set where now : ∀ {x y v} (x⇓v : x ⇓ v) (y⇓v : y ⇓ v) → x ≈W y later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y laterʳW : ∀ {A : Set} {x : A ⊥} {y} → x ≈W ♭ y → x ≈W later y laterʳW {y = y} x≈y with ♭ y | P.inspect ♭ y laterʳW x≈y | y′ | [ eq ] with x≈y laterʳW x≈y | y′ | [ eq ] | now {v = v} x⇓v y⇓v = now x⇓v (later (P.subst (λ y → y ⇓ v) (P.sym eq) y⇓v)) laterʳW x≈y | later y′ | [ eq ] | later x′≈y′ = later (P.subst (_≈P_ _) (P.sym eq) (laterʳ x′≈y′)) laterˡW : ∀ {A : Set} {x} {y : A ⊥} → ♭ x ≈W y → later x ≈W y laterˡW {x = x} x≈y with ♭ x | P.inspect ♭ x laterˡW x≈y | x′ | [ eq ] with x≈y laterˡW x≈y | x′ | [ eq ] | now {v = v} x⇓v y⇓v = now (later (P.subst (λ x → x ⇓ v) (P.sym eq) x⇓v)) y⇓v laterˡW x≈y | later x′ | [ eq ] | later {y = y′} x′≈y′ = later (P.subst (λ x → x ≈P ♭ y′) (P.sym eq) (laterˡ x′≈y′)) whnf : {A : Set} {x y : A ⊥} → x ≈P y → x ≈W y whnf (now x⇓v y⇓v) = now x⇓v y⇓v whnf (later x≈y) = later (♭ x≈y) whnf (laterʳ x≈y) = laterʳW (whnf x≈y) whnf (laterˡ x≈y) = laterˡW (whnf x≈y) mutual ⟦_⟧W : {A : Set} {x y : A ⊥} → x ≈W y → x ≈ y ⟦ now x⇓v y⇓v ⟧W = now x⇓v y⇓v ⟦ later x≈y ⟧W = later (♯ ⟦ x≈y ⟧P) ⟦_⟧P : {A : Set} {x y : A ⊥} → x ≈P y → x ≈ y ⟦ x≈y ⟧P = ⟦ whnf x≈y ⟧W complete : {A : Set} {x y : A ⊥} → x ≋ y → x ≈ y complete x≋y = ⟦ completeP x≋y ⟧P where completeP : {A : Set} {x y : A ⊥} → x ≋ y → x ≈P y completeP WeakEquality.now = now now now completeP (WeakEquality.later x≈y) = later (♯ completeP (♭ x≈y)) completeP (WeakEquality.laterʳ x≈y) = laterʳ (completeP x≈y) completeP (WeakEquality.laterˡ x≈y) = laterˡ (completeP x≈y) ------------------------------------------------------------------------ -- The weak equality above coincides with weak bisimilarity module WeakBisimilarity {A : Set} where -- The function drop n drops n later constructors (if possible). drop : ℕ → A ⊥ → A ⊥ drop zero x = x drop _ (now v) = now v drop (suc n) (later x) = drop n (♭ x) -- Weak simulations and bisimulations. The removal of a later -- constructor is treated as a silent transition. record IsWeakSimulation (_R_ : A ⊥ → A ⊥ → Set) : Set where field match-later : ∀ {x y} → later x R y → ∃ λ n → ♭ x R drop n y match-now : ∀ {v y} → now v R y → ∃ λ n → now v ≡ drop n y record IsWeakBisimulation (_R_ : A ⊥ → A ⊥ → Set) : Set where field left : IsWeakSimulation _R_ right : IsWeakSimulation (flip _R_) -- Weak bisimilarity. record _≈_ (x y : A ⊥) : Set₁ where field _R_ : A ⊥ → A ⊥ → Set xRy : x R y bisim : IsWeakBisimulation _R_ open WeakEquality hiding (module _≈_) renaming (_≈_ to _≋_) -- Completeness. complete : ∀ {x y} → x ≋ y → x ≈ y complete x≋y = record { _R_ = _≋_ ; xRy = x≋y ; bisim = record { left = record { match-later = λ lx≋y → (0 , laterˡ⁻¹ lx≋y) ; match-now = match-now } ; right = record { match-later = λ x≋ly → (0 , laterʳ⁻¹ x≋ly) ; match-now = match-now ∘ sym } } } where match-now : ∀ {v y} → now v ≋ y → ∃ λ n → now v ≡ drop n y match-now now = (0 , P.refl) match-now (laterʳ v≋y) = Prod.map suc id (match-now v≋y) -- Soundness. module Sound {x y} (x≈y : x ≈ y) where open _≈_ x≈y open IsWeakBisimulation open IsWeakSimulation helper₁ : ∀ {x} y → (∃ λ n → now x ≡ drop n y) → now x ≋ y helper₁ (now y) (zero , P.refl) = now helper₁ (now y) (suc n , P.refl) = now helper₁ (later y) (zero , ()) helper₁ (later y) (suc n , nx≡y-n) = laterʳ (helper₁ (♭ y) (n , nx≡y-n)) mutual helper₂ : ∀ {x} y → (∃ λ n → x R drop n y) → x ≋ y helper₂ y (zero , xRy) = sound _ _ xRy helper₂ (now y) (suc n , xRny) = sound _ _ xRny helper₂ (later y) (suc n , xRy-n) = laterʳ (helper₂ (♭ y) (n , xRy-n)) helper₃ : ∀ x {y} → (∃ λ n → drop (suc n) x R y) → x ≋ y helper₃ (now x) (n , nxRy) = sound _ _ nxRy helper₃ (later x) (zero , xRy) = laterˡ (sound _ _ xRy) helper₃ (later x) (suc n , x-nRy) = laterˡ (helper₃ (♭ x) (n , x-nRy)) sound : ∀ x y → x R y → x ≋ y sound (now x) y nxRy = helper₁ y $ match-now (left bisim) nxRy sound (later x) (now y) lxRny = sym $ helper₁ (later x) $ match-now (right bisim) lxRny sound (later x) (later y) lxRly with match-later (left bisim) lxRly ... | (suc n , xRy-n) = later (♯ helper₂ (♭ y) (n , xRy-n)) ... | (zero , xRly) with match-later (right bisim) xRly ... | (zero , xRy) = later (♯ sound _ _ xRy) ... | (suc n , x-1+nRy) = later (♯ helper₃ (♭ x) (n , x-1+nRy)) sound : ∀ {x y} → x ≈ y → x ≋ y sound x≈y = Sound.sound x≈y _ _ (_≈_.xRy x≈y) -- Note that the problem illustrated in ExtendedWeakEquality is -- related to the problem of weak bisimulation up to weak -- bisimilarity. Let R be a relation which is only inhabited for the -- pair (later (♯ x), later (♯ y)). R is a weak bisimulation up to -- weak bisimilarity (_≈_): -- -- later (♯ x) R later (♯ y) -- ↓ = -- x ≈ later (♯ x) R later (♯ y) -- -- later (♯ x) R later (♯ y) -- = ↓ -- later (♯ x) R later (♯ y) ≈ y -- -- Weak bisimilarity is transitive, so if every relation which is a -- weak bisimulation up to weak bisimilarity were contained in weak -- bisimilarity we would have x ≈ y for all x and y.
34.6
86
0.486843
7c6e418a6dd9374fffb258ceeb590f1b94dd0446
1,425
agda
Agda
agda-stdlib/src/Data/Vec/Functional/Relation/Unary/All.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Vec/Functional/Relation/Unary/All.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Vec/Functional/Relation/Unary/All.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Universal lifting of predicates over Vectors ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Vec.Functional.Relation.Unary.All where open import Data.Fin.Base open import Data.Fin.Properties open import Data.Nat.Base open import Data.Product using (_,_) open import Data.Vec.Functional as VF hiding (map) open import Level using (Level) open import Relation.Unary private variable a p q ℓ : Level A : Set a ------------------------------------------------------------------------ -- Definition All : Pred A ℓ → ∀ {n} → Vector A n → Set ℓ All P xs = ∀ i → P (xs i) ------------------------------------------------------------------------ -- Operations module _ {P : Pred A p} {Q : Pred A q} where map : P ⊆ Q → ∀ {n} → All P {n = n} ⊆ All Q map p⊆q ps i = p⊆q (ps i) ------------------------------------------------------------------------ -- Properties of predicates preserved by All module _ {P : Pred A p} where all : Decidable P → ∀ {n} → Decidable (All P {n = n}) all p? xs = all? λ i → p? (xs i) universal : Universal P → ∀ {n} → Universal (All P {n = n}) universal uni xs i = uni (xs i) satisfiable : Satisfiable P → ∀ {n} → Satisfiable (All P {n = n}) satisfiable (x , px) = (λ _ → x) , (λ _ → px)
27.941176
72
0.465263
3ff61f1e34db57d25cb37c5576a1b2ce8c3cc5da
1,729
agda
Agda
test/interaction/Issue2096.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/interaction/Issue2096.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/interaction/Issue2096.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
-- {-# OPTIONS -v tc.size.solve:100 #-} open import Agda.Builtin.Size data Cx (U : Set) : Set where ⌀ : Cx U _,_ : Cx U → U → Cx U module _ {U : Set} where data _⊆_ : Cx U → Cx U → Set where done : ⌀ ⊆ ⌀ skip : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊆ (Γ′ , A) keep : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → (Γ , A) ⊆ (Γ′ , A) data _∈_ (A : U) : Cx U → Set where top : ∀ {Γ} → A ∈ (Γ , A) pop : ∀ {C Γ} → A ∈ Γ → A ∈ (Γ , C) mono∈ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → A ∈ Γ → A ∈ Γ′ mono∈ done () mono∈ (skip η) i = pop (mono∈ η i) mono∈ (keep η) top = top mono∈ (keep η) (pop i) = pop (mono∈ η i) refl⊆ : ∀ {Γ} → Γ ⊆ Γ refl⊆ {⌀} = done refl⊆ {Γ , A} = keep refl⊆ infixr 3 _⊃_ data Ty : Set where ι : Ty _⊃_ : Ty → Ty → Ty infix 1 _⊢⟨_⟩_ data _⊢⟨_⟩_ (Γ : Cx Ty) : Size → Ty → Set where var : ∀ {p A} → A ∈ Γ → Γ ⊢⟨ p ⟩ A lam : ∀ {n A B} {o : Size< n} → Γ , A ⊢⟨ o ⟩ B → Γ ⊢⟨ n ⟩ A ⊃ B app : ∀ {m A B} {l k : Size< m} → Γ ⊢⟨ k ⟩ A ⊃ B → Γ ⊢⟨ l ⟩ A → Γ ⊢⟨ m ⟩ B mono⊢ : ∀ {m A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⟨ m ⟩ A → Γ′ ⊢⟨ m ⟩ A mono⊢ η (var i) = var (mono∈ η i) mono⊢ η (lam t) = lam (mono⊢ (keep η) t) mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u) det : ∀ {i A B Γ} {j : Size< i} → Γ ⊢⟨ j ⟩ A ⊃ B → Γ , A ⊢⟨ i ⟩ B det t = app (mono⊢ (skip refl⊆) t) (var top) ccont : ∀ {m A B Γ} → Γ ⊢⟨ ↑ ↑ ↑ ↑ m ⟩ (A ⊃ A ⊃ B) ⊃ A ⊃ B ccont = lam (lam (app (app (var (pop top)) (var top)) (var top))) cont : ∀ {m A B Γ} {m′ : Size< m} → (Γ , A) , A ⊢⟨ ↑ ↑ m′ ⟩ B → Γ , A ⊢⟨ ↑ ↑ ↑ ↑ ↑ m ⟩ B cont {m = m} {m′ = m′} t = det (app {m = ↑ ↑ ↑ ↑ m} ccont (lam (lam t))) cont′ : ∀ {q A B Γ} {r : Size< q} → (Γ , A) , A ⊢⟨ {!q!} ⟩ B → Γ , A ⊢⟨ {!!} ⟩ B cont′ t = det (app ccont (lam (lam t)))
30.875
88
0.396183
73166570fc48b047da5940582c6bb5426eab60be
926
agda
Agda
agda/Relation/Nullary/Stable/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Relation/Nullary/Stable/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Relation/Nullary/Stable/Properties.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe #-} module Relation.Nullary.Stable.Properties where open import Data.Empty open import Level open import Relation.Nullary.Stable.Base open import Path open import HLevels open import Data.Empty.Properties open import Cubical.Foundations.Everything using (hcomp; _∧_; i0; i1) Stable≡→isSet : ∀ {ℓ} {A : Type ℓ} → (st : ∀ (a b : A) → Stable (a ≡ b)) → isSet A Stable≡→isSet {A = A} st a b p q j i = let f : (x : A) → a ≡ x → a ≡ x f x p = st a x (λ h → h p) fIsConst : (x : A) → (p q : a ≡ x) → f x p ≡ f x q fIsConst = λ x p q i → st a x (isProp¬ _ (λ h → h p) (λ h → h q) i) rem : (p : a ≡ b) → PathP (λ i → a ≡ p i) (f a refl) (f b p) rem p j = f (p j) (λ i → p (i ∧ j)) in hcomp (λ k → λ { (i = i0) → f a refl k ; (i = i1) → fIsConst b p q j k ; (j = i0) → rem p i k ; (j = i1) → rem q i k }) a
34.296296
82
0.5054
1b0e4088d9e5974fb6991f0ba53f1b4159db40b1
450
agda
Agda
src/Data/ByteString/Utf8.agda
semenov-vladyslav/bytes-agda
98a53f35fca27e3379cf851a9a6bdfe5bd8c9626
[ "MIT" ]
null
null
null
src/Data/ByteString/Utf8.agda
semenov-vladyslav/bytes-agda
98a53f35fca27e3379cf851a9a6bdfe5bd8c9626
[ "MIT" ]
null
null
null
src/Data/ByteString/Utf8.agda
semenov-vladyslav/bytes-agda
98a53f35fca27e3379cf851a9a6bdfe5bd8c9626
[ "MIT" ]
null
null
null
module Data.ByteString.Utf8 where open import Data.ByteString.Primitive open import Data.String using (String) {-# FOREIGN GHC import qualified Data.ByteString #-} {-# FOREIGN GHC import qualified Data.Text.Encoding #-} postulate packStrict : String → ByteStringStrict unpackStrict : ByteStringStrict → String {-# COMPILE GHC packStrict = (Data.Text.Encoding.encodeUtf8) #-} {-# COMPILE GHC unpackStrict = (Data.Text.Encoding.decodeUtf8) #-}
30
66
0.76
7c408990c513508b5a2c8e20bfd635852ab2ab0a
1,896
agda
Agda
function/core.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
27
2015-04-14T15:47:03.000Z
2022-01-09T07:26:57.000Z
src/function/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/function/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T12:17:00.000Z
2019-05-04T19:31:00.000Z
{-# OPTIONS --without-K #-} module function.core where open import level -- copied from Agda's standard library infixr 9 _∘'_ infixr 0 _$_ _∘'_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} → (∀ {x} (y : B x) → C y) → (g : (x : A) → B x) → ((x : A) → C (g x)) f ∘' g = λ x → f (g x) const : ∀ {a b} {A : Set a} {B : Set b} → A → B → A const x = λ _ → x _$_ : ∀ {a b} {A : Set a} {B : A → Set b} → ((x : A) → B x) → ((x : A) → B x) f $ x = f x flip : ∀ {a b c} {A : Set a} {B : Set b} {C : A → B → Set c} → ((x : A) (y : B) → C x y) → ((y : B) (x : A) → C x y) flip f = λ y x → f x y record Composition u₁ u₂ u₃ u₁₂ u₂₃ u₁₃ : Set (lsuc (u₁ ⊔ u₂ ⊔ u₃ ⊔ u₁₂ ⊔ u₂₃ ⊔ u₁₃)) where infixl 9 _∘_ field U₁ : Set u₁ U₂ : Set u₂ U₃ : Set u₃ hom₁₂ : U₁ → U₂ → Set u₁₂ hom₂₃ : U₂ → U₃ → Set u₂₃ hom₁₃ : U₁ → U₃ → Set u₁₃ _∘_ : {X₁ : U₁}{X₂ : U₂}{X₃ : U₃} → hom₂₃ X₂ X₃ → hom₁₂ X₁ X₂ → hom₁₃ X₁ X₃ record Identity u e : Set (lsuc (u ⊔ e)) where field U : Set u endo : U → Set e id : {X : U} → endo X id- : (X : U) → endo X id- X = id {X} instance func-comp : ∀ {i j k} → Composition _ _ _ _ _ _ func-comp {i}{j}{k} = record { U₁ = Set i ; U₂ = Set j ; U₃ = Set k ; hom₁₂ = λ X Y → X → Y ; hom₂₃ = λ X Y → X → Y ; hom₁₃ = λ X Y → X → Y ; _∘_ = λ f g x → f (g x) } instance func-id : ∀ {i} → Identity _ _ func-id {i} = record { U = Set i ; endo = λ X → X → X ; id = λ x → x } module ComposeInterface {u₁ u₂ u₃ u₁₂ u₂₃ u₁₃} ⦃ comp : Composition u₁ u₂ u₃ u₁₂ u₂₃ u₁₃ ⦄ where open Composition comp public using (_∘_) open ComposeInterface public module IdentityInterface {i e} ⦃ identity : Identity i e ⦄ where open Identity identity public using (id; id-) open IdentityInterface public
24.307692
79
0.48154
1148c5a036cf097b511e8c30b41118cab5c5da3e
25,689
agda
Agda
agda-stdlib/src/Data/List/Relation/Unary/Any/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Relation/Unary/Any/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Relation/Unary/Any/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties related to Any ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Unary.Any.Properties where open import Category.Monad open import Data.Bool.Base using (Bool; false; true; T) open import Data.Bool.Properties open import Data.Empty using (⊥) open import Data.Fin.Base using (Fin) renaming (zero to fzero; suc to fsuc) open import Data.List.Base as List open import Data.List.Categorical using (monad) open import Data.List.Relation.Unary.Any as Any using (Any; here; there) open import Data.List.Membership.Propositional open import Data.List.Membership.Propositional.Properties.Core using (Any↔; find∘map; map∘find; lose∘find) open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_) open import Data.Nat.Base using (zero; suc; _<_; z≤n; s≤s) open import Data.Maybe.Base using (Maybe; just; nothing) open import Data.Maybe.Relation.Unary.Any as MAny using (just) open import Data.Product as Prod using (_×_; _,_; ∃; ∃₂; proj₁; proj₂; uncurry′) open import Data.Product.Properties open import Data.Product.Function.NonDependent.Propositional using (_×-cong_) import Data.Product.Function.Dependent.Propositional as Σ open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_]′) open import Data.Sum.Function.Propositional using (_⊎-cong_) open import Function.Base open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence using (_⇔_; equivalence; Equivalence) open import Function.Inverse as Inv using (_↔_; inverse; Inverse) open import Function.Related as Related using (Kind; Related; SK-sym) open import Level using (Level) open import Relation.Binary as B open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; inspect) open import Relation.Unary as U using (Pred; _⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_) open import Relation.Nullary using (¬_; _because_; does; ofʸ; ofⁿ) open import Relation.Nullary.Negation using (contradiction; ¬?; decidable-stable) private open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ}) private variable a b p q r ℓ : Level A : Set a B : Set b ------------------------------------------------------------------------ -- Equality properties module _ {P : A → Set p} {_≈_ : Rel A ℓ} where lift-resp : P Respects _≈_ → (Any P) Respects (Pointwise _≈_) lift-resp resp (x≈y ∷ xs≈ys) (here px) = here (resp x≈y px) lift-resp resp (x≈y ∷ xs≈ys) (there pxs) = there (lift-resp resp xs≈ys pxs) module _ {P : A → Set p} {x xs} where here-injective : ∀ {p q : P x} → here {P = P} {xs = xs} p ≡ here q → p ≡ q here-injective refl = refl there-injective : ∀ {p q : Any P xs} → there {x = x} p ≡ there q → p ≡ q there-injective refl = refl ------------------------------------------------------------------------ -- Misc module _ {P : A → Set p} where ¬Any[] : ¬ Any P [] ¬Any[] () ------------------------------------------------------------------------ -- Any is a congruence module _ {k : Kind} {P : Pred A p} {Q : Pred A q} where Any-cong : ∀ {xs ys : List A} → (∀ x → Related k (P x) (Q x)) → (∀ {z} → Related k (z ∈ xs) (z ∈ ys)) → Related k (Any P xs) (Any Q ys) Any-cong {xs} {ys} P↔Q xs≈ys = Any P xs ↔⟨ SK-sym Any↔ ⟩ (∃ λ x → x ∈ xs × P x) ∼⟨ Σ.cong Inv.id (xs≈ys ×-cong P↔Q _) ⟩ (∃ λ x → x ∈ ys × Q x) ↔⟨ Any↔ ⟩ Any Q ys ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- map map-id : ∀ {P : A → Set p} (f : P ⋐ P) {xs} → (∀ {x} (p : P x) → f p ≡ p) → (p : Any P xs) → Any.map f p ≡ p map-id f hyp (here p) = P.cong here (hyp p) map-id f hyp (there p) = P.cong there $ map-id f hyp p map-∘ : ∀ {P : A → Set p} {Q : A → Set q} {R : A → Set r} (f : Q ⋐ R) (g : P ⋐ Q) {xs} (p : Any P xs) → Any.map (f ∘ g) p ≡ Any.map f (Any.map g p) map-∘ f g (here p) = refl map-∘ f g (there p) = P.cong there $ map-∘ f g p ------------------------------------------------------------------------ -- lookup lookup-result : ∀ {P : Pred A p} {xs} → (p : Any P xs) → P (Any.lookup p) lookup-result (here px) = px lookup-result (there p) = lookup-result p ------------------------------------------------------------------------ -- Swapping -- Nested occurrences of Any can sometimes be swapped. See also ×↔. swap : ∀ {P : A → B → Set ℓ} {xs ys} → Any (λ x → Any (P x) ys) xs → Any (λ y → Any (flip P y) xs) ys swap (here pys) = Any.map here pys swap (there pxys) = Any.map there (swap pxys) swap-there : ∀ {P : A → B → Set ℓ} {x xs ys} → (any : Any (λ x → Any (P x) ys) xs) → swap (Any.map (there {x = x}) any) ≡ there (swap any) swap-there (here pys) = refl swap-there (there pxys) = P.cong (Any.map there) (swap-there pxys) swap-invol : ∀ {P : A → B → Set ℓ} {xs ys} → (any : Any (λ x → Any (P x) ys) xs) → swap (swap any) ≡ any swap-invol (here (here px)) = refl swap-invol (here (there pys)) = P.cong (Any.map there) (swap-invol (here pys)) swap-invol (there pxys) = P.trans (swap-there (swap pxys)) (P.cong there (swap-invol pxys)) swap↔ : ∀ {P : A → B → Set ℓ} {xs ys} → Any (λ x → Any (P x) ys) xs ↔ Any (λ y → Any (flip P y) xs) ys swap↔ = inverse swap swap swap-invol swap-invol ------------------------------------------------------------------------ -- Lemmas relating Any to ⊥ ⊥↔Any⊥ : ∀ {xs : List A} → ⊥ ↔ Any (const ⊥) xs ⊥↔Any⊥ {A = A} = inverse (λ()) (λ p → from p) (λ()) (λ p → from p) where from : {xs : List A} → Any (const ⊥) xs → ∀ {b} {B : Set b} → B from (there p) = from p ⊥↔Any[] : ∀ {P : A → Set p} → ⊥ ↔ Any P [] ⊥↔Any[] = inverse (λ()) (λ()) (λ()) (λ()) ------------------------------------------------------------------------ -- Lemmas relating Any to ⊤ -- These introduction and elimination rules are not inverses, though. any⁺ : ∀ (p : A → Bool) {xs} → Any (T ∘ p) xs → T (any p xs) any⁺ p (here px) = Equivalence.from T-∨ ⟨$⟩ inj₁ px any⁺ p (there {x = x} pxs) with p x ... | true = _ ... | false = any⁺ p pxs any⁻ : ∀ (p : A → Bool) xs → T (any p xs) → Any (T ∘ p) xs any⁻ p (x ∷ xs) px∷xs with p x | inspect p x ... | true | P.[ eq ] = here (Equivalence.from T-≡ ⟨$⟩ eq) ... | false | _ = there (any⁻ p xs px∷xs) any⇔ : ∀ {p : A → Bool} {xs} → Any (T ∘ p) xs ⇔ T (any p xs) any⇔ = equivalence (any⁺ _) (any⁻ _ _) ------------------------------------------------------------------------ -- Sums commute with Any module _ {P : A → Set p} {Q : A → Set q} where Any-⊎⁺ : ∀ {xs} → Any P xs ⊎ Any Q xs → Any (λ x → P x ⊎ Q x) xs Any-⊎⁺ = [ Any.map inj₁ , Any.map inj₂ ]′ Any-⊎⁻ : ∀ {xs} → Any (λ x → P x ⊎ Q x) xs → Any P xs ⊎ Any Q xs Any-⊎⁻ (here (inj₁ p)) = inj₁ (here p) Any-⊎⁻ (here (inj₂ q)) = inj₂ (here q) Any-⊎⁻ (there p) = Sum.map there there (Any-⊎⁻ p) ⊎↔ : ∀ {xs} → (Any P xs ⊎ Any Q xs) ↔ Any (λ x → P x ⊎ Q x) xs ⊎↔ = inverse Any-⊎⁺ Any-⊎⁻ from∘to to∘from where from∘to : ∀ {xs} (p : Any P xs ⊎ Any Q xs) → Any-⊎⁻ (Any-⊎⁺ p) ≡ p from∘to (inj₁ (here p)) = refl from∘to (inj₁ (there p)) rewrite from∘to (inj₁ p) = refl from∘to (inj₂ (here q)) = refl from∘to (inj₂ (there q)) rewrite from∘to (inj₂ q) = refl to∘from : ∀ {xs} (p : Any (λ x → P x ⊎ Q x) xs) → Any-⊎⁺ (Any-⊎⁻ p) ≡ p to∘from (here (inj₁ p)) = refl to∘from (here (inj₂ q)) = refl to∘from (there p) with Any-⊎⁻ p | to∘from p to∘from (there .(Any.map inj₁ p)) | inj₁ p | refl = refl to∘from (there .(Any.map inj₂ q)) | inj₂ q | refl = refl ------------------------------------------------------------------------ -- Products "commute" with Any. module _ {P : Pred A p} {Q : Pred B q} where Any-×⁺ : ∀ {xs ys} → Any P xs × Any Q ys → Any (λ x → Any (λ y → P x × Q y) ys) xs Any-×⁺ (p , q) = Any.map (λ p → Any.map (λ q → (p , q)) q) p Any-×⁻ : ∀ {xs ys} → Any (λ x → Any (λ y → P x × Q y) ys) xs → Any P xs × Any Q ys Any-×⁻ pq with Prod.map id (Prod.map id find) (find pq) ... | (x , x∈xs , y , y∈ys , p , q) = (lose x∈xs p , lose y∈ys q) ×↔ : ∀ {xs ys} → (Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs ×↔ {xs} {ys} = inverse Any-×⁺ Any-×⁻ from∘to to∘from where open P.≡-Reasoning from∘to : ∀ pq → Any-×⁻ (Any-×⁺ pq) ≡ pq from∘to (p , q) = Any-×⁻ (Any-×⁺ (p , q)) ≡⟨⟩ (let (x , x∈xs , pq) = find (Any-×⁺ (p , q)) (y , y∈ys , p , q) = find pq in lose x∈xs p , lose y∈ys q) ≡⟨ P.cong (λ • → let (x , x∈xs , pq) = • (y , y∈ys , p , q) = find pq in lose x∈xs p , lose y∈ys q) (find∘map p (λ p → Any.map (p ,_) q)) ⟩ (let (x , x∈xs , p) = find p (y , y∈ys , p , q) = find (Any.map (p ,_) q) in lose x∈xs p , lose y∈ys q) ≡⟨ P.cong (λ • → let (x , x∈xs , p) = find p (y , y∈ys , p , q) = • in lose x∈xs p , lose y∈ys q) (find∘map q (proj₂ (proj₂ (find p)) ,_)) ⟩ (let (x , x∈xs , p) = find p (y , y∈ys , q) = find q in lose x∈xs p , lose y∈ys q) ≡⟨ P.cong₂ _,_ (lose∘find p) (lose∘find q) ⟩ (p , q) ∎ to∘from : ∀ pq → Any-×⁺ {xs} (Any-×⁻ pq) ≡ pq to∘from pq with find pq | (λ (f : (proj₁ (find pq) ≡_) ⋐ _) → map∘find pq {f}) ... | (x , x∈xs , pq′) | lem₁ with find pq′ | (λ (f : (proj₁ (find pq′) ≡_) ⋐ _) → map∘find pq′ {f}) ... | (y , y∈ys , p , q) | lem₂ rewrite P.sym $ map-∘ {R = λ x → Any (λ y → P x × Q y) ys} (λ p → Any.map (λ q → p , q) (lose y∈ys q)) (λ y → P.subst P y p) x∈xs = lem₁ _ helper where helper : Any.map (λ q → p , q) (lose y∈ys q) ≡ pq′ helper rewrite P.sym $ map-∘ (λ q → p , q) (λ y → P.subst Q y q) y∈ys = lem₂ _ refl ------------------------------------------------------------------------ -- Half-applied product commutes with Any. module _ {_~_ : REL A B r} where Any-Σ⁺ʳ : ∀ {xs} → (∃ λ x → Any (_~ x) xs) → Any (∃ ∘ _~_) xs Any-Σ⁺ʳ (b , here px) = here (b , px) Any-Σ⁺ʳ (b , there pxs) = there (Any-Σ⁺ʳ (b , pxs)) Any-Σ⁻ʳ : ∀ {xs} → Any (∃ ∘ _~_) xs → ∃ λ x → Any (_~ x) xs Any-Σ⁻ʳ (here (b , x)) = b , here x Any-Σ⁻ʳ (there xs) = Prod.map₂ there $ Any-Σ⁻ʳ xs ------------------------------------------------------------------------ -- Invertible introduction (⁺) and elimination (⁻) rules for various -- list functions ------------------------------------------------------------------------ ------------------------------------------------------------------------ -- singleton module _ {P : Pred A p} where singleton⁺ : ∀ {x} → P x → Any P [ x ] singleton⁺ Px = here Px singleton⁻ : ∀ {x} → Any P [ x ] → P x singleton⁻ (here Px) = Px ------------------------------------------------------------------------ -- map module _ {f : A → B} where map⁺ : ∀ {P : B → Set p} {xs} → Any (P ∘ f) xs → Any P (List.map f xs) map⁺ (here p) = here p map⁺ (there p) = there $ map⁺ p map⁻ : ∀ {P : B → Set p} {xs} → Any P (List.map f xs) → Any (P ∘ f) xs map⁻ {xs = x ∷ xs} (here p) = here p map⁻ {xs = x ∷ xs} (there p) = there $ map⁻ p map⁺∘map⁻ : ∀ {P : B → Set p} {xs} → (p : Any P (List.map f xs)) → map⁺ (map⁻ p) ≡ p map⁺∘map⁻ {xs = x ∷ xs} (here p) = refl map⁺∘map⁻ {xs = x ∷ xs} (there p) = P.cong there (map⁺∘map⁻ p) map⁻∘map⁺ : ∀ (P : B → Set p) {xs} → (p : Any (P ∘ f) xs) → map⁻ {P = P} (map⁺ p) ≡ p map⁻∘map⁺ P (here p) = refl map⁻∘map⁺ P (there p) = P.cong there (map⁻∘map⁺ P p) map↔ : ∀ {P : B → Set p} {xs} → Any (P ∘ f) xs ↔ Any P (List.map f xs) map↔ = inverse map⁺ map⁻ (map⁻∘map⁺ _) map⁺∘map⁻ module _ {f : A → B} {P : A → Set p} {Q : B → Set q} where gmap : P ⋐ Q ∘ f → Any P ⋐ Any Q ∘ map f gmap g = map⁺ ∘ Any.map g ------------------------------------------------------------------------ -- mapMaybe module _ {P : B → Set p} (f : A → Maybe B) where mapMaybe⁺ : ∀ xs → Any (MAny.Any P) (map f xs) → Any P (mapMaybe f xs) mapMaybe⁺ (x ∷ xs) ps with f x | ps ... | nothing | here () ... | nothing | there pxs = mapMaybe⁺ xs pxs ... | just _ | here (just py) = here py ... | just _ | there pxs = there (mapMaybe⁺ xs pxs) ------------------------------------------------------------------------ -- _++_ module _ {P : A → Set p} where ++⁺ˡ : ∀ {xs ys} → Any P xs → Any P (xs ++ ys) ++⁺ˡ (here p) = here p ++⁺ˡ (there p) = there (++⁺ˡ p) ++⁺ʳ : ∀ xs {ys} → Any P ys → Any P (xs ++ ys) ++⁺ʳ [] p = p ++⁺ʳ (x ∷ xs) p = there (++⁺ʳ xs p) ++⁻ : ∀ xs {ys} → Any P (xs ++ ys) → Any P xs ⊎ Any P ys ++⁻ [] p = inj₂ p ++⁻ (x ∷ xs) (here p) = inj₁ (here p) ++⁻ (x ∷ xs) (there p) = Sum.map there id (++⁻ xs p) ++⁺∘++⁻ : ∀ xs {ys} (p : Any P (xs ++ ys)) → [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs p) ≡ p ++⁺∘++⁻ [] p = refl ++⁺∘++⁻ (x ∷ xs) (here p) = refl ++⁺∘++⁻ (x ∷ xs) (there p) with ++⁻ xs p | ++⁺∘++⁻ xs p ++⁺∘++⁻ (x ∷ xs) (there p) | inj₁ p′ | ih = P.cong there ih ++⁺∘++⁻ (x ∷ xs) (there p) | inj₂ p′ | ih = P.cong there ih ++⁻∘++⁺ : ∀ xs {ys} (p : Any P xs ⊎ Any P ys) → ++⁻ xs ([ ++⁺ˡ , ++⁺ʳ xs ]′ p) ≡ p ++⁻∘++⁺ [] (inj₂ p) = refl ++⁻∘++⁺ (x ∷ xs) (inj₁ (here p)) = refl ++⁻∘++⁺ (x ∷ xs) {ys} (inj₁ (there p)) rewrite ++⁻∘++⁺ xs {ys} (inj₁ p) = refl ++⁻∘++⁺ (x ∷ xs) (inj₂ p) rewrite ++⁻∘++⁺ xs (inj₂ p) = refl ++↔ : ∀ {xs ys} → (Any P xs ⊎ Any P ys) ↔ Any P (xs ++ ys) ++↔ {xs = xs} = inverse [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs) (++⁻∘++⁺ xs) (++⁺∘++⁻ xs) ++-comm : ∀ xs ys → Any P (xs ++ ys) → Any P (ys ++ xs) ++-comm xs ys = [ ++⁺ʳ ys , ++⁺ˡ ]′ ∘ ++⁻ xs ++-comm∘++-comm : ∀ xs {ys} (p : Any P (xs ++ ys)) → ++-comm ys xs (++-comm xs ys p) ≡ p ++-comm∘++-comm [] {ys} p rewrite ++⁻∘++⁺ ys {ys = []} (inj₁ p) = refl ++-comm∘++-comm (x ∷ xs) {ys} (here p) rewrite ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₂ (here p)) = refl ++-comm∘++-comm (x ∷ xs) (there p) with ++⁻ xs p | ++-comm∘++-comm xs p ++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ʳ ys p)))) | inj₁ p | refl rewrite ++⁻∘++⁺ ys (inj₂ p) | ++⁻∘++⁺ ys (inj₂ $ there {x = x} p) = refl ++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ˡ p)))) | inj₂ p | refl rewrite ++⁻∘++⁺ ys {ys = xs} (inj₁ p) | ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₁ p) = refl ++↔++ : ∀ xs ys → Any P (xs ++ ys) ↔ Any P (ys ++ xs) ++↔++ xs ys = inverse (++-comm xs ys) (++-comm ys xs) (++-comm∘++-comm xs) (++-comm∘++-comm ys) ++-insert : ∀ xs {ys x} → P x → Any P (xs ++ [ x ] ++ ys) ++-insert xs Px = ++⁺ʳ xs (++⁺ˡ (singleton⁺ Px)) ------------------------------------------------------------------------ -- concat module _ {P : A → Set p} where concat⁺ : ∀ {xss} → Any (Any P) xss → Any P (concat xss) concat⁺ (here p) = ++⁺ˡ p concat⁺ (there {x = xs} p) = ++⁺ʳ xs (concat⁺ p) concat⁻ : ∀ xss → Any P (concat xss) → Any (Any P) xss concat⁻ ([] ∷ xss) p = there $ concat⁻ xss p concat⁻ ((x ∷ xs) ∷ xss) (here p) = here (here p) concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p ... | here p′ = here (there p′) ... | there p′ = there p′ concat⁻∘++⁺ˡ : ∀ {xs} xss (p : Any P xs) → concat⁻ (xs ∷ xss) (++⁺ˡ p) ≡ here p concat⁻∘++⁺ˡ xss (here p) = refl concat⁻∘++⁺ˡ xss (there p) rewrite concat⁻∘++⁺ˡ xss p = refl concat⁻∘++⁺ʳ : ∀ xs xss (p : Any P (concat xss)) → concat⁻ (xs ∷ xss) (++⁺ʳ xs p) ≡ there (concat⁻ xss p) concat⁻∘++⁺ʳ [] xss p = refl concat⁻∘++⁺ʳ (x ∷ xs) xss p rewrite concat⁻∘++⁺ʳ xs xss p = refl concat⁺∘concat⁻ : ∀ xss (p : Any P (concat xss)) → concat⁺ (concat⁻ xss p) ≡ p concat⁺∘concat⁻ ([] ∷ xss) p = concat⁺∘concat⁻ xss p concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (here p) = refl concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p | concat⁺∘concat⁻ (xs ∷ xss) p concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ˡ p′)) | here p′ | refl = refl concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ʳ xs (concat⁺ p′))) | there p′ | refl = refl concat⁻∘concat⁺ : ∀ {xss} (p : Any (Any P) xss) → concat⁻ xss (concat⁺ p) ≡ p concat⁻∘concat⁺ (here p) = concat⁻∘++⁺ˡ _ p concat⁻∘concat⁺ (there {x = xs} {xs = xss} p) rewrite concat⁻∘++⁺ʳ xs xss (concat⁺ p) = P.cong there $ concat⁻∘concat⁺ p concat↔ : ∀ {xss} → Any (Any P) xss ↔ Any P (concat xss) concat↔ {xss} = inverse concat⁺ (concat⁻ xss) concat⁻∘concat⁺ (concat⁺∘concat⁻ xss) ------------------------------------------------------------------------ -- applyUpTo module _ {P : A → Set p} where applyUpTo⁺ : ∀ f {i n} → P (f i) → i < n → Any P (applyUpTo f n) applyUpTo⁺ _ p (s≤s z≤n) = here p applyUpTo⁺ f p (s≤s (s≤s i<n)) = there (applyUpTo⁺ (f ∘ suc) p (s≤s i<n)) applyUpTo⁻ : ∀ f {n} → Any P (applyUpTo f n) → ∃ λ i → i < n × P (f i) applyUpTo⁻ f {suc n} (here p) = zero , s≤s z≤n , p applyUpTo⁻ f {suc n} (there p) with applyUpTo⁻ (f ∘ suc) p ... | i , i<n , q = suc i , s≤s i<n , q ------------------------------------------------------------------------ -- tabulate module _ {P : A → Set p} where tabulate⁺ : ∀ {n} {f : Fin n → A} i → P (f i) → Any P (tabulate f) tabulate⁺ fzero p = here p tabulate⁺ (fsuc i) p = there (tabulate⁺ i p) tabulate⁻ : ∀ {n} {f : Fin n → A} → Any P (tabulate f) → ∃ λ i → P (f i) tabulate⁻ {suc n} (here p) = fzero , p tabulate⁻ {suc n} (there p) = Prod.map fsuc id (tabulate⁻ p) ------------------------------------------------------------------------ -- filter module _ {P : A → Set p} {Q : A → Set q} (Q? : U.Decidable Q) where filter⁺ : ∀ {xs} → (p : Any P xs) → Any P (filter Q? xs) ⊎ ¬ Q (Any.lookup p) filter⁺ {x ∷ xs} (here px) with Q? x ... | true because _ = inj₁ (here px) ... | false because ofⁿ ¬Qx = inj₂ ¬Qx filter⁺ {x ∷ xs} (there p) with Q? x ... | true because _ = Sum.map₁ there (filter⁺ p) ... | false because _ = filter⁺ p filter⁻ : ∀ {xs} → Any P (filter Q? xs) → Any P xs filter⁻ {x ∷ xs} p with does (Q? x) filter⁻ {x ∷ xs} (here px) | true = here px filter⁻ {x ∷ xs} (there p) | true = there (filter⁻ p) filter⁻ {x ∷ xs} p | false = there (filter⁻ p) ------------------------------------------------------------------------ -- derun and deduplicate module _ {P : A → Set p} {R : A → A → Set r} (R? : B.Decidable R) where private derun⁺-aux : ∀ x xs → P Respects R → P x → Any P (derun R? (x ∷ xs)) derun⁺-aux x [] P-resp-R Px = here Px derun⁺-aux x (y ∷ xs) P-resp-R Px with R? x y ... | true because ofʸ Rxy = derun⁺-aux y xs P-resp-R (P-resp-R Rxy Px) ... | false because _ = here Px derun⁺ : ∀ {xs} → P Respects R → Any P xs → Any P (derun R? xs) derun⁺ {x ∷ xs} P-resp-R (here px) = derun⁺-aux x xs P-resp-R px derun⁺ {x ∷ y ∷ xs} P-resp-R (there any[P,xs]) with R? x y ... | true because _ = derun⁺ P-resp-R any[P,xs] ... | false because _ = there (derun⁺ P-resp-R any[P,xs]) deduplicate⁺ : ∀ {xs} → P Respects (flip R) → Any P xs → Any P (deduplicate R? xs) deduplicate⁺ {x ∷ xs} P-resp-R (here px) = here px deduplicate⁺ {x ∷ xs} P-resp-R (there any[P,xs]) with filter⁺ (¬? ∘ R? x) (deduplicate⁺ {xs} P-resp-R any[P,xs]) ... | inj₁ p = there p ... | inj₂ ¬¬q with decidable-stable (R? x (Any.lookup (deduplicate⁺ P-resp-R any[P,xs]))) ¬¬q ... | q = here (P-resp-R q (lookup-result (deduplicate⁺ P-resp-R any[P,xs]))) private derun⁻-aux : ∀ {x xs} → Any P (derun R? (x ∷ xs)) → Any P (x ∷ xs) derun⁻-aux {x} {[]} (here px) = here px derun⁻-aux {x} {y ∷ xs} any[P,derun[x∷y∷xs]] with R? x y derun⁻-aux {x} {y ∷ xs} any[P,derun[y∷xs]] | true because _ = there (derun⁻-aux any[P,derun[y∷xs]]) derun⁻-aux {x} {y ∷ xs} (here px) | false because _ = here px derun⁻-aux {x} {y ∷ xs} (there any[P,derun[y∷xs]]) | false because _ = there (derun⁻-aux any[P,derun[y∷xs]]) derun⁻ : ∀ {xs} → Any P (derun R? xs) → Any P xs derun⁻ {x ∷ xs} any[P,derun[x∷xs]] = derun⁻-aux any[P,derun[x∷xs]] deduplicate⁻ : ∀ {xs} → Any P (deduplicate R? xs) → Any P xs deduplicate⁻ {x ∷ xs} (here px) = here px deduplicate⁻ {x ∷ xs} (there any[P,dedup[xs]]) = there (deduplicate⁻ (filter⁻ (¬? ∘ R? x) any[P,dedup[xs]])) ------------------------------------------------------------------------ -- map-with-∈. module _ {P : B → Set p} where map-with-∈⁺ : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) → (∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) → Any P (map-with-∈ xs f) map-with-∈⁺ f (_ , here refl , p) = here p map-with-∈⁺ f (_ , there x∈xs , p) = there $ map-with-∈⁺ (f ∘ there) (_ , x∈xs , p) map-with-∈⁻ : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) → Any P (map-with-∈ xs f) → ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs) map-with-∈⁻ (y ∷ xs) f (here p) = (y , here refl , p) map-with-∈⁻ (y ∷ xs) f (there p) = Prod.map id (Prod.map there id) $ map-with-∈⁻ xs (f ∘ there) p map-with-∈↔ : ∀ {xs : List A} {f : ∀ {x} → x ∈ xs → B} → (∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) ↔ Any P (map-with-∈ xs f) map-with-∈↔ = inverse (map-with-∈⁺ _) (map-with-∈⁻ _ _) (from∘to _) (to∘from _ _) where from∘to : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) (p : ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) → map-with-∈⁻ xs f (map-with-∈⁺ f p) ≡ p from∘to f (_ , here refl , p) = refl from∘to f (_ , there x∈xs , p) rewrite from∘to (f ∘ there) (_ , x∈xs , p) = refl to∘from : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) (p : Any P (map-with-∈ xs f)) → map-with-∈⁺ f (map-with-∈⁻ xs f p) ≡ p to∘from (y ∷ xs) f (here p) = refl to∘from (y ∷ xs) f (there p) = P.cong there $ to∘from xs (f ∘ there) p ------------------------------------------------------------------------ -- return module _ {P : A → Set p} {x : A} where return⁺ : P x → Any P (return x) return⁺ = here return⁻ : Any P (return x) → P x return⁻ (here p) = p return⁺∘return⁻ : (p : Any P (return x)) → return⁺ (return⁻ p) ≡ p return⁺∘return⁻ (here p) = refl return⁻∘return⁺ : (p : P x) → return⁻ (return⁺ p) ≡ p return⁻∘return⁺ p = refl return↔ : P x ↔ Any P (return x) return↔ = inverse return⁺ return⁻ return⁻∘return⁺ return⁺∘return⁻ ------------------------------------------------------------------------ -- _∷_ module _ (P : Pred A p) where ∷↔ : ∀ {x xs} → (P x ⊎ Any P xs) ↔ Any P (x ∷ xs) ∷↔ {x} {xs} = (P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩ (Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩ Any P (x ∷ xs) ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- _>>=_ module _ {A B : Set ℓ} {P : B → Set p} {f : A → List B} where >>=↔ : ∀ {xs} → Any (Any P ∘ f) xs ↔ Any P (xs >>= f) >>=↔ {xs} = Any (Any P ∘ f) xs ↔⟨ map↔ ⟩ Any (Any P) (List.map f xs) ↔⟨ concat↔ ⟩ Any P (xs >>= f) ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- _⊛_ ⊛↔ : ∀ {P : B → Set ℓ} {fs : List (A → B)} {xs : List A} → Any (λ f → Any (P ∘ f) xs) fs ↔ Any P (fs ⊛ xs) ⊛↔ {P = P} {fs} {xs} = Any (λ f → Any (P ∘ f) xs) fs ↔⟨ Any-cong (λ _ → Any-cong (λ _ → return↔) (_ ∎)) (_ ∎) ⟩ Any (λ f → Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ ) (_ ∎) ⟩ Any (λ f → Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ ⟩ Any P (fs ⊛ xs) ∎ where open Related.EquationalReasoning -- An alternative introduction rule for _⊛_ ⊛⁺′ : ∀ {P : A → Set ℓ} {Q : B → Set ℓ} {fs : List (A → B)} {xs} → Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs) ⊛⁺′ pq p = Inverse.to ⊛↔ ⟨$⟩ Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq ------------------------------------------------------------------------ -- _⊗_ ⊗↔ : {P : A × B → Set ℓ} {xs : List A} {ys : List B} → Any (λ x → Any (λ y → P (x , y)) ys) xs ↔ Any P (xs ⊗ ys) ⊗↔ {P = P} {xs} {ys} = Any (λ x → Any (λ y → P (x , y)) ys) xs ↔⟨ return↔ ⟩ Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩ Any (λ x, → Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩ Any P (xs ⊗ ys) ∎ where open Related.EquationalReasoning ⊗↔′ : {P : A → Set ℓ} {Q : B → Set ℓ} {xs : List A} {ys : List B} → (Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys) ⊗↔′ {P = P} {Q} {xs} {ys} = (Any P xs × Any Q ys) ↔⟨ ×↔ ⟩ Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩ Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎ where open Related.EquationalReasoning
38.001479
114
0.440811
14e2d2a8cdf5117150127428495a57b582f05064
6,862
agda
Agda
agda-stdlib/src/Relation/Binary/Construct/Add/Infimum/Strict.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Relation/Binary/Construct/Add/Infimum/Strict.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Relation/Binary/Construct/Add/Infimum/Strict.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- The lifting of a non-strict order to incorporate a new infimum ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This module is designed to be used with -- Relation.Nullary.Construct.Add.Infimum open import Relation.Binary module Relation.Binary.Construct.Add.Infimum.Strict {a ℓ} {A : Set a} (_<_ : Rel A ℓ) where open import Level using (_⊔_) open import Data.Product open import Function open import Relation.Binary.PropositionalEquality as P using (_≡_; refl) import Relation.Binary.Construct.Add.Infimum.Equality as Equality import Relation.Binary.Construct.Add.Infimum.NonStrict as NonStrict open import Relation.Nullary hiding (Irrelevant) open import Relation.Nullary.Construct.Add.Infimum import Relation.Nullary.Decidable as Dec ------------------------------------------------------------------------ -- Definition data _<₋_ : Rel (A ₋) (a ⊔ ℓ) where ⊥₋<[_] : (l : A) → ⊥₋ <₋ [ l ] [_] : {k l : A} → k < l → [ k ] <₋ [ l ] ------------------------------------------------------------------------ -- Relational properties [<]-injective : ∀ {k l} → [ k ] <₋ [ l ] → k < l [<]-injective [ p ] = p <₋-asym : Asymmetric _<_ → Asymmetric _<₋_ <₋-asym <-asym [ p ] [ q ] = <-asym p q <₋-trans : Transitive _<_ → Transitive _<₋_ <₋-trans <-trans ⊥₋<[ l ] [ q ] = ⊥₋<[ _ ] <₋-trans <-trans [ p ] [ q ] = [ <-trans p q ] <₋-dec : Decidable _<_ → Decidable _<₋_ <₋-dec _<?_ ⊥₋ ⊥₋ = no (λ ()) <₋-dec _<?_ ⊥₋ [ l ] = yes ⊥₋<[ l ] <₋-dec _<?_ [ k ] ⊥₋ = no (λ ()) <₋-dec _<?_ [ k ] [ l ] = Dec.map′ [_] [<]-injective (k <? l) <₋-irrelevant : Irrelevant _<_ → Irrelevant _<₋_ <₋-irrelevant <-irr ⊥₋<[ l ] ⊥₋<[ l ] = P.refl <₋-irrelevant <-irr [ p ] [ q ] = P.cong _ (<-irr p q) module _ {r} {_≤_ : Rel A r} where open NonStrict _≤_ <₋-transʳ : Trans _≤_ _<_ _<_ → Trans _≤₋_ _<₋_ _<₋_ <₋-transʳ <-transʳ (⊥₋≤ .⊥₋) (⊥₋<[ l ]) = ⊥₋<[ l ] <₋-transʳ <-transʳ (⊥₋≤ l) [ q ] = ⊥₋<[ _ ] <₋-transʳ <-transʳ [ p ] [ q ] = [ <-transʳ p q ] <₋-transˡ : Trans _<_ _≤_ _<_ → Trans _<₋_ _≤₋_ _<₋_ <₋-transˡ <-transˡ ⊥₋<[ l ] [ q ] = ⊥₋<[ _ ] <₋-transˡ <-transˡ [ p ] [ q ] = [ <-transˡ p q ] ------------------------------------------------------------------------ -- Relational properties + propositional equality <₋-cmp-≡ : Trichotomous _≡_ _<_ → Trichotomous _≡_ _<₋_ <₋-cmp-≡ <-cmp ⊥₋ ⊥₋ = tri≈ (λ ()) refl (λ ()) <₋-cmp-≡ <-cmp ⊥₋ [ l ] = tri< ⊥₋<[ l ] (λ ()) (λ ()) <₋-cmp-≡ <-cmp [ k ] ⊥₋ = tri> (λ ()) (λ ()) ⊥₋<[ k ] <₋-cmp-≡ <-cmp [ k ] [ l ] with <-cmp k l ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ []-injective) (¬c ∘ [<]-injective) ... | tri≈ ¬a refl ¬c = tri≈ (¬a ∘ [<]-injective) refl (¬c ∘ [<]-injective) ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ []-injective) [ c ] <₋-irrefl-≡ : Irreflexive _≡_ _<_ → Irreflexive _≡_ _<₋_ <₋-irrefl-≡ <-irrefl refl [ x ] = <-irrefl refl x <₋-respˡ-≡ : _<₋_ Respectsˡ _≡_ <₋-respˡ-≡ = P.subst (_<₋ _) <₋-respʳ-≡ : _<₋_ Respectsʳ _≡_ <₋-respʳ-≡ = P.subst (_ <₋_) <₋-resp-≡ : _<₋_ Respects₂ _≡_ <₋-resp-≡ = <₋-respʳ-≡ , <₋-respˡ-≡ ------------------------------------------------------------------------ -- Relational properties + setoid equality module _ {e} {_≈_ : Rel A e} where open Equality _≈_ <₋-cmp : Trichotomous _≈_ _<_ → Trichotomous _≈₋_ _<₋_ <₋-cmp <-cmp ⊥₋ ⊥₋ = tri≈ (λ ()) ⊥₋≈⊥₋ (λ ()) <₋-cmp <-cmp ⊥₋ [ l ] = tri< ⊥₋<[ l ] (λ ()) (λ ()) <₋-cmp <-cmp [ k ] ⊥₋ = tri> (λ ()) (λ ()) ⊥₋<[ k ] <₋-cmp <-cmp [ k ] [ l ] with <-cmp k l ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ [≈]-injective) (¬c ∘ [<]-injective) ... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ [<]-injective) [ b ] (¬c ∘ [<]-injective) ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ [≈]-injective) [ c ] <₋-irrefl : Irreflexive _≈_ _<_ → Irreflexive _≈₋_ _<₋_ <₋-irrefl <-irrefl [ p ] [ q ] = <-irrefl p q <₋-respˡ-≈₋ : _<_ Respectsˡ _≈_ → _<₋_ Respectsˡ _≈₋_ <₋-respˡ-≈₋ <-respˡ-≈ ⊥₋≈⊥₋ q = q <₋-respˡ-≈₋ <-respˡ-≈ [ p ] [ q ] = [ <-respˡ-≈ p q ] <₋-respʳ-≈₋ : _<_ Respectsʳ _≈_ → _<₋_ Respectsʳ _≈₋_ <₋-respʳ-≈₋ <-respʳ-≈ ⊥₋≈⊥₋ q = q <₋-respʳ-≈₋ <-respʳ-≈ [ p ] ⊥₋<[ l ] = ⊥₋<[ _ ] <₋-respʳ-≈₋ <-respʳ-≈ [ p ] [ q ] = [ <-respʳ-≈ p q ] <₋-resp-≈₋ : _<_ Respects₂ _≈_ → _<₋_ Respects₂ _≈₋_ <₋-resp-≈₋ = map <₋-respʳ-≈₋ <₋-respˡ-≈₋ ------------------------------------------------------------------------ -- Structures + propositional equality <₋-isStrictPartialOrder-≡ : IsStrictPartialOrder _≡_ _<_ → IsStrictPartialOrder _≡_ _<₋_ <₋-isStrictPartialOrder-≡ strict = record { isEquivalence = P.isEquivalence ; irrefl = <₋-irrefl-≡ irrefl ; trans = <₋-trans trans ; <-resp-≈ = <₋-resp-≡ } where open IsStrictPartialOrder strict <₋-isDecStrictPartialOrder-≡ : IsDecStrictPartialOrder _≡_ _<_ → IsDecStrictPartialOrder _≡_ _<₋_ <₋-isDecStrictPartialOrder-≡ dectot = record { isStrictPartialOrder = <₋-isStrictPartialOrder-≡ isStrictPartialOrder ; _≟_ = ≡-dec _≟_ ; _<?_ = <₋-dec _<?_ } where open IsDecStrictPartialOrder dectot <₋-isStrictTotalOrder-≡ : IsStrictTotalOrder _≡_ _<_ → IsStrictTotalOrder _≡_ _<₋_ <₋-isStrictTotalOrder-≡ strictot = record { isEquivalence = P.isEquivalence ; trans = <₋-trans trans ; compare = <₋-cmp-≡ compare } where open IsStrictTotalOrder strictot ------------------------------------------------------------------------ -- Structures + setoid equality module _ {e} {_≈_ : Rel A e} where open Equality _≈_ <₋-isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_ → IsStrictPartialOrder _≈₋_ _<₋_ <₋-isStrictPartialOrder strict = record { isEquivalence = ≈₋-isEquivalence isEquivalence ; irrefl = <₋-irrefl irrefl ; trans = <₋-trans trans ; <-resp-≈ = <₋-resp-≈₋ <-resp-≈ } where open IsStrictPartialOrder strict <₋-isDecStrictPartialOrder : IsDecStrictPartialOrder _≈_ _<_ → IsDecStrictPartialOrder _≈₋_ _<₋_ <₋-isDecStrictPartialOrder dectot = record { isStrictPartialOrder = <₋-isStrictPartialOrder isStrictPartialOrder ; _≟_ = ≈₋-dec _≟_ ; _<?_ = <₋-dec _<?_ } where open IsDecStrictPartialOrder dectot <₋-isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsStrictTotalOrder _≈₋_ _<₋_ <₋-isStrictTotalOrder strictot = record { isEquivalence = ≈₋-isEquivalence isEquivalence ; trans = <₋-trans trans ; compare = <₋-cmp compare } where open IsStrictTotalOrder strictot
37.091892
75
0.488342
cc234faa45b5739dffa8e0f63ebf5476e6bf33f9
406
agda
Agda
test/Fail/Issue2862fun.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2862fun.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2862fun.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-12-04, Re: issue #2862, reported by m0davis, -- Make sure there is similar problem with functions. open import Agda.Builtin.Equality data Bool : Set where true false : Bool val : Bool module M where val = true -- Should fail val≡true : val ≡ true val≡true = refl val = false data ⊥ : Set where ¬val≡true : val ≡ true → ⊥ ¬val≡true () boom : ⊥ boom = ¬val≡true Z.val≡true
15.615385
61
0.660099
36232f1e491af8039961a7842f379ba6ba73baf2
10,100
agda
Agda
nicolai/pseudotruncations/PseudoTruncs-wconst-seq.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
nicolai/pseudotruncations/PseudoTruncs-wconst-seq.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
nicolai/pseudotruncations/PseudoTruncs-wconst-seq.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.NType2 open import lib.PathFunctor open import lib.PathGroupoid open import lib.types.Bool open import lib.types.IteratedSuspension open import lib.types.LoopSpace open import lib.types.Nat open import lib.types.Paths open import lib.types.Pi open import lib.types.Pointed open import lib.types.Sigma open import lib.types.Suspension open import lib.types.TLevel open import lib.types.Unit open import nicolai.pseudotruncations.Preliminary-definitions open import nicolai.pseudotruncations.Liblemmas open import nicolai.pseudotruncations.SeqColim open import nicolai.pseudotruncations.wconstSequence module nicolai.pseudotruncations.PseudoTruncs-wconst-seq where open import nicolai.pseudotruncations.pointed-O-Sphere open import nicolai.pseudotruncations.LoopsAndSpheres open import nicolai.pseudotruncations.PseudoTruncs {- The special sequence that we consider -} module PtruncsSeq {i} (X : Type i) where A : ℕ → Type i A O = X A (S n) = Pseudo n -1-trunc (A n) f : (n : ℕ) → A n → A (S n) f n x = point n -1 x C : Sequence {i} C = (A , f) {- A main result: If we have an inhabitant of X, then the sequence is weakly constant. This is Lemma 6.2 ! -} module PtruncSeqWC {i} (X : Type i) (x₀ : X) where open PtruncsSeq {i} X fs : (n : ℕ) → A n fs O = x₀ fs (S n) = f n (fs n) P : (n : ℕ) → (x : A n) → Type i P n x = f n x == fs (S n) {- This is the easy 'Case j ≡ -2' -} f₀-x₀ : (y : X) → P O y f₀-x₀ y = (spoke O -1 r (lift false)) ∙ ! (spoke O -1 r (lift true)) where r : Sphere {i} O → X r (lift true) = x₀ r (lift false) = y {- Now, the general case is done by induction on n (note that this variable is called 'j' in the paper). Hence, what is 'j' in the paper is now 'S n'. Unfortunately, we have to do everything in one "big" step with many "where" clauses due to the mutual dependencies. -} fₙ-x₀ : (n : ℕ) → (y : A n) → P n y fₙ-x₀ O y = f₀-x₀ y fₙ-x₀ (S n) = Pseudotrunc-ind n Point Hub Spoke where -- just for convenience - saves brackets norₙ' : Sphere' {i} n norₙ' = nor' n fⁿx₀ = fs n Point : (w : A n) → P (S n) (point n -1 w) Point w = ap (point (S n) -1) (fₙ-x₀ n w) Hub : (r : Sphere' n → A n) → point S n -1 _ == _ Hub r = ap (point (S n) -1) (! (spoke n -1 r norₙ') ∙ fₙ-x₀ n (r norₙ')) {- The definition of [Spoke] is the hard part. First, we do the easy things that we have to do... -} Spoke : (r : _) → (x : Sphere' n) → _ Spoke r = λ x → from-transp (P (S n)) (spoke n -1 r x) ( transport (P (S n)) (spoke n -1 r x) (Point (r x)) =⟨ trans-ap₁ (f (S n)) (fs (S (S n))) (spoke n -1 r x) (Point (r x)) ⟩ ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ Point (r x) =⟨ ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ₗ ! (∙-unit-r (Point (r x))) ⟩ ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ Point (r x) ∙ idp {- Now comes the hard step which requires A LOT of work in the where clause below: we can compose with something which, for a complicated reason, is idp! -} =⟨ ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ₗ (Point (r x) ∙ₗ ! (k-const x)) ⟩ ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ Point (r x) ∙ k x {- From here, it's easy; we just have to re-associate paths and cancel inverses. This could be done with standard library lemmas, but it's easier to just use an 'ad-hoc' lemma. -} =⟨ multi-cancelling (ap (point S n -1) (spoke n -1 r x)) (Point (r x)) (Hub r) ⟩ Hub r ∎ ) where {- Now, the actual work follows! -} {- First, we define the interesting loop. In the paper, it is called [kₓ]. Here, it is just [k x]. -} k : (x : Sphere' {i} n) → Ω (Pseudo S n -1-trunc (A (S n)) , f (S n) (f n fⁿx₀)) k x = ! (Point (r x)) ∙ ap (point (S n) -1) (spoke n -1 r x) ∙ (Hub r) {- We want to show that [k] factors as [ap pₙ ∘ h]. First, we define h. -} h : Sphere' {i} n → Ω (Pseudo n -1-trunc (A n) , f n fⁿx₀) h x = ! (fₙ-x₀ n (r x)) ∙ (spoke n -1 r x) ∙ (! (spoke n -1 r norₙ') ∙ fₙ-x₀ n (r norₙ')) {- The statement that k == ap pₙ ∘ h: -} k-p-h : k == ap (point S n -1) ∘ h k-p-h = λ= (λ (x : Sphere' {i} n) → k x =⟨ idp ⟩ ! (Point (r x)) ∙ (ap (point (S n) -1) (spoke n -1 r x) ∙ (Hub r)) =⟨ !-ap (point S n -1) (fₙ-x₀ n (r x)) ∙ᵣ ( ap (point S n -1) (spoke n -1 r x) ∙ Hub r) ⟩ ap (point (S n) -1) (! (fₙ-x₀ n (r x))) ∙ ap (point (S n) -1) (spoke n -1 r x) ∙ (Hub r) =⟨ ! (ap (point (S n) -1) (! (fₙ-x₀ n (r x))) ∙ₗ ap-∙ point S n -1 (spoke n -1 r x) _ ) ⟩ ap (point (S n) -1) (! (fₙ-x₀ n (r x))) ∙ ap (point (S n) -1) ( spoke n -1 r x ∙ (! (spoke n -1 r norₙ') ∙ fₙ-x₀ n (r norₙ'))) =⟨ ! (ap-∙ point S n -1 (! (fₙ-x₀ n (r x))) _) ⟩ ap (point S n -1) (h x) ∎) {- [h] can be made into a a pointed map, written [ĥ] -} ĥ : (⊙Sphere' {i} n) →̇ ⊙Ω (A (S n) , f n fⁿx₀) ĥ = h , (! (fₙ-x₀ n (r _)) ∙ (spoke n -1 r _) ∙ ! (spoke n -1 r norₙ') ∙ fₙ-x₀ n (r norₙ') =⟨ (! (fₙ-x₀ n (r _))) ∙ₗ (! (∙-assoc (spoke n -1 r _) (! (spoke n -1 r norₙ')) (fₙ-x₀ n (r norₙ')))) ⟩ ! (fₙ-x₀ n (r _)) ∙ ((spoke n -1 r _) ∙ (! (spoke n -1 r norₙ'))) ∙ fₙ-x₀ n (r norₙ') =⟨ ! (fₙ-x₀ n (r _)) ∙ₗ !-inv-r (spoke n -1 r _) ∙ᵣ fₙ-x₀ n (r norₙ') ⟩ ! (fₙ-x₀ n (r _)) ∙ idp ∙ fₙ-x₀ n (r norₙ') =⟨ !-inv-l (fₙ-x₀ n (r _)) ⟩ idp ∎ ) {- A pointed version of the first constructor. -} pointsₙ : (A (S n) , f n fⁿx₀) →̇ A (S (S n)) , f (S n) (f n fⁿx₀) pointsₙ = point S n -1 , idp open null open hom-adjoint points-Φ⁻¹-null : isNull∙ (pointsₙ ⊙∘ Φ⁻¹ _ _ ĥ) points-Φ⁻¹-null = <– (isNull-equiv (pointsₙ ⊙∘ Φ⁻¹ _ _ ĥ)) -- translate from isNull∙' (null-lequiv (pointsₙ ⊙∘ Φ⁻¹ _ _ ĥ) -- translate from isNulld; this, -- we have done already! (cmp-nll'.from-sphere-null'∙ n (Φ⁻¹ _ _ ĥ))) ap-points-ĥ-null : isNull∙ (⊙ap (point S n -1 , idp) ⊙∘ ĥ) ap-points-ĥ-null = –> (combine-isnull-nat' ĥ (point S n -1 , idp)) points-Φ⁻¹-null {- ... consequently, h is always refl [in the library "idp"]: -} points-h-const : (x : Sphere' n) → ap (point S n -1) (h x) == idp points-h-const x = null-lequiv-easy _ ap-points-ĥ-null x {- ... and so is k: -} k-const : (x : Sphere' n) → k x == idp k-const x = app= k-p-h x ∙ points-h-const x {- Main result: each function in the sequence is propositional! -} wconst-f : wconst-chain C wconst-f n w₁ w₂ = fₙ-x₀ n w₁ ∙ ! (fₙ-x₀ n w₂) {- Another important result: if we want to show a proposition, we can assume A₀ instead of Aω But this should follow from the general induction principle, so... TODO -} module PtruncSeqResult' {i} (X : Type i) where open PtruncsSeq {i} X -- this defines the chain C of pseudo-truncations SC = SeqCo C reduction-lemma : (P : Type i) → (is-prop P) → (A O → P) → (SC → P) reduction-lemma P ip ff = SeqCo-rec {C = C} {B = P} Ins Glue where Ins : (n : ℕ) → A n → P Ins O = ff Ins (S n) = Pseudotrunc-rec {P = P} n Point-1 Hub-1 Spoke-1 where Point-1 : _ → P Point-1 x = Ins n x Hub-1 : (Sphere' n → A n) → P Hub-1 r = Ins n (r (nor' n)) Spoke-1 : (r : Sphere' n → A n) (x : Sphere' n) → Point-1 (r x) == Hub-1 r Spoke-1 r x = prop-has-all-paths {A = P} ip _ _ Glue : (n : ℕ) (a : A n) → Ins n a == Ins (S n) (f n a) Glue n a = prop-has-all-paths ip _ _ {- Corollary of the main result: The colimit of the considered sequence is propositional! -} module PtruncSeqResult {i} (X : Type i) where open PtruncsSeq {i} X -- this defines the chain C of pseudo-truncations colim-is-prp : is-prop (SeqCo C) colim-is-prp = inhab-to-contr-is-prop (PtruncSeqResult'.reduction-lemma X (is-contr (SeqCo C)) has-level-is-prop (λ x₀ → ins O x₀ , prop-has-all-paths (wconst-prop C (PtruncSeqWC.wconst-f X x₀)) (ins O x₀))) open PtruncSeqResult' X {- If we have the propositional truncation in the theory: -} open import lib.types.Truncation colim-is-trunc : (Trunc ⟨-1⟩ X) ≃ SeqCo C colim-is-trunc = equiv (Trunc-rec (colim-is-prp) (ins 0)) (reduction-lemma (Trunc ⟨-1⟩ X) Trunc-level [_]) (λ _ → prop-has-all-paths colim-is-prp _ _) (λ _ → prop-has-all-paths Trunc-level _ _)
35.56338
94
0.468515
364f861418b542be487ab5df0cd7ce93587b3b48
790
agda
Agda
Cubical/Algebra/Monoid/Construct/Unit.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Monoid/Construct/Unit.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Monoid/Construct/Unit.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Monoid.Construct.Unit where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Algebra.Monoid open import Cubical.Data.Prod using (_,_) open import Cubical.Data.Unit import Cubical.Algebra.Semigroup.Construct.Unit as ⊤Semigroup open ⊤Semigroup public hiding (⊤-isSemigroup; ⊤-Semigroup) ◯-identityˡ : LeftIdentity tt _◯_ ◯-identityˡ _ = refl ◯-identityʳ : RightIdentity tt _◯_ ◯-identityʳ _ = refl ◯-identity : Identity tt _◯_ ◯-identity = ◯-identityˡ , ◯-identityʳ ⊤-isMonoid : IsMonoid ⊤ _◯_ tt ⊤-isMonoid = record { isSemigroup = ⊤Semigroup.⊤-isSemigroup ; identity = ◯-identity } ⊤-Monoid : Monoid ℓ-zero ⊤-Monoid = record { isMonoid = ⊤-isMonoid }
24.6875
61
0.73038
21e726a409a09ebfed61ad609cf80db575785147
232
agda
Agda
test/Succeed/NoQualifiedInstances-ParameterizedImport.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/NoQualifiedInstances-ParameterizedImport.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/NoQualifiedInstances-ParameterizedImport.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --no-qualified-instances #-} module NoQualifiedInstances-ParameterizedImport where postulate T : Set open import NoQualifiedInstances.ParameterizedImport.A T as A postulate f : {{A.I}} → A.I test : A.I test = f
15.466667
61
0.728448
2e93f26b4829e04d9ab459df5de4a694e1b58f86
408
agda
Agda
benchmark/monad/IndexedMap.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
benchmark/monad/IndexedMap.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
benchmark/monad/IndexedMap.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Relation.Binary open import Relation.Binary.PropositionalEquality open import Data.Product open import Level module IndexedMap {Index : Set} {Key : Index → Set} {_≈_ _<_ : Rel (∃ Key) zero} (isOrderedKeySet : IsStrictTotalOrder _≈_ _<_) -- Equal keys must have equal indices. (indicesEqual : _≈_ =[ proj₁ ]⇒ _≡_) (Value : Index → Set) where
31.384615
71
0.634804