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
042c0c105f6cbd4342f7f1c55ac0b98e602b28ef
768
agda
Agda
Cubical/Data/Fin/Recursive/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Data/Fin/Recursive/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Data/Fin/Recursive/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe --no-import-sorts #-} module Cubical.Data.Fin.Recursive.Base where open import Cubical.Foundations.Prelude open import Cubical.Data.Empty as Empty hiding (rec; elim) open import Cubical.Data.Nat hiding (elim) data FinF (X : Type₀) : Type₀ where zero : FinF X suc : X → FinF X Fin : ℕ → Type₀ Fin zero = ⊥ Fin (suc k) = FinF (Fin k) private variable ℓ : Level k : ℕ R : Type ℓ rec : R → (R → R) → Fin k → R rec {k = suc k} z _ zero = z rec {k = suc k} z s (suc x) = s (rec z s x) elim : ∀(P : ∀{k} → Fin k → Type ℓ) → (∀{k} → P {suc k} zero) → (∀{k} (fn : Fin k) → P fn → P {suc k} (suc fn)) → (fn : Fin k) → P fn elim {k = suc k} P fz fs zero = fz elim {k = suc k} P fz fs (suc x) = fs x (elim P fz fs x)
21.942857
58
0.570313
cc1e9a0cc9641a1e9de93e4b98d77a2623b44e59
221
agda
Agda
testData/parse/agda/private-primitive-variable.agda
ice1000/intellij-minitt
7e601041978a0497db7d4cf3bcf4971f532235cd
[ "Apache-2.0" ]
30
2019-05-11T16:26:38.000Z
2022-01-29T13:18:34.000Z
testData/parse/agda/private-primitive-variable.agda
ice1000/intellij-minitt
7e601041978a0497db7d4cf3bcf4971f532235cd
[ "Apache-2.0" ]
16
2019-03-30T04:29:32.000Z
2021-03-15T17:04:36.000Z
testData/parse/agda/private-primitive-variable.agda
owo-lang/intellij-owo
7e601041978a0497db7d4cf3bcf4971f532235cd
[ "Apache-2.0" ]
3
2019-10-07T01:38:12.000Z
2021-03-12T21:33:35.000Z
-- -- Created by Dependently-Typed Lambda Calculus on 2019-05-15 -- private-primitive-variable -- Author: ice1000 -- {-# OPTIONS --without-K --safe #-} private variable A : Set a : A primitive primInterval : Set
13.8125
61
0.678733
6485e98e7a328f4fa11353347b8d0a8631b3ba5d
2,266
agda
Agda
examples/Monad.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/Monad.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/Monad.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Monad where module Prelude where infixl 40 _∘_ id : {A : Set} -> A -> A id x = x _∘_ : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C f ∘ g = \x -> f (g x) data Nat : Set where zero : Nat suc : Nat -> Nat module Base where data Monad (M : Set -> Set) : Set1 where monad : (return : {A : Set} -> A -> M A) -> (bind : {A B : Set} -> M A -> (A -> M B) -> M B) -> Monad M monadReturn : {M : Set -> Set} -> Monad M -> {A : Set} -> A -> M A monadReturn (monad ret bind) = ret monadBind : {M : Set -> Set} -> Monad M -> {A B : Set} -> M A -> (A -> M B) -> M B monadBind (monad ret bind) = bind module Monad {M : Set -> Set}(monadM : Base.Monad M) where open Prelude infixl 15 _>>=_ -- Return and bind -------------------------------------------------------- return : {A : Set} -> A -> M A return = Base.monadReturn monadM _>>=_ : {A B : Set} -> M A -> (A -> M B) -> M B _>>=_ = Base.monadBind monadM -- Other operations ------------------------------------------------------- liftM : {A B : Set} -> (A -> B) -> M A -> M B liftM f m = m >>= return ∘ f module List where infixr 20 _++_ _::_ -- The list datatype ------------------------------------------------------ data List (A : Set) : Set where nil : List A _::_ : A -> List A -> List A -- Some list operations --------------------------------------------------- foldr : {A B : Set} -> (A -> B -> B) -> B -> List A -> B foldr f e nil = e foldr f e (x :: xs) = f x (foldr f e xs) map : {A B : Set} -> (A -> B) -> List A -> List B map f nil = nil map f (x :: xs) = f x :: map f xs _++_ : {A : Set} -> List A -> List A -> List A nil ++ ys = ys (x :: xs) ++ ys = x :: (xs ++ ys) concat : {A : Set} -> List (List A) -> List A concat = foldr _++_ nil -- List is a monad -------------------------------------------------------- open Base monadList : Monad List monadList = monad ret bind where ret : {A : Set} -> A -> List A ret x = x :: nil bind : {A B : Set} -> List A -> (A -> List B) -> List B bind xs f = concat (map f xs) open Prelude open List module MonadList = Monad monadList open MonadList
23.852632
84
0.424978
ed8548ce7a980c4b70043522515e08d490e7afe3
770
agda
Agda
test/Fail/Issue787.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue787.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue787.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v term:20 #-} module Issue787 where data ⊥ : Set where data List (A : Set) : Set where [] : List A _∷_ : A → List A → List A data Rat' {X : Set} : List (List X) → List X → Set where cons : ∀{ss x xs} → Rat' ((x ∷ xs) ∷ ss) xs → Rat' ss (x ∷ xs) bad : {X : Set} (xs : List X) (acc : List (List X)) (p : Rat' acc xs) → ⊥ bad .(x ∷ xs) acc (cons {ss = .acc} {x = x} {xs = xs} p) = bad (x ∷ xs) acc (cons {ss = acc} {x = x} {xs = xs} p) -- Andreas, 2013-02-18 -- This should give a termination error. -- It did pass up to today because of the idempotency check -- excluded bad calls with embedded sub-matrices. -- Disabling matrix-shaped orders, which do not have a formal semantics -- anyway, bring the termination problem to Agda's attention.
33.478261
73
0.602597
4eb9f8a8d8f39a9182a585a73d91359cb5ecfff9
1,219
agda
Agda
Univalence/LeqLemmas.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
Univalence/LeqLemmas.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
Univalence/LeqLemmas.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 LeqLemmas where open import Data.Nat using (ℕ; suc; _+_; _*_; _<_; _≤_; _≤?_; z≤n; s≤s; module ≤-Reasoning) open import Data.Nat.Properties.Simple using (+-comm) open import Data.Nat.Properties using (n≤m+n) open import Relation.Binary using (Decidable) ------------------------------------------------------------------------------ -- Proofs and definitions about ≤ on natural numbers _<?_ : Decidable _<_ i <? j = suc i ≤? j cong+r≤ : ∀ {i j} → i ≤ j → (k : ℕ) → i + k ≤ j + k cong+r≤ {0} {j} z≤n k = n≤m+n j k cong+r≤ {suc i} {0} () k -- absurd cong+r≤ {suc i} {suc j} (s≤s i≤j) k = s≤s (cong+r≤ {i} {j} i≤j k) cong+l≤ : ∀ {i j} → i ≤ j → (k : ℕ) → k + i ≤ k + j cong+l≤ {i} {j} i≤j k = begin (k + i ≡⟨ +-comm k i ⟩ i + k ≤⟨ cong+r≤ i≤j k ⟩ j + k ≡⟨ +-comm j k ⟩ k + j ∎) where open ≤-Reasoning cong*r≤ : ∀ {i j} → i ≤ j → (k : ℕ) → i * k ≤ j * k cong*r≤ {0} {j} z≤n k = z≤n cong*r≤ {suc i} {0} () k -- absurd cong*r≤ {suc i} {suc j} (s≤s i≤j) k = cong+l≤ (cong*r≤ i≤j k) k ------------------------------------------------------------------------------
31.25641
78
0.406071
1156079c25d4f61c84c4f929decbbf131b230aab
674
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Propositional/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Propositional/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Propositional/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of interleaving using propositional equality ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Ternary.Interleaving.Propositional.Properties {a} {A : Set a} where import Data.List.Relation.Ternary.Interleaving.Setoid.Properties as SetoidProperties open import Relation.Binary.PropositionalEquality using (setoid) ------------------------------------------------------------------------ -- Re-exporting existing properties open SetoidProperties (setoid A) public
33.7
72
0.532641
52b5be80acaa58d7fb5d59315704c0cad9aecee2
50,106
agda
Agda
src/Lens/Non-dependent/Equivalent-preimages.agda
Saizan/dependent-lenses
b7921cc6b52858cd7d8a52c183c7a6544d1a4062
[ "MIT" ]
null
null
null
src/Lens/Non-dependent/Equivalent-preimages.agda
Saizan/dependent-lenses
b7921cc6b52858cd7d8a52c183c7a6544d1a4062
[ "MIT" ]
null
null
null
src/Lens/Non-dependent/Equivalent-preimages.agda
Saizan/dependent-lenses
b7921cc6b52858cd7d8a52c183c7a6544d1a4062
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Lenses defined in terms of a getter, equivalences between the -- getter's "preimages", and a coherence property ------------------------------------------------------------------------ {-# OPTIONS --cubical --safe #-} import Equality.Path as P module Lens.Non-dependent.Equivalent-preimages {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude renaming (_∘_ to _⊚_) open import Bijection equality-with-J as B using (_↔_) open import Equality.Path.Isomorphisms eq hiding (univ) open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional eq as PT using (∥_∥; ∣_∣) open import Preimage equality-with-J using (_⁻¹_) open import Surjection equality-with-J using (_↠_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent eq import Lens.Non-dependent.Higher eq as Higher import Lens.Non-dependent.Traditional eq as Traditional private variable ℓ : Level A B C : Set ℓ a b c z : A ------------------------------------------------------------------------ -- The lens type family -- Lenses defined in terms of a getter, equivalences between the -- getter's "preimages", and a coherence property. -- -- This definition is based on a suggestion from Andrea Vezzosi. Note -- that the fields and some derived properties correspond to things -- discussed by Paolo Capriotti in the context of his higher lenses -- (http://homotopytypetheory.org/2014/04/29/higher-lenses/). record Lens (A : Set a) (B : Set b) : Set (a ⊔ b) where no-eta-equality pattern constructor lens field -- A getter. get : A → B -- A function from one "preimage" of get to another. get⁻¹-const : (b₁ b₂ : B) → get ⁻¹ b₁ → get ⁻¹ b₂ -- This function is an equivalence. get⁻¹-const-equivalence : (b₁ b₂ : B) → Is-equivalence (get⁻¹-const b₁ b₂) -- A coherence property. get⁻¹-const-∘ : (b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p -- All the getter's "preimages" are equivalent. get⁻¹-constant : (b₁ b₂ : B) → get ⁻¹ b₁ ≃ get ⁻¹ b₂ get⁻¹-constant b₁ b₂ = Eq.⟨ _ , get⁻¹-const-equivalence b₁ b₂ ⟩ -- The inverse of get⁻¹-const. get⁻¹-const⁻¹ : (b₁ b₂ : B) → get ⁻¹ b₂ → get ⁻¹ b₁ get⁻¹-const⁻¹ b₁ b₂ = _≃_.from (get⁻¹-constant b₁ b₂) -- Some derived coherence properties. get⁻¹-const-id : (b : B) (p : get ⁻¹ b) → get⁻¹-const b b p ≡ p get⁻¹-const-id b p = get⁻¹-const b b p ≡⟨ sym $ _≃_.left-inverse-of (get⁻¹-constant _ _) _ ⟩ get⁻¹-const⁻¹ b b (get⁻¹-const b b (get⁻¹-const b b p)) ≡⟨ cong (get⁻¹-const⁻¹ b b) $ get⁻¹-const-∘ _ _ _ _ ⟩ get⁻¹-const⁻¹ b b (get⁻¹-const b b p) ≡⟨ _≃_.left-inverse-of (get⁻¹-constant _ _) _ ⟩∎ p ∎ get⁻¹-const-inverse : (b₁ b₂ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₁ b₂ p ≡ get⁻¹-const⁻¹ b₂ b₁ p get⁻¹-const-inverse b₁ b₂ p = sym $ _≃_.to-from (get⁻¹-constant _ _) ( get⁻¹-const b₂ b₁ (get⁻¹-const b₁ b₂ p) ≡⟨ get⁻¹-const-∘ _ _ _ _ ⟩ get⁻¹-const b₁ b₁ p ≡⟨ get⁻¹-const-id _ _ ⟩∎ p ∎) -- A setter. set : A → B → A set a b = $⟨ a , refl _ ⟩ get ⁻¹ get a ↝⟨ get⁻¹-const (get a) b ⟩ get ⁻¹ b ↝⟨ proj₁ ⟩□ A □ -- The lens laws can be proved. get-set : ∀ a b → get (set a b) ≡ b get-set a b = get (proj₁ (get⁻¹-const (get a) b (a , refl _))) ≡⟨ proj₂ (get⁻¹-const (get a) b (a , refl _)) ⟩∎ b ∎ set-get : ∀ a → set a (get a) ≡ a set-get a = proj₁ (get⁻¹-const (get a) (get a) (a , refl _)) ≡⟨ cong proj₁ $ get⁻¹-const-id _ _ ⟩∎ a ∎ set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ set-set a b₁ b₂ = proj₁ (get⁻¹-const (get (set a b₁)) b₂ (set a b₁ , refl _)) ≡⟨ elim¹ (λ {b} eq → proj₁ (get⁻¹-const (get (set a b₁)) b₂ (set a b₁ , refl _)) ≡ proj₁ (get⁻¹-const b b₂ (set a b₁ , eq))) (refl _) (get-set a b₁) ⟩ proj₁ (get⁻¹-const b₁ b₂ (set a b₁ , get-set a b₁)) ≡⟨⟩ proj₁ (get⁻¹-const b₁ b₂ (get⁻¹-const (get a) b₁ (a , refl _))) ≡⟨ cong proj₁ $ get⁻¹-const-∘ _ _ _ _ ⟩∎ proj₁ (get⁻¹-const (get a) b₂ (a , refl _)) ∎ -- A traditional lens. traditional-lens : Traditional.Lens A B traditional-lens = record { get = get ; set = set ; get-set = get-set ; set-get = set-get ; set-set = set-set } instance -- The lenses defined above have getters and setters. has-getter-and-setter : Has-getter-and-setter (Lens {a = a} {b = b}) has-getter-and-setter = record { get = Lens.get ; set = Lens.set } -- The record type above is equivalent to a nested Σ-type. Lens-as-Σ : Lens A B ≃ ∃ λ (get : A → B) → ∃ λ (get⁻¹-const : (b₁ b₂ : B) → get ⁻¹ b₁ → get ⁻¹ b₂) → ((b₁ b₂ : B) → Is-equivalence (get⁻¹-const b₁ b₂)) × ((b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p) Lens-as-Σ = Eq.↔→≃ (λ l → get l , get⁻¹-const l , get⁻¹-const-equivalence l , get⁻¹-const-∘ l) (λ (g , c , c-e , c-∘) → record { get = g ; get⁻¹-const = c ; get⁻¹-const-equivalence = c-e ; get⁻¹-const-∘ = c-∘ }) refl (λ { (lens _ _ _ _) → refl _ }) where open Lens -- A variant of Lens-as-Σ. Lens-as-Σ′ : Lens A B ≃ ∃ λ (get : A → B) → ∃ λ (get⁻¹-constant : (b₁ b₂ : B) → get ⁻¹ b₁ ≃ get ⁻¹ b₂) → let get⁻¹-const : ∀ _ _ → _ get⁻¹-const = λ b₁ b₂ → _≃_.to (get⁻¹-constant b₁ b₂) in (b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p Lens-as-Σ′ {A = A} {B = B} = Lens A B ↝⟨ Lens-as-Σ ⟩ (∃ λ (get : A → B) → ∃ λ (get⁻¹-const : (b₁ b₂ : B) → get ⁻¹ b₁ → get ⁻¹ b₂) → ((b₁ b₂ : B) → Is-equivalence (get⁻¹-const b₁ b₂)) × ((b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p)) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩ (∃ λ (get : A → B) → ∃ λ ((get⁻¹-const , _) : ∃ λ (get⁻¹-const : (b₁ b₂ : B) → get ⁻¹ b₁ → get ⁻¹ b₂) → (b₁ b₂ : B) → Is-equivalence (get⁻¹-const b₁ b₂)) → (b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p) ↝⟨ (∃-cong λ _ → Σ-cong-contra (ΠΣ-comm F.∘ ∀-cong ext (λ _ → ΠΣ-comm)) λ _ → F.id) ⟩ (∃ λ (get : A → B) → ∃ λ (f : (b₁ b₂ : B) → ∃ λ (get⁻¹-const : get ⁻¹ b₁ → get ⁻¹ b₂) → Is-equivalence get⁻¹-const) → let get⁻¹-const : ∀ _ _ → _ get⁻¹-const = λ b₁ b₂ → proj₁ (f b₁ b₂) in (b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p) ↝⟨ (∃-cong λ _ → Σ-cong-contra (∀-cong ext λ _ → ∀-cong ext λ _ → Eq.≃-as-Σ) λ _ → F.id) ⟩□ (∃ λ (get : A → B) → ∃ λ (get⁻¹-constant : (b₁ b₂ : B) → get ⁻¹ b₁ ≃ get ⁻¹ b₂) → let get⁻¹-const : ∀ _ _ → _ get⁻¹-const = λ b₁ b₂ → _≃_.to (get⁻¹-constant b₁ b₂) in (b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) → get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p) □ ------------------------------------------------------------------------ -- Some results related to h-levels -- If the domain of a lens is inhabited and has h-level n, -- then the codomain also has h-level n. h-level-respects-lens-from-inhabited : ∀ n → Lens A B → A → H-level n A → H-level n B h-level-respects-lens-from-inhabited {A = A} {B = B} n l a = H-level n A ↝⟨ H-level.respects-surjection surj n ⟩□ H-level n B □ where open Lens l surj : A ↠ B surj = record { logical-equivalence = record { to = get ; from = set a } ; right-inverse-of = λ b → get (set a b) ≡⟨ get-set a b ⟩∎ b ∎ } -- If A and B have h-level n given the assumption that the other type -- is inhabited, then Lens A B has h-level n. lens-preserves-h-level : ∀ n → (B → H-level n A) → (A → H-level n B) → H-level n (Lens A B) lens-preserves-h-level {B = B} {A = A} n hA hB = H-level-cong _ n (inverse Lens-as-Σ′) $ Σ-closure n (Π-closure ext n λ a → hB a) λ _ → Σ-closure n (Π-closure ext n λ b → Π-closure ext n λ _ → Eq.h-level-closure ext n (⁻¹-closure (hA b) hB) (⁻¹-closure (hA b) hB)) λ _ → (Π-closure ext n λ b → Π-closure ext n λ _ → Π-closure ext n λ _ → Π-closure ext n λ _ → ⇒≡ n (⁻¹-closure (hA b) hB)) where ⁻¹-closure : {f : A → B} {x : B} → H-level n A → (A → H-level n B) → H-level n (f ⁻¹ x) ⁻¹-closure hA hB = Σ-closure n hA λ a → ⇒≡ n (hB a) -- If A has positive h-level n, then Lens A B also has h-level n. lens-preserves-h-level-of-domain : ∀ n → H-level (1 + n) A → H-level (1 + n) (Lens A B) lens-preserves-h-level-of-domain n hA = [inhabited⇒+]⇒+ n λ l → lens-preserves-h-level (1 + n) (λ _ → hA) λ a → h-level-respects-lens-from-inhabited _ l a hA ------------------------------------------------------------------------ -- Some equality characterisation lemmas -- An equality characterisation lemma. equality-characterisation : let open Lens in {A : Set a} {B : Set b} {l₁ l₂ : Lens A B} → (l₁ ≡ l₂) ≃ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (gc : ∀ b₁ b₂ p → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ b₂ p ≡ get⁻¹-const l₂ b₁ b₂ p) → subst (λ (get , gc) → ∀ b₁ b₂ b₃ (p : get ⁻¹ b₁) → gc b₂ b₃ (gc b₁ b₂ p) ≡ gc b₁ b₃ p) (Σ-≡,≡→≡ (⟨ext⟩ g) (⟨ext⟩ λ b₁ → ⟨ext⟩ λ b₂ → ⟨ext⟩ λ p → gc b₁ b₂ p)) (get⁻¹-const-∘ l₁) ≡ get⁻¹-const-∘ l₂) equality-characterisation {l₁ = l₁} {l₂ = l₂} = l₁ ≡ l₂ ↝⟨ inverse $ Eq.≃-≡ (lemma₁ F.∘ Lens-as-Σ) ⟩ ( ((get l₁ , get⁻¹-const l₁) , get⁻¹-const-∘ l₁) , get⁻¹-const-equivalence l₁ ) ≡ ( ((get l₂ , get⁻¹-const l₂) , get⁻¹-const-∘ l₂) , get⁻¹-const-equivalence l₂ ) ↔⟨ inverse $ ignore-propositional-component (Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Eq.propositional ext _) ⟩ ((get l₁ , get⁻¹-const l₁) , get⁻¹-const-∘ l₁) ≡ ((get l₂ , get⁻¹-const l₂) , get⁻¹-const-∘ l₂) ↔⟨ inverse B.Σ-≡,≡↔≡ ⟩ (∃ λ (p : (get l₁ , get⁻¹-const l₁) ≡ (get l₂ , get⁻¹-const l₂)) → subst (λ (get , gc) → ∀ b₁ b₂ b₃ (p : get ⁻¹ b₁) → gc b₂ b₃ (gc b₁ b₂ p) ≡ gc b₁ b₃ p) p (get⁻¹-const-∘ l₁) ≡ get⁻¹-const-∘ l₂) ↝⟨ (Σ-cong-contra B.Σ-≡,≡↔≡ λ _ → F.id) ⟩ (∃ λ (p : ∃ λ (g : get l₁ ≡ get l₂) → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) g (get⁻¹-const l₁) ≡ get⁻¹-const l₂) → subst (λ (get , gc) → ∀ b₁ b₂ b₃ (p : get ⁻¹ b₁) → gc b₂ b₃ (gc b₁ b₂ p) ≡ gc b₁ b₃ p) (uncurry Σ-≡,≡→≡ p) (get⁻¹-const-∘ l₁) ≡ get⁻¹-const-∘ l₂) ↔⟨ inverse Σ-assoc ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (gc : subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) g (get⁻¹-const l₁) ≡ get⁻¹-const l₂) → subst (λ (get , gc) → ∀ b₁ b₂ b₃ (p : get ⁻¹ b₁) → gc b₂ b₃ (gc b₁ b₂ p) ≡ gc b₁ b₃ p) (Σ-≡,≡→≡ g gc) (get⁻¹-const-∘ l₁) ≡ get⁻¹-const-∘ l₂) ↝⟨ (Σ-cong-contra (Eq.extensionality-isomorphism bad-ext) λ _ → F.id) ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (gc : subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) ≡ get⁻¹-const l₂) → subst (λ (get , gc) → ∀ b₁ b₂ b₃ (p : get ⁻¹ b₁) → gc b₂ b₃ (gc b₁ b₂ p) ≡ gc b₁ b₃ p) (Σ-≡,≡→≡ (⟨ext⟩ g) gc) (get⁻¹-const-∘ l₁) ≡ get⁻¹-const-∘ l₂) ↝⟨ (∃-cong λ _ → Σ-cong-contra (inverse $ lemma₂ _) λ _ → F.id) ⟩□ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (gc : ∀ b₁ b₂ p → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ b₂ p ≡ get⁻¹-const l₂ b₁ b₂ p) → subst (λ (get , gc) → ∀ b₁ b₂ b₃ (p : get ⁻¹ b₁) → gc b₂ b₃ (gc b₁ b₂ p) ≡ gc b₁ b₃ p) (Σ-≡,≡→≡ (⟨ext⟩ g) (⟨ext⟩ λ b₁ → ⟨ext⟩ λ b₂ → ⟨ext⟩ λ p → gc b₁ b₂ p)) (get⁻¹-const-∘ l₁) ≡ get⁻¹-const-∘ l₂) □ where open Lens lemma₁ : {P : A → Set ℓ} {Q R : (x : A) → P x → Set ℓ} → (∃ λ (x : A) → ∃ λ (y : P x) → Q x y × R x y) ≃ (∃ λ (((x , y) , _) : Σ (Σ A P) (uncurry R)) → Q x y) lemma₁ {A = A} {P = P} {Q = Q} {R = R} = (∃ λ (x : A) → ∃ λ (y : P x) → Q x y × R x y) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩ (∃ λ (x : A) → ∃ λ (y : P x) → R x y × Q x y) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩ (∃ λ (x : A) → ∃ λ ((y , _) : ∃ λ (y : P x) → R x y) → Q x y) ↔⟨ Σ-assoc ⟩ (∃ λ ((x , y , _) : ∃ λ (x : A) → ∃ λ (y : P x) → R x y) → Q x y) ↝⟨ (Σ-cong Σ-assoc λ _ → F.id) ⟩□ (∃ λ (((x , y) , _) : Σ (Σ A P) (uncurry R)) → Q x y) □ lemma₂ : (g : ∀ a → get l₁ a ≡ get l₂ a) → _ lemma₂ g = subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) ≡ get⁻¹-const l₂ ↝⟨ inverse $ Eq.extensionality-isomorphism bad-ext ⟩ (∀ b₁ → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ ≡ get⁻¹-const l₂ b₁) ↝⟨ (∀-cong ext λ _ → inverse $ Eq.extensionality-isomorphism bad-ext) ⟩ (∀ b₁ b₂ → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ b₂ ≡ get⁻¹-const l₂ b₁ b₂) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → inverse $ Eq.extensionality-isomorphism bad-ext) ⟩□ (∀ b₁ b₂ p → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ b₂ p ≡ get⁻¹-const l₂ b₁ b₂ p) □ -- An equality characterisation lemma for lenses from sets. equality-characterisation-for-sets : let open Lens in {A : Set a} {B : Set b} {l₁ l₂ : Lens A B} → Is-set A → (l₁ ≡ l₂) ≃ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∀ b₁ b₂ p → proj₁ (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p)) ≡ proj₁ (get⁻¹-const l₂ b₁ b₂ p)) equality-characterisation-for-sets {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} A-set = l₁ ≡ l₂ ↝⟨ equality-characterisation ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (gc : ∀ b₁ b₂ p → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ b₂ p ≡ get⁻¹-const l₂ b₁ b₂ p) → subst (λ (get , gc) → ∀ b₁ b₂ b₃ (p : get ⁻¹ b₁) → gc b₂ b₃ (gc b₁ b₂ p) ≡ gc b₁ b₃ p) (Σ-≡,≡→≡ (⟨ext⟩ g) (⟨ext⟩ λ b₁ → ⟨ext⟩ λ b₂ → ⟨ext⟩ λ p → gc b₁ b₂ p)) (get⁻¹-const-∘ l₁) ≡ get⁻¹-const-∘ l₂) ↔⟨ (∃-cong λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ +⇒≡ $ Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → ⁻¹-set) ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∀ b₁ b₂ p → subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ b₂ p ≡ get⁻¹-const l₂ b₁ b₂ p) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_≡ _) $ lemma₁ _ _ _ _) ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∀ b₁ b₂ p → subst (_⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p)) ≡ get⁻¹-const l₂ b₁ b₂ p) ↔⟨ (∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ p → drop-⊤-right (λ _ → _⇔_.to contractible⇔↔⊤ $ +⇒≡ (B-set (proj₁ p))) F.∘ inverse B.Σ-≡,≡↔≡) ⟩ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∀ b₁ b₂ p → proj₁ (subst (_⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p))) ≡ proj₁ (get⁻¹-const l₂ b₁ b₂ p)) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_≡ _) $ lemma₂ _ _ _ _) ⟩□ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∀ b₁ b₂ p → proj₁ (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p)) ≡ proj₁ (get⁻¹-const l₂ b₁ b₂ p)) □ where open Lens B-set : A → Is-set B B-set a = h-level-respects-lens-from-inhabited 2 l₁ a A-set ⁻¹-set : Is-set (get l₂ ⁻¹ b) ⁻¹-set = Σ-closure 2 A-set λ a → mono₁ 1 (B-set a) lemma₁ : ∀ g b₁ b₂ p → _ lemma₁ g b₁ b₂ p = subst (λ get → ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁) b₁ b₂ p ≡⟨ cong (λ f → f b₂ p) $ sym $ push-subst-application (⟨ext⟩ g) (λ get b₁ → ∀ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) ⟩ subst (λ get → ∀ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁ b₁) b₂ p ≡⟨ cong (λ f → f p) $ sym $ push-subst-application (⟨ext⟩ g) (λ get b₂ → get ⁻¹ b₁ → get ⁻¹ b₂) ⟩ subst (λ get → get ⁻¹ b₁ → get ⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁ b₁ b₂) p ≡⟨ subst-→ {x₁≡x₂ = ⟨ext⟩ g} ⟩∎ subst (_⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p)) ∎ lemma₂ : ∀ g b₁ b₂ p → _ lemma₂ g b₁ b₂ p = proj₁ (subst (_⁻¹ b₂) (⟨ext⟩ g) (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p))) ≡⟨ cong proj₁ $ push-subst-pair {y≡z = ⟨ext⟩ g} _ _ ⟩ subst (λ _ → A) (⟨ext⟩ g) (proj₁ (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p))) ≡⟨ subst-const (⟨ext⟩ g) ⟩∎ proj₁ (get⁻¹-const l₁ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ g) p)) ∎ ------------------------------------------------------------------------ -- Conversions between different kinds of lenses -- Higher lenses can be converted to the ones defined above. higher→ : Higher.Lens A B → Lens A B higher→ l@(Higher.⟨ _ , _ , _ ⟩) = _≃_.from Lens-as-Σ′ ( Higher.Lens.get l , Higher.get⁻¹-constant l , Higher.get⁻¹-constant-∘ l ) -- The conversion preserves getters and setters. higher→-preserves-getters-and-setters : Preserves-getters-and-setters-→ A B higher→ higher→-preserves-getters-and-setters Higher.⟨ _ , _ , _ ⟩ = refl _ , refl _ -- A lens of the kind defined above can be converted to a higher one -- if the codomain is inhabited when it is merely inhabited. →higher : (∥ B ∥ → B) → Lens A B → Higher.Lens A B →higher {B = B} {A = A} ∥B∥→B l@(lens _ _ _ _) = record { R = ∃ λ (b : ∥ B ∥) → Lens.get l ⁻¹ (∥B∥→B b) ; equiv = A ↔⟨ (inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ other-singleton-contractible _) ⟩ (∃ λ a → ∃ λ b → Lens.get l a ≡ b) ↔⟨ ∃-comm ⟩ (∃ λ b → Lens.get l ⁻¹ b) ↝⟨ (Σ-cong (inverse PT.∥∥×≃) λ _ → Lens.get⁻¹-constant l _ _) ⟩ (∃ λ ((b , _) : ∥ B ∥ × B) → Lens.get l ⁻¹ (∥B∥→B b)) ↔⟨ inverse Σ-assoc ⟩ (∃ λ (b : ∥ B ∥) → B × Lens.get l ⁻¹ (∥B∥→B b)) ↔⟨ (∃-cong λ _ → ×-comm) ⟩ (∃ λ (b : ∥ B ∥) → Lens.get l ⁻¹ (∥B∥→B b) × B) ↔⟨ Σ-assoc ⟩□ (∃ λ (b : ∥ B ∥) → Lens.get l ⁻¹ (∥B∥→B b)) × B □ ; inhabited = proj₁ } -- The conversion preserves getters and setters. →higher-preserves-getters-and-setters : {B : Set b} (∥B∥→B : ∥ B ∥ → B) → Preserves-getters-and-setters-→ A B (→higher ∥B∥→B) →higher-preserves-getters-and-setters {A = A} ∥B∥→B l@(lens _ _ _ _) = refl _ , ⟨ext⟩ λ a → ⟨ext⟩ λ b → let a′ = set a b in _≃_.to-from (Higher.Lens.equiv (→higher ∥B∥→B l)) $ cong₂ _,_ (∣ get a′ ∣ , get⁻¹-const (get a′) (∥B∥→B ∣ get a′ ∣) (a′ , refl _) ≡⟨ Σ-≡,≡→≡ (PT.truncation-is-proposition _ _) ( subst (λ b → get ⁻¹ ∥B∥→B b) (PT.truncation-is-proposition _ _) (get⁻¹-const (get a′) (∥B∥→B ∣ get a′ ∣) (a′ , refl _)) ≡⟨ elim¹ (λ {f} _ → subst (λ b → get ⁻¹ f b) (PT.truncation-is-proposition _ _) (get⁻¹-const (get a′) (f ∣ get a′ ∣) (a′ , refl _)) ≡ get⁻¹-const (get a) (f ∣ get a ∣) (a , refl _)) ( subst (λ _ → get ⁻¹ ∥B∥→B ∣ b ∣) (PT.truncation-is-proposition _ _) (get⁻¹-const (get a′) (∥B∥→B ∣ b ∣) (a′ , refl _)) ≡⟨ subst-const (PT.truncation-is-proposition _ _) ⟩ get⁻¹-const (get a′) (∥B∥→B ∣ b ∣) (a′ , refl _) ≡⟨ sym $ get⁻¹-const-∘ _ _ _ _ ⟩ get⁻¹-const (get a) (∥B∥→B ∣ b ∣) (get⁻¹-const (get a′) (get a) (a′ , refl _)) ≡⟨ cong (get⁻¹-const (get a) (∥B∥→B ∣ b ∣)) $ elim¹ (λ {b} eq → get⁻¹-const (get a′) (get a) (a′ , refl _) ≡ get⁻¹-const b (get a) (a′ , eq)) (refl _) (get-set a b) ⟩ get⁻¹-const (get a) (∥B∥→B ∣ b ∣) (get⁻¹-const b (get a) (set a b , get-set a b)) ≡⟨⟩ get⁻¹-const (get a) (∥B∥→B ∣ b ∣) (get⁻¹-const b (get a) (get⁻¹-const (get a) b (a , refl _))) ≡⟨ cong (λ p → get⁻¹-const (get a) (∥B∥→B ∣ b ∣) (get⁻¹-const b (get a) p)) $ get⁻¹-const-inverse _ _ _ ⟩ get⁻¹-const (get a) (∥B∥→B ∣ b ∣) (get⁻¹-const b (get a) (get⁻¹-const⁻¹ b (get a) (a , refl _))) ≡⟨ cong (get⁻¹-const (get a) (∥B∥→B ∣ b ∣)) $ _≃_.right-inverse-of (get⁻¹-constant _ _) _ ⟩∎ get⁻¹-const (get a) (∥B∥→B ∣ b ∣) (a , refl _) ∎) (⟨ext⟩ λ _ → cong ∥B∥→B $ PT.truncation-is-proposition _ _) ⟩∎ get⁻¹-const (get a) (∥B∥→B ∣ get a ∣) (a , refl _) ∎) ⟩∎ ∣ get a ∣ , get⁻¹-const (get a) (∥B∥→B ∣ get a ∣) (a , refl _) ∎) (get (set a b) ≡⟨ get-set a b ⟩∎ b ∎) where open Lens l -- There is a split surjection from Lens A B to Higher.Lens A B if B -- is inhabited when it is merely inhabited (assuming univalence). ↠higher : {A : Set a} {B : Set b} → Univalence (a ⊔ b) → (∥ B ∥ → B) → Lens A B ↠ Higher.Lens A B ↠higher {A = A} {B = B} univ ∥B∥→B = record { logical-equivalence = record { to = →higher ∥B∥→B ; from = higher→ } ; right-inverse-of = λ l → Higher.lenses-equal-if-setters-equal univ _ _ (λ _ → ∥B∥→B) (set (→higher ∥B∥→B (higher→ l)) ≡⟨ proj₂ $ →higher-preserves-getters-and-setters ∥B∥→B (higher→ l) ⟩ Lens.set (higher→ l) ≡⟨ proj₂ $ higher→-preserves-getters-and-setters l ⟩∎ set l ∎) } where open Higher.Lens -- The split surjection preserves getters and setters. ↠higher-preserves-getters-and-setters : {A : Set a} {B : Set b} (univ : Univalence (a ⊔ b)) (∥B∥→B : ∥ B ∥ → B) → Preserves-getters-and-setters-⇔ A B (_↠_.logical-equivalence (↠higher univ ∥B∥→B)) ↠higher-preserves-getters-and-setters _ ∥B∥→B = →higher-preserves-getters-and-setters ∥B∥→B , higher→-preserves-getters-and-setters -- If B is inhabited when it is merely inhabited and A has positive -- h-level n, then Higher.Lens A B also has h-level n (assuming -- univalence). higher-lens-preserves-h-level-of-domain : {A : Set a} {B : Set b} → Univalence (a ⊔ b) → (∥ B ∥ → B) → ∀ n → H-level (1 + n) A → H-level (1 + n) (Higher.Lens A B) higher-lens-preserves-h-level-of-domain {A = A} {B = B} univ ∥B∥→B n = H-level (1 + n) A ↝⟨ lens-preserves-h-level-of-domain n ⟩ H-level (1 + n) (Lens A B) ↝⟨ H-level.respects-surjection (↠higher univ ∥B∥→B) (1 + n) ⟩□ H-level (1 + n) (Higher.Lens A B) □ -- Traditional lenses that satisfy some coherence properties can be -- translated to lenses of the kind defined above. coherent→ : Block "conversion" → Traditional.Coherent-lens A B → Lens A B coherent→ ⊠ l = _≃_.from Lens-as-Σ′ ( get , (λ b₁ b₂ → Eq.↔→≃ (gg b₁ b₂) (gg b₂ b₁) (gg∘gg b₁ b₂) (gg∘gg b₂ b₁)) , (λ b₁ b₂ b₃ (a , _) → Σ-≡,≡→≡ (set (set a b₂) b₃ ≡⟨ set-set a b₂ b₃ ⟩∎ set a b₃ ∎) (subst (λ a → get a ≡ b₃) (set-set a b₂ b₃) (get-set (set a b₂) b₃) ≡⟨ subst-∘ _ _ (set-set a b₂ b₃) ⟩ subst (_≡ b₃) (cong get (set-set a b₂ b₃)) (get-set (set a b₂) b₃) ≡⟨ subst-trans-sym {y≡x = cong get (set-set a b₂ b₃)} ⟩ trans (sym (cong get (set-set a b₂ b₃))) (get-set (set a b₂) b₃) ≡⟨ get-set-set′ _ _ _ ⟩∎ get-set a b₃ ∎)) ) where open Traditional.Coherent-lens l get-set-set′ : ∀ a b₁ b₂ → trans (sym (cong get (set-set a b₁ b₂))) (get-set (set a b₁) b₂) ≡ get-set a b₂ get-set-set′ a b₁ b₂ = trans (sym (cong get (set-set a b₁ b₂))) (get-set (set a b₁) b₂) ≡⟨ cong (λ eq → trans (sym eq) (get-set _ _)) $ get-set-set _ _ _ ⟩ trans (sym (trans (get-set (set a b₁) b₂) (sym (get-set a b₂)))) (get-set (set a b₁) b₂) ≡⟨ cong (flip trans (get-set _ _)) $ sym-trans _ (sym (get-set _ _)) ⟩ trans (trans (sym (sym (get-set a b₂))) (sym (get-set (set a b₁) b₂))) (get-set (set a b₁) b₂) ≡⟨ trans-[trans-sym]- _ (get-set _ _) ⟩ sym (sym (get-set a b₂)) ≡⟨ sym-sym (get-set _ _) ⟩∎ get-set a b₂ ∎ gg : ∀ b₁ b₂ → get ⁻¹ b₁ → get ⁻¹ b₂ gg b₁ b₂ (a , _) = set a b₂ , get-set a b₂ gg∘gg : ∀ b₁ b₂ p → gg b₁ b₂ (gg b₂ b₁ p) ≡ p gg∘gg b₁ b₂ (a , get-a≡b₂) = Σ-≡,≡→≡ eq₁ (subst (λ a → get a ≡ b₂) eq₁ (get-set (set a b₁) b₂) ≡⟨ subst-∘ _ _ eq₁ ⟩ subst (_≡ b₂) (cong get eq₁) (get-set (set a b₁) b₂) ≡⟨ subst-trans-sym {y≡x = cong get eq₁} ⟩ trans (sym (cong get eq₁)) (get-set (set a b₁) b₂) ≡⟨ cong (flip trans (get-set (set a b₁) b₂)) lemma₂ ⟩ trans (trans (trans (sym (cong get (set-get a))) (cong (get ⊚ set a) get-a≡b₂)) (sym (cong get (set-set a b₁ b₂)))) (get-set (set a b₁) b₂) ≡⟨ trans-assoc _ _ (get-set (set a b₁) b₂) ⟩ trans (trans (sym (cong get (set-get a))) (cong (get ⊚ set a) get-a≡b₂)) (trans (sym (cong get (set-set a b₁ b₂))) (get-set (set a b₁) b₂)) ≡⟨ trans-assoc _ _ (trans (sym (cong get (set-set a b₁ b₂))) (get-set (set a b₁) b₂)) ⟩ trans (sym (cong get (set-get a))) (trans (cong (get ⊚ set a) get-a≡b₂) (trans (sym (cong get (set-set a b₁ b₂))) (get-set (set a b₁) b₂))) ≡⟨ cong₂ (λ p q → trans (sym p) (trans (cong (get ⊚ set a) get-a≡b₂) q)) (get-set-get _) (get-set-set′ _ _ _) ⟩ trans (sym (get-set a (get a))) (trans (cong (get ⊚ set a) get-a≡b₂) (get-set a b₂)) ≡⟨ cong (λ eq → trans (sym (eq (get a))) (trans (cong (get ⊚ set a) get-a≡b₂) (eq b₂))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) _ ⟩ trans (sym (ext⁻¹ (⟨ext⟩ (get-set a)) (get a))) (trans (cong (get ⊚ set a) get-a≡b₂) (ext⁻¹ (⟨ext⟩ (get-set a)) b₂)) ≡⟨ elim₁ (λ {f} gs → trans (sym (ext⁻¹ gs (get a))) (trans (cong f get-a≡b₂) (ext⁻¹ gs b₂)) ≡ get-a≡b₂) ( trans (sym (ext⁻¹ (refl id) (get a))) (trans (cong id get-a≡b₂) (ext⁻¹ (refl id) b₂)) ≡⟨ cong₂ (λ p q → trans (sym p) (trans (cong id get-a≡b₂) q)) (ext⁻¹-refl _) (ext⁻¹-refl _) ⟩ trans (sym (refl _)) (trans (cong id get-a≡b₂) (refl _)) ≡⟨ cong₂ trans sym-refl (trans-reflʳ _) ⟩ trans (refl _) (cong id get-a≡b₂) ≡⟨ trans-reflˡ (cong id get-a≡b₂) ⟩ cong id get-a≡b₂ ≡⟨ sym $ cong-id get-a≡b₂ ⟩∎ get-a≡b₂ ∎) (⟨ext⟩ (get-set a)) ⟩ get-a≡b₂ ∎) where eq₁ = set (set a b₁) b₂ ≡⟨ set-set a b₁ b₂ ⟩ set a b₂ ≡⟨ cong (set a) (sym get-a≡b₂) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎ lemma₁ = sym (cong get (cong (set a) (sym get-a≡b₂))) ≡⟨ cong sym $ cong-∘ _ _ (sym get-a≡b₂) ⟩ sym (cong (get ⊚ set a) (sym get-a≡b₂)) ≡⟨ sym $ cong-sym _ (sym get-a≡b₂) ⟩ cong (get ⊚ set a) (sym (sym get-a≡b₂)) ≡⟨ cong (cong (get ⊚ set a)) $ sym-sym get-a≡b₂ ⟩∎ cong (get ⊚ set a) get-a≡b₂ ∎ lemma₂ = sym (cong get eq₁) ≡⟨⟩ sym (cong get (trans (set-set a b₁ b₂) (trans (cong (set a) (sym get-a≡b₂)) (set-get a)))) ≡⟨ cong sym $ cong-trans _ _ (trans (cong (set a) (sym get-a≡b₂)) (set-get a)) ⟩ sym (trans (cong get (set-set a b₁ b₂)) (cong get (trans (cong (set a) (sym get-a≡b₂)) (set-get a)))) ≡⟨ cong (λ eq → sym (trans _ eq)) $ cong-trans _ _ (set-get a) ⟩ sym (trans (cong get (set-set a b₁ b₂)) (trans (cong get (cong (set a) (sym get-a≡b₂))) (cong get (set-get a)))) ≡⟨ sym-trans _ (trans (cong get (cong (set a) (sym get-a≡b₂))) (cong get (set-get a))) ⟩ trans (sym (trans (cong get (cong (set a) (sym get-a≡b₂))) (cong get (set-get a)))) (sym (cong get (set-set a b₁ b₂))) ≡⟨ cong (flip trans (sym (cong get (set-set a b₁ b₂)))) $ sym-trans _ (cong get (set-get a)) ⟩ trans (trans (sym (cong get (set-get a))) (sym (cong get (cong (set a) (sym get-a≡b₂))))) (sym (cong get (set-set a b₁ b₂))) ≡⟨ cong (λ eq → trans (trans (sym (cong get (set-get a))) eq) (sym (cong get (set-set a b₁ b₂)))) lemma₁ ⟩∎ trans (trans (sym (cong get (set-get a))) (cong (get ⊚ set a) get-a≡b₂)) (sym (cong get (set-set a b₁ b₂))) ∎ -- The conversion preserves getters and setters. coherent→-preserves-getters-and-setters : (b : Block "conversion") → Preserves-getters-and-setters-→ A B (coherent→ b) coherent→-preserves-getters-and-setters ⊠ _ = refl _ , refl _ -- If A is a set, then Traditional.Lens A B is equivalent to Lens A B. traditional≃ : Block "conversion" → Is-set A → Traditional.Lens A B ≃ Lens A B traditional≃ {A = A} {B = B} b@⊠ A-set = Eq.↔→≃ (Traditional.Lens A B ↔⟨ Traditional.≃coherent A-set ⟩ Traditional.Coherent-lens A B ↝⟨ coherent→ b ⟩□ Lens A B □) Lens.traditional-lens (λ l → _≃_.from (equality-characterisation-for-sets A-set) ( (λ _ → refl _) , (λ b₁ b₂ p@(a , _) → let l′ = traditional-lens l l″ = coherent→ b (_≃_.to (Traditional.≃coherent A-set) l′) in proj₁ (get⁻¹-const l″ b₁ b₂ (subst (_⁻¹ b₁) (sym $ ⟨ext⟩ λ _ → refl _) p)) ≡⟨ cong (λ eq → proj₁ (get⁻¹-const l″ b₁ b₂ (subst (_⁻¹ b₁) (sym eq) p))) ext-refl ⟩ proj₁ (get⁻¹-const l″ b₁ b₂ (subst (_⁻¹ b₁) (sym (refl _)) p)) ≡⟨ cong (λ eq → proj₁ (get⁻¹-const l″ b₁ b₂ (subst (_⁻¹ b₁) eq p))) sym-refl ⟩ proj₁ (get⁻¹-const l″ b₁ b₂ (subst (_⁻¹ b₁) (refl _) p)) ≡⟨ cong (proj₁ ⊚ get⁻¹-const l″ b₁ b₂) $ subst-refl _ _ ⟩ proj₁ (get⁻¹-const l″ b₁ b₂ p) ≡⟨⟩ set l (proj₁ p) b₂ ≡⟨⟩ proj₁ (get⁻¹-const l (get l a) b₂ (a , refl _)) ≡⟨ elim¹ (λ {b} eq → proj₁ (get⁻¹-const l (get l a) b₂ (a , refl _)) ≡ proj₁ (get⁻¹-const l b b₂ (a , eq))) (refl _) (proj₂ p) ⟩∎ proj₁ (get⁻¹-const l b₁ b₂ p) ∎) )) (λ _ → _↔_.from (Traditional.equality-characterisation-for-sets A-set) (refl _)) where open Lens B-set : Traditional.Lens A B → A → Is-set B B-set l a = Traditional.h-level-respects-lens-from-inhabited 2 l a A-set -- The equivalence preserves getters and setters. traditional≃-preserves-getters-and-setters : {A : Set a} (b : Block "conversion") (s : Is-set A) → Preserves-getters-and-setters-⇔ A B (_≃_.logical-equivalence (traditional≃ b s)) traditional≃-preserves-getters-and-setters ⊠ _ = (λ _ → refl _ , refl _) , (λ _ → refl _ , refl _) -- If B is inhabited when it is merely inhabited, then -- Traditional.Coherent-lens A B is logically equivalent to -- Higher.Lens A B. coherent⇔higher : Block "conversion" → (∥ B ∥ → B) → Traditional.Coherent-lens A B ⇔ Higher.Lens A B coherent⇔higher {B = B} {A = A} b ∥B∥→B = record { to = Traditional.Coherent-lens A B ↝⟨ coherent→ b ⟩ Lens A B ↝⟨ →higher ∥B∥→B ⟩□ Higher.Lens A B □ ; from = Higher.Lens.coherent-lens } -- The logical equivalence preserves getters and setters. coherent⇔higher-preserves-getters-and-setters : {B : Set b} (bc : Block "conversion") (∥B∥→B : ∥ B ∥ → B) → Preserves-getters-and-setters-⇔ A B (coherent⇔higher bc ∥B∥→B) coherent⇔higher-preserves-getters-and-setters b ∥B∥→B = Preserves-getters-and-setters-→-∘ {f = →higher ∥B∥→B} {g = coherent→ b} (→higher-preserves-getters-and-setters ∥B∥→B) (coherent→-preserves-getters-and-setters b) , (λ _ → refl _ , refl _) -- If B is inhabited when it is merely inhabited, then there is a -- split surjection from Traditional.Coherent-lens A B to -- Higher.Lens A B (assuming univalence). coherent↠higher : {A : Set a} {B : Set b} → Block "conversion" → Univalence (a ⊔ b) → (∥ B ∥ → B) → Traditional.Coherent-lens A B ↠ Higher.Lens A B coherent↠higher {A = A} {B = B} b univ ∥B∥→B = record { logical-equivalence = coherent⇔higher b ∥B∥→B ; right-inverse-of = λ l → Higher.lenses-equal-if-setters-equal univ _ _ (λ _ → ∥B∥→B) $ proj₂ (proj₁ (coherent⇔higher-preserves-getters-and-setters b ∥B∥→B) _) } -- The split surjection preserves getters and setters. coherent↠higher-preserves-getters-and-setters : {A : Set a} {B : Set b} (bc : Block "conversion") (univ : Univalence (a ⊔ b)) (∥B∥→B : ∥ B ∥ → B) → Preserves-getters-and-setters-⇔ A B (_↠_.logical-equivalence (coherent↠higher bc univ ∥B∥→B)) coherent↠higher-preserves-getters-and-setters b _ ∥B∥→B = coherent⇔higher-preserves-getters-and-setters b ∥B∥→B ------------------------------------------------------------------------ -- Composition -- A lemma used to define composition. ∘⁻¹≃ : Block "∘⁻¹≃" → (f : B → C) (g : A → B) → f ⊚ g ⁻¹ z ≃ ∃ λ ((y , _) : f ⁻¹ z) → g ⁻¹ y ∘⁻¹≃ {z = z} ⊠ f g = f ⊚ g ⁻¹ z ↔⟨⟩ (∃ λ a → f (g a) ≡ z) ↔⟨ (∃-cong λ _ → ∃-intro _ _) ⟩ (∃ λ a → ∃ λ y → f y ≡ z × y ≡ g a) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩ (∃ λ a → ∃ λ ((y , _) : f ⁻¹ z) → y ≡ g a) ↔⟨ ∃-comm ⟩ (∃ λ ((y , _) : f ⁻¹ z) → ∃ λ a → y ≡ g a) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ≡-comm) ⟩ (∃ λ ((y , _) : f ⁻¹ z) → g ⁻¹ y) □ -- Composition. infixr 9 _∘_ _∘_ : Lens B C → Lens A B → Lens A C l₁@(lens _ _ _ _) ∘ l₂@(lens _ _ _ _) = block λ b → _≃_.from Lens-as-Σ′ ( get l₁ ⊚ get l₂ , (λ c₁ c₂ → get l₁ ⊚ get l₂ ⁻¹ c₁ ↝⟨ ∘⁻¹≃ b _ _ ⟩ (∃ λ ((b , _) : get l₁ ⁻¹ c₁) → get l₂ ⁻¹ b) ↝⟨ (Σ-cong (get⁻¹-constant l₁ c₁ c₂) λ p@(b , _) → get⁻¹-constant l₂ b (proj₁ (get⁻¹-const l₁ c₁ c₂ p))) ⟩ (∃ λ ((b , _) : get l₁ ⁻¹ c₂) → get l₂ ⁻¹ b) ↝⟨ inverse $ ∘⁻¹≃ b _ _ ⟩□ get l₁ ⊚ get l₂ ⁻¹ c₂ □) , (λ c₁ c₂ c₃ p → _≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₂ c₃) (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₂ c₃ p))) (_≃_.to (∘⁻¹≃ b _ _) (_≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₁ c₂) (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₁ c₂ p))) (_≃_.to (∘⁻¹≃ b _ _) p))))) ≡⟨ cong (λ x → _≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₂ c₃) (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₂ c₃ p))) x)) $ _≃_.right-inverse-of (∘⁻¹≃ b _ _) _ ⟩ _≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₂ c₃) (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₂ c₃ p))) (Σ-map (get⁻¹-const l₁ c₁ c₂) (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₁ c₂ p))) (_≃_.to (∘⁻¹≃ b _ _) p))) ≡⟨⟩ _≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₂ c₃ ⊚ get⁻¹-const l₁ c₁ c₂) (λ {p@(b , _)} → get⁻¹-const l₂ (proj₁ (get⁻¹-const l₁ c₁ c₂ p)) (proj₁ (get⁻¹-const l₁ c₂ c₃ (get⁻¹-const l₁ c₁ c₂ p))) ⊚ get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₁ c₂ p))) (_≃_.to (∘⁻¹≃ b _ _) p)) ≡⟨ cong (λ f → _≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₂ c₃ ⊚ get⁻¹-const l₁ c₁ c₂) (λ {p} → f {p}) (_≃_.to (∘⁻¹≃ b _ _) p))) $ (implicit-extensionality ext λ p → ⟨ext⟩ (get⁻¹-const-∘ l₂ _ (proj₁ (get⁻¹-const l₁ c₁ c₂ p)) _)) ⟩ _≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₂ c₃ ⊚ get⁻¹-const l₁ c₁ c₂) (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₂ c₃ (get⁻¹-const l₁ c₁ c₂ p)))) (_≃_.to (∘⁻¹≃ b _ _) p)) ≡⟨ cong (λ f → _≃_.from (∘⁻¹≃ b _ _) (Σ-map f (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (f p))) (_≃_.to (∘⁻¹≃ b _ _) p))) $ ⟨ext⟩ (get⁻¹-const-∘ l₁ _ _ _) ⟩∎ _≃_.from (∘⁻¹≃ b _ _) (Σ-map (get⁻¹-const l₁ c₁ c₃) (λ {p@(b , _)} → get⁻¹-const l₂ b (proj₁ (get⁻¹-const l₁ c₁ c₃ p))) (_≃_.to (∘⁻¹≃ b _ _) p)) ∎) ) where open Lens -- The setter of the resulting lens is defined in the "right" way. set-∘≡ : (l₁ : Lens B C) (l₂ : Lens A B) → Lens.set (l₁ ∘ l₂) a c ≡ Lens.set l₂ a (Lens.set l₁ (Lens.get l₂ a) c) set-∘≡ {a = a} {c = c} l₁@(lens _ _ _ _) l₂@(lens _ _ _ _) = proj₁ (get⁻¹-const l₂ (get l₂ a) (proj₁ (get⁻¹-const l₁ c′ c ( get l₂ a , _↔_.to (subst (λ b → get l₁ b ≡ c′ ↔ c′ ≡ c′) (refl _) F.id) (refl _)) )) (a , sym (refl _))) ≡⟨ cong₂ (λ f eq → proj₁ (get⁻¹-const l₂ _ (proj₁ (get⁻¹-const l₁ _ _ (_ , _↔_.to f (refl _)))) (_ , eq))) (subst-refl _ _) sym-refl ⟩ proj₁ (get⁻¹-const l₂ (get l₂ a) (proj₁ (get⁻¹-const l₁ c′ c (get l₂ a , refl _))) (a , refl _)) ≡⟨⟩ set l₂ a (set l₁ (get l₂ a) c) ∎ where open Lens c′ = get l₁ (get l₂ a) -- Composition for higher lenses, defined under the assumption that -- the resulting codomain is inhabited if it is merely inhabited. infix 9 ⟨_⟩_⊚_ ⟨_⟩_⊚_ : (∥ C ∥ → C) → Higher.Lens B C → Higher.Lens A B → Higher.Lens A C ⟨_⟩_⊚_ {C = C} {B = B} {A = A} ∥C∥→C = curry ( Higher.Lens B C × Higher.Lens A B ↝⟨ Σ-map higher→ higher→ ⟩ Lens B C × Lens A B ↝⟨ uncurry _∘_ ⟩ Lens A C ↝⟨ →higher ∥C∥→C ⟩□ Higher.Lens A C □) -- The setter of the resulting lens is defined in the "right" way. set-⊚≡ : ∀ ∥C∥→C (l₁ : Higher.Lens B C) (l₂ : Higher.Lens A B) → Higher.Lens.set (⟨ ∥C∥→C ⟩ l₁ ⊚ l₂) a c ≡ Higher.Lens.set l₂ a (Higher.Lens.set l₁ (Higher.Lens.get l₂ a) c) set-⊚≡ {a = a} {c = c} ∥C∥→C l₁ l₂ = set (⟨ ∥C∥→C ⟩ l₁ ⊚ l₂) a c ≡⟨ cong (λ f → f a c) $ proj₂ $ →higher-preserves-getters-and-setters ∥C∥→C (higher→ l₁ ∘ higher→ l₂) ⟩ Lens.set (higher→ l₁ ∘ higher→ l₂) a c ≡⟨ set-∘≡ (higher→ l₁) (higher→ l₂) ⟩ Lens.set (higher→ l₂) a (Lens.set (higher→ l₁) (Lens.get (higher→ l₂) a) c) ≡⟨ cong (λ f → Lens.set (higher→ l₂) a (Lens.set (higher→ l₁) (f a) c)) $ proj₁ $ higher→-preserves-getters-and-setters l₂ ⟩ Lens.set (higher→ l₂) a (Lens.set (higher→ l₁) (get l₂ a) c) ≡⟨ cong (λ f → Lens.set (higher→ l₂) a (f (get l₂ a) c)) $ proj₂ $ higher→-preserves-getters-and-setters l₁ ⟩ Lens.set (higher→ l₂) a (set l₁ (get l₂ a) c) ≡⟨ cong (λ f → f a (set l₁ (get l₂ a) c)) $ proj₂ $ higher→-preserves-getters-and-setters l₂ ⟩∎ set l₂ a (set l₁ (get l₂ a) c) ∎ where open Higher.Lens -- The implementation of composition for higher lenses given above -- matches the one in Higher when both are defined (assuming -- univalence). ⊚≡∘ : ∀ a b {A : Set (a ⊔ b ⊔ c)} {B : Set (b ⊔ c)} {C : Set c} → Univalence (a ⊔ b ⊔ c) → (∥C∥→C : ∥ C ∥ → C) → ⟨_⟩_⊚_ {B = B} {A = A} ∥C∥→C ≡ Higher.Lens-combinators.⟨ a , b ⟩_∘_ ⊚≡∘ a b {A = A} {B = B} {C = C} univ ∥C∥→C = Higher.Lens-combinators.composition≡∘ a b univ ∥C∥→C ⟨ ∥C∥→C ⟩_⊚_ (λ l₁ l₂ _ _ → set-⊚≡ ∥C∥→C l₁ l₂)
45.09991
153
0.399453
7c817ac0a9621140c14733fcc97efb7067347b38
2,105
agda
Agda
src/CF/Syntax.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
6
2020-10-07T14:07:17.000Z
2021-02-28T21:49:08.000Z
src/CF/Syntax.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
null
null
null
src/CF/Syntax.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
1
2021-12-28T17:37:15.000Z
2021-12-28T17:37:15.000Z
{-# OPTIONS --safe --no-qualified-instances #-} module CF.Syntax where open import Level open import Data.Integer open import Data.Bool open import Data.String open import Data.Product open import Data.List hiding (null) open import Data.List.Relation.Unary.All open import Relation.Unary hiding (_⊢_) open import Relation.Unary.PredicateTransformer using (Pt) open import Relation.Binary.Structures using (IsPreorder) open import Relation.Binary.PropositionalEquality using (isEquivalence; refl) open import Relation.Ternary.Core open import Relation.Ternary.Structures open import Relation.Ternary.Structures.Syntax open import Relation.Ternary.Monad.Possibly open import Relation.Ternary.Monad.Weakening open import Relation.Ternary.Data.Bigstar hiding ([_]) open import CF.Types open import CF.Contexts.Lexical open import Relation.Ternary.Construct.Product using (fst; snd) open import Relation.Ternary.Data.Allstar Ty data BinOp : Ty → Ty → Ty → Set where add sub mul div xor : BinOp int int int eq ne lt ge gt le : BinOp int int bool data Exp : Ty → Pred Ctx 0ℓ where unit : ε[ Exp void ] num : ℤ → ε[ Exp int ] bool : Bool → ε[ Exp bool ] ifthenelse : ∀[ Exp bool ✴ Exp a ✴ Exp a ⇒ Exp a ] var' : ∀[ Var a ⇒ Exp a ] bop : BinOp a b c → ∀[ Exp a ✴ Exp b ⇒ Exp c ] pattern var = var' vars module Statements (Block : Ty → Pred Ctx 0ℓ) where data Statement (r : Ty) : Pred Ctx 0ℓ where asgn : ∀[ Var a ✴ Exp a ⇒ Statement r ] run : ∀[ Exp a ⇒ Statement r ] ifthenelse : ∀[ Exp bool ✴ Statement r ✴ Statement r ⇒ Statement r ] while : ∀[ Exp bool ✴ Statement r ⇒ Statement r ] block : ∀[ Block r ⇒ Statement r ] mutual Stmt = Statements.Statement Block data Block (r : Ty) : Pred Ctx 0ℓ where local : ∀[ Exp a ✴ [ a ] ⊢ (Block r) ⇒ Block r ] cons : ∀[ Stmt r ✴ Block r ⇒ Block r ] emp : ε[ Block r ] -- make constructors visible open Statements Block public infixr 5 _⍮⟨_⟩_ pattern _⍮⟨_⟩_ s σ b = cons (s ∙⟨ σ ⟩ b) pattern _≔⟨_⟩_ e σ b = local (e ∙⟨ σ ⟩ b)
30.955882
77
0.666033
cc259e1ec04ec812ed220901ef3b1ed470562b7e
1,038
agda
Agda
test/Compiler/simple/Issue2664.agda
xekoukou/agda-ocaml
026a8f8473ab91f99c3f6545728e71fa847d2720
[ "BSD-3-Clause" ]
7
2018-11-05T22:13:36.000Z
2018-11-06T16:38:43.000Z
test/Compiler/simple/Issue2664.agda
xekoukou/agda-ocaml
026a8f8473ab91f99c3f6545728e71fa847d2720
[ "BSD-3-Clause" ]
16
2018-10-08T00:32:04.000Z
2019-09-08T13:47:04.000Z
test/Compiler/simple/Issue2664.agda
xekoukou/agda-ocaml
026a8f8473ab91f99c3f6545728e71fa847d2720
[ "BSD-3-Clause" ]
null
null
null
-- Andreas, 2017-08-10, issue #2664, reported by csetzer -- Test case by Ulf -- {-# OPTIONS -v tc.rec:40 #-} -- {-# OPTIONS -v tc.cc:60 #-} open import Agda.Builtin.IO open import Agda.Builtin.String open import Agda.Builtin.Unit open import Agda.Builtin.Nat mutual -- Error WAS: -- The presence of mutual affected the compilation of the projections -- since it triggered a record pattern translation for them. record R : Set where constructor mkR field dummy : Nat str : String helloWorld : R helloWorld = mkR 0 "Hello World!" postulate putStrLn : String → IO ⊤ {-# FOREIGN GHC import qualified Data.Text.IO as Text #-} {-# COMPILE GHC putStrLn = Text.putStrLn #-} {-# COMPILE JS putStrLn = function(x) { return function(cb) { process.stdout.write(x + "\n"); cb(0); }; } #-} {-# FOREIGN OCaml let printEndline y world = Lwt.return (print_endline y) #-} {-# COMPILE OCaml putStrLn = printEndline #-} main : IO ⊤ main = putStrLn (R.str helloWorld) -- Expected: Should print -- -- Hello World!
23.590909
110
0.671484
118ff4a08fafb28df5a8d47599e63ccbddb2a9a8
622
agda
Agda
test/Fail/Errors/SchematicPropositionalFunctionsWithoutPredicateSymbols.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
10
2015-09-03T20:54:16.000Z
2019-12-03T13:44:25.000Z
test/Fail/Errors/SchematicPropositionalFunctionsWithoutPredicateSymbols.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
121
2015-01-25T13:22:12.000Z
2018-04-22T06:01:44.000Z
test/Fail/Errors/SchematicPropositionalFunctionsWithoutPredicateSymbols.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
4
2016-05-10T23:06:19.000Z
2016-08-03T03:54:55.000Z
------------------------------------------------------------------------------ -- Incompatible options ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- The @--schematic-propositional-functions@ and -- @--without-predicate-symbols@ options are incompatible. module SchematicPropositionalFunctionsWithoutPredicateSymbols where postulate D : Set postulate id : {P : D → Set}{x : D} → P x → P x {-# ATP prove id #-}
32.736842
78
0.467846
edd5ab6c809c3272e1a584b03babf0f418963adb
251
agda
Agda
test/Fail/Issue437.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue437.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue437.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
record Unit : Set where data Bool : Set where true false : Bool F : Bool -> Set F true = Bool F false = Unit f : (b : Bool) -> F b f true = true f false = record {} -- this should give an error, but only gives yellow test : Bool test = f _ false
16.733333
51
0.641434
5907ce6045e0e9a33bbe7fb10d6cd40000f13957
21,685
agda
Agda
Cubical/Data/FinSet/Cardinality.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Data/FinSet/Cardinality.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Data/FinSet/Cardinality.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- Properties and Formulae about Cardinality This file contains: - Relation between abstract properties and cardinality in special cases; - Combinatorial formulae, namely, cardinality of A+B, A×B, ΣAB, ΠAB, etc; - A general form of Pigeonhole Principle; - Maximal value of numerical function on finite sets; - Set truncation of FinSet is equivalent to ℕ; - FinProp is equivalent to Bool. -} {-# OPTIONS --safe #-} module Cubical.Data.FinSet.Cardinality where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_) open import Cubical.Foundations.Equiv.Properties open import Cubical.Foundations.Transport open import Cubical.HITs.PropositionalTruncation as Prop open import Cubical.HITs.SetTruncation as Set open import Cubical.Data.Nat open import Cubical.Data.Nat.Order open import Cubical.Data.Unit open import Cubical.Data.Empty as Empty open import Cubical.Data.Bool hiding (_≟_; _≤_; _≥_; isProp≤) open import Cubical.Data.Sum open import Cubical.Data.Sigma open import Cubical.Data.Fin using (Fin-inj) open import Cubical.Data.Fin.LehmerCode as LehmerCode open import Cubical.Data.SumFin open import Cubical.Data.FinSet.Base open import Cubical.Data.FinSet.Properties open import Cubical.Data.FinSet.FiniteChoice open import Cubical.Data.FinSet.Constructors open import Cubical.Data.FinSet.Induction hiding (_+_) open import Cubical.Relation.Nullary open import Cubical.Functions.Fibration open import Cubical.Functions.Embedding open import Cubical.Functions.Surjection private variable ℓ ℓ' ℓ'' : Level n : ℕ X : FinSet ℓ Y : FinSet ℓ' -- cardinality of finite sets ∣≃card∣ : (X : FinSet ℓ) → ∥ X .fst ≃ Fin (card X) ∥₁ ∣≃card∣ X = X .snd .snd -- cardinality is invariant under equivalences cardEquiv : (X : FinSet ℓ)(Y : FinSet ℓ') → ∥ X .fst ≃ Y .fst ∥₁ → card X ≡ card Y cardEquiv X Y e = Prop.rec (isSetℕ _ _) (λ p → Fin-inj _ _ (ua p)) (∣ invEquiv (SumFin≃Fin _) ∣₁ ⋆̂ ∣invEquiv∣ (∣≃card∣ X) ⋆̂ e ⋆̂ ∣≃card∣ Y ⋆̂ ∣ SumFin≃Fin _ ∣₁) cardInj : card X ≡ card Y → ∥ X .fst ≃ Y .fst ∥₁ cardInj {X = X} {Y = Y} p = ∣≃card∣ X ⋆̂ ∣ pathToEquiv (cong Fin p) ∣₁ ⋆̂ ∣invEquiv∣ (∣≃card∣ Y) cardReflection : card X ≡ n → ∥ X .fst ≃ Fin n ∥₁ cardReflection {X = X} = cardInj {X = X} {Y = _ , isFinSetFin} card≡MereEquiv : (card X ≡ card Y) ≡ ∥ X .fst ≃ Y .fst ∥₁ card≡MereEquiv {X = X} {Y = Y} = hPropExt (isSetℕ _ _) isPropPropTrunc (cardInj {X = X} {Y = Y}) (cardEquiv X Y) -- special properties about specific cardinality module _ {X : FinSet ℓ} where card≡0→isEmpty : card X ≡ 0 → ¬ X .fst card≡0→isEmpty p x = Prop.rec isProp⊥ (λ e → subst Fin p (e .fst x)) (∣≃card∣ X) card>0→isInhab : card X > 0 → ∥ X .fst ∥₁ card>0→isInhab p = Prop.map (λ e → invEq e (Fin>0→isInhab _ p)) (∣≃card∣ X) card>1→hasNonEqualTerm : card X > 1 → ∥ Σ[ a ∈ X .fst ] Σ[ b ∈ X .fst ] ¬ a ≡ b ∥₁ card>1→hasNonEqualTerm p = Prop.map (λ e → e .fst (Fin>1→hasNonEqualTerm _ p .fst) , e .fst (Fin>1→hasNonEqualTerm _ p .snd .fst) , Fin>1→hasNonEqualTerm _ p .snd .snd ∘ invEq (congEquiv e)) (∣invEquiv∣ (∣≃card∣ X)) card≡1→isContr : card X ≡ 1 → isContr (X .fst) card≡1→isContr p = Prop.rec isPropIsContr (λ e → isOfHLevelRespectEquiv 0 (invEquiv (e ⋆ substEquiv Fin p)) isContrSumFin1) (∣≃card∣ X) card≤1→isProp : card X ≤ 1 → isProp (X .fst) card≤1→isProp p = Prop.rec isPropIsProp (λ e → isOfHLevelRespectEquiv 1 (invEquiv e) (Fin≤1→isProp (card X) p)) (∣≃card∣ X) card≡n : card X ≡ n → ∥ X ≡ 𝔽in n ∥₁ card≡n {n = n} p = Prop.map (λ e → (λ i → ua e i , isProp→PathP {B = λ j → isFinSet (ua e j)} (λ _ → isPropIsFinSet) (X .snd) (𝔽in n .snd) i )) (∣≃card∣ X ⋆̂ ∣ pathToEquiv (cong Fin p) ⋆ invEquiv (𝔽in≃Fin n) ∣₁) card≡0 : card X ≡ 0 → X ≡ 𝟘 card≡0 p = propTruncIdempotent≃ (isOfHLevelRespectEquiv 1 (FinSet≡ X 𝟘) (isOfHLevel≡ 1 (card≤1→isProp (subst (λ a → a ≤ 1) (sym p) (≤-solver 0 1))) (isProp⊥*))) .fst (card≡n p) card≡1 : card X ≡ 1 → X ≡ 𝟙 card≡1 p = propTruncIdempotent≃ (isOfHLevelRespectEquiv 1 (FinSet≡ X 𝟙) (isOfHLevel≡ 1 (card≤1→isProp (subst (λ a → a ≤ 1) (sym p) (≤-solver 1 1))) (isPropUnit*))) .fst (Prop.map (λ q → q ∙ 𝔽in1≡𝟙) (card≡n p)) module _ (X : FinSet ℓ) where isEmpty→card≡0 : ¬ X .fst → card X ≡ 0 isEmpty→card≡0 p = Prop.rec (isSetℕ _ _) (λ e → sym (isEmpty→Fin≡0 _ (p ∘ invEq e))) (∣≃card∣ X) isInhab→card>0 : ∥ X .fst ∥₁ → card X > 0 isInhab→card>0 = Prop.rec2 isProp≤ (λ p x → isInhab→Fin>0 _ (p .fst x)) (∣≃card∣ X) hasNonEqualTerm→card>1 : {a b : X. fst} → ¬ a ≡ b → card X > 1 hasNonEqualTerm→card>1 {a = a} {b = b} q = Prop.rec isProp≤ (λ p → hasNonEqualTerm→Fin>1 _ (p .fst a) (p .fst b) (q ∘ invEq (congEquiv p))) (∣≃card∣ X) isContr→card≡1 : isContr (X .fst) → card X ≡ 1 isContr→card≡1 p = cardEquiv X (_ , isFinSetUnit) ∣ isContr→≃Unit p ∣₁ isProp→card≤1 : isProp (X .fst) → card X ≤ 1 isProp→card≤1 p = isProp→Fin≤1 (card X) (Prop.rec isPropIsProp (λ e → isOfHLevelRespectEquiv 1 e p) (∣≃card∣ X)) {- formulae about cardinality -} -- results to be used in direct induction on FinSet card𝟘 : card (𝟘 {ℓ}) ≡ 0 card𝟘 {ℓ = ℓ} = isEmpty→card≡0 (𝟘 {ℓ}) (Empty.rec*) card𝟙 : card (𝟙 {ℓ}) ≡ 1 card𝟙 {ℓ = ℓ} = isContr→card≡1 (𝟙 {ℓ}) isContrUnit* card𝔽in : (n : ℕ) → card (𝔽in {ℓ} n) ≡ n card𝔽in {ℓ = ℓ} n = cardEquiv (𝔽in {ℓ} n) (_ , isFinSetFin) ∣ 𝔽in≃Fin n ∣₁ -- addition/product formula module _ (X : FinSet ℓ ) (Y : FinSet ℓ') where card+ : card (_ , isFinSet⊎ X Y) ≡ card X + card Y card+ = refl card× : card (_ , isFinSet× X Y) ≡ card X · card Y card× = refl -- total summation/product of numerical functions from finite sets module _ (X : FinSet ℓ) (f : X .fst → ℕ) where sum : ℕ sum = card (_ , isFinSetΣ X (λ x → Fin (f x) , isFinSetFin)) prod : ℕ prod = card (_ , isFinSetΠ X (λ x → Fin (f x) , isFinSetFin)) module _ (f : 𝟘 {ℓ} .fst → ℕ) where sum𝟘 : sum 𝟘 f ≡ 0 sum𝟘 = isEmpty→card≡0 (_ , isFinSetΣ 𝟘 (λ x → Fin (f x) , isFinSetFin)) ((invEquiv (Σ-cong-equiv-fst (invEquiv 𝟘≃Empty)) ⋆ ΣEmpty _) .fst) prod𝟘 : prod 𝟘 f ≡ 1 prod𝟘 = isContr→card≡1 (_ , isFinSetΠ 𝟘 (λ x → Fin (f x) , isFinSetFin)) (isContrΠ⊥*) module _ (f : 𝟙 {ℓ} .fst → ℕ) where sum𝟙 : sum 𝟙 f ≡ f tt* sum𝟙 = cardEquiv (_ , isFinSetΣ 𝟙 (λ x → Fin (f x) , isFinSetFin)) (Fin (f tt*) , isFinSetFin) ∣ Σ-contractFst isContrUnit* ∣₁ prod𝟙 : prod 𝟙 f ≡ f tt* prod𝟙 = cardEquiv (_ , isFinSetΠ 𝟙 (λ x → Fin (f x) , isFinSetFin)) (Fin (f tt*) , isFinSetFin) ∣ ΠUnit* _ ∣₁ module _ (X : FinSet ℓ ) (Y : FinSet ℓ') (f : X .fst ⊎ Y .fst → ℕ) where sum⊎ : sum (_ , isFinSet⊎ X Y) f ≡ sum X (f ∘ inl) + sum Y (f ∘ inr) sum⊎ = cardEquiv (_ , isFinSetΣ (_ , isFinSet⊎ X Y) (λ x → Fin (f x) , isFinSetFin)) (_ , isFinSet⊎ (_ , isFinSetΣ X (λ x → Fin (f (inl x)) , isFinSetFin)) (_ , isFinSetΣ Y (λ y → Fin (f (inr y)) , isFinSetFin))) ∣ Σ⊎≃ ∣₁ ∙ card+ (_ , isFinSetΣ X (λ x → Fin (f (inl x)) , isFinSetFin)) (_ , isFinSetΣ Y (λ y → Fin (f (inr y)) , isFinSetFin)) prod⊎ : prod (_ , isFinSet⊎ X Y) f ≡ prod X (f ∘ inl) · prod Y (f ∘ inr) prod⊎ = cardEquiv (_ , isFinSetΠ (_ , isFinSet⊎ X Y) (λ x → Fin (f x) , isFinSetFin)) (_ , isFinSet× (_ , isFinSetΠ X (λ x → Fin (f (inl x)) , isFinSetFin)) (_ , isFinSetΠ Y (λ y → Fin (f (inr y)) , isFinSetFin))) ∣ Π⊎≃ ∣₁ ∙ card× (_ , isFinSetΠ X (λ x → Fin (f (inl x)) , isFinSetFin)) (_ , isFinSetΠ Y (λ y → Fin (f (inr y)) , isFinSetFin)) -- technical lemma module _ (n : ℕ)(f : 𝔽in {ℓ} (1 + n) .fst → ℕ) where sum𝔽in1+n : sum (𝔽in (1 + n)) f ≡ f (inl tt*) + sum (𝔽in n) (f ∘ inr) sum𝔽in1+n = sum⊎ 𝟙 (𝔽in n) f ∙ (λ i → sum𝟙 (f ∘ inl) i + sum (𝔽in n) (f ∘ inr)) prod𝔽in1+n : prod (𝔽in (1 + n)) f ≡ f (inl tt*) · prod (𝔽in n) (f ∘ inr) prod𝔽in1+n = prod⊎ 𝟙 (𝔽in n) f ∙ (λ i → prod𝟙 (f ∘ inl) i · prod (𝔽in n) (f ∘ inr)) sumConst𝔽in : (n : ℕ)(f : 𝔽in {ℓ} n .fst → ℕ)(c : ℕ)(h : (x : 𝔽in n .fst) → f x ≡ c) → sum (𝔽in n) f ≡ c · n sumConst𝔽in 0 f c _ = sum𝟘 f ∙ 0≡m·0 c sumConst𝔽in (suc n) f c h = sum𝔽in1+n n f ∙ (λ i → h (inl tt*) i + sumConst𝔽in n (f ∘ inr) c (h ∘ inr) i) ∙ sym (·-suc c n) prodConst𝔽in : (n : ℕ)(f : 𝔽in {ℓ} n .fst → ℕ)(c : ℕ)(h : (x : 𝔽in n .fst) → f x ≡ c) → prod (𝔽in n) f ≡ c ^ n prodConst𝔽in 0 f c _ = prod𝟘 f prodConst𝔽in (suc n) f c h = prod𝔽in1+n n f ∙ (λ i → h (inl tt*) i · prodConst𝔽in n (f ∘ inr) c (h ∘ inr) i) module _ (X : FinSet ℓ) (f : X .fst → ℕ) (c : ℕ)(h : (x : X .fst) → f x ≡ c) where sumConst : sum X f ≡ c · card X sumConst = elimProp (λ X → (f : X .fst → ℕ)(c : ℕ)(h : (x : X .fst) → f x ≡ c) → sum X f ≡ c · (card X)) (λ X → isPropΠ3 (λ _ _ _ → isSetℕ _ _)) (λ n f c h → sumConst𝔽in n f c h ∙ (λ i → c · card𝔽in {ℓ = ℓ} n (~ i))) X f c h prodConst : prod X f ≡ c ^ card X prodConst = elimProp (λ X → (f : X .fst → ℕ)(c : ℕ)(h : (x : X .fst) → f x ≡ c) → prod X f ≡ c ^ (card X)) (λ X → isPropΠ3 (λ _ _ _ → isSetℕ _ _)) (λ n f c h → prodConst𝔽in n f c h ∙ (λ i → c ^ card𝔽in {ℓ = ℓ} n (~ i))) X f c h private ≡≤ : {m n l k r s : ℕ} → m ≤ n → l ≤ k → r ≡ m + l → s ≡ n + k → r ≤ s ≡≤ {m = m} {l = l} {k = k} p q u v = subst2 (_≤_) (sym u) (sym v) (≤-+-≤ p q) ≡< : {m n l k r s : ℕ} → m < n → l ≤ k → r ≡ m + l → s ≡ n + k → r < s ≡< {m = m} {l = l} {k = k} p q u v = subst2 (_<_) (sym u) (sym v) (<-+-≤ p q) sum≤𝔽in : (n : ℕ)(f g : 𝔽in {ℓ} n .fst → ℕ)(h : (x : 𝔽in n .fst) → f x ≤ g x) → sum (𝔽in n) f ≤ sum (𝔽in n) g sum≤𝔽in 0 f g _ = subst2 (_≤_) (sym (sum𝟘 f)) (sym (sum𝟘 g)) ≤-refl sum≤𝔽in (suc n) f g h = ≡≤ (h (inl tt*)) (sum≤𝔽in n (f ∘ inr) (g ∘ inr) (h ∘ inr)) (sum𝔽in1+n n f) (sum𝔽in1+n n g) sum<𝔽in : (n : ℕ)(f g : 𝔽in {ℓ} n .fst → ℕ)(t : ∥ 𝔽in {ℓ} n .fst ∥₁)(h : (x : 𝔽in n .fst) → f x < g x) → sum (𝔽in n) f < sum (𝔽in n) g sum<𝔽in {ℓ = ℓ} 0 _ _ t _ = Empty.rec (<→≢ (isInhab→card>0 (𝔽in 0) t) (card𝟘 {ℓ = ℓ})) sum<𝔽in (suc n) f g t h = ≡< (h (inl tt*)) (sum≤𝔽in n (f ∘ inr) (g ∘ inr) (<-weaken ∘ h ∘ inr)) (sum𝔽in1+n n f) (sum𝔽in1+n n g) module _ (X : FinSet ℓ) (f g : X .fst → ℕ) where module _ (h : (x : X .fst) → f x ≡ g x) where sum≡ : sum X f ≡ sum X g sum≡ i = sum X (λ x → h x i) prod≡ : prod X f ≡ prod X g prod≡ i = prod X (λ x → h x i) module _ (h : (x : X .fst) → f x ≤ g x) where sum≤ : sum X f ≤ sum X g sum≤ = elimProp (λ X → (f g : X .fst → ℕ)(h : (x : X .fst) → f x ≤ g x) → sum X f ≤ sum X g) (λ X → isPropΠ3 (λ _ _ _ → isProp≤)) sum≤𝔽in X f g h module _ (t : ∥ X .fst ∥₁) (h : (x : X .fst) → f x < g x) where sum< : sum X f < sum X g sum< = elimProp (λ X → (f g : X .fst → ℕ)(t : ∥ X .fst ∥₁)(h : (x : X .fst) → f x < g x) → sum X f < sum X g) (λ X → isPropΠ4 (λ _ _ _ _ → isProp≤)) sum<𝔽in X f g t h module _ (X : FinSet ℓ) (f : X .fst → ℕ) where module _ (c : ℕ)(h : (x : X .fst) → f x ≤ c) where sumBounded : sum X f ≤ c · card X sumBounded = subst (λ a → sum X f ≤ a) (sumConst X (λ _ → c) c (λ _ → refl)) (sum≤ X f (λ _ → c) h) module _ (c : ℕ)(h : (x : X .fst) → f x ≥ c) where sumBoundedBelow : sum X f ≥ c · card X sumBoundedBelow = subst (λ a → sum X f ≥ a) (sumConst X (λ _ → c) c (λ _ → refl)) (sum≤ X (λ _ → c) f h) -- some combinatorial identities module _ (X : FinSet ℓ ) (Y : X .fst → FinSet ℓ') where cardΣ : card (_ , isFinSetΣ X Y) ≡ sum X (λ x → card (Y x)) cardΣ = cardEquiv (_ , isFinSetΣ X Y) (_ , isFinSetΣ X (λ x → Fin (card (Y x)) , isFinSetFin)) (Prop.map Σ-cong-equiv-snd (choice X (λ x → Y x .fst ≃ Fin (card (Y x))) (λ x → ∣≃card∣ (Y x)))) cardΠ : card (_ , isFinSetΠ X Y) ≡ prod X (λ x → card (Y x)) cardΠ = cardEquiv (_ , isFinSetΠ X Y) (_ , isFinSetΠ X (λ x → Fin (card (Y x)) , isFinSetFin)) (Prop.map equivΠCod (choice X (λ x → Y x .fst ≃ Fin (card (Y x))) (λ x → ∣≃card∣ (Y x)))) module _ (X : FinSet ℓ ) (Y : FinSet ℓ') where card→ : card (_ , isFinSet→ X Y) ≡ card Y ^ card X card→ = cardΠ X (λ _ → Y) ∙ prodConst X (λ _ → card Y) (card Y) (λ _ → refl) module _ (X : FinSet ℓ ) where cardAut : card (_ , isFinSetAut X) ≡ LehmerCode.factorial (card X) cardAut = refl module _ (X : FinSet ℓ ) (Y : FinSet ℓ') (f : X .fst → Y .fst) where sumCardFiber : card X ≡ sum Y (λ y → card (_ , isFinSetFiber X Y f y)) sumCardFiber = cardEquiv X (_ , isFinSetΣ Y (λ y → _ , isFinSetFiber X Y f y)) ∣ totalEquiv f ∣₁ ∙ cardΣ Y (λ y → _ , isFinSetFiber X Y f y) -- the pigeonhole priniple -- a logical lemma private ¬ΠQ→¬¬ΣP : (X : Type ℓ) (P : X → Type ℓ' ) (Q : X → Type ℓ'') (r : (x : X) → ¬ (P x) → Q x) → ¬ ((x : X) → Q x) → ¬ ¬ (Σ X P) ¬ΠQ→¬¬ΣP _ _ _ r g f = g (λ x → r x (λ p → f (x , p))) module _ (f : X .fst → Y .fst) (n : ℕ) where fiberCount : ((y : Y .fst) → card (_ , isFinSetFiber X Y f y) ≤ n) → card X ≤ n · card Y fiberCount h = subst (λ a → a ≤ _) (sym (sumCardFiber X Y f)) (sumBounded Y (λ y → card (_ , isFinSetFiber X Y f y)) n h) module _ (p : card X > n · card Y) where ¬¬pigeonHole : ¬ ¬ (Σ[ y ∈ Y .fst ] card (_ , isFinSetFiber X Y f y) > n) ¬¬pigeonHole = ¬ΠQ→¬¬ΣP (Y .fst) (λ y → _ > n) (λ y → _ ≤ n) (λ y → <-asym') (λ h → <-asym p (fiberCount h)) pigeonHole : ∥ Σ[ y ∈ Y .fst ] card (_ , isFinSetFiber X Y f y) > n ∥₁ pigeonHole = PeirceLaw (isFinSetΣ Y (λ _ → _ , isDecProp→isFinSet isProp≤ (≤Dec _ _))) ¬¬pigeonHole -- a special case, proved in Cubical.Data.Fin.Properties -- a technical lemma private Σ∥P∥→∥ΣP∥ : (X : Type ℓ)(P : X → Type ℓ') → Σ X (λ x → ∥ P x ∥₁) → ∥ Σ X P ∥₁ Σ∥P∥→∥ΣP∥ _ _ (x , p) = Prop.map (λ q → x , q) p module _ (f : X .fst → Y .fst) (p : card X > card Y) where fiberNonEqualTerm : Σ[ y ∈ Y .fst ] card (_ , isFinSetFiber X Y f y) > 1 → ∥ Σ[ y ∈ Y .fst ] Σ[ a ∈ fiber f y ] Σ[ b ∈ fiber f y ] ¬ a ≡ b ∥₁ fiberNonEqualTerm (y , p) = Σ∥P∥→∥ΣP∥ _ _ (y , card>1→hasNonEqualTerm {X = _ , isFinSetFiber X Y f y} p) nonInj : Σ[ y ∈ Y .fst ] Σ[ a ∈ fiber f y ] Σ[ b ∈ fiber f y ] ¬ a ≡ b → Σ[ x ∈ X .fst ] Σ[ x' ∈ X .fst ] (¬ x ≡ x') × (f x ≡ f x') nonInj (y , (x , p) , (x' , q) , t) .fst = x nonInj (y , (x , p) , (x' , q) , t) .snd .fst = x' nonInj (y , (x , p) , (x' , q) , t) .snd .snd .fst u = t (λ i → u i , isSet→SquareP (λ i j → isFinSet→isSet (Y .snd)) p q (cong f u) refl i) nonInj (y , (x , p) , (x' , q) , t) .snd .snd .snd = p ∙ sym q pigeonHole' : ∥ Σ[ x ∈ X .fst ] Σ[ x' ∈ X .fst ] (¬ x ≡ x') × (f x ≡ f x') ∥₁ pigeonHole' = Prop.map nonInj (Prop.rec isPropPropTrunc fiberNonEqualTerm (pigeonHole {X = X} {Y = Y} f 1 (subst (λ a → _ > a) (sym (·-identityˡ _)) p))) -- cardinality and injection/surjection module _ (X : FinSet ℓ ) (Y : FinSet ℓ') where module _ (f : X .fst → Y .fst) where card↪Inequality' : isEmbedding f → card X ≤ card Y card↪Inequality' p = subst2 (_≤_) (sym (sumCardFiber X Y f)) (·-identityˡ _) (sumBounded Y (λ y → card (_ , isFinSetFiber X Y f y)) 1 (λ y → isProp→card≤1 (_ , isFinSetFiber X Y f y) (isEmbedding→hasPropFibers p y))) card↠Inequality' : isSurjection f → card X ≥ card Y card↠Inequality' p = subst2 (_≥_) (sym (sumCardFiber X Y f)) (·-identityˡ _) (sumBoundedBelow Y (λ y → card (_ , isFinSetFiber X Y f y)) 1 (λ y → isInhab→card>0 (_ , isFinSetFiber X Y f y) (p y))) card↪Inequality : ∥ X .fst ↪ Y .fst ∥₁ → card X ≤ card Y card↪Inequality = Prop.rec isProp≤ (λ (f , p) → card↪Inequality' f p) card↠Inequality : ∥ X .fst ↠ Y .fst ∥₁ → card X ≥ card Y card↠Inequality = Prop.rec isProp≤ (λ (f , p) → card↠Inequality' f p) -- maximal value of numerical functions module _ (X : Type ℓ) (f : X → ℕ) where module _ (x : X) where isMax : Type ℓ isMax = (x' : X) → f x' ≤ f x isPropIsMax : isProp isMax isPropIsMax = isPropΠ (λ _ → isProp≤) uniqMax : (x x' : X) → isMax x → isMax x' → f x ≡ f x' uniqMax x x' p q = ≤-antisym (q x) (p x') ΣMax : Type ℓ ΣMax = Σ[ x ∈ X ] isMax x ∃Max : Type ℓ ∃Max = ∥ ΣMax ∥₁ ∃Max→maxValue : ∃Max → ℕ ∃Max→maxValue = SetElim.rec→Set isSetℕ (λ (x , p) → f x) (λ (x , p) (x' , q) → uniqMax x x' p q) -- lemma about maximal value on sum type module _ (X : Type ℓ ) (Y : Type ℓ') (f : X ⊎ Y → ℕ) where ΣMax⊎-case : ((x , p) : ΣMax X (f ∘ inl))((y , q) : ΣMax Y (f ∘ inr)) → Trichotomy (f (inl x)) (f (inr y)) → ΣMax (X ⊎ Y) f ΣMax⊎-case (x , p) (y , q) (lt r) .fst = inr y ΣMax⊎-case (x , p) (y , q) (lt r) .snd (inl x') = ≤-trans (p x') (<-weaken r) ΣMax⊎-case (x , p) (y , q) (lt r) .snd (inr y') = q y' ΣMax⊎-case (x , p) (y , q) (eq r) .fst = inr y ΣMax⊎-case (x , p) (y , q) (eq r) .snd (inl x') = ≤-trans (p x') (_ , r) ΣMax⊎-case (x , p) (y , q) (eq r) .snd (inr y') = q y' ΣMax⊎-case (x , p) (y , q) (gt r) .fst = inl x ΣMax⊎-case (x , p) (y , q) (gt r) .snd (inl x') = p x' ΣMax⊎-case (x , p) (y , q) (gt r) .snd (inr y') = ≤-trans (q y') (<-weaken r) ∃Max⊎ : ∃Max X (f ∘ inl) → ∃Max Y (f ∘ inr) → ∃Max (X ⊎ Y) f ∃Max⊎ = Prop.map2 (λ p q → ΣMax⊎-case p q (_≟_ _ _)) ΣMax𝟙 : (f : 𝟙 {ℓ} .fst → ℕ) → ΣMax _ f ΣMax𝟙 f .fst = tt* ΣMax𝟙 f .snd x = _ , cong f (sym (isContrUnit* .snd x)) ∃Max𝟙 : (f : 𝟙 {ℓ} .fst → ℕ) → ∃Max _ f ∃Max𝟙 f = ∣ ΣMax𝟙 f ∣₁ ∃Max𝔽in : (n : ℕ)(f : 𝔽in {ℓ} n .fst → ℕ)(x : ∥ 𝔽in {ℓ} n .fst ∥₁) → ∃Max _ f ∃Max𝔽in {ℓ = ℓ} 0 _ x = Empty.rec (<→≢ (isInhab→card>0 (𝔽in 0) x) (card𝟘 {ℓ = ℓ})) ∃Max𝔽in 1 f _ = subst (λ X → (f : X .fst → ℕ) → ∃Max _ f) (sym 𝔽in1≡𝟙) ∃Max𝟙 f ∃Max𝔽in (suc (suc n)) f _ = ∃Max⊎ (𝟙 .fst) (𝔽in (suc n) .fst) f (∃Max𝟙 (f ∘ inl)) (∃Max𝔽in (suc n) (f ∘ inr) ∣ * {n = n} ∣₁) module _ (X : FinSet ℓ) (f : X .fst → ℕ) (x : ∥ X .fst ∥₁) where ∃MaxFinSet : ∃Max _ f ∃MaxFinSet = elimProp (λ X → (f : X .fst → ℕ)(x : ∥ X .fst ∥₁) → ∃Max _ f) (λ X → isPropΠ2 (λ _ _ → isPropPropTrunc)) ∃Max𝔽in X f x maxValue : ℕ maxValue = ∃Max→maxValue _ _ ∃MaxFinSet {- some formal consequences of card -} -- card induces equivalence from set truncation of FinSet to natural numbers open Iso Iso-∥FinSet∥₂-ℕ : Iso ∥ FinSet ℓ ∥₂ ℕ Iso-∥FinSet∥₂-ℕ .fun = Set.rec isSetℕ card Iso-∥FinSet∥₂-ℕ .inv n = ∣ 𝔽in n ∣₂ Iso-∥FinSet∥₂-ℕ .rightInv n = card𝔽in n Iso-∥FinSet∥₂-ℕ {ℓ = ℓ} .leftInv = Set.elim {B = λ X → ∣ 𝔽in (Set.rec isSetℕ card X) ∣₂ ≡ X} (λ X → isSetPathImplicit) (elimProp (λ X → ∣ 𝔽in (card X) ∣₂ ≡ ∣ X ∣₂) (λ X → squash₂ _ _) (λ n i → ∣ 𝔽in (card𝔽in {ℓ = ℓ} n i) ∣₂)) -- this is the definition of natural numbers you learned from school ∥FinSet∥₂≃ℕ : ∥ FinSet ℓ ∥₂ ≃ ℕ ∥FinSet∥₂≃ℕ = isoToEquiv Iso-∥FinSet∥₂-ℕ -- FinProp is equivalent to Bool Bool→FinProp : Bool → FinProp ℓ Bool→FinProp true = 𝟙 , isPropUnit* Bool→FinProp false = 𝟘 , isProp⊥* injBool→FinProp : (x y : Bool) → Bool→FinProp {ℓ = ℓ} x ≡ Bool→FinProp y → x ≡ y injBool→FinProp true true _ = refl injBool→FinProp false false _ = refl injBool→FinProp true false p = Empty.rec (snotz (cong (card ∘ fst) p)) injBool→FinProp false true p = Empty.rec (znots (cong (card ∘ fst) p)) isEmbeddingBool→FinProp : isEmbedding (Bool→FinProp {ℓ = ℓ}) isEmbeddingBool→FinProp = injEmbedding isSetBool isSetFinProp (λ {x} {y} → injBool→FinProp x y) card-case : (P : FinProp ℓ) → {n : ℕ} → card (P .fst) ≡ n → Σ[ x ∈ Bool ] Bool→FinProp x ≡ P card-case P {n = 0} p = false , FinProp≡ (𝟘 , isProp⊥*) P .fst (cong fst (sym (card≡0 {X = P .fst} p))) card-case P {n = 1} p = true , FinProp≡ (𝟙 , isPropUnit*) P .fst (cong fst (sym (card≡1 {X = P .fst} p))) card-case P {n = suc (suc n)} p = Empty.rec (¬-<-zero (pred-≤-pred (subst (λ a → a ≤ 1) p (isProp→card≤1 (P .fst) (P .snd))))) isSurjectionBool→FinProp : isSurjection (Bool→FinProp {ℓ = ℓ}) isSurjectionBool→FinProp P = ∣ card-case P refl ∣₁ FinProp≃Bool : FinProp ℓ ≃ Bool FinProp≃Bool = invEquiv (Bool→FinProp , isEmbedding×isSurjection→isEquiv (isEmbeddingBool→FinProp , isSurjectionBool→FinProp)) isFinSetFinProp : isFinSet (FinProp ℓ) isFinSetFinProp = EquivPresIsFinSet (invEquiv FinProp≃Bool) isFinSetBool -- a more computationally efficient version of equivalence type module _ (X : FinSet ℓ ) (Y : FinSet ℓ') where isFinSet≃Eff' : Dec (card X ≡ card Y) → isFinSet (X .fst ≃ Y .fst) isFinSet≃Eff' (yes p) = factorial (card Y) , Prop.elim2 (λ _ _ → isPropPropTrunc {A = _ ≃ Fin _}) (λ p1 p2 → ∣ equivComp (p1 ⋆ pathToEquiv (cong Fin p) ⋆ SumFin≃Fin _) (p2 ⋆ SumFin≃Fin _) ⋆ lehmerEquiv ⋆ lehmerFinEquiv ⋆ invEquiv (SumFin≃Fin _) ∣₁) (∣≃card∣ X) (∣≃card∣ Y) isFinSet≃Eff' (no ¬p) = 0 , ∣ uninhabEquiv (¬p ∘ cardEquiv X Y ∘ ∣_∣₁) (idfun _) ∣₁ isFinSet≃Eff : isFinSet (X .fst ≃ Y .fst) isFinSet≃Eff = isFinSet≃Eff' (discreteℕ _ _) module _ (X Y : FinSet ℓ) where isFinSetType≡Eff : isFinSet (X .fst ≡ Y .fst) isFinSetType≡Eff = EquivPresIsFinSet (invEquiv univalence) (isFinSet≃Eff X Y)
33.724728
114
0.548121
7395e22258120a917a1cb80eac08507cc561ee66
2,128
agda
Agda
test/Succeed/Issue1470.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1470.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1470.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-03-26 -- Andrea discovered that unfold for Lists is typable with sized types -- (and termination checks). -- Dually, fold for Streams should work. Therefore, the restriction -- of coinductive records to recursive records should be lifted. {-# OPTIONS --copatterns --sized-types #-} open import Common.Size -- StreamF A X i = ∀j<i. A × X j record StreamF (A : Set) (X : Size → Set) (i : Size) : Set where coinductive field head : A tail : ∀{j : Size< i} → X j module F = StreamF record Stream (A : Set) (i : Size) : Set where coinductive field head : A tail : ∀{j : Size< i} → Stream A j module S = Stream module Inlined {A T} (f : ∀ i → StreamF A T i → T i) where fix : ∀ i → Stream A i → StreamF A T i F.head (fix i s) = S.head s F.tail (fix i s) {j = j} = f j (fix j (S.tail s {j = j})) module Mutual {A T} (f : ∀ i → StreamF A T i → T i) where mutual fold : ∀ i → Stream A i → T i fold i s = f i (h i s) h : ∀ i → Stream A i → StreamF A T i F.head (h i s) = S.head s F.tail (h i s) {j = j} = fold j (S.tail s {j = j}) module Local where fold : ∀{A T} → (f : ∀ i → StreamF A T i → T i) → ∀ i → Stream A i → T i fold {A} {T} f i s = f i (h i s) where h : ∀ i → Stream A i → StreamF A T i F.head (h i s) = S.head s F.tail (h i s) {j = j} = fold f j (S.tail s {j = j}) -- Unfold for lists -- ListF A X i = ⊤ + ∃j<i. A × X j data ListF (A : Set) (X : Size → Set) (i : Size) : Set where [] : ListF A X i _∷_ : ∀{j : Size< i} (a : A) (xs : X j) → ListF A X i data List (A : Set) (i : Size) : Set where [] : List A i _∷_ : ∀{j : Size< i} (a : A) (xs : List A j) → List A i module With where unfold : ∀{A}{S : Size → Set} → (f : ∀ i → S i → ListF A S i) → ∀ i → S i → List A i unfold f i s with f i s ... | [] = [] ... | _∷_ {j = j} a s' = a ∷ unfold f j s' unfold : ∀{A}{S : Size → Set} → (f : ∀ i → S i → ListF A S i) → ∀ i → S i → List A i unfold {A}{S} f i s = aux (f i s) where aux : ListF A S i → List A i aux [] = [] aux (_∷_ {j = j} a s') = a ∷ unfold f j s'
24.744186
70
0.514568
117de5680fdffc4475c4f8f1d4c23e2ea0bb893a
1,352
agda
Agda
test/Succeed/Issue1973.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1973.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1973.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-05-13 Issue 1973 reported by Nisse -- Problems with parameters to overloaded projections -- {-# OPTIONS -v tc.proj.amb:100 #-} -- {-# OPTIONS -v tc.deftype:100 #-} record R₁ : Set₁ where field f : Set open R₁ public postulate F : ∀ {a} → Set a → Set a module M (_ : Set₁) where record R₂ a (G : Set a → Set a) (A : Set a) : Set a where field f : G A open R₂ public open module N = M Set using (f) works : ∀ a (A : Set a) → N.R₂ a F A → F A works a A x = N.R₂.f x -- WAS: -- a F !=< F A of type Set -- when checking that the expression f x has type F A ill-formed-term-in-error-message : ∀ a (A : Set a) → N.R₂ a F A → F A ill-formed-term-in-error-message a A x = f x -- What Agda did here is to copy parameters from the reduced record type -- M.R₂ Set a F A -- to the unreduced projection -- N.R₂.f -- The number of projections (3) was queried from N.R₂.f, but the projections -- were taken from M.R₂ Set a F A. -- Now, take the original version of the projection, -- M.R₂.f -- which accepts 4 parameters, and these are the ones provided by M.R₂ Set a F A. -- WAS: -- An internal error has occurred. Please report this as a bug. -- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:93 internal-error : (A : Set) → N.R₂ _ F A → F A internal-error A x = f x -- should work now.
25.037037
82
0.644231
6495c44f7ef46b386724311f9245721a9883e1ef
3,484
agda
Agda
src/Util/Hash.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/Util/Hash.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/Util/Hash.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020 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 Util.ByteString open import Util.Encode open import Util.Prelude open import Util.Lemmas -- This module defines Hash functions, and related properties module Util.Hash where ------------------------------------------------- -- Hash function postulates -- postulate -- valid assumption: hashes are some (unspecified) number of bytes hashNumBytes : ℕ Hash : Set Hash = Σ ByteString (λ bs → length bs ≡ hashNumBytes) hashLen-pi : ∀ {bs : ByteString} {n : ℕ } → (p1 p2 : length bs ≡ n) → p1 ≡ p2 hashLen-pi {[]} {.0} refl refl = refl hashLen-pi {h ∷ t} {.(suc (length t))} refl refl = refl sameBS⇒sameHash : ∀ {h1 h2 : Hash} → proj₁ h1 ≡ proj₁ h2 → h1 ≡ h2 sameBS⇒sameHash { h1a , h1b } { h2a , h2b } refl rewrite hashLen-pi {h2a} h1b h2b = refl _≟Hash_ : (h₁ h₂ : Hash) → Dec (h₁ ≡ h₂) (l , pl) ≟Hash (m , pm) with List-≡-dec (Vec-≡-dec _≟Bool_) l m ...| yes refl = yes (cong (_,_ l) (≡-pi pl pm)) ...| no abs = no (abs ∘ ,-injectiveˡ) instance Eq-Hash : Eq Hash Eq._≟_ Eq-Hash = _≟Hash_ encodeH : Hash → ByteString encodeH (bs , _) = bs encodeH-inj : ∀ i j → encodeH i ≡ encodeH j → i ≡ j encodeH-inj (i , pi) (j , pj) refl = cong (_,_ i) (≡-pi pi pj) encodeH-len : ∀{h} → length (encodeH h) ≡ hashNumBytes encodeH-len { bs , p } = p encodeH-len-lemma : ∀ i j → length (encodeH i) ≡ length (encodeH j) encodeH-len-lemma i j = trans (encodeH-len {i}) (sym (encodeH-len {j})) -- Which means that we can make a helper function that combines -- the necessary injections into one big injection ++b-2-inj : (h₁ h₂ : Hash){l₁ l₂ : Hash} → encodeH h₁ ++ encodeH l₁ ≡ encodeH h₂ ++ encodeH l₂ → h₁ ≡ h₂ × l₁ ≡ l₂ ++b-2-inj h₁ h₂ {l₁} {l₂} hip with ++-inj {m = encodeH h₁} {n = encodeH h₂} (encodeH-len-lemma h₁ h₂) hip ...| hh , ll = encodeH-inj h₁ h₂ hh , encodeH-inj l₁ l₂ ll Collision : {A B : Set}(f : A → B)(a₁ a₂ : A) → Set Collision f a₁ a₂ = a₁ ≢ a₂ × f a₁ ≡ f a₂ instance enc-Hash : Encoder Hash enc-Hash = record { encode = encodeH ; encode-inj = encodeH-inj _ _ } module WithCryptoHash -- A Hash function maps a bytestring into a hash. (hash : BitString → Hash) (hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y) where -- We define the concatenation of hashes like one would expect hash-concat : List Hash → Hash hash-concat l = hash (bs-concat (List-map encodeH l)) -- And voila, it is either injective ot we broke the hash function! hash-concat-inj : ∀{l₁ l₂} → hash-concat l₁ ≡ hash-concat l₂ → NonInjective-≡ hash ⊎ l₁ ≡ l₂ hash-concat-inj {l₁} {l₂} hyp with hash-cr hyp ...| inj₁ col = inj₁ ((_ , _) , col) ...| inj₂ same with bs-concat-inj (List-map encodeH l₁) (List-map encodeH l₂) same ...| res = inj₂ (map-inj encodeH (encodeH-inj _ _) res) where map-inj : ∀{a b}{A : Set a}{B : Set b}(f : A → B) → (f-injective : ∀{a₁ a₂} → f a₁ ≡ f a₂ → a₁ ≡ a₂) → ∀{xs ys} → List-map f xs ≡ List-map f ys → xs ≡ ys map-inj f finj {[]} {[]} hyp = refl map-inj f finj {x ∷ xs} {y ∷ ys} hyp = cong₂ _∷_ (finj (proj₁ (∷-injective hyp))) (map-inj f finj (proj₂ (∷-injective hyp)))
35.917526
111
0.596441
7c544ce8cc55748f8ce5ea76abc596a66aa472c3
350
agda
Agda
test/Fail/EmptyInductiveRecord.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/EmptyInductiveRecord.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/EmptyInductiveRecord.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --copatterns #-} module EmptyInductiveRecord where mutual data E : Set where e : F -> E record F : Set where inductive constructor c field f : E open F data ⊥ : Set where elim : E → ⊥ elim (e (c x)) = elim x mutual empty : E empty = e empty? empty? : F f empty? = empty absurd : ⊥ absurd = elim empty
11.666667
33
0.594286
360dc46540b3957409615ddee1b6ca2bd269230a
968
agda
Agda
agda-stdlib/src/Data/Vec/Functional/Relation/Binary/Pointwise.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/Binary/Pointwise.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Vec/Functional/Relation/Binary/Pointwise.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Pointwise lifting of relations over Vector ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Vec.Functional.Relation.Binary.Pointwise where open import Data.Fin.Base open import Data.Nat.Base open import Data.Vec.Functional as VF hiding (map) open import Level using (Level) open import Relation.Binary private variable a b r s ℓ : Level A : Set a B : Set b ------------------------------------------------------------------------ -- Definition Pointwise : REL A B ℓ → ∀ {n} → Vector A n → Vector B n → Set ℓ Pointwise R xs ys = ∀ i → R (xs i) (ys i) ------------------------------------------------------------------------ -- Operations module _ {R : REL A B r} {S : REL A B s} where map : R ⇒ S → ∀ {n} → Pointwise R ⇒ Pointwise S {n = n} map f rs i = f (rs i)
26.888889
72
0.452479
0df604468d3b6365c7e0c7f6a5656db814795c38
2,821
agda
Agda
src/Categories/Object/InternalRelation.agda
sergey-goncharov/agda-categories
e2d7596549e7840b521576f48746ac3c4560f126
[ "MIT" ]
null
null
null
src/Categories/Object/InternalRelation.agda
sergey-goncharov/agda-categories
e2d7596549e7840b521576f48746ac3c4560f126
[ "MIT" ]
null
null
null
src/Categories/Object/InternalRelation.agda
sergey-goncharov/agda-categories
e2d7596549e7840b521576f48746ac3c4560f126
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- Formalization of internal relations -- (=congruences: https://ncatlab.org/nlab/show/congruence) open import Categories.Category module Categories.Object.InternalRelation {o ℓ e} (𝒞 : Category o ℓ e) where open import Level hiding (zero) open import Data.Unit open import Data.Fin using (Fin; zero) renaming (suc to nzero) import Categories.Morphism as Mor import Categories.Morphism.Reasoning as MR open import Categories.Morphism.Notation open import Categories.Diagram.Pullback open import Categories.Diagram.KernelPair open import Categories.Category.Cartesian open import Categories.Category.BinaryProducts 𝒞 using (BinaryProducts; module BinaryProducts) private module 𝒞 = Category 𝒞 open Category 𝒞 open Mor 𝒞 -- A relation is a span, "which is (-1)-truncated as a morphism into the cartesian product." -- (https://ncatlab.org/nlab/show/span#correspondences) isRelation : {X Y R : 𝒞.Obj} (f : R ⇒ X) (g : R ⇒ Y) → Set (o ⊔ ℓ ⊔ e) isRelation{X}{Y}{R} f g = JointMono (Fin 2)(λ{zero → X; (nzero _) → Y}) λ{zero → f; (nzero _) → g} record Relation (X Y : 𝒞.Obj) : Set (suc (o ⊔ ℓ ⊔ e)) where open Mor 𝒞 field dom : 𝒞.Obj p₁ : dom ⇒ X p₂ : dom ⇒ Y field relation : isRelation p₁ p₂ record isEqSpan {X R : 𝒞.Obj} (f : R ⇒ X) (g : R ⇒ X) : Set (suc (o ⊔ ℓ ⊔ e)) where field R×R : Pullback 𝒞 f g module R×R = Pullback R×R renaming (P to dom) field refl : X ⇒ R sym : R ⇒ R trans : R×R.dom ⇒ R is-refl₁ : f ∘ refl ≈ id is-refl₂ : g ∘ refl ≈ id is-sym₁ : f ∘ sym ≈ g is-sym₂ : g ∘ sym ≈ f is-trans₁ : f ∘ trans ≈ f ∘ R×R.p₁ is-trans₂ : g ∘ trans ≈ g ∘ R×R.p₂ -- Internal equivalence record Equivalence (X : 𝒞.Obj) : Set (suc (o ⊔ ℓ ⊔ e)) where open Mor 𝒞 open BinaryProducts field R : Relation X X open Relation R module R = Relation R field eqspan : isEqSpan R.p₁ R.p₂ module _ where open Pullback hiding (P) KP⇒EqSpan : {X Y : 𝒞.Obj} (f : X ⇒ Y) → (kp : KernelPair 𝒞 f) → (p : Pullback 𝒞 (p₁ kp) (p₂ kp)) → isEqSpan (p₁ kp) (p₂ kp) KP⇒EqSpan f kp p = record { R×R = p ; refl = universal kp {_} {id}{id} 𝒞.Equiv.refl ; sym = universal kp {_} {p₂ kp}{p₁ kp} (𝒞.Equiv.sym (commute kp)) ; trans = universal kp {_}{p₁ kp ∘ p₁ p}{p₂ kp ∘ p₂ p} (∘-resp-≈ʳ (commute p)) ; is-refl₁ = p₁∘universal≈h₁ kp ; is-refl₂ = p₂∘universal≈h₂ kp ; is-sym₁ = p₁∘universal≈h₁ kp ; is-sym₂ = p₂∘universal≈h₂ kp ; is-trans₁ = p₁∘universal≈h₁ kp ; is-trans₂ = p₂∘universal≈h₂ kp } KP⇒Relation : {X Y : 𝒞.Obj} (f : X ⇒ Y) → (kp : KernelPair 𝒞 f) → (p : Pullback 𝒞 (p₁ kp) (p₂ kp)) → isRelation (p₁ kp) (p₂ kp) KP⇒Relation f kp _ _ _ eq = unique-diagram kp (eq zero) (eq (nzero zero))
28.785714
129
0.613967
7c91eabfdf8b0232a16763061110567ce6f60211
6,703
agda
Agda
Formalization/SKICombinatorCalculus.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Formalization/SKICombinatorCalculus.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Formalization/SKICombinatorCalculus.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Formalization.SKICombinatorCalculus where import Lvl import Function open import Functional using (_∘_) open import Type open import Structure.Relator.Properties open import Syntax.Transitivity data Term : Type{Lvl.𝟎} where S : Term -- Fusion K : Term -- Constant _·_ : Term → Term → Term infixl 30 _·_ pattern B = S · (K · S) · K -- Composition pattern C = S · (S · (K · B) · S) · (K · K) -- Swapped application pattern I = S · K · K -- Identity of operation pattern SA = (S · I) · I -- Self application pattern W = S · S · (S · K) -- pattern Ω = SA · SA -- pattern SW = S · (K · (S · I)) · K -- Swapped operation T = C Z = B -- Z = C · (C · (B · N · (S · I · I)) · Ω) · I {- TODO: Is this possible? term-fn-type : ∀{ℓ} → Term → Type{Lvl.𝐒(ℓ)} term-fn-type {ℓ} S = ∀{X Y Z : Type{ℓ}} → (X → (Y → Z)) → (X → Y) → (X → Z) term-fn-type {ℓ} K = ∀{X Y : Type{ℓ}} → Y → X → Y term-fn-type {ℓ} (x · y) = {!term-fn-type {ℓ} x!} -} module Derivation where -- TODO: But there are no base cases? data deriv : Term → Type{Lvl.𝟎} where constant : ∀{α β γ ι} → deriv(α · ((K · β) · γ) · ι) → deriv(α · β · ι) fuse : ∀{α β γ δ ι} → deriv(α · (((S · β) · γ) · δ) · ι) → deriv(α · ((β · δ) · (γ · δ)) · ι) _⇒_ : Term → Term → Type a ⇒ b = ∀{α ι} → deriv(α · a · ι) → deriv(α · b · ι) identity : ∀{β} → ((I · β) ⇒ β) identity = constant ∘ fuse -- composition : ∀{α ι a b c} → deriv(α · (B · a · b · c) · ι) → deriv(α · ((a · (b · c))) · ι) -- composition = {!!} -- TODO: Is this really correct? Should be similar to deriv data _⟶_ : Term → Term → Type{Lvl.𝟎} where -- TODO: Use reflexive-transitive closure instead constant : ∀{c t} → (((K · c) · t) ⟶ c) fuse : ∀{a b c} → ((((S · a) · b) · c) ⟶ ((a · c) · (b · c))) comp : ∀{a₁ a₂ b₁ b₂} → (a₁ ⟶ a₂) → (b₁ ⟶ b₂) → ((a₁ · b₁) ⟶ (a₂ · b₂)) refl : ∀{a} → (a ⟶ a) trans : ∀{a b c} → (a ⟶ b) → (b ⟶ c) → (a ⟶ c) infixl 29 _⟶_ instance [⟶]-reflexivity : Reflexivity(_⟶_) [⟶]-reflexivity = intro refl instance [⟶]-transitivity : Transitivity(_⟶_) [⟶]-transitivity = intro trans -- identity : ∀{t} → ((I · t) ⟶ t) pattern identity = trans fuse constant -- compₗ : ∀{a₁ a₂ b} → (a₁ ⟶ a₂) → ((a₁ · b) ⟶ (a₂ · b)) pattern compₗ p = comp p refl -- compᵣ : ∀{a b₁ b₂} → (b₁ ⟶ b₂) → ((a · b₁) ⟶ (a · b₂)) pattern compᵣ p = comp refl p composition : ∀{a b c} → ((B · a · b · c) ⟶ (a · (b · c))) composition {a}{b}{c} = B · a · b · c 🝖-[ refl ] ((S · (K · S) · K · a) · b) · c 🝖-[ compₗ (compₗ fuse) ] (((K · S · a) · (K · a)) · b) · c 🝖-[ compₗ (compₗ (compₗ constant)) ] ((S · (K · a)) · b) · c 🝖-[ fuse ] (K · a · c) · (b · c) 🝖-[ compₗ constant ] a · (b · c) 🝖-end swapped-application : ∀{a b c} → ((C · a · b · c) ⟶ ((a · c) · b)) swapped-application {a}{b}{c} = C · a · b · c 🝖-[ refl ] S · (S · (K · B) · S) · (K · K) · a · b · c 🝖-[ compₗ (compₗ fuse) ] (S · (K · B) · S · a) · (K · K · a) · b · c 🝖-[ compₗ (compₗ (comp fuse constant)) ] (K · B · a · (S · a)) · K · b · c 🝖-[ compₗ (compₗ (compₗ (compₗ constant))) ] (B · (S · a)) · K · b · c 🝖-[ compₗ composition ] (S · a) · (K · b) · c 🝖-[ fuse ] (a · c) · (K · b · c) 🝖-[ compᵣ constant ] (a · c) · b 🝖-end apply-self : ∀{t} → ((SA · t) ⟶ (t · t)) apply-self = trans fuse (comp identity identity) swapping : ∀{a b} → ((SW · a · b) ⟶ (b · a)) swapping {a}{b} = S · (K · (S · I)) · K · a · b 🝖-[ compₗ fuse ] (K · (S · I) · a) · (K · a) · b 🝖-[ compₗ (compₗ constant) ] (S · I) · (K · a) · b 🝖-[ fuse ] I · b · (K · a · b) 🝖-[ comp identity constant ] b · a 🝖-end module Boolean where TRUE = K -- True FALSE = S · K -- False NOT = FALSE · TRUE -- Not (Negation) OR = TRUE -- Or (Disjunction) AND = FALSE -- And (Conjunction) IsTrue : Term → Type{Lvl.𝟎} IsTrue(a) = ∀{t f} → ((a · t · f) ⟶ t) IsFalse : Term → Type{Lvl.𝟎} IsFalse(a) = ∀{t f} → ((a · t · f) ⟶ f) reduce-true-is-true : ∀{t} → (t ⟶ TRUE) → IsTrue(t) reduce-true-is-true tT = (compₗ (compₗ tT)) 🝖 constant reduce-false-is-false : ∀{t} → (t ⟶ FALSE) → IsFalse(t) reduce-false-is-false tT = (compₗ (compₗ tT)) 🝖 identity true : IsTrue(TRUE) true = constant false : IsFalse(FALSE) false = identity not-true-is-false : ∀{t} → IsTrue(t) → IsFalse(t · NOT) not-true-is-false t-true = (compₗ t-true) 🝖 fuse 🝖 constant {-not-false-is-true : ∀{t} → IsFalse(t) → IsTrue(t · NOT) not-false-is-true {term} t-false {t}{f} = term · NOT · t · f 🝖-[ refl ] term · (S · K · K) · t · f 🝖-[ {!!} ] f · (S · K · K) · t · f 🝖-[ {!!} ] t 🝖-end -} not-true : IsFalse(TRUE · NOT) not-true {t}{f} = not-true-is-false constant {-TRUE · NOT · t · f 🝖-[ refl ] TRUE · (FALSE · TRUE) · t · f 🝖-[ refl ] K · (S · K · K) · t · f 🝖-[ compₗ constant ] S · K · K · f 🝖-[ fuse ] K · f · (K · f) 🝖-[ constant ] f 🝖-end-} {- not-false : IsTrue(FALSE · NOT) not-false {t}{f} = FALSE · NOT · t · f 🝖-[ refl ] FALSE · (FALSE · TRUE) · t · f 🝖-[ refl ] S · K · (S · K · K) · t · f 🝖-[ compₗ fuse ] K · t · (S · K · K · t) · f 🝖-[ compₗ constant ] t · f 🝖-[ {!!} ] -- TODO: ??? t 🝖-end -- not-false-is-true identity -} or-true-true : IsTrue(TRUE · OR · TRUE) or-true-true = reduce-true-is-true constant or-true-false : IsTrue(TRUE · OR · FALSE) or-true-false = reduce-true-is-true constant or-false-true : IsTrue(FALSE · OR · TRUE) or-false-true = reduce-true-is-true(fuse 🝖 constant) or-false-true2 : IsTrue(FALSE · OR · TRUE) or-false-true2 = reduce-true-is-true(fuse 🝖 constant) or-false-false : IsFalse(FALSE · OR · FALSE) or-false-false = reduce-false-is-false(fuse 🝖 constant) and-true-true : IsTrue(TRUE · TRUE · AND) and-true-true = reduce-true-is-true(constant) and-true-false : IsFalse(TRUE · FALSE · AND) and-true-false = reduce-false-is-false(constant) and-false-true : IsFalse(FALSE · TRUE · AND) and-false-true = reduce-false-is-false(identity) and-false-false : IsFalse(FALSE · FALSE · AND) and-false-false = reduce-false-is-false(fuse 🝖 constant)
34.911458
101
0.464717
73800c13f7411059a969ff323df7873b737e9649
724
agda
Agda
core/lib/types/HList.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
core/lib/types/HList.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
core/lib/types/HList.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 lib.Basics open import lib.types.List module lib.types.HList where data HList {i} : List (Type i) → Type (lsucc i) where nil : HList nil _::_ : {A : Type i} {L : List (Type i)} → A → HList L → HList (A :: L) hlist-curry-type : ∀ {i j} (L : List (Type i)) (B : HList L → Type (lmax i j)) → Type (lmax i j) hlist-curry-type nil B = B nil hlist-curry-type {j = j} (A :: L) B = (x : A) → hlist-curry-type {j = j} L (λ xs → B (x :: xs)) hlist-curry : ∀ {i j} {L : List (Type i)} {B : HList L → Type (lmax i j)} (f : Π (HList L) B) → hlist-curry-type {j = j} L B hlist-curry {L = nil} f = f nil hlist-curry {L = A :: _} f = λ x → hlist-curry (λ xs → f (x :: xs))
32.909091
73
0.558011
1b5583e116df1d377a12efe0d93dfb6d026a72f5
279
agda
Agda
test/interaction/Issue2669.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2669.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2669.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where record Pair (A B : Set) : Set where field π₁ : A π₂ : B open Pair foo : {A B : Set} → Pair A B → Pair A B foo = λ { x → {!x!} } {- Case splitting on x produces: foo = λ { record { π₁ = π₃ ; π₂ = π₃ } → ? } Repeated variables in pattern: π₃ -}
16.411765
47
0.537634
cc66a819c172ef84dc80d7cff184ea993de14270
6,563
agda
Agda
src/Categories/Category/Monoidal/Reasoning.agda
o1lo01ol1o/agda-categories
5fc007768264a270b8ff319570225986773da601
[ "MIT" ]
null
null
null
src/Categories/Category/Monoidal/Reasoning.agda
o1lo01ol1o/agda-categories
5fc007768264a270b8ff319570225986773da601
[ "MIT" ]
null
null
null
src/Categories/Category/Monoidal/Reasoning.agda
o1lo01ol1o/agda-categories
5fc007768264a270b8ff319570225986773da601
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Categories.Category using (Category) open import Categories.Category.Monoidal using (Monoidal) module Categories.Category.Monoidal.Reasoning {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where open import Data.Product using (_,_) open import Categories.Functor using (Functor) open Category C private variable X Y : Obj f g h i : X ⇒ Y open Monoidal M using (_⊗₀_; _⊗₁_; ⊗) open Functor ⊗ using (F-resp-≈; homomorphism) open HomReasoning public infixr 6 _⟩⊗⟨_ refl⟩⊗⟨_ infixl 7 _⟩⊗⟨refl ⊗-resp-≈ : f ≈ h → g ≈ i → (f ⊗₁ g) ≈ (h ⊗₁ i) ⊗-resp-≈ p q = F-resp-≈ (p , q) ⊗-resp-≈ˡ : f ≈ h → (f ⊗₁ g) ≈ (h ⊗₁ g) ⊗-resp-≈ˡ p = ⊗-resp-≈ p Equiv.refl ⊗-resp-≈ʳ : g ≈ i → (f ⊗₁ g) ≈ (f ⊗₁ i) ⊗-resp-≈ʳ p = ⊗-resp-≈ Equiv.refl p _⟩⊗⟨_ : f ≈ h → g ≈ i → (f ⊗₁ g) ≈ (h ⊗₁ i) _⟩⊗⟨_ = ⊗-resp-≈ refl⟩⊗⟨_ : g ≈ i → (f ⊗₁ g) ≈ (f ⊗₁ i) refl⟩⊗⟨_ = ⊗-resp-≈ʳ _⟩⊗⟨refl : f ≈ h → (f ⊗₁ g) ≈ (h ⊗₁ g) _⟩⊗⟨refl = ⊗-resp-≈ˡ -- This corresponds to the graphical coherence property of diagrams -- modelling monoidal categories: -- -- | | | | -- [h] [i] [h] [i] -- | | ≈ | | -- [f] [g] | | -- | | | | -- [f] [g] -- | | ⊗-distrib-over-∘ : ((f ∘ h) ⊗₁ (g ∘ i)) ≈ ((f ⊗₁ g) ∘ (h ⊗₁ i)) ⊗-distrib-over-∘ = homomorphism -- Parallel commutation parallel : ∀ {X₁ X₂ Y₁ Y₂ Z₁ Z₂ W₁ W₂} {f₁ : Y₁ ⇒ W₁} {f₂ : Z₁ ⇒ W₁} {g₁ : Y₂ ⇒ W₂} {g₂ : Z₂ ⇒ W₂} {h₁ : X₁ ⇒ Y₁} {h₂ : X₁ ⇒ Z₁} {i₁ : X₂ ⇒ Y₂} {i₂ : X₂ ⇒ Z₂} → f₁ ∘ h₁ ≈ f₂ ∘ h₂ → g₁ ∘ i₁ ≈ g₂ ∘ i₂ → f₁ ⊗₁ g₁ ∘ h₁ ⊗₁ i₁ ≈ f₂ ⊗₁ g₂ ∘ h₂ ⊗₁ i₂ parallel {f₁ = f₁} {f₂} {g₁} {g₂} {h₁} {h₂} {i₁} {i₂} hyp₁ hyp₂ = begin f₁ ⊗₁ g₁ ∘ h₁ ⊗₁ i₁ ≈˘⟨ ⊗-distrib-over-∘ ⟩ (f₁ ∘ h₁) ⊗₁ (g₁ ∘ i₁) ≈⟨ hyp₁ ⟩⊗⟨ hyp₂ ⟩ (f₂ ∘ h₂) ⊗₁ (g₂ ∘ i₂) ≈⟨ ⊗-distrib-over-∘ ⟩ f₂ ⊗₁ g₂ ∘ h₂ ⊗₁ i₂ ∎ -- Parallel-to-serial conversions -- -- | | | | | | -- | | | [g] [f] | -- [f] [g] = | | = | | -- | | [f] | | [g] -- | | | | | | serialize₁₂ : ∀ {X₁ Y₁ X₂ Y₂} {f : X₁ ⇒ Y₁} {g : X₂ ⇒ Y₂} → f ⊗₁ g ≈ f ⊗₁ id ∘ id ⊗₁ g serialize₁₂ {f = f} {g} = begin f ⊗₁ g ≈˘⟨ identityʳ ⟩⊗⟨ identityˡ ⟩ (f ∘ id) ⊗₁ (id ∘ g) ≈⟨ ⊗-distrib-over-∘ ⟩ f ⊗₁ id ∘ id ⊗₁ g ∎ serialize₂₁ : ∀ {X₁ Y₁ X₂ Y₂} {f : X₁ ⇒ Y₁} {g : X₂ ⇒ Y₂} → f ⊗₁ g ≈ id ⊗₁ g ∘ f ⊗₁ id serialize₂₁ {f = f} {g} = begin f ⊗₁ g ≈˘⟨ identityˡ ⟩⊗⟨ identityʳ ⟩ (id ∘ f) ⊗₁ (g ∘ id) ≈⟨ ⊗-distrib-over-∘ ⟩ id ⊗₁ g ∘ f ⊗₁ id ∎ -- Split a composite in the first component -- -- | | | | | | -- [g] | [g] | [g] [h] -- | [h] = | | = | | -- [f] | [f] [h] [f] | -- | | | | | | split₁ʳ : ∀ {X₁ Y₁ Z₁ X₂ Y₂} {f : Y₁ ⇒ Z₁} {g : X₁ ⇒ Y₁} {h : X₂ ⇒ Y₂} → (f ∘ g) ⊗₁ h ≈ f ⊗₁ h ∘ g ⊗₁ id split₁ʳ {f = f} {g} {h} = begin (f ∘ g) ⊗₁ h ≈˘⟨ refl⟩⊗⟨ identityʳ ⟩ (f ∘ g) ⊗₁ (h ∘ id) ≈⟨ ⊗-distrib-over-∘ ⟩ f ⊗₁ h ∘ g ⊗₁ id ∎ split₁ˡ : ∀ {X₁ Y₁ Z₁ X₂ Y₂} {f : Y₁ ⇒ Z₁} {g : X₁ ⇒ Y₁} {h : X₂ ⇒ Y₂} → (f ∘ g) ⊗₁ h ≈ f ⊗₁ id ∘ g ⊗₁ h split₁ˡ {f = f} {g} {h} = begin (f ∘ g) ⊗₁ h ≈˘⟨ refl⟩⊗⟨ identityˡ ⟩ (f ∘ g) ⊗₁ (id ∘ h) ≈⟨ ⊗-distrib-over-∘ ⟩ f ⊗₁ id ∘ g ⊗₁ h ∎ -- Split a composite in the second component -- -- | | | | | | -- | [h] | [h] [f] [h] -- [f] | = | | = | | -- | [g] [f] [g] | [g] -- | | | | | | split₂ʳ : ∀ {X₁ Y₁ X₂ Y₂ Z₂} {f : X₁ ⇒ Y₁} {g : Y₂ ⇒ Z₂} {h : X₂ ⇒ Y₂} → f ⊗₁ (g ∘ h) ≈ f ⊗₁ g ∘ id ⊗₁ h split₂ʳ {f = f} {g} {h} = begin f ⊗₁ (g ∘ h) ≈˘⟨ identityʳ ⟩⊗⟨refl ⟩ (f ∘ id) ⊗₁ (g ∘ h) ≈⟨ ⊗-distrib-over-∘ ⟩ f ⊗₁ g ∘ id ⊗₁ h ∎ split₂ˡ : ∀ {X₁ Y₁ X₂ Y₂ Z₂} {f : X₁ ⇒ Y₁} {g : Y₂ ⇒ Z₂} {h : X₂ ⇒ Y₂} → f ⊗₁ (g ∘ h) ≈ id ⊗₁ g ∘ f ⊗₁ h split₂ˡ {f = f} {g} {h} = begin f ⊗₁ (g ∘ h) ≈˘⟨ identityˡ ⟩⊗⟨refl ⟩ (id ∘ f) ⊗₁ (g ∘ h) ≈⟨ ⊗-distrib-over-∘ ⟩ id ⊗₁ g ∘ f ⊗₁ h ∎ -- Combined splitting and re-association. module _ {X Y Z} {f : X ⇒ Z} {g : Y ⇒ Z} {h : X ⇒ Y} (f≈gh : f ≈ g ∘ h) where infixr 4 split₁_⟩∘⟨_ split₂_⟩∘⟨_ infixl 5 _⟩∘⟨split₁_ _⟩∘⟨split₂_ split₁_⟩∘⟨_ : ∀ {V W} {i j : V ⇒ X ⊗₀ W} → i ≈ j → f ⊗₁ id ∘ i ≈ g ⊗₁ id ∘ h ⊗₁ id ∘ j split₁_⟩∘⟨_ {_} {_} {i} {j} i≈j = begin f ⊗₁ id ∘ i ≈⟨ f≈gh ⟩⊗⟨refl ⟩∘⟨ i≈j ⟩ (g ∘ h) ⊗₁ id ∘ j ≈⟨ split₁ˡ ⟩∘⟨refl ⟩ (g ⊗₁ id ∘ h ⊗₁ id) ∘ j ≈⟨ assoc ⟩ g ⊗₁ id ∘ (h ⊗₁ id ∘ j) ∎ split₂_⟩∘⟨_ : ∀ {V W} {i j : V ⇒ W ⊗₀ X} → i ≈ j → id ⊗₁ f ∘ i ≈ id ⊗₁ g ∘ id ⊗₁ h ∘ j split₂_⟩∘⟨_ {_} {_} {i} {j} i≈j = begin id ⊗₁ f ∘ i ≈⟨ refl⟩⊗⟨ f≈gh ⟩∘⟨ i≈j ⟩ id ⊗₁ (g ∘ h) ∘ j ≈⟨ split₂ˡ ⟩∘⟨refl ⟩ (id ⊗₁ g ∘ id ⊗₁ h) ∘ j ≈⟨ assoc ⟩ id ⊗₁ g ∘ (id ⊗₁ h ∘ j) ∎ _⟩∘⟨split₁_ : ∀ {V W} {i j : Z ⊗₀ W ⇒ V} → i ≈ j → i ∘ f ⊗₁ id ≈ (j ∘ g ⊗₁ id) ∘ h ⊗₁ id _⟩∘⟨split₁_ {_} {_} {i} {j} i≈j = begin i ∘ f ⊗₁ id ≈⟨ i≈j ⟩∘⟨ f≈gh ⟩⊗⟨refl ⟩ j ∘ (g ∘ h) ⊗₁ id ≈⟨ refl⟩∘⟨ split₁ˡ ⟩ j ∘ (g ⊗₁ id ∘ h ⊗₁ id) ≈⟨ sym-assoc ⟩ (j ∘ g ⊗₁ id) ∘ h ⊗₁ id ∎ _⟩∘⟨split₂_ : ∀ {V W} {i j : W ⊗₀ Z ⇒ V} → i ≈ j → i ∘ id ⊗₁ f ≈ (j ∘ id ⊗₁ g) ∘ id ⊗₁ h _⟩∘⟨split₂_ {_} {_} {i} {j} i≈j = begin i ∘ id ⊗₁ f ≈⟨ i≈j ⟩∘⟨ refl⟩⊗⟨ f≈gh ⟩ j ∘ id ⊗₁ (g ∘ h) ≈⟨ refl⟩∘⟨ split₂ˡ ⟩ j ∘ (id ⊗₁ g ∘ id ⊗₁ h) ≈⟨ sym-assoc ⟩ (j ∘ id ⊗₁ g) ∘ id ⊗₁ h ∎ -- Combined merging and re-association. module _ {X Y Z} {f : Y ⇒ Z} {g : X ⇒ Y} {h : X ⇒ Z} (fg≈h : f ∘ g ≈ h) where infixr 4 merge₁_⟩∘⟨_ merge₂_⟩∘⟨_ infixl 5 _⟩∘⟨merge₁_ _⟩∘⟨merge₂_ merge₁_⟩∘⟨_ : ∀ {V W} {i j : V ⇒ X ⊗₀ W} → i ≈ j → f ⊗₁ id ∘ g ⊗₁ id ∘ i ≈ h ⊗₁ id ∘ j merge₁_⟩∘⟨_ i≈j = ⟺ (split₁ ⟺ fg≈h ⟩∘⟨ ⟺ i≈j) merge₂_⟩∘⟨_ : ∀ {V W} {i j : V ⇒ W ⊗₀ X} → i ≈ j → id ⊗₁ f ∘ id ⊗₁ g ∘ i ≈ id ⊗₁ h ∘ j merge₂_⟩∘⟨_ i≈j = ⟺ (split₂ ⟺ fg≈h ⟩∘⟨ ⟺ i≈j) _⟩∘⟨merge₁_ : ∀ {V W} {i j : Z ⊗₀ W ⇒ V} → i ≈ j → (i ∘ f ⊗₁ id) ∘ g ⊗₁ id ≈ j ∘ h ⊗₁ id _⟩∘⟨merge₁_ i≈j = ⟺ (⟺ fg≈h ⟩∘⟨split₁ ⟺ i≈j) _⟩∘⟨merge₂_ : ∀ {V W} {i j : W ⊗₀ Z ⇒ V} → i ≈ j → (i ∘ id ⊗₁ f) ∘ id ⊗₁ g ≈ j ∘ id ⊗₁ h _⟩∘⟨merge₂_ i≈j = ⟺ (⟺ fg≈h ⟩∘⟨split₂ ⟺ i≈j)
33.146465
97
0.381533
0da49f32240262a548b29384c9ae189c1ab6eb87
3,756
agda
Agda
Cubical/Foundations/Function.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Foundations/Function.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Foundations/Function.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{- Definitions for functions -} {-# OPTIONS --cubical --safe #-} module Cubical.Foundations.Function where open import Cubical.Foundations.Prelude -- The identity function idfun : ∀ {ℓ} → (A : Type ℓ) → A → A idfun _ x = x infixr 9 _∘_ _∘_ : ∀ {ℓ ℓ′ ℓ″} {A : Type ℓ} {B : A → Type ℓ′} {C : (a : A) → B a → Type ℓ″} (g : {a : A} → (b : B a) → C a b) → (f : (a : A) → B a) → (a : A) → C a (f a) g ∘ f = λ x → g (f x) ∘-assoc : ∀ {ℓ ℓ′ ℓ″ ℓ‴} {A : Type ℓ} {B : A → Type ℓ′} {C : (a : A) → B a → Type ℓ″} {D : (a : A) (b : B a) → C a b → Type ℓ‴} (h : {a : A} {b : B a} → (c : C a b) → D a b c) (g : {a : A} → (b : B a) → C a b) (f : (a : A) → B a) → (h ∘ g) ∘ f ≡ h ∘ (g ∘ f) ∘-assoc h g f i x = h (g (f x)) ∘-idˡ : ∀ {ℓ ℓ′} {A : Type ℓ} {B : A → Type ℓ′} (f : (a : A) → B a) → f ∘ idfun A ≡ f ∘-idˡ f i x = f x ∘-idʳ : ∀ {ℓ ℓ′} {A : Type ℓ} {B : A → Type ℓ′} (f : (a : A) → B a) → (λ {a} → idfun (B a)) ∘ f ≡ f ∘-idʳ f i x = f x const : ∀ {ℓ ℓ′} {A : Type ℓ} {B : Type ℓ′} → A → B → A const x = λ _ → x case_of_ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} → (x : A) → (∀ x → B x) → B x case x of f = f x case_return_of_ : ∀ {ℓ ℓ'} {A : Type ℓ} (x : A) (B : A → Type ℓ') → (∀ x → B x) → B x case x return P of f = f x uncurry : ∀{ℓ ℓ′ ℓ″} {A : Type ℓ} {B : A → Type ℓ′} {C : (a : A) → B a → Type ℓ″} → ((x : A) → (y : B x) → C x y) → (p : Σ A B) → C (fst p) (snd p) uncurry f (x , y) = f x y module _ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where -- Notions of 'coherently constant' functions for low dimensions. -- These are the properties of functions necessary to e.g. eliminate -- from the propositional truncation. -- 2-Constant functions are coherently constant if B is a set. 2-Constant : (A → B) → Type _ 2-Constant f = ∀ x y → f x ≡ f y 2-Constant-isProp : isSet B → (f : A → B) → isProp (2-Constant f) 2-Constant-isProp Bset f link1 link2 i x y j = Bset (f x) (f y) (link1 x y) (link2 x y) i j -- 3-Constant functions are coherently constant if B is a groupoid. record 3-Constant (f : A → B) : Type (ℓ-max ℓ ℓ') where field link : 2-Constant f coh₁ : ∀ x y z → Square (link x y) (link x z) refl (link y z) coh₂ : ∀ x y z → Square (link x z) (link y z) (link x y) refl coh₂ x y z i j = hcomp (λ k → λ { (j = i0) → link x y i ; (i = i0) → link x z (j ∧ k) ; (j = i1) → link x z (i ∨ k) ; (i = i1) → link y z j }) (coh₁ x y z j i) link≡refl : ∀ x → refl ≡ link x x link≡refl x i j = hcomp (λ k → λ { (i = i0) → link x x (j ∧ ~ k) ; (i = i1) → link x x j ; (j = i0) → f x ; (j = i1) → link x x (~ i ∧ ~ k) }) (coh₁ x x x (~ i) j) downleft : ∀ x y → Square (link x y) refl refl (link y x) downleft x y i j = hcomp (λ k → λ { (i = i0) → link x y j ; (i = i1) → link≡refl x (~ k) j ; (j = i0) → f x ; (j = i1) → link y x i }) (coh₁ x y x i j) link≡symlink : ∀ x y → link x y ≡ sym (link y x) link≡symlink x y i j = hcomp (λ k → λ { (i = i0) → link x y j ; (i = i1) → link y x (~ j ∨ ~ k) ; (j = i0) → f x ; (j = i1) → link y x (i ∧ ~ k) }) (downleft x y i j) homotopySymInv : ∀ {ℓ} {A : Type ℓ} {f : A → A} (p : ∀ a → f a ≡ a) (a : A) → Path (f a ≡ f a) (λ i → p (p a (~ i)) i) refl homotopySymInv {f = f} p a j i = hcomp (λ k → λ { (i = i0) → f a; (i = i1) → p a (j ∧ ~ k); (j = i0) → p (p a (~ i)) i; (j = i1) → p a (i ∧ ~ k)}) (p (p a (~ i ∨ j)) i)
32.37931
127
0.417199
644d697b11bc261a542d85fe8317b438a1d1298a
700
agda
Agda
test/Compiler/simple/Issue5288.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/Issue5288.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Compiler/simple/Issue5288.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2021-04-10, issue #5288 -- De Bruijn index problem in treeless compiler -- {-# OPTIONS -v tc.cc:20 #-} -- {-# OPTIONS -v treeless:40 #-} -- {-# OPTIONS -v treeless.convert.lambdas:40 #-} open import Agda.Builtin.Equality open import Agda.Builtin.IO open import Agda.Builtin.Nat open import Agda.Builtin.Unit f : Nat → Nat → Nat f _ zero = 0 f m = λ _ → m -- this catch-all was wrongly compiled postulate printNat : Nat → IO ⊤ {-# COMPILE GHC printNat = print #-} {-# COMPILE JS printNat = function (x) { return function(cb) { process.stdout.write(x + "\n"); cb(0); }; } #-} test : Nat test = f 123 1 prf : test ≡ 123 prf = refl main = printNat test -- Should print 123
21.875
111
0.645714
ed29bc18eaecbe785f8f4e27ff5296870d3ebf0b
421
agda
Agda
src/Direction.agda
kcaliban/dual-session
cd41919582013e75463308c32750e2712cf2de86
[ "BSD-2-Clause" ]
null
null
null
src/Direction.agda
kcaliban/dual-session
cd41919582013e75463308c32750e2712cf2de86
[ "BSD-2-Clause" ]
null
null
null
src/Direction.agda
kcaliban/dual-session
cd41919582013e75463308c32750e2712cf2de86
[ "BSD-2-Clause" ]
null
null
null
module Direction where open import Relation.Binary.PropositionalEquality hiding (Extensionality) ---------------------------------------------------------------------- -- direction data Dir : Set where SND RCV : Dir variable d d₁ d₂ d₃ : Dir -- dual dual-dir : Dir → Dir dual-dir SND = RCV dual-dir RCV = SND dual-dir-inv : (d : Dir) → dual-dir (dual-dir d) ≡ d dual-dir-inv SND = refl dual-dir-inv RCV = refl
18.304348
73
0.577197
3f38d8fcce20331542fb972f09acd1d8aa6389b0
20,520
agda
Agda
Cubical/Data/Int/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Data/Int/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Data/Int/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Data.Int.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Function open import Cubical.Data.Empty as Empty open import Cubical.Data.Nat hiding (+-assoc ; +-comm) renaming (_·_ to _·ℕ_; _+_ to _+ℕ_ ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Data.Bool open import Cubical.Data.Sum open import Cubical.Data.Int.Base open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq sucPred : ∀ i → sucℤ (predℤ i) ≡ i sucPred (pos zero) = refl sucPred (pos (suc n)) = refl sucPred (negsuc n) = refl predSuc : ∀ i → predℤ (sucℤ i) ≡ i predSuc (pos n) = refl predSuc (negsuc zero) = refl predSuc (negsuc (suc n)) = refl injPos : ∀ {a b : ℕ} → pos a ≡ pos b → a ≡ b injPos {a} h = subst T h refl where T : ℤ → Type₀ T (pos x) = a ≡ x T (negsuc _) = ⊥ injNegsuc : ∀ {a b : ℕ} → negsuc a ≡ negsuc b → a ≡ b injNegsuc {a} h = subst T h refl where T : ℤ → Type₀ T (pos _) = ⊥ T (negsuc x) = a ≡ x posNotnegsuc : ∀ (a b : ℕ) → ¬ (pos a ≡ negsuc b) posNotnegsuc a b h = subst T h 0 where T : ℤ → Type₀ T (pos _) = ℕ T (negsuc _) = ⊥ negsucNotpos : ∀ (a b : ℕ) → ¬ (negsuc a ≡ pos b) negsucNotpos a b h = subst T h 0 where T : ℤ → Type₀ T (pos _) = ⊥ T (negsuc _) = ℕ discreteℤ : Discrete ℤ discreteℤ (pos n) (pos m) with discreteℕ n m ... | yes p = yes (cong pos p) ... | no p = no (λ x → p (injPos x)) discreteℤ (pos n) (negsuc m) = no (posNotnegsuc n m) discreteℤ (negsuc n) (pos m) = no (negsucNotpos n m) discreteℤ (negsuc n) (negsuc m) with discreteℕ n m ... | yes p = yes (cong negsuc p) ... | no p = no (λ x → p (injNegsuc x)) isSetℤ : isSet ℤ isSetℤ = Discrete→isSet discreteℤ -pos : ∀ n → - (pos n) ≡ neg n -pos zero = refl -pos (suc n) = refl -neg : ∀ n → - (neg n) ≡ pos n -neg zero = refl -neg (suc n) = refl -Involutive : ∀ z → - (- z) ≡ z -Involutive (pos n) = cong -_ (-pos n) ∙ -neg n -Involutive (negsuc n) = refl isEquiv- : isEquiv (-_) isEquiv- = isoToIsEquiv (iso -_ -_ -Involutive -Involutive) sucℤ+pos : ∀ n m → sucℤ (m +pos n) ≡ (sucℤ m) +pos n sucℤ+pos zero m = refl sucℤ+pos (suc n) m = cong sucℤ (sucℤ+pos n m) predℤ+negsuc : ∀ n m → predℤ (m +negsuc n) ≡ (predℤ m) +negsuc n predℤ+negsuc zero m = refl predℤ+negsuc (suc n) m = cong predℤ (predℤ+negsuc n m) sucℤ+negsuc : ∀ n m → sucℤ (m +negsuc n) ≡ (sucℤ m) +negsuc n sucℤ+negsuc zero m = (sucPred _) ∙ (sym (predSuc _)) sucℤ+negsuc (suc n) m = _ ≡⟨ sucPred _ ⟩ m +negsuc n ≡[ i ]⟨ predSuc m (~ i) +negsuc n ⟩ (predℤ (sucℤ m)) +negsuc n ≡⟨ sym (predℤ+negsuc n (sucℤ m)) ⟩ predℤ (sucℤ m +negsuc n) ∎ predℤ+pos : ∀ n m → predℤ (m +pos n) ≡ (predℤ m) +pos n predℤ+pos zero m = refl predℤ+pos (suc n) m = _ ≡⟨ predSuc _ ⟩ m +pos n ≡[ i ]⟨ sucPred m (~ i) + pos n ⟩ (sucℤ (predℤ m)) +pos n ≡⟨ sym (sucℤ+pos n (predℤ m))⟩ (predℤ m) +pos (suc n) ∎ predℤ-pos : ∀ n → predℤ(- (pos n)) ≡ negsuc n predℤ-pos zero = refl predℤ-pos (suc n) = refl predℤ+ : ∀ m n → predℤ (m + n) ≡ (predℤ m) + n predℤ+ m (pos n) = predℤ+pos n m predℤ+ m (negsuc n) = predℤ+negsuc n m +predℤ : ∀ m n → predℤ (m + n) ≡ m + (predℤ n) +predℤ m (pos zero) = refl +predℤ m (pos (suc n)) = (predSuc (m + pos n)) ∙ (cong (_+_ m) (sym (predSuc (pos n)))) +predℤ m (negsuc n) = refl sucℤ+ : ∀ m n → sucℤ (m + n) ≡ (sucℤ m) + n sucℤ+ m (pos n) = sucℤ+pos n m sucℤ+ m (negsuc n) = sucℤ+negsuc n m +sucℤ : ∀ m n → sucℤ (m + n) ≡ m + (sucℤ n) +sucℤ m (pos n) = refl +sucℤ m (negsuc zero) = sucPred _ +sucℤ m (negsuc (suc n)) = (sucPred (m +negsuc n)) ∙ (cong (_+_ m) (sym (sucPred (negsuc n)))) pos0+ : ∀ z → z ≡ pos 0 + z pos0+ (pos zero) = refl pos0+ (pos (suc n)) = cong sucℤ (pos0+ (pos n)) pos0+ (negsuc zero) = refl pos0+ (negsuc (suc n)) = cong predℤ (pos0+ (negsuc n)) negsuc0+ : ∀ z → predℤ z ≡ negsuc 0 + z negsuc0+ (pos zero) = refl negsuc0+ (pos (suc n)) = (sym (sucPred (pos n))) ∙ (cong sucℤ (negsuc0+ _)) negsuc0+ (negsuc zero) = refl negsuc0+ (negsuc (suc n)) = cong predℤ (negsuc0+ (negsuc n)) ind-comm : {A : Type₀} (_∙_ : A → A → A) (f : ℕ → A) (g : A → A) (p : ∀ {n} → f (suc n) ≡ g (f n)) (g∙ : ∀ a b → g (a ∙ b) ≡ g a ∙ b) (∙g : ∀ a b → g (a ∙ b) ≡ a ∙ g b) (base : ∀ z → z ∙ f 0 ≡ f 0 ∙ z) → ∀ z n → z ∙ f n ≡ f n ∙ z ind-comm _∙_ f g p g∙ ∙g base z 0 = base z ind-comm _∙_ f g p g∙ ∙g base z (suc n) = z ∙ f (suc n) ≡[ i ]⟨ z ∙ p {n} i ⟩ z ∙ g (f n) ≡⟨ sym ( ∙g z (f n)) ⟩ g (z ∙ f n) ≡⟨ cong g IH ⟩ g (f n ∙ z) ≡⟨ g∙ (f n) z ⟩ g (f n) ∙ z ≡[ i ]⟨ p {n} (~ i) ∙ z ⟩ f (suc n) ∙ z ∎ where IH = ind-comm _∙_ f g p g∙ ∙g base z n ind-assoc : {A : Type₀} (_·_ : A → A → A) (f : ℕ → A) (g : A → A) (p : ∀ a b → g (a · b) ≡ a · (g b)) (q : ∀ {c} → f (suc c) ≡ g (f c)) (base : ∀ m n → (m · n) · (f 0) ≡ m · (n · (f 0))) (m n : A) (o : ℕ) → m · (n · (f o)) ≡ (m · n) · (f o) ind-assoc _·_ f g p q base m n 0 = sym (base m n) ind-assoc _·_ f g p q base m n (suc o) = m · (n · (f (suc o))) ≡[ i ]⟨ m · (n · q {o} i) ⟩ m · (n · (g (f o))) ≡[ i ]⟨ m · (p n (f o) (~ i)) ⟩ m · (g (n · (f o))) ≡⟨ sym (p m (n · (f o)))⟩ g (m · (n · (f o))) ≡⟨ cong g IH ⟩ g ((m · n) · (f o)) ≡⟨ p (m · n) (f o) ⟩ (m · n) · (g (f o)) ≡[ i ]⟨ (m · n) · q {o} (~ i) ⟩ (m · n) · (f (suc o)) ∎ where IH = ind-assoc _·_ f g p q base m n o +Comm : ∀ m n → m + n ≡ n + m +Comm m (pos n) = ind-comm _+_ pos sucℤ refl sucℤ+ +sucℤ pos0+ m n +Comm m (negsuc n) = ind-comm _+_ negsuc predℤ refl predℤ+ +predℤ negsuc0+ m n +Assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o +Assoc m n (pos o) = ind-assoc _+_ pos sucℤ +sucℤ refl (λ _ _ → refl) m n o +Assoc m n (negsuc o) = ind-assoc _+_ negsuc predℤ +predℤ refl +predℤ m n o -- Compose sucPathℤ with itself n times. Transporting along this -- will be addition, transporting with it backwards will be subtraction. -- Use this to define _+'_ for which is easier to prove -- isEquiv (λ n → n +' m) since _+'_ is defined by transport sucPathℤ : ℤ ≡ ℤ sucPathℤ = ua (sucℤ , isoToIsEquiv (iso sucℤ predℤ sucPred predSuc)) addEq : ℕ → ℤ ≡ ℤ addEq zero = refl addEq (suc n) = (addEq n) ∙ sucPathℤ predPathℤ : ℤ ≡ ℤ predPathℤ = ua (predℤ , isoToIsEquiv (iso predℤ sucℤ predSuc sucPred)) subEq : ℕ → ℤ ≡ ℤ subEq zero = refl subEq (suc n) = (subEq n) ∙ predPathℤ _+'_ : ℤ → ℤ → ℤ m +' pos n = transport (addEq n) m m +' negsuc n = transport (subEq (suc n)) m +'≡+ : _+'_ ≡ _+_ +'≡+ i m (pos zero) = m +'≡+ i m (pos (suc n)) = sucℤ (+'≡+ i m (pos n)) +'≡+ i m (negsuc zero) = predℤ m +'≡+ i m (negsuc (suc n)) = predℤ (+'≡+ i m (negsuc n)) -- -- compPath (λ i → (+'≡+ i (predℤ m) (negsuc n))) (sym (predℤ+negsuc n m)) i isEquivAddℤ' : (m : ℤ) → isEquiv (λ n → n +' m) isEquivAddℤ' (pos n) = isEquivTransport (addEq n) isEquivAddℤ' (negsuc n) = isEquivTransport (subEq (suc n)) isEquivAddℤ : (m : ℤ) → isEquiv (λ n → n + m) isEquivAddℤ = subst (λ add → (m : ℤ) → isEquiv (λ n → add n m)) +'≡+ isEquivAddℤ' -- below is an alternate proof of isEquivAddℤ for comparison -- We also have two useful lemma here. minusPlus : ∀ m n → (n - m) + m ≡ n minusPlus (pos zero) n = refl minusPlus (pos 1) = sucPred minusPlus (pos (suc (suc m))) n = sucℤ ((n +negsuc (suc m)) +pos (suc m)) ≡⟨ sucℤ+pos (suc m) _ ⟩ sucℤ (n +negsuc (suc m)) +pos (suc m) ≡[ i ]⟨ sucPred (n +negsuc m) i +pos (suc m) ⟩ (n - pos (suc m)) +pos (suc m) ≡⟨ minusPlus (pos (suc m)) n ⟩ n ∎ minusPlus (negsuc zero) = predSuc minusPlus (negsuc (suc m)) n = predℤ (sucℤ (sucℤ (n +pos m)) +negsuc m) ≡⟨ predℤ+negsuc m _ ⟩ predℤ (sucℤ (sucℤ (n +pos m))) +negsuc m ≡[ i ]⟨ predSuc (sucℤ (n +pos m)) i +negsuc m ⟩ sucℤ (n +pos m) +negsuc m ≡⟨ minusPlus (negsuc m) n ⟩ n ∎ -≡0 : (m n : ℤ) → m - n ≡ 0 → m ≡ n -≡0 m n p = sym (subst (λ a → a + n ≡ m) p (minusPlus n m)) ∙ +Comm 0 n plusMinus : ∀ m n → (n + m) - m ≡ n plusMinus (pos zero) n = refl plusMinus (pos (suc m)) = minusPlus (negsuc m) plusMinus (negsuc m) = minusPlus (pos (suc m)) private alternateProof : (m : ℤ) → isEquiv (λ n → n + m) alternateProof m = isoToIsEquiv (iso (λ n → n + m) (λ n → n - m) (minusPlus m) (plusMinus m)) -Cancel : ∀ z → z - z ≡ 0 -Cancel z = cong (_- z) (pos0+ z) ∙ plusMinus z (pos zero) -Cancel' : ∀ z → - z + z ≡ 0 -Cancel' z = +Comm (- z) z ∙ -Cancel z pos+ : ∀ m n → pos (m +ℕ n) ≡ pos m + pos n pos+ zero zero = refl pos+ zero (suc n) = pos (zero +ℕ suc n) ≡⟨ +Comm (pos (suc n)) (pos zero) ⟩ pos zero + pos (suc n) ∎ pos+ (suc m) zero = pos (suc (m +ℕ zero)) ≡⟨ cong pos (cong suc (+-zero m)) ⟩ pos (suc m) + pos zero ∎ pos+ (suc m) (suc n) = pos (suc m +ℕ suc n) ≡⟨ cong pos (cong suc (+-suc m n)) ⟩ sucℤ (pos (suc (m +ℕ n))) ≡⟨ cong sucℤ (cong sucℤ (pos+ m n)) ⟩ sucℤ (sucℤ (pos m + pos n)) ≡⟨ sucℤ+ (pos m) (sucℤ (pos n)) ⟩ pos (suc m) + pos (suc n) ∎ negsuc+ : ∀ m n → negsuc (m +ℕ n) ≡ negsuc m - pos n negsuc+ zero zero = refl negsuc+ zero (suc n) = negsuc (zero +ℕ suc n) ≡⟨ negsuc0+ (negsuc n) ⟩ negsuc zero + negsuc n ≡⟨ cong (negsuc zero +_) (-pos (suc n)) ⟩ negsuc zero - pos (suc n) ∎ negsuc+ (suc m) zero = negsuc (suc m +ℕ zero) ≡⟨ cong negsuc (cong suc (+-zero m)) ⟩ negsuc (suc m) - pos zero ∎ negsuc+ (suc m) (suc n) = negsuc (suc m +ℕ suc n) ≡⟨ cong negsuc (sym (+-suc m (suc n))) ⟩ negsuc (m +ℕ suc (suc n)) ≡⟨ negsuc+ m (suc (suc n)) ⟩ negsuc m - pos (suc (suc n)) ≡⟨ sym (+predℤ (negsuc m) (negsuc n)) ⟩ predℤ (negsuc m + negsuc n ) ≡⟨ predℤ+ (negsuc m) (negsuc n) ⟩ negsuc (suc m) - pos (suc n) ∎ neg+ : ∀ m n → neg (m +ℕ n) ≡ neg m + neg n neg+ zero zero = refl neg+ zero (suc n) = neg (zero +ℕ suc n) ≡⟨ +Comm (neg (suc n)) (pos zero) ⟩ neg zero + neg (suc n) ∎ neg+ (suc m) zero = neg (suc (m +ℕ zero)) ≡⟨ cong neg (cong suc (+-zero m)) ⟩ neg (suc m) + neg zero ∎ neg+ (suc m) (suc n) = neg (suc m +ℕ suc n) ≡⟨ negsuc+ m (suc n) ⟩ neg (suc m) + neg (suc n) ∎ ℕ-AntiComm : ∀ m n → m ℕ- n ≡ - (n ℕ- m) ℕ-AntiComm zero zero = refl ℕ-AntiComm zero (suc n) = refl ℕ-AntiComm (suc m) zero = refl ℕ-AntiComm (suc m) (suc n) = suc m ℕ- suc n ≡⟨ ℕ-AntiComm m n ⟩ - (suc n ℕ- suc m) ∎ pos- : ∀ m n → m ℕ- n ≡ pos m - pos n pos- zero zero = refl pos- zero (suc n) = zero ℕ- suc n ≡⟨ +Comm (negsuc n) (pos zero) ⟩ pos zero - pos (suc n) ∎ pos- (suc m) zero = refl pos- (suc m) (suc n) = suc m ℕ- suc n ≡⟨ pos- m n ⟩ pos m - pos n ≡⟨ sym (sucPred (pos m - pos n)) ⟩ sucℤ (predℤ (pos m - pos n)) ≡⟨ cong sucℤ (+predℤ (pos m) (- pos n)) ⟩ sucℤ (pos m + predℤ (- (pos n))) ≡⟨ cong sucℤ (cong (pos m +_) (predℤ-pos n)) ⟩ sucℤ (pos m + negsuc n) ≡⟨ sucℤ+negsuc n (pos m) ⟩ pos (suc m) - pos (suc n) ∎ -AntiComm : ∀ m n → m - n ≡ - (n - m) -AntiComm (pos n) (pos m) = pos n - pos m ≡⟨ sym (pos- n m) ⟩ n ℕ- m ≡⟨ ℕ-AntiComm n m ⟩ - (m ℕ- n) ≡⟨ cong -_ (pos- m n) ⟩ - (pos m - pos n) ∎ -AntiComm (pos n) (negsuc m) = pos n - negsuc m ≡⟨ +Comm (pos n) (pos (suc m)) ⟩ pos (suc m) + pos n ≡⟨ sym (pos+ (suc m) n) ⟩ pos (suc m +ℕ n) ≡⟨ sym (-neg (suc m +ℕ n)) ⟩ - neg (suc m +ℕ n) ≡⟨ cong -_ (neg+ (suc m) n) ⟩ - (neg (suc m) + neg n) ≡⟨ cong -_ (cong (negsuc m +_) (sym (-pos n))) ⟩ - (negsuc m - pos n) ∎ -AntiComm (negsuc n) (pos m) = negsuc n - pos m ≡⟨ sym (negsuc+ n m) ⟩ negsuc (n +ℕ m) ≡⟨ cong -_ (pos+ (suc n) m) ⟩ - (pos (suc n) + pos m) ≡⟨ cong -_ (+Comm (pos (suc n)) (pos m)) ⟩ - (pos m - negsuc n) ∎ -AntiComm (negsuc n) (negsuc m) = negsuc n - negsuc m ≡⟨ +Comm (negsuc n) (pos (suc m)) ⟩ pos (suc m) + negsuc n ≡⟨ sym (pos- (suc m) (suc n)) ⟩ suc m ℕ- suc n ≡⟨ ℕ-AntiComm (suc m) (suc n) ⟩ - (suc n ℕ- suc m) ≡⟨ cong -_ (pos- (suc n) (suc m)) ⟩ - (pos (suc n) - pos (suc m)) ≡⟨ cong -_ (+Comm (pos (suc n)) (negsuc m)) ⟩ - (negsuc m - negsuc n) ∎ -Dist+ : ∀ m n → - (m + n) ≡ (- m) + (- n) -Dist+ (pos n) (pos m) = - (pos n + pos m) ≡⟨ cong -_ (sym (pos+ n m)) ⟩ - pos (n +ℕ m) ≡⟨ -pos (n +ℕ m) ⟩ neg (n +ℕ m) ≡⟨ neg+ n m ⟩ neg n + neg m ≡⟨ cong (neg n +_) (sym (-pos m)) ⟩ neg n + (- pos m) ≡⟨ cong (_+ (- pos m)) (sym (-pos n)) ⟩ (- pos n) + (- pos m) ∎ -Dist+ (pos n) (negsuc m) = - (pos n + negsuc m) ≡⟨ sym (-AntiComm (pos (suc m)) (pos n)) ⟩ pos (suc m) - pos n ≡⟨ +Comm (pos (suc m)) (- pos n) ⟩ (- pos n) + (- negsuc m) ∎ -Dist+ (negsuc n) (pos m) = - (negsuc n + pos m) ≡⟨ cong -_ (+Comm (negsuc n) (pos m)) ⟩ - (pos m + negsuc n) ≡⟨ sym (-AntiComm (- negsuc n) (pos m)) ⟩ (- negsuc n) + (- pos m) ∎ -Dist+ (negsuc n) (negsuc m) = - (negsuc n + negsuc m) ≡⟨ cong -_ (sym (neg+ (suc n) (suc m))) ⟩ - neg (suc n +ℕ suc m) ≡⟨ pos+ (suc n) (suc m) ⟩ (- negsuc n) + (- negsuc m) ∎ -- multiplication pos·pos : (n m : ℕ) → pos (n ·ℕ m) ≡ pos n · pos m pos·pos zero m = refl pos·pos (suc n) m = pos+ m (n ·ℕ m) ∙ cong (pos m +_) (pos·pos n m) pos·negsuc : (n m : ℕ) → pos n · negsuc m ≡ - (pos n · pos (suc m)) pos·negsuc zero m = refl pos·negsuc (suc n) m = (λ i → negsuc m + (pos·negsuc n m i)) ∙ sym (-Dist+ (pos (suc m)) (pos n · pos (suc m))) negsuc·pos : (n m : ℕ) → negsuc n · pos m ≡ - (pos (suc n) · pos m) negsuc·pos zero m = refl negsuc·pos (suc n) m = cong ((- pos m) +_) (negsuc·pos n m) ∙ sym (-Dist+ (pos m) (pos m + (pos n · pos m))) negsuc·negsuc : (n m : ℕ) → negsuc n · negsuc m ≡ pos (suc n) · pos (suc m) negsuc·negsuc zero m = refl negsuc·negsuc (suc n) m = cong (pos (suc m) +_) (negsuc·negsuc n m) ·Comm : (x y : ℤ) → x · y ≡ y · x ·Comm (pos n) (pos m) = lem n m where lem : (n m : ℕ) → (pos n · pos m) ≡ (pos m · pos n) lem zero zero = refl lem zero (suc m) i = +Comm (lem zero m i) (pos zero) i lem (suc n) zero i = +Comm (pos zero) (lem n zero i) i lem (suc n) (suc m) = (λ i → pos (suc m) + (lem n (suc m) i)) ∙∙ +Assoc (pos (suc m)) (pos n) (pos m · pos n) ∙∙ (λ i → sucℤ+ (pos m) (pos n) (~ i) + (pos m · pos n)) ∙∙ (λ i → +Comm (pos m) (pos (suc n)) i + (pos m · pos n)) ∙∙ sym (+Assoc (pos (suc n)) (pos m) (pos m · pos n)) ∙∙ (λ i → pos (suc n) + (pos m + (lem n m (~ i)))) ∙∙ λ i → pos (suc n) + (lem (suc n) m i) ·Comm (pos n) (negsuc m) = pos·negsuc n m ∙∙ cong -_ (·Comm (pos n) (pos (suc m))) ∙∙ sym (negsuc·pos m n) ·Comm (negsuc n) (pos m) = sym (pos·negsuc m n ∙∙ cong -_ (·Comm (pos m) (pos (suc n))) ∙∙ sym (negsuc·pos n m)) ·Comm (negsuc n) (negsuc m) = negsuc·negsuc n m ∙∙ ·Comm (pos (suc n)) (pos (suc m)) ∙∙ sym (negsuc·negsuc m n) ·Rid : (x : ℤ) → x · 1 ≡ x ·Rid x = ·Comm x 1 private distrHelper : (x y z w : ℤ) → (x + y) + (z + w) ≡ ((x + z) + (y + w)) distrHelper x y z w = +Assoc (x + y) z w ∙∙ cong (_+ w) (sym (+Assoc x y z) ∙∙ cong (x +_) (+Comm y z) ∙∙ +Assoc x z y) ∙∙ sym (+Assoc (x + z) y w) ·DistR+ : (x y z : ℤ) → x · (y + z) ≡ x · y + x · z ·DistR+ (pos zero) y z = refl ·DistR+ (pos (suc n)) y z = cong ((y + z) +_) (·DistR+ (pos n) y z) ∙ distrHelper y z (pos n · y) (pos n · z) ·DistR+ (negsuc zero) y z = -Dist+ y z ·DistR+ (negsuc (suc n)) y z = cong₂ _+_ (-Dist+ y z) (·DistR+ (negsuc n) y z) ∙ distrHelper (- y) (- z) (negsuc n · y) (negsuc n · z) ·DistL+ : (x y z : ℤ) → (x + y) · z ≡ x · z + y · z ·DistL+ x y z = ·Comm (x + y) z ∙∙ ·DistR+ z x y ∙∙ cong₂ _+_ (·Comm z x) (·Comm z y) -DistL· : (b c : ℤ) → - (b · c) ≡ - b · c -DistL· (pos zero) c = refl -DistL· (pos (suc n)) (pos m) = sym (negsuc·pos n m) -DistL· (pos (suc zero)) (negsuc m) = -Dist+ (negsuc m) (pos zero · negsuc m) ∙ cong (pos (suc m) +_) (-DistL· (pos zero) (negsuc m)) -DistL· (pos (suc (suc n))) (negsuc m) = -Dist+ (negsuc m) (pos (suc n) · negsuc m) ∙ cong (pos (suc m) +_) (-DistL· (pos (suc n)) (negsuc m)) -DistL· (negsuc zero) c = -Involutive c -DistL· (negsuc (suc n)) c = -Dist+ (- c) (negsuc n · c) ∙∙ cong (_+ (- (negsuc n · c))) (-Involutive c) ∙∙ cong (c +_) (-DistL· (negsuc n) c) -DistR· : (b c : ℤ) → - (b · c) ≡ b · - c -DistR· b c = cong (-_) (·Comm b c) ∙∙ -DistL· c b ∙∙ ·Comm (- c) b -DistLR· : (b c : ℤ) → b · c ≡ - b · - c -DistLR· b c = sym (-Involutive (b · c)) ∙ (λ i → - -DistL· b c i) ∙ -DistR· (- b) c ℤ·negsuc : (n : ℤ) (m : ℕ) → n · negsuc m ≡ - (n · pos (suc m)) ℤ·negsuc (pos n) m = pos·negsuc n m ℤ·negsuc (negsuc n) m = negsuc·negsuc n m ∙ sym (-DistL· (negsuc n) (pos (suc m))) ·Assoc : (a b c : ℤ) → (a · (b · c)) ≡ ((a · b) · c) ·Assoc (pos zero) b c = refl ·Assoc (pos (suc n)) b c = cong ((b · c) +_) (·Assoc (pos n) b c) ∙∙ cong₂ _+_ (·Comm b c) (·Comm (pos n · b) c) ∙∙ sym (·DistR+ c b (pos n · b)) ∙ sym (·Comm _ c) ·Assoc (negsuc zero) = -DistL· ·Assoc (negsuc (suc n)) b c = cong ((- (b · c)) +_) (·Assoc (negsuc n) b c) ∙∙ cong (_+ ((negsuc n · b) · c)) (-DistL· b c) ∙∙ sym (·DistL+ (- b) (negsuc n · b) c) minus≡0- : (x : ℤ) → - x ≡ (0 - x) minus≡0- x = +Comm (- x) 0 -- Absolute values abs→⊎ : (x : ℤ) (n : ℕ) → abs x ≡ n → (x ≡ pos n) ⊎ (x ≡ - pos n) abs→⊎ x n = J (λ n _ → (x ≡ pos n) ⊎ (x ≡ - pos n)) (help x) where help : (x : ℤ) → (x ≡ pos (abs x)) ⊎ (x ≡ - pos (abs x)) help (pos n) = inl refl help (negsuc n) = inr refl ⊎→abs : (x : ℤ) (n : ℕ) → (x ≡ pos n) ⊎ (x ≡ - pos n) → abs x ≡ n ⊎→abs (pos n₁) n (inl x₁) = cong abs x₁ ⊎→abs (negsuc n₁) n (inl x₁) = cong abs x₁ ⊎→abs x zero (inr x₁) = cong abs x₁ ⊎→abs x (suc n) (inr x₁) = cong abs x₁ abs≡0 : (x : ℤ) → abs x ≡ 0 → x ≡ 0 abs≡0 x p = case (abs→⊎ x 0 p) return (λ _ → x ≡ 0) of λ { (inl r) → r ; (inr r) → r } ¬x≡0→¬abs≡0 : {x : ℤ} → ¬ x ≡ 0 → ¬ abs x ≡ 0 ¬x≡0→¬abs≡0 p q = p (abs≡0 _ q) abs- : (x : ℤ) → abs (- x) ≡ abs x abs- (pos zero) = refl abs- (pos (suc n)) = refl abs- (negsuc n) = refl absPos·Pos : (m n : ℕ) → abs (pos m · pos n) ≡ abs (pos m) ·ℕ abs (pos n) absPos·Pos m n i = abs (pos·pos m n (~ i)) abs· : (m n : ℤ) → abs (m · n) ≡ abs m ·ℕ abs n abs· (pos m) (pos n) = absPos·Pos m n abs· (pos m) (negsuc n) = cong abs (pos·negsuc m n) ∙ abs- (pos m · pos (suc n)) ∙ absPos·Pos m (suc n) abs· (negsuc m) (pos n) = cong abs (negsuc·pos m n) ∙ abs- (pos (suc m) · pos n) ∙ absPos·Pos (suc m) n abs· (negsuc m) (negsuc n) = cong abs (negsuc·negsuc m n) ∙ absPos·Pos (suc m) (suc n) -- ℤ is integral domain isIntegralℤPosPos : (c m : ℕ) → pos c · pos m ≡ 0 → ¬ c ≡ 0 → m ≡ 0 isIntegralℤPosPos 0 m _ q = Empty.rec (q refl) isIntegralℤPosPos (suc c) m p _ = sym (0≡n·sm→0≡n {n = m} {m = c} (sym (injPos (pos·pos (suc c) m ∙ p)) ∙ ·ℕ-comm (suc c) m)) isIntegralℤ : (c m : ℤ) → c · m ≡ 0 → ¬ c ≡ 0 → m ≡ 0 isIntegralℤ (pos c) (pos m) p h i = pos (isIntegralℤPosPos c m p (λ r → h (cong pos r)) i) isIntegralℤ (pos c) (negsuc m) p h = Empty.rec (snotz (isIntegralℤPosPos c (suc m) (sym (-Involutive _) ∙ cong (-_) (sym (pos·negsuc c m) ∙ p)) (λ r → h (cong pos r)))) isIntegralℤ (negsuc c) (pos m) p _ i = pos (isIntegralℤPosPos (suc c) m (sym (-Involutive _) ∙ cong (-_) (sym (negsuc·pos c m) ∙ p)) snotz i) isIntegralℤ (negsuc c) (negsuc m) p _ = Empty.rec (snotz (isIntegralℤPosPos (suc c) (suc m) (sym (negsuc·negsuc c m) ∙ p) snotz)) private ·lCancel-helper : (c m n : ℤ) → c · m ≡ c · n → c · (m - n) ≡ 0 ·lCancel-helper c m n p = ·DistR+ c m (- n) ∙ (λ i → c · m + -DistR· c n (~ i)) ∙ subst (λ a → c · m - a ≡ 0) p (-Cancel (c · m)) ·lCancel : (c m n : ℤ) → c · m ≡ c · n → ¬ c ≡ 0 → m ≡ n ·lCancel c m n p h = -≡0 _ _ (isIntegralℤ c (m - n) (·lCancel-helper c m n p) h) ·rCancel : (c m n : ℤ) → m · c ≡ n · c → ¬ c ≡ 0 → m ≡ n ·rCancel c m n p h = ·lCancel c m n (·Comm c m ∙ p ∙ ·Comm n c) h
36.972973
94
0.502242
4ed3df28736257727b9e37c92ef3bba3df79094a
775
agda
Agda
test/fail/IrrelevantFamilyIndex.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/fail/IrrelevantFamilyIndex.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/IrrelevantFamilyIndex.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
-- Andreas, 2011-04-07 module IrrelevantFamilyIndex where data Nat : Set where zero : Nat suc : Nat -> Nat -- irrelevant index data Fin : .Nat -> Set where zero : .(n : Nat) -> Fin (suc n) suc : .(n : Nat) -> Fin n -> Fin (suc n) t : Fin zero t = zero zero -- the following is ok, since Fin _ is really just Nat toNat : Fin zero -> Nat toNat (zero _) = zero toNat (suc _ i) = suc (toNat i) data Pos : Nat -> Set where pos : (n : Nat) -> Pos (suc n) f : (n : Nat) -> Fin n -> Pos n f .(suc n) (zero n) = pos n f .(suc n) (suc n i) = pos n -- cannot infer value of dot pattern {- f : (n : Nat) -> Fin n -> Pos n f .(suc _) (zero _) = pos _ f .(suc _) (suc _ _) = pos _ f' : (n : Nat) -> Fin n -> Pos n f' _ (zero _) = pos _ f' _ (suc _ _) = pos _ -}
18.902439
54
0.549677
3f4b5c7568497536b0f378c24ec85855721c71ce
2,548
agda
Agda
agda-stdlib/src/Data/Float/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Float/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Float/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 of operations on floats ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Float.Properties where open import Data.Bool.Base as Bool using (Bool) open import Data.Float.Base import Data.Word.Base as Word import Data.Word.Properties as Wₚ open import Relation.Nullary.Decidable as RN using (map′) open import Relation.Binary import Relation.Binary.Construct.On as On open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- Primitive properties open import Agda.Builtin.Float.Properties renaming (primFloatToWord64Injective to toWord-injective) public ------------------------------------------------------------------------ -- Properties of _≈_ ≈⇒≡ : _≈_ ⇒ _≡_ ≈⇒≡ eq = toWord-injective _ _ (Wₚ.≈⇒≡ eq) ≈-reflexive : _≡_ ⇒ _≈_ ≈-reflexive eq = Wₚ.≈-reflexive (cong toWord eq) ≈-refl : Reflexive _≈_ ≈-refl = refl ≈-sym : Symmetric _≈_ ≈-sym = sym ≈-trans : Transitive _≈_ ≈-trans = trans ≈-subst : ∀ {ℓ} → Substitutive _≈_ ℓ ≈-subst P x≈y p = subst P (≈⇒≡ x≈y) p infix 4 _≈?_ _≈?_ : Decidable _≈_ _≈?_ = On.decidable toWord Word._≈_ Wₚ._≈?_ ≈-isEquivalence : IsEquivalence _≈_ ≈-isEquivalence = record { refl = λ {i} → ≈-refl {i} ; sym = λ {i j} → ≈-sym {i} {j} ; trans = λ {i j k} → ≈-trans {i} {j} {k} } ≈-setoid : Setoid _ _ ≈-setoid = record { isEquivalence = ≈-isEquivalence } ≈-isDecEquivalence : IsDecEquivalence _≈_ ≈-isDecEquivalence = record { isEquivalence = ≈-isEquivalence ; _≟_ = _≈?_ } ≈-decSetoid : DecSetoid _ _ ≈-decSetoid = record { isDecEquivalence = ≈-isDecEquivalence } ------------------------------------------------------------------------ -- Properties of _≡_ infix 4 _≟_ _≟_ : DecidableEquality Float x ≟ y = map′ ≈⇒≡ ≈-reflexive (x ≈? y) ≡-setoid : Setoid _ _ ≡-setoid = setoid Float ≡-decSetoid : DecSetoid _ _ ≡-decSetoid = decSetoid _≟_ ------------------------------------------------------------------------ -- Boolean equality test. infix 4 _==_ _==_ : Float → Float → Bool w₁ == w₂ = RN.⌊ w₁ ≟ w₂ ⌋ ------------------------------------------------------------------------ -- Properties of _<_ infix 4 _<?_ _<?_ : Decidable _<_ _<?_ = On.decidable toWord Word._<_ Wₚ._<?_ <-strictTotalOrder-≈ : StrictTotalOrder _ _ _ <-strictTotalOrder-≈ = On.strictTotalOrder Wₚ.<-strictTotalOrder-≈ toWord
24.737864
73
0.532182
1454066955d175ed3b3a2f1f0214fc962096b2e1
325
agda
Agda
core/lib/Coinduction.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
core/lib/Coinduction.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
core/lib/Coinduction.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 lib.Base module lib.Coinduction where infix 100 ♯_ postulate -- Coinduction ∞ : ∀ {i} (A : Type i) → Type i ♯_ : ∀ {i} {A : Type i} → A → ∞ A ♭ : ∀ {i} {A : Type i} → ∞ A → A {-# BUILTIN INFINITY ∞ #-} {-# BUILTIN SHARP ♯_ #-} {-# BUILTIN FLAT ♭ #-}
19.117647
39
0.507692
146240fac0a8bec2b7d990182aaec3d8599ae5f5
385
agda
Agda
test/Succeed/Issue3655.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3655.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3655.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Primitive postulate F : (a : Level) → Set a → Set a P : (a : Level) (A : Set a) → F a A → Set a p : (a : Level) (A : Set a) (x : F a A) → P a A x Q : (a : Level) (A : Set a) → A → Set a variable a : Level A : Set a postulate q : (x : F _ A) → Q a _ (p a A x) q' : {a : Level} {A : Set a} (x : F a A) → Q a (P a A x) (p a A x) q' {a} {A} = q {a} {A}
20.263158
66
0.454545
8b92a9abd738adc9212e8f429c20ede9ff547d08
24,178
agda
Agda
src/FOmegaInt/Kinding/Canonical/Equivalence.agda
Blaisorblade/f-omega-int-agda
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
[ "MIT" ]
12
2017-06-13T16:05:35.000Z
2021-09-27T05:53:06.000Z
src/FOmegaInt/Kinding/Canonical/Equivalence.agda
Blaisorblade/f-omega-int-agda
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
[ "MIT" ]
1
2021-05-14T08:09:40.000Z
2021-05-14T08:54:39.000Z
src/FOmegaInt/Kinding/Canonical/Equivalence.agda
Blaisorblade/f-omega-int-agda
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
[ "MIT" ]
2
2021-05-13T22:29:48.000Z
2021-05-14T10:25:05.000Z
------------------------------------------------------------------------ -- Equivalence of declarative and canonical kinding of Fω with -- interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module FOmegaInt.Kinding.Canonical.Equivalence where open import Data.Fin using (zero) open import Data.Fin.Substitution using (module VarSubst) open import Data.Fin.Substitution.Typed open import Data.Product as Prod using (_,_; proj₁; proj₂) open import Data.Vec using ([]) open import Function using (_∘_) open import Relation.Binary.PropositionalEquality hiding ([_]) open import FOmegaInt.Syntax open import FOmegaInt.Syntax.HereditarySubstitution open import FOmegaInt.Syntax.Normalization open import FOmegaInt.Syntax.WeakEquality import FOmegaInt.Typing as Original import FOmegaInt.Typing.Validity as OriginalValidity import FOmegaInt.Kinding.Declarative as Extended import FOmegaInt.Kinding.Declarative.Validity as ExtendedValidity import FOmegaInt.Kinding.Declarative.Equivalence as ExtendedEquiv import FOmegaInt.Kinding.Declarative.Normalization as OriginalNorm open import FOmegaInt.Kinding.Canonical as Canonical open import FOmegaInt.Kinding.Canonical.Validity open import FOmegaInt.Kinding.Canonical.WeakEquality import FOmegaInt.Kinding.Simple as SimpKind import FOmegaInt.Kinding.Simple.EtaExpansion as SimpEtaExp open import FOmegaInt.Kinding.Simple.Normalization private -- Original declarative rules and lemmas. module O where open Original public open Typing public open TermCtx public open TypedSubstitution public open OriginalValidity public open OriginalNorm public -- Extended declarative rules and lemmas. module E where open Extended public open Extended.Kinding public open TermCtx public open KindedSubstitution public open ExtendedValidity public open ExtendedEquiv public -- Canonical rules and lemmas. module C where open Canonical public open Kinding public open ElimCtx public open Syntax open Substitution using (_Kind[_]) open ElimCtx open SimpleCtx using (kd) open ContextConversions open WeakEqNormalization open Kinding open KindedRenaming open ContextNarrowing open Original.Typing hiding (_ctx; _⊢_wf; _⊢_kd; _⊢_<∷_; _⊢_<:_∈_; _⊢_≅_) open Extended.Kinding hiding (_ctx; _⊢_wf; _⊢_kd; _⊢_<∷_; _⊢_<:_∈_; _⊢_≅_) ------------------------------------------------------------------------ -- Soundness of canonical (sub)kinding w.r.t. declarative (sub)kinding mutual sound-wf : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ a wf → ⌞ Γ ⌟Ctx O.⊢ ⌞ a ⌟Asc wf sound-wf (wf-kd k-kd) = wf-kd (sound-kd k-kd) sound-wf (wf-tp a⇉a⋯a) = wf-tp (O.Tp∈-⋯-* (sound-Nf⇉ a⇉a⋯a)) sound-ctx : ∀ {n} {Γ : Ctx n} → Γ ctx → ⌞ Γ ⌟Ctx O.ctx sound-ctx C.[] = O.[] sound-ctx (a-wf C.∷ Γ-ctx) = sound-wf a-wf O.∷ sound-ctx Γ-ctx sound-kd : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → ⌞ Γ ⌟Ctx O.⊢ ⌞ k ⌟Kd kd sound-kd (kd-⋯ a⇉a⋯a b⇉b⋯b) = kd-⋯ (O.Tp∈-⋯-* (sound-Nf⇉ a⇉a⋯a)) (O.Tp∈-⋯-* (sound-Nf⇉ b⇉b⋯b)) sound-kd (kd-Π j-kd k-kd) = kd-Π (sound-kd j-kd) (sound-kd k-kd) sound-Nf⇉ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → ⌞ Γ ⌟Ctx O.⊢Tp ⌞ a ⌟ ∈ ⌞ k ⌟Kd sound-Nf⇉ (⇉-⊥-f Γ-ctx) = ∈-s-i (∈-⊥-f (sound-ctx Γ-ctx)) sound-Nf⇉ (⇉-⊤-f Γ-ctx) = ∈-s-i (∈-⊤-f (sound-ctx Γ-ctx)) sound-Nf⇉ (⇉-∀-f k-kd a⇉a⋯a) = ∈-s-i (∈-∀-f (sound-kd k-kd) (O.Tp∈-⋯-* (sound-Nf⇉ a⇉a⋯a))) sound-Nf⇉ (⇉-→-f a⇉a⋯a b⇉b⋯b) = ∈-s-i (∈-→-f (O.Tp∈-⋯-* (sound-Nf⇉ a⇉a⋯a)) (O.Tp∈-⋯-* (sound-Nf⇉ b⇉b⋯b))) sound-Nf⇉ (⇉-Π-i j-kd a⇉k) = let ⌞a⌟∈⌞k⌟ = sound-Nf⇉ a⇉k in ∈-Π-i (sound-kd j-kd) ⌞a⌟∈⌞k⌟ sound-Nf⇉ (⇉-s-i a⇉b⋯c) = ∈-s-i (sound-Ne∈ a⇉b⋯c) sound-Ne∈ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Ne a ∈ k → ⌞ Γ ⌟Ctx O.⊢Tp ⌞ a ⌟ ∈ ⌞ k ⌟Kd sound-Ne∈ (∈-∙ x∈j j⇉as⇉k) = sound-Sp⇉ (sound-Var∈ x∈j) j⇉as⇉k sound-Sp⇉ : ∀ {n} {Γ : Ctx n} {a bs j k} → ⌞ Γ ⌟Ctx O.⊢Tp a ∈ ⌞ j ⌟Kd → Γ ⊢ j ⇉∙ bs ⇉ k → ⌞ Γ ⌟Ctx O.⊢Tp a ⌞∙⌟ ⌞ bs ⌟Sp ∈ ⌞ k ⌟Kd sound-Sp⇉ a∈⌞j⌟ ⇉-[] = a∈⌞j⌟ sound-Sp⇉ a∈⌞Πjk⌟ (⇉-∷ b⇇j j-kd k[b]⇉bs⇉l) with O.Tp∈-valid a∈⌞Πjk⌟ ... | (kd-Π ⌞j⌟-kd ⌞k⌟-kd) = let ⌞b⌟∈⌞j⌟ = sound-Nf⇇ b⇇j in sound-Sp⇉ (∈-⇑ (∈-Π-e a∈⌞Πjk⌟ ⌞b⌟∈⌞j⌟) (O.≅⇒<∷ (O.kd-⌞⌟-[]-≅ ⌞k⌟-kd ⌞b⌟∈⌞j⌟))) k[b]⇉bs⇉l sound-Nf⇇ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇇ k → ⌞ Γ ⌟Ctx O.⊢Tp ⌞ a ⌟ ∈ ⌞ k ⌟Kd sound-Nf⇇ (⇇-⇑ a⇉j j<∷k) = ∈-⇑ (sound-Nf⇉ a⇉j) (sound-<∷ j<∷k) sound-Var∈ : ∀ {n} {Γ : Ctx n} {x k} → Γ ⊢Var x ∈ k → ⌞ Γ ⌟Ctx O.⊢Tp var x ∈ ⌞ k ⌟Kd sound-Var∈ {_} {Γ} (⇉-var {k} x Γ-ctx Γ[x]≡kd-k) = ∈-var x (sound-ctx Γ-ctx) (begin TermCtx.lookup ⌞ Γ ⌟Ctx x ≡⟨ ⌞⌟Asc-lookup Γ x ⟩ ⌞ lookup Γ x ⌟Asc ≡⟨ cong ⌞_⌟Asc Γ[x]≡kd-k ⟩ kd ⌞ k ⌟Kd ∎) where open ≡-Reasoning open Substitution using (⌞⌟Asc-weaken) sound-Var∈ (⇇-⇑ x∈j j<∷k k-kd) = ∈-⇑ (sound-Var∈ x∈j) (sound-<∷ j<∷k) sound-<∷ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → ⌞ Γ ⌟Ctx O.⊢ ⌞ j ⌟Kd <∷ ⌞ k ⌟Kd sound-<∷ (<∷-⋯ a₂<:a₁ b₁<:b₂) = <∷-⋯ (sound-<: a₂<:a₁) (sound-<: b₁<:b₂) sound-<∷ (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) = <∷-Π (sound-<∷ j₂<∷j₁) (sound-<∷ k₁<∷k₂) (sound-kd Πj₁k₁-kd) sound-<: : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a <: b → ⌞ Γ ⌟Ctx O.⊢ ⌞ a ⌟ <: ⌞ b ⌟ ∈ * sound-<: (<:-trans a<:b b<:c) = <:-trans (sound-<: a<:b) (sound-<: b<:c) sound-<: (<:-⊥ a⇉a⋯a) = <:-⊥ (O.Tp∈-⋯-* (sound-Nf⇉ a⇉a⋯a)) sound-<: (<:-⊤ a⇉a⋯a) = <:-⊤ (O.Tp∈-⋯-* (sound-Nf⇉ a⇉a⋯a)) sound-<: (<:-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁) = <:-∀ (sound-<∷ k₂<∷k₁) (sound-<: a₁<:a₂) (O.Tp∈-⋯-* (sound-Nf⇉ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁)) sound-<: (<:-→ a₂<:a₁ b₁<:b₂) = <:-→ (sound-<: a₂<:a₁) (sound-<: b₁<:b₂) sound-<: (<:-∙ x∈j j⇉as⇉k) = O.<:-⋯-* (sound-<:-∙-≃ (<:-refl (sound-Var∈ x∈j)) j⇉as⇉k) sound-<: (<:-⟨| a∈b⋯c) = <:-⟨| (sound-Ne∈ a∈b⋯c) sound-<: (<:-|⟩ a∈b⋯c) = <:-|⟩ (sound-Ne∈ a∈b⋯c) sound-<:⇇ : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ⇇ k → ⌞ Γ ⌟Ctx O.⊢ ⌞ a ⌟ <: ⌞ b ⌟ ∈ ⌞ k ⌟Kd sound-<:⇇ (<:-⇇ (⇇-⇑ a₁⇉c₁⋯d₁ (<∷-⋯ c₁<:c d<:d₁)) (⇇-⇑ a₂⇉c₂⋯d₂ (<∷-⋯ c₂<:c d<:d₂)) a<:b) with Nf⇉-≡ a₁⇉c₁⋯d₁ | Nf⇉-≡ a₂⇉c₂⋯d₂ sound-<:⇇ (<:-⇇ (⇇-⇑ a₁⇉a₁⋯a₁ (<∷-⋯ c<:a₁ _)) (⇇-⇑ a₂⇉a₂⋯a₂ (<∷-⋯ _ a₂<:d)) a<:b) | refl , refl | refl , refl = <:-⇑ (<:-⋯-i (sound-<: a<:b)) (<∷-⋯ (sound-<: c<:a₁) (sound-<: a₂<:d)) sound-<:⇇ (<:-λ a₁<:a₂⇇k Λj₁a₁⇇Πjk Λj₂a₂⇇Πjk) = <:-λ (sound-<:⇇ a₁<:a₂⇇k) (sound-Nf⇇ Λj₁a₁⇇Πjk) (sound-Nf⇇ Λj₂a₂⇇Πjk) sound-≅ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → ⌞ Γ ⌟Ctx O.⊢ ⌞ j ⌟Kd ≅ ⌞ k ⌟Kd sound-≅ (<∷-antisym _ _ j<∷k k<∷j) = <∷-antisym (sound-<∷ j<∷k) (sound-<∷ k<∷j) sound-≃ : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ⇇ k → ⌞ Γ ⌟Ctx O.⊢ ⌞ a ⌟ ≃ ⌞ b ⌟ ∈ ⌞ k ⌟Kd sound-≃ (<:-antisym k-kd a<:b⇇k b<:a⇇k) = <:-antisym (sound-<:⇇ a<:b⇇k) (sound-<:⇇ b<:a⇇k) sound-<:-∙-≃ : ∀ {n} {Γ : Ctx n} {a b as bs j k} → ⌞ Γ ⌟Ctx O.⊢ a <: b ∈ ⌞ j ⌟Kd → Γ ⊢ j ⇉∙ as ≃ bs ⇉ k → ⌞ Γ ⌟Ctx O.⊢ a ⌞∙⌟ ⌞ as ⌟Sp <: b ⌞∙⌟ ⌞ bs ⌟Sp ∈ ⌞ k ⌟Kd sound-<:-∙-≃ a<:b∈⌞j⌟ ≃-[] = a<:b∈⌞j⌟ sound-<:-∙-≃ a<:b∈⌞Πjk⌟ (≃-∷ c≃d⇇j k[c]⇉cs≃ds⇉l) with O.<:-valid-kd a<:b∈⌞Πjk⌟ ... | (kd-Π ⌞j⌟-kd ⌞k⌟-kd) = let ⌞c⌟≃⌞d⌟∈⌞j⌟ = sound-≃ c≃d⇇j ⌞c⌟∈⌞j⌟ , _ = O.≃-valid ⌞c⌟≃⌞d⌟∈⌞j⌟ in sound-<:-∙-≃ (<:-⇑ (<:-· a<:b∈⌞Πjk⌟ ⌞c⌟≃⌞d⌟∈⌞j⌟) (O.≅⇒<∷ (O.kd-⌞⌟-[]-≅ ⌞k⌟-kd ⌞c⌟∈⌞j⌟))) k[c]⇉cs≃ds⇉l ------------------------------------------------------------------------ -- Completeness of canonical (sub)kinding w.r.t. declarative -- (sub)kinding open Substitution hiding (subst) module TrackSimpleKindsCanonicalEtaExp where open RenamingCommutes open SimpHSubstLemmas private module V = VarSubst module TK = TrackSimpleKindsEtaExp module TKE = SimpEtaExp.TrackSimpleKindsKindedEtaExp -- Hereditary substitutions of a variable by its well-kinded -- η-expansion in well-formed kinds vanish. -- -- NOTE. We will strengthen this lemma below, once we have proven -- that η-expansion preserves canonical kinding. kd-[]-η-var : ∀ {k n} {Γ : Ctx n} {j l} → Γ ⊢ j kd → kd j ∷ Γ ⊢ l kd → let j′ = weakenKind′ j in (hyp : ⌊ j′ ⌋≡ k) → let η-z = TK.η-exp j′ hyp (var∙ zero) in kd j ∷ Γ ⊢Nf η-z ⇇ j′ → kd j ∷ Γ ⊢ (l Kind′/Var V.wk V.↑) Kind[ η-z ∈ ⌊ j′ ⌋ ] ≅ l kd-[]-η-var j-kd l-kd hyp η-z⇇j = let open TypedVarSubst typedVarSubst open SimpKind.Kinding using (_⊢_kds) open SimpleCtx using (kd) j-wf = wf-kd j-kd j-kd′ = kd-weaken j-wf j-kd ⌊j⌋≡k = trans (sym (⌊⌋-Kind′/Var _)) (⌊⌋≡⇒⌊⌋-≡ hyp) η-z = TK.η-exp _ hyp (var∙ zero) j-kds′ = subst (λ k → kd k ∷ _ ⊢ _ kds) ⌊j⌋≡k (kd-kds j-kd′) l-kds = subst (λ k → kd k ∷ _ ⊢ _ kds) ⌊j⌋≡k (kd-kds l-kd) l[z]≋l = TKE.kds-[]-η-var [] hyp j-kds′ l-kds wk↑∈j∷Γ = ∈-↑′ j-kd′ (∈-wk j-wf) l[z]-kd = kd-[] (kd-/Var l-kd wk↑∈j∷Γ) η-z⇇j in ≋-≅ l[z]-kd l-kd (subst (λ l → _ Kind[ η-z ∈ l ] ≋ _) (sym (⌊⌋≡⇒⌊⌋-≡ hyp)) l[z]≋l) -- NOTE. The definition of the function η-exp-Ne∈ below is -- structurally recursive in the *shape* parameter k, but *not* in -- the kind j because we need to weaken the domain j₁ of the -- dependent kind (j = Π j₁ j₂) in the arrow case. The additional -- hypothesis ⌊ j ⌋≡ k ensures that k is indeed the shape of the -- kind j. -- η-expansion preserves canonical kinding of neutral types. η-exp-Ne∈ : ∀ {n} {Γ : Ctx n} {a j k l} (hyp : ⌊ j ⌋≡ k) → Γ ⊢ j kd → Γ ⊢Ne a ∈ l → Γ ⊢ l <∷ j → Γ ⊢Nf TK.η-exp j hyp a ⇇ j η-exp-Ne∈ is-★ b₂⋯c₂-kd a∈b₁⋯c₁ (<∷-⋯ b₂<:b₁ c₁<:c₂) = Nf⇇-⇑ (Nf⇇-ne a∈b₁⋯c₁) (<∷-⋯ b₂<:b₁ c₁<:c₂) η-exp-Ne∈ (is-⇒ ⌊j₁⌋≡k₁ ⌊j₂⌋≡k₂) (kd-Π j₁-kd j₂-kd) (∈-∙ {x} {_} {_} {as} x∈l l⇉as∈Πl₁l₂) (<∷-Π j₁<∷l₁ l₂<∷j₂ (kd-Π l₁-kd l₂-kd)) = Nf⇇-Π-i j₁-kd (η-exp-Ne∈ ⌊j₂⌋≡k₂ j₂-kd x∙as·z∈l₂[z] l₂[z]<∷j₂) where open TypedVarSubst typedVarSubst j₁-wf = wf-kd j₁-kd j₁∷Γ-ctx = j₁-wf C.∷ Var∈-ctx x∈l j₁-kd′ = kd-weaken j₁-wf j₁-kd l₁-kd′ = kd-weaken j₁-wf l₁-kd ⌊j₁′⌋≡k₁ = ⌊⌋≡-weaken ⌊j₁⌋≡k₁ η-z = TK.η-exp _ ⌊j₁′⌋≡k₁ (var∙ zero) z⇇j₁ = η-exp-Ne∈ ⌊j₁′⌋≡k₁ j₁-kd′ (∈-∙ (⇉-var zero j₁∷Γ-ctx refl) ⇉-[]) (<∷-refl j₁-kd′) z⇇l₁ = Nf⇇-⇑ z⇇j₁ (<∷-weaken j₁-wf j₁<∷l₁) wk↑∈j₁∷Γ = ∈-↑′ j₁-kd′ (∈-wk j₁-wf) j₂[z]<∷j₂ = ≅⇒<∷ (kd-[]-η-var j₁-kd j₂-kd ⌊j₁′⌋≡k₁ z⇇j₁) l₂[z]<∷j₂[z] = <∷-[≃] (<∷-/Var l₂<∷j₂ wk↑∈j₁∷Γ) (≃-reflNf⇇ z⇇j₁ j₁-kd′) l₂[z]<∷j₂ = subst (λ l → _ ⊢ _ Kind[ η-z ∈ l ] <∷ _) (<∷-⌊⌋ (<∷-weaken j₁-wf j₁<∷l₁)) (<∷-trans l₂[z]<∷j₂[z] j₂[z]<∷j₂) x∙as·z∈l₂[z] = (∈-∙ (Var∈-weaken j₁-wf x∈l) (⇉-∷ʳ (Sp⇉-weaken j₁-wf l⇉as∈Πl₁l₂) z⇇l₁ l₁-kd′)) private module TK = TrackSimpleKindsCanonicalEtaExp -- η-expansion preserves canonical kinding of neutral types. η-exp-Ne∈ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢ k kd → Γ ⊢Ne a ∈ k → Γ ⊢Nf η-exp k a ⇇ k η-exp-Ne∈ k-kd a∈k = TK.η-exp-Ne∈ (⌊⌋-⌊⌋≡ _) k-kd a∈k (<∷-refl k-kd) η-exp-Var∈ : ∀ {n} {Γ : Ctx n} {x k} → Γ ⊢ k kd → Γ ⊢Var x ∈ k → Γ ⊢Nf η-exp k (var∙ x) ⇇ k η-exp-Var∈ k-kd x∈k = η-exp-Ne∈ k-kd (∈-∙ x∈k ⇉-[]) -- Hereditary substitutions in well-formed kinds of a variable by its -- η-expansion vanish. kd-[]-η-var : ∀ {n} {Γ : Ctx n} {j l} → Γ ⊢ j kd → kd j ∷ Γ ⊢ l kd → let j′ = weakenKind′ j l′ = l Kind′/Var VarSubst.wk VarSubst.↑ in kd j ∷ Γ ⊢ l′ Kind[ η-exp j′ (var∙ zero) ∈ ⌊ j′ ⌋ ] ≅ l kd-[]-η-var j-kd l-kd = let j-kd′ = kd-weaken (wf-kd j-kd) j-kd in TK.kd-[]-η-var j-kd l-kd (⌊⌋-⌊⌋≡ _) (η-exp-Var∈ j-kd′ (⇉-var zero (kd-ctx j-kd′) refl)) open RenamingCommutesNorm -- Completeness of canonical (sub)kinding w.r.t. extended declarative -- (sub)kinding module CompletenessExtended where mutual complete-wf : ∀ {n} {Γ : E.Ctx n} {a} → Γ E.⊢ a wf → nfCtx Γ ⊢ nfAsc (nfCtx Γ) a wf complete-wf (wf-kd k-kd) = wf-kd (complete-kd k-kd) complete-wf (wf-tp a∈*) = wf-tp (Nf⇇-s-i (complete-Tp∈ a∈*)) complete-ctx : ∀ {n} {Γ : E.Ctx n} → Γ E.ctx → nfCtx Γ ctx complete-ctx E.[] = C.[] complete-ctx (a-wf E.∷ Γ-ctx) = complete-wf a-wf C.∷ complete-ctx Γ-ctx complete-kd : ∀ {n} {Γ : E.Ctx n} {k} → Γ E.⊢ k kd → nfCtx Γ ⊢ nfKind (nfCtx Γ) k kd complete-kd (kd-⋯ a∈* b∈*) = kd-⋯ (Nf⇇-s-i (complete-Tp∈ a∈*)) (Nf⇇-s-i (complete-Tp∈ b∈*)) complete-kd (kd-Π j-kd k-kd) = kd-Π (complete-kd j-kd) (complete-kd k-kd) complete-Tp∈ : ∀ {n} {Γ : E.Ctx n} {a k} → Γ E.⊢Tp a ∈ k → nfCtx Γ ⊢Nf nf (nfCtx Γ) a ⇇ nfKind (nfCtx Γ) k complete-Tp∈ {_} {Γ} (∈-var x Γ-ctx Γ[x]≡kd-k) with C.lookup (nfCtx Γ) x | nfCtx-lookup-kd x Γ Γ[x]≡kd-k complete-Tp∈ {_} {Γ} (∈-var x Γ-ctx Γ[x]≡kd-k) | kd ._ | refl = η-exp-Var∈ (WfCtxOps.lookup-kd x nf-Γ-ctx nf-Γ[x]≡kd-nf-k) (⇉-var x nf-Γ-ctx nf-Γ[x]≡kd-nf-k) where nf-Γ-ctx = complete-ctx Γ-ctx nf-Γ[x]≡kd-nf-k = nfCtx-lookup-kd x Γ Γ[x]≡kd-k complete-Tp∈ (∈-⊥-f Γ-ctx) = Nf⇉-⋯-* (⇉-⊥-f (complete-ctx Γ-ctx)) complete-Tp∈ (∈-⊤-f Γ-ctx) = Nf⇉-⋯-* (⇉-⊤-f (complete-ctx Γ-ctx)) complete-Tp∈ (∈-∀-f k-kd a∈*) = Nf⇇-∀-f (complete-kd k-kd) (complete-Tp∈ a∈*) complete-Tp∈ (∈-→-f a∈* b∈*) = Nf⇇-→-f (complete-Tp∈ a∈*) (complete-Tp∈ b∈*) complete-Tp∈ (∈-Π-i j-kd a∈k k-kd) = Nf⇇-Π-i (complete-kd j-kd) (complete-Tp∈ a∈k) complete-Tp∈ (∈-Π-e {a} {b} a∈Πjk b∈j k-kd k[a]-kd) = Nf⇇-⇑ (Nf⇇-Π-e′ (complete-Tp∈ a∈Πjk) (complete-Tp∈ b∈j)) (≅⇒<∷ (≅-nfKind-[] k-kd b∈j k[a]-kd)) complete-Tp∈ (∈-s-i a∈b⋯c) = let nf-a⇉a⋯a = Nf⇇-s-i (complete-Tp∈ a∈b⋯c) in ⇇-⇑ nf-a⇉a⋯a (<∷-⋯ (<:-reflNf⇉ nf-a⇉a⋯a) (<:-reflNf⇉ nf-a⇉a⋯a)) complete-Tp∈ (∈-⇑ a∈j j<∷k) = Nf⇇-⇑ (complete-Tp∈ a∈j) (complete-<∷ j<∷k) complete-<∷ : ∀ {n} {Γ : E.Ctx n} {j k} → Γ E.⊢ j <∷ k → nfCtx Γ ⊢ nfKind (nfCtx Γ) j <∷ nfKind (nfCtx Γ) k complete-<∷ (<∷-⋯ a₂<:a₁ b₁<:b₂) = <∷-⋯ (complete-<:-⋯ a₂<:a₁) (complete-<:-⋯ b₁<:b₂) complete-<∷ (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) with complete-kd Πj₁k₁-kd ... | kd-Π nf-j₁-kd nf-k₁-kd = let nf-j₂<∷j₁ = complete-<∷ j₂<∷j₁ nf-k₁′<∷k₂ = complete-<∷ k₁<∷k₂ ⌊nf-j₁∷Γ⌋≡⌊nf-j₂∷Γ⌋ = cong (λ k → kd k ∷ _) (sym (<∷-⌊⌋ nf-j₂<∷j₁)) nf-k₁≋k₁′ = ≋-nfKind ⌊nf-j₁∷Γ⌋≡⌊nf-j₂∷Γ⌋ _ nf-j₂-kd = proj₁ (<∷-valid nf-j₂<∷j₁) nf-k₁′-kd = proj₁ (<∷-valid nf-k₁′<∷k₂) nf-k₁<∷k₁′ = ≋-<∷ (⇓-kd nf-j₂-kd nf-j₂<∷j₁ nf-k₁-kd) nf-k₁′-kd nf-k₁≋k₁′ nf-k₁<∷k₂ = <∷-trans nf-k₁<∷k₁′ nf-k₁′<∷k₂ in <∷-Π nf-j₂<∷j₁ nf-k₁<∷k₂ (kd-Π nf-j₁-kd nf-k₁-kd) complete-<:-⋯ : ∀ {n} {Γ : E.Ctx n} {a b c d} → Γ E.⊢ a <: b ∈ c ⋯ d → nfCtx Γ ⊢ nf (nfCtx Γ) a <: nf (nfCtx Γ) b complete-<:-⋯ a<:b∈c⋯d with complete-<: a<:b∈c⋯d complete-<:-⋯ a<:b∈c⋯d | <:-⇇ _ _ a<:b = a<:b complete-<: : ∀ {n} {Γ : E.Ctx n} {a b k} → Γ E.⊢ a <: b ∈ k → nfCtx Γ ⊢ nf (nfCtx Γ) a <: nf (nfCtx Γ) b ⇇ nfKind (nfCtx Γ) k complete-<: (<:-refl a∈k) = let nf-a∈k = complete-Tp∈ a∈k in <:⇇-reflNf⇇ nf-a∈k (Nf⇇-valid nf-a∈k) complete-<: (<:-trans a<:b b<:c) = <:⇇-trans (complete-<: a<:b) (complete-<: b<:c) complete-<: (<:-β₁ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) = ≃⇒<: (≃-β-nf a∈k b∈j k-kd a[b]∈k[b] k[b]-kd) complete-<: (<:-β₂ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) = ≃⇒<: (≃-sym (≃-β-nf a∈k b∈j k-kd a[b]∈k[b] k[b]-kd)) complete-<: (<:-η₁ a∈Πjk) = ≃⇒<: (≃-η-nf a∈Πjk) complete-<: (<:-η₂ a∈Πjk) = ≃⇒<: (≃-sym (≃-η-nf a∈Πjk)) complete-<: (<:-⊥ a∈b⋯c) = <:-⋯-* (<:-⊥ (Nf⇇-s-i (complete-Tp∈ a∈b⋯c))) complete-<: (<:-⊤ a∈b⋯c) = <:-⋯-* (<:-⊤ (Nf⇇-s-i (complete-Tp∈ a∈b⋯c))) complete-<: (<:-∀ {a₁ = a₁} k₂<∷k₁ a₁<:a₂ Πk₁a₁∈*) with complete-Tp∈ Πk₁a₁∈* ... | (⇇-⇑ (⇉-∀-f nf-k₁-kd nf-a₁⇉a₁⋯a₁) _) = let nf-k₂<∷k₁ = complete-<∷ k₂<∷k₁ nf-a₁′<:a₂ = complete-<:-⋯ a₁<:a₂ ⌊nf-k₁∷Γ⌋≡⌊nf-k₂∷Γ⌋ = cong (λ k → kd k ∷ _) (sym (<∷-⌊⌋ nf-k₂<∷k₁)) nf-a₁≈a₁′ = ≈-nf ⌊nf-k₁∷Γ⌋≡⌊nf-k₂∷Γ⌋ a₁ nf-k₂-kd = proj₁ (<∷-valid nf-k₂<∷k₁) nf-a₁⇉a₁⋯a₁′ = proj₁ (<:-valid nf-a₁′<:a₂) nf-a₁<:a₁′ = ≈-<: (⇓-Nf⇉ nf-k₂-kd nf-k₂<∷k₁ nf-a₁⇉a₁⋯a₁) nf-a₁⇉a₁⋯a₁′ nf-a₁≈a₁′ nf-a₁<:a₂ = <:-trans nf-a₁<:a₁′ nf-a₁′<:a₂ in <:-⋯-* (<:-∀ nf-k₂<∷k₁ nf-a₁<:a₂ (⇉-∀-f nf-k₁-kd nf-a₁⇉a₁⋯a₁)) ... | (⇇-⇑ (⇉-s-i ()) _) complete-<: (<:-→ a₂<:a₁ b₁<:b₂) = <:-⋯-* (<:-→ (complete-<:-⋯ a₂<:a₁) (complete-<:-⋯ b₁<:b₂)) complete-<: (<:-λ {a₁ = a₁} {a₂} a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) with complete-Tp∈ Λj₁a₁∈Πjk | complete-Tp∈ Λj₂a₂∈Πjk ... | ⇇-⇑ (⇉-Π-i nf-j₁-kd nf-a₁⇉k₁) (<∷-Π nf-j<∷j₁ nf-k₁<∷k Πj₁k₁-kd) | ⇇-⇑ (⇉-Π-i nf-j₂-kd nf-a₂⇉k₂) (<∷-Π nf-j<∷j₂ nf-k₂<∷k Πj₂k₂-kd) = let nf-a₁′<:a₂′⇇k = complete-<: a₁<:a₂∈k nf-a₁′⇇k , nf-a₂′⇇k = <:⇇-valid nf-a₁′<:a₂′⇇k j-kd = proj₁ (<∷-valid nf-j<∷j₁) k-kd = proj₂ (<∷-valid nf-k₁<∷k) ⌊nf-j₁∷Γ⌋≡⌊nf-j∷Γ⌋ = cong (λ k → kd k ∷ _) (sym (<∷-⌊⌋ nf-j<∷j₁)) ⌊nf-j∷Γ⌋≡⌊nf-j₂∷Γ⌋ = cong (λ k → kd k ∷ _) (<∷-⌊⌋ nf-j<∷j₂) nf-a₁≈a₁′ = ≈-nf ⌊nf-j₁∷Γ⌋≡⌊nf-j∷Γ⌋ a₁ nf-a₂′≈a₂ = ≈-nf ⌊nf-j∷Γ⌋≡⌊nf-j₂∷Γ⌋ a₂ nf-a₁<:a₁′⇇k = ≈-<:⇇ k-kd (⇇-⇑ (⇓-Nf⇉ j-kd nf-j<∷j₁ nf-a₁⇉k₁) nf-k₁<∷k) nf-a₁′⇇k nf-a₁≈a₁′ nf-a₂′<:a₂⇇k = ≈-<:⇇ k-kd nf-a₂′⇇k (⇇-⇑ (⇓-Nf⇉ j-kd nf-j<∷j₂ nf-a₂⇉k₂) nf-k₂<∷k) nf-a₂′≈a₂ nf-a₁<:a₂⇇k = <:⇇-trans (<:⇇-trans nf-a₁<:a₁′⇇k nf-a₁′<:a₂′⇇k) nf-a₂′<:a₂⇇k in <:-λ nf-a₁<:a₂⇇k (⇇-⇑ (⇉-Π-i nf-j₁-kd nf-a₁⇉k₁) (<∷-Π nf-j<∷j₁ nf-k₁<∷k Πj₁k₁-kd)) (⇇-⇑ (⇉-Π-i nf-j₂-kd nf-a₂⇉k₂) (<∷-Π nf-j<∷j₂ nf-k₂<∷k Πj₂k₂-kd)) ... | ⇇-⇑ (⇉-Π-i _ _) _ | ⇇-⇑ (⇉-s-i ()) _ ... | ⇇-⇑ (⇉-s-i ()) _ | _ complete-<: (<:-· {a₁} {a₂} {b₁} {b₂} a₁<:a₂∈Πjk b₁≃b₂∈j b₁∈j k-kd k[b₁]-kd) = let nf-a₁<:a₂⇇Πjk = complete-<: a₁<:a₂∈Πjk nf-a₁⇇Πjk , nf-a₂⇇Πjk = <:⇇-valid nf-a₁<:a₂⇇Πjk in <:⇇-⇑ (<:-↓⌜·⌝ nf-a₁<:a₂⇇Πjk (complete-≃ b₁≃b₂∈j)) (≅⇒<∷ (≅-nfKind-[] k-kd b₁∈j k[b₁]-kd)) (complete-kd k[b₁]-kd) complete-<: (<:-⟨| a∈b⋯c) = <:-⋯-* (<:-⟨|-Nf⇇ (complete-Tp∈ a∈b⋯c)) complete-<: (<:-|⟩ a∈b⋯c) = <:-⋯-* (<:-|⟩-Nf⇇ (complete-Tp∈ a∈b⋯c)) complete-<: (<:-⋯-i a<:b) = <:⇇-⋯-i (complete-<: a<:b) complete-<: (<:-⇑ a<:b∈j j<∷k) = let nf-j<∷k = complete-<∷ j<∷k in <:⇇-⇑ (complete-<: a<:b∈j) nf-j<∷k (proj₂ (<∷-valid nf-j<∷k)) complete-≅ : ∀ {n} {Γ : E.Ctx n} {j k} → Γ E.⊢ j ≅ k → nfCtx Γ ⊢ nfKind (nfCtx Γ) j ≅ nfKind (nfCtx Γ) k complete-≅ (<∷-antisym j<∷k k<∷j) = let nf-j<∷k = complete-<∷ j<∷k nf-j-kd , nf-k-kd = <∷-valid nf-j<∷k in <∷-antisym nf-j-kd nf-k-kd nf-j<∷k (complete-<∷ k<∷j) complete-≃ : ∀ {n} {Γ : E.Ctx n} {a b k} → Γ E.⊢ a ≃ b ∈ k → nfCtx Γ ⊢ nf (nfCtx Γ) a ≃ nf (nfCtx Γ) b ⇇ nfKind (nfCtx Γ) k complete-≃ (<:-antisym a<:b∈k b<:a∈k) = let nf-a<:b⇇k = complete-<: a<:b∈k in <:-antisym (<:⇇-valid-kd nf-a<:b⇇k) nf-a<:b⇇k (complete-<: b<:a∈k) -- η-expansion of normal forms is admissible in canonical kinding. ≃-η-nf : ∀ {n} {Γ : E.Ctx n} {a j k} → Γ E.⊢Tp a ∈ Π j k → nfCtx Γ ⊢ nf (nfCtx Γ) (Λ j (weaken a · var zero)) ≃ nf (nfCtx Γ) a ⇇ nfKind (nfCtx Γ) (Π j k) ≃-η-nf a∈Πjk with complete-Tp∈ a∈Πjk ≃-η-nf {_} {Γ} {a} {j} a∈Πjk | nf-a⇇Πjk with Nf⇇-valid nf-a⇇Πjk ... | (kd-Π nf-j-kd nf-k-kd) = let nf-Γ = nfCtx Γ nf-j = nfKind nf-Γ j nf-j-wf = wf-kd nf-j-kd nf-j-kd′ = kd-weaken nf-j-wf nf-j-kd nf-a⇇Πjk′ = subst (kd nf-j ∷ nf-Γ ⊢Nf_⇇ _) (nf-weaken (kd nf-j) a) (Nf⇇-weaken nf-j-wf nf-a⇇Πjk) η-z⇇j′ = η-exp-Var∈ nf-j-kd′ (⇉-var zero (kd-ctx nf-j-kd′) refl) nf-a·z⇇k[z] = Nf⇇-Π-e′ nf-a⇇Πjk′ η-z⇇j′ nf-a·z⇇k = Nf⇇-⇑ nf-a·z⇇k[z] (≅⇒<∷ (kd-[]-η-var nf-j-kd nf-k-kd)) in ≈-≃ (kd-Π nf-j-kd nf-k-kd) (Nf⇇-Π-i nf-j-kd nf-a·z⇇k) nf-a⇇Πjk (≈-η-nf a∈Πjk) -- Substitution in well-formed kinds commutes with normalization. ≅-nfKind-[] : ∀ {n} {Γ : E.Ctx n} {a j k} → kd k ∷ Γ E.⊢ j kd → Γ E.⊢Tp a ∈ k → Γ E.⊢ j Kind[ a ] kd → nfCtx Γ ⊢ (nfKind (nfCtx (kd k ∷ Γ)) j) Kind[ nf (nfCtx Γ) a ∈ ⌊ nfKind (nfCtx Γ) k ⌋ ] ≅ nfKind (nfCtx Γ) (j Kind[ a ]) ≅-nfKind-[] {_} {Γ} {a} {j} {k} j-kd a∈k j[a]-kd = let nf-Γ = nfCtx Γ nf-k = nfKind nf-Γ k nf-a = nf nf-Γ a nf-k∷Γ = kd nf-k ∷ nf-Γ nf-j = nfKind (nf-k∷Γ) j ⌊k⌋≡⌊nf-k⌋ = sym (⌊⌋-nf {_} {nf-Γ} k) nf-j-kd = complete-kd j-kd nf-a⇇k = complete-Tp∈ a∈k nf-j[a]-kd = complete-kd j[a]-kd nf-j[a∈⌊k⌋]-kd = kd-[] nf-j-kd nf-a⇇k nf-j[a∈⌊k⌋]≋j[a] = subst (λ l → nf-j Kind[ nf-a ∈ l ] ≋ _) ⌊k⌋≡⌊nf-k⌋ (≋-sym (nfKind-[] j-kd a∈k)) in ≋-≅ nf-j[a∈⌊k⌋]-kd nf-j[a]-kd nf-j[a∈⌊k⌋]≋j[a] -- β-reduction of normal forms is admissible in canonical kinding. ≃-β-nf : ∀ {n} {Γ : E.Ctx n} {a b j k} → kd j ∷ Γ E.⊢Tp a ∈ k → Γ E.⊢Tp b ∈ j → kd j ∷ Γ E.⊢ k kd → Γ E.⊢Tp a [ b ] ∈ k Kind[ b ] → Γ E.⊢ k Kind[ b ] kd → nfCtx Γ ⊢ nf (nfCtx Γ) ((Λ j a) · b) ≃ nf (nfCtx Γ) (a [ b ]) ⇇ nfKind (nfCtx Γ) (k Kind[ b ]) ≃-β-nf {_} {Γ} {a} {b} {j} {k} a∈k b∈j k-kd a[b]∈k[b] k[b]-kd = let nf-Γ = nfCtx Γ nf-j = nfKind nf-Γ j nf-b = nf nf-Γ b nf-j∷Γ = kd nf-j ∷ nf-Γ nf-a = nf (nf-j∷Γ) a ⌊j⌋≡⌊nf-j⌋ = sym (⌊⌋-nf {_} {nf-Γ} j) nf-a⇇k = complete-Tp∈ a∈k nf-b⇇j = complete-Tp∈ b∈j nf-a[b]⇇k[b] = complete-Tp∈ a[b]∈k[b] nf-k[b]-kd = complete-kd k[b]-kd nf-a[b∈⌊j⌋]⇇k[b∈⌊j⌋] = Nf⇇-[] nf-a⇇k nf-b⇇j nf-k[b∈⌊j⌋]<∷k[b] = ≅⇒<∷ (≅-nfKind-[] k-kd b∈j k[b]-kd) nf-a[b∈⌊j⌋]⇇k[b] = Nf⇇-⇑ nf-a[b∈⌊j⌋]⇇k[b∈⌊j⌋] nf-k[b∈⌊j⌋]<∷k[b] nf-a[b∈⌊j⌋]≈a[b] = subst (λ l → nf-a [ nf-b ∈ l ] ≈ _) ⌊j⌋≡⌊nf-j⌋ (≈-sym (nf-[] a∈k b∈j)) in ≈-≃ nf-k[b]-kd nf-a[b∈⌊j⌋]⇇k[b] nf-a[b]⇇k[b] nf-a[b∈⌊j⌋]≈a[b] -- Completeness of canonical subkinding and subtyping -- w.r.t. declarative subkinding and subtyping complete-<:-⋯ : ∀ {n} {Γ : E.Ctx n} {a b c d} → Γ O.⊢ a <: b ∈ c ⋯ d → nfCtx Γ ⊢ nf (nfCtx Γ) a <: nf (nfCtx Γ) b complete-<:-⋯ = CompletenessExtended.complete-<:-⋯ ∘ E.complete-<: complete-<: : ∀ {n} {Γ : E.Ctx n} {a b k} → Γ O.⊢ a <: b ∈ k → nfCtx Γ ⊢ nf (nfCtx Γ) a <: nf (nfCtx Γ) b ⇇ nfKind (nfCtx Γ) k complete-<: = CompletenessExtended.complete-<: ∘ E.complete-<: complete-<∷ : ∀ {n} {Γ : E.Ctx n} {j k} → Γ O.⊢ j <∷ k → nfCtx Γ ⊢ nfKind (nfCtx Γ) j <∷ nfKind (nfCtx Γ) k complete-<∷ = CompletenessExtended.complete-<∷ ∘ E.complete-<∷
45.965779
81
0.452726
4e8ad8dcaef43ed52b6daee8942ca461ee76c3c7
286
agda
Agda
stdlib-exts/Prelude/Strings.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
35
2019-06-13T07:44:50.000Z
2021-10-12T22:59:10.000Z
stdlib-exts/Prelude/Strings.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
10
2019-06-13T17:44:43.000Z
2020-04-25T15:29:17.000Z
stdlib-exts/Prelude/Strings.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
2
2019-06-27T23:12:48.000Z
2021-10-20T10:46:20.000Z
module Prelude.Strings where import Data.String.Literals import Data.List.Literals open import Data.Unit open import Agda.Builtin.FromString public instance isStringStringPublic = Data.String.Literals.isString isStringListPublic = Data.List.Literals.isString unitInstance = tt
22
54
0.825175
a02923d7b9feb4e7b1457a9a1dddf9e388040e93
409
agda
Agda
src/data/lib/prim/Agda/Builtin/Char.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
src/data/lib/prim/Agda/Builtin/Char.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
src/data/lib/prim/Agda/Builtin/Char.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
module Agda.Builtin.Char where open import Agda.Builtin.Nat open import Agda.Builtin.Bool postulate Char : Set {-# BUILTIN CHAR Char #-} primitive primIsLower primIsDigit primIsAlpha primIsSpace primIsAscii primIsLatin1 primIsPrint primIsHexDigit : Char → Bool primToUpper primToLower : Char → Char primCharToNat : Char → Nat primNatToChar : Nat → Char primCharEquality : Char → Char → Bool
24.058824
61
0.765281
30bf6337c7b55fd94f9e0a9920fff1be1d406584
376
agda
Agda
test/interaction/Issue2749-2.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2749-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2749-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue2749-2 where -- testing unicode lambda and arrow id : {A : Set} -> A -> A id = {!!} -- testing unicode double braces it : {A : Set} {{a : A}} → A → A it = {!!} data B : Set where mkB : B → B → B -- testing unicode suffixes left : B → B left b₁ = {!!} open import Agda.Builtin.Equality -- testing ascii only forall allq : (∀ m n → m ≡ n) ≡ {!!} allq = refl
16.347826
35
0.577128
ed0a214868fa718021f5294e61866a350a2bbcc3
7,655
agda
Agda
agda-stdlib/src/Data/Product/Function/Dependent/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Product/Function/Dependent/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Product/Function/Dependent/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Dependent product combinators for setoid equality preserving -- functions ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Product.Function.Dependent.Setoid where open import Data.Product open import Data.Product.Relation.Binary.Pointwise.Dependent open import Relation.Binary open import Function.Base open import Function.Equality as F using (_⟶_; _⟨$⟩_) open import Function.Equivalence as Eq using (Equivalence; _⇔_; module Equivalence) open import Function.Injection as Inj using (Injection; Injective; _↣_; module Injection) open import Function.Inverse as Inv using (Inverse; _↔_; module Inverse) open import Function.LeftInverse as LeftInv using (LeftInverse; _↞_; _LeftInverseOf_; _RightInverseOf_; module LeftInverse) open import Function.Surjection as Surj using (Surjection; _↠_; module Surjection) open import Relation.Binary as B open import Relation.Binary.Indexed.Heterogeneous using (IndexedSetoid) open import Relation.Binary.Indexed.Heterogeneous.Construct.At using (_atₛ_) open import Relation.Binary.PropositionalEquality as P using (_≡_) ------------------------------------------------------------------------ -- Properties related to "relatedness" ------------------------------------------------------------------------ private subst-cong : ∀ {i a p} {I : Set i} {A : I → Set a} (P : ∀ {i} → A i → A i → Set p) {i i′} {x y : A i} (i≡i′ : i ≡ i′) → P x y → P (P.subst A i≡i′ x) (P.subst A i≡i′ y) subst-cong P P.refl p = p ⟶ : ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′} {A₁ : Set a₁} {A₂ : Set a₂} {B₁ : IndexedSetoid A₁ b₁ b₁′} (B₂ : IndexedSetoid A₂ b₂ b₂′) (f : A₁ → A₂) → (∀ {x} → (B₁ atₛ x) ⟶ (B₂ atₛ (f x))) → setoid (P.setoid A₁) B₁ ⟶ setoid (P.setoid A₂) B₂ ⟶ {A₁ = A₁} {A₂} {B₁} B₂ f g = record { _⟨$⟩_ = fg ; cong = fg-cong } where open B.Setoid (setoid (P.setoid A₁) B₁) using () renaming (_≈_ to _≈₁_) open B.Setoid (setoid (P.setoid A₂) B₂) using () renaming (_≈_ to _≈₂_) open B using (_=[_]⇒_) fg = map f (_⟨$⟩_ g) fg-cong : _≈₁_ =[ fg ]⇒ _≈₂_ fg-cong (P.refl , ∼) = (P.refl , F.cong g ∼) module _ {a₁ a₂ b₁ b₁′ b₂ b₂′} {A₁ : Set a₁} {A₂ : Set a₂} where equivalence : {B₁ : IndexedSetoid A₁ b₁ b₁′} {B₂ : IndexedSetoid A₂ b₂ b₂′} (A₁⇔A₂ : A₁ ⇔ A₂) → (∀ {x} → _⟶_ (B₁ atₛ x) (B₂ atₛ (Equivalence.to A₁⇔A₂ ⟨$⟩ x))) → (∀ {y} → _⟶_ (B₂ atₛ y) (B₁ atₛ (Equivalence.from A₁⇔A₂ ⟨$⟩ y))) → Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂) equivalence {B₁} {B₂} A₁⇔A₂ B-to B-from = record { to = ⟶ B₂ (_⟨$⟩_ (to A₁⇔A₂)) B-to ; from = ⟶ B₁ (_⟨$⟩_ (from A₁⇔A₂)) B-from } where open Equivalence equivalence-↞ : (B₁ : IndexedSetoid A₁ b₁ b₁′) {B₂ : IndexedSetoid A₂ b₂ b₂′} (A₁↞A₂ : A₁ ↞ A₂) → (∀ {x} → Equivalence (B₁ atₛ (LeftInverse.from A₁↞A₂ ⟨$⟩ x)) (B₂ atₛ x)) → Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂) equivalence-↞ B₁ {B₂} A₁↞A₂ B₁⇔B₂ = equivalence (LeftInverse.equivalence A₁↞A₂) B-to B-from where B-to : ∀ {x} → _⟶_ (B₁ atₛ x) (B₂ atₛ (LeftInverse.to A₁↞A₂ ⟨$⟩ x)) B-to = record { _⟨$⟩_ = λ x → Equivalence.to B₁⇔B₂ ⟨$⟩ P.subst (IndexedSetoid.Carrier B₁) (P.sym $ LeftInverse.left-inverse-of A₁↞A₂ _) x ; cong = F.cong (Equivalence.to B₁⇔B₂) ∘ subst-cong (λ {x} → IndexedSetoid._≈_ B₁ {x} {x}) (P.sym (LeftInverse.left-inverse-of A₁↞A₂ _)) } B-from : ∀ {y} → _⟶_ (B₂ atₛ y) (B₁ atₛ (LeftInverse.from A₁↞A₂ ⟨$⟩ y)) B-from = Equivalence.from B₁⇔B₂ equivalence-↠ : {B₁ : IndexedSetoid A₁ b₁ b₁′} (B₂ : IndexedSetoid A₂ b₂ b₂′) (A₁↠A₂ : A₁ ↠ A₂) → (∀ {x} → Equivalence (B₁ atₛ x) (B₂ atₛ (Surjection.to A₁↠A₂ ⟨$⟩ x))) → Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂) equivalence-↠ {B₁ = B₁} B₂ A₁↠A₂ B₁⇔B₂ = equivalence (Surjection.equivalence A₁↠A₂) B-to B-from where B-to : ∀ {x} → _⟶_ (B₁ atₛ x) (B₂ atₛ (Surjection.to A₁↠A₂ ⟨$⟩ x)) B-to = Equivalence.to B₁⇔B₂ B-from : ∀ {y} → _⟶_ (B₂ atₛ y) (B₁ atₛ (Surjection.from A₁↠A₂ ⟨$⟩ y)) B-from = record { _⟨$⟩_ = λ x → Equivalence.from B₁⇔B₂ ⟨$⟩ P.subst (IndexedSetoid.Carrier B₂) (P.sym $ Surjection.right-inverse-of A₁↠A₂ _) x ; cong = F.cong (Equivalence.from B₁⇔B₂) ∘ subst-cong (λ {x} → IndexedSetoid._≈_ B₂ {x} {x}) (P.sym (Surjection.right-inverse-of A₁↠A₂ _)) } injection : {B₁ : IndexedSetoid A₁ b₁ b₁′} (B₂ : IndexedSetoid A₂ b₂ b₂′) → (A₁↣A₂ : A₁ ↣ A₂) → (∀ {x} → Injection (B₁ atₛ x) (B₂ atₛ (Injection.to A₁↣A₂ ⟨$⟩ x))) → Injection (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂) injection {B₁ = B₁} B₂ A₁↣A₂ B₁↣B₂ = record { to = to ; injective = inj } where to = ⟶ B₂ (Injection.to A₁↣A₂ ⟨$⟩_) (Injection.to B₁↣B₂) inj : Injective to inj (x , y) = Injection.injective A₁↣A₂ x , lemma (Injection.injective A₁↣A₂ x) y where lemma : ∀ {x x′} {y : IndexedSetoid.Carrier B₁ x} {y′ : IndexedSetoid.Carrier B₁ x′} → x ≡ x′ → (eq : IndexedSetoid._≈_ B₂ (Injection.to B₁↣B₂ ⟨$⟩ y) (Injection.to B₁↣B₂ ⟨$⟩ y′)) → IndexedSetoid._≈_ B₁ y y′ lemma P.refl = Injection.injective B₁↣B₂ left-inverse : (B₁ : IndexedSetoid A₁ b₁ b₁′) {B₂ : IndexedSetoid A₂ b₂ b₂′} → (A₁↞A₂ : A₁ ↞ A₂) → (∀ {x} → LeftInverse (B₁ atₛ (LeftInverse.from A₁↞A₂ ⟨$⟩ x)) (B₂ atₛ x)) → LeftInverse (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂) left-inverse B₁ {B₂} A₁↞A₂ B₁↞B₂ = record { to = Equivalence.to eq ; from = Equivalence.from eq ; left-inverse-of = left } where eq = equivalence-↞ B₁ A₁↞A₂ (LeftInverse.equivalence B₁↞B₂) left : Equivalence.from eq LeftInverseOf Equivalence.to eq left (x , y) = LeftInverse.left-inverse-of A₁↞A₂ x , IndexedSetoid.trans B₁ (LeftInverse.left-inverse-of B₁↞B₂ _) (lemma (P.sym (LeftInverse.left-inverse-of A₁↞A₂ x))) where lemma : ∀ {x x′ y} (eq : x ≡ x′) → IndexedSetoid._≈_ B₁ (P.subst (IndexedSetoid.Carrier B₁) eq y) y lemma P.refl = IndexedSetoid.refl B₁ surjection : {B₁ : IndexedSetoid A₁ b₁ b₁′} (B₂ : IndexedSetoid A₂ b₂ b₂′) → (A₁↠A₂ : A₁ ↠ A₂) → (∀ {x} → Surjection (B₁ atₛ x) (B₂ atₛ (Surjection.to A₁↠A₂ ⟨$⟩ x))) → Surjection (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂) surjection B₂ A₁↠A₂ B₁↠B₂ = record { to = Equivalence.to eq ; surjective = record { from = Equivalence.from eq ; right-inverse-of = right } } where eq = equivalence-↠ B₂ A₁↠A₂ (Surjection.equivalence B₁↠B₂) right : Equivalence.from eq RightInverseOf Equivalence.to eq right (x , y) = Surjection.right-inverse-of A₁↠A₂ x , IndexedSetoid.trans B₂ (Surjection.right-inverse-of B₁↠B₂ _) (lemma (P.sym $ Surjection.right-inverse-of A₁↠A₂ x)) where lemma : ∀ {x x′ y} (eq : x ≡ x′) → IndexedSetoid._≈_ B₂ (P.subst (IndexedSetoid.Carrier B₂) eq y) y lemma P.refl = IndexedSetoid.refl B₂ -- See also Data.Product.Function.Dependent.Setoid.WithK.inverse.
38.467337
81
0.553494
36694c5c733ec9d5a8ec6aa8b8e39c2a2b0d6bfb
2,345
agda
Agda
String.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
String.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
String.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module String where import Lvl open import Data.Boolean open import Data.List open import Numeral.Natural open import Type postulate Char : Type{Lvl.𝟎} {-# BUILTIN CHAR Char #-} postulate String : Type{Lvl.𝟎} {-# BUILTIN STRING String #-} private module Primitives where primitive primStringToList : String → List(Char) primitive primStringFromList : List(Char) → String primitive primStringAppend : String → String → String primitive primStringEquality : String → String → Bool primitive primShowChar : Char → String primitive primShowString : String → String primitive primShowNat : ℕ → String primitive primIsLower : Char → Bool primitive primIsDigit : Char → Bool primitive primIsAlpha : Char → Bool primitive primIsSpace : Char → Bool primitive primIsAscii : Char → Bool primitive primIsLatin1 : Char → Bool primitive primIsPrint : Char → Bool primitive primIsHexDigit : Char → Bool primitive primToUpper : Char → Char primitive primToLower : Char → Char primitive primCharToNat : Char → ℕ primitive primNatToChar : ℕ → Char primitive primCharEquality : Char → Char → Bool module String where open Primitives renaming ( primStringToList to toList ; primStringFromList to fromList ; primStringAppend to _++_ ; primStringEquality to _==_ ; primShowChar to fromChar ; primShowNat to fromℕ ) public {- open import Relator.Equals open import Relator.Equals.Proofs open import Syntax.Transitivity primitive primEraseEquality : ∀{ℓ}{A : Type{ℓ}}{x y : A} → (x ≡ y) → (x ≡ y) unsafeDefinitionalEquality : ∀{ℓ}{A : Type{ℓ}}{x y : A} → (x ≡ y) unsafeDefinitionalEquality {x = x}{y = y} = primEraseEquality xy where postulate xy : x ≡ y toList-fromList-of-[⊰] : ∀{x}{l} → (toList(fromList(x ⊰ l)) ≡ x ⊰ toList(fromList(l))) toList-fromList-of-[⊰] = unsafeDefinitionalEquality fromList-toList-inverse : ∀{s} → (fromList(toList(s)) ≡ s) fromList-toList-inverse = unsafeDefinitionalEquality toList-fromList-inverse : ∀{l} → (toList(fromList(l)) ≡ l) toList-fromList-inverse {∅} = [≡]-intro toList-fromList-inverse {x ⊰ l} = toList-fromList-of-[⊰] 🝖 [≡]-with(x ⊰_) (toList-fromList-inverse {l}) -}
33.5
105
0.663113
64df16dcae562f212806fd2a254507c1902d2c0b
17,416
agda
Agda
Cubical/Algebra/DirectSum/Equiv-DSHIT-DSFun.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/DirectSum/Equiv-DSHIT-DSFun.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/DirectSum/Equiv-DSHIT-DSFun.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.DirectSum.Equiv-DSHIT-DSFun where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Transport open import Cubical.Relation.Nullary open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Nat renaming (_+_ to _+n_) open import Cubical.Data.Nat.Order open import Cubical.Data.Sigma open import Cubical.Data.Sum open import Cubical.Data.Vec open import Cubical.Data.Vec.DepVec open import Cubical.HITs.PropositionalTruncation as PT open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.AbGroup open import Cubical.Algebra.AbGroup.Instances.DirectSumFun open import Cubical.Algebra.AbGroup.Instances.DirectSumHIT open import Cubical.Algebra.AbGroup.Instances.NProd open import Cubical.Algebra.DirectSum.DirectSumFun.Base open import Cubical.Algebra.DirectSum.DirectSumHIT.Base open import Cubical.Algebra.DirectSum.DirectSumHIT.Properties open import Cubical.Algebra.DirectSum.DirectSumHIT.PseudoNormalForm private variable ℓ : Level open GroupTheory open AbGroupTheory open AbGroupStr ----------------------------------------------------------------------------- -- Notation module Equiv-Properties (G : ℕ → Type ℓ) (Gstr : (n : ℕ) → AbGroupStr (G n)) where -- the convention is a bit different and had a - -- because otherwise it is unreadable open AbGroupStr (snd (⊕HIT-AbGr ℕ G Gstr)) using () renaming ( 0g to 0⊕HIT ; _+_ to _+⊕HIT_ ; -_ to -⊕HIT_ ; +Assoc to +⊕HIT-Assoc ; +IdR to +⊕HIT-IdR ; +IdL to +⊕HIT-IdL ; +InvR to +⊕HIT-InvR ; +InvL to +⊕HIT-InvL ; +Comm to +⊕HIT-Comm ; is-set to isSet⊕HIT) open AbGroupStr (snd (⊕Fun-AbGr G Gstr)) using () renaming ( 0g to 0⊕Fun ; _+_ to _+⊕Fun_ ; -_ to -⊕Fun_ ; +Assoc to +⊕Fun-Assoc ; +IdR to +⊕Fun-IdR ; +IdL to +⊕Fun-IdL ; +InvR to +⊕Fun-InvR ; +InvL to +⊕Fun-InvL ; +Comm to +⊕Fun-Comm ; is-set to isSet⊕Fun) ----------------------------------------------------------------------------- -- AbGroup on Fun -> produit ? sequence ? open AbGroupStr (snd (NProd-AbGroup G Gstr)) using () renaming ( 0g to 0Fun ; _+_ to _+Fun_ ; -_ to -Fun_ ; +Assoc to +FunAssoc ; +IdR to +FunIdR ; +IdL to +FunIdL ; +InvR to +FunInvR ; +InvL to +FunInvL ; +Comm to +FunComm ; is-set to isSetFun) ----------------------------------------------------------------------------- -- Some simplification for transport open SubstLemma ℕ G Gstr substG : (g : (n : ℕ) → G n) → {k n : ℕ} → (p : k ≡ n) → subst G p (g k) ≡ g n substG g {k} {n} p = J (λ n p → subst G p (g k) ≡ g n) (transportRefl _) p ----------------------------------------------------------------------------- -- Direct Sense -- To facilitate the proof the translation to the function -- and its properties are done in two times --------------------------------------------------------------------------- -- Translation to the function fun-trad : (k : ℕ) → (a : G k) → (n : ℕ) → G n fun-trad k a n with (discreteℕ k n) ... | yes p = subst G p a ... | no ¬p = 0g (Gstr n) fun-trad-eq : (k : ℕ) → (a : G k) → fun-trad k a k ≡ a fun-trad-eq k a with discreteℕ k k ... | yes p = cong (λ X → subst G X a) (isSetℕ _ _ _ _) ∙ transportRefl a ... | no ¬p = ⊥.rec (¬p refl) fun-trad-neq : (k : ℕ) → (a : G k) → (n : ℕ) → (k ≡ n → ⊥) → fun-trad k a n ≡ 0g (Gstr n) fun-trad-neq k a n ¬q with discreteℕ k n ... | yes p = ⊥.rec (¬q p) ... | no ¬p = refl ⊕HIT→Fun : ⊕HIT ℕ G Gstr → (n : ℕ) → G n ⊕HIT→Fun = DS-Rec-Set.f _ _ _ _ isSetFun 0Fun fun-trad _+Fun_ +FunAssoc +FunIdR +FunComm (λ k → funExt (λ n → base0-eq k n)) λ k a b → funExt (λ n → base-add-eq k a b n) where base0-eq : (k : ℕ) → (n : ℕ) → fun-trad k (0g (Gstr k)) n ≡ 0g (Gstr n) base0-eq k n with (discreteℕ k n) ... | yes p = subst0g _ ... | no ¬p = refl base-add-eq : (k : ℕ) → (a b : G k) → (n : ℕ) → PathP (λ _ → G n) (Gstr n ._+_ (fun-trad k a n) (fun-trad k b n)) (fun-trad k ((Gstr k + a) b) n) base-add-eq k a b n with (discreteℕ k n) ... | yes p = subst+ _ _ _ ... | no ¬p = +IdR (Gstr n)_ ⊕HIT→Fun-pres0 : ⊕HIT→Fun 0⊕HIT ≡ 0Fun ⊕HIT→Fun-pres0 = refl ⊕HIT→Fun-pres+ : (x y : ⊕HIT ℕ G Gstr) → ⊕HIT→Fun (x +⊕HIT y) ≡ ((⊕HIT→Fun x) +Fun (⊕HIT→Fun y)) ⊕HIT→Fun-pres+ x y = refl --------------------------------------------------------------------------- -- Translation to the properties nfun-trad : (k : ℕ) → (a : G k) → AlmostNull G Gstr (fun-trad k a) nfun-trad k a = k , fix-eq where fix-eq : (n : ℕ) → k < n → fun-trad k a n ≡ 0g (Gstr n) fix-eq n q with (discreteℕ k n) ... | yes p = ⊥.rec (<→≢ q p) ... | no ¬p = refl ⊕HIT→⊕AlmostNull : (x : ⊕HIT ℕ G Gstr) → AlmostNullP G Gstr (⊕HIT→Fun x) ⊕HIT→⊕AlmostNull = DS-Ind-Prop.f _ _ _ _ (λ x → squash₁) ∣ (0 , (λ n q → refl)) ∣₁ (λ r a → ∣ (nfun-trad r a) ∣₁) λ {U} {V} → PT.elim (λ _ → isPropΠ (λ _ → squash₁)) (λ { (k , nu) → PT.elim (λ _ → squash₁) λ { (l , nv) → ∣ ((k +n l) , (λ n q → cong₂ ((Gstr n)._+_) (nu n (<-+k-trans q)) (nv n (<-k+-trans q)) ∙ +IdR (Gstr n) _)) ∣₁} }) --------------------------------------------------------------------------- -- Translation + Morphism ⊕HIT→⊕Fun : ⊕HIT ℕ G Gstr → ⊕Fun G Gstr ⊕HIT→⊕Fun x = (⊕HIT→Fun x) , (⊕HIT→⊕AlmostNull x) ⊕HIT→⊕Fun-pres0 : ⊕HIT→⊕Fun 0⊕HIT ≡ 0⊕Fun ⊕HIT→⊕Fun-pres0 = refl ⊕HIT→⊕Fun-pres+ : (x y : ⊕HIT ℕ G Gstr) → ⊕HIT→⊕Fun (x +⊕HIT y) ≡ ((⊕HIT→⊕Fun x) +⊕Fun (⊕HIT→⊕Fun y)) ⊕HIT→⊕Fun-pres+ x y = ΣPathTransport→PathΣ _ _ (refl , (squash₁ _ _)) ----------------------------------------------------------------------------- -- Converse sense ----------------------------------------------------------------------------- -- Prood that ⊕HIT→⊕Fun is injective open DefPNF G Gstr sumFun : {m : ℕ} → depVec G m → (n : ℕ) → G n sumFun {0} ⋆ = 0Fun sumFun {suc m} (a □ dv) = (⊕HIT→Fun (base m a)) +Fun (sumFun dv) SumHIT→SumFun : {m : ℕ} → (dv : depVec G m) → ⊕HIT→Fun (sumHIT dv) ≡ sumFun dv SumHIT→SumFun {0} ⋆ = refl SumHIT→SumFun {suc m} (a □ dv) = cong₂ _+Fun_ refl (SumHIT→SumFun dv) sumFun< : {m : ℕ} → (dv : depVec G m) → (i : ℕ) → (m ≤ i) → sumFun dv i ≡ 0g (Gstr i) sumFun< {0} ⋆ i r = refl sumFun< {suc m} (a □ dv) i r with discreteℕ m i ... | yes p = ⊥.rec (<→≢ r p) ... | no ¬p = +IdL (Gstr i) _ ∙ sumFun< dv i (≤-trans ≤-sucℕ r) sumFunHead : {m : ℕ} → (a b : (G m)) → (dva dvb : depVec G m) → (x : sumFun (a □ dva) ≡ sumFun (b □ dvb)) → a ≡ b sumFunHead {m} a b dva dvb x = a ≡⟨ sym (+IdR (Gstr m) _) ⟩ (Gstr m)._+_ a (0g (Gstr m)) ≡⟨ cong₂ (Gstr m ._+_) (sym (fun-trad-eq m a)) (sym (sumFun< dva m ≤-refl)) ⟩ (Gstr m)._+_ (fun-trad m a m) (sumFun dva m) ≡⟨ funExt⁻ x m ⟩ (Gstr m)._+_ (fun-trad m b m) (sumFun dvb m) ≡⟨ cong₂ (Gstr m ._+_) (fun-trad-eq m b) (sumFun< dvb m ≤-refl) ⟩ (Gstr m)._+_ b (0g (Gstr m)) ≡⟨ +IdR (Gstr m) _ ⟩ b ∎ substSumFun : {m : ℕ} → (dv : depVec G m) → (n : ℕ) → (p : m ≡ n) → subst G p (sumFun dv m) ≡ sumFun dv n substSumFun {m} dv n p = J (λ n p → subst G p (sumFun dv m) ≡ sumFun dv n) (transportRefl _) p sumFunTail : {m : ℕ} → (a b : (G m)) → (dva dvb : depVec G m) → (x : sumFun (a □ dva) ≡ sumFun (b □ dvb)) → (n : ℕ) → sumFun dva n ≡ sumFun dvb n sumFunTail {m} a b dva dvb x n with discreteℕ m n ... | yes p = sumFun dva n ≡⟨ sym (substSumFun dva n p) ⟩ subst G p (sumFun dva m) ≡⟨ cong (subst G p) (sumFun< dva m ≤-refl) ⟩ subst G p (0g (Gstr m)) ≡⟨ subst0g p ⟩ 0g (Gstr n) ≡⟨ sym (subst0g p) ⟩ subst G p (0g (Gstr m)) ≡⟨ sym (cong (subst G p) (sumFun< dvb m ≤-refl)) ⟩ subst G p (sumFun dvb m) ≡⟨ substSumFun dvb n p ⟩ sumFun dvb n ∎ ... | no ¬p = sumFun dva n ≡⟨ sym (+IdL (Gstr n) _) ⟩ (Gstr n)._+_ (0g (Gstr n)) (sumFun dva n) ≡⟨ cong (λ X → (Gstr n)._+_ X (sumFun dva n)) (sym (fun-trad-neq m a n ¬p)) ⟩ Gstr n ._+_ (fun-trad m a n) (sumFun dva n) ≡⟨ funExt⁻ x n ⟩ Gstr n ._+_ (fun-trad m b n) (sumFun dvb n) ≡⟨ cong (λ X → Gstr n ._+_ X (sumFun dvb n)) (fun-trad-neq m b n ¬p) ⟩ (Gstr n)._+_ (0g (Gstr n)) (sumFun dvb n) ≡⟨ +IdL (Gstr n) _ ⟩ sumFun dvb n ∎ injSumFun : {m : ℕ} → (dva dvb : depVec G m) → sumFun dva ≡ sumFun dvb → dva ≡ dvb injSumFun {0} ⋆ ⋆ x = refl injSumFun {suc m} (a □ dva) (b □ dvb) x = depVecPath.decode G (a □ dva) (b □ dvb) ((sumFunHead a b dva dvb x) , (injSumFun dva dvb (funExt (sumFunTail a b dva dvb x)))) injSumHIT : {m : ℕ} → (dva dvb : depVec G m) → ⊕HIT→Fun (sumHIT dva) ≡ ⊕HIT→Fun (sumHIT dvb) → dva ≡ dvb injSumHIT dva dvb r = injSumFun dva dvb (sym (SumHIT→SumFun dva) ∙ r ∙ SumHIT→SumFun dvb) inj-⊕HIT→Fun : (x y : ⊕HIT ℕ G Gstr) → ⊕HIT→Fun x ≡ ⊕HIT→Fun y → x ≡ y inj-⊕HIT→Fun x y r = helper (⊕HIT→PNF2 x y) r where helper : PNF2 x y → ⊕HIT→Fun x ≡ ⊕HIT→Fun y → x ≡ y helper = PT.elim (λ _ → isPropΠ (λ _ → isSet⊕HIT _ _)) λ { (m , dva , dvb , p , q) r → p ∙ cong sumHIT (injSumHIT dva dvb (sym (cong ⊕HIT→Fun p) ∙ r ∙ cong ⊕HIT→Fun q)) ∙ sym q} inj-⊕HIT→⊕Fun : (x y : ⊕HIT ℕ G Gstr) → ⊕HIT→⊕Fun x ≡ ⊕HIT→⊕Fun y → x ≡ y inj-⊕HIT→⊕Fun x y p = inj-⊕HIT→Fun x y (fst (PathΣ→ΣPathTransport _ _ p)) lemProp : (g : ⊕Fun G Gstr) → isProp (Σ[ x ∈ ⊕HIT ℕ G Gstr ] ⊕HIT→⊕Fun x ≡ g ) lemProp g (x , p) (y , q) = ΣPathTransport→PathΣ _ _ ((inj-⊕HIT→⊕Fun x y (p ∙ sym q)) , isSet⊕Fun _ _ _ _) --------------------------------------------------------------------------- -- General translation for underliyng function Strad : (g : (n : ℕ) → G n) → (i : ℕ) → ⊕HIT ℕ G Gstr Strad g zero = base 0 (g 0) Strad g (suc i) = (base (suc i) (g (suc i))) +⊕HIT (Strad g i) Strad-pres+ : (f g : (n : ℕ) → G n) → (i : ℕ) → Strad (f +Fun g) i ≡ Strad f i +⊕HIT Strad g i Strad-pres+ f g zero = sym (base-add 0 (f 0) (g 0)) Strad-pres+ f g (suc i) = cong₂ _+⊕HIT_ (sym (base-add _ _ _)) (Strad-pres+ f g i) ∙ comm-4 (⊕HIT-AbGr ℕ G Gstr) _ _ _ _ -- Properties in the converse sens Strad-max : (f : (n : ℕ) → G n) → (k : ℕ) → (ng : AlmostNullProof G Gstr f k) → (i : ℕ) → (r : k ≤ i) → Strad f i ≡ Strad f k Strad-max f k ng zero r = sym (cong (Strad f) (≤0→≡0 r)) Strad-max f k ng (suc i) r with ≤-split r ... | inl x = cong₂ _+⊕HIT_ (cong (base (suc i)) (ng (suc i) x) ∙ base-neutral (suc i)) (Strad-max f k ng i (pred-≤-pred x)) ∙ +⊕HIT-IdL _ ... | inr x = cong (Strad f) (sym x) -- if m < n then the translation of sum up to i is 0 Strad-m<n : (g : (n : ℕ) → G n) → (m : ℕ) → (n : ℕ) → (r : m < n) → ⊕HIT→Fun (Strad g m) n ≡ 0g (Gstr n) Strad-m<n g zero n r with discreteℕ 0 n ... | yes p = ⊥.rec (<→≢ r p) ... | no ¬p = refl Strad-m<n g (suc m) n r with discreteℕ (suc m) n ... | yes p = ⊥.rec (<→≢ r p) ... | no ¬p = +IdL (Gstr n) _ ∙ Strad-m<n g m n (<-trans ≤-refl r) {- if n ≤ m, prove ⊕HIT→Fun (∑_{i ∈〚0, m〛} base i (g i)) ≡ g n then n is equal to only one〚0, m〛=> induction on m case 0 : ok case suc m : if n ≡ suc m, then the rest of the sum is 0 by trad-m<n if n ≢ suc m, then it is in the rest of the sum => recursive call -} Strad-n≤m : (g : (n : ℕ) → G n) → (m : ℕ) → (n : ℕ) → (r : n ≤ m) → ⊕HIT→Fun (Strad g m) n ≡ g n Strad-n≤m g zero n r with discreteℕ 0 n ... | yes p = substG g p ... | no ¬p = ⊥.rec (¬p (sym (≤0→≡0 r))) Strad-n≤m g (suc m) n r with discreteℕ (suc m) n ... | yes p = cong₂ ((Gstr n)._+_) (substG g p) (Strad-m<n g m n (0 , p)) ∙ +IdR (Gstr n) _ ... | no ¬p = +IdL (Gstr n) _ ∙ Strad-n≤m g m n (≤-suc-≢ r λ x → ¬p (sym x)) --------------------------------------------------------------------------- -- Translation + Morphsim -- translation ⊕Fun→⊕HIT+ : (g : ⊕Fun G Gstr) → Σ[ x ∈ ⊕HIT ℕ G Gstr ] ⊕HIT→⊕Fun x ≡ g ⊕Fun→⊕HIT+ (g , Ang) = PT.rec (lemProp (g , Ang)) (λ { (k , ng) → Strad g k , ΣPathTransport→PathΣ _ _ ((funExt (trad-section g k ng)) , (squash₁ _ _)) }) Ang where trad-section : (g : (n : ℕ) → G n) → (k : ℕ) → (ng : (n : ℕ) → ( k < n) → g n ≡ 0g (Gstr n)) → (n : ℕ) → ⊕HIT→Fun (Strad g k) n ≡ g n trad-section g k ng n with splitℕ-≤ n k ... | inl x = Strad-n≤m g k n x ... | inr x = Strad-m<n g k n x ∙ sym (ng n x) ⊕Fun→⊕HIT : ⊕Fun G Gstr → ⊕HIT ℕ G Gstr ⊕Fun→⊕HIT g = fst (⊕Fun→⊕HIT+ g) -- morphism ⊕Fun→⊕HIT-pres0 : ⊕Fun→⊕HIT 0⊕Fun ≡ 0⊕HIT ⊕Fun→⊕HIT-pres0 = base-neutral 0 ⊕Fun→⊕HIT-pres+ : (f g : ⊕Fun G Gstr) → ⊕Fun→⊕HIT (f +⊕Fun g) ≡ (⊕Fun→⊕HIT f) +⊕HIT (⊕Fun→⊕HIT g) ⊕Fun→⊕HIT-pres+ (f , Anf) (g , Ang) = PT.elim2 (λ x y → isSet⊕HIT (⊕Fun→⊕HIT ((f , x) +⊕Fun (g , y))) ((⊕Fun→⊕HIT (f , x)) +⊕HIT (⊕Fun→⊕HIT (g , y)))) (λ x y → AN f x g y) Anf Ang where AN : (f : (n : ℕ) → G n) → (x : AlmostNull G Gstr f) → (g : (n : ℕ) → G n) → (y : AlmostNull G Gstr g) → ⊕Fun→⊕HIT ((f , ∣ x ∣₁) +⊕Fun (g , ∣ y ∣₁)) ≡ (⊕Fun→⊕HIT (f , ∣ x ∣₁)) +⊕HIT (⊕Fun→⊕HIT (g , ∣ y ∣₁)) AN f (k , nf) g (l , ng) = Strad-pres+ f g (k +n l) ∙ cong₂ _+⊕HIT_ (Strad-max f k nf (k +n l) (l , (+-comm l k))) (Strad-max g l ng (k +n l) (k , refl)) ----------------------------------------------------------------------------- -- Section e-sect : (g : ⊕Fun G Gstr) → ⊕HIT→⊕Fun (⊕Fun→⊕HIT g) ≡ g e-sect g = snd (⊕Fun→⊕HIT+ g) ----------------------------------------------------------------------------- -- Retraction lemmaSkk : (k : ℕ) → (a : G k) → (i : ℕ) → (r : i < k) → Strad (λ n → fun-trad k a n) i ≡ 0⊕HIT lemmaSkk k a zero r with discreteℕ k 0 ... | yes p = ⊥.rec (<→≢ r (sym p)) ... | no ¬p = base-neutral 0 lemmaSkk k a (suc i) r with discreteℕ k (suc i) ... | yes p = ⊥.rec (<→≢ r (sym p)) ... | no ¬p = cong₂ _+⊕HIT_ (base-neutral (suc i)) (lemmaSkk k a i (<-trans ≤-refl r)) ∙ +⊕HIT-IdR _ lemmakk : (k : ℕ) → (a : G k) → ⊕Fun→⊕HIT (⊕HIT→⊕Fun (base k a)) ≡ base k a lemmakk zero a = cong (base 0) (transportRefl a) lemmakk (suc k) a with (discreteℕ (suc k) (suc k)) | (discreteℕ k k) ... | yes p | yes q = cong₂ _add_ (sym (constSubstCommSlice G (⊕HIT ℕ G Gstr) base (cong suc q) a)) (lemmaSkk (suc k) a k ≤-refl) ∙ +⊕HIT-IdR _ ... | yes p | no ¬q = ⊥.rec (¬q refl) ... | no ¬p | yes q = ⊥.rec (¬p refl) ... | no ¬p | no ¬q = ⊥.rec (¬q refl) e-retr : (x : ⊕HIT ℕ G Gstr) → ⊕Fun→⊕HIT (⊕HIT→⊕Fun x) ≡ x e-retr = DS-Ind-Prop.f _ _ _ _ (λ _ → isSet⊕HIT _ _) (base-neutral 0) lemmakk λ {U} {V} ind-U ind-V → cong ⊕Fun→⊕HIT (⊕HIT→⊕Fun-pres+ U V) ∙ ⊕Fun→⊕HIT-pres+ (⊕HIT→⊕Fun U) (⊕HIT→⊕Fun V) ∙ cong₂ _+⊕HIT_ ind-U ind-V module _ (G : ℕ → Type ℓ) (Gstr : (n : ℕ) → AbGroupStr (G n)) where open Iso open Equiv-Properties G Gstr Equiv-DirectSum : AbGroupEquiv (⊕HIT-AbGr ℕ G Gstr) (⊕Fun-AbGr G Gstr) fst Equiv-DirectSum = isoToEquiv is where is : Iso (⊕HIT ℕ G Gstr) (⊕Fun G Gstr) fun is = ⊕HIT→⊕Fun Iso.inv is = ⊕Fun→⊕HIT rightInv is = e-sect leftInv is = e-retr snd Equiv-DirectSum = makeIsGroupHom ⊕HIT→⊕Fun-pres+
40.978824
124
0.447462
7cd3791792738b9f3f4786cff897587705fc8efc
1,663
agda
Agda
proglangs-learning/Agda/sv20/assign2/SetTheory/PMI.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
proglangs-learning/Agda/sv20/assign2/SetTheory/PMI.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
4
2020-03-10T19:20:21.000Z
2021-06-07T15:39:48.000Z
proglangs-learning/Agda/sv20/assign2/SetTheory/PMI.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
------------------------------------------ -- Mathematical induction derived from Z ------------------------------------------ module sv20.assign2.SetTheory.PMI where open import sv20.assign2.SetTheory.Logic open import sv20.assign2.SetTheory.ZAxioms open import sv20.assign2.SetTheory.Algebra open import sv20.assign2.SetTheory.Subset open import sv20.assign2.SetTheory.Pairs -- Axiom of infinity postulate infinity : ∃ (λ I → ∅ ∈ I ∧ ∀ x → x ∈ I → x ∪ singleton x ∈ I) succ : 𝓢 → 𝓢 succ x = x ∪ singleton x -- Inductive property Inductive : 𝓢 → Set Inductive A = ∅ ∈ A ∧ ((x : 𝓢) → x ∈ A → succ x ∈ A) -- An inductive set. I : 𝓢 I = proj₁ infinity formulaN : 𝓢 → Set formulaN x = (A : 𝓢) → Inductive A → x ∈ A fullN : ∃ (λ B → {z : 𝓢} → z ∈ B ⇔ z ∈ I ∧ formulaN z) fullN = sub formulaN I ℕ : 𝓢 ℕ = proj₁ fullN x∈ℕ→x∈InductiveSet : (x : 𝓢) → x ∈ ℕ → (A : 𝓢) → Inductive A → x ∈ A x∈ℕ→x∈InductiveSet x h = ∧-proj₂ (∧-proj₁ (proj₂ _ fullN) h) -- PMI version from Ivorra Castillo (n.d.), Teorema 8.13. PMI : (A : 𝓢) → A ⊆ ℕ → ∅ ∈ A → ((n : 𝓢) → n ∈ A → succ n ∈ A) → A ≡ ℕ PMI A h₁ h₂ h₃ = equalitySubset A ℕ (prf₁ , prf₂) where prf₁ : (z : 𝓢) → z ∈ A → z ∈ ℕ prf₁ z h = h₁ z h inductiveA : Inductive A inductiveA = h₂ , h₃ prf₂ : (z : 𝓢) → z ∈ ℕ → z ∈ A prf₂ z h = x∈ℕ→x∈InductiveSet z h A inductiveA -- References -- -- Suppes, Patrick (1960). Axiomatic Set Theory. -- The University Series in Undergraduate Mathematics. -- D. Van Nostrand Company, inc. -- -- Enderton, Herbert B. (1977). Elements of Set Theory. -- Academic Press Inc. -- -- Ivorra Castillo, Carlos (n.d.). Lógica y Teoría de -- Conjuntos. https://www.uv.es/ivorra/
25.984375
70
0.593506
edf1d5d042b176b66a6ab877835f79bb4daf29b9
1,632
agda
Agda
Definition/Typed/Reduction.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2018-06-21T08:39:01.000Z
2022-01-17T16:13:53.000Z
Definition/Typed/Reduction.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
null
null
null
Definition/Typed/Reduction.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2022-01-26T14:55:51.000Z
2022-02-15T19:42:19.000Z
{-# OPTIONS --safe #-} module Definition.Typed.Reduction where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties -- Weak head expansion of type equality reduction : ∀ {A A′ B B′ r Γ} → Γ ⊢ A ⇒* A′ ^ r → Γ ⊢ B ⇒* B′ ^ r → Whnf A′ → Whnf B′ → Γ ⊢ A′ ≡ B′ ^ r → Γ ⊢ A ≡ B ^ r reduction D D′ whnfA′ whnfB′ A′≡B′ = trans (subset* D) (trans A′≡B′ (sym (subset* D′))) reduction′ : ∀ {A A′ B B′ r Γ} → Γ ⊢ A ⇒* A′ ^ r → Γ ⊢ B ⇒* B′ ^ r → Whnf A′ → Whnf B′ → Γ ⊢ A ≡ B ^ r → Γ ⊢ A′ ≡ B′ ^ r reduction′ D D′ whnfA′ whnfB′ A≡B = trans (sym (subset* D)) (trans A≡B (subset* D′)) -- Weak head expansion of term equality reductionₜ : ∀ {a a′ b b′ A B l Γ} → Γ ⊢ A ⇒* B ^ [ ! , l ] → Γ ⊢ a ⇒* a′ ∷ B ^ l → Γ ⊢ b ⇒* b′ ∷ B ^ l → Whnf B → Whnf a′ → Whnf b′ → Γ ⊢ a′ ≡ b′ ∷ B ^ [ ! , l ] → Γ ⊢ a ≡ b ∷ A ^ [ ! , l ] reductionₜ D d d′ whnfB whnfA′ whnfB′ a′≡b′ = conv (trans (subset*Term d) (trans a′≡b′ (sym (subset*Term d′)))) (sym (subset* D)) reductionₜ′ : ∀ {a a′ b b′ A B l Γ} → Γ ⊢ A ⇒* B ^ [ ! , l ] → Γ ⊢ a ⇒* a′ ∷ B ^ l → Γ ⊢ b ⇒* b′ ∷ B ^ l → Whnf B → Whnf a′ → Whnf b′ → Γ ⊢ a ≡ b ∷ A ^ [ ! , l ] → Γ ⊢ a′ ≡ b′ ∷ B ^ [ ! , l ] reductionₜ′ D d d′ whnfB whnfA′ whnfB′ a≡b = trans (sym (subset*Term d)) (trans (conv a≡b (subset* D)) (subset*Term d′))
28.137931
55
0.400735
ed4ec6c12de3b2afa088c29627a28f3d87dba20d
479
agda
Agda
test/Fail/Issue2120.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2120.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2120.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-07-28 issue 2120, reported by guillaume -- {-# OPTIONS -v tc.term.exlam:50 #-} open import Common.Product data Nat : Set where zero : Nat data Eq {A : Set}(a : A) : A → Set where refl : Eq a a postulate _<∣_ : ∀ {X Y : Set} → (X → Y) → X → Y test : Nat test = ( λ { (zero , refl) → zero } ) <∣ (zero , zero) -- WAS: Internal error in Reduce -- EXPECTED: Proper error, like -- -- Type mismatch -- when checking that the pattern refl has type _15 zero
19.958333
56
0.611691
11f1f741c3aea842ce1bf52ab0605c4b09d765b1
34,199
agda
Agda
Cubical/HITs/Sn/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/HITs/Sn/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/HITs/Sn/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.HITs.Sn.Properties where open import Cubical.Foundations.Pointed open import Cubical.Foundations.Path open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Transport open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Univalence open import Cubical.HITs.S1 renaming (_·_ to _*_) hiding (rec ; elim) open import Cubical.HITs.S2 renaming (S¹×S¹→S² to S¹×S¹→S²') open import Cubical.HITs.S3 open import Cubical.Data.Nat hiding (elim) open import Cubical.Data.Sigma open import Cubical.HITs.Sn.Base open import Cubical.HITs.Susp renaming (toSusp to σ) open import Cubical.HITs.Truncation open import Cubical.Homotopy.Connected open import Cubical.HITs.Join renaming (joinS¹S¹→S³ to joinS¹S¹→S3) open import Cubical.Data.Bool private variable ℓ : Level open Iso IsoSucSphereSusp : (n : ℕ) → Iso (S₊ (suc n)) (Susp (S₊ n)) IsoSucSphereSusp zero = S¹IsoSuspBool IsoSucSphereSusp (suc n) = idIso IsoSucSphereSusp∙ : (n : ℕ) → Iso.inv (IsoSucSphereSusp n) north ≡ ptSn (suc n) IsoSucSphereSusp∙ zero = refl IsoSucSphereSusp∙ (suc n) = refl -- Elimination principles for spheres sphereElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isOfHLevel (suc n) (A x)) → A (ptSn (suc n)) → (x : S₊ (suc n)) → A x sphereElim zero hlev pt = toPropElim hlev pt sphereElim (suc n) hlev pt north = pt sphereElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt sphereElim (suc n) {A = A} hlev pt (merid a i) = sphereElim n {A = λ a → PathP (λ i → A (merid a i)) pt (subst A (merid (ptSn (suc n))) pt)} (λ a → isOfHLevelPathP' (suc n) (hlev south) _ _) (λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∧ j))) (~ i) pt) a i sphereElim2 : ∀ {ℓ} (n : ℕ) {A : (S₊ (suc n)) → (S₊ (suc n)) → Type ℓ} → ((x y : S₊ (suc n)) → isOfHLevel (suc n) (A x y)) → A (ptSn (suc n)) (ptSn (suc n)) → (x y : S₊ (suc n)) → A x y sphereElim2 n hlev pt = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → hlev _ _) (sphereElim n (hlev _ ) pt) private compPath-lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y) → PathP (λ i → (p ∙ sym q) i ≡ y) p q compPath-lem {y = y} p q i j = hcomp (λ k → λ { (i = i0) → p j ; (i = i1) → q (~ k ∨ j) ; (j = i1) → y }) (p (j ∨ i)) sphereToPropElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isProp (A x)) → A (ptSn (suc n)) → (x : S₊ (suc n)) → A x sphereToPropElim zero = toPropElim sphereToPropElim (suc n) hlev pt north = pt sphereToPropElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt sphereToPropElim (suc n) {A = A} hlev pt (merid a i) = isProp→PathP {B = λ i → A (merid a i)} (λ _ → hlev _) pt (subst A (merid (ptSn (suc n))) pt) i -- Elimination rule for fibrations (x : Sⁿ) → (y : Sᵐ) → A x y of h-Level (n + m). -- The following principle is just the special case of the "Wedge Connectivity Lemma" -- for spheres (See Cubical.Homotopy.WedgeConnectivity or chapter 8.6 in the HoTT book). -- We prove it directly here for three reasons: -- (i) it should perform better -- (ii) we get a slightly stronger statement for spheres: one of the homotopies will, by design, be refl -- (iii) the fact that the two homotopies only differ by (composition with) the homotopy leftFunction(base) ≡ rightFunction(base) -- is close to trivial wedgeconFun : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ} → ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y)) → (f : (x : _) → A (ptSn (suc n)) x) → (g : (x : _) → A x (ptSn (suc m))) → (g (ptSn (suc n)) ≡ f (ptSn (suc m))) → (x : S₊ (suc n)) (y : S₊ (suc m)) → A x y wedgeconLeft : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ} → (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y))) → (f : (x : _) → A (ptSn (suc n)) x) → (g : (x : _) → A x (ptSn (suc m))) → (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m))) → (x : _) → wedgeconFun n m hLev f g hom (ptSn (suc n)) x ≡ f x wedgeconRight : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ} → (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y))) → (f : (x : _) → A (ptSn (suc n)) x) → (g : (x : _) → A x (ptSn (suc m))) → (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m))) → (x : _) → wedgeconFun n m hLev f g hom x (ptSn (suc m)) ≡ g x wedgeconFun zero zero {A = A} hlev f g hom = F where helper : SquareP (λ i j → A (loop i) (loop j)) (cong f loop) (cong f loop) (λ i → hcomp (λ k → λ { (i = i0) → hom k ; (i = i1) → hom k }) (g (loop i))) λ i → hcomp (λ k → λ { (i = i0) → hom k ; (i = i1) → hom k }) (g (loop i)) helper = toPathP (isOfHLevelPathP' 1 (hlev _ _) _ _ _ _) F : (x y : S¹) → A x y F base y = f y F (loop i) base = hcomp (λ k → λ { (i = i0) → hom k ; (i = i1) → hom k }) (g (loop i)) F (loop i) (loop j) = helper i j wedgeconFun zero (suc m) {A = A} hlev f g hom = F₀ module _ where transpLemma₀ : (x : S₊ (suc m)) → transport (λ i₁ → A base (merid x i₁)) (g base) ≡ f south transpLemma₀ x = cong (transport (λ i₁ → A base (merid x i₁))) hom ∙ (λ i → transp (λ j → A base (merid x (i ∨ j))) i (f (merid x i))) pathOverMerid₀ : (x : S₊ (suc m)) → PathP (λ i₁ → A base (merid x i₁)) (g base) (transport (λ i₁ → A base (merid (ptSn (suc m)) i₁)) (g base)) pathOverMerid₀ x i = hcomp (λ k → λ { (i = i0) → g base ; (i = i1) → (transpLemma₀ x ∙ sym (transpLemma₀ (ptSn (suc m)))) k}) (transp (λ i₁ → A base (merid x (i₁ ∧ i))) (~ i) (g base)) pathOverMeridId₀ : pathOverMerid₀ (ptSn (suc m)) ≡ λ i → transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g base) pathOverMeridId₀ = (λ j i → hcomp (λ k → λ {(i = i0) → g base ; (i = i1) → rCancel (transpLemma₀ (ptSn (suc m))) j k}) (transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g base))) ∙ λ j i → hfill (λ k → λ { (i = i0) → g base ; (i = i1) → transport (λ i₁ → A base (merid (ptSn (suc m)) i₁)) (g base)}) (inS (transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g base))) (~ j) indStep₀ : (x : _) (a : _) → PathP (λ i → A x (merid a i)) (g x) (subst (λ y → A x y) (merid (ptSn (suc m))) (g x)) indStep₀ = wedgeconFun zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _) pathOverMerid₀ (λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g a)) (sym pathOverMeridId₀) F₀ : (x : S¹) (y : Susp (S₊ (suc m))) → A x y F₀ x north = g x F₀ x south = subst (λ y → A x y) (merid (ptSn (suc m))) (g x) F₀ x (merid a i) = indStep₀ x a i wedgeconFun (suc n) m {A = A} hlev f g hom = F₁ module _ where transpLemma₁ : (x : S₊ (suc n)) → transport (λ i₁ → A (merid x i₁) (ptSn (suc m))) (f (ptSn (suc m))) ≡ g south transpLemma₁ x = cong (transport (λ i₁ → A (merid x i₁) (ptSn (suc m)))) (sym hom) ∙ (λ i → transp (λ j → A (merid x (i ∨ j)) (ptSn (suc m))) i (g (merid x i))) pathOverMerid₁ : (x : S₊ (suc n)) → PathP (λ i₁ → A (merid x i₁) (ptSn (suc m))) (f (ptSn (suc m))) (transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m))) (f (ptSn (suc m)))) pathOverMerid₁ x i = hcomp (λ k → λ { (i = i0) → f (ptSn (suc m)) ; (i = i1) → (transpLemma₁ x ∙ sym (transpLemma₁ (ptSn (suc n)))) k }) (transp (λ i₁ → A (merid x (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m)))) pathOverMeridId₁ : pathOverMerid₁ (ptSn (suc n)) ≡ λ i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))) pathOverMeridId₁ = (λ j i → hcomp (λ k → λ { (i = i0) → f (ptSn (suc m)) ; (i = i1) → rCancel (transpLemma₁ (ptSn (suc n))) j k }) (transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))))) ∙ λ j i → hfill (λ k → λ { (i = i0) → f (ptSn (suc m)) ; (i = i1) → transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m))) (f (ptSn (suc m))) }) (inS (transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))))) (~ j) indStep₁ : (a : _) (y : _) → PathP (λ i → A (merid a i) y) (f y) (subst (λ x → A x y) (merid (ptSn (suc n))) (f y)) indStep₁ = wedgeconFun n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _) (λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i) (f a)) pathOverMerid₁ pathOverMeridId₁ F₁ : (x : Susp (S₊ (suc n))) (y : S₊ (suc m)) → A x y F₁ north y = f y F₁ south y = subst (λ x → A x y) (merid (ptSn (suc n))) (f y) F₁ (merid a i) y = indStep₁ a y i wedgeconRight zero zero {A = A} hlev f g hom = right where right : (x : S¹) → _ right base = sym hom right (loop i) j = hcomp (λ k → λ { (i = i0) → hom (~ j ∧ k) ; (i = i1) → hom (~ j ∧ k) ; (j = i1) → g (loop i) }) (g (loop i)) wedgeconRight zero (suc m) {A = A} hlev f g hom x = refl wedgeconRight (suc n) m {A = A} hlev f g hom = right where lem : (x : _) → indStep₁ n m hlev f g hom x (ptSn (suc m)) ≡ _ lem = wedgeconRight n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _) (λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i) (f a)) (pathOverMerid₁ n m hlev f g hom) (pathOverMeridId₁ n m hlev f g hom) right : (x : Susp (S₊ (suc n))) → _ ≡ g x right north = sym hom right south = cong (subst (λ x → A x (ptSn (suc m))) (merid (ptSn (suc n)))) (sym hom) ∙ λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∨ j)) (ptSn (suc m))) i (g (merid (ptSn (suc n)) i)) right (merid a i) j = hcomp (λ k → λ { (i = i0) → hom (~ j) ; (i = i1) → transpLemma₁ n m hlev f g hom (ptSn (suc n)) j ; (j = i0) → lem a (~ k) i ; (j = i1) → g (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom (~ j) ; (i = i1) → compPath-lem (transpLemma₁ n m hlev f g hom a) (transpLemma₁ n m hlev f g hom (ptSn (suc n))) k j ; (j = i1) → g (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom (~ j) ; (j = i0) → transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))) ; (j = i1) → transp (λ j → A (merid a (i ∧ (j ∨ k))) (ptSn (suc m))) (k ∨ ~ i) (g (merid a (i ∧ k))) }) (transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i) (hom (~ j))))) wedgeconLeft zero zero {A = A} hlev f g hom x = refl wedgeconLeft zero (suc m) {A = A} hlev f g hom = help where left₁ : (x : _) → indStep₀ m hlev f g hom base x ≡ _ left₁ = wedgeconLeft zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _) (pathOverMerid₀ m hlev f g hom) (λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g a)) (sym (pathOverMeridId₀ m hlev f g hom)) help : (x : S₊ (suc (suc m))) → _ help north = hom help south = cong (subst (A base) (merid (ptSn (suc m)))) hom ∙ λ i → transp (λ j → A base (merid (ptSn (suc m)) (i ∨ j))) i (f (merid (ptSn (suc m)) i)) help (merid a i) j = hcomp (λ k → λ { (i = i0) → hom j ; (i = i1) → transpLemma₀ m hlev f g hom (ptSn (suc m)) j ; (j = i0) → left₁ a (~ k) i ; (j = i1) → f (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom j ; (i = i1) → compPath-lem (transpLemma₀ m hlev f g hom a) (transpLemma₀ m hlev f g hom (ptSn (suc m))) k j ; (j = i1) → f (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom j ; (j = i0) → transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i) (g base) ; (j = i1) → transp (λ j → A base (merid a (i ∧ (j ∨ k)))) (k ∨ ~ i) (f (merid a (i ∧ k)))}) (transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i) (hom j)))) wedgeconLeft (suc n) m {A = A} hlev f g hom _ = refl ---------- Connectedness ----------- sphereConnected : (n : HLevel) → isConnected (suc n) (S₊ n) sphereConnected n = ∣ ptSn n ∣ , elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) (λ a → sym (spoke ∣_∣ (ptSn n)) ∙ spoke ∣_∣ a) -- The fact that path spaces of Sn are connected can be proved directly for Sⁿ. -- (Unfortunately, this does not work for higher paths) pathIdTruncSⁿ : (n : ℕ) (x y : S₊ (suc n)) → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣ → hLevelTrunc (suc n) (x ≡ y) pathIdTruncSⁿ n = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n)) (sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n)) λ _ → ∣ refl ∣) pathIdTruncSⁿ⁻ : (n : ℕ) (x y : S₊ (suc n)) → hLevelTrunc (suc n) (x ≡ y) → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣ pathIdTruncSⁿ⁻ n x y = rec (isOfHLevelTrunc (2 + n) _ _) (J (λ y _ → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣) refl) pathIdTruncSⁿretract : (n : ℕ) (x y : S₊ (suc n)) → (p : hLevelTrunc (suc n) (x ≡ y)) → pathIdTruncSⁿ n x y (pathIdTruncSⁿ⁻ n x y p) ≡ p pathIdTruncSⁿretract n = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ y → elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) (J (λ y p → pathIdTruncSⁿ n (ptSn (suc n)) y (pathIdTruncSⁿ⁻ n (ptSn (suc n)) y ∣ p ∣) ≡ ∣ p ∣) (cong (pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n))) (transportRefl refl) ∙ pm-help n)) where pm-help : (n : ℕ) → pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n)) refl ≡ ∣ refl ∣ pm-help zero = refl pm-help (suc n) = refl isConnectedPathSⁿ : (n : ℕ) (x y : S₊ (suc n)) → isConnected (suc n) (x ≡ y) isConnectedPathSⁿ n x y = isContrRetract (pathIdTruncSⁿ⁻ n x y) (pathIdTruncSⁿ n x y) (pathIdTruncSⁿretract n x y) ((isContr→isProp (sphereConnected (suc n)) ∣ x ∣ ∣ y ∣) , isProp→isSet (isContr→isProp (sphereConnected (suc n))) _ _ _) -- Some lemmas on the H space structure on S¹ rUnitS¹ : (x : S¹) → x * base ≡ x rUnitS¹ base = refl rUnitS¹ (loop i₁) = refl commS¹ : (a x : S¹) → a * x ≡ x * a commS¹ = wedgeconFun _ _ (λ _ _ → isGroupoidS¹ _ _) (sym ∘ rUnitS¹) rUnitS¹ refl assocS¹ : (x y z : S¹) → x * (y * z) ≡ (x * y) * z assocS¹ = wedgeconFun _ _ (λ _ _ → isSetΠ λ _ → isGroupoidS¹ _ _) (λ _ _ → refl) (λ x z i → (rUnitS¹ x (~ i)) * z) refl invLooperDistr : (x y : S¹) → invLooper (x * y) ≡ invLooper x * invLooper y invLooperDistr = wedgeconFun 0 0 (λ _ _ → isGroupoidS¹ _ _) (λ _ → refl) (λ x → cong invLooper (rUnitS¹ x) ∙ sym (rUnitS¹ (invLooper x))) (sym (rUnit refl)) SuspS¹-hom : (a x : S¹) → Path (Path (hLevelTrunc 4 (S₊ 2)) _ _) (cong ∣_∣ₕ (σ (S₊∙ 1) (a * x))) (cong ∣_∣ₕ (σ (S₊∙ 1) a) ∙ (cong ∣_∣ₕ (σ (S₊∙ 1) x))) SuspS¹-hom = wedgeconFun _ _ (λ _ _ → isOfHLevelTrunc 4 _ _ _ _) (λ x → lUnit _ ∙ cong (_∙ cong ∣_∣ₕ (σ (S₊∙ 1) x)) (cong (cong ∣_∣ₕ) (sym (rCancel (merid base))))) (λ x → (λ i → cong ∣_∣ₕ (σ (S₊∙ 1) (rUnitS¹ x i))) ∙∙ rUnit _ ∙∙ cong (cong ∣_∣ₕ (σ (S₊∙ 1) x) ∙_) (cong (cong ∣_∣ₕ) (sym (rCancel (merid base))))) (sym (l (cong ∣_∣ₕ (σ (S₊∙ 1) base)) (cong (cong ∣_∣ₕ) (sym (rCancel (merid base)))))) where l : ∀ {ℓ} {A : Type ℓ} {x : A} (p : x ≡ x) (P : refl ≡ p) → lUnit p ∙ cong (_∙ p) P ≡ rUnit p ∙ cong (p ∙_) P l p = J (λ p P → lUnit p ∙ cong (_∙ p) P ≡ rUnit p ∙ cong (p ∙_) P) refl rCancelS¹ : (x : S¹) → ptSn 1 ≡ x * (invLooper x) rCancelS¹ base = refl rCancelS¹ (loop i) j = hcomp (λ r → λ {(i = i0) → base ; (i = i1) → base ; (j = i0) → base}) base SuspS¹-inv : (x : S¹) → Path (Path (hLevelTrunc 4 (S₊ 2)) _ _) (cong ∣_∣ₕ (σ (S₊∙ 1) (invLooper x))) (cong ∣_∣ₕ (sym (σ (S₊∙ 1) x))) SuspS¹-inv x = (lUnit _ ∙∙ cong (_∙ cong ∣_∣ₕ (σ (S₊∙ 1) (invLooper x))) (sym (lCancel (cong ∣_∣ₕ (σ (S₊∙ 1) x)))) ∙∙ sym (assoc _ _ _)) ∙∙ cong (sym (cong ∣_∣ₕ (σ (S₊∙ 1) x)) ∙_) lem ∙∙ (assoc _ _ _ ∙∙ cong (_∙ (cong ∣_∣ₕ (sym (σ (S₊∙ 1) x)))) (lCancel (cong ∣_∣ₕ (σ (S₊∙ 1) x))) ∙∙ sym (lUnit _)) where lem : cong ∣_∣ₕ (σ (S₊∙ 1) x) ∙ cong ∣_∣ₕ (σ (S₊∙ 1) (invLooper x)) ≡ cong ∣_∣ₕ (σ (S₊∙ 1) x) ∙ cong ∣_∣ₕ (sym (σ (S₊∙ 1) x)) lem = sym (SuspS¹-hom x (invLooper x)) ∙ ((λ i → cong ∣_∣ₕ (σ (S₊∙ 1) (rCancelS¹ x (~ i)))) ∙ cong (cong ∣_∣ₕ) (rCancel (merid base))) ∙ sym (rCancel _) -------------------- join Sⁿ Sᵐ ≃ Sⁿ⁺¹⁺ᵐ ------------------------- {- This section contains a proof that join Sⁿ Sᵐ ≃ Sⁿ⁺ᵐ⁺¹. This is easy using various properties proved in HITs.Join. However, we would like the map join Sⁿ Sᵐ → Sⁿ⁺ᵐ⁺¹ to be nice, in particular when n = m = 1. Therefore, we put in some extra work into the equivalence. -} {- We begin with join S¹ S¹ ≃ S³. The iso is induced by: -} S¹×S¹→S² : S¹ → S¹ → S₊ 2 S¹×S¹→S² base y = north S¹×S¹→S² (loop i) base = north S¹×S¹→S² (loop i) (loop j) = (sym (rCancel (merid base)) ∙∙ (λ i → merid (loop i) ∙ sym (merid base)) ∙∙ rCancel (merid base)) i j joinS¹S¹→S³ : join S¹ S¹ → S₊ 3 joinS¹S¹→S³ (inl x) = north joinS¹S¹→S³ (inr x) = south joinS¹S¹→S³ (push a b i) = merid (S¹×S¹→S² a b) i {- Proving that this is an equivalence directly is painful, so we simply prove that it is equal to the old definition of the equivalence join S¹ S¹ ≃ S³ ≃ S₊ 3 To this end, we start by rephrasing the map -} private 3cell : (r i j k : I) → S₊ 3 3cell r i j k = hfill (λ r → λ {(i = i0) → merid (merid base j) (k ∧ ~ r) ; (i = i1) → merid (merid base j) (k ∧ ~ r) ; (j = i0) → merid north (k ∧ ~ r) ; (j = i1) → merid south (k ∧ ~ r) ; (k = i0) → north ; (k = i1) → merid (merid base j) (~ r)}) (inS (merid (merid (loop i) j) k)) r joinS¹S¹→S³' : join S¹ S¹ → S₊ 3 joinS¹S¹→S³' (inl x) = north joinS¹S¹→S³' (inr x) = north joinS¹S¹→S³' (push base b i) = north joinS¹S¹→S³' (push (loop i₁) base i) = north joinS¹S¹→S³' (push (loop i₁) (loop i₂) i) = 3cell i1 i₁ i₂ i {- These two maps are equal -} joinS¹S¹→S³'≡joinS¹S¹→S³' : (x : _) → joinS¹S¹→S³ x ≡ joinS¹S¹→S³' x joinS¹S¹→S³'≡joinS¹S¹→S³' (inl base) = refl joinS¹S¹→S³'≡joinS¹S¹→S³' (inl (loop i)) = refl joinS¹S¹→S³'≡joinS¹S¹→S³' (inr base) = sym (merid north) joinS¹S¹→S³'≡joinS¹S¹→S³' (inr (loop i)) = sym (merid north) joinS¹S¹→S³'≡joinS¹S¹→S³' (push base base i) k = merid north (~ k ∧ i) joinS¹S¹→S³'≡joinS¹S¹→S³' (push base (loop i₁) i) k = merid north (~ k ∧ i) joinS¹S¹→S³'≡joinS¹S¹→S³' (push (loop i₁) base i) k = (merid north) (~ k ∧ i) joinS¹S¹→S³'≡joinS¹S¹→S³' (push (loop i) (loop j) k) l = hcomp (λ r → λ { (i = i0) → merid (sym (rCancel (merid base)) (~ r) j) (~ l ∧ k) ; (i = i1) → merid (sym (rCancel (merid base)) (~ r) j) (~ l ∧ k) ; (j = i0) → merid north (~ l ∧ k) ; (j = i1) → merid north (~ l ∧ k) ; (k = i0) → north ; (k = i1) → merid (sym (rCancel (merid base)) (~ r) j) (~ l) ; (l = i0) → merid (doubleCompPath-filler (sym (rCancel (merid base))) (cong (σ (S₊∙ 1)) loop) (rCancel (merid base)) r i j) k ; (l = i1) → 3cell i1 i j k}) (hcomp (λ r → λ {(i = i0) → merid (cp-fill base r j) (k ∧ ~ l) ; (i = i1) → merid (cp-fill base r j) (k ∧ ~ l) ; (j = i0) → merid north (~ l ∧ k) ; (j = i1) → merid (merid base (~ r)) (~ l ∧ k) ; (k = i0) → north ; (k = i1) → merid (cp-fill base r j) (~ l) ; (l = i0) → merid (cp-fill (loop i) r j) k ; (l = i1) → 3cell i1 i j k}) (hcomp (λ r → λ {(i = i0) → merid (merid base j) (k ∧ (~ r ∨ ~ l)) ; (i = i1) → merid (merid base j) (k ∧ (~ r ∨ ~ l)) ; (j = i0) → merid north (k ∧ (~ l ∨ ~ r)) ; (j = i1) → merid south (k ∧ (~ l ∨ ~ r)) ; (k = i0) → north ; (k = i1) → merid (merid base j) (~ r ∨ ~ l) ; (l = i0) → merid (merid (loop i) j) k ; (l = i1) → 3cell r i j k}) (merid (merid (loop i) j) k))) where cp-fill : (a : S¹) → _ cp-fill a = compPath-filler (merid a) (sym (merid base)) {- joinS¹S¹→S³' is equal to the original equivalence (modulo a flipping of interval variables) -} joinS¹S¹→S³'Id : (x : join S¹ S¹) → joinS¹S¹→S³' x ≡ (Iso.fun IsoS³S3 ∘ flip₀₂S³ ∘ joinS¹S¹→S3) x joinS¹S¹→S³'Id (inl x) = refl joinS¹S¹→S³'Id (inr x) = refl joinS¹S¹→S³'Id (push base base i) = refl joinS¹S¹→S³'Id (push base (loop i₁) i) = refl joinS¹S¹→S³'Id (push (loop i₁) base i) = refl joinS¹S¹→S³'Id (push (loop i) (loop j) k) l = hcomp (λ r → λ {(i = i0) → merid (merid base (j ∧ ~ l)) (~ r ∧ k) ; (i = i1) → merid (merid base (j ∧ ~ l)) (~ r ∧ k) ; (j = i0) → merid north (k ∧ ~ r) ; (j = i1) → merid (merid base (~ l)) (~ r ∧ k) ; (k = i0) → north ; (k = i1) → merid (merid base (j ∧ ~ l)) (~ r) ; (l = i0) → 3cell r i j k ; (l = i1) → Iso.fun (IsoType→IsoSusp S²IsoSuspS¹) (meridian-contraction-2 k j i r)}) (merid (S²Cube i j l) k) where S²Cube : Cube {A = S₊ 2} (λ j l → merid base (j ∧ ~ l)) (λ j l → merid base (j ∧ ~ l)) (λ i l → north) (λ i l → merid base (~ l)) (λ i j → merid (loop i) j) λ i j → fun S²IsoSuspS¹ (surf j i) S²Cube i j l = hcomp (λ r → λ {(i = i0) → merid base (j ∧ (~ l ∨ ~ r)) ; (i = i1) → merid base (j ∧ (~ l ∨ ~ r)) ; (j = i0) → north ; (j = i1) → merid base (~ l ∨ ~ r) ; (l = i0) → merid (loop i) j ; (l = i1) → meridian-contraction j i r}) (merid (loop i) j) {-So, finally our map joinS¹S¹→S³ is an iso. We state its inverse explicitly. -} Iso-joinS¹S¹-S³ : Iso (join S¹ S¹) (S₊ 3) fun Iso-joinS¹S¹-S³ = joinS¹S¹→S³ inv Iso-joinS¹S¹-S³ = S³→joinS¹S¹ ∘ flip₀₂S³ ∘ Iso.inv IsoS³S3 rightInv Iso-joinS¹S¹-S³ x = joinS¹S¹→S³'≡joinS¹S¹→S³' ((S³→joinS¹S¹ ∘ flip₀₂S³ ∘ Iso.inv IsoS³S3) x) ∙∙ joinS¹S¹→S³'Id ((S³→joinS¹S¹ ∘ flip₀₂S³ ∘ Iso.inv IsoS³S3) x) ∙∙ Iso.leftInv (compIso (invIso IsoS³S3) (compIso flip₀₂S³Iso (S³IsojoinS¹S¹))) x leftInv Iso-joinS¹S¹-S³ x = cong (S³→joinS¹S¹ ∘ flip₀₂S³ ∘ inv IsoS³S3) (joinS¹S¹→S³'≡joinS¹S¹→S³' x ∙ joinS¹S¹→S³'Id x) ∙ Iso.rightInv (compIso (invIso IsoS³S3) (compIso flip₀₂S³Iso (S³IsojoinS¹S¹))) x {- We now get the full iso Sⁿ * Sᵐ ≃ Sⁿ⁺ᵐ⁺¹ -} IsoSphereJoin : (n m : ℕ) → Iso (join (S₊ n) (S₊ m)) (S₊ (suc (n + m))) IsoSphereJoin zero zero = compIso (invIso Susp-iso-joinBool) (invIso S¹IsoSuspBool) IsoSphereJoin zero (suc m) = compIso join-comm (invIso Susp-iso-joinBool) IsoSphereJoin (suc zero) zero = (invIso Susp-iso-joinBool) IsoSphereJoin (suc zero) (suc zero) = Iso-joinS¹S¹-S³ IsoSphereJoin (suc zero) (suc (suc m)) = compIso join-comm (compIso (compIso (Iso-joinSusp-suspJoin {A = S₊∙ (suc m)} {B = S₊∙ (suc zero)}) (congSuspIso join-comm)) (congSuspIso (IsoSphereJoin (suc zero) (suc m)))) IsoSphereJoin (suc (suc n)) m = compIso (Iso-joinSusp-suspJoin {A = S₊∙ (suc n)} {B = S₊∙ m}) (congSuspIso (IsoSphereJoin (suc n) m)) {- Pointedness holds by refl. This is due to the explicit definition of Iso-joinSusp-suspJoin -} IsoSphereJoinPres∙ : (n m : ℕ) → Iso.fun (IsoSphereJoin n m) (inl (ptSn n)) ≡ ptSn (suc (n + m)) IsoSphereJoinPres∙ zero zero = refl IsoSphereJoinPres∙ zero (suc m) = refl IsoSphereJoinPres∙ (suc zero) zero = refl IsoSphereJoinPres∙ (suc zero) (suc zero) = refl IsoSphereJoinPres∙ (suc zero) (suc (suc m)) = refl IsoSphereJoinPres∙ (suc (suc n)) m = refl IsoSphereJoin⁻Pres∙ : (n m : ℕ) → Iso.inv (IsoSphereJoin n m) (ptSn (suc (n + m))) ≡ inl (ptSn n) IsoSphereJoin⁻Pres∙ n m = cong (Iso.inv (IsoSphereJoin n m)) (sym (IsoSphereJoinPres∙ n m)) ∙ Iso.leftInv (IsoSphereJoin n m) (inl (ptSn n)) -- Inversion on spheres invSphere : {n : ℕ} → S₊ n → S₊ n invSphere {n = zero} = not invSphere {n = (suc zero)} = invLooper invSphere {n = (suc (suc n))} = invSusp invSphere² : (n : ℕ) (x : S₊ n) → invSphere (invSphere x) ≡ x invSphere² zero = notnot invSphere² (suc zero) base = refl invSphere² (suc zero) (loop i) = refl invSphere² (suc (suc n)) = invSusp² -- Interaction between σ and invSphere σ-invSphere : (n : ℕ) (x : S₊ (suc n)) → σ (S₊∙ (suc n)) (invSphere x) ≡ sym (σ (S₊∙ (suc n)) x) σ-invSphere zero base = rCancel (merid base) ∙∙ refl ∙∙ cong sym (sym (rCancel (merid base))) σ-invSphere zero (loop i) j = hcomp (λ k → λ { (j = i0) → doubleCompPath-filler (sym (rCancel (merid base))) (λ i → (σ (S₊∙ 1) (loop (~ i)))) (rCancel (merid base)) (~ k) i ; (j = i1) → doubleCompPath-filler (sym (cong sym (rCancel (merid base)))) (λ i → sym (σ (S₊∙ 1) (loop i))) (cong sym (rCancel (merid base))) (~ k) i}) (sym≡cong-sym (sym (rCancel (merid base)) ∙∙ (λ i → (σ (S₊∙ 1) (loop i))) ∙∙ (rCancel (merid base))) j i) σ-invSphere (suc n) x = toSusp-invSusp (S₊∙ (suc n)) x -- Some facts about the map S¹×S¹→S² -- Todo: generalise to Sⁿ×Sᵐ→Sⁿ⁺ᵐ S¹×S¹→S²rUnit : (a : S¹) → S¹×S¹→S² a base ≡ north S¹×S¹→S²rUnit base = refl S¹×S¹→S²rUnit (loop i) = refl S¹×S¹→S²x+x : (x : S¹) → S¹×S¹→S² x x ≡ north S¹×S¹→S²x+x base = refl S¹×S¹→S²x+x (loop i) k = lem k i where lem : cong₂ S¹×S¹→S² loop loop ≡ refl lem = cong₂Funct S¹×S¹→S² loop loop ∙ (λ i → rUnit (cong (λ x → S¹×S¹→S²rUnit x i) loop) (~ i)) S¹×S¹→S²-antiComm : (a b : S¹) → S¹×S¹→S² a b ≡ S¹×S¹→S² b (invLooper a) S¹×S¹→S²-antiComm base base = refl S¹×S¹→S²-antiComm base (loop i) = refl S¹×S¹→S²-antiComm (loop i) base = refl S¹×S¹→S²-antiComm (loop i) (loop j) k = sym≡flipSquare (λ j i → S¹×S¹→S² (loop i) (loop j)) (~ k) i j private S¹×S¹→S²-Distr-filler : (i : I) → cong₂ (λ b c → S¹×S¹→S² ((loop i) * b) c) loop loop ≡ cong (S¹×S¹→S² (loop i)) loop S¹×S¹→S²-Distr-filler i = cong₂Funct (λ b c → S¹×S¹→S² ((loop i) * b) c) loop loop ∙∙ (λ j → cong (λ x → S¹×S¹→S²rUnit (rotLoop x i) j) loop ∙ cong (λ c → S¹×S¹→S² (loop i) c) loop) ∙∙ sym (lUnit _) S¹×S¹→S²-Distr : (a b : S¹) → S¹×S¹→S² (a * b) b ≡ S¹×S¹→S² a b S¹×S¹→S²-Distr a base j = S¹×S¹→S² (rUnitS¹ a j) base S¹×S¹→S²-Distr base (loop i) k = S¹×S¹→S²-Distr-filler i0 k i S¹×S¹→S²-Distr (loop i₁) (loop i) k = S¹×S¹→S²-Distr-filler i₁ k i invSusp∘S¹×S¹→S² : (a b : S¹) → S¹×S¹→S² a (invLooper b) ≡ invSusp (S¹×S¹→S² a b) invSusp∘S¹×S¹→S² base b = merid base invSusp∘S¹×S¹→S² (loop i) base = merid base invSusp∘S¹×S¹→S² (loop i) (loop j) k = hcomp (λ r → λ {(i = i0) → i-Boundary₂ r j k ; (i = i1) → i-Boundary₂ r j k ; (j = i0) → m-b k ; (j = i1) → m-b k ; (k = i0) → doubleCompPath-filler rCancel-mb⁻¹ (cong σ₁ loop) rCancel-mb r i (~ j) ; (k = i1) → invSusp (doubleCompPath-filler rCancel-mb⁻¹ (cong σ₁ loop) rCancel-mb r i j)}) (hcomp (λ r → λ {(i = i0) → i-Boundary r (~ j) k ; (i = i1) → i-Boundary r (~ j) k ; (j = i0) → merid base (~ r ∨ k) ; (j = i1) → merid base (r ∧ k) ; (k = i0) → cp-filler (loop i) r (~ j) ; (k = i1) → invSusp (cp-filler (loop i) r j)}) (merid (loop i) (~ j))) where σ₁ = σ (S₊∙ 1) m-b = merid base rCancel-mb = rCancel m-b rCancel-mb⁻¹ = sym (rCancel m-b) cp-filler : (a : S¹) (i j : I) → S₊ 2 cp-filler a i j = compPath-filler (merid a) (sym (merid base)) i j i-Boundary : I → I → I → S₊ 2 i-Boundary r j k = hfill (λ r → λ{(j = i0) → m-b (k ∧ r) ; (j = i1) → m-b (~ r ∨ k) ; (k = i0) → cp-filler base r j ; (k = i1) → invSusp (cp-filler base r (~ j))}) (inS (m-b j)) r i-Boundary₂ : I → I → I → S₊ 2 i-Boundary₂ r j k = hcomp (λ i → λ {(r = i0) → i-Boundary i (~ j) k ; (r = i1) → m-b k ; (j = i0) → m-b (k ∨ (~ i ∧ ~ r)) ; (j = i1) → m-b (k ∧ (i ∨ r)) ; (k = i0) → rCancel-filler m-b i r (~ j) ; (k = i1) → invSusp (rCancel-filler m-b i r j) }) (hcomp (λ i → λ {(r = i0) → m-b (~ j ∨ (~ i ∧ k)) ; (r = i1) → m-b (k ∨ (~ i ∧ ~ j)) ; (j = i0) → m-b (k ∨ (~ r ∨ ~ i)) ; (j = i1) → m-b (k ∧ (~ i ∨ r)) ; (k = i0) → m-b (~ j ∧ (~ r ∨ ~ i)) ; (k = i1) → m-b ((~ j ∨ ~ i) ∨ r) }) (m-b (~ j ∨ k))) -- Interaction between S¹×S¹→S² and SuspS¹→S² SuspS¹→S²-S¹×S¹→S² : (a b : S¹) → (SuspS¹→S² (S¹×S¹→S² a b)) ≡ (S¹×S¹→S²' b a) SuspS¹→S²-S¹×S¹→S² base base = refl SuspS¹→S²-S¹×S¹→S² base (loop i) = refl SuspS¹→S²-S¹×S¹→S² (loop i) base = refl SuspS¹→S²-S¹×S¹→S² (loop i) (loop j) k = hcomp (λ r → λ {(i = i0) → rUnit (λ _ → base) (~ r ∧ ~ k) j ; (i = i1) → rUnit (λ _ → base) (~ r ∧ ~ k) j ; (j = i0) → base ; (j = i1) → base ; (k = i0) → SuspS¹→S² (doubleCompPath-filler ( sym (rCancel (merid base))) ((λ i → merid (loop i) ∙ sym (merid base))) (rCancel (merid base)) r i j ) ; (k = i1) → surf j i}) (hcomp (λ r → λ {(i = i0) → rUnit (λ _ → base) (r ∧ ~ k) j ; (i = i1) → rUnit (λ _ → base) (r ∧ ~ k) j ; (j = i0) → base ; (j = i1) → base ; (k = i0) → SuspS¹→S² (compPath-filler (merid (loop i)) (sym (merid base)) r j) ; (k = i1) → surf j i}) (surf j i))
47.630919
138
0.455364
30c88137469bfee1735711298f59d8c487492f2a
682
agda
Agda
test/interaction/ExtendedLambdaCase.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/ExtendedLambdaCase.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/ExtendedLambdaCase.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module ExtendedLambdaCase where data Bool : Set where true false : Bool data Void : Set where foo : Bool → Bool → Bool → Bool foo = λ { x → λ { y z → {!!} } } module parameterised {A : Set}(B : A → Set) where data Bar : (Bool → Bool) → Set where baz : (t : Void) → Bar λ { x → {!!} } -- with hidden argument data Bar' : (Bool → Bool) → Set where baz' : {t : Void} → (t' : Void) → Bar' λ { x' → {!!} } baz : Bool → {w : Bool} → Bool baz = λ { z {w} → {!!} } another-short-name : {A : Set} → (A → {x : A} → A → A) another-short-name = {! λ { a {x} b → a } !} f : Set f = (y : Bool) → parameterised.Bar {Bool}(λ _ → Void) (λ { true → true ; false → false })
23.517241
90
0.516129
3046b3c89b9f5a35e41fe8288a32800f4cd2c5dc
251
agda
Agda
Numeral/Integer/Relation/Divisibility.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Numeral/Integer/Relation/Divisibility.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Numeral/Integer/Relation/Divisibility.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Numeral.Integer.Relation.Divisibility where open import Functional open import Logic.Propositional import Numeral.Natural.Relation.Divisibility as ℕ open import Numeral.Integer open import Type _∣_ = (ℕ._∣_) on₂ absₙ _∤_ = (¬_) ∘₂ (_∣_)
22.818182
54
0.76494
11783e699013502c0400723d13d50aa92f4910a6
23,281
agda
Agda
src/Bisimilarity/Up-to/Counterexamples.agda
nad/up-to
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
[ "MIT" ]
null
null
null
src/Bisimilarity/Up-to/Counterexamples.agda
nad/up-to
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
[ "MIT" ]
null
null
null
src/Bisimilarity/Up-to/Counterexamples.agda
nad/up-to
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Some counterexamples ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} module Bisimilarity.Up-to.Counterexamples where open import Equality.Propositional open import Logical-equivalence using (_⇔_) open import Prelude open import Prelude.Size open import Bijection equality-with-J using (_↔_) open import Equality.Decision-procedures equality-with-J open import Fin equality-with-J open import Function-universe equality-with-J hiding (id; _∘_) open import Surjection equality-with-J using (_↠_) open import Indexed-container using (Container; ν; ⟦_⟧; force) open import Labelled-transition-system import Up-to import Bisimilarity import Bisimilarity.Classical open import Bisimilarity.Comparison import Bisimilarity.Equational-reasoning-instances import Bisimilarity.Step import Bisimilarity.Up-to open import Equational-reasoning open import Relation private -- A combination of some parametrised modules. module Combination {ℓ} (lts : LTS ℓ) where open Bisimilarity lts public open Bisimilarity.Classical lts public using (Progression) open Bisimilarity.Up-to lts public open LTS lts public hiding (_[_]⟶_) private module S = Bisimilarity.Step lts (LTS._[_]⟶_ lts) (LTS._[_]⟶_ lts) open S public using (Step; Step↔StepC) hiding (module Step) module Step where open S public using (⟨_,_⟩) open S.Step public -- There is a size-preserving relation transformer that is neither -- monotone nor extensive. ∃size-preserving׬[monotone⊎extensive] : ∃ λ (lts : LTS lzero) → let open Combination lts in ∃ λ (F : Trans₂ (# 0) Proc) → Size-preserving F × ¬ (Monotone F ⊎ Extensive F) ∃size-preserving׬[monotone⊎extensive] = one-loop , F , F-pres , [ ¬-F-mono , ¬-F-extensive ] where open Combination one-loop F : Trans₂ (# 0) Proc F R = ¬_ ∘ R ¬-F-mono : ¬ Monotone F ¬-F-mono = Monotone F ↝⟨ (λ mono → mono {_}) ⟩ ((λ _ → ⊥) ⊆ (λ _ → ↑ _ ⊤) → F (λ _ → ⊥) ⊆ F (λ _ → ↑ _ ⊤)) ↔⟨⟩ ((λ _ → ⊥) ⊆ (λ _ → ↑ _ ⊤) → (λ _ → ¬ ⊥) ⊆ (λ _ → ¬ ↑ _ ⊤)) ↝⟨ _$ _ ⟩ (λ _ → ¬ ⊥) ⊆ (λ _ → ¬ ↑ _ ⊤) ↝⟨ (λ hyp → hyp {tt}) ⟩ (¬ ⊥ → ¬ ↑ _ ⊤) ↝⟨ _$ ⊥-elim ⟩ ¬ ↑ _ ⊤ ↝⟨ _$ _ ⟩□ ⊥ □ ¬-F-extensive : ¬ Extensive F ¬-F-extensive = Extensive F ↝⟨ (λ hyp → hyp _) ⟩ (↑ _ ⊤ → ¬ ↑ _ ⊤) ↝⟨ (_$ _) ∘ (_$ _) ⟩□ ⊥ □ total : ∀ {i x y} → [ i ] x ∼ y total = reflexive F-pres : Size-preserving F F-pres _ _ = total -- A slight strengthening of the previous result, with a somewhat more -- complicated proof: There are (at least two) size-preserving -- relation transformers that are neither monotone nor extensive. ∃-2-size-preserving׬[monotone⊎extensive] : ∃ λ (lts : LTS lzero) → let open Combination lts in ∃ λ (F : Trans₂ (# 0) Proc) → ∃ λ (G : Trans₂ (# 0) Proc) → Size-preserving F × ¬ (Monotone F ⊎ Extensive F) × Size-preserving G × ¬ (Monotone G ⊎ Extensive G) × F ≢ G ∃-2-size-preserving׬[monotone⊎extensive] = lts , F ⊤ , F ⊥ , F-pres , [ ¬-F-mono , ¬-F-extensive ] , F-pres , [ ¬-F-mono , ¬-F-extensive ] , F⊤≢F⊥ where lts : LTS lzero lts = record { Proc = Bool ; Label = ⊥ ; _[_]⟶_ = λ _ () ; is-silent = λ () } open Combination lts F : Type → Trans₂ (# 0) Bool F A R p@(true , false) = R p × A F A R p@(false , true) = R p F A R p = ¬ R p ¬-F-mono : ∀ {A} → ¬ Monotone (F A) ¬-F-mono {A} = Monotone (F A) ↝⟨ (λ mono → mono {_}) ⟩ ((λ _ → ⊥) ⊆ (λ _ → ↑ _ ⊤) → F A (λ _ → ⊥) ⊆ F A (λ _ → ↑ _ ⊤)) ↝⟨ (λ hyp {p} → hyp _ {p}) ⟩ F A (λ _ → ⊥) ⊆ F A (λ _ → ↑ _ ⊤) ↝⟨ (λ hyp → hyp {true , true}) ⟩ (¬ ⊥ → ¬ ↑ _ ⊤) ↝⟨ _$ ⊥-elim ⟩ ¬ ↑ _ ⊤ ↝⟨ _$ _ ⟩□ ⊥ □ ¬-F-extensive : ∀ {A} → ¬ Extensive (F A) ¬-F-extensive {A} = Extensive (F A) ↝⟨ (λ hyp → hyp (λ _ → ↑ _ ⊤) {true , true}) ⟩ (↑ _ ⊤ → ¬ ↑ _ ⊤) ↝⟨ (_$ _) ∘ (_$ _) ⟩□ ⊥ □ F-pres : ∀ {A} → Size-preserving (F A) F-pres R⊆∼i {true , false} = R⊆∼i ∘ proj₁ F-pres R⊆∼i {false , true} = R⊆∼i F-pres _ {true , true} = λ _ → true ■ F-pres _ {false , false} = λ _ → false ■ F⊤≢F⊥ : F ⊤ ≢ F ⊥ F⊤≢F⊥ = F ⊤ ≡ F ⊥ ↝⟨ subst (λ F → F (λ _ → ⊤) (true , false)) ⟩ (F ⊤ (λ _ → ⊤) (true , false) → F ⊥ (λ _ → ⊤) (true , false)) ↔⟨⟩ (⊤ × ⊤ → ⊤ × ⊥) ↝⟨ proj₂ ∘ (_$ _) ⟩□ ⊥ □ -- There is a container C such that there are (at least two) relation -- transformers satisfying λ F → ∀ {i} → F (ν C i) ⊆ ν C i that are -- not up-to techniques with respect to C. ∃special-case-of-size-preserving׬up-to : ∃ λ (I : Type) → ∃ λ (C : Container I I) → ∃ λ (F : Trans (# 0) I) → ∃ λ (G : Trans (# 0) I) → (∀ {i} → F (ν C i) ⊆ ν C i) × ¬ Up-to.Up-to-technique C F × (∀ {i} → G (ν C i) ⊆ ν C i) × ¬ Up-to.Up-to-technique C G × F ≢ G ∃special-case-of-size-preserving׬up-to = (Proc × Proc) , StepC , G ⊤ , G ⊥ , bisimilarity-pre-fixpoint , ¬-up-to , bisimilarity-pre-fixpoint , ¬-up-to , G⊤≢G⊥ where data Proc : Type where p q r : Proc data _⟶_ : Proc → Proc → Type where p : p ⟶ p q : q ⟶ r lts = record { Proc = Proc ; Label = ⊤ ; _[_]⟶_ = λ p _ q → p ⟶ q ; is-silent = λ _ → false } open Combination lts hiding (Proc) G : Type → Trans₂ (# 0) Proc G A R x = R (r , r) → ¬ R (p , r) → R x × A p≁r : ∀ {i} → ¬ Bisimilarity i (p , r) p≁r hyp with left-to-right hyp p ... | _ , () , _ bisimilarity-pre-fixpoint : ∀ {A i} → G A (Bisimilarity i) ⊆ Bisimilarity i bisimilarity-pre-fixpoint hyp = proj₁ (hyp reflexive p≁r) data S : Rel₂ (# 0) Proc where pq : S (p , q) S⊆StepGS : ∀ {A} → S ⊆ Step (G A S) Step.left-to-right (S⊆StepGS pq) p = r , q , λ () Step.right-to-left (S⊆StepGS pq) q = p , p , λ () p≁q : ¬ Bisimilarity ∞ (p , q) p≁q hyp with left-to-right hyp p ... | r , q , p∼r = p≁r (force p∼r) ¬-up-to : ∀ {A} → ¬ Up-to-technique (G A) ¬-up-to {A} = Up-to-technique (G A) ↝⟨ (λ up-to → up-to) ⟩ (S ⊆ ⟦ StepC ⟧ (G A S) → S ⊆ Bisimilarity ∞) ↝⟨ (λ hyp below → hyp (Step↔StepC _ ∘ below)) ⟩ (S ⊆ Step (G A S) → S ⊆ Bisimilarity ∞) ↝⟨ _$ S⊆StepGS ⟩ S ⊆ Bisimilarity ∞ ↝⟨ _$ pq ⟩ Bisimilarity ∞ (p , q) ↝⟨ p≁q ⟩□ ⊥ □ G⊤≢G⊥ : G ⊤ ≢ G ⊥ G⊤≢G⊥ = G ⊤ ≡ G ⊥ ↝⟨ subst (λ G → G (uncurry _≡_) (q , q)) ⟩ (G ⊤ (uncurry _≡_) (q , q) → G ⊥ (uncurry _≡_) (q , q)) ↔⟨⟩ ((r ≡ r → p ≢ r → q ≡ q × ⊤) → (r ≡ r → p ≢ r → q ≡ q × ⊥)) ↝⟨ _$ (λ _ _ → refl , _) ⟩ (r ≡ r → p ≢ r → q ≡ q × ⊥) ↝⟨ proj₂ ∘ (_$ λ ()) ∘ (_$ refl) ⟩□ ⊥ □ -- There is a container C such that there are (at least two) relation -- transformers satisfying λ F → ∀ {i} → F (ν C i) ⊆ ν C i that are -- not size-preserving with respect to C. ∃special-case-of-size-preserving׬size-preserving : ∃ λ (I : Type) → ∃ λ (C : Container I I) → ∃ λ (F : Trans (# 0) I) → ∃ λ (G : Trans (# 0) I) → (∀ {i} → F (ν C i) ⊆ ν C i) × ¬ Up-to.Size-preserving C F × (∀ {i} → G (ν C i) ⊆ ν C i) × ¬ Up-to.Size-preserving C G × F ≢ G ∃special-case-of-size-preserving׬size-preserving = Σ-map id (Σ-map id (Σ-map id (Σ-map id (Σ-map id (Σ-map (_∘ Up-to.size-preserving→up-to _) (Σ-map id (Σ-map (_∘ Up-to.size-preserving→up-to _) id))))))) ∃special-case-of-size-preserving׬up-to -- There is a monotone, extensive and size-preserving relation -- transformer that is not compatible. ∃monotone×extensive×size-preserving׬compatible : ∃ λ (lts : LTS lzero) → let open Combination lts in ∃ λ (F : Trans₂ (# 0) Proc) → Monotone F × Extensive F × Size-preserving F × ¬ Compatible F ∃monotone×extensive×size-preserving׬compatible = one-transition , F , mono , extensive , pres , ¬comp where -- An LTS with two distinct processes and one transition from one to -- the other. one-transition : LTS lzero one-transition = record { Proc = Bool ; Label = ⊤ ; _[_]⟶_ = λ x _ y → T (x ∧ not y) ; is-silent = λ _ → false } open Combination one-transition -- A relation transformer. F : Trans₂ (# 0) Proc F R (true , true) = R (false , false) ⊎ R (true , true) F R = R -- F is monotone. mono : Monotone F mono R⊆S {true , true} = ⊎-map R⊆S R⊆S mono R⊆S {true , false} = R⊆S mono R⊆S {false , true} = R⊆S mono R⊆S {false , false} = R⊆S -- F is extensive. extensive : Extensive F extensive R {true , true} = inj₂ extensive R {true , false} = id extensive R {false , true} = id extensive R {false , false} = id -- Bisimilarity of size i is a pre-fixpoint of F. pre : ∀ {i} → F (Bisimilarity i) ⊆ Bisimilarity i pre {x = true , true} = λ _ → true ■ pre {x = true , false} = id pre {x = false , true} = id pre {x = false , false} = id -- F is size-preserving. pres : Size-preserving F pres = _⇔_.from (monotone→⇔ mono) (λ {_ x} → pre {x = x}) -- A relation. R : Rel₂ (# 0) Proc R _ = ⊥ -- A lemma. StepRff : Step R (false , false) Step.left-to-right StepRff () Step.right-to-left StepRff () -- F is not compatible. ¬comp : ¬ Compatible F ¬comp = Compatible F ↝⟨ (λ comp {x} → comp {x = x}) ⟩ F (⟦ StepC ⟧ R) ⊆ ⟦ StepC ⟧ (F R) ↝⟨ (λ le → le {true , true}) ⟩ (F (⟦ StepC ⟧ R) (true , true) → ⟦ StepC ⟧ (F R) (true , true)) ↔⟨⟩ (⟦ StepC ⟧ R (false , false) ⊎ ⟦ StepC ⟧ R (true , true) → ⟦ StepC ⟧ (F R) (true , true)) ↝⟨ _$ inj₁ (_⇔_.to (Step↔StepC _) StepRff) ⟩ ⟦ StepC ⟧ (F R) (true , true) ↝⟨ (λ step → StepC.left-to-right {p = true} {q = true} step {p′ = false} _ ) ⟩ (∃ λ y → T (not y) × F R (false , y)) ↔⟨⟩ (∃ λ y → T (not y) × ⊥) ↝⟨ proj₂ ∘ proj₂ ⟩□ ⊥ □ -- An LTS used in a couple of lemmas below, along with some -- properties. module PQR where -- An LTS with two sets of processes, three "to the left", and three -- "to the right". Side : Type Side = Bool pattern left = true pattern right = false data Process : Type where p q r : Side → Process data Label : Type where pq pr : Label qq rr : Side → Label infix 4 _[_]⟶_ data _[_]⟶_ : Process → Label → Process → Type where pq : ∀ {s} → p s [ pq ]⟶ q s pr : ∀ {s} → p s [ pr ]⟶ r s qq : ∀ {s} → q s [ qq s ]⟶ q s rr : ∀ {s} → r s [ rr s ]⟶ r s lts : LTS lzero lts = record { Proc = Process ; Label = Label ; _[_]⟶_ = _[_]⟶_ ; is-silent = λ _ → false } open Combination lts public hiding (Label) -- Two relation transformers: F and G both add (at most) one pair to -- the underlying relation. data F (R : Rel₂ (# 0) Proc) : Rel₂ (# 0) Proc where qq : F R (q left , q right) [_] : ∀ {x} → R x → F R x data G (R : Rel₂ (# 0) Proc) : Rel₂ (# 0) Proc where rr : G R (r left , r right) [_] : ∀ {x} → R x → G R x -- A relation that adds one pair to reflexivity. data S : Rel₂ (# 0) Proc where pp : S (p left , p right) refl : ∀ {x} → S (x , x) -- S progresses to F (G S). S-prog : Progression S (F (G S)) S-prog pp = Step.⟨ (λ where pq → _ , pq , qq pr → _ , pr , [ rr ]) , (λ where pq → _ , pq , qq pr → _ , pr , [ rr ]) ⟩ S-prog refl = Step.⟨ (λ where pq → _ , pq , [ [ refl ] ] pr → _ , pr , [ [ refl ] ] qq → _ , qq , [ [ refl ] ] rr → _ , rr , [ [ refl ] ]) , (λ where pq → _ , pq , [ [ refl ] ] pr → _ , pr , [ [ refl ] ] qq → _ , qq , [ [ refl ] ] rr → _ , rr , [ [ refl ] ]) ⟩ S-prog′ : S ⊆ ⟦ StepC ⟧ (F (G S)) S-prog′ Sx = _⇔_.to (Step↔StepC _) (S-prog Sx) -- The two processes q left and q right are not bisimilar. q≁q : ¬ q left ∼ q right q≁q = q left ∼ q right ↝⟨ (λ rel → StepC.left-to-right rel qq) ⟩ (∃ λ y → q right [ qq left ]⟶ y × q left ∼′ y) ↝⟨ (λ { (_ , () , _) }) ⟩□ ⊥ □ -- The two processes r left and r right are not bisimilar. r≁r : ¬ r left ∼ r right r≁r = r left ∼ r right ↝⟨ (λ rel → StepC.left-to-right rel rr) ⟩ (∃ λ y → r right [ rr left ]⟶ y × r left ∼′ y) ↝⟨ (λ { (_ , () , _) }) ⟩□ ⊥ □ -- F ∘ G is not an up-to technique. ¬-F∘G-up-to : ¬ Up-to-technique (F ∘ G) ¬-F∘G-up-to = Up-to-technique (F ∘ G) ↝⟨ (λ up-to → up-to S-prog′) ⟩ S ⊆ Bisimilarity ∞ ↝⟨ (λ le → le pp) ⟩ p left ∼ p right ↝⟨ (λ rel → StepC.left-to-right rel pq) ⟩ (∃ λ y → p right [ pq ]⟶ y × q left ∼′ y) ↝⟨ (λ { (.(q right) , pq , rel) → rel }) ⟩ q left ∼′ q right ↝⟨ (λ rel → q≁q (force rel)) ⟩ ⊥ □ -- F is not equal to G. F≢G : F ≢ G F≢G = F ≡ G ↝⟨ subst (λ F → F (λ _ → ⊥) (q left , q right)) ⟩ (F (λ _ → ⊥) (q left , q right) → G (λ _ → ⊥) (q left , q right)) ↝⟨ _$ qq ⟩ G (λ _ → ⊥) (q left , q right) ↝⟨ (λ { [ () ] }) ⟩□ ⊥ □ module F-lemmas where -- F is monotone. mono : Monotone F mono R⊆S qq = qq mono R⊆S [ Rxy ] = [ R⊆S Rxy ] -- F is extensive. ext : Extensive F ext = λ _ → [_] -- F is not size-preserving. ¬-pres : ¬ Size-preserving F ¬-pres = Size-preserving F ↝⟨ (λ pres → _⇔_.to (monotone→⇔ mono) pres) ⟩ F (Bisimilarity ∞) ⊆ Bisimilarity ∞ ↝⟨ _$ qq ⟩ q left ∼ q right ↝⟨ q≁q ⟩□ ⊥ □ -- F is an up-to technique. module _ {R} (R-prog′ : R ⊆ ⟦ StepC ⟧ (F R)) where R-prog : Progression R (F R) R-prog Rx = _⇔_.from (Step↔StepC _) (R-prog′ Rx) ¬rr : ∀ {s} → ¬ R (r s , r (not s)) ¬rr rel with Progression.left-to-right R-prog rel rr ¬rr {true} _ | _ , () , _ ¬rr {false} _ | _ , () , _ ¬qq : ∀ {s} → ¬ R (q s , q (not s)) ¬qq rel with Progression.left-to-right R-prog rel qq ¬qq {true} _ | _ , () , _ ¬qq {false} _ | _ , () , _ ¬pp : ∀ {s} → ¬ R (p s , p (not s)) ¬pp rel with Progression.left-to-right R-prog rel pr ... | .(r _) , pr , [ rel′ ] = ¬rr rel′ ¬pq : ∀ {s₁ s₂} → ¬ R (p s₁ , q s₂) ¬pq rel with Progression.left-to-right R-prog rel pq ... | _ , () , _ ¬qp : ∀ {s₁ s₂} → ¬ R (q s₁ , p s₂) ¬qp rel with Progression.right-to-left R-prog rel pq ... | _ , () , _ ¬pr : ∀ {s₁ s₂} → ¬ R (p s₁ , r s₂) ¬pr rel with Progression.left-to-right R-prog rel pq ... | _ , () , _ ¬rp : ∀ {s₁ s₂} → ¬ R (r s₁ , p s₂) ¬rp rel with Progression.right-to-left R-prog rel pq ... | _ , () , _ ¬qr : ∀ {s₁ s₂} → ¬ R (q s₁ , r s₂) ¬qr rel with Progression.right-to-left R-prog rel rr ... | _ , () , _ ¬rq : ∀ {s₁ s₂} → ¬ R (r s₁ , q s₂) ¬rq rel with Progression.left-to-right R-prog rel rr ... | _ , () , _ up-to : R ⊆ Bisimilarity ∞ up-to {p left , p left} rel = reflexive up-to {p left , p right} rel = ⊥-elim (¬pp rel) up-to {p right , p left} rel = ⊥-elim (¬pp rel) up-to {p right , p right} rel = reflexive up-to {p _ , q _} rel = ⊥-elim (¬pq rel) up-to {p _ , r _} rel = ⊥-elim (¬pr rel) up-to {q _ , p _} rel = ⊥-elim (¬qp rel) up-to {q left , q left} rel = reflexive up-to {q left , q right} rel = ⊥-elim (¬qq rel) up-to {q right , q left} rel = ⊥-elim (¬qq rel) up-to {q right , q right} rel = reflexive up-to {q _ , r _} rel = ⊥-elim (¬qr rel) up-to {r _ , p _} rel = ⊥-elim (¬rp rel) up-to {r _ , q _} rel = ⊥-elim (¬rq rel) up-to {r left , r left} rel = reflexive up-to {r left , r right} rel = ⊥-elim (¬rr rel) up-to {r right , r left} rel = ⊥-elim (¬rr rel) up-to {r right , r right} rel = reflexive module G-lemmas where -- G is monotone. mono : Monotone G mono R⊆S rr = rr mono R⊆S [ Rxy ] = [ R⊆S Rxy ] -- G is extensive. ext : Extensive G ext = λ _ → [_] -- G is not size-preserving. ¬-pres : ¬ Size-preserving G ¬-pres = Size-preserving G ↝⟨ (λ pres → _⇔_.to (monotone→⇔ mono) pres) ⟩ G (Bisimilarity ∞) ⊆ Bisimilarity ∞ ↝⟨ _$ rr ⟩ r left ∼ r right ↝⟨ r≁r ⟩□ ⊥ □ -- G is an up-to technique. module _ {R} (R-prog′ : R ⊆ ⟦ StepC ⟧ (G R)) where R-prog : Progression R (G R) R-prog Rx = _⇔_.from (Step↔StepC _) (R-prog′ Rx) ¬rr : ∀ {s} → ¬ R (r s , r (not s)) ¬rr rel with Progression.left-to-right R-prog rel rr ¬rr {true} _ | _ , () , _ ¬rr {false} _ | _ , () , _ ¬qq : ∀ {s} → ¬ R (q s , q (not s)) ¬qq rel with Progression.left-to-right R-prog rel qq ¬qq {true} _ | _ , () , _ ¬qq {false} _ | _ , () , _ ¬pp : ∀ {s} → ¬ R (p s , p (not s)) ¬pp rel with Progression.left-to-right R-prog rel pq ... | .(q _) , pq , [ rel′ ] = ¬qq rel′ ¬pq : ∀ {s₁ s₂} → ¬ R (p s₁ , q s₂) ¬pq rel with Progression.left-to-right R-prog rel pq ... | _ , () , _ ¬qp : ∀ {s₁ s₂} → ¬ R (q s₁ , p s₂) ¬qp rel with Progression.right-to-left R-prog rel pq ... | _ , () , _ ¬pr : ∀ {s₁ s₂} → ¬ R (p s₁ , r s₂) ¬pr rel with Progression.left-to-right R-prog rel pq ... | _ , () , _ ¬rp : ∀ {s₁ s₂} → ¬ R (r s₁ , p s₂) ¬rp rel with Progression.right-to-left R-prog rel pq ... | _ , () , _ ¬qr : ∀ {s₁ s₂} → ¬ R (q s₁ , r s₂) ¬qr rel with Progression.right-to-left R-prog rel rr ... | _ , () , _ ¬rq : ∀ {s₁ s₂} → ¬ R (r s₁ , q s₂) ¬rq rel with Progression.left-to-right R-prog rel rr ... | _ , () , _ up-to : R ⊆ Bisimilarity ∞ up-to {p left , p left} rel = reflexive up-to {p left , p right} rel = ⊥-elim (¬pp rel) up-to {p right , p left} rel = ⊥-elim (¬pp rel) up-to {p right , p right} rel = reflexive up-to {p _ , q _} rel = ⊥-elim (¬pq rel) up-to {p _ , r _} rel = ⊥-elim (¬pr rel) up-to {q _ , p _} rel = ⊥-elim (¬qp rel) up-to {q left , q left} rel = reflexive up-to {q left , q right} rel = ⊥-elim (¬qq rel) up-to {q right , q left} rel = ⊥-elim (¬qq rel) up-to {q right , q right} rel = reflexive up-to {q _ , r _} rel = ⊥-elim (¬qr rel) up-to {r _ , p _} rel = ⊥-elim (¬rp rel) up-to {r _ , q _} rel = ⊥-elim (¬rq rel) up-to {r left , r left} rel = reflexive up-to {r left , r right} rel = ⊥-elim (¬rr rel) up-to {r right , r left} rel = ⊥-elim (¬rr rel) up-to {r right , r right} rel = reflexive -- There are monotone and extensive up-to techniques F and G such -- that F ∘ G is not an up-to-technique. -- -- Pous and Sangiorgi discuss another instance of this property in -- Section 6.5.4 of "Enhancements of the bisimulation proof method". ∃[monotone×extensive×up-to]²×¬∘-up-to : ∃ λ (lts : LTS lzero) → let open Combination lts in ∃ λ (F : Trans₂ (# 0) Proc) → ∃ λ (G : Trans₂ (# 0) Proc) → Monotone F × Extensive F × Up-to-technique F × Monotone G × Extensive G × Up-to-technique G × ¬ Up-to-technique (F ∘ G) ∃[monotone×extensive×up-to]²×¬∘-up-to = lts , F , G , F-lemmas.mono , F-lemmas.ext , F-lemmas.up-to , G-lemmas.mono , G-lemmas.ext , G-lemmas.up-to , ¬-F∘G-up-to where open PQR -- It is not the case that every monotone and extensive up-to -- technique is size-preserving. ¬monotone×extensive×up-to→size-preserving : ∃ λ (lts : LTS lzero) → let open Combination lts in ¬ (∀ {F} → Monotone F → Extensive F → Up-to-technique F → Size-preserving F) ¬monotone×extensive×up-to→size-preserving = lts , λ up-to→pres → ¬-F∘G-up-to $ size-preserving→up-to $ ∘-closure (up-to→pres F-lemmas.mono F-lemmas.ext F-lemmas.up-to) (up-to→pres G-lemmas.mono G-lemmas.ext G-lemmas.up-to) where open PQR -- Up-to-technique is not closed under composition, not even for -- monotone and extensive relation transformers. ¬-∘-closure : ∃ λ (lts : LTS lzero) → let open Combination lts in ¬ ({F G : Trans₂ (# 0) Proc} → Monotone F → Extensive F → Monotone G → Extensive G → Up-to-technique F → Up-to-technique G → Up-to-technique (F ∘ G)) ¬-∘-closure = lts , λ ∘-closure → ¬-F∘G-up-to (∘-closure F-lemmas.mono F-lemmas.ext G-lemmas.mono G-lemmas.ext F-lemmas.up-to G-lemmas.up-to) where open PQR -- There are (at least two) monotone and extensive up-to techniques -- that are not size-preserving. ∃monotone×extensive×up-to׬size-preserving : ∃ λ (lts : LTS lzero) → let open Combination lts in ∃ λ (F : Trans₂ (# 0) Proc) → ∃ λ (G : Trans₂ (# 0) Proc) → Monotone F × Extensive F × Up-to-technique F × ¬ Size-preserving F × Monotone G × Extensive G × Up-to-technique G × ¬ Size-preserving G × F ≢ G ∃monotone×extensive×up-to׬size-preserving = lts , F , G , F-lemmas.mono , F-lemmas.ext , F-lemmas.up-to , F-lemmas.¬-pres , G-lemmas.mono , G-lemmas.ext , G-lemmas.up-to , G-lemmas.¬-pres , F≢G where open PQR
31.848153
147
0.46321
ccb5da3c8f74d61d13d50844c05bc77b1890167d
8,123
agda
Agda
agda/sn-calculus-confluence/potpot.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
3
2020-04-16T10:58:53.000Z
2020-07-01T03:59:31.000Z
agda/sn-calculus-confluence/potpot.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
null
null
null
agda/sn-calculus-confluence/potpot.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
1
2020-04-15T20:02:49.000Z
2020-04-15T20:02:49.000Z
module sn-calculus-confluence.potpot where open import utility open import sn-calculus open import context-properties using (->pot-view) open import Esterel.Lang open import Esterel.Lang.CanFunction using (Can ; Canₛ ; Canₛₕ ; Canθ ; Canθₛ ; Canθₛₕ) open import Esterel.Lang.CanFunction.Properties using ( canθₛ-set-sig-monotonic-absence-lemma ; canθₛₕ-set-sig-monotonic-absence-lemma ; canθ-shr-var-irr ) open import Esterel.Environment as Env using (Env ; Θ ; _←_ ; module SigMap ; module ShrMap ; module VarMap) open import Esterel.Context open import Esterel.CompletionCode as Code using () renaming (CompletionCode to Code) open import Esterel.Variable.Signal as Signal using (Signal) open import Esterel.Variable.Shared as SharedVar using (SharedVar) open import Esterel.Variable.Sequential as SeqVar using (SeqVar) open import Data.Bool using (Bool ; true ; false ; if_then_else_) open import Data.Empty using (⊥ ; ⊥-elim) open import Data.List using (List ; [] ; _∷_ ; [_]) open import Data.List.Any using (Any ; here ; there ; any) open import Data.Maybe using (Maybe ; just ; nothing) open import Data.Nat using (ℕ ; _≟_ ; zero ; suc ; _+_) open import Data.Nat.Properties.Simple using ( +-comm ; +-assoc) open import Data.Product using (Σ ; Σ-syntax ; _,_ ; proj₁ ; proj₂ ; _,′_ ; _×_) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) open import Function using (_∘_ ; id ; _∋_) open import Relation.Nullary using (¬_ ; Dec ; yes ; no) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym ; trans ; cong ; subst ; module ≡-Reasoning) open ->pot-view open ≡-Reasoning using (begin_ ; _∎ ; _≡⟨_⟩_ ; _≡⟨⟩_) open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM pot-pot-conf-rec : ∀{p θ ql θl qr θr eql eqr A Al Ar Aql Arl} → {ρθ·psn⟶₁ρθl·ql : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θl , Al ⟩· ql)} → {ρθ·psn⟶₁ρθr·qr : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θr , Ar ⟩· qr)} → ->pot-view ρθ·psn⟶₁ρθl·ql eql Aql → ->pot-view ρθ·psn⟶₁ρθr·qr eqr Arl → (ρ⟨ θl , Al ⟩· ql ≡ ρ⟨ θr , Ar ⟩· qr) ⊎ Σ[ θo ∈ Env ] (ρ⟨ θl , Al ⟩· ql) sn⟶₁ (ρ⟨ θo , A ⟩· p) × (ρ⟨ θr , Ar ⟩· qr) sn⟶₁ (ρ⟨ θo , A ⟩· p) pot-pot-conf-rec {p} {θ} {.p} {θl} {.p} {θr} {_} {_} {A} {.A} {.A} {refl} {refl} {.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)} {.(rabsence {θ} {p} {S'} S'∈ θS'≡unknown S'∉can-p-θ)} (vabsence S S∈ θS≡unknown S∉can-p-θ) (vabsence S' S'∈ θS'≡unknown S'∉can-p-θ) with S Signal.≟ S' ... | yes refl = inj₁ refl ... | no S≢S' = inj₂ (_ , subst (λ sig* → ρ⟨ θl , A ⟩· p sn⟶₁ ρ⟨ (Θ sig* (Env.shr θl) (Env.var θl)) , A ⟩· p) (SigMap.put-comm {_} {Env.sig θ} {S} {S'} {Signal.absent} {Signal.absent} S≢S') (rabsence {θl} {p} {S'} S'∈Domθl θlS'≡unknown (λ S'∈can-p-θl → S'∉can-p-θ (canθₛ-set-sig-monotonic-absence-lemma (Env.sig θ) 0 p S Env.[]env S∈ θS≡unknown (Signal.unwrap S') S'∈can-p-θl))) ,′ rabsence {θr} {p} {S} S∈Domθr θrS≡unknown (λ S∈can-p-θr → S∉can-p-θ (canθₛ-set-sig-monotonic-absence-lemma (Env.sig θ) 0 p S' Env.[]env S'∈ θS'≡unknown (Signal.unwrap S) S∈can-p-θr))) where S∈Domθr = Env.sig-set-mono' {S} {S'} {θ} {Signal.absent} {S'∈} S∈ S'∈Domθl = Env.sig-set-mono' {S'} {S} {θ} {Signal.absent} {S∈} S'∈ θrS≡unknown = SigMap.putputget {_} {Env.sig θ} {S} {S'} {Signal.unknown} {Signal.absent} S≢S' S∈ S∈Domθr θS≡unknown θlS'≡unknown = SigMap.putputget {_} {Env.sig θ} {S'} {S} {Signal.unknown} {Signal.absent} (S≢S' ∘ sym) S'∈ S'∈Domθl θS'≡unknown pot-pot-conf-rec {p} {θ} {.p} {θl} {.p} {θr} {_} {_} {A} {.A} {.A} {refl} {refl} {.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)} {.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)} (vabsence S S∈ θS≡unknown S∉can-p-θ) (vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ) = inj₂ (_ , rreadyness {θl} {p} {s} s∈ θs≡old⊎θs≡new (λ s∈can-p-θl → s∉can-p-θ (canθₛₕ-set-sig-monotonic-absence-lemma (Env.sig θ) 0 p S Env.[]env S∈ θS≡unknown (SharedVar.unwrap s) s∈can-p-θl)) ,′ rabsence {θr} {p} {S} S∈ θS≡unknown (λ S∈can-p-θr → S∉can-p-θ (subst (Signal.unwrap S ∈_) (cong proj₁ (canθ-shr-var-irr (Env.sig θ) 0 p Env.[]env Env.[]env refl)) S∈can-p-θr))) pot-pot-conf-rec {p} {θ} {.p} {θl} {.p} {θr} {_} {_} {A} {.A} {.A} {refl} {refl} {.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)} {.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)} (vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ) (vabsence S S∈ θS≡unknown S∉can-p-θ) = inj₂ (_ , rabsence {θl} {p} {S} S∈ θS≡unknown (λ S∈can-p-θl → S∉can-p-θ (subst (Signal.unwrap S ∈_) (cong proj₁ (canθ-shr-var-irr (Env.sig θ) 0 p Env.[]env Env.[]env refl)) S∈can-p-θl)) ,′ rreadyness {θr} {p} {s} s∈ θs≡old⊎θs≡new (λ s∈can-p-θr → s∉can-p-θ (canθₛₕ-set-sig-monotonic-absence-lemma (Env.sig θ) 0 p S Env.[]env S∈ θS≡unknown (SharedVar.unwrap s) s∈can-p-θr))) pot-pot-conf-rec {p} {θ} {.p} {θl} {.p} {θr} {_} {_} {A} {.A} {.A} {refl} {refl} {.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)} {.(rreadyness {θ} {p} {s'} s'∈ θs'≡old⊎θs'≡new s'∉can-p-θ)} (vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ) (vreadyness s' s'∈ θs'≡old⊎θs'≡new s'∉can-p-θ) with s SharedVar.≟ s' ... | yes refl rewrite Env.shr-vals-∈-irr {s'} {θ} s∈ s'∈ = inj₁ refl ... | no s≢s' = inj₂ (_ , subst (λ shr* → ρ⟨ θl , A ⟩· p sn⟶₁ ρ⟨ (Θ (Env.sig θl) shr* (Env.var θl)) , A ⟩· p) (cong Env.shr (begin Env.set-shr {s'} θl s'∈Domθl SharedVar.ready (Env.shr-vals {s'} θl s'∈Domθl) ≡⟨ cong (Env.set-shr {s'} θl s'∈Domθl SharedVar.ready ∘ proj₂) θls'≡θs' ⟩ Env.set-shr {s'} θl s'∈Domθl SharedVar.ready θs' ≡⟨ cong (λ shr* → Θ (Env.sig θ) shr* (Env.var θ)) (ShrMap.put-comm {_} {Env.shr θ} {s} {s'} {SharedVar.ready , θs} {SharedVar.ready , θs'} s≢s') ⟩ Env.set-shr {s} θr s∈Domθr SharedVar.ready θs ≡⟨ cong (Env.set-shr {s} θr s∈Domθr SharedVar.ready ∘ proj₂) (sym θrs≡θs) ⟩ Env.set-shr {s} θr s∈Domθr SharedVar.ready (Env.shr-vals {s} θr s∈Domθr) ∎)) (rreadyness {θl} {p} {s'} s'∈Domθl (Data.Sum.map (trans (cong proj₁ θls'≡θs')) (trans (cong proj₁ θls'≡θs')) θs'≡old⊎θs'≡new) (λ s'∈can-p-θl → s'∉can-p-θ (subst (SharedVar.unwrap s' ∈_) (cong (proj₂ ∘ proj₂) (canθ-shr-var-irr (Env.sig θ) 0 p Env.[]env Env.[]env refl)) s'∈can-p-θl))) ,′ rreadyness {θr} {p} {s} s∈Domθr (Data.Sum.map (trans (cong proj₁ θrs≡θs)) (trans (cong proj₁ θrs≡θs)) θs≡old⊎θs≡new) (λ s∈can-p-θr → s∉can-p-θ (subst (SharedVar.unwrap s ∈_) (cong (proj₂ ∘ proj₂) (canθ-shr-var-irr (Env.sig θ) 0 p Env.[]env Env.[]env refl)) s∈can-p-θr))) where θs = Env.shr-vals {s} θ s∈ θs' = Env.shr-vals {s'} θ s'∈ s∈Domθr = Env.shr-set-mono' {s} {s'} {θ} {SharedVar.ready} {θs'} {s'∈} s∈ s'∈Domθl = Env.shr-set-mono' {s'} {s} {θ} {SharedVar.ready} {θs} {s∈} s'∈ θrs≡θs = ShrMap.putputget {_} {Env.shr θ} {s} {s'} {_} {SharedVar.ready ,′ θs'} s≢s' s∈ s∈Domθr refl θls'≡θs' = ShrMap.putputget {_} {Env.shr θ} {s'} {s} {_} {SharedVar.ready ,′ θs} (s≢s' ∘ sym) s'∈ s'∈Domθl refl
41.233503
97
0.527391
ed08a855778f79f18f575d35099214a9f473226c
4,207
agda
Agda
src/Data/List/Prefix.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
10
2017-11-17T17:10:36.000Z
2021-09-24T08:02:33.000Z
src/Data/List/Prefix.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2019-01-13T13:03:47.000Z
2020-10-14T13:41:58.000Z
src/Data/List/Prefix.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2021-12-28T17:38:05.000Z
2021-12-28T17:38:05.000Z
module Data.List.Prefix where open import Level open import Data.Nat open import Data.List open import Data.List.At open import Data.List.Membership.Propositional open import Data.List.Relation.Unary.Any hiding (map) open import Data.List.Relation.Binary.Pointwise as P hiding (refl; map) open import Relation.Binary open import Relation.Binary.PropositionalEquality as ≡ -- prefix predicate for lists infix 4 _⊑_ data _⊑_ {a} {A : Set a} : List A → List A → Set a where [] : ∀ {ys} → [] ⊑ ys _∷_ : ∀ x {xs ys} → xs ⊑ ys → x ∷ xs ⊑ x ∷ ys ⊑-refl : ∀ {a} {A : Set a} → Reflexive (_⊑_ {A = A}) ⊑-refl {x = []} = [] ⊑-refl {x = x ∷ xs} = x ∷ ⊑-refl ⊑-trans : ∀ {a} {A : Set a} → Transitive (_⊑_ {A = A}) ⊑-trans [] _ = [] ⊑-trans (x ∷ p) (.x ∷ q) = x ∷ ⊑-trans p q open import Relation.Binary.PropositionalEquality ⊑-unique : ∀ {a}{A : Set a}{k l : List A}(xs ys : k ⊑ l) → xs ≡ ys ⊑-unique [] [] = refl ⊑-unique (x ∷ xs) (.x ∷ ys) = cong (λ u → x ∷ u) (⊑-unique xs ys) ⊑-trans-refl : ∀ {a}{A : Set a}{k l}{xs : k ⊑ l} → ⊑-trans {A = A} ⊑-refl xs ≡ xs ⊑-trans-refl {xs = []} = refl ⊑-trans-refl {xs = x ∷ xs} = cong (λ u → x ∷ u) ⊑-trans-refl ⊑-trans-refl' : ∀ {a}{A : Set a}{k l}{xs : k ⊑ l} → ⊑-trans {A = A} xs ⊑-refl ≡ xs ⊑-trans-refl' {xs = []} = refl ⊑-trans-refl' {xs = x ∷ xs} = cong (λ u → x ∷ u) ⊑-trans-refl' ⊑-trans-assoc : ∀ {a}{A : Set a}{k l m n : List A}{p : k ⊑ l}{q : l ⊑ m}{r : m ⊑ n} → ⊑-trans p (⊑-trans q r) ≡ ⊑-trans (⊑-trans p q) r ⊑-trans-assoc {p = []} {q} = refl ⊑-trans-assoc {p = x ∷ p} {.x ∷ q} {.x ∷ r} = cong (λ u → x ∷ u) ⊑-trans-assoc remainder : ∀ {a}{A : Set a}{xs ys : List A} → xs ⊑ ys → List A remainder ([] {ys}) = ys remainder (x ∷ xs) = remainder xs -- list extensions; reverse prefix relation infix 4 _⊒_ _⊒_ : ∀ {a} {A : Set a} → List A → List A → Set a xs ⊒ ys = ys ⊑ xs -- appending to a list gives a list extension; -- or, appending to a list makes the original a prefix ∷ʳ-⊒ : ∀ {a} {A : Set a} (x : A) xs → xs ∷ʳ x ⊒ xs ∷ʳ-⊒ x [] = [] ∷ʳ-⊒ x (x₁ ∷ Σ₁) = x₁ ∷ (∷ʳ-⊒ x Σ₁) -- indexes into a prefix point to the same element in extensions xs⊒ys[i] : ∀ {a} {A : Set a} {xs : List A} {ys : List A} {i y} → xs [ i ]= y → (p : ys ⊒ xs) → ys [ i ]= y xs⊒ys[i] () [] xs⊒ys[i] {i = zero} p (x ∷ a) = p xs⊒ys[i] {i = suc i} p (x ∷ a) = xs⊒ys[i] p a -- prefix is preserved by map ⊑-map : ∀ {a b} {A : Set a} {B : Set b} {xs ys : List A} {f : A → B} → xs ⊑ ys → map f xs ⊑ map f ys ⊑-map [] = [] ⊑-map {f = f} (x ∷ p) = f x ∷ (⊑-map p) -- all elemens in a list, also exist in it's extensions ∈-⊒ : ∀ {a}{A : Set a}{xs : List A}{x} → x ∈ xs → ∀ {ys} → ys ⊒ xs → x ∈ ys ∈-⊒ () [] ∈-⊒ (here px) (x ∷ q) = here px ∈-⊒ (there p) (x ∷ q) = there (∈-⊒ p q) ∈-⊒-refl : ∀ {a}{A : Set a}{xs : List A}{x}{p : x ∈ xs} → ∈-⊒ p ⊑-refl ≡ p ∈-⊒-refl {p = here px} = refl ∈-⊒-refl {p = there p} = cong there ∈-⊒-refl ∈-⊒-trans : ∀ {a}{A : Set a}{xs ys zs : List A}{x}{p : x ∈ xs}(q : ys ⊒ xs)(r : zs ⊒ ys) → ∈-⊒ p (⊑-trans q r) ≡ ∈-⊒ (∈-⊒ p q) r ∈-⊒-trans {p = here px} (x ∷ l) (.x ∷ r) = refl ∈-⊒-trans {p = there p} (x ∷ l) (.x ∷ r) = cong there (∈-⊒-trans l r) open import Relation.Binary open import Relation.Binary.Core open import Relation.Nullary module Decidable {a}{A : Set a}(_≟_ : Decidable (_≡_ {A = A})) where _⊑?_ : Decidable (_⊑_ {A = A}) [] ⊑? _ = yes [] (x ∷ xs) ⊑? [] = no (λ ()) (x ∷ xs) ⊑? (y ∷ ys) with x ≟ y (x ∷ xs) ⊑? (y ∷ ys) | no ¬p = no (λ{ (.x ∷ z) → ¬p refl }) (x ∷ xs) ⊑? (.x ∷ ys) | yes refl with xs ⊑? ys ... | yes px = yes (x ∷ px) ... | no ¬px = no (λ{ (.x ∷ px) → ¬px px}) _⊒?_ : Decidable (_⊒_ {A = A}) xs ⊒? ys = ys ⊑? xs import Relation.Binary.PropositionalEquality.Core as PC ⊑-preorder : ∀ {ℓ}{A : Set ℓ} → Preorder ℓ ℓ ℓ ⊑-preorder {A = A} = record { Carrier = List A ; _≈_ = _≡_ ; _∼_ = _⊑_ ; isPreorder = record { isEquivalence = ≡.isEquivalence ; reflexive = λ{ refl → ⊑-refl } ; trans = ⊑-trans } } ⊒-preorder : ∀ {ℓ}{A : Set ℓ} → Preorder _ _ _ ⊒-preorder {A = A} = record { Carrier = List A ; _≈_ = _≡_ ; _∼_ = _⊒_ ; isPreorder = record { isEquivalence = ≡.isEquivalence ; reflexive = λ{ refl → ⊑-refl } ; trans = λ p q → ⊑-trans q p } }
35.058333
128
0.511053
36d25c83154e393c50fcf1806b6a7a132b872fad
3,724
agda
Agda
src/CF/Transform/Compile/Expressions.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
6
2020-10-07T14:07:17.000Z
2021-02-28T21:49:08.000Z
src/CF/Transform/Compile/Expressions.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
null
null
null
src/CF/Transform/Compile/Expressions.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
1
2021-12-28T17:37:15.000Z
2021-12-28T17:37:15.000Z
{-# OPTIONS --safe --no-qualified-instances #-} module CF.Transform.Compile.Expressions where open import Function using (_∘_) open import Level open import Data.Unit open import Data.Bool open import Data.Product as P open import Data.List as L hiding (null; [_]) open import Data.List.Membership.Propositional open import Data.List.Membership.Propositional.Properties open import Data.List.Relation.Unary.All open import Relation.Binary.PropositionalEquality hiding ([_]) open import Relation.Unary hiding (_∈_) open import Relation.Ternary.Core open import Relation.Ternary.Structures open import Relation.Ternary.Structures.Syntax open import Relation.Ternary.Monad open import Relation.Ternary.Construct.Bag.Properties private module Src where open import CF.Syntax.DeBruijn public open import CF.Types public open import CF.Contexts.Lexical using (module DeBruijn) public; open DeBruijn public module Tgt where open import JVM.Types public open import JVM.Model StackTy public open import JVM.Syntax.Values public open import JVM.Syntax.Instructions public open Src open Tgt open import JVM.Compiler open import CF.Transform.Compile.ToJVM -- Compilation of CF expressions compileₑₛ : ∀ {as ψ Γ} → Exps as Γ → ε[ Compiler ⟦ Γ ⟧ ψ (⟦ as ⟧ ++ ψ) Emp ] compileₑ : ∀ {a ψ Γ} → Exp a Γ → ε[ Compiler ⟦ Γ ⟧ ψ (⟦ a ⟧ ∷ ψ) Emp ] compileₑ (unit) = do code (push (bool true)) compileₑ (num x) = do code (push (num x)) compileₑ (bool b) = do code (push (bool b)) compileₑ (var' x) = do code (load ⟦ x ⟧) compileₑ (bop f e₁ e₂) = do compileₑ e₁ compileₑ e₂ compile-bop f where -- a < b compiles to (assume a and b on stack): -- -- if_icmplt l⁻ -- iconst_1 -- goto e⁻ -- l⁺: iconst_0 -- e⁺: nop -- -- Other comparisons go similar compile-comp : ∀ {Γ as} → Comparator as → ε[ Compiler Γ (as ++ ψ) (boolean ∷ ψ) Emp ] compile-comp cmp = do ↓ lfalse⁻ ∙⟨ σ ⟩ lfalse⁺ ← ✴-swap ⟨$⟩ freshLabel lfalse⁺ ← ✴-id⁻ˡ ⟨$⟩ (code (if cmp lfalse⁻) ⟨ Up _ # σ ⟩& lfalse⁺) lfalse⁺ ← ✴-id⁻ˡ ⟨$⟩ (code (push (bool false)) ⟨ Up _ # ∙-idˡ ⟩& lfalse⁺) ↓ lend⁻ ∙⟨ σ ⟩ labels ← (✴-rotateₗ ∘ ✴-assocᵣ) ⟨$⟩ (freshLabel ⟨ Up _ # ∙-idˡ ⟩& lfalse⁺) lfalse⁺ ∙⟨ σ ⟩ lend⁺ ← ✴-id⁻ˡ ⟨$⟩ (code (goto lend⁻) ⟨ _ ✴ _ # σ ⟩& labels) lend⁺ ← ✴-id⁻ˡ ⟨$⟩ (attach lfalse⁺ ⟨ Up _ # σ ⟩& lend⁺) code (push (bool true)) attach lend⁺ -- Compile comparisons and other binary operations compile-bop : ∀ {Γ a b c} → BinOp a b c → ε[ Compiler Γ (⟦ b ⟧ ∷ ⟦ a ⟧ ∷ ψ) (⟦ c ⟧ ∷ ψ) Emp ] compile-bop add = code (bop add) compile-bop sub = code (bop sub) compile-bop mul = code (bop mul) compile-bop div = code (bop div) compile-bop xor = code (bop xor) compile-bop eq = compile-comp icmpeq compile-bop ne = compile-comp icmpne compile-bop lt = compile-comp icmplt compile-bop ge = compile-comp icmpge compile-bop gt = compile-comp icmpgt compile-bop le = compile-comp icmplt compileₑ (ifthenelse c e₁ e₂) = do -- condition compileₑ c lthen+ ∙⟨ σ ⟩ ↓ lthen- ← freshLabel lthen+ ← ✴-id⁻ˡ ⟨$⟩ (code (if ne lthen-) ⟨ Up _ # ∙-comm σ ⟩& lthen+) -- else compileₑ e₂ ↓ lend- ∙⟨ σ ⟩ labels ← (✴-rotateₗ ∘ ✴-assocᵣ) ⟨$⟩ (freshLabel ⟨ Up _ # ∙-idˡ ⟩& lthen+) -- then lthen+ ∙⟨ σ ⟩ lend+ ← ✴-id⁻ˡ ⟨$⟩ (code (goto lend-) ⟨ _ ✴ _ # σ ⟩& labels) lend+ ← ✴-id⁻ˡ ⟨$⟩ (attach lthen+ ⟨ Up _ # σ ⟩& lend+) compileₑ e₁ -- label the end attach lend+ compileₑₛ [] = return refl compileₑₛ (e ∷ es) = do compileₑₛ es compileₑ e
31.294118
100
0.608754
3d4b4dfc4a4de3253c756cdef2b4deaee7f96ee1
4,870
agda
Agda
Cats/Category/Presheaves/Facts/Exponential.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
24
2017-11-03T15:18:57.000Z
2021-08-06T05:00:46.000Z
Cats/Category/Presheaves/Facts/Exponential.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
null
null
null
Cats/Category/Presheaves/Facts/Exponential.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.Presheaves.Facts.Exponential where open import Data.Product using (_,_) open import Relation.Binary using (Setoid) open import Cats.Category open import Cats.Category.Fun using (Fun ; ≈-intro ; ≈-elim) open import Cats.Category.Presheaves using (Presheaves) open import Cats.Category.Setoids as Setoids using (≈-intro ; ≈-elim) open import Cats.Functor using (Functor) open import Cats.Trans using (Trans ; component ; natural) import Cats.Category.Fun.Facts.Product as Product import Cats.Category.Setoids.Facts open Functor open HasBinaryProducts {{...}} open Setoids._⇒_ module _ {l} {ℂ : Category l l l} where private module ℂ = Category ℂ open Category (Presheaves ℂ l l) module $ (F : Obj) {x : Category.Obj ℂ} = Setoid (fobj F x) -- Could replace this with transposeBifunctor₂ HomF, but that would introduce -- even more redundant compositions with the identity. y : ℂ.Obj → Obj y d = record { fobj = λ c → ℂ.Hom c d ; fmap = λ f → record { arr = (ℂ._∘ f) ; resp = ℂ.∘-resp-l } ; fmap-resp = λ eq₁ → ≈-intro λ eq₂ → ℂ.∘-resp eq₂ eq₁ ; fmap-id = ≈-intro λ eq → ℂ.≈.trans ℂ.id-r eq ; fmap-∘ = ≈-intro λ eq → ℂ.≈.trans ℂ.assoc (ℂ.∘-resp-l eq) } _↝_ : (F G : Obj) → Obj F ↝ G = record { fobj = λ d → Hom (y d × F) G ; fmap = λ {d} {d′} f → record { arr = λ α → record { component = λ d → record { arr = λ where (g , c) → arr (component α d) (f ℂ.∘ g , c) ; resp = λ where (eq₁ , eq₂) → resp (component α d) (ℂ.∘-resp-r eq₁ , eq₂) } ; natural = λ {e} {e′} {g} → ≈-intro λ where {h , c} {h′ , c′} (h≈h′ , c≈c′) → $.trans G (resp (component α e′) (ℂ.unassoc , $.refl F)) (≈-elim (natural α) (ℂ.∘-resp-r h≈h′ , c≈c′)) } ; resp = λ α≈β → ≈-intro (≈-intro λ where (f≈g , h≈i) → ≈-elim (≈-elim α≈β) (ℂ.∘-resp-r f≈g , h≈i)) } ; fmap-resp = λ f≈g → ≈-intro λ α≈β → ≈-intro (≈-intro λ where (c≈d , h≈i) → ≈-elim (≈-elim α≈β) ((ℂ.∘-resp f≈g c≈d) , h≈i)) ; fmap-id = ≈-intro λ α≈β → ≈-intro (≈-intro λ where (c≈d , h≈i) → ≈-elim (≈-elim α≈β) ((ℂ.≈.trans ℂ.id-l c≈d) , h≈i)) ; fmap-∘ = ≈-intro λ α≈β → ≈-intro (≈-intro λ where (c≈d , h≈i) → ≈-elim (≈-elim α≈β) ((ℂ.≈.trans ℂ.unassoc (ℂ.∘-resp-r c≈d)) , h≈i)) } Eval : ∀ F G → F ↝ G × F ⇒ G Eval F G = record { component = λ c → record { arr = λ where (α , x) → arr (component α c) (ℂ.id , x) ; resp = λ where (α≈β , f≈g) → ≈-elim (≈-elim α≈β) (ℂ.≈.refl , f≈g) } ; natural = λ {c} {d} → ≈-intro λ where {α , f} {β , g} (α≈β , f≈g) → $.trans G (≈-elim (≈-elim α≈β) (ℂ.≈.trans ℂ.id-r (ℂ.≈.sym ℂ.id-l) , resp (fmap F _) f≈g)) (≈-elim (natural β) (ℂ.≈.refl , $.refl F)) } Curry : ∀ E F G → E × F ⇒ G → E ⇒ F ↝ G Curry E F G α = record { component = λ d → record { arr = λ x → record { component = λ c → record { arr = λ where (f , y) → arr (component α c) (arr (fmap E f) x , y) ; resp = λ where (c≈d , x≈y) → resp (component α c) (≈-elim (fmap-resp E c≈d) ($.refl E) , x≈y) } ; natural = ≈-intro λ where (f≈g , x≈y) → $.trans G (resp (component α _) (($.sym E (≈-elim (fmap-∘ E) ($.refl E))) , ($.refl F))) (≈-elim (natural α) (≈-elim (fmap-resp E f≈g) ($.refl E) , x≈y)) } ; resp = λ x≈y → ≈-intro (≈-intro λ where (f≈g , c≈d) → resp (component α _) ((≈-elim (fmap-resp E f≈g) x≈y) , c≈d)) } ; natural = ≈-intro λ x≈y → ≈-intro (≈-intro λ where (f≈g , c≈d) → resp (component α _) ( $.trans E (≈-elim (fmap-∘ E) x≈y) (≈-elim (fmap-resp E (ℂ.∘-resp-r f≈g)) ($.refl E)) , c≈d )) } instance hasExponentials : HasExponentials (Presheaves ℂ l l) hasExponentials = record { hasBinaryProducts = Product.hasBinaryProducts ; _↝′_ = λ F G → record { Cᴮ = F ↝ G ; eval = Eval F G ; curry′ = λ {E} α → record { arr = Curry E F G α ; prop = ≈-intro (≈-intro λ where (x≈y , u≈v) → resp (component α _) (≈-elim (fmap-id E) x≈y , u≈v)) ; unique = λ {α} α≈ → ≈-intro (≈-intro (λ x≈y → ≈-intro (≈-intro (λ where (f≈g , u≈v) → $.trans G (≈-elim (≈-elim (≈.sym α≈)) (≈-elim (fmap-resp E f≈g) ($.refl E) , u≈v)) ($.trans G (≈-elim (≈-elim (≈-elim (natural α) x≈y)) (ℂ.≈.refl , ($.refl F))) (resp (component (arr (component α _) _) _) (ℂ.id-r , ($.refl F)))))))) } } }
35.289855
89
0.47269
64d195c1aa7151f02d3f12382a475a188d1cc83a
29,704
agda
Agda
src/main.agda
zmthy/cedille
9df4b85b55b57f97466242fdbb499adbd3bca893
[ "MIT" ]
null
null
null
src/main.agda
zmthy/cedille
9df4b85b55b57f97466242fdbb499adbd3bca893
[ "MIT" ]
null
null
null
src/main.agda
zmthy/cedille
9df4b85b55b57f97466242fdbb499adbd3bca893
[ "MIT" ]
null
null
null
module main where import string-format -- for parser for Cedille open import cedille-types -- for parser for options files import options-types import cedille-options -- for parser for Cedille comments & whitespace import cws-types open import constants open import general-util open import json createOptionsFile : (dot-ced-dir : string) → IO ⊤ createOptionsFile dot-ced-dir = let ops-fp = combineFileNames dot-ced-dir options-file-name in createDirectoryIfMissing ff (takeDirectory ops-fp) >> withFile ops-fp WriteMode (flip hPutRope (cedille-options.options-to-rope cedille-options.default-options)) options-absolute-path : (options-fp some-fp : filepath) → IO filepath options-absolute-path ofp fp = (filepath-replace-tilde fp >>= flip maybe-else return (doesFileExist fp >>=r λ fpₑ → if fpₑ then fp else combineFileNames (takeDirectory (takeDirectory ofp)) fp)) >>= canonicalizePath opts-to-options : filepath → options-types.opts → IO cedille-options.options opts-to-options ofp (options-types.OptsCons (options-types.Lib fps) ops) = opts-to-options ofp ops >>= λ ops → paths-to-stringset fps >>=r λ ip → record ops { include-path = ip } where paths-to-stringset : options-types.paths → IO (𝕃 string × stringset) paths-to-stringset (options-types.PathsCons fp fps) = let rfp = combineFileNames (takeDirectory (takeDirectory ofp)) fp in paths-to-stringset fps >>= λ ps → doesDirectoryExist rfp >>= λ rfpₑ → doesDirectoryExist fp >>= λ fpₑ → (if rfpₑ then (canonicalizePath rfp >>= λ rfp → return (cedille-options.include-path-insert rfp ps)) else return ps) >>= λ ps → if fpₑ then (canonicalizePath fp >>= λ fp → return (cedille-options.include-path-insert fp ps)) else return ps paths-to-stringset options-types.PathsNil = return ([] , empty-stringset) opts-to-options ofp (options-types.OptsCons (options-types.UseCedeFiles b) ops) = opts-to-options ofp ops >>=r λ ops → record ops { use-cede-files = b } opts-to-options ofp (options-types.OptsCons (options-types.MakeRktFiles b) ops) = opts-to-options ofp ops >>=r λ ops → record ops { make-rkt-files = b } opts-to-options ofp (options-types.OptsCons (options-types.GenerateLogs b) ops) = opts-to-options ofp ops >>=r λ ops → record ops { generate-logs = b } opts-to-options ofp (options-types.OptsCons (options-types.ShowQualifiedVars b) ops) = opts-to-options ofp ops >>=r λ ops → record ops { show-qualified-vars = b } opts-to-options ofp (options-types.OptsCons (options-types.EraseTypes b) ops) = opts-to-options ofp ops >>=r λ ops → record ops { erase-types = b } opts-to-options ofp (options-types.OptsCons (options-types.PrettyPrintColumns b) ops) = opts-to-options ofp ops >>=r λ ops → record ops { pretty-print-columns = string-to-ℕ0 b } opts-to-options ofp (options-types.OptsCons (options-types.DatatypeEncoding fp?) ops) = maybe-map (options-absolute-path ofp) fp? >>=? λ fp? → opts-to-options ofp ops >>=r λ ops → record ops { datatype-encoding = (_, nothing) <$> fp? } opts-to-options ofp options-types.OptsNil = return cedille-options.default-options -- helper function to try to parse the options file processOptions : filepath → string → IO (string ⊎ cedille-options.options) processOptions filename s with options-types.scanOptions s ...| options-types.Left cs = return (inj₁ ("Parse error in file " ^ filename ^ " " ^ cs ^ ".")) ...| options-types.Right (options-types.File oo) = opts-to-options filename oo >>= λ opts → if cedille-options.options.make-rkt-files opts then return ∘ inj₁ $ "Racket compilation disabled, please set to false in " ^ filename ^ "." else (return ∘ inj₂ $ opts) getOptionsFile : (filepath : string) → string getOptionsFile fp = combineFileNames (dot-cedille-directory fp) options-file-name findOptionsFile' : (filepath : string) → IO (maybe string) findOptionsFile' fp = traverseParents fp (fp-fuel fp) >>= λ where fpc?@(just fpc) → return fpc? nothing → getHomeDirectory >>= λ hd → canonicalizePath hd >>= getOptions? where getOptions? : (filepath : string) → IO ∘ maybe $ string getOptions? fp = let fpc = getOptionsFile fp in doesFileExist fpc >>= λ where ff → return nothing tt → return ∘ just $ fpc traverseParents : string → ℕ → IO (maybe string) traverseParents fp 0 = return nothing traverseParents fp (suc n) = getOptions? fp >>= λ where nothing → traverseParents (takeDirectory fp) n fpc?@(just fpc) → return fpc? fp-fuel : (filepath : string) → ℕ fp-fuel fp = pred ∘' length ∘' splitPath $ fp findOptionsFile : IO (maybe string) findOptionsFile = (getCurrentDirectory >>= canonicalizePath) >>= findOptionsFile' readOptions : maybe string → IO (string × cedille-options.options) readOptions nothing = (getHomeDirectory >>= canonicalizePath) >>= λ home → createOptionsFile (dot-cedille-directory home) >>r dot-cedille-directory home , cedille-options.default-options readOptions (just fp) = readFiniteFile fp >>= λ fc → processOptions fp fc >>= λ where (inj₁ err) → putStrLn (global-error-string err) >>r fp , cedille-options.default-options (inj₂ ops) → return (fp , ops) module main-with-options (compileTime : UTC) (options-filepath : filepath) (options : cedille-options.options) (die : {A : Set} → 𝕃 char → IO A) where open import ctxt --open import instances open import process-cmd options {IO} open import parser open import spans options {IO} open import syntax-util open import to-string options open import toplevel-state options {IO} open import interactive-cmds options open import rkt options open import elab-util options logFilepath : IO filepath logFilepath = getHomeDirectory >>=r λ home → combineFileNames (dot-cedille-directory home) "log" maybeClearLogFile : IO ⊤ maybeClearLogFile = if cedille-options.options.generate-logs options then logFilepath >>= clearFile else return triv logRope : rope → IO ⊤ logRope s with cedille-options.options.generate-logs options ...| ff = return triv ...| tt = getCurrentTime >>= λ time → logFilepath >>= λ fn → withFile fn AppendMode λ hdl → hPutRope hdl ([[ "([" ^ utcToString time ^ "] " ]] ⊹⊹ s ⊹⊹ [[ ")\n" ]]) logMsg : (message : string) → IO ⊤ logMsg msg = logRope [[ msg ]] sendProgressUpdate : string → IO ⊤ sendProgressUpdate msg = putStr "progress: " >> putStr msg >> putStr "\n" progressUpdate : (filename : string) → {-(do-check : 𝔹) → -} IO ⊤ progressUpdate filename {-do-check-} = sendProgressUpdate ((if {-do-check-} tt then "Checking " else "Skipping ") ^ filename) fileBaseName : filepath → string fileBaseName fn = base-filename (takeFileName fn) fileSuffix : filepath → string fileSuffix = maybe-else cedille-extension id ∘ var-suffix {------------------------------------------------------------------------------- .cede support -------------------------------------------------------------------------------} cede-suffix = ".cede" rkt-suffix = ".rkt" ced-aux-filename : (suffix ced-path : filepath) → filepath ced-aux-filename sfx ced-path = let dir = takeDirectory ced-path in combineFileNames (dot-cedille-directory dir) (fileBaseName ced-path ^ sfx) cede-filename = ced-aux-filename cede-suffix rkt-filename = ced-aux-filename rkt-suffix maybe-write-aux-file : include-elt → (create-dot-ced-if-missing : IO ⊤) → (filename file-suffix : filepath) → (cedille-options.options → 𝔹) → (include-elt → 𝔹) → rope → IO ⊤ maybe-write-aux-file ie mk-dot-ced fn sfx f f' r with f options && ~ f' ie ...| ff = return triv ...| tt = mk-dot-ced >> logMsg ("Starting writing " ^ sfx ^ " file " ^ fn) >> writeRopeToFile fn r >> logMsg ("Finished writing " ^ sfx ^ " file " ^ fn) write-aux-files : toplevel-state → filepath → IO ⊤ write-aux-files s filename with get-include-elt-if s filename ...| nothing = return triv ...| just ie = let dot-ced = createDirectoryIfMissing ff (dot-cedille-directory (takeDirectory filename)) in maybe-write-aux-file ie dot-ced (cede-filename filename) cede-suffix cedille-options.options.use-cede-files include-elt.cede-up-to-date ((if include-elt.err ie then [[ "e" ]] else [[]]) ⊹⊹ json-to-rope (include-elt-spans-to-json ie)) >> maybe-write-aux-file ie dot-ced (rkt-filename filename) rkt-suffix cedille-options.options.make-rkt-files include-elt.rkt-up-to-date (to-rkt-file filename (toplevel-state.Γ s) ie rkt-filename) -- we assume the cede file is known to exist at this point read-cede-file : (ced-path : filepath) → IO (𝔹 × string) read-cede-file ced-path = let cede = cede-filename ced-path in logMsg ("Started reading .cede file " ^ cede) >> (get-file-contents cede >>= finish) >≯ logMsg ("Finished reading .cede file " ^ cede) where finish : maybe string → IO (𝔹 × string) finish nothing = return (tt , global-error-string ("Could not read the file " ^ cede-filename ced-path ^ ".")) finish (just ss) with string-to-𝕃char ss finish (just ss) | ('e' :: ss') = forceFileRead ss >>r tt , 𝕃char-to-string ss' finish (just ss) | _ = forceFileRead ss >>r ff , ss --add-cedille-extension : string → string --add-cedille-extension x = x ^ "." ^ cedille-extension --add-cdle-extension : string → string --add-cdle-extension x = x ^ "." ^ cdle-extension -- Allows you to say "import FOO.BAR.BAZ" rather than "import FOO/BAR/BAZ" replace-dots : filepath → filepath replace-dots s = 𝕃char-to-string (h (string-to-𝕃char s)) where h : 𝕃 char → 𝕃 char h ('.' :: '.' :: cs) = '.' :: '.' :: h cs h ('.' :: cs) = pathSeparator :: h cs h (c :: cs) = c :: h cs h [] = [] find-imported-file : (sfx : string) → (dirs : 𝕃 filepath) → (unit-name : string) → IO (maybe filepath) find-imported-file sfx [] unit-name = return nothing find-imported-file sfx (dir :: dirs) unit-name = let e = combineFileNames dir (unit-name ^ "." ^ sfx) in doesFileExist e >>= λ where tt → canonicalizePath e >>=r just ff → find-imported-file sfx dirs unit-name {- find-imported-file sfx (dir :: dirs) unit-name = let e₁ = combineFileNames dir (add-cedille-extension unit-name) e₂ = combineFileNames dir (add-cdle-extension unit-name) e? = λ e → doesFileExist e >>=r λ e? → maybe-if e? ≫maybe just e in (e? e₁ >>= λ e₁ → e? e₂ >>=r λ e₂ → e₁ maybe-or e₂) >>= λ where nothing → find-imported-file sfx dirs unit-name (just e) → canonicalizePath e >>=r just -} find-imported-files : (sfx : string) → (dirs : 𝕃 filepath) → (imports : 𝕃 string) → IO (𝕃 (string × filepath)) find-imported-files sfx dirs (u :: us) = find-imported-file sfx dirs (replace-dots u) >>= λ where nothing → logMsg ("Error finding file: " ^ replace-dots u) >> find-imported-files sfx dirs us (just fp) → logMsg ("Found import: " ^ fp) >> find-imported-files sfx dirs us >>=r (u , fp) ::_ find-imported-files sfx dirs [] = return [] get-imports : ex-file → 𝕃 string get-imports (ExModule is _ _ mn _ cs _) = map (λ {(ExImport _ _ _ x _ _ _) → x}) (is ++ ex-cmds-to-imps cs) {- new parser test integration -} reparse : toplevel-state → filepath → IO toplevel-state reparse st filename = doesFileExist filename >>= λ fileExists → (if fileExists then (readFiniteFile filename >>= λ source → getCurrentTime >>= λ time → processText source >>= λ ie → return (set-last-parse-time-include-elt ie time) >>=r λ ie -> set-source-include-elt ie source) else return (error-include-elt ("The file " ^ filename ^ " could not be opened for reading."))) >>=r set-include-elt st filename where processText : string → IO include-elt processText x with parseStart x processText x | Left (Left cs) = return (error-span-include-elt ("Error in file " ^ filename ^ ".") "Lexical error." cs) processText x | Left (Right cs) = return (error-span-include-elt ("Error in file " ^ filename ^ ".") "Parsing error." cs) processText x | Right t with cws-types.scanComments x processText x | Right t | t2 = find-imported-files (fileSuffix filename) (fst (cedille-options.include-path-insert (takeDirectory filename) (toplevel-state.include-path st))) (get-imports t) >>= λ deps → logMsg ("deps for file " ^ filename ^ ": " ^ 𝕃-to-string (λ {(a , b) → "short: " ^ a ^ ", long: " ^ b}) ", " deps) >>r new-include-elt filename deps t t2 nothing reparse-file : filepath → toplevel-state → IO toplevel-state reparse-file filename s = reparse s filename >>=r λ s → set-include-elt s filename (set-cede-file-up-to-date-include-elt (set-do-type-check-include-elt (get-include-elt s filename) tt) ff) infixl 2 _&&>>_ _&&>>_ : IO 𝔹 → IO 𝔹 → IO 𝔹 (a &&>> b) = a >>= λ a → if a then b else return ff aux-up-to-date : filepath → toplevel-state → IO toplevel-state aux-up-to-date filename s = let rkt = rkt-filename filename in (doesFileExist rkt &&>> fileIsOlder filename rkt) >>=r (set-include-elt s filename ∘ (set-rkt-file-up-to-date-include-elt (get-include-elt s filename))) ie-up-to-date : filepath → include-elt → IO 𝔹 ie-up-to-date filename ie = getModificationTime filename >>=r λ mt → maybe-else ff (λ lpt → lpt utc-after mt) (include-elt.last-parse-time ie) import-changed : toplevel-state → filepath → (import-file : string) → IO 𝔹 import-changed s filename import-file = let dtc = include-elt.do-type-check (get-include-elt s import-file) cede = cede-filename filename cede' = cede-filename import-file in case cedille-options.options.use-cede-files options of λ where ff → return dtc tt → (doesFileExist cede &&>> doesFileExist cede') >>= λ where ff → return ff tt → fileIsOlder cede cede' >>=r λ fio → dtc || fio any-imports-changed : toplevel-state → filepath → (imports : 𝕃 string) → IO 𝔹 any-imports-changed s filename [] = return ff any-imports-changed s filename (h :: t) = import-changed s filename h >>= λ where tt → return tt ff → any-imports-changed s filename t file-after-compile : filepath → IO 𝔹 file-after-compile fn = getModificationTime fn >>= λ mt → case mt utc-after compileTime of λ where tt → doesFileExist options-filepath &&>> fileIsOlder options-filepath fn ff → return ff ensure-ast-depsh : filepath → toplevel-state → IO toplevel-state ensure-ast-depsh filename s with get-include-elt-if s filename ...| just ie = ie-up-to-date filename ie >>= λ where ff → reparse-file filename s tt → return s ...| nothing = let cede = cede-filename filename in (return (cedille-options.options.use-cede-files options) &&>> doesFileExist cede &&>> fileIsOlder filename cede &&>> file-after-compile cede) >>= λ where ff → reparse-file filename s tt → reparse s filename >>= λ s → read-cede-file filename >>= λ where (err , ss) → return (set-include-elt s filename (set-do-type-check-include-elt (set-need-to-add-symbols-to-context-include-elt (set-spans-string-include-elt (get-include-elt s filename) err ss) tt) ff)) {- helper function for update-asts, which keeps track of the files we have seen so we avoid importing the same file twice, and also avoid following cycles in the import graph. -} {-# TERMINATING #-} update-astsh : stringset {- seen already -} → toplevel-state → filepath → IO (stringset {- seen already -} × toplevel-state) update-astsh seen s filename = if stringset-contains seen filename then return (seen , s) else ((ensure-ast-depsh filename s >>= aux-up-to-date filename) >>= cont (stringset-insert seen filename)) where cont : stringset → toplevel-state → IO (stringset × toplevel-state) cont seen s with get-include-elt s filename cont seen s | ie with include-elt.deps ie cont seen s | ie | ds = proc seen s ds where proc : stringset → toplevel-state → 𝕃 string → IO (stringset × toplevel-state) proc seen s [] = any-imports-changed s filename ds >>=r λ changed → seen , set-include-elt s filename (set-do-type-check-include-elt ie (include-elt.do-type-check ie || changed)) proc seen s (d :: ds) = update-astsh seen s d >>= λ p → proc (fst p) (snd p) ds {- this function updates the ast associated with the given filename in the toplevel state. So if we do not have an up-to-date .cede file (i.e., there is no such file at all, or it is older than the given file), reparse the file. We do this recursively for all dependencies (i.e., imports) of the file. -} update-asts : toplevel-state → filepath → IO toplevel-state update-asts s filename = update-astsh empty-stringset s filename >>=r snd log-files-to-check : toplevel-state → IO ⊤ log-files-to-check s = logRope ([[ "\n" ]] ⊹⊹ (h (trie-mappings (toplevel-state.is s)))) where h : 𝕃 (string × include-elt) → rope h [] = [[]] h ((fn , ie) :: t) = [[ "file: " ]] ⊹⊹ [[ fn ]] ⊹⊹ [[ "\nadd-symbols: " ]] ⊹⊹ [[ 𝔹-to-string (include-elt.need-to-add-symbols-to-context ie) ]] ⊹⊹ [[ "\ndo-type-check: " ]] ⊹⊹ [[ 𝔹-to-string (include-elt.do-type-check ie) ]] ⊹⊹ [[ "\n\n" ]] ⊹⊹ h t {- this function checks the given file (if necessary), updates .cede and .rkt files (again, if necessary), and replies on stdout if appropriate -} checkFile : (string → IO ⊤) → toplevel-state → filepath → (should-print-spans : 𝔹) → IO toplevel-state checkFile progressUpdate s filename should-print-spans = update-asts s filename >>= λ s → log-files-to-check s >> logMsg (𝕃-to-string (λ {(im , fn) → "im: " ^ im ^ ", fn: " ^ fn}) "; " (trie-mappings (include-elt.import-to-dep (get-include-elt s filename)))) >> process-file progressUpdate logMsg s filename (fileBaseName filename) >>= finish where reply : toplevel-state → IO ⊤ reply s with get-include-elt-if s filename reply s | nothing = putStrLn (global-error-string ("Internal error looking up information for file " ^ filename ^ ".")) reply s | just ie = if should-print-spans then putJson (include-elt-spans-to-json ie) else return triv finish : (toplevel-state × file × string × string × params × qualif) → IO toplevel-state finish (s @ (mk-toplevel-state ip mod is Γ) , f , ret-mod) = logMsg ("Started reply for file " ^ filename) >> -- Lazy, so checking has not been calculated yet? reply s >> logMsg ("Finished reply for file " ^ filename) >> logMsg ("Files with updated spans:\n" ^ 𝕃-to-string (λ x → x) "\n" mod) >> let Γ = ctxt-set-current-mod Γ ret-mod in writeo mod >>r -- Should process-file now always add files to the list of modified ones because now the cede-/rkt-up-to-date fields take care of whether to rewrite them? mk-toplevel-state ip [] is Γ -- Reset files with updated spans where writeo : 𝕃 string → IO ⊤ writeo [] = return triv writeo (f :: us) = writeo us >> --let ie = get-include-elt s f in write-aux-files s f -- (if cedille-options.options.make-rkt-files options && ~ include-elt.rkt-up-to-date ie then (write-rkt-file f (toplevel-state.Γ s) ie rkt-filename) else return triv) -- this is the function that handles requests (from the frontend) on standard input {-# TERMINATING #-} readCommandsFromFrontend : toplevel-state → IO ⊤ readCommandsFromFrontend s = getLine >>= λ input → logMsg ("Frontend input: " ^ input) >> let input-list : 𝕃 string input-list = string-split (undo-escape-string input) delimiter in handleCommands input-list s >>= readCommandsFromFrontend where errorCommand : 𝕃 string → toplevel-state → IO ⊤ errorCommand ls s = putStrLn (global-error-string "Invalid command sequence \\\\\"" ^ (𝕃-to-string (λ x → x) ", " ls) ^ "\\\\\".") debugCommand : toplevel-state → IO ⊤ debugCommand s = putStrLn (escape-string (toplevel-state-to-string s)) checkCommand : 𝕃 string → toplevel-state → IO toplevel-state checkCommand (input :: []) s = canonicalizePath input >>= λ input-filename → checkFile progressUpdate (set-include-path s (cedille-options.include-path-insert (takeDirectory input-filename) (toplevel-state.include-path s))) input-filename tt {- should-print-spans -} checkCommand ls s = errorCommand ls s >>r s createArchive-h : toplevel-state → trie json → 𝕃 string → json createArchive-h s t (filename :: filenames) with trie-contains t filename | get-include-elt-if s filename ...| ff | just ie = createArchive-h s (trie-insert t filename $ include-elt-to-archive ie) (filenames ++ include-elt.deps ie) ...| _ | _ = createArchive-h s t filenames createArchive-h s t [] = json-object $ trie-mappings t createArchive : toplevel-state → string → json createArchive s filename = createArchive-h s empty-trie (filename :: []) archiveCommand : 𝕃 string → toplevel-state → IO toplevel-state archiveCommand (input :: []) s = canonicalizePath input >>= λ filename → update-asts s filename >>= λ s → process-file (λ _ → return triv) (λ _ → return triv) s filename (fileBaseName filename) >>=c λ s _ → putRopeLn (json-to-rope (createArchive s filename)) >>r s archiveCommand ls s = errorCommand ls s >>r s handleCommands : 𝕃 string → toplevel-state → IO toplevel-state handleCommands ("progress stub" :: xs) = return handleCommands ("status ping" :: xs) s = putStrLn "idle" >> return s handleCommands ("check" :: xs) s = checkCommand xs s handleCommands ("debug" :: []) s = debugCommand s >>r s handleCommands ("elaborate" :: fm :: to :: []) s = elab-all s fm to >>r s handleCommands ("interactive" :: xs) s = interactive-cmd xs s >>r s handleCommands ("archive" :: xs) s = archiveCommand xs s handleCommands ("br" :: xs) s = putJson interactive-not-br-cmd-msg >>r s -- handleCommands ("find" :: xs) s = findCommand xs s handleCommands xs s = errorCommand xs s >>r s {- mk-new-toplevel-state : IO toplevel-state mk-new-toplevel-state = let s = new-toplevel-state (cedille-options.options.include-path options) in maybe-else' (cedille-options.options.datatype-encoding options) (return s) λ fp → readFiniteFile fp >>= λ de → case parseStart de of λ where (Left (Left e)) → putStrLn ("Lexical error in datatype encoding at position " ^ e) >>r s (Left (Right e)) → putStrLn ("Parse error in datatype encoding at position " ^ e) >>r s (Right de) → {!!} -} processFile : string → IO toplevel-state processFile input-filename = checkFile progressUpdate (new-toplevel-state (cedille-options.include-path-insert (takeDirectory input-filename) (cedille-options.options.include-path options))) input-filename ff typecheckFile : string → IO toplevel-state typecheckFile f = processFile f >>= λ s → let ie = get-include-elt s f in if include-elt.err ie then die (string-to-𝕃char ("Type Checking Failed")) else return s -- function to process command-line arguments processArgs : 𝕃 string → IO ⊤ -- this is the case for when we are called with a single command-line argument, the name of the file to process processArgs (input-filename :: []) = canonicalizePath input-filename >>= λ input-filename' → typecheckFile input-filename' >>r triv -- FIXME: For some reason the parameters get here reversed (?) processArgs (to :: fm :: "-e" :: []) = canonicalizePath fm >>= λ fm' → typecheckFile fm' >>= λ s → elab-all s fm' to >>r triv -- this is the case where we will go into a loop reading commands from stdin, from the fronted processArgs [] = readCommandsFromFrontend (new-toplevel-state (cedille-options.options.include-path options)) -- all other cases are errors processArgs xs = putStrLn ("Run with the name of one file to process," ^ " or run with no command-line arguments and enter the\n" ^ "names of files one at a time followed by newlines (this is for the emacs mode).") main' : 𝕃 string → IO ⊤ main' args = maybeClearLogFile >> logMsg ("Started Cedille process (compiled at: " ^ utcToString compileTime ^ ")") >> processArgs args postulate initializeStdinToUTF8 : IO ⊤ setStdinNewlineMode : IO ⊤ compileTime : UTC templatesDir : filepath die : {A : Set} → 𝕃 char → IO A {-# FOREIGN GHC {-# LANGUAGE TemplateHaskell #-} #-} {-# FOREIGN GHC import qualified System.IO #-} {-# FOREIGN GHC import qualified System.Exit #-} {-# FOREIGN GHC import qualified Data.Time.Clock #-} {-# FOREIGN GHC import qualified Data.Time.Format #-} {-# FOREIGN GHC import qualified Data.Time.Clock.POSIX #-} {-# FOREIGN GHC import qualified Language.Haskell.TH.Syntax #-} {-# COMPILE GHC die = \ _ -> System.Exit.die #-} {-# COMPILE GHC initializeStdinToUTF8 = System.IO.hSetEncoding System.IO.stdin System.IO.utf8 #-} {-# COMPILE GHC setStdinNewlineMode = System.IO.hSetNewlineMode System.IO.stdin System.IO.universalNewlineMode #-} {-# COMPILE GHC compileTime = maybe (Data.Time.Clock.POSIX.posixSecondsToUTCTime (fromIntegral 0)) id (Data.Time.Format.parseTimeM True Data.Time.Format.defaultTimeLocale "%s" $(Language.Haskell.TH.Syntax.runIO (Data.Time.Clock.getCurrentTime >>= \ t -> return (Language.Haskell.TH.Syntax.LitE (Language.Haskell.TH.Syntax.StringL (Data.Time.Format.formatTime Data.Time.Format.defaultTimeLocale "%s" t))))) :: Maybe Data.Time.Clock.UTCTime) #-} record cedille-args : Set where constructor mk-cedille-args field opts-file : maybe filepath files : 𝕃 string getCedilleArgs : IO cedille-args getCedilleArgs = getArgs >>= λ args → filterArgs args (mk-cedille-args nothing []) where is-opts-flag = "--options" =string_ bad-flag : IO ⊤ bad-flag = putStrLn "Warning: Flag --options should be followed by a Cedille options file" -- allow for later --options to override earlier. This is a bash idiom filterArgs : 𝕃 string → cedille-args → IO cedille-args filterArgs [] args = return args filterArgs (x :: []) args = if is-opts-flag x then bad-flag >> return args else (return $ record args {files = x :: cedille-args.files args}) filterArgs (x :: y :: xs) args = if is-opts-flag x then filterArgs xs (record args { opts-file = just y}) else filterArgs (y :: xs) (record args { files = x :: cedille-args.files args}) process-encoding : filepath → cedille-options.options → IO cedille-options.options process-encoding ofp ops @ (cedille-options.mk-options ip cede rkt log qvs etp de col ~? nl) = maybe-else' de (return ops) λ de-f → let de = fst de-f s = new-toplevel-state (cedille-options.include-path-insert (takeDirectory de) ip) in update-asts s de >>= λ s → process-encoding-file s de >>= λ f? → maybe-else' f? (return ops) λ ast~ → return (record ops {datatype-encoding = just (de , just ast~)}) where ops' = record ops {datatype-encoding = nothing; use-cede-files = ff} open main-with-options compileTime ofp ops' die open import spans ops' {IO} open import toplevel-state ops' {IO} open import process-cmd ops' {IO} (λ _ → return triv) (λ _ → return triv) open import syntax-util open import ctxt process-encoding-file : toplevel-state → filepath → IO (maybe file) process-encoding-file s fp with get-include-elt-if s fp >>= include-elt.ast ...| nothing = putStrLn ("Error looking up datatype encoding information from file " ^ fp) >> return nothing ...| just (ExModule is pi1 pi2 mn ps cs pi3) = (process-cmds (record s {Γ = ctxt-initiate-file (toplevel-state.Γ s) fp mn}) (map ExCmdImport is) >>=c λ s is' → process-params s first-position [] >>=c λ s _ → check-and-add-params (toplevel-state.Γ s) (params-end-pos first-position ps) ps >>=c λ Γₚₛ ps~ → process-cmds (record s {Γ = Γₚₛ}) cs >>=c λ s cs → return2 ps~ (is' ++ cs)) empty-spans >>=c uncurry λ ps cs _ → return (just (Module mn ps cs)) -- main entrypoint for the backend main : IO ⊤ main = initializeStdoutToUTF8 >> initializeStdinToUTF8 >> setStdoutNewlineMode >> setStdinNewlineMode >> setToLineBuffering >> getCedilleArgs >>= λ args → let mk-cedille-args optsf fs = args in maybe-else' optsf (findOptionsFile >>= readOptions) (readOptions ∘ just) >>=c λ ofp ops → let log = cedille-options.options.generate-logs ops in process-encoding ofp (record ops {generate-logs = ff}) >>= λ ops → main-with-options.main' compileTime ofp (record ops {generate-logs = log}) die fs
47.755627
251
0.643213
6500eaad38b49d3a44b1dc9c4c7b456c6e7dc6d2
214
agda
Agda
test/Succeed/Issue1719/Spans.agda
zgrannan/agda
5953ce337eb6b77b29ace7180478f49c541aea1c
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/Issue1719/Spans.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue1719/Spans.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --without-K --rewriting #-} module Issue1719.Spans where open import Issue1719.Common record Span : Set₁ where constructor span field A B C : Set f : C → A g : C → B open Span public
15.285714
39
0.649533
cc7a1b23c22c7d288d9b9a3f51cf67b1021ddac5
6,634
agda
Agda
Cubical/Experiments/ZCohomologyOld/Groups/Wedge.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Experiments/ZCohomologyOld/Groups/Wedge.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Experiments/ZCohomologyOld/Groups/Wedge.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-} module Cubical.Experiments.ZCohomologyOld.Groups.Wedge where open import Cubical.ZCohomology.Base open import Cubical.Experiments.ZCohomologyOld.Properties open import Cubical.Experiments.ZCohomologyOld.MayerVietorisUnreduced open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Function open import Cubical.HITs.Wedge open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁) open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2) open import Cubical.Data.Nat open import Cubical.Algebra.Group open import Cubical.Experiments.ZCohomologyOld.Groups.Unit open import Cubical.Experiments.ZCohomologyOld.Groups.Sn open import Cubical.HITs.Pushout open import Cubical.Data.Sigma open import Cubical.Foundations.Isomorphism open import Cubical.Homotopy.Connected open import Cubical.HITs.Susp open import Cubical.HITs.S1 open import Cubical.HITs.Sn open import Cubical.Foundations.Equiv module _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') where module I = MV (typ A) (typ B) Unit (λ _ → pt A) (λ _ → pt B) Hⁿ-⋁ : (n : ℕ) → GroupIso (coHomGr (suc n) (A ⋁ B)) (×coHomGr (suc n) (typ A) (typ B)) Hⁿ-⋁ zero = BijectionIsoToGroupIso bijIso where surj-helper : (x : coHom 0 Unit) → isInIm _ _ (I.Δ 0) x surj-helper = sElim (λ _ → isOfHLevelSuc 1 propTruncIsProp) λ f → ∣ (∣ (λ _ → f tt) ∣₂ , 0ₕ 0) , cong ∣_∣₂ (funExt λ _ → -rUnitₖ 0 (f tt)) ∣₁ helper : (x : coHom 1 (A ⋁ B)) → isInIm _ _ (I.d 0) x → x ≡ 0ₕ 1 helper x inim = pRec (setTruncIsSet _ _) (λ p → sym (snd p) ∙ MV.Im-Δ⊂Ker-d _ _ Unit (λ _ → pt A) (λ _ → pt B) 0 (fst p) (surj-helper (fst p))) inim bijIso : BijectionIso (coHomGr 1 (A ⋁ B)) (×coHomGr 1 (typ A) (typ B)) BijectionIso.map' bijIso = I.i 1 BijectionIso.inj bijIso = sElim (λ _ → isSetΠ λ _ → isProp→isSet (setTruncIsSet _ _)) λ f inker → helper ∣ f ∣₂ (I.Ker-i⊂Im-d 0 ∣ f ∣₂ inker) BijectionIso.surj bijIso p = I.Ker-Δ⊂Im-i 1 p (isContr→isProp (isContrHⁿ-Unit 0) _ _) Hⁿ-⋁ (suc n) = Iso+Hom→GrIso mainIso (sElim2 (λ _ _ → isOfHLevelPath 2 (isOfHLevel× 2 setTruncIsSet setTruncIsSet) _ _) λ _ _ → refl) where helpIso : ∀ {ℓ'''} {C : Type ℓ'''} → Iso (A ⋁ B → C) (Σ[ f ∈ (typ A → C) × (typ B → C) ] (fst f) (pt A) ≡ (snd f) (pt B)) Iso.fun helpIso f = ((λ x → f (inl x)) , λ x → f (inr x)) , cong f (push tt) Iso.inv helpIso ((f , g) , p) (inl x) = f x Iso.inv helpIso ((f , g) , p) (inr x) = g x Iso.inv helpIso ((f , g) , p) (push a i) = p i Iso.rightInv helpIso ((f , g) , p) = ΣPathP (ΣPathP (refl , refl) , refl) Iso.leftInv helpIso f = funExt λ {(inl a) → refl ; (inr a) → refl ; (push a i) → refl} mainIso : Iso (coHom (2 + n) (A ⋁ B)) (coHom (2 + n) (typ A) × coHom (2 + n) (typ B)) mainIso = compIso (setTruncIso helpIso) (compIso theIso setTruncOfProdIso) where forget : ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂ → ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂ forget = sMap (λ {((f , g) , _) → f , g}) isEq : (f : ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂) → isContr (fiber forget f) isEq = sElim (λ _ → isOfHLevelSuc 1 isPropIsContr) (uncurry λ f g → helper f g (f (pt A)) (g (pt B)) refl refl) where helper : (f : (typ A → coHomK (2 + n))) (g : (typ B → coHomK (2 + n))) (x y : coHomK (2 + n)) → f (pt A) ≡ x → g (pt B) ≡ y → isContr (fiber forget ∣ f , g ∣₂) helper f g = trElim2 (λ _ _ → isProp→isOfHLevelSuc (3 + n) (isPropΠ2 λ _ _ → isPropIsContr)) (suspToPropElim2 (ptSn (suc n)) (λ _ _ → isPropΠ2 λ _ _ → isPropIsContr) λ p q → (∣ (f , g) , (p ∙ sym q) ∣₂ , refl) , uncurry (sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 (isOfHLevelΣ 2 setTruncIsSet λ _ → isOfHLevelPath 2 setTruncIsSet _ _) _ _) λ { ((f' , g') , id1) y → Σ≡Prop (λ _ → setTruncIsSet _ _) (pRec (setTruncIsSet _ _) (λ id2 → trRec (setTruncIsSet _ _) (λ pathp → cong ∣_∣₂ (ΣPathP ((sym id2) , pathp))) (isConnectedPathP 1 {A = λ i → (fst (id2 (~ i)) (pt A) ≡ snd (id2 (~ i)) (pt B))} (isConnectedPath 2 (isConnectedSubtr 3 n (subst (λ m → isConnected m (coHomK (2 + n))) (+-comm 3 n) (isConnectedKn (suc n)))) _ _) (p ∙ sym q) id1 .fst)) (Iso.fun PathIdTrunc₀Iso y))})) theIso : Iso ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂ ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂ theIso = equivToIso (forget , record { equiv-proof = isEq }) {- Alternative, less direct proof : vSES→GroupIso _ _ (ses (isOfHLevelSuc 0 (isContrHⁿ-Unit n)) (isOfHLevelSuc 0 (isContrHⁿ-Unit (suc n))) (I.d (suc n)) (I.Δ (suc (suc n))) (I.i (suc (suc n))) (I.Ker-i⊂Im-d (suc n)) (I.Ker-Δ⊂Im-i (suc (suc n)))) -} wedgeConnected : ((x : typ A) → ∥ pt A ≡ x ∥) → ((x : typ B) → ∥ pt B ≡ x ∥) → (x : A ⋁ B) → ∥ inl (pt A) ≡ x ∥ wedgeConnected conA conB = PushoutToProp (λ _ → propTruncIsProp) (λ a → pRec propTruncIsProp (λ p → ∣ cong inl p ∣₁) (conA a)) λ b → pRec propTruncIsProp (λ p → ∣ push tt ∙ cong inr p ∣₁) (conB b)
53.934959
154
0.500904
640eab8dcdec83dc61130b221fe0e1db93305b83
9,146
agda
Agda
lib/Equivalences.agda
UlrikBuchholtz/HoTT-Agda
f8fa68bf753d64d7f45556ca09d0da7976709afa
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
lib/Equivalences.agda
UlrikBuchholtz/HoTT-Agda
f8fa68bf753d64d7f45556ca09d0da7976709afa
[ "MIT" ]
null
null
null
lib/Equivalences.agda
UlrikBuchholtz/HoTT-Agda
f8fa68bf753d64d7f45556ca09d0da7976709afa
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Base open import lib.PathGroupoid open import lib.PathFunctor open import lib.NType module lib.Equivalences where {- We use the half-adjoint definition of equivalences (but this fact should be invisible to the user of the library). The constructor of the type of equivalences is [equiv], it takes two maps and the two proofs that the composites are equal: [equiv to from to-from from-to] The type of equivalences between two types [A] and [B] can be written either [A ≃ B] or [Equiv A B]. Given an equivalence [e] : [A ≃ B], you can extract the two maps as follows: [–> e] : [A → B] and [<– e] : [B → A] (the dash is an en dash) The proofs that the composites are the identities are [<–-inv-l] and [<–-inv-r]. The identity equivalence on [A] is [ide A], the composition of two equivalences is [_∘e_] (function composition order) and the inverse of an equivalence is [_⁻¹] -} module _ {i} {j} {A : Type i} {B : Type j} where record is-equiv (f : A → B) : Type (lmax i j) where field g : B → A f-g : (b : B) → f (g b) == b g-f : (a : A) → g (f a) == a adj : (a : A) → ap f (g-f a) == f-g (f a) {- In order to prove that something is an equivalence, you have to give an inverse and a proof that it’s an inverse (you don’t need the adj part). [is-eq] is a very, very bad name. -} is-eq : (f : A → B) (g : B → A) (f-g : (b : B) → f (g b) == b) (g-f : (a : A) → g (f a) == a) → is-equiv f is-eq f g f-g g-f = record {g = g; f-g = f-g'; g-f = g-f; adj = adj} where f-g' : (b : B) → f (g b) == b f-g' b = ! (ap (f ∘ g) (f-g b)) ∙ ap f (g-f (g b)) ∙ f-g b adj : (a : A) → ap f (g-f a) == f-g' (f a) adj a = ap f (g-f a) =⟨ ! (!-inv-l (ap (f ∘ g) (f-g (f a)))) |in-ctx (λ q → q ∙ ap f (g-f a)) ⟩ (! (ap (f ∘ g) (f-g (f a))) ∙ ap (f ∘ g) (f-g (f a))) ∙ ap f (g-f a) =⟨ ∙-assoc (! (ap (f ∘ g) (f-g (f a)))) (ap (f ∘ g) (f-g (f a))) _ ⟩ ! (ap (f ∘ g) (f-g (f a))) ∙ ap (f ∘ g) (f-g (f a)) ∙ ap f (g-f a) =⟨ lemma |in-ctx (λ q → ! (ap (f ∘ g) (f-g (f a))) ∙ q) ⟩ ! (ap (f ∘ g) (f-g (f a))) ∙ ap f (g-f (g (f a))) ∙ f-g (f a) ∎ where lemma : ap (f ∘ g) (f-g (f a)) ∙ ap f (g-f a) == ap f (g-f (g (f a))) ∙ f-g (f a) lemma = ap (f ∘ g) (f-g (f a)) ∙ ap f (g-f a) =⟨ htpy-natural-toid f-g (f a) |in-ctx (λ q → q ∙ ap f (g-f a)) ⟩ f-g (f (g (f a))) ∙ ap f (g-f a) =⟨ ! (ap-idf (ap f (g-f a))) |in-ctx (λ q → f-g (f (g (f a))) ∙ q) ⟩ f-g (f (g (f a))) ∙ ap (idf B) (ap f (g-f a)) =⟨ ! (htpy-natural f-g (ap f (g-f a))) ⟩ ap (f ∘ g) (ap f (g-f a)) ∙ f-g (f a) =⟨ ap-∘ f g (ap f (g-f a)) |in-ctx (λ q → q ∙ f-g (f a)) ⟩ ap f (ap g (ap f (g-f a))) ∙ f-g (f a) =⟨ ∘-ap g f (g-f a) ∙ htpy-natural-toid g-f a |in-ctx (λ q → ap f q ∙ f-g (f a)) ⟩ ap f (g-f (g (f a))) ∙ f-g (f a) ∎ infix 30 _≃_ _≃_ : ∀ {i j} (A : Type i) (B : Type j) → Type (lmax i j) A ≃ B = Σ (A → B) is-equiv Equiv = _≃_ module _ {i} {j} {A : Type i} {B : Type j} where equiv : (f : A → B) (g : B → A) (f-g : (b : B) → f (g b) == b) (g-f : (a : A) → g (f a) == a) → A ≃ B equiv f g f-g g-f = (f , is-eq f g f-g g-f) –> : (e : A ≃ B) → (A → B) –> e = fst e <– : (e : A ≃ B) → (B → A) <– e = is-equiv.g (snd e) <–-inv-l : (e : A ≃ B) (a : A) → (<– e (–> e a) == a) <–-inv-l e a = is-equiv.g-f (snd e) a <–-inv-r : (e : A ≃ B) (b : B) → (–> e (<– e b) == b) <–-inv-r e b = is-equiv.f-g (snd e) b <–-inv-adj : (e : A ≃ B) (a : A) → ap (–> e) (<–-inv-l e a) == <–-inv-r e (–> e a) <–-inv-adj e a = is-equiv.adj (snd e) a -- Equivalences are "injective" equiv-inj : (e : A ≃ B) {x y : A} → (–> e x == –> e y → x == y) equiv-inj e {x} {y} p = ! (<–-inv-l e x) ∙ ap (<– e) p ∙ <–-inv-l e y idf-is-equiv : ∀ {i} (A : Type i) → is-equiv (idf A) idf-is-equiv A = is-eq _ (idf A) (λ _ → idp) (λ _ → idp) ide : ∀ {i} (A : Type i) → A ≃ A ide A = equiv (idf A) (idf A) (λ _ → idp) (λ _ → idp) infixr 80 _∘e_ infixr 80 _∘ise_ _∘e_ : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} → B ≃ C → A ≃ B → A ≃ C e1 ∘e e2 = equiv (–> e1 ∘ –> e2) (<– e2 ∘ <– e1) (λ c → –> e1 (–> e2 (<– e2 (<– e1 c))) =⟨ <–-inv-r e2 (<– e1 c) |in-ctx (–> e1) ⟩ –> e1 (<– e1 c) =⟨ <–-inv-r e1 c ⟩ c ∎) (λ a → <– e2 (<– e1 (–> e1 (–> e2 a))) =⟨ <–-inv-l e1 (–> e2 a) |in-ctx (<– e2) ⟩ <– e2 (–> e2 a) =⟨ <–-inv-l e2 a ⟩ a ∎) _∘ise_ : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} {f : A → B} {g : B → C} → is-equiv g → is-equiv f → is-equiv (g ∘ f) i1 ∘ise i2 = snd ((_ , i1) ∘e (_ , i2)) infix 120 _⁻¹ _⁻¹ : ∀ {i j} {A : Type i} {B : Type j} → (A ≃ B) → (B ≃ A) e ⁻¹ = equiv (<– e) (–> e) (<–-inv-l e) (<–-inv-r e) {- Equational reasoning for equivalences -} infix 15 _≃∎ infixr 10 _≃⟨_⟩_ _≃⟨_⟩_ : ∀ {i j k} (A : Type i) {B : Type j} {C : Type k} → A ≃ B → B ≃ C → A ≃ C A ≃⟨ u ⟩ v = v ∘e u _≃∎ : ∀ {i} (A : Type i) → A ≃ A _≃∎ = ide {- lifting is an equivalence -} lift-equiv : ∀ {i j} {A : Type i} → Lift {j = j} A ≃ A lift-equiv = equiv lower lift (λ _ → idp) (λ _ → idp) {- Any contractible type is equivalent to (all liftings of) the unit type -} module _ {i} {A : Type i} (h : is-contr A) where contr-equiv-Unit : A ≃ Unit contr-equiv-Unit = equiv (λ _ → unit) (λ _ → fst h) (λ _ → idp) (snd h) contr-equiv-LiftUnit : ∀ {j} → A ≃ Lift {j = j} Unit contr-equiv-LiftUnit = lift-equiv ⁻¹ ∘e contr-equiv-Unit {- An equivalence induces an equivalence on the path spaces -} module _ {i j} {A : Type i} {B : Type j} (e : A ≃ B) where private abstract left-inverse : {x y : A} (p : x == y) → equiv-inj e (ap (–> e) p) == p left-inverse idp = !-inv-l (<–-inv-l e _) right-inverse : {x y : A} (p : –> e x == –> e y) → ap (–> e) (equiv-inj e p) == p right-inverse {x} {y} p = ap f (! (g-f x) ∙ ap g p ∙ (g-f y)) =⟨ ap-∙ f (! (g-f x)) (ap g p ∙ (g-f y)) ⟩ ap f (! (g-f x)) ∙ ap f (ap g p ∙ (g-f y)) =⟨ ap-∙ f (ap g p) (g-f y) |in-ctx (λ q → ap f (! (g-f x)) ∙ q) ⟩ ap f (! (g-f x)) ∙ ap f (ap g p) ∙ ap f (g-f y) =⟨ ∘-ap f g p |in-ctx (λ q → ap f (! (g-f x)) ∙ q ∙ ap f (g-f y)) ⟩ ap f (! (g-f x)) ∙ ap (f ∘ g) p ∙ ap f (g-f y) =⟨ adj y |in-ctx (λ q → ap f (! (g-f x)) ∙ ap (f ∘ g) p ∙ q) ⟩ ap f (! (g-f x)) ∙ ap (f ∘ g) p ∙ (f-g (f y)) =⟨ ap-! f (g-f x) |in-ctx (λ q → q ∙ ap (f ∘ g) p ∙ (f-g (f y))) ⟩ ! (ap f (g-f x)) ∙ ap (f ∘ g) p ∙ (f-g (f y)) =⟨ adj x |in-ctx (λ q → ! q ∙ ap (f ∘ g) p ∙ (f-g (f y))) ⟩ ! (f-g (f x)) ∙ ap (f ∘ g) p ∙ (f-g (f y)) =⟨ htpy-natural f-g p |in-ctx (λ q → ! (f-g (f x)) ∙ q) ⟩ ! (f-g (f x)) ∙ (f-g (f x)) ∙ ap (idf B) p =⟨ ! (∙-assoc (! (f-g (f x))) (f-g (f x)) (ap (idf B) p)) ∙ ap (λ q → q ∙ ap (idf B) p) (!-inv-l (f-g (f x))) ∙ ap-idf p ⟩ p ∎ where f : A → B f = fst e open is-equiv (snd e) equiv-ap : (x y : A) → (x == y) ≃ (–> e x == –> e y) equiv-ap x y = equiv (ap (–> e)) (equiv-inj e) right-inverse left-inverse {- Equivalent types have the same truncation level -} equiv-preserves-level : ∀ {i j} {A : Type i} {B : Type j} {n : ℕ₋₂} (e : A ≃ B) → (has-level n A → has-level n B) equiv-preserves-level {n = ⟨-2⟩} e (x , p) = (–> e x , (λ y → ap (–> e) (p _) ∙ <–-inv-r e y)) equiv-preserves-level {n = S n} e c = λ x y → equiv-preserves-level (equiv-ap (e ⁻¹) x y ⁻¹) (c (<– e x) (<– e y)) {- This is a collection of type equivalences involving basic type formers. We exclude Empty since Π₁-Empty requires λ=. -} module _ {j} {B : Unit → Type j} where Σ₁-Unit : Σ Unit B ≃ B unit Σ₁-Unit = equiv (λ {(unit , b) → b}) (λ b → (unit , b)) (λ _ → idp) (λ _ → idp) Π₁-Unit : Π Unit B ≃ B unit Π₁-Unit = equiv (λ f → f unit) (λ b _ → b) (λ _ → idp) (λ _ → idp) module _ {i} {A : Type i} where Σ₂-Unit : Σ A (λ _ → Unit) ≃ A Σ₂-Unit = equiv fst (λ a → (a , unit)) (λ _ → idp) (λ _ → idp) Π₂-Unit : Π A (λ _ → Unit) ≃ Unit Π₂-Unit = equiv (λ _ → unit) (λ _ _ → unit) (λ _ → idp) (λ _ → idp) module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} where Σ-assoc : Σ (Σ A B) (uncurry C) ≃ Σ A (λ a → Σ (B a) (C a)) Σ-assoc = equiv (λ {((a , b) , c) → (a , (b , c))}) (λ {(a , (b , c)) → ((a , b) , c)}) (λ _ → idp) (λ _ → idp) curry-equiv : Π (Σ A B) (uncurry C) ≃ Π A (λ a → Π (B a) (C a)) curry-equiv = equiv curry uncurry (λ _ → idp) (λ _ → idp) {- The type-theoretic axiom of choice -} choice : Π A (λ a → Σ (B a) (λ b → C a b)) ≃ Σ (Π A B) (λ g → Π A (λ a → C a (g a))) choice = equiv f g (λ _ → idp) (λ _ → idp) where f = λ c → ((λ a → fst (c a)) , (λ a → snd (c a))) g = λ d → (λ a → (fst d a , snd d a)) {- Homotopy fibers -} hfiber : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) (y : B) → Type (lmax i j) hfiber {A = A} f y = Σ A (λ x → f x == y)
37.330612
86
0.442051
5262cddd3a72b46377fa43aae459f7a8255a3998
57
agda
Agda
test/Succeed/PublicWithoutOpen2.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/PublicWithoutOpen2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/PublicWithoutOpen2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module PublicWithoutOpen2 where import Imports.A public
14.25
31
0.859649
7cce6bf8c0bc7ee36056fd15676971a691106b79
917
agda
Agda
agda-stdlib/src/Data/Nat.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Nat.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Nat.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Natural numbers ------------------------------------------------------------------------ -- See README.Data.Nat for examples of how to use and reason about -- naturals. {-# OPTIONS --without-K --safe #-} module Data.Nat where ------------------------------------------------------------------------ -- Publicly re-export the contents of the base module open import Data.Nat.Base public ------------------------------------------------------------------------ -- Publicly re-export queries open import Data.Nat.Properties public using ( _≟_ ; _≤?_ ; _≥?_ ; _<?_ ; _>?_ ; _≤′?_; _≥′?_; _<′?_; _>′?_ ; _≤″?_; _<″?_; _≥″?_; _>″?_ ) ------------------------------------------------------------------------ -- Deprecated -- Version 0.17 open import Data.Nat.Properties public using (≤-pred)
24.783784
72
0.381679
43c965cb38852ebf903ccc463b33c324a5e6d5bf
10,085
agda
Agda
agda/paper/Dijkstra-monad/2019-03-Wouter-Swierstra_A_Predicate_Transformer_for_Effects/x.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
36
2015-01-29T14:37:15.000Z
2021-07-30T06:55:03.000Z
agda/paper/Dijkstra-monad/2019-03-Wouter-Swierstra_A_Predicate_Transformer_for_Effects/x.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
null
null
null
agda/paper/Dijkstra-monad/2019-03-Wouter-Swierstra_A_Predicate_Transformer_for_Effects/x.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
8
2015-04-13T21:40:15.000Z
2021-09-21T15:58:10.000Z
{-# OPTIONS --type-in-type #-} -- NOT SOUND! open import Data.Empty using (⊥) open import Data.Nat renaming (ℕ to Nat) open import Data.Nat.DivMod open import Data.Product hiding (map) open import Data.Unit using (⊤) module x where {- https://webspace.science.uu.nl/~swier004/publications/2019-icfp-submission-a.pdf A predicate transformer semantics for effects WOUTER SWIERSTRA and TIM BAANEN, Universiteit Utrecht abstract reasoning about effectful code harder than pure code predicate transformer (PT) semantics gives a refinement relation that can be used to - relate a program to its specification, or - calculate effectful programs that are correct by construction INTRODUCTION key techniques - syntax of effectful computations represented as free monads - assigning meaning to these monads gives meaning to the syntactic ops each effect provides - paper shows how to assign PT semantics to computations arising from Kleisli arrows on free monads - enables computing the weakest precondition associated with a given postcondition - using weakest precondition semantics - define refinement on computations - show how to - use this refinement relation to show a program satisfies its specification, or - calculate a program from its specification. - show how programs and specifications may be mixed, enabling verified programs to be calculated from their specification one step at a time 2 BACKGROUND Free monads -} -- C : type of commands -- Free C R : returns an 'a' or issues command c : C -- For each c : C, there is a set of responses R c -- 2nd arg of Step is continuation : how to proceed after receiving response R c data Free (C : Set) (R : C → Set) (a : Set) : Set where Pure : a → Free C R a Step : (c : C) → (R c → Free C R a) → Free C R a -- show that 'Free' is a monad: map : ∀ {a b C : Set} {R : C → Set} → (a → b) → Free C R a → Free C R b map f (Pure x) = Pure (f x) map f (Step c k) = Step c (λ r → map f (k r)) return : ∀ {a C : Set} {R : C → Set} → a → Free C R a return = Pure _>>=_ : ∀ {a b C : Set} {R : C → Set} → Free C R a → (a → Free C R b) → Free C R b Pure x >>= f = f x Step c x >>= f = Step c (λ r → x r >>= f) {- different effects choose C and R differently, depending on their ops Weakest precondition semantics idea of associating weakest precondition semantics with imperative programs dates to Dijkstra’s Guarded Command Language [1975] ways to specify behaviour of function f : a → b - reference implementation - define a relation R : a → b → Set - write contracts and test cases - PT semantics call values of type a → Set : predicate on type a PTs are functions between predicates e.g., weakest precondition: -} -- "maps" -- function f : a → b and -- desired postcondition on the function’s output, b → Set -- to weakest precondition a → Set on function’s input that ensures postcondition satisfied -- -- note: definition is just reverse function composition -- wp0 : ∀ {a b : Set} → (f : a → b) → (b → Set) → (a → Set) wp0 : ∀ {a : Set} {b : Set} (f : a → b) → (b → Set) → (a → Set) wp0 f P = λ x → P (f x) {- above wp semantics is sometimes too restrictive - no way to specify that output is related to input - fix via making f dependent: -} wp : ∀ {a : Set} {b : a → Set} (f : (x : a) → b x) → ((x : a) → b x → Set) → (a → Set) wp f P = λ x → P x (f x) -- shorthand for working with predicates and predicates transformers _⊆_ : ∀ {a : Set} → (a → Set) → (a → Set) → Set P ⊆ Q = ∀ x → P x → Q x -- refinement relation defined between PTs _⊑_ : ∀ {a : Set} {b : a → Set} → (pt1 pt2 : ((x : a) → b x → Set) → (a → Set)) → Set₁ pt1 ⊑ pt2 = ∀ P → pt1 P ⊆ pt2 P {- use refinement relation - to relate PT semantics between programs and specifications - to show a program satisfies its specification; or - to show that one program is somehow ‘better’ than another, where ‘better’ is defined by choice of PT semantics in pure setting, this refinement relation is not interesting: the refinement relation corresponds to extensional equality between functions: lemma follows from the ‘Leibniz rule’ for equality in intensional type theory: refinement : ∀ (f g : a → b) → (wp f ⊑ wp g) ↔ (∀ x → f x ≡ g x) this paper defines PT semantics for Kleisli arrows of form a → Free C R b could use 'wp' to assign semantics to these computations directly, but typically not interested in syntactic equality between free monads rather want to study semantics of effectful programs they represent to define a PT semantics for effects define a function with form: -- how to lift a predicate on 'a' over effectful computation returning 'a' pt : (a → Set) → Free C R a → Set 'pt' def depends on semantics desired for a particulr free monad Crucially, choice of pt and weakest precondition semantics, wp, together give a way to assign weakest precondition semantics to Kleisli arrows representing effectful computations 3 PARTIALITY Partial computations : i.e., 'Maybe' make choices for commands C and responses R -} data C : Set where Abort : C -- no continuation R : C → Set R Abort = ⊥ -- since C has no continuation, valid responses is empty Partial : Set → Set Partial = Free C R -- smart constructor for failure: abort : ∀ {a : Set} → Partial a abort = Step Abort (λ ()) {- computation of type Partial a will either - return a value of type a or - fail, issuing abort command Note that responses to Abort command are empty; abort smart constructor abort uses this to discharge the continuation in the second argument of the Step constructor Example: division expression language, closed under division and natural numbers: -} data Expr : Set where Val : Nat → Expr Div : Expr → Expr → Expr -- semantics specified using inductively defined RELATION: -- def rules out erroneous results by requiring the divisor evaluates to non-zero data _⇓_ : Expr → Nat → Set where Base : ∀ {x : Nat} → Val x ⇓ x Step : ∀ {l r : Expr} {v1 v2 : Nat} → l ⇓ v1 → r ⇓ (suc v2) → Div l r ⇓ (v1 div (suc v2)) -- Alternatively -- evaluate Expr via monadic INTERPRETER, using Partial to handle division-by-zero -- op used by ⟦_⟧ interpreter _÷_ : Nat → Nat → Partial Nat n ÷ zero = abort n ÷ (suc k) = return (n div (suc k)) ⟦_⟧ : Expr → Partial Nat ⟦ Val x ⟧ = return x ⟦ Div e1 e2 ⟧ = ⟦ e1 ⟧ >>= λ v1 → ⟦ e2 ⟧ >>= λ v2 → v1 ÷ v2 {- std lib 'div' requires implicit proof that divisor is non-zero when divisor is zero, interpreter fail explicitly with abort How to relate these two definitions? Assign a weakest precondition semantics to Kleisli arrows of the form a → Partial b -} wpPartial : ∀ {a : Set} {b : a → Set} → (f : (x : a) → Partial (b x)) → (P : (x : a) → b x → Set) → (a → Set) wpPartial f P = wp f (mustPT P) where mustPT : ∀ {a : Set} {b : a → Set} → (P : (x : a) → b x → Set) → (x : a) → Partial (b x) → Set mustPT P _ (Pure y) = P _ y mustPT P _ (Step Abort _) = ⊥ {- To call 'wp', must show how to transform - predicate P : b → Set - to a predicate on partial results : Partial b → Set Done via proposition 'mustPT P c' - holds when computation c of type Partial b successfully returns a 'b' that satisfies P particular PT semantics of partial computations determined by def mustPT here: rule out failure entirely - so case Abort returns empty type Given this PT semantics for Kleisli arrows in general, can now study semantics of above monadic interpreter via passing - interpreter: ⟦_⟧ - desired postcondition : _⇓_ as arguments to wpPartial: wpPartial ⟦_⟧ _⇓_ : Expr → Set resulting in a predicate on expressions for all expressions satisfying this predicate, the monadic interpreter and the relational specification, _⇓_, must agree on the result of evaluation What does this say about correctness of interpreter? To understand the predicate better, consider defining this predicate on expressions: -} SafeDiv : Expr → Set SafeDiv (Val x) = ⊤ SafeDiv (Div e1 e2) = (e2 ⇓ zero → ⊥) {-∧-} × SafeDiv e1 {-∧-} × SafeDiv e2 {- Expect : any expr e for which SafeDiv e holds can be evaluated without division-by-zero can prove SafeDiv is sufficient condition for two notions of evaluation to coincide: -- lemma relates the two semantics -- expressed as a relation and an evaluator -- for those expressions that satisfy the SafeDiv property correct : SafeDiv ⊆ wpPartial ⟦_⟧ _⇓_ Instead of manually defining SafeDiv, define more general predicate characterising the domain of a partial function: -} dom : ∀ {a : Set} {b : a → Set} → ((x : a) → Partial (b x)) → (a → Set) dom f = wpPartial f (λ _ _ → ⊤) {- can show that the two semantics agree precisely on the domain of the interpreter: sound : dom ⟦_⟧ ⊆ wpPartial ⟦_⟧ _⇓_ complete : wpPartial ⟦_⟧ _⇓_ ⊆ dom ⟦_⟧ both proofs proceed by induction on the argument expression Refinement weakest precondition semantics on partial computations give rise to a refinement relation on Kleisli arrows of the form a → Partial b can characterise this relation by proving: refinement : (f g : a → Maybe b) → (wpPartial f ⊑ wpPartial g) ↔ (∀ x → (f x ≡ g x) ∨ (f x ≡ Nothing)) use refinement to relate Kleisli morphisms, and to relate a program to a specification given by a pre- and postcondition Example: Add (interpreter for stack machine) add top two elements; can fail fail if stack has too few elements below shows how to prove the definition meets its specification Define specification in terms of a pre/post condition. The specification of a function of type (x : a) → b x consists of -} record Spec (a : Set) (b : a → Set) : Set where constructor [_,_] field pre : a → Set -- a precondition on a, and post : (x : a) → b x → Set -- a postcondition relating inputs that satisfy this precondition -- and the corresponding outputs
31.126543
96
0.677243
7c7105b9f9dd9d53b6edb027eedcb201d67bc38c
628
agda
Agda
NonReflectiveQ.agda
z-murray/AnalysisAgda
6fbaca08b1d63b5765d184f6284fb0e58c9f5e52
[ "MIT" ]
null
null
null
NonReflectiveQ.agda
z-murray/AnalysisAgda
6fbaca08b1d63b5765d184f6284fb0e58c9f5e52
[ "MIT" ]
null
null
null
NonReflectiveQ.agda
z-murray/AnalysisAgda
6fbaca08b1d63b5765d184f6284fb0e58c9f5e52
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Agda.Builtin.Bool open import Data.Maybe.Base using (Maybe; just; nothing) open import Relation.Nullary open import Data.Rational.Unnormalised.Base using (ℚᵘ; 0ℚᵘ; _≃_) open import Data.Rational.Unnormalised.Properties using (+-*-commutativeRing; _≃?_) isZero? : ∀ (p : ℚᵘ) -> Maybe (0ℚᵘ ≃ p) isZero? p with 0ℚᵘ ≃? p ... | .true because ofʸ p₁ = just p₁ ... | .false because ofⁿ ¬p = nothing open import Tactic.RingSolver.Core.AlmostCommutativeRing using (fromCommutativeRing) open import Tactic.RingSolver.NonReflective (fromCommutativeRing +-*-commutativeRing isZero?) public
39.25
100
0.743631
ccd5f258143213af6dc09540bc5411c3f7822225
16,619
agda
Agda
agda-stdlib-0.9/src/Data/Nat/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/Nat/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Nat/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- A bunch of properties about natural number operations ------------------------------------------------------------------------ -- See README.Nat for some examples showing how this module can be -- used. module Data.Nat.Properties where open import Data.Nat as Nat open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≡⟨_⟩'_) open import Relation.Binary open DecTotalOrder Nat.decTotalOrder using () renaming (refl to ≤-refl) open import Function open import Algebra open import Algebra.Structures open import Relation.Nullary open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; _≢_; refl; sym; cong; cong₂) open PropEq.≡-Reasoning import Algebra.FunctionProperties as P; open P (_≡_ {A = ℕ}) open import Data.Product open import Data.Sum ------------------------------------------------------------------------ -- basic lemmas about (ℕ, +, *, 0, 1): open import Data.Nat.Properties.Simple -- (ℕ, +, *, 0, 1) is a commutative semiring isCommutativeSemiring : IsCommutativeSemiring _≡_ _+_ _*_ 0 1 isCommutativeSemiring = record { +-isCommutativeMonoid = record { isSemigroup = record { isEquivalence = PropEq.isEquivalence ; assoc = +-assoc ; ∙-cong = cong₂ _+_ } ; identityˡ = λ _ → refl ; comm = +-comm } ; *-isCommutativeMonoid = record { isSemigroup = record { isEquivalence = PropEq.isEquivalence ; assoc = *-assoc ; ∙-cong = cong₂ _*_ } ; identityˡ = +-right-identity ; comm = *-comm } ; distribʳ = distribʳ-*-+ ; zeroˡ = λ _ → refl } commutativeSemiring : CommutativeSemiring _ _ commutativeSemiring = record { _+_ = _+_ ; _*_ = _*_ ; 0# = 0 ; 1# = 1 ; isCommutativeSemiring = isCommutativeSemiring } import Algebra.RingSolver.Simple as Solver import Algebra.RingSolver.AlmostCommutativeRing as ACR module SemiringSolver = Solver (ACR.fromCommutativeSemiring commutativeSemiring) _≟_ ------------------------------------------------------------------------ -- (ℕ, ⊔, ⊓, 0) is a commutative semiring without one private ⊔-assoc : Associative _⊔_ ⊔-assoc zero _ _ = refl ⊔-assoc (suc m) zero o = refl ⊔-assoc (suc m) (suc n) zero = refl ⊔-assoc (suc m) (suc n) (suc o) = cong suc $ ⊔-assoc m n o ⊔-identity : Identity 0 _⊔_ ⊔-identity = (λ _ → refl) , n⊔0≡n where n⊔0≡n : RightIdentity 0 _⊔_ n⊔0≡n zero = refl n⊔0≡n (suc n) = refl ⊔-comm : Commutative _⊔_ ⊔-comm zero n = sym $ proj₂ ⊔-identity n ⊔-comm (suc m) zero = refl ⊔-comm (suc m) (suc n) = begin suc m ⊔ suc n ≡⟨ refl ⟩ suc (m ⊔ n) ≡⟨ cong suc (⊔-comm m n) ⟩ suc (n ⊔ m) ≡⟨ refl ⟩ suc n ⊔ suc m ∎ ⊓-assoc : Associative _⊓_ ⊓-assoc zero _ _ = refl ⊓-assoc (suc m) zero o = refl ⊓-assoc (suc m) (suc n) zero = refl ⊓-assoc (suc m) (suc n) (suc o) = cong suc $ ⊓-assoc m n o ⊓-zero : Zero 0 _⊓_ ⊓-zero = (λ _ → refl) , n⊓0≡0 where n⊓0≡0 : RightZero 0 _⊓_ n⊓0≡0 zero = refl n⊓0≡0 (suc n) = refl ⊓-comm : Commutative _⊓_ ⊓-comm zero n = sym $ proj₂ ⊓-zero n ⊓-comm (suc m) zero = refl ⊓-comm (suc m) (suc n) = begin suc m ⊓ suc n ≡⟨ refl ⟩ suc (m ⊓ n) ≡⟨ cong suc (⊓-comm m n) ⟩ suc (n ⊓ m) ≡⟨ refl ⟩ suc n ⊓ suc m ∎ distrib-⊓-⊔ : _⊓_ DistributesOver _⊔_ distrib-⊓-⊔ = (distribˡ-⊓-⊔ , distribʳ-⊓-⊔) where distribʳ-⊓-⊔ : _⊓_ DistributesOverʳ _⊔_ distribʳ-⊓-⊔ (suc m) (suc n) (suc o) = cong suc $ distribʳ-⊓-⊔ m n o distribʳ-⊓-⊔ (suc m) (suc n) zero = cong suc $ refl distribʳ-⊓-⊔ (suc m) zero o = refl distribʳ-⊓-⊔ zero n o = begin (n ⊔ o) ⊓ 0 ≡⟨ ⊓-comm (n ⊔ o) 0 ⟩ 0 ⊓ (n ⊔ o) ≡⟨ refl ⟩ 0 ⊓ n ⊔ 0 ⊓ o ≡⟨ ⊓-comm 0 n ⟨ cong₂ _⊔_ ⟩ ⊓-comm 0 o ⟩ n ⊓ 0 ⊔ o ⊓ 0 ∎ distribˡ-⊓-⊔ : _⊓_ DistributesOverˡ _⊔_ distribˡ-⊓-⊔ m n o = begin m ⊓ (n ⊔ o) ≡⟨ ⊓-comm m _ ⟩ (n ⊔ o) ⊓ m ≡⟨ distribʳ-⊓-⊔ m n o ⟩ n ⊓ m ⊔ o ⊓ m ≡⟨ ⊓-comm n m ⟨ cong₂ _⊔_ ⟩ ⊓-comm o m ⟩ m ⊓ n ⊔ m ⊓ o ∎ ⊔-⊓-0-isCommutativeSemiringWithoutOne : IsCommutativeSemiringWithoutOne _≡_ _⊔_ _⊓_ 0 ⊔-⊓-0-isCommutativeSemiringWithoutOne = record { isSemiringWithoutOne = record { +-isCommutativeMonoid = record { isSemigroup = record { isEquivalence = PropEq.isEquivalence ; assoc = ⊔-assoc ; ∙-cong = cong₂ _⊔_ } ; identityˡ = proj₁ ⊔-identity ; comm = ⊔-comm } ; *-isSemigroup = record { isEquivalence = PropEq.isEquivalence ; assoc = ⊓-assoc ; ∙-cong = cong₂ _⊓_ } ; distrib = distrib-⊓-⊔ ; zero = ⊓-zero } ; *-comm = ⊓-comm } ⊔-⊓-0-commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne _ _ ⊔-⊓-0-commutativeSemiringWithoutOne = record { _+_ = _⊔_ ; _*_ = _⊓_ ; 0# = 0 ; isCommutativeSemiringWithoutOne = ⊔-⊓-0-isCommutativeSemiringWithoutOne } ------------------------------------------------------------------------ -- (ℕ, ⊓, ⊔) is a lattice private absorptive-⊓-⊔ : Absorptive _⊓_ _⊔_ absorptive-⊓-⊔ = abs-⊓-⊔ , abs-⊔-⊓ where abs-⊔-⊓ : _⊔_ Absorbs _⊓_ abs-⊔-⊓ zero n = refl abs-⊔-⊓ (suc m) zero = refl abs-⊔-⊓ (suc m) (suc n) = cong suc $ abs-⊔-⊓ m n abs-⊓-⊔ : _⊓_ Absorbs _⊔_ abs-⊓-⊔ zero n = refl abs-⊓-⊔ (suc m) (suc n) = cong suc $ abs-⊓-⊔ m n abs-⊓-⊔ (suc m) zero = cong suc $ begin m ⊓ m ≡⟨ cong (_⊓_ m) $ sym $ proj₂ ⊔-identity m ⟩ m ⊓ (m ⊔ 0) ≡⟨ abs-⊓-⊔ m zero ⟩ m ∎ isDistributiveLattice : IsDistributiveLattice _≡_ _⊓_ _⊔_ isDistributiveLattice = record { isLattice = record { isEquivalence = PropEq.isEquivalence ; ∨-comm = ⊓-comm ; ∨-assoc = ⊓-assoc ; ∨-cong = cong₂ _⊓_ ; ∧-comm = ⊔-comm ; ∧-assoc = ⊔-assoc ; ∧-cong = cong₂ _⊔_ ; absorptive = absorptive-⊓-⊔ } ; ∨-∧-distribʳ = proj₂ distrib-⊓-⊔ } distributiveLattice : DistributiveLattice _ _ distributiveLattice = record { _∨_ = _⊓_ ; _∧_ = _⊔_ ; isDistributiveLattice = isDistributiveLattice } ------------------------------------------------------------------------ -- Converting between ≤ and ≤′ ≤-step : ∀ {m n} → m ≤ n → m ≤ 1 + n ≤-step z≤n = z≤n ≤-step (s≤s m≤n) = s≤s (≤-step m≤n) ≤′⇒≤ : _≤′_ ⇒ _≤_ ≤′⇒≤ ≤′-refl = ≤-refl ≤′⇒≤ (≤′-step m≤′n) = ≤-step (≤′⇒≤ m≤′n) z≤′n : ∀ {n} → zero ≤′ n z≤′n {zero} = ≤′-refl z≤′n {suc n} = ≤′-step z≤′n s≤′s : ∀ {m n} → m ≤′ n → suc m ≤′ suc n s≤′s ≤′-refl = ≤′-refl s≤′s (≤′-step m≤′n) = ≤′-step (s≤′s m≤′n) ≤⇒≤′ : _≤_ ⇒ _≤′_ ≤⇒≤′ z≤n = z≤′n ≤⇒≤′ (s≤s m≤n) = s≤′s (≤⇒≤′ m≤n) ------------------------------------------------------------------------ -- Various order-related properties ≤-steps : ∀ {m n} k → m ≤ n → m ≤ k + n ≤-steps zero m≤n = m≤n ≤-steps (suc k) m≤n = ≤-step (≤-steps k m≤n) m≤m+n : ∀ m n → m ≤ m + n m≤m+n zero n = z≤n m≤m+n (suc m) n = s≤s (m≤m+n m n) m≤′m+n : ∀ m n → m ≤′ m + n m≤′m+n m n = ≤⇒≤′ (m≤m+n m n) n≤′m+n : ∀ m n → n ≤′ m + n n≤′m+n zero n = ≤′-refl n≤′m+n (suc m) n = ≤′-step (n≤′m+n m n) n≤m+n : ∀ m n → n ≤ m + n n≤m+n m n = ≤′⇒≤ (n≤′m+n m n) n≤1+n : ∀ n → n ≤ 1 + n n≤1+n _ = ≤-step ≤-refl 1+n≰n : ∀ {n} → ¬ 1 + n ≤ n 1+n≰n (s≤s le) = 1+n≰n le ≤pred⇒≤ : ∀ m n → m ≤ pred n → m ≤ n ≤pred⇒≤ m zero le = le ≤pred⇒≤ m (suc n) le = ≤-step le ≤⇒pred≤ : ∀ m n → m ≤ n → pred m ≤ n ≤⇒pred≤ zero n le = le ≤⇒pred≤ (suc m) n le = start m ≤⟨ n≤1+n m ⟩ suc m ≤⟨ le ⟩ n □ ¬i+1+j≤i : ∀ i {j} → ¬ i + suc j ≤ i ¬i+1+j≤i zero () ¬i+1+j≤i (suc i) le = ¬i+1+j≤i i (≤-pred le) n∸m≤n : ∀ m n → n ∸ m ≤ n n∸m≤n zero n = ≤-refl n∸m≤n (suc m) zero = ≤-refl n∸m≤n (suc m) (suc n) = start n ∸ m ≤⟨ n∸m≤n m n ⟩ n ≤⟨ n≤1+n n ⟩ suc n □ n≤m+n∸m : ∀ m n → n ≤ m + (n ∸ m) n≤m+n∸m m zero = z≤n n≤m+n∸m zero (suc n) = ≤-refl n≤m+n∸m (suc m) (suc n) = s≤s (n≤m+n∸m m n) m⊓n≤m : ∀ m n → m ⊓ n ≤ m m⊓n≤m zero _ = z≤n m⊓n≤m (suc m) zero = z≤n m⊓n≤m (suc m) (suc n) = s≤s $ m⊓n≤m m n m≤m⊔n : ∀ m n → m ≤ m ⊔ n m≤m⊔n zero _ = z≤n m≤m⊔n (suc m) zero = ≤-refl m≤m⊔n (suc m) (suc n) = s≤s $ m≤m⊔n m n ⌈n/2⌉≤′n : ∀ n → ⌈ n /2⌉ ≤′ n ⌈n/2⌉≤′n zero = ≤′-refl ⌈n/2⌉≤′n (suc zero) = ≤′-refl ⌈n/2⌉≤′n (suc (suc n)) = s≤′s (≤′-step (⌈n/2⌉≤′n n)) ⌊n/2⌋≤′n : ∀ n → ⌊ n /2⌋ ≤′ n ⌊n/2⌋≤′n zero = ≤′-refl ⌊n/2⌋≤′n (suc n) = ≤′-step (⌈n/2⌉≤′n n) <-trans : Transitive _<_ <-trans {i} {j} {k} i<j j<k = start 1 + i ≤⟨ i<j ⟩ j ≤⟨ n≤1+n j ⟩ 1 + j ≤⟨ j<k ⟩ k □ ≰⇒> : _≰_ ⇒ _>_ ≰⇒> {zero} z≰n with z≰n z≤n ... | () ≰⇒> {suc m} {zero} _ = s≤s z≤n ≰⇒> {suc m} {suc n} m≰n = s≤s (≰⇒> (m≰n ∘ s≤s)) ------------------------------------------------------------------------ -- (ℕ, _≡_, _<_) is a strict total order m≢1+m+n : ∀ m {n} → m ≢ suc (m + n) m≢1+m+n zero () m≢1+m+n (suc m) eq = m≢1+m+n m (cong pred eq) strictTotalOrder : StrictTotalOrder _ _ _ strictTotalOrder = record { Carrier = ℕ ; _≈_ = _≡_ ; _<_ = _<_ ; isStrictTotalOrder = record { isEquivalence = PropEq.isEquivalence ; trans = <-trans ; compare = cmp ; <-resp-≈ = PropEq.resp₂ _<_ } } where 2+m+n≰m : ∀ {m n} → ¬ 2 + (m + n) ≤ m 2+m+n≰m (s≤s le) = 2+m+n≰m le cmp : Trichotomous _≡_ _<_ cmp m n with compare m n cmp .m .(suc (m + k)) | less m k = tri< (m≤m+n (suc m) k) (m≢1+m+n _) 2+m+n≰m cmp .n .n | equal n = tri≈ 1+n≰n refl 1+n≰n cmp .(suc (n + k)) .n | greater n k = tri> 2+m+n≰m (m≢1+m+n _ ∘ sym) (m≤m+n (suc n) k) ------------------------------------------------------------------------ -- Miscellaneous other properties 0∸n≡0 : LeftZero zero _∸_ 0∸n≡0 zero = refl 0∸n≡0 (suc _) = refl n∸n≡0 : ∀ n → n ∸ n ≡ 0 n∸n≡0 zero = refl n∸n≡0 (suc n) = n∸n≡0 n ∸-+-assoc : ∀ m n o → (m ∸ n) ∸ o ≡ m ∸ (n + o) ∸-+-assoc m n zero = cong (_∸_ m) (sym $ +-right-identity n) ∸-+-assoc zero zero (suc o) = refl ∸-+-assoc zero (suc n) (suc o) = refl ∸-+-assoc (suc m) zero (suc o) = refl ∸-+-assoc (suc m) (suc n) (suc o) = ∸-+-assoc m n (suc o) +-∸-assoc : ∀ m {n o} → o ≤ n → (m + n) ∸ o ≡ m + (n ∸ o) +-∸-assoc m (z≤n {n = n}) = begin m + n ∎ +-∸-assoc m (s≤s {m = o} {n = n} o≤n) = begin (m + suc n) ∸ suc o ≡⟨ cong (λ n → n ∸ suc o) (+-suc m n) ⟩ suc (m + n) ∸ suc o ≡⟨ refl ⟩ (m + n) ∸ o ≡⟨ +-∸-assoc m o≤n ⟩ m + (n ∸ o) ∎ m+n∸n≡m : ∀ m n → (m + n) ∸ n ≡ m m+n∸n≡m m n = begin (m + n) ∸ n ≡⟨ +-∸-assoc m (≤-refl {x = n}) ⟩ m + (n ∸ n) ≡⟨ cong (_+_ m) (n∸n≡0 n) ⟩ m + 0 ≡⟨ +-right-identity m ⟩ m ∎ m+n∸m≡n : ∀ {m n} → m ≤ n → m + (n ∸ m) ≡ n m+n∸m≡n {m} {n} m≤n = begin m + (n ∸ m) ≡⟨ sym $ +-∸-assoc m m≤n ⟩ (m + n) ∸ m ≡⟨ cong (λ n → n ∸ m) (+-comm m n) ⟩ (n + m) ∸ m ≡⟨ m+n∸n≡m n m ⟩ n ∎ m⊓n+n∸m≡n : ∀ m n → (m ⊓ n) + (n ∸ m) ≡ n m⊓n+n∸m≡n zero n = refl m⊓n+n∸m≡n (suc m) zero = refl m⊓n+n∸m≡n (suc m) (suc n) = cong suc $ m⊓n+n∸m≡n m n [m∸n]⊓[n∸m]≡0 : ∀ m n → (m ∸ n) ⊓ (n ∸ m) ≡ 0 [m∸n]⊓[n∸m]≡0 zero zero = refl [m∸n]⊓[n∸m]≡0 zero (suc n) = refl [m∸n]⊓[n∸m]≡0 (suc m) zero = refl [m∸n]⊓[n∸m]≡0 (suc m) (suc n) = [m∸n]⊓[n∸m]≡0 m n [i+j]∸[i+k]≡j∸k : ∀ i j k → (i + j) ∸ (i + k) ≡ j ∸ k [i+j]∸[i+k]≡j∸k zero j k = refl [i+j]∸[i+k]≡j∸k (suc i) j k = [i+j]∸[i+k]≡j∸k i j k -- TODO: Can this proof be simplified? An automatic solver which can -- handle ∸ would be nice... i∸k∸j+j∸k≡i+j∸k : ∀ i j k → i ∸ (k ∸ j) + (j ∸ k) ≡ i + j ∸ k i∸k∸j+j∸k≡i+j∸k zero j k = begin 0 ∸ (k ∸ j) + (j ∸ k) ≡⟨ cong (λ x → x + (j ∸ k)) (0∸n≡0 (k ∸ j)) ⟩ 0 + (j ∸ k) ≡⟨ refl ⟩ j ∸ k ∎ i∸k∸j+j∸k≡i+j∸k (suc i) j zero = begin suc i ∸ (0 ∸ j) + j ≡⟨ cong (λ x → suc i ∸ x + j) (0∸n≡0 j) ⟩ suc i ∸ 0 + j ≡⟨ refl ⟩ suc (i + j) ∎ i∸k∸j+j∸k≡i+j∸k (suc i) zero (suc k) = begin i ∸ k + 0 ≡⟨ +-right-identity _ ⟩ i ∸ k ≡⟨ cong (λ x → x ∸ k) (sym (+-right-identity _)) ⟩ i + 0 ∸ k ∎ i∸k∸j+j∸k≡i+j∸k (suc i) (suc j) (suc k) = begin suc i ∸ (k ∸ j) + (j ∸ k) ≡⟨ i∸k∸j+j∸k≡i+j∸k (suc i) j k ⟩ suc i + j ∸ k ≡⟨ cong (λ x → x ∸ k) (sym (+-suc i j)) ⟩ i + suc j ∸ k ∎ i+j≡0⇒i≡0 : ∀ i {j} → i + j ≡ 0 → i ≡ 0 i+j≡0⇒i≡0 zero eq = refl i+j≡0⇒i≡0 (suc i) () i+j≡0⇒j≡0 : ∀ i {j} → i + j ≡ 0 → j ≡ 0 i+j≡0⇒j≡0 i {j} i+j≡0 = i+j≡0⇒i≡0 j $ begin j + i ≡⟨ +-comm j i ⟩ i + j ≡⟨ i+j≡0 ⟩ 0 ∎ i*j≡0⇒i≡0∨j≡0 : ∀ i {j} → i * j ≡ 0 → i ≡ 0 ⊎ j ≡ 0 i*j≡0⇒i≡0∨j≡0 zero {j} eq = inj₁ refl i*j≡0⇒i≡0∨j≡0 (suc i) {zero} eq = inj₂ refl i*j≡0⇒i≡0∨j≡0 (suc i) {suc j} () i*j≡1⇒i≡1 : ∀ i j → i * j ≡ 1 → i ≡ 1 i*j≡1⇒i≡1 (suc zero) j _ = refl i*j≡1⇒i≡1 zero j () i*j≡1⇒i≡1 (suc (suc i)) (suc (suc j)) () i*j≡1⇒i≡1 (suc (suc i)) (suc zero) () i*j≡1⇒i≡1 (suc (suc i)) zero eq with begin 0 ≡⟨ *-comm 0 i ⟩ i * 0 ≡⟨ eq ⟩ 1 ∎ ... | () i*j≡1⇒j≡1 : ∀ i j → i * j ≡ 1 → j ≡ 1 i*j≡1⇒j≡1 i j eq = i*j≡1⇒i≡1 j i (begin j * i ≡⟨ *-comm j i ⟩ i * j ≡⟨ eq ⟩ 1 ∎) cancel-+-left : ∀ i {j k} → i + j ≡ i + k → j ≡ k cancel-+-left zero eq = eq cancel-+-left (suc i) eq = cancel-+-left i (cong pred eq) cancel-+-left-≤ : ∀ i {j k} → i + j ≤ i + k → j ≤ k cancel-+-left-≤ zero le = le cancel-+-left-≤ (suc i) (s≤s le) = cancel-+-left-≤ i le cancel-*-right : ∀ i j {k} → i * suc k ≡ j * suc k → i ≡ j cancel-*-right zero zero eq = refl cancel-*-right zero (suc j) () cancel-*-right (suc i) zero () cancel-*-right (suc i) (suc j) {k} eq = cong suc (cancel-*-right i j (cancel-+-left (suc k) eq)) cancel-*-right-≤ : ∀ i j k → i * suc k ≤ j * suc k → i ≤ j cancel-*-right-≤ zero _ _ _ = z≤n cancel-*-right-≤ (suc i) zero _ () cancel-*-right-≤ (suc i) (suc j) k le = s≤s (cancel-*-right-≤ i j k (cancel-+-left-≤ (suc k) le)) *-distrib-∸ʳ : _*_ DistributesOverʳ _∸_ *-distrib-∸ʳ i zero k = begin (0 ∸ k) * i ≡⟨ cong₂ _*_ (0∸n≡0 k) refl ⟩ 0 ≡⟨ sym $ 0∸n≡0 (k * i) ⟩ 0 ∸ k * i ∎ *-distrib-∸ʳ i (suc j) zero = begin i + j * i ∎ *-distrib-∸ʳ i (suc j) (suc k) = begin (j ∸ k) * i ≡⟨ *-distrib-∸ʳ i j k ⟩ j * i ∸ k * i ≡⟨ sym $ [i+j]∸[i+k]≡j∸k i _ _ ⟩ i + j * i ∸ (i + k * i) ∎ im≡jm+n⇒[i∸j]m≡n : ∀ i j m n → i * m ≡ j * m + n → (i ∸ j) * m ≡ n im≡jm+n⇒[i∸j]m≡n i j m n eq = begin (i ∸ j) * m ≡⟨ *-distrib-∸ʳ m i j ⟩ (i * m) ∸ (j * m) ≡⟨ cong₂ _∸_ eq (refl {x = j * m}) ⟩ (j * m + n) ∸ (j * m) ≡⟨ cong₂ _∸_ (+-comm (j * m) n) (refl {x = j * m}) ⟩ (n + j * m) ∸ (j * m) ≡⟨ m+n∸n≡m n (j * m) ⟩ n ∎ i+1+j≢i : ∀ i {j} → i + suc j ≢ i i+1+j≢i i eq = ¬i+1+j≤i i (reflexive eq) where open DecTotalOrder decTotalOrder ⌊n/2⌋-mono : ⌊_/2⌋ Preserves _≤_ ⟶ _≤_ ⌊n/2⌋-mono z≤n = z≤n ⌊n/2⌋-mono (s≤s z≤n) = z≤n ⌊n/2⌋-mono (s≤s (s≤s m≤n)) = s≤s (⌊n/2⌋-mono m≤n) ⌈n/2⌉-mono : ⌈_/2⌉ Preserves _≤_ ⟶ _≤_ ⌈n/2⌉-mono m≤n = ⌊n/2⌋-mono (s≤s m≤n) pred-mono : pred Preserves _≤_ ⟶ _≤_ pred-mono z≤n = z≤n pred-mono (s≤s le) = le _+-mono_ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_ _+-mono_ {zero} {m₂} {n₁} {n₂} z≤n n₁≤n₂ = start n₁ ≤⟨ n₁≤n₂ ⟩ n₂ ≤⟨ n≤m+n m₂ n₂ ⟩ m₂ + n₂ □ s≤s m₁≤m₂ +-mono n₁≤n₂ = s≤s (m₁≤m₂ +-mono n₁≤n₂) _*-mono_ : _*_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_ z≤n *-mono n₁≤n₂ = z≤n s≤s m₁≤m₂ *-mono n₁≤n₂ = n₁≤n₂ +-mono (m₁≤m₂ *-mono n₁≤n₂) ∸-mono : _∸_ Preserves₂ _≤_ ⟶ _≥_ ⟶ _≤_ ∸-mono z≤n (s≤s n₁≥n₂) = z≤n ∸-mono (s≤s m₁≤m₂) (s≤s n₁≥n₂) = ∸-mono m₁≤m₂ n₁≥n₂ ∸-mono {m₁} {m₂} m₁≤m₂ (z≤n {n = n₁}) = start m₁ ∸ n₁ ≤⟨ n∸m≤n n₁ m₁ ⟩ m₁ ≤⟨ m₁≤m₂ ⟩ m₂ □
29.15614
88
0.432998
43a9d06c900b68e9eab0961ad8949c44d851cbab
190
agda
Agda
test/Succeed/IntegerLiteral.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/IntegerLiteral.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/IntegerLiteral.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Nat open import Agda.Builtin.Equality _ : 10_000 * 100_000 ≡ 1_000_000_000 _ = refl _ : 0xDEADBEEF ≡ 3735928559 _ = refl _ : 0b01001000_01001001 ≡ 18505 _ = refl
15.833333
36
0.742105
219b0765e28a519c64c50e4da0c21a0c491f2e4f
5,784
agda
Agda
archive/agda-1/UnifyMguFTerminationHunt.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-1/UnifyMguFTerminationHunt.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-1/UnifyMguFTerminationHunt.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
open import Relation.Binary using (IsDecEquivalence) open import Agda.Builtin.Equality -- module UnifyMguFTerminationHunt (FunctionName : Set) ⦃ isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) ⦄ where module UnifyMguFTerminationHunt where postulate FunctionName : Set instance isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) open IsDecEquivalence isDecEquivalenceA using () renaming (_≟_ to _≟F_) open import UnifyTermF FunctionName open import Data.Product using (∃; _,_) open import Data.Maybe using (Maybe; just; nothing) open import Category.Monad using (RawMonad) import Level open RawMonad (Data.Maybe.monad {Level.zero}) open import Relation.Nullary using (Dec; yes; no) open import Data.Fin using (Fin) open import Data.Nat using (suc) postulate _◃′_ : ∀ {m n} -> (f : m ~> n) -> Term m -> Term n _for'_ : ∀ {n} (t' : Term n) (x : Fin (suc n)) -> Fin (suc n) -> Term n amterm : ∀ {m} (s t : Term m) (acc : ∃ (AList m)) -> Maybe (∃ (AList m)) amterm leaf leaf acc = just acc amterm leaf (function _ _) acc = nothing amterm leaf (s' fork t') acc = nothing amterm (s' fork t') leaf acc = nothing amterm (s' fork t') (function _ _) acc = nothing amterm (s1 fork s2) (t1 fork t2) acc = amterm s2 t2 =<< amterm s1 t1 acc {- Data.Maybe.maybe (⋆amgu.amgu ⋆amguTerm' s2 t2) nothing (⋆amgu.amgu ⋆amguTerm' s1 t1 acc) -} amterm (function fn₁ ts₁) leaf acc = nothing amterm (function fn₁ {n₁} ts₁) (function fn₂ {n₂} ts₂) acc = nothing amterm (function fn₁ ts₁) (_ fork _) acc = nothing amterm (i x) (i y) (m , anil) = nothing amterm (i x) t (m , anil) = nothing amterm t (i x) (m , anil) = nothing amterm s t (n , σ asnoc r / z) = (λ σ -> σ ∃asnoc r / z) <$> -- amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ) amterm ((r for' z) ◃′ s) ((r for' z) ◃′ t) (n , σ) -- instance ⋆amguTerm' : ⋆amgu Term -- ⋆amguTerm' .⋆amgu.amgu leaf leaf acc = just acc -- ⋆amguTerm' .⋆amgu.amgu leaf (function _ _) acc = nothing -- ⋆amguTerm' .⋆amgu.amgu leaf (s' fork t') acc = nothing -- ⋆amguTerm' .⋆amgu.amgu (s' fork t') leaf acc = nothing -- ⋆amguTerm' .⋆amgu.amgu (s' fork t') (function _ _) acc = nothing -- ⋆amguTerm' .⋆amgu.amgu (s1 fork s2) (t1 fork t2) acc = amgu s2 t2 =<< amgu s1 t1 acc {- Data.Maybe.maybe (⋆amgu.amgu ⋆amguTerm' s2 t2) nothing (⋆amgu.amgu ⋆amguTerm' s1 t1 acc) -} -- ⋆amguTerm' .⋆amgu.amgu (function fn₁ ts₁) leaf acc = nothing -- ⋆amguTerm' .⋆amgu.amgu (function fn₁ {n₁} ts₁) (function fn₂ {n₂} ts₂) acc = nothing -- ⋆amguTerm' .⋆amgu.amgu (function fn₁ ts₁) (_ fork _) acc = nothing -- ⋆amguTerm' .⋆amgu.amgu (i x) (i y) (m , anil) = nothing -- ⋆amguTerm' .⋆amgu.amgu (i x) t (m , anil) = nothing -- ⋆amguTerm' .⋆amgu.amgu t (i x) (m , anil) = nothing -- ⋆amguTerm' .⋆amgu.amgu s t (n , σ asnoc r / z) = -- (λ σ -> σ ∃asnoc r / z) <$> -- -- amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ) -- amgu ((r for z) ◃′ s) ((r for z) ◃′ t) (n , σ) -- -- instance ⋆amguTerm' : ⋆amgu Term -- -- ⋆amgu.amgu ⋆amguTerm' leaf leaf acc = just acc -- -- ⋆amgu.amgu ⋆amguTerm' leaf (function _ _) acc = nothing -- -- ⋆amgu.amgu ⋆amguTerm' leaf (s' fork t') acc = nothing -- -- ⋆amgu.amgu ⋆amguTerm' (s' fork t') leaf acc = nothing -- -- ⋆amgu.amgu ⋆amguTerm' (s' fork t') (function _ _) acc = nothing -- -- ⋆amgu.amgu ⋆amguTerm' (s1 fork s2) (t1 fork t2) acc = {!amgu s2 t2 =<< amgu s1 t1 acc!} {- Data.Maybe.maybe (⋆amgu.amgu ⋆amguTerm' s2 t2) nothing (⋆amgu.amgu ⋆amguTerm' s1 t1 acc) -} -- -- ⋆amgu.amgu ⋆amguTerm' (function fn₁ ts₁) leaf acc = nothing -- -- ⋆amgu.amgu ⋆amguTerm' (function fn₁ {n₁} ts₁) (function fn₂ {n₂} ts₂) acc = nothing -- -- ⋆amgu.amgu ⋆amguTerm' (function fn₁ ts₁) (_ fork _) acc = nothing -- -- ⋆amgu.amgu ⋆amguTerm' (i x) (i y) (m , anil) = nothing -- -- ⋆amgu.amgu ⋆amguTerm' (i x) t (m , anil) = nothing -- -- ⋆amgu.amgu ⋆amguTerm' t (i x) (m , anil) = nothing -- -- ⋆amgu.amgu ⋆amguTerm' s t (n , σ asnoc r / z) = -- -- (λ σ -> σ ∃asnoc r / z) <$> -- -- -- amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ) -- -- amgu ((r for z) ◃′ s) ((r for z) ◃′ t) (n , σ) -- -- -- mutual -- -- -- instance ⋆amguTerm : ⋆amgu Term -- -- -- ⋆amgu.amgu ⋆amguTerm leaf leaf acc = just acc -- -- -- ⋆amgu.amgu ⋆amguTerm leaf (function _ _) acc = nothing -- -- -- ⋆amgu.amgu ⋆amguTerm leaf (s' fork t') acc = nothing -- -- -- ⋆amgu.amgu ⋆amguTerm (s' fork t') leaf acc = nothing -- -- -- ⋆amgu.amgu ⋆amguTerm (s' fork t') (function _ _) acc = nothing -- -- -- ⋆amgu.amgu ⋆amguTerm (s1 fork s2) (t1 fork t2) acc = -- -- -- amgu s2 t2 =<< amgu s1 t1 acc -- -- -- ⋆amgu.amgu ⋆amguTerm (function fn₁ ts₁) leaf acc = nothing -- -- -- ⋆amgu.amgu ⋆amguTerm (function fn₁ {n₁} ts₁) (function fn₂ {n₂} ts₂) acc -- -- -- with fn₁ ≟F fn₂ -- -- -- … | no _ = nothing -- -- -- … | yes _ with n₁ ≟ n₂ -- -- -- … | no _ = nothing -- -- -- … | yes refl = amgu ts₁ ts₂ acc -- -- -- ⋆amgu.amgu ⋆amguTerm (function fn₁ ts₁) (_ fork _) acc = nothing -- -- -- ⋆amgu.amgu ⋆amguTerm (i x) (i y) (m , anil) = just (flexFlex x y) -- -- -- ⋆amgu.amgu ⋆amguTerm (i x) t (m , anil) = flexRigid x t -- -- -- ⋆amgu.amgu ⋆amguTerm t (i x) (m , anil) = flexRigid x t -- -- -- ⋆amgu.amgu ⋆amguTerm s t (n , σ asnoc r / z) = -- -- -- (λ σ -> σ ∃asnoc r / z) <$> -- -- -- amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ) -- -- -- instance ⋆amguVecTerm : ∀ {N} → ⋆amgu (flip Vec N ∘ Term) -- -- -- ⋆amgu.amgu ⋆amguVecTerm [] [] acc = just acc -- -- -- ⋆amgu.amgu ⋆amguVecTerm (t₁ ∷ t₁s) (t₂ ∷ t₂s) acc = amgu t₁s t₂s =<< amgu t₁ t₂ acc -- -- -- mgu : ∀ {m} -> (s t : Term m) -> Maybe (∃ (AList m)) -- -- -- mgu {m} s t = amgu s t (m , anil)
49.435897
188
0.568811
218583dd349588f691098b71949f699565c82688
639
agda
Agda
agda/InsertSort/Impl2.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/InsertSort/Impl2.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/InsertSort/Impl2.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
open import Relation.Binary.Core module InsertSort.Impl2 {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import Bound.Lower A open import Bound.Lower.Order _≤_ open import Data.List open import Data.Sum open import OList _≤_ insert : {b : Bound}{x : A} → LeB b (val x) → OList b → OList b insert {b} {x} b≤x onil = :< b≤x onil insert {b} {x} b≤x (:< {x = y} b≤y ys) with tot≤ x y ... | inj₁ x≤y = :< b≤x (:< (lexy x≤y) ys) ... | inj₂ y≤x = :< b≤y (insert (lexy y≤x) ys) insertSort : List A → OList bot insertSort [] = onil insertSort (x ∷ xs) = insert {bot} {x} lebx (insertSort xs)
27.782609
63
0.5759
648bb5e8034990539b4dcce59d04af6cd32a1967
816
agda
Agda
src/Categories/Category/Construction/Presheaves.agda
MirceaS/agda-categories
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
[ "MIT" ]
null
null
null
src/Categories/Category/Construction/Presheaves.agda
MirceaS/agda-categories
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
[ "MIT" ]
null
null
null
src/Categories/Category/Construction/Presheaves.agda
MirceaS/agda-categories
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Categories.Category.Construction.Presheaves where -- The Category of Presheaves over a Category C, i.e. -- the Functor Category [ C.op , Setoids ] -- Again, the levels are made explicit to show the generality and constraints. open import Level open import Categories.Category open import Categories.Category.Construction.Functors open import Categories.Category.Instance.Setoids using (Setoids) Presheaves′ : ∀ o′ ℓ′ {o ℓ e : Level} → Category o ℓ e → Category (o ⊔ ℓ ⊔ e ⊔ suc (o′ ⊔ ℓ′)) (o ⊔ ℓ ⊔ o′ ⊔ ℓ′) (o ⊔ o′ ⊔ ℓ′) Presheaves′ o′ ℓ′ C = Functors (Category.op C) (Setoids o′ ℓ′) Presheaves : ∀ {o ℓ e o′ ℓ′ : Level} → Category o ℓ e → Category (o ⊔ ℓ ⊔ e ⊔ suc (o′ ⊔ ℓ′)) (o ⊔ ℓ ⊔ o′ ⊔ ℓ′) (o ⊔ o′ ⊔ ℓ′) Presheaves {o} {ℓ} {e} {o′} {ℓ′} C = Presheaves′ o′ ℓ′ C
40.8
78
0.640931
7c411a69241eb336b9b50d680142e1a899bccff9
364
agda
Agda
zerepoch-metatheory/test/Negation.agda
Quantum-One-DLT/zerepoch
c8cf4619e6e496930c9092cf6d64493eff300177
[ "Apache-2.0" ]
null
null
null
zerepoch-metatheory/test/Negation.agda
Quantum-One-DLT/zerepoch
c8cf4619e6e496930c9092cf6d64493eff300177
[ "Apache-2.0" ]
null
null
null
zerepoch-metatheory/test/Negation.agda
Quantum-One-DLT/zerepoch
c8cf4619e6e496930c9092cf6d64493eff300177
[ "Apache-2.0" ]
2
2021-11-13T21:25:19.000Z
2022-02-21T16:38:59.000Z
module test.Negation where open import Type open import Declarative open import Builtin open import Builtin.Constant.Type open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆ -- zerepoch/zerepoch-core/test/data/negation.plc open import Declarative.StdLib.Bool negate : ∀{Γ} → Γ ⊢ boolean ⇒ boolean negate {Γ} = ƛ (if ·⋆ boolean · ` Z · false · true)
24.266667
62
0.736264
0359fb4eb57e66369a829cec9d42f3ee8737a75a
1,021
agda
Agda
src/Categories/Category/Construction/Path.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Construction/Path.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Construction/Path.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Level open import Categories.Category module Categories.Category.Construction.Path {o ℓ e : Level} (C : Category o ℓ e) where open import Function using (flip) open import Relation.Binary hiding (_⇒_) open import Relation.Binary.Construct.Closure.Transitive open Category C -- Defining the Path Category ∘-tc : {A B : Obj} → A [ _⇒_ ]⁺ B → A ⇒ B ∘-tc [ f ] = f ∘-tc (_ ∼⁺⟨ f⁺ ⟩ f⁺′) = ∘-tc f⁺′ ∘ ∘-tc f⁺ infix 4 _≈⁺_ _≈⁺_ : {A B : Obj} → (i j : A [ _⇒_ ]⁺ B) → Set e f⁺ ≈⁺ g⁺ = ∘-tc f⁺ ≈ ∘-tc g⁺ Path : Category o (o ⊔ ℓ) e Path = record { Obj = Obj ; _⇒_ = λ A B → A [ _⇒_ ]⁺ B ; _≈_ = _≈⁺_ ; id = [ id ] ; _∘_ = flip (_ ∼⁺⟨_⟩_) ; assoc = assoc ; sym-assoc = sym-assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; identity² = identity² ; equiv = record { refl = Equiv.refl ; sym = Equiv.sym ; trans = Equiv.trans } ; ∘-resp-≈ = ∘-resp-≈ } where open HomReasoning
23.744186
87
0.538688
1108f9b0157647533cd2e652560ac394679564fd
131
agda
Agda
src/data/lib/prim/Agda/Builtin/TrustMe.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
src/data/lib/prim/Agda/Builtin/TrustMe.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
src/data/lib/prim/Agda/Builtin/TrustMe.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
module Agda.Builtin.TrustMe where open import Agda.Builtin.Equality primitive primTrustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y
18.714286
59
0.679389
190a8b08c18057bc19ad165caaa8271841808363
908
agda
Agda
Cubical/HITs/2GroupoidTruncation/Properties.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/HITs/2GroupoidTruncation/Properties.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/HITs/2GroupoidTruncation/Properties.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{- This file contains: - Properties of 2-groupoid truncations -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.2GroupoidTruncation.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.HITs.2GroupoidTruncation.Base rec : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (gB : is2Groupoid B) → (A → B) → (∥ A ∥₂ → B) rec gB f ∣ x ∣₂ = f x rec gB f (squash₂ _ _ _ _ _ _ t u i j k l) = gB _ _ _ _ _ _ (λ m n o → rec gB f (t m n o)) (λ m n o → rec gB f (u m n o)) i j k l elim : ∀ {ℓ ℓ'} {A : Type ℓ} {B : ∥ A ∥₂ → Type ℓ'} (bG : (x : ∥ A ∥₂) → is2Groupoid (B x)) (f : (x : A) → B ∣ x ∣₂) (x : ∥ A ∥₂) → B x elim bG f ∣ x ∣₂ = f x elim bG f (squash₂ x y p q r s u v i j k l) = isOfHLevel→isOfHLevelDep 4 bG _ _ _ _ _ _ (λ j k l → elim bG f (u j k l)) (λ j k l → elim bG f (v j k l)) (squash₂ x y p q r s u v) i j k l
28.375
87
0.560573
64c81dd9df6be0d24388116c0c71446b592302c9
146
agda
Agda
test/Compiler/simple/Issue561.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
4
2017-02-24T16:53:22.000Z
2019-12-23T04:56:23.000Z
test/Compiler/simple/Issue561.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
6
2017-02-24T19:27:31.000Z
2017-02-24T19:38:17.000Z
test/Compiler/simple/Issue561.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
module Issue561 where open import Common.Prelude hiding (primIsDigit) primitive primIsDigit : Char → Bool main : IO Bool main = return true
13.272727
47
0.760274
11004e4eb090bfc3b13a6977c9bdc7336cb956c3
1,281
agda
Agda
src/Fragment/Equational/Coproduct.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
18
2021-06-15T15:45:39.000Z
2022-01-17T17:26:09.000Z
src/Fragment/Equational/Coproduct.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
1
2021-06-16T09:44:31.000Z
2021-06-16T10:24:15.000Z
src/Fragment/Equational/Coproduct.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
3
2021-06-15T15:34:50.000Z
2021-06-16T08:04:31.000Z
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Equational.Theory module Fragment.Equational.Coproduct (Θ : Theory) where open import Fragment.Equational.Model Θ open import Fragment.Algebra.Homomorphism (Σ Θ) open import Level using (Level; Setω) private variable a b c ℓ₁ ℓ₂ ℓ₃ : Level module _ (A : Model {a} {ℓ₁}) (B : Model {b} {ℓ₂}) (A+B : Model {c} {ℓ₃}) where record IsCoproduct : Setω where field inl : ∥ A ∥ₐ ⟿ ∥ A+B ∥ₐ inr : ∥ B ∥ₐ ⟿ ∥ A+B ∥ₐ _[_,_] : ∀ {d ℓ₄} (X : Model {d} {ℓ₄}) → ∥ A ∥ₐ ⟿ ∥ X ∥ₐ → ∥ B ∥ₐ ⟿ ∥ X ∥ₐ → ∥ A+B ∥ₐ ⟿ ∥ X ∥ₐ commute₁ : ∀ {d ℓ₄} {X : Model {d} {ℓ₄}} → {f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ} → {g : ∥ B ∥ₐ ⟿ ∥ X ∥ₐ} → X [ f , g ] ⊙ inl ≗ f commute₂ : ∀ {d ℓ₄} {X : Model {d} {ℓ₄}} → {f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ} → {g : ∥ B ∥ₐ ⟿ ∥ X ∥ₐ} → X [ f , g ] ⊙ inr ≗ g universal : ∀ {d ℓ₄} {X : Model {d} {ℓ₄}} → {f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ} → {g : ∥ B ∥ₐ ⟿ ∥ X ∥ₐ} → {h : ∥ A+B ∥ₐ ⟿ ∥ X ∥ₐ} → h ⊙ inl ≗ f → h ⊙ inr ≗ g → X [ f , g ] ≗ h
26.142857
55
0.373927
64b2ebbfbf64a6ed99a08b8567e79aad15f42030
1,404
agda
Agda
test/succeed/Issue408.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/Issue408.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/Issue408.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Issue408 where open import Common.Prelude open import Common.Equality -- 1. Agda should prefer to split on an argument that covers data Fin : Nat → Set where zero : {n : Nat} → Fin (suc n) suc : {n : Nat} → Fin n → Fin (suc n) wk : {n : Nat} → Fin n → Fin (suc n) wk zero = zero wk (suc n) = suc (wk n) predFin : (n : Nat) → Fin n → Fin n predFin (suc n) zero = zero predFin (suc n) (suc i) = wk i -- predFin should be covering data Vec (A : Set) : Nat → Set where [] : Vec A zero _∷_ : {n : Nat} (x : A) (xs : Vec A n) → Vec A (suc n) _!!_ : {A : Set}{n : Nat} → Vec A n → Fin n → A (x ∷ xs) !! zero = x (x ∷ xs) !! (suc i) = xs !! i -- should be covering, no need for absurd clause test!!1 : ∀ {A}{n} (x : A) (xs : Vec A n) → (x ∷ xs) !! zero ≡ x test!!1 x xs = refl test!!2 : ∀ {A}{n} (x : A) (xs : Vec A n) i → (x ∷ xs) !! (suc i) ≡ xs !! i test!!2 x xs i = refl -- 2. Agda should prefer to split on an argument that has only -- constructor patterns. For max below, split on 2nd, then on 1st. max : Nat → Nat → Nat max (suc n) (suc m) = suc (max n m) max 0 (suc m) = suc m max n 0 = n testmax1 : {n m : Nat} → max (suc n) (suc m) ≡ suc (max n m) testmax1 = refl testmax2 : {m : Nat} → max 0 (suc m) ≡ suc m testmax2 = refl {- DOES NOT WORK YET testmax3 : {n : Nat} → max n 0 ≡ n testmax3 = refl -- equation should hold definitionally -}
25.071429
75
0.559829
302360e23a57db2cd2ad1bd2ca6c74fc31a2073d
2,458
agda
Agda
archive/agda-3/src/Oscar/Class/Surjextensionality.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-3/src/Oscar/Class/Surjextensionality.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/Surjextensionality.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
open import Oscar.Prelude open import Oscar.Class open import Oscar.Class.Surjection open import Oscar.Class.Smap open import Oscar.Data.Constraint module Oscar.Class.Surjextensionality where module Surjextensionality {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁) (_∼̇₁_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁) (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂) (_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂) (surjection : Surjection.type 𝔒₁ 𝔒₂) (smap : Smap.type _∼₁_ _∼₂_ surjection surjection) where open ℭLASS (_∼₁_ ,, {- FIXME including `(λ {x y} → _∼̇₁_ {x} {y}) ,, ` leads to instance search depth exhausted in Oscar.Data.Surjextenscollation -} _∼₂_ ,, (λ {x y} → _∼̇₂_ {x} {y}) ,, surjection ,, (λ {x y} → smap {x} {y})) (∀ x y (f₁ f₂ : x ∼₁ y) → f₁ ∼̇₁ f₂ → smap f₁ ∼̇₂ smap f₂) public TYPE = ∀ {x y} {f₁ f₂ : x ∼₁ y} → f₁ ∼̇₁ f₂ → smap f₁ ∼̇₂ smap f₂ module Surjextensionality! {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁) (_∼̇₁_ : ∀ {x y} → _∼₁_ x y → _∼₁_ x y → Ø ℓ₁) (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂) (_∼̇₂_ : ∀ {x y} → _∼₂_ x y → _∼₂_ x y → Ø ℓ₂) ⦃ _ : Surjection.class 𝔒₁ 𝔒₂ ⦄ ⦃ _ : Smap.class _∼₁_ _∼₂_ surjection surjection ⦄ = Surjextensionality (_∼₁_) (λ {x y} → _∼̇₁_ {x} {y}) (_∼₂_) (λ {x y} → _∼̇₂_ {x} {y}) surjection (λ {x y} → smap {x = x} {y}) module _ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} {∼₁ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁} {∼̇₁ : ∀ {x y} → ∼₁ x y → ∼₁ x y → Ø ℓ₁} {∼₂ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂} {∼̇₂ : ∀ {x y} → ∼₂ x y → ∼₂ x y → Ø ℓ₂} {surjection : Surjection.type 𝔒₁ 𝔒₂} {smap : Smap.type ∼₁ ∼₂ surjection surjection} where open Surjextensionality ∼₁ (λ {x y} → ∼̇₁ {x} {y}) ∼₂ (λ {x y} → ∼̇₂ {x} {y}) surjection (λ {x y} → smap {x = x} {y}) surjextensionality : ⦃ _ : class ⦄ → TYPE surjextensionality = method _ _ _ _ module _ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} {∼₁ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁} {∼̇₁ : ∀ {x y} → ∼₁ x y → ∼₁ x y → Ø ℓ₁} {∼₂ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂} (∼̇₂ : ∀ {x y} → ∼₂ x y → ∼₂ x y → Ø ℓ₂) {surjection : Surjection.type 𝔒₁ 𝔒₂} {smap : Smap.type ∼₁ ∼₂ surjection surjection} where open Surjextensionality ∼₁ (λ {x y} → ∼̇₁ {x} {y}) ∼₂ (λ {x y} → ∼̇₂ {x} {y}) surjection (λ {x y} → smap {x = x} {y}) surjextensionality[_] : ⦃ _ : class ⦄ → TYPE surjextensionality[_] = surjextensionality ⟪⟫-surjextensionality[]-syntax = surjextensionality[_] syntax ⟪⟫-surjextensionality[]-syntax t x = ⟪ x ⟫[ t ]
34.619718
293
0.538242
3602f36bd9956ea82855be8b2193d01319f4f555
195
agda
Agda
Dave/Functions.agda
DavidStahl97/formal-proofs
05213fb6ab1f51f770f9858b61526ba950e06232
[ "MIT" ]
null
null
null
Dave/Functions.agda
DavidStahl97/formal-proofs
05213fb6ab1f51f770f9858b61526ba950e06232
[ "MIT" ]
null
null
null
Dave/Functions.agda
DavidStahl97/formal-proofs
05213fb6ab1f51f770f9858b61526ba950e06232
[ "MIT" ]
null
null
null
module Dave.Functions where _∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C) (g ∘ f) a = g (f a) _∘´_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C) (g ∘´ f) = λ x → g (f x)
27.857143
56
0.333333
a1b3d9a6ad9b2d7139a81cbe9ccffa24979ddb07
1,808
agda
Agda
Type/Category/IntensionalFunctionsCategory/HomFunctor.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Type/Category/IntensionalFunctionsCategory/HomFunctor.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Type/Category/IntensionalFunctionsCategory/HomFunctor.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Type.Category.IntensionalFunctionsCategory.HomFunctor where import Functional as Fn open import Function.Proofs open import Logic.Predicate import Lvl open import Relator.Equals open import Relator.Equals.Proofs import Relator.Equals.Proofs.Equiv open import Structure.Category open import Structure.Category.Dual open import Structure.Category.Functor open import Structure.Function open import Structure.Operator open import Structure.Relator.Properties open import Syntax.Function open import Syntax.Transitivity open import Type.Category.IntensionalFunctionsCategory open import Type private variable ℓ ℓₒ ℓₘ ℓₑ : Lvl.Level module _ {Obj : Type{ℓₒ}} {_⟶_ : Obj → Obj → Type{ℓₘ}} (C : Category(_⟶_)) where open Category(C) covariantHomFunctor : Obj → (intro(C) →ᶠᵘⁿᶜᵗᵒʳ typeIntensionalFnCategoryObject{ℓₘ}) ∃.witness (covariantHomFunctor x) y = (x ⟶ y) Functor.map (∃.proof (covariantHomFunctor _)) = (_∘_) Function.congruence (Functor.map-function (∃.proof (covariantHomFunctor _))) = congruence₁(_∘_) Functor.op-preserving (∃.proof (covariantHomFunctor x)) {f = f} {g = g} = (h ↦ (f ∘ g) ∘ h) 🝖[ _≡_ ]-[ {!!} ] -- TODO: Requires func. ext? (h ↦ f ∘ (g ∘ h)) 🝖[ _≡_ ]-[] (f ∘_) Fn.∘ (g ∘_) 🝖-end Functor.id-preserving (∃.proof (covariantHomFunctor x)) = {!!} {- contravariantHomFunctor : Object → (dual(C) →ᶠᵘⁿᶜᵗᵒʳ typeIntensionalFnCategoryObject{ℓₘ}) ∃.witness (contravariantHomFunctor x) y = (y ⟶ x) Functor.map (∃.proof (contravariantHomFunctor _)) = Fn.swap(_∘_) Function.congruence (Functor.map-function (∃.proof (contravariantHomFunctor x))) x₁ = {!!} _⊜_.proof (Functor.op-preserving (∃.proof (contravariantHomFunctor x))) {x₁} = {!!} _⊜_.proof (Functor.id-preserving (∃.proof (contravariantHomFunctor x))) {x₁} = {!!} -}
37.666667
97
0.710177
fd7f607f7a52df9fc9e51ee6a2c647aa92996428
1,084
agda
Agda
test/asset/agda-stdlib-1.0/Category/Functor.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Category/Functor.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Category/Functor.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Functors ------------------------------------------------------------------------ -- Note that currently the functor laws are not included here. {-# OPTIONS --without-K --safe #-} module Category.Functor where open import Function open import Level open import Relation.Binary.PropositionalEquality record RawFunctor {ℓ} (F : Set ℓ → Set ℓ) : Set (suc ℓ) where infixl 4 _<$>_ _<$_ infixl 1 _<&>_ field _<$>_ : ∀ {A B} → (A → B) → F A → F B _<$_ : ∀ {A B} → A → F B → F A x <$ y = const x <$> y _<&>_ : ∀ {A B} → F A → (A → B) → F B _<&>_ = flip _<$>_ -- A functor morphism from F₁ to F₂ is an operation op such that -- op (F₁ f x) ≡ F₂ f (op x) record Morphism {ℓ} {F₁ F₂ : Set ℓ → Set ℓ} (fun₁ : RawFunctor F₁) (fun₂ : RawFunctor F₂) : Set (suc ℓ) where open RawFunctor field op : ∀{X} → F₁ X → F₂ X op-<$> : ∀{X Y} (f : X → Y) (x : F₁ X) → op (fun₁ ._<$>_ f x) ≡ fun₂ ._<$>_ f (op x)
25.809524
72
0.4631
3505a824fb14410dda6f0f1030c92a0db3811d53
24,301
agda
Agda
Agda/24-sequences.agda
tmoux/HoTT-Intro
22023fd35023cb6804424ce12cd10d252b80fd29
[ "CC-BY-4.0" ]
null
null
null
Agda/24-sequences.agda
tmoux/HoTT-Intro
22023fd35023cb6804424ce12cd10d252b80fd29
[ "CC-BY-4.0" ]
null
null
null
Agda/24-sequences.agda
tmoux/HoTT-Intro
22023fd35023cb6804424ce12cd10d252b80fd29
[ "CC-BY-4.0" ]
null
null
null
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-} module 24-sequences where import 23-id-pushout open 23-id-pushout public {- We introduce two types of sequences: one with the arrows going up and one with the arrows going down. -} Sequence : ( l : Level) → UU (lsuc l) Sequence l = Σ (ℕ → UU l) (λ A → (n : ℕ) → A n → A (succ-ℕ n)) type-seq : { l : Level} (A : Sequence l) → (n : ℕ) → UU l type-seq A = pr1 A map-seq : { l : Level} (A : Sequence l) → ( n : ℕ) → (type-seq A n) → (type-seq A (succ-ℕ n)) map-seq A = pr2 A Sequence' : ( l : Level) → UU (lsuc l) Sequence' l = Σ (ℕ → UU l) (λ A → (n : ℕ) → A (succ-ℕ n) → A n) type-seq' : { l : Level} (A : Sequence' l) → (n : ℕ) → UU l type-seq' A = pr1 A map-seq' : { l : Level} (A : Sequence' l) → (n : ℕ) → (type-seq' A (succ-ℕ n)) → (type-seq' A n) map-seq' A = pr2 A {- We characterize the identity type of Sequence l. -} naturality-hom-Seq : { l1 l2 : Level} (A : Sequence l1) (B : Sequence l2) ( h : (n : ℕ) → type-seq A n → type-seq B n) (n : ℕ) → UU (l1 ⊔ l2) naturality-hom-Seq A B h n = ((map-seq B n) ∘ (h n)) ~ ((h (succ-ℕ n)) ∘ (map-seq A n)) equiv-Seq : { l1 l2 : Level} (A : Sequence l1) (B : Sequence l2) → UU (l1 ⊔ l2) equiv-Seq A B = Σ ( (n : ℕ) → (type-seq A n) ≃ (type-seq B n)) ( λ e → (n : ℕ) → naturality-hom-Seq A B (λ n → map-equiv (e n)) n) reflexive-equiv-Seq : { l1 : Level} (A : Sequence l1) → equiv-Seq A A reflexive-equiv-Seq A = pair ( λ n → equiv-id (type-seq A n)) ( λ n → htpy-refl) equiv-eq-Seq : { l1 : Level} (A B : Sequence l1) → Id A B → equiv-Seq A B equiv-eq-Seq A .A refl = reflexive-equiv-Seq A is-contr-total-equiv-Seq : { l1 : Level} (A : Sequence l1) → is-contr (Σ (Sequence l1) (equiv-Seq A)) is-contr-total-equiv-Seq A = is-contr-total-Eq-structure ( λ B g (e : (n : ℕ) → (type-seq A n) ≃ B n) → (n : ℕ) → naturality-hom-Seq A (pair B g) (λ n → map-equiv (e n)) n) ( is-contr-total-Eq-Π ( λ n X → type-seq A n ≃ X) ( λ n → is-contr-total-equiv (type-seq A n)) ( type-seq A)) ( pair (type-seq A) (λ n → equiv-id (type-seq A n))) ( is-contr-total-Eq-Π ( λ n h → h ~ (map-seq A n)) ( λ n → is-contr-total-htpy' (map-seq A n)) ( map-seq A)) is-equiv-equiv-eq-Seq : { l1 : Level} (A B : Sequence l1) → is-equiv (equiv-eq-Seq A B) is-equiv-equiv-eq-Seq A = fundamental-theorem-id A ( reflexive-equiv-Seq A) ( is-contr-total-equiv-Seq A) ( equiv-eq-Seq A) eq-equiv-Seq : { l1 : Level} {A B : Sequence l1} → equiv-Seq A B → Id A B eq-equiv-Seq {A = A} {B} = inv-is-equiv (is-equiv-equiv-eq-Seq A B) {- We characterize the identity type of Sequence' l. -} equiv-Seq' : { l1 l2 : Level} (A : Sequence' l1) (B : Sequence' l2) → UU (l1 ⊔ l2) equiv-Seq' A B = Σ ( (n : ℕ) → (type-seq' A n) ≃ (type-seq' B n)) (λ e → ( n : ℕ) → ( (map-seq' B n) ∘ (map-equiv (e (succ-ℕ n)))) ~ ( (map-equiv (e n)) ∘ (map-seq' A n))) reflexive-equiv-Seq' : { l1 : Level} (A : Sequence' l1) → equiv-Seq' A A reflexive-equiv-Seq' A = pair ( λ n → equiv-id (type-seq' A n)) ( λ n → htpy-refl) equiv-eq-Seq' : { l1 : Level} (A B : Sequence' l1) → Id A B → equiv-Seq' A B equiv-eq-Seq' A .A refl = reflexive-equiv-Seq' A is-contr-total-equiv-Seq' : { l1 : Level} (A : Sequence' l1) → is-contr (Σ (Sequence' l1) (equiv-Seq' A)) is-contr-total-equiv-Seq' A = is-contr-total-Eq-structure ( λ B g (e : (n : ℕ) → (type-seq' A n) ≃ (B n)) → (n : ℕ) → ( (g n) ∘ (map-equiv (e (succ-ℕ n)))) ~ ( (map-equiv (e n)) ∘ (map-seq' A n))) ( is-contr-total-Eq-Π ( λ n B → (type-seq' A n) ≃ B) ( λ n → is-contr-total-equiv (type-seq' A n)) ( type-seq' A)) ( pair (type-seq' A) (λ n → equiv-id (type-seq' A n))) ( is-contr-total-Eq-Π ( λ n g → g ~ (map-seq' A n)) ( λ n → is-contr-total-htpy' (map-seq' A n)) ( map-seq' A)) is-equiv-equiv-eq-Seq' : { l1 : Level} (A B : Sequence' l1) → is-equiv (equiv-eq-Seq' A B) is-equiv-equiv-eq-Seq' A = fundamental-theorem-id A ( reflexive-equiv-Seq' A) ( is-contr-total-equiv-Seq' A) ( equiv-eq-Seq' A) eq-equiv-Seq' : { l1 : Level} (A B : Sequence' l1) → equiv-Seq' A B → Id A B eq-equiv-Seq' A B = inv-is-equiv (is-equiv-equiv-eq-Seq' A B) {- We introduce cones on a type sequence. -} cone-sequence : { l1 l2 : Level} (A : Sequence' l1) (X : UU l2) → UU (l1 ⊔ l2) cone-sequence A X = Σ ( (n : ℕ) → X → type-seq' A n) ( λ p → (n : ℕ) → ((map-seq' A n) ∘ (p (succ-ℕ n))) ~ (p n)) map-cone-sequence : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( n : ℕ) → X → type-seq' A n map-cone-sequence A c = pr1 c triangle-cone-sequence : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( n : ℕ) → ( (map-seq' A n) ∘ (map-cone-sequence A c (succ-ℕ n))) ~ ( map-cone-sequence A c n) triangle-cone-sequence A c = pr2 c {- We characterize the identity type of cone-sequence. -} naturality-htpy-cone-sequence : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c c' : cone-sequence A X) → ( H : (n : ℕ) → (map-cone-sequence A c n) ~ (map-cone-sequence A c' n)) → ( n : ℕ) → UU (l1 ⊔ l2) naturality-htpy-cone-sequence A c c' H n = ( ((map-seq' A n) ·l (H (succ-ℕ n))) ∙h (triangle-cone-sequence A c' n)) ~ ( (triangle-cone-sequence A c n) ∙h (H n)) htpy-cone-sequence : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} → ( c c' : cone-sequence A X) → UU (l1 ⊔ l2) htpy-cone-sequence A c c' = Σ ( (n : ℕ) → (map-cone-sequence A c n) ~ (map-cone-sequence A c' n)) (λ H → (n : ℕ) → naturality-htpy-cone-sequence A c c' H n) reflexive-htpy-cone-sequence : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → htpy-cone-sequence A c c reflexive-htpy-cone-sequence A c = pair ( λ n → htpy-refl) ( λ n → htpy-inv htpy-right-unit) htpy-cone-sequence-eq : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c c' : cone-sequence A X) → Id c c' → htpy-cone-sequence A c c' htpy-cone-sequence-eq A c .c refl = reflexive-htpy-cone-sequence A c is-contr-total-htpy-cone-sequence : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → is-contr (Σ (cone-sequence A X) (htpy-cone-sequence A c)) is-contr-total-htpy-cone-sequence A c = is-contr-total-Eq-structure ( λ p t H → (n : ℕ) → naturality-htpy-cone-sequence A c (pair p t) H n) ( is-contr-total-Eq-Π ( λ n pn → (map-cone-sequence A c n) ~ pn) ( λ n → is-contr-total-htpy (map-cone-sequence A c n)) ( map-cone-sequence A c)) ( pair (map-cone-sequence A c) (λ n → htpy-refl)) ( is-contr-total-Eq-Π ( λ n H → H ~ ((triangle-cone-sequence A c n) ∙h htpy-refl)) ( λ n → is-contr-total-htpy' ((triangle-cone-sequence A c n) ∙h htpy-refl)) ( triangle-cone-sequence A c)) is-equiv-htpy-cone-sequence-eq : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c c' : cone-sequence A X) → is-equiv (htpy-cone-sequence-eq A c c') is-equiv-htpy-cone-sequence-eq A c = fundamental-theorem-id c ( reflexive-htpy-cone-sequence A c) ( is-contr-total-htpy-cone-sequence A c) ( htpy-cone-sequence-eq A c) eq-htpy-cone-sequence : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c c' : cone-sequence A X) → htpy-cone-sequence A c c' → Id c c' eq-htpy-cone-sequence A {X} c c' = inv-is-equiv (is-equiv-htpy-cone-sequence-eq A c c') equiv-htpy-cone-sequence-eq : { l1 l2 : Level} (A : Sequence' l1) {X : UU l2} (c c' : cone-sequence A X) → Id c c' ≃ (htpy-cone-sequence A c c') equiv-htpy-cone-sequence-eq A c c' = pair ( htpy-cone-sequence-eq A c c') ( is-equiv-htpy-cone-sequence-eq A c c') {- We introduce sequential limits. -} cone-sequence-map : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( Y : UU l3) → (Y → X) → cone-sequence A Y cone-sequence-map A c Y h = pair ( λ n → (map-cone-sequence A c n) ∘ h) ( λ n → (triangle-cone-sequence A c n) ·r h) universal-property-sequential-limit : ( l : Level) {l1 l2 : Level} (A : Sequence' l1) {X : UU l2} ( c : cone-sequence A X) → UU (lsuc l ⊔ l1 ⊔ l2) universal-property-sequential-limit l A c = (Y : UU l) → is-equiv (cone-sequence-map A c Y) {- We introduce the canonical sequential limit. -} canonical-sequential-limit : { l1 : Level} (A : Sequence' l1) → UU l1 canonical-sequential-limit A = Σ ( (n : ℕ) → type-seq' A n) ( λ a → (n : ℕ) → Id (map-seq' A n (a (succ-ℕ n))) (a n)) {- We characterize the identity type of the canonical sequential limit. -} Eq-canonical-sequential-limit : { l1 : Level} (A : Sequence' l1) (x y : canonical-sequential-limit A) → UU l1 Eq-canonical-sequential-limit A x y = Σ ( (pr1 x) ~ (pr1 y)) (λ H → (n : ℕ) → Id ((ap (map-seq' A n) (H (succ-ℕ n))) ∙ (pr2 y n)) ((pr2 x n) ∙ (H n))) reflexive-Eq-canonical-sequential-limit : { l1 : Level} (A : Sequence' l1) (x : canonical-sequential-limit A) → Eq-canonical-sequential-limit A x x reflexive-Eq-canonical-sequential-limit A x = pair htpy-refl (htpy-inv htpy-right-unit) Eq-canonical-sequential-limit-eq : { l1 : Level} (A : Sequence' l1) (x y : canonical-sequential-limit A) → Id x y → Eq-canonical-sequential-limit A x y Eq-canonical-sequential-limit-eq A x .x refl = reflexive-Eq-canonical-sequential-limit A x is-contr-total-Eq-canonical-sequential-limit : { l1 : Level} (A : Sequence' l1) (x : canonical-sequential-limit A) → is-contr ( Σ (canonical-sequential-limit A) (Eq-canonical-sequential-limit A x)) is-contr-total-Eq-canonical-sequential-limit A x = is-contr-total-Eq-structure ( λ y q (H : (n : ℕ) → Id (pr1 x n) (y n)) → (n : ℕ) → Id ((ap (map-seq' A n) (H (succ-ℕ n))) ∙ (q n)) ((pr2 x n) ∙ (H n))) ( is-contr-total-Eq-Π ( λ n yn → Id (pr1 x n) yn) ( λ n → is-contr-total-path (pr1 x n)) ( pr1 x)) ( pair (pr1 x) htpy-refl) ( is-contr-total-Eq-Π ( λ n q → Id q ((pr2 x n) ∙ refl)) ( λ n → is-contr-total-path' ((pr2 x n) ∙ refl)) ( pr2 x)) is-equiv-Eq-canonical-sequential-limit : { l1 : Level} (A : Sequence' l1) (x y : canonical-sequential-limit A) → is-equiv (Eq-canonical-sequential-limit-eq A x y) is-equiv-Eq-canonical-sequential-limit A x = fundamental-theorem-id x ( reflexive-Eq-canonical-sequential-limit A x) ( is-contr-total-Eq-canonical-sequential-limit A x) ( Eq-canonical-sequential-limit-eq A x) eq-Eq-canonical-sequential-limit : { l1 : Level} (A : Sequence' l1) {x y : canonical-sequential-limit A} → Eq-canonical-sequential-limit A x y → Id x y eq-Eq-canonical-sequential-limit A {x} {y} = inv-is-equiv (is-equiv-Eq-canonical-sequential-limit A x y) {- We equip the canonical sequential limit with the structure of a cone. -} cone-canonical-sequential-limit : { l1 : Level} (A : Sequence' l1) → cone-sequence A (canonical-sequential-limit A) cone-canonical-sequential-limit A = pair ( λ n a → pr1 a n) ( λ n a → pr2 a n) {- We show that the canonical sequential limit satisfies the universal property of sequential limits. -} inv-canonical-cone-sequence-map : { l1 l2 : Level} (A : Sequence' l1) (Y : UU l2) → cone-sequence A Y → (Y → canonical-sequential-limit A) inv-canonical-cone-sequence-map A Y c y = pair ( λ n → map-cone-sequence A c n y) ( λ n → triangle-cone-sequence A c n y) issec-inv-canonical-cone-sequence-map : { l1 l2 : Level} (A : Sequence' l1) (Y : UU l2) → ( ( cone-sequence-map A (cone-canonical-sequential-limit A) Y) ∘ ( inv-canonical-cone-sequence-map A Y)) ~ id issec-inv-canonical-cone-sequence-map A Y c = eq-htpy-cone-sequence A ( cone-sequence-map A ( cone-canonical-sequential-limit A) ( Y) ( inv-canonical-cone-sequence-map A Y c)) ( c) ( reflexive-htpy-cone-sequence A c) isretr-inv-canonical-cone-sequence-map : { l1 l2 : Level} (A : Sequence' l1) (Y : UU l2) → ( ( inv-canonical-cone-sequence-map A Y) ∘ ( cone-sequence-map A (cone-canonical-sequential-limit A) Y)) ~ id isretr-inv-canonical-cone-sequence-map A Y h = eq-htpy (λ y → eq-Eq-canonical-sequential-limit A ( reflexive-Eq-canonical-sequential-limit A (h y))) universal-property-canonical-sequential-limit : ( l : Level) {l1 : Level} (A : Sequence' l1) → universal-property-sequential-limit l A (cone-canonical-sequential-limit A) universal-property-canonical-sequential-limit l A Y = is-equiv-has-inverse ( inv-canonical-cone-sequence-map A Y) ( issec-inv-canonical-cone-sequence-map A Y) ( isretr-inv-canonical-cone-sequence-map A Y) {- Unique mapping property for sequential limits. -} unique-mapping-property-sequential-limit' : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) { Y : UU l3} (c' : cone-sequence A Y) → is-contr (fib (cone-sequence-map A c Y) c') unique-mapping-property-sequential-limit' {l3 = l3} A c up-X {Y} = is-contr-map-is-equiv (up-X l3 Y) map-universal-property-sequential-limit : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) → { Y : UU l3} (c' : cone-sequence A Y) → Y → X map-universal-property-sequential-limit A c up-X c' = pr1 (center (unique-mapping-property-sequential-limit' A c up-X c')) path-universal-property-sequential-limit : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) → { Y : UU l3} (c' : cone-sequence A Y) → Id ( cone-sequence-map A c Y ( map-universal-property-sequential-limit A c up-X c')) ( c') path-universal-property-sequential-limit A c up-X c' = pr2 (center (unique-mapping-property-sequential-limit' A c up-X c')) unique-mapping-property-sequential-limit : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) → { Y : UU l3} (c' : cone-sequence A Y) → is-contr ( Σ ( Y → X) ( λ h → htpy-cone-sequence A (cone-sequence-map A c Y h) c')) unique-mapping-property-sequential-limit {l3 = l3} A c up-X {Y} c' = is-contr-equiv' ( fib (cone-sequence-map A c Y) c') ( equiv-tot ( λ h → equiv-htpy-cone-sequence-eq A (cone-sequence-map A c Y h) c')) ( unique-mapping-property-sequential-limit' A c up-X c') htpy-universal-property-sequential-limit : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) → { Y : UU l3} (c' : cone-sequence A Y) → htpy-cone-sequence A ( cone-sequence-map A c Y ( map-universal-property-sequential-limit A c up-X c')) ( c') htpy-universal-property-sequential-limit A c up-X {Y} c' = htpy-cone-sequence-eq A ( cone-sequence-map A c Y ( map-universal-property-sequential-limit A c up-X c')) ( c') ( path-universal-property-sequential-limit A c up-X c') uniqueness-map-sequential-limit' : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) { Y : UU l3} (c' : cone-sequence A Y) → ( h : Y → X) (H : Id (cone-sequence-map A c Y h) c') ( h' : Y → X) (H' : Id (cone-sequence-map A c Y h') c') → h ~ h' uniqueness-map-sequential-limit' A c up-X c' h H h' H' = htpy-eq ( ap pr1 ( is-prop-is-contr' ( unique-mapping-property-sequential-limit' A c up-X c') ( pair h H) ( pair h' H'))) uniqueness-map-sequential-limit : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) → { Y : UU l3} (c' : cone-sequence A Y) ( h : Y → X) (H : htpy-cone-sequence A (cone-sequence-map A c Y h) c') ( h' : Y → X) (H' : htpy-cone-sequence A (cone-sequence-map A c Y h') c') → h ~ h' uniqueness-map-sequential-limit A c up-X c' h H h' H' = htpy-eq ( ap pr1 ( is-prop-is-contr' ( unique-mapping-property-sequential-limit A c up-X c') ( pair h H) ( pair h' H'))) {- We show a 3-for-2 property of sequential limits. -} compose-cone-sequence-map : { l1 l2 l3 l4 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) { Y : UU l3} {Z : UU l4} (h : Y → X) (k : Z → Y) → Id ( cone-sequence-map A (cone-sequence-map A c Y h) Z k) ( cone-sequence-map A c Z (h ∘ k)) compose-cone-sequence-map A c h k = refl module 3-for-2-sequential-limit { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} {Y : UU l3} ( c : cone-sequence A X) (c' : cone-sequence A Y) (h : Y → X) ( e : htpy-cone-sequence A (cone-sequence-map A c Y h) c') where triangle-cone-cone-sequence : {l4 : Level} (Z : UU l4) → ( cone-sequence-map A c' Z) ~ ( ( cone-sequence-map A c Z) ∘ (λ (k : Z → Y) → h ∘ k)) triangle-cone-cone-sequence Z k = ap (λ t → cone-sequence-map A t Z k) (inv (eq-htpy-cone-sequence A (cone-sequence-map A c Y h) c' e)) is-equiv-universal-property-sequential-limit : ((l : Level) → universal-property-sequential-limit l A c) → ((l : Level) → universal-property-sequential-limit l A c') → is-equiv h is-equiv-universal-property-sequential-limit up-X up-Y = is-equiv-is-equiv-postcomp h (λ {l} Z → is-equiv-right-factor ( cone-sequence-map A c' Z) ( cone-sequence-map A c Z) ( λ k → h ∘ k) ( triangle-cone-cone-sequence Z) ( up-X l Z) ( up-Y l Z)) universal-property-sequential-limit-is-equiv' : ((l : Level) → universal-property-sequential-limit l A c) → is-equiv h → ((l : Level) → universal-property-sequential-limit l A c') universal-property-sequential-limit-is-equiv' up-X is-equiv-h l Z = is-equiv-comp ( cone-sequence-map A c' Z) ( cone-sequence-map A c Z) ( λ k → h ∘ k) ( triangle-cone-cone-sequence Z) ( is-equiv-postcomp-is-equiv h is-equiv-h Z) ( up-X l Z) universal-property-sequential-limit-is-equiv : ((l : Level) → universal-property-sequential-limit l A c') → is-equiv h → ((l : Level) → universal-property-sequential-limit l A c) universal-property-sequential-limit-is-equiv up-Y is-equiv-h l Z = is-equiv-left-factor ( cone-sequence-map A c' Z) ( cone-sequence-map A c Z) ( λ k → h ∘ k) ( triangle-cone-cone-sequence Z) ( up-Y l Z) ( is-equiv-postcomp-is-equiv h is-equiv-h Z) open 3-for-2-sequential-limit public {- We prove the uniquely uniqueness of sequential limits. -} uniquely-uniqueness-sequential-limit : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} {Y : UU l3} → ( c : cone-sequence A X) (c' : cone-sequence A Y) → ( (l : Level) → universal-property-sequential-limit l A c) → ( (l : Level) → universal-property-sequential-limit l A c') → is-contr (Σ (Y ≃ X) (λ e → htpy-cone-sequence A (cone-sequence-map A c Y (map-equiv e)) c')) uniquely-uniqueness-sequential-limit A {X} {Y} c c' up-X up-Y = is-contr-total-Eq-substructure ( unique-mapping-property-sequential-limit A c up-X c') ( is-subtype-is-equiv) ( map-universal-property-sequential-limit A c up-X c') ( htpy-universal-property-sequential-limit A c up-X c') ( is-equiv-universal-property-sequential-limit A c c' ( map-universal-property-sequential-limit A c up-X c') ( htpy-universal-property-sequential-limit A c up-X c') ( up-X) ( up-Y)) {- We introduce the sequence of function types. -} mapping-sequence : { l1 l2 : Level} (A : Sequence' l1) (X : UU l2) → Sequence' (l1 ⊔ l2) mapping-sequence A X = pair ( λ n → X → type-seq' A n) ( λ n h → (map-seq' A n) ∘ h) cone-mapping-sequence : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( Y : UU l3) → cone-sequence (mapping-sequence A Y) (Y → X) cone-mapping-sequence A c Y = pair ( λ n h → (map-cone-sequence A c n) ∘ h) ( λ n h → eq-htpy ((triangle-cone-sequence A c n) ·r h)) universal-property-sequential-limit-cone-mapping-sequence : { l1 l2 l3 : Level} (A : Sequence' l1) {X : UU l2} (c : cone-sequence A X) → ( up-X : (l : Level) → universal-property-sequential-limit l A c) → ( Y : UU l3) (l : Level) → universal-property-sequential-limit l ( mapping-sequence A Y) ( cone-mapping-sequence A c Y) universal-property-sequential-limit-cone-mapping-sequence A c up-X Y l Z = {!!} {- We introduce cocones on a type sequence. -} cocone-sequence : { l1 l2 : Level} (A : Sequence l1) (X : UU l2) → UU (l1 ⊔ l2) cocone-sequence A X = Σ ( (n : ℕ) → type-seq A n → X) (λ i → (n : ℕ) → (i n) ~ ((i (succ-ℕ n)) ∘ (map-seq A n))) map-cocone-sequence : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} (c : cocone-sequence A X) → ( n : ℕ) → type-seq A n → X map-cocone-sequence A c = pr1 c triangle-cocone-sequence : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} (c : cocone-sequence A X) → ( n : ℕ) → ( map-cocone-sequence A c n) ~ ( (map-cocone-sequence A c (succ-ℕ n)) ∘ (map-seq A n)) triangle-cocone-sequence A c = pr2 c {- We characterize the identity type of cocone-sequence. -} naturality-htpy-cocone-sequence : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} (c c' : cocone-sequence A X) → ( H : (n : ℕ) → (map-cocone-sequence A c n) ~ (map-cocone-sequence A c' n)) → ( n : ℕ) → UU (l1 ⊔ l2) naturality-htpy-cocone-sequence A c c' H n = ( (H n) ∙h (triangle-cocone-sequence A c' n)) ~ ( ( triangle-cocone-sequence A c n) ∙h ( (H (succ-ℕ n)) ·r (map-seq A n))) htpy-cocone-sequence : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} ( c c' : cocone-sequence A X) → UU (l1 ⊔ l2) htpy-cocone-sequence A c c' = Σ ( (n : ℕ) → (map-cocone-sequence A c n) ~ (map-cocone-sequence A c' n)) ( λ H → (n : ℕ) → naturality-htpy-cocone-sequence A c c' H n) reflexive-htpy-cocone-sequence : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} → ( c : cocone-sequence A X) → htpy-cocone-sequence A c c reflexive-htpy-cocone-sequence A c = pair ( λ n → htpy-refl) ( λ n → htpy-inv htpy-right-unit) htpy-cocone-sequence-eq : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} → ( c c' : cocone-sequence A X) → Id c c' → htpy-cocone-sequence A c c' htpy-cocone-sequence-eq A c .c refl = reflexive-htpy-cocone-sequence A c is-contr-total-htpy-cocone-sequence : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} (c : cocone-sequence A X) → is-contr (Σ (cocone-sequence A X) (htpy-cocone-sequence A c)) is-contr-total-htpy-cocone-sequence A c = is-contr-total-Eq-structure ( λ j t H → (n : ℕ) → naturality-htpy-cocone-sequence A c (pair j t) H n) ( is-contr-total-Eq-Π ( λ n j → map-cocone-sequence A c n ~ j) ( λ n → is-contr-total-htpy (map-cocone-sequence A c n)) ( map-cocone-sequence A c)) ( pair ( map-cocone-sequence A c) ( λ n → htpy-refl)) ( is-contr-total-Eq-Π ( λ n H → H ~ ((triangle-cocone-sequence A c n) ∙h htpy-refl)) ( λ n → is-contr-total-htpy' ( (triangle-cocone-sequence A c n) ∙h htpy-refl)) ( triangle-cocone-sequence A c)) is-equiv-htpy-cocone-sequence-eq : { l1 l2 : Level} (A : Sequence l1) {X : UU l2} (c c' : cocone-sequence A X) → is-equiv (htpy-cocone-sequence-eq A c c') is-equiv-htpy-cocone-sequence-eq A c = fundamental-theorem-id c ( reflexive-htpy-cocone-sequence A c) ( is-contr-total-htpy-cocone-sequence A c) ( htpy-cocone-sequence-eq A c) {- We introduce the universal property of sequential colimits. -} cocone-sequence-map : { l1 l2 l3 : Level} (A : Sequence l1) {X : UU l2} → cocone-sequence A X → (Y : UU l3) → (X → Y) → cocone-sequence A Y cocone-sequence-map A c Y h = pair ( λ n → h ∘ (map-cocone-sequence A c n)) ( λ n → h ·l (triangle-cocone-sequence A c n)) universal-property-sequential-colimit : ( l : Level) {l1 l2 : Level} (A : Sequence l1) {X : UU l2} ( c : cocone-sequence A X) → UU (lsuc l ⊔ l1 ⊔ l2) universal-property-sequential-colimit l A c = (Y : UU l) → is-equiv (cocone-sequence-map A c Y)
36.708459
79
0.598329
368865f009e2ee55e5520c85cf3f57397f8eddfa
1,142
agda
Agda
vendor/stdlib/src/Data/Sum.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
vendor/stdlib/src/Data/Sum.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
vendor/stdlib/src/Data/Sum.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
------------------------------------------------------------------------ -- Sums (disjoint unions) ------------------------------------------------------------------------ module Data.Sum where open import Data.Function open import Data.Maybe.Core ------------------------------------------------------------------------ -- Definition infixr 1 _⊎_ data _⊎_ (A B : Set) : Set where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B ------------------------------------------------------------------------ -- Functions [_,_] : ∀ {A B} {C : A ⊎ B → Set} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ] (inj₁ x) = f x [ f , g ] (inj₂ y) = g y [_,_]′ : ∀ {A B C : Set} → (A → C) → (B → C) → (A ⊎ B → C) [_,_]′ = [_,_] map : ∀ {a b c d} → (a → c) → (b → d) → (a ⊎ b → c ⊎ d) map f g = [ inj₁ ∘ f , inj₂ ∘ g ] infixr 1 _-⊎-_ _-⊎-_ : ∀ {a b} → (a → b → Set) → (a → b → Set) → (a → b → Set) f -⊎- g = f -[ _⊎_ ]₁- g isInj₁ : ∀ {A B} → A ⊎ B → Maybe A isInj₁ (inj₁ x) = just x isInj₁ (inj₂ y) = nothing isInj₂ : ∀ {A B} → A ⊎ B → Maybe B isInj₂ (inj₁ x) = nothing isInj₂ (inj₂ y) = just y
24.826087
72
0.330123
737cef30846ce4b2d3dcd75f14f44a8d319562c5
364
agda
Agda
test/Fail/Issue1078.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1078.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1078.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v import:10 -v scope:10 #-} module Issue1078 where import Common.Level import Issue1078.A import Issue1078.B -- Was: weird scope error in Issue1078.B -- Should give error: -- You tried to load Issue1078/B.agda -- which defines the module Issue1078.A. However, according to the -- include path this module should be defined in Issue1078/A.agda.
24.266667
66
0.741758
2109658ab7bf29a53f09bf8f9edbe2b201b85132
771
agda
Agda
Cubical/Data/NatMinusOne/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/NatMinusOne/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/NatMinusOne/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --no-exact-split --safe #-} module Cubical.Data.NatMinusOne.Base where open import Cubical.Core.Primitives open import Cubical.Data.Nat open import Cubical.Data.Empty record ℕ₋₁ : Type₀ where constructor -1+_ field n : ℕ pattern neg1 = -1+ zero pattern ℕ→ℕ₋₁ n = -1+ (suc n) 1+_ : ℕ₋₁ → ℕ 1+_ (-1+ n) = n suc₋₁ : ℕ₋₁ → ℕ₋₁ suc₋₁ (-1+ n) = -1+ (suc n) -- Natural number and negative integer literals for ℕ₋₁ open import Cubical.Data.Nat.Literals public instance fromNatℕ₋₁ : HasFromNat ℕ₋₁ fromNatℕ₋₁ = record { Constraint = λ _ → Unit ; fromNat = ℕ→ℕ₋₁ } instance fromNegℕ₋₁ : HasFromNeg ℕ₋₁ fromNegℕ₋₁ = record { Constraint = λ { (suc (suc _)) → ⊥ ; _ → Unit } ; fromNeg = λ { zero → 0 ; (suc zero) → neg1 } }
22.676471
71
0.626459
cc90ca4b51dd94b27cbe3c53708aa5d32f3fbd29
112
agda
Agda
problems/DeMorgan/DeMorgan.agda
danr/agder
ece25bed081a24f02e9f85056d05933eae2afabf
[ "BSD-3-Clause" ]
1
2021-05-17T12:07:03.000Z
2021-05-17T12:07:03.000Z
problems/DeMorgan/DeMorgan.agda
danr/agder
ece25bed081a24f02e9f85056d05933eae2afabf
[ "BSD-3-Clause" ]
null
null
null
problems/DeMorgan/DeMorgan.agda
danr/agder
ece25bed081a24f02e9f85056d05933eae2afabf
[ "BSD-3-Clause" ]
null
null
null
module DeMorgan where open import Definitions deMorgan : {A B : Set} → ¬ A ∧ ¬ B → ¬ (A ∨ B) deMorgan = {!!}
14
46
0.580357
3faed2c71a1b11f7a694341018feed792dda82a0
1,979
agda
Agda
src/fot/FOTC/Data/Conat/Equality/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Data/Conat/Equality/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Data/Conat/Equality/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Equality on Conat ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Conat.Equality.Type where open import FOTC.Base infix 4 _≈_ ------------------------------------------------------------------------------ -- Functional for the relation _≈_ (adapted from (Sander 1992, -- p. 58)). -- -- ≈-F : (D → D → Set) → D → D → Set -- ≈-F R m n = -- (m ≡ zero ∧ n ≡ zero) ∨ (∃[ m' ] ∃[ n' ] m ≡ succ m' ∧ n ≡ succ n' ∧ R m' n') -- The relation _≈_ is the greatest post-fixed point of the functional -- ≈-F (by ≈-out and ≈-coind). -- The equality on Conat. postulate _≈_ : D → D → Set -- The relation _≈_ is a post-fixed point of the functional ≈-F, -- i.e. -- -- _≈_ ≤ ≈-F _≈_. postulate ≈-out : ∀ {m n} → m ≈ n → m ≡ zero ∧ n ≡ zero ∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ m' ≈ n') {-# ATP axiom ≈-out #-} -- The relation _N≈_ is the greatest post-fixed point of _N≈_, i.e. -- -- ∀ R. R ≤ ≈-F R ⇒ R ≤ _N≈_. -- -- N.B. This is an axiom schema. Because in the automatic proofs we -- *must* use an instance, we do not add this postulate as an ATP -- axiom. postulate ≈-coind : (R : D → D → Set) → -- R is a post-fixed point of the functional ≈-F. (∀ {m n} → R m n → m ≡ zero ∧ n ≡ zero ∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')) → -- _≈_ is greater than R. ∀ {m n} → R m n → m ≈ n ------------------------------------------------------------------------------ -- References -- -- Sander, Herbert P. (1992). A Logic of Functional Programs with an -- Application to Concurrency. PhD thesis. Department of Computer -- Sciences: Chalmers University of Technology and University of -- Gothenburg.
31.919355
80
0.457302
73d6faef971afeb56b5b902f92d066a34296cafd
515
agda
Agda
test/interaction/Issue3095-fail.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue3095-fail.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue3095-fail.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2018-05-28, issue #3095, fail on attempt to make hidden parent variable visible data Nat : Set where suc : {n : Nat} → Nat data IsSuc : Nat → Set where isSuc : ∀{n} → IsSuc (suc {n}) test : ∀{m} → IsSuc m → Set test p = aux p where aux : ∀{n} → IsSuc n → Set aux isSuc = {!m!} -- Split on m here -- Context: -- p : IsSuc m -- m : Nat (out of scope) -- n : Nat (out of scope) -- Expected error: -- Cannot split on module parameter m -- when checking that the expression ? has type Set
22.391304
91
0.61165
ede23164208b5d3fda7007541d0fc614f1c89913
1,909
agda
Agda
core/lib/Function.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
core/lib/Function.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
core/lib/Function.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import lib.Base open import lib.PathGroupoid {- This file contains various basic definitions and lemmas about functions (non-dependent [Pi] types) that do not belong anywhere else. -} module lib.Function where {- Basic lemmas about pointed maps -} -- concatenation ⊙∘-pt : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (f : A → B) {b : B} → a₁ == a₂ → f a₂ == b → f a₁ == b ⊙∘-pt f p q = ap f p ∙ q infixr 80 _⊙∘_ _⊙∘_ : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (g : Y ⊙→ Z) (f : X ⊙→ Y) → X ⊙→ Z (g , gpt) ⊙∘ (f , fpt) = (g ∘ f) , ⊙∘-pt g fpt gpt ⊙∘-unit-l : ∀ {i j} {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y) → ⊙idf Y ⊙∘ f == f ⊙∘-unit-l (f , idp) = idp ⊙∘-unit-r : ∀ {i j} {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y) → f ⊙∘ ⊙idf X == f ⊙∘-unit-r f = idp {- Homotopy fibers -} module _ {i j} {A : Type i} {B : Type j} (f : A → B) where hfiber : (y : B) → Type (lmax i j) hfiber y = Σ A (λ x → f x == y) {- Note that [is-inj] is not a mere proposition. -} is-inj : Type (lmax i j) is-inj = (a₁ a₂ : A) → f a₁ == f a₂ → a₁ == a₂ preserves-≠ : Type (lmax i j) preserves-≠ = {a₁ a₂ : A} → a₁ ≠ a₂ → f a₁ ≠ f a₂ module _ {i j} {A : Type i} {B : Type j} {f : A → B} where abstract inj-preserves-≠ : is-inj f → preserves-≠ f inj-preserves-≠ inj ¬p q = ¬p (inj _ _ q) module _ {i j k} {A : Type i} {B : Type j} {C : Type k} {f : A → B} {g : B → C} where ∘-is-inj : is-inj g → is-inj f → is-inj (g ∘ f) ∘-is-inj g-is-inj f-is-inj a₁ a₂ = f-is-inj a₁ a₂ ∘ g-is-inj (f a₁) (f a₂) {- Maps between two functions -} record CommSquare {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁} (f₀ : A₀ → B₀) (f₁ : A₁ → B₁) (hA : A₀ → A₁) (hB : B₀ → B₁) : Type (lmax (lmax i₀ i₁) (lmax j₀ j₁)) where constructor comm-sqr field commutes : ∀ a₀ → (hB ∘ f₀) a₀ == (f₁ ∘ hA) a₀ open CommSquare public
27.271429
76
0.520168
73156c200f3ac8096d127870954d8d132fe0793d
116
agda
Agda
test/Succeed/NonConjectures/Issue18.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
10
2015-09-03T20:54:16.000Z
2019-12-03T13:44:25.000Z
test/Succeed/NonConjectures/Issue18.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
121
2015-01-25T13:22:12.000Z
2018-04-22T06:01:44.000Z
test/Succeed/NonConjectures/Issue18.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
4
2016-05-10T23:06:19.000Z
2016-08-03T03:54:55.000Z
module Issue18 where postulate D : Set data ∃ (A : D → Set) : Set where _,_ : (witness : D) → A witness → ∃ A
14.5
39
0.577586
37c401c6122c6a4298898b1fd0bc9e342130339d
12,192
agda
Agda
GauInt/EucDomain.agda
onestruggler/EucDomain
7e268e8354065fde734c9c2d9998d2cfd4a21f71
[ "CC0-1.0" ]
null
null
null
GauInt/EucDomain.agda
onestruggler/EucDomain
7e268e8354065fde734c9c2d9998d2cfd4a21f71
[ "CC0-1.0" ]
null
null
null
GauInt/EucDomain.agda
onestruggler/EucDomain
7e268e8354065fde734c9c2d9998d2cfd4a21f71
[ "CC0-1.0" ]
null
null
null
-- We show Gausssian Integers forms an Euclidean domain. The proofs -- are straightforward. {-# OPTIONS --without-K --safe #-} module GauInt.EucDomain where -- imports from local. -- Hiding the usual div and mod function. We will the new instance in -- Integer.EucDomain2 import Instances hiding (DMℤ) open Instances open import Integer.EucDomain2 renaming (div' to divℤ ; mod' to modℤ ; euc-eq' to euc-eqℤ ; euc-rank' to euc-rankℤ) open import Integer.Properties open import GauInt.Base using (𝔾 ; _+_i ; _ᶜ ; Re ; Im ; _+0i ; _+0i' ; 0𝔾 ; 1𝔾) open import GauInt.Properties open import GauInt.Instances -- imports from stdlib and Agda. open import Relation.Nullary using (yes ; no ; ¬_) open import Relation.Binary.PropositionalEquality open import Data.Product as P using (_×_ ; _,_ ; proj₁ ; proj₂) open import Data.Sum as S renaming ([_,_]′ to ⊎-elim) open import Data.Nat as Nat using (ℕ ; suc ; zero ; z≤n) import Data.Nat.Properties as NatP open import Data.Integer as Int using (0ℤ ; +0 ; +_ ; _≥_ ; +≤+ ; +[1+_] ; -[1+_] ; ℤ ; ∣_∣) import Data.Integer.Properties as IntP import Data.Nat.Solver as NS import Data.Integer.Solver as IS import GauInt.Solver as GS open import Algebra.Properties.Ring +-*-ring open import Algebra.Definitions (_≡_ {A = 𝔾}) using (AlmostLeftCancellative) open import Function.Base using (_$_) -- ---------------------------------------------------------------------- -- Euclidean Structure on 𝔾 -- As explained in the imports part, we will use the div and mod -- function defined in Integer.EucDomain2. -- A special case when the divisor is a positive natural number. The proof: -- Let x = a + b i, and y = d. By integer euc-eq and euc-rank we have -- step-a : a = ra + qa * d, with rank ra ≤ d / 2. -- step-b : b = rb + qb * d, with rank rb ≤ d / 2. -- We let q = qa + qb i, r = ra + rb i. Easy to check that -- eq : x = r + q y. Slightly harder to check -- le : rank r ≤ d / 2 (see below). div' : 𝔾 -> (d : ℕ) -> ¬ d ≡ 0# -> 𝔾 div' n zero n0 with n0 refl ... | () div' (a + b i) d@(suc e) n0 = qa + qb i where qa = a / + d qb = b / + d mod' : 𝔾 -> (d : ℕ) -> ¬ d ≡ 0# -> 𝔾 mod' n zero n0 with n0 refl ... | () mod' (a + b i) d@(suc e) n0 = ra + rb i where ra = a % + d rb = b % + d div : (x y : 𝔾) -> ¬ y ≡ 0# -> 𝔾 div x y n0 = div' (x * y ᶜ) y*yᶜ n0' where y*yᶜ : ℕ y*yᶜ = rank y n0' : ¬ rank y ≡ 0# n0' = y≠0#⇒rank≠0 n0 mod : (x y : 𝔾) -> ¬ y ≡ 0# -> 𝔾 mod x y n0 = (x - q * y) where q = div x y n0 -- ---------------------------------------------------------------------- -- euc-eq and euc-rank property for div' and mod' -- Dividend = reminder + quotient * divisor. euc-eq' : ∀ (x : 𝔾) (d : ℕ) (n0 : ¬ d ≡ 0) -> let r = mod' x d n0 in let q = div' x d n0 in x ≡ r + q * (d +0i) euc-eq' n zero n0 with n0 refl ... | () euc-eq' x@(a + b i) d@(suc e) n0 = eq where -- setting up q and r. n0' : ¬ + d ≡ 0# n0' p = n0 (IntP.+-injective p) qa = a / + d qb = b / + d ra = a % + d rb = b % + d ea : a ≡ ra + qa * + d ea = euc-eqℤ a (+ d) n0' eb : b ≡ rb + qb * + d eb = euc-eqℤ b (+ d) n0' q : 𝔾 q = qa + qb i r : 𝔾 r = ra + rb i -- Inject natural number d to Gaussian integer. y = d +0i -- Proving x = r + q * y. eq : x ≡ r + q * y eq = begin x ≡⟨ refl ⟩ a + b i ≡⟨ cong (λ x -> x + b i) ea ⟩ (ra + qa * (+ d)) + b i ≡⟨ cong (λ x -> (ra + qa * (+ d)) + x i) eb ⟩ (ra + qa * (+ d)) + (rb + qb * (+ d)) i ≡⟨ refl ⟩ (ra + rb i) + ((qa * (+ d)) + (qb * (+ d)) i) ≡⟨ cong (λ x → (ra + rb i) + ((qa * (+ d)) + x i)) ((solve 3 (λ qa d qb → qb :* d := qa :* con 0ℤ :+ qb :* d) refl) qa (+ d) qb) ⟩ (ra + rb i) + ((qa * (+ d)) + (qa * 0ℤ + qb * (+ d)) i) ≡⟨ cong (λ x → (ra + rb i) + (x + (qa * 0ℤ + qb * (+ d)) i)) ((solve 3 (λ qa d qb → qa :* d := qa :* d :- qb :* con 0ℤ) refl) qa (+ d) qb) ⟩ (ra + rb i) + ((qa * (+ d) - qb * 0ℤ) + (qa * 0ℤ + qb * (+ d)) i) ≡⟨ refl ⟩ (ra + rb i) + (qa + qb i) * y ≡⟨ refl ⟩ r + q * y ∎ where open IS.+-*-Solver open ≡-Reasoning -- rank r < rank (inj d) euc-rank' : ∀ (x : 𝔾) (d : ℕ) (n0 : ¬ d ≡ 0) -> let r = mod' x d n0 in let q = div' x d n0 in rank r < rank (d +0i) euc-rank' n zero n0 with n0 refl ... | () euc-rank' x@(a + b i) d@(suc e) n0 = le where -- setting up q and r. n0' : ¬ + d ≡ 0# n0' p = n0 (IntP.+-injective p) r : 𝔾 r = mod' x d n0 ra = Re r rb = Im r q : 𝔾 q = div' x d n0 qa = Re q qb = Im q lea : ∣ ra ∣ ≤ d / 2 lea = euc-rankℤ a (+ d) n0' leb : ∣ rb ∣ ≤ d / 2 leb = euc-rankℤ b (+ d) n0' y = d +0i -- Proving rank r < rank y. -- Some auxillary lemmas. lem1 : ∀ {d : ℕ} -> d / 2 + d / 2 ≤ d lem1 {d} = begin d / 2 + d / 2 ≡⟨ solve 1 (λ x → x :+ x := x :* con 2) refl (d / 2) ⟩ d / 2 * 2 ≤⟨ NatP.m≤n+m (d / 2 * 2) (d % 2) ⟩ d % 2 + d / 2 * 2 ≡⟨ (sym $ NatESR.euc-eq d 2 (λ ())) ⟩ d ∎ where open NatP.≤-Reasoning open NS.+-*-Solver lem2 : ∀ {d : Nat.ℕ} -> d / 2 ≤ d lem2 {d} = begin d / 2 ≤⟨ NatP.m≤n+m (d / 2) (d / 2) ⟩ d / 2 + d / 2 ≤⟨ lem1 {d} ⟩ d ∎ where open NatP.≤-Reasoning open NS.+-*-Solver lem2-strict : ∀ {d : Nat.ℕ} .{{_ : NonZero d}} -> (d / 2) < d lem2-strict {x@(suc d)} with x / 2 Nat.≟ 0 ... | no ¬p = begin-strict x / 2 <⟨ NatP.m<n+m (x / 2) x/2>0 ⟩ x / 2 + x / 2 ≤⟨ lem1 {x} ⟩ x ∎ where open NatP.≤-Reasoning open NS.+-*-Solver open import Relation.Binary.Definitions open import Data.Empty x/2>0 : 0 < (x / 2) x/2>0 with NatP.<-cmp 0 (x / 2) ... | tri< a ¬b ¬c = a ... | tri≈ ¬a b ¬c = ⊥-elim (¬p (sym b)) ... | yes p rewrite p = Nat.s≤s Nat.z≤n lem3 : rank y ≡ d * d lem3 = begin rank y ≡⟨ refl ⟩ ∣ (+ d) * (+ d) + 0ℤ * 0ℤ ∣ ≡⟨ cong ∣_∣ (solve 1 (λ x → x :* x :+ con 0ℤ :* con 0ℤ := x :* x) refl (+ d)) ⟩ ∣ (+ d) * (+ d) ∣ ≡⟨ IntP.abs-*-commute (+ d) (+ d) ⟩ ∣ (+ d) ∣ * ∣ (+ d) ∣ ≡⟨ refl ⟩ d * d ∎ where open IS.+-*-Solver open ≡-Reasoning -- The proof idea: -- rank r = ∣ ra * ra + rb * rb ∣ = ∣ ra ∣ * ∣ ra ∣ + ∣ rb ∣ * ∣ rb ∣ -- ≤ d / 2 * d / 2 + d / 2 * d / 2 by the integer divmod property. -- ≤ d * d -- = rank y le : rank r < rank y le = begin-strict rank r ≡⟨ refl ⟩ let (sa , sae) = (a*a=+b ra) in let (sb , sbe) = a*a=+b rb in ∣ ra * ra + rb * rb ∣ ≡⟨ tri-eq' ra rb ⟩ ∣ ra * ra ∣ + ∣ rb * rb ∣ ≡⟨ cong₂ _+_ (IntP.abs-*-commute ra ra) (IntP.abs-*-commute rb rb) ⟩ ∣ ra ∣ * ∣ ra ∣ + ∣ rb ∣ * ∣ rb ∣ ≤⟨ NatP.+-mono-≤ (NatP.*-mono-≤ lea lea) (NatP.*-mono-≤ leb leb) ⟩ (d / 2) * (d / 2) + (d / 2) * (d / 2) ≡⟨ solve 1 (λ x → (x :* x) :+ (x :* x) := x :* (x :+ x)) refl (d / 2) ⟩ (d / 2) * ((d / 2) + (d / 2)) ≤⟨ NatP.*-monoʳ-≤ (d / 2) lem1 ⟩ (d / 2) * d <⟨ NatP.*-monoˡ-< d (lem2-strict {d}) ⟩ d * d ≡⟨ sym lem3 ⟩ rank y ∎ where open NatP.≤-Reasoning open NS.+-*-Solver -- ---------------------------------------------------------------------- -- euc-eq and euc-rank property for div and mod -- This is the case when the divisor y = c + d i is an arbitrary -- non-zero Gaussian integer. Easy to see rank y ᶜ = rank y = y * y -- ᶜ = ∣ c * c + d * d ∣ ≠ 0. Notice that by the previous spcial -- case (when the divisor is a positive natural number) we have -- eq' : x * y ᶜ = r' + q' * (y * y ᶜ), and -- le' : rank r' < rank (y * y ᶜ) = rank y * rank y ᶜ -- (eq') ⇒ r' = x * y ᶜ - q' * (y * y ᶜ) = (x - q' * y) * y ᶜ -- ⇒ eqr: rank r' = rank (x - q' * y) * rank y ᶜ -- (le') & (eqr) ⇒ rank (x - q' * y) < rank y since rank y ᶜ ≠ 0. -- So setting q = q', and r = x - q' * y as div and mod functions do, -- then check the euc-rank property holds. -- Dividend = reminder + quotient * divisor. euc-eq : ∀ (x y : 𝔾) (n0 : ¬ y ≡ 0𝔾) -> let r = mod x y n0 in let q = div x y n0 in x ≡ r + q * y euc-eq x y n0 = claim where -- Setting up r and q. r : 𝔾 r = mod x y n0 q : 𝔾 q = div x y n0 claim : x ≡ (x - q * y) + q * y claim = begin x ≡⟨ solve 2 (\ x qy -> x := (x :- qy) :+ qy) refl x (q * y) ⟩ (x - q * y) + q * y ∎ where open GS.+-*-Solver open ≡-Reasoning -- rank r < rank y. euc-rank : ∀ (x y : 𝔾) (n0 : ¬ y ≡ 0#) -> let r = mod x y n0 in let q = div x y n0 in rank r < rank y euc-rank x y n0 = claim where n0' : ¬ rank y ≡ 0# n0' = y≠0#⇒rank≠0 n0 r : 𝔾 r = mod x y n0 q : 𝔾 q = div x y n0 eq : x ≡ r + q * y eq = euc-eq x y n0 r' : 𝔾 r' = mod' (x * y ᶜ) (rank y) n0' q' : 𝔾 q' = div' (x * y ᶜ) (rank y) n0' eq' : x * y ᶜ ≡ r' + q' * (rank y +0i) eq' = euc-eq' (x * y ᶜ) (rank y) n0' le' : rank r' < rank (rank y +0i) le' = euc-rank' (x * y ᶜ) (rank y) n0' q=q' : q ≡ q' q=q' = refl -- eqr : rank r' = rank (x - q' * y) * rank y ᶜ ---- (3) eqr : rank r' ≡ rank (x - q' * y) * rank (y ᶜ) eqr = begin rank r' ≡⟨ cong rank step ⟩ rank ((x - q' * y) * y ᶜ) ≡⟨ rank-*-commute (x - q * y) (y ᶜ) ⟩ rank (x - q' * y) * rank (y ᶜ) ∎ where open ≡-Reasoning step : r' ≡ (x - q' * y) * y ᶜ step = begin r' ≡⟨ solve 2 (λ r x → r := r :+ x :- x) refl r' (q' * (rank y +0i)) ⟩ r' + q' * (rank y +0i) - q' * (rank y +0i) ≡⟨ cong (_- q' * (rank y +0i)) (sym eq') ⟩ x * y ᶜ - q' * (rank y +0i) ≡⟨ cong (λ z → x * y ᶜ - q' * z) (sym $ y*yᶜ=rank {y}) ⟩ x * y ᶜ - q' * (y * y ᶜ) ≡⟨ solve 4 (\ x yc q y -> x :* yc :- q :* ( y :* yc) := (x :- q :* y) :* yc) refl x (y ᶜ) q' y ⟩ (x - q' * y) * y ᶜ ∎ where open GS.+-*-Solver open ≡-Reasoning -- (le') & (eqr) ⇒ rank (x - q' * y) < rank y since rank y ᶜ ≠ 0. claim : rank (x - q' * y) < rank y claim = NatP.*-cancelʳ-< {rank (y ᶜ)} (rank (x - q * y)) (rank y) eqr' where eqr' : rank (x - q' * y) * rank (y ᶜ) < rank y * rank (y ᶜ) eqr' = begin-strict rank (x - q' * y) * rank (y ᶜ) ≡⟨ sym eqr ⟩ rank r' <⟨ le' ⟩ rank (rank y +0i) ≡⟨ cong rank (sym $ y*yᶜ=rank {y}) ⟩ rank (y * y ᶜ) ≡⟨ rank-*-commute y (y ᶜ) ⟩ rank y * rank (y ᶜ) ∎ where open GS.+-*-Solver open NatP.≤-Reasoning -- ---------------------------------------------------------------------- -- 𝔾 is an Euclidean Domain. import EuclideanDomain open EuclideanDomain.Structures (_≡_ {A = 𝔾}) using (IsEuclideanDomain) open EuclideanDomain.Bundles using (EuclideanDomainBundle) +-*-isEuclideanDomain : IsEuclideanDomain _+_ _*_ -_ 0𝔾 1𝔾 +-*-isEuclideanDomain = record { isCommutativeRing = +-*-isCommutativeRing ; *-alc = *-alc-𝔾 ; div = div ; mod = mod ; rank = rank ; euc-eq = euc-eq ; euc-rank = euc-rank } -- Bundle. +-*-euclideanDomain : EuclideanDomainBundle _ _ +-*-euclideanDomain = record { isEuclideanDomain = +-*-isEuclideanDomain' } -- ---------------------------------------------------------------------- -- Making 𝔾 an DivMod instance, overloading div and mod. -- Translation between two nonzeros. nz𝔾 : ∀ (x : 𝔾) -> .{{NonZero x}} -> ¬ x ≡ 0# nz𝔾 (+_ zero + +[1+ n ] i) {{n0}} i0 with i0 ... | () instance g-divmod : DivMod 𝔾 DivMod.NZT g-divmod = NZT𝔾 (g-divmod DivMod./ n) d = div n d (nz𝔾 d) (g-divmod DivMod.% n) d = mod n d (nz𝔾 d)
31.261538
205
0.434957
1be353f53c465574a7319ddb00b2b6a70ce4b4b2
292
agda
Agda
test/Succeed/Issue263b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue263b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue263b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Datatype modules weren't added as sections properly. module Issue263b where module M (A : Set) where data D : Set where postulate A : Set open M.D A -- The module M.D is not parameterized, but is being applied to -- arguments -- when checking the module application module _ = M.D A
20.857143
63
0.726027
cc399a67a8af104a11aab06d01639b0824491f5a
3,300
agda
Agda
README.agda
nad/delay-monad
495f9996673d0f1f34ce202902daaa6c39f8925e
[ "MIT" ]
null
null
null
README.agda
nad/delay-monad
495f9996673d0f1f34ce202902daaa6c39f8925e
[ "MIT" ]
null
null
null
README.agda
nad/delay-monad
495f9996673d0f1f34ce202902daaa6c39f8925e
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Code related to the delay monad -- -- Nils Anders Danielsson ------------------------------------------------------------------------ {-# OPTIONS --cubical --sized-types #-} module README where -- The concept referred to as the delay monad here is the monad -- presented by Capretta in "General Recursion via Coinductive Types". ------------------------------------------------------------------------ -- The delay monad -- The delay monad, defined coinductively. import Delay-monad -- A type used to index a combined definition of strong and weak -- bisimilarity and expansion. import Delay-monad.Bisimilarity.Kind -- A combined definition of strong and weak bisimilarity and -- expansion, along with various properties. import Delay-monad.Bisimilarity -- Strong bisimilarity for partially defined values, along with a -- proof showing that this relation is pointwise isomorphic to path -- equality. import Delay-monad.Bisimilarity.For-all-sizes -- A variant of weak bisimilarity that can be used to relate the -- number of steps in two computations. import Delay-monad.Quantitative-weak-bisimilarity -- Termination. import Delay-monad.Termination -- Alternative definitions of weak bisimilarity. import Delay-monad.Bisimilarity.Alternative -- An observation about weak bisimilarity. import Delay-monad.Bisimilarity.Observation -- Some negative results related to weak bisimilarity and expansion. import Delay-monad.Bisimilarity.Negative -- An example showing that transitivity-like proofs that are not -- size-preserving can sometimes be used in a compositional way. import Delay-monad.Bisimilarity.Transitivity-constructor -- A partial order. import Delay-monad.Partial-order -- Least upper bounds. import Delay-monad.Least-upper-bound -- The delay monad is a monad up to strong bisimilarity. import Delay-monad.Monad -- The "always true" predicate, □. import Delay-monad.Always -- A combinator for running two (independent) computations in -- sequence. import Delay-monad.Sequential -- A combinator for running two computations in parallel. import Delay-monad.Parallel ------------------------------------------------------------------------ -- A variant of the delay monad with a sized type parameter -- The delay monad, defined coinductively, with a sized type -- parameter. import Delay-monad.Sized -- A combined definition of strong and weak bisimilarity and -- expansion, along with various properties. import Delay-monad.Sized.Bisimilarity -- Strong bisimilarity for partially defined values, along with a -- proof showing that this relation is pointwise isomorphic to path -- equality. import Delay-monad.Sized.Bisimilarity.For-all-sizes -- Termination. import Delay-monad.Sized.Termination -- Alternative definitions of weak bisimilarity. import Delay-monad.Sized.Bisimilarity.Alternative -- Some negative results related to weak bisimilarity and expansion. import Delay-monad.Sized.Bisimilarity.Negative -- A partial order. import Delay-monad.Sized.Partial-order -- Least upper bounds. import Delay-monad.Sized.Least-upper-bound -- A monad-like structure. import Delay-monad.Sized.Monad -- The "always true" predicate, □. import Delay-monad.Sized.Always
24.626866
72
0.712727
36ef0c336a77e70703675fe2d0e4738c82681610
4,255
agda
Agda
BasicIS4/Semantics/TarskiClosedOvergluedHilbert.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIS4/Semantics/TarskiClosedOvergluedHilbert.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIS4/Semantics/TarskiClosedOvergluedHilbert.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇. -- Tarski-style semantics with glueing for α, ▻, and □, after Coquand-Dybjer and Gabbay-Nanevski. -- Hilbert-style closed syntax. module BasicIS4.Semantics.TarskiClosedOvergluedHilbert where open import BasicIS4.Syntax.Common public open import Common.Semantics public -- Tarski models. record Model : Set₁ where infix 3 ⊩ᵅ_ [⊢]_ field -- Forcing for atomic propositions. ⊩ᵅ_ : Atom → Set -- Hilbert-style closed syntax representation. [⊢]_ : Ty → Set [app] : ∀ {A B} → [⊢] A ▻ B → [⊢] A → [⊢] B [ci] : ∀ {A} → [⊢] A ▻ A [ck] : ∀ {A B} → [⊢] A ▻ B ▻ A [cs] : ∀ {A B C} → [⊢] (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C [box] : ∀ {A} → [⊢] A → [⊢] □ A [cdist] : ∀ {A B} → [⊢] □ (A ▻ B) ▻ □ A ▻ □ B [cup] : ∀ {A} → [⊢] □ A ▻ □ □ A [cdown] : ∀ {A} → [⊢] □ A ▻ A [cpair] : ∀ {A B} → [⊢] A ▻ B ▻ A ∧ B [cfst] : ∀ {A B} → [⊢] A ∧ B ▻ A [csnd] : ∀ {A B} → [⊢] A ∧ B ▻ B [unit] : [⊢] ⊤ infix 3 [⊢]⋆_ [⊢]⋆_ : Cx Ty → Set [⊢]⋆ ∅ = 𝟙 [⊢]⋆ Ξ , A = [⊢]⋆ Ξ × [⊢] A open Model {{…}} public -- Forcing in a particular model. module _ {{_ : Model}} where infix 3 ⊩_ ⊩_ : Ty → Set ⊩ α P = Glue ([⊢] α P) (⊩ᵅ P) ⊩ A ▻ B = Glue ([⊢] A ▻ B) (⊩ A → ⊩ B) ⊩ □ A = Glue ([⊢] □ A) (⊩ A) ⊩ A ∧ B = ⊩ A × ⊩ B ⊩ ⊤ = 𝟙 infix 3 ⊩⋆_ ⊩⋆_ : Cx Ty → Set ⊩⋆ ∅ = 𝟙 ⊩⋆ Ξ , A = ⊩⋆ Ξ × ⊩ A -- Entailment, or forcing in all models. infix 3 ⊨_ ⊨_ : Ty → Set₁ ⊨ A = ∀ {{_ : Model}} → ⊩ A -- Extraction of syntax representation in a particular model. module _ {{_ : Model}} where reifyʳ : ∀ {A} → ⊩ A → [⊢] A reifyʳ {α P} s = syn s reifyʳ {A ▻ B} s = syn s reifyʳ {□ A} s = syn s reifyʳ {A ∧ B} s = [app] ([app] [cpair] (reifyʳ {A} (π₁ s))) (reifyʳ {B} (π₂ s)) reifyʳ {⊤} s = [unit] reifyʳ⋆ : ∀ {Ξ} → ⊩⋆ Ξ → [⊢]⋆ Ξ reifyʳ⋆ {∅} ∙ = ∙ reifyʳ⋆ {Ξ , A} (ts , t) = reifyʳ⋆ ts , reifyʳ t -- Additional useful equipment. module _ {{_ : Model}} where _⟪$⟫_ : ∀ {A B} → ⊩ A ▻ B → ⊩ A → ⊩ B s ⟪$⟫ a = sem s a ⟪K⟫ : ∀ {A B} → ⊩ A → ⊩ B ▻ A ⟪K⟫ a = [app] [ck] (reifyʳ a) ⅋ K a ⟪S⟫ : ∀ {A B C} → ⊩ A ▻ B ▻ C → ⊩ A ▻ B → ⊩ A → ⊩ C ⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a) ⟪S⟫′ : ∀ {A B C} → ⊩ A ▻ B ▻ C → ⊩ (A ▻ B) ▻ A ▻ C ⟪S⟫′ s₁ = [app] [cs] (reifyʳ s₁) ⅋ λ s₂ → [app] ([app] [cs] (reifyʳ s₁)) (reifyʳ s₂) ⅋ ⟪S⟫ s₁ s₂ _⟪D⟫_ : ∀ {A B} → ⊩ □ (A ▻ B) → ⊩ □ A → ⊩ □ B s₁ ⟪D⟫ s₂ = let t ⅋ s₁′ = s₁ u ⅋ a = s₂ in [app] ([app] [cdist] t) u ⅋ s₁′ ⟪$⟫ a _⟪D⟫′_ : ∀ {A B} → ⊩ □ (A ▻ B) → ⊩ □ A ▻ □ B _⟪D⟫′_ s₁ = [app] [cdist] (reifyʳ s₁) ⅋ _⟪D⟫_ s₁ ⟪↑⟫ : ∀ {A} → ⊩ □ A → ⊩ □ □ A ⟪↑⟫ s = [box] (syn s) ⅋ s ⟪↓⟫ : ∀ {A} → ⊩ □ A → ⊩ A ⟪↓⟫ s = sem s _⟪,⟫′_ : ∀ {A B} → ⊩ A → ⊩ B ▻ A ∧ B _⟪,⟫′_ a = [app] [cpair] (reifyʳ a) ⅋ _,_ a -- Forcing in a particular model, for sequents. module _ {{_ : Model}} where infix 3 ⊩_⇒_ ⊩_⇒_ : Cx Ty → Ty → Set ⊩ Γ ⇒ A = ⊩⋆ Γ → ⊩ A infix 3 ⊩_⇒⋆_ ⊩_⇒⋆_ : Cx Ty → Cx Ty → Set ⊩ Γ ⇒⋆ Ξ = ⊩⋆ Γ → ⊩⋆ Ξ -- Entailment, or forcing in all models, for sequents. infix 3 _⊨_ _⊨_ : Cx Ty → Ty → Set₁ Γ ⊨ A = ∀ {{_ : Model}} → ⊩ Γ ⇒ A infix 3 _⊨⋆_ _⊨⋆_ : Cx Ty → Cx Ty → Set₁ Γ ⊨⋆ Ξ = ∀ {{_ : Model}} → ⊩ Γ ⇒⋆ Ξ -- Additional useful equipment, for sequents. module _ {{_ : Model}} where lookup : ∀ {A Γ} → A ∈ Γ → ⊩ Γ ⇒ A lookup top (γ , a) = a lookup (pop i) (γ , b) = lookup i γ ⟦λ⟧ : ∀ {A B Γ} → [⊢] A ▻ B → ⊩ Γ , A ⇒ B → ⊩ Γ ⇒ A ▻ B ⟦λ⟧ t s γ = t ⅋ λ a → s (γ , a) _⟦$⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ A ▻ B → ⊩ Γ ⇒ A → ⊩ Γ ⇒ B (s₁ ⟦$⟧ s₂) γ = s₁ γ ⟪$⟫ s₂ γ ⟦S⟧ : ∀ {A B C Γ} → ⊩ Γ ⇒ A ▻ B ▻ C → ⊩ Γ ⇒ A ▻ B → ⊩ Γ ⇒ A → ⊩ Γ ⇒ C ⟦S⟧ s₁ s₂ a γ = ⟪S⟫ (s₁ γ) (s₂ γ) (a γ) _⟦D⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ □ (A ▻ B) → ⊩ Γ ⇒ □ A → ⊩ Γ ⇒ □ B (s₁ ⟦D⟧ s₂) γ = (s₁ γ) ⟪D⟫ (s₂ γ) ⟦↑⟧ : ∀ {A Γ} → ⊩ Γ ⇒ □ A → ⊩ Γ ⇒ □ □ A ⟦↑⟧ s γ = ⟪↑⟫ (s γ) ⟦↓⟧ : ∀ {A Γ} → ⊩ Γ ⇒ □ A → ⊩ Γ ⇒ A ⟦↓⟧ s γ = ⟪↓⟫ (s γ) _⟦,⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ A → ⊩ Γ ⇒ B → ⊩ Γ ⇒ A ∧ B (a ⟦,⟧ b) γ = a γ , b γ ⟦π₁⟧ : ∀ {A B Γ} → ⊩ Γ ⇒ A ∧ B → ⊩ Γ ⇒ A ⟦π₁⟧ s γ = π₁ (s γ) ⟦π₂⟧ : ∀ {A B Γ} → ⊩ Γ ⇒ A ∧ B → ⊩ Γ ⇒ B ⟦π₂⟧ s γ = π₂ (s γ)
24.883041
97
0.389424
4e96c41f120683694c7efdefa75ed0795efc33ef
1,053
agda
Agda
agda/Avionics/Bool.agda
RPI-WCL/safety-envelopes-sentinels
896e67a2ad21041a1c9ef5f3ad6318c67d730341
[ "BSD-3-Clause" ]
null
null
null
agda/Avionics/Bool.agda
RPI-WCL/safety-envelopes-sentinels
896e67a2ad21041a1c9ef5f3ad6318c67d730341
[ "BSD-3-Clause" ]
null
null
null
agda/Avionics/Bool.agda
RPI-WCL/safety-envelopes-sentinels
896e67a2ad21041a1c9ef5f3ad6318c67d730341
[ "BSD-3-Clause" ]
1
2020-09-20T00:36:09.000Z
2020-09-20T00:36:09.000Z
module Avionics.Bool where open import Data.Bool using (Bool; true; false; _∧_; T) open import Data.Unit using (⊤; tt) open import Data.Product using (_×_; _,_) open import Relation.Binary.PropositionalEquality using (_≡_; refl; inspect; [_]) --open import Avionics.Product using (_×_; ⟨_,_⟩) --TODO: Replace with T⇔≡ from standard library ≡→T : ∀ {b : Bool} → b ≡ true → T b ≡→T refl = tt T→≡ : ∀ {b : Bool} → T b → b ≡ true T→≡ {true} tt = refl T∧→× : ∀ {x y} → T (x ∧ y) → (T x) × (T y) T∧→× {true} {true} tt = tt , tt --TODO: Find a way to extract the function below from `T-∧` (standard library) --T∧→× {x} {y} = ? -- Equivalence.to (T-∧ {x} {y}) ×→T∧ : ∀ {x y} → (T x) × (T y) → T (x ∧ y) ×→T∧ {true} {true} (tt , tt) = tt lem∧ : {a b : Bool} → a ∧ b ≡ true → a ≡ true × b ≡ true lem∧ {true} {true} refl = refl , refl ∧≡true→×≡ : ∀ {A B : Set} {f : A → Bool} {g : B → Bool} (n : A) (m : B) → f n ∧ g m ≡ true → f n ≡ true × g m ≡ true ∧≡true→×≡ {f = f} {g = g} n m fn∧gm≡true = lem∧ {f n} {g m} fn∧gm≡true
30.970588
81
0.518519
73dd0f79f4d4fb4e084bef18c4bc175a799bd6d2
5,527
agda
Agda
Cubical/Data/Int/MoreInts/QuoInt/Base.agda
anuyts/cubical
2868ce7542c0b63f185344cffbd90c1cc033027c
[ "MIT" ]
null
null
null
Cubical/Data/Int/MoreInts/QuoInt/Base.agda
anuyts/cubical
2868ce7542c0b63f185344cffbd90c1cc033027c
[ "MIT" ]
null
null
null
Cubical/Data/Int/MoreInts/QuoInt/Base.agda
anuyts/cubical
2868ce7542c0b63f185344cffbd90c1cc033027c
[ "MIT" ]
null
null
null
-- Define the integers as a HIT by identifying +0 and -0 {-# OPTIONS --safe #-} module Cubical.Data.Int.MoreInts.QuoInt.Base where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Relation.Nullary open import Cubical.Data.Int using () renaming (ℤ to Int ; discreteℤ to discreteInt ; isSetℤ to isSetInt ; 0≢1-ℤ to 0≢1-Int) open import Cubical.Data.Nat as ℕ using (ℕ; zero; suc) open import Cubical.Data.Bool as Bool using (Bool; not; notnot) variable l : Level Sign : Type₀ Sign = Bool pattern spos = Bool.false pattern sneg = Bool.true _·S_ : Sign → Sign → Sign _·S_ = Bool._⊕_ data ℤ : Type₀ where signed : (s : Sign) (n : ℕ) → ℤ posneg : signed spos 0 ≡ signed sneg 0 pattern pos n = signed spos n pattern neg n = signed sneg n sign : ℤ → Sign sign (signed _ zero) = spos sign (signed s (suc _)) = s sign (posneg i) = spos sign-pos : ∀ n → sign (pos n) ≡ spos sign-pos zero = refl sign-pos (suc n) = refl abs : ℤ → ℕ abs (signed _ n) = n abs (posneg i) = zero signed-inv : ∀ n → signed (sign n) (abs n) ≡ n signed-inv (pos zero) = refl signed-inv (neg zero) = posneg signed-inv (signed s (suc n)) = refl signed-inv (posneg i) j = posneg (i ∧ j) signed-zero : ∀ s₁ s₂ → signed s₁ zero ≡ signed s₂ zero signed-zero spos spos = refl signed-zero sneg sneg = refl signed-zero spos sneg = posneg signed-zero sneg spos = sym posneg rec : ∀ {A : Type l} → (pos' neg' : ℕ → A) → pos' 0 ≡ neg' 0 → ℤ → A rec pos' neg' eq (pos m) = pos' m rec pos' neg' eq (neg m) = neg' m rec pos' neg' eq (posneg i) = eq i elim : ∀ (P : ℤ → Type l) → (pos' : ∀ n → P (pos n)) → (neg' : ∀ n → P (neg n)) → (λ i → P (posneg i)) [ pos' 0 ≡ neg' 0 ] → ∀ z → P z elim P pos' neg' eq (pos n) = pos' n elim P pos' neg' eq (neg n) = neg' n elim P pos' neg' eq (posneg i) = eq i Int→ℤ : Int → ℤ Int→ℤ (Int.pos n) = pos n Int→ℤ (Int.negsuc n) = neg (suc n) ℤ→Int : ℤ → Int ℤ→Int (pos n) = Int.pos n ℤ→Int (neg zero) = Int.pos 0 ℤ→Int (neg (suc n)) = Int.negsuc n ℤ→Int (posneg _) = Int.pos 0 ℤ→Int→ℤ : ∀ (n : ℤ) → Int→ℤ (ℤ→Int n) ≡ n ℤ→Int→ℤ (pos n) _ = pos n ℤ→Int→ℤ (neg zero) i = posneg i ℤ→Int→ℤ (neg (suc n)) _ = neg (suc n) ℤ→Int→ℤ (posneg j) i = posneg (j ∧ i) Int→ℤ→Int : ∀ (n : Int) → ℤ→Int (Int→ℤ n) ≡ n Int→ℤ→Int (Int.pos n) _ = Int.pos n Int→ℤ→Int (Int.negsuc n) _ = Int.negsuc n Int≡ℤ : Int ≡ ℤ Int≡ℤ = isoToPath (iso Int→ℤ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int) discreteℤ : Discrete ℤ discreteℤ = subst Discrete Int≡ℤ discreteInt isSetℤ : isSet ℤ isSetℤ = subst isSet Int≡ℤ isSetInt -_ : ℤ → ℤ - signed s n = signed (not s) n - posneg i = posneg (~ i) negate-invol : ∀ n → - - n ≡ n negate-invol (signed s n) i = signed (notnot s i) n negate-invol (posneg i) _ = posneg i negateEquiv : ℤ ≃ ℤ negateEquiv = isoToEquiv (iso -_ -_ negate-invol negate-invol) negateEq : ℤ ≡ ℤ negateEq = ua negateEquiv infixl 6 _+_ infixl 7 _·_ sucℤ : ℤ → ℤ sucℤ (pos n) = pos (suc n) sucℤ (neg zero) = pos 1 sucℤ (neg (suc n)) = neg n sucℤ (posneg _) = pos 1 predℤ : ℤ → ℤ predℤ = subst (λ Z → (Z → Z)) negateEq sucℤ -- definitionally equal to λ n → - (sucℤ (- n)) -- strictly more useful than the direct pattern matching version, -- see negateSuc and negatePred sucPredℤ : ∀ n → sucℤ (predℤ n) ≡ n sucPredℤ (pos zero) = sym posneg sucPredℤ (pos (suc _)) = refl sucPredℤ (neg _) = refl sucPredℤ (posneg i) j = posneg (i ∨ ~ j) predSucℤ : ∀ n → predℤ (sucℤ n) ≡ n predSucℤ (pos _) = refl predSucℤ (neg zero) = posneg predSucℤ (neg (suc _)) = refl predSucℤ (posneg i) j = posneg (i ∧ j) _+_ : ℤ → ℤ → ℤ (signed _ zero) + n = n (posneg _) + n = n (pos (suc m)) + n = sucℤ (pos m + n) (neg (suc m)) + n = predℤ (neg m + n) sucPathℤ : ℤ ≡ ℤ sucPathℤ = isoToPath (iso sucℤ predℤ sucPredℤ predSucℤ) -- We do the same trick as in Cubical.Data.Int to prove that addition -- is an equivalence addEqℤ : ℕ → ℤ ≡ ℤ addEqℤ zero = refl addEqℤ (suc n) = addEqℤ n ∙ sucPathℤ predPathℤ : ℤ ≡ ℤ predPathℤ = isoToPath (iso predℤ sucℤ predSucℤ sucPredℤ) subEqℤ : ℕ → ℤ ≡ ℤ subEqℤ zero = refl subEqℤ (suc n) = subEqℤ n ∙ predPathℤ addℤ : ℤ → ℤ → ℤ addℤ (pos m) n = transport (addEqℤ m) n addℤ (neg m) n = transport (subEqℤ m) n addℤ (posneg _) n = n isEquivAddℤ : (m : ℤ) → isEquiv (addℤ m) isEquivAddℤ (pos n) = isEquivTransport (addEqℤ n) isEquivAddℤ (neg n) = isEquivTransport (subEqℤ n) isEquivAddℤ (posneg _) = isEquivTransport refl addℤ≡+ℤ : addℤ ≡ _+_ addℤ≡+ℤ i (pos (suc m)) n = sucℤ (addℤ≡+ℤ i (pos m) n) addℤ≡+ℤ i (neg (suc m)) n = predℤ (addℤ≡+ℤ i (neg m) n) addℤ≡+ℤ i (pos zero) n = n addℤ≡+ℤ i (neg zero) n = n addℤ≡+ℤ _ (posneg _) n = n isEquiv+ℤ : (m : ℤ) → isEquiv (m +_) isEquiv+ℤ = subst (λ _+_ → (m : ℤ) → isEquiv (m +_)) addℤ≡+ℤ isEquivAddℤ _·_ : ℤ → ℤ → ℤ m · n = signed (sign m ·S sign n) (abs m ℕ.· abs n) private ·-abs : ∀ m n → abs (m · n) ≡ abs m ℕ.· abs n ·-abs m n = refl -- Natural number and negative integer literals for ℤ open import Cubical.Data.Nat.Literals public instance fromNatℤ : HasFromNat ℤ fromNatℤ = record { Constraint = λ _ → Unit ; fromNat = λ n → pos n } instance fromNegℤ : HasFromNeg ℤ fromNegℤ = record { Constraint = λ _ → Unit ; fromNeg = λ n → neg n } -- ℤ is non-trivial 0≢1-ℤ : ¬ 0 ≡ 1 0≢1-ℤ p = 0≢1-Int (cong ℤ→Int p)
24.784753
88
0.617514
65361911c28bf308ccc81b5f3e5eb50ea89833f6
11,483
agda
Agda
Cubical/Data/Sigma/Properties.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
Cubical/Data/Sigma/Properties.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
Cubical/Data/Sigma/Properties.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
{- Basic properties about Σ-types - Action of Σ on functions ([map-fst], [map-snd]) - Characterization of equality in Σ-types using dependent paths ([ΣPath{Iso,≃,≡}PathΣ], [Σ≡Prop]) - Proof that discrete types are closed under Σ ([discreteΣ]) - Commutativity and associativity ([Σ-swap-*, Σ-assoc-*]) - Distributivity of Π over Σ ([Σ-Π-*]) - Action of Σ on isomorphisms, equivalences, and paths ([Σ-cong-fst], [Σ-cong-snd], ...) - Characterization of equality in Σ-types using transport ([ΣPathTransport{≃,≡}PathΣ]) - Σ with a contractible base is its fiber ([Σ-contractFst, ΣUnit]) -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Sigma.Properties where open import Cubical.Data.Sigma.Base open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Path open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Relation.Nullary open import Cubical.Data.Unit.Base open Iso private variable ℓ ℓ' : Level A A' : Type ℓ B B' : (a : A) → Type ℓ C : (a : A) (b : B a) → Type ℓ map-fst : {B : Type ℓ} → (f : A → A') → A × B → A' × B map-fst f (a , b) = (f a , b) map-snd : (∀ {a} → B a → B' a) → Σ A B → Σ A B' map-snd f (a , b) = (a , f b) map-× : {B : Type ℓ} {B' : Type ℓ'} → (A → A') → (B → B') → A × B → A' × B' map-× f g (a , b) = (f a , g b) ≡-× : {A : Type ℓ} {B : Type ℓ'} {x y : A × B} → fst x ≡ fst y → snd x ≡ snd y → x ≡ y ≡-× p q i = (p i) , (q i) -- Characterization of paths in Σ using dependent paths module _ {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ'} {x : Σ (A i0) (B i0)} {y : Σ (A i1) (B i1)} where ΣPathP : Σ[ p ∈ PathP A (fst x) (fst y) ] PathP (λ i → B i (p i)) (snd x) (snd y) → PathP (λ i → Σ (A i) (B i)) x y ΣPathP eq i = fst eq i , snd eq i ΣPathIsoPathΣ : Iso (Σ[ p ∈ PathP A (fst x) (fst y) ] (PathP (λ i → B i (p i)) (snd x) (snd y))) (PathP (λ i → Σ (A i) (B i)) x y) fun ΣPathIsoPathΣ = ΣPathP inv ΣPathIsoPathΣ eq = (λ i → fst (eq i)) , (λ i → snd (eq i)) rightInv ΣPathIsoPathΣ _ = refl leftInv ΣPathIsoPathΣ _ = refl ΣPath≃PathΣ : (Σ[ p ∈ PathP A (fst x) (fst y) ] (PathP (λ i → B i (p i)) (snd x) (snd y))) ≃ (PathP (λ i → Σ (A i) (B i)) x y) ΣPath≃PathΣ = isoToEquiv ΣPathIsoPathΣ ΣPath≡PathΣ : (Σ[ p ∈ PathP A (fst x) (fst y) ] (PathP (λ i → B i (p i)) (snd x) (snd y))) ≡ (PathP (λ i → Σ (A i) (B i)) x y) ΣPath≡PathΣ = ua ΣPath≃PathΣ ×≡Prop : isProp A' → {u v : A × A'} → u .fst ≡ v .fst → u ≡ v ×≡Prop pB {u} {v} p i = (p i) , (pB (u .snd) (v .snd) i) Σ≡Prop : ((x : A) → isProp (B x)) → {u v : Σ A B} → (p : u .fst ≡ v .fst) → u ≡ v Σ≡Prop pB {u} {v} p i = (p i) , isProp→PathP (λ i → pB (p i)) (u .snd) (v .snd) i -- Characterization of dependent paths in Σ module _ {A : I → Type ℓ} {B : (i : I) → (a : A i) → Type ℓ'} {x : Σ (A i0) (B i0)} {y : Σ (A i1) (B i1)} where ΣPathPIsoPathPΣ : Iso (Σ[ p ∈ PathP A (x .fst) (y .fst) ] PathP (λ i → B i (p i)) (x .snd) (y .snd)) (PathP (λ i → Σ (A i) (B i)) x y) ΣPathPIsoPathPΣ .fun (p , q) i = p i , q i ΣPathPIsoPathPΣ .inv pq .fst i = pq i .fst ΣPathPIsoPathPΣ .inv pq .snd i = pq i .snd ΣPathPIsoPathPΣ .rightInv _ = refl ΣPathPIsoPathPΣ .leftInv _ = refl ΣPathP≃PathPΣ = isoToEquiv ΣPathPIsoPathPΣ ΣPathP≡PathPΣ = ua ΣPathP≃PathPΣ -- Σ of discrete types discreteΣ : Discrete A → ((a : A) → Discrete (B a)) → Discrete (Σ A B) discreteΣ {B = B} Adis Bdis (a0 , b0) (a1 , b1) = discreteΣ' (Adis a0 a1) where discreteΣ' : Dec (a0 ≡ a1) → Dec ((a0 , b0) ≡ (a1 , b1)) discreteΣ' (yes p) = J (λ a1 p → ∀ b1 → Dec ((a0 , b0) ≡ (a1 , b1))) (discreteΣ'') p b1 where discreteΣ'' : (b1 : B a0) → Dec ((a0 , b0) ≡ (a0 , b1)) discreteΣ'' b1 with Bdis a0 b0 b1 ... | (yes q) = yes (transport ΣPath≡PathΣ (refl , q)) ... | (no ¬q) = no (λ r → ¬q (subst (λ X → PathP (λ i → B (X i)) b0 b1) (Discrete→isSet Adis a0 a0 (cong fst r) refl) (cong snd r))) discreteΣ' (no ¬p) = no (λ r → ¬p (cong fst r)) Σ-swap-Iso : Iso (A × A') (A' × A) fun Σ-swap-Iso (x , y) = (y , x) inv Σ-swap-Iso (x , y) = (y , x) rightInv Σ-swap-Iso _ = refl leftInv Σ-swap-Iso _ = refl Σ-swap-≃ : A × A' ≃ A' × A Σ-swap-≃ = isoToEquiv Σ-swap-Iso Σ-assoc-Iso : Iso (Σ[ (a , b) ∈ Σ A B ] C a b) (Σ[ a ∈ A ] Σ[ b ∈ B a ] C a b) fun Σ-assoc-Iso ((x , y) , z) = (x , (y , z)) inv Σ-assoc-Iso (x , (y , z)) = ((x , y) , z) rightInv Σ-assoc-Iso _ = refl leftInv Σ-assoc-Iso _ = refl Σ-assoc-≃ : (Σ[ (a , b) ∈ Σ A B ] C a b) ≃ (Σ[ a ∈ A ] Σ[ b ∈ B a ] C a b) Σ-assoc-≃ = isoToEquiv Σ-assoc-Iso Σ-Π-Iso : Iso ((a : A) → Σ[ b ∈ B a ] C a b) (Σ[ f ∈ ((a : A) → B a) ] ∀ a → C a (f a)) fun Σ-Π-Iso f = (fst ∘ f , snd ∘ f) inv Σ-Π-Iso (f , g) x = (f x , g x) rightInv Σ-Π-Iso _ = refl leftInv Σ-Π-Iso _ = refl Σ-Π-≃ : ((a : A) → Σ[ b ∈ B a ] C a b) ≃ (Σ[ f ∈ ((a : A) → B a) ] ∀ a → C a (f a)) Σ-Π-≃ = isoToEquiv Σ-Π-Iso Σ-cong-iso-fst : (isom : Iso A A') → Iso (Σ A (B ∘ fun isom)) (Σ A' B) fun (Σ-cong-iso-fst isom) x = fun isom (x .fst) , x .snd inv (Σ-cong-iso-fst {B = B} isom) x = inv isom (x .fst) , subst B (sym (ε (x .fst))) (x .snd) where ε = isHAEquiv.rinv (snd (iso→HAEquiv isom)) rightInv (Σ-cong-iso-fst {B = B} isom) (x , y) = ΣPathP (ε x , toPathP goal) where ε = isHAEquiv.rinv (snd (iso→HAEquiv isom)) goal : subst B (ε x) (subst B (sym (ε x)) y) ≡ y goal = sym (substComposite B (sym (ε x)) (ε x) y) ∙∙ cong (λ x → subst B x y) (lCancel (ε x)) ∙∙ substRefl {B = B} y leftInv (Σ-cong-iso-fst {A = A} {B = B} isom) (x , y) = ΣPathP (leftInv isom x , toPathP goal) where ε = isHAEquiv.rinv (snd (iso→HAEquiv isom)) γ = isHAEquiv.com (snd (iso→HAEquiv isom)) lem : (x : A) → sym (ε (fun isom x)) ∙ cong (fun isom) (leftInv isom x) ≡ refl lem x = cong (λ a → sym (ε (fun isom x)) ∙ a) (γ x) ∙ lCancel (ε (fun isom x)) goal : subst B (cong (fun isom) (leftInv isom x)) (subst B (sym (ε (fun isom x))) y) ≡ y goal = sym (substComposite B (sym (ε (fun isom x))) (cong (fun isom) (leftInv isom x)) y) ∙∙ cong (λ a → subst B a y) (lem x) ∙∙ substRefl {B = B} y Σ-cong-equiv-fst : (e : A ≃ A') → Σ A (B ∘ equivFun e) ≃ Σ A' B Σ-cong-equiv-fst e = isoToEquiv (Σ-cong-iso-fst (equivToIso e)) Σ-cong-fst : (p : A ≡ A') → Σ A (B ∘ transport p) ≡ Σ A' B Σ-cong-fst {B = B} p i = Σ (p i) (B ∘ transp (λ j → p (i ∨ j)) i) Σ-cong-iso-snd : ((x : A) → Iso (B x) (B' x)) → Iso (Σ A B) (Σ A B') fun (Σ-cong-iso-snd isom) (x , y) = x , fun (isom x) y inv (Σ-cong-iso-snd isom) (x , y') = x , inv (isom x) y' rightInv (Σ-cong-iso-snd isom) (x , y) = ΣPathP (refl , rightInv (isom x) y) leftInv (Σ-cong-iso-snd isom) (x , y') = ΣPathP (refl , leftInv (isom x) y') Σ-cong-equiv-snd : (∀ a → B a ≃ B' a) → Σ A B ≃ Σ A B' Σ-cong-equiv-snd h = isoToEquiv (Σ-cong-iso-snd (equivToIso ∘ h)) Σ-cong-snd : ((x : A) → B x ≡ B' x) → Σ A B ≡ Σ A B' Σ-cong-snd {A = A} p i = Σ[ x ∈ A ] (p x i) Σ-cong-iso : (isom : Iso A A') → ((x : A) → Iso (B x) (B' (fun isom x))) → Iso (Σ A B) (Σ A' B') Σ-cong-iso isom isom' = compIso (Σ-cong-iso-snd isom') (Σ-cong-iso-fst isom) Σ-cong-equiv : (e : A ≃ A') → ((x : A) → B x ≃ B' (equivFun e x)) → Σ A B ≃ Σ A' B' Σ-cong-equiv e e' = isoToEquiv (Σ-cong-iso (equivToIso e) (equivToIso ∘ e')) Σ-cong' : (p : A ≡ A') → PathP (λ i → p i → Type ℓ') B B' → Σ A B ≡ Σ A' B' Σ-cong' p p' = cong₂ (λ (A : Type _) (B : A → Type _) → Σ A B) p p' -- Alternative version for path in Σ-types, as in the HoTT book ΣPathTransport : (a b : Σ A B) → Type _ ΣPathTransport {B = B} a b = Σ[ p ∈ (fst a ≡ fst b) ] transport (λ i → B (p i)) (snd a) ≡ snd b IsoΣPathTransportPathΣ : (a b : Σ A B) → Iso (ΣPathTransport a b) (a ≡ b) IsoΣPathTransportPathΣ {B = B} a b = compIso (Σ-cong-iso-snd (λ p → invIso (equivToIso (PathP≃Path (λ i → B (p i)) _ _)))) ΣPathIsoPathΣ ΣPathTransport≃PathΣ : (a b : Σ A B) → ΣPathTransport a b ≃ (a ≡ b) ΣPathTransport≃PathΣ {B = B} a b = isoToEquiv (IsoΣPathTransportPathΣ a b) ΣPathTransport→PathΣ : (a b : Σ A B) → ΣPathTransport a b → (a ≡ b) ΣPathTransport→PathΣ a b = Iso.fun (IsoΣPathTransportPathΣ a b) PathΣ→ΣPathTransport : (a b : Σ A B) → (a ≡ b) → ΣPathTransport a b PathΣ→ΣPathTransport a b = Iso.inv (IsoΣPathTransportPathΣ a b) ΣPathTransport≡PathΣ : (a b : Σ A B) → ΣPathTransport a b ≡ (a ≡ b) ΣPathTransport≡PathΣ a b = ua (ΣPathTransport≃PathΣ a b) Σ-contractFst : (c : isContr A) → Σ A B ≃ B (c .fst) Σ-contractFst {B = B} c = isoToEquiv isom where isom : Iso _ _ isom .fun (a , b) = subst B (sym (c .snd a)) b isom .inv b = (c .fst , b) isom .rightInv b = cong (λ p → subst B p b) (isProp→isSet (isContr→isProp c) _ _ _ _) ∙ transportRefl _ isom .leftInv (a , b) = ΣPathTransport≃PathΣ _ _ .fst (c .snd a , transportTransport⁻ (cong B (c .snd a)) _) -- a special case of the above ΣUnit : ∀ {ℓ} (A : Unit → Type ℓ) → Σ Unit A ≃ A tt ΣUnit A = isoToEquiv (iso snd (λ { x → (tt , x) }) (λ _ → refl) (λ _ → refl)) Σ-contractSnd : ((a : A) → isContr (B a)) → Σ A B ≃ A Σ-contractSnd c = isoToEquiv isom where isom : Iso _ _ isom .fun = fst isom .inv a = a , c a .fst isom .rightInv _ = refl isom .leftInv (a , b) = cong (a ,_) (c a .snd b) ≃-× : ∀ {ℓ'' ℓ'''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''} → A ≃ C → B ≃ D → A × B ≃ C × D ≃-× eq1 eq2 = map-× (fst eq1) (fst eq2) , record { equiv-proof = λ {(c , d) → ((eq1⁻ c .fst .fst , eq2⁻ d .fst .fst) , ≡-× (eq1⁻ c .fst .snd) (eq2⁻ d .fst .snd)) , λ {((a , b) , p) → ΣPathP (≡-× (cong fst (eq1⁻ c .snd (a , cong fst p))) (cong fst (eq2⁻ d .snd (b , cong snd p))) , λ i → ≡-× (snd ((eq1⁻ c .snd (a , cong fst p)) i)) (snd ((eq2⁻ d .snd (b , cong snd p)) i)))}}} where eq1⁻ = equiv-proof (eq1 .snd) eq2⁻ = equiv-proof (eq2 .snd) {- Some simple ismorphisms -} prodIso : ∀ {ℓ ℓ' ℓ'' ℓ'''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''} → Iso A C → Iso B D → Iso (A × B) (C × D) Iso.fun (prodIso iAC iBD) (a , b) = (Iso.fun iAC a) , Iso.fun iBD b Iso.inv (prodIso iAC iBD) (c , d) = (Iso.inv iAC c) , Iso.inv iBD d Iso.rightInv (prodIso iAC iBD) (c , d) = ΣPathP ((Iso.rightInv iAC c) , (Iso.rightInv iBD d)) Iso.leftInv (prodIso iAC iBD) (a , b) = ΣPathP ((Iso.leftInv iAC a) , (Iso.leftInv iBD b)) toProdIso : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} → Iso (A → B × C) ((A → B) × (A → C)) Iso.fun toProdIso = λ f → (λ a → fst (f a)) , (λ a → snd (f a)) Iso.inv toProdIso (f , g) = λ a → (f a) , (g a) Iso.rightInv toProdIso (f , g) = refl Iso.leftInv toProdIso b = funExt λ _ → refl curryIso : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} → Iso (A × B → C) (A → B → C) Iso.fun curryIso f a b = f (a , b) Iso.inv curryIso f a = f (fst a) (snd a) Iso.rightInv curryIso a = refl Iso.leftInv curryIso f = funExt λ _ → refl
39.460481
140
0.535139
653de73ffb3a69e7a01abb914e8d655f084eeef1
881
agda
Agda
Cubical/Data/InfNat/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/InfNat/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/InfNat/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --no-exact-split --safe #-} module Cubical.Data.InfNat.Properties where open import Cubical.Data.Nat as ℕ using (ℕ) open import Cubical.Data.InfNat.Base open import Cubical.Core.Primitives open import Cubical.Foundations.Prelude open import Cubical.Relation.Nullary open import Cubical.Data.Unit open import Cubical.Data.Empty fromInf-def : ℕ → ℕ+∞ → ℕ fromInf-def n ∞ = n fromInf-def _ (fin n) = n fin-inj : (n m : ℕ) → fin n ≡ fin m → n ≡ m fin-inj x _ eq = cong (fromInf-def x) eq discreteInfNat : Discrete ℕ+∞ discreteInfNat ∞ ∞ = yes (λ i → ∞) discreteInfNat ∞ (fin _) = no λ p → subst (caseInfNat ⊥ Unit) p tt discreteInfNat (fin _) ∞ = no λ p → subst (caseInfNat Unit ⊥) p tt discreteInfNat (fin n) (fin m) with ℕ.discreteℕ n m discreteInfNat (fin n) (fin m) | yes p = yes (cong fin p) discreteInfNat (fin n) (fin m) | no ¬p = no (λ p → ¬p (fin-inj n m p))
32.62963
70
0.68672
4e54ab93f02e0e0a87e6c36371551de910b74fd4
344
agda
Agda
test/Fail/WithoutK5.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Fail/WithoutK5.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Fail/WithoutK5.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --cubical-compatible --show-implicit #-} -- {-# OPTIONS -v tc.data.sort:20 -v tc.lhs.split.well-formed:100 #-} module WithoutK5 where -- Equality defined with one index. data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x weak-K : {A : Set} {a b : A} (p q : a ≡ b) (α β : p ≡ q) → α ≡ β weak-K refl .refl refl refl = refl
26.461538
69
0.584302
2151f7a71bb65efc2c437eb02faace274949dbae
3,432
agda
Agda
src/LibraBFT/Impl/Consensus/Liveness/Properties/ProposerElection.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/Liveness/Properties/ProposerElection.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/Liveness/Properties/ProposerElection.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 open import LibraBFT.Impl.Consensus.Liveness.ProposerElection open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.LBFT open import Optics.All open import Util.Lemmas open import Util.Prelude module LibraBFT.Impl.Consensus.Liveness.Properties.ProposerElection where -- TUTORIAL module isValidProposalMSpec (b : Block) where pe = _^∙ lProposerElection mAuthor = b ^∙ bAuthor round = b ^∙ bRound contract : ∀ pre Post → (mAuthor ≡ nothing → Post (Left ProposalDoesNotHaveAnAuthor) pre []) → (Maybe-Any (getValidProposer (pe pre) round ≢_) mAuthor → Post (Left ProposerForBlockIsNotValidForThisRound) pre []) → (Maybe-Any (getValidProposer (pe pre) round ≡_) mAuthor → Post (Right unit) pre []) → LBFT-weakestPre (isValidProposalM b) Post pre -- 1. `isValidProposalM` begins with `RWS-maybe`, so we must provide two cases: -- one where `b ^∙ bAuthor` is `nothing` and one where it is `just` -- something -- 2. When it is nothing, we appeal to the assumed proof proj₁ (contract pre Post pfNone pf≢ pfOk) mAuthor≡nothing = pfNone mAuthor≡nothing -- 3. When it is something, we step into `isValidProposerM`. This means: -- - we use the proposer election of the round manager (`pe` and `pe≡`) -- - we apply `isValidProposer` to `pe` (`isvp-pe` and `isvp-pe≡`) -- - we push the pure value `a` into the LBFT monad and apply `isvp-pe` to -- it (`.a`, `isvp-pe-a`, and `isvp-pe-a≡`) -- - we push the pure value `b ^∙ bRound` (`r` and `r≡`) into the LBFT -- monad, and the returned value is the result of applying `isvp-pe-a` to -- this -- - now out of `isValidProposalM`, we are given an alias `r'` for `r` -- > proj₂ (contract Post pre pfNone pf≢ pfOk) a ma≡just-a isvp isvp≡ pe pe≡ isvp-pe isvp-pe≡ .a refl isvp-pe-a isvp-pe-a≡ r r≡ r' r'≡ = {!!} -- 4. Since the returned value we want to reason about is directly related to -- the behavior of these bound functions which are partial applications of -- `isValidProposer`, we perform case-analysis on each of the equality -- proofs (we can't pattern match on `ma≡just-a` directly) -- > proj₂ (contract pre Post pfNone pf≢ pfOk) a ma≡just-a ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl = {!!} -- 5. Now we encounter an `ifD`, which means we must provide two cases, one corresponding to each branch. proj₁ (proj₂ (contract pre Post pfNone pf≢ pfOk) a ma≡just-a ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl) vp≡true -- 6. The types of `pfOk` and `pf≢` are still "stuck" on the expression -- > b ^∙ bAuthor -- So, in both the `false` and `true` cases we rewrite by `ma≡just-a`, which -- tells us that the result is `just a` rewrite ma≡just-a = -- 7. To finish, we use `toWitnessF` to convert between the two forms of evidence. pfOk (just (toWitnessT vp≡true)) proj₂ (proj₂ (contract pre Post pfNone pf≢ pfOk) a ma≡just-a ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl) vp≡false rewrite ma≡just-a = pf≢ (just (toWitnessF vp≡false))
52.8
143
0.67803
d1f056b83640613577e3bf019b661484ac5835e3
2,832
agda
Agda
core/lib/path-seq/Split.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
core/lib/path-seq/Split.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
core/lib/path-seq/Split.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 lib.Base open import lib.Function open import lib.PathFunctor open import lib.PathGroupoid open import lib.path-seq.Concat module lib.path-seq.Split {i} {A : Type i} where point-from-start : (n : ℕ) {a a' : A} (s : a =-= a') → A point-from-start O {a} s = a point-from-start (S n) {a = a} [] = a point-from-start (S n) (p ◃∙ s) = point-from-start n s drop : (n : ℕ) {a a' : A} (s : a =-= a') → point-from-start n s =-= a' drop 0 s = s drop (S n) [] = [] drop (S n) (p ◃∙ s) = drop n s tail : {a a' : A} (s : a =-= a') → point-from-start 1 s =-= a' tail = drop 1 private last1 : {a a' : A} (s : a =-= a') → A last1 {a = a} [] = a last1 {a = a} (p ◃∙ []) = a last1 (p ◃∙ s@(_ ◃∙ _)) = last1 s strip : {a a' : A} (s : a =-= a') → a =-= last1 s strip [] = [] strip (p ◃∙ []) = [] strip (p ◃∙ s@(_ ◃∙ _)) = p ◃∙ strip s point-from-end : (n : ℕ) {a a' : A} (s : a =-= a') → A point-from-end O {a} {a'} s = a' point-from-end (S n) s = point-from-end n (strip s) !- : (n : ℕ) {a a' : A} (s : a =-= a') → a =-= point-from-end n s !- O s = s !- (S n) s = !- n (strip s) take : (n : ℕ) {a a' : A} (s : a =-= a') → a =-= point-from-start n s take O s = [] take (S n) [] = [] take (S n) (p ◃∙ s) = p ◃∙ take n s private take-drop-split' : {a a' : A} (n : ℕ) (s : a =-= a') → s == take n s ∙∙ drop n s take-drop-split' O s = idp take-drop-split' (S n) [] = idp take-drop-split' (S n) (p ◃∙ s) = ap (λ v → p ◃∙ v) (take-drop-split' n s) abstract take-drop-split : {a a' : A} (n : ℕ) (s : a =-= a') → ↯ s ◃∎ =ₛ ↯ (take n s) ◃∙ ↯ (drop n s) ◃∎ take-drop-split n s = =ₛ-in $ ↯ s =⟨ ap ↯ (take-drop-split' n s) ⟩ ↯ (take n s ∙∙ drop n s) =⟨ ↯-∙∙ (take n s) (drop n s) ⟩ ↯ (take n s) ∙ ↯ (drop n s) =∎ private split : {a a' : A} (s : a =-= a') → Σ A (λ a'' → Σ (a =-= a'') (λ _ → a'' == a')) split {a = a} [] = (a , ([] , idp)) split {a = a} (p ◃∙ []) = (a , ([] , p)) split (p ◃∙ s@(_ ◃∙ _)) = let (a'' , (t , q)) = split s in (a'' , (p ◃∙ t) , q) point-from-end' : (n : ℕ) {a a' : A} (s : a =-= a') → A point-from-end' n {a = a} [] = a point-from-end' O (p ◃∙ s) = point-from-end' O s point-from-end' (S n) (p ◃∙ s) = point-from-end' n (fst (snd (split (p ◃∙ s)))) #- : (n : ℕ) {a a' : A} (s : a =-= a') → point-from-end' n s =-= a' #- n [] = [] #- O (p ◃∙ s) = #- O s #- (S n) (p ◃∙ s) = let (a' , (t , q)) = split (p ◃∙ s) in #- n t ∙▹ q infix 120 _!0 _!1 _!2 _!3 _!4 _!5 _!0 = !- 0 _!1 = !- 1 _!2 = !- 2 _!3 = !- 3 _!4 = !- 4 _!5 = !- 5 0! = drop 0 1! = drop 1 2! = drop 2 3! = drop 3 4! = drop 4 5! = drop 5 infix 120 _#0 _#1 _#2 _#3 _#4 _#5 _#0 = #- 0 _#1 = #- 1 _#2 = #- 2 _#3 = #- 3 _#4 = #- 4 _#5 = #- 5 0# = take 0 1# = take 1 2# = take 2 3# = take 3 4# = take 4 5# = take 5
24.842105
81
0.434322
64fb203ddbe0cd335ca4ed18fe51a4f04b9b7153
2,652
agda
Agda
TotalParserCombinators/Laws/AdditiveMonoid.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
1
2020-07-03T08:56:13.000Z
2020-07-03T08:56:13.000Z
TotalParserCombinators/Laws/AdditiveMonoid.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
TotalParserCombinators/Laws/AdditiveMonoid.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Laws related to _∣_ and fail ------------------------------------------------------------------------ module TotalParserCombinators.Laws.AdditiveMonoid where open import Algebra open import Codata.Musical.Notation import Data.List.Relation.Binary.BagAndSetEquality as Eq open import Data.Product using (proj₁; proj₂) open import Function private module BagMonoid {k} {A : Set} = CommutativeMonoid (Eq.commutativeMonoid k A) open import TotalParserCombinators.Derivative open import TotalParserCombinators.Congruence open import TotalParserCombinators.Parser ------------------------------------------------------------------------ -- _∣_ and fail form a commutative monoid -- This monoid is idempotent if language equivalence is used. commutative : ∀ {Tok R xs₁ xs₂} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → p₁ ∣ p₂ ≅P p₂ ∣ p₁ commutative {xs₁ = xs₁} {xs₂} p₁ p₂ = BagMonoid.comm xs₁ xs₂ ∷ λ t → ♯ commutative (D t p₁) (D t p₂) left-identity : ∀ {Tok R xs} (p : Parser Tok R xs) → fail ∣ p ≅P p left-identity {xs = xs} p = proj₁ BagMonoid.identity xs ∷ λ t → ♯ left-identity (D t p) right-identity : ∀ {Tok R xs} (p : Parser Tok R xs) → p ∣ fail ≅P p right-identity {xs = xs} p = proj₂ BagMonoid.identity xs ∷ λ t → ♯ right-identity (D t p) associative : ∀ {Tok R xs₁ xs₂ xs₃} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) (p₃ : Parser Tok R xs₃) → (p₁ ∣ p₂) ∣ p₃ ≅P p₁ ∣ (p₂ ∣ p₃) associative {xs₁ = xs₁} p₁ p₂ p₃ = BagMonoid.assoc xs₁ _ _ ∷ λ t → ♯ associative (D t p₁) (D t p₂) (D t p₃) -- Note that this law uses language equivalence, not parser -- equivalence. idempotent : ∀ {Tok R xs} (p : Parser Tok R xs) → p ∣ p ≈P p idempotent {xs = xs} p = Eq.++-idempotent xs ∷ λ t → ♯ idempotent (D t p) ------------------------------------------------------------------------ -- A lemma which can be convenient when proving distributivity laws swap : ∀ {Tok R xs₁ xs₂ xs₃ xs₄} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) (p₃ : Parser Tok R xs₃) (p₄ : Parser Tok R xs₄) → (p₁ ∣ p₂) ∣ (p₃ ∣ p₄) ≅P (p₁ ∣ p₃) ∣ (p₂ ∣ p₄) swap p₁ p₂ p₃ p₄ = (p₁ ∣ p₂) ∣ (p₃ ∣ p₄) ≅⟨ associative p₁ p₂ (p₃ ∣ p₄) ⟩ p₁ ∣ (p₂ ∣ (p₃ ∣ p₄)) ≅⟨ (p₁ ∎) ∣ ( p₂ ∣ (p₃ ∣ p₄) ≅⟨ sym $ associative p₂ p₃ p₄ ⟩ (p₂ ∣ p₃) ∣ p₄ ≅⟨ commutative p₂ p₃ ∣ (p₄ ∎) ⟩ (p₃ ∣ p₂) ∣ p₄ ≅⟨ associative p₃ p₂ p₄ ⟩ p₃ ∣ (p₂ ∣ p₄) ∎) ⟩ p₁ ∣ (p₃ ∣ (p₂ ∣ p₄)) ≅⟨ sym $ associative p₁ p₃ (p₂ ∣ p₄) ⟩ (p₁ ∣ p₃) ∣ (p₂ ∣ p₄) ∎
37.352113
72
0.532051
11ac00311439fc97b28680fce80c245c8522b95a
8,750
agda
Agda
examples/tactics/ac/AC.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/tactics/ac/AC.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/tactics/ac/AC.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --no-termination-check #-} module AC where import Nat import Bool import List import Fin import Logic import Vec import EqProof open Nat hiding (_<_) renaming (_==_ to _=Nat=_) open Bool open List hiding (module Eq) open Fin renaming (_==_ to _=Fin=_) open Logic open Vec infix 20 _○_ infix 10 _≡_ ForAll : {A : Set}(n : Nat) -> (Vec n A -> Set) -> Set ForAll zero F = F ε ForAll {A} (suc n) F = (x : A) -> ForAll _ \xs -> F (x ∷ xs) apply : {n : Nat}{A : Set}(F : Vec n A -> Set) -> ForAll n F -> (xs : Vec n A) -> F xs apply {zero} F t (vec vnil) = t apply {suc n} F f (vec (vcons x xs)) = apply _ (f x) xs lambda : {n : Nat}{A : Set}(F : Vec n A -> Set) -> ((xs : Vec n A) -> F xs) -> ForAll n F lambda {zero } F f = f ε lambda {suc n} F f = \x -> lambda _ (\xs -> f (x ∷ xs)) data Expr (n : Nat) : Set where zro : Expr n var : Fin n -> Expr n _○_ : Expr n -> Expr n -> Expr n data Theorem (n : Nat) : Set where _≡_ : Expr n -> Expr n -> Theorem n theorem : (n : Nat) -> ({m : Nat} -> ForAll {Expr m} n \_ -> Theorem m) -> Theorem n theorem n thm = apply _ thm (map var (fzeroToN-1 n)) module Provable where NF : Nat -> Set NF n = List (Fin n) infix 12 _⊕_ _⊕_ : {n : Nat} -> NF n -> NF n -> NF n [] ⊕ ys = ys x :: xs ⊕ [] = x :: xs x :: xs ⊕ y :: ys = if x < y then x :: (xs ⊕ y :: ys) else y :: (x :: xs ⊕ ys) normalise : {n : Nat} -> Expr n -> NF n normalise zro = [] normalise (var n) = n :: [] normalise (a ○ b) = normalise a ⊕ normalise b infix 30 _↓ _↓ : {n : Nat} -> NF n -> Expr n (i :: is) ↓ = var i ○ is ↓ [] ↓ = zro infix 10 _=Expr=_ _=NF=_ _=NF=_ : {n : Nat} -> NF n -> NF n -> Bool _=NF=_ = ListEq._==_ where module ListEq = List.Eq _=Fin=_ substNF : {n : Nat}{xs ys : NF n}(P : NF n -> Set) -> IsTrue (xs =NF= ys) -> P xs -> P ys substNF = List.Subst.subst _=Fin=_ (subst {_}) _=Expr=_ : {n : Nat} -> Expr n -> Expr n -> Bool a =Expr= b = normalise a =NF= normalise b provable : {n : Nat} -> Theorem n -> Bool provable (a ≡ b) = a =Expr= b module Semantics {A : Set} (_==_ : A -> A -> Set) (_*_ : A -> A -> A) (one : A) (refl : {x : A} -> x == x) (sym : {x y : A} -> x == y -> y == x) (trans : {x y z : A} -> x == y -> y == z -> x == z) (idL : {x : A} -> (one * x) == x) (idR : {x : A} -> (x * one) == x) (comm : {x y : A} -> (x * y) == (y * x)) (assoc : {x y z : A} -> (x * (y * z)) == ((x * y) * z)) (congL : {x y z : A} -> y == z -> (x * y) == (x * z)) (congR : {x y z : A} -> x == y -> (x * z) == (y * z)) where open Provable module EqP = EqProof _==_ refl trans open EqP expr[_] : {n : Nat} -> Expr n -> Vec n A -> A expr[ zro ] ρ = one expr[ var i ] ρ = ρ ! i expr[ a ○ b ] ρ = expr[ a ] ρ * expr[ b ] ρ eq[_] : {n : Nat} -> Theorem n -> Vec n A -> Set eq[ a ≡ b ] ρ = expr[ a ] ρ == expr[ b ] ρ data CantProve (A : Set) : Set where no-proof : CantProve A Prf : {n : Nat} -> Theorem n -> Bool -> Set Prf thm true = ForAll _ \ρ -> eq[ thm ] ρ Prf thm false = CantProve (Prf thm true) Proof : {n : Nat} -> Theorem n -> Set Proof thm = Prf thm (provable thm) lem0 : {n : Nat} -> (xs ys : NF n) -> (ρ : Vec n A) -> eq[ xs ↓ ○ ys ↓ ≡ (xs ⊕ ys) ↓ ] ρ lem0 [] ys ρ = idL lem0 (x :: xs) [] ρ = idR lem0 (x :: xs) (y :: ys) ρ = if' x < y then less else more where lhs = (var x ○ xs ↓) ○ (var y ○ ys ↓) lbranch = x :: (xs ⊕ y :: ys) rbranch = y :: (x :: xs ⊕ ys) P = \z -> eq[ lhs ≡ (if z then lbranch else rbranch) ↓ ] ρ less : IsTrue (x < y) -> _ less x<y = BoolEq.subst {true}{x < y} P x<y (spine (lem0 xs (y :: ys) ρ)) where spine : forall {x' xs' y' ys' zs} h -> _ spine {x'}{xs'}{y'}{ys'}{zs} h = eqProof> ((x' * xs') * (y' * ys')) === (x' * (xs' * (y' * ys'))) by sym assoc === (x' * zs) by congL h more : IsFalse (x < y) -> _ more x>=y = BoolEq.subst {false}{x < y} P x>=y (spine (lem0 (x :: xs) ys ρ)) where spine : forall {x' xs' y' ys' zs} h -> _ spine {x'}{xs'}{y'}{ys'}{zs} h = eqProof> ((x' * xs') * (y' * ys')) === ((y' * ys') * (x' * xs')) by comm === (y' * (ys' * (x' * xs'))) by sym assoc === (y' * ((x' * xs') * ys')) by congL comm === (y' * zs) by congL h lem1 : {n : Nat} -> (e : Expr n) -> (ρ : Vec n A) -> eq[ e ≡ normalise e ↓ ] ρ lem1 zro ρ = refl lem1 (var i) ρ = sym idR lem1 (a ○ b) ρ = trans step1 (trans step2 step3) where step1 : eq[ a ○ b ≡ normalise a ↓ ○ b ] ρ step1 = congR (lem1 a ρ) step2 : eq[ normalise a ↓ ○ b ≡ normalise a ↓ ○ normalise b ↓ ] ρ step2 = congL (lem1 b ρ) step3 : eq[ normalise a ↓ ○ normalise b ↓ ≡ (normalise a ⊕ normalise b) ↓ ] ρ step3 = lem0 (normalise a) (normalise b) ρ lem2 : {n : Nat} -> (xs ys : NF n) -> (ρ : Vec n A) -> IsTrue (xs =NF= ys) -> eq[ xs ↓ ≡ ys ↓ ] ρ lem2 xs ys ρ eq = substNF {_}{xs}{ys} (\z -> eq[ xs ↓ ≡ z ↓ ] ρ) eq refl prove : {n : Nat} -> (thm : Theorem n) -> Proof thm prove thm = proof (provable thm) thm (\h -> h) where proof : {n : Nat}(valid : Bool)(thm : Theorem n) -> (IsTrue valid -> IsTrue (provable thm)) -> Prf thm valid proof false _ _ = no-proof proof true (a ≡ b) isValid = lambda eq[ a ≡ b ] \ρ -> trans (step-a ρ) (trans (step-ab ρ) (step-b ρ)) where step-a : forall ρ -> eq[ a ≡ normalise a ↓ ] ρ step-a ρ = lem1 a ρ step-b : forall ρ -> eq[ normalise b ↓ ≡ b ] ρ step-b ρ = sym (lem1 b ρ) step-ab : forall ρ -> eq[ normalise a ↓ ≡ normalise b ↓ ] ρ step-ab ρ = lem2 (normalise a) (normalise b) ρ (isValid tt) n0 = zero n1 = suc n0 n2 = suc n1 n3 = suc n2 n4 = suc n3 n5 = suc n4 n6 = suc n5 n7 = suc n6 n8 = suc n7 n9 = suc n8 open Provable thmRefl = theorem n1 \x -> x ≡ x thmCom = theorem n2 \x y -> x ○ y ≡ y ○ x thm1 = theorem n3 \x y z -> x ○ (y ○ z) ≡ (z ○ y) ○ x thm2 = theorem n3 \x y z -> x ○ (y ○ z) ≡ (z ○ x) ○ x thm3 = theorem n5 \a b c d e -> (a ○ (a ○ b)) ○ ((c ○ d) ○ (e ○ e)) ≡ b ○ ((e ○ (c ○ a)) ○ (d ○ (e ○ a))) infix 10 _===_ data _===_ (n m : Nat) : Set where eqn : IsTrue (n =Nat= m) -> n === m postulate refl : {x : Nat} -> x === x sym : {x y : Nat} -> x === y -> y === x trans : {x y z : Nat} -> x === y -> y === z -> x === z idL : {x : Nat} -> (zero + x) === x idR : {x : Nat} -> (x + zero) === x comm : {x y : Nat} -> (x + y) === (y + x) assoc : {x y z : Nat} -> (x + (y + z)) === ((x + y) + z) congL : {x y z : Nat} -> y === z -> x + y === x + z congR : {x y z : Nat} -> x === y -> x + z === y + z module NatPlus = Semantics _===_ _+_ zero refl sym trans idL idR (\{x}{y} -> comm {x}{y}) (\{x}{y}{z} -> assoc {x}{y}{z}) (\{x} -> congL {x}) (\{_}{_}{z} -> congR {z = z}) open NatPlus test : (x y z : Nat) -> x + (y + z) === (z + x) + y test = prove (theorem n3 \x y z -> x ○ (y ○ z) ≡ (z ○ x) ○ y) {- _437 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 -> lem0 (x15 :: x16) x18 x19 | [ (expr[ ((x :: xs) ↓ ○ ys ↓) ]) ρ == (expr[ ((x :: xs ⊕ ys) ↓) ]) ρ = _395 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x>=y (ρ ! x) ((expr[ (xs ↓) ]) ρ) (ρ ! y) ((expr[ (ys ↓) ]) ρ) ((expr[ ((x :: xs ⊕ ys) ↓) ]) ρ) : Set ] _428 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 -> x26 | [ _395 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x>=y x xs y ys zs = x * xs * ys == zs : Set ] _364 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 -> lem0 x16 (x17 :: x18) x19 | [(expr[ (xs ↓ ○ (y :: ys) ↓) ]) ρ == (expr[ ((xs ⊕ y :: ys) ↓) ]) ρ = _337 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x<y (ρ ! x) ((expr[ (xs ↓) ]) ρ) (ρ ! y) ((expr[ (ys ↓) ]) ρ) ((expr[ ((xs ⊕ y :: ys) ↓) ]) ρ) : Set] _355 := \x' x'' x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 -> x26 | [_337 A _==_ _*_ one refl sym trans idL idR comm assoc congL congR _n x xs y ys ρ x<y x xs y ys zs = xs * (y * ys) == zs : Set] -}
33.524904
167
0.447429
34652779581fa0b66b80f0c72ca7bd511fe08233
61
agda
Agda
src/Isos/Isomorphism.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
1
2020-04-15T15:28:03.000Z
2020-04-15T15:28:03.000Z
src/Isos/Isomorphism.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
null
null
null
src/Isos/Isomorphism.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
null
null
null
module Isos.Isomorphism where open import Logics.And public
15.25
29
0.836066
65166c38d671156d6200935c6d25cde95a795e26
13,063
agda
Agda
complexity/complexity-final/submit/Bounding.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
2
2016-04-26T20:22:22.000Z
2019-08-08T12:27:18.000Z
complexity/complexity-final/submit/Bounding.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
1
2020-03-23T08:39:04.000Z
2020-05-12T00:32:45.000Z
complexity/complexity-final/submit/Bounding.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
null
null
null
{- PROOF OF BOUNDING THEOREM WITH NEW COMPLEXITY LANGUAGE -} open import Preliminaries open import Source open import Complexity open import Translation open import Bounding-Lemmas module Bounding where boundingRec : ∀ {τ} (v : [] Source.|- nat) (val-v : val v) (e0 : [] Source.|- τ) (e1 : (nat :: susp τ :: []) Source.|- τ) (E : [] Complexity.|- nat) (E0 : [] Complexity.|- || τ ||) (E1 : (nat :: || τ || :: []) Complexity.|- || τ ||) → valBound v val-v E → expBound e0 E0 → ((v' : [] Source.|- nat) (val-v' : val v') (E' : [] Complexity.|- nat) → valBound v' val-v' E' → (r : [] Source.|- susp τ) (val-r : val r) (R : [] Complexity.|- || τ ||) → valBound r val-r R → expBound (Source.subst e1 (Source.lem4 v' r)) (Complexity.subst E1 (Complexity.lem4 E' R))) → ((vbranch : [] Source.|- τ) (val-vbranch : val vbranch) (nbranch : Cost) → evals-rec-branch e0 e1 v vbranch nbranch → (plusC 1C (interp-Cost nbranch) ≤s l-proj (rec E (1C +C E0) (1C +C E1)) × (valBound vbranch val-vbranch (r-proj (rec E (1C +C E0) (1C +C E1)))))) boundingRec .z z-isval e0 e1 E E0 E1 vbound e0bound e1bound vbranch val-vbranch nbranch (evals-rec-z evals-branch) = (cong-+ refl-s (fst usee0bound ) trans l-proj-s) trans cong-lproj (rec-steps-z trans cong-rec vbound) , weakeningVal' val-vbranch (snd usee0bound) (r-proj-s trans cong-rproj (rec-steps-z trans (cong-rec (vbound)))) where usee0bound = (e0bound vbranch val-vbranch nbranch evals-branch) boundingRec .(suc v') (suc-isval v' val-v') e0 e1 E E0 E1 (E' , v'bound , sucE'≤E) e0bound e1bound vbranch val-vbranch nbranch (evals-rec-s evals-branch) = (cong-+ refl-s (fst usee1bound) trans l-proj-s) trans cong-lproj (rec-steps-s trans cong-rec sucE'≤E) , weakeningVal' val-vbranch (snd usee1bound) (r-proj-s trans cong-rproj (rec-steps-s trans cong-rec sucE'≤E)) where IH = boundingRec v' val-v' e0 e1 E' E0 E1 v'bound e0bound e1bound usee1bound = e1bound v' val-v' E' v'bound (delay (rec v' e0 e1)) (delay-isval _) (rec E' (1C +C E0) (1C +C E1) ) (λ { vr vvr ._ (rec-evals{n1 = n1} {n2 = n2} D D') → let useIH = IH vr vvr n2 (transport (λ H → evals-rec-branch e0 e1 H vr n2) (! (fst (val-evals-inversion val-v' D))) D') in (cong-+ (Eq0C-≤0 (snd (val-evals-inversion val-v' D))) refl-s trans +-unit-l) trans fst useIH , snd useIH } ) vbranch val-vbranch nbranch evals-branch boundingListRec : ∀ {τ τ'} (v : [] Source.|- list τ') (vv : val v) (e0 : [] Source.|- τ) (e1 : τ' :: list τ' :: susp τ :: [] Source.|- τ) (E : [] Complexity.|- list ⟨⟨ τ' ⟩⟩) (E0 : [] Complexity.|- || τ ||) (E1 : ⟨⟨ τ' ⟩⟩ :: list ⟨⟨ τ' ⟩⟩ :: || τ || :: [] Complexity.|- || τ ||) → valBound v vv E → expBound e0 E0 → ((h' : [] Source.|- τ') (vh' : val h') (H' : [] Complexity.|- ⟨⟨ τ' ⟩⟩) → valBound h' vh' H' → (v' : [] Source.|- list τ') (vv' : val v') (V' : [] Complexity.|- list ⟨⟨ τ' ⟩⟩) → valBound v' vv' V' → (r : [] Source.|- susp τ) (vr : val r) (R : [] Complexity.|- || τ ||) → valBound r vr R → expBound (Source.subst e1 (Source.lem5 h' v' r)) (Complexity.subst E1 (Complexity.lem5 H' V' R))) → (vbranch : [] Source.|- τ) (vvbranch : val vbranch) (nbranch : Cost) → evals-listrec-branch e0 e1 v vbranch nbranch → plusC 1C (interp-Cost nbranch) ≤s l-proj (listrec E (1C +C E0) (1C +C E1)) × valBound vbranch vvbranch (r-proj (listrec E (1C +C E0) (1C +C E1))) boundingListRec .nil nil-isval e0 e1 E E0 E1 vbv e0b e1b vbranch vvbranch n (evals-listrec-nil evals-branch) = ((cong-+ refl-s (fst usee0bound) trans l-proj-s) trans cong-lproj (listrec-steps-nil trans cong-listrec vbv)) , weakeningVal' vvbranch (snd usee0bound) (r-proj-s trans cong-rproj (listrec-steps-nil trans cong-listrec vbv)) where usee0bound = e0b vbranch vvbranch n evals-branch boundingListRec .(x ::s xs) (cons-isval x xs vv vv₁) e0 e1 E E0 E1 (h' , t' , (vbxh' , vbxst') , h'::t'≤sE) e0b e1b vbranch vvbranch nbranch (evals-listrec-cons evals-branch) = (cong-+ refl-s (fst usee1bound) trans l-proj-s) trans cong-lproj (listrec-steps-cons trans cong-listrec h'::t'≤sE) , weakeningVal' vvbranch (snd usee1bound) (r-proj-s trans cong-rproj (listrec-steps-cons trans cong-listrec h'::t'≤sE)) where IH = boundingListRec xs vv₁ e0 e1 t' E0 E1 vbxst' e0b e1b usee1bound = e1b x vv h' vbxh' xs vv₁ t' vbxst' (delay (listrec xs e0 e1)) (delay-isval _) (listrec t' (1C +C E0) (1C +C E1)) (λ { vr vvr ._ (listrec-evals {_} {n2} D D') → let useIH = IH vr vvr n2 (transport (λ H → evals-listrec-branch e0 e1 H vr n2) (! (fst (val-evals-inversion vv₁ D))) D') in (cong-+ (Eq0C-≤0 (snd (val-evals-inversion vv₁ D))) refl-s trans +-unit-l) trans fst useIH , snd useIH } ) vbranch vvbranch nbranch evals-branch bounding : ∀{Γ τ} → (e : Γ Source.|- τ) → (Θ : Source.sctx [] Γ) → (a : substVal Θ) → (Θ' : Complexity.sctx [] ⟨⟨ Γ ⟩⟩c) → substBound Θ a Θ' → expBound (Source.subst e Θ) (Complexity.subst || e ||e Θ') bounding unit Θ a Θ' sb .unit unit-isval .0c unit-evals = l-proj-s , <> bounding (var x) Θ a Θ' sb v vv c evals = inv1 (a x) evals trans l-proj-s , weakeningVal' vv (transport-valBound (inv2 (a x) evals) (val-hprop (transport val (inv2 (a x) evals) (a x)) vv) _ (sb x)) r-proj-s bounding z Θ a Θ' sb .z z-isval .0c z-evals = l-proj-s , r-proj-s bounding (suc e) Θ a Θ' sb .(suc e₁) (suc-isval e₁ vv) n (s-evals evals) = fst IH trans l-proj-s , (r-proj (Complexity.subst || e ||e Θ')) , (snd IH) , r-proj-s where IH = (bounding e Θ a Θ' sb _ vv _ evals) bounding (rec e e₁ e₂) Θ a Θ' sb e' val-e' ._ (rec-evals {v = v} arg-evals branch-evals) = cong-+ (fst IH1) (fst lemma) trans l-proj-s , weakeningVal' val-e' (snd lemma) r-proj-s where IH1 = bounding e Θ a Θ' sb _ (evals-val arg-evals) _ arg-evals lemma = boundingRec v (evals-val arg-evals) _ (Source.subst e₂ (Source.s-extend (Source.s-extend Θ))) _ _ (Complexity.subst || e₂ ||e (Complexity.s-extend (Complexity.s-extend Θ'))) (snd IH1) (bounding e₁ Θ a Θ' sb ) (λ v' valv' E' valBoundv' r valr R valBoundR v'' valv'' c'' evals-rec → let IH3 = (bounding e₂ (Source.lem4' Θ v' r) (extend-substVal2 a valv' valr) (Complexity.lem4' Θ' E' R) (extend-substBound2 sb valBoundv' valBoundR) v'' valv'' c'' (transport (λ x → evals x v'' c'') (Source.subst-compose4 Θ v' r e₂) evals-rec)) in (fst IH3 trans cong-lproj (subst-compose4-r Θ' E' R || e₂ ||e)) , weakeningVal' valv'' (snd IH3) (cong-rproj (subst-compose4-r Θ' E' R || e₂ ||e))) e' val-e' _ branch-evals bounding (lam e) Θ a Θ' sb .(lam (Source.subst e (Source.s-extend Θ))) (lam-isval .(Source.subst e (Source.s-extend Θ))) .0c lam-evals = l-proj-s , (λ v₁ vv₁ E1 valbound1 v vv n body-evals → let IH : _ IH = bounding e (Source.lem3' Θ v₁) (extend-substVal a vv₁) (Complexity.lem3' Θ' E1) (extend-substBound sb valbound1) v vv n (transport (λ x → evals x v n) (subst-compose Θ v₁ e) body-evals) in fst IH trans cong-lproj (subst-compose-r Θ' E1 || e ||e trans lam-s trans cong-app r-proj-s) , weakeningVal' vv (snd IH) (cong-rproj (subst-compose-r Θ' E1 || e ||e trans lam-s trans cong-app r-proj-s))) bounding (app e1 e2) Θ a Θ' sb v val-v .((n0 +c n1) +c n) (app-evals {n0} {n1} {n} {τ2} {τ} {.(Source.subst e1 Θ)} {e1'} {.(Source.subst e2 Θ)} {v2} e1-evals e2-evals subst-evals) = cong-+ (cong-+ (fst IH1 trans +-unit-l' trans cong-+ lt (cong-lproj refl-s)) (fst IH2)) (fst IH1a) trans l-proj-s , --cong-+ (cong-+ (fst IH1) (fst IH2)) (fst IH1a) trans l-proj-s , weakeningVal' val-v (snd IH1a) r-proj-s where IH1 = (bounding e1 Θ a Θ' sb (lam e1') (lam-isval e1') n0 e1-evals) v2-val = evals-val e2-evals IH2 = (bounding e2 Θ a Θ' sb v2 v2-val n1 e2-evals) IH1a = snd IH1 v2 v2-val (r-proj (Complexity.subst || e2 ||e Θ')) (snd IH2) v val-v n subst-evals bounding {Γ} {τ1 ×s τ2} (prod e1 e2) Θ a Θ' sb .(prod e3 e4) (pair-isval e3 e4 val-e3 val-e4) .(n1 +c n2) (pair-evals {n1} {n2} evals-c1 evals-c2) = cong-+ (fst IH1) (fst IH2) trans l-proj-s , weakeningVal' val-e3 (snd IH1) (l-proj-s trans cong-lproj r-proj-s) , weakeningVal' val-e4 (snd IH2) (r-proj-s trans cong-rproj r-proj-s) where IH1 = (bounding e1 Θ a Θ' sb _ val-e3 _ evals-c1) IH2 = (bounding e2 Θ a Θ' sb _ val-e4 _ evals-c2) bounding (delay e) Θ a Θ' sb .(delay (Source.subst e Θ)) (delay-isval .(Source.subst e Θ)) .0c delay-evals = l-proj-s , (λ v₁ vv n x → let IH = bounding e Θ a Θ' sb v₁ vv n x in fst IH trans cong-lproj (r-proj-s trans refl-s) , weakeningVal' vv (snd IH) (cong-rproj r-proj-s)) bounding (force e) Θ a Θ' sb v vv ._ (force-evals {n1} {n2} {τ} {e'} {.v} {.(Source.subst e Θ)} evals evals₁) = (cong-+ (fst IH) (fst (snd IH v vv n2 evals₁)) trans l-proj-s) , weakeningVal' vv (snd (snd IH v vv n2 evals₁)) r-proj-s where IH = (bounding e Θ a Θ' sb _ (delay-isval e') n1 evals) bounding {Γ} {τ} (split e0 e1) Θ a Θ' sb e' val-e' .(n1 +c n2) (split-evals {n1} {n2} {.τ} {τ1} {τ2} {.(Source.subst e0 Θ)} {v1} {v2} evals-in-c0 evals-in-c1) with evals-val evals-in-c0 | (bounding e0 Θ a Θ' sb (prod v1 v2) (evals-val evals-in-c0) _ evals-in-c0) ... | pair-isval ._ ._ val-v1 val-v2 | (IH11 , vb1 , vb2) = (cong-+ IH11 (fst IH2) trans cong-+ refl-s (cong-lproj (subst-compose3-r Θ' || e1 ||e (l-proj (r-proj || e0 ||e)) (r-proj (r-proj || e0 ||e))))) trans l-proj-s , weakeningVal' val-e' (snd IH2) (cong-rproj (subst-compose3-r Θ' || e1 ||e (l-proj (r-proj || e0 ||e)) (r-proj (r-proj || e0 ||e))) trans r-proj-s) where IH2 = bounding e1 (Source.lem4' Θ v1 v2) (extend-substVal2 a val-v1 val-v2) (Complexity.lem4' Θ' (l-proj (r-proj (Complexity.subst || e0 ||e Θ'))) (r-proj (r-proj (Complexity.subst || e0 ||e Θ')))) (extend-substBound2 sb vb1 vb2) e' val-e' n2 (transport (λ x → evals x e' n2) (Source.subst-compose3 Θ e1 v1 v2) evals-in-c1) bounding nil Θ a Θ' sb .nil nil-isval .0c nil-evals = l-proj-s , r-proj-s bounding (e ::s e₁) Θ a Θ' sb .(x ::s xs) (cons-isval x xs vv vv₁) ._ (cons-evals evals evals₁) = (cong-+ (fst IH1) (fst IH2) trans l-proj-s) , (r-proj (Complexity.subst || e ||e Θ')) , r-proj (Complexity.subst || e₁ ||e Θ') , ((snd IH1 , snd IH2) , r-proj-s) where IH1 = (bounding e Θ a Θ' sb _ vv _ evals) IH2 = (bounding e₁ Θ a Θ' sb _ vv₁ _ evals₁) bounding (listrec e e₁ e₂) Θ a Θ' sb v vv ._ (listrec-evals {v = k} arg-evals branch-evals) = (cong-+ (fst IH1) (fst lemma) trans l-proj-s) , weakeningVal' vv (snd lemma) r-proj-s where IH1 = bounding e Θ a Θ' sb _ (evals-val arg-evals) _ arg-evals lemma = boundingListRec k (evals-val arg-evals) _ (Source.subst e₂ (Source.s-extend (Source.s-extend (Source.s-extend Θ)))) _ _ (Complexity.subst || e₂ ||e (Complexity.s-extend (Complexity.s-extend (Complexity.s-extend Θ')))) (snd IH1) (bounding e₁ Θ a Θ' sb) (λ h' vh' H' vbh'H' v' vv' V' vbv'V' r vr R vbrR v₁ vv₁ n x₂ → let IH3 = bounding e₂ (Source.lem5' Θ h' v' r) (extend-substVal3 a vh' vv' vr) (Complexity.lem5' Θ' H' V' R) (extend-substBound3 sb vbh'H' vbv'V' vbrR) v₁ vv₁ n (transport (λ x → evals x v₁ n) (Source.subst-compose5 Θ e₂ h' v' r) x₂) in fst IH3 trans cong-lproj (subst-compose5-r Θ' || e₂ ||e H' V' R) , weakeningVal' vv₁ (snd IH3) (cong-rproj (subst-compose5-r Θ' || e₂ ||e H' V' R))) v vv _ branch-evals bounding true Θ a Θ' sb .true true-isval .0c true-evals = l-proj-s , r-proj-s bounding false Θ a Θ' sb .false false-isval .0c false-evals = l-proj-s , r-proj-s
73.38764
264
0.543061
64ffafbf264c95d07025c612e5d995e0b904c1dc
4,240
agda
Agda
Cubical/Algebra/Group/QuotientGroup.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/Algebra/Group/QuotientGroup.agda
snu-development/cubical
58f2d0dd07e51f8aa5b348a522691097b6695d1c
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/QuotientGroup.agda
snu-development/cubical
58f2d0dd07e51f8aa5b348a522691097b6695d1c
[ "MIT" ]
null
null
null
{- This file contains quotient groups -} {-# OPTIONS --safe #-} module Cubical.Algebra.Group.QuotientGroup where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Structure open import Cubical.Foundations.Powerset open import Cubical.Foundations.GroupoidLaws hiding (assoc) open import Cubical.Data.Sigma open import Cubical.HITs.SetQuotients.Base renaming (_/_ to _/s_) open import Cubical.HITs.SetQuotients.Properties open import Cubical.Relation.Binary.Base open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Subgroup private variable ℓ : Level module _ (G' : Group ℓ) (H' : Subgroup G') (Hnormal : isNormal H') where open BinaryRelation open isSubgroup (snd H') open GroupStr (snd G') open GroupTheory G' private G = ⟨ G' ⟩ _~_ : G → G → Type ℓ x ~ y = x · inv y ∈ ⟪ H' ⟫ isRefl~ : isRefl _~_ isRefl~ x = subst-∈ ⟪ H' ⟫ (sym (invr x)) id-closed G/H : Type ℓ G/H = G /s _~_ 1/H : G/H 1/H = [ 1g ] _·/H_ : G/H → G/H → G/H x ·/H y = setQuotBinOp isRefl~ isRefl~ _·_ rem x y where rem : (a a' b b' : G) → a · inv a' ∈ ⟪ H' ⟫ → b · inv b' ∈ ⟪ H' ⟫ → (a · b) · inv (a' · b') ∈ ⟪ H' ⟫ rem a a' b b' haa' hbb' = subst-∈ ⟪ H' ⟫ (cong (_ ·_) (sym (invDistr _ _))) rem5 where rem1 : (inv a' · a) · b · inv b' ∈ ⟪ H' ⟫ rem1 = ·CommNormalSubgroup H' Hnormal (op-closed hbb' (·CommNormalSubgroup H' Hnormal haa')) rem2 : ((inv a' · a) · b) · inv b' ∈ ⟪ H' ⟫ rem2 = subst-∈ ⟪ H' ⟫ (assoc _ _ _) rem1 rem3 : inv b' · (inv a' · a) · b ∈ ⟪ H' ⟫ rem3 = ·CommNormalSubgroup H' Hnormal rem2 rem4 : (inv b' · inv a') · (a · b) ∈ ⟪ H' ⟫ rem4 = subst-∈ ⟪ H' ⟫ (cong (inv b' ·_) (sym (assoc _ _ _)) ∙ assoc _ _ _) rem3 rem5 : (a · b) · inv b' · inv a' ∈ ⟪ H' ⟫ rem5 = ·CommNormalSubgroup H' Hnormal rem4 inv/H : G/H → G/H inv/H = setQuotUnaryOp inv rem where rem : (a a' : G) → a · inv a' ∈ ⟪ H' ⟫ → inv a · inv (inv a') ∈ ⟪ H' ⟫ rem a a' haa' = subst-∈ ⟪ H' ⟫ (cong (inv a ·_) (sym (invInv a'))) rem1 where ha'a : a' · inv a ∈ ⟪ H' ⟫ ha'a = subst-∈ ⟪ H' ⟫ (invDistr a (inv a') ∙ cong (_· inv a) (invInv a')) (inv-closed haa') rem1 : inv a · a' ∈ ⟪ H' ⟫ rem1 = ·CommNormalSubgroup H' Hnormal ha'a ·/H-assoc : (a b c : G/H) → (a ·/H (b ·/H c)) ≡ ((a ·/H b) ·/H c) ·/H-assoc = elimProp3 (λ x y z → squash/ _ _) λ x y z → cong [_] (assoc x y z) ·/H-rid : (a : G/H) → (a ·/H 1/H) ≡ a ·/H-rid = elimProp (λ x → squash/ _ _) λ x → cong [_] (rid x) ·/H-invr : (a : G/H) → (a ·/H inv/H a) ≡ 1/H ·/H-invr = elimProp (λ x → squash/ _ _) λ x → cong [_] (invr x) asGroup : Group ℓ asGroup = makeGroup-right 1/H _·/H_ inv/H squash/ ·/H-assoc ·/H-rid ·/H-invr _/_ : (G : Group ℓ) → (H : NormalSubgroup G) → Group ℓ G / H = asGroup G (H .fst) (H .snd) [_]/G : {G : Group ℓ} {H : NormalSubgroup G} → ⟨ G ⟩ → ⟨ G / H ⟩ [ x ]/G = [ x ] -- Quotienting by a trivial subgroup module _ {G' : Group ℓ} (H' : NormalSubgroup G') (contrH : (x y : fst G') → _~_ G' (fst H') (snd H') x y → x ≡ y) where private -- open isSubgroup (snd H') open GroupStr (snd G') open GroupTheory G' G = fst G' G/H' = fst (G' / H') Code : (g : G) → G/H' → hProp ℓ Code g = elim (λ _ → isSetHProp) (λ a → (g ≡ a) , is-set _ _) λ a b r → Σ≡Prop (λ _ → isPropIsProp) (cong (g ≡_) (contrH a b r)) decode : (g : G) (x : G/H') → [ g ] ≡ x → Code g x .fst decode g x = J (λ x _ → Code g x .fst) refl trivialRel→elimPath : {g h : G} → Path G/H' [ g ] [ h ] → g ≡ h trivialRel→elimPath {g = g} {h = h} = decode g [ h ] trivialRelIso : GroupIso G' (G' / H') Iso.fun (fst trivialRelIso) g = [ g ] Iso.inv (fst trivialRelIso) = rec is-set (λ g → g) contrH Iso.rightInv (fst trivialRelIso) = elimProp (λ _ → squash/ _ _) λ _ → refl Iso.leftInv (fst trivialRelIso) _ = refl snd trivialRelIso = makeIsGroupHom λ _ _ → refl
30.724638
97
0.556604
fd3b5b2de495af2b26169e3dc480bd278a2df4bb
3,159
agda
Agda
proofs/AKS/Binary/Base.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
1
2020-12-01T22:38:27.000Z
2020-12-01T22:38:27.000Z
proofs/AKS/Binary/Base.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
null
null
null
proofs/AKS/Binary/Base.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
null
null
null
open import Relation.Nullary.Decidable using (False) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong; module ≡-Reasoning) open import Data.List using (List) open List open import Data.Unit using (tt) module AKS.Binary.Base where open import Polynomial.Simple.AlmostCommutativeRing using (AlmostCommutativeRing) open import Polynomial.Simple.AlmostCommutativeRing.Instances using (module Nat) open Nat.Reflection using (∀⟨_⟩) open import AKS.Nat using (ℕ; _+_; _*_; _≟_; _<_; lte; suc-mono-≤) open ℕ open import AKS.Nat using (ℕ⁺; ℕ+; ⟅_⇑⟆) open import AKS.Nat using (Euclidean; Euclidean✓; _div_) open import AKS.Nat using (Acc; acc; <-well-founded) 2* : ℕ → ℕ 2* n = n + n infixl 5 _0ᵇ _1ᵇ data 𝔹⁺ : Set where 𝕓1ᵇ : 𝔹⁺ _0ᵇ _1ᵇ : 𝔹⁺ → 𝔹⁺ infixr 4 +_ data 𝔹 : Set where 𝕓0ᵇ : 𝔹 +_ : 𝔹⁺ → 𝔹 ⟦_⇓⟧⁺ : 𝔹⁺ → ℕ ⟦ 𝕓1ᵇ ⇓⟧⁺ = 1 ⟦ x 0ᵇ ⇓⟧⁺ = 2* ⟦ x ⇓⟧⁺ ⟦ x 1ᵇ ⇓⟧⁺ = 1 + 2* ⟦ x ⇓⟧⁺ ⟦_⇓⟧ : 𝔹 → ℕ ⟦ 𝕓0ᵇ ⇓⟧ = 0 ⟦ + x ⇓⟧ = ⟦ x ⇓⟧⁺ private lemma₁ : ∀ {q} → suc q < suc (q + suc (q + zero)) lemma₁ {q} = lte q (∀⟨ q ∷ [] ⟩) lemma₂ : ∀ {q} → suc q < suc (suc (q + suc (q + zero))) lemma₂ {q} = lte (suc q) (∀⟨ q ∷ [] ⟩) ⟦_⇑_⟧ʰ : ∀ n → Acc _<_ n → ∀ {≢0 : False (n ≟ 0)} → 𝔹⁺ ⟦ suc n ⇑ acc downward ⟧ʰ with suc n div 2 ... | Euclidean✓ (suc q) 0 refl r<m = ⟦ suc q ⇑ downward lemma₁ ⟧ʰ 0ᵇ ... | Euclidean✓ zero 1 refl r<m = 𝕓1ᵇ ... | Euclidean✓ (suc q) 1 refl r<m = ⟦ suc q ⇑ downward lemma₂ ⟧ʰ 1ᵇ ⟦_⇑⟧⁺ : ℕ⁺ → 𝔹⁺ ⟦ ℕ+ n ⇑⟧⁺ = ⟦ suc n ⇑ <-well-founded ⟧ʰ ⟦_⇑⟧ : ℕ → 𝔹 ⟦ zero ⇑⟧ = 𝕓0ᵇ ⟦ suc n ⇑⟧ = + ⟦ ℕ+ n ⇑⟧⁺ ℕ→𝔹→ℕ : ∀ n → ⟦ ⟦ n ⇑⟧ ⇓⟧ ≡ n ℕ→𝔹→ℕ zero = refl ℕ→𝔹→ℕ (suc n) = ℕ⁺→𝔹⁺→ℕ (suc n) <-well-founded where ℕ⁺→𝔹⁺→ℕ : ∀ (n : ℕ) (rec : Acc _<_ n) {≢0 : False (n ≟ 0)} → ⟦ ⟦ n ⇑ rec ⟧ʰ {≢0} ⇓⟧⁺ ≡ n ℕ⁺→𝔹⁺→ℕ (suc n) (acc downward) with suc n div 2 ... | Euclidean✓ (suc q) 0 refl r<m rewrite ℕ⁺→𝔹⁺→ℕ (suc q) (downward lemma₁) {tt} = ∀⟨ q ∷ [] ⟩ ... | Euclidean✓ zero 1 refl r<m = refl ... | Euclidean✓ (suc q) 1 refl r<m rewrite ℕ⁺→𝔹⁺→ℕ (suc q) (downward lemma₂) {tt} = ∀⟨ q ∷ [] ⟩ ⌈log₂_⌉⁺ : 𝔹⁺ → ℕ ⌈log₂ 𝕓1ᵇ ⌉⁺ = 1 ⌈log₂ (b 0ᵇ) ⌉⁺ = 1 + ⌈log₂ b ⌉⁺ ⌈log₂ (b 1ᵇ) ⌉⁺ = 1 + ⌈log₂ b ⌉⁺ ⌈log₂_⌉ : 𝔹 → ℕ ⌈log₂ 𝕓0ᵇ ⌉ = 0 ⌈log₂ + b ⌉ = ⌈log₂ b ⌉⁺ ⌊_/2⌋⁺ : 𝔹⁺ → 𝔹⁺ ⌊ 𝕓1ᵇ /2⌋⁺ = 𝕓1ᵇ ⌊ b 0ᵇ /2⌋⁺ = b ⌊ b 1ᵇ /2⌋⁺ = b ⌊_/2⌋ : 𝔹 → 𝔹 ⌊ 𝕓0ᵇ /2⌋ = 𝕓0ᵇ ⌊ + b /2⌋ = + ⌊ b /2⌋⁺ -- _+ᵇ_ : 𝔹 → 𝔹 → 𝔹 -- n +ᵇ m = ⟦ ⟦ n ⇓⟧ + ⟦ m ⇓⟧ ⇑⟧ -- -- data Bit : Set where -- -- 0𝑏 : Bit -- -- 1𝑏 : Bit -- -- _+ᵇ⁺_ : 𝔹⁺ → 𝔹⁺ → 𝔹⁺ -- -- n +ᵇ⁺ m = ⟦ ⟦ n ⇓⟧⁺ ⇑⟧⁺ -- -- where -- -- loop : Bit → 𝔹⁺ → 𝔹⁺ → 𝔹⁺ -- -- loop carry x y = ? -- -- unique⁺ : ∀ x y → ⟦ x ⇓⟧⁺ ≡ ⟦ y ⇓⟧⁺ → x ≡ y -- -- unique⁺ 1ᵇ 1ᵇ p = refl -- -- unique⁺ 1ᵇ (y 0ᵇ) p = {!!} -- -- unique⁺ 1ᵇ (y 1ᵇ) p = {!!} -- -- unique⁺ (x 0ᵇ) 1ᵇ p = {!!} -- -- unique⁺ (x 0ᵇ) (y 0ᵇ) p = {!!} -- -- unique⁺ (x 0ᵇ) (y 1ᵇ) p = {!!} -- -- unique⁺ (x 1ᵇ) y p = {!!} -- -- unique : ∀ x y → ⟦ x ⇓⟧ ≡ ⟦ y ⇓⟧ → x ≡ y -- -- unique 𝕓0ᵇ 𝕓0ᵇ p = refl -- -- unique 𝕓0ᵇ (𝕓 y) p = {!!} -- -- unique (𝕓 x) 𝕓0ᵇ p = {!!} -- -- unique (𝕓 x) (𝕓 y) p = {!!} module Test where eval-unit₁ : ⟦ + 𝕓1ᵇ 0ᵇ 1ᵇ 0ᵇ ⇓⟧ ≡ 10 eval-unit₁ = refl log-unit₁ : ⌈log₂ ⟦ 15 ⇑⟧ ⌉ ≡ 4 log-unit₁ = refl
25.682927
98
0.487496
a03befdb39687319415e2d3324b51561f279d4f4
1,766
agda
Agda
agda-stdlib/src/Data/Vec/Membership/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Vec/Membership/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Vec/Membership/Setoid.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Membership of vectors, along with some additional definitions. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Setoid; _Respects_) module Data.Vec.Membership.Setoid {c ℓ} (S : Setoid c ℓ) where open import Function open import Data.Vec.Base as Vec using (Vec; []; _∷_) open import Data.Vec.Relation.Unary.Any as Any using (Any; here; there; index) open import Data.Product using (∃; _×_; _,_) open import Relation.Nullary using (¬_) open import Relation.Unary using (Pred) open Setoid S renaming (Carrier to A) ------------------------------------------------------------------------ -- Definitions infix 4 _∈_ _∉_ _∈_ : A → ∀ {n} → Vec A n → Set _ x ∈ xs = Any (x ≈_) xs _∉_ : A → ∀ {n} → Vec A n → Set _ x ∉ xs = ¬ x ∈ xs ------------------------------------------------------------------------ -- Operations mapWith∈ : ∀ {b} {B : Set b} {n} (xs : Vec A n) → (∀ {x} → x ∈ xs → B) → Vec B n mapWith∈ [] f = [] mapWith∈ (x ∷ xs) f = f (here refl) ∷ mapWith∈ xs (f ∘ there) _∷=_ : ∀ {n} {xs : Vec A n} {x} → x ∈ xs → A → Vec A n _∷=_ {xs = xs} x∈xs v = xs Vec.[ index x∈xs ]≔ v ------------------------------------------------------------------------ -- Finding and losing witnesses module _ {p} {P : Pred A p} where find : ∀ {n} {xs : Vec A n} → Any P xs → ∃ λ x → x ∈ xs × P x find (here px) = (_ , here refl , px) find (there pxs) with find pxs ... | (x , x∈xs , px) = (x , there x∈xs , px) lose : P Respects _≈_ → ∀ {x n} {xs : Vec A n} → x ∈ xs → P x → Any P xs lose resp x∈xs px = Any.map (flip resp px) x∈xs
30.982456
74
0.458097
ed049b0a09eb2bc987e9291a61adf7702b63dcfa
14,415
agda
Agda
agda-stdlib/src/Data/Nat/DivMod/Core.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Nat/DivMod/Core.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Nat/DivMod/Core.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Core lemmas for division and modulus operations ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Nat.DivMod.Core where open import Agda.Builtin.Nat using () renaming (div-helper to divₕ; mod-helper to modₕ) open import Data.Nat.Base open import Data.Nat.Properties open import Data.Sum.Base using (_⊎_; inj₁; inj₂) open import Data.Product using (_×_; _,_) open import Relation.Binary.PropositionalEquality open import Relation.Nullary using (yes; no) open import Relation.Nullary.Negation using (contradiction) open ≤-Reasoning ------------------------------------------------------------------------- -- Helper lemmas that have no interpretation for _%_, only for modₕ private mod-cong₃ : ∀ {c n a₁ a₂ b} → a₁ ≡ a₂ → modₕ c n a₁ b ≡ modₕ c n a₂ b mod-cong₃ refl = refl modₕ-skipTo0 : ∀ acc n a b → modₕ acc n (b + a) a ≡ modₕ (a + acc) n b 0 modₕ-skipTo0 acc n zero b = cong (λ v → modₕ acc n v 0) (+-identityʳ b) modₕ-skipTo0 acc n (suc a) b = begin-equality modₕ acc n (b + suc a) (suc a) ≡⟨ mod-cong₃ (+-suc b a) ⟩ modₕ acc n (suc b + a) (suc a) ≡⟨⟩ modₕ (suc acc) n (b + a) a ≡⟨ modₕ-skipTo0 (suc acc) n a b ⟩ modₕ (a + suc acc) n b 0 ≡⟨ cong (λ v → modₕ v n b 0) (+-suc a acc) ⟩ modₕ (suc a + acc) n b 0 ∎ ------------------------------------------------------------------------- -- Lemmas for modₕ that also have an interpretation for _%_ a[modₕ]1≡0 : ∀ a → modₕ 0 0 a 0 ≡ 0 a[modₕ]1≡0 zero = refl a[modₕ]1≡0 (suc a) = a[modₕ]1≡0 a n[modₕ]n≡0 : ∀ acc v → modₕ acc (acc + v) (suc v) v ≡ 0 n[modₕ]n≡0 acc v = modₕ-skipTo0 acc (acc + v) v 1 a[modₕ]n<n : ∀ acc d n → modₕ acc (acc + n) d n ≤ acc + n a[modₕ]n<n acc zero n = m≤m+n acc n a[modₕ]n<n acc (suc d) zero = a[modₕ]n<n zero d (acc + 0) a[modₕ]n<n acc (suc d) (suc n) rewrite +-suc acc n = a[modₕ]n<n (suc acc) d n a[modₕ]n≤a : ∀ acc a n → modₕ acc (acc + n) a n ≤ acc + a a[modₕ]n≤a acc zero n = ≤-reflexive (sym (+-identityʳ acc)) a[modₕ]n≤a acc (suc a) (suc n) = begin modₕ acc (acc + suc n) (suc a) (suc n) ≡⟨ cong (λ v → modₕ acc v (suc a) (suc n)) (+-suc acc n) ⟩ modₕ acc (suc acc + n) (suc a) (suc n) ≤⟨ a[modₕ]n≤a (suc acc) a n ⟩ suc acc + a ≡⟨ sym (+-suc acc a) ⟩ acc + suc a ∎ a[modₕ]n≤a acc (suc a) zero = begin modₕ acc (acc + 0) (suc a) 0 ≡⟨ cong (λ v → modₕ acc v (suc a) 0) (+-identityʳ acc) ⟩ modₕ acc acc (suc a) 0 ≤⟨ a[modₕ]n≤a 0 a acc ⟩ a ≤⟨ n≤1+n a ⟩ suc a ≤⟨ m≤n+m (suc a) acc ⟩ acc + suc a ∎ a≤n⇒a[modₕ]n≡a : ∀ acc n a b → modₕ acc n a (a + b) ≡ acc + a a≤n⇒a[modₕ]n≡a acc n zero b = sym (+-identityʳ acc) a≤n⇒a[modₕ]n≡a acc n (suc a) b = begin-equality modₕ (suc acc) n a (a + b) ≡⟨ a≤n⇒a[modₕ]n≡a (suc acc) n a b ⟩ suc acc + a ≡⟨ sym (+-suc acc a) ⟩ acc + suc a ∎ modₕ-idem : ∀ acc a n → modₕ 0 (acc + n) (modₕ acc (acc + n) a n) (acc + n) ≡ modₕ acc (acc + n) a n modₕ-idem acc zero n = a≤n⇒a[modₕ]n≡a 0 (acc + n) acc n modₕ-idem acc (suc a) zero rewrite +-identityʳ acc = modₕ-idem 0 a acc modₕ-idem acc (suc a) (suc n) rewrite +-suc acc n = modₕ-idem (suc acc) a n a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 : ∀ acc l n → modₕ acc (acc + l) (suc n) l ≡ 0 → modₕ acc (acc + l) n l ≡ acc + l a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 acc zero zero eq rewrite +-identityʳ acc = refl a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 acc zero (suc n) eq rewrite +-identityʳ acc = a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 0 acc n eq a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 acc (suc l) (suc n) eq rewrite +-suc acc l = a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 (suc acc) l n eq k<1+a[modₕ]n⇒k≤a[modₕ]n : ∀ acc k n l → suc k ≤ modₕ acc (acc + l) (suc n) l → k ≤ modₕ acc (acc + l) n l k<1+a[modₕ]n⇒k≤a[modₕ]n acc k zero (suc l) (s≤s leq) = leq k<1+a[modₕ]n⇒k≤a[modₕ]n acc k (suc n) zero leq rewrite +-identityʳ acc = k<1+a[modₕ]n⇒k≤a[modₕ]n 0 k n acc leq k<1+a[modₕ]n⇒k≤a[modₕ]n acc k (suc n) (suc l) leq rewrite +-suc acc l = k<1+a[modₕ]n⇒k≤a[modₕ]n (suc acc) k n l leq 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k : ∀ acc k n l → 0 < modₕ acc (acc + l) (suc n) l → modₕ acc (acc + l) (suc n) l ≤ suc k → modₕ acc (acc + l) n l ≤ k 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k acc k zero (suc l) 0<mod (s≤s leq) = leq 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k acc k (suc n) zero 0<mod leq rewrite +-identityʳ acc = 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k 0 k n acc 0<mod leq 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k acc k (suc n) (suc l) 0<mod leq rewrite +-suc acc l = 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k (suc acc) k n l 0<mod leq a+n[modₕ]n≡a[modₕ]n : ∀ acc a n → modₕ acc (acc + n) (acc + a + suc n) n ≡ modₕ acc (acc + n) a n a+n[modₕ]n≡a[modₕ]n acc zero n rewrite +-identityʳ acc = begin-equality modₕ acc (acc + n) (acc + suc n) n ≡⟨ mod-cong₃ (+-suc acc n) ⟩ modₕ acc (acc + n) (suc acc + n) n ≡⟨ modₕ-skipTo0 acc (acc + n) n (suc acc) ⟩ modₕ (acc + n) (acc + n) (suc acc) 0 ≡⟨⟩ modₕ 0 (acc + n) acc (acc + n) ≡⟨ a≤n⇒a[modₕ]n≡a 0 (acc + n) acc n ⟩ acc ∎ a+n[modₕ]n≡a[modₕ]n acc (suc a) zero rewrite +-identityʳ acc = begin-equality modₕ acc acc (acc + suc a + 1) 0 ≡⟨ mod-cong₃ (+-comm (acc + suc a) 1) ⟩ modₕ acc acc (1 + (acc + suc a)) 0 ≡⟨⟩ modₕ 0 acc (acc + suc a) acc ≡⟨ mod-cong₃ (+-comm acc (suc a)) ⟩ modₕ 0 acc (suc a + acc) acc ≡⟨ mod-cong₃ (sym (+-suc a acc)) ⟩ modₕ 0 acc (a + suc acc) acc ≡⟨ a+n[modₕ]n≡a[modₕ]n 0 a acc ⟩ modₕ 0 acc a acc ∎ a+n[modₕ]n≡a[modₕ]n acc (suc a) (suc n) rewrite +-suc acc n = begin-equality mod₁ (acc + suc a + (2 + n)) (suc n) ≡⟨ cong (λ v → mod₁ (v + suc (suc n)) (suc n)) (+-suc acc a) ⟩ mod₁ (suc acc + a + (2 + n)) (suc n) ≡⟨⟩ mod₂ (acc + a + (2 + n)) n ≡⟨ mod-cong₃ (sym (+-assoc (acc + a) 1 (suc n))) ⟩ mod₂ (acc + a + 1 + suc n) n ≡⟨ mod-cong₃ (cong (_+ suc n) (+-comm (acc + a) 1)) ⟩ mod₂ (suc acc + a + suc n) n ≡⟨ a+n[modₕ]n≡a[modₕ]n (suc acc) a n ⟩ mod₂ a n ∎ where mod₁ = modₕ acc (suc acc + n) mod₂ = modₕ (suc acc) (suc acc + n) ------------------------------------------------------------------------- -- Helper lemmas that have no interpretation for `_/_`, only for `divₕ` private div-cong₃ : ∀ {c n a₁ a₂ b} → a₁ ≡ a₂ → divₕ c n a₁ b ≡ divₕ c n a₂ b div-cong₃ refl = refl divₕ-restart : ∀ {acc} d n j → j < n → divₕ acc d n j ≡ divₕ (suc acc) d (n ∸ suc j) d divₕ-restart d (suc n) zero j<n = refl divₕ-restart d (suc n) (suc j) (s≤s j<n) = divₕ-restart d n j j<n divₕ-finish : ∀ {acc} d n j → j ≥ n → divₕ acc d n j ≡ acc divₕ-finish d zero j j≥n = refl divₕ-finish d (suc n) (suc j) (s≤s j≥n) = divₕ-finish d n j j≥n acc≤divₕ[acc] : ∀ {acc} d n j → acc ≤ divₕ acc d n j acc≤divₕ[acc] {acc} d zero j = ≤-refl acc≤divₕ[acc] {acc} d (suc n) zero = ≤-trans (n≤1+n acc) (acc≤divₕ[acc] d n d) acc≤divₕ[acc] {acc} d (suc n) (suc j) = acc≤divₕ[acc] d n j divₕ-extractAcc : ∀ acc d n j → divₕ acc d n j ≡ acc + divₕ 0 d n j divₕ-extractAcc acc d zero j = sym (+-identityʳ acc) divₕ-extractAcc acc d (suc n) (suc j) = divₕ-extractAcc acc d n j divₕ-extractAcc acc d (suc n) zero = begin-equality divₕ (suc acc) d n d ≡⟨ divₕ-extractAcc (suc acc) d n d ⟩ suc acc + divₕ 0 d n d ≡⟨ sym (+-suc acc _) ⟩ acc + suc (divₕ 0 d n d) ≡⟨ cong (acc +_) (sym (divₕ-extractAcc 1 d n d)) ⟩ acc + divₕ 1 d n d ∎ pattern inj₂′ x = inj₂ (inj₁ x) pattern inj₃ x = inj₂ (inj₂ x) -- This hideous lemma details the conditions needed for two divisions to -- be equal when the two offsets (i.e. the 4ᵗʰ parameters) are different. -- It may be that this triple sum has an elegant simplification to a -- set of inequalities involving the modulus but I can't find it. divₕ-offsetEq : ∀ {acc₁ acc₂} d n j k → j ≤ d → k ≤ d → (acc₁ ≡ acc₂ × j ≤ k × k < modₕ 0 d n d) ⊎ (acc₁ ≡ acc₂ × modₕ 0 d n d ≤ j × j ≤ k) ⊎ (acc₁ ≡ suc acc₂ × k < modₕ 0 d n d × modₕ 0 d n d ≤ j) → divₕ acc₁ d n j ≡ divₕ acc₂ d n k divₕ-offsetEq d zero j k j≤d k≤d (inj₁ (refl , _)) = refl divₕ-offsetEq d zero j k j≤d k≤d (inj₂′ (refl , _)) = refl divₕ-offsetEq d zero j k j≤d k≤d (inj₃ (eq , () , _)) -- (0 , 0) cases divₕ-offsetEq d (suc n) zero zero j≤d k≤d (inj₁ (refl , _)) = divₕ-offsetEq d n d d ≤-refl ≤-refl (inj₂′ (refl , a[modₕ]n<n 0 n d , ≤-refl)) divₕ-offsetEq d (suc n) zero zero j≤d k≤d (inj₂′ (refl , _)) = divₕ-offsetEq d n d d ≤-refl ≤-refl (inj₂′ (refl , a[modₕ]n<n 0 n d , ≤-refl)) divₕ-offsetEq d (suc n) zero zero j≤d k≤d (inj₃ (_ , 0<mod , mod≤0)) = contradiction (<-transˡ 0<mod mod≤0) λ() -- (0 , suc) cases divₕ-offsetEq d (suc n) zero (suc k) j≤d k≤d (inj₁ (refl , _ , 1+k<mod)) = divₕ-offsetEq d n d k ≤-refl (<⇒≤ k≤d) (inj₃ (refl , k<1+a[modₕ]n⇒k≤a[modₕ]n 0 (suc k) n d 1+k<mod , a[modₕ]n<n 0 n d)) divₕ-offsetEq d (suc n) zero (suc k) j≤d k≤d (inj₂′ (refl , mod≤0 , _)) = divₕ-offsetEq d n d k ≤-refl (<⇒≤ k≤d) (inj₃ (refl , subst (k <_) (sym (a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 0 d n (n≤0⇒n≡0 mod≤0))) k≤d , a[modₕ]n<n 0 n d)) divₕ-offsetEq d (suc n) zero (suc k) j≤d k≤d (inj₃ (_ , 1+k<mod , mod≤0)) = contradiction (<-transˡ 1+k<mod mod≤0) λ() -- (suc , 0) cases divₕ-offsetEq d (suc n) (suc j) zero j≤d k≤d (inj₁ (_ , () , _)) divₕ-offsetEq d (suc n) (suc j) zero j≤d k≤d (inj₂′ (_ , _ , ())) divₕ-offsetEq d (suc n) (suc j) zero j≤d k≤d (inj₃ (eq , 0<mod , mod≤1+j)) = divₕ-offsetEq d n j d (<⇒≤ j≤d) ≤-refl (inj₂′ (eq , 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k 0 j n d 0<mod mod≤1+j , <⇒≤ j≤d)) -- (suc , suc) cases divₕ-offsetEq d (suc n) (suc j) (suc k) j≤d k≤d (inj₁ (eq , s≤s j≤k , 1+k<mod)) = divₕ-offsetEq d n j k (<⇒≤ j≤d) (<⇒≤ k≤d) (inj₁ (eq , j≤k , k<1+a[modₕ]n⇒k≤a[modₕ]n 0 (suc k) n d 1+k<mod)) divₕ-offsetEq d (suc n) (suc j) (suc k) j≤d k≤d (inj₂′ (eq , mod≤1+j , (s≤s j≤k))) with modₕ 0 d (suc n) d ≟ 0 ... | yes mod≡0 = divₕ-offsetEq d n j k (<⇒≤ j≤d) (<⇒≤ k≤d) (inj₁ (eq , j≤k , subst (k <_) (sym (a+1[modₕ]n≡0⇒a[modₕ]n≡n-1 0 d n mod≡0)) k≤d)) ... | no mod≢0 = divₕ-offsetEq d n j k (<⇒≤ j≤d) (<⇒≤ k≤d) (inj₂′ (eq , 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k 0 j n d (n≢0⇒n>0 mod≢0) mod≤1+j , j≤k)) divₕ-offsetEq d (suc n) (suc j) (suc k) j≤d k≤d (inj₃ (eq , k<mod , mod≤1+j)) = divₕ-offsetEq d n j k (<⇒≤ j≤d) (<⇒≤ k≤d) (inj₃ (eq , k<1+a[modₕ]n⇒k≤a[modₕ]n 0 (suc k) n d k<mod , 1+a[modₕ]n≤1+k⇒a[modₕ]n≤k 0 j n d (<-transʳ z≤n k<mod) mod≤1+j)) ------------------------------------------------------------------------- -- Lemmas for divₕ that also have an interpretation for _/_ -- The quotient and remainder are related to the dividend and -- divisor in the right way. div-mod-lemma : ∀ accᵐ accᵈ d n → accᵐ + accᵈ * suc (accᵐ + n) + d ≡ modₕ accᵐ (accᵐ + n) d n + divₕ accᵈ (accᵐ + n) d n * suc (accᵐ + n) div-mod-lemma accᵐ accᵈ zero n = +-identityʳ _ div-mod-lemma accᵐ accᵈ (suc d) zero rewrite +-identityʳ accᵐ = begin-equality accᵐ + accᵈ * suc accᵐ + suc d ≡⟨ +-suc _ d ⟩ suc accᵈ * suc accᵐ + d ≡⟨ div-mod-lemma zero (suc accᵈ) d accᵐ ⟩ modₕ 0 accᵐ d accᵐ + divₕ (suc accᵈ) accᵐ d accᵐ * suc accᵐ ≡⟨⟩ modₕ accᵐ accᵐ (suc d) 0 + divₕ accᵈ accᵐ (suc d) 0 * suc accᵐ ∎ div-mod-lemma accᵐ accᵈ (suc d) (suc n) rewrite +-suc accᵐ n = begin-equality accᵐ + accᵈ * m + suc d ≡⟨ +-suc _ d ⟩ suc (accᵐ + accᵈ * m + d) ≡⟨ div-mod-lemma (suc accᵐ) accᵈ d n ⟩ modₕ _ _ d n + divₕ accᵈ _ d n * m ∎ where m = 2 + accᵐ + n n[divₕ]n≡1 : ∀ n m → divₕ 0 n (suc m) m ≡ 1 n[divₕ]n≡1 n zero = refl n[divₕ]n≡1 n (suc m) = n[divₕ]n≡1 n m a[divₕ]1≡a : ∀ acc a → divₕ acc 0 a 0 ≡ acc + a a[divₕ]1≡a acc zero = sym (+-identityʳ acc) a[divₕ]1≡a acc (suc a) = trans (a[divₕ]1≡a (suc acc) a) (sym (+-suc acc a)) a*n[divₕ]n≡a : ∀ acc a n → divₕ acc n (a * suc n) n ≡ acc + a a*n[divₕ]n≡a acc zero n = sym (+-identityʳ acc) a*n[divₕ]n≡a acc (suc a) n = begin-equality divₕ acc n (suc a * suc n) n ≡⟨ divₕ-restart n (suc a * suc n) n (m≤m+n (suc n) _) ⟩ divₕ (suc acc) n (suc a * suc n ∸ suc n) n ≡⟨⟩ divₕ (suc acc) n (suc n + a * suc n ∸ suc n) n ≡⟨ div-cong₃ (m+n∸m≡n (suc n) (a * suc n)) ⟩ divₕ (suc acc) n (a * suc n) n ≡⟨ a*n[divₕ]n≡a (suc acc) a n ⟩ suc acc + a ≡⟨ sym (+-suc acc a) ⟩ acc + suc a ∎ +-distrib-divₕ : ∀ acc k m n j → modₕ k (k + j) m j + modₕ 0 (k + j) n (k + j) < suc (k + j) → divₕ acc (k + j) (m + n) j ≡ divₕ acc (k + j) m j + divₕ 0 (k + j) n (k + j) +-distrib-divₕ acc k (suc m) n zero leq rewrite +-identityʳ k = +-distrib-divₕ (suc acc) 0 m n k leq +-distrib-divₕ acc k (suc m) n (suc j) leq rewrite +-suc k j = +-distrib-divₕ acc (suc k) m n j leq +-distrib-divₕ acc k zero n j leq = begin-equality divₕ acc (k + j) n j ≡⟨ divₕ-extractAcc acc (k + j) n j ⟩ acc + divₕ 0 (k + j) n j ≡⟨ cong (acc +_) (divₕ-offsetEq _ n j _ (m≤n+m j k) ≤-refl case) ⟩ acc + divₕ 0 (k + j) n (k + j) ∎ where case = inj₂′ (refl , +-cancelˡ-≤ (suc k) leq , m≤n+m j k) divₕ-mono-≤ : ∀ {acc} k {m n o p} → m ≤ n → p ≤ o → divₕ acc (k + o) m o ≤ divₕ acc (k + p) n p divₕ-mono-≤ {acc} k {0} {n} {_} {p} z≤n p≤o = acc≤divₕ[acc] (k + p) n p divₕ-mono-≤ {acc} k {_} {_} {suc o} {suc p} (s≤s m≤n) (s≤s p≤o) rewrite +-suc k o | +-suc k p = divₕ-mono-≤ (suc k) m≤n p≤o divₕ-mono-≤ {acc} k {suc m} {suc n} {o} {0} (s≤s m≤n) z≤n with o <? suc m ... | no o≮1+m rewrite +-identityʳ k = begin divₕ acc (k + o) (suc m) o ≡⟨ divₕ-finish (k + o) (suc m) o (≮⇒≥ o≮1+m) ⟩ acc ≤⟨ n≤1+n acc ⟩ suc acc ≤⟨ acc≤divₕ[acc] k n k ⟩ divₕ (suc acc) k n k ∎ ... | yes o<1+m rewrite +-identityʳ k = begin divₕ acc (k + o) (suc m) o ≡⟨ divₕ-restart (k + o) (suc m) o o<1+m ⟩ divₕ (suc acc) (k + o) (m ∸ o) (k + o) ≤⟨ divₕ-mono-≤ 0 (≤-trans (m∸n≤m m o) m≤n) (m≤m+n k o) ⟩ divₕ (suc acc) k n k ∎
54.809886
168
0.513215