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
503c037a69320f46bb7a6fe4af6df50b2bb16e67
1,540
agda
Agda
test/Succeed/WithoutKRestrictiveNoUniPoly.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/WithoutKRestrictiveNoUniPoly.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/WithoutKRestrictiveNoUniPoly.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K --show-implicit #-} -- {-# OPTIONS -v tc.lhs.split.well-formed:100 #-} -- Andreas, adapted from Andres Sicard, 2013-05-29 module WithoutKRestrictiveNoUniPoly where data ℕ : Set where zero : ℕ suc : ℕ → ℕ data _≤_ : ℕ → ℕ → Set where z≤n : ∀ {n} → zero ≤ n s≤s : ∀ {n m} → n ≤ m → suc n ≤ suc m _<_ : ℕ → ℕ → Set n < m = suc n ≤ m refl≤ : ∀ (n : ℕ) → n ≤ n refl≤ zero = z≤n refl≤ (suc n) = s≤s (refl≤ n) data List (A : Set) : Set where [] : List A _∷_ : (x : A) (xs : List A) → List A length : {A : Set} → List A → ℕ length [] = zero length (x ∷ xs) = suc (length xs) record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ data _≡_ {A : Set}(a : A) : A → Set where refl : a ≡ a subst : {A : Set}(P : A → Set){a b : A} → a ≡ b → P a → P b subst P refl x = x sym : {A : Set}{a b : A} → a ≡ b → b ≡ a sym refl = refl P : {A : Set} → List A → List A → Set P xs ys = Σ _ (λ x → ys ≡ (x ∷ xs)) Q : {A : Set} → List A → List A → Set Q xs ys = (length xs) < (length ys) helper : {A : Set}(y : A)(xs : List A) → (length xs) < (length (y ∷ xs)) helper y [] = s≤s z≤n helper y (x ∷ xs) = s≤s (refl≤ _) -- Why the --without-K option rejects the following proof foo : {A : Set}(xs ys : List A) → P xs ys → Q xs ys foo xs .(x ∷ xs) (x , refl) = helper x xs -- if I can prove foo using only subst foo' : {A : Set}(xs ys : List A) → P xs ys → Q xs ys foo' xs ys (x , h) = subst (λ ys' → length xs < length ys') (sym h) (helper x xs)
24.0625
72
0.521429
0b761bec74b265ace8e7d65ea2bb3e5790f9163a
70
agda
Agda
tests/covered/Dot.agda
andrejtokarcik/agda-semantics
dc333ed142584cf52cc885644eed34b356967d8b
[ "MIT" ]
3
2015-08-10T15:33:56.000Z
2018-12-06T17:24:25.000Z
tests/covered/Dot.agda
andrejtokarcik/agda-semantics
dc333ed142584cf52cc885644eed34b356967d8b
[ "MIT" ]
null
null
null
tests/covered/Dot.agda
andrejtokarcik/agda-semantics
dc333ed142584cf52cc885644eed34b356967d8b
[ "MIT" ]
null
null
null
module Dot where postulate h : Set f : Set -> Set -> Set f .n n = h
10
21
0.585714
fbc592774280b81a74f677b925eae4f5074aaa09
1,257
agda
Agda
src/Polynomial/NormalForm.agda
mckeankylej/agda-ring-solver
f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500
[ "MIT" ]
36
2019-01-25T16:40:52.000Z
2022-02-15T00:57:55.000Z
src/Polynomial/NormalForm.agda
oisdk/agda-algebra
7e4ee048dab68ccb0a8673a6a663a37c1d1f4080
[ "MIT" ]
5
2019-04-17T20:48:48.000Z
2022-03-12T01:55:42.000Z
src/Polynomial/NormalForm.agda
oisdk/agda-algebra
7e4ee048dab68ccb0a8673a6a663a37c1d1f4080
[ "MIT" ]
4
2019-04-16T02:23:16.000Z
2022-01-20T07:07:11.000Z
{-# OPTIONS --without-K --safe #-} -- Polynomials over a commutative ring in sparse Horner normal form. -- -- Much of the implementation is inspired by: -- -- B. Grégoire and A. Mahboubi, ‘Proving Equalities in a Commutative -- Ring Done Right in Coq’, in Theorem Proving in Higher Order -- Logics, Berlin, Heidelberg, 2005, vol. 3603, pp. 98–113. -- -- The main sources of efficience come from: -- -- * Careful arrangement of operators to maintain *syntactic equality*. -- -- * Avoiding of identities (like *1 or +0) with specialised data -- structures. open import Polynomial.Parameters module Polynomial.NormalForm {c r₁ r₂ r₃} (homo : Homomorphism c r₁ r₂ r₃) where open Homomorphism homo -- The "injection index" is what allows us to store the nested -- polynomials sparsely. open import Polynomial.NormalForm.InjectionIndex public -- The definition and types for the polynomial. open import Polynomial.NormalForm.Definition coeffs public -- Normalizing constructors. open import Polynomial.NormalForm.Construction coeffs public -- Definition of arithmetic operations etc. open import Polynomial.NormalForm.Operations coeffs public -- "Running" the polynomial on some input. open import Polynomial.NormalForm.Semantics homo public
30.658537
71
0.759745
2904e8515aaacb415227f6aea515cb86db24066c
7,731
agda
Agda
Cubical/Algebra/Lattice/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Algebra/Lattice/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Algebra/Lattice/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.Lattice.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.Semilattice open import Cubical.Displayed.Base open import Cubical.Displayed.Auto open import Cubical.Displayed.Record open import Cubical.Displayed.Universe open import Cubical.Reflection.RecordEquiv open Iso private variable ℓ ℓ' : Level record IsLattice {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) : Type ℓ where constructor islattice field joinSemilattice : IsSemilattice 0l _∨l_ meetSemilattice : IsSemilattice 1l _∧l_ absorb : (x y : L) → (x ∨l (x ∧l y) ≡ x) × (x ∧l (x ∨l y) ≡ x) open IsSemilattice joinSemilattice public renaming ( assoc to ∨lAssoc ; identity to ∨lIdentity ; lid to ∨lLid ; rid to ∨lRid ; comm to ∨lComm ; idem to ∨lIdem ; isCommMonoid to ∨lIsCommMonoid ; isMonoid to ∨lIsMonoid ; isSemigroup to ∨lIsSemigroup ) open IsSemilattice meetSemilattice public renaming ( assoc to ∧lAssoc ; identity to ∧lIdentity ; lid to ∧lLid ; rid to ∧lRid ; comm to ∧lComm ; idem to ∧lIdem ; isCommMonoid to ∧lIsCommMonoid ; isMonoid to ∧lIsMonoid ; isSemigroup to ∧lIsSemigroup ) hiding ( is-set ) ∨lAbsorb∧l : (x y : L) → x ∨l (x ∧l y) ≡ x ∨lAbsorb∧l x y = absorb x y .fst ∧lAbsorb∨l : (x y : L) → x ∧l (x ∨l y) ≡ x ∧lAbsorb∨l x y = absorb x y .snd record LatticeStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor latticestr field 0l : A 1l : A _∨l_ : A → A → A _∧l_ : A → A → A isLattice : IsLattice 0l 1l _∨l_ _∧l_ infix 7 _∨l_ infix 6 _∧l_ open IsLattice isLattice public Lattice : ∀ ℓ → Type (ℓ-suc ℓ) Lattice ℓ = TypeWithStr ℓ LatticeStr isSetLattice : (L : Lattice ℓ) → isSet ⟨ L ⟩ isSetLattice L = L .snd .LatticeStr.is-set makeIsLattice : {L : Type ℓ} {0l 1l : L} {_∨l_ _∧l_ : L → L → L} (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-lid : (x : L) → 0l ∨l x ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-lid : (x : L) → 1l ∧l x ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) → IsLattice 0l 1l _∨l_ _∧l_ makeIsLattice {0l = 0l} {1l = 1l} {_∨l_ = _∨l_} {_∧l_ = _∧l_} is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l = islattice (makeIsSemilattice is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∨l-idem) (makeIsSemilattice is-setL ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∧l-idem) λ x y → ∨l-absorb-∧l x y , ∧l-absorb-∨l x y where ∨l-idem : ∀ x → x ∨l x ≡ x ∨l-idem x = cong (x ∨l_) (sym (∧l-rid _)) ∙ ∨l-absorb-∧l _ _ ∧l-idem : ∀ x → x ∧l x ≡ x ∧l-idem x = cong (x ∧l_) (sym (∨l-rid _)) ∙ ∧l-absorb-∨l _ _ makeLattice : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-lid : (x : L) → 0l ∨l x ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∨l-idem : (x : L) → x ∨l x ≡ x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-lid : (x : L) → 1l ∧l x ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∧l-idem : (x : L) → x ∧l x ≡ x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) → Lattice ℓ makeLattice 0l 1l _∨l_ _∧l_ is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∨l-idem ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∧l-idem ∨l-absorb-∧l ∧l-absorb-∨l = _ , latticestr 0l 1l _∨l_ _∧l_ (makeIsLattice is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l) record IsLatticeHom {A : Type ℓ} {B : Type ℓ'} (L : LatticeStr A) (f : A → B) (M : LatticeStr B) : Type (ℓ-max ℓ ℓ') where -- Shorter qualified names private module L = LatticeStr L module M = LatticeStr M field pres0 : f L.0l ≡ M.0l pres1 : f L.1l ≡ M.1l pres∨l : (x y : A) → f (x L.∨l y) ≡ f x M.∨l f y pres∧l : (x y : A) → f (x L.∧l y) ≡ f x M.∧l f y unquoteDecl IsLatticeHomIsoΣ = declareRecordIsoΣ IsLatticeHomIsoΣ (quote IsLatticeHom) LatticeHom : (L : Lattice ℓ) (M : Lattice ℓ') → Type (ℓ-max ℓ ℓ') LatticeHom L M = Σ[ f ∈ (⟨ L ⟩ → ⟨ M ⟩) ] IsLatticeHom (L .snd) f (M .snd) IsLatticeEquiv : {A : Type ℓ} {B : Type ℓ'} (M : LatticeStr A) (e : A ≃ B) (N : LatticeStr B) → Type (ℓ-max ℓ ℓ') IsLatticeEquiv M e N = IsLatticeHom M (e .fst) N LatticeEquiv : (L : Lattice ℓ) (M : Lattice ℓ') → Type (ℓ-max ℓ ℓ') LatticeEquiv L M = Σ[ e ∈ (⟨ L ⟩ ≃ ⟨ M ⟩) ] IsLatticeEquiv (L .snd) e (M .snd) isPropIsLattice : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) → isProp (IsLattice 0l 1l _∨l_ _∧l_) isPropIsLattice 0l 1l _∨l_ _∧l_ (islattice LJ LM LA) (islattice MJ MM MA) = λ i → islattice (isPropIsSemilattice _ _ LJ MJ i) (isPropIsSemilattice _ _ LM MM i) (isPropAbsorb LA MA i) where isSetL : isSet _ isSetL = LJ .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set isPropAbsorb : isProp ((x y : _) → (x ∨l (x ∧l y) ≡ x) × (x ∧l (x ∨l y) ≡ x)) isPropAbsorb = isPropΠ2 λ _ _ → isProp× (isSetL _ _) (isSetL _ _) isPropIsLatticeHom : {A : Type ℓ} {B : Type ℓ'} (R : LatticeStr A) (f : A → B) (S : LatticeStr B) → isProp (IsLatticeHom R f S) isPropIsLatticeHom R f S = isOfHLevelRetractFromIso 1 IsLatticeHomIsoΣ (isProp×3 (isSetLattice (_ , S) _ _) (isSetLattice (_ , S) _ _) (isPropΠ2 λ _ _ → isSetLattice (_ , S) _ _) (isPropΠ2 λ _ _ → isSetLattice (_ , S) _ _)) 𝒮ᴰ-Lattice : DUARel (𝒮-Univ ℓ) LatticeStr ℓ 𝒮ᴰ-Lattice = 𝒮ᴰ-Record (𝒮-Univ _) IsLatticeEquiv (fields: data[ 0l ∣ null ∣ pres0 ] data[ 1l ∣ null ∣ pres1 ] data[ _∨l_ ∣ bin ∣ pres∨l ] data[ _∧l_ ∣ bin ∣ pres∧l ] prop[ isLattice ∣ (λ _ _ → isPropIsLattice _ _ _ _) ]) where open LatticeStr open IsLatticeHom -- faster with some sharing null = autoDUARel (𝒮-Univ _) (λ A → A) bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A) LatticePath : (L M : Lattice ℓ) → LatticeEquiv L M ≃ (L ≡ M) LatticePath = ∫ 𝒮ᴰ-Lattice .UARel.ua Lattice→JoinSemilattice : Lattice ℓ → Semilattice ℓ Lattice→JoinSemilattice (A , latticestr _ _ _ _ L) = semilattice _ _ _ (L .IsLattice.joinSemilattice ) Lattice→MeetSemilattice : Lattice ℓ → Semilattice ℓ Lattice→MeetSemilattice (A , latticestr _ _ _ _ L) = semilattice _ _ _ (L .IsLattice.meetSemilattice )
34.36
102
0.549476
298ca5291b7db02ec06a5ca2884dcb72f54238ae
5,255
agda
Agda
PiFrac/Opsem.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
PiFrac/Opsem.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
PiFrac/Opsem.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
module PiFrac.Opsem where open import Data.Empty open import Data.Unit hiding (_≟_) open import Data.Sum open import Data.Product open import Relation.Binary.Core open import Relation.Binary open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Function using (_∘_) open import Base open import PiFrac.Syntax infix 1 _↦_ -- Base combinators base : ∀ {A B} (c : A ↔ B) → Set base uniti₊l = ⊤ base unite₊l = ⊤ base swap₊ = ⊤ base assocl₊ = ⊤ base assocr₊ = ⊤ base unite⋆l = ⊤ base uniti⋆l = ⊤ base swap⋆ = ⊤ base assocl⋆ = ⊤ base assocr⋆ = ⊤ base dist = ⊤ base factor = ⊤ base _ = ⊥ -- Dual combinators dual : ∀ {A B} (c : A ↔ B) → Set dual (ηₓ v) = ⊤ dual (εₓ v) = ⊤ dual _ = ⊥ base-is-prop : ∀ {A B} (c : A ↔ B) → is-prop (base c) base-is-prop uniti₊l tt tt = refl base-is-prop unite₊l tt tt = refl base-is-prop swap₊ tt tt = refl base-is-prop assocl₊ tt tt = refl base-is-prop assocr₊ tt tt = refl base-is-prop unite⋆l tt tt = refl base-is-prop uniti⋆l tt tt = refl base-is-prop swap⋆ tt tt = refl base-is-prop assocl⋆ tt tt = refl base-is-prop assocr⋆ tt tt = refl base-is-prop dist tt tt = refl base-is-prop factor tt tt = refl -- Evaluator for base combinators δ : ∀ {A B} (c : A ↔ B) {_ : base c} → ⟦ A ⟧ → ⟦ B ⟧ δ uniti₊l v = inj₂ v δ unite₊l (inj₂ y) = y δ swap₊ (inj₁ x) = inj₂ x δ swap₊ (inj₂ y) = inj₁ y δ assocl₊ (inj₁ v) = inj₁ (inj₁ v) δ assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v) δ assocl₊ (inj₂ (inj₂ v)) = inj₂ v δ assocr₊ (inj₁ (inj₁ v)) = inj₁ v δ assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v) δ assocr₊ (inj₂ v) = inj₂ (inj₂ v) δ unite⋆l (tt , v) = v δ uniti⋆l v = (tt , v) δ swap⋆ (x , y) = (y , x) δ assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃) δ assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃)) δ dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃) δ dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃) δ factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃) δ factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃) -- Decidable equality of PiFrac values _≟_ : {t : 𝕌} → Decidable (_≡_ {A = ⟦ t ⟧}) _≟_ {𝟙} tt tt = yes refl _≟_ {t₁ +ᵤ t₂} (inj₁ x) (inj₁ y) with x ≟ y ... | yes refl = yes refl ... | no x≠y = no (x≠y ∘ λ {refl → refl}) _≟_ {t₁ +ᵤ t₂} (inj₁ x) (inj₂ y) = no (λ ()) _≟_ {t₁ +ᵤ t₂} (inj₂ x) (inj₁ y) = no (λ ()) _≟_ {t₁ +ᵤ t₂} (inj₂ x) (inj₂ y) with x ≟ y ... | yes refl = yes refl ... | no x≠y = no (x≠y ∘ λ {refl → refl}) _≟_ {t₁ ×ᵤ t₂} (x₁ , x₂) (y₁ , y₂) with x₁ ≟ y₁ | x₂ ≟ y₂ ... | yes refl | yes refl = yes refl ... | yes refl | no x₂≠y₂ = no (x₂≠y₂ ∘ cong proj₂) ... | no x₁≠y₁ | yes refl = no (x₁≠y₁ ∘ cong proj₁) ... | no x₁≠y₁ | no x₂≠y₂ = no (x₁≠y₁ ∘ cong proj₁) _≟_ {𝟙/ v} ↻ ↻ = yes refl -- Context data Context : {A B : 𝕌} → Set where ☐ : ∀ {A B} → Context {A} {B} ☐⨾_•_ : ∀ {A B C} → (c₂ : B ↔ C) → Context {A} {C} → Context {A} {B} _⨾☐•_ : ∀ {A B C} → (c₁ : A ↔ B) → Context {A} {C} → Context {B} {C} ☐⊕_•_ : ∀ {A B C D} → (c₂ : C ↔ D) → Context {A +ᵤ C} {B +ᵤ D} → Context {A} {B} _⊕☐•_ : ∀ {A B C D} → (c₁ : A ↔ B) → Context {A +ᵤ C} {B +ᵤ D} → Context {C} {D} ☐⊗[_,_]•_ : ∀ {A B C D} → (c₂ : C ↔ D) → ⟦ C ⟧ → Context {A ×ᵤ C} {B ×ᵤ D} → Context {A} {B} [_,_]⊗☐•_ : ∀ {A B C D} → (c₁ : A ↔ B) → ⟦ B ⟧ → Context {A ×ᵤ C} {B ×ᵤ D} → Context {C} {D} -- Machine state data State : Set where ⟨_∣_∣_⟩ : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → Context {A} {B} → State [_∣_∣_] : ∀ {A B} → (c : A ↔ B) → ⟦ B ⟧ → Context {A} {B} → State ⊠ : State -- Reduction relation data _↦_ : State → State → Set where ↦₁ : ∀ {A B} {c : A ↔ B} {b : base c} {v : ⟦ A ⟧} {κ : Context} → ⟨ c ∣ v ∣ κ ⟩ ↦ [ c ∣ δ c {b} v ∣ κ ] ↦₂ : ∀ {A} {v : ⟦ A ⟧} {κ : Context} → ⟨ id↔ ∣ v ∣ κ ⟩ ↦ [ id↔ ∣ v ∣ κ ] ↦₃ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ A ⟧} {κ : Context} → ⟨ c₁ ⨾ c₂ ∣ v ∣ κ ⟩ ↦ ⟨ c₁ ∣ v ∣ ☐⨾ c₂ • κ ⟩ ↦₄ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ A ⟧} {κ : Context} → ⟨ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ⟩ ↦ ⟨ c₁ ∣ x ∣ ☐⊕ c₂ • κ ⟩ ↦₅ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {y : ⟦ C ⟧} {κ : Context} → ⟨ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ⟩ ↦ ⟨ c₂ ∣ y ∣ c₁ ⊕☐• κ ⟩ ↦₆ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ A ⟧} {y : ⟦ C ⟧} {κ : Context} → ⟨ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ⟩ ↦ ⟨ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ⟩ ↦₇ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ B ⟧} {κ : Context} → [ c₁ ∣ v ∣ ☐⨾ c₂ • κ ] ↦ ⟨ c₂ ∣ v ∣ (c₁ ⨾☐• κ) ⟩ ↦₈ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {y : ⟦ C ⟧} {κ : Context} → [ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ] ↦ ⟨ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ⟩ ↦₉ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {y : ⟦ D ⟧} {κ : Context} → [ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ] ↦ [ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ] ↦₁₀ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ C ⟧} {κ : Context} → [ c₂ ∣ v ∣ (c₁ ⨾☐• κ) ] ↦ [ c₁ ⨾ c₂ ∣ v ∣ κ ] ↦₁₁ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {κ : Context} → [ c₁ ∣ x ∣ ☐⊕ c₂ • κ ] ↦ [ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ] ↦₁₂ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {y : ⟦ D ⟧} {κ : Context} → [ c₂ ∣ y ∣ c₁ ⊕☐• κ ] ↦ [ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ] ↦η : ∀ {A} {v : ⟦ A ⟧} {κ : Context} → ⟨ ηₓ v ∣ tt ∣ κ ⟩ ↦ [ ηₓ v ∣ (v , ↻) ∣ κ ] ↦ε₁ : ∀ {A} {v v' : ⟦ A ⟧} {κ : Context} {eq : v ≡ v'} → ⟨ εₓ v ∣ (v' , ↻) ∣ κ ⟩ ↦ [ εₓ v ∣ tt ∣ κ ] ↦ε₂ : ∀ {A} {v v' : ⟦ A ⟧} {κ : Context} {neq : v ≢ v'} → ⟨ εₓ v ∣ (v' , ↻) ∣ κ ⟩ ↦ ⊠
38.639706
103
0.454424
41588a5bffde149ad0542e727c9d969d97746c5c
652
agda
Agda
agda/SList.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/SList.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/SList.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
{-# OPTIONS --sized-types #-} module SList (A : Set) where open import Data.List open import Data.Product open import Size data SList : {ι : Size} → Set where snil : {ι : Size} → SList {↑ ι} _∙_ : {ι : Size}(x : A) → SList {ι} → SList {↑ ι} size : List A → SList size [] = snil size (x ∷ xs) = x ∙ (size xs) unsize : {ι : Size} → SList {ι} → List A unsize snil = [] unsize (x ∙ xs) = x ∷ unsize xs unsize× : {ι : Size} → SList {ι} × SList {ι} → List A × List A unsize× (xs , ys) = unsize xs , unsize ys _⊕_ : SList → SList → SList snil ⊕ ys = ys (x ∙ xs) ⊕ ys = x ∙ (xs ⊕ ys)
19.176471
62
0.503067
1cf5da60ec79cb9546aaed682e02ca0cdd7e1490
4,075
agda
Agda
Cubical/Algebra/Polynomials/UnivariateHIT/Polyn-nPoly.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/Polynomials/UnivariateHIT/Polyn-nPoly.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/Polynomials/UnivariateHIT/Polyn-nPoly.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.Polynomials.UnivariateHIT.Polyn-nPoly where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Data.Nat renaming (_+_ to _+n_; _·_ to _·n_) open import Cubical.Data.Vec open import Cubical.Data.Sigma open import Cubical.Algebra.DirectSum.DirectSumHIT.Base open import Cubical.Algebra.Ring open import Cubical.Algebra.GradedRing.DirectSumFun open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Instances.Polynomials.UnivariatePolyHIT open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Poly0-A open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.An[Am[X]]-Anm[X] open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.AB-An[X]Bn[X] open CommRingEquivs renaming (compCommRingEquiv to _∘-ecr_ ; invCommRingEquiv to inv-ecr) private variable ℓ : Level ----------------------------------------------------------------------------- -- Definition module equiv1 (A'@(A , Astr) : CommRing ℓ) where private PA = PolyCommRing A' 1 PAstr = snd PA PA' = nUnivariatePolyHIT A' 1 PA'str = snd PA' open CommRingStr directSense : fst (PolyCommRing A' 1) → fst (nUnivariatePolyHIT A' 1) directSense = DS-Rec-Set.f _ _ _ _ (is-set PA'str) (0r PA'str) (λ { (n ∷ []) a → base n a}) (_+_ PA'str) (+Assoc PA'str) (+IdR PA'str) (+Comm PA'str) (λ { (n ∷ []) → base-neutral _ }) λ { (n ∷ []) a b → base-add _ _ _} convSense : fst (nUnivariatePolyHIT A' 1) → fst (PolyCommRing A' 1) convSense = DS-Rec-Set.f _ _ _ _ (is-set PAstr) (0r PAstr) (λ n a → base (n ∷ []) a) (_+_ PAstr) (+Assoc PAstr) (+IdR PAstr) (+Comm PAstr) (λ n → base-neutral _) λ _ _ _ → base-add _ _ _ retr : (x : fst (PolyCommRing A' 1)) → convSense (directSense x) ≡ x retr = DS-Ind-Prop.f _ _ _ _ (λ _ → is-set PAstr _ _) refl (λ { (n ∷ []) a → refl}) (λ {U V} ind-U ind-V → cong₂ (_+_ PAstr) ind-U ind-V) sect : (x : fst (nUnivariatePolyHIT A' 1)) → (directSense (convSense x) ≡ x) sect = DS-Ind-Prop.f _ _ _ _ (λ _ → is-set PA'str _ _) refl (λ n a → refl) (λ {U V} ind-U ind-V → cong₂ (_+_ PA'str) ind-U ind-V) converseSense-pres· : (x y : fst (PolyCommRing A' 1)) → directSense (_·_ PAstr x y) ≡ _·_ PA'str (directSense x) (directSense y) converseSense-pres· = DS-Ind-Prop.f _ _ _ _ (λ _ → isPropΠ λ _ → is-set PA'str _ _) (λ _ → refl) (λ { (n ∷ []) a → DS-Ind-Prop.f _ _ _ _ (λ _ → is-set PA'str _ _) refl (λ { (m ∷ []) b → refl}) λ {U V} ind-U ind-V → cong₂ (_+_ PA'str) ind-U ind-V}) λ {U V} ind-U ind-V y → cong₂ (_+_ PA'str) (ind-U y) (ind-V y) open Iso equivR : CommRingEquiv PA PA' fst equivR = isoToEquiv is where is : Iso (PA .fst) (PA' .fst) fun is = directSense inv is = convSense rightInv is = sect leftInv is = retr snd equivR = makeIsRingHom refl (λ _ _ → refl) converseSense-pres· open equiv1 Equiv-Polyn-nPolyHIT : (A' : CommRing ℓ) → (n : ℕ) → CommRingEquiv (PolyCommRing A' n) (nUnivariatePolyHIT A' n) Equiv-Polyn-nPolyHIT A' zero = CRE-Poly0-A A' Equiv-Polyn-nPolyHIT A' (suc n) = inv-ecr _ _ (CRE-PolyN∘M-PolyN+M A' 1 n) ∘-ecr (lift-equiv-poly _ _ 1 (Equiv-Polyn-nPolyHIT A' n) ∘-ecr equivR (nUnivariatePolyHIT A' n))
36.711712
112
0.557546
5799a543cf46e76735430b44711ea1c2c210b7cf
4,960
agda
Agda
examples/instance-arguments/07-subclasses.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
examples/instance-arguments/07-subclasses.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
examples/instance-arguments/07-subclasses.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} -- {-# OPTIONS --verbose tc.records.ifs:15 #-} -- {-# OPTIONS --verbose tc.constr.findInScope:15 #-} -- {-# OPTIONS --verbose tc.term.args.ifs:15 #-} -- {-# OPTIONS --verbose cta.record.ifs:15 #-} -- {-# OPTIONS --verbose tc.section.apply:25 #-} -- {-# OPTIONS --verbose tc.mod.apply:100 #-} -- {-# OPTIONS --verbose scope.rec:15 #-} -- {-# OPTIONS --verbose tc.rec.def:15 #-} module 07-subclasses where module Imports where module L where postulate Level : Set zero : Level suc : Level → Level _⊔_ : Level → Level → Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO zero #-} {-# BUILTIN LEVELSUC suc #-} {-# BUILTIN LEVELMAX _⊔_ #-} -- extract from Function id : ∀ {a} {A : Set a} → A → A id x = x _$_ : ∀ {a b} {A : Set a} {B : A → Set b} → ((x : A) → B x) → ((x : A) → B x) f $ x = f x _∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} → (∀ {x} (y : B x) → C y) → (g : (x : A) → B x) → ((x : A) → C (g x)) f ∘ g = λ x → f (g x) -- extract from Data.Bool infixr 5 _∨_ data Bool : Set where true : Bool false : Bool not : Bool → Bool not true = false not false = true _∨_ : Bool → Bool → Bool true ∨ b = true false ∨ b = b -- extract from Relation.Nullary.Decidable and friends infix 3 ¬_ data ⊥ : Set where ¬_ : ∀ {ℓ} → Set ℓ → Set ℓ ¬ P = P → ⊥ data Dec {p} (P : Set p) : Set p where yes : ( p : P) → Dec P no : (¬p : ¬ P) → Dec P ⌊_⌋ : ∀ {p} {P : Set p} → Dec P → Bool ⌊ yes _ ⌋ = true ⌊ no _ ⌋ = false -- extract from Relation.Binary.PropositionalEquality data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x cong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {x y} → x ≡ y → f x ≡ f y cong f refl = refl -- extract from Data.Nat data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ {-# BUILTIN NATURAL ℕ #-} {-# BUILTIN ZERO zero #-} {-# BUILTIN SUC suc #-} pred : ℕ → ℕ pred zero = zero pred (suc n) = n _≟_ : (x y : ℕ) → Dec (x ≡ y) zero ≟ zero = yes refl suc m ≟ suc n with m ≟ n suc m ≟ suc .m | yes refl = yes refl suc m ≟ suc n | no prf = no (prf ∘ cong pred) zero ≟ suc n = no λ() suc m ≟ zero = no λ() open Imports -- Begin of actual example! record Eq (A : Set) : Set where field eq : A → A → Bool primEqBool : Bool → Bool → Bool primEqBool true = id primEqBool false = not eqBool : Eq Bool eqBool = record { eq = primEqBool } primEqNat : ℕ → ℕ → Bool primEqNat a b = ⌊ a ≟ b ⌋ primLtNat : ℕ → ℕ → Bool primLtNat 0 _ = true primLtNat (suc a) (suc b) = primLtNat a b primLtNat _ _ = false neq : {t : Set} → {{eqT : Eq t}} → t → t → Bool neq a b = not $ eq a b where open Eq {{...}} record Ord₁ (A : Set) : Set where field _<_ : A → A → Bool eqA : Eq A ord₁Nat : Ord₁ ℕ ord₁Nat = record { _<_ = primLtNat; eqA = eqNat } where eqNat : Eq ℕ eqNat = record { eq = primEqNat } record Ord₂ {A : Set} (eqA : Eq A) : Set where field _<_ : A → A → Bool ord₂Nat : Ord₂ (record { eq = primEqNat }) ord₂Nat = record { _<_ = primLtNat } record Ord₃ (A : Set) : Set where field _<_ : A → A → Bool eqA : Eq A open Eq eqA public ord₃Nat : Ord₃ ℕ ord₃Nat = record { _<_ = primLtNat; eqA = eqNat } where eqNat : Eq ℕ eqNat = record { eq = primEqNat } record Ord₄ {A : Set} (eqA : Eq A) : Set where field _<_ : A → A → Bool open Eq eqA public ord₄Nat : Ord₄ (record { eq = primEqNat }) ord₄Nat = record { _<_ = primLtNat } module test₁ where open Ord₁ {{...}} open Eq {{...}} eqNat : Eq _ eqNat = eqA test₁ = 5 < 3 test₂ = eq 5 3 test₃ = eq true false test₄ : {A : Set} → {{ ordA : Ord₁ A }} → A → A → Bool test₄ a b = a < b ∨ eq a b where eqA' : Eq _ eqA' = eqA module test₂ where open Ord₂ {{...}} open Eq {{...}} eqNat : Eq ℕ eqNat = record { eq = primEqNat } test₁ = 5 < 3 test₂ = eq 5 3 test₃ = eq true false test₄ : {A : Set} → {eqA : Eq A} → {{ ordA : Ord₂ eqA }} → A → A → Bool test₄ {eqA = _} a b = a < b ∨ eq a b module test₃ where open Ord₃ {{...}} open Eq {{...}} renaming (eq to eq') test₁ = 5 < 3 test₂ = eq 5 3 test₃ = eq' true false test₄ : {A : Set} → {{ ordA : Ord₃ A }} → A → A → Bool test₄ a b = a < b ∨ eq a b module test₄ where open Ord₄ {{...}} open Eq {{...}} renaming (eq to eq') test₁ = 5 < 3 test₂ = eq 5 3 test₃ = eq' true false test₄ : {A : Set} → {eqA : Eq A} → {{ ordA : Ord₄ eqA }} → A → A → Bool test₄ a b = a < b ∨ eq a b module test₄′ where open Ord₄ {{...}} hiding (eq) open Eq {{...}} eqNat : Eq ℕ eqNat = record { eq = primEqNat } test₁ = 5 < 3 test₂ = eq 5 3 test₃ = eq true false test₄ : {A : Set} → {eqA : Eq A} → {{ ordA : Ord₄ eqA }} → A → A → Bool test₄ {eqA = _} a b = a < b ∨ eq a b
22.242152
73
0.516532
59fd394fc1bdfed7bb06c2e9662f449f9f87351f
4,268
agda
Agda
src/Util/Relation/Binary/PropositionalEquality.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
5
2021-04-13T21:31:17.000Z
2021-06-26T06:37:31.000Z
src/Util/Relation/Binary/PropositionalEquality.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
src/Util/Relation/Binary/PropositionalEquality.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Util.Relation.Binary.PropositionalEquality where open import Relation.Binary.PropositionalEquality public open import Data.Product using (uncurry) open import Util.Prelude private variable α β γ γ′ δ : Level A B C A′ B′ C′ : Set α trans-unassoc : {a b c d : A} (p : a ≡ b) {q : b ≡ c} {r : c ≡ d} → trans p (trans q r) ≡ trans (trans p q) r trans-unassoc p = sym (trans-assoc p) Σ-≡⁻ : {A : Set α} {B : A → Set β} {x y : Σ A B} → x ≡ y → Σ[ p ∈ (proj₁ x ≡ proj₁ y) ] subst B p (proj₂ x) ≡ proj₂ y Σ-≡⁻ refl = refl , refl Σ-≡⁺ : {A : Set α} {B : A → Set β} {x y : Σ A B} → Σ[ p ∈ (proj₁ x ≡ proj₁ y) ] subst B p (proj₂ x) ≡ proj₂ y → x ≡ y Σ-≡⁺ (refl , refl) = refl Σ-≡⁺∘Σ-≡⁻ : {A : Set α} {B : A → Set β} {x y : Σ A B} → (p : x ≡ y) → Σ-≡⁺ (Σ-≡⁻ p) ≡ p Σ-≡⁺∘Σ-≡⁻ refl = refl Σ-≡⁻∘Σ-≡⁺ : {A : Set α} {B : A → Set β} {x y : Σ A B} → (p : Σ[ p ∈ (proj₁ x ≡ proj₁ y) ] subst B p (proj₂ x) ≡ proj₂ y) → Σ-≡⁻ (Σ-≡⁺ p) ≡ p Σ-≡⁻∘Σ-≡⁺ (refl , refl) = refl ×-≡⁺ : {x y : A × B} → (proj₁ x ≡ proj₁ y) × (proj₂ x ≡ proj₂ y) → x ≡ y ×-≡⁺ (refl , refl) = refl ×-≡⁻ : {x y : A × B} → x ≡ y → (proj₁ x ≡ proj₁ y) × (proj₂ x ≡ proj₂ y) ×-≡⁻ refl = refl , refl ×-≡⁺∘×-≡⁻ : {x y : A × B} (p : x ≡ y) → ×-≡⁺ (×-≡⁻ p) ≡ p ×-≡⁺∘×-≡⁻ refl = refl ×-≡⁻∘×-≡⁺ : {x y : A × B} (p : (proj₁ x ≡ proj₁ y) × (proj₂ x ≡ proj₂ y)) → ×-≡⁻ (×-≡⁺ p) ≡ p ×-≡⁻∘×-≡⁺ (refl , refl) = refl cast : A ≡ B → A → B cast = subst (λ x → x) cast-refl : {x : A} → cast refl x ≡ x cast-refl = refl cast-trans : (B≡C : B ≡ C) (A≡B : A ≡ B) {x : A} → cast B≡C (cast A≡B x) ≡ cast (trans A≡B B≡C) x cast-trans refl refl = refl subst-trans : ∀ {P : A → Set β} {x y z : A} {p : P x} → (x≡y : x ≡ y) (y≡z : y ≡ z) → subst P y≡z (subst P x≡y p) ≡ subst P (trans x≡y y≡z) p subst-trans refl refl = refl subst₂-trans : (C : A → B → Set γ) → {a₀ a₁ a₂ : A} (p : a₀ ≡ a₁) (p′ : a₁ ≡ a₂) → {b₀ b₁ b₂ : B} (q : b₀ ≡ b₁) (q′ : b₁ ≡ b₂) → {x : C a₀ b₀} → subst₂ C p′ q′ (subst₂ C p q x) ≡ subst₂ C (trans p p′) (trans q q′) x subst₂-trans C refl refl refl refl = refl subst₂-subst₂-sym : (C : A → B → Set γ) → {a a′ : A} (p : a ≡ a′) → {b b′ : B} (q : b ≡ b′) → {x : C a′ b′} → subst₂ C p q (subst₂ C (sym p) (sym q) x) ≡ x subst₂-subst₂-sym C refl refl = refl subst₂-sym-subst₂ : (C : A → B → Set γ) → {a a′ : A} (p : a ≡ a′) → {b b′ : B} (q : b ≡ b′) → {x : C a b} → subst₂ C (sym p) (sym q) (subst₂ C p q x) ≡ x subst₂-sym-subst₂ C refl refl = refl subst₂-cong : (C : A′ → B′ → Set γ) → (f : A → A′) (g : B → B′) → {a a′ : A} (p : a ≡ a′) → {b b′ : B} (q : b ≡ b′) → {x : C (f a) (g b)} → subst₂ C (cong f p) (cong g q) x ≡ subst₂ (λ a b → C (f a) (g b)) p q x subst₂-cong C f g refl refl = refl subst₂≡subst : ∀ {la} {A : Set la} {lb} {B : Set lb} {lc} (C : A → B → Set lc) → ∀ {a a′} (p : a ≡ a′) {b b′} (q : b ≡ b′) {x : C a b} → subst₂ C p q x ≡ subst (uncurry C) (cong₂ _,_ p q) x subst₂≡subst C refl refl = refl subst₂-application : (C : A → B → Set γ) {C′ : A′ → B′ → Set γ′} → {fa : A′ → A} {fb : B′ → B} → {a a′ : A′} {b b′ : B′} {c : C (fa a) (fb b)} → (g : ∀ a b → C (fa a) (fb b) → C′ a b) → (eqa : a ≡ a′) → (eqb : b ≡ b′) → subst₂ C′ eqa eqb (g a b c) ≡ g a′ b′ (subst₂ C (cong fa eqa) (cong fb eqb) c) subst₂-application _ _ refl refl = refl subst₂-application′ : {C : A → B → Set γ} (C′ : A′ → B′ → Set γ′) → {fa : A → A′} {fb : B → B′} → {a a′ : A} {b b′ : B} {c : C a b} → (g : ∀ a b → C a b → C′ (fa a) (fb b)) → (eqa : a ≡ a′) → (eqb : b ≡ b′) → subst₂ C′ (cong fa eqa) (cong fb eqb) (g a b c) ≡ g a′ b′ (subst₂ C eqa eqb c) subst₂-application′ _ _ refl refl = refl cong₂-dep : {A : Set α} {B : A → Set β} {C : Set γ} → (f : (a : A) → B a → C) → {x y : A} (p : x ≡ y) → {u : B x} {v : B y} (q : subst B p u ≡ v) → f x u ≡ f y v cong₂-dep f refl refl = refl cong₃-dep : {A : Set α} {B : A → Set β} {C : (a : A) → B a → Set γ} → {D : Set δ} → (f : (a : A) (b : B a) → C a b → D) → {x y : A} (p : x ≡ y) → {u : B x} {v : B y} (q : subst B p u ≡ v) → {w : C x u} {z : C y v} (r : subst (λ i → C (proj₁ i) (proj₂ i)) (Σ-≡⁺ (p , q)) w ≡ z) → f x u w ≡ f y v z cong₃-dep f refl refl refl = refl
26.02439
90
0.447751
4131eadba26c7a758ad5239ae4cc8047f7e3248d
11,056
agda
Agda
Cubical/Papers/RepresentationIndependence.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
null
null
null
Cubical/Papers/RepresentationIndependence.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
null
null
null
Cubical/Papers/RepresentationIndependence.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{- Please do not move this file. Changes should only be made if necessary. This file contains pointers to the code examples and main results from the paper: Internalizing Representation Independence with Univalence Carlo Angiuli, Evan Cavallo, Anders Mörtberg, Max Zeuner Preprint: https://arxiv.org/abs/2009.05547 -} {-# OPTIONS --safe #-} module Cubical.Papers.RepresentationIndependence where -- 2.1 import Agda.Builtin.Cubical.Path as Path import Cubical.Foundations.Prelude as Prelude -- 2.2 import Cubical.Foundations.Univalence as Univalence import Cubical.Foundations.HLevels as HLevels import Cubical.Foundations.Equiv as Equivalences import Cubical.Data.Sigma.Properties as Sigma -- 2.3 import Cubical.HITs.PropositionalTruncation as PropositionalTruncation import Cubical.HITs.Cost.Base as CostMonad import Cubical.HITs.SetQuotients as SetQuotients import Cubical.HITs.Rationals.QuoQ as SetQuoQ import Cubical.HITs.Rationals.SigmaQ as SigmaQ -- 3.1 import Cubical.Foundations.SIP as SIP import Cubical.Structures.Axioms as Axioms import Cubical.Algebra.Semigroup.Base as Semigroup open import Cubical.Data.Sigma.Base -- 3.2 import Cubical.Structures.Pointed as PointedStr import Cubical.Structures.Constant as ConstantStr import Cubical.Structures.Product as ProductStr import Cubical.Structures.Function as FunctionStr import Cubical.Structures.Maybe as MaybeStr import Cubical.Foundations.Structure as Structure import Cubical.Structures.Auto as Auto open import Cubical.Data.Maybe.Base -- 4.1 import Cubical.Data.Vec.Base as Vector import Cubical.Algebra.Matrix as Matrices import Cubical.Data.FinData.Base as Finite open import Cubical.Algebra.AbGroup.Base open import Cubical.Data.Bool.Base -- 4.2 import Cubical.Structures.Queue as Queues import Cubical.Data.Queue.Truncated2List as BatchedQueues -- 5.1 import Cubical.Relation.Binary.Base as BinRel import Cubical.Relation.ZigZag.Base as QER import Cubical.Relation.ZigZag.Applications.MultiSet as MultiSets -- 5.2 import Cubical.Foundations.RelationalStructure as RelStructure import Cubical.Structures.Relational.Function as RelFunction ------------------------------------------------------------------------- -- 2. Programming in Cubical Type Theory -- 2.1 Equalities as Paths -- 2.2 Univalence -- 2.3 Higher Inductive Types ------------------------------------------------------------------------- -- 2.1 Equalities as Paths open Path using (PathP) public open Prelude using (_≡_ ; refl ; cong ; funExt ; transport ; subst ; J) public -- 2.2 Univalence open Univalence using (ua ; uaβ) public -- Sets and Propositions open Prelude using (isProp ; isSet) public open HLevels using (isPropΠ) public open Prelude using (isContr) public -- Equivalences and Isomorphisms open Equivalences using (isEquiv ; _≃_) public open Equivalences renaming (fiber to preim) public open Sigma using (ΣPath≃PathΣ) public open Equivalences renaming (propBiimpl→Equiv to prop≃) public -- 2.3 Higher Inductive Types -- Propositional Truncation open PropositionalTruncation using (∥_∥ ; map) public open CostMonad using (Cost ; Cost≡ ; _>>=_ ; return ; fib ; fibTail) public -- Computation _ : fib 20 ≡ (6765 , PropositionalTruncation.∣ 21890 ∣) _ = refl _ : fibTail 20 ≡ (6765 , PropositionalTruncation.∣ 19 ∣) _ = refl -- Set Quotients open SetQuotients using (_/_ ; setQuotUniversal) public -- Rational Numbers open SetQuoQ using (_∼_ ; ℚ) public open SigmaQ renaming (ℚ to ℚ') public ------------------------------------------------------------------------- -- 3. The Structure Identity Principle -- 3.1 Structures -- 3.2 Building Strucutres ------------------------------------------------------------------------- -- 3.1 Structures open SIP using (TypeWithStr ; StrEquiv ; _≃[_]_ ; UnivalentStr ; SIP ; sip) public -- the last two terms above correspond to lemma 3.3 -- and corollary 3.4 respectively open Axioms using ( AxiomsStructure ; AxiomsEquivStr ; axiomsUnivalentStr ; transferAxioms) public -- Monoids are defined using records and Σ-types in the library RawMonoidStructure : Type → Type RawMonoidStructure X = X × (X → X → X) MonoidAxioms : (M : Type) → RawMonoidStructure M → Type MonoidAxioms M (e , _·_) = Semigroup.IsSemigroup _·_ × ((x : M) → (x · e ≡ x) × (e · x ≡ x)) MonoidStructure : Type → Type MonoidStructure = AxiomsStructure RawMonoidStructure MonoidAxioms Monoid : Type₁ Monoid = TypeWithStr ℓ-zero MonoidStructure MonoidEquiv : (M N : Monoid) → fst M ≃ fst N → Type MonoidEquiv (_ , (εᴹ , _·_) , _) (_ , (εᴺ , _∗_) , _) (φ , _) = (φ εᴹ ≡ εᴺ) × (∀ x y → φ (x · y) ≡ (φ x) ∗ (φ y)) -- 3.2 Building Structures -- Constant and Pointed Structures open PointedStr using (PointedStructure ; PointedEquivStr ; pointedUnivalentStr) public open ConstantStr using (ConstantStructure ; ConstantEquivStr ; constantUnivalentStr) public -- Product Structures open ProductStr using (ProductStructure ; ProductEquivStr ; productUnivalentStr) public -- Function Structures open FunctionStr using (FunctionEquivStr) public -- Maybe Structures open MaybeStr using (MaybeEquivStr) public -- Transport Structures open Structure using (EquivAction) public open SIP using (TransportStr ; TransportStr→UnivalentStr ; UnivalentStr→TransportStr) public open Structure using (EquivAction→StrEquiv) public open FunctionStr using (FunctionEquivStr+) public -- Monoids Revisited RawMonoid : Type₁ RawMonoid = TypeWithStr _ RawMonoidStructure Monoid→RawMonoid : Monoid → RawMonoid Monoid→RawMonoid (A , r , _) = (A , r) RawMonoidEquivStr = Auto.AutoEquivStr RawMonoidStructure rawMonoidUnivalentStr : UnivalentStr _ RawMonoidEquivStr rawMonoidUnivalentStr = Auto.autoUnivalentStr RawMonoidStructure isPropMonoidAxioms : (M : Type) (s : RawMonoidStructure M) → isProp (MonoidAxioms M s) isPropMonoidAxioms M (e , _·_) = HLevels.isPropΣ (Semigroup.isPropIsSemigroup _·_) (λ α → isPropΠ λ _ → HLevels.isProp× (Semigroup.IsSemigroup.is-set α _ _) (Semigroup.IsSemigroup.is-set α _ _)) MonoidEquivStr : StrEquiv MonoidStructure ℓ-zero MonoidEquivStr = AxiomsEquivStr RawMonoidEquivStr MonoidAxioms monoidUnivalentStr : UnivalentStr MonoidStructure MonoidEquivStr monoidUnivalentStr = axiomsUnivalentStr _ isPropMonoidAxioms rawMonoidUnivalentStr MonoidΣPath : (M N : Monoid) → (M ≃[ MonoidEquivStr ] N) ≃ (M ≡ N) MonoidΣPath = SIP monoidUnivalentStr InducedMonoid : (M : Monoid) (N : RawMonoid) (e : M .fst ≃ N .fst) → RawMonoidEquivStr (Monoid→RawMonoid M) N e → Monoid InducedMonoid M N e r = Axioms.inducedStructure rawMonoidUnivalentStr M N (e , r) InducedMonoidPath : (M : Monoid) (N : RawMonoid) (e : M .fst ≃ N .fst) (E : RawMonoidEquivStr (Monoid→RawMonoid M) N e) → M ≡ InducedMonoid M N e E InducedMonoidPath M N e E = MonoidΣPath M (InducedMonoid M N e E) .fst (e , E) -- Automation open Auto using (Transp[_] ; AutoEquivStr ; autoUnivalentStr) public module _ (A : Type) (Aset : isSet A) where RawQueueEquivStr = AutoEquivStr (λ (X : Type) → X × (A → X → X) × (X → Transp[ Maybe (X × A) ])) ------------------------------------------------------------------------- -- 4. Representation Independence through the SIP -- 4.1 Matrices -- 4.2 Queues ------------------------------------------------------------------------- -- 4.1 Matrices open Vector using (Vec) public open Finite using (Fin ; _==_) public open Matrices using (VecMatrix ; FinMatrix ; FinMatrix≡VecMatrix ; FinMatrix≃VecMatrix) public open Matrices.FinMatrixAbGroup using (addFinMatrix ; addFinMatrixComm) public -- example (not in the library) open import Cubical.Data.Int renaming (Int to ℤ ; isSetInt to isSetℤ) hiding (-_) ℤ-AbGroup : AbGroup ℓ-zero ℤ-AbGroup = makeAbGroup {G = ℤ} 0 _+_ -_ isSetℤ +-assoc (λ x _ → x) rem +-comm where -_ : ℤ → ℤ - x = 0 - x rem : (x : ℤ) → x + (- x) ≡ 0 rem x = +-comm x (pos 0 - x) Prelude.∙ minusPlus x 0 module experiment where open Prelude M : FinMatrix ℤ 2 2 M i j = if i == j then 1 else 0 N : FinMatrix ℤ 2 2 N i j = if i == j then 0 else 1 replaceGoal : {A B : Type} {x y : A} → (e : A ≃ B) (h : invEq e (equivFun e x) ≡ invEq e (equivFun e y)) → x ≡ y replaceGoal e h = sym (retEq e _) ∙∙ h ∙∙ retEq e _ _ : addFinMatrix ℤ-AbGroup M N ≡ (λ _ _ → 1) _ = replaceGoal (FinMatrix≃VecMatrix) refl -- 4.2 Queues open Queues.Queues-on using (RawQueueStructure ; QueueAxioms) public open BatchedQueues.Truncated2List renaming (Q to BatchedQueueHIT) using (Raw-1≡2 ; WithLaws) public ------------------------------------------------------------------------- -- 5. Structured Equivalences from Structured Relations -- 5.1 Quasi-Equivalence Relations -- 5.2 Structured Relations ------------------------------------------------------------------------- -- 5.1 Quasi-Equivalence Relations --Lemma (5.1) open BinRel using (idPropRel ; invPropRel ; compPropRel ; graphRel) public -- Definitions (5.2) and (5.3) open QER using (isZigZagComplete ; isQuasiEquivRel) public -- Lemma (5.4) open QER.QER→Equiv using (Thm ; bwd≡ToRel) public -- Multisets open MultiSets renaming (AList to AssocList) public open MultiSets.Lists&ALists using (addIfEq ; R ; φ ; ψ ; List/Rᴸ≃AList/Rᴬᴸ) public open MultiSets.Lists&ALists.L using (insert ; union ; count) open MultiSets.Lists&ALists.AL using (insert ; union ; count) -- 5.2 Structured Relations open RelStructure using (StrRel) public -- Definition (5.6) open RelStructure using (SuitableStrRel) public -- Theorem (5.7) open RelStructure using (structuredQER→structuredEquiv) public -- Definition (5.9) open RelStructure using (StrRelAction) public -- Lemma (5.10) open RelStructure using (strRelQuotientComparison) public -- Definition (5.11) open RelStructure using (PositiveStrRel) public -- Theorem (5.12) open RelFunction using (functionSuitableRel) public -- Multisets -- (main is applying 5.7 to the example) open MultiSets.Lists&ALists using (multisetShape ; isStructuredR ; main ; List/Rᴸ≡AList/Rᴬᴸ) renaming ( hasAssociativeUnion to unionAssocAxiom ; LQassoc to LUnionAssoc ; ALQassoc to ALUnionAssoc) public
35.098413
92
0.642004
59777234898c6af8830dc56651fa8649fac45a8d
15,978
agda
Agda
src/data/lib/prim/Agda/Builtin/Reflection.agda
sseefried/agda
6b13364d36eeb60d8ec15eaf8effe23c73401900
[ "BSD-2-Clause" ]
1
2022-03-05T00:25:14.000Z
2022-03-05T00:25:14.000Z
src/data/lib/prim/Agda/Builtin/Reflection.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
src/data/lib/prim/Agda/Builtin/Reflection.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-} module Agda.Builtin.Reflection where open import Agda.Builtin.Unit open import Agda.Builtin.Bool open import Agda.Builtin.Nat open import Agda.Builtin.Word open import Agda.Builtin.List open import Agda.Builtin.String open import Agda.Builtin.Char open import Agda.Builtin.Float open import Agda.Builtin.Int open import Agda.Builtin.Sigma open import Agda.Primitive -- Names -- postulate Name : Set {-# BUILTIN QNAME Name #-} primitive primQNameEquality : Name → Name → Bool primQNameLess : Name → Name → Bool primShowQName : Name → String -- Fixity -- data Associativity : Set where left-assoc : Associativity right-assoc : Associativity non-assoc : Associativity data Precedence : Set where related : Float → Precedence unrelated : Precedence data Fixity : Set where fixity : Associativity → Precedence → Fixity {-# BUILTIN ASSOC Associativity #-} {-# BUILTIN ASSOCLEFT left-assoc #-} {-# BUILTIN ASSOCRIGHT right-assoc #-} {-# BUILTIN ASSOCNON non-assoc #-} {-# BUILTIN PRECEDENCE Precedence #-} {-# BUILTIN PRECRELATED related #-} {-# BUILTIN PRECUNRELATED unrelated #-} {-# BUILTIN FIXITY Fixity #-} {-# BUILTIN FIXITYFIXITY fixity #-} {-# COMPILE GHC Associativity = data MAlonzo.RTE.Assoc (MAlonzo.RTE.LeftAssoc | MAlonzo.RTE.RightAssoc | MAlonzo.RTE.NonAssoc) #-} {-# COMPILE GHC Precedence = data MAlonzo.RTE.Precedence (MAlonzo.RTE.Related | MAlonzo.RTE.Unrelated) #-} {-# COMPILE GHC Fixity = data MAlonzo.RTE.Fixity (MAlonzo.RTE.Fixity) #-} {-# COMPILE JS Associativity = function (x,v) { return v[x](); } #-} {-# COMPILE JS left-assoc = "left-assoc" #-} {-# COMPILE JS right-assoc = "right-assoc" #-} {-# COMPILE JS non-assoc = "non-assoc" #-} {-# COMPILE JS Precedence = function (x,v) { if (x === "unrelated") { return v[x](); } else { return v["related"](x); }} #-} {-# COMPILE JS related = function(x) { return x; } #-} {-# COMPILE JS unrelated = "unrelated" #-} {-# COMPILE JS Fixity = function (x,v) { return v["fixity"](x["assoc"], x["prec"]); } #-} {-# COMPILE JS fixity = function (x) { return function (y) { return { "assoc": x, "prec": y}; }; } #-} primitive primQNameFixity : Name → Fixity primQNameToWord64s : Name → Σ Word64 (λ _ → Word64) -- Metavariables -- postulate Meta : Set {-# BUILTIN AGDAMETA Meta #-} primitive primMetaEquality : Meta → Meta → Bool primMetaLess : Meta → Meta → Bool primShowMeta : Meta → String primMetaToNat : Meta → Nat -- Arguments -- -- Arguments can be (visible), {hidden}, or {{instance}}. data Visibility : Set where visible hidden instance′ : Visibility {-# BUILTIN HIDING Visibility #-} {-# BUILTIN VISIBLE visible #-} {-# BUILTIN HIDDEN hidden #-} {-# BUILTIN INSTANCE instance′ #-} -- Arguments can be relevant or irrelevant. data Relevance : Set where relevant irrelevant : Relevance {-# BUILTIN RELEVANCE Relevance #-} {-# BUILTIN RELEVANT relevant #-} {-# BUILTIN IRRELEVANT irrelevant #-} -- Arguments also have a quantity. data Quantity : Set where quantity-0 quantity-ω : Quantity {-# BUILTIN QUANTITY Quantity #-} {-# BUILTIN QUANTITY-0 quantity-0 #-} {-# BUILTIN QUANTITY-ω quantity-ω #-} -- Relevance and quantity are combined into a modality. data Modality : Set where modality : (r : Relevance) (q : Quantity) → Modality {-# BUILTIN MODALITY Modality #-} {-# BUILTIN MODALITY-CONSTRUCTOR modality #-} data ArgInfo : Set where arg-info : (v : Visibility) (m : Modality) → ArgInfo data Arg {a} (A : Set a) : Set a where arg : (i : ArgInfo) (x : A) → Arg A {-# BUILTIN ARGINFO ArgInfo #-} {-# BUILTIN ARGARGINFO arg-info #-} {-# BUILTIN ARG Arg #-} {-# BUILTIN ARGARG arg #-} -- Name abstraction -- data Abs {a} (A : Set a) : Set a where abs : (s : String) (x : A) → Abs A {-# BUILTIN ABS Abs #-} {-# BUILTIN ABSABS abs #-} -- Literals -- data Literal : Set where nat : (n : Nat) → Literal word64 : (n : Word64) → Literal float : (x : Float) → Literal char : (c : Char) → Literal string : (s : String) → Literal name : (x : Name) → Literal meta : (x : Meta) → Literal {-# BUILTIN AGDALITERAL Literal #-} {-# BUILTIN AGDALITNAT nat #-} {-# BUILTIN AGDALITWORD64 word64 #-} {-# BUILTIN AGDALITFLOAT float #-} {-# BUILTIN AGDALITCHAR char #-} {-# BUILTIN AGDALITSTRING string #-} {-# BUILTIN AGDALITQNAME name #-} {-# BUILTIN AGDALITMETA meta #-} -- Terms and patterns -- data Term : Set data Sort : Set data Pattern : Set data Clause : Set Type = Term Telescope = List (Σ String λ _ → Arg Type) data Term where var : (x : Nat) (args : List (Arg Term)) → Term con : (c : Name) (args : List (Arg Term)) → Term def : (f : Name) (args : List (Arg Term)) → Term lam : (v : Visibility) (t : Abs Term) → Term pat-lam : (cs : List Clause) (args : List (Arg Term)) → Term pi : (a : Arg Type) (b : Abs Type) → Term agda-sort : (s : Sort) → Term lit : (l : Literal) → Term meta : (x : Meta) → List (Arg Term) → Term unknown : Term data Sort where set : (t : Term) → Sort lit : (n : Nat) → Sort prop : (t : Term) → Sort propLit : (n : Nat) → Sort inf : (n : Nat) → Sort unknown : Sort data Pattern where con : (c : Name) (ps : List (Arg Pattern)) → Pattern dot : (t : Term) → Pattern var : (x : Nat) → Pattern lit : (l : Literal) → Pattern proj : (f : Name) → Pattern absurd : (x : Nat) → Pattern -- absurd patterns counts as variables data Clause where clause : (tel : Telescope) (ps : List (Arg Pattern)) (t : Term) → Clause absurd-clause : (tel : Telescope) (ps : List (Arg Pattern)) → Clause {-# BUILTIN AGDATERM Term #-} {-# BUILTIN AGDASORT Sort #-} {-# BUILTIN AGDAPATTERN Pattern #-} {-# BUILTIN AGDACLAUSE Clause #-} {-# BUILTIN AGDATERMVAR var #-} {-# BUILTIN AGDATERMCON con #-} {-# BUILTIN AGDATERMDEF def #-} {-# BUILTIN AGDATERMMETA meta #-} {-# BUILTIN AGDATERMLAM lam #-} {-# BUILTIN AGDATERMEXTLAM pat-lam #-} {-# BUILTIN AGDATERMPI pi #-} {-# BUILTIN AGDATERMSORT agda-sort #-} {-# BUILTIN AGDATERMLIT lit #-} {-# BUILTIN AGDATERMUNSUPPORTED unknown #-} {-# BUILTIN AGDASORTSET set #-} {-# BUILTIN AGDASORTLIT lit #-} {-# BUILTIN AGDASORTPROP prop #-} {-# BUILTIN AGDASORTPROPLIT propLit #-} {-# BUILTIN AGDASORTINF inf #-} {-# BUILTIN AGDASORTUNSUPPORTED unknown #-} {-# BUILTIN AGDAPATCON con #-} {-# BUILTIN AGDAPATDOT dot #-} {-# BUILTIN AGDAPATVAR var #-} {-# BUILTIN AGDAPATLIT lit #-} {-# BUILTIN AGDAPATPROJ proj #-} {-# BUILTIN AGDAPATABSURD absurd #-} {-# BUILTIN AGDACLAUSECLAUSE clause #-} {-# BUILTIN AGDACLAUSEABSURD absurd-clause #-} -- Definitions -- data Definition : Set where function : (cs : List Clause) → Definition data-type : (pars : Nat) (cs : List Name) → Definition record-type : (c : Name) (fs : List (Arg Name)) → Definition data-cons : (d : Name) → Definition axiom : Definition prim-fun : Definition {-# BUILTIN AGDADEFINITION Definition #-} {-# BUILTIN AGDADEFINITIONFUNDEF function #-} {-# BUILTIN AGDADEFINITIONDATADEF data-type #-} {-# BUILTIN AGDADEFINITIONRECORDDEF record-type #-} {-# BUILTIN AGDADEFINITIONDATACONSTRUCTOR data-cons #-} {-# BUILTIN AGDADEFINITIONPOSTULATE axiom #-} {-# BUILTIN AGDADEFINITIONPRIMITIVE prim-fun #-} -- Errors -- data ErrorPart : Set where strErr : String → ErrorPart termErr : Term → ErrorPart pattErr : Pattern → ErrorPart nameErr : Name → ErrorPart {-# BUILTIN AGDAERRORPART ErrorPart #-} {-# BUILTIN AGDAERRORPARTSTRING strErr #-} {-# BUILTIN AGDAERRORPARTTERM termErr #-} {-# BUILTIN AGDAERRORPARTPATT pattErr #-} {-# BUILTIN AGDAERRORPARTNAME nameErr #-} -- TC monad -- postulate TC : ∀ {a} → Set a → Set a returnTC : ∀ {a} {A : Set a} → A → TC A bindTC : ∀ {a b} {A : Set a} {B : Set b} → TC A → (A → TC B) → TC B unify : Term → Term → TC ⊤ typeError : ∀ {a} {A : Set a} → List ErrorPart → TC A inferType : Term → TC Type checkType : Term → Type → TC Term normalise : Term → TC Term reduce : Term → TC Term catchTC : ∀ {a} {A : Set a} → TC A → TC A → TC A quoteTC : ∀ {a} {A : Set a} → A → TC Term unquoteTC : ∀ {a} {A : Set a} → Term → TC A quoteωTC : ∀ {A : Setω} → A → TC Term getContext : TC Telescope extendContext : ∀ {a} {A : Set a} → String → Arg Type → TC A → TC A inContext : ∀ {a} {A : Set a} → Telescope → TC A → TC A freshName : String → TC Name declareDef : Arg Name → Type → TC ⊤ declarePostulate : Arg Name → Type → TC ⊤ defineFun : Name → List Clause → TC ⊤ getType : Name → TC Type getDefinition : Name → TC Definition blockOnMeta : ∀ {a} {A : Set a} → Meta → TC A commitTC : TC ⊤ isMacro : Name → TC Bool -- If the argument is 'true' makes the following primitives also normalise -- their results: inferType, checkType, quoteTC, getType, and getContext withNormalisation : ∀ {a} {A : Set a} → Bool → TC A → TC A -- Makes the following primitives to reconstruct hidden arguments -- getDefinition, normalise, reduce, inferType, checkType and getContext withReconstructed : ∀ {a} {A : Set a} → TC A → TC A formatErrorParts : List ErrorPart → TC String -- Prints the third argument if the corresponding verbosity level is turned -- on (with the -v flag to Agda). debugPrint : String → Nat → List ErrorPart → TC ⊤ -- Only allow reduction of specific definitions while executing the TC computation onlyReduceDefs : ∀ {a} {A : Set a} → List Name → TC A → TC A -- Don't allow reduction of specific definitions while executing the TC computation dontReduceDefs : ∀ {a} {A : Set a} → List Name → TC A → TC A -- Fail if the given computation gives rise to new, unsolved -- "blocking" constraints. noConstraints : ∀ {a} {A : Set a} → TC A → TC A -- Run the given TC action and return the first component. Resets to -- the old TC state if the second component is 'false', or keep the -- new TC state if it is 'true'. runSpeculative : ∀ {a} {A : Set a} → TC (Σ A λ _ → Bool) → TC A -- Get a list of all possible instance candidates for the given meta -- variable (it does not have to be an instance meta). getInstances : Meta → TC (List Term) {-# BUILTIN AGDATCM TC #-} {-# BUILTIN AGDATCMRETURN returnTC #-} {-# BUILTIN AGDATCMBIND bindTC #-} {-# BUILTIN AGDATCMUNIFY unify #-} {-# BUILTIN AGDATCMTYPEERROR typeError #-} {-# BUILTIN AGDATCMINFERTYPE inferType #-} {-# BUILTIN AGDATCMCHECKTYPE checkType #-} {-# BUILTIN AGDATCMNORMALISE normalise #-} {-# BUILTIN AGDATCMREDUCE reduce #-} {-# BUILTIN AGDATCMCATCHERROR catchTC #-} {-# BUILTIN AGDATCMQUOTETERM quoteTC #-} {-# BUILTIN AGDATCMUNQUOTETERM unquoteTC #-} {-# BUILTIN AGDATCMQUOTEOMEGATERM quoteωTC #-} {-# BUILTIN AGDATCMGETCONTEXT getContext #-} {-# BUILTIN AGDATCMEXTENDCONTEXT extendContext #-} {-# BUILTIN AGDATCMINCONTEXT inContext #-} {-# BUILTIN AGDATCMFRESHNAME freshName #-} {-# BUILTIN AGDATCMDECLAREDEF declareDef #-} {-# BUILTIN AGDATCMDECLAREPOSTULATE declarePostulate #-} {-# BUILTIN AGDATCMDEFINEFUN defineFun #-} {-# BUILTIN AGDATCMGETTYPE getType #-} {-# BUILTIN AGDATCMGETDEFINITION getDefinition #-} {-# BUILTIN AGDATCMBLOCKONMETA blockOnMeta #-} {-# BUILTIN AGDATCMCOMMIT commitTC #-} {-# BUILTIN AGDATCMISMACRO isMacro #-} {-# BUILTIN AGDATCMWITHNORMALISATION withNormalisation #-} {-# BUILTIN AGDATCMFORMATERRORPARTS formatErrorParts #-} {-# BUILTIN AGDATCMDEBUGPRINT debugPrint #-} {-# BUILTIN AGDATCMONLYREDUCEDEFS onlyReduceDefs #-} {-# BUILTIN AGDATCMDONTREDUCEDEFS dontReduceDefs #-} {-# BUILTIN AGDATCMWITHRECONSPARAMS withReconstructed #-} {-# BUILTIN AGDATCMNOCONSTRAINTS noConstraints #-} {-# BUILTIN AGDATCMRUNSPECULATIVE runSpeculative #-} {-# BUILTIN AGDATCMGETINSTANCES getInstances #-} -- All the TC primitives are compiled to functions that return -- undefined, rather than just undefined, in an attempt to make sure -- that code will run properly. {-# COMPILE JS returnTC = _ => _ => _ => undefined #-} {-# COMPILE JS bindTC = _ => _ => _ => _ => _ => _ => undefined #-} {-# COMPILE JS unify = _ => _ => undefined #-} {-# COMPILE JS typeError = _ => _ => _ => undefined #-} {-# COMPILE JS inferType = _ => undefined #-} {-# COMPILE JS checkType = _ => _ => undefined #-} {-# COMPILE JS normalise = _ => undefined #-} {-# COMPILE JS reduce = _ => undefined #-} {-# COMPILE JS catchTC = _ => _ => _ => _ => undefined #-} {-# COMPILE JS quoteTC = _ => _ => _ => undefined #-} {-# COMPILE JS unquoteTC = _ => _ => _ => undefined #-} {-# COMPILE JS quoteωTC = _ => _ => undefined #-} {-# COMPILE JS getContext = undefined #-} {-# COMPILE JS extendContext = _ => _ => _ => _ => _ => undefined #-} {-# COMPILE JS inContext = _ => _ => _ => _ => undefined #-} {-# COMPILE JS freshName = _ => undefined #-} {-# COMPILE JS declareDef = _ => _ => undefined #-} {-# COMPILE JS declarePostulate = _ => _ => undefined #-} {-# COMPILE JS defineFun = _ => _ => undefined #-} {-# COMPILE JS getType = _ => undefined #-} {-# COMPILE JS getDefinition = _ => undefined #-} {-# COMPILE JS blockOnMeta = _ => _ => _ => undefined #-} {-# COMPILE JS commitTC = undefined #-} {-# COMPILE JS isMacro = _ => undefined #-} {-# COMPILE JS withNormalisation = _ => _ => _ => _ => undefined #-} {-# COMPILE JS withReconstructed = _ => _ => _ => undefined #-} {-# COMPILE JS debugPrint = _ => _ => _ => undefined #-} {-# COMPILE JS onlyReduceDefs = _ => _ => _ => _ => undefined #-} {-# COMPILE JS dontReduceDefs = _ => _ => _ => _ => undefined #-} {-# COMPILE JS noConstraints = _ => _ => _ => undefined #-} {-# COMPILE JS runSpeculative = _ => _ => _ => undefined #-} {-# COMPILE JS getInstances = _ => undefined #-}
40.145729
130
0.554888
0b4e0a2244dc461a7ac8bb897f291eb3692f845a
3,546
agda
Agda
src/sigmatypes/TermsSized.agda
kcaliban/ldlc
a87fb6402639c3d2bb393cc5466426c28e7a0398
[ "BSD-3-Clause" ]
null
null
null
src/sigmatypes/TermsSized.agda
kcaliban/ldlc
a87fb6402639c3d2bb393cc5466426c28e7a0398
[ "BSD-3-Clause" ]
null
null
null
src/sigmatypes/TermsSized.agda
kcaliban/ldlc
a87fb6402639c3d2bb393cc5466426c28e7a0398
[ "BSD-3-Clause" ]
1
2019-03-14T17:52:29.000Z
2019-03-14T17:52:29.000Z
-- Terms using Agdas Sized Types -- module TermsSized where open import Data.Vec hiding (_++_) open import Relation.Binary.PropositionalEquality open import Data.Nat open import Data.List open import Data.List.Relation.Unary.All open import Data.Fin.Base open import Size -- Ranked alphabet: Vector of natural numbers, where vec[i] denotes the arity of symbol i RankedAlphabet : ℕ → Set RankedAlphabet n = Vec ℕ n -- Types data Type : Set where TTerm : ∀ {n} → RankedAlphabet n → Type TFun : Type → Type → Type -- Type environment Env : Set Env = List Type -- Environment lookup data _∈`_ : Type → Env → Set where here : ∀ {φ A} → A ∈` (A ∷ φ) there : ∀ {φ A A'} → A ∈` φ → A ∈` (A' ∷ φ) -- Bind a type n times on top of an environment bind : Env → (A : Type) → ℕ → Env bind φ A zero = φ bind φ A (suc n) = A ∷ (bind φ A n) -- Zero & Successor, Variables, prim. recursion, Abstraction, Application data Expr : {j : Size} → Env → Type → Set where ETerm : ∀ {j : Size} {φ n} {vec : RankedAlphabet n} {sym : Fin n} → Vec (Expr {j} φ (TTerm vec)) (Data.Vec.lookup vec sym) → Expr {↑ j} φ (TTerm vec) ETerm-Rec : ∀ {j : Size} {φ n} {vec : RankedAlphabet n} {A} → (∀ {sym : Fin n} → Expr {j} (bind φ A (Data.Vec.lookup vec sym)) A) → Expr {j} φ (TTerm vec) → Expr {↑ j} φ A Var : ∀ {φ A} → A ∈` φ → Expr {∞} φ A Abs : ∀ {φ A B} → Expr (A ∷ φ) B → Expr φ (TFun A B) App : ∀ {φ A B} → Expr φ (TFun A B) → Expr φ A → Expr φ B -- Terms data Term {n} (ra : RankedAlphabet n) : {i : Size} → Set where mk : ∀ {i} → (sym : Fin n) → Vec (Term ra {i}) (Data.Vec.lookup ra sym) → Term ra {↑ i} -- Values Value : Type → Set Value (TTerm ra) = Term ra Value (TFun A B) = Value A → Value B -- Lookup in environment of all Values access : ∀ {A φ} → A ∈` φ → All Value φ → Value A access here (px ∷ p) = px access (there x) (px ∷ p) = access x p extend : ∀ {ϕ A} → (m : ℕ) → (ϱ₁ : Vec (Value A) m) → (ϱ : All Value ϕ) → All Value (bind ϕ A m) extend 0F [] ϱ = ϱ extend (suc m) (x ∷ ϱ₁) ϱ = x ∷ extend m ϱ₁ ϱ trec : ∀ {j : Size} {a} {n} {VA : Set a} (ra : RankedAlphabet n) → ((sym : Fin n) → Vec VA (Data.Vec.lookup ra sym) → VA) → Term ra {j} → VA trec ra g (mk sym₁ subterms) = g sym₁ (Data.Vec.map (trec ra g) subterms) -- Evaluation eval : ∀ {j : Size} {ϕ A} → Expr{j} ϕ A → All Value ϕ → Value A eval (ETerm{sym = sym} x) ϱ = mk sym (Data.Vec.map (λ exp → eval exp ϱ) x) eval {j} {ϕ} {A} (ETerm-Rec{n = n}{vec = ra} exprs body) ϱ with eval body ϱ ... | term = trec {VA = Value A} ra (λ sym₁ ϱ₁ → eval {A = A} (exprs {sym₁}) (extend (Data.Vec.lookup ra sym₁) ϱ₁ ϱ)) term eval (Var x) ϱ = access x ϱ eval (Abs expr) ϱ = λ x → eval expr (x ∷ ϱ) eval (App expr expr₁) ϱ = (eval expr ϱ) (eval expr₁ ϱ) -- Example: Very tiny subset of propositional logic -- Σ = {¬, ⊤, ⊥}, α(¬) = 1, α(⊤) = 0, α(⊥) = 0 Σ : Vec ℕ 3 Σ = (1 ∷ 0 ∷ 0 ∷ []) PropLog : Type PropLog = TTerm Σ 1≤3 : 1 Data.Nat.< 3 1≤3 = s≤s (s≤s z≤n) 2≤3 : 2 Data.Nat.< 3 2≤3 = s≤s (s≤s (s≤s z≤n)) ⊤ : Expr [] PropLog ⊤ = ETerm{n = 3} {sym = fromℕ< {1} {3} 1≤3} [] ⊥ : Expr [] PropLog ⊥ = ETerm{n = 3} {sym = fromℕ< {2} {3} 2≤3} [] NegFunc : ∀ {sym : Fin 3} → Expr (bind [] PropLog (Data.Vec.lookup Σ sym)) PropLog NegFunc {zero} = Var here NegFunc {suc zero} = ⊥ NegFunc {suc (suc zero)} = ⊤ ¬⊥ : Expr [] PropLog ¬⊥ = ETerm-Rec{vec = Σ} (λ {sym} → NegFunc {sym}) (ETerm{n = 3} {sym = fromℕ< {0} {3} (s≤s z≤n)} (⊥ ∷ []) ) _ : (eval ¬⊥ []) ≡ (eval ⊤ []) _ = refl
31.380531
174
0.558094
1df392bffeeea716d5f3343cbeb06f3fc8b7da65
1,060
agda
Agda
agda/SList/Order/Properties.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/SList/Order/Properties.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/SList/Order/Properties.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
{-# OPTIONS --sized-types #-} module SList.Order.Properties {A : Set}(_≤_ : A → A → Set) where open import List.Sorted _≤_ open import Size open import SList open import SList.Order _≤_ lemma-slist-sorted : {ι : Size}{x : A}{xs : SList A {ι}} → x *≤ xs → Sorted (unsize A xs) → Sorted (unsize A (x ∙ xs)) lemma-slist-sorted {x = x} genx nils = singls x lemma-slist-sorted (gecx x≤y genx) (singls y) = conss x≤y (singls y) lemma-slist-sorted (gecx x≤y x*≤zys ) syzys = conss x≤y syzys lemma-sorted⊕ : {ι : Size}{x : A}{xs : SList A {ι}} → xs ≤* x → Sorted (unsize A xs) → Sorted (unsize A (_⊕_ A xs (x ∙ snil))) lemma-sorted⊕ {x = x} {xs = snil} _ nils = singls x lemma-sorted⊕ {x = x} {xs = y ∙ snil} (lecx y≤x _) (singls .y) = conss y≤x (singls x) lemma-sorted⊕ {xs = y ∙ (z ∙ ys)} (lecx y≤x zys≤*x) (conss y≤z szys) = conss y≤z (lemma-sorted⊕ zys≤*x szys) lemma-⊕≤* : {ι : Size}{x t : A}{xs : SList A {ι}} → x ≤ t → xs ≤* t → (_⊕_ A xs (x ∙ snil)) ≤* t lemma-⊕≤* x≤t lenx = lecx x≤t lenx lemma-⊕≤* x≤t (lecx y≤t ys≤*t) = lecx y≤t (lemma-⊕≤* x≤t ys≤*t)
48.181818
126
0.587736
dfd2015c6de162ca8e66ea47bc12d8dbdabe4e07
293
agda
Agda
src/data/lib/prim/Agda/Builtin/Char/Properties.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2016-05-20T13:58:52.000Z
2016-05-20T13:58:52.000Z
src/data/lib/prim/Agda/Builtin/Char/Properties.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T15:49:15.000Z
2015-09-15T15:49:15.000Z
src/data/lib/prim/Agda/Builtin/Char/Properties.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness --no-subtyping #-} module Agda.Builtin.Char.Properties where open import Agda.Builtin.Char open import Agda.Builtin.Equality primitive primCharToNatInjective : ∀ a b → primCharToNat a ≡ primCharToNat b → a ≡ b
24.416667
76
0.709898
2fe0ff2b4a1e0df9525bb09a4d102e9eb38ad292
1,893
agda
Agda
Cubical/Data/HomotopyGroup/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Data/HomotopyGroup/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Data/HomotopyGroup/Base.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.HomotopyGroup.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels import Cubical.Foundations.GroupoidLaws as GL open import Cubical.Foundations.Pointed open import Cubical.Data.Nat open import Cubical.Data.Group.Base open import Cubical.HITs.SetTruncation as SetTrunc Ω : ∀ {ℓ} → Pointed ℓ → Pointed ℓ Ω (A , a ) = ( (a ≡ a) , refl) Ω^_ : ∀ {ℓ} → ℕ → Pointed ℓ → Pointed ℓ (Ω^ 0) p = p (Ω^ (suc n)) p = Ω ((Ω^ n) p) π^_ : ∀ {ℓ} → ℕ → Pointed ℓ → Group ℓ π^_ {ℓ} n p = group ∥ A ∥₀ squash₀ g where n' : ℕ n' = suc n A : Type ℓ A = typ ((Ω^ n') p) g : isGroup ∥ A ∥₀ g = group-struct e _⁻¹ _⊙_ lUnit rUnit assoc lCancel rCancel where e : ∥ A ∥₀ e = ∣ pt ((Ω^ n') p) ∣₀ _⁻¹ : ∥ A ∥₀ → ∥ A ∥₀ _⁻¹ = SetTrunc.elim {B = λ _ → ∥ A ∥₀} (λ x → squash₀) λ a → ∣ sym a ∣₀ _⊙_ : ∥ A ∥₀ → ∥ A ∥₀ → ∥ A ∥₀ _⊙_ = SetTrunc.elim2 (λ _ _ → squash₀) λ a₀ a₁ → ∣ a₀ ∙ a₁ ∣₀ lUnit : (a : ∥ A ∥₀) → (e ⊙ a) ≡ a lUnit = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _)) (λ a → cong ∣_∣₀ (sym (GL.lUnit a) )) rUnit : (a : ∥ A ∥₀) → a ⊙ e ≡ a rUnit = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _)) (λ a → cong ∣_∣₀ (sym (GL.rUnit a) )) assoc : (a b c : ∥ A ∥₀) → ((a ⊙ b) ⊙ c) ≡ (a ⊙ (b ⊙ c)) assoc = SetTrunc.elim3 (λ _ _ _ → isProp→isSet (squash₀ _ _)) (λ a b c → cong ∣_∣₀ (sym (GL.assoc _ _ _))) lCancel : (a : ∥ A ∥₀) → ((a ⁻¹) ⊙ a) ≡ e lCancel = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _)) λ a → cong ∣_∣₀ (GL.lCancel _) rCancel : (a : ∥ A ∥₀) → (a ⊙ (a ⁻¹)) ≡ e rCancel = SetTrunc.elim (λ _ → isProp→isSet (squash₀ _ _)) λ a → cong ∣_∣₀ (GL.rCancel _)
31.032787
80
0.498679
4ac62a0f6e0418ab4f6297b33f7df6484a3727fb
2,534
agda
Agda
src/Construct/DirectProduct.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
2
2021-08-15T06:16:13.000Z
2021-08-17T09:14:03.000Z
src/Construct/DirectProduct.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
2
2021-10-04T05:30:30.000Z
2021-10-09T08:24:56.000Z
src/Construct/DirectProduct.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Algebra.Construct.DirectProduct module Construct.DirectProduct where open import Algebra import Algebra.Construct.DirectProduct as DirectProduct open import Data.Product open import Data.Product.Relation.Binary.Pointwise.NonDependent open import Level using (Level; _⊔_) private variable a b ℓ₁ ℓ₂ : Level ------------------------------------------------------------------------ -- Raw bundles rawQuasigroup : RawQuasigroup a ℓ₁ → RawQuasigroup b ℓ₂ → RawQuasigroup (a ⊔ b) (ℓ₁ ⊔ ℓ₂) rawQuasigroup M N = record { Carrier = M.Carrier × N.Carrier ; _≈_ = Pointwise M._≈_ N._≈_ ; _∙_ = zip M._∙_ N._∙_ ; _\\_ = zip M._\\_ N._\\_ ; _//_ = zip M._//_ N._//_ } where module M = RawQuasigroup M; module N = RawQuasigroup N rawLoop : RawLoop a ℓ₁ → RawLoop b ℓ₂ → RawLoop (a ⊔ b) (ℓ₁ ⊔ ℓ₂) rawLoop M N = record { Carrier = M.Carrier × N.Carrier ; _≈_ = Pointwise M._≈_ N._≈_ ; _∙_ = zip M._∙_ N._∙_ ; _\\_ = zip M._\\_ N._\\_ ; _//_ = zip M._//_ N._//_ ; ε = M.ε , N.ε } where module M = RawLoop M; module N = RawLoop N ------------------------------------------------------------------------ -- Bundles unitalMagma : UnitalMagma a ℓ₁ → UnitalMagma b ℓ₂ → UnitalMagma (a ⊔ b) (ℓ₁ ⊔ ℓ₂) unitalMagma M N = record { ε = M.ε , N.ε ; isUnitalMagma = record { isMagma = Magma.isMagma (magma M.magma N.magma) ; identity = (M.identityˡ , N.identityˡ <*>_) , (M.identityʳ , N.identityʳ <*>_) } } where module M = UnitalMagma M; module N = UnitalMagma N invertibleMagma : InvertibleMagma a ℓ₁ → InvertibleMagma b ℓ₂ → InvertibleMagma (a ⊔ b) (ℓ₁ ⊔ ℓ₂) invertibleMagma M N = record { _⁻¹ = map M._⁻¹ N._⁻¹ ; isInvertibleMagma = record { isMagma = Magma.isMagma (magma M.magma N.magma) ; inverse = (λ x → (M.inverseˡ , N.inverseˡ) <*> x) , (λ x → (M.inverseʳ , N.inverseʳ) <*> x) } } where module M = InvertibleMagma M; module N = InvertibleMagma N invertibleUnitalMagma : InvertibleUnitalMagma a ℓ₁ → InvertibleUnitalMagma b ℓ₂ → InvertibleUnitalMagma (a ⊔ b) (ℓ₁ ⊔ ℓ₂) invertibleUnitalMagma M N = record { ε = M.ε , N.ε ; isInvertibleUnitalMagma = record { isInvertibleMagma = InvertibleMagma.isInvertibleMagma (invertibleMagma M.invertibleMagma N.invertibleMagma) ; identity = (M.identityˡ , N.identityˡ <*>_) , (M.identityʳ , N.identityʳ <*>_) } } where module M = InvertibleUnitalMagma M; module N = InvertibleUnitalMagma N
35.194444
121
0.60734
122db3c30618378f18fefc77af3cea668f05528c
712
agda
Agda
test/Succeed/Issue870.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue870.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue870.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v impossible:100 #-} -- 2013-06-15 Andreas, reported by evancavallo module Issue870 where {- The following fails with An internal error has occurred. Please report this as a bug. Location of the error: src/full/Agda/TypeChecking/Rules/Term.hs:421 in Agda 2.3.3 on Ubuntu. Works fine using Set instead of Type or after tweaking the definition of test into a more sensible form. -} Type = Set data ⊤ : Type where tt : ⊤ record R : Type where field a : ⊤ test : ⊤ → R test t = (λ a → record {a = a}) t -- There was a possible __IMPOSSIBLE__ in the code for -- guessing the record type of record{a = a}. -- The problem was that a defined sort like Type, needs to be -- reduced.
24.551724
132
0.69382
1d848ff41537a68a0c30fc42e08bad375583e2a3
3,064
agda
Agda
src/hott/truncation/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
20
2015-06-12T12:20:17.000Z
2022-02-01T11:25:54.000Z
src/hott/truncation/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/hott/truncation/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T12:17:00.000Z
2019-05-04T19:31:00.000Z
{-# OPTIONS --without-K #-} module hott.truncation.core where open import sum open import equality open import function.core open import function.fibration open import function.extensionality open import function.isomorphism open import sets.nat.core open import hott.equivalence open import hott.level.core open import hott.level.closure module _ {i j i' j'}{A : Set i}{A' : Set i'} {B : A → Set j}{B' : A' → Set j'} (f : A → A') (g : (a : A) → B a → B' (f a)) where private E E' : Set _ E = Σ A B E' = Σ A' B' p : E → A p = proj₁ p' : E' → A' p' = proj₁ t : E → E' t (a , b) = (f a , g a b) module _ (f-equiv : weak-equiv f) (t-equiv : weak-equiv t) where private φ : A ≅ A' φ = ≈⇒≅ (f , f-equiv) τ : E ≅ E' τ = ≈⇒≅ (t , t-equiv) lem : (a : A)(e : E) → (p e ≡ a) ≅ (p' (t e) ≡ f a) lem a e = iso≡ φ fib-equiv : (a : A) → B a ≅ B' (f a) fib-equiv a = sym≅ (fib-iso a) ·≅ Σ-ap-iso τ (lem a) ·≅ fib-iso (f a) postulate Trunc : ∀ {i} → ℕ → Set i → Set i Trunc-level : ∀ {i} n {X : Set i} → h n (Trunc n X) [_] : ∀ {i n} {X : Set i} → X → Trunc n X Trunc-ext : ∀ {i j} n (X : Set i)(Y : Set j) → (Trunc n X → Y) → X → Y Trunc-ext n X Y f x = f [ x ] postulate Trunc-univ : ∀ {i j} n (X : Set i)(Y : Set j) → h n Y → weak-equiv (Trunc-ext n X Y) Trunc-elim-iso : ∀ {i j} n (X : Set i)(Y : Set j) → h n Y → (Trunc n X → Y) ≅ (X → Y) Trunc-elim-iso n X Y hY = ≈⇒≅ (Trunc-ext n X Y , Trunc-univ n X Y hY) Trunc-elim : ∀ {i j} n (X : Set i)(Y : Set j) → h n Y → (X → Y) → (Trunc n X → Y) Trunc-elim n X Y hY = invert (Trunc-elim-iso n X Y hY) Trunc-elim-β : ∀ {i j} n (X : Set i)(Y : Set j)(hY : h n Y) → (f : X → Y)(x : X) → Trunc-elim n X Y hY f [ x ] ≡ f x Trunc-elim-β n X Y hY f x = funext-inv (_≅_.iso₂ (Trunc-elim-iso n X Y hY) f) x module _ {i j} n {X : Set i} (Y : Trunc n X → Set j) (hY : (x : Trunc n X) → h n (Y x)) where private Z : Set _ Z = Σ (Trunc n X) Y hZ : h n Z hZ = Σ-level (Trunc-level n) hY Sec₂ : ∀ {k}{A : Set k} → (A → Trunc n X) → Set _ Sec₂ {A = A} r = (x : A) → Y (r x) Sec : ∀ {k} → Set k → Set _ Sec A = Σ (A → Trunc n X) Sec₂ τ : Sec (Trunc n X) ≅ Sec X τ = sym≅ ΠΣ-swap-iso ·≅ Trunc-elim-iso n X Z hZ ·≅ ΠΣ-swap-iso ψ : (r : Trunc n X → Trunc n X) → (Sec₂ r) ≅ Sec₂ (r ∘ [_]) ψ = fib-equiv {A = Trunc n X → Trunc n X}{A' = X → Trunc n X}{B = Sec₂} {B' = Sec₂} (Trunc-ext n X (Trunc n X)) (λ r g x → g [ x ]) (Trunc-univ n X (Trunc n X) (Trunc-level n)) (proj₂ (≅⇒≈ τ)) Trunc-dep-iso : Sec₂ (λ x → x) ≅ Sec₂ [_] Trunc-dep-iso = ψ (λ x → x) Trunc-dep-elim : ((x : X) → Y [ x ]) → (x : Trunc n X) → Y x Trunc-dep-elim = invert Trunc-dep-iso Trunc-dep-elim-β : (d : ((x : X) → Y [ x ])) → (x : X) → Trunc-dep-elim d [ x ] ≡ d x Trunc-dep-elim-β d = funext-inv (_≅_.iso₂ Trunc-dep-iso d)
27.854545
87
0.475849
57c43e294ce34470bb3332fd678f5e7a3e3a358b
2,335
agda
Agda
Cubical/Data/Sum/Properties.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/Data/Sum/Properties.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/Data/Sum/Properties.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Sum.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Data.Empty open import Cubical.Data.Nat open import Cubical.Data.Sum.Base -- Path space of sum type module SumPath {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where Cover : A ⊎ B → A ⊎ B → Type (ℓ-max ℓ ℓ') Cover (inl a) (inl a') = Lift {j = ℓ-max ℓ ℓ'} (a ≡ a') Cover (inl _) (inr _) = Lift ⊥ Cover (inr _) (inl _) = Lift ⊥ Cover (inr b) (inr b') = Lift {j = ℓ-max ℓ ℓ'} (b ≡ b') reflCode : (c : A ⊎ B) → Cover c c reflCode (inl a) = lift refl reflCode (inr b) = lift refl encode : ∀ c c' → c ≡ c' → Cover c c' encode c _ = J (λ c' _ → Cover c c') (reflCode c) encodeRefl : ∀ c → encode c c refl ≡ reflCode c encodeRefl c = JRefl (λ c' _ → Cover c c') (reflCode c) decode : ∀ c c' → Cover c c' → c ≡ c' decode (inl a) (inl a') (lift p) = cong inl p decode (inl a) (inr b') () decode (inr b) (inl a') () decode (inr b) (inr b') (lift q) = cong inr q decodeRefl : ∀ c → decode c c (reflCode c) ≡ refl decodeRefl (inl a) = refl decodeRefl (inr b) = refl decodeEncode : ∀ c c' → (p : c ≡ c') → decode c c' (encode c c' p) ≡ p decodeEncode c _ = J (λ c' p → decode c c' (encode c c' p) ≡ p) (cong (decode c c) (encodeRefl c) ∙ decodeRefl c) isOfHLevelCover : (n : ℕ) → isOfHLevel (suc (suc n)) A → isOfHLevel (suc (suc n)) B → ∀ c c' → isOfHLevel (suc n) (Cover c c') isOfHLevelCover n p q (inl a) (inl a') = isOfHLevelLift (suc n) (p a a') isOfHLevelCover n p q (inl a) (inr b') = isOfHLevelLift (suc n) (subst (λ m → isOfHLevel m ⊥) (+-comm n 1) (hLevelLift n isProp⊥)) isOfHLevelCover n p q (inr b) (inl a') = isOfHLevelLift (suc n) (subst (λ m → isOfHLevel m ⊥) (+-comm n 1) (hLevelLift n isProp⊥)) isOfHLevelCover n p q (inr b) (inr b') = isOfHLevelLift (suc n) (q b b') isOfHLevelSum : ∀ {ℓ ℓ'} (n : ℕ) {A : Type ℓ} {B : Type ℓ'} → isOfHLevel (suc (suc n)) A → isOfHLevel (suc (suc n)) B → isOfHLevel (suc (suc n)) (A ⊎ B) isOfHLevelSum n lA lB c c' = retractIsOfHLevel (suc n) (SumPath.encode c c') (SumPath.decode c c') (SumPath.decodeEncode c c') (SumPath.isOfHLevelCover n lA lB c c')
32.887324
74
0.588437
29a95114a01d9bc91e2e77d2da4357d80dfa6a24
6,952
agda
Agda
homotopy/Pi2HSusp.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/Pi2HSusp.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/Pi2HSusp.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT open import homotopy.HSpace renaming (HSpaceStructure to HSS) open import homotopy.WedgeExtension module homotopy.Pi2HSusp where module Pi2HSusp {i} (A : Type i) (gA : has-level ⟨ 1 ⟩ A) (cA : is-connected ⟨0⟩ A) (A-H : HSS A) (μcoh : HSS.μe- A-H (HSS.e A-H) == HSS.μ-e A-H (HSS.e A-H)) where {- TODO this belongs somewhere else, but where? -} private Type=-ext : ∀ {i} {A B : Type i} (p q : A == B) → ((x : A) → coe p x == coe q x) → p == q Type=-ext p q α = ! (ua-η p) ∙ ap ua (pair= (λ= α) (prop-has-all-paths-↓ (is-equiv-is-prop (coe q)))) ∙ ua-η q open HSpaceStructure A-H open ConnectedHSpace A cA A-H P : Suspension A → Type i P x = Trunc ⟨ 1 ⟩ (north A == x) module Codes = SuspensionRec A A A (λ a → ua (μ-equiv a)) Codes : Suspension A → Type i Codes = Codes.f Codes-level : (x : Suspension A) → has-level ⟨ 1 ⟩ (Codes x) Codes-level = Suspension-elim A gA gA (λ _ → prop-has-all-paths-↓ has-level-is-prop) encode₀ : {x : Suspension A} → (north A == x) → Codes x encode₀ α = transport Codes α e encode : {x : Suspension A} → P x → Codes x encode {x} = Trunc-rec (Codes-level x) encode₀ decode' : A → P (north A) decode' a = [ (merid A a ∙ ! (merid A e)) ] abstract transport-Codes-mer : (a a' : A) → transport Codes (merid A a) a' == μ a a' transport-Codes-mer a a' = coe (ap Codes (merid A a)) a' =⟨ Codes.glue-β a |in-ctx (λ w → coe w a') ⟩ coe (ua (μ-equiv a)) a' =⟨ coe-β (μ-equiv a) a' ⟩ μ a a' ∎ transport-Codes-mer-e-! : (a : A) → transport Codes (! (merid A e)) a == a transport-Codes-mer-e-! a = coe (ap Codes (! (merid A e))) a =⟨ ap-! Codes (merid A e) |in-ctx (λ w → coe w a) ⟩ coe (! (ap Codes (merid A e))) a =⟨ Codes.glue-β e |in-ctx (λ w → coe (! w) a) ⟩ coe (! (ua (μ-equiv e))) a =⟨ Type=-ext (ua (μ-equiv e)) idp (λ x → coe-β _ x ∙ μe- x) |in-ctx (λ w → coe (! w) a) ⟩ coe (! idp) a ∎ abstract encode-decode' : (a : A) → encode (decode' a) == a encode-decode' a = transport Codes (merid A a ∙ ! (merid A e)) e =⟨ trans-∙ {B = Codes} (merid A a) (! (merid A e)) e ⟩ transport Codes (! (merid A e)) (transport Codes (merid A a) e) =⟨ transport-Codes-mer a e ∙ μ-e a |in-ctx (λ w → transport Codes (! (merid A e)) w) ⟩ transport Codes (! (merid A e)) a =⟨ transport-Codes-mer-e-! a ⟩ a ∎ abstract homomorphism : (a a' : A) → Path {A = Trunc ⟨ 1 ⟩ (north A == south A)} [ merid A (μ a a' ) ] [ merid A a' ∙ ! (merid A e) ∙ merid A a ] homomorphism = WedgeExt.ext args where args : WedgeExt.args {a₀ = e} {b₀ = e} args = record {m = ⟨-2⟩; n = ⟨-2⟩; cA = cA; cB = cA; P = λ a a' → (_ , Trunc-level {n = ⟨ 1 ⟩} _ _); f = λ a → ap [_] $ merid A (μ a e) =⟨ ap (merid A) (μ-e a) ⟩ merid A a =⟨ ap (λ w → w ∙ merid A a) (! (!-inv-r (merid A e))) ∙ ∙-assoc (merid A e) (! (merid A e)) (merid A a) ⟩ merid A e ∙ ! (merid A e) ∙ merid A a ∎; g = λ a' → ap [_] $ merid A (μ e a') =⟨ ap (merid A) (μe- a') ⟩ merid A a' =⟨ ! (∙-unit-r (merid A a')) ∙ ap (λ w → merid A a' ∙ w) (! (!-inv-l (merid A e))) ⟩ merid A a' ∙ ! (merid A e) ∙ merid A e ∎ ; p = ap (λ {(p₁ , p₂) → ap [_] $ merid A (μ e e) =⟨ p₁ ⟩ merid A e =⟨ p₂ ⟩ merid A e ∙ ! (merid A e) ∙ merid A e ∎}) (pair×= (ap (λ x → ap (merid A) x) (! μcoh)) (coh (merid A e)))} where coh : {B : Type i} {b b' : B} (p : b == b') → ap (λ w → w ∙ p) (! (!-inv-r p)) ∙ ∙-assoc p (! p) p == ! (∙-unit-r p) ∙ ap (λ w → p ∙ w) (! (!-inv-l p)) coh idp = idp decode : {x : Suspension A} → Codes x → P x decode {x} = Suspension-elim A {P = λ x → Codes x → P x} decode' (λ a → [ merid A a ]) (λ a → ↓-→-from-transp (λ= $ STS a)) x where abstract STS : (a a' : A) → transport P (merid A a) (decode' a') == [ merid A (transport Codes (merid A a) a') ] STS a a' = transport P (merid A a) [ merid A a' ∙ ! (merid A e) ] =⟨ transport-Trunc (λ x → north A == x) (merid A a) _ ⟩ [ transport (λ x → north A == x) (merid A a) (merid A a' ∙ ! (merid A e)) ] =⟨ ap [_] (trans-pathfrom {A = Suspension A} (merid A a) _) ⟩ [ (merid A a' ∙ ! (merid A e)) ∙ merid A a ] =⟨ ap [_] (∙-assoc (merid A a') (! (merid A e)) (merid A a)) ⟩ [ merid A a' ∙ ! (merid A e) ∙ merid A a ] =⟨ ! (homomorphism a a') ⟩ [ merid A (μ a a') ] =⟨ ap ([_] ∘ merid A) (! (transport-Codes-mer a a')) ⟩ [ merid A (transport Codes (merid A a) a') ] ∎ abstract decode-encode : {x : Suspension A} (tα : P x) → decode {x} (encode {x} tα) == tα decode-encode {x} = Trunc-elim {P = λ tα → decode {x} (encode {x} tα) == tα} (λ _ → =-preserves-level ⟨ 1 ⟩ Trunc-level) (J (λ y p → decode {y} (encode {y} [ p ]) == [ p ]) (ap [_] (!-inv-r (merid A e)))) main-lemma-eqv : Trunc ⟨ 1 ⟩ (north A == north A) ≃ A main-lemma-eqv = equiv encode decode' encode-decode' decode-encode ⊙main-lemma : ⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e))) == (A , e) ⊙main-lemma = ⊙ua main-lemma-eqv idp abstract main-lemma-iso : (t1 : 1 ≠ 0) → Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e)))) Trunc-level ≃ᴳ Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (A , e)) Trunc-level main-lemma-iso _ = (record {f = f; pres-comp = pres-comp} , ie) where h : fst (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e))) ⊙→ ⊙Trunc ⟨ 1 ⟩ (A , e)) h = (λ x → [ encode x ]) , idp f : Ω (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e)))) → Ω (⊙Trunc ⟨ 1 ⟩ (A , e)) f = fst (ap^ 1 h) pres-comp : (p q : Ω^ 1 (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e))))) → f (conc^ 1 (ℕ-S≠O _) p q) == conc^ 1 (ℕ-S≠O _) (f p) (f q) pres-comp = ap^-conc^ 1 (ℕ-S≠O _) h ie : is-equiv f ie = is-equiv-ap^ 1 h (snd $ ((unTrunc-equiv A gA)⁻¹ ∘e main-lemma-eqv)) abstract π₂-Suspension : (t1 : 1 ≠ 0) (t2 : 2 ≠ 0) → π 2 t2 (⊙Susp (A , e)) == π 1 t1 (A , e) π₂-Suspension t1 t2 = π 2 t2 (⊙Susp (A , e)) =⟨ π-inner-iso 1 t1 t2 (⊙Susp (A , e)) ⟩ π 1 t1 (⊙Ω (⊙Susp (A , e))) =⟨ ! (π-Trunc-shift-iso 1 t1 (⊙Ω (⊙Susp (A , e)))) ⟩ Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e)))) Trunc-level =⟨ group-ua (main-lemma-iso t1) ⟩ Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (A , e)) Trunc-level =⟨ π-Trunc-shift-iso 1 t1 (A , e) ⟩ π 1 t1 (A , e) ∎
37.578378
83
0.454689
31187526362e6bcffd35e040811f484b3933c31b
5,208
agda
Agda
Cubical/Algebra/CommRing/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/CommRing/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/CommRing/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Displayed.Base open import Cubical.Displayed.Auto open import Cubical.Displayed.Record open import Cubical.Displayed.Universe open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Ring.Base open Iso private variable ℓ ℓ' : Level record IsCommRing {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where constructor iscommring field isRing : IsRing 0r 1r _+_ _·_ -_ ·-comm : (x y : R) → x · y ≡ y · x open IsRing isRing public record CommRingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor commringstr field 0r : A 1r : A _+_ : A → A → A _·_ : A → A → A -_ : A → A isCommRing : IsCommRing 0r 1r _+_ _·_ -_ infix 8 -_ infixl 7 _·_ infixl 6 _+_ open IsCommRing isCommRing public CommRing : ∀ ℓ → Type (ℓ-suc ℓ) CommRing ℓ = TypeWithStr ℓ CommRingStr makeIsCommRing : {R : Type ℓ} {0r 1r : R} {_+_ _·_ : R → R → R} { -_ : R → R} (is-setR : isSet R) (+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z) (+-rid : (x : R) → x + 0r ≡ x) (+-rinv : (x : R) → x + (- x) ≡ 0r) (+-comm : (x y : R) → x + y ≡ y + x) (·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z) (·-rid : (x : R) → x · 1r ≡ x) (·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)) (·-comm : (x y : R) → x · y ≡ y · x) → IsCommRing 0r 1r _+_ _·_ -_ makeIsCommRing {_+_ = _+_} is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm = iscommring (makeIsRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid (λ x → ·-comm _ _ ∙ ·-rid x) ·-rdist-+ (λ x y z → ·-comm _ _ ∙∙ ·-rdist-+ z x y ∙∙ λ i → (·-comm z x i) + (·-comm z y i))) ·-comm makeCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) (is-setR : isSet R) (+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z) (+-rid : (x : R) → x + 0r ≡ x) (+-rinv : (x : R) → x + (- x) ≡ 0r) (+-comm : (x y : R) → x + y ≡ y + x) (·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z) (·-rid : (x : R) → x · 1r ≡ x) (·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)) (·-comm : (x y : R) → x · y ≡ y · x) → CommRing ℓ makeCommRing 0r 1r _+_ _·_ -_ is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm = _ , commringstr _ _ _ _ _ (makeIsCommRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm) CommRingStr→RingStr : {A : Type ℓ} → CommRingStr A → RingStr A CommRingStr→RingStr (commringstr _ _ _ _ _ H) = ringstr _ _ _ _ _ (IsCommRing.isRing H) CommRing→Ring : CommRing ℓ → Ring ℓ CommRing→Ring (_ , commringstr _ _ _ _ _ H) = _ , ringstr _ _ _ _ _ (IsCommRing.isRing H) CommRingHom : (R : CommRing ℓ) (S : CommRing ℓ') → Type (ℓ-max ℓ ℓ') CommRingHom R S = RingHom (CommRing→Ring R) (CommRing→Ring S) IsCommRingEquiv : {A : Type ℓ} {B : Type ℓ'} (R : CommRingStr A) (e : A ≃ B) (S : CommRingStr B) → Type (ℓ-max ℓ ℓ') IsCommRingEquiv R e S = IsRingHom (CommRingStr→RingStr R) (e .fst) (CommRingStr→RingStr S) CommRingEquiv : (R : CommRing ℓ) (S : CommRing ℓ') → Type (ℓ-max ℓ ℓ') CommRingEquiv R S = Σ[ e ∈ (R .fst ≃ S .fst) ] IsCommRingEquiv (R .snd) e (S .snd) isPropIsCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) → isProp (IsCommRing 0r 1r _+_ _·_ -_) isPropIsCommRing 0r 1r _+_ _·_ -_ (iscommring RR RC) (iscommring SR SC) = λ i → iscommring (isPropIsRing _ _ _ _ _ RR SR i) (isPropComm RC SC i) where isSetR : isSet _ isSetR = RR .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set isPropComm : isProp ((x y : _) → x · y ≡ y · x) isPropComm = isPropΠ2 λ _ _ → isSetR _ _ 𝒮ᴰ-CommRing : DUARel (𝒮-Univ ℓ) CommRingStr ℓ 𝒮ᴰ-CommRing = 𝒮ᴰ-Record (𝒮-Univ _) IsCommRingEquiv (fields: data[ 0r ∣ null ∣ pres0 ] data[ 1r ∣ null ∣ pres1 ] data[ _+_ ∣ bin ∣ pres+ ] data[ _·_ ∣ bin ∣ pres· ] data[ -_ ∣ autoDUARel _ _ ∣ pres- ] prop[ isCommRing ∣ (λ _ _ → isPropIsCommRing _ _ _ _ _) ]) where open CommRingStr open IsRingHom -- faster with some sharing null = autoDUARel (𝒮-Univ _) (λ A → A) bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A) CommRingPath : (R S : CommRing ℓ) → CommRingEquiv R S ≃ (R ≡ S) CommRingPath = ∫ 𝒮ᴰ-CommRing .UARel.ua isSetCommRing : ((R , str) : CommRing ℓ) → isSet R isSetCommRing (R , str) = str .CommRingStr.is-set
35.917241
115
0.542435
31c11082d3ba568aa423aaa69bfc0bf47fd55122
13,759
agda
Agda
Cubical/HITs/SetTruncation/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/HITs/SetTruncation/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/HITs/SetTruncation/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- This file contains: - Properties of set truncations -} {-# OPTIONS --safe #-} module Cubical.HITs.SetTruncation.Properties where open import Cubical.HITs.SetTruncation.Base open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Univalence open import Cubical.Foundations.Pointed.Base open import Cubical.Data.Sigma open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim to pElim) hiding (elim2 ; elim3 ; rec2 ; map) private variable ℓ ℓ' ℓ'' : Level A B C D : Type ℓ isSetPathImplicit : {x y : ∥ A ∥₂} → isSet (x ≡ y) isSetPathImplicit = isOfHLevelPath 2 squash₂ _ _ rec : isSet B → (A → B) → ∥ A ∥₂ → B rec Bset f ∣ x ∣₂ = f x rec Bset f (squash₂ x y p q i j) = Bset _ _ (cong (rec Bset f) p) (cong (rec Bset f) q) i j rec2 : isSet C → (A → B → C) → ∥ A ∥₂ → ∥ B ∥₂ → C rec2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y rec2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) = Cset _ _ (cong (rec2 Cset f ∣ x ∣₂) p) (cong (rec2 Cset f ∣ x ∣₂) q) i j rec2 Cset f (squash₂ x y p q i j) z = Cset _ _ (cong (λ a → rec2 Cset f a z) p) (cong (λ a → rec2 Cset f a z) q) i j -- Old version: -- rec2 Cset f = rec (isSetΠ λ _ → Cset) λ x → rec Cset (f x) -- lemma 6.9.1 in HoTT book elim : {B : ∥ A ∥₂ → Type ℓ} (Bset : (x : ∥ A ∥₂) → isSet (B x)) (f : (a : A) → B (∣ a ∣₂)) (x : ∥ A ∥₂) → B x elim Bset f ∣ a ∣₂ = f a elim Bset f (squash₂ x y p q i j) = isOfHLevel→isOfHLevelDep 2 Bset _ _ (cong (elim Bset f) p) (cong (elim Bset f) q) (squash₂ x y p q) i j elim2 : {C : ∥ A ∥₂ → ∥ B ∥₂ → Type ℓ} (Cset : ((x : ∥ A ∥₂) (y : ∥ B ∥₂) → isSet (C x y))) (f : (a : A) (b : B) → C ∣ a ∣₂ ∣ b ∣₂) (x : ∥ A ∥₂) (y : ∥ B ∥₂) → C x y elim2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y elim2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) = isOfHLevel→isOfHLevelDep 2 (λ a → Cset ∣ x ∣₂ a) _ _ (cong (elim2 Cset f ∣ x ∣₂) p) (cong (elim2 Cset f ∣ x ∣₂) q) (squash₂ y z p q) i j elim2 Cset f (squash₂ x y p q i j) z = isOfHLevel→isOfHLevelDep 2 (λ a → Cset a z) _ _ (cong (λ a → elim2 Cset f a z) p) (cong (λ a → elim2 Cset f a z) q) (squash₂ x y p q) i j -- Old version: -- elim2 Cset f = elim (λ _ → isSetΠ (λ _ → Cset _ _)) -- (λ a → elim (λ _ → Cset _ _) (f a)) -- TODO: generalize elim3 : {B : (x y z : ∥ A ∥₂) → Type ℓ} (Bset : ((x y z : ∥ A ∥₂) → isSet (B x y z))) (g : (a b c : A) → B ∣ a ∣₂ ∣ b ∣₂ ∣ c ∣₂) (x y z : ∥ A ∥₂) → B x y z elim3 Bset g = elim2 (λ _ _ → isSetΠ (λ _ → Bset _ _ _)) (λ a b → elim (λ _ → Bset _ _ _) (g a b)) -- the recursor for maps into groupoids following the "HIT proof" in: -- https://arxiv.org/abs/1507.01150 -- i.e. for any type A and groupoid B we can construct a map ∥ A ∥₂ → B -- from a map A → B satisfying the condition -- ∀ (a b : A) (p q : a ≡ b) → cong f p ≡ cong f q -- TODO: prove that this is an equivalence module rec→Gpd {A : Type ℓ} {B : Type ℓ'} (Bgpd : isGroupoid B) (f : A → B) (congFConst : ∀ (a b : A) (p q : a ≡ b) → cong f p ≡ cong f q) where data H : Type ℓ where η : A → H ε : ∀ (a b : A) → ∥ a ≡ b ∥₁ → η a ≡ η b -- prop. trunc. of a≡b δ : ∀ (a b : A) (p : a ≡ b) → ε a b ∣ p ∣₁ ≡ cong η p gtrunc : isGroupoid H -- write elimination principle for H module Helim {P : H → Type ℓ''} (Pgpd : ∀ h → isGroupoid (P h)) (η* : (a : A) → P (η a)) (ε* : ∀ (a b : A) (∣p∣₁ : ∥ a ≡ b ∥₁) → PathP (λ i → P (ε a b ∣p∣₁ i)) (η* a) (η* b)) (δ* : ∀ (a b : A) (p : a ≡ b) → PathP (λ i → PathP (λ j → P (δ a b p i j)) (η* a) (η* b)) (ε* a b ∣ p ∣₁) (cong η* p)) where fun : (h : H) → P h fun (η a) = η* a fun (ε a b ∣p∣₁ i) = ε* a b ∣p∣₁ i fun (δ a b p i j) = δ* a b p i j fun (gtrunc x y p q α β i j k) = isOfHLevel→isOfHLevelDep 3 Pgpd (fun x) (fun y) (cong fun p) (cong fun q) (cong (cong fun) α) (cong (cong fun) β) (gtrunc x y p q α β) i j k module Hrec {C : Type ℓ''} (Cgpd : isGroupoid C) (η* : A → C) (ε* : ∀ (a b : A) → ∥ a ≡ b ∥₁ → η* a ≡ η* b) (δ* : ∀ (a b : A) (p : a ≡ b) → ε* a b ∣ p ∣₁ ≡ cong η* p) where fun : H → C fun (η a) = η* a fun (ε a b ∣p∣₁ i) = ε* a b ∣p∣₁ i fun (δ a b p i j) = δ* a b p i j fun (gtrunc x y p q α β i j k) = Cgpd (fun x) (fun y) (cong fun p) (cong fun q) (cong (cong fun) α) (cong (cong fun) β) i j k module HelimProp {P : H → Type ℓ''} (Pprop : ∀ h → isProp (P h)) (η* : (a : A) → P (η a)) where fun : ∀ h → P h fun = Helim.fun (λ _ → isSet→isGroupoid (isProp→isSet (Pprop _))) η* (λ a b ∣p∣₁ → isOfHLevel→isOfHLevelDep 1 Pprop _ _ (ε a b ∣p∣₁)) λ a b p → isOfHLevel→isOfHLevelDep 1 {B = λ p → PathP (λ i → P (p i)) (η* a) (η* b)} (λ _ → isOfHLevelPathP 1 (Pprop _) _ _) _ _ (δ a b p) -- The main trick: eliminating into hsets is easy -- i.e. H has the universal property of set truncation... module HelimSet {P : H → Type ℓ''} (Pset : ∀ h → isSet (P h)) (η* : ∀ a → P (η a)) where fun : (h : H) → P h fun = Helim.fun (λ _ → isSet→isGroupoid (Pset _)) η* ε* λ a b p → isOfHLevel→isOfHLevelDep 1 {B = λ p → PathP (λ i → P (p i)) (η* a) (η* b)} (λ _ → isOfHLevelPathP' 1 (Pset _) _ _) _ _ (δ a b p) where ε* : (a b : A) (∣p∣₁ : ∥ a ≡ b ∥₁) → PathP (λ i → P (ε a b ∣p∣₁ i)) (η* a) (η* b) ε* a b = pElim (λ _ → isOfHLevelPathP' 1 (Pset _) (η* a) (η* b)) λ p → subst (λ x → PathP (λ i → P (x i)) (η* a) (η* b)) (sym (δ a b p)) (cong η* p) -- Now we need to prove that H is a set. -- We start with a little lemma: localHedbergLemma : {X : Type ℓ''} (P : X → Type ℓ'') → (∀ x → isProp (P x)) → ((x : X) → P x → (y : X) → P y → x ≡ y) -------------------------------------------------- → (x : X) → P x → (y : X) → isProp (x ≡ y) localHedbergLemma {X = X} P Pprop P→≡ x px y = isPropRetract (λ p → subst P p px) (λ py → sym (P→≡ x px x px) ∙ P→≡ x px y py) isRetract (Pprop y) where isRetract : (p : x ≡ y) → (sym (P→≡ x px x px)) ∙ P→≡ x px y (subst P p px) ≡ p isRetract = J (λ y' p' → (sym (P→≡ x px x px)) ∙ P→≡ x px y' (subst P p' px) ≡ p') (subst (λ px' → sym (P→≡ x px x px) ∙ P→≡ x px x px' ≡ refl) (sym (substRefl {B = P} px)) (lCancel (P→≡ x px x px))) Hset : isSet H Hset = HelimProp.fun (λ _ → isPropΠ λ _ → isPropIsProp) baseCaseLeft where baseCaseLeft : (a₀ : A) (y : H) → isProp (η a₀ ≡ y) baseCaseLeft a₀ = localHedbergLemma (λ x → Q x .fst) (λ x → Q x .snd) Q→≡ _ ∣ refl ∣₁ where Q : H → hProp ℓ Q = HelimSet.fun (λ _ → isSetHProp) λ b → ∥ a₀ ≡ b ∥₁ , isPropPropTrunc -- Q (η b) = ∥ a ≡ b ∥₁ Q→≡ : (x : H) → Q x .fst → (y : H) → Q y .fst → x ≡ y Q→≡ = HelimSet.fun (λ _ → isSetΠ3 λ _ _ _ → gtrunc _ _) λ a p → HelimSet.fun (λ _ → isSetΠ λ _ → gtrunc _ _) λ b q → sym (ε a₀ a p) ∙ ε a₀ b q -- our desired function will split through H, -- i.e. we get a function ∥ A ∥₂ → H → B fun : ∥ A ∥₂ → B fun = f₁ ∘ f₂ where f₁ : H → B f₁ = Hrec.fun Bgpd f εᶠ λ _ _ _ → refl where εᶠ : (a b : A) → ∥ a ≡ b ∥₁ → f a ≡ f b εᶠ a b = rec→Set (Bgpd _ _) (cong f) λ p q → congFConst a b p q -- this is the inductive step, -- we use that maps ∥ A ∥₁ → B for an hset B -- correspond to 2-Constant maps A → B (which cong f is by assumption) f₂ : ∥ A ∥₂ → H f₂ = rec Hset η map : (A → B) → ∥ A ∥₂ → ∥ B ∥₂ map f = rec squash₂ λ x → ∣ f x ∣₂ map∙ : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) → ∥ A ∥₂∙ →∙ ∥ B ∥₂∙ fst (map∙ f) = map (fst f) snd (map∙ f) = cong ∣_∣₂ (snd f) setTruncUniversal : isSet B → (∥ A ∥₂ → B) ≃ (A → B) setTruncUniversal {B = B} Bset = isoToEquiv (iso (λ h x → h ∣ x ∣₂) (rec Bset) (λ _ → refl) rinv) where rinv : (f : ∥ A ∥₂ → B) → rec Bset (λ x → f ∣ x ∣₂) ≡ f rinv f i x = elim (λ x → isProp→isSet (Bset (rec Bset (λ x → f ∣ x ∣₂) x) (f x))) (λ _ → refl) x i isSetSetTrunc : isSet ∥ A ∥₂ isSetSetTrunc a b p q = squash₂ a b p q setTruncIdempotentIso : isSet A → Iso ∥ A ∥₂ A Iso.fun (setTruncIdempotentIso hA) = rec hA (idfun _) Iso.inv (setTruncIdempotentIso hA) x = ∣ x ∣₂ Iso.rightInv (setTruncIdempotentIso hA) _ = refl Iso.leftInv (setTruncIdempotentIso hA) = elim (λ _ → isSet→isGroupoid isSetSetTrunc _ _) (λ _ → refl) setTruncIdempotent≃ : isSet A → ∥ A ∥₂ ≃ A setTruncIdempotent≃ {A = A} hA = isoToEquiv (setTruncIdempotentIso hA) setTruncIdempotent : isSet A → ∥ A ∥₂ ≡ A setTruncIdempotent hA = ua (setTruncIdempotent≃ hA) isContr→isContrSetTrunc : isContr A → isContr (∥ A ∥₂) isContr→isContrSetTrunc contr = ∣ fst contr ∣₂ , elim (λ _ → isOfHLevelPath 2 (isSetSetTrunc) _ _) λ a → cong ∣_∣₂ (snd contr a) setTruncIso : Iso A B → Iso ∥ A ∥₂ ∥ B ∥₂ Iso.fun (setTruncIso is) = rec isSetSetTrunc (λ x → ∣ Iso.fun is x ∣₂) Iso.inv (setTruncIso is) = rec isSetSetTrunc (λ x → ∣ Iso.inv is x ∣₂) Iso.rightInv (setTruncIso is) = elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) λ a → cong ∣_∣₂ (Iso.rightInv is a) Iso.leftInv (setTruncIso is) = elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) λ a → cong ∣_∣₂ (Iso.leftInv is a) setSigmaIso : {B : A → Type ℓ} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ setSigmaIso {A = A} {B = B} = iso fun funinv sect retr where {- writing it out explicitly to avoid yellow highlighting -} fun : ∥ Σ A B ∥₂ → ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ fun = rec isSetSetTrunc λ {(a , p) → ∣ a , ∣ p ∣₂ ∣₂} funinv : ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ → ∥ Σ A B ∥₂ funinv = rec isSetSetTrunc (λ {(a , p) → rec isSetSetTrunc (λ p → ∣ a , p ∣₂) p}) sect : section fun funinv sect = elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) λ { (a , p) → elim {B = λ p → fun (funinv ∣ a , p ∣₂) ≡ ∣ a , p ∣₂} (λ p → isOfHLevelPath 2 isSetSetTrunc _ _) (λ _ → refl) p } retr : retract fun funinv retr = elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) λ { _ → refl } sigmaElim : {B : ∥ A ∥₂ → Type ℓ} {C : Σ ∥ A ∥₂ B → Type ℓ'} (Bset : (x : Σ ∥ A ∥₂ B) → isSet (C x)) (g : (a : A) (b : B ∣ a ∣₂) → C (∣ a ∣₂ , b)) (x : Σ ∥ A ∥₂ B) → C x sigmaElim {B = B} {C = C} set g (x , y) = elim {B = λ x → (y : B x) → C (x , y)} (λ _ → isSetΠ λ _ → set _) g x y sigmaProdElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} {D : Σ (∥ A ∥₂ × ∥ B ∥₂) C → Type ℓ'} (Bset : (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → isSet (D x)) (g : (a : A) (b : B) (c : C (∣ a ∣₂ , ∣ b ∣₂)) → D ((∣ a ∣₂ , ∣ b ∣₂) , c)) (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → D x sigmaProdElim {B = B} {C = C} {D = D} set g ((x , y) , c) = elim {B = λ x → (y : ∥ B ∥₂) (c : C (x , y)) → D ((x , y) , c)} (λ _ → isSetΠ λ _ → isSetΠ λ _ → set _) (λ x → elim (λ _ → isSetΠ λ _ → set _) (g x)) x y c prodElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} → ((x : ∥ A ∥₂ × ∥ B ∥₂) → isSet (C x)) → ((a : A) (b : B) → C (∣ a ∣₂ , ∣ b ∣₂)) → (x : ∥ A ∥₂ × ∥ B ∥₂) → C x prodElim setC f (a , b) = elim2 (λ x y → setC (x , y)) f a b prodRec : {C : Type ℓ} → isSet C → (A → B → C) → ∥ A ∥₂ × ∥ B ∥₂ → C prodRec setC f (a , b) = rec2 setC f a b prodElim2 : {E : (∥ A ∥₂ × ∥ B ∥₂) → (∥ C ∥₂ × ∥ D ∥₂) → Type ℓ} → ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → isSet (E x y)) → ((a : A) (b : B) (c : C) (d : D) → E (∣ a ∣₂ , ∣ b ∣₂) (∣ c ∣₂ , ∣ d ∣₂)) → ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → (E x y)) prodElim2 isset f = prodElim (λ _ → isSetΠ λ _ → isset _ _) λ a b → prodElim (λ _ → isset _ _) λ c d → f a b c d setTruncOfProdIso : Iso ∥ A × B ∥₂ (∥ A ∥₂ × ∥ B ∥₂) Iso.fun setTruncOfProdIso = rec (isSet× isSetSetTrunc isSetSetTrunc) λ { (a , b) → ∣ a ∣₂ , ∣ b ∣₂ } Iso.inv setTruncOfProdIso = prodRec isSetSetTrunc λ a b → ∣ a , b ∣₂ Iso.rightInv setTruncOfProdIso = prodElim (λ _ → isOfHLevelPath 2 (isSet× isSetSetTrunc isSetSetTrunc) _ _) λ _ _ → refl Iso.leftInv setTruncOfProdIso = elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) λ {(a , b) → refl} IsoSetTruncateSndΣ : {A : Type ℓ} {B : A → Type ℓ'} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ Iso.fun IsoSetTruncateSndΣ = map λ a → (fst a) , ∣ snd a ∣₂ Iso.inv IsoSetTruncateSndΣ = rec isSetSetTrunc (uncurry λ x → map λ b → x , b) Iso.rightInv IsoSetTruncateSndΣ = elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) (uncurry λ a → elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) λ _ → refl) Iso.leftInv IsoSetTruncateSndΣ = elim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _) λ _ → refl PathIdTrunc₀Iso : {a b : A} → Iso (∣ a ∣₂ ≡ ∣ b ∣₂) ∥ a ≡ b ∥₁ Iso.fun (PathIdTrunc₀Iso {b = b}) p = transport (λ i → rec {B = TypeOfHLevel _ 1} (isOfHLevelTypeOfHLevel 1) (λ a → ∥ a ≡ b ∥₁ , squash₁) (p (~ i)) .fst) ∣ refl ∣₁ Iso.inv PathIdTrunc₀Iso = pRec (squash₂ _ _) (cong ∣_∣₂) Iso.rightInv PathIdTrunc₀Iso _ = squash₁ _ _ Iso.leftInv PathIdTrunc₀Iso _ = squash₂ _ _ _ _
41.820669
101
0.494367
59cb9f34e7e10aac67ff77cffd26bbe070da660f
6,333
agda
Agda
proglangs-learning/Agda/plfa-exercises/part1/Decidable.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
proglangs-learning/Agda/plfa-exercises/part1/Decidable.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
4
2020-03-10T19:20:21.000Z
2021-06-07T15:39:48.000Z
proglangs-learning/Agda/plfa-exercises/part1/Decidable.agda
helq/old_code
a432faf1b340cb379190a2f2b11b997b02d1cd8d
[ "CC0-1.0" ]
null
null
null
module plfa-exercises.part1.Decidable where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; sym; cong) open Eq.≡-Reasoning open import Data.Nat using (ℕ; zero; suc; pred) open import Data.Product using (_×_) renaming (_,_ to ⟨_,_⟩) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Relation.Nullary using (¬_) open import Relation.Nullary.Negation using () renaming (contradiction to ¬¬-intro) open import Data.Unit using (⊤; tt) open import Data.Empty using (⊥; ⊥-elim) open import plfa.part1.Relations using (_<_; z<s; s<s) open import plfa.part1.Isomorphism using (_⇔_) open import Function.Base using (_∘_) infix 4 _≤_ data _≤_ : ℕ → ℕ → Set where z≤n : ∀ {n : ℕ} -------- → zero ≤ n s≤s : ∀ {m n : ℕ} → m ≤ n ------------- → suc m ≤ suc n _ : 2 ≤ 4 _ = s≤s (s≤s z≤n) ¬4≤2 : ¬ (4 ≤ 2) --¬4≤2 (s≤s (s≤s ())) = ? -- This causes Agda to die! TODO: Report ¬4≤2 (s≤s (s≤s ())) data Bool : Set where true : Bool false : Bool infix 4 _≤ᵇ_ _≤ᵇ_ : ℕ → ℕ → Bool zero ≤ᵇ n = true suc m ≤ᵇ zero = false suc m ≤ᵇ suc n = m ≤ᵇ n _ : (2 ≤ᵇ 4) ≡ true _ = refl _ : (5 ≤ᵇ 4) ≡ false _ = refl T : Bool → Set T true = ⊤ T false = ⊥ ≤→≤ᵇ : ∀ {m n} → (m ≤ n) → T (m ≤ᵇ n) ≤→≤ᵇ z≤n = tt ≤→≤ᵇ (s≤s m≤n) = ≤→≤ᵇ m≤n ≤ᵇ→≤ : ∀ {m n} → T (m ≤ᵇ n) → (m ≤ n) ≤ᵇ→≤ {zero} {_} tt = z≤n -- What is going on in here? Left `t` has type `T (suc m ≤ᵇ suc n)` and the right `t` has type `T (m ≤ᵇ n)` -- λ m n → T (suc m ≤ᵇ suc n) => reduces to: λ m n → T (m ≤ᵇ n) -- Ohh! Ok. It is because the third rule of `≤ᵇ` reduces `suc m ≤ᵇ suc n` to `m ≤ᵇ n` ≤ᵇ→≤ {suc m} {suc n} t = s≤s (≤ᵇ→≤ {m} {n} t) -- λ m → T (suc m ≤ᵇ zero) => reduces to: λ m → ⊥ -- which means that there are no rules for `fromᵇ {suc m} {zero}` ≤ᵇ→≤ {suc m} {zero} () proof≡computation : ∀ {m n} → (m ≤ n) ⇔ T (m ≤ᵇ n) proof≡computation {m} {n} = record { from = ≤ᵇ→≤ ; to = ≤→≤ᵇ } T→≡ : ∀ (b : Bool) → T b → b ≡ true T→≡ true tt = refl T→≡ false () --postulate -- lie : false ≡ true ≡→T : ∀ {b : Bool} → b ≡ true → T b --≡→T {false} refl = ? -- This is impossible because of refl's definition. Unification forces `b` to be `true` --≡→T {false} rewrite lie = λ refl → ? -- Even postulating a lie, it is impossible to create a bottom value ≡→T refl = tt _ : 2 ≤ 4 _ = ≤ᵇ→≤ tt ¬4≤2₂ : ¬ (4 ≤ 2) --¬4≤2₂ 4≤2 = ≤→≤ᵇ 4≤2 --¬4≤2₂ = ≤→≤ᵇ {4} {2} -- The type of `T (4 ≤ᵇ 2)` which reduces to `T false` and then `⊥` ¬4≤2₂ = ≤→≤ᵇ -- Notice how defining ≤ᵇ lifts from us the demand of computing the correct -- `evidence` (implementation) for the `proof` (function type) data Dec (A : Set) : Set where yes : A → Dec A no : ¬ A → Dec A ¬s≤z : {m : ℕ} → ¬ (suc m) ≤ zero --¬s≤z = ≤→≤ᵇ ¬s≤z () ¬s≤s : {m n : ℕ} → ¬ m ≤ n → ¬ suc m ≤ suc n ¬s≤s ¬m≤n = λ { (s≤s m≤n) → ¬m≤n m≤n } _≤?_ : (m n : ℕ) → Dec (m ≤ n) zero ≤? n = yes z≤n (suc m) ≤? zero = no ¬s≤z (suc m) ≤? (suc n) with m ≤? n ... | yes m≤n = yes (s≤s m≤n) ... | no ¬m≤n = no (¬s≤s ¬m≤n) -- `2 ≤? 4` reduces to `yes (s≤s (s≤s z≤n))` _ : Dec (2 ≤ 4) _ = 2 ≤? 4 _ = yes (s≤s (s≤s (z≤n {2}))) ⌊_⌋ : ∀ {A : Set} → Dec A → Bool ⌊ yes x ⌋ = true ⌊ no ¬x ⌋ = false _ : Bool _ = true _ = ⌊ 3 ≤? 4 ⌋ _ : ⌊ 3 ≤? 4 ⌋ ≡ true _ = refl _ : ⌊ 3 ≤? 2 ⌋ ≡ false _ = refl toWitness : ∀ {A : Set} {D : Dec A} → T ⌊ D ⌋ → A toWitness {_} {yes v} tt = v --toWitness {_} {no _} = ? -- `T ⌊ no x ⌋ → A` reduces to `⊥ → A` toWitness {_} {no _} () -- Empty because there is no value for `⊥` fromWitness : ∀ {A : Set} {D : Dec A} → A → T ⌊ D ⌋ fromWitness {_} {yes _} _ = tt fromWitness {_} {no ¬a} a = ¬a a -- with type ⊥ _ : 2 ≤ 4 --_ = toWitness {D = 2 ≤? 4} tt _ = toWitness {_} {2 ≤? 4} tt ¬4≤2₃ : ¬ (4 ≤ 2) --¬4≤2₃ = fromWitness {D = 4 ≤? 2} ¬4≤2₃ = fromWitness {_} {4 ≤? 2} ¬z<z : ¬ (zero < zero) ¬z<z () ¬s<z : ∀ {m : ℕ} → ¬ (suc m < zero) ¬s<z () _<?_ : ∀ (m n : ℕ) → Dec (m < n) zero <? zero = no ¬z<z zero <? suc n = yes z<s suc m <? zero = no ¬s<z suc m <? suc n with m <? n ... | yes m<n = yes (s<s m<n) ... | no ¬m<n = no λ{(s<s m<n) → ¬m<n m<n} _ : ⌊ 2 <? 4 ⌋ ≡ true _ = refl ¬z≡sn : ∀ {n : ℕ} → ¬ zero ≡ suc n ¬z≡sn () _≡ℕ?_ : ∀ (m n : ℕ) → Dec (m ≡ n) zero ≡ℕ? zero = yes refl zero ≡ℕ? (suc n) = no ¬z≡sn --(suc m) ≡ℕ? zero = no (λ{sn≡z → ¬z≡sn (sym sn≡z)}) --(suc m) ≡ℕ? zero = no (¬z≡sn ∘ sym) (suc m) ≡ℕ? zero = no ((λ()) ∘ sym) --The following doesn't work though --(suc m) ≡ℕ? zero with zero ≡ℕ? (suc m) --... | yes z≡sm = yes (sym z≡sm) --... | no ¬z≡sm = no (¬z≡sm ∘ sym) (suc m) ≡ℕ? (suc n) with m ≡ℕ? n ... | yes m≡n = yes (cong suc m≡n) ... | no ¬m≡n = no (¬m≡n ∘ (cong pred)) infixr 6 _×-dec_ _×-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A × B) yes x ×-dec yes y = yes ⟨ x , y ⟩ no ¬x ×-dec _ = no λ{ ⟨ x , y ⟩ → ¬x x } _ ×-dec no ¬y = no λ{ ⟨ x , y ⟩ → ¬y y } infixr 6 _⊎-dec_ _⊎-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⊎ B) yes x ⊎-dec _ = yes (inj₁ x) _ ⊎-dec yes y = yes (inj₂ y) no ¬x ⊎-dec no ¬y = no λ{(inj₁ x) → ¬x x; (inj₂ y) → ¬y y} ¬? : ∀ {A : Set} → Dec A → Dec (¬ A) ¬? (yes x) = no (¬¬-intro x) ¬? (no ¬x) = yes ¬x _→-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A → B) _ →-dec yes y = yes (λ _ → y) --no ¬x →-dec _ = yes ((λ()) ∘ ¬x) no ¬x →-dec _ = yes (⊥-elim ∘ ¬x) yes x →-dec no ¬y = no (λ{x→y → ¬y (x→y x)}) infixr 6 _∧_ _∧_ : Bool → Bool → Bool true ∧ true = true false ∧ _ = false _ ∧ false = false ∧-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∧ ⌊ y ⌋ ≡ ⌊ x ×-dec y ⌋ ∧-× (yes x) (yes y) = refl ∧-× (no ¬x) _ = refl ∧-× (yes x) (no ¬y) = refl _iff_ : Bool → Bool → Bool true iff true = true false iff false = true _ iff _ = false _⇔-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⇔ B) yes x ⇔-dec yes y = yes (record { from = λ{_ → x} ; to = λ{_ → y} }) no ¬x ⇔-dec no ¬y = yes (record { from = (λ()) ∘ ¬y ; to = (λ()) ∘ ¬x }) yes x ⇔-dec no ¬y = no (λ x⇔y → ¬y (_⇔_.to x⇔y x)) no ¬x ⇔-dec yes y = no (λ x⇔y → ¬x (_⇔_.from x⇔y y)) iff-⇔ : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ iff ⌊ y ⌋ ≡ ⌊ x ⇔-dec y ⌋ iff-⇔ (yes x) (yes y) = refl iff-⇔ (no ¬x) (no ¬y) = refl iff-⇔ (no ¬x) (yes y) = refl iff-⇔ (yes x) (no ¬y) = refl
25.743902
110
0.471972
31c4f536a7093cc01cd0e73f12f4f1cef3e46e2d
22,858
agda
Agda
agda-stdlib-0.9/src/Data/List/Any/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/List/Any/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/List/Any/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties related to Any ------------------------------------------------------------------------ -- The other modules under Data.List.Any also contain properties -- related to Any. module Data.List.Any.Properties where open import Algebra import Algebra.FunctionProperties as FP open import Category.Monad open import Data.Bool open import Data.Bool.Properties open import Data.Empty open import Data.List as List open import Data.List.Any as Any using (Any; here; there) open import Data.Product as Prod hiding (swap) open import Data.Sum as Sum using (_⊎_; inj₁; inj₂; [_,_]′) open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence as Eq using (_⇔_; module Equivalence) open import Function.Inverse as Inv using (_↔_; module Inverse) open import Function.Related as Related using (Related) open import Function.Related.TypeIsomorphisms open import Level open import Relation.Binary import Relation.Binary.HeterogeneousEquality as H open import Relation.Binary.Product.Pointwise open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; inspect) renaming ([_] to P[_]) open import Relation.Unary using (_⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_) import Relation.Binary.Sigma.Pointwise as Σ open import Relation.Binary.Sum open Any.Membership-≡ open Related.EquationalReasoning private module ×⊎ {k ℓ} = CommutativeSemiring (×⊎-CommutativeSemiring k ℓ) open module ListMonad {ℓ} = RawMonad (List.monad {ℓ = ℓ}) ------------------------------------------------------------------------ -- Some lemmas related to map, find and lose -- Any.map is functorial. map-id : ∀ {a p} {A : Set a} {P : A → Set p} (f : P ⋐ P) {xs} → (∀ {x} (p : P x) → f p ≡ p) → (p : Any P xs) → Any.map f p ≡ p map-id f hyp (here p) = P.cong here (hyp p) map-id f hyp (there p) = P.cong there $ map-id f hyp p map-∘ : ∀ {a p q r} {A : Set a} {P : A → Set p} {Q : A → Set q} {R : A → Set r} (f : Q ⋐ R) (g : P ⋐ Q) {xs} (p : Any P xs) → Any.map (f ∘ g) p ≡ Any.map f (Any.map g p) map-∘ f g (here p) = refl map-∘ f g (there p) = P.cong there $ map-∘ f g p -- Lemmas relating map and find. map∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs} (p : Any P xs) → let p′ = find p in {f : _≡_ (proj₁ p′) ⋐ P} → f refl ≡ proj₂ (proj₂ p′) → Any.map f (proj₁ (proj₂ p′)) ≡ p map∘find (here p) hyp = P.cong here hyp map∘find (there p) hyp = P.cong there (map∘find p hyp) find∘map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {xs : List A} (p : Any P xs) (f : P ⋐ Q) → find (Any.map f p) ≡ Prod.map id (Prod.map id f) (find p) find∘map (here p) f = refl find∘map (there p) f rewrite find∘map p f = refl -- find satisfies a simple equality when the predicate is a -- propositional equality. find-∈ : ∀ {a} {A : Set a} {x : A} {xs : List A} (x∈xs : x ∈ xs) → find x∈xs ≡ (x , x∈xs , refl) find-∈ (here refl) = refl find-∈ (there x∈xs) rewrite find-∈ x∈xs = refl private -- find and lose are inverses (more or less). lose∘find : ∀ {a p} {A : Set a} {P : A → Set p} {xs : List A} (p : Any P xs) → uncurry′ lose (proj₂ (find p)) ≡ p lose∘find p = map∘find p P.refl find∘lose : ∀ {a p} {A : Set a} (P : A → Set p) {x xs} (x∈xs : x ∈ xs) (pp : P x) → find {P = P} (lose x∈xs pp) ≡ (x , x∈xs , pp) find∘lose P x∈xs p rewrite find∘map x∈xs (flip (P.subst P) p) | find-∈ x∈xs = refl -- Any can be expressed using _∈_. Any↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} → (∃ λ x → x ∈ xs × P x) ↔ Any P xs Any↔ {P = P} {xs} = record { to = P.→-to-⟶ to ; from = P.→-to-⟶ (find {P = P}) ; inverse-of = record { left-inverse-of = λ p → find∘lose P (proj₁ (proj₂ p)) (proj₂ (proj₂ p)) ; right-inverse-of = lose∘find } } where to : (∃ λ x → x ∈ xs × P x) → Any P xs to = uncurry′ lose ∘ proj₂ ------------------------------------------------------------------------ -- Any is a congruence Any-cong : ∀ {k ℓ} {A : Set ℓ} {P₁ P₂ : A → Set ℓ} {xs₁ xs₂ : List A} → (∀ x → Related k (P₁ x) (P₂ x)) → xs₁ ∼[ k ] xs₂ → Related k (Any P₁ xs₁) (Any P₂ xs₂) Any-cong {P₁ = P₁} {P₂} {xs₁} {xs₂} P₁↔P₂ xs₁≈xs₂ = Any P₁ xs₁ ↔⟨ sym $ Any↔ {P = P₁} ⟩ (∃ λ x → x ∈ xs₁ × P₁ x) ∼⟨ Σ.cong Inv.id (xs₁≈xs₂ ×-cong P₁↔P₂ _) ⟩ (∃ λ x → x ∈ xs₂ × P₂ x) ↔⟨ Any↔ {P = P₂} ⟩ Any P₂ xs₂ ∎ ------------------------------------------------------------------------ -- Swapping -- Nested occurrences of Any can sometimes be swapped. See also ×↔. swap : ∀ {ℓ} {A B : Set ℓ} {P : A → B → Set ℓ} {xs ys} → Any (λ x → Any (P x) ys) xs ↔ Any (λ y → Any (flip P y) xs) ys swap {ℓ} {P = P} {xs} {ys} = Any (λ x → Any (P x) ys) xs ↔⟨ sym $ Any↔ {a = ℓ} {p = ℓ} ⟩ (∃ λ x → x ∈ xs × Any (P x) ys) ↔⟨ sym $ Σ.cong Inv.id (λ {x} → (x ∈ xs ∎) ⟨ ×⊎.*-cong {ℓ = ℓ} ⟩ Any↔ {a = ℓ} {p = ℓ}) ⟩ (∃ λ x → x ∈ xs × ∃ λ y → y ∈ ys × P x y) ↔⟨ Σ.cong {a₁ = ℓ} Inv.id (∃∃↔∃∃ {a = ℓ} {b = ℓ} {p = ℓ} _) ⟩ (∃₂ λ x y → x ∈ xs × y ∈ ys × P x y) ↔⟨ ∃∃↔∃∃ {a = ℓ} {b = ℓ} {p = ℓ} _ ⟩ (∃₂ λ y x → x ∈ xs × y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → Σ.cong Inv.id (λ {x} → (x ∈ xs × y ∈ ys × P x y) ↔⟨ sym $ ×⊎.*-assoc _ _ _ ⟩ ((x ∈ xs × y ∈ ys) × P x y) ↔⟨ ×⊎.*-comm (x ∈ xs) (y ∈ ys) ⟨ ×⊎.*-cong ⟩ (P x y ∎) ⟩ ((y ∈ ys × x ∈ xs) × P x y) ↔⟨ ×⊎.*-assoc _ _ _ ⟩ (y ∈ ys × x ∈ xs × P x y) ∎)) ⟩ (∃₂ λ y x → y ∈ ys × x ∈ xs × P x y) ↔⟨ Σ.cong {a₁ = ℓ} Inv.id (∃∃↔∃∃ {a = ℓ} {b = ℓ} {p = ℓ} _) ⟩ (∃ λ y → y ∈ ys × ∃ λ x → x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → (y ∈ ys ∎) ⟨ ×⊎.*-cong {ℓ = ℓ} ⟩ Any↔ {a = ℓ} {p = ℓ}) ⟩ (∃ λ y → y ∈ ys × Any (flip P y) xs) ↔⟨ Any↔ {a = ℓ} {p = ℓ} ⟩ Any (λ y → Any (flip P y) xs) ys ∎ ------------------------------------------------------------------------ -- Lemmas relating Any to ⊥ ⊥↔Any⊥ : ∀ {a} {A : Set a} {xs : List A} → ⊥ ↔ Any (const ⊥) xs ⊥↔Any⊥ {A = A} = record { to = P.→-to-⟶ (λ ()) ; from = P.→-to-⟶ (λ p → from p) ; inverse-of = record { left-inverse-of = λ () ; right-inverse-of = λ p → from p } } where from : {xs : List A} → Any (const ⊥) xs → ∀ {b} {B : Set b} → B from (here ()) from (there p) = from p ⊥↔Any[] : ∀ {a} {A : Set a} {P : A → Set} → ⊥ ↔ Any P [] ⊥↔Any[] = record { to = P.→-to-⟶ (λ ()) ; from = P.→-to-⟶ (λ ()) ; inverse-of = record { left-inverse-of = λ () ; right-inverse-of = λ () } } ------------------------------------------------------------------------ -- Lemmas relating Any to sums and products -- Sums commute with Any (for a fixed list). ⊎↔ : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {xs} → (Any P xs ⊎ Any Q xs) ↔ Any (λ x → P x ⊎ Q x) xs ⊎↔ {P = P} {Q} = record { to = P.→-to-⟶ to ; from = P.→-to-⟶ from ; inverse-of = record { left-inverse-of = from∘to ; right-inverse-of = to∘from } } where to : ∀ {xs} → Any P xs ⊎ Any Q xs → Any (λ x → P x ⊎ Q x) xs to = [ Any.map inj₁ , Any.map inj₂ ]′ from : ∀ {xs} → Any (λ x → P x ⊎ Q x) xs → Any P xs ⊎ Any Q xs from (here (inj₁ p)) = inj₁ (here p) from (here (inj₂ q)) = inj₂ (here q) from (there p) = Sum.map there there (from p) from∘to : ∀ {xs} (p : Any P xs ⊎ Any Q xs) → from (to p) ≡ p from∘to (inj₁ (here p)) = P.refl from∘to (inj₁ (there p)) rewrite from∘to (inj₁ p) = P.refl from∘to (inj₂ (here q)) = P.refl from∘to (inj₂ (there q)) rewrite from∘to (inj₂ q) = P.refl to∘from : ∀ {xs} (p : Any (λ x → P x ⊎ Q x) xs) → to (from p) ≡ p to∘from (here (inj₁ p)) = P.refl to∘from (here (inj₂ q)) = P.refl to∘from (there p) with from p | to∘from p to∘from (there .(Any.map inj₁ p)) | inj₁ p | P.refl = P.refl to∘from (there .(Any.map inj₂ q)) | inj₂ q | P.refl = P.refl -- Products "commute" with Any. ×↔ : {A B : Set} {P : A → Set} {Q : B → Set} {xs : List A} {ys : List B} → (Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs ×↔ {P = P} {Q} {xs} {ys} = record { to = P.→-to-⟶ to ; from = P.→-to-⟶ from ; inverse-of = record { left-inverse-of = from∘to ; right-inverse-of = to∘from } } where to : Any P xs × Any Q ys → Any (λ x → Any (λ y → P x × Q y) ys) xs to (p , q) = Any.map (λ p → Any.map (λ q → (p , q)) q) p from : Any (λ x → Any (λ y → P x × Q y) ys) xs → Any P xs × Any Q ys from pq with Prod.map id (Prod.map id find) (find pq) ... | (x , x∈xs , y , y∈ys , p , q) = (lose x∈xs p , lose y∈ys q) from∘to : ∀ pq → from (to pq) ≡ pq from∘to (p , q) rewrite find∘map {Q = λ x → Any (λ y → P x × Q y) ys} p (λ p → Any.map (λ q → (p , q)) q) | find∘map {Q = λ y → P (proj₁ (find p)) × Q y} q (λ q → proj₂ (proj₂ (find p)) , q) | lose∘find p | lose∘find q = refl to∘from : ∀ pq → to (from pq) ≡ pq to∘from pq with find pq | (λ (f : _≡_ (proj₁ (find pq)) ⋐ _) → map∘find pq {f}) ... | (x , x∈xs , pq′) | lem₁ with find pq′ | (λ (f : _≡_ (proj₁ (find pq′)) ⋐ _) → map∘find pq′ {f}) ... | (y , y∈ys , p , q) | lem₂ rewrite P.sym $ map-∘ {R = λ x → Any (λ y → P x × Q y) ys} (λ p → Any.map (λ q → p , q) (lose y∈ys q)) (λ y → P.subst P y p) x∈xs = lem₁ _ helper where helper : Any.map (λ q → p , q) (lose y∈ys q) ≡ pq′ helper rewrite P.sym $ map-∘ {R = λ y → P x × Q y} (λ q → p , q) (λ y → P.subst Q y q) y∈ys = lem₂ _ refl ------------------------------------------------------------------------ -- Invertible introduction (⁺) and elimination (⁻) rules for various -- list functions -- map. private map⁺ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → Any (P ∘ f) xs → Any P (List.map f xs) map⁺ (here p) = here p map⁺ (there p) = there $ map⁺ p map⁻ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → Any P (List.map f xs) → Any (P ∘ f) xs map⁻ {xs = []} () map⁻ {xs = x ∷ xs} (here p) = here p map⁻ {xs = x ∷ xs} (there p) = there $ map⁻ p map⁺∘map⁻ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → (p : Any P (List.map f xs)) → map⁺ (map⁻ p) ≡ p map⁺∘map⁻ {xs = []} () map⁺∘map⁻ {xs = x ∷ xs} (here p) = refl map⁺∘map⁻ {xs = x ∷ xs} (there p) = P.cong there (map⁺∘map⁻ p) map⁻∘map⁺ : ∀ {a b p} {A : Set a} {B : Set b} (P : B → Set p) {f : A → B} {xs} → (p : Any (P ∘ f) xs) → map⁻ {P = P} (map⁺ p) ≡ p map⁻∘map⁺ P (here p) = refl map⁻∘map⁺ P (there p) = P.cong there (map⁻∘map⁺ P p) map↔ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} {xs} → Any (P ∘ f) xs ↔ Any P (List.map f xs) map↔ {P = P} {f = f} = record { to = P.→-to-⟶ $ map⁺ {P = P} {f = f} ; from = P.→-to-⟶ $ map⁻ {P = P} {f = f} ; inverse-of = record { left-inverse-of = map⁻∘map⁺ P ; right-inverse-of = map⁺∘map⁻ } } -- _++_. private ++⁺ˡ : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} → Any P xs → Any P (xs ++ ys) ++⁺ˡ (here p) = here p ++⁺ˡ (there p) = there (++⁺ˡ p) ++⁺ʳ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} → Any P ys → Any P (xs ++ ys) ++⁺ʳ [] p = p ++⁺ʳ (x ∷ xs) p = there (++⁺ʳ xs p) ++⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} → Any P (xs ++ ys) → Any P xs ⊎ Any P ys ++⁻ [] p = inj₂ p ++⁻ (x ∷ xs) (here p) = inj₁ (here p) ++⁻ (x ∷ xs) (there p) = Sum.map there id (++⁻ xs p) ++⁺∘++⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P (xs ++ ys)) → [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs p) ≡ p ++⁺∘++⁻ [] p = refl ++⁺∘++⁻ (x ∷ xs) (here p) = refl ++⁺∘++⁻ (x ∷ xs) (there p) with ++⁻ xs p | ++⁺∘++⁻ xs p ++⁺∘++⁻ (x ∷ xs) (there p) | inj₁ p′ | ih = P.cong there ih ++⁺∘++⁻ (x ∷ xs) (there p) | inj₂ p′ | ih = P.cong there ih ++⁻∘++⁺ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P xs ⊎ Any P ys) → ++⁻ xs ([ ++⁺ˡ , ++⁺ʳ xs ]′ p) ≡ p ++⁻∘++⁺ [] (inj₁ ()) ++⁻∘++⁺ [] (inj₂ p) = refl ++⁻∘++⁺ (x ∷ xs) (inj₁ (here p)) = refl ++⁻∘++⁺ (x ∷ xs) {ys} (inj₁ (there p)) rewrite ++⁻∘++⁺ xs {ys} (inj₁ p) = refl ++⁻∘++⁺ (x ∷ xs) (inj₂ p) rewrite ++⁻∘++⁺ xs (inj₂ p) = refl ++ˡ = ++⁺ˡ ++ʳ = ++⁺ʳ ++↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} → (Any P xs ⊎ Any P ys) ↔ Any P (xs ++ ys) ++↔ {P = P} {xs = xs} = record { to = P.→-to-⟶ [ ++⁺ˡ {P = P}, ++⁺ʳ {P = P} xs ]′ ; from = P.→-to-⟶ $ ++⁻ {P = P} xs ; inverse-of = record { left-inverse-of = ++⁻∘++⁺ xs ; right-inverse-of = ++⁺∘++⁻ xs } } -- return. private return⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {x} → P x → Any P (return x) return⁺ = here return⁻ : ∀ {a p} {A : Set a} {P : A → Set p} {x} → Any P (return x) → P x return⁻ (here p) = p return⁻ (there ()) return⁺∘return⁻ : ∀ {a p} {A : Set a} {P : A → Set p} {x} (p : Any P (return x)) → return⁺ (return⁻ p) ≡ p return⁺∘return⁻ (here p) = refl return⁺∘return⁻ (there ()) return⁻∘return⁺ : ∀ {a p} {A : Set a} (P : A → Set p) {x} (p : P x) → return⁻ {P = P} (return⁺ p) ≡ p return⁻∘return⁺ P p = refl return↔ : ∀ {a p} {A : Set a} {P : A → Set p} {x} → P x ↔ Any P (return x) return↔ {P = P} = record { to = P.→-to-⟶ $ return⁺ {P = P} ; from = P.→-to-⟶ $ return⁻ {P = P} ; inverse-of = record { left-inverse-of = return⁻∘return⁺ P ; right-inverse-of = return⁺∘return⁻ } } -- _∷_. ∷↔ : ∀ {a p} {A : Set a} (P : A → Set p) {x xs} → (P x ⊎ Any P xs) ↔ Any P (x ∷ xs) ∷↔ P {x} {xs} = (P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩ (Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩ Any P (x ∷ xs) ∎ -- concat. private concat⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} → Any (Any P) xss → Any P (concat xss) concat⁺ (here p) = ++⁺ˡ p concat⁺ (there {x = xs} p) = ++⁺ʳ xs (concat⁺ p) concat⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xss → Any P (concat xss) → Any (Any P) xss concat⁻ [] () concat⁻ ([] ∷ xss) p = there $ concat⁻ xss p concat⁻ ((x ∷ xs) ∷ xss) (here p) = here (here p) concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p ... | here p′ = here (there p′) ... | there p′ = there p′ concat⁻∘++⁺ˡ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} xss (p : Any P xs) → concat⁻ (xs ∷ xss) (++⁺ˡ p) ≡ here p concat⁻∘++⁺ˡ xss (here p) = refl concat⁻∘++⁺ˡ xss (there p) rewrite concat⁻∘++⁺ˡ xss p = refl concat⁻∘++⁺ʳ : ∀ {a p} {A : Set a} {P : A → Set p} xs xss (p : Any P (concat xss)) → concat⁻ (xs ∷ xss) (++⁺ʳ xs p) ≡ there (concat⁻ xss p) concat⁻∘++⁺ʳ [] xss p = refl concat⁻∘++⁺ʳ (x ∷ xs) xss p rewrite concat⁻∘++⁺ʳ xs xss p = refl concat⁺∘concat⁻ : ∀ {a p} {A : Set a} {P : A → Set p} xss (p : Any P (concat xss)) → concat⁺ (concat⁻ xss p) ≡ p concat⁺∘concat⁻ [] () concat⁺∘concat⁻ ([] ∷ xss) p = concat⁺∘concat⁻ xss p concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (here p) = refl concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p | concat⁺∘concat⁻ (xs ∷ xss) p concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ˡ p′)) | here p′ | refl = refl concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ʳ xs (concat⁺ p′))) | there p′ | refl = refl concat⁻∘concat⁺ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} (p : Any (Any P) xss) → concat⁻ xss (concat⁺ p) ≡ p concat⁻∘concat⁺ (here p) = concat⁻∘++⁺ˡ _ p concat⁻∘concat⁺ (there {x = xs} {xs = xss} p) rewrite concat⁻∘++⁺ʳ xs xss (concat⁺ p) = P.cong there $ concat⁻∘concat⁺ p concat↔ : ∀ {a p} {A : Set a} {P : A → Set p} {xss} → Any (Any P) xss ↔ Any P (concat xss) concat↔ {P = P} {xss = xss} = record { to = P.→-to-⟶ $ concat⁺ {P = P} ; from = P.→-to-⟶ $ concat⁻ {P = P} xss ; inverse-of = record { left-inverse-of = concat⁻∘concat⁺ ; right-inverse-of = concat⁺∘concat⁻ xss } } -- _>>=_. >>=↔ : ∀ {ℓ p} {A B : Set ℓ} {P : B → Set p} {xs} {f : A → List B} → Any (Any P ∘ f) xs ↔ Any P (xs >>= f) >>=↔ {P = P} {xs} {f} = Any (Any P ∘ f) xs ↔⟨ map↔ {P = Any P} {f = f} ⟩ Any (Any P) (List.map f xs) ↔⟨ concat↔ {P = P} ⟩ Any P (xs >>= f) ∎ -- _⊛_. ⊛↔ : ∀ {ℓ} {A B : Set ℓ} {P : B → Set ℓ} {fs : List (A → B)} {xs : List A} → Any (λ f → Any (P ∘ f) xs) fs ↔ Any P (fs ⊛ xs) ⊛↔ {ℓ} {P = P} {fs} {xs} = Any (λ f → Any (P ∘ f) xs) fs ↔⟨ Any-cong (λ _ → Any-cong (λ _ → return↔ {a = ℓ} {p = ℓ}) (_ ∎)) (_ ∎) ⟩ Any (λ f → Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ {ℓ = ℓ} {p = ℓ}) (_ ∎) ⟩ Any (λ f → Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩ Any P (fs ⊛ xs) ∎ -- An alternative introduction rule for _⊛_. ⊛⁺′ : ∀ {ℓ} {A B : Set ℓ} {P : A → Set ℓ} {Q : B → Set ℓ} {fs : List (A → B)} {xs} → Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs) ⊛⁺′ {ℓ} pq p = Inverse.to (⊛↔ {ℓ = ℓ}) ⟨$⟩ Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq -- _⊗_. ⊗↔ : ∀ {ℓ} {A B : Set ℓ} {P : A × B → Set ℓ} {xs : List A} {ys : List B} → Any (λ x → Any (λ y → P (x , y)) ys) xs ↔ Any P (xs ⊗ ys) ⊗↔ {ℓ} {P = P} {xs} {ys} = Any (λ x → Any (λ y → P (x , y)) ys) xs ↔⟨ return↔ {a = ℓ} {p = ℓ} ⟩ Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩ Any (λ x, → Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩ Any P (xs ⊗ ys) ∎ ⊗↔′ : {A B : Set} {P : A → Set} {Q : B → Set} {xs : List A} {ys : List B} → (Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys) ⊗↔′ {P = P} {Q} {xs} {ys} = (Any P xs × Any Q ys) ↔⟨ ×↔ ⟩ Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩ Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎ -- map-with-∈. map-with-∈↔ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {xs : List A} {f : ∀ {x} → x ∈ xs → B} → (∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) ↔ Any P (map-with-∈ xs f) map-with-∈↔ {A = A} {B} {P} = record { to = P.→-to-⟶ (map-with-∈⁺ _) ; from = P.→-to-⟶ (map-with-∈⁻ _ _) ; inverse-of = record { left-inverse-of = from∘to _ ; right-inverse-of = to∘from _ _ } } where map-with-∈⁺ : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) → (∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) → Any P (map-with-∈ xs f) map-with-∈⁺ f (_ , here refl , p) = here p map-with-∈⁺ f (_ , there x∈xs , p) = there $ map-with-∈⁺ (f ∘ there) (_ , x∈xs , p) map-with-∈⁻ : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) → Any P (map-with-∈ xs f) → ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs) map-with-∈⁻ [] f () map-with-∈⁻ (y ∷ xs) f (here p) = (y , here refl , p) map-with-∈⁻ (y ∷ xs) f (there p) = Prod.map id (Prod.map there id) $ map-with-∈⁻ xs (f ∘ there) p from∘to : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) (p : ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) → map-with-∈⁻ xs f (map-with-∈⁺ f p) ≡ p from∘to f (_ , here refl , p) = refl from∘to f (_ , there x∈xs , p) rewrite from∘to (f ∘ there) (_ , x∈xs , p) = refl to∘from : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) (p : Any P (map-with-∈ xs f)) → map-with-∈⁺ f (map-with-∈⁻ xs f p) ≡ p to∘from [] f () to∘from (y ∷ xs) f (here p) = refl to∘from (y ∷ xs) f (there p) = P.cong there $ to∘from xs (f ∘ there) p ------------------------------------------------------------------------ -- Any and any are related via T -- These introduction and elimination rules are not inverses, though. private any⁺ : ∀ {a} {A : Set a} (p : A → Bool) {xs} → Any (T ∘ p) xs → T (any p xs) any⁺ p (here px) = Equivalence.from T-∨ ⟨$⟩ inj₁ px any⁺ p (there {x = x} pxs) with p x ... | true = _ ... | false = any⁺ p pxs any⁻ : ∀ {a} {A : Set a} (p : A → Bool) xs → T (any p xs) → Any (T ∘ p) xs any⁻ p [] () any⁻ p (x ∷ xs) px∷xs with p x | inspect p x any⁻ p (x ∷ xs) px∷xs | true | P[ eq ] = here (Equivalence.from T-≡ ⟨$⟩ eq) any⁻ p (x ∷ xs) px∷xs | false | _ = there (any⁻ p xs px∷xs) any⇔ : ∀ {a} {A : Set a} {p : A → Bool} {xs} → Any (T ∘ p) xs ⇔ T (any p xs) any⇔ = Eq.equivalence (any⁺ _) (any⁻ _ _) ------------------------------------------------------------------------ -- _++_ is commutative private ++-comm : ∀ {a p} {A : Set a} {P : A → Set p} xs ys → Any P (xs ++ ys) → Any P (ys ++ xs) ++-comm xs ys = [ ++⁺ʳ ys , ++⁺ˡ ]′ ∘ ++⁻ xs ++-comm∘++-comm : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P (xs ++ ys)) → ++-comm ys xs (++-comm xs ys p) ≡ p ++-comm∘++-comm [] {ys} p rewrite ++⁻∘++⁺ ys {ys = []} (inj₁ p) = P.refl ++-comm∘++-comm {P = P} (x ∷ xs) {ys} (here p) rewrite ++⁻∘++⁺ {P = P} ys {ys = x ∷ xs} (inj₂ (here p)) = P.refl ++-comm∘++-comm (x ∷ xs) (there p) with ++⁻ xs p | ++-comm∘++-comm xs p ++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ʳ ys p)))) | inj₁ p | P.refl rewrite ++⁻∘++⁺ ys (inj₂ p) | ++⁻∘++⁺ ys (inj₂ $ there {x = x} p) = P.refl ++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ˡ p)))) | inj₂ p | P.refl rewrite ++⁻∘++⁺ ys {ys = xs} (inj₁ p) | ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₁ p) = P.refl ++↔++ : ∀ {a p} {A : Set a} {P : A → Set p} xs ys → Any P (xs ++ ys) ↔ Any P (ys ++ xs) ++↔++ {P = P} xs ys = record { to = P.→-to-⟶ $ ++-comm {P = P} xs ys ; from = P.→-to-⟶ $ ++-comm {P = P} ys xs ; inverse-of = record { left-inverse-of = ++-comm∘++-comm xs ; right-inverse-of = ++-comm∘++-comm ys } }
36.398089
133
0.418716
4103cfc550f0703916f84ab6a78c4944908fc40a
72
agda
Agda
test/Fail/Issue2075.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2075.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2075.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
data Unit : Set where unit : Unit F : Unit → Set₁ F {x = unit} = Set
12
21
0.583333
506853d6b7d6a6bfd9d31f561dc8aeda41ab6103
80
agda
Agda
Hello-Worlds/helloworld.agda
LumaLiana/Hello-World
bb1e3f58ee30ae147518d9d0aa4cd77ff4a3f7a4
[ "Apache-2.0" ]
32
2019-04-29T03:16:15.000Z
2022-02-19T19:52:37.000Z
Hello-Worlds/helloworld.agda
LumaLiana/Hello-World
bb1e3f58ee30ae147518d9d0aa4cd77ff4a3f7a4
[ "Apache-2.0" ]
14
2020-01-10T18:43:49.000Z
2021-10-23T01:44:52.000Z
Hello-Worlds/helloworld.agda
LumaLiana/Hello-World
bb1e3f58ee30ae147518d9d0aa4cd77ff4a3f7a4
[ "Apache-2.0" ]
7
2020-01-10T18:16:16.000Z
2021-03-05T01:59:10.000Z
module hello-world where open import IO main = run (putStrLn "Hello, World!")
13.333333
37
0.725
57ebb05caff2cbe4e4e5b51b41507368458f5d7b
5,274
agda
Agda
Definition/LogicalRelation/Substitution/Introductions/Application.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2018-06-21T08:39:01.000Z
2022-01-17T16:13:53.000Z
Definition/LogicalRelation/Substitution/Introductions/Application.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
null
null
null
Definition/LogicalRelation/Substitution/Introductions/Application.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2022-01-26T14:55:51.000Z
2022-02-15T19:42:19.000Z
{-# OPTIONS --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Introductions.Application {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Application open import Definition.LogicalRelation.Substitution open import Definition.LogicalRelation.Substitution.Introductions.SingleSubst open import Definition.LogicalRelation.Substitution.Introductions.Pi open import Definition.LogicalRelation.Substitution.Weakening import Definition.LogicalRelation.Substitution.Irrelevance as S open import Tools.Product import Tools.PropositionalEquality as PE import Data.Nat as Nat -- Application of valid terms. appᵛ : ∀ {F G rF lF lG rΠ lΠ t u Γ l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ rF , ι lF ] / [Γ]) ([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rΠ , ι lΠ ] / [Γ]) ([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rΠ , ι lΠ ] / [Γ] / [ΠFG]) ([u] : Γ ⊩ᵛ⟨ l ⟩ u ∷ F ^ [ rF , ι lF ] / [Γ] / [F]) → Γ ⊩ᵛ⟨ l ⟩ t ∘ u ^ lΠ ∷ G [ u ] ^ [ rΠ , ι lG ] / [Γ] / substSΠ {F} {G} {u} [Γ] [F] [ΠFG] [u] appᵛ {F} {G} {rF} {lF} {lG} {rΠ} {lΠ} {t} {u} [Γ] [F] [ΠFG] [t] [u] {σ = σ} ⊢Δ [σ] = let [G[u]] = substSΠ {F} {G} {u} [Γ] [F] [ΠFG] [u] [σF] = proj₁ ([F] ⊢Δ [σ]) [σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ]) [σt] = proj₁ ([t] ⊢Δ [σ]) [σu] = proj₁ ([u] ⊢Δ [σ]) [σG[u]] = proj₁ ([G[u]] ⊢Δ [σ]) [σG[u]]′ = irrelevance′ (singleSubstLift G u) [σG[u]] in irrelevanceTerm′ (PE.sym (singleSubstLift G u)) PE.refl PE.refl [σG[u]]′ [σG[u]] (appTerm PE.refl [σF] [σG[u]]′ [σΠFG] [σt] [σu]) , (λ [σ′] [σ≡σ′] → let [σu′] = convTerm₂ [σF] (proj₁ ([F] ⊢Δ [σ′])) (proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′]) (proj₁ ([u] ⊢Δ [σ′])) in irrelevanceEqTerm′ (PE.sym (singleSubstLift G u)) PE.refl PE.refl [σG[u]]′ [σG[u]] (app-congTerm [σF] [σG[u]]′ [σΠFG] (proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′]) [σu] [σu′] (proj₂ ([u] ⊢Δ [σ]) [σ′] [σ≡σ′]))) -- Application congurence of valid terms. app-congᵛ : ∀ {F G rF lF lG rΠ lΠ t u a b Γ l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ rF , ι lF ] / [Γ]) ([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rΠ , ι lΠ ] / [Γ]) ([t≡u] : Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rΠ , ι lΠ ] / [Γ] / [ΠFG]) ([a] : Γ ⊩ᵛ⟨ l ⟩ a ∷ F ^ [ rF , ι lF ] / [Γ] / [F]) ([b] : Γ ⊩ᵛ⟨ l ⟩ b ∷ F ^ [ rF , ι lF ] / [Γ] / [F]) ([a≡b] : Γ ⊩ᵛ⟨ l ⟩ a ≡ b ∷ F ^ [ rF , ι lF ] / [Γ] / [F]) → Γ ⊩ᵛ⟨ l ⟩ t ∘ a ^ lΠ ≡ u ∘ b ^ lΠ ∷ G [ a ] ^ [ rΠ , ι lG ] / [Γ] / substSΠ {F} {G} {a} [Γ] [F] [ΠFG] [a] app-congᵛ {F} {G} {rF} {lF} {lG} {rΠ} {a = a} [Γ] [F] [ΠFG] [t≡u] [a] [b] [a≡b] ⊢Δ [σ] = let [σF] = proj₁ ([F] ⊢Δ [σ]) [G[a]] = proj₁ (substSΠ {F} {G} {a} [Γ] [F] [ΠFG] [a] ⊢Δ [σ]) [G[a]]′ = irrelevance′ (singleSubstLift G a) [G[a]] [σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ]) [σa] = proj₁ ([a] ⊢Δ [σ]) [σb] = proj₁ ([b] ⊢Δ [σ]) in irrelevanceEqTerm′ (PE.sym (singleSubstLift G a)) PE.refl PE.refl [G[a]]′ [G[a]] (app-congTerm [σF] [G[a]]′ [σΠFG] ([t≡u] ⊢Δ [σ]) [σa] [σb] ([a≡b] ⊢Δ [σ])) appᵛ↑ : ∀ {F F' G rF rF' lF lF' lG rΠ lΠ t u Γ l} (lF≤ : lF ≤ lΠ) (lG≤ : lG ≤ lΠ) ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ rF , ι lF ] / [Γ]) ([F'] : Γ ⊩ᵛ⟨ l ⟩ F' ^ [ rF' , ι lF' ] / [Γ]) ([G] : Γ ∙ F ^ [ rF , ι lF ] ⊩ᵛ⟨ l ⟩ G ^ [ rΠ , ι lG ] / [Γ] ∙ [F]) ([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rΠ , ι lΠ ] / [Γ]) ([t] : Γ ∙ F' ^ [ rF' , ι lF' ] ⊩ᵛ⟨ l ⟩ t ∷ wk1 (Π F ^ rF ° lF ▹ G ° lG ° lΠ) ^ [ rΠ , ι lΠ ] / [Γ] ∙ [F'] / wk1ᵛ {A = Π F ^ rF ° lF ▹ G ° lG ° lΠ} {F = F'} [Γ] [F'] [ΠFG]) ([u] : Γ ∙ F' ^ [ rF' , ι lF' ] ⊩ᵛ⟨ l ⟩ u ∷ wk1 F ^ [ rF , ι lF ] / [Γ] ∙ [F'] / wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F]) → Γ ∙ F' ^ [ rF' , ι lF' ] ⊩ᵛ⟨ l ⟩ t ∘ u ^ lΠ ∷ G [ u ]↑ ^ [ rΠ , ι lG ] / [Γ] ∙ [F'] / subst↑S {F'} {G} {u} {F' = F} [Γ] [F'] [F] [G] [u] appᵛ↑ {F} {F'} {G} {rF} {rF'} {lF} {lF'} {lG} {rΠ} {lΠ} {t} {u} lF≤ lG≤ [Γ] [F] [F'] [G] [ΠFG] [t] [u] = let [G[u]] = subst↑S {F'} {G} {u} {F' = F} [Γ] [F'] [F] [G] [u] [wF] = wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F] [wΠFG] = wk1ᵛ {A = Π F ^ rF ° lF ▹ G ° lG ° lΠ} {F = F'} [Γ] [F'] [ΠFG] [app] = appᵛ {F = wk1 F} {G = wk1d G} {t = t} {u = u} (_∙_ {A = F'} [Γ] [F']) [wF] [wΠFG] [t] [u] in S.irrelevanceTerm′ {A = wk1d G [ u ]} {A′ = G [ u ]↑} {t = t ∘ u ^ lΠ} (PE.sym (wk1d[]-[]↑ G u)) PE.refl (_∙_ {A = F'} [Γ] [F']) (_∙_ {A = F'} [Γ] [F']) (substSΠ {wk1 F} {wk1d G} {u} (_∙_ {A = F'} [Γ] [F']) [wF] [wΠFG] [u]) [G[u]] [app]
54.9375
179
0.414486
418f5c9ed79395ce06d7905369056014fc059717
153
agda
Agda
test/interaction/Issue1339.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1339.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1339.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2014-11-02 {-# OPTIONS --guardedness #-} record U : Set where coinductive constructor inn field out : U f : U → U f u = {!u!}
12.75
29
0.575163
57874f7bc60146dd635b24ba0a4ea8f7d198aaf1
707
agda
Agda
Cubical/Data/NatPlusOne/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Data/NatPlusOne/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Data/NatPlusOne/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --no-exact-split --safe #-} module Cubical.Data.NatPlusOne.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 one = 1+ zero pattern 2+_ n = 1+ (suc n) -1+_ : ℕ₊₁ → ℕ -1+ (1+ n) = n ℕ₊₁→ℕ : ℕ₊₁ → ℕ ℕ₊₁→ℕ (1+ n) = suc n suc₊₁ : ℕ₊₁ → ℕ₊₁ suc₊₁ (1+ n) = 1+ (suc n) _+₁_ : ℕ₊₁ → ℕ₊₁ → ℕ₊₁ (1+ m) +₁ (1+ n) = 1+ (suc (m + n)) -- Natural number literals for ℕ₊₁ open import Cubical.Data.Nat.Literals public instance fromNatℕ₊₁ : HasFromNat ℕ₊₁ fromNatℕ₊₁ = record { Constraint = λ { zero → ⊥ ; _ → Unit } ; fromNat = λ { (suc n) → 1+ n } }
19.638889
62
0.584158
1d9c2a4fe0d8365eb72cd4266c37579f134ac780
243
agda
Agda
test/Fail/InferRecordTypes-3.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/InferRecordTypes-3.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/InferRecordTypes-3.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Sometimes we can't infer a record type module InferRecordTypes-3 where postulate A : Set record R : Set₁ where field x₁ : Set x₂ : Set record R′ : Set₁ where field x₁ : Set x₃ : Set bad = record { x₂ = A; x₃ = A }
13.5
41
0.613169
2fd513ab257d4717418ccd1a42b40c298fdce162
7,222
agda
Agda
lib/Haskell/RangedSetsProp/library.agda
ioanasv/agda2hs
17cdbeb36af3d0b735c5db83bb811034c39a19cd
[ "MIT" ]
1
2021-05-25T09:41:34.000Z
2021-05-25T09:41:34.000Z
lib/Haskell/RangedSetsProp/library.agda
ioanasv/agda2hs
17cdbeb36af3d0b735c5db83bb811034c39a19cd
[ "MIT" ]
null
null
null
lib/Haskell/RangedSetsProp/library.agda
ioanasv/agda2hs
17cdbeb36af3d0b735c5db83bb811034c39a19cd
[ "MIT" ]
null
null
null
module Haskell.RangedSetsProp.library where open import Agda.Builtin.Equality open import Agda.Builtin.Bool open import Haskell.Prim open import Haskell.Prim.Ord open import Haskell.Prim.Bool open import Haskell.Prim.Eq open import Haskell.Prim.Int open import Haskell.Prim.List open import Haskell.RangedSets.Boundaries open import Haskell.RangedSets.Ranges -- symmetry of equality sym : {A : Set} {x y : A} → x ≡ y → y ≡ x sym refl = refl -- transitivity of equality trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z trans refl refl = refl -- congruence of equality cong : {A B : Set} {x y : A} → (f : A → B) → x ≡ y → f x ≡ f y cong f refl = refl begin_ : {A : Set} → {x y : A} → x ≡ y → x ≡ y begin p = p _end : {A : Set} → (x : A) → x ≡ x x end = refl _=⟨_⟩_ : {A : Set} → (x : A) → {y z : A} → x ≡ y → y ≡ z → x ≡ z x =⟨ p ⟩ q = trans p q _=⟨⟩_ : {A : Set} → (x : A) → {y : A} → x ≡ y → x ≡ y x =⟨⟩ q = x =⟨ refl ⟩ q infix 1 begin_ infix 3 _end infixr 2 _=⟨_⟩_ infixr 2 _=⟨⟩_ subst : {A : Set} {x y : A} → (P : A → Set) → x ≡ y → P x → P y subst P refl p = p isTrue&&₁ : {x y : Bool} → IsTrue (x && y) → IsTrue x isTrue&&₂ : {x y : Bool} → IsTrue (x && y) → IsTrue y isTrue&&₁ {true} _ = IsTrue.itsTrue isTrue&&₁ {false} () isTrue&&₂ {true} p = p isTrue&&₂ {false} () ifThenElseHelper : {a : Set ℓ} → a → a → Bool → a ifThenElseHelper b c d = if_then_else_ d b c propIf : {a b : Set} → {x y : a} (f : a → b) (c : Bool) → f (if c then x else y) ≡ (if c then f x else f y) propIf f false = refl propIf f true = refl propIf2 : ⦃ Ord a ⦄ → {x y : a} (c : Bool) → IsTrue c → (if c then x else y) ≡ x propIf2 true f = refl propIf3 : ⦃ Ord a ⦄ → {x y : a} (c : Bool) → IsFalse c → (if c then x else y) ≡ y propIf3 false f = refl propIf2' : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → {x y : List (Range a)} (c : Bool) → IsTrue c → (if c then x else y) ≡ x propIf2' true f = refl propIf3' : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → {x y : List (Range a)} (c : Bool) → IsFalse c → (if c then x else y) ≡ y propIf3' false f = refl propIsFalse : (x : Bool) → IsFalse x → x ≡ false propIsFalse false f = refl propIsTrue : (x : Bool) → IsTrue x → x ≡ true propIsTrue true f = refl prop_or_and_eqiv_true : (x y : Bool) -> IsTrue x -> IsTrue y -> (x || y) ≡ (x && y) prop_or_and_eqiv_true true true _ _ = refl prop_or_and_eqiv_false : (x y : Bool) -> IsFalse x -> IsFalse y -> (x || y) ≡ (x && y) prop_or_and_eqiv_false false false _ _ = refl postulate isTrueAndIsFalse1 : {b : Bool} -> IsTrue b -> IsFalse (not b) isTrueAndIsFalse2 : {b : Bool} -> IsTrue (not b) -> IsFalse b isTrueAndIsFalse3 : {b : Bool} -> IsFalse (not b) -> IsTrue b isTrueAndIsFalse4 : {b : Bool} -> IsFalse b -> IsTrue (not b) gteq : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → (_>=_ ⦃ o ⦄ x y) ≡ true lt : ⦃ o : Ord a ⦄ → (x y : a) → (x ≡ y) → IsFalse (_>_ ⦃ o ⦄ x y) lteq : ⦃ o : Ord a ⦄ → (x y : a) → (_<_ ⦃ o ⦄ x y) ≡ (_<=_ ⦃ o ⦄ x y) gt : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → not (_>_ ⦃ o ⦄ x y) ≡ true eq0 : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → IsTrue (x == y) eq1 : ⦃ o : Ord a ⦄ → (x y : a) → ((_>=_ ⦃ o ⦄ x y) && (not (_>_ ⦃ o ⦄ x y))) ≡ (y == x) eq2 : ⦃ o : Ord a ⦄ → (x y : a) → not (_<=_ ⦃ o ⦄ x y) ≡ (_<_ ⦃ o ⦄ y x) eq3 : ⦃ o : Ord a ⦄ → (x y i j : a) → ⦃ IsTrue ((_<_ ⦃ o ⦄ i x) && (_<_ ⦃ o ⦄ j y)) ⦄ → ((min ⦃ o ⦄ x y) <= (max ⦃ o ⦄ i j)) ≡ ((_<=_ ⦃ o ⦄ x j) || (_<=_ ⦃ o ⦄ y i)) eq4 : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → ((compare x y) == EQ) ≡ true boundaries0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x : a) → (b c : Boundary a) → ((x />/ b) && (x />/ c)) ≡ (x />/ (max b c)) boundaries1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x : a) → (b c : Boundary a) → ((x />/ b) || (x />/ c)) ≡ (x />/ (min b c)) prop_and_assoc : (a b c : Bool) → ((a && b) && c) ≡ (a && (b && c)) prop_and_assoc true b c = begin ((true && b) && c) =⟨⟩ (b && c) =⟨⟩ (true && (b && c)) end prop_and_assoc false b c = begin ((false && b) && c) =⟨⟩ (false && c) =⟨⟩ false =⟨⟩ (false && (b && c)) end prop_and_cancel : (a : Bool) {b : Bool} → (a && a && b) ≡ (a && b) prop_and_cancel true = refl prop_and_cancel false = refl prop_or_assoc : (a b c : Bool) → ((a || b) || c) ≡ (a || (b || c)) prop_or_assoc true b c = refl prop_or_assoc false b c = refl prop_or_sym : (a b : Bool) → (a || b) ≡ (b || a) prop_or_sym true true = refl prop_or_sym true false = refl prop_or_sym false true = refl prop_or_sym false false = refl prop_or_same_value : (a : Bool) → (a || a) ≡ a prop_or_same_value true = refl prop_or_same_value false = refl prop_and_false : (a : Bool) → (a && false) ≡ false prop_and_false true = refl prop_and_false false = refl prop_and_true : (a : Bool) → (a && true) ≡ a prop_and_true true = refl prop_and_true false = refl prop_or_false : (a : Bool) → (false || a) ≡ a prop_or_false true = refl prop_or_false false = refl prop_or_false2 : (a : Bool) → (a || false) ≡ a prop_or_false2 true = refl prop_or_false2 false = refl prop_or_false3 : (a : Bool) → (a || true) ≡ true prop_or_false3 true = refl prop_or_false3 false = refl prop_or_true : (a : Bool) → (true || a) ≡ true prop_or_true true = refl prop_or_true false = refl prop_and_comm : (a b : Bool) → (a && b) ≡ (b && a) prop_and_comm false b = begin (false && b) =⟨⟩ false =⟨ sym (prop_and_false b) ⟩ (b && false) end prop_and_comm true b = begin (true && b) =⟨⟩ b =⟨ sym (prop_and_true b) ⟩ (b && true) end prop_distr : (a b c : Bool) → ((a || b) && c) ≡ ((a && c) || (b && c)) prop_distr true b true = refl prop_distr true true false = refl prop_distr true false false = refl prop_distr false true true = refl prop_distr false true false = refl prop_distr false false false = refl prop_distr false false true = refl prop_dnf : (a b c d : Bool) → ((a || b) && (c || d)) ≡ ((a && c) || (b && d) || (b && c) || (a && d)) prop_dnf true b true d = refl prop_dnf true true false true = refl prop_dnf true false false true = refl prop_dnf true true false false = refl prop_dnf true false false false = refl prop_dnf false true true true = refl prop_dnf false true false true = refl prop_dnf false false true true = refl prop_dnf false false true false = refl prop_dnf false false false true = refl prop_dnf false false false false = refl prop_dnf false true true false = refl prop_dnf false true false false = refl prop_demorgan2 : (a b : Bool) → ((not a) && (not b)) ≡ (not (a || b)) prop_demorgan2 false b = refl prop_demorgan2 true b = refl prop_demorgan : (a b : Bool) → (not (a && b)) ≡ ((not a) || (not b)) prop_demorgan false b = refl prop_demorgan true b = refl not-not : (b : Bool) → b ≡ not (not b) not-not false = refl not-not true = begin not (not true) =⟨⟩ not false =⟨⟩ true end demorgan3 : (a b c d : Bool) → (not (a || b || c || d)) ≡ ((not a) && (not b) && (not c) && (not d)) demorgan3 true b c d = refl demorgan3 false true c d = refl demorgan3 false false true d = refl demorgan3 false false false true = refl demorgan3 false false false false = refl
30.601695
168
0.558709
5923bb70ee56aeaf446ba484c16f40e3026e35d9
97,327
agda
Agda
src/Lens/Non-dependent/Traditional/Combinators.agda
nad/dependent-lenses
f2da6f7e95b87ca525e8ea43929c6d6163a74811
[ "MIT" ]
3
2020-04-16T12:10:46.000Z
2020-07-03T08:55:52.000Z
src/Lens/Non-dependent/Traditional/Combinators.agda
nad/dependent-lenses
f2da6f7e95b87ca525e8ea43929c6d6163a74811
[ "MIT" ]
null
null
null
src/Lens/Non-dependent/Traditional/Combinators.agda
nad/dependent-lenses
f2da6f7e95b87ca525e8ea43929c6d6163a74811
[ "MIT" ]
1
2020-07-01T14:33:26.000Z
2020-07-01T14:33:26.000Z
------------------------------------------------------------------------ -- Identity and composition for traditional non-dependent lenses ------------------------------------------------------------------------ {-# OPTIONS --cubical #-} import Equality.Path as P module Lens.Non-dependent.Traditional.Combinators {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (module _⇔_) open import Prelude as P hiding (id) renaming (_∘_ to _⊚_) import Bi-invertibility open import Bijection equality-with-J as Bijection using (_↔_) open import Category equality-with-J as C using (Category; Precategory) open import Circle eq as Circle using (𝕊¹) open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Erased.Cubical eq as E using (Erased; [_]) 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 T using (∥_∥) import Integer equality-with-J as Int open import Preimage equality-with-J using (_⁻¹_) open import Surjection equality-with-J as Surjection using (_↠_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent.Traditional eq private variable a b h o : Level A B C D : Type a l₁ l₂ : Lens A B ------------------------------------------------------------------------ -- Lens combinators -- If two types are isomorphic, then there is a lens between them. ↔→lens : {A : Type a} {B : Type b} → A ↔ B → Lens A B ↔→lens A↔B = record { get = to ; set = const from ; get-set = const right-inverse-of ; set-get = left-inverse-of ; set-set = λ _ _ _ → refl _ } where open _↔_ A↔B -- If two types are equivalent, then there is a lens between them. ≃→lens : {A : Type a} {B : Type b} → A ≃ B → Lens A B ≃→lens = ↔→lens ⊚ _≃_.bijection -- Identity lens. id : Lens A A id = ↔→lens F.id -- Composition of lenses. infixr 9 _∘_ _∘_ : Lens B C → Lens A B → Lens A C l₁ ∘ l₂ = record { get = λ a → get l₁ (get l₂ a) ; set = λ a c → set l₂ a (set l₁ (get l₂ a) c) ; get-set = λ a c → get l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c))) ≡⟨ cong (get l₁) $ get-set l₂ _ _ ⟩ get l₁ (set l₁ (get l₂ a) c) ≡⟨ get-set l₁ _ _ ⟩∎ c ∎ ; set-get = λ a → set l₂ a (set l₁ (get l₂ a) (get l₁ (get l₂ a))) ≡⟨ cong (set l₂ _) $ set-get l₁ _ ⟩ set l₂ a (get l₂ a) ≡⟨ set-get l₂ _ ⟩∎ a ∎ ; set-set = λ a c₁ c₂ → set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ set-set l₂ _ _ _ ⟩ set l₂ a (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ cong (λ b → set l₂ _ (set l₁ b _)) $ get-set l₂ _ _ ⟩ set l₂ a (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ cong (set l₂ _) $ set-set l₁ _ _ _ ⟩∎ set l₂ a (set l₁ (get l₂ a) c₂) ∎ } where open Lens -- Note that composition can be defined in several different ways. -- Here are two alternative implementations. infixr 9 _∘′_ _∘″_ _∘′_ : Lens B C → Lens A B → Lens A C l₁ ∘′ l₂ = record (l₁ ∘ l₂) { set-set = λ a c₁ c₂ → set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ cong (λ b → set l₂ (set l₂ _ (set l₁ _ _)) (set l₁ b _)) $ get-set l₂ _ _ ⟩ set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ set-set l₂ _ _ _ ⟩ set l₂ a (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ cong (set l₂ _) $ set-set l₁ _ _ _ ⟩∎ set l₂ a (set l₁ (get l₂ a) c₂) ∎ } where open Lens _∘″_ : Lens B C → Lens A B → Lens A C l₁ ∘″ l₂ = record (l₁ ∘ l₂) { set-set = λ a c₁ c₂ → set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ (set l₂ a (set l₁ (get l₂ a) c₁))) c₂) ≡⟨ cong (λ b → set l₂ (set l₂ _ (set l₁ _ _)) (set l₁ b _)) $ get-set l₂ _ _ ⟩ set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (set l₁ (get l₂ a) c₁) c₂) ≡⟨ cong (set l₂ _) $ set-set l₁ _ _ _ ⟩ set l₂ (set l₂ a (set l₁ (get l₂ a) c₁)) (set l₁ (get l₂ a) c₂) ≡⟨ set-set l₂ _ _ _ ⟩∎ set l₂ a (set l₁ (get l₂ a) c₂) ∎ } where open Lens -- These two implementations are pointwise equal to the other one. -- However, I don't know if there is some other definition that is -- distinct from these two (if we require that the definitions are -- polymorphic, that get and set are implemented in the same way as -- for _∘_, and that the three composition laws below hold). ∘≡∘′ : l₁ ∘ l₂ ≡ l₁ ∘′ l₂ ∘≡∘′ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡ (λ _ _ → refl _) (λ _ → refl _) (λ a c₁ c₂ → let b₁ = set l₁ (get l₂ a) c₁ b₂ = set l₁ b₁ c₂ a′ = set l₂ a b₁ b′ = set l₁ (get l₂ a′) c₂ in set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩ trans (set-set l₂ a b₁ b′) (trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans (set-set l₂ a b₁ b′) (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁))) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ cong (flip trans _) $ elim₁ (λ eq → trans (set-set l₂ _ b₁ _) (cong (λ b → set l₂ _ (set l₁ b _)) eq) ≡ trans (cong (λ b → set l₂ _ (set l₁ b _)) eq) (set-set l₂ _ _ _)) ( trans (set-set l₂ a b₁ b₂) (cong (λ b → set l₂ a (set l₁ b c₂)) (refl _)) ≡⟨ trans (cong (trans _) $ cong-refl _) $ trans-reflʳ _ ⟩ set-set l₂ a b₁ b₂ ≡⟨ sym $ trans (cong (flip trans _) $ cong-refl _) $ trans-reflˡ _ ⟩∎ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (refl _)) (set-set l₂ a b₁ b₂) ∎) (get-set l₂ a b₁) ⟩ trans (trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (set-set l₂ a b₁ b₂)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ trans-assoc _ _ _ ⟩ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (trans (set-set l₂ a b₁ b₂) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨⟩ set-set (l₁ ∘′ l₂) a c₁ c₂ ∎) where open Lens ∘≡∘″ : l₁ ∘ l₂ ≡ l₁ ∘″ l₂ ∘≡∘″ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡ (λ _ _ → refl _) (λ _ → refl _) (λ a c₁ c₂ → let b₁ = set l₁ (get l₂ a) c₁ b₂ = set l₁ (get l₂ a) c₂ a′ = set l₂ a b₁ b′ = set l₁ (get l₂ a′) c₂ eq : b′ ≡ b₂ eq = trans (cong (λ b → set l₁ b c₂) (get-set l₂ a b₁)) (set-set l₁ (get l₂ a) c₁ c₂) in set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩ trans (set-set l₂ a b₁ b′) (trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ cong (trans (set-set l₂ a b₁ b′)) $ trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _ ⟩ trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡⟨ elim¹ (λ {b₂} eq → trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡ trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂)) ( trans (set-set l₂ a b₁ b′) (cong (set l₂ a) (refl _)) ≡⟨ cong (trans _) $ cong-refl _ ⟩ trans (set-set l₂ a b₁ b′) (refl _) ≡⟨ trans-reflʳ _ ⟩ set-set l₂ a b₁ b′ ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl _) (set-set l₂ a b₁ b′) ≡⟨ cong (flip trans _) $ sym $ cong-refl _ ⟩∎ trans (cong (set l₂ a′) (refl _)) (set-set l₂ a b₁ b′) ∎) eq ⟩ trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂) ≡⟨ trans (cong (flip trans _) $ trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _) $ trans-assoc _ _ _ ⟩ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (trans (cong (set l₂ a′) (set-set l₁ (get l₂ a) c₁ c₂)) (set-set l₂ a b₁ b₂)) ≡⟨⟩ set-set (l₁ ∘″ l₂) a c₁ c₂ ∎) where open Lens -- id is a left identity of _∘_. left-identity : (l : Lens A B) → id ∘ l ≡ l left-identity l = equal-laws→≡ (λ a b → trans (cong P.id (get-set a b)) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong P.id (get-set a b) ≡⟨ sym $ cong-id _ ⟩∎ get-set a b ∎) (λ a → trans (cong (set a) (refl _)) (set-get a) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (set-get a) ≡⟨ trans-reflˡ _ ⟩∎ set-get a ∎) (λ a b₁ b₂ → trans (set-set a b₁ b₂) (trans (cong (λ _ → set a b₂) (get-set a b₁)) (cong (set a) (refl _))) ≡⟨ cong₂ (λ p q → trans _ (trans p q)) (cong-const _) (cong-refl _) ⟩ trans (set-set a b₁ b₂) (trans (refl _) (refl _)) ≡⟨ trans (cong (trans _) trans-refl-refl) $ trans-reflʳ _ ⟩∎ set-set a b₁ b₂ ∎) where open Lens l -- id is a right identity of _∘_. right-identity : (l : Lens A B) → l ∘ id ≡ l right-identity l = equal-laws→≡ (λ a b → trans (cong get (refl _)) (get-set a b) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (get-set a b) ≡⟨ trans-reflˡ _ ⟩∎ get-set a b ∎) (λ a → trans (cong P.id (set-get a)) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong P.id (set-get a) ≡⟨ sym $ cong-id _ ⟩∎ set-get a ∎) (λ a b₁ b₂ → trans (refl _) (trans (cong (λ b → set b b₂) (refl _)) (cong P.id (set-set a b₁ b₂))) ≡⟨ trans-reflˡ _ ⟩ trans (cong (λ b → set b b₂) (refl _)) (cong P.id (set-set a b₁ b₂)) ≡⟨ cong₂ trans (cong-refl _) (sym $ cong-id _) ⟩ trans (refl _) (set-set a b₁ b₂) ≡⟨ trans-reflˡ _ ⟩∎ set-set a b₁ b₂ ∎) where open Lens l -- _∘_ is associative. associativity : (l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) → l₁ ∘ (l₂ ∘ l₃) ≡ (l₁ ∘ l₂) ∘ l₃ associativity l₁ l₂ l₃ = equal-laws→≡ lemma₁ lemma₂ lemma₃ where open Lens lemma₁ = λ a d → let f = get l₁ g = get l₂ b = get l₃ a c = g b c′ = set l₁ c d x = get-set l₃ a (set l₂ b c′) y = get-set l₂ b c′ z = get-set l₁ c d in trans (cong f $ trans (cong g x) y) z ≡⟨ cong (λ x → trans x z) (cong-trans f _ y) ⟩ trans (trans (cong f $ cong g x) (cong f y)) z ≡⟨ trans-assoc _ _ z ⟩ trans (cong f $ cong g x) (trans (cong f y) z) ≡⟨ cong (λ x → trans x (trans (cong f y) z)) (cong-∘ f g x) ⟩∎ trans (cong (f ⊚ g) x) (trans (cong f y) z) ∎ lemma₂ = λ a → let b = get l₃ a f = set l₃ a g = set l₂ b x = set-get l₁ (get l₂ b) y = set-get l₂ b z = set-get l₃ a in trans (cong (f ⊚ g) x) (trans (cong f y) z) ≡⟨ sym $ trans-assoc _ _ z ⟩ trans (trans (cong (f ⊚ g) x) (cong f y)) z ≡⟨ cong (λ x → trans (trans x (cong f y)) z) (sym $ cong-∘ f g x) ⟩ trans (trans (cong f (cong g x)) (cong f y)) z ≡⟨ cong (λ x → trans x z) (sym $ cong-trans f _ y) ⟩∎ trans (cong f $ trans (cong g x) y) z ∎ lemma₃ = λ a d₁ d₂ → let f = set l₃ a g = set l₂ (get l₃ a) h = λ x → set l₁ x d₂ i = get l₂ c₁ = set l₁ (get (l₂ ∘ l₃) a) d₁ c₂ = h (i (get l₃ a)) c₂′ = h (i (get l₃ (set (l₂ ∘ l₃) a c₁))) c₂″ = h (i (set l₂ (get l₃ a) c₁)) b₁ = g c₁ b₁′ = get l₃ (f b₁) x = set-set l₃ a b₁ (set l₂ b₁′ c₂′) y = get-set l₃ a b₁ z = set-set l₂ (get l₃ a) c₁ u = get-set l₂ (get l₃ a) c₁ v = set-set l₁ (get (l₂ ∘ l₃) a) d₁ d₂ c₂′≡c₂″ = c₂′ ≡⟨ cong (h ⊚ i) y ⟩∎ c₂″ ∎ lemma₁₀ = trans (sym (cong (h ⊚ i) y)) (cong h (cong i y)) ≡⟨ cong (trans _) (cong-∘ h i y) ⟩ trans (sym (cong (h ⊚ i) y)) (cong (h ⊚ i) y) ≡⟨ trans-symˡ (cong (h ⊚ i) y) ⟩∎ refl _ ∎ lemma₉ = trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″) ≡⟨ cong (trans (cong (λ x → set l₂ x c₂′) y)) (cong-∘ (set l₂ b₁) (h ⊚ i) y) ⟩ trans (cong (λ x → set l₂ x (h (i b₁′))) y) (cong (λ x → set l₂ b₁ (h (i x ))) y) ≡⟨ trans-cong-cong (λ x y → set l₂ x (h (i y))) y ⟩∎ cong (λ x → set l₂ x (h (i x))) y ∎ lemma₈ = sym (cong (set l₂ b₁) (sym c₂′≡c₂″)) ≡⟨ sym $ cong-sym (set l₂ b₁) (sym c₂′≡c₂″) ⟩ cong (set l₂ b₁) (sym (sym c₂′≡c₂″)) ≡⟨ cong (cong (set l₂ b₁)) (sym-sym c₂′≡c₂″) ⟩∎ cong (set l₂ b₁) c₂′≡c₂″ ∎ lemma₇ = trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y))) ≡⟨ sym $ cong-trans g _ (cong h (cong i y)) ⟩ cong g (trans (sym c₂′≡c₂″) (cong h (cong i y))) ≡⟨ cong (cong g) lemma₁₀ ⟩ cong g (refl _) ≡⟨ cong-refl _ ⟩∎ refl _ ∎ lemma₆ = trans (cong (λ x → set l₂ x c₂′) y) (trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) ≡⟨ sym $ trans-assoc _ _ (trans _ (cong g (sym c₂′≡c₂″))) ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″)) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₉ ⟩ trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ sym $ trans-assoc _ _ (cong g (sym c₂′≡c₂″)) ⟩∎ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (sym c₂′≡c₂″)) ∎ lemma₅ = z c₂′ ≡⟨ sym $ dcong z (sym c₂′≡c₂″) ⟩ subst (λ x → set l₂ b₁ x ≡ g x) (sym c₂′≡c₂″) (z c₂″) ≡⟨ subst-in-terms-of-trans-and-cong {f = set l₂ b₁} {g = g} {x≡y = sym c₂′≡c₂″} ⟩ trans (sym (cong (set l₂ b₁) (sym c₂′≡c₂″))) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₈ ⟩∎ trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ∎ lemma₄ = trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans (trans (cong (λ x → set l₂ x c₂′) y) e) (cong g (cong h (cong i y)))) lemma₅ ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″))))) (cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans e (cong g (cong h (cong i y)))) lemma₆ ⟩ trans (trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (sym c₂′≡c₂″))) (cong g (cong h (cong i y))) ≡⟨ trans-assoc _ _ (cong g (cong h (cong i y))) ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y)))) ≡⟨ cong (trans (trans _ (z c₂″))) lemma₇ ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (refl _) ≡⟨ trans-reflʳ _ ⟩∎ trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″) ∎ lemma₃ = cong g (trans (cong h (trans (cong i y) u)) v) ≡⟨ cong (λ e → cong g (trans e v)) (cong-trans h _ u) ⟩ cong g (trans (trans (cong h (cong i y)) (cong h u)) v) ≡⟨ cong (cong g) (trans-assoc _ _ v) ⟩ cong g (trans (cong h (cong i y)) (trans (cong h u) v)) ≡⟨ cong-trans g _ (trans _ v) ⟩∎ trans (cong g (cong h (cong i y))) (cong g (trans (cong h u) v)) ∎ lemma₂ = trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (trans (trans _ (z c₂′))) lemma₃ ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (trans (cong g (cong h (cong i y))) (cong g (trans (cong h u) v))) ≡⟨ sym $ trans-assoc _ _ (cong g (trans _ v)) ⟩ trans (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (cong h (cong i y)))) (cong g (trans (cong h u) v)) ≡⟨ cong (λ e → trans e (cong g (trans (cong h u) v))) lemma₄ ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (trans (cong h u) v)) ≡⟨ trans-assoc _ _ (cong g (trans _ v)) ⟩∎ trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (trans (cong h u) v))) ∎ lemma₁ = trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (λ e → trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) e) (sym $ cong-∘ f g (trans _ v)) ⟩ trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong f (cong g (trans (cong h (trans (cong i y) u)) v))) ≡⟨ sym $ cong-trans f (trans _ (z c₂′)) (cong g (trans _ v)) ⟩ cong f (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (cong f) lemma₂ ⟩ cong f (trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong-trans _ _ _ ⟩ trans (cong f (cong (λ x → set l₂ x (h (i x))) y)) (cong f (trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong₂ (λ p q → trans p (cong f (trans (z c₂″) q))) (cong-∘ _ _ _) (trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _) ⟩∎ trans (cong (λ x → f (set l₂ x (h (i x)))) y) (cong f (trans (z c₂″) (trans (cong (g ⊚ h) u) (cong g v)))) ∎ in trans (trans x (trans (cong (λ x → f (set l₂ x c₂′)) y) (cong f (z c₂′)))) (trans (cong (f ⊚ g ⊚ h) (trans (cong i y) u)) (cong (f ⊚ g) v)) ≡⟨ cong₂ (λ p q → trans (trans x p) q) (trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _) (trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _) ⟩ trans (trans x (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ trans-assoc _ _ _ ⟩ trans x (trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (trans x) lemma₁ ⟩∎ trans x (trans (cong (λ x → f (set l₂ x (h (i x)))) y) (cong f (trans (z c₂″) (trans (cong (g ⊚ h) u) (cong g v))))) ∎ -- Every lens of type Lens A A that satisfies a certain right -- identity law is equal to the identity lens. id-unique : (id′ : Lens A A) → ((l : Lens A A) → l ∘ id′ ≡ l) → id′ ≡ id id-unique id′ right-identity = id′ ≡⟨ sym $ left-identity _ ⟩ id ∘ id′ ≡⟨ right-identity _ ⟩∎ id ∎ -- An equality characterisation lemma that can be used when one of -- the lenses is the identity. equality-characterisation-id : {l : Lens A A} → let open Lens l in l ≡ id ↔ ∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) equality-characterisation-id {l = l} = l ≡ id ↝⟨ equality-characterisation₄ ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡ refl _) × (∀ a → trans (sym (trans (s a (get a)) (cong P.id (g a)))) (set-get a) ≡ refl _) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (refl _))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → ∃-cong λ _ → (∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ eq → trans (sym (trans _ eq)) (set-get _) ≡ _) $ sym $ cong-id (g _)) ×-cong ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_ ≡_) $ trans-reflʳ _) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡ refl _) × (∀ a → trans (sym (trans (s a (get a)) (g a))) (set-get a) ≡ refl _) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))) ↝⟨ (∃-cong λ g → ∃-cong λ s → (∀-cong ext λ _ → ∀-cong ext λ _ → ≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘ ≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm) ×-cong (∀-cong ext λ _ → ≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘ ≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm) ×-cong F.id) ⟩□ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → (∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))) □ where open Lens l -- A lemma that can be used to show that a lens with a constant -- setter (such as the ones produced by getter-equivalence→lens -- below) is equal to the identity lens. constant-setter→≡id : {l′ : ∃ λ (get : A → A) → ∃ λ (set : A → A) → (A → ∀ a → get (set a) ≡ a) × (∀ a → set (get a) ≡ a) × (A → A → ∀ a → set a ≡ set a)} → let l = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′) set = proj₁ (proj₂ l′) open Lens l hiding (set) in (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _)) → l ≡ id constant-setter→≡id {A = A} {l′ = l′} = (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _)) ↝⟨ (Σ-map P.id $ Σ-map P.id λ {s} → Σ-map P.id $ Σ-map P.id λ hyp a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡⟨ cong (λ eq → trans eq (s a₂)) $ hyp _ _ _ ⟩ trans (refl _) (s a₂) ≡⟨ trans-reflˡ (s _) ⟩∎ s a₂ ∎) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ s a₂)) ↔⟨ (∃-cong λ _ → ∃-cong λ s → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ a₁ → ∀-cong ext λ a₂ → ≡⇒↝ equivalence $ cong (trans _ (s _) ≡_) ( s a₂ ≡⟨ sym $ cong-ext s ⟩ cong (λ set → set a₂) (⟨ext⟩ s) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ s) ⟩ cong (λ set → set (set a a₁) a₂) (cong const (⟨ext⟩ s)) ≡⟨ cong (cong (λ set → set (set a a₁) a₂)) $ sym $ ext-const (⟨ext⟩ s) ⟩∎ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s) ∎)) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s))) ↝⟨ Σ-map P.id (Σ-map const P.id) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : A → ∀ a → set a ≡ a) → (∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₁ a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a a₂) ≡ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))) ↔⟨ inverse equality-characterisation-id ⟩□ l″ ≡ id □ where l″ = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′) set = proj₁ (proj₂ l′) open Lens l″ hiding (set) -- An identity function for lenses for which the forward direction -- is an equivalence. -- -- Note that the setter of the resulting lens is definitionally -- equal to a constant function returning the right-to-left -- direction of the equivalence. -- -- Note also that two proofs, set-get and set-set, have been -- "obfuscated". They could have been shorter, but then it might not -- have been possible to prove getter-equivalence→lens≡. getter-equivalence→lens : (l : Lens A B) → Is-equivalence (Lens.get l) → Lens A B getter-equivalence→lens l is-equiv = record { get = to ; set = const from ; get-set = const right-inverse-of ; set-get = λ a → from (to a) ≡⟨ cong from (sym (get-set a (to a))) ⟩ from (get (set a (to a))) ≡⟨⟩ from (to (set a (get a))) ≡⟨ cong (from ⊚ to) (set-get a) ⟩ from (to a) ≡⟨ left-inverse-of _ ⟩∎ a ∎ ; set-set = λ a b₁ b₂ → let s = from≡set l is-equiv in from b₂ ≡⟨ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)) ⟩ set (set a b₁) b₂ ≡⟨ set-set a b₁ b₂ ⟩ set a b₂ ≡⟨ sym (s a b₂) ⟩∎ from b₂ ∎ } where A≃B = Eq.⟨ _ , is-equiv ⟩ open _≃_ A≃B open Lens l -- The function getter-equivalence→lens returns its input. getter-equivalence→lens≡ : ∀ (l : Lens A B) is-equiv → getter-equivalence→lens l is-equiv ≡ l getter-equivalence→lens≡ l is-equiv = _↔_.from equality-characterisation₄ ( g , s , lemma₁ , lemma₂ , lemma₃ ) where open Lens A≃B = Eq.⟨ get l , is-equiv ⟩ open _≃_ A≃B l′ = getter-equivalence→lens l is-equiv g = λ _ → refl _ s = from≡set l is-equiv lemma₁ = λ a b → let lem = cong (get l) (s a b) ≡⟨⟩ cong (get l) (trans (cong from (sym (get-set l a b))) (left-inverse-of _)) ≡⟨ cong-trans _ _ (left-inverse-of _) ⟩ trans (cong (get l) (cong from (sym (get-set l a b)))) (cong (get l) (left-inverse-of _)) ≡⟨ cong₂ trans (cong-∘ _ _ (sym (get-set l a b))) (left-right-lemma _) ⟩∎ trans (cong (get l ⊚ from) (sym (get-set l a b))) (right-inverse-of _) ∎ in trans (sym (trans (cong (get l) (s a b)) (g (set l a b)))) (get-set l′ a b) ≡⟨⟩ trans (sym (trans (cong (get l) (s a b)) (refl _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym eq) (right-inverse-of _)) $ trans-reflʳ _ ⟩ trans (sym (cong (get l) (s a b))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym eq) (right-inverse-of _)) lem ⟩ trans (sym (trans (cong (get l ⊚ from) (sym (get-set l a b))) (right-inverse-of _))) (right-inverse-of _) ≡⟨ elim¹ (λ eq → trans (sym (trans (cong (get l ⊚ from) (sym eq)) (right-inverse-of _))) (right-inverse-of _) ≡ eq) ( trans (sym (trans (cong (get l ⊚ from) (sym (refl _))) (right-inverse-of _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym (trans (cong (get l ⊚ from) eq) _)) _) sym-refl ⟩ trans (sym (trans (cong (get l ⊚ from) (refl _)) (right-inverse-of _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym (trans eq _)) _) $ cong-refl _ ⟩ trans (sym (trans (refl _) (right-inverse-of _))) (right-inverse-of _) ≡⟨ cong (λ eq → trans (sym eq) (right-inverse-of _)) $ trans-reflˡ (right-inverse-of _) ⟩ trans (sym (right-inverse-of _)) (right-inverse-of _) ≡⟨ trans-symˡ (right-inverse-of _) ⟩∎ refl _ ∎) _ ⟩∎ get-set l a b ∎ lemma₂ = λ a → trans (sym (trans (s a (get l a)) (cong (set l a) (g a)))) (set-get l′ a) ≡⟨⟩ trans (sym (trans (s a (get l a)) (cong (set l a) (refl _)))) (set-get l′ a) ≡⟨ cong (λ eq → trans (sym (trans (s a (get l a)) eq)) (set-get l′ a)) $ cong-refl _ ⟩ trans (sym (trans (s a (get l a)) (refl _))) (set-get l′ a) ≡⟨ cong (λ eq → trans (sym eq) (set-get l′ a)) $ trans-reflʳ _ ⟩ trans (sym (s a (get l a))) (set-get l′ a) ≡⟨⟩ trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (cong from (sym (get-set l a (get l a)))) (trans (cong (from ⊚ get l) (set-get l a)) (left-inverse-of _))) ≡⟨ cong (λ eq → trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (cong from (sym (get-set l a (get l a)))) eq)) $ elim¹ (λ eq → trans (cong (from ⊚ get l) eq) (left-inverse-of _) ≡ trans (left-inverse-of _) eq) ( trans (cong (from ⊚ get l) (refl _)) (left-inverse-of (set l a (get l a))) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (left-inverse-of (set l a (get l a))) ≡⟨ trans-reflˡ _ ⟩ left-inverse-of (set l a (get l a)) ≡⟨ sym $ trans-reflʳ _ ⟩∎ trans (left-inverse-of (set l a (get l a))) (refl _) ∎) (set-get l a) ⟩ trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (cong from (sym (get-set l a (get l a)))) (trans (left-inverse-of _) (set-get l a))) ≡⟨ cong (trans _) $ sym $ trans-assoc _ _ (set-get l a) ⟩ trans (sym (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _))) (trans (trans (cong from (sym (get-set l a (get l a)))) (left-inverse-of _)) (set-get l a)) ≡⟨ trans-sym-[trans] _ _ ⟩∎ set-get l a ∎ lemma₃ = λ a b₁ b₂ → trans (set-set l′ a b₁ b₂) (s a b₂) ≡⟨⟩ trans (trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (trans (set-set l a b₁ b₂) (sym (s a b₂)))) (s a b₂) ≡⟨ cong (λ eq → trans eq (s a b₂)) $ sym $ trans-assoc _ _ (sym (s a b₂)) ⟩ trans (trans (trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (set-set l a b₁ b₂)) (sym (s a b₂))) (s a b₂) ≡⟨ trans-[trans-sym]- _ (s a b₂) ⟩∎ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (set-set l a b₁ b₂) ∎ ------------------------------------------------------------------------ -- Some existence results -- The lenses bad a and id {A = ↑ a 𝕊¹} have equal setters, and their -- getters are equivalences, but they are not equal (assuming -- univalence). equal-setters-and-equivalences-as-getters-but-not-equal : Univalence lzero → let l₁ = bad a l₂ = id {A = ↑ a 𝕊¹} in Is-equivalence (Lens.get l₁) × Is-equivalence (Lens.get l₂) × Lens.set l₁ ≡ Lens.set l₂ × l₁ ≢ l₂ equal-setters-and-equivalences-as-getters-but-not-equal {a = ℓa} univ = let is-equiv , not-coherent , _ = getter-equivalence-but-not-coherent univ in is-equiv , _≃_.is-equivalence F.id , refl _ , (bad ℓa ≡ id ↝⟨ (λ eq → subst (λ l → ∀ a → cong (get l) (set-get l a) ≡ get-set l a (get l a)) (sym eq) (λ _ → cong-refl _)) ⟩ (∀ a → cong (get (bad ℓa)) (set-get (bad ℓa) a) ≡ get-set (bad ℓa) a (get (bad ℓa) a)) ↝⟨ not-coherent ⟩□ ⊥ □) where open Lens -- There is in general no split surjection from equivalences to lenses -- with getters that are equivalences, if the right-to-left direction -- of the split surjection is required to return the lens's getter -- plus some proof (assuming univalence). ¬-≃-↠-Σ-Lens-Is-equivalence-get : Univalence lzero → ¬ ∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p) ¬-≃-↠-Σ-Lens-Is-equivalence-get {a = a} univ = let is-equiv₁ , is-equiv₂ , _ , bad≢id = equal-setters-and-equivalences-as-getters-but-not-equal univ in λ (f , hyp) → $⟨ refl _ ⟩ Lens.get (bad a) ≡ Lens.get id ↝⟨ (λ eq → trans (hyp _) (trans eq (sym (hyp _)))) ⟩ _≃_.to (_↠_.from f (bad a , is-equiv₁)) ≡ _≃_.to (_↠_.from f (id , is-equiv₂)) ↝⟨ Eq.lift-equality ext ⟩ _↠_.from f (bad a , is-equiv₁) ≡ _↠_.from f (id , is-equiv₂) ↝⟨ _↠_.to (Surjection.↠-≡ f) ⟩ (bad a , is-equiv₁) ≡ (id , is-equiv₂) ↝⟨ cong proj₁ ⟩ bad a ≡ id ↝⟨ bad≢id ⟩□ ⊥ □ -- There is in general no equivalence from equivalences to lenses with -- getters that are equivalences, if the right-to-left direction of -- the equivalence is required to return the lens's getter plus some -- proof (assuming univalence). ¬-≃-≃-Σ-Lens-Is-equivalence-get : Univalence lzero → ¬ ∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_≃_.from f p) ≡ Lens.get (proj₁ p) ¬-≃-≃-Σ-Lens-Is-equivalence-get {a = a} univ = (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_≃_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ Σ-map _≃_.surjection P.id ⟩ (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃-↠-Σ-Lens-Is-equivalence-get univ ⟩□ ⊥ □ -- The lemma ≃Σ∥set⁻¹∥× does not hold in general if the requirement -- that A is a set is dropped (assuming univalence). -- -- I proved this together with Paolo Capriotti. -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.𝕊¹≄𝕊¹×𝕊¹.) ≄Σ∥set⁻¹∥× : Univalence lzero → ¬ ({A B : Type a} (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B)) ≄Σ∥set⁻¹∥× {a = a} _ = ({A B : Type a} (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B)) ↝⟨ (λ hyp → hyp) ⟩ ((l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → ↑ a 𝕊¹ ≃ ((∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ Lens.set l ⁻¹ f ∥) × ↑ a 𝕊¹)) ↝⟨ _$ id ⟩ ↑ a 𝕊¹ ≃ ((∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ const P.id ⁻¹ f ∥) × ↑ a 𝕊¹) ↝⟨ lemma ⟩ 𝕊¹ ≃ (𝕊¹ × 𝕊¹) ↝⟨ 𝕊¹≄𝕊¹×𝕊¹ ⟩□ ⊥ □ where open Circle open Int lemma = λ hyp → 𝕊¹ ↔⟨ inverse Bijection.↑↔ ⟩ ↑ a 𝕊¹ ↝⟨ hyp ⟩ (∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ const P.id ⁻¹ f ∥) × ↑ a 𝕊¹ ↔⟨⟩ (∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ ↑ a 𝕊¹ × P.id ≡ f ∥) × ↑ a 𝕊¹ ↝⟨ (×-cong₁ λ _ → ∃-cong λ _ → T.∥∥-cong-⇔ $ record { to = proj₂; from = λ eq → lift base , eq }) ⟩ (∃ λ (f : ↑ a 𝕊¹ → ↑ a 𝕊¹) → ∥ P.id ≡ f ∥) × ↑ a 𝕊¹ ↝⟨ (Σ-cong (→-cong ext Bijection.↑↔ Bijection.↑↔) λ _ → T.∥∥-cong $ inverse $ Eq.≃-≡ (Eq.↔⇒≃ $ →-cong ext Bijection.↑↔ Bijection.↑↔)) ×-cong Eq.↔⇒≃ Bijection.↑↔ ⟩ (∃ λ (f : 𝕊¹ → 𝕊¹) → ∥ P.id ≡ f ∥) × 𝕊¹ ↝⟨ (×-cong₁ λ _ → Σ-cong 𝕊¹→𝕊¹≃𝕊¹×ℤ λ f → T.∥∥-cong ( P.id ≡ f ↝⟨ inverse $ Eq.≃-≡ 𝕊¹→𝕊¹≃𝕊¹×ℤ ⟩ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ P.id ≡ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f ↝⟨ ≡⇒≃ $ cong (_≡ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f) 𝕊¹→𝕊¹≃𝕊¹×ℤ-id ⟩ (base , + 1) ≡ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f ↔⟨ ≡-comm ⟩□ _≃_.to 𝕊¹→𝕊¹≃𝕊¹×ℤ f ≡ (base , + 1) □)) ⟩ (∃ λ (p : 𝕊¹ × ℤ) → ∥ p ≡ (base , + 1) ∥) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → ∃-cong λ _ → inverse $ T.∥∥-cong ≡×≡↔≡ F.∘ T.∥∥×∥∥↔∥×∥) ⟩ (∃ λ ((x , i) : 𝕊¹ × ℤ) → ∥ x ≡ base ∥ × ∥ i ≡ + 1 ∥) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → Σ-assoc F.∘ (∃-cong λ _ → ∃-comm) F.∘ inverse Σ-assoc) ⟩ ((∃ λ x → ∥ x ≡ base ∥) × (∃ λ i → ∥ i ≡ + 1 ∥)) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → (drop-⊤-right λ _ → T.inhabited⇒∥∥↔⊤ $ all-points-on-the-circle-are-merely-equal _) ×-cong ∃-cong λ _ → T.∥∥↔ ℤ-set) ⟩ (𝕊¹ × (∃ λ i → i ≡ + 1)) × 𝕊¹ ↔⟨ (×-cong₁ λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ⟩□ 𝕊¹ × 𝕊¹ □ ------------------------------------------------------------------------ -- Isomorphisms expressed using lens quasi-inverses private module B {a} = Bi-invertibility equality-with-J (Type a) Lens id _∘_ module BM {a} = B.More {a = a} left-identity right-identity associativity -- A form of isomorphism between types, expressed using lenses. open B public using () renaming (_≅_ to _≅_; Has-quasi-inverse to Has-quasi-inverse) -- An equality characterisation lemma for A ≅ B that applies when A is -- a set. equality-characterisation-for-sets-≅ : let open Lens in {f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≅ B} → Is-set A → f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂ equality-characterisation-for-sets-≅ {f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set = f₁ ≡ f₂ ↔⟨ BM.equality-characterisation-≅-domain (lens-preserves-h-level-of-domain 1 A-set) _ _ ⟩ l₁₁ ≡ l₁₂ ↝⟨ equality-characterisation-for-sets A-set ⟩□ set l₁₁ ≡ set l₁₂ □ where open Lens -- There is a split surjection from A ≅ B to A ≃ B. ≅↠≃ : (A ≅ B) ↠ (A ≃ B) ≅↠≃ {A = A} {B = B} = record { logical-equivalence = record { to = λ (l₁ , l₂ , eq₁ , eq₂) → Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { to = get l₁ ; from = get l₂ } ; right-inverse-of = ext⁻¹ $ getters-equal-if-setters-equal (l₁ ∘ l₂) id (cong set eq₁) } ; left-inverse-of = ext⁻¹ $ getters-equal-if-setters-equal (l₂ ∘ l₁) id (cong set eq₂) }) ; from = λ A≃B → ≃→lens A≃B , ≃→lens (inverse A≃B) , lemma A≃B , (≃→lens (inverse A≃B) ∘ ≃→lens A≃B ≡⟨ cong (λ A≃B′ → ≃→lens (inverse A≃B) ∘ ≃→lens A≃B′) $ sym $ Eq.inverse-involutive ext A≃B ⟩ ≃→lens (inverse A≃B) ∘ ≃→lens (inverse $ inverse A≃B) ≡⟨ lemma (inverse A≃B) ⟩∎ id ∎) } ; right-inverse-of = λ _ → Eq.lift-equality ext (refl _) } where open Lens lemma : (C≃D : C ≃ D) → ≃→lens C≃D ∘ ≃→lens (inverse C≃D) ≡ id lemma C≃D = _↔_.from equality-characterisation₂ ( ⟨ext⟩ (_≃_.right-inverse-of C≃D) , (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) , lemma₁ , lemma₂ , lemma₃ ) where lemma₁ = λ d₁ d₂ → let lemma = cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂)))) $ ext-const (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂))) (cong const $ ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₂))) (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (_≃_.to C≃D ⊚ _≃_.from C≃D) (cong (λ set → set d₂) (⟨ext⟩ $ _≃_.right-inverse-of C≃D)) ≡⟨ cong (cong (_≃_.to C≃D ⊚ _≃_.from C≃D)) $ cong-ext _ ⟩ cong (_≃_.to C≃D ⊚ _≃_.from C≃D) (_≃_.right-inverse-of C≃D _) ≡⟨ sym $ cong-∘ _ _ (_≃_.right-inverse-of C≃D _) ⟩ cong (_≃_.to C≃D) (cong (_≃_.from C≃D) (_≃_.right-inverse-of C≃D _)) ≡⟨ cong (cong (_≃_.to C≃D)) $ _≃_.right-left-lemma C≃D _ ⟩∎ cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _) ∎ in trans (sym (trans (cong (λ set → _≃_.to C≃D (_≃_.from C≃D (set d₁ d₂))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D)) (cong (λ get → get d₂) (⟨ext⟩ $ _≃_.right-inverse-of C≃D)))) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _)) ≡⟨ cong₂ (λ p q → trans (sym (trans p q)) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _))) lemma (cong-ext _) ⟩ trans (sym (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _))) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃_.right-inverse-of C≃D _)) ⟩∎ refl _ ∎ lemma₂ = λ d → let lemma = cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d)))) $ ext-const (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d))) (cong const $ ⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ cong (λ set → set (_≃_.to C≃D (_≃_.from C≃D d))) (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ≡⟨ cong-ext _ ⟩∎ _≃_.right-inverse-of C≃D _ ∎ in trans (sym (trans (cong (λ set → set d (_≃_.to C≃D (_≃_.from C≃D d))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D)) (cong (λ get → get d) (⟨ext⟩ $ _≃_.right-inverse-of C≃D)))) (trans (cong (_≃_.to C≃D) (_≃_.left-inverse-of C≃D _)) (_≃_.left-inverse-of (inverse C≃D) _)) ≡⟨ cong₂ (λ p q → trans (sym p) q) (cong₂ trans lemma (cong-ext _)) (cong₂ trans (_≃_.left-right-lemma C≃D _) (Eq.left-inverse-of∘inverse C≃D)) ⟩ trans (sym (trans (_≃_.right-inverse-of C≃D _) (_≃_.right-inverse-of C≃D _))) (trans (_≃_.right-inverse-of C≃D _) (_≃_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃_.right-inverse-of C≃D _)) ⟩∎ refl _ ∎ lemma₃ = λ d d₁ d₂ → subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) (trans (refl _) (trans (cong (λ _ → _≃_.to C≃D (_≃_.from C≃D d₂)) (_≃_.right-inverse-of (inverse C≃D) (_≃_.from C≃D d₁))) (cong (_≃_.to C≃D) (refl _)))) ≡⟨ cong (subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D)) $ trans (trans-reflˡ _) $ trans (cong (flip trans _) $ cong-const _) $ trans (trans-reflˡ _) $ cong-refl _ ⟩ subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃_.right-inverse-of C≃D) (refl _) ≡⟨ cong (flip (subst (λ set → set (set d d₁) d₂ ≡ set d d₂)) _) $ ext-const (⟨ext⟩ $ _≃_.right-inverse-of C≃D) ⟩ subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (cong const $ ⟨ext⟩ $ _≃_.right-inverse-of C≃D) (refl _) ≡⟨ sym $ subst-∘ _ _ _ ⟩ subst (λ set → set d₂ ≡ set d₂) (⟨ext⟩ $ _≃_.right-inverse-of C≃D) (refl _) ≡⟨ subst-ext _ _ ⟩ subst (λ set → set ≡ set) (_≃_.right-inverse-of C≃D d₂) (refl _) ≡⟨ ≡⇒↝ _ (sym [subst≡]≡[trans≡trans]) ( trans (refl _) (_≃_.right-inverse-of C≃D d₂) ≡⟨ trans-reflˡ _ ⟩ _≃_.right-inverse-of C≃D d₂ ≡⟨ sym $ trans-reflʳ _ ⟩ trans (_≃_.right-inverse-of C≃D d₂) (refl _) ∎) ⟩ refl _ ∎ -- The right-to-left direction of ≅↠≃ maps identity to an isomorphism -- for which the first projection is the identity. ≅↠≃-id≡id : proj₁ (_↠_.from ≅↠≃ F.id) ≡ id {A = A} ≅↠≃-id≡id = equal-laws→≡ (λ _ _ → refl _) (λ a → _≃_.left-inverse-of F.id a ≡⟨ sym $ _≃_.right-left-lemma F.id _ ⟩ cong P.id (_≃_.right-inverse-of F.id a) ≡⟨⟩ cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎ refl _ ∎) (λ _ _ _ → refl _) -- If A is a set, then there is an equivalence between A ≃ B and A ≅ B. ≃≃≅ : Is-set A → (A ≃ B) ≃ (A ≅ B) ≃≃≅ {A = A} {B = B} A-set = Eq.↔⇒≃ $ inverse (record { surjection = ≅↠≃ ; left-inverse-of = λ (l₁ , l₂ , eq₁ , eq₂) → _↔_.from (equality-characterisation-for-sets-≅ A-set) $ ⟨ext⟩ λ a → ⟨ext⟩ λ b → get l₂ b ≡⟨ sym $ ext⁻¹ (ext⁻¹ (cong set eq₂) _) _ ⟩ set l₁ (set l₁ a b) (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ set-set l₁ _ _ _ ⟩ set l₁ a (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ cong (λ b′ → set l₁ a (set l₂ b′ (get l₂ b))) $ get-set l₁ _ _ ⟩ set l₁ a (set l₂ b (get l₂ b)) ≡⟨ cong (set l₁ a) $ set-get l₂ _ ⟩∎ set l₁ a b ∎ }) where open Lens -- The equivalence maps identity to an isomorphism for which the first -- projection is the identity. ≃≃≅-id≡id : (A-set : Is-set A) → proj₁ (_≃_.to (≃≃≅ A-set) F.id) ≡ id ≃≃≅-id≡id _ = ≅↠≃-id≡id -- The type Has-quasi-inverse id is not necessarily a proposition -- (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.¬-type-of-refl-propositional.) Has-quasi-inverse-id-not-proposition : Univalence lzero → ∃ λ (A : Type a) → ¬ Is-proposition (Has-quasi-inverse (id {A = A})) Has-quasi-inverse-id-not-proposition _ = X , (Is-proposition (Has-quasi-inverse id) ↝⟨ flip propositional⇒inhabited⇒contractible q ⟩ Contractible (Has-quasi-inverse id) ↝⟨ H-level-cong _ 0 lemma₁ ⟩ Contractible (∃ λ (g : (x : X) → x ≡ x) → _) ↝⟨ flip proj₁-closure 0 (λ g → (λ _ x → sym (g x)) , lemma₂ g , lemma₃ g , lemma₄ g) ⟩ Contractible ((x : X) → x ≡ x) ↝⟨ mono₁ 0 ⟩ Is-proposition ((x : X) → x ≡ x) ↝⟨ ¬-prop ⟩□ ⊥ □) where X = Erased (proj₁ Circle.¬-type-of-refl-propositional) ¬-prop = E.Stable-¬ [ Is-proposition ((x : X) → x ≡ x) ↝⟨ H-level-cong _ 1 (Π-cong ext (E.erased E.Erased↔) λ _ → inverse E.≡≃[]≡[]) ⟩ Is-proposition ((x : ↑ _ 𝕊¹) → x ≡ x) ↝⟨ proj₂ Circle.¬-type-of-refl-propositional ⟩□ ⊥ □ ] q = id , left-identity _ , right-identity _ lemma₁ = Has-quasi-inverse id ↝⟨ BM.Has-quasi-inverse≃id≡id-domain q ⟩ id ≡ id ↔⟨ equality-characterisation₄ ⟩□ (∃ λ (g : ∀ x → x ≡ x) → ∃ λ (s : X → ∀ x → x ≡ x) → (∀ x y → trans (sym (trans (cong P.id (s x y)) (g y))) (refl _) ≡ refl _) × (∀ x → trans (sym (trans (s x x) (cong P.id (g x)))) (refl _) ≡ refl _) × (∀ x y z → trans (refl _) (s x z) ≡ trans (cong (λ set → set (set x y) z) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (refl _))) □ lemma₂ : (g : ∀ x → x ≡ x) (x y : X) → _ lemma₂ g x y = trans (sym (trans (cong P.id (sym (g y))) (g y))) (refl _) ≡⟨ trans-reflʳ _ ⟩ sym (trans (cong P.id (sym (g y))) (g y)) ≡⟨ cong (λ eq → sym (trans eq (g y))) $ sym $ cong-id _ ⟩ sym (trans (sym (g y)) (g y)) ≡⟨ cong sym $ trans-symˡ (g y) ⟩ sym (refl _) ≡⟨ sym-refl ⟩∎ refl _ ∎ lemma₃ : (g : ∀ x → x ≡ x) (x : X) → _ lemma₃ g x = trans (sym (trans (sym (g x)) (cong P.id (g x)))) (refl _) ≡⟨ trans-reflʳ _ ⟩ sym (trans (sym (g x)) (cong P.id (g x))) ≡⟨ cong (λ eq → sym (trans (sym (g x)) eq)) $ sym $ cong-id (g x) ⟩ sym (trans (sym (g x)) (g x)) ≡⟨ cong sym $ trans-symˡ (g x) ⟩ sym (refl _) ≡⟨ sym-refl ⟩∎ refl _ ∎ lemma₄ : (g : ∀ x → x ≡ x) (x y z : X) → _ lemma₄ g x y z = trans (refl _) (sym (g z)) ≡⟨ trans-reflˡ (sym (g z)) ⟩ sym (g z) ≡⟨ sym $ cong-ext (sym ⊚ g) ⟩ cong (_$ z) (⟨ext⟩ (sym ⊚ g)) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ (sym ⊚ g)) ⟩ cong (λ set → set (set x y) z) (cong const (⟨ext⟩ (sym ⊚ g))) ≡⟨ cong (cong (λ set → set (set x y) z)) $ sym $ ext-const (⟨ext⟩ (sym ⊚ g)) ⟩ cong (λ set → set (set x y) z) (⟨ext⟩ λ _ → ⟨ext⟩ (sym ⊚ g)) ≡⟨ sym $ trans-reflʳ _ ⟩∎ trans (cong (λ set → set (set x y) z) (⟨ext⟩ λ _ → ⟨ext⟩ (sym ⊚ g))) (refl _) ∎ -- There is not necessarily a split surjection from -- Is-equivalence (Lens.get l) to Has-quasi-inverse l, if l is a lens -- between types in the same universe (assuming univalence). ¬Is-equivalence↠Has-quasi-inverse : Univalence lzero → ¬ ({A B : Type a} (l : Lens A B) → Is-equivalence (Lens.get l) ↠ Has-quasi-inverse l) ¬Is-equivalence↠Has-quasi-inverse univ surj = $⟨ mono₁ 0 ⊤-contractible ⟩ Is-proposition ⊤ ↝⟨ H-level.respects-surjection lemma 1 ⟩ Is-proposition (Has-quasi-inverse id) ↝⟨ proj₂ $ Has-quasi-inverse-id-not-proposition univ ⟩□ ⊥ □ where lemma = ⊤ ↔⟨ inverse $ _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Eq.propositional ext _) (_≃_.is-equivalence Eq.id) ⟩ Is-equivalence P.id ↝⟨ surj id ⟩□ Has-quasi-inverse id □ ------------------------------------------------------------------------ -- Isomorphisms expressed using bi-invertibility for lenses -- A form of isomorphism between types, expressed using lenses. open B public using () renaming (_≊_ to _≊_; Has-left-inverse to Has-left-inverse; Has-right-inverse to Has-right-inverse; Is-bi-invertible to Is-bi-invertible) open BM public using () renaming (Is-bi-invertible-propositional to Is-bi-invertible-propositional) -- An equality characterisation lemma for A ≊ B that applies when A is -- a set. equality-characterisation-for-sets-≊ : let open Lens in {f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≊ B} → Is-set A → f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂ equality-characterisation-for-sets-≊ {f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set = f₁ ≡ f₂ ↔⟨ BM.equality-characterisation-≊ _ _ ⟩ l₁₁ ≡ l₁₂ ↝⟨ equality-characterisation-for-sets A-set ⟩□ set l₁₁ ≡ set l₁₂ □ where open Lens -- There is a split surjection from A ≊ B to A ≃ B. ≊↠≃ : (A ≊ B) ↠ (A ≃ B) ≊↠≃ = record { logical-equivalence = record { to = _↠_.to ≅↠≃ ⊚ _↠_.from BM.≅↠≊ ; from = _↠_.to BM.≅↠≊ ⊚ _↠_.from ≅↠≃ } ; right-inverse-of = λ _ → Eq.lift-equality ext (refl _) } -- The right-to-left direction maps identity to an isomorphism for -- which the first projection is the identity. ≊↠≃-id≡id : proj₁ (_↠_.from ≊↠≃ F.id) ≡ id {A = A} ≊↠≃-id≡id = equal-laws→≡ (λ _ _ → refl _) (λ a → _≃_.left-inverse-of F.id a ≡⟨ sym $ _≃_.right-left-lemma F.id _ ⟩ cong P.id (_≃_.right-inverse-of F.id a) ≡⟨⟩ cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎ refl _ ∎) (λ _ _ _ → refl _) -- If A is a set, then there is an equivalence between A ≊ B and -- A ≃ B. ≃≃≊ : Is-set A → (A ≃ B) ≃ (A ≊ B) ≃≃≊ {A = A} {B = B} A-set = A ≃ B ↝⟨ ≃≃≅ A-set ⟩ A ≅ B ↝⟨ inverse $ BM.≊≃≅-domain (lens-preserves-h-level-of-domain 1 A-set) ⟩□ A ≊ B □ -- The equivalence ≃≃≊ maps identity to an isomorphism for which the -- first projection is the identity. ≃≃≊-id≡id : (A-set : Is-set A) → proj₁ (_≃_.to (≃≃≊ A-set) F.id) ≡ id ≃≃≊-id≡id _ = ≊↠≃-id≡id -- The right-to-left direction of ≃≃≊ maps bi-invertible lenses to -- their getter functions. to-from-≃≃≊≡get : (A-set : Is-set A) (A≊B@(l , _) : A ≊ B) → _≃_.to (_≃_.from (≃≃≊ A-set) A≊B) ≡ Lens.get l to-from-≃≃≊≡get _ _ = refl _ -- The getter function of a bi-invertible lens is an equivalence. Is-bi-invertible→Is-equivalence-get : (l : Lens A B) → Is-bi-invertible l → Is-equivalence (Lens.get l) Is-bi-invertible→Is-equivalence-get l is-bi-inv = _≃_.is-equivalence (_↠_.to ≊↠≃ (l , is-bi-inv)) -- If the getter function is an equivalence, then the lens is -- bi-invertible. Is-equivalence-get→Is-bi-invertible : (l : Lens A B) → Is-equivalence (Lens.get l) → Is-bi-invertible l Is-equivalence-get→Is-bi-invertible {A = A} {B = B} l′ is-equiv = block λ b → $⟨ l⁻¹′ b , l∘l⁻¹≡id b , l⁻¹∘l≡id b ⟩ Has-quasi-inverse l ↝⟨ B.Has-quasi-inverse→Is-bi-invertible l ⟩ Is-bi-invertible l ↝⟨ subst Is-bi-invertible (getter-equivalence→lens≡ l′ is-equiv) ⟩□ Is-bi-invertible l′ □ where open Lens -- A lens that is equal to l′. l : Lens A B l = getter-equivalence→lens l′ is-equiv A≃B = Eq.⟨ get l , is-equiv ⟩ open _≃_ A≃B -- An inverse of l. -- -- Note that the set-get and set-set proofs have been "obfuscated". -- They could have been shorter, but then it might not have been -- possible to prove l∘l⁻¹≡id and l⁻¹∘l≡id. l⁻¹ : Lens B A l⁻¹ = record { get = from ; set = λ _ → get l ; get-set = λ _ a → from (get l a) ≡⟨ left-inverse-of a ⟩∎ a ∎ ; set-get = λ b → get l (from b) ≡⟨ sym $ cong (get l) $ set-get l (from b) ⟩ get l (from (get l (from b))) ≡⟨ right-inverse-of (get l (from b)) ⟩ get l (from b) ≡⟨ right-inverse-of b ⟩∎ b ∎ ; set-set = λ b a₁ a₂ → get l a₂ ≡⟨ sym $ right-inverse-of _ ⟩ get l (from (get l a₂)) ≡⟨ sym $ cong (get l) (set-set l (from b) (get l a₁) (get l a₂)) ⟩ get l (from (get l a₂)) ≡⟨ right-inverse-of _ ⟩∎ get l a₂ ∎ } -- A blocked variant of l⁻¹. l⁻¹′ : Block "l⁻¹" → Lens B A l⁻¹′ ⊠ = l⁻¹ -- The lens l⁻¹ is a right inverse of l. l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹′ b ≡ id l∘l⁻¹≡id ⊠ = constant-setter→≡id ( right-inverse-of , right-inverse-of , (λ b₁ b₂ → get-set (l ∘ l⁻¹) b₁ b₂ ≡⟨⟩ trans (cong (get l) (get-set l⁻¹ b₁ (from b₂))) (get-set l (from b₁) b₂) ≡⟨⟩ trans (cong (get l) (left-inverse-of (from b₂))) (right-inverse-of b₂) ≡⟨ cong (λ eq → trans (cong (get l) eq) (right-inverse-of b₂)) $ sym $ right-left-lemma _ ⟩ trans (cong (get l) (cong from (right-inverse-of b₂))) (right-inverse-of b₂) ≡⟨ cong (λ eq → trans eq (right-inverse-of b₂)) $ cong-∘ _ _ (right-inverse-of b₂) ⟩ trans (cong (get l ⊚ from) (right-inverse-of b₂)) (right-inverse-of b₂) ≡⟨⟩ trans (cong (get (l ∘ l⁻¹)) (right-inverse-of b₂)) (right-inverse-of b₂) ∎) , (λ b → set-get (l ∘ l⁻¹) b ≡⟨⟩ trans (cong (get l) (set-get l (from b))) (set-get l⁻¹ b) ≡⟨⟩ trans (cong (get l) (set-get l (from b))) (trans (sym (cong (get l) (set-get l (from b)))) (trans (right-inverse-of (get l (from b))) (right-inverse-of b))) ≡⟨ trans--[trans-sym] _ _ ⟩ trans (right-inverse-of (get l (from b))) (right-inverse-of b) ≡⟨⟩ trans (right-inverse-of (get (l ∘ l⁻¹) b)) (right-inverse-of b) ∎) , (λ b b₁ b₂ → set-set (l ∘ l⁻¹) b b₁ b₂ ≡⟨⟩ trans (set-set l⁻¹ b (from b₁) (from b₂)) (trans (cong (λ _ → get l (from b₂)) (get-set l⁻¹ b (from b₁))) (cong (get l) (set-set l (from b) b₁ b₂))) ≡⟨ cong (trans _) $ trans (cong (flip trans _) $ cong-const _) $ trans-reflˡ _ ⟩ trans (set-set l⁻¹ b (from b₁) (from b₂)) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨⟩ trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) (get l (from b₁)) (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ b′ → trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) b′ (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂))) $ right-inverse-of _ ⟩ trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ f → trans (trans (sym (f _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (f _))) (cong (get l) (set-set l (from b) b₁ b₂))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) right-inverse-of ⟩ trans (trans (sym (ext⁻¹ (⟨ext⟩ right-inverse-of) _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (ext⁻¹ (⟨ext⟩ right-inverse-of) _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : ∀ b → f b ≡ f b) → trans (trans (sym (ext⁻¹ p (f b₂))) (trans (sym (q (f b₂))) (ext⁻¹ p (f b₂)))) (q b₂) ≡ refl _) (λ q → trans (trans (sym (ext⁻¹ (refl P.id) _)) (trans (sym (q _)) (ext⁻¹ (refl P.id) _))) (q _) ≡⟨ cong (λ eq → trans (trans (sym eq) (trans (sym (q _)) eq)) (q _)) $ ext⁻¹-refl _ ⟩ trans (trans (sym (refl _)) (trans (sym (q _)) (refl _))) (q _) ≡⟨ cong₂ (λ p r → trans (trans p r) (q _)) sym-refl (trans-reflʳ _) ⟩ trans (trans (refl _) (sym (q _))) (q _) ≡⟨ cong (λ eq → trans eq (q _)) $ trans-reflˡ (sym (q _)) ⟩ trans (sym (q _)) (q _) ≡⟨ trans-symˡ (q _) ⟩∎ refl _ ∎) (⟨ext⟩ right-inverse-of) (cong (get l) ⊚ set-set l (from b) b₁) ⟩ refl _ ∎) ) -- The lens l⁻¹ is a left inverse of l. l⁻¹∘l≡id : ∀ b → l⁻¹′ b ∘ l ≡ id l⁻¹∘l≡id ⊠ = constant-setter→≡id ( left-inverse-of , left-inverse-of , (λ a₁ a₂ → get-set (l⁻¹ ∘ l) a₁ a₂ ≡⟨⟩ trans (cong from (get-set l a₁ (to a₂))) (get-set l⁻¹ (get l a₁) a₂) ≡⟨⟩ trans (cong from (right-inverse-of (to a₂))) (left-inverse-of a₂) ≡⟨ cong (λ eq → trans (cong from eq) (left-inverse-of _)) $ sym $ left-right-lemma _ ⟩ trans (cong from (cong (get l) (left-inverse-of a₂))) (left-inverse-of a₂) ≡⟨ cong (λ eq → trans eq (left-inverse-of _)) $ cong-∘ _ _ (left-inverse-of _) ⟩ trans (cong (from ⊚ get l) (left-inverse-of a₂)) (left-inverse-of a₂) ≡⟨⟩ trans (cong (get (l⁻¹ ∘ l)) (left-inverse-of a₂)) (left-inverse-of a₂) ∎) , (λ a → let lemma₁ = cong from (trans (sym (cong (get l) (set-get l (from (get l a))))) (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong-trans _ _ (trans _ (right-inverse-of _)) ⟩ trans (cong from (sym (cong (get l) (set-get l (from (get l a)))))) (cong from (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong (λ eq → trans (cong from eq) (cong from (trans (right-inverse-of _) (right-inverse-of _)))) $ sym $ cong-sym _ (set-get l (from (get l a))) ⟩ trans (cong from (cong (get l) (sym (set-get l (from (get l a)))))) (cong from (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong₂ trans (cong-∘ _ _ (sym (set-get l (from (get l a))))) (cong-trans _ _ (right-inverse-of _)) ⟩ trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans (cong from (right-inverse-of _)) (cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p q → trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans p q)) (right-left-lemma _) (right-left-lemma _) ⟩∎ trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans (left-inverse-of _) (left-inverse-of _)) ∎ f = from ⊚ get l lemma₂ : ∀ _ → _ lemma₂ = λ a → trans (left-inverse-of (f a)) (left-inverse-of a) ≡⟨ cong (λ g → trans (g (f a)) (g a)) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) left-inverse-of ⟩∎ trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)) (ext⁻¹ (⟨ext⟩ left-inverse-of) a) ∎ lemma₃ = trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ≡⟨ cong₂ trans (ext⁻¹-refl _) (ext⁻¹-refl _) ⟩ trans (refl _) (refl _) ≡⟨ trans-refl-refl ⟩∎ refl _ ∎ in trans (cong from (set-get l⁻¹ (get l a))) (set-get l a) ≡⟨⟩ trans (cong from (trans (sym (cong (get l) (set-get l (from (get l a))))) (trans (right-inverse-of _) (right-inverse-of _)))) (set-get l a) ≡⟨ cong (λ eq → trans eq (set-get l a)) lemma₁ ⟩ trans (trans (cong f (sym (set-get l (f a)))) (trans (left-inverse-of (f (f a))) (left-inverse-of (f a)))) (set-get l a) ≡⟨ cong (λ eq → trans (trans (cong f (sym (set-get l (f a)))) eq) (set-get l a)) $ lemma₂ _ ⟩ trans (trans (cong f (sym (set-get l (f a)))) (trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f (f a))) (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)))) (set-get l a) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : ∀ a → f a ≡ a) → trans (trans (cong f (sym (q (f a)))) (trans (ext⁻¹ p (f (f a))) (ext⁻¹ p (f a)))) (q a) ≡ trans (ext⁻¹ p (f a)) (ext⁻¹ p a)) (λ q → trans (trans (cong P.id (sym (q a))) (trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a))) (q a) ≡⟨ cong₂ (λ p r → trans (trans p r) (q a)) (sym $ cong-id _) lemma₃ ⟩ trans (trans (sym (q a)) (refl _)) (q a) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩ trans (sym (q a)) (q a) ≡⟨ trans-symˡ (q a) ⟩ refl _ ≡⟨ sym lemma₃ ⟩∎ trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ∎) (⟨ext⟩ left-inverse-of) (set-get l) ⟩ trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)) (ext⁻¹ (⟨ext⟩ left-inverse-of) a) ≡⟨ sym $ lemma₂ _ ⟩ trans (left-inverse-of (f a)) (left-inverse-of a) ≡⟨⟩ trans (left-inverse-of (get (l⁻¹ ∘ l) a)) (left-inverse-of a) ∎) , (λ a a₁ a₂ → let q = set-set l a (get l a₁) (get l a₂) lemma = cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) q)) (right-inverse-of _))) ≡⟨ cong-trans _ _ (trans (sym (cong (get l) q)) (right-inverse-of _)) ⟩ trans (cong from (sym (right-inverse-of _))) (cong from (trans (sym (cong (get l) q)) (right-inverse-of _))) ≡⟨ cong₂ trans (cong-sym _ (right-inverse-of _)) (cong-trans _ _ (right-inverse-of _)) ⟩ trans (sym (cong from (right-inverse-of _))) (trans (cong from (sym (cong (get l) q))) (cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p r → trans (sym p) (trans (cong from (sym (cong (get l) q))) r)) (right-left-lemma _) (right-left-lemma _) ⟩ trans (sym (left-inverse-of _)) (trans (cong from (sym (cong (get l) q))) (left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _)) (trans eq (left-inverse-of _))) $ cong-sym _ (cong (get l) q) ⟩ trans (sym (left-inverse-of _)) (trans (sym (cong from (cong (get l) q))) (left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _)) (trans (sym eq) (left-inverse-of _))) $ cong-∘ _ _ q ⟩ trans (sym (left-inverse-of _)) (trans (sym (cong (from ⊚ get l) q)) (left-inverse-of _)) ≡⟨ cong (λ g → trans (sym (g _)) (trans (sym (cong (from ⊚ get l) q)) (g _))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) left-inverse-of ⟩∎ trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) _)) (trans (sym (cong (from ⊚ get l) q)) (ext⁻¹ (⟨ext⟩ left-inverse-of) _)) ∎ f = from ⊚ get l in set-set (l⁻¹ ∘ l) a a₁ a₂ ≡⟨⟩ trans (set-set l a (get l a₁) (get l a₂)) (trans (cong (λ _ → from (get l a₂)) (right-inverse-of (get l a₁))) (cong from (set-set l⁻¹ (get l a) a₁ a₂))) ≡⟨ cong (trans _) $ trans (cong (flip trans _) $ cong-const _) $ trans-reflˡ _ ⟩ trans (set-set l a (get l a₁) (get l a₂)) (cong from (set-set l⁻¹ (get l a) a₁ a₂)) ≡⟨⟩ trans (set-set l a (get l a₁) (get l a₂)) (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from (get l a)) (get l a₁) (get l a₂)))) (right-inverse-of _)))) ≡⟨ cong (λ a′ → trans q (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l a′ (get l a₁) (get l a₂)))) (right-inverse-of _))))) $ left-inverse-of _ ⟩ trans q (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) q)) (right-inverse-of _)))) ≡⟨ cong (trans q) lemma ⟩ trans q (trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂))) (trans (sym (cong f q)) (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂)))) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : f a₂ ≡ f a₂) → trans q (trans (sym (ext⁻¹ p (f a₂))) (trans (sym (cong f q)) (ext⁻¹ p (f a₂)))) ≡ refl _) (λ q → trans q (trans (sym (ext⁻¹ (refl P.id) a₂)) (trans (sym (cong P.id q)) (ext⁻¹ (refl P.id) a₂))) ≡⟨ cong (λ eq → trans q (trans (sym eq) (trans (sym (cong P.id q)) eq))) $ ext⁻¹-refl _ ⟩ trans q (trans (sym (refl _)) (trans (sym (cong P.id q)) (refl _))) ≡⟨ cong₂ (λ p r → trans q (trans p r)) sym-refl (trans-reflʳ _) ⟩ trans q (trans (refl _) (sym (cong P.id q))) ≡⟨ cong (trans q) $ trans-reflˡ (sym (cong P.id q)) ⟩ trans q (sym (cong P.id q)) ≡⟨ cong (λ eq → trans q (sym eq)) $ sym $ cong-id q ⟩ trans q (sym q) ≡⟨ trans-symʳ q ⟩∎ refl _ ∎) (⟨ext⟩ left-inverse-of) q ⟩ refl _ ∎) ) -- There is an equivalence between "l is bi-invertible" and "the -- getter of l is an equivalence". Is-bi-invertible≃Is-equivalence-get : (l : Lens A B) → Is-bi-invertible l ≃ Is-equivalence (Lens.get l) Is-bi-invertible≃Is-equivalence-get l = Eq.⇔→≃ (BM.Is-bi-invertible-propositional l) (Eq.propositional ext _) (Is-bi-invertible→Is-equivalence-get l) (Is-equivalence-get→Is-bi-invertible l) -- There is in general no split surjection from equivalences to -- bi-invertible lenses, if the right-to-left direction of the split -- surjection is required to map bi-invertible lenses to their getter -- functions (assuming univalence). ¬≃↠≊ : Univalence lzero → ¬ ∃ λ (≃↠≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_↠_.from ≃↠≊ x) ≡ Lens.get l ¬≃↠≊ {a = a} univ = (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ Σ-map ((∃-cong λ l → _≃_.surjection $ Is-bi-invertible≃Is-equivalence-get l) F.∘_) (λ hyp _ → hyp _) ⟩ (∃ λ (f : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (∃ λ (l : Lens (↑ a 𝕊¹) (↑ a 𝕊¹)) → Is-equivalence (Lens.get l))) → ∀ p → _≃_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃-↠-Σ-Lens-Is-equivalence-get univ ⟩□ ⊥ □ -- There is in general no equivalence between equivalences and -- bi-invertible lenses, if the right-to-left direction of the -- equivalence is required to map bi-invertible lenses to their getter -- functions (assuming univalence). ¬≃≃≊ : Univalence lzero → ¬ ∃ λ (≃≃≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_≃_.from ≃≃≊ x) ≡ Lens.get l ¬≃≃≊ {a = a} univ = (∃ λ (≃≃≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ≃ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_≃_.from ≃≃≊ x) ≡ Lens.get l) ↝⟨ Σ-map _≃_.surjection P.id ⟩ (∃ λ (≃↠≊ : (↑ a 𝕊¹ ≃ ↑ a 𝕊¹) ↠ (↑ a 𝕊¹ ≊ ↑ a 𝕊¹)) → (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_↠_.from ≃↠≊ x) ≡ Lens.get l) ↝⟨ ¬≃↠≊ univ ⟩□ ⊥ □ ------------------------------------------------------------------------ -- A category -- Lenses between sets with the same universe level form a -- precategory. precategory : Precategory (lsuc a) a precategory {a = a} = record { precategory = Set a , (λ (A , A-set) (B , _) → Lens A B , lens-preserves-h-level-of-domain 1 A-set) , id , _∘_ , left-identity _ , right-identity _ , (λ {_ _ _ _ l₁ l₂ l₃} → associativity l₃ l₂ l₁) } -- Lenses between sets with the same universe level form a -- category (assuming univalence). category : Univalence a → Category (lsuc a) a category {a = a} univ = C.precategory-with-Set-to-category ext (λ _ _ → univ) (proj₂ Pre.precategory) (λ (_ , A-set) _ → ≃≃≅ A-set) (λ (_ , A-set) → ≃≃≅-id≡id A-set) where module Pre = C.Precategory precategory -- The following four results (up to and including ¬-univalent) are -- based on a suggestion by Paolo Capriotti, in response to a question -- from an anonymous reviewer. -- A "naive" notion of category. -- -- Note that the hom-sets are not required to be sets. Naive-category : (o h : Level) → Type (lsuc (o ⊔ h)) Naive-category o h = ∃ λ (Obj : Type o) → ∃ λ (Hom : Obj → Obj → Type h) → ∃ λ (id : {A : Obj} → Hom A A) → ∃ λ (_∘_ : {A B C : Obj} → Hom B C → Hom A B → Hom A C) → ({A B : Obj} (h : Hom A B) → id ∘ h ≡ h) × ({A B : Obj} (h : Hom A B) → h ∘ id ≡ h) × ({A B C D : Obj} (h₁ : Hom C D) (h₂ : Hom B C) (h₃ : Hom A B) → (h₁ ∘ (h₂ ∘ h₃)) ≡ ((h₁ ∘ h₂) ∘ h₃)) -- A notion of univalence for naive categories. Univalent : Naive-category o h → Type (o ⊔ h) Univalent (Obj , Hom , id , _∘_ , id-∘ , ∘-id , assoc) = Bi-invertibility.More.Univalence-≊ equality-with-J Obj Hom id _∘_ id-∘ ∘-id assoc -- Types in a fixed universe and traditional lenses between them form -- a naive category. naive-category : ∀ a → Naive-category (lsuc a) a naive-category a = Type a , Lens , id , _∘_ , left-identity , right-identity , associativity -- However, this category is not univalent (assuming univalence). ¬-univalent : Univalence lzero → Univalence a → ¬ Univalent (naive-category a) ¬-univalent {a = a} univ₀ univ u = ¬≃≃≊ univ₀ (equiv , lemma₂) where equiv : {A B : Type a} → (A ≃ B) ≃ (A ≊ B) equiv {A = A} {B = B} = (A ≃ B) ↝⟨ inverse $ ≡≃≃ univ ⟩ (A ≡ B) ↝⟨ Eq.⟨ _ , u ⟩ ⟩□ (A ≊ B) □ lemma₁ : (eq : ↑ a 𝕊¹ ≃ ↑ a 𝕊¹) → _≃_.to eq ≡ Lens.get (proj₁ (_≃_.to equiv eq)) lemma₁ = ≃-elim₁ univ (λ eq → _≃_.to eq ≡ Lens.get (proj₁ (_≃_.to equiv eq))) (P.id ≡⟨ cong (Lens.get ⊚ proj₁) $ sym $ elim-refl _ _ ⟩ Lens.get (proj₁ (BM.≡→≊ (refl _))) ≡⟨ cong (Lens.get ⊚ proj₁ ⊚ BM.≡→≊) $ sym $ ≃⇒≡-id univ ⟩ Lens.get (proj₁ (BM.≡→≊ (≃⇒≡ univ Eq.id))) ≡⟨⟩ Lens.get (proj₁ (_≃_.to equiv Eq.id)) ∎) lemma₂ : (x@(l , _) : ↑ a 𝕊¹ ≊ ↑ a 𝕊¹) → _≃_.to (_≃_.from equiv x) ≡ Lens.get l lemma₂ x@(l , _) = _≃_.to (_≃_.from equiv x) ≡⟨ lemma₁ (_≃_.from equiv x) ⟩ Lens.get (proj₁ (_≃_.to equiv (_≃_.from equiv x))) ≡⟨ cong (Lens.get ⊚ proj₁) $ _≃_.right-inverse-of equiv _ ⟩ Lens.get (proj₁ x) ≡⟨⟩ Lens.get l ∎ -- There is in general no pointwise equivalence between equivalences -- and bi-invertible lenses (assuming univalence). ¬Π≃≃≊ : Univalence lzero → Univalence a → ¬ ({A B : Type a} → (A ≃ B) ≃ (A ≊ B)) ¬Π≃≃≊ {a = a} univ₀ univ = ({A B : Type a} → (A ≃ B) ≃ (A ≊ B)) ↝⟨ F._∘ ≡≃≃ univ ⟩ ({A B : Type a} → (A ≡ B) ≃ (A ≊ B)) ↝⟨ BM.≡≃≊→Univalence-≊ ⟩ Univalent (naive-category a) ↝⟨ ¬-univalent univ₀ univ ⟩□ ⊥ □ -- There is in general no pointwise equivalence between equivalences -- (between types in the same universe) and lenses with getters that -- are equivalences (assuming univalence). ¬Π≃-≃-Σ-Lens-Is-equivalence-get : Univalence lzero → Univalence a → ¬ ({A B : Type a} → (A ≃ B) ≃ ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l)) ¬Π≃-≃-Σ-Lens-Is-equivalence-get {a = a} univ₀ univ = ({A B : Type a} → (A ≃ B) ≃ ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l)) ↝⟨ inverse (∃-cong Is-bi-invertible≃Is-equivalence-get) F.∘_ ⟩ ({A B : Type a} → (A ≃ B) ≃ (A ≊ B)) ↝⟨ ¬Π≃≃≊ univ₀ univ ⟩□ ⊥ □
48.83442
152
0.363989
41b789887feee6fbad928da4d01c205857d5a291
681
agda
Agda
Cubical/Relation/Binary/Extensionality.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Relation/Binary/Extensionality.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Relation/Binary/Extensionality.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Relation.Binary.Extensionality where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Transport open import Cubical.Data.Sigma open import Cubical.Relation.Binary.Base module _ {ℓ ℓ'} {A : Type ℓ} (_≺_ : Rel A A ℓ') where ≡→≺Equiv : (x y : A) → x ≡ y → ∀ z → (z ≺ x) ≃ (z ≺ y) ≡→≺Equiv _ _ p z = substEquiv (z ≺_) p isWeaklyExtensional : Type _ isWeaklyExtensional = ∀ {x y} → isEquiv (≡→≺Equiv x y) isPropIsWeaklyExtensional : isProp isWeaklyExtensional isPropIsWeaklyExtensional = isPropImplicitΠ2 λ _ _ → isPropIsEquiv _
30.954545
70
0.71953
3d32f6bab19db8eec9a46596bca0241e299fd7b2
710
agda
Agda
notes/k-axiom/UIP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/k-axiom/UIP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/k-axiom/UIP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} -- {-# OPTIONS --without-K #-} -- [1] Hofmann, Martin and Thomas Streicher (1998). “The groupoid -- interpretation on type theory”. In: Twenty-five Years of -- Constructive Type Theory. Ed. by Giovanni Sambin and Jan -- M. Smith. Oxford University Press. Chap. 6. module UIP where data Id (A : Set)(x : A) : A → Set where refl : Id A x x K : (A : Set)(x : A)(P : Id A x x → Set) → P refl → (p : Id A x x ) → P p K A x P pr refl = pr -- From [1, p. 88]. UIP : (A : Set)(a a' : A)(p p' : Id A a a') → Id (Id A a a') p p' UIP A a .a refl refl = refl
32.272727
73
0.54507
125616389d0efe9140fc75016201338bb6e0efa0
806
agda
Agda
examples/Introduction/Data/Vec.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/Introduction/Data/Vec.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/Introduction/Data/Vec.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- When defining types by recursion it is sometimes difficult to infer implicit -- arguments. This module illustrates the problem and shows how to get around -- it. module Introduction.Data.Vec where data Nat : Set where zero : Nat suc : Nat -> Nat data Nil : Set where nil' : Nil data Cons (A As : Set) : Set where _::'_ : A -> As -> Cons A As mutual Vec' : Set -> Nat -> Set Vec' A zero = Nil Vec' A (suc n) = Cons A (Vec A n) data Vec (A : Set)(n : Nat) : Set where vec : Vec' A n -> Vec A n nil : {A : Set} -> Vec A zero nil = vec nil' _::_ : {A : Set}{n : Nat} -> A -> Vec A n -> Vec A (suc n) x :: xs = vec (x ::' xs) map : {n : Nat}{A B : Set} -> (A -> B) -> Vec A n -> Vec B n map {zero} f (vec nil') = nil map {suc n} f (vec (x ::' xs)) = f x :: map f xs
22.388889
79
0.555831
0e86adec58c711bd388f4c219b10027f5f09b721
5,122
agda
Agda
lemmas-complete.agda
hazelgrove/hazelnut-agda
a3640d7b0f76cdac193afd382694197729ed6d57
[ "MIT" ]
null
null
null
lemmas-complete.agda
hazelgrove/hazelnut-agda
a3640d7b0f76cdac193afd382694197729ed6d57
[ "MIT" ]
null
null
null
lemmas-complete.agda
hazelgrove/hazelnut-agda
a3640d7b0f76cdac193afd382694197729ed6d57
[ "MIT" ]
null
null
null
open import Nat open import Prelude open import dynamics-core open import lemmas-gcomplete module lemmas-complete where -- no term is both complete and indeterminate lem-ind-comp : ∀{d} → d dcomplete → d indet → ⊥ lem-ind-comp DCNum () lem-ind-comp (DCPlus comp comp₁) (IPlus1 ind fin) = lem-ind-comp comp ind lem-ind-comp (DCPlus comp comp₁) (IPlus2 fin ind) = lem-ind-comp comp₁ ind lem-ind-comp DCVar () lem-ind-comp (DCLam comp x₁) () lem-ind-comp (DCAp comp comp₁) (IAp x ind x₁) = lem-ind-comp comp ind lem-ind-comp (DCCast comp x x₁) (ICastArr x₂ ind) = lem-ind-comp comp ind lem-ind-comp (DCCast comp x x₁) (ICastGroundHole x₂ ind) = lem-ind-comp comp ind lem-ind-comp (DCCast comp x x₁) (ICastHoleGround x₂ ind x₃) = lem-ind-comp comp ind lem-ind-comp (DCInl x comp) (IInl ind) = lem-ind-comp comp ind lem-ind-comp (DCInr x comp) (IInr ind) = lem-ind-comp comp ind lem-ind-comp (DCCase comp comp₁ comp₂) (ICase x x₁ x₂ ind) = lem-ind-comp comp ind lem-ind-comp (DCCast comp x x₁) (ICastSum x₂ ind) = lem-ind-comp comp ind lem-ind-comp (DCPair comp comp₁) (IPair1 ind x) = lem-ind-comp comp ind lem-ind-comp (DCPair comp comp₁) (IPair2 x ind) = lem-ind-comp comp₁ ind lem-ind-comp (DCFst comp) (IFst x x₁ ind) = lem-ind-comp comp ind lem-ind-comp (DCSnd comp) (ISnd x x₁ ind) = lem-ind-comp comp ind lem-ind-comp (DCCast comp x x₁) (ICastProd x₂ ind) = lem-ind-comp comp ind -- complete types that are consistent are equal complete-consistency : ∀{τ1 τ2} → τ1 ~ τ2 → τ1 tcomplete → τ2 tcomplete → τ1 == τ2 complete-consistency TCRefl TCNum comp2 = refl complete-consistency TCRefl (TCArr comp1 comp2) comp3 = refl complete-consistency TCRefl (TCSum tc1 tc3) comp2 = refl complete-consistency TCHole1 comp1 () complete-consistency (TCArr consis consis₁) (TCArr comp1 comp2) (TCArr comp3 comp4) with complete-consistency consis comp1 comp3 | complete-consistency consis₁ comp2 comp4 ... | refl | refl = refl complete-consistency (TCSum consis consis₁) (TCSum comp1 comp2) (TCSum comp3 comp4) with complete-consistency consis comp1 comp3 | complete-consistency consis₁ comp2 comp4 ... | refl | refl = refl complete-consistency TCRefl (TCProd comp comp₁) comp2 = refl complete-consistency TCHole2 () comp2 complete-consistency (TCProd consis consis₁) (TCProd comp1 comp2) (TCProd comp3 comp4) with complete-consistency consis comp1 comp3 | complete-consistency consis₁ comp2 comp4 ... | refl | refl = refl -- a well typed complete term is assigned a complete type complete-ta : ∀{Γ Δ d τ} → (Γ gcomplete) → (Δ , Γ ⊢ d :: τ) → d dcomplete → τ tcomplete complete-ta gc TANum comp = TCNum complete-ta gc (TAPlus wt wt₁) comp = TCNum complete-ta gc (TAVar x₁) DCVar = gc _ _ x₁ complete-ta gc (TALam a wt) (DCLam comp x₁) = TCArr x₁ (complete-ta (gcomp-extend gc x₁ a ) wt comp) complete-ta gc (TAAp wt wt₁) (DCAp comp comp₁) with complete-ta gc wt comp ... | TCArr qq qq₁ = qq₁ complete-ta gc (TAEHole x x₁) () complete-ta gc (TANEHole x wt x₁) () complete-ta gc (TACast wt x) (DCCast comp x₁ x₂) = x₂ complete-ta gc (TAFailedCast wt x x₁ x₂) () complete-ta gc (TAInl wt) (DCInl x comp) = TCSum (complete-ta gc wt comp) x complete-ta gc (TAInr wt) (DCInr x comp) = TCSum x (complete-ta gc wt comp) complete-ta gc (TACase wt apt₁ wt₁ apt₂ wt₂) (DCCase comp comp₁ comp₂) with complete-ta gc wt comp ... | TCSum τc1 τc2 = complete-ta (gcomp-extend gc τc1 apt₁) wt₁ comp₁ complete-ta gc (TAPair wt wt₁) (DCPair comp comp₁) = TCProd (complete-ta gc wt comp) (complete-ta gc wt₁ comp₁) complete-ta gc (TAFst wt) (DCFst comp) with complete-ta gc wt comp ... | TCProd τc1 τc2 = τc1 complete-ta gc (TASnd wt) (DCSnd comp) with complete-ta gc wt comp ... | TCProd τc1 τc2 = τc2 -- a well typed term synthesizes a complete type comp-synth : ∀{Γ e τ} → Γ gcomplete → e ecomplete → Γ ⊢ e => τ → τ tcomplete comp-synth gc ec SNum = TCNum comp-synth gc ec (SPlus x x₁) = TCNum comp-synth gc (ECAsc x ec) (SAsc x₁) = x comp-synth gc ec (SVar x) = gc _ _ x comp-synth gc (ECAp ec ec₁) (SAp wt MAHole x₁) with comp-synth gc ec wt ... | () comp-synth gc (ECAp ec ec₁) (SAp wt MAArr x₁) with comp-synth gc ec wt comp-synth gc (ECAp ec ec₁) (SAp wt MAArr x₁) | TCArr qq qq₁ = qq₁ comp-synth gc () SEHole comp-synth gc () (SNEHole wt) comp-synth gc (ECLam2 ec x₁) (SLam x₂ wt) = TCArr x₁ (comp-synth (gcomp-extend gc x₁ x₂) ec wt) comp-synth gc (ECPair ec ec₁) (SPair wt wt₁) with comp-synth gc ec wt | comp-synth gc ec₁ wt₁ ... | τc1 | τc2 = TCProd τc1 τc2 comp-synth gc (ECFst ec) (SFst wt MPHole) with comp-synth gc ec wt ... | () comp-synth gc (ECFst ec) (SFst wt MPProd) with comp-synth gc ec wt ... | TCProd τc1 τc2 = τc1 comp-synth gc (ECSnd ec) (SSnd wt MPHole) with comp-synth gc ec wt ... | () comp-synth gc (ECSnd ec) (SSnd wt MPProd) with comp-synth gc ec wt ... | TCProd τc1 τc2 = τc2
49.25
113
0.668098
23b18efc92701267e3a8c3ab2642e3c06b276fee
385
agda
Agda
Cats/Category/Constructions/Mono.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
24
2017-11-03T15:18:57.000Z
2021-08-06T05:00:46.000Z
Cats/Category/Constructions/Mono.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
null
null
null
Cats/Category/Constructions/Mono.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
1
2019-03-18T15:35:07.000Z
2019-03-18T15:35:07.000Z
{-# OPTIONS --without-K --safe #-} module Cats.Category.Constructions.Mono where open import Level open import Cats.Category.Base module Build {lo la l≈} (Cat : Category lo la l≈) where private open module Cat = Category Cat open Cat.≈-Reasoning IsMono : ∀ {A B} → A ⇒ B → Set (lo ⊔ la ⊔ l≈) IsMono {A} f = ∀ {C} {g h : C ⇒ A} → f ∘ g ≈ f ∘ h → g ≈ h open Build public
20.263158
60
0.612987
595d0fc8cbcf7e9ed71095728141c09291fef171
234
agda
Agda
test/Compiler/simple/Issue326.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/Issue326.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/Issue326.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue326 where open import Common.Prelude postulate QName : Set {-# BUILTIN QNAME QName #-} primitive primQNameEquality : QName → QName → Bool main : IO Unit main = printBool (primQNameEquality (quote Unit) (quote IO))
15.6
60
0.735043
59850d6559e7539eea9852732172275af6c80e10
6,011
agda
Agda
agda-stdlib-0.9/src/Data/Nat/Divisibility.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/Divisibility.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Nat/Divisibility.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Divisibility ------------------------------------------------------------------------ module Data.Nat.Divisibility where open import Data.Nat as Nat open import Data.Nat.DivMod import Data.Nat.Properties as NatProp open import Data.Fin as Fin using (Fin; zero; suc) import Data.Fin.Properties as FP open NatProp.SemiringSolver open import Algebra private module CS = CommutativeSemiring NatProp.commutativeSemiring open import Data.Product open import Relation.Nullary open import Relation.Binary import Relation.Binary.PartialOrderReasoning as PartialOrderReasoning open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; _≢_; refl; sym; cong; subst) open import Function -- m ∣ n is inhabited iff m divides n. Some sources, like Hardy and -- Wright's "An Introduction to the Theory of Numbers", require m to -- be non-zero. However, some things become a bit nicer if m is -- allowed to be zero. For instance, _∣_ becomes a partial order, and -- the gcd of 0 and 0 becomes defined. infix 4 _∣_ data _∣_ : ℕ → ℕ → Set where divides : {m n : ℕ} (q : ℕ) (eq : n ≡ q * m) → m ∣ n -- Extracts the quotient. quotient : ∀ {m n} → m ∣ n → ℕ quotient (divides q _) = q -- If m divides n, and n is positive, then m ≤ n. ∣⇒≤ : ∀ {m n} → m ∣ suc n → m ≤ suc n ∣⇒≤ (divides zero ()) ∣⇒≤ {m} {n} (divides (suc q) eq) = begin m ≤⟨ NatProp.m≤m+n m (q * m) ⟩ suc q * m ≡⟨ sym eq ⟩ suc n ∎ where open ≤-Reasoning -- _∣_ is a partial order. poset : Poset _ _ _ poset = record { Carrier = ℕ ; _≈_ = _≡_ ; _≤_ = _∣_ ; isPartialOrder = record { isPreorder = record { isEquivalence = PropEq.isEquivalence ; reflexive = reflexive ; trans = trans } ; antisym = antisym } } where module DTO = DecTotalOrder Nat.decTotalOrder open PropEq.≡-Reasoning reflexive : _≡_ ⇒ _∣_ reflexive {n} refl = divides 1 (sym $ proj₁ CS.*-identity n) antisym : Antisymmetric _≡_ _∣_ antisym (divides {n = zero} q₁ eq₁) (divides {n = n₂} q₂ eq₂) = begin n₂ ≡⟨ eq₂ ⟩ q₂ * 0 ≡⟨ CS.*-comm q₂ 0 ⟩ 0 ∎ antisym (divides {n = n₁} q₁ eq₁) (divides {n = zero} q₂ eq₂) = begin 0 ≡⟨ CS.*-comm 0 q₁ ⟩ q₁ * 0 ≡⟨ sym eq₁ ⟩ n₁ ∎ antisym (divides {n = suc n₁} q₁ eq₁) (divides {n = suc n₂} q₂ eq₂) = DTO.antisym (∣⇒≤ (divides q₁ eq₁)) (∣⇒≤ (divides q₂ eq₂)) trans : Transitive _∣_ trans (divides q₁ refl) (divides q₂ refl) = divides (q₂ * q₁) (sym (CS.*-assoc q₂ q₁ _)) module ∣-Reasoning = PartialOrderReasoning poset renaming (_≤⟨_⟩_ to _∣⟨_⟩_; _≈⟨_⟩_ to _≡⟨_⟩_) private module P = Poset poset -- 1 divides everything. 1∣_ : ∀ n → 1 ∣ n 1∣ n = divides n (sym $ proj₂ CS.*-identity n) -- Everything divides 0. _∣0 : ∀ n → n ∣ 0 n ∣0 = divides 0 refl -- 0 only divides 0. 0∣⇒≡0 : ∀ {n} → 0 ∣ n → n ≡ 0 0∣⇒≡0 {n} 0∣n = P.antisym (n ∣0) 0∣n -- Only 1 divides 1. ∣1⇒≡1 : ∀ {n} → n ∣ 1 → n ≡ 1 ∣1⇒≡1 {n} n∣1 = P.antisym n∣1 (1∣ n) -- If i divides m and n, then i divides their sum. ∣-+ : ∀ {i m n} → i ∣ m → i ∣ n → i ∣ m + n ∣-+ (divides {m = i} q refl) (divides q' refl) = divides (q + q') (sym $ proj₂ CS.distrib i q q') -- If i divides m and n, then i divides their difference. ∣-∸ : ∀ {i m n} → i ∣ m + n → i ∣ m → i ∣ n ∣-∸ (divides {m = i} q' eq) (divides q refl) = divides (q' ∸ q) (sym $ NatProp.im≡jm+n⇒[i∸j]m≡n q' q i _ $ sym eq) -- A simple lemma: n divides kn. ∣-* : ∀ k {n} → n ∣ k * n ∣-* k = divides k refl -- If i divides j, then ki divides kj. *-cong : ∀ {i j} k → i ∣ j → k * i ∣ k * j *-cong {i} {j} k (divides q eq) = divides q lemma where open PropEq.≡-Reasoning lemma = begin k * j ≡⟨ cong (_*_ k) eq ⟩ k * (q * i) ≡⟨ solve 3 (λ k q i → k :* (q :* i) := q :* (k :* i)) refl k q i ⟩ q * (k * i) ∎ -- If ki divides kj, and k is positive, then i divides j. /-cong : ∀ {i j} k → suc k * i ∣ suc k * j → i ∣ j /-cong {i} {j} k (divides q eq) = divides q lemma where open PropEq.≡-Reasoning k′ = suc k lemma = NatProp.cancel-*-right j (q * i) (begin j * k′ ≡⟨ CS.*-comm j k′ ⟩ k′ * j ≡⟨ eq ⟩ q * (k′ * i) ≡⟨ solve 3 (λ q k i → q :* (k :* i) := q :* i :* k) refl q k′ i ⟩ q * i * k′ ∎) -- If the remainder after division is non-zero, then the divisor does -- not divide the dividend. nonZeroDivisor-lemma : ∀ m q (r : Fin (1 + m)) → Fin.toℕ r ≢ 0 → ¬ (1 + m) ∣ (Fin.toℕ r + q * (1 + m)) nonZeroDivisor-lemma m zero r r≢zero (divides zero eq) = r≢zero $ begin Fin.toℕ r ≡⟨ sym $ proj₁ CS.*-identity (Fin.toℕ r) ⟩ 1 * Fin.toℕ r ≡⟨ eq ⟩ 0 ∎ where open PropEq.≡-Reasoning nonZeroDivisor-lemma m zero r r≢zero (divides (suc q) eq) = NatProp.¬i+1+j≤i m $ begin m + suc (q * suc m) ≡⟨ solve 2 (λ m q → m :+ (con 1 :+ q) := con 1 :+ m :+ q) refl m (q * suc m) ⟩ suc (m + q * suc m) ≡⟨ sym eq ⟩ 1 * Fin.toℕ r ≡⟨ proj₁ CS.*-identity (Fin.toℕ r) ⟩ Fin.toℕ r ≤⟨ ≤-pred $ FP.bounded r ⟩ m ∎ where open ≤-Reasoning nonZeroDivisor-lemma m (suc q) r r≢zero d = nonZeroDivisor-lemma m q r r≢zero (∣-∸ d' P.refl) where lem = solve 3 (λ m r q → r :+ (m :+ q) := m :+ (r :+ q)) refl (suc m) (Fin.toℕ r) (q * suc m) d' = subst (λ x → (1 + m) ∣ x) lem d -- Divisibility is decidable. _∣?_ : Decidable _∣_ zero ∣? zero = yes (0 ∣0) zero ∣? suc n = no ((λ ()) ∘′ 0∣⇒≡0) suc m ∣? n with n divMod suc m suc m ∣? .(q * suc m) | result q zero refl = yes $ divides q refl suc m ∣? .(1 + Fin.toℕ r + q * suc m) | result q (suc r) refl = no $ nonZeroDivisor-lemma m q (suc r) (λ())
29.038647
72
0.520213
1dcf737765b94986b7daab4dddcf4349d1a81817
1,522
agda
Agda
Function/Names.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Function/Names.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Function/Names.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
import Lvl module Function.Names where open import Functional.Dependent open import Logic.Predicate open import Structure.Setoid open import Type private variable ℓ ℓₒ ℓₒ₁ ℓₒ₂ ℓₒ₃ ℓₗ ℓₗ₁ ℓₗ₂ ℓₗ₃ : Lvl.Level module _ {A : Type{ℓₒ₁}} {B : A → Type{ℓₒ₂}} ⦃ _ : ∀{a} → Equiv{ℓₗ₃}(B(a)) ⦄ where -- Extensional equality on functions. -- Alternative definition: f ⊜ g = (∀{x} → (f(x) ≡ g(x))) _⊜_ : ((a : A) → B(a)) → ((a : A) → B(a)) → Type _⊜_ = ∀¹ ∘₂ pointwise₂,₁(_≡_) _⊜₁_ = _⊜_ module _ {A : Type{ℓₒ₁}} {B : A → Type{ℓₒ₂}} ⦃ _ : ∀{a} → Equiv{ℓₗ₃}(B(a)) ⦄ where _⊜ᵢ_ : ({a : A} → B(a)) → ({a : A} → B(a)) → Type _⊜ᵢ_ f g = (∀{x} → (f{x} ≡ g{x})) module _ {A : Type{ℓₒ₁}} {B : A → Type{ℓₒ₂}} ⦃ _ : ∀{a} → Equiv{ℓₗ₃}(B(a)) ⦄ where _⦃⊜⦄_ : (⦃ a : A ⦄ → B(a)) → (⦃ a : A ⦄ → B(a)) → Type _⦃⊜⦄_ f g = (∀{x} → (f ⦃ x ⦄ ≡ g ⦃ x ⦄)) module _ {A₁ : Type{ℓₒ₁}} {A₂ : A₁ → Type{ℓₒ₂}} {B : (a₁ : A₁) → A₂(a₁) → Type{ℓₒ₂}} ⦃ _ : ∀{a₁}{a₂} → Equiv{ℓₗ₃}(B(a₁)(a₂)) ⦄ where -- Alternative definition: f ⊜ g = (∀{x}{y} → (f(x)(y) ≡ g(x)(y))) _⊜₂_ : (f g : ∀(a₁)(a₂) → B(a₁)(a₂)) → Type _⊜₂_ = ∀¹ ∘₂ (∀¹ ∘₃ pointwise₂,₂(_≡_)) module _ {A₁ : Type{ℓₒ₁}} {A₂ : A₁ → Type{ℓₒ₂}} {A₃ : (a₁ : A₁) → A₂(a₁) → Type{ℓₒ₂}} {B : (a₁ : A₁) → (a₂ : A₂(a₁)) → A₃(a₁)(a₂) → Type{ℓₒ₂}} ⦃ _ : ∀{a₁}{a₂}{a₃} → Equiv{ℓₗ₃}(B(a₁)(a₂)(a₃)) ⦄ where -- Alternative definition: f ⊜ g = (∀{x}{y}{z} → (f(x)(y)(z) ≡ g(x)(y)(z))) _⊜₃_ : (f g : ∀(a₁)(a₂)(a₃) → B(a₁)(a₂)(a₃)) → Type _⊜₃_ = ∀¹ ∘₂ (∀¹ ∘₃ (∀¹ ∘₄ pointwise₂,₃(_≡_)))
42.277778
198
0.48883
12edc19b9a3b4ebdf84606d66810806116989f5d
6,875
agda
Agda
agda-stdlib/src/Reflection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Reflection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Reflection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Support for reflection ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Reflection where import Agda.Builtin.Reflection as Builtin ------------------------------------------------------------------------ -- Names, Metas, and Literals re-exported publicly open import Reflection.Abstraction as Abstraction public using (Abs; abs) open import Reflection.Argument as Argument public using (Arg; arg; Args; vArg; hArg; iArg) open import Reflection.Definition as Definition public using (Definition) open import Reflection.Meta as Meta public using (Meta) open import Reflection.Name as Name public using (Name; Names) open import Reflection.Literal as Literal public using (Literal) open import Reflection.Pattern as Pattern public using (Pattern) open import Reflection.Term as Term public using (Term; Type; Clause; Clauses; Sort) import Reflection.Argument.Relevance as Relevance import Reflection.Argument.Visibility as Visibility import Reflection.Argument.Information as Information open Definition.Definition public open Information.ArgInfo public open Literal.Literal public open Relevance.Relevance public open Term.Term public open Visibility.Visibility public ------------------------------------------------------------------------ -- Fixity open Builtin public using (non-assoc; related; unrelated; fixity) renaming ( left-assoc to assocˡ ; right-assoc to assocʳ ; primQNameFixity to getFixity ) ------------------------------------------------------------------------ -- Type checking monad -- Type errors open Builtin public using (ErrorPart; strErr; termErr; nameErr) -- The monad open Builtin public using ( TC; bindTC; unify; typeError; inferType; checkType ; normalise; reduce ; catchTC; quoteTC; unquoteTC ; getContext; extendContext; inContext; freshName ; declareDef; declarePostulate; defineFun; getType; getDefinition ; blockOnMeta; commitTC; isMacro; withNormalisation ; debugPrint; noConstraints; runSpeculative) renaming (returnTC to return) -- Standard monad operators open import Reflection.TypeChecking.MonadSyntax public using (_>>=_; _>>_) newMeta : Type → TC Term newMeta = checkType unknown ------------------------------------------------------------------------ -- Show open import Reflection.Show public ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 1.1 returnTC = return {-# WARNING_ON_USAGE returnTC "Warning: returnTC was deprecated in v1.1. Please use return instead." #-} -- Version 1.3 Arg-info = Information.ArgInfo {-# WARNING_ON_USAGE Arg-info "Warning: Arg-info was deprecated in v1.3. Please use Reflection.Argument.Information's ArgInfo instead." #-} infix 4 _≟-Lit_ _≟-Name_ _≟-Meta_ _≟-Visibility_ _≟-Relevance_ _≟-Arg-info_ _≟-Pattern_ _≟-ArgPatterns_ _≟-Lit_ = Literal._≟_ {-# WARNING_ON_USAGE _≟-Lit_ "Warning: _≟-Lit_ was deprecated in v1.3. Please use Reflection.Literal's _≟_ instead." #-} _≟-Name_ = Name._≟_ {-# WARNING_ON_USAGE _≟-Name_ "Warning: _≟-Name_ was deprecated in v1.3. Please use Reflection.Name's _≟_ instead." #-} _≟-Meta_ = Meta._≟_ {-# WARNING_ON_USAGE _≟-Meta_ "Warning: _≟-Meta_ was deprecated in v1.3. Please use Reflection.Meta's _≟_ instead." #-} _≟-Visibility_ = Visibility._≟_ {-# WARNING_ON_USAGE _≟-Visibility_ "Warning: _≟-Visibility_ was deprecated in v1.3. Please use Reflection.Argument.Visibility's _≟_ instead." #-} _≟-Relevance_ = Relevance._≟_ {-# WARNING_ON_USAGE _≟-Relevance_ "Warning: _≟-Relevance_ was deprecated in v1.3. Please use Reflection.Argument.Relevance's _≟_ instead." #-} _≟-Arg-info_ = Information._≟_ {-# WARNING_ON_USAGE _≟-Arg-info_ "Warning: _≟-Arg-info_ was deprecated in v1.3. Please use Reflection.Argument.Information's _≟_ instead." #-} _≟-Pattern_ = Pattern._≟_ {-# WARNING_ON_USAGE _≟-Pattern_ "Warning: _≟-Pattern_ was deprecated in v1.3. Please use Reflection.Pattern's _≟_ instead." #-} _≟-ArgPatterns_ = Pattern._≟s_ {-# WARNING_ON_USAGE _≟-ArgPatterns_ "Warning: _≟-ArgPatterns_ was deprecated in v1.3. Please use Reflection.Pattern's _≟s_ instead." #-} map-Abs = Abstraction.map {-# WARNING_ON_USAGE map-Abs "Warning: map-Abs was deprecated in v1.3. Please use Reflection.Abstraction's map instead." #-} map-Arg = Argument.map {-# WARNING_ON_USAGE map-Arg "Warning: map-Arg was deprecated in v1.3. Please use Reflection.Argument's map instead." #-} map-Args = Argument.map-Args {-# WARNING_ON_USAGE map-Args "Warning: map-Args was deprecated in v1.3. Please use Reflection.Argument's map-Args instead." #-} visibility = Information.visibility {-# WARNING_ON_USAGE visibility "Warning: visibility was deprecated in v1.3. Please use Reflection.Argument.Information's visibility instead." #-} relevance = Information.relevance {-# WARNING_ON_USAGE relevance "Warning: relevance was deprecated in v1.3. Please use Reflection.Argument.Information's relevance instead." #-} infix 4 _≟-AbsTerm_ _≟-AbsType_ _≟-ArgTerm_ _≟-ArgType_ _≟-Args_ _≟-Clause_ _≟-Clauses_ _≟_ _≟-Sort_ _≟-AbsTerm_ = Term._≟-AbsTerm_ {-# WARNING_ON_USAGE _≟-AbsTerm_ "Warning: _≟-AbsTerm_ was deprecated in v1.3. Please use Reflection.Term's _≟-AbsTerm_ instead." #-} _≟-AbsType_ = Term._≟-AbsType_ {-# WARNING_ON_USAGE _≟-AbsType_ "Warning: _≟-AbsType_ was deprecated in v1.3. Please use Reflection.Term's _≟-AbsType_ instead." #-} _≟-ArgTerm_ = Term._≟-ArgTerm_ {-# WARNING_ON_USAGE _≟-ArgTerm_ "Warning: _≟-ArgTerm_ was deprecated in v1.3. Please use Reflection.Term's _≟-ArgTerm_ instead." #-} _≟-ArgType_ = Term._≟-ArgType_ {-# WARNING_ON_USAGE _≟-ArgType_ "Warning: _≟-ArgType_ was deprecated in v1.3. Please use Reflection.Term's _≟-ArgType_ instead." #-} _≟-Args_ = Term._≟-Args_ {-# WARNING_ON_USAGE _≟-Args_ "Warning: _≟-Args_ was deprecated in v1.3. Please use Reflection.Term's _≟-Args_ instead." #-} _≟-Clause_ = Term._≟-Clause_ {-# WARNING_ON_USAGE _≟-Clause_ "Warning: _≟-Clause_ was deprecated in v1.3. Please use Reflection.Term's _≟-Clause_ instead." #-} _≟-Clauses_ = Term._≟-Clauses_ {-# WARNING_ON_USAGE _≟-Clauses_ "Warning: _≟-Clauses_ was deprecated in v1.3. Please use Reflection.Term's _≟-Clauses_ instead." #-} _≟_ = Term._≟_ {-# WARNING_ON_USAGE _≟_ "Warning: _≟_ was deprecated in v1.3. Please use Reflection.Term's _≟_ instead." #-} _≟-Sort_ = Term._≟-Sort_ {-# WARNING_ON_USAGE _≟-Sort_ "Warning: _≟-Sort_ was deprecated in v1.3. Please use Reflection.Term's _≟-Sort_ instead." #-}
27.834008
75
0.675636
a18a90536af0171cc7e14e8cf0a574c1be7e24d8
9,738
agda
Agda
src/Categories/Bicategory/Construction/LaxSlice.agda
maxsnew/agda-categories
8f3c844d929508040dfa21f681fa260056214b73
[ "MIT" ]
null
null
null
src/Categories/Bicategory/Construction/LaxSlice.agda
maxsnew/agda-categories
8f3c844d929508040dfa21f681fa260056214b73
[ "MIT" ]
null
null
null
src/Categories/Bicategory/Construction/LaxSlice.agda
maxsnew/agda-categories
8f3c844d929508040dfa21f681fa260056214b73
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- Mentioned in passing here: -- https://ncatlab.org/nlab/show/slice+2-category open import Categories.Bicategory using (Bicategory) module Categories.Bicategory.Construction.LaxSlice {o ℓ e t} (𝒞 : Bicategory o ℓ e t) where open import Data.Product using (_,_) open import Function using (_$_) open import Level using (_⊔_) open import Categories.Bicategory.Extras 𝒞 open Shorthands open import Categories.Category using () renaming (Category to 1Category) open import Categories.Functor using (Functor) open Functor using (F₀) open import Categories.Functor.Bifunctor using (Bifunctor) open import Categories.Functor.Construction.Constant using (const) import Categories.Morphism.Reasoning as MR open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; niHelper) record SliceObj (X : Obj) : Set (t ⊔ o) where constructor sliceobj field {Y} : Obj arr : Y ⇒₁ X module SliceHom (A : Obj) where record Slice⇒₁ (X Y : SliceObj A) : Set (o ⊔ ℓ) where constructor slicearr₁ private module X = SliceObj X module Y = SliceObj Y field {h} : X.Y ⇒₁ Y.Y Δ : X.arr ⇒₂ (Y.arr ∘₁ h) record Slice⇒₂ {X Y : SliceObj A} (J K : Slice⇒₁ X Y) : Set (ℓ ⊔ e) where constructor slicearr₂ private module Y = SliceObj Y module J = Slice⇒₁ J module K = Slice⇒₁ K field {ϕ} : J.h ⇒₂ K.h E : K.Δ ≈ (Y.arr ▷ ϕ ∘ᵥ J.Δ) _∘ᵥ/_ : ∀ {X Y : SliceObj A}{J K L : Slice⇒₁ X Y} → Slice⇒₂ K L → Slice⇒₂ J K → Slice⇒₂ J L _∘ᵥ/_ {X}{Y}{J}{K}{L} (slicearr₂ {ϕ = ϕ} E) (slicearr₂ {ϕ = ψ} F) = slicearr₂ {ϕ = ϕ ∘ᵥ ψ} $ begin L.Δ ≈⟨ E ⟩ (Y.arr ▷ ϕ ∘ᵥ K.Δ) ≈⟨ refl⟩∘⟨ F ⟩ Y.arr ▷ ϕ ∘ᵥ (Y.arr ▷ ψ ∘ᵥ J.Δ) ≈⟨ pullˡ ∘ᵥ-distr-▷ ⟩ Y.arr ▷ (ϕ ∘ᵥ ψ) ∘ᵥ J.Δ ∎ where module X = SliceObj X module Y = SliceObj Y module J = Slice⇒₁ J module K = Slice⇒₁ K module L = Slice⇒₁ L open 1Category (hom X.Y A) open HomReasoning open Equiv open MR (hom X.Y A) SliceHomCat : SliceObj A → SliceObj A → 1Category (o ⊔ ℓ) (ℓ ⊔ e) e SliceHomCat X Y = record { Obj = Slice⇒₁ X Y ; _⇒_ = Slice⇒₂ ; _≈_ = λ (slicearr₂ {ϕ} _) (slicearr₂ {ψ} _) → ϕ ≈ ψ ; id = slice-id _ ; _∘_ = _∘ᵥ/_ ; assoc = hom.assoc ; sym-assoc = hom.sym-assoc ; identityˡ = hom.identityˡ ; identityʳ = hom.identityʳ ; identity² = hom.identity² ; equiv = record { refl = refl ; sym = sym ; trans = trans } ; ∘-resp-≈ = hom.∘-resp-≈ } where open hom.Equiv module X = SliceObj X module Y = SliceObj Y slice-id : ∀ (J : Slice⇒₁ X Y) → Slice⇒₂ J J slice-id J = slicearr₂ $ begin J.Δ ≈˘⟨ identity₂ˡ ⟩ id₂ ∘ᵥ J.Δ ≈˘⟨ ▷id₂ ⟩∘⟨refl ⟩ (Y.arr ▷ id₂) ∘ J.Δ ∎ where module J = Slice⇒₁ J open 1Category (hom X.Y A) open HomReasoning _⊚₀/_ : ∀ {X Y Z : SliceObj A} → Slice⇒₁ Y Z → Slice⇒₁ X Y → Slice⇒₁ X Z _⊚₀/_ {X}{Y}{Z} J K = slicearr₁ ((α⇒ ∘ᵥ J.Δ ◁ K.h) ∘ᵥ K.Δ) where module K = Slice⇒₁ K module J = Slice⇒₁ J _⊚₁/_ : ∀ {X Y Z : SliceObj A} → {J J' : Slice⇒₁ Y Z} → {K K' : Slice⇒₁ X Y} → Slice⇒₂ J J' → Slice⇒₂ K K' → Slice⇒₂ (J ⊚₀/ K) (J' ⊚₀/ K') _⊚₁/_ {X}{Y}{Z}{J'}{J}{K'}{K} δ γ = slicearr₂ $ begin (α⇒ ∘ᵥ J.Δ ◁ K.h) ∘ᵥ K.Δ ≈⟨ (refl⟩∘⟨ γ.E) ⟩ (α⇒ ∘ᵥ J.Δ ◁ K.h) ∘ᵥ (Y.arr ▷ γ.ϕ ∘ᵥ K'.Δ) ≈⟨ ((refl⟩∘⟨ δ.E ⟩⊚⟨refl) ⟩∘⟨refl) ⟩ (α⇒ ∘ᵥ (Z.arr ▷ δ.ϕ ∘ᵥ J'.Δ) ◁ K.h) ∘ᵥ (Y.arr ▷ γ.ϕ ∘ᵥ K'.Δ) ≈˘⟨ (((refl⟩∘⟨ ∘ᵥ-distr-◁ ) ⟩∘⟨refl)) ⟩ (α⇒ ∘ᵥ ((Z.arr ▷ δ.ϕ) ◁ K.h ∘ᵥ J'.Δ ◁ K.h)) ∘ᵥ (Y.arr ▷ γ.ϕ ∘ᵥ K'.Δ) ≈⟨ pullʳ (center (sym ◁-▷-exchg)) ⟩ α⇒ ∘ᵥ (Z.arr ▷ δ.ϕ) ◁ K.h ∘ᵥ (Z.arr ⊚₀ J'.h ▷ γ.ϕ ∘ᵥ J'.Δ ◁ K'.h) ∘ᵥ K'.Δ ≈⟨ pushʳ ( pullˡ (pullˡ (sym ⊚.homomorphism)) ) ⟩ (α⇒ ∘ᵥ (Z.arr ▷ δ.ϕ ∘ᵥ id₂) ⊚₁ (id₂ ∘ᵥ γ.ϕ) ∘ᵥ J'.Δ ◁ K'.h) ∘ᵥ K'.Δ ≈⟨ ((refl⟩∘⟨ (identity₂ʳ ⟩⊚⟨ identity₂ˡ ⟩∘⟨refl)) ⟩∘⟨refl) ⟩ (α⇒ ∘ᵥ ((Z.arr ▷ δ.ϕ) ⊚₁ γ.ϕ) ∘ᵥ J'.Δ ◁ K'.h) ∘ᵥ K'.Δ ≈⟨ pushˡ (pullˡ (⊚-assoc.⇒.commute ((id₂ , δ.ϕ) , γ.ϕ))) ⟩ (Z.arr ▷ δ.ϕ ⊚₁ γ.ϕ ∘ᵥ α⇒) ∘ᵥ J'.Δ ◁ K'.h ∘ᵥ K'.Δ ≈⟨ pullʳ (sym assoc) ⟩ (Z.arr ▷ δ.ϕ ⊚₁ γ.ϕ) ∘ᵥ ((α⇒ ∘ᵥ J'.Δ ◁ K'.h) ∘ᵥ K'.Δ) ∎ where module X = SliceObj X module Y = SliceObj Y module Z = SliceObj Z module J = Slice⇒₁ J module J' = Slice⇒₁ J' module K = Slice⇒₁ K module K' = Slice⇒₁ K' module γ = Slice⇒₂ γ module δ = Slice⇒₂ δ open 1Category (hom X.Y A) open HomReasoning open MR (hom X.Y A) open Equiv id/ : ∀ {X : SliceObj A} → Slice⇒₁ X X id/ = slicearr₁ ρ⇐ _⊚/_ : ∀ {X Y Z : SliceObj A} → Bifunctor (SliceHomCat Y Z) (SliceHomCat X Y) (SliceHomCat X Z) _⊚/_ {X}{Y}{Z} = record { F₀ = λ (J , K) → J ⊚₀/ K ; F₁ = λ (δ , γ) → δ ⊚₁/ γ ; identity = ⊚.identity ; homomorphism = ⊚.homomorphism ; F-resp-≈ = ⊚.F-resp-≈ } where module X = SliceObj X module Y = SliceObj Y module Z = SliceObj Z α⇒/ : ∀ {W X Y Z}(J : Slice⇒₁ Y Z) (K : Slice⇒₁ X Y) (L : Slice⇒₁ W X) → Slice⇒₂ ((J ⊚₀/ K) ⊚₀/ L) (J ⊚₀/ (K ⊚₀/ L)) α⇒/ {W}{X}{Y}{Z} J K L = slicearr₂ $ begin (α⇒ ∘ᵥ J.Δ ◁ K.h ⊚₀ L.h) ∘ᵥ ((α⇒ ∘ᵥ K.Δ ◁ L.h) ∘ᵥ L.Δ ) ≈⟨ pullʳ (center⁻¹ (sym α⇒-◁-∘₁) refl) ⟩ α⇒ ∘ᵥ (α⇒ ∘ᵥ J.Δ ◁ K.h ◁ L.h) ∘ᵥ K.Δ ◁ L.h ∘ᵥ L.Δ ≈⟨ pullˡ (pullˡ (sym pentagon)) ⟩ ((Z.arr ▷ α⇒ ∘ᵥ α⇒ ∘ᵥ α⇒ ◁ L.h) ∘ᵥ J.Δ ◁ K.h ◁ L.h) ∘ᵥ (K.Δ ◁ L.h ∘ᵥ L.Δ) ≈⟨ pullˡ (pushˡ (pull-last ∘ᵥ-distr-◁ )) ⟩ (Z.arr ▷ α⇒ ∘ᵥ (α⇒ ∘ᵥ ((α⇒ ∘ᵥ J.Δ ◁ K.h) ◁ L.h)) ∘ᵥ K.Δ ◁ L.h) ∘ᵥ L.Δ ≈⟨ pushˡ (pushʳ (pullʳ ∘ᵥ-distr-◁)) ⟩ ((Z.arr ▷ α⇒ ∘ᵥ α⇒)) ∘ᵥ (((α⇒ ∘ᵥ J.Δ ◁ K.h) ∘ᵥ K.Δ) ◁ L.h) ∘ᵥ L.Δ ≈⟨ pullʳ (pushʳ refl) ⟩ Z.arr ▷ α⇒ ∘ᵥ ((α⇒ ∘ᵥ (((α⇒ ∘ᵥ J.Δ ◁ K.h)) ∘ᵥ K.Δ) ◁ L.h) ∘ᵥ L.Δ) ∎ where module W = SliceObj W module X = SliceObj X module Y = SliceObj Y module Z = SliceObj Z module J = Slice⇒₁ J module K = Slice⇒₁ K module L = Slice⇒₁ L open 1Category (hom W.Y A) open HomReasoning open MR (hom W.Y A) open hom.Equiv λ⇒/ : ∀ {X Y} (J : Slice⇒₁ X Y) → Slice⇒₂ (id/ ⊚₀/ J) J λ⇒/ {X}{Y} J = slicearr₂ $ begin J.Δ ≈⟨ introˡ id₂◁ ⟩ (id₂ ◁ J.h) ∘ᵥ J.Δ ≈˘⟨ (unitʳ.iso.isoʳ (Y.arr , _) ⟩⊚⟨refl ⟩∘⟨refl) ⟩ ((ρ⇒ ∘ᵥ ρ⇐) ◁ J.h) ∘ᵥ J.Δ ≈˘⟨ (∘ᵥ-distr-◁ ⟩∘⟨refl) ⟩ (ρ⇒ ◁ J.h ∘ᵥ ρ⇐ ◁ J.h) ∘ᵥ J.Δ ≈⟨ pushˡ (sym triangle ⟩∘⟨ refl) ⟩ (Y.arr ▷ λ⇒ ∘ᵥ α⇒) ∘ᵥ ρ⇐ ◁ J.h ∘ᵥ J.Δ ≈⟨ pullʳ (sym assoc) ⟩ Y.arr ▷ λ⇒ ∘ᵥ (α⇒ ∘ᵥ ρ⇐ ◁ J.h) ∘ᵥ J.Δ ∎ where module X = SliceObj X module Y = SliceObj Y module J = Slice⇒₁ J open 1Category (hom X.Y A) open HomReasoning open MR (hom X.Y A) open hom.Equiv ρ⇒/ : ∀{X}{Y} (J : Slice⇒₁ X Y) → Slice⇒₂ (J ⊚₀/ id/) J ρ⇒/ {X}{Y} J = slicearr₂ $ begin J.Δ ≈⟨ introʳ (unitʳ.iso.isoʳ _) ⟩ J.Δ ∘ᵥ ρ⇒ ∘ᵥ ρ⇐ ≈⟨ pullˡ (sym ρ⇒-∘ᵥ-◁) ⟩ (ρ⇒ ∘ᵥ J.Δ ◁ id₁) ∘ᵥ ρ⇐ ≈⟨ unitorʳ-coherence ⟩∘⟨refl ⟩∘⟨refl ⟩ ((Y.arr ▷ ρ⇒ ∘ᵥ α⇒) ∘ᵥ J.Δ ◁ id₁) ∘ᵥ ρ⇐ ≈⟨ pushˡ assoc ⟩ Y.arr ▷ ρ⇒ ∘ᵥ (α⇒ ∘ᵥ J.Δ ◁ id₁) ∘ᵥ ρ⇐ ∎ where module X = SliceObj X module Y = SliceObj Y module J = Slice⇒₁ J open 1Category (hom X.Y A) open HomReasoning open MR (hom X.Y A) open hom.Equiv slice-inv : ∀ {X}{Y}{J : Slice⇒₁ X Y}{K} (α : Slice⇒₂ J K) → (f : Slice⇒₁.h K ⇒₂ Slice⇒₁.h J) → (f ∘ᵥ (Slice⇒₂.ϕ α) ≈ id₂) → Slice⇒₂ K J slice-inv {X}{Y}{J}{K} α f p = slicearr₂ $ begin J.Δ ≈⟨ introˡ ▷id₂ ⟩ (Y.arr ▷ id₂) ∘ᵥ J.Δ ≈˘⟨ (refl⟩⊚⟨ p ⟩∘⟨refl) ⟩ (Y.arr ▷ (f ∘ᵥ α.ϕ)) ∘ᵥ J.Δ ≈˘⟨ (∘ᵥ-distr-▷ ⟩∘⟨refl) ⟩ (Y.arr ▷ f ∘ᵥ Y.arr ▷ α.ϕ) ∘ᵥ J.Δ ≈⟨ pullʳ (sym α.E) ⟩ Y.arr ▷ f ∘ᵥ K.Δ ∎ where module X = SliceObj X module Y = SliceObj Y module J = Slice⇒₁ J module K = Slice⇒₁ K module α = Slice⇒₂ α open 1Category (hom X.Y A) open HomReasoning open MR (hom X.Y A) open hom.Equiv LaxSlice : Obj → Bicategory (o ⊔ ℓ) (ℓ ⊔ e) e (o ⊔ t) LaxSlice A = record { enriched = record { Obj = SliceObj A ; hom = SliceHomCat ; id = const id/ ; ⊚ = _⊚/_ ; ⊚-assoc = niHelper (record { η = λ ((J , K) , L) → α⇒/ J K L ; η⁻¹ = λ ((J , K) , L) → slice-inv (α⇒/ J K L) α⇐ (⊚-assoc.iso.isoˡ _) ; commute = λ f → ⊚-assoc.⇒.commute _ ; iso = λ _ → record { isoˡ = ⊚-assoc.iso.isoˡ _ ; isoʳ = ⊚-assoc.iso.isoʳ _ } }) ; unitˡ = niHelper (record { η = λ (_ , J) → λ⇒/ J ; η⁻¹ = λ (_ , J) → slice-inv (λ⇒/ J) λ⇐ (unitˡ.iso.isoˡ _) ; commute = λ _ → λ⇒-∘ᵥ-▷ ; iso = λ _ → record { isoˡ = unitˡ.iso.isoˡ _ ; isoʳ = unitˡ.iso.isoʳ _ } }) ; unitʳ = niHelper (record { η = λ (J , _) → ρ⇒/ J ; η⁻¹ = λ (J , _) → slice-inv (ρ⇒/ J) ρ⇐ (unitʳ.iso.isoˡ _) ; commute = λ _ → ρ⇒-∘ᵥ-◁ ; iso = λ _ → record { isoˡ = unitʳ.iso.isoˡ _ ; isoʳ = unitʳ.iso.isoʳ _ } }) } ; triangle = triangle ; pentagon = pentagon } where open SliceHom A
40.074074
140
0.463237
c54027ed98195706bee262dcca64d930393d7ba5
23,242
agda
Agda
setoid_rr.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2018-06-21T08:39:01.000Z
2022-01-17T16:13:53.000Z
setoid_rr.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
null
null
null
setoid_rr.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2022-01-26T14:55:51.000Z
2022-02-15T19:42:19.000Z
{-# OPTIONS --rewriting --prop --confluence-check #-} open import Agda.Primitive open import Agda.Builtin.Bool open import Agda.Builtin.Nat open import Agda.Builtin.List open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite open import Agda.Builtin.Sigma open import Agda.Builtin.Unit open import Data.Vec.Base open import Data.Bool open import Data.Sum -- sigma type in Prop used to handle telescopes. record Tel {a b} (A : Prop a) (B : A → Prop b) : Prop (a ⊔ b) where constructor _,_ field fstC : A sndC : B fstC open Tel public infixr 4 _,_ record ΣCov {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where constructor _,_ field fstCov : A sndCov : B fstCov open ΣCov public record prod {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where constructor _,_ field fstprod : A sndprod : B open prod public variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level -- a bit of boilerplate to deal with Prop data ⊥ : Prop where record ⊤P : Prop ℓ where constructor ttP record Box (A : Prop ℓ) : Set ℓ where constructor box field unbox : A open Box public _×_ : ∀ (A : Prop ℓ) (B : Prop ℓ₁) → Prop (ℓ ⊔ ℓ₁) A × B = Tel A (λ _ → B) -- we need this for cumulativity record i (A : Prop ℓ) : Prop (ℓ ⊔ ℓ₁) where constructor inj field uninj : A open i public record iS (A : Set ℓ) : Set (ℓ ⊔ ℓ₁) where constructor inj field uninj : A open iS public {- Axiomatisation of Id, Id-refl, transport (for proposition), cast Note that Id-refl, transport are axioms in Prop, so we don't need to give them a computation content. Also transport-refl is useless for transport on Prop -} postulate Id : (A : Set ℓ) → A → A → Prop ℓ postulate cast : (A B : Set ℓ) (e : Id (Set ℓ) A B) → A → B postulate Id-refl : {A : Set ℓ} (x : A) → Id A x x postulate cast-refl : {A : Set ℓ} (e : Id _ A A) (a : A) → Id A (cast A A e a) a postulate transport : {A : Set ℓ} (P : A → Prop ℓ₁) (x : A) (t : P x) (y : A) (e : Id A x y) → P y -- cast-refl' : {A : Set ℓ} (e : Id (Set ℓ) A A) (a : A) → Id A (cast A A e a) a -- cast-refl' {A = A} e a = transport (λ z → Id A z a) {!!} (Id-refl a) {!!} {!!} -- direct derived functions ap : {A : Set ℓ} {B : Set ℓ₁} {x y : A} (f : A → B) (e : Id A x y) → Id B (f x) (f y) ap {ℓ} {ℓ₁} {A} {B} {x} {y} f e = transport (λ z → Id B (f x) (f z)) x (Id-refl _) y e transport-Id : {A : Set ℓ} (P : A → Set ℓ₁) (x : A) (t : P x) (y : A) (e : Id A x y) → P y transport-Id P x t y e = cast (P x) (P y) (ap P e) t transport-refl : {A : Set ℓ} (P : A → Set ℓ₁) (x : A) (t : P x) (e : Id A x x) → Id _ (transport-Id P x t x e) t transport-refl P x t e = cast-refl (ap P e) t inverse : (A : Set ℓ) {x y : A} (p : Id {ℓ} A x y) → Id A y x inverse A {x} {y} p = transport (λ z → Id A z x) x (Id-refl x) y p concatId : (A : Set ℓ) {x y z : A} (p : Id {ℓ} A x y) (q : Id {ℓ} A y z) → Id A x z concatId A {x} {y} {z} p q = transport (λ t → Id A x t) y p z q -- we now state rewrite rules for the identity type postulate Id-Pi : (A : Set ℓ) (B : A → Set ℓ₁) (f g : (a : A) → B a) → Id ((a : A) → B a) f g ≡ ((a : A) → Id (B a) (f a) (g a)) {-# REWRITE Id-Pi #-} -- rewrite rules on Id-refl are not needed because it is in Prop refl-Pi : (A : Set ℓ) (B : A → Set ℓ₁) (f : (a : A) → B a) → box (Id-refl f) ≡ box (λ a → Id-refl (f a)) refl-Pi A B f = refl -- sanity check for funext funext : (A : Set ℓ) (B : A → Set ℓ₁) (f g : (a : A) → B a) → ((a : A) → Id (B a) (f a) (g a)) → Id ((a : A) → B a) f g funext A B f g e = e postulate Id-Sigma : (A : Set ℓ) (B : A → Set ℓ₁) (a a' : A) (b : B a) (b' : B a') → Id (Σ A B) (a , b) (a' , b') ≡ Tel (Id A a a') (λ e → Id (B a') (transport-Id B a b a' e) b') {-# REWRITE Id-Sigma #-} postulate Id-SigmaCov : (A : Set ℓ) (B : A → Set ℓ₁) (a a' : A) (b : B a) (b' : B a') → Id (ΣCov A B) (a , b) (a' , b') ≡ Tel (Id A a a') (λ e → Id (B a) b (transport-Id B a' b' a (inverse A e))) {-# REWRITE Id-SigmaCov #-} postulate Id-prod : (A : Set ℓ) (B : Set ℓ₁) (a a' : A) (b b' : B) → Id (prod A B) (a , b) (a' , b') ≡ (Id A a a') × (Id B b b') {-# REWRITE Id-prod #-} postulate Id-Box : (A : Prop ℓ) (p q : A) → Id (Box A) (box p) (box q) ≡ ⊤P {-# REWRITE Id-Box #-} postulate Id-Unit : (p q : ⊤) → Id ⊤ p q ≡ ⊤P {-# REWRITE Id-Unit #-} postulate Id-list-nil-nil : (A : Set ℓ) → Id (List A) [] [] ≡ ⊤P -- postulate Id-list-nil-cons : (A : Set ℓ) (a' : A) (l' : List A) → -- Id (List A) [] (a' ∷ l') ≡ i ⊥ -- postulate Id-list-cons-nil : (A : Set ℓ) (a : A) (l : List A) → -- Id (List A) (a ∷ l) [] ≡ i ⊥ postulate Id-list-cons-cons : (A : Set ℓ) (a a' : A) (l l' : List A) → Id (List A) (a ∷ l) (a' ∷ l') ≡ Id A a a' × Id (List A) l l' {-# REWRITE Id-list-nil-nil #-} {-# REWRITE Id-list-cons-cons #-} postulate Id-nat-zero-zero : Id Nat 0 0 ≡ ⊤P -- postulate Id-nat-zero-suc : (n : Nat) → -- Id Nat 0 (suc n) ≡ i ⊥ -- postulate Id-nat-suc-zero : (n : Nat) → -- Id Nat (suc n) zero ≡ i ⊥ postulate Id-nat-suc-suc : (n n' : Nat) → Id Nat (suc n) (suc n') ≡ Id Nat n n' {-# REWRITE Id-nat-zero-zero #-} {-# REWRITE Id-nat-suc-suc #-} postulate Id-bool-true-true : Id Bool true true ≡ ⊤P postulate Id-bool-false-false : Id Bool false false ≡ ⊤P {-# REWRITE Id-bool-true-true #-} {-# REWRITE Id-bool-false-false #-} postulate Id-sum-inj₁-inj₁ : (A : Set ℓ) (B : Set ℓ₁) (a a' : A) → Id (A ⊎ B) (inj₁ a) (inj₁ a') ≡ i {ℓ = ℓ} {ℓ₁ = ℓ₁} (Id A a a') postulate Id-sum-inj₂-inj₂ : (A : Set ℓ) (B : Set ℓ₁) (b b' : B) → Id (A ⊎ B) (inj₂ b) (inj₂ b') ≡ i {ℓ = ℓ₁} {ℓ₁ = ℓ} (Id B b b') {-# REWRITE Id-sum-inj₁-inj₁ #-} {-# REWRITE Id-sum-inj₂-inj₂ #-} -- rewrite rules for the identity type on the universe telescope-Sigma : Set (lsuc (ℓ ⊔ ℓ₁)) telescope-Sigma {ℓ} {ℓ₁} = ΣCov (Set ℓ) (λ A → A → Set ℓ₁) postulate Id-Type-Sigma : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) → Id (Set (ℓ ⊔ ℓ₁)) (Σ A B) (Σ A' B') ≡ Id telescope-Sigma (A , B) (A' , B') {-# REWRITE Id-Type-Sigma #-} telescope-Forall : Set (lsuc (ℓ ⊔ ℓ₁)) telescope-Forall {ℓ} {ℓ₁} = Σ (Set ℓ) (λ A → A → Set ℓ₁) postulate Id-Type-Pi : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) → Id (Set (ℓ ⊔ ℓ₁)) ((a : A) → B a) ((a' : A') → B' a') ≡ Id telescope-Forall (A , B) (A' , B') {-# REWRITE Id-Type-Pi #-} telescope-Sum : Set (lsuc (ℓ ⊔ ℓ₁)) telescope-Sum {ℓ} {ℓ₁} = Σ (Set ℓ) (λ _ → Set ℓ₁) postulate Id-Type-Sum : (A A' : Set ℓ) (B B' : Set ℓ₁) → Id (Set (ℓ ⊔ ℓ₁)) (A ⊎ B) (A' ⊎ B') ≡ Id telescope-Sum (A , B) (A' , B') {-# REWRITE Id-Type-Sum #-} postulate Id-Type-prod : (A A' : Set ℓ) (B B' : Set ℓ₁) → Id (Set (ℓ ⊔ ℓ₁)) (prod A B) (prod A' B') ≡ Id telescope-Sum (A , B) (A' , B') {-# REWRITE Id-Type-prod #-} telescope-List : Set (lsuc ℓ) telescope-List {ℓ} = Set ℓ postulate Id-Type-List : (A A' : Set ℓ) → Id (Set ℓ) (List A) (List A') ≡ Id telescope-List A A' {-# REWRITE Id-Type-List #-} postulate Id-Type-Unit : Id Set ⊤ ⊤ ≡ ⊤P {-# REWRITE Id-Type-Unit #-} postulate Id-Type-Nat : Id Set Nat Nat ≡ Id Set ⊤ ⊤ {-# REWRITE Id-Type-Nat #-} postulate Id-Type-Bool : Id Set Bool Bool ≡ Id Set ⊤ ⊤ {-# REWRITE Id-Type-Bool #-} telescope-Box : Set (lsuc ℓ) telescope-Box {ℓ} = Prop ℓ postulate Id-Type-Box : (P P' : Prop ℓ) → Id (Set ℓ) (Box P) (Box P') ≡ Id telescope-Box P P' {-# REWRITE Id-Type-Box #-} -- rewrite rules for the identity type on Prop : Prop ext modulo cumul postulate Id-prop : (P Q : Prop ℓ) → Id (Prop ℓ) P Q ≡ i (P → Q) × (Q → P) {-# REWRITE Id-prop #-} postulate Id-set : Id (Set (lsuc ℓ₁)) (Set ℓ₁) (Set ℓ₁) ≡ ⊤P {-# REWRITE Id-set #-} -- non-diagonal cases {- There are n^2 cases, that's a pain, this is not exhaustive for the moment -} postulate Id-set-nat : Id _ (Set ℓ) (iS Nat) ≡ i ⊥ postulate Id-nat-set : Id (Set (lsuc ℓ)) (iS Nat) (Set ℓ) ≡ i ⊥ postulate Id-set-bool : Id _ (Set ℓ) (iS Bool) ≡ i ⊥ postulate Id-bool-set : Id (Set (lsuc ℓ)) (iS Bool) (Set ℓ) ≡ i ⊥ postulate Id-bool-nat : Id _ Bool Nat ≡ i ⊥ postulate Id-nat-bool : Id _ Nat Bool ≡ i ⊥ postulate Id-set-pi : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ)) (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} ((a : A) → B a)) ≡ i ⊥ postulate Id-pi-set : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} ((a : A) → B a)) (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ)) ≡ i ⊥ postulate Id-set-sigma : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ)) (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Σ A B)) ≡ i ⊥ postulate Id-sigma-set : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Σ A B)) (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ)) ≡ i ⊥ {-# REWRITE Id-set-nat Id-nat-set Id-set-bool Id-bool-set Id-bool-nat Id-nat-bool Id-set-pi Id-pi-set Id-set-sigma Id-sigma-set #-} --- Contractibility of singletons and J can be defined contr-sing : (A : Set ℓ) {x y : A} (p : Id {ℓ} A x y) → Id (Σ A (λ y → Box (Id A x y))) (x , box (Id-refl x)) (y , box p) contr-sing A {x} {y} p = p , ttP J : (A : Set ℓ) (x : A) (P : (y : A) → Id A x y → Prop ℓ₁) (t : P x (Id-refl x)) (y : A) (e : Id A x y) → P y e J A x P t y e = transport (λ z → P (fst z) (unbox (snd z))) (x , box (Id-refl x)) t (y , box e) (contr-sing A e) -- tranporting back and forth is the identity -- cast-inv : (A B : Set ℓ) (e : Id _ A B) (a : A) → -- Id A (cast B A (inverse (Set ℓ) {x = A} {y = B} e) (cast A B e a)) a -- cast-inv {ℓ} A B e a = let e-refl = cast-refl (Id-refl A) a in -- let e-refl-cast = cast-refl (Id-refl A) (cast A A (Id-refl A) a) in -- J (Set ℓ) A (λ B e → Id A (cast B A (inverse (Set ℓ) {x = A} {y = B} e) (cast A B e a)) a) -- (concatId A e-refl-cast e-refl) B e postulate cast-set : (A : Set ℓ) (e : _) → cast (Set ℓ) (Set ℓ) e A ≡ A {-# REWRITE cast-set #-} postulate cast-prop : (A : Prop ℓ) (e : _) → cast (Prop ℓ) (Prop ℓ) e A ≡ A {-# REWRITE cast-prop #-} postulate cast-type-family : (A A' : Set ℓ) (f : (a : A) → Set ℓ₁) (e : _) → cast ((a : A) → Set ℓ₁) ((a' : A') → Set ℓ₁) e f ≡ λ (a' : A') → let a = cast A' A (inverse (Set ℓ) {x = A} {y = A'} (fstC e)) a' in f a {-# REWRITE cast-type-family #-} postulate cast-Pi : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) (f : (a : A) → B a) (e : Id _ ((a : A) → B a) ((a' : A') → B' a')) → cast ((a : A) → B a) ((a' : A') → B' a') e f ≡ λ (a' : A') → let a = cast A' A (inverse (Set ℓ) {x = A} {y = A'} (fstC e)) a' in cast _ _ (sndC e a') (f a) {-# REWRITE cast-Pi #-} postulate cast-Sigma : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) (x : A) (y : B x) (e : _) → let eA = fstC e in let x' = cast A A' eA x in let eB = sndC e x in cast (Σ A B) (Σ A' B') e (x , y) ≡ (cast A A' eA x , cast (B x) (B' x') eB y) {-# REWRITE cast-Sigma #-} postulate cast-prod : (A A' : Set ℓ) (B B' : Set ℓ₁) (x : A) (y : B) (e : _) → let eA = fstC e in let eB = sndC e in cast (prod A B) (prod A' B') e (x , y) ≡ (cast A A' eA x , cast B B' eB y) {-# REWRITE cast-prod #-} postulate cast-Sum-inj₁ : (A A' : Set ℓ) (B B' : Set ℓ₁) (a : A) (e : _) → let eA = fstC e in let eB = sndC e in cast (A ⊎ B) (A' ⊎ B') e (inj₁ a) ≡ inj₁ (cast A A' eA a) postulate cast-Sum-inj₂ : (A A' : Set ℓ) (B B' : Set ℓ₁) (b : B) (e : _) → let eA = fstC e in let eB = sndC e in cast (A ⊎ B) (A' ⊎ B') e (inj₂ b) ≡ inj₂ (cast B B' eB b) {-# REWRITE cast-Sum-inj₁ #-} {-# REWRITE cast-Sum-inj₂ #-} postulate cast-List-nil : (A A' : Set ℓ) (e : _) → cast (List A) (List A') e [] ≡ [] postulate cast-List-cons : (A A' : Set ℓ) (e : _) (a : A) (l : List A) → cast (List A) (List A') e (a ∷ l) ≡ cast A A' e a ∷ cast _ _ e l {-# REWRITE cast-List-nil #-} {-# REWRITE cast-List-cons #-} postulate cast-Nat : (e : _) (n : Nat) → cast Nat Nat e n ≡ n {-# REWRITE cast-Nat #-} postulate cast-Bool : (e : _) (b : Bool) → cast Bool Bool e b ≡ b {-# REWRITE cast-Bool #-} postulate cast-Unit : (e : _) (t : ⊤) → cast ⊤ ⊤ e t ≡ t {-# REWRITE cast-Unit #-} postulate cast-Box : (A A' : Prop ℓ) (a : A) (f : _) (g : _) → cast (Box A) (Box A') (f , g) (box a) ≡ box (uninj f a) {-# REWRITE cast-Box #-} -- sanity check on closed terms foo : transport-Id (λ (T : Σ Set (λ A → Σ A (λ _ → A → Set))) → ((snd (snd T)) (fst (snd T)))) (Nat , (0 , λ _ → Nat)) 3 (Nat , (0 , λ _ → Nat)) (Id-refl {A = Σ Set (λ A → Σ A (λ _ → A → Set))} (Nat , (0 , λ _ → Nat))) ≡ 3 foo = refl test-J-refl-on-closed-term : (X : Set ℓ) (x : X) → transport-Id (λ z → Σ ⊤ (λ z → ⊤)) x (tt , tt) x (Id-refl x) ≡ (tt , tt) test-J-refl-on-closed-term X x = refl -- Quotient types {- Note that r s and t are not used in the definitions, they are just here to make sure the theory stays consistent, because postulating the quotient, we can derive them. In particular, with R = λ - - → ⊥, we would get a direct inconsistency using Id-refl -} record quotient-data ℓ : Set (lsuc ℓ) where constructor q-data field carrier : Set ℓ rel : carrier → carrier → Prop ℓ rel-refl : (x : carrier) → rel x x rel-sym : (x y : carrier) → rel x y → rel y x rel-trans : (x y z : carrier) → rel x y → rel y z → rel x z open quotient-data public postulate Quotient : (Q : quotient-data ℓ) → Set ℓ postulate pi : {Q : quotient-data ℓ} → carrier Q → Quotient Q telescope-Quotient : Set (lsuc ℓ) telescope-Quotient {ℓ} = Σ (Set ℓ) (λ A → A → A → Prop ℓ) postulate Id-Quotient : (Q : quotient-data ℓ) (a a' : carrier Q) → Id (Quotient Q) (pi a) (pi a') ≡ rel Q a a' {-# REWRITE Id-Quotient #-} postulate Quotient-elim : (Q : quotient-data ℓ) (P : Quotient Q → Set ℓ₁) (p : (x : carrier Q) → P (pi x)) (e : (x y : carrier Q) → (r : rel Q x y) → Id _ (transport-Id P (pi x) (p x) (pi y) r) (p y)) (w : Quotient Q) → P w postulate Quotient-elim-red : (Q : quotient-data ℓ) (P : Quotient Q → Set ℓ₁) (p : (x : carrier Q) → P (pi x)) (e : (x y : carrier Q) → (r : rel Q x y) → Id _ (transport-Id P (pi x) (p x) (pi y) r) (p y)) (a : carrier Q) → Quotient-elim Q P p e (pi a) ≡ p a {-# REWRITE Quotient-elim-red #-} postulate Quotient-elim-prop : (Q : quotient-data ℓ) (P : Quotient Q → Prop ℓ₁) (p : (x : carrier Q) → P (pi x)) (w : Quotient Q) → P w postulate Id-Type-Quotient : (Q Q' : quotient-data ℓ) → Id (Set ℓ) (Quotient Q) (Quotient Q') ≡ Id telescope-Quotient (carrier Q , rel Q) (carrier Q' , rel Q') {-# REWRITE Id-Type-Quotient #-} postulate cast-Quotient : (Q Q' : quotient-data ℓ) (a : carrier Q) (e : _) → cast (Quotient Q) (Quotient Q') e (pi a) ≡ pi (cast (carrier Q) (carrier Q') (fstC e) a) {-# REWRITE cast-Quotient #-} -- double induction principle Quotient-elim2-aux : (Q : quotient-data ℓ) (P : Quotient Q → Quotient Q → Set ℓ₁) (p : (x y : carrier Q) → P (pi x) (pi y)) (e : (x x' y y' : carrier Q) → (Q-rel1 : rel Q x x') → (Q-rel2 : rel Q y y') → Id _ (transport-Id (P (pi x')) (pi y) (transport-Id (λ x → P x (pi y)) (pi x) (p x y) (pi x') Q-rel1) (pi y') Q-rel2) (p x' y')) (x : carrier Q) (w : Quotient Q) → P w (pi x) Quotient-elim2-aux Q P p e x = Quotient-elim Q (λ w → P w (pi x)) (λ y → p y x) (λ y y' r → let e-cst = e y y' x x r (rel-refl Q x) in transport (λ e → Id (P (pi y') (pi x)) (e (cast (P (pi y) (pi x)) (P (pi y') (pi x)) (ap (λ y → P y (pi x)) r) (p y x))) (p y' x)) (cast (P (pi y') (pi x)) (P (pi y') (pi x)) (ap (P (pi y')) (rel-refl Q x))) e-cst (λ w → w) λ a → cast-refl {A = P (pi y') (pi x)} (Id-refl (P (pi y') (pi x))) a ) Quotient-elim2 : (Q : quotient-data ℓ) (P : Quotient Q → Quotient Q → Set ℓ₁) (p : (x y : carrier Q) → P (pi x) (pi y)) (e : (x x' y y' : carrier Q) → (Q-rel1 : rel Q x x') → (Q-rel2 : rel Q y y') → Id _ (transport-Id (P (pi x')) (pi y) (transport-Id (λ x → P x (pi y)) (pi x) (p x y) (pi x') Q-rel1) (pi y') Q-rel2) (p x' y')) (w w' : Quotient Q) → P w w' Quotient-elim2 Q P p e w = Quotient-elim Q (P w) (λ x → Quotient-elim2-aux Q P p e x w) (λ x x' r → Quotient-elim-prop Q (λ w → Id (P w (pi x')) (transport-Id (P w) (pi x) (Quotient-elim2-aux Q P p e x w) (pi x') r) (Quotient-elim2-aux Q P p e x' w)) (λ y → let e-cst = e y y x x' (rel-refl Q y) r in transport (λ e → Id (P (pi y) (pi x')) (cast (P (pi y) (pi x)) (P (pi y) (pi x')) (ap (P (pi y)) r) (e (p y x))) (p y x')) (cast (P (pi y) (pi x)) (P (pi y) (pi x)) (ap (P (pi y)) (rel-refl Q x))) e-cst (λ w → w) λ a → cast-refl {A = P (pi y) (pi x)} (Id-refl (P (pi y) (pi x))) a ) w) {- -- Sanity Check: transport-refl on quotient type transport-refl-Quotient : (X : Set ℓ) (carrier Q : X -> Set ℓ₁) (R : (x : X) → carrier Q x → carrier Q x → Prop ℓ₁) (r : (z : X) (x : carrier Q z) → R z x x) (s : (z : X) (x y : carrier Q z) → R z x y → R z y x) (t : (zz : X) (x y z : carrier Q zz) → R zz x y → R zz y z → R zz x z) (x : X) (q : Quotient (carrier Q x) (R x) (r x) (s x) (t x)) (e : Id X x x) → Id _ (transport-Id (λ x → Quotient (carrier Q x) (R x) (r x) (s x) (t x)) x q x e) q transport-refl-Quotient X carrier Q R r s t x q e = Quotient-elim-prop (carrier Q x) (R x) (r x) (s x) (t x) ((λ a → Id _ (transport-Id (λ (x : X) → Quotient (carrier Q x) (R x) (r x) (s x) (t x)) x a x e) a)) (λ a → transport (λ a' → R x a' a) a (r x a) (cast (carrier Q x) (carrier Q x) _ a) (inverse (carrier Q x) (transport-refl carrier Q x a e))) q -} -- Now for Path telescope-Path : Set (lsuc ℓ) telescope-Path {ℓ} = Σ (Set ℓ) (λ A → prod A A) postulate Id-Path : (A : Set ℓ) (x : A) (y : A) (e e' : _)→ Id (x ≡ y) e e' ≡ ⊤P {-# REWRITE Id-Path #-} postulate Id-Type-Path : (A A' : Set ℓ) (x y : A) (x' y' : A') → Id (Set ℓ) (x ≡ y) (x' ≡ y') ≡ Id telescope-Path (A , (x , y)) (A' , (x' , y' )) {-# REWRITE Id-Type-Path #-} -- not enough to get canonicity -- postulate cast-Path : (A A' : Set ℓ) (x : A) (x' : A') (e : _) → -- cast (x ≡ x) (x' ≡ x') e refl ≡ refl -- {-# REWRITE cast-Path #-} transport-Path : {A : Set ℓ} (x : A) (P : (y : A) → Set ℓ₁) (t : P x) (y : A) (e : x ≡ y) → P y transport-Path P x t y refl = t transport-Path-refl : {A : Set ℓ} (P : A → Prop ℓ₁) (x : A) (t : P x) (y : A) (e : x ≡ y) → P y transport-Path-refl P x t .x refl = t path-to-Id : {A : Set ℓ} {x y : A} → x ≡ y → Id A x y path-to-Id {ℓ} {A} {x} {y} = transport-Path-refl (Id A x) x (Id-refl x) y -- we treat cast X (a ≡ b) e x as a new constructor of equality postulate IdPath : {A : Set ℓ} {x y : A} → Id A x y → x ≡ y postulate transport-Path-cast-refl : {A B : Set ℓ} (a : A) (b b' : B) (e : Id (Set ℓ) (a ≡ a) (b ≡ b')) → cast (a ≡ a) (b ≡ b') e refl ≡ IdPath ( let X = fstC (sndC e) in let Y = sndC (sndC e) in concatId B (inverse B X) Y) {-# REWRITE transport-Path-cast-refl #-} postulate transport-Path-IdPath : {A : Set ℓ} (x : A) (P : (y : A) → Set ℓ₁) (t : P x) (y : A) (e : Id A x y) → transport-Path x P t y (IdPath e) ≡ transport-Id P x t y e {-# REWRITE transport-Path-IdPath #-} postulate transport-Path-cast-IdPath : {A B : Set ℓ} (a a' : A) (b b' : B) (ea : Id A a a') (e : Id (Set ℓ) (a ≡ a') (b ≡ b')) → cast (a ≡ a') (b ≡ b') e (IdPath ea) ≡ IdPath (concatId B (inverse B (fstC (sndC e))) (concatId B (ap (cast A B (fstC e)) ea) (sndC (sndC e)))) {-# REWRITE transport-Path-cast-IdPath #-} transport-refl-Path : {A : Set ℓ} (P : A → Set ℓ₁) (x : A) (t : P x) → transport-Path x P t x refl ≡ t transport-refl-Path P x t = refl funext-Path : (A : Set ℓ) (B : A → Set ℓ₁) (f g : (a : A) → B a) → ((a : A) → f a ≡ g a) → f ≡ g funext-Path A B f g e = IdPath (λ a → path-to-Id (e a)) etaBool : (a : Bool) → a ≡ (if a then true else false) etaBool true = refl etaBool false = refl eq_fun : (λ (b : Bool) → b) ≡ (λ (b : Bool) → if b then true else false) eq_fun = funext-Path Bool (λ - → Bool) _ _ λ a → etaBool a -- standard boolean using equality std-bool : Bool std-bool = transport-Path (λ (b : Bool) → b) (λ f → Bool) true (λ (b : Bool) → if b then true else false) eq_fun sanity-check : std-bool ≡ true sanity-check = refl
35.978328
202
0.459169
1c58da252d9a77f4466f73dd7e267d381f423a76
1,056
agda
Agda
archive/agda-1/UnifyWith.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-1/UnifyWith.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-1/UnifyWith.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
open import Relation.Binary using (IsDecEquivalence) open import Agda.Builtin.Equality module UnifyWith (FunctionName : Set) ⦃ isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) ⦄ where open import UnifyTermF FunctionName open import UnifyMguF FunctionName open import UnifyMguCorrectF FunctionName open import Data.Fin using (Fin; suc; zero) open import Data.Nat hiding (_≤_) open import Relation.Binary.PropositionalEquality renaming ([_] to [[_]]) open import Function using (_∘_; id; case_of_; _$_; flip) open import Relation.Nullary open import Data.Product renaming (map to _***_) open import Data.Empty open import Data.Maybe open import Category.Functor open import Category.Monad import Level open RawMonad (Data.Maybe.monad {Level.zero}) open import Data.Sum open import Data.Maybe using (maybe; maybe′; nothing; just; monad; Maybe) open import Data.List renaming (_++_ to _++L_) open ≡-Reasoning open import Data.Vec using (Vec; []; _∷_) renaming (_++_ to _++V_; map to mapV) open import Data.Unit -- moved to UnifyMguCorrectF
32
109
0.772727
41adc3b4847509483128f96c44f6dae7cb55252e
410
agda
Agda
agda/Algebra/Construct/Free/Semilattice.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
agda/Algebra/Construct/Free/Semilattice.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Algebra/Construct/Free/Semilattice.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} -- Free join semilattice module Algebra.Construct.Free.Semilattice where open import Algebra.Construct.Free.Semilattice.Definition public open import Algebra.Construct.Free.Semilattice.Eliminators public open import Algebra.Construct.Free.Semilattice.Union public using (_∪_; 𝒦-semilattice) open import Algebra.Construct.Free.Semilattice.Homomorphism public using (μ; ∙-hom)
41
86
0.812195
59cf68aa8ce468bc2fff05d40b5bdc0ab2da8071
513
agda
Agda
Cubical/Structures/LeftAction.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Structures/LeftAction.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Structures/LeftAction.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.Structures.LeftAction where open import Cubical.Foundations.Prelude open import Cubical.Foundations.SIP open import Cubical.Structures.Auto module _ {ℓ ℓ' : Level} (A : Type ℓ') where LeftActionStructure : Type ℓ → Type (ℓ-max ℓ ℓ') LeftActionStructure X = A → X → X LeftActionEquivStr = AutoEquivStr LeftActionStructure leftActionUnivalentStr : UnivalentStr _ LeftActionEquivStr leftActionUnivalentStr = autoUnivalentStr LeftActionStructure
28.5
63
0.777778
0e3da75ebb42085c1aeb88ebec4456bac1c3be26
9,823
agda
Agda
nicolai/thesis/Trunc/Basics.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
nicolai/thesis/Trunc/Basics.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
nicolai/thesis/Trunc/Basics.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} {- Here, truncations with propositional computational behaviour are defined. This lack of a definitional β-rule enabled us to talk about this notion inside type theory without truncations, albeit complicating setup and proofs. After definition and basic accessories concerning universal properties, recursion and elimination, we prove that truncation is functorial. With this, we turn our attention to the problem of uniqueness of truncation, i.e. the type of truncations of a given type being propositional. -} module Trunc.Basics where open import lib.Basics hiding (_⊔_) open import lib.NType2 open import lib.Equivalences2 open import lib.types.Unit open import lib.types.Nat hiding (_+_) open import lib.types.Pi open import lib.types.Sigma open import lib.types.Paths open import Preliminaries open import Pointed open import UniverseOfNTypes open import Trunc.Universal -- Definition 7.6.4 record trunc-ty {i} (n : ℕ₋₂) (A : Type i) (j : ULevel) : Type (lsucc (i ⊔ j)) where constructor ty-cons field type : n -Type i cons : A → ⟦ type ⟧ univ : univ-Type type cons j module _ {i} {n : ℕ₋₂} {A : Type i} where trunc-ty-lower : ∀ {j₀} (j₁ : ULevel) → trunc-ty n A (j₀ ⊔ j₁) → trunc-ty n A j₀ trunc-ty-lower {j₀} j₁ (ty-cons t c u) = ty-cons t c (univ-lower t c (j₀ ⊔ j₁) u) {- Since Agda does not support specifying ordering relations on universe levels, we encounter an awkward dependency inversion: the index k needs to be specified in the module arguments, since the truncation type depends on it, even though we would rather have it at each individual definition. This shortcoming will be the source of many explicitely specified levels. -} module trunc-props {i} {n : ℕ₋₂} {A : Type i} {j k} (tr : trunc-ty n A (i ⊔ j ⊔ k)) where open trunc-ty tr up : (U : n -Type k) → (⟦ type ⟧ → ⟦ U ⟧) ≃ (A → ⟦ U ⟧) up U = ((λ f → f ∘ cons) , univ-lower type cons (i ⊔ j ⊔ k) univ U) dup : (U : ⟦ type ⟧ → n -Type k) → ((ta : ⟦ type ⟧) → ⟦ U ta ⟧) ≃ ((a : A) → ⟦ U (cons a) ⟧) dup U = ((λ f → f ∘ cons) , with-univ.duniv type cons (univ-lower type cons (i ⊔ j ⊔ k) univ) U) abstract rec : (U : n -Type k) → (A → ⟦ U ⟧) → ⟦ type ⟧ → ⟦ U ⟧ rec U = <– (up U) elim : (U : ⟦ type ⟧ → n -Type k) → ((a : A) → ⟦ U (cons a) ⟧) → (ta : ⟦ type ⟧) → ⟦ U ta ⟧ elim U = <– (dup U) rec-β : {U : n -Type k} {f : A → ⟦ U ⟧} (a : A) → rec U f (cons a) == f a rec-β {U} {f} a = app= (<–-inv-r (up U) f) a elim-β : {U : ⟦ type ⟧ → n -Type k} {f : (a : A) → ⟦ U (cons a) ⟧} (a : A) → elim U f (cons a) == f a elim-β {U} {f} a = app= (<–-inv-r (dup U) f) a {- Truncation acts as a functor. While tedious, we state all lemmata in their most general form. Instead of assuming an n-truncation operator, we individually assume a truncation for each type we need. While seeming overly convoluted at first, this generality will actually pay off with an unconventional use of fmap-equiv in showing that trunc-ty is propositional. -} module trunc-functor {n : ℕ₋₂} where open trunc-ty open trunc-props -- The functorial action of truncation (truncation preserves maps). module _ {ia ib j} where module fmap {A : Type ia} {B : Type ib} (TrA : trunc-ty n A (ia ⊔ ib ⊔ j)) (TrB : trunc-ty n B (ia ⊔ ib ⊔ j)) (f : A → B) where map : ⟦ type TrA ⟧ → ⟦ type TrB ⟧ map = rec {j = ia ⊔ ib ⊔ j} TrA (type TrB) (cons TrB ∘ f) β : (a : A) → map (cons TrA a) == cons TrB (f a) β = rec-β TrA {type TrB} -- The functorial action preserves the identity. module _ {i j} {A : Type i} (TrA : trunc-ty n A (i ⊔ j)) where private module I = fmap {j = i ⊔ j} TrA TrA (idf _) fmap-fuse-id : (ta : ⟦ type TrA ⟧) → I.map ta == ta fmap-fuse-id = elim {j = i ⊔ j} TrA (λ ta → Path-≤ (type TrA) (I.map ta) ta) I.β -- The functorial action preserves composition. module _ {ia ib ic j} where private l : ULevel l = ia ⊔ ib ⊔ ic ⊔ j module _ {A : Type ia} {B : Type ib} {C : Type ic} (TrA : trunc-ty n A l) (TrB : trunc-ty n B l) (TrC : trunc-ty n C l) (f : A → B) (g : B → C) where private module F = fmap {j = l} TrA TrB f module G = fmap {j = l} TrB TrC g module GF = fmap {j = l} TrA TrC (g ∘ f) open trunc-props fmap-fuse-∘ : (ta : ⟦ type TrA ⟧) → GF.map ta == G.map (F.map ta) fmap-fuse-∘ = elim {j = l} TrA (λ ta → Path-≤ (type TrC) (GF.map ta) (G.map (F.map ta))) $ λ a → GF.map (cons TrA a) =⟨ GF.β a ⟩ cons TrC (g (f a)) =⟨ ! (G.β (f a)) ⟩ G.map (cons TrB (f a)) =⟨ ap G.map (! (F.β a)) ⟩ G.map (F.map (cons TrA a)) ∎ {- Corollary: truncation preserves equivalences. The below general form produces a unexpected benefit: the underlying type of a truncation is unique up to constructor-preserving equivalence. -} module _ where private module _ {ia ib j} where private l : ULevel l = ia ⊔ ib ⊔ j module half {A : Type ia} {B : Type ib} (TrA : trunc-ty n A l) (TrB : trunc-ty n B l) (e : A ≃ B) where module F = fmap {j = l} TrA TrB (–> e) module G = fmap {j = l} TrB TrA (<– e) module BB = fmap {j = l} TrB TrB f-g : (tb : ⟦ type TrB ⟧) → F.map (G.map tb) == tb f-g tb = F.map (G.map tb) =⟨ ! (fmap-fuse-∘ {j = l} TrB TrA TrB (<– e) (–> e) tb) ⟩ BB.map (–> e ∘ <– e) tb =⟨ app= (ap BB.map (λ= (<–-inv-r e))) tb ⟩ BB.map (idf _) tb =⟨ fmap-fuse-id {j = l} TrB tb ⟩ tb ∎ module _ {ia ib j} where module _ {A : Type ia} {B : Type ib} (TrA : trunc-ty n A (ia ⊔ ib ⊔ j)) (TrB : trunc-ty n B (ia ⊔ ib ⊔ j)) (e : A ≃ B) where private module H = half {j = j} TrA TrB e module K = half {j = j} TrB TrA (e ⁻¹) fmap-equiv : ⟦ type TrA ≃-≤ type TrB ⟧ fmap-equiv = equiv H.F.map K.F.map H.f-g K.f-g {- The type of n-truncations of A is propositional: truncations are unique if existent. -} module _ {i} {n : ℕ₋₂} {A : Type i} where open trunc-ty open trunc-functor {- For the purpose of this module, it will be easier for us to regard trunc-ty as a left-associatived Σ-type. In this way, we may examine the equality on the first component while disregarding the second one, which is a proposition. -} private e : ∀ {j} → trunc-ty n A j ≃ Σ (Σ _ _) _ e = equiv (λ {(ty-cons t c u) → ((t , c) , u)}) (λ {((t , c) , u) → ty-cons t c u}) (λ _ → idp) (λ _ → idp) {- First, let us structurally decompose the combined equality over the type and cons record fields of trunc-ty. Note that this kind of lemma would be superfluous in a proof assistant fully supporting univalent foundations. -} path : (U V : Σ (n -Type i) (λ ty → A → ⟦ ty ⟧)) → (U == V) ≃ Σ (⟦ fst U ⟧ ≃ ⟦ fst V ⟧) (λ e → –> e ∘ snd U == snd V) path ((X , u) , f) ((Y , v) , g) = equiv-Σ eq₁ (_⁻¹ ∘ eq₂) ∘e =Σ-eqv _ _ ⁻¹ where eq₁ : ((X , u) == (Y , v)) ≃ (X ≃ Y) eq₁ = (X , u) == (Y , v) ≃⟨ =Σ-eqv _ _ ⁻¹ ⟩ Σ (X == Y) (λ p → u == v [ _ ↓ p ]) ≃⟨ Σ₂-contr h ⟩ X == Y ≃⟨ ua-equiv ⁻¹ ⟩ X ≃ Y ≃∎ where h : (p : X == Y) → is-contr (u == v [ _ ↓ p ]) h _ = ↓-level (λ _ → has-level-is-prop) eq₂ : (e : X ≃ Y) → (–> e ∘ f == g) ≃ (f == g [ _ ↓ <– eq₁ e ]) eq₂ = λ e → –> e ∘ f == g ≃⟨ app=-equiv ⟩ (∀ a → –> e (f a) == g a) ≃⟨ equiv-Π-r (λ a → ↓-idf-ua-equiv e) ⟩ (∀ a → f a == g a [ _ ↓ ua e ]) ≃⟨ ↓-cst→app-equiv ⟩ (f == g [ _ ↓ ua e ]) ≃⟨ ↓-cst2-equiv _ _ ⟩ (f == g [ _ ↓ <– eq₁ e ]) ≃∎ module _ {j} where {- Important special case of the general form of fmap-equiv: the underlying type of a truncation is unique up to constructor-preserving equivalence. -} module unique (Tr₁ : trunc-ty n A (i ⊔ j)) (Tr₂ : trunc-ty n A (i ⊔ j)) where type-equiv : ⟦ type Tr₁ ≃-≤ type Tr₂ ⟧ type-equiv = fmap-equiv {j = j} Tr₁ Tr₂ (ide _) cons-path : –> type-equiv ∘ cons Tr₁ == cons Tr₂ cons-path = λ= (fmap.β {j = j} Tr₁ Tr₂ (idf _)) type-cons-path : Path {A = Σ (n -Type i) (λ ty → A → ⟦ ty ⟧)} (fst (–> e Tr₁)) (fst (–> e Tr₂)) type-cons-path = <– (path _ _) (type-equiv , cons-path) -- Lemma 7.6.7 -- We are now ready to prove propositionality of trunc-ty. trunc-ty-prop : is-prop (trunc-ty n A _) trunc-ty-prop = all-paths-is-prop $ λ Tr₀ Tr₁ → <– (equiv-ap e _ _) (pair= (unique.type-cons-path Tr₀ Tr₁) (prop-has-all-paths-↓ (Π-level (λ _ → is-equiv-is-prop _)))) trunc-inhab-contr : trunc-ty n A _ → is-contr (trunc-ty n A _) trunc-inhab-contr Tr = (Tr , prop-has-all-paths trunc-ty-prop _) -- Corollary 7.6.8 (for completeness; -- not used later in this formalisation) trunc-ty-gen-prop : (i j : ULevel) → is-prop ((nA : ℕ₋₂ × Type i) → trunc-ty (fst nA) (snd nA) (i ⊔ j)) trunc-ty-gen-prop i j = Π-level {A = ℕ₋₂ × Type i} {B = λ nA → trunc-ty (fst nA) (snd nA) (i ⊔ j)} {n = ⟨-1⟩} (λ nA → trunc-ty-prop {n = fst nA} {A = snd nA} {j = j})
40.929167
105
0.518172
4d98409ccc23451bec507cc7a4bddbdad2113873
14,733
agda
Agda
deBruijn/Substitution/Data/Simple.agda
nad/dependently-typed-syntax
498f8aefc570f7815fd1d6616508eeb92c52abce
[ "MIT" ]
5
2020-04-16T12:14:44.000Z
2020-07-08T22:51:36.000Z
deBruijn/Substitution/Data/Simple.agda
nad/dependently-typed-syntax
498f8aefc570f7815fd1d6616508eeb92c52abce
[ "MIT" ]
null
null
null
deBruijn/Substitution/Data/Simple.agda
nad/dependently-typed-syntax
498f8aefc570f7815fd1d6616508eeb92c52abce
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Some simple substitution combinators ------------------------------------------------------------------------ -- Given a term type which supports weakening and transformation of -- variables to terms various substitutions are defined and various -- lemmas proved. open import Data.Universe.Indexed module deBruijn.Substitution.Data.Simple {i u e} {Uni : IndexedUniverse i u e} where import deBruijn.Context; open deBruijn.Context Uni open import deBruijn.Substitution.Data.Basics open import deBruijn.Substitution.Data.Map open import Function as F using (_$_) open import Level using (_⊔_) open import Relation.Binary.PropositionalEquality as P using (_≡_) open P.≡-Reasoning -- Simple substitutions. record Simple {t} (T : Term-like t) : Set (i ⊔ u ⊔ e ⊔ t) where open Term-like T field -- Weakens terms. weaken : ∀ {Γ} {σ : Type Γ} → [ T ⟶ T ] ŵk[ σ ] -- A synonym. weaken[_] : ∀ {Γ} (σ : Type Γ) → [ T ⟶ T ] ŵk[ σ ] weaken[_] _ = weaken field -- Takes variables to terms. var : [ Var ⟶⁼ T ] -- A property relating weaken and var. weaken-var : ∀ {Γ σ τ} (x : Γ ∋ τ) → weaken[ σ ] · (var · x) ≅-⊢ var · suc[ σ ] x -- Weakens substitutions. wk-subst : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → Sub T (ρ̂ ∘̂ ŵk[ σ ]) wk-subst ρ = map weaken ρ wk-subst[_] : ∀ {Γ Δ} σ {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → Sub T (ρ̂ ∘̂ ŵk[ σ ]) wk-subst[ _ ] = wk-subst -- N-ary weakening of substitutions. wk-subst⁺ : ∀ {Γ Δ} Δ⁺ {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → Sub T (ρ̂ ∘̂ ŵk⁺ Δ⁺) wk-subst⁺ ε ρ = ρ wk-subst⁺ (Δ⁺ ▻ σ) ρ = wk-subst (wk-subst⁺ Δ⁺ ρ) wk-subst₊ : ∀ {Γ Δ} Δ₊ {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → Sub T (ρ̂ ∘̂ ŵk₊ Δ₊) wk-subst₊ ε ρ = ρ wk-subst₊ (σ ◅ Δ₊) ρ = wk-subst₊ Δ₊ (wk-subst ρ) -- Lifting. infixl 10 _↑_ _↑⋆_ infix 10 _↑ _↑⋆ _↑_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → ∀ σ → Sub T (ρ̂ ↑̂ σ) ρ ↑ _ = P.subst (Sub T) (≅-⇨̂-⇒-≡ $ ▻̂-cong P.refl P.refl (P.sym $ corresponds var zero)) (wk-subst ρ ▻ var · zero) _↑ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → Sub T (ρ̂ ↑̂ σ) ρ ↑ = ρ ↑ _ _↑⋆ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → Subs T (ρ̂ ↑̂ σ) ε ↑⋆ = ε (ρs ▻ ρ) ↑⋆ = ρs ↑⋆ ▻ ρ ↑ _↑⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → ∀ σ → Subs T (ρ̂ ↑̂ σ) ρs ↑⋆ _ = ρs ↑⋆ -- N-ary lifting. infixl 10 _↑⁺_ _↑⁺⋆_ _↑₊_ _↑₊⋆_ _↑⁺_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → ∀ Γ⁺ → Sub T (ρ̂ ↑̂⁺ Γ⁺) ρ ↑⁺ ε = ρ ρ ↑⁺ (Γ⁺ ▻ σ) = (ρ ↑⁺ Γ⁺) ↑ _↑⁺⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → ∀ Γ⁺ → Subs T (ρ̂ ↑̂⁺ Γ⁺) ρs ↑⁺⋆ ε = ρs ρs ↑⁺⋆ (Γ⁺ ▻ σ) = (ρs ↑⁺⋆ Γ⁺) ↑⋆ _↑₊_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → ∀ Γ₊ → Sub T (ρ̂ ↑̂₊ Γ₊) ρ ↑₊ ε = ρ ρ ↑₊ (σ ◅ Γ₊) = ρ ↑ ↑₊ Γ₊ _↑₊⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → ∀ Γ₊ → Subs T (ρ̂ ↑̂₊ Γ₊) ρs ↑₊⋆ ε = ρs ρs ↑₊⋆ (σ ◅ Γ₊) = ρs ↑⋆ ↑₊⋆ Γ₊ -- The identity substitution. id[_] : ∀ Γ → Sub T îd[ Γ ] id[ ε ] = ε id[ Γ ▻ σ ] = id[ Γ ] ↑ id : ∀ {Γ} → Sub T îd[ Γ ] id = id[ _ ] -- N-ary weakening. wk⁺ : ∀ {Γ} (Γ⁺ : Ctxt⁺ Γ) → Sub T (ŵk⁺ Γ⁺) wk⁺ ε = id wk⁺ (Γ⁺ ▻ σ) = wk-subst (wk⁺ Γ⁺) wk₊ : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → Sub T (ŵk₊ Γ₊) wk₊ Γ₊ = wk-subst₊ Γ₊ id -- Weakening. wk[_] : ∀ {Γ} (σ : Type Γ) → Sub T ŵk[ σ ] wk[ σ ] = wk⁺ (ε ▻ σ) wk : ∀ {Γ} {σ : Type Γ} → Sub T ŵk[ σ ] wk = wk[ _ ] private -- Three possible definitions of wk coincide definitionally. coincide₁ : ∀ {Γ} {σ : Type Γ} → wk⁺ (ε ▻ σ) ≡ wk₊ (σ ◅ ε) coincide₁ = P.refl coincide₂ : ∀ {Γ} {σ : Type Γ} → wk⁺ (ε ▻ σ) ≡ wk-subst id coincide₂ = P.refl -- A substitution which only replaces the first variable. sub : ∀ {Γ σ} (t : Γ ⊢ σ) → Sub T (ŝub ⟦ t ⟧) sub t = id ▻ t -- Some congruence lemmas. weaken-cong : ∀ {Γ₁ σ₁ τ₁} {t₁ : Γ₁ ⊢ τ₁} {Γ₂ σ₂ τ₂} {t₂ : Γ₂ ⊢ τ₂} → σ₁ ≅-Type σ₂ → t₁ ≅-⊢ t₂ → weaken[ σ₁ ] · t₁ ≅-⊢ weaken[ σ₂ ] · t₂ weaken-cong P.refl P.refl = P.refl var-cong : ∀ {Γ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {Γ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} → x₁ ≅-∋ x₂ → var · x₁ ≅-⊢ var · x₂ var-cong P.refl = P.refl wk-subst-cong : ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} → σ₁ ≅-Type σ₂ → ρ₁ ≅-⇨ ρ₂ → wk-subst[ σ₁ ] ρ₁ ≅-⇨ wk-subst[ σ₂ ] ρ₂ wk-subst-cong P.refl P.refl = P.refl wk-subst⁺-cong : ∀ {Γ₁ Δ₁ Γ⁺₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {Γ₂ Δ₂ Γ⁺₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} → Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ρ₁ ≅-⇨ ρ₂ → wk-subst⁺ Γ⁺₁ ρ₁ ≅-⇨ wk-subst⁺ Γ⁺₂ ρ₂ wk-subst⁺-cong P.refl P.refl = P.refl wk-subst₊-cong : ∀ {Γ₁ Δ₁ Γ₊₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {Γ₂ Δ₂ Γ₊₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} → Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρ₁ ≅-⇨ ρ₂ → wk-subst₊ Γ₊₁ ρ₁ ≅-⇨ wk-subst₊ Γ₊₂ ρ₂ wk-subst₊-cong P.refl P.refl = P.refl ↑-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {σ₁} {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} {σ₂} → ρ₁ ≅-⇨ ρ₂ → σ₁ ≅-Type σ₂ → ρ₁ ↑ σ₁ ≅-⇨ ρ₂ ↑ σ₂ ↑-cong P.refl P.refl = P.refl ↑⋆-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T ρ̂₁} {σ₁} {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T ρ̂₂} {σ₂} → ρs₁ ≅-⇨⋆ ρs₂ → σ₁ ≅-Type σ₂ → ρs₁ ↑⋆ σ₁ ≅-⇨⋆ ρs₂ ↑⋆ σ₂ ↑⋆-cong P.refl P.refl = P.refl ↑⁺-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {Γ⁺₁} {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} {Γ⁺₂} → ρ₁ ≅-⇨ ρ₂ → Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ρ₁ ↑⁺ Γ⁺₁ ≅-⇨ ρ₂ ↑⁺ Γ⁺₂ ↑⁺-cong P.refl P.refl = P.refl ↑⁺⋆-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T ρ̂₁} {Γ⁺₁} {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T ρ̂₂} {Γ⁺₂} → ρs₁ ≅-⇨⋆ ρs₂ → Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ρs₁ ↑⁺⋆ Γ⁺₁ ≅-⇨⋆ ρs₂ ↑⁺⋆ Γ⁺₂ ↑⁺⋆-cong P.refl P.refl = P.refl ↑₊-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {Γ₊₁} {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} {Γ₊₂} → ρ₁ ≅-⇨ ρ₂ → Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρ₁ ↑₊ Γ₊₁ ≅-⇨ ρ₂ ↑₊ Γ₊₂ ↑₊-cong P.refl P.refl = P.refl ↑₊⋆-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T ρ̂₁} {Γ₊₁} {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T ρ̂₂} {Γ₊₂} → ρs₁ ≅-⇨⋆ ρs₂ → Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρs₁ ↑₊⋆ Γ₊₁ ≅-⇨⋆ ρs₂ ↑₊⋆ Γ₊₂ ↑₊⋆-cong P.refl P.refl = P.refl id-cong : ∀ {Γ₁ Γ₂} → Γ₁ ≅-Ctxt Γ₂ → id[ Γ₁ ] ≅-⇨ id[ Γ₂ ] id-cong P.refl = P.refl wk⁺-cong : ∀ {Γ₁} {Γ⁺₁ : Ctxt⁺ Γ₁} {Γ₂} {Γ⁺₂ : Ctxt⁺ Γ₂} → Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → wk⁺ Γ⁺₁ ≅-⇨ wk⁺ Γ⁺₂ wk⁺-cong P.refl = P.refl wk₊-cong : ∀ {Γ₁} {Γ₊₁ : Ctxt₊ Γ₁} {Γ₂} {Γ₊₂ : Ctxt₊ Γ₂} → Γ₊₁ ≅-Ctxt₊ Γ₊₂ → wk₊ Γ₊₁ ≅-⇨ wk₊ Γ₊₂ wk₊-cong P.refl = P.refl wk-cong : ∀ {Γ₁} {σ₁ : Type Γ₁} {Γ₂} {σ₂ : Type Γ₂} → σ₁ ≅-Type σ₂ → wk[ σ₁ ] ≅-⇨ wk[ σ₂ ] wk-cong P.refl = P.refl sub-cong : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁} {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂} → t₁ ≅-⊢ t₂ → sub t₁ ≅-⇨ sub t₂ sub-cong P.refl = P.refl abstract -- Unfolding lemma for _↑. unfold-↑ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T ρ̂) → ρ ↑ σ ≅-⇨ wk-subst[ σ / ρ ] ρ ▻⇨[ σ ] var · zero unfold-↑ _ = drop-subst-Sub F.id (≅-⇨̂-⇒-≡ $ ▻̂-cong P.refl P.refl (P.sym $ corresponds var zero)) -- Some lemmas relating variables to lifting. /∋-↑ : ∀ {Γ Δ σ τ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ▻ σ ∋ τ) (ρ : Sub T ρ̂) → x /∋ ρ ↑ ≅-⊢ x /∋ (wk-subst[ σ / ρ ] ρ ▻ var · zero) /∋-↑ x ρ = /∋-cong (P.refl {x = [ x ]}) (unfold-↑ ρ) zero-/∋-↑ : ∀ {Γ Δ} σ {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T ρ̂) → zero[ σ ] /∋ ρ ↑ ≅-⊢ var · zero[ σ / ρ ] zero-/∋-↑ σ ρ = begin [ zero[ σ ] /∋ ρ ↑ ] ≡⟨ /∋-↑ zero[ σ ] ρ ⟩ [ zero[ σ ] /∋ (wk-subst ρ ▻ var · zero) ] ≡⟨ P.refl ⟩ [ var · zero ] ∎ suc-/∋-↑ : ∀ {Γ Δ τ} σ {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ τ) (ρ : Sub T ρ̂) → suc[ σ ] x /∋ ρ ↑ ≅-⊢ x /∋ wk-subst[ σ / ρ ] ρ suc-/∋-↑ σ x ρ = begin [ suc[ σ ] x /∋ ρ ↑ ] ≡⟨ /∋-↑ (suc[ σ ] x) ρ ⟩ [ suc[ σ ] x /∋ (wk-subst ρ ▻ var · zero) ] ≡⟨ P.refl ⟩ [ x /∋ wk-subst ρ ] ∎ -- One can weaken either before or after looking up a variable. /∋-wk-subst : ∀ {Γ Δ σ τ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ τ) (ρ : Sub T ρ̂) → x /∋ wk-subst[ σ ] ρ ≅-⊢ weaken[ σ ] · (x /∋ ρ) /∋-wk-subst x ρ = /∋-map x weaken ρ -- A corollary. /∋-wk-subst-var : ∀ {Γ Δ σ τ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T ρ̂) (x : Γ ∋ τ) (y : Δ ∋ τ / ρ) → x /∋ ρ ≅-⊢ var · y → x /∋ wk-subst[ σ ] ρ ≅-⊢ var · suc[ σ ] y /∋-wk-subst-var ρ x y hyp = begin [ x /∋ wk-subst ρ ] ≡⟨ /∋-wk-subst x ρ ⟩ [ weaken · (x /∋ ρ) ] ≡⟨ weaken-cong P.refl hyp ⟩ [ weaken · (var · y) ] ≡⟨ weaken-var y ⟩ [ var · suc y ] ∎ -- The identity substitution has no effect. /-id : ∀ {Γ} (σ : Type Γ) → σ / id ≅-Type σ /-id σ = P.refl /⁺-id : ∀ {Γ} (Γ⁺ : Ctxt⁺ Γ) → Γ⁺ /⁺ id ≅-Ctxt⁺ Γ⁺ /⁺-id Γ⁺ = begin [ Γ⁺ /⁺ id ] ≡⟨ P.refl ⟩ [ Γ⁺ /̂⁺ îd ] ≡⟨ /̂⁺-îd Γ⁺ ⟩ [ Γ⁺ ] ∎ /₊-id : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → Γ₊ /₊ id ≅-Ctxt₊ Γ₊ /₊-id Γ₊ = begin [ Γ₊ /₊ id ] ≡⟨ P.refl ⟩ [ Γ₊ /̂₊ îd ] ≡⟨ /̂₊-îd Γ₊ ⟩ [ Γ₊ ] ∎ mutual /∋-id : ∀ {Γ σ} (x : Γ ∋ σ) → x /∋ id ≅-⊢ var · x /∋-id {Γ = ε} () /∋-id {Γ = Γ ▻ σ} x = begin [ x /∋ id ↑ ] ≡⟨ /∋-↑ x id ⟩ [ x /∋ (wk ▻ var · zero) ] ≡⟨ lemma x ⟩ [ var · x ] ∎ where lemma : ∀ {τ} (x : Γ ▻ σ ∋ τ) → x /∋ (wk[ σ ] ▻ var · zero) ≅-⊢ var · x lemma zero = P.refl lemma (suc x) = /∋-wk x -- Weakening a variable is equivalent to incrementing it. /∋-wk : ∀ {Γ σ τ} (x : Γ ∋ τ) → x /∋ wk[ σ ] ≅-⊢ var · suc[ σ ] x /∋-wk x = /∋-wk-subst-var id x x (/∋-id x) -- The n-ary lifting of the identity substitution is the identity -- substitution. id-↑⁺ : ∀ {Γ} (Γ⁺ : Ctxt⁺ Γ) → id ↑⁺ Γ⁺ ≅-⇨ id[ Γ ++⁺ Γ⁺ ] id-↑⁺ ε = P.refl id-↑⁺ (Γ⁺ ▻ σ) = begin [ (id ↑⁺ Γ⁺) ↑ ] ≡⟨ ↑-cong (id-↑⁺ Γ⁺) P.refl ⟩ [ id ↑ ] ∎ ε-↑⁺⋆ : ∀ {Γ} (Γ⁺ : Ctxt⁺ Γ) → ε ↑⁺⋆ Γ⁺ ≅-⇨⋆ ε⇨⋆[ Γ ++⁺ Γ⁺ ] ε-↑⁺⋆ ε = P.refl ε-↑⁺⋆ (Γ⁺ ▻ σ) = begin [ (ε ↑⁺⋆ Γ⁺) ↑⋆ ] ≡⟨ ↑⋆-cong (ε-↑⁺⋆ Γ⁺) P.refl ⟩ [ ε ↑⋆ ] ≡⟨ P.refl ⟩ [ ε ] ∎ id-↑₊ : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → id ↑₊ Γ₊ ≅-⇨ id[ Γ ++₊ Γ₊ ] id-↑₊ ε = P.refl id-↑₊ (σ ◅ Γ₊) = begin [ id ↑ ↑₊ Γ₊ ] ≡⟨ P.refl ⟩ [ id ↑₊ Γ₊ ] ≡⟨ id-↑₊ Γ₊ ⟩ [ id ] ∎ ε-↑₊⋆ : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → ε ↑₊⋆ Γ₊ ≅-⇨⋆ ε⇨⋆[ Γ ++₊ Γ₊ ] ε-↑₊⋆ ε = P.refl ε-↑₊⋆ (σ ◅ Γ₊) = begin [ ε ↑⋆ ↑₊⋆ Γ₊ ] ≡⟨ P.refl ⟩ [ ε ↑₊⋆ Γ₊ ] ≡⟨ ε-↑₊⋆ Γ₊ ⟩ [ ε ] ∎ -- The identity substitution has no effect even if lifted. /∋-id-↑⁺ : ∀ {Γ} Γ⁺ {σ} (x : Γ ++⁺ Γ⁺ ∋ σ) → x /∋ id ↑⁺ Γ⁺ ≅-⊢ var · x /∋-id-↑⁺ Γ⁺ x = begin [ x /∋ id ↑⁺ Γ⁺ ] ≡⟨ /∋-cong (P.refl {x = [ x ]}) (id-↑⁺ Γ⁺) ⟩ [ x /∋ id ] ≡⟨ /∋-id x ⟩ [ var · x ] ∎ /∋-id-↑₊ : ∀ {Γ} Γ₊ {σ} (x : Γ ++₊ Γ₊ ∋ σ) → x /∋ id ↑₊ Γ₊ ≅-⊢ var · x /∋-id-↑₊ Γ₊ x = begin [ x /∋ id ↑₊ Γ₊ ] ≡⟨ /∋-cong (P.refl {x = [ x ]}) (id-↑₊ Γ₊) ⟩ [ x /∋ id ] ≡⟨ /∋-id x ⟩ [ var · x ] ∎ -- N-ary lifting distributes over composition. ▻-↑⁺⋆ : ∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} (ρs : Subs T ρ̂₁) (ρ : Sub T ρ̂₂) Γ⁺ → (ρs ▻ ρ) ↑⁺⋆ Γ⁺ ≅-⇨⋆ ρs ↑⁺⋆ Γ⁺ ▻ ρ ↑⁺ (Γ⁺ /⁺⋆ ρs) ▻-↑⁺⋆ ρs ρ ε = P.refl ▻-↑⁺⋆ ρs ρ (Γ⁺ ▻ σ) = begin [ ((ρs ▻ ρ) ↑⁺⋆ Γ⁺) ↑⋆ ] ≡⟨ ↑⋆-cong (▻-↑⁺⋆ ρs ρ Γ⁺) P.refl ⟩ [ (ρs ↑⁺⋆ Γ⁺ ▻ ρ ↑⁺ (Γ⁺ /⁺⋆ ρs)) ↑⋆ ] ≡⟨ P.refl ⟩ [ (ρs ↑⁺⋆ Γ⁺) ↑⋆ ▻ (ρ ↑⁺ (Γ⁺ /⁺⋆ ρs)) ↑ ] ∎ ▻-↑₊⋆ : ∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} (ρs : Subs T ρ̂₁) (ρ : Sub T ρ̂₂) Γ₊ → (ρs ▻ ρ) ↑₊⋆ Γ₊ ≅-⇨⋆ ρs ↑₊⋆ Γ₊ ▻ ρ ↑₊ (Γ₊ /₊⋆ ρs) ▻-↑₊⋆ ρs ρ ε = P.refl ▻-↑₊⋆ ρs ρ (σ ◅ Γ₊) = begin [ (ρs ▻ ρ) ↑⋆ ↑₊⋆ Γ₊ ] ≡⟨ P.refl ⟩ [ (ρs ↑⋆ ▻ ρ ↑) ↑₊⋆ Γ₊ ] ≡⟨ ▻-↑₊⋆ (ρs ↑⋆) (ρ ↑) Γ₊ ⟩ [ ρs ↑₊⋆ (σ ◅ Γ₊) ▻ ρ ↑₊ ((σ ◅ Γ₊) /₊⋆ ρs) ] ∎ -- If ρ is morally a renaming, then "deep application" of ρ to a -- variable is still a variable. /∋-↑⁺ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T ρ̂) (f : [ Var ⟶ Var ] ρ̂) → (∀ {σ} (x : Γ ∋ σ) → x /∋ ρ ≅-⊢ var · (f · x)) → ∀ Γ⁺ {σ} (x : Γ ++⁺ Γ⁺ ∋ σ) → x /∋ ρ ↑⁺ Γ⁺ ≅-⊢ var · (lift f Γ⁺ · x) /∋-↑⁺ ρ f hyp ε x = hyp x /∋-↑⁺ ρ f hyp (Γ⁺ ▻ σ) zero = begin [ zero[ σ ] /∋ (ρ ↑⁺ Γ⁺) ↑ ] ≡⟨ zero-/∋-↑ σ (ρ ↑⁺ Γ⁺) ⟩ [ var · zero ] ∎ /∋-↑⁺ ρ f hyp (Γ⁺ ▻ σ) (suc x) = begin [ suc[ σ ] x /∋ (ρ ↑⁺ Γ⁺) ↑ ] ≡⟨ suc-/∋-↑ σ x (ρ ↑⁺ Γ⁺) ⟩ [ x /∋ wk-subst (ρ ↑⁺ Γ⁺) ] ≡⟨ /∋-wk-subst x (ρ ↑⁺ Γ⁺) ⟩ [ weaken · (x /∋ ρ ↑⁺ Γ⁺) ] ≡⟨ weaken-cong P.refl (/∋-↑⁺ ρ f hyp Γ⁺ x) ⟩ [ weaken · (var · (lift f Γ⁺ · x)) ] ≡⟨ weaken-var (lift f Γ⁺ · x) ⟩ [ var · suc (lift f Γ⁺ · x) ] ∎ -- "Deep weakening" of a variable can be expressed without -- reference to the weaken function. /∋-wk-↑⁺ : ∀ {Γ σ} Γ⁺ {τ} (x : Γ ++⁺ Γ⁺ ∋ τ) → x /∋ wk[ σ ] ↑⁺ Γ⁺ ≅-⊢ var · (lift weaken∋[ σ ] Γ⁺ · x) /∋-wk-↑⁺ = /∋-↑⁺ wk weaken∋ /∋-wk /∋-wk-↑⁺-↑⁺ : ∀ {Γ σ} Γ⁺ Γ⁺⁺ {τ} (x : Γ ++⁺ Γ⁺ ++⁺ Γ⁺⁺ ∋ τ) → x /∋ wk[ σ ] ↑⁺ Γ⁺ ↑⁺ Γ⁺⁺ ≅-⊢ var · (lift (lift weaken∋[ σ ] Γ⁺) Γ⁺⁺ · x) /∋-wk-↑⁺-↑⁺ Γ⁺ = /∋-↑⁺ (wk ↑⁺ Γ⁺) (lift weaken∋ Γ⁺) (/∋-wk-↑⁺ Γ⁺) -- Two n-ary liftings can be merged into one. ↑⁺-⁺++⁺ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T ρ̂) Γ⁺ Γ⁺⁺ → ρ ↑⁺ (Γ⁺ ⁺++⁺ Γ⁺⁺) ≅-⇨ ρ ↑⁺ Γ⁺ ↑⁺ Γ⁺⁺ ↑⁺-⁺++⁺ ρ Γ⁺ ε = P.refl ↑⁺-⁺++⁺ ρ Γ⁺ (Γ⁺⁺ ▻ σ) = begin [ (ρ ↑⁺ (Γ⁺ ⁺++⁺ Γ⁺⁺)) ↑ ] ≡⟨ ↑-cong (↑⁺-⁺++⁺ ρ Γ⁺ Γ⁺⁺) (drop-subst-Type F.id (++⁺-++⁺ Γ⁺ Γ⁺⁺)) ⟩ [ (ρ ↑⁺ Γ⁺ ↑⁺ Γ⁺⁺) ↑ ] ∎ ↑₊-₊++₊ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρ : Sub T ρ̂) Γ₊ Γ₊₊ → ρ ↑₊ (Γ₊ ₊++₊ Γ₊₊) ≅-⇨ ρ ↑₊ Γ₊ ↑₊ Γ₊₊ ↑₊-₊++₊ ρ ε Γ₊₊ = P.refl ↑₊-₊++₊ ρ (σ ◅ Γ₊) Γ₊₊ = begin [ ρ ↑ ↑₊ (Γ₊ ₊++₊ Γ₊₊) ] ≡⟨ ↑₊-₊++₊ (ρ ↑) Γ₊ Γ₊₊ ⟩ [ ρ ↑ ↑₊ Γ₊ ↑₊ Γ₊₊ ] ∎
34.183295
88
0.356343
3d5137f11f01faff50ce243d2f225ff5713979a8
4,138
agda
Agda
agda-stdlib/src/Data/Product.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Product.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Product.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Products ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Product where open import Function.Base open import Level open import Relation.Nullary open import Agda.Builtin.Equality private variable a b c d e f ℓ p q r : Level A : Set a B : Set b C : Set c D : Set d E : Set e F : Set f ------------------------------------------------------------------------ -- Definition of dependent products open import Agda.Builtin.Sigma public renaming (fst to proj₁; snd to proj₂) hiding (module Σ) module Σ = Agda.Builtin.Sigma.Σ renaming (fst to proj₁; snd to proj₂) -- The syntax declaration below is attached to Σ-syntax, to make it -- easy to import Σ without the special syntax. infix 2 Σ-syntax Σ-syntax : (A : Set a) → (A → Set b) → Set (a ⊔ b) Σ-syntax = Σ syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B ------------------------------------------------------------------------ -- Definition of non-dependent products infixr 4 _,′_ infixr 2 _×_ _×_ : ∀ (A : Set a) (B : Set b) → Set (a ⊔ b) A × B = Σ[ x ∈ A ] B _,′_ : A → B → A × B _,′_ = _,_ ------------------------------------------------------------------------ -- Existential quantifiers ∃ : ∀ {A : Set a} → (A → Set b) → Set (a ⊔ b) ∃ = Σ _ ∄ : ∀ {A : Set a} → (A → Set b) → Set (a ⊔ b) ∄ P = ¬ ∃ P ∃₂ : ∀ {A : Set a} {B : A → Set b} (C : (x : A) → B x → Set c) → Set (a ⊔ b ⊔ c) ∃₂ C = ∃ λ a → ∃ λ b → C a b -- Unique existence (parametrised by an underlying equality). ∃! : {A : Set a} → (A → A → Set ℓ) → (A → Set b) → Set (a ⊔ b ⊔ ℓ) ∃! _≈_ B = ∃ λ x → B x × (∀ {y} → B y → x ≈ y) -- Syntax ∃-syntax : ∀ {A : Set a} → (A → Set b) → Set (a ⊔ b) ∃-syntax = ∃ syntax ∃-syntax (λ x → B) = ∃[ x ] B ∄-syntax : ∀ {A : Set a} → (A → Set b) → Set (a ⊔ b) ∄-syntax = ∄ syntax ∄-syntax (λ x → B) = ∄[ x ] B ------------------------------------------------------------------------ -- Operations over dependent products infix 4 -,_ infixr 2 _-×-_ _-,-_ -- Sometimes the first component can be inferred. -,_ : ∀ {A : Set a} {B : A → Set b} {x} → B x → ∃ B -, y = _ , y <_,_> : ∀ {A : Set a} {B : A → Set b} {C : ∀ {x} → B x → Set c} (f : (x : A) → B x) → ((x : A) → C (f x)) → ((x : A) → Σ (B x) C) < f , g > x = (f x , g x) map : ∀ {P : A → Set p} {Q : B → Set q} → (f : A → B) → (∀ {x} → P x → Q (f x)) → Σ A P → Σ B Q map f g (x , y) = (f x , g y) map₁ : (A → B) → A × C → B × C map₁ f = map f id map₂ : ∀ {A : Set a} {B : A → Set b} {C : A → Set c} → (∀ {x} → B x → C x) → Σ A B → Σ A C map₂ f = map id f zip : ∀ {P : A → Set p} {Q : B → Set q} {R : C → Set r} → (_∙_ : A → B → C) → (∀ {x y} → P x → Q y → R (x ∙ y)) → Σ A P → Σ B Q → Σ C R zip _∙_ _∘_ (a , p) (b , q) = ((a ∙ b) , (p ∘ q)) curry : ∀ {A : Set a} {B : A → Set b} {C : Σ A B → Set c} → ((p : Σ A B) → C p) → ((x : A) → (y : B x) → C (x , y)) curry f x y = f (x , y) uncurry : ∀ {A : Set a} {B : A → Set b} {C : Σ A B → Set c} → ((x : A) → (y : B x) → C (x , y)) → ((p : Σ A B) → C p) uncurry f (x , y) = f x y ------------------------------------------------------------------------ -- Operations for non-dependent products -- Any of the above operations for dependent products will also work for -- non-dependent products but sometimes Agda has difficulty inferring -- the non-dependency. Primed (′ = \prime) versions of the operations -- are therefore provided below that sometimes have better inference -- properties. zip′ : (A → B → C) → (D → E → F) → A × D → B × E → C × F zip′ f g = zip f g curry′ : (A × B → C) → (A → B → C) curry′ = curry uncurry′ : (A → B → C) → (A × B → C) uncurry′ = uncurry -- Operations that can only be defined for non-dependent products swap : A × B → B × A swap (x , y) = (y , x) _-×-_ : (A → B → Set p) → (A → B → Set q) → (A → B → Set _) f -×- g = f -[ _×_ ]- g _-,-_ : (A → B → C) → (A → B → D) → (A → B → C × D) f -,- g = f -[ _,_ ]- g
25.8625
72
0.422668
0e0aeaa8372529803c9c5a53a87f6133cce3229b
2,807
agda
Agda
Structure/Operator.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Structure/Operator.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Structure/Operator.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Structure.Operator where import Lvl open import Functional using (_$_) open import Lang.Instance open import Logic.Predicate open import Logic open import Structure.Setoid open import Structure.Function.Names open import Structure.Function open import Structure.Relator.Properties open import Syntax.Function open import Syntax.Transitivity open import Type private variable ℓ ℓₒ ℓₒ₁ ℓₒ₂ ℓₒ₃ ℓₒ₄ ℓₗ ℓₗ₁ ℓₗ₂ ℓₗ₃ ℓₗ₄ : Lvl.Level private variable A₁ A₂ A₃ B : Type{ℓ} module _ ⦃ equiv-A₁ : Equiv{ℓₗ₁}(A₁) ⦄ ⦃ equiv-A₂ : Equiv{ℓₗ₂}(A₂) ⦄ ⦃ equiv-B : Equiv{ℓₗ₃}(B) ⦄ (_▫_ : A₁ → A₂ → B) where -- The operator `_▫_` "(behaves like)/is a function" in the context of `_≡_` from the Equiv instance. -- `congruence` is the defining property of a binary operation. record BinaryOperator : Type{Lvl.of(A₁) Lvl.⊔ Lvl.of(A₂) Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓₗ₃} where constructor intro field congruence : Congruence₂(_▫_) instance left : ∀{x} → Function(_▫ x) left = intro(proof ↦ congruence proof (reflexivity(_≡_))) instance right : ∀{x} → Function(x ▫_) right = intro(proof ↦ congruence (reflexivity(_≡_)) proof) congruenceₗ : ∀{x₁ x₂}{y} → (x₁ ≡ x₂) → (x₁ ▫ y ≡ x₂ ▫ y) congruenceₗ = Function.congruence(left) congruenceᵣ : ∀{x}{y₁ y₂} → (y₁ ≡ y₂) → (x ▫ y₁ ≡ x ▫ y₂) congruenceᵣ = Function.congruence(right) [≡]-congruence2-left : ⦃ inst : BinaryOperator ⦄ → (x : _) → Function(_▫ x) [≡]-congruence2-left = x ↦ inst-fn(BinaryOperator.left) {x} [≡]-congruence2-right : ⦃ inst : BinaryOperator ⦄ → (x : _) → Function(x ▫_) [≡]-congruence2-right = x ↦ inst-fn(BinaryOperator.right) {x} congruence₂ = inst-fn BinaryOperator.congruence congruence₂ₗ : ⦃ inst : BinaryOperator ⦄ → (a : A₂) → ∀{x y : A₁} → (x ≡ y) → (x ▫ a ≡ y ▫ a) congruence₂ₗ _ = inst-fn BinaryOperator.congruenceₗ -- (congruence₁(_▫ a) ⦃ [≡]-congruence2-left ⦃ inst ⦄ a ⦄) congruence₂ᵣ : ⦃ inst : BinaryOperator ⦄ → (a : A₁) → ∀{x y : A₂} → (x ≡ y) → (a ▫ x ≡ a ▫ y) congruence₂ᵣ _ = inst-fn BinaryOperator.congruenceᵣ functions-to-binaryOperator : ⦃ l : ∀{y} → Function(_▫ y) ⦄ ⦃ r : ∀{x} → Function(x ▫_) ⦄ → BinaryOperator BinaryOperator.congruence functions-to-binaryOperator {x₁} {y₁} {x₂} {y₂} leq req = (x₁ ▫ x₂) 🝖[ _≡_ ]-[ congruence₁(_▫ x₂) leq ] (y₁ ▫ x₂) 🝖[ _≡_ ]-[ congruence₁(y₁ ▫_) req ] (y₁ ▫ y₂) 🝖-end module _ ⦃ equiv-A₁ : Equiv{ℓₗ₁}(A₁) ⦄ ⦃ equiv-A₂ : Equiv{ℓₗ₂}(A₂) ⦄ ⦃ equiv-A₃ : Equiv{ℓₗ₃}(A₃) ⦄ ⦃ equiv-B : Equiv{ℓₗ₄}(B) ⦄ (_▫_▫_ : A₁ → A₂ → A₃ → B) where record TrinaryOperator : Type{Lvl.of(A₁) Lvl.⊔ Lvl.of(A₂) Lvl.⊔ Lvl.of(A₃) Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓₗ₄} where constructor intro field congruence : Congruence₃(_▫_▫_) congruence₃ = inst-fn TrinaryOperator.congruence
35.531646
123
0.639473
4141c6d76f09648c38b9447d6139daa716cdf2b3
465
agda
Agda
Cubical/Data/DescendingList/Strict.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/DescendingList/Strict.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/DescendingList/Strict.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
------------------------------------------------------------------------ -- Strictly descending lists ------------------------------------------------------------------------ {-# OPTIONS --safe #-} open import Cubical.Core.Everything module Cubical.Data.DescendingList.Strict (A : Type₀) (_>_ : A → A → Type₀) where open import Cubical.Data.DescendingList.Base A _>_ renaming (_≥ᴴ_ to _>ᴴ_; ≥ᴴ[] to >ᴴ[]; ≥ᴴcons to >ᴴcons; DL to SDL) using ([]; cons) public
31
141
0.468817
1204be9268681716198cf4430218f1f2b914adc7
361
agda
Agda
test/Fail/Issue1194m.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1194m.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1194m.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where postulate D : Set module A where infixr 5 _∷_ postulate _∷_ : Set₁ → D → D module B where infix 5 _∷_ postulate _∷_ : Set₁ → Set₁ → D open A open B foo : D foo = Set ∷ Set -- Expected error: -- -- <preciseErrorLocation> -- Ambiguous name _∷_. It could refer to any one of -- A._∷_ bound at ... -- B._∷_ bound at ...
11.645161
51
0.598338
dff751554e1f92845c211b8e24d0d2cd0ace1449
337
agda
Agda
Cubical/HITs/SetTruncation/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/HITs/SetTruncation/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/SetTruncation/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{- This file contains: - Definition of set truncations -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.SetTruncation.Base where open import Cubical.Core.Primitives -- set truncation as a higher inductive type: data ∥_∥₀ {ℓ} (A : Type ℓ) : Type ℓ where ∣_∣₀ : A → ∥ A ∥₀ squash₀ : ∀ (x y : ∥ A ∥₀) (p q : x ≡ y) → p ≡ q
18.722222
50
0.623145
063e88b955cf19b29101d024475a8e7bc2a7dd70
51
agda
Agda
test/Succeed/Issue3991FractionalPrecedence.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3991FractionalPrecedence.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3991FractionalPrecedence.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
infix -3.14 _+_ postulate _+_ : Set → Set → Set
10.2
23
0.588235
57d48fda9d0aef6f692a88e6b96d13defe2f1a72
638
agda
Agda
test/asset/agda-stdlib-1.0/Data/Fin/Dec.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Fin/Dec.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Fin/Dec.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Decision procedures for finite sets and subsets of finite sets -- -- This module is DEPRECATED. Please use the Data.Fin.Properties -- and Data.Fin.Subset.Properties directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Fin.Dec where open import Data.Fin.Properties public using (decFinSubset; any?; all?; ¬∀⟶∃¬-smallest; ¬∀⟶∃¬) open import Data.Fin.Subset.Properties public using (_∈?_; _⊆?_; nonempty?; anySubset?) renaming (Lift? to decLift)
31.9
72
0.548589
1cafa22d9efc9d5fceec345738804c4d675e3df8
9,993
agda
Agda
src/Model/Size.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
5
2021-04-13T21:31:17.000Z
2021-06-26T06:37:31.000Z
src/Model/Size.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
src/Model/Size.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} module Model.Size where open import Relation.Binary using (Rel ; Preorder ; IsPreorder) import Data.Nat as ℕ import Data.Nat.Induction as ℕ import Data.Nat.Properties as ℕ import Relation.Binary.Construct.On as On open import Model.RGraph as RG using (RGraph) open import Source.Size as S using (Δ ; Ω) open import Source.Size.Substitution.Universe using (⟨_⟩ ; Sub⊢ᵤ) open import Util.HoTT.HLevel open import Util.Induction.WellFounded as WFInd using (Acc ; acc ; WellFounded) open import Util.Prelude import Source.Size.Substitution.Canonical as SC import Source.Size.Substitution.Universe as S open S.Ctx open S.Size open S.Sub open S.Sub⊢ᵤ open S.Var open S._<_ hiding (<-trans) infix 4 _<_ _≤_ private variable i j k : ℕ {- This is an encoding of the set of ordinals ℕ ∪ { ω + i | i ∈ ℕ } i.e. of the ordinals below ω*2. -} data Size : Set where zero+ : (i : ℕ) → Size ∞+ : (i : ℕ) → Size variable n m o : Size nat : ℕ → Size nat = zero+ abstract zero+-inj : zero+ i ≡ zero+ j → i ≡ j zero+-inj refl = refl zero+-≡-canon : (p : zero+ i ≡ zero+ j) → p ≡ cong zero+ (zero+-inj p) zero+-≡-canon refl = refl ∞+-inj : ∞+ i ≡ ∞+ j → i ≡ j ∞+-inj refl = refl ∞+-≡-canon : (p : ∞+ i ≡ ∞+ j) → p ≡ cong ∞+ (∞+-inj p) ∞+-≡-canon refl = refl Size-IsSet : IsSet Size Size-IsSet {zero+ i} {zero+ j} p refl = trans (zero+-≡-canon p) (cong (cong zero+) (ℕ.≡-irrelevant _ _)) Size-IsSet {∞+ i} {∞+ j} p refl = trans (∞+-≡-canon p) (cong (cong ∞+) (ℕ.≡-irrelevant _ _)) data _<_ : (n m : Size) → Set where zero+ : (i<j : i ℕ.< j) → zero+ i < zero+ j ∞+ : (i<j : i ℕ.< j) → ∞+ i < ∞+ j zero<∞ : zero+ i < ∞+ j data _≤_ (n m : Size) : Set where reflexive : n ≡ m → n ≤ m <→≤ : n < m → n ≤ m pattern ≤-refl = reflexive refl abstract <-trans : n < m → m < o → n < o <-trans (zero+ i<j) (zero+ j<k) = zero+ (ℕ.<-trans i<j j<k) <-trans (zero+ i<j) zero<∞ = zero<∞ <-trans (∞+ i<j) (∞+ j<k) = ∞+ (ℕ.<-trans i<j j<k) <-trans zero<∞ (∞+ i<j) = zero<∞ ≤→<→< : n ≤ m → m < o → n < o ≤→<→< ≤-refl m<o = m<o ≤→<→< (<→≤ n<m) m<o = <-trans n<m m<o <→≤→< : n < m → m ≤ o → n < o <→≤→< n<m ≤-refl = n<m <→≤→< n<m (<→≤ m<o) = <-trans n<m m<o ≤-trans : n ≤ m → m ≤ o → n ≤ o ≤-trans n≤m ≤-refl = n≤m ≤-trans n≤m (<→≤ m<o) = <→≤ (≤→<→< n≤m m<o) ⟦zero⟧ ⟦∞⟧ : Size ⟦zero⟧ = zero+ 0 ⟦∞⟧ = ∞+ 0 ⟦suc⟧ : Size → Size ⟦suc⟧ (zero+ i) = zero+ (suc i) ⟦suc⟧ (∞+ i) = ∞+ (suc i) abstract ⟦zero⟧<⟦suc⟧ : ⟦zero⟧ < ⟦suc⟧ n ⟦zero⟧<⟦suc⟧ {zero+ i} = zero+ (ℕ.s≤s ℕ.z≤n) ⟦zero⟧<⟦suc⟧ {∞+ i} = zero<∞ ⟦zero⟧<⟦∞⟧ : ⟦zero⟧ < ⟦∞⟧ ⟦zero⟧<⟦∞⟧ = zero<∞ ⟦suc⟧<⟦suc⟧ : n < m → ⟦suc⟧ n < ⟦suc⟧ m ⟦suc⟧<⟦suc⟧ (zero+ i<j) = zero+ (ℕ.s≤s i<j) ⟦suc⟧<⟦suc⟧ (∞+ i<j) = ∞+ (ℕ.s≤s i<j) ⟦suc⟧<⟦suc⟧ zero<∞ = zero<∞ ⟦suc⟧<⟦∞⟧ : n < ⟦∞⟧ → ⟦suc⟧ n < ⟦∞⟧ ⟦suc⟧<⟦∞⟧ zero<∞ = zero<∞ <⟦suc⟧ : n < ⟦suc⟧ n <⟦suc⟧ {zero+ i} = zero+ (ℕ.s≤s ℕ.≤-refl) <⟦suc⟧ {∞+ i} = ∞+ (ℕ.s≤s ℕ.≤-refl) Size< : Size → Set Size< n = ∃[ m ] (m < n) mutual ⟦_⟧Δ′ : S.Ctx → Set ⟦ [] ⟧Δ′ = ⊤ ⟦ Δ ∙ n ⟧Δ′ = Σ[ δ ∈ ⟦ Δ ⟧Δ′ ] (Size< (⟦ n ⟧n′ δ)) ⟦_⟧x′ : S.Var Δ → ⟦ Δ ⟧Δ′ → Size ⟦ zero ⟧x′ (δ , n , _) = n ⟦ suc x ⟧x′ (δ , _ , _) = ⟦ x ⟧x′ δ ⟦_⟧n′ : S.Size Δ → ⟦ Δ ⟧Δ′ → Size ⟦ var x ⟧n′ = ⟦ x ⟧x′ ⟦ ∞ ⟧n′ _ = ⟦∞⟧ ⟦ zero ⟧n′ _ = ⟦zero⟧ ⟦ suc n ⟧n′ = ⟦suc⟧ ∘ ⟦ n ⟧n′ abstract ⟦wk⟧ : ∀ (n m : S.Size Δ) {δ} → ⟦ S.wk {n = n} m ⟧n′ δ ≡ ⟦ m ⟧n′ (proj₁ δ) ⟦wk⟧ n (var x) = refl ⟦wk⟧ n ∞ = refl ⟦wk⟧ n zero = refl ⟦wk⟧ n (suc m) = cong ⟦suc⟧ (⟦wk⟧ n m) ⟦<⟧ₓ : ∀ (x : S.Var Δ) {δ} → ⟦ x ⟧x′ δ < ⟦ S.bound x ⟧n′ δ ⟦<⟧ₓ {Δ ∙ n} zero {δ , m , m<n} = subst (m <_) (sym (⟦wk⟧ n n)) m<n ⟦<⟧ₓ {Δ ∙ n} (suc x) {δ , m , m<n} = subst (⟦ x ⟧x′ δ <_) (sym (⟦wk⟧ n (S.bound x))) (⟦<⟧ₓ x) ⟦<⟧ : ∀ {n m : S.Size Δ} {δ} → n S.< m → ⟦ n ⟧n′ δ < ⟦ m ⟧n′ δ ⟦<⟧ (var {x = x} refl) = ⟦<⟧ₓ x ⟦<⟧ zero<suc = ⟦zero⟧<⟦suc⟧ ⟦<⟧ zero<∞ = ⟦zero⟧<⟦∞⟧ ⟦<⟧ (suc<suc n<m) = ⟦suc⟧<⟦suc⟧ (⟦<⟧ n<m) ⟦<⟧ (suc<∞ n<m) = ⟦suc⟧<⟦∞⟧ (⟦<⟧ n<m) ⟦<⟧ (S.<-trans n<m m<o) = <-trans (⟦<⟧ n<m) (⟦<⟧ m<o) ⟦<⟧ <suc = <⟦suc⟧ <-irrefl : ¬ n < n <-irrefl {zero+ i} (zero+ i<i) = ℕ.<⇒≢ i<i refl <-irrefl {∞+ i} (∞+ i<i) = ℕ.<⇒≢ i<i refl ≤-antisym : n ≤ m → m ≤ n → n ≡ m ≤-antisym ≤-refl m≤n = refl ≤-antisym (<→≤ n<m) m≤n = ⊥-elim (<-irrefl (<→≤→< n<m m≤n)) <-IsProp : IsProp (n < m) <-IsProp (zero+ i<j) (zero+ i<j₁) = cong zero+ (ℕ.<-irrelevant _ _) <-IsProp (∞+ i<j) (∞+ i<j₁) = cong ∞+ (ℕ.<-irrelevant _ _) <-IsProp zero<∞ zero<∞ = refl ≤-IsProp : IsProp (n ≤ m) ≤-IsProp (reflexive p) (reflexive q) = cong reflexive (Size-IsSet _ _) ≤-IsProp ≤-refl (<→≤ q) = ⊥-elim (<-irrefl q) ≤-IsProp (<→≤ p) ≤-refl = ⊥-elim (<-irrefl p) ≤-IsProp (<→≤ p) (<→≤ q) = cong <→≤ (<-IsProp p q) Size<-≡⁺ : (m k : Size< n) → proj₁ m ≡ proj₁ k → m ≡ k Size<-≡⁺ (m , _) (k , _) refl = cong (m ,_) (<-IsProp _ _) Size<-IsSet : ∀ {n} → IsSet (Size< n) Size<-IsSet = Σ-IsSet Size-IsSet λ _ → IsOfHLevel-suc 1 <-IsProp ⟦Δ⟧-IsSet : ∀ Δ → IsSet ⟦ Δ ⟧Δ′ ⟦Δ⟧-IsSet [] = ⊤-IsSet ⟦Δ⟧-IsSet (Δ ∙ n) = Σ-IsSet (⟦Δ⟧-IsSet Δ) λ _ → Size<-IsSet ⟦Δ⟧-HSet : S.Ctx → HSet 0ℓ ⟦Δ⟧-HSet Δ = HLevel⁺ _ (⟦Δ⟧-IsSet Δ) abstract ⟦Δ∙n⟧-≡⁺ : ∀ Δ (n : S.Size Δ) {δ δ′ : ⟦ Δ ⟧Δ′} {m m′ : Size} → (m<n : m < ⟦ n ⟧n′ δ) → (m′<n : m′ < ⟦ n ⟧n′ δ′) → δ ≡ δ′ → m ≡ m′ → (δ , m , m<n) ≡ (δ′ , m′ , m′<n) ⟦Δ∙n⟧-≡⁺ Δ n {δ} _ _ refl eq₂ = cong (δ ,_) (Size<-≡⁺ _ _ eq₂) zero+-<ℕ-acc→<-acc : Acc ℕ._<_ i → Acc _<_ (zero+ i) zero+-<ℕ-acc→<-acc (acc rs) = acc λ where (zero+ i) (zero+ i<j) → zero+-<ℕ-acc→<-acc (rs i i<j) zero+-acc : Acc _<_ (zero+ i) zero+-acc = zero+-<ℕ-acc→<-acc (ℕ.<-wellFounded _) ∞+-<ℕ-acc→<-acc : Acc ℕ._<_ i → Acc _<_ (∞+ i) ∞+-<ℕ-acc→<-acc (acc rs) = acc λ where (∞+ i) (∞+ i<j) → ∞+-<ℕ-acc→<-acc (rs i i<j) (zero+ i) zero<∞ → zero+-acc ∞+-acc : Acc _<_ (∞+ i) ∞+-acc = ∞+-<ℕ-acc→<-acc (ℕ.<-wellFounded _) <-wf : WellFounded _<_ <-wf m = acc λ where _ (zero+ i<j) → zero+-acc _ (∞+ i<j) → ∞+-acc _ zero<∞ → zero+-acc open WFInd.Build <-wf public using () renaming ( wfInd to <-ind ; wfRec to <-rec ; wfInd-unfold to <-ind-unfold ; wfRec-unfold to <-rec-unfold ; wfInd-ind to <-ind-ind ; wfIndΣ to <-indΣ ; wfIndΣ-unfold to <-indΣ-unfold ; wfIndΣ′ to <-indΣ′ ) <-ind-ind₂ = WFInd.wfInd-ind₂ <-wf mutual ⟦_⟧σ′ : ∀ {σ} → σ ∶ Δ ⇒ᵤ Ω → ⟦ Δ ⟧Δ′ → ⟦ Ω ⟧Δ′ ⟦ Id ⟧σ′ δ = δ ⟦ comp σ τ ⟧σ′ δ = ⟦ τ ⟧σ′ (⟦ σ ⟧σ′ δ) ⟦ Wk ⟧σ′ (δ , m) = δ ⟦ Lift {n = n} σ refl ⟧σ′ (δ , m , m<n) = ⟦ σ ⟧σ′ δ , m , subst (m <_) (⟦sub⟧ σ n) m<n ⟦ Sing {n = n} n<m ⟧σ′ δ = δ , ⟦ n ⟧n′ δ , ⟦<⟧ n<m ⟦ Skip ⟧σ′ ((δ , m , m<n) , k , k<m) = δ , k , <-trans k<m m<n abstract ⟦subV′⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (x : S.Var Ω) {δ} → ⟦ S.subV′ σ x ⟧n′ δ ≡ ⟦ x ⟧x′ (⟦ ⊢σ ⟧σ′ δ) ⟦subV′⟧ Id x = refl ⟦subV′⟧ (comp {σ = σ} {τ = τ} ⊢σ ⊢τ) x = trans (⟦sub′⟧ ⊢σ (S.subV′ τ x)) (⟦subV′⟧ ⊢τ x) ⟦subV′⟧ Wk x = refl ⟦subV′⟧ (Lift ⊢σ refl) zero {δ , m} = refl ⟦subV′⟧ (Lift {σ = σ} {n = n} ⊢σ refl) (suc x) {δ , m} rewrite ⟦wk⟧ (S.sub σ n) (S.subV′ σ x) {δ , m} = ⟦subV′⟧ ⊢σ x ⟦subV′⟧ (Sing n<m) zero = refl ⟦subV′⟧ (Sing n<m) (suc x) = refl ⟦subV′⟧ Skip zero = refl ⟦subV′⟧ Skip (suc x) = refl ⟦sub′⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (n : S.Size Ω) {δ} → ⟦ S.sub′ σ n ⟧n′ δ ≡ ⟦ n ⟧n′ (⟦ ⊢σ ⟧σ′ δ) ⟦sub′⟧ σ (var x) = ⟦subV′⟧ σ x ⟦sub′⟧ σ ∞ = refl ⟦sub′⟧ σ zero = refl ⟦sub′⟧ σ (suc n) = cong ⟦suc⟧ (⟦sub′⟧ σ n) ⟦sub⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (n : S.Size Ω) {δ} → ⟦ S.sub σ n ⟧n′ δ ≡ ⟦ n ⟧n′ (⟦ ⊢σ ⟧σ′ δ) ⟦sub⟧ {σ = σ} ⊢σ n {δ} = trans (cong (λ k → ⟦ k ⟧n′ δ) (sym (S.sub′≡sub σ n))) (⟦sub′⟧ ⊢σ n) abstract ⟦subV⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (x : S.Var Ω) {δ} → ⟦ S.subV σ x ⟧n′ δ ≡ ⟦ x ⟧x′ (⟦ ⊢σ ⟧σ′ δ) ⟦subV⟧ {σ = σ} ⊢σ x {δ} = trans (cong (λ k → ⟦ k ⟧n′ δ) (sym (S.subV′≡subV σ x))) (⟦subV′⟧ ⊢σ x) ⟦⟧σ-param : ∀ {σ} (p q : σ ∶ Δ ⇒ᵤ Ω) {δ} → ⟦ p ⟧σ′ δ ≡ ⟦ q ⟧σ′ δ ⟦⟧σ-param Id Id = refl ⟦⟧σ-param (comp p p′) (comp q q′) = trans (⟦⟧σ-param p′ q′) (cong (⟦ q′ ⟧σ′) (⟦⟧σ-param p q)) ⟦⟧σ-param Wk Wk = refl ⟦⟧σ-param {Ω = Ω ∙ m} (Lift p refl) (Lift q m≡n[σ]₁) rewrite S.Size-IsSet m≡n[σ]₁ refl = ⟦Δ∙n⟧-≡⁺ Ω m _ _ (⟦⟧σ-param p q) refl ⟦⟧σ-param {Δ = Δ} {σ = Sing {m = m} n} (Sing n<m) (Sing n<m₁) = ⟦Δ∙n⟧-≡⁺ Δ m (⟦<⟧ n<m) (⟦<⟧ n<m₁) refl refl ⟦⟧σ-param Skip Skip = refl ⟦_⟧Δ : S.Ctx → RGraph ⟦ Δ ⟧Δ = record { ObjHSet = ⟦Δ⟧-HSet Δ ; eqHProp = λ _ _ → ⊤-HProp } Sizes : RGraph Sizes = record { ObjHSet = HLevel⁺ Size Size-IsSet ; eqHProp = λ _ _ → ⊤-HProp } ⟦_⟧n : ∀ {Δ} (n : S.Size Δ) → ⟦ Δ ⟧Δ RG.⇒ Sizes ⟦ n ⟧n = record { fobj = ⟦ n ⟧n′ } ⟦_⟧σ : ∀ {Δ Ω σ} → σ ∶ Δ ⇒ᵤ Ω → ⟦ Δ ⟧Δ RG.⇒ ⟦ Ω ⟧Δ ⟦ σ ⟧σ = record { fobj = ⟦ σ ⟧σ′ } data _≤′_ : (n m : Size) → Set where zero+ : (i≤j : i ℕ.≤ j) → zero+ i ≤′ zero+ j ∞+ : (i≤j : i ℕ.≤ j) → ∞+ i ≤′ ∞+ j zero<∞ : zero+ i ≤′ ∞+ j abstract ≤→≤′ : n ≤ m → n ≤′ m ≤→≤′ {zero+ i} ≤-refl = zero+ ℕ.≤-refl ≤→≤′ {∞+ i} ≤-refl = ∞+ ℕ.≤-refl ≤→≤′ (<→≤ (zero+ i<j)) = zero+ (ℕ.<⇒≤ i<j) ≤→≤′ (<→≤ (∞+ i<j)) = ∞+ (ℕ.<⇒≤ i<j) ≤→≤′ (<→≤ zero<∞) = zero<∞ ≤′→≤ : n ≤′ m → n ≤ m ≤′→≤ (zero+ i≤j) with ℕ.≤⇒≤′ i≤j ... | ℕ.≤′-refl = ≤-refl ... | ℕ.≤′-step i≤′j = <→≤ (zero+ (ℕ.s≤s (ℕ.≤′⇒≤ i≤′j))) ≤′→≤ (∞+ i≤j) with ℕ.≤⇒≤′ i≤j ... | ℕ.≤′-refl = ≤-refl ... | ℕ.≤′-step i≤′j = <→≤ (∞+ (ℕ.s≤s (ℕ.≤′⇒≤ i≤′j))) ≤′→≤ zero<∞ = <→≤ zero<∞ 0≤n : ⟦zero⟧ ≤ n 0≤n {zero+ zero} = ≤-refl 0≤n {zero+ (suc i)} = <→≤ (zero+ (ℕ.s≤s ℕ.z≤n)) 0≤n {∞+ i} = <→≤ zero<∞ n<m→Sn≤m : n < m → ⟦suc⟧ n ≤ m n<m→Sn≤m (zero+ (ℕ.s≤s i≤j)) = ≤′→≤ (zero+ (ℕ.s≤s i≤j)) n<m→Sn≤m (∞+ (ℕ.s≤s i≤j)) = ≤′→≤ (∞+ (ℕ.s≤s i≤j)) n<m→Sn≤m zero<∞ = <→≤ zero<∞ Sn≤m→n<m : ⟦suc⟧ n ≤ m → n < m Sn≤m→n<m ≤-refl = <⟦suc⟧ Sn≤m→n<m (<→≤ Sn<m) = <-trans <⟦suc⟧ Sn<m
23.624113
79
0.437806
fb0386356025361e7dbd82d2231c0cc6de643c82
674
agda
Agda
test/Compiler/simple/Issue1126.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/Issue1126.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/Issue1126.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-07-28, issue #1126 reported by Saizan is fixed data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ {-# BUILTIN NATURAL ℕ #-} data Unit : Set where unit : Unit slow : ℕ → Unit slow zero = unit slow (suc n) = slow n postulate IO : Set → Set {-# COMPILE GHC IO = type IO #-} {-# BUILTIN IO IO #-} postulate return : ∀ {A} → A → IO A {-# COMPILE GHC return = (\ _ -> return) #-} {-# COMPILE JS return = function(u0) { return function(u1) { return function(x) { return function(cb) { cb(x); }; }; }; } #-} force : Unit → IO Unit force unit = return unit n = 3000000000 main : IO Unit main = force (slow n) -- Should terminate instantaneously.
19.257143
105
0.603858
41718b3fbf52c79534f4fcef2287040285ce0761
13,097
agda
Agda
theorems/homotopy/PtdAdjoint.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
theorems/homotopy/PtdAdjoint.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
theorems/homotopy/PtdAdjoint.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT {- The pseudo-adjoint functors F,G : Ptd → Ptd - It stops at composition and ignores - all the higher associahedrons. -} module homotopy.PtdAdjoint where record PtdFunctor i j : Type (lsucc (lmax i j)) where field obj : Ptd i → Ptd j arr : {X Y : Ptd i} → fst (X ⊙→ Y) → fst (obj X ⊙→ obj Y) id : (X : Ptd i) → arr (⊙idf X) == ⊙idf (obj X) comp : {X Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y)) → arr (g ⊙∘ f) == arr g ⊙∘ arr f {- counit-unit description of F ⊣ G -} record CounitUnitAdjoint {i j} (F : PtdFunctor i j) (G : PtdFunctor j i) : Type (lsucc (lmax i j)) where private module F = PtdFunctor F module G = PtdFunctor G field η : (X : Ptd i) → fst (X ⊙→ G.obj (F.obj X)) ε : (U : Ptd j) → fst (F.obj (G.obj U) ⊙→ U) η-natural : {X Y : Ptd i} (h : fst (X ⊙→ Y)) → η Y ⊙∘ h == G.arr (F.arr h) ⊙∘ η X ε-natural : {U V : Ptd j} (k : fst (U ⊙→ V)) → ε V ⊙∘ F.arr (G.arr k) == k ⊙∘ ε U εF-Fη : (X : Ptd i) → ε (F.obj X) ⊙∘ F.arr (η X) == ⊙idf (F.obj X) Gε-ηG : (U : Ptd j) → G.arr (ε U) ⊙∘ η (G.obj U) == ⊙idf (G.obj U) {- hom-set isomorphism description of F ⊣ G -} record HomAdjoint {i j} (F : PtdFunctor i j) (G : PtdFunctor j i) : Type (lsucc (lmax i j)) where private module F = PtdFunctor F module G = PtdFunctor G field eq : (X : Ptd i) (U : Ptd j) → fst (F.obj X ⊙→ U) ≃ fst (X ⊙→ G.obj U) nat-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j) (r : fst (F.obj Y ⊙→ U)) → –> (eq Y U) r ⊙∘ h == –> (eq X U) (r ⊙∘ F.arr h) nat-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V)) (r : fst (F.obj X ⊙→ U)) → G.arr k ⊙∘ –> (eq X U) r == –> (eq X V) (k ⊙∘ r) nat!-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j) (s : fst (Y ⊙→ G.obj U)) → <– (eq Y U) s ⊙∘ F.arr h == <– (eq X U) (s ⊙∘ h) nat!-dom {X} {Y} h U s = ! (<–-inv-l (eq X U) (<– (eq Y U) s ⊙∘ F.arr h)) ∙ ap (<– (eq X U)) (! (nat-dom h U (<– (eq Y U) s))) ∙ ap (λ w → <– (eq X U) (w ⊙∘ h)) (<–-inv-r (eq Y U) s) nat!-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V)) (s : fst (X ⊙→ G.obj U)) → k ⊙∘ <– (eq X U) s == <– (eq X V) (G.arr k ⊙∘ s) nat!-cod X {U} {V} k s = ! (<–-inv-l (eq X V) (k ⊙∘ <– (eq X U) s)) ∙ ap (<– (eq X V)) (! (nat-cod X k (<– (eq X U) s))) ∙ ap (λ w → <– (eq X V) (G.arr k ⊙∘ w)) (<–-inv-r (eq X U) s) counit-unit-to-hom : ∀ {i j} {F : PtdFunctor i j} {G : PtdFunctor j i} → CounitUnitAdjoint F G → HomAdjoint F G counit-unit-to-hom {i} {j} {F} {G} adj = record { eq = eq; nat-dom = nat-dom; nat-cod = nat-cod} where module F = PtdFunctor F module G = PtdFunctor G open CounitUnitAdjoint adj module _ (X : Ptd i) (U : Ptd j) where into : fst (F.obj X ⊙→ U) → fst (X ⊙→ G.obj U) into r = G.arr r ⊙∘ η X out : fst (X ⊙→ G.obj U) → fst (F.obj X ⊙→ U) out s = ε U ⊙∘ F.arr s into-out : (s : fst (X ⊙→ G.obj U)) → into (out s) == s into-out s = G.arr (ε U ⊙∘ F.arr s) ⊙∘ η X =⟨ G.comp (ε U) (F.arr s) |in-ctx (λ w → w ⊙∘ η X) ⟩ (G.arr (ε U) ⊙∘ G.arr (F.arr s)) ⊙∘ η X =⟨ ⊙∘-assoc (G.arr (ε U)) (G.arr (F.arr s)) (η X) ⟩ G.arr (ε U) ⊙∘ G.arr (F.arr s) ⊙∘ η X =⟨ ! (η-natural s) |in-ctx (λ w → G.arr (ε U) ⊙∘ w) ⟩ G.arr (ε U) ⊙∘ η (G.obj U) ⊙∘ s =⟨ ! (⊙∘-assoc (G.arr (ε U)) (η (G.obj U)) s) ⟩ (G.arr (ε U) ⊙∘ η (G.obj U)) ⊙∘ s =⟨ Gε-ηG U |in-ctx (λ w → w ⊙∘ s) ⟩ ⊙idf (G.obj U) ⊙∘ s =⟨ ⊙∘-unit-l s ⟩ s ∎ out-into : (r : fst (F.obj X ⊙→ U)) → out (into r) == r out-into r = ε U ⊙∘ F.arr (G.arr r ⊙∘ η X) =⟨ F.comp (G.arr r) (η X) |in-ctx (λ w → ε U ⊙∘ w) ⟩ ε U ⊙∘ F.arr (G.arr r) ⊙∘ F.arr (η X) =⟨ ! (⊙∘-assoc (ε U) (F.arr (G.arr r)) (F.arr (η X))) ⟩ (ε U ⊙∘ F.arr (G.arr r)) ⊙∘ F.arr (η X) =⟨ ε-natural r |in-ctx (λ w → w ⊙∘ F.arr (η X)) ⟩ (r ⊙∘ ε (F.obj X)) ⊙∘ F.arr (η X) =⟨ ⊙∘-assoc r (ε (F.obj X)) (F.arr (η X)) ⟩ r ⊙∘ ε (F.obj X) ⊙∘ F.arr (η X) =⟨ εF-Fη X |in-ctx (λ w → r ⊙∘ w) ⟩ r ∎ eq : fst (F.obj X ⊙→ U) ≃ fst (X ⊙→ G.obj U) eq = equiv into out into-out out-into nat-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j) (r : fst (F.obj Y ⊙→ U)) → –> (eq Y U) r ⊙∘ h == –> (eq X U) (r ⊙∘ F.arr h) nat-dom {X} {Y} h U r = (G.arr r ⊙∘ η Y) ⊙∘ h =⟨ ⊙∘-assoc (G.arr r) (η Y) h ⟩ G.arr r ⊙∘ η Y ⊙∘ h =⟨ η-natural h |in-ctx (λ w → G.arr r ⊙∘ w) ⟩ G.arr r ⊙∘ G.arr (F.arr h) ⊙∘ η X =⟨ ! (⊙∘-assoc (G.arr r) (G.arr (F.arr h)) (η X)) ⟩ (G.arr r ⊙∘ G.arr (F.arr h)) ⊙∘ η X =⟨ ! (G.comp r (F.arr h)) |in-ctx (λ w → w ⊙∘ η X) ⟩ G.arr (r ⊙∘ F.arr h) ⊙∘ η X ∎ nat-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V)) (r : fst (F.obj X ⊙→ U)) → G.arr k ⊙∘ –> (eq X U) r == –> (eq X V) (k ⊙∘ r) nat-cod X k r = G.arr k ⊙∘ (G.arr r ⊙∘ η X) =⟨ ! (⊙∘-assoc (G.arr k) (G.arr r) (η X)) ⟩ (G.arr k ⊙∘ G.arr r) ⊙∘ η X =⟨ ! (G.comp k r) |in-ctx (λ w → w ⊙∘ η X) ⟩ G.arr (k ⊙∘ r) ⊙∘ η X ∎ {- a right adjoint preserves products -} module RightAdjoint× {i j} {F : PtdFunctor i j} {G : PtdFunctor j i} (adj : HomAdjoint F G) (U V : Ptd j) where private module F = PtdFunctor F module G = PtdFunctor G module A = HomAdjoint adj ⊙into : fst (G.obj (U ⊙× V) ⊙→ G.obj U ⊙× G.obj V) ⊙into = ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd) ⊙out : fst (G.obj U ⊙× G.obj V ⊙→ G.obj (U ⊙× V)) ⊙out = –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ⊙into-out : ⊙into ⊙∘ ⊙out == ⊙idf _ ⊙into-out = ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd) ⊙∘ ⊙out =⟨ ⊙×-in-pre∘ (G.arr ⊙fst) (G.arr ⊙snd) ⊙out ⟩ ⊙×-in (G.arr ⊙fst ⊙∘ ⊙out) (G.arr ⊙snd ⊙∘ ⊙out) =⟨ ap2 ⊙×-in (A.nat-cod _ ⊙fst (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ∙ ap (–> (A.eq _ _)) (⊙fst-⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ∙ <–-inv-r (A.eq _ _) ⊙fst) (A.nat-cod _ ⊙snd (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ∙ ap (–> (A.eq _ _)) (⊙snd-⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ∙ <–-inv-r (A.eq _ _) ⊙snd) ⟩ ⊙×-in ⊙fst ⊙snd ∎ ⊙out-into : ⊙out ⊙∘ ⊙into == ⊙idf _ ⊙out-into = –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ⊙∘ ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd) =⟨ A.nat-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _ (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ⟩ –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd) ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))) =⟨ ⊙×-in-pre∘ (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd) (F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))) |in-ctx –> (A.eq _ _) ⟩ –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))) (<– (A.eq _ _) ⊙snd ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)))) =⟨ ap2 (λ f g → –> (A.eq _ _) (⊙×-in f g)) (A.nat!-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _ ⊙fst ∙ ap (<– (A.eq _ _)) (⊙fst-⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) ∙ ! (A.nat!-cod _ ⊙fst (⊙idf _))) (A.nat!-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _ ⊙snd ∙ ap (<– (A.eq _ _)) (⊙snd-⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) ∙ ! (A.nat!-cod _ ⊙snd (⊙idf _))) ⟩ –> (A.eq _ _) (⊙×-in (⊙fst ⊙∘ <– (A.eq _ _) (⊙idf _)) (⊙snd ⊙∘ <– (A.eq _ _) (⊙idf _))) =⟨ ap (–> (A.eq _ _)) (! (⊙×-in-pre∘ ⊙fst ⊙snd (<– (A.eq _ _) (⊙idf _)))) ⟩ –> (A.eq _ _) (⊙×-in ⊙fst ⊙snd ⊙∘ <– (A.eq _ _) (⊙idf _)) =⟨ ⊙∘-unit-l _ |in-ctx –> (A.eq _ _) ⟩ –> (A.eq _ _) (<– (A.eq _ _) (⊙idf _)) =⟨ <–-inv-r (A.eq _ _) (⊙idf _) ⟩ ⊙idf _ ∎ ⊙eq : G.obj (U ⊙× V) ⊙≃ G.obj U ⊙× G.obj V ⊙eq = ⊙≃-in (equiv (fst ⊙into) (fst ⊙out) (app= (ap fst ⊙into-out)) (app= (ap fst ⊙out-into))) (snd ⊙into) ⊙path = ⊙ua ⊙eq {- Using the equivalence in RightAdjoint× we get a binary - "G.arr2" : (X × Y → Z) → (G X × G Y → G Z) - and there is some kind of naturality wrt the (FX→Y)≃(X→GY) equivalence - (use case: from ⊙ap we get ⊙ap2) -} module RightAdjointBinary {i j} {F : PtdFunctor i j} {G : PtdFunctor j i} (adj : HomAdjoint F G) where private module F = PtdFunctor F module G = PtdFunctor G module A = HomAdjoint adj module A× = RightAdjoint× adj arr2 : {X Y Z : Ptd j} → fst (X ⊙× Y ⊙→ Z) → fst (G.obj X ⊙× G.obj Y ⊙→ G.obj Z) arr2 {X} {Y} {Z} f = G.arr f ⊙∘ A×.⊙out X Y nat-cod : {X : Ptd i} {Y Z W : Ptd j} (r₁ : fst (F.obj X ⊙→ Y)) (r₂ : fst (F.obj X ⊙→ Z)) (o : fst (Y ⊙× Z ⊙→ W)) → –> (A.eq X W) (o ⊙∘ ⊙×-in r₁ r₂) == arr2 o ⊙∘ ⊙×-in (–> (A.eq X Y) r₁) (–> (A.eq X Z) r₂) nat-cod {X} {Y} {Z} {W} r₁ r₂ o = –> (A.eq X W) (o ⊙∘ ⊙×-in r₁ r₂) =⟨ ! (A.nat-cod X o (⊙×-in r₁ r₂)) ⟩ G.arr o ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂) =⟨ ! (A×.⊙out-into Y Z) |in-ctx (λ w → (G.arr o ⊙∘ w) ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) ⟩ (G.arr o ⊙∘ (A×.⊙out Y Z ⊙∘ A×.⊙into Y Z)) ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂) =⟨ ⊙∘-assoc-lemma (G.arr o) (A×.⊙out Y Z) (A×.⊙into Y Z) (–> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) ⟩ arr2 o ⊙∘ A×.⊙into Y Z ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂) =⟨ ⊙×-in-pre∘ (G.arr ⊙fst) (G.arr ⊙snd) (–> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) |in-ctx (λ w → arr2 o ⊙∘ w) ⟩ arr2 o ⊙∘ ⊙×-in (G.arr ⊙fst ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) (G.arr ⊙snd ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) =⟨ ap2 (λ w₁ w₂ → arr2 o ⊙∘ ⊙×-in w₁ w₂) (A.nat-cod X ⊙fst (⊙×-in r₁ r₂) ∙ ap (–> (A.eq X Y)) (⊙fst-⊙×-in r₁ r₂)) (A.nat-cod X ⊙snd (⊙×-in r₁ r₂) ∙ ap (–> (A.eq X Z)) (⊙snd-⊙×-in r₁ r₂)) ⟩ arr2 o ⊙∘ ⊙×-in (–> (A.eq X Y) r₁) (–> (A.eq X Z) r₂) ∎ where ⊙∘-assoc-lemma : ∀ {i j k l m} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {U : Ptd l} {V : Ptd m} (k : fst (U ⊙→ V)) (h : fst (Z ⊙→ U)) (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y)) → (k ⊙∘ (h ⊙∘ g)) ⊙∘ f == (k ⊙∘ h) ⊙∘ g ⊙∘ f ⊙∘-assoc-lemma (k , idp) (h , idp) (g , idp) (f , idp) = idp {- a left adjoint preserves wedges -} module LeftAdjoint∨ {i j} {F : PtdFunctor i j} {G : PtdFunctor j i} (adj : HomAdjoint F G) (U V : Ptd i) where private module F = PtdFunctor F module G = PtdFunctor G module A = HomAdjoint adj module Into = ⊙WedgeRec (F.arr ⊙winl) (F.arr ⊙winr) ⊙into : fst (F.obj U ⊙∨ F.obj V ⊙→ F.obj (U ⊙∨ V)) ⊙into = Into.⊙f module OutHelp = ⊙WedgeRec (–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr) ⊙out : fst (F.obj (U ⊙∨ V) ⊙→ F.obj U ⊙∨ F.obj V) ⊙out = <– (A.eq _ _) OutHelp.⊙f ⊙into-out : ⊙into ⊙∘ ⊙out == ⊙idf _ ⊙into-out = ⊙into ⊙∘ ⊙out =⟨ A.nat!-cod _ ⊙into (⊙wedge-rec (–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr)) ⟩ <– (A.eq _ _) (G.arr ⊙into ⊙∘ ⊙wedge-rec (–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr)) =⟨ ap (<– (A.eq _ _)) (⊙wedge-rec-post∘ (G.arr ⊙into) (–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr)) ⟩ <– (A.eq _ _) (⊙wedge-rec (G.arr ⊙into ⊙∘ –> (A.eq _ _) ⊙winl) (G.arr ⊙into ⊙∘ –> (A.eq _ _) ⊙winr)) =⟨ ap2 (λ w₁ w₂ → <– (A.eq _ _) (⊙wedge-rec w₁ w₂)) (A.nat-cod _ ⊙into ⊙winl ∙ ap (–> (A.eq _ _)) (Into.⊙winl-β ∙ ! (⊙∘-unit-l _)) ∙ ! (A.nat-dom ⊙winl _ (⊙idf _))) (A.nat-cod _ ⊙into ⊙winr ∙ ap (–> (A.eq _ _)) (Into.⊙winr-β ∙ ! (⊙∘-unit-l _)) ∙ ! (A.nat-dom ⊙winr _ (⊙idf _))) ⟩ <– (A.eq _ _) (⊙wedge-rec (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙winl) (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙winr)) =⟨ ap (<– (A.eq _ _)) (! (⊙wedge-rec-post∘ (–> (A.eq _ _) (⊙idf _)) ⊙winl ⊙winr)) ⟩ <– (A.eq _ _) (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙wedge-rec ⊙winl ⊙winr) =⟨ ap (λ w → <– (A.eq _ _) (–> (A.eq _ _) (⊙idf _) ⊙∘ w)) ⊙wedge-rec-η ⟩ <– (A.eq _ _) (–> (A.eq _ _) (⊙idf _)) =⟨ <–-inv-l (A.eq _ _) (⊙idf _) ⟩ ⊙idf _ ∎ ⊙out-into : ⊙out ⊙∘ ⊙into == ⊙idf _ ⊙out-into = ⊙out ⊙∘ ⊙wedge-rec (F.arr ⊙winl) (F.arr ⊙winr) =⟨ ⊙wedge-rec-post∘ ⊙out (F.arr ⊙winl) (F.arr ⊙winr) ⟩ ⊙wedge-rec (⊙out ⊙∘ F.arr ⊙winl) (⊙out ⊙∘ F.arr ⊙winr) =⟨ ap2 ⊙wedge-rec (A.nat!-dom ⊙winl _ (⊙wedge-rec _ _) ∙ ap (<– (A.eq _ _)) OutHelp.⊙winl-β ∙ <–-inv-l (A.eq _ _) ⊙winl) (A.nat!-dom ⊙winr _ (⊙wedge-rec _ _) ∙ ap (<– (A.eq _ _)) OutHelp.⊙winr-β ∙ <–-inv-l (A.eq _ _) ⊙winr) ⟩ ⊙wedge-rec ⊙winl ⊙winr =⟨ ⊙wedge-rec-η ⟩ ⊙idf _ ∎ ⊙eq : F.obj U ⊙∨ F.obj V ⊙≃ F.obj (U ⊙∨ V) ⊙eq = ⊙≃-in (equiv (fst ⊙into) (fst ⊙out) (app= (ap fst ⊙into-out)) (app= (ap fst ⊙out-into))) (snd ⊙into) ⊙path = ⊙ua ⊙eq
38.295322
82
0.409025
1da84d002549e905f63b2d5bfeab67f3f266187f
3,329
agda
Agda
archive/agda-2/Oscar/Class/Substitute.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-2/Oscar/Class/Substitute.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-2/Oscar/Class/Substitute.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module Oscar.Class.Substitute where open import Oscar.Class.Substitution open import Oscar.Data.Equality open import Oscar.Function open import Oscar.Relation open import Oscar.Level record Substitute {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) {d} (D : A → Set d) : Set (a ⊔ b ⊔ c ⊔ d) where field ⦃ substitution ⦄ : Substitution B C _◃_ : ∀ {m n} → (B m → C n) → m ⟨ D ⟩→ n ◃-identity : ∀ {m} → (x : D m) → ε ◃ x ≡ x ◃-associativity : ∀ {l m n} (f : B l → C m) (g : B m → C n) (t : D l) → (g ◇ f) ◃ t ≡ g ◃ (f ◃ t) ◃-extensionality : ∀ {m n} {f g : B m → C n} → f ≡̇ g → f ◃_ ≡̇ g ◃_ open Substitute ⦃ … ⦄ public {-# DISPLAY Substitute._◃_ _ = _◃_ #-} instance Substitute-id : ∀ {a} {A : Set a} {bcd} {BCD : A → Set bcd} → Substitute BCD BCD BCD Substitute.substitution Substitute-id = Substitution-id Substitute._◃_ Substitute-id = id Substitute.◃-identity Substitute-id _ = refl Substitute.◃-associativity Substitute-id _ _ _ = refl Substitute.◃-extensionality Substitute-id f≡̇g = f≡̇g -- record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) {d} (D : A → Set d) : Set (a ⊔ b ⊔ c ⊔ d) where -- field -- _◃_ : ∀ {m n} → (B m → C n) → m ⟨ D ⟩→ n -- ε : ∀ {m} → B m → C m -- ◃-identity : ∀ {m} → (x : D m) → ε ◃ x ≡ x -- _◇_ : ∀ {l m n} → (g : B m → C n) (f : B l → C m) → B l → C n -- ◃-associativity : ∀ {l m n} → {f : B m → C n} {g : B l → C m} (t : D l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t) -- ◃-extensionality : ∀ {m n} {f g : B m → C n} → f ≡̇ g → f ◃_ ≡̇ g ◃_ -- {- -- Unifies : ∀ {m} (s t : A m) → Property m -- Unifies s t f = f ◃ s ≡ f ◃ t -- -} -- open Substitution ⦃ … ⦄ public -- -- record Substitution {a} {A : Set a} {b} (S : A → A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where -- -- field -- -- _◃_ : ∀ {m n} → S m n → m ⟨ C ⟩→ n -- -- ε : ∀ {m} → S m m -- -- ◃-identity : ∀ {m} → (x : C m) → ε ◃ x ≡ x -- -- _◇_ : ∀ {l m n} → S m n → S l m → S l n -- -- field -- -- ◃-associativity : ∀ {l m n} → {f : S m n} {g : S l m} (t : C l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t) -- -- ◃-extensionality : ∀ {m n} {f g : S m n} → f ≡ g → f ◃_ ≡̇ g ◃_ -- -- open Substitution ⦃ … ⦄ public -- -- -- record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where -- -- -- field -- -- -- _◃_ : ∀ {m n} → (B m → C n) → m ⟨ C ⟩→ n -- -- -- ε : ∀ {m} → B m → C m -- -- -- ◃-identity : ∀ {m} → (x : C m) → ε ◃ x ≡ x -- -- -- _◇_ : ∀ {l m n} → (f : B m → C n) (g : B l → C m) → B l → C n -- -- -- _◇_ f g = (f ◃_) ∘ g -- -- -- field -- -- -- ◃-associativity : ∀ {l m n} → {f : B m → C n} {g : B l → C m} (t : C l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t) -- -- -- ◃-extensionality : ∀ {m n} {f g : B m → C n} → f ≡̇ g → f ◃_ ≡̇ g ◃_ -- -- -- {- -- -- -- Unifies : ∀ {m} (s t : A m) → Property m -- -- -- Unifies s t f = f ◃ s ≡ f ◃ t -- -- -- -} -- -- -- open Substitution ⦃ … ⦄ public -- -- -- instance Substitution⋆ : ∀ {a} {A : Set a} {bc} {BC : A → Set bc} → Substitution BC BC -- -- -- Substitution._◃_ Substitution⋆ = id -- -- -- Substitution.ε Substitution⋆ = id -- -- -- Substitution.◃-identity Substitution⋆ _ = refl -- -- -- Substitution.◃-associativity Substitution⋆ _ = refl -- -- -- Substitution.◃-extensionality Substitution⋆ f≡̇g x = f≡̇g x
39.630952
126
0.452989
2fe5dcbc59aa5c9f8d403789232ea55e970620a6
8,173
agda
Agda
Cubical/Foundations/Logic.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Foundations/Logic.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Foundations/Logic.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Foundations.Logic where import Cubical.Data.Empty as D import Cubical.Data.Prod as D import Cubical.Data.Sum as D import Cubical.Data.Unit as D open import Cubical.Foundations.Prelude open import Cubical.HITs.PropositionalTruncation open import Cubical.Foundations.HLevels using (hProp; ΣProp≡; isPropIsProp; propPi) public open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Function open import Cubical.Relation.Nullary hiding (¬_) infix 10 ¬_ infixr 8 _⊔_ infixr 8 _⊔′_ infixr 8 _⊓_ infixr 8 _⊓′_ infixr 6 _⇒_ infixr 4 _⇔_ infix 30 _≡ₚ_ infix 30 _≢ₚ_ infix 2 ∃[]-syntax infix 2 ∃[∶]-syntax infix 2 ∀[∶]-syntax infix 2 ∀[]-syntax infix 2 ⇒∶_⇐∶_ infix 2 ⇐∶_⇒∶_ -------------------------------------------------------------------------------- -- The type hProp of mere propositions -- the definition hProp is given in Foundations.HLevels -- hProp {ℓ} = Σ (Type ℓ) isProp private variable ℓ ℓ' ℓ'' : Level P Q R : hProp ℓ A B C : Type ℓ [_] : hProp ℓ → Type ℓ [_] = fst ∥_∥ₚ : Type ℓ → hProp ℓ ∥ A ∥ₚ = ∥ A ∥ , propTruncIsProp _≡ₚ_ : (x y : A) → hProp _ x ≡ₚ y = ∥ x ≡ y ∥ₚ hProp≡ : [ P ] ≡ [ Q ] → P ≡ Q hProp≡ p = ΣProp≡ (\ _ → isPropIsProp) p -------------------------------------------------------------------------------- -- Logical implication of mere propositions _⇒_ : (A : hProp ℓ) → (B : hProp ℓ') → hProp _ A ⇒ B = ([ A ] → [ B ]) , propPi λ _ → B .snd ⇔toPath : [ P ⇒ Q ] → [ Q ⇒ P ] → P ≡ Q ⇔toPath {P = P} {Q = Q} P⇒Q Q⇒P = hProp≡ (isoToPath (iso P⇒Q Q⇒P (λ b → Q .snd (P⇒Q (Q⇒P b)) b) λ a → P .snd (Q⇒P (P⇒Q a)) a)) pathTo⇒ : P ≡ Q → [ P ⇒ Q ] pathTo⇒ p x = subst fst p x pathTo⇐ : P ≡ Q → [ Q ⇒ P ] pathTo⇐ p x = subst fst (sym p) x substₚ : {x y : A} (B : A → hProp ℓ) → [ x ≡ₚ y ⇒ B x ⇒ B y ] substₚ {x = x} {y = y} B = elimPropTrunc (λ _ → propPi λ _ → B y .snd) (subst (fst ∘ B)) -------------------------------------------------------------------------------- -- Mixfix notations for ⇔-toPath -- see ⊔-identityˡ and ⊔-identityʳ for the difference ⇒∶_⇐∶_ : [ P ⇒ Q ] → [ Q ⇒ P ] → P ≡ Q ⇒∶_⇐∶_ = ⇔toPath ⇐∶_⇒∶_ : [ Q ⇒ P ] → [ P ⇒ Q ] → P ≡ Q ⇐∶ g ⇒∶ f = ⇔toPath f g -------------------------------------------------------------------------------- -- False and True ⊥ : hProp _ ⊥ = D.⊥ , λ () ⊤ : hProp _ ⊤ = D.Unit , (λ _ _ _ → D.tt) -------------------------------------------------------------------------------- -- Pseudo-complement of mere propositions ¬_ : hProp ℓ → hProp _ ¬ A = ([ A ] → D.⊥) , propPi λ _ → D.isProp⊥ _≢ₚ_ : (x y : A) → hProp _ x ≢ₚ y = ¬ x ≡ₚ y -------------------------------------------------------------------------------- -- Disjunction of mere propositions _⊔′_ : Type ℓ → Type ℓ' → Type _ A ⊔′ B = ∥ A D.⊎ B ∥ _⊔_ : hProp ℓ → hProp ℓ' → hProp _ P ⊔ Q = ∥ [ P ] D.⊎ [ Q ] ∥ₚ inl : A → A ⊔′ B inl x = ∣ D.inl x ∣ inr : B → A ⊔′ B inr x = ∣ D.inr x ∣ ⊔-elim : (P : hProp ℓ) (Q : hProp ℓ') (R : [ P ⊔ Q ] → hProp ℓ'') → (∀ x → [ R (inl x) ]) → (∀ y → [ R (inr y) ]) → (∀ z → [ R z ]) ⊔-elim _ _ R P⇒R Q⇒R = elimPropTrunc (snd ∘ R) (D.elim-⊎ P⇒R Q⇒R) -------------------------------------------------------------------------------- -- Conjunction of mere propositions _⊓′_ : Type ℓ → Type ℓ' → Type _ A ⊓′ B = A D.× B _⊓_ : hProp ℓ → hProp ℓ' → hProp _ A ⊓ B = [ A ] ⊓′ [ B ] , D.hLevelProd 1 (A .snd) (B .snd) ⊓-intro : (P : hProp ℓ) (Q : [ P ] → hProp ℓ') (R : [ P ] → hProp ℓ'') → (∀ a → [ Q a ]) → (∀ a → [ R a ]) → (∀ (a : [ P ]) → [ Q a ⊓ R a ] ) ⊓-intro _ _ _ = D.intro-× -------------------------------------------------------------------------------- -- Logical bi-implication of mere propositions _⇔_ : hProp ℓ → hProp ℓ' → hProp _ A ⇔ B = (A ⇒ B) ⊓ (B ⇒ A) -------------------------------------------------------------------------------- -- Universal Quantifier ∀[∶]-syntax : (A → hProp ℓ) → hProp _ ∀[∶]-syntax {A = A} P = (∀ x → [ P x ]) , propPi (snd ∘ P) ∀[]-syntax : (A → hProp ℓ) → hProp _ ∀[]-syntax {A = A} P = (∀ x → [ P x ]) , propPi (snd ∘ P) syntax ∀[∶]-syntax {A = A} (λ a → P) = ∀[ a ∶ A ] P syntax ∀[]-syntax (λ a → P) = ∀[ a ] P -------------------------------------------------------------------------------- -- Existential Quantifier ∃[]-syntax : (A → hProp ℓ) → hProp _ ∃[]-syntax {A = A} P = ∥ Σ A (fst ∘ P) ∥ₚ ∃[∶]-syntax : (A → hProp ℓ) → hProp _ ∃[∶]-syntax {A = A} P = ∥ Σ A (fst ∘ P) ∥ₚ syntax ∃[]-syntax {A = A} (λ x → P) = ∃[ x ∶ A ] P syntax ∃[∶]-syntax (λ x → P) = ∃[ x ] P -------------------------------------------------------------------------------- -- Decidable mere proposition Decₚ : (P : hProp ℓ) → hProp ℓ Decₚ P = Dec [ P ] , isPropDec (snd P) -------------------------------------------------------------------------------- -- Negation commutes with truncation ∥¬A∥≡¬∥A∥ : (A : Type ℓ) → ∥ (A → D.⊥) ∥ₚ ≡ (¬ ∥ A ∥ₚ) ∥¬A∥≡¬∥A∥ _ = ⇒∶ (λ ¬A A → elimPropTrunc (λ _ → D.isProp⊥) (elimPropTrunc (λ _ → propPi λ _ → D.isProp⊥) (λ ¬p p → ¬p p) ¬A) A) ⇐∶ λ ¬p → ∣ (λ p → ¬p ∣ p ∣) ∣ -------------------------------------------------------------------------------- -- (hProp, ⊔, ⊥) is a bounded ⊔-semilattice ⊔-assoc : (P : hProp ℓ) (Q : hProp ℓ') (R : hProp ℓ'') → P ⊔ (Q ⊔ R) ≡ (P ⊔ Q) ⊔ R ⊔-assoc P Q R = ⇒∶ ⊔-elim P (Q ⊔ R) (λ _ → (P ⊔ Q) ⊔ R) (inl ∘ inl) (⊔-elim Q R (λ _ → (P ⊔ Q) ⊔ R) (inl ∘ inr) inr) ⇐∶ assoc2 where assoc2 : (A ⊔′ B) ⊔′ C → A ⊔′ (B ⊔′ C) assoc2 ∣ D.inr a ∣ = ∣ D.inr ∣ D.inr a ∣ ∣ assoc2 ∣ D.inl ∣ D.inr b ∣ ∣ = ∣ D.inr ∣ D.inl b ∣ ∣ assoc2 ∣ D.inl ∣ D.inl c ∣ ∣ = ∣ D.inl c ∣ assoc2 ∣ D.inl (squash x y i) ∣ = propTruncIsProp (assoc2 ∣ D.inl x ∣) (assoc2 ∣ D.inl y ∣) i assoc2 (squash x y i) = propTruncIsProp (assoc2 x) (assoc2 y) i ⊔-idem : (P : hProp ℓ) → P ⊔ P ≡ P ⊔-idem P = ⇒∶ (⊔-elim P P (\ _ → P) (\ x → x) (\ x → x)) ⇐∶ inl ⊔-comm : (P : hProp ℓ) (Q : hProp ℓ') → P ⊔ Q ≡ Q ⊔ P ⊔-comm P Q = ⇒∶ (⊔-elim P Q (\ _ → (Q ⊔ P)) inr inl) ⇐∶ (⊔-elim Q P (\ _ → (P ⊔ Q)) inr inl) ⊔-identityˡ : (P : hProp ℓ) → ⊥ ⊔ P ≡ P ⊔-identityˡ P = ⇒∶ (⊔-elim ⊥ P (λ _ → P) (λ ()) (λ x → x)) ⇐∶ inr ⊔-identityʳ : (P : hProp ℓ) → P ⊔ ⊥ ≡ P ⊔-identityʳ P = ⇔toPath (⊔-elim P ⊥ (λ _ → P) (λ x → x) λ ()) inl -------------------------------------------------------------------------------- -- (hProp, ⊓, ⊤) is a bounded ⊓-lattice ⊓-assoc : (P : hProp ℓ) (Q : hProp ℓ') (R : hProp ℓ'') → P ⊓ Q ⊓ R ≡ (P ⊓ Q) ⊓ R ⊓-assoc _ _ _ = ⇒∶ (λ {(x D., (y D., z)) → (x D., y) D., z}) ⇐∶ (λ {((x D., y) D., z) → x D., (y D., z) }) ⊓-comm : (P : hProp ℓ) (Q : hProp ℓ') → P ⊓ Q ≡ Q ⊓ P ⊓-comm _ _ = ⇔toPath D.swap D.swap ⊓-idem : (P : hProp ℓ) → P ⊓ P ≡ P ⊓-idem _ = ⇔toPath D.proj₁ (λ x → x D., x) ⊓-identityˡ : (P : hProp ℓ) → ⊤ ⊓ P ≡ P ⊓-identityˡ _ = ⇔toPath D.proj₂ λ x → D.tt D., x ⊓-identityʳ : (P : hProp ℓ) → P ⊓ ⊤ ≡ P ⊓-identityʳ _ = ⇔toPath D.proj₁ λ x → x D., D.tt -------------------------------------------------------------------------------- -- Distributive laws ⇒-⊓-distrib : (P : hProp ℓ) (Q : hProp ℓ')(R : hProp ℓ'') → P ⇒ (Q ⊓ R) ≡ (P ⇒ Q) ⊓ (P ⇒ R) ⇒-⊓-distrib _ _ _ = ⇒∶ (λ f → (D.proj₁ ∘ f) D., (D.proj₂ ∘ f)) ⇐∶ (λ { (f D., g) x → f x D., g x}) ⊓-⊔-distribˡ : (P : hProp ℓ) (Q : hProp ℓ')(R : hProp ℓ'') → P ⊓ (Q ⊔ R) ≡ (P ⊓ Q) ⊔ (P ⊓ R) ⊓-⊔-distribˡ P Q R = ⇒∶ (λ { (x D., a) → ⊔-elim Q R (λ _ → (P ⊓ Q) ⊔ (P ⊓ R)) (λ y → ∣ D.inl (x D., y) ∣ ) (λ z → ∣ D.inr (x D., z) ∣ ) a }) ⇐∶ ⊔-elim (P ⊓ Q) (P ⊓ R) (λ _ → P ⊓ Q ⊔ R) (λ y → D.proj₁ y D., inl (D.proj₂ y)) (λ z → D.proj₁ z D., inr (D.proj₂ z)) ⊔-⊓-distribˡ : (P : hProp ℓ) (Q : hProp ℓ')(R : hProp ℓ'') → P ⊔ (Q ⊓ R) ≡ (P ⊔ Q) ⊓ (P ⊔ R) ⊔-⊓-distribˡ P Q R = ⇒∶ ⊔-elim P (Q ⊓ R) (λ _ → (P ⊔ Q) ⊓ (P ⊔ R) ) (D.intro-× inl inl) (D.map-× inr inr) ⇐∶ (λ { (x D., y) → ⊔-elim P R (λ _ → P ⊔ Q ⊓ R) inl (λ z → ⊔-elim P Q (λ _ → P ⊔ Q ⊓ R) inl (λ y → inr (y D., z)) x) y }) ⊓-∀-distrib : (P : A → hProp ℓ) (Q : A → hProp ℓ') → (∀[ a ∶ A ] P a) ⊓ (∀[ a ∶ A ] Q a) ≡ (∀[ a ∶ A ] (P a ⊓ Q a)) ⊓-∀-distrib P Q = ⇒∶ (λ {(p D., q) a → p a D., q a}) ⇐∶ λ pq → (D.proj₁ ∘ pq ) D., (D.proj₂ ∘ pq)
29.612319
97
0.402545
29eeb695ef9aaabc671715b96b5e98e6aed743db
521
agda
Agda
test/Succeed/Issue292-19.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue292-19.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue292-19.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue292-19 where postulate I : Set i₁ i₂ : I J : Set j : I → J data D : I → Set where d₁ : D i₁ d₂ : D i₂ data P : ∀ i → D i → Set where p₁ : P i₁ d₁ p₂ : P i₂ d₂ data P′ : ∀ i → D i → Set where p₁ : P′ i₁ d₁ data E : J → Set where e₁ : E (j i₁) e₂ : E (j i₂) data Q : ∀ i → E i → Set where q₁ : Q (j i₁) e₁ q₂ : Q (j i₂) e₂ Ok : Q (j i₁) e₁ → Set₁ Ok q₁ = Set AlsoOk : P i₁ d₁ → Set₁ AlsoOk p₁ = Set Foo : ∀ {i} (d : D i) → P′ i d → Set₁ Foo d₁ _ = Set Foo d₂ ()
13.710526
37
0.487524
41067bab67eb2963022886e02edb7af3d8b830d7
867
agda
Agda
test/succeed/InstanceGuessesMeta2.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/InstanceGuessesMeta2.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/InstanceGuessesMeta2.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
-- Andreas, 2012-01-10 -- {-# OPTIONS -v tc.constr.findInScope:50 #-} module InstanceGuessesMeta2 where open import Common.Level data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ record takeClass {a} (F : Set a → Set a) (G : Set a → ℕ → Set a) : Set (lsuc a) where field take : {A : Set a} → (n : ℕ) → F A → G A n take : ∀ {a} {A : Set a} {F : Set a → Set a} {G : Set a → ℕ → Set a} {{takeA : takeClass F G}} → (n : ℕ) → F A → G A n take {{takeA}} = takeClass.take takeA postulate List : ∀ {a} → Set a → Set a BVec : ∀ {a} → Set a → ℕ → Set a toList : ∀ {a}{A : Set a}{n : ℕ} → BVec A n → List A -- universe polymorphic instance takeInstanceList : {a : Level} → takeClass (List {a = a}) BVec take0 : {A : Set} → List A → BVec A zero take0 l = take zero l take1 : {A : Set} → List A → List A take1 l = toList (take (suc zero) l)
25.5
68
0.551326
416a17bc3b54abca550f946407c1d970286d21c7
3,229
agda
Agda
agda-stdlib/src/Algebra/Morphism/MonoidMonomorphism.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Algebra/Morphism/MonoidMonomorphism.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Algebra/Morphism/MonoidMonomorphism.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Consequences of a monomorphism between monoid-like structures ------------------------------------------------------------------------ -- See Data.Nat.Binary.Properties for examples of how this and similar -- modules can be used to easily translate properties between types. {-# OPTIONS --without-K --safe #-} open import Algebra.Bundles open import Algebra.Morphism.Structures open import Relation.Binary.Core module Algebra.Morphism.MonoidMonomorphism {a b ℓ₁ ℓ₂} {M₁ : RawMonoid a ℓ₁} {M₂ : RawMonoid b ℓ₂} {⟦_⟧} (isMonoidMonomorphism : IsMonoidMonomorphism M₁ M₂ ⟦_⟧) where open IsMonoidMonomorphism isMonoidMonomorphism open RawMonoid M₁ renaming (Carrier to A; _≈_ to _≈₁_; _∙_ to _∙_; ε to ε₁) open RawMonoid M₂ renaming (Carrier to B; _≈_ to _≈₂_; _∙_ to _◦_; ε to ε₂) open import Algebra.Definitions open import Algebra.Structures open import Data.Product using (map) import Relation.Binary.Reasoning.Setoid as SetoidReasoning ------------------------------------------------------------------------ -- Re-export all properties of magma monomorphisms open import Algebra.Morphism.MagmaMonomorphism isMagmaMonomorphism public ------------------------------------------------------------------------ -- Properties module _ (◦-isMagma : IsMagma _≈₂_ _◦_) where open IsMagma ◦-isMagma renaming (∙-cong to ◦-cong) open SetoidReasoning setoid identityˡ : LeftIdentity _≈₂_ ε₂ _◦_ → LeftIdentity _≈₁_ ε₁ _∙_ identityˡ idˡ x = injective (begin ⟦ ε₁ ∙ x ⟧ ≈⟨ homo ε₁ x ⟩ ⟦ ε₁ ⟧ ◦ ⟦ x ⟧ ≈⟨ ◦-cong ε-homo refl ⟩ ε₂ ◦ ⟦ x ⟧ ≈⟨ idˡ ⟦ x ⟧ ⟩ ⟦ x ⟧ ∎) identityʳ : RightIdentity _≈₂_ ε₂ _◦_ → RightIdentity _≈₁_ ε₁ _∙_ identityʳ idʳ x = injective (begin ⟦ x ∙ ε₁ ⟧ ≈⟨ homo x ε₁ ⟩ ⟦ x ⟧ ◦ ⟦ ε₁ ⟧ ≈⟨ ◦-cong refl ε-homo ⟩ ⟦ x ⟧ ◦ ε₂ ≈⟨ idʳ ⟦ x ⟧ ⟩ ⟦ x ⟧ ∎) identity : Identity _≈₂_ ε₂ _◦_ → Identity _≈₁_ ε₁ _∙_ identity = map identityˡ identityʳ zeroˡ : LeftZero _≈₂_ ε₂ _◦_ → LeftZero _≈₁_ ε₁ _∙_ zeroˡ zeˡ x = injective (begin ⟦ ε₁ ∙ x ⟧ ≈⟨ homo ε₁ x ⟩ ⟦ ε₁ ⟧ ◦ ⟦ x ⟧ ≈⟨ ◦-cong ε-homo refl ⟩ ε₂ ◦ ⟦ x ⟧ ≈⟨ zeˡ ⟦ x ⟧ ⟩ ε₂ ≈˘⟨ ε-homo ⟩ ⟦ ε₁ ⟧ ∎) zeroʳ : RightZero _≈₂_ ε₂ _◦_ → RightZero _≈₁_ ε₁ _∙_ zeroʳ zeʳ x = injective (begin ⟦ x ∙ ε₁ ⟧ ≈⟨ homo x ε₁ ⟩ ⟦ x ⟧ ◦ ⟦ ε₁ ⟧ ≈⟨ ◦-cong refl ε-homo ⟩ ⟦ x ⟧ ◦ ε₂ ≈⟨ zeʳ ⟦ x ⟧ ⟩ ε₂ ≈˘⟨ ε-homo ⟩ ⟦ ε₁ ⟧ ∎) zero : Zero _≈₂_ ε₂ _◦_ → Zero _≈₁_ ε₁ _∙_ zero = map zeroˡ zeroʳ ------------------------------------------------------------------------ -- Structures isMonoid : IsMonoid _≈₂_ _◦_ ε₂ → IsMonoid _≈₁_ _∙_ ε₁ isMonoid isMonoid = record { isSemigroup = isSemigroup M.isSemigroup ; identity = identity M.isMagma M.identity } where module M = IsMonoid isMonoid isCommutativeMonoid : IsCommutativeMonoid _≈₂_ _◦_ ε₂ → IsCommutativeMonoid _≈₁_ _∙_ ε₁ isCommutativeMonoid isCommMonoid = record { isMonoid = isMonoid C.isMonoid ; comm = comm C.isMagma C.comm } where module C = IsCommutativeMonoid isCommMonoid
33.989474
75
0.557758
06a9091556abe6834f1c2e4853df7126003420e7
2,006
agda
Agda
src/Data/Vec/Any/Membership/Properties.agda
tizmd/agda-vector-any
1a60f72b9ea1dd61845311ee97dc380aa542b874
[ "MIT" ]
null
null
null
src/Data/Vec/Any/Membership/Properties.agda
tizmd/agda-vector-any
1a60f72b9ea1dd61845311ee97dc380aa542b874
[ "MIT" ]
null
null
null
src/Data/Vec/Any/Membership/Properties.agda
tizmd/agda-vector-any
1a60f72b9ea1dd61845311ee97dc380aa542b874
[ "MIT" ]
null
null
null
module Data.Vec.Any.Membership.Properties where open import Relation.Binary open import Data.Vec module SingleSetoid {a ℓ} (S : Setoid a ℓ) where open Setoid S renaming (Carrier to A) open import Data.Vec.Any open import Data.Vec.Any.Membership S open import Function using (flip) open import Data.Vec.Equality using (module Equality) open Equality S renaming (_≈_ to _≋_; trans to ≋-trans) ⊆-reflexive : ∀ {n m} {xs : Vec A n} {ys : Vec A m} → xs ≋ ys → xs ⊆ ys ⊆-reflexive []-cong () ⊆-reflexive (x₁≈x₂ ∷-cong eq) (here x≈x₁) = here (trans x≈x₁ x₁≈x₂) ⊆-reflexive (_ ∷-cong eq) (there p) = there (⊆-reflexive eq p) ∈′-resp-≈ : ∀ {x} → (x ≈_) Respects _≈_ ∈′-resp-≈ = flip trans ∈′-resp-≋ : ∀ {n₁ n₂ x}{xs₁ : Vec A n₁}{xs₂ : Vec A n₂} → xs₁ ≋ xs₂ → x ∈′ xs₁ → x ∈′ xs₂ ∈′-resp-≋ {xs₁ = .[]} {.[]} []-cong () ∈′-resp-≋ {xs₁ = .(_ ∷ _)} {.(_ ∷ _)} (x¹≈x² ∷-cong eq) (here x≈x₁) = here (trans x≈x₁ x¹≈x²) ∈′-resp-≋ {xs₁ = .(_ ∷ _)} {.(_ ∷ _)} (x¹≈x² ∷-cong eq) (there p) = there (∈′-resp-≋ eq p) open SingleSetoid public module DoubleSetoid {a₁ a₂ ℓ₁ ℓ₂} (S₁ : Setoid a₁ ℓ₁) (S₂ : Setoid a₂ ℓ₂) where open import Data.Vec.Any.Properties import Data.Vec.Any as Any open import Data.Product hiding (map) open Setoid S₁ renaming (Carrier to A₁; _≈_ to _≈₁_; refl to refl₁) open Setoid S₂ renaming (Carrier to A₂; _≈_ to _≈₂_) open import Data.Vec.Any.Membership S₁ renaming (_∈′_ to _∈′₁_) using (find′) open import Data.Vec.Any.Membership S₂ renaming (_∈′_ to _∈′₂_) using () ∈′-map⁺ : ∀ {n x}{xs : Vec A₁ n} {f} → f Preserves _≈₁_ ⟶ _≈₂_ → x ∈′₁ xs → f x ∈′₂ map f xs ∈′-map⁺ pres x∈′xs = map⁺ (Any.map pres x∈′xs) ∈′-map⁻ : ∀ {n y}{xs : Vec A₁ n} {f} → y ∈′₂ map f xs → ∃ λ x → x ∈′₁ xs × y ≈₂ f x ∈′-map⁻ y∈′map with find′ (map⁻ y∈′map) ... | _ , x∈xs , px = , x∈xs , px open DoubleSetoid public
37.849057
97
0.551844
4d7a8ced3625dd286048ef5fae1440ce1aa8c714
564
agda
Agda
examples/Termination/simplified-comb.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/Termination/simplified-comb.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/Termination/simplified-comb.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module simplified-comb where infixr 50 _⟶_ data Ty : Set where ι : Ty _⟶_ : Ty -> Ty -> Ty data Tm : Ty -> Set where _$_ : {σ τ : Ty} -> Tm (σ ⟶ τ) -> Tm σ -> Tm τ data Nf : Ty -> Set where data _↓_ : {σ : Ty} -> Tm σ -> Nf σ -> Set where r$ : {σ τ : Ty} -> {t : Tm (σ ⟶ τ)} -> {f : Nf (σ ⟶ τ)} -> t ↓ f -> {u : Tm σ} -> {a : Nf σ} -> u ↓ a -> {v : Nf τ} -> (t $ u ) ↓ v nf* : {σ : Ty} -> (t : Tm σ) -> {n : Nf σ} -> t ↓ n -> Set nf* .{τ} (_$_ {σ} {τ} t u) {v} (r$ {f = f} p q) with nf* {σ ⟶ τ} t {f} p nf* (t $ u) (r$ p q) | _ = Ty
25.636364
72
0.388298
0e4db7bc658d94b562b4637c43e8c90711b2cefe
1,559
agda
Agda
src/fot/PA/Inductive2Standard.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/PA/Inductive2Standard.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/PA/Inductive2Standard.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- From inductive PA to standard axiomatic PA ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- From the definition of PA using Agda data types and primitive -- recursive functions for addition and multiplication, we can prove -- the following axioms (see (Machover 1996, p. 263) and (Hájek and -- Pudlák 1998, p. 28)): -- PA₁. 0 ≠ n' -- PA₂. m' = n' → m = n -- PA₃. 0 + n = n -- PA₄. m' + n = (m + n)' -- PA₅. 0 * n = 0 -- PA₆. m' * n = n + (m * n) -- Axiom of induction: -- φ(0) → (∀n.φ(n) → φ(succ n)) → ∀n.φ(n), for any formulae φ module PA.Inductive2Standard where open import PA.Inductive.Base ------------------------------------------------------------------------------ PA₁ : ∀ {n} → zero ≢ succ n PA₁ () PA₂ : ∀ {m n} → succ m ≡ succ n → m ≡ n PA₂ refl = refl PA₃ : ∀ n → zero + n ≡ n PA₃ n = refl PA₄ : ∀ m n → succ m + n ≡ succ (m + n) PA₄ m n = refl PA₅ : ∀ n → zero * n ≡ zero PA₅ n = refl PA₆ : ∀ m n → succ m * n ≡ n + m * n PA₆ m n = refl ------------------------------------------------------------------------------ -- References -- -- Machover, Moshé (1996). Set theory, Logic and their -- Limitations. Cambridge University Press. -- Hájek, Petr and Pudlák, Pavel (1998). Metamathematics of -- First-Order Arithmetic. 2nd printing. Springer.
27.839286
78
0.463759
29560794ce492e865b0e2fa733a16e398586cc59
4,622
agda
Agda
Data/List/Relation/Binary/Lexicographic.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/List/Relation/Binary/Lexicographic.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/List/Relation/Binary/Lexicographic.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} open import Relation.Binary open import Prelude hiding (Decidable) module Data.List.Relation.Binary.Lexicographic {e ℓ₁ ℓ₂} {E : Type e} (ord : TotalOrder E ℓ₁ ℓ₂) where open import Data.List import Path as ≡ open TotalOrder ord renaming (refl to ≤-refl) import Data.Empty.UniversePolymorphic as Poly import Data.Unit.UniversePolymorphic as Poly infix 4 _<′_ _<′_ : List E → List E → Type (e ℓ⊔ ℓ₁ ℓ⊔ ℓ₂) xs <′ [] = Poly.⊥ [] <′ y ∷ ys = Poly.⊤ x ∷ xs <′ y ∷ ys = (x < y) ⊎ ((x ≡ y) × (xs <′ ys)) infix 4 _≤′_ _≤′_ : List E → List E → Type (e ℓ⊔ ℓ₁ ℓ⊔ ℓ₂) [] ≤′ ys = Poly.⊤ x ∷ xs ≤′ [] = Poly.⊥ x ∷ xs ≤′ y ∷ ys = (x < y) ⊎ ((x ≡ y) × (xs ≤′ ys)) <′-trans : Transitive _<′_ <′-trans {[]} {y ∷ ys} {z ∷ zs} p q = Poly.tt <′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inl q) = inl (<-trans p q) <′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inr q) = inl (subst (_ <_) (fst q) p) <′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr p) (inl q) = inl (subst (_< _) (sym (fst p)) q) <′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr (p , ps)) (inr (q , qs)) = inr (p ; q , <′-trans ps qs) ≤′-trans : Transitive _≤′_ ≤′-trans {[]} {ys} {zs} p q = Poly.tt ≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inl q) = inl (<-trans p q) ≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inr q) = inl (subst (_ <_) (fst q) p) ≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr p) (inl q) = inl (subst (_< _) (sym (fst p)) q) ≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr (p , ps)) (inr (q , qs)) = inr (p ; q , ≤′-trans ps qs) ≤′-antisym : Antisymmetric _≤′_ ≤′-antisym {[]} {[]} p q = refl ≤′-antisym {x ∷ xs} {y ∷ ys} (inl p) (inl q) = ⊥-elim (asym p q) ≤′-antisym {x ∷ xs} {y ∷ ys} (inl p) (inr q) = ⊥-elim (irrefl (subst (_< _) (sym (fst q)) p)) ≤′-antisym {x ∷ xs} {y ∷ ys} (inr p) (inl q) = ⊥-elim (irrefl (subst (_< _) (sym (fst p)) q)) ≤′-antisym {x ∷ xs} {y ∷ ys} (inr (p , ps)) (inr (_ , qs)) = cong₂ _∷_ p (≤′-antisym ps qs) ≤′-refl : Reflexive _≤′_ ≤′-refl {[]} = Poly.tt ≤′-refl {x ∷ xs} = inr (refl , ≤′-refl) <′-asym : Asymmetric _<′_ <′-asym {x ∷ xs} {y ∷ ys} (inl p) (inl q) = asym p q <′-asym {x ∷ xs} {y ∷ ys} (inl p) (inr q) = irrefl (subst (_< _) (sym (fst q)) p) <′-asym {x ∷ xs} {y ∷ ys} (inr p) (inl q) = irrefl (subst (_< _) (sym (fst p)) q) <′-asym {x ∷ xs} {y ∷ ys} (inr p) (inr q) = <′-asym (snd p) (snd q) ≮′⇒≥′ : ∀ {xs ys} → ¬ (xs <′ ys) → ys ≤′ xs ≮′⇒≥′ {xs} {[]} p = Poly.tt ≮′⇒≥′ {[]} {y ∷ ys} p = ⊥-elim (p _) ≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys with compare x y ≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys | lt x<y = ⊥-elim (xs≮ys (inl x<y)) ≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys | eq x≡y = inr (sym x≡y , ≮′⇒≥′ (xs≮ys ∘ inr ∘ _,_ x≡y)) ≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys | gt x>y = inl x>y <′-conn : Connected _<′_ <′-conn xs≮ys ys≮xs = ≤′-antisym (≮′⇒≥′ ys≮xs) (≮′⇒≥′ xs≮ys) <′-irrefl : Irreflexive _<′_ <′-irrefl {x ∷ xs} (inl x<x) = irrefl x<x <′-irrefl {x ∷ xs} (inr xs<xs) = <′-irrefl (snd xs<xs) ≰′⇒>′ : ∀ {xs ys} → ¬ (xs ≤′ ys) → ys <′ xs ≰′⇒>′ {[]} xs≰ys = ⊥-elim (xs≰ys _) ≰′⇒>′ {x ∷ xs} {[]} xs≰ys = Poly.tt ≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys with compare x y ≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys | lt x<y = ⊥-elim (xs≰ys (inl x<y)) ≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys | eq x≡y = inr (sym x≡y , ≰′⇒>′ (xs≰ys ∘ inr ∘ _,_ x≡y)) ≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys | gt x>y = inl x>y ≮′-cons : ∀ {x y xs ys} → x ≡ y → ¬ (xs <′ ys) → ¬ (x ∷ xs <′ y ∷ ys) ≮′-cons x≡y xs≮ys (inl x<y) = irrefl (subst (_< _) x≡y x<y) ≮′-cons x≡y xs≮ys (inr (x≡y₁ , x∷xs<y∷ys)) = xs≮ys x∷xs<y∷ys _<′?_ : Decidable _<′_ xs <′? [] = no (λ ()) [] <′? (y ∷ ys) = yes Poly.tt (x ∷ xs) <′? (y ∷ ys) with compare x y ((x ∷ xs) <′? (y ∷ ys)) | lt x<y = yes (inl x<y) ((x ∷ xs) <′? (y ∷ ys)) | eq x≡y = map-dec (inr ∘ _,_ x≡y) (≮′-cons x≡y) (xs <′? ys) ((x ∷ xs) <′? (y ∷ ys)) | gt x>y = no (<′-asym (inl x>y)) listOrd : TotalOrder (List E) _ _ StrictPreorder._<_ (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder listOrd)) = _<′_ StrictPreorder.trans (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder listOrd)) = <′-trans StrictPreorder.irrefl (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder listOrd)) = <′-irrefl StrictPartialOrder.conn (TotalOrder.strictPartialOrder listOrd) = <′-conn Preorder._≤_ (PartialOrder.preorder (TotalOrder.partialOrder listOrd)) = _≤′_ Preorder.refl (PartialOrder.preorder (TotalOrder.partialOrder listOrd)) = ≤′-refl Preorder.trans (PartialOrder.preorder (TotalOrder.partialOrder listOrd)) = ≤′-trans PartialOrder.antisym (TotalOrder.partialOrder listOrd) = ≤′-antisym TotalOrder._<?_ listOrd = _<′?_ TotalOrder.≰⇒> listOrd = ≰′⇒>′ TotalOrder.≮⇒≥ listOrd = ≮′⇒≥′
42.796296
110
0.523367
230b4c5aefc1be2a34482c9dd9dc4abd1e418ca3
1,497
agda
Agda
Groups/Homomorphisms/Image.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Groups/Homomorphisms/Image.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Groups/Homomorphisms/Image.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import Groups.Definition open import Setoids.Setoids open import Setoids.Subset open import LogicalFormulae open import Sets.EquivalenceRelations open import Groups.Homomorphisms.Definition open import Groups.Homomorphisms.Lemmas open import Groups.Subgroups.Definition open import Groups.Lemmas open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Groups.Homomorphisms.Image {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_+A_ : A → A → A} {_+B_ : B → B → B} {G : Group S _+A_} {H : Group T _+B_} {f : A → B} (fHom : GroupHom G H f) where imageGroupPred : B → Set (a ⊔ d) imageGroupPred b = Sg A (λ a → Setoid._∼_ T (f a) b) imageGroupSubset : subset T imageGroupPred imageGroupSubset {x} {y} x=y (a , fa=x) = a , transitive fa=x x=y where open Setoid T open Equivalence eq imageGroupSubgroup : Subgroup H imageGroupPred Subgroup.isSubset imageGroupSubgroup = imageGroupSubset Subgroup.closedUnderPlus imageGroupSubgroup {x} {y} (a , fa=x) (b , fb=y) = (a +A b) , transitive (GroupHom.groupHom fHom) (Group.+WellDefined H fa=x fb=y) where open Setoid T open Equivalence eq Subgroup.containsIdentity imageGroupSubgroup = Group.0G G , imageOfIdentityIsIdentity fHom Subgroup.closedUnderInverse imageGroupSubgroup {x} (a , fa=x) = Group.inverse G a , transitive (homRespectsInverse fHom) (inverseWellDefined H fa=x) where open Setoid T open Equivalence eq
40.459459
235
0.721443
3df64beea5a5a6f8a6baa96880476bba112fc292
2,458
agda
Agda
README/Correct-by-Construction-Pretty-Printing.agda
nad/pretty
b956803ba90b6c5f57bbbaab01bb18485d948492
[ "MIT" ]
null
null
null
README/Correct-by-Construction-Pretty-Printing.agda
nad/pretty
b956803ba90b6c5f57bbbaab01bb18485d948492
[ "MIT" ]
null
null
null
README/Correct-by-Construction-Pretty-Printing.agda
nad/pretty
b956803ba90b6c5f57bbbaab01bb18485d948492
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- A README directed towards readers of the paper -- "Correct-by-Construction Pretty-Printing" -- -- Nils Anders Danielsson ------------------------------------------------------------------------ {-# OPTIONS --guardedness #-} module README.Correct-by-Construction-Pretty-Printing where ------------------------------------------------------------------------ -- 2: Grammars -- The basic grammar data type, including its semantics. Only a small -- number of derived combinators is defined directly for this data -- type. It is proved that an inductive version of this type would be -- quite restrictive. import Grammar.Infinite.Basic -- The extended grammar data type mentioned in Section 4.3, along with -- a semantics and lots of derived combinators. This type is proved to -- be no more expressive than the previous one; but it is also proved -- that every language that can be recursively enumerated can be -- represented by a (unit-valued) grammar. import Grammar.Infinite ------------------------------------------------------------------------ -- 3: Pretty-Printers import Pretty ------------------------------------------------------------------------ -- 4: Examples -- Reusable document combinators introduced in this section. import Pretty -- The symbol combinator and the heuristic procedure -- trailing-whitespace. import Grammar.Infinite -- 4.1: Boolean literals. import Examples.Bool -- 4.2: Expressions, and 4.3: Expressions, Take Two. import Examples.Expression -- 4.4: Identifiers. import Examples.Identifier -- 4.5: Other Examples. -- Some of these examples are not mentioned in the paper. -- Another expression example based on one in Matsuda and Wang's -- "FliPpr: A Prettier Invertible Printing System". import Examples.Expression -- An example based on one in Swierstra and Chitil's "Linear, bounded, -- functional pretty-printing". import Examples.Identifier-list -- Two examples, both based on examples in Wadler's "A prettier -- printer". import Examples.Tree import Examples.XML -- The fill combinator. import Pretty -- A general grammar and pretty-printer for binary operators of -- various (not necessarily linearly ordered) precedences. import Examples.Precedence ------------------------------------------------------------------------ -- 5: Renderers import Renderer -- Unambiguous and Parser. import Grammar.Infinite
25.604167
72
0.626119
a16fc2cb11b1b30403cb97d9e1b8b326a63cd0f0
9,691
agda
Agda
agda-stdlib/src/Function/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Function/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Function/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Bundles for types of functions ------------------------------------------------------------------------ -- The contents of this file should usually be accessed from `Function`. -- Note that these bundles differ from those found elsewhere in other -- library hierarchies as they take Setoids as parameters. This is -- because a function is of no use without knowing what its domain and -- codomain is, as well which equalities are being considered over them. -- One consequence of this is that they are not built from the -- definitions found in `Function.Structures` as is usually the case in -- other library hierarchies, as this would duplicate the equality -- axioms. {-# OPTIONS --without-K --safe #-} module Function.Bundles where import Function.Definitions as FunctionDefinitions import Function.Structures as FunctionStructures open import Level using (Level; _⊔_; suc) open import Data.Product using (proj₁; proj₂) open import Relation.Binary open import Relation.Binary.PropositionalEquality as ≡ using (_≡_) open Setoid using (isEquivalence) private variable a b ℓ₁ ℓ₂ : Level ------------------------------------------------------------------------ -- Setoid bundles module _ (From : Setoid a ℓ₁) (To : Setoid b ℓ₂) where open Setoid From using () renaming (Carrier to A; _≈_ to _≈₁_) open Setoid To using () renaming (Carrier to B; _≈_ to _≈₂_) open FunctionDefinitions _≈₁_ _≈₂_ open FunctionStructures _≈₁_ _≈₂_ record Injection : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B cong : f Preserves _≈₁_ ⟶ _≈₂_ injective : Injective f isCongruent : IsCongruent f isCongruent = record { cong = cong ; isEquivalence₁ = isEquivalence From ; isEquivalence₂ = isEquivalence To } open IsCongruent isCongruent public using (module Eq₁; module Eq₂) isInjection : IsInjection f isInjection = record { isCongruent = isCongruent ; injective = injective } record Surjection : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B cong : f Preserves _≈₁_ ⟶ _≈₂_ surjective : Surjective f isCongruent : IsCongruent f isCongruent = record { cong = cong ; isEquivalence₁ = isEquivalence From ; isEquivalence₂ = isEquivalence To } open IsCongruent isCongruent public using (module Eq₁; module Eq₂) isSurjection : IsSurjection f isSurjection = record { isCongruent = isCongruent ; surjective = surjective } record Bijection : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B cong : f Preserves _≈₁_ ⟶ _≈₂_ bijective : Bijective f injective : Injective f injective = proj₁ bijective surjective : Surjective f surjective = proj₂ bijective injection : Injection injection = record { cong = cong ; injective = injective } surjection : Surjection surjection = record { cong = cong ; surjective = surjective } open Injection injection public using (isInjection) open Surjection surjection public using (isSurjection) isBijection : IsBijection f isBijection = record { isInjection = isInjection ; surjective = surjective } open IsBijection isBijection public using (module Eq₁; module Eq₂) record Equivalence : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B g : B → A cong₁ : f Preserves _≈₁_ ⟶ _≈₂_ cong₂ : g Preserves _≈₂_ ⟶ _≈₁_ record LeftInverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B g : B → A cong₁ : f Preserves _≈₁_ ⟶ _≈₂_ cong₂ : g Preserves _≈₂_ ⟶ _≈₁_ inverseˡ : Inverseˡ f g isCongruent : IsCongruent f isCongruent = record { cong = cong₁ ; isEquivalence₁ = isEquivalence From ; isEquivalence₂ = isEquivalence To } open IsCongruent isCongruent public using (module Eq₁; module Eq₂) isLeftInverse : IsLeftInverse f g isLeftInverse = record { isCongruent = isCongruent ; cong₂ = cong₂ ; inverseˡ = inverseˡ } equivalence : Equivalence equivalence = record { cong₁ = cong₁ ; cong₂ = cong₂ } record RightInverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B g : B → A cong₁ : f Preserves _≈₁_ ⟶ _≈₂_ cong₂ : g Preserves _≈₂_ ⟶ _≈₁_ inverseʳ : Inverseʳ f g isCongruent : IsCongruent f isCongruent = record { cong = cong₁ ; isEquivalence₁ = isEquivalence From ; isEquivalence₂ = isEquivalence To } isRightInverse : IsRightInverse f g isRightInverse = record { isCongruent = isCongruent ; cong₂ = cong₂ ; inverseʳ = inverseʳ } equivalence : Equivalence equivalence = record { cong₁ = cong₁ ; cong₂ = cong₂ } record BiEquivalence : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B g₁ : B → A g₂ : B → A cong₁ : f Preserves _≈₁_ ⟶ _≈₂_ cong₂ : g₁ Preserves _≈₂_ ⟶ _≈₁_ cong₃ : g₂ Preserves _≈₂_ ⟶ _≈₁_ record BiInverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B g₁ : B → A g₂ : B → A cong₁ : f Preserves _≈₁_ ⟶ _≈₂_ cong₂ : g₁ Preserves _≈₂_ ⟶ _≈₁_ cong₃ : g₂ Preserves _≈₂_ ⟶ _≈₁_ inverseˡ : Inverseˡ f g₁ inverseʳ : Inverseʳ f g₂ f-isCongruent : IsCongruent f f-isCongruent = record { cong = cong₁ ; isEquivalence₁ = isEquivalence From ; isEquivalence₂ = isEquivalence To } isBiInverse : IsBiInverse f g₁ g₂ isBiInverse = record { f-isCongruent = f-isCongruent ; cong₂ = cong₂ ; inverseˡ = inverseˡ ; cong₃ = cong₃ ; inverseʳ = inverseʳ } biEquivalence : BiEquivalence biEquivalence = record { cong₁ = cong₁ ; cong₂ = cong₂ ; cong₃ = cong₃ } record Inverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field f : A → B f⁻¹ : B → A cong₁ : f Preserves _≈₁_ ⟶ _≈₂_ cong₂ : f⁻¹ Preserves _≈₂_ ⟶ _≈₁_ inverse : Inverseᵇ f f⁻¹ inverseˡ : Inverseˡ f f⁻¹ inverseˡ = proj₁ inverse inverseʳ : Inverseʳ f f⁻¹ inverseʳ = proj₂ inverse leftInverse : LeftInverse leftInverse = record { cong₁ = cong₁ ; cong₂ = cong₂ ; inverseˡ = inverseˡ } rightInverse : RightInverse rightInverse = record { cong₁ = cong₁ ; cong₂ = cong₂ ; inverseʳ = inverseʳ } open LeftInverse leftInverse public using (isLeftInverse) open RightInverse rightInverse public using (isRightInverse) isInverse : IsInverse f f⁻¹ isInverse = record { isLeftInverse = isLeftInverse ; inverseʳ = inverseʳ } open IsInverse isInverse public using (module Eq₁; module Eq₂) ------------------------------------------------------------------------ -- Bundles specialised for propositional equality infix 3 _↣_ _↠_ _⤖_ _⇔_ _↩_ _↪_ _↩↪_ _↔_ _↣_ : Set a → Set b → Set _ A ↣ B = Injection (≡.setoid A) (≡.setoid B) _↠_ : Set a → Set b → Set _ A ↠ B = Surjection (≡.setoid A) (≡.setoid B) _⤖_ : Set a → Set b → Set _ A ⤖ B = Bijection (≡.setoid A) (≡.setoid B) _⇔_ : Set a → Set b → Set _ A ⇔ B = Equivalence (≡.setoid A) (≡.setoid B) _↩_ : Set a → Set b → Set _ A ↩ B = LeftInverse (≡.setoid A) (≡.setoid B) _↪_ : Set a → Set b → Set _ A ↪ B = RightInverse (≡.setoid A) (≡.setoid B) _↩↪_ : Set a → Set b → Set _ A ↩↪ B = BiInverse (≡.setoid A) (≡.setoid B) _↔_ : Set a → Set b → Set _ A ↔ B = Inverse (≡.setoid A) (≡.setoid B) -- We now define some constructors for the above that -- automatically provide the required congruency proofs. module _ {A : Set a} {B : Set b} where open FunctionDefinitions {A = A} {B} _≡_ _≡_ mk↣ : ∀ {f : A → B} → Injective f → A ↣ B mk↣ {f} inj = record { f = f ; cong = ≡.cong f ; injective = inj } mk↠ : ∀ {f : A → B} → Surjective f → A ↠ B mk↠ {f} surj = record { f = f ; cong = ≡.cong f ; surjective = surj } mk⤖ : ∀ {f : A → B} → Bijective f → A ⤖ B mk⤖ {f} bij = record { f = f ; cong = ≡.cong f ; bijective = bij } mk⇔ : ∀ (f : A → B) (g : B → A) → A ⇔ B mk⇔ f g = record { f = f ; g = g ; cong₁ = ≡.cong f ; cong₂ = ≡.cong g } mk↩ : ∀ {f : A → B} {g : B → A} → Inverseˡ f g → A ↩ B mk↩ {f} {g} invˡ = record { f = f ; g = g ; cong₁ = ≡.cong f ; cong₂ = ≡.cong g ; inverseˡ = invˡ } mk↪ : ∀ {f : A → B} {g : B → A} → Inverseʳ f g → A ↪ B mk↪ {f} {g} invʳ = record { f = f ; g = g ; cong₁ = ≡.cong f ; cong₂ = ≡.cong g ; inverseʳ = invʳ } mk↩↪ : ∀ {f : A → B} {g₁ : B → A} {g₂ : B → A} → Inverseˡ f g₁ → Inverseʳ f g₂ → A ↩↪ B mk↩↪ {f} {g₁} {g₂} invˡ invʳ = record { f = f ; g₁ = g₁ ; g₂ = g₂ ; cong₁ = ≡.cong f ; cong₂ = ≡.cong g₁ ; cong₃ = ≡.cong g₂ ; inverseˡ = invˡ ; inverseʳ = invʳ } mk↔ : ∀ {f : A → B} {f⁻¹ : B → A} → Inverseᵇ f f⁻¹ → A ↔ B mk↔ {f} {f⁻¹} inv = record { f = f ; f⁻¹ = f⁻¹ ; cong₁ = ≡.cong f ; cong₂ = ≡.cong f⁻¹ ; inverse = inv }
25.502632
72
0.540914
4d7a429df5b12020b6dd12c0eaf37f44219004ca
18,433
agda
Agda
Everything.agda
tetrapharmakon/agda-categories
cfa6aefd3069d4db995191b458c886edcfba8294
[ "MIT" ]
5
2019-05-21T17:07:19.000Z
2019-05-22T03:54:24.000Z
Everything.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
null
null
null
Everything.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
null
null
null
import Categories.2-Category import Categories.2-Functor import Categories.Adjoint import Categories.Adjoint.AFT import Categories.Adjoint.AFT.SolutionSet import Categories.Adjoint.Alternatives import Categories.Adjoint.Compose import Categories.Adjoint.Construction.CoKleisli import Categories.Adjoint.Construction.EilenbergMoore import Categories.Adjoint.Construction.Kleisli import Categories.Adjoint.Equivalence import Categories.Adjoint.Equivalence.Properties import Categories.Adjoint.Equivalents import Categories.Adjoint.Instance.0-Truncation import Categories.Adjoint.Instance.01-Truncation import Categories.Adjoint.Instance.Core import Categories.Adjoint.Instance.PathsOf import Categories.Adjoint.Instance.PosetCore import Categories.Adjoint.Instance.StrictCore import Categories.Adjoint.Instance.StrictDiscrete import Categories.Adjoint.Mate import Categories.Adjoint.Monadic import Categories.Adjoint.Monadic.Crude import Categories.Adjoint.Monadic.Properties import Categories.Adjoint.Properties import Categories.Adjoint.RAPL import Categories.Adjoint.Relative import Categories.Adjoint.TwoSided import Categories.Adjoint.TwoSided.Compose import Categories.Bicategory import Categories.Bicategory.Bigroupoid import Categories.Bicategory.Construction.1-Category import Categories.Bicategory.Construction.Spans import Categories.Bicategory.Construction.Spans.Properties import Categories.Bicategory.Extras import Categories.Bicategory.Instance.Cats import Categories.Bicategory.Instance.EnrichedCats import Categories.Bicategory.Monad import Categories.Bicategory.Monad.Properties import Categories.Bicategory.Opposite import Categories.Category import Categories.Category.BicartesianClosed import Categories.Category.BinaryProducts import Categories.Category.CMonoidEnriched import Categories.Category.Cartesian import Categories.Category.Cartesian.Bundle import Categories.Category.Cartesian.Monoidal import Categories.Category.Cartesian.Properties import Categories.Category.Cartesian.SymmetricMonoidal import Categories.Category.CartesianClosed import Categories.Category.CartesianClosed.Canonical import Categories.Category.CartesianClosed.Locally import Categories.Category.CartesianClosed.Locally.Properties import Categories.Category.CartesianClosed.Properties import Categories.Category.Closed import Categories.Category.Cocartesian import Categories.Category.Cocartesian.Bundle import Categories.Category.Cocomplete import Categories.Category.Cocomplete.Finitely import Categories.Category.Cocomplete.Finitely.Properties import Categories.Category.Cocomplete.Properties import Categories.Category.Complete import Categories.Category.Complete.Finitely import Categories.Category.Complete.Finitely.Properties import Categories.Category.Complete.Properties import Categories.Category.Complete.Properties.Construction import Categories.Category.Complete.Properties.SolutionSet import Categories.Category.Concrete import Categories.Category.Concrete.Properties import Categories.Category.Construction.0-Groupoid import Categories.Category.Construction.Adjoints import Categories.Category.Construction.Arrow import Categories.Category.Construction.CoKleisli import Categories.Category.Construction.Cocones import Categories.Category.Construction.Comma import Categories.Category.Construction.Cones import Categories.Category.Construction.Coproduct import Categories.Category.Construction.Core import Categories.Category.Construction.Cowedges import Categories.Category.Construction.EilenbergMoore import Categories.Category.Construction.Elements import Categories.Category.Construction.EnrichedFunctors import Categories.Category.Construction.F-Algebras import Categories.Category.Construction.Fin import Categories.Category.Construction.Functors import Categories.Category.Construction.Grothendieck import Categories.Category.Construction.GroupAsCategory import Categories.Category.Construction.KanComplex import Categories.Category.Construction.KaroubiEnvelope import Categories.Category.Construction.KaroubiEnvelope.Properties import Categories.Category.Construction.Kleisli import Categories.Category.Construction.LT-Models import Categories.Category.Construction.MonoidAsCategory import Categories.Category.Construction.MonoidalFunctors import Categories.Category.Construction.Monoids import Categories.Category.Construction.ObjectRestriction import Categories.Category.Construction.Path import Categories.Category.Construction.PathCategory import Categories.Category.Construction.Presheaves import Categories.Category.Construction.Properties.CoKleisli import Categories.Category.Construction.Properties.Comma import Categories.Category.Construction.Properties.EilenbergMoore import Categories.Category.Construction.Properties.Functors import Categories.Category.Construction.Properties.Kleisli import Categories.Category.Construction.Properties.Presheaves import Categories.Category.Construction.Properties.Presheaves.Cartesian import Categories.Category.Construction.Properties.Presheaves.CartesianClosed import Categories.Category.Construction.Properties.Presheaves.Complete import Categories.Category.Construction.Properties.Presheaves.FromCartesianCCC import Categories.Category.Construction.Pullbacks import Categories.Category.Construction.SetoidDiscrete import Categories.Category.Construction.Spans import Categories.Category.Construction.StrictDiscrete import Categories.Category.Construction.SymmetricMonoidalFunctors import Categories.Category.Construction.Thin import Categories.Category.Construction.TwistedArrow import Categories.Category.Construction.Wedges import Categories.Category.Core import Categories.Category.Dagger import Categories.Category.Dagger.Construction.Discrete import Categories.Category.Dagger.Instance.Rels import Categories.Category.Diagram.Span import Categories.Category.Discrete import Categories.Category.Duality import Categories.Category.Equivalence import Categories.Category.Equivalence.Preserves import Categories.Category.Equivalence.Properties import Categories.Category.Finite import Categories.Category.Finite.Fin import Categories.Category.Finite.Fin.Construction.Discrete import Categories.Category.Finite.Fin.Construction.Poset import Categories.Category.Finite.Fin.Instance.Parallel import Categories.Category.Finite.Fin.Instance.Span import Categories.Category.Finite.Fin.Instance.Triangle import Categories.Category.Groupoid import Categories.Category.Groupoid.Properties import Categories.Category.Helper import Categories.Category.Indiscrete import Categories.Category.Instance.Cartesians import Categories.Category.Instance.Cats import Categories.Category.Instance.EmptySet import Categories.Category.Instance.FamilyOfSetoids import Categories.Category.Instance.FinCatShapes import Categories.Category.Instance.FinSetoids import Categories.Category.Instance.Globe import Categories.Category.Instance.Groupoids import Categories.Category.Instance.KanComplexes import Categories.Category.Instance.LawvereTheories import Categories.Category.Instance.Monoidals import Categories.Category.Instance.Nat import Categories.Category.Instance.One import Categories.Category.Instance.PartialFunctions import Categories.Category.Instance.PointedSets import Categories.Category.Instance.Posets import Categories.Category.Instance.Properties.Cats import Categories.Category.Instance.Properties.Posets import Categories.Category.Instance.Properties.Setoids import Categories.Category.Instance.Properties.Setoids.CCC import Categories.Category.Instance.Properties.Setoids.Cocomplete import Categories.Category.Instance.Properties.Setoids.Complete import Categories.Category.Instance.Properties.Setoids.LCCC import Categories.Category.Instance.Properties.Setoids.Limits.Canonical import Categories.Category.Instance.Quivers import Categories.Category.Instance.Rels import Categories.Category.Instance.Setoids import Categories.Category.Instance.Sets import Categories.Category.Instance.Simplex import Categories.Category.Instance.SimplicialSet import Categories.Category.Instance.SimplicialSet.Properties import Categories.Category.Instance.SingletonSet import Categories.Category.Instance.Span import Categories.Category.Instance.StrictCats import Categories.Category.Instance.StrictGroupoids import Categories.Category.Instance.Zero import Categories.Category.Inverse import Categories.Category.Lift import Categories.Category.Monoidal import Categories.Category.Monoidal.Braided import Categories.Category.Monoidal.Braided.Properties import Categories.Category.Monoidal.Bundle import Categories.Category.Monoidal.Closed import Categories.Category.Monoidal.Closed.IsClosed import Categories.Category.Monoidal.Closed.IsClosed.Diagonal import Categories.Category.Monoidal.Closed.IsClosed.Dinatural import Categories.Category.Monoidal.Closed.IsClosed.Identity import Categories.Category.Monoidal.Closed.IsClosed.L import Categories.Category.Monoidal.Closed.IsClosed.Pentagon import Categories.Category.Monoidal.CompactClosed import Categories.Category.Monoidal.Construction.Minus2 import Categories.Category.Monoidal.Construction.Product import Categories.Category.Monoidal.Core import Categories.Category.Monoidal.Instance.Cats import Categories.Category.Monoidal.Instance.One import Categories.Category.Monoidal.Instance.Rels import Categories.Category.Monoidal.Instance.Setoids import Categories.Category.Monoidal.Instance.Sets import Categories.Category.Monoidal.Instance.StrictCats import Categories.Category.Monoidal.Interchange import Categories.Category.Monoidal.Interchange.Braided import Categories.Category.Monoidal.Interchange.Symmetric import Categories.Category.Monoidal.Properties import Categories.Category.Monoidal.Reasoning import Categories.Category.Monoidal.Rigid import Categories.Category.Monoidal.Star-Autonomous import Categories.Category.Monoidal.Symmetric import Categories.Category.Monoidal.Traced import Categories.Category.Monoidal.Utilities import Categories.Category.Product import Categories.Category.Product.Properties import Categories.Category.Regular import Categories.Category.Restriction import Categories.Category.Restriction.Construction.Trivial import Categories.Category.Restriction.Instance.PartialFunctions import Categories.Category.Restriction.Properties import Categories.Category.RigCategory import Categories.Category.Site import Categories.Category.Slice import Categories.Category.Slice.Properties import Categories.Category.Species import Categories.Category.Species.Constructions import Categories.Category.SubCategory import Categories.Category.Topos import Categories.Category.Unbundled import Categories.Category.Unbundled.Properties import Categories.Category.Unbundled.Utilities import Categories.CoYoneda import Categories.Comonad import Categories.Comonad.Relative import Categories.Diagram.Cocone import Categories.Diagram.Cocone.Properties import Categories.Diagram.Coend import Categories.Diagram.Coend.Properties import Categories.Diagram.Coequalizer import Categories.Diagram.Coequalizer.Properties import Categories.Diagram.Colimit import Categories.Diagram.Colimit.DualProperties import Categories.Diagram.Colimit.Lan import Categories.Diagram.Colimit.Properties import Categories.Diagram.Cone import Categories.Diagram.Cone.Properties import Categories.Diagram.Cowedge import Categories.Diagram.Cowedge.Properties import Categories.Diagram.Duality import Categories.Diagram.End import Categories.Diagram.End.Properties import Categories.Diagram.Equalizer import Categories.Diagram.Equalizer.Indexed import Categories.Diagram.Equalizer.Limit import Categories.Diagram.Equalizer.Properties import Categories.Diagram.Finite import Categories.Diagram.KernelPair import Categories.Diagram.Limit import Categories.Diagram.Limit.Properties import Categories.Diagram.Limit.Ran import Categories.Diagram.Pullback import Categories.Diagram.Pullback.Limit import Categories.Diagram.Pullback.Properties import Categories.Diagram.Pushout import Categories.Diagram.Pushout.Properties import Categories.Diagram.ReflexivePair import Categories.Diagram.SubobjectClassifier import Categories.Diagram.Wedge import Categories.Diagram.Wedge.Properties import Categories.Enriched.Category import Categories.Enriched.Category.Opposite import Categories.Enriched.Category.Underlying import Categories.Enriched.Functor import Categories.Enriched.NaturalTransformation import Categories.Enriched.NaturalTransformation.NaturalIsomorphism import Categories.Enriched.Over.One import Categories.Enriched.Over.Setoids import Categories.Functor import Categories.Functor.Algebra import Categories.Functor.Bifunctor import Categories.Functor.Bifunctor.Properties import Categories.Functor.Cartesian import Categories.Functor.Cartesian.Properties import Categories.Functor.Coalgebra import Categories.Functor.Construction.Constant import Categories.Functor.Construction.Diagonal import Categories.Functor.Construction.FromDiscrete import Categories.Functor.Construction.LiftSetoids import Categories.Functor.Construction.Limit import Categories.Functor.Construction.ObjectRestriction import Categories.Functor.Construction.PathsOf import Categories.Functor.Construction.SubCategory import Categories.Functor.Construction.SubCategory.Properties import Categories.Functor.Construction.Zero import Categories.Functor.Core import Categories.Functor.Duality import Categories.Functor.Equivalence import Categories.Functor.Fibration import Categories.Functor.Groupoid import Categories.Functor.Hom import Categories.Functor.Hom.Properties import Categories.Functor.Hom.Properties.Contra import Categories.Functor.Hom.Properties.Covariant import Categories.Functor.IdentityOnObjects import Categories.Functor.Instance.0-Truncation import Categories.Functor.Instance.01-Truncation import Categories.Functor.Instance.Core import Categories.Functor.Instance.Discrete import Categories.Functor.Instance.SetoidDiscrete import Categories.Functor.Instance.StrictCore import Categories.Functor.Instance.Twisted import Categories.Functor.Instance.UnderlyingQuiver import Categories.Functor.Limits import Categories.Functor.Monoidal import Categories.Functor.Monoidal.Braided import Categories.Functor.Monoidal.Construction.Product import Categories.Functor.Monoidal.PointwiseTensor import Categories.Functor.Monoidal.Properties import Categories.Functor.Monoidal.Symmetric import Categories.Functor.Monoidal.Tensor import Categories.Functor.Power import Categories.Functor.Power.Functorial import Categories.Functor.Power.NaturalTransformation import Categories.Functor.Presheaf import Categories.Functor.Profunctor import Categories.Functor.Properties import Categories.Functor.Representable import Categories.Functor.Restriction import Categories.Functor.Slice import Categories.GlobularSet import Categories.Kan import Categories.Kan.Duality import Categories.Minus2-Category import Categories.Minus2-Category.Construction.Indiscrete import Categories.Minus2-Category.Instance.One import Categories.Minus2-Category.Properties import Categories.Monad import Categories.Monad.Duality import Categories.Monad.Idempotent import Categories.Monad.Relative import Categories.Monad.Strong import Categories.Morphism import Categories.Morphism.Cartesian import Categories.Morphism.Duality import Categories.Morphism.HeterogeneousIdentity import Categories.Morphism.HeterogeneousIdentity.Properties import Categories.Morphism.Idempotent import Categories.Morphism.Idempotent.Bundles import Categories.Morphism.IsoEquiv import Categories.Morphism.Isomorphism import Categories.Morphism.Normal import Categories.Morphism.Notation import Categories.Morphism.Properties import Categories.Morphism.Reasoning import Categories.Morphism.Reasoning.Core import Categories.Morphism.Reasoning.Iso import Categories.Morphism.Regular import Categories.Morphism.Universal import Categories.Multi.Category.Indexed import Categories.NaturalTransformation import Categories.NaturalTransformation.Core import Categories.NaturalTransformation.Dinatural import Categories.NaturalTransformation.Equivalence import Categories.NaturalTransformation.Extranatural import Categories.NaturalTransformation.Hom import Categories.NaturalTransformation.Monoidal import Categories.NaturalTransformation.Monoidal.Braided import Categories.NaturalTransformation.Monoidal.Symmetric import Categories.NaturalTransformation.NaturalIsomorphism import Categories.NaturalTransformation.NaturalIsomorphism.Equivalence import Categories.NaturalTransformation.NaturalIsomorphism.Functors import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal.Braided import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal.Symmetric import Categories.NaturalTransformation.NaturalIsomorphism.Properties import Categories.NaturalTransformation.Properties import Categories.Object.Biproduct import Categories.Object.Cokernel import Categories.Object.Coproduct import Categories.Object.Duality import Categories.Object.Exponential import Categories.Object.Initial import Categories.Object.Kernel import Categories.Object.Kernel.Properties import Categories.Object.Monoid import Categories.Object.NaturalNumber import Categories.Object.NaturalNumber.Properties.F-Algebras import Categories.Object.Product import Categories.Object.Product.Construction import Categories.Object.Product.Core import Categories.Object.Product.Indexed import Categories.Object.Product.Indexed.Properties import Categories.Object.Product.Limit import Categories.Object.Product.Morphisms import Categories.Object.Subobject import Categories.Object.Subobject.Properties import Categories.Object.Terminal import Categories.Object.Terminal.Limit import Categories.Object.Zero import Categories.Pseudofunctor import Categories.Pseudofunctor.Composition import Categories.Pseudofunctor.Hom import Categories.Pseudofunctor.Identity import Categories.Pseudofunctor.Instance.EnrichedUnderlying import Categories.Tactic.Category import Categories.Theory.Lawvere import Categories.Theory.Lawvere.Instance.Identity import Categories.Theory.Lawvere.Instance.Triv import Categories.Utils.EqReasoning import Categories.Utils.Product import Categories.Yoneda import Categories.Yoneda.Continuous import Categories.Yoneda.Properties import Data.Quiver import Data.Quiver.Morphism import Data.Quiver.Paths import Relation.Binary.PropositionalEquality.Subst.Properties
44.740291
78
0.892475
3d973c37d8f3c5ed2d2af1b312e0cf7b4181f7bf
1,026
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Reverse.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/Reverse.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Reverse.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Reverse view ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Reverse where open import Data.List.Base as L hiding (reverse) open import Data.List.Properties open import Function open import Relation.Binary.PropositionalEquality -- If you want to traverse a list from the end, then you can use the -- reverse view of it. infixl 5 _∶_∶ʳ_ data Reverse {a} {A : Set a} : List A → Set a where [] : Reverse [] _∶_∶ʳ_ : ∀ xs (rs : Reverse xs) (x : A) → Reverse (xs ∷ʳ x) module _ {a} {A : Set a} where reverse : (xs : List A) → Reverse (L.reverse xs) reverse [] = [] reverse (x ∷ xs) = cast $ _ ∶ reverse xs ∶ʳ x where cast = subst Reverse (sym $ unfold-reverse x xs) reverseView : (xs : List A) → Reverse xs reverseView xs = cast $ reverse (L.reverse xs) where cast = subst Reverse (reverse-involutive xs)
29.314286
72
0.559454
fb28682470add9af6d1557c4d47022951e27917a
3,939
agda
Agda
test/Succeed/Issue1324.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1324.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1324.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
------------------------------------------------------------------------ -- Library stuff data ⊥ : Set where record ⊤ : Set where constructor tt data Bool : Set where true false : Bool if_then_else_ : ∀ {A : Set} → Bool → A → A → A if true then t else f = t if false then t else f = f data ℕ : Set where zero : ℕ suc : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} _∸_ : ℕ → ℕ → ℕ m ∸ zero = m zero ∸ suc n = zero suc m ∸ suc n = m ∸ n _≤_ : ℕ → ℕ → Bool zero ≤ n = true suc m ≤ zero = false suc m ≤ suc n = m ≤ n data _⊎_ (A : Set) (B : Set) : Set where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B [_,_]₁ : ∀ {A : Set} {B : Set} {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 data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x record Σ (X : Set) (Y : X → Set) : Set where constructor _,_ field proj₁ : X proj₂ : Y proj₁ _×_ : Set → Set → Set X × Y = Σ X λ _ → Y record Sig : Set₁ where constructor _◃_ field Parameter : Set Arity : Parameter → Set open Sig public ⟦_⟧ : Sig → Set → Set ⟦ P ◃ A ⟧ X = Σ P λ p → A p → X Alg : Sig → Set → Set Alg Σ X = ⟦ Σ ⟧ X → X data μ (C : Sig) : Set where sup : Alg C (μ C) const^C : Set → Sig const^C X = X ◃ λ _ → ⊥ _⊎^C_ : Sig → Sig → Sig (P₁ ◃ A₁) ⊎^C (P₂ ◃ A₂) = (P₁ ⊎ P₂) ◃ [ A₁ , A₂ ]₁ _⋆^C_ : Sig → Set → Sig C ⋆^C X = const^C X ⊎^C C _⋆_ : Sig → Set → Set C ⋆ X = μ (C ⋆^C X) act : ∀ {C X} → Alg C (C ⋆ X) act (p , k) = sup (inj₂ p , k) record Monad (T : Set → Set) : Set₁ where infixl 1 _>>=_ field return : ∀ {X} → X → T X _>>=_ : ∀ {X Y} → T X → (X → T Y) → T Y monad : ∀ {Σ} → Monad (_⋆_ Σ) monad {Σ} = record { return = λ x → sup (inj₁ x , λ ()) ; _>>=_ = _>>=_ } where _>>=_ : ∀ {X Y} → Σ ⋆ X → (X → Σ ⋆ Y) → Σ ⋆ Y sup (inj₁ x , _) >>= f = f x sup (inj₂ p , k) >>= f = act (p , λ a → k a >>= f) generic : ∀ {Σ} (p : Parameter Σ) → Σ ⋆ Arity Σ p generic p = act (p , return) where open Monad monad ------------------------------------------------------------------------ -- Example Π : (X : Set) → (X → Set) → Set Π X Y = (x : X) → (X ◃ Y) ⋆ Y x call : ∀ {X Y} → Π X Y call x = generic x dom : ∀ {X Y} → ∀ {x} → (X ◃ Y) ⋆ Y x → (X → Set) → Set dom (sup (inj₁ _ , _)) R = ⊤ dom {Y = Y} (sup (inj₂ x , k)) R = R x × ((y : Y x) → dom (k y) R) data Dom {X}{Y} (f : (x : X) → (X ◃ Y) ⋆ Y x) : X → Set where ⟨_⟩ : ∀ {x} → dom (f x) (Dom f) → Dom f x dom-map : ∀ {X Y} {R₁ R₂ : X → Set} {x} {w : (X ◃ Y) ⋆ Y x} → (∀ {x} → R₁ x → R₂ x) → dom w R₁ → dom w R₂ dom-map {w = sup (inj₁ _ , _)} f _ = tt dom-map {w = sup (inj₂ _ , _)} f (y₁ , k) = f y₁ , λ y₂ → dom-map f (k y₂) {-# TERMINATING #-} bove-capretta : ∀ {X Y} (f : Π X Y) → (x : X) → Dom f x → Y x bove-capretta {X}{Y} f x ⟨ d ⟩ = helper (f x) (dom-map (λ {x′} → bove-capretta f x′) d) where helper : ∀ {x} (w : (X ◃ Y) ⋆ Y x) → dom w Y → Y x helper (sup (inj₁ y , _)) _ = y helper (sup (inj₂ _ , k)) (d , dk) = helper (k d) (dk d) -- AIM XXIX, 2019-03-18, issue #3597 -- Freezing cannot be prevented by eta-expansion any more. -- WAS: -- module _ where -- open Monad monad -- -- Ulf: proper use of monad would be this: -- module _ where -- open module M {Σ} = Monad (monad {Σ}) -- -- Andreas: this works because metas in module parameters are not frozed immediately module _ (open Monad monad) where gcd : Π (ℕ × ℕ) (λ _ → ℕ) gcd (0 , n) = return n gcd (m , 0) = return m gcd (suc m , suc n) = if m ≤ n then call (suc m , (n ∸ m)) else call ((m ∸ n) , suc n) acc : Dom gcd (8 , 12) acc = ⟨ ⟨ ⟨ ⟨ _ ⟩ , _ ⟩ , _ ⟩ , _ ⟩ -- ⟨ ⟨ ⟨ ⟨ tt ⟩ , (λ _ → tt) ⟩ , (λ _ → tt) ⟩ , (λ _ → tt) ⟩ test-gcd′ : bove-capretta gcd (8 , 12) acc ≡ 4 test-gcd′ = refl
23.586826
96
0.44199
580a11db74be97a3a50f2ff2952bfbebcc83ca5e
8,013
agda
Agda
Cubical/Algebra/Lattice/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/Lattice/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/Lattice/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.Lattice.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.Semilattice open import Cubical.Displayed.Base open import Cubical.Displayed.Auto open import Cubical.Displayed.Record open import Cubical.Displayed.Universe open import Cubical.Reflection.RecordEquiv open Iso private variable ℓ ℓ' : Level record IsLattice {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) : Type ℓ where constructor islattice field joinSemilattice : IsSemilattice 0l _∨l_ meetSemilattice : IsSemilattice 1l _∧l_ absorb : (x y : L) → (x ∨l (x ∧l y) ≡ x) × (x ∧l (x ∨l y) ≡ x) open IsSemilattice joinSemilattice public renaming ( assoc to ∨lAssoc ; identity to ∨lIdentity ; lid to ∨lLid ; rid to ∨lRid ; comm to ∨lComm ; idem to ∨lIdem ; isCommMonoid to ∨lIsCommMonoid ; isMonoid to ∨lIsMonoid ; isSemigroup to ∨lIsSemigroup ) open IsSemilattice meetSemilattice public renaming ( assoc to ∧lAssoc ; identity to ∧lIdentity ; lid to ∧lLid ; rid to ∧lRid ; comm to ∧lComm ; idem to ∧lIdem ; isCommMonoid to ∧lIsCommMonoid ; isMonoid to ∧lIsMonoid ; isSemigroup to ∧lIsSemigroup ) hiding ( is-set ) ∨lAbsorb∧l : (x y : L) → x ∨l (x ∧l y) ≡ x ∨lAbsorb∧l x y = absorb x y .fst ∧lAbsorb∨l : (x y : L) → x ∧l (x ∨l y) ≡ x ∧lAbsorb∨l x y = absorb x y .snd record LatticeStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor latticestr field 0l : A 1l : A _∨l_ : A → A → A _∧l_ : A → A → A isLattice : IsLattice 0l 1l _∨l_ _∧l_ infix 6 _∨l_ infix 6 _∧l_ open IsLattice isLattice public Lattice : ∀ ℓ → Type (ℓ-suc ℓ) Lattice ℓ = TypeWithStr ℓ LatticeStr isSetLattice : (L : Lattice ℓ) → isSet ⟨ L ⟩ isSetLattice L = L .snd .LatticeStr.is-set makeIsLattice : {L : Type ℓ} {0l 1l : L} {_∨l_ _∧l_ : L → L → L} (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-lid : (x : L) → 0l ∨l x ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-lid : (x : L) → 1l ∧l x ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) → IsLattice 0l 1l _∨l_ _∧l_ makeIsLattice {0l = 0l} {1l = 1l} {_∨l_ = _∨l_} {_∧l_ = _∧l_} is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l = islattice (makeIsSemilattice is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∨l-idem) (makeIsSemilattice is-setL ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∧l-idem) λ x y → ∨l-absorb-∧l x y , ∧l-absorb-∨l x y where ∨l-idem : ∀ x → x ∨l x ≡ x ∨l-idem x = cong (x ∨l_) (sym (∧l-rid _)) ∙ ∨l-absorb-∧l _ _ ∧l-idem : ∀ x → x ∧l x ≡ x ∧l-idem x = cong (x ∧l_) (sym (∨l-rid _)) ∙ ∧l-absorb-∨l _ _ makeLattice : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) (is-setL : isSet L) (∨l-assoc : (x y z : L) → x ∨l (y ∨l z) ≡ (x ∨l y) ∨l z) (∨l-rid : (x : L) → x ∨l 0l ≡ x) (∨l-lid : (x : L) → 0l ∨l x ≡ x) (∨l-comm : (x y : L) → x ∨l y ≡ y ∨l x) (∨l-idem : (x : L) → x ∨l x ≡ x) (∧l-assoc : (x y z : L) → x ∧l (y ∧l z) ≡ (x ∧l y) ∧l z) (∧l-rid : (x : L) → x ∧l 1l ≡ x) (∧l-lid : (x : L) → 1l ∧l x ≡ x) (∧l-comm : (x y : L) → x ∧l y ≡ y ∧l x) (∧l-idem : (x : L) → x ∧l x ≡ x) (∨l-absorb-∧l : (x y : L) → x ∨l (x ∧l y) ≡ x) (∧l-absorb-∨l : (x y : L) → x ∧l (x ∨l y) ≡ x) → Lattice ℓ makeLattice 0l 1l _∨l_ _∧l_ is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∨l-idem ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∧l-idem ∨l-absorb-∧l ∧l-absorb-∨l = _ , latticestr 0l 1l _∨l_ _∧l_ (makeIsLattice is-setL ∨l-assoc ∨l-rid ∨l-lid ∨l-comm ∧l-assoc ∧l-rid ∧l-lid ∧l-comm ∨l-absorb-∧l ∧l-absorb-∨l) record IsLatticeHom {A : Type ℓ} {B : Type ℓ'} (L : LatticeStr A) (f : A → B) (M : LatticeStr B) : Type (ℓ-max ℓ ℓ') where -- Shorter qualified names private module L = LatticeStr L module M = LatticeStr M field pres0 : f L.0l ≡ M.0l pres1 : f L.1l ≡ M.1l pres∨l : (x y : A) → f (x L.∨l y) ≡ f x M.∨l f y pres∧l : (x y : A) → f (x L.∧l y) ≡ f x M.∧l f y unquoteDecl IsLatticeHomIsoΣ = declareRecordIsoΣ IsLatticeHomIsoΣ (quote IsLatticeHom) LatticeHom : (L : Lattice ℓ) (M : Lattice ℓ') → Type (ℓ-max ℓ ℓ') LatticeHom L M = Σ[ f ∈ (⟨ L ⟩ → ⟨ M ⟩) ] IsLatticeHom (L .snd) f (M .snd) idLatticeHom : (L : Lattice ℓ) → LatticeHom L L fst (idLatticeHom L) x = x IsLatticeHom.pres0 (snd (idLatticeHom L)) = refl IsLatticeHom.pres1 (snd (idLatticeHom L)) = refl IsLatticeHom.pres∨l (snd (idLatticeHom L)) x y = refl IsLatticeHom.pres∧l (snd (idLatticeHom L)) x y = refl IsLatticeEquiv : {A : Type ℓ} {B : Type ℓ'} (M : LatticeStr A) (e : A ≃ B) (N : LatticeStr B) → Type (ℓ-max ℓ ℓ') IsLatticeEquiv M e N = IsLatticeHom M (e .fst) N LatticeEquiv : (L : Lattice ℓ) (M : Lattice ℓ') → Type (ℓ-max ℓ ℓ') LatticeEquiv L M = Σ[ e ∈ (⟨ L ⟩ ≃ ⟨ M ⟩) ] IsLatticeEquiv (L .snd) e (M .snd) isPropIsLattice : {L : Type ℓ} (0l 1l : L) (_∨l_ _∧l_ : L → L → L) → isProp (IsLattice 0l 1l _∨l_ _∧l_) isPropIsLattice 0l 1l _∨l_ _∧l_ (islattice LJ LM LA) (islattice MJ MM MA) = λ i → islattice (isPropIsSemilattice _ _ LJ MJ i) (isPropIsSemilattice _ _ LM MM i) (isPropAbsorb LA MA i) where isSetL : isSet _ isSetL = LJ .IsSemilattice.isCommMonoid .IsCommMonoid.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set isPropAbsorb : isProp ((x y : _) → (x ∨l (x ∧l y) ≡ x) × (x ∧l (x ∨l y) ≡ x)) isPropAbsorb = isPropΠ2 λ _ _ → isProp× (isSetL _ _) (isSetL _ _) isPropIsLatticeHom : {A : Type ℓ} {B : Type ℓ'} (R : LatticeStr A) (f : A → B) (S : LatticeStr B) → isProp (IsLatticeHom R f S) isPropIsLatticeHom R f S = isOfHLevelRetractFromIso 1 IsLatticeHomIsoΣ (isProp×3 (isSetLattice (_ , S) _ _) (isSetLattice (_ , S) _ _) (isPropΠ2 λ _ _ → isSetLattice (_ , S) _ _) (isPropΠ2 λ _ _ → isSetLattice (_ , S) _ _)) 𝒮ᴰ-Lattice : DUARel (𝒮-Univ ℓ) LatticeStr ℓ 𝒮ᴰ-Lattice = 𝒮ᴰ-Record (𝒮-Univ _) IsLatticeEquiv (fields: data[ 0l ∣ null ∣ pres0 ] data[ 1l ∣ null ∣ pres1 ] data[ _∨l_ ∣ bin ∣ pres∨l ] data[ _∧l_ ∣ bin ∣ pres∧l ] prop[ isLattice ∣ (λ _ _ → isPropIsLattice _ _ _ _) ]) where open LatticeStr open IsLatticeHom -- faster with some sharing null = autoDUARel (𝒮-Univ _) (λ A → A) bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A) LatticePath : (L M : Lattice ℓ) → LatticeEquiv L M ≃ (L ≡ M) LatticePath = ∫ 𝒮ᴰ-Lattice .UARel.ua Lattice→JoinSemilattice : Lattice ℓ → Semilattice ℓ Lattice→JoinSemilattice (A , latticestr _ _ _ _ L) = semilattice _ _ _ (L .IsLattice.joinSemilattice ) Lattice→MeetSemilattice : Lattice ℓ → Semilattice ℓ Lattice→MeetSemilattice (A , latticestr _ _ _ _ L) = semilattice _ _ _ (L .IsLattice.meetSemilattice )
34.538793
102
0.555472
0b0efefaf6555c6c82ff2a6f6220ad4c1e9930c1
148
agda
Agda
test/interaction/Issue3032.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue3032.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue3032.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
postulate A : Set B : Set t : B data C : (b : B) → Set foo : (b : B) → C b → B data C where c : (x : C t) → C (foo t x) foo b x = {!x!}
10.571429
29
0.425676
a149bb1e877edf01aedc8d49b43c99b78a2f8302
12,702
agda
Agda
theorems/cw/cohomology/ReconstructedCochainsEquivCellularCochains.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/cw/cohomology/ReconstructedCochainsEquivCellularCochains.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/cw/cohomology/ReconstructedCochainsEquivCellularCochains.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import cw.CW open import cw.FinCW open import cw.FinBoundary open import cohomology.Theory open import cohomology.ChainComplex module cw.cohomology.ReconstructedCochainsEquivCellularCochains (OT : OrdinaryTheory lzero) where open OrdinaryTheory OT open import cw.cohomology.cellular.ChainComplex as CCC open import cw.cohomology.reconstructed.cochain.Complex OT as RCC open import cw.cohomology.ReconstructedCochainsIsoCellularCochains OT open import cw.cohomology.cochainequiv.AugmentCommSquare OT open import cw.cohomology.cochainequiv.FirstCoboundaryCommSquare OT open import cw.cohomology.cochainequiv.HigherCoboundaryCommSquare OT private frcc-comm-fccc-Type : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) {m} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n)) (coboundary : AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ m≤n?) →ᴳ AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ Sm≤n?)) (boundary : AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ Sm≤n?) →ᴳ AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ m≤n?)) → Type₀ frcc-comm-fccc-Type {n} ⊙fin-skel {m} m≤n? Sm≤n? coboundary boundary = CommSquareᴳ coboundary (pre∘ᴳ-hom (C2-abgroup 0) boundary) (GroupIso.f-hom (rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ m≤n? (⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero))) (GroupIso.f-hom (rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ Sm≤n? (⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero))) CCC-boundary-template' : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) → {m : ℕ} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n)) → AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ Sm≤n?) →ᴳ AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ m≤n?) CCC-boundary-template' ⊙fin-skel = CCC.boundary-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)) RCC-coboundary-template' : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) → {m : ℕ} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n)) → AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ m≤n?) →ᴳ AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ Sm≤n?) RCC-coboundary-template' ⊙fin-skel = RCC.coboundary-template ⊙⦉ ⊙fin-skel ⦊ abstract {- This can be directly generalized to the non-finite cases. -} frcc-comm-fccc-above : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) {m} (m≤n? : Dec (m ≤ n)) (Sm≰n : ¬ (S m ≤ n)) → frcc-comm-fccc-Type ⊙fin-skel m≤n? (inr Sm≰n) (RCC-coboundary-template' ⊙fin-skel m≤n? (inr Sm≰n)) (CCC-boundary-template' ⊙fin-skel m≤n? (inr Sm≰n)) frcc-comm-fccc-above ⊙fin-skel m≤n? Sm≰n = (comm-sqrᴳ λ g → group-hom= $ λ= λ _ → ! $ GroupHom.pres-ident (GroupIso.f (rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ m≤n? (⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero)) g)) frcc-comm-fccc-nth-zero : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) (0≤n : 0 ≤ n) (1≤n : 1 ≤ n) → frcc-comm-fccc-Type ⊙fin-skel (inl 0≤n) (inl 1≤n) (RCC-coboundary-template' ⊙fin-skel (inl 0≤n) (inl 1≤n)) (CCC-boundary-template' ⊙fin-skel (inl 0≤n) (inl 1≤n)) frcc-comm-fccc-nth-zero ⊙fin-skel (inl idp) (inl 1=0) = ⊥-rec (ℕ-S≠O O 1=0) frcc-comm-fccc-nth-zero ⊙fin-skel (inl idp) (inr ()) frcc-comm-fccc-nth-zero ⊙fin-skel (inr ltS) (inl 1=1) = transport! (λ 1=1 → frcc-comm-fccc-Type ⊙fin-skel (inl lteS) (inl (inl 1=1)) (RCC-coboundary-template' ⊙fin-skel (inl lteS) (inl (inl 1=1))) (CCC-boundary-template' ⊙fin-skel (inl lteS) (inl (inl 1=1)))) (prop-has-all-paths 1=1 idp) (coe! (ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel {m = O} (inl (inr ltS)) (inl (inl idp)) p₁ p₂) (RCC.coboundary-first-template-β ⊙⦉ ⊙fin-skel ⦊) (CCC.boundary-template-β ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)))) (fst (first-coboundary-comm-sqrᴳ ⊙fin-skel))) frcc-comm-fccc-nth-zero ⊙fin-skel (inr ltS) (inr (ltSR ())) frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR 0<n)) (inl 1=Sn) = ⊥-rec (<-to-≠ (<-ap-S 0<n) 1=Sn) frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR ltS)) (inr 1<2) = transport! (λ 1<2 → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr 1<2)) (RCC-coboundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr 1<2))) (CCC-boundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr 1<2)))) (prop-has-all-paths 1<2 ltS) (coe! (ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr ltS)) p₁ p₂) (RCC.coboundary-first-template-descend-from-two ⊙⦉ ⊙fin-skel ⦊) (CCC.boundary-template-descend-from-two-above ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)))) (frcc-comm-fccc-nth-zero (⊙fcw-init ⊙fin-skel) (inr ltS) (inl idp))) frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR (ltSR ()))) (inr ltS) frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR (ltSR 0<n))) (inr (ltSR 1<Sn)) = (coe! (ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR (ltSR 0<n)))) (inl (inr (ltSR 1<Sn))) p₁ p₂) (RCC.coboundary-first-template-descend-from-far ⊙⦉ ⊙fin-skel ⦊ (ltSR 0<n) 1<Sn) (CCC.boundary-template-descend-from-far ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)) (ltSR 0<n) 1<Sn)) (frcc-comm-fccc-nth-zero (⊙fcw-init ⊙fin-skel) (inr (ltSR 0<n)) (inr 1<Sn))) frcc-comm-fccc-nth-higher : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) {m} (Sm≤n : S m ≤ n) (SSm≤n : S (S m) ≤ n) → frcc-comm-fccc-Type ⊙fin-skel (inl Sm≤n) (inl SSm≤n) (RCC-coboundary-template' ⊙fin-skel (inl Sm≤n) (inl SSm≤n)) (CCC-boundary-template' ⊙fin-skel (inl Sm≤n) (inl SSm≤n)) frcc-comm-fccc-nth-higher ⊙fin-skel (inl idp) (inl SSm=Sm) = ⊥-rec (<-to-≠ ltS (! SSm=Sm)) frcc-comm-fccc-nth-higher ⊙fin-skel (inl idp) (inr SSm<Sm) = ⊥-rec (<-to-≠ (<-trans SSm<Sm ltS) idp) frcc-comm-fccc-nth-higher ⊙fin-skel {m} (inr ltS) (inl SSm=SSm) = transport! (λ SSm=SSm → frcc-comm-fccc-Type ⊙fin-skel (inl lteS) (inl (inl SSm=SSm)) (RCC-coboundary-template' ⊙fin-skel (inl lteS) (inl (inl SSm=SSm))) (CCC-boundary-template' ⊙fin-skel (inl lteS) (inl (inl SSm=SSm)))) (prop-has-all-paths SSm=SSm idp) (coe! (ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel {m = S m} (inl (inr ltS)) (inl (inl idp)) p₁ p₂) (RCC.coboundary-higher-template-β ⊙⦉ ⊙fin-skel ⦊) (CCC.boundary-template-β ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)))) (fst (higher-coboundary-comm-sqrᴳ ⊙fin-skel))) frcc-comm-fccc-nth-higher ⊙fin-skel (inr ltS) (inr SSm<SSm) = ⊥-rec (<-to-≠ SSm<SSm idp) frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR Sm<n)) (inl SSm=Sn) = ⊥-rec (<-to-≠ (<-ap-S Sm<n) SSm=Sn) frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR ltS)) (inr SSm<SSSm) = transport! (λ SSm<SSSm → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr SSm<SSSm)) (RCC-coboundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr SSm<SSSm))) (CCC-boundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr SSm<SSSm)))) (prop-has-all-paths SSm<SSSm ltS) (coe! (ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr ltS)) p₁ p₂) (RCC.coboundary-higher-template-descend-from-one-above ⊙⦉ ⊙fin-skel ⦊) (CCC.boundary-template-descend-from-two-above ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)))) (frcc-comm-fccc-nth-higher (⊙fcw-init ⊙fin-skel) (inr ltS) (inl idp))) frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR (ltSR Sm<Sm))) (inr ltS) = ⊥-rec (<-to-≠ Sm<Sm idp) frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR (ltSR Sm<n))) (inr (ltSR SSm<Sn)) = (coe! (ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR (ltSR Sm<n)))) (inl (inr (ltSR SSm<Sn))) p₁ p₂) (RCC.coboundary-higher-template-descend-from-far ⊙⦉ ⊙fin-skel ⦊ (ltSR Sm<n) SSm<Sn) (CCC.boundary-template-descend-from-far ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)) (ltSR Sm<n) SSm<Sn)) (frcc-comm-fccc-nth-higher (⊙fcw-init ⊙fin-skel) (inr (ltSR Sm<n)) (inr SSm<Sn))) frcc-comm-fccc-template : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) {m} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n)) → frcc-comm-fccc-Type ⊙fin-skel m≤n? Sm≤n? (RCC-coboundary-template' ⊙fin-skel m≤n? Sm≤n?) (CCC-boundary-template' ⊙fin-skel m≤n? Sm≤n?) frcc-comm-fccc-template ⊙fin-skel m≤n? (inr Sm≰n) = frcc-comm-fccc-above ⊙fin-skel m≤n? Sm≰n frcc-comm-fccc-template ⊙fin-skel (inr m≰n) (inl Sm≤n) = ⊥-rec $ m≰n (≤-trans lteS Sm≤n) frcc-comm-fccc-template ⊙fin-skel {m = O} (inl m≤n) (inl Sm≤n) = frcc-comm-fccc-nth-zero ⊙fin-skel m≤n Sm≤n frcc-comm-fccc-template ⊙fin-skel {m = S m} (inl Sm≤n) (inl SSm≤n) = frcc-comm-fccc-nth-higher ⊙fin-skel Sm≤n SSm≤n frcc-comm-fccc : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) m → frcc-comm-fccc-Type ⊙fin-skel (≤-dec m n) (≤-dec (S m) n) (RCC-coboundary-template' ⊙fin-skel (≤-dec m n) (≤-dec (S m) n)) (CCC-boundary-template' ⊙fin-skel (≤-dec m n) (≤-dec (S m) n)) frcc-comm-fccc {n} ⊙fin-skel m = frcc-comm-fccc-template ⊙fin-skel {m} (≤-dec m n) (≤-dec (S m) n) frcc-comm-fccc-augment : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) → CommSquareᴳ (CochainComplex.augment (RCC.cochain-complex ⊙⦉ ⊙fin-skel ⦊)) (pre∘ᴳ-hom (C2-abgroup 0) (FreeAbelianGroup.Freeness.extend _ (Lift-abgroup {j = lzero} ℤ-abgroup) λ _ → lift 1)) (GroupIso.f-hom rhead-iso-chead) (GroupIso.f-hom (rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ (inl (O≤ n)) (⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero))) frcc-comm-fccc-augment {n = O} ⊙fin-skel = fst (augment-comm-sqrᴳ ⊙fin-skel) frcc-comm-fccc-augment {n = S O} ⊙fin-skel = frcc-comm-fccc-augment (⊙fcw-init ⊙fin-skel) frcc-comm-fccc-augment {n = S (S n)} ⊙fin-skel = frcc-comm-fccc-augment (⊙fcw-init ⊙fin-skel) frcc-equiv-fccc : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) → CochainComplexEquiv (RCC.cochain-complex ⊙⦉ ⊙fin-skel ⦊) (CCC.cochain-complex ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)) (C2-abgroup 0)) frcc-equiv-fccc {n} ⊙fin-skel = record { head = rhead-iso-chead ; cochain = λ m → rcc-iso-ccc ⊙⦉ ⊙fin-skel ⦊ m (⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero) ; augment = frcc-comm-fccc-augment ⊙fin-skel ; coboundary = frcc-comm-fccc ⊙fin-skel} frc-iso-fcc : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) (m : ℤ) → cohomology-group (RCC.cochain-complex ⊙⦉ ⊙fin-skel ⦊) m ≃ᴳ cohomology-group (CCC.cochain-complex ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ (FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel)) (FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel)) (C2-abgroup 0)) m frc-iso-fcc ⊙fin-skel = cohomology-group-emap (frcc-equiv-fccc ⊙fin-skel)
60.485714
125
0.591324
580427716fc8f33b4193a2e1f6d9086fa74c42fa
460
agda
Agda
test/Succeed/Issue3538.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3538.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3538.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --rewriting #-} open import Agda.Builtin.Equality {-# BUILTIN REWRITE _≡_ #-} module _ (Form : Set) where -- FAILS -- postulate Form : Set -- WORKS data Cxt : Set where ε : Cxt _∙_ : (Γ : Cxt) (A : Form) → Cxt data _≤_ : (Γ Δ : Cxt) → Set where id≤ : ∀{Γ} → Γ ≤ Γ weak : ∀{A Γ Δ} (τ : Γ ≤ Δ) → (Γ ∙ A) ≤ Δ lift : ∀{A Γ Δ} (τ : Γ ≤ Δ) → (Γ ∙ A) ≤ (Δ ∙ A) postulate lift-id≤ : ∀{Γ A} → lift id≤ ≡ id≤ {Γ ∙ A} {-# REWRITE lift-id≤ #-}
23
52
0.5
57aba13abe277a62d2890838e77d1e4287efd81d
14,760
agda
Agda
agda/sn-calculus-compatconf.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
3
2020-04-16T10:58:53.000Z
2020-07-01T03:59:31.000Z
agda/sn-calculus-compatconf.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
null
null
null
agda/sn-calculus-compatconf.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
1
2020-04-15T20:02:49.000Z
2020-04-15T20:02:49.000Z
module sn-calculus-compatconf where open import sn-calculus open import utility renaming (_U̬_ to _∪_) open import context-properties using (get-view ; ->E-view ; ->pot-view) open import sn-calculus-compatconf.eview using (1-steplρ-E-view) open import sn-calculus-compatconf.pot using (1-steplρ-pot) open import sn-calculus-confluence using (R-confluent) open import Esterel.Lang open import Esterel.Lang.Binding open import Esterel.Lang.Properties open import Esterel.Environment as Env using (Env ; Θ ; _←_ ; module SigMap ; module ShrMap ; module VarMap) open import Esterel.Context using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ; Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c) 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 Relation.Nullary using (¬_ ; Dec ; yes ; no) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning) open import Data.Bool using (Bool ; if_then_else_) open import Data.Empty using (⊥ ; ⊥-elim) open import Data.List using (List ; _∷_ ; [] ; _++_) open import Data.List.Any using (Any ; any ; here ; there) open import Data.List.Any.Properties using () renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ) open import Data.Maybe using (Maybe ; just ; nothing) open import Data.Nat using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_) open import Data.Product using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_ ; ∃) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) open import Function using (_∘_ ; id ; _∋_) 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 open ->E-view open ->pot-view open EvaluationContext1 open _≐_⟦_⟧e open Context1 open _≐_⟦_⟧c open ListSet Data.Nat._≟_ 1-step-sn⟶₁ : ∀{p q r BV FV} → CorrectBinding p BV FV → p sn⟶₁ q → p sn⟶₁ r → Σ[ p' ∈ Term ] (q sn⟶* p' × r sn⟶* p') 1-step-sn⟶₁ cb psn⟶₁q psn⟶₁r with R-confluent cb psn⟶₁q psn⟶₁r ... | inj₁ refl = _ , rrefl ,′ rrefl ... | inj₂ (inj₁ (_ , qsn⟶₁s , rsn⟶₁s)) = _ , sn⟶*-inclusion (sn⟶-inclusion qsn⟶₁s) ,′ sn⟶*-inclusion (sn⟶-inclusion rsn⟶₁s) ... | inj₂ (inj₂ (inj₁ qsn⟶₁r)) = _ , sn⟶*-inclusion (sn⟶-inclusion qsn⟶₁r) ,′ rrefl ... | inj₂ (inj₂ (inj₂ rsn⟶₁q)) = _ , rrefl ,′ sn⟶*-inclusion (sn⟶-inclusion rsn⟶₁q) 1-steplρ : ∀{p q r θ θq BV FV A Aq} → CorrectBinding (ρ⟨ θ , A ⟩· p) BV FV → ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θq , Aq ⟩· q → p sn⟶ r → Σ[ p' ∈ Term ] ((ρ⟨ θq , Aq ⟩· q) sn⟶* p' × (ρ⟨ θ , A ⟩· r) sn⟶* p') 1-steplρ {p} {q} {r} cb ρθ·psn⟶₁ρθq·q psn⟶r@(rcontext {.p} {rin} {ro} C p≐C⟦rin⟧ rinsn⟶₁ro) with get-view ρθ·psn⟶₁ρθq·q ... | inj₂ (refl , refl , pot) = _ , 1-steplρ-pot cb pot psn⟶r ... | inj₁ (E , qin , qo , p≐E⟦qin⟧ , q≐E⟦qo⟧ , e-view) = _ , proj₂ (1-steplρ-E-view cb p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐C⟦rin⟧ rinsn⟶₁ro) 1-stepl : ∀{p q r BV FV} → CorrectBinding p BV FV → p sn⟶₁ q → p sn⟶ r → Σ[ p' ∈ Term ] (q sn⟶* p' × r sn⟶* p') 1-stepl cb psn⟶₁q (rcontext [] dchole psn⟶₁r) = 1-step-sn⟶₁ cb psn⟶₁q psn⟶₁r 1-stepl cb (rpar-done-right p' q') (rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) = ⊥-elim (halted-¬sn⟶ p' (rcontext _ dcr psn⟶₁r)) 1-stepl cb (rpar-done-left (dhalted p') q') (rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) = ⊥-elim (halted-¬sn⟶ p' (rcontext _ dcr psn⟶₁r)) 1-stepl cb (rpar-done-left (dpaused p') hnothin) (rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ dcr psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ dchole (rpar-done-left (dpaused (paused-sn⟶ p' (rcontext _ dcr psn⟶₁r))) hnothin)) 1-stepl cb (rpar-done-left (dpaused p') (hexit n)) (rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) = _ , rrefl ,′ sn⟶*-inclusion (rcontext _ dchole (rpar-done-left (dpaused (paused-sn⟶ p' (rcontext _ dcr psn⟶₁r))) (hexit n))) 1-stepl cb (rpar-done-right p' (dhalted q')) (rcontext (ceval (epar₂ p₁) ∷ crs) (dcpar₂ dcr) psn⟶₁r) = ⊥-elim (halted-¬sn⟶ q' (rcontext _ dcr psn⟶₁r)) 1-stepl cb (rpar-done-right hnothin (dpaused q')) (rcontext (ceval (epar₂ .nothin) ∷ crs) (dcpar₂ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ dcr psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ dchole (rpar-done-right hnothin (dpaused (paused-sn⟶ q' (rcontext _ dcr psn⟶₁r))))) 1-stepl cb (rpar-done-right (hexit n) (dpaused q')) (rcontext (ceval (epar₂ .(exit n)) ∷ crs) (dcpar₂ dcr) psn⟶₁r) = _ , rrefl ,′ sn⟶*-inclusion (rcontext _ dchole (rpar-done-right (hexit n) (dpaused (paused-sn⟶ q' (rcontext _ dcr psn⟶₁r))))) 1-stepl cb (rpar-done-left p' q') (rcontext (ceval (epar₂ p₁) ∷ crs) (dcpar₂ dcr) psn⟶₁r) = ⊥-elim (halted-¬sn⟶ q' (rcontext _ dcr psn⟶₁r)) 1-stepl cb rseq-done (rcontext _ (dcseq₁ dchole) psn⟶₁r) = ⊥-elim (halted-¬sn⟶₁ hnothin psn⟶₁r) 1-stepl cb rseq-exit (rcontext _ (dcseq₁ dchole) psn⟶₁r) = ⊥-elim (halted-¬sn⟶₁ (hexit _) psn⟶₁r) 1-stepl cb rloopˢ-exit (rcontext _ (dcloopˢ₁ dchole) psn⟶₁r) = ⊥-elim (halted-¬sn⟶₁ (hexit _) psn⟶₁r) 1-stepl cb (rsuspend-done p') (rcontext (ceval (esuspend S) ∷ crs) (dcsuspend dcr) psn⟶₁r) = ⊥-elim (halted-¬sn⟶₁ (halted-⟦⟧c p' dcr) psn⟶₁r) 1-stepl cb (rtrap-done p') (rcontext (ceval etrap ∷ crs) (dctrap dcr) psn⟶₁r) = ⊥-elim (halted-¬sn⟶₁ (halted-⟦⟧c p' dcr) psn⟶₁r) 1-stepl cb rraise-signal (rcontext (csignl S ∷ crs) (dcsignl dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcenv dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ dchole rraise-signal) 1-stepl cb rloop-unroll (rcontext (cloop ∷ crs) (dcloop dcr) psn⟶₁r) = _ , rstep (rcontext _ (dcloopˢ₁ dcr) psn⟶₁r) (rstep (rcontext _ (dcloopˢ₂ dcr) psn⟶₁r) rrefl) ,′ sn⟶*-inclusion (rcontext [] dchole rloop-unroll) 1-stepl cb rseq-done (rcontext (cseq₂ .nothin ∷ crs) (dcseq₂ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ dcr psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ dchole rseq-done) 1-stepl cb rseq-exit (rcontext (cseq₂ .(exit _) ∷ crs) (dcseq₂ dcr) psn⟶₁r) = _ , rrefl ,′ sn⟶*-inclusion (rcontext _ dchole rseq-exit) 1-stepl cb rloopˢ-exit (rcontext (cloopˢ₂ .(exit _) ∷ crs) (dcloopˢ₂ dcr) psn⟶₁r) = _ , rrefl ,′ sn⟶*-inclusion (rcontext _ dchole rloopˢ-exit) 1-stepl {ρ⟨ .θ , .A ⟩· p} cb ρθpsn⟶₁q ρθpsn⟶r@(rcontext {p = p₂} {p' = r} (cenv θ A ∷ crs) (dcenv p≐crs⟦p₂⟧) p₂sn⟶₁r) with ρ-stays-ρ-sn⟶₁ ρθpsn⟶₁q ... | θ' , A' , qin , refl = 1-steplρ cb ρθpsn⟶₁q (rcontext crs p≐crs⟦p₂⟧ p₂sn⟶₁r) 1-step : ∀{p q r BV FV} → CorrectBinding p BV FV → p sn⟶ q → p sn⟶ r → Σ[ p' ∈ Term ] (q sn⟶* p' × r sn⟶* p') 1-step cb (rcontext [] dchole psn⟶₁q) psn⟶r = 1-stepl cb psn⟶₁q psn⟶r 1-step cb psn⟶q@(rcontext (_ ∷ _) _ _) (rcontext [] dchole psn⟶₁r) with 1-stepl cb psn⟶₁r psn⟶q ... | _ , rsn⟶*p' , qsn⟶*p' = _ , qsn⟶*p' ,′ rsn⟶*p' 1-step cb@(CBpar cbp cbq _ _ _ _) (rcontext (cq ∷ cqs) (dcpar₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpar₁ dcr) psn⟶₁r) with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBpar cbp cbq _ _ _ _) (rcontext (cq ∷ cqs) (dcpar₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpar₂ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcpar₂ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcpar₁ dcq) psn⟶₁q) 1-step cb@(CBpar cbp cbq _ _ _ _) (rcontext (cq ∷ cqs) (dcpar₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpar₁ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcpar₁ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcpar₂ dcq) psn⟶₁q) 1-step cb@(CBpar cbp cbq _ _ _ _) (rcontext (cq ∷ cqs) (dcpar₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpar₂ dcr) psn⟶₁r) with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBseq cbp cbq _) (rcontext (cq ∷ cqs) (dcseq₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcseq₁ dcr) psn⟶₁r) with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb (rcontext (cq ∷ cqs) (dcseq₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcseq₂ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcseq₂ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcseq₁ dcq) psn⟶₁q) 1-step cb (rcontext (cq ∷ cqs) (dcseq₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcseq₁ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcseq₁ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcseq₂ dcq) psn⟶₁q) 1-step cb@(CBseq cbp cbq _) (rcontext (cq ∷ cqs) (dcseq₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcseq₂ dcr) psn⟶₁r) with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBloopˢ cbp cbq _ _) (rcontext (cq ∷ cqs) (dcloopˢ₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcloopˢ₁ dcr) psn⟶₁r) with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb (rcontext (cq ∷ cqs) (dcloopˢ₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcloopˢ₂ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcloopˢ₂ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcloopˢ₁ dcq) psn⟶₁q) 1-step cb (rcontext (cq ∷ cqs) (dcloopˢ₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcloopˢ₁ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcloopˢ₁ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcloopˢ₂ dcq) psn⟶₁q) 1-step cb@(CBloopˢ cbp cbq _ _) (rcontext (cq ∷ cqs) (dcloopˢ₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcloopˢ₂ dcr) psn⟶₁r) with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBsusp cb' _) (rcontext (cq ∷ cqs) (dcsuspend dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcsuspend dcr) psn⟶₁r) with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBtrap cb') (rcontext (cq ∷ cqs) (dctrap dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dctrap dcr) psn⟶₁r) with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBsig cb') (rcontext (cq ∷ cqs) (dcsignl dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcsignl dcr) psn⟶₁r) with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBpresent cbp cbq) (rcontext (cq ∷ cqs) (dcpresent₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpresent₁ dcr) psn⟶₁r) with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb (rcontext (cq ∷ cqs) (dcpresent₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpresent₂ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcpresent₂ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcpresent₁ dcq) psn⟶₁q) 1-step cb (rcontext (cq ∷ cqs) (dcpresent₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpresent₁ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcpresent₁ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcpresent₂ dcq) psn⟶₁q) 1-step cb@(CBpresent cbp cbq) (rcontext (cq ∷ cqs) (dcpresent₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcpresent₂ dcr) psn⟶₁r) with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBloop cb' _) (rcontext (cq ∷ cqs) (dcloop dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcloop dcr) psn⟶₁r) with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBshared cb') (rcontext (cq ∷ cqs) (dcshared dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcshared dcr) psn⟶₁r) with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBvar cb') (rcontext (cq ∷ cqs) (dcvar dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcvar dcr) psn⟶₁r) with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBif cbp cbq) (rcontext (cq ∷ cqs) (dcif₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcif₁ dcr) psn⟶₁r) with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb (rcontext (cq ∷ cqs) (dcif₁ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcif₂ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcif₂ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcif₁ dcq) psn⟶₁q) 1-step cb (rcontext (cq ∷ cqs) (dcif₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcif₁ dcr) psn⟶₁r) = _ , sn⟶*-inclusion (rcontext _ (dcif₁ dcr) psn⟶₁r) ,′ sn⟶*-inclusion (rcontext _ (dcif₂ dcq) psn⟶₁q) 1-step cb@(CBif cbp cbq) (rcontext (cq ∷ cqs) (dcif₂ dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcif₂ dcr) psn⟶₁r) with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p'' 1-step cb@(CBρ cb') (rcontext (cq ∷ cqs) (dcenv dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcenv dcr) psn⟶₁r) with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r) ... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
41.694915
97
0.591734
57c8f0736bd1ffef1c5f9b7c6f9165a049135109
123
agda
Agda
test/interaction/Issue936.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue936.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue936.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue936 where -- The highlighting generated for this file should not contain -- any references to Agda.Primitive.
24.6
62
0.796748
29a4abb97421bf9ff8858d77c759234305c82bb9
24
agda
Agda
test/Fail/InvalidNamePartMeta.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/InvalidNamePartMeta.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/InvalidNamePartMeta.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
test = forall _?_ → Set
12
23
0.625
31b6ff17f24aa79316ba5528b3bbc4eee0a3408a
2,866
agda
Agda
Lists.agda
NAMEhzj/Divide-and-Conquer-in-Agda
99bd3a5e772563153d78f61c1bbca48d7809ff48
[ "MIT" ]
null
null
null
Lists.agda
NAMEhzj/Divide-and-Conquer-in-Agda
99bd3a5e772563153d78f61c1bbca48d7809ff48
[ "MIT" ]
null
null
null
Lists.agda
NAMEhzj/Divide-and-Conquer-in-Agda
99bd3a5e772563153d78f61c1bbca48d7809ff48
[ "MIT" ]
null
null
null
{-# OPTIONS --no-universe-polymorphism #-} open import Induction.WellFounded as WF open import Induction.Nat open import Relation.Binary.Core hiding (Total) open import Relation.Unary as U using (Decidable) open import Relation.Nullary open import Function using (_on_) open import Data.Nat import Level as L using (zero) open import Data.List open import BagEquality module Lists where infixr 8 _<l_ _<l_ : {A : Set} → Rel (List A) L.zero _<l_ = Data.Nat._<′_ on length <l-wellFounded : {A : Set} → Well-founded (_<l_ {A = A}) <l-wellFounded = newWf where module InverseOfProj = WF.Inverse-image length newWf = InverseOfProj.well-founded <′-well-founded data Ordered : {A : Set} → Rel A _ → List A → Set where NilIsOrd : {A : Set} {LEQ : Rel A _} → Ordered LEQ [] SingleIsOrd : {A : Set} {LEQ : Rel A _} {x : A} → Ordered LEQ [ x ] HeadTailOrd : {A : Set} {LEQ : Rel A _} {x y : A} {zs : List A} → LEQ x y → Ordered LEQ (y ∷ zs) → Ordered LEQ (x ∷ (y ∷ zs)) cons-Order-cong : {A : Set} → {LEQ : Rel A L.zero} → {x : A} → {ys : List A} → (∀ z → z ∈ ys → LEQ x z) → Ordered LEQ ys → Ordered LEQ (x ∷ ys) cons-Order-cong {A} {LEQ} {y} {[]} _ _ = SingleIsOrd cons-Order-cong {A} {LEQ} {x} {y ∷ ys} xLEQ ord-ys = HeadTailOrd (xLEQ y (inj₁ refl)) ord-ys ++-Order-cong : {A : Set} {LEQ : Rel A L.zero} → {xs ys : List A} {y : A} → (∀ z → z ∈ xs → LEQ z y) → Ordered LEQ xs → Ordered LEQ (y ∷ ys) → Ordered LEQ (xs ++ (y ∷ ys)) ++-Order-cong {A} {LEQ} {[]} {ys} {y} _ _ ord-y∷ys = ord-y∷ys ++-Order-cong {A} {LEQ} {x ∷ []} {ys} {y} yGEQ _ ord-y∷ys = HeadTailOrd (yGEQ x (inj₁ refl)) ord-y∷ys ++-Order-cong {A} {LEQ} {x₁ ∷ (x₂ ∷ xs)} {ys} {y} yGEQ (HeadTailOrd x₁LEQx₂ ord-x∷xs) ord-y∷ys = HeadTailOrd x₁LEQx₂ (++-Order-cong (λ z zIn → yGEQ z (inj₂ zIn)) ord-x∷xs ord-y∷ys) Total : {A : Set} → Rel A L.zero → Set Total {A} LEQ = (x y : A) → LEQ x y ⊕ LEQ y x data ListPrimitive : {A : Set} → List A → Set where NilIsPrim : ∀{A} → ListPrimitive {A = A} [] consIsNotPrim : {A : Set} → {x : A} → {xs : List A} → ¬ ListPrimitive (x ∷ xs) consIsNotPrim () primDec : {A : Set} → U.Decidable (ListPrimitive {A = A}) primDec [] = yes NilIsPrim primDec (x ∷ xs) = no consIsNotPrim data ListPrimitive2 : {A : Set} → List A → Set where NilIsPrim2 : ∀{A} → ListPrimitive2 {A = A} [] SingleIsPrim2 : ∀{A} {x : A} → ListPrimitive2 (x ∷ []) consConsIsNotPrim2 : {A : Set} → {x y : A} → {zs : List A} → ¬ ListPrimitive2 (x ∷ (y ∷ zs)) consConsIsNotPrim2 () prim2Dec : {A : Set} → U.Decidable (ListPrimitive2 {A = A}) prim2Dec [] = yes NilIsPrim2 prim2Dec (x ∷ []) = yes SingleIsPrim2 prim2Dec (x ∷ (y ∷ zs)) = no consConsIsNotPrim2
40.366197
180
0.564899
a1c53762ffdc7799e1e087ac60dd2cd867de48ff
1,769
agda
Agda
Cubical/Categories/Functor.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
Cubical/Categories/Functor.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
Cubical/Categories/Functor.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Categories.Functor where open import Cubical.Foundations.Prelude open import Cubical.Data.Sigma open import Cubical.Categories.Category private variable ℓC ℓC' ℓD ℓD' : Level record Functor (C : Precategory ℓC ℓC') (D : Precategory ℓD ℓD') : Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where no-eta-equality open Precategory field F-ob : C .ob → D .ob F-hom : {x y : C .ob} → C [ x , y ] → D [(F-ob x) , (F-ob y)] F-id : {x : C .ob} → F-hom (C .id x) ≡ D .id (F-ob x) F-seq : {x y z : C .ob} (f : C [ x , y ]) (g : C [ y , z ]) → F-hom (f ⋆⟨ C ⟩ g) ≡ (F-hom f) ⋆⟨ D ⟩ (F-hom g) isFull = (x y : _) (F[f] : D [(F-ob x) , (F-ob y)]) → ∃ (C [ x , y ]) (λ f → F-hom f ≡ F[f]) isFaithful = (x y : _) (f g : C [ x , y ]) → F-hom f ≡ F-hom g → f ≡ g -- Functor results module _ (C : Precategory ℓC ℓC') (D : Precategory ℓC ℓC') (F : Functor C D ) where open Precategory open Functor F open CatIso -- functors preserve isomorphisms preserveIsosF : ∀ {x y : C .ob} → CatIso {C = C} x y → CatIso {C = D} (F-ob x) (F-ob y) preserveIsosF {x} {y} (catiso f f⁻¹ sec' ret') = catiso g g⁻¹ -- sec ( (g⁻¹ ⋆⟨ D ⟩ g) ≡⟨ sym (F-seq f⁻¹ f) ⟩ F-hom (f⁻¹ ⋆⟨ C ⟩ f) ≡⟨ cong F-hom sec' ⟩ F-hom (C .id y) ≡⟨ F-id ⟩ D .id y' ∎ ) -- ret ( (g ⋆⟨ D ⟩ g⁻¹) ≡⟨ sym (F-seq f f⁻¹) ⟩ F-hom (f ⋆⟨ C ⟩ f⁻¹) ≡⟨ cong F-hom ret' ⟩ F-hom (C .id x) ≡⟨ F-id ⟩ D .id x' ∎ ) where x' : D .ob x' = F-ob x y' : D .ob y' = F-ob y g : D [ x' , y' ] g = F-hom f g⁻¹ : D [ y' , x' ] g⁻¹ = F-hom f⁻¹
25.637681
115
0.458451
57107e0b353ff3c3c6fbb6cb999b59565bef3198
16,280
agda
Agda
Categories/Adjoint/Properties.agda
Taneb/agda-categories
6ebc1349ee79669c5c496dcadd551d5bbefd1972
[ "MIT" ]
null
null
null
Categories/Adjoint/Properties.agda
Taneb/agda-categories
6ebc1349ee79669c5c496dcadd551d5bbefd1972
[ "MIT" ]
null
null
null
Categories/Adjoint/Properties.agda
Taneb/agda-categories
6ebc1349ee79669c5c496dcadd551d5bbefd1972
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Categories.Adjoint.Properties where open import Level open import Data.Product using (Σ; _,_; -,_; proj₂; uncurry) open import Function using (_$_) open import Categories.Adjoint using (_⊣_; Adjoint; Hom-NI′⇒Adjoint) open import Categories.Adjoint.RAPL public open import Categories.Category using (Category; _[_,_]) open import Categories.Category.Product using (_⁂_; _⁂ⁿⁱ_) open import Categories.Category.Construction.Comma using (CommaObj; Comma⇒; _↙_) open import Categories.Functor renaming (id to idF) open import Categories.Functor.Hom open import Categories.Functor.Construction.Constant open import Categories.Functor.Construction.LiftSetoids open import Categories.Functor.Properties open import Categories.Functor.Continuous open import Categories.Functor.Cocontinuous open import Categories.Functor.Bifunctor open import Categories.Functor.Bifunctor.Properties open import Categories.NaturalTransformation open import Categories.NaturalTransformation.Properties open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; _≃_; _ⓘₕ_; _ⓘˡ_; module ≃) open import Categories.NaturalTransformation.NaturalIsomorphism.Properties open import Categories.Monad open import Categories.Monad.Duality open import Categories.Comonad open import Categories.Morphism.Universal open import Categories.Yoneda import Categories.Yoneda.Properties as YP import Categories.Diagram.Colimit as Col import Categories.Diagram.Duality as Duality import Categories.Morphism as Mor import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D E J : Category o ℓ e -- if the left adjoint functor is a partial application of bifunctor, then it uniquely -- determines a bifunctor compatible with the right adjoint functor. module _ {C : Category o ℓ e} (L : Bifunctor C E D) {R : ∀ (X : Category.Obj E) → Functor D C} (LR : ∀ (X : Category.Obj E) → appʳ L X ⊣ R X) where private module C = Category C module D = Category D module E = Category E module L = Functor L module R X = Functor (R X) module LR X = Adjoint (LR X) open C F′ : ∀ {A X B Y} f g → R.F₀ A X ⇒ R.F₀ B Y F′ {A} {X} {B} {Y} f g = LR.Ladjunct B (LR.counit.η A Y D.∘ L.F₁ (R.F₁ A g , f)) -- R.F₁ B (LR.counit.η A Y) ∘ R.F₁ B (L.F₁ (R.F₁ A g , f)) ∘ LR.unit.η B (R.F₀ A X) commute′ : ∀ {A B X} (f : A E.⇒ B) → LR.counit.η A X D.∘ L.F₁ (F′ f D.id , E.id) D.≈ LR.counit.η B X D.∘ L.F₁ (C.id , f) commute′ {A} {B} {X} f = begin LR.counit.η A X D.∘ L.F₁ (F′ f D.id , E.id) ≈⟨ LR.RLadjunct≈id A ⟩ LR.counit.η B X D.∘ L.F₁ (R.F₁ B D.id , f) ≈⟨ refl ⟩∘⟨ L.F-resp-≈ (R.identity B , E.Equiv.refl) ⟩ LR.counit.η B X D.∘ L.F₁ (C.id , f) ∎ where open D.HomReasoning open HomReasoning decompose₁ : ∀ {A B X Y} {f : A E.⇒ B} {g : X D.⇒ Y} → F′ f g ≈ R.F₁ A g ∘ F′ f D.id decompose₁ {A} {B} {X} {Y} {f} {g} = begin F′ f g ≈⟨ R.F-resp-≈ A (D.∘-resp-≈ʳ [ L ]-decompose₁) ⟩∘⟨refl ⟩ R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (R.F₁ B g , E.id) D.∘ L.F₁ (C.id , f)) ∘ LR.unit.η A (R.F₀ B X) ≈⟨ R.F-resp-≈ A (pullˡ (LR.counit.commute B g)) ⟩∘⟨refl ⟩ R.F₁ A ((g D.∘ LR.counit.η B X) D.∘ L.F₁ (C.id , f)) ∘ LR.unit.η A (R.F₀ B X) ≈˘⟨ R.F-resp-≈ A (pushʳ (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity B , E.Equiv.refl)))) ⟩∘⟨refl ⟩ R.F₁ A (g D.∘ LR.counit.η B X D.∘ L.F₁ (R.F₁ B D.id , f)) ∘ LR.unit.η A (R.F₀ B X) ≈⟨ R.homomorphism A ⟩∘⟨refl ⟩ (R.F₁ A g ∘ R.F₁ A (LR.counit.η B X D.∘ L.F₁ (R.F₁ B D.id , f))) ∘ LR.unit.η A (R.F₀ B X) ≈⟨ assoc ⟩ R.F₁ A g ∘ F′ f D.id ∎ where open MR D decompose₂ : ∀ {A B X Y} {f : A E.⇒ B} {g : X D.⇒ Y} → F′ f g ≈ F′ f D.id ∘ R.F₁ B g decompose₂ {A} {B} {X} {Y} {f} {g} = begin F′ f g ≈⟨ R.F-resp-≈ A (D.∘-resp-≈ʳ [ L ]-decompose₂) ⟩∘⟨refl ⟩ R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (C.id , f) D.∘ L.F₁ (R.F₁ B g , E.id)) ∘ LR.unit.η A (R.F₀ B X) ≈˘⟨ R.F-resp-≈ A (pushˡ (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity B , E.Equiv.refl)))) ⟩∘⟨refl ⟩ R.F₁ A ((LR.counit.η B Y D.∘ L.F₁ (R.F₁ B D.id , f)) D.∘ L.F₁ (R.F₁ B g , E.id)) ∘ LR.unit.η A (R.F₀ B X) ≈⟨ R.homomorphism A ⟩∘⟨refl ⟩ (R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (R.F₁ B D.id , f)) ∘ R.F₁ A (L.F₁ (R.F₁ B g , E.id))) ∘ LR.unit.η A (R.F₀ B X) ≈˘⟨ MR.pushʳ C (LR.unit.commute A (R.F₁ B g)) ⟩ R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (R.F₁ B D.id , f)) ∘ LR.unit.η A (R.F₀ B Y) ∘ R.F₁ B g ≈˘⟨ assoc ⟩ F′ f D.id ∘ R.F₁ B g ∎ where open MR D swap : ∀ {A B X Y} {f : A E.⇒ B} {g : X D.⇒ Y} → R.F₁ A g ∘ F′ f D.id ≈ F′ f D.id ∘ R.F₁ B g swap = trans (⟺ decompose₁) decompose₂ commute″ : ∀ {X Y Z A} {f : Y E.⇒ Z} {g : X E.⇒ Y} → F′ (f E.∘ g) (D.id {A}) ≈ F′ g D.id ∘ F′ f D.id commute″ {X} {Y} {Z} {A} {f} {g} = begin F′ (f E.∘ g) D.id ≈⟨ R.F-resp-≈ X (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity Z , E.Equiv.refl))) ⟩∘⟨refl ⟩ R.F₁ X (LR.counit.η Z A D.∘ L.F₁ (C.id , f E.∘ g)) ∘ LR.unit.η X (R.F₀ Z A) ≈⟨ R.F-resp-≈ X (D.∘-resp-≈ʳ (Functor.homomorphism (appˡ L (R.F₀ Z A)))) ⟩∘⟨refl ⟩ R.F₁ X (LR.counit.η Z A D.∘ L.F₁ (C.id , f) D.∘ L.F₁ (C.id , g)) ∘ LR.unit.η X (R.F₀ Z A) ≈˘⟨ R.F-resp-≈ X (MR.pushˡ D (commute′ f)) ⟩∘⟨refl ⟩ R.F₁ X ((LR.counit.η Y A D.∘ L.F₁ (F′ f D.id , E.id)) D.∘ L.F₁ (C.id , g)) ∘ LR.unit.η X (R.F₀ Z A) ≈˘⟨ R.F-resp-≈ X (MR.pushʳ D [ L ]-commute) ⟩∘⟨refl ⟩ R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (C.id , g) D.∘ L.F₁ (F′ f D.id , E.id)) ∘ LR.unit.η X (R.F₀ Z A) ≈˘⟨ R.F-resp-≈ X D.assoc ⟩∘⟨refl ⟩ R.F₁ X ((LR.counit.η Y A D.∘ L.F₁ (C.id , g)) D.∘ L.F₁ (F′ f D.id , E.id)) ∘ LR.unit.η X (R.F₀ Z A) ≈⟨ R.homomorphism X ⟩∘⟨refl ⟩ (R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (C.id , g)) ∘ R.F₁ X (L.F₁ (F′ f D.id , E.id))) ∘ LR.unit.η X (R.F₀ Z A) ≈˘⟨ MR.pushʳ C (LR.unit.commute X (F′ f D.id)) ⟩ R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (C.id , g)) ∘ LR.unit.η X (R.F₀ Y A) ∘ F′ f D.id ≈˘⟨ R.F-resp-≈ X (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity Y , E.Equiv.refl))) ⟩∘⟨ refl ⟩∘⟨ refl ⟩ R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (R.F₁ Y D.id , g)) ∘ LR.unit.η X (R.F₀ Y A) ∘ F′ f D.id ≈˘⟨ assoc ⟩ F′ g D.id ∘ F′ f D.id ∎ induced-bifunctorʳ : Bifunctor E.op D C induced-bifunctorʳ = record { F₀ = uncurry R.F₀ ; F₁ = uncurry F′ ; identity = λ where {e , d} → let open MR D in begin F′ E.id D.id ≈⟨ R.F-resp-≈ e (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity e , E.Equiv.refl))) ⟩∘⟨ refl ⟩ R.F₁ e (LR.counit.η e d D.∘ L.F₁ (C.id , E.id)) ∘ LR.unit.η e (R.F₀ e d) ≈⟨ R.F-resp-≈ e (elimʳ L.identity) ⟩∘⟨ refl ⟩ R.F₁ e (LR.counit.η e d) ∘ LR.unit.η e (R.F₀ e d) ≈⟨ LR.zag e ⟩ C.id ∎ ; homomorphism = λ where {A , X} {B , Y} {W , Z} {f , h} {g , i} → let open MR C in begin F′ (f E.∘ g) (i D.∘ h) ≈⟨ decompose₁ ⟩ R.F₁ W (i D.∘ h) ∘ F′ (f E.∘ g) D.id ≈˘⟨ center⁻¹ (⟺ (R.homomorphism W)) (⟺ commute″) ⟩ R.F₁ W i ∘ (R.F₁ W h ∘ F′ g D.id) ∘ F′ f D.id ≈˘⟨ center (⟺ swap) ⟩ (R.F₁ W i ∘ F′ g D.id) ∘ R.F₁ B h ∘ F′ f D.id ≈˘⟨ decompose₁ ⟩∘⟨ decompose₁ ⟩ F′ g i ∘ F′ f h ∎ ; F-resp-≈ = λ where {A , X} {B , Y} (eq , eq′) → ∘-resp-≈ˡ (R.F-resp-≈ B (D.∘-resp-≈ʳ (L.F-resp-≈ (R.F-resp-≈ A eq′ , eq)))) } -- LAPC: left adjoint preserves colimits. module _ {L : Functor C D} {R : Functor D C} (L⊣R : L ⊣ R) (F : Functor J C) where private module F = Functor F open Col lapc : Colimit F → Colimit (L ∘F F) lapc col = Duality.coLimit⇒Colimit D (rapl (Adjoint.op L⊣R) F.op (Duality.Colimit⇒coLimit C col)) -- adjoint functors induce monads and comonads module _ {L : Functor C D} {R : Functor D C} (L⊣R : L ⊣ R) where private module C = Category C module D = Category D module L = Functor L module R = Functor R open Adjoint L⊣R rapl′ : ∀ {o ℓ e} → Continuous o ℓ e R rapl′ lim = rapl L⊣R _ lim , Mor.≅.refl C lapc′ : ∀ {o ℓ e} → Cocontinuous o ℓ e L lapc′ col = lapc L⊣R _ col , Mor.≅.refl D adjoint⇒monad : Monad C adjoint⇒monad = record { F = R ∘F L ; η = unit ; μ = record { η = μ′.η ; commute = μ′.commute ; sym-commute = μ′.sym-commute } ; assoc = [ R ]-resp-square (counit.commute _) ; sym-assoc = [ R ]-resp-square (counit.sym-commute _) ; identityˡ = λ {X} → begin μ′.η X ∘ R.F₁ (L.F₁ (unit.η X)) ≈⟨ [ R ]-resp-∘ zig ⟩ R.F₁ D.id ≈⟨ R.identity ⟩ C.id ∎ ; identityʳ = zag } where open C open HomReasoning μ′ : NaturalTransformation (R ∘F (L ∘F R) ∘F L) (R ∘F Categories.Functor.id ∘F L) μ′ = R ∘ˡ counit ∘ʳ L module μ′ = NaturalTransformation μ′ module _ {L : Functor C D} {R : Functor D C} (L⊣R : L ⊣ R) where open Adjoint L⊣R adjoint⇒comonad : Comonad D adjoint⇒comonad = coMonad⇒Comonad D (adjoint⇒monad op) -- adjoint functors are the same as universal morphisms module _ {R : Functor D C} where private module C = Category C module D = Category D module R = Functor R adjoint⇒universalMorphisms : ∀ {L : Functor C D} → L ⊣ R → ∀ (X : C.Obj) → UniversalMorphism X R adjoint⇒universalMorphisms {L} L⊣R X = record { initial = record { ⊥ = record { f = unit.η X } ; ! = let open C.HomReasoning in record { commute = LRadjunct≈id ○ ⟺ C.identityʳ } ; !-unique = λ {A} g → let open D.HomReasoning in -, (begin Radjunct (f A) ≈⟨ Radjunct-resp-≈ (C.Equiv.sym (C.Equiv.trans (commute g) (C.identityʳ {f = f A}))) ⟩ Radjunct (Ladjunct (h g)) ≈⟨ RLadjunct≈id ⟩ h g ∎) } } where module L = Functor L open Adjoint L⊣R open Comma⇒ open CommaObj universalMophisms⇒adjoint : (∀ (X : C.Obj) → UniversalMorphism X R) → Σ (Functor C D) (λ L → L ⊣ R) universalMophisms⇒adjoint umors = L , record { unit = ntHelper record { η = λ c → f (umors.⊥ c) ; commute = λ i → let open C.HomReasoning in ⟺ (commute (⊥X⇒⊥Y i) ○ C.identityʳ ) } ; counit = ntHelper record { η = ε ; commute = λ {X Y} i → let open C.HomReasoning open MR C in proj₂ $ umors.!-unique₂ (R.F₀ X) {record { f = R.F₁ i }} (record { h = ε Y D.∘ L₁ (R.F₁ i) ; commute = begin R.F₁ (ε Y D.∘ L₁ (R.F₁ i)) C.∘ f (⊥Rd X) ≈⟨ R.homomorphism ⟩∘⟨refl ⟩ (R.F₁ (ε Y) C.∘ R.F₁ (L₁ (R.F₁ i))) C.∘ f (⊥Rd X) ≈⟨ pullʳ (commute (⊥X⇒⊥Y (R.F₁ i)) ○ C.identityʳ) ⟩ R.F₁ (ε Y) C.∘ f (⊥Rd Y) C.∘ R.F₁ i ≈⟨ cancelˡ (commute (⊥Rd⇒id Y) ○ C.identityˡ) ⟩ R.F₁ i ≈˘⟨ C.identityʳ ⟩ R.F₁ i C.∘ C.id ∎ }) (record { h = i D.∘ ε X ; commute = begin R.F₁ (i D.∘ ε X) C.∘ f (⊥Rd X) ≈⟨ R.homomorphism ⟩∘⟨refl ⟩ (R.F₁ i C.∘ R.F₁ (ε X)) C.∘ f (⊥Rd X) ≈⟨ cancelʳ (commute (⊥Rd⇒id X) ○ C.identityˡ) ⟩ R.F₁ i ≈˘⟨ C.identityʳ ⟩ R.F₁ i C.∘ C.id ∎ }) } ; zig = λ {c} → let open C.HomReasoning open MR C α = f (umors.⊥ c) in proj₂ $ umors.!-unique₂ c {record { f = α }} (record { h = ε (L₀ c) D.∘ L₁ α ; commute = begin R.F₁ (ε (L₀ c) D.∘ L₁ α) C.∘ α ≈⟨ R.homomorphism ⟩∘⟨refl ⟩ (R.F₁ (ε (L₀ c)) C.∘ R.F₁ (L₁ α)) C.∘ α ≈⟨ pullʳ (commute (⊥X⇒⊥Y α) ○ C.identityʳ) ⟩ R.F₁ (ε (L₀ c)) C.∘ f (⊥Rd (L₀ c)) C.∘ α ≈⟨ cancelˡ (commute (⊥Rd⇒id (L₀ c)) ○ C.identityˡ) ⟩ α ≈˘⟨ C.identityʳ ⟩ α C.∘ C.id ∎ }) (record { h = D.id ; commute = C.∘-resp-≈ˡ R.identity ○ id-comm-sym }) ; zag = λ {d} → C.Equiv.trans (commute (⊥Rd⇒id d)) C.identityˡ } where module umors X = UniversalMorphism (umors X) open CommaObj open Comma⇒ commaObj∘g : ∀ {X Y} → X C.⇒ Y → CommaObj (const! X) R commaObj∘g {X} {Y} g = record { f = f (umors.⊥ Y) C.∘ g } ⊥X⇒⊥Y : ∀ {X Y} (g : X C.⇒ Y) → (X ↙ R) [ umors.⊥ X , commaObj∘g g ] ⊥X⇒⊥Y {X} {Y} g = umors.! X {commaObj∘g g} L₀ : ∀ X → D.Obj L₀ X = β (umors.⊥ X) L₁ : ∀ {X Y} → X C.⇒ Y → β (umors.⊥ X) D.⇒ β (umors.⊥ Y) L₁ {X} {Y} g = h (⊥X⇒⊥Y g) L : Functor C D L = record { F₀ = L₀ ; F₁ = L₁ ; identity = λ {X} → proj₂ $ umors.!-unique X $ record { commute = elimˡ R.identity ○ ⟺ C.identityʳ ○ ⟺ C.identityʳ } ; homomorphism = λ {X Y Z} {i j} → proj₂ $ umors.!-unique₂ X (umors.! X) $ record { commute = begin R.F₁ (h (umors.! Y) D.∘ h (umors.! X)) C.∘ f (umors.⊥ X) ≈⟨ (C.∘-resp-≈ˡ R.homomorphism) ○ C.assoc ⟩ R.F₁ (h (umors.! Y)) C.∘ R.F₁ (h (umors.! X)) C.∘ f (umors.⊥ X) ≈⟨ (C.∘-resp-≈ʳ (commute (⊥X⇒⊥Y i) ○ C.identityʳ)) ○ C.sym-assoc ⟩ (R.F₁ (h (umors.! Y)) C.∘ f (umors.⊥ Y)) C.∘ i ≈⟨ pushˡ (commute (⊥X⇒⊥Y j) ○ C.identityʳ) ⟩ f (umors.⊥ Z) C.∘ j C.∘ i ≈˘⟨ C.identityʳ ⟩ (f (umors.⊥ Z) C.∘ j C.∘ i) C.∘ C.id ∎ } ; F-resp-≈ = λ {X} eq → proj₂ $ umors.!-unique₂ X (umors.! X) $ record { commute = commute (umors.! X) ○ C.∘-resp-≈ˡ (C.∘-resp-≈ʳ (⟺ eq)) } } where open C.HomReasoning open MR C module L = Functor L ⊥Rd : (d : D.Obj) → CommaObj (const! (R.F₀ d)) R ⊥Rd d = umors.⊥ (R.F₀ d) ⊥Rd⇒id : (d : D.Obj) → (R.F₀ d ↙ R) [ ⊥Rd d , record { f = C.id } ] ⊥Rd⇒id d = umors.! (R.F₀ d) {record { f = C.id }} ε : ∀ d → L₀ (R.F₀ d) D.⇒ d ε d = h (⊥Rd⇒id d) -- adjoint functors of a functor are isomorphic module _ (L : Functor C D) where open YP C R≃R′ : ∀ {R R′} → L ⊣ R → L ⊣ R′ → R ≃ R′ R≃R′ {R} {R′} L⊣R L⊣R′ = yoneda-NI R R′ (unlift-≃ Hom[-,R-]≃Hom[-,R′-]) where module ⊣₁ = Adjoint L⊣R module ⊣₂ = Adjoint L⊣R′ Hom[-,R-]≃Hom[-,R′-] : ⊣₁.Hom[-,R-]′ ≃ ⊣₂.Hom[-,R-]′ Hom[-,R-]≃Hom[-,R′-] = ≃.trans (≃.sym ⊣₁.Hom-NI) ⊣₂.Hom-NI module _ {R : Functor D C} where L≃L′ : ∀ {L L′} → L ⊣ R → L′ ⊣ R → L ≃ L′ L≃L′ L⊣R L′⊣R = NaturalIsomorphism.op L′≃Lᵒᵖ where module ⊣₁ = Adjoint L⊣R module ⊣₂ = Adjoint L′⊣R L′≃Lᵒᵖ = R≃R′ (Functor.op R) ⊣₂.op ⊣₁.op -- adjoint functors are preserved by natural isomorphisms module _ {L L′ : Functor C D} {R R′ : Functor D C} where private module C = Category C module D = Category D module L = Functor L module L′ = Functor L′ module R = Functor R module R′ = Functor R′ ⊣×≃⇒⊣ : L ⊣ R → L ≃ L′ → R ≃ R′ → L′ ⊣ R′ ⊣×≃⇒⊣ L⊣R L≃L′ R≃R′ = Hom-NI′⇒Adjoint (≃.trans (LiftSetoids _ _ ⓘˡ Hom[L′-,-]≃Hom[L-,-]) (≃.trans Hom-NI (LiftSetoids _ _ ⓘˡ Hom[-,R-]≃Hom[-,R′-]))) where open Adjoint L⊣R Hom[L′-,-]≃Hom[L-,-] : Hom[ D ][-,-] ∘F (L′.op ⁂ idF) ≃ Hom[ D ][-,-] ∘F (L.op ⁂ idF) Hom[L′-,-]≃Hom[L-,-] = Hom[ D ][-,-] ⓘˡ (NaturalIsomorphism.op L≃L′ ⁂ⁿⁱ ≃.refl) Hom[-,R-]≃Hom[-,R′-] : Hom[ C ][-,-] ∘F (idF ⁂ R) ≃ Hom[ C ][-,-] ∘F (idF ⁂ R′) Hom[-,R-]≃Hom[-,R′-] = Hom[ C ][-,-] ⓘˡ (≃.refl ⁂ⁿⁱ R≃R′)
42.729659
124
0.480098
d0fa9c0d6a0fe41889b9ace1dba45baaa745a396
762
agda
Agda
lib/types/Unit.agda
sattlerc/HoTT-Agda
c8fb8da3354fc9e0c430ac14160161759b4c5b37
[ "MIT" ]
null
null
null
lib/types/Unit.agda
sattlerc/HoTT-Agda
c8fb8da3354fc9e0c430ac14160161759b4c5b37
[ "MIT" ]
null
null
null
lib/types/Unit.agda
sattlerc/HoTT-Agda
c8fb8da3354fc9e0c430ac14160161759b4c5b37
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics module lib.types.Unit where ⊤ = Unit tt = unit abstract -- Unit is contractible Unit-is-contr : is-contr Unit Unit-is-contr = (unit , λ y → idp) Unit-has-level : {n : ℕ₋₂} → has-level n Unit Unit-has-level = contr-has-level Unit-is-contr -- [Unit-has-level#instance] produces unsolved metas Unit-has-level-S#instance : {n : ℕ₋₂} → has-level (S n) Unit Unit-has-level-S#instance = contr-has-level Unit-is-contr Unit-is-prop : is-prop Unit Unit-is-prop = Unit-has-level Unit-is-set : is-set Unit Unit-is-set = Unit-has-level Unit-level = Unit-is-contr ⊤-is-contr = Unit-is-contr ⊤-level = Unit-is-contr ⊤-has-level = Unit-has-level ⊤-is-prop = Unit-is-prop ⊤-is-set = Unit-is-set
22.411765
62
0.666667
3d6f4cf44e208c2635dda6c4ebfca12fc3e9a122
2,695
agda
Agda
container/core.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
27
2015-04-14T15:47:03.000Z
2022-01-09T07:26:57.000Z
container/core.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
2
2015-02-11T11:14:59.000Z
2015-02-11T15:20:34.000Z
container/core.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
4
2015-04-11T17:19:12.000Z
2019-02-26T06:17:38.000Z
{-# OPTIONS --without-K #-} module container.core where open import level open import sum open import equality open import function module _ {li}{I : Set li} where -- homsets in the slice category _→ⁱ_ : ∀ {lx ly} → (I → Set lx) → (I → Set ly) → Set _ X →ⁱ Y = (i : I) → X i → Y i -- identity of the slice category idⁱ : ∀ {lx}{X : I → Set lx} → X →ⁱ X idⁱ i x = x -- composition in the slice category _∘ⁱ_ : ∀ {lx ly lz} {X : I → Set lx}{Y : I → Set ly}{Z : I → Set lz} → (Y →ⁱ Z) → (X →ⁱ Y) → (X →ⁱ Z) (f ∘ⁱ g) i = f i ∘ g i infixl 9 _∘ⁱ_ -- extensionality funext-isoⁱ : ∀ {lx ly} {X : I → Set lx}{Y : (i : I) → X i → Set ly} → {f g : (i : I)(x : X i) → Y i x} → (∀ i x → f i x ≡ g i x) ≅ (f ≡ g) funext-isoⁱ {f = f}{g = g} = (Π-ap-iso refl≅ λ i → strong-funext-iso) ·≅ strong-funext-iso funext-invⁱ : ∀ {lx ly} {X : I → Set lx}{Y : (i : I) → X i → Set ly} → {f g : (i : I)(x : X i) → Y i x} → f ≡ g → ∀ i x → f i x ≡ g i x funext-invⁱ = invert funext-isoⁱ funextⁱ : ∀ {lx ly} {X : I → Set lx}{Y : (i : I) → X i → Set ly} → {f g : (i : I)(x : X i) → Y i x} → (∀ i x → f i x ≡ g i x) → f ≡ g funextⁱ = apply funext-isoⁱ -- Definition 1 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO]) record Container (li la lb : Level) : Set (lsuc (li ⊔ la ⊔ lb)) where constructor container field I : Set li A : I → Set la B : {i : I} → A i → Set lb r : {i : I}{a : A i} → B a → I -- Definition 2 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO]) -- functor associated to this indexed container F : ∀ {lx} → (I → Set lx) → I → Set _ F X i = Σ (A i) λ a → (b : B a) → X (r b) F-ap-iso : ∀ {lx ly}{X : I → Set lx}{Y : I → Set ly} → (∀ i → X i ≅ Y i) → ∀ i → F X i ≅ F Y i F-ap-iso isom i = Σ-ap-iso refl≅ λ a → Π-ap-iso refl≅ λ b → isom (r b) -- morphism map for the functor F imap : ∀ {lx ly} → {X : I → Set lx} → {Y : I → Set ly} → (X →ⁱ Y) → (F X →ⁱ F Y) imap g i (a , f) = a , λ b → g (r b) (f b) -- action of a functor on homotopies hmap : ∀ {lx ly} → {X : I → Set lx} → {Y : I → Set ly} → {f g : X →ⁱ Y} → (∀ i x → f i x ≡ g i x) → (∀ i x → imap f i x ≡ imap g i x) hmap p i (a , u) = ap (_,_ a) (funext (λ b → p (r b) (u b))) hmap-id : ∀ {lx ly} → {X : I → Set lx} → {Y : I → Set ly} → (f : X →ⁱ Y) → ∀ i x → hmap (λ i x → refl {x = f i x}) i x ≡ refl hmap-id f i (a , u) = ap (ap (_,_ a)) (funext-id _)
30.280899
80
0.444156
dc2963ee5f593f7fd7c2a66c205e2fb1f657898d
1,798
agda
Agda
agda-stdlib/src/Codata/Musical/Cofin.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Codata/Musical/Cofin.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Codata/Musical/Cofin.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- "Finite" sets indexed on coinductive "natural" numbers ------------------------------------------------------------------------ {-# OPTIONS --without-K --sized-types --guardedness #-} module Codata.Musical.Cofin where open import Codata.Musical.Notation open import Codata.Musical.Conat as Conat using (Coℕ; suc; ∞ℕ) open import Data.Nat.Base using (ℕ; zero; suc) open import Data.Fin.Base using (Fin; zero; suc) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl) open import Function ------------------------------------------------------------------------ -- The type -- Note that Cofin ∞ℕ is /not/ finite. Note also that this is not a -- coinductive type, but it is indexed on a coinductive type. data Cofin : Coℕ → Set where zero : ∀ {n} → Cofin (suc n) suc : ∀ {n} (i : Cofin (♭ n)) → Cofin (suc n) suc-injective : ∀ {m} {p q : Cofin (♭ m)} → (Cofin (suc m) ∋ suc p) ≡ suc q → p ≡ q suc-injective refl = refl ------------------------------------------------------------------------ -- Some operations fromℕ : ℕ → Cofin ∞ℕ fromℕ zero = zero fromℕ (suc n) = suc (fromℕ n) toℕ : ∀ {n} → Cofin n → ℕ toℕ zero = zero toℕ (suc i) = suc (toℕ i) fromFin : ∀ {n} → Fin n → Cofin (Conat.fromℕ n) fromFin zero = zero fromFin (suc i) = suc (fromFin i) toFin : ∀ n → Cofin (Conat.fromℕ n) → Fin n toFin (suc n) zero = zero toFin (suc n) (suc i) = suc (toFin n i) import Codata.Cofin as C fromMusical : ∀ {n} → Cofin n → C.Cofin (Conat.fromMusical n) fromMusical zero = C.zero fromMusical (suc n) = C.suc (fromMusical n) toMusical : ∀ {n} → C.Cofin n → Cofin (Conat.toMusical n) toMusical C.zero = zero toMusical (C.suc n) = suc (toMusical n)
30.474576
83
0.548387
50d8e107575fd7976a05a85339aa09c9d712bf57
2,556
agda
Agda
Cubical/Codata/M/AsLimit/itree.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Codata/M/AsLimit/itree.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Codata/M/AsLimit/itree.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --guardedness --safe #-} module Cubical.Codata.M.AsLimit.itree where open import Cubical.Data.Unit open import Cubical.Data.Prod open import Cubical.Data.Nat as ℕ using (ℕ ; suc ; _+_ ) open import Cubical.Data.Sum open import Cubical.Data.Empty open import Cubical.Data.Bool open import Cubical.Foundations.Function open import Cubical.Foundations.Prelude open import Cubical.Codata.M.AsLimit.Container open import Cubical.Codata.M.AsLimit.M open import Cubical.Codata.M.AsLimit.Coalg -- Delay monad defined as an M-type delay-S : (R : Type₀) -> Container ℓ-zero delay-S R = (Unit ⊎ R) , λ { (inr _) -> ⊥ ; (inl tt) -> Unit } delay : (R : Type₀) -> Type₀ delay R = M (delay-S R) delay-ret : {R : Type₀} -> R -> delay R delay-ret r = in-fun (inr r , λ ()) delay-tau : {R : Type₀} -> delay R -> delay R delay-tau S = in-fun (inl tt , λ x → S) -- Bottom element raised data ⊥₁ : Type₁ where -- TREES tree-S : (E : Type₀ -> Type₁) (R : Type₀) -> Container (ℓ-suc ℓ-zero) tree-S E R = (R ⊎ (Σ[ A ∈ Type₀ ] (E A))) , (λ { (inl _) -> ⊥₁ ; (inr (A , e)) -> Lift A } ) tree : (E : Type₀ -> Type₁) (R : Type₀) -> Type₁ tree E R = M (tree-S E R) tree-ret : ∀ {E} {R} -> R -> tree E R tree-ret {E} {R} r = in-fun (inl r , λ ()) tree-vis : ∀ {E} {R} -> ∀ {A} -> E A -> (A -> tree E R) -> tree E R tree-vis {A = A} e k = in-fun (inr (A , e) , λ { (lift x) -> k x } ) -- ITrees (and buildup examples) -- https://arxiv.org/pdf/1906.00046.pdf -- Interaction Trees: Representing Recursive and Impure Programs in Coq -- Li-yao Xia, Yannick Zakowski, Paul He, Chung-Kil Hur, Gregory Malecha, Benjamin C. Pierce, Steve Zdancewic itree-S : ∀ (E : Type₀ -> Type₁) (R : Type₀) -> Container (ℓ-suc ℓ-zero) itree-S E R = ((Unit ⊎ R) ⊎ (Σ[ A ∈ Type₀ ] (E A))) , (λ { (inl (inl _)) -> Lift Unit ; (inl (inr _)) -> ⊥₁ ; (inr (A , e)) -> Lift A } ) itree : ∀ (E : Type₀ -> Type₁) (R : Type₀) -> Type₁ itree E R = M (itree-S E R) ret' : ∀ {E} {R} -> R -> P₀ (itree-S E R) (itree E R) ret' {E} {R} r = inl (inr r) , λ () tau' : {E : Type₀ -> Type₁} -> {R : Type₀} -> itree E R -> P₀ (itree-S E R) (itree E R) tau' t = inl (inl tt) , λ x → t vis' : ∀ {E} {R} -> ∀ {A : Type₀} -> E A -> (A -> itree E R) -> P₀ (itree-S E R) (itree E R) vis' {A = A} e k = inr (A , e) , λ { (lift x) -> k x } ret : ∀ {E} {R} -> R -> itree E R ret = in-fun ∘ ret' tau : {E : Type₀ -> Type₁} -> {R : Type₀} -> itree E R -> itree E R tau = in-fun ∘ tau' vis : ∀ {E} {R} -> ∀ {A : Type₀} -> E A -> (A -> itree E R) -> itree E R vis {A = A} e = in-fun ∘ (vis' {A = A} e)
33.631579
137
0.563772
31e236aff4bebbb443625deaab653c5d4c368b23
789
agda
Agda
notes/FOT/FOTC/Data/Nat/AddPartialRightIdentity.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/FOTC/Data/Nat/AddPartialRightIdentity.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/FOTC/Data/Nat/AddPartialRightIdentity.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Reasoning partially about functions ------------------------------------------------------------------------------ {-# OPTIONS --allow-unsolved-metas #-} {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- We cannot reasoning partially about partial functions intended to -- operate in total values. module FOT.FOTC.Data.Nat.AddPartialRightIdentity where open import FOTC.Base open import FOTC.Data.Nat ------------------------------------------------------------------------------ -- How proceed? +-partialRightIdentity : ∀ n → n + zero ≡ n +-partialRightIdentity n = {!!}
32.875
78
0.455006
1224f08ac9fdd65c80e17556af5f7e763570bdc3
452
agda
Agda
src/is-lib/InfSys.agda
boystrange/FairSubtypingAgda
c4b78e70c3caf68d509f4360b9171d9f80ecb825
[ "MIT" ]
4
2021-07-29T14:32:30.000Z
2022-01-24T14:38:47.000Z
src/is-lib/InfSys.agda
boystrange/FairSubtypingAgda
c4b78e70c3caf68d509f4360b9171d9f80ecb825
[ "MIT" ]
null
null
null
src/is-lib/InfSys.agda
boystrange/FairSubtypingAgda
c4b78e70c3caf68d509f4360b9171d9f80ecb825
[ "MIT" ]
null
null
null
-------------------------------------------------------------------------------- -- This is part of Agda Inference Systems {-# OPTIONS --guardedness #-} module is-lib.InfSys {𝓁} where open import is-lib.InfSys.Base {𝓁} public open import is-lib.InfSys.Induction {𝓁} public open import is-lib.InfSys.Coinduction {𝓁} public open import is-lib.InfSys.FlexCoinduction {𝓁} public open MetaRule public open FinMetaRule public open IS public
34.769231
80
0.608407
06c8305dab78e058c1377ddf174cb4e1171a8f35
1,821
agda
Agda
Cubical/HITs/Rationals/SigmaQ/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/HITs/Rationals/SigmaQ/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/HITs/Rationals/SigmaQ/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Rationals.SigmaQ.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.HITs.Ints.QuoInt open import Cubical.Data.Nat as ℕ hiding (_·_) open import Cubical.Data.NatPlusOne open import Cubical.Data.Sigma open import Cubical.Data.Nat.GCD open import Cubical.Data.Nat.Coprime -- ℚ as the set of coprime pairs in ℤ × ℕ₊₁ ℚ : Type₀ ℚ = Σ[ (a , b) ∈ ℤ × ℕ₊₁ ] areCoprime (abs a , ℕ₊₁→ℕ b) isSetℚ : isSet ℚ isSetℚ = isSetΣ (isSet× isSetℤ (subst isSet 1+Path isSetℕ)) (λ _ → isProp→isSet isPropIsGCD) signedPair : Sign → ℕ × ℕ₊₁ → ℤ × ℕ₊₁ signedPair s (a , b) = (signed s a , b) [_] : ℤ × ℕ₊₁ → ℚ [ signed s a , b ] = signedPair s (toCoprime (a , b)) , toCoprimeAreCoprime (a , b) [ posneg i , b ] = (posneg i , 1) , toCoprimeAreCoprime (0 , b) []-cancelʳ : ∀ ((a , b) : ℤ × ℕ₊₁) k → [ a · pos (ℕ₊₁→ℕ k) , b ·₊₁ k ] ≡ [ a , b ] []-cancelʳ (signed s zero , b) k = Σ≡Prop (λ _ → isPropIsGCD) (λ i → signed-zero spos s i , 1) []-cancelʳ (signed s (suc a) , b) k = Σ≡Prop (λ _ → isPropIsGCD) (λ i → signedPair (·S-comm s spos i) (toCoprime-cancelʳ (suc a , b) k i)) []-cancelʳ (posneg i , b) k j = isSet→isSet' isSetℚ ([]-cancelʳ (pos zero , b) k) ([]-cancelʳ (neg zero , b) k) (λ i → [ posneg i · pos (ℕ₊₁→ℕ k) , b ·₊₁ k ]) (λ i → [ posneg i , b ]) i j -- 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 , 1) , oneGCD n } instance fromNegℚ : HasFromNeg ℚ fromNegℚ = record { Constraint = λ _ → Unit ; fromNeg = λ n → (neg n , 1) , oneGCD n }
33.109091
97
0.602965
0b71bbc555dbdbaced03ec091a50334d8a585edf
1,455
agda
Agda
examples/AIM4/bag/Nat.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/AIM4/bag/Nat.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/AIM4/bag/Nat.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Nat where import Prelude import Equiv import Datoid open Prelude open Equiv open Datoid data Nat : Set where zero : Nat suc : Nat -> Nat one : Nat one = suc zero _+_ : Nat -> Nat -> Nat zero + n = n suc m + n = suc (m + n) private eqNat : Nat -> Nat -> Bool eqNat zero zero = True eqNat (suc m) (suc n) = eqNat m n eqNat _ _ = False refl' : (x : Nat) -> T (eqNat x x) refl' zero = unit refl' (suc n) = refl' n sym' : (x y : Nat) -> T (eqNat x y) -> T (eqNat y x) sym' zero zero _ = unit sym' (suc n1) (suc n2) eq = sym' n1 n2 eq sym' (suc _) zero wrong = wrong sym' zero (suc _) wrong = wrong trans' : (x y z : Nat) -> T (eqNat x y) -> T (eqNat y z) -> T (eqNat x z) trans' zero _ zero _ _ = unit trans' (suc n1) (suc n2) (suc n3) eq12 eq23 = trans' n1 n2 n3 eq12 eq23 trans' zero (suc _) _ wrong _ = absurdElim wrong trans' _ zero (suc _) _ wrong = absurdElim wrong trans' (suc _) zero _ wrong _ = absurdElim wrong trans' _ (suc _) zero _ wrong = absurdElim wrong decidableEquiv : DecidableEquiv Nat decidableEquiv = decEquiv (equiv (T' eqNat) refl' sym' trans') (boolFunctionsDecidable eqNat) natDatoid : Datoid natDatoid = datoid Nat decidableEquiv
26.944444
77
0.525086
2323a297c88f440dac644e59c4e2e730789995be
986
agda
Agda
Modules/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Modules/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Modules/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import Groups.Definition open import Groups.Abelian.Definition open import Setoids.Setoids open import Rings.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Modules.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+R_ : A → A → A} {_*_ : A → A → A} (R : Ring S _+R_ _*_) {m n : _} {M : Set m} {T : Setoid {m} {n} M} {_+_ : M → M → M} {G' : Group T _+_} (G : AbelianGroup G') (_·_ : A → M → M) where record Module : Set (a ⊔ b ⊔ m ⊔ n) where field dotWellDefined : {r s : A} {t u : M} → Setoid._∼_ S r s → Setoid._∼_ T t u → Setoid._∼_ T (r · t) (s · u) dotDistributesLeft : {r : A} {x y : M} → Setoid._∼_ T (r · (x + y)) ((r · x) + (r · y)) dotDistributesRight : {r s : A} {x : M} → Setoid._∼_ T ((r +R s) · x) ((r · x) + (s · x)) dotAssociative : {r s : A} {x : M} → Setoid._∼_ T ((r * s) · x) (r · (s · x)) dotIdentity : {x : M} → Setoid._∼_ T ((Ring.1R R) · x) x
51.894737
257
0.53854
577fa5e17342743a2c8ea3007964bb9f217b7c56
9,977
agda
Agda
src/Pts/Reduction/Full.agda
asr/pts-agda
d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43
[ "BSD-3-Clause" ]
21
2016-05-13T12:11:10.000Z
2021-08-31T10:47:57.000Z
src/Pts/Reduction/Full.agda
asr/pts-agda
d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43
[ "BSD-3-Clause" ]
1
2017-08-21T14:48:09.000Z
2017-08-21T16:01:50.000Z
src/Pts/Reduction/Full.agda
asr/pts-agda
d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43
[ "BSD-3-Clause" ]
4
2017-08-20T10:29:44.000Z
2019-08-11T23:28:33.000Z
------------------------------------------------------------------------ -- Full β-reduction in pure type systems (PTS) ------------------------------------------------------------------------ module Pts.Reduction.Full where open import Data.Fin.Substitution open import Data.Fin.Substitution.ExtraLemmas open import Data.Star using (ε; _◅_; map; gmap; _⋆) open import Data.Sum using ([_,_]) open import Data.Product using (_,_; ∃; _×_) open import Function using (_∘_) open import Relation.Binary import Relation.Binary.EquivalenceClosure as EqClos import Relation.Binary.PropositionalEquality as P import Relation.Binary.SymmetricClosure as SymClos open import Relation.Binary.Reduction import Function.Equivalence as Equiv open import Pts.Syntax open import Pts.Reduction.Parallel as Par hiding (reduction; _⋄*_; Π-inj) -- All remaining submodules are parametrized by a given set of sorts. module _ {Sort : Set} where open Syntax Sort open Substitution Sort using (_[_]) ---------------------------------------------------------------------- -- Full β-reduction and equivalence relations infixl 9 _·₁_ _·₂_ infix 5 _→β_ -- One-step β-reduction. data _→β_ {n} : Term n → Term n → Set where cont : ∀ a b c → (ƛ a b) · c →β b [ c ] Π₁ : ∀ {a₁ a₂} → a₁ →β a₂ → ∀ b → Π a₁ b →β Π a₂ b Π₂ : ∀ {b₁ b₂} a → b₁ →β b₂ → Π a b₁ →β Π a b₂ ƛ₁ : ∀ {a₁ a₂} → a₁ →β a₂ → ∀ b → ƛ a₁ b →β ƛ a₂ b ƛ₂ : ∀ {b₁ b₂} a → b₁ →β b₂ → ƛ a b₁ →β ƛ a b₂ _·₁_ : ∀ {a₁ a₂} → a₁ →β a₂ → ∀ b → a₁ · b →β a₂ · b _·₂_ : ∀ {b₁ b₂} a → b₁ →β b₂ → a · b₁ →β a · b₂ reduction : Reduction Term reduction = record { _→1_ = _→β_ } -- Full beta reduction and equivalence. open Reduction reduction public renaming (_→*_ to _→β*_; _↔_ to _≡β_) ---------------------------------------------------------------------- -- Substitutions in full β-reductions/equivalence -- -- The applications _/→β_, _/→β*_ and _/≡β_ below may be considered -- substitution lemmas, i.e. they establish the commutativity of the -- respective reductions/equivalence with substitutions. -- Application of generic substitutions to the -- reductions/equivalence. record BetaSubstApp {T} (l : Lift T Term) : Set where open Lift l open SubstApp Sort l open P hiding ([_]) -- Substitutions commute. field /-sub-↑ : ∀ {m n} a b (σ : Sub T m n) → a [ b ] / σ ≡ (a / σ ↑) [ b / σ ] infixl 8 _/→β_ -- Substitution commutes with one-step β-reduction. _/→β_ : ∀ {m n a b} → a →β b → (σ : Sub T m n) → a / σ →β b / σ cont a b c /→β σ = subst (_→β_ _) (sym (/-sub-↑ b c σ)) (cont (a / σ) (b / σ ↑) (c / σ)) Π₁ a₁→a₂ b /→β σ = Π₁ (a₁→a₂ /→β σ) (b / σ ↑) Π₂ a b₁→b₂ /→β σ = Π₂ (a / σ) (b₁→b₂ /→β σ ↑) ƛ₁ a₁→a₂ b /→β σ = ƛ₁ (a₁→a₂ /→β σ) (b / σ ↑) ƛ₂ a b₁→b₂ /→β σ = ƛ₂ (a / σ) (b₁→b₂ /→β σ ↑) a₁→a₂ ·₁ b /→β σ = (a₁→a₂ /→β σ) ·₁ (b / σ) a ·₂ b₁→b₂ /→β σ = (a / σ) ·₂ (b₁→b₂ /→β σ) redSubstApp : RedSubstApp reduction (record { _/_ = _/_ }) redSubstApp = record { _/→1_ = _/→β_ } open RedSubstApp redSubstApp public hiding (_/→1_) renaming (_/→*_ to _/→β*_; _/↔_ to _/≡β_) -- Term substitutions in reductions/equivalences. module BetaSubstitution where open Substitution Sort using (termSubst; weaken; sub-commutes; varLiftSubLemmas) -- Application of renamings to reductions/equivalences. varSubstApp : BetaSubstApp (TermSubst.varLift termSubst) varSubstApp = record { /-sub-↑ = /-sub-↑ } where open LiftSubLemmas varLiftSubLemmas private module V = BetaSubstApp varSubstApp -- Weakening of one-step β-reductions. weaken-→β : ∀ {n} {a b : Term n} → a →β b → weaken a →β weaken b weaken-→β a→b = a→b V./→β VarSubst.wk -- Weakening of β-reductions. weaken-→β* : ∀ {n} {a b : Term n} → a →β* b → weaken a →β* weaken b weaken-→β* = gmap weaken weaken-→β -- Weakening of β-equivalences. weaken-≡β : ∀ {n} {a b : Term n} → a ≡β b → weaken a ≡β weaken b weaken-≡β = EqClos.gmap weaken weaken-→β -- Application of term substitutions to reductions/equivalences. termSubstApp : BetaSubstApp (TermSubst.termLift termSubst) termSubstApp = record { /-sub-↑ = λ a _ _ → sub-commutes a } open BetaSubstApp termSubstApp public ---------------------------------------------------------------------- -- Simple properties of the β-reductions/equivalence -- Inclusions. →β⇒→β* = →1⇒→* reduction →β*⇒≡β = →*⇒↔ reduction →β⇒≡β = →1⇒↔ reduction -- β-reduction is a preorder. →β*-predorder = →*-predorder reduction -- Preorder reasoning for β-reduction. module →β*-Reasoning = →*-Reasoning reduction -- Terms together with β-equivalence form a setoid. ≡β-setoid = ↔-setoid reduction -- Equational reasoning for β-equivalence. module ≡β-Reasoning = ↔-Reasoning reduction ---------------------------------------------------------------------- -- Relationships between β-reduction and parallel reduction -- One-step β-reduction implies one-step parallel reduction. →β⇒⇛ : ∀ {n} {a b : Term n} → a →β b → a ⇛ b →β⇒⇛ (cont a b c) = cont refl refl →β⇒⇛ (Π₁ a₁→a₂ b) = Π (→β⇒⇛ a₁→a₂) refl →β⇒⇛ (Π₂ a b₁→b₂) = Π refl (→β⇒⇛ b₁→b₂) →β⇒⇛ (ƛ₁ a₁→a₂ b) = ƛ (→β⇒⇛ a₁→a₂) refl →β⇒⇛ (ƛ₂ a b₁→b₂) = ƛ refl (→β⇒⇛ b₁→b₂) →β⇒⇛ (a₁→a₂ ·₁ b) = →β⇒⇛ a₁→a₂ · refl →β⇒⇛ (a ·₂ b₁→b₂) = refl · →β⇒⇛ b₁→b₂ -- β-reduction implies parallel reduction. →β*⇒⇛* : ∀ {n} {a b : Term n} → a →β* b → a ⇛* b →β*⇒⇛* = map →β⇒⇛ -- β-equivalence implies parallel equivalence. ≡β⇒≡p : ∀ {n} {a b : Term n} → a ≡β b → a ≡p b ≡β⇒≡p = EqClos.map →β⇒⇛ open →*-Reasoning reduction -- One-step parallel reduction implies β-reduction. ⇛⇒→β* : ∀ {n} {a b : Term n} → a ⇛ b → a →β* b ⇛⇒→β* refl = ε ⇛⇒→β* (Π {a₁} {a₂} {b₁} {b₂} a₁⇛a₂ b₁⇛b₂) = begin Π a₁ b₁ ⟶⋆⟨ gmap (λ a → Π a _) (λ a₁→a₂ → Π₁ a₁→a₂ _) (⇛⇒→β* a₁⇛a₂) ⟩ Π a₂ b₁ ⟶⋆⟨ gmap (Π _) (Π₂ _) (⇛⇒→β* b₁⇛b₂) ⟩ Π a₂ b₂ ∎ ⇛⇒→β* (ƛ {a₁} {a₂} {b₁} {b₂} a₁⇛a₂ b₁⇛b₂) = begin ƛ a₁ b₁ ⟶⋆⟨ gmap (λ a → ƛ a _) (λ a₁→a₂ → ƛ₁ a₁→a₂ _) (⇛⇒→β* a₁⇛a₂) ⟩ ƛ a₂ b₁ ⟶⋆⟨ gmap (ƛ _) (ƛ₂ _) (⇛⇒→β* b₁⇛b₂) ⟩ ƛ a₂ b₂ ∎ ⇛⇒→β* (_·_ {a₁} {a₂} {b₁} {b₂} a₁⇛a₂ b₁⇛b₂) = begin a₁ · b₁ ⟶⋆⟨ gmap (λ a → a · _) (λ a₁→a₂ → a₁→a₂ ·₁ _) (⇛⇒→β* a₁⇛a₂) ⟩ a₂ · b₁ ⟶⋆⟨ gmap (_·_ _) (_·₂_ _) (⇛⇒→β* b₁⇛b₂) ⟩ a₂ · b₂ ∎ ⇛⇒→β* (cont {a} {b₁} {b₂} {c₁} {c₂} b₁⇛b₂ c₁⇛c₂) = begin (ƛ a b₁) · c₁ ⟶⋆⟨ gmap (λ b → (ƛ _ b) · _) (λ b₁→b₂ → (ƛ₂ _ b₁→b₂) ·₁ _) (⇛⇒→β* b₁⇛b₂) ⟩ (ƛ a b₂) · c₁ ⟶⋆⟨ gmap (_·_ _) (_·₂_ _) (⇛⇒→β* c₁⇛c₂) ⟩ (ƛ a b₂) · c₂ ⟶⟨ cont a b₂ c₂ ⟩ b₂ [ c₂ ] ∎ -- Parallel reduction implies β-reduction. ⇛*⇒→β* : ∀ {n} {a b : Term n} → a ⇛* b → a →β* b ⇛*⇒→β* a⇛*b = (⇛⇒→β* ⋆) a⇛*b -- Parallel equivalence implies β-equivalence. ≡p⇒≡β : ∀ {n} {a b : Term n} → a ≡p b → a ≡β b ≡p⇒≡β a≡b = ([ ⇛⇒≡β , sym ∘ ⇛⇒≡β ] ⋆) a≡b where open Setoid ≡β-setoid using (sym) ⇛⇒≡β : ∀ {n} {a b : Term n} → a ⇛ b → a ≡β b ⇛⇒≡β = →*⇒↔ reduction ∘ ⇛⇒→β* open Equiv using (_⇔_; equivalence) -- Full β-reduction is equivalent to parallel reduction. →β*-⇛*-equivalence : ∀ {n} {a b : Term n} → a →β* b ⇔ a ⇛* b →β*-⇛*-equivalence = equivalence →β*⇒⇛* ⇛*⇒→β* -- β-equivalence is equivalent to parallel equivalence. ≡β-≡p-equivalence : ∀ {n} {a b : Term n} → a ≡β b ⇔ a ≡p b ≡β-≡p-equivalence = equivalence ≡β⇒≡p ≡p⇒≡β -- Shorthand for single-variable substitutions lifted to β-redcution. _[→β_] : ∀ {n} a {b₁ b₂ : Term n} → b₁ →β b₂ → a [ b₁ ] →β* a [ b₂ ] a [→β b₁→b₂ ] = ⇛⇒→β* (a / sub (→β⇒⇛ b₁→b₂)) where open ParSubstitution using (_/_; sub) open P using (_≡_) -- Shapes are preserved by full β-reduction. sort-→β* : ∀ {n s} {a : Term n} → sort s →β* a → sort s ≡ a sort-→β* ε = P.refl sort-→β* (() ◅ _) ƛ-→β* : ∀ {n} {a : Term n} {b c} → ƛ a b →β* c → ∃ λ a′ → ∃ λ b′ → a →β* a′ × b →β* b′ × ƛ a′ b′ ≡ c ƛ-→β* λab→*c = let a′ , b′ , a⇛a′ , b⇛b′ , λa′b′≡c = ƛ-⇛* (→β*⇒⇛* λab→*c) in a′ , b′ , ⇛*⇒→β* a⇛a′ , ⇛*⇒→β* b⇛b′ , λa′b′≡c Π-→β* : ∀ {n} {a : Term n} {b c} → Π a b →β* c → ∃ λ a′ → ∃ λ b′ → a →β* a′ × b →β* b′ × Π a′ b′ ≡ c Π-→β* Πab→*c = let a′ , b′ , a⇛a′ , b⇛b′ , Πa′b′≡c = Π-⇛* (→β*⇒⇛* Πab→*c) in a′ , b′ , ⇛*⇒→β* a⇛a′ , ⇛*⇒→β* b⇛b′ , Πa′b′≡c ---------------------------------------------------------------------- -- Confluence (aka the Church-Rosser property) of full β-reduction -- -- Full β-reduction is confluent, i.e. i.e. for any pair a →β* b₁, -- a →β* b₂ of parallel reductions, there is a term c, such that -- -- →β* -- a ------→ b₂ -- | : -- →β* | : →β* -- ↓ →β* ↓ -- b₁ ·····→ c -- -- commutes. -- Confluence of _→β*_ (aka the Church-Rosser property). _⋄*_ : ∀ {n} {a b₁ b₂ : Term n} → a →β* b₁ → a →β* b₂ → ∃ λ c → b₁ →β* c × b₂ →β* c a→*b₁ ⋄* a→*b₂ = let c , b₁⇛*c , b₂⇛*c = (→β*⇒⇛* a→*b₁) Par.⋄* (→β*⇒⇛* a→*b₂) in c , ⇛*⇒→β* b₁⇛*c , ⇛*⇒→β* b₂⇛*c -- Factorization of β-equivalence into β-reductions. ≡β⇒→β* : ∀ {n} {a b : Term n} → a ≡β b → ∃ λ c → a →β* c × b →β* c ≡β⇒→β* a≡b = let c , a⇛*c , b⇛*c = ≡p⇒⇛* (≡β⇒≡p a≡b) in c , ⇛*⇒→β* a⇛*c , ⇛*⇒→β* b⇛*c -- Π-injectivity (with respect to ≡β). Π-inj : ∀ {n} {a₁ a₂ : Term n} {b₁ b₂} → Π a₁ b₁ ≡β Π a₂ b₂ → a₁ ≡β a₂ × b₁ ≡β b₂ Π-inj Πa₁b₁≡Πa₂b₂ = let a₁≡a₂ , b₁≡b₂ = Par.Π-inj (≡β⇒≡p Πa₁b₁≡Πa₂b₂) in ≡p⇒≡β a₁≡a₂ , ≡p⇒≡β b₁≡b₂ -- β-equivalence on sorts implies syntactic equivalence. sort-≡β : ∀ {n s₁ s₂} → sort {n} s₁ ≡β sort s₂ → s₁ ≡ s₂ sort-≡β s₁≡βs₂ = Par.sort-≡p (≡β⇒≡p s₁≡βs₂)
36.680147
75
0.494137
312ea657da89b7f2ce1dcc552474d1d0661e1f03
800
agda
Agda
src/Fiber.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
src/Fiber.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
src/Fiber.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K #-} module Fiber where open import Equivalence open import NTypes.Contractible open import PathOperations open import Types fib : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) (y : B) → Set _ fib {A = A} f y = Σ A λ x → f x ≡ y fib→dom : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) → Σ B (fib f) → A fib→dom f (b , a , p) = a dom→fib : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) → A → Σ B (fib f) dom→fib f a = f a , a , refl fib-dom-eq : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) → Σ B (fib f) ≃ A fib-dom-eq {A = A} {B = B} f = fib→dom f , (dom→fib f , λ _ → refl) , (dom→fib f , λ {(b , a , p) → ap (swap ∘ _,_ a) (π₂ (pp-space-contr (f a)) (b , p))}) where swap : (Σ A λ x → Σ B λ y → f x ≡ y) → Σ B (fib f) swap (b , a , p) = a , b , p
25
61
0.47
2f2b042348c701f30ceafdcc8d02ed9480a3884f
1,751
agda
Agda
PiFrac/Interp.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
PiFrac/Interp.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
PiFrac/Interp.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
module PiFrac.Interp where open import Data.Empty open import Data.Unit hiding (_≟_) open import Data.Sum open import Data.Product open import Data.Maybe open import Relation.Binary.Core open import Relation.Binary open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Function using (_∘_) open import PiFrac.Syntax open import PiFrac.Opsem interp : {t₁ t₂ : 𝕌} → (t₁ ↔ t₂) → ⟦ t₁ ⟧ → Maybe ⟦ t₂ ⟧ interp unite₊l (inj₂ v) = just v interp uniti₊l v = just (inj₂ v) interp swap⋆ (v₁ , v₂) = just (v₂ , v₁) interp swap₊ (inj₁ v) = just (inj₂ v) interp swap₊ (inj₂ v) = just (inj₁ v) interp assocl₊ (inj₁ v) = just (inj₁ (inj₁ v)) interp assocl₊ (inj₂ (inj₁ v)) = just (inj₁ (inj₂ v)) interp assocl₊ (inj₂ (inj₂ v)) = just (inj₂ v) interp assocr₊ (inj₁ (inj₁ v)) = just (inj₁ v) interp assocr₊ (inj₁ (inj₂ v)) = just (inj₂ (inj₁ v)) interp assocr₊ (inj₂ v) = just (inj₂ (inj₂ v)) interp unite⋆l v = just (proj₂ v) interp uniti⋆l v = just (tt , v) interp assocl⋆ (v₁ , v₂ , v₃) = just ((v₁ , v₂) , v₃) interp assocr⋆ ((v₁ , v₂) , v₃) = just (v₁ , v₂ , v₃) interp dist (inj₁ v₁ , v₃) = just (inj₁ (v₁ , v₃)) interp dist (inj₂ v₂ , v₃) = just (inj₂ (v₂ , v₃)) interp factor (inj₁ (v₁ , v₃)) = just (inj₁ v₁ , v₃) interp factor (inj₂ (v₂ , v₃)) = just (inj₂ v₂ , v₃) interp id↔ v = just v interp (c₁ ⊕ c₂) (inj₁ v) = interp c₁ v >>= just ∘ inj₁ interp (c₁ ⊕ c₂) (inj₂ v) = interp c₂ v >>= just ∘ inj₂ interp (c₁ ⊗ c₂) (v₁ , v₂) = interp c₁ v₁ >>= (λ v₁' → interp c₂ v₂ >>= λ v₂' → just (v₁' , v₂')) interp (c₁ ⨾ c₂) v = interp c₁ v >>= interp c₂ interp (ηₓ v) tt = just (v , ↻) interp (εₓ v) (v' , ○) with v ≟ v' ... | yes _ = just tt ... | no _ = nothing
38.065217
59
0.611079
2923552eb8b680b1f789ad49c3368c6fece33a1a
676
agda
Agda
test/interaction/Issue1360.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1360.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1360.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v interaction.give:20 #-} -- Reported by stevan.andjelkovic, Yesterday (17 hours ago) -- Trying to give the expression in the goal gives the following error: -- tt != tt p a of type Prop -- when checking that the expression (λ x y → ?) has type -- ({o : ⊤} (p : ⊤) → ⊥ → ⊤) record _▷_ (I O : Set) : Set₁ where constructor _◃_/_ field Parameter : (o : O) → Set Arity : ∀ {o} (p : Parameter o) → Set input : ∀ {o} (p : Parameter o) (a : Arity p) → I open _▷_ public data ⊥ : Set where record ⊤ : Set where constructor tt --data ⊤ : Set where -- tt : ⊤ Abort : ⊤ ▷ ⊤ Abort = (λ _ → ⊤) ◃ (λ _ → ⊥) / {!!λ x y → {!!}!}
21.806452
71
0.54142
31ffce97f94d24a397def688d6c3007225761a12
10,038
agda
Agda
Cubical/Experiments/EscardoSIP.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Experiments/EscardoSIP.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Experiments/EscardoSIP.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{- This is a rather literal translation of Martin Hötzel-Escardó's structure identity principle into cubical Agda. See https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns All the needed preliminary results from the lecture notes are stated and proven in this file. It would be interesting to compare the proves with the one in Cubical.Foundations.SIP -} {-# OPTIONS --cubical --safe #-} module Cubical.Experiments.EscardoSIP where open import Cubical.Core.Everything open import Cubical.Foundations.Everything open import Cubical.Foundations.HAEquiv open import Cubical.Data.Sigma.Properties private variable ℓ ℓ' ℓ'' : Level -- We prove several useful equalities and equivalences between Σ-types all the proofs are taken from -- Martin Hötzel-Escardó's lecture notes. -- The next result is just a reformulation of pathSigma≡sigmaPath from Sigma.Properties. Σ-≡-≃ : {X : Type ℓ} {A : X → Type ℓ'} → (σ τ : Σ X A) → ((σ ≡ τ) ≃ (Σ[ p ∈ (σ .fst) ≡ (τ .fst) ] (subst A p (σ .snd) ≡ (τ .snd)))) Σ-≡-≃ {A = A} σ τ = pathToEquiv (pathSigma≡sigmaPath σ τ) -- This cubical proof is much shorter than in HoTT but requires that A, B live in the same universe. Σ-cong : {X : Type ℓ} {A B : X → Type ℓ'} → ((x : X) → (A x ≡ B x)) → (Σ X A ≡ Σ X B) Σ-cong {X = X} p i = Σ[ x ∈ X ] (p x i) -- Two lemmas for the more general formulation using equivalences NatΣ : {X : Type ℓ} {A : X → Type ℓ'} {B : X → Type ℓ''} → ((x : X) → (A x) → (B x)) → (Σ X A) → (Σ X B) NatΣ τ (x , a) = (x , τ x a) Σ-to-PathP : {X : Type ℓ} {A : X → Type ℓ'} {x : X} {a b : A x} → (a ≡ b) → PathP (λ i → Σ X A) (x , a) (x , b) Σ-to-PathP {x = x} p i = (x , p i) Σ-cong-≃ : {X : Type ℓ} {A : X → Type ℓ'} {B : X → Type ℓ''} → ((x : X) → (A x ≃ B x)) → (Σ X A ≃ Σ X B) Σ-cong-≃ {X = X} {A = A} {B = B} φ = isoToEquiv (iso (NatΣ f) (NatΣ g) NatΣ-ε NatΣ-η) where f : (x : X) → (A x) → (B x) f x = equivFun (φ x) g : (x : X) → (B x) → (A x) g x = equivFun (invEquiv (φ x)) η : (x : X) → (a : A x) → (g x) ((f x) a) ≡ a η x = retEq (invEquiv (φ x)) ε : (x : X) → (b : B x) → f x (g x b) ≡ b ε x = secEq (invEquiv (φ x)) NatΣ-η : (w : Σ X A) → NatΣ g (NatΣ f w) ≡ w NatΣ-η (x , a) = (x , g x (f x a)) ≡⟨ Σ-to-PathP (η x a) ⟩ (x , a) ∎ NatΣ-ε : (u : Σ X B) → NatΣ f (NatΣ g u) ≡ u NatΣ-ε (x , b) = (x , f x (g x b)) ≡⟨ Σ-to-PathP (ε x b) ⟩ (x , b) ∎ -- The next result is stated a bit awkwardly but is rather straightforward to prove. Σ-change-of-variable-Iso : {X : Type ℓ} {Y : Type ℓ'} {A : Y → Type ℓ''} (f : X → Y) → (isHAEquiv f) → (Iso (Σ X (A ∘ f)) (Σ Y A)) Σ-change-of-variable-Iso {ℓ = ℓ} {ℓ' = ℓ'} {X = X} {Y = Y} {A = A} f isHAEquivf = iso φ ψ φψ ψφ where g : Y → X g = isHAEquiv.g isHAEquivf ε : (x : X) → (g (f x)) ≡ x ε = isHAEquiv.sec isHAEquivf η : (y : Y) → f (g y) ≡ y η = isHAEquiv.ret isHAEquivf τ : (x : X) → cong f (ε x) ≡ η (f x) τ = isHAEquiv.com isHAEquivf φ : (Σ X (A ∘ f)) → (Σ Y A) φ (x , a) = (f x , a) ψ : (Σ Y A) → (Σ X (A ∘ f)) ψ (y , a) = (g y , subst A (sym (η y)) a) φψ : (z : (Σ Y A)) → φ (ψ z) ≡ z φψ (y , a) = sigmaPath→pathSigma (φ (ψ (y , a))) (y , a) (η y , transportTransport⁻ (λ i → A (η y i)) a) -- last term proves transp (λ i → A (η y i)) i0 (transp (λ i → A (η y (~ i))) i0 a) ≡ a ψφ : (z : (Σ X (A ∘ f))) → ψ (φ z) ≡ z ψφ (x , a) = sigmaPath→pathSigma (ψ (φ (x , a))) (x , a) (ε x , q) where b : A (f (g (f x))) b = (transp (λ i → A (η (f x) (~ i))) i0 a) q : transp (λ i → A (f (ε x i))) i0 (transp (λ i → A (η (f x) (~ i))) i0 a) ≡ a q = transp (λ i → A (f (ε x i))) i0 b ≡⟨ S ⟩ transp (λ i → A (η (f x) i)) i0 b ≡⟨ transportTransport⁻ (λ i → A (η (f x) i)) a ⟩ a ∎ where S : (transp (λ i → A (f (ε x i))) i0 b) ≡ (transp (λ i → A (η (f x) i)) i0 b) S = subst (λ p → (transp (λ i → A (f (ε x i))) i0 b) ≡ (transp (λ i → A (p i)) i0 b)) (τ x) refl -- Using the result above we can prove the following quite useful result. Σ-change-of-variable-≃ : {X : Type ℓ} {Y : Type ℓ'} {A : Y → Type ℓ''} (f : X → Y) → (isEquiv f) → ((Σ X (A ∘ f)) ≃ (Σ Y A)) Σ-change-of-variable-≃ f isEquivf = isoToEquiv (Σ-change-of-variable-Iso f (equiv→HAEquiv (f , isEquivf) .snd)) Σ-assoc-Iso : (X : Type ℓ) (A : X → Type ℓ') (P : Σ X A → Type ℓ'') → (Iso (Σ (Σ X A) P) (Σ[ x ∈ X ] (Σ[ a ∈ A x ] P (x , a)))) Σ-assoc-Iso X A P = iso f g ε η where f : (Σ (Σ X A) P) → (Σ[ x ∈ X ] (Σ[ a ∈ A x ] P (x , a))) f ((x , a) , p) = (x , (a , p)) g : (Σ[ x ∈ X ] (Σ[ a ∈ A x ] P (x , a))) → (Σ (Σ X A) P) g (x , (a , p)) = ((x , a) , p) ε : section f g ε n = refl η : retract f g η m = refl Σ-assoc-≃ : (X : Type ℓ) (A : X → Type ℓ') (P : Σ X A → Type ℓ'') → (Σ (Σ X A) P) ≃ (Σ[ x ∈ X ] (Σ[ a ∈ A x ] P (x , a))) Σ-assoc-≃ X A P = isoToEquiv (Σ-assoc-Iso X A P) -- A structure is a type-family S : Type ℓ → Type ℓ', i.e. for X : Type ℓ and s : S X, the pair (X , s) -- means that X is equipped with a S-structure, which is witnessed by s. -- An S-structure should have a notion of S-homomorphism, or rather S-isomorphism. -- This will be implemented by a function ι -- that gives us for any two types with S-structure (X , s) and (Y , t) a family: -- ι (X , s) (Y , t) : (X ≃ Y) → Type ℓ'' -- Note that for any equivalence (f , e) : X ≃ Y the type ι (X , s) (Y , t) (f , e) need not to be -- a proposition. Indeed this type should correspond to the ways s and t can be identified -- as S-structures. This we call a standard notion of structure. SNS : (S : Type ℓ → Type ℓ') → ((A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A .fst) ≃ (B .fst)) → Type ℓ'') → Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'') SNS {ℓ = ℓ} S ι = ∀ {X : (Type ℓ)} (s t : S X) → ((s ≡ t) ≃ ι (X , s) (X , t) (idEquiv X)) -- Escardo's ρ can actually be defined from this: ρ : {S : Type ℓ → Type ℓ'} → {ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A .fst) ≃ (B .fst)) → Type ℓ''} → (SNS S ι) → (A : Σ[ X ∈ (Type ℓ) ] (S X)) → (ι A A (idEquiv (A .fst))) ρ θ A = equivFun (θ (A .snd) (A .snd)) refl -- We introduce the notation a bit differently: _≃[_]_ : {S : Type ℓ → Type ℓ'} → (Σ[ X ∈ (Type ℓ) ] (S X)) → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A .fst) ≃ (B .fst)) → Type ℓ'') → (Σ[ X ∈ (Type ℓ) ] (S X)) → (Type (ℓ-max ℓ ℓ'')) A ≃[ ι ] B = Σ[ f ∈ ((A .fst) ≃ (B. fst)) ] (ι A B f) Id→homEq : (S : Type ℓ → Type ℓ') → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A .fst) ≃ (B .fst)) → Type ℓ'') → (ρ : (A : Σ[ X ∈ (Type ℓ) ] (S X)) → ι A A (idEquiv (A .fst))) → (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A ≡ B → (A ≃[ ι ] B) Id→homEq S ι ρ A B p = J (λ y x → A ≃[ ι ] y) (idEquiv (A .fst) , ρ A) p -- Use a PathP version of Escardó's homomorphism-lemma hom-lemma-dep : (S : Type ℓ → Type ℓ') → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A .fst) ≃ (B .fst)) → Type ℓ'') → (θ : SNS S ι) → (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → (p : (A .fst) ≡ (B. fst)) → (PathP (λ i → S (p i)) (A .snd) (B .snd)) ≃ (ι A B (pathToEquiv p)) hom-lemma-dep S ι θ A B p = (J P (λ s → γ s) p) (B .snd) where P = (λ y x → (s : S y) → PathP (λ i → S (x i)) (A .snd) s ≃ ι A (y , s) (pathToEquiv x)) γ : (s : S (A .fst)) → ((A .snd) ≡ s) ≃ ι A ((A .fst) , s) (pathToEquiv refl) γ s = subst (λ f → ((A .snd) ≡ s) ≃ ι A ((A .fst) , s) f) (sym pathToEquivRefl) (θ (A. snd) s) -- Define the inverse of Id→homEq directly. ua-lemma : (A B : Type ℓ) (e : A ≃ B) → (pathToEquiv (ua e)) ≡ e ua-lemma A B e = EquivJ (λ b a f → (pathToEquiv (ua f)) ≡ f) (λ x → subst (λ r → pathToEquiv r ≡ idEquiv x) (sym uaIdEquiv) pathToEquivRefl) B A e homEq→Id : (S : Type ℓ → Type ℓ') → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A .fst) ≃ (B .fst)) → Type ℓ'') → (θ : SNS S ι) → (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → (A ≃[ ι ] B) → A ≡ B homEq→Id S ι θ A B (f , φ) = ΣPathP (p , q) where p = ua f ψ : ι A B (pathToEquiv p) ψ = subst (λ g → ι A B g) (sym (ua-lemma (A .fst) (B. fst) f)) φ q : PathP (λ i → S (p i)) (A .snd) (B .snd) q = equivFun (invEquiv (hom-lemma-dep S ι θ A B p)) ψ -- Proof of the SIP: SIP : (S : Type ℓ → Type ℓ') → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A .fst) ≃ (B .fst)) → Type ℓ'') → (θ : SNS S ι) → (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → ((A ≡ B) ≃ (A ≃[ ι ] B)) SIP S ι θ A B = (A ≡ B) ≃⟨ i ⟩ (Σ[ p ∈ (A .fst) ≡ (B. fst) ] PathP (λ i → S (p i)) (A .snd) (B .snd)) ≃⟨ ii ⟩ (Σ[ p ∈ (A .fst) ≡ (B. fst) ] (ι A B (pathToEquiv p))) ≃⟨ iii ⟩ (A ≃[ ι ] B) ■ where i = invEquiv Σ≡ ii = Σ-cong-≃ (hom-lemma-dep S ι θ A B) iii = Σ-change-of-variable-≃ pathToEquiv (equivIsEquiv univalence) -- A simple example: pointed types pointed-structure : Type ℓ → Type ℓ pointed-structure X = X Pointed-Type : Type (ℓ-suc ℓ) Pointed-Type {ℓ = ℓ} = Σ (Type ℓ) pointed-structure pointed-ι : (A B : Pointed-Type) → (A .fst) ≃ (B. fst) → Type ℓ pointed-ι (X , x) (Y , y) f = (equivFun f) x ≡ y pointed-is-sns : SNS {ℓ = ℓ} pointed-structure pointed-ι pointed-is-sns s t = idEquiv (s ≡ t) pointed-type-sip : (X Y : Type ℓ) (x : X) (y : Y) → (Σ[ f ∈ X ≃ Y ] (f .fst) x ≡ y) ≃ ((X , x) ≡ (Y , y)) pointed-type-sip X Y x y = invEquiv (SIP pointed-structure pointed-ι pointed-is-sns (X , x) (Y , y))
38.607692
115
0.461447
184148f43a45602b960b3d519dec547b4a463d9a
4,151
agda
Agda
src/ZAxioms.agda
acallesalda/setform
4ab3c1a8bfd679cb3ced25500aa8103cb6c4b1f4
[ "MIT" ]
3
2019-08-02T23:13:13.000Z
2022-01-06T20:04:13.000Z
src/ZAxioms.agda
acallesalda/setform
4ab3c1a8bfd679cb3ced25500aa8103cb6c4b1f4
[ "MIT" ]
null
null
null
src/ZAxioms.agda
acallesalda/setform
4ab3c1a8bfd679cb3ced25500aa8103cb6c4b1f4
[ "MIT" ]
null
null
null
------------------------------------------------- -- Formalisation of the Z axioms of set theory. ------------------------------------------------- infix 1 ∃ infix 5 _⊆_ infix 5 _∈_ _∉_ infix 4 _≡_ module ZAxioms where open import Logic -- The universe of discourse (pure sets) and the membership -- relationship. (The letter 𝓢 is type by "\MCS") postulate 𝓢 : Set _∈_ : 𝓢 → 𝓢 → Set -- Existential quantifier data ∃ (A : 𝓢 → Set) : Set where _,_ : (t : 𝓢) → A t → ∃ A -- Sugar syntax for the existential quantifier. syntax ∃ (λ x → e) = ∃[ x ] e -- Existential projections. proj₁ : {A : 𝓢 → Set} → ∃ A → 𝓢 proj₁ (t , _) = t proj₂ : (A : 𝓢 → Set) → (foo : ∃ A) → A (proj₁ foo) proj₂ A (_ , Ax) = Ax -- Equivalence and non equivalence with some useful properties data _≡_ (x : 𝓢) : 𝓢 → Set where refl : x ≡ x _≢_ : 𝓢 → 𝓢 → Set x ≢ y = ¬ x ≡ y sym : (x y : 𝓢) → x ≡ y → y ≡ x sym x .x refl = refl cong : (f :  𝓢 → 𝓢) {x y : 𝓢} → x ≡ y → f x ≡ f y cong f refl = refl subs : (P : 𝓢 → Set) {x y : 𝓢} (p : x ≡ y) (h : P x) → P y subs P {x} {.x} refl h = h trans : {x y z : 𝓢} → x ≡ y → y ≡ z → x ≡ z trans refl refl = refl -- Property concerning bi-implication, needed in a proof. ⇔-p₂ : (z : 𝓢) → {A B C : Set} → A ⇔ (B ∧ C) → (C → B) → A ⇔ C ⇔-p₂ z (h₁ , h₂) h₃ = (λ a → ∧-proj₂ (h₁ a)) , (λ c → h₂ ((h₃ c) , c)) -- Definitions of subset and not-membership. _⊆_ : 𝓢 → 𝓢 → Set x ⊆ y = (t : 𝓢) → t ∈ x → t ∈ y _∉_ : 𝓢 → 𝓢 → Set x ∉ y = ¬ (x ∈ y) {-# ATP definition _∉_ #-} _⊂_ : 𝓢 → 𝓢 → Set x ⊂ y = x ⊆ y ∧ x ≢ y _⊂'_ : 𝓢 → 𝓢 → Set x ⊂' y = x ⊆ y ∧ ∃ (λ z → z ∈ y ∧ z ∉ x) ------------------------------------------- -- ZFC's axioms -- From (Suppes 1960, p. 56) -- ext (Extensionality) : If two sets have exactly the same members, -- they are equal. -- empt (Empty Set Axiom) : There is a set having no -- members. Allows us to define the empty set. -- pair (Pairing Axiom) : For any sets y and z, there is a set having -- as members just y and z. Allows to define a set which is just -- the pair of any two sets. -- pow (Power Set Axiom): For any x there is a set whose members are -- exactly the subsets of x. Allows us to define the power set -- operation. -- sub (Subset Axiom, or Specification Axiom): This axiom asserts the -- existence of a set B whose members are exactly those sets x in y -- such that they satisfy certain property. Allows us to define -- many operations like cartesian products and difference of sets. -- uni (Union Axiom) : For any set x, there exists a set A whose -- elements are exactly the members of x. Allows us to define the -- union of two sets. -- pem (Principle of the excluded middle) : To prove some things -- not valid in intuitionistic logic and valid in classical logic. Taken -- from the Standford Encyclopedia entry on Intuitionistic Logic. -- (https://plato.stanford.edu/entries/logic-intuitionistic/). -- The sum axioms allow us to define the union operation -- over a family of sets. postulate empt : ∃ (λ B → ∀ x → x ∉ B) ext : (x y : 𝓢) → ∀ {z} → z ∈ x ⇔ z ∈ y → x ≡ y union : (x y : 𝓢) → ∃ (λ B → {z : 𝓢} → z ∈ B ⇔ z ∈ x ∨ z ∈ y) pair : (x y : 𝓢) → ∃ (λ B → {z : 𝓢} → z ∈ B ⇔ (z ≡ x ∨ z ≡ y)) pow : (x : 𝓢) → ∃ (λ B → ∀ {y} → y ∈ B ⇔ y ⊆ x) sub : (A : 𝓢 → Set) → (y : 𝓢) → ∃ (λ B → {z : 𝓢} → (z ∈ B ⇔ (z ∈ y ∧ A z))) pem : (A : Set) → A ∨ ¬ A sum : (A : 𝓢) → ∃ (λ C → (x : 𝓢) → x ∈ C ⇔ ∃ (λ B → x ∈ B ∧ B ∈ A)) {-# ATP axioms empt ext union pair pow #-} -- sub not given to apia since it is an axiom schema and ATPs don't deal -- with that. -- pem isn't given either since ATP's use classical logic so it uses -- this principle by default. ∅ : 𝓢 ∅ = proj₁ empt {-# ATP definition ∅ #-} -- Axiom of regularity: Axiom that have two very intuitive consequences: -- ∀ A (A ∉ A) and ¬ ∀ A,B (A∈B ∧ B∈A). From Suppes, p. 56 (1960). postulate reg : (A : 𝓢) → A ≢ ∅ → ∃ (λ x → x ∈ A ∧ ∀ y → y ∈ x → y ∉ A) -- 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.
28.431507
78
0.558901
59d1107fcd84a5116bd6798e7e2af5cf7812d87c
5,248
agda
Agda
prototyping/Luau/Type.agda
saga/luau
5bb9f379b07e378db0a170e7c4030e3a943b2f14
[ "MIT" ]
null
null
null
prototyping/Luau/Type.agda
saga/luau
5bb9f379b07e378db0a170e7c4030e3a943b2f14
[ "MIT" ]
null
null
null
prototyping/Luau/Type.agda
saga/luau
5bb9f379b07e378db0a170e7c4030e3a943b2f14
[ "MIT" ]
null
null
null
module Luau.Type where open import FFI.Data.Maybe using (Maybe; just; nothing; just-inv) open import Agda.Builtin.Equality using (_≡_; refl) open import Properties.Dec using (Dec; yes; no) open import Properties.Equality using (cong) open import FFI.Data.Maybe using (Maybe; just; nothing) data Type : Set where nil : Type _⇒_ : Type → Type → Type never : Type unknown : Type boolean : Type number : Type string : Type _∪_ : Type → Type → Type _∩_ : Type → Type → Type data Scalar : Type → Set where number : Scalar number boolean : Scalar boolean string : Scalar string nil : Scalar nil lhs : Type → Type lhs (T ⇒ _) = T lhs (T ∪ _) = T lhs (T ∩ _) = T lhs nil = nil lhs never = never lhs unknown = unknown lhs number = number lhs boolean = boolean lhs string = string rhs : Type → Type rhs (_ ⇒ T) = T rhs (_ ∪ T) = T rhs (_ ∩ T) = T rhs nil = nil rhs never = never rhs unknown = unknown rhs number = number rhs boolean = boolean rhs string = string _≡ᵀ_ : ∀ (T U : Type) → Dec(T ≡ U) nil ≡ᵀ nil = yes refl nil ≡ᵀ (S ⇒ T) = no (λ ()) nil ≡ᵀ never = no (λ ()) nil ≡ᵀ unknown = no (λ ()) nil ≡ᵀ number = no (λ ()) nil ≡ᵀ boolean = no (λ ()) nil ≡ᵀ (S ∪ T) = no (λ ()) nil ≡ᵀ (S ∩ T) = no (λ ()) nil ≡ᵀ string = no (λ ()) (S ⇒ T) ≡ᵀ string = no (λ ()) never ≡ᵀ string = no (λ ()) unknown ≡ᵀ string = no (λ ()) boolean ≡ᵀ string = no (λ ()) number ≡ᵀ string = no (λ ()) (S ∪ T) ≡ᵀ string = no (λ ()) (S ∩ T) ≡ᵀ string = no (λ ()) (S ⇒ T) ≡ᵀ nil = no (λ ()) (S ⇒ T) ≡ᵀ (U ⇒ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ⇒ T) ≡ᵀ (S ⇒ T) | yes refl | yes refl = yes refl (S ⇒ T) ≡ᵀ (U ⇒ V) | _ | no p = no (λ q → p (cong rhs q)) (S ⇒ T) ≡ᵀ (U ⇒ V) | no p | _ = no (λ q → p (cong lhs q)) (S ⇒ T) ≡ᵀ never = no (λ ()) (S ⇒ T) ≡ᵀ unknown = no (λ ()) (S ⇒ T) ≡ᵀ number = no (λ ()) (S ⇒ T) ≡ᵀ boolean = no (λ ()) (S ⇒ T) ≡ᵀ (U ∪ V) = no (λ ()) (S ⇒ T) ≡ᵀ (U ∩ V) = no (λ ()) never ≡ᵀ nil = no (λ ()) never ≡ᵀ (U ⇒ V) = no (λ ()) never ≡ᵀ never = yes refl never ≡ᵀ unknown = no (λ ()) never ≡ᵀ number = no (λ ()) never ≡ᵀ boolean = no (λ ()) never ≡ᵀ (U ∪ V) = no (λ ()) never ≡ᵀ (U ∩ V) = no (λ ()) unknown ≡ᵀ nil = no (λ ()) unknown ≡ᵀ (U ⇒ V) = no (λ ()) unknown ≡ᵀ never = no (λ ()) unknown ≡ᵀ unknown = yes refl unknown ≡ᵀ number = no (λ ()) unknown ≡ᵀ boolean = no (λ ()) unknown ≡ᵀ (U ∪ V) = no (λ ()) unknown ≡ᵀ (U ∩ V) = no (λ ()) number ≡ᵀ nil = no (λ ()) number ≡ᵀ (T ⇒ U) = no (λ ()) number ≡ᵀ never = no (λ ()) number ≡ᵀ unknown = no (λ ()) number ≡ᵀ number = yes refl number ≡ᵀ boolean = no (λ ()) number ≡ᵀ (T ∪ U) = no (λ ()) number ≡ᵀ (T ∩ U) = no (λ ()) boolean ≡ᵀ nil = no (λ ()) boolean ≡ᵀ (T ⇒ U) = no (λ ()) boolean ≡ᵀ never = no (λ ()) boolean ≡ᵀ unknown = no (λ ()) boolean ≡ᵀ boolean = yes refl boolean ≡ᵀ number = no (λ ()) boolean ≡ᵀ (T ∪ U) = no (λ ()) boolean ≡ᵀ (T ∩ U) = no (λ ()) string ≡ᵀ nil = no (λ ()) string ≡ᵀ (x ⇒ x₁) = no (λ ()) string ≡ᵀ never = no (λ ()) string ≡ᵀ unknown = no (λ ()) string ≡ᵀ boolean = no (λ ()) string ≡ᵀ number = no (λ ()) string ≡ᵀ string = yes refl string ≡ᵀ (U ∪ V) = no (λ ()) string ≡ᵀ (U ∩ V) = no (λ ()) (S ∪ T) ≡ᵀ nil = no (λ ()) (S ∪ T) ≡ᵀ (U ⇒ V) = no (λ ()) (S ∪ T) ≡ᵀ never = no (λ ()) (S ∪ T) ≡ᵀ unknown = no (λ ()) (S ∪ T) ≡ᵀ number = no (λ ()) (S ∪ T) ≡ᵀ boolean = no (λ ()) (S ∪ T) ≡ᵀ (U ∪ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ∪ T) ≡ᵀ (S ∪ T) | yes refl | yes refl = yes refl (S ∪ T) ≡ᵀ (U ∪ V) | _ | no p = no (λ q → p (cong rhs q)) (S ∪ T) ≡ᵀ (U ∪ V) | no p | _ = no (λ q → p (cong lhs q)) (S ∪ T) ≡ᵀ (U ∩ V) = no (λ ()) (S ∩ T) ≡ᵀ nil = no (λ ()) (S ∩ T) ≡ᵀ (U ⇒ V) = no (λ ()) (S ∩ T) ≡ᵀ never = no (λ ()) (S ∩ T) ≡ᵀ unknown = no (λ ()) (S ∩ T) ≡ᵀ number = no (λ ()) (S ∩ T) ≡ᵀ boolean = no (λ ()) (S ∩ T) ≡ᵀ (U ∪ V) = no (λ ()) (S ∩ T) ≡ᵀ (U ∩ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ∩ T) ≡ᵀ (U ∩ V) | yes refl | yes refl = yes refl (S ∩ T) ≡ᵀ (U ∩ V) | _ | no p = no (λ q → p (cong rhs q)) (S ∩ T) ≡ᵀ (U ∩ V) | no p | _ = no (λ q → p (cong lhs q)) _≡ᴹᵀ_ : ∀ (T U : Maybe Type) → Dec(T ≡ U) nothing ≡ᴹᵀ nothing = yes refl nothing ≡ᴹᵀ just U = no (λ ()) just T ≡ᴹᵀ nothing = no (λ ()) just T ≡ᴹᵀ just U with T ≡ᵀ U (just T ≡ᴹᵀ just T) | yes refl = yes refl (just T ≡ᴹᵀ just U) | no p = no (λ q → p (just-inv q)) src : Type → Type src nil = never src number = never src boolean = never src string = never src (S ⇒ T) = S src (S ∪ T) = (src S) ∩ (src T) src (S ∩ T) = (src S) ∪ (src T) src never = unknown src unknown = never tgt : Type → Type tgt nil = never tgt (S ⇒ T) = T tgt never = never tgt unknown = unknown tgt number = never tgt boolean = never tgt string = never tgt (S ∪ T) = (tgt S) ∪ (tgt T) tgt (S ∩ T) = (tgt S) ∩ (tgt T) optional : Type → Type optional nil = nil optional (T ∪ nil) = (T ∪ nil) optional T = (T ∪ nil) normalizeOptional : Type → Type normalizeOptional (S ∪ T) with normalizeOptional S | normalizeOptional T normalizeOptional (S ∪ T) | (S′ ∪ nil) | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | S′ | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | (S′ ∪ nil) | T′ = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | S′ | nil = optional S′ normalizeOptional (S ∪ T) | nil | T′ = optional T′ normalizeOptional (S ∪ T) | S′ | T′ = S′ ∪ T′ normalizeOptional T = T
28.367568
72
0.517912
20300660e0e5a0be5787989dab973458d5581852
2,000
agda
Agda
Cubical/ZCohomology/Groups/Connected.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/Connected.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/Connected.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.ZCohomology.Groups.Connected where open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.Groups.Unit open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∥_∥ to ∥_∥₁ ; ∣_∣ to ∣_∣₁) open import Cubical.HITs.Nullification open import Cubical.Data.Sigma hiding (_×_) open import Cubical.Data.Int renaming (_+_ to _+ℤ_; +-comm to +ℤ-comm ; +-assoc to +ℤ-assoc) open import Cubical.Data.Nat open import Cubical.HITs.Truncation renaming (rec to trRec) open import Cubical.Algebra.Group open import Cubical.Homotopy.Connected open import Cubical.Foundations.Equiv private H⁰-connected-type : ∀ {ℓ} {A : Type ℓ} (a : A) → isConnected 2 A → Iso (coHom 0 A) Int Iso.fun (H⁰-connected-type a con) = sRec isSetInt λ f → f a Iso.inv (H⁰-connected-type a con) b = ∣ (λ x → b) ∣₂ Iso.rightInv (H⁰-connected-type a con) b = refl Iso.leftInv (H⁰-connected-type a con) = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f → cong ∣_∣₂ (funExt λ x → trRec (isSetInt _ _) (cong f) (isConnectedPath 1 con a x .fst)) H⁰-connected : ∀ {ℓ} {A : Type ℓ} (a : A) → ((x : A) → ∥ a ≡ x ∥₁) → GroupIso (coHomGr 0 A) intGroup GroupHom.fun (GroupIso.map (H⁰-connected a con)) = sRec isSetInt (λ f → f a) GroupHom.isHom (GroupIso.map (H⁰-connected a con)) = sElim2 (λ _ _ → isProp→isSet (isSetInt _ _)) λ x y → refl GroupIso.inv (H⁰-connected a con) b = ∣ (λ _ → b) ∣₂ GroupIso.rightInv (H⁰-connected a con) _ = refl GroupIso.leftInv (H⁰-connected a con) = sElim (λ _ → isProp→isSet (setTruncIsSet _ _)) (λ f → cong ∣_∣₂ (funExt λ x → pRec (isSetInt _ _) (cong f) (con x)))
45.454545
104
0.7095