Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --with-K -vtc.lhs.unify:50 #-}
open import Agda.Primitive using (Setω)
open import Agda.Builtin.Equality using (_≡_; refl)
-- change `Set` to `Setω` breaks `seq`
data RecD (I : Set) : Setω where
ι : (i : I) → RecD I
data RecO {I J : Set} (e : I → J) : RecD I → RecD J → Setω where
ι : (i : I) (j : J) (eq : e i ≡ j) → RecO e (ι i) (ι j)
seq : {I J K : Set} {e : I → J} {f : J → K} {D : RecD I} {E : RecD J} {F : RecD K}
→ RecO f E F → RecO e D E
→ RecO (λ i → f (e i)) D F
seq (ι _ _ refl) (ι _ _ refl) = ι _ _ refl
| {
"alphanum_fraction": 0.5218978102,
"avg_line_length": 32.2352941176,
"ext": "agda",
"hexsha": "42e960d20f5c17ff3559bff442880ffa6028344c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/Succeed/Issue5730.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/Succeed/Issue5730.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6b13364d36eeb60d8ec15eaf8effe23c73401900",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "sseefried/agda",
"max_stars_repo_path": "test/Succeed/Issue5730.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z",
"num_tokens": 242,
"size": 548
} |
{-# OPTIONS --cubical --no-import-sorts --postfix-projections --safe #-}
module Cubical.Categories.Presheaf.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open import Cubical.Categories.Instances.Sets
open import Cubical.Categories.Instances.Functors
module _ {ℓ ℓ'} where
PreShv : Precategory ℓ ℓ' → (ℓS : Level) → Precategory (ℓ-max (ℓ-max ℓ ℓ') (ℓ-suc ℓS)) (ℓ-max (ℓ-max ℓ ℓ') ℓS)
PreShv C ℓS = FUNCTOR (C ^op) (SET ℓS)
instance
isCatPreShv : ∀ {ℓ ℓ'} {C : Precategory ℓ ℓ'} {ℓS}
→ isCategory (PreShv C ℓS)
isCatPreShv {C = C} {ℓS} = isCatFUNCTOR (C ^op) (SET ℓS)
private
variable
ℓ ℓ' : Level
module Yoneda (C : Precategory ℓ ℓ') ⦃ C-cat : isCategory C ⦄ where
open Functor
open NatTrans
open Precategory C
yo : ob → Functor (C ^op) (SET ℓ')
yo x .F-ob y .fst = C [ y , x ]
yo x .F-ob y .snd = C-cat .isSetHom
yo x .F-hom f g = f ⋆⟨ C ⟩ g
yo x .F-id i f = ⋆IdL f i
yo x .F-seq f g i h = ⋆Assoc g f h i
YO : Functor C (PreShv C ℓ')
YO .F-ob = yo
YO .F-hom f .N-ob z g = g ⋆⟨ C ⟩ f
YO .F-hom f .N-hom g i h = ⋆Assoc g h f i
YO .F-id = makeNatTransPath λ i _ → λ f → ⋆IdR f i
YO .F-seq f g = makeNatTransPath λ i _ → λ h → ⋆Assoc h f g (~ i)
module _ {x} (F : Functor (C ^op) (SET ℓ')) where
yo-yo-yo : NatTrans (yo x) F → F .F-ob x .fst
yo-yo-yo α = α .N-ob _ (id _)
no-no-no : F .F-ob x .fst → NatTrans (yo x) F
no-no-no a .N-ob y f = F .F-hom f a
no-no-no a .N-hom f = funExt λ g i → F .F-seq g f i a
yoIso : Iso (NatTrans (yo x) F) (F .F-ob x .fst)
yoIso .Iso.fun = yo-yo-yo
yoIso .Iso.inv = no-no-no
yoIso .Iso.rightInv b i = F .F-id i b
yoIso .Iso.leftInv a = makeNatTransPath (funExt λ _ → funExt rem)
where
rem : ∀ {z} (x₁ : C [ z , x ]) → F .F-hom x₁ (yo-yo-yo a) ≡ (a .N-ob z) x₁
rem g =
F .F-hom g (yo-yo-yo a)
≡[ i ]⟨ a .N-hom g (~ i) (id x) ⟩
a .N-hom g i0 (id x)
≡[ i ]⟨ a .N-ob _ (⋆IdR g i) ⟩
(a .N-ob _) g
∎
yoEquiv : NatTrans (yo x) F ≃ F .F-ob x .fst
yoEquiv = isoToEquiv yoIso
isFullYO : isFull YO
isFullYO x y F[f] = ∣ yo-yo-yo _ F[f] , yoIso {x} (yo y) .Iso.leftInv F[f] ∣
isFaithfulYO : isFaithful YO
isFaithfulYO x y f g p i =
hcomp
(λ j → λ{ (i = i0) → ⋆IdL f j; (i = i1) → ⋆IdL g j})
(yo-yo-yo _ (p i))
| {
"alphanum_fraction": 0.5807926829,
"avg_line_length": 30.8705882353,
"ext": "agda",
"hexsha": "da5ba1d2756384bf3f6a8beb7e97645b5ceb7246",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Categories/Presheaf/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Categories/Presheaf/Base.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Categories/Presheaf/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1109,
"size": 2624
} |
module UniqueFloatNaN where
-- See Issue: Inconsistency: Rounding op differentiates NaNs #3749
-- https://github.com/agda/agda/issues/3749
open import Agda.Builtin.Float
renaming ( primRound to round
; primFloor to floor
; primCeiling to ceiling
; primFloatNegate to -_
; primFloatDiv to _/_)
open import Agda.Builtin.Equality
PNaN : Float
PNaN = 0.0 / 0.0
NNaN : Float
NNaN = - (0.0 / 0.0)
f : round PNaN ≡ round NNaN
f = refl
g : floor PNaN ≡ floor NNaN
g = refl
h : ceiling PNaN ≡ ceiling NNaN
h = refl
| {
"alphanum_fraction": 0.6589285714,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "83ca05e43b9c4459069326376bae901213e5ffe9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/UniqueFloatNaN.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/UniqueFloatNaN.agda",
"max_line_length": 66,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/UniqueFloatNaN.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 180,
"size": 560
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some properties about integers
------------------------------------------------------------------------
module Data.Integer.Properties where
open import Algebra
import Algebra.FunctionProperties
import Algebra.Morphism as Morphism
import Algebra.Properties.AbelianGroup
open import Algebra.Structures
open import Data.Integer hiding (suc; _≤?_)
import Data.Integer.Addition.Properties as Add
import Data.Integer.Multiplication.Properties as Mul
open import Data.Nat
using (ℕ; suc; zero; _∸_; _≤?_; _<_; _≥_; _≱_; s≤s; z≤n; ≤-pred)
renaming (_+_ to _ℕ+_; _*_ to _ℕ*_)
open import Data.Nat.Properties as ℕ using (_*-mono_)
open import Data.Product using (proj₁; proj₂; _,_)
open import Data.Sign as Sign using () renaming (_*_ to _S*_)
import Data.Sign.Properties as SignProp
open import Function using (_∘_; _$_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Negation using (contradiction)
open Algebra.FunctionProperties (_≡_ {A = ℤ})
open CommutativeMonoid Add.commutativeMonoid
using ()
renaming ( assoc to +-assoc; comm to +-comm; identity to +-identity
; isCommutativeMonoid to +-isCommutativeMonoid
; isMonoid to +-isMonoid
)
open CommutativeMonoid Mul.commutativeMonoid
using ()
renaming ( assoc to *-assoc; comm to *-comm; identity to *-identity
; isCommutativeMonoid to *-isCommutativeMonoid
; isMonoid to *-isMonoid
)
open CommutativeSemiring ℕ.commutativeSemiring
using () renaming (zero to *-zero; distrib to *-distrib)
open DecTotalOrder Data.Nat.decTotalOrder
using () renaming (refl to ≤-refl)
open Morphism.Definitions ℤ ℕ _≡_
open ℕ.SemiringSolver
open ≡-Reasoning
------------------------------------------------------------------------
-- Miscellaneous properties
-- Some properties relating sign and ∣_∣ to _◃_.
sign-◃ : ∀ s n → sign (s ◃ suc n) ≡ s
sign-◃ Sign.- _ = refl
sign-◃ Sign.+ _ = refl
sign-cong : ∀ {s₁ s₂ n₁ n₂} →
s₁ ◃ suc n₁ ≡ s₂ ◃ suc n₂ → s₁ ≡ s₂
sign-cong {s₁} {s₂} {n₁} {n₂} eq = begin
s₁ ≡⟨ sym $ sign-◃ s₁ n₁ ⟩
sign (s₁ ◃ suc n₁) ≡⟨ cong sign eq ⟩
sign (s₂ ◃ suc n₂) ≡⟨ sign-◃ s₂ n₂ ⟩
s₂ ∎
abs-◃ : ∀ s n → ∣ s ◃ n ∣ ≡ n
abs-◃ _ zero = refl
abs-◃ Sign.- (suc n) = refl
abs-◃ Sign.+ (suc n) = refl
abs-cong : ∀ {s₁ s₂ n₁ n₂} →
s₁ ◃ n₁ ≡ s₂ ◃ n₂ → n₁ ≡ n₂
abs-cong {s₁} {s₂} {n₁} {n₂} eq = begin
n₁ ≡⟨ sym $ abs-◃ s₁ n₁ ⟩
∣ s₁ ◃ n₁ ∣ ≡⟨ cong ∣_∣ eq ⟩
∣ s₂ ◃ n₂ ∣ ≡⟨ abs-◃ s₂ n₂ ⟩
n₂ ∎
-- ∣_∣ commutes with multiplication.
abs-*-commute : Homomorphic₂ ∣_∣ _*_ _ℕ*_
abs-*-commute i j = abs-◃ _ _
-- If you subtract a natural from itself, then you get zero.
n⊖n≡0 : ∀ n → n ⊖ n ≡ + 0
n⊖n≡0 zero = refl
n⊖n≡0 (suc n) = n⊖n≡0 n
------------------------------------------------------------------------
-- The integers form a commutative ring
private
----------------------------------------------------------------------
-- Additive abelian group.
inverseˡ : LeftInverse (+ 0) -_ _+_
inverseˡ -[1+ n ] = n⊖n≡0 n
inverseˡ (+ zero) = refl
inverseˡ (+ suc n) = n⊖n≡0 n
inverseʳ : RightInverse (+ 0) -_ _+_
inverseʳ i = begin
i + - i ≡⟨ +-comm i (- i) ⟩
- i + i ≡⟨ inverseˡ i ⟩
+ 0 ∎
+-isAbelianGroup : IsAbelianGroup _≡_ _+_ (+ 0) -_
+-isAbelianGroup = record
{ isGroup = record
{ isMonoid = +-isMonoid
; inverse = inverseˡ , inverseʳ
; ⁻¹-cong = cong -_
}
; comm = +-comm
}
open Algebra.Properties.AbelianGroup
(record { isAbelianGroup = +-isAbelianGroup })
using () renaming (⁻¹-involutive to -‿involutive)
----------------------------------------------------------------------
-- Distributivity
-- Various lemmas used to prove distributivity.
sign-⊖-< : ∀ {m n} → m < n → sign (m ⊖ n) ≡ Sign.-
sign-⊖-< {zero} (s≤s z≤n) = refl
sign-⊖-< {suc n} (s≤s m<n) = sign-⊖-< m<n
sign-⊖-≱ : ∀ {m n} → m ≱ n → sign (m ⊖ n) ≡ Sign.-
sign-⊖-≱ = sign-⊖-< ∘ ℕ.≰⇒>
+-⊖-left-cancel : ∀ a b c → (a ℕ+ b) ⊖ (a ℕ+ c) ≡ b ⊖ c
+-⊖-left-cancel zero b c = refl
+-⊖-left-cancel (suc a) b c = +-⊖-left-cancel a b c
⊖-swap : ∀ a b → a ⊖ b ≡ - (b ⊖ a)
⊖-swap zero zero = refl
⊖-swap (suc _) zero = refl
⊖-swap zero (suc _) = refl
⊖-swap (suc a) (suc b) = ⊖-swap a b
-- Lemmas relating _⊖_ and _∸_.
∣⊖∣-< : ∀ {m n} → m < n → ∣ m ⊖ n ∣ ≡ n ∸ m
∣⊖∣-< {zero} (s≤s z≤n) = refl
∣⊖∣-< {suc n} (s≤s m<n) = ∣⊖∣-< m<n
∣⊖∣-≱ : ∀ {m n} → m ≱ n → ∣ m ⊖ n ∣ ≡ n ∸ m
∣⊖∣-≱ = ∣⊖∣-< ∘ ℕ.≰⇒>
⊖-≥ : ∀ {m n} → m ≥ n → m ⊖ n ≡ + (m ∸ n)
⊖-≥ z≤n = refl
⊖-≥ (s≤s n≤m) = ⊖-≥ n≤m
⊖-< : ∀ {m n} → m < n → m ⊖ n ≡ - + (n ∸ m)
⊖-< {zero} (s≤s z≤n) = refl
⊖-< {suc m} (s≤s m<n) = ⊖-< m<n
⊖-≱ : ∀ {m n} → m ≱ n → m ⊖ n ≡ - + (n ∸ m)
⊖-≱ = ⊖-< ∘ ℕ.≰⇒>
-- Lemmas working around the fact that _◃_ pattern matches on its
-- second argument before its first.
+‿◃ : ∀ n → Sign.+ ◃ n ≡ + n
+‿◃ zero = refl
+‿◃ (suc _) = refl
-‿◃ : ∀ n → Sign.- ◃ n ≡ - + n
-‿◃ zero = refl
-‿◃ (suc _) = refl
-- The main distributivity proof.
distrib-lemma :
∀ a b c → (c ⊖ b) * -[1+ a ] ≡ a ℕ+ b ℕ* suc a ⊖ (a ℕ+ c ℕ* suc a)
distrib-lemma a b c
rewrite +-⊖-left-cancel a (b ℕ* suc a) (c ℕ* suc a)
| ⊖-swap (b ℕ* suc a) (c ℕ* suc a)
with b ≤? c
... | yes b≤c
rewrite ⊖-≥ b≤c
| ⊖-≥ (b≤c *-mono (≤-refl {x = suc a}))
| -‿◃ ((c ∸ b) ℕ* suc a)
| ℕ.*-distrib-∸ʳ (suc a) c b
= refl
... | no b≰c
rewrite sign-⊖-≱ b≰c
| ∣⊖∣-≱ b≰c
| +‿◃ ((b ∸ c) ℕ* suc a)
| ⊖-≱ (b≰c ∘ ℕ.cancel-*-right-≤ b c a)
| -‿involutive (+ (b ℕ* suc a ∸ c ℕ* suc a))
| ℕ.*-distrib-∸ʳ (suc a) b c
= refl
distribʳ : _*_ DistributesOverʳ _+_
distribʳ (+ zero) y z
rewrite proj₂ *-zero ∣ y ∣
| proj₂ *-zero ∣ z ∣
| proj₂ *-zero ∣ y + z ∣
= refl
distribʳ x (+ zero) z
rewrite proj₁ +-identity z
| proj₁ +-identity (sign z S* sign x ◃ ∣ z ∣ ℕ* ∣ x ∣)
= refl
distribʳ x y (+ zero)
rewrite proj₂ +-identity y
| proj₂ +-identity (sign y S* sign x ◃ ∣ y ∣ ℕ* ∣ x ∣)
= refl
distribʳ -[1+ a ] -[1+ b ] -[1+ c ] = cong +_ $
solve 3 (λ a b c → (con 2 :+ b :+ c) :* (con 1 :+ a)
:= (con 1 :+ b) :* (con 1 :+ a) :+
(con 1 :+ c) :* (con 1 :+ a))
refl a b c
distribʳ (+ suc a) (+ suc b) (+ suc c) = cong +_ $
solve 3 (λ a b c → (con 1 :+ b :+ (con 1 :+ c)) :* (con 1 :+ a)
:= (con 1 :+ b) :* (con 1 :+ a) :+
(con 1 :+ c) :* (con 1 :+ a))
refl a b c
distribʳ -[1+ a ] (+ suc b) (+ suc c) = cong -[1+_] $
solve 3 (λ a b c → a :+ (b :+ (con 1 :+ c)) :* (con 1 :+ a)
:= (con 1 :+ b) :* (con 1 :+ a) :+
(a :+ c :* (con 1 :+ a)))
refl a b c
distribʳ (+ suc a) -[1+ b ] -[1+ c ] = cong -[1+_] $
solve 3 (λ a b c → a :+ (con 1 :+ a :+ (b :+ c) :* (con 1 :+ a))
:= (con 1 :+ b) :* (con 1 :+ a) :+
(a :+ c :* (con 1 :+ a)))
refl a b c
distribʳ -[1+ a ] -[1+ b ] (+ suc c) = distrib-lemma a b c
distribʳ -[1+ a ] (+ suc b) -[1+ c ] = distrib-lemma a c b
distribʳ (+ suc a) -[1+ b ] (+ suc c)
rewrite +-⊖-left-cancel a (c ℕ* suc a) (b ℕ* suc a)
with b ≤? c
... | yes b≤c
rewrite ⊖-≥ b≤c
| +-comm (- (+ (a ℕ+ b ℕ* suc a))) (+ (a ℕ+ c ℕ* suc a))
| ⊖-≥ (b≤c *-mono ≤-refl {x = suc a})
| ℕ.*-distrib-∸ʳ (suc a) c b
| +‿◃ (c ℕ* suc a ∸ b ℕ* suc a)
= refl
... | no b≰c
rewrite sign-⊖-≱ b≰c
| ∣⊖∣-≱ b≰c
| -‿◃ ((b ∸ c) ℕ* suc a)
| ⊖-≱ (b≰c ∘ ℕ.cancel-*-right-≤ b c a)
| ℕ.*-distrib-∸ʳ (suc a) b c
= refl
distribʳ (+ suc c) (+ suc a) -[1+ b ]
rewrite +-⊖-left-cancel c (a ℕ* suc c) (b ℕ* suc c)
with b ≤? a
... | yes b≤a
rewrite ⊖-≥ b≤a
| ⊖-≥ (b≤a *-mono ≤-refl {x = suc c})
| +‿◃ ((a ∸ b) ℕ* suc c)
| ℕ.*-distrib-∸ʳ (suc c) a b
= refl
... | no b≰a
rewrite sign-⊖-≱ b≰a
| ∣⊖∣-≱ b≰a
| ⊖-≱ (b≰a ∘ ℕ.cancel-*-right-≤ b a c)
| -‿◃ ((b ∸ a) ℕ* suc c)
| ℕ.*-distrib-∸ʳ (suc c) b a
= refl
-- The IsCommutativeSemiring module contains a proof of
-- distributivity which is used below.
isCommutativeSemiring : IsCommutativeSemiring _≡_ _+_ _*_ (+ 0) (+ 1)
isCommutativeSemiring = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isCommutativeMonoid = *-isCommutativeMonoid
; distribʳ = distribʳ
; zeroˡ = λ _ → refl
}
commutativeRing : CommutativeRing _ _
commutativeRing = record
{ Carrier = ℤ
; _≈_ = _≡_
; _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = + 0
; 1# = + 1
; isCommutativeRing = record
{ isRing = record
{ +-isAbelianGroup = +-isAbelianGroup
; *-isMonoid = *-isMonoid
; distrib = IsCommutativeSemiring.distrib
isCommutativeSemiring
}
; *-comm = *-comm
}
}
import Algebra.RingSolver.Simple as Solver
import Algebra.RingSolver.AlmostCommutativeRing as ACR
module RingSolver =
Solver (ACR.fromCommutativeRing commutativeRing) _≟_
------------------------------------------------------------------------
-- More properties
-- Multiplication is right cancellative for non-zero integers.
cancel-*-right : ∀ i j k →
k ≢ + 0 → i * k ≡ j * k → i ≡ j
cancel-*-right i j k ≢0 eq with signAbs k
cancel-*-right i j .(+ 0) ≢0 eq | s ◂ zero = contradiction refl ≢0
cancel-*-right i j .(s ◃ suc n) ≢0 eq | s ◂ suc n
with ∣ s ◃ suc n ∣ | abs-◃ s (suc n) | sign (s ◃ suc n) | sign-◃ s n
... | .(suc n) | refl | .s | refl =
◃-cong (sign-i≡sign-j i j eq) $
ℕ.cancel-*-right ∣ i ∣ ∣ j ∣ $ abs-cong eq
where
sign-i≡sign-j : ∀ i j →
sign i S* s ◃ ∣ i ∣ ℕ* suc n ≡
sign j S* s ◃ ∣ j ∣ ℕ* suc n →
sign i ≡ sign j
sign-i≡sign-j i j eq with signAbs i | signAbs j
sign-i≡sign-j .(+ 0) .(+ 0) eq | s₁ ◂ zero | s₂ ◂ zero = refl
sign-i≡sign-j .(+ 0) .(s₂ ◃ suc n₂) eq | s₁ ◂ zero | s₂ ◂ suc n₂
with ∣ s₂ ◃ suc n₂ ∣ | abs-◃ s₂ (suc n₂)
... | .(suc n₂) | refl
with abs-cong {s₁} {sign (s₂ ◃ suc n₂) S* s} {0} {suc n₂ ℕ* suc n} eq
... | ()
sign-i≡sign-j .(s₁ ◃ suc n₁) .(+ 0) eq | s₁ ◂ suc n₁ | s₂ ◂ zero
with ∣ s₁ ◃ suc n₁ ∣ | abs-◃ s₁ (suc n₁)
... | .(suc n₁) | refl
with abs-cong {sign (s₁ ◃ suc n₁) S* s} {s₁} {suc n₁ ℕ* suc n} {0} eq
... | ()
sign-i≡sign-j .(s₁ ◃ suc n₁) .(s₂ ◃ suc n₂) eq | s₁ ◂ suc n₁ | s₂ ◂ suc n₂
with ∣ s₁ ◃ suc n₁ ∣ | abs-◃ s₁ (suc n₁)
| sign (s₁ ◃ suc n₁) | sign-◃ s₁ n₁
| ∣ s₂ ◃ suc n₂ ∣ | abs-◃ s₂ (suc n₂)
| sign (s₂ ◃ suc n₂) | sign-◃ s₂ n₂
... | .(suc n₁) | refl | .s₁ | refl | .(suc n₂) | refl | .s₂ | refl =
SignProp.cancel-*-right s₁ s₂ (sign-cong eq)
-- Multiplication with a positive number is right cancellative (for
-- _≤_).
cancel-*-+-right-≤ : ∀ m n o → m * + suc o ≤ n * + suc o → m ≤ n
cancel-*-+-right-≤ (-[1+ m ]) (-[1+ n ]) o (-≤- n≤m) =
-≤- (≤-pred (ℕ.cancel-*-right-≤ (suc n) (suc m) o (s≤s n≤m)))
cancel-*-+-right-≤ ℤ.-[1+ _ ] (+ _) _ _ = -≤+
cancel-*-+-right-≤ (+ 0) ℤ.-[1+ _ ] _ ()
cancel-*-+-right-≤ (+ suc _) ℤ.-[1+ _ ] _ ()
cancel-*-+-right-≤ (+ 0) (+ 0) _ _ = +≤+ z≤n
cancel-*-+-right-≤ (+ 0) (+ suc _) _ _ = +≤+ z≤n
cancel-*-+-right-≤ (+ suc _) (+ 0) _ (+≤+ ())
cancel-*-+-right-≤ (+ suc m) (+ suc n) o (+≤+ m≤n) =
+≤+ (ℕ.cancel-*-right-≤ (suc m) (suc n) o m≤n)
-- Multiplication with a positive number is monotone.
*-+-right-mono : ∀ n → (λ x → x * + suc n) Preserves _≤_ ⟶ _≤_
*-+-right-mono _ (-≤+ {n = 0}) = -≤+
*-+-right-mono _ (-≤+ {n = suc _}) = -≤+
*-+-right-mono x (-≤- n≤m) =
-≤- (≤-pred (s≤s n≤m *-mono ≤-refl {x = suc x}))
*-+-right-mono _ (+≤+ {m = 0} {n = 0} m≤n) = +≤+ m≤n
*-+-right-mono _ (+≤+ {m = 0} {n = suc _} m≤n) = +≤+ z≤n
*-+-right-mono _ (+≤+ {m = suc _} {n = 0} ())
*-+-right-mono x (+≤+ {m = suc _} {n = suc _} m≤n) =
+≤+ (m≤n *-mono ≤-refl {x = suc x})
| {
"alphanum_fraction": 0.4528934644,
"avg_line_length": 33.390625,
"ext": "agda",
"hexsha": "19cf2d498547b1ba9b506a5a8e5a4bb9c0dcc7a6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Integer/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Integer/Properties.agda",
"max_line_length": 83,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Integer/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 5374,
"size": 12822
} |
open import Nat
open import Prelude
open import List
open import contexts
open import judgemental-erase
open import moveerase
open import sensibility
open import statics-checks
open import statics-core
module examples where
-- actions must always specify enough names to name all inserted holes. depending on
-- the context, not all names are used, and we pass this argument to make that clear.
-- an actual implementation could automatically insert hole names as needed
no-hole : Nat
no-hole = 0
-- the function (λx. x + 1) where x is named "0".
add1 : hexp
add1 = ·λ 0 (X 0 ·+ N 1)
-- this is the derivation that fn has type num ==> num
ex1 : ∅ ⊢ add1 <= (num ==> num)
ex1 = ALam refl MAArr
(ASubsume (SPlus (ASubsume (SVar refl) TCRefl) (ASubsume SNum TCRefl))
TCRefl)
-- the derivation that when applied to the numeric argument 10 add1
-- produces a num.
ex2 : ∅ ⊢ (add1 ·: (num ==> num)) ∘ (N 10) => num
ex2 = SAp (SAsc ex1) MAArr (ASubsume SNum TCRefl)
-- the slightly longer derivation that argues that add1 applied to a
-- variable that's known to be a num produces a num
ex2b : (∅ ,, (1 , num)) ⊢ (add1 ·: (num ==> num)) ∘ (X 1) => num
ex2b = SAp (SAsc (ALam refl MAArr
(ASubsume (SPlus (ASubsume (SVar refl) TCRefl) (ASubsume SNum TCRefl))
TCRefl)))
MAArr (ASubsume (SVar refl) TCRefl)
-- eta-expanding addition to curry it gets num → num → num
ex3 : ∅ ⊢ ·λ 0 ( (·λ 1 (X 0 ·+ X 1)) ·: (num ==> num))
<= (num ==> (num ==> num))
ex3 = ALam refl MAArr (ASubsume (SAsc (ALam refl MAArr (ASubsume
(SPlus (ASubsume (SVar refl) TCRefl) (ASubsume (SVar refl) TCRefl))
TCRefl))) TCRefl)
-- applying three to four has type hole -- but there is no action that
-- can fill the hole in the type so this term is forever incomplete.
ex4 : ∅ ⊢ ((N 3) ·: ⦇-⦈) ∘ (N 4) => ⦇-⦈
ex4 = SAp (SAsc (ASubsume SNum TCHole2)) MAHole (ASubsume SNum TCHole2)
-- this module contains small examples that demonstrate the judgements
-- and definitions in action. a few of them are directly from the paper,
-- to aid in comparision between the on-paper notation and the
-- corresponding agda syntax.
-- these smaller derivations motivate the need for the zipper rules: you
-- have to unzip down to the point of the structure where you want to
-- apply an edit, do the local edit rule, and then put it back together
-- around you
talk0 : ∅ ⊢ (▹ ⦇-⦈[ 0 ] ◃ ·+₁ ⦇-⦈[ 1 ]) => num ~ construct (numlit 7 no-hole) ~>
(▹ N 7 ◃ ·+₁ ⦇-⦈[ 1 ]) => num
talk0 = SAZipPlus1 (AASubsume EETop SEHole SAConNumlit TCRefl)
talk1 : ∅ ⊢ (·λ 0 ⦇-⦈[ 0 ] ·:₂ (▹ ⦇-⦈ ◃ ==>₁ ⦇-⦈)) => (⦇-⦈ ==> ⦇-⦈) ~ construct num ~>
(·λ 0 ⦇-⦈[ 0 ] ·:₂ (▹ num ◃ ==>₁ ⦇-⦈)) => (num ==> ⦇-⦈)
talk1 = SAZipAsc2 (TMArrZip1 TMConNum) (ETArrL ETTop) (ETArrL ETTop)
(ALam refl MAArr (ASubsume SEHole TCRefl))
-- this is similar to figure one from the paper, but with a half annotated lambda
-- rather than a lambda with a full type ascription
fig1-l : List action
fig1-l = construct (lam 0 no-hole no-hole) ::
construct num ::
move parent ::
move (child 2) ::
construct (var 0 no-hole) ::
construct (plus no-hole no-hole) ::
construct (numlit 1 no-hole) ::
[]
figure1 : runsynth ∅ ▹ ⦇-⦈[ 0 ] ◃ ⦇-⦈ fig1-l
(·λ 0 ·[ num ]₂ (X 0 ·+₂ ▹ N 1 ◃)) (num ==> num)
figure1 =
DoSynth (SAConLam refl)
(DoSynth (SAZipLam1 refl ETTop ETTop TMConNum SEHole SEHole)
(DoSynth (SAMove EMHalfLamParent1)
(DoSynth (SAMove EMHalfLamChild2)
(DoSynth (SAZipLam2 refl EETop SEHole (SAConVar refl))
(DoSynth (SAZipLam2 refl EETop (SVar refl) (SAConPlus1 TCRefl))
(DoSynth (SAZipLam2 refl (EEPlusR EETop)
(SPlus (ASubsume (SVar refl) TCRefl) (ASubsume SEHole TCHole1))
(SAZipPlus2 (AASubsume EETop SEHole SAConNumlit TCRefl))) DoRefl))))))
-- this is figure two from the paper
incr : Nat
incr = 0
fig2-l : List action
fig2-l = construct (var incr no-hole) ::
construct (ap no-hole no-hole) ::
construct (var incr 0) ::
construct (ap no-hole no-hole) ::
construct (numlit 3 no-hole) ::
move parent ::
move parent ::
finish ::
[]
figure2 : runsynth (∅ ,, (incr , num ==> num)) ▹ ⦇-⦈[ 0 ] ◃ ⦇-⦈ fig2-l
(X incr ∘₂ ▹ X incr ∘ (N 3) ◃) num
figure2 =
DoSynth (SAConVar refl)
(DoSynth (SAConApArr MAArr)
(DoSynth (SAZipApAna MAArr (SVar refl) (AAConVar (λ ()) refl))
(DoSynth (SAZipApAna MAArr (SVar refl)
(AASubsume (EENEHole EETop) (SNEHole (SVar refl))
(SAZipNEHole EETop (SVar refl) (SAConApArr MAArr)) TCHole1))
(DoSynth (SAZipApAna MAArr (SVar refl)
(AASubsume (EENEHole (EEApR EETop))
(SNEHole (SAp (SVar refl) MAArr (ASubsume SEHole TCHole1)))
(SAZipNEHole (EEApR EETop)
(SAp (SVar refl) MAArr (ASubsume SEHole TCHole1))
(SAZipApAna MAArr (SVar refl)
(AASubsume EETop SEHole SAConNumlit TCRefl)))
TCHole1))
(DoSynth (SAZipApAna MAArr (SVar refl)
(AASubsume (EENEHole (EEApR EETop))
(SNEHole (SAp (SVar refl) MAArr (ASubsume SNum TCRefl)))
(SAZipNEHole (EEApR EETop) (SAp (SVar refl) MAArr
(ASubsume SNum TCRefl)) (SAMove EMApParent2))
TCHole1))
(DoSynth (SAZipApAna MAArr (SVar refl) (AAMove EMNEHoleParent))
(DoSynth (SAZipApAna MAArr (SVar refl)
(AAFinish (ASubsume (SAp (SVar refl) MAArr (ASubsume SNum TCRefl)) TCRefl)))
DoRefl)))))))
--- this demonstrates that the other ordering discussed is also fine. it
--- results in different proof terms and actions but ultimately produces
--- the same expression. there are many other lists of actions that would
--- also work, these are just two.
fig2alt-l : List action
fig2alt-l = construct (var incr no-hole) ::
construct (ap no-hole 0) ::
construct (ap no-hole 1) ::
construct (numlit 3 no-hole) ::
move parent ::
move (child 1) ::
construct (var incr no-hole) ::
move parent ::
[]
figure2alt : runsynth (∅ ,, (incr , num ==> num)) ▹ ⦇-⦈[ 0 ] ◃ ⦇-⦈ fig2alt-l
(X incr ∘₂ ▹ X incr ∘ (N 3) ◃) num
figure2alt =
DoSynth (SAConVar refl)
(DoSynth (SAConApArr MAArr)
(DoSynth (SAZipApAna MAArr (SVar refl)
(AASubsume EETop SEHole (SAConApArr MAHole) TCHole1))
(DoSynth (SAZipApAna MAArr (SVar refl) (AASubsume (EEApR EETop)
(SAp SEHole MAHole (ASubsume SEHole TCRefl))
(SAZipApAna MAHole SEHole (AASubsume EETop SEHole SAConNumlit TCHole2)) TCHole1))
(DoSynth (SAZipApAna MAArr (SVar refl) (AAMove EMApParent2))
(DoSynth (SAZipApAna MAArr (SVar refl) (AAMove EMApChild1))
(DoSynth (SAZipApAna MAArr (SVar refl) (AASubsume (EEApL EETop)
(SAp SEHole MAHole (ASubsume SNum TCHole2))
(SAZipApArr MAArr EETop SEHole (SAConVar refl) (ASubsume SNum TCRefl)) TCRefl))
(DoSynth (SAZipApAna MAArr (SVar refl) (AAMove EMApParent1))
DoRefl)))))))
-- these motivate why actions aren't deterministic, and why it's
-- reasonable to ban the derivations that we do. the things that differ
-- in the term as a result of the appeal to subsumption in the second
-- derivation aren't needed -- the ascription is redundant because the
-- type is already pinned to num, so that's the only thing that
-- could fill the holes produced.
notdet1A : ∅ ⊢ ▹ ⦇-⦈[ 0 ] ◃ ~ construct asc ~> ⦇-⦈[ 0 ] ·:₂ ▹ num ◃ ⇐ num
notdet1A = AAConAsc
notdet1B : ∅ ⊢ ▹ ⦇-⦈[ 0 ] ◃ ~ construct asc ~> ⦇-⦈[ 0 ] ·:₂ ▹ ⦇-⦈ ◃ ⇐ num
notdet1B = AASubsume EETop SEHole SAConAsc TCHole1
| {
"alphanum_fraction": 0.5833835765,
"avg_line_length": 44.1117021277,
"ext": "agda",
"hexsha": "ae003f66bc106b73cc170468bb8b63fd599bb78f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "examples.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "examples.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2854,
"size": 8293
} |
module 050-group where
-- We need monoids.
open import 040-monoid
-- A group is a monoid where every element has an inverse. This is
-- equivalent to saying that we have a function mapping every element
-- to an inverse of that element: this function is called "invert"
-- below.
record Group
{M : Set}
(_==_ : M -> M -> Set)
(_*_ : M -> M -> M)
(id : M)
(invert : M -> M)
: Set1 where
field
monoid : Monoid _==_ _*_ id
icong : ∀ {r s} -> (r == s) -> (invert r) == (invert s)
r*ir==id : ∀ {r} -> (r * (invert r)) == id
ir*r==id : ∀ {r} -> ((invert r) * r) == id
open Monoid monoid public
-- Trivial but useful equalities.
id==r*ir : ∀ {r} -> id == (r * (invert r))
id==r*ir = symm r*ir==id
id==ir*r : ∀ {r} -> id == ((invert r) * r)
id==ir*r = symm ir*r==id
-- Double inverse gets back original.
iir==r : ∀ {r} -> (invert (invert r)) == r
iir==r {r} = trans3 iir==r*ir*iir r*ir*iir==r*id r*id==r
where iir==r*ir*iir :
(invert (invert r)) == (r * ((invert r) * (invert (invert r))))
iir==r*ir*iir = trans3 r==id*r (cong id==r*ir refl) assoc
-- assoc {r} {ir} {iir} : (r * ir) * iir == r * (ir * iir)
-- id==r*ir : id == r * ir
-- cong % (refl {iir}) : id * iir == (r * ir) * iir
-- id*r==r {iir} : iir == id * iir
-- trans3 % %% %%%% : iir == r * (ir * iir)
r*ir*iir==r*id : (r * ((invert r) * (invert (invert r)))) == (r * id)
r*ir*iir==r*id = cong refl r*ir==id
-- Uniqueness of (left and right) inverse.
irleftunique : ∀ {r} -> ∀ {s} -> (s * r) == id -> s == (invert r)
irleftunique {r} {s} s*r==id = trans (symm s*r*ir==s) (s*r*ir==ir)
where s*r*ir==ir : ((s * r) * (invert r)) == (invert r)
s*r*ir==ir = trans (cong s*r==id refl) id*r==r
s*r*ir==s : ((s * r) * (invert r)) == s
s*r*ir==s = trans3 assoc (cong refl r*ir==id) r*id==r
irrightunique : ∀ {r} -> ∀ {s} -> (r * s) == id -> s == (invert r)
irrightunique {r} {s} r*s==id = trans (symm ir*r*s==s) (ir*r*s==ir)
where ir*r*s==ir : ((invert r) * (r * s)) == (invert r)
ir*r*s==ir = trans (cong refl r*s==id) r*id==r
ir*r*s==s : ((invert r) * (r * s)) == s
ir*r*s==s = trans3 (symm assoc) (cong ir*r==id refl) id*r==r
| {
"alphanum_fraction": 0.4804804805,
"avg_line_length": 38.85,
"ext": "agda",
"hexsha": "0a3a413faca02b54677ec1754d3fed592e98a988",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mcmtroffaes/agda-proofs",
"max_forks_repo_path": "050-group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mcmtroffaes/agda-proofs",
"max_issues_repo_path": "050-group.agda",
"max_line_length": 79,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mcmtroffaes/agda-proofs",
"max_stars_repo_path": "050-group.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-17T16:15:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-09T22:51:55.000Z",
"num_tokens": 900,
"size": 2331
} |
------------------------------------------------------------------------------
-- Some properties of the function iter₀
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Iter0.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.PropertiesI
open import FOTC.Base.List
open import FOTC.Data.List.PropertiesI
open import FOTC.Data.Nat.Type
open import FOTC.Data.Nat.List.Type
open import FOTC.Program.Iter0.Iter0
------------------------------------------------------------------------------
iter₀-0 : ∀ f → iter₀ f zero ≡ []
iter₀-0 f =
iter₀ f zero
≡⟨ iter₀-eq f zero ⟩
(if (iszero₁ zero) then [] else (zero ∷ iter₀ f (f · zero)))
≡⟨ ifCong₁ iszero-0 ⟩
(if true then [] else (zero ∷ iter₀ f (f · zero)))
≡⟨ if-true [] ⟩
[] ∎
| {
"alphanum_fraction": 0.496124031,
"avg_line_length": 31.2727272727,
"ext": "agda",
"hexsha": "490dcbc9d2ea76160838b3e34295e6d8b4627209",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/Iter0/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/Iter0/PropertiesI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/Iter0/PropertiesI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 253,
"size": 1032
} |
{-# OPTIONS --without-K #-}
{- After a few preliminary lemmata about representing dependent functions,
this module will derive the dependent universal property of
our truncations (defined later) from the non-dependent one. -}
module Universe.Trunc.Universal where
open import lib.Basics
open import lib.Equivalences2
open import lib.NType2
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.Unit
open import Universe.Utility.General
open import Universe.Utility.TruncUniverse
-- In the fibration fst : Σ A B → A, the fiber over a is given by B a.
trivial-fibers : ∀ {i j} {A : Type i} {B : A → Type j} (a : A)
→ B a ≃ Σ (Σ A B) (λ s → a == fst s)
trivial-fibers {A = A} {B} a =
B a ≃⟨ Σ₁-Unit ⁻¹ ⟩
Σ ⊤ (λ _ → B a) ≃⟨ equiv-Σ-fst _ (snd (e ⁻¹)) ⟩
Σ (Σ A (λ s → a == s)) (B ∘ fst) ≃⟨ Σ-comm-snd ⟩
Σ (Σ A B) (λ s → a == fst s) ≃∎ where
e : Σ A (λ s → a == s) ≃ ⊤
e = contr-equiv-Unit (pathfrom-is-contr a)
{- Liftings of u : Π A B through fst : {a : A} → Σ (B a) (C a) → B a
correponds to dependent functions from (a : A) to C a (u a).
As mentioned in the article, we will make use only of a special case:
liftings of u : A → B through fst : Σ B C → B correponds to
dependent functions from (a : A) to C a. -}
Π-as-liftings : ∀ {i j k} {A : Type i} {B : A → Type j}
(u : Π A B) {C : (a : A) → B a → Type k} → _
Π-as-liftings {A = A} {B} u {C} =
Π A (λ a → C a (u a))
≃⟨ trivial-fibers u ⟩
Σ (Σ (Π A B) (λ r → Π A (λ a → C a (r a)))) (λ {(r , _) → u == r})
≃⟨ equiv-Σ-fst _ (snd choice) ⁻¹ ⟩
Σ (Π A (λ a → Σ (B a) (C a))) (λ s → u == fst ∘ s)
≃∎
{- Dependent functions from (a : A) to B a
are given by sections of fst : Σ A B → A.
Noting that sections are non-dependent functions, this folklore insight
is a main ingredient in passing from non-dependent universal property
to the dependent one. -}
Π-as-sections : ∀ {i j} {A : Type i} {B : A → Type j}
→ Π A B ≃ Σ (A → Σ A B) (λ s → idf _ == fst ∘ s)
Π-as-sections = Π-as-liftings (idf _)
{- Fix a truncation level n and a Type A. We will examine what it means
for an n-type 'type' with constructor cons : A → ⟦ type ⟧
to have the universal property of the n-truncation of A. -}
module _ {i} {n : ℕ₋₂} {A : Type i}
(type : n -Type i) (cons : A → ⟦ type ⟧) where
-- *** Definition 6.2 ***
{- The (non-dependent) universal property:
λ f → f ∘ cons induces equivalence (type → X) ≃ (A → X) -}
univ-Type : ∀ (k : ULevel) → Type (i ⊔ lsucc k)
univ-Type k = (X : n -Type k) → is-equiv
{A = ⟦ type ⟧ → ⟦ X ⟧}
{B = A → ⟦ X ⟧}
(λ f → f ∘ cons)
{- The dependent universal property:
λ f → f ∘ cons induces ((a : type) → X a) ≃ ((a : A) → X (cons a)) -}
duniv-Type : ∀ (k : ULevel) → Type (i ⊔ lsucc k)
duniv-Type k = (X : ⟦ type ⟧ → n -Type k) → is-equiv
{A = Π ⟦ type ⟧ (⟦_⟧ ∘ X )}
{B = Π A (⟦_⟧ ∘ X ∘ cons)}
(λ f → f ∘ cons)
{- If the universal property holds for a certain elimination universe U_j₂,
then also for an elimination universe U_j₁ with j₁ ≤ j₂.
Agda does not support specifying ordering relations between
universe levels directly, but we may simulate j₁ ≤ j₂
by decomposing j₁ = k₁ and j₂ = k₁ ⊔ k₂. -}
univ-lower : ∀ {k₁} (k₂ : ULevel) → univ-Type (k₁ ⊔ k₂) → univ-Type k₁
univ-lower {k₁} k₂ univ X = transport (λ z → is-equiv (λ f → z ∘ f ∘ cons))
(λ= (<–-inv-r e)) hup where
e : Lift {j = k₁ ⊔ k₂} ⟦ X ⟧ ≃ ⟦ X ⟧
e = lift-equiv
hup : is-equiv (λ f → –> e ∘ <– e ∘ f ∘ cons)
hup = pre∘-is-equiv (snd e)
∘ise univ (Lift-≤ X)
∘ise pre∘-is-equiv (snd (e ⁻¹))
-- *** Lemma 6.6 ***
{- We will now prove the main lemma of this section:
The (non-dependent) universal property implies the dependent one. -}
module with-univ {j} (univ : univ-Type (i ⊔ j)) (P : ⟦ type ⟧ → n -Type j) where
-- abbreviating the underlying types (for readability)
T = ⟦ type ⟧
Q = ⟦_⟧ ∘ P
{- As is usual for deriving dependent eliminators, the crux for deriving
the dependent universal property is to first transform the *dependent*
function spaces into *non-dependent* sections/liftings according to
the lemmata above. -}
eqv : Π T Q ≃ Π A (Q ∘ cons)
eqv = Π-as-liftings cons ⁻¹ ∘e eqv-liftings ∘e Π-as-liftings (idf _) where
{- Our goal now is an equivalence of Σ-types where the first components
fit the template of the *non-dependent* universal property. -}
eqv-liftings : Σ (T → Σ T Q) (λ s → idf _ == fst ∘ s)
≃ Σ (A → Σ T Q) (λ t → cons == fst ∘ t)
eqv-liftings = equiv-Σ' (_ , univ (Σ-≤ type P)) lem where
{- What remains is just the universal property applied to X itself,
and then switching to path spaces. In the usual derivation of
dependent elimination, this corresponds to application of
the η-rule to the identity function. -}
lem : (s : T → Σ T Q) → (idf _ == fst ∘ s) ≃ (cons == fst ∘ s ∘ cons)
lem s = equiv-ap (_ , univ-lower (i ⊔ j) univ type) (idf _) (fst ∘ s)
{- Due to construction of the above equivalence via conjugation of
the (non-dependent) universal property (on the first component),
its action ends up being precisely composition with the constructor.
Because of technical limitations of the Agda type-checker,
we encapsulate the result in an abstract block to prevent
the type checker from unnecessarily unfolding its value later on. -}
abstract
duniv : is-equiv (λ (f : ⟦ Π-≤ ⟦ type ⟧ P ⟧) → f ∘ cons)
duniv = snd eqv
| {
"alphanum_fraction": 0.567008547,
"avg_line_length": 43.6567164179,
"ext": "agda",
"hexsha": "72343d2b0e96c2917e74d8396c4da706d4a6ea9f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sattlerc/HoTT-Agda",
"max_forks_repo_path": "Universe/Trunc/Universal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "sattlerc/HoTT-Agda",
"max_issues_repo_path": "Universe/Trunc/Universal.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sattlerc/HoTT-Agda",
"max_stars_repo_path": "Universe/Trunc/Universal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1995,
"size": 5850
} |
-- notes-03-wednesday.agda
open import mylib
{-
Classical vs intuitionistic logic
In classical logica, we assume that each proposition is either true or false.
Excluded middle, tertium non datur (the third is not given).
To prove P, assume not P and derive a contradiction: indirect proof, reduction
ad absurdum, reduction to the absurd.
-}
TND : prop → prop
TND P = P ∨ ¬ P
deMorgan' : TND P → ¬ (P ∧ Q) ⇔ ¬ P ∨ ¬ Q
proj₁ (deMorgan' (inj₁ p)) h = inj₂ (λ q → h (p , q))
proj₁ (deMorgan' (inj₂ np)) h = inj₁ np
proj₂ (deMorgan' tnd) (inj₁ np) (p , q) = np p
proj₂ (deMorgan' _) (inj₂ nq) (p , q) = nq q
RAA : prop → prop
RAA P = ¬ ¬ P → P
tnd→raa : TND P → RAA P
tnd→raa (inj₁ p) nnp = p
tnd→raa (inj₂ np) nnp = case⊥ (nnp np)
{-
raa→tnd : RAA P → TND P
is not provable.
-}
nntnd : ¬ ¬ (P ∨ ¬ P)
nntnd h = h (inj₂ (λ p → h (inj₁ p)))
raa→tnd : ({P : prop} → RAA P) → {Q : prop} → TND Q
raa→tnd raa = raa nntnd
{-
Datatypes, infinite types
ℕ - natural numbers, Peano
Every natural number is either 0 or a successor of a number.
Peano arithmetic.
-}
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
one : ℕ
one = suc zero
two : ℕ
two = suc one
{-# BUILTIN NATURAL ℕ #-}
fifteen : ℕ
fifteen = 15
infixl 2 _+_
_+_ : ℕ → ℕ → ℕ -- structural recursive definition
zero + n = n
suc m + n = suc (m + n)
infixl 4 _*_
_*_ : ℕ → ℕ → ℕ
zero * n = 0
suc m * n = m * n + n
data List (A : Set) : Set where
[] : List A -- nil
_∷_ : A → List A → List A -- cons
-- ℕ = List ⊤
_++_ : List A → List A → List A -- append
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
-- _++'_ : List A \to List B \to List (A \vee B)?
-- recursive but not inductive
{-# NO_POSITIVITY_CHECK #-}
data Λ : Set where
lam : (Λ → Λ) → Λ
app : Λ → Λ → Λ
app (lam f) x = f x
self-apply : Λ
self-apply = lam λ x → app x x
Ω : Λ
Ω = app self-apply self-apply
-- normalisation doesn't terminate
data Ord : Set where
zero : Ord
suc : Ord → Ord
lim : (ℕ → Ord) → Ord
-- strictly positive
{-# NO_POSITIVITY_CHECK #-}
data Reynolds : Set where
inn : ((Reynolds → Bool) → Bool) → Reynolds
{-
Inconsistent with classical logic
It doesn't adhere to the intuitionistic explanation of inductive datatypes.
Hence we reject types like this.
- strictly positive = recursive type only appears on the right of an arrow
type.
- strictly positive = container / polynomial functors.
-}
| {
"alphanum_fraction": 0.6122022566,
"avg_line_length": 20.1092436975,
"ext": "agda",
"hexsha": "a4bfe0de1281a41609ed6bc52b19445d7482897e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FoxySeta/mgs-2021",
"max_forks_repo_path": "Type Theory/notes-03-wednesday.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534",
"max_issues_repo_issues_event_max_datetime": "2021-07-14T20:35:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-07-14T20:34:53.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "FoxySeta/mgs-2021",
"max_issues_repo_path": "Type Theory/notes-03-wednesday.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FoxySeta/mgs-2021",
"max_stars_repo_path": "Type Theory/notes-03-wednesday.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 892,
"size": 2393
} |
------------------------------------------------------------------------
-- Substitutions
------------------------------------------------------------------------
module RecursiveTypes.Substitution where
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
import Data.Fin.Substitution.List as ListSubst
open import Data.Nat
open import Data.List
open import Data.Vec as Vec
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl; sym; cong₂)
open PropEq.≡-Reasoning
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
using (Star; ε; _◅_; _▻_)
open import RecursiveTypes.Syntax
-- Code for applying substitutions.
module TyApp {T : ℕ → Set} (l : Lift T Ty) where
open Lift l hiding (var)
-- Applies a substitution to a recursive type.
infixl 8 _/_
_/_ : ∀ {m n} → Ty m → Sub T m n → Ty n
⊥ / ρ = ⊥
⊤ / ρ = ⊤
var x / ρ = lift (Vec.lookup ρ x)
σ ⟶ τ / ρ = (σ / ρ) ⟶ (τ / ρ)
μ σ ⟶ τ / ρ = μ (σ / ρ ↑) ⟶ (τ / ρ ↑)
open Application (record { _/_ = _/_ }) using (_/✶_)
-- Some lemmas about _/_.
⊥-/✶-↑✶ : ∀ k {m n} (ρs : Subs T m n) → ⊥ /✶ ρs ↑✶ k ≡ ⊥
⊥-/✶-↑✶ k ε = refl
⊥-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (⊥-/✶-↑✶ k ρs) refl
⊤-/✶-↑✶ : ∀ k {m n} (ρs : Subs T m n) → ⊤ /✶ ρs ↑✶ k ≡ ⊤
⊤-/✶-↑✶ k ε = refl
⊤-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (⊤-/✶-↑✶ k ρs) refl
⟶-/✶-↑✶ : ∀ k {m n σ τ} (ρs : Subs T m n) →
σ ⟶ τ /✶ ρs ↑✶ k ≡ (σ /✶ ρs ↑✶ k) ⟶ (τ /✶ ρs ↑✶ k)
⟶-/✶-↑✶ k ε = refl
⟶-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (⟶-/✶-↑✶ k ρs) refl
μ⟶-/✶-↑✶ : ∀ k {m n σ τ} (ρs : Subs T m n) →
μ σ ⟶ τ /✶ ρs ↑✶ k ≡
μ (σ /✶ ρs ↑✶ suc k) ⟶ (τ /✶ ρs ↑✶ suc k)
μ⟶-/✶-↑✶ k ε = refl
μ⟶-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (μ⟶-/✶-↑✶ k ρs) refl
tySubst : TermSubst Ty
tySubst = record { var = var; app = TyApp._/_ }
open TermSubst tySubst hiding (var)
-- σ [0≔ τ ] replaces all occurrences of variable 0 in σ with τ.
infix 8 _[0≔_]
_[0≔_] : ∀ {n} → Ty (suc n) → Ty n → Ty n
σ [0≔ τ ] = σ / sub τ
-- The unfolding of a fixpoint.
unfold[μ_⟶_] : ∀ {n} → Ty (suc n) → Ty (suc n) → Ty n
unfold[μ σ ⟶ τ ] = σ ⟶ τ [0≔ μ σ ⟶ τ ]
-- Substitution lemmas.
tyLemmas : TermLemmas Ty
tyLemmas = record
{ termSubst = tySubst
; app-var = refl
; /✶-↑✶ = Lemma./✶-↑✶
}
where
module Lemma {T₁ T₂} {lift₁ : Lift T₁ Ty} {lift₂ : Lift T₂ Ty} where
open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_)
open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_)
/✶-↑✶ : ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) →
∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k
/✶-↑✶ ρs₁ ρs₂ hyp k ⊥ = begin
⊥ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TyApp.⊥-/✶-↑✶ _ k ρs₁ ⟩
⊥ ≡⟨ sym (TyApp.⊥-/✶-↑✶ _ k ρs₂) ⟩
⊥ /✶₂ ρs₂ ↑✶₂ k ∎
/✶-↑✶ ρs₁ ρs₂ hyp k ⊤ = begin
⊤ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TyApp.⊤-/✶-↑✶ _ k ρs₁ ⟩
⊤ ≡⟨ sym (TyApp.⊤-/✶-↑✶ _ k ρs₂) ⟩
⊤ /✶₂ ρs₂ ↑✶₂ k ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (var x) = hyp k x
/✶-↑✶ ρs₁ ρs₂ hyp k (σ ⟶ τ) = begin
σ ⟶ τ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TyApp.⟶-/✶-↑✶ _ k ρs₁ ⟩
(σ /✶₁ ρs₁ ↑✶₁ k) ⟶ (τ /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _⟶_ (/✶-↑✶ ρs₁ ρs₂ hyp k σ)
(/✶-↑✶ ρs₁ ρs₂ hyp k τ) ⟩
(σ /✶₂ ρs₂ ↑✶₂ k) ⟶ (τ /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (TyApp.⟶-/✶-↑✶ _ k ρs₂) ⟩
σ ⟶ τ /✶₂ ρs₂ ↑✶₂ k ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (μ σ ⟶ τ) = begin
μ σ ⟶ τ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TyApp.μ⟶-/✶-↑✶ _ k ρs₁ ⟩
μ (σ /✶₁ ρs₁ ↑✶₁ suc k) ⟶ (τ /✶₁ ρs₁ ↑✶₁ suc k) ≡⟨ cong₂ μ_⟶_ (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) σ)
(/✶-↑✶ ρs₁ ρs₂ hyp (suc k) τ) ⟩
μ (σ /✶₂ ρs₂ ↑✶₂ suc k) ⟶ (τ /✶₂ ρs₂ ↑✶₂ suc k) ≡⟨ sym (TyApp.μ⟶-/✶-↑✶ _ k ρs₂) ⟩
μ σ ⟶ τ /✶₂ ρs₂ ↑✶₂ k ∎
open TermLemmas tyLemmas public hiding (var)
module // where
private
open module LS = ListSubst lemmas₄ public hiding (_//_)
-- _//_ is redefined in order to make it bind weaker than
-- RecursiveTypes.Subterm._∗, which binds weaker than _/_.
infixl 6 _//_
_//_ : ∀ {m n} → List (Ty m) → Sub Ty m n → List (Ty n)
_//_ = LS._//_
| {
"alphanum_fraction": 0.4418228082,
"avg_line_length": 33.2538461538,
"ext": "agda",
"hexsha": "279c86d5c3656f9bac63e0f6c7039786e45734f2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "RecursiveTypes/Substitution.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "RecursiveTypes/Substitution.agda",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "RecursiveTypes/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 2148,
"size": 4323
} |
-- A tactic that applies congruence and symmetry of equality proofs.
-- Given a hole and a lemma it tries (in order)
-- - refl
-- - lemma
-- - sym lemma
-- - f $≡ X₁ *≡ .. *≡ Xₙ and recurses on Xᵢ
-- if the goal is f us ≡ f vs
-- Hidden and instance arguments of f are left alone.
module Tactic.Cong where
open import Prelude
open import Container.Traversable
open import Tactic.Reflection
private
refl′ : ∀ {a} {A : Set a} (x : A) → x ≡ x
refl′ _ = refl
pattern `refl a = def₁ (quote refl′) a
parseEq : Term → Maybe (Term × Term)
parseEq (def (quote _≡_) (hArg _ ∷ hArg _ ∷ vArg x ∷ vArg y ∷ [])) = just (x , y)
parseEq _ = nothing
-- build-cong f ps = f $≡ p₁ *≡ .. *≡ pₙ
build-cong : Term → List Term → Term
build-cong f [] = `refl unknown -- we tried this
build-cong f (p ∷ ps) = foldl ap (def₂ (quote cong) f p) ps
where
ap = λ p q → def₂ (quote _*≡_) p q
zipWithM!₃ : {A B C : Set} → (A → B → C → TC ⊤) → List A → List B → List C → TC ⊤
zipWithM!₃ f (x ∷ xs) (y ∷ ys) (z ∷ zs) = f x y z *> zipWithM!₃ f xs ys zs
zipWithM!₃ _ _ _ _ = pure _
module _ (lemma : Term) where
go go-cong : (d : Nat) (lhs rhs hole : Term) → TC ⊤
go d lhs rhs hole =
checkType hole (def₂ (quote _≡_) lhs rhs) *>
( unify hole (`refl lhs)
<|> unify hole lemma
<|> unify hole (def₁ (quote sym) lemma)
<|> go-cong d lhs rhs hole
<|> do lhs ← reduce lhs
rhs ← reduce rhs
go-cong d lhs rhs hole)
solve : (d : Nat) (hole : Term) → TC ⊤
solve d hole =
caseM parseEq <$> (reduce =<< inferType hole) of λ where
nothing → typeErrorS "Goal is not an equality type."
(just (lhs , rhs)) → go d lhs rhs hole
go-cong′ : ∀ d f us vs hole → TC ⊤
go-cong′ d f us vs hole = do
let us₁ = map unArg (filter isVisible us)
vs₁ = map unArg (filter isVisible vs)
holes ← traverse (const newMeta!) us₁
zipWithM!₃ (go d) us₁ vs₁ holes
unify hole (build-cong f holes)
go-cong (suc d) (def f us) (def f₁ vs) hole = guard (f == f₁) (go-cong′ d (def₀ f) us vs hole)
go-cong (suc d) (con c us) (con c₁ vs) hole = guard (c == c₁) (go-cong′ d (con₀ c) us vs hole)
go-cong (suc d) (var x us) (var x₁ vs) hole = guard (x == x₁) (go-cong′ d (var₀ x) us vs hole)
go-cong _ lhs rhs _ = empty
macro
by-cong : ∀ {a} {A : Set a} {x y : A} → x ≡ y → Tactic
by-cong {x = x} {y} lemma hole = do
`lemma ← quoteTC lemma
ensureNoMetas =<< inferType hole
lemMeta ← lemProxy `lemma
solve lemMeta 100 hole <|> typeErrorS "Congruence failed"
unify lemMeta `lemma
where
-- Create a meta for the lemma to avoid retype-checking it in case
-- it's expensive. Don't do this if the lemma is a variable.
lemProxy : Term → TC Term
lemProxy lemma@(var _ []) = pure lemma
lemProxy lemma = newMeta =<< quoteTC (x ≡ y)
| {
"alphanum_fraction": 0.5735243944,
"avg_line_length": 35.313253012,
"ext": "agda",
"hexsha": "52e962e1dae80ccc9a38d75c3bc04d689d79daca",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Tactic/Cong.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Tactic/Cong.agda",
"max_line_length": 98,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Tactic/Cong.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 1039,
"size": 2931
} |
------------------------------------------------------------------------
-- A definitional interpreter
------------------------------------------------------------------------
{-# OPTIONS --cubical --sized-types #-}
module Lambda.Partiality-monad.Inductive.Interpreter where
open import Equality.Propositional.Cubical
open import Prelude hiding (⊥)
open import Bijection equality-with-J using (_↔_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import Maybe equality-with-J
open import Monad equality-with-J
open import Vec.Function equality-with-J
open import Partiality-monad.Inductive
open import Partiality-monad.Inductive.Fixpoints
open import Partiality-monad.Inductive.Monad
open import Lambda.Syntax hiding ([_])
open Closure Tm
------------------------------------------------------------------------
-- An interpreter monad
-- The interpreter monad.
M : ∀ {ℓ} → Type ℓ → Type ℓ
M = MaybeT _⊥
-- Information ordering.
infix 4 _⊑M_
_⊑M_ : ∀ {a} {A : Type a} → M A → M A → Type a
x ⊑M y = run x ⊑ run y
-- Bind is monotone.
_>>=ᵐ-mono_ :
∀ {ℓ} {A B : Type ℓ} {x y : M A} {f g : A → M B} →
x ⊑M y → (∀ z → f z ⊑M g z) → x >>= f ⊑M y >>= g
_>>=ᵐ-mono_ {x = x} {y} {f} {g} x⊑y f⊑g =
run x >>= maybe (MaybeT.run ∘ f) (return nothing) ⊑⟨ x⊑y >>=-mono maybe f⊑g (run fail ■) ⟩■
run y >>= maybe (MaybeT.run ∘ g) (return nothing) ■
-- A variant of bind for sequences.
infix 5 _>>=ˢ_
_>>=ˢ_ : {A B : Type} →
Increasing-sequence (Maybe A) →
(A → Increasing-sequence (Maybe B)) →
Increasing-sequence (Maybe B)
s >>=ˢ f =
(λ n → MaybeT.run (wrap (s [ n ]) >>= λ x → wrap (f x [ n ])))
, (λ n → increasing s n >>=ᵐ-mono λ x → increasing (f x) n)
------------------------------------------------------------------------
-- One interpreter
module Interpreter₁ where
-- This interpreter is defined as the least upper bound of a
-- sequence of increasingly defined interpreters.
infix 10 _∙_
mutual
⟦_⟧′ : ∀ {n} → Tm n → Env n → ℕ → M Value
⟦ con i ⟧′ ρ n = return (con i)
⟦ var x ⟧′ ρ n = return (ρ x)
⟦ ƛ t ⟧′ ρ n = return (ƛ t ρ)
⟦ t₁ · t₂ ⟧′ ρ n = ⟦ t₁ ⟧′ ρ n >>= λ v₁ →
⟦ t₂ ⟧′ ρ n >>= λ v₂ →
(v₁ ∙ v₂) n
_∙_ : Value → Value → ℕ → M Value
(con i ∙ v₂) n = fail
(ƛ t₁ ρ ∙ v₂) zero = liftʳ never
(ƛ t₁ ρ ∙ v₂) (suc n) = ⟦ t₁ ⟧′ (cons v₂ ρ) n
mutual
⟦⟧′-increasing :
∀ {n} (t : Tm n) ρ n → ⟦ t ⟧′ ρ n ⊑M ⟦ t ⟧′ ρ (suc n)
⟦⟧′-increasing (con i) ρ n = MaybeT.run (return (con i)) ■
⟦⟧′-increasing (var x) ρ n = MaybeT.run (return (ρ x)) ■
⟦⟧′-increasing (ƛ t) ρ n = MaybeT.run (return (ƛ t ρ)) ■
⟦⟧′-increasing (t₁ · t₂) ρ n =
⟦⟧′-increasing t₁ ρ n >>=ᵐ-mono λ v₁ →
⟦⟧′-increasing t₂ ρ n >>=ᵐ-mono λ v₂ →
∙-increasing v₁ v₂ n
∙-increasing : ∀ v₁ v₂ n → (v₁ ∙ v₂) n ⊑M (v₁ ∙ v₂) (suc n)
∙-increasing (con i) v₂ n = run fail ■
∙-increasing (ƛ t₁ ρ) v₂ (suc n) = ⟦⟧′-increasing t₁ (cons v₂ ρ) n
∙-increasing (ƛ t₁ ρ) v₂ zero =
never >>= return ∘ just ≡⟨ never->>= ⟩⊑
never ⊑⟨ never⊑ _ ⟩■
run (⟦ t₁ ⟧′ (cons v₂ ρ) 0) ■
⟦_⟧ˢ : ∀ {n} → Tm n → Env n → Increasing-sequence (Maybe Value)
⟦ t ⟧ˢ ρ = MaybeT.run ∘ ⟦ t ⟧′ ρ , ⟦⟧′-increasing t ρ
⟦_⟧ : ∀ {n} → Tm n → Env n → M Value
run (⟦ t ⟧ ρ) = ⨆ (⟦ t ⟧ˢ ρ)
------------------------------------------------------------------------
-- Another interpreter
module Interpreter₂ where
-- This interpreter is defined using a fixpoint combinator.
M′ : Type → Type₁
M′ = MaybeT (Partial (∃ λ n → Tm n × Env n) (λ _ → Maybe Value))
infix 10 _∙_
_∙_ : Value → Value → M′ Value
con i ∙ v₂ = fail
ƛ t₁ ρ ∙ v₂ = wrap (rec (_ , t₁ , cons v₂ ρ))
⟦_⟧′ : ∀ {n} → Tm n → Env n → M′ Value
⟦ con i ⟧′ ρ = return (con i)
⟦ var x ⟧′ ρ = return (ρ x)
⟦ ƛ t ⟧′ ρ = return (ƛ t ρ)
⟦ t₁ · t₂ ⟧′ ρ = ⟦ t₁ ⟧′ ρ >>= λ v₁ →
⟦ t₂ ⟧′ ρ >>= λ v₂ →
v₁ ∙ v₂
⟦_⟧ : ∀ {n} → Tm n → Env n → M Value
run (⟦ t ⟧ ρ) =
fixP {A = ∃ λ n → Tm n × Env n}
(λ { (_ , t , ρ) → run (⟦ t ⟧′ ρ) }) (_ , t , ρ)
------------------------------------------------------------------------
-- The two interpreters are pointwise equal
interpreters-equal :
∀ {n} (t : Tm n) ρ →
Interpreter₁.⟦ t ⟧ ρ ≡ Interpreter₂.⟦ t ⟧ ρ
interpreters-equal = λ t ρ →
$⟨ ⟦⟧-lemma t ρ ⟩
(∀ n → run (Interpreter₁.⟦ t ⟧′ ρ n) ≡
app→ step₂ (suc n) (_ , t , ρ)) ↝⟨ cong ⨆ ∘ _↔_.to equality-characterisation-increasing ⟩
⨆ (Interpreter₁.⟦ t ⟧ˢ ρ) ≡
⨆ (tailˢ (at (fix→-sequence step₂) (_ , t , ρ))) ↝⟨ flip trans (⨆tail≡⨆ _) ⟩
⨆ (Interpreter₁.⟦ t ⟧ˢ ρ) ≡
⨆ (at (fix→-sequence step₂) (_ , t , ρ)) ↝⟨ id ⟩
run (Interpreter₁.⟦ t ⟧ ρ) ≡ run (Interpreter₂.⟦ t ⟧ ρ) ↝⟨ cong wrap ⟩□
Interpreter₁.⟦ t ⟧ ρ ≡ Interpreter₂.⟦ t ⟧ ρ □
where
open Partial
open Trans-⊑
step₂ : Trans-⊑ (∃ λ n → Tm n × Env n) (λ _ → Maybe Value)
step₂ = transformer λ { (_ , t , ρ) → run (Interpreter₂.⟦ t ⟧′ ρ) }
mutual
⟦⟧-lemma :
∀ {n} (t : Tm n) ρ n →
run (Interpreter₁.⟦ t ⟧′ ρ n) ≡
function (run (Interpreter₂.⟦ t ⟧′ ρ)) (app→ step₂ n)
⟦⟧-lemma (con i) ρ n = refl
⟦⟧-lemma (var x) ρ n = refl
⟦⟧-lemma (ƛ t) ρ n = refl
⟦⟧-lemma (t₁ · t₂) ρ n =
cong₂ _>>=_ (⟦⟧-lemma t₁ ρ n) $ ⟨ext⟩ $ flip maybe refl λ v₁ →
cong₂ _>>=_ (⟦⟧-lemma t₂ ρ n) $ ⟨ext⟩ $ flip maybe refl λ v₂ →
∙-lemma v₁ v₂ n
∙-lemma :
∀ v₁ v₂ n →
run ((v₁ Interpreter₁.∙ v₂) n) ≡
function (run (v₁ Interpreter₂.∙ v₂)) (app→ step₂ n)
∙-lemma (con i) v₂ n = refl
∙-lemma (ƛ t₁ ρ) v₂ zero = never >>= return ∘ just ≡⟨ never->>= ⟩∎
never ∎
∙-lemma (ƛ t₁ ρ) v₂ (suc n) = ⟦⟧-lemma t₁ (cons v₂ ρ) n
-- Let us use Interpreter₁ as the default interpreter.
open Interpreter₁ public
------------------------------------------------------------------------
-- An example
-- The semantics of Ω is the non-terminating computation never.
Ω-loops : run (⟦ Ω ⟧ nil) ≡ never
Ω-loops =
antisymmetry (least-upper-bound _ _ lemma) (never⊑ _)
where
ω-nil = ƛ (var fzero · var fzero) nil
reduce-twice :
∀ n → run (⟦ Ω ⟧′ nil n) ≡ run ((ω-nil ∙ ω-nil) n)
reduce-twice n =
run (⟦ Ω ⟧′ nil n) ≡⟨ now->>= ⟩
run (⟦ ω ⟧′ nil n >>= λ v₂ → (ω-nil ∙ v₂) n) ≡⟨ now->>= ⟩∎
run ((ω-nil ∙ ω-nil) n) ∎
lemma : ∀ n → run (⟦ Ω ⟧′ nil n) ⊑ never
lemma zero =
run (⟦ Ω ⟧′ nil zero) ≡⟨ reduce-twice zero ⟩⊑
run ((ω-nil ∙ ω-nil) zero) ≡⟨ never->>= ⟩⊑
never ■
lemma (suc n) =
run (⟦ Ω ⟧′ nil (suc n)) ≡⟨ reduce-twice (suc n) ⟩⊑
run (⟦ Ω ⟧′ nil n) ⊑⟨ lemma n ⟩■
never ■
| {
"alphanum_fraction": 0.461134006,
"avg_line_length": 31.5560538117,
"ext": "agda",
"hexsha": "de6ead6c0baf62068214a99416a05ab1c7517b58",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Lambda/Partiality-monad/Inductive/Interpreter.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Lambda/Partiality-monad/Inductive/Interpreter.agda",
"max_line_length": 116,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Lambda/Partiality-monad/Inductive/Interpreter.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 2835,
"size": 7037
} |
import Issue953
g : Set₁
g = Issue953.f
| {
"alphanum_fraction": 0.6904761905,
"avg_line_length": 7,
"ext": "agda",
"hexsha": "9e3deeb351fe4c4bc0f6ac1ade59db15c75dcc38",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/ImportAnonymousModule.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/ImportAnonymousModule.agda",
"max_line_length": 15,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/ImportAnonymousModule.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 16,
"size": 42
} |
--------------------------------------------------------------------------------
-- This is part of Agda Inference Systems
open import Agda.Builtin.Equality
open import Data.Product
open import Data.Sum
open import Data.Vec using (Vec; fromList; length) renaming (lookup to get)
open import Data.Fin using (Fin)
open import Level
open import Relation.Unary using (_⊆_)
module is-lib.InfSys.Base {𝓁} where
record MetaRule {𝓁c 𝓁p : Level} (U : Set 𝓁) : Set (𝓁 ⊔ suc 𝓁c ⊔ suc 𝓁p) where
field
Ctx : Set 𝓁c
Pos : Ctx → Set 𝓁p
prems : (c : Ctx) → Pos c → U
conclu : Ctx → U
addSideCond : ∀{𝓁'} → (U → Set 𝓁') → MetaRule {𝓁c ⊔ 𝓁'} U
(addSideCond P) .Ctx = Σ[ c ∈ Ctx ] P (conclu c)
(addSideCond P) .Pos (c , _) = Pos c
(addSideCond P) .prems (c , _) p = prems c p
(addSideCond P) .conclu (c , _) = conclu c
RF[_] : ∀{𝓁'} → (U → Set 𝓁') → (U → Set _)
RF[_] P u = Σ[ c ∈ Ctx ] (u ≡ conclu c × (∀ p → P (prems c p)))
RClosed : ∀{𝓁'} → (U → Set 𝓁') → Set _
RClosed P = ∀ c → (∀ p → P (prems c p)) → P (conclu c)
{- Finitary Rule -}
record FinMetaRule {𝓁c n} (U : Set 𝓁) : Set (𝓁 ⊔ suc 𝓁c) where
field
Ctx : Set 𝓁c
comp : Ctx → Vec U n × U
from : MetaRule {𝓁c} {zero} U
from .MetaRule.Ctx = Ctx
from .MetaRule.Pos = λ _ → Fin n
from .MetaRule.prems c n = get (proj₁ (comp c)) n
from .MetaRule.conclu c = proj₂ (comp c)
open MetaRule
record IS {𝓁c 𝓁p 𝓁n : Level} (U : Set 𝓁) : Set (𝓁 ⊔ suc 𝓁c ⊔ suc 𝓁p ⊔ suc 𝓁n) where
field
Names : Set 𝓁n
rules : Names → MetaRule {𝓁c} {𝓁p} U
ISF[_] : ∀{𝓁'} → (U → Set 𝓁') → (U → Set _)
ISF[_] P u = Σ[ rn ∈ Names ] RF[ rules rn ] P u
ISClosed : ∀{𝓁'} → (U → Set 𝓁') → Set _
ISClosed P = ∀ rn → RClosed (rules rn) P
open IS
_∪_ : ∀{𝓁c 𝓁p 𝓁n 𝓁n'}{U : Set 𝓁} → IS {𝓁c} {𝓁p} {𝓁n} U → IS {_} {_} {𝓁n'} U → IS {_} {_} {𝓁n ⊔ 𝓁n'} U
(is1 ∪ is2) .Names = (is1 .Names) ⊎ (is2 .Names)
(is1 ∪ is2) .rules = [ is1 .rules , is2 .rules ]
_⊓_ : ∀{𝓁c 𝓁p 𝓁n 𝓁'}{U : Set 𝓁} → IS {𝓁c} {𝓁p} {𝓁n} U → (U → Set 𝓁') → IS {𝓁c ⊔ 𝓁'} {_} {_} U
(is ⊓ P) .Names = is .Names
(is ⊓ P) .rules rn = addSideCond (is .rules rn) P
{- Properties -}
-- closed implies prefix
closed⇒prefix : ∀{𝓁c 𝓁p}{U : Set 𝓁} → (m : MetaRule {𝓁c} {𝓁p} U) → ∀{𝓁'}{P : U → Set 𝓁'} → RClosed m {𝓁'} P → RF[ m ] P ⊆ P
closed⇒prefix _ cl (_ , refl , pr) = cl _ pr
-- prefix implies closed
prefix⇒closed : ∀{𝓁c 𝓁p}{U : Set 𝓁} → (m : MetaRule {𝓁c} {𝓁p} U) → ∀{𝓁'}{P : U → Set 𝓁'} → (RF[ m ] P ⊆ P) → RClosed m {𝓁'} P
prefix⇒closed _ prf c pr = prf (c , refl , pr) | {
"alphanum_fraction": 0.5108323831,
"avg_line_length": 34.1688311688,
"ext": "agda",
"hexsha": "829194f6f7909d89c3c263031a8a85af0214d1ac",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "src/is-lib/InfSys/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "src/is-lib/InfSys/Base.agda",
"max_line_length": 127,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "src/is-lib/InfSys/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 1226,
"size": 2631
} |
open import Functional hiding (Domain)
import Structure.Logic.Classical.NaturalDeduction
import Structure.Logic.Classical.SetTheory.ZFC
module Structure.Logic.Classical.SetTheory.ZFC.Proofs {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ classicLogic : _ ⦄ (_∈_ : Domain → Domain → Formula) ⦃ signature : _ ⦄ ⦃ axioms : _ ⦄ where
open Structure.Logic.Classical.NaturalDeduction.ClassicalLogic {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} (classicLogic)
open Structure.Logic.Classical.SetTheory.ZFC.Signature {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ classicLogic ⦄ {_∈_} (signature)
open Structure.Logic.Classical.SetTheory.ZFC.ZF {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ classicLogic ⦄ {_∈_} ⦃ signature ⦄ (axioms)
open import Lang.Instance
import Lvl
open import Structure.Logic.Classical.NaturalDeduction.Proofs ⦃ classicLogic ⦄
open import Structure.Logic.Classical.SetTheory.SetBoundedQuantification ⦃ classicLogic ⦄ (_∈_)
open import Structure.Logic.Classical.SetTheory.Relation ⦃ classicLogic ⦄ (_∈_)
open import Structure.Logic.Classical.SetTheory ⦃ classicLogic ⦄ (_∈_)
open Structure.Logic.Classical.SetTheory.ZFC ⦃ classicLogic ⦄ (_∈_)
open import Structure.Logic.Constructive.Functions(Domain)
open import Structure.Logic.Constructive.Functions.Properties ⦃ constructiveLogicSignature ⦄
open SetEquality ⦃ ... ⦄ hiding (extensional)
open SingletonSet ⦃ ... ⦄ hiding (singleton)
open FilterSet ⦃ ... ⦄ hiding (filter)
open PowerSet ⦃ ... ⦄ hiding (℘)
open SetUnionSet ⦃ ... ⦄ hiding (⋃)
open UnionSet ⦃ ... ⦄ hiding (_∪_)
open IntersectionSet ⦃ ... ⦄ hiding (_∩_)
open WithoutSet ⦃ ... ⦄ hiding (_∖_)
open SetIntersectionSet ⦃ ... ⦄ hiding (⋂)
-- All sets are either empty or non-empty.
postulate Empty-excluded-middle : ∀{s} → Proof(Empty(s) ∨ NonEmpty(s))
pair-membership : Proof(∀ₗ(a₁ ↦ ∀ₗ(a₂ ↦ (∀ₗ(x ↦ (x ∈ pair(a₁)(a₂)) ⟷ (x ≡ a₁)∨(x ≡ a₂))))))
pair-membership = pairing
postulate pair-membership-[≡ₛ] : Proof(∀ₗ(a₁ ↦ ∀ₗ(a₂ ↦ (∀ₗ(x ↦ (x ∈ pair(a₁)(a₂)) ⟷ (x ≡ₛ a₁)∨(x ≡ₛ a₂))))))
-- pair-membership-[≡ₛ] = pairing
instance
setEqualityInstance : SetEquality
setEqualityInstance = SetEquality.intro extensional
instance
emptySetInstance : EmptySet
emptySetInstance = EmptySet.intro ∅ empty
instance
singletonSetInstance : SingletonSet
singletonSetInstance = SingletonSet.intro singleton
([∀].intro (\{a} →
([∀].intro (\{x} →
[↔].transitivity
([∀].elim([∀].elim([∀].elim(pair-membership-[≡ₛ]){a}){a}){x})
([↔].intro ([∨].redundancyₗ) ([∨].redundancyᵣ))
))
))
instance
filterSetInstance : FilterSet
filterSetInstance = FilterSet.intro filter comprehension
instance
powerSetInstance : PowerSet
powerSetInstance = PowerSet.intro ℘ power
instance
setUnionSetInstance : SetUnionSet
setUnionSetInstance = SetUnionSet.intro ⋃ union
instance
unionSetInstance : UnionSet
unionSetInstance = UnionSet.intro _∪_
([∀].intro (\{a} →
([∀].intro (\{b} →
([∀].intro (\{x} →
([∀].elim([∀].elim [⋃]-membership{pair(a)(b)}){x})
⦗ₗ [↔].transitivity ⦘
([↔]-with-[∃] (\{s} →
([↔]-with-[∧]ₗ ([∀].elim([∀].elim([∀].elim pair-membership{a}){b}){s}))
⦗ₗ [↔].transitivity ⦘
([∧][∨]-distributivityᵣ)
⦗ₗ [↔].transitivity ⦘
[↔]-with-[∨] ([≡]-substitute-this-is-almost-trivial) ([≡]-substitute-this-is-almost-trivial)
))
⦗ₗ [↔].transitivity ⦘
([↔].intro ([∃]-redundancyₗ) ([∃]-redundancyᵣ))
))
))
))
instance
intersectionSetInstance : IntersectionSet
intersectionSetInstance = IntersectionSet.intro _∩_
([∀].intro (\{a} →
([∀].intro (\{b} →
([∀].elim(filter-membership){a})
))
))
instance
withoutSetInstance : WithoutSet
withoutSetInstance = WithoutSet.intro _∖_
([∀].intro (\{a} →
([∀].intro (\{b} →
([∀].elim(filter-membership){a})
))
))
instance
setIntersectionSetInstance : SetIntersectionSet
setIntersectionSetInstance = SetIntersectionSet.intro ⋂
([∀].intro (\{ss} →
([∀].intro (\{x} →
([↔].intro
-- (⟵)-case
(allssinssxins ↦
([↔].elimₗ
([∀].elim([∀].elim filter-membership{⋃(ss)}){x})
([∧].intro
-- x ∈ ⋃(ss)
([∨].elim
-- Empty(ss) ⇒ _
(allyyninss ↦
proof -- TODO: But: Empty(ss) ⇒ (ss ≡ ∅) ⇒ ⋃(ss) ≡ ∅ ⇒ (x ∉ ⋃(ss)) ? Maybe use this argument further up instead to prove something like: (⋂(ss) ≡ ∅) ⇒ (x ∉ ∅)
)
-- NonEmpty(ss) ⇒ _
(existsyinss ↦
([∃].elim
(\{y} → yinss ↦ (
([↔].elimₗ([∀].elim([∀].elim([⋃]-membership){ss}){x}))
([∃].intro{_}
{y}
([∧].intro
-- y ∈ ss
(yinss)
-- x ∈ y
([→].elim
([∀].elim(allssinssxins){y})
(yinss)
)
)
)
))
(existsyinss)
)
)
(Empty-excluded-middle{ss})
)
-- ∀(s∊ss). x∈s
(allssinssxins)
)
)
)
-- (⟶)-case
(xinintersectss ↦
([∀].intro (\{s} →
([→].intro (sinss ↦
([→].elim
([∀].elim
([∧].elimᵣ
([↔].elimᵣ
([∀].elim
([∀].elim
filter-membership
{⋃(ss)}
)
{x}
)
(xinintersectss)
)
)
{s}
)
(sinss)
)
))
))
)
)
))
))
where postulate proof : ∀{a} → a
-- postulate any : ∀{l}{a : Set(l)} → a
-- TODO: Just used for reference. Remove these lines later
-- ⋂(a) = filter(⋃(ss)) (x ↦ ∀ₗ(a₂ ↦ (a₂ ∈ ss) ⟶ (x ∈ a₂)))
-- filter-membership : ∀{φ : Domain → Formula} → Proof(∀ₗ(s ↦ ∀ₗ(x ↦ ((x ∈ filter(s)(φ)) ⟷ ((x ∈ s) ∧ φ(x))))))
-- [⋃]-membership : Proof(∀ₗ(ss ↦ ∀ₗ(x ↦ (x ∈ ⋃(ss)) ⟷ ∃ₗ(s ↦ (s ∈ ss)∧(x ∈ s)))))
-- [⨯]-membership : Proof(∀ₗ(a ↦ ∀ₗ(b ↦ ∀ₗ(x ↦ (x ∈ (a ⨯ b)) ⟷ ∃ₛ(a)(x₁ ↦ ∃ₛ(b)(x₂ ↦ x ≡ (x₁ , x₂)))))))
-- [⨯]-membership =
-- [⋃][℘]-inverse : Proof(∀ₗ(s ↦ ⋃(℘(s)) ≡ s))
-- TODO: https://planetmath.org/SurjectionAndAxiomOfChoice
| {
"alphanum_fraction": 0.4786130453,
"avg_line_length": 34.8366336634,
"ext": "agda",
"hexsha": "98e71337bccc51f7af7c126199df61c107698c78",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Structure/Logic/Classical/SetTheory/ZFC/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Structure/Logic/Classical/SetTheory/ZFC/Proofs.agda",
"max_line_length": 190,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Structure/Logic/Classical/SetTheory/ZFC/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 2279,
"size": 7037
} |
open import FRP.JS.Bool using ( Bool ; not )
open import FRP.JS.Maybe using ( Maybe ; just ; nothing ; _≟[_]_ )
open import FRP.JS.Float using ( ℝ ; _≟_ ; -_ ; _+_ ; _*_ ; _-_ ; _/_ ; _/?_ ; _≤_ ; _<_ ; show )
open import FRP.JS.String using () renaming ( _≟_ to _≟s_ )
open import FRP.JS.QUnit using ( TestSuite ; ok ; ok! ; test ; _,_ )
module FRP.JS.Test.Float where
infixr 2 _≟?_
_≟?_ : Maybe ℝ → Maybe ℝ → Bool
x ≟? y = x ≟[ _≟_ ] y
tests : TestSuite
tests =
( test "≟"
( ok "0 ≟ 0" (0.0 ≟ 0.0)
, ok "1 ≟ 1" (1.0 ≟ 1.0)
, ok "2 ≟ 2" (2.0 ≟ 2.0)
, ok "0 != 1" (not (0.0 ≟ 1.0))
, ok "0 != 2" (not (0.0 ≟ 2.0))
, ok "1 != 2" (not (1.0 ≟ 2.0))
, ok "1 != 0" (not (1.0 ≟ 0.0)) )
, test "+"
( ok "0 + 0" (0.0 + 0.0 ≟ 0.0)
, ok "1 + 1" (1.0 + 1.0 ≟ 2.0)
, ok "37 + 0" (37.0 + 0.0 ≟ 37.0)
, ok "37 + 1" (37.0 + 1.0 ≟ 38.0)
, ok "37 + 5" (37.0 + 5.0 ≟ 42.0) )
, test "*"
( ok "0 * 0" (0.0 * 0.0 ≟ 0.0)
, ok "1 * 1" (1.0 * 1.0 ≟ 1.0)
, ok "37 * 0" (37.0 * 0.0 ≟ 0.0)
, ok "37 * 1" (37.0 * 1.0 ≟ 37.0)
, ok "37 * 5" (37.0 * 5.0 ≟ 185.0) )
, test "-"
( ok "0 - 0" (0.0 - 0.0 ≟ 0.0)
, ok "1 - 1" (1.0 - 1.0 ≟ 0.0)
, ok "37 - 0" (37.0 - 0.0 ≟ 37.0)
, ok "37 - 1" (37.0 - 1.0 ≟ 36.0)
, ok "37 - 5" (37.0 - 5.0 ≟ 32.0)
, ok "5 - 37" (5.0 - 37.0 ≟ - 32.0) )
, test "/"
( ok "1 / 1" (1.0 / 1.0 ≟ 1.0)
, ok "37 / 1" (37.0 / 1.0 ≟ 37.0)
, ok "37 / 5" (37.0 / 5.0 ≟ 7.4)
, ok "0 /? 0" (0.0 /? 0.0 ≟? nothing)
, ok "1 /? 1" (1.0 /? 1.0 ≟? just 1.0)
, ok "37 /? 0" (37.0 /? 0.0 ≟? nothing)
, ok "37 /? 1" (37.0 /? 1.0 ≟? just 37.0)
, ok "37 /? 5" (37.0 /? 5.0 ≟? just 7.4) )
, test "≤"
( ok "0 ≤ 0" (0.0 ≤ 0.0)
, ok "0 ≤ 1" (0.0 ≤ 1.0)
, ok "1 ≤ 0" (not (1.0 ≤ 0.0))
, ok "1 ≤ 1" (1.0 ≤ 1.0)
, ok "37 ≤ 0" (not (37.0 ≤ 0.0))
, ok "37 ≤ 1" (not (37.0 ≤ 1.0))
, ok "37 ≤ 5" (not (37.0 ≤ 5.0))
, ok "5 ≤ 37" (5.0 ≤ 37.0) )
, test "<"
( ok "0 < 0" (not (0.0 < 0.0))
, ok "0 < 1" (0.0 < 1.0)
, ok "1 < 0" (not (1.0 < 0.0))
, ok "1 < 1" (not (1.0 < 1.0))
, ok "37 < 0" (not (37.0 < 0.0))
, ok "37 < 1" (not (37.0 < 1.0))
, ok "37 < 5" (not (37.0 < 5.0))
, ok "5 < 37" (5.0 < 37.0) )
, test "show"
( ok "show 0" (show 0.0 ≟s "0")
, ok "show 1" (show 1.0 ≟s "1")
, ok "show 5" (show 5.0 ≟s "5")
, ok "show 37" (show 37.0 ≟s "37")
, ok "show -0" (show (- 0.0) ≟s "0")
, ok "show -37" (show (- 37.0) ≟s "-37")
, ok "show 3.1415" (show 3.1415 ≟s "3.1415")
, ok "show -3.1415" (show (- 3.1415) ≟s "-3.1415") ) )
| {
"alphanum_fraction": 0.3854047891,
"avg_line_length": 33.3037974684,
"ext": "agda",
"hexsha": "8d1e19e4de760cf796d34fb3443d80bf2bbee262",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "test/agda/FRP/JS/Test/Float.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "test/agda/FRP/JS/Test/Float.agda",
"max_line_length": 97,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "test/agda/FRP/JS/Test/Float.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 1508,
"size": 2631
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
open import homotopy.PushoutSplit
open import homotopy.DisjointlyPointedSet
open import cw.CW
module cw.cohomology.WedgeOfCells {i} (OT : OrdinaryTheory i)
{n} (⊙skel : ⊙Skeleton {i} (S n)) where
open OrdinaryTheory OT
open import cohomology.Sphere OT
Xₙ/Xₙ₋₁ : Ptd i
Xₙ/Xₙ₋₁ = ⊙Cofiber (⊙cw-incl-last ⊙skel)
module _ (m : ℤ) where
CXₙ/Xₙ₋₁ : Group i
CXₙ/Xₙ₋₁ = C m Xₙ/Xₙ₋₁
CEl-Xₙ/Xₙ₋₁ : Type i
CEl-Xₙ/Xₙ₋₁ = Group.El CXₙ/Xₙ₋₁
abstract
CXₙ/Xₙ₋₁-is-abelian : is-abelian CXₙ/Xₙ₋₁
CXₙ/Xₙ₋₁-is-abelian = C-is-abelian m Xₙ/Xₙ₋₁
CXₙ/Xₙ₋₁-abgroup : AbGroup i
CXₙ/Xₙ₋₁-abgroup = CXₙ/Xₙ₋₁ , CXₙ/Xₙ₋₁-is-abelian
{- the equivalence is in the opposite direction because
cohomology functors are contravariant. -}
BigWedge-⊙equiv-Xₙ/Xₙ₋₁ : ⊙BigWedge {A = ⊙cells-last ⊙skel} (λ _ → ⊙Sphere (S n)) ⊙≃ Xₙ/Xₙ₋₁
BigWedge-⊙equiv-Xₙ/Xₙ₋₁ = ≃-to-⊙≃
(PS.split-equiv ∘e equiv to from to-from from-to) idp
where
open AttachedSkeleton (⊙Skeleton.skel ⊙skel)
module PS = PushoutLSplit (uncurry attaching) (λ _ → tt) fst
module SphereToCofiber (a : fst cells) = SuspRec {A = Sphere n}
(cfbase' (fst :> (fst cells × Sphere n → fst cells)))
(cfcod a) (λ s → cfglue (a , s))
module To = BigWedgeRec {A = fst cells} {X = λ _ → ⊙Sphere (S n)}
cfbase SphereToCofiber.f (λ _ → idp)
to = To.f
module From = CofiberRec {f = fst :> (fst cells × Sphere n → fst cells)}
(bwbase {A = fst cells} {X = λ _ → ⊙Sphere (S n)})
(λ a → bwin a south) (λ{(a , s) → bwglue a ∙ ap (bwin a) (merid s)})
from = From.f
abstract
from-to : ∀ b → from (to b) == b
from-to = BigWedge-elim
idp
(λ a → Susp-elim (bwglue a) idp
(λ s → ↓-='-from-square $
( ap-∘ from (SphereToCofiber.f a) (merid s)
∙ ap (ap from) (SphereToCofiber.merid-β a s)
∙ From.glue-β (a , s))
∙v⊡ (tl-square (bwglue a) ⊡h vid-square)))
(λ a → ↓-∘=idf-from-square from to $
ap (ap from) (To.glue-β a) ∙v⊡ br-square (bwglue a))
to-from : ∀ c → to (from c) == c
to-from = Cofiber-elim
idp (λ a → idp)
(λ{(a , s) → ↓-∘=idf-in' to from $
ap (ap to) (From.glue-β (a , s))
∙ ap-∙ to (bwglue a) (ap (bwin a) (merid s))
∙ ap2 _∙_ (To.glue-β a)
( ∘-ap to (bwin a) (merid s)
∙ SphereToCofiber.merid-β a s)})
CXₙ/Xₙ₋₁-β : ∀ m → ⊙has-cells-with-choice 0 ⊙skel i
→ C m Xₙ/Xₙ₋₁ ≃ᴳ Πᴳ (⊙cells-last ⊙skel) (λ _ → C m (⊙Lift (⊙Sphere (S n))))
CXₙ/Xₙ₋₁-β m ac = C-additive-iso m (λ _ → ⊙Lift (⊙Sphere (S n))) (⊙cells-last-has-choice ⊙skel ac)
∘eᴳ C-emap m ( BigWedge-⊙equiv-Xₙ/Xₙ₋₁
⊙∘e ⊙BigWedge-emap-r (λ _ → ⊙lower-equiv))
CXₙ/Xₙ₋₁-β-diag : ⊙has-cells-with-choice 0 ⊙skel i
→ CXₙ/Xₙ₋₁ (ℕ-to-ℤ (S n)) ≃ᴳ Πᴳ (⊙cells-last ⊙skel) (λ _ → C2 0)
CXₙ/Xₙ₋₁-β-diag ac = Πᴳ-emap-r (⊙cells-last ⊙skel) (λ _ → C-Sphere-diag (S n))
∘eᴳ CXₙ/Xₙ₋₁-β (ℕ-to-ℤ (S n)) ac
abstract
CXₙ/Xₙ₋₁-≠-is-trivial : ∀ {m} (m≠Sn : m ≠ ℕ-to-ℤ (S n))
→ ⊙has-cells-with-choice 0 ⊙skel i
→ is-trivialᴳ (CXₙ/Xₙ₋₁ m)
CXₙ/Xₙ₋₁-≠-is-trivial {m} m≠Sn ac =
iso-preserves'-trivial (CXₙ/Xₙ₋₁-β m ac) $
Πᴳ-is-trivial (⊙cells-last ⊙skel)
(λ _ → C m (⊙Lift (⊙Sphere (S n))))
(λ _ → C-Sphere-≠-is-trivial m (S n) m≠Sn)
CXₙ/Xₙ₋₁-<-is-trivial : ∀ {m} (m<Sn : m < S n)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ is-trivialᴳ (CXₙ/Xₙ₋₁ (ℕ-to-ℤ m))
CXₙ/Xₙ₋₁-<-is-trivial m<Sn = CXₙ/Xₙ₋₁-≠-is-trivial (ℕ-to-ℤ-≠ (<-to-≠ m<Sn))
CXₙ/Xₙ₋₁->-is-trivial : ∀ {m} (m>Sn : S n < m)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ is-trivialᴳ (CXₙ/Xₙ₋₁ (ℕ-to-ℤ m))
CXₙ/Xₙ₋₁->-is-trivial m>Sn = CXₙ/Xₙ₋₁-≠-is-trivial (≠-inv (ℕ-to-ℤ-≠ (<-to-≠ m>Sn)))
| {
"alphanum_fraction": 0.5540401441,
"avg_line_length": 35.9814814815,
"ext": "agda",
"hexsha": "334505a9146d8967f5e1a391e7315a8fa0d24a62",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/WedgeOfCells.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/WedgeOfCells.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/WedgeOfCells.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1857,
"size": 3886
} |
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
module Maybe where
data Maybe {a : _} (A : Set a) : Set a where
no : Maybe A
yes : A → Maybe A
joinMaybe : {a : _} → {A : Set a} → Maybe (Maybe A) → Maybe A
joinMaybe no = no
joinMaybe (yes s) = s
bindMaybe : {a b : _} → {A : Set a} → {B : Set b} → Maybe A → (A → Maybe B) → Maybe B
bindMaybe no f = no
bindMaybe (yes x) f = f x
applyMaybe : {a b : _} → {A : Set a} → {B : Set b} → Maybe (A → B) → Maybe A → Maybe B
applyMaybe f no = no
applyMaybe no (yes x) = no
applyMaybe (yes f) (yes x) = yes (f x)
yesInjective : {a : _} → {A : Set a} → {x y : A} → (yes x ≡ yes y) → x ≡ y
yesInjective {a} {A} {x} {.x} refl = refl
mapMaybe : {a b : _} → {A : Set a} → {B : Set b} → (f : A → B) → Maybe A → Maybe B
mapMaybe f no = no
mapMaybe f (yes x) = yes (f x)
defaultValue : {a : _} → {A : Set a} → (default : A) → Maybe A → A
defaultValue default no = default
defaultValue default (yes x) = x
noNotYes : {a : _} {A : Set a} {b : A} → (no ≡ yes b) → False
noNotYes ()
mapMaybePreservesNo : {a b : _} {A : Set a} {B : Set b} {f : A → B} {x : Maybe A} → mapMaybe f x ≡ no → x ≡ no
mapMaybePreservesNo {f = f} {no} pr = refl
mapMaybePreservesYes : {a b : _} {A : Set a} {B : Set b} {f : A → B} {x : Maybe A} {y : B} → mapMaybe f x ≡ yes y → Sg A (λ z → (x ≡ yes z) && (f z ≡ y))
mapMaybePreservesYes {f = f} {x} {y} map with x
mapMaybePreservesYes {f = f} {x} {y} map | yes z = z , (refl ,, yesInjective map)
| {
"alphanum_fraction": 0.5555555556,
"avg_line_length": 33.9545454545,
"ext": "agda",
"hexsha": "6f429c268100236db1db9e8ce308736f41492a19",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Maybe.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Maybe.agda",
"max_line_length": 153,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Maybe.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 604,
"size": 1494
} |
{-# OPTIONS --cubical --safe --no-import-sorts #-}
{-
Implements the monadic interface of propositional truncation, for reasoning in do-syntax.
-}
module Cubical.HITs.PropositionalTruncation.Monad where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Functions.Logic
open import Cubical.HITs.PropositionalTruncation
private
variable
ℓ : Level
P Q : Type ℓ
infix 1 proof_by_
proof_by_ : (P : hProp ℓ) → ∥ ⟨ P ⟩ ∥ → ⟨ P ⟩
proof P by p = rec (isProp⟨⟩ P) (λ p → p) p
return : P → ∥ P ∥
return p = ∣ p ∣
exact_ : ∥ P ∥ → ∥ P ∥
exact p = p
_>>=_ : ∥ P ∥ → (P → ∥ Q ∥) → ∥ Q ∥
p >>= f = rec propTruncIsProp f p
_>>_ : ∥ P ∥ → ∥ Q ∥ → ∥ Q ∥
_ >> q = q
| {
"alphanum_fraction": 0.6472919419,
"avg_line_length": 22.2647058824,
"ext": "agda",
"hexsha": "db769bf4910f51db4e07ca62980ad10a6483dee0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/PropositionalTruncation/Monad.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/PropositionalTruncation/Monad.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/PropositionalTruncation/Monad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 284,
"size": 757
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Applicative functors on indexed sets (predicates)
------------------------------------------------------------------------
-- Note that currently the applicative functor laws are not included
-- here.
{-# OPTIONS --without-K --safe #-}
module Category.Applicative.Predicate where
open import Category.Functor.Predicate
open import Data.Product
open import Function
open import Level
open import Relation.Unary
open import Relation.Unary.PredicateTransformer using (Pt)
------------------------------------------------------------------------
record RawPApplicative {i ℓ} {I : Set i} (F : Pt I ℓ) :
Set (i ⊔ suc ℓ) where
infixl 4 _⊛_ _<⊛_ _⊛>_
infix 4 _⊗_
field
pure : ∀ {P} → P ⊆ F P
_⊛_ : ∀ {P Q} → F (P ⇒ Q) ⊆ F P ⇒ F Q
rawPFunctor : RawPFunctor F
rawPFunctor = record
{ _<$>_ = λ g x → pure g ⊛ x
}
private
open module RF = RawPFunctor rawPFunctor public
_<⊛_ : ∀ {P Q} → F P ⊆ const (∀ {j} → F Q j) ⇒ F P
x <⊛ y = const <$> x ⊛ y
_⊛>_ : ∀ {P Q} → const (∀ {i} → F P i) ⊆ F Q ⇒ F Q
x ⊛> y = flip const <$> x ⊛ y
_⊗_ : ∀ {P Q} → F P ⊆ F Q ⇒ F (P ∩ Q)
x ⊗ y = (_,_) <$> x ⊛ y
zipWith : ∀ {P Q R} → (P ⊆ Q ⇒ R) → F P ⊆ F Q ⇒ F R
zipWith f x y = f <$> x ⊛ y
| {
"alphanum_fraction": 0.4715025907,
"avg_line_length": 26.4901960784,
"ext": "agda",
"hexsha": "545ac4a4a66ece7c0a908c63c7e46bd777332608",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Category/Applicative/Predicate.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Category/Applicative/Predicate.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Category/Applicative/Predicate.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 445,
"size": 1351
} |
-- Parameter arguments of overloaded projection applications
-- should not be skipped!
record R A : Set where
field f : A → A
open R
record S A : Set where
field f : A → A
open S
r : ∀{A} → R A
f r x = x
test : ∀{A : Set} → A → A
test a = f r a
| {
"alphanum_fraction": 0.6086956522,
"avg_line_length": 14.8823529412,
"ext": "agda",
"hexsha": "33d8b37684675cc965951aae8ce0d05ff65f2a2c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/Succeed/Issue1944-poly-record.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "test/Succeed/Issue1944-poly-record.agda",
"max_line_length": 60,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/Succeed/Issue1944-poly-record.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 86,
"size": 253
} |
module Issue4022.Import where
open import Agda.Builtin.Nat
Binary : Set
Binary = Nat → Nat → Nat
-- Search should be able to find `plus` if:
-- * either we do not normalise the type and look for `Binary`
-- * or we do normalise the type and look for `Nat`
plus : Binary
plus = _+_
| {
"alphanum_fraction": 0.701754386,
"avg_line_length": 20.3571428571,
"ext": "agda",
"hexsha": "97f0f2549b01ef413e2ebb923e368d69de2a8209",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue4022/Import.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue4022/Import.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue4022/Import.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 80,
"size": 285
} |
{-
Functions building UARels and DUARels on function types
-}
{-# OPTIONS --no-exact-split --safe #-}
module Cubical.Displayed.Function where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Functions.FunExtEquiv
open import Cubical.Functions.Implicit
open import Cubical.Displayed.Base
open import Cubical.Displayed.Constant
open import Cubical.Displayed.Morphism
open import Cubical.Displayed.Subst
open import Cubical.Displayed.Sigma
private
variable
ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C : Level
-- UARel on dependent function type
-- from UARel on domain and DUARel on codomain
module _ {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) {B : A → Type ℓB} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B) where
open UARel 𝒮-A
open DUARel 𝒮ᴰ-B
𝒮-Π : UARel ((a : A) → B a) (ℓ-max ℓA ℓ≅B)
UARel._≅_ 𝒮-Π f f' = ∀ a → f a ≅ᴰ⟨ ρ a ⟩ f' a
UARel.ua 𝒮-Π f f' =
compEquiv
(equivΠCod λ a → uaᴰρ (f a) (f' a))
funExtEquiv
-- Parameterize UARel by type
_→𝒮_ : (A : Type ℓA) {B : Type ℓB} (𝒮-B : UARel B ℓ≅B) → UARel (A → B) (ℓ-max ℓA ℓ≅B)
(A →𝒮 𝒮-B) .UARel._≅_ f f' = ∀ a → 𝒮-B .UARel._≅_ (f a) (f' a)
(A →𝒮 𝒮-B) .UARel.ua f f' =
compEquiv
(equivΠCod λ a → 𝒮-B .UARel.ua (f a) (f' a))
funExtEquiv
𝒮-app : {A : Type ℓA} {B : Type ℓB} {𝒮-B : UARel B ℓ≅B}
→ A → UARelHom (A →𝒮 𝒮-B) 𝒮-B
𝒮-app a .UARelHom.fun f = f a
𝒮-app a .UARelHom.rel h = h a
𝒮-app a .UARelHom.ua h = refl
-- DUARel on dependent function type
-- from DUARels on domain and codomain
module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B)
{C : (a : A) → B a → Type ℓC} (𝒮ᴰ-C : DUARel (∫ 𝒮ᴰ-B) (uncurry C) ℓ≅C)
where
open UARel 𝒮-A
private
module B = DUARel 𝒮ᴰ-B
module C = DUARel 𝒮ᴰ-C
𝒮ᴰ-Π : DUARel 𝒮-A (λ a → (b : B a) → C a b) (ℓ-max (ℓ-max ℓB ℓ≅B) ℓ≅C)
DUARel._≅ᴰ⟨_⟩_ 𝒮ᴰ-Π f p f' =
∀ {b b'} (q : b B.≅ᴰ⟨ p ⟩ b') → f b C.≅ᴰ⟨ p , q ⟩ f' b'
DUARel.uaᴰ 𝒮ᴰ-Π f p f' =
compEquiv
(equivImplicitΠCod λ {b} →
(equivImplicitΠCod λ {b'} →
(equivΠ (B.uaᴰ b p b') (λ q → C.uaᴰ (f b) (p , q) (f' b')))))
funExtDepEquiv
_→𝒮ᴰ_ : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B)
{C : A → Type ℓC} (𝒮ᴰ-C : DUARel 𝒮-A C ℓ≅C)
→ DUARel 𝒮-A (λ a → B a → C a) (ℓ-max (ℓ-max ℓB ℓ≅B) ℓ≅C)
𝒮ᴰ-B →𝒮ᴰ 𝒮ᴰ-C =
𝒮ᴰ-Π 𝒮ᴰ-B (𝒮ᴰ-Lift _ 𝒮ᴰ-C 𝒮ᴰ-B)
-- DUARel on dependent function type
-- from a SubstRel on the domain and DUARel on the codomain
module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B)
{C : (a : A) → B a → Type ℓC} (𝒮ᴰ-C : DUARel (∫ˢ 𝒮ˢ-B) (uncurry C) ℓ≅C)
where
open UARel 𝒮-A
open SubstRel 𝒮ˢ-B
open DUARel 𝒮ᴰ-C
𝒮ᴰ-Πˢ : DUARel 𝒮-A (λ a → (b : B a) → C a b) (ℓ-max ℓB ℓ≅C)
DUARel._≅ᴰ⟨_⟩_ 𝒮ᴰ-Πˢ f p f' =
(b : B _) → f b ≅ᴰ⟨ p , refl ⟩ f' (act p .fst b)
DUARel.uaᴰ 𝒮ᴰ-Πˢ f p f' =
compEquiv
(compEquiv
(equivΠCod λ b → Jequiv (λ b' q → f b ≅ᴰ⟨ p , q ⟩ f' b'))
(invEquiv implicit≃Explicit))
(DUARel.uaᴰ (𝒮ᴰ-Π (Subst→DUA 𝒮ˢ-B) 𝒮ᴰ-C) f p f')
-- SubstRel on a dependent function type
-- from a SubstRel on the domain and SubstRel on the codomain
equivΠ' : ∀ {ℓA ℓA' ℓB ℓB'} {A : Type ℓA} {A' : Type ℓA'}
{B : A → Type ℓB} {B' : A' → Type ℓB'}
(eA : A ≃ A')
(eB : {a : A} {a' : A'} → eA .fst a ≡ a' → B a ≃ B' a')
→ ((a : A) → B a) ≃ ((a' : A') → B' a')
equivΠ' {B' = B'} eA eB = isoToEquiv isom
where
open Iso
isom : Iso _ _
isom .fun f a' =
eB (retEq eA a') .fst (f (invEq eA a'))
isom .inv f' a =
invEq (eB refl) (f' (eA .fst a))
isom .rightInv f' =
funExt λ a' →
J (λ a'' p → eB p .fst (invEq (eB refl) (f' (p i0))) ≡ f' a'')
(retEq (eB refl) (f' (eA .fst (invEq eA a'))))
(retEq eA a')
isom .leftInv f =
funExt λ a →
subst
(λ p → invEq (eB refl) (eB p .fst (f (invEq eA (eA .fst a)))) ≡ f a)
(sym (commPathIsEq (eA .snd) a))
(J (λ a'' p → invEq (eB refl) (eB (cong (eA .fst) p) .fst (f (invEq eA (eA .fst a)))) ≡ f a'')
(secEq (eB refl) (f (invEq eA (eA .fst a))))
(secEq eA a))
module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B)
{C : Σ A B → Type ℓC} (𝒮ˢ-C : SubstRel (∫ˢ 𝒮ˢ-B) C)
where
open UARel 𝒮-A
open SubstRel
private
module B = SubstRel 𝒮ˢ-B
module C = SubstRel 𝒮ˢ-C
𝒮ˢ-Π : SubstRel 𝒮-A (λ a → (b : B a) → C (a , b))
𝒮ˢ-Π .act p = equivΠ' (B.act p) (λ q → C.act (p , q))
𝒮ˢ-Π .uaˢ p f =
fromPathP
(DUARel.uaᴰ (𝒮ᴰ-Π (Subst→DUA 𝒮ˢ-B) (Subst→DUA 𝒮ˢ-C)) f p (equivFun (𝒮ˢ-Π .act p) f) .fst
(λ {b} →
J (λ b' q →
equivFun (C.act (p , q)) (f b)
≡ equivFun (equivΠ' (𝒮ˢ-B .act p) (λ q → C.act (p , q))) f b')
(λ i →
C.act (p , λ j → commSqIsEq (𝒮ˢ-B .act p .snd) b (~ i) j) .fst
(f (secEq (𝒮ˢ-B .act p) b (~ i))))))
| {
"alphanum_fraction": 0.5473053892,
"avg_line_length": 30.5487804878,
"ext": "agda",
"hexsha": "501df080b3a93eb2593455383c90633fa5418c90",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "94b474af2909727d04706d562d949928c19faf7b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jespercockx/cubical",
"max_forks_repo_path": "Cubical/Displayed/Function.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "94b474af2909727d04706d562d949928c19faf7b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jespercockx/cubical",
"max_issues_repo_path": "Cubical/Displayed/Function.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "94b474af2909727d04706d562d949928c19faf7b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jespercockx/cubical",
"max_stars_repo_path": "Cubical/Displayed/Function.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2629,
"size": 5010
} |
-- AIM XXXV, 2022-05-06, issue #5891.
-- When checking that the sort of a data type admits data definitions
-- (checkDataSort), we need to handle the case of PiSort.
mutual
Univ1 = _
Univ2 = _
Univ3 = _
postulate
A1 : Univ1
A2 : Univ2
A : Univ3
A = A1 → A2
-- This demonstrates that the sort of a data types can be a PiSort
-- (temporarily, until further information becomes available later):
data Empty : Univ3 where
_ : Univ1
_ = Set
_ : Univ2
_ = Set
-- Should succeed.
| {
"alphanum_fraction": 0.6556420233,
"avg_line_length": 18.3571428571,
"ext": "agda",
"hexsha": "ff3ed85306ee306425f34d814403c8b01dd2de7d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue5891DataOfPiSort.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue5891DataOfPiSort.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue5891DataOfPiSort.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 163,
"size": 514
} |
module Human.Equality where
data _==_ {A : Set} (x : A) : A -> Set where
refl : x == x
{-# BUILTIN EQUALITY _==_ #-}
sym : {A : Set} (x : A) (y : A) -> x == y -> y == x
sym x .x refl = refl
cong : {A : Set} {B : Set} (x : A) (y : A) (f : A -> B) -> x == y -> f x == f y
cong x y f refl = refl
| {
"alphanum_fraction": 0.4548494983,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "1a088d46445671efd86022bcd99bd7065dd0f168",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MaisaMilena/AgdaCalculator",
"max_forks_repo_path": "src/Human/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MaisaMilena/AgdaCalculator",
"max_issues_repo_path": "src/Human/Equality.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MaisaMilena/AgdaCalculator",
"max_stars_repo_path": "src/Human/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-29T02:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-29T02:30:10.000Z",
"num_tokens": 126,
"size": 299
} |
module Issue271 where
data D (A : Set) : Set where
d : D A → D A
f : {A : Set} → D A → D A
f x = d {!!}
| {
"alphanum_fraction": 0.4907407407,
"avg_line_length": 13.5,
"ext": "agda",
"hexsha": "6f27001ce2635ee77c984e1d2d57bc9ca75d3bc4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue271.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue271.agda",
"max_line_length": 28,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue271.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 45,
"size": 108
} |
{-# OPTIONS --prop --rewriting #-}
open import Examples.Sorting.Parallel.Comparable
module Examples.Sorting.Parallel.MergeSortPar.Merge (M : Comparable) where
open Comparable M
open import Examples.Sorting.Parallel.Core M
open import Calf costMonoid
open import Calf.ParMetalanguage parCostMonoid
open import Calf.Types.Bool
open import Calf.Types.Nat
open import Calf.Types.List
open import Calf.Types.Eq
open import Calf.Types.Bounded costMonoid
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; module ≡-Reasoning)
open import Data.Product using (_×_; _,_; ∃; proj₁; proj₂)
open import Data.Sum using (inj₁; inj₂)
open import Data.Nat as Nat using (ℕ; zero; suc; z≤n; s≤s; _+_; _*_; ⌊_/2⌋; ⌈_/2⌉; pred; _⊔_)
open import Data.Nat.Properties as N using (module ≤-Reasoning)
open import Data.Nat.Log2
open import Data.Nat.PredExp2
open import Examples.Sorting.Parallel.MergeSort.Split M
triple = Σ++ (list A) λ _ → Σ++ A λ _ → (list A)
splitMid/clocked : cmp (Π nat λ k → Π (list A) λ l → Π (U (meta (k Nat.< length l))) λ _ → F triple)
splitMid/clocked zero (x ∷ xs) (s≤s h) = ret ([] , x , xs)
splitMid/clocked (suc k) (x ∷ xs) (s≤s h) =
bind (F triple) (splitMid/clocked k xs h) λ (l₁ , mid , l₂) → ret ((x ∷ l₁) , mid , l₂)
splitMid/clocked/correct : ∀ k k' l h → k + suc k' ≡ length l →
◯ (∃ λ l₁ → ∃ λ mid → ∃ λ l₂ → splitMid/clocked k l h ≡ ret (l₁ , mid , l₂) × length l₁ ≡ k × length l₂ ≡ k' × l ≡ (l₁ ++ [ mid ] ++ l₂))
splitMid/clocked/correct zero k' (x ∷ xs) (s≤s h) refl u = [] , x , xs , refl , refl , refl , refl
splitMid/clocked/correct (suc k) k' (x ∷ xs) (s≤s h) h-length u =
let (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) = splitMid/clocked/correct k k' xs h (N.suc-injective h-length) u in
x ∷ l₁ , mid , l₂ , Eq.cong (λ e → bind (F triple) e _) ≡ , Eq.cong suc h₁ , h₂ , Eq.cong (x ∷_) ≡-↭
splitMid/clocked/cost : cmp (Π nat λ k → Π (list A) λ l → Π (U (meta (k Nat.< length l))) λ _ → cost)
splitMid/clocked/cost _ _ _ = 𝟘
splitMid/clocked≤splitMid/clocked/cost : ∀ k l h → IsBounded triple (splitMid/clocked k l h) (splitMid/clocked/cost k l h)
splitMid/clocked≤splitMid/clocked/cost zero (x ∷ xs) (s≤s h) = bound/ret
splitMid/clocked≤splitMid/clocked/cost (suc k) (x ∷ xs) (s≤s h) =
bound/bind/const 𝟘 𝟘 (splitMid/clocked≤splitMid/clocked/cost k xs h) λ _ → bound/ret
splitMid : cmp (Π (list A) λ l → Π (U (meta (0 Nat.< length l))) λ _ → F triple)
splitMid (x ∷ xs) (s≤s h) = splitMid/clocked ⌊ length (x ∷ xs) /2⌋ (x ∷ xs) (N.⌊n/2⌋<n _)
splitMid/correct : ∀ l h →
◯ (∃ λ l₁ → ∃ λ mid → ∃ λ l₂ → splitMid l h ≡ ret (l₁ , mid , l₂) × length l₁ Nat.≤ ⌊ length l /2⌋ × length l₂ Nat.≤ ⌊ length l /2⌋ × l ≡ (l₁ ++ [ mid ] ++ l₂))
splitMid/correct (x ∷ xs) (s≤s h) u =
let (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) = splitMid/clocked/correct ⌊ length (x ∷ xs) /2⌋ ⌊ pred (length (x ∷ xs)) /2⌋ (x ∷ xs) (N.⌊n/2⌋<n _)
(let open ≡-Reasoning in
begin
⌊ length (x ∷ xs) /2⌋ + suc ⌊ pred (length (x ∷ xs)) /2⌋
≡⟨⟩
⌊ length (x ∷ xs) /2⌋ + suc ⌊ length xs /2⌋
≡⟨⟩
⌈ length xs /2⌉ + suc ⌊ length xs /2⌋
≡⟨ N.+-suc ⌈ length xs /2⌉ ⌊ length xs /2⌋ ⟩
suc (⌈ length xs /2⌉ + ⌊ length xs /2⌋)
≡⟨ Eq.cong suc (N.+-comm ⌈ length xs /2⌉ ⌊ length xs /2⌋) ⟩
suc (⌊ length xs /2⌋ + ⌈ length xs /2⌉)
≡⟨ Eq.cong suc (N.⌊n/2⌋+⌈n/2⌉≡n (length xs)) ⟩
suc (length xs)
≡⟨⟩
length (x ∷ xs)
∎) u in
l₁ , mid , l₂ , ≡ , N.≤-reflexive h₁ , (
let open ≤-Reasoning in
begin
length l₂
≡⟨ h₂ ⟩
⌊ pred (length (x ∷ xs)) /2⌋
≤⟨ N.⌊n/2⌋-mono N.pred[n]≤n ⟩
⌊ length (x ∷ xs) /2⌋
∎
), ≡-↭
splitMid/cost : cmp (Π (list A) λ l → Π (U (meta (0 Nat.< length l))) λ _ → cost)
splitMid/cost (x ∷ xs) (s≤s h) = splitMid/clocked/cost ⌊ length (x ∷ xs) /2⌋ (x ∷ xs) (N.⌊n/2⌋<n _)
splitMid≤splitMid/cost : ∀ l h → IsBounded triple (splitMid l h) (splitMid/cost l h)
splitMid≤splitMid/cost (x ∷ xs) (s≤s h) = splitMid/clocked≤splitMid/clocked/cost ⌊ length (x ∷ xs) /2⌋ (x ∷ xs) (N.⌊n/2⌋<n _)
splitBy/clocked : cmp (Π nat λ _ → Π (list A) λ _ → Π A λ _ → F pair)
splitBy/clocked/aux : cmp (Π nat λ _ → Π A λ _ → Π (list A) λ _ → Π A λ _ → Π (list A) λ _ → Π bool λ _ → F pair)
splitBy/clocked zero l pivot = ret ([] , l)
splitBy/clocked (suc k) [] pivot = ret ([] , [])
splitBy/clocked (suc k) (x ∷ xs) pivot =
bind (F pair) (splitMid (x ∷ xs) (s≤s z≤n)) λ (l₁ , mid , l₂) →
bind (F pair) (mid ≤ᵇ pivot) (splitBy/clocked/aux k pivot l₁ mid l₂)
splitBy/clocked/aux k pivot l₁ mid l₂ false =
bind (F pair) (splitBy/clocked k l₁ pivot) λ (l₁₁ , l₁₂) → ret (l₁₁ , l₁₂ ++ mid ∷ l₂)
splitBy/clocked/aux k pivot l₁ mid l₂ true =
bind (F pair) (splitBy/clocked k l₂ pivot) λ (l₂₁ , l₂₂) → ret (l₁ ++ mid ∷ l₂₁ , l₂₂)
splitBy/clocked/correct : ∀ k l pivot → ⌈log₂ suc (length l) ⌉ Nat.≤ k →
◯ (∃ λ l₁ → ∃ λ l₂ → splitBy/clocked k l pivot ≡ ret (l₁ , l₂) × (Sorted l → All (_≤ pivot) l₁ × All (pivot ≤_) l₂) × l ≡ (l₁ ++ l₂))
splitBy/clocked/correct zero l pivot h u with ⌈log₂n⌉≡0⇒n≤1 {suc (length l)} (N.n≤0⇒n≡0 h)
splitBy/clocked/correct zero [] pivot h u | s≤s z≤n = [] , [] , refl , (λ _ → [] , []) , refl
splitBy/clocked/correct (suc k) [] pivot h u = [] , [] , refl , (λ _ → [] , []) , refl
splitBy/clocked/correct (suc k) (x ∷ xs) pivot (s≤s h) u with splitMid/correct (x ∷ xs) (s≤s z≤n) u
splitBy/clocked/correct (suc k) (x ∷ xs) pivot (s≤s h) u | (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) with h-cost mid pivot
splitBy/clocked/correct (suc k) (x ∷ xs) pivot (s≤s h) u | (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) | ⇓ b withCost q [ _ , h-eq ]
with ≤ᵇ-reflects-≤ u (Eq.trans (eq/ref h-eq) (step/ext (F bool) (ret b) q u)) | ≤-total mid pivot
splitBy/clocked/correct (suc k) (x ∷ xs) pivot (s≤s h) u | (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) | ⇓ b withCost q [ _ , h-eq ] | ofⁿ ¬p | inj₁ mid≤pivot = contradiction mid≤pivot ¬p
splitBy/clocked/correct (suc k) (x ∷ xs) pivot (s≤s h) u | (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) | ⇓ false withCost q [ _ , h-eq ] | ofⁿ ¬p | inj₂ pivot≤mid =
let (l₁₁ , l₁₂ , ≡' , h-sorted , ≡-↭') = splitBy/clocked/correct k l₁ pivot (
let open ≤-Reasoning in
begin
⌈log₂ suc (length l₁) ⌉
≤⟨ log₂-mono (s≤s h₁) ⟩
⌈log₂ suc ⌊ length (x ∷ xs) /2⌋ ⌉
≤⟨ h ⟩
k
∎
) u in
l₁₁ , l₁₂ ++ mid ∷ l₂ , (
let open ≡-Reasoning in
begin
splitBy/clocked (suc k) (x ∷ xs) pivot
≡⟨⟩
(bind (F pair) (splitMid (x ∷ xs) (s≤s z≤n)) λ (l₁ , mid , l₂) →
bind (F pair) (mid ≤ᵇ pivot) (splitBy/clocked/aux k pivot l₁ mid l₂))
≡⟨ Eq.cong (λ e → bind (F pair) e _) (≡) ⟩
bind (F pair) (mid ≤ᵇ pivot) (splitBy/clocked/aux k pivot l₁ mid l₂)
≡⟨ Eq.cong (λ e → bind (F pair) e (splitBy/clocked/aux k pivot l₁ mid l₂)) (eq/ref h-eq) ⟩
step (F pair) q (splitBy/clocked/aux k pivot l₁ mid l₂ false)
≡⟨ step/ext (F pair) (splitBy/clocked/aux k pivot l₁ mid l₂ false) q u ⟩
splitBy/clocked/aux k pivot l₁ mid l₂ false
≡⟨⟩
(bind (F pair) (splitBy/clocked k l₁ pivot) λ (l₁₁ , l₁₂) → ret (l₁₁ , l₁₂ ++ mid ∷ l₂))
≡⟨ Eq.cong (λ e → bind (F pair) e _) ≡' ⟩
ret (l₁₁ , l₁₂ ++ mid ∷ l₂)
∎
) , (
λ sorted →
let sorted' = Eq.subst Sorted ≡-↭ sorted in
let (h₁₁ , h₁₂) = h-sorted (++⁻ˡ l₁ sorted') in
h₁₁ , ++⁺-All h₁₂ (pivot≤mid ∷ ≤-≤* pivot≤mid (uncons₁ (++⁻ʳ l₁ sorted')))
) , (
let open ≡-Reasoning in
begin
(x ∷ xs)
≡⟨ ≡-↭ ⟩
l₁ ++ mid ∷ l₂
≡⟨ Eq.cong (_++ (mid ∷ l₂)) ≡-↭' ⟩
(l₁₁ ++ l₁₂) ++ mid ∷ l₂
≡⟨ ++-assoc l₁₁ l₁₂ (mid ∷ l₂) ⟩
l₁₁ ++ (l₁₂ ++ mid ∷ l₂)
∎
)
splitBy/clocked/correct (suc k) (x ∷ xs) pivot (s≤s h) u | (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) | ⇓ true withCost q [ _ , h-eq ] | ofʸ p | _ =
let (l₂₁ , l₂₂ , ≡' , h-sorted , ≡-↭') = splitBy/clocked/correct k l₂ pivot (
let open ≤-Reasoning in
begin
⌈log₂ suc (length l₂) ⌉
≤⟨ log₂-mono (s≤s h₂) ⟩
⌈log₂ suc ⌊ length (x ∷ xs) /2⌋ ⌉
≤⟨ h ⟩
k
∎
) u in
l₁ ++ mid ∷ l₂₁ , l₂₂ , (
let open ≡-Reasoning in
begin
splitBy/clocked (suc k) (x ∷ xs) pivot
≡⟨⟩
(bind (F pair) (splitMid (x ∷ xs) (s≤s z≤n)) λ (l₁ , mid , l₂) →
bind (F pair) (mid ≤ᵇ pivot) (splitBy/clocked/aux k pivot l₁ mid l₂))
≡⟨ Eq.cong (λ e → bind (F pair) e _) (≡) ⟩
bind (F pair) (mid ≤ᵇ pivot) (splitBy/clocked/aux k pivot l₁ mid l₂)
≡⟨ Eq.cong (λ e → bind (F pair) e (splitBy/clocked/aux k pivot l₁ mid l₂)) (eq/ref h-eq) ⟩
step (F pair) q (splitBy/clocked/aux k pivot l₁ mid l₂ true)
≡⟨ step/ext (F pair) (splitBy/clocked/aux k pivot l₁ mid l₂ true) q u ⟩
splitBy/clocked/aux k pivot l₁ mid l₂ true
≡⟨⟩
(bind (F pair) (splitBy/clocked k l₂ pivot) λ (l₂₁ , l₂₂) → ret (l₁ ++ mid ∷ l₂₁ , l₂₂))
≡⟨ Eq.cong (λ e → bind (F pair) e _) ≡' ⟩
ret (l₁ ++ mid ∷ l₂₁ , l₂₂)
∎
) , (
λ sorted →
let sorted' = Eq.subst Sorted ≡-↭ sorted in
let (h₂₁ , h₂₂) = h-sorted (uncons₂ (++⁻ʳ l₁ sorted')) in
++⁺-All
(map (λ h → ≤-trans h p) (split-sorted₁ l₁ (++⁻ˡ (l₁ ∷ʳ mid) (Eq.subst Sorted (Eq.sym (++-assoc l₁ [ mid ] l₂)) sorted'))))
(p ∷ h₂₁) ,
h₂₂
) , (
let open ≡-Reasoning in
begin
(x ∷ xs)
≡⟨ ≡-↭ ⟩
l₁ ++ mid ∷ l₂
≡⟨ Eq.cong (λ l₂ → l₁ ++ mid ∷ l₂) ≡-↭' ⟩
l₁ ++ mid ∷ (l₂₁ ++ l₂₂)
≡˘⟨ ++-assoc l₁ (mid ∷ l₂₁) l₂₂ ⟩
(l₁ ++ mid ∷ l₂₁) ++ l₂₂
∎
)
splitBy/clocked/cost : cmp (Π nat λ _ → Π (list A) λ _ → Π A λ _ → cost)
splitBy/clocked/cost/aux : cmp (Π nat λ _ → Π A λ _ → Π (list A) λ _ → Π A λ _ → Π (list A) λ _ → Π bool λ _ → cost)
splitBy/clocked/cost zero l pivot = 𝟘
splitBy/clocked/cost (suc k) [] pivot = 𝟘
splitBy/clocked/cost (suc k) (x ∷ xs) pivot =
bind cost (splitMid (x ∷ xs) (s≤s z≤n)) λ (l₁ , mid , l₂) → splitMid/cost (x ∷ xs) (s≤s z≤n) ⊕
bind cost (mid ≤ᵇ pivot) λ b → (1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b
splitBy/clocked/cost/aux k pivot l₁ mid l₂ false =
bind cost (splitBy/clocked k l₁ pivot) λ (l₁₁ , l₁₂) → splitBy/clocked/cost k l₁ pivot ⊕ 𝟘
splitBy/clocked/cost/aux k pivot l₁ mid l₂ true =
bind cost (splitBy/clocked k l₂ pivot) λ (l₂₁ , l₂₂) → splitBy/clocked/cost k l₂ pivot ⊕ 𝟘
splitBy/clocked/cost/closed : cmp (Π nat λ _ → Π (list A) λ _ → Π A λ _ → cost)
splitBy/clocked/cost/closed k _ _ = k , k
splitBy/clocked/cost≤splitBy/clocked/cost/closed : ∀ k l pivot → ⌈log₂ suc (length l) ⌉ Nat.≤ k →
◯ (splitBy/clocked/cost k l pivot ≤ₚ splitBy/clocked/cost/closed k l pivot)
splitBy/clocked/cost/aux≤k : ∀ k pivot l₁ mid l₂ b → ⌈log₂ suc (length l₁) ⌉ Nat.≤ k → ⌈log₂ suc (length l₂) ⌉ Nat.≤ k →
◯ (splitBy/clocked/cost/aux k pivot l₁ mid l₂ b ≤ₚ (k , k))
splitBy/clocked/cost≤splitBy/clocked/cost/closed zero l pivot h u = z≤n , z≤n
splitBy/clocked/cost≤splitBy/clocked/cost/closed (suc k) [] pivot h u = z≤n , z≤n
splitBy/clocked/cost≤splitBy/clocked/cost/closed (suc k) (x ∷ xs) pivot (s≤s h) u with splitMid/correct (x ∷ xs) (s≤s z≤n) u
... | (l₁ , mid , l₂ , ≡ , h₁ , h₂ , ≡-↭) with h-cost mid pivot
... | ⇓ b withCost q [ _ , h-eq ] =
begin
splitBy/clocked/cost (suc k) (x ∷ xs) pivot
≡⟨⟩
(bind cost (splitMid (x ∷ xs) (s≤s z≤n)) λ (l₁ , mid , l₂) → splitMid/cost (x ∷ xs) (s≤s z≤n) ⊕
bind cost (mid ≤ᵇ pivot) λ b → (1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b)
≡⟨ Eq.cong (λ e → bind cost e _) (≡) ⟩
(splitMid/cost (x ∷ xs) (s≤s z≤n) ⊕
bind cost (mid ≤ᵇ pivot) λ b → (1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b)
≡⟨⟩
(𝟘 ⊕
bind cost (mid ≤ᵇ pivot) λ b → (1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b)
≡⟨ ⊕-identityˡ _ ⟩
(bind cost (mid ≤ᵇ pivot) λ b → (1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b)
≡⟨ Eq.cong (λ e → bind cost e λ b → (1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b) (eq/ref h-eq) ⟩
step cost q ((1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b)
≡⟨ step/ext cost _ q u ⟩
(1 , 1) ⊕ splitBy/clocked/cost/aux k pivot l₁ mid l₂ b
≤⟨
⊕-monoʳ-≤ (1 , 1) (
splitBy/clocked/cost/aux≤k k pivot l₁ mid l₂ b
(N.≤-trans (log₂-mono (s≤s h₁)) h)
(N.≤-trans (log₂-mono (s≤s h₂)) h)
u
)
⟩
(1 , 1) ⊕ (k , k)
≡⟨⟩
(suc k , suc k)
≡⟨⟩
splitBy/clocked/cost/closed (suc k) (x ∷ xs) pivot
∎
where open ≤ₚ-Reasoning
splitBy/clocked/cost/aux≤k k pivot l₁ mid l₂ false h₁ h₂ u =
let (l₁₁ , l₁₂ , ≡' , _ , ≡-↭') = splitBy/clocked/correct k l₁ pivot h₁ u in
begin
splitBy/clocked/cost/aux k pivot l₁ mid l₂ false
≡⟨⟩
(bind cost (splitBy/clocked k l₁ pivot) λ (l₁₁ , l₁₂) → splitBy/clocked/cost k l₁ pivot ⊕ 𝟘)
≡⟨ Eq.cong (λ e → bind cost e λ (l₁₁ , l₁₂) → splitBy/clocked/cost k l₁ pivot ⊕ 𝟘) ≡' ⟩
splitBy/clocked/cost k l₁ pivot ⊕ 𝟘
≡⟨ ⊕-identityʳ _ ⟩
splitBy/clocked/cost k l₁ pivot
≤⟨ splitBy/clocked/cost≤splitBy/clocked/cost/closed k l₁ pivot h₁ u ⟩
(k , k)
∎
where open ≤ₚ-Reasoning
splitBy/clocked/cost/aux≤k k pivot l₁ mid l₂ true h₁ h₂ u =
let (l₂₁ , l₂₂ , ≡' , _ , ≡-↭') = splitBy/clocked/correct k l₂ pivot h₂ u in
begin
splitBy/clocked/cost/aux k pivot l₁ mid l₂ true
≡⟨⟩
(bind cost (splitBy/clocked k l₂ pivot) λ (l₂₁ , l₂₂) → splitBy/clocked/cost k l₂ pivot ⊕ 𝟘)
≡⟨ Eq.cong (λ e → bind cost e λ (l₂₁ , l₂₂) → splitBy/clocked/cost k l₂ pivot ⊕ 𝟘) ≡' ⟩
splitBy/clocked/cost k l₂ pivot ⊕ 𝟘
≡⟨ ⊕-identityʳ _ ⟩
splitBy/clocked/cost k l₂ pivot
≤⟨ splitBy/clocked/cost≤splitBy/clocked/cost/closed k l₂ pivot h₂ u ⟩
(k , k)
∎
where open ≤ₚ-Reasoning
splitBy/clocked≤splitBy/clocked/cost : ∀ k l pivot → IsBounded pair (splitBy/clocked k l pivot) (splitBy/clocked/cost k l pivot)
splitBy/clocked≤splitBy/clocked/cost zero l pivot = bound/ret
splitBy/clocked≤splitBy/clocked/cost (suc k) [] pivot = bound/ret
splitBy/clocked≤splitBy/clocked/cost (suc k) (x ∷ xs) pivot =
bound/bind {e = splitMid (x ∷ xs) (s≤s z≤n)} (splitMid/cost (x ∷ xs) (s≤s z≤n)) _ (splitMid≤splitMid/cost (x ∷ xs) (s≤s z≤n)) λ (l₁ , mid , l₂) →
bound/bind (1 , 1) _ (h-cost mid pivot)
λ { false → bound/bind (splitBy/clocked/cost k l₁ pivot) (λ _ → 𝟘) (splitBy/clocked≤splitBy/clocked/cost k l₁ pivot) λ _ → bound/ret
; true → bound/bind (splitBy/clocked/cost k l₂ pivot) (λ _ → 𝟘) (splitBy/clocked≤splitBy/clocked/cost k l₂ pivot) λ _ → bound/ret }
splitBy/clocked≤splitBy/clocked/cost/closed : ∀ k l pivot → ⌈log₂ suc (length l) ⌉ Nat.≤ k → IsBounded pair (splitBy/clocked k l pivot) (splitBy/clocked/cost/closed k l pivot)
splitBy/clocked≤splitBy/clocked/cost/closed k l pivot h = bound/relax (splitBy/clocked/cost≤splitBy/clocked/cost/closed k l pivot h) (splitBy/clocked≤splitBy/clocked/cost k l pivot)
splitBy : cmp (Π (list A) λ _ → Π A λ _ → F pair)
splitBy l pivot = splitBy/clocked ⌈log₂ suc (length l) ⌉ l pivot
splitBy/correct : ∀ l pivot →
◯ (∃ λ l₁ → ∃ λ l₂ → splitBy l pivot ≡ ret (l₁ , l₂) × (Sorted l → All (_≤ pivot) l₁ × All (pivot ≤_) l₂) × l ≡ (l₁ ++ l₂))
splitBy/correct l pivot = splitBy/clocked/correct ⌈log₂ suc (length l) ⌉ l pivot N.≤-refl
splitBy/cost : cmp (Π (list A) λ _ → Π A λ _ → cost)
splitBy/cost l pivot = splitBy/clocked/cost ⌈log₂ suc (length l) ⌉ l pivot
splitBy/cost/closed : cmp (Π (list A) λ _ → Π A λ _ → cost)
splitBy/cost/closed l pivot = splitBy/clocked/cost/closed ⌈log₂ suc (length l) ⌉ l pivot
splitBy≤splitBy/cost : ∀ l pivot → IsBounded pair (splitBy l pivot) (splitBy/cost l pivot)
splitBy≤splitBy/cost l pivot = splitBy/clocked≤splitBy/clocked/cost ⌈log₂ suc (length l) ⌉ l pivot
splitBy≤splitBy/cost/closed : ∀ l pivot → IsBounded pair (splitBy l pivot) (splitBy/cost/closed l pivot)
splitBy≤splitBy/cost/closed l pivot = splitBy/clocked≤splitBy/clocked/cost/closed ⌈log₂ suc (length l) ⌉ l pivot N.≤-refl
merge/clocked : cmp (Π nat λ _ → Π pair λ _ → F (list A))
merge/clocked zero (l₁ , l₂) = ret (l₁ ++ l₂)
merge/clocked (suc k) ([] , l₂) = ret l₂
merge/clocked (suc k) (x ∷ l₁ , l₂) =
bind (F (list A)) (splitMid (x ∷ l₁) (s≤s z≤n)) λ (l₁₁ , pivot , l₁₂) →
bind (F (list A)) (splitBy l₂ pivot) λ (l₂₁ , l₂₂) →
bind (F (list A)) (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') →
ret (l₁' ++ pivot ∷ l₂')
merge/clocked/correct : ∀ k l₁ l₂ → ⌈log₂ suc (length l₁) ⌉ Nat.≤ k →
◯ (∃ λ l → merge/clocked k (l₁ , l₂) ≡ ret l × (Sorted l₁ → Sorted l₂ → SortedOf (l₁ ++ l₂) l))
merge/clocked/correct zero l₁ l₂ h-clock u with ⌈log₂n⌉≡0⇒n≤1 {suc (length l₁)} (N.n≤0⇒n≡0 h-clock)
merge/clocked/correct zero [] l₂ h-clock u | s≤s z≤n = l₂ , refl , (λ sorted₁ sorted₂ → refl , sorted₂)
merge/clocked/correct (suc k) [] l₂ h-clock u = l₂ , refl , (λ sorted₁ sorted₂ → refl , sorted₂)
merge/clocked/correct (suc k) (x ∷ l₁) l₂ h-clock u =
let (l₁₁ , pivot , l₁₂ , ≡ , h₁₁ , h₁₂ , ≡-↭) = splitMid/correct (x ∷ l₁) (s≤s z≤n) u in
let (l₂₁ , l₂₂ , ≡' , h-sorted₂ , ≡-↭') = splitBy/correct l₂ pivot u in
let (l₁' , ≡₁' , h-sorted₁') = merge/clocked/correct k l₁₁ l₂₁
(let open ≤-Reasoning in
begin
⌈log₂ suc (length l₁₁) ⌉
≤⟨ log₂-mono (s≤s h₁₁) ⟩
⌈log₂ ⌈ suc (length (x ∷ l₁)) /2⌉ ⌉
≤⟨ log₂-suc (suc (length (x ∷ l₁))) h-clock ⟩
k
∎)
u in
let (l₂' , ≡₂' , h-sorted₂') = merge/clocked/correct k l₁₂ l₂₂
(let open ≤-Reasoning in
begin
⌈log₂ suc (length l₁₂) ⌉
≤⟨ log₂-mono (s≤s h₁₂) ⟩
⌈log₂ ⌈ suc (length (x ∷ l₁)) /2⌉ ⌉
≤⟨ log₂-suc (suc (length (x ∷ l₁))) h-clock ⟩
k
∎)
u in
l₁' ++ pivot ∷ l₂' , (
let open ≡-Reasoning in
begin
merge/clocked (suc k) (x ∷ l₁ , l₂)
≡⟨⟩
(bind (F (list A)) (splitMid (x ∷ l₁) (s≤s z≤n)) λ (l₁₁ , pivot , l₁₂) →
bind (F (list A)) (splitBy l₂ pivot) λ (l₂₁ , l₂₂) →
bind (F (list A)) (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') →
ret (l₁' ++ pivot ∷ l₂'))
≡⟨ Eq.cong (λ e → bind (F (list A)) e _) (≡) ⟩
(bind (F (list A)) (splitBy l₂ pivot) λ (l₂₁ , l₂₂) →
bind (F (list A)) (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') →
ret (l₁' ++ pivot ∷ l₂'))
≡⟨ Eq.cong (λ e → bind (F (list A)) e _) (≡') ⟩
(bind (F (list A)) (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') →
ret (l₁' ++ pivot ∷ l₂'))
≡⟨ Eq.cong (λ e → bind (F (list A)) e _) (Eq.cong₂ _&_ ≡₁' ≡₂') ⟩
ret (l₁' ++ pivot ∷ l₂')
∎
) ,
λ sorted₁ sorted₂ →
let (h₂₁ , h₂₂) = h-sorted₂ sorted₂ in
let sorted₁ = Eq.subst Sorted ≡-↭ sorted₁
sorted₂ = Eq.subst Sorted ≡-↭' sorted₂ in
let (↭₁' , sorted₁') = h-sorted₁' (++⁻ˡ l₁₁ sorted₁) (++⁻ˡ l₂₁ sorted₂)
(↭₂' , sorted₂') = h-sorted₂' (uncons₂ (++⁻ʳ l₁₁ sorted₁)) (++⁻ʳ l₂₁ sorted₂) in
(
let open PermutationReasoning in
begin
(x ∷ l₁) ++ l₂
≡⟨ Eq.cong₂ (_++_) ≡-↭ ≡-↭' ⟩
(l₁₁ ++ pivot ∷ l₁₂) ++ (l₂₁ ++ l₂₂)
≡⟨ ++-assoc l₁₁ (pivot ∷ l₁₂) (l₂₁ ++ l₂₂) ⟩
l₁₁ ++ (pivot ∷ l₁₂ ++ (l₂₁ ++ l₂₂))
↭⟨ ++⁺ˡ-↭ l₁₁ (++⁺ˡ-↭ (pivot ∷ l₁₂) (++-comm-↭ l₂₁ l₂₂)) ⟩
l₁₁ ++ (pivot ∷ l₁₂ ++ (l₂₂ ++ l₂₁))
≡˘⟨ Eq.cong (l₁₁ ++_) (++-assoc (pivot ∷ l₁₂) l₂₂ l₂₁) ⟩
l₁₁ ++ ((pivot ∷ l₁₂ ++ l₂₂) ++ l₂₁)
↭⟨ ++⁺ˡ-↭ l₁₁ (++-comm-↭ (pivot ∷ l₁₂ ++ l₂₂) l₂₁) ⟩
l₁₁ ++ (l₂₁ ++ (pivot ∷ l₁₂ ++ l₂₂))
≡˘⟨ ++-assoc l₁₁ l₂₁ (pivot ∷ l₁₂ ++ l₂₂) ⟩
(l₁₁ ++ l₂₁) ++ (pivot ∷ l₁₂ ++ l₂₂)
≡⟨⟩
(l₁₁ ++ l₂₁) ++ pivot ∷ (l₁₂ ++ l₂₂)
↭⟨ ++⁺-↭ ↭₁' (prep pivot ↭₂') ⟩
l₁' ++ pivot ∷ l₂'
∎
) ,
join-sorted
sorted₁'
sorted₂'
(All-resp-↭ ↭₁' (++⁺-All (split-sorted₁ l₁₁ (++⁻ˡ (l₁₁ ∷ʳ pivot) (Eq.subst Sorted (Eq.sym (++-assoc l₁₁ [ pivot ] l₁₂)) sorted₁))) h₂₁))
(All-resp-↭ ↭₂' (++⁺-All (uncons₁ (++⁻ʳ l₁₁ sorted₁)) h₂₂))
merge/clocked/cost : cmp (Π nat λ _ → Π pair λ _ → cost)
merge/clocked/cost zero (l₁ , l₂) = 𝟘
merge/clocked/cost (suc k) ([] , l₂) = 𝟘
merge/clocked/cost (suc k) (x ∷ l₁ , l₂) =
bind cost (splitMid (x ∷ l₁) (s≤s z≤n)) λ (l₁₁ , pivot , l₁₂) → splitMid/cost (x ∷ l₁) (s≤s z≤n) ⊕
bind cost (splitBy l₂ pivot) λ (l₂₁ , l₂₂) → splitBy/cost/closed l₂ pivot ⊕
bind cost (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘
merge/clocked/cost/closed : cmp (Π nat λ _ → Π pair λ _ → cost)
merge/clocked/cost/closed k (l₁ , l₂) = pred[2^ k ] * ⌈log₂ suc (length l₂) ⌉ , k * ⌈log₂ suc (length l₂) ⌉
merge/clocked/cost≤merge/clocked/cost/closed : ∀ k l₁ l₂ → ⌈log₂ suc (length l₁) ⌉ Nat.≤ k →
◯ (merge/clocked/cost k (l₁ , l₂) ≤ₚ merge/clocked/cost/closed k (l₁ , l₂))
merge/clocked/cost≤merge/clocked/cost/closed zero l₁ l₂ h-clock u = z≤n , z≤n
merge/clocked/cost≤merge/clocked/cost/closed (suc k) [] l₂ h-clock u = z≤n , z≤n
merge/clocked/cost≤merge/clocked/cost/closed (suc k) (x ∷ l₁) l₂ h-clock u =
let (l₁₁ , pivot , l₁₂ , ≡-splitMid , h₁₁ , h₁₂ , ≡-↭) = splitMid/correct (x ∷ l₁) (s≤s z≤n) u in
let (l₂₁ , l₂₂ , ≡' , _ , ≡-↭') = splitBy/correct l₂ pivot u in
let h₁ : ⌈log₂ suc (length l₁₁) ⌉ Nat.≤ k
h₁ =
let open ≤-Reasoning in
begin
⌈log₂ suc (length l₁₁) ⌉
≤⟨ log₂-mono (s≤s h₁₁) ⟩
⌈log₂ ⌈ suc (length (x ∷ l₁)) /2⌉ ⌉
≤⟨ log₂-suc (suc (length (x ∷ l₁))) h-clock ⟩
k
∎
h₂ : ⌈log₂ suc (length l₁₂) ⌉ Nat.≤ k
h₂ =
let open ≤-Reasoning in
begin
⌈log₂ suc (length l₁₂) ⌉
≤⟨ log₂-mono (s≤s h₁₂) ⟩
⌈log₂ ⌈ suc (length (x ∷ l₁)) /2⌉ ⌉
≤⟨ log₂-suc (suc (length (x ∷ l₁))) h-clock ⟩
k
∎
in
let (l₁' , ≡₁' , _) = merge/clocked/correct k l₁₁ l₂₁ h₁ u in
let (l₂' , ≡₂' , _) = merge/clocked/correct k l₁₂ l₂₂ h₂ u in
let open ≤ₚ-Reasoning in
begin
(bind cost (splitMid (x ∷ l₁) (s≤s z≤n)) λ (l₁₁ , pivot , l₁₂) → splitMid/cost (x ∷ l₁) (s≤s z≤n) ⊕
bind cost (splitBy l₂ pivot) λ (l₂₁ , l₂₂) → splitBy/cost/closed l₂ pivot ⊕
bind cost (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘)
≡⟨ Eq.cong (λ e → bind cost e λ (l₁₁ , pivot , l₁₂) → splitMid/cost (x ∷ l₁) (s≤s z≤n) ⊕ _) ≡-splitMid ⟩
(splitMid/cost (x ∷ l₁) (s≤s z≤n) ⊕
bind cost (splitBy l₂ pivot) λ (l₂₁ , l₂₂) → splitBy/cost/closed l₂ pivot ⊕
bind cost (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘)
≡⟨⟩
(𝟘 ⊕
bind cost (splitBy l₂ pivot) λ (l₂₁ , l₂₂) → splitBy/cost/closed l₂ pivot ⊕
bind cost (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘)
≡⟨ ⊕-identityˡ _ ⟩
(bind cost (splitBy l₂ pivot) λ (l₂₁ , l₂₂) → splitBy/cost/closed l₂ pivot ⊕
bind cost (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘)
≡⟨
Eq.cong
(λ e →
bind cost e λ (l₂₁ , l₂₂) → splitBy/cost/closed l₂ pivot ⊕
bind cost (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘)
≡'
⟩
(splitBy/cost/closed l₂ pivot ⊕
bind cost (merge/clocked k (l₁₁ , l₂₁) & merge/clocked k (l₁₂ , l₂₂)) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘)
≡⟨
Eq.cong₂
(λ e₁ e₂ →
splitBy/cost/closed l₂ pivot ⊕
bind cost (e₁ & e₂) λ (l₁' , l₂') → (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕
𝟘)
≡₁'
≡₂' ⟩
splitBy/cost/closed l₂ pivot ⊕ ((merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) ⊕ 𝟘)
≡⟨ Eq.cong (splitBy/cost/closed l₂ pivot ⊕_) (⊕-identityʳ _) ⟩
splitBy/cost/closed l₂ pivot ⊕ (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂))
≤⟨
⊕-monoʳ-≤ (splitBy/cost/closed l₂ pivot) (
⊗-mono-≤
(merge/clocked/cost≤merge/clocked/cost/closed k l₁₁ l₂₁ h₁ u)
(merge/clocked/cost≤merge/clocked/cost/closed k l₁₂ l₂₂ h₂ u)
)
⟩
splitBy/cost/closed l₂ pivot ⊕ (merge/clocked/cost/closed k (l₁₁ , l₂₁) ⊗ merge/clocked/cost/closed k (l₁₂ , l₂₂))
≡⟨⟩
(⌈log₂ suc (length l₂) ⌉ , ⌈log₂ suc (length l₂) ⌉) ⊕
((pred[2^ k ] * ⌈log₂ suc (length l₂₁) ⌉ , k * ⌈log₂ suc (length l₂₁) ⌉) ⊗
(pred[2^ k ] * ⌈log₂ suc (length l₂₂) ⌉ , k * ⌈log₂ suc (length l₂₂) ⌉))
≤⟨
⊕-monoʳ-≤ (⌈log₂ suc (length l₂) ⌉ , ⌈log₂ suc (length l₂) ⌉) (
let h-length : length l₂₁ + length l₂₂ ≡ length l₂
h-length = Eq.sym (Eq.trans (Eq.cong length ≡-↭') (length-++ l₂₁))
h₁ : ⌈log₂ suc (length l₂₁) ⌉ Nat.≤ ⌈log₂ suc (length l₂) ⌉
h₁ = log₂-mono (s≤s (N.m+n≤o⇒m≤o (length l₂₁) (N.≤-reflexive h-length)))
h₂ : ⌈log₂ suc (length l₂₂) ⌉ Nat.≤ ⌈log₂ suc (length l₂) ⌉
h₂ = log₂-mono (s≤s (N.m+n≤o⇒n≤o (length l₂₁) (N.≤-reflexive h-length)))
in
⊗-mono-≤
(N.*-monoʳ-≤ pred[2^ k ] h₁ , N.*-monoʳ-≤ k h₁)
(N.*-monoʳ-≤ pred[2^ k ] h₂ , N.*-monoʳ-≤ k h₂)
)
⟩
(⌈log₂ suc (length l₂) ⌉ , ⌈log₂ suc (length l₂) ⌉) ⊕
((pred[2^ k ] * ⌈log₂ suc (length l₂) ⌉ , k * ⌈log₂ suc (length l₂) ⌉) ⊗
(pred[2^ k ] * ⌈log₂ suc (length l₂) ⌉ , k * ⌈log₂ suc (length l₂) ⌉))
≡⟨ Eq.cong₂ _,_ (arithmetic/work ⌈log₂ suc (length l₂) ⌉) (arithmetic/span ⌈log₂ suc (length l₂) ⌉) ⟩
pred[2^ suc k ] * ⌈log₂ suc (length l₂) ⌉ , suc k * ⌈log₂ suc (length l₂) ⌉
≡⟨⟩
merge/clocked/cost/closed (suc k) (x ∷ l₁ , l₂)
∎
where
arithmetic/work : ∀ n → n + (pred[2^ k ] * n + pred[2^ k ] * n) ≡ pred[2^ suc k ] * n
arithmetic/work n =
begin
n + (pred[2^ k ] * n + pred[2^ k ] * n)
≡˘⟨ Eq.cong (n +_) (N.*-distribʳ-+ n (pred[2^ k ]) (pred[2^ k ])) ⟩
n + (pred[2^ k ] + pred[2^ k ]) * n
≡⟨⟩
suc (pred[2^ k ] + pred[2^ k ]) * n
≡⟨ Eq.cong (_* n) (pred[2^suc[n]] k) ⟩
pred[2^ suc k ] * n
∎
where open ≡-Reasoning
arithmetic/span : ∀ n → n + (k * n ⊔ k * n) ≡ suc k * n
arithmetic/span n =
begin
n + (k * n ⊔ k * n)
≡⟨ Eq.cong (n +_) (N.⊔-idem (k * n)) ⟩
n + k * n
≡⟨⟩
suc k * n
∎
where open ≡-Reasoning
merge/clocked≤merge/clocked/cost : ∀ k l₁ l₂ → IsBounded (list A) (merge/clocked k (l₁ , l₂)) (merge/clocked/cost k (l₁ , l₂))
merge/clocked≤merge/clocked/cost zero l₁ l₂ = bound/ret
merge/clocked≤merge/clocked/cost (suc k) [] l₂ = bound/ret
merge/clocked≤merge/clocked/cost (suc k) (x ∷ l₁) l₂ =
bound/bind (splitMid/cost (x ∷ l₁) (s≤s z≤n)) _ (splitMid≤splitMid/cost (x ∷ l₁) (s≤s z≤n)) λ (l₁₁ , pivot , l₁₂) →
bound/bind (splitBy/cost/closed l₂ pivot) _ (splitBy≤splitBy/cost/closed l₂ pivot) λ (l₂₁ , l₂₂) →
bound/bind (merge/clocked/cost k (l₁₁ , l₂₁) ⊗ merge/clocked/cost k (l₁₂ , l₂₂)) _ (bound/par (merge/clocked≤merge/clocked/cost k l₁₁ l₂₁) (merge/clocked≤merge/clocked/cost k l₁₂ l₂₂)) λ (l₁' , l₂') →
bound/ret
merge/clocked≤merge/clocked/cost/closed : ∀ k l₁ l₂ → ⌈log₂ suc (length l₁) ⌉ Nat.≤ k →
IsBounded (list A) (merge/clocked k (l₁ , l₂)) (merge/clocked/cost/closed k (l₁ , l₂))
merge/clocked≤merge/clocked/cost/closed k l₁ l₂ h =
bound/relax (merge/clocked/cost≤merge/clocked/cost/closed k l₁ l₂ h) (merge/clocked≤merge/clocked/cost k l₁ l₂)
merge : cmp (Π pair λ _ → F (list A))
merge (l₁ , l₂) = merge/clocked ⌈log₂ suc (length l₁) ⌉ (l₁ , l₂)
merge/correct : ∀ l₁ l₂ →
◯ (∃ λ l → merge (l₁ , l₂) ≡ ret l × (Sorted l₁ → Sorted l₂ → SortedOf (l₁ ++ l₂) l))
merge/correct l₁ l₂ = merge/clocked/correct ⌈log₂ suc (length l₁) ⌉ l₁ l₂ N.≤-refl
merge/cost : cmp (Π pair λ _ → cost)
merge/cost (l₁ , l₂) = merge/clocked/cost ⌈log₂ suc (length l₁) ⌉ (l₁ , l₂)
merge/cost/closed : cmp (Π pair λ _ → cost)
merge/cost/closed (l₁ , l₂) = merge/clocked/cost/closed ⌈log₂ suc (length l₁) ⌉ (l₁ , l₂)
merge≤merge/cost : ∀ l₁ l₂ → IsBounded (list A) (merge (l₁ , l₂)) (merge/cost (l₁ , l₂))
merge≤merge/cost l₁ l₂ = merge/clocked≤merge/clocked/cost ⌈log₂ suc (length l₁) ⌉ l₁ l₂
merge≤merge/cost/closed : ∀ l₁ l₂ → IsBounded (list A) (merge (l₁ , l₂)) (merge/cost/closed (l₁ , l₂))
merge≤merge/cost/closed l₁ l₂ = merge/clocked≤merge/clocked/cost/closed ⌈log₂ suc (length l₁) ⌉ l₁ l₂ N.≤-refl
| {
"alphanum_fraction": 0.5246607727,
"avg_line_length": 51.0396694215,
"ext": "agda",
"hexsha": "b3d9eb49678ba12fd70ccae5505f6f61e3928c66",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Examples/Sorting/Parallel/MergeSortPar/Merge.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Examples/Sorting/Parallel/MergeSortPar/Merge.agda",
"max_line_length": 206,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Examples/Sorting/Parallel/MergeSortPar/Merge.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 13303,
"size": 30879
} |
module Data.List.Instance where
open import Category.FAM
open import Data.List
open import Data.List.Properties
open import Function using (_$_)
open import Relation.Binary.PropositionalEquality hiding ([_])
instance
ListFunctor : ∀ {ℓ} → Functor {ℓ} List
ListFunctor = record
{ _<$>_ = map
; isFunctor = record
{ identity = map-id
; homo = λ f g a → map-compose a
}
}
ListApplicative : ∀ {ℓ} → Applicative {ℓ} List
ListApplicative {ℓ} = record
{ pure = [_]
; _⊛_ = λ fs xs → concat (map (flip map xs) fs)
; isApplicative = record
{ identity = λ xs → begin
map id xs ++ []
≡⟨ ++-identityʳ (map id xs) ⟩
map id xs
≡⟨ map-id xs ⟩
xs
∎
; compose = compose
; homo = λ _ _ → refl
; interchange = interchange
}
}
where
open ≡-Reasoning
open import Function
concat-∷ : {A : Set ℓ} (xs : List A) (xss : List (List A))
→ concat (xs ∷ xss) ≡ xs ++ concat xss
concat-∷ [] xss = refl
concat-∷ (x ∷ xs) xss = refl
concat-++ : {A : Set ℓ} (xs ys : List (List A))
→ concat (xs ++ ys) ≡ concat xs ++ concat ys
concat-++ [] ys = refl
concat-++ (xs ∷ xss) ys = begin
concat ((xs ∷ xss) ++ ys)
≡⟨ refl ⟩
concat (xs ∷ xss ++ ys)
≡⟨ concat-∷ xs (xss ++ ys) ⟩
xs ++ concat (xss ++ ys)
≡⟨ cong (λ x → xs ++ x) (concat-++ xss ys) ⟩
xs ++ concat xss ++ concat ys
≡⟨ sym (++-assoc xs (concat xss) (concat ys)) ⟩
(xs ++ concat xss) ++ concat ys
≡⟨ cong (λ x → x ++ concat ys) (sym (concat-∷ xs xss)) ⟩
concat (xs ∷ xss) ++ concat ys
∎
lemma : {A B C : Set ℓ} (f : B → C) (gs : List (A → B)) (xs : List A)
→ map (flip map xs) (flip map gs (_∘′_ f)) ≡ map (map f) (map (flip map xs) gs)
lemma f [] xs = refl
lemma f (g ∷ gs) xs =
let shit = map (flip map xs) (map (_∘′_ f) gs) in
begin
flip map xs (f ∘′ g) ∷ shit
≡⟨ refl ⟩
map (f ∘′ g) xs ∷ shit
≡⟨ cong (λ x → x ∷ shit) (map-compose xs) ⟩
map f (map g xs) ∷ shit
≡⟨ refl ⟩
map f (flip map xs g) ∷ shit
≡⟨ cong (λ x → map f (flip map xs g) ∷ x) (lemma f gs xs) ⟩
map f (flip map xs g) ∷ map (map f) (map (flip map xs) gs)
∎
compose : {A B C : Set ℓ} (fs : List (B → C)) (gs : List (A → B)) (xs : List A)
→ concat (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))
≡ concat (map (flip map (concat (map (flip map xs) gs))) fs)
compose [] gs xs = refl
compose (f ∷ fs) gs xs =
begin
concat (map (flip map xs) (concat (flip map gs (_∘′_ f) ∷ map (flip map gs) (map _∘′_ fs ++ []))))
≡⟨ cong (λ x → concat (map (flip map xs) x)) (concat-∷ (flip map gs (_∘′_ f)) (map (flip map gs) (map _∘′_ fs ++ []))) ⟩
concat (map (flip map xs) (flip map gs (_∘′_ f) ++ concat (map (flip map gs) (map _∘′_ fs ++ []))))
≡⟨ cong concat (map-++-commute (flip map xs) (flip map gs (_∘′_ f)) (concat (map (flip map gs) (map _∘′_ fs ++ [])))) ⟩
concat (map (flip map xs) (flip map gs (_∘′_ f)) ++ map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))
≡⟨ concat-++ (map (flip map xs) (flip map gs (_∘′_ f))) (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ [])))) ⟩
concat (map (flip map xs) (flip map gs (_∘′_ f))) ++ concat (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))
≡⟨ cong (λ x → concat x ++ concat (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))) (lemma f gs xs) ⟩
concat (map (map f) (map (flip map xs) gs)) ++ concat (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))
≡⟨ cong (λ x → x ++ concat (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))) (concat-map ((map (flip map xs) gs)))⟩
map f (concat (map (flip map xs) gs)) ++ concat (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))
≡⟨ refl ⟩
flip map (concat (map (flip map xs) gs)) f ++ concat (map (flip map xs) (concat (map (flip map gs) (map _∘′_ fs ++ []))))
≡⟨ cong (λ x → flip map (concat (map (flip map xs) gs)) f ++ x) (compose fs gs xs) ⟩
flip map (concat (map (flip map xs) gs)) f ++ concat (map (flip map (concat (map (flip map xs) gs))) fs)
≡⟨ sym (concat-∷ (flip map (concat (map (flip map xs) gs)) f) (map (flip map (concat (map (flip map xs) gs))) fs)) ⟩
concat (flip map (concat (map (flip map xs) gs)) f ∷ map (flip map (concat (map (flip map xs) gs))) fs)
≡⟨ refl ⟩
concat (map (flip map (concat (map (flip map xs) gs))) (f ∷ fs))
∎
interchange : {A B : Set ℓ} (fs : List (A → B)) (x : A)
→ concat (map (flip map [ x ]) fs) ≡ concat (map (flip map fs) [ (λ g → g x) ])
interchange [] x = refl
interchange (f ∷ fs) x =
begin
concat (flip map [ x ] f ∷ map (flip map [ x ]) fs)
≡⟨ refl ⟩
concat (map f [ x ] ∷ map (flip map [ x ]) fs)
≡⟨ concat-∷ (map f [ x ]) (map (flip map [ x ]) fs) ⟩
map f [ x ] ++ concat (map (flip map [ x ]) fs)
≡⟨ cong (λ w → map f [ x ] ++ w) (interchange fs x) ⟩
map f [ x ] ++ map (λ z → z x) fs ++ []
≡⟨ refl ⟩
concat (flip map (f ∷ fs) (λ g → g x) ∷ [])
∎
| {
"alphanum_fraction": 0.419858156,
"avg_line_length": 52.875,
"ext": "agda",
"hexsha": "b0cf155751aadfdb4d1d509357e3f4767ebb059d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e5e562e4cde2face1f3f5b6d0486c8c56a47b435",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/FAM",
"max_forks_repo_path": "src/Data/List/Instance.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e5e562e4cde2face1f3f5b6d0486c8c56a47b435",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/FAM",
"max_issues_repo_path": "src/Data/List/Instance.agda",
"max_line_length": 151,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e5e562e4cde2face1f3f5b6d0486c8c56a47b435",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/FAM",
"max_stars_repo_path": "src/Data/List/Instance.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2002,
"size": 6345
} |
{-# OPTIONS --cubical --no-import-sorts #-}
module NumberFirstAttempt where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
private
variable
ℓ ℓ' ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Binary.Base -- Rel
open import Cubical.Data.Unit.Base -- Unit
record PoorField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
Carrier : Type ℓ
-- comm ring
0f : Carrier
1f : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
-- lattice
_<_ : Rel Carrier Carrier ℓ' -- stronger than _#_ and _≤_
min : Carrier → Carrier → Carrier
max : Carrier → Carrier → Carrier
-- other
_#_ : Rel Carrier Carrier ℓ'
_≤_ : Rel Carrier Carrier ℓ'
∣_∣ᶠ' : Carrier → Σ[ x ∈ Carrier ] 0f ≤ x -- absolute value NOTE: better have `0 ≤ x` as a separate property
_⁻¹ᶠ : (x : Carrier) → {{x # 0f}} → Carrier
conj : Carrier → Carrier -- complex conjugation (only for ℂ; this is the identity function on ℝ)
-- sqrt⁺ -- positive sqrt
-- -- need that on ℝ₀⁺ to define a norm from an inner product
-- -- on ℝ₀⁺ we have `∀ x → sqrt (x · x) ≡ x`
-- NOTE: squares are nonnegative in an ordered field
∣_∣ᶠ : Carrier → Carrier -- NOTE: well, this should be "into" ℝ₀⁺
∣ x ∣ᶠ = fst (∣ x ∣ᶠ')
_-_ : Carrier → Carrier → Carrier
x - y = x + (- y)
infix 9 _⁻¹ᶠ
infix 8 -_
infixl 7 _·_
infixl 6 _+_
infixl 6 _-_
infixl 4 _#_
infixl 4 _<_
infixl 4 _≤_
record IsℝField (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
record Isℝ₀⁺Field (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
field
isℝField : IsℝField PF
isNonnegative : ∀ x → 0f ≤ x
open IsℝField isℝField public
record Isℝ⁺Field (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
field
isℝField : IsℝField PF
-- NOTE: 0f is not an element of ℝ⁺, so we do not have a neutral element for addition
-- so the following holds in a different way
-- isPositive : ∀ x → 0f < x
open IsℝField isℝField public
record Is𝕂Field (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
record ℝField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
isℝField : IsℝField poorField
open PoorField poorField public
open IsℝField isℝField public
record ℝ₀⁺Field : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
isℝ₀⁺Field : Isℝ₀⁺Field poorField
open PoorField poorField public
open Isℝ₀⁺Field isℝ₀⁺Field public
record ℝ⁺Field : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
isℝ⁺Field : Isℝ⁺Field poorField
open PoorField poorField public
open Isℝ⁺Field isℝ⁺Field public
record 𝕂Field : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
is𝕂Field : Is𝕂Field poorField
open PoorField poorField public
open Is𝕂Field is𝕂Field public
postulate
ℝℓ ℝℓ' : Level
ℝF : ℝField {ℝℓ} {ℝℓ'} -- reals
ℝ⁺F : ℝ⁺Field {ℝℓ} {ℝℓ'} -- positive reals without 0
ℝ₀⁺F : ℝ₀⁺Field {ℝℓ} {ℝℓ'} -- positive reals with 0
open ℝField ℝF using () renaming
( Carrier to ℝ
)
record PoorSubField-ℝ (φ : ℝ → Type ℓ) : Type (ℓ-max ℝℓ ℓ) where
-- module R = ℝField ℝF
open ℝField ℝF
field
ι : Σ ℝ φ
_<⁺_ : Σ ℝ φ → Σ ℝ φ → Type ℝℓ'
_<⁺_ (x , xp) (y , yp) = x < y
module Test where
module R = ℝField ℝF
φᵢ = λ(x : ℝ) → Unit
-- the following "absorbs" different `Σ ℝ φ` ℝ-numbers and falls back to the "raw" operation from ℝ
_+_ : {φ₁ φ₂ : ℝ → Type ℓ'} → Σ ℝ φ₁ → Σ ℝ φ₂ → Σ ℝ φᵢ
_+_ (x , _) (y , _) = x R.+ y , tt
-- we might add an enumeration for different φs and pattern-match on those
data ℝ-props (x : ℝ) : Type ℝℓ where
φ-id : Unit → ℝ-props x
-- more ...
-- this works for subsets of ℝ but not for inter-sort-mixing (e.g. ℕ + ℝ) .. which we do want to coerce explicitly?
-- we could start with a number, e.g. z₀ ∈ ℕ
-- then include it into ℝ and have a Σ ℝ φ-from-nat
-- we could track the from-nat'ness and back-coerce this number when needed (as long as from-nat is preserved)
{-
data ℝ-sub (x : ℝ) : Type ℝℓ where
φ-from-ℝ : Unit -- default "fallback" case
φ-from-ℕ : Σ[ z ∈ ℕ ] ℕ↪ℝ z ≡ x -- with this we can use the `reflects`-properties of `ℕ↪ℝ` to get corresponding properties on ℕ
φ-from-ℤ : Σ[ z ∈ ℤ ] ℤ↪ℝ z ≡ x
φ-from-ℚ : Σ[ z ∈ ℚ ] ℚ↪ℝ z ≡ x
φ-from-ℝ₀⁺ : 0f ≤ x
¬( x < 0f)
φ-from-ℝ⁺ : 0f < x
-- ... more
-- first projection
num : ∀{x} → ℝ-sub x → ℝ
num p = ... cases
-- target type "table"
+-Coerce : (x y : ℝ-sub) → Type ℝℓ
+-Coerce x y = ... cases
-- implementation
_+_ : (x y : ℝ-sub) → +-Coerce x y
x + y = ... cases
-}
record IsPoorFieldInclusion
{ℓ ℓ' ℓₚ ℓₚ'}
(F : PoorField {ℓ} {ℓₚ}) (G : PoorField {ℓ'} {ℓₚ'})
(f : (PoorField.Carrier F) → (PoorField.Carrier G)) : Type (ℓ-max (ℓ-max ℓ ℓ') (ℓ-max ℓₚ ℓₚ'))
where
private
module F = PoorField F
module G = PoorField G
field
-- injectivity? might follow from preserves-#?
reflects-≡ : ∀ x y → f x ≡ f y → x ≡ y
-- lattice
preserves-< : ∀ x y → x F.< y → f x G.< f y
preserves-≤ : ∀ x y → x F.≤ y → f x G.≤ f y
preserves-# : ∀ x y → x F.# y → f x G.# f y
reflects-< : ∀ x y → f x G.< f y → x F.< y
reflects-≤ : ∀ x y → f x G.≤ f y → x F.≤ y
reflects-# : ∀ x y → f x G.# f y → x F.# y
preserves-min : ∀ x y → f (F.min x y) ≡ G.min (f x) (f y)
preserves-max : ∀ x y → f (F.max x y) ≡ G.max (f x) (f y)
preserves-0 : f F.0f ≡ G.0f
-- Fin 1 does not preserve
preserves-1 : f F.1f ≡ G.1f
-- Fin k might not preserve
preserves-+ : ∀ x y → f (x F.+ y) ≡ f x G.+ f y
preserves-· : ∀ x y → f (x F.· y) ≡ f x G.· f y
-- ℕ might not preserve
preserves- : ∀ x → f ( F.- x) ≡ G.- (f x)
-- ℤ does not preserve
-- preserves-⁻¹' : ∀ x → (p : x F.# F.0f) → f (F._⁻¹ᶠ x {{p}}) ≡ G._⁻¹ᶠ (f x) {{ transport (λ i → f x G.# preserves-0 i) (preserves-# x F.0f p) }}
-- NOTE: we better let the "user" decide how the proof of `f x # 0` is obtained
preserves-⁻¹ : ∀ x → (p : x F.# F.0f) → (q : f x G.# G.0f) → f (F._⁻¹ᶠ x {{p}}) ≡ G._⁻¹ᶠ (f x) {{q}}
record PoorFieldInclusion {ℓ ℓ' ℓₚ ℓₚ'} (F : PoorField {ℓ} {ℓₚ}) (G : PoorField {ℓ'} {ℓₚ'}) : Type (ℓ-max (ℓ-max ℓ ℓ') (ℓ-max ℓₚ ℓₚ')) where
constructor poorfieldmor
module F = PoorField F
module G = PoorField G
field
fun : F.Carrier → G.Carrier
isPoorFieldInclusion : IsPoorFieldInclusion F G fun
open IsPoorFieldInclusion isPoorFieldInclusion public
| {
"alphanum_fraction": 0.577324066,
"avg_line_length": 33.2019230769,
"ext": "agda",
"hexsha": "756256d866410bd0744ce7724479246febde92e1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "test/NumberFirstAttempt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "test/NumberFirstAttempt.agda",
"max_line_length": 150,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "test/NumberFirstAttempt.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 2807,
"size": 6906
} |
module Nat where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
one : Nat
one = suc zero
| {
"alphanum_fraction": 0.5596330275,
"avg_line_length": 10.9,
"ext": "agda",
"hexsha": "d6fd5231615618318dddfb684c8f146647b1e99a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/Nat.agda",
"max_line_length": 22,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 36,
"size": 109
} |
------------------------------------------------------------------------
-- A variant of the propositional truncation operator with an erased
-- truncation constructor
------------------------------------------------------------------------
-- Partly following the HoTT book, but adapted for erasure.
{-# OPTIONS --erased-cubical --safe #-}
-- The module is parametrised by a notion of equality. The higher
-- constructor of the HIT defining the propositional truncation
-- operator uses path equality, but the supplied notion of equality is
-- used for many other things.
import Equality.Path as P
module H-level.Truncation.Propositional.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Prelude as P
open import Logical-equivalence using (_⇔_)
open import Bijection equality-with-J as Bijection using (_↔_)
import Colimit.Sequential.Very-erased eq as C
open import Embedding equality-with-J as Emb using (Is-embedding)
open import Equality.Decidable-UIP equality-with-J
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Equivalence.Erased equality-with-J as EEq
using (_≃ᴱ_; Is-equivalenceᴱ)
open import Equivalence.Erased.Contractible-preimages equality-with-J
as ECP using (Contractibleᴱ; _⁻¹ᴱ_)
open import Equivalence-relation equality-with-J
open import Erased.Cubical eq as Er
using (Erased; [_]; erased; Very-stableᴱ-≡; Erased-singleton)
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.One-step eq as O
using (∥_∥¹-out-^)
import H-level.Truncation.Propositional.Non-recursive.Erased eq as N
open import Monad equality-with-J
open import Preimage equality-with-J using (_⁻¹_)
open import Surjection equality-with-J as S
using (_↠_; Split-surjective)
private
variable
a b ℓ p r : Level
A A₁ A₂ B B₁ B₂ C : Type a
P Q : A → Type p
R : A → A → Type r
f g k x y : A
------------------------------------------------------------------------
-- The type former
-- A propositional truncation operator with an erased higher
-- constructor.
data ∥_∥ᴱ (A : Type a) : Type a where
∣_∣ : A → ∥ A ∥ᴱ
@0 truncation-is-propositionᴾ : P.Is-proposition ∥ A ∥ᴱ
-- The truncation produces propositions (in erased contexts).
@0 truncation-is-proposition : Is-proposition ∥ A ∥ᴱ
truncation-is-proposition =
_↔_.from (H-level↔H-level 1) truncation-is-propositionᴾ
------------------------------------------------------------------------
-- Eliminators
-- A dependent eliminator, expressed using paths.
record Elimᴾ′ {A : Type a} (P : ∥ A ∥ᴱ → Type p) : Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : (x : A) → P ∣ x ∣
@0 truncation-is-propositionʳ :
(p : P x) (q : P y) →
P.[ (λ i → P (truncation-is-propositionᴾ x y i)) ] p ≡ q
open Elimᴾ′ public
elimᴾ′ : Elimᴾ′ P → (x : ∥ A ∥ᴱ) → P x
elimᴾ′ {A = A} {P = P} e = helper
where
module E = Elimᴾ′ e
helper : (x : ∥ A ∥ᴱ) → P x
helper ∣ x ∣ = E.∣∣ʳ x
helper (truncation-is-propositionᴾ x y i) =
E.truncation-is-propositionʳ (helper x) (helper y) i
-- A possibly more useful dependent eliminator, expressed using paths.
record Elimᴾ {A : Type a} (P : ∥ A ∥ᴱ → Type p) : Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : (x : A) → P ∣ x ∣
@0 truncation-is-propositionʳ :
(x : ∥ A ∥ᴱ) → P.Is-proposition (P x)
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : ∥ A ∥ᴱ) → P x
elimᴾ e = elimᴾ′ λ where
.∣∣ʳ → E.∣∣ʳ
.truncation-is-propositionʳ _ _ →
P.heterogeneous-irrelevance E.truncation-is-propositionʳ
where
module E = Elimᴾ e
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
@0 truncation-is-propositionʳ : P.Is-proposition B
open Recᴾ public
recᴾ : Recᴾ A B → ∥ A ∥ᴱ → B
recᴾ r = elimᴾ λ where
.∣∣ʳ → R.∣∣ʳ
.truncation-is-propositionʳ _ → R.truncation-is-propositionʳ
where
module R = Recᴾ r
-- A dependently typed eliminator.
record Elim {A : Type a} (P : ∥ A ∥ᴱ → Type p) : Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : (x : A) → P ∣ x ∣
@0 truncation-is-propositionʳ :
(x : ∥ A ∥ᴱ) → Is-proposition (P x)
open Elim public
elim : Elim P → (x : ∥ A ∥ᴱ) → P x
elim e = elimᴾ λ where
.∣∣ʳ → E.∣∣ʳ
.truncation-is-propositionʳ →
_↔_.to (H-level↔H-level 1) ∘ E.truncation-is-propositionʳ
where
module E = Elim e
-- Primitive "recursion".
record Rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
@0 truncation-is-propositionʳ : Is-proposition B
open Rec public
rec : Rec A B → ∥ A ∥ᴱ → B
rec r = recᴾ λ where
.∣∣ʳ → R.∣∣ʳ
.truncation-is-propositionʳ →
_↔_.to (H-level↔H-level 1) R.truncation-is-propositionʳ
where
module R = Rec r
------------------------------------------------------------------------
-- Conversion functions
-- ∥_∥ᴱ is pointwise equivalent to N.∥_∥ᴱ.
∥∥ᴱ≃∥∥ᴱ : ∥ A ∥ᴱ ≃ N.∥ A ∥ᴱ
∥∥ᴱ≃∥∥ᴱ = Eq.↔→≃
(rec λ where
.∣∣ʳ → N.∣_∣
.truncation-is-propositionʳ → N.∥∥ᴱ-proposition)
(N.elim λ where
.N.∣∣ʳ → ∣_∣
.N.is-propositionʳ _ → truncation-is-proposition)
(N.elim λ where
.N.∣∣ʳ _ → refl _
.N.is-propositionʳ _ → mono₁ 1 N.∥∥ᴱ-proposition)
(elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ → mono₁ 1 truncation-is-proposition)
------------------------------------------------------------------------
-- Some preservation lemmas and related results
-- A map function.
∥∥ᴱ-map : (A → B) → ∥ A ∥ᴱ → ∥ B ∥ᴱ
∥∥ᴱ-map f = rec λ where
.∣∣ʳ → ∣_∣ ∘ f
.truncation-is-propositionʳ → truncation-is-proposition
mutual
-- If A and B are logically equivalent, then there is an equivalence
-- with erased proofs between ∥ A ∥ᴱ and ∥ B ∥ᴱ.
∥∥ᴱ-cong-⇔ : A ⇔ B → ∥ A ∥ᴱ ≃ᴱ ∥ B ∥ᴱ
∥∥ᴱ-cong-⇔ A⇔B = ∥∥ᴱ-cong-⇔′ (∣_∣ ∘ _⇔_.to A⇔B) (∣_∣ ∘ _⇔_.from A⇔B)
-- A variant of the previous result.
∥∥ᴱ-cong-⇔′ : (A → ∥ B ∥ᴱ) → (B → ∥ A ∥ᴱ) → ∥ A ∥ᴱ ≃ᴱ ∥ B ∥ᴱ
∥∥ᴱ-cong-⇔′ A→∥B∥ B→∥A∥ = EEq.⇔→≃ᴱ
truncation-is-proposition
truncation-is-proposition
(rec λ where
.∣∣ʳ → A→∥B∥
.truncation-is-propositionʳ → truncation-is-proposition)
(rec λ where
.∣∣ʳ → B→∥A∥
.truncation-is-propositionʳ → truncation-is-proposition)
-- If there is a split surjection from A to B, then there is a split
-- surjection from ∥ A ∥ᴱ to ∥ B ∥ᴱ.
∥∥ᴱ-cong-↠ : A ↠ B → ∥ A ∥ᴱ ↠ ∥ B ∥ᴱ
∥∥ᴱ-cong-↠ A↠B = record
{ logical-equivalence = record
{ to = ∥∥ᴱ-map (_↠_.to A↠B)
; from = ∥∥ᴱ-map (_↠_.from A↠B)
}
; right-inverse-of = elim λ where
.∣∣ʳ x →
∣ _↠_.to A↠B (_↠_.from A↠B x) ∣ ≡⟨ cong ∣_∣ (_↠_.right-inverse-of A↠B x) ⟩∎
∣ x ∣ ∎
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition
}
private
∥∥ᴱ-cong-↔ : A ↔ B → ∥ A ∥ᴱ ↔ ∥ B ∥ᴱ
∥∥ᴱ-cong-↔ A↔B = record
{ surjection = ∥∥ᴱ-cong-↠ (_↔_.surjection A↔B)
; left-inverse-of = elim λ where
.∣∣ʳ x →
∣ _↔_.from A↔B (_↔_.to A↔B x) ∣ ≡⟨ cong ∣_∣ (_↔_.left-inverse-of A↔B x) ⟩∎
∣ x ∣ ∎
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition
}
-- The truncation operator preserves "symmetric" functions.
∥∥ᴱ-cong : A ↝[ ⌊ k ⌋-sym ] B → ∥ A ∥ᴱ ↝[ ⌊ k ⌋-sym ] ∥ B ∥ᴱ
∥∥ᴱ-cong {k = logical-equivalence} = _≃ᴱ_.logical-equivalence ∘
∥∥ᴱ-cong-⇔
∥∥ᴱ-cong {k = bijection} = ∥∥ᴱ-cong-↔
∥∥ᴱ-cong {k = equivalence} = from-isomorphism ∘ ∥∥ᴱ-cong-↔ ∘
from-isomorphism
∥∥ᴱ-cong {k = equivalenceᴱ} = ∥∥ᴱ-cong-⇔ ∘
_≃ᴱ_.logical-equivalence
------------------------------------------------------------------------
-- Some bijections/erased equivalences
-- If the underlying type is a proposition, then truncations of the
-- type are isomorphic to the type itself.
∥∥ᴱ↔ : @0 Is-proposition A → ∥ A ∥ᴱ ↔ A
∥∥ᴱ↔ A-prop = record
{ surjection = record
{ logical-equivalence = record
{ to = rec λ where
.∣∣ʳ → id
.truncation-is-propositionʳ → A-prop
; from = ∣_∣
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ → mono₁ 1 truncation-is-proposition
}
-- If A is merely inhabited, then the truncation of A is equivalent
-- (with erased proofs) to the unit type.
inhabited⇒∥∥ᴱ≃ᴱ⊤ : ∥ A ∥ᴱ → ∥ A ∥ᴱ ≃ᴱ ⊤
inhabited⇒∥∥ᴱ≃ᴱ⊤ ∥a∥ =
EEq.inhabited→Is-proposition→≃ᴱ⊤ ∥a∥ truncation-is-proposition
-- If A is not inhabited, then the propositional truncation of A is
-- isomorphic to the empty type.
not-inhabited⇒∥∥ᴱ↔⊥ : ¬ A → ∥ A ∥ᴱ ↔ ⊥ {ℓ = ℓ}
not-inhabited⇒∥∥ᴱ↔⊥ {A = A} =
¬ A ↝⟨ (λ ¬a → rec λ where
.∣∣ʳ → ¬a
.truncation-is-propositionʳ → ⊥-propositional) ⟩
¬ ∥ A ∥ᴱ ↝⟨ inverse ∘ Bijection.⊥↔uninhabited ⟩□
∥ A ∥ᴱ ↔ ⊥ □
-- The negation of the truncation of A is isomorphic to the negation
-- of A.
¬∥∥ᴱ↔¬ : ¬ ∥ A ∥ᴱ ↔ ¬ A
¬∥∥ᴱ↔¬ {A = A} = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → f ∘ ∣_∣
; from = λ ¬A → rec λ where
.∣∣ʳ → ¬A
.truncation-is-propositionʳ → ⊥-propositional
}
; right-inverse-of = λ _ → ¬-propositional ext _ _
}
; left-inverse-of = λ _ → ¬-propositional ext _ _
}
-- A form of idempotence for binary sums.
idempotent : ∥ A ⊎ A ∥ᴱ ≃ᴱ ∥ A ∥ᴱ
idempotent = ∥∥ᴱ-cong-⇔ (record { to = P.[ id , id ]; from = inj₁ })
------------------------------------------------------------------------
-- The universal property, and some related results
mutual
-- The propositional truncation operator's universal property.
--
-- See also Quotient.Erased.Σ→Erased-Constant≃∥∥ᴱ→.
universal-property :
@0 Is-proposition B →
(∥ A ∥ᴱ → B) ≃ (A → B)
universal-property B-prop = universal-property-Π (λ _ → B-prop)
-- A generalisation of the universal property.
universal-property-Π :
@0 (∀ x → Is-proposition (P x)) →
((x : ∥ A ∥ᴱ) → P x) ≃ ((x : A) → P ∣ x ∣)
universal-property-Π {A = A} {P = P} P-prop =
((x : ∥ A ∥ᴱ) → P x) ↝⟨ Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → ∣ f ∘ ∣_∣ ∣
; from = rec λ where
.∣∣ʳ f → elim λ where
.∣∣ʳ → f
.truncation-is-propositionʳ → P-prop
.truncation-is-propositionʳ →
Π-closure ext 1 λ _ → P-prop _
}
; right-inverse-of = elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition
}
; left-inverse-of = λ f → ⟨ext⟩ $ elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ →
mono₁ 1 (P-prop _)
}) ⟩
∥ ((x : A) → P ∣ x ∣) ∥ᴱ ↔⟨ ∥∥ᴱ↔ (Π-closure ext 1 λ _ → P-prop _) ⟩□
((x : A) → P ∣ x ∣) □
-- The universal property computes in the "right" way.
_ :
(@0 B-prop : Is-proposition B)
(f : ∥ A ∥ᴱ → B) →
_≃_.to (universal-property B-prop) f ≡ f ∘ ∣_∣
_ = λ _ _ → refl _
_ :
(@0 B-prop : Is-proposition B)
(f : A → B) (x : A) →
_≃_.from (universal-property B-prop) f ∣ x ∣ ≡ f x
_ = λ _ _ _ → refl _
-- Functions from ∥ A ∥ᴱ can be expressed as functions from A along
-- with some erased data.
∥∥ᴱ→≃ :
(∥ A ∥ᴱ → B)
≃
(∃ λ (f : A → B) →
Erased (∃ λ (g : ∀ n → ∥ A ∥¹-out-^ (suc n) → B) →
(∀ x → g zero O.∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) O.∣ x ∣ ≡ g n x)))
∥∥ᴱ→≃ {A = A} {B = B} =
(∥ A ∥ᴱ → B) ↝⟨ →-cong ext ∥∥ᴱ≃∥∥ᴱ F.id ⟩
(N.∥ A ∥ᴱ → B) ↝⟨ C.universal-property ⟩□
(∃ λ (f : A → B) →
Erased (∃ λ (g : ∀ n → ∥ A ∥¹-out-^ (suc n) → B) →
(∀ x → g zero O.∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) O.∣ x ∣ ≡ g n x))) □
-- A function of type (x : ∥ A ∥ᴱ) → P x, along with an erased proof
-- showing that the function is equal to some erased function, is
-- equivalent to a function of type (x : A) → P ∣ x ∣, along with an
-- erased equality proof.
Σ-Π-∥∥ᴱ-Erased-≡-≃ :
{@0 g : (x : ∥ A ∥ᴱ) → P x} →
(∃ λ (f : (x : ∥ A ∥ᴱ) → P x) → Erased (f ≡ g)) ≃
(∃ λ (f : (x : A) → P ∣ x ∣) → Erased (f ≡ g ∘ ∣_∣))
Σ-Π-∥∥ᴱ-Erased-≡-≃ {A = A} {P = P} {g = g} =
(∃ λ (f : (x : ∥ A ∥ᴱ) → P x) → Erased (f ≡ g)) ↝⟨ (Σ-cong lemma λ _ → Er.Erased-cong (inverse $ Eq.≃-≡ lemma)) ⟩
(∃ λ (f : (x : N.∥ A ∥ᴱ) → P (_≃_.from ∥∥ᴱ≃∥∥ᴱ x)) →
Erased (f ≡ g ∘ _≃_.from ∥∥ᴱ≃∥∥ᴱ)) ↝⟨ N.Σ-Π-∥∥ᴱ-Erased-≡-≃ ⟩□
(∃ λ (f : (x : A) → P ∣ x ∣) → Erased (f ≡ g ∘ ∣_∣)) □
where
lemma = Π-cong-contra ext (inverse ∥∥ᴱ≃∥∥ᴱ) λ _ → Eq.id
------------------------------------------------------------------------
-- Some results based on "Generalizations of Hedberg's Theorem" by
-- Kraus, Escardó, Coquand and Altenkirch
-- Types with constant endofunctions are "h-stable" (meaning that
-- "mere inhabitance" implies inhabitance).
constant-endofunction⇒h-stable :
{f : A → A} → @0 Constant f → ∥ A ∥ᴱ → A
constant-endofunction⇒h-stable {A = A} {f = f} c =
∥ A ∥ᴱ ↝⟨ (rec λ where
.∣∣ʳ x → f x , [ c (f x) x ]
.truncation-is-propositionʳ → prop) ⟩
(∃ λ (x : A) → Erased (f x ≡ x)) ↝⟨ proj₁ ⟩□
A □
where
@0 prop : _
prop = $⟨ fixpoint-lemma f c ⟩
Is-proposition (∃ λ x → f x ≡ x) ↝⟨ H-level-cong _ 1 (∃-cong λ _ → inverse $ Er.erased Er.Erased↔) ⦂ (_ → _) ⟩□
Is-proposition (∃ λ x → Erased (f x ≡ x)) □
-- Having a constant endofunction is logically equivalent to being
-- h-stable.
constant-endofunction⇔h-stable :
(∃ λ (f : A → A) → Erased (Constant f)) ⇔ (∥ A ∥ᴱ → A)
constant-endofunction⇔h-stable = record
{ to = λ (_ , [ c ]) → constant-endofunction⇒h-stable c
; from = λ f → f ∘ ∣_∣
, [ (λ x y →
f ∣ x ∣ ≡⟨ cong f $ truncation-is-proposition _ _ ⟩∎
f ∣ y ∣ ∎)
]
}
------------------------------------------------------------------------
-- Some results related to _×_
-- The cartesian product of the truncation of A and A is equivalent
-- (with erased "proofs") to A.
∥∥ᴱ×≃ᴱ : (∥ A ∥ᴱ × A) ≃ᴱ A
∥∥ᴱ×≃ᴱ = EEq.↔→≃ᴱ
proj₂
(λ x → ∣ x ∣ , x)
refl
(λ _ → cong (_, _) (truncation-is-proposition _ _))
-- The application _≃ᴱ_.right-inverse-of ∥∥ᴱ×≃ᴱ x computes in a
-- certain way.
_ : _≃ᴱ_.right-inverse-of ∥∥ᴱ×≃ᴱ x ≡ refl _
_ = refl _
-- ∥_∥ᴱ commutes with _×_.
∥∥ᴱ×∥∥ᴱ↔∥×∥ᴱ : (∥ A ∥ᴱ × ∥ B ∥ᴱ) ↔ ∥ A × B ∥ᴱ
∥∥ᴱ×∥∥ᴱ↔∥×∥ᴱ = record
{ surjection = record
{ logical-equivalence = record
{ from = λ p → ∥∥ᴱ-map proj₁ p , ∥∥ᴱ-map proj₂ p
; to = uncurry $ rec λ where
.∣∣ʳ x → rec λ where
.∣∣ʳ y → ∣ x , y ∣
.truncation-is-propositionʳ →
truncation-is-proposition
.truncation-is-propositionʳ →
Π-closure ext 1 λ _ →
truncation-is-proposition
}
; right-inverse-of = elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition
}
; left-inverse-of = uncurry $ elim λ where
.∣∣ʳ _ → elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ →
mono₁ 1 $
×-closure 1 truncation-is-proposition
truncation-is-proposition
.truncation-is-propositionʳ _ →
Π-closure ext 1 λ _ →
mono₁ 1 $
×-closure 1 truncation-is-proposition
truncation-is-proposition
}
------------------------------------------------------------------------
-- Some results related to h-levels
-- Variants of proj₁-closure.
private
H-level-×₁-lemma :
(A → ∥ B ∥ᴱ) →
∀ n → H-level (suc n) (A × B) → H-level (suc n) A
H-level-×₁-lemma inhabited n h =
[inhabited⇒+]⇒+ n λ a →
flip rec (inhabited a) λ where
.∣∣ʳ b →
proj₁-closure (λ _ → b) (suc n) h
.truncation-is-propositionʳ →
H-level-propositional ext (suc n)
H-level-×₁ :
(A → ∥ B ∥ᴱ) →
∀ n → H-level n (A × B) → H-level n A
H-level-×₁ inhabited zero h =
propositional⇒inhabited⇒contractible
(H-level-×₁-lemma inhabited 0 (mono₁ 0 h))
(proj₁ (proj₁ h))
H-level-×₁ inhabited (suc n) =
H-level-×₁-lemma inhabited n
H-level-×₂ :
(B → ∥ A ∥ᴱ) →
∀ n → H-level n (A × B) → H-level n B
H-level-×₂ {B = B} {A = A} inhabited n =
H-level n (A × B) ↝⟨ H-level.respects-surjection (from-bijection ×-comm) n ⟩
H-level n (B × A) ↝⟨ H-level-×₁ inhabited n ⟩□
H-level n B □
------------------------------------------------------------------------
-- Flattening
-- A generalised flattening lemma.
flatten′ :
(F : (Type ℓ → Type ℓ) → Type f)
(map : ∀ {G H} → (∀ {A} → G A → H A) → F G → F H)
(f : F ∥_∥ᴱ → ∥ F id ∥ᴱ) →
(∀ x → f (map ∣_∣ x) ≡ ∣ x ∣) →
(∀ x → ∥∥ᴱ-map (map ∣_∣) (f x) ≡ ∣ x ∣) →
∥ F ∥_∥ᴱ ∥ᴱ ↔ ∥ F id ∥ᴱ
flatten′ _ map f f-map map-f = record
{ surjection = record
{ logical-equivalence = record
{ to = rec λ where
.∣∣ʳ → f
.truncation-is-propositionʳ → truncation-is-proposition
; from = ∥∥ᴱ-map (map ∣_∣)
}
; right-inverse-of = elim λ where
.∣∣ʳ → f-map
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition
}
; left-inverse-of = elim λ where
.∣∣ʳ → map-f
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition
}
-- Nested truncations can be flattened.
flatten : ∥ ∥ A ∥ᴱ ∥ᴱ ↔ ∥ A ∥ᴱ
flatten {A = A} = flatten′
(λ F → F A)
(λ f → f)
id
(λ _ → refl _)
(elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ → mono₁ 1 truncation-is-proposition)
private
-- Another flattening lemma, given as an example of how flatten′ can
-- be used.
∥∃∥∥ᴱ∥ᴱ↔∥∃∥ᴱ : ∥ ∃ (∥_∥ᴱ ∘ P) ∥ᴱ ↔ ∥ ∃ P ∥ᴱ
∥∃∥∥ᴱ∥ᴱ↔∥∃∥ᴱ {P = P} = flatten′
(λ F → ∃ (F ∘ P))
(λ f → Σ-map id f)
(uncurry λ x → ∥∥ᴱ-map (x ,_))
(λ _ → refl _)
(uncurry λ _ → elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition)
-- A variant of flatten′ with _≃ᴱ_ instead of _↔_.
flatten-≃ᴱ :
(F : (Type ℓ → Type ℓ) → Type f)
(map : ∀ {G H} → (∀ {A} → G A → H A) → F G → F H)
(f : F ∥_∥ᴱ → ∥ F id ∥ᴱ) →
@0 (∀ x → f (map ∣_∣ x) ≡ ∣ x ∣) →
@0 (∀ x → ∥∥ᴱ-map (map ∣_∣) (f x) ≡ ∣ x ∣) →
∥ F ∥_∥ᴱ ∥ᴱ ≃ᴱ ∥ F id ∥ᴱ
flatten-≃ᴱ _ map f f-map map-f = EEq.↔→≃ᴱ
(rec λ where
.∣∣ʳ → f
.truncation-is-propositionʳ → truncation-is-proposition)
(∥∥ᴱ-map (map ∣_∣))
(elim λ @0 where
.∣∣ʳ → f-map
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition)
(elim λ @0 where
.∣∣ʳ → map-f
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition)
------------------------------------------------------------------------
-- The propositional truncation operator is a monad
-- A universe-polymorphic variant of bind.
infixl 5 _>>=′_
_>>=′_ : ∥ A ∥ᴱ → (A → ∥ B ∥ᴱ) → ∥ B ∥ᴱ
x >>=′ f = _↔_.to flatten (∥∥ᴱ-map f x)
-- The universe-polymorphic variant of bind is associative.
>>=′-associative :
(x : ∥ A ∥ᴱ) →
x >>=′ (λ x → f x >>=′ g) ≡ x >>=′ f >>=′ g
>>=′-associative = elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ → ⇒≡ 1 truncation-is-proposition
instance
-- The propositional truncation operator is a monad.
raw-monad : Raw-monad (∥_∥ᴱ {a = a})
Raw-monad.return raw-monad = ∣_∣
Raw-monad._>>=_ raw-monad = _>>=′_
monad : Monad (∥_∥ᴱ {a = a})
Monad.raw-monad monad = raw-monad
Monad.left-identity monad _ _ = refl _
Monad.associativity monad x _ _ = >>=′-associative x
Monad.right-identity monad = elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ → ⇒≡ 1 truncation-is-proposition
------------------------------------------------------------------------
-- Surjectivity
-- A variant of surjectivity with "erased proofs".
Surjectiveᴱ :
{A : Type a} {B : Type b} →
(A → B) → Type (a ⊔ b)
Surjectiveᴱ f = ∀ y → ∥ f ⁻¹ᴱ y ∥ᴱ
-- The property Surjectiveᴱ f is a proposition (in erased contexts).
@0 Surjectiveᴱ-propositional : Is-proposition (Surjectiveᴱ f)
Surjectiveᴱ-propositional =
Π-closure ext 1 λ _ →
truncation-is-proposition
-- The function ∣_∣ is surjective (with erased proofs).
∣∣-surjective : Surjectiveᴱ (∣_∣ {A = A})
∣∣-surjective = elim λ where
.∣∣ʳ x → ∣ x , [ refl _ ] ∣
.truncation-is-propositionʳ _ → truncation-is-proposition
-- Split surjective functions are surjective (with erased proofs).
Split-surjective→Surjectiveᴱ :
Split-surjective f → Surjectiveᴱ f
Split-surjective→Surjectiveᴱ s = λ y → ∣ ECP.⁻¹→⁻¹ᴱ (s y) ∣
-- Being both surjective (with erased proofs) and an embedding
-- (completely erased) is equivalent to being an equivalence (with
-- erased proofs).
--
-- This result, without erasure, is Corollary 4.6.4 from the first
-- edition of the HoTT book.
Surjectiveᴱ×Erased-Is-embedding≃ᴱIs-equivalenceᴱ :
(Surjectiveᴱ f × Erased (Is-embedding f)) ≃ᴱ Is-equivalenceᴱ f
Surjectiveᴱ×Erased-Is-embedding≃ᴱIs-equivalenceᴱ {f = f} = EEq.⇔→≃ᴱ
(×-closure 1
Surjectiveᴱ-propositional
(Er.H-level-Erased 1
(Emb.Is-embedding-propositional ext)))
(EEq.Is-equivalenceᴱ-propositional ext f)
(λ (is-surj , is-emb) →
_⇔_.from EEq.Is-equivalenceᴱ⇔Is-equivalenceᴱ-CP $ λ y →
$⟨ is-surj y ⟩
∥ f ⁻¹ᴱ y ∥ᴱ ↝⟨ (rec λ where
.∣∣ʳ p → ECP.inhabited→Is-proposition→Contractibleᴱ p
(H-level-cong _ 1
ECP.⁻¹≃⁻¹ᴱ
(Emb.embedding→⁻¹-propositional (Er.erased is-emb) _))
.truncation-is-propositionʳ →
ECP.Contractibleᴱ-propositional ext) ⟩□
Contractibleᴱ (f ⁻¹ᴱ y) □)
(λ is-eq@(inv , [ r-inv , _ ]) →
(λ y → $⟨ inv y , [ r-inv y ] ⟩
f ⁻¹ᴱ y ↝⟨ ∣_∣ ⟩
∥ f ⁻¹ᴱ y ∥ᴱ □)
, ($⟨ is-eq ⟩
Is-equivalenceᴱ f ↝⟨ Er.[_]→ ⟩
Erased (Is-equivalenceᴱ f) ↝⟨ Er.map EEq.Is-equivalenceᴱ→Is-equivalence ⟩
Erased (Is-equivalence f) ↝⟨ Er.map Emb.Is-equivalence→Is-embedding ⟩□
Erased (Is-embedding f) □))
------------------------------------------------------------------------
-- Another lemma
-- The function λ R x y → ∥ R x y ∥ᴱ preserves Is-equivalence-relation.
∥∥ᴱ-preserves-Is-equivalence-relation :
Is-equivalence-relation R →
Is-equivalence-relation (λ x y → ∥ R x y ∥ᴱ)
∥∥ᴱ-preserves-Is-equivalence-relation R-equiv = record
{ reflexive = ∣ reflexive ∣
; symmetric = symmetric ⟨$⟩_
; transitive = λ p q → transitive ⟨$⟩ p ⊛ q
}
where
open Is-equivalence-relation R-equiv
------------------------------------------------------------------------
-- Definitions related to truncated binary sums
-- Truncated binary sums.
infixr 1 _∥⊎∥ᴱ_
_∥⊎∥ᴱ_ : Type a → Type b → Type (a ⊔ b)
A ∥⊎∥ᴱ B = ∥ A ⊎ B ∥ᴱ
-- Introduction rules.
∣inj₁∣ : A → A ∥⊎∥ᴱ B
∣inj₁∣ = ∣_∣ ∘ inj₁
∣inj₂∣ : B → A ∥⊎∥ᴱ B
∣inj₂∣ = ∣_∣ ∘ inj₂
-- In erased contexts _∥⊎∥ᴱ_ is pointwise propositional.
@0 ∥⊎∥ᴱ-propositional : Is-proposition (A ∥⊎∥ᴱ B)
∥⊎∥ᴱ-propositional = truncation-is-proposition
-- The _∥⊎∥ᴱ_ operator preserves "symmetric" functions.
infixr 1 _∥⊎∥ᴱ-cong_
_∥⊎∥ᴱ-cong_ :
A₁ ↝[ ⌊ k ⌋-sym ] A₂ → B₁ ↝[ ⌊ k ⌋-sym ] B₂ →
(A₁ ∥⊎∥ᴱ B₁) ↝[ ⌊ k ⌋-sym ] (A₂ ∥⊎∥ᴱ B₂)
A₁↝A₂ ∥⊎∥ᴱ-cong B₁↝B₂ = ∥∥ᴱ-cong (A₁↝A₂ ⊎-cong B₁↝B₂)
-- _∥⊎∥ᴱ_ is commutative.
∥⊎∥ᴱ-comm : A ∥⊎∥ᴱ B ↔ B ∥⊎∥ᴱ A
∥⊎∥ᴱ-comm = ∥∥ᴱ-cong ⊎-comm
-- If one truncates the types to the left or right of _∥⊎∥ᴱ_, then one
-- ends up with an isomorphic type.
truncate-left-∥⊎∥ᴱ : A ∥⊎∥ᴱ B ↔ ∥ A ∥ᴱ ∥⊎∥ᴱ B
truncate-left-∥⊎∥ᴱ =
inverse $
flatten′
(λ F → F _ ⊎ _)
(λ f → ⊎-map f id)
P.[ ∥∥ᴱ-map inj₁ , ∣inj₂∣ ]
P.[ (λ _ → refl _) , (λ _ → refl _) ]
P.[ (elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ →
mono₁ 1 ∥⊎∥ᴱ-propositional)
, (λ _ → refl _)
]
truncate-right-∥⊎∥ᴱ : A ∥⊎∥ᴱ B ↔ A ∥⊎∥ᴱ ∥ B ∥ᴱ
truncate-right-∥⊎∥ᴱ {A = A} {B = B} =
A ∥⊎∥ᴱ B ↝⟨ ∥⊎∥ᴱ-comm ⟩
B ∥⊎∥ᴱ A ↝⟨ truncate-left-∥⊎∥ᴱ ⟩
∥ B ∥ᴱ ∥⊎∥ᴱ A ↝⟨ ∥⊎∥ᴱ-comm ⟩□
A ∥⊎∥ᴱ ∥ B ∥ᴱ □
-- _∥⊎∥ᴱ_ is associative.
∥⊎∥ᴱ-assoc : A ∥⊎∥ᴱ (B ∥⊎∥ᴱ C) ↔ (A ∥⊎∥ᴱ B) ∥⊎∥ᴱ C
∥⊎∥ᴱ-assoc {A = A} {B = B} {C = C} =
∥ A ⊎ ∥ B ⊎ C ∥ᴱ ∥ᴱ ↝⟨ inverse truncate-right-∥⊎∥ᴱ ⟩
∥ A ⊎ B ⊎ C ∥ᴱ ↝⟨ ∥∥ᴱ-cong ⊎-assoc ⟩
∥ (A ⊎ B) ⊎ C ∥ᴱ ↝⟨ truncate-left-∥⊎∥ᴱ ⟩□
∥ ∥ A ⊎ B ∥ᴱ ⊎ C ∥ᴱ □
-- ⊥ is a left and right identity of _∥⊎∥ᴱ_ if the other argument is a
-- proposition.
∥⊎∥ᴱ-left-identity : @0 Is-proposition A → ⊥ {ℓ = ℓ} ∥⊎∥ᴱ A ↔ A
∥⊎∥ᴱ-left-identity {A = A} A-prop =
∥ ⊥ ⊎ A ∥ᴱ ↝⟨ ∥∥ᴱ-cong ⊎-left-identity ⟩
∥ A ∥ᴱ ↝⟨ ∥∥ᴱ↔ A-prop ⟩□
A □
∥⊎∥ᴱ-right-identity : @0 Is-proposition A → A ∥⊎∥ᴱ ⊥ {ℓ = ℓ} ↔ A
∥⊎∥ᴱ-right-identity {A = A} A-prop =
A ∥⊎∥ᴱ ⊥ ↔⟨ ∥⊎∥ᴱ-comm ⟩
⊥ ∥⊎∥ᴱ A ↔⟨ ∥⊎∥ᴱ-left-identity A-prop ⟩□
A □
-- _∥⊎∥ᴱ_ is idempotent for propositions (up to equivalences with
-- erased proofs).
∥⊎∥ᴱ-idempotent : @0 Is-proposition A → (A ∥⊎∥ᴱ A) ≃ᴱ A
∥⊎∥ᴱ-idempotent {A = A} A-prop =
∥ A ⊎ A ∥ᴱ ↝⟨ idempotent ⟩
∥ A ∥ᴱ ↔⟨ ∥∥ᴱ↔ A-prop ⟩□
A □
-- Sometimes a truncated binary sum is equivalent (with erased proofs)
-- to one of its summands.
drop-left-∥⊎∥ᴱ :
@0 Is-proposition B → (A → B) → (A ∥⊎∥ᴱ B) ≃ᴱ B
drop-left-∥⊎∥ᴱ B-prop A→B = EEq.⇔→≃ᴱ
∥⊎∥ᴱ-propositional
B-prop
(rec λ where
.∣∣ʳ → P.[ A→B , id ]
.truncation-is-propositionʳ → B-prop)
∣inj₂∣
drop-right-∥⊎∥ᴱ :
@0 Is-proposition A → (B → A) → (A ∥⊎∥ᴱ B) ≃ᴱ A
drop-right-∥⊎∥ᴱ {A = A} {B = B} A-prop B→A =
A ∥⊎∥ᴱ B ↔⟨ ∥⊎∥ᴱ-comm ⟩
B ∥⊎∥ᴱ A ↝⟨ drop-left-∥⊎∥ᴱ A-prop B→A ⟩□
A □
-- Sometimes a truncated binary sum is isomorphic to one of its
-- summands.
drop-⊥-right-∥⊎∥ᴱ :
@0 Is-proposition A → ¬ B → A ∥⊎∥ᴱ B ↔ A
drop-⊥-right-∥⊎∥ᴱ A-prop ¬B = record
{ surjection = record
{ logical-equivalence = record
{ to = rec λ where
.∣∣ʳ → P.[ id , ⊥-elim ∘ ¬B ]
.truncation-is-propositionʳ → A-prop
; from = ∣inj₁∣
}
; right-inverse-of = refl
}
; left-inverse-of = elim λ where
.∣∣ʳ → P.[ (λ _ → refl _) , ⊥-elim ∘ ¬B ]
.truncation-is-propositionʳ _ →
mono₁ 1 ∥⊎∥ᴱ-propositional
}
drop-⊥-left-∥⊎∥ᴱ :
@0 Is-proposition B → ¬ A → A ∥⊎∥ᴱ B ↔ B
drop-⊥-left-∥⊎∥ᴱ B-prop ¬A = record
{ surjection = record
{ logical-equivalence = record
{ to = rec λ where
.∣∣ʳ → P.[ ⊥-elim ∘ ¬A , id ]
.truncation-is-propositionʳ → B-prop
; from = ∣inj₂∣
}
; right-inverse-of = refl
}
; left-inverse-of = elim λ where
.∣∣ʳ → P.[ ⊥-elim ∘ ¬A , (λ _ → refl _) ]
.truncation-is-propositionʳ _ →
mono₁ 1 ∥⊎∥ᴱ-propositional
}
-- A type of functions from a truncated binary sum to a family of
-- propositions can be expressed as a binary product of function
-- types.
Π∥⊎∥ᴱ↔Π×Π :
@0 (∀ x → Is-proposition (P x)) →
((x : A ∥⊎∥ᴱ B) → P x)
↔
((x : A) → P (∣inj₁∣ x)) × ((y : B) → P (∣inj₂∣ y))
Π∥⊎∥ᴱ↔Π×Π {A = A} {B = B} {P = P} P-prop =
((x : A ∥⊎∥ᴱ B) → P x) ↔⟨ universal-property-Π P-prop ⟩
((x : A ⊎ B) → P ∣ x ∣) ↝⟨ Π⊎↔Π×Π ext ⟩□
((x : A) → P (∣inj₁∣ x)) × ((y : B) → P (∣inj₂∣ y)) □
-- Two distributivity laws for Σ and _∥⊎∥ᴱ_.
Σ-∥⊎∥ᴱ-distrib-left :
@0 Is-proposition A →
Σ A (λ x → P x ∥⊎∥ᴱ Q x) ↔ Σ A P ∥⊎∥ᴱ Σ A Q
Σ-∥⊎∥ᴱ-distrib-left {P = P} {Q = Q} A-prop =
(∃ λ x → ∥ P x ⊎ Q x ∥ᴱ) ↝⟨ inverse $ ∥∥ᴱ↔ (Σ-closure 1 A-prop λ _ → ∥⊎∥ᴱ-propositional) ⟩
∥ (∃ λ x → ∥ P x ⊎ Q x ∥ᴱ) ∥ᴱ ↝⟨ flatten′
(λ F → (∃ λ x → F (P x ⊎ Q x)))
(λ f → Σ-map id f)
(uncurry λ x → ∥∥ᴱ-map (x ,_))
(λ _ → refl _)
(uncurry λ _ → elim λ where
.∣∣ʳ _ → refl _
.truncation-is-propositionʳ _ →
mono₁ 1 truncation-is-proposition) ⟩
∥ (∃ λ x → P x ⊎ Q x) ∥ᴱ ↝⟨ ∥∥ᴱ-cong ∃-⊎-distrib-left ⟩□
∥ ∃ P ⊎ ∃ Q ∥ᴱ □
Σ-∥⊎∥ᴱ-distrib-right :
@0 (∀ x → Is-proposition (P x)) →
Σ (A ∥⊎∥ᴱ B) P ↔ Σ A (P ∘ ∣inj₁∣) ∥⊎∥ᴱ Σ B (P ∘ ∣inj₂∣)
Σ-∥⊎∥ᴱ-distrib-right {A = A} {B = B} {P = P} P-prop = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry $ elim λ where
.∣∣ʳ → curry (∣_∣ ∘ _↔_.to ∃-⊎-distrib-right)
.truncation-is-propositionʳ _ →
Π-closure ext 1 λ _ →
∥⊎∥ᴱ-propositional
; from = rec λ where
.∣∣ʳ → Σ-map ∣_∣ id ∘ _↔_.from ∃-⊎-distrib-right
.truncation-is-propositionʳ → prop
}
; right-inverse-of = elim λ where
.∣∣ʳ → P.[ (λ _ → refl _) , (λ _ → refl _) ]
.truncation-is-propositionʳ _ →
mono₁ 1 ∥⊎∥ᴱ-propositional
}
; left-inverse-of = uncurry $ elim λ where
.∣∣ʳ → P.[ (λ _ _ → refl _) , (λ _ _ → refl _) ]
.truncation-is-propositionʳ _ →
Π-closure ext 1 λ _ →
mono₁ 1 prop
}
where
@0 prop : _
prop = Σ-closure 1 ∥⊎∥ᴱ-propositional P-prop
-- A variant of one of De Morgan's laws.
¬∥⊎∥ᴱ¬↔¬× :
Dec (¬ A) → Dec (¬ B) →
(¬ A ∥⊎∥ᴱ ¬ B) ≃ᴱ (¬ (A × B))
¬∥⊎∥ᴱ¬↔¬× {A = A} {B = B} dec-¬A dec-¬B = EEq.⇔→≃ᴱ
∥⊎∥ᴱ-propositional
(¬-propositional ext)
(rec λ where
.∣∣ʳ → ¬⊎¬→׬
.truncation-is-propositionʳ → ¬-propositional ext)
(∣_∣ ∘ _↠_.from (¬⊎¬↠¬× ext dec-¬A dec-¬B))
------------------------------------------------------------------------
-- Code related to Erased-singleton
-- A corollary of erased-singleton-with-erased-center-propositional.
↠→↠Erased-singleton :
{@0 y : B}
(A↠B : A ↠ B) →
∥ (∃ λ (x : A) → Erased (_↠_.to A↠B x ≡ y)) ∥ᴱ ↠ Erased-singleton y
↠→↠Erased-singleton {A = A} {y = y} A↠B =
∥ (∃ λ (x : A) → Erased (_↠_.to A↠B x ≡ y)) ∥ᴱ ↝⟨ ∥∥ᴱ-cong-↠ (S.Σ-cong A↠B λ _ → F.id) ⟩
∥ Erased-singleton y ∥ᴱ ↔⟨ ∥∥ᴱ↔
(Er.erased-singleton-with-erased-center-propositional $
Er.Very-stable→Very-stableᴱ 1 $
Er.Very-stable→Very-stable-≡ 0 $
erased Er.Erased-Very-stable) ⟩□
Erased-singleton y □
-- Another corollary of
-- erased-singleton-with-erased-center-propositional.
↠→≃ᴱErased-singleton :
{@0 y : B}
(A↠B : A ↠ B) →
∥ (∃ λ (x : A) → Erased (_↠_.to A↠B x ≡ y)) ∥ᴱ ≃ᴱ Erased-singleton y
↠→≃ᴱErased-singleton {A = A} {y = y} A↠B =
∥ (∃ λ (x : A) → Erased (_↠_.to A↠B x ≡ y)) ∥ᴱ ↝⟨ ∥∥ᴱ-cong-⇔ (S.Σ-cong-⇔ A↠B λ _ → F.id) ⟩
∥ Erased-singleton y ∥ᴱ ↔⟨ ∥∥ᴱ↔
(Er.erased-singleton-with-erased-center-propositional $
Er.Very-stable→Very-stableᴱ 1 $
Er.Very-stable→Very-stable-≡ 0 $
erased Er.Erased-Very-stable) ⟩□
Erased-singleton y □
-- A corollary of Σ-Erased-Erased-singleton↔ and ↠→≃ᴱErased-singleton.
Σ-Erased-∥-Σ-Erased-≡-∥≃ᴱ :
(A↠B : A ↠ B) →
(∃ λ (x : Erased B) →
∥ (∃ λ (y : A) → Erased (_↠_.to A↠B y ≡ erased x)) ∥ᴱ) ≃ᴱ
B
Σ-Erased-∥-Σ-Erased-≡-∥≃ᴱ {A = A} {B = B} A↠B =
(∃ λ (x : Erased B) →
∥ (∃ λ (y : A) → Erased (_↠_.to A↠B y ≡ erased x)) ∥ᴱ) ↝⟨ (∃-cong λ _ → ↠→≃ᴱErased-singleton A↠B) ⟩
(∃ λ (x : Erased B) → Erased-singleton (erased x)) ↔⟨ Er.Σ-Erased-Erased-singleton↔ ⟩□
B □
-- In an erased context the left-to-right direction of
-- Σ-Erased-∥-Σ-Erased-≡-∥≃ᴱ returns the erased first component.
@0 to-Σ-Erased-∥-Σ-Erased-≡-∥≃ᴱ≡ :
∀ (A↠B : A ↠ B) x →
_≃ᴱ_.to (Σ-Erased-∥-Σ-Erased-≡-∥≃ᴱ A↠B) x ≡ erased (proj₁ x)
to-Σ-Erased-∥-Σ-Erased-≡-∥≃ᴱ≡ A↠B ([ x ] , y) =
_≃ᴱ_.to (Σ-Erased-∥-Σ-Erased-≡-∥≃ᴱ A↠B) ([ x ] , y) ≡⟨⟩
proj₁ (_≃ᴱ_.to (↠→≃ᴱErased-singleton A↠B) y) ≡⟨ erased (proj₂ (_≃ᴱ_.to (↠→≃ᴱErased-singleton A↠B) y)) ⟩∎
x ∎
| {
"alphanum_fraction": 0.4812963282,
"avg_line_length": 33.4673076923,
"ext": "agda",
"hexsha": "8c18d1781aacb098608ab72694f2ffc67050b8fb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/H-level/Truncation/Propositional/Erased.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/H-level/Truncation/Propositional/Erased.agda",
"max_line_length": 125,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/H-level/Truncation/Propositional/Erased.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 14539,
"size": 34806
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor hiding (id)
module Categories.Diagram.Colimit.Properties
{o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) where
private
module F = Functor F
module C = Category C
open C
open import Categories.Diagram.Limit F.op
open import Categories.Diagram.Colimit F
open import Categories.Category.Construction.Cocones F
open import Categories.Diagram.Duality C
module _ (X : Obj) (coapex₁ : Coapex X) (coapex₂ : Coapex X) (L : Colimit) where
private
module coapex₁ = Coapex coapex₁
module coapex₂ = Coapex coapex₂
module L = Colimit L
K₁ : Cocone
K₁ = record { coapex = coapex₁ }
module K₁ = Cocone K₁
K₂ : Cocone
K₂ = record { coapex = coapex₂ }
module K₂ = Cocone K₂
coψ-≈⇒rep-≈ : (∀ A → coapex₁.ψ A ≈ coapex₂.ψ A) → L.rep K₁ ≈ L.rep K₂
coψ-≈⇒rep-≈ = ψ-≈⇒rep-≈ X (Coapex⇒coApex X coapex₁) (Coapex⇒coApex X coapex₂) (Colimit⇒coLimit L)
| {
"alphanum_fraction": 0.668627451,
"avg_line_length": 29.1428571429,
"ext": "agda",
"hexsha": "36a8494bb9ea1d5f81fbba9dcfb1a4acf566e3d6",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Colimit/Properties.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Colimit/Properties.agda",
"max_line_length": 99,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Colimit/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 398,
"size": 1020
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.HomotopyGroup where
open import Cubical.Data.HomotopyGroup.Base public
| {
"alphanum_fraction": 0.7692307692,
"avg_line_length": 28.6,
"ext": "agda",
"hexsha": "22829cea626e9d90069058f76001070928b5deda",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/HomotopyGroup.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/HomotopyGroup.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/HomotopyGroup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 38,
"size": 143
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Nat
open import lib.types.Group
open import lib.types.TLevel
module lib.types.Int where
data ℤ : Type₀ where
O : ℤ
pos : (n : ℕ) → ℤ
neg : (n : ℕ) → ℤ
Int = ℤ
succ : ℤ → ℤ
succ O = pos O
succ (pos n) = pos (S n)
succ (neg O) = O
succ (neg (S n)) = neg n
pred : ℤ → ℤ
pred O = neg O
pred (pos O) = O
pred (pos (S n)) = pos n
pred (neg n) = neg (S n)
abstract
succ-pred : (n : ℤ) → succ (pred n) == n
succ-pred O = idp
succ-pred (pos O) = idp
succ-pred (pos (S n)) = idp
succ-pred (neg n) = idp
pred-succ : (n : ℤ) → pred (succ n) == n
pred-succ O = idp
pred-succ (pos n) = idp
pred-succ (neg O) = idp
pred-succ (neg (S n)) = idp
succ-equiv : ℤ ≃ ℤ
succ-equiv = equiv succ pred succ-pred pred-succ
pred-injective : (z₁ z₂ : ℤ) → pred z₁ == pred z₂ → z₁ == z₂
pred-injective z₁ z₂ p = ! (succ-pred z₁) ∙ ap succ p ∙ succ-pred z₂
succ-injective : (z₁ z₂ : ℤ) → succ z₁ == succ z₂ → z₁ == z₂
succ-injective z₁ z₂ p = ! (pred-succ z₁) ∙ ap pred p ∙ pred-succ z₂
{- Converting between ℤ, ℕ, and ℕ₋₂ -}
ℤ-to-ℕ₋₂ : ℤ → ℕ₋₂
ℤ-to-ℕ₋₂ O = ⟨0⟩
ℤ-to-ℕ₋₂ (pos m) = S ⟨ m ⟩
ℤ-to-ℕ₋₂ (neg O) = ⟨-1⟩
ℤ-to-ℕ₋₂ (neg _) = ⟨-2⟩
ℕ-to-ℤ : ℕ → ℤ
ℕ-to-ℤ n = pred (pos n)
{- Proof that [ℤ] has decidable equality and hence is a set -}
private
ℤ-get-pos : ℤ → ℕ
ℤ-get-pos O = 0
ℤ-get-pos (pos n) = n
ℤ-get-pos (neg n) = 0
ℤ-get-neg : ℤ → ℕ
ℤ-get-neg O = 0
ℤ-get-neg (pos n) = 0
ℤ-get-neg (neg n) = n
ℤ-neg≠O≠pos-type : ℤ → Type₀
ℤ-neg≠O≠pos-type O = Unit
ℤ-neg≠O≠pos-type (pos n) = Empty
ℤ-neg≠O≠pos-type (neg n) = Empty
ℤ-neg≠pos-type : ℤ → Type₀
ℤ-neg≠pos-type O = Unit
ℤ-neg≠pos-type (pos n) = Empty
ℤ-neg≠pos-type (neg n) = Unit
abstract
pos-injective : (n m : ℕ) (p : pos n == pos m) → n == m
pos-injective n m p = ap ℤ-get-pos p
neg-injective : (n m : ℕ) (p : neg n == neg m) → n == m
neg-injective n m p = ap ℤ-get-neg p
ℤ-O≠pos : (n : ℕ) → O ≠ pos n
ℤ-O≠pos n p = transport ℤ-neg≠O≠pos-type p unit
ℤ-pos≠O : (n : ℕ) → pos n ≠ O
ℤ-pos≠O n p = transport ℤ-neg≠O≠pos-type (! p) unit
ℤ-O≠neg : (n : ℕ) → O ≠ neg n
ℤ-O≠neg n p = transport ℤ-neg≠O≠pos-type p unit
ℤ-neg≠O : (n : ℕ) → neg n ≠ O
ℤ-neg≠O n p = transport ℤ-neg≠O≠pos-type (! p) unit
ℤ-neg≠pos : (n m : ℕ) → neg n ≠ pos m
ℤ-neg≠pos n m p = transport ℤ-neg≠pos-type p unit
ℤ-pos≠neg : (n m : ℕ) → pos n ≠ neg m
ℤ-pos≠neg n m p = transport ℤ-neg≠pos-type (! p) unit
ℤ-has-dec-eq : has-dec-eq ℤ
ℤ-has-dec-eq O O = inl idp
ℤ-has-dec-eq O (pos n) = inr (ℤ-O≠pos n)
ℤ-has-dec-eq O (neg n) = inr (ℤ-O≠neg n)
ℤ-has-dec-eq (pos n) O = inr (ℤ-pos≠O n)
ℤ-has-dec-eq (pos n) (pos m) with ℕ-has-dec-eq n m
ℤ-has-dec-eq (pos n) (pos m) | inl p = inl (ap pos p)
ℤ-has-dec-eq (pos n) (pos m) | inr p⊥ = inr (λ p → p⊥ (pos-injective n m p))
ℤ-has-dec-eq (pos n) (neg m) = inr (ℤ-pos≠neg n m)
ℤ-has-dec-eq (neg n) O = inr (ℤ-neg≠O n)
ℤ-has-dec-eq (neg n) (pos m) = inr (ℤ-neg≠pos n m)
ℤ-has-dec-eq (neg n) (neg m) with ℕ-has-dec-eq n m
ℤ-has-dec-eq (neg n) (neg m) | inl p = inl (ap neg p)
ℤ-has-dec-eq (neg n) (neg m) | inr p⊥ = inr (λ p → p⊥ (neg-injective n m p))
ℤ-is-set : is-set ℤ
ℤ-is-set = dec-eq-is-set ℤ-has-dec-eq
ℤ-level = ℤ-is-set
{-
ℤ is also a group!
-}
-- inv
ℤ~ : ℤ → ℤ
ℤ~ O = O
ℤ~ (pos n) = neg n
ℤ~ (neg n) = pos n
-- comp
_ℤ+_ : ℤ → ℤ → ℤ
O ℤ+ z = z
pos O ℤ+ z = succ z
pos (S n) ℤ+ z = succ (pos n ℤ+ z)
neg O ℤ+ z = pred z
neg (S n) ℤ+ z = pred (neg n ℤ+ z)
-- unit-l
ℤ+-unit-l : ∀ z → O ℤ+ z == z
ℤ+-unit-l _ = idp
-- unit-r
private
ℤ+-unit-r-pos : ∀ n → pos n ℤ+ O == pos n
ℤ+-unit-r-pos O = idp
ℤ+-unit-r-pos (S n) = ap succ $ ℤ+-unit-r-pos n
ℤ+-unit-r-neg : ∀ n → neg n ℤ+ O == neg n
ℤ+-unit-r-neg O = idp
ℤ+-unit-r-neg (S n) = ap pred $ ℤ+-unit-r-neg n
ℤ+-unit-r : ∀ z → z ℤ+ O == z
ℤ+-unit-r O = idp
ℤ+-unit-r (pos n) = ℤ+-unit-r-pos n
ℤ+-unit-r (neg n) = ℤ+-unit-r-neg n
-- assoc
succ-ℤ+ : ∀ z₁ z₂ → succ z₁ ℤ+ z₂ == succ (z₁ ℤ+ z₂)
succ-ℤ+ O _ = idp
succ-ℤ+ (pos n) _ = idp
succ-ℤ+ (neg O) _ = ! $ succ-pred _
succ-ℤ+ (neg (S n)) _ = ! $ succ-pred _
pred-ℤ+ : ∀ z₁ z₂ → pred z₁ ℤ+ z₂ == pred (z₁ ℤ+ z₂)
pred-ℤ+ O _ = idp
pred-ℤ+ (neg n) _ = idp
pred-ℤ+ (pos O) _ = ! $ pred-succ _
pred-ℤ+ (pos (S n)) _ = ! $ pred-succ _
private
ℤ+-assoc-pos : ∀ n₁ z₂ z₃ → (pos n₁ ℤ+ z₂) ℤ+ z₃ == pos n₁ ℤ+ (z₂ ℤ+ z₃)
ℤ+-assoc-pos O z₂ z₃ = succ-ℤ+ z₂ z₃
ℤ+-assoc-pos (S n₁) z₂ z₃ =
succ (pos n₁ ℤ+ z₂) ℤ+ z₃ =⟨ succ-ℤ+ (pos n₁ ℤ+ z₂) z₃ ⟩
succ ((pos n₁ ℤ+ z₂) ℤ+ z₃) =⟨ ap succ $ ℤ+-assoc-pos n₁ z₂ z₃ ⟩
succ (pos n₁ ℤ+ (z₂ ℤ+ z₃)) ∎
ℤ+-assoc-neg : ∀ n₁ z₂ z₃ → (neg n₁ ℤ+ z₂) ℤ+ z₃ == neg n₁ ℤ+ (z₂ ℤ+ z₃)
ℤ+-assoc-neg O z₂ z₃ = pred-ℤ+ z₂ z₃
ℤ+-assoc-neg (S n₁) z₂ z₃ =
pred (neg n₁ ℤ+ z₂) ℤ+ z₃ =⟨ pred-ℤ+ (neg n₁ ℤ+ z₂) z₃ ⟩
pred ((neg n₁ ℤ+ z₂) ℤ+ z₃) =⟨ ap pred $ ℤ+-assoc-neg n₁ z₂ z₃ ⟩
pred (neg n₁ ℤ+ (z₂ ℤ+ z₃)) ∎
ℤ+-assoc : ∀ z₁ z₂ z₃ → (z₁ ℤ+ z₂) ℤ+ z₃ == z₁ ℤ+ (z₂ ℤ+ z₃)
ℤ+-assoc O _ _ = idp
ℤ+-assoc (pos n₁) _ _ = ℤ+-assoc-pos n₁ _ _
ℤ+-assoc (neg n₁) _ _ = ℤ+-assoc-neg n₁ _ _
private
pos-S-ℤ+-neg-S : ∀ n₁ n₂ → pos (S n₁) ℤ+ neg (S n₂) == pos n₁ ℤ+ neg n₂
pos-S-ℤ+-neg-S O n₂ = idp
pos-S-ℤ+-neg-S (S n₁) n₂ = ap succ $ pos-S-ℤ+-neg-S n₁ n₂
neg-S-ℤ+-pos-S : ∀ n₁ n₂ → neg (S n₁) ℤ+ pos (S n₂) == neg n₁ ℤ+ pos n₂
neg-S-ℤ+-pos-S O n₂ = idp
neg-S-ℤ+-pos-S (S n₁) n₂ = ap pred $ neg-S-ℤ+-pos-S n₁ n₂
ℤ~-inv-r-pos : ∀ n → pos n ℤ+ neg n == O
ℤ~-inv-r-pos O = idp
ℤ~-inv-r-pos (S n) =
pos (S n) ℤ+ neg (S n) =⟨ pos-S-ℤ+-neg-S n n ⟩
pos n ℤ+ neg n =⟨ ℤ~-inv-r-pos n ⟩
O ∎
ℤ~-inv-r-neg : ∀ n → neg n ℤ+ pos n == O
ℤ~-inv-r-neg O = idp
ℤ~-inv-r-neg (S n) =
neg (S n) ℤ+ pos (S n) =⟨ neg-S-ℤ+-pos-S n n ⟩
neg n ℤ+ pos n =⟨ ℤ~-inv-r-neg n ⟩
O ∎
ℤ~-inv-r : ∀ z → z ℤ+ ℤ~ z == O
ℤ~-inv-r O = idp
ℤ~-inv-r (pos n) = ℤ~-inv-r-pos n
ℤ~-inv-r (neg n) = ℤ~-inv-r-neg n
ℤ~-inv-l : ∀ z → ℤ~ z ℤ+ z == O
ℤ~-inv-l O = idp
ℤ~-inv-l (pos n) = ℤ~-inv-r-neg n
ℤ~-inv-l (neg n) = ℤ~-inv-r-pos n
ℤ-group-structure : GroupStructure ℤ
ℤ-group-structure = record
{ ident = O
; inv = ℤ~
; comp = _ℤ+_
; unitl = ℤ+-unit-l
; unitr = ℤ+-unit-r
; assoc = ℤ+-assoc
; invr = ℤ~-inv-r
; invl = ℤ~-inv-l
}
ℤ-group : Group₀
ℤ-group = group _ ℤ-is-set ℤ-group-structure
| {
"alphanum_fraction": 0.5207948244,
"avg_line_length": 26.1774193548,
"ext": "agda",
"hexsha": "e4898826768711adcc3df81fd4bea3d51dae60c7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "lib/types/Int.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "danbornside/HoTT-Agda",
"max_issues_repo_path": "lib/types/Int.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "lib/types/Int.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3309,
"size": 6492
} |
module Numeral.Sign.Oper.Proofs where
| {
"alphanum_fraction": 0.8421052632,
"avg_line_length": 19,
"ext": "agda",
"hexsha": "a697b20c25b24b68c98115085e960fdc8233f4c9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Sign/Oper/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Sign/Oper/Proofs.agda",
"max_line_length": 37,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Sign/Oper/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 10,
"size": 38
} |
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub
open import Agda.Primitive renaming (_⊔_ to ℓ-max)
open import Agda.Builtin.Sigma
private
internalFiber : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) (y : B) → Set (ℓ-max ℓ ℓ')
internalFiber {A = A} f y = Σ A \ x → y ≡ f x
infix 4 _≃_
postulate
_≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ-max ℓ ℓ')
equivFun : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → A ≃ B → A → B
equivProof : ∀ {la lt} (T : Set la) (A : Set lt) → (w : T ≃ A) → (a : A)
→ ∀ ψ → (Partial ψ (internalFiber (equivFun w) a)) → internalFiber (equivFun w) a
{-# BUILTIN EQUIV _≃_ #-}
{-# BUILTIN EQUIVFUN equivFun #-}
{-# BUILTIN EQUIVPROOF equivProof #-}
-- This is a module so we can easily rename the primitives.
module GluePrims where
primitive
primGlue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
→ (T : Partial φ (Set ℓ')) → (e : PartialP φ (λ o → T o ≃ A))
→ Set ℓ'
prim^glue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
→ {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
→ PartialP φ T → A → primGlue A T e
prim^unglue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
→ {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
→ primGlue A T e → A
-- Needed for transp in Glue.
primFaceForall : (I → I) → I
open GluePrims public
renaming ( prim^glue to glue
; prim^unglue to unglue)
-- We uncurry Glue to make it a bit more pleasant to use
Glue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
→ (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
→ Set ℓ'
Glue A Te = primGlue A (λ x → Te x .fst) (λ x → Te x .snd)
module _ {ℓ ℓ'} (A : Set ℓ) {φ : I} (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
(ψ : I) (u : I → Partial ψ (Glue A Te)) (u0 : Sub (Glue A Te) ψ (u i0) ) where
result : Glue A Te
result = glue {φ = φ} (\ { (φ = i1) → primHComp {A = Te itIsOne .fst} u (primSubOut u0) })
(primHComp {A = A} (\ i → \ { (ψ = i1) → unglue {φ = φ} (u i itIsOne)
; (φ = i1) → equivFun (Te itIsOne .snd)
(primHComp (\ j → \ { (ψ = i1) → u (primIMin i j) itIsOne
; (i = i0) → primSubOut u0 })
(primSubOut u0)) })
(unglue {φ = φ} (primSubOut u0)))
test : primHComp {A = Glue A Te} {ψ} u (primSubOut u0) ≡ result
test i = primHComp {A = Glue A Te} {ψ} u (primSubOut u0)
| {
"alphanum_fraction": 0.4636463281,
"avg_line_length": 42.765625,
"ext": "agda",
"hexsha": "f45a6212e06f2e11847ac48ddd88d31023551522",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bennn/agda",
"max_forks_repo_path": "test/Succeed/Issue3399.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "bennn/agda",
"max_issues_repo_path": "test/Succeed/Issue3399.agda",
"max_line_length": 131,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bennn/agda",
"max_stars_repo_path": "test/Succeed/Issue3399.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1014,
"size": 2737
} |
open import Structures
open import Data.String using (String)
open import Data.Nat
open import Data.Nat.Show renaming (show to showNat)
open import Data.Vec as V using (Vec; []; _∷_)
open import Data.List as L using (List; []; _∷_)
open import Data.Sum
open import Data.Product
open import Relation.Nullary
open import Function using (_$_)
data Nesting : Set where
hom : Nesting
nes : Nesting
data SacTy : Set where
unit : SacTy
int : SacTy
float : SacTy
bool : SacTy
char : SacTy
-- Nested `n`-dimensional array is isomorphic to Listⁿ
-- Homogeneous `n`-dimensional array is isomorphic to Vecⁿ
-- The first argument does not tell whether the entire array needs
-- to be implemented as nested or not (just an annotation), e.g:
-- akd hom (akd nest nat 3)
-- akd nes nat 2
-- akd nes (akd nes nat 1)
-- and so on. In actual sac (with no support for nested arrays)
-- it all collapses to three cases, but it is convenient to keep
-- this distinction in the model.
aud : Nesting → SacTy → (sh : Prog) → SacTy
akd : Nesting → SacTy → (sh : Prog) → ℕ → SacTy
aks : Nesting → SacTy → (sh : Prog) → (n : ℕ) → Vec ℕ n → SacTy
data SacBase : SacTy → Set where
unit : SacBase unit
int : SacBase int
float : SacBase float
bool : SacBase bool
char : SacBase char
data SacArray : SacTy → Set where
aud : ∀ {n? τ es} → SacArray (aud n? τ es)
akd : ∀ {n? τ es n} → SacArray (akd n? τ es n)
aks : ∀ {n? τ es n s} → SacArray (aks n? τ es n s)
array-or-base : ∀ τ → SacBase τ ⊎ SacArray τ
array-or-base unit = inj₁ unit
array-or-base int = inj₁ int
array-or-base float = inj₁ float
array-or-base bool = inj₁ bool
array-or-base char = inj₁ char
array-or-base (aud x τ es) = inj₂ aud
array-or-base (akd x τ es x₁) = inj₂ akd
array-or-base (aks x τ es n x₁) = inj₂ aks
is-base : ∀ τ → Dec (SacBase τ)
is-base τ with array-or-base τ
... | inj₁ bt = yes bt
... | inj₂ aud = no λ ()
... | inj₂ akd = no λ ()
... | inj₂ aks = no λ ()
is-array : ∀ τ → Dec (SacArray τ)
is-array τ with array-or-base τ
... | inj₂ ar = yes ar
... | inj₁ unit = no λ ()
... | inj₁ int = no λ ()
... | inj₁ float = no λ ()
... | inj₁ bool = no λ ()
... | inj₁ char = no λ ()
-- Is it the case that the entire array can be implemented
-- as a flattened homogeneous (multi-dimensional) array.
nested? : SacTy → Nesting
nested? unit = hom
nested? int = hom
nested? float = hom
nested? bool = hom
nested? char = hom
nested? (aud hom τ _) = nested? τ
nested? (aud nes _ _) = nes
nested? (akd hom τ _ _) = nested? τ
nested? (akd nes _ _ _) = nes
nested? (aks hom τ _ _ _) = nested? τ
nested? (aks nes _ _ _ _) = nes
get-base : SacTy → Σ[ τ ∈ SacTy ] SacBase τ
get-base unit = unit , unit
get-base int = int , int
get-base float = float , float
get-base bool = bool , bool
get-base char = char , char
get-base (aud x τ es) = get-base τ
get-base (akd x τ es x₁) = get-base τ
get-base (aks x τ es n x₁) = get-base τ
bt-tostring : ∀ {τ} → SacBase τ → String
bt-tostring unit = "unit"
bt-tostring int = "int"
bt-tostring float = "float"
bt-tostring bool = "bool"
bt-tostring char = "char"
postfix-aud = "[*]"
postfix-akd : ℕ → String
postfix-akd n = "[" ++ ("," ++/ L.replicate n ".") ++ "]"
postfix-aks : (n : ℕ) → Vec ℕ n → String
postfix-aks n s = "[" ++ ("," ++/ L.map showNat (V.toList s)) ++ "]"
bt : SacTy → String
bt τ = bt-tostring (proj₂ $ get-base τ)
sacty-to-string : SacTy → String
sacty-to-string σ with array-or-base σ
sacty-to-string σ | inj₁ bt = bt-tostring bt
sacty-to-string σ | inj₂ (aud {nes} {τ}) = sacty-to-string τ ++ postfix-aud
sacty-to-string σ | inj₂ (aud {hom} {τ}) with nested? τ
... | hom = bt τ ++ postfix-aud
... | nes = sacty-to-string τ ++ postfix-aud
sacty-to-string σ | inj₂ (akd {nes} {τ} {_} {n}) = sacty-to-string τ ++ postfix-akd n
sacty-to-string σ | inj₂ (akd {hom} {τ} {_} {n}) with nested? τ
... | nes = sacty-to-string τ ++ postfix-akd n
... | hom with array-or-base τ
... | inj₁ bt =
bt-tostring bt ++ postfix-akd n
... | inj₂ aud =
--(τ[*])[.,.,.] → τ([.,.,.] ++ [*]) = τ[*]
bt τ ++ postfix-aud
... | inj₂ (akd {n = m}) =
--(τ[.,.])[.,.,.] → τ([.,.,.] ++ [.,.]) = τ[.,.,., .,.]
bt τ ++ postfix-akd (n + m)
... | inj₂ (aks {n = m}) =
--(τ[5,6])[.,.,.] → τ([.,.,.] ++ [5,6]) = τ[.,.,., .,.]
bt τ ++ postfix-akd (n + m)
sacty-to-string σ | inj₂ (aks {nes} {τ} {_} {n} {s}) = sacty-to-string τ ++ postfix-aks n s
sacty-to-string σ | inj₂ (aks {hom} {τ} {_} {n} {s}) with nested? τ
... | nes = sacty-to-string τ ++ postfix-aks n s
... | hom with array-or-base τ
... | inj₁ bt =
bt-tostring bt ++ postfix-aks n s
... | inj₂ aud =
-- (τ[*])[5,6] → τ([5,6] ++ [*]) = τ[*]
bt τ ++ postfix-aud
... | inj₂ (akd {n = m}) =
--(τ[.,.])[5,6] → τ([5,6] ++ [.,.]) = τ[.,.,.,.]
bt τ ++ postfix-akd (n + m)
... | inj₂ (aks {s = s′}) =
--(τ[7,8])[5,6] → τ([5,6] ++ [7,8]) = τ[5,6,7,8]
bt τ ++ postfix-aks _ (s V.++ s′)
-- For some rare cases we can eliminate nesting
-- Note that this function does not recurse, as:
-- a: List (hom X) ~ Vec (hom X) (length a)
-- but
-- a: List (List (hom X)) ≁ Vec (Vec X _) _
sacty-normalise : SacTy → SacTy
sacty-normalise τ with array-or-base τ
sacty-normalise τ | inj₁ bt = τ
sacty-normalise τ | inj₂ aud = τ
sacty-normalise τ | inj₂ (akd {hom}) = τ
sacty-normalise τ | inj₂ (akd {nes} {σ} {es} {0}) = -- There is no need to nest a 0-dimensional array
akd hom σ es 0
sacty-normalise τ | inj₂ (akd {nes} {σ} {es} {1}) = -- Nested array of depth 1 of homogeneous elements
-- is the same as homogeneous of dimension 1.
akd hom σ es 1
sacty-normalise τ | inj₂ (akd {nes} {_} {_}) = τ
sacty-normalise τ | inj₂ (aks {hom}) = τ
sacty-normalise τ | inj₂ (aks {nes} {σ} {es} {n} {s}) = aks hom σ es n s
sacty-shape : SacTy → Prog
sacty-shape τ with array-or-base τ
... | inj₁ bt = ok $ "[]"
... | inj₂ (aud {hom} {σ} {s}) = s ⊕ " ++ " ⊕ sacty-shape σ
... | inj₂ (aud {nes} {σ} {s}) = error $ "sacty-shape: nested-array `" ++ sacty-to-string τ ++ "`"
... | inj₂ (akd {hom} {σ} {s}) = s ⊕ " ++ " ⊕ sacty-shape σ
... | inj₂ (akd {nes} {σ} {s}) = error $ "sacty-shape: nested-array `" ++ sacty-to-string τ ++ "`"
... | inj₂ (aks {hom} {σ} {s}) = s ⊕ " ++ " ⊕ sacty-shape σ
... | inj₂ (aks {nes} {σ} {s}) = error $ "sacty-shape: nested-array `" ++ sacty-to-string τ ++ "`"
| {
"alphanum_fraction": 0.5533093741,
"avg_line_length": 34.78125,
"ext": "agda",
"hexsha": "251eae0b7cca9b5c702c7169c2b739edb3413a59",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-extractor",
"max_forks_repo_path": "SacTy.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "ashinkarov/agda-extractor",
"max_issues_repo_path": "SacTy.agda",
"max_line_length": 102,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-extractor",
"max_stars_repo_path": "SacTy.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z",
"num_tokens": 2368,
"size": 6678
} |
------------------------------------------------------------------------
-- The delay monad, defined coinductively, with a sized type parameter
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Delay-monad.Sized where
open import Equality.Propositional
open import Prelude
open import Prelude.Size
open import Bijection equality-with-J using (_↔_)
-- The delay monad.
mutual
data Delay {a} (A : Size → Type a) (i : Size) : Type a where
now : A i → Delay A i
later : Delay′ A i → Delay A i
record Delay′ {a} (A : Size → Type a) (i : Size) : Type a where
coinductive
field
force : {j : Size< i} → Delay A j
open Delay′ public
module _ {a} {A : Size → Type a} where
mutual
-- A non-terminating computation.
never : ∀ {i} → Delay A i
never = later never′
never′ : ∀ {i} → Delay′ A i
force never′ = never
-- Removes a later constructor, if possible.
drop-later : Delay A ∞ → Delay A ∞
drop-later (now x) = now x
drop-later (later x) = force x
-- An unfolding lemma for Delay.
Delay↔ : ∀ {i} → Delay A i ↔ A i ⊎ Delay′ A i
Delay↔ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (now x) → inj₁ x; (later x) → inj₂ x }
; from = [ now , later ]
}
; right-inverse-of = [ (λ _ → refl) , (λ _ → refl) ]
}
; left-inverse-of = λ { (now _) → refl; (later _) → refl }
}
| {
"alphanum_fraction": 0.5195154778,
"avg_line_length": 24.3606557377,
"ext": "agda",
"hexsha": "dcc4fdee8e50180e22f376fc20568534841db841",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Sized.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Sized.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Sized.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 427,
"size": 1486
} |
{-# OPTIONS -v term.with.inline:20 -v term.with.call:30 #-}
data Nat : Set where
zero : Nat
suc : Nat → Nat
_+_ : Nat → Nat → Nat
zero + m = m
suc n + m = suc (n + m)
data [_] : Nat → Set where
⟨_⟩ : ∀ n → [ n ]
f : Nat → Nat
g : Nat → Nat
h : ∀ n → [ f n ]
f zero = zero
f (suc n) with f n
f (suc n) | zero = zero
f (suc n) | suc m = f n + m
-- f's with-function should not get inlined into the clauses of g!
g zero = zero
g (suc n) = _ -- f (suc n) | f n
h zero = ⟨ zero ⟩
h (suc n) = ⟨ g (suc n) ⟩
| {
"alphanum_fraction": 0.5202312139,
"avg_line_length": 17.3,
"ext": "agda",
"hexsha": "3eb746df4c32c1e8845872be83061e156313d6ca",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/interaction/Issue59.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/interaction/Issue59.agda",
"max_line_length": 66,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/interaction/Issue59.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 212,
"size": 519
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.SuspAdjointLoopIso
open import cohomology.WithCoefficients
open import cohomology.Theory
open import cohomology.Exactness
open import cohomology.Choice
module cohomology.SpectrumModel
{i} (E : ℤ → Ptd i) (spectrum : (n : ℤ) → ⊙Ω (E (succ n)) == E n) where
module SpectrumModel where
{- Definition of cohomology group C -}
module _ (n : ℤ) (X : Ptd i) where
C : Group i
C = →Ω-Group X (E (succ n))
{- convenient abbreviations -}
CEl = Group.El C
⊙CEl = Group.⊙El C
Cid = Group.ident C
{- before truncation -}
⊙uCEl : Ptd i
⊙uCEl = X ⊙→ ⊙Ω (E (succ n))
uCEl = fst ⊙uCEl
uCid = snd ⊙uCEl
{- Cⁿ(X) is an abelian group -}
C-abelian : (n : ℤ) (X : Ptd i) → is-abelian (C n X)
C-abelian n X =
transport (is-abelian ∘ →Ω-Group X) (spectrum (succ n)) C-abelian-lemma
where
pt-lemma : ∀ {i} {X : Ptd i} {α β : Ω^ 2 X}
(γ : α == idp^ 2) (δ : β == idp^ 2)
→ ap2 _∙_ γ δ == conc^2-comm α β ∙ ap2 _∙_ δ γ
pt-lemma idp idp = idp
C-abelian-lemma = Trunc-elim
(λ _ → Π-level (λ _ → =-preserves-level _ Trunc-level))
(λ {(f , fpt) → Trunc-elim
(λ _ → =-preserves-level _ Trunc-level)
(λ {(g , gpt) → ap [_] $ ⊙λ=
(λ x → conc^2-comm (f x) (g x))
(pt-lemma fpt gpt)})})
{- CF, the functorial action of C:
- contravariant functor from pointed spaces to abelian groups -}
module _ (n : ℤ) {X Y : Ptd i} where
{- before truncation - from pointed spaces to pointed spaces -}
uCF : fst (X ⊙→ Y) → fst (⊙uCEl n Y ⊙→ ⊙uCEl n X)
uCF f =
((λ g → g ⊙∘ f) ,
pair= idp (∙-unit-r _ ∙ ap-cst idp (snd f)))
CF-hom : fst (X ⊙→ Y) → (C n Y →ᴳ C n X)
CF-hom f = record {
f = Trunc-fmap {n = ⟨0⟩} (fst (uCF f));
pres-comp = Trunc-elim
(λ _ → Π-level (λ _ → =-preserves-level _ Trunc-level))
(λ g → Trunc-elim
(λ _ → =-preserves-level _ Trunc-level)
(λ h → ap [_] $ pair= idp (comp-snd _∙_ f g h)))}
where
comp-snd : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {C : Type k}
{c₁ c₂ : C} (_⊕_ : C → C → C) (f : fst (X ⊙→ Y))
(g : fst (Y ⊙→ ⊙[ C , c₁ ])) (h : fst (Y ⊙→ ⊙[ C , c₂ ]))
→ ap (λ x → fst g x ⊕ fst h x) (snd f) ∙ ap2 _⊕_ (snd g) (snd h)
== ap2 _⊕_ (ap (fst g) (snd f) ∙ snd g) (ap (fst h) (snd f) ∙ snd h)
comp-snd _⊕_ (_ , idp) (_ , idp) (_ , idp) = idp
CF : fst (X ⊙→ Y) → fst (⊙CEl n Y ⊙→ ⊙CEl n X)
CF F = GroupHom.⊙f (CF-hom F)
{- CF-hom is a functor from pointed spaces to abelian groups -}
module _ (n : ℤ) {X : Ptd i} where
CF-ident : CF-hom n {X} {X} (⊙idf X) == idhom (C n X)
CF-ident = hom= _ _ $ λ= $ Trunc-elim
(λ _ → =-preserves-level _ Trunc-level)
(λ _ → idp)
CF-comp : {Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))
→ CF-hom n (g ⊙∘ f) == CF-hom n f ∘ᴳ CF-hom n g
CF-comp g f = hom= _ _ $ λ= $ Trunc-elim
(λ _ → =-preserves-level _ Trunc-level)
(λ h → ap [_] (! (⊙∘-assoc h g f)))
{- Eilenberg-Steenrod Axioms -}
{- Suspension Axiom -}
C-Susp : (n : ℤ) (X : Ptd i) → C (succ n) (⊙Susp X) == C n X
C-Susp n X =
group-ua (SuspAdjointLoopIso.iso X (E (succ (succ n))))
∙ ap (→Ω-Group X) (spectrum (succ n))
{- Non-truncated Exactness Axiom -}
module _ (n : ℤ) {X Y : Ptd i} where
{- [uCF n (⊙cfcod f) ∘ uCF n f] is constant -}
uC-exact-itok-lemma : (f : fst (X ⊙→ Y)) (g : uCEl n (⊙Cof f))
→ fst (uCF n f) (fst (uCF n (⊙cfcod f)) g) == uCid n X
uC-exact-itok-lemma (f , fpt) (g , gpt) = ⊙λ=
(λ x → ap g (! (cfglue f x)) ∙ gpt)
(ap (g ∘ cfcod f) fpt
∙ ap g (ap (cfcod f) (! fpt) ∙ ! (cfglue f (snd X))) ∙ gpt
=⟨ lemma (cfcod f) g fpt (! (cfglue f (snd X))) gpt ⟩
ap g (! (cfglue f (snd X))) ∙ gpt
=⟨ ! (∙-unit-r _) ⟩
(ap g (! (cfglue f (snd X))) ∙ gpt) ∙ idp ∎)
where
lemma : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
{a₁ a₂ : A} {b : B} {c : C} (f : A → B) (g : B → C)
(p : a₁ == a₂) (q : f a₁ == b) (r : g b == c)
→ ap (g ∘ f) p ∙ ap g (ap f (! p) ∙ q) ∙ r == ap g q ∙ r
lemma f g idp idp idp = idp
{- in kernel of [uCF n f] ⇒ in image of [uCF n (⊙cfcod f)] -}
uC-exact-ktoi-lemma : (f : fst (X ⊙→ Y)) (g : uCEl n Y)
→ fst (uCF n f) g == uCid n X
→ Σ (uCEl n (⊙Cof f)) (λ h → fst (uCF n (⊙cfcod f)) h == g)
uC-exact-ktoi-lemma (f , fpt) (h , hpt) p =
((g , ! q ∙ hpt) ,
pair= idp (! (∙-assoc q (! q) hpt) ∙ ap (λ w → w ∙ hpt) (!-inv-r q)))
where
g : Cofiber f → Ω (E (succ n))
g = CofiberRec.f f idp h (! ∘ app= (ap fst p))
q : h (snd Y) == g (cfbase f)
q = ap g (snd (⊙cfcod (f , fpt)))
{- Truncated Exactness Axiom -}
module _ (n : ℤ) {X Y : Ptd i} where
{- in image of (CF n (⊙cfcod f)) ⇒ in kernel of (CF n f) -}
abstract
C-exact-itok : (f : fst (X ⊙→ Y))
→ is-exact-itok (CF n (⊙cfcod f)) (CF n f)
C-exact-itok f =
itok-alt-in (CF n (⊙cfcod f)) (CF n f) (Trunc-level {n = ⟨0⟩}) $
Trunc-elim (λ _ → =-preserves-level _ (Trunc-level {n = ⟨0⟩}))
(ap [_] ∘ uC-exact-itok-lemma n f)
{- in kernel of (CF n f) ⇒ in image of (CF n (⊙cfcod f)) -}
abstract
C-exact-ktoi : (f : fst (X ⊙→ Y))
→ is-exact-ktoi (CF n (⊙cfcod f)) (CF n f)
C-exact-ktoi f =
Trunc-elim
(λ _ → Π-level (λ _ → raise-level _ Trunc-level))
(λ h tp → Trunc-rec Trunc-level (lemma h) (–> (Trunc=-equiv _ _) tp))
where
lemma : (h : uCEl n Y)
→ fst (uCF n f) h == uCid n X
→ Trunc ⟨-1⟩ (Σ (CEl n (⊙Cof f))
(λ tk → fst (CF n (⊙cfcod f)) tk == [ h ]))
lemma h p = [ [ fst wit ] , ap [_] (snd wit) ]
where
wit : Σ (uCEl n (⊙Cof f)) (λ k → fst (uCF n (⊙cfcod f)) k == h)
wit = uC-exact-ktoi-lemma n f h p
C-exact : (f : fst (X ⊙→ Y)) → is-exact (CF n (⊙cfcod f)) (CF n f)
C-exact f = record {itok = C-exact-itok f; ktoi = C-exact-ktoi f}
{- Additivity Axiom -}
module _ (n : ℤ) {A : Type i} (X : A → Ptd i)
(ac : (W : A → Type i) → has-choice ⟨0⟩ A W)
where
uie : has-choice ⟨0⟩ A (uCEl n ∘ X)
uie = ac (uCEl n ∘ X)
R' : CEl n (⊙BigWedge X) → Trunc ⟨0⟩ (Π A (uCEl n ∘ X))
R' = Trunc-rec Trunc-level (λ H → [ (λ a → H ⊙∘ ⊙bwin a) ])
L' : Trunc ⟨0⟩ (Π A (uCEl n ∘ X)) → CEl n (⊙BigWedge X)
L' = Trunc-rec Trunc-level
(λ k → [ BigWedgeRec.f idp (fst ∘ k) (! ∘ snd ∘ k) , idp ])
R = unchoose ∘ R'
L = L' ∘ (is-equiv.g uie)
R'-L' : ∀ y → R' (L' y) == y
R'-L' = Trunc-elim
(λ _ → =-preserves-level _ Trunc-level)
(λ K → ap [_] (λ= (λ a → pair= idp $
ap (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (! (bwglue a)) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (! (bwglue a))
=⟨ ap-! (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (bwglue a) ⟩
! (ap (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (bwglue a))
=⟨ ap ! (BigWedgeRec.glue-β idp (fst ∘ K) (! ∘ snd ∘ K) a) ⟩
! (! (snd (K a)))
=⟨ !-! (snd (K a)) ⟩
snd (K a) ∎)))
L'-R' : ∀ x → L' (R' x) == x
L'-R' = Trunc-elim
{P = λ tH → L' (R' tH) == tH}
(λ _ → =-preserves-level _ Trunc-level)
(λ {(h , hpt) → ap [_] (pair=
(λ= (L-R-fst (h , hpt)))
(↓-app=cst-in $ ! $
ap (λ w → w ∙ hpt) (app=-β (L-R-fst (h , hpt)) bwbase)
∙ !-inv-l hpt))})
where
lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a₁ a₂ : A} {b : B} (p : a₁ == a₂) (q : f a₁ == b)
→ ! q ∙ ap f p == ! (ap f (! p) ∙ q)
lemma f idp idp = idp
l∘r : fst (⊙BigWedge X ⊙→ ⊙Ω (E (succ n)))
→ (BigWedge X → Ω (E (succ n)))
l∘r (h , hpt) =
BigWedgeRec.f idp (λ a → h ∘ bwin a)
(λ a → ! (ap h (! (bwglue a)) ∙ hpt))
L-R-fst : (h : fst (⊙BigWedge X ⊙→ ⊙Ω (E (succ n))))
→ ∀ w → (l∘r h) w == fst h w
L-R-fst (h , hpt) = BigWedge-elim
(! hpt)
(λ _ _ → idp)
(λ a → ↓-='-in $
! hpt ∙ ap h (bwglue a)
=⟨ lemma h (bwglue a) hpt ⟩
! (ap h (! (bwglue a)) ∙ hpt)
=⟨ ! (BigWedgeRec.glue-β idp (λ a → h ∘ bwin a)
(λ a → ! (ap h (! (bwglue a)) ∙ hpt)) a) ⟩
ap (l∘r (h , hpt)) (bwglue a) ∎)
R-is-equiv : is-equiv R
R-is-equiv = uie ∘ise (is-eq R' L' R'-L' L'-R')
pres-comp : (tf tg : CEl n (⊙BigWedge X))
→ R (Group.comp (C n (⊙BigWedge X)) tf tg)
== Group.comp (Πᴳ A (C n ∘ X)) (R tf) (R tg)
pres-comp = Trunc-elim
(λ _ → Π-level (λ _ → =-preserves-level _ (Π-level (λ _ → Trunc-level))))
(λ {(f , fpt) → Trunc-elim
(λ _ → =-preserves-level _ (Π-level (λ _ → Trunc-level)))
(λ {(g , gpt) → λ= $ λ a → ap [_] $
pair= idp (comp-snd f g (! (bwglue a)) fpt gpt)})})
where
comp-snd : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} {b₀ : B}
{p q : b₀ == b₀} (f : A → b₀ == b₀) (g : A → b₀ == b₀)
(r : a₁ == a₂) (α : f a₂ == p) (β : g a₂ == q)
→ ap (λ x → f x ∙ g x) r ∙ ap2 _∙_ α β
== ap2 _∙_ (ap f r ∙ α) (ap g r ∙ β)
comp-snd f g idp idp idp = idp
abstract
C-additive : C n (⊙BigWedge X) == Πᴳ A (C n ∘ X)
C-additive = group-ua (group-hom R pres-comp , R-is-equiv)
open SpectrumModel
spectrum-cohomology : CohomologyTheory i
spectrum-cohomology = record {
C = C;
CF-hom = CF-hom;
CF-ident = CF-ident;
CF-comp = CF-comp;
C-abelian = C-abelian;
C-Susp = C-Susp;
C-exact = C-exact;
C-additive = C-additive}
spectrum-C-S⁰ : (n : ℤ) → C n (⊙Sphere O) == π 1 (ℕ-S≠O _) (E (succ n))
spectrum-C-S⁰ n = Bool⊙→Ω-is-π₁ (E (succ n))
| {
"alphanum_fraction": 0.4615073752,
"avg_line_length": 36.1240875912,
"ext": "agda",
"hexsha": "d38c65238cdb0426a261853473eaabd030b491b1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "cohomology/SpectrumModel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "danbornside/HoTT-Agda",
"max_issues_repo_path": "cohomology/SpectrumModel.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "cohomology/SpectrumModel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4348,
"size": 9898
} |
{-# OPTIONS --without-K #-}
open import Prelude
import GSeTT.Syntax
import GSeTT.Rules
open import CaTT.Ps-contexts
open import CaTT.Relation
open import CaTT.Uniqueness-Derivations-Ps
open import CaTT.Decidability-ps
open import CaTT.Fullness
import GSeTT.Typed-Syntax
module CaTT.CaTT where
J : Set₁
J = Σ (ps-ctx × Ty) λ {(Γ , A) → A is-full-in Γ }
open import Globular-TT.Syntax J
Ty→Pre-Ty : Ty → Pre-Ty
Tm→Pre-Tm : Tm → Pre-Tm
Sub→Pre-Sub : Sub → Pre-Sub
Ty→Pre-Ty ∗ = ∗
Ty→Pre-Ty (⇒ A t u) = ⇒ (Ty→Pre-Ty A) (Tm→Pre-Tm t) (Tm→Pre-Tm u)
Tm→Pre-Tm (v x) = Var x
Tm→Pre-Tm (coh Γ A Afull γ) = Tm-constructor (((Γ , A)) , Afull) (Sub→Pre-Sub γ)
Sub→Pre-Sub <> = <>
Sub→Pre-Sub < γ , x ↦ t > = < Sub→Pre-Sub γ , x ↦ Tm→Pre-Tm t >
_[_]Ty : Ty → Sub → Ty
_[_]Tm : Tm → Sub → Tm
_∘ₛ_ : Sub → Sub → Sub
∗ [ σ ]Ty = ∗
⇒ A t u [ σ ]Ty = ⇒ (A [ σ ]Ty) (t [ σ ]Tm) (u [ σ ]Tm)
v x [ <> ]Tm = v x
v x [ < σ , y ↦ t > ]Tm = if x ≡ y then t else ((v x) [ σ ]Tm)
coh Γ A full γ [ σ ]Tm = coh Γ A full (γ ∘ₛ σ)
<> ∘ₛ γ = <>
< γ , x ↦ t > ∘ₛ δ = < γ ∘ₛ δ , x ↦ t [ δ ]Tm >
GPre-Ty→Ty : GSeTT.Syntax.Pre-Ty → Ty
GPre-Ty→Ty GSeTT.Syntax.∗ = ∗
GPre-Ty→Ty (GSeTT.Syntax.⇒ A (GSeTT.Syntax.Var x) (GSeTT.Syntax.Var y)) = ⇒ (GPre-Ty→Ty A) (v x) (v y)
Ty→Pre-Ty[] : ∀ {A γ} → ((GPre-Ty A) [ Sub→Pre-Sub γ ]Pre-Ty) == Ty→Pre-Ty ((GPre-Ty→Ty A) [ γ ]Ty)
Tm→Pre-Tm[] : ∀ {x γ} → ((Var x) [ Sub→Pre-Sub γ ]Pre-Tm) == Tm→Pre-Tm ((v x) [ γ ]Tm)
Ty→Pre-Ty[] {GSeTT.Syntax.∗} {γ} = idp
Ty→Pre-Ty[] {GSeTT.Syntax.⇒ A (GSeTT.Syntax.Var x) (GSeTT.Syntax.Var y)} {γ} = ap³ ⇒ Ty→Pre-Ty[] (Tm→Pre-Tm[] {x} {γ}) (Tm→Pre-Tm[] {y} {γ})
Tm→Pre-Tm[] {x} {<>} = idp
Tm→Pre-Tm[] {x} {< γ , y ↦ t >} with eqdecℕ x y
... | inl idp = idp
... | inr _ = Tm→Pre-Tm[] {x} {γ}
dim-Pre-Ty[] : ∀ {A γ} → dim (Ty→Pre-Ty ((GPre-Ty→Ty A) [ γ ]Ty)) == dim (GPre-Ty A)
dim-Pre-Ty[] {GSeTT.Syntax.∗} {γ} = idp
dim-Pre-Ty[] {GSeTT.Syntax.⇒ A (GSeTT.Syntax.Var _) (GSeTT.Syntax.Var _)} {γ} = ap S dim-Pre-Ty[]
rule : J → GSeTT.Typed-Syntax.Ctx × Pre-Ty
rule ((Γ , A) , _) = (fst Γ , Γ⊢ps→Γ⊢ (snd Γ)) , Ty→Pre-Ty A
open GSeTT.Typed-Syntax
open import Sets ℕ eqdecℕ
open import Globular-TT.Rules J rule
open import Globular-TT.CwF-Structure J rule
eqdecJ : eqdec J
eqdecJ ((Γ , A) , Afull) ((Γ' , A') , A'full) with eqdec-ps Γ Γ' | CaTT.Fullness.eqdec-Ty A A'
... | inl idp | inl idp = inl (ap (λ X → ((Γ , A) , X)) (is-prop-has-all-paths (is-prop-full Γ A) Afull A'full))
... | inr Γ≠Γ' | _ = inr λ{idp → Γ≠Γ' idp}
... | inl idp | inr A≠A' = inr λ{A=A' → A≠A' (snd (=, (fst-is-inj A=A')))}
open import Globular-TT.Uniqueness-Derivations J rule eqdecJ
open import Globular-TT.Disks J rule eqdecJ
dim-tm : ∀ {Γ x A} → Γ ⊢t Var x # A → ℕ
dim-tm {Γ} {x} {A} _ = dim A
GdimT : ∀ {A} → GSeTT.Syntax.dim A == dim (GPre-Ty A)
GdimT {GSeTT.Syntax.∗} = idp
GdimT {GSeTT.Syntax.⇒ A _ _} = ap S GdimT
GdimC : ∀ {Γ} → GSeTT.Syntax.dimC Γ == dimC (GPre-Ctx Γ)
GdimC {nil} = idp
GdimC {Γ :: (x , A)} = ap² max (GdimC {Γ}) GdimT
G#∈ : ∀ {Γ x A} → x GSeTT.Syntax.# A ∈ Γ → x # (GPre-Ty A) ∈ (GPre-Ctx Γ)
G#∈ {Γ :: a} (inl x∈Γ) = inl (G#∈ x∈Γ)
G#∈ {Γ :: a} (inr (idp , idp)) = inr (idp , idp)
G∈ : ∀ {Γ x} → x GSeTT.Syntax.∈ Γ → x ∈-set (varC Γ)
G∈ {Γ :: (a , _)} (inl x∈Γ) = ∈-∪₁ {A = varC Γ} {B = singleton a} (G∈ x∈Γ)
G∈ {Γ :: (x , _)} (inr idp) = ∈-∪₂ {A = varC Γ} {B = singleton x} (∈-singleton x)
private
every-term-has-variables : ∀ {Γ t A} → Γ ⊢t (Tm→Pre-Tm t) # A → Σ ℕ λ x → x ∈-set vart t
every-term-has-variables {Γ} {v x} {A} Γ⊢t = x , ∈-singleton x
every-term-has-variables {Γ} {coh (nil , (ps Δ⊢ps)) _ _ γ} {A} (tm _ Γ⊢γ idp) = ⊥-elim (∅-is-not-ps _ _ Δ⊢ps)
every-term-has-variables {Γ} {coh ((_ :: _) , Δ⊢ps) _ _ <>} {A} (tm _ () idp)
every-term-has-variables {Γ} {coh ((_ :: _) , Δ⊢ps) _ _ < γ , _ ↦ u >} {A} (tm _ (sc _ _ Γ⊢u _) idp) with every-term-has-variables Γ⊢u
... | (x , x∈) = x , ∈-∪₂ {A = varS γ} {B = vart u} x∈
side-cond₁-not𝔻0 : ∀ Γ Γ⊢ps A t → (GPre-Ctx Γ) ⊢t (Tm→Pre-Tm t) # (Ty→Pre-Ty A) → ((varT A) ∪-set (vart t)) ⊂ (src-var (Γ , Γ⊢ps)) → Γ ≠ (nil :: (0 , GSeTT.Syntax.∗))
side-cond₁-not𝔻0 .(nil :: (0 , GSeTT.Syntax.∗)) (ps pss) A t Γ⊢t incl idp with every-term-has-variables Γ⊢t | dec-≤ 0 0
... | x , x∈A | inl _ = incl _ (∈-∪₂ {A = varT A} {B = vart t} x∈A)
... | x , x∈A | inr _ = incl _ (∈-∪₂ {A = varT A} {B = vart t} x∈A)
side-cond₁-not𝔻0 .(nil :: (0 , GSeTT.Syntax.∗)) (ps (psd Γ⊢psf)) A t Γ⊢t incl idp = ⇒≠∗ (𝔻0-type _ _ (psvar Γ⊢psf))
max-srcᵢ-var-def : ∀ {Γ x A i} → (Γ⊢psx : Γ ⊢ps x # A) → 0 < i → ℕ × Pre-Ty
max-srcᵢ-var-def pss _ = 0 , ∗
max-srcᵢ-var-def (psd Γ⊢psx) 0<i = max-srcᵢ-var-def Γ⊢psx 0<i
max-srcᵢ-var-def {_} {x} {A} {i} (pse Γ⊢psx idp idp idp idp idp) 0<i with dec-≤ i (GSeTT.Syntax.dim A)
... | inl i≤dA = max-srcᵢ-var-def Γ⊢psx 0<i
... | inr dA<i with dec-≤ (GSeTT.Syntax.dim A) (dim (snd (max-srcᵢ-var-def Γ⊢psx 0<i)))
... | inl _ = max-srcᵢ-var-def Γ⊢psx 0<i
... | inr _ = x , GPre-Ty A
max-srcᵢ-var-∈ : ∀ {Γ x A i} → (Γ⊢psx : Γ ⊢ps x # A) → (0<i : 0 < i) → fst (max-srcᵢ-var-def Γ⊢psx 0<i) ∈-list (srcᵢ-var i Γ⊢psx)
max-srcᵢ-var-∈ pss 0<i = transport {B = 0 ∈-list_} (simplify-if 0<i ^) (inr idp)
max-srcᵢ-var-∈ (psd Γ⊢psx) 0<i = max-srcᵢ-var-∈ Γ⊢psx 0<i
max-srcᵢ-var-∈ {Γ} {x} {A} {i} (pse Γ⊢psx idp idp idp idp idp) 0<i with dec-≤ i (GSeTT.Syntax.dim A)
... | inl _ = max-srcᵢ-var-∈ Γ⊢psx 0<i
... | inr _ with dec-≤ (GSeTT.Syntax.dim A) (dim (snd (max-srcᵢ-var-def Γ⊢psx 0<i)))
... | inl _ = inl (inl (max-srcᵢ-var-∈ Γ⊢psx 0<i))
... | inr _ = inr idp
max-srcᵢ-var-⊢ : ∀ {Γ x A i} → (Γ⊢psx : Γ ⊢ps x # A) → (0<i : 0 < i) → GPre-Ctx Γ ⊢t Var (fst (max-srcᵢ-var-def Γ⊢psx 0<i)) # snd (max-srcᵢ-var-def Γ⊢psx 0<i)
max-srcᵢ-var-⊢ pss 0<i = var (cc ec (ob ec) idp) (inr (idp , idp))
max-srcᵢ-var-⊢ (psd Γ⊢psx) 0<i = max-srcᵢ-var-⊢ Γ⊢psx 0<i
max-srcᵢ-var-⊢ {Γ} {x} {A} {i} Γ+⊢ps@(pse Γ⊢psx idp idp idp idp idp) 0<i with dec-≤ i (GSeTT.Syntax.dim A)
... | inl _ = wkt (wkt (max-srcᵢ-var-⊢ Γ⊢psx 0<i) ((GCtx _ (GSeTT.Rules.Γ,x:A⊢→Γ⊢ (psv Γ+⊢ps))))) (GCtx _ (psv Γ+⊢ps))
... | inr _ with dec-≤ (GSeTT.Syntax.dim A) (dim (snd (max-srcᵢ-var-def Γ⊢psx 0<i)))
... | inl _ = wkt (wkt (max-srcᵢ-var-⊢ Γ⊢psx 0<i) ((GCtx _ (GSeTT.Rules.Γ,x:A⊢→Γ⊢ (psv Γ+⊢ps))))) (GCtx _ (psv Γ+⊢ps))
... | inr _ = var (GCtx _ (psv Γ+⊢ps)) (inr (idp , idp))
max-srcᵢ-var-dim : ∀ {Γ x A i} → (Γ⊢psx : Γ ⊢ps x # A) → (0<i : 0 < i) → min i (S (dimC (GPre-Ctx Γ))) == S (dim (snd (max-srcᵢ-var-def Γ⊢psx 0<i)))
max-srcᵢ-var-dim pss 0<i = simplify-min-r 0<i
max-srcᵢ-var-dim (psd Γ⊢psx) 0<i = max-srcᵢ-var-dim Γ⊢psx 0<i
max-srcᵢ-var-dim {Γ} {x} {A} {i} (pse {Γ = Δ} Γ⊢psx idp idp idp idp idp) 0<i with dec-≤ i (GSeTT.Syntax.dim A)
... | inl i≤dA = simplify-min-l (n≤m→n≤Sm (≤T (≤-= i≤dA (GdimT {A})) (m≤max (max (dimC (GPre-Ctx Δ)) _) (dim (GPre-Ty A))) )) >> (simplify-min-l (≤T i≤dA (≤-= (S≤ (dim-dangling Γ⊢psx)) (ap S (GdimC {Δ})))) ^) >> max-srcᵢ-var-dim Γ⊢psx 0<i
max-srcᵢ-var-dim {Γ} {x} {A} {i} (pse {Γ = Δ} Γ⊢psx idp idp idp idp idp) 0<i | inr dA<i with dec-≤ (GSeTT.Syntax.dim A) (dim (snd (max-srcᵢ-var-def Γ⊢psx 0<i)))
... | inl dA≤m = let dA<dΔ = (S≤S (≤T (=-≤-= (ap S (GdimT {A} ^)) (S≤ dA≤m) (max-srcᵢ-var-dim Γ⊢psx 0<i ^)) (min≤m i (S (dimC (GPre-Ctx Δ)))))) in
ap (min i)
(ap S (simplify-max-l {max (dimC (GPre-Ctx Δ)) _} {dim (GPre-Ty A)} (≤T dA<dΔ (n≤max _ _))
>> simplify-max-l {dimC (GPre-Ctx Δ)} {_} (Sn≤m→n≤m dA<dΔ)))
>> max-srcᵢ-var-dim Γ⊢psx 0<i
... | inr m<dA = simplify-min-r {i} {S (max (max (dimC (GPre-Ctx Δ)) _) (dim (GPre-Ty A)))}
(up-maxS {max (dimC (GPre-Ctx Δ)) _} {dim (GPre-Ty A)}
(up-maxS {dimC (GPre-Ctx Δ)} {_}
(min<l (=-≤ (ap S (max-srcᵢ-var-dim Γ⊢psx 0<i)) (≤T (S≤ (≰ m<dA)) (≰ dA<i))))
(=-≤ (GdimT {A} ^) (≤T (n≤Sn _) (≰ dA<i))))
(=-≤ (ap S (GdimT {A}) ^) (≰ dA<i)))
>> ap S (simplify-max-r {max (dimC (GPre-Ctx Δ)) _} {dim (GPre-Ty A)}
(up-max {dimC (GPre-Ctx Δ)} {_} (≤-= (Sn≤m→n≤m (greater-than-min-r (≰ dA<i) (=-≤ (max-srcᵢ-var-dim Γ⊢psx 0<i) (≰ m<dA)))) (ap S GdimT)) (n≤Sn _)))
max-srcᵢ-var : ∀ {Γ x A i} → (Γ⊢psx : Γ ⊢ps x # A) → 0 < i → Σ (Σ (ℕ × Pre-Ty) (λ {(x , B) → GPre-Ctx Γ ⊢t Var x # B})) (λ {((x , B) , Γ⊢x) → (x ∈-list (srcᵢ-var i Γ⊢psx)) × (min i (S (dimC (GPre-Ctx Γ))) == S (dim-tm Γ⊢x))})
max-srcᵢ-var Γ⊢psx 0<i = (max-srcᵢ-var-def Γ⊢psx 0<i , max-srcᵢ-var-⊢ Γ⊢psx 0<i) , (max-srcᵢ-var-∈ Γ⊢psx 0<i , max-srcᵢ-var-dim Γ⊢psx 0<i)
max-src-var : ∀ Γ → (Γ⊢ps : Γ ⊢ps) → (Γ ≠ (nil :: (0 , GSeTT.Syntax.∗))) → Σ (Σ (ℕ × Pre-Ty) (λ {(x , B) → GPre-Ctx Γ ⊢t Var x # B})) (λ {((x , B) , Γ⊢x) → (x ∈-set (src-var (Γ , Γ⊢ps))) × (dimC (GPre-Ctx Γ) == S (dim-tm Γ⊢x))})
max-src-var Γ Γ⊢ps@(ps Γ⊢psx) Γ≠𝔻0 with max-srcᵢ-var {i = GSeTT.Syntax.dimC Γ} Γ⊢psx (dim-ps-not-𝔻0 Γ⊢ps Γ≠𝔻0)
... | ((x , B) , (x∈ , p)) = (x , B) , (∈-list-∈-set _ _ x∈ , (ap (λ n → min n (S (dimC (GPre-Ctx Γ)))) (GdimC {Γ}) >> simplify-min-l (n≤Sn _) ^ >> p) )
full-term-have-max-variables : ∀ {Γ A Γ⊢ps} → GPre-Ctx Γ ⊢T (Ty→Pre-Ty A) → A is-full-in ((Γ , Γ⊢ps)) →
Σ (Σ (ℕ × Pre-Ty) (λ {(x , B) → GPre-Ctx Γ ⊢t Var x # B})) (λ {((x , B) , Γ⊢x) → (x ∈-set varT A) × (dimC (GPre-Ctx Γ) ≤ S (dim-tm Γ⊢x))})
full-term-have-max-variables {Γ} {_} {Γ⊢ps} Γ⊢A (side-cond₁ .(_ , _) A t u (incl , incl₂) _) with max-src-var Γ Γ⊢ps (side-cond₁-not𝔻0 _ Γ⊢ps A t (Γ⊢src Γ⊢A) incl₂)
... | ((x , B) , Γ⊢x) , (x∈src , dimΓ=Sdimx) = ((x , B) , Γ⊢x) , (A∪B⊂A∪B∪C (varT A) (vart t) (vart u) _ (incl _ x∈src) , transport {B = λ x → (dimC (GPre-Ctx Γ)) ≤ x} dimΓ=Sdimx (n≤n _))
full-term-have-max-variables {Γ} {_} {Γ⊢ps@(ps Γ⊢psx)} _ (side-cond₂ .(_ , _) _ (incl , _)) with max-var {Γ} Γ⊢ps
... | (x , B) , (x∈Γ , dimx) = ((x , (GPre-Ty B)) , var (GCtx Γ (psv Γ⊢psx)) (G#∈ x∈Γ)) , (incl _ (G∈ (x#A∈Γ→x∈Γ x∈Γ)) , ≤-= (=-≤ ((GdimC {Γ} ^) >> dimx) (n≤Sn _)) (ap S GdimT))
dim-∈-var : ∀ {Γ A x B} → Γ ⊢t Var x # B → Γ ⊢T (Ty→Pre-Ty A) → x ∈-set varT A → dim B < dim (Ty→Pre-Ty A)
dim-∈-var-t : ∀ {Γ t A x B} → Γ ⊢t Var x # B → Γ ⊢t (Tm→Pre-Tm t) # (Ty→Pre-Ty A) → x ∈-set vart t → dim B ≤ dim (Ty→Pre-Ty A)
dim-∈-var-S : ∀ {Δ γ Γ x B} → Δ ⊢t Var x # B → Δ ⊢S (Sub→Pre-Sub γ) > (GPre-Ctx Γ) → x ∈-set varS γ → dim B ≤ dimC (GPre-Ctx Γ)
dim-full-ty : ∀ {Γ A} → (Γ⊢ps : Γ ⊢ps) → (GPre-Ctx Γ) ⊢T (Ty→Pre-Ty A) → A is-full-in (Γ , Γ⊢ps) → dimC (GPre-Ctx Γ) ≤ dim (Ty→Pre-Ty A)
dim-∈-var {Γ} {A⇒@(⇒ A t u)} {x} {B} Γ⊢x (ar Γ⊢A Γ⊢t Γ⊢u) x∈A⇒ with ∈-∪ {varT A} {vart t ∪-set vart u} x∈A⇒
... | inl x∈A = n≤m→n≤Sm (dim-∈-var Γ⊢x Γ⊢A x∈A)
... | inr x∈t∪u with ∈-∪ {vart t} {vart u} x∈t∪u
... | inl x∈t = S≤ (dim-∈-var-t Γ⊢x Γ⊢t x∈t)
... | inr x∈u = S≤ (dim-∈-var-t Γ⊢x Γ⊢u x∈u)
dim-∈-var-t {t = v x} Γ⊢x Γ⊢t (inr idp) with unique-type Γ⊢x Γ⊢t (ap Var idp)
... | idp = n≤n _
dim-∈-var-t {t = coh Γ A Afull γ} Γ⊢x (tm Γ⊢A Δ⊢γ:Γ p) x∈t = ≤-= (≤T (dim-∈-var-S Γ⊢x Δ⊢γ:Γ x∈t) (dim-full-ty (snd Γ) Γ⊢A Afull) ) ((dim[] _ _ ^) >> ap dim (p ^))
dim-∈-var-S {Δ} {< γ , y ↦ t >} {Γ :: (_ , A)} {x} {B} Δ⊢x (sc Δ⊢γ:Γ Γ+⊢ Δ⊢t idp) x∈γ+ with ∈-∪ {varS γ} {vart t} x∈γ+
... | inl x∈γ = ≤T (dim-∈-var-S Δ⊢x Δ⊢γ:Γ x∈γ) (n≤max _ _)
... | inr x∈t = ≤T (dim-∈-var-t Δ⊢x (transport {B = Δ ⊢t (Tm→Pre-Tm t) #_} Ty→Pre-Ty[] Δ⊢t) x∈t) (=-≤ (dim-Pre-Ty[]) (m≤max (dimC (GPre-Ctx Γ)) (dim (GPre-Ty A))))
dim-full-ty Γ⊢ps Γ⊢A Afull with full-term-have-max-variables Γ⊢A Afull
... | ((x , B) , Γ⊢x) , (x∈A , dimx) = ≤T dimx (dim-∈-var Γ⊢x Γ⊢A x∈A)
well-foundedness : well-founded
well-foundedness ((Γ , A) , Afull) Γ⊢A with full-term-have-max-variables Γ⊢A Afull
... |((x , B) , Γ⊢x) , (x∈Γ , dimΓ≤Sdimx) = ≤T dimΓ≤Sdimx (dim-∈-var Γ⊢x Γ⊢A x∈Γ)
open import Globular-TT.Dec-Type-Checking J rule well-foundedness eqdecJ
| {
"alphanum_fraction": 0.4946873226,
"avg_line_length": 61.0346534653,
"ext": "agda",
"hexsha": "61aa703892d579a579f1290039d7a26212d695c7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thibautbenjamin/catt-formalization",
"max_forks_repo_path": "CaTT/CaTT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thibautbenjamin/catt-formalization",
"max_issues_repo_path": "CaTT/CaTT.agda",
"max_line_length": 241,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thibautbenjamin/catt-formalization",
"max_stars_repo_path": "CaTT/CaTT.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6516,
"size": 12329
} |
module Issue1494 where
open import Issue1494.Helper
module M (r : Record) where
open Module r
postulate
A : Set
a b : A
Foo : a ≡ b
Foo = {!!}
| {
"alphanum_fraction": 0.5963855422,
"avg_line_length": 11.0666666667,
"ext": "agda",
"hexsha": "c7df4364a4b6c05e60b5c8c094f9b099d0dc8521",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue1494.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue1494.agda",
"max_line_length": 28,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue1494.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 56,
"size": 166
} |
{-# OPTIONS --without-K #-}
open import M-types.Base.Core
module M-types.Base.Sum where
infixr 4 _,_
record ∑ (X : Ty ℓ₀) (Y : X → Ty ℓ₁) : Ty (ℓ-max ℓ₀ ℓ₁) where
constructor _,_
field
pr₀ : X
pr₁ : Y pr₀
open ∑ public
{-# BUILTIN SIGMA ∑ #-}
∑-syntax : (X : Ty ℓ₀) → (Y : X → Ty ℓ₁) → Ty (ℓ-max ℓ₀ ℓ₁)
∑-syntax = ∑
infix 2 ∑-syntax
syntax ∑-syntax X (λ x → Y) = ∑[ x ∈ X ] Y
infixr 2 _×_
_×_ : (X : Ty ℓ₀) → (Y : Ty ℓ₁) → Ty (ℓ-max ℓ₀ ℓ₁)
X × Y = ∑[ x ∈ X ] Y
ty = pr₀
fun = pr₀
| {
"alphanum_fraction": 0.4562607204,
"avg_line_length": 18.8064516129,
"ext": "agda",
"hexsha": "7bb485c933109d14718ee90351f33df054fedee1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DDOtten/M-types",
"max_forks_repo_path": "Base/Sum.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DDOtten/M-types",
"max_issues_repo_path": "Base/Sum.agda",
"max_line_length": 65,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DDOtten/M-types",
"max_stars_repo_path": "Base/Sum.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 252,
"size": 583
} |
module WellTypedTerms where
open import Library
open import Categories
open import Functors
open import RMonads
open import FunctorCat
open import Categories.Sets
open import Categories.Families
data Ty : Set where
ι : Ty
_⇒_ : Ty → Ty → Ty
data Con : Set where
ε : Con
_<_ : Con → Ty → Con
data Var : Con → Ty → Set where
vz : ∀{Γ σ} → Var (Γ < σ) σ
vs : ∀{Γ σ τ} → Var Γ σ → Var (Γ < τ) σ
data Tm : Con → Ty → Set where
var : ∀{Γ σ} → Var Γ σ → Tm Γ σ
app : ∀{Γ σ τ} → Tm Γ (σ ⇒ τ) → Tm Γ σ → Tm Γ τ
lam : ∀{Γ σ τ} → Tm (Γ < σ) τ → Tm Γ (σ ⇒ τ)
Ren : Con → Con → Set
Ren Γ Δ = ∀ {σ} → Var Γ σ → Var Δ σ
renId : ∀{Γ} → Ren Γ Γ
renId = id
renComp : ∀{B Γ Δ} → Ren Γ Δ → Ren B Γ → Ren B Δ
renComp f g = f ∘ g
ConCat : Cat
ConCat = record{
Obj = Con;
Hom = Ren;
iden = renId;
comp = renComp;
idl = iext λ _ → refl;
idr = iext λ _ → refl;
ass = iext λ _ → refl}
wk : ∀{Γ Δ σ} → Ren Γ Δ → Ren (Γ < σ) (Δ < σ)
wk f vz = vz
wk f (vs i) = vs (f i)
ren : ∀{Γ Δ} → Ren Γ Δ → ∀ {σ} → Tm Γ σ → Tm Δ σ
ren f (var x) = var (f x)
ren f (app t u) = app (ren f t) (ren f u)
ren f (lam t) = lam (ren (wk f) t)
wkid : ∀{Γ σ τ}(x : Var (Γ < τ) σ) → wk renId x ≅ renId x
wkid vz = refl
wkid (vs x) = refl
renid : ∀{Γ σ}(t : Tm Γ σ) → ren renId t ≅ id t
renid (var x) = refl
renid (app t u) =
proof
app (ren renId t) (ren renId u)
≅⟨ cong₂ app (renid t) (renid u) ⟩
app t u
∎
renid (lam t) =
proof lam (ren (wk renId) t)
≅⟨ cong (λ (f : Ren _ _) → lam (ren f t)) (iext λ _ → ext wkid) ⟩
lam (ren renId t)
≅⟨ cong lam (renid t) ⟩
lam t
∎
wkcomp : ∀ {B Γ Δ}(f : Ren Γ Δ)(g : Ren B Γ){σ τ}(x : Var (B < σ) τ) →
wk (renComp f g) x ≅ renComp (wk f) (wk g) x
wkcomp f g vz = refl
wkcomp f g (vs i) = refl
rencomp : ∀ {B Γ Δ}(f : Ren Γ Δ)(g : Ren B Γ){σ}(t : Tm B σ) →
ren (renComp f g) t ≅ (ren f ∘ ren g) t
rencomp f g (var x) = refl
rencomp f g (app t u) =
proof
app (ren (renComp f g) t) (ren (renComp f g) u)
≅⟨ cong₂ app (rencomp f g t) (rencomp f g u) ⟩
app (ren f (ren g t)) (ren f (ren g u))
∎
rencomp f g (lam t) =
proof
lam (ren (wk (renComp f g)) t)
≅⟨ cong (λ (f : Ren _ _) → lam (ren f t)) (iext λ _ → ext (wkcomp f g)) ⟩
lam (ren (renComp (wk f) (wk g)) t)
≅⟨ cong lam (rencomp (wk f) (wk g) t) ⟩
lam (ren (wk f) (ren (wk g) t))
∎
Sub : Con → Con → Set
Sub Γ Δ = ∀{σ} → Var Γ σ → Tm Δ σ
lift : ∀{Γ Δ σ} → Sub Γ Δ → Sub (Γ < σ) (Δ < σ)
lift f vz = var vz
lift f (vs x) = ren vs (f x)
sub : ∀{Γ Δ} → Sub Γ Δ → ∀{σ} → Tm Γ σ → Tm Δ σ
sub f (var x) = f x
sub f (app t u) = app (sub f t) (sub f u)
sub f (lam t) = lam (sub (lift f) t)
subId : ∀{Γ} → Sub Γ Γ
subId = var
subComp : ∀{B Γ Δ} → Sub Γ Δ → Sub B Γ → Sub B Δ
subComp f g = sub f ∘ g
liftid : ∀{Γ σ τ}(x : Var (Γ < σ) τ) → lift subId x ≅ subId x
liftid vz = refl
liftid (vs x) = refl
subid : ∀{Γ σ}(t : Tm Γ σ) → sub subId t ≅ id t
subid (var x) = refl
subid (app t u) =
proof
app (sub subId t) (sub subId u)
≅⟨ cong₂ app (subid t) (subid u) ⟩
app t u
∎
subid (lam t) =
proof
lam (sub (lift subId) t)
≅⟨ cong (λ (f : Sub _ _) → lam (sub f t)) (iext λ _ → ext liftid) ⟩
lam (sub subId t)
≅⟨ cong lam (subid t) ⟩
lam t
∎
-- time for the mysterious four lemmas:
liftwk : ∀{B Γ Δ}(f : Sub Γ Δ)(g : Ren B Γ){σ τ}(x : Var (B < σ) τ) →
(lift f ∘ wk g) x ≅ lift (f ∘ g) x
liftwk f g vz = refl
liftwk f g (vs x) = refl
subren : ∀{B Γ Δ}(f : Sub Γ Δ)(g : Ren B Γ){σ}(t : Tm B σ) →
(sub f ∘ ren g) t ≅ sub (f ∘ g) t
subren f g (var x) = refl
subren f g (app t u) =
proof
app (sub f (ren g t)) (sub f (ren g u))
≅⟨ cong₂ app (subren f g t) (subren f g u) ⟩
app (sub (f ∘ g) t) (sub (f ∘ g) u)
∎
subren f g (lam t) =
proof
lam (sub (lift f) (ren (wk g) t))
≅⟨ cong lam (subren (lift f) (wk g) t) ⟩
lam (sub (lift f ∘ wk g) t)
≅⟨ cong (λ (f : Sub _ _) → lam (sub f t)) (iext (λ _ → ext (liftwk f g))) ⟩
lam (sub (lift (f ∘ g)) t) ∎
renwklift : ∀{B Γ Δ}(f : Ren Γ Δ)(g : Sub B Γ){σ τ}(x : Var (B < σ) τ) →
(ren (wk f) ∘ lift g) x ≅ lift (ren f ∘ g) x
renwklift f g vz = refl
renwklift f g (vs x) =
proof
ren (wk f) (ren vs (g x))
≅⟨ sym (rencomp (wk f) vs (g x)) ⟩
ren (wk f ∘ vs) (g x)
≅⟨ rencomp vs f (g x) ⟩
ren vs (ren f (g x))
∎
rensub : ∀{B Γ Δ}(f : Ren Γ Δ)(g : Sub B Γ){σ}(t : Tm B σ) →
(ren f ∘ sub g) t ≅ sub (ren f ∘ g) t
rensub f g (var x) = refl
rensub f g (app t u) =
proof
app (ren f (sub g t)) (ren f (sub g u))
≅⟨ cong₂ app (rensub f g t) (rensub f g u) ⟩
app (sub (ren f ∘ g) t) (sub (ren f ∘ g) u)
∎
rensub f g (lam t) =
proof
lam (ren (wk f) (sub (lift g) t))
≅⟨ cong lam (rensub (wk f) (lift g) t) ⟩
lam (sub (ren (wk f) ∘ lift g) t)
≅⟨ cong (λ (f₁ : Sub _ _) → lam (sub f₁ t))
(iext (λ _ → ext (renwklift f g))) ⟩
lam (sub (lift (ren f ∘ g)) t)
∎
liftcomp : ∀{B Γ Δ}(f : Sub Γ Δ)(g : Sub B Γ){σ τ}(x : Var (B < σ) τ) →
lift (subComp f g) x ≅ subComp (lift f) (lift g) x
liftcomp f g vz = refl
liftcomp f g (vs x) =
proof
ren vs (sub f (g x))
≅⟨ rensub vs f (g x) ⟩
sub (ren vs ∘ f) (g x)
≅⟨ sym (subren (lift f) vs (g x)) ⟩
sub (lift f) (ren vs (g x))
∎
subcomp : ∀{B Γ Δ}(f : Sub Γ Δ)(g : Sub B Γ){σ}(t : Tm B σ) →
sub (subComp f g) t ≅ (sub f ∘ sub g) t
subcomp f g (var x) = refl
subcomp f g (app t u) =
proof
app (sub (subComp f g) t) (sub (subComp f g) u)
≅⟨ cong₂ app (subcomp f g t) (subcomp f g u) ⟩
app (sub f (sub g t)) (sub f (sub g u))
∎
subcomp f g (lam t) =
proof
lam (sub (lift (subComp f g)) t)
≅⟨ cong (λ (f : Sub _ _) → lam (sub f t))
(iext λ _ → ext (liftcomp f g)) ⟩
lam (sub (subComp (lift f) (lift g)) t)
≅⟨ cong lam (subcomp (lift f) (lift g) t) ⟩
lam (sub (lift f) (sub (lift g) t)) ∎
VarF : Fun ConCat (Fam Ty)
VarF = record {
OMap = Var;
HMap = id;
fid = refl;
fcomp = refl }
TmRMonad : RMonad VarF
TmRMonad = record {
T = Tm;
η = var;
bind = sub;
law1 = iext λ _ → ext subid ;
law2 = refl;
law3 = λ{_ _ _ f g} → iext λ σ → ext (subcomp g f)}
-- not needed here
sub<< : ∀{Γ Δ σ}(f : Sub Γ Δ)(t : Tm Δ σ) → Sub (Γ < σ) Δ
sub<< f t vz = t
sub<< f t (vs x) = f x
lem1 : ∀{B Γ Δ σ}{f : Sub Γ Δ}{g : Ren B Γ}{t : Tm Δ σ}{τ}(x : Var (B < σ) τ) →
(sub<< f t ∘ wk g) x ≅ (sub<< (f ∘ g) t) x
lem1 vz = refl
lem1 (vs x) = refl
lem2 : ∀{B Γ Δ σ}{f : Sub Γ Δ}{g : Sub B Γ}{t : Tm Δ σ}{τ}(x : Var (B < σ) τ) →
(subComp (sub<< f t) (lift g)) x ≅ (sub<< (subComp f g) t) x
lem2 vz = refl
lem2 {f = f}{g = g}{t = t} (vs x) = subren (sub<< f t) vs (g x)
| {
"alphanum_fraction": 0.4931972789,
"avg_line_length": 26.8333333333,
"ext": "agda",
"hexsha": "a98c591d74763c3fa6320f1d975b8846419e15d5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "WellTypedTerms.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "WellTypedTerms.agda",
"max_line_length": 80,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "WellTypedTerms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 3149,
"size": 6762
} |
module Ag04 where
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
infix 4 _≡_
≡-sym : ∀ {A : Set} {x y : A} → x ≡ y → y ≡ x
≡-sym refl = refl
trans : ∀ {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
cong : ∀ {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y
cong f refl = refl
cong₂ : ∀ {A B C : Set} (f : A → B → C) {u x : A} {v y : B}
→ u ≡ x → v ≡ y → f u v ≡ f x y
cong₂ f refl refl = refl
cong-app : ∀ {A B : Set} {f g : A → B} → f ≡ g → ∀ (x : A) → f x ≡ g x
cong-app refl x = refl
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
_+_ : ℕ → ℕ → ℕ
zero + m = m
(suc n) + m = suc (n + m)
postulate
+-identity : ∀ (m : ℕ) → m + zero ≡ m
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-comm : ∀ (m n : ℕ) → m + n ≡ n + m
_≐_ : ∀ {A : Set} (x y : A) → Set₁
_≐_ {A} x y = ∀ (P : A → Set) → P x → P y
refl-≐ : ∀ {A : Set} {x : A} → x ≐ x
refl-≐ P Px = Px
trans-≐ : ∀ {A : Set} {x y z : A} → x ≐ y → y ≐ z → x ≐ z
trans-≐ x≐y y≐z P Px = y≐z P (x≐y P Px)
sym-≐ : ∀ {A : Set} {x y : A} → x ≐ y → y ≐ x
sym-≐ {A} {x} {y} x≐y P = Qy
where
Q : A → Set
Q z = P z → P x
Qx : Q x
Qx = refl-≐ P
Qy : Q y
Qy = x≐y Q Qx
subst : ∀ {A : Set} {x y : A} (P : A → Set)
→ x ≡ y
---------
→ P x → P y
subst P refl px = px
≡-implies-≐ : ∀ {A : Set} {x y : A} → x ≡ y → x ≐ y
≡-implies-≐ x≡y P = subst P x≡y
≐-implies-≡ : ∀ {A : Set} {x y : A} → x ≐ y → x ≡ y
≐-implies-≡ {A} {x} {y} x≐y = Qy
where
Q : A → Set
Q z = x ≡ z
Qx : Q x
Qx = refl
Qy : Q y
Qy = x≐y Q Qx
open import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc)
data _≡'_ {ℓ : Level} {A : Set ℓ} (x : A) : A → Set ℓ where
refl' : x ≡' x
| {
"alphanum_fraction": 0.4139941691,
"avg_line_length": 21.1728395062,
"ext": "agda",
"hexsha": "671283ba42c7038557fc1ec8d9ad35a24adb4aad",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Brethland/LEARNING-STUFF",
"max_forks_repo_path": "Agda/Ag04.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Brethland/LEARNING-STUFF",
"max_issues_repo_path": "Agda/Ag04.agda",
"max_line_length": 74,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Brethland/LEARNING-STUFF",
"max_stars_repo_path": "Agda/Ag04.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z",
"num_tokens": 900,
"size": 1715
} |
------------------------------------------------------------------------------
-- Definition of FOTC Conat using Agda's co-inductive combinators
------------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Data.Conat.TypeSL where
open import Codata.Musical.Notation
open import FOTC.Base
------------------------------------------------------------------------------
data Conat : D → Set where
cozero : Conat zero
cosucc : ∀ {n} → ∞ (Conat n) → Conat (succ₁ n)
Conat-out : ∀ {n} → Conat n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ Conat n')
Conat-out cozero = inj₁ refl
Conat-out (cosucc {n} Cn) = inj₂ (n , refl , ♭ Cn)
Conat-in : ∀ {n} →
n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ Conat n') →
Conat n
Conat-in (inj₁ n≡0) = subst Conat (sym n≡0) cozero
Conat-in (inj₂ (n' , prf , Cn')) = subst Conat (sym prf) (cosucc (♯ Cn'))
-- TODO (2019-01-04): Agda doesn't accept this definition which was
-- accepted by a previous version.
{-# TERMINATING #-}
Conat-coind : (A : D → Set) →
(∀ {n} → A n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ A n')) →
∀ {n} → A n → Conat n
Conat-coind A h An with h An
... | inj₁ refl = cozero
... | inj₂ (n' , refl , An') = cosucc (♯ (Conat-coind A h An'))
-- TODO (07 January 2014): We couldn't prove Conat-stronger-coind.
Conat-stronger-coind :
∀ (A : D → Set) {n} →
(A n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ A n')) →
A n → Conat n
Conat-stronger-coind A h An with h An
... | inj₁ n≡0 = subst Conat (sym n≡0) cozero
... | inj₂ (n' , prf , An') =
subst Conat (sym prf) (cosucc (♯ (Conat-coind A {!!} An')))
postulate
∞D : D
∞-eq : ∞D ≡ succ₁ ∞D
-- TODO (06 January 2014): Agda doesn't accept the proof of Conat ∞D.
{-# TERMINATING #-}
∞-Conat : Conat ∞D
∞-Conat = subst Conat (sym ∞-eq) (cosucc (♯ ∞-Conat))
| {
"alphanum_fraction": 0.4855072464,
"avg_line_length": 34.5,
"ext": "agda",
"hexsha": "93424e880b9f1c1a3c0a31b35c99eed7b23ac696",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Data/Conat/TypeSL.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Data/Conat/TypeSL.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Data/Conat/TypeSL.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 704,
"size": 2070
} |
module DuplicateBuiltinBinding where
{-# BUILTIN STRING String #-}
{-# BUILTIN STRING String #-}
| {
"alphanum_fraction": 0.7272727273,
"avg_line_length": 16.5,
"ext": "agda",
"hexsha": "c17854556ffc704f5bbb17d989f18483e6d6dbeb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/DuplicateBuiltinBinding.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/DuplicateBuiltinBinding.agda",
"max_line_length": 36,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/DuplicateBuiltinBinding.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-07T10:49:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-07T10:49:57.000Z",
"num_tokens": 19,
"size": 99
} |
data Nat : Set where
succ : Nat → Nat
data Fin : Nat → Set where
zero : (n : Nat) → Fin (succ n)
data Tm (n : Nat) : Set where
var : Fin n → Tm n
piv : Fin (succ n) → Tm n
data Cx : Nat → Set where
succ : (n : Nat) → Tm n → Cx (succ n)
data CxChk : ∀ n → Cx n → Set where
succ : (n : Nat) (T : Tm n) → CxChk (succ n) (succ n T)
data TmChk (n : Nat) : Cx n → Tm n → Set where
vtyp : (g : Cx n) (v : Fin n) → CxChk n g → TmChk n g (var v)
error : ∀ n g s → TmChk n g s → Set
error n g s (vtyp g' (zero x) (succ n' (piv (zero y)))) = Nat -- Internal error here.
error _ _ _ (vtyp g' (zero n) (succ n (var x))) = Nat -- This clause added to pass 2.5.3.
| {
"alphanum_fraction": 0.5469448584,
"avg_line_length": 27.9583333333,
"ext": "agda",
"hexsha": "0106b41326f39ad5a47b8f6d4322f4ac6c43b424",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "6dd1d63a927442aac42ef299f15054dd944d7fa9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Forty-Bot/agda",
"max_forks_repo_path": "test/Succeed/Issue3544.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6dd1d63a927442aac42ef299f15054dd944d7fa9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "Forty-Bot/agda",
"max_issues_repo_path": "test/Succeed/Issue3544.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6dd1d63a927442aac42ef299f15054dd944d7fa9",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Forty-Bot/agda",
"max_stars_repo_path": "test/Succeed/Issue3544.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 285,
"size": 671
} |
module Common.Coinduction where
open import Common.Level
infix 1000 ♯_
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
private
my-♯ : ∀ {a} {A : Set a} → A → ∞ A
my-♯ x = ♯ x
| {
"alphanum_fraction": 0.4640718563,
"avg_line_length": 16.7,
"ext": "agda",
"hexsha": "36d44bc9addbd662f4bc0d951e44b84078e4fcfc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/Common/Coinduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/Common/Coinduction.agda",
"max_line_length": 36,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/Common/Coinduction.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 151,
"size": 334
} |
{-# OPTIONS --without-K #-}
open import HoTT
module cw.Attached {i j k : ULevel} where
-- The type of attaching maps.
-- In intended uses, [B] is the type of cells and [C] is the [Sphere]s.
Attaching : (A : Type i) (B : Type j) (C : Type k) → Type (lmax i (lmax j k))
Attaching A B C = B → C → A
module _ {A : Type i} {B : Type j} {C : Type k} where
-- [Attached] is the type with all the cells attached.
Attached-span : Attaching A B C → Span {i} {j} {lmax j k}
Attached-span attaching = span A B (B × C) (uncurry attaching) fst
Attached : Attaching A B C → Type (lmax i (lmax j k))
Attached attaching = Pushout (Attached-span attaching)
module _ {A : Type i} {B : Type j} {C : Type k} {attaching : Attaching A B C} where
incl : A → Attached attaching
incl = left
hub : B → Attached attaching
hub = right
spoke : ∀ b c → incl (attaching b c) == hub b
spoke = curry glue
module AttachedElim {l} {P : Attached attaching → Type l}
(incl* : (a : A) → P (incl a))
(hub* : (b : B) → P (hub b))
(spoke* : (b : B) (c : C)
→ incl* (attaching b c) == hub* b [ P ↓ spoke b c ]) where
module P = PushoutElim
{d = Attached-span attaching} {P = P}
incl* hub* (uncurry spoke*)
f = P.f
spoke-β = curry P.glue-β
open AttachedElim public using () renaming (f to Attached-elim)
module AttachedRec {l} {D : Type l}
(incl* : (a : A) → D)
(hub* : (b : B) → D)
(spoke* : (b : B) (c : C) → incl* (attaching b c) == hub* b) where
module P = PushoutRec
{d = Attached-span attaching} {D = D}
incl* hub* (uncurry spoke*)
f = P.f
spoke-β = curry P.glue-β
open AttachedRec public using () renaming (f to Attached-rec)
| {
"alphanum_fraction": 0.5841584158,
"avg_line_length": 27.6935483871,
"ext": "agda",
"hexsha": "474382160fe56d2d606fb5323f84e0c1349a7388",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/Attached.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/Attached.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/Attached.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 578,
"size": 1717
} |
module Tactic.Nat.Subtract.By where
open import Prelude hiding (abs)
open import Builtin.Reflection
open import Tactic.Reflection.Quote
open import Tactic.Reflection.DeBruijn
open import Tactic.Reflection.Substitute
open import Tactic.Reflection
open import Control.Monad.State
open import Tactic.Nat.Reflect
open import Tactic.Nat.NF
open import Tactic.Nat.Exp
open import Tactic.Nat.Auto
open import Tactic.Nat.Auto.Lemmas
open import Tactic.Nat.Simpl.Lemmas
open import Tactic.Nat.Simpl
open import Tactic.Nat.Refute
open import Tactic.Nat.Reflect
open import Tactic.Nat.Subtract.Exp
open import Tactic.Nat.Subtract.Reflect
open import Tactic.Nat.Subtract.Lemmas
open import Tactic.Nat.Less.Lemmas
private
NFGoal : (R₁ R₂ : Nat → Nat → Set) (a b c d : SubNF) → Env Var → Set
NFGoal _R₁_ _R₂_ a b c d ρ = ⟦ a ⟧ns (atomEnvS ρ) R₁ ⟦ b ⟧ns (atomEnvS ρ) → ⟦ c ⟧ns (atomEnvS ρ) R₂ ⟦ d ⟧ns (atomEnvS ρ)
follows-diff-prf : {a b c d : Nat} → a ≤ b → b < c → c ≤ d → d ≡ suc (d - suc a) + a
follows-diff-prf {a} (diff! i) (diff! j) (diff! k) =
sym $ (λ z → suc z + a) $≡ lem-sub-zero (k + suc (j + (i + a))) (suc a) (i + j + k) auto ʳ⟨≡⟩
auto
decide-leq : ∀ u v ρ → Maybe (⟦ u ⟧ns (atomEnvS ρ) ≤ ⟦ v ⟧ns (atomEnvS ρ))
decide-leq u v ρ with cancel u v | λ a b → cancel-sound-s′ a b u v (atomEnvS ρ)
... | [] , d | sound =
let eval x = ⟦ x ⟧ns (atomEnvS ρ) in
just (diff (eval d) $ sym (sound (suc (eval d)) 1 auto))
... | _ , _ | _ = nothing
by-proof-less-nf : ∀ u u₁ v v₁ ρ → Maybe (NFGoal _<_ _<_ u u₁ v v₁ ρ)
by-proof-less-nf u u₁ v v₁ ρ = do
v≤u ← decide-leq v u ρ
u₁≤v₁ ← decide-leq u₁ v₁ ρ
pure λ u<u₁ →
diff (⟦ v₁ ⟧ns (atomEnvS ρ) - suc (⟦ v ⟧ns (atomEnvS ρ)))
(follows-diff-prf v≤u u<u₁ u₁≤v₁)
by-proof-less : ∀ a a₁ b b₁ ρ → Maybe (SubExpLess a a₁ ρ → SubExpLess b b₁ ρ)
by-proof-less a a₁ b b₁ ρ with cancel (normSub a) (normSub a₁)
| cancel (normSub b) (normSub b₁)
| complicateSubLess a a₁ ρ
| simplifySubLess b b₁ ρ
... | u , u₁ | v , v₁ | compl | simpl = do
prf ← by-proof-less-nf u u₁ v v₁ ρ
pure (simpl ∘ prf ∘ compl)
lem-plus-zero-r : (a b : Nat) → a + b ≡ 0 → b ≡ 0
lem-plus-zero-r zero b eq = eq
lem-plus-zero-r (suc a) b ()
lem-leq-zero : {a b : Nat} → a ≤ b → b ≡ 0 → a ≡ 0
lem-leq-zero (diff k eq) refl = lem-plus-zero-r k _ (follows-from (sym eq))
⟨+⟩-sound-ns : ∀ {Atom} {{_ : Ord Atom}} u v (ρ : Env Atom) → ⟦ u +nf v ⟧ns ρ ≡ ⟦ u ⟧ns ρ + ⟦ v ⟧ns ρ
⟨+⟩-sound-ns u v ρ =
ns-sound (u +nf v) ρ ⟨≡⟩
⟨+⟩-sound u v ρ ⟨≡⟩ʳ
_+_ $≡ ns-sound u ρ *≡ ns-sound v ρ
by-proof-eq-nf : Nat → ∀ u u₁ v v₁ ρ → Maybe (NFGoal _≡_ _≡_ u u₁ v v₁ ρ)
by-proof-eq-sub : Nat → ∀ u u₁ v v₁ v₂ ρ → Maybe (NFGoal _≡_ _≡_ u u₁ [ 1 , [ v ⟨-⟩ v₁ ] ] v₂ ρ)
by-proof-eq-sub n u u₁ v v₁ v₂ ρ = do
let eval x = ⟦ x ⟧ns (atomEnvS ρ)
evals x = ⟦ x ⟧sns ρ
prf ← by-proof-eq-nf n u u₁ v (v₁ +nf v₂) ρ
pure (λ u=u₁ →
sym $ lem-sub-zero (evals v) (evals v₁) (eval v₂) $ sym $
lem-eval-sns-ns v ρ ⟨≡⟩
prf u=u₁ ⟨≡⟩
⟨+⟩-sound-ns v₁ v₂ (atomEnvS ρ) ⟨≡⟩ʳ
(_+ eval v₂) $≡ (lem-eval-sns-ns v₁ ρ))
by-proof-eq-sub₂ : Nat → ∀ u u₁ v v₁ v₂ v₃ ρ → Maybe (NFGoal _≡_ _≡_ u u₁ [ 1 , [ v ⟨-⟩ v₁ ] ] [ 1 , [ v₂ ⟨-⟩ v₃ ] ] ρ)
by-proof-eq-sub₂ n u u₁ v v₁ v₂ v₃ ρ = do
let eval x = ⟦ x ⟧ns (atomEnvS ρ)
evals x = ⟦ x ⟧sns ρ
prf ← by-proof-eq-nf n u u₁ (v₃ +nf v) (v₂ +nf v₁) ρ
pure λ u=u₁ →
lem-sub (evals v₂) (evals v₃) (evals v) (evals v₁) $
_+_ $≡ lem-eval-sns-ns v₃ ρ *≡ lem-eval-sns-ns v ρ ⟨≡⟩
⟨+⟩-sound-ns v₃ v (atomEnvS ρ) ʳ⟨≡⟩
prf u=u₁ ⟨≡⟩ ⟨+⟩-sound-ns v₂ v₁ (atomEnvS ρ) ⟨≡⟩ʳ
_+_ $≡ lem-eval-sns-ns v₂ ρ *≡ lem-eval-sns-ns v₁ ρ
-- More advanced tactics for equalities
-- a + b ≡ 0 → a ≡ 0
by-proof-eq-adv : Nat → ∀ u u₁ v v₁ ρ → Maybe (NFGoal _≡_ _≡_ u u₁ v v₁ ρ)
by-proof-eq-adv _ u [] v [] ρ = do leq ← decide-leq v u ρ; pure (lem-leq-zero leq)
by-proof-eq-adv _ [] u₁ v [] ρ = do leq ← decide-leq v u₁ ρ; pure (lem-leq-zero leq ∘ sym)
by-proof-eq-adv _ u [] [] v₁ ρ = do leq ← decide-leq v₁ u ρ; pure (sym ∘ lem-leq-zero leq)
by-proof-eq-adv _ [] u₁ [] v₁ ρ = do leq ← decide-leq v₁ u₁ ρ; pure (sym ∘ lem-leq-zero leq ∘ sym)
by-proof-eq-adv (suc n) u u₁ [ 1 , [ v ⟨-⟩ v₁ ] ] [ 1 , [ v₂ ⟨-⟩ v₃ ] ] ρ = by-proof-eq-sub₂ n u u₁ v v₁ v₂ v₃ ρ
by-proof-eq-adv n u u₁ [ 1 , [ v ⟨-⟩ v₁ ] ] v₂ ρ = by-proof-eq-sub n u u₁ v v₁ v₂ ρ
by-proof-eq-adv (suc n) u u₁ v₂ [ 1 , [ v ⟨-⟩ v₁ ] ] ρ = do
prf ← by-proof-eq-sub n u u₁ v v₁ v₂ ρ
pure (sym ∘ prf)
by-proof-eq-adv _ u u₁ v v₁ ρ = nothing
by-proof-eq-nf n u u₁ v v₁ ρ with u == v | u₁ == v₁
by-proof-eq-nf n u u₁ .u .u₁ ρ | yes refl | yes refl = just id
... | _ | _ with u == v₁ | u₁ == v -- try sym
by-proof-eq-nf n u u₁ .u₁ .u ρ | _ | _ | yes refl | yes refl = just sym
... | _ | _ = by-proof-eq-adv n u u₁ v v₁ ρ -- try advanced stuff
by-proof-eq : ∀ a a₁ b b₁ ρ → Maybe (SubExpEq a a₁ ρ → SubExpEq b b₁ ρ)
by-proof-eq a a₁ b b₁ ρ with cancel (normSub a) (normSub a₁)
| cancel (normSub b) (normSub b₁)
| complicateSubEq a a₁ ρ
| simplifySubEq b b₁ ρ
... | u , u₁ | v , v₁ | compl | simpl = do
prf ← by-proof-eq-nf 10 u u₁ v v₁ ρ
pure (simpl ∘ prf ∘ compl)
not-less-zero′ : {n : Nat} → n < 0 → ⊥
not-less-zero′ (diff _ ())
not-less-zero : {A : Set} {n : Nat} → n < 0 → A
not-less-zero n<0 = ⊥-elim (erase-⊥ (not-less-zero′ n<0))
less-one-is-zero : {n : Nat} → n < 1 → n ≡ 0
less-one-is-zero {zero} _ = refl
less-one-is-zero {suc n} (diff k eq) = refute eq
by-proof-less-eq-nf : ∀ u u₁ v v₁ ρ → Maybe (NFGoal _<_ _≡_ u u₁ v v₁ ρ)
by-proof-less-eq-nf u [] v v₁ ρ = just not-less-zero -- could've used refute, but we'll take it
by-proof-less-eq-nf u [ 1 , [] ] v v₁ ρ = do
prf ← by-proof-eq-nf 10 u [] v v₁ ρ
pure (prf ∘ less-one-is-zero)
by-proof-less-eq-nf u u₁ v v₁ ρ = nothing
by-proof-less-eq : ∀ a a₁ b b₁ ρ → Maybe (SubExpLess a a₁ ρ → SubExpEq b b₁ ρ)
by-proof-less-eq a a₁ b b₁ ρ with cancel (normSub a) (normSub a₁)
| cancel (normSub b) (normSub b₁)
| complicateSubLess a a₁ ρ
| simplifySubEq b b₁ ρ
... | u , u₁ | v , v₁ | compl | simpl = do
prf ← by-proof-less-eq-nf u u₁ v v₁ ρ
pure (simpl ∘ prf ∘ compl)
by-proof : ∀ hyp goal ρ → Maybe (⟦ hyp ⟧eqn ρ → ⟦ goal ⟧eqn ρ)
by-proof (a :≡ a₁) (b :≡ b₁) ρ = by-proof-eq a a₁ b b₁ ρ
by-proof (a :< a₁) (b :≡ b₁) ρ = by-proof-less-eq a a₁ b b₁ ρ
by-proof (a :< a₁) (b :< b₁) ρ = by-proof-less a a₁ b b₁ ρ
by-proof (a :≡ a₁) (b :< b₁) ρ = do
prf ← by-proof-less a (lit 1 ⟨+⟩ a₁) b b₁ ρ
pure λ eq → prf (diff 0 (cong suc (sym eq)))
by-tactic : Term → Type → TC Term
by-tactic prf g = do
ensureNoMetas prf
h ← inferNormalisedType prf
let t = pi (vArg h) (abs "_" (weaken 1 g))
just (hyp ∷ goal ∷ [] , Γ) ← termToSubHyps t
where _ → typeError $ strErr "Invalid goal:" ∷ termErr t ∷ []
pure $
applyTerm (safe
(getProof (quote cantProve) t $
def (quote by-proof)
( vArg (` hyp)
∷ vArg (` goal)
∷ vArg (quotedEnv Γ)
∷ [])) _) (vArg prf ∷ [])
| {
"alphanum_fraction": 0.5431057564,
"avg_line_length": 41.9662921348,
"ext": "agda",
"hexsha": "6efb39bd689378de4afbaf089811d92c0ed1ef1e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Subtract/By.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Subtract/By.agda",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Subtract/By.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3230,
"size": 7470
} |
{-# OPTIONS --without-K --safe --erased-cubical --no-import-sorts #-}
module Prelude where
open import Agda.Primitive renaming (Set to Type) public
open import Agda.Builtin.Reflection hiding (Type) renaming (primQNameEquality to _==_) public
open import Reflection using (_>>=_) public
open import Agda.Builtin.String public
open import Agda.Builtin.Sigma public
open import Data.Bool using (Bool; not; true; false; if_then_else_) public
open import Data.List using (List; []; _∷_; map; concat; concatMap; _++_; foldr; zip; length; take) public
open import Data.Maybe using (Maybe; just; nothing) public
open import Data.Fin.Base using (Fin; toℕ) renaming (zero to fz) public
open import Data.Integer.Base using (ℤ; +_; -[1+_]) public
open import Data.Nat.Base using (ℕ; zero; suc; _^_) public
open import Data.Nat.DivMod using (_%_; _mod_) public
open import Data.Product using (_×_; _,_) public
open import Data.Unit using (⊤) public
open import Data.Vec using (Vec; []; _∷_; updateAt) public
open import Function using (id; _∘_; flip) public
open import Definition.Conversion.Soundness public
open import Interval public
open import Note public
open import Pitch using (Pitch; a; b; b♭; c; c♯; d; d♯; e; f; f♯; g; g♯) public
open import Transformation public
open import MidiEvent using (InstrumentNumber-1; maxChannels; MidiTrack) public
open import FarmCanon using () renaming (subject to canonsubject) public
open import FarmFugue using (b1; b2; b3; b4; b5; b6; b7; b8; b9; b10; b11; b12; b13; subject; countersubject; extra) public
| {
"alphanum_fraction": 0.7454780362,
"avg_line_length": 43,
"ext": "agda",
"hexsha": "f6c2722953bac20a7d895db4dd8c1b6593daa76f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:05:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-11-10T04:05:31.000Z",
"max_forks_repo_head_hexsha": "5d9a1bbfbe52f55acf33d960763dce0872689c2b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/Music",
"max_forks_repo_path": "Soundness/agda/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5d9a1bbfbe52f55acf33d960763dce0872689c2b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/Music",
"max_issues_repo_path": "Soundness/agda/Prelude.agda",
"max_line_length": 123,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "5d9a1bbfbe52f55acf33d960763dce0872689c2b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/Music",
"max_stars_repo_path": "Soundness/agda/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-10T04:05:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-11-10T04:05:28.000Z",
"num_tokens": 450,
"size": 1548
} |
------------------------------------------------------------------------------
-- Totality properties respect to ListN
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.Properties.Totality.ListN-I where
open import FOTC.Base
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.List.PropertiesI
open import FOTC.Program.SortList.SortList
------------------------------------------------------------------------------
-- The function flatten generates a ListN.
flatten-ListN : ∀ {t} → Tree t → ListN (flatten t)
flatten-ListN tnil = subst ListN (sym flatten-nil) lnnil
flatten-ListN (ttip {i} Ni) =
subst ListN (sym (flatten-tip i)) (lncons Ni lnnil)
flatten-ListN (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂)
= subst ListN
(sym (flatten-node t₁ i t₂))
(++-ListN (flatten-ListN Tt₁)
(flatten-ListN Tt₂))
| {
"alphanum_fraction": 0.5046382189,
"avg_line_length": 38.5,
"ext": "agda",
"hexsha": "d7ed6a02bfd23f413a0185f9c7bb21a841924fc9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/SortList/Properties/Totality/ListN-I.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/SortList/Properties/Totality/ListN-I.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/SortList/Properties/Totality/ListN-I.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 250,
"size": 1078
} |
module FSM where
open import Sec4
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Bool
-- open import Data.Rational
-- open import Data.Integer
-- open import Relation.Nullary.Decidable
data Loc : Set where
A : Loc
DONE : Loc
record Values : Set where
field
x : ℕ
δ : ℕ
k : ℕ
data _Π_ (A B : Set) : Set where
<_,_> : (a : Loc) → (b : Values) → A Π B
-- The computation of x in the state
-- The state machine step function
step : (Loc Π Values) → (Loc Π Values)
step < A , b > =
if (X >= 10)
then
< DONE , record { x = X; δ = Values.δ b ; k = Values.k b Data.Nat.+ 1 } >
else
< A , record { x = X; δ = Values.δ b ; k = Values.k b Data.Nat.+ 1 } >
where
funₓ : ℕ → ℕ → ℕ → ℕ -- slope = 1 here!
funₓ x k δ = x Data.Nat.+ δ Data.Nat.* k
_>=_ : ℕ → ℕ → Bool
zero >= zero = true
zero >= suc y = false
suc x >= zero = false
suc x >= suc y = x >= y
_==_ : ℕ → ℕ → Bool
zero == zero = true
zero == suc y = false
suc x == zero = false
suc x == suc y = x == y
X : ℕ
X = funₓ (Values.x b) (Values.k b) (Values.δ b)
step < DONE , b > = < DONE , b > -- Just remain in this state forever
runFSM : (n : ℕ) → (st : (Loc Π Values)) → (Loc Π Values)
runFSM zero st = st
runFSM (suc n) st = runFSM n (step st)
theorem : runFSM 10 (< A , (record { x = zero ; δ = 1 ; k = zero }) >) ≡ < DONE ,
record { x = 10 ; δ = 1 ; k = 5 } >
theorem = refl
-- invariant when in DONE state, X ≥ 10
invariant : (Loc Π Values) → Prop
invariant < A , record { x = x ; δ = δ ; k = k } > = ⊥
invariant < DONE , record { x = x ; δ = δ ; k = k } > = x ≥ 10
thm : invariant (runFSM 5 (< A , (record { x = zero ; δ = 1 ; k = zero }) >))
thm = s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))))))
-- Example of state machine as a relation
data State : Set where
A : ∀ (n : ℕ) → State
D : ∀ (n : ℕ) → State
private funₓ : ℕ → ℕ → ℕ → ℕ
funₓ x δ slope = x Data.Nat.+ δ Data.Nat.* slope
data _↓_ : State → State → Prop where
S1 : ∀ (n : ℕ) → (n < 10) → (A n) ↓ (A (funₓ n 1 1))
S2 : ∀ (n : ℕ) → (n ≥ 10) → (A n) ↓ (D n)
data fState : State → Prop where
F : ∀ (n : ℕ) → (n ≥ 10) → fState (D n)
data oState : State → Prop where
O : oState (A 0)
y : ∀ (n : ℕ) → (p : n < 10) → (A n) ↓ (A (ℕ.suc n))
y .0 (s≤s z≤n) = S1 zero (s≤s z≤n)
y .1 (s≤s (s≤s z≤n)) = S1 (suc zero) (s≤s (s≤s z≤n))
y .2 (s≤s (s≤s (s≤s z≤n))) = S1 (suc (suc zero)) (s≤s (s≤s (s≤s z≤n)))
y .3 (s≤s (s≤s (s≤s (s≤s z≤n)))) = S1 (suc (suc (suc zero))) (s≤s (s≤s (s≤s (s≤s z≤n))))
y .4 (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))) = S1 (suc (suc (suc (suc zero)))) (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))
y .5 (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))) = S1 (suc (suc (suc (suc (suc zero)))))
(s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))
y .6 (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))) = S1 (suc (suc (suc (suc (suc (suc zero))))))
(s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))))
y .7 (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))))) = S1 (suc (suc (suc (suc (suc (suc (suc zero)))))))
(s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))))
y .8 (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))))) = S1 (suc (suc (suc (suc (suc (suc (suc (suc zero))))))))
(s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))))))
y .9 (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n)))))))))) = S1 (suc (suc (suc (suc (suc (suc (suc (suc (suc zero)))))))))
(s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))))))
y1 : ∀ (n : ℕ) → (p : n ≥ 10) → (A n) ↓ (D n)
y1 n p = S2 n p
-- Example of arithexpr as a relation
data aexp : Set where
ANum : ∀ (n : ℕ) → aexp
APlus : aexp → aexp → aexp
AMult : aexp → aexp → aexp
aeval : aexp → ℕ
aeval (ANum n) = n
aeval (APlus a₁ a₂) = (aeval a₁) + (aeval a₂)
aeval (AMult n₁ n₂) = (aeval n₁) * (aeval n₂)
_==_ : ℕ → ℕ → Bool
zero == zero = true
zero == suc y = false
suc x == zero = false
suc x == suc y = x == y
-- compiler optimization
aexp-opt1 : aexp → aexp
aexp-opt1 (ANum n) = ANum n
aexp-opt1 (APlus (ANum n) (ANum n₁)) with (n == 0) Data.Bool.∧ (n₁ == n)
aexp-opt1 (APlus (ANum n) (ANum n₁)) | false = (APlus (ANum n) (ANum n₁))
aexp-opt1 (APlus (ANum n) (ANum n₁)) | true = (ANum 0)
aexp-opt1 (APlus x x₁) = APlus x x₁
aexp-opt1 (AMult (ANum n) (ANum n₁)) with (n == 0) Data.Bool.∨ (n₁ == 0)
aexp-opt1 (AMult (ANum n) (ANum n₁)) | true = ANum 0
aexp-opt1 (AMult (ANum n) (ANum n₁)) | false = (AMult (ANum n) (ANum n₁))
aexp-opt1 (AMult x x₁) = (AMult x x₁)
-- Theorem that the optimization is correct!
thm-opt1 : ∀ (a : aexp) → ∀ (n : ℕ)
→ (aeval a ≡ n)
→ aeval (aexp-opt1 a) ≡ n
thm-opt1 (ANum n) .n refl = refl
thm-opt1 (APlus (ANum zero) (ANum zero)) .0 refl = refl
thm-opt1 (APlus (ANum zero) (ANum (suc n))) .(suc n) refl = refl
thm-opt1 (APlus (ANum (suc n)) (ANum n₁)) .(suc (n + n₁)) refl = refl
thm-opt1 (APlus (ANum n) (APlus b b₁)) .(n + (aeval b + aeval b₁)) refl = refl
thm-opt1 (APlus (ANum n) (AMult b b₁)) .(n + aeval b * aeval b₁) refl = refl
thm-opt1 (APlus (APlus a a₁) b) .(aeval a + aeval a₁ + aeval b) refl = refl
thm-opt1 (APlus (AMult a a₁) b) .(aeval a * aeval a₁ + aeval b) refl = refl
thm-opt1 (AMult (ANum zero) (ANum n₁)) .0 refl = refl
thm-opt1 (AMult (ANum (suc n)) (ANum zero)) .(n * 0) refl = cc n
where
cc : ∀ (n : ℕ) → (0 ≡ n * 0)
cc zero = refl
cc (suc n) = cc n
thm-opt1 (AMult (ANum (suc n)) (ANum (suc p))) .(suc (p + n * suc p)) refl = refl
thm-opt1 (AMult (ANum n) (APlus b b₁)) .(n * (aeval b + aeval b₁)) refl = refl
thm-opt1 (AMult (ANum n) (AMult b b₁)) .(n * (aeval b * aeval b₁)) refl = refl
thm-opt1 (AMult (APlus a a₁) b) .((aeval a + aeval a₁) * aeval b) refl = refl
thm-opt1 (AMult (AMult a a₁) b) .(aeval a * aeval a₁ * aeval b) refl = refl
-- Now as a relation
data _⇓_ : aexp → ℕ → Set where
ANumR : ∀ (n : ℕ) → ANum n ⇓ n
APlusR : ∀ (n₁ n₂ : ℕ) → ∀ (a₁ a₂ : aexp)
→ (a₁ ⇓ n₁) → (a₂ ⇓ n₂)
→ (APlus a₁ a₂) ⇓ (n₁ + n₂)
AMultR : ∀ (n₁ n₂ : ℕ) → ∀ (a₁ a₂ : aexp)
→ (a₁ ⇓ n₁) → (a₂ ⇓ n₂)
→ (AMult a₁ a₂) ⇓ (n₁ * n₂)
∧-Zero : ∀ (x y : ℕ) → ((x ≡ 0) Sec4.∧ (y ≡ 0)) Sec4.∨ ⊤
∧-Zero zero zero = ora (and refl refl)
∧-Zero zero (suc y) = orb ⋆
∧-Zero (suc x) y = orb ⋆
∨-Zero : ∀ (x y : ℕ) → ((x ≡ 0) Sec4.∨ (y ≡ 0)) Sec4.∨ ⊤
∨-Zero zero _ = ora (ora refl)
∨-Zero (suc x) zero = ora (orb refl)
∨-Zero (suc x) (suc y) = orb ⋆
-- compiler optimization
aexp-opt2 : aexp → aexp
aexp-opt2 (ANum n) = ANum n
aexp-opt2 (APlus (ANum n) (ANum n₁)) with ∧-Zero n n₁
aexp-opt2 (APlus (ANum .0) (ANum .0)) | ora (and refl refl) = ANum zero
aexp-opt2 (APlus (ANum n) (ANum n₁)) | orb _ = (APlus (ANum n) (ANum n₁))
aexp-opt2 (APlus x x₁) = APlus x x₁
aexp-opt2 (AMult (ANum n) (ANum n₁)) with ∨-Zero n n₁
aexp-opt2 (AMult (ANum .0) (ANum n₁)) | ora (ora refl) = ANum 0
aexp-opt2 (AMult (ANum n) (ANum .0)) | ora (orb refl) = ANum 0
aexp-opt2 (AMult (ANum n) (ANum n₁)) | orb x = (AMult (ANum n) (ANum n₁))
aexp-opt2 (AMult x x₁) = (AMult x x₁)
yy : ∀ (n : ℕ) → (n * 0) ≡ 0
yy zero = refl
yy (suc n) = yy n
-- Theorem that the optimization is correct in relations
thm-rel-opt2 : ∀ (a : aexp) → ∀ (p : ℕ) → (a ⇓ p) → ((aexp-opt2 a) ⇓ p)
thm-rel-opt2 (ANum n) p e = e
thm-rel-opt2 (APlus (ANum n) (ANum n₁)) p e with ∧-Zero n n₁
thm-rel-opt2 (APlus (ANum .0) (ANum .0)) .0 (APlusR .0 .0 .(ANum 0) .(ANum 0) (ANumR .0) (ANumR .0)) | ora (and refl refl) = ANumR zero
thm-rel-opt2 (APlus (ANum n) (ANum n₁)) p e | orb x = e
thm-rel-opt2 (APlus (ANum n) (APlus a a₁)) p e = e
thm-rel-opt2 (APlus (ANum n) (AMult a a₁)) p e = e
thm-rel-opt2 (APlus (APlus a a₁) a₂) p e = e
thm-rel-opt2 (APlus (AMult a a₁) a₂) p e = e
thm-rel-opt2 (AMult (ANum n) (ANum n₁)) p e with ∨-Zero n n₁
thm-rel-opt2 (AMult (ANum .0) (ANum n₃)) .0 (AMultR .0 .n₃ .(ANum 0) .(ANum n₃) (ANumR .0) (ANumR .n₃)) | ora (ora refl) = ANumR zero
-- The below is rewrite
thm-rel-opt2 (AMult (ANum n₁) (ANum .0)) .(n₁ * 0) (AMultR .n₁ .0 .(ANum n₁) .(ANum 0) (ANumR .n₁) (ANumR .0)) | ora (orb refl) with (yy n₁)
thm-rel-opt2 (AMult (ANum n₁) (ANum .0)) .(n₁ * 0) (AMultR .n₁ .0 .(ANum n₁) .(ANum 0) (ANumR .n₁) (ANumR .0)) | ora (orb refl) | j with n₁ * 0
thm-rel-opt2 (AMult (ANum n₁) (ANum _)) .(n₁ * _) (AMultR .n₁ _ .(ANum n₁) .(ANum _) (ANumR .n₁) (ANumR _)) | ora (orb refl) | refl | .0 = ANumR zero
thm-rel-opt2 (AMult (ANum n) (ANum n₁)) p e | orb x = e
thm-rel-opt2 (AMult (ANum n) (APlus b b₁)) p e = e
thm-rel-opt2 (AMult (ANum n) (AMult b b₁)) p e = e
thm-rel-opt2 (AMult (APlus a a₁) b) p e = e
thm-rel-opt2 (AMult (AMult a a₁) b) p e = e
th : (APlus (ANum 10) (ANum 10)) ⇓ 20
th = APlusR
(suc (suc (suc (suc (suc (suc (suc (suc (suc (suc zero))))))))))
(suc (suc (suc (suc (suc (suc (suc (suc (suc (suc zero))))))))))
(ANum
(suc (suc (suc (suc (suc (suc (suc (suc (suc (suc zero)))))))))))
(ANum
(suc (suc (suc (suc (suc (suc (suc (suc (suc (suc zero)))))))))))
(ANumR
(suc (suc (suc (suc (suc (suc (suc (suc (suc (suc zero)))))))))))
(ANumR
(suc (suc (suc (suc (suc (suc (suc (suc (suc (suc zero)))))))))))
t : ∀ (a : aexp) (p : ℕ) → (aeval a ≡ p) → (a ⇓ p)
t (ANum n) .n refl = ANumR n
t (APlus a a₁) .(aeval a + aeval a₁) refl = APlusR (aeval a) (aeval a₁) a a₁ (t a (aeval a) refl)
(t a₁ (aeval a₁) refl)
t (AMult a a₁) .(aeval a * aeval a₁) refl = AMultR (aeval a) (aeval a₁) a a₁ (t a (aeval a) refl)
(t a₁ (aeval a₁) refl)
tt : ∀ (a : aexp) (n : ℕ) → (a ⇓ n) → (aeval a ≡ n)
tt (ANum n₁) .n₁ (ANumR .n₁) = refl
tt (APlus a a₁) .(n₁ + n₂) (APlusR n₁ n₂ .a .a₁ p p₁) with tt a n₁ p | tt a₁ n₂ p₁
tt (APlus a a₁) .(aeval a + aeval a₁) (APlusR .(aeval a) .(aeval a₁) .a .a₁ p p₁) | refl | refl = refl
tt (AMult a a₁) .(n₁ * n₂) (AMultR n₁ n₂ .a .a₁ p p₁) with tt a n₁ p | tt a₁ n₂ p₁
tt (AMult a a₁) .(aeval a * aeval a₁) (AMultR .(aeval a) .(aeval a₁) .a .a₁ p p₁) | refl | refl = refl
| {
"alphanum_fraction": 0.5133190745,
"avg_line_length": 41.4758064516,
"ext": "agda",
"hexsha": "56160287700a84be719b9670b410a8660360023b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "amal029/agda-tutorial-dybjer",
"max_forks_repo_path": "FSM.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "amal029/agda-tutorial-dybjer",
"max_issues_repo_path": "FSM.agda",
"max_line_length": 149,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "amal029/agda-tutorial-dybjer",
"max_stars_repo_path": "FSM.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:52:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:52:30.000Z",
"num_tokens": 4933,
"size": 10286
} |
module Issue719 where
import Common.Size as A
module M where
private open module A = M
-- NOT NICE:
-- Duplicate definition of module A. Previous definition of module A
-- at /Users/abel/cover/alfa/Agda2-clean/test/Common/Size.agda:7,15-19
-- when scope checking the declaration
-- open module A = M
| {
"alphanum_fraction": 0.729903537,
"avg_line_length": 23.9230769231,
"ext": "agda",
"hexsha": "33fe303d8112212139c7db8fc13c0beed7a37af7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue719.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/Issue719.agda",
"max_line_length": 70,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue719.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 86,
"size": 311
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Monoidal.Construction.Product where
-- The functors associated with the product A × B of
-- (braided/symmetric) monoidal categories A and B are again
-- (braided/symmetric) monoidal.
open import Level using (Level)
open import Data.Product using (_,_; <_,_>)
open import Categories.Category using (Category)
open import Categories.Category.Product
open import Categories.Category.Monoidal
open import Categories.Category.Monoidal.Braided using (Braided)
open import Categories.Category.Monoidal.Construction.Product
open import Categories.Category.Monoidal.Symmetric using (Symmetric)
open import Categories.Functor using (Functor)
open import Categories.Functor.Bifunctor using (Bifunctor)
open import Categories.Functor.Monoidal
import Categories.Functor.Monoidal.Braided as BMF
import Categories.Functor.Monoidal.Symmetric as SMF
import Categories.Morphism as Morphism
import Categories.Morphism.Reasoning as MorphismReasoning
open import Categories.NaturalTransformation using (ntHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism using (niHelper)
private
variable
o ℓ e o₁ ℓ₁ e₁ o′₁ ℓ′₁ e′₁ o₂ ℓ₂ e₂ o′₂ ℓ′₂ e′₂ : Level
module _ {D₁ : MonoidalCategory o₁ ℓ₁ e₁} {D₂ : MonoidalCategory o₂ ℓ₂ e₂} where
open MonoidalCategory using (U)
private D₁×D₂ = Product-MonoidalCategory D₁ D₂
-- Pairing for monoidal categories is a monoidal functor
module _ {C : MonoidalCategory o ℓ e}
{F : Functor (U C) (U D₁)} {G : Functor (U C) (U D₂)} where
※-IsMonoidalFunctor : IsMonoidalFunctor C D₁ F →
IsMonoidalFunctor C D₂ G →
IsMonoidalFunctor C D₁×D₂ (F ※ G)
※-IsMonoidalFunctor FM GM = record
{ ε = FM.ε , GM.ε
; ⊗-homo = ntHelper (record
{ η = λ XY → FM.⊗-homo.η XY , GM.⊗-homo.η XY
; commute = λ fg → FM.⊗-homo.commute fg , GM.⊗-homo.commute fg
})
; associativity = FM.associativity , GM.associativity
; unitaryˡ = FM.unitaryˡ , GM.unitaryˡ
; unitaryʳ = FM.unitaryʳ , GM.unitaryʳ
}
where
module FM = IsMonoidalFunctor FM
module GM = IsMonoidalFunctor GM
※-IsStrongMonoidalFunctor : IsStrongMonoidalFunctor C D₁ F →
IsStrongMonoidalFunctor C D₂ G →
IsStrongMonoidalFunctor C D₁×D₂ (F ※ G)
※-IsStrongMonoidalFunctor FM GM = record
{ ε = record
{ from = FM.ε.from , GM.ε.from
; to = FM.ε.to , GM.ε.to
; iso = record
{ isoˡ = FM.ε.isoˡ , GM.ε.isoˡ
; isoʳ = FM.ε.isoʳ , GM.ε.isoʳ
}
}
; ⊗-homo = niHelper (record
{ η = < FM.⊗-homo.⇒.η , GM.⊗-homo.⇒.η >
; η⁻¹ = < FM.⊗-homo.⇐.η , GM.⊗-homo.⇐.η >
; commute = < FM.⊗-homo.⇒.commute , GM.⊗-homo.⇒.commute >
; iso = λ XY → record
{ isoˡ = FM.⊗-homo.iso.isoˡ XY , GM.⊗-homo.iso.isoˡ XY
; isoʳ = FM.⊗-homo.iso.isoʳ XY , GM.⊗-homo.iso.isoʳ XY
}
})
; associativity = FM.associativity , GM.associativity
; unitaryˡ = FM.unitaryˡ , GM.unitaryˡ
; unitaryʳ = FM.unitaryʳ , GM.unitaryʳ
}
where
module FM = IsStrongMonoidalFunctor FM
module GM = IsStrongMonoidalFunctor GM
module _ {C : MonoidalCategory o ℓ e} where
※-MonoidalFunctor : MonoidalFunctor C D₁ → MonoidalFunctor C D₂ →
MonoidalFunctor C D₁×D₂
※-MonoidalFunctor FM GM = record
{ isMonoidal = ※-IsMonoidalFunctor (isMonoidal FM) (isMonoidal GM) }
where open MonoidalFunctor using (isMonoidal)
※-StrongMonoidalFunctor : StrongMonoidalFunctor C D₁ →
StrongMonoidalFunctor C D₂ →
StrongMonoidalFunctor C D₁×D₂
※-StrongMonoidalFunctor FM GM = record
{ isStrongMonoidal =
※-IsStrongMonoidalFunctor (isStrongMonoidal FM) (isStrongMonoidal GM)
}
where open StrongMonoidalFunctor using (isStrongMonoidal)
-- The projections out of a product of monoidal categories are
-- monoidal functors
πˡ-IsStrongMonoidalFunctor : IsStrongMonoidalFunctor D₁×D₂ D₁ πˡ
πˡ-IsStrongMonoidalFunctor = record
{ ε = ≅.refl
; ⊗-homo = niHelper (record
{ η = λ _ → id
; η⁻¹ = λ _ → id
; commute = λ _ → id-comm-sym
; iso = λ _ → record { isoˡ = identity² ; isoʳ = identity² }
})
; associativity = begin
associator.from ∘ id ∘ id ⊗₁ id ≈⟨ refl⟩∘⟨ elimʳ ⊗.identity ⟩
associator.from ∘ id ≈⟨ id-comm ⟩
id ∘ associator.from ≈⟨ pushˡ (introʳ ⊗.identity) ⟩
id ∘ id ⊗₁ id ∘ associator.from ∎
; unitaryˡ = begin
unitorˡ.from ∘ id ∘ id ⊗₁ id ≈⟨ refl⟩∘⟨ elimʳ ⊗.identity ⟩
unitorˡ.from ∘ id ≈⟨ identityʳ ⟩
unitorˡ.from ∎
; unitaryʳ = begin
unitorʳ.from ∘ id ∘ id ⊗₁ id ≈⟨ refl⟩∘⟨ elimʳ ⊗.identity ⟩
unitorʳ.from ∘ id ≈⟨ identityʳ ⟩
unitorʳ.from ∎
}
where
open MonoidalCategory D₁
open HomReasoning
open Morphism (U D₁) using (module ≅)
open MorphismReasoning (U D₁)
πˡ-IsMonoidalFunctor : IsMonoidalFunctor D₁×D₂ D₁ πˡ
πˡ-IsMonoidalFunctor =
IsStrongMonoidalFunctor.isMonoidal πˡ-IsStrongMonoidalFunctor
πˡ-StrongMonoidalFunctor : StrongMonoidalFunctor D₁×D₂ D₁
πˡ-StrongMonoidalFunctor = record
{ isStrongMonoidal = πˡ-IsStrongMonoidalFunctor }
πˡ-MonoidalFunctor : MonoidalFunctor D₁×D₂ D₁
πˡ-MonoidalFunctor =
StrongMonoidalFunctor.monoidalFunctor πˡ-StrongMonoidalFunctor
πʳ-IsStrongMonoidalFunctor : IsStrongMonoidalFunctor D₁×D₂ D₂ πʳ
πʳ-IsStrongMonoidalFunctor = record
{ ε = ≅.refl
; ⊗-homo = niHelper (record
{ η = λ _ → id
; η⁻¹ = λ _ → id
; commute = λ _ → id-comm-sym
; iso = λ _ → record { isoˡ = identity² ; isoʳ = identity² }
})
; associativity = begin
associator.from ∘ id ∘ id ⊗₁ id ≈⟨ refl⟩∘⟨ elimʳ ⊗.identity ⟩
associator.from ∘ id ≈⟨ id-comm ⟩
id ∘ associator.from ≈⟨ pushˡ (introʳ ⊗.identity) ⟩
id ∘ id ⊗₁ id ∘ associator.from ∎
; unitaryˡ = begin
unitorˡ.from ∘ id ∘ id ⊗₁ id ≈⟨ refl⟩∘⟨ elimʳ ⊗.identity ⟩
unitorˡ.from ∘ id ≈⟨ identityʳ ⟩
unitorˡ.from ∎
; unitaryʳ = begin
unitorʳ.from ∘ id ∘ id ⊗₁ id ≈⟨ refl⟩∘⟨ elimʳ ⊗.identity ⟩
unitorʳ.from ∘ id ≈⟨ identityʳ ⟩
unitorʳ.from ∎
}
where
open MonoidalCategory D₂
open HomReasoning
open Morphism (U D₂) using (module ≅)
open MorphismReasoning (U D₂)
πʳ-IsMonoidalFunctor : IsMonoidalFunctor D₁×D₂ D₂ πʳ
πʳ-IsMonoidalFunctor =
IsStrongMonoidalFunctor.isMonoidal πʳ-IsStrongMonoidalFunctor
πʳ-StrongMonoidalFunctor : StrongMonoidalFunctor D₁×D₂ D₂
πʳ-StrongMonoidalFunctor = record
{ isStrongMonoidal = πʳ-IsStrongMonoidalFunctor }
πʳ-MonoidalFunctor : MonoidalFunctor D₁×D₂ D₂
πʳ-MonoidalFunctor =
StrongMonoidalFunctor.monoidalFunctor πʳ-StrongMonoidalFunctor
-- The cartesian product of two monoidal functors is again a
-- monoidal functor
module _ {C₁ : MonoidalCategory o′₁ ℓ′₁ e′₁}
{C₂ : MonoidalCategory o′₂ ℓ′₂ e′₂}
{F : Functor (U C₁) (U D₁)} {G : Functor (U C₂) (U D₂)} where
private C₁×C₂ = Product-MonoidalCategory C₁ C₂
⁂-IsMonoidalFunctor : IsMonoidalFunctor C₁ D₁ F →
IsMonoidalFunctor C₂ D₂ G →
IsMonoidalFunctor C₁×C₂ D₁×D₂ (F ⁂ G)
⁂-IsMonoidalFunctor FM GM = record
{ ε = FM.ε , GM.ε
; ⊗-homo = ntHelper (record
{ η = λ{ ((X₁ , X₂) , (Y₁ , Y₂)) →
FM.⊗-homo.η (X₁ , Y₁) , GM.⊗-homo.η (X₂ , Y₂) }
; commute = λ{ ((f₁ , f₂) , (g₁ , g₂)) →
FM.⊗-homo.commute (f₁ , g₁) , GM.⊗-homo.commute (f₂ , g₂) }
})
; associativity = FM.associativity , GM.associativity
; unitaryˡ = FM.unitaryˡ , GM.unitaryˡ
; unitaryʳ = FM.unitaryʳ , GM.unitaryʳ
}
where
module FM = IsMonoidalFunctor FM
module GM = IsMonoidalFunctor GM
⁂-IsStrongMonoidalFunctor : IsStrongMonoidalFunctor C₁ D₁ F →
IsStrongMonoidalFunctor C₂ D₂ G →
IsStrongMonoidalFunctor C₁×C₂ D₁×D₂ (F ⁂ G)
⁂-IsStrongMonoidalFunctor FM GM = record
{ ε = record
{ from = FM.ε.from , GM.ε.from
; to = FM.ε.to , GM.ε.to
; iso = record
{ isoˡ = FM.ε.isoˡ , GM.ε.isoˡ
; isoʳ = FM.ε.isoʳ , GM.ε.isoʳ
}
}
; ⊗-homo = niHelper (record
{ η = λ{ ((X₁ , X₂) , (Y₁ , Y₂)) →
FM.⊗-homo.⇒.η (X₁ , Y₁) , GM.⊗-homo.⇒.η (X₂ , Y₂) }
; η⁻¹ = λ{ ((X₁ , X₂) , (Y₁ , Y₂)) →
FM.⊗-homo.⇐.η (X₁ , Y₁) , GM.⊗-homo.⇐.η (X₂ , Y₂) }
; commute = λ{ ((f₁ , f₂) , (g₁ , g₂)) →
FM.⊗-homo.⇒.commute (f₁ , g₁) ,
GM.⊗-homo.⇒.commute (f₂ , g₂) }
; iso = λ{ ((X₁ , X₂) , (Y₁ , Y₂)) → record
{ isoˡ = FM.⊗-homo.iso.isoˡ (X₁ , Y₁) , GM.⊗-homo.iso.isoˡ (X₂ , Y₂)
; isoʳ = FM.⊗-homo.iso.isoʳ (X₁ , Y₁) , GM.⊗-homo.iso.isoʳ (X₂ , Y₂)
} }
})
; associativity = FM.associativity , GM.associativity
; unitaryˡ = FM.unitaryˡ , GM.unitaryˡ
; unitaryʳ = FM.unitaryʳ , GM.unitaryʳ
}
where
module FM = IsStrongMonoidalFunctor FM
module GM = IsStrongMonoidalFunctor GM
module _ {C₁ : MonoidalCategory o′₁ ℓ′₁ e′₁}
{C₂ : MonoidalCategory o′₂ ℓ′₂ e′₂} where
private C₁×C₂ = Product-MonoidalCategory C₁ C₂
⁂-MonoidalFunctor : MonoidalFunctor C₁ D₁ → MonoidalFunctor C₂ D₂ →
MonoidalFunctor C₁×C₂ D₁×D₂
⁂-MonoidalFunctor FM GM = record
{ isMonoidal = ⁂-IsMonoidalFunctor (isMonoidal FM) (isMonoidal GM) }
where open MonoidalFunctor using (isMonoidal)
⁂-StrongMonoidalFunctor : StrongMonoidalFunctor C₁ D₁ →
StrongMonoidalFunctor C₂ D₂ →
StrongMonoidalFunctor C₁×C₂ D₁×D₂
⁂-StrongMonoidalFunctor FM GM = record
{ isStrongMonoidal =
⁂-IsStrongMonoidalFunctor (isStrongMonoidal FM) (isStrongMonoidal GM)
}
where open StrongMonoidalFunctor using (isStrongMonoidal)
module _ {D₁ : BraidedMonoidalCategory o₁ ℓ₁ e₁}
{D₂ : BraidedMonoidalCategory o₂ ℓ₂ e₂} where
open BMF
open BraidedMonoidalCategory using (U)
private D₁×D₂ = Product-BraidedMonoidalCategory D₁ D₂
-- Pairing for braided monoidal categories is a braided monoidal
-- functor
module _ {C : BraidedMonoidalCategory o ℓ e}
{F : Functor (U C) (U D₁)} {G : Functor (U C) (U D₂)} where
※-IsBraidedMonoidalFunctor : Lax.IsBraidedMonoidalFunctor C D₁ F →
Lax.IsBraidedMonoidalFunctor C D₂ G →
Lax.IsBraidedMonoidalFunctor C D₁×D₂ (F ※ G)
※-IsBraidedMonoidalFunctor FB GB = record
{ isMonoidal = ※-IsMonoidalFunctor (isMonoidal FB) (isMonoidal GB)
; braiding-compat = (braiding-compat FB) , (braiding-compat GB)
}
where open Lax.IsBraidedMonoidalFunctor
※-IsStrongBraidedMonoidalFunctor :
Strong.IsBraidedMonoidalFunctor C D₁ F →
Strong.IsBraidedMonoidalFunctor C D₂ G →
Strong.IsBraidedMonoidalFunctor C D₁×D₂ (F ※ G)
※-IsStrongBraidedMonoidalFunctor FB GB = record
{ isStrongMonoidal =
※-IsStrongMonoidalFunctor (isStrongMonoidal FB) (isStrongMonoidal GB)
; braiding-compat = (braiding-compat FB) , (braiding-compat GB)
}
where open Strong.IsBraidedMonoidalFunctor
module _ {C : BraidedMonoidalCategory o ℓ e} where
※-BraidedMonoidalFunctor : Lax.BraidedMonoidalFunctor C D₁ →
Lax.BraidedMonoidalFunctor C D₂ →
Lax.BraidedMonoidalFunctor C D₁×D₂
※-BraidedMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
※-IsBraidedMonoidalFunctor (isBraidedMonoidal FB) (isBraidedMonoidal GB)
}
where open Lax.BraidedMonoidalFunctor
※-StrongBraidedMonoidalFunctor : Strong.BraidedMonoidalFunctor C D₁ →
Strong.BraidedMonoidalFunctor C D₂ →
Strong.BraidedMonoidalFunctor C D₁×D₂
※-StrongBraidedMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
※-IsStrongBraidedMonoidalFunctor (isBraidedMonoidal FB)
(isBraidedMonoidal GB)
}
where open Strong.BraidedMonoidalFunctor
-- The projections out of a product of braided monoidal categories are
-- braided monoidal functors
πˡ-IsStrongBraidedMonoidalFunctor : Strong.IsBraidedMonoidalFunctor D₁×D₂ D₁ πˡ
πˡ-IsStrongBraidedMonoidalFunctor = record
{ isStrongMonoidal = πˡ-IsStrongMonoidalFunctor
; braiding-compat = MorphismReasoning.id-comm (U D₁)
}
πˡ-IsBraidedMonoidalFunctor : Lax.IsBraidedMonoidalFunctor D₁×D₂ D₁ πˡ
πˡ-IsBraidedMonoidalFunctor =
Strong.IsBraidedMonoidalFunctor.isLaxBraidedMonoidal
πˡ-IsStrongBraidedMonoidalFunctor
πˡ-StrongBraidedMonoidalFunctor : Strong.BraidedMonoidalFunctor D₁×D₂ D₁
πˡ-StrongBraidedMonoidalFunctor = record
{ isBraidedMonoidal = πˡ-IsStrongBraidedMonoidalFunctor }
πˡ-BraidedMonoidalFunctor : Lax.BraidedMonoidalFunctor D₁×D₂ D₁
πˡ-BraidedMonoidalFunctor =
Strong.BraidedMonoidalFunctor.laxBraidedMonoidalFunctor
πˡ-StrongBraidedMonoidalFunctor
πʳ-IsStrongBraidedMonoidalFunctor : Strong.IsBraidedMonoidalFunctor D₁×D₂ D₂ πʳ
πʳ-IsStrongBraidedMonoidalFunctor = record
{ isStrongMonoidal = πʳ-IsStrongMonoidalFunctor
; braiding-compat = MorphismReasoning.id-comm (U D₂)
}
πʳ-IsBraidedMonoidalFunctor : Lax.IsBraidedMonoidalFunctor D₁×D₂ D₂ πʳ
πʳ-IsBraidedMonoidalFunctor =
Strong.IsBraidedMonoidalFunctor.isLaxBraidedMonoidal
πʳ-IsStrongBraidedMonoidalFunctor
πʳ-StrongBraidedMonoidalFunctor : Strong.BraidedMonoidalFunctor D₁×D₂ D₂
πʳ-StrongBraidedMonoidalFunctor = record
{ isBraidedMonoidal = πʳ-IsStrongBraidedMonoidalFunctor }
πʳ-BraidedMonoidalFunctor : Lax.BraidedMonoidalFunctor D₁×D₂ D₂
πʳ-BraidedMonoidalFunctor =
Strong.BraidedMonoidalFunctor.laxBraidedMonoidalFunctor
πʳ-StrongBraidedMonoidalFunctor
-- The cartesian product of two braided monoidal functors is again a
-- braided monoidal functor
module _ {C₁ : BraidedMonoidalCategory o′₁ ℓ′₁ e′₁}
{C₂ : BraidedMonoidalCategory o′₂ ℓ′₂ e′₂}
{F : Functor (U C₁) (U D₁)} {G : Functor (U C₂) (U D₂)} where
private C₁×C₂ = Product-BraidedMonoidalCategory C₁ C₂
⁂-IsBraidedMonoidalFunctor : Lax.IsBraidedMonoidalFunctor C₁ D₁ F →
Lax.IsBraidedMonoidalFunctor C₂ D₂ G →
Lax.IsBraidedMonoidalFunctor C₁×C₂ D₁×D₂ (F ⁂ G)
⁂-IsBraidedMonoidalFunctor FB GB = record
{ isMonoidal = ⁂-IsMonoidalFunctor (isMonoidal FB) (isMonoidal GB)
; braiding-compat = braiding-compat FB , braiding-compat GB
}
where open Lax.IsBraidedMonoidalFunctor
⁂-IsStrongBraidedMonoidalFunctor :
Strong.IsBraidedMonoidalFunctor C₁ D₁ F →
Strong.IsBraidedMonoidalFunctor C₂ D₂ G →
Strong.IsBraidedMonoidalFunctor C₁×C₂ D₁×D₂ (F ⁂ G)
⁂-IsStrongBraidedMonoidalFunctor FB GB = record
{ isStrongMonoidal =
⁂-IsStrongMonoidalFunctor (isStrongMonoidal FB) (isStrongMonoidal GB)
; braiding-compat = braiding-compat FB , braiding-compat GB
}
where open Strong.IsBraidedMonoidalFunctor
module _ {C₁ : BraidedMonoidalCategory o′₁ ℓ′₁ e′₁}
{C₂ : BraidedMonoidalCategory o′₂ ℓ′₂ e′₂} where
private C₁×C₂ = Product-BraidedMonoidalCategory C₁ C₂
⁂-BraidedMonoidalFunctor : Lax.BraidedMonoidalFunctor C₁ D₁ →
Lax.BraidedMonoidalFunctor C₂ D₂ →
Lax.BraidedMonoidalFunctor C₁×C₂ D₁×D₂
⁂-BraidedMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
⁂-IsBraidedMonoidalFunctor (isBraidedMonoidal FB) (isBraidedMonoidal GB)
}
where open Lax.BraidedMonoidalFunctor
⁂-StrongBraidedMonoidalFunctor : Strong.BraidedMonoidalFunctor C₁ D₁ →
Strong.BraidedMonoidalFunctor C₂ D₂ →
Strong.BraidedMonoidalFunctor C₁×C₂ D₁×D₂
⁂-StrongBraidedMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
⁂-IsStrongBraidedMonoidalFunctor (isBraidedMonoidal FB)
(isBraidedMonoidal GB)
}
where open Strong.BraidedMonoidalFunctor
module _ {D₁ : SymmetricMonoidalCategory o₁ ℓ₁ e₁}
{D₂ : SymmetricMonoidalCategory o₂ ℓ₂ e₂} where
open SMF
open SymmetricMonoidalCategory using (U)
renaming (braidedMonoidalCategory to B)
private D₁×D₂ = Product-SymmetricMonoidalCategory D₁ D₂
-- Pairing for symmetric monoidal categories is a symmetric monoidal
-- functor
module _ {C : SymmetricMonoidalCategory o ℓ e} where
※-SymmetricMonoidalFunctor : Lax.SymmetricMonoidalFunctor C D₁ →
Lax.SymmetricMonoidalFunctor C D₂ →
Lax.SymmetricMonoidalFunctor C D₁×D₂
※-SymmetricMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
※-IsBraidedMonoidalFunctor (isBraidedMonoidal FB) (isBraidedMonoidal GB)
}
where open Lax.SymmetricMonoidalFunctor
※-StrongSymmetricMonoidalFunctor : Strong.SymmetricMonoidalFunctor C D₁ →
Strong.SymmetricMonoidalFunctor C D₂ →
Strong.SymmetricMonoidalFunctor C D₁×D₂
※-StrongSymmetricMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
※-IsStrongBraidedMonoidalFunctor (isBraidedMonoidal FB)
(isBraidedMonoidal GB)
}
where open Strong.SymmetricMonoidalFunctor
-- The projections out of a product of symmetric monoidal categories are
-- symmetric monoidal functors
πˡ-StrongSymmetricMonoidalFunctor : Strong.SymmetricMonoidalFunctor D₁×D₂ D₁
πˡ-StrongSymmetricMonoidalFunctor = record
{ isBraidedMonoidal = πˡ-IsStrongBraidedMonoidalFunctor {D₂ = B D₂} }
πˡ-SymmetricMonoidalFunctor : Lax.SymmetricMonoidalFunctor D₁×D₂ D₁
πˡ-SymmetricMonoidalFunctor =
Strong.SymmetricMonoidalFunctor.laxSymmetricMonoidalFunctor
πˡ-StrongSymmetricMonoidalFunctor
πʳ-StrongSymmetricMonoidalFunctor : Strong.SymmetricMonoidalFunctor D₁×D₂ D₂
πʳ-StrongSymmetricMonoidalFunctor = record
{ isBraidedMonoidal = πʳ-IsStrongBraidedMonoidalFunctor {D₁ = B D₁} }
πʳ-SymmetricMonoidalFunctor : Lax.SymmetricMonoidalFunctor D₁×D₂ D₂
πʳ-SymmetricMonoidalFunctor =
Strong.SymmetricMonoidalFunctor.laxSymmetricMonoidalFunctor
πʳ-StrongSymmetricMonoidalFunctor
-- The cartesian product of two symmetric monoidal functors is again a
-- symmetric monoidal functor
module _ {C₁ : SymmetricMonoidalCategory o′₁ ℓ′₁ e′₁}
{C₂ : SymmetricMonoidalCategory o′₂ ℓ′₂ e′₂} where
private C₁×C₂ = Product-SymmetricMonoidalCategory C₁ C₂
⁂-SymmetricMonoidalFunctor : Lax.SymmetricMonoidalFunctor C₁ D₁ →
Lax.SymmetricMonoidalFunctor C₂ D₂ →
Lax.SymmetricMonoidalFunctor C₁×C₂ D₁×D₂
⁂-SymmetricMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
⁂-IsBraidedMonoidalFunctor (isBraidedMonoidal FB) (isBraidedMonoidal GB)
}
where open Lax.SymmetricMonoidalFunctor
⁂-StrongSymmetricMonoidalFunctor : Strong.SymmetricMonoidalFunctor C₁ D₁ →
Strong.SymmetricMonoidalFunctor C₂ D₂ →
Strong.SymmetricMonoidalFunctor C₁×C₂ D₁×D₂
⁂-StrongSymmetricMonoidalFunctor FB GB = record
{ isBraidedMonoidal =
⁂-IsStrongBraidedMonoidalFunctor (isBraidedMonoidal FB)
(isBraidedMonoidal GB)
}
where open Strong.SymmetricMonoidalFunctor
| {
"alphanum_fraction": 0.6310168181,
"avg_line_length": 41.7177419355,
"ext": "agda",
"hexsha": "b8e2e5c59219d256a654e9305c1ccdad156218d4",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Monoidal/Construction/Product.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Monoidal/Construction/Product.agda",
"max_line_length": 82,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Monoidal/Construction/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 6964,
"size": 20692
} |
module Tuple where
import Level
import Data.List as List
open import Data.List hiding (_++_; [_]; _∷ʳ_)
open import Data.Fin
open import Relation.Binary.PropositionalEquality hiding ([_])
infixr 5 _∷_
data Tuple {a} : List (Set a) → Set a where
[] : Tuple []
_∷_ : ∀ {A As} → A → Tuple As → Tuple (A ∷ As)
[_] : ∀ {a} {A : Set a} → A → Tuple (A ∷ [])
[ x ] = x ∷ []
_++_ : ∀ {a} {xs ys : List (Set a)}
→ Tuple xs → Tuple ys → Tuple (xs List.++ ys)
_++_ {xs = []} [] ys = ys
_++_ {xs = _ ∷ _} (x ∷ xs) ys = x ∷ (xs ++ ys)
_∷ʳ_ : ∀ {a} {x : Set a} {xs : List (Set a)}
→ Tuple xs → x → Tuple (xs List.∷ʳ x)
_∷ʳ_ xs x = xs ++ [ x ]
private
listLookup : ∀ {a} {A : Set a} (xs : List A) → (n : Fin (length xs)) → A
listLookup [] ()
listLookup (x ∷ xs) zero = x
listLookup (x ∷ xs) (suc n) = listLookup xs n
lookup : ∀ {a} {xs : List (Set a)}
→ (n : Fin (length xs)) → Tuple xs → listLookup xs n
lookup {xs = []} () []
lookup {xs = _ ∷ _} zero (x ∷ xs) = x
lookup {xs = _ ∷ _} (suc n) (x ∷ xs) = lookup n xs
unfoldToFunc : ∀ {a} → List (Set a) → Set a → Set a
unfoldToFunc [] B = B
unfoldToFunc (A ∷ As) B = A → unfoldToFunc As B
apply : {Xs : List Set} {A : Set} → unfoldToFunc Xs A → Tuple Xs → A
apply {[]} f [] = f
apply {_ ∷ _} f (x ∷ xs) = apply (f x) xs
list-proof : ∀ {a} {A : Set a} (xs : List A) → xs ≡ (xs List.++ [])
list-proof [] = refl
list-proof (x ∷ xs) = cong (_∷_ x) (list-proof xs)
list-proof₁ : ∀ {a} {A : Set a} (xs ys zs : List A)
→ (xs List.++ ys) List.++ zs ≡ xs List.++ (ys List.++ zs)
list-proof₁ [] ys zs = refl
list-proof₁ (x ∷ xs) ys zs = cong (_∷_ x) (list-proof₁ xs ys zs)
curry : ∀ {a} (xs : List (Set a)) → unfoldToFunc xs (Tuple xs)
curry xs = curry' [] xs []
where curry' : ∀ {a} (xs ys : List (Set a)) → Tuple xs
→ unfoldToFunc ys (Tuple (xs List.++ ys))
curry' xs [] tpl = subst Tuple (list-proof xs) tpl
curry' xs (y ∷ ys) tpl x₁ =
subst (λ x → unfoldToFunc ys (Tuple x))
(list-proof₁ xs List.[ y ] ys)
(curry' (xs List.∷ʳ y) ys (tpl ∷ʳ x₁))
proof₁ : ∀ {a} (As : List (Set a)) {B : Set a}
→ (Tuple As → B) → unfoldToFunc As B
proof₁ [] f = f []
proof₁ (A ∷ As) f x = proof₁ As (λ xs → f (x ∷ xs))
proof₂ : ∀ {a} (As : List (Set a)) {B : Set a}
→ unfoldToFunc As B → Tuple As → B
proof₂ [] f [] = f
proof₂ (A ∷ As) f (x ∷ xs) = proof₂ As (f x) xs
| {
"alphanum_fraction": 0.5163021048,
"avg_line_length": 31.8815789474,
"ext": "agda",
"hexsha": "7e92f6c22a8bec2f76bed1c28ac2658677585187",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mr-ohman/general-induction",
"max_forks_repo_path": "Tuple.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mr-ohman/general-induction",
"max_issues_repo_path": "Tuple.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mr-ohman/general-induction",
"max_stars_repo_path": "Tuple.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 949,
"size": 2423
} |
module builtinInModule where
module Str where
postulate S : Set
{-# BUILTIN STRING S #-}
primitive primStringAppend : S → S → S
| {
"alphanum_fraction": 0.6884057971,
"avg_line_length": 13.8,
"ext": "agda",
"hexsha": "7938d89c161dd54cbb2fa965e5e28c86db3999f4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/builtinInModule.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/builtinInModule.agda",
"max_line_length": 40,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/builtinInModule.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 38,
"size": 138
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor hiding (id)
-- Also defines the category of cocones "over a Functor F"
module Categories.Category.Construction.Cocones
{o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) where
open Category C
private
variable
X : Obj
open HomReasoning
open Functor F
open import Data.Product
open import Relation.Binary using (Rel; IsEquivalence; Setoid)
import Categories.Morphism as Mor
import Categories.Morphism.IsoEquiv as IsoEquiv
open import Categories.Diagram.Cocone F public
open Mor C
open IsoEquiv C
open import Categories.Morphism.Reasoning C
open Cocone
open Coapex
open Cocone⇒
Cocones : Category _ _ _
Cocones = record
{ Obj = Cocone
; _⇒_ = Cocone⇒
; _≈_ = λ f g → arr f ≈ arr g
; id = record { arr = id ; commute = identityˡ }
; _∘_ = λ {A B C} f g → record
{ arr = arr f ∘ arr g
; commute = λ {X} → begin
(arr f ∘ arr g) ∘ ψ A X ≈⟨ pullʳ (commute g) ⟩
arr f ∘ ψ B X ≈⟨ commute f ⟩
ψ C X ∎
}
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≈ = ∘-resp-≈
}
module Cocones = Category Cocones
private
variable
K K′ : Cocone
module CM = Mor Cocones
module CI = IsoEquiv Cocones
open CM using () renaming (_≅_ to _⇔_)
open CI using () renaming (_≃_ to _↮_)
cocone-resp-iso : ∀ (κ : Cocone) → Cocone.N κ ≅ X → Σ[ κ′ ∈ Cocone ] κ ⇔ κ′
cocone-resp-iso {X = X} κ κ≅X = record
{ coapex = record
{ ψ = λ Y → from ∘ Cocone.ψ κ Y
; commute = λ f → pullʳ (Cocone.commute κ f)
}
} , record
{ from = record
{ arr = from
; commute = refl
}
; to = record
{ arr = to
; commute = cancelˡ isoˡ
}
; iso = record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
}
where open _≅_ κ≅X
open Cocone
open Coapex
iso-cocone⇒iso-coapex : K ⇔ K′ → N K ≅ N K′
iso-cocone⇒iso-coapex K⇔K′ = record
{ from = arr from
; to = arr to
; iso = record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
}
where open _⇔_ K⇔K′
| {
"alphanum_fraction": 0.5764400173,
"avg_line_length": 22.637254902,
"ext": "agda",
"hexsha": "bb046fdd8db7270996c11ab6a050de451aa74c86",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/Cocones.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/Cocones.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/Cocones.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 864,
"size": 2309
} |
-- Andreas, 2015-08-26
{-# OPTIONS --rewriting #-} -- Should give error
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE refl #-}
| {
"alphanum_fraction": 0.642384106,
"avg_line_length": 18.875,
"ext": "agda",
"hexsha": "d5ed402fa938aebe6a36ae1a502f1cd73cac9b35",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/RewritingNotSafe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/RewritingNotSafe.agda",
"max_line_length": 48,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/RewritingNotSafe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 44,
"size": 151
} |
{-# OPTIONS --without-K #-}
open import M-types.Base.Core
open import M-types.Base.Sum
open import M-types.Base.Prod
module M-types.Base.Eq where
infix 4 _≡_
data _≡_ {X : Ty ℓ} : X → X → Ty ℓ where
refl : {x : X} → x ≡ x
open _≡_ public
infix 10 _⁻¹
_⁻¹ : {X : Ty ℓ} {x₀ x₁ : X} →
x₀ ≡ x₁ → x₁ ≡ x₀
refl ⁻¹ = refl
infixr 9 _·_
_·_ : {X : Ty ℓ} {x₀ x₁ x₂ : X} →
x₀ ≡ x₁ → x₁ ≡ x₂ → x₀ ≡ x₂
refl · refl = refl
·-neutr₀ : {X : Ty ℓ} {x₀ x₁ : X} →
∏[ p ∈ x₀ ≡ x₁ ] refl · p ≡ p
·-neutr₀ refl = refl
·-neutr₁ : {X : Ty ℓ} {x₀ x₁ : X} →
∏[ p ∈ x₀ ≡ x₁ ] p · refl ≡ p
·-neutr₁ refl = refl
infix 1 begin_
begin_ : {X : Ty ℓ} {x₀ x₁ : X} →
(x₀ ≡ x₁) → (x₀ ≡ x₁)
begin p = p
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : {X : Ty ℓ₀} {x₁ x₂ : X} →
∏[ x₀ ∈ X ] ((x₀ ≡ x₁) → (x₁ ≡ x₂) → (x₀ ≡ x₂))
x₀ ≡⟨ p₀ ⟩ p₁ = p₀ · p₁
infix 3 _∎
_∎ : {X : Ty ℓ} →
∏[ x ∈ X ] x ≡ x
x ∎ = refl
tra : {X : Ty ℓ} {x₀ x₁ : X} →
∏[ Y ∈ (X → Ty ℓ₁) ] (x₀ ≡ x₁ → (Y x₀ → Y x₁))
tra f refl = id
tra-con : {X : Ty ℓ₀} {x₀ x₁ x₂ : X} →
∏[ Y ∈ (X → Ty ℓ₁) ] ∏[ p₀ ∈ x₀ ≡ x₁ ] ∏[ p₁ ∈ x₁ ≡ x₂ ]
(tra Y p₁) ∘ (tra Y p₀) ≡ tra Y (p₀ · p₁)
tra-con Y refl refl = refl
ap : {X : Ty ℓ₀} {Y : Ty ℓ₁} {x₀ x₁ : X} →
∏[ f ∈ (X → Y) ] ((x₀ ≡ x₁) → (f x₀ ≡ f x₁))
ap f refl = refl
ap-inv : {X : Ty ℓ₀} {Y : Ty ℓ₁} {x₀ x₁ : X} →
∏[ f ∈ (X → Y) ] ∏[ p ∈ x₀ ≡ x₁ ] (ap f p)⁻¹ ≡ ap f (p ⁻¹)
ap-inv f refl = refl
apd : {X : Ty ℓ₀} {Y : X → Ty ℓ₁} {x₀ x₁ : X} →
∏[ f ∈ (∏ X Y) ] ∏[ p ∈ x₀ ≡ x₁ ] tra Y p (f x₀) ≡ f x₁
apd f refl = refl
≡-pair : {X : Ty ℓ₀} {Y : X → Ty ℓ₁} {w₀ w₁ : ∑ X Y} →
(∑[ p ∈ pr₀ w₀ ≡ pr₀ w₁ ] (tra Y p (pr₁ w₀) ≡ pr₁ w₁)) → (w₀ ≡ w₁)
≡-pair {ℓ₀} {ℓ₁} {X} {Y} {w} {w} (refl , refl) = refl
≡-apply : {X : Ty ℓ₀} {Y : X → Ty ℓ₁} {f₀ f₁ : ∏ X Y} →
(f₀ ≡ f₁) → (∏[ x ∈ X ] (f₀ x ≡ f₁ x))
≡-apply refl = λ x → refl
| {
"alphanum_fraction": 0.3952241715,
"avg_line_length": 25.0243902439,
"ext": "agda",
"hexsha": "ef7617f60bfd1bda8edff1b6c741fc5494b8667c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DDOtten/M-types",
"max_forks_repo_path": "Base/Eq.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DDOtten/M-types",
"max_issues_repo_path": "Base/Eq.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DDOtten/M-types",
"max_stars_repo_path": "Base/Eq.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1079,
"size": 2052
} |
module Issue3545 where
open import Agda.Builtin.Nat
open import Agda.Builtin.List
open import Common.IO
createElem : Nat → Set
createElem n = Nat
{-# NOINLINE createElem #-}
{-# COMPILE JS createElem = function (x0) {
return x0;
} #-}
-- WAS: silently accepted
-- WANT: `createElem` is going to be erased; don't do that!
map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
{-# COMPILE GHC map = \ _ _ _ _ -> Prelude.map #-}
-- `map` however is not erased so this should not raise a warning.
value : List Set
value = map (λ n → createElem n) (1 ∷ 1 ∷ [])
| {
"alphanum_fraction": 0.620414673,
"avg_line_length": 21.6206896552,
"ext": "agda",
"hexsha": "7ac5124afca6d2be66e0352235bb6f98a43e1401",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3545.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3545.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3545.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 201,
"size": 627
} |
open import Prelude hiding (id; Bool; _∷_; [])
module Examples.CompleteResolution where
data TC : Set where
tc-int : TC
tc-bool : TC
_tc≟_ : (a b : TC) → Dec (a ≡ b)
tc-int tc≟ tc-int = yes refl
tc-int tc≟ tc-bool = no (λ ())
tc-bool tc≟ tc-int = no (λ ())
tc-bool tc≟ tc-bool = yes refl
open import Implicits.Syntax TC _tc≟_
open import Implicits.WellTyped TC _tc≟_
open import Implicits.Substitutions TC _tc≟_
open import Implicits.Syntax.Type.Unification TC _tc≟_
open import Implicits.Resolution.Finite.Resolution TC _tc≟_
open import Implicits.Resolution.Finite.Algorithm TC _tc≟_
open import Data.Maybe
open import Data.List
open import Category.Monad.Partiality
Bool : ∀ {n} → Type n
Bool = simpl (tc tc-bool)
Int : ∀ {n} → Type n
Int = simpl (tc tc-int)
module Ex₁ where
Δ : ICtx zero
Δ = Bool ∷ Int ∷ []
-- resolves directly using a value from the implicit context
r = resolve Δ Int
p : is-just r ≡ true
p = refl
module Ex₂ where
Δ : ICtx zero
Δ = Bool ∷ (Bool ⇒ Int) ∷ []
-- resolves using implicit application
r = resolve Δ Int
p : is-just r ≡ true
p = refl
module Ex₃ where
Δ : ICtx zero
Δ = Bool ∷ (∀' (Bool ⇒ (simpl (tvar zero)))) ∷ []
-- resolves using polymorphic implicit application
r = resolve Δ Int
p : is-just r ≡ true
p = refl
module Ex₅ where
-- The following context would not resolved Int in Oliveira's deterministic calculus.
-- Demonstratint that partial resolution is more powerful for terminating contexts.
Δ : ICtx zero
Δ = (Bool ⇒ Int) ∷ Int ∷ []
r = resolve Δ Int
p : is-just r ≡ true
p = refl
module Ex₆ where
Δ : ICtx zero
Δ = Bool ∷ (∀' (Bool ⇒ (simpl (tvar zero)))) ∷ []
-- resolves rule types
r = resolve Δ (Bool ⇒ Int)
p : is-just r ≡ true
p = refl
module Ex₇ where
Δ : ICtx zero
Δ = Bool ∷ (∀' (Bool ⇒ (simpl (tvar zero)))) ∷ []
q : Type zero
q = (∀' (Bool ⇒ (simpl (tvar zero))))
-- Resolves polymorphic types.
-- Note that it doesn't resolve to the rule in the context directly.
-- Instead, it will apply r-tabs and r-iabs, to obtain resolve Δ' ⊢ᵣ (∀' (tvar zero))
r = resolve Δ q
p : is-just r ≡ true
p = refl
module Ex₈ where
Δ : ICtx zero
Δ = Bool ∷ (∀' ((simpl (tvar zero)) ⇒ (simpl (tvar zero)))) ∷ []
-- infinite derivation exists: fails divergence checking
r = resolve Δ Int
p : is-just r ≡ false
p = refl
module Ex₉ where
a⇒consta : Type zero
a⇒consta = (∀' ((simpl (tvar zero)) ⇒ (∀' (simpl (simpl (tvar zero) →' (simpl (tvar (suc zero))))))))
Δ : ICtx zero
Δ = Bool ∷ a⇒consta ∷ []
const-bool : Type zero
const-bool = (∀' (simpl ((simpl (tvar zero)) →' Bool)))
r = resolve Δ const-bool
p : is-just r ≡ true
p = refl
module Ex₁₀ where
-- similar to Ex₉ but for this particular example we have that for the rule part
-- || ρ₁ || ≮ || ρ₂ || such that Oliveira's ⊢term predicate on ρ₁ ⇒ ρ₂ fails
a⇒∀a : Type zero
a⇒∀a = (∀' ((simpl (tvar zero)) ⇒ (∀' (simpl (tvar (suc zero))))))
Δ : ICtx zero
Δ = Bool ∷ a⇒∀a ∷ []
r = resolve Δ (∀' Bool)
p : is-just r ≡ true
p = refl
| {
"alphanum_fraction": 0.6240310078,
"avg_line_length": 21.5,
"ext": "agda",
"hexsha": "d267558898bd3fb777d9ae6ec76cfbc181f209ae",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Examples/CompleteResolution.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Examples/CompleteResolution.agda",
"max_line_length": 103,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Examples/CompleteResolution.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 1091,
"size": 3096
} |
module Section1 where
-- 1. Introduction
-- ===============
--
-- 1.1. Outline of the formalisation
-- ---------------------------------
--
-- - We formalize terms-in-context, `Γ ⊢ t ∷ A`, as a calculus of proof trees, `Γ ⊢ A`, for
-- implicational logic, i.e., term `t` is seen as a proof tree that derives `A` from the assumptions
-- contained in `Γ`. A notion of equivalence of terms-in-context (including, e.g., β-reduction
-- and η-conversion) is then defined with a conversion relation `_≅_` on these proof trees.
--
-- - We give a Kripke model with an ordered set of worlds and define when a proposition `A` is
-- true for a world `w` in the model, `w ⊩ A`. We also define an extensional equality between
-- objects in the model.
--
-- - We define an interpreter `⟦_⟧` that maps a proof tree in the theory to its semantics in the
-- Kripke model. According to the Curry-Howard correspondence of programs to proofs
-- and types to propositions, the type of the interpreter expresses soundness of the theory of
-- proof trees with respect to the Kripke model. Consequently, the interpreter can be seen
-- as a constructive soundness proof.
--
-- - We also define an inversion function, `reify`, which returns a proof tre corresponding to
-- a given semantic object, yielding—again by the Curry-Howard isomorphism—a
-- completeness proof.
--
-- The inversion function is based on the principle of normalization by evaluation [3].
-- Obviously, for proof trees `M` and `N` with the same semantics, inversion yields the same proof
-- tree `reify ⟦ M ⟧ = reify ⟦ N ⟧`. Consequently, we define a normalization function, `nf`, as
-- the composition of the interpreter and the inversion function. We prove that if `M` is a proof
-- tree, then `M ≅ nf M`; together with the soundness result, this yields a decision algorithm
-- for convertibility. We further show that `nf` returns a proof term in long η-normal form.
--
-- - We prove that the convertibility relation on proof trees is sound and complete. The proof
-- of soundness, i.e., convertible proof trees have the same semantics, is straightforward by
-- induction on the structure of the trees. The completeness proof, i.e., if `⟦ M ⟧` and `⟦ N ⟧` are
-- equal, then `M` and `N` are convertible, uses the fact that `reify ⟦ M ⟧` is exactly the same as
-- `reify ⟦ N ⟧`, and since `M ≅ nf M ≡ reify ⟦ M ⟧` and vice versa for `N`, we get that `M ≅ N`.
--
-- - We define a calculus of simply typed ƛterms, a typed convertibility relation on the terms,
-- and a deterministic reduction, `_⇓_`. We also define an erasure function on proof trees that
-- maps a proof tree `M` into a well-typed term `M ⁻`. For every well-typed term there is at
-- least one proof tree that erases to this term; for defining the semantics of well-typed terms
-- through that of proof trees, it suffices to show that all proof trees that erase to the same
-- well-typed term have the same semantics.
--
-- - Because we know that convertible proof trees have the same semantics, it remains to
-- show that all proof trees that erase to a given well-typed term are convertible. We use an
-- argument due to Streicher [19]: we first prove that if `nf M ⁻` and `nf N ⁻` are the same,
-- then `M ≅ N`. Secondly, we prove that if a proof tree `M` erases to a well-typed term `t`,
-- then `t ⇓ nf M ⁻`. Now, if two proof trees `M` and `N` erase to the same well-typed term
-- `t`, then `t ⇓ nf M ⁻` and `t ⇓ nf N ⁻`. Since the reduction is deterministic we have that
-- `nf M ⁻` and `nf N ⁻` are the same, and hence `M ≅ N`.
--
-- - We prove that the convertibility relation on proof trees is sound and complete, and give
-- a decision algorithm for checking convertibility of two well-typed terms.
--
-- (…)
open import Agda.Builtin.FromString public
using (IsString ; fromString)
open import Data.Bool public
using (Bool ; T ; true ; false ; not)
renaming (_∧_ to and)
open import Data.Empty public
using (⊥)
renaming (⊥-elim to elim⊥)
open import Data.Product public
using (Σ ; _,_ ; _×_ ; proj₁ ; proj₂)
open import Data.Unit public
using (⊤ ; tt)
import Data.String as Str
open Str
using (String)
open import Function public
using (_∘_ ; case_of_ ; flip ; id)
open import Relation.Binary.PropositionalEquality public
using (_≡_ ; _≢_ ; refl ; cong ; subst ; sym ; trans)
renaming (cong₂ to cong²)
open import Relation.Nullary public
using (¬_ ; Dec ; yes ; no)
import Relation.Nullary.Decidable as Decidable
open Decidable using (⌊_⌋) public
open import Relation.Nullary.Negation public
renaming (contradiction to _↯_)
module _ where
data Name : Set where
name : String → Name
module _ where
inj-name : ∀ {s s′} → name s ≡ name s′ → s ≡ s′
inj-name refl = refl
_≟_ : (x x′ : Name) → Dec (x ≡ x′)
name s ≟ name s′ = Decidable.map′ (cong name) inj-name (s Str.≟ s′)
_≠_ : Name → Name → Bool
x ≠ x′ = not ⌊ x ≟ x′ ⌋
instance
str-Name : IsString Name
str-Name = record
{ Constraint = λ s → ⊤
; fromString = λ s → name s
}
module _ where
record Raiseable
{World : Set}
(_⊩◌ : World → Set)
{_⊒_ : World → World → Set} : Set₁ where
field
↑⟨_⟩ : ∀ {w w′} → w′ ⊒ w → w ⊩◌ → w′ ⊩◌
open Raiseable {{…}} public
record Lowerable
{World : Set}
(◌⊩_ : World → Set)
{_⊒_ : World → World → Set} : Set₁ where
field
↓⟨_⟩ : ∀ {w w′} → w′ ⊒ w → ◌⊩ w′ → ◌⊩ w
open Lowerable {{…}} public
| {
"alphanum_fraction": 0.6489890032,
"avg_line_length": 40.5611510791,
"ext": "agda",
"hexsha": "8e255aabbfda1e2f1b52392ed56ef8120c4d411a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/coquand",
"max_forks_repo_path": "src/Section1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/coquand",
"max_issues_repo_path": "src/Section1.agda",
"max_line_length": 105,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/coquand",
"max_stars_repo_path": "src/Section1.agda",
"max_stars_repo_stars_event_max_datetime": "2017-09-07T12:44:40.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-27T01:29:58.000Z",
"num_tokens": 1676,
"size": 5638
} |
module Dissect where
import Functor
import Sets
import Isomorphism
open Sets
open Functor
open Functor.Semantics
open Functor.Recursive
infixr 40 _+₂_
infixr 60 _×₂_
∇ : U -> U₂
∇ (K A) = K₂ [0]
∇ Id = K₂ [1]
∇ (F + G) = ∇ F +₂ ∇ G
∇ (F × G) = ∇ F ×₂ ↗ G +₂ ↖ F ×₂ ∇ G
diagonal : U₂ -> U
diagonal (K₂ A) = K A
diagonal (↖ F) = F
diagonal (↗ F) = F
diagonal (F +₂ G) = diagonal F + diagonal G
diagonal (F ×₂ G) = diagonal F × diagonal G
module Derivative where
import Derivative as D
∂ : U -> U
∂ F = diagonal (∇ F)
open Isomorphism
same : (F : U)(X : Set) -> ⟦ ∂ F ⟧ X ≅ ⟦ D.∂ F ⟧ X
same (K A) X = refl-≅ [0]
same Id X = refl-≅ [1]
same (F + G) X = iso[+] (same F X) (same G X)
same (F × G) X = iso[+] (iso[×] (same F X) (refl-≅ _))
(iso[×] (refl-≅ _) (same G X))
Stack : (F : U) -> Set -> Set -> Set
Stack F C J = List (⟦ ∇ F ⟧₂ C J)
NextJoker : U -> Set -> Set -> Set
NextJoker F C J = J [×] ⟦ ∇ F ⟧₂ C J [+] ⟦ F ⟧ C
mutual
into : (F : U){C J : Set} -> ⟦ F ⟧ J -> NextJoker F C J
into (K A) a = inr a
into Id x = inl < x , <> >
into (F + G) (inl f) = (id <×> inl <+> inl) (into F f)
into (F + G) (inr g) = (id <×> inr <+> inr) (into G g)
into (F × G) < fj , gj > = tryL F G (into F fj) gj
next : (F : U){C J : Set} -> ⟦ ∇ F ⟧₂ C J -> C -> NextJoker F C J
next (K A) () _
next Id <> c = inr c
next (F + G) (inl f') c = (id <×> inl <+> inl) (next F f' c)
next (F + G) (inr g') c = (id <×> inr <+> inr) (next G g' c)
next (F × G) (inl < f' , gj >) c = tryL F G (next F f' c) gj
next (F × G) (inr < fc , g' >) c = tryR F G fc (next G g' c)
tryL : (F G : U){C J : Set} ->
NextJoker F C J -> ⟦ G ⟧ J -> NextJoker (F × G) C J
tryL F G (inl < j , f' >) gj = inl < j , inl < f' , gj > >
tryL F G (inr fc) gj = tryR F G fc (into G gj)
tryR : (F G : U){C J : Set} ->
⟦ F ⟧ C -> NextJoker G C J -> NextJoker (F × G) C J
tryR F G fc (inl < j , g' >) = inl < j , inr < fc , g' > >
tryR F G fc (inr gc) = inr < fc , gc >
map : (F : U){C J : Set} -> (J -> C) -> ⟦ F ⟧ J -> ⟦ F ⟧ C
map F φ f = iter (into F f) where
iter : NextJoker F _ _ -> ⟦ F ⟧ _
iter (inl < j , d >) = iter (next F d (φ j))
iter (inr f) = f
fold : (F : U){T : Set} -> (⟦ F ⟧ T -> T) -> μ F -> T
fold F {T} φ r = inward r [] where
mutual
inward : μ F -> Stack F T (μ F) -> T
inward (inn f) γ = onward (into F f) γ
outward : T -> Stack F T (μ F) -> T
outward t [] = t
outward t (f' :: γ) = onward (next F f' t) γ
onward : NextJoker F T (μ F) -> Stack F T (μ F) -> T
onward (inl < r , f' >) γ = inward r (f' :: γ)
onward (inr t) γ = outward (φ t) γ
-- can we make a non-tail recursive fold?
-- of course, nothing could be simpler: (not structurally recursive though)
fold' : (F : U){T : Set} -> (⟦ F ⟧ T -> T) -> μ F -> T
fold' F φ = φ ∘ map F (fold' F φ) ∘ out
-- Fold operators
Φ : (F : U) -> Set -> Set
Φ (K A) T = A -> T
Φ Id T = T -> T
Φ (F + G) T = Φ F T [×] Φ G T
Φ (F × G) T = (T -> T -> T) [×] (Φ F T [×] Φ G T)
mkφ : (F : U){T : Set} -> Φ F T -> ⟦ F ⟧ T -> T
mkφ (K A) f a = f a
mkφ Id f t = f t
mkφ (F + G) < φf , φg > (inl f) = mkφ F φf f
mkφ (F + G) < φf , φg > (inr g) = mkφ G φg g
mkφ (F × G) < _○_ , < φf , φg > > < f , g > = mkφ F φf f ○ mkφ G φg g
| {
"alphanum_fraction": 0.4314334086,
"avg_line_length": 30.5517241379,
"ext": "agda",
"hexsha": "dbb75b732cb828076625bf3c2a789c6adaf451aa",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/clowns/Dissect.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/clowns/Dissect.agda",
"max_line_length": 77,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/clowns/Dissect.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 1602,
"size": 3544
} |
{-# OPTIONS --without-K --safe #-}
module Math.NumberTheory.Summation.Nat where
-- agda-stdlib
open import Algebra
open import Data.Nat.Properties
-- agda-misc
open import Math.NumberTheory.Summation.Generic
-- DO NOT change this line
open MonoidSummation (Semiring.+-monoid *-+-semiring) public
| {
"alphanum_fraction": 0.76,
"avg_line_length": 21.4285714286,
"ext": "agda",
"hexsha": "35584f1bff6b91bbec0dd0e9afb8b94c92cbcd69",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Math/NumberTheory/Summation/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Math/NumberTheory/Summation/Nat.agda",
"max_line_length": 60,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Math/NumberTheory/Summation/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 80,
"size": 300
} |
{-
Theory about path split equivalences.
They are convenient to construct localization HITs as in
(the "modalities paper")
https://arxiv.org/abs/1706.07526
- there are construction from and to equivalences ([pathSplitToEquiv] , [equivToPathSplit])
- the structure of a path split equivalence is actually a proposition ([isPropIsPathSplitEquiv])
The module starts with a couple of general facts about equivalences:
- if f is an equivalence then (cong f) is an equivalence ([equivCong])
- if f is an equivalence then pre- and postcomposition with f are equivalences ([preCompEquiv], [postCompEquiv])
(those are not in 'Equiv.agda' because they need Univalence.agda (which imports Equiv.agda))
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.PathSplitEquiv where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv.Properties
record isPathSplitEquiv {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where
field
s : B → A
sec : section f s
secCong : (x y : A) → Σ[ s' ∈ (f(x) ≡ f(y) → x ≡ y) ] section (cong f) s'
PathSplitEquiv : ∀ {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ')
PathSplitEquiv A B = Σ[ f ∈ (A → B) ] isPathSplitEquiv f
open isPathSplitEquiv
idIsPathSplitEquiv : ∀ {ℓ} {A : Type ℓ} → isPathSplitEquiv (λ (x : A) → x)
s idIsPathSplitEquiv x = x
sec idIsPathSplitEquiv x = refl
secCong idIsPathSplitEquiv = λ x y → (λ p → p) , λ p _ → p
module _ {ℓ} {A B : Type ℓ} where
toIsEquiv : (f : A → B) → isPathSplitEquiv f → isEquiv f
toIsEquiv f record { s = s ; sec = sec ; secCong = secCong } =
(isoToEquiv (iso f s sec (λ x → (secCong (s (f x)) x).fst (sec (f x))))) .snd
sectionOfEquiv' : (f : A → B) → isEquiv f → B → A
sectionOfEquiv' f record { equiv-proof = all-fibers-contractible } x =
all-fibers-contractible x .fst .fst
isSec : (f : A → B) → (pf : isEquiv f) → section f (sectionOfEquiv' f pf)
isSec f record { equiv-proof = all-fibers-contractible } x =
all-fibers-contractible x .fst .snd
sectionOfEquiv : (f : A → B) → isEquiv f → Σ (B → A) (section f)
sectionOfEquiv f e = sectionOfEquiv' f e , isSec f e
module _ {ℓ} {A B : Type ℓ} where
abstract
fromIsEquiv : (f : A → B) → isEquiv f → isPathSplitEquiv f
s (fromIsEquiv f pf) = sectionOfEquiv' f pf
sec (fromIsEquiv f pf) = isSec f pf
secCong (fromIsEquiv f pf) x y = sectionOfEquiv cong-f eq-cong
where
cong-f : x ≡ y → f x ≡ f y
cong-f = λ (p : x ≡ y) → cong f p
eq-cong : isEquiv cong-f
eq-cong = isEquivCong (f , pf)
pathSplitToEquiv : PathSplitEquiv A B → A ≃ B
fst (pathSplitToEquiv (f , _)) = f
snd (pathSplitToEquiv (_ , e)) = toIsEquiv _ e
equivToPathSplit : A ≃ B → PathSplitEquiv A B
fst (equivToPathSplit (f , _)) = f
snd (equivToPathSplit (_ , e)) = fromIsEquiv _ e
equivHasUniqueSection : (f : A → B)
→ isEquiv f → isContr (Σ (B → A) (section f))
equivHasUniqueSection f eq = helper'
where
idB = λ (x : B) → x
abstract
helper : isContr (fiber (λ (φ : B → A) → f ∘ φ) idB)
helper = (equiv-proof (snd (postCompEquiv (f , eq)))) idB
helper' : isContr (Σ[ φ ∈ (B → A) ] ((x : B) → f (φ x) ≡ x))
fst helper' = (φ , λ x i → η i x)
where φ = fst (fst helper)
η : f ∘ φ ≡ idB
η = snd (fst helper)
(snd helper') y i = (fst (η i) , λ b j → snd (η i) j b)
where η = (snd helper) (fst y , λ i b → snd y b i)
{-
PathSplitEquiv is a proposition and the type
of path split equivs is equivalent to the type of equivalences
-}
isPropIsPathSplitEquiv : ∀ {ℓ} {A B : Type ℓ} (f : A → B)
→ isProp (isPathSplitEquiv f)
isPropIsPathSplitEquiv {_} {A} {B} f
record { s = φ ; sec = sec-φ ; secCong = secCong-φ }
record { s = ψ ; sec = sec-ψ ; secCong = secCong-ψ } i
=
record {
s = fst (sectionsAreEqual i) ;
sec = snd (sectionsAreEqual i) ;
secCong = λ x y → congSectionsAreEqual x y (secCong-φ x y) (secCong-ψ x y) i
}
where
φ' = record { s = φ ; sec = sec-φ ; secCong = secCong-φ }
ψ' = record { s = ψ ; sec = sec-ψ ; secCong = secCong-ψ }
sectionsAreEqual : (φ , sec-φ) ≡ (ψ , sec-ψ)
sectionsAreEqual = (sym (contraction (φ , sec-φ))) ∙ (contraction (ψ , sec-ψ))
where contraction = snd (equivHasUniqueSection f (toIsEquiv f φ'))
congSectionsAreEqual : (x y : A) (l u : Σ (f(x) ≡ f(y) → x ≡ y) (section (cong f))) → l ≡ u
congSectionsAreEqual x y l u = (sym (contraction l)) ∙ (contraction u)
where contraction = snd (equivHasUniqueSection
(λ (p : x ≡ y) → cong f p)
(isEquivCong (pathSplitToEquiv (f , φ'))))
module _ {ℓ} {A B : Type ℓ} where
isEquivIsPathSplitToIsEquiv : (f : A → B) → isEquiv (fromIsEquiv f)
isEquivIsPathSplitToIsEquiv f =
isoToIsEquiv
(iso (fromIsEquiv f) (toIsEquiv f) (λ b → isPropIsPathSplitEquiv f _ _) (λ a → isPropIsEquiv f _ _ ))
isEquivPathSplitToEquiv : isEquiv (pathSplitToEquiv {A = A} {B = B})
isEquivPathSplitToEquiv =
isoToIsEquiv
(iso pathSplitToEquiv equivToPathSplit
(λ {(f , e) i → (f , isPropIsEquiv f (toIsEquiv f (fromIsEquiv f e)) e i)})
(λ {(f , e) i → (f , isPropIsPathSplitEquiv f (fromIsEquiv f (toIsEquiv f e)) e i)}))
equivPathSplitToEquiv : (PathSplitEquiv A B) ≃ (A ≃ B)
equivPathSplitToEquiv = (pathSplitToEquiv , isEquivPathSplitToEquiv)
| {
"alphanum_fraction": 0.6239858907,
"avg_line_length": 40.2127659574,
"ext": "agda",
"hexsha": "4907841979bddfbb27d14ada1ded097ffb67f7c1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Foundations/PathSplitEquiv.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Foundations/PathSplitEquiv.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Foundations/PathSplitEquiv.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2045,
"size": 5670
} |
module Type.Size.Countable where
import Data.Either as Type
import Data.Either.Equiv as Either
import Data.Tuple as Type
import Data.Tuple.Equiv as Tuple
import Lvl
open import Logic
open import Logic.Predicate
open import Numeral.Natural
open import Numeral.Natural.Sequence
open import Numeral.Natural.Sequence.Proofs
open import Relator.Equals.Proofs.Equivalence
open import Structure.Setoid
open import Type
open import Type.Size
open import Type.Size.Proofs
private variable ℓ ℓ₁ ℓ₂ ℓₑ : Lvl.Level
-- Definition of a countable type
Countable : (T : Type{ℓ}) → ⦃ _ : Equiv{ℓₑ}(T) ⦄ → Stmt
Countable(T) = (ℕ ≽ T)
-- Definition of a countably infinite type
CountablyInfinite : (T : Type{ℓ}) → ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → Stmt
CountablyInfinite(T) ⦃ equiv ⦄ = _≍_ ℕ ⦃ [≡]-equiv ⦄ T
private variable A : Type{ℓ₁}
private variable B : Type{ℓ₂}
private variable ⦃ equiv-A ⦄ : Equiv{ℓₑ}(A)
private variable ⦃ equiv-B ⦄ : Equiv{ℓₑ}(B)
private variable ⦃ equiv-A‖B ⦄ : Equiv{ℓₑ}(A Type.‖ B)
private variable ⦃ equiv-A⨯B ⦄ : Equiv{ℓₑ}(A Type.⨯ B)
module Countable where
-- TODO: Do something similar to CountablyInfinite here
-- _+_ : Countable (A) ⦃ equiv-A ⦄ → Countable(B) ⦃ equiv-B ⦄ → Countable(A ‖ B) ⦃ equiv-A‖B ⦄
-- [∃]-intro a ⦃ intro pa ⦄ + [∃]-intro b ⦃ intro pb ⦄ = [∃]-intro (Left ∘ a) ⦃ intro (\{y} → [∃]-intro ([∃]-witness pa) ⦃ {!!} ⦄) ⦄
-- [∃]-intro (Left ∘ a) ⦃ intro (\{y} → [∃]-intro ([∃]-witness pa) ⦃ {!!} ⦄) ⦄
-- _⋅_ : Countable (A) ⦃ equiv-A ⦄ → Countable(B) ⦃ equiv-B ⦄ → Countable(A ⨯ B) ⦃ equiv-A⨯B ⦄
module CountablyInfinite where
index : ∀{ℓ} → (T : Type{ℓ}) → ⦃ equiv-T : Equiv{ℓₑ}(T) ⦄ → ⦃ size : CountablyInfinite(T) ⦄ → (ℕ → T)
index(_) ⦃ size = size ⦄ = [∃]-witness size
indexing : ∀{ℓ} → (T : Type{ℓ}) → ⦃ equiv-T : Equiv{ℓₑ}(T) ⦄ → ⦃ size : CountablyInfinite(T) ⦄ → (T → ℕ)
indexing(T) ⦃ size = size ⦄ = [∃]-witness([≍]-symmetry-raw ⦃ [≡]-equiv ⦄ size ⦃ [≡]-to-function ⦄)
_+_ : ⦃ ext : Either.Extensionality ⦃ equiv-A ⦄ ⦃ equiv-B ⦄ (equiv-A‖B) ⦄ → CountablyInfinite(A) ⦃ equiv-A ⦄ → CountablyInfinite(B) ⦃ equiv-B ⦄ → CountablyInfinite(A Type.‖ B) ⦃ equiv-A‖B ⦄
[∃]-intro a + [∃]-intro b = [∃]-intro (interleave a b)
_⨯_ : ⦃ ext : Tuple.Extensionality ⦃ equiv-A ⦄ ⦃ equiv-B ⦄ (equiv-A⨯B) ⦄ → CountablyInfinite(A) ⦃ equiv-A ⦄ → CountablyInfinite(B) ⦃ equiv-B ⦄ → CountablyInfinite(A Type.⨯ B) ⦃ equiv-A⨯B ⦄
[∃]-intro a ⨯ [∃]-intro b = [∃]-intro (pair a b)
| {
"alphanum_fraction": 0.6225490196,
"avg_line_length": 42.9473684211,
"ext": "agda",
"hexsha": "b66df4cb6868f8fa23271b130541ea878ff35c5a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Type/Size/Countable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Type/Size/Countable.agda",
"max_line_length": 191,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Type/Size/Countable.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1078,
"size": 2448
} |
module regular-concat where
open import Level renaming ( suc to Suc ; zero to Zero )
open import Data.List
open import Data.Nat hiding ( _≟_ )
open import Data.Fin hiding ( _+_ )
open import Data.Empty
open import Data.Unit
open import Data.Product
-- open import Data.Maybe
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import logic
open import nat
open import automaton
open import regular-language
open import nfa
open import sbconst2
open import finiteSet
open import finiteSetUtil
open Automaton
open FiniteSet
open RegularLanguage
Concat-NFA : {Σ : Set} → (A B : RegularLanguage Σ ) → NAutomaton (states A ∨ states B) Σ
Concat-NFA {Σ} A B = record { Nδ = δnfa ; Nend = nend }
module Concat-NFA where
δnfa : states A ∨ states B → Σ → states A ∨ states B → Bool
δnfa (case1 q) i (case1 q₁) = equal? (afin A) (δ (automaton A) q i) q₁
δnfa (case1 qa) i (case2 qb) = (aend (automaton A) qa ) /\
(equal? (afin B) qb (δ (automaton B) (astart B) i) )
δnfa (case2 q) i (case2 q₁) = equal? (afin B) (δ (automaton B) q i) q₁
δnfa _ i _ = false
nend : states A ∨ states B → Bool
nend (case2 q) = aend (automaton B) q
nend (case1 q) = aend (automaton A) q /\ aend (automaton B) (astart B) -- empty B case
Concat-NFA-start : {Σ : Set} → (A B : RegularLanguage Σ ) → states A ∨ states B → Bool
Concat-NFA-start A B q = equal? (fin-∨ (afin A) (afin B)) (case1 (astart A)) q
CNFA-exist : {Σ : Set} → (A B : RegularLanguage Σ ) → (states A ∨ states B → Bool) → Bool
CNFA-exist A B qs = exists (fin-∨ (afin A) (afin B)) qs
M-Concat : {Σ : Set} → (A B : RegularLanguage Σ ) → RegularLanguage Σ
M-Concat {Σ} A B = record {
states = states A ∨ states B → Bool
; astart = Concat-NFA-start A B
; afin = finf
; automaton = subset-construction (CNFA-exist A B) (Concat-NFA A B)
} where
fin : FiniteSet (states A ∨ states B )
fin = fin-∨ (afin A) (afin B)
finf : FiniteSet (states A ∨ states B → Bool )
finf = fin→ fin
-- closed-in-concat' : {Σ : Set} → (A B : RegularLanguage Σ ) → ( x : List Σ ) → isRegular (Concat (contain A) (contain B)) x ( M-Concat A B )
-- closed-in-concat' {Σ} A B x = ≡-Bool-func closed-in-concat→ closed-in-concat← where
-- closed-in-concat→ : Concat (contain A) (contain B) x ≡ true → contain (M-Concat A B) x ≡ true
-- closed-in-concat→ = {!!}
-- closed-in-concat← : contain (M-Concat A B) x ≡ true → Concat (contain A) (contain B) x ≡ true
-- closed-in-concat← = {!!}
record Split {Σ : Set} (A : List Σ → Bool ) ( B : List Σ → Bool ) (x : List Σ ) : Set where
field
sp0 : List Σ
sp1 : List Σ
sp-concat : sp0 ++ sp1 ≡ x
prop0 : A sp0 ≡ true
prop1 : B sp1 ≡ true
open Split
list-empty++ : {Σ : Set} → (x y : List Σ) → x ++ y ≡ [] → (x ≡ [] ) ∧ (y ≡ [] )
list-empty++ [] [] refl = record { proj1 = refl ; proj2 = refl }
list-empty++ [] (x ∷ y) ()
list-empty++ (x ∷ x₁) y ()
open _∧_
open import Relation.Binary.PropositionalEquality hiding ( [_] )
c-split-lemma : {Σ : Set} → (A B : List Σ → Bool ) → (h : Σ) → ( t : List Σ ) → split A B (h ∷ t ) ≡ true
→ ( ¬ (A [] ≡ true )) ∨ ( ¬ (B ( h ∷ t ) ≡ true) )
→ split (λ t1 → A (h ∷ t1)) B t ≡ true
c-split-lemma {Σ} A B h t eq p = sym ( begin
true
≡⟨ sym eq ⟩
split A B (h ∷ t )
≡⟨⟩
A [] /\ B (h ∷ t) \/ split (λ t1 → A (h ∷ t1)) B t
≡⟨ cong ( λ k → k \/ split (λ t1 → A (h ∷ t1)) B t ) (lemma-p p ) ⟩
false \/ split (λ t1 → A (h ∷ t1)) B t
≡⟨ bool-or-1 refl ⟩
split (λ t1 → A (h ∷ t1)) B t
∎ ) where
open ≡-Reasoning
lemma-p : ( ¬ (A [] ≡ true )) ∨ ( ¬ (B ( h ∷ t ) ≡ true) ) → A [] /\ B (h ∷ t) ≡ false
lemma-p (case1 ¬A ) = bool-and-1 ( ¬-bool-t ¬A )
lemma-p (case2 ¬B ) = bool-and-2 ( ¬-bool-t ¬B )
split→AB : {Σ : Set} → (A B : List Σ → Bool ) → ( x : List Σ ) → split A B x ≡ true → Split A B x
split→AB {Σ} A B [] eq with bool-≡-? (A []) true | bool-≡-? (B []) true
split→AB {Σ} A B [] eq | yes eqa | yes eqb =
record { sp0 = [] ; sp1 = [] ; sp-concat = refl ; prop0 = eqa ; prop1 = eqb }
split→AB {Σ} A B [] eq | yes p | no ¬p = ⊥-elim (lemma-∧-1 eq (¬-bool-t ¬p ))
split→AB {Σ} A B [] eq | no ¬p | t = ⊥-elim (lemma-∧-0 eq (¬-bool-t ¬p ))
split→AB {Σ} A B (h ∷ t ) eq with bool-≡-? (A []) true | bool-≡-? (B (h ∷ t )) true
... | yes px | yes py = record { sp0 = [] ; sp1 = h ∷ t ; sp-concat = refl ; prop0 = px ; prop1 = py }
... | no px | _ with split→AB (λ t1 → A ( h ∷ t1 )) B t (c-split-lemma A B h t eq (case1 px) )
... | S = record { sp0 = h ∷ sp0 S ; sp1 = sp1 S ; sp-concat = cong ( λ k → h ∷ k) (sp-concat S) ; prop0 = prop0 S ; prop1 = prop1 S }
split→AB {Σ} A B (h ∷ t ) eq | _ | no px with split→AB (λ t1 → A ( h ∷ t1 )) B t (c-split-lemma A B h t eq (case2 px) )
... | S = record { sp0 = h ∷ sp0 S ; sp1 = sp1 S ; sp-concat = cong ( λ k → h ∷ k) (sp-concat S) ; prop0 = prop0 S ; prop1 = prop1 S }
AB→split : {Σ : Set} → (A B : List Σ → Bool ) → ( x y : List Σ ) → A x ≡ true → B y ≡ true → split A B (x ++ y ) ≡ true
AB→split {Σ} A B [] [] eqa eqb = begin
split A B []
≡⟨⟩
A [] /\ B []
≡⟨ cong₂ (λ j k → j /\ k ) eqa eqb ⟩
true
∎ where open ≡-Reasoning
AB→split {Σ} A B [] (h ∷ y ) eqa eqb = begin
split A B (h ∷ y )
≡⟨⟩
A [] /\ B (h ∷ y) \/ split (λ t1 → A (h ∷ t1)) B y
≡⟨ cong₂ (λ j k → j /\ k \/ split (λ t1 → A (h ∷ t1)) B y ) eqa eqb ⟩
true /\ true \/ split (λ t1 → A (h ∷ t1)) B y
≡⟨⟩
true \/ split (λ t1 → A (h ∷ t1)) B y
≡⟨⟩
true
∎ where open ≡-Reasoning
AB→split {Σ} A B (h ∷ t) y eqa eqb = begin
split A B ((h ∷ t) ++ y)
≡⟨⟩
A [] /\ B (h ∷ t ++ y) \/ split (λ t1 → A (h ∷ t1)) B (t ++ y)
≡⟨ cong ( λ k → A [] /\ B (h ∷ t ++ y) \/ k ) (AB→split {Σ} (λ t1 → A (h ∷ t1)) B t y eqa eqb ) ⟩
A [] /\ B (h ∷ t ++ y) \/ true
≡⟨ bool-or-3 ⟩
true
∎ where open ≡-Reasoning
open NAutomaton
open import Data.List.Properties
closed-in-concat : {Σ : Set} → (A B : RegularLanguage Σ ) → ( x : List Σ ) → isRegular (Concat (contain A) (contain B)) x ( M-Concat A B )
closed-in-concat {Σ} A B x = ≡-Bool-func closed-in-concat→ closed-in-concat← where
finab = (fin-∨ (afin A) (afin B))
NFA = (Concat-NFA A B)
abmove : (q : states A ∨ states B) → (h : Σ ) → states A ∨ states B
abmove (case1 q) h = case1 (δ (automaton A) q h)
abmove (case2 q) h = case2 (δ (automaton B) q h)
lemma-nmove-ab : (q : states A ∨ states B) → (h : Σ ) → Nδ NFA q h (abmove q h) ≡ true
lemma-nmove-ab (case1 q) h = equal?-refl (afin A)
lemma-nmove-ab (case2 q) h = equal?-refl (afin B)
nmove : (q : states A ∨ states B) (nq : states A ∨ states B → Bool ) → (nq q ≡ true) → ( h : Σ ) →
exists finab (λ qn → nq qn /\ Nδ NFA qn h (abmove q h)) ≡ true
nmove (case1 q) nq nqt h = found finab (case1 q) ( bool-and-tt nqt (lemma-nmove-ab (case1 q) h) )
nmove (case2 q) nq nqt h = found finab (case2 q) ( bool-and-tt nqt (lemma-nmove-ab (case2 q) h) )
acceptB : (z : List Σ) → (q : states B) → (nq : states A ∨ states B → Bool ) → (nq (case2 q) ≡ true) → ( accept (automaton B) q z ≡ true )
→ Naccept NFA (CNFA-exist A B) nq z ≡ true
acceptB [] q nq nqt fb = lemma8 where
lemma8 : exists finab ( λ q → nq q /\ Nend NFA q ) ≡ true
lemma8 = found finab (case2 q) ( bool-and-tt nqt fb )
acceptB (h ∷ t ) q nq nq=q fb = acceptB t (δ (automaton B) q h) (Nmoves NFA (CNFA-exist A B) nq h) (nmove (case2 q) nq nq=q h) fb
acceptA : (y z : List Σ) → (q : states A) → (nq : states A ∨ states B → Bool ) → (nq (case1 q) ≡ true)
→ ( accept (automaton A) q y ≡ true ) → ( accept (automaton B) (astart B) z ≡ true )
→ Naccept NFA (CNFA-exist A B) nq (y ++ z) ≡ true
acceptA [] [] q nq nqt fa fb = found finab (case1 q) (bool-and-tt nqt (bool-and-tt fa fb ))
acceptA [] (h ∷ z) q nq nq=q fa fb = acceptB z nextb (Nmoves NFA (CNFA-exist A B) nq h) lemma70 fb where
nextb : states B
nextb = δ (automaton B) (astart B) h
lemma70 : exists finab (λ qn → nq qn /\ Nδ NFA qn h (case2 nextb)) ≡ true
lemma70 = found finab (case1 q) ( bool-and-tt nq=q (bool-and-tt fa (lemma-nmove-ab (case2 (astart B)) h) ))
acceptA (h ∷ t) z q nq nq=q fa fb = acceptA t z (δ (automaton A) q h) (Nmoves NFA (CNFA-exist A B) nq h) (nmove (case1 q) nq nq=q h) fa fb
acceptAB : Split (contain A) (contain B) x
→ Naccept NFA (CNFA-exist A B) (equal? finab (case1 (astart A))) x ≡ true
acceptAB S = subst ( λ k → Naccept NFA (CNFA-exist A B) (equal? finab (case1 (astart A))) k ≡ true ) ( sp-concat S )
(acceptA (sp0 S) (sp1 S) (astart A) (equal? finab (case1 (astart A))) (equal?-refl finab) (prop0 S) (prop1 S) )
closed-in-concat→ : Concat (contain A) (contain B) x ≡ true → contain (M-Concat A B) x ≡ true
closed-in-concat→ concat with split→AB (contain A) (contain B) x concat
... | S = begin
accept (subset-construction (CNFA-exist A B) (Concat-NFA A B) ) (Concat-NFA-start A B ) x
≡⟨ ≡-Bool-func (subset-construction-lemma← (CNFA-exist A B) NFA (equal? finab (case1 (astart A))) x )
(subset-construction-lemma→ (CNFA-exist A B) NFA (equal? finab (case1 (astart A))) x ) ⟩
Naccept NFA (CNFA-exist A B) (equal? finab (case1 (astart A))) x
≡⟨ acceptAB S ⟩
true
∎ where open ≡-Reasoning
open Found
ab-case : (q : states A ∨ states B ) → (qa : states A ) → (x : List Σ ) → Set
ab-case (case1 qa') qa x = qa' ≡ qa
ab-case (case2 qb) qa x = ¬ ( accept (automaton B) qb x ≡ true )
contain-A : (x : List Σ) → (nq : states A ∨ states B → Bool ) → (fn : Naccept NFA (CNFA-exist A B) nq x ≡ true )
→ (qa : states A ) → ( (q : states A ∨ states B) → nq q ≡ true → ab-case q qa x )
→ split (accept (automaton A) qa ) (contain B) x ≡ true
contain-A [] nq fn qa cond with found← finab fn -- at this stage, A and B must be satisfied with [] (ab-case cond forces it)
... | S with found-q S | inspect found-q S | cond (found-q S) (bool-∧→tt-0 (found-p S))
... | case1 qa' | record { eq = refl } | refl = bool-∧→tt-1 (found-p S)
... | case2 qb | record { eq = refl } | ab = ⊥-elim ( ab (bool-∧→tt-1 (found-p S)))
contain-A (h ∷ t) nq fn qa cond with bool-≡-? ((aend (automaton A) qa) /\ accept (automaton B) (δ (automaton B) (astart B) h) t ) true
... | yes eq = bool-or-41 eq -- found A ++ B all end
... | no ne = bool-or-31 (contain-A t (Nmoves NFA (CNFA-exist A B) nq h) fn (δ (automaton A) qa h) lemma11 ) where -- B failed continue with ab-base condtion
--- prove ab-case condition (we haven't checked but case2 b may happen)
lemma11 : (q : states A ∨ states B) → exists finab (λ qn → nq qn /\ Nδ NFA qn h q) ≡ true → ab-case q (δ (automaton A) qa h) t
lemma11 (case1 qa') ex with found← finab ex
... | S with found-q S | inspect found-q S | cond (found-q S) (bool-∧→tt-0 (found-p S))
... | case1 qa | record { eq = refl } | refl = sym ( equal→refl (afin A) ( bool-∧→tt-1 (found-p S) )) -- continued A case
... | case2 qb | record { eq = refl } | nb with bool-∧→tt-1 (found-p S) -- δnfa (case2 q) i (case1 q₁) is false
... | ()
lemma11 (case2 qb) ex with found← finab ex
... | S with found-q S | inspect found-q S | cond (found-q S) (bool-∧→tt-0 (found-p S))
lemma11 (case2 qb) ex | S | case2 qb' | record { eq = refl } | nb = contra-position lemma13 nb where -- continued B case should fail
lemma13 : accept (automaton B) qb t ≡ true → accept (automaton B) qb' (h ∷ t) ≡ true
lemma13 fb = subst (λ k → accept (automaton B) k t ≡ true ) (sym (equal→refl (afin B) (bool-∧→tt-1 (found-p S)))) fb
lemma11 (case2 qb) ex | S | case1 qa | record { eq = refl } | refl with bool-∧→tt-1 (found-p S)
... | eee = contra-position lemma12 ne where -- starting B case should fail
lemma12 : accept (automaton B) qb t ≡ true → aend (automaton A) qa /\ accept (automaton B) (δ (automaton B) (astart B) h) t ≡ true
lemma12 fb = bool-and-tt (bool-∧→tt-0 eee) (subst ( λ k → accept (automaton B) k t ≡ true ) (equal→refl (afin B) (bool-∧→tt-1 eee) ) fb )
lemma10 : Naccept NFA (CNFA-exist A B) (equal? finab (case1 (astart A))) x ≡ true → split (contain A) (contain B) x ≡ true
lemma10 CC = contain-A x (Concat-NFA-start A B ) CC (astart A) lemma15 where
lemma15 : (q : states A ∨ states B) → Concat-NFA-start A B q ≡ true → ab-case q (astart A) x
lemma15 q nq=t with equal→refl finab nq=t
... | refl = refl
closed-in-concat← : contain (M-Concat A B) x ≡ true → Concat (contain A) (contain B) x ≡ true
closed-in-concat← C with subset-construction-lemma← (CNFA-exist A B) NFA (equal? finab (case1 (astart A))) x C
... | CC = lemma10 CC
| {
"alphanum_fraction": 0.5486637568,
"avg_line_length": 53.7407407407,
"ext": "agda",
"hexsha": "3b4ae7eef2f35ca6c5a763b540724eb72cd0f434",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/regular-concat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/regular-concat.agda",
"max_line_length": 161,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/regular-concat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5102,
"size": 13059
} |
open import Categories
open import Monads
module Monads.CatofAdj.InitAdj {a b}{C : Cat {a}{b} }(M : Monad C) where
open import Library
open import Functors
open import Naturals hiding (Iso; module Iso)
open import Adjunctions
open import Monads.CatofAdj M
open import Categories.Initial
open import Monads.Kleisli M
open import Monads.Kleisli.Functors M
open import Monads.Kleisli.Adjunction M
open import Adjunctions.Adj2Mon
open Cat
open Fun
open Monad M
open NatT
open Adj
lemX : R KlAdj ○ L KlAdj ≅ TFun M
lemX = FunctorEq _ _ refl refl
KlObj : Obj CatofAdj
KlObj = record {
D = Kl;
adj = KlAdj;
law = lemX;
ηlaw = refl;
bindlaw = λ{X}{Y}{f} →
cong bind
(stripsubst (Hom C X) f (fcong Y (cong OMap (sym lemX))))}
open ObjAdj
open import Isomorphism
open Iso
lemZ : {D : Cat {a}{b}}{F G G' : Fun C D} →
G ≅ G' → {α : NatT F G}{β : NatT F G'} → α ≅ β →
∀ {X} → cmp α {X} ≅ cmp β {X}
lemZ refl refl = refl
lemZ' : {D : Cat {a}{b}}{F F' G G' : Fun C D} →
F ≅ F' → G ≅ G' → {α : NatT F G}{β : NatT F' G'} → α ≅ β →
∀ {X} → cmp α {X} ≅ cmp β {X}
lemZ' refl refl refl = refl
lemfid : {D : Cat {a}{b}}(L : Fun C D)(R : Fun D C)(T : Fun C C)
(p : T ≅ R ○ L) (η : ∀ {X} → Hom C X (OMap T X))
(right : {X : Obj C}{Y : Obj D} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →
(left : {X : Obj C}{Y : Obj D} → Hom D (OMap L X) Y → Hom C X (OMap R Y)) →
(q : {X : Obj C}{Y : Obj D}(f : Hom D (OMap L X) Y) → right (left f) ≅ f) →
(r : {X : Obj C} → left (iden D {OMap L X}) ≅ η {X}) →
{X : Obj C} →
right (subst (Hom C X) (fcong X (cong OMap p)) η)
≅
iden D {OMap L X}
lemfid {D = D} L R .(R ○ L) refl η right left q r {X} =
trans (cong right (sym r)) (q (iden D))
lemfcomp : {D : Cat {a}{b}}(L : Fun C D)(R : Fun D C)(T : Fun C C)
(p : T ≅ R ○ L)
(bind : ∀{X Y} → Hom C X (OMap T Y) → Hom C (OMap T X) (OMap T Y)) →
(right : {X : Obj C} {Y : Obj D} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →
(q : {X Y : Obj C} {f : Hom C X (OMap T Y)} →
HMap R (right (subst (Hom C X) (fcong Y (cong OMap p)) f)) ≅ bind f) →
(r : {X X' : Obj C}{Y Y' : Obj D}
(f : Hom C X' X)(g : Hom D Y Y')
(h : Hom C X (OMap R Y)) →
right (comp C (HMap R g) (comp C h f))
≅
comp D g (comp D (right h) (HMap L f))) →
∀{X Y Z : Obj C} {f : Hom C Y (OMap T Z)} {g : Hom C X (OMap T Y)} →
right (subst (Hom C X) (fcong Z (cong OMap p)) (comp C (bind f) g))
≅
comp D (right (subst (Hom C Y) (fcong Z (cong OMap p)) f))
(right (subst (Hom C X) (fcong Y (cong OMap p)) g))
lemfcomp {D = D} L R .(R ○ L) refl bind right q r {X}{Y}{Z}{f}{g} =
trans (cong₂ (λ f g → right (comp C f g)) (sym (q {f = f})) (sym (idr C)))
(trans (r (iden C) (right f) g)
(cong (comp D (right f))
(trans (cong (comp D (right g)) (fid L)) (idr D))))
lemLlaw : {D : Cat {a}{b}}(L : Fun C D)(R : Fun D C)(T : Fun C C)
(p : T ≅ R ○ L) (η : ∀ {X} → Hom C X (OMap T X)) →
(right : {X : Obj C} {Y : Obj D} →
Hom C X (OMap R Y) → Hom D (OMap L X) Y) →
(left : {X : Obj C} {Y : Obj D} →
Hom D (OMap L X) Y → Hom C X (OMap R Y)) →
(q : {X : Obj C} {Y : Obj D} (f : Hom D (OMap L X) Y) →
right (left f) ≅ f) →
(r : {X : Obj C} → left (iden D {OMap L X}) ≅ η {X}) →
(t : {X X' : Obj C}{Y Y' : Obj D}
(f : Hom C X' X)(g : Hom D Y Y')
(h : Hom C X (OMap R Y)) →
right (comp C (HMap R g) (comp C h f))
≅
comp D g (comp D (right h) (HMap L f)) ) →
{X Y : Obj C} (f : Hom C X Y) →
right (subst (Hom C X) (fcong Y (cong OMap p)) (comp C η f))
≅
HMap L f
lemLlaw {D = D} L R .(R ○ L) refl η right left q r t {X}{Y} f =
trans (cong (λ g → right (comp C g f)) (sym r))
(trans (trans (trans (cong right
(trans (sym (idl C))
(cong (λ g → comp C g
(comp C (left (iden D)) f))
(sym (fid R)))))
(t f (iden D) (left (iden D))))
(cong (comp D (iden D))
(trans (cong (λ g → comp D g (HMap L f))
(q (iden D)))
(idl D))))
(idl D))
K' : (A : Obj CatofAdj) → Fun (D KlObj) (D A)
K' A = record {
OMap = OMap (L (adj A));
HMap =
λ {X} {Y} f →
right (adj A)
(subst (Hom C X) (fcong Y (cong OMap (sym (law A)))) f);
fid =
lemfid (L (adj A)) (R (adj A)) (TFun M) (sym (law A)) η
(right (adj A)) (left (adj A)) (lawa (adj A)) (ηlaw A);
fcomp =
lemfcomp (L (adj A))
(R (adj A))
(TFun M)
(sym (law A))
bind
(right (adj A))
(bindlaw A)
(natright (adj A)) }
Llaw' : (A : Obj CatofAdj) → K' A ○ L (adj KlObj) ≅ L (adj A)
Llaw' A = FunctorEq
_
_
refl
(iext λ _ → iext λ _ → ext $ lemLlaw
(L (adj A))
(R (adj A))
(TFun M)
(sym (law A))
η
(right (adj A))
(left (adj A))
(lawa (adj A))
(ηlaw A)
(natright (adj A)))
Rlaw' : (A : Obj CatofAdj) → R (adj KlObj) ≅ R (adj A) ○ K' A
Rlaw' A = FunctorEq
_
_
(cong OMap (sym (law A)))
(iext λ _ → iext λ _ → ext λ _ → sym (bindlaw A))
rightlaw' : (A : Obj CatofAdj) →
{X : Obj C} {Y : Obj (D KlObj)}
{f : Hom C X (OMap (R (adj KlObj)) Y)} →
HMap (K' A) (right (adj KlObj) f) ≅
right (adj A) (subst (Hom C X) (fcong Y (cong OMap (Rlaw' A))) f)
rightlaw' A {X}{Y}{f} =
cong (right (adj A))
(trans (stripsubst (Hom C X) f (fcong Y (cong OMap (sym (law A)))))
(sym (stripsubst (Hom C X) f (fcong Y (cong OMap (Rlaw' A))))))
KlHom : {A : Obj CatofAdj} → Hom CatofAdj KlObj A
KlHom {A} = record {
K = K' A;
Llaw = Llaw' A;
Rlaw = Rlaw' A;
rightlaw = rightlaw' A }
uniq : {X : Obj CatofAdj}{f : Hom CatofAdj KlObj X} → KlHom ≅ f
uniq {X}{V} = HomAdjEq
_
_
(FunctorEq
_
_
(cong OMap (sym (HomAdj.Llaw V)))
(iext λ A → iext λ B → ext λ f →
trans (cong₂ (λ B₁ → right (adj X) {A} {B₁})
(sym (fcong B (cong OMap (HomAdj.Llaw V))))
(trans (stripsubst
(Hom C A)
f
(fcong B (cong OMap (sym (law X)))))
(sym (stripsubst
(Hom C A)
f
(fcong
B
(cong OMap (HomAdj.Rlaw V)))))))
(sym (HomAdj.rightlaw V))))
KlIsInit : Init CatofAdj KlObj
KlIsInit = record {
i = KlHom;
law = uniq}
-- -}
| {
"alphanum_fraction": 0.4080664294,
"avg_line_length": 35.9573459716,
"ext": "agda",
"hexsha": "cdb70496286120f0203b7a3d0f2a79440a83bdea",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Monads/CatofAdj/InitAdj.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Monads/CatofAdj/InitAdj.agda",
"max_line_length": 80,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Monads/CatofAdj/InitAdj.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 2727,
"size": 7587
} |
{-# OPTIONS --cubical --no-sized-types --no-guardedness #-}
module Issue2487.c where
postulate admit : {A : Set} -> A
| {
"alphanum_fraction": 0.6638655462,
"avg_line_length": 23.8,
"ext": "agda",
"hexsha": "9ef8ed45e9dee9a6865823106099eabb6d276ea9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2487/c.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2487/c.agda",
"max_line_length": 59,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2487/c.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 35,
"size": 119
} |
------------------------------------------------------------------------
-- Tactics for proving instances of Σ-cong (and Surjection.Σ-cong)
-- with "better" computational behaviour
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Tactic.Sigma-cong
{e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where
open Derived-definitions-and-properties eq
open import Logical-equivalence as L using (_⇔_)
open import Prelude
open import Bijection eq as B using (_↔_)
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq as F hiding (id; _∘_)
open import Monad eq
open import Surjection eq as S using (_↠_)
open import TC-monad eq hiding (Type)
private
variable
a b : Level
A B : Type a
f g k k₁ k₂ p q x y : A
P Q : A → Type p
------------------------------------------------------------------------
-- Σ-cong-refl
-- Building blocks used to construct the proofs in Σ-cong-refl.
record Σ-cong-refl-proofs
(k : Kind)
(A : Type a) (B : Type b) (P : A → Type p) (Q : B → Type q) :
Type (lsuc (a ⊔ b ⊔ p ⊔ q)) where
field
refl₁ : (x : Σ B Q) → x ≡ x
refl₂ : (x : Σ A P) → x ≡ x
cong-refl₃ :
(f : Σ A P → Σ B Q)
(p : Σ A P) →
cong f (refl p) ≡ refl (f p)
→↝ :
(A⇔B : A ⇔ B)
(P→Q : ∀ x → P x → Q (_⇔_.to A⇔B x))
(Q→P : ∀ x → Q x → P (_⇔_.from A⇔B x)) →
(eq₁ : (p : Σ B Q) →
Σ-map (_⇔_.to A⇔B) (P→Q _)
(Σ-map (_⇔_.from A⇔B) (Q→P _) p) ≡
p) →
(eq₂ : (p : Σ A P) →
Σ-map (_⇔_.from A⇔B) (Q→P _)
(Σ-map (_⇔_.to A⇔B) (P→Q _) p) ≡
p) →
((p : Σ A P) →
cong (Σ-map (_⇔_.to A⇔B) (P→Q _)) (eq₂ p) ≡
eq₁ (Σ-map (_⇔_.to A⇔B) (P→Q _) p)) →
Σ A P ↝[ k ] Σ B Q
instance
-- The building blocks can be proved.
instance-of-Σ-cong-refl-proofs :
Σ-cong-refl-proofs k A B P Q
instance-of-Σ-cong-refl-proofs = λ where
.refl₁ _ → refl _
.refl₂ _ → refl _
.cong-refl₃ _ _ → cong-refl _
.→↝ A⇔B P→Q Q→P p q r →
from-equivalence $
Eq.⟨ Σ-map (_⇔_.to A⇔B) (P→Q _)
, ( Σ-map (_⇔_.from A⇔B) (Q→P _)
, p
, q
, r
)
⟩
where
open Σ-cong-refl-proofs
private
-- Used to implement Σ-cong-refl.
--
-- The constructed term is returned.
Σ-cong-refl-tactic :
Σ-cong-refl-proofs k A B P Q →
(A⇔B : A ⇔ B) → (∀ x → P x ⇔ Q (_⇔_.to A⇔B x)) →
Term → TC Term
Σ-cong-refl-tactic proofs A⇔B P⇔Q goal = do
refl₁ ← quoteTC (Σ-cong-refl-proofs.refl₁ proofs)
refl₂ ← quoteTC (Σ-cong-refl-proofs.refl₂ proofs)
cong-refl₃ ← quoteTC (Σ-cong-refl-proofs.cong-refl₃ proofs
(Σ-map (_⇔_.to A⇔B) (_⇔_.to (P⇔Q _))))
proofs ← quoteTC proofs
P→Q ← quoteTC (_⇔_.to ∘ P⇔Q)
Q→P ← quoteTC (_⇔_.from ∘ P⇔Q ∘ _⇔_.from A⇔B)
A⇔B ← quoteTC A⇔B
let t = def (quote Σ-cong-refl-proofs.→↝)
(varg proofs ∷
varg A⇔B ∷
varg P→Q ∷
varg Q→P ∷
varg refl₁ ∷
varg refl₂ ∷
varg cong-refl₃ ∷
[])
unify goal t
return t
macro
-- A macro that tries to prove Σ A P ↝[ k₃ ] Σ B Q.
--
-- If k₃ is symmetric, then the two directions of the proof are
-- constructed in the following way:
--
-- * The forward direction is a function from Σ A P to Σ B Q,
-- constructed in the "obvious" way using the forward directions
-- of the two supplied proofs.
--
-- * The other direction is a function from Σ B (Q ∘ f ∘ g) to
-- Σ A P, where f and g are the two directions of the first proof.
-- This function is also constructed in the "obvious" way, using
-- the right-to-left directions of the two supplied proofs. It is
-- assumed that Q ∘ f ∘ g is definitionally equal to Q.
--
-- The two functions are assumed to be definitionally equal, so that
-- they can be proved to be inverses of each other (pointwise) using
-- reflexivity.
Σ-cong-refl :
{k₁ k₂ : Symmetric-kind} {k₃ : Kind}
⦃ proofs : Σ-cong-refl-proofs k₃ A B P Q ⦄ →
(A↝B : A ↝[ ⌊ k₁ ⌋-sym ] B) →
(∀ x → P x ↝[ ⌊ k₂ ⌋-sym ] Q (_⇔_.to (sym→⇔ A↝B) x)) →
Term → TC ⊤
Σ-cong-refl ⦃ proofs = proofs ⦄ A↝B P↝Q goal = do
Σ-cong-refl-tactic proofs (sym→⇔ A↝B) (sym→⇔ ∘ P↝Q) goal
return _
private
-- Some unit tests.
t₁ : (A × A) ≃ (A × A)
t₁ = Σ-cong-refl L.id λ _ → B.id
_ : _≃_.to t₁ p ≡ p
_ = refl _
_ : _≃_.from t₁ p ≡ p
_ = refl _
_ :
{p : A × A} →
_≃_.right-inverse-of t₁ p ≡ refl _
_ = refl _
_ :
{p : A × A} →
_≃_.left-inverse-of t₁ p ≡ refl _
_ = refl _
t₂ : (A × A) ↔ (A × A)
t₂ = Σ-cong-refl Eq.id λ _ → L.id
_ : _↔_.to t₂ p ≡ p
_ = refl _
_ : _↔_.from t₂ p ≡ p
_ = refl _
_ :
{p : A × A} →
_↔_.right-inverse-of t₂ p ≡ refl _
_ = refl _
_ :
{p : A × A} →
_↔_.left-inverse-of t₂ p ≡ refl _
_ = refl _
t₃ :
{P : A → B → Type p} {Q : A → B → (∀ x y → P x y) → Type q} →
(∃ λ (f : ∀ x y → P x y) → ∀ x y → Q x y f) ≃
(∃ λ (f : ∀ y x → P x y) → ∀ y x → Q x y (flip f))
t₃ = Σ-cong-refl Π-comm λ _ → Π-comm
_ : _≃_.to t₃ p ≡ Σ-map flip flip p
_ = refl _
_ : _≃_.from t₃ p ≡ Σ-map flip flip p
_ = refl _
_ :
{P : A → B → Type p} {Q : A → B → (∀ x y → P x y) → Type q}
{p : ∃ λ (f : ∀ y x → P x y) → ∀ y x → Q x y (flip f)} →
_≃_.right-inverse-of (t₃ {Q = Q}) p ≡ refl _
_ = refl _
_ :
{P : A → B → Type p} {Q : A → B → (∀ x y → P x y) → Type q}
{p : ∃ λ (f : ∀ x y → P x y) → ∀ x y → Q x y f} →
_≃_.left-inverse-of (t₃ {Q = Q}) p ≡ refl _
_ = refl _
-- The following proof—implemented using Σ-cong—is, at the time of
-- writing, "worse".
t₃′ :
{P : A → B → Type p} {Q : A → B → (∀ x y → P x y) → Type q} →
(∃ λ (f : ∀ x y → P x y) → ∀ x y → Q x y f) ≃
(∃ λ (f : ∀ y x → P x y) → ∀ y x → Q x y (flip f))
t₃′ = Eq.↔⇒≃ $ Σ-cong Π-comm λ _ → Π-comm
_ : _≃_.to t₃′ p ≡ Σ-map flip flip p
_ = refl _
_ :
∀ {P : A → B → Type p} {Q : A → B → (∀ x y → P x y) → Type q} {p} →
_≃_.from (t₃′ {Q = Q}) p ≡
Σ-map flip
(flip ∘ subst (λ f → ∀ y x → Q x y (flip f)) (sym (refl _)))
p
_ = refl _
------------------------------------------------------------------------
-- Σ-cong-id
-- Building blocks used to construct the proofs in Σ-cong-id.
record Σ-cong-id-proofs
(k : Kind) (A : Type a) (B : Type b) (P : B → Type p) :
Type (lsuc (a ⊔ b ⊔ p)) where
field
refl₁ : (x : Σ B P) → x ≡ x
subst-refl₂ :
(A≃B : A ≃ B)
((x , y) : Σ A (P ∘ _≃_.to A≃B)) →
subst P (refl (_≃_.to A≃B x)) y ≡ y
→↝ :
(A≃B : A ≃ B)
(g : ∀ x → P x → P (_≃_.to A≃B (_≃_.from A≃B x))) →
((p : Σ B P) →
Σ-map (_≃_.to A≃B) id (Σ-map (_≃_.from A≃B) (g _) p) ≡ p) →
(((x , y) : Σ A (P ∘ _≃_.to A≃B)) →
subst P (_≃_.right-inverse-of A≃B (_≃_.to A≃B x)) (g _ y) ≡ y) →
Σ A (P ∘ _≃_.to A≃B) ↝[ k ] Σ B P
instance
-- The building blocks can be proved.
instance-of-Σ-cong-id-proofs : Σ-cong-id-proofs k A B P
instance-of-Σ-cong-id-proofs {P = P} = λ where
.refl₁ → refl
.subst-refl₂ _ _ → subst-refl _ _
.→↝ A≃B g p q →
let open _≃_ A≃B in
from-equivalence $
Eq.↔→≃
(Σ-map to id)
(Σ-map from (g _))
p
(λ (x , y) →
Σ-≡,≡→≡ (left-inverse-of _)
(subst (P ∘ to) (left-inverse-of x) (g _ y) ≡⟨ subst-∘ _ _ _ ⟩
subst P (cong to (left-inverse-of x)) (g _ y) ≡⟨ cong (λ eq → subst P eq _) (left-right-lemma x) ⟩
subst P (right-inverse-of (to x)) (g _ y) ≡⟨ q _ ⟩∎
y ∎))
where
open Σ-cong-id-proofs
private
-- Used to implement Σ-cong-id.
--
-- The constructed term is returned.
Σ-cong-id-tactic :
Σ-cong-id-proofs k A B P →
A ≃ B → Term → TC Term
Σ-cong-id-tactic proofs A≃B goal = do
refl₁ ← quoteTC (Σ-cong-id-proofs.refl₁ proofs)
subst-refl₂ ← quoteTC (Σ-cong-id-proofs.subst-refl₂ proofs A≃B)
proofs ← quoteTC proofs
A≃B ← quoteTC A≃B
let t = def (quote Σ-cong-id-proofs.→↝)
(varg proofs ∷
varg A≃B ∷
varg (lam visible $ abs "_" $
lam visible $ abs "x" $
var 0 []) ∷
varg refl₁ ∷
varg subst-refl₂ ∷
[])
unify goal t
return t
macro
-- A macro that tries to prove
-- Σ A (P ∘ from-isomorphism eq) ↝[ k₂ ] Σ B P, given that there is
-- a proof eq : A ↔[ k₁ ] B for which the "right inverse of" proof
-- is definitionally equal to reflexivity. If k₂ is surjection,
-- bijection or equivalence, then the "right inverse of" component
-- of the resulting proof is reflexivity.
Σ-cong-id :
⦃ proofs : Σ-cong-id-proofs k₂ A B P ⦄ →
A ↔[ k₁ ] B → Term → TC ⊤
Σ-cong-id ⦃ proofs = proofs ⦄ A↝B goal = do
Σ-cong-id-tactic proofs (from-isomorphism A↝B) goal
return _
private
-- Some unit tests.
t₄ : (A × A) ↔ (A × A)
t₄ = Σ-cong-id B.id
_ : _↔_.to t₄ p ≡ p
_ = refl _
_ : _↔_.from t₄ p ≡ p
_ = refl _
_ :
{p : A × A} →
_↔_.right-inverse-of t₄ p ≡ refl _
_ = refl _
t₅ : (∃ λ (x : ⊥₀ ⊎ A) → _↔_.to ⊎-left-identity x ≡ y) ≃
(∃ λ (x : A) → x ≡ y)
t₅ = Σ-cong-id ⊎-left-identity
_ : _≃_.to t₅ (inj₂ x , p) ≡ (x , p)
_ = refl _
_ : _≃_.from t₅ p ≡ Σ-map inj₂ id p
_ = refl _
_ :
{p : ∃ λ (x : A) → x ≡ y} →
_≃_.right-inverse-of t₅ p ≡ refl _
_ = refl _
-- The following proof—implemented using Σ-cong—is, at the time of
-- writing, "worse".
t₅′ : (∃ λ (x : ⊥₀ ⊎ A) → _↔_.to ⊎-left-identity x ≡ y) ≃
(∃ λ (x : A) → x ≡ y)
t₅′ = Eq.↔⇒≃ $ Σ-cong ⊎-left-identity λ _ → F.id
_ : _≃_.to t₅′ (inj₂ x , p) ≡ (x , p)
_ = refl _
_ : _≃_.from t₅′ p ≡
Σ-map inj₂ (subst (_≡ y) (sym (refl _))) p
_ = refl _
------------------------------------------------------------------------
-- Σ-cong-id-↠
-- Building blocks used to construct the proofs in Σ-cong-id-↠.
record Σ-cong-id-↠-proofs
(A : Type a) (B : Type b) (P : B → Type p) :
Type (lsuc (a ⊔ b ⊔ p)) where
field
refl₁ : (x : Σ B P) → x ≡ x
→↠ :
(A↠B : A ↠ B)
(g : ∀ x → P x → P (_↠_.to A↠B (_↠_.from A↠B x))) →
((p : Σ B P) →
Σ-map (_↠_.to A↠B) id (Σ-map (_↠_.from A↠B) (g _) p) ≡ p) →
Σ A (P ∘ _↠_.to A↠B) ↠ Σ B P
instance
-- The building blocks can be proved.
instance-of-Σ-cong-id-↠-proofs : Σ-cong-id-↠-proofs A B P
instance-of-Σ-cong-id-↠-proofs {P = P} = λ where
.refl₁ → refl
.→↠ A↠B g p → record
{ logical-equivalence = record
{ to = Σ-map (_↠_.to A↠B) id
; from = Σ-map (_↠_.from A↠B) (g _)
}
; right-inverse-of = p
}
where
open Σ-cong-id-↠-proofs
private
-- Used to implement Σ-cong-id-↠.
--
-- The constructed term is returned.
Σ-cong-id-↠-tactic :
Σ-cong-id-↠-proofs A B P →
A ↠ B → Term → TC Term
Σ-cong-id-↠-tactic proofs A↠B goal = do
refl₁ ← quoteTC (Σ-cong-id-↠-proofs.refl₁ proofs)
proofs ← quoteTC proofs
A↠B ← quoteTC A↠B
let t = def (quote Σ-cong-id-↠-proofs.→↠)
(varg proofs ∷
varg A↠B ∷
varg (lam visible $ abs "_" $
lam visible $ abs "x" $
var 0 []) ∷
varg refl₁ ∷
[])
unify goal t
return t
macro
-- A macro that tries to prove Σ A (P ∘ _↠_.to eq) ↠ Σ B P, given a
-- proof eq for which _↠_.to eq ∘ _↠_.from eq is definitionally
-- equal to the identity function. The right-inverse-of component of
-- the resulting proof is reflexivity.
Σ-cong-id-↠ :
⦃ proofs : Σ-cong-id-↠-proofs A B P ⦄ →
A ↠ B → Term → TC ⊤
Σ-cong-id-↠ ⦃ proofs = proofs ⦄ A↠B goal = do
Σ-cong-id-↠-tactic proofs A↠B goal
return _
private
-- Some unit tests.
t₆ : (A × A) ↠ (A × A)
t₆ = Σ-cong-id-↠ S.id
_ : _↠_.to t₆ p ≡ p
_ = refl _
_ : _↠_.from t₆ p ≡ p
_ = refl _
_ :
{p : A × A} →
_↠_.right-inverse-of t₆ p ≡ refl _
_ = refl _
t₇ :
(∃ λ (f : (x : A ⊎ B) → P x) → (f ∘ inj₁ , f ∘ inj₂) ≡ q) ↠
(∃ λ (p : ((x : A) → P (inj₁ x)) ×
((y : B) → P (inj₂ y))) →
p ≡ q)
t₇ = Σ-cong-id-↠ Π⊎↠Π×Π
_ : _↠_.to t₇ (f , p) ≡ ((f ∘ inj₁ , f ∘ inj₂) , p)
_ = refl _
_ : _↠_.from t₇ ((f , g) , p) ≡ ([ f , g ] , p)
_ = refl _
_ :
∀ {P : A ⊎ B → Type p} {q}
{p : ∃ λ (p : ((x : A) → P (inj₁ x)) ×
((y : B) → P (inj₂ y))) →
p ≡ q} →
_↠_.right-inverse-of (t₇ {P = P}) p ≡ refl p
_ = refl _
-- The following proof—implemented using S.Σ-cong—is, at the time of
-- writing, "worse".
t₇′ :
(∃ λ (f : (x : A ⊎ B) → P x) → (f ∘ inj₁ , f ∘ inj₂) ≡ q) ↠
(∃ λ (p : ((x : A) → P (inj₁ x)) ×
((y : B) → P (inj₂ y))) →
p ≡ q)
t₇′ = S.Σ-cong Π⊎↠Π×Π λ _ → F.id
_ : _↠_.to t₇′ (f , p) ≡ ((f ∘ inj₁ , f ∘ inj₂) , p)
_ = refl _
_ : _↠_.from t₇′ ((f , g) , p) ≡
([ f , g ] , subst (_≡ q) (sym (refl _)) p)
_ = refl _
| {
"alphanum_fraction": 0.4577227433,
"avg_line_length": 27.0793650794,
"ext": "agda",
"hexsha": "e98d4d56901d3a57008fb01800c805f54cc7f92f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Tactic/Sigma-cong.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Tactic/Sigma-cong.agda",
"max_line_length": 115,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Tactic/Sigma-cong.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 5679,
"size": 13648
} |
module #3 where
open import Relation.Binary.PropositionalEquality
{-
Exercise 2.3 Give a fourth, different, proof of Lemma 2.1.2, and prove that it is equal to the others.
-}
based-ind₌ : ∀ {i} {A : Set i}{a : A} → (C : (x : A) → (a ≡ x) → Set i) → C a refl → {x : A} → (p : a ≡ x) → C x p
based-ind₌ C c p rewrite p = c
-- Uses based path induction
composite''' : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
composite''' {i} {A} {x}{y}{_} p = based-ind₌ D d where
D : (z : A) → (q : y ≡ z) → Set i
D z _ = x ≡ z
d : D _ refl
d = p
| {
"alphanum_fraction": 0.5222024867,
"avg_line_length": 28.15,
"ext": "agda",
"hexsha": "7e675a719523c15dfca7d24c77ec5c65280b77bf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Chapter2/#3.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Chapter2/#3.agda",
"max_line_length": 114,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Chapter2/#3.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 239,
"size": 563
} |
module plfa-code.Isomorphism where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; cong-app)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Properties using (+-comm)
_∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(g ∘ f) x = g (f x)
_∘′_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
g ∘′ f = λ x → g (f x)
postulate
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
_+′_ : ℕ → ℕ → ℕ
m +′ zero = m
m +′ suc n = suc (m +′ n)
same-app : ∀ (m n : ℕ) → m +′ n ≡ m + n
same-app m n rewrite +-comm m n = helper m n
where
helper : ∀ (m n : ℕ) → m +′ n ≡ n + m
helper m zero = refl
helper m (suc n) = cong suc (helper m n)
same : _+′_ ≡ _+_
same = extensionality (λ m → extensionality (λ n → same-app m n))
infix 0 _≃_
record _≃_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
-- equal to
data _≃′_ (A B : Set): Set where
mk-≃′ : ∀ (to : A → B) →
∀ (from : B → A) →
∀ (from∘to : (∀ (x : A) → from (to x) ≡ x)) →
∀ (to∘from : (∀ (y : B) → to (from y) ≡ y)) →
A ≃′ B
to′ : ∀ {A B : Set} → (A ≃′ B) → (A → B)
to′ (mk-≃′ f g g∘f f∘g) = f
from′ : ∀ {A B : Set} → (A ≃′ B) → (B → A)
from′ (mk-≃′ f g g∘f f∘g) = g
from∘to′ : ∀ {A B : Set} → (A≃B : A ≃′ B) → (∀ (x : A) → from′ A≃B (to′ A≃B x) ≡ x)
from∘to′ (mk-≃′ f g g∘f f∘g) = g∘f
to∘from′ : ∀ {A B : Set} → (A≃B : A ≃′ B) → (∀ (y : B) → to′ A≃B (from′ A≃B y) ≡ y)
to∘from′ (mk-≃′ f g g∘f f∘g) = f∘g
-- which means `field record` will take the field
≃-refl : ∀ {A : Set}
-----
→ A ≃ A
≃-refl =
record
{ to = λ{x → x}
; from = λ{y → y}
; from∘to = λ{x → refl}
; to∘from = λ{y → refl}
}
≃-sym : ∀ {A B : Set}
→ A ≃ B
-----
→ B ≃ A
≃-sym A≃B =
record
{ to = from A≃B
; from = to A≃B
; from∘to = to∘from A≃B
; to∘from = from∘to A≃B
}
≃-trans : ∀ {A B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
≃-trans A≃B B≃C =
record
{ to = to B≃C ∘ to A≃B
; from = from A≃B ∘ from B≃C
; from∘to = λ{x →
begin
(from A≃B ∘ from B≃C) ((to B≃C ∘ to A≃B) x)
≡⟨⟩
from A≃B (from B≃C (to B≃C (to A≃B x)))
≡⟨ cong (from A≃B) (from∘to B≃C (to A≃B x)) ⟩
from A≃B (to A≃B x)
≡⟨ from∘to A≃B x ⟩
x
∎
}
; to∘from = λ{y →
begin
(to B≃C ∘ to A≃B) ((from A≃B ∘ from B≃C) y)
≡⟨⟩
to B≃C (to A≃B (from A≃B (from B≃C y)))
≡⟨ cong (to B≃C) (to∘from A≃B (from B≃C y)) ⟩
to B≃C (from B≃C y)
≡⟨ to∘from B≃C y ⟩
y
∎}
}
module ≃-Reasoning where
infix 1 ≃-begin_
infixr 2 _≃⟨_⟩_
infix 3 _≃-∎
≃-begin_ : ∀ {A B : Set}
→ A ≃ B
-----
→ A ≃ B
≃-begin A≃B = A≃B
_≃⟨_⟩_ : ∀ (A : Set) {B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
A ≃⟨ A≃B ⟩ B≃C = ≃-trans A≃B B≃C
_≃-∎ : ∀ (A : Set)
-----
→ A ≃ A
A ≃-∎ = ≃-refl
open ≃-Reasoning
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
≲-refl : ∀ {A : Set} → A ≲ A
≲-refl =
record
{ to = λ{x → x}
; from = λ{y → y}
; from∘to = λ{x → refl}
}
≲-trans : ∀ {A B C : Set} → A ≲ B → B ≲ C → A ≲ C
≲-trans A≲B B≲C =
record
{ to = λ{x → to B≲C (to A≲B x)}
; from = λ{y → from A≲B (from B≲C y)}
; from∘to = λ{x →
begin
from A≲B (from B≲C (to B≲C (to A≲B x)))
≡⟨ cong (from A≲B) (from∘to B≲C (to A≲B x)) ⟩
from A≲B (to A≲B x)
≡⟨ from∘to A≲B x ⟩
x
∎}
}
≲-antisym : ∀ {A B : Set}
→ (A≲B : A ≲ B)
→ (B≲A : B ≲ A)
→ (to A≲B ≡ from B≲A)
→ (from A≲B ≡ to B≲A)
-------------------
→ A ≃ B
≲-antisym A≲B B≲A to≡from from≡to =
record
{ to = to A≲B
; from = from A≲B
; from∘to = from∘to A≲B
; to∘from = λ{y →
begin
to A≲B (from A≲B y)
≡⟨ cong (to A≲B) (cong-app from≡to y) ⟩
to A≲B (to B≲A y)
≡⟨ cong-app to≡from (to B≲A y) ⟩
from B≲A (to B≲A y)
≡⟨ from∘to B≲A y ⟩
y
∎
}
}
module ≲-Reasoning where
infix 1 ≲-begin_
infixr 2 _≲⟨_⟩_
infix 3 _≲-∎
≲-begin_ : ∀ {A B : Set}
→ A ≲ B
-----
→ A ≲ B
≲-begin A≲B = A≲B
_≲⟨_⟩_ : ∀ (A : Set) {B C : Set}
→ A ≲ B
→ B ≲ C
-----
→ A ≲ C
A ≲⟨ A≲B ⟩ B≲C = ≲-trans A≲B B≲C
_≲-∎ : ∀ (A : Set)
-----
→ A ≲ A
A ≲-∎ = ≲-refl
open ≲-Reasoning
---------- practice ----------
≃-implies-≲ : ∀ {A B : Set}
→ A ≃ B
-----
→ A ≲ B
≃-implies-≲ A≃B =
record
{ to = to A≃B
; from = from A≃B
; from∘to = from∘to A≃B
}
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
open _⇔_
⇔-refl : ∀ {A : Set} → A ⇔ A
⇔-refl = record { to = λ z → z ; from = λ z → z }
⇔-sym : ∀ {A B : Set} → A ⇔ B → B ⇔ A
⇔-sym A⇔B = record { to = from A⇔B ; from = to A⇔B }
⇔-trans : ∀ {A B C : Set} → A ⇔ B → B ⇔ C → A ⇔ C
⇔-trans A⇔B B⇔C =
record
{ to = to B⇔C ∘ to A⇔B
; from = from A⇔B ∘ from B⇔C
}
data Bin : Set where
nil : Bin
x0_ : Bin → Bin
x1_ : Bin → Bin
postulate
toB : ℕ → Bin
fromB : Bin → ℕ
from-to-const : ∀ (n : ℕ) → fromB (toB n) ≡ n
ℕ-embedding-Bin : ℕ ≲ Bin
ℕ-embedding-Bin =
record
{ to = toB
; from = fromB
; from∘to = from-to-const
}
| {
"alphanum_fraction": 0.4023932845,
"avg_line_length": 20.0681003584,
"ext": "agda",
"hexsha": "c23c3d3d881197bd7693ea7073d60d43b49e492b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "chirsz-ever/plfa-code",
"max_forks_repo_path": "src/plfa-code/Isomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "chirsz-ever/plfa-code",
"max_issues_repo_path": "src/plfa-code/Isomorphism.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "chirsz-ever/plfa-code",
"max_stars_repo_path": "src/plfa-code/Isomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2852,
"size": 5599
} |
module Base where
open import Relation.Binary.PropositionalEquality
is-prop : Set → Set
is-prop X = (x y : X) → x ≡ y
_∼_ : {A B : Set} → (f g : A → B) → Set
f ∼ g = ∀ a → f a ≡ g a
| {
"alphanum_fraction": 0.5675675676,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "4ee65ad59a3f73839779077a66fc5d4ab86bdcee",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "Base.agda",
"max_line_length": 49,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 74,
"size": 185
} |
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Free (Σ : Signature) where
open import Fragment.Algebra.Free.Base Σ public
open import Fragment.Algebra.Free.Properties Σ public
open import Fragment.Algebra.Free.Monad Σ public
open import Fragment.Algebra.Free.Evaluation Σ public
| {
"alphanum_fraction": 0.795389049,
"avg_line_length": 31.5454545455,
"ext": "agda",
"hexsha": "fea262977a22d293e17c7dd1d8fc80c7d2781892",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Algebra/Free.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Algebra/Free.agda",
"max_line_length": 53,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Algebra/Free.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 77,
"size": 347
} |
{-
Half adjoint equivalences ([HAEquiv])
- Iso to HAEquiv ([iso→HAEquiv])
- Equiv to HAEquiv ([equiv→HAEquiv])
- Cong is an equivalence ([congEquiv])
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.HAEquiv where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Nat
record isHAEquiv {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where
field
g : B → A
sec : ∀ a → g (f a) ≡ a
ret : ∀ b → f (g b) ≡ b
com : ∀ a → cong f (sec a) ≡ ret (f a)
-- from redtt's ha-equiv/symm
com-op : ∀ b → cong g (ret b) ≡ sec (g b)
com-op b j i = hcomp (λ k → λ { (i = i0) → sec (g b) (j ∧ (~ k))
; (j = i0) → g (ret b i)
; (j = i1) → sec (g b) (i ∨ (~ k))
; (i = i1) → g b })
(cap1 j i)
where cap0 : Square {- (i = i0) -} (λ j → f (sec (g b) j))
{- (j = i0) -} (λ i → f (g (ret b i)))
{- (j = i1) -} (λ i → ret b i)
{- (i = i1) -} (λ j → ret b j)
cap0 j i = hcomp (λ k → λ { (i = i0) → com (g b) (~ k) j
; (j = i0) → f (g (ret b i))
; (j = i1) → ret b i
; (i = i1) → ret b j })
(ret (ret b i) j)
filler : I → I → A
filler j i = hfill (λ k → λ { (i = i0) → g (ret b k)
; (i = i1) → g b })
(inS (sec (g b) i)) j
cap1 : Square {- (i = i0) -} (λ j → sec (g b) j)
{- (j = i0) -} (λ i → g (ret b i))
{- (j = i1) -} (λ i → g b)
{- (i = i1) -} (λ j → g b)
cap1 j i = hcomp (λ k → λ { (i = i0) → sec (sec (g b) j) k
; (j = i0) → sec (g (ret b i)) k
; (j = i1) → filler i k
; (i = i1) → filler j k })
(g (cap0 j i))
HAEquiv : ∀ {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ')
HAEquiv A B = Σ (A → B) λ f → isHAEquiv f
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
iso→HAEquiv : Iso A B → HAEquiv A B
iso→HAEquiv {A = A} {B = B} (iso f g ε η) = f , (record { g = g ; sec = η ; ret = ret ; com = com })
where
sides : ∀ b i j → Partial (~ i ∨ i) B
sides b i j = λ { (i = i0) → ε (f (g b)) j
; (i = i1) → ε b j }
bot : ∀ b i → B
bot b i = cong f (η (g b)) i
ret : (b : B) → f (g b) ≡ b
ret b i = hcomp (sides b i) (bot b i)
com : (a : A) → cong f (η a) ≡ ret (f a)
com a i j = hcomp (λ k → λ { (i = i0) → ε (f (η a j)) k
; (i = i1) → hfill (sides (f a) j) (inS (bot (f a) j)) k
; (j = i0) → ε (f (g (f a))) k
; (j = i1) → ε (f a) k})
(cong (cong f) (sym (Hfa≡fHa (λ x → g (f x)) η a)) i j)
equiv→HAEquiv : A ≃ B → HAEquiv A B
equiv→HAEquiv e = iso→HAEquiv (equivToIso e)
congEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {x y : A} (e : A ≃ B) → (x ≡ y) ≃ (e .fst x ≡ e .fst y)
congEquiv {A = A} {B} {x} {y} e = isoToEquiv (iso intro elim intro-elim elim-intro)
where
e' : HAEquiv A B
e' = equiv→HAEquiv e
f : A → B
f = e' .fst
g : B → A
g = isHAEquiv.g (e' .snd)
sec : ∀ a → g (f a) ≡ a
sec = isHAEquiv.sec (e' .snd)
ret : ∀ b → f (g b) ≡ b
ret = isHAEquiv.ret (e' .snd)
com : ∀ a → cong f (sec a) ≡ ret (f a)
com = isHAEquiv.com (e' .snd)
intro : x ≡ y → f x ≡ f y
intro = cong f
elim-sides : ∀ p i j → Partial (~ i ∨ i) A
elim-sides p i j = λ { (i = i0) → sec x j
; (i = i1) → sec y j }
elim-bot : ∀ p i → A
elim-bot p i = cong g p i
elim : f x ≡ f y → x ≡ y
elim p i = hcomp (elim-sides p i) (elim-bot p i)
intro-elim : ∀ p → intro (elim p) ≡ p
intro-elim p i j =
hcomp (λ k → λ { (i = i0) → f (hfill (elim-sides p j)
(inS (elim-bot p j)) k)
; (i = i1) → ret (p j) k
; (j = i0) → com x i k
; (j = i1) → com y i k })
(f (g (p j)))
elim-intro : ∀ p → elim (intro p) ≡ p
elim-intro p i j =
hcomp (λ k → λ { (i = i0) → hfill (λ l → λ { (j = i0) → secEq e x l
; (j = i1) → secEq e y l })
(inS (cong (λ z → g (f z)) p j)) k
; (i = i1) → p j
; (j = i0) → secEq e x (i ∨ k)
; (j = i1) → secEq e y (i ∨ k) })
(secEq e (p j) i)
| {
"alphanum_fraction": 0.3763100653,
"avg_line_length": 33.7133333333,
"ext": "agda",
"hexsha": "e9555f3853213a5814e76f716a15eceae116d51e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Foundations/HAEquiv.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Foundations/HAEquiv.agda",
"max_line_length": 103,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Foundations/HAEquiv.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1871,
"size": 5057
} |
module monad-instances where
open import lib
open import general-util
instance
IO-monad : monad IO
IO-monad = record {returnM = return; bindM = _>>=_}
instance
id-monad : monad id
id-monad = record {returnM = id; bindM = λ a f → f a}
| {
"alphanum_fraction": 0.6885245902,
"avg_line_length": 20.3333333333,
"ext": "agda",
"hexsha": "95532d3073165a88970c33c97def8dd13e309a89",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/monad-instances.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "xoltar/cedille",
"max_issues_repo_path": "src/monad-instances.agda",
"max_line_length": 55,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/monad-instances.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 79,
"size": 244
} |
{-# OPTIONS --cubical --safe #-}
module Relation.Nullary.Discrete where
open import Relation.Nullary.Discrete.Base public
| {
"alphanum_fraction": 0.7661290323,
"avg_line_length": 20.6666666667,
"ext": "agda",
"hexsha": "f0d86ea92880de6c6339e8054eed08d2113dceb7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Relation/Nullary/Discrete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Relation/Nullary/Discrete.agda",
"max_line_length": 49,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Relation/Nullary/Discrete.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 27,
"size": 124
} |
{-# OPTIONS --cubical-compatible #-}
module Issue712 where
data _≡_ {A : Set} : A → A → Set where
refl : (x : A) → x ≡ x
record _×_ (A B : Set) : Set where
field
p1 : A
p2 : B
open _×_
lemma : {A B : Set} {u v : A × B} (p : u ≡ v) → p1 u ≡ p1 v
lemma (refl _) = refl _
| {
"alphanum_fraction": 0.5157894737,
"avg_line_length": 17.8125,
"ext": "agda",
"hexsha": "6ea8be7ebbca341097ccedf5a39d827777c50f65",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue712.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue712.agda",
"max_line_length": 59,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue712.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 120,
"size": 285
} |
data ⊥ : Set where
_ : @0 ⊥ → Set
_ = λ @0 { () }
| {
"alphanum_fraction": 0.3921568627,
"avg_line_length": 10.2,
"ext": "agda",
"hexsha": "25ec6ce79d8298f2791553e41e73655552a187a6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue4525b.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue4525b.agda",
"max_line_length": 18,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4525b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 24,
"size": 51
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Zero-cost coercion to cross the FFI boundary
------------------------------------------------------------------------
{-# OPTIONS --without-K #-}
module Foreign.Haskell.Coerce where
------------------------------------------------------------------------
-- Motivation
-- Problem: No COMPILE directives for common inductive types
-- In order to guarantee that the vast majority of the libary is
-- considered safe by Agda, we had to remove the COMPILE pragmas
-- associated to common inductive types.
-- These directives cannot possibly be checked by the compiler and
-- the user could define unsound mappings (e.g. swapping Bool's
-- true and false).
-- Solution: Essentially identical definitions + zero-cost coercions
-- To solve this problem, we have introduced a number of essentially
-- identical definitions in the Foreign.Haskell.* modules. However
-- converting back and forth between the FFI-friendly type and its
-- safe counterpart would take linear time.
-- This module defines zero cost coercions between these types.
------------------------------------------------------------------------
-- Definition
open import Level using (Level; _⊔_)
open import Agda.Builtin.Nat
open import Agda.Builtin.Int
import IO.Primitive as STD
import Data.List.Base as STD
import Data.Maybe.Base as STD
import Data.Product as STD
import Data.Sum as STD
import Foreign.Haskell.Maybe as FFI
import Foreign.Haskell.Pair as FFI
import Foreign.Haskell.Either as FFI
private
variable
a b c d e f : Level
A : Set a
B : Set b
C : Set c
D : Set d
-- We define a simple indexed datatype `Coercible`. A value of `Coercible A B`
-- is a proof that ̀A` and `B` have the same underlying runtime representation.
-- The only possible proof is an incantation from the implementer begging to
-- be trusted.
-- We need this type to be concrete so that overlapping instances can be checked
-- for equality: we do not care what proof we get as long as we get one.
-- We need for it to be a data type rather than a record type so that Agda does
-- not mistakenly build arbitrary instances by η-expansion.
data Coercible (A : Set a) (B : Set b) : Set where
TrustMe : Coercible A B
{-# FOREIGN GHC data AgdaCoercible l1 l2 a b = TrustMe #-}
{-# COMPILE GHC Coercible = data AgdaCoercible (TrustMe) #-}
-- Once we get our hands on a proof that `Coercible A B` we postulate that it
-- is safe to convert an `A` into a `B`. This is done under the hood by using
-- `unsafeCoerce`.
postulate coerce : {{_ : Coercible A B}} → A → B
{-# FOREIGN GHC import Unsafe.Coerce #-}
{-# COMPILE GHC coerce = \ _ _ _ _ _ -> unsafeCoerce #-}
------------------------------------------------------------------------
-- Unary and binary variants for covariant type constructors
Coercible₁ : ∀ a c → (T : Set a → Set b) (U : Set c → Set d) → Set _
Coercible₁ _ _ T U = ∀ {A B} → {{_ : Coercible A B}} → Coercible (T A) (U B)
Coercible₂ : ∀ a b d e → (T : Set a → Set b → Set c) (U : Set d → Set e → Set f) → Set _
Coercible₂ _ _ _ _ T U = ∀ {A B} → {{_ : Coercible A B}} → Coercible₁ _ _ (T A) (U B)
------------------------------------------------------------------------
-- Instances
-- Nat
-- Our first instance reveals one of Agda's secrets: natural numbers are
-- represented by (arbitrary precision) integers at runtime! Note that we
-- may only coerce in one direction: arbitrary integers may actually be
-- negative and will not do as mere natural numbers.
instance
nat-toInt : Coercible Nat Int
nat-toInt = TrustMe
-- We then proceed to state that data types from the standard library
-- can be converted to their FFI equivalents which are bound to actual
-- Haskell types.
-- Maybe
maybe-toFFI : Coercible₁ a b STD.Maybe FFI.Maybe
maybe-toFFI = TrustMe
maybe-fromFFI : Coercible₁ a b FFI.Maybe STD.Maybe
maybe-fromFFI = TrustMe
-- Product
pair-toFFI : Coercible₂ a b c d STD._×_ FFI.Pair
pair-toFFI = TrustMe
pair-fromFFI : Coercible₂ a b c d FFI.Pair STD._×_
pair-fromFFI = TrustMe
-- Sum
either-toFFI : Coercible₂ a b c d STD._⊎_ FFI.Either
either-toFFI = TrustMe
either-fromFFI : Coercible₂ a b c d FFI.Either STD._⊎_
either-fromFFI = TrustMe
-- We follow up with purely structural rules for builtin data types which
-- already have known low-level representations.
-- List
coerce-list : Coercible₁ a b STD.List STD.List
coerce-list = TrustMe
-- IO
coerce-IO : Coercible₁ a b STD.IO STD.IO
coerce-IO = TrustMe
-- Function
-- Note that functions are contravariant in their domain.
coerce-fun : {{_ : Coercible A B}} → Coercible₁ c d (λ C → B → C) (λ D → A → D)
coerce-fun = TrustMe
-- Finally we add a reflexivity proof to discharge all the dangling constraints
-- involving type variables and concrete builtin types such as `Bool`.
-- This rule overlaps with the purely structural ones: when attempting to prove
-- `Coercible (List A) (List A)`, should Agda use the proof obtained by `coerce-refl`
-- or the one obtained by `coerce-list coerce-refl`? Because we are using a
-- datatype with a single constructor these distinctions do not matter: both proofs
-- are definitionally equal.
coerce-refl : Coercible A A
coerce-refl = TrustMe
| {
"alphanum_fraction": 0.6546883773,
"avg_line_length": 32.5792682927,
"ext": "agda",
"hexsha": "a2d883eb8fe1820b8b18e0a2fca1b395a6c0c3c2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Foreign/Haskell/Coerce.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Foreign/Haskell/Coerce.agda",
"max_line_length": 88,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Foreign/Haskell/Coerce.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1372,
"size": 5343
} |
------------------------------------------------------------------------------
-- The gcd program is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module proves the correctness of the gcd program using
-- the Euclid's algorithm.
module FOTC.Program.GCD.Total.CorrectnessProofI where
open import FOTC.Base
open import FOTC.Data.Nat.Type
open import FOTC.Program.GCD.Total.CommonDivisorI using ( gcdCD )
open import FOTC.Program.GCD.Total.Definitions using ( gcdSpec )
open import FOTC.Program.GCD.Total.DivisibleI using ( gcdDivisible )
open import FOTC.Program.GCD.Total.GCD using ( gcd )
------------------------------------------------------------------------------
-- The gcd is correct.
gcdCorrect : ∀ {m n} → N m → N n → gcdSpec m n (gcd m n)
gcdCorrect Nm Nn = gcdCD Nm Nn , gcdDivisible Nm Nn
| {
"alphanum_fraction": 0.5321637427,
"avg_line_length": 39.4615384615,
"ext": "agda",
"hexsha": "2ba5a26d610bd45dc4ebd24080e6adf1546e31ea",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/GCD/Total/CorrectnessProofI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/GCD/Total/CorrectnessProofI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/GCD/Total/CorrectnessProofI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 216,
"size": 1026
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Basic types related to coinduction
------------------------------------------------------------------------
module Coinduction where
import Level
------------------------------------------------------------------------
-- A type used to make recursive arguments coinductive
infix 1000 ♯_
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
------------------------------------------------------------------------
-- Rec, a type which is analogous to the Rec type constructor used in
-- ΠΣ (see Altenkirch, Danielsson, Löh and Oury. ΠΣ: Dependent Types
-- without the Sugar. FLOPS 2010, LNCS 6009.)
data Rec {a} (A : ∞ (Set a)) : Set a where
fold : (x : ♭ A) → Rec A
unfold : ∀ {a} {A : ∞ (Set a)} → Rec A → ♭ A
unfold (fold x) = x
{-
-- If --guardedness-preserving-type-constructors is enabled one can
-- define types like ℕ by recursion:
open import Data.Sum
open import Data.Unit
ℕ : Set
ℕ = ⊤ ⊎ Rec (♯ ℕ)
zero : ℕ
zero = inj₁ _
suc : ℕ → ℕ
suc n = inj₂ (fold n)
ℕ-rec : (P : ℕ → Set) →
P zero →
(∀ n → P n → P (suc n)) →
∀ n → P n
ℕ-rec P z s (inj₁ _) = z
ℕ-rec P z s (inj₂ (fold n)) = s n (ℕ-rec P z s n)
-- This feature is very experimental, though: it may lead to
-- inconsistencies.
-}
| {
"alphanum_fraction": 0.4520547945,
"avg_line_length": 23.953125,
"ext": "agda",
"hexsha": "9587fbbb2ebef6203543a028ae70429f0a47f54b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Coinduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Coinduction.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Coinduction.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 466,
"size": 1533
} |
module tree-test where
open import tree
open import nat
open import bool
open import bool-to-string
open import list
test-tree = node 2 ( (leaf 3) :: (node 4 ( (leaf 5) :: (leaf 7) :: [] )) :: (leaf 6) :: (leaf 7) :: [])
perfect3 = perfect-binary-tree 3 tt
perfect3-string = 𝕋-to-string 𝔹-to-string perfect3 | {
"alphanum_fraction": 0.6655948553,
"avg_line_length": 23.9230769231,
"ext": "agda",
"hexsha": "31580d2c0771090906e797c1d5b353bebdf0d44a",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "tree-test.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "tree-test.agda",
"max_line_length": 103,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "tree-test.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 99,
"size": 311
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Bool
open import lib.types.Coproduct
open import lib.types.Paths
open import lib.types.Span
open import lib.types.Pushout
open import lib.types.Cofiber
open import lib.types.Sigma
open import lib.types.Wedge
module lib.types.Smash {i j} where
module _ (X : Ptd i) (Y : Ptd j) where
⊙∧-span : ⊙Span
⊙∧-span = ⊙span (X ⊙× Y) ⊙Bool (X ⊙⊔ Y)
(⊔-rec (_, pt Y) (pt X ,_) , idp)
(⊙⊔-fmap {Y = Y} ⊙cst ⊙cst)
∧-span : Span
∧-span = ⊙Span-to-Span ⊙∧-span
_∧_ = Pushout ∧-span
_⊙∧_ = ⊙Pushout ⊙∧-span
Smash = _∧_
⊙Smash = _⊙∧_
module _ {X : Ptd i} {Y : Ptd j} where
smin : de⊙ X → de⊙ Y → Smash X Y
smin x y = left (x , y)
smbasel : Smash X Y
smbasel = right true
smbaser : Smash X Y
smbaser = right false
smgluel : (x : de⊙ X) → smin x (pt Y) == smbasel
smgluel x = glue (inl x)
smgluer : (y : de⊙ Y) → smin (pt X) y == smbaser
smgluer y = glue (inr y)
module SmashElim {k} {P : Smash X Y → Type k}
(smin* : (x : de⊙ X) (y : de⊙ Y) → P (smin x y))
(smbasel* : P smbasel) (smbaser* : P smbaser)
(smgluel* : (x : de⊙ X) → smin* x (pt Y) == smbasel* [ P ↓ smgluel x ])
(smgluer* : (y : de⊙ Y) → smin* (pt X) y == smbaser* [ P ↓ smgluer y ]) where
private
module M = PushoutElim
(uncurry smin*)
(Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*))
(Coprod-elim smgluel* smgluer*)
f = M.f
smgluel-β = M.glue-β ∘ inl
smgluer-β = M.glue-β ∘ inr
Smash-elim = SmashElim.f
module SmashRec {k} {C : Type k}
(smin* : (x : de⊙ X) (y : de⊙ Y) → C)
(smbasel* smbaser* : C)
(smgluel* : (x : de⊙ X) → smin* x (pt Y) == smbasel*)
(smgluer* : (y : de⊙ Y) → smin* (pt X) y == smbaser*) where
private
module M = PushoutRec {d = ∧-span X Y}
(uncurry smin*)
(Coprod-rec (λ _ → smbasel*) (λ _ → smbaser*))
(Coprod-elim smgluel* smgluer*)
f = M.f
smgluel-β = M.glue-β ∘ inl
smgluer-β = M.glue-β ∘ inr
Smash-rec = SmashRec.f
| {
"alphanum_fraction": 0.5540475036,
"avg_line_length": 25.7875,
"ext": "agda",
"hexsha": "e62d598161bb7f06ed57438669f10c28b76958fb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Smash.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Smash.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Smash.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 895,
"size": 2063
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Structure where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
private
variable
ℓ ℓ' ℓ'' : Level
S : Type ℓ → Type ℓ'
-- A structure is a type-family S : Type ℓ → Type ℓ', i.e. for X : Type ℓ and s : S X,
-- the pair (X , s) : TypeWithStr ℓ S means that X is equipped with a S-structure, witnessed by s.
TypeWithStr : (ℓ : Level) (S : Type ℓ → Type ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ')
TypeWithStr ℓ S = Σ[ X ∈ Type ℓ ] S X
typ : TypeWithStr ℓ S → Type ℓ
typ = fst
str : (A : TypeWithStr ℓ S) → S (typ A)
str = snd
-- Alternative notation for typ
⟨_⟩ : TypeWithStr ℓ S → Type ℓ
⟨_⟩ = typ
-- An S-structure should have a notion of S-homomorphism, or rather S-isomorphism.
-- This will be implemented by a function ι : StrEquiv S ℓ'
-- that gives us for any two types with S-structure (X , s) and (Y , t) a family:
-- ι (X , s) (Y , t) : (X ≃ Y) → Type ℓ''
StrEquiv : (S : Type ℓ → Type ℓ'') (ℓ' : Level) → Type (ℓ-max (ℓ-suc (ℓ-max ℓ ℓ')) ℓ'')
StrEquiv {ℓ} S ℓ' = (A B : TypeWithStr ℓ S) → typ A ≃ typ B → Type ℓ'
-- An S-structure may instead be equipped with an action on equivalences, which will
-- induce a notion of S-homomorphism
EquivAction : (S : Type ℓ → Type ℓ'') → Type (ℓ-max (ℓ-suc ℓ) ℓ'')
EquivAction {ℓ} S = {X Y : Type ℓ} → X ≃ Y → S X ≃ S Y
EquivAction→StrEquiv : {S : Type ℓ → Type ℓ''}
→ EquivAction S → StrEquiv S ℓ''
EquivAction→StrEquiv α (X , s) (Y , t) e = equivFun (α e) s ≡ t
| {
"alphanum_fraction": 0.6254901961,
"avg_line_length": 34,
"ext": "agda",
"hexsha": "a770fba97034125fd41b0e29e8925117bd98f6eb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Foundations/Structure.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Foundations/Structure.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Foundations/Structure.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 592,
"size": 1530
} |
{-# OPTIONS --type-in-type #-}
open import Agda.Primitive
test : Set
test = Setω
| {
"alphanum_fraction": 0.6626506024,
"avg_line_length": 11.8571428571,
"ext": "agda",
"hexsha": "a13a7276b51490574be95051b83fdaba23d70c9e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3439.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3439.agda",
"max_line_length": 30,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3439.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 23,
"size": 83
} |
open import Oscar.Prelude
open import Oscar.Class
module Oscar.Class.Transitivity where
module Transitivity'
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
x y z
= ℭLASS (x ,, y ,, z ,, _∼_) (x ∼ y → y ∼ z → x ∼ z)
module Transitivity
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
where
class = ∀ {x y z} → Transitivity'.class _∼_ x y z
type = ∀ {x y z} → Transitivity'.type _∼_ x y z
method : ⦃ _ : class ⦄ → type
method {x = x} {y} {z} = Transitivity'.method _∼_ x y z
module _
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
where
transitivity = Transitivity.method _∼_
module _
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
⦃ _ : Transitivity.class _∼_ ⦄
where
transitivity[_] = λ {x y z} (x∼y : x ∼ y) (y∼z : y ∼ z) → Transitivity.method _∼_ x∼y y∼z
infixr 9 ∙[]-syntax
∙[]-syntax = transitivity[_]
syntax ∙[]-syntax _⊸_ f g = g ∙[ _⊸_ ] f
module FlipTransitivity
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
where
class = Transitivity.class _∼_
type = ∀ {x y z} → y ∼ z → x ∼ y → x ∼ z
method : ⦃ _ : class ⦄ → type
method = flip transitivity
module _
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
⦃ _ : Transitivity.class _∼_ ⦄
where
infixr 9 _∙_
_∙_ : ∀ {x y z} (y∼z : y ∼ z) (x∼y : x ∼ y) → x ∼ z
g ∙ f = transitivity f g
module _
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} {𝔓 : 𝔒 → Ø 𝔭}
where
open import Oscar.Data.Proposequality
≡̇-transitivity = transitivity[ Proposextensequality⟦ 𝔓 ⟧ ]
infixr 9 ≡̇-transitivity
syntax ≡̇-transitivity f g = g ≡̇-∙ f
infixr 9 ≡̇-transitivity-syntax
≡̇-transitivity-syntax = ≡̇-transitivity
syntax ≡̇-transitivity-syntax f g = g ⟨≡̇⟩ f
| {
"alphanum_fraction": 0.5464684015,
"avg_line_length": 22.7323943662,
"ext": "agda",
"hexsha": "9eac85757e1eb579a6b2a2ff2456e1ddbe5113e9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Transitivity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Transitivity.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Transitivity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 842,
"size": 1614
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Machine words
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Word where
------------------------------------------------------------------------
-- Re-export base definitions and decidability of equality
open import Data.Word.Base public
open import Data.Word.Properties using (_≈?_; _<?_; _≟_; _==_) public
| {
"alphanum_fraction": 0.3955375254,
"avg_line_length": 30.8125,
"ext": "agda",
"hexsha": "4a55ddc35cfdb4c0755b77f9e95eb38eafcc20b7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Word.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Word.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Word.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 72,
"size": 493
} |
{-# OPTIONS --safe --without-K #-}
module Level where
open import Agda.Primitive
using (Level)
renaming ( _⊔_ to _ℓ⊔_
; lzero to ℓzero
; lsuc to ℓsuc
; Set to Type
)
public
variable
a b c : Level
A : Type a
B : Type b
C : Type c
| {
"alphanum_fraction": 0.5238095238,
"avg_line_length": 15.4736842105,
"ext": "agda",
"hexsha": "751fc1428a2bdab88fc983bca6df004049e04dab",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Level.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Level.agda",
"max_line_length": 34,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Level.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 101,
"size": 294
} |
module negation where
open import level
open import empty
----------------------------------------------------------------------
-- syntax
----------------------------------------------------------------------
infix 7 ¬
----------------------------------------------------------------------
-- defined types
----------------------------------------------------------------------
¬ : ∀{ℓ}(x : Set ℓ) → Set ℓ
¬ {ℓ} x = x → (⊥ {ℓ})
| {
"alphanum_fraction": 0.2,
"avg_line_length": 22.8947368421,
"ext": "agda",
"hexsha": "524ffe052e9c73a3e79c828dd1131a61d78b350f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "negation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "negation.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "negation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 67,
"size": 435
} |
{-# OPTIONS --without-K #-}
module hott.loop.properties where
open import sum
open import equality
open import function.core
open import function.extensionality
open import function.isomorphism.core
open import function.overloading
open import pointed
open import sets.nat.core
open import hott.loop.core
mapΩ₁-const : ∀ {i j}{𝓧 : PSet i}{𝓨 : PSet j}
→ mapΩ₁ (constP 𝓧 𝓨) ≡ constP _ _
mapΩ₁-const = apply≅ pmap-eq (ap-const _ , refl)
where
ap-const : ∀ {i j}{X : Set i}{Y : Set j}(y : Y)
→ {x x' : X}(p : x ≡ x') → ap (λ _ → y) p ≡ refl
ap-const y refl = refl
mapΩP-const : ∀ {i j} n → {𝓧 : PSet i}{𝓨 : PSet j}
→ mapΩP n (constP 𝓧 𝓨) ≡ constP _ _
mapΩP-const zero = refl
mapΩP-const (suc n) = ap (mapΩP n) mapΩ₁-const · mapΩP-const n
mapΩ-const : ∀ {i j} n → {X : Set i}{Y : Set j}(y : Y)
→ (x : X) (p : Ω n x)
→ mapΩ n (λ _ → y) p ≡ refl' n y
mapΩ-const n y x p = funext-inv (ap proj₁ (mapΩP-const n)) p
mapΩ₁-hom : ∀ {i j k}{𝓧 : PSet i}{𝓨 : PSet j}{𝓩 : PSet k}
→ (f : PMap 𝓧 𝓨)(g : PMap 𝓨 𝓩)
→ mapΩ₁ g ∘ mapΩ₁ f ≡ mapΩ₁ (g ∘ f)
mapΩ₁-hom (f , refl) (g , refl) = apply≅ pmap-eq (ap-hom f g , refl)
mapΩP-hom : ∀ {i j k} n → {𝓧 : PSet i}{𝓨 : PSet j}{𝓩 : PSet k}
→ (f : PMap 𝓧 𝓨)(g : PMap 𝓨 𝓩)
→ mapΩP n g ∘ mapΩP n f ≡ mapΩP n (g ∘ f)
mapΩP-hom zero f g = refl
mapΩP-hom (suc n) f g = mapΩP-hom n (mapΩ₁ f) (mapΩ₁ g)
· ap (mapΩP n) (mapΩ₁-hom f g)
mapΩ-hom : ∀ {i j k} n {X : Set i}{Y : Set j}{Z : Set k}
→ (f : X → Y)(g : Y → Z){x : X}(p : Ω n x)
→ mapΩ n g (mapΩ n f p) ≡ mapΩ n (g ∘ f) p
mapΩ-hom n f g = proj₁ (invert≅ pmap-eq (mapΩP-hom n (f , refl) (g , refl)))
mapΩ-refl : ∀ {i j} n {X : Set i}{Y : Set j}
→ (f : X → Y){x : X}
→ mapΩ n f (refl' n x) ≡ refl' n (f x)
mapΩ-refl n f = proj₂ (mapΩP n (f , refl))
| {
"alphanum_fraction": 0.5261489699,
"avg_line_length": 35.7169811321,
"ext": "agda",
"hexsha": "b85f8fb45d6267fe0a6fd4c0ff373119435faa9d",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/hott/loop/properties.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/hott/loop/properties.agda",
"max_line_length": 76,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/hott/loop/properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 872,
"size": 1893
} |
------------------------------------------------------------------------
-- Containers, including a definition of bag equivalence
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Container {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (id; List)
open import Bag-equivalence eq using (Kind); open Kind
open import Bijection eq as Bijection using (_↔_; module _↔_)
open import Equivalence eq as Eq
using (Is-equivalence; _≃_; ⟨_,_⟩; module _≃_)
open import Function-universe eq as Function-universe
hiding (inverse; Kind) renaming (_∘_ to _⟨∘⟩_)
open import H-level eq
open import H-level.Closure eq
open import Surjection eq using (module _↠_)
------------------------------------------------------------------------
-- Containers
record Container c : Type (lsuc c) where
constructor _▷_
field
Shape : Type c
Position : Shape → Type c
open Container public
-- Interpretation of containers.
⟦_⟧ : ∀ {c ℓ} → Container c → Type ℓ → Type _
⟦ S ▷ P ⟧ A = ∃ λ (s : S) → (P s → A)
------------------------------------------------------------------------
-- Some projections
-- The shape of something.
shape : ∀ {a c} {A : Type a} {C : Container c} → ⟦ C ⟧ A → Shape C
shape = proj₁
-- Finds the value at the given position.
index : ∀ {a c} {A : Type a} {C : Container c}
(xs : ⟦ C ⟧ A) → Position C (shape xs) → A
index = proj₂
------------------------------------------------------------------------
-- Map
-- Containers are functors.
map : ∀ {c x y} {C : Container c} {X : Type x} {Y : Type y} →
(X → Y) → ⟦ C ⟧ X → ⟦ C ⟧ Y
map f = Σ-map id (f ∘_)
module Map where
identity : ∀ {c x} {C : Container c} {X : Type x}
(xs : ⟦ C ⟧ X) → map id xs ≡ xs
identity xs = refl _
composition :
∀ {c x y z}
{C : Container c} {X : Type x} {Y : Type y} {Z : Type z}
(f : Y → Z) (g : X → Y) (xs : ⟦ C ⟧ X) →
map f (map g xs) ≡ map (f ∘ g) xs
composition f g xs = refl _
-- Naturality.
Natural : ∀ {c₁ c₂ a} {C₁ : Container c₁} {C₂ : Container c₂} →
({A : Type a} → ⟦ C₁ ⟧ A → ⟦ C₂ ⟧ A) → Type (c₁ ⊔ c₂ ⊔ lsuc a)
Natural function =
∀ {A B} (f : A → B) xs →
map f (function xs) ≡ function (map f xs)
-- Natural transformations.
infixr 4 _[_]⟶_
record _[_]⟶_ {c₁ c₂} (C₁ : Container c₁) ℓ (C₂ : Container c₂) :
Type (c₁ ⊔ c₂ ⊔ lsuc ℓ) where
field
function : {A : Type ℓ} → ⟦ C₁ ⟧ A → ⟦ C₂ ⟧ A
natural : Natural function
-- Natural isomorphisms.
record _[_]↔_ {c₁ c₂} (C₁ : Container c₁) ℓ (C₂ : Container c₂) :
Type (c₁ ⊔ c₂ ⊔ lsuc ℓ) where
field
isomorphism : {A : Type ℓ} → ⟦ C₁ ⟧ A ↔ ⟦ C₂ ⟧ A
natural : Natural (_↔_.to isomorphism)
-- Natural isomorphisms are natural transformations.
natural-transformation : C₁ [ ℓ ]⟶ C₂
natural-transformation = record
{ function = _↔_.to isomorphism
; natural = natural
}
-- Natural isomorphisms can be inverted.
inverse : C₂ [ ℓ ]↔ C₁
inverse = record
{ isomorphism = Function-universe.inverse isomorphism
; natural = λ f xs →
map f (from xs) ≡⟨ sym $ left-inverse-of _ ⟩
from (to (map f (from xs))) ≡⟨ sym $ cong from $ natural f (from xs) ⟩
from (map f (to (from xs))) ≡⟨ cong (from ∘ map f) $ right-inverse-of _ ⟩∎
from (map f xs) ∎
}
where open module I {A : Type ℓ} = _↔_ (isomorphism {A = A})
open Function-universe using (inverse)
------------------------------------------------------------------------
-- Any, _∈_, bag equivalence and similar relations
-- Definition of Any for containers.
Any : ∀ {a c p} {A : Type a} {C : Container c} →
(A → Type p) → (⟦ C ⟧ A → Type (c ⊔ p))
Any {C = S ▷ P} Q (s , f) = ∃ λ (p : P s) → Q (f p)
-- Membership predicate.
infix 4 _∈_
_∈_ : ∀ {a c} {A : Type a} {C : Container c} → A → ⟦ C ⟧ A → Type _
x ∈ xs = Any (λ y → x ≡ y) xs
-- Bag equivalence etc. Note that the containers can be different as
-- long as the elements they contain have equal types.
infix 4 _∼[_]_
_∼[_]_ : ∀ {a c₁ c₂}
{A : Type a} {C₁ : Container c₁} {C₂ : Container c₂} →
⟦ C₁ ⟧ A → Kind → ⟦ C₂ ⟧ A → Type _
xs ∼[ k ] ys = ∀ z → z ∈ xs ↝[ k ] z ∈ ys
-- Bag equivalence.
infix 4 _≈-bag_
_≈-bag_ : ∀ {a c₁ c₂}
{A : Type a} {C₁ : Container c₁} {C₂ : Container c₂} →
⟦ C₁ ⟧ A → ⟦ C₂ ⟧ A → Type _
xs ≈-bag ys = xs ∼[ bag ] ys
------------------------------------------------------------------------
-- Various properties related to Any, _∈_ and _∼[_]_
-- Lemma relating Any to map.
Any-map : ∀ {a b c p} {A : Type a} {B : Type b} {C : Container c}
(P : B → Type p) (f : A → B) (xs : ⟦ C ⟧ A) →
Any P (map f xs) ↔ Any (P ∘ f) xs
Any-map P f xs = Any P (map f xs) □
-- Any can be expressed using _∈_.
Any-∈ : ∀ {a c p} {A : Type a} {C : Container c}
(P : A → Type p) (xs : ⟦ C ⟧ A) →
Any P xs ↔ ∃ λ x → P x × x ∈ xs
Any-∈ P (s , f) =
(∃ λ p → P (f p)) ↔⟨ ∃-cong (λ p → ∃-intro P (f p)) ⟩
(∃ λ p → ∃ λ x → P x × x ≡ f p) ↔⟨ ∃-comm ⟩
(∃ λ x → ∃ λ p → P x × x ≡ f p) ↔⟨ ∃-cong (λ _ → ∃-comm) ⟩
(∃ λ x → P x × ∃ λ p → x ≡ f p) □
-- Using this property we can prove that Any and _⊎_ commute.
Any-⊎ : ∀ {a c p q} {A : Type a} {C : Container c}
(P : A → Type p) (Q : A → Type q) (xs : ⟦ C ⟧ A) →
Any (λ x → P x ⊎ Q x) xs ↔ Any P xs ⊎ Any Q xs
Any-⊎ P Q xs =
Any (λ x → P x ⊎ Q x) xs ↔⟨ Any-∈ (λ x → P x ⊎ Q x) xs ⟩
(∃ λ x → (P x ⊎ Q x) × x ∈ xs) ↔⟨ ∃-cong (λ x → ×-⊎-distrib-right) ⟩
(∃ λ x → P x × x ∈ xs ⊎ Q x × x ∈ xs) ↔⟨ ∃-⊎-distrib-left ⟩
(∃ λ x → P x × x ∈ xs) ⊎ (∃ λ x → Q x × x ∈ xs) ↔⟨ inverse $ Any-∈ P xs ⊎-cong Any-∈ Q xs ⟩
Any P xs ⊎ Any Q xs □
-- Any preserves functions of various kinds and respects bag
-- equivalence and similar relations.
Any-cong : ∀ {k a c d p q}
{A : Type a} {C : Container c} {D : Container d}
(P : A → Type p) (Q : A → Type q)
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) →
(∀ x → P x ↝[ k ] Q x) → xs ∼[ k ] ys →
Any P xs ↝[ k ] Any Q ys
Any-cong P Q xs ys P↔Q xs∼ys =
Any P xs ↔⟨ Any-∈ P xs ⟩
(∃ λ z → P z × z ∈ xs) ↝⟨ ∃-cong (λ z → P↔Q z ×-cong xs∼ys z) ⟩
(∃ λ z → Q z × z ∈ ys) ↔⟨ inverse (Any-∈ Q ys) ⟩
Any Q ys □
-- Map preserves the relations.
map-cong :
∀ {k a b c d}
{A : Type a} {B : Type b} {C : Container c} {D : Container d}
(f : A → B)
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) →
xs ∼[ k ] ys → map f xs ∼[ k ] map f ys
map-cong f xs ys xs∼ys = λ z →
z ∈ map f xs ↔⟨ Any-map (_≡_ z) f xs ⟩
Any (λ x → z ≡ f x) xs ↝⟨ Any-cong _ _ xs ys (λ x → z ≡ f x □) xs∼ys ⟩
Any (λ x → z ≡ f x) ys ↔⟨ inverse (Any-map (_≡_ z) f ys) ⟩
z ∈ map f ys □
-- Lemma relating Any to if_then_else_.
Any-if : ∀ {a c p} {A : Type a} {C : Container c}
(P : A → Type p) (xs ys : ⟦ C ⟧ A) b →
Any P (if b then xs else ys) ↔
T b × Any P xs ⊎ T (not b) × Any P ys
Any-if P xs ys =
inverse ∘ if-lemma (λ b → Any P (if b then xs else ys)) id id
-- One can reconstruct (up to natural isomorphism) the shape set and
-- the position predicate from the interpretation and the Any
-- predicate transformer.
--
-- (The following lemmas were suggested by an anonymous reviewer.)
Shape′ : ∀ {c} → (Type → Type c) → Type c
Shape′ F = F ⊤
Shape-⟦⟧ : ∀ {c} (C : Container c) →
Shape C ↔ Shape′ ⟦ C ⟧
Shape-⟦⟧ C =
Shape C ↔⟨ inverse ×-right-identity ⟩
Shape C × ⊤ ↔⟨ ∃-cong (λ _ → inverse →-right-zero) ⟩
(∃ λ (s : Shape C) → Position C s → ⊤) □
Position′ : ∀ {c} (F : Type → Type c) →
({A : Type} → (A → Type) → (F A → Type c)) →
Shape′ F → Type c
Position′ _ Any = Any (λ (_ : ⊤) → ⊤)
Position-Any : ∀ {c} {C : Container c} (s : Shape C) →
Position C s ↔
Position′ ⟦ C ⟧ Any (_↔_.to (Shape-⟦⟧ C) s)
Position-Any {C = C} s =
Position C s ↔⟨ inverse ×-right-identity ⟩
Position C s × ⊤ □
expressed-in-terms-of-interpretation-and-Any :
∀ {c ℓ} (C : Container c) →
C [ ℓ ]↔ (⟦ C ⟧ ⊤ ▷ Any (λ _ → ⊤))
expressed-in-terms-of-interpretation-and-Any C = record
{ isomorphism = λ {A} →
(∃ λ (s : Shape C) → Position C s → A) ↔⟨ Σ-cong (Shape-⟦⟧ C) (λ _ → lemma) ⟩
(∃ λ (s : Shape′ ⟦ C ⟧) → Position′ ⟦ C ⟧ Any s → A) □
; natural = λ _ _ → refl _
}
where
-- If equality of functions had been extensional, then the following
-- lemma could have been replaced by a congruence lemma applied to
-- Position-Any.
lemma : ∀ {a b} {A : Type a} {B : Type b} → (B → A) ↔ (B × ⊤ → A)
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { f (p , tt) → f p }
; from = λ f p → f (p , tt)
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
------------------------------------------------------------------------
-- Alternative definition of bag equivalence
-- Two things are bag equivalent if there is a bijection (or
-- equivalence) between their positions that relates equal things.
infix 4 _≈[_]′_
_≈[_]′_ : ∀ {a c d} {A : Type a} {C : Container c} {D : Container d} →
⟦ C ⟧ A → Isomorphism-kind → ⟦ D ⟧ A → Type _
_≈[_]′_ {C = C} {D} (s , f) k (s′ , f′) =
∃ λ (P↔P : Position C s ↔[ k ] Position D s′) →
(∀ p → f p ≡ f′ (to-implication P↔P p))
-- If the position sets are sets (have H-level two), then the two
-- instantiations of _≈[_]′_ are isomorphic (assuming extensionality).
≈′↔≈′ : ∀ {a c d} {A : Type a} {C : Container c} {D : Container d} →
Extensionality (c ⊔ d) (c ⊔ d) →
(∀ s → Is-set (Position C s)) →
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) →
xs ≈[ bag ]′ ys ↔ xs ≈[ bag-with-equivalence ]′ ys
≈′↔≈′ ext P-set (s , f) (s′ , f′) =
(∃ λ P↔P → ∀ p → f p ≡ f′ (to-implication P↔P p)) ↔⟨ Σ-cong (Eq.↔↔≃ ext (P-set s)) (λ _ → Bijection.id) ⟩
(∃ λ P↔P → ∀ p → f p ≡ f′ (to-implication P↔P p)) □
-- The definition _≈[_]′_ is also logically equivalent to the one
-- given above. The proof is very similar to the one given in
-- Bag-equivalence.
-- Membership can be expressed as "there is an index which points to
-- the element". In fact, membership /is/ expressed in this way, so
-- this proof is unnecessary.
∈-index : ∀ {a c} {A : Type a} {C : Container c} {z}
(xs : ⟦ C ⟧ A) → z ∈ xs ↔ ∃ λ p → z ≡ index xs p
∈-index {z = z} xs = z ∈ xs □
-- The index which points to the element (not used below).
index-of : ∀ {a c} {A : Type a} {C : Container c} {z}
(xs : ⟦ C ⟧ A) → z ∈ xs → Position C (shape xs)
index-of xs = proj₁ ∘ to-implication (∈-index xs)
-- The positions for a given shape can be expressed in terms of the
-- membership predicate.
Position-shape :
∀ {a c} {A : Type a} {C : Container c} (xs : ⟦ C ⟧ A) →
(∃ λ z → z ∈ xs) ↔ Position C (shape xs)
Position-shape {C = C} (s , f) =
(∃ λ z → ∃ λ p → z ≡ f p) ↔⟨ ∃-comm ⟩
(∃ λ p → ∃ λ z → z ≡ f p) ↔⟨⟩
(∃ λ p → Singleton (f p)) ↔⟨ ∃-cong (λ _ → _⇔_.to contractible⇔↔⊤ (singleton-contractible _)) ⟩
Position C s × ⊤ ↔⟨ ×-right-identity ⟩
Position C s □
-- Position _ ∘ shape respects the various relations.
Position-shape-cong :
∀ {k a c d} {A : Type a} {C : Container c} {D : Container d}
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) →
xs ∼[ k ] ys → Position C (shape xs) ↝[ k ] Position D (shape ys)
Position-shape-cong {C = C} {D} xs ys xs∼ys =
Position C (shape xs) ↔⟨ inverse $ Position-shape xs ⟩
∃ (λ z → z ∈ xs) ↝⟨ ∃-cong xs∼ys ⟩
∃ (λ z → z ∈ ys) ↔⟨ Position-shape ys ⟩
Position D (shape ys) □
-- Furthermore Position-shape-cong relates equal elements.
Position-shape-cong-relates :
∀ {k a c d} {A : Type a} {C : Container c} {D : Container d}
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) (xs≈ys : xs ∼[ k ] ys) p →
index xs p ≡
index ys (to-implication (Position-shape-cong xs ys xs≈ys) p)
Position-shape-cong-relates {bag} xs ys xs≈ys p =
index xs p ≡⟨ proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _) ⟩
index ys (proj₁ $ to-implication (xs≈ys (index xs p))
(p , refl _)) ≡⟨⟩
index ys (_↔_.to (Position-shape ys) $
Σ-map id (λ {z} → to-implication (xs≈ys z)) $
_↔_.from (Position-shape xs) $ p) ≡⟨⟩
index ys (_↔_.to (Position-shape ys) $
to-implication (∃-cong xs≈ys) $
_↔_.from (Position-shape xs) $ p) ≡⟨⟩
index ys (to-implication
((from-bijection (Position-shape ys) ⟨∘⟩
∃-cong xs≈ys) ⟨∘⟩
from-bijection (inverse $ Position-shape xs))
p) ≡⟨⟩
index ys (to-implication (Position-shape-cong xs ys xs≈ys) p) ∎
Position-shape-cong-relates {bag-with-equivalence} xs ys xs≈ys p =
proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _)
Position-shape-cong-relates {bag-with-equivalenceᴱ} xs ys xs≈ys p =
proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _)
Position-shape-cong-relates {subbag} xs ys xs≈ys p =
proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _)
Position-shape-cong-relates {set} xs ys xs≈ys p =
proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _)
Position-shape-cong-relates {subset} xs ys xs≈ys p =
proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _)
Position-shape-cong-relates {embedding} xs ys xs≈ys p =
proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _)
Position-shape-cong-relates {surjection} xs ys xs≈ys p =
proj₂ $ to-implication (xs≈ys (index xs p)) (p , refl _)
-- We get that the two definitions of bag equivalence are logically
-- equivalent.
≈⇔≈′ : ∀ {k a c d} {A : Type a} {C : Container c} {D : Container d}
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) →
xs ∼[ ⌊ k ⌋-iso ] ys ⇔ xs ≈[ k ]′ ys
≈⇔≈′ {k} xs ys = record
{ to = λ xs≈ys → ( Position-shape-cong xs ys xs≈ys
, Position-shape-cong-relates xs ys xs≈ys
)
; from = from
}
where
from : xs ≈[ k ]′ ys → xs ∼[ ⌊ k ⌋-iso ] ys
from (P↔P , related) = λ z →
z ∈ xs ↔⟨⟩
∃ (λ p → z ≡ index xs p) ↔⟨ Σ-cong P↔P (λ p → _↠_.from (Π≡↔≡-↠-≡ k _ _) (related p) z) ⟩
∃ (λ p → z ≡ index ys p) ↔⟨⟩
z ∈ ys □
-- If equivalences are used, then the definitions are isomorphic
-- (assuming extensionality).
--
-- Thierry Coquand helped me with this proof: At first I wasn't sure
-- if it was true or not, but then I managed to prove it for singleton
-- lists, Thierry found a proof for lists of length two, I found one
-- for streams, and finally I could complete a proof of the statement
-- below.
≈↔≈′ : ∀ {a c d} {A : Type a} {C : Container c} {D : Container d} →
Extensionality (a ⊔ c ⊔ d) (a ⊔ c ⊔ d) →
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) →
xs ∼[ bag-with-equivalence ] ys ↔
xs ≈[ bag-with-equivalence ]′ ys
≈↔≈′ {a} {c} {d} {C = C} {D} ext xs ys = record
{ surjection = record
{ logical-equivalence = equiv
; right-inverse-of = λ { (⟨ f , f-eq ⟩ , related) →
let
P : (Position C (shape xs) → Position D (shape ys)) →
Type (a ⊔ c)
P f = ∀ p → index xs p ≡ index ys (f p)
f-eq′ : Is-equivalence f
f-eq′ = _
irr : f-eq′ ≡ f-eq
irr = proj₁ $ +⇒≡ $
Eq.propositional (lower-extensionality a a ext) f
f≡f : ⟨ f , f-eq′ ⟩ ≡ ⟨ f , f-eq ⟩
f≡f = cong (⟨_,_⟩ f) irr
cong-to-f≡f : cong _≃_.to f≡f ≡ refl f
cong-to-f≡f =
cong _≃_.to f≡f ≡⟨ cong-∘ _≃_.to (⟨_,_⟩ f) irr ⟩
cong (_≃_.to ∘ ⟨_,_⟩ f) irr ≡⟨ cong-const irr ⟩∎
refl _ ∎
in
Σ-≡,≡→≡ f≡f
(subst (P ∘ _≃_.to) f≡f (trans (refl _) ∘ related) ≡⟨ cong (subst (P ∘ _≃_.to) f≡f)
(apply-ext (lower-extensionality (a ⊔ d) (c ⊔ d) ext) λ _ → trans-reflˡ _) ⟩
subst (P ∘ _≃_.to) f≡f related ≡⟨ subst-∘ P _≃_.to f≡f ⟩
subst P (cong _≃_.to f≡f) related ≡⟨ cong (λ eq → subst P eq related) cong-to-f≡f ⟩
subst P (refl _) related ≡⟨ subst-refl P related ⟩∎
related ∎) }
}
; left-inverse-of = λ xs≈ys →
apply-ext (lower-extensionality (c ⊔ d) a ext) λ z →
Eq.lift-equality ext $
apply-ext (lower-extensionality d c ext) λ { (p , z≡xs[p]) →
let xs[p]≡ys[-] : ∃ λ p′ → index xs p ≡ index ys p′
xs[p]≡ys[-] = _≃_.to (xs≈ys (index xs p)) (p , refl _)
in
Σ-map id (trans z≡xs[p]) xs[p]≡ys[-] ≡⟨ elim₁ (λ {z} z≡xs[p] → Σ-map id (trans z≡xs[p]) xs[p]≡ys[-] ≡
_≃_.to (xs≈ys z) (p , z≡xs[p]))
(Σ-map id (trans (refl _)) xs[p]≡ys[-] ≡⟨ cong (_,_ _) (trans-reflˡ _) ⟩∎
xs[p]≡ys[-] ∎)
z≡xs[p] ⟩∎
_≃_.to (xs≈ys z) (p , z≡xs[p]) ∎ }
}
where
equiv = ≈⇔≈′ {k = equivalence} xs ys
open _⇔_ equiv
------------------------------------------------------------------------
-- Another alternative definition of bag equivalence
-- A higher-order variant of _∼[_]_. Note that this definition is
-- large (due to the quantification over predicates).
infix 4 _∼[_]″_
_∼[_]″_ : ∀ {a c d} {A : Type a} {C : Container c} {D : Container d} →
⟦ C ⟧ A → Kind → ⟦ D ⟧ A → Type (lsuc a ⊔ c ⊔ d)
_∼[_]″_ {a} {A = A} xs k ys =
(P : A → Type a) → Any P xs ↝[ k ] Any P ys
-- This definition is logically equivalent to _∼[_]_.
∼⇔∼″ : ∀ {k a c d} {A : Type a} {C : Container c} {D : Container d}
(xs : ⟦ C ⟧ A) (ys : ⟦ D ⟧ A) →
xs ∼[ k ] ys ⇔ xs ∼[ k ]″ ys
∼⇔∼″ xs ys = record
{ to = λ xs∼ys P → Any-cong P P xs ys (λ _ → id) xs∼ys
; from = λ Any-xs↝Any-ys z → Any-xs↝Any-ys (λ x → z ≡ x)
}
------------------------------------------------------------------------
-- The ⟦_⟧₂ operator
-- Lifts a family of binary relations from A to ⟦ C ⟧ A.
⟦_⟧₂ :
∀ {a c r} {A : Type a} (C : Container c) →
(A → A → Type r) →
⟦ C ⟧ A → ⟦ C ⟧ A → Type (c ⊔ r)
⟦ C ⟧₂ R (s , f) (t , g) =
∃ λ (eq : s ≡ t) →
(p : Position C s) →
R (f p) (g (subst (Position C) eq p))
where
open Container
-- A map function for ⟦_⟧₂.
⟦⟧₂-map :
∀ {a b c r s} {A : Type a} {B : Type b} {C : Container c}
(R : A → A → Type r) (S : B → B → Type s) (f : A → B) →
(∀ x y → R x y → S (f x) (f y)) →
(∀ x y → ⟦ C ⟧₂ R x y → ⟦ C ⟧₂ S (map f x) (map f y))
⟦⟧₂-map _ _ _ f _ _ = Σ-map id (f _ _ ∘_)
-- ⟦_⟧₂ preserves reflexivity.
⟦⟧₂-reflexive :
∀ {a c r} {A : Type a} {C : Container c}
(R : A → A → Type r) →
(∀ x → R x x) →
(∀ x → ⟦ C ⟧₂ R x x)
⟦⟧₂-reflexive {C = C} R r (xs , f) =
refl _
, λ p → $⟨ r _ ⟩
R (f p) (f p) ↝⟨ subst (R _ ∘ f) (sym $ subst-refl _ _) ⟩□
R (f p) (f (subst (Position C) (refl xs) p)) □
-- ⟦_⟧₂ preserves symmetry.
⟦⟧₂-symmetric :
∀ {a c r} {A : Type a} {C : Container c}
(R : A → A → Type r) →
(∀ {x y} → R x y → R y x) →
(∀ {x y} → ⟦ C ⟧₂ R x y → ⟦ C ⟧₂ R y x)
⟦⟧₂-symmetric {C = C} R r {_ , f} {_ , g} (eq , h) =
sym eq
, λ p → $⟨ h (subst (Position C) (sym eq) p) ⟩
R (f (subst (Position C) (sym eq) p))
(g (subst (Position C) eq (subst (Position C) (sym eq) p))) ↝⟨ subst (R (f (subst (Position C) (sym eq) p)) ∘ g) $ subst-subst-sym _ _ _ ⟩
R (f (subst (Position C) (sym eq) p)) (g p) ↝⟨ r ⟩□
R (g p) (f (subst (Position C) (sym eq) p)) □
-- ⟦_⟧₂ preserves transitivity.
⟦⟧₂-transitive :
∀ {a c r} {A : Type a} {C : Container c}
(R : A → A → Type r) →
(∀ {x y z} → R x y → R y z → R x z) →
(∀ {x y z} → ⟦ C ⟧₂ R x y → ⟦ C ⟧₂ R y z → ⟦ C ⟧₂ R x z)
⟦⟧₂-transitive {C = C}
R r {_ , f} {_ , g} {_ , h} (eq₁ , f₁) (eq₂ , f₂) =
trans eq₁ eq₂
, λ p → $⟨ f₂ _ ⟩
R (g (subst (Position C) eq₁ p))
(h (subst (Position C) eq₂ (subst (Position C) eq₁ p))) ↝⟨ subst (R (g (subst (Position C) _ _)) ∘ h) $ subst-subst _ _ _ _ ⟩
R (g (subst (Position C) eq₁ p))
(h (subst (Position C) (trans eq₁ eq₂) p)) ↝⟨ f₁ _ ,_ ⟩
R (f p) (g (subst (Position C) eq₁ p)) ×
R (g (subst (Position C) eq₁ p))
(h (subst (Position C) (trans eq₁ eq₂) p)) ↝⟨ uncurry r ⟩□
R (f p) (h (subst (Position C) (trans eq₁ eq₂) p)) □
| {
"alphanum_fraction": 0.4727699531,
"avg_line_length": 36.5979381443,
"ext": "agda",
"hexsha": "285e1d40166bd131d5449b85ca62f4f5a74f9a69",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Container.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Container.agda",
"max_line_length": 147,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Container.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 8035,
"size": 21300
} |
{-
Descriptor language for easily defining structures
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Structures.Macro where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.SIP
open import Cubical.Functions.FunExtEquiv
open import Cubical.Data.Sigma
open import Cubical.Data.Maybe
open import Cubical.Structures.Constant
open import Cubical.Structures.Maybe
open import Cubical.Structures.NAryOp
open import Cubical.Structures.Parameterized
open import Cubical.Structures.Pointed
open import Cubical.Structures.Product
open import Cubical.Structures.Functorial
data FuncDesc (ℓ : Level) : Typeω where
-- constant structure: X ↦ A
constant : ∀ {ℓ'} → Type ℓ' → FuncDesc ℓ
-- pointed structure: X ↦ X
var : FuncDesc ℓ
-- join of structures S,T : X ↦ (S X × T X)
_,_ : FuncDesc ℓ → FuncDesc ℓ → FuncDesc ℓ
-- structure S parameterized by constant A : X ↦ (A → S X)
param : ∀ {ℓ'} → (A : Type ℓ') → FuncDesc ℓ → FuncDesc ℓ
-- structure S parameterized by variable argument: X ↦ (X → S X)
maybe : FuncDesc ℓ → FuncDesc ℓ
data Desc (ℓ : Level) : Typeω where
-- constant structure: X ↦ A
constant : ∀ {ℓ'} → Type ℓ' → Desc ℓ
-- pointed structure: X ↦ X
var : Desc ℓ
-- join of structures S,T : X ↦ (S X × T X)
_,_ : Desc ℓ → Desc ℓ → Desc ℓ
-- structure S parameterized by constant A : X ↦ (A → S X)
param : ∀ {ℓ'} → (A : Type ℓ') → Desc ℓ → Desc ℓ
-- structure S parameterized by variable argument: X ↦ (X → S X)
recvar : Desc ℓ → Desc ℓ
-- Maybe on a structure S: X ↦ Maybe (S X)
maybe : Desc ℓ → Desc ℓ
-- SNS from functorial action
functorial : FuncDesc ℓ → Desc ℓ
-- arbitrary standard notion of structure
foreign : ∀ {ℓ' ℓ''} {S : Type ℓ → Type ℓ'} (ι : StrEquiv S ℓ'') → UnivalentStr S ι → Desc ℓ
infixr 4 _,_
{- Functorial structures -}
funcMacroLevel : ∀ {ℓ} → FuncDesc ℓ → Level
funcMacroLevel (constant {ℓ'} x) = ℓ'
funcMacroLevel {ℓ} var = ℓ
funcMacroLevel {ℓ} (d₀ , d₁) = ℓ-max (funcMacroLevel d₀) (funcMacroLevel d₁)
funcMacroLevel (param {ℓ'} A d) = ℓ-max ℓ' (funcMacroLevel d)
funcMacroLevel (maybe d) = funcMacroLevel d
-- Structure defined by a functorial descriptor
FuncMacroStructure : ∀ {ℓ} (d : FuncDesc ℓ) → Type ℓ → Type (funcMacroLevel d)
FuncMacroStructure (constant A) X = A
FuncMacroStructure var X = X
FuncMacroStructure (d₀ , d₁) X = FuncMacroStructure d₀ X × FuncMacroStructure d₁ X
FuncMacroStructure (param A d) X = A → FuncMacroStructure d X
FuncMacroStructure (maybe d) = MaybeStructure (FuncMacroStructure d)
-- Action defined by a functorial descriptor
funcMacroAction : ∀ {ℓ} (d : FuncDesc ℓ)
{X Y : Type ℓ} → (X → Y) → FuncMacroStructure d X → FuncMacroStructure d Y
funcMacroAction (constant A) _ = idfun A
funcMacroAction var f = f
funcMacroAction (d₀ , d₁) f (s₀ , s₁) = funcMacroAction d₀ f s₀ , funcMacroAction d₁ f s₁
funcMacroAction (param A d) f s a = funcMacroAction d f (s a)
funcMacroAction (maybe d) f = map-Maybe (funcMacroAction d f)
-- Proof that the action preserves the identity
funcMacroId : ∀ {ℓ} (d : FuncDesc ℓ)
{X : Type ℓ} → ∀ s → funcMacroAction d (idfun X) s ≡ s
funcMacroId (constant A) _ = refl
funcMacroId var _ = refl
funcMacroId (d₀ , d₁) (s₀ , s₁) = ΣPath≃PathΣ .fst (funcMacroId d₀ s₀ , funcMacroId d₁ s₁)
funcMacroId (param A d) s = funExt λ a → funcMacroId d (s a)
funcMacroId (maybe d) s = cong₂ map-Maybe (funExt (funcMacroId d)) refl ∙ map-Maybe-id s
{- General structures -}
macroStrLevel : ∀ {ℓ} → Desc ℓ → Level
macroStrLevel (constant {ℓ'} x) = ℓ'
macroStrLevel {ℓ} var = ℓ
macroStrLevel {ℓ} (d₀ , d₁) = ℓ-max (macroStrLevel d₀) (macroStrLevel d₁)
macroStrLevel (param {ℓ'} A d) = ℓ-max ℓ' (macroStrLevel d)
macroStrLevel {ℓ} (recvar d) = ℓ-max ℓ (macroStrLevel d)
macroStrLevel (maybe d) = macroStrLevel d
macroStrLevel (functorial d) = funcMacroLevel d
macroStrLevel (foreign {ℓ'} _ _) = ℓ'
macroEquivLevel : ∀ {ℓ} → Desc ℓ → Level
macroEquivLevel (constant {ℓ'} x) = ℓ'
macroEquivLevel {ℓ} var = ℓ
macroEquivLevel {ℓ} (d₀ , d₁) = ℓ-max (macroEquivLevel d₀) (macroEquivLevel d₁)
macroEquivLevel (param {ℓ'} A d) = ℓ-max ℓ' (macroEquivLevel d)
macroEquivLevel {ℓ} (recvar d) = ℓ-max ℓ (macroEquivLevel d)
macroEquivLevel (maybe d) = macroEquivLevel d
macroEquivLevel (functorial d) = funcMacroLevel d
macroEquivLevel (foreign {ℓ'' = ℓ''} _ _) = ℓ''
-- Structure defined by a descriptor
MacroStructure : ∀ {ℓ} (d : Desc ℓ) → Type ℓ → Type (macroStrLevel d)
MacroStructure (constant A) X = A
MacroStructure var X = X
MacroStructure (d₀ , d₁) X = MacroStructure d₀ X × MacroStructure d₁ X
MacroStructure (param A d) X = A → MacroStructure d X
MacroStructure (recvar d) X = X → MacroStructure d X
MacroStructure (maybe d) = MaybeStructure (MacroStructure d)
MacroStructure (functorial d) = FuncMacroStructure d
MacroStructure (foreign {S = S} _ _) = S
-- Notion of structured equivalence defined by a descriptor
MacroEquivStr : ∀ {ℓ} → (d : Desc ℓ) → StrEquiv {ℓ} (MacroStructure d) (macroEquivLevel d)
MacroEquivStr (constant A) = ConstantEquivStr A
MacroEquivStr var = PointedEquivStr
MacroEquivStr (d₀ , d₁) = ProductEquivStr (MacroEquivStr d₀) (MacroEquivStr d₁)
MacroEquivStr (param A d) = ParamEquivStr A λ _ → MacroEquivStr d
MacroEquivStr (recvar d) = UnaryFunEquivStr (MacroEquivStr d)
MacroEquivStr (maybe d) = MaybeEquivStr (MacroEquivStr d)
MacroEquivStr (functorial d) = FunctorialEquivStr (funcMacroAction d)
MacroEquivStr (foreign ι _) = ι
-- Proof that structure induced by descriptor is univalent
MacroUnivalentStr : ∀ {ℓ} → (d : Desc ℓ) → UnivalentStr (MacroStructure d) (MacroEquivStr d)
MacroUnivalentStr (constant A) = constantUnivalentStr A
MacroUnivalentStr var = pointedUnivalentStr
MacroUnivalentStr (d₀ , d₁) =
ProductUnivalentStr (MacroEquivStr d₀) (MacroUnivalentStr d₀) (MacroEquivStr d₁) (MacroUnivalentStr d₁)
MacroUnivalentStr (param A d) = ParamUnivalentStr A (λ _ → MacroEquivStr d) (λ _ → MacroUnivalentStr d)
MacroUnivalentStr (recvar d) = unaryFunUnivalentStr (MacroEquivStr d) (MacroUnivalentStr d)
MacroUnivalentStr (maybe d) = maybeUnivalentStr (MacroEquivStr d) (MacroUnivalentStr d)
MacroUnivalentStr (functorial d) = functorialUnivalentStr (funcMacroAction d) (funcMacroId d)
MacroUnivalentStr (foreign _ θ) = θ
-- Module for easy importing
module Macro ℓ (d : Desc ℓ) where
structure = MacroStructure d
equiv = MacroEquivStr d
univalent = MacroUnivalentStr d
| {
"alphanum_fraction": 0.7214667685,
"avg_line_length": 42.2258064516,
"ext": "agda",
"hexsha": "98695c81057006811476a25861bc1a6ddb43d7c4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Structures/Macro.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Structures/Macro.agda",
"max_line_length": 105,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Structures/Macro.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2213,
"size": 6545
} |
{-# OPTIONS --sized-types #-}
module SNat.Order where
open import Size
open import SNat
data _≤_ : {ι ι' : Size} → SNat {ι} → SNat {ι'} → Set where
z≤n : {ι ι' : Size}
→ (n : SNat {ι'})
→ _≤_ (zero {ι}) n
s≤s : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}}
→ m ≤ n
→ (succ m) ≤ (succ n)
data _≅_ : {ι ι' : Size} → SNat {ι} → SNat {ι'} → Set where
z≅z : {ι ι' : Size}
→ zero {ι} ≅ zero {ι'}
s≅s : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}}
→ m ≅ n
→ succ m ≅ succ n
data _≤′_ : {ι ι' : Size} → SNat {ι} → SNat {ι'} → Set where
≤′-eq : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}}
→ m ≅ n
→ m ≤′ n
≤′-step : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}}
→ m ≤′ n
→ m ≤′ succ n
| {
"alphanum_fraction": 0.3462389381,
"avg_line_length": 31.1724137931,
"ext": "agda",
"hexsha": "653609f43a358946ac44370a671ba888eb9cb663",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/SNat/Order.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/SNat/Order.agda",
"max_line_length": 60,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/SNat/Order.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 362,
"size": 904
} |
module Oscar.Data.List where
open import Agda.Builtin.List public using (List; []; _∷_)
| {
"alphanum_fraction": 0.7333333333,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "6440fe6a3c8ddcd9b69e8fcc6b5f1724f929e9c7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Data/List.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Data/List.agda",
"max_line_length": 58,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Data/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 24,
"size": 90
} |
module FinMap where
open import Level using () renaming (zero to ℓ₀)
open import Data.Nat using (ℕ ; zero ; suc)
open import Data.Maybe using (Maybe ; just ; nothing ; maybe′)
open import Data.Fin using (Fin ; zero ; suc)
open import Data.Fin.Properties using (_≟_)
open import Data.Vec using (Vec ; [] ; _∷_ ; _[_]≔_ ; replicate ; tabulate ; foldr ; zip ; toList) renaming (lookup to lookupVec ; map to mapV)
open import Data.Vec.Equality using ()
open import Data.Product using (_×_ ; _,_)
open import Data.List.All as All using (All)
import Data.List.All.Properties as AllP
import Data.List.Any as Any
open import Function using (id ; _∘_ ; flip ; const)
open import Function.Equality using (module Π)
open import Function.Surjection using (module Surjection)
open import Relation.Nullary using (yes ; no)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary.Core using (_≡_ ; refl ; _≢_ ; Decidable)
open import Relation.Binary.PropositionalEquality as P using (cong ; sym ; _≗_ ; trans ; cong₂)
open P.≡-Reasoning using (begin_ ; _≡⟨_⟩_ ; _∎)
open import Generic using (just-injective)
_∈_ : {A : Set} {n : ℕ} → A → Vec A n → Set
_∈_ {A} x xs = Any.Membership._∈_ (P.setoid A) x (toList xs)
_∉_ : {A : Set} {n : ℕ} → A → Vec A n → Set
_∉_ {A} x xs = All (_≢_ x) (toList xs)
data Dec∈ {A : Set} {n : ℕ} (x : A) (xs : Vec A n) : Set where
yes-∈ : x ∈ xs → Dec∈ x xs
no-∉ : x ∉ xs → Dec∈ x xs
is-∈ : {A : Set} {n : ℕ} → Decidable (_≡_ {A = A}) → (x : A) → (xs : Vec A n) → Dec∈ x xs
is-∈ eq? x xs with Any.any (eq? x) (toList xs)
... | yes x∈xs = yes-∈ x∈xs
... | no x∉xs = no-∉ (Π._⟨$⟩_ (Surjection.to AllP.¬Any↠All¬) x∉xs)
FinMapMaybe : ℕ → Set → Set
FinMapMaybe n A = Vec (Maybe A) n
lookupM : {A : Set} {n : ℕ} → Fin n → FinMapMaybe n A → Maybe A
lookupM = lookupVec
insert : {A : Set} {n : ℕ} → Fin n → A → FinMapMaybe n A → FinMapMaybe n A
insert f a m = m [ f ]≔ (just a)
empty : {A : Set} {n : ℕ} → FinMapMaybe n A
empty = replicate nothing
fromAscList : {A : Set} {n m : ℕ} → Vec (Fin n × A) m → FinMapMaybe n A
fromAscList [] = empty
fromAscList ((f , a) ∷ xs) = insert f a (fromAscList xs)
fromFunc : {A : Set} {n : ℕ} → (Fin n → A) → FinMapMaybe n A
fromFunc = tabulate ∘ _∘_ Maybe.just
reshape : {n : ℕ} {A : Set} → FinMapMaybe n A → (l : ℕ) → FinMapMaybe l A
reshape m zero = []
reshape [] (suc l) = nothing ∷ (reshape [] l)
reshape (x ∷ xs) (suc l) = x ∷ (reshape xs l)
union : {A : Set} {n : ℕ} → FinMapMaybe n A → FinMapMaybe n A → FinMapMaybe n A
union m1 m2 = tabulate (λ f → maybe′ just (lookupM f m2) (lookupM f m1))
restrict : {A : Set} {n m : ℕ} → (Fin n → A) → Vec (Fin n) m → FinMapMaybe n A
restrict f is = fromAscList (zip is (mapV f is))
delete : {A : Set} {n : ℕ} → Fin n → FinMapMaybe n A → FinMapMaybe n A
delete i m = m [ i ]≔ nothing
delete-many : {A : Set} {n m : ℕ} → Vec (Fin n) m → FinMapMaybe n A → FinMapMaybe n A
delete-many = flip (foldr (const _) delete)
lemma-insert-same : {n : ℕ} {A : Set} → (m : FinMapMaybe n A) → (f : Fin n) → {a : A} → lookupM f m ≡ just a → m ≡ insert f a m
lemma-insert-same [] () p
lemma-insert-same {suc n} (x ∷ xs) zero p = cong (flip _∷_ xs) p
lemma-insert-same (x ∷ xs) (suc i) p = cong (_∷_ x) (lemma-insert-same xs i p)
lemma-lookupM-empty : {A : Set} {n : ℕ} → (i : Fin n) → lookupM {A} i empty ≡ nothing
lemma-lookupM-empty zero = refl
lemma-lookupM-empty (suc i) = lemma-lookupM-empty i
lemma-lookupM-insert : {A : Set} {n : ℕ} → (i : Fin n) → (a : A) → (m : FinMapMaybe n A) → lookupM i (insert i a m) ≡ just a
lemma-lookupM-insert zero a (x ∷ xs) = refl
lemma-lookupM-insert (suc i) a (x ∷ xs) = lemma-lookupM-insert i a xs
lemma-lookupM-insert-other : {A : Set} {n : ℕ} → (i j : Fin n) → (a : A) → (m : FinMapMaybe n A) → i ≢ j → lookupM i (insert j a m) ≡ lookupM i m
lemma-lookupM-insert-other zero zero a m p = contradiction refl p
lemma-lookupM-insert-other zero (suc j) a (x ∷ xs) p = refl
lemma-lookupM-insert-other (suc i) zero a (x ∷ xs) p = refl
lemma-lookupM-insert-other (suc i) (suc j) a (x ∷ xs) p = lemma-lookupM-insert-other i j a xs (p ∘ cong suc)
lemma-lookupM-restrict : {A : Set} {n m : ℕ} → (i : Fin n) → (f : Fin n → A) → (is : Vec (Fin n) m) → {a : A} → lookupM i (restrict f is) ≡ just a → f i ≡ a
lemma-lookupM-restrict i f [] p = contradiction (trans (sym p) (lemma-lookupM-empty i)) (λ ())
lemma-lookupM-restrict i f (i' ∷ is) p with i ≟ i'
lemma-lookupM-restrict i f (.i ∷ is) {a} p | yes refl = just-injective (begin
just (f i)
≡⟨ sym (lemma-lookupM-insert i (f i) (restrict f is)) ⟩
lookupM i (insert i (f i) (restrict f is))
≡⟨ p ⟩
just a ∎)
lemma-lookupM-restrict i f (i' ∷ is) {a} p | no i≢i' = lemma-lookupM-restrict i f is (begin
lookupM i (restrict f is)
≡⟨ sym (lemma-lookupM-insert-other i i' (f i') (restrict f is) i≢i') ⟩
lookupM i (insert i' (f i') (restrict f is))
≡⟨ p ⟩
just a ∎)
lemma-lookupM-restrict-∈ : {A : Set} {n m : ℕ} → (i : Fin n) → (f : Fin n → A) → (js : Vec (Fin n) m) → i ∈ js → lookupM i (restrict f js) ≡ just (f i)
lemma-lookupM-restrict-∈ i f [] ()
lemma-lookupM-restrict-∈ i f (j ∷ js) p with i ≟ j
lemma-lookupM-restrict-∈ i f (.i ∷ js) p | yes refl = lemma-lookupM-insert i (f i) (restrict f js)
lemma-lookupM-restrict-∈ i f (j ∷ js) (Any.here i≡j) | no i≢j = contradiction i≡j i≢j
lemma-lookupM-restrict-∈ i f (j ∷ js) (Any.there p) | no i≢j =
trans (lemma-lookupM-insert-other i j (f j) (restrict f js) i≢j)
(lemma-lookupM-restrict-∈ i f js p)
lemma-lookupM-restrict-∉ : {A : Set} {n m : ℕ} → (i : Fin n) → (f : Fin n → A) → (js : Vec (Fin n) m) → i ∉ js → lookupM i (restrict f js) ≡ nothing
lemma-lookupM-restrict-∉ i f [] i∉[] = lemma-lookupM-empty i
lemma-lookupM-restrict-∉ i f (j ∷ js) i∉jjs =
trans (lemma-lookupM-insert-other i j (f j) (restrict f js) (All.head i∉jjs))
(lemma-lookupM-restrict-∉ i f js (All.tail i∉jjs))
lemma-tabulate-∘ : {n : ℕ} {A : Set} → {f g : Fin n → A} → f ≗ g → tabulate f ≡ tabulate g
lemma-tabulate-∘ {zero} {_} {f} {g} f≗g = refl
lemma-tabulate-∘ {suc n} {_} {f} {g} f≗g = cong₂ _∷_ (f≗g zero) (lemma-tabulate-∘ (f≗g ∘ suc))
lemma-lookupM-fromFunc : {n : ℕ} {A : Set} → (f : Fin n → A) → flip lookupM (fromFunc f) ≗ Maybe.just ∘ f
lemma-lookupM-fromFunc f zero = refl
lemma-lookupM-fromFunc f (suc i) = lemma-lookupM-fromFunc (f ∘ suc) i
lemma-lookupM-delete : {n : ℕ} {A : Set} {i j : Fin n} → (f : FinMapMaybe n A) → i ≢ j → lookupM i (delete j f) ≡ lookupM i f
lemma-lookupM-delete {i = zero} {j = zero} (_ ∷ _) p = contradiction refl p
lemma-lookupM-delete {i = zero} {j = suc j} (_ ∷ _) p = refl
lemma-lookupM-delete {i = suc i} {j = zero} (x ∷ xs) p = refl
lemma-lookupM-delete {i = suc i} {j = suc j} (x ∷ xs) p = lemma-lookupM-delete xs (p ∘ cong suc)
lemma-lookupM-delete-many : {n m : ℕ} {A : Set} (h : FinMapMaybe n A) → (i : Fin n) → (js : Vec (Fin n) m) → i ∉ js → lookupM i (delete-many js h) ≡ lookupM i h
lemma-lookupM-delete-many {n} h i [] i∉[] = refl
lemma-lookupM-delete-many {n} h i (j ∷ js) i∉jjs =
trans (lemma-lookupM-delete (delete-many js h) (All.head i∉jjs))
(lemma-lookupM-delete-many h i js (All.tail i∉jjs))
lemma-reshape-id : {n : ℕ} {A : Set} → (m : FinMapMaybe n A) → reshape m n ≡ m
lemma-reshape-id [] = refl
lemma-reshape-id (x ∷ xs) = cong (_∷_ x) (lemma-reshape-id xs)
lemma-disjoint-union : {n m : ℕ} {A : Set} → (f : Fin n → A) → (t : Vec (Fin n) m) → union (restrict f t) (delete-many t (fromFunc f)) ≡ fromFunc f
lemma-disjoint-union {n} f t = lemma-tabulate-∘ inner
where inner : (x : Fin n) → maybe′ just (lookupM x (delete-many t (fromFunc f))) (lookupM x (restrict f t)) ≡ just (f x)
inner x with is-∈ _≟_ x t
inner x | yes-∈ x∈t = cong (maybe′ just (lookupM x (delete-many t (fromFunc f)))) (lemma-lookupM-restrict-∈ x f t x∈t)
inner x | no-∉ x∉t = begin
maybe′ just (lookupM x (delete-many t (fromFunc f))) (lookupM x (restrict f t))
≡⟨ cong₂ (maybe′ just) (lemma-lookupM-delete-many (fromFunc f) x t x∉t) (lemma-lookupM-restrict-∉ x f t x∉t) ⟩
maybe′ just (lookupM x (fromFunc f)) nothing
≡⟨ lemma-lookupM-fromFunc f x ⟩
just (f x) ∎
lemma-exchange-maps : {n m : ℕ} → {A : Set} → {h h′ : FinMapMaybe n A} → {P : Fin n → Set} → (∀ j → P j → lookupM j h ≡ lookupM j h′) → {is : Vec (Fin n) m} → All P (toList is) → mapV (flip lookupM h) is ≡ mapV (flip lookupM h′) is
lemma-exchange-maps h≈h′ {[]} All.[] = refl
lemma-exchange-maps h≈h′ {i ∷ is} (pi All.∷ pis) = cong₂ _∷_ (h≈h′ i pi) (lemma-exchange-maps h≈h′ pis)
| {
"alphanum_fraction": 0.5938394595,
"avg_line_length": 53.25,
"ext": "agda",
"hexsha": "ca7e73b5c04cd8d5e1c15b79102aa5ce3e8106c8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jvoigtlaender/bidiragda",
"max_forks_repo_path": "FinMap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jvoigtlaender/bidiragda",
"max_issues_repo_path": "FinMap.agda",
"max_line_length": 231,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jvoigtlaender/bidiragda",
"max_stars_repo_path": "FinMap.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3403,
"size": 8733
} |
module HasDecidableValidation where
open import OscarPrelude
open import 𝓐ssertion
open import HasSatisfaction
open import Validation
record HasDecidableValidation (A : Set) ⦃ _ : HasSatisfaction A ⦄ : Set₁
where
field
⊨?_ : (x : A) → Dec $ ⊨ x
open HasDecidableValidation ⦃ … ⦄ public
| {
"alphanum_fraction": 0.7441077441,
"avg_line_length": 19.8,
"ext": "agda",
"hexsha": "fc0af738cc1351f8ec8f710844c6e9985fc0c9e9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/HasDecidableValidation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/HasDecidableValidation.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/HasDecidableValidation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 96,
"size": 297
} |
-- Andreas, 2015-06-29, issue reported by Nisse
-- {-# OPTIONS -v tc.polarity:20 -v tc.pos:10 #-}
-- {-# OPTIONS -v tc.conv.elim:25 --show-implicit #-}
data ⊥ : Set where
data _≡_ {a} {A : Set a} : A → A → Set a where
refl : ∀ x → x ≡ x
subst : ∀ {a p} {A : Set a} (P : A → Set p) {x y : A} →
x ≡ y → P x → P y
subst P (refl x) p = p
record _∼_ (A B : Set₁) : Set₁ where
field
to : A → B
from : B → A
right-inverse-of : ∀ x → x ≡ to (from x)
mutual
record R (c : ⊥) : Set₂ where
field
P : F c → Set₁
Q : {I J : F c} → S c I J → P I → P J → Set₁
Q′ : ∀ {I J} → S c I J → P I → P J → Set₁
Q′ s x y = subst P (_∼_.to (S∼≡ c) s) x ≡ y
field
Q∼Q′ : ∀ {I J} (s : S c I J) {x y} → Q s x y ∼ Q′ s x y
F : ⊥ → Set₁
F ()
S : (c : ⊥) → F c → F c → Set₁
S ()
S∼≡ : (c : ⊥) {I J : F c} → S c I J ∼ (I ≡ J)
S∼≡ ()
s : ∀ c I → S c I I
s c I = _∼_.from (S∼≡ c) (refl I)
q : ∀ c e I x → R.Q e (s c I) x x
q c e I x =
_∼_.from (R.Q∼Q′ e (s c I))
(subst (λ eq → subst (R.P e) eq x ≡ x)
(_∼_.right-inverse-of (S∼≡ c) (refl I))
(refl x))
-- ERROR WAS (due to faulty positivity analysis for projections):
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:770
| {
"alphanum_fraction": 0.4598117306,
"avg_line_length": 24.2280701754,
"ext": "agda",
"hexsha": "6f6b89aba6b18fde7859139bac580771bd9ae869",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1592.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1592.agda",
"max_line_length": 70,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1592.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 587,
"size": 1381
} |
Subsets and Splits