hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
109b3e6161052a90f8309a05d19fb391684bfe76
| 1,037
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Codata/Colist/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Codata/Colist/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Codata/Colist/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on the Colist type
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Colist.Properties where
open import Size
open import Codata.Thunk using (Thunk; force)
open import Codata.Conat
open import Codata.Colist
open import Codata.Colist.Bisimilarity
open import Function
open import Relation.Binary.PropositionalEquality as Eq
-- Functor laws
module _ {a} {A : Set a} where
map-identity : ∀ (as : Colist A ∞) {i} → i ⊢ map id as ≈ as
map-identity [] = []
map-identity (a ∷ as) = Eq.refl ∷ λ where .force → map-identity (as .force)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
map-map-fusion : ∀ (f : A → B) (g : B → C) as {i} → i ⊢ map g (map f as) ≈ map (g ∘ f) as
map-map-fusion f g [] = []
map-map-fusion f g (a ∷ as) = Eq.refl ∷ λ where .force → map-map-fusion f g (as .force)
| 31.424242
| 90
| 0.552555
|
c585c3f3719dd8ee046345859cece21b5bffda30
| 5,210
|
agda
|
Agda
|
prototyping/Luau/Type/FromJSON.agda
|
Tr4shh/Roblox-Luau
|
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
|
[
"MIT"
] | null | null | null |
prototyping/Luau/Type/FromJSON.agda
|
Tr4shh/Roblox-Luau
|
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
|
[
"MIT"
] | null | null | null |
prototyping/Luau/Type/FromJSON.agda
|
Tr4shh/Roblox-Luau
|
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
|
[
"MIT"
] | null | null | null |
module Luau.Type.FromJSON where
open import Luau.Type using (Type; nil; _⇒_; _∪_; _∩_; any; number)
open import Agda.Builtin.List using (List; _∷_; [])
open import FFI.Data.Aeson using (Value; Array; Object; object; array; string; fromString; lookup)
open import FFI.Data.Bool using (true; false)
open import FFI.Data.Either using (Either; Left; Right)
open import FFI.Data.Maybe using (Maybe; nothing; just)
open import FFI.Data.String using (String; _++_)
open import FFI.Data.Vector using (head; tail; null; empty)
name = fromString "name"
type = fromString "type"
argTypes = fromString "argTypes"
returnTypes = fromString "returnTypes"
types = fromString "types"
{-# TERMINATING #-}
typeFromJSON : Value → Either String Type
compoundFromArray : (Type → Type → Type) → Array → Either String Type
typeFromJSON (object o) with lookup type o
typeFromJSON (object o) | just (string "AstTypeFunction") with lookup argTypes o | lookup returnTypes o
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) with lookup types argsSet | lookup types retsSet
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just (array args) | just (array rets) with head args | head rets
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just (array args) | just (array rets) | just argValue | just retValue with typeFromJSON argValue | typeFromJSON retValue
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just (array args) | just (array rets) | just argValue | just retValue | Right arg | Right ret = Right (arg ⇒ ret)
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just (array args) | just (array rets) | just argValue | just retValue | Left err | _ = Left err
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just (array args) | just (array rets) | just argValue | just retValue | _ | Left err = Left err
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just (array args) | just (array rets) | _ | nothing = Left "No return type"
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just (array args) | just (array rets) | nothing | _ = Left "No argument type"
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | just _ | _ = Left "argTypes.types is not an array"
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | _ | just _ = Left "retTypes.types is not an array"
typeFromJSON (object o) | just (string "AstTypeFunction") | just (object argsSet) | just (object retsSet) | nothing | _ = Left "argTypes.types does not exist"
typeFromJSON (object o) | just (string "AstTypeFunction") | _ | just _ = Left "argTypes is not an object"
typeFromJSON (object o) | just (string "AstTypeFunction") | just _ | _ = Left "returnTypes is not an object"
typeFromJSON (object o) | just (string "AstTypeFunction") | nothing | nothing = Left "Missing argTypes and returnTypes"
typeFromJSON (object o) | just (string "AstTypeReference") with lookup name o
typeFromJSON (object o) | just (string "AstTypeReference") | just (string "nil") = Right nil
typeFromJSON (object o) | just (string "AstTypeReference") | just (string "any") = Right any
typeFromJSON (object o) | just (string "AstTypeReference") | just (string "number") = Right number
typeFromJSON (object o) | just (string "AstTypeReference") | _ = Left "Unknown referenced type"
typeFromJSON (object o) | just (string "AstTypeUnion") with lookup types o
typeFromJSON (object o) | just (string "AstTypeUnion") | just (array types) = compoundFromArray _∪_ types
typeFromJSON (object o) | just (string "AstTypeUnion") | _ = Left "`types` field must be an array"
typeFromJSON (object o) | just (string "AstTypeIntersection") with lookup types o
typeFromJSON (object o) | just (string "AstTypeIntersection") | just (array types) = compoundFromArray _∩_ types
typeFromJSON (object o) | just (string "AstTypeIntersection") | _ = Left "`types` field must be an array"
typeFromJSON (object o) | just (string ty) = Left ("Unsupported type " ++ ty)
typeFromJSON (object o) | just _ = Left "`type` field must be a string"
typeFromJSON (object o) | nothing = Left "No `type` field"
typeFromJSON _ = Left "Unsupported JSON type"
compoundFromArray ctor ts with head ts | tail ts
compoundFromArray ctor ts | just hd | tl with null tl
compoundFromArray ctor ts | just hd | tl | true = typeFromJSON hd
compoundFromArray ctor ts | just hd | tl | false with typeFromJSON hd | compoundFromArray ctor tl
compoundFromArray ctor ts | just hd | tl | false | Right hdTy | Right tlTy = Right (ctor hdTy tlTy)
compoundFromArray ctor ts | just hd | tl | false | Left err | _ = Left err
compoundFromArray ctor ts | just hd | tl | false | _ | Left Err = Left Err
compoundFromArray ctor ts | nothing | empty = Left "Empty types array?"
| 76.617647
| 228
| 0.726488
|
dcae8076b53e4a0e661b2b045820e1a4c09c0624
| 3,509
|
agda
|
Agda
|
FStream/FVec.agda
|
Aerate/condatis
|
64d95885579395f641e9a9cb1b9487cf79280446
|
[
"Unlicense"
] | 1
|
2019-12-13T16:52:28.000Z
|
2019-12-13T16:52:28.000Z
|
FStream/FVec.agda
|
zimbatm/condatis
|
64d95885579395f641e9a9cb1b9487cf79280446
|
[
"Unlicense"
] | 5
|
2017-06-03T20:02:22.000Z
|
2020-09-01T16:52:07.000Z
|
FStream/FVec.agda
|
zimbatm/condatis
|
64d95885579395f641e9a9cb1b9487cf79280446
|
[
"Unlicense"
] | 1
|
2019-12-13T15:56:38.000Z
|
2019-12-13T15:56:38.000Z
|
module FStream.FVec where
------------------------------------------------------------------------
-- Dissecting effectful streams
------------------------------------------------------------------------
open import Library
open import FStream.Core
open import Data.Fin
infixr 5 _▻_
infix 6 ⟨_▻⋯
infix 7 _⟩
data FVec {ℓ₁ ℓ₂} (C : Container ℓ₁) (A : Set ℓ₂) : (n : ℕ) → Set (ℓ₁ ⊔ ℓ₂) where
FNil : FVec C A 0
FCons : ∀ {n} → ⟦ C ⟧ (A × FVec C A n) → FVec C A (suc n)
-- TODO Syntactic sugar for these as well
data FVec' {ℓ₁ ℓ₂} (C : Container ℓ₁) (A : Set ℓ₂) : (n : ℕ) → Set (ℓ₁ ⊔ ℓ₂) where
FNil' : FVec' C A 0
FCons' : ∀ {n} → A → ⟦ C ⟧ (FVec' C A n) → FVec' C A (suc n)
_▻'_ : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →
A → ⟦ C ⟧ (FVec' C A n) → FVec' C A (suc n)
_▻'_ = FCons'
fVec'ToFVec : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →
FVec' C A n → FVec C A n
fVec'ToFVec FNil' = FNil
fVec'ToFVec (FCons' a v) = FCons (fmap (λ x → a , fVec'ToFVec x) v)
nest : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →
Vec (⟦ C ⟧ A) n → FVec C A n
nest [] = FNil
nest (a ∷ as) = FCons (fmap (_, nest as) a)
_▻_ : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →
⟦ C ⟧ A → (FVec C A n) → FVec C A (suc n)
a ▻ v = FCons (fmap (λ x → x , v) a)
_⟩ : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} → ⟦ C ⟧ A → FVec C A 1
a ⟩ = a ▻ FNil
mutual
vmap : ∀ {ℓ₁ ℓ₂ ℓ₃} {C : Container ℓ₁} {A : Set ℓ₂} {B : Set ℓ₃} {n} →
(f : A → B) → FVec C A n → FVec C B n
vmap _ FNil = FNil
vmap f (FCons x) = FCons (fmap (vmap' f) x)
vmap' : ∀ {ℓ₁ ℓ₂ ℓ₃} {C : Container ℓ₁} {A : Set ℓ₂} {B : Set ℓ₃} {n} →
(f : A → B) → A × FVec C A n → B × FVec C B n
vmap' f (a , v) = f a , vmap f v
mutual
take : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} →
(n : ℕ) → FStream C A → FVec C A n
take ℕ.zero as = FNil
take (ℕ.suc n) as = FCons (fmap (take' n) (inF as))
take' : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} →
(n : ℕ) → FStream' C A → A × FVec C A n
proj₁ (take' n as) = head as
proj₂ (take' n as) = take n (tail as)
take'' : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} →
(n : ℕ) → FStream' C A → FVec' C A n
take'' zero as = FNil'
take'' (suc n) as = FCons' (head as) (fmap (take'' n) (inF (tail as)))
_pre⟨_▻⋯' : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {m n}
→ FVec' C A m → FVec' C A (suc n) → FStream' {i} C A
head (FNil' pre⟨ FCons' a _ ▻⋯') = a
inF (tail (FNil' pre⟨ FCons' a v ▻⋯')) = fmap (_pre⟨ (FCons' a v) ▻⋯') v
head (FCons' x _ pre⟨ v' ▻⋯') = x
inF (tail (FCons' _ v pre⟨ v' ▻⋯')) = fmap (_pre⟨ v' ▻⋯') v
⟨_▻⋯' : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n : ℕ}
→ FVec' C A (suc n) → FStream' {i} C A
⟨ v ▻⋯' = FNil' pre⟨ v ▻⋯'
mutual
_pre⟨_▻⋯ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {m n}
→ FVec C A m → FVec C A (suc n) → FStream {i} C A
inF (FCons x pre⟨ keep ▻⋯) = fmap (_aux keep) x
inF (FNil pre⟨ FCons x ▻⋯) = fmap (_aux (FCons x)) x
_aux_ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n m : ℕ}
→ A × FVec C A m → FVec C A (suc n) → FStream' {i} C A
head ((a , _ ) aux v) = a
tail ((_ , v') aux v) = v' pre⟨ v ▻⋯
⟨_▻⋯ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n : ℕ}
→ FVec C A (suc n) → FStream {i} C A
⟨ as ▻⋯ = FNil pre⟨ as ▻⋯
data _[_]=_ {a} {A : Set a} {ℓ} {C : Container ℓ} : {n : ℕ} → FVec C A n → Fin n → ⟦ C ⟧ A → Set (a ⊔ ℓ) where
here : ∀ {n} {x : ⟦ C ⟧ A} {xs : FVec C A n} → (x ▻ xs) [ zero ]= x
there : ∀ {n} {k} {x y} {xs : FVec C A n} → xs [ k ]= x → (y ▻ xs) [ suc k ]= x
| 35.444444
| 110
| 0.476204
|
c50e2ba4ebea4f418d4b4c7c0d5932f613bf672a
| 1,639
|
agda
|
Agda
|
Cubical/HITs/InfNat/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/InfNat/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/InfNat/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.HITs.InfNat.Properties where
open import Cubical.Core.Everything
open import Cubical.Data.Maybe
open import Cubical.Data.Nat
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.InfNat.Base
import Cubical.Data.InfNat as Coprod
ℕ+∞→Cℕ+∞ : ℕ+∞ → Coprod.ℕ+∞
ℕ+∞→Cℕ+∞ zero = Coprod.zero
ℕ+∞→Cℕ+∞ (suc n) = Coprod.suc (ℕ+∞→Cℕ+∞ n)
ℕ+∞→Cℕ+∞ ∞ = Coprod.∞
ℕ+∞→Cℕ+∞ (suc-inf i) = Coprod.∞
ℕ→ℕ+∞ : ℕ → ℕ+∞
ℕ→ℕ+∞ zero = zero
ℕ→ℕ+∞ (suc n) = suc (ℕ→ℕ+∞ n)
Cℕ+∞→ℕ+∞ : Coprod.ℕ+∞ → ℕ+∞
Cℕ+∞→ℕ+∞ Coprod.∞ = ∞
Cℕ+∞→ℕ+∞ (Coprod.fin n) = ℕ→ℕ+∞ n
ℕ→ℕ+∞→Cℕ+∞ : ∀ n → ℕ+∞→Cℕ+∞ (ℕ→ℕ+∞ n) ≡ Coprod.fin n
ℕ→ℕ+∞→Cℕ+∞ zero = refl
ℕ→ℕ+∞→Cℕ+∞ (suc n) = cong Coprod.suc (ℕ→ℕ+∞→Cℕ+∞ n)
Cℕ+∞→ℕ+∞→Cℕ+∞ : ∀ n → ℕ+∞→Cℕ+∞ (Cℕ+∞→ℕ+∞ n) ≡ n
Cℕ+∞→ℕ+∞→Cℕ+∞ Coprod.∞ = refl
Cℕ+∞→ℕ+∞→Cℕ+∞ (Coprod.fin n) = ℕ→ℕ+∞→Cℕ+∞ n
suc-hom : ∀ n → Cℕ+∞→ℕ+∞ (Coprod.suc n) ≡ suc (Cℕ+∞→ℕ+∞ n)
suc-hom Coprod.∞ = suc-inf
suc-hom (Coprod.fin x) = refl
ℕ+∞→Cℕ+∞→ℕ+∞ : ∀ n → Cℕ+∞→ℕ+∞ (ℕ+∞→Cℕ+∞ n) ≡ n
ℕ+∞→Cℕ+∞→ℕ+∞ zero = refl
ℕ+∞→Cℕ+∞→ℕ+∞ ∞ = refl
ℕ+∞→Cℕ+∞→ℕ+∞ (suc n) = suc-hom (ℕ+∞→Cℕ+∞ n) ∙ cong suc (ℕ+∞→Cℕ+∞→ℕ+∞ n)
ℕ+∞→Cℕ+∞→ℕ+∞ (suc-inf i) = lemma i
where
lemma : (λ i → ∞ ≡ suc-inf i) [ refl ≡ suc-inf ∙ refl ]
lemma i j = hcomp (λ k → λ
{ (i = i0) → ∞
; (i = i1) → compPath-filler suc-inf refl k j
; (j = i0) → ∞
; (j = i1) → suc-inf i
}) (suc-inf (i ∧ j))
open Iso
ℕ+∞⇔Cℕ+∞ : Iso ℕ+∞ Coprod.ℕ+∞
ℕ+∞⇔Cℕ+∞ .fun = ℕ+∞→Cℕ+∞
ℕ+∞⇔Cℕ+∞ .inv = Cℕ+∞→ℕ+∞
ℕ+∞⇔Cℕ+∞ .leftInv = ℕ+∞→Cℕ+∞→ℕ+∞
ℕ+∞⇔Cℕ+∞ .rightInv = Cℕ+∞→ℕ+∞→Cℕ+∞
| 26.435484
| 71
| 0.52227
|
0e7328b74e4e17580e64968ea43d09483fd442bd
| 698
|
agda
|
Agda
|
test/interaction/Issue2466.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/interaction/Issue2466.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue2466.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, 2017-03-21, issue #2466
-- The unifier should not turn user-written variable patterns into
-- dot patterns.
-- {-# OPTIONS -v reify.implicit:100 -v interaction.case:100 #-}
-- {-# OPTIONS -v tc.lhs.unify:40 #-}
postulate
A B : Set
module Explicit where
data D : A → B → Set where
c : ∀ p {p'} x → D p' x → D p x
test : ∀ p x → D p x → D p x
test .p _ (c p x pp) = {!.p'!}
where
y = x
-- Expected: test .p _ (c p {p'} x pp) = ?
module Implicit where
data D : A → B → Set where
c : ∀ {p p' x} → D p' x → D p x
test : ∀ p {x} → D p x → D p x
test .p (c {p} {x = x} pp) = {!.p'!}
where
y = x
-- Expected: test .p (c {p} {p'} {x} pp) = ?
| 19.942857
| 66
| 0.508596
|
fb17361c4890910cba9fd316a6f2069da1e05c08
| 117
|
agda
|
Agda
|
test/Fail/Issue1698-postulate.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1698-postulate.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1698-postulate.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
postulate
foo = Foo
-- Error message is:
-- A postulate block can only contain type signatures or instance blocks
| 19.5
| 72
| 0.752137
|
c566167e3be57755489545f7c919d7d5a7da15ec
| 1,108
|
agda
|
Agda
|
BasicIS4/Metatheory/Gentzen-BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIS4/Metatheory/Gentzen-BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIS4/Metatheory/Gentzen-BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module BasicIS4.Metatheory.Gentzen-BasicKripkeOno where
open import BasicIS4.Syntax.Gentzen public
open import BasicIS4.Semantics.BasicKripkeOno public
-- Soundness with respect to all models, or evaluation.
mutual
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = λ ξ a → eval t (mono⊩⋆ ξ γ , a)
eval (app {A} {B} t u) γ = _⟪$⟫_ {A} {B} (eval t γ) (eval u γ)
eval (multibox ts u) γ = λ ζ → eval u (thing ts γ ζ)
eval (down {A} t) γ = ⟪↓⟫ {A} (eval t γ)
eval (pair t u) γ = eval t γ , eval u γ
eval (fst t) γ = π₁ (eval t γ)
eval (snd t) γ = π₂ (eval t γ)
eval unit γ = ∙
-- TODO: What is this?
thing : ∀ {{_ : Model}} {Δ Γ} {w : World}
→ Γ ⊢⋆ □⋆ Δ → w ⊩⋆ Γ → ∀ {v′} → w R v′ → v′ ⊩⋆ □⋆ Δ
thing {∅} ∙ γ ζ = ∙
thing {Δ , B} (ts , t) γ ζ = thing ts γ ζ , λ ζ′ → eval t γ (transR ζ ζ′)
eval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ
eval⋆ {∅} ∙ γ = ∙
eval⋆ {Ξ , A} (ts , t) γ = eval⋆ ts γ , eval t γ
-- TODO: Correctness of evaluation with respect to conversion.
| 33.575758
| 75
| 0.499097
|
2050a4b8653f545572dab61b41a02cbc8d3ae9f2
| 5,721
|
agda
|
Agda
|
lib/PathFunctor.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/PathFunctor.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/PathFunctor.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Base
open import lib.PathGroupoid
module lib.PathFunctor where
{- Nondependent stuff -}
module _ {i j} {A : Type i} {B : Type j} (f : A → B) where
!-ap : {x y : A} (p : x == y)
→ ! (ap f p) == ap f (! p)
!-ap idp = idp
ap-! : {x y : A} (p : x == y)
→ ap f (! p) == ! (ap f p)
ap-! idp = idp
∙-ap : {x y z : A} (p : x == y) (q : y == z)
→ ap f p ∙ ap f q == ap f (p ∙ q)
∙-ap idp q = idp
ap-∙ : {x y z : A} (p : x == y) (q : y == z)
→ ap f (p ∙ q) == ap f p ∙ ap f q
ap-∙ idp q = idp
∙'-ap : {x y z : A} (p : x == y) (q : y == z)
→ ap f p ∙' ap f q == ap f (p ∙' q)
∙'-ap p idp = idp
ap-∙' : {x y z : A} (p : x == y) (q : y == z)
→ ap f (p ∙' q) == ap f p ∙' ap f q
ap-∙' p idp = idp
{- Dependent stuff -}
module _ {i j} {A : Type i} {B : A → Type j} (f : Π A B) where
apd-∙ : {x y z : A} (p : x == y) (q : y == z)
→ apd f (p ∙ q) == apd f p ∙ᵈ apd f q
apd-∙ idp idp = idp
apd-∙' : {x y z : A} (p : x == y) (q : y == z)
→ apd f (p ∙' q) == apd f p ∙'ᵈ apd f q
apd-∙' idp idp = idp
{- Over stuff -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(f : {a : A} → B a → C a) where
ap↓-◃ : {x y z : A} {u : B x} {v : B y} {w : B z}
{p : x == y} {p' : y == z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ])
→ ap↓ f (q ◃ r) == ap↓ f q ◃ ap↓ f r
ap↓-◃ {p = idp} {p' = idp} idp idp = idp
ap↓-▹! : {x y z : A} {u : B x} {v : B y} {w : B z}
{p : x == y} {p' : z == y} (q : u == v [ B ↓ p ]) (r : w == v [ B ↓ p' ])
→ ap↓ f (q ▹! r) == ap↓ f q ▹! ap↓ f r
ap↓-▹! {p = idp} {p' = idp} idp idp = idp
{- Fuse and unfuse -}
∘-ap : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (g : B → C) (f : A → B)
{x y : A} (p : x == y) → ap g (ap f p) == ap (g ∘ f) p
∘-ap f g idp = idp
ap-∘ : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (g : B → C) (f : A → B)
{x y : A} (p : x == y) → ap (g ∘ f) p == ap g (ap f p)
ap-∘ f g idp = idp
ap-cst : ∀ {i j} {A : Type i} {B : Type j} (b : B) {x y : A} (p : x == y)
→ ap (cst b) p == idp
ap-cst b idp = idp
ap-idf : ∀ {i} {A : Type i} {u v : A} (p : u == v) → ap (idf A) p == p
ap-idf idp = idp
{- Functoriality of [coe] -}
coe-∙ : ∀ {i} {A B C : Type i} (p : A == B) (q : B == C) (a : A)
→ coe (p ∙ q) a == coe q (coe p a)
coe-∙ idp q a = idp
coe-! : ∀ {i} {A B : Type i} (p : A == B) → coe (! p) == coe! p
coe-! idp = idp
coe!-inv-r : ∀ {i} {A B : Type i} (p : A == B) (b : B)
→ coe p (coe! p b) == b
coe!-inv-r idp b = idp
coe!-inv-l : ∀ {i} {A B : Type i} (p : A == B) (a : A)
→ coe! p (coe p a) == a
coe!-inv-l idp a = idp
coe-inv-adj : ∀ {i} {A B : Type i} (p : A == B) (a : A) →
ap (coe p) (coe!-inv-l p a) == coe!-inv-r p (coe p a)
coe-inv-adj idp a = idp
coe!-inv-adj : ∀ {i} {A B : Type i} (p : A == B) (b : B) →
ap (coe! p) (coe!-inv-r p b) == coe!-inv-l p (coe! p b)
coe!-inv-adj idp b = idp
coe-ap-! : ∀ {i j} {A : Type i} (P : A → Type j) {a b : A} (p : a == b)
(x : P b)
→ coe (ap P (! p)) x == coe! (ap P p) x
coe-ap-! P idp x = idp
{- Functoriality of transport -}
trans-∙ : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A}
(p : x == y) (q : y == z) (b : B x)
→ transport B (p ∙ q) b == transport B q (transport B p b)
trans-∙ idp _ _ = idp
trans-∙' : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A}
(p : x == y) (q : y == z) (b : B x)
→ transport B (p ∙' q) b == transport B q (transport B p b)
trans-∙' _ idp _ = idp
{- Naturality of homotopies -}
htpy-natural : ∀ {i j} {A : Type i} {B : Type j} {x y : A} {f g : A → B}
(p : ∀ x → (f x == g x)) (q : x == y) → ap f q ∙ p y == p x ∙ ap g q
htpy-natural p idp = ! (∙-unit-r _)
htpy-natural-toid : ∀ {i} {A : Type i} {f : A → A}
(p : ∀ (x : A) → f x == x) → (∀ x → ap f (p x) == p (f x))
htpy-natural-toid {f = f} p x = anti-whisker-right (p x) $
htpy-natural p (p x) ∙ ap (λ q → p (f x) ∙ q) (ap-idf (p x))
{- for functions with two arguments -}
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → B → C) where
ap2 : {x y : A} {w z : B}
→ (x == y) → (w == z) → f x w == f y z
ap2 idp idp = idp
ap2-out : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 p q == ap (λ u → f u w) p ∙ ap (λ v → f y v) q
ap2-out idp idp = idp
ap2-idp-l : {x : A} {w z : B} (q : w == z)
→ ap2 (idp {a = x}) q == ap (f x) q
ap2-idp-l idp = idp
ap2-idp-r : {x y : A} {w : B} (p : x == y)
→ ap2 p (idp {a = w}) == ap (λ z → f z w) p
ap2-idp-r idp = idp
{- ap2 lemmas -}
module _ {i j} {A : Type i} {B : Type j} where
ap2-fst : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 (curry fst) p q == p
ap2-fst idp idp = idp
ap2-snd : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 (curry snd) p q == q
ap2-snd idp idp = idp
ap-ap2 : ∀ {k l} {C : Type k} {D : Type l}
(g : C → D) (f : A → B → C) {x y : A} {w z : B}
(p : x == y) (q : w == z)
→ ap g (ap2 f p q) == ap2 (λ a b → g (f a b)) p q
ap-ap2 g f idp idp = idp
ap2-ap-l : ∀ {k l} {C : Type k} {D : Type l}
(g : B → C → D) (f : A → B) {x y : A} {w z : C}
(p : x == y) (q : w == z)
→ ap2 g (ap f p) q == ap2 (λ a c → g (f a) c) p q
ap2-ap-l g f idp idp = idp
ap2-ap-r : ∀ {k l} {C : Type k} {D : Type l}
(g : A → C → D) (f : B → C) {x y : A} {w z : B}
(p : x == y) (q : w == z)
→ ap2 g p (ap f q) == ap2 (λ a b → g a (f b)) p q
ap2-ap-r g f idp idp = idp
ap2-diag : (f : A → A → B)
{x y : A} (p : x == y)
→ ap2 f p p == ap (λ x → f x x) p
ap2-diag f idp = idp
-- unsure where this belongs
trans-pathfrom : ∀ {i} {A : Type i} {a x y : A} (p : x == y) (q : a == x)
→ transport (λ x → a == x) p q == q ∙ p
trans-pathfrom idp q = ! (∙-unit-r q)
| 31.262295
| 79
| 0.406572
|
cb3bcb9ee3986d35724010dd717a585eb19c21a8
| 138
|
agda
|
Agda
|
examples/outdated-and-incorrect/Alonzo/PreludeAll.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/Alonzo/PreludeAll.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/Alonzo/PreludeAll.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module PreludeAll where
import PreludeBool public
import PreludeNat
import PreludeShow
open PreludeBool
open PreludeNat
open PreludeShow
| 15.333333
| 25
| 0.876812
|
50def15eb7b9ce4a8a4f5ba5182839ccf5895ea2
| 21,163
|
agda
|
Agda
|
agda/book/Programming_Language_Foundations_in_Agda/x10-747Lists-hc.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/Programming_Language_Foundations_in_Agda/x10-747Lists-hc.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/Programming_Language_Foundations_in_Agda/x10-747Lists-hc.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module x10-747Lists-hc where
-- Library
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong)
open Eq.≡-Reasoning
open import Data.Bool using (Bool; true; false; T; _∧_; _∨_; not)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _≤_; s≤s; z≤n)
open import Data.Nat.Properties using (+-assoc; +-identityˡ; +-identityʳ; *-assoc; *-identityˡ; *-identityʳ)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Product using (_×_; ∃; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_∘_)
open import Level using (Level)
open import Data.Empty using (⊥)
------------------------------------------------------------------------------
-- Copied from 747Isomorphism.
infix 0 _≃_
record _≃_ (A B : Set) : Set where
constructor mk-≃ -- This has been added, not in PLFA
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
open _⇔_
------------------------------------------------------------------------------
-- Polymorphic lists (parameterized version).
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
infixr 5 _∷_
-- example
_ : List ℕ
_ = 0 ∷ 1 ∷ 2 ∷ []
-- equivalent indexed version
data List' : Set → Set where
[]' : ∀ {A : Set} → List' A
_∷'_ : ∀ {A : Set} → A → List' A → List' A
-- using implicit arguments in above example (why?)
_ : List ℕ
_ = _∷_ {ℕ} 0 (_∷_ {ℕ} 1 (_∷_ {ℕ} 2 ([] {ℕ})))
-- tell Agda to use Haskell lists internally
{-# BUILTIN LIST List #-}
-- useful syntax
pattern [_] z = z ∷ []
pattern [_,_] y z = y ∷ z ∷ []
pattern [_,_,_] x y z = x ∷ y ∷ z ∷ []
pattern [_,_,_,_] w x y z = w ∷ x ∷ y ∷ z ∷ []
pattern [_,_,_,_,_] v w x y z = v ∷ w ∷ x ∷ y ∷ z ∷ []
pattern [_,_,_,_,_,_] u v w x y z = u ∷ v ∷ w ∷ x ∷ y ∷ z ∷ []
-- append for lists
infixr 5 _++_
_++_ : ∀ {A : Set} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
_ : [ 0 , 2 , 4 ] ++ [ 3 , 5 ] ≡ [ 0 , 2 , 4 , 3 , 5 ]
_ = refl
-- associativity of append
++-assoc : ∀ {A : Set} → (xs ys zs : List A) → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)
++-assoc [] ys zs = refl
++-assoc (x ∷ xs) ys zs rewrite ++-assoc xs ys zs = refl
-- left/right identities for append
++-identityˡ : ∀ {A : Set} → (xs : List A) → [] ++ xs ≡ xs
++-identityˡ xs = refl
++-identityʳ : ∀ {A : Set} → (xs : List A) → xs ++ [] ≡ xs
++-identityʳ [] = refl
++-identityʳ (x ∷ xs) rewrite ++-identityʳ xs = refl
-- length of a list
length : ∀ {A : Set} → List A → ℕ
length [] = zero
length (x ∷ xs) = suc (length xs)
_ : length [ 0 , 1 , 2 ] ≡ 3
_ = refl
-- reasoning about length.
length-++ : ∀ {A : Set} → (xs ys : List A) → length (xs ++ ys) ≡ length xs + length ys
length-++ [] ys = refl
length-++ (x ∷ xs) ys rewrite length-++ xs ys = refl
-- quadratic time reverse using structural recursion
reverse : ∀ {A : Set} → List A → List A
reverse [] = []
reverse (x ∷ xs) = reverse xs ++ [ x ]
_ : reverse [ 0 , 1 , 2 ] ≡ [ 2 , 1 , 0 ]
_ = refl
-- 747/PLFA exercise: RevCommApp (1 point)
-- reverse commutes with ++
-- https://gist.github.com/pedrominicz/012e842362f6c65361722ed1aaf10178
-- The key to this one is NOT splitting ys.
reverse-++-commute : ∀ {A : Set}
→ (xs ys : List A)
→ reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-++-commute [] ys rewrite ++-identityʳ (reverse ys) = refl
reverse-++-commute (x ∷ xs) ys
-- reverse ((x ∷ xs) ++ ys) ≡ reverse ys ++ reverse (x ∷ xs)
-- reverse (xs ++ ys) ++ [ x ] ≡ reverse ys ++ reverse xs ++ [ x ]
rewrite
reverse-++-commute xs ys
-- (reverse ys ++ reverse xs) ++ [ x ] ≡ reverse ys ++ reverse xs ++ [ x ]
| ++-assoc (reverse ys) (reverse xs) [ x ]
-- reverse ys ++ reverse xs ++ [ x ] ≡ reverse ys ++ reverse xs ++ [ x ]
= refl
-- NOT USED
snoc : {A : Set} → List A → A → List A
snoc [] x = x ∷ []
snoc (y ∷ l) x = y ∷ (snoc l x)
-- NOT USED
snoc≡app : {A : Set} → (l : List A) → (a : A) → snoc l a ≡ l ++ [ a ]
snoc≡app [] a = refl
snoc≡app (x ∷ l) a rewrite (snoc≡app l a) = refl
-- NOT USED
reverse-snoc : ∀ {A : Set} → (xs : List A) → List A
reverse-snoc [] = []
reverse-snoc (x ∷ xs) = snoc (reverse-snoc xs) x
_ : reverse-snoc [ 0 , 1 , 2 ] ≡ [ 2 , 1 , 0 ]
_ = refl
-- NOT USED
reverse≡reverse-snoc : ∀ {A : Set} → (xs : List A) → reverse xs ≡ reverse-snoc xs
reverse≡reverse-snoc [] = refl
reverse≡reverse-snoc (x ∷ xs) -- reverse (x ∷ xs) ≡ reverse-snoc (x ∷ xs)
-- reverse xs ++ [ x ] ≡ snoc (reverse-snoc xs) x
rewrite
reverse≡reverse-snoc xs -- reverse-snoc xs ++ [ x ] ≡ snoc (reverse-snoc xs) x
| snoc≡app (reverse-snoc xs) x -- reverse-snoc xs ++ [ x ] ≡ reverse-snoc xs ++ [ x ]
= refl
-- 747/PLFA exercise: RevInvol (1 point)
-- Reverse is its own inverse.
reverse-involutive : ∀ {A : Set} → (xs : List A) → reverse (reverse xs) ≡ xs
reverse-involutive [] = refl
reverse-involutive (x ∷ xs) -- reverse (reverse (x ∷ xs)) ≡ x ∷ xs
-- reverse (reverse xs ++ [ x ]) ≡ x ∷ xs
rewrite
(reverse-++-commute (reverse xs) [ x ]) -- x ∷ reverse (reverse xs) ≡ x ∷ xs
| reverse-involutive xs -- x ∷ xs ≡ x ∷ xs
= refl
-- towards more efficient linear time reverse
-- generalization of reverse
shunt : ∀ {A : Set} → List A → List A → List A
shunt [] ys = ys
shunt (x ∷ xs) ys = shunt xs (x ∷ ys)
-- explanation of what shunt is doing
shunt-reverse : ∀ {A : Set} → (xs ys : List A) → shunt xs ys ≡ reverse xs ++ ys
shunt-reverse [] ys = refl
shunt-reverse (x ∷ xs) [] -- shunt (x ∷ xs) [] ≡ reverse (x ∷ xs) ++ []
-- shunt xs [ x ] ≡ (reverse xs ++ [ x ]) ++ []
rewrite
++-identityʳ (reverse xs ++ [ x ])
-- shunt xs [ x ] ≡ reverse xs ++ [ x ]
| shunt-reverse xs [ x ] -- reverse xs ++ [ x ] ≡ reverse xs ++ [ x ]
= refl
shunt-reverse (x ∷ xs) (y ∷ ys)
-- shunt (x ∷ xs) (y ∷ ys) ≡ reverse (x ∷ xs) ++ y ∷ ys
-- shunt xs (x ∷ y ∷ ys) ≡ (reverse xs ++ [ x ]) ++ y ∷ ys
rewrite
shunt-reverse xs (x ∷ y ∷ ys)
-- reverse xs ++ x ∷ y ∷ ys ≡ (reverse xs ++ [ x ]) ++ y ∷ ys
| ++-assoc (reverse xs) [ x ] (y ∷ ys)
-- reverse xs ++ x ∷ y ∷ ys ≡ reverse xs ++ x ∷ y ∷ ys
= refl
-- linear reverse is a special case of shunt
reverse' : ∀ {A : Set} → List A → List A
reverse' xs = shunt xs []
_ : reverse' [ 0 , 1 , 2 ] ≡ [ 2 , 1 , 0 ]
_ = refl
-- prove quadratic and linear reverse are equivalent
reverses : ∀ {A : Set} → (xs : List A) → reverse' xs ≡ reverse xs
reverses [] = refl
reverses (x ∷ xs) -- reverse' (x ∷ xs) ≡ reverse (x ∷ xs)
-- reverse' (x ∷ xs) ≡ reverse xs ++ [ x ]
rewrite shunt-reverse xs [ x ] -- reverse xs ++ [ x ] ≡ reverse xs ++ [ x ]
= refl
-- common higher-order list functions
map : ∀ {A B : Set} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
_ : map suc [ 0 , 1 , 2 ] ≡ [ 1 , 2 , 3 ]
_ = refl
-- 747/PLFA exercise: MapCompose (1 point)
-- The map of a composition is the composition of maps.
-- Changed from PLFA: some arguments made explicit, uses pointwise equality.
map-compose : ∀ {A B C : Set} (f : A → B) (g : B → C) (xs : List A)
→ map (g ∘ f) xs ≡ (map g ∘ map f) xs
map-compose f g [] = refl
map-compose f g (x ∷ xs) -- map (g ∘ f) (x ∷ xs) ≡ (map g ∘ map f) (x ∷ xs)
-- (g ∘ f) x ∷ map (g ∘ f) xs ≡ (map g ∘ map f) (x ∷ xs)
rewrite
map-compose f g xs -- g (f x) ∷ map g (map f xs) ≡ g (f x) ∷ map g (map f xs)
= refl
-- 747/PLFA exercise: MapAppendComm (1 point)
-- The map of an append is the append of maps.
-- Changed from PLFA: some arguments made explicit.
map-++-commute : ∀ {A B : Set} (f : A → B) (xs ys : List A)
→ map f (xs ++ ys) ≡ map f xs ++ map f ys
map-++-commute f [] ys = refl
map-++-commute f (x ∷ xs) ys -- map f ((x ∷ xs) ++ ys) ≡ map f (x ∷ xs) ++ map f ys
-- f x ∷ map f (xs ++ ys) ≡ f x ∷ map f xs ++ map f ys
rewrite
map-++-commute f xs ys -- f x ∷ map f xs ++ map f ys ≡ f x ∷ map f xs ++ map f ys
= refl
------------------------------------------------------------------------------
-- PLFA exercise: map over trees
-- trees with leaves of type A and internal nodes of type B
data Tree (A B : Set) : Set where
leaf : A → Tree A B
node : Tree A B → B → Tree A B → Tree A B
map-Tree : ∀ {A B C D : Set} → (A → C) → (B → D) → Tree A B → Tree C D
map-Tree f g (leaf a) = leaf (f a)
map-Tree f g (node tl b tr) = node (map-Tree f g tl) (g b) (map-Tree f g tr)
------------------------------------------------------------------------------
-- Fold-right: put operator ⊗ between each list element (and supplied final element).
-- ⊗ is considered right-associative.
-- Fold-right is universal for structural recursion on one argument.
foldr : ∀ {A B : Set} → (A → B → B) → B → List A → B
foldr _⊗_ e [] = e
foldr _⊗_ e (x ∷ xs) = x ⊗ foldr _⊗_ e xs
_ : foldr _+_ 0 [ 1 , 2 , 3 , 4 ] ≡ 10
_ = refl
-- Summing a list using foldr.
sum : List ℕ → ℕ
sum = foldr _+_ 0
_ : sum [ 1 , 2 , 3 , 4 ] ≡ 10
_ = refl
-- PLFA exercise: use foldr to define product on lists of naturals
product : List ℕ → ℕ
product = foldr _*_ 1
_ : product [ 1 , 2 , 3 , 4 ] ≡ 24
_ = refl
-- 747/PLFA exercise: FoldrOverAppend (1 point)
-- prove foldr over an append can be expressed as foldrs over each list.
foldr-++ : ∀ {A B : Set} (_⊗_ : A → B → B) (b : B) (xs ys : List A) →
foldr _⊗_ b (xs ++ ys) ≡ foldr _⊗_ (foldr _⊗_ b ys) xs
foldr-++ _⊗_ b [] ys = refl
foldr-++ _⊗_ b (x ∷ xs) ys
-- foldr _⊗_ b ((x ∷ xs) ++ ys) ≡ foldr _⊗_ (foldr _⊗_ b ys) (x ∷ xs)
-- (x ⊗ foldr _⊗_ b (xs ++ ys)) ≡ (x ⊗ foldr _⊗_ (foldr _⊗_ b ys) xs)
rewrite foldr-++ _⊗_ b xs ys
-- (x ⊗ foldr _⊗_ (foldr _⊗_ b ys) xs) ≡ (x ⊗ foldr _⊗_ (foldr _⊗_ b ys) xs)
= refl
-- 747/PLFA exercise: MapIsFoldr (1 point)
-- Show that map can be expressed as a fold.
-- Changed from PLFA: some arguments made explicit, uses pointwise equality.
map-is-foldr : ∀ {A B : Set} (f : A → B) (xs : List A)
→ map f xs ≡ foldr (λ x rs → f x ∷ rs) [] xs
map-is-foldr f [] = refl
map-is-foldr f (x ∷ xs) rewrite map-is-foldr f xs = refl
-- PLFA exercise: write a fold for trees
fold-Tree : ∀ {A B C : Set} → (A → C) → (C → B → C → C) → Tree A B → C
fold-Tree f g (leaf a) = f a
fold-Tree f g (node tl b tr) = g (fold-Tree f g tl) b (fold-Tree f g tr)
-- PLFA exercise: the downFrom function computes a countdown list
-- Prove an equality about its sum
downFrom : ℕ → List ℕ
downFrom zero = []
downFrom (suc n) = n ∷ downFrom n
_ : downFrom 4 ≡ [ 3 , 2 , 1 , 0 ]
_ = refl
_ : sum (downFrom 4) ≡ 6
_ = refl
{- TODO
sum-downFrom : ∀ (n : ℕ) → sum (downFrom n) * 2 ≡ n * (n ∸ 1)
sum-downFrom n = {!!}
-}
------------------------------------------------------------------------------
-- 'Monoid' : set with
-- - an associative operator
-- - an element which is the left and right identity
record IsMonoid (A : Set) : Set where
field
id : A
_⊗_ : A → A → A
assoc : ∀ (x y z : A) → (x ⊗ y) ⊗ z ≡ x ⊗ (y ⊗ z)
identityˡ : ∀ (x : A) → id ⊗ x ≡ x
identityʳ : ∀ (x : A) → x ⊗ id ≡ x
-- The following open command is different from PLFA; it uses instance arguments,
-- which work like typeclasses in Haskell (allow overloading, which is cleaner).
open IsMonoid {{ ...}} public
-- These pragmas make displays of goal and context look nicer.
{-# DISPLAY IsMonoid.id _ = id #-}
{-# DISPLAY IsMonoid._⊗_ _ = _⊗_ #-}
-- instances of Monoid
instance
+-monoid : IsMonoid ℕ
IsMonoid.id +-monoid = 0
IsMonoid._⊗_ +-monoid = _+_
IsMonoid.assoc +-monoid = +-assoc
IsMonoid.identityˡ +-monoid = +-identityˡ
IsMonoid.identityʳ +-monoid = +-identityʳ
*-monoid : IsMonoid ℕ
IsMonoid.id *-monoid = 1
IsMonoid._⊗_ *-monoid = _*_
IsMonoid.assoc *-monoid = *-assoc
IsMonoid.identityˡ *-monoid = *-identityˡ
IsMonoid.identityʳ *-monoid = *-identityʳ
++-monoid : ∀ {A : Set} → IsMonoid (List A)
IsMonoid.id ++-monoid = []
IsMonoid._⊗_ ++-monoid = _++_
IsMonoid.assoc ++-monoid = ++-assoc
IsMonoid.identityˡ ++-monoid = ++-identityˡ
IsMonoid.identityʳ ++-monoid = ++-identityʳ
-- property of foldr over a monoid
foldr-monoid : ∀ {A : Set} → {{m : IsMonoid A}} →
∀ (xs : List A) (y : A)
→ foldr _⊗_ y xs ≡ (foldr _⊗_ id xs) ⊗ y
foldr-monoid {A} ⦃ m ⦄ [] y
rewrite identityˡ y = refl
foldr-monoid {A} ⦃ m ⦄ (x ∷ xs) y
with foldr-monoid xs y
... | xxx
rewrite
xxx
| sym (assoc x (foldr _⊗_ id xs) y)
= refl
foldr-monoid-++ : ∀ {A : Set} → {{m : IsMonoid A}} →
∀ (xs ys : List A)
→ foldr _⊗_ id (xs ++ ys) ≡ foldr _⊗_ id xs ⊗ foldr _⊗_ id ys
foldr-monoid-++ {A} ⦃ m ⦄ [] ys
rewrite
sym (foldr-monoid {A} {{m}} [] (foldr _⊗_ id ys))
= refl
foldr-monoid-++ {A} ⦃ m ⦄ (x ∷ xs) ys
rewrite
foldr-monoid-++ {A} {{m}} xs ys
| assoc x (foldr _⊗_ id xs) (foldr _⊗_ id ys)
= refl
-- 747/PLFA exercise: Foldl (1 point)
-- Define foldl, which associates left instead of right, e.g.
-- foldr _⊗_ e [ x , y , z ] = x ⊗ (y ⊗ (z ⊗ e))
-- foldl _⊗_ e [ x , y , z ] = ((e ⊗ x) ⊗ y) ⊗ z
foldl : ∀ {A B : Set} → (B → A → B) → B → List A → B
foldl _⊗_ e [] = e
foldl _⊗_ e (x ∷ xs) = foldl _⊗_ (e ⊗ x) xs
sum-foldl : foldl _+_ 0 [ 4 , 3 , 2 , 1 ] ≡ 10
sum-foldl = refl
monus-foldl : foldl _∸_ 20 [ 4 , 3 , 2 ] ≡ 11
monus-foldl = refl
monus-foldr : foldr _∸_ 20 [ 4 , 3 , 2 ] ≡ 1
monus-foldr = refl
-- 747/PLFA exercise: FoldrMonFoldl (2 points)
-- Show that foldr and foldl compute the same value on a monoid
-- when the base case is the identity.
-- Hint: generalize to when the base case is an arbitrary value.
foldl-r-mon-helper : ∀ {A : Set} {{m : IsMonoid A}}
→ ∀ (xs : List A) (y : A)
→ foldl _⊗_ y xs ≡ y ⊗ foldl _⊗_ id xs
foldl-r-mon-helper [] y rewrite identityʳ y = refl
foldl-r-mon-helper (x ∷ xs) y -- foldl _⊗_ y (x ∷ xs) ≡ (y ⊗ foldl _⊗_ id (x ∷ xs))
-- foldl _⊗_ (y ⊗ x) xs ≡ (y ⊗ foldl _⊗_ (id ⊗ x) xs)
rewrite
identityˡ x -- foldl _⊗_ (y ⊗ x) xs ≡ (y ⊗ foldl _⊗_ x xs)
| foldl-r-mon-helper xs (y ⊗ x) -- ((y ⊗ x) ⊗ foldl _⊗_ id xs) ≡ (y ⊗ foldl _⊗_ x xs)
| assoc y x (foldl _⊗_ id xs) -- (y ⊗ (x ⊗ foldl _⊗_ id xs)) ≡ (y ⊗ foldl _⊗_ x xs)
| foldl-r-mon-helper xs x -- (y ⊗ (x ⊗ foldl _⊗_ id xs)) ≡ (y ⊗ (x ⊗ foldl _⊗_ id xs))
= refl
foldl-r-mon : ∀ {A : Set} → {{m : IsMonoid A}}
→ ∀ (xs : List A) → foldl _⊗_ id xs ≡ foldr _⊗_ id xs
foldl-r-mon [] = refl
foldl-r-mon (x ∷ xs)
-- foldl _⊗_ id (x ∷ xs) ≡ foldr _⊗_ id (x ∷ xs)
-- foldl _⊗_ (id ⊗ x) xs ≡ (x ⊗ foldr _⊗_ id xs)
rewrite
identityˡ x -- foldl _⊗_ x xs ≡ (x ⊗ foldr _⊗_ id xs)
| foldl-r-mon-helper xs x -- (x ⊗ foldl _⊗_ id xs) ≡ (x ⊗ foldr _⊗_ id xs)
| foldl-r-mon xs -- (x ⊗ foldr _⊗_ id xs) ≡ (x ⊗ foldr _⊗_ id xs)
= refl
------------------------------------------------------------------------------
-- Inductively-defined predicates over lists
-- All P xs means P x holds for every element of xs
data All {A : Set} (P : A → Set) : List A → Set where
[] : All P []
_∷_ : ∀ {x : A} {xs : List A} → P x → All P xs → All P (x ∷ xs)
_ : All (_≤ 2) [ 0 , 1 , 2 ]
_ = z≤n ∷ s≤s z≤n ∷ s≤s (s≤s z≤n) ∷ []
-- Any P xs means P x holds for some element of xs
data Any {A : Set} (P : A → Set) : List A → Set where
here : ∀ {x : A} {xs : List A} → P x → Any P (x ∷ xs)
there : ∀ {x : A} {xs : List A} → Any P xs → Any P (x ∷ xs)
-- membership in list as application of Any
infix 4 _∈_ _∉_
_∈_ : ∀ {A : Set} (x : A) (xs : List A) → Set
x ∈ xs = Any (x ≡_) xs
_∉_ : ∀ {A : Set} (x : A) (xs : List A) → Set
x ∉ xs = ¬ (x ∈ xs)
_ : 0 ∈ [ 0 , 1 , 0 , 2 ]
_ = here refl
_ : 0 ∈ [ 1 , 2 , 0 ]
_ = there (there (here refl))
not-in : 3 ∉ [ 0 , 1 , 0 , 2 ]
not-in (here ())
not-in (there (here ()))
not-in (there (there (here ())))
not-in (there (there (there (here ()))))
-- The development in PLFA, repeated with our notation.
All-++-⇔ : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ All P (xs ++ ys) ⇔ (All P xs × All P ys)
to (All-++-⇔ xs ys) = to' xs ys
where
to' : ∀ {A : Set} {P : A → Set} (xs ys : List A)
→ All P (xs ++ ys) → (All P xs × All P ys)
to' [] ys = λ All-P-ys → ⟨ [] , All-P-ys ⟩
to' (x ∷ xs) ys (Px ∷ All-P-xs++ys) with to' xs ys All-P-xs++ys
... | ⟨ All-P-xs , All-PP-ys ⟩ = ⟨ Px ∷ All-P-xs , All-PP-ys ⟩
from (All-++-⇔ xs ys) = from' xs ys
where
from' : ∀ { A : Set} {P : A → Set} (xs ys : List A)
→ All P xs × All P ys → All P (xs ++ ys)
from' [] ys = λ { ⟨ All-P-[] , All-P-ys ⟩ → All-P-ys }
from' (x ∷ xs) ys = λ { ⟨ Px ∷ All-P-xs , All-P-ys ⟩ → Px ∷ from' xs ys ⟨ All-P-xs , All-P-ys ⟩ }
-- PLFA exercise: state and prove Any-++-⇔
Any-++-⇔ : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ Any P (xs ++ ys) ⇔ (Any P xs ⊎ Any P ys)
to (Any-++-⇔ xs ys) = to' xs ys
where
to' : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ Any P (xs ++ ys)
→ (Any P xs ⊎ Any P ys)
to' [] ys = λ Any-P-ys → inj₂ Any-P-ys
to' (x ∷ xs) ys (here Px ) = inj₁ (here Px)
to' (x ∷ xs) ys (there Any-P-xs++ys) with to' xs ys Any-P-xs++ys
... | inj₁ Any-P-xs = inj₁ (there Any-P-xs)
... | inj₂ Any-P-ys = inj₂ Any-P-ys
from (Any-++-⇔ xs ys) = from' xs ys
where
from' : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ (Any P xs ⊎ Any P ys)
→ Any P (xs ++ ys)
from' [] ys (inj₂ Any-P-ys) = Any-P-ys
from' (x ∷ xs) ys (inj₂ Any-P-ys) = there (from' xs ys (inj₂ Any-P-ys))
from' (x ∷ xs) ys (inj₁ (here Px)) = here Px
from' (x ∷ xs) ys (inj₁ (there Any-P-xs)) = there (from' xs ys (inj₁ Any-P-xs))
-- use Any-++-⇔ to demonstrate an equivalence relating ∈ and _++_ TODO
-- PLFA exercise: Show that the equivalence All-++-⇔ can be extended to an isomorphism.
-- PLFA exercise: Here is a universe-polymorphic version of composition,
-- and a version of DeMorgan's law for Any and All expressed using it.
_∘'_ : ∀ {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set ℓ₁} {B : Set ℓ₂} {C : Set ℓ₃}
→ (B → C) → (A → B) → A → C
(g ∘' f) x = g (f x)
¬Any≃All¬ : ∀ {A : Set} (P : A → Set) (xs : List A)
→ (¬_ ∘' Any P) xs ≃ All (¬_ ∘' P) xs
to (¬Any≃All¬ _ []) ¬_∘'AnyPxs = []
to (¬Any≃All¬ P (_ ∷ xs)) ¬_∘'AnyPxs with to (¬Any≃All¬ P xs)
... | AnyPxs→⊥→Allλx₁→Px₁→⊥xs
= (λ Px → ¬ here Px ∘'AnyPxs) ∷ AnyPxs→⊥→Allλx₁→Px₁→⊥xs (λ AnyPxs → ¬ there AnyPxs ∘'AnyPxs)
from (¬Any≃All¬ _ []) All¬_∘'Pxs ()
from (¬Any≃All¬ P (x ∷ xs)) All¬_∘'Pxs (here Px) with from (¬Any≃All¬ P xs)
... | All-λx₁→Px₁→⊥-xs→AnyPxs→⊥
= All-λx₁→Px₁→⊥-xs→AnyPxs→⊥ {!!} {!!}
from (¬Any≃All¬ _ (x ∷ xs)) All¬_∘'Pxs (there AnyPxs) = {!!}
from∘to (¬Any≃All¬ P xs) = {!!}
to∘from (¬Any≃All¬ P xs) = {!!}
{-
-- Can we prove the following? If not, explain why.
-- ¬All≃Any¬ : ∀ {A : Set} (P : A → Set) (xs : List A)
-- → (¬_ ∘' All P) xs ≃ Any (¬_ ∘' P) xs
-- End of PLFA exercise
-- Decidability of All
-- A Boolean analogue of All
all : ∀ {A : Set} → (A → Bool) → List A → Bool
all p = foldr _∧_ true ∘ map p
-- A Dec analogue of All
-- A definition of a predicate being decidable
Decidable : ∀ {A : Set} → (A → Set) → Set
Decidable {A} P = ∀ (x : A) → Dec (P x)
All? : ∀ {A : Set} {P : A → Set} → Decidable P → Decidable (All P)
All? P? [] = yes []
All? P? (x ∷ xs) with P? x | All? P? xs
All? P? (x ∷ xs) | yes p | yes p₁ = yes (p ∷ p₁)
All? P? (x ∷ xs) | yes p | no ¬p = no (λ { (x ∷ x₁) → ¬p x₁})
All? P? (x ∷ xs) | no ¬p | _ = no (λ { (x ∷ x₁) → ¬p x})
-- PLFA exercise: repeat above for Any
-- PLFA exercises: All-∀ and Any-∃
-- You will need the stronger version of extensionality
-- (for dependent function types) given in PLFA Isomorphism.
-- PLFA exercise: a version of 'filter' for decidable predicates
-- filter? : ∀ {A : Set} {P : A → Set}
-- → (P? : Decidable P) → List A → ∃[ ys ]( All P ys )
-- filter? P? xs = {!!}
-}
| 34.922442
| 108
| 0.49974
|
1024a00f5e8ae8ac2ae8f5e680a7b6ac2951bdaa
| 3,362
|
agda
|
Agda
|
test/Fail/Issue921.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue921.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue921.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --without-K #-}
{-# OPTIONS --allow-unsolved-metas #-}
-- This issue demonstrates that a failing termination check,
-- subsequently blocking reductions, makes some `impossible'
-- cases possible in the conversion checker.
module Issue921 where
infix 3 _==_
postulate
_==_ : {A : Set} → A → A → Set
transport : {A : Set} (B : A → Set) {x y : A} (p : x == y) → (B x → B y)
! : {A : Set} {x y : A} → (x == y → y == x)
infixr 1 _,_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
open Σ public
infix 4 _≃_
_≃_ : ∀ (A : Set) (B : Set) → Set
A ≃ B = Σ (A → B) (λ _ → B → A)
postulate
<– : {A : Set} {B : Set} → (A ≃ B) → B → A
infixr 4 _∘e_
_∘e_ : {A : Set} {B : Set} {C : Set} → B ≃ C → A ≃ B → A ≃ C
e1 ∘e e2 = ({!!} , λ c → snd e2 (snd e1 c))
module _ {A : Set} {B : A → Set} {C : (a : A) → B a → Set} where
Σ-assoc : Σ (Σ A B) (λ z → C (fst z) (snd z)) ≃ Σ A (λ a → Σ (B a) (C a))
Σ-assoc = ({!!} , λ {(a , (b , c)) → ((a , b) , c)})
data Ctx : Set
postulate
Ty : Ctx → Set
data Ctx where
_·_ : (Γ : Ctx) → Ty {!!} → Ctx
infix 5 _ctx-⇛_
_ctx-⇛_ : Ctx → Ctx → Set
-- swap these two lines and the internal error disappears
Tm : Σ Ctx Ty → Set
Γ ctx-⇛ (Δ · A) = Σ {!!} {!!}
infix 10 _*_
postulate
_*_ : {Γ Δ : Ctx} (m : Γ ctx-⇛ Δ) → Ty {!!} → Ty {!!}
pullback : {Γ Δ : Ctx} {A : Ty Δ} → Tm (Δ , A) → (m : Γ ctx-⇛ Δ) → Tm (Γ , m * A)
infix 7 _·_
data Xtc (Γ : Ctx) : Set where
_·_ : (A : Ty {!!}) → Xtc {!!} → Xtc Γ
infix 6 _⋯_
_⋯_ : (Γ : Ctx) → Xtc Γ → Ctx
Γ ⋯ (A · s) = (Γ · A) ⋯ s
module xtc where
infix 5 _⇛_∣_
_⇛_∣_ : (Γ : Ctx) {Δ : Ctx} (m : Γ ctx-⇛ Δ) → Xtc Δ → Set
Γ ⇛ m ∣ A · T = Σ (Tm (Γ , m * A)) (λ t → Γ ⇛ (m , t) ∣ T)
infix 5 _⇛_
_⇛_ : (Γ : Ctx) → Σ Ctx (λ Δ → Xtc Δ) → Set
Γ ⇛ (Δ , T) = Σ (Γ ctx-⇛ Δ) (λ m → Γ ⇛ m ∣ T)
eq : {Γ Δ : Ctx} {T : Xtc Δ} → Γ ctx-⇛ Δ ⋯ T ≃ Γ ⇛ (Δ , T)
eq {T = A · T} = Σ-assoc ∘e eq
weaken : (Γ : Ctx) {T : Xtc Γ} → Γ ⋯ T ctx-⇛ Γ
infix 10 _○_
_○_ : {Γ Δ Θ : Ctx} → Δ ctx-⇛ Θ → Γ ctx-⇛ Δ → Γ ctx-⇛ Θ
postulate
_○=_ : {Γ Δ Θ : Ctx} (n : Δ ctx-⇛ Θ) (m : Γ ctx-⇛ {!!}) {A : Ty {!!}} → (n ○ m) * A == m * (n * A)
Tm P = Σ Ctx λ Γ → Σ (Ty {!!}) λ A → Σ (Xtc (Γ · A)) λ T → (Γ · A ⋯ T , weaken Γ {A · T} * A) == P
weaken (Γ · A) {T} = (weaken Γ {A · T} , (Γ , A , T , {!!}))
_○_ {Θ = Θ · _} (n , x) m = (n ○ m , transport (λ z → Tm (_ , z)) (! (n ○= m)) (pullback x m))
weaken-○-scope : {Γ Δ : Ctx} {T : Xtc Δ} (ms : Γ xtc.⇛ (Δ , T)) → weaken Δ {T} ○ snd xtc.eq ms == fst ms
pullback-var : {Γ Δ : Ctx} {A : Ty {!!}} {T : Xtc (Δ · A)}
(ms : Γ xtc.⇛ (Δ , A · T))
→ Tm (Γ , snd xtc.eq ms * (weaken Δ {A · T} * A))
pullback-var {Γ} {Δ} {A} {T} ms =
transport (λ z → Tm (Γ , z)) (weaken Δ {A · T} ○= snd xtc.eq ms)
(transport (λ z → Tm (Γ , z * A)) (! (weaken-○-scope ms))
(fst (snd ms)))
pullback (Δ' , _ , T , p) = transport (λ P → (m : _ ctx-⇛ fst P) → Tm (_ , m * snd P)) p (<– {!!} pullback-var)
weaken-○-scope {Γ} {Δ · A} {T} ((m , t) , ts) = {!!} where
helper3 : transport (λ z → Tm (Γ , z))
(! (fst (weaken (Δ · A)) ○= snd xtc.eq ((m , t) , ts)))
(pullback-var {!!})
== transport (λ z → Tm (Γ , z * A))
(! (weaken-○-scope (m , t , ts)))
t
helper3 = {!!}
| 28.491525
| 111
| 0.436347
|
1068bdcd5a16284f55d94c03888ee5e782355f46
| 4,524
|
agda
|
Agda
|
examples/outdated-and-incorrect/Alonzo/Vec.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
examples/outdated-and-incorrect/Alonzo/Vec.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/Alonzo/Vec.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module examples.Vec where
{- Computed datatypes -}
data One : Set where
unit : One
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data _*_ (A B : Set) : Set where
pair : A -> B -> A * B
infixr 20 _=>_
data _=>_ (A B : Set) : Set where
lam : (A -> B) -> A => B
lam2 : {A B C : Set} -> (A -> B -> C) -> (A => B => C)
lam2 f = lam (\x -> lam (f x))
app : {A B : Set} -> (A => B) -> A -> B
app (lam f) x = f x
Vec : Nat -> Set -> Set
Vec zero X = One
Vec (suc n) X = X * Vec n X
{- ... construct the vectors of a given length -}
vHead : {X : Set} -> (n : Nat)-> Vec (suc n) X -> X
vHead n (pair a b) = a
vTail : {X : Set} -> (n : Nat)-> Vec (suc n) X -> Vec n X
vTail n (pair a b) = b
{- safe destructors for nonempty vectors -}
{- useful vector programming operators -}
vec : {X : Set} -> (n : Nat) -> X -> Vec n X
vec zero x = unit
vec (suc n) x = pair x (vec n x)
vapp : {S T : Set} -> (n : Nat) -> Vec n (S => T) -> Vec n S -> Vec n T
vapp zero unit unit = unit
vapp (suc n) (pair f fs) (pair s ss) = pair (app f s) (vapp n fs ss)
{- mapping and zipping come from these -}
vMap : {S T : Set} -> (n : Nat) -> (S -> T) -> Vec n S -> Vec n T
vMap n f ss = vapp n (vec n (lam f)) ss
{- transposition gets the type it deserves -}
transpose : {X : Set} -> (m n : Nat)-> Vec m (Vec n X) -> Vec n (Vec m X)
transpose zero n xss = vec n unit
transpose (suc m) n (pair xs xss) =
vapp n (vapp n (vec n (lam2 pair)) xs)
(transpose m n xss)
{- Sets of a given finite size may be computed as follows... -}
{- Resist the temptation to mention idioms. -}
data Zero : Set where
data _+_ (A B : Set) : Set where
inl : A -> A + B
inr : B -> A + B
Fin : Nat -> Set
Fin zero = Zero
Fin (suc n) = One + Fin n
{- We can use these sets to index vectors safely. -}
vProj : {X : Set} -> (n : Nat)-> Vec n X -> Fin n -> X
-- vProj zero () we can pretend that there is an exhaustiveness check
vProj (suc n) (pair x xs) (inl unit) = x
vProj (suc n) (pair x xs) (inr i) = vProj n xs i
{- We can also tabulate a function as a vector. Resist
the temptation to mention logarithms. -}
vTab : {X : Set} -> (n : Nat)-> (Fin n -> X) -> Vec n X
vTab zero _ = unit
vTab (suc n) f = pair (f (inl unit)) (vTab n (\x -> f (inr x)))
{- Question to ponder in your own time:
if we use functional vectors what are vec and vapp -}
{- Answer: K and S -}
{- Inductive datatypes of the unfocused variety -}
{- Every constructor must target the whole family rather
than focusing on specific indices. -}
data Tm (n : Nat) : Set where
evar : Fin n -> Tm n
eapp : Tm n -> Tm n -> Tm n
elam : Tm (suc n) -> Tm n
{- Renamings -}
Ren : Nat -> Nat -> Set
Ren m n = Vec m (Fin n)
_`Ren`_ = Ren
{- identity and composition -}
idR : (n : Nat) -> n `Ren` n
idR n = vTab n (\i -> i)
coR : (l m n : Nat) -> m `Ren` n -> l `Ren` m -> l `Ren` n
coR l m n m2n l2m = vMap l (vProj m m2n) l2m
{- what theorems should we prove -}
{- the lifting functor for Ren -}
liftR : (m n : Nat) -> m `Ren` n -> suc m `Ren` suc n
liftR m n m2n = pair (inl unit) (vMap m inr m2n)
{- what theorems should we prove -}
{- the functor from Ren to Tm-arrows -}
rename : {m n : Nat} -> (m `Ren` n) -> Tm m -> Tm n
rename {m}{n} m2n (evar i) = evar (vProj m m2n i)
rename {m}{n} m2n (eapp f s) = eapp (rename m2n f) (rename m2n s)
rename {m}{n} m2n (elam t) = elam (rename (liftR m n m2n) t)
{- Substitutions -}
Sub : Nat -> Nat -> Set
Sub m n = Vec m (Tm n)
_`Sub`_ = Sub
{- identity; composition must wait; why -}
idS : (n : Nat) -> n `Sub` n
idS n = vTab n (evar {n})
{- functor from renamings to substitutions -}
Ren2Sub : (m n : Nat) -> m `Ren` n -> m `Sub` n
Ren2Sub m n m2n = vMap m evar m2n
{- lifting functor for substitution -}
liftS : (m n : Nat) -> m `Sub` n -> suc m `Sub` suc n
liftS m n m2n = pair (evar (inl unit))
(vMap m (rename (vMap n inr (idR n))) m2n)
{- functor from Sub to Tm-arrows -}
subst : {m n : Nat} -> m `Sub` n -> Tm m -> Tm n
subst {m}{n} m2n (evar i) = vProj m m2n i
subst {m}{n} m2n (eapp f s) = eapp (subst m2n f) (subst m2n s)
subst {m}{n} m2n (elam t) = elam (subst (liftS m n m2n) t)
{- and now we can define composition -}
coS : (l m n : Nat) -> m `Sub` n -> l `Sub` m -> l `Sub` n
coS l m n m2n l2m = vMap l (subst m2n) l2m
| 26.769231
| 75
| 0.539346
|
39937c3f6f68622cac23bd72579f0dce65493869
| 16,322
|
agda
|
Agda
|
Categories/Square.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 1
|
2018-12-29T21:51:57.000Z
|
2018-12-29T21:51:57.000Z
|
Categories/Square.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | null | null | null |
Categories/Square.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Square where
open import Level
open import Function renaming (id to idᶠ; _∘_ to _©_)
open import Categories.Support.PropositionalEquality
open import Categories.Category
import Categories.Morphisms as Mor
open import Relation.Binary hiding (_⇒_)
module GlueSquares {o ℓ e} (C : Category o ℓ e) where
private module C = Category C
open C
open Mor C
module Pulls {X Y Z} {a : Y ⇒ Z} {b : X ⇒ Y} {c : X ⇒ Z} (ab≡c : a ∘ b ≡ c) where
.pullʳ : ∀ {W} {f : Z ⇒ W} → (f ∘ a) ∘ b ≡ f ∘ c
pullʳ {f = f} =
begin
(f ∘ a) ∘ b
↓⟨ assoc ⟩
f ∘ (a ∘ b)
↓⟨ ∘-resp-≡ʳ ab≡c ⟩
f ∘ c
∎
where open HomReasoning
.pullˡ : ∀ {W} {f : W ⇒ X} → a ∘ (b ∘ f) ≡ c ∘ f
pullˡ {f = f} =
begin
a ∘ (b ∘ f)
↑⟨ assoc ⟩
(a ∘ b) ∘ f
↓⟨ ∘-resp-≡ˡ ab≡c ⟩
c ∘ f
∎
where open HomReasoning
open Pulls public
module Pushes {X Y Z} {a : Y ⇒ Z} {b : X ⇒ Y} {c : X ⇒ Z} (c≡ab : c ≡ a ∘ b) where
.pushʳ : ∀ {W} {f : Z ⇒ W} → f ∘ c ≡ (f ∘ a) ∘ b
pushʳ {f = f} =
begin
f ∘ c
↓⟨ ∘-resp-≡ʳ c≡ab ⟩
f ∘ (a ∘ b)
↑⟨ assoc ⟩
(f ∘ a) ∘ b
∎
where open HomReasoning
.pushˡ : ∀ {W} {f : W ⇒ X} → c ∘ f ≡ a ∘ (b ∘ f)
pushˡ {f = f} =
begin
c ∘ f
↓⟨ ∘-resp-≡ˡ c≡ab ⟩
(a ∘ b) ∘ f
↓⟨ assoc ⟩
a ∘ (b ∘ f)
∎
where open HomReasoning
open Pushes public
module IntroElim {X} {a : X ⇒ X} (a≡id : a ≡ id) where
.elimʳ : ∀ {W} {f : X ⇒ W} → (f ∘ a) ≡ f
elimʳ {f = f} =
begin
f ∘ a
↓⟨ ∘-resp-≡ʳ a≡id ⟩
f ∘ id
↓⟨ identityʳ ⟩
f
∎
where
open HomReasoning
.introʳ : ∀ {W} {f : X ⇒ W} → f ≡ f ∘ a
introʳ = Equiv.sym elimʳ
.elimˡ : ∀ {W} {f : W ⇒ X} → (a ∘ f) ≡ f
elimˡ {f = f} =
begin
a ∘ f
↓⟨ ∘-resp-≡ˡ a≡id ⟩
id ∘ f
↓⟨ identityˡ ⟩
f
∎
where
open HomReasoning
.introˡ : ∀ {W} {f : W ⇒ X} → f ≡ a ∘ f
introˡ = Equiv.sym elimˡ
open IntroElim public
module Extends {X Y Z W} {f : X ⇒ Y} {g : X ⇒ Z} {h : Y ⇒ W} {i : Z ⇒ W} (s : CommutativeSquare f g h i) where
.extendˡ : ∀ {A} {a : W ⇒ A} → CommutativeSquare f g (a ∘ h) (a ∘ i)
extendˡ {a = a} =
begin
(a ∘ h) ∘ f
↓⟨ pullʳ s ⟩
a ∘ i ∘ g
↑⟨ assoc ⟩
(a ∘ i) ∘ g
∎
where
open HomReasoning
.extendʳ : ∀ {A} {a : A ⇒ X} → CommutativeSquare (f ∘ a) (g ∘ a) h i
extendʳ {a = a} =
begin
h ∘ (f ∘ a)
↓⟨ pullˡ s ⟩
(i ∘ g) ∘ a
↓⟨ assoc ⟩
i ∘ (g ∘ a)
∎
where
open HomReasoning
.extend² : ∀ {A B} {a : W ⇒ A} {b : B ⇒ X} → CommutativeSquare (f ∘ b) (g ∘ b) (a ∘ h) (a ∘ i)
extend² {a = a} {b} =
begin
(a ∘ h) ∘ (f ∘ b)
↓⟨ pullʳ extendʳ ⟩
a ∘ (i ∘ (g ∘ b))
↑⟨ assoc ⟩
(a ∘ i) ∘ (g ∘ b)
∎
where
open HomReasoning
open Extends public
-- essentially composition in the arrow category
.glue : {X Y Y′ Z Z′ W : Obj} {a : Z ⇒ W} {a′ : Y′ ⇒ Z′} {b : Y ⇒ Z} {b′ : X ⇒ Y′} {c : X ⇒ Y} {c′ : Y′ ⇒ Z} {c″ : Z′ ⇒ W} → CommutativeSquare c′ a′ a c″ → CommutativeSquare c b′ b c′ → CommutativeSquare c (a′ ∘ b′) (a ∘ b) c″
glue {a = a} {a′} {b} {b′} {c} {c′} {c″} sq-a sq-b =
begin
(a ∘ b) ∘ c
↓⟨ pullʳ sq-b ⟩
a ∘ (c′ ∘ b′)
↓⟨ pullˡ sq-a ⟩
(c″ ∘ a′) ∘ b′
↓⟨ assoc ⟩
c″ ∘ (a′ ∘ b′)
∎
where
open HomReasoning
.glue◃◽ : {X Y Y′ Z W : Obj} {a : Z ⇒ W} {b : Y ⇒ Z} {b′ : X ⇒ Y′} {c : X ⇒ Y} {c′ : Y′ ⇒ Z} {c″ : Y′ ⇒ W} → a ∘ c′ ≡ c″ → CommutativeSquare c b′ b c′ → CommutativeSquare c b′ (a ∘ b) c″
glue◃◽ {a = a} {b} {b′} {c} {c′} {c″} tri-a sq-b =
begin
(a ∘ b) ∘ c
↓⟨ pullʳ sq-b ⟩
a ∘ (c′ ∘ b′)
↓⟨ pullˡ tri-a ⟩
c″ ∘ b′
∎
where
open HomReasoning
-- essentially composition in the over category
.glueTrianglesʳ : ∀ {X X′ X″ Y} {a : X ⇒ Y} {b : X′ ⇒ X} {a′ : X′ ⇒ Y} {b′ : X″ ⇒ X′} {a″ : X″ ⇒ Y}
→ a ∘ b ≡ a′ → a′ ∘ b′ ≡ a″ → a ∘ (b ∘ b′) ≡ a″
glueTrianglesʳ {a = a} {b} {a′} {b′} {a″} a∘b≡a′ a′∘b′≡a″ =
begin
a ∘ (b ∘ b′)
↓⟨ pullˡ a∘b≡a′ ⟩
a′ ∘ b′
↓⟨ a′∘b′≡a″ ⟩
a″
∎
where open HomReasoning
-- essentially composition in the under category
.glueTrianglesˡ : ∀ {X Y Y′ Y″} {b : X ⇒ Y} {a : Y ⇒ Y′} {b′ : X ⇒ Y′} {a′ : Y′ ⇒ Y″} {b″ : X ⇒ Y″} → a′ ∘ b′ ≡ b″ → a ∘ b ≡ b′ → (a′ ∘ a) ∘ b ≡ b″
glueTrianglesˡ {b = b} {a} {b′} {a′} {b″} a′∘b′≡b″ a∘b≡b′ =
begin
(a′ ∘ a) ∘ b
↓⟨ pullʳ a∘b≡b′ ⟩
a′ ∘ b′
↓⟨ a′∘b′≡b″ ⟩
b″
∎
where open HomReasoning
module Cancellers {Y Y′ : Obj} {h : Y′ ⇒ Y} {i : Y ⇒ Y′} (inv : h ∘ i ≡ id) where
.cancelRight : ∀ {Z} {f : Y ⇒ Z} → (f ∘ h) ∘ i ≡ f
cancelRight {f = f} =
begin
(f ∘ h) ∘ i
↓⟨ pullʳ inv ⟩
f ∘ id
↓⟨ identityʳ ⟩
f
∎
where open HomReasoning
.cancelLeft : ∀ {X} {f : X ⇒ Y} → h ∘ (i ∘ f) ≡ f
cancelLeft {f = f} =
begin
h ∘ (i ∘ f)
↓⟨ pullˡ inv ⟩
id ∘ f
↓⟨ identityˡ ⟩
f
∎
where open HomReasoning
.cancelInner : ∀ {X Z} {f : Y ⇒ Z} {g : X ⇒ Y} → (f ∘ h) ∘ (i ∘ g) ≡ f ∘ g
cancelInner {f = f} {g} =
begin
(f ∘ h) ∘ (i ∘ g)
↓⟨ pullˡ cancelRight ⟩
f ∘ g
∎
where open HomReasoning
open Cancellers public
module Switch {X Y} (i : X ≅ Y) where
open _≅_ i
.switch-fgˡ : ∀ {W} {h : W ⇒ X} {k : W ⇒ Y} → (f ∘ h ≡ k) → (h ≡ g ∘ k)
switch-fgˡ {h = h} {k} pf =
begin
h
↑⟨ cancelLeft isoˡ ⟩
g ∘ (f ∘ h)
↓⟨ ∘-resp-≡ʳ pf ⟩
g ∘ k
∎
where open HomReasoning
.switch-gfˡ : ∀ {W} {h : W ⇒ Y} {k : W ⇒ X} → (g ∘ h ≡ k) → (h ≡ f ∘ k)
switch-gfˡ {h = h} {k} pf =
begin
h
↑⟨ cancelLeft isoʳ ⟩
f ∘ (g ∘ h)
↓⟨ ∘-resp-≡ʳ pf ⟩
f ∘ k
∎
where open HomReasoning
.switch-fgʳ : ∀ {W} {h : Y ⇒ W} {k : X ⇒ W} → (h ∘ f ≡ k) → (h ≡ k ∘ g)
switch-fgʳ {h = h} {k} pf =
begin
h
↑⟨ cancelRight isoʳ ⟩
(h ∘ f) ∘ g
↓⟨ ∘-resp-≡ˡ pf ⟩
k ∘ g
∎
where open HomReasoning
.switch-gfʳ : ∀ {W} {h : X ⇒ W} {k : Y ⇒ W} → (h ∘ g ≡ k) → (h ≡ k ∘ f)
switch-gfʳ {h = h} {k} pf =
begin
h
↑⟨ cancelRight isoˡ ⟩
(h ∘ g) ∘ f
↓⟨ ∘-resp-≡ˡ pf ⟩
k ∘ f
∎
where open HomReasoning
open Switch public
module Yon-Eda {o ℓ e} (C : Category o ℓ e) where
private module C = Category C
open C
open Equiv
record Yon (X Y : Obj) : Set (o ⊔ ℓ ⊔ e) where
field
arr : X ⇒ Y
fun : ∀ {W} (f : W ⇒ X) → (W ⇒ Y)
.ok : ∀ {W} (f : W ⇒ X) → fun f ≡ arr ∘ f
norm : X ⇒ Y
norm = fun id
.norm≡arr : norm ≡ arr
norm≡arr = trans (ok id) identityʳ
record _≡′_ {X Y : Obj} (f g : Yon X Y) : Set (o ⊔ ℓ ⊔ e) where
constructor yeq
field
arr-≡ : Yon.arr f ≡ Yon.arr g
open _≡′_ public using (arr-≡)
module _ {X Y} where
.Yon-refl : Reflexive (_≡′_ {X} {Y})
Yon-refl = yeq refl
.Yon-sym : Symmetric (_≡′_ {X} {Y})
Yon-sym = yeq © sym © arr-≡
.Yon-trans : Transitive (_≡′_ {X} {Y})
Yon-trans eq eq′ = yeq (trans (arr-≡ eq) (arr-≡ eq′))
Yon-id : ∀ {X} → Yon X X
Yon-id = record
{ arr = id
; fun = idᶠ
; ok = λ _ → sym identityˡ
}
Yon-inject : ∀ {X Y} → (X ⇒ Y) → Yon X Y
Yon-inject f = record { arr = f; fun = _∘_ f; ok = λ _ → refl }
Yon-compose : ∀ {X Y Z} → (Yon Y Z) → (Yon X Y) → (Yon X Z)
Yon-compose g f = record
{ arr = g.fun f.arr
; fun = g.fun © f.fun
; ok = λ h → trans (g.ok (f.fun h)) (trans (∘-resp-≡ʳ (f.ok h)) (trans (sym assoc) (sym (∘-resp-≡ˡ (g.ok f.arr)))))
}
where
module g = Yon g
module f = Yon f
.Yon-assoc : ∀ {X Y Z W} (f : Yon Z W) (g : Yon Y Z) (h : Yon X Y) → Yon-compose f (Yon-compose g h) ≣ Yon-compose (Yon-compose f g) h
Yon-assoc f g h = ≣-refl
.Yon-identityˡ : ∀ {X Y} (f : Yon X Y) → Yon-compose Yon-id f ≣ f
Yon-identityˡ f = ≣-refl
.Yon-identityʳ : ∀ {X Y} (f : Yon X Y) → Yon-compose f Yon-id ≡′ f
Yon-identityʳ f = yeq (Yon.norm≡arr f)
.Yon-compose-resp-≡′ : ∀ {X Y Z} {f f′ : Yon Y Z} {g g′ : Yon X Y}
→ f ≡′ f′ → g ≡′ g′
→ Yon-compose f g ≡′ Yon-compose f′ g′
Yon-compose-resp-≡′ {f = f} {f′} {g} {g′} f≡′f′ g≡′g′
= yeq (trans (Yon.ok f (Yon.arr g))
(trans (∘-resp-≡ (arr-≡ f≡′f′) (arr-≡ g≡′g′))
(sym (Yon.ok f′ (Yon.arr g′)))))
record Eda (X Y : Obj) : Set (o ⊔ ℓ ⊔ e) where
field
yon : Yon X Y
fun : ∀ {Z} (f : Yon Y Z) → Yon X Z
.ok : ∀ {Z} (f : Yon Y Z) → fun f ≡′ Yon-compose f yon
norm : Yon X Y
norm = fun Yon-id
open Yon yon public using (arr)
Eda-id : ∀ {X} → Eda X X
Eda-id = record
{ yon = Yon-id
; fun = idᶠ
; ok = yeq © sym © arr-≡ © Yon-identityʳ
}
Eda-inject : ∀ {X Y} → Yon X Y → Eda X Y
Eda-inject f = record { yon = f; fun = flip Yon-compose f; ok = λ _ → yeq refl }
Eda-compose : ∀ {X Y Z} → (Eda Y Z) → (Eda X Y) → (Eda X Z)
Eda-compose {X} {Y} {Z} g f = record
{ yon = f.fun g.yon
; fun = f.fun © g.fun
; ok = λ {W} h → Yon-trans {X} {W} {f.fun (g.fun h)} (f.ok (g.fun h))
(Yon-trans (Yon-compose-resp-≡′ (g.ok h) (Yon-refl {x = f.yon}))
(Yon-sym (Yon-compose-resp-≡′ (Yon-refl {x = h}) (f.ok g.yon))))
}
where
module g = Eda g
module f = Eda f
.Eda-assoc : ∀ {X Y Z W} (f : Eda Z W) (g : Eda Y Z) (h : Eda X Y) → Eda-compose f (Eda-compose g h) ≣ Eda-compose (Eda-compose f g) h
Eda-assoc f g h = ≣-refl
-- .Eda-identityˡ : ∀ {X Y} (f : Eda X Y) → Eda-compose Eda-id f ≣ f
-- Eda-identityˡ f = {!!}
.Eda-identityʳ : ∀ {X Y} (f : Eda X Y) → Eda-compose f Eda-id ≣ f
Eda-identityʳ f = ≣-refl
record NormReasoning {o ℓ e} (C : Category o ℓ e) (o′ ℓ′ : _) : Set (suc o′ ⊔ o ⊔ ℓ ⊔ e ⊔ suc ℓ′) where
private module C = Category C
field
U : Set o′
T : U -> C.Obj
_#⇒_ : U -> U -> Set ℓ′
eval : ∀ {A B} -> A #⇒ B -> T A C.⇒ T B
norm : ∀ {A B} -> A #⇒ B -> T A C.⇒ T B
.norm≡eval : ∀ {A B} (f : A #⇒ B) -> norm f C.≡ eval f
open C.Equiv
open C
infix 4 _IsRelatedTo_
infix 1 begin_
infixr 2 _≈⟨_⟩_ _↓⟨_⟩_ _↑⟨_⟩_ _↓≡⟨_⟩_ _↑≡⟨_⟩_ _↕_
infix 3 _∎
data _IsRelatedTo_ {X Y} (f g : _#⇒_ X Y) : Set e where
relTo : (f∼g : norm f ≡ norm g) → f IsRelatedTo g
.begin_ : ∀ {X Y} {f g : _#⇒_ X Y} → f IsRelatedTo g → eval f ≡ eval g
begin_ {f = f} {g} (relTo f∼g) = trans (sym (norm≡eval f)) (trans f∼g (norm≡eval g))
._↓⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → (norm f ≡ norm g) → g IsRelatedTo h → f IsRelatedTo h
_ ↓⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h)
._↑⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → (norm g ≡ norm f) → g IsRelatedTo h → f IsRelatedTo h
_ ↑⟨ g∼f ⟩ relTo g∼h = relTo (trans (sym g∼f) g∼h)
-- the syntax of the ancients, for compatibility
._≈⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → (norm f ≡ norm g) → g IsRelatedTo h → f IsRelatedTo h
_ ≈⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h)
._↓≡⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → eval f ≡ eval g → g IsRelatedTo h → f IsRelatedTo h
_↓≡⟨_⟩_ f {g} f∼g (relTo g∼h) = relTo (trans (norm≡eval f) (trans f∼g (trans (sym (norm≡eval g)) g∼h)))
._↑≡⟨_⟩_ : ∀ {X Y} (f : _#⇒_ X Y) {g h} → eval g ≡ eval f → g IsRelatedTo h → f IsRelatedTo h
_↑≡⟨_⟩_ f {g} g∼f (relTo g∼h) = relTo (trans (norm≡eval f) (trans (sym g∼f) (trans (sym (norm≡eval g)) g∼h)))
._↕_ : ∀ {X Y} (f : _#⇒_ X Y) {h} → f IsRelatedTo h → f IsRelatedTo h
_ ↕ f∼h = f∼h
._∎ : ∀ {X Y} (f : _#⇒_ X Y) → f IsRelatedTo f
_∎ _ = relTo refl
.by_ : ∀ {X Y} {f g h : X ⇒ Y} -> ((h ≡ h) -> f ≡ g) -> f ≡ g
by eq = eq refl
.computation : ∀ {X Y} (f g : X #⇒ Y) -> norm f ≡ norm g → eval f ≡ eval g
computation f g eq = begin f ↓⟨ eq ⟩ g ∎
module AUReasoning {o ℓ e} (C : Category o ℓ e) where
private module C = Category C
open C
open Equiv
{-
infix 4 _IsRelatedTo_
infix 2 _∎
infixr 2 _≈⟨_⟩_
infixr 2 _↓⟨_⟩_
infixr 2 _↑⟨_⟩_
infixr 2 _↓≡⟨_⟩_
infixr 2 _↑≡⟨_⟩_
infixr 2 _↕_
infix 1 begin_
-}
infixr 8 _∙_
open Yon-Eda C public
data Climb : Rel Obj (o ⊔ ℓ) where
ID : ∀ {X} → Climb X X
leaf : ∀ {X Y} → (X ⇒ Y) → Climb X Y
_branch_ : ∀ {X Y Z} (l : Climb Y Z) (r : Climb X Y) → Climb X Z
interp : ∀ {p} (P : Rel Obj p)
(f-id : ∀ {X} → P X X)
(f-leaf : ∀ {X Y} → X ⇒ Y → P X Y)
(f-branch : ∀ {X Y Z} → P Y Z → P X Y → P X Z)
→ ∀ {X Y} → Climb X Y → P X Y
interp P f-id f-leaf f-branch ID = f-id
interp P f-id f-leaf f-branch (leaf y) = f-leaf y
interp P f-id f-leaf f-branch (l branch r) = f-branch
(interp P f-id f-leaf f-branch l)
(interp P f-id f-leaf f-branch r)
eval : ∀ {X Y} → Climb X Y → X ⇒ Y
eval = interp _⇒_ id idᶠ _∘_
yeval : ∀ {X Y} → Climb X Y → Yon X Y
yeval = interp Yon Yon-id Yon-inject Yon-compose
.yarr : ∀ {X Y} → (t : Climb X Y) → Yon.arr (yeval t) ≡ eval t
yarr ID = refl
yarr (leaf y) = refl
yarr (t branch t1) = trans (Yon.ok (yeval t) (Yon.arr (yeval t1))) (∘-resp-≡ (yarr t) (yarr t1))
eeval : ∀ {X Y} → Climb X Y → Eda X Y
eeval = interp Eda Eda-id (Eda-inject © Yon-inject) Eda-compose
.eyon : ∀ {X Y} → (t : Climb X Y) → Eda.yon (eeval t) ≡′ yeval t
eyon ID = Yon-refl
eyon (leaf y) = Yon-refl
eyon (t branch t1) = Yon-trans (Eda.ok (eeval t1) (Eda.yon (eeval t)))
(Yon-compose-resp-≡′ (eyon t) (eyon t1))
.earr : ∀ {X Y} → (t : Climb X Y) → Eda.arr (eeval t) ≡ eval t
earr t = trans (arr-≡ (eyon t)) (yarr t)
yyeval : ∀ {X Y} → (t : Climb X Y) → (X ⇒ Y)
yyeval = Eda.arr © eeval
record ClimbBuilder (X Y : Obj) {t} (T : Set t) : Set (o ⊔ ℓ ⊔ t) where
field build : T → Climb X Y
instance
leafBuilder : ∀ {X Y} → ClimbBuilder X Y (X ⇒ Y)
leafBuilder = record { build = leaf }
idBuilder : ∀ {X Y} → ClimbBuilder X Y (Climb X Y)
idBuilder = record { build = idᶠ }
_∙_ : ∀ {X Y Z} {s} {S : Set s} {{Sb : ClimbBuilder Y Z S}} (f : S) {t} {T : Set t} {{Tb : ClimbBuilder X Y T}} (g : T) → Climb X Z
_∙_ {{Sb}} f {{Tb}} g = ClimbBuilder.build Sb f branch ClimbBuilder.build Tb g
aureasoning : NormReasoning C o (ℓ ⊔ o)
aureasoning = record
{ U = Obj
; T = λ A → A
; _#⇒_ = Climb
; eval = eval
; norm = yyeval
; norm≡eval = earr
}
open NormReasoning aureasoning public hiding (eval)
{-
data _IsRelatedTo_ {X Y} (f g : Climb X Y) : Set e where
relTo : (f∼g : yyeval f ≡ yyeval g) → f IsRelatedTo g
.begin_ : ∀ {X Y} {f g : Climb X Y} → f IsRelatedTo g → eval f ≡ eval g
begin_ {f = f} {g} (relTo f∼g) = trans (sym (earr f)) (trans f∼g (earr g))
._↓⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → (yyeval f ≡ yyeval g) → g IsRelatedTo h → f IsRelatedTo h
_ ↓⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h)
._↑⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → (yyeval g ≡ yyeval f) → g IsRelatedTo h → f IsRelatedTo h
_ ↑⟨ g∼f ⟩ relTo g∼h = relTo (trans (sym g∼f) g∼h)
-- the syntax of the ancients, for compatibility
._≈⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → (yyeval f ≡ yyeval g) → g IsRelatedTo h → f IsRelatedTo h
_ ≈⟨ f∼g ⟩ relTo g∼h = relTo (trans f∼g g∼h)
._↓≡⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → eval f ≡ eval g → g IsRelatedTo h → f IsRelatedTo h
_↓≡⟨_⟩_ f {g} f∼g (relTo g∼h) = relTo (trans (earr f) (trans f∼g (trans (sym (earr g)) g∼h)))
._↑≡⟨_⟩_ : ∀ {X Y} (f : Climb X Y) {g h} → eval g ≡ eval f → g IsRelatedTo h → f IsRelatedTo h
_↑≡⟨_⟩_ f {g} g∼f (relTo g∼h) = relTo (trans (earr f) (trans (sym g∼f) (trans (sym (earr g)) g∼h)))
{-
-- XXX i want this to work whenever the Edas are equal -- but that probably
-- requires Climb to be indexed by yyeval! oh, for cheap ornamentation.
._↕_ : ∀ {X Y} (f : Climb X Y) {h} → f IsRelatedTo h → f IsRelatedTo h
_ ↕ f∼h = f∼h
-}
._∎ : ∀ {X Y} (f : Climb X Y) → f IsRelatedTo f
_∎ _ = relTo refl
-}
| 29.356115
| 228
| 0.46373
|
235bbd3535af076cdae0860e27f967408f0c4e9e
| 237
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Unit.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
src/data/lib/prim/Agda/Builtin/Unit.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
src/data/lib/prim/Agda/Builtin/Unit.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2021-04-01T18:30:09.000Z
|
2021-04-01T18:30:09.000Z
|
{-# OPTIONS --without-K --safe --no-universe-polymorphism --no-sized-types --no-guardedness #-}
module Agda.Builtin.Unit where
record ⊤ : Set where
instance constructor tt
{-# BUILTIN UNIT ⊤ #-}
{-# COMPILE GHC ⊤ = data () (()) #-}
| 23.7
| 95
| 0.64135
|
df629bb46167d73aa1b55ddffa3f0c080b4f56b1
| 15,233
|
agda
|
Agda
|
Numbers/BinaryNaturals/Multiplication.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Numbers/BinaryNaturals/Multiplication.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Numbers/BinaryNaturals/Multiplication.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Lists.Lists
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Naturals
open import Numbers.BinaryNaturals.Definition
open import Numbers.BinaryNaturals.Addition
open import Semirings.Definition
module Numbers.BinaryNaturals.Multiplication where
_*Binherit_ : BinNat → BinNat → BinNat
a *Binherit b = NToBinNat (binNatToN a *N binNatToN b)
_*B_ : BinNat → BinNat → BinNat
[] *B b = []
(zero :: a) *B b = zero :: (a *B b)
(one :: a) *B b = (zero :: (a *B b)) +B b
private
contr : {a : _} {A : Set a} {l1 l2 : List A} → {x : A} → l1 ≡ [] → l1 ≡ x :: l2 → False
contr {l1 = []} p1 ()
contr {l1 = x :: l1} () p2
*BEmpty : (a : BinNat) → canonical (a *B []) ≡ []
*BEmpty [] = refl
*BEmpty (zero :: a) rewrite *BEmpty a = refl
*BEmpty (one :: a) rewrite *BEmpty a = refl
canonicalDistributesPlus : (a b : BinNat) → canonical (a +B b) ≡ canonical a +B canonical b
canonicalDistributesPlus a b = transitivity ans (+BIsInherited (canonical a) (canonical b) (canonicalIdempotent a) (canonicalIdempotent b))
where
ans : canonical (a +B b) ≡ NToBinNat (binNatToN (canonical a) +N binNatToN (canonical b))
ans rewrite binNatToNIsCanonical a | binNatToNIsCanonical b = equalityCommutative (+BIsInherited' a b)
incrPullsOut : (a b : BinNat) → incr (a +B b) ≡ (incr a) +B b
incrPullsOut [] [] = refl
incrPullsOut [] (zero :: b) = refl
incrPullsOut [] (one :: b) = refl
incrPullsOut (zero :: a) [] = refl
incrPullsOut (zero :: a) (zero :: b) = refl
incrPullsOut (zero :: a) (one :: b) = refl
incrPullsOut (one :: a) [] = refl
incrPullsOut (one :: a) (zero :: b) = applyEquality (zero ::_) (incrPullsOut a b)
incrPullsOut (one :: a) (one :: b) = applyEquality (one ::_) (incrPullsOut a b)
timesZero : (a b : BinNat) → canonical a ≡ [] → canonical (a *B b) ≡ []
timesZero [] b pr = refl
timesZero (zero :: a) b pr with inspect (canonical a)
timesZero (zero :: a) b pr | [] with≡ prA rewrite prA | timesZero a b prA = refl
timesZero (zero :: a) b pr | (a1 :: as) with≡ prA rewrite prA = exFalso (nonEmptyNotEmpty pr)
timesZero'' : (a b : BinNat) → canonical (a *B b) ≡ [] → (canonical a ≡ []) || (canonical b ≡ [])
timesZero'' [] b pr = inl refl
timesZero'' (x :: a) [] pr = inr refl
timesZero'' (zero :: as) (zero :: bs) pr with inspect (canonical as)
timesZero'' (zero :: as) (zero :: bs) pr | y with≡ x with inspect (canonical bs)
timesZero'' (zero :: as) (zero :: bs) pr | [] with≡ prAs | y₁ with≡ prBs rewrite prAs = inl refl
timesZero'' (zero :: as) (zero :: bs) pr | (a1 :: a's) with≡ prAs | [] with≡ prBs rewrite prBs = inr refl
timesZero'' (zero :: as) (zero :: bs) pr | (a1 :: a's) with≡ prAs | (x :: y) with≡ prBs with inspect (canonical (as *B (zero :: bs)))
timesZero'' (zero :: as) (zero :: bs) pr | (a1 :: a's) with≡ prAs | (b1 :: b's) with≡ prBs | [] with≡ pr' with timesZero'' as (zero :: bs) pr'
timesZero'' (zero :: as) (zero :: bs) pr | (a1 :: a's) with≡ prAs | (b1 :: b's) with≡ prBs | [] with≡ pr' | inl x rewrite prAs | prBs | pr' | x = exFalso (nonEmptyNotEmpty x)
timesZero'' (zero :: as) (zero :: bs) pr | (a1 :: a's) with≡ prAs | (b1 :: b's) with≡ prBs | [] with≡ pr' | inr x rewrite prBs | pr' | x = exFalso (nonEmptyNotEmpty x)
timesZero'' (zero :: as) (zero :: bs) pr | (a1 :: a's) with≡ prAs | (b1 :: b's) with≡ prBs | (x :: y) with≡ pr' rewrite prAs | prBs | pr' = exFalso (nonEmptyNotEmpty pr)
timesZero'' (zero :: as) (one :: bs) pr with inspect (canonical as)
timesZero'' (zero :: as) (one :: bs) pr | [] with≡ x rewrite x = inl refl
timesZero'' (zero :: as) (one :: bs) pr | (a1 :: a's) with≡ x with inspect (canonical (as *B (one :: bs)))
timesZero'' (zero :: as) (one :: bs) pr | (a1 :: a's) with≡ x | [] with≡ pr' with timesZero'' as (one :: bs) pr'
timesZero'' (zero :: as) (one :: bs) pr | (a1 :: a's) with≡ x | [] with≡ pr' | inl pr'' rewrite x | pr' | pr'' = exFalso (nonEmptyNotEmpty pr'')
timesZero'' (zero :: as) (one :: bs) pr | (a1 :: a's) with≡ x | (x₁ :: y) with≡ pr' rewrite x | pr' = exFalso (nonEmptyNotEmpty pr)
timesZero'' (one :: as) (zero :: bs) pr with inspect (canonical bs)
timesZero'' (one :: as) (zero :: bs) pr | [] with≡ x rewrite x = inr refl
timesZero'' (one :: as) (zero :: bs) pr | (b1 :: b's) with≡ prB with inspect (canonical ((as *B (zero :: bs)) +B bs))
timesZero'' (one :: as) (zero :: bs) pr | (b1 :: b's) with≡ prB | [] with≡ x rewrite equalityCommutative (+BIsInherited' (as *B (zero :: bs)) bs) = exFalso (nonEmptyNotEmpty (transitivity (equalityCommutative prB) v))
where
t : binNatToN (as *B (zero :: bs)) +N binNatToN bs ≡ 0
t = transitivity (equalityCommutative (nToN _)) (applyEquality binNatToN x)
u : (binNatToN (as *B (zero :: bs)) ≡ 0) && (binNatToN bs ≡ 0)
u = sumZeroImpliesSummandsZero t
v : canonical bs ≡ []
v with u
... | fst ,, snd = binNatToNZero bs snd
timesZero'' (one :: as) (zero :: bs) pr | (b1 :: b's) with≡ prB | (x₁ :: y) with≡ x rewrite prB | x = exFalso (nonEmptyNotEmpty pr)
lemma : {i : Bit} → (a b : BinNat) → canonical a ≡ canonical b → canonical (i :: a) ≡ canonical (i :: b)
lemma {zero} a b pr with inspect (canonical a)
lemma {zero} a b pr | [] with≡ x rewrite x | equalityCommutative pr = refl
lemma {zero} a b pr | (a1 :: as) with≡ x rewrite x | equalityCommutative pr = refl
lemma {one} a b pr = applyEquality (one ::_) pr
binNatToNDistributesPlus : (a b : BinNat) → binNatToN (a +B b) ≡ binNatToN a +N binNatToN b
binNatToNDistributesPlus a b = transitivity (equalityCommutative (binNatToNIsCanonical (a +B b))) (transitivity (applyEquality binNatToN (equalityCommutative (+BIsInherited' a b))) (nToN (binNatToN a +N binNatToN b)))
+BAssociative : (a b c : BinNat) → canonical (a +B (b +B c)) ≡ canonical ((a +B b) +B c)
+BAssociative a b c rewrite equalityCommutative (+BIsInherited' a (b +B c)) | equalityCommutative (+BIsInherited' (a +B b) c) | binNatToNDistributesPlus a b | binNatToNDistributesPlus b c | equalityCommutative (Semiring.+Associative ℕSemiring (binNatToN a) (binNatToN b) (binNatToN c)) = refl
timesOne : (a b : BinNat) → (canonical b) ≡ (one :: []) → canonical (a *B b) ≡ canonical a
timesOne [] b pr = refl
timesOne (zero :: a) b pr with inspect (canonical (a *B b))
timesOne (zero :: a) b pr | [] with≡ prAB with timesZero'' a b prAB
timesOne (zero :: a) b pr | [] with≡ prAB | inl a=0 rewrite a=0 | prAB = refl
timesOne (zero :: a) b pr | [] with≡ prAB | inr b=0 = exFalso (nonEmptyNotEmpty (transitivity (equalityCommutative pr) b=0))
timesOne (zero :: a) b pr | (ab1 :: abs) with≡ prAB with inspect (canonical a)
timesOne (zero :: a) b pr | (ab1 :: abs) with≡ prAB | [] with≡ x = exFalso (nonEmptyNotEmpty (transitivity (equalityCommutative prAB) (timesZero a b x)))
timesOne (zero :: a) b pr | (ab1 :: abs) with≡ prAB | (x₁ :: y) with≡ x rewrite prAB | x | timesOne a b pr = applyEquality (zero ::_) (transitivity (equalityCommutative prAB) x)
timesOne (one :: a) (zero :: b) pr with canonical b
timesOne (one :: a) (zero :: b) () | []
timesOne (one :: a) (zero :: b) () | x :: bl
timesOne (one :: a) (one :: b) pr rewrite canonicalDistributesPlus (a *B (one :: b)) b | ::Inj pr | +BCommutative (canonical (a *B (one :: b))) [] | timesOne a (one :: b) pr = refl
timesZero' : (a b : BinNat) → canonical b ≡ [] → canonical (a *B b) ≡ []
timesZero' [] b pr = refl
timesZero' (zero :: a) b pr with inspect (canonical (a *B b))
timesZero' (zero :: a) b pr | [] with≡ x rewrite x = refl
timesZero' (zero :: a) b pr | (ab1 :: abs) with≡ prAB rewrite prAB = exFalso (nonEmptyNotEmpty (transitivity (equalityCommutative prAB) (timesZero' a b pr)))
timesZero' (one :: a) b pr rewrite canonicalDistributesPlus (zero :: (a *B b)) b | pr | +BCommutative (canonical (zero :: (a *B b))) [] = ans
where
ans : canonical (zero :: (a *B b)) ≡ []
ans with inspect (canonical (a *B b))
ans | [] with≡ x rewrite x = refl
ans | (x₁ :: y) with≡ x rewrite x = exFalso (nonEmptyNotEmpty (transitivity (equalityCommutative x) (timesZero' a b pr)))
canonicalDistributesTimes : (a b : BinNat) → canonical (a *B b) ≡ canonical ((canonical a) *B (canonical b))
canonicalDistributesTimes [] b = refl
canonicalDistributesTimes (zero :: a) b with inspect (canonical a)
canonicalDistributesTimes (zero :: a) b | [] with≡ x rewrite timesZero a b x | x = refl
canonicalDistributesTimes (zero :: a) b | (a1 :: as) with≡ prA with inspect (canonical b)
canonicalDistributesTimes (zero :: a) b | (a1 :: as) with≡ prA | [] with≡ prB rewrite prA | prB = ans
where
ans : canonical (zero :: (a *B b)) ≡ canonical (zero :: ((a1 :: as) *B []))
ans with inspect (canonical ((a1 :: as) *B []))
ans | [] with≡ x rewrite x | timesZero' a b prB = refl
ans | (x₁ :: y) with≡ x = exFalso (nonEmptyNotEmpty (equalityCommutative (transitivity (equalityCommutative (timesZero' (a1 :: as) [] refl)) x)))
canonicalDistributesTimes (zero :: a) b | (a1 :: as) with≡ prA | (b1 :: bs) with≡ prB with inspect (canonical (a *B b))
canonicalDistributesTimes (zero :: a) b | (a1 :: as) with≡ prA | (b1 :: bs) with≡ prB | [] with≡ x with timesZero'' a b x
canonicalDistributesTimes (zero :: a) b | (a1 :: as) with≡ prA | (b1 :: bs) with≡ prB | [] with≡ x | inl a=0 = exFalso (nonEmptyNotEmpty (transitivity (equalityCommutative prA) a=0))
canonicalDistributesTimes (zero :: a) b | (a1 :: as) with≡ prA | (b1 :: bs) with≡ prB | [] with≡ x | inr b=0 = exFalso (nonEmptyNotEmpty (transitivity (equalityCommutative prB) b=0))
canonicalDistributesTimes (zero :: a) b | (a1 :: as) with≡ prA | (b1 :: bs) with≡ prB | (ab1 :: abs) with≡ x rewrite prA | prB | x = ans
where
ans : zero :: ab1 :: abs ≡ canonical (zero :: ((a1 :: as) *B (b1 :: bs)))
ans rewrite equalityCommutative prA | equalityCommutative prB | equalityCommutative (canonicalDistributesTimes a b) | x = refl
canonicalDistributesTimes (one :: a) b = transitivity (canonicalDistributesPlus (zero :: (a *B b)) b) (transitivity (transitivity (applyEquality (_+B canonical b) (transitivity (equalityCommutative (canonicalAscends'' (a *B b))) (transitivity (applyEquality (λ i → canonical (zero :: i)) (canonicalDistributesTimes a b)) (canonicalAscends'' (canonical a *B canonical b))))) (applyEquality (λ i → canonical (zero :: (canonical a *B canonical b)) +B i) (canonicalIdempotent b))) (equalityCommutative (canonicalDistributesPlus (zero :: (canonical a *B canonical b)) (canonical b))))
NToBinNatDistributesPlus : (a b : ℕ) → NToBinNat (a +N b) ≡ NToBinNat a +B NToBinNat b
NToBinNatDistributesPlus zero b = refl
NToBinNatDistributesPlus (succ a) b with inspect (NToBinNat a)
... | bl with≡ prA with inspect (NToBinNat (a +N b))
... | q with≡ prAB = transitivity (applyEquality incr (NToBinNatDistributesPlus a b)) (incrPullsOut (NToBinNat a) (NToBinNat b))
timesCommutative : (a b : BinNat) → canonical (a *B b) ≡ canonical (b *B a)
timesCommLemma : (a b : BinNat) → canonical (zero :: (b *B a)) ≡ canonical (b *B (zero :: a))
timesCommLemma a b rewrite timesCommutative b (zero :: a) | equalityCommutative (canonicalAscends'' {zero} (b *B a)) | equalityCommutative (canonicalAscends'' {zero} (a *B b)) | timesCommutative b a = refl
timesCommutative [] b rewrite timesZero' b [] refl = refl
timesCommutative (x :: a) [] rewrite timesZero' (x :: a) [] refl = refl
timesCommutative (zero :: as) (zero :: b) rewrite equalityCommutative (canonicalAscends'' {zero} (as *B (zero :: b))) | timesCommutative as (zero :: b) | canonicalAscends'' {zero} (zero :: b *B as) | equalityCommutative (canonicalAscends'' {zero} (b *B (zero :: as))) | timesCommutative b (zero :: as) | canonicalAscends'' {zero} (zero :: (as *B b)) = ans
where
ans : canonical (zero :: zero :: (b *B as)) ≡ canonical (zero :: zero :: (as *B b))
ans rewrite equalityCommutative (canonicalAscends'' {zero} (zero :: (b *B as))) | equalityCommutative (canonicalAscends'' {zero} (b *B as)) | timesCommutative b as | canonicalAscends'' {zero} (as *B b) | canonicalAscends'' {zero} (zero :: (as *B b)) = refl
timesCommutative (zero :: as) (one :: b) = transitivity (equalityCommutative (canonicalAscends'' (as *B (one :: b)))) (transitivity (applyEquality (λ i → canonical (zero :: i)) (timesCommutative as (one :: b))) (transitivity (applyEquality (λ i → canonical (zero :: i)) ans) (canonicalAscends'' ((b *B (zero :: as)) +B as))))
where
ans : canonical ((zero :: (b *B as)) +B as) ≡ canonical ((b *B (zero :: as)) +B as)
ans rewrite canonicalDistributesPlus (zero :: (b *B as)) as | canonicalDistributesPlus (b *B (zero :: as)) as = applyEquality (_+B canonical as) (timesCommLemma as b)
timesCommutative (one :: as) (zero :: bs) = transitivity (equalityCommutative (canonicalAscends'' ((as *B (zero :: bs)) +B bs))) (transitivity (applyEquality (λ i → canonical (zero :: i)) ans) (canonicalAscends'' (bs *B (one :: as))))
where
ans : canonical ((as *B (zero :: bs)) +B bs) ≡ canonical (bs *B (one :: as))
ans rewrite timesCommutative bs (one :: as) | canonicalDistributesPlus (as *B (zero :: bs)) bs | canonicalDistributesPlus (zero :: (as *B bs)) bs = applyEquality (_+B canonical bs) (equalityCommutative (timesCommLemma bs as))
timesCommutative (one :: as) (one :: bs) = applyEquality (one ::_) (transitivity (canonicalDistributesPlus (as *B (one :: bs)) bs) (transitivity (transitivity (applyEquality (_+B canonical bs) (timesCommutative as (one :: bs))) (transitivity ans (equalityCommutative (applyEquality (_+B canonical as) (timesCommutative bs (one :: as)))))) (equalityCommutative (canonicalDistributesPlus (bs *B (one :: as)) as))))
where
ans : canonical ((zero :: (bs *B as)) +B as) +B canonical bs ≡ canonical ((zero :: (as *B bs)) +B bs) +B canonical as
ans rewrite equalityCommutative (canonicalDistributesPlus ((zero :: (bs *B as)) +B as) bs) | equalityCommutative (canonicalDistributesPlus ((zero :: (as *B bs)) +B bs) as) | equalityCommutative (+BAssociative (zero :: (bs *B as)) as bs) | equalityCommutative (+BAssociative (zero :: (as *B bs)) bs as) | canonicalDistributesPlus (zero :: (bs *B as)) (as +B bs) | canonicalDistributesPlus (zero :: (as *B bs)) (bs +B as) | equalityCommutative (canonicalAscends'' {zero} (bs *B as)) | timesCommutative bs as | canonicalAscends'' {zero} (as *B bs) | +BCommutative as bs = refl
*BIsInherited : (a b : BinNat) → a *Binherit b ≡ canonical (a *B b)
*BIsInherited a b = transitivity (applyEquality NToBinNat t) (transitivity (binToBin (canonical (a *B b))) (equalityCommutative (canonicalIdempotent (a *B b))))
where
ans : (a b : BinNat) → binNatToN a *N binNatToN b ≡ binNatToN (a *B b)
ans [] b = refl
ans (zero :: a) b rewrite equalityCommutative (ans a b) = equalityCommutative (Semiring.*Associative ℕSemiring 2 (binNatToN a) (binNatToN b))
ans (one :: a) b rewrite binNatToNDistributesPlus (zero :: (a *B b)) b | Semiring.commutative ℕSemiring (binNatToN b) ((2 *N (binNatToN a)) *N (binNatToN b)) | equalityCommutative (ans a b) = applyEquality (_+N binNatToN b) (equalityCommutative (Semiring.*Associative ℕSemiring 2 (binNatToN a) (binNatToN b)))
t : (binNatToN a *N binNatToN b) ≡ binNatToN (canonical (a *B b))
t = transitivity (ans a b) (equalityCommutative (binNatToNIsCanonical (a *B b)))
| 83.240437
| 579
| 0.648067
|
d0fb3bffb75d012a4d51dc62624085af07dec009
| 355
|
agda
|
Agda
|
test/Fail/RewritingNotSafe.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/RewritingNotSafe.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/RewritingNotSafe.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-08-26
{-# OPTIONS --rewriting #-} -- Should give error
open import Agda.Builtin.Equality
open import Common.List
{-# BUILTIN REWRITE _≡_ #-}
lengthMap : {A B : Set} (f : A → B) (xs : List A) →
length (map f xs) ≡ length xs
lengthMap f [] = refl
lengthMap f (x ∷ xs) rewrite lengthMap f xs = refl
{-# REWRITE lengthMap #-}
| 23.666667
| 51
| 0.622535
|
1c6ea96f7b655abd92dda486d6cd0a54ed3e57bd
| 428
|
agda
|
Agda
|
test/LibSucceed/InstanceArguments/01-arguments.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/LibSucceed/InstanceArguments/01-arguments.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/LibSucceed/InstanceArguments/01-arguments.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS --verbose tc.constr.findInScope:15 #-}
module InstanceArguments.01-arguments where
data T : Set where
instance tt : T
data A : Set where
instance mkA : A
mkA2 : T → A
giveA : ⦃ a : A ⦄ → A
giveA {{a}} = a
test : A → T
test a = tt
test2 : T
test2 = test giveA
id : {A : Set} → A → A
id v = v
test5 : T → T
test5 = id
⋯ : {A : Set} → {{a : A}} → A
⋯ {{a}} = a
--giveA' : {{a : A}} → A
--giveA' = ⋯
| 12.969697
| 53
| 0.525701
|
0e8739882df7d262e6d632d1ddeeca29f44c66d5
| 1,363
|
agda
|
Agda
|
test/Fail/TypeConstructorsWhichPreserveGuardedness1.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/TypeConstructorsWhichPreserveGuardedness1.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Fail/TypeConstructorsWhichPreserveGuardedness1.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- Note that the flag --guardedness-preserving-type-constructors is
-- not (should not be) enabled in this module.
module TypeConstructorsWhichPreserveGuardedness1 where
open import Common.Coinduction
record ⊤ : Set where
data _⊎_ (A B : Set) : Set where
inj₁ : A → A ⊎ B
inj₂ : B → A ⊎ B
record ∃ {A : Set} (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
data Rec (A : ∞ Set) : Set where
fold : ♭ A → Rec A
module ℕ₁ where
-- Without the flag, the following is non-terminating,
-- hence, not reduced.
{-# NON_TERMINATING #-}
ℕ : Set
ℕ = ⊤ ⊎ Rec (♯ ℕ)
zero : ℕ
zero = inj₁ _ -- yields a type error since ℕ does not reduce
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)
module ℕ₂ where
data ℕC : Set where
′zero : ℕC
′suc : ℕC
mutual
ℕ : Set
ℕ = ∃ λ (c : ℕC) → ℕ′ c
ℕ′ : ℕC → Set
ℕ′ ′zero = ⊤
ℕ′ ′suc = Rec (♯ ℕ)
zero : ℕ
zero = (′zero , _)
suc : ℕ → ℕ
suc n = (′suc , fold n)
ℕ-rec : (P : ℕ → Set) →
P zero →
(∀ n → P n → P (suc n)) →
∀ n → P n
ℕ-rec P z s (′zero , _) = z
ℕ-rec P z s (′suc , fold n) = s n (ℕ-rec P z s n)
| 19.197183
| 67
| 0.507704
|
4ac1ed730d146597a317cf36a8623d32aa129b8e
| 493
|
agda
|
Agda
|
test/interaction/Issue2407-u.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/interaction/Issue2407-u.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/interaction/Issue2407-u.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- {-# OPTIONS -v tc.cover:20 #-}
-- Andreas, 2017-01-18, issue #2407
-- If underscores are not preserved (issue #819),
-- the case split fails due to size constraints.
open import Common.Size
data D (i : Size) : (j : Size< ↑ i) → Set where
c : ∀ (j : Size< ↑ i) (k : Size< ↑ j)
→ D i j
→ D j k
→ D i k
split-u : ∀ i (j : Size< ↑ i) → D i j → Set
split-u _ _ x = {!x!} -- split on x
-- Expected: splitting on x succeeds with
-- split-u _ _ (c j k x x₁) = {!!}
| 22.409091
| 49
| 0.533469
|
50970f679e04c68d876953008a825628505e796f
| 638
|
agda
|
Agda
|
src/Categories/Functor/Construction/Zero.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Functor/Construction/Zero.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Functor/Construction/Zero.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Construction.Zero where
-- The Zero functor maps everything to the initial object of a
-- category (when it exists). Note quite const.
open import Level
open import Categories.Category
open import Categories.Functor using (Functor)
open import Categories.Object.Initial
private
variable
o ℓ e : Level
C D : Category o ℓ e
Zero : Initial D → Functor C D
Zero {D = D} init = record
{ F₀ = λ _ → ⊥
; F₁ = λ _ → id
; identity = Equiv.refl
; homomorphism = Equiv.sym identity²
; F-resp-≈ = λ _ → Equiv.refl
}
where
open Initial init
open Category D
| 22
| 62
| 0.688088
|
fbff2710b40d4457aaa2208ac4407eb0e5b6c8e9
| 2,394
|
agda
|
Agda
|
ON/ON.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
ON/ON.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
ON/ON.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --copatterns --sized-types #-}
open import Function
open import Data.Unit as Unit renaming (tt to ∗)
open import Data.List as List
TyCtx = List ⊤
data TyVar : (Γ : TyCtx) → Set where
zero : ∀{Γ} → TyVar (∗ ∷ Γ)
succ : ∀{Γ} → (x : TyVar Γ) → TyVar (∗ ∷ Γ)
data Type (Γ : TyCtx) : Set where
unit : Type Γ
var : (x : TyVar Γ) → Type Γ
_⊕_ : (t₁ : Type Γ) (t₂ : Type Γ) → Type Γ
μ : (t : Type (_ ∷ Γ)) → Type Γ
_⊗_ : (t₁ : Type Γ) (t₂ : Type Γ) → Type Γ
_⇒_ : (t₁ : Type []) (t₂ : Type Γ) → Type Γ
ν : (t : Type (_ ∷ Γ)) → Type Γ
-- | Variable renaming in types
_▹_ : (Γ Δ : TyCtx) → Set
Γ ▹ Δ = TyVar Γ → TyVar Δ
{-
rename : {Γ Δ : TyCtx} → (ρ : Γ ▹ Δ) → Type Γ → Type Δ
rename ρ unit = unit
rename ρ (var x) = var (ρ ∗ x)
rename ρ (t₁ ⊕ t₂) = rename ρ t₁ ⊕ rename ρ t₂
rename {Γ} {Δ} ρ (μ t) = μ (rename ρ' t)
where
ρ' : (∗ ∷ Γ) ▹ (∗ ∷ Δ)
ρ' = ?
-- ρ' = id {[ ∗ ]} ⧻ ρ
rename ρ (t₁ ⊗ t₂) = rename ρ t₁ ⊗ rename ρ t₂
rename ρ (t₁ ⇒ t₂) = t₁ ⇒ rename ρ t₂
rename {Γ} {Δ} ρ (ν t) = ν (rename ρ' t)
where
ρ' : (∗ ∷ Γ) ▹ (∗ ∷ Δ)
ρ' = ?
-- ρ' = ctx-id {[ ∗ ]} ⧻ ρ
-------------------------
---- Generating structure on contexts (derived from renaming)
weaken : {Γ : TyCtx} (Δ : TyCtx) → Type Γ -> Type (Δ ++ Γ)
weaken {Γ} Δ = rename {Γ} {Δ ++ Γ} ?
exchange : (Γ Δ : TyCtx) → Type (Γ ++ Δ) -> Type (Δ ++ Γ)
exchange Γ Δ = rename [ i₂ {Δ} {Γ} , i₁ {Δ} {Γ} ]
contract : {Γ : TyCtx} → Type (Γ ∐ Γ) -> Type Γ
contract = rename [ ctx-id , ctx-id ]
-}
Subst : TyCtx → TyCtx → Set
Subst Γ Δ = TyVar Γ → Type Δ
update : ∀{Γ Δ : TyCtx} → Subst Γ Δ → Type Δ → (Subst (∗ ∷ Γ) Δ)
update σ a zero = a
update σ _ (succ x) = σ x
lift : ∀{Γ Δ} → Subst Γ Δ → Subst (∗ ∷ Γ) (∗ ∷ Δ)
lift σ zero = {!!}
lift σ (succ x) = {!!}
-- | Simultaneous substitution
subst : {Γ Δ : TyCtx} → (σ : Subst Γ Δ) → Type Γ → Type Δ
subst σ unit = unit
subst σ (var x) = σ x
subst σ (t₁ ⊕ t₂) = subst σ t₁ ⊕ subst σ t₂
subst {Γ} {Δ} σ (μ t) = μ (subst (lift σ) t)
subst σ (t₁ ⊗ t₂) = subst σ t₁ ⊗ subst σ t₂
subst σ (t₁ ⇒ t₂) = t₁ ⇒ subst σ t₂
subst {Γ} {Δ} σ (ν t) = ν (subst (lift σ) t)
data Term : Set where
| 29.195122
| 64
| 0.457811
|
20964c5fb7770914a10bde3fe49ca1af56b190b8
| 819
|
agda
|
Agda
|
vendor/stdlib/src/Relation/Binary/Props/Poset.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Relation/Binary/Props/Poset.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Relation/Binary/Props/Poset.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Properties satisfied by posets
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.Props.Poset (p : Poset) where
open Relation.Binary.Poset p hiding (trans)
import Relation.Binary.NonStrictToStrict as Conv
open Conv _≈_ _≤_
------------------------------------------------------------------------
-- Posets can be turned into strict partial orders
strictPartialOrder : StrictPartialOrder
strictPartialOrder = record
{ isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = irrefl
; trans = trans isPartialOrder
; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
}
}
open StrictPartialOrder strictPartialOrder
| 30.333333
| 72
| 0.531136
|
1cf4e6b7563cd27e648aea641a488c150b2721cb
| 13,871
|
agda
|
Agda
|
Cubical/Algebra/Matrix.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Matrix.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Matrix.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Matrix where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat hiding (_+_ ; _·_; +-comm ; +-assoc; ·-assoc)
open import Cubical.Data.Vec
open import Cubical.Data.Sigma.Base
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Ring
open Iso
private
variable
ℓ : Level
A : Type ℓ
-- Equivalence between Vec matrix and Fin function matrix
FinMatrix : (A : Type ℓ) (m n : ℕ) → Type ℓ
FinMatrix A m n = FinVec (FinVec A n) m
VecMatrix : (A : Type ℓ) (m n : ℕ) → Type ℓ
VecMatrix A m n = Vec (Vec A n) m
FinMatrix→VecMatrix : {m n : ℕ} → FinMatrix A m n → VecMatrix A m n
FinMatrix→VecMatrix M = FinVec→Vec (λ fm → FinVec→Vec (M fm))
VecMatrix→FinMatrix : {m n : ℕ} → VecMatrix A m n → FinMatrix A m n
VecMatrix→FinMatrix M fn fm = lookup fm (lookup fn M)
FinMatrix→VecMatrix→FinMatrix : {m n : ℕ} (M : FinMatrix A m n)
→ VecMatrix→FinMatrix (FinMatrix→VecMatrix M) ≡ M
FinMatrix→VecMatrix→FinMatrix {m = zero} M = funExt (⊥.rec ∘ ¬Fin0)
FinMatrix→VecMatrix→FinMatrix {n = zero} M = funExt₂ (λ _ → ⊥.rec ∘ ¬Fin0)
FinMatrix→VecMatrix→FinMatrix {m = suc m} {n = suc n} M = funExt₂ goal
where
goal : (fm : Fin (suc m)) (fn : Fin (suc n))
→ VecMatrix→FinMatrix (_ ∷ FinMatrix→VecMatrix (M ∘ suc)) fm fn ≡ M fm fn
goal zero zero = refl
goal zero (suc fn) i = FinVec→Vec→FinVec (M zero ∘ suc) i fn
goal (suc fm) fn i = FinMatrix→VecMatrix→FinMatrix (M ∘ suc) i fm fn
VecMatrix→FinMatrix→VecMatrix : {m n : ℕ} (M : VecMatrix A m n)
→ FinMatrix→VecMatrix (VecMatrix→FinMatrix M) ≡ M
VecMatrix→FinMatrix→VecMatrix {m = zero} [] = refl
VecMatrix→FinMatrix→VecMatrix {m = suc m} (M ∷ MS) i =
Vec→FinVec→Vec M i ∷ VecMatrix→FinMatrix→VecMatrix MS i
FinMatrixIsoVecMatrix : (A : Type ℓ) (m n : ℕ) → Iso (FinMatrix A m n) (VecMatrix A m n)
fun (FinMatrixIsoVecMatrix A m n) = FinMatrix→VecMatrix
inv (FinMatrixIsoVecMatrix A m n) = VecMatrix→FinMatrix
rightInv (FinMatrixIsoVecMatrix A m n) = VecMatrix→FinMatrix→VecMatrix
leftInv (FinMatrixIsoVecMatrix A m n) = FinMatrix→VecMatrix→FinMatrix
FinMatrix≃VecMatrix : {m n : ℕ} → FinMatrix A m n ≃ VecMatrix A m n
FinMatrix≃VecMatrix {_} {A} {m} {n} = isoToEquiv (FinMatrixIsoVecMatrix A m n)
FinMatrix≡VecMatrix : (A : Type ℓ) (m n : ℕ) → FinMatrix A m n ≡ VecMatrix A m n
FinMatrix≡VecMatrix _ _ _ = ua FinMatrix≃VecMatrix
-- Define abelian group structure on matrices
module FinMatrixAbGroup (G' : AbGroup ℓ) where
open AbGroupStr (snd G') renaming ( is-set to isSetG )
private G = ⟨ G' ⟩
zeroFinMatrix : ∀ {m n} → FinMatrix G m n
zeroFinMatrix _ _ = 0g
negFinMatrix : ∀ {m n} → FinMatrix G m n → FinMatrix G m n
negFinMatrix M i j = - M i j
addFinMatrix : ∀ {m n} → FinMatrix G m n → FinMatrix G m n → FinMatrix G m n
addFinMatrix M N i j = M i j + N i j
isSetFinMatrix : ∀ {m n} → isSet (FinMatrix G m n)
isSetFinMatrix = isSetΠ2 λ _ _ → isSetG
addFinMatrixAssoc : ∀ {m n} → (M N K : FinMatrix G m n)
→ addFinMatrix M (addFinMatrix N K) ≡ addFinMatrix (addFinMatrix M N) K
addFinMatrixAssoc M N K i j k = assoc (M j k) (N j k) (K j k) i
addFinMatrix0r : ∀ {m n} → (M : FinMatrix G m n)
→ addFinMatrix M zeroFinMatrix ≡ M
addFinMatrix0r M i j k = rid (M j k) i
addFinMatrix0l : ∀ {m n} → (M : FinMatrix G m n)
→ addFinMatrix zeroFinMatrix M ≡ M
addFinMatrix0l M i j k = lid (M j k) i
addFinMatrixNegMatrixr : ∀ {m n} → (M : FinMatrix G m n)
→ addFinMatrix M (negFinMatrix M) ≡ zeroFinMatrix
addFinMatrixNegMatrixr M i j k = invr (M j k) i
addFinMatrixNegMatrixl : ∀ {m n} → (M : FinMatrix G m n)
→ addFinMatrix (negFinMatrix M) M ≡ zeroFinMatrix
addFinMatrixNegMatrixl M i j k = invl (M j k) i
addFinMatrixComm : ∀ {m n} → (M N : FinMatrix G m n)
→ addFinMatrix M N ≡ addFinMatrix N M
addFinMatrixComm M N i k l = comm (M k l) (N k l) i
FinMatrixAbGroup : (m n : ℕ) → AbGroup ℓ
FinMatrixAbGroup m n =
makeAbGroup {G = FinMatrix G m n} zeroFinMatrix addFinMatrix negFinMatrix
isSetFinMatrix addFinMatrixAssoc addFinMatrix0r
addFinMatrixNegMatrixr addFinMatrixComm
-- Define a abelian group structure on vector matrices and prove that
-- it is equal to FinMatrixAbGroup using the SIP
module _ (G' : AbGroup ℓ) where
open AbGroupStr (snd G')
private G = ⟨ G' ⟩
zeroVecMatrix : ∀ {m n} → VecMatrix G m n
zeroVecMatrix = replicate (replicate 0g)
negVecMatrix : ∀ {m n} → VecMatrix G m n → VecMatrix G m n
negVecMatrix = map (map (λ x → - x))
addVec : ∀ {m} → Vec G m → Vec G m → Vec G m
addVec [] [] = []
addVec (x ∷ xs) (y ∷ ys) = x + y ∷ addVec xs ys
addVecMatrix : ∀ {m n} → VecMatrix G m n → VecMatrix G m n → VecMatrix G m n
addVecMatrix [] [] = []
addVecMatrix (M ∷ MS) (N ∷ NS) = addVec M N ∷ addVecMatrix MS NS
open FinMatrixAbGroup
-- Proof that FinMatrix→VecMatrix is a group homorphism
FinMatrix→VecMatrixHomAdd : (m n : ℕ) (M N : FinMatrix G m n)
→ FinMatrix→VecMatrix (addFinMatrix G' M N) ≡
addVecMatrix (FinMatrix→VecMatrix M) (FinMatrix→VecMatrix N)
FinMatrix→VecMatrixHomAdd zero n M N = refl
FinMatrix→VecMatrixHomAdd (suc m) n M N =
λ i → lem n (M zero) (N zero) i
∷ FinMatrix→VecMatrixHomAdd m n (λ i j → M (suc i) j) (λ i j → N (suc i) j) i
where
lem : (n : ℕ) (V W : FinVec G n)
→ FinVec→Vec (λ j → V j + W j) ≡ addVec (FinVec→Vec V) (FinVec→Vec W)
lem zero V W = refl
lem (suc n) V W = λ i → V zero + W zero ∷ lem n (V ∘ suc) (W ∘ suc) i
-- Combine everything to get an induced abelian group structure of
-- VecMatrix that is equal to the one on FinMatrix
VecMatrixAbGroup : (m n : ℕ) → AbGroup ℓ
VecMatrixAbGroup m n =
InducedAbGroup (FinMatrixAbGroup G' m n) addVecMatrix
FinMatrix≃VecMatrix (FinMatrix→VecMatrixHomAdd m n)
FinMatrixAbGroup≡VecMatrixAbGroup : (m n : ℕ) → FinMatrixAbGroup G' m n ≡ VecMatrixAbGroup m n
FinMatrixAbGroup≡VecMatrixAbGroup m n =
InducedAbGroupPath (FinMatrixAbGroup G' m n) addVecMatrix
FinMatrix≃VecMatrix (FinMatrix→VecMatrixHomAdd m n)
-- Define identity matrix and matrix multiplication for FinMatrix and
-- prove that square matrices form a ring
module _ (R' : Ring ℓ) where
open RingStr (snd R') renaming ( is-set to isSetR )
open RingTheory R'
open FinMatrixAbGroup (_ , abgroupstr _ _ _ (snd R' .RingStr.+IsAbGroup))
private R = ⟨ R' ⟩
oneFinMatrix : ∀ {n} → FinMatrix R n n
oneFinMatrix i j = if i == j then 1r else 0r
-- TODO: upstream and state for monoids
∑ : ∀ {n} → FinVec R n → R
∑ = foldrFin _+_ 0r
mulFinMatrix : ∀ {m1 m2 m3} → FinMatrix R m1 m2 → FinMatrix R m2 m3 → FinMatrix R m1 m3
mulFinMatrix M N i k = ∑ λ j → M i j · N j k
-- Properties
sumVecExt : ∀ {n} → {V W : FinVec R n} → ((i : Fin n) → V i ≡ W i) → ∑ V ≡ ∑ W
sumVecExt {n = zero} _ = refl
sumVecExt {n = suc n} h i = h zero i + sumVecExt (h ∘ suc) i
sumVecSplit : ∀ {n} → (V W : FinVec R n) → ∑ (λ i → V i + W i) ≡ ∑ V + ∑ W
sumVecSplit {n = zero} V W = sym (+Rid 0r)
sumVecSplit {n = suc n} V W =
V zero + W zero + ∑ (λ i → V (suc i) + W (suc i)) ≡⟨ (λ i → V zero + W zero + sumVecSplit (V ∘ suc) (W ∘ suc) i) ⟩
V zero + W zero + (∑ (V ∘ suc) + ∑ (W ∘ suc)) ≡⟨ sym (+Assoc _ _ _) ⟩
V zero + (W zero + (∑ (V ∘ suc) + ∑ (W ∘ suc))) ≡⟨ cong (λ x → V zero + x) (+Assoc-comm1 _ _ _) ⟩
V zero + (∑ (V ∘ suc) + (W zero + (∑ (W ∘ suc)))) ≡⟨ +Assoc _ _ _ ⟩
V zero + ∑ (V ∘ suc) + (W zero + ∑ (W ∘ suc)) ∎
sumVec0r : (n : ℕ) → ∑ (λ (i : Fin n) → 0r) ≡ 0r
sumVec0r zero = refl
sumVec0r (suc n) = cong (λ x → 0r + x) (sumVec0r n) ∙ +Rid 0r
sumVecExchange : ∀ {m n} → (M : FinMatrix R m n) → ∑ (λ i → ∑ (λ j → M i j)) ≡ ∑ (λ j → ∑ (λ i → M i j))
sumVecExchange {m = zero} {n = n} M = sym (sumVec0r n)
sumVecExchange {m = suc m} {n = zero} M = cong (λ x → 0r + x) (sumVec0r m) ∙ +Rid 0r
sumVecExchange {m = suc m} {n = suc n} M =
let a = M zero zero
L = ∑ λ j → M zero (suc j)
C = ∑ λ i → M (suc i) zero
N = ∑ λ i → ∑ λ j → M (suc i) (suc j)
-- N reindexed
N' = ∑ λ j → ∑ λ i → M (suc i) (suc j)
in a + L + ∑ (λ i → ∑ (λ j → M (suc i) j)) ≡⟨ (λ k → a + L + sumVecSplit (λ i → M (suc i) zero) (λ i → ∑ (λ j → M (suc i) (suc j))) k) ⟩
a + L + (C + N) ≡⟨ (λ k → a + L + (C + sumVecExchange (λ i j → M (suc i) (suc j)) k)) ⟩
a + L + (C + N') ≡⟨ sym (+Assoc _ _ _) ⟩
a + (L + (C + N')) ≡⟨ (λ k → a + +Assoc-comm1 L C N' k) ⟩
a + (C + (L + N')) ≡⟨ +Assoc _ _ _ ⟩
a + C + (L + N') ≡⟨ (λ k → a + C + sumVecSplit (λ j → M zero (suc j)) (λ j → ∑ (λ i → M (suc i) (suc j))) (~ k)) ⟩
a + C + ∑ (λ j → ∑ (λ i → M i (suc j))) ∎
sumVecMulrdist : ∀ {n} → (x : R) → (V : FinVec R n)
→ x · ∑ V ≡ ∑ λ i → x · V i
sumVecMulrdist {n = zero} x _ = 0RightAnnihilates x
sumVecMulrdist {n = suc n} x V =
x · (V zero + ∑ (V ∘ suc)) ≡⟨ ·Rdist+ _ _ _ ⟩
x · V zero + x · ∑ (V ∘ suc) ≡⟨ (λ i → x · V zero + sumVecMulrdist x (V ∘ suc) i) ⟩
x · V zero + ∑ (λ i → x · V (suc i)) ∎
sumVecMulldist : ∀ {n} → (x : R) → (V : FinVec R n)
→ (∑ V) · x ≡ ∑ λ i → V i · x
sumVecMulldist {n = zero} x _ = 0LeftAnnihilates x
sumVecMulldist {n = suc n} x V =
(V zero + ∑ (V ∘ suc)) · x ≡⟨ ·Ldist+ _ _ _ ⟩
V zero · x + (∑ (V ∘ suc)) · x ≡⟨ (λ i → V zero · x + sumVecMulldist x (V ∘ suc) i) ⟩
V zero · x + ∑ (λ i → V (suc i) · x) ∎
sumVecMulr0 : ∀ {n} → (V : FinVec R n) → ∑ (λ i → V i · 0r) ≡ 0r
sumVecMulr0 V = sym (sumVecMulldist 0r V) ∙ 0RightAnnihilates _
sumVecMul0r : ∀ {n} → (V : FinVec R n) → ∑ (λ i → 0r · V i) ≡ 0r
sumVecMul0r V = sym (sumVecMulrdist 0r V) ∙ 0LeftAnnihilates _
sumVecMulr1 : (n : ℕ) (V : FinVec R n) → (j : Fin n) → ∑ (λ i → V i · (if i == j then 1r else 0r)) ≡ V j
sumVecMulr1 (suc n) V zero = (λ k → ·Rid (V zero) k + sumVecMulr0 (V ∘ suc) k) ∙ +Rid (V zero)
sumVecMulr1 (suc n) V (suc j) =
(λ i → 0RightAnnihilates (V zero) i + ∑ (λ x → V (suc x) · (if x == j then 1r else 0r)))
∙∙ +Lid _ ∙∙ sumVecMulr1 n (V ∘ suc) j
sumVecMul1r : (n : ℕ) (V : FinVec R n) → (j : Fin n) → ∑ (λ i → (if j == i then 1r else 0r) · V i) ≡ V j
sumVecMul1r (suc n) V zero = (λ k → ·Lid (V zero) k + sumVecMul0r (V ∘ suc) k) ∙ +Rid (V zero)
sumVecMul1r (suc n) V (suc j) =
(λ i → 0LeftAnnihilates (V zero) i + ∑ (λ i → (if j == i then 1r else 0r) · V (suc i)))
∙∙ +Lid _ ∙∙ sumVecMul1r n (V ∘ suc) j
mulFinMatrixAssoc : ∀ {m n k l} → (M : FinMatrix R m n) → (N : FinMatrix R n k) → (K : FinMatrix R k l)
→ mulFinMatrix M (mulFinMatrix N K) ≡ mulFinMatrix (mulFinMatrix M N) K
mulFinMatrixAssoc M N K = funExt₂ λ i j →
∑ (λ k → M i k · ∑ (λ l → N k l · K l j)) ≡⟨ sumVecExt (λ k → sumVecMulrdist (M i k) (λ l → N k l · K l j)) ⟩
∑ (λ k → ∑ (λ l → M i k · (N k l · K l j))) ≡⟨ sumVecExt (λ k → sumVecExt (λ l → ·Assoc (M i k) (N k l) (K l j))) ⟩
∑ (λ k → ∑ (λ l → M i k · N k l · K l j)) ≡⟨ sumVecExchange (λ k l → M i k · N k l · K l j) ⟩
∑ (λ l → ∑ (λ k → M i k · N k l · K l j)) ≡⟨ sumVecExt (λ l → sym (sumVecMulldist (K l j) (λ k → M i k · N k l))) ⟩
∑ (λ l → ∑ (λ k → M i k · N k l) · K l j) ∎
mulFinMatrixr1 : ∀ {m n} → (M : FinMatrix R m n) → mulFinMatrix M oneFinMatrix ≡ M
mulFinMatrixr1 M = funExt₂ λ i j → sumVecMulr1 _ (M i) j
mulFinMatrix1r : ∀ {m n} → (M : FinMatrix R m n) → mulFinMatrix oneFinMatrix M ≡ M
mulFinMatrix1r M = funExt₂ λ i j → sumVecMul1r _ (λ x → M x j) i
mulFinMatrixrDistrAddFinMatrix : ∀ {n} (M N K : FinMatrix R n n)
→ mulFinMatrix M (addFinMatrix N K) ≡ addFinMatrix (mulFinMatrix M N) (mulFinMatrix M K)
mulFinMatrixrDistrAddFinMatrix M N K = funExt₂ λ i j →
∑ (λ k → M i k · (N k j + K k j)) ≡⟨ sumVecExt (λ k → ·Rdist+ (M i k) (N k j) (K k j)) ⟩
∑ (λ k → M i k · N k j + M i k · K k j) ≡⟨ sumVecSplit (λ k → M i k · N k j) (λ k → M i k · K k j) ⟩
∑ (λ k → M i k · N k j) + ∑ (λ k → M i k · K k j) ∎
mulFinMatrixlDistrAddFinMatrix : ∀ {n} (M N K : FinMatrix R n n)
→ mulFinMatrix (addFinMatrix M N) K ≡ addFinMatrix (mulFinMatrix M K) (mulFinMatrix N K)
mulFinMatrixlDistrAddFinMatrix M N K = funExt₂ λ i j →
∑ (λ k → (M i k + N i k) · K k j) ≡⟨ sumVecExt (λ k → ·Ldist+ (M i k) (N i k) (K k j)) ⟩
∑ (λ k → M i k · K k j + N i k · K k j) ≡⟨ sumVecSplit (λ k → M i k · K k j) (λ k → N i k · K k j) ⟩
∑ (λ k → M i k · K k j) + ∑ (λ k → N i k · K k j) ∎
FinMatrixRing : (n : ℕ) → Ring ℓ
FinMatrixRing n =
makeRing {R = FinMatrix R n n} zeroFinMatrix oneFinMatrix addFinMatrix
mulFinMatrix negFinMatrix isSetFinMatrix addFinMatrixAssoc
addFinMatrix0r addFinMatrixNegMatrixr addFinMatrixComm
mulFinMatrixAssoc mulFinMatrixr1 mulFinMatrix1r
mulFinMatrixrDistrAddFinMatrix mulFinMatrixlDistrAddFinMatrix
| 45.778878
| 145
| 0.574724
|
4afb824677c03ca4b5525e8b98ee1baf1942d3a0
| 578
|
agda
|
Agda
|
test/Succeed/SharedDefinitions.agda
|
sseefried/agda
|
6b13364d36eeb60d8ec15eaf8effe23c73401900
|
[
"BSD-2-Clause"
] | 1
|
2022-02-25T00:40:56.000Z
|
2022-02-25T00:40:56.000Z
|
test/Succeed/SharedDefinitions.agda
|
SNU-2D/agda
|
b5b3b1657556f720a7310cb7744edb1fac71eaf4
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Succeed/SharedDefinitions.agda
|
SNU-2D/agda
|
b5b3b1657556f720a7310cb7744edb1fac71eaf4
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --profile=interactive #-}
open import Common.Prelude
open import Common.Equality
`1 = suc zero
`2 = `1 + `1
`4 = `2 + `2
`8 = `4 + `4
`16 = `8 + `8
`32 = `16 + `16
`64 = `32 + `32
`128 = `64 + `64
`256 = `128 + `128
`512 = `256 + `256
`1024 = `512 + `512
`2048 = `1024 + `1024
`4096 = `2048 + `2048
`8192 = `4096 + `4096
`16384 = `8192 + `8192
`32768 = `16384 + `16384
`65536 = `32768 + `32768
prf8 : `8 ≡ 8
prf8 = refl
prf65k : `65536 ≡ 65536
prf65k = refl
| 20.642857
| 37
| 0.448097
|
dfd119dd6dd1ea38c6a3bec2b264aad2a531ae50
| 710
|
agda
|
Agda
|
test/Succeed/Issue778b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue778b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue778b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS -v impossible:10 #-}
-- {-# OPTIONS -v tc.term.exlam:100 -v extendedlambda:100 -v int2abs.reifyterm:100 -v tc.with:100 -v tc.mod.apply:100 #-}
module Issue778b (Param : Set) where
open import Issue778M Param
data D : (Nat → Nat) → Set where
d : D pred → D pred
-- Ulf, 2013-11-11: With the fix to issue 59 that inlines with functions,
-- this no longer termination checks. The problem is having a termination
-- path going through a with-expression (the variable x in this case).
{-# TERMINATING #-}
test : (f : Nat → Nat) → D f → Nat
test .pred (d x) = bla
where bla : Nat
bla with (d x) -- Andreas, 2014-11-06 "with x" has been outlawed.
... | (d (d y)) = test pred y
| 30.869565
| 121
| 0.646479
|
10ceb6ba31f0ec9c2d6f0789f4d8d163922f5462
| 14,077
|
agda
|
Agda
|
Definition/Untyped.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/Untyped.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/Untyped.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
-- Raw terms, weakening (renaming) and substitution.
{-# OPTIONS --without-K --safe #-}
module Definition.Untyped where
open import Tools.Nat
open import Tools.Product
open import Tools.List
import Tools.PropositionalEquality as PE
infixl 30 _∙_
infix 30 Π_▹_
infixr 22 _▹▹_
infix 30 Σ_▹_
infixr 22 _××_
infix 30 ⟦_⟧_▹_
infixl 30 _ₛ•ₛ_ _•ₛ_ _ₛ•_
infix 25 _[_]
infix 25 _[_]↑
-- Typing contexts (snoc-lists, isomorphic to lists).
data Con (A : Set) : Set where
ε : Con A -- Empty context.
_∙_ : Con A → A → Con A -- Context extension.
record GenT (A : Set) : Set where
inductive
constructor ⟦_,_⟧
field
l : Nat
t : A
data Kind : Set where
Ukind : Kind
Pikind : Kind
Lamkind : Kind
Appkind : Kind
Sigmakind : Kind
Prodkind : Kind
Fstkind : Kind
Sndkind : Kind
Natkind : Kind
Zerokind : Kind
Suckind : Kind
Natreckind : Kind
Unitkind : Kind
Starkind : Kind
Emptykind : Kind
Emptyreckind : Kind
data Term : Set where
var : (x : Nat) → Term
gen : (k : Kind) (c : List (GenT Term)) → Term
-- The Grammar of our language.
-- We represent the expressions of our language as de Bruijn terms.
-- Variables are natural numbers interpreted as de Bruijn indices.
-- Π, lam, and natrec are binders.
-- Type constructors.
U : Term -- Universe.
U = gen Ukind []
pattern Univ u = gen (Ukind u) []
Π_▹_ : (A B : Term) → Term -- Dependent function type (B is a binder).
Π A ▹ B = gen Pikind (⟦ 0 , A ⟧ ∷ ⟦ 1 , B ⟧ ∷ [])
Σ_▹_ : (A B : Term) → Term
Σ A ▹ B = gen Sigmakind (⟦ 0 , A ⟧ ∷ ⟦ 1 , B ⟧ ∷ [])
ℕ : Term -- Type of natural numbers.
ℕ = gen Natkind []
Empty : Term
Empty = gen Emptykind []
Unit : Term
Unit = gen Unitkind []
-- Lambda-calculus.
-- var : (x : Nat) → Term -- Variable (de Bruijn index).
-- var = var
lam : (t : Term) → Term -- Function abstraction (binder).
lam t = gen Lamkind (⟦ 1 , t ⟧ ∷ [])
_∘_ : (t u : Term) → Term -- Application.
t ∘ u = gen Appkind (⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ [])
-- Dependent products
prod : (t u : Term) → Term
prod t u = gen Prodkind (⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ [])
fst : (t : Term) → Term
fst t = gen Fstkind (⟦ 0 , t ⟧ ∷ [])
snd : (t : Term) → Term
snd t = gen Sndkind (⟦ 0 , t ⟧ ∷ [])
-- Introduction and elimination of natural numbers.
zero : Term -- Natural number zero.
zero = gen Zerokind []
suc : (t : Term) → Term -- Successor.
suc t = gen Suckind (⟦ 0 , t ⟧ ∷ [])
natrec : (A t u v : Term) → Term -- Recursor (A is a binder).
natrec A t u v = gen Natreckind (⟦ 1 , A ⟧ ∷ ⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ ⟦ 0 , v ⟧ ∷ [])
-- Unit type
star : Term
star = gen Starkind []
-- Empty type
Emptyrec : (A e : Term) → Term
Emptyrec A e = gen Emptyreckind (⟦ 0 , A ⟧ ∷ ⟦ 0 , e ⟧ ∷ [])
-- Binding types
data BindingType : Set where
BΠ : BindingType
BΣ : BindingType
⟦_⟧_▹_ : BindingType → Term → Term → Term
⟦ BΠ ⟧ F ▹ G = Π F ▹ G
⟦ BΣ ⟧ F ▹ G = Σ F ▹ G
-- Injectivity of term constructors w.r.t. propositional equality.
-- If W F G = W H E then F = H and G = E.
B-PE-injectivity : ∀ {F G H E} W → ⟦ W ⟧ F ▹ G PE.≡ ⟦ W ⟧ H ▹ E → F PE.≡ H × G PE.≡ E
B-PE-injectivity BΠ PE.refl = PE.refl , PE.refl
B-PE-injectivity BΣ PE.refl = PE.refl , PE.refl
-- If suc n = suc m then n = m.
suc-PE-injectivity : ∀ {n m} → suc n PE.≡ suc m → n PE.≡ m
suc-PE-injectivity PE.refl = PE.refl
-- Neutral terms.
-- A term is neutral if it has a variable in head position.
-- The variable blocks reduction of such terms.
data Neutral : Term → Set where
var : ∀ n → Neutral (var n)
∘ₙ : ∀ {k u} → Neutral k → Neutral (k ∘ u)
fstₙ : ∀ {p} → Neutral p → Neutral (fst p)
sndₙ : ∀ {p} → Neutral p → Neutral (snd p)
natrecₙ : ∀ {C c g k} → Neutral k → Neutral (natrec C c g k)
Emptyrecₙ : ∀ {A e} → Neutral e → Neutral (Emptyrec A e)
-- Weak head normal forms (whnfs).
-- These are the (lazy) values of our language.
data Whnf : Term → Set where
-- Type constructors are whnfs.
Uₙ : Whnf U
Πₙ : ∀ {A B} → Whnf (Π A ▹ B)
Σₙ : ∀ {A B} → Whnf (Σ A ▹ B)
ℕₙ : Whnf ℕ
Unitₙ : Whnf Unit
Emptyₙ : Whnf Empty
-- Introductions are whnfs.
lamₙ : ∀ {t} → Whnf (lam t)
zeroₙ : Whnf zero
sucₙ : ∀ {t} → Whnf (suc t)
starₙ : Whnf star
prodₙ : ∀ {t u} → Whnf (prod t u)
-- Neutrals are whnfs.
ne : ∀ {n} → Neutral n → Whnf n
-- Whnf inequalities.
-- Different whnfs are trivially distinguished by propositional equality.
-- (The following statements are sometimes called "no-confusion theorems".)
U≢ne : ∀ {K} → Neutral K → U PE.≢ K
U≢ne () PE.refl
ℕ≢ne : ∀ {K} → Neutral K → ℕ PE.≢ K
ℕ≢ne () PE.refl
Empty≢ne : ∀ {K} → Neutral K → Empty PE.≢ K
Empty≢ne () PE.refl
Unit≢ne : ∀ {K} → Neutral K → Unit PE.≢ K
Unit≢ne () PE.refl
B≢ne : ∀ {F G K} W → Neutral K → ⟦ W ⟧ F ▹ G PE.≢ K
B≢ne BΠ () PE.refl
B≢ne BΣ () PE.refl
U≢B : ∀ {F G} W → U PE.≢ ⟦ W ⟧ F ▹ G
U≢B BΠ ()
U≢B BΣ ()
ℕ≢B : ∀ {F G} W → ℕ PE.≢ ⟦ W ⟧ F ▹ G
ℕ≢B BΠ ()
ℕ≢B BΣ ()
Empty≢B : ∀ {F G} W → Empty PE.≢ ⟦ W ⟧ F ▹ G
Empty≢B BΠ ()
Empty≢B BΣ ()
Unit≢B : ∀ {F G} W → Unit PE.≢ ⟦ W ⟧ F ▹ G
Unit≢B BΠ ()
Unit≢B BΣ ()
zero≢ne : ∀ {k} → Neutral k → zero PE.≢ k
zero≢ne () PE.refl
suc≢ne : ∀ {n k} → Neutral k → suc n PE.≢ k
suc≢ne () PE.refl
-- Several views on whnfs (note: not recursive).
-- A whnf of type ℕ is either zero, suc t, or neutral.
data Natural : Term → Set where
zeroₙ : Natural zero
sucₙ : ∀ {t} → Natural (suc t)
ne : ∀ {n} → Neutral n → Natural n
-- A (small) type in whnf is either Π A B, ℕ, or neutral.
-- Large types could also be U.
data Type : Term → Set where
Πₙ : ∀ {A B} → Type (Π A ▹ B)
Σₙ : ∀ {A B} → Type (Σ A ▹ B)
ℕₙ : Type ℕ
Emptyₙ : Type Empty
Unitₙ : Type Unit
ne : ∀{n} → Neutral n → Type n
⟦_⟧-type : ∀ (W : BindingType) {F} {G} → Type (⟦ W ⟧ F ▹ G)
⟦ BΠ ⟧-type = Πₙ
⟦ BΣ ⟧-type = Σₙ
-- A whnf of type Π A ▹ B is either lam t or neutral.
data Function : Term → Set where
lamₙ : ∀ {t} → Function (lam t)
ne : ∀ {n} → Neutral n → Function n
-- A whnf of type Σ A ▹ B is either prod t u or neutral.
data Product : Term → Set where
prodₙ : ∀ {t u} → Product (prod t u)
ne : ∀ {n} → Neutral n → Product n
-- These views classify only whnfs.
-- Natural, Type, and Function are a subsets of Whnf.
naturalWhnf : ∀ {n} → Natural n → Whnf n
naturalWhnf sucₙ = sucₙ
naturalWhnf zeroₙ = zeroₙ
naturalWhnf (ne x) = ne x
typeWhnf : ∀ {A} → Type A → Whnf A
typeWhnf Πₙ = Πₙ
typeWhnf Σₙ = Σₙ
typeWhnf ℕₙ = ℕₙ
typeWhnf Emptyₙ = Emptyₙ
typeWhnf Unitₙ = Unitₙ
typeWhnf (ne x) = ne x
functionWhnf : ∀ {f} → Function f → Whnf f
functionWhnf lamₙ = lamₙ
functionWhnf (ne x) = ne x
productWhnf : ∀ {p} → Product p → Whnf p
productWhnf prodₙ = prodₙ
productWhnf (ne x) = ne x
⟦_⟧ₙ : (W : BindingType) → ∀ {F G} → Whnf (⟦ W ⟧ F ▹ G)
⟦_⟧ₙ BΠ = Πₙ
⟦_⟧ₙ BΣ = Σₙ
------------------------------------------------------------------------
-- Weakening
-- In the following we define untyped weakenings η : Wk.
-- The typed form could be written η : Γ ≤ Δ with the intention
-- that η transport a term t living in context Δ to a context Γ
-- that can bind additional variables (which cannot appear in t).
-- Thus, if Δ ⊢ t : A and η : Γ ≤ Δ then Γ ⊢ wk η t : wk η A.
--
-- Even though Γ is "larger" than Δ we write Γ ≤ Δ to be conformant
-- with subtyping A ≤ B. With subtyping, relation Γ ≤ Δ could be defined as
-- ``for all x ∈ dom(Δ) have Γ(x) ≤ Δ(x)'' (in the sense of subtyping)
-- and this would be the natural extension of weakenings.
data Wk : Set where
id : Wk -- η : Γ ≤ Γ.
step : Wk → Wk -- If η : Γ ≤ Δ then step η : Γ∙A ≤ Δ.
lift : Wk → Wk -- If η : Γ ≤ Δ then lift η : Γ∙A ≤ Δ∙A.
-- Composition of weakening.
-- If η : Γ ≤ Δ and η′ : Δ ≤ Φ then η • η′ : Γ ≤ Φ.
infixl 30 _•_
_•_ : Wk → Wk → Wk
id • η′ = η′
step η • η′ = step (η • η′)
lift η • id = lift η
lift η • step η′ = step (η • η′)
lift η • lift η′ = lift (η • η′)
repeat : {A : Set} → (A → A) → A → Nat → A
repeat f a 0 = a
repeat f a (1+ n) = f (repeat f a n)
-- Weakening of variables.
-- If η : Γ ≤ Δ and x ∈ dom(Δ) then wkVar η x ∈ dom(Γ).
wkVar : (ρ : Wk) (n : Nat) → Nat
wkVar id n = n
wkVar (step ρ) n = 1+ (wkVar ρ n)
wkVar (lift ρ) 0 = 0
wkVar (lift ρ) (1+ n) = 1+ (wkVar ρ n)
-- Weakening of terms.
-- If η : Γ ≤ Δ and Δ ⊢ t : A then Γ ⊢ wk η t : wk η A.
mutual
wkGen : (ρ : Wk) (g : List (GenT Term)) → List (GenT Term)
wkGen ρ [] = []
wkGen ρ (⟦ l , t ⟧ ∷ g) = ⟦ l , (wk (repeat lift ρ l) t) ⟧ ∷ wkGen ρ g
wk : (ρ : Wk) (t : Term) → Term
wk ρ (var x) = var (wkVar ρ x)
wk ρ (gen x c) = gen x (wkGen ρ c)
-- Adding one variable to the context requires wk1.
-- If Γ ⊢ t : B then Γ∙A ⊢ wk1 t : wk1 B.
wk1 : Term → Term
wk1 = wk (step id)
-- Weakening of a neutral term.
wkNeutral : ∀ {t} ρ → Neutral t → Neutral (wk ρ t)
wkNeutral ρ (var n) = var (wkVar ρ n)
wkNeutral ρ (∘ₙ n) = ∘ₙ (wkNeutral ρ n)
wkNeutral ρ (fstₙ n) = fstₙ (wkNeutral ρ n)
wkNeutral ρ (sndₙ n) = sndₙ (wkNeutral ρ n)
wkNeutral ρ (natrecₙ n) = natrecₙ (wkNeutral ρ n)
wkNeutral ρ (Emptyrecₙ e) = Emptyrecₙ (wkNeutral ρ e)
-- Weakening can be applied to our whnf views.
wkNatural : ∀ {t} ρ → Natural t → Natural (wk ρ t)
wkNatural ρ sucₙ = sucₙ
wkNatural ρ zeroₙ = zeroₙ
wkNatural ρ (ne x) = ne (wkNeutral ρ x)
wkType : ∀ {t} ρ → Type t → Type (wk ρ t)
wkType ρ Πₙ = Πₙ
wkType ρ Σₙ = Σₙ
wkType ρ ℕₙ = ℕₙ
wkType ρ Emptyₙ = Emptyₙ
wkType ρ Unitₙ = Unitₙ
wkType ρ (ne x) = ne (wkNeutral ρ x)
wkFunction : ∀ {t} ρ → Function t → Function (wk ρ t)
wkFunction ρ lamₙ = lamₙ
wkFunction ρ (ne x) = ne (wkNeutral ρ x)
wkProduct : ∀ {t} ρ → Product t → Product (wk ρ t)
wkProduct ρ prodₙ = prodₙ
wkProduct ρ (ne x) = ne (wkNeutral ρ x)
wkWhnf : ∀ {t} ρ → Whnf t → Whnf (wk ρ t)
wkWhnf ρ Uₙ = Uₙ
wkWhnf ρ Πₙ = Πₙ
wkWhnf ρ Σₙ = Σₙ
wkWhnf ρ ℕₙ = ℕₙ
wkWhnf ρ Emptyₙ = Emptyₙ
wkWhnf ρ Unitₙ = Unitₙ
wkWhnf ρ lamₙ = lamₙ
wkWhnf ρ prodₙ = prodₙ
wkWhnf ρ zeroₙ = zeroₙ
wkWhnf ρ sucₙ = sucₙ
wkWhnf ρ starₙ = starₙ
wkWhnf ρ (ne x) = ne (wkNeutral ρ x)
-- Non-dependent version of Π.
_▹▹_ : Term → Term → Term
A ▹▹ B = Π A ▹ wk1 B
-- Non-dependent products.
_××_ : Term → Term → Term
A ×× B = Σ A ▹ wk1 B
------------------------------------------------------------------------
-- Substitution
-- The substitution operation subst σ t replaces the free de Bruijn indices
-- of term t by chosen terms as specified by σ.
-- The substitution σ itself is a map from natural numbers to terms.
Subst : Set
Subst = Nat → Term
-- Given closed contexts ⊢ Γ and ⊢ Δ,
-- substitutions may be typed via Γ ⊢ σ : Δ meaning that
-- Γ ⊢ σ(x) : (subst σ Δ)(x) for all x ∈ dom(Δ).
--
-- The substitution operation is then typed as follows:
-- If Γ ⊢ σ : Δ and Δ ⊢ t : A, then Γ ⊢ subst σ t : subst σ A.
--
-- Although substitutions are untyped, typing helps us
-- to understand the operation on substitutions.
-- We may view σ as the infinite stream σ 0, σ 1, ...
-- Extract the substitution of the first variable.
--
-- If Γ ⊢ σ : Δ∙A then Γ ⊢ head σ : subst σ A.
head : Subst → Term
head σ = σ 0
-- Remove the first variable instance of a substitution
-- and shift the rest to accommodate.
--
-- If Γ ⊢ σ : Δ∙A then Γ ⊢ tail σ : Δ.
tail : Subst → Subst
tail σ n = σ (1+ n)
-- Substitution of a variable.
--
-- If Γ ⊢ σ : Δ then Γ ⊢ substVar σ x : (subst σ Δ)(x).
substVar : (σ : Subst) (x : Nat) → Term
substVar σ x = σ x
-- Identity substitution.
-- Replaces each variable by itself.
--
-- Γ ⊢ idSubst : Γ.
idSubst : Subst
idSubst = var
-- Weaken a substitution by one.
--
-- If Γ ⊢ σ : Δ then Γ∙A ⊢ wk1Subst σ : Δ.
wk1Subst : Subst → Subst
wk1Subst σ x = wk1 (σ x)
-- Lift a substitution.
--
-- If Γ ⊢ σ : Δ then Γ∙A ⊢ liftSubst σ : Δ∙A.
liftSubst : (σ : Subst) → Subst
liftSubst σ 0 = var 0
liftSubst σ (1+ x) = wk1Subst σ x
-- Transform a weakening into a substitution.
--
-- If ρ : Γ ≤ Δ then Γ ⊢ toSubst ρ : Δ.
toSubst : Wk → Subst
toSubst pr x = var (wkVar pr x)
-- Apply a substitution to a term.
--
-- If Γ ⊢ σ : Δ and Δ ⊢ t : A then Γ ⊢ subst σ t : subst σ A.
mutual
substGen : (σ : Subst) (g : List (GenT Term)) → List (GenT Term)
substGen σ [] = []
substGen σ (⟦ l , t ⟧ ∷ g) = ⟦ l , (subst (repeat liftSubst σ l) t) ⟧ ∷ substGen σ g
subst : (σ : Subst) (t : Term) → Term
subst σ (var x) = substVar σ x
subst σ (gen x c) = gen x (substGen σ c)
-- Extend a substitution by adding a term as
-- the first variable substitution and shift the rest.
--
-- If Γ ⊢ σ : Δ and Γ ⊢ t : subst σ A then Γ ⊢ consSubst σ t : Δ∙A.
consSubst : Subst → Term → Subst
consSubst σ t 0 = t
consSubst σ t (1+ n) = σ n
-- Singleton substitution.
--
-- If Γ ⊢ t : A then Γ ⊢ sgSubst t : Γ∙A.
sgSubst : Term → Subst
sgSubst = consSubst idSubst
-- Compose two substitutions.
--
-- If Γ ⊢ σ : Δ and Δ ⊢ σ′ : Φ then Γ ⊢ σ ₛ•ₛ σ′ : Φ.
_ₛ•ₛ_ : Subst → Subst → Subst
_ₛ•ₛ_ σ σ′ x = subst σ (σ′ x)
-- Composition of weakening and substitution.
--
-- If ρ : Γ ≤ Δ and Δ ⊢ σ : Φ then Γ ⊢ ρ •ₛ σ : Φ.
_•ₛ_ : Wk → Subst → Subst
_•ₛ_ ρ σ x = wk ρ (σ x)
-- If Γ ⊢ σ : Δ and ρ : Δ ≤ Φ then Γ ⊢ σ ₛ• ρ : Φ.
_ₛ•_ : Subst → Wk → Subst
_ₛ•_ σ ρ x = σ (wkVar ρ x)
-- Substitute the first variable of a term with an other term.
--
-- If Γ∙A ⊢ t : B and Γ ⊢ s : A then Γ ⊢ t[s] : B[s].
_[_] : (t : Term) (s : Term) → Term
t [ s ] = subst (sgSubst s) t
-- Substitute the first variable of a term with an other term,
-- but let the two terms share the same context.
--
-- If Γ∙A ⊢ t : B and Γ∙A ⊢ s : A then Γ∙A ⊢ t[s]↑ : B[s]↑.
_[_]↑ : (t : Term) (s : Term) → Term
t [ s ]↑ = subst (consSubst (wk1Subst idSubst) s) t
B-subst : (σ : Subst) (W : BindingType) (F G : Term)
→ subst σ (⟦ W ⟧ F ▹ G) PE.≡ ⟦ W ⟧ (subst σ F) ▹ (subst (liftSubst σ) G)
B-subst σ BΠ F G = PE.refl
B-subst σ BΣ F G = PE.refl
| 25.003552
| 86
| 0.567877
|
fb6f4c4bfc4dc4044205950c7b95145fd35a1b1f
| 6,354
|
agda
|
Agda
|
Cubical/Algebra/CommRingSolver/Solver.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/CommRingSolver/Solver.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRingSolver/Solver.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRingSolver.Solver where
open import Cubical.Foundations.Prelude
open import Cubical.Data.FinData
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Nat.Order using (zero-≤)
open import Cubical.Data.Vec.Base
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRingSolver.RawAlgebra renaming (⟨_⟩ to ⟨_⟩ᵣ)
open import Cubical.Algebra.CommRingSolver.AlgebraExpression
open import Cubical.Algebra.CommRingSolver.IntAsRawRing
open import Cubical.Algebra.CommRingSolver.HornerForms
open import Cubical.Algebra.CommRingSolver.EvalHom
open import Cubical.Algebra.CommRingSolver.HornerEval
private
variable
ℓ : Level
module EqualityToNormalform (R : CommRing ℓ) where
νR = CommRing→RawℤAlgebra R
open CommRingStr (snd R)
open RingTheory (CommRing→Ring R)
open Eval ℤAsRawRing νR
open IteratedHornerOperations νR
open HomomorphismProperties R
ℤExpr : (n : ℕ) → Type _
ℤExpr = Expr ℤAsRawRing (fst R)
normalize : {n : ℕ} → ℤExpr n → IteratedHornerForms νR n
normalize {n = n} (K r) = Constant n νR r
normalize {n = n} (∣ k) = Variable n νR k
normalize (x +' y) =
(normalize x) +ₕ (normalize y)
normalize (x ·' y) =
(normalize x) ·ₕ (normalize y)
normalize (-' x) = -ₕ (normalize x)
isEqualToNormalform :
{n : ℕ} (e : ℤExpr n) (xs : Vec (fst R) n)
→ eval (normalize e) xs ≡ ⟦ e ⟧ xs
isEqualToNormalform (K r) [] = refl
isEqualToNormalform {n = ℕ.suc n} (K r) (x ∷ xs) =
eval (Constant (ℕ.suc n) νR r) (x ∷ xs) ≡⟨ refl ⟩
eval (0ₕ ·X+ Constant n νR r) (x ∷ xs) ≡⟨ combineCasesEval R 0ₕ (Constant n νR r) x xs ⟩
eval 0ₕ (x ∷ xs) · x + eval (Constant n νR r) xs ≡⟨ cong (λ u → u · x + eval (Constant n νR r) xs)
(Eval0H (x ∷ xs)) ⟩
0r · x + eval (Constant n νR r) xs ≡⟨ cong
(λ u → u + eval (Constant n νR r) xs)
(0LeftAnnihilates _) ⟩
0r + eval (Constant n νR r) xs ≡⟨ +Lid _ ⟩
eval (Constant n νR r) xs ≡⟨ isEqualToNormalform (K r) xs ⟩
_ ∎
isEqualToNormalform (∣ zero) (x ∷ xs) =
eval (1ₕ ·X+ 0ₕ) (x ∷ xs) ≡⟨ combineCasesEval R 1ₕ 0ₕ x xs ⟩
eval 1ₕ (x ∷ xs) · x + eval 0ₕ xs ≡⟨ cong (λ u → u · x + eval 0ₕ xs)
(Eval1ₕ (x ∷ xs)) ⟩
1r · x + eval 0ₕ xs ≡⟨ cong (λ u → 1r · x + u ) (Eval0H xs) ⟩
1r · x + 0r ≡⟨ +Rid _ ⟩
1r · x ≡⟨ ·Lid _ ⟩
x ∎
isEqualToNormalform {n = ℕ.suc n} (∣ (suc k)) (x ∷ xs) =
eval (0ₕ ·X+ Variable n νR k) (x ∷ xs) ≡⟨ combineCasesEval R 0ₕ (Variable n νR k) x xs ⟩
eval 0ₕ (x ∷ xs) · x + eval (Variable n νR k) xs ≡⟨ cong (λ u → u · x + eval (Variable n νR k) xs)
(Eval0H (x ∷ xs)) ⟩
0r · x + eval (Variable n νR k) xs ≡⟨ cong (λ u → u + eval (Variable n νR k) xs)
(0LeftAnnihilates _) ⟩
0r + eval (Variable n νR k) xs ≡⟨ +Lid _ ⟩
eval (Variable n νR k) xs ≡⟨ isEqualToNormalform (∣ k) xs ⟩
⟦ ∣ (suc k) ⟧ (x ∷ xs) ∎
isEqualToNormalform (-' e) [] =
eval (-ₕ (normalize e)) [] ≡⟨ -EvalDist (normalize e) [] ⟩
- eval (normalize e) [] ≡⟨ cong -_ (isEqualToNormalform e [] ) ⟩
- ⟦ e ⟧ [] ∎
isEqualToNormalform (-' e) (x ∷ xs) =
eval (-ₕ (normalize e)) (x ∷ xs) ≡⟨ -EvalDist (normalize e) (x ∷ xs) ⟩
- eval (normalize e) (x ∷ xs) ≡⟨ cong -_ (isEqualToNormalform e (x ∷ xs) ) ⟩
- ⟦ e ⟧ (x ∷ xs) ∎
isEqualToNormalform (e +' e₁) [] =
eval (normalize e +ₕ normalize e₁) []
≡⟨ +Homeval (normalize e) _ [] ⟩
eval (normalize e) []
+ eval (normalize e₁) []
≡⟨ cong (λ u → u + eval (normalize e₁) [])
(isEqualToNormalform e []) ⟩
⟦ e ⟧ []
+ eval (normalize e₁) []
≡⟨ cong (λ u → ⟦ e ⟧ [] + u) (isEqualToNormalform e₁ []) ⟩
⟦ e ⟧ [] + ⟦ e₁ ⟧ [] ∎
isEqualToNormalform (e +' e₁) (x ∷ xs) =
eval (normalize e +ₕ normalize e₁) (x ∷ xs)
≡⟨ +Homeval (normalize e) _ (x ∷ xs) ⟩
eval (normalize e) (x ∷ xs) + eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → u + eval (normalize e₁) (x ∷ xs))
(isEqualToNormalform e (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs) + eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → ⟦ e ⟧ (x ∷ xs) + u) (isEqualToNormalform e₁ (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs) + ⟦ e₁ ⟧ (x ∷ xs) ∎
isEqualToNormalform (e ·' e₁) [] =
eval (normalize e ·ₕ normalize e₁) []
≡⟨ ·Homeval (normalize e) _ [] ⟩
eval (normalize e) [] · eval (normalize e₁) []
≡⟨ cong (λ u → u · eval (normalize e₁) [])
(isEqualToNormalform e []) ⟩
⟦ e ⟧ [] · eval (normalize e₁) []
≡⟨ cong (λ u → ⟦ e ⟧ [] · u) (isEqualToNormalform e₁ []) ⟩
⟦ e ⟧ [] · ⟦ e₁ ⟧ [] ∎
isEqualToNormalform (e ·' e₁) (x ∷ xs) =
eval (normalize e ·ₕ normalize e₁) (x ∷ xs)
≡⟨ ·Homeval (normalize e) _ (x ∷ xs) ⟩
eval (normalize e) (x ∷ xs) · eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → u · eval (normalize e₁) (x ∷ xs))
(isEqualToNormalform e (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs) · eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → ⟦ e ⟧ (x ∷ xs) · u) (isEqualToNormalform e₁ (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs) · ⟦ e₁ ⟧ (x ∷ xs) ∎
solve :
{n : ℕ} (e₁ e₂ : ℤExpr n) (xs : Vec (fst R) n)
(p : eval (normalize e₁) xs ≡ eval (normalize e₂) xs)
→ ⟦ e₁ ⟧ xs ≡ ⟦ e₂ ⟧ xs
solve e₁ e₂ xs p =
⟦ e₁ ⟧ xs ≡⟨ sym (isEqualToNormalform e₁ xs) ⟩
eval (normalize e₁) xs ≡⟨ p ⟩
eval (normalize e₂) xs ≡⟨ isEqualToNormalform e₂ xs ⟩
⟦ e₂ ⟧ xs ∎
ℤExpr : (R : CommRing ℓ) (n : ℕ)
→ _
ℤExpr R n = EqualityToNormalform.ℤExpr R n
solve : (R : CommRing ℓ)
{n : ℕ} (e₁ e₂ : ℤExpr R n) (xs : Vec (fst R) n)
(p : eval (EqualityToNormalform.normalize R e₁) xs ≡ eval (EqualityToNormalform.normalize R e₂) xs)
→ _
solve R = EqualityToNormalform.solve R
| 43.520548
| 107
| 0.506295
|
1c4813e7422fc37b1d25a2dc5eddb6a0e927ed2e
| 3,039
|
agda
|
Agda
|
L0E.agda
|
daherb/Agda-Montague
|
9f8bbff7248dbeb54919e03957daf9b35ec1ac23
|
[
"Artistic-2.0"
] | 1
|
2020-12-18T11:56:24.000Z
|
2020-12-18T11:56:24.000Z
|
L0E.agda
|
daherb/Agda-Montague
|
9f8bbff7248dbeb54919e03957daf9b35ec1ac23
|
[
"Artistic-2.0"
] | null | null | null |
L0E.agda
|
daherb/Agda-Montague
|
9f8bbff7248dbeb54919e03957daf9b35ec1ac23
|
[
"Artistic-2.0"
] | null | null | null |
module L0E where
open import Common
-- Syntax
data Conj : Set where
and or : Conj
data N : Set where
Saddie Liz Hank : N
data Vᵢ : Set where
snores sleeps is-boring : Vᵢ
data Vₜ : Set where
loves hates is-taller-than : Vₜ
data Neg : Set where
it-is-not-the-case-that : Neg
data VP : Set where
iv : Vᵢ -> VP
tv : Vₜ -> N -> VP
data S : Set where
sconjs : S -> Conj -> S -> S
negs : Neg -> S -> S
predvp : N -> VP -> S
example1 : S
example1 = predvp Saddie (iv snores)
example2 : S
example2 = predvp Liz (iv sleeps)
example3 : S
example3 = negs it-is-not-the-case-that (predvp Hank (iv snores))
example41 example42 : S
example41 = sconjs (sconjs (predvp Saddie (iv sleeps)) or (predvp Liz (iv is-boring))) and (predvp Hank (iv snores))
example42 = sconjs (predvp Saddie (iv sleeps)) or (sconjs (predvp Liz (iv is-boring)) and (predvp Hank (iv snores)))
example5 : S
example5 = negs it-is-not-the-case-that (negs it-is-not-the-case-that (predvp Saddie (iv sleeps)))
-- Semantics
data Individual : Set where
Anwar_Sadat : Individual
Queen_Elizabeth_II : Individual
Henry_Kissinger : Individual
⟦_⟧N : N -> Individual
⟦ Saddie ⟧N = Anwar_Sadat
⟦ Liz ⟧N = Queen_Elizabeth_II
⟦ Hank ⟧N = Henry_Kissinger
⟦_⟧̬̬̌Vᵢ : Vᵢ -> Individual -> Bool
⟦ snores ⟧̬̬̌Vᵢ Anwar_Sadat = true
⟦ snores ⟧̬̬̌Vᵢ Queen_Elizabeth_II = true
⟦ snores ⟧̬̬̌Vᵢ Henry_Kissinger = false
⟦ sleeps ⟧̬̬̌Vᵢ Anwar_Sadat = true
⟦ sleeps ⟧̬̬̌Vᵢ Queen_Elizabeth_II = false
⟦ sleeps ⟧̬̬̌Vᵢ Henry_Kissinger = false
⟦ is-boring ⟧̬̬̌Vᵢ Anwar_Sadat = true
⟦ is-boring ⟧̬̬̌Vᵢ Queen_Elizabeth_II = true
⟦ is-boring ⟧̬̬̌Vᵢ Henry_Kissinger = true
⟦_⟧Vₜ : Vₜ -> Individual -> Individual -> Bool
⟦ loves ⟧Vₜ Anwar_Sadat _ = true
⟦ loves ⟧Vₜ Queen_Elizabeth_II Anwar_Sadat = false
⟦ loves ⟧Vₜ Queen_Elizabeth_II Queen_Elizabeth_II = true
⟦ loves ⟧Vₜ Queen_Elizabeth_II Henry_Kissinger = false
⟦ loves ⟧Vₜ Henry_Kissinger Anwar_Sadat = true
⟦ loves ⟧Vₜ Henry_Kissinger Queen_Elizabeth_II = false
⟦ loves ⟧Vₜ Henry_Kissinger Henry_Kissinger = true
⟦ hates ⟧Vₜ Anwar_Sadat _ = false
⟦ hates ⟧Vₜ Queen_Elizabeth_II Anwar_Sadat = true
⟦ hates ⟧Vₜ Queen_Elizabeth_II Queen_Elizabeth_II = false
⟦ hates ⟧Vₜ Queen_Elizabeth_II Henry_Kissinger = true
⟦ hates ⟧Vₜ Henry_Kissinger Anwar_Sadat = false
⟦ hates ⟧Vₜ Henry_Kissinger Queen_Elizabeth_II = true
⟦ hates ⟧Vₜ Henry_Kissinger Henry_Kissinger = false
⟦ is-taller-than ⟧Vₜ Anwar_Sadat Anwar_Sadat = false
⟦ is-taller-than ⟧Vₜ Anwar_Sadat Queen_Elizabeth_II = true
⟦ is-taller-than ⟧Vₜ Anwar_Sadat Henry_Kissinger = false
⟦ is-taller-than ⟧Vₜ Queen_Elizabeth_II _ = false
⟦ is-taller-than ⟧Vₜ Henry_Kissinger Anwar_Sadat = true
⟦ is-taller-than ⟧Vₜ Henry_Kissinger Queen_Elizabeth_II = true
⟦ is-taller-than ⟧Vₜ Henry_Kissinger Henry_Kissinger = false
⟦_⟧VP : VP -> Individual -> Bool
⟦ iv v ⟧VP = ⟦ v ⟧̬̬̌Vᵢ
⟦ tv v n ⟧VP = ⟦ v ⟧Vₜ ⟦ n ⟧N
⟦_⟧S : S -> Bool
⟦ sconjs x and x₂ ⟧S = ⟦ x ⟧S && ⟦ x₂ ⟧S
⟦ sconjs x or x₂ ⟧S = ⟦ x ⟧S || ⟦ x₂ ⟧S
⟦ negs x x₁ ⟧S = neg ⟦ x₁ ⟧S
⟦ predvp x x₁ ⟧S = ⟦ x₁ ⟧VP ⟦ x ⟧N
| 28.401869
| 116
| 0.698585
|
1c66284b351da097c555f3e214dea067396d4188
| 652
|
agda
|
Agda
|
src/pointed/core.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 20
|
2015-06-12T12:20:17.000Z
|
2022-02-01T11:25:54.000Z
|
src/pointed/core.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T14:32:16.000Z
|
2016-10-26T11:57:26.000Z
|
src/pointed/core.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T12:17:00.000Z
|
2019-05-04T19:31:00.000Z
|
{-# OPTIONS --without-K #-}
module pointed.core where
open import sum
open import equality.core
open import function.core
open import function.isomorphism.core
PSet : ∀ i → Set _
PSet i = Σ (Set i) λ X → X
PMap : ∀ {i j} → PSet i → PSet j → Set _
PMap (X , x) (Y , y) = Σ (X → Y) λ f → f x ≡ y
_∘P_ : ∀ {i j k}{𝓧 : PSet i}{𝓨 : PSet j}{𝓩 : PSet k}
→ PMap 𝓨 𝓩 → PMap 𝓧 𝓨 → PMap 𝓧 𝓩
(g , q) ∘P (f , p) = (g ∘ f , ap g p · q)
instance
pmap-comp : ∀ {i j k} → Composition _ _ _ _ _ _
pmap-comp {i}{j}{k} = record
{ U₁ = PSet i
; U₂ = PSet j
; U₃ = PSet k
; hom₁₂ = PMap
; hom₂₃ = PMap
; hom₁₃ = PMap
; _∘_ = _∘P_ }
| 22.482759
| 52
| 0.529141
|
c564596242d842d15369c28dce25537436de0398
| 810
|
agda
|
Agda
|
src/fot/FOTC/Program/McCarthy91/McCarthy91.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/McCarthy91/McCarthy91.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/McCarthy91/McCarthy91.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- The McCarthy 91 function: A function with nested recursion
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.McCarthy91.McCarthy91 where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
-- The McCarthy 91 function.
postulate
f₉₁ : D → D
f₉₁-eq : ∀ n → f₉₁ n ≡ (if (gt n 100') then n ∸ 10' else f₉₁ (f₉₁ (n + 11')))
{-# ATP axiom f₉₁-eq #-}
| 35.217391
| 79
| 0.446914
|
0e7157505a46a45784cc8a636c9ca3497f5b2f86
| 143
|
agda
|
Agda
|
test/Succeed/DeadCodePatSyn.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/DeadCodePatSyn.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/DeadCodePatSyn.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
module _ where
open import DeadCodePatSyn.Lib
-- Check that pattern synonyms count when computing dead code
f : _ → Set₁
f not-hidden = Set
| 15.888889
| 61
| 0.755245
|
c5e1a6672fe134d6db887f9172c526a211eda593
| 443
|
agda
|
Agda
|
Data/List/Sorting/HeapSort.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Data/List/Sorting/HeapSort.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Data/List/Sorting/HeapSort.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
open import Data.Boolean
open import Type
module Data.List.Sorting.HeapSort {ℓ} {T : Type{ℓ}} (_≤?_ : T → T → Bool) where
import Lvl
open import Data.List
import Data.List.Functions as List
open import Data.BinaryTree
import Data.BinaryTree.Heap as Heap
open import Functional using (_∘_)
heapSort : List(T) → List(T)
heapSort = Heap.foldOrdered(_≤?_)(_⊰_) ∅ ∘ List.foldᵣ(Heap.insert(_≤?_)) emptyTree
module Proofs where
| 24.611111
| 82
| 0.706546
|
c5e80facfd6612ae63401016388fd6c7d91fa432
| 3,955
|
agda
|
Agda
|
Agda/21-image.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/21-image.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/21-image.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}
module 21-image where
import 20-sequences
open 20-sequences public
{- We give the formal specification of propositional truncation. -}
precomp-Prop :
{ l1 l2 l3 : Level} {A : UU l1} (P : hProp l2) →
(A → type-Prop P) → (Q : hProp l3) →
(type-Prop P → type-Prop Q) → A → type-Prop Q
precomp-Prop P f Q g = g ∘ f
universal-property-propositional-truncation :
( l : Level) {l1 l2 : Level} {A : UU l1} (P : hProp l2) →
( A → type-Prop P) → UU (lsuc l ⊔ l1 ⊔ l2)
universal-property-propositional-truncation l P f =
(Q : hProp l) → is-equiv (precomp-Prop P f Q)
universal-property-propositional-truncation' :
( l : Level) {l1 l2 : Level} {A : UU l1} (P : hProp l2) →
( A → type-Prop P) → UU (lsuc l ⊔ l1 ⊔ l2)
universal-property-propositional-truncation' l {A = A} P f =
(Q : hProp l) → (A → type-Prop Q) → (type-Prop P → type-Prop Q)
universal-property-propositional-truncation-simplify :
{ l1 l2 : Level} {A : UU l1} (P : hProp l2)
( f : A → type-Prop P) →
( (l : Level) → universal-property-propositional-truncation' l P f) →
( (l : Level) → universal-property-propositional-truncation l P f)
universal-property-propositional-truncation-simplify P f up-P l Q =
is-equiv-is-prop
( is-prop-Π (λ x → is-prop-type-Prop Q))
( is-prop-Π (λ x → is-prop-type-Prop Q))
( up-P l Q)
precomp-Π-Prop :
{ l1 l2 l3 : Level} {A : UU l1} (P : hProp l2) →
( f : A → type-Prop P) (Q : type-Prop P → hProp l3) →
( g : (p : type-Prop P) → type-Prop (Q p)) → (x : A) → type-Prop (Q (f x))
precomp-Π-Prop P f Q g x = g (f x)
dependent-universal-property-propositional-truncation :
( l : Level) {l1 l2 : Level} {A : UU l1} (P : hProp l2) →
( A → type-Prop P) → UU (lsuc l ⊔ l1 ⊔ l2)
dependent-universal-property-propositional-truncation l P f =
(Q : type-Prop P → hProp l) → is-equiv (precomp-Π-Prop P f Q)
{- We introduce the image inclusion of a map. -}
precomp-emb :
{ l1 l2 l3 l4 : Level} {X : UU l1} {A : UU l2} (f : A → X)
{B : UU l3} ( i : B ↪ X) (q : hom-slice f (map-emb i)) →
{C : UU l4} ( j : C ↪ X) (r : hom-slice (map-emb i) (map-emb j)) →
hom-slice f (map-emb j)
precomp-emb f i q j r =
pair
( ( map-hom-slice (map-emb i) (map-emb j) r) ∘
( map-hom-slice f (map-emb i) q))
( ( triangle-hom-slice f (map-emb i) q) ∙h
( ( triangle-hom-slice (map-emb i) (map-emb j) r) ·r
( map-hom-slice f (map-emb i) q)))
is-prop-hom-slice :
{ l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →
{ B : UU l3} (i : B ↪ X) → is-prop (hom-slice f (map-emb i))
is-prop-hom-slice {X = X} f i =
is-prop-is-equiv
( (x : X) → fib f x → fib (map-emb i) x)
( fiberwise-hom-hom-slice f (map-emb i))
( is-equiv-fiberwise-hom-hom-slice f (map-emb i))
( is-prop-Π
( λ x → is-prop-Π
( λ p → is-prop-map-is-emb (map-emb i) (is-emb-map-emb i) x)))
universal-property-image :
( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →
{ B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →
UU (lsuc l ⊔ l1 ⊔ l2 ⊔ l3)
universal-property-image l {X = X} f i q =
( C : UU l) (j : C ↪ X) → is-equiv (precomp-emb f i q j)
universal-property-image' :
( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →
{ B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →
UU (lsuc l ⊔ l1 ⊔ l2 ⊔ l3)
universal-property-image' l {X = X} f i q =
( C : UU l) (j : C ↪ X) →
hom-slice f (map-emb j) → hom-slice (map-emb i) (map-emb j)
universal-property-image-universal-property-image' :
( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →
{ B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →
universal-property-image' l f i q → universal-property-image l f i q
universal-property-image-universal-property-image' l f i q up' C j =
is-equiv-is-prop
( is-prop-hom-slice (map-emb i) j)
( is-prop-hom-slice f j)
( up' C j)
| 38.028846
| 76
| 0.573704
|
101300cc6e3e857f0dc52c7f1e3dad02695f5cda
| 8,019
|
agda
|
Agda
|
Security.agda
|
iwilare/imp-semantics
|
cb98e3b3b93362654b79152bfdf2c21eb4951fcc
|
[
"MIT"
] | 6
|
2020-09-08T11:54:07.000Z
|
2022-02-24T22:29:44.000Z
|
Security.agda
|
iwilare/imp-semantics
|
cb98e3b3b93362654b79152bfdf2c21eb4951fcc
|
[
"MIT"
] | null | null | null |
Security.agda
|
iwilare/imp-semantics
|
cb98e3b3b93362654b79152bfdf2c21eb4951fcc
|
[
"MIT"
] | null | null | null |
open import Data.Nat using (ℕ; suc; zero; _<_; _≤_; z≤n; s≤s; _+_; _⊔_)
open import Data.Bool using (Bool; true; false; not; _∧_)
open import Data.Sum using (inj₁; inj₂; _⊎_; [_,_])
open import Data.Product using (_×_; _,_; -,_; _-,-_; ∃; ∃-syntax; proj₂)
open import Data.String using (String; _≟_; length)
open import Relation.Nullary using (¬_; yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong; trans; cong₂)
open import Data.Nat.Properties hiding (_≤?_; _≟_)
open import IMP
level = ℕ
sec : vname → level
-- We can also temporarily use "sec x" to avoid the
-- automatic expansion of the definition in error messages
sec x = length x
secₐ : aexp → level
secₐ (N n) = 0
secₐ (V x) = sec x
secₐ (Plus a b) = secₐ a ⊔ secₐ b
sec₆ : bexp → level
sec₆ (Bc x) = 0
sec₆ (Not b) = sec₆ b
sec₆ (And b₁ b₂) = sec₆ b₁ ⊔ sec₆ b₂
sec₆ (Less a b) = secₐ a ⊔ secₐ b
_≡_⦅≤_⦆ : state → state → level → Set
s₁ ≡ s₂ ⦅≤ l ⦆ = ∀ x → sec x ≤ l → s₁ x ≡ s₂ x
_≡_⦅<_⦆ : state → state → level → Set
s₁ ≡ s₂ ⦅< l ⦆ = ∀ x → sec x < l → s₁ x ≡ s₂ x
non-interference-aexp : ∀ a {s₁ s₂ l}
→ s₁ ≡ s₂ ⦅≤ l ⦆
→ secₐ a ≤ l
→ aval a s₁ ≡ aval a s₂
non-interference-aexp (N x) r e = refl
non-interference-aexp (V x) r e = r x e
non-interference-aexp (Plus a b) r e =
cong₂ (_+_) (non-interference-aexp a r (m⊔n≤o⇒m≤o _ _ e))
(non-interference-aexp b r (m⊔n≤o⇒n≤o _ _ e))
non-interference-bexp : ∀ a {s₁ s₂ l}
→ s₁ ≡ s₂ ⦅≤ l ⦆
→ sec₆ a ≤ l
→ bval a s₁ ≡ bval a s₂
non-interference-bexp (Bc x) r e = refl
non-interference-bexp (Not a) r e = cong not (non-interference-bexp a r e)
non-interference-bexp (And a b) r e =
cong₂ (_∧_) (non-interference-bexp a r (m⊔n≤o⇒m≤o _ _ e))
(non-interference-bexp b r (m⊔n≤o⇒n≤o _ _ e))
non-interference-bexp (Less a b) r e =
cong₂ (_≤?_) (non-interference-aexp a r (m⊔n≤o⇒m≤o _ _ e))
(non-interference-aexp b r (m⊔n≤o⇒n≤o _ _ e))
data _⊢_ : level → com → Set where
SecSkip : ∀{l}
→ l ⊢ SKIP
SecLoc : ∀{l a x}
→ secₐ a ≤ sec x
→ l ≤ sec x
→ l ⊢ (x ::= a)
SecSeq : ∀{l c₁ c₂}
→ l ⊢ c₁
→ l ⊢ c₂
→ l ⊢ (c₁ :: c₂)
SecIf : ∀{b l c₁ c₂}
→ (l ⊔ sec₆ b) ⊢ c₁
→ (l ⊔ sec₆ b) ⊢ c₂
→ l ⊢ (IF b THEN c₁ ELSE c₂)
SecWhile : ∀{b l c}
→ (l ⊔ sec₆ b) ⊢ c
→ l ⊢ (WHILE b DO c)
anti-monotonicity : ∀{l l′ c}
→ l ⊢ c
→ l′ ≤ l
→ l′ ⊢ c
anti-monotonicity SecSkip s = SecSkip
anti-monotonicity (SecLoc x x₁) s = SecLoc x (≤-trans s x₁)
anti-monotonicity (SecSeq d d₁) s = SecSeq (anti-monotonicity d s) (anti-monotonicity d₁ s)
anti-monotonicity (SecIf d d₁) s = SecIf (anti-monotonicity d (⊔-monoˡ-≤ _ s)) (anti-monotonicity d₁ (⊔-monoˡ-≤ _ s))
anti-monotonicity (SecWhile d) s = SecWhile ((anti-monotonicity d (⊔-monoˡ-≤ _ s)))
data ⦅_,_⦆⇒_ : com → state → state → Set where
Skip : ∀{s} → ⦅ SKIP , s ⦆⇒ s
Loc : ∀{s x a}
→ ⦅ x ::= a , s ⦆⇒ (s [ x ::= aval a s ])
Seq : ∀{c₁ c₂ s₁ s₂ s₃}
→ ⦅ c₁ , s₁ ⦆⇒ s₂
→ ⦅ c₂ , s₂ ⦆⇒ s₃
→ ⦅ c₁ :: c₂ , s₁ ⦆⇒ s₃
IfTrue : ∀{c₁ c₂ b s t}
→ bval b s ≡ true
→ ⦅ c₁ , s ⦆⇒ t
→ ⦅ IF b THEN c₁ ELSE c₂ , s ⦆⇒ t
IfFalse : ∀{c₁ c₂ b s t}
→ bval b s ≡ false
→ ⦅ c₂ , s ⦆⇒ t
→ ⦅ IF b THEN c₁ ELSE c₂ , s ⦆⇒ t
WhileFalse : ∀{c b s}
→ bval b s ≡ false
→ ⦅ WHILE b DO c , s ⦆⇒ s
WhileTrue : ∀{c b s₁ s₂ s₃}
→ bval b s₁ ≡ true
→ ⦅ c , s₁ ⦆⇒ s₂
→ ⦅ WHILE b DO c , s₂ ⦆⇒ s₃
→ ⦅ WHILE b DO c , s₁ ⦆⇒ s₃
confinement : ∀{c s t l}
→ ⦅ c , s ⦆⇒ t
→ l ⊢ c
→ s ≡ t ⦅< l ⦆
confinement Skip SecSkip x₂ x₃ = refl
confinement (Loc {x = x₂}) (SecLoc x x₁) e r with e ≟ x₂
... | yes refl = contradiction x₁ (<⇒≱ r)
... | no _ = refl
confinement (Seq x x₄) (SecSeq x₁ x₅) x₂ x₃ =
trans (confinement x x₁ x₂ x₃)
(confinement x₄ x₅ x₂ x₃)
confinement (IfTrue x x₄) (SecIf x₁ x₅) x₂ x₃ = confinement x₄ x₁ x₂ (m<n⇒m<n⊔o _ x₃)
confinement (IfFalse x x₄) (SecIf x₁ x₅) x₂ x₃ = confinement x₄ x₅ x₂ (m<n⇒m<n⊔o _ x₃)
confinement (WhileFalse x) (SecWhile x₁) x₂ x₃ = refl
confinement {l = l} (WhileTrue x x₄ x₅) (SecWhile x₁) x₂ x₃ =
trans (confinement x₄ (anti-monotonicity x₁ (m≤m⊔n _ _)) x₂ x₃)
(confinement x₅ (SecWhile x₁) x₂ x₃)
true≢false : ¬ (true ≡ false)
true≢false = λ ()
reversal₁ : ∀{b c s₁ s₃}
→ ⦅ WHILE b DO c , s₁ ⦆⇒ s₃
→ bval b s₁ ≡ true
→ ∃[ s₂ ] ( ⦅ c , s₁ ⦆⇒ s₂ × ⦅ WHILE b DO c , s₂ ⦆⇒ s₃)
reversal₁ (WhileFalse x) v = contradiction (trans (sym v) x) true≢false
reversal₁ (WhileTrue x e e₁) v = -, e , e₁
reversal₂ : ∀{b c s₁ s₃}
→ ⦅ WHILE b DO c , s₁ ⦆⇒ s₃
→ bval b s₁ ≡ false
→ s₁ ≡ s₃
reversal₂ (WhileFalse x) v = refl
reversal₂ (WhileTrue x r r₁) v = contradiction (trans (sym x) v) true≢false
level-cong : ∀{l l′ c} → l ≡ l′ → l ⊢ c → l′ ⊢ c
level-cong refl x = x
≤⇒<suc : ∀{a b} → a ≤ b → a < suc b
≤⇒<suc z≤n = s≤s z≤n
≤⇒<suc (s≤s r) = s≤s (≤⇒<suc r)
non-interference : ∀{c s s′ t t′ l}
→ ⦅ c , s ⦆⇒ s′
→ ⦅ c , t ⦆⇒ t′
→ 0 ⊢ c
→ s ≡ t ⦅≤ l ⦆
→ s′ ≡ t′ ⦅≤ l ⦆
non-interference Skip Skip z e = e
non-interference (Loc {x = x₂} {a}) Loc (SecLoc x₃ z≤n) e x x₁ with x ≟ x₂
... | yes refl = non-interference-aexp a e (≤-trans x₃ x₁)
... | no _ = e x x₁
non-interference (Seq x cs) (Seq y ct) (SecSeq z z₁) e =
non-interference cs ct z₁ (non-interference x y z e)
non-interference {l = l} (IfTrue {b = b} x cs) (IfTrue x₁ red) (SecIf w w₁) e r r₁ =
non-interference cs red (anti-monotonicity w z≤n) e r r₁
non-interference {l = l} (IfTrue {b = b} x cs) (IfFalse x₁ red) (SecIf w w₁) e r r₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym x) (trans wr x₁)) true≢false)
, (λ l<secb → let oo₁ = confinement cs w
oo₂ = confinement red w₁
in trans (sym (oo₁ r (<-transʳ r₁ l<secb)))
(trans (e r r₁)
(oo₂ r (<-transʳ r₁ l<secb))))
] (≤-<-connex (sec₆ b) l)
non-interference {l = l} (IfFalse x₁ red) (IfTrue {b = b} x cs) (SecIf w w₁) e r r₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym x) (trans (sym wr) x₁)) true≢false)
, (λ l<secb → let oo₁ = confinement cs w
oo₂ = confinement red w₁
in trans (sym (oo₂ r (<-transʳ r₁ l<secb)))
(trans (e r r₁)
(oo₁ r (<-transʳ r₁ l<secb))))
] (≤-<-connex (sec₆ b) l)
non-interference (IfFalse x₁ red) (IfFalse x cs) (SecIf x₇ x₈) =
non-interference red cs (anti-monotonicity x₈ z≤n)
non-interference (WhileFalse x) (WhileFalse x₁) (SecWhile z) e = e
non-interference {l = l} (WhileFalse {b = b} r) (WhileTrue c ct ct₁) (SecWhile z) e x x₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym c) (trans (sym wr) r)) true≢false)
, (λ l<secb →
let simp = confinement ct z
simp2 = confinement ct₁ (SecWhile (level-cong (sym (m≤n⇒m⊔n≡n l<secb)) z))
in trans (e x x₁) (trans (simp x (<-transʳ x₁ l<secb)) (simp2 x (≤⇒<suc x₁))))
] (≤-<-connex (sec₆ b) l)
non-interference {l = l} (WhileTrue c ct ct₁) (WhileFalse {b = b} r) (SecWhile z) e x x₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym c) (trans wr r)) true≢false)
, (λ l<secb →
let simp = confinement ct z
simp2 = confinement ct₁ (SecWhile (level-cong (sym (m≤n⇒m⊔n≡n l<secb)) z))
in trans (trans (sym (simp2 x (≤⇒<suc x₁))) (sym (simp x ((<-transʳ x₁ l<secb))))) (e x x₁))
] (≤-<-connex (sec₆ b) l)
non-interference {l = l} (WhileTrue {b = b} r cs cs₁) (WhileTrue c ct ct₁) (SecWhile z) e =
let h₁ = non-interference cs ct (anti-monotonicity z z≤n) e
h₂ = non-interference cs₁ ct₁ (SecWhile z) h₁
in h₂
| 36.616438
| 117
| 0.555805
|
fbe1fa6256d5540430ced8a90c0175fbe559e1a4
| 168
|
agda
|
Agda
|
test/succeed/Issue778M.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/Issue778M.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Issue778M.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module Issue778M (Param : Set) where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
pred : Nat → Nat
pred = λ { zero → zero; (suc n) → n }
where aux = zero
| 14
| 37
| 0.589286
|
50789ad7f76d64807ffb3d81916a8f86997a82bd
| 45,758
|
agda
|
Agda
|
Agda/09-fundamental-theorem.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/09-fundamental-theorem.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/09-fundamental-theorem.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split #-}
module 09-fundamental-theorem where
import 08-contractible-types
open 08-contractible-types public
-- Section 8.1 Families of equivalences
{- Any family of maps induces a map on the total spaces. -}
tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → ( Σ A B → Σ A C)
tot f t = pair (pr1 t) (f (pr1 t) (pr2 t))
{- We show that for any family of maps, the fiber of the induced map on total
spaces are equivalent to the fibers of the maps in the family. -}
fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (tot f) t → fib (f (pr1 t)) (pr2 t)
fib-ftr-fib-tot f .(pair x (f x y)) (pair (pair x y) refl) = pair y refl
fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (f (pr1 t)) (pr2 t) → fib (tot f) t
fib-tot-fib-ftr F (pair a .(F a y)) (pair y refl) = pair (pair a y) refl
issec-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-ftr-fib-tot f t) ∘ (fib-tot-fib-ftr f t)) ~ id
issec-fib-tot-fib-ftr f (pair x .(f x y)) (pair y refl) = refl
isretr-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-tot-fib-ftr f t) ∘ (fib-ftr-fib-tot f t)) ~ id
isretr-fib-tot-fib-ftr f .(pair x (f x y)) (pair (pair x y) refl) = refl
abstract
is-equiv-fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-ftr-fib-tot f t)
is-equiv-fib-ftr-fib-tot f t =
is-equiv-has-inverse
( fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
( isretr-fib-tot-fib-ftr f t)
abstract
is-equiv-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-tot-fib-ftr f t)
is-equiv-fib-tot-fib-ftr f t =
is-equiv-has-inverse
( fib-ftr-fib-tot f t)
( isretr-fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
{- Now that we have shown that the fibers of the induced map on total spaces
are equivalent to the fibers of the maps in the family, it follows that
the induced map on total spaces is an equivalence if and only if each map
in the family is an equivalence. -}
is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → UU (i ⊔ (j ⊔ k))
is-fiberwise-equiv f = (x : _) → is-equiv (f x)
abstract
is-equiv-tot-is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
{f : (x : A) → B x → C x} → is-fiberwise-equiv f →
is-equiv (tot f )
is-equiv-tot-is-fiberwise-equiv {f = f} H =
is-equiv-is-contr-map
( λ t → is-contr-is-equiv _
( fib-ftr-fib-tot f t)
( is-equiv-fib-ftr-fib-tot f t)
( is-contr-map-is-equiv (H _) (pr2 t)))
abstract
is-fiberwise-equiv-is-equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → is-equiv (tot f) →
is-fiberwise-equiv f
is-fiberwise-equiv-is-equiv-tot {A = A} {B} {C} f is-equiv-tot-f x =
is-equiv-is-contr-map
( λ z → is-contr-is-equiv'
( fib (tot f) (pair x z))
( fib-ftr-fib-tot f (pair x z))
( is-equiv-fib-ftr-fib-tot f (pair x z))
( is-contr-map-is-equiv is-equiv-tot-f (pair x z)))
equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x ≃ C x) → (Σ A B) ≃ (Σ A C)
equiv-tot e =
pair
( tot (λ x → map-equiv (e x)))
( is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-map-equiv (e x)))
{- In the second part of this section we show that any equivalence f on base
types also induces an equivalence on total spaces. -}
Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
Σ A (λ x → C (f x)) → Σ B C
Σ-map-base-map f C s = pair (f (pr1 s)) (pr2 s)
{- The proof is similar to the previous part: we show that the fibers of f
and Σ-kap-base-map f C are equivalent. -}
fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib f (pr1 t) → fib (Σ-map-base-map f C) t
fib-Σ-map-base-map-fib f C (pair .(f x) z) (pair x refl) =
pair (pair x z) refl
fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib (Σ-map-base-map f C) t → fib f (pr1 t)
fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
pair x refl
issec-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-Σ-map-base-map-fib f C t) ∘ (fib-fib-Σ-map-base-map f C t)) ~ id
issec-fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
refl
isretr-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-fib-Σ-map-base-map f C t) ∘ (fib-Σ-map-base-map-fib f C t)) ~ id
isretr-fib-fib-Σ-map-base-map f C (pair .(f x) z) (pair x refl) = refl
abstract
is-equiv-fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → is-equiv (fib-Σ-map-base-map-fib f C t)
is-equiv-fib-Σ-map-base-map-fib f C t =
is-equiv-has-inverse
( fib-fib-Σ-map-base-map f C t)
( issec-fib-fib-Σ-map-base-map f C t)
( isretr-fib-fib-Σ-map-base-map f C t)
abstract
is-contr-map-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-contr-map f → is-contr-map (Σ-map-base-map f C)
is-contr-map-Σ-map-base-map C f is-contr-f (pair y z) =
is-contr-is-equiv'
( fib f y)
( fib-Σ-map-base-map-fib f C (pair y z))
( is-equiv-fib-Σ-map-base-map-fib f C (pair y z))
( is-contr-f y)
abstract
is-equiv-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-equiv f → is-equiv (Σ-map-base-map f C)
is-equiv-Σ-map-base-map C f is-equiv-f =
is-equiv-is-contr-map
( is-contr-map-Σ-map-base-map C f (is-contr-map-is-equiv is-equiv-f))
{- Now we combine the two parts of this section. -}
toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
Σ A C → Σ B D
toto D f g t = pair (f (pr1 t)) (g (pr1 t) (pr2 t))
{- A special case of toto is the functoriality of the cartesian product. -}
{- We construct the functoriality of cartesian products. -}
functor-prod :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (A × B) → (C × D)
functor-prod f g (pair a b) = pair (f a) (g b)
functor-prod-pr1 :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (pr1 ∘ (functor-prod f g)) ~ (f ∘ pr1)
functor-prod-pr1 f g (pair a b) = refl
functor-prod-pr2 :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (pr2 ∘ (functor-prod f g)) ~ (g ∘ pr2)
functor-prod-pr2 f g (pair a b) = refl
{- For our convenience we show that the functorial action of cartesian products
preserves identity maps, compositions, homotopies, and equivalences. -}
functor-prod-id :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
(functor-prod (id {A = A}) (id {A = B})) ~ id
functor-prod-id (pair a b) = refl
functor-prod-comp :
{l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{E : UU l5} {F : UU l6} (f : A → C) (g : B → D) (h : C → E) (k : D → F) →
functor-prod (h ∘ f) (k ∘ g) ~ ((functor-prod h k) ∘ (functor-prod f g))
functor-prod-comp f g h k (pair a b) = refl
functor-prod-htpy :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{f f' : A → C} (H : f ~ f') {g g' : B → D} (K : g ~ g') →
functor-prod f g ~ functor-prod f' g'
functor-prod-htpy {f = f} {f'} H {g} {g'} K (pair a b) =
eq-pair-triv (pair (H a) (K b))
abstract
is-equiv-functor-prod :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) →
is-equiv f → is-equiv g → is-equiv (functor-prod f g)
is-equiv-functor-prod f g
( pair (pair sf issec-sf) (pair rf isretr-rf))
( pair (pair sg issec-sg) (pair rg isretr-rg)) =
pair
( pair
( functor-prod sf sg)
( ( htpy-inv (functor-prod-comp sf sg f g)) ∙h
( (functor-prod-htpy issec-sf issec-sg) ∙h functor-prod-id)))
( pair
( functor-prod rf rg)
( ( htpy-inv (functor-prod-comp f g rf rg)) ∙h
( (functor-prod-htpy isretr-rf isretr-rg) ∙h functor-prod-id)))
{- triangle -}
triangle-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
(toto D f g) ~ ((Σ-map-base-map f D) ∘ (tot g))
triangle-toto D f g t = refl
abstract
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → (is-fiberwise-equiv g) →
is-equiv (toto D f g)
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map
D f g is-equiv-f is-fiberwise-equiv-g =
is-equiv-comp
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
equiv-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (e : A ≃ B) (g : (x : A) → C x ≃ D (map-equiv e x)) →
Σ A C ≃ Σ B D
equiv-toto D e g =
pair
( toto D (map-equiv e) (λ x → map-equiv (g x)))
( is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map D
( map-equiv e)
( λ x → map-equiv (g x))
( is-equiv-map-equiv e)
( λ x → is-equiv-map-equiv (g x)))
abstract
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → is-equiv (toto D f g) → is-fiberwise-equiv g
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map
D f g is-equiv-f is-equiv-toto-fg =
is-fiberwise-equiv-is-equiv-tot g
( is-equiv-right-factor
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
( is-equiv-toto-fg))
-- Section 8.2 The fundamental theorem
-- The general form of the fundamental theorem of identity types
abstract
fundamental-theorem-id :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → (f : (x : A) → Id a x → B x) → is-fiberwise-equiv f
fundamental-theorem-id {A = A} a b is-contr-AB f =
is-fiberwise-equiv-is-equiv-tot f
( is-equiv-is-contr (tot f) (is-contr-total-path a) is-contr-AB)
abstract
fundamental-theorem-id' :
{i j : Level} {A : UU i} {B : A → UU j}
(a : A) (b : B a) (f : (x : A) → Id a x → B x) →
is-fiberwise-equiv f → is-contr (Σ A B)
fundamental-theorem-id' {A = A} {B = B} a b f is-fiberwise-equiv-f =
is-contr-is-equiv'
( Σ A (Id a))
( tot f)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-f)
( is-contr-total-path a)
-- The canonical form of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → is-fiberwise-equiv (ind-Id a (λ x p → B x) b)
fundamental-theorem-id-J {i} {j} {A} {B} a b is-contr-AB =
fundamental-theorem-id a b is-contr-AB (ind-Id a (λ x p → B x) b)
-- The converse of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J' :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-fiberwise-equiv (ind-Id a (λ x p → B x) b)) → is-contr (Σ A B)
fundamental-theorem-id-J' {i} {j} {A} {B} a b H =
is-contr-is-equiv'
( Σ A (Id a))
( tot (ind-Id a (λ x p → B x) b))
( is-equiv-tot-is-fiberwise-equiv H)
( is-contr-total-path a)
-- As an application we show that equivalences are embeddings.
is-emb :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j)
is-emb f = (x y : _) → is-equiv (ap f {x} {y})
_↪_ :
{i j : Level} → UU i → UU j → UU (i ⊔ j)
A ↪ B = Σ (A → B) is-emb
map-emb :
{i j : Level} {A : UU i} {B : UU j} → A ↪ B → A → B
map-emb f = pr1 f
is-emb-map-emb :
{ i j : Level} {A : UU i} {B : UU j} (f : A ↪ B) → is-emb (map-emb f)
is-emb-map-emb f = pr2 f
abstract
is-emb-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → is-equiv f → is-emb f
is-emb-is-equiv {i} {j} {A} {B} f is-equiv-f x =
fundamental-theorem-id x refl
( is-contr-equiv
( fib f (f x))
( equiv-tot (λ y → equiv-inv (f x) (f y)))
( is-contr-map-is-equiv is-equiv-f (f x)))
( λ y p → ap f p)
equiv-ap :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x y : A) →
(Id x y) ≃ (Id (map-equiv e x) (map-equiv e y))
equiv-ap e x y =
pair
( ap (map-equiv e) {x} {y})
( is-emb-is-equiv (map-equiv e) (is-equiv-map-equiv e) x y)
-- Section 7.3 Identity systems
IND-identity-system :
{i j : Level} (k : Level) {A : UU i} (B : A → UU j) (a : A) (b : B a) → UU _
IND-identity-system k {A} B a b =
( P : (x : A) (y : B x) → UU k) →
sec (λ (h : (x : A) (y : B x) → P x y) → h a b)
fam-Σ :
{i j k : Level} {A : UU i} {B : A → UU j} (C : (x : A) → B x → UU k) →
Σ A B → UU k
fam-Σ C (pair x y) = C x y
abstract
ind-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) (P : (x : A) → B x → UU k) →
P a b → (x : A) (y : B x) → P x y
ind-identity-system a b is-contr-AB P p x y =
tr
( fam-Σ P)
( is-prop-is-contr' is-contr-AB (pair a b) (pair x y))
( p)
comp-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
(P : (x : A) → B x → UU k) (p : P a b) →
Id (ind-identity-system a b is-contr-AB P p a b) p
comp-identity-system a b is-contr-AB P p =
ap
( λ t → tr (fam-Σ P) t p)
( is-prop-is-contr'
( is-prop-is-contr is-contr-AB (pair a b) (pair a b))
( is-prop-is-contr' is-contr-AB (pair a b) (pair a b))
( refl))
Ind-identity-system :
{i j : Level} (k : Level) {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
IND-identity-system k B a b
Ind-identity-system k a b is-contr-AB P =
pair
( ind-identity-system a b is-contr-AB P)
( comp-identity-system a b is-contr-AB P)
contraction-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(t : Σ A B) → Id (pair a b) t
contraction-total-space-IND-identity-system a b ind (pair x y) =
pr1 (ind (λ x' y' → Id (pair a b) (pair x' y'))) refl x y
abstract
is-contr-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b → is-contr (Σ A B)
is-contr-total-space-IND-identity-system a b ind =
pair
( pair a b)
( contraction-total-space-IND-identity-system a b ind)
abstract
fundamental-theorem-id-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(f : (x : A) → Id a x → B x) → (x : A) → is-equiv (f x)
fundamental-theorem-id-IND-identity-system a b ind f =
fundamental-theorem-id a b (is-contr-total-space-IND-identity-system a b ind) f
-- Section 7.4 Disjointness of coproducts
-- Raising universe levels
postulate Raise : {l1 : Level} (l2 : Level) → (A : UU l1) → Σ (UU (l1 ⊔ l2)) (λ X → A ≃ X)
abstract
raise :
{l1 : Level} (l2 : Level) → UU l1 → UU (l1 ⊔ l2)
raise l2 A = pr1 (Raise l2 A)
equiv-raise :
{l1 : Level} (l2 : Level) (A : UU l1) → A ≃ raise l2 A
equiv-raise l2 A = pr2 (Raise l2 A)
map-raise :
{l1 : Level} (l2 : Level) (A : UU l1) → A → raise l2 A
map-raise l2 A = map-equiv (equiv-raise l2 A)
is-equiv-map-raise :
{l1 : Level} (l2 : Level) (A : UU l1) →
is-equiv (map-raise l2 A)
is-equiv-map-raise l2 A = is-equiv-map-equiv (equiv-raise l2 A)
-- Lemmas about coproducts
left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) → Σ (coprod A B) C →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
left-distributive-coprod-Σ-map A B C (pair (inl x) z) = inl (pair x z)
left-distributive-coprod-Σ-map A B C (pair (inr y) z) = inr (pair y z)
inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y))) → Σ (coprod A B) C
inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = pair (inl x) z
inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = pair (inr y) z
issec-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (left-distributive-coprod-Σ-map A B C) ∘
(inv-left-distributive-coprod-Σ-map A B C)) ~ id
issec-inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = refl
issec-inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = refl
isretr-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (inv-left-distributive-coprod-Σ-map A B C) ∘
(left-distributive-coprod-Σ-map A B C)) ~ id
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inl x) z) = refl
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inr y) z) = refl
abstract
is-equiv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
is-equiv (left-distributive-coprod-Σ-map A B C)
is-equiv-left-distributive-coprod-Σ-map A B C =
is-equiv-has-inverse
( inv-left-distributive-coprod-Σ-map A B C)
( issec-inv-left-distributive-coprod-Σ-map A B C)
( isretr-inv-left-distributive-coprod-Σ-map A B C)
equiv-left-distributive-coprod-Σ :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
Σ (coprod A B) C ≃ coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
equiv-left-distributive-coprod-Σ A B C =
pair ( left-distributive-coprod-Σ-map A B C)
( is-equiv-left-distributive-coprod-Σ-map A B C)
abstract
is-equiv-map-to-empty :
{l : Level} {A : UU l} (f : A → empty) → is-equiv f
is-equiv-map-to-empty f =
is-equiv-has-inverse
ind-empty
ind-empty
( λ x → ind-empty {P = λ t → Id (ind-empty (f x)) x} (f x))
map-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) → empty
map-Σ-empty-fam A (pair x ())
abstract
is-equiv-map-Σ-empty-fam :
{l : Level} (A : UU l) → is-equiv (map-Σ-empty-fam A)
is-equiv-map-Σ-empty-fam A = is-equiv-map-to-empty (map-Σ-empty-fam A)
equiv-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) ≃ empty
equiv-Σ-empty-fam A =
pair (map-Σ-empty-fam A) (is-equiv-map-Σ-empty-fam A)
-- The identity types of coproducts
Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
coprod A B → coprod A B → UU (l1 ⊔ l2)
Eq-coprod {l1} {l2} A B (inl x) (inl y) = raise (l1 ⊔ l2) (Id x y)
Eq-coprod {l1} {l2} A B (inl x) (inr y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inl y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inr y) = raise (l1 ⊔ l2) (Id x y)
reflexive-Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(t : coprod A B) → Eq-coprod A B t t
reflexive-Eq-coprod {l1} {l2} A B (inl x) = map-raise (l1 ⊔ l2) (Id x x) refl
reflexive-Eq-coprod {l1} {l2} A B (inr x) = map-raise (l1 ⊔ l2) (Id x x) refl
Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(s t : coprod A B) → Id s t → Eq-coprod A B s t
Eq-coprod-eq A B s .s refl = reflexive-Eq-coprod A B s
abstract
is-contr-total-Eq-coprod-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inl x)))
is-contr-total-Eq-coprod-inl A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inl x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inl x)))
( is-contr-equiv'
( coprod
( Σ A (Id x))
( Σ B (λ y → empty)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( equiv-tot (λ y → equiv-raise _ empty)))
( is-contr-equiv
( coprod (Σ A (Id x)) empty)
( equiv-functor-coprod
( equiv-id (Σ A (Id x)))
( equiv-Σ-empty-fam B))
( is-contr-equiv'
( Σ A (Id x))
( right-unit-law-coprod (Σ A (Id x)))
( is-contr-total-path x))))
abstract
is-contr-total-Eq-coprod-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inr x)))
is-contr-total-Eq-coprod-inr A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inr x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inr x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inr x)))
( is-contr-equiv'
( coprod (Σ A (λ y → empty)) (Σ B (Id x)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ empty))
( equiv-tot (λ y → equiv-raise _ (Id x y))))
( is-contr-equiv
( coprod empty (Σ B (Id x)))
( equiv-functor-coprod
( equiv-Σ-empty-fam A)
( equiv-id (Σ B (Id x))))
( is-contr-equiv'
( Σ B (Id x))
( left-unit-law-coprod (Σ B (Id x)))
( is-contr-total-path x))))
abstract
is-equiv-Eq-coprod-eq-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-fiberwise-equiv (Eq-coprod-eq A B (inl x))
is-equiv-Eq-coprod-eq-inl A B x =
fundamental-theorem-id
( inl x)
( reflexive-Eq-coprod A B (inl x))
( is-contr-total-Eq-coprod-inl A B x)
( Eq-coprod-eq A B (inl x))
abstract
is-equiv-Eq-coprod-eq-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-fiberwise-equiv (Eq-coprod-eq A B (inr x))
is-equiv-Eq-coprod-eq-inr A B x =
fundamental-theorem-id
( inr x)
( reflexive-Eq-coprod A B (inr x))
( is-contr-total-Eq-coprod-inr A B x)
( Eq-coprod-eq A B (inr x))
abstract
is-equiv-Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2)
(s : coprod A B) → is-fiberwise-equiv (Eq-coprod-eq A B s)
is-equiv-Eq-coprod-eq A B (inl x) = is-equiv-Eq-coprod-eq-inl A B x
is-equiv-Eq-coprod-eq A B (inr x) = is-equiv-Eq-coprod-eq-inr A B x
map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → Id (inl {B = B} x) (inl {B = B} x') → Id x x'
map-compute-eq-coprod-inl-inl x x' =
( inv-is-equiv (is-equiv-map-raise _ (Id x x'))) ∘
( Eq-coprod-eq _ _ (inl x) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → is-equiv (map-compute-eq-coprod-inl-inl {B = B} x x')
is-equiv-map-compute-eq-coprod-inl-inl x x' =
is-equiv-comp
( map-compute-eq-coprod-inl-inl x x')
( inv-is-equiv (is-equiv-map-raise _ (Id x x')))
( Eq-coprod-eq _ _ (inl x) (inl x'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id x x')))
compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → (Id (inl {B = B} x) (inl x')) ≃ (Id x x')
compute-eq-coprod-inl-inl x x' =
pair
( map-compute-eq-coprod-inl-inl x x')
( is-equiv-map-compute-eq-coprod-inl-inl x x')
map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → Id (inl x) (inr y') → empty
map-compute-eq-coprod-inl-inr x y' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inl x) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → is-equiv (map-compute-eq-coprod-inl-inr x y')
is-equiv-map-compute-eq-coprod-inl-inr x y' =
is-equiv-comp
( map-compute-eq-coprod-inl-inr x y')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inl x) (inr y'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → (Id (inl x) (inr y')) ≃ empty
compute-eq-coprod-inl-inr x y' =
pair
( map-compute-eq-coprod-inl-inr x y')
( is-equiv-map-compute-eq-coprod-inl-inr x y')
map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr {A = A} y) (inl x')) → empty
map-compute-eq-coprod-inr-inl y x' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inr y) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → is-equiv (map-compute-eq-coprod-inr-inl y x')
is-equiv-map-compute-eq-coprod-inr-inl y x' =
is-equiv-comp
( map-compute-eq-coprod-inr-inl y x')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inr y) (inl x'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr y) (inl x')) ≃ empty
compute-eq-coprod-inr-inl y x' =
pair
( map-compute-eq-coprod-inr-inl y x')
( is-equiv-map-compute-eq-coprod-inr-inl y x')
map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) → Id y y'
map-compute-eq-coprod-inr-inr y y' =
( inv-is-equiv (is-equiv-map-raise _ (Id y y'))) ∘
( Eq-coprod-eq _ _ (inr y) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → is-equiv (map-compute-eq-coprod-inr-inr {A = A} y y')
is-equiv-map-compute-eq-coprod-inr-inr y y' =
is-equiv-comp
( map-compute-eq-coprod-inr-inr y y')
( inv-is-equiv (is-equiv-map-raise _ (Id y y')))
( Eq-coprod-eq _ _ (inr y) (inr y'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id y y')))
compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) ≃ (Id y y')
compute-eq-coprod-inr-inr y y' =
pair
( map-compute-eq-coprod-inr-inr y y')
( is-equiv-map-compute-eq-coprod-inr-inr y y')
-- Exercises
-- Exercise 7.1
abstract
is-emb-empty :
{i : Level} (A : UU i) → is-emb (ind-empty {P = λ x → A})
is-emb-empty A = ind-empty
-- Exercise 7.2
path-adjointness-equiv :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x : A) (y : B) →
(Id (map-equiv e x) y) ≃ (Id x (inv-map-equiv e y))
path-adjointness-equiv e x y =
( inv-equiv (equiv-ap e x (inv-map-equiv e y))) ∘e
( equiv-concat'
( map-equiv e x)
( inv (issec-inv-is-equiv (is-equiv-map-equiv e) y)))
-- Exercise 7.3
abstract
is-equiv-top-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
is-equiv i → is-equiv f → is-equiv g → is-equiv h
is-equiv-top-is-equiv-left-square f g h i H Ei Ef Eg =
is-equiv-right-factor (i ∘ f) g h H Eg
( is-equiv-comp (i ∘ f) i f refl-htpy Ef Ei)
abstract
is-emb-htpy :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb g → is-emb f
is-emb-htpy f g H is-emb-g x y =
is-equiv-top-is-equiv-left-square
( ap g)
( concat' (f x) (H y))
( ap f)
( concat (H x) (g y))
( htpy-nat H)
( is-equiv-concat (H x) (g y))
( is-emb-g x y)
( is-equiv-concat' (f x) (H y))
abstract
is-emb-htpy' :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb f → is-emb g
is-emb-htpy' f g H is-emb-f =
is-emb-htpy g f (htpy-inv H) is-emb-f
-- Exercise 7.4
abstract
is-emb-comp :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb h → is-emb f
is-emb-comp f g h H is-emb-g is-emb-h =
is-emb-htpy f (g ∘ h) H
( λ x y → is-equiv-comp (ap (g ∘ h)) (ap g) (ap h) (ap-comp g h)
( is-emb-h x y)
( is-emb-g (h x) (h y)))
abstract
is-emb-right-factor :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb f → is-emb h
is-emb-right-factor f g h H is-emb-g is-emb-f x y =
is-equiv-right-factor
( ap (g ∘ h))
( ap g)
( ap h)
( ap-comp g h)
( is-emb-g (h x) (h y))
( is-emb-htpy (g ∘ h) f (htpy-inv H) is-emb-f x y)
abstract
is-emb-triangle-is-equiv :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb g → is-emb f
is-emb-triangle-is-equiv f g e H is-equiv-e is-emb-g =
is-emb-comp f g e H is-emb-g (is-emb-is-equiv e is-equiv-e)
abstract
is-emb-triangle-is-equiv' :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb f → is-emb g
is-emb-triangle-is-equiv' f g e H is-equiv-e is-emb-f =
is-emb-triangle-is-equiv g f
( inv-is-equiv is-equiv-e)
( triangle-section f g e H
( pair
( inv-is-equiv is-equiv-e)
( issec-inv-is-equiv is-equiv-e)))
( is-equiv-inv-is-equiv is-equiv-e)
( is-emb-f)
-- Exercise 7.5
abstract
is-emb-inl :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inl {A = A} {B = B})
is-emb-inl A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( tot (λ y → Eq-coprod-eq A B (inl x) (inl y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inl x) (inl y)))
( is-contr-equiv'
( Σ A (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inl)
abstract
is-emb-inr :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inr {A = A} {B = B})
is-emb-inr A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ B (λ y → Eq-coprod A B (inr x) (inr y)))
( tot (λ y → Eq-coprod-eq A B (inr x) (inr y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inr x) (inr y)))
( is-contr-equiv'
( Σ B (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inr)
-- Exercise 7.6
-- Exercise 7.7
tot-htpy :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k}
{f g : (x : A) → B x → C x} → (H : (x : A) → f x ~ g x) → tot f ~ tot g
tot-htpy H (pair x y) = eq-pair refl (H x y)
tot-id :
{i j : Level} {A : UU i} (B : A → UU j) →
(tot (λ x (y : B x) → y)) ~ id
tot-id B (pair x y) = refl
tot-comp :
{i j j' j'' : Level}
{A : UU i} {B : A → UU j} {B' : A → UU j'} {B'' : A → UU j''}
(f : (x : A) → B x → B' x) (g : (x : A) → B' x → B'' x) →
tot (λ x → (g x) ∘ (f x)) ~ ((tot g) ∘ (tot f))
tot-comp f g (pair x y) = refl
-- Exercise 7.8
abstract
fundamental-theorem-id-retr :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) →
(i : (x : A) → B x → Id a x) → (R : (x : A) → retr (i x)) →
is-fiberwise-equiv i
fundamental-theorem-id-retr {_} {_} {A} {B} a i R =
is-fiberwise-equiv-is-equiv-tot i
( is-equiv-is-contr (tot i)
( is-contr-retract-of (Σ _ (λ y → Id a y))
( pair (tot i)
( pair (tot λ x → pr1 (R x))
( ( htpy-inv (tot-comp i (λ x → pr1 (R x)))) ∙h
( ( tot-htpy λ x → pr2 (R x)) ∙h (tot-id B)))))
( is-contr-total-path a))
( is-contr-total-path a))
abstract
is-equiv-sec-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (sec-f : sec f) →
is-equiv (pr1 sec-f) → is-equiv f
is-equiv-sec-is-equiv {A = A} {B = B} f (pair g issec-g) is-equiv-sec-f =
let h : A → B
h = inv-is-equiv is-equiv-sec-f
in
is-equiv-htpy h
( ( htpy-left-whisk f (htpy-inv (issec-inv-is-equiv is-equiv-sec-f))) ∙h
( htpy-right-whisk issec-g h))
( is-equiv-inv-is-equiv is-equiv-sec-f)
abstract
fundamental-theorem-id-sec :
{i j : Level} {A : UU i} {B : A → UU j} (a : A)
(f : (x : A) → Id a x → B x) → ((x : A) → sec (f x)) →
is-fiberwise-equiv f
fundamental-theorem-id-sec {A = A} {B = B} a f sec-f x =
let i : (x : A) → B x → Id a x
i = λ x → pr1 (sec-f x)
retr-i : (x : A) → retr (i x)
retr-i = λ x → pair (f x) (pr2 (sec-f x))
is-fiberwise-equiv-i : is-fiberwise-equiv i
is-fiberwise-equiv-i = fundamental-theorem-id-retr a i retr-i
in is-equiv-sec-is-equiv (f x) (sec-f x) (is-fiberwise-equiv-i x)
-- Exercise 7.9
abstract
is-emb-sec-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) →
((x y : A) → sec (ap f {x = x} {y = y})) → is-emb f
is-emb-sec-ap f sec-ap-f x =
fundamental-theorem-id-sec x (λ y → ap f {y = y}) (sec-ap-f x)
-- Exercise 7.10
coherence-is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (g : B → A)
(G : (f ∘ g) ~ id) (H : (g ∘ f) ~ id) → UU (l1 ⊔ l2)
coherence-is-half-adjoint-equivalence f g G H =
( htpy-right-whisk G f) ~ (htpy-left-whisk f H)
is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-half-adjoint-equivalence {A = A} {B = B} f =
Σ (B → A)
( λ g → Σ ((f ∘ g) ~ id)
( λ G → Σ ((g ∘ f) ~ id) (coherence-is-half-adjoint-equivalence f g G)))
is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-path-split {A = A} {B = B} f =
sec f × ((x y : A) → sec (ap f {x = x} {y = y}))
abstract
is-path-split-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-path-split f
is-path-split-is-equiv f is-equiv-f =
pair (pr1 is-equiv-f) (λ x y → pr1 (is-emb-is-equiv f is-equiv-f x y))
abstract
is-half-adjoint-equivalence-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-path-split {A = A} {B = B} f
( pair (pair g issec-g) sec-ap-f) =
let φ : ((x : A) → fib (ap f) (issec-g (f x))) →
Σ ((g ∘ f) ~ id)
( λ H → (htpy-right-whisk issec-g f) ~ (htpy-left-whisk f H))
φ = ( tot (λ H' → htpy-inv)) ∘
( λ s → pair (λ x → pr1 (s x)) (λ x → pr2 (s x)))
in
pair g
( pair issec-g
( φ (λ x → pair
( pr1 (sec-ap-f (g (f x)) x) (issec-g (f x)))
( pr2 (sec-ap-f (g (f x)) x) (issec-g (f x))))))
abstract
is-equiv-is-half-adjoint-equivalence :
{ l1 l2 : Level} {A : UU l1} {B : UU l2}
(f : A → B) → is-half-adjoint-equivalence f → is-equiv f
is-equiv-is-half-adjoint-equivalence f (pair g (pair G (pair H K))) =
is-equiv-has-inverse g G H
abstract
is-equiv-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-equiv f
is-equiv-is-path-split f =
( is-equiv-is-half-adjoint-equivalence f) ∘
( is-half-adjoint-equivalence-is-path-split f)
abstract
is-half-adjoint-equivalence-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-equiv f =
( is-half-adjoint-equivalence-is-path-split f) ∘ (is-path-split-is-equiv f)
-- Exercise 7.11
abstract
is-equiv-top-is-equiv-bottom-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv i) → (is-equiv h)
is-equiv-top-is-equiv-bottom-square
f g h i H is-equiv-f is-equiv-g is-equiv-i =
is-equiv-right-factor (i ∘ f) g h H is-equiv-g
( is-equiv-comp' i f is-equiv-f is-equiv-i)
abstract
is-equiv-bottom-is-equiv-top-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv h) → (is-equiv i)
is-equiv-bottom-is-equiv-top-square
f g h i H is-equiv-f is-equiv-g is-equiv-h =
is-equiv-left-factor' i f
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g) is-equiv-f
abstract
is-equiv-left-is-equiv-right-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv g) → (is-equiv f)
is-equiv-left-is-equiv-right-square
f g h i H is-equiv-h is-equiv-i is-equiv-g =
is-equiv-right-factor' i f is-equiv-i
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g)
abstract
is-equiv-right-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv f) → (is-equiv g)
is-equiv-right-is-equiv-left-square
f g h i H is-equiv-h is-equiv-i is-equiv-f =
is-equiv-left-factor (i ∘ f) g h H
( is-equiv-comp' i f is-equiv-f is-equiv-i)
( is-equiv-h)
fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h))
(x : X) → (fib f x) → (fib g x)
fib-triangle f g h H .(f a) (pair a refl) = pair (h a) (inv (H a))
square-tot-fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(h ∘ (Σ-fib-to-domain f)) ~
((Σ-fib-to-domain g) ∘ (tot (fib-triangle f g h H)))
square-tot-fib-triangle f g h H (pair .(f a) (pair a refl)) = refl
abstract
is-fiberwise-equiv-is-equiv-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-equiv h) → is-fiberwise-equiv (fib-triangle f g h H)
is-fiberwise-equiv-is-equiv-triangle f g h H E =
is-fiberwise-equiv-is-equiv-tot
( fib-triangle f g h H)
( is-equiv-top-is-equiv-bottom-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( E))
abstract
is-equiv-triangle-is-fiberwise-equiv :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-fiberwise-equiv (fib-triangle f g h H)) → is-equiv h
is-equiv-triangle-is-fiberwise-equiv f g h H E =
is-equiv-bottom-is-equiv-top-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( is-equiv-tot-is-fiberwise-equiv E)
-- Extra material
{- In order to show that the total space of htpy-cone is contractible, we give
a general construction that helps us characterize the identity type of
a structure. This construction is called
is-contr-total-Eq-structure.
We first give some definitions that help us with the construction of
is-contr-total-Eq-structure. -}
swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))) →
Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t)))
swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) =
pair (pair a c) (pair b d)
htpy-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
( ( swap-total-Eq-structure B C D) ∘
( swap-total-Eq-structure C B (λ x z y → D x y z))) ~ id
htpy-swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) = refl
abstract
is-equiv-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
is-equiv (swap-total-Eq-structure B C D)
is-equiv-swap-total-Eq-structure B C D =
is-equiv-has-inverse
( swap-total-Eq-structure C B (λ x z y → D x y z))
( htpy-swap-total-Eq-structure B C D)
( htpy-swap-total-Eq-structure C B (λ x z y → D x y z))
abstract
is-contr-Σ :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → ((x : A) → is-contr (B x)) → is-contr (Σ A B)
is-contr-Σ {A = A} {B = B} is-contr-A is-contr-B =
is-contr-equiv'
( B (center is-contr-A))
( left-unit-law-Σ B is-contr-A)
( is-contr-B (center is-contr-A))
abstract
is-contr-Σ' :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → (a : A) → is-contr (B a) → is-contr (Σ A B)
is-contr-Σ' {A = A} {B} is-contr-A a is-contr-B =
is-contr-is-equiv'
( B a)
( left-unit-law-Σ-map-gen B is-contr-A a)
( is-equiv-left-unit-law-Σ-map-gen B is-contr-A a)
( is-contr-B)
abstract
is-contr-total-Eq-structure :
{ l1 l2 l3 l4 : Level} { A : UU l1} {B : A → UU l2} {C : A → UU l3}
( D : (x : A) → B x → C x → UU l4) →
( is-contr-AC : is-contr (Σ A C)) →
( t : Σ A C) →
is-contr (Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))) →
is-contr (Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))))
is-contr-total-Eq-structure
{A = A} {B = B} {C = C} D is-contr-AC t is-contr-BD =
is-contr-is-equiv
( Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))))
( swap-total-Eq-structure B C D)
( is-equiv-swap-total-Eq-structure B C D)
( is-contr-Σ' is-contr-AC t is-contr-BD)
-- Characterizing the identity type of a fiber as the fiber of the action on
-- paths
fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) {b : B} (s t : fib f b) (p : Id (pr1 s) (pr1 t)) →
(Id (tr (λ (a : A) → Id (f a) b) p (pr2 s)) (pr2 t)) →
(Id (ap f p) ((pr2 s) ∙ (inv (pr2 t))))
fib-ap-eq-fib-fiberwise f (pair .x' p) (pair x' refl) refl =
inv ∘ (concat right-unit refl)
abstract
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B} (s t : fib f b) →
is-fiberwise-equiv (fib-ap-eq-fib-fiberwise f s t)
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise
f (pair x y) (pair .x refl) refl =
is-equiv-comp
( fib-ap-eq-fib-fiberwise f (pair x y) (pair x refl) refl)
( inv)
( concat right-unit refl)
( refl-htpy)
( is-equiv-concat right-unit refl)
( is-equiv-inv (y ∙ refl) refl)
fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → Id s t →
fib (ap f {x = pr1 s} {y = pr1 t}) ((pr2 s) ∙ (inv (pr2 t)))
fib-ap-eq-fib f s .s refl = pair refl (inv (right-inv (pr2 s)))
triangle-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B)
{b : B} (s t : fib f b) →
(fib-ap-eq-fib f s t) ~ ((tot (fib-ap-eq-fib-fiberwise f s t)) ∘ (pair-eq {s = s} {t}))
triangle-fib-ap-eq-fib f (pair x refl) .(pair x refl) refl = refl
abstract
is-equiv-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → is-equiv (fib-ap-eq-fib f s t)
is-equiv-fib-ap-eq-fib f s t =
is-equiv-comp
( fib-ap-eq-fib f s t)
( tot (fib-ap-eq-fib-fiberwise f s t))
( pair-eq {s = s} {t})
( triangle-fib-ap-eq-fib f s t)
( is-equiv-pair-eq s t)
( is-equiv-tot-is-fiberwise-equiv
( is-fiberwise-equiv-fib-ap-eq-fib-fiberwise f s t))
eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) →
Id (pair x q) (pair y (refl {x = f y})) → fib (ap f {x = x} {y = y}) q
eq-fib-fib-ap f x y q = (tr (fib (ap f)) right-unit) ∘ (fib-ap-eq-fib f (pair x q) (pair y refl))
abstract
is-equiv-eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) → is-equiv (eq-fib-fib-ap f x y q)
is-equiv-eq-fib-fib-ap f x y q =
is-equiv-comp
( eq-fib-fib-ap f x y q)
( tr (fib (ap f)) right-unit)
( fib-ap-eq-fib f (pair x q) (pair y refl))
( refl-htpy)
( is-equiv-fib-ap-eq-fib f (pair x q) (pair y refl))
( is-equiv-tr (fib (ap f)) right-unit)
-- Comparing fib and fib'
fib'-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
fib f y → fib' f y
fib'-fib f y t = tot (λ x → inv) t
abstract
is-equiv-fib'-fib :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) → is-fiberwise-equiv (fib'-fib f)
is-equiv-fib'-fib f y =
is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-inv (f x) y)
| 35.776388
| 97
| 0.530465
|
3973eafe9462cda3ba36254bc14efdb966434003
| 1,226
|
agda
|
Agda
|
notes/thesis/report/LogicalFramework/CommAddition.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/thesis/report/LogicalFramework/CommAddition.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/thesis/report/LogicalFramework/CommAddition.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- A Peano arithmetic proof without using a where clause
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LogicalFramework.CommAddition where
open import Common.FOL.Relation.Binary.EqReasoning
open import PA.Axiomatic.Standard.Base
------------------------------------------------------------------------------
postulate
+-rightIdentity : ∀ n → n + zero ≡ n
x+Sy≡S[x+y] : ∀ m n → m + succ n ≡ succ (m + n)
succCong : ∀ {m n} → m ≡ n → succ m ≡ succ n
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity = PA₃
A : ℕ → Set
A m = ∀ n → m + n ≡ n + m
A0 : A zero
A0 n = zero + n ≡⟨ +-leftIdentity n ⟩
n ≡⟨ sym (+-rightIdentity n) ⟩
n + zero ∎
is : ∀ m → A m → A (succ m)
is m ih n = succ m + n ≡⟨ PA₄ m n ⟩
succ (m + n) ≡⟨ succCong (ih n) ⟩
succ (n + m) ≡⟨ sym (x+Sy≡S[x+y] n m) ⟩
n + succ m ∎
+-comm : ∀ m n → m + n ≡ n + m
+-comm = ℕ-ind A A0 is
| 29.190476
| 78
| 0.40783
|
1c98ffbd2fed23ade13879e2f3951fd1fb6ba635
| 11,716
|
agda
|
Agda
|
src/Tactic/Reflection/Equality.agda
|
lclem/agda-prelude
|
75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6
|
[
"MIT"
] | null | null | null |
src/Tactic/Reflection/Equality.agda
|
lclem/agda-prelude
|
75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6
|
[
"MIT"
] | null | null | null |
src/Tactic/Reflection/Equality.agda
|
lclem/agda-prelude
|
75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6
|
[
"MIT"
] | null | null | null |
module Tactic.Reflection.Equality where
open import Prelude
open import Builtin.Reflection
open import Builtin.Float
instance
EqVisibility : Eq Visibility
_==_ {{EqVisibility}} visible visible = yes refl
_==_ {{EqVisibility}} visible hidden = no (λ ())
_==_ {{EqVisibility}} visible instance′ = no (λ ())
_==_ {{EqVisibility}} hidden visible = no (λ ())
_==_ {{EqVisibility}} hidden hidden = yes refl
_==_ {{EqVisibility}} hidden instance′ = no (λ ())
_==_ {{EqVisibility}} instance′ visible = no (λ ())
_==_ {{EqVisibility}} instance′ hidden = no (λ ())
_==_ {{EqVisibility}} instance′ instance′ = yes refl
EqRelevance : Eq Relevance
_==_ {{EqRelevance}} relevant relevant = yes refl
_==_ {{EqRelevance}} relevant irrelevant = no (λ ())
_==_ {{EqRelevance}} irrelevant relevant = no (λ ())
_==_ {{EqRelevance}} irrelevant irrelevant = yes refl
EqArgInfo : Eq ArgInfo
_==_ {{EqArgInfo}} (arg-info v r) (arg-info v₁ r₁) =
decEq₂ arg-info-inj₁ arg-info-inj₂ (v == v₁) (r == r₁)
EqArg : ∀ {A} {{EqA : Eq A}} → Eq (Arg A)
_==_ {{EqArg}} (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (x == x₁)
EqLiteral : Eq Literal
_==_ {{EqLiteral}} = eqLit
where
eqLit : (x y : Literal) → Dec (x ≡ y)
eqLit (nat x) (nat y) = decEq₁ nat-inj (x == y)
eqLit (word64 x) (word64 y) = decEq₁ word64-inj (x == y)
eqLit (float x) (float y) = decEq₁ float-inj (x == y)
eqLit (char x) (char y) = decEq₁ char-inj (x == y)
eqLit (string x) (string y) = decEq₁ string-inj (x == y)
eqLit (name x) (name y) = decEq₁ name-inj (x == y)
eqLit (meta x) (meta y) = decEq₁ meta-inj (x == y)
eqLit (nat _) (float _) = no λ()
eqLit (nat _) (word64 _) = no λ()
eqLit (nat _) (char _) = no λ()
eqLit (nat _) (string _) = no λ()
eqLit (nat _) (name _) = no λ()
eqLit (nat _) (meta _) = no λ()
eqLit (word64 _) (nat _) = no λ()
eqLit (word64 _) (float _) = no λ()
eqLit (word64 _) (char _) = no λ()
eqLit (word64 _) (string _) = no λ()
eqLit (word64 _) (name _) = no λ()
eqLit (word64 _) (meta _) = no λ()
eqLit (float _) (nat _) = no λ()
eqLit (float _) (word64 _) = no λ()
eqLit (float _) (char _) = no λ()
eqLit (float _) (string _) = no λ()
eqLit (float _) (name _) = no λ()
eqLit (float _) (meta _) = no λ()
eqLit (char _) (nat _) = no λ()
eqLit (char _) (word64 _) = no λ()
eqLit (char _) (float _) = no λ()
eqLit (char _) (string _) = no λ()
eqLit (char _) (name _) = no λ()
eqLit (char _) (meta _) = no λ()
eqLit (string _) (nat _) = no λ()
eqLit (string _) (word64 _) = no λ()
eqLit (string _) (float _) = no λ()
eqLit (string _) (char _) = no λ()
eqLit (string _) (name _) = no λ()
eqLit (string _) (meta _) = no λ()
eqLit (name _) (nat _) = no λ()
eqLit (name _) (word64 _) = no λ()
eqLit (name _) (float _) = no λ()
eqLit (name _) (char _) = no λ()
eqLit (name _) (string _) = no λ()
eqLit (name _) (meta _) = no λ()
eqLit (meta _) (nat _) = no λ()
eqLit (meta _) (word64 _) = no λ()
eqLit (meta _) (float _) = no λ()
eqLit (meta _) (char _) = no λ()
eqLit (meta _) (string _) = no λ()
eqLit (meta _) (name _) = no λ()
private
eqSort : (x y : Sort) → Dec (x ≡ y)
eqTerm : (x y : Term) → Dec (x ≡ y)
eqPat : (x y : Pattern) → Dec (x ≡ y)
eqClause : (x y : Clause) → Dec (x ≡ y)
eqArgTerm : (x y : Arg Term) → Dec (x ≡ y)
eqArgTerm (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (eqTerm x x₁)
eqArgPat : (x y : Arg Pattern) → Dec (x ≡ y)
eqArgPat (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (eqPat x x₁)
eqAbsTerm : (x y : Abs Term) → Dec (x ≡ y)
eqAbsTerm (abs s x) (abs s₁ x₁) = decEq₂ abs-inj₁ abs-inj₂ (s == s₁) (eqTerm x x₁)
eqPats : (x y : List (Arg Pattern)) → Dec (x ≡ y)
eqPats [] [] = yes refl
eqPats [] (x ∷ xs) = no λ ()
eqPats (x ∷ xs) [] = no λ ()
eqPats (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqArgPat x y) (eqPats xs ys)
eqArgs : (x y : List (Arg Term)) → Dec (x ≡ y)
eqArgs [] [] = yes refl
eqArgs [] (x ∷ xs) = no λ ()
eqArgs (x ∷ xs) [] = no λ ()
eqArgs (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqArgTerm x y) (eqArgs xs ys)
eqClauses : (x y : List Clause) → Dec (x ≡ y)
eqClauses [] [] = yes refl
eqClauses [] (x ∷ xs) = no λ ()
eqClauses (x ∷ xs) [] = no λ ()
eqClauses (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqClause x y) (eqClauses xs ys)
eqTerm (var x args) (var x₁ args₁) = decEq₂ var-inj₁ var-inj₂ (x == x₁) (eqArgs args args₁)
eqTerm (con c args) (con c₁ args₁) = decEq₂ con-inj₁ con-inj₂ (c == c₁) (eqArgs args args₁)
eqTerm (def f args) (def f₁ args₁) = decEq₂ def-inj₁ def-inj₂ (f == f₁) (eqArgs args args₁)
eqTerm (meta x args) (meta x₁ args₁) = decEq₂ meta-inj₁ meta-inj₂ (x == x₁) (eqArgs args args₁)
eqTerm (lam v x) (lam v₁ y) = decEq₂ lam-inj₁ lam-inj₂ (v == v₁) (eqAbsTerm x y)
eqTerm (pi t₁ t₂) (pi t₃ t₄) = decEq₂ pi-inj₁ pi-inj₂ (eqArgTerm t₁ t₃) (eqAbsTerm t₂ t₄)
eqTerm (agda-sort x) (agda-sort x₁) = decEq₁ sort-inj (eqSort x x₁)
eqTerm (lit l) (lit l₁) = decEq₁ lit-inj (l == l₁)
eqTerm (pat-lam c args) (pat-lam c₁ args₁) = decEq₂ pat-lam-inj₁ pat-lam-inj₂ (eqClauses c c₁) (eqArgs args args₁)
eqTerm unknown unknown = yes refl
eqTerm (var x args) (con c args₁) = no λ ()
eqTerm (var x args) (def f args₁) = no λ ()
eqTerm (var x args) (lam v y) = no λ ()
eqTerm (var x args) (pi t₁ t₂) = no λ ()
eqTerm (var x args) (agda-sort x₁) = no λ ()
eqTerm (var x args) (lit x₁) = no λ ()
eqTerm (var x args) unknown = no λ ()
eqTerm (con c args) (var x args₁) = no λ ()
eqTerm (con c args) (def f args₁) = no λ ()
eqTerm (con c args) (lam v y) = no λ ()
eqTerm (con c args) (pi t₁ t₂) = no λ ()
eqTerm (con c args) (agda-sort x) = no λ ()
eqTerm (con c args) (lit x) = no λ ()
eqTerm (con c args) unknown = no λ ()
eqTerm (def f args) (var x args₁) = no λ ()
eqTerm (def f args) (con c args₁) = no λ ()
eqTerm (def f args) (lam v y) = no λ ()
eqTerm (def f args) (pi t₁ t₂) = no λ ()
eqTerm (def f args) (agda-sort x) = no λ ()
eqTerm (def f args) (lit x) = no λ ()
eqTerm (def f args) unknown = no λ ()
eqTerm (lam v x) (var x₁ args) = no λ ()
eqTerm (lam v x) (con c args) = no λ ()
eqTerm (lam v x) (def f args) = no λ ()
eqTerm (lam v x) (pi t₁ t₂) = no λ ()
eqTerm (lam v x) (agda-sort x₁) = no λ ()
eqTerm (lam v x) (lit x₁) = no λ ()
eqTerm (lam v x) unknown = no λ ()
eqTerm (pi t₁ t₂) (var x args) = no λ ()
eqTerm (pi t₁ t₂) (con c args) = no λ ()
eqTerm (pi t₁ t₂) (def f args) = no λ ()
eqTerm (pi t₁ t₂) (lam v y) = no λ ()
eqTerm (pi t₁ t₂) (agda-sort x) = no λ ()
eqTerm (pi t₁ t₂) (lit x) = no λ ()
eqTerm (pi t₁ t₂) unknown = no λ ()
eqTerm (agda-sort x) (var x₁ args) = no λ ()
eqTerm (agda-sort x) (con c args) = no λ ()
eqTerm (agda-sort x) (def f args) = no λ ()
eqTerm (agda-sort x) (lam v y) = no λ ()
eqTerm (agda-sort x) (pi t₁ t₂) = no λ ()
eqTerm (agda-sort x) (lit x₁) = no λ ()
eqTerm (agda-sort x) unknown = no λ ()
eqTerm (lit x) (var x₁ args) = no λ ()
eqTerm (lit x) (con c args) = no λ ()
eqTerm (lit x) (def f args) = no λ ()
eqTerm (lit x) (lam v y) = no λ ()
eqTerm (lit x) (pi t₁ t₂) = no λ ()
eqTerm (lit x) (agda-sort x₁) = no λ ()
eqTerm (lit x) unknown = no λ ()
eqTerm unknown (var x args) = no λ ()
eqTerm unknown (con c args) = no λ ()
eqTerm unknown (def f args) = no λ ()
eqTerm unknown (lam v y) = no λ ()
eqTerm unknown (pi t₁ t₂) = no λ ()
eqTerm unknown (agda-sort x) = no λ ()
eqTerm unknown (lit x) = no λ ()
eqTerm (var _ _) (meta _ _) = no λ ()
eqTerm (con _ _) (meta _ _) = no λ ()
eqTerm (def _ _) (meta _ _) = no λ ()
eqTerm (lam _ _) (meta _ _) = no λ ()
eqTerm (pi _ _) (meta _ _) = no λ ()
eqTerm (agda-sort _) (meta _ _) = no λ ()
eqTerm (lit _) (meta _ _) = no λ ()
eqTerm unknown (meta _ _) = no λ ()
eqTerm (meta _ _) (var _ _) = no λ ()
eqTerm (meta _ _) (con _ _) = no λ ()
eqTerm (meta _ _) (def _ _) = no λ ()
eqTerm (meta _ _) (lam _ _) = no λ ()
eqTerm (meta _ _) (pi _ _) = no λ ()
eqTerm (meta _ _) (agda-sort _) = no λ ()
eqTerm (meta _ _) (lit _) = no λ ()
eqTerm (meta _ _) unknown = no λ ()
eqTerm (var _ _) (pat-lam _ _) = no λ ()
eqTerm (con _ _) (pat-lam _ _) = no λ ()
eqTerm (def _ _) (pat-lam _ _) = no λ ()
eqTerm (lam _ _) (pat-lam _ _) = no λ ()
eqTerm (pi _ _) (pat-lam _ _) = no λ ()
eqTerm (meta _ _) (pat-lam _ _) = no λ ()
eqTerm (agda-sort _) (pat-lam _ _) = no λ ()
eqTerm (lit _) (pat-lam _ _) = no λ ()
eqTerm unknown (pat-lam _ _) = no λ ()
eqTerm (pat-lam _ _) (var _ _) = no λ ()
eqTerm (pat-lam _ _) (con _ _) = no λ ()
eqTerm (pat-lam _ _) (def _ _) = no λ ()
eqTerm (pat-lam _ _) (lam _ _) = no λ ()
eqTerm (pat-lam _ _) (pi _ _) = no λ ()
eqTerm (pat-lam _ _) (meta _ _) = no λ ()
eqTerm (pat-lam _ _) (agda-sort _) = no λ ()
eqTerm (pat-lam _ _) (lit _) = no λ ()
eqTerm (pat-lam _ _) unknown = no λ ()
eqSort (set t) (set t₁) = decEq₁ set-inj (eqTerm t t₁)
eqSort (lit n) (lit n₁) = decEq₁ slit-inj (n == n₁)
eqSort unknown unknown = yes refl
eqSort (set t) (lit n) = no λ ()
eqSort (set t) unknown = no λ ()
eqSort (lit n) (set t) = no λ ()
eqSort (lit n) unknown = no λ ()
eqSort unknown (set t) = no λ ()
eqSort unknown (lit n) = no λ ()
eqPat (con c ps) (con c₁ ps₁) = decEq₂ pcon-inj₁ pcon-inj₂ (c == c₁) (eqPats ps ps₁)
eqPat dot dot = yes refl
eqPat (var s) (var s₁) = decEq₁ pvar-inj (s == s₁)
eqPat (lit l) (lit l₁) = decEq₁ plit-inj (l == l₁)
eqPat (proj f) (proj f₁) = decEq₁ proj-inj (f == f₁)
eqPat absurd absurd = yes refl
eqPat (con _ _) dot = no λ ()
eqPat (con _ _) (var _) = no λ ()
eqPat (con _ _) (lit _) = no λ ()
eqPat (con _ _) (proj _) = no λ ()
eqPat (con _ _) absurd = no λ ()
eqPat dot (con _ _) = no λ ()
eqPat dot (var _) = no λ ()
eqPat dot (lit _) = no λ ()
eqPat dot (proj _) = no λ ()
eqPat dot absurd = no λ ()
eqPat (var _) (con _ _) = no λ ()
eqPat (var _) dot = no λ ()
eqPat (var _) (lit _) = no λ ()
eqPat (var _) (proj _) = no λ ()
eqPat (var _) absurd = no λ ()
eqPat (lit _) (con _ _) = no λ ()
eqPat (lit _) dot = no λ ()
eqPat (lit _) (var _) = no λ ()
eqPat (lit _) (proj _) = no λ ()
eqPat (lit _) absurd = no λ ()
eqPat (proj _) (con _ _) = no λ ()
eqPat (proj _) dot = no λ ()
eqPat (proj _) (var _) = no λ ()
eqPat (proj _) (lit _) = no λ ()
eqPat (proj _) absurd = no λ ()
eqPat absurd (con _ _) = no λ ()
eqPat absurd dot = no λ ()
eqPat absurd (var _) = no λ ()
eqPat absurd (lit _) = no λ ()
eqPat absurd (proj _) = no λ ()
eqClause (clause ps t) (clause ps₁ t₁) = decEq₂ clause-inj₁ clause-inj₂ (eqPats ps ps₁) (eqTerm t t₁)
eqClause (absurd-clause ps) (absurd-clause ps₁) = decEq₁ absurd-clause-inj (eqPats ps ps₁)
eqClause (clause _ _) (absurd-clause _) = no λ ()
eqClause (absurd-clause _) (clause _ _) = no λ ()
instance
EqTerm : Eq Term
_==_ {{EqTerm}} = eqTerm
EqSort : Eq Sort
_==_ {{EqSort}} = eqSort
EqClause : Eq Clause
_==_ {{EqClause}} = eqClause
EqPattern : Eq Pattern
_==_ {{EqPattern}} = eqPat
| 39.715254
| 116
| 0.540287
|
10003989d3299ee258b6aeed204e1c17e0cc9ac6
| 1,002
|
agda
|
Agda
|
notes/FOT/FOTC/Program/Mirror/TreeR.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Program/Mirror/TreeR.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Program/Mirror/TreeR.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Well-founded relation on trees
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Mirror.TreeR where
open import FOTC.Base
open import FOTC.Data.List.WF-Relation.LT-Cons
open import FOTC.Program.Mirror.Type
------------------------------------------------------------------------------
-- Well-founded relation on trees.
-- A well-founded relation for rose trees is the lexicographical order
--
-- (t : ts) < (t' : ts') = t < t' or t ≡ t' and ts < ts'.
--
-- It seems we would not to use the first conjunct in the mirror
-- example.
TreeR : D → D → Set
TreeR t₁ t₂ = ∃[ d ] ∃[ ts₁ ] ∃[ ts₂ ]
t₁ ≡ node d ts₁
∧ t₂ ≡ node d ts₂
∧ LTC ts₁ ts₂
| 33.4
| 78
| 0.441118
|
d0020d59f1bc08d0be7bfc459c5e8a2a46d6586e
| 6,428
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Base.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Base.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Base.agda
|
Edlyr/cubical
|
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.CommRing.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Reflection.StrictEquiv
open import Cubical.Structures.Axioms
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring.Base
open Iso
private
variable
ℓ : Level
record IsCommRing {R : Type ℓ}
(0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
constructor iscommring
field
isRing : IsRing 0r 1r _+_ _·_ -_
·-comm : (x y : R) → x · y ≡ y · x
open IsRing isRing public
record CommRingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
constructor commringstr
field
0r : A
1r : A
_+_ : A → A → A
_·_ : A → A → A
-_ : A → A
isCommRing : IsCommRing 0r 1r _+_ _·_ -_
infix 8 -_
infixl 7 _·_
infixl 6 _+_
open IsCommRing isCommRing public
CommRing : Type (ℓ-suc ℓ)
CommRing = TypeWithStr _ CommRingStr
makeIsCommRing : {R : Type ℓ} {0r 1r : R} {_+_ _·_ : R → R → R} { -_ : R → R}
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-comm : (x y : R) → x · y ≡ y · x)
→ IsCommRing 0r 1r _+_ _·_ -_
makeIsCommRing {_+_ = _+_} is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm =
iscommring (makeIsRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid
(λ x → ·-comm _ _ ∙ ·-rid x) ·-rdist-+
(λ x y z → ·-comm _ _ ∙∙ ·-rdist-+ z x y ∙∙ λ i → (·-comm z x i) + (·-comm z y i))) ·-comm
makeCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
(is-setR : isSet R)
(+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+-rid : (x : R) → x + 0r ≡ x)
(+-rinv : (x : R) → x + (- x) ≡ 0r)
(+-comm : (x y : R) → x + y ≡ y + x)
(·-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·-rid : (x : R) → x · 1r ≡ x)
(·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·-comm : (x y : R) → x · y ≡ y · x)
→ CommRing
makeCommRing 0r 1r _+_ _·_ -_ is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm =
_ , commringstr _ _ _ _ _ (makeIsCommRing is-setR +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-rdist-+ ·-comm)
CommRing→Ring : CommRing {ℓ} → Ring
CommRing→Ring (_ , commringstr _ _ _ _ _ H) = _ , ringstr _ _ _ _ _ (IsCommRing.isRing H)
CommRingEquiv : (R S : CommRing) (e : ⟨ R ⟩ ≃ ⟨ S ⟩) → Type ℓ
CommRingEquiv R S e = RingEquiv (CommRing→Ring R) (CommRing→Ring S) e
CommRingHom : (R S : CommRing) → Type ℓ
CommRingHom R S = RingHom (CommRing→Ring R) (CommRing→Ring S)
module CommRingΣTheory {ℓ} where
open RingΣTheory
CommRingAxioms : (R : Type ℓ) (s : RawRingStructure R) → Type ℓ
CommRingAxioms R (_+_ , 1r , _·_) = RingAxioms R (_+_ , 1r , _·_)
× ((x y : R) → x · y ≡ y · x)
CommRingStructure : Type ℓ → Type ℓ
CommRingStructure = AxiomsStructure RawRingStructure CommRingAxioms
CommRingΣ : Type (ℓ-suc ℓ)
CommRingΣ = TypeWithStr ℓ CommRingStructure
CommRingEquivStr : StrEquiv CommRingStructure ℓ
CommRingEquivStr = AxiomsEquivStr RawRingEquivStr CommRingAxioms
isPropCommRingAxioms : (R : Type ℓ) (s : RawRingStructure R)
→ isProp (CommRingAxioms R s)
isPropCommRingAxioms R (_·_ , 0r , _+_) =
isPropΣ (isPropRingAxioms R (_·_ , 0r , _+_))
λ { (_ , x , _) → isPropΠ2 λ _ _ →
x .IsMonoid.isSemigroup .IsSemigroup.is-set _ _}
CommRing→CommRingΣ : CommRing → CommRingΣ
CommRing→CommRingΣ (_ , commringstr _ _ _ _ _ (iscommring G C)) =
_ , _ , Ring→RingΣ (_ , ringstr _ _ _ _ _ G) .snd .snd , C
CommRingΣ→CommRing : CommRingΣ → CommRing
CommRingΣ→CommRing (_ , _ , G , C) =
_ , commringstr _ _ _ _ _ (iscommring (RingΣ→Ring (_ , _ , G) .snd .RingStr.isRing) C)
CommRingIsoCommRingΣ : Iso CommRing CommRingΣ
CommRingIsoCommRingΣ =
iso CommRing→CommRingΣ CommRingΣ→CommRing (λ _ → refl) (λ _ → refl)
commRingUnivalentStr : UnivalentStr CommRingStructure CommRingEquivStr
commRingUnivalentStr = axiomsUnivalentStr _ isPropCommRingAxioms rawRingUnivalentStr
CommRingΣPath : (R S : CommRingΣ) → (R ≃[ CommRingEquivStr ] S) ≃ (R ≡ S)
CommRingΣPath = SIP commRingUnivalentStr
CommRingEquivΣ : (R S : CommRing) → Type ℓ
CommRingEquivΣ R S = CommRing→CommRingΣ R ≃[ CommRingEquivStr ] CommRing→CommRingΣ S
CommRingPath : (R S : CommRing) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] CommRingEquiv R S e) ≃ (R ≡ S)
CommRingPath R S =
Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] CommRingEquiv R S e ≃⟨ strictIsoToEquiv RingIsoΣPath ⟩
CommRingEquivΣ R S ≃⟨ CommRingΣPath _ _ ⟩
CommRing→CommRingΣ R ≡ CommRing→CommRingΣ S
≃⟨ isoToEquiv (invIso (congIso CommRingIsoCommRingΣ)) ⟩
R ≡ S ■
CommRingPath : (R S : CommRing {ℓ}) → (Σ[ e ∈ ⟨ R ⟩ ≃ ⟨ S ⟩ ] CommRingEquiv R S e) ≃ (R ≡ S)
CommRingPath = CommRingΣTheory.CommRingPath
isSetCommRing : ((R , str) : CommRing {ℓ}) → isSet R
isSetCommRing (R , str) = str .CommRingStr.is-set
isPropIsCommRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
→ isProp (IsCommRing 0r 1r _+_ _·_ -_)
isPropIsCommRing 0r 1r _+_ _·_ -_ (iscommring RR RC) (iscommring SR SC) =
λ i → iscommring (isPropIsRing _ _ _ _ _ RR SR i)
(isPropComm RC SC i)
where
isSetR : isSet _
isSetR = RR .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
isPropComm : isProp ((x y : _) → x · y ≡ y · x)
isPropComm = isPropΠ2 λ _ _ → isSetR _ _
| 37.811765
| 115
| 0.569384
|
dc0a68d2ab3854831a4e48f179e6ddf588f61862
| 1,265
|
agda
|
Agda
|
examples/examplesPaperJFP/Colists.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
examples/examplesPaperJFP/Colists.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
examples/examplesPaperJFP/Colists.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module examplesPaperJFP.Colists where
-- open import Function
-- Case expressions (to be used with pattern-matching lambdas, see
-- README.Case).
infix 0 case_return_of_ case_of_
case_return_of_ :
∀ {a b} {A : Set a}
(x : A) (B : A → Set b) → ((x : A) → B x) → B x
case x return B of f = f x
case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = case x return _ of f
data ListF A S : Set where
nil : ListF A S
cons : (a : A) (s : S) → ListF A S
record Colist A : Set where
coinductive
field force : ListF A (Colist A)
open Colist using (force)
mapF : ∀{A S S′} (f : S → S′) → (ListF A S → ListF A S′)
mapF f nil = nil
mapF f (cons a s) = cons a (f s)
-- As an example, we define mapping over potentially infinite lists using
-- copattern matching:
map : ∀{A B} (f : A → B) (l : Colist A) → Colist B
force (map f l) with force l
... | nil = nil
... | cons x xs = cons (f x) (map f xs)
unfold : ∀{A S} (t : S → ListF A S) → (S → Colist A)
force (unfold t s) with t s
... | nil = nil
... | cons a s′ = cons a (unfold t s′)
fmap : ∀{A B} (f : A → B) (l : Colist A) → Colist B
fmap f = unfold λ l → case force l of λ
{ nil → nil
; (cons a s) → cons (f a) s
}
| 24.326923
| 73
| 0.550988
|
508cd9a2423574c67857cea571c473e549c9e148
| 6,875
|
agda
|
Agda
|
Cubical/HITs/SetTruncation/Properties.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetTruncation/Properties.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/SetTruncation/Properties.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Properties of set truncations
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetTruncation.Properties where
open import Cubical.HITs.SetTruncation.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
private
variable
ℓ ℓ' : Level
A B C D : Type ℓ
rec : isSet B → (A → B) → ∥ A ∥₂ → B
rec Bset f ∣ x ∣₂ = f x
rec Bset f (squash₂ x y p q i j) =
Bset _ _ (cong (rec Bset f) p) (cong (rec Bset f) q) i j
rec2 : isSet C → (A → B → C) → ∥ A ∥₂ → ∥ B ∥₂ → C
rec2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y
rec2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) =
Cset _ _ (cong (rec2 Cset f ∣ x ∣₂) p) (cong (rec2 Cset f ∣ x ∣₂) q) i j
rec2 Cset f (squash₂ x y p q i j) z =
Cset _ _ (cong (λ a → rec2 Cset f a z) p) (cong (λ a → rec2 Cset f a z) q) i j
-- Old version:
-- rec2 Cset f = rec (isSetΠ λ _ → Cset) λ x → rec Cset (f x)
-- lemma 6.9.1 in HoTT book
elim : {B : ∥ A ∥₂ → Type ℓ}
(Bset : (x : ∥ A ∥₂) → isSet (B x))
(f : (a : A) → B (∣ a ∣₂))
(x : ∥ A ∥₂) → B x
elim Bset f ∣ a ∣₂ = f a
elim Bset f (squash₂ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 Bset _ _
(cong (elim Bset f) p) (cong (elim Bset f) q) (squash₂ x y p q) i j
elim2 : {C : ∥ A ∥₂ → ∥ B ∥₂ → Type ℓ}
(Cset : ((x : ∥ A ∥₂) (y : ∥ B ∥₂) → isSet (C x y)))
(f : (a : A) (b : B) → C ∣ a ∣₂ ∣ b ∣₂)
(x : ∥ A ∥₂) (y : ∥ B ∥₂) → C x y
elim2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y
elim2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) =
isOfHLevel→isOfHLevelDep 2 (λ a → Cset ∣ x ∣₂ a) _ _
(cong (elim2 Cset f ∣ x ∣₂) p) (cong (elim2 Cset f ∣ x ∣₂) q) (squash₂ y z p q) i j
elim2 Cset f (squash₂ x y p q i j) z =
isOfHLevel→isOfHLevelDep 2 (λ a → Cset a z) _ _
(cong (λ a → elim2 Cset f a z) p) (cong (λ a → elim2 Cset f a z) q) (squash₂ x y p q) i j
-- Old version:
-- elim2 Cset f = elim (λ _ → isSetΠ (λ _ → Cset _ _))
-- (λ a → elim (λ _ → Cset _ _) (f a))
-- TODO: generalize
elim3 : {B : (x y z : ∥ A ∥₂) → Type ℓ}
(Bset : ((x y z : ∥ A ∥₂) → isSet (B x y z)))
(g : (a b c : A) → B ∣ a ∣₂ ∣ b ∣₂ ∣ c ∣₂)
(x y z : ∥ A ∥₂) → B x y z
elim3 Bset g = elim2 (λ _ _ → isSetΠ (λ _ → Bset _ _ _))
(λ a b → elim (λ _ → Bset _ _ _) (g a b))
setTruncUniversal : isSet B → (∥ A ∥₂ → B) ≃ (A → B)
setTruncUniversal {B = B} Bset =
isoToEquiv (iso (λ h x → h ∣ x ∣₂) (rec Bset) (λ _ → refl) rinv)
where
rinv : (f : ∥ A ∥₂ → B) → rec Bset (λ x → f ∣ x ∣₂) ≡ f
rinv f i x =
elim (λ x → isProp→isSet (Bset (rec Bset (λ x → f ∣ x ∣₂) x) (f x)))
(λ _ → refl) x i
setTruncIsSet : isSet ∥ A ∥₂
setTruncIsSet a b p q = squash₂ a b p q
setTruncIdempotent≃ : isSet A → ∥ A ∥₂ ≃ A
setTruncIdempotent≃ {A = A} hA = isoToEquiv f
where
f : Iso ∥ A ∥₂ A
Iso.fun f = rec hA (idfun A)
Iso.inv f x = ∣ x ∣₂
Iso.rightInv f _ = refl
Iso.leftInv f = elim (λ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ → refl)
setTruncIdempotent : isSet A → ∥ A ∥₂ ≡ A
setTruncIdempotent hA = ua (setTruncIdempotent≃ hA)
isContr→isContrSetTrunc : isContr A → isContr (∥ A ∥₂)
isContr→isContrSetTrunc contr = ∣ fst contr ∣₂
, elim (λ _ → isOfHLevelPath 2 (setTruncIsSet) _ _)
λ a → cong ∣_∣₂ (snd contr a)
setTruncIso : Iso A B → Iso ∥ A ∥₂ ∥ B ∥₂
Iso.fun (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.fun is x ∣₂)
Iso.inv (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.inv is x ∣₂)
Iso.rightInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.rightInv is a)
Iso.leftInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.leftInv is a)
setSigmaIso : {B : A → Type ℓ} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
setSigmaIso {A = A} {B = B} = iso fun funinv sect retr
where
{- writing it out explicitly to avoid yellow highlighting -}
fun : ∥ Σ A B ∥₂ → ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
fun = rec setTruncIsSet λ {(a , p) → ∣ a , ∣ p ∣₂ ∣₂}
funinv : ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ → ∥ Σ A B ∥₂
funinv = rec setTruncIsSet (λ {(a , p) → rec setTruncIsSet (λ p → ∣ a , p ∣₂) p})
sect : section fun funinv
sect = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { (a , p) → elim {B = λ p → fun (funinv ∣ a , p ∣₂) ≡ ∣ a , p ∣₂}
(λ p → isOfHLevelPath 2 setTruncIsSet _ _) (λ _ → refl) p }
retr : retract fun funinv
retr = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { _ → refl }
sigmaElim : {B : ∥ A ∥₂ → Type ℓ} {C : Σ ∥ A ∥₂ B → Type ℓ'}
(Bset : (x : Σ ∥ A ∥₂ B) → isSet (C x))
(g : (a : A) (b : B ∣ a ∣₂) → C (∣ a ∣₂ , b))
(x : Σ ∥ A ∥₂ B) → C x
sigmaElim {B = B} {C = C} set g (x , y) =
elim {B = λ x → (y : B x) → C (x , y)} (λ _ → isSetΠ λ _ → set _) g x y
sigmaProdElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} {D : Σ (∥ A ∥₂ × ∥ B ∥₂) C → Type ℓ'}
(Bset : (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → isSet (D x))
(g : (a : A) (b : B) (c : C (∣ a ∣₂ , ∣ b ∣₂)) → D ((∣ a ∣₂ , ∣ b ∣₂) , c))
(x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → D x
sigmaProdElim {B = B} {C = C} {D = D} set g ((x , y) , c) =
elim {B = λ x → (y : ∥ B ∥₂) (c : C (x , y)) → D ((x , y) , c)}
(λ _ → isSetΠ λ _ → isSetΠ λ _ → set _)
(λ x → elim (λ _ → isSetΠ λ _ → set _) (g x))
x y c
prodElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) → isSet (C x))
→ ((a : A) (b : B) → C (∣ a ∣₂ , ∣ b ∣₂))
→ (x : ∥ A ∥₂ × ∥ B ∥₂) → C x
prodElim setC f (a , b) = elim2 (λ x y → setC (x , y)) f a b
prodRec : {C : Type ℓ} → isSet C → (A → B → C) → ∥ A ∥₂ × ∥ B ∥₂ → C
prodRec setC f (a , b) = rec2 setC f a b
prodElim2 : {E : (∥ A ∥₂ × ∥ B ∥₂) → (∥ C ∥₂ × ∥ D ∥₂) → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → isSet (E x y))
→ ((a : A) (b : B) (c : C) (d : D) → E (∣ a ∣₂ , ∣ b ∣₂) (∣ c ∣₂ , ∣ d ∣₂))
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → (E x y))
prodElim2 isset f = prodElim (λ _ → isSetΠ λ _ → isset _ _)
λ a b → prodElim (λ _ → isset _ _)
λ c d → f a b c d
setTruncOfProdIso : Iso ∥ A × B ∥₂ (∥ A ∥₂ × ∥ B ∥₂)
Iso.fun setTruncOfProdIso = rec (isSet× setTruncIsSet setTruncIsSet) λ { (a , b) → ∣ a ∣₂ , ∣ b ∣₂ }
Iso.inv setTruncOfProdIso = prodRec setTruncIsSet λ a b → ∣ a , b ∣₂
Iso.rightInv setTruncOfProdIso =
prodElim (λ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _) λ _ _ → refl
Iso.leftInv setTruncOfProdIso =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ {(a , b) → refl}
| 39.97093
| 100
| 0.504582
|
4ab717df5b821a1a5ad08aeb1ff6fdadeb4ca7dc
| 4,787
|
agda
|
Agda
|
Cubical/HITs/KleinBottle/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/KleinBottle/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/KleinBottle/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-
Definition of the Klein bottle as a HIT
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.KleinBottle.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Data.Nat
open import Cubical.Data.Int public renaming (_+_ to _+Int_ ; +-assoc to +Int-assoc; +-comm to +Int-comm)
open import Cubical.Data.Prod
open import Cubical.Data.Sigma
open import Cubical.HITs.S1
open import Cubical.HITs.PropositionalTruncation as PropTrunc
open import Cubical.HITs.KleinBottle.Base
loop1 : S¹ → KleinBottle
loop1 base = point
loop1 (loop i) = line1 i
invS¹Loop : S¹ → Set
invS¹Loop base = S¹
invS¹Loop (loop i) = invS¹Path i
loop1Inv : (s : S¹) → loop1 (inv s) ≡ loop1 s
loop1Inv base = line2
loop1Inv (loop i) = square i
twist : (s : S¹) → PathP (λ i → invS¹Path i) s (inv s)
twist s i = glue (λ {(i = i0) → s; (i = i1) → inv s}) (inv s)
twistBaseLoop : (s : S¹) → invS¹Loop s
twistBaseLoop base = base
twistBaseLoop (loop i) = twist base i
kleinBottle≃Σ : KleinBottle ≃ Σ S¹ invS¹Loop
kleinBottle≃Σ = isoToEquiv (iso fro to froTo toFro)
where
fro : KleinBottle → Σ S¹ invS¹Loop
fro point = (base , base)
fro (line1 i) = (base , loop i)
fro (line2 j) = (loop (~ j) , twist base (~ j))
fro (square i j) = (loop (~ j) , twist (loop i) (~ j))
toLoopFiller : (j : I) → ua invS¹Equiv j → I → KleinBottle
toLoopFiller j g l =
hfill
(λ l → λ
{ (j = i0) → loop1Inv g l
; (j = i1) → loop1 g
})
(inS (loop1 (unglue (j ∨ ~ j) g)))
l
to : Σ S¹ invS¹Loop → KleinBottle
to (base , s) = loop1 s
to (loop j , g) = toLoopFiller j g i1
toFro : (a : KleinBottle) → to (fro a) ≡ a
toFro point = refl
toFro (line1 i) = refl
toFro (line2 j) k = lUnit line2 (~ k) j
toFro (square i j) k = lUnit (square i) (~ k) j
froLoop1 : (s : S¹) → fro (loop1 s) ≡ (base , s)
froLoop1 base = refl
froLoop1 (loop i) = refl
froLoop1Inv :
PathP (λ k → (s : S¹) → froLoop1 (inv s) k ≡ froLoop1 s k)
(λ s l → fro (loop1Inv s l))
(λ s l → loop (~ l) , twist s (~ l))
froLoop1Inv k base l = loop (~ l) , twist base (~ l)
froLoop1Inv k (loop i) l = loop (~ l) , twist (loop i) (~ l)
froTo : (a : Σ S¹ invS¹Loop) → fro (to a) ≡ a
froTo (base , s) = froLoop1 s
froTo (loop j , g) k =
hcomp
(λ l → λ
{ (j = i0) → froLoop1Inv k g l
; (j = i1) → froLoop1 g k
; (k = i0) → fro (toLoopFiller j g l)
; (k = i1) →
( loop (j ∨ ~ l)
, glue
(λ
{ (j = i0) (l = i1) → g
; (j = i1) → g
; (l = i0) → unglue (j ∨ ~ j) g
})
(unglue (j ∨ ~ j) g)
)
})
(froLoop1 (unglue (j ∨ ~ j) g) k)
isGroupoidKleinBottle : isGroupoid KleinBottle
isGroupoidKleinBottle =
transport (λ i → isGroupoid (ua kleinBottle≃Σ (~ i)))
(isOfHLevelΣ 3 isGroupoidS¹
(λ s →
PropTrunc.rec
(isPropIsOfHLevel 3)
(λ p → subst (λ s → isGroupoid (invS¹Loop s)) p isGroupoidS¹)
(isConnectedS¹ s)))
-- Transport across the following is too slow :(
ΩKlein≡Int² : Path KleinBottle point point ≡ Int × Int
ΩKlein≡Int² =
Path KleinBottle point point
≡⟨ (λ i → basePath i ≡ basePath i) ⟩
Path (Σ S¹ invS¹Loop) (base , base) (base , base)
≡⟨ sym (ua Σ≡) ⟩
Σ ΩS¹ (λ p → PathP (λ j → invS¹Loop (p j)) base base)
≡⟨ (λ i → Σ ΩS¹ (λ p → PathP (λ j → invS¹Loop (p (j ∨ i))) (twistBaseLoop (p i)) base)) ⟩
Σ ΩS¹ (λ _ → ΩS¹)
≡⟨ sym A×B≡A×ΣB ⟩
ΩS¹ × ΩS¹
≡⟨ (λ i → ΩS¹≡Int i × ΩS¹≡Int i) ⟩
Int × Int ∎
where
basePath : PathP (λ i → ua kleinBottle≃Σ i) point (base , base)
basePath i = glue (λ {(i = i0) → point; (i = i1) → base , base}) (base , base)
-- We can at least define the winding function directly and get results on small examples
windingKlein : Path KleinBottle point point → Int × Int
windingKlein p = (z₀ , z₁)
where
step₀ : Path (Σ S¹ invS¹Loop) (base , base) (base , base)
step₀ = (λ i → kleinBottle≃Σ .fst (p i))
z₀ : Int
z₀ = winding (λ i → kleinBottle≃Σ .fst (p i) .fst)
z₁ : Int
z₁ = winding
(transport
(λ i → PathP (λ j → invS¹Loop (step₀ (j ∨ i) .fst)) (twistBaseLoop (step₀ i .fst)) base)
(cong snd step₀))
_ : windingKlein line1 ≡ (pos 0 , pos 1)
_ = refl
_ : windingKlein line2 ≡ (negsuc 0 , pos 0)
_ = refl
_ : windingKlein (line1 ∙ line2) ≡ (negsuc 0 , negsuc 0)
_ = refl
_ : windingKlein (line1 ∙ line2 ∙ line1) ≡ (negsuc 0 , pos 0)
_ = refl
| 29.189024
| 105
| 0.594318
|
231c120927d5371672ce35239fd659afdcf9aa98
| 387
|
agda
|
Agda
|
test/Compiler/with-stdlib/TrustMe.agda
|
andreasabel/agda-with-old-branches
|
04941fb75be06039b0085ab047117625294cbc99
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Compiler/with-stdlib/TrustMe.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Compiler/with-stdlib/TrustMe.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
module TrustMe where
open import Data.String
open import Data.Unit using (⊤)
open import IO
import IO.Primitive as Prim
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
-- Check that trustMe works.
testTrustMe : IO ⊤
testTrustMe with "apa" ≟ "apa"
... | yes refl = putStrLn "Yes!"
... | no _ = putStrLn "No."
main : Prim.IO ⊤
main = run testTrustMe
| 20.368421
| 49
| 0.723514
|
3906499be099b7aaa45304f9fc694b1597b71bc5
| 2,082
|
agda
|
Agda
|
test/LibSucceed/SizeInconsistentMeta4.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/LibSucceed/SizeInconsistentMeta4.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/LibSucceed/SizeInconsistentMeta4.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2012-02-24 example by Ramana Kumar
{-# OPTIONS --sized-types #-}
-- {-# OPTIONS --show-implicit -v tc.size.solve:20 -v tc.conv.size:15 #-}
module SizeInconsistentMeta4 where
open import Data.Nat using (ℕ;zero;suc) renaming (_<_ to _N<_)
open import Data.Product using (_,_;_×_)
open import Data.Product.Relation.Binary.Lex.Strict using (×-Lex; ×-transitive)
open import Data.List using (List)
open import Data.List.Relation.Binary.Lex.Strict using (Lex-<) renaming (<-transitive to Lex<-trans)
open import Relation.Binary using (Rel;_Respects₂_;Transitive;IsEquivalence)
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_)
open import Level using (0ℓ)
open import Size using (Size;↑_)
-- keeping the definition of Vec for the positivity check
infixr 5 _∷_
data Vec {a} (A : Set a) : ℕ → Set a where
[] : Vec A zero
_∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n)
{- produces different error
data Lex-< {A : _} (_≈_ _<_ : Rel A Level.zero) : Rel (List A) Level.zero where
postulate
Lex<-trans : ∀ {P _≈_ _<_} →
IsEquivalence _≈_ → _<_ Respects₂ _≈_ → Transitive _<_ →
Transitive (Lex-< _≈_ _<_)
-}
postulate
N<-trans : Transitive _N<_
-- Vec : ∀ {a} (A : Set a) → ℕ → Set a
Vec→List : ∀ {a n} {A : Set a} → Vec A n → List A
data Type : Size → Set where
TyApp : {z : Size} (n : ℕ) → (as : Vec (Type z) n) → Type (↑ z)
<-transf : ∀ {z} → Rel (Type z) 0ℓ → Rel (ℕ × List (Type z)) 0ℓ
<-transf _<_ = ×-Lex _≡_ _N<_ (Lex-< _≡_ _<_)
infix 4 _<_
data _<_ : {z : Size} → Rel (Type z) 0ℓ where
TyApp<TyApp : ∀ {z} {n₁} {as₁} {n₂} {as₂} →
<-transf (_<_ {z}) (n₁ , Vec→List as₁) (n₂ , Vec→List as₂) →
_<_ {↑ z} (TyApp n₁ as₁) (TyApp n₂ as₂)
<-trans : ∀ {z} → Transitive (_<_ {z})
<-trans (TyApp<TyApp p) (TyApp<TyApp q) =
TyApp<TyApp (×-transitive {_<₂_ = Lex-< _≡_ _<_}
PropEq.isEquivalence
(PropEq.resp₂ _N<_)
N<-trans
(Lex<-trans PropEq.isEquivalence (PropEq.resp₂ _<_) <-trans)
p q)
| 36.526316
| 100
| 0.595581
|
cb697b96d3fb4c3725163512c454cabcccd73dd2
| 7,525
|
agda
|
Agda
|
theorems/homotopy/3x3/From.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/homotopy/3x3/From.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/homotopy/3x3/From.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
--open import HoTT
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
open import homotopy.3x3.Common
module homotopy.3x3.From {i} (d : Span^2 {i}) where
open Span^2 d
open M d hiding (Pushout^2)
open M (transpose d) using () renaming (A₀∙ to A∙₀; A₂∙ to A∙₂; A₄∙ to A∙₄;
module F₁∙ to F∙₁; f₁∙ to f∙₁;
module F₃∙ to F∙₃; f₃∙ to f∙₃;
v-h-span to h-v-span)
open M using (Pushout^2)
module I∙₀ = PushoutRec {D = Pushout^2 d}
(left ∘ left) (right ∘ left) (glue ∘ left)
i∙₀ : A∙₀ → Pushout^2 d
i∙₀ = I∙₀.f
module I∙₄ = PushoutRec {D = Pushout^2 d}
(left ∘ right) (right ∘ right) (glue ∘ right)
i∙₄ : A∙₄ → Pushout^2 d
i∙₄ = I∙₄.f
module E∙₂Red (c : A₂₂) where
lhs-o : _
lhs-o =
ap (i∙₄ ∘ f∙₃) (glue c)
=⟨ ap-∘ i∙₄ f∙₃ (glue c) ⟩
ap i∙₄ (ap f∙₃ (glue c))
=⟨ F∙₃.glue-β c |in-ctx (ap i∙₄) ⟩
ap i∙₄ (ap left (H₁₃ c) ∙ glue (f₂₃ c) ∙ ap right (! (H₃₃ c)))
=⟨ ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c) ⟩
ap (left ∘ right) (H₁₃ c) ∙ ap i∙₄ (glue (f₂₃ c)) ∙ ! (ap (right ∘ right) (H₃₃ c))
=⟨ I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))) ⟩
ap (left ∘ right) (H₁₃ c) ∙ glue (right (f₂₃ c)) ∙ ! (ap (right ∘ right) (H₃₃ c)) ∎
rhs-o : _
rhs-o =
! (ap (left ∘ left) (H₁₁ c)) ∙ glue (left (f₂₁ c)) ∙ ap (right ∘ left) (H₃₁ c)
=⟨ ! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))) ⟩
! (ap (left ∘ left) (H₁₁ c)) ∙ ap i∙₀ (glue (f₂₁ c)) ∙ ap (right ∘ left) (H₃₁ c)
=⟨ ! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)) ⟩
ap i∙₀ (ap left (! (H₁₁ c)) ∙ glue (f₂₁ c) ∙ ap right (H₃₁ c))
=⟨ ! (F∙₁.glue-β c) |in-ctx (λ u → ap i∙₀ u) ⟩
ap i∙₀ (ap f∙₁ (glue c))
=⟨ ∘-ap i∙₀ f∙₁ (glue c) ⟩
ap (i∙₀ ∘ f∙₁) (glue c) ∎
T-lhs : Type _
T-lhs = right (left (f₃₀ (f₂₁ c))) == right (right (f₃₄ (f₂₃ c))) :> Pushout^2 d
lhs-i : _ == _ :> T-lhs
lhs-i =
ap (right ∘ left) (H₃₁ c) ∙ ap right (glue (f₃₂ c)) ∙ ap (right ∘ right) (H₃₃ c)
=⟨ ! (ap-∙∙`∘`∘ right left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)) ⟩
ap right (ap left (H₃₁ c) ∙ glue (f₃₂ c) ∙ ap right (H₃₃ c))
=⟨ ! (ap (ap right) (F₃∙.glue-β c)) ⟩
ap right (ap f₃∙ (glue c))
=⟨ ∘-ap right f₃∙ (glue c) ⟩
ap (right ∘ f₃∙) (glue c) ∎
T-rhs : Type _
T-rhs = left (left (f₁₀ (f₂₁ c))) == left (right (f₁₄ (f₂₃ c))) :> Pushout^2 d
rhs-i : _ == _ :> T-rhs
rhs-i =
ap (left ∘ f₁∙) (glue c)
=⟨ ap-∘ left f₁∙ (glue c) ⟩
ap left (ap f₁∙ (glue c))
=⟨ F₁∙.glue-β c |in-ctx (ap left) ⟩
ap left (ap left (H₁₁ c) ∙ glue (f₁₂ c) ∙ ap right (H₁₃ c))
=⟨ ap-∙∙`∘`∘ left left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c) ⟩
(ap (left ∘ left) (H₁₁ c) ∙ ap left (glue (f₁₂ c)) ∙ ap (left ∘ right) (H₁₃ c)) ∎
coh! : (p : (_ , _ =□ _ , _)) → _
coh! = pp-coh! {A = Pushout^2 d}
{u = glue (left (f₂₁ c))}
{ap (right ∘ left) (H₃₁ c)}
{ap right (glue (f₃₂ c))}
{ap (right ∘ right) (H₃₃ c)}
{ap (left ∘ left) (H₁₁ c)}
{ap left (glue (f₁₂ c))}
{ap (left ∘ right) (H₁₃ c)}
{glue (right (f₂₃ c))}
coh : (p : (_ , _ =□ _ , _)) → _
coh = pp-coh {A = Pushout^2 d}
{p = ap left (glue (f₁₂ c))}
{ap (left ∘ right) (H₁₃ c)}
{glue (right (f₂₃ c))}
{ap (right ∘ right) (H₃₃ c)}
{ap (left ∘ left) (H₁₁ c)}
{glue (left (f₂₁ c))}
{ap (right ∘ left) (H₃₁ c)}
{ap right (glue (f₃₂ c))}
module _ (to : Pushout^2 d → Pushout^2 (transpose d)) where
ap-ap-coh! : (p : _ , _ =□ _ , _) → _
ap-ap-coh! = pp-coh! {u = ap to (glue (left (f₂₁ c)))}
{ap (to ∘ right ∘ left) (H₃₁ c)}
{ap to (ap right (glue (f₃₂ c)))}
{ap (to ∘ right ∘ right) (H₃₃ c)}
{ap (to ∘ left ∘ left) (H₁₁ c)}
{ap to (ap left (glue (f₁₂ c)))}
{ap (to ∘ left ∘ right) (H₁₃ c)}
{ap to (glue (right (f₂₃ c)))}
ap-ap-coh : (p : _ , _ =□ _ , _) → _
ap-ap-coh = pp-coh {p = ap to (ap left (glue (f₁₂ c)))}
{ap (to ∘ left ∘ right) (H₁₃ c)}
{ap to (glue (right (f₂₃ c)))}
{ap (to ∘ right ∘ right) (H₃₃ c)}
{ap (to ∘ left ∘ left) (H₁₁ c)}
{ap to (glue (left (f₂₁ c)))}
{ap (to ∘ right ∘ left) (H₃₁ c)}
{ap to (ap right (glue (f₃₂ c)))}
ap-ap-coh!-lhs-i : _
ap-ap-coh!-lhs-i = ! (ap-∙∙`∘`∘ to (right ∘ left) (right ∘ right) (H₃₁ c) (ap right (glue (f₃₂ c))) (H₃₃ c))
ap-ap-coh!-rhs-i : _
ap-ap-coh!-rhs-i = ap-∙∙`∘`∘ to (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₁₂ c))) (H₁₃ c)
ap-ap-coh!-lhs-o : _
ap-ap-coh!-lhs-o = ap-∙∙!'`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (H₃₃ c)
ap-ap-coh!-rhs-o : _
ap-ap-coh!-rhs-o = ! (ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c))
ap-ap-coh!-β : (α : _)
→ ap□ to (coh! α) == ap-ap-coh! (ap□ to α
∙□-i/ ap-ap-coh!-lhs-i
/ ap-ap-coh!-rhs-i /)
∙□-i/ ap-ap-coh!-lhs-o
/ ap-ap-coh!-rhs-o /
ap-ap-coh!-β α = ap□-coh! {g₁ = left ∘ right} {right ∘ right} {left ∘ left} {right ∘ left} to
{u = glue (left (f₂₁ c))} {H₃₁ c} {ap right (glue (f₃₂ c))} {H₃₃ c}
{H₁₁ c} {ap left (glue (f₁₂ c))} {H₁₃ c} {glue (right (f₂₃ c))}
α
open E∙₂Red
module E∙₂ = PushoutElim {d = span _ _ _ f₁₂ f₃₂} {P = λ c → i∙₀ (f∙₁ c) == i∙₄ (f∙₃ c)}
(ap left ∘ glue) (ap right ∘ glue)
(λ c → ↓-='-in' (coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ lhs-i c / rhs-i c /)
∙□-i/ lhs-o c / rhs-o c /))
e∙₂ : (c : A∙₂) → i∙₀ (f∙₁ c) == i∙₄ (f∙₃ c)
e∙₂ = E∙₂.f
module From = PushoutRec {d = h-v-span} {D = Pushout^2 d}
i∙₀ i∙₄ e∙₂
from : Pushout^2 (transpose d) → Pushout^2 d
from = From.f
from-glue-glue-β : (c : A₂₂) → ap↓ (ap from) (apd glue (glue c))
== (↓-='-in' (coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ lhs-i c / rhs-i c /)
∙□-i/ lhs-o c / rhs-o c /))
◃/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /
from-glue-glue-β c = ∘'-apd (ap from) glue (glue c)
∙ coh1 {p = apd (ap from ∘ glue) (glue c)} {From.glue-β (right (f₃₂ c))}
{From.glue-β (left (f₁₂ c))} {apd e∙₂ (glue c)}
(↓-=-out (apd From.glue-β (glue c)))
∙ (E∙₂.glue-β c |in-ctx (λ u → u ◃/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c)))/))
| 42.755682
| 118
| 0.413821
|
1086d39c5ab0c25a0ece2293c8a5b9a6c942c44d
| 378
|
agda
|
Agda
|
prototyping/Luau/Value.agda
|
Tr4shh/Roblox-Luau
|
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
|
[
"MIT"
] | null | null | null |
prototyping/Luau/Value.agda
|
Tr4shh/Roblox-Luau
|
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
|
[
"MIT"
] | null | null | null |
prototyping/Luau/Value.agda
|
Tr4shh/Roblox-Luau
|
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
|
[
"MIT"
] | null | null | null |
module Luau.Value where
open import Agda.Builtin.Float using (Float)
open import Luau.Addr using (Addr)
open import Luau.Syntax using (Block; Expr; nil; addr; number)
open import Luau.Var using (Var)
data Value : Set where
nil : Value
addr : Addr → Value
number : Float → Value
val : ∀ {a} → Value → Expr a
val nil = nil
val (addr a) = addr a
val (number x) = number x
| 22.235294
| 62
| 0.693122
|
0e7dbfd211145d66629440d6605316a326c8e0aa
| 20,801
|
agda
|
Agda
|
Definition/LogicalRelation.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Definition/LogicalRelation.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U
open import Definition.Typed
open import Definition.Typed.Weakening
open import Definition.Typed.Reduction
open import Tools.Product
import Tools.PropositionalEquality as PE
import Data.Fin as Fin
import Data.Nat as Nat
-- The different cases of the logical relation are spread out through out
-- this file. This is due to them having different dependencies.
-- We will refer to expressions that satisfies the logical relation as reducible.
-- Reducibility of Neutrals:
-- Neutral type
record _⊩ne_^[_,_] (Γ : Con Term) (A : Term) (r : Relevance) (l : Level) : Set where
constructor ne
field
K : Term
D : Γ ⊢ A :⇒*: K ^ [ r , ι l ]
neK : Neutral K
K≡K : Γ ⊢ K ~ K ∷ (Univ r l) ^ [ ! , next l ]
-- Neutral type equality
record _⊩ne_≡_^[_,_]/_ (Γ : Con Term) (A B : Term) (r : Relevance) (l : Level) ([A] : Γ ⊩ne A ^[ r , l ]) : Set where
constructor ne₌
open _⊩ne_^[_,_] [A]
field
M : Term
D′ : Γ ⊢ B :⇒*: M ^ [ r , ι l ]
neM : Neutral M
K≡M : Γ ⊢ K ~ M ∷ (Univ r l) ^ [ ! , next l ]
-- Neutral term in WHNF
record _⊩neNf_∷_^_ (Γ : Con Term) (k A : Term) (r : TypeInfo) : Set where
inductive
constructor neNfₜ
field
neK : Neutral k
⊢k : Γ ⊢ k ∷ A ^ r
k≡k : Γ ⊢ k ~ k ∷ A ^ r
-- Neutral relevant term
record _⊩ne_∷_^_/_ (Γ : Con Term) (t A : Term) (l : Level) ([A] : Γ ⊩ne A ^[ ! , l ]) : Set where
inductive
constructor neₜ
open _⊩ne_^[_,_] [A]
field
k : Term
d : Γ ⊢ t :⇒*: k ∷ K ^ ι l
nf : Γ ⊩neNf k ∷ K ^ [ ! , ι l ]
-- Neutral irrelevant term
record _⊩neIrr_∷_^_/_ (Γ : Con Term) (t A : Term) (l : Level) ([A] : Γ ⊩ne A ^[ % , l ]) : Set where
inductive
constructor neₜ
open _⊩ne_^[_,_] [A]
field
d : Γ ⊢ t ∷ A ^ [ % , ι l ]
-- Neutral term equality in WHNF
record _⊩neNf_≡_∷_^_ (Γ : Con Term) (k m A : Term) (r : TypeInfo) : Set where
inductive
constructor neNfₜ₌
field
neK : Neutral k
neM : Neutral m
k≡m : Γ ⊢ k ~ m ∷ A ^ r
-- Neutral relevant term equality
record _⊩ne_≡_∷_^_/_ (Γ : Con Term) (t u A : Term) (l : Level) ([A] : Γ ⊩ne A ^[ ! , l ]) : Set where
constructor neₜ₌
open _⊩ne_^[_,_] [A]
field
k m : Term
d : Γ ⊢ t :⇒*: k ∷ K ^ ι l
d′ : Γ ⊢ u :⇒*: m ∷ K ^ ι l
nf : Γ ⊩neNf k ≡ m ∷ K ^ [ ! , ι l ]
-- Neutral irrelevant term equality
record _⊩neIrr_≡_∷_^_/_ (Γ : Con Term) (t u A : Term) (l : Level) ([A] : Γ ⊩ne A ^[ % , l ]) : Set where
constructor neₜ₌
open _⊩ne_^[_,_] [A]
field
d : Γ ⊢ t ∷ A ^ [ % , ι l ]
d′ : Γ ⊢ u ∷ A ^ [ % , ι l ]
-- Reducibility of natural numbers:
-- Natural number type
_⊩ℕ_ : (Γ : Con Term) (A : Term) → Set
Γ ⊩ℕ A = Γ ⊢ A :⇒*: ℕ ^ [ ! , ι ⁰ ]
-- Natural number type equality
_⊩ℕ_≡_ : (Γ : Con Term) (A B : Term) → Set
Γ ⊩ℕ A ≡ B = Γ ⊢ B ⇒* ℕ ^ [ ! , ι ⁰ ]
mutual
-- Natural number term
data _⊩ℕ_∷ℕ (Γ : Con Term) (t : Term) : Set where
ℕₜ : (n : Term) (d : Γ ⊢ t :⇒*: n ∷ ℕ ^ ι ⁰) (n≡n : Γ ⊢ n ≅ n ∷ ℕ ^ [ ! , ι ⁰ ])
(prop : Natural-prop Γ n)
→ Γ ⊩ℕ t ∷ℕ
-- WHNF property of natural number terms
data Natural-prop (Γ : Con Term) : (n : Term) → Set where
sucᵣ : ∀ {n} → Γ ⊩ℕ n ∷ℕ → Natural-prop Γ (suc n)
zeroᵣ : Natural-prop Γ zero
ne : ∀ {n} → Γ ⊩neNf n ∷ ℕ ^ [ ! , ι ⁰ ] → Natural-prop Γ n
mutual
-- Natural number term equality
data _⊩ℕ_≡_∷ℕ (Γ : Con Term) (t u : Term) : Set where
ℕₜ₌ : (k k′ : Term) (d : Γ ⊢ t :⇒*: k ∷ ℕ ^ ι ⁰) (d′ : Γ ⊢ u :⇒*: k′ ∷ ℕ ^ ι ⁰)
(k≡k′ : Γ ⊢ k ≅ k′ ∷ ℕ ^ [ ! , ι ⁰ ])
(prop : [Natural]-prop Γ k k′) → Γ ⊩ℕ t ≡ u ∷ℕ
-- WHNF property of Natural number term equality
data [Natural]-prop (Γ : Con Term) : (n n′ : Term) → Set where
sucᵣ : ∀ {n n′} → Γ ⊩ℕ n ≡ n′ ∷ℕ → [Natural]-prop Γ (suc n) (suc n′)
zeroᵣ : [Natural]-prop Γ zero zero
ne : ∀ {n n′} → Γ ⊩neNf n ≡ n′ ∷ ℕ ^ [ ! , ι ⁰ ] → [Natural]-prop Γ n n′
-- Natural extraction from term WHNF property
natural : ∀ {Γ n} → Natural-prop Γ n → Natural n
natural (sucᵣ x) = sucₙ
natural zeroᵣ = zeroₙ
natural (ne (neNfₜ neK ⊢k k≡k)) = ne neK
-- Natural extraction from term equality WHNF property
split : ∀ {Γ a b} → [Natural]-prop Γ a b → Natural a × Natural b
split (sucᵣ x) = sucₙ , sucₙ
split zeroᵣ = zeroₙ , zeroₙ
split (ne (neNfₜ₌ neK neM k≡m)) = ne neK , ne neM
-- Reducibility of Empty
-- Empty type
_⊩Empty_^_ : (Γ : Con Term) (A : Term) (l : Level) → Set
Γ ⊩Empty A ^ l = Γ ⊢ A :⇒*: Empty l ^ [ % , ι l ]
-- Empty type equality
_⊩Empty_≡_^_ : (Γ : Con Term) (A B : Term) (l : Level) → Set
Γ ⊩Empty A ≡ B ^ l = Γ ⊢ B ⇒* Empty l ^ [ % , ι l ]
data Empty-prop (Γ : Con Term) (n : Term) (l : Level) : Set where
ne : Γ ⊢ n ∷ Empty l ^ [ % , ι l ] → Empty-prop Γ n l
-- -- Empty term
data _⊩Empty_∷Empty^_ (Γ : Con Term) (t : Term) (l : Level) : Set where
Emptyₜ : (prop : Empty-prop Γ t l) → Γ ⊩Empty t ∷Empty^ l
data [Empty]-prop (Γ : Con Term) : (n n′ : Term) (l : Level) → Set where
ne : ∀ {n n′ l} → Γ ⊢ n ∷ Empty l ^ [ % , ι l ] → Γ ⊢ n′ ∷ Empty l ^ [ % , ι l ] → [Empty]-prop Γ n n′ l
-- Empty term equality
data _⊩Empty_≡_∷Empty^_ (Γ : Con Term) (t u : Term) (l : Level) : Set where
Emptyₜ₌ : (prop : [Empty]-prop Γ t u l) → Γ ⊩Empty t ≡ u ∷Empty^ l
-- Logical relation
record LogRelKit : Set₁ where
constructor Kit
field
_⊩U_^_ : (Γ : Con Term) → Term → TypeLevel → Set
_⊩Π_^[_,_] : (Γ : Con Term) → Term → Relevance → Level → Set
_⊩∃_^_ : (Γ : Con Term) → Term → Level → Set
_⊩_^_ : (Γ : Con Term) → Term → TypeInfo → Set
_⊩_≡_^_/_ : (Γ : Con Term) (A B : Term) (r : TypeInfo) → Γ ⊩ A ^ r → Set
_⊩_∷_^_/_ : (Γ : Con Term) (t A : Term) (r : TypeInfo) → Γ ⊩ A ^ r → Set
_⊩_≡_∷_^_/_ : (Γ : Con Term) (t u A : Term) (r : TypeInfo) → Γ ⊩ A ^ r → Set
module LogRel (l : TypeLevel) (rec : ∀ {l′} → l′ <∞ l → LogRelKit) where
-- Reducibility of Universe:
-- Universe type
record _⊩¹U_^_ (Γ : Con Term) (A : Term) (ll : TypeLevel) : Set where
constructor Uᵣ
field
r : Relevance
l′ : Level
l< : ι l′ <∞ l
eq : next l′ PE.≡ ll
d : Γ ⊢ A :⇒*: Univ r l′ ^ [ ! , next l′ ]
-- Universe type equality
_⊩¹U_≡_^_/_ : (Γ : Con Term) (A B : Term) (ll : TypeLevel) ([A] : Γ ⊩¹U A ^ ll) → Set
Γ ⊩¹U A ≡ B ^ ll / [A] = Γ ⊢ B ⇒* Univ (_⊩¹U_^_.r [A]) (_⊩¹U_^_.l′ [A]) ^ [ ! , ll ]
-- Universe term
record _⊩¹U_∷_^_/_ (Γ : Con Term) (t : Term) (A : Term) (ll : TypeLevel) ([A] : Γ ⊩¹U A ^ ll) : Set where
constructor Uₜ
open _⊩¹U_^_ [A]
open LogRelKit (rec l<)
field
K : Term
d : Γ ⊢ t :⇒*: K ∷ Univ r l′ ^ next l′
typeK : Type K
K≡K : Γ ⊢ K ≅ K ∷ Univ r l′ ^ [ ! , next l′ ]
[t] : ∀ {ρ Δ} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ) → Δ ⊩ U.wk ρ t ^ [ r , ι l′ ]
-- Universe term equality
record _⊩¹U_≡_∷_^_/_ (Γ : Con Term) (t u : Term) (X : Term) (ll : TypeLevel) ([X] : Γ ⊩¹U X ^ ll) : Set where
constructor Uₜ₌
open _⊩¹U_^_ [X]
open LogRelKit (rec l<)
field
[t] : Γ ⊩¹U t ∷ X ^ ll / [X]
[u] : Γ ⊩¹U u ∷ X ^ ll / [X]
A≡B : Γ ⊢ _⊩¹U_∷_^_/_.K [t] ≅ _⊩¹U_∷_^_/_.K [u] ∷ Univ r l′ ^ [ ! , next l′ ]
[t≡u] : ∀ {ρ Δ} → ([ρ] : ρ ∷ Δ ⊆ Γ) → (⊢Δ : ⊢ Δ) → Δ ⊩ U.wk ρ t ≡ U.wk ρ u ^ [ r , ι l′ ] / _⊩¹U_∷_^_/_.[t] [t] [ρ] ⊢Δ
mutual
-- Reducibility of Π:
-- Π-type
record _⊩¹Π_^[_,_] (Γ : Con Term) (A : Term) (r : Relevance) (lΠ : Level) : Set where
inductive
eta-equality
constructor Πᵣ
field
rF : Relevance
lF : Level
lG : Level
lF≤ : lF ≤ lΠ
lG≤ : lG ≤ lΠ
F : Term
G : Term
D : Γ ⊢ A :⇒*: Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ r , ι lΠ ]
⊢F : Γ ⊢ F ^ [ rF , ι lF ]
⊢G : Γ ∙ F ^ [ rF , ι lF ] ⊢ G ^ [ r , ι lG ]
A≡A : Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≅ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ r , ι lΠ ]
[F] : ∀ {ρ Δ} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ) → Δ ⊩¹ U.wk ρ F ^ [ rF , ι lF ]
[G] : ∀ {ρ Δ a}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊩¹ a ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ
→ Δ ⊩¹ U.wk (lift ρ) G [ a ] ^ [ r , ι lG ]
G-ext : ∀ {ρ Δ a b}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩¹ a ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
→ ([b] : Δ ⊩¹ b ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
→ Δ ⊩¹ a ≡ b ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ
→ Δ ⊩¹ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G [ b ] ^ [ r , ι lG ] / [G] [ρ] ⊢Δ [a]
-- Π-type equality
record _⊩¹Π_≡_^[_,_]/_ (Γ : Con Term) (A B : Term) (r : Relevance) (lΠ : Level) ([A] : Γ ⊩¹Π A ^[ r , lΠ ]) : Set where
inductive
eta-equality
constructor Π₌
open _⊩¹Π_^[_,_] [A]
field
F′ : Term
G′ : Term
D′ : Γ ⊢ B ⇒* Π F′ ^ rF ° lF ▹ G′ ° lG ° lΠ ^ [ r , ι lΠ ]
A≡B : Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≅ Π F′ ^ rF ° lF ▹ G′ ° lG ° lΠ ^ [ r , ι lΠ ]
[F≡F′] : ∀ {ρ Δ}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊩¹ U.wk ρ F ≡ U.wk ρ F′ ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ
[G≡G′] : ∀ {ρ Δ a}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩¹ a ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
→ Δ ⊩¹ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G′ [ a ] ^ [ r , ι lG ] / [G] [ρ] ⊢Δ [a]
-- relevant Term of Π-type
_⊩¹Π_∷_^_/_ : (Γ : Con Term) (t A : Term) (lΠ : Level) ([A] : Γ ⊩¹Π A ^[ ! , lΠ ]) → Set
Γ ⊩¹Π t ∷ A ^ lΠ / Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
∃ λ f → Γ ⊢ t :⇒*: f ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ ι lΠ
× Function f
× Γ ⊢ f ≅ f ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ ! , ι lΠ ]
× (∀ {ρ Δ a b}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
([a] : Δ ⊩¹ a ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
([b] : Δ ⊩¹ b ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
([a≡b] : Δ ⊩¹ a ≡ b ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
→ Δ ⊩¹ U.wk ρ f ∘ a ^ lΠ ≡ U.wk ρ f ∘ b ^ lΠ ∷ U.wk (lift ρ) G [ a ] ^ [ ! , ι lG ] / [G] [ρ] ⊢Δ [a])
× (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩¹ a ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
→ Δ ⊩¹ U.wk ρ f ∘ a ^ lΠ ∷ U.wk (lift ρ) G [ a ] ^ [ ! , ι lG ] / [G] [ρ] ⊢Δ [a])
-- Issue: Agda complains about record use not being strictly positive.
-- Therefore we have to use ×
-- Irrelevant term of Π-type
_⊩¹Πirr_∷_^_/_ : (Γ : Con Term) (t A : Term) (l′ : Level) ([A] : Γ ⊩¹Π A ^[ % , l′ ]) → Set
Γ ⊩¹Πirr t ∷ A ^ l′ / Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
Γ ⊢ t ∷ Π F ^ rF ° lF ▹ G ° lG ° l′ ^ [ % , ι l′ ]
-- Term equality of Π-type
_⊩¹Π_≡_∷_^_/_ : (Γ : Con Term) (t u A : Term) (l′ : Level) ([A] : Γ ⊩¹Π A ^[ ! , l′ ]) → Set
Γ ⊩¹Π t ≡ u ∷ A ^ l′ / Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
let [A] = Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext
in ∃₂ λ f g →
( Γ ⊢ t :⇒*: f ∷ Π F ^ rF ° lF ▹ G ° lG ° l′ ^ ι l′ )
× ( Γ ⊢ u :⇒*: g ∷ Π F ^ rF ° lF ▹ G ° lG ° l′ ^ ι l′ )
× Function f
× Function g
× Γ ⊢ f ≅ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l′ ^ [ ! , ι l′ ]
× Γ ⊩¹Π t ∷ A ^ l′ / [A]
× Γ ⊩¹Π u ∷ A ^ l′ / [A]
× (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩¹ a ∷ U.wk ρ F ^ [ rF , ι lF ] / [F] [ρ] ⊢Δ)
→ Δ ⊩¹ U.wk ρ f ∘ a ^ l′ ≡ U.wk ρ g ∘ a ^ l′ ∷ U.wk (lift ρ) G [ a ] ^ [ ! , ι lG ] / [G] [ρ] ⊢Δ [a])
-- Issue: Same as above.
-- Irrelevant term equality of Π-type
_⊩¹Πirr_≡_∷_^_/_ : (Γ : Con Term) (t u A : Term) (l′ : Level) ([A] : Γ ⊩¹Π A ^[ % , l′ ] ) → Set
Γ ⊩¹Πirr t ≡ u ∷ A ^ l′ / Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
(Γ ⊢ t ∷ Π F ^ rF ° lF ▹ G ° lG ° l′ ^ [ % , ι l′ ])
×
(Γ ⊢ u ∷ Π F ^ rF ° lF ▹ G ° lG ° l′ ^ [ % , ι l′ ])
-- Existential types
record _⊩¹∃_^_ (Γ : Con Term) (A : Term) (l′ : Level) : Set where
inductive
eta-equality
constructor ∃ᵣ
field
F : Term
G : Term
D : Γ ⊢ A :⇒*: ∃ F ▹ G ^ [ % , ι l′ ]
⊢F : Γ ⊢ F ^ [ % , ι l′ ]
⊢G : Γ ∙ F ^ [ % , ι l′ ] ⊢ G ^ [ % , ι l′ ]
A≡A : Γ ⊢ (∃ F ▹ G) ≅ (∃ F ▹ G) ^ [ % , ι l′ ]
[F] : ∀ {ρ Δ} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ) → Δ ⊩¹ U.wk ρ F ^ [ % , ι l′ ]
[G] : ∀ {ρ Δ a}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊩¹ a ∷ U.wk ρ F ^ [ % , ι l′ ] / [F] [ρ] ⊢Δ
→ Δ ⊩¹ U.wk (lift ρ) G [ a ] ^ [ % , ι l′ ]
G-ext : ∀ {ρ Δ a b}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩¹ a ∷ U.wk ρ F ^ [ % , ι l′ ] / [F] [ρ] ⊢Δ)
→ ([b] : Δ ⊩¹ b ∷ U.wk ρ F ^ [ % , ι l′ ] / [F] [ρ] ⊢Δ)
→ Δ ⊩¹ a ≡ b ∷ U.wk ρ F ^ [ % , ι l′ ] / [F] [ρ] ⊢Δ
→ Δ ⊩¹ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G [ b ] ^ [ % , ι l′ ] / [G] [ρ] ⊢Δ [a]
-- ∃-type equality
record _⊩¹∃_≡_^_/_ (Γ : Con Term) (A B : Term) (l′ : Level) ([A] : Γ ⊩¹∃ A ^ l′) : Set where
inductive
eta-equality
constructor ∃₌
open _⊩¹∃_^_ [A]
field
F′ : Term
G′ : Term
D′ : Γ ⊢ B ⇒* ∃ F′ ▹ G′ ^ [ % , ι l′ ]
A≡B : Γ ⊢ ∃ F ▹ G ≅ ∃ F′ ▹ G′ ^ [ % , ι l′ ]
[F≡F′] : ∀ {ρ Δ}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊩¹ U.wk ρ F ≡ U.wk ρ F′ ^ [ % , ι l′ ] / [F] [ρ] ⊢Δ
[G≡G′] : ∀ {ρ Δ a}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩¹ a ∷ U.wk ρ F ^ [ % , ι l′ ] / [F] [ρ] ⊢Δ)
→ Δ ⊩¹ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G′ [ a ] ^ [ % , ι l′ ] / [G] [ρ] ⊢Δ [a]
-- Terms of ∃-types (always irrelevant)
_⊩¹∃_∷_^_/_ : (Γ : Con Term) (t A : Term) (l′ : Level) ([A] : Γ ⊩¹∃ A ^ l′) → Set
Γ ⊩¹∃ t ∷ A ^ l′ / ∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
Γ ⊢ t ∷ ∃ F ▹ G ^ [ % , ι l′ ]
-- Term equality for ∃-types
_⊩¹∃_≡_∷_^_/_ : (Γ : Con Term) (t u A : Term) (l′ : Level) ([A] : Γ ⊩¹∃ A ^ l′) → Set
Γ ⊩¹∃ t ≡ u ∷ A ^ l′ / ∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
(Γ ⊢ t ∷ ∃ F ▹ G ^ [ % , ι l′ ])
×
(Γ ⊢ u ∷ ∃ F ▹ G ^ [ % , ι l′ ])
-- Logical relation definition
data _⊩¹_^_ (Γ : Con Term) : Term → TypeInfo → Set where
Uᵣ : ∀ {A ll} → (UA : Γ ⊩¹U A ^ ll) → Γ ⊩¹ A ^ [ ! , ll ]
ℕᵣ : ∀ {A} → Γ ⊩ℕ A → Γ ⊩¹ A ^ [ ! , ι ⁰ ]
Emptyᵣ : ∀ {A l} → Γ ⊩Empty A ^ l → Γ ⊩¹ A ^ [ % , ι l ]
ne : ∀ {A r l} → Γ ⊩ne A ^[ r , l ] → Γ ⊩¹ A ^ [ r , ι l ]
Πᵣ : ∀ {A r l} → Γ ⊩¹Π A ^[ r , l ] → Γ ⊩¹ A ^ [ r , ι l ]
∃ᵣ : ∀ {A l} → Γ ⊩¹∃ A ^ l → Γ ⊩¹ A ^ [ % , ι l ]
emb : ∀ {A r l′} (l< : l′ <∞ l) (let open LogRelKit (rec l<))
([A] : Γ ⊩ A ^ r) → Γ ⊩¹ A ^ r
_⊩¹_≡_^_/_ : (Γ : Con Term) (A B : Term) (r : TypeInfo) → Γ ⊩¹ A ^ r → Set
Γ ⊩¹ A ≡ B ^ [ .! , l ] / Uᵣ UA = Γ ⊩¹U A ≡ B ^ l / UA
Γ ⊩¹ A ≡ B ^ [ .! , .ι ⁰ ] / ℕᵣ D = Γ ⊩ℕ A ≡ B
Γ ⊩¹ A ≡ B ^ [ .% , .ι l ] / Emptyᵣ D = Γ ⊩Empty A ≡ B ^ l
Γ ⊩¹ A ≡ B ^ [ r , ι l ] / ne neA = Γ ⊩ne A ≡ B ^[ r , l ]/ neA
Γ ⊩¹ A ≡ B ^ [ r , ι l ] / Πᵣ ΠA = Γ ⊩¹Π A ≡ B ^[ r , l ]/ ΠA
Γ ⊩¹ A ≡ B ^ [ .% , ι l ] / ∃ᵣ ∃A = Γ ⊩¹∃ A ≡ B ^ l / ∃A
Γ ⊩¹ A ≡ B ^ r / emb l< [A] = Γ ⊩ A ≡ B ^ r / [A]
where open LogRelKit (rec l<)
_⊩¹_∷_^_/_ : (Γ : Con Term) (t A : Term) (r : TypeInfo) → Γ ⊩¹ A ^ r → Set
Γ ⊩¹ t ∷ A ^ [ .! , ll ] / Uᵣ UA = Γ ⊩¹U t ∷ A ^ ll / UA
Γ ⊩¹ t ∷ A ^ .([ ! , ι ⁰ ]) / ℕᵣ x = Γ ⊩ℕ t ∷ℕ
Γ ⊩¹ t ∷ A ^ [ .% , ι ll ] / Emptyᵣ x = Γ ⊩Empty t ∷Empty^ ll
Γ ⊩¹ t ∷ A ^ .([ ! , ι l ]) / ne {r = !} {l} neA = Γ ⊩ne t ∷ A ^ l / neA
Γ ⊩¹ t ∷ A ^ .([ % , ι l ]) / ne {r = %} {l} neA = Γ ⊩neIrr t ∷ A ^ l / neA
Γ ⊩¹ t ∷ A ^ [ ! , ι l ] / Πᵣ ΠA = Γ ⊩¹Π t ∷ A ^ l / ΠA
Γ ⊩¹ t ∷ A ^ [ % , ι l ] / Πᵣ ΠA = Γ ⊩¹Πirr t ∷ A ^ l / ΠA
Γ ⊩¹ t ∷ A ^ .([ % , ι l ]) / ∃ᵣ {l = l} ∃A = Γ ⊩¹∃ t ∷ A ^ l / ∃A
Γ ⊩¹ t ∷ A ^ r / emb l< [A] = Γ ⊩ t ∷ A ^ r / [A]
where open LogRelKit (rec l<)
_⊩¹_≡_∷_^_/_ : (Γ : Con Term) (t u A : Term) (r : TypeInfo) → Γ ⊩¹ A ^ r → Set
Γ ⊩¹ t ≡ u ∷ A ^ [ .! , ll ] / Uᵣ UA = Γ ⊩¹U t ≡ u ∷ A ^ ll / UA
Γ ⊩¹ t ≡ u ∷ A ^ .([ ! , ι ⁰ ]) / ℕᵣ D = Γ ⊩ℕ t ≡ u ∷ℕ
Γ ⊩¹ t ≡ u ∷ A ^ [ .% , ι ll ] / Emptyᵣ D = Γ ⊩Empty t ≡ u ∷Empty^ ll
Γ ⊩¹ t ≡ u ∷ A ^ .([ ! , ι l ]) / ne {r = !} {l} neA = Γ ⊩ne t ≡ u ∷ A ^ l / neA
Γ ⊩¹ t ≡ u ∷ A ^ .([ % , ι l ]) / ne {r = %} {l} neA = Γ ⊩neIrr t ≡ u ∷ A ^ l / neA
Γ ⊩¹ t ≡ u ∷ A ^ [ ! , ι l ] / Πᵣ ΠA = Γ ⊩¹Π t ≡ u ∷ A ^ l / ΠA
Γ ⊩¹ t ≡ u ∷ A ^ [ % , ι l ] / Πᵣ ΠA = Γ ⊩¹Πirr t ≡ u ∷ A ^ l / ΠA
Γ ⊩¹ t ≡ u ∷ A ^ .([ % , ι l ]) / ∃ᵣ {l = l} ∃A = Γ ⊩¹∃ t ≡ u ∷ A ^ l / ∃A
Γ ⊩¹ t ≡ u ∷ A ^ r / emb l< [A] = Γ ⊩ t ≡ u ∷ A ^ r / [A]
where open LogRelKit (rec l<)
kit : LogRelKit
kit = Kit _⊩¹U_^_ _⊩¹Π_^[_,_] _⊩¹∃_^_
_⊩¹_^_ _⊩¹_≡_^_/_ _⊩¹_∷_^_/_ _⊩¹_≡_∷_^_/_
open LogRel public using (Uᵣ; ℕᵣ; Emptyᵣ; ne; Πᵣ ; ∃ᵣ ; emb; Uₜ; Uₜ₌; Π₌; ∃₌)
-- Patterns for the non-records of Π
pattern Πₜ a b c d e f = a , b , c , d , e , f
pattern Πₜ₌ a b c d e f g h i j = a , b , c , d , e , f , g , h , i , j
pattern Uᵣ′ A ll r l a e d = Uᵣ {A = A} {ll = ll} (Uᵣ r l a e d)
pattern ne′ b c d e = ne (ne b c d e)
pattern Πᵣ′ a a' a'' lf lg b c d e f g h i j = Πᵣ (Πᵣ a a' a'' lf lg b c d e f g h i j)
pattern ∃ᵣ′ a b c d e f g h i = ∃ᵣ (∃ᵣ a b c d e f g h i)
-- we need to split the LogRelKit into the level part and the general part to convince Agda termination checker
logRelRec : ∀ l {l′} → l′ <∞ l → LogRelKit
logRelRec (ι ⁰) = λ ()
logRelRec (ι ¹) X = LogRel.kit (ι ⁰) λ ()
logRelRec ∞ X = LogRel.kit (ι ¹) (λ X → LogRel.kit (ι ⁰) λ ())
kit : ∀ (i : TypeLevel) → LogRelKit
kit l = LogRel.kit l (logRelRec l)
_⊩′⟨_⟩U_^_ : (Γ : Con Term) (l : TypeLevel) → Term → TypeLevel → Set
Γ ⊩′⟨ l ⟩U A ^ ll = Γ ⊩U A ^ ll where open LogRelKit (kit l)
_⊩′⟨_⟩Π_^[_,_] : (Γ : Con Term) (l : TypeLevel) → Term → Relevance → Level → Set
Γ ⊩′⟨ l ⟩Π A ^[ r , lΠ ] = Γ ⊩Π A ^[ r , lΠ ] where open LogRelKit (kit l)
_⊩′⟨_⟩∃_^_ : (Γ : Con Term) (l : TypeLevel) → Term → Level → Set
Γ ⊩′⟨ l ⟩∃ A ^ l' = Γ ⊩∃ A ^ l' where open LogRelKit (kit l)
_⊩⟨_⟩_^_ : (Γ : Con Term) (l : TypeLevel) → Term → TypeInfo → Set
Γ ⊩⟨ l ⟩ A ^ r = Γ ⊩ A ^ r where open LogRelKit (kit l)
_⊩⟨_⟩_≡_^_/_ : (Γ : Con Term) (l : TypeLevel) (A B : Term) (r : TypeInfo) → Γ ⊩⟨ l ⟩ A ^ r → Set
Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A] = Γ ⊩ A ≡ B ^ r / [A] where open LogRelKit (kit l)
_⊩⟨_⟩_∷_^_/_ : (Γ : Con Term) (l : TypeLevel) (t A : Term) (r : TypeInfo) → Γ ⊩⟨ l ⟩ A ^ r → Set
Γ ⊩⟨ l ⟩ t ∷ A ^ r / [A] = Γ ⊩ t ∷ A ^ r / [A] where open LogRelKit (kit l)
_⊩⟨_⟩_≡_∷_^_/_ : (Γ : Con Term) (l : TypeLevel) (t u A : Term) (r : TypeInfo) → Γ ⊩⟨ l ⟩ A ^ r → Set
Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ r / [A] = Γ ⊩ t ≡ u ∷ A ^ r / [A] where open LogRelKit (kit l)
-- Well-typed irrelevant terms are always reducible
logRelIrr : ∀ {l t Γ l' A} ([A] : Γ ⊩⟨ l ⟩ A ^ [ % , l' ]) (⊢t : Γ ⊢ t ∷ A ^ [ % , l' ]) → Γ ⊩⟨ l ⟩ t ∷ A ^ [ % , l' ] / [A]
logRelIrr (Emptyᵣ [[ ⊢A , ⊢B , D ]]) ⊢t = Emptyₜ (ne (conv ⊢t (reduction D (id ⊢B) Emptyₙ Emptyₙ (refl ⊢B))))
logRelIrr (ne x) ⊢t = neₜ ⊢t
logRelIrr (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ⊢t = conv ⊢t (reduction (red D) (id (_⊢_:⇒*:_^_.⊢B D)) Πₙ Πₙ (refl (_⊢_:⇒*:_^_.⊢B D)))
logRelIrr (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ⊢t = conv ⊢t (reduction (red D) (id (_⊢_:⇒*:_^_.⊢B D)) ∃ₙ ∃ₙ (refl (_⊢_:⇒*:_^_.⊢B D)))
logRelIrr {ι ¹} (emb X [A]) ⊢t = logRelIrr [A] ⊢t
logRelIrr {∞} (emb X [A]) ⊢t = logRelIrr [A] ⊢t
-- Well-typed irrelevant terms are reducibly equal as soon as they have the same type
logRelIrrEq : ∀ {l t u Γ l' A} ([A] : Γ ⊩⟨ l ⟩ A ^ [ % , l' ]) (⊢t : Γ ⊢ t ∷ A ^ [ % , l' ]) (⊢u : Γ ⊢ u ∷ A ^ [ % , l' ]) → Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ [ % , l' ] / [A]
logRelIrrEq (Emptyᵣ [[ ⊢A , ⊢B , D ]]) ⊢t ⊢u = Emptyₜ₌ (ne ((conv ⊢t (reduction D (id ⊢B) Emptyₙ Emptyₙ (refl ⊢B))))
(conv ⊢u (reduction D (id ⊢B) Emptyₙ Emptyₙ (refl ⊢B))))
logRelIrrEq (ne x) ⊢t ⊢u = neₜ₌ ⊢t ⊢u
logRelIrrEq (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ⊢t ⊢u = (conv ⊢t (reduction (red D) (id (_⊢_:⇒*:_^_.⊢B D)) Πₙ Πₙ (refl (_⊢_:⇒*:_^_.⊢B D))) ) , (conv ⊢u (reduction (red D) (id (_⊢_:⇒*:_^_.⊢B D)) Πₙ Πₙ (refl (_⊢_:⇒*:_^_.⊢B D))) )
logRelIrrEq (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ⊢t ⊢u = (conv ⊢t (reduction (red D) (id (_⊢_:⇒*:_^_.⊢B D)) ∃ₙ ∃ₙ (refl (_⊢_:⇒*:_^_.⊢B D))) ) , (conv ⊢u (reduction (red D) (id (_⊢_:⇒*:_^_.⊢B D)) ∃ₙ ∃ₙ (refl (_⊢_:⇒*:_^_.⊢B D))) )
logRelIrrEq {ι ¹} (emb X [A]) ⊢t = logRelIrrEq [A] ⊢t
logRelIrrEq {∞} (emb X [A]) ⊢t = logRelIrrEq [A] ⊢t
| 42.278455
| 240
| 0.423537
|
10160963e79f37b8040ecbdda7f4a159ef43ce3c
| 8,635
|
agda
|
Agda
|
src/Generics/Prelude.agda
|
flupe/generics
|
db764f858d908aa39ea4901669a6bbce1525f757
|
[
"MIT"
] | 11
|
2021-04-08T15:10:20.000Z
|
2022-02-05T09:35:17.000Z
|
src/Generics/Prelude.agda
|
flupe/generics
|
db764f858d908aa39ea4901669a6bbce1525f757
|
[
"MIT"
] | 4
|
2021-09-13T07:33:50.000Z
|
2022-01-14T10:48:30.000Z
|
src/Generics/Prelude.agda
|
flupe/generics
|
db764f858d908aa39ea4901669a6bbce1525f757
|
[
"MIT"
] | 3
|
2021-04-08T08:32:42.000Z
|
2022-01-14T10:35:16.000Z
|
{-# OPTIONS --safe --without-K #-}
module Generics.Prelude where
open import Function.Base public
open import Data.Product public hiding (map; uncurry; uncurry′; curry′)
open import Level public using (Setω; Level; _⊔_; Lift; lift)
renaming (zero to lzero; suc to lsuc)
open import Relation.Binary.PropositionalEquality public
hiding ([_]; Extensionality; ∀-extensionality)
open import Data.Nat.Base public using (ℕ; zero; suc; _+_)
renaming (_∸_ to _-_)
open import Data.Unit public using (⊤; tt)
open import Data.Empty public using (⊥)
open import Data.List public using (List; []; _∷_)
open import Data.Vec.Base public using (Vec; []; _∷_; map; lookup)
open import Data.Fin.Base as Fin public using (Fin; zero; suc)
open import Axiom.Extensionality.Propositional public
open import Data.String using (String)
open import Reflection public
hiding (var; return; _>>=_; _>>_; assocˡ; assocʳ; visibility; relevance; module Arg)
import Reflection.Argument
module Arg = Reflection.Argument
open import Reflection.Argument.Information public using (ArgInfo; arg-info; visibility)
renaming (modality to getModality)
open import Reflection.Argument.Modality public using (Modality; modality)
open import Reflection.Argument.Relevance public using (Relevance; relevant; irrelevant)
open import Reflection.Argument.Visibility public using (Visibility; visible; hidden; instance′)
private variable
m n : ℕ
k : Fin n
l l' : Level
A B : Set l
record Irr (A : Set l) : Set l where
constructor irrv
field
.unirr : A
open Irr public
<_>_ : Relevance → Set l → Set l
< relevant > A = A
< irrelevant > A = Irr A
relevance : ArgInfo → Relevance
relevance = Reflection.Argument.Modality.relevance ∘ getModality
-- withAI : ArgInfo → Term → Term
-- withAI i t with relevance i
-- ... | relevant = t
-- ... | irrelevant = con (quote irrv) (vArg t ∷ [])
-- macro
-- Π<> : ((n , i) : String × ArgInfo) → Term → Term → Term → TC ⊤
-- Π<> (n , ai) S′ (Term.var k []) =
-- unify (pi (arg ai S′) (abs n (Term.var (suc k) (vArg (withAI ai (Term.var 0 [])) ∷ []))))
-- Π<> (n , ai) S′ _ hole = typeError (strErr "" ∷ [])
-- TODO: do this with reflection, using names
-- TODO: deal with quantities
Π<_> : ((a , i) : String × ArgInfo) (A : Set l) → (< relevance i > A → Set l') → Set (l ⊔ l')
Π< _ , arg-info visible (modality relevant q) > A B = (x : A) → B x
Π< _ , arg-info visible (modality irrelevant q) > A B = .(x : A) → B (irrv x)
Π< _ , arg-info hidden (modality relevant q) > A B = {x : A} → B x
Π< _ , arg-info hidden (modality irrelevant q) > A B = .{x : A} → B (irrv x)
Π< _ , arg-info instance′ (modality relevant q) > A B = {{x : A}} → B x
Π< _ , arg-info instance′ (modality irrelevant q) > A B = .{{x : A}} → B (irrv x)
_→<_>_ : Set l → String × ArgInfo → Set l' → Set (l ⊔ l')
A →< i > B = Π< i > A λ _ → B
fun<_> : (ai@(a , i) : String × ArgInfo) {A : Set l} {B : < relevance i > A → Set l'}
→ (f : (x : < relevance i > A) → B x) → Π< ai > A B
fun< _ , arg-info visible (modality relevant q) > f x = f x
fun< _ , arg-info visible (modality irrelevant q) > f x = f (irrv x)
fun< _ , arg-info hidden (modality relevant q) > f {x} = f x
fun< _ , arg-info hidden (modality irrelevant q) > f {x} = f (irrv x)
fun< _ , arg-info instance′ (modality relevant q) > f {{x}} = f x
fun< _ , arg-info instance′ (modality irrelevant q) > f {{x}} = f (irrv x)
app<_> : (ai@(a , i) : String × ArgInfo) {A : Set l} {B : < relevance i > A → Set l'}
→ (f : Π< ai > A B) → (x : < relevance i > A) → B x
app< _ , arg-info visible (modality relevant q) > f x = f x
app< _ , arg-info visible (modality irrelevant q) > f (irrv x) = f x
app< _ , arg-info hidden (modality relevant q) > f x = f {x}
app< _ , arg-info hidden (modality irrelevant q) > f (irrv x) = f {x}
app< _ , arg-info instance′ (modality relevant q) > f x = f {{x}}
app< _ , arg-info instance′ (modality irrelevant q) > f (irrv x) = f {{x}}
-- Instead of the definitions from Function.Nary.NonDependent in the
-- standard library, we use a *functional* representation of vectors
-- of levels and types. This makes it much easier to work with
-- operations like lookup and tabulate, at the cost of losing certain
-- eta laws for nil and cons (see the comment for `uncurryₙ` below).
Levels : ℕ → Set
Levels n = Fin n → Level
private variable ls ls' : Levels n
[]l : Levels 0
[]l ()
_∷l_ : Level → Levels n → Levels (suc n)
(l ∷l ls) zero = l
(l ∷l ls) (suc k) = ls k
headl : Levels (suc n) → Level
headl ls = ls zero
taill : Levels (suc n) → Levels n
taill ls = ls ∘ suc
_++l_ : Levels m → Levels n → Levels (m + n)
_++l_ {zero} ls ls' = ls'
_++l_ {suc m} ls ls' zero = headl ls
_++l_ {suc m} ls ls' (suc x) = (taill ls ++l ls') x
⨆ : Levels n → Level
⨆ {zero} ls = lzero
⨆ {suc n} ls = ls zero ⊔ ⨆ (ls ∘ suc)
Sets : (ls : Levels n) → Setω
Sets {n} ls = (k : Fin n) → Set (ls k)
private variable As Bs : Sets ls
[]S : {ls : Levels 0} → Sets ls
[]S ()
_∷S_ : Set (headl ls) → Sets (taill ls) → Sets ls
(A ∷S As) zero = A
(A ∷S As) (suc k) = As k
headS : Sets ls → Set (headl ls)
headS As = As zero
tailS : Sets ls → Sets (taill ls)
tailS As k = As (suc k)
_++S_ : Sets ls → Sets ls' → Sets (ls ++l ls')
_++S_ {zero} As Bs = Bs
_++S_ {suc m} As Bs zero = headS As
_++S_ {suc m} As Bs (suc k) = (tailS As ++S Bs) k
Els : (As : Sets ls) → Setω
Els {n} As = (k : Fin n) → As k
private variable xs : Els As
[]El : {As : Sets {zero} ls} → Els As
[]El ()
_∷El_ : headS As → Els (tailS As) → Els As
(x ∷El xs) zero = x
(x ∷El xs) (suc k) = xs k
headEl : Els As → headS As
headEl xs = xs zero
tailEl : Els As → Els (tailS As)
tailEl xs k = xs (suc k)
_++El_ : Els As → Els Bs → Els (As ++S Bs)
_++El_ {zero} xs ys = ys
_++El_ {suc m} xs ys zero = headEl xs
_++El_ {suc m} xs ys (suc k) = (tailEl xs ++El ys) k
++El-proj₁ : Els (As ++S Bs) → Els As
++El-proj₁ xs zero = xs zero
++El-proj₁ xs (suc k) = ++El-proj₁ (tailEl xs) k
++El-proj₂ : Els (As ++S Bs) → Els Bs
++El-proj₂ {zero} xs k = xs k
++El-proj₂ {suc m} xs k = ++El-proj₂ (tailEl xs) k
Pis : (As : Sets ls) (B : Els As → Set l) → Set (⨆ ls ⊔ l)
Pis {zero} As B = B []El
Pis {suc n} As B = (x : As zero) → Pis (tailS As) (λ xs → B (x ∷El xs))
Arrows : (As : Sets ls) (B : Set l) → Set (⨆ ls ⊔ l)
Arrows As B = Pis As (λ _ → B)
curryₙ : {B : Els As → Set l} → ((xs : Els As) → B xs) → Pis As B
curryₙ {zero} f = f []El
curryₙ {suc n} f = λ x → curryₙ (λ xs → f (x ∷El xs))
-- It is not possible to define the dependent version of uncurryₙ, as
-- it requires the laws that `xs = []El` for all `xs : Els {zero} As`
-- and `xs = headEl xs ∷El tailEl xs` for all `xs : Els {suc n} As`,
-- which do not hold definitionally and require funExt to prove.
uncurryₙ : Arrows As B → Els As → B
uncurryₙ {zero} f _ = f
uncurryₙ {suc n} f xs = uncurryₙ (f (headEl xs)) (tailEl xs)
------------------------------------
-- Some utilities to work with Setω
-- TODO: move this somewhere else
-- TODO: consistent naming
record ⊤ω : Setω where
instance constructor tt
data ⊥ω : Setω where
⊥⇒⊥ω : ⊥ → ⊥ω
⊥⇒⊥ω ()
⊥ω-elimω : {A : Setω} → ⊥ω → A
⊥ω-elimω ()
ttω : ⊤ω
ttω = tt
record Liftω (A : Set l) : Setω where
constructor liftω
field lower : A
instance
liftω-inst : {A : Set l} → ⦃ A ⦄ → Liftω A
liftω-inst ⦃ x ⦄ = liftω x
record _×ω_ (A B : Setω) : Setω where
constructor _,_
field fst : A
snd : B
_ω,ω_ : {A B : Setω} → A → B → A ×ω B
_ω,ω_ = _,_
data _≡ω_ {A : Setω} (x : A) : A → Setω where
refl : x ≡ω x
congω : ∀ {A b} {B : Set b} (f : ∀ x → B)
→ ∀ {x y : A} → x ≡ω y → f x ≡ f y
congω f refl = refl
cong≡ω : {A : Set l} {B : Setω} (f : ∀ x → B)
→ ∀ {x y : A} → x ≡ y → f x ≡ω f y
cong≡ω f refl = refl
cong≡ωω : {A B : Setω} (f : ∀ x → B)
→ ∀ {x y : A} → x ≡ω y → f x ≡ω f y
cong≡ωω f refl = refl
reflω : {A : Setω} {x : A} → x ≡ω x
reflω = refl
transω : {A : Setω} {x y z : A}
→ x ≡ω y → y ≡ω z → x ≡ω z
transω refl refl = refl
symω : {A : Setω} {x y : A} → x ≡ω y → y ≡ω x
symω refl = refl
instance
×ω-inst : ∀ {A B} → ⦃ A ⦄ → ⦃ B ⦄ → A ×ω B
×ω-inst ⦃ x ⦄ ⦃ y ⦄ = x , y
record Σω {a} (A : Set a) (B : A → Setω) : Setω where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
data Decω (A : Setω) : Setω where
yesω : A → Decω A
noω : (A → ⊥) → Decω A
| 31.514599
| 97
| 0.570006
|
20c07d92e9fb29790bcd3139d1e7f194ca26ca27
| 715
|
agda
|
Agda
|
test/Succeed/Issue2484-6.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Succeed/Issue2484-6.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Issue2484-6.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module _ (_ : Set) where
open import Agda.Builtin.Size
postulate
I : Set
record ∃ (B : I → Set) : Set where
constructor _,_
field
proj₁ : I
proj₂ : B proj₁
module M (_ : Set₁) where
mutual
data P (i : Size) (x y : I) : Set where
⟨_⟩ : ∃ (Q i x) → P i x y
record Q (i : Size) (x y : I) : Set where
coinductive
field
force : {j : Size< i} → P j x y
open M Set
postulate
map : (B : I → Set) → (∀ x → B x → B x) → ∃ B → ∃ B
lemma : ∀ x y i → Q i x y → Q i x y
p : ∀ x i → P i x x
q′ : ∀ x i → ∃ λ y → Q i x y
q : ∀ x i → Q i x x
p x i = ⟨ map _ (λ y → lemma x y _) (q′ x _) ⟩
q′ x i = x , q x i
Q.force (q x i) {j} = p _ _
| 18.333333
| 60
| 0.454545
|
d04209cc76473c6a9b33ba0cd1d2aebab9e4989f
| 2,564
|
agda
|
Agda
|
Relation/Binary/Construct/UpperBound.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Relation/Binary/Construct/UpperBound.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Relation/Binary/Construct/UpperBound.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe --postfix-projections #-}
open import Prelude
open import Relation.Binary
module Relation.Binary.Construct.UpperBound {e} {E : Type e} {r₁ r₂} (totalOrder : TotalOrder E r₁ r₂) where
open TotalOrder totalOrder renaming (refl to <-refl)
import Data.Unit.UniversePolymorphic as Poly
import Data.Empty.UniversePolymorphic as Poly
open import Data.Maybe.Base using () renaming (nothing to ⌈⊤⌉; just to ⌈_⌉) public
⌈∙⌉ : Type e
⌈∙⌉ = Maybe E
_≤⌈_⌉ : ⌈∙⌉ → E → Type _
⌈⊤⌉ ≤⌈ y ⌉ = Poly.⊥
⌈ x ⌉ ≤⌈ y ⌉ = x ≤ y
_⌈≤⌉_ : ⌈∙⌉ → ⌈∙⌉ → Type _
x ⌈≤⌉ ⌈⊤⌉ = Poly.⊤
x ⌈≤⌉ ⌈ y ⌉ = x ≤⌈ y ⌉
⌈_⌉<_ : E → ⌈∙⌉ → Type _
⌈ x ⌉< ⌈⊤⌉ = Poly.⊤
⌈ x ⌉< ⌈ y ⌉ = x < y
_⌈<⌉_ : ⌈∙⌉ → ⌈∙⌉ → Type _
⌈⊤⌉ ⌈<⌉ _ = Poly.⊥
⌈ x ⌉ ⌈<⌉ y = ⌈ x ⌉< y
ub-pord : PartialOrder ⌈∙⌉ _
ub-pord .PartialOrder.preorder .Preorder._≤_ = _⌈≤⌉_
ub-pord .PartialOrder.preorder .Preorder.refl {⌈⊤⌉} = Poly.tt
ub-pord .PartialOrder.preorder .Preorder.refl {⌈ x ⌉} = <-refl
ub-pord .PartialOrder.preorder .Preorder.trans {x} {y} {⌈⊤⌉} x≤y y≤z = Poly.tt
ub-pord .PartialOrder.preorder .Preorder.trans {⌈ x ⌉} {⌈ y ⌉} {⌈ z ⌉} x≤y y≤z = ≤-trans x≤y y≤z
ub-pord .PartialOrder.antisym {⌈⊤⌉} {⌈⊤⌉} p q = refl
ub-pord .PartialOrder.antisym {⌈ x ⌉} {⌈ y ⌉} p q = cong ⌈_⌉ (antisym p q)
ub-sord : StrictPartialOrder ⌈∙⌉ _
StrictPreorder._<_ (StrictPartialOrder.strictPreorder ub-sord) = _⌈<⌉_
StrictPreorder.trans (StrictPartialOrder.strictPreorder ub-sord) {⌈ x ⌉} {⌈ y ⌉} {⌈⊤⌉} p q = Poly.tt
StrictPreorder.trans (StrictPartialOrder.strictPreorder ub-sord) {⌈ x ⌉} {⌈ y ⌉} {⌈ z ⌉} p q = <-trans p q
StrictPreorder.irrefl (StrictPartialOrder.strictPreorder ub-sord) {⌈ x ⌉} = irrefl {x = x}
StrictPartialOrder.conn ub-sord {⌈⊤⌉} {⌈⊤⌉} p q = refl
StrictPartialOrder.conn ub-sord {⌈⊤⌉} {⌈ x ⌉} p q = ⊥-elim (q Poly.tt)
StrictPartialOrder.conn ub-sord {⌈ x ⌉} {⌈⊤⌉} p q = ⊥-elim (p Poly.tt)
StrictPartialOrder.conn ub-sord {⌈ x ⌉} {⌈ y ⌉} p q = cong ⌈_⌉ (conn p q)
ub-lt : ∀ x y → Dec (x ⌈<⌉ y)
ub-lt ⌈⊤⌉ y = no λ ()
ub-lt ⌈ x ⌉ ⌈⊤⌉ = yes Poly.tt
ub-lt ⌈ x ⌉ ⌈ y ⌉ = x <? y
ub-ord : TotalOrder ⌈∙⌉ _ _
TotalOrder.strictPartialOrder ub-ord = ub-sord
TotalOrder.partialOrder ub-ord = ub-pord
TotalOrder._<?_ ub-ord = ub-lt
TotalOrder.≰⇒> ub-ord {x} {⌈⊤⌉} p = ⊥-elim (p Poly.tt)
TotalOrder.≰⇒> ub-ord {⌈⊤⌉} {⌈ y ⌉} p = Poly.tt
TotalOrder.≰⇒> ub-ord {⌈ x ⌉} {⌈ y ⌉} p = ≰⇒> p
TotalOrder.≮⇒≥ ub-ord {⌈⊤⌉} {y} p = Poly.tt
TotalOrder.≮⇒≥ ub-ord {⌈ x ⌉} {⌈⊤⌉} p = ⊥-elim (p Poly.tt)
TotalOrder.≮⇒≥ ub-ord {⌈ x ⌉} {⌈ y ⌉} p = ≮⇒≥ p
import Data.Maybe.Sugar
module UBSugar = Data.Maybe.Sugar
| 36.628571
| 108
| 0.592824
|
fbba3d868d5d916bc1c56415d41b484f8e9635f4
| 5,455
|
agda
|
Agda
|
BasicIS4/Semantics/BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIS4/Semantics/BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIS4/Semantics/BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.
-- Basic Kripke-style semantics with abstract worlds, for soundness only.
-- Ono-style conditions.
module BasicIS4.Semantics.BasicKripkeOno where
open import BasicIS4.Syntax.Common public
-- Intuitionistic modal Kripke models, with frame conditions given by Ono.
record Model : Set₁ where
infix 3 _⊩ᵅ_
field
World : Set
-- Intuitionistic accessibility; preorder.
_≤_ : World → World → Set
refl≤ : ∀ {w} → w ≤ w
trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″
-- Modal accessibility; preorder.
_R_ : World → World → Set
reflR : ∀ {w} → w R w
transR : ∀ {w w′ w″} → w R w′ → w′ R w″ → w R w″
-- Forcing for atomic propositions; monotonic.
_⊩ᵅ_ : World → Atom → Set
mono⊩ᵅ : ∀ {P w w′} → w ≤ w′ → w ⊩ᵅ P → w′ ⊩ᵅ P
-- Composition of accessibility.
_≤⨾R_ : World → World → Set
_≤⨾R_ = _≤_ ⨾ _R_
_R⨾≤_ : World → World → Set
_R⨾≤_ = _R_ ⨾ _≤_
-- Persistence condition.
--
-- w′ v′ → v′
-- ◌───R───● → ●
-- │ → ╱
-- ≤ ξ,ζ → R
-- │ → ╱
-- ● → ●
-- w → w
field
≤⨾R→R : ∀ {v′ w} → w ≤⨾R v′ → w R v′
-- Minor persistence condition.
--
-- w′ v′ → v′
-- ◌───R───● → ●
-- │ → │
-- ≤ ξ,ζ → ≤
-- │ → │
-- ● → ●───R───◌
-- w → w v
--
-- w″ → w″
-- ● → ●
-- │ → │
-- ξ′,ζ′ ≤ → │
-- │ → │
-- ●───R───◌ → ≤
-- │ v′ → │
-- ξ,ζ ≤ → │
-- │ → │
-- ●───R───◌ → ●───────R───────◌
-- w v → w v″
≤⨾R→R⨾≤ : ∀ {v′ w} → w ≤⨾R v′ → w R⨾≤ v′
≤⨾R→R⨾≤ {v′} ξ,ζ = v′ , (≤⨾R→R ξ,ζ , refl≤)
reflR⨾≤ : ∀ {w} → w R⨾≤ w
reflR⨾≤ {w} = w , (reflR , refl≤)
transR⨾≤ : ∀ {w′ w w″} → w R⨾≤ w′ → w′ R⨾≤ w″ → w R⨾≤ w″
transR⨾≤ {w′} (v , (ζ , ξ)) (v′ , (ζ′ , ξ′)) = let v″ , (ζ″ , ξ″) = ≤⨾R→R⨾≤ (w′ , (ξ , ζ′))
in v″ , (transR ζ ζ″ , trans≤ ξ″ ξ′)
≤→R : ∀ {v′ w} → w ≤ v′ → w R v′
≤→R {v′} ξ = ≤⨾R→R (v′ , (ξ , reflR))
open Model {{…}} public
-- Forcing in a particular world of a particular model.
module _ {{_ : Model}} where
infix 3 _⊩_
_⊩_ : World → Ty → Set
w ⊩ α P = w ⊩ᵅ P
w ⊩ A ▻ B = ∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B
w ⊩ □ A = ∀ {v′} → w R v′ → v′ ⊩ A
w ⊩ A ∧ B = w ⊩ A × w ⊩ B
w ⊩ ⊤ = 𝟙
infix 3 _⊩⋆_
_⊩⋆_ : World → Cx Ty → Set
w ⊩⋆ ∅ = 𝟙
w ⊩⋆ Ξ , A = w ⊩⋆ Ξ × w ⊩ A
-- Monotonicity with respect to intuitionistic accessibility.
module _ {{_ : Model}} where
mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A
mono⊩ {α P} ξ s = mono⊩ᵅ ξ s
mono⊩ {A ▻ B} ξ s = λ ξ′ a → s (trans≤ ξ ξ′) a
mono⊩ {□ A} ξ s = λ ζ → s (transR (≤→R ξ) ζ)
mono⊩ {A ∧ B} ξ s = mono⊩ {A} ξ (π₁ s) , mono⊩ {B} ξ (π₂ s)
mono⊩ {⊤} ξ s = ∙
mono⊩⋆ : ∀ {Γ w w′} → w ≤ w′ → w ⊩⋆ Γ → w′ ⊩⋆ Γ
mono⊩⋆ {∅} ξ ∙ = ∙
mono⊩⋆ {Γ , A} ξ (γ , a) = mono⊩⋆ {Γ} ξ γ , mono⊩ {A} ξ a
-- Additional useful equipment.
module _ {{_ : Model}} where
_⟪$⟫_ : ∀ {A B w} → w ⊩ A ▻ B → w ⊩ A → w ⊩ B
s ⟪$⟫ a = s refl≤ a
⟪K⟫ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A
⟪K⟫ {A} a ξ = K (mono⊩ {A} ξ a)
⟪S⟫ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ A ▻ B → w ⊩ A → w ⊩ C
⟪S⟫ {A} {B} {C} s₁ s₂ a = _⟪$⟫_ {B} {C} (_⟪$⟫_ {A} {B ▻ C} s₁ a) (_⟪$⟫_ {A} {B} s₂ a)
⟪S⟫′ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ {A} {B} {C} s₁ ξ s₂ ξ′ a = let s₁′ = mono⊩ {A ▻ B ▻ C} (trans≤ ξ ξ′) s₁
s₂′ = mono⊩ {A ▻ B} ξ′ s₂
in ⟪S⟫ {A} {B} {C} s₁′ s₂′ a
_⟪D⟫_ : ∀ {A B w} → w ⊩ □ (A ▻ B) → w ⊩ □ A → w ⊩ □ B
_⟪D⟫_ {A} {B} s₁ s₂ ζ = let s₁′ = s₁ ζ
s₂′ = s₂ ζ
in _⟪$⟫_ {A} {B} s₁′ s₂′
_⟪D⟫′_ : ∀ {A B w} → w ⊩ □ (A ▻ B) → w ⊩ □ A ▻ □ B
_⟪D⟫′_ {A} {B} s₁ ξ = _⟪D⟫_ {A} {B} (mono⊩ {□ (A ▻ B)} ξ s₁)
⟪↑⟫ : ∀ {A w} → w ⊩ □ A → w ⊩ □ □ A
⟪↑⟫ s ζ ζ′ = s (transR ζ ζ′)
⟪↓⟫ : ∀ {A w} → w ⊩ □ A → w ⊩ A
⟪↓⟫ s = s reflR
_⟪,⟫′_ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ∧ B
_⟪,⟫′_ {A} {B} a ξ = _,_ (mono⊩ {A} ξ a)
-- Forcing in a particular world of a particular model, for sequents.
module _ {{_ : Model}} where
infix 3 _⊩_⇒_
_⊩_⇒_ : World → Cx Ty → Ty → Set
w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A
infix 3 _⊩_⇒⋆_
_⊩_⇒⋆_ : World → Cx Ty → Cx Ty → Set
w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ
-- Entailment, or forcing in all worlds of all models, for sequents.
infix 3 _⊨_
_⊨_ : Cx Ty → Ty → Set₁
Γ ⊨ A = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx Ty → Cx Ty → Set₁
Γ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒⋆ Ξ
infix 3 _⁏_⊨_
_⁏_⊨_ : Cx Ty → Cx Ty → Ty → Set₁
Γ ⁏ Δ ⊨ A = ∀ {{_ : Model}} {w : World}
→ w ⊩⋆ Γ → (∀ {v′} → w R v′ → v′ ⊩⋆ Δ) → w ⊩ A
-- Additional useful equipment, for sequents.
module _ {{_ : Model}} where
lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
| 28.118557
| 93
| 0.352521
|
fb6e5ffba761c4f5bc5a8a9626e980608ec2386c
| 644
|
agda
|
Agda
|
agda-stdlib/src/Relation/Binary/PartialOrderReasoning.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Relation/Binary/PartialOrderReasoning.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Relation/Binary/PartialOrderReasoning.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use the
-- Relation.Binary.Reasoning.PartialOrder module directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.PartialOrderReasoning
{p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where
open import Relation.Binary.Reasoning.PartialOrder P public
{-# WARNING_ON_IMPORT
"Relation.Binary.PartialOrderReasoning was deprecated in v1.0.
Use Relation.Binary.Reasoning.PartialOrder instead."
#-}
| 30.666667
| 72
| 0.588509
|
230d8e74941392c4e4f4ab8d33c6d3b18a630fe9
| 4,107
|
agda
|
Agda
|
test/Succeed/Builtin.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 1
|
2021-07-07T10:49:57.000Z
|
2021-07-07T10:49:57.000Z
|
test/Succeed/Builtin.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Builtin.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
module Builtin where
data Bool : Set where
false : Bool
true : Bool
not : Bool -> Bool
not true = false
not false = true
_||_ : Bool -> Bool -> Bool
true || _ = true
false || x = x
_&&_ : Bool -> Bool -> Bool
true && x = x
false && _ = false
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
zero' : Nat
zero' = 0
one : Nat
one = 1
data Int : Set where
pos : Nat → Int
negsuc : Nat → Int
{-# BUILTIN INTEGER Int #-}
{-# BUILTIN INTEGERPOS pos #-}
{-# BUILTIN INTEGERNEGSUC negsuc #-}
{-# BUILTIN STRING String #-}
{-# BUILTIN FLOAT Float #-}
{-# BUILTIN CHAR Char #-}
infixr 10 _::_
data List (A : Set) : Set where
nil : List A
_::_ : A -> List A -> List A
{-# BUILTIN LIST List #-}
primitive
-- Integer functions
primShowInteger : Int -> String
-- Floating point functions
primNatToFloat : Nat -> Float
primFloatPlus : Float -> Float -> Float
primFloatMinus : Float -> Float -> Float
primFloatTimes : Float -> Float -> Float
primFloatNegate : Float -> Float
primFloatDiv : Float -> Float -> Float
primFloatEquality : Float -> Float -> Bool
primFloatNumericalEquality : Float -> Float -> Bool
primFloatNumericalLess : Float -> Float -> Bool
primFloatSqrt : Float -> Float
primRound : Float -> Int
primFloor : Float -> Int
primCeiling : Float -> Int
primExp : Float -> Float
primLog : Float -> Float
primSin : Float -> Float
primCos : Float -> Float
primTan : Float -> Float
primASin : Float -> Float
primACos : Float -> Float
primATan : Float -> Float
primATan2 : Float -> Float -> Float
primShowFloat : Float -> String
-- Character functions
primCharEquality : Char -> Char -> Bool
primIsLower : Char -> Bool
primIsDigit : Char -> Bool
primIsAlpha : Char -> Bool
primIsSpace : Char -> Bool
primIsAscii : Char -> Bool
primIsLatin1 : Char -> Bool
primIsPrint : Char -> Bool
primIsHexDigit : Char -> Bool
primToUpper : Char -> Char
primToLower : Char -> Char
primCharToNat : Char -> Nat
primNatToChar : Nat -> Char -- partial
primShowChar : Char -> String
-- String functions
primStringToList : String -> List Char
primStringFromList : List Char -> String
primStringAppend : String -> String -> String
primStringEquality : String -> String -> Bool
primShowString : String -> String
isLower : Char -> Bool
isLower = primIsLower
isAlpha : Char -> Bool
isAlpha = primIsAlpha
isUpper : Char -> Bool
isUpper c = isAlpha c && not (isLower c)
infixl 14 _/_
nat0 = primCharToNat '\0'
int0 = pos nat0
_/_ = primFloatDiv
pi : Float
pi = 3.141592653589793
sin : Float -> Float
sin = primSin
cos : Float -> Float
cos = primCos
tan : Float -> Float
tan = primTan
reverse : {A : Set} -> List A -> List A
reverse xs = rev xs nil
where
rev : {A : Set} -> List A -> List A -> List A
rev nil ys = ys
rev (x :: xs) ys = rev xs (x :: ys)
infixr 20 _∘_
_∘_ : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C
f ∘ g = \x -> f (g x)
map : {A B : Set} -> (A -> B) -> List A -> List B
map f nil = nil
map f (x :: xs) = f x :: map f xs
stringAsList : (List Char -> List Char) -> String -> String
stringAsList f = primStringFromList ∘ f ∘ primStringToList
revStr : String -> String
revStr = stringAsList reverse
mapStr : (Char -> Char) -> String -> String
mapStr f = stringAsList (map f)
-- Testing unicode literals
uString = "åäö⊢ξ∀"
uChar = '∀'
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
thm-show-pos : primShowInteger (pos 42) ≡ "42"
thm-show-pos = refl
thm-show-neg : primShowInteger (negsuc 41) ≡ "-42"
thm-show-neg = refl
thm-floor : primFloor 4.2 ≡ pos 4
thm-floor = refl
thm-ceiling : primCeiling -5.1 ≡ negsuc 4
thm-ceiling = refl
| 23.335227
| 59
| 0.585342
|
d0074e91f192fa2aa94f767c685f34c49a4b8b0d
| 30,243
|
agda
|
Agda
|
HP.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
HP.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
HP.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
{--
Make a version of this file with plain PI and ℕ as a model
Make another version with PI+NEG+FRAC (meadow style) and ℚ as a model
Keep extending; add imaginary numbers and try ℂ as a model
then add square roots and try algebraic numbers as a model
An orthogonal direction is to try other models that are not numbers: in
particular groupoid-based models like we started in F2.agda and F2a.agda
--}
module HP where
-- Pi as a higher-order inductive type
open import Agda.Prim
open import Data.Empty
open import Data.Unit
open import Data.Unit.Core
open import Data.Maybe hiding (map)
open import Data.Nat renaming (_⊔_ to _⊔ℕ_)
open import Data.Integer hiding (_⊔_)
open import Data.Sum renaming (map to _⊎→_)
open import Data.Product renaming (map to _×→_)
open import Data.List
open import Data.Rational hiding (_≃_)
open import Function renaming (_∘_ to _○_)
infixr 8 _∘_ -- path composition
infix 4 _≡_ -- propositional equality
infix 4 _∼_ -- homotopy between two functions
infix 4 _≃_ -- type of equivalences
infix 2 _∎ -- equational reasoning
infixr 2 _≡⟨_⟩_ -- equational reasoning
infix 2 _∎≃ -- equational reasoning for equivalences
infixr 2 _≃⟨_⟩_ -- equational reasoning for equivalences
------------------------------------------------------------------------------
-- Identity types and path induction principles
-- Our own version of refl that makes 'a' explicit
data _≡_ {ℓ} {A : Set ℓ} : (a b : A) → Set ℓ where
refl : (a : A) → (a ≡ a)
pathInd : ∀ {u ℓ} → {A : Set u} →
(C : {x y : A} → x ≡ y → Set ℓ) →
(c : (x : A) → C (refl x)) →
({x y : A} (p : x ≡ y) → C p)
pathInd C c (refl x) = c x
basedPathInd : {A : Set} → (a : A) → (C : (x : A) → (a ≡ x) → Set) →
C a (refl a) → ((x : A) (p : a ≡ x) → C x p)
basedPathInd a C c .a (refl .a) = c
------------------------------------------------------------------------------
-- Ch. 2
-- Lemma 2.1.1
! : ∀ {u} → {A : Set u} {x y : A} → (x ≡ y) → (y ≡ x)
! = pathInd (λ {x} {y} _ → y ≡ x) refl
-- Lemma 2.1.2
_∘_ : ∀ {u} → {A : Set u} → {x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
_∘_ {u} {A} {x} {y} {z} p q =
pathInd
(λ {x} {y} p → ((z : A) → (q : y ≡ z) → (x ≡ z)))
(λ x z q → pathInd (λ {x} {z} _ → x ≡ z) refl {x} {z} q)
{x} {y} p z q
-- Lemma 2.1.4
-- p ≡ p ∘ refl
unitTransR : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ p ∘ refl y)
unitTransR {A} {x} {y} p =
pathInd
(λ {x} {y} p → p ≡ p ∘ (refl y))
(λ x → refl (refl x))
{x} {y} p
-- p ≡ refl ∘ p
unitTransL : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ refl x ∘ p)
unitTransL {A} {x} {y} p =
pathInd
(λ {x} {y} p → p ≡ (refl x) ∘ p)
(λ x → refl (refl x))
{x} {y} p
-- ! p ∘ p ≡ refl
invTransL : {A : Set} {x y : A} → (p : x ≡ y) → (! p ∘ p ≡ refl y)
invTransL {A} {x} {y} p =
pathInd
(λ {x} {y} p → ! p ∘ p ≡ refl y)
(λ x → refl (refl x))
{x} {y} p
-- p ∘ ! p ≡ refl
invTransR : ∀ {ℓ} {A : Set ℓ} {x y : A} → (p : x ≡ y) → (p ∘ ! p ≡ refl x)
invTransR {ℓ} {A} {x} {y} p =
pathInd
(λ {x} {y} p → p ∘ ! p ≡ refl x)
(λ x → refl (refl x))
{x} {y} p
-- ! (! p) ≡ p
invId : {A : Set} {x y : A} → (p : x ≡ y) → (! (! p) ≡ p)
invId {A} {x} {y} p =
pathInd
(λ {x} {y} p → ! (! p) ≡ p)
(λ x → refl (refl x))
{x} {y} p
-- p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r
assocP : {A : Set} {x y z w : A} → (p : x ≡ y) → (q : y ≡ z) → (r : z ≡ w) →
(p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r)
assocP {A} {x} {y} {z} {w} p q r =
pathInd
(λ {x} {y} p → (z : A) → (w : A) → (q : y ≡ z) → (r : z ≡ w) →
p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r)
(λ x z w q r →
pathInd
(λ {x} {z} q → (w : A) → (r : z ≡ w) →
(refl x) ∘ (q ∘ r) ≡ ((refl x) ∘ q) ∘ r)
(λ x w r →
pathInd
(λ {x} {w} r →
(refl x) ∘ ((refl x) ∘ r) ≡
((refl x) ∘ (refl x)) ∘ r)
(λ x → (refl (refl x)))
{x} {w} r)
{x} {z} q w r)
{x} {y} p z w q r
-- ! (p ∘ q) ≡ ! q ∘ ! p
invComp : {A : Set} {x y z : A} → (p : x ≡ y) → (q : y ≡ z) →
! (p ∘ q) ≡ ! q ∘ ! p
invComp {A} {x} {y} {z} p q =
pathInd
(λ {x} {y} p → (z : A) → (q : y ≡ z) → ! (p ∘ q) ≡ ! q ∘ ! p)
(λ x z q →
pathInd
(λ {x} {z} q → ! (refl x ∘ q) ≡ ! q ∘ ! (refl x))
(λ x → refl (refl x))
{x} {z} q)
{x} {y} p z q
-- Introduce equational reasoning syntax to simplify proofs
_≡⟨_⟩_ : ∀ {u} → {A : Set u} (x : A) {y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
_ ≡⟨ p ⟩ q = p ∘ q
bydef : ∀ {u} → {A : Set u} {x : A} → (x ≡ x)
bydef {u} {A} {x} = refl x
_∎ : ∀ {u} → {A : Set u} (x : A) → x ≡ x
_∎ x = refl x
------------------------------------------------------------------------------
-- Functions are functors
-- Lemma 2.2.1
-- computation rule: ap f (refl x) = refl (f x)
ap : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {x y : A} →
(f : A → B) → (x ≡ y) → (f x ≡ f y)
ap f p =
pathInd
(λ {x} {y} _ → f x ≡ f y)
(λ x → refl (f x))
p
ap₂ : ∀ {ℓ ℓ' ℓ''} → {A : Set ℓ} {B : Set ℓ'} {C : Set ℓ''}
{x₁ y₁ : A} {x₂ y₂ : B} →
(f : A → B → C) → (x₁ ≡ y₁) → (x₂ ≡ y₂) → (f x₁ x₂ ≡ f y₁ y₂)
ap₂ {ℓ} {ℓ'} {ℓ''} {A} {B} {C} {x₁} {y₁} {x₂} {y₂} f p₁ p₂ =
pathInd -- on p₁
(λ {x₁} {y₁} p₁ → f x₁ x₂ ≡ f y₁ y₂)
(λ x →
pathInd -- on p₂
(λ {x₂} {y₂} p₂ → f x x₂ ≡ f x y₂)
(λ y → refl (f x y))
{x₂} {y₂} p₂)
{x₁} {y₁} p₁
-- Lemma 2.2.2
-- f (p ∘ q) ≡ f p ∘ f q
apfTrans : ∀ {u} → {A B : Set u} {x y z : A} →
(f : A → B) → (p : x ≡ y) → (q : y ≡ z) → ap f (p ∘ q) ≡ (ap f p) ∘ (ap f q)
apfTrans {u} {A} {B} {x} {y} {z} f p q =
pathInd {u}
(λ {x} {y} p → (z : A) → (q : y ≡ z) →
ap f (p ∘ q) ≡ (ap f p) ∘ (ap f q))
(λ x z q →
pathInd {u}
(λ {x} {z} q →
ap f (refl x ∘ q) ≡ (ap f (refl x)) ∘ (ap f q))
(λ x → refl (refl (f x)))
{x} {z} q)
{x} {y} p z q
-- f (! p) ≡ ! (f p)
apfInv : ∀ {u} → {A B : Set u} {x y : A} → (f : A → B) → (p : x ≡ y) →
ap f (! p) ≡ ! (ap f p)
apfInv f p =
pathInd
(λ p → ap f (! p) ≡ ! (ap f p))
(λ x → refl (ap f (refl x)))
p
-- g (f p) ≡ (g ○ f) p
apfComp : {A B C : Set} {x y : A} → (f : A → B) → (g : B → C) → (p : x ≡ y) →
ap g (ap f p) ≡ ap (g ○ f) p
apfComp {A} {B} {C} {x} {y} f g p =
pathInd
(λ {x} {y} p → ap g (ap f p) ≡ ap (g ○ f) p)
(λ x → refl (ap g (ap f (refl x))))
{x} {y} p
-- id p ≡ p
apfId : {A : Set} {x y : A} → (p : x ≡ y) → ap id p ≡ p
apfId {A} {x} {y} p =
pathInd
(λ {x} {y} p → ap id p ≡ p)
(λ x → refl (refl x))
{x} {y} p
-- Transport
-- Lemma 2.3.1
transport : ∀ {ℓ ℓ'} → {A : Set ℓ} {x y : A} →
(P : A → Set ℓ') → (p : x ≡ y) → P x → P y
transport {x = x} {y} P p =
pathInd
(λ {x'} {y'} _ → (P x' → P y'))
(λ _ → id)
{x} {y} p
-- Lemma 2.3.10
transport-f : ∀ {ℓ ℓ' ℓ''} → {A : Set ℓ} {B : Set ℓ'} {x y : A} →
(f : A → B) → (P : B → Set ℓ'') →
(p : x ≡ y) → (u : P (f x)) →
transport (P ○ f) p u ≡ transport P (ap f p) u
transport-f {ℓ} {ℓ'} {ℓ''} {A} {B} {x} {y} f P p u =
pathInd -- on p
(λ {x} {y} p → (u : P (f x)) →
transport (P ○ f) p u ≡ transport P (ap f p) u)
(λ x u → refl u)
{x} {y} p u
-- Lemma 2.11.2
transportIdR : {A : Set} {a y z : A} → (p : y ≡ z) → (q : a ≡ y) →
transport (λ x → a ≡ x) p q ≡ q ∘ p
transportIdR {A} {a} {y} {z} p q =
pathInd
(λ {y} {z} p → (q : a ≡ y) → transport (λ x → a ≡ x) p q ≡ q ∘ p)
(λ y q → transport (λ x → a ≡ x) (refl y) q
≡⟨ bydef ⟩
q
≡⟨ unitTransR q ⟩
q ∘ refl y ∎)
{y} {z} p q
transportIdL : {A : Set} {a y z : A} → (p : y ≡ z) → (q : y ≡ a) →
transport (λ x → x ≡ a) p q ≡ ! p ∘ q
transportIdL {A} {a} {y} {z} p q =
pathInd
(λ {y} {z} p → (q : y ≡ a) → transport (λ x → x ≡ a) p q ≡ ! p ∘ q)
(λ y q → transport (λ x → x ≡ a) (refl y) q
≡⟨ bydef ⟩
q
≡⟨ unitTransL q ⟩
! (refl y) ∘ q ∎)
{y} {z} p q
transportIdRefl : {A : Set} {y z : A} → (p : y ≡ z) → (q : y ≡ y) →
transport (λ x → x ≡ x) p q ≡ ! p ∘ q ∘ p
transportIdRefl {A} {y} {z} p q =
pathInd
(λ {y} {z} p → (q : y ≡ y) → transport (λ x → x ≡ x) p q ≡ ! p ∘ q ∘ p)
(λ y q → transport (λ x → x ≡ x) (refl y) q
≡⟨ bydef ⟩
q
≡⟨ unitTransR q ⟩
q ∘ refl y
≡⟨ unitTransL (q ∘ refl y) ⟩
! (refl y) ∘ q ∘ refl y ∎)
{y} {z} p q
-- Thm 2.11.3
transportId : {A B : Set} {y z : A} → (f g : A → B) →
(p : y ≡ z) → (q : f y ≡ g y) →
transport (λ x → f x ≡ g x) p q ≡ ! (ap f p) ∘ q ∘ (ap g p)
transportId {A} {B} {y} {z} f g p q =
pathInd
(λ {y} {z} p → (q : f y ≡ g y) →
transport (λ x → f x ≡ g x) p q ≡ ! (ap f p) ∘ q ∘ (ap g p))
(λ y q → q
≡⟨ unitTransR q ⟩
q ∘ refl (g y)
≡⟨ unitTransL (q ∘ refl (g y)) ⟩
refl (f y) ∘ q ∘ refl (g y) ∎)
{y} {z} p q
-------------------------------------------------------------------------------
-- Homotopies and equivalences
_∼_ : ∀ {ℓ ℓ'} → {A : Set ℓ} {P : A → Set ℓ'} →
(f g : (x : A) → P x) → Set (_⊔_ ℓ ℓ')
_∼_ {ℓ} {ℓ'} {A} {P} f g = (x : A) → f x ≡ g x
-- Quasi-inverses
record qinv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) :
Set (_⊔_ ℓ ℓ') where
constructor mkqinv
field
g : B → A
α : (f ○ g) ∼ id
β : (g ○ f) ∼ id
-- Example 2.4.7
idqinv : ∀ {ℓ} → {A : Set ℓ} → qinv {ℓ} {ℓ} {A} {A} id
idqinv = record {
g = id ;
α = λ b → refl b ;
β = λ a → refl a
}
-- Equivalences
record isequiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) :
Set (_⊔_ ℓ ℓ') where
constructor mkisequiv
field
g : B → A
α : (f ○ g) ∼ id
h : B → A
β : (h ○ f) ∼ id
equiv₁ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → qinv f → isequiv f
equiv₁ (mkqinv qg qα qβ) = mkisequiv qg qα qg qβ
equiv₂ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → isequiv f → qinv f
equiv₂ {f = f} (mkisequiv ig iα ih iβ) =
record {
g = ig ;
α = iα ;
β = λ x → ig (f x)
≡⟨ ! (iβ (ig (f x))) ⟩
ih (f (ig (f x)))
≡⟨ ap ih (iα (f x)) ⟩
ih (f x)
≡⟨ iβ x ⟩
x ∎
}
_≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (_⊔_ ℓ ℓ')
A ≃ B = Σ (A → B) isequiv
id≃ : ∀ {ℓ} {A : Set ℓ} → A ≃ A
id≃ = (id , equiv₁ idqinv)
sym≃ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → (A ≃ B) → B ≃ A
sym≃ (A→B , equiv) with equiv₂ equiv
... | mkqinv g α β = g , equiv₁ (mkqinv A→B β α)
trans≃ : {A B C : Set} → A ≃ B → B ≃ C → A ≃ C
trans≃ (f , feq) (g , geq) with equiv₂ feq | equiv₂ geq
... | mkqinv ff fα fβ | mkqinv gg gα gβ =
(g ○ f , equiv₁ (mkqinv
(ff ○ gg)
(λ c → g (f (ff (gg c)))
≡⟨ ap g (fα (gg c)) ⟩
g (gg c)
≡⟨ gα c ⟩
c ∎)
(λ a → ff (gg (g (f a)))
≡⟨ ap ff (gβ (f a)) ⟩
ff (f a)
≡⟨ fβ a ⟩
a ∎)))
-- identities are equivalences
idtoeqv : {A B : Set} → (A ≡ B) → (A ≃ B)
idtoeqv {A} {B} p =
pathInd
(λ {A'} {B'} _ → A' ≃ B')
(λ _ → id≃)
{A} {B} p
-- equivalences are injective
_⋆_ : {A B : Set} → (A ≃ B) → (x : A) → B
(f , _) ⋆ x = f x
inj≃ : {A B : Set} → (eq : A ≃ B) → (x y : A) → (eq ⋆ x ≡ eq ⋆ y → x ≡ y)
inj≃ (f , mkisequiv g α h β) x y p = ! (β x) ∘ (ap h p ∘ β y)
-- equivalences for coproducts (Sec. 2.12)
indCP : {A B : Set} → (C : A ⊎ B → Set) →
((a : A) → C (inj₁ a)) → ((b : B) → C (inj₂ b)) → ((x : A ⊎ B) → C x)
indCP C f g (inj₁ a) = f a
indCP C f g (inj₂ b) = g b
code : {A B : Set} → (a₀ : A) → A ⊎ B → Set
code a₀ (inj₁ a) = a₀ ≡ a
code a₀ (inj₂ b) = ⊥
encode : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (p : inj₁ a₀ ≡ x) → code a₀ x
encode {A} {B} a₀ x p = transport (code a₀) p (refl a₀)
decode : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (c : code a₀ x) → inj₁ a₀ ≡ x
decode a₀ (inj₁ a) c = ap inj₁ c
decode a₀ (inj₂ b) ()
codeqinv : {A B : Set} {a₀ : A} {x : A ⊎ B} → qinv (encode a₀ x)
codeqinv {A} {B} {a₀} {x} = record {
g = decode a₀ x ;
α = indCP
(λ x → (c : code a₀ x) → encode a₀ x (decode a₀ x c) ≡ c)
(λ a c → encode a₀ (inj₁ a) (decode a₀ (inj₁ a) c)
≡⟨ bydef ⟩
encode a₀ (inj₁ a) (ap inj₁ c)
≡⟨ bydef ⟩
transport (code a₀) (ap inj₁ c) (refl a₀)
≡⟨ ! (transport-f inj₁ (code a₀) c (refl a₀)) ⟩
transport (λ a → code {A} {B} a₀ (inj₁ a)) c (refl a₀)
≡⟨ bydef ⟩
transport (λ a → a₀ ≡ a) c (refl a₀)
≡⟨ transportIdR c (refl a₀) ⟩
(refl a₀) ∘ c
≡⟨ ! (unitTransL c) ⟩
c ∎)
(λ b ())
x ;
β = λ p → basedPathInd
(inj₁ a₀)
(λ x p → decode a₀ x (encode a₀ x p) ≡ p)
(decode a₀ (inj₁ a₀)
(encode {A} {B} a₀ (inj₁ a₀) (refl (inj₁ a₀)))
≡⟨ bydef ⟩
(decode a₀ (inj₁ a₀)
(transport (code {A} {B} a₀) (refl (inj₁ a₀)) (refl a₀)))
≡⟨ bydef ⟩
(decode a₀ (inj₁ a₀) (refl a₀))
≡⟨ bydef ⟩
(ap inj₁ (refl a₀))
≡⟨ bydef ⟩
refl (inj₁ a₀) ∎)
x p }
thm2-12-5 : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (inj₁ a₀ ≡ x) ≃ code a₀ x
thm2-12-5 {A} {B} a₀ x = (encode a₀ x , equiv₁ codeqinv)
inj₁₁path : {A B : Set} → (a₁ a₂ : A) →
(inj₁ {A = A} {B = B} a₁ ≡ inj₁ a₂) ≃ (a₁ ≡ a₂)
inj₁₁path a₁ a₂ = thm2-12-5 a₁ (inj₁ a₂)
inj₁₂path : {A B : Set} → (a : A) (b : B) → (inj₁ a ≡ inj₂ b) ≃ ⊥
inj₁₂path a b = thm2-12-5 a (inj₂ b)
-- Abbreviations for equivalence compositions
_≃⟨_⟩_ : (A : Set) {B C : Set} → (A ≃ B) → (B ≃ C) → (A ≃ C)
_ ≃⟨ p ⟩ q = trans≃ p q
_∎≃ : {ℓ : Level} {A : Set ℓ} → A ≃ A
_∎≃ {ℓ} {A} = id≃ {ℓ} {A}
------------------------------------------------------------------------------
-- Type equivalences
-- unite₊ and uniti₊
unite₊ : {A : Set} → ⊥ ⊎ A → A
unite₊ (inj₁ ())
unite₊ (inj₂ y) = y
uniti₊ : {A : Set} → A → ⊥ ⊎ A
uniti₊ a = inj₂ a
uniti₊∘unite₊ : {A : Set} → uniti₊ ○ unite₊ ∼ id {A = ⊥ ⊎ A}
uniti₊∘unite₊ (inj₁ ())
uniti₊∘unite₊ (inj₂ y) = refl (inj₂ y)
unite₊∙uniti₊ : {A : Set} → unite₊ ○ uniti₊ ∼ id {A = A}
unite₊∙uniti₊ = refl
unite₊≃ : {A : Set} → (⊥ ⊎ A) ≃ A
unite₊≃ = (unite₊ , mkisequiv uniti₊ refl uniti₊ uniti₊∘unite₊)
uniti₊≃ : {A : Set} → A ≃ (⊥ ⊎ A)
uniti₊≃ = uniti₊ , mkisequiv unite₊ uniti₊∘unite₊ unite₊ unite₊∙uniti₊
-- swap₊
swap₊ : {A B : Set} → A ⊎ B → B ⊎ A
swap₊ (inj₁ a) = inj₂ a
swap₊ (inj₂ b) = inj₁ b
swapswap₊ : {A B : Set} → swap₊ ○ swap₊ {A} {B} ∼ id
swapswap₊ (inj₁ a) = refl (inj₁ a)
swapswap₊ (inj₂ b) = refl (inj₂ b)
swap₊≃ : {A B : Set} → (A ⊎ B) ≃ (B ⊎ A)
swap₊≃ = (swap₊ , equiv₁ (mkqinv swap₊ swapswap₊ swapswap₊))
-- assocl₊ and assocr₊
assocl₊ : {A B C : Set} → (A ⊎ (B ⊎ C)) → ((A ⊎ B) ⊎ C)
assocl₊ (inj₁ a) = inj₁ (inj₁ a)
assocl₊ (inj₂ (inj₁ b)) = inj₁ (inj₂ b)
assocl₊ (inj₂ (inj₂ c)) = inj₂ c
assocr₊ : {A B C : Set} → ((A ⊎ B) ⊎ C) → (A ⊎ (B ⊎ C))
assocr₊ (inj₁ (inj₁ a)) = inj₁ a
assocr₊ (inj₁ (inj₂ b)) = inj₂ (inj₁ b)
assocr₊ (inj₂ c) = inj₂ (inj₂ c)
assocl₊∘assocr₊ : {A B C : Set} → assocl₊ ○ assocr₊ ∼ id {A = ((A ⊎ B) ⊎ C)}
assocl₊∘assocr₊ (inj₁ (inj₁ a)) = refl (inj₁ (inj₁ a))
assocl₊∘assocr₊ (inj₁ (inj₂ b)) = refl (inj₁ (inj₂ b))
assocl₊∘assocr₊ (inj₂ c) = refl (inj₂ c)
assocr₊∘assocl₊ : {A B C : Set} → assocr₊ ○ assocl₊ ∼ id {A = (A ⊎ (B ⊎ C))}
assocr₊∘assocl₊ (inj₁ a) = refl (inj₁ a)
assocr₊∘assocl₊ (inj₂ (inj₁ b)) = refl (inj₂ (inj₁ b))
assocr₊∘assocl₊ (inj₂ (inj₂ c)) = refl (inj₂ (inj₂ c))
assocl₊≃ : {A B C : Set} → (A ⊎ (B ⊎ C)) ≃ ((A ⊎ B) ⊎ C)
assocl₊≃ =
assocl₊ , mkisequiv assocr₊ assocl₊∘assocr₊ assocr₊ assocr₊∘assocl₊
assocr₊≃ : {A B C : Set} → ((A ⊎ B) ⊎ C) ≃ (A ⊎ (B ⊎ C))
assocr₊≃ =
assocr₊ , mkisequiv assocl₊ assocr₊∘assocl₊ assocl₊ assocl₊∘assocr₊
-- unite⋆ and uniti⋆
unite⋆ : {A : Set} → ⊤ × A → A
unite⋆ (tt , x) = x
uniti⋆ : {A : Set} → A → ⊤ × A
uniti⋆ x = tt , x
uniti⋆∘unite⋆ : {A : Set} → uniti⋆ ○ unite⋆ ∼ id {A = ⊤ × A}
uniti⋆∘unite⋆ (tt , x) = refl (tt , x)
unite⋆≃ : {A : Set} → (⊤ × A) ≃ A
unite⋆≃ = unite⋆ , mkisequiv uniti⋆ refl uniti⋆ uniti⋆∘unite⋆
uniti⋆≃ : {A : Set} → A ≃ (⊤ × A)
uniti⋆≃ = uniti⋆ , mkisequiv unite⋆ uniti⋆∘unite⋆ unite⋆ refl
-- swap⋆
swap⋆ : {A B : Set} → A × B → B × A
swap⋆ (a , b) = (b , a)
swapswap⋆ : {A B : Set} → swap⋆ ○ swap⋆ ∼ id {A = A × B}
swapswap⋆ (a , b) = refl (a , b)
swap⋆≃ : {A B : Set} → (A × B) ≃ (B × A)
swap⋆≃ = swap⋆ , mkisequiv swap⋆ swapswap⋆ swap⋆ swapswap⋆
-- assocl⋆ and assocr⋆
assocl⋆ : {A B C : Set} → (A × (B × C)) → ((A × B) × C)
assocl⋆ (a , (b , c)) = ((a , b) , c)
assocr⋆ : {A B C : Set} → ((A × B) × C) → (A × (B × C))
assocr⋆ ((a , b) , c) = (a , (b , c))
assocl⋆∘assocr⋆ : {A B C : Set} → assocl⋆ ○ assocr⋆ ∼ id {A = ((A × B) × C)}
assocl⋆∘assocr⋆ x = refl x
assocr⋆∘assocl⋆ : {A B C : Set} → assocr⋆ ○ assocl⋆ ∼ id {A = (A × (B × C))}
assocr⋆∘assocl⋆ x = refl x
assocl⋆≃ : {A B C : Set} → (A × (B × C)) ≃ ((A × B) × C)
assocl⋆≃ =
assocl⋆ , mkisequiv assocr⋆ assocl⋆∘assocr⋆ assocr⋆ assocr⋆∘assocl⋆
assocr⋆≃ : {A B C : Set} → ((A × B) × C) ≃ (A × (B × C))
assocr⋆≃ =
assocr⋆ , mkisequiv assocl⋆ assocr⋆∘assocl⋆ assocl⋆ assocl⋆∘assocr⋆
-- distz and factorz
distz : { A : Set} → (⊥ × A) → ⊥
distz (() , _)
factorz : {A : Set} → ⊥ → (⊥ × A)
factorz ()
distz∘factorz : {A : Set} → distz ○ factorz {A} ∼ id
distz∘factorz ()
factorz∘distz : {A : Set} → factorz {A} ○ distz ∼ id
factorz∘distz (() , proj₂)
distz≃ : {A : Set} → (⊥ × A) ≃ ⊥
distz≃ {A} =
distz , mkisequiv factorz (distz∘factorz {A}) factorz factorz∘distz
factorz≃ : {A : Set} → ⊥ ≃ (⊥ × A)
factorz≃ {A} =
factorz , mkisequiv distz factorz∘distz distz (distz∘factorz {A})
-- dist and factor
dist : {A B C : Set} → ((A ⊎ B) × C) → (A × C) ⊎ (B × C)
dist (inj₁ x , c) = inj₁ (x , c)
dist (inj₂ y , c) = inj₂ (y , c)
factor : {A B C : Set} → (A × C) ⊎ (B × C) → ((A ⊎ B) × C)
factor (inj₁ (a , c)) = inj₁ a , c
factor (inj₂ (b , c)) = inj₂ b , c
dist∘factor : {A B C : Set} → dist {A} {B} {C} ○ factor ∼ id
dist∘factor (inj₁ x) = refl (inj₁ x)
dist∘factor (inj₂ y) = refl (inj₂ y)
factor∘dist : {A B C : Set} → factor {A} {B} {C} ○ dist ∼ id
factor∘dist (inj₁ x , c) = refl (inj₁ x , c)
factor∘dist (inj₂ y , c) = refl (inj₂ y , c)
dist≃ : {A B C : Set} → ((A ⊎ B) × C) ≃ ((A × C) ⊎ (B × C))
dist≃ = dist , mkisequiv factor dist∘factor factor factor∘dist
factor≃ : {A B C : Set} → ((A × C) ⊎ (B × C)) ≃ ((A ⊎ B) × C)
factor≃ = factor , (mkisequiv dist factor∘dist dist dist∘factor)
-- congruence
-- ⊕
_⊎∼_ : {A B C D : Set} {f : A → C} {finv : C → A} {g : B → D} {ginv : D → B} →
(α : f ○ finv ∼ id) → (β : g ○ ginv ∼ id) →
(f ⊎→ g) ○ (finv ⊎→ ginv) ∼ id {A = C ⊎ D}
_⊎∼_ α β (inj₁ x) = ap inj₁ (α x)
_⊎∼_ α β (inj₂ y) = ap inj₂ (β y)
path⊎ : {A B C D : Set} → A ≃ C → B ≃ D → (A ⊎ B) ≃ (C ⊎ D)
path⊎ (fp , eqp) (fq , eqq) =
Data.Sum.map fp fq ,
mkisequiv (P.g ⊎→ Q.g) (P.α ⊎∼ Q.α) (P.h ⊎→ Q.h) (P.β ⊎∼ Q.β)
where module P = isequiv eqp
module Q = isequiv eqq
-- ⊗
_×∼_ : {A B C D : Set} {f : A → C} {finv : C → A} {g : B → D} {ginv : D → B} →
(α : f ○ finv ∼ id) → (β : g ○ ginv ∼ id) →
(f ×→ g) ○ (finv ×→ ginv) ∼ id {A = C × D}
_×∼_ α β (x , y) = ap₂ _,_ (α x) (β y)
path× : {A B C D : Set} → A ≃ C → B ≃ D → (A × B) ≃ (C × D)
path× {A} {B} {C} {D} (fp , eqp) (fq , eqq) =
Data.Product.map fp fq ,
mkisequiv
(P.g ×→ Q.g)
(_×∼_ {A} {B} {C} {D} {fp} {P.g} {fq} {Q.g} P.α Q.α)
(P.h ×→ Q.h)
(_×∼_ {C} {D} {A} {B} {P.h} {fp} {Q.h} {fq} P.β Q.β)
where module P = isequiv eqp
module Q = isequiv eqq
------------------------------------------------------------------------------
-- Pi as a higher-order inductive type
module PI where
-- hidden
private
data FT* : Set where
ZERO* : FT*
ONE* : FT*
PLUS* : FT* → FT* → FT*
TIMES* : FT* → FT* → FT*
NEG* : FT* → FT*
RECIP* : FT* → FT*
-- exported
FT : Set
FT = FT*
ZERO : FT
ZERO = ZERO*
ONE : FT
ONE = ONE*
PLUS : FT → FT → FT
PLUS = PLUS*
TIMES : FT → FT → FT
TIMES = TIMES*
NEG : FT → FT
NEG = NEG*
RECIP : FT → FT
RECIP = RECIP*
postulate
-- additive structure
unite₊≡ : { b : FT } → PLUS ZERO b ≡ b
uniti₊≡ : { b : FT } → b ≡ PLUS ZERO b
swap₊≡ : { b₁ b₂ : FT } → PLUS b₁ b₂ ≡ PLUS b₂ b₁
assocl₊≡ : { b₁ b₂ b₃ : FT } → PLUS b₁ (PLUS b₂ b₃) ≡ PLUS (PLUS b₁ b₂) b₃
assocr₊≡ : { b₁ b₂ b₃ : FT } → PLUS (PLUS b₁ b₂) b₃ ≡ PLUS b₁ (PLUS b₂ b₃)
-- multiplicative structure
unite⋆≡ : { b : FT } → TIMES ONE b ≡ b
uniti⋆≡ : { b : FT } → b ≡ TIMES ONE b
swap⋆≡ : { b₁ b₂ : FT } → TIMES b₁ b₂ ≡ TIMES b₂ b₁
assocl⋆≡ : { b₁ b₂ b₃ : FT } →
TIMES b₁ (TIMES b₂ b₃) ≡ TIMES (TIMES b₁ b₂) b₃
assocr⋆≡ : { b₁ b₂ b₃ : FT } →
TIMES (TIMES b₁ b₂) b₃ ≡ TIMES b₁ (TIMES b₂ b₃)
-- distributivity
distz≡ : { b : FT } → TIMES ZERO b ≡ ZERO
factorz≡ : { b : FT } → ZERO ≡ TIMES ZERO b
dist≡ : { b₁ b₂ b₃ : FT } →
TIMES (PLUS b₁ b₂) b₃ ≡ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)
factor≡ : { b₁ b₂ b₃ : FT } →
PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ≡ TIMES (PLUS b₁ b₂) b₃
-- negatives and fractionals
η₊ : { b : FT } → ZERO ≡ PLUS (NEG b) b
ε₊ : { b : FT } → PLUS (NEG b) b ≡ ZERO
refe⋆ : { b : FT } → RECIP (RECIP b) ≡ b
refi⋆ : { b : FT } → b ≡ RECIP (RECIP b)
rile⋆ : { b : FT } → TIMES b (TIMES b (RECIP b)) ≡ b
rili⋆ : { b : FT } → b ≡ TIMES b (TIMES b (RECIP b))
-- no need to postulate congruence; it will be provable
-- Any function mapping PI to a type C must produce one of the following
-- records that shows how both points and paths are mapped
record PIR {ℓ : Level} (C : Set ℓ) : Set (lsuc ℓ) where
field
czero : C
cone : C
cplus : C → C → C
ctimes : C → C → C
cneg : C → C
crecip : C → C
cunite₊≡ : { c : C } → cplus czero c ≡ c
cuniti₊≡ : { c : C } → c ≡ cplus czero c
cswap₊≡ : { c₁ c₂ : C } → cplus c₁ c₂ ≡ cplus c₂ c₁
cassocl₊≡ : { c₁ c₂ c₃ : C } →
cplus c₁ (cplus c₂ c₃) ≡ cplus (cplus c₁ c₂) c₃
cassocr₊≡ : { c₁ c₂ c₃ : C } →
cplus (cplus c₁ c₂) c₃ ≡ cplus c₁ (cplus c₂ c₃)
cunite⋆≡ : { c : C } → ctimes cone c ≡ c
cuniti⋆≡ : { c : C } → c ≡ ctimes cone c
cswap⋆≡ : { c₁ c₂ : C } → ctimes c₁ c₂ ≡ ctimes c₂ c₁
cassocl⋆≡ : { c₁ c₂ c₃ : C } →
ctimes c₁ (ctimes c₂ c₃) ≡ ctimes (ctimes c₁ c₂) c₃
cassocr⋆≡ : { c₁ c₂ c₃ : C } →
ctimes (ctimes c₁ c₂) c₃ ≡ ctimes c₁ (ctimes c₂ c₃)
cdistz≡ : { c : C } → ctimes czero c ≡ czero
cfactorz≡ : { c : C } → czero ≡ ctimes czero c
cdist≡ : { c₁ c₂ c₃ : C } →
ctimes (cplus c₁ c₂) c₃ ≡ cplus (ctimes c₁ c₃) (ctimes c₂ c₃)
cfactor≡ : { c₁ c₂ c₃ : C } →
cplus (ctimes c₁ c₃) (ctimes c₂ c₃) ≡ ctimes (cplus c₁ c₂) c₃
cη₊ : { c : C } → czero ≡ cplus (cneg c) c
cε₊ : { c : C } → cplus (cneg c) c ≡ czero
crefe⋆ : { c : C } → crecip (crecip c) ≡ c
crefi⋆ : { c : C } → c ≡ crecip (crecip c)
crile⋆ : { c : C } → ctimes c (ctimes c (crecip c)) ≡ c
crili⋆ : { c : C } → c ≡ ctimes c (ctimes c (crecip c))
open PIR
-- recursion principle for PI: given a target type C and a target record as
-- above that has appropriate points and paths, recPI shows how points are
-- mapped to points; the postulates assert that paths are transported as
-- expected
recPI : {ℓ : Level} {C : Set ℓ} → (PIR C) → FT → C
recPI pir ZERO* = czero pir
recPI pir ONE* = cone pir
recPI pir (PLUS* B₁ B₂) = cplus pir (recPI pir B₁) (recPI pir B₂)
recPI pir (TIMES* B₁ B₂) = ctimes pir (recPI pir B₁) (recPI pir B₂)
recPI pir (NEG* B) = cneg pir (recPI pir B)
recPI pir (RECIP* B) = crecip pir (recPI pir B)
postulate
βreccunite₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (unite₊≡ {b}) ≡ cunite₊≡ pir
βreccuniti₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (uniti₊≡ {b}) ≡ cuniti₊≡ pir
βreccswap₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ : FT} → ap (recPI pir) (swap₊≡ {b₁} {b₂}) ≡ cswap₊≡ pir
βreccassocl₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocl₊≡ {b₁} {b₂} {b₃}) ≡
cassocl₊≡ pir
βreccassocr₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocr₊≡ {b₁} {b₂} {b₃}) ≡
cassocr₊≡ pir
βreccunite⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (unite⋆≡ {b}) ≡ cunite⋆≡ pir
βreccuniti⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (uniti⋆≡ {b}) ≡ cuniti⋆≡ pir
βreccswap⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ : FT} → ap (recPI pir) (swap⋆≡ {b₁} {b₂}) ≡ cswap⋆≡ pir
βreccassocl⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocl⋆≡ {b₁} {b₂} {b₃}) ≡
cassocl⋆≡ pir
βreccassocr⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocr⋆≡ {b₁} {b₂} {b₃}) ≡
cassocr⋆≡ pir
βreccdistz≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (distz≡ {b}) ≡ cdistz≡ pir
βreccfactorz≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (factorz≡ {b}) ≡ cfactorz≡ pir
βreccdist≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (dist≡ {b₁} {b₂} {b₃}) ≡
cdist≡ pir
βreccfactor≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (factor≡ {b₁} {b₂} {b₃}) ≡
cfactor≡ pir
βreccη₊ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (η₊ {b}) ≡ cη₊ pir
βreccε₊ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (ε₊ {b}) ≡ cε₊ pir
βreccrefe⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (refe⋆ {b}) ≡ crefe⋆ pir
βreccrefi⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (refi⋆ {b}) ≡ crefi⋆ pir
βreccrile⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (rile⋆ {b}) ≡ crile⋆ pir
βreccrili⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (rili⋆ {b}) ≡ crili⋆ pir
open PI public
------------------------------------------------------------------------------
-- Semantics I
-- The rationals are a model of PI
{--
unitPlus : (n : ℕ) -> (n + 0) ≡ n
unitPlus 0 = refl 0
unitPlus (suc m) = ap suc (unitPlus m)
sPlus : (n m : ℕ) -> suc (n + m) ≡ (n + suc m)
sPlus 0 m = refl (suc m)
sPlus (suc n) m = ap suc (sPlus n m)
commPlus : (m n : ℕ) -> (m + n) ≡ (n + m)
commPlus 0 n = ! (unitPlus n)
commPlus (suc m) n = (ap suc (commPlus m n)) ∘ (sPlus n m)
assocPlus : (m n o : ℕ) ->((m + n) + o) ≡ (m + (n + o))
assocPlus 0 n o = refl (n + o)
assocPlus (suc m) n o = ap suc (assocPlus m n o)
--
unitMult : (i : ℕ) → 1 * i ≡ i
unitMult 0 = refl 0
unitMult (suc i) = ap suc (unitMult i)
mulSuc : (m n : ℕ) → m * suc n ≡ m + m * n
mulSuc 0 n = refl 0
mulSuc (suc m) n = ap (λ x → suc n + x) (mulSuc m n) ∘
ap suc (! (assocPlus n m (m * n))) ∘
ap (λ x → suc (x + m * n)) (commPlus n m) ∘
ap suc (assocPlus m n (m * n))
annMult : (i : ℕ) → i * 0 ≡ 0
annMult 0 = refl 0
annMult (suc i) = annMult i
commMult : (i j : ℕ) → i * j ≡ j * i
commMult 0 j = ! (annMult j)
commMult (suc i) j = ap (λ x → j + x) (commMult i j) ∘
(! (mulSuc j i))
distrib : (i j k : ℕ) → (j + k) * i ≡ j * i + k * i
distrib i 0 k = refl (k * i)
distrib i (suc j) k = ap (_+_ i) (distrib i j k) ∘
(! (assocPlus i (j * i) (k * i)))
assocMult : (i j k : ℕ) → (i * j) * k ≡ i * (j * k)
assocMult 0 j k = refl 0
assocMult (suc i) j k = distrib k j (i * j) ∘
ap (λ x → j * k + x) (assocMult i j k)
--}
--
toℚ : FT → ℚ
toℚ b = recPI (record {
czero = + 0 ÷ 1 ;
cone = + 1 ÷ 1 ;
cplus = {!!} ; --_+_ ;
ctimes = {!!} ; --_*_ ;
cneg = {!!} ;
crecip = {!!} ;
cunite₊≡ = {!!} ; --λ {c} → refl c ;
cuniti₊≡ = {!!} ; --λ {c} → refl c ;
cswap₊≡ = {!!} ; --λ {a b} → commPlus a b ;
cassocl₊≡ = {!!} ; --λ {a b c} → ! (assocPlus a b c) ;
cassocr₊≡ = {!!} ; --λ {a b c} → assocPlus a b c ;
cunite⋆≡ = {!!} ; --λ {a} → unitMult a ;
cuniti⋆≡ = {!!} ; --λ {a} → ! (unitMult a) ;
cswap⋆≡ = {!!} ; --λ {a b} → commMult a b ;
cassocl⋆≡ = {!!} ; --λ {a b c} → ! (assocMult a b c) ;
cassocr⋆≡ = {!!} ; --λ {a b c} → assocMult a b c ;
cdistz≡ = {!!} ; --refl 0 ;
cfactorz≡ = {!!} ; --refl 0 ;
cdist≡ = {!!} ; --λ {a b c} → distrib c a b ;
cfactor≡ = {!!} ; --λ {a b c} → ! (distrib c a b) ;
cη₊ = {!!} ;
cε₊ = {!!} ;
crefe⋆ = {!!} ;
crefi⋆ = {!!} ;
crile⋆ = {!!} ;
crili⋆ = {!!}
}) b
------------------------------------------------------------------------------
| 31.568894
| 79
| 0.424363
|
c5f39499950be1880e6ec46dcf408900c6c1a64b
| 926
|
agda
|
Agda
|
Definition/Conversion/Universe.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Definition/Conversion/Universe.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Definition/Conversion/Universe.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
{-# OPTIONS --safe #-}
module Definition.Conversion.Universe where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.RedSteps
open import Definition.Conversion
open import Definition.Conversion.Reduction
open import Definition.Conversion.Lift
import Tools.PropositionalEquality as PE
-- Algorithmic equality of terms in WHNF of type U are equal as types.
univConv↓ : ∀ {A B r Γ l}
→ Γ ⊢ A [conv↓] B ∷ Univ r l ^ next l
→ Γ ⊢ A [conv↓] B ^ [ r , ι l ]
univConv↓ X = univ X
-- Algorithmic equality of terms of type U are equal as types.
univConv↑ : ∀ {A B r Γ l}
→ Γ ⊢ A [conv↑] B ∷ Univ r l ^ next l
→ Γ ⊢ A [conv↑] B ^ [ r , ι l ]
univConv↑ ([↑]ₜ B₁ t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u)
rewrite PE.sym (whnfRed* D Uₙ) =
reductionConv↑ (univ* d) (univ* d′) whnft′ whnfu′ (liftConv (univConv↓ t<>u))
| 30.866667
| 79
| 0.661987
|
4ad4cf5cb8c4c5d27277339952707405fd29fe24
| 1,679
|
agda
|
Agda
|
src/Categories/Category/CartesianClosed/Properties.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
src/Categories/Category/CartesianClosed/Properties.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | null | null | null |
src/Categories/Category/CartesianClosed/Properties.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.CartesianClosed.Properties where
open import Level
open import Data.Product using (Σ; _,_; Σ-syntax; proj₁; proj₂)
open import Categories.Category.Core
open import Categories.Category.CartesianClosed
import Categories.Morphism.Reasoning as MR
module _ {o ℓ e} {𝒞 : Category o ℓ e} (𝓥 : CartesianClosed 𝒞) where
open Category 𝒞
open CartesianClosed 𝓥
open HomReasoning
open MR 𝒞
PointSurjective : ∀ {A X Y : Obj} → (X ⇒ Y ^ A) → Set (ℓ ⊔ e)
PointSurjective {A = A} {X = X} {Y = Y} ϕ =
∀ (f : A ⇒ Y) → Σ[ x ∈ ⊤ ⇒ X ] (∀ (a : ⊤ ⇒ A) → eval′ ∘ first ϕ ∘ ⟨ x , a ⟩ ≈ f ∘ a)
lawvere-fixed-point : ∀ {A B : Obj} → (ϕ : A ⇒ B ^ A) → PointSurjective ϕ → (f : B ⇒ B) → Σ[ s ∈ ⊤ ⇒ B ] f ∘ s ≈ s
lawvere-fixed-point {A = A} {B = B} ϕ surjective f = g ∘ x , g-fixed-point
where
g : A ⇒ B
g = f ∘ eval′ ∘ ⟨ ϕ , id ⟩
x : ⊤ ⇒ A
x = proj₁ (surjective g)
g-surjective : eval′ ∘ first ϕ ∘ ⟨ x , x ⟩ ≈ g ∘ x
g-surjective = proj₂ (surjective g) x
lemma : ∀ {A B C D} → (f : B ⇒ C) → (g : B ⇒ D) → (h : A ⇒ B) → (f ⁂ g) ∘ ⟨ h , h ⟩ ≈ ⟨ f , g ⟩ ∘ h
lemma f g h = begin
(f ⁂ g) ∘ ⟨ h , h ⟩ ≈⟨ ⁂∘⟨⟩ ⟩
⟨ f ∘ h , g ∘ h ⟩ ≈˘⟨ ⟨⟩∘ ⟩
⟨ f , g ⟩ ∘ h ∎
g-fixed-point : f ∘ (g ∘ x) ≈ g ∘ x
g-fixed-point = begin
f ∘ g ∘ x ≈˘⟨ refl⟩∘⟨ g-surjective ⟩
f ∘ eval′ ∘ first ϕ ∘ ⟨ x , x ⟩ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ lemma ϕ id x ⟩
f ∘ eval′ ∘ ⟨ ϕ , id ⟩ ∘ x ≈⟨ ∘-resp-≈ʳ sym-assoc ○ sym-assoc ⟩
(f ∘ eval′ ∘ ⟨ ϕ , id ⟩) ∘ x ≡⟨⟩
g ∘ x ∎
| 34.979167
| 116
| 0.461584
|
502fb37d337b615833b8b2d4389a5f1e41b3b0e8
| 4,606
|
agda
|
Agda
|
FormalLanguage/RegularExpression.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
FormalLanguage/RegularExpression.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
FormalLanguage/RegularExpression.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
import Lvl
open import Type
module FormalLanguage.RegularExpression {ℓ} (Σ : Type{ℓ}) where
open import Data.Boolean
open import Data.Boolean.Stmt.Proofs
open import Data.List as List using (List)
open import FormalLanguage
open import FormalLanguage.Proofs
open import Functional
open import Logic
open import Logic.Propositional
open import Numeral.Natural
open import Relator.Equals
data RegExp : Type{ℓ} where
∅ : RegExp -- Empty language (Consisting of no words).
ε : RegExp -- Empty word language (Consisting of a single empty word).
• : Σ → RegExp -- Singleton language (Consisting of a single one letter word).
_++_ : RegExp → RegExp → RegExp -- Concatenation language (Consisting of the words concatenated pairwise).
_‖_ : RegExp → RegExp → RegExp -- Union language (Consisting of the words in both languages).
_* : RegExp → RegExp -- Infinite concatenations language (Consisting of the words concatenated with themselves any number of times).
-- Non-empty infinite concatenations language.
_+ : RegExp → RegExp
e + = e ++ (e *)
-- Optional expression language
_?? : RegExp → RegExp
e ?? = ε ‖ e
-- Finitely repeated expression language
exactly : ℕ → RegExp → RegExp
exactly 𝟎 e = ε
exactly (𝐒(n)) e = e ++ (exactly n e)
-- Minimum repetitions of an expression language
at-least : ℕ → RegExp → RegExp
at-least 𝟎 e = e *
at-least (𝐒(n)) e = e ++ (at-least n e)
-- Maximum repetitions of an expression language
at-most : ℕ → RegExp → RegExp
at-most 𝟎 e = ε
at-most (𝐒(n)) e = ε ‖ (e ++ (at-most n e))
-- Relation for whether a pattern/expression matches a word (whether the word is in the language that the pattern/expression describes).
data _matches_ : RegExp → List(Σ) → Stmt{ℓ} where
empty-word : ε matches List.∅
concatenation : ∀{r₁ r₂}{l₁ l₂} → (r₁ matches l₁) → (r₂ matches l₂) → ((r₁ ++ r₂) matches (l₁ List.++ l₂))
disjunctionₗ : ∀{rₗ rᵣ}{l} → (rₗ matches l) → ((rₗ ‖ rᵣ) matches l)
disjunctionᵣ : ∀{rₗ rᵣ}{l} → (rᵣ matches l) → ((rₗ ‖ rᵣ) matches l)
iteration : ∀{r}{l₁ l₂} → (r matches l₁) → ((r *) matches l₂) → ((r *) matches (l₁ List.++ l₂))
literal : ∀{a} → ((• a) matches List.singleton(a))
-- optional-empty : ∀{e} → ((e ??) matches List.∅)
pattern optional-empty = disjunctionₗ empty-word
optional-self : ∀{e}{l} → (e matches l) → ((e ??) matches l)
optional-self = disjunctionᵣ
empty-none : ∀{l} → ¬(∅ matches l)
empty-none ()
module _ ⦃ _ : ComputablyDecidable(_≡_) ⦄ where
language : RegExp → Language(Σ)
language ∅ = Oper.∅
language ε = Oper.ε
language (• x) = Oper.single x
language (x ++ y) = language(x) Oper.𝁼 language(y)
language (x ‖ y) = language(x) Oper.∪ language(y)
language (x *) = language(x) Oper.*
postulate matches-language : ∀{e}{l} → (e matches l) → (l Oper.∈ language(e))
{-matches-language {ε} {List.∅} empty-word = [⊤]-intro
matches-language {• a} {.a List.⊰ .List.∅} literal = {!!}
matches-language {e₁ ++ e₂} {List.∅} p = {!!}
matches-language {e₁ ++ e₂} {x List.⊰ l} p = {!!}
matches-language {e₁ ‖ e₂} {List.∅} (disjunctionₗ p) = IsTrue.[∨]-introₗ(matches-language {e₁} p)
matches-language {e₁ ‖ e₂} {List.∅} (disjunctionᵣ p) = IsTrue.[∨]-introᵣ(matches-language {e₂} p)
matches-language {e₁ ‖ e₂} {x List.⊰ l} (disjunctionₗ p) = [↔]-to-[←] ([∪]-containment {x = x List.⊰ l}{A = language(e₁)}{B = language(e₂)}) ([∨]-introₗ (matches-language {e₁} p))
matches-language {e₁ ‖ e₂} {x List.⊰ l} (disjunctionᵣ p) = [↔]-to-[←] ([∪]-containment {x = x List.⊰ l}{A = language(e₁)}{B = language(e₂)}) ([∨]-introᵣ (matches-language {e₂} p))
matches-language {e *} {List.∅} p = {!!}
matches-language {e *} {x List.⊰ l} p = {!!}
-}
postulate language-matches : ∀{e}{l} → (l Oper.∈ language(e)) → (e matches l)
{-language-matches {∅} {x List.⊰ l} p with () ← language-matches {∅} {l} p
language-matches {ε} {List.∅} [⊤]-intro = empty-word
language-matches {ε} {x List.⊰ l} p with () ← [↔]-to-[→] ([ε]-containment {x = x List.⊰ l}) p
language-matches {• a} {x List.⊰ l} p with [≡]-intro ← [↔]-to-[→] (single-containment {x = x List.⊰ l}) p = literal
language-matches {e₁ ++ e₂} {List.∅} p = {!!}
language-matches {e₁ ++ e₂} {x List.⊰ l} p = {!!}
language-matches {e₁ ‖ e₂} {l} p = [∨]-elim (disjunctionₗ ∘ language-matches) (disjunctionᵣ ∘ language-matches) ([↔]-to-[→] ([∪]-containment {x = l} {A = language(e₁)} {B = language(e₂)}) p)
language-matches {e *} {List.∅} [⊤]-intro = {![*]-containment!}
language-matches {e *} {x List.⊰ l} p = {!!}
-}
| 46.525253
| 193
| 0.616153
|
0e036e3b65998f1899638ae78af17c9f2af3a975
| 3,188
|
agda
|
Agda
|
src/Categories/Category/Construction/Properties/EilenbergMoore.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Construction/Properties/EilenbergMoore.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Construction/Properties/EilenbergMoore.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.Properties.EilenbergMoore where
open import Level
import Relation.Binary.PropositionalEquality as ≡
open import Categories.Adjoint
open import Categories.Adjoint.Properties
open import Categories.Category
open import Categories.Functor using (Functor; _∘F_)
open import Categories.Functor.Equivalence
open import Categories.Monad
open import Categories.NaturalTransformation renaming (id to idN)
open import Categories.Morphism.HeterogeneousIdentity
open import Categories.Adjoint.Construction.EilenbergMoore
open import Categories.Category.Construction.EilenbergMoore
private
variable
o ℓ e : Level
𝒞 𝒟 : Category o ℓ e
module _ {F : Functor 𝒞 𝒟} {G : Functor 𝒟 𝒞} (F⊣G : Adjoint F G) where
private
T : Monad 𝒞
T = adjoint⇒monad F⊣G
𝒞ᵀ : Category _ _ _
𝒞ᵀ = EilenbergMoore T
module 𝒞 = Category 𝒞
module 𝒟 = Category 𝒟
module 𝒞ᵀ = Category 𝒞ᵀ
open 𝒞.HomReasoning
module T = Monad T
module F = Functor F
module G = Functor G
open Adjoint F⊣G
open NaturalTransformation
-- Maclane's Comparison Functor
ComparisonF : Functor 𝒟 𝒞ᵀ
ComparisonF = record
{ F₀ = λ X → record
{ A = G.F₀ X
; action = G.F₁ (counit.η X)
; commute = commute (G ∘ˡ counit) (counit.η X)
; identity = zag
}
; F₁ = λ {A} {B} f → record
{ arr = G.F₁ f
; commute = begin
𝒞 [ G.F₁ f ∘ G.F₁ (counit.η A) ] ≈˘⟨ G.homomorphism ⟩
G.F₁ (𝒟 [ f ∘ (counit.η A) ]) ≈˘⟨ G.F-resp-≈ (counit.commute f) ⟩
G.F₁ (𝒟 [ counit.η B ∘ F.F₁ (G.F₁ f) ]) ≈⟨ G.homomorphism ⟩
𝒞 [ G.F₁ (counit.η B) ∘ G.F₁ (F.F₁ (G.F₁ f)) ] ∎
}
; identity = G.identity
; homomorphism = G.homomorphism
; F-resp-≈ = G.F-resp-≈
}
private
K = ComparisonF
module K = Functor K
module Gᵀ = Functor (Forgetful T)
module Fᵀ = Functor (Free T)
Comparison∘F≡Free : (ComparisonF ∘F F) ≡F Free T
Comparison∘F≡Free = record
{ eq₀ = λ X → ≡.refl
; eq₁ = λ {A} {B} f → begin
Module⇒.arr (𝒞ᵀ [ (hid 𝒞ᵀ ≡.refl) ∘ K.F₁ (F.F₁ f) ]) ≈⟨ hid-refl 𝒞ᵀ {A = K.F₀ (F.F₀ B)} ⟩∘⟨refl ⟩
Module⇒.arr (𝒞ᵀ [ 𝒞ᵀ.id ∘ K.F₁ (F.F₁ f) ]) ≈⟨ 𝒞.identityˡ {f = Module⇒.arr (K.F₁ (F.F₁ f))} ⟩
Module⇒.arr (K.F₁ (F.F₁ f)) ≈⟨ refl ⟩
Module⇒.arr (Fᵀ.F₁ f) ≈˘⟨ 𝒞ᵀ.identityʳ {f = Fᵀ.F₁ f} ⟩
Module⇒.arr (𝒞ᵀ [ Fᵀ.F₁ f ∘ 𝒞ᵀ.id ]) ≈˘⟨ refl⟩∘⟨ hid-refl 𝒞ᵀ {A = Fᵀ.F₀ A} ⟩
Module⇒.arr (𝒞ᵀ [ Fᵀ.F₁ f ∘ (hid 𝒞ᵀ ≡.refl) ]) ∎
}
Forgetful∘ComparisonF≡G : (Forgetful T ∘F ComparisonF) ≡F G
Forgetful∘ComparisonF≡G = record
{ eq₀ = λ X → ≡.refl
; eq₁ = λ f → begin
𝒞 [ (hid 𝒞 ≡.refl) ∘ (Gᵀ.F₁ (K.F₁ f)) ] ≈⟨ hid-refl 𝒞 ⟩∘⟨refl ⟩
𝒞 [ 𝒞.id ∘ (Gᵀ.F₁ (K.F₁ f)) ] ≈⟨ 𝒞.identityˡ ⟩
(Gᵀ.F₁ (K.F₁ f)) ≈⟨ refl ⟩
G.F₁ f ≈˘⟨ 𝒞.identityʳ ⟩
𝒞 [ G.F₁ f ∘ 𝒞.id ] ≈˘⟨ refl⟩∘⟨ hid-refl 𝒞 ⟩
𝒞 [ G.F₁ f ∘ (hid 𝒞 ≡.refl) ] ∎
}
| 32.865979
| 109
| 0.54611
|
df70cc3b22ad6f966f8fece1d8d62832cba0d98c
| 701
|
agda
|
Agda
|
Cubical/Algebra/Group.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/Group.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/Group.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group where
open import Cubical.Algebra.Group.Base public
open import Cubical.Algebra.Group.Properties public
open import Cubical.Algebra.Group.GroupPath public
open import Cubical.Algebra.Group.DirProd public
open import Cubical.Algebra.Group.Morphisms public
open import Cubical.Algebra.Group.MorphismProperties public
open import Cubical.Algebra.Group.Subgroup public
open import Cubical.Algebra.Group.QuotientGroup public
open import Cubical.Algebra.Group.IsomorphismTheorems public
open import Cubical.Algebra.Group.Instances.Unit public
open import Cubical.Algebra.Group.Instances.Bool public
open import Cubical.Algebra.Group.Instances.Int public
| 43.8125
| 60
| 0.850214
|
396b67cf9a8a2d0eacb972062a0c2f3c856a57c5
| 1,221
|
agda
|
Agda
|
UniDB/Morph/Sub.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Morph/Sub.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Morph/Sub.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
module UniDB.Morph.Sub where
open import UniDB.Spec
open import UniDB.Morph.Depth
--------------------------------------------------------------------------------
data Single (T : STX) : MOR where
single : {γ : Dom} (t : T γ) → Single T (suc γ) γ
instance
iLkSingle : {T : STX} {{vrT : Vr T}} → Lk T (Single T)
lk {{iLkSingle {T}}} (single t) zero = t
lk {{iLkSingle {T}}} (single t) (suc i) = vr {T} i
iBetaSingle : {T : STX} → Beta T (Single T)
beta {{iBetaSingle}} = single
--------------------------------------------------------------------------------
data Sub (T : STX) : MOR where
sub : {γ₁ γ₂ : Dom} (ξ : Depth (Single T) γ₁ γ₂) → Sub T γ₁ γ₂
module _ {T : STX} where
instance
iLkSub : {{vrT : Vr T}} {{wkT : Wk T}} → Lk T (Sub T)
lk {{iLkSub}} (sub ξ) = lk {T} {Depth (Single T)} ξ
iUpSub : Up (Sub T)
_↑₁ {{iUpSub}} (sub ζ) = sub (ζ ↑₁)
_↑_ {{iUpSub}} ξ 0 = ξ
_↑_ {{iUpSub}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁
↑-zero {{iUpSub}} ξ = refl
↑-suc {{iUpSub}} ξ δ = refl
iBetaSub : Beta T (Sub T)
beta {{iBetaSub}} t = sub (beta {T} {Depth (Single T)} t)
--------------------------------------------------------------------------------
| 29.780488
| 80
| 0.425061
|
50c15cb11047053e46158876d8264abf94666c2a
| 9,554
|
agda
|
Agda
|
Cubical/Experiments/ZariskiLatticeBasicOpens.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Experiments/ZariskiLatticeBasicOpens.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/ZariskiLatticeBasicOpens.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Experiments.ZariskiLatticeBasicOpens where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Poset
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.CommRing.Localisation.InvertingElements
open import Cubical.Algebra.CommAlgebra.Base
open import Cubical.Algebra.CommAlgebra.Properties
open import Cubical.Algebra.CommAlgebra.Localisation
open import Cubical.Algebra.RingSolver.Reflection
open import Cubical.Algebra.Semilattice
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
open BinaryRelation
open isEquivRel
private
variable
ℓ ℓ' : Level
module Presheaf (A' : CommRing ℓ) where
open CommRingStr (snd A') renaming (_·_ to _·r_ ; ·Comm to ·r-comm ; ·Assoc to ·rAssoc
; ·Lid to ·rLid ; ·Rid to ·rRid)
open Exponentiation A'
open CommRingTheory A'
open InvertingElementsBase A'
open isMultClosedSubset
open CommAlgebraStr ⦃...⦄
private
A = fst A'
A[1/_] : A → CommAlgebra A' ℓ
A[1/ x ] = AlgLoc.S⁻¹RAsCommAlg A' [ x ⁿ|n≥0] (powersFormMultClosedSubset _)
A[1/_]ˣ : (x : A) → ℙ (fst A[1/ x ])
A[1/ x ]ˣ = (CommAlgebra→CommRing A[1/ x ]) ˣ
_≼_ : A → A → Type ℓ
x ≼ y = ∃[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y -- rad(x) ⊆ rad(y)
-- ≼ is a pre-order:
Refl≼ : isRefl _≼_
Refl≼ x = PT.∣ 1 , 1r , ·r-comm _ _ ∣
Trans≼ : isTrans _≼_
Trans≼ x y z = map2 Trans≼Σ
where
Trans≼Σ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] y ^ n ≡ a ·r z
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r z
Trans≼Σ (n , a , p) (m , b , q) = n ·ℕ m , (a ^ m ·r b) , path
where
path : x ^ (n ·ℕ m) ≡ a ^ m ·r b ·r z
path = x ^ (n ·ℕ m) ≡⟨ ^-rdist-·ℕ x n m ⟩
(x ^ n) ^ m ≡⟨ cong (_^ m) p ⟩
(a ·r y) ^ m ≡⟨ ^-ldist-· a y m ⟩
a ^ m ·r y ^ m ≡⟨ cong (a ^ m ·r_) q ⟩
a ^ m ·r (b ·r z) ≡⟨ ·rAssoc _ _ _ ⟩
a ^ m ·r b ·r z ∎
R : A → A → Type ℓ
R x y = x ≼ y × y ≼ x -- rad(x) ≡ rad(y)
RequivRel : isEquivRel R
RequivRel .reflexive x = Refl≼ x , Refl≼ x
RequivRel .symmetric _ _ Rxy = (Rxy .snd) , (Rxy .fst)
RequivRel .transitive _ _ _ Rxy Ryz = Trans≼ _ _ _ (Rxy .fst) (Ryz .fst)
, Trans≼ _ _ _ (Ryz .snd) (Rxy .snd)
RpropValued : isPropValued R
RpropValued x y = isProp× isPropPropTrunc isPropPropTrunc
powerIs≽ : (x a : A) → x ∈ [ a ⁿ|n≥0] → a ≼ x
powerIs≽ x a = map powerIs≽Σ
where
powerIs≽Σ : Σ[ n ∈ ℕ ] (x ≡ a ^ n) → Σ[ n ∈ ℕ ] Σ[ z ∈ A ] (a ^ n ≡ z ·r x)
powerIs≽Σ (n , p) = n , 1r , sym p ∙ sym (·rLid _)
module ≼ToLoc (x y : A) where
private
instance
_ = snd A[1/ x ]
lemma : x ≼ y → y ⋆ 1a ∈ A[1/ x ]ˣ -- y/1 ∈ A[1/x]ˣ
lemma = PT.rec (A[1/ x ]ˣ (y ⋆ 1a) .snd) lemmaΣ
where
path1 : (y z : A) → 1r ·r (y ·r 1r ·r z) ·r 1r ≡ z ·r y
path1 = solve A'
path2 : (xn : A) → xn ≡ 1r ·r 1r ·r (1r ·r 1r ·r xn)
path2 = solve A'
lemmaΣ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y → y ⋆ 1a ∈ A[1/ x ]ˣ
lemmaΣ (n , z , p) = [ z , (x ^ n) , PT.∣ n , refl ∣ ] -- xⁿ≡zy → y⁻¹ ≡ z/xⁿ
, eq/ _ _ ((1r , powersFormMultClosedSubset _ .containsOne)
, (path1 _ _ ∙∙ sym p ∙∙ path2 _))
module ≼PowerToLoc (x y : A) (x≼y : x ≼ y) where
private
[yⁿ|n≥0] = [ y ⁿ|n≥0]
instance
_ = snd A[1/ x ]
lemma : ∀ (s : A) → s ∈ [yⁿ|n≥0] → s ⋆ 1a ∈ A[1/ x ]ˣ
lemma _ s∈[yⁿ|n≥0] = ≼ToLoc.lemma _ _ (Trans≼ _ y _ x≼y (powerIs≽ _ _ s∈[yⁿ|n≥0]))
𝓞ᴰ : A / R → CommAlgebra A' ℓ
𝓞ᴰ = rec→Gpd.fun isGroupoidCommAlgebra (λ a → A[1/ a ]) RCoh LocPathProp
where
RCoh : ∀ a b → R a b → A[1/ a ] ≡ A[1/ b ]
RCoh a b (a≼b , b≼a) = fst (isContrS₁⁻¹R≡S₂⁻¹R (≼PowerToLoc.lemma _ _ b≼a)
(≼PowerToLoc.lemma _ _ a≼b))
where
open AlgLocTwoSubsets A' [ a ⁿ|n≥0] (powersFormMultClosedSubset _)
[ b ⁿ|n≥0] (powersFormMultClosedSubset _)
LocPathProp : ∀ a b → isProp (A[1/ a ] ≡ A[1/ b ])
LocPathProp a b = isPropS₁⁻¹R≡S₂⁻¹R
where
open AlgLocTwoSubsets A' [ a ⁿ|n≥0] (powersFormMultClosedSubset _)
[ b ⁿ|n≥0] (powersFormMultClosedSubset _)
-- The quotient A/R corresponds to the basic opens of the Zariski topology.
-- Multiplication lifts to the quotient and corresponds to intersection
-- of basic opens, i.e. we get a meet-semilattice with:
_∧/_ : A / R → A / R → A / R
_∧/_ = setQuotSymmBinOp (RequivRel .reflexive) (RequivRel .transitive) _·r_
(λ a b → subst (λ x → R (a ·r b) x) (·r-comm a b) (RequivRel .reflexive (a ·r b))) ·r-lcoh
where
·r-lcoh-≼ : (x y z : A) → x ≼ y → (x ·r z) ≼ (y ·r z)
·r-lcoh-≼ x y z = map ·r-lcoh-≼Σ
where
path : (x z a y zn : A) → x ·r z ·r (a ·r y ·r zn) ≡ x ·r zn ·r a ·r (y ·r z)
path = solve A'
·r-lcoh-≼Σ : Σ[ n ∈ ℕ ] Σ[ a ∈ A ] x ^ n ≡ a ·r y
→ Σ[ n ∈ ℕ ] Σ[ a ∈ A ] (x ·r z) ^ n ≡ a ·r (y ·r z)
·r-lcoh-≼Σ (n , a , p) = suc n , (x ·r z ^ n ·r a) , (cong (x ·r z ·r_) (^-ldist-· _ _ _)
∙∙ cong (λ v → x ·r z ·r (v ·r z ^ n)) p
∙∙ path _ _ _ _ _)
·r-lcoh : (x y z : A) → R x y → R (x ·r z) (y ·r z)
·r-lcoh x y z Rxy = ·r-lcoh-≼ x y z (Rxy .fst) , ·r-lcoh-≼ y x z (Rxy .snd)
BasicOpens : Semilattice ℓ
BasicOpens = makeSemilattice [ 1r ] _∧/_ squash/
(elimProp3 (λ _ _ _ → squash/ _ _) λ _ _ _ → cong [_] (·rAssoc _ _ _))
(elimProp (λ _ → squash/ _ _) λ _ → cong [_] (·rRid _))
(elimProp (λ _ → squash/ _ _) λ _ → cong [_] (·rLid _))
(elimProp2 (λ _ _ → squash/ _ _) λ _ _ → cong [_] (·r-comm _ _))
(elimProp (λ _ → squash/ _ _) λ a → eq/ _ _ -- R a a²
(∣ 1 , a , ·rRid _ ∣ , ∣ 2 , 1r , cong (a ·r_) (·rRid a) ∙ sym (·rLid _) ∣))
-- The induced partial order
open MeetSemilattice BasicOpens renaming (_≤_ to _≼/_ ; IndPoset to BasicOpensAsPoset)
-- coincides with our ≼
≼/CoincidesWith≼ : ∀ (x y : A) → ([ x ] ≼/ [ y ]) ≡ (x ≼ y)
≼/CoincidesWith≼ x y = [ x ] ≼/ [ y ] -- ≡⟨ refl ⟩ [ x ·r y ] ≡ [ x ]
≡⟨ isoToPath (isEquivRel→effectiveIso RpropValued RequivRel _ _) ⟩
R (x ·r y) x
≡⟨ isoToPath Σ-swap-Iso ⟩
R x (x ·r y)
≡⟨ hPropExt (RpropValued _ _) isPropPropTrunc ·To≼ ≼To· ⟩
x ≼ y ∎
where
x≼xy→x≼yΣ : Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r (x ·r y)
→ Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y
x≼xy→x≼yΣ (n , z , p) = n , (z ·r x) , p ∙ ·rAssoc _ _ _
·To≼ : R x (x ·r y) → x ≼ y
·To≼ (x≼xy , _) = PT.map x≼xy→x≼yΣ x≼xy
x≼y→x≼xyΣ : Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r y
→ Σ[ n ∈ ℕ ] Σ[ z ∈ A ] x ^ n ≡ z ·r (x ·r y)
x≼y→x≼xyΣ (n , z , p) = suc n , z , cong (x ·r_) p ∙ ·CommAssocl _ _ _
≼To· : x ≼ y → R x ( x ·r y)
≼To· x≼y = PT.map x≼y→x≼xyΣ x≼y , PT.∣ 1 , y , ·rRid _ ∙ ·r-comm _ _ ∣
open IsPoset
open PosetStr
Refl≼/ : isRefl _≼/_
Refl≼/ = BasicOpensAsPoset .snd .isPoset .is-refl
Trans≼/ : isTrans _≼/_
Trans≼/ = BasicOpensAsPoset .snd .isPoset .is-trans
-- The restrictions:
ρᴰᴬ : (a b : A) → a ≼ b → isContr (CommAlgebraHom A[1/ b ] A[1/ a ])
ρᴰᴬ _ b a≼b = A[1/b]HasUniversalProp _ (≼PowerToLoc.lemma _ _ a≼b)
where
open AlgLoc A' [ b ⁿ|n≥0] (powersFormMultClosedSubset _)
renaming (S⁻¹RHasAlgUniversalProp to A[1/b]HasUniversalProp)
ρᴰᴬId : ∀ (a : A) (r : a ≼ a) → ρᴰᴬ a a r .fst ≡ idAlgHom
ρᴰᴬId a r = ρᴰᴬ a a r .snd _
ρᴰᴬComp : ∀ (a b c : A) (l : a ≼ b) (m : b ≼ c)
→ ρᴰᴬ a c (Trans≼ _ _ _ l m) .fst ≡ ρᴰᴬ a b l .fst ∘a ρᴰᴬ b c m .fst
ρᴰᴬComp a _ c l m = ρᴰᴬ a c (Trans≼ _ _ _ l m) .snd _
ρᴰ : (x y : A / R) → x ≼/ y → CommAlgebraHom (𝓞ᴰ y) (𝓞ᴰ x)
ρᴰ = elimContr2 λ _ _ → isContrΠ
λ [a]≼/[b] → ρᴰᴬ _ _ (transport (≼/CoincidesWith≼ _ _) [a]≼/[b])
ρᴰId : ∀ (x : A / R) (r : x ≼/ x) → ρᴰ x x r ≡ idAlgHom
ρᴰId = SQ.elimProp (λ _ → isPropΠ (λ _ → isSetAlgebraHom _ _ _ _))
λ a r → ρᴰᴬId a (transport (≼/CoincidesWith≼ _ _) r)
ρᴰComp : ∀ (x y z : A / R) (l : x ≼/ y) (m : y ≼/ z)
→ ρᴰ x z (Trans≼/ _ _ _ l m) ≡ ρᴰ x y l ∘a ρᴰ y z m
ρᴰComp = SQ.elimProp3 (λ _ _ _ → isPropΠ2 (λ _ _ → isSetAlgebraHom _ _ _ _))
λ a b c _ _ → sym (ρᴰᴬ a c _ .snd _) ∙ ρᴰᴬComp a b c _ _
| 38.216
| 100
| 0.534227
|
5005a7b9cc66989d06c91cc09f047d442b633a9b
| 402
|
agda
|
Agda
|
test/Fail/Issue2494-pattern-hidden.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2494-pattern-hidden.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2494-pattern-hidden.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-04-13, issue #2494, reported by identicalsnowflake
-- Consecutive hidden record fields confused the implicit argument insertion
-- due to lack of names in NamedArg.
-- {-# OPTIONS -v tc.lhs:30 #-}
-- {-# OPTIONS -v tc.term.args:100 #-}
postulate
Red Blue : Set
record Colors : Set where
field
{red} : Red
{blue} : Blue
f : Colors → Red
f record { blue = blue } = blue
| 22.333333
| 76
| 0.661692
|
200900d2055a70a81ac744d3bb2a882c7c2626cc
| 83
|
agda
|
Agda
|
archive/agda-1/Prologue.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/Prologue.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/Prologue.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Prologue where
open import Relation.Binary.Core
open IsEquivalence ⦃ … ⦄
| 11.857143
| 32
| 0.771084
|
1cfbb93b620f0232fea3e6c0a1027b498c1cbd41
| 346
|
agda
|
Agda
|
test/succeed/TelescopingLet5.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/TelescopingLet5.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
test/succeed/TelescopingLet5.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
module TelescopingLet5 where
postulate
A : Set
a : A
module B (a : A) where
postulate
C : Set
-- B.C : (a : A) → Set
module N = B a
module M' (open N) (c : C) where
postulate cc : C
-- M.cc : (a : B.A a) → B.A a
E = let open B a in C
module M (open B a) (x : A) where
D = C
postulate cc : C
-- M.cc : (a : B.A a) → B.A a
| 13.84
| 33
| 0.526012
|
50dfa2e9b1231a2910be0570424c8c4cbc1d7acb
| 201
|
agda
|
Agda
|
Cubical/HITs/Modulo.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/HITs/Modulo.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/HITs/Modulo.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.HITs.Modulo where
open import Cubical.HITs.Modulo.Base public
open import Cubical.HITs.Modulo.Properties public
open import Cubical.HITs.Modulo.FinEquiv public
| 22.333333
| 49
| 0.79602
|
cbd245ea512ae0a440fdcead7e60e43266b0b957
| 1,735
|
agda
|
Agda
|
Decidable/Relations.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Decidable/Relations.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Decidable/Relations.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Decidable.Relations where
DecidableRelation : {a b : _} {A : Set a} (f : A → Set b) → Set (a ⊔ b)
DecidableRelation {A = A} f = (x : A) → (f x) || (f x → False)
orDecidable : {a b c : _} {A : Set a} {f : A → Set b} {g : A → Set c} → DecidableRelation f → DecidableRelation g → DecidableRelation (λ x → (f x) || (g x))
orDecidable fDec gDec x with fDec x
orDecidable fDec gDec x | inl fx = inl (inl fx)
orDecidable fDec gDec x | inr !fx with gDec x
orDecidable fDec gDec x | inr !fx | inl gx = inl (inr gx)
orDecidable {f = f} {g} fDec gDec x | inr !fx | inr !gx = inr t
where
t : (f x || g x) → False
t (inl x) = !fx x
t (inr x) = !gx x
andDecidable : {a b c : _} {A : Set a} {f : A → Set b} {g : A → Set c} → DecidableRelation f → DecidableRelation g → DecidableRelation (λ x → (f x) && (g x))
andDecidable fDec gDec x with fDec x
andDecidable fDec gDec x | inl fx with gDec x
andDecidable fDec gDec x | inl fx | inl gx = inl (fx ,, gx)
andDecidable fDec gDec x | inl fx | inr !gx = inr (λ x → !gx (_&&_.snd x))
andDecidable fDec gDec x | inr !fx = inr (λ x → !fx (_&&_.fst x))
notDecidable : {a b : _} {A : Set a} {f : A → Set b} → DecidableRelation f → DecidableRelation (λ x → (f x) → False)
notDecidable fDec x with fDec x
notDecidable fDec x | inl fx = inr (λ x → x fx)
notDecidable fDec x | inr !fx = inl !fx
doubleNegation : {a b : _} {A : Set a} {f : A → Set b} → DecidableRelation f → (x : A) → (((f x) → False) → False) → f x
doubleNegation fDec x with fDec x
doubleNegation fDec x | inl fx = λ _ → fx
doubleNegation fDec x | inr !fx = λ p → exFalso (p !fx)
| 45.657895
| 157
| 0.61902
|
1ce845593e3ec3bb26039ecf3b14153bd0997cf1
| 8,512
|
agda
|
Agda
|
Groups/SymmetricGroups/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Groups/SymmetricGroups/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Groups/SymmetricGroups/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Setoids.Setoids
open import Groups.Definition
open import Groups.Lemmas
open import Groups.Homomorphisms.Definition
open import Groups.QuotientGroup.Definition
open import Groups.Homomorphisms.Lemmas
open import Groups.Actions.Definition
open import Sets.EquivalenceRelations
module Groups.SymmetricGroups.Lemmas where
trivialAction : {m n o p : _} {A : Set m} {S : Setoid {m} {o} A} {_·_ : A → A → A} {B : Set n} (G : Group S _·_) (X : Setoid {n} {p} B) → GroupAction G X
trivialAction G X = record { action = λ _ x → x ; actionWellDefined1 = λ _ → reflexive ; actionWellDefined2 = λ wd1 → wd1 ; identityAction = reflexive ; associativeAction = reflexive }
where
open Setoid X renaming (eq to setoidEq)
open Equivalence (Setoid.eq X)
leftRegularAction : {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_·_ : A → A → A} (G : Group S _·_) → GroupAction G S
GroupAction.action (leftRegularAction {_·_ = _·_} G) g h = g · h
where
open Group G
GroupAction.actionWellDefined1 (leftRegularAction {S = S} G) eq1 = +WellDefined eq1 reflexive
where
open Group G
open Setoid S renaming (eq to setoidEq)
open Equivalence setoidEq
GroupAction.actionWellDefined2 (leftRegularAction {S = S} G) {g} {x} {y} eq1 = +WellDefined reflexive eq1
where
open Group G
open Setoid S
open Equivalence eq
GroupAction.identityAction (leftRegularAction G) = identLeft
where
open Group G
GroupAction.associativeAction (leftRegularAction {S = S} G) = symmetric +Associative
where
open Group G
open Setoid S
open Equivalence eq
conjugationAction : {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_·_ : A → A → A} → (G : Group S _·_) → GroupAction G S
conjugationAction {S = S} {_·_ = _·_} G = record { action = λ g h → (g · h) · (inverse g) ; actionWellDefined1 = λ gh → +WellDefined (+WellDefined gh reflexive) (inverseWellDefined G gh) ; actionWellDefined2 = λ x~y → +WellDefined (+WellDefined reflexive x~y) reflexive ; identityAction = transitive (+WellDefined reflexive (invIdent G)) (transitive identRight identLeft) ; associativeAction = λ {x} {g} {h} → transitive (+WellDefined reflexive (invContravariant G)) (transitive +Associative (+WellDefined (transitive (symmetric +Associative) (transitive (symmetric (+Associative)) (+WellDefined reflexive +Associative))) reflexive)) }
where
open Group G
open Setoid S
open Equivalence eq
conjugationNormalSubgroupAction : {m n o p : _} {A : Set m} {B : Set o} {S : Setoid {m} {n} A} {T : Setoid {o} {p} B} {_·A_ : A → A → A} {_·B_ : B → B → B} → (G : Group S _·A_) → (H : Group T _·B_) → {underF : A → B} (f : GroupHom G H underF) → GroupAction G (quotientGroupSetoid G f)
GroupAction.action (conjugationNormalSubgroupAction {_·A_ = _·A_} G H {f} fHom) a b = a ·A (b ·A (Group.inverse G a))
GroupAction.actionWellDefined1 (conjugationNormalSubgroupAction {S = S} {T = T} {_·A_ = _·A_} G H {f} fHom) {g} {h} {x} g~h = ans
where
open Group G
open Setoid T
open Equivalence eq
ans : f ((g ·A (x ·A (inverse g))) ·A inverse (h ·A (x ·A inverse h))) ∼ Group.0G H
ans = transitive (GroupHom.wellDefined fHom (transferToRight'' G (Group.+WellDefined G g~h (Group.+WellDefined G (Equivalence.reflexive (Setoid.eq S)) (inverseWellDefined G g~h))))) (imageOfIdentityIsIdentity fHom)
GroupAction.actionWellDefined2 (conjugationNormalSubgroupAction {S = S} {T = T} {_·A_ = _·A_} {_·B_ = _·B_} G H {f} fHom) {g} {x} {y} x~y = ans
where
open Group G
open Setoid T
open Equivalence (Setoid.eq S)
open Equivalence (Setoid.eq T) renaming (transitive to transitiveH ; symmetric to symmetricH ; reflexive to reflexiveH)
input : f (x ·A inverse y) ∼ Group.0G H
input = x~y
p1 : Setoid._∼_ S ((g ·A (x ·A inverse g)) ·A inverse (g ·A (y ·A inverse g))) ((g ·A (x ·A inverse g)) ·A (inverse (y ·A (inverse g)) ·A inverse g))
p1 = Group.+WellDefined G reflexive (invContravariant G)
p2 : Setoid._∼_ S ((g ·A (x ·A inverse g)) ·A (inverse (y ·A (inverse g)) ·A inverse g)) ((g ·A (x ·A inverse g)) ·A ((inverse (inverse g) ·A inverse y) ·A inverse g))
p2 = Group.+WellDefined G reflexive (Group.+WellDefined G (invContravariant G) reflexive)
p3 : Setoid._∼_ S ((g ·A (x ·A inverse g)) ·A ((inverse (inverse g) ·A inverse y) ·A inverse g)) (g ·A (((x ·A inverse g) ·A (inverse (inverse g) ·A inverse y)) ·A inverse g))
p3 = symmetric (transitive (+WellDefined reflexive (symmetric +Associative)) +Associative)
p4 : Setoid._∼_ S (g ·A (((x ·A inverse g) ·A (inverse (inverse g) ·A inverse y)) ·A inverse g)) (g ·A ((x ·A ((inverse g ·A inverse (inverse g)) ·A inverse y)) ·A inverse g))
p4 = Group.+WellDefined G reflexive (Group.+WellDefined G (symmetric (transitive (+WellDefined reflexive (symmetric +Associative)) +Associative)) reflexive)
p5 : Setoid._∼_ S (g ·A ((x ·A ((inverse g ·A inverse (inverse g)) ·A inverse y)) ·A inverse g)) (g ·A ((x ·A (0G ·A inverse y)) ·A inverse g))
p5 = Group.+WellDefined G reflexive (Group.+WellDefined G (Group.+WellDefined G reflexive (Group.+WellDefined G invRight reflexive)) reflexive)
p6 : Setoid._∼_ S (g ·A ((x ·A (0G ·A inverse y)) ·A inverse g)) (g ·A ((x ·A inverse y) ·A inverse g))
p6 = Group.+WellDefined G reflexive (Group.+WellDefined G (Group.+WellDefined G reflexive identLeft) reflexive)
intermediate : Setoid._∼_ S ((g ·A (x ·A inverse g)) ·A inverse (g ·A (y ·A inverse g))) (g ·A ((x ·A inverse y) ·A inverse g))
intermediate = transitive p1 (transitive p2 (transitive p3 (transitive p4 (transitive p5 p6))))
p7 : f ((g ·A (x ·A inverse g)) ·A inverse (g ·A (y ·A inverse g))) ∼ f (g ·A ((x ·A inverse y) ·A inverse g))
p7 = GroupHom.wellDefined fHom intermediate
p8 : f (g ·A ((x ·A inverse y) ·A inverse g)) ∼ (f g) ·B (f ((x ·A inverse y) ·A inverse g))
p8 = GroupHom.groupHom fHom
p9 : (f g) ·B (f ((x ·A inverse y) ·A inverse g)) ∼ (f g) ·B (f (x ·A inverse y) ·B f (inverse g))
p9 = Group.+WellDefined H reflexiveH (GroupHom.groupHom fHom)
p10 : (f g) ·B (f (x ·A inverse y) ·B f (inverse g)) ∼ (f g) ·B (Group.0G H ·B f (inverse g))
p10 = Group.+WellDefined H reflexiveH (Group.+WellDefined H input reflexiveH)
p11 : (f g) ·B (Group.0G H ·B f (inverse g)) ∼ (f g) ·B (f (inverse g))
p11 = Group.+WellDefined H reflexiveH (Group.identLeft H)
p12 : (f g) ·B (f (inverse g)) ∼ f (g ·A (inverse g))
p12 = symmetricH (GroupHom.groupHom fHom)
intermediate2 : f ((g ·A (x ·A inverse g)) ·A inverse (g ·A (y ·A inverse g))) ∼ (f (g ·A (inverse g)))
intermediate2 = transitiveH p7 (transitiveH p8 (transitiveH p9 (transitiveH p10 (transitiveH p11 p12))))
ans : f ((g ·A (x ·A inverse g)) ·A inverse (g ·A (y ·A inverse g))) ∼ Group.0G H
ans = transitiveH intermediate2 (transitiveH (GroupHom.wellDefined fHom invRight) (imageOfIdentityIsIdentity fHom))
GroupAction.identityAction (conjugationNormalSubgroupAction {S = S} {T = T} {_·A_ = _·A_} G H {f} fHom) {x} = ans
where
open Group G
open Setoid S
open Setoid T renaming (_∼_ to _∼T_)
open Equivalence (Setoid.eq T)
i : Setoid._∼_ S (x ·A inverse 0G) x
i = Equivalence.transitive (Setoid.eq S) (+WellDefined (Equivalence.reflexive (Setoid.eq S)) (invIdent G)) identRight
h : 0G ·A (x ·A inverse 0G) ∼ x
h = Equivalence.transitive (Setoid.eq S) identLeft i
g : ((0G ·A (x ·A inverse 0G)) ·A inverse x) ∼ 0G
g = transferToRight'' G h
ans : f ((0G ·A (x ·A inverse 0G)) ·A Group.inverse G x) ∼T Group.0G H
ans = transitive (GroupHom.wellDefined fHom g) (imageOfIdentityIsIdentity fHom)
GroupAction.associativeAction (conjugationNormalSubgroupAction {S = S} {T = T} {_·A_ = _·A_} G H {f} fHom) {x} {g} {h} = ans
where
open Group G
open Setoid T renaming (_∼_ to _∼T_)
open Setoid S renaming (_∼_ to _∼S_)
open Equivalence (Setoid.eq T) renaming (transitive to transitiveH)
open Equivalence (Setoid.eq S) renaming (transitive to transitiveG ; symmetric to symmetricG ; reflexive to reflexiveG)
ans : f (((g ·A h) ·A (x ·A inverse (g ·A h))) ·A inverse ((g ·A ((h ·A (x ·A inverse h)) ·A inverse g)))) ∼T Group.0G H
ans = transitiveH (GroupHom.wellDefined fHom (transferToRight'' G (transitiveG (symmetricG +Associative) (Group.+WellDefined G reflexiveG (transitiveG (+WellDefined reflexiveG (transitiveG (+WellDefined reflexiveG (invContravariant G)) +Associative)) +Associative))))) (imageOfIdentityIsIdentity fHom)
| 70.933333
| 636
| 0.661184
|
4a43393f430e40d0a428376652ffda7d75361dd9
| 5,978
|
agda
|
Agda
|
Cubical/Algebra/DistLattice/BigOps.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/DistLattice/BigOps.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/DistLattice/BigOps.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
-- define ⋁ and ⋀ as the bigOps of a Ring when interpreted
-- as an additive/multiplicative monoid
{-# OPTIONS --safe #-}
module Cubical.Algebra.DistLattice.BigOps where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ ; zero ; suc)
open import Cubical.Data.FinData
open import Cubical.Data.Bool hiding (_≤_)
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Monoid.BigOp
open import Cubical.Algebra.CommMonoid
open import Cubical.Algebra.Semilattice
open import Cubical.Algebra.Lattice
open import Cubical.Algebra.DistLattice
open import Cubical.Relation.Binary.Poset
private
variable
ℓ : Level
module KroneckerDelta (L' : DistLattice ℓ) where
private
L = fst L'
open DistLatticeStr (snd L')
δ : {n : ℕ} (i j : Fin n) → L
δ i j = if i == j then 1l else 0l
module Join (L' : DistLattice ℓ) where
private
L = fst L'
open DistLatticeStr (snd L')
open MonoidBigOp (Semilattice→Monoid (Lattice→JoinSemilattice (DistLattice→Lattice L')))
open LatticeTheory (DistLattice→Lattice L')
open KroneckerDelta L'
⋁ = bigOp
⋁Ext = bigOpExt
⋁0l = bigOpε
⋁Last = bigOpLast
⋁Split : ∀ {n} → (V W : FinVec L n) → ⋁ (λ i → V i ∨l W i) ≡ ⋁ V ∨l ⋁ W
⋁Split = bigOpSplit ∨lComm
⋁Meetrdist : ∀ {n} → (x : L) → (V : FinVec L n)
→ x ∧l ⋁ V ≡ ⋁ λ i → x ∧l V i
⋁Meetrdist {n = zero} x _ = 0lRightAnnihilates∧l x
⋁Meetrdist {n = suc n} x V =
x ∧l (V zero ∨l ⋁ (V ∘ suc)) ≡⟨ ∧lLdist∨l _ _ _ ⟩ --Ldist and Rdist wrong way around?
(x ∧l V zero) ∨l (x ∧l ⋁ (V ∘ suc)) ≡⟨ (λ i → (x ∧l V zero) ∨l ⋁Meetrdist x (V ∘ suc) i) ⟩
(x ∧l V zero) ∨l ⋁ (λ i → x ∧l V (suc i)) ∎
⋁Meetldist : ∀ {n} → (x : L) → (V : FinVec L n)
→ (⋁ V) ∧l x ≡ ⋁ λ i → V i ∧l x
⋁Meetldist {n = zero} x _ = 0lLeftAnnihilates∧l x
⋁Meetldist {n = suc n} x V =
(V zero ∨l ⋁ (V ∘ suc)) ∧l x ≡⟨ ∧lRdist∨l _ _ _ ⟩
(V zero ∧l x) ∨l ((⋁ (V ∘ suc)) ∧l x) ≡⟨ (λ i → (V zero ∧l x) ∨l ⋁Meetldist x (V ∘ suc) i) ⟩
(V zero ∧l x) ∨l ⋁ (λ i → V (suc i) ∧l x) ∎
⋁Meetr0 : ∀ {n} → (V : FinVec L n) → ⋁ (λ i → V i ∧l 0l) ≡ 0l
⋁Meetr0 V = sym (⋁Meetldist 0l V) ∙ 0lRightAnnihilates∧l _
⋁Meet0r : ∀ {n} → (V : FinVec L n) → ⋁ (λ i → 0l ∧l V i) ≡ 0l
⋁Meet0r V = sym (⋁Meetrdist 0l V) ∙ 0lLeftAnnihilates∧l _
⋁Meetr1 : (n : ℕ) (V : FinVec L n) → (j : Fin n) → ⋁ (λ i → V i ∧l δ i j) ≡ V j
⋁Meetr1 (suc n) V zero = (λ k → ∧lRid (V zero) k ∨l ⋁Meetr0 (V ∘ suc) k) ∙ ∨lRid (V zero)
⋁Meetr1 (suc n) V (suc j) =
(λ i → 0lRightAnnihilates∧l (V zero) i ∨l ⋁ (λ x → V (suc x) ∧l δ x j))
∙∙ ∨lLid _ ∙∙ ⋁Meetr1 n (V ∘ suc) j
⋁Meet1r : (n : ℕ) (V : FinVec L n) → (j : Fin n) → ⋁ (λ i → (δ j i) ∧l V i) ≡ V j
⋁Meet1r (suc n) V zero = (λ k → ∧lLid (V zero) k ∨l ⋁Meet0r (V ∘ suc) k) ∙ ∨lRid (V zero)
⋁Meet1r (suc n) V (suc j) =
(λ i → 0lLeftAnnihilates∧l (V zero) i ∨l ⋁ (λ i → (δ j i) ∧l V (suc i)))
∙∙ ∨lLid _ ∙∙ ⋁Meet1r n (V ∘ suc) j
-- inequalities of big joins
open JoinSemilattice (Lattice→JoinSemilattice (DistLattice→Lattice L'))
open PosetReasoning IndPoset
open PosetStr (IndPoset .snd) hiding (_≤_)
ind≤⋁ : {n : ℕ} (U : FinVec L n) (i : Fin n) → U i ≤ ⋁ U
ind≤⋁ {n = suc n} U zero = ∨≤RCancel _ _
ind≤⋁ {n = suc n} U (suc i) = is-trans _ (⋁ (U ∘ suc)) _ (ind≤⋁ (U ∘ suc) i) (∨≤LCancel _ _)
⋁IsMax : {n : ℕ} (U : FinVec L n) (x : L) → (∀ i → U i ≤ x) → ⋁ U ≤ x
⋁IsMax {n = zero} _ _ _ = ∨lLid _
⋁IsMax {n = suc n} U x U≤x =
⋁ U ≤⟨ is-refl _ ⟩
U zero ∨l ⋁ (U ∘ suc) ≤⟨ ≤-∨LPres _ _ _ (⋁IsMax _ _ (U≤x ∘ suc)) ⟩
U zero ∨l x ≤⟨ ∨lIsMax _ _ _ (U≤x zero) (is-refl x) ⟩
x ◾
≤-⋁Ext : {n : ℕ} (U W : FinVec L n) → (∀ i → U i ≤ W i) → ⋁ U ≤ ⋁ W
≤-⋁Ext {n = zero} U W U≤W = is-refl 0l
≤-⋁Ext {n = suc n} U W U≤W =
⋁ U ≤⟨ is-refl _ ⟩
U zero ∨l ⋁ (U ∘ suc) ≤⟨ ≤-∨Pres _ _ _ _ (U≤W zero) (≤-⋁Ext _ _ (U≤W ∘ suc)) ⟩
W zero ∨l ⋁ (W ∘ suc) ≤⟨ is-refl _ ⟩
⋁ W ◾
module Meet (L' : DistLattice ℓ) where
private
L = fst L'
open DistLatticeStr (snd L')
open MonoidBigOp (Semilattice→Monoid (Lattice→MeetSemilattice (DistLattice→Lattice L')))
-- extra DistLattice→MeetMonoid?
open LatticeTheory (DistLattice→Lattice L')
open KroneckerDelta L'
⋀ = bigOp
⋀Ext = bigOpExt
⋀1l = bigOpε
⋀Last = bigOpLast
⋀Split : ∀ {n} → (V W : FinVec L n) → ⋀ (λ i → V i ∧l W i) ≡ ⋀ V ∧l ⋀ W
⋀Split = bigOpSplit ∧lComm
⋀Joinrdist : ∀ {n} → (x : L) → (V : FinVec L n)
→ x ∨l ⋀ V ≡ ⋀ λ i → x ∨l V i
⋀Joinrdist {n = zero} x _ = 1lRightAnnihilates∨l x
⋀Joinrdist {n = suc n} x V =
x ∨l (V zero ∧l ⋀ (V ∘ suc)) ≡⟨ ∨lLdist∧l _ _ _ ⟩ --Ldist and Rdist wrong way around?
(x ∨l V zero) ∧l (x ∨l ⋀ (V ∘ suc)) ≡⟨ (λ i → (x ∨l V zero) ∧l ⋀Joinrdist x (V ∘ suc) i) ⟩
(x ∨l V zero) ∧l ⋀ (λ i → x ∨l V (suc i)) ∎
⋀Joinldist : ∀ {n} → (x : L) → (V : FinVec L n)
→ (⋀ V) ∨l x ≡ ⋀ λ i → V i ∨l x
⋀Joinldist {n = zero} x _ = 1lLeftAnnihilates∨l x
⋀Joinldist {n = suc n} x V =
(V zero ∧l ⋀ (V ∘ suc)) ∨l x ≡⟨ ∨lRdist∧l _ _ _ ⟩
(V zero ∨l x) ∧l ((⋀ (V ∘ suc)) ∨l x) ≡⟨ (λ i → (V zero ∨l x) ∧l ⋀Joinldist x (V ∘ suc) i) ⟩
(V zero ∨l x) ∧l ⋀ (λ i → V (suc i) ∨l x) ∎
⋀Joinr1 : ∀ {n} → (V : FinVec L n) → ⋀ (λ i → V i ∨l 1l) ≡ 1l
⋀Joinr1 V = sym (⋀Joinldist 1l V) ∙ 1lRightAnnihilates∨l _
⋀Join1r : ∀ {n} → (V : FinVec L n) → ⋀ (λ i → 1l ∨l V i) ≡ 1l
⋀Join1r V = sym (⋀Joinrdist 1l V) ∙ 1lLeftAnnihilates∨l _
| 36.901235
| 101
| 0.562228
|
1cfcb4b0130f4a3317e75793d09c9fc2eab5a0f1
| 286
|
agda
|
Agda
|
Container/Membership.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Container/Membership.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Container/Membership.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --safe --cubical #-}
open import Container
module Container.Membership {s p} (𝒞 : Container s p) where
open import Prelude
open import HLevels
infixr 5 _∈_ _∈!_
_∈_ : A → ⟦ 𝒞 ⟧ A → Type _
x ∈ xs = fiber (snd xs) x
_∈!_ : A → ⟦ 𝒞 ⟧ A → Type _
x ∈! xs = isContr (x ∈ xs)
| 17.875
| 59
| 0.604895
|
cb68009bca24fbad5176a5e6ba1f5b856bb400d3
| 909
|
agda
|
Agda
|
test/interaction/Issue635.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue635.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue635.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v interaction.case:10 -v tc.cover:40 #-}
module Issue635 where
record Pointed : Set₁ where
field
Carrier : Set
empty : Carrier
equal : Carrier → Carrier → Set
record PointedMorphism (M₁ M₂ : Pointed) : Set where
constructor morph
module M₁ = Pointed M₁
module M₂ = Pointed M₂
field
f : M₁.Carrier → M₂.Carrier
.identity : M₂.equal (f M₁.empty) M₂.empty
g : ∀ (M₁ M₂ : Pointed) → PointedMorphism M₁ M₂ → PointedMorphism M₁ M₂
g M₁ M₂ (morph f identity) = morph f identity
f : ∀ {M₁ M₂ : Pointed} → PointedMorphism M₁ M₂ → PointedMorphism M₁ M₂
f x = {!x!}
{- WAS:
case splitting on x in that hole produces this monstrosity:
f {.Splitting.recCon-NOT-PRINTED Carrier empty times equal} {.Splitting.recCon-NOT-PRINTED Carrier₁ empty₁ times₁ equal₁} (morph f identity) = ?
-}
-- Andreas, 2013-03-21
-- NOW: case splitting on x yields pattern (morph f identity)
| 28.40625
| 144
| 0.694169
|
0e7c889f8b27b7979f9afa08c9ccea83aab3b6b7
| 1,077
|
agda
|
Agda
|
Categories/Monad/Duality.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Monad/Duality.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Monad/Duality.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Monad.Duality {o ℓ e} (C : Category o ℓ e) where
open import Categories.Functor
open import Categories.NaturalTransformation
open import Categories.Monad
open import Categories.Comonad
private
module C = Category C
open C
open HomReasoning
coMonad⇒Comonad : Monad C.op → Comonad C
coMonad⇒Comonad M = record
{ F = Functor.op F
; ε = NaturalTransformation.op η
; δ = NaturalTransformation.op μ
; assoc = M.sym-assoc
; sym-assoc = M.assoc
; identityˡ = M.identityˡ
; identityʳ = M.identityʳ
}
where module M = Monad M
open M using (F; η; μ)
Comonad⇒coMonad : Comonad C → Monad C.op
Comonad⇒coMonad M = record
{ F = Functor.op F
; η = NaturalTransformation.op ε
; μ = NaturalTransformation.op δ
; assoc = M.sym-assoc
; sym-assoc = M.assoc
; identityˡ = M.identityˡ
; identityʳ = M.identityʳ
}
where module M = Comonad M
open M using (F; ε; δ)
| 25.642857
| 66
| 0.630455
|
23c9c39b1cd5c8db96f094433826bba9b88879fc
| 9,784
|
agda
|
Agda
|
agda-aplas14/Substitution.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 32
|
2017-05-22T14:33:27.000Z
|
2021-03-05T12:12:03.000Z
|
agda-aplas14/Substitution.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 2
|
2018-02-14T16:42:36.000Z
|
2018-02-20T14:54:18.000Z
|
agda-aplas14/Substitution.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 4
|
2017-11-10T16:44:52.000Z
|
2018-02-23T18:22:17.000Z
|
module Substitution where
open import Library
open import Terms
-- VarTm n specifies whether the substitution produces variables or terms.
-- The index is used to impose an order on the constructors
-- and so pass termination checking in lift/subst.
data VarTm : ℕ → Set where
`Var : VarTm 0
`Tm : VarTm 1
max01 : ℕ → ℕ → ℕ
max01 0 m = m
max01 n m = n
_∙VT_ : ∀ {m n} → VarTm m → VarTm n → VarTm (max01 m n)
`Var ∙VT vt = vt
`Tm ∙VT vt = `Tm
VT : ∀ {m} → VarTm m → Cxt → Ty → Set
VT `Var Γ a = Var Γ a
VT `Tm Γ a = Tm Γ a
vt2tm : ∀ {Γ a m} vt → VT {m} vt Γ a → Tm Γ a
vt2tm `Var x = var x
vt2tm `Tm t = t
RenSub : ∀ {m} → VarTm m → Cxt → Cxt → Set
RenSub vt Γ Δ = ∀ {a} → Var Γ a → VT vt Δ a
mutual
-- Lifiting a substitution
lifts : ∀ {m vt Γ Δ a} → RenSub {m} vt Γ Δ → RenSub vt (a ∷ Γ) (a ∷ Δ)
lifts {vt = `Var} σ (zero) = zero
lifts {vt = `Var} σ (suc x) = suc (σ x)
lifts {vt = `Tm} σ (zero) = var (zero)
lifts {vt = `Tm} σ (suc x) = subst {vt = `Var} suc (σ x)
-- Performing a substitution
subst : ∀ {m vt Γ Δ τ} → RenSub {m} vt Γ Δ → Tm Γ τ → Tm Δ τ
subst σ (abs t) = abs (subst (lifts σ) t)
subst σ (app t u) = app (subst σ t) (subst σ u)
subst σ (var x) = vt2tm _ (σ x)
-- Performing substitution, inductive specification
data IndSubst {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) : ∀ {τ} → Tm Γ τ → Tm Δ τ → Set where
var : ∀{a t} (x : Var Γ a)
→ vt2tm _ (σ x) ≡ t
→ IndSubst σ (var x) t
abs : ∀{a b} {t : Tm (a ∷ Γ) b} {t'}
→ IndSubst (lifts σ) t t'
→ IndSubst σ (abs t) (abs t')
app : ∀{a b} {t : Tm Γ (a →̂ b)} {u t' u'}
→ IndSubst σ t t'
→ IndSubst σ u u'
→ IndSubst σ (app t u) (app t' u')
-- Performing renaming, inductive specification
data IndRen {Γ Δ} (σ : RenSub `Var Γ Δ) : ∀ {τ} → Tm Γ τ → Tm Δ τ → Set where
var : ∀{a y} (x : Var Γ a)
→ (σ x) ≡ y
→ IndRen σ (var x) (var y)
abs : ∀{a b} {t : Tm (a ∷ Γ) b} {t'}
→ IndRen (lifts σ) t t'
→ IndRen σ (abs t) (abs t')
app : ∀{a b} {t : Tm Γ (a →̂ b)} {u t' u'}
→ IndRen σ t t'
→ IndRen σ u u'
→ IndRen σ (app t u) (app t' u')
-- Logical equivalence between inductive and algorithmic substitution
IndS→prop : ∀ {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → IndSubst σ t t' → subst σ t ≡ t'
IndS→prop σ (var x ≡.refl) = ≡.refl
IndS→prop σ (abs t) = ≡.cong abs (IndS→prop (lifts σ) t)
IndS→prop σ (app t t₁) = ≡.cong₂ app (IndS→prop σ t) (IndS→prop σ t₁)
prop→IndS' : ∀ {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) {τ} (t : Tm Γ τ) → IndSubst σ t (subst σ t)
prop→IndS' σ (var x) = var x ≡.refl
prop→IndS' σ (abs t) = abs (prop→IndS' (lifts σ) t)
prop→IndS' σ (app t u) = app (prop→IndS' σ t) (prop→IndS' σ u)
prop→IndS : ∀ {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → subst σ t ≡ t' → IndSubst σ t t'
prop→IndS _ ≡.refl = prop→IndS' _ _
-- Logical equivalence between inductive and algorithmic renaming
Ind→prop : ∀ {Γ Δ} (σ : RenSub `Var Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → IndRen σ t t' → subst σ t ≡ t'
Ind→prop σ (var x ≡.refl) = ≡.refl
Ind→prop σ (abs t) = ≡.cong abs (Ind→prop (lifts σ) t)
Ind→prop σ (app t t₁) = ≡.cong₂ app (Ind→prop σ t) (Ind→prop σ t₁)
prop→Ind' : ∀ {Γ Δ} (σ : RenSub `Var Γ Δ) {τ} (t : Tm Γ τ) → IndRen σ t (subst σ t)
prop→Ind' σ (var x) = var x ≡.refl
prop→Ind' σ (abs t) = abs (prop→Ind' (lifts σ) t)
prop→Ind' σ (app t u) = app (prop→Ind' σ t) (prop→Ind' σ u)
prop→Ind : ∀ {Γ Δ} (σ : RenSub `Var Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → subst σ t ≡ t' → IndRen σ t t'
prop→Ind _ ≡.refl = prop→Ind' _ _
-- Identity substitution
ids : ∀ {i vt Γ} → RenSub {i} vt Γ Γ
ids {vt = `Var} x = x
ids {vt = `Tm } x = var x
-- substitution composition
_•s_ : ∀ {Γ₀ Γ₁ Γ₂}
{n}{vt2 : VarTm n}(τ : RenSub vt2 Γ₁ Γ₂)
{m}{vt1 : VarTm m}(σ : RenSub vt1 Γ₀ Γ₁) → RenSub (vt1 ∙VT vt2) Γ₀ Γ₂
_•s_ τ {vt1 = `Var} σ x = τ (σ x)
_•s_ τ {vt1 = `Tm } σ x = subst τ (σ x)
-- Term substitution
Subst : Cxt → Cxt → Set
Subst Γ Δ = ∀ {a : Ty} → Var Γ a → Tm Δ a
-- Extending a substitution
_∷s_ : ∀ {Γ Δ a} → Tm Γ a → Subst Δ Γ → Subst (a ∷ Δ) Γ
(t ∷s σ) (zero) = t
(t ∷s σ) (suc x) = σ x
-- Substitution for 0th variable
sgs : ∀ {Γ a} → Tm Γ a → Subst (a ∷ Γ) Γ
sgs t = t ∷s ids
-- Substituting for the 0th variable [u/0]t
subst0 : ∀ {Γ a b} → Tm Γ a → Tm (a ∷ Γ) b → Tm Γ b
subst0 u = subst (sgs u)
-- Renamings
Ren : (Γ Δ : Cxt) → Set
Ren = RenSub `Var
_≤_ : (Γ Δ : Cxt) → Set
_≤_ Γ Δ = RenSub `Var Δ Γ
rename : ∀ {Γ Δ : Cxt} {a : Ty} (η : Γ ≤ Δ) (x : Tm Δ a) → Tm Γ a
rename = subst
-- Weakening renaming
weak : ∀{Γ a} → (a ∷ Γ) ≤ Γ
weak = suc
-- Weakening substitution
weaks : ∀{n}{vt : VarTm n}{a Γ Δ} (σ : RenSub vt Γ Δ) → RenSub vt (Γ) (a ∷ Δ)
weaks {vt = `Var} σ x = suc (σ x)
weaks {vt = `Tm} σ x = rename suc (σ x)
-- Properties
_≡s_ : ∀ {Γ Δ} {m n vt1 vt2} → (f : RenSub {m} vt1 Γ Δ)(g : RenSub {n} vt2 Γ Δ) → Set
f ≡s g = (∀ {a} x → vt2tm _ (f {a} x) ≡ vt2tm _ (g x))
mutual
subst-ext : ∀ {Γ Δ} {m n vt1 vt2} {f : RenSub {m} vt1 Γ Δ}{g : RenSub {n} vt2 Γ Δ} → f ≡s g → ∀ {a} (t : Tm Γ a) → subst f t ≡ subst g t
subst-ext f≐g (var v) = (f≐g v)
subst-ext {f = f} {g = g} f≐g (abs t) = ≡.cong abs (subst-ext (lifts-ext {f = f} {g = g} f≐g) t)
subst-ext f≐g (app t t₁) = ≡.cong₂ app (subst-ext f≐g t) (subst-ext f≐g t₁)
lifts-ext : ∀ {Γ Δ b} {m n vt1 vt2} {f : RenSub {m} vt1 Γ Δ}{g : RenSub {n} vt2 Γ Δ} → f ≡s g → lifts {a = b} f ≡s lifts g
lifts-ext {vt1 = `Var} {`Var} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Var} {`Var} {f} {g} f≐g (suc x) with f x | g x | f≐g x
lifts-ext {Γ} {Δ} {b} {._} {._} {`Var} {`Var} f≐g (suc x) | z | .z | ≡.refl = ≡.refl
lifts-ext {vt1 = `Var} {`Tm} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Var} {`Tm} f≐g (suc x) rewrite ≡.sym (f≐g x) = ≡.refl
lifts-ext {vt1 = `Tm} {`Var} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Tm} {`Var} f≐g (suc x) rewrite (f≐g x) = ≡.refl
lifts-ext {vt1 = `Tm} {`Tm} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Tm} {`Tm} f≐g (suc x) = ≡.cong (subst suc) (f≐g x)
mutual
subst-∙ : ∀ {Γ₀ Γ₁ Γ₂}
{n}{vt2 : VarTm n}(τ : RenSub vt2 Γ₁ Γ₂)
{m}{vt1 : VarTm m}(σ : RenSub vt1 Γ₀ Γ₁) → ∀ {a} (t : Tm Γ₀ a) → subst (τ •s σ) t ≡ subst τ (subst σ t)
subst-∙ τ {vt1 = `Var} σ (var x) = ≡.refl
subst-∙ τ {vt1 = `Tm} σ (var x) = ≡.refl
subst-∙ τ σ (abs t) = ≡.cong abs (≡.trans (subst-ext (lifts-∙ τ σ) t) (subst-∙ (lifts τ) (lifts σ) t))
subst-∙ τ σ (app t t₁) = ≡.cong₂ app (subst-∙ τ σ t) (subst-∙ τ σ t₁)
lifts-∙ : ∀ {Γ₀ Γ₁ Γ₂}
{n}{vt2 : VarTm n}(τ : RenSub vt2 Γ₁ Γ₂)
{m}{vt1 : VarTm m}(σ : RenSub vt1 Γ₀ Γ₁) → ∀ {a} → lifts {a = a} (τ •s σ) ≡s (lifts τ •s lifts σ)
lifts-∙ {vt2 = `Var} τ {vt1 = `Var} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Tm} τ {vt1 = `Var} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Var} τ {vt1 = `Var} σ (suc x) = ≡.refl
lifts-∙ {vt2 = `Tm} τ {vt1 = `Var} σ (suc x) = ≡.refl
lifts-∙ {vt2 = `Var} τ {vt1 = `Tm} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Tm} τ {vt1 = `Tm} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Var} τ {vt1 = `Tm} σ (suc x) = ≡.trans (≡.sym (subst-∙ suc τ (σ x))) (subst-∙ (lifts τ) suc (σ x))
lifts-∙ {vt2 = `Tm} τ {vt1 = `Tm} σ (suc x) = ≡.trans (≡.sym (subst-∙ suc τ (σ x))) (subst-∙ (lifts τ) suc (σ x))
mutual
subst-id : ∀ {m vt Γ a} → (t : Tm Γ a) → subst (ids {m} {vt}) t ≡ t
subst-id {vt = `Var} (var v) = ≡.refl
subst-id {vt = `Tm} (var v) = ≡.refl
subst-id {m} {vt} {Γ} (abs t) = ≡.cong abs (≡.trans (subst-ext {n = m} {vt2 = vt} (lifts-id {m} {vt}) t) (subst-id t))
subst-id (app t t₁) = ≡.cong₂ app (subst-id t) (subst-id t₁)
lifts-id : ∀ {m vt Γ b} → lifts {a = b} (ids {m} {vt} {Γ = Γ}) ≡s ids {m} {vt} {Γ = b ∷ Γ}
lifts-id {vt = `Var} (zero) = ≡.refl
lifts-id {vt = `Var} (suc x) = ≡.refl
lifts-id {vt = `Tm} (zero) = ≡.refl
lifts-id {vt = `Tm} (suc x) = ≡.refl
sgs-lifts : ∀ {m vt Γ Δ a} {σ : RenSub {m} vt Γ Δ} {u : Tm Γ a} → (sgs (subst σ u) •s lifts σ) ≡s (σ •s sgs u)
sgs-lifts {vt = `Var} = (λ { (zero) → ≡.refl ; (suc x) → ≡.refl })
sgs-lifts {vt = `Tm} {σ = σ} {u} = (λ { (zero) → ≡.refl ; (suc x) → ≡.sym (≡.trans (≡.sym (subst-id (σ x)))
(subst-∙ (sgs (subst σ u)) {vt1 = `Var} suc (σ x))) })
sgs-lifts-term : ∀ {m vt Γ Δ a b} {σ : RenSub {m} vt Γ Δ} {u : Tm Γ a}{t : Tm (a ∷ Γ) b}
→ subst (sgs (subst σ u)) (subst (lifts σ) t) ≡ subst σ (subst (sgs u) t)
sgs-lifts-term {σ = σ} {u} {t} = (≡.trans (≡.sym (subst-∙ (sgs (subst σ u)) (lifts σ) t))
(≡.trans (subst-ext sgs-lifts t)
(subst-∙ σ (sgs u) t)))
renId : ∀ {Γ a}{t : Tm Γ a} → rename id t ≡ t
renId = subst-id _
contract : ∀ {a Γ} → RenSub `Var (a ∷ a ∷ Γ) (a ∷ Γ)
contract (zero) = zero
contract (suc x) = x
contract-sgs : ∀ {a Γ} → contract {a} {Γ} ≡s sgs (var zero)
contract-sgs (zero) = ≡.refl
contract-sgs (suc x) = ≡.refl
sgs-weak₀ : ∀ {Γ a} {u : Tm Γ a} {b} (x : Var Γ b) → sgs u (suc x) ≡ var x
sgs-weak₀ x = ≡.refl
sgs-weak₁ : ∀ {Γ a} {u : Tm Γ a} → (sgs u ∘ suc) ≡s (ids {vt = `Tm})
sgs-weak₁ x = ≡.refl
sgs-weak : ∀ {Γ a} {u : Tm Γ a} → (sgs u •s weak) ≡s (ids {vt = `Tm})
sgs-weak x = ≡.refl
cons-to-sgs : ∀ {Γ Δ a} (u : Tm Δ a) (σ : Subst Γ Δ)
→ (u ∷s σ) ≡s (sgs u •s lifts σ)
cons-to-sgs u σ (zero) = ≡.refl
cons-to-sgs u σ (suc x) = begin
σ x ≡⟨ ≡.sym (subst-id (σ x)) ⟩
subst (ids {vt = `Tm}) (σ x) ≡⟨ subst-ext (λ _ → ≡.refl) (σ x) ⟩
subst (sgs u •s weak) (σ x) ≡⟨ subst-∙ (sgs u) weak (σ x) ⟩
subst (sgs u) (subst suc (σ x))
∎
where open ≡-Reasoning
-- -}
| 35.970588
| 138
| 0.500409
|
4ab48c08e942aa3458ce290ec6bb304034d8502b
| 432
|
agda
|
Agda
|
Light/Implementation/Data/Unit.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | 1
|
2019-12-20T21:33:05.000Z
|
2019-12-20T21:33:05.000Z
|
Light/Implementation/Data/Unit.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
Light/Implementation/Data/Unit.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Implementation.Data.Unit where
open import Light.Library.Data.Unit using (Library ; Dependencies)
instance dependencies : Dependencies
dependencies = record {}
instance library : Library dependencies
library = record { Implementation }
where
module Implementation where
record Unit : Set where constructor unit
| 28.8
| 79
| 0.747685
|
4a9353e58127bb44955e3257fbbe42e610424470
| 6,907
|
agda
|
Agda
|
UniDB/Subst/Inst.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Subst/Inst.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Subst/Inst.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
module UniDB.Subst.Inst where
open import UniDB.Spec
open import UniDB.Subst.Core
open import UniDB.Subst.Pair
open import UniDB.Subst.Shifts
open import UniDB.Morph.Pair
open import UniDB.Morph.Shift
open import UniDB.Morph.Shifts
open import UniDB.Morph.Unit
-- These are two unused instances. Just to show that ApHComp is slightly
-- stronger than ApPair, but given ApRel then ApPair and ApHComp become
-- equivalent. Unfortunately neither ApPair nor ApHComp imply ApRel but
-- both can be made stronger to do so.
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
(X : STX) {{apTX : Ap T X}} {{apHCompTX : ApHComp T X}}
where
iApPair : ApPair T X
ap-pair {{iApPair}} {Ξ} {Ζ} ξ ζ x = ap-⊡ {T} {X} {Ξ} {Ζ} {Pair Ξ Ζ} ξ ζ x
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}}
(X : STX) {{wkX : Wk X}} {{apTX : Ap T X}}
{{apRelTX : ApRel T X}}
(Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{wkmΞ : Wkm Ξ}}
{{lkUpTΞ : LkUp T Ξ}} {{lkWkmTΞ : LkWkm T Ξ}}
(Ζ : MOR) {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{wkmΖ : Wkm Ζ}}
{{lkUpTΖ : LkUp T Ζ}} {{lkWkmTΖ : LkWkm T Ζ}}
where
ap-wkm-rel : {γ : Dom} (δ : Dom) (x : X γ) →
ap {T} (wkm {Ξ} δ) x ≡ ap {T} (wkm {Ζ} δ) x
ap-wkm-rel {γ} δ = ap-rel≃ {T} lemma
where
lemma : [ T ] wkm {Ξ} {γ} δ ≃ wkm {Ζ} δ
lk≃ lemma i = begin
lk {T} (wkm {Ξ} δ) i ≡⟨ lk-wkm {T} {Ξ} δ i ⟩
vr (wk δ i) ≡⟨ sym (lk-wkm {T} {Ζ} δ i) ⟩
lk {T} (wkm {Ζ} δ) i ∎
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
(X : STX) {{apTX : Ap T X}} {{apPairTX : ApPair T X}} {{apRelTX : ApRel T X}}
where
iApHComp : ApHComp T X
ap-⊡ {{iApHComp}} {Ξ} {Ζ} {Θ} ξ ζ x = begin
ap {T} {X} {Θ} (ξ ⊡ ζ) x ≡⟨ ap-rel≅ {T} (≃-to-≅` lem) x ⟩
ap {T} {X} {Pair Ξ Ζ} (ξ ⊡ ζ) x ≡⟨ ap-pair {T} ξ ζ x ⟩
ap {T} {X} {Ζ} ζ (ap {T} {X} {Ξ} ξ x) ∎
where
lem : (δ : Dom) → [ T ] ((_⊡_ {Θ = Θ} ξ ζ) ↑ δ) ≃ (ξ ⊗ ζ) ↑ δ
lk≃ (lem δ) i = begin
lk {T} {Θ} ((ξ ⊡ ζ) ↑ δ) i ≡⟨ cong (λ ρ → lk {T} {Θ} ρ i) (⊡-↑ {Ξ} {Ζ} {Θ} ξ ζ δ) ⟩
lk {T} {Θ} (ξ ↑ δ ⊡ ζ ↑ δ) i ≡⟨ lk-⊡-ap {T} {Ξ} {Ζ} {Θ} (ξ ↑ δ) (ζ ↑ δ) i ⟩
lk {T} {Pair Ξ Ζ} (ξ ↑ δ ⊗ ζ ↑ δ) i ≡⟨ cong (λ ρ → lk {T} {Pair Ξ Ζ} ρ i) (sym (⊡-↑ {Ξ} {Ζ} {Pair Ξ Ζ} ξ ζ δ)) ⟩
lk {T} {Pair Ξ Ζ} ((ξ ⊗ ζ) ↑ δ) i ∎
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
(X : STX) {{apTX : Ap T X}} {{apPairTX : ApPair T X}} {{apRelTX : ApRel T X}}
where
iApComp : ApComp T X
ap-⊙ {{iApComp}} {Ξ} ξ ζ x = begin
ap {T} (ξ ⊙ ζ) x ≡⟨ ap-rel≅ {T} (≃-to-≅` lem) x ⟩
ap {T} (ξ ⊗ ζ) x ≡⟨ ap-pair {T} ξ ζ x ⟩
ap {T} ζ (ap {T} ξ x) ∎
where
lem : (δ : Dom) → [ T ] (ξ ⊙ ζ) ↑ δ ≃ (ξ ⊗ ζ) ↑ δ
lk≃ (lem δ) i = begin
lk ((ξ ⊙ ζ) ↑ δ) i ≡⟨ cong (λ ρ → lk ρ i) (⊙-↑ ξ ζ δ) ⟩
lk (ξ ↑ δ ⊙ ζ ↑ δ) i ≡⟨ lk-⊙-ap (ξ ↑ δ) (ζ ↑ δ) i ⟩
ap {T} (ζ ↑ δ) (lk (ξ ↑ δ) i) ≡⟨ refl ⟩
lk (ξ ↑ δ ⊗ ζ ↑ δ) i ≡⟨ refl ⟩ -- cong (λ ρ → lk ρ i) (sym (⊡-↑ {Ξ} {Ξ} {Pair Ξ Ξ} ξ ζ δ)) ⟩
lk ((ξ ⊗ ζ) ↑ δ) i ∎
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
{{apVrT : ApVr T}} {{apWkmWkTT : ApWkmWk T T}}
(X : STX) {{wkX : Wk X}} {{apTX : Ap T X}}
{{apWkmWkTX : ApWkmWk T X}}
{{apPairTX : ApPair T X}} {{apRelTX : ApRel T X}}
(Ρ : MOR) {{lkTΡ : Lk T Ρ}} {{upΡ : Up Ρ}} {{lkUpTΡ : LkUp T Ρ}}
{{wkmΡ : Wkm Ρ}} {{lkWkmΡ : LkWkm T Ρ}}
(Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}}
{{lkUpPairΞΡ : LkUp T (Pair Ξ Ρ)}}
{{lkUpPairΞΡ : LkUp T (Pair Ρ Ξ)}}
where
ap-wk₁-gen : {γ₁ γ₂ : Dom} (ξ : Ξ γ₁ γ₂) (x : X γ₁) →
ap {T} {X} {Ξ} (ξ ↑₁) (wk₁ x) ≡ wk₁ (ap {T} {X} {Ξ} ξ x)
ap-wk₁-gen ξ x = begin
ap {T} (ξ ↑₁) (wk₁ x) ≡⟨ cong (ap {T} (ξ ↑₁)) (sym (ap-wkm-wk₁ {T} {X} {Ρ} x)) ⟩
ap {T} (ξ ↑₁) (ap {T} (wkm {Ρ} 1) x) ≡⟨ sym (ap-pair {T} (wkm {Ρ} 1) (ξ ↑₁) x) ⟩
ap {T} (wkm {Ρ} 1 ⊗ ξ ↑₁) x ≡⟨ ap-rel≃ {T} lem x ⟩
ap {T} (ξ ⊗ wkm {Ρ} 1) x ≡⟨ ap-pair {T} ξ (wkm {Ρ} 1) x ⟩
ap {T} (wkm {Ρ} 1) (ap {T} ξ x) ≡⟨ ap-wkm-wk₁ {T} (ap {T} ξ x) ⟩
wk₁ (ap {T} ξ x)
∎
where
lem : [ T ] (wkm {Ρ} 1 ⊗ ξ ↑₁) ≃ (ξ ⊗ wkm {Ρ} 1)
lk≃ lem i = begin
ap {T} (ξ ↑₁) (lk {T} (wkm {Ρ} 1) i) ≡⟨ cong (ap {T} (_↑₁ ξ)) (lk-wkm {T} {Ρ} 1 i) ⟩
ap {T} (ξ ↑₁) (vr (suc i)) ≡⟨ ap-vr {T} (ξ ↑₁) (suc i) ⟩
lk {T} (ξ ↑₁) (suc i) ≡⟨ lk-↑₁-suc {T} ξ i ⟩
wk₁ (lk {T} ξ i) ≡⟨ sym (ap-wkm-wk₁ {T} (lk {T} ξ i)) ⟩
ap {T} (wkm {Ρ} 1) (lk {T} ξ i) ∎
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
{{wkVrT : WkVr T}}
{{apVrT : ApVr T}} {{apWkmWkTT : ApWkmWk T T}}
{{apPairTT : ApPair T T}} {{apRelTT : ApRel T T}}
(X : STX) {{wkX : Wk X}} {{apTX : Ap T X}}
{{apWkmWkTX : ApWkmWk T X}}
{{apPairTX : ApPair T X}} {{apRelTX : ApRel T X}}
where
private
Ren : MOR
Ren = Shift
iApWk : ApWk T X
ap-wk₁ {{iApWk}} {Ξ} = ap-wk₁-gen T X Ren Ξ
where
instance
iLkUpRenRen : LkUp T (Pair Ren Ren)
iLkUpRenRen = iLkUpPairRenaming T Ren Ren
iLkUpRenΞ : LkUp T (Pair Ren Ξ)
iLkUpRenΞ = iLkUpPairRenaming T Ren Ξ
iLkUpΞRen : LkUp T (Pair Ξ Ren)
iLkUpΞRen = iLkUpPairSubstitution T Ξ Ren
(ap-wk₁-gen T T Ren Ren)
{-
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
{{wkVrT : WkVr T}} {{apVrT : ApVr T}}
(X : STX) {{wkX : Wk X}} {{apTX : Ap T X}}
{{apWkmWkTX : ApWkmWk T X}} {{apIdmTX : ApIdm T X}} {{apCompTX : ApComp T X}}
where
private
module _
(Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
{{idmΞ : Idm Ξ}} {{wkmΞ : Wkm Ξ}} {{compΞ : Comp Ξ}}
{{lkUpTΞ : LkUp T Ξ}} {{lkWkmTΞ : LkWkm T Ξ}} {{lkIdmTΞ : LkIdm T Ξ}}
{{upIdmΞ : UpIdm Ξ}} {{upCompΞ : UpComp Ξ}} {{lkCompTΞ : LkCompAp T Ξ}}
{{wkmHomΞ : WkmHom Ξ}}
where
iWkHom` : WkHom X
wk-zero {{iWkHom`}} x = begin
wk 0 x ≡⟨ sym (ap-wkm-wk T X Ξ 0 x) ⟩
ap T X Ξ (wkm Ξ 0) x ≡⟨ cong (λ ξ → ap T X Ξ ξ x) (wkm-zero Ξ) ⟩
ap T X Ξ (idm Ξ _) x ≡⟨ ap-idm T X Ξ x ⟩
x ∎
wk-suc {{iWkHom`}} δ x = begin
wk (suc δ) x ≡⟨ sym (ap-wkm-wk T X Ξ (suc δ) x) ⟩
ap T X Ξ (wkm Ξ (suc δ)) x ≡⟨ cong (λ ξ → ap T X Ξ ξ x) (wkm-suc Ξ δ) ⟩
ap T X Ξ (wkm Ξ δ ⊙ wkm Ξ 1) x ≡⟨ ap-⊙ T X Ξ (wkm Ξ δ) (wkm Ξ 1) x ⟩
ap T X Ξ (wkm Ξ 1) (ap T X Ξ (wkm Ξ δ) x) ≡⟨ ap-wkm-wk₁ T X Ξ (ap T X Ξ (wkm Ξ δ) x) ⟩
wk₁ (ap T X Ξ (wkm Ξ δ) x) ≡⟨ cong wk₁ (ap-wkm-wk T X Ξ δ x) ⟩
wk₁ (wk δ x) ∎
iWkHom : WkHom X
iWkHom = iWkHom` Shifts
-}
| 39.924855
| 120
| 0.442884
|
10d78bbd9b27e9613a803a5e6b0d9d6d566d7de0
| 715
|
agda
|
Agda
|
test/Succeed/Issue2484-9.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Succeed/Issue2484-9.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Issue2484-9.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module _ (_ : Set) where
open import Agda.Builtin.Size
postulate
I : Set
record ∃ (B : I → Set) : Set where
constructor _,_
field
proj₁ : I
proj₂ : B proj₁
module M (_ : Set₁) where
mutual
data P (i : Size) (x y : I) : Set where
⟨_⟩ : ∃ (Q i x) → P i x y
record Q (i : Size) (x y : I) : Set where
coinductive
field
force : {j : Size< i} → P j x y
open M Set
postulate
map : (B : I → Set) → (∀ x → B x → B x) → ∃ B → ∃ B
lemma : ∀ x y i → Q i x y → Q i x y
p : ∀ x i → P i x x
q′ : ∀ x i → ∃ λ y → Q i x y
q : ∀ x i → Q i x x
q′ x i = x , q x i
p x i = ⟨ map _ (λ y → lemma x y _) (q′ x i) ⟩
Q.force (q x i) {j} = p _ _
| 18.333333
| 60
| 0.454545
|
185d655b7b1eb4502d0e472ebd03d6acb0a0b82d
| 2,060
|
agda
|
Agda
|
Data/Fin/Injective.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Data/Fin/Injective.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Data/Fin/Injective.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Data.Fin.Injective where
open import Prelude
open import Data.Fin.Base
open import Data.Fin.Properties using (discreteFin)
open import Data.Nat
open import Data.Nat.Properties using (+-comm)
open import Function.Injective
private
variable n m : ℕ
infix 4 _≢ᶠ_ _≡ᶠ_
_≢ᶠ_ _≡ᶠ_ : Fin n → Fin n → Type _
n ≢ᶠ m = T (not (discreteFin n m .does))
n ≡ᶠ m = T (discreteFin n m .does)
_F↣_ : ℕ → ℕ → Type
n F↣ m = Σ[ f ⦂ (Fin n → Fin m) ] × ∀ {x y} → x ≢ᶠ y → f x ≢ᶠ f y
shift : (x y : Fin (suc n)) → x ≢ᶠ y → Fin n
shift f0 (fs y) x≢y = y
shift {suc _} (fs x) f0 x≢y = f0
shift {suc _} (fs x) (fs y) x≢y = fs (shift x y x≢y)
shift-inj : ∀ (x y z : Fin (suc n)) x≢y x≢z → y ≢ᶠ z → shift x y x≢y ≢ᶠ shift x z x≢z
shift-inj f0 (fs y) (fs z) x≢y x≢z x+y≢x+z = x+y≢x+z
shift-inj {suc _} (fs x) f0 (fs z) x≢y x≢z x+y≢x+z = tt
shift-inj {suc _} (fs x) (fs y) f0 x≢y x≢z x+y≢x+z = tt
shift-inj {suc _} (fs x) (fs y) (fs z) x≢y x≢z x+y≢x+z = shift-inj x y z x≢y x≢z x+y≢x+z
shrink : suc n F↣ suc m → n F↣ m
shrink (f , inj) .fst x = shift (f f0) (f (fs x)) (inj tt)
shrink (f , inj) .snd p = shift-inj (f f0) (f (fs _)) (f (fs _)) (inj tt) (inj tt) (inj p)
¬plus-inj : ∀ n m → ¬ (suc (n + m) F↣ m)
¬plus-inj zero zero (f , _) = f f0
¬plus-inj zero (suc m) inj = ¬plus-inj zero m (shrink inj)
¬plus-inj (suc n) m (f , p) = ¬plus-inj n m (f ∘ fs , p)
toFin-inj : (Fin n ↣ Fin m) → n F↣ m
toFin-inj f .fst = f .fst
toFin-inj (f , inj) .snd {x} {y} x≢ᶠy with discreteFin x y | discreteFin (f x) (f y)
... | no ¬p | yes p = ¬p (inj _ _ p)
... | no _ | no _ = tt
n≢sn+m : ∀ n m → Fin n ≢ Fin (suc (n + m))
n≢sn+m n m n≡m =
¬plus-inj m n
(toFin-inj
(subst
(_↣ Fin n)
(n≡m ; cong (Fin ∘ suc) (+-comm n m))
refl-↣))
Fin-inj : Injective Fin
Fin-inj n m eq with compare n m
... | equal _ = refl
... | less n k = ⊥-elim (n≢sn+m n k eq)
... | greater m k = ⊥-elim (n≢sn+m m k (sym eq))
| 30.746269
| 92
| 0.517961
|
10e0eae92cab52c912df6290a66ff88da1f1e01e
| 2,254
|
agda
|
Agda
|
lib/Explore/Experimental/iso-probabilistic-reasoning.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | 2
|
2016-06-05T09:25:32.000Z
|
2017-06-28T19:19:29.000Z
|
lib/Explore/Experimental/iso-probabilistic-reasoning.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | 1
|
2019-03-16T14:24:04.000Z
|
2019-03-16T14:24:04.000Z
|
lib/Explore/Experimental/iso-probabilistic-reasoning.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module isos-examples where
open import Function
open import Function.Related.TypeIsomorphisms.NP
import Function.Inverse.NP as FI
open FI using (_↔_; inverses; module Inverse) renaming (_$₁_ to to; _$₂_ to from)
import Function.Related as FR
open import Type hiding (★)
open import Data.Product.NP
open import Data.Bool.NP using (✓)
open import Data.One using (𝟙)
open import Data.Bits
open import Relation.Binary
import Relation.Binary.PropositionalEquality as ≡
open ≡ using (_≡_; subst)
_≈₂_ : ∀ {a} {A : ★ a} (f g : A → Bit) → ★ _
_≈₂_ {A = A} f g = Σ A (✓ ∘ f) ↔ Σ A (✓ ∘ g)
module _ {a r} {A : ★ a} {R : ★ r} where
_≈_ : (f g : A → R) → ★ _
f ≈ g = ∀ (O : R → ★ r) → Σ A (O ∘ f) ↔ Σ A (O ∘ g)
≈-refl : Reflexive {A = A → R} _≈_
≈-refl _ = FI.id
≈-trans : Transitive {A = A → R} _≈_
≈-trans p q O = q O FI.∘ p O
≈-sym : Symmetric {A = A → R} _≈_
≈-sym p O = FI.sym (p O)
module _ {a r} {A : ★ a} {R : ★ r} (f : A → R) (p : A ↔ A) where
stable : f ≈ (f ∘ from p)
stable _ = first-iso p
stable′ : f ≈ (f ∘ to p)
stable′ _ = first-iso (FI.sym p)
module _ {a b r} {A : ★ a} {B : ★ b} {R : ★ r} where
_≋_ : (f : A → R) (g : B → R) → ★ _
f ≋ g = (f ∘ proj₁) ≈ (g ∘ proj₂)
module _ {a b r} {A : ★ a} {B : ★ b} {R : ★ r} where
_≋′_ : (f : A → R) (g : B → R) → ★ _
f ≋′ g = ∀ (O : R → ★ r) →
(B × Σ A (O ∘ f)) ↔ (A × Σ B (O ∘ g))
module _ {f : A → R} {g : B → R} where
open FR.EquationalReasoning
≋′→≋ : f ≋′ g → f ≋ g
≋′→≋ h O = Σ (A × B) (O ∘ f ∘ proj₁)
↔⟨ Σ×-swap ⟩
Σ (B × A) (O ∘ f ∘ proj₂)
↔⟨ Σ-assoc ⟩
(B × Σ A (O ∘ f))
↔⟨ h O ⟩
(A × Σ B (O ∘ g))
↔⟨ FI.sym Σ-assoc ⟩
Σ (A × B) (O ∘ g ∘ proj₂)
∎
≋→≋′ : f ≋ g → f ≋′ g
≋→≋′ h O = (B × Σ A (O ∘ f))
↔⟨ FI.sym Σ-assoc ⟩
Σ (B × A) (O ∘ f ∘ proj₂)
↔⟨ Σ×-swap ⟩
Σ (A × B) (O ∘ f ∘ proj₁)
↔⟨ h O ⟩
Σ (A × B) (O ∘ g ∘ proj₂)
↔⟨ Σ-assoc ⟩
(A × Σ B (O ∘ g))
∎
-- -}
-- -}
-- -}
-- -}
-- -}
| 27.487805
| 81
| 0.404614
|
fbf902dc99a58dab6439d14644237a1272c459b7
| 3,567
|
agda
|
Agda
|
Univalence/DivMod23.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/DivMod23.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/DivMod23.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Integer division
------------------------------------------------------------------------
module DivMod23 where
open import Data.Nat as Nat
open import Data.Nat.Properties
open SemiringSolver
open import Data.Fin as Fin using (Fin; zero; suc; toℕ; fromℕ)
import Data.Fin.Properties as Fin
open import Induction.Nat
open import Relation.Nullary.Decidable
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Function
------------------------------------------------------------------------
-- Some boring lemmas
private
lem₁ : (m k : ℕ) →
Nat.suc m ≡ suc (toℕ (Fin.inject+ k (fromℕ m)) + 0)
lem₁ m k = cong suc $ begin
m
≡⟨ sym $ Fin.to-from m ⟩
toℕ (fromℕ m)
≡⟨ Fin.inject+-lemma k (fromℕ m) ⟩
toℕ (Fin.inject+ k (fromℕ m))
≡⟨ solve 1 (λ x → x := x :+ con 0) refl _ ⟩
toℕ (Fin.inject+ k (fromℕ m)) + 0
∎
lem₂ : ∀ n → _
lem₂ = solve 1 (λ n → con 1 :+ n := con 1 :+ (n :+ con 0)) refl
lem₃ : ∀ n k q (r : Fin n) eq → suc n + k ≡ toℕ r + suc q * n
lem₃ n k q r eq = begin
suc n + k
≡⟨ solve 2 (λ n k → con 1 :+ n :+ k := n :+ (con 1 :+ k))
refl n k ⟩
n + suc k
≡⟨ cong (_+_ n) eq ⟩
n + (toℕ r + q * n)
≡⟨ solve 3 (λ n r q → n :+ (r :+ q :* n) :=
r :+ (con 1 :+ q) :* n)
refl n (toℕ r) q ⟩
toℕ r + suc q * n
∎
------------------------------------------------------------------------
-- Division
infixl 7 _divMod_ _div_ _mod_
-- A specification of integer division.
record DivMod (dividend divisor : ℕ) : Set where
constructor result
field
quotient : ℕ
remainder : Fin divisor
property : dividend ≡ toℕ remainder + quotient * divisor
-- Integer division with remainder.
-- Note that Induction.Nat.<-rec is used to establish termination of
-- division. The run-time complexity of this implementation of integer
-- division should be linear in the size of the dividend, assuming
-- that well-founded recursion and the equality type are optimised
-- properly (see "Inductive Families Need Not Store Their Indices"
-- (Brady, McBride, McKinna, TYPES 2003)).
_divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
_divMod_ m n {≢0} = <-rec Pred dm m n {≢0}
where
Pred : ℕ → Set
Pred dividend = (divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
1+_ : ∀ {k n} → DivMod (suc k) n → DivMod (suc n + k) n
1+_ {k} {n} (result q r eq) = result (1 + q) r (lem₃ n k q r eq)
dm : (dividend : ℕ) → <-Rec Pred dividend → Pred dividend
dm m rec zero {≢0 = ()}
dm zero rec (suc n) = result 0 zero refl
dm (suc m) rec (suc n) with compare m n
dm (suc m) rec (suc .(suc m + k)) | less .m k = result 0 r (lem₁ m k)
where r = suc (Fin.inject+ k (fromℕ m))
dm (suc m) rec (suc .m) | equal .m = result 1 zero (lem₂ m)
dm (suc .(suc n + k)) rec (suc n) | greater .n k =
1+ rec (suc k) le (suc n)
where le = s≤′s (s≤′s (n≤′m+n n k))
-- Integer division.
_div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
_div_ m n {≢0} = DivMod.quotient $ _divMod_ m n {≢0}
-- The remainder after integer division.
_mod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → Fin divisor
_mod_ m n {≢0} = DivMod.remainder $ _divMod_ m n {≢0}
| 33.027778
| 79
| 0.520886
|
cb143e82389bb192aced5df1a7e030478df6d278
| 3,413
|
agda
|
Agda
|
Definition/LogicalRelation/Substitution.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation/Substitution.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
Definition/LogicalRelation/Substitution.agda
|
Vtec234/logrel-mltt
|
4746894adb5b8edbddc8463904ee45c2e9b29b69
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution {{eqrel : EqRelSet}} where
open import Definition.Untyped
open import Definition.Typed
open import Definition.LogicalRelation
open import Tools.Product
open import Tools.Unit
-- The validity judgements:
-- We consider expressions that satisfy these judgments valid
mutual
-- Validity of contexts
data ⊩ᵛ_ : Con Term → Set where
ε : ⊩ᵛ ε
_∙_ : ∀ {Γ A l} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ A / [Γ]
→ ⊩ᵛ Γ ∙ A
-- Validity of types
_⊩ᵛ⟨_⟩_/_ : (Γ : Con Term) (l : TypeLevel) (A : Term) → ⊩ᵛ Γ → Set
Γ ⊩ᵛ⟨ l ⟩ A / [Γ] =
∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Σ (Δ ⊩⟨ l ⟩ subst σ A) (λ [Aσ]
→ ∀ {σ′} ([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)
([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])
→ Δ ⊩⟨ l ⟩ subst σ A ≡ subst σ′ A / [Aσ])
-- Logical relation for substitutions from a valid context
_⊩ˢ_∷_/_/_ : (Δ : Con Term) (σ : Subst) (Γ : Con Term) ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
→ Set
Δ ⊩ˢ σ ∷ .ε / ε / ⊢Δ = ⊤
Δ ⊩ˢ σ ∷ .(Γ ∙ A) / (_∙_ {Γ} {A} {l} [Γ] [A]) / ⊢Δ =
Σ (Δ ⊩ˢ tail σ ∷ Γ / [Γ] / ⊢Δ) λ [tailσ] →
(Δ ⊩⟨ l ⟩ head σ ∷ subst (tail σ) A / proj₁ ([A] ⊢Δ [tailσ]))
-- Logical relation for equality of substitutions from a valid context
_⊩ˢ_≡_∷_/_/_/_ : (Δ : Con Term) (σ σ′ : Subst) (Γ : Con Term) ([Γ] : ⊩ᵛ Γ)
(⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Set
Δ ⊩ˢ σ ≡ σ′ ∷ .ε / ε / ⊢Δ / [σ] = ⊤
Δ ⊩ˢ σ ≡ σ′ ∷ .(Γ ∙ A) / (_∙_ {Γ} {A} {l} [Γ] [A]) / ⊢Δ / [σ] =
(Δ ⊩ˢ tail σ ≡ tail σ′ ∷ Γ / [Γ] / ⊢Δ / proj₁ [σ]) ×
(Δ ⊩⟨ l ⟩ head σ ≡ head σ′ ∷ subst (tail σ) A / proj₁ ([A] ⊢Δ (proj₁ [σ])))
-- Validity of terms
_⊩ᵛ⟨_⟩_∷_/_/_ : (Γ : Con Term) (l : TypeLevel) (t A : Term) ([Γ] : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) → Set
Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A] =
∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) →
Σ (Δ ⊩⟨ l ⟩ subst σ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ])) λ [tσ] →
∀ {σ′} → Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]
→ Δ ⊩⟨ l ⟩ subst σ t ≡ subst σ′ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ])
-- Validity of type equality
_⊩ᵛ⟨_⟩_≡_/_/_ : (Γ : Con Term) (l : TypeLevel) (A B : Term) ([Γ] : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) → Set
Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A] =
∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩⟨ l ⟩ subst σ A ≡ subst σ B / proj₁ ([A] ⊢Δ [σ])
-- Validity of term equality
_⊩ᵛ⟨_⟩_≡_∷_/_/_ : (Γ : Con Term) (l : TypeLevel) (t u A : Term) ([Γ] : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) → Set
Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A] =
∀ {Δ σ} → (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩⟨ l ⟩ subst σ t ≡ subst σ u ∷ subst σ A / proj₁ ([A] ⊢Δ [σ])
-- Valid term equality with validity of its type and terms
record [_⊩ᵛ⟨_⟩_≡_∷_/_] (Γ : Con Term) (l : TypeLevel)
(t u A : Term) ([Γ] : ⊩ᵛ Γ) : Set where
constructor modelsTermEq
field
[A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]
[t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A]
[u] : Γ ⊩ᵛ⟨ l ⟩ u ∷ A / [Γ] / [A]
[t≡u] : Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A]
-- Validity of reduction of terms
_⊩ᵛ_⇒_∷_/_ : (Γ : Con Term) (t u A : Term) ([Γ] : ⊩ᵛ Γ) → Set
Γ ⊩ᵛ t ⇒ u ∷ A / [Γ] = ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊢ subst σ t ⇒ subst σ u ∷ subst σ A
| 38.784091
| 80
| 0.425725
|
fb2cfd3138a180c8a60c4725a80f78a67e3a4cd0
| 14,600
|
agda
|
Agda
|
Cubical/Categories/Constructions/Slice.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Constructions/Slice.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Constructions/Slice.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Categories.Category
open import Cubical.Categories.Morphism renaming (isIso to isIsoC)
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open Iso
open import Cubical.Foundations.HLevels
open Precategory
open import Cubical.Core.Glue
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport using (transpFill)
module Cubical.Categories.Constructions.Slice {ℓ ℓ' : Level} (C : Precategory ℓ ℓ') (c : C .ob) {{isC : isCategory C}} where
open import Cubical.Data.Sigma
-- just a helper to prevent redundency
TypeC : Type (ℓ-suc (ℓ-max ℓ ℓ'))
TypeC = Type (ℓ-max ℓ ℓ')
-- Components of a slice category
record SliceOb : TypeC where
constructor sliceob
field
{S-ob} : C .ob
S-arr : C [ S-ob , c ]
open SliceOb public
record SliceHom (a b : SliceOb) : Type ℓ' where
constructor slicehom
field
S-hom : C [ S-ob a , S-ob b ]
-- commutative diagram
S-comm : S-hom ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a
open SliceHom public
-- Helpers for working with equality
-- can probably replace these by showing that SliceOb is isomorphic to Sigma and
-- that paths are isomorphic to Sigma? But sounds like that would need a lot of transp
SliceOb-≡-intro : ∀ {a b} {f g}
→ (p : a ≡ b)
→ PathP (λ i → C [ p i , c ]) f g
→ sliceob {a} f ≡ sliceob {b} g
SliceOb-≡-intro p q = λ i → sliceob {p i} (q i)
module _ {xf yg : SliceOb} where
private
x = xf .S-ob
f = xf .S-arr
y = yg .S-ob
g = yg .S-arr
-- a path between slice objects is the "same" as a pair of paths between C obs and C arrows
SOPathIsoPathΣ : Iso (xf ≡ yg) (Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g)
SOPathIsoPathΣ .fun p = (λ i → (p i) .S-ob) , (λ i → (p i) .S-arr)
SOPathIsoPathΣ .inv (p , q) i = sliceob {p i} (q i)
SOPathIsoPathΣ .rightInv _ = refl
SOPathIsoPathΣ .leftInv _ = refl
SOPath≃PathΣ = isoToEquiv SOPathIsoPathΣ
SOPath≡PathΣ = ua (isoToEquiv SOPathIsoPathΣ)
-- intro and elim for working with SliceHom equalities (is there a better way to do this?)
SliceHom-≡-intro : ∀ {a b} {f g} {c₁} {c₂}
→ (p : f ≡ g)
→ PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
→ slicehom f c₁ ≡ slicehom g c₂
SliceHom-≡-intro p q = λ i → slicehom (p i) (q i)
SliceHom-≡-elim : ∀ {a b} {f g} {c₁} {c₂}
→ slicehom f c₁ ≡ slicehom g c₂
→ Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
SliceHom-≡-elim r = (λ i → S-hom (r i)) , λ i → S-comm (r i)
SliceHom-≡-intro' : ∀ {a b} {f g : C [ a .S-ob , b .S-ob ]} {c₁} {c₂}
→ (p : f ≡ g)
→ slicehom f c₁ ≡ slicehom g c₂
SliceHom-≡-intro' {a} {b} {f} {g} {c₁} {c₂} p i = slicehom (p i) (c₁≡c₂ i)
where
c₁≡c₂ : PathP (λ i → (p i) ⋆⟨ C ⟩ (b .S-arr) ≡ a .S-arr) c₁ c₂
c₁≡c₂ = isOfHLevel→isOfHLevelDep 1 (λ _ → isC .isSetHom _ _) c₁ c₂ p
-- SliceHom is isomorphic to the Sigma type with the same components
SliceHom-Σ-Iso : ∀ {a b}
→ Iso (SliceHom a b) (Σ[ h ∈ C [ S-ob a , S-ob b ] ] h ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a)
SliceHom-Σ-Iso .fun (slicehom h c) = h , c
SliceHom-Σ-Iso .inv (h , c) = slicehom h c
SliceHom-Σ-Iso .rightInv = λ x → refl
SliceHom-Σ-Iso .leftInv = λ x → refl
-- Precategory definition
SliceCat : Precategory _ _
SliceCat .ob = SliceOb
SliceCat .Hom[_,_] = SliceHom
SliceCat .id (sliceob {x} f) = slicehom (C .id x) (C .⋆IdL _)
SliceCat ._⋆_ {sliceob j} {sliceob k} {sliceob l} (slicehom f p) (slicehom g p') =
slicehom
(f ⋆⟨ C ⟩ g)
( f ⋆⟨ C ⟩ g ⋆⟨ C ⟩ l
≡⟨ C .⋆Assoc _ _ _ ⟩
f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ l)
≡⟨ cong (λ v → f ⋆⟨ C ⟩ v) p' ⟩
f ⋆⟨ C ⟩ k
≡⟨ p ⟩
j
∎)
SliceCat .⋆IdL (slicehom S-hom S-comm) =
SliceHom-≡-intro (⋆IdL C _) (toPathP (isC .isSetHom _ _ _ _))
SliceCat .⋆IdR (slicehom S-hom S-comm) =
SliceHom-≡-intro (⋆IdR C _) (toPathP (isC .isSetHom _ _ _ _))
SliceCat .⋆Assoc f g h =
SliceHom-≡-intro (⋆Assoc C _ _ _) (toPathP (isC .isSetHom _ _ _ _))
-- SliceCat is a Category
instance
isCatSlice : isCategory SliceCat
isCatSlice .isSetHom {a} {b} (slicehom f c₁) (slicehom g c₂) p q = cong isoP p'≡q'
where
-- paths between SliceHoms are equivalent to the projection paths
p' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
p' = SliceHom-≡-elim p
q' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
q' = SliceHom-≡-elim q
-- we want all paths between (dependent) paths of this type to be equal
B = λ v → v ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a
-- need the groupoidness for dependent paths
homIsGroupoidDep : isOfHLevelDep 2 B
homIsGroupoidDep = isOfHLevel→isOfHLevelDep 2 (λ v x y → isSet→isGroupoid (isC .isSetHom) _ _ x y)
-- we first prove that the projected paths are equal
p'≡q' : p' ≡ q'
p'≡q' = ΣPathP ((isC .isSetHom _ _ _ _) , toPathP (homIsGroupoidDep _ _ _ _ _))
-- and then we can use equivalence to lift these paths up
-- to actual SliceHom paths
isoP = λ g → cong (inv SliceHom-Σ-Iso) (fun (ΣPathIsoPathΣ) g)
-- SliceCat is univalent if C is univalent
module _ ⦃ isU : isUnivalent C ⦄ where
open CatIso
open Iso
module _ { xf yg : SliceOb } where
private
x = xf .S-ob
y = yg .S-ob
-- names for the equivalences/isos
pathIsoEquiv : (x ≡ y) ≃ (CatIso x y)
pathIsoEquiv = univEquiv isU x y
isoPathEquiv : (CatIso x y) ≃ (x ≡ y)
isoPathEquiv = invEquiv pathIsoEquiv
pToIIso' : Iso (x ≡ y) (CatIso x y)
pToIIso' = equivToIso pathIsoEquiv
-- the iso in SliceCat we're given induces an iso in C between x and y
module _ ( cIso@(catiso kc lc s r) : CatIso {C = SliceCat} xf yg ) where
extractIso' : CatIso {C = C} x y
extractIso' .mor = kc .S-hom
extractIso' .inv = lc .S-hom
extractIso' .sec i = (s i) .S-hom
extractIso' .ret i = (r i) .S-hom
instance
preservesUnivalenceSlice : isUnivalent SliceCat
-- we prove the equivalence by going through Iso
preservesUnivalenceSlice .univ xf@(sliceob {x} f) yg@(sliceob {y} g) = isoToIsEquiv sIso
where
-- this is just here because the type checker can't seem to infer xf and yg
pToIIso : Iso (x ≡ y) (CatIso x y)
pToIIso = pToIIso' {xf = xf} {yg}
-- the meat of the proof
sIso : Iso (xf ≡ yg) (CatIso xf yg)
sIso .fun p = pathToIso xf yg p -- we use the normal pathToIso via path induction to get an isomorphism
sIso .inv is@(catiso kc lc s r) = SliceOb-≡-intro x≡y (symP (sym (lc .S-comm) ◁ lf≡f))
where
-- we get a path between xf and yg by combining paths between
-- x and y, and f and g
-- 1. x≡y follows from univalence of C
-- 2. f≡g is more tricky; by commutativity, we know that g ≡ l ⋆ f
-- so we want l to be id; we get this by showing: id ≡ pathToIso x y x≡y ≡ l
-- where the first step follows from path induction, and the second from univalence of C
-- morphisms in C from kc and lc
k = kc .S-hom
l = lc .S-hom
-- extract out the iso between x and y
extractIso : CatIso {C = C} x y
extractIso = extractIso' is
-- and we can use univalence of C to get x ≡ y
x≡y : x ≡ y
x≡y = pToIIso .inv extractIso
-- to show that f ≡ g, we show that l ≡ id
-- by using C's isomorphism
pToI≡id : PathP (λ i → C [ x≡y (~ i) , x ]) (pathToIso {C = C} x y x≡y .inv) (C .id x)
pToI≡id = J (λ y p → PathP (λ i → C [ p (~ i) , x ]) (pathToIso {C = C} x y p .inv) (C .id x))
(λ j → JRefl pToIFam pToIBase j .inv)
x≡y
where
idx = C .id x
pToIFam = (λ z _ → CatIso {C = C} x z)
pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx)
l≡pToI : l ≡ pathToIso {C = C} x y x≡y .inv
l≡pToI i = pToIIso .rightInv extractIso (~ i) .inv
l≡id : PathP (λ i → C [ x≡y (~ i) , x ]) l (C .id x)
l≡id = l≡pToI ◁ pToI≡id
lf≡f : PathP (λ i → C [ x≡y (~ i) , c ]) (l ⋆⟨ C ⟩ f) f
lf≡f = (λ i → (l≡id i) ⋆⟨ C ⟩ f) ▷ C .⋆IdL _
sIso .rightInv is@(catiso kc lc s r) i = catiso (kc'≡kc i) (lc'≡lc i) (s'≡s i) (r'≡r i)
-- we prove rightInv using a combination of univalence and the fact that homs are an h-set
where
kc' = (sIso .fun) (sIso .inv is) .mor
lc' = (sIso .fun) (sIso .inv is) .inv
k' = kc' .S-hom
l' = lc' .S-hom
k = kc .S-hom
l = lc .S-hom
extractIso : CatIso {C = C} x y
extractIso = extractIso' is
-- we do the equality component wise
-- mor
k'≡k : k' ≡ k
k'≡k i = (pToIIso .rightInv extractIso) i .mor
kcom'≡kcom : PathP (λ j → (k'≡k j) ⋆⟨ C ⟩ g ≡ f) (kc' .S-comm) (kc .S-comm)
kcom'≡kcom = isSetHomP1 _ _ λ i → (k'≡k i) ⋆⟨ C ⟩ g
kc'≡kc : kc' ≡ kc
kc'≡kc i = slicehom (k'≡k i) (kcom'≡kcom i)
-- inv
l'≡l : l' ≡ l
l'≡l i = (pToIIso .rightInv extractIso) i .inv
lcom'≡lcom : PathP (λ j → (l'≡l j) ⋆⟨ C ⟩ f ≡ g) (lc' .S-comm) (lc .S-comm)
lcom'≡lcom = isSetHomP1 _ _ λ i → (l'≡l i) ⋆⟨ C ⟩ f
lc'≡lc : lc' ≡ lc
lc'≡lc i = slicehom (l'≡l i) (lcom'≡lcom i)
-- sec
s' = (sIso .fun) (sIso .inv is) .sec
s'≡s : PathP (λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i ≡ SliceCat .id _) s' s
s'≡s = isSetHomP1 _ _ λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i
-- ret
r' = (sIso .fun) (sIso .inv is) .ret
r'≡r : PathP (λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i ≡ SliceCat .id _) r' r
r'≡r = isSetHomP1 _ _ λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i
sIso .leftInv p = p'≡p
-- to show that the round trip is equivalent to the identity
-- we show that this is true for each component (S-ob, S-arr)
-- and then combine
-- specifically, we show that p'Ob≡pOb and p'Mor≡pMor
-- and it follows that p'≡p
where
p' = (sIso .inv) (sIso .fun p)
pOb : x ≡ y
pOb i = (p i) .S-ob
p'Ob : x ≡ y
p'Ob i = (p' i) .S-ob
pMor : PathP (λ i → C [ pOb i , c ]) f g
pMor i = (p i) .S-arr
p'Mor : PathP (λ i → C [ p'Ob i , c ]) f g
p'Mor i = (p' i) .S-arr
-- we first show that it's equivalent to use sIso first then extract, or to extract first than use pToIIso
extractCom : extractIso' (sIso .fun p) ≡ pToIIso .fun pOb
extractCom = J (λ yg' p̃ → extractIso' (pathToIso xf yg' p̃) ≡ pToIIso' {xf = xf} {yg'} .fun (λ i → (p̃ i) .S-ob))
(cong extractIso' (JRefl pToIFam' pToIBase') ∙ sym (JRefl pToIFam pToIBase))
p
where
idx = C .id x
pToIFam = (λ z _ → CatIso {C = C} x z)
pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx)
idxf = SliceCat .id xf
pToIFam' = (λ z _ → CatIso {C = SliceCat} xf z)
pToIBase' = catiso (SliceCat .id xf) idxf (SliceCat .⋆IdL idxf) (SliceCat .⋆IdL idxf)
-- why does this not follow definitionally?
-- from extractCom, we get that performing the roundtrip on pOb gives us back p'Ob
ppp : p'Ob ≡ (pToIIso .inv) (pToIIso .fun pOb)
ppp = cong (pToIIso .inv) extractCom
-- apply univalence of C
-- this gives us the first component that we want
p'Ob≡pOb : p'Ob ≡ pOb
p'Ob≡pOb = ppp ∙ pToIIso .leftInv pOb
-- isSetHom gives us the second component, path between morphisms
p'Mor≡pMor : PathP (λ j → PathP (λ i → C [ (p'Ob≡pOb j) i , c ]) f g) p'Mor pMor
p'Mor≡pMor = isSetHomP2l _ _ p'Mor pMor p'Ob≡pOb
-- we can use the above paths to show that p' ≡ p
p'≡p : p' ≡ p
p'≡p i = comp (λ i' → SOPath≡PathΣ {xf = xf} {yg} (~ i'))
(λ j → λ { (i = i0) → left (~ j) ; (i = i1) → right (~ j) })
(p'Σ≡pΣ i)
where
-- we break up p' and p into their constituent paths
-- first via transport and then via our component definitions from before
-- we show that p'ΣT ≡ p'Σ (and same for p) via univalence
-- and p'Σ≡pΣ follows from our work from above
p'ΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
p'ΣT = transport SOPath≡PathΣ p'
p'Σ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
p'Σ = (p'Ob , p'Mor)
pΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
pΣT = transport SOPath≡PathΣ p
pΣ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
pΣ = (pOb , pMor)-- transport SOPathP≡PathPSO p
-- using the computation rule to ua
p'ΣT≡p'Σ : p'ΣT ≡ p'Σ
p'ΣT≡p'Σ = uaβ SOPath≃PathΣ p'
pΣT≡pΣ : pΣT ≡ pΣ
pΣT≡pΣ = uaβ SOPath≃PathΣ p
p'Σ≡pΣ : p'Σ ≡ pΣ
p'Σ≡pΣ = ΣPathP (p'Ob≡pOb , p'Mor≡pMor)
-- two sides of the square we're connecting
left : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p' p'Σ
left = transport-filler SOPath≡PathΣ p' ▷ p'ΣT≡p'Σ
right : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p pΣ
right = transport-filler SOPath≡PathΣ p ▷ pΣT≡pΣ
-- properties
-- TODO: move to own file
open isIsoC renaming (inv to invC)
-- make a slice isomorphism from just the hom
sliceIso : ∀ {a b} (f : C [ a .S-ob , b .S-ob ]) (c : (f ⋆⟨ C ⟩ b .S-arr) ≡ a .S-arr)
→ isIsoC {C = C} f
→ isIsoC {C = SliceCat} (slicehom f c)
sliceIso f c isof .invC = slicehom (isof .invC) (sym (invMoveL (isIso→areInv isof) c))
sliceIso f c isof .sec = SliceHom-≡-intro' (isof .sec)
sliceIso f c isof .ret = SliceHom-≡-intro' (isof .ret)
| 38.020833
| 126
| 0.52274
|
0b61e755fb073c8d03f1e6bf92ce9b305a5dd2ae
| 871
|
agda
|
Agda
|
theorems/cohomology/CupProduct/OnEM/InLowDegrees2.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/cohomology/CupProduct/OnEM/InLowDegrees2.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/cohomology/CupProduct/OnEM/InLowDegrees2.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.EilenbergMacLane
module cohomology.CupProduct.OnEM.InLowDegrees2 {i} {j} (G : AbGroup i) (H : AbGroup j) where
private
module G = AbGroup G
module H = AbGroup H
module G⊗H = TensorProduct G H
open EMExplicit G⊗H.abgroup
open import cohomology.CupProduct.OnEM.InLowDegrees G H public
open import cohomology.CupProduct.OnEM.CommutativityInLowDegrees
open CP₁₁-comm G H
cp₁₁-embase-r : (x : EM₁ G.grp) → cp₁₁ x embase == [ north ]₂
cp₁₁-embase-r x = CP₁₁Comm.f x embase
module ∧-cp₁₁-Rec =
SmashRec {X = ⊙EM₁ G.grp} {Y = ⊙EM₁ H.grp} {C = EM 2}
cp₁₁
[ north ]₂ [ north ]₂
cp₁₁-embase-r
(λ y → idp)
∧-cp₁₁ : ⊙EM₁ G.grp ∧ ⊙EM₁ H.grp → EM 2
∧-cp₁₁ = ∧-cp₁₁-Rec.f
⊙∧-cp₁₁ : ⊙EM₁ G.grp ⊙∧ ⊙EM₁ H.grp ⊙→ ⊙EM 2
⊙∧-cp₁₁ = ∧-cp₁₁-Rec.f , idp
| 26.393939
| 93
| 0.638347
|
23d8a8720d406ff818bb447af12c038d8e44fcf6
| 265
|
agda
|
Agda
|
test/Succeed/Issue1583.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1583.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1583.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-06-24 Parsing of forall should be like lambda
open import Common.Prelude
open import Common.Product
test : ⊤ × ∀ (B : Set) → B → B -- should parse
test = _ , λ B b → b
test1 : ⊤ × forall (B : Set) → B → B -- should parse
test1 = _ , λ B b → b
| 24.090909
| 62
| 0.611321
|
505b0f0c8174d1b94f0a7d68a4344aab882de3db
| 11,269
|
agda
|
Agda
|
Cubical/Foundations/Id.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Foundations/Id.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Id.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Id, refl and J (with definitional computation rule)
- Basic theory about Id, proved using J
- Lemmas for going back and forth between Path and Id
- Function extensionality for Id
- fiber, isContr, equiv all defined using Id
- The univalence axiom expressed using only Id ([EquivContr])
- Propositional truncation and its elimination principle
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.Id where
open import Cubical.Foundations.Prelude public
hiding ( _≡_ ; _≡⟨_⟩_ ; _∎ ; isPropIsContr)
renaming ( refl to reflPath
; transport to transportPath
; J to JPath
; JRefl to JPathRefl
; sym to symPath
; _∙_ to compPath
; cong to congPath
; funExt to funExtPath
; isContr to isContrPath
; isProp to isPropPath
; isSet to isSetPath
; fst to pr₁ -- as in the HoTT book
; snd to pr₂ )
open import Cubical.Foundations.Equiv
renaming ( fiber to fiberPath
; isEquiv to isEquivPath
; _≃_ to EquivPath
; equivFun to equivFunPath
; isPropIsEquiv to isPropIsEquivPath )
hiding ( equivCtr
; equivIsEquiv )
open import Cubical.Foundations.Univalence
renaming ( EquivContr to EquivContrPath )
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.PropositionalTruncation public
renaming ( squash to squashPath
; rec to recPropTruncPath
; elim to elimPropTruncPath )
open import Cubical.Core.Id public
using (Id; ⟨_,_⟩; faceId; pathId; elimId; _≡_)
private
variable
ℓ ℓ' : Level
A : Type ℓ
-- Version of the constructor for Id where the y is also
-- explicit. This is sometimes useful when it is needed for
-- typechecking (see JId below).
conId : ∀ {x : A} φ (y : A [ φ ↦ (λ _ → x) ])
(w : (Path _ x (outS y)) [ φ ↦ (λ { (φ = i1) → λ _ → x}) ]) →
x ≡ outS y
conId φ _ w = ⟨ φ , outS w ⟩
-- Reflexivity
refl : ∀ {x : A} → x ≡ x
refl {x = x} = ⟨ i1 , (λ _ → x) ⟩
-- Definition of J for Id
module _ {x : A} (P : ∀ (y : A) → Id x y → Type ℓ') (d : P x refl) where
J : ∀ {y : A} (w : x ≡ y) → P y w
J {y = y} = elimId P (λ φ y w → comp (λ i → P _ (conId (φ ∨ ~ i) (inS (outS w i))
(inS (λ j → outS w (i ∧ j)))))
(λ i → λ { (φ = i1) → d}) d) {y = y}
-- Check that J of refl is the identity function
Jdefeq : Path _ (J refl) d
Jdefeq _ = d
-- Basic theory about Id, proved using J
transport : ∀ (B : A → Type ℓ') {x y : A}
→ x ≡ y → B x → B y
transport B {x} p b = J (λ y p → B y) b p
_⁻¹ : {x y : A} → x ≡ y → y ≡ x
_⁻¹ {x = x} p = J (λ z _ → z ≡ x) refl p
ap : ∀ {B : Type ℓ'} (f : A → B) → ∀ {x y : A} → x ≡ y → f x ≡ f y
ap f {x} = J (λ z _ → f x ≡ f z) refl
_∙_ : ∀ {x y z : A} → x ≡ y → y ≡ z → x ≡ z
_∙_ {x = x} p = J (λ y _ → x ≡ y) p
infix 4 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ p ⟩ q = p ∙ q
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- Convert between Path and Id
pathToId : ∀ {x y : A} → Path _ x y → Id x y
pathToId {x = x} = JPath (λ y _ → Id x y) refl
pathToIdRefl : ∀ {x : A} → Path _ (pathToId (λ _ → x)) refl
pathToIdRefl {x = x} = JPathRefl (λ y _ → Id x y) refl
idToPath : ∀ {x y : A} → Id x y → Path _ x y
idToPath {x = x} = J (λ y _ → Path _ x y) (λ _ → x)
idToPathRefl : ∀ {x : A} → Path _ (idToPath {x = x} refl) reflPath
idToPathRefl {x = x} _ _ = x
pathToIdToPath : ∀ {x y : A} → (p : Path _ x y) → Path _ (idToPath (pathToId p)) p
pathToIdToPath {x = x} = JPath (λ y p → Path _ (idToPath (pathToId p)) p)
(λ i → idToPath (pathToIdRefl i))
idToPathToId : ∀ {x y : A} → (p : Id x y) → Path _ (pathToId (idToPath p)) p
idToPathToId {x = x} = J (λ b p → Path _ (pathToId (idToPath p)) p) pathToIdRefl
-- We get function extensionality by going back and forth between Path and Id
funExt : ∀ {B : A → Type ℓ'} {f g : (x : A) → B x} →
((x : A) → f x ≡ g x) → f ≡ g
funExt p = pathToId (λ i x → idToPath (p x) i)
-- Equivalences expressed using Id
fiber : ∀ {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ')
fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (x ≡ y)
record isEquiv {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where
field
equiv-proof : (y : B) → isContr (fiber f y)
open isEquiv public
infix 4 _≃_
_≃_ : ∀ (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ')
A ≃ B = Σ[ f ∈ (A → B) ] (isEquiv f)
equivFun : ∀ {B : Type ℓ'} → A ≃ B → A → B
equivFun e = pr₁ e
equivIsEquiv : ∀ {B : Type ℓ'} (e : A ≃ B) → isEquiv (equivFun e)
equivIsEquiv e = pr₂ e
equivCtr : ∀ {B : Type ℓ'} (e : A ≃ B) (y : B) → fiber (equivFun e) y
equivCtr e y = e .pr₂ .equiv-proof y .pr₁
-- Functions for going between the various definitions. This could
-- also be achieved by making lines in the universe and transporting
-- back and forth along them.
fiberPathToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B} →
fiberPath f y → fiber f y
fiberPathToFiber (x , p) = (x , pathToId p)
fiberToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B} →
fiber f y → fiberPath f y
fiberToFiberPath (x , p) = (x , idToPath p)
fiberToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B}
(p : fiber f y) → Path _ (fiberPathToFiber (fiberToFiberPath p)) p
fiberToFiber (x , p) = λ i → x , idToPathToId p i
fiberPathToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B}
(p : fiberPath f y) → Path _ (fiberToFiberPath (fiberPathToFiber p)) p
fiberPathToFiberPath (x , p) = λ i → x , pathToIdToPath p i
isContrPathToIsContr : isContrPath A → isContr A
isContrPathToIsContr (ctr , p) = (ctr , λ y → pathToId (p y))
isContrToIsContrPath : isContr A → isContrPath A
isContrToIsContrPath (ctr , p) = (ctr , λ y → idToPath (p y))
isPropPathToIsProp : isPropPath A → isProp A
isPropPathToIsProp H x y = pathToId (H x y)
isPropToIsPropPath : isProp A → isPropPath A
isPropToIsPropPath H x y i = idToPath (H x y) i
-- Specialized helper lemmas for going back and forth between
-- isContrPath and isContr:
helper1 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A)
(h : (y : B) → Path B (f (g y)) y) → isContrPath A → isContr B
helper1 f g h (x , p) =
(f x , λ y → pathToId (λ i → hcomp (λ j → λ { (i = i0) → f x
; (i = i1) → h y j })
(f (p (g y) i))))
helper2 : ∀ {A B : Type ℓ} (f : A → B) (g : B → A)
(h : (y : A) → Path A (g (f y)) y) → isContr B → isContrPath A
helper2 {A = A} f g h (x , p) = (g x , λ y → idToPath (rem y))
where
rem : ∀ (y : A) → g x ≡ y
rem y =
g x ≡⟨ ap g (p (f y)) ⟩
g (f y) ≡⟨ pathToId (h y) ⟩
y ∎
-- This proof is essentially the one for proving that isContr with
-- Path is a proposition, but as we are working with Id we have to
-- insert a lof of conversion functions. It is still nice that is
-- works like this though.
isPropIsContr : ∀ (p1 p2 : isContr A) → Path (isContr A) p1 p2
isPropIsContr (a0 , p0) (a1 , p1) j =
( idToPath (p0 a1) j ,
hcomp (λ i → λ { (j = i0) → λ x → idToPathToId (p0 x) i
; (j = i1) → λ x → idToPathToId (p1 x) i })
(λ x → pathToId (λ i → hcomp (λ k → λ { (i = i0) → idToPath (p0 a1) j
; (i = i1) → idToPath (p0 x) (j ∨ k)
; (j = i0) → idToPath (p0 x) (i ∧ k)
; (j = i1) → idToPath (p1 x) i })
(idToPath (p0 (idToPath (p1 x) i)) j))))
-- We now prove that isEquiv is a proposition
isPropIsEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → {f : A → B} → (h1 h2 : isEquiv f) → Path _ h1 h2
equiv-proof (isPropIsEquiv {f = f} h1 h2 i) y =
isPropIsContr {A = fiber f y} (h1 .equiv-proof y) (h2 .equiv-proof y) i
-- Go from a Path equivalence to an Id equivalence
equivPathToEquiv : ∀ {A : Type ℓ} {B : Type ℓ'} → EquivPath A B → A ≃ B
equivPathToEquiv (f , p) =
(f , λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (p .equiv-proof y) })
-- Go from an Id equivalence to a Path equivalence
equivToEquivPath : ∀ {A : Type ℓ} {B : Type ℓ'} → A ≃ B → EquivPath A B
equivToEquivPath (f , p) =
(f , λ { .equiv-proof y → helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y) })
equivToEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → (p : A ≃ B) → Path _ (equivPathToEquiv (equivToEquivPath p)) p
equivToEquiv (f , p) i =
(f , isPropIsEquiv (λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber
(helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y)) }) p i)
-- We can finally prove univalence with Id everywhere from the one for Path
EquivContr : ∀ (A : Type ℓ) → isContr (Σ[ T ∈ Type ℓ ] (T ≃ A))
EquivContr {ℓ = ℓ} A = helper1 f1 f2 f12 (EquivContrPath A)
where
f1 : {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (EquivPath T A) → Σ[ T ∈ Type ℓ ] (T ≃ A)
f1 (x , p) = x , equivPathToEquiv p
f2 : {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (T ≃ A) → Σ[ T ∈ Type ℓ ] (EquivPath T A)
f2 (x , p) = x , equivToEquivPath p
f12 : (y : Σ[ T ∈ Type ℓ ] (T ≃ A)) → Path (Σ[ T ∈ Type ℓ ] (T ≃ A)) (f1 (f2 y)) y
f12 (x , p) i = x , equivToEquiv {A = x} {B = A} p i
-- Propositional truncation
∥∥-isProp : ∀ (x y : ∥ A ∥) → x ≡ y
∥∥-isProp x y = pathToId (squashPath x y)
∥∥-recursion : ∀ {A : Type ℓ} {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P
∥∥-recursion Pprop f x = recPropTruncPath (isPropToIsPropPath Pprop) f x
∥∥-induction : ∀ {A : Type ℓ} {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) →
((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
∥∥-induction Pprop f x = elimPropTruncPath (λ a → isPropToIsPropPath (Pprop a)) f x
-- Univalence
path≡Id : ∀ {ℓ} {A B : Type ℓ} → Path _ (Path _ A B) (Id A B)
path≡Id = isoToPath (iso pathToId idToPath idToPathToId pathToIdToPath )
equivPathToEquivPath : ∀ {ℓ} {A : Type ℓ} {B : Type ℓ} → (p : EquivPath A B) →
Path _ (equivToEquivPath (equivPathToEquiv p)) p
equivPathToEquivPath (f , p) i =
( f , isPropIsEquivPath f (equivToEquivPath (equivPathToEquiv (f , p)) .pr₂) p i )
equivPath≡Equiv : ∀ {ℓ} {A B : Type ℓ} → Path _ (EquivPath A B) (A ≃ B)
equivPath≡Equiv {ℓ} = isoToPath (iso (equivPathToEquiv {ℓ}) equivToEquivPath equivToEquiv equivPathToEquivPath)
univalenceId : ∀ {ℓ} {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalenceId {ℓ} {A = A} {B = B} = equivPathToEquiv rem
where
rem0 : Path _ (Lift (EquivPath A B)) (Lift (A ≃ B))
rem0 = congPath Lift equivPath≡Equiv
rem1 : Path _ (Id A B) (Lift (A ≃ B))
rem1 i = hcomp (λ j → λ { (i = i0) → path≡Id {A = A} {B = B} j
; (i = i1) → rem0 j })
(univalencePath {A = A} {B = B} i)
rem : EquivPath (Id A B) (A ≃ B)
rem = compEquiv (eqweqmap rem1) (invEquiv LiftEquiv)
| 35.888535
| 136
| 0.54752
|
1c63cd733b017de5258df3379dc4287ac260ced1
| 283
|
agda
|
Agda
|
test/Fail/Prop-NoImpredicativity.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Prop-NoImpredicativity.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Prop-NoImpredicativity.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --prop #-}
True : Prop
True = {P : Prop} → P → P
-- Old error (incomprehensible):
-- Set₁ != Set
-- when checking that the expression {P : Prop} → P → P has type Prop
-- New error:
-- Prop₁ != Prop
-- when checking that the expression {P : Prop} → P → P has type Prop
| 21.769231
| 69
| 0.607774
|
0b992b6d8623956567d450780c86d70e80254cc8
| 423
|
agda
|
Agda
|
test/Fail/Issue478.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue478.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue478.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v tc.display:100 #-}
module Issue478 where
record Ko (Q : Set) : Set₁ where
field
T : Set
module Bo (P : Set) (ko : Ko P) where
open Ko ko
err : T
err = Set
{- The error message was:
Set₁ !=< T P ko of type Set₂
when checking that the expression Set has type T P ko
We now get the desired error message:
Set₁ !=< T of type Set₂
when checking that the expression Set has type T
-}
| 16.92
| 55
| 0.64539
|
0b08733a8b25ccc0adae6ae1a34a819523aed3a3
| 7,880
|
agda
|
Agda
|
BasicIS4/Semantics/TarskiOvergluedDyadicGentzen.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIS4/Semantics/TarskiOvergluedDyadicGentzen.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIS4/Semantics/TarskiOvergluedDyadicGentzen.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.
-- Tarski-style semantics with context pairs as concrete worlds, and glueing for α, ▻, and □.
-- Gentzen-style syntax.
module BasicIS4.Semantics.TarskiOvergluedDyadicGentzen where
open import BasicIS4.Syntax.Common public
open import Common.Semantics public
-- Intuitionistic Tarski models.
record Model : Set₁ where
infix 3 _⊩ᵅ_ _[⊢]_
field
-- Forcing for atomic propositions; monotonic.
_⊩ᵅ_ : Cx² Ty Ty → Atom → Set
mono²⊩ᵅ : ∀ {P Π Π′} → Π ⊆² Π′ → Π ⊩ᵅ P → Π′ ⊩ᵅ P
-- Gentzen-style syntax representation; monotonic.
_[⊢]_ : Cx² Ty Ty → Ty → Set
mono²[⊢] : ∀ {A Π Π′} → Π ⊆² Π′ → Π [⊢] A → Π′ [⊢] A
[var] : ∀ {A Γ Δ} → A ∈ Γ → Γ ⁏ Δ [⊢] A
[lam] : ∀ {A B Γ Δ} → Γ , A ⁏ Δ [⊢] B → Γ ⁏ Δ [⊢] A ▻ B
[app] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B → Γ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] B
[mvar] : ∀ {A Γ Δ} → A ∈ Δ → Γ ⁏ Δ [⊢] A
[box] : ∀ {A Γ Δ} → ∅ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] □ A
[unbox] : ∀ {A C Γ Δ} → Γ ⁏ Δ [⊢] □ A → Γ ⁏ Δ , A [⊢] C → Γ ⁏ Δ [⊢] C
[pair] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] B → Γ ⁏ Δ [⊢] A ∧ B
[fst] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B → Γ ⁏ Δ [⊢] A
[snd] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B → Γ ⁏ Δ [⊢] B
[unit] : ∀ {Γ Δ} → Γ ⁏ Δ [⊢] ⊤
infix 3 _[⊢]⋆_
_[⊢]⋆_ : Cx² Ty Ty → Cx Ty → Set
Π [⊢]⋆ ∅ = 𝟙
Π [⊢]⋆ Ξ , A = Π [⊢]⋆ Ξ × Π [⊢] A
open Model {{…}} public
-- Forcing in a particular model.
module _ {{_ : Model}} where
infix 3 _⊩_
_⊩_ : Cx² Ty Ty → Ty → Set
Π ⊩ α P = Glue (Π [⊢] α P) (Π ⊩ᵅ P)
Π ⊩ A ▻ B = ∀ {Π′} → Π ⊆² Π′ → Glue (Π′ [⊢] A ▻ B) (Π′ ⊩ A → Π′ ⊩ B)
Π ⊩ □ A = ∀ {Π′} → Π ⊆² Π′ → Glue (Π′ [⊢] □ A) (Π′ ⊩ A)
Π ⊩ A ∧ B = Π ⊩ A × Π ⊩ B
Π ⊩ ⊤ = 𝟙
infix 3 _⊩⋆_
_⊩⋆_ : Cx² Ty Ty → Cx Ty → Set
Π ⊩⋆ ∅ = 𝟙
Π ⊩⋆ Ξ , A = Π ⊩⋆ Ξ × Π ⊩ A
-- Monotonicity with respect to context inclusion.
module _ {{_ : Model}} where
mono²⊩ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊩ A → Π′ ⊩ A
mono²⊩ {α P} ψ s = mono²[⊢] ψ (syn s) ⅋ mono²⊩ᵅ ψ (sem s)
mono²⊩ {A ▻ B} ψ s = λ ψ′ → s (trans⊆² ψ ψ′)
mono²⊩ {□ A} ψ s = λ ψ′ → s (trans⊆² ψ ψ′)
mono²⊩ {A ∧ B} ψ s = mono²⊩ {A} ψ (π₁ s) , mono²⊩ {B} ψ (π₂ s)
mono²⊩ {⊤} ψ s = ∙
mono²⊩⋆ : ∀ {Ξ Π Π′} → Π ⊆² Π′ → Π ⊩⋆ Ξ → Π′ ⊩⋆ Ξ
mono²⊩⋆ {∅} ψ ∙ = ∙
mono²⊩⋆ {Ξ , A} ψ (ts , t) = mono²⊩⋆ ψ ts , mono²⊩ {A} ψ t
-- Extraction of syntax representation in a particular model.
module _ {{_ : Model}} where
reifyʳ : ∀ {A Π} → Π ⊩ A → Π [⊢] A
reifyʳ {α P} s = syn s
reifyʳ {A ▻ B} s = syn (s refl⊆²)
reifyʳ {□ A} s = syn (s refl⊆²)
reifyʳ {A ∧ B} s = [pair] (reifyʳ {A} (π₁ s)) (reifyʳ {B} (π₂ s))
reifyʳ {⊤} s = [unit]
reifyʳ⋆ : ∀ {Ξ Π} → Π ⊩⋆ Ξ → Π [⊢]⋆ Ξ
reifyʳ⋆ {∅} ∙ = ∙
reifyʳ⋆ {Ξ , A} (ts , t) = reifyʳ⋆ ts , reifyʳ t
-- Shorthand for variables.
module _ {{_ : Model}} where
[v₀] : ∀ {A Γ Δ} → Γ , A ⁏ Δ [⊢] A
[v₀] = [var] i₀
[v₁] : ∀ {A B Γ Δ} → Γ , A , B ⁏ Δ [⊢] A
[v₁] = [var] i₁
[v₂] : ∀ {A B C Γ Δ} → Γ , A , B , C ⁏ Δ [⊢] A
[v₂] = [var] i₂
[mv₀] : ∀ {A Γ Δ} → Γ ⁏ Δ , A [⊢] A
[mv₀] = [mvar] i₀
[mv₁] : ∀ {A B Γ Δ} → Γ ⁏ Δ , A , B [⊢] A
[mv₁] = [mvar] i₁
[mv₂] : ∀ {A B C Γ Δ} → Γ ⁏ Δ , A , B , C [⊢] A
[mv₂] = [mvar] i₂
-- Useful theorems in functional form.
module _ {{_ : Model}} where
[mlam] : ∀ {A B Γ Δ} → Γ ⁏ Δ , A [⊢] B → Γ ⁏ Δ [⊢] □ A ▻ B
[mlam] t = [lam] ([unbox] [v₀] (mono²[⊢] (weak⊆ , refl⊆) t))
[multicut] : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ [⊢]⋆ Ξ → Ξ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] A
[multicut] {∅} ∙ u = mono²[⊢] (bot⊆ , refl⊆) u
[multicut] {Ξ , B} (ts , t) u = [app] ([multicut] ts ([lam] u)) t
[mmulticut] : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ [⊢]⋆ □⋆ Ξ → Γ ⁏ Ξ [⊢] A → Γ ⁏ Δ [⊢] A
[mmulticut] {∅} ∙ u = mono²[⊢] (refl⊆ , bot⊆) u
[mmulticut] {Ξ , B} (ts , t) u = [app] ([mmulticut] ts ([mlam] u)) t
[multicut²] : ∀ {Ξ Ξ′ A Γ Δ} → Γ ⁏ Δ [⊢]⋆ Ξ → Γ ⁏ Δ [⊢]⋆ □⋆ Ξ′ → Ξ ⁏ Ξ′ [⊢] A → Γ ⁏ Δ [⊢] A
[multicut²] {∅} ∙ us v = [mmulticut] us (mono²[⊢] (bot⊆ , refl⊆) v)
[multicut²] {Ξ , B} (ts , t) us v = [app] ([multicut²] ts us ([lam] v)) t
[dist] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] □ (A ▻ B) → Γ ⁏ Δ [⊢] □ A → Γ ⁏ Δ [⊢] □ B
[dist] t u = [unbox] t ([unbox] (mono²[⊢] (refl⊆ , weak⊆) u) ([box] ([app] [mv₁] [mv₀])))
[up] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A → Γ ⁏ Δ [⊢] □ □ A
[up] t = [unbox] t ([box] ([box] [mv₀]))
[down] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A → Γ ⁏ Δ [⊢] A
[down] t = [unbox] t [mv₀]
-- Useful theorems in combinatory form.
module _ {{_ : Model}} where
[ci] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] A ▻ A
[ci] = [lam] [v₀]
[ck] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B ▻ A
[ck] = [lam] ([lam] [v₁])
[cs] : ∀ {A B C Γ Δ} → Γ ⁏ Δ [⊢] (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
[cs] = [lam] ([lam] ([lam] ([app] ([app] [v₂] [v₀]) ([app] [v₁] [v₀]))))
[cdist] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] □ (A ▻ B) ▻ □ A ▻ □ B
[cdist] = [lam] ([lam] ([dist] [v₁] [v₀]))
[cup] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A ▻ □ □ A
[cup] = [lam] ([up] [v₀])
[cdown] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A ▻ A
[cdown] = [lam] ([down] [v₀])
[cpair] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B ▻ A ∧ B
[cpair] = [lam] ([lam] ([pair] [v₁] [v₀]))
[cfst] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B ▻ A
[cfst] = [lam] ([fst] [v₀])
[csnd] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B ▻ B
[csnd] = [lam] ([snd] [v₀])
-- Additional useful equipment.
module _ {{_ : Model}} where
_⟪$⟫_ : ∀ {A B Π} → Π ⊩ A ▻ B → Π ⊩ A → Π ⊩ B
s ⟪$⟫ a = sem (s refl⊆²) a
⟪K⟫ : ∀ {A B Π} → Π ⊩ A → Π ⊩ B ▻ A
⟪K⟫ {A} a ψ = let a′ = mono²⊩ {A} ψ a
in [app] [ck] (reifyʳ a′) ⅋ K a′
⟪S⟫ : ∀ {A B C Π} → Π ⊩ A ▻ B ▻ C → Π ⊩ A ▻ B → Π ⊩ A → Π ⊩ C
⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a)
⟪S⟫′ : ∀ {A B C Π} → Π ⊩ A ▻ B ▻ C → Π ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ {A} {B} {C} s₁ ψ = let s₁′ = mono²⊩ {A ▻ B ▻ C} ψ s₁
t = syn (s₁′ refl⊆²)
in [app] [cs] t ⅋ λ s₂ ψ′ →
let s₁″ = mono²⊩ {A ▻ B ▻ C} (trans⊆² ψ ψ′) s₁
s₂′ = mono²⊩ {A ▻ B} ψ′ s₂
t′ = syn (s₁″ refl⊆²)
u = syn (s₂′ refl⊆²)
in [app] ([app] [cs] t′) u ⅋ ⟪S⟫ s₁″ s₂′
_⟪D⟫_ : ∀ {A B Π} → Π ⊩ □ (A ▻ B) → Π ⊩ □ A → Π ⊩ □ B
(s₁ ⟪D⟫ s₂) ψ = let t ⅋ s₁′ = s₁ ψ
u ⅋ a = s₂ ψ
in [app] ([app] [cdist] t) u ⅋ s₁′ ⟪$⟫ a
_⟪D⟫′_ : ∀ {A B Π} → Π ⊩ □ (A ▻ B) → Π ⊩ □ A ▻ □ B
_⟪D⟫′_ {A} {B} s₁ ψ = let s₁′ = mono²⊩ {□ (A ▻ B)} ψ s₁
in [app] [cdist] (reifyʳ (λ {_} ψ′ → s₁′ ψ′)) ⅋ _⟪D⟫_ s₁′
⟪↑⟫ : ∀ {A Π} → Π ⊩ □ A → Π ⊩ □ □ A
⟪↑⟫ {A} s ψ = [app] [cup] (syn (s ψ)) ⅋ λ ψ′ → s (trans⊆² ψ ψ′)
⟪↓⟫ : ∀ {A Π} → Π ⊩ □ A → Π ⊩ A
⟪↓⟫ s = sem (s refl⊆²)
_⟪,⟫′_ : ∀ {A B Π} → Π ⊩ A → Π ⊩ B ▻ A ∧ B
_⟪,⟫′_ {A} a ψ = let a′ = mono²⊩ {A} ψ a
in [app] [cpair] (reifyʳ a′) ⅋ _,_ a′
-- Forcing in a particular world of a particular model, for sequents.
module _ {{_ : Model}} where
infix 3 _⊩_⇒_
_⊩_⇒_ : Cx² Ty Ty → Cx² Ty Ty → Ty → Set
Π ⊩ Γ ⁏ Δ ⇒ A = Π ⊩⋆ Γ → Π ⊩⋆ □⋆ Δ → Π ⊩ A
infix 3 _⊩_⇒⋆_
_⊩_⇒⋆_ : Cx² Ty Ty → Cx² Ty Ty → Cx Ty → Set
Π ⊩ Γ ⁏ Δ ⇒⋆ Ξ = Π ⊩⋆ Γ → Π ⊩⋆ □⋆ Δ → Π ⊩⋆ Ξ
-- Entailment, or forcing in all worlds of all models, for sequents.
infix 3 _⊨_
_⊨_ : Cx² Ty Ty → Ty → Set₁
Π ⊨ A = ∀ {{_ : Model}} {w : Cx² Ty Ty} → w ⊩ Π ⇒ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx² Ty Ty → Cx Ty → Set₁
Π ⊨⋆ Ξ = ∀ {{_ : Model}} {w : Cx² Ty Ty} → w ⊩ Π ⇒⋆ Ξ
-- Additional useful equipment, for sequents.
module _ {{_ : Model}} where
lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩⋆ Γ → w ⊩ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
mlookup : ∀ {A Δ w} → A ∈ Δ → w ⊩⋆ □⋆ Δ → w ⊩ A
mlookup top (γ , s) = sem (s refl⊆²)
mlookup (pop i) (γ , s) = mlookup i γ
-- TODO: More equipment.
| 31.774194
| 93
| 0.393401
|
c5f861f73809644bc58f98442646c60d8aca8939
| 609
|
agda
|
Agda
|
test/Fail/Issue1035.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1035.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1035.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
data * : Set where ! : *
postulate
prop : ∀ x → x ≡ !
record StrictTotalOrder : Set where
field compare : *
open StrictTotalOrder
module M (Key : StrictTotalOrder) where
postulate
intersection′-₁ : ∀ x → x ≡ compare Key
-- Doesn't termination check, but shouldn't get __IMPOSSIBLE__
-- when termination checking!
to-∈-intersection′ : * → * → Set
to-∈-intersection′ x h with intersection′-₁ x
to-∈-intersection′ ._ h | refl with prop h
to-∈-intersection′ ._ ._ | refl | refl = to-∈-intersection′ ! !
| 23.423077
| 71
| 0.610837
|
18e96ad59586e3e8040cd85b580ac8a3e4a0ed28
| 1,051
|
agda
|
Agda
|
Data/List/Kleene/Relation/Unary/All.agda
|
oisdk/agda-kleene-lists
|
a7e99bc288e12e83440c891dbd3e5077d9b1657e
|
[
"MIT"
] | null | null | null |
Data/List/Kleene/Relation/Unary/All.agda
|
oisdk/agda-kleene-lists
|
a7e99bc288e12e83440c891dbd3e5077d9b1657e
|
[
"MIT"
] | null | null | null |
Data/List/Kleene/Relation/Unary/All.agda
|
oisdk/agda-kleene-lists
|
a7e99bc288e12e83440c891dbd3e5077d9b1657e
|
[
"MIT"
] | null | null | null |
module Data.List.Kleene.Relation.Unary.All where
open import Data.List.Kleene.Base
open import Relation.Unary
open import Relation.Nullary
open import Level using (_⊔_)
open import Function
mutual
record All⁺ {a p} {A : Set a} (P : Pred A p) (xs : A ⁺) : Set (a ⊔ p) where
constructor P⟨_&_⟩
inductive
field
P⟨head⟩ : P (head xs)
P⟨tail⟩ : All⋆ P (tail xs)
data All⋆ {a p} {A : Set a} (P : Pred A p) : Pred (A ⋆) (a ⊔ p) where
P⟨[]⟩ : All⋆ P []
P⟨∹_⟩ : ∀ {xs} → All⁺ P xs → All⋆ P (∹ xs)
open All⁺ public
module _ {a p} {A : Set a} {P : Pred A p} where
mutual
all⋆ : Decidable P → Decidable (All⋆ P)
all⋆ p? [] = yes P⟨[]⟩
all⋆ p? (∹ xs) with all⁺ p? xs
all⋆ p? (∹ xs) | yes p = yes P⟨∹ p ⟩
all⋆ p? (∹ xs) | no ¬p = no λ { P⟨∹ x ⟩ → ¬p x }
all⁺ : Decidable P → Decidable (All⁺ P)
all⁺ p? xs with p? (head xs) | all⋆ p? (tail xs)
all⁺ p? xs | no ¬p | ys = no (¬p ∘ P⟨head⟩)
all⁺ p? xs | yes p | yes ps = yes P⟨ p & ps ⟩
all⁺ p? xs | yes p | no ¬p = no (¬p ∘ P⟨tail⟩)
| 28.405405
| 77
| 0.52236
|
c5f2f675b4ed29a5cff78c9c7a25c50c0f44340d
| 35,194
|
agda
|
Agda
|
Agda/11-truncation-levels.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/11-truncation-levels.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/11-truncation-levels.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 30
|
2018-09-26T09:08:57.000Z
|
2022-03-16T00:33:50.000Z
|
{-# OPTIONS --without-K --exact-split --safe #-}
module 11-truncation-levels where
import 10-fundamental-theorem
open 10-fundamental-theorem public
-- Section 8.1 Propositions
is-prop :
{i : Level} (A : UU i) → UU i
is-prop A = (x y : A) → is-contr (Id x y)
{- We introduce the universe of all propositions. -}
UU-Prop :
(l : Level) → UU (lsuc l)
UU-Prop l = Σ (UU l) is-prop
type-Prop :
{l : Level} → UU-Prop l → UU l
type-Prop P = pr1 P
is-prop-type-Prop :
{l : Level} (P : UU-Prop l) → is-prop (type-Prop P)
is-prop-type-Prop P = pr2 P
{- The empty type is a proposition. -}
abstract
is-prop-empty : is-prop empty
is-prop-empty ()
empty-Prop : UU-Prop lzero
empty-Prop = pair empty is-prop-empty
abstract
is-prop-unit : is-prop unit
is-prop-unit = is-prop-is-contr is-contr-unit
unit-Prop : UU-Prop lzero
unit-Prop = pair unit is-prop-unit
is-prop' :
{i : Level} (A : UU i) → UU i
is-prop' A = (x y : A) → Id x y
abstract
is-prop-is-prop' :
{i : Level} {A : UU i} → is-prop' A → is-prop A
is-prop-is-prop' {i} {A} H x y =
pair
( (inv (H x x)) ∙ (H x y))
( ind-Id x
( λ z p → Id ((inv (H x x)) ∙ (H x z)) p)
( left-inv (H x x)) y)
abstract
is-prop'-is-prop :
{i : Level} {A : UU i} → is-prop A → is-prop' A
is-prop'-is-prop H x y = pr1 (H x y)
abstract
is-contr-is-prop-inh :
{i : Level} {A : UU i} → is-prop A → A → is-contr A
is-contr-is-prop-inh H a = pair a (is-prop'-is-prop H a)
abstract
is-prop-is-contr-if-inh :
{i : Level} {A : UU i} → (A → is-contr A) → is-prop A
is-prop-is-contr-if-inh H x y = is-prop-is-contr (H x) x y
is-subtype :
{i j : Level} {A : UU i} (B : A → UU j) → UU (i ⊔ j)
is-subtype B = (x : _) → is-prop (B x)
double-structure-swap :
{l1 l2 l3 : Level} (A : UU l1) (B : A → UU l2) (C : A → UU l3) →
Σ (Σ A B) (λ t → C (pr1 t)) → Σ (Σ A C) (λ t → B (pr1 t))
double-structure-swap A B C (pair (pair a b) c) = (pair (pair a c) b)
htpy-double-structure-swap :
{l1 l2 l3 : Level} (A : UU l1) (B : A → UU l2) (C : A → UU l3) →
((double-structure-swap A C B) ∘ (double-structure-swap A B C)) ~ id
htpy-double-structure-swap A B C (pair (pair a b) c) =
eq-pair (eq-pair refl refl) refl
is-equiv-double-structure-swap :
{l1 l2 l3 : Level} (A : UU l1) (B : A → UU l2) (C : A → UU l3) →
is-equiv (double-structure-swap A B C)
is-equiv-double-structure-swap A B C =
is-equiv-has-inverse
( double-structure-swap A C B)
( htpy-double-structure-swap A C B)
( htpy-double-structure-swap A B C)
{- The following is a general construction that will help us show that
the identity type of a subtype agrees with the identity type of the
original type. We already know that the first projection of a family of
propositions is an embedding, but the following lemma still has its uses. -}
abstract
is-contr-total-Eq-substructure :
{l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {P : A → UU l3} →
is-contr (Σ A B) → (is-subtype P) → (a : A) (b : B a) (p : P a) →
is-contr (Σ (Σ A P) (λ t → B (pr1 t)))
is-contr-total-Eq-substructure {A = A} {B} {P}
is-contr-AB is-subtype-P a b p =
is-contr-is-equiv
( Σ (Σ A B) (λ t → P (pr1 t)))
( double-structure-swap A P B)
( is-equiv-double-structure-swap A P B)
( is-contr-is-equiv'
( P a)
( left-unit-law-Σ-map-gen (λ t → P (pr1 t)) is-contr-AB (pair a b))
( is-equiv-left-unit-law-Σ-map-gen _ is-contr-AB (pair a b))
( is-contr-is-prop-inh (is-subtype-P a) p))
Eq-total-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} → is-subtype B →
(Σ A B) → (Σ A B) → UU l1
Eq-total-subtype is-subtype-B p p' = Id (pr1 p) (pr1 p')
reflexive-Eq-total-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p : Σ A B) → Eq-total-subtype is-subtype-B p p
reflexive-Eq-total-subtype is-subtype-B (pair x y) = refl
Eq-total-subtype-eq :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p p' : Σ A B) → Id p p' → Eq-total-subtype is-subtype-B p p'
Eq-total-subtype-eq is-subtype-B p .p refl =
reflexive-Eq-total-subtype is-subtype-B p
is-contr-total-Eq-total-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p : Σ A B) → is-contr (Σ (Σ A B) (Eq-total-subtype is-subtype-B p))
is-contr-total-Eq-total-subtype is-subtype-B (pair x y) =
is-contr-total-Eq-substructure
( is-contr-total-path x)
( is-subtype-B)
x refl y
is-equiv-Eq-total-subtype-eq :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p p' : Σ A B) → is-equiv (Eq-total-subtype-eq is-subtype-B p p')
is-equiv-Eq-total-subtype-eq is-subtype-B p =
fundamental-theorem-id p
( reflexive-Eq-total-subtype is-subtype-B p)
( is-contr-total-Eq-total-subtype is-subtype-B p)
( Eq-total-subtype-eq is-subtype-B p)
equiv-Eq-total-subtype-eq :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p p' : Σ A B) → (Id p p') ≃ (Eq-total-subtype is-subtype-B p p')
equiv-Eq-total-subtype-eq is-subtype-B p p' =
pair
( Eq-total-subtype-eq is-subtype-B p p')
( is-equiv-Eq-total-subtype-eq is-subtype-B p p')
eq-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
{p p' : Σ A B} → Eq-total-subtype is-subtype-B p p' → Id p p'
eq-subtype is-subtype-B {p} {p'} =
inv-is-equiv (is-equiv-Eq-total-subtype-eq is-subtype-B p p')
-- Section 8.2 Sets
is-set :
{i : Level} → UU i → UU i
is-set A = (x y : A) → is-prop (Id x y)
UU-Set :
(i : Level) → UU (lsuc i)
UU-Set i = Σ (UU i) is-set
type-Set :
{l : Level} → UU-Set l → UU l
type-Set X = pr1 X
is-set-type-Set :
{l : Level} (X : UU-Set l) → is-set (type-Set X)
is-set-type-Set X = pr2 X
axiom-K :
{i : Level} → UU i → UU i
axiom-K A = (x : A) (p : Id x x) → Id refl p
abstract
is-set-axiom-K :
{i : Level} (A : UU i) → axiom-K A → is-set A
is-set-axiom-K A H x y =
is-prop-is-prop' (ind-Id x (λ z p → (q : Id x z) → Id p q) (H x) y)
abstract
axiom-K-is-set :
{i : Level} (A : UU i) → is-set A → axiom-K A
axiom-K-is-set A H x p =
( inv (contraction (is-contr-is-prop-inh (H x x) refl) refl)) ∙
( contraction (is-contr-is-prop-inh (H x x) refl) p)
abstract
is-equiv-prop-in-id :
{i j : Level} {A : UU i}
(R : A → A → UU j)
(p : (x y : A) → is-prop (R x y))
(ρ : (x : A) → R x x)
(i : (x y : A) → R x y → Id x y) →
(x y : A) → is-equiv (i x y)
is-equiv-prop-in-id R p ρ i x =
fundamental-theorem-id-retr x (i x)
(λ y → pair
(ind-Id x (λ z p → R x z) (ρ x) y)
((λ r → is-prop'-is-prop (p x y) _ r)))
abstract
is-prop-is-equiv :
{i j : Level} {A : UU i} (B : UU j) (f : A → B) (E : is-equiv f) →
is-prop B → is-prop A
is-prop-is-equiv B f E H x y =
is-contr-is-equiv _ (ap f {x} {y}) (is-emb-is-equiv f E x y) (H (f x) (f y))
is-prop-equiv :
{i j : Level} {A : UU i} (B : UU j) (e : A ≃ B) → is-prop B → is-prop A
is-prop-equiv B (pair f is-equiv-f) = is-prop-is-equiv B f is-equiv-f
abstract
is-prop-is-equiv' :
{i j : Level} (A : UU i) {B : UU j} (f : A → B) (E : is-equiv f) →
is-prop A → is-prop B
is-prop-is-equiv' A f E H =
is-prop-is-equiv _ (inv-is-equiv E) (is-equiv-inv-is-equiv E) H
is-prop-equiv' :
{i j : Level} (A : UU i) {B : UU j} (e : A ≃ B) → is-prop A → is-prop B
is-prop-equiv' A (pair f is-equiv-f) = is-prop-is-equiv' A f is-equiv-f
abstract
is-set-prop-in-id :
{i j : Level} {A : UU i} (R : A → A → UU j)
(p : (x y : A) → is-prop (R x y))
(ρ : (x : A) → R x x)
(i : (x y : A) → R x y → Id x y) →
is-set A
is-set-prop-in-id R p ρ i x y =
is-prop-is-equiv'
( R x y)
( i x y)
( is-equiv-prop-in-id R p ρ i x y) (p x y)
abstract
is-prop-Eq-ℕ :
(n m : ℕ) → is-prop (Eq-ℕ n m)
is-prop-Eq-ℕ zero-ℕ zero-ℕ = is-prop-unit
is-prop-Eq-ℕ zero-ℕ (succ-ℕ m) = is-prop-empty
is-prop-Eq-ℕ (succ-ℕ n) zero-ℕ = is-prop-empty
is-prop-Eq-ℕ (succ-ℕ n) (succ-ℕ m) = is-prop-Eq-ℕ n m
abstract
is-set-ℕ : is-set ℕ
is-set-ℕ =
is-set-prop-in-id
Eq-ℕ
is-prop-Eq-ℕ
refl-Eq-ℕ
eq-Eq-ℕ
ℕ-Set : UU-Set lzero
ℕ-Set = pair ℕ is-set-ℕ
-- Section 8.3 General truncation levels
data 𝕋 : UU lzero where
neg-two-𝕋 : 𝕋
succ-𝕋 : 𝕋 → 𝕋
neg-one-𝕋 : 𝕋
neg-one-𝕋 = succ-𝕋 (neg-two-𝕋)
zero-𝕋 : 𝕋
zero-𝕋 = succ-𝕋 (neg-one-𝕋)
one-𝕋 : 𝕋
one-𝕋 = succ-𝕋 (zero-𝕋)
ℕ-in-𝕋 : ℕ → 𝕋
ℕ-in-𝕋 zero-ℕ = zero-𝕋
ℕ-in-𝕋 (succ-ℕ n) = succ-𝕋 (ℕ-in-𝕋 n)
-- Probably it is better to define this where we first need it.
add-𝕋 : 𝕋 → 𝕋 → 𝕋
add-𝕋 neg-two-𝕋 neg-two-𝕋 = neg-two-𝕋
add-𝕋 neg-two-𝕋 (succ-𝕋 neg-two-𝕋) = neg-two-𝕋
add-𝕋 neg-two-𝕋 (succ-𝕋 (succ-𝕋 y)) = y
add-𝕋 (succ-𝕋 neg-two-𝕋) neg-two-𝕋 = neg-two-𝕋
add-𝕋 (succ-𝕋 neg-two-𝕋) (succ-𝕋 y) = y
add-𝕋 (succ-𝕋 (succ-𝕋 neg-two-𝕋)) y = y
add-𝕋 (succ-𝕋 (succ-𝕋 (succ-𝕋 x))) y = succ-𝕋 (add-𝕋 (succ-𝕋 (succ-𝕋 x)) y)
is-trunc : {i : Level} (k : 𝕋) → UU i → UU i
is-trunc neg-two-𝕋 A = is-contr A
is-trunc (succ-𝕋 k) A = (x y : A) → is-trunc k (Id x y)
-- We introduce some notation for the special case of 1-types --
is-1-type : {l : Level} → UU l → UU l
is-1-type = is-trunc one-𝕋
UU-1-Type : (l : Level) → UU (lsuc l)
UU-1-Type l = Σ (UU l) is-1-type
type-1-Type :
{l : Level} → UU-1-Type l → UU l
type-1-Type = pr1
is-1-type-type-1-Type :
{l : Level} (A : UU-1-Type l) → is-1-type (type-1-Type A)
is-1-type-type-1-Type = pr2
-- We introduce some notation for the special case of 2-types --
is-2-type : {l : Level} → UU l → UU l
is-2-type = is-trunc (succ-𝕋 one-𝕋)
UU-2-Type : (l : Level) → UU (lsuc l)
UU-2-Type l = Σ (UU l) is-2-type
type-2-Type :
{l : Level} → UU-2-Type l → UU l
type-2-Type = pr1
is-2-type-type-2-Type :
{l : Level} (A : UU-2-Type l) → is-2-type (type-2-Type A)
is-2-type-type-2-Type = pr2
-- We introduce some notation for the universe of k-truncated types --
UU-Truncated-Type : 𝕋 → (l : Level) → UU (lsuc l)
UU-Truncated-Type k l = Σ (UU l) (is-trunc k)
type-Truncated-Type :
(k : 𝕋) {l : Level} → UU-Truncated-Type k l → UU l
type-Truncated-Type k = pr1
is-trunc-type-Truncated-Type :
(k : 𝕋) {l : Level} (A : UU-Truncated-Type k l) →
is-trunc k (type-Truncated-Type k A)
is-trunc-type-Truncated-Type k = pr2
-- We show that if a type is k-truncated, then it is (k+1)-truncated. --
abstract
is-trunc-succ-is-trunc :
(k : 𝕋) {i : Level} {A : UU i} →
is-trunc k A → is-trunc (succ-𝕋 k) A
is-trunc-succ-is-trunc neg-two-𝕋 H =
is-prop-is-contr H
is-trunc-succ-is-trunc (succ-𝕋 k) H x y =
is-trunc-succ-is-trunc k (H x y)
truncated-type-succ-Truncated-Type :
(k : 𝕋) {l : Level} → UU-Truncated-Type k l → UU-Truncated-Type (succ-𝕋 k) l
truncated-type-succ-Truncated-Type k A =
pair
( type-Truncated-Type k A)
( is-trunc-succ-is-trunc k (is-trunc-type-Truncated-Type k A))
set-Prop :
{l : Level} → UU-Prop l → UU-Set l
set-Prop P = truncated-type-succ-Truncated-Type neg-one-𝕋 P
1-type-Set :
{l : Level} → UU-Set l → UU-1-Type l
1-type-Set A = truncated-type-succ-Truncated-Type zero-𝕋 A
-- We show that k-truncated types are closed under equivalences --
abstract
is-trunc-is-equiv :
{i j : Level} (k : 𝕋) {A : UU i} (B : UU j) (f : A → B) → is-equiv f →
is-trunc k B → is-trunc k A
is-trunc-is-equiv neg-two-𝕋 B f is-equiv-f H =
is-contr-is-equiv B f is-equiv-f H
is-trunc-is-equiv (succ-𝕋 k) B f is-equiv-f H x y =
is-trunc-is-equiv k (Id (f x) (f y)) (ap f {x} {y})
(is-emb-is-equiv f is-equiv-f x y) (H (f x) (f y))
abstract
is-set-is-equiv :
{i j : Level} {A : UU i} (B : UU j) (f : A → B) → is-equiv f →
is-set B → is-set A
is-set-is-equiv = is-trunc-is-equiv zero-𝕋
abstract
is-trunc-equiv :
{i j : Level} (k : 𝕋) {A : UU i} (B : UU j) (e : A ≃ B) →
is-trunc k B → is-trunc k A
is-trunc-equiv k B (pair f is-equiv-f) =
is-trunc-is-equiv k B f is-equiv-f
abstract
is-set-equiv :
{i j : Level} {A : UU i} (B : UU j) (e : A ≃ B) →
is-set B → is-set A
is-set-equiv = is-trunc-equiv zero-𝕋
abstract
is-trunc-is-equiv' :
{i j : Level} (k : 𝕋) (A : UU i) {B : UU j} (f : A → B) →
is-equiv f → is-trunc k A → is-trunc k B
is-trunc-is-equiv' k A f is-equiv-f is-trunc-A =
is-trunc-is-equiv k A
( inv-is-equiv is-equiv-f)
( is-equiv-inv-is-equiv is-equiv-f)
( is-trunc-A)
abstract
is-set-is-equiv' :
{i j : Level} (A : UU i) {B : UU j} (f : A → B) → is-equiv f →
is-set A → is-set B
is-set-is-equiv' = is-trunc-is-equiv' zero-𝕋
abstract
is-trunc-equiv' :
{i j : Level} (k : 𝕋) (A : UU i) {B : UU j} (e : A ≃ B) →
is-trunc k A → is-trunc k B
is-trunc-equiv' k A (pair f is-equiv-f) =
is-trunc-is-equiv' k A f is-equiv-f
abstract
is-set-equiv' :
{i j : Level} (A : UU i) {B : UU j} (e : A ≃ B) →
is-set A → is-set B
is-set-equiv' = is-trunc-equiv' zero-𝕋
-- We show that if A embeds into a (k+1)-type B, then A is a (k+1)-type. --
abstract
is-trunc-succ-is-emb : {i j : Level} (k : 𝕋) {A : UU i} {B : UU j}
(f : A → B) → is-emb f → is-trunc (succ-𝕋 k) B → is-trunc (succ-𝕋 k) A
is-trunc-succ-is-emb k f Ef H x y =
is-trunc-is-equiv k (Id (f x) (f y)) (ap f {x} {y}) (Ef x y) (H (f x) (f y))
is-trunc-map :
{i j : Level} (k : 𝕋) {A : UU i} {B : UU j} → (A → B) → UU (i ⊔ j)
is-trunc-map k f = (y : _) → is-trunc k (fib f y)
trunc-map : {i j : Level} (k : 𝕋) (A : UU i) (B : UU j) → UU (i ⊔ j)
trunc-map k A B = Σ (A → B) (is-trunc-map k)
abstract
is-trunc-pr1-is-trunc-fam :
{i j : Level} (k : 𝕋) {A : UU i} (B : A → UU j) →
((x : A) → is-trunc k (B x)) → is-trunc-map k (pr1 {i} {j} {A} {B})
is-trunc-pr1-is-trunc-fam k B H x =
is-trunc-is-equiv k
( B x)
( fib-fam-fib-pr1 B x)
( is-equiv-fib-fam-fib-pr1 B x)
( H x)
trunc-pr1 :
{i j : Level} (k : 𝕋) {A : UU i} (B : A → UU-Truncated-Type k j) →
trunc-map k (Σ A (λ x → pr1 (B x))) A
trunc-pr1 k B =
pair pr1 (is-trunc-pr1-is-trunc-fam k (λ x → pr1 (B x)) (λ x → pr2 (B x)))
abstract
is-trunc-fam-is-trunc-pr1 : {i j : Level} (k : 𝕋) {A : UU i} (B : A → UU j) →
is-trunc-map k (pr1 {i} {j} {A} {B}) → ((x : A) → is-trunc k (B x))
is-trunc-fam-is-trunc-pr1 k B is-trunc-pr1 x =
is-trunc-is-equiv k
( fib pr1 x)
( fib-pr1-fib-fam B x)
( is-equiv-fib-pr1-fib-fam B x)
( is-trunc-pr1 x)
abstract
is-trunc-map-is-trunc-ap : {i j : Level} (k : 𝕋) {A : UU i} {B : UU j}
(f : A → B) → ((x y : A) → is-trunc-map k (ap f {x = x} {y = y})) →
is-trunc-map (succ-𝕋 k) f
is-trunc-map-is-trunc-ap k f is-trunc-ap-f b (pair x p) (pair x' p') =
is-trunc-is-equiv k
( fib (ap f) (p ∙ (inv p')))
( fib-ap-eq-fib f (pair x p) (pair x' p'))
( is-equiv-fib-ap-eq-fib f (pair x p) (pair x' p'))
( is-trunc-ap-f x x' (p ∙ (inv p')))
abstract
is-trunc-ap-is-trunc-map : {i j : Level} (k : 𝕋) {A : UU i} {B : UU j}
(f : A → B) → is-trunc-map (succ-𝕋 k) f →
(x y : A) → is-trunc-map k (ap f {x = x} {y = y})
is-trunc-ap-is-trunc-map k f is-trunc-map-f x y p =
is-trunc-is-equiv' k
( Id (pair x p) (pair y refl))
( eq-fib-fib-ap f x y p)
( is-equiv-eq-fib-fib-ap f x y p)
( is-trunc-map-f (f y) (pair x p) (pair y refl))
is-prop-map : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j)
is-prop-map f = (b : _) → is-trunc neg-one-𝕋 (fib f b)
abstract
is-emb-is-prop-map : {i j : Level} {A : UU i} {B : UU j} (f : A → B) →
is-prop-map f → is-emb f
is-emb-is-prop-map f is-prop-map-f x y =
is-equiv-is-contr-map
( is-trunc-ap-is-trunc-map neg-two-𝕋 f is-prop-map-f x y)
abstract
is-prop-map-is-emb : {i j : Level} {A : UU i} {B : UU j} (f : A → B) →
is-emb f → is-prop-map f
is-prop-map-is-emb f is-emb-f =
is-trunc-map-is-trunc-ap neg-two-𝕋 f
( λ x y → is-contr-map-is-equiv (is-emb-f x y))
fib-prop-emb :
{i j : Level} {A : UU i} {B : UU j} (f : A ↪ B) → B → UU-Prop (i ⊔ j)
fib-prop-emb f y =
pair ( fib (map-emb f) y)
( is-prop-map-is-emb (map-emb f) (is-emb-map-emb f) y)
abstract
is-emb-pr1-is-subtype : {i j : Level} {A : UU i} {B : A → UU j} →
is-subtype B → is-emb (pr1 {B = B})
is-emb-pr1-is-subtype {B = B} is-subtype-B =
is-emb-is-prop-map pr1
( λ x → is-trunc-is-equiv neg-one-𝕋
( B x)
( fib-fam-fib-pr1 _ x)
( is-equiv-fib-fam-fib-pr1 _ x)
( is-subtype-B x))
equiv-ap-pr1-is-subtype : {i j : Level} {A : UU i} {B : A → UU j} →
is-subtype B → {s t : Σ A B} → Id s t ≃ Id (pr1 s) (pr1 t)
equiv-ap-pr1-is-subtype is-subtype-B {s} {t} =
pair
( ap pr1)
( is-emb-pr1-is-subtype is-subtype-B s t)
abstract
is-subtype-is-emb-pr1 : {i j : Level} {A : UU i} {B : A → UU j} →
is-emb (pr1 {B = B}) → is-subtype B
is-subtype-is-emb-pr1 is-emb-pr1-B x =
is-trunc-is-equiv neg-one-𝕋
( fib pr1 x)
( fib-pr1-fib-fam _ x)
( is-equiv-fib-pr1-fib-fam _ x)
( is-prop-map-is-emb pr1 is-emb-pr1-B x)
abstract
is-trunc-succ-subtype :
{i j : Level} (k : 𝕋) {A : UU i} {P : A → UU j} →
((x : A) → is-prop (P x)) →
is-trunc (succ-𝕋 k) A → is-trunc (succ-𝕋 k) (Σ A P)
is-trunc-succ-subtype k H is-trunc-A =
is-trunc-succ-is-emb k pr1 (is-emb-pr1-is-subtype H) is-trunc-A
is-fiberwise-trunc : {l1 l2 l3 : Level} (k : 𝕋) {A : UU l1} {B : A → UU l2}
{C : A → UU l3} (f : (x : A) → B x → C x) → UU (l1 ⊔ (l2 ⊔ l3))
is-fiberwise-trunc k f = (x : _) → is-trunc-map k (f x)
abstract
is-trunc-tot-is-fiberwise-trunc : {l1 l2 l3 : Level} (k : 𝕋)
{A : UU l1} {B : A → UU l2} {C : A → UU l3} (f : (x : A) → B x → C x) →
is-fiberwise-trunc k f → is-trunc-map k (tot f)
is-trunc-tot-is-fiberwise-trunc k f is-fiberwise-trunc-f (pair x z) =
is-trunc-is-equiv k
( fib (f x) z)
( fib-ftr-fib-tot f (pair x z))
( is-equiv-fib-ftr-fib-tot f (pair x z))
( is-fiberwise-trunc-f x z)
abstract
is-fiberwise-trunc-is-trunc-tot : {l1 l2 l3 : Level} (k : 𝕋)
{A : UU l1} {B : A → UU l2} {C : A → UU l3} (f : (x : A) → B x → C x) →
is-trunc-map k (tot f) → is-fiberwise-trunc k f
is-fiberwise-trunc-is-trunc-tot k f is-trunc-tot-f x z =
is-trunc-is-equiv k
( fib (tot f) (pair x z))
( fib-tot-fib-ftr f (pair x z))
( is-equiv-fib-tot-fib-ftr f (pair x z))
( is-trunc-tot-f (pair x z))
-- Exercises
-- Exercise 8.1
-- Exercise 8.1
diagonal : {l : Level} (A : UU l) → A → A × A
diagonal A x = pair x x
abstract
is-prop-is-equiv-diagonal : {l : Level} (A : UU l) →
is-equiv (diagonal A) → is-prop A
is-prop-is-equiv-diagonal A is-equiv-d =
is-prop-is-prop' ( λ x y →
let α = issec-inv-is-equiv is-equiv-d (pair x y) in
( inv (ap pr1 α)) ∙ (ap pr2 α))
eq-fib-diagonal : {l : Level} (A : UU l) (t : A × A) →
fib (diagonal A) t → Id (pr1 t) (pr2 t)
eq-fib-diagonal A (pair x y) (pair z α) = (inv (ap pr1 α)) ∙ (ap pr2 α)
fib-diagonal-eq : {l : Level} (A : UU l) (t : A × A) →
Id (pr1 t) (pr2 t) → fib (diagonal A) t
fib-diagonal-eq A (pair x y) β =
pair x (eq-pair-triv (pair refl β))
issec-fib-diagonal-eq : {l : Level} (A : UU l) (t : A × A) →
((eq-fib-diagonal A t) ∘ (fib-diagonal-eq A t)) ~ id
issec-fib-diagonal-eq A (pair x .x) refl = refl
isretr-fib-diagonal-eq : {l : Level} (A : UU l) (t : A × A) →
((fib-diagonal-eq A t) ∘ (eq-fib-diagonal A t)) ~ id
isretr-fib-diagonal-eq A .(pair z z) (pair z refl) = refl
abstract
is-equiv-eq-fib-diagonal : {l : Level} (A : UU l) (t : A × A) →
is-equiv (eq-fib-diagonal A t)
is-equiv-eq-fib-diagonal A t =
is-equiv-has-inverse
( fib-diagonal-eq A t)
( issec-fib-diagonal-eq A t)
( isretr-fib-diagonal-eq A t)
abstract
is-trunc-is-trunc-diagonal : {l : Level} (k : 𝕋) (A : UU l) →
is-trunc-map k (diagonal A) → is-trunc (succ-𝕋 k) A
is-trunc-is-trunc-diagonal k A is-trunc-d x y =
is-trunc-is-equiv' k
( fib (diagonal A) (pair x y))
( eq-fib-diagonal A (pair x y))
( is-equiv-eq-fib-diagonal A (pair x y))
( is-trunc-d (pair x y))
abstract
is-trunc-diagonal-is-trunc : {l : Level} (k : 𝕋) (A : UU l) →
is-trunc (succ-𝕋 k) A → is-trunc-map k (diagonal A)
is-trunc-diagonal-is-trunc k A is-trunc-A t =
is-trunc-is-equiv k
( Id (pr1 t) (pr2 t))
( eq-fib-diagonal A t)
( is-equiv-eq-fib-diagonal A t)
( is-trunc-A (pr1 t) (pr2 t))
-- Exercise 8.2
-- Exercise 8.2(a)
abstract
is-trunc-Σ : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : A → UU l2} →
is-trunc k A → ((x : A) → is-trunc k (B x)) → is-trunc k (Σ A B)
is-trunc-Σ neg-two-𝕋 is-trunc-A is-trunc-B =
is-contr-Σ is-trunc-A is-trunc-B
is-trunc-Σ (succ-𝕋 k) {B = B} is-trunc-A is-trunc-B s t =
is-trunc-is-equiv k
( Σ (Id (pr1 s) (pr1 t)) (λ p → Id (tr B p (pr2 s)) (pr2 t)))
( pair-eq)
( is-equiv-pair-eq s t)
( is-trunc-Σ k
( is-trunc-A (pr1 s) (pr1 t))
( λ p → is-trunc-B (pr1 t) (tr B p (pr2 s)) (pr2 t)))
abstract
is-trunc-prod : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} →
is-trunc k A → is-trunc k B → is-trunc k (A × B)
is-trunc-prod k is-trunc-A is-trunc-B =
is-trunc-Σ k is-trunc-A (λ x → is-trunc-B)
abstract
is-prop-Σ : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-prop A → is-subtype B → is-prop (Σ A B)
is-prop-Σ = is-trunc-Σ neg-one-𝕋
Σ-Prop :
{l1 l2 : Level} (P : UU-Prop l1) (Q : type-Prop P → UU-Prop l2) →
UU-Prop (l1 ⊔ l2)
Σ-Prop P Q =
pair
( Σ (type-Prop P) (λ p → type-Prop (Q p)))
( is-prop-Σ
( is-prop-type-Prop P)
( λ p → is-prop-type-Prop (Q p)))
abstract
is-prop-prod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
is-prop A → is-prop B → is-prop (A × B)
is-prop-prod = is-trunc-prod neg-one-𝕋
prod-Prop : {l1 l2 : Level} → UU-Prop l1 → UU-Prop l2 → UU-Prop (l1 ⊔ l2)
prod-Prop P Q =
pair
( type-Prop P × type-Prop Q)
( is-prop-prod (is-prop-type-Prop P) (is-prop-type-Prop Q))
abstract
is-set-Σ : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-set A → ((x : A) → is-set (B x)) → is-set (Σ A B)
is-set-Σ = is-trunc-Σ zero-𝕋
set-Σ :
{l1 l2 : Level} (A : UU-Set l1) (B : pr1 A → UU-Set l2) → UU-Set (l1 ⊔ l2)
set-Σ (pair A is-set-A) B =
pair
( Σ A (λ x → (pr1 (B x))))
( is-set-Σ is-set-A (λ x → pr2 (B x)))
abstract
is-set-prod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
is-set A → is-set B → is-set (A × B)
is-set-prod = is-trunc-prod zero-𝕋
set-prod :
{l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → UU-Set (l1 ⊔ l2)
set-prod (pair A is-set-A) (pair B is-set-B) =
pair (A × B) (is-set-prod is-set-A is-set-B)
-- Exercise 8.2 (b)
abstract
is-trunc-Id : {l : Level} (k : 𝕋) {A : UU l} →
is-trunc k A → (x y : A) → is-trunc k (Id x y)
is-trunc-Id neg-two-𝕋 is-trunc-A = is-prop-is-contr is-trunc-A
is-trunc-Id (succ-𝕋 k) is-trunc-A x y =
is-trunc-succ-is-trunc k {A = Id x y} (is-trunc-A x y)
-- Exercise 8.2 (c)
abstract
is-trunc-map-is-trunc-domain-codomain : {l1 l2 : Level} (k : 𝕋) {A : UU l1}
{B : UU l2} {f : A → B} → is-trunc k A → is-trunc k B → is-trunc-map k f
is-trunc-map-is-trunc-domain-codomain k {f = f} is-trunc-A is-trunc-B b =
is-trunc-Σ k is-trunc-A (λ x → is-trunc-Id k is-trunc-B (f x) b)
-- Exercise 8.2 (d)
abstract
is-trunc-fam-is-trunc-Σ :
{l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : A → UU l2} →
is-trunc k A → is-trunc k (Σ A B) → (x : A) → is-trunc k (B x)
is-trunc-fam-is-trunc-Σ k {B = B} is-trunc-A is-trunc-ΣAB x =
is-trunc-is-equiv' k
( fib pr1 x)
( fib-fam-fib-pr1 B x)
( is-equiv-fib-fam-fib-pr1 B x)
( is-trunc-map-is-trunc-domain-codomain k is-trunc-ΣAB is-trunc-A x)
-- Exercise 8.3
abstract
is-prop-Eq-𝟚 : (x y : bool) → is-prop (Eq-𝟚 x y)
is-prop-Eq-𝟚 true true = is-prop-unit
is-prop-Eq-𝟚 true false = is-prop-empty
is-prop-Eq-𝟚 false true = is-prop-empty
is-prop-Eq-𝟚 false false = is-prop-unit
abstract
is-set-bool : is-set bool
is-set-bool = is-set-prop-in-id Eq-𝟚 is-prop-Eq-𝟚 reflexive-Eq-𝟚 (λ x y → eq-Eq-𝟚)
set-bool : UU-Set lzero
set-bool = pair bool is-set-bool
-- Exercise 8.4
abstract
is-prop'-coprod :
{l1 l2 : Level} {P : UU l1} {Q : UU l2} →
(P → ¬ Q) → is-prop' P → is-prop' Q → is-prop' (coprod P Q)
is-prop'-coprod
{P = P} {Q = Q} f is-prop-P is-prop-Q (inl p) (inl p') =
ap inl (is-prop-P p p')
is-prop'-coprod
{P = P} {Q = Q} f is-prop-P is-prop-Q (inl p) (inr q') =
ind-empty (f p q')
is-prop'-coprod
{P = P} {Q = Q} f is-prop-P is-prop-Q (inr q) (inl p') =
ind-empty (f p' q)
is-prop'-coprod
{P = P} {Q = Q} f is-prop-P is-prop-Q (inr q) (inr q') =
ap inr (is-prop-Q q q')
abstract
is-prop-coprod :
{l1 l2 : Level} {P : UU l1} {Q : UU l2} →
(P → ¬ Q) → is-prop P → is-prop Q → is-prop (coprod P Q)
is-prop-coprod f is-prop-P is-prop-Q =
is-prop-is-prop'
( is-prop'-coprod f
( is-prop'-is-prop is-prop-P)
( is-prop'-is-prop is-prop-Q))
abstract
is-trunc-succ-empty : (k : 𝕋) → is-trunc (succ-𝕋 k) empty
is-trunc-succ-empty k = ind-empty
abstract
is-trunc-coprod : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} →
is-trunc (succ-𝕋 (succ-𝕋 k)) A → is-trunc (succ-𝕋 (succ-𝕋 k)) B →
is-trunc (succ-𝕋 (succ-𝕋 k)) (coprod A B)
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inl x) (inl y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inl x) (inl y))
( Eq-coprod-eq A B (inl x) (inl y))
( is-equiv-Eq-coprod-eq A B (inl x) (inl y))
( is-trunc-is-equiv' (succ-𝕋 k)
( Id x y)
( map-raise {A = Id x y})
( is-equiv-map-raise _ (Id x y))
( is-trunc-A x y))
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inl x) (inr y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inl x) (inr y))
( Eq-coprod-eq A B (inl x) (inr y))
( is-equiv-Eq-coprod-eq A B (inl x) (inr y))
( is-trunc-is-equiv' (succ-𝕋 k)
( empty)
( map-raise {A = empty})
( is-equiv-map-raise _ empty)
( is-trunc-succ-empty k))
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inr x) (inl y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inr x) (inl y))
( Eq-coprod-eq A B (inr x) (inl y))
( is-equiv-Eq-coprod-eq A B (inr x) (inl y))
( is-trunc-is-equiv' (succ-𝕋 k)
( empty)
( map-raise {A = empty})
( is-equiv-map-raise _ empty)
( is-trunc-succ-empty k))
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inr x) (inr y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inr x) (inr y))
( Eq-coprod-eq A B (inr x) (inr y))
( is-equiv-Eq-coprod-eq A B (inr x) (inr y))
( is-trunc-is-equiv' (succ-𝕋 k)
( Id x y)
( map-raise {A = Id x y})
( is-equiv-map-raise _ (Id x y))
( is-trunc-B x y))
abstract
is-set-coprod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
is-set A → is-set B → is-set (coprod A B)
is-set-coprod = is-trunc-coprod neg-two-𝕋
set-coprod :
{l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → UU-Set (l1 ⊔ l2)
set-coprod (pair A is-set-A) (pair B is-set-B) =
pair (coprod A B) (is-set-coprod is-set-A is-set-B)
abstract
is-set-unit : is-set unit
is-set-unit = is-trunc-succ-is-trunc neg-one-𝕋 is-prop-unit
set-unit : UU-Set lzero
set-unit = pair unit is-set-unit
abstract
is-set-ℤ : is-set ℤ
is-set-ℤ = is-set-coprod is-set-ℕ (is-set-coprod is-set-unit is-set-ℕ)
set-ℤ : UU-Set lzero
set-ℤ = pair ℤ is-set-ℤ
ℤ-Set : UU-Set lzero
ℤ-Set = pair ℤ is-set-ℤ
is-set-empty : is-set empty
is-set-empty ()
abstract
is-set-Fin :
(n : ℕ) → is-set (Fin n)
is-set-Fin zero-ℕ = is-set-empty
is-set-Fin (succ-ℕ n) =
is-set-coprod (is-set-Fin n) is-set-unit
set-Fin :
(n : ℕ) → UU-Set lzero
set-Fin n = pair (Fin n) (is-set-Fin n)
-- Exercise 8.7
abstract
is-trunc-retract-of : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} →
A retract-of B → is-trunc k B → is-trunc k A
is-trunc-retract-of neg-two-𝕋 (pair i (pair r H)) is-trunc-B =
is-contr-retract-of _ (pair i (pair r H)) is-trunc-B
is-trunc-retract-of (succ-𝕋 k) (pair i retr-i) is-trunc-B x y =
is-trunc-retract-of k
( pair (ap i) (retr-ap i retr-i x y))
( is-trunc-B (i x) (i y))
-- Exercise 8.8
is-injective : {l1 l2 : Level} {A : UU l1} (is-set-A : is-set A) {B : UU l2}
(is-set-B : is-set B) (f : A → B) → UU (l1 ⊔ l2)
is-injective {A = A} is-set-A is-set-B f = (x y : A) → Id (f x) (f y) → Id x y
is-injective-const-true : is-injective is-set-unit is-set-bool
(const unit bool true)
is-injective-const-true x y p = center (is-prop-unit x y)
is-injective-const-false : is-injective is-set-unit is-set-bool
(const unit bool false)
is-injective-const-false x y p = center (is-prop-unit x y)
abstract
is-equiv-is-prop : {l1 l2 : Level} {A : UU l1} {B : UU l2} → is-prop A →
is-prop B → {f : A → B} → (B → A) → is-equiv f
is-equiv-is-prop is-prop-A is-prop-B {f} g =
is-equiv-has-inverse
( g)
( λ y → center (is-prop-B (f (g y)) y))
( λ x → center (is-prop-A (g (f x)) x))
equiv-prop :
{ l1 l2 : Level} {A : UU l1} {B : UU l2} → is-prop A → is-prop B →
( A → B) → (B → A) → A ≃ B
equiv-prop is-prop-A is-prop-B f g =
pair f (is-equiv-is-prop is-prop-A is-prop-B g)
equiv-total-subtype :
{ l1 l2 l3 : Level} {A : UU l1} {P : A → UU l2} {Q : A → UU l3} →
( is-subtype-P : is-subtype P) (is-subtype-Q : is-subtype Q) →
( f : (x : A) → P x → Q x) →
( g : (x : A) → Q x → P x) →
( Σ A P) ≃ (Σ A Q)
equiv-total-subtype is-subtype-P is-subtype-Q f g =
pair
( tot f)
( is-equiv-tot-is-fiberwise-equiv {f = f}
( λ x → is-equiv-is-prop (is-subtype-P x) (is-subtype-Q x) (g x)))
abstract
is-emb-is-injective : {l1 l2 : Level} {A : UU l1} (is-set-A : is-set A)
{B : UU l2} (is-set-B : is-set B) (f : A → B) →
is-injective is-set-A is-set-B f → is-emb f
is-emb-is-injective is-set-A is-set-B f is-injective-f x y =
is-equiv-is-prop
( is-set-A x y)
( is-set-B (f x) (f y))
( is-injective-f x y)
abstract
is-injective-is-emb : {l1 l2 : Level} {A : UU l1} {is-set-A : is-set A}
{B : UU l2} {is-set-B : is-set B} {f : A → B} →
is-emb f → is-injective is-set-A is-set-B f
is-injective-is-emb is-emb-f x y = inv-is-equiv (is-emb-f x y)
-- Exercise 8.9
abstract
is-trunc-const-is-trunc : {l : Level} (k : 𝕋) {A : UU l} →
is-trunc (succ-𝕋 k) A → (x : A) → is-trunc-map k (const unit A x)
is-trunc-const-is-trunc k is-trunc-A x y =
is-trunc-is-equiv' k
( Id x y)
( left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-equiv-left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-trunc-A x y)
abstract
is-trunc-is-trunc-const : {l : Level} (k : 𝕋) {A : UU l} →
((x : A) → is-trunc-map k (const unit A x)) → is-trunc (succ-𝕋 k) A
is-trunc-is-trunc-const k is-trunc-const x y =
is-trunc-is-equiv k
( Σ unit (λ t → Id x y))
( left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-equiv-left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-trunc-const x y)
-- Exercise 8.10
map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) →
(x : X) → fib (g ∘ h) x → Σ (fib g x) (λ t → fib h (pr1 t))
map-fib-comp g h x (pair a p) =
pair
( pair (h a) p)
( pair a refl)
inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) →
(x : X) → Σ (fib g x) (λ t → fib h (pr1 t)) → fib (g ∘ h) x
inv-map-fib-comp g h c t =
pair (pr1 (pr2 t)) ((ap g (pr2 (pr2 t))) ∙ (pr2 (pr1 t)))
issec-inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) →
(x : X) →
((map-fib-comp g h x) ∘ (inv-map-fib-comp g h x)) ~ id
issec-inv-map-fib-comp g h x
(pair (pair .(h a) refl) (pair a refl)) = refl
isretr-inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) (x : X) →
((inv-map-fib-comp g h x) ∘ (map-fib-comp g h x)) ~ id
isretr-inv-map-fib-comp g h .(g (h a)) (pair a refl) = refl
abstract
is-equiv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) (x : X) →
is-equiv (map-fib-comp g h x)
is-equiv-map-fib-comp g h x =
is-equiv-has-inverse
( inv-map-fib-comp g h x)
( issec-inv-map-fib-comp g h x)
( isretr-inv-map-fib-comp g h x)
abstract
is-equiv-inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) (x : X) →
is-equiv (inv-map-fib-comp g h x)
is-equiv-inv-map-fib-comp g h x =
is-equiv-has-inverse
( map-fib-comp g h x)
( isretr-inv-map-fib-comp g h x)
( issec-inv-map-fib-comp g h x)
abstract
is-trunc-map-htpy : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
(f g : A → B) → f ~ g → is-trunc-map k g → is-trunc-map k f
is-trunc-map-htpy k {A} f g H is-trunc-g b =
is-trunc-is-equiv k
( Σ A (λ z → Id (g z) b))
( fib-triangle f g id H b)
( is-fiberwise-equiv-is-equiv-triangle f g id H (is-equiv-id _) b)
( is-trunc-g b)
abstract
is-trunc-map-comp : {l1 l2 l3 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
{X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
is-trunc-map k g → is-trunc-map k h → is-trunc-map k f
is-trunc-map-comp k f g h H is-trunc-g is-trunc-h =
is-trunc-map-htpy k f (g ∘ h) H
( λ x → is-trunc-is-equiv k
( Σ (fib g x) (λ t → fib h (pr1 t)))
( map-fib-comp g h x)
( is-equiv-map-fib-comp g h x)
( is-trunc-Σ k
( is-trunc-g x)
( λ t → is-trunc-h (pr1 t))))
abstract
is-trunc-map-right-factor : {l1 l2 l3 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
{X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
is-trunc-map k g → is-trunc-map k f → is-trunc-map k h
is-trunc-map-right-factor k {A} f g h H is-trunc-g is-trunc-f b =
is-trunc-fam-is-trunc-Σ k
( is-trunc-g (g b))
( is-trunc-is-equiv' k
( Σ A (λ z → Id (g (h z)) (g b)))
( map-fib-comp g h (g b))
( is-equiv-map-fib-comp g h (g b))
( is-trunc-map-htpy k (g ∘ h) f (htpy-inv H) is-trunc-f (g b)))
( pair b refl)
abstract
is-trunc-map-succ-is-trunc-map :
{l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
(f : A → B) → is-trunc-map k f → is-trunc-map (succ-𝕋 k) f
is-trunc-map-succ-is-trunc-map k f is-trunc-f b =
is-trunc-succ-is-trunc k (is-trunc-f b)
--------------------------------------------------------------------------------
{- We show that if f : A → B is an embedding, then the induced map
Σ A (C ∘ f) → Σ A C is also an embedding. -}
is-emb-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
is-emb f → is-emb (Σ-map-base-map f C)
is-emb-Σ-map-base-map f C is-emb-f =
is-emb-is-prop-map
( Σ-map-base-map f C)
( λ x →
is-prop-equiv'
( fib f (pr1 x))
( equiv-fib-Σ-map-base-map-fib f C x)
( is-prop-map-is-emb f is-emb-f (pr1 x)))
| 32.436866
| 84
| 0.547366
|
4ad2c3964e66a7d0ae1487946b55412b1078c169
| 565
|
agda
|
Agda
|
test/Fail/MatchingOnCoinductiveRecord.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/MatchingOnCoinductiveRecord.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/MatchingOnCoinductiveRecord.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{-# OPTIONS --copatterns #-}
-- 2013-05-30 Andreas, Oury's counterexample to subject reduction in Coq
-- 2014-11-04 Andreas: simplified (removed force)
module MatchingOnCoinductiveRecord where
open import Common.Equality
record U : Set where
coinductive
constructor inn
field
out : U
open U
u : U
out u = u
eq : (x : U) → x ≡ inn (out x)
eq (inn y) = refl
-- should fail, as internally this is just
-- eq x = refl
-- and we do not have η for coinductive records
equ : u ≡ inn u
equ = eq u
-- normalizes to refl, which does not have type u ≡ inn u
| 18.833333
| 72
| 0.683186
|
1c55681cdb07269fca0fbfe10d738d4b0a97f291
| 213
|
agda
|
Agda
|
test/Fail/WrongDotPattern.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/WrongDotPattern.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/WrongDotPattern.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module WrongDotPattern where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data NonZero : Nat -> Set where
nonZ : (n : Nat) -> NonZero (suc n)
f : (n : Nat) -> NonZero n -> Nat
f .zero (nonZ n) = n
| 15.214286
| 37
| 0.586854
|
103fe245d3185267679ea35119d6845978523d06
| 3,638
|
agda
|
Agda
|
notes/fixed-points/GFPs/Colist.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/fixed-points/GFPs/Colist.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/fixed-points/GFPs/Colist.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Co-lists
------------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module GFPs.Colist where
open import FOTC.Base
open import FOTC.Base.List
------------------------------------------------------------------------------
-- Colist is a greatest fixed-point of a functor
-- The functor.
ListF : (D → Set) → D → Set
ListF A xs = xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs')
-- Colist is the greatest fixed-point of ListF.
postulate
Colist : D → Set
-- Colist is a post-fixed point of ListF, i.e.
--
-- Colist ≤ ListF Colist.
Colist-out-ho : ∀ {n} → Colist n → ListF Colist n
-- Colist is the greatest post-fixed point of ListF, i.e.
--
-- ∀ A. A ≤ ListF A ⇒ A ≤ Colist.
Colist-coind-ho :
(A : D → Set) →
-- A is post-fixed point of ListF.
(∀ {xs} → A xs → ListF A xs) →
-- Colist is greater than A.
∀ {xs} → A xs → Colist xs
------------------------------------------------------------------------------
-- First-order versions
Colist-out : ∀ {xs} →
Colist xs →
xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Colist xs')
Colist-out = Colist-out-ho
Colist-coind :
(A : D → Set) →
(∀ {xs} → A xs → xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs')) →
∀ {xs} → A xs → Colist xs
Colist-coind = Colist-coind-ho
------------------------------------------------------------------------------
-- Because a greatest post-fixed point is a fixed-point, then the
-- Colist predicate is also a pre-fixed point of the functional ListF,
-- i.e.
--
-- ListF Colist ≤ Colist.
Colist-in-ho : ∀ {xs} → ListF Colist xs → Colist xs
Colist-in-ho h = Colist-coind-ho A h' h
where
A : D → Set
A xs = ListF Colist xs
h' : ∀ {xs} → A xs → ListF A xs
h' (inj₁ xs≡0) = inj₁ xs≡0
h' (inj₂ (x' , xs' , prf , CLxs' )) =
inj₂ (x' , xs' , prf , Colist-out CLxs')
-- The first-order version.
Colist-in : ∀ {xs} →
xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Colist xs') →
Colist xs
Colist-in = Colist-in-ho
------------------------------------------------------------------------------
-- A stronger co-induction principle
--
-- From (Paulson, 1997. p. 16).
postulate
Colist-coind-stronger-ho :
(A : D → Set) →
(∀ {xs} → A xs → ListF A xs ∨ Colist xs) →
∀ {xs} → A xs → Colist xs
Colist-coind-ho' :
(A : D → Set) →
(∀ {xs} → A xs → ListF A xs) →
∀ {xs} → A xs → Colist xs
Colist-coind-ho' A h Axs =
Colist-coind-stronger-ho A (λ Ays → inj₁ (h Ays)) Axs
-- The first-order version.
Colist-coind-stronger :
(A : D → Set) →
(∀ {xs} → A xs →
(xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'))
∨ Colist xs) →
∀ {xs} → A xs → Colist xs
Colist-coind-stronger = Colist-coind-stronger-ho
-- 13 January 2014. As expected, we cannot prove
-- Colist-coind-stronger-ho from Colist-coind-ho.
Colist-coind-stronger-ho' :
(A : D → Set) →
(∀ {xs} → A xs → ListF A xs ∨ Colist xs) →
∀ {xs} → A xs → Colist xs
Colist-coind-stronger-ho' A h {xs} Axs = case prf (λ h' → h') (h Axs)
where
prf : ListF A xs → Colist xs
prf h' = Colist-coind-ho A {!!} Axs
------------------------------------------------------------------------------
-- References
--
-- Paulson, L. C. (1997). Mechanizing Coinduction and Corecursion in
-- Higher-order Logic. Journal of Logic and Computation 7.2,
-- pp. 175–204.
| 29.577236
| 78
| 0.468664
|
cb3fb57e1ea5451fd77b8e545d923fe2595aaa45
| 65
|
agda
|
Agda
|
test/interaction/Issue604.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue604.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue604.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue604 where
f : (y : Set1) → (x : Set) → Set1
f x = ?
| 13
| 33
| 0.538462
|
4aa3c2326511f672d874cc5982d2ed5971032dfe
| 5,374
|
agda
|
Agda
|
Cubical/Categories/Constructions/Elements.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Constructions/Elements.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Constructions/Elements.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
-- The Category of Elements
open import Cubical.Categories.Category
module Cubical.Categories.Constructions.Elements {ℓ ℓ'} {C : Precategory ℓ ℓ'} where
open import Cubical.Categories.Instances.Sets
open import Cubical.Categories.Functor
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
import Cubical.Categories.Morphism as Morphism
import Cubical.Categories.Constructions.Slice as Slice
-- some issues
-- * always need to specify objects during composition because can't infer isSet
open Precategory
open Functor
getIsSet : {C : Precategory ℓ ℓ'} (F : Functor C (SET ℓ)) → (c : C .ob) → isSet (fst (F ⟅ c ⟆))
getIsSet F c = snd (F ⟅ c ⟆)
infix 50 ∫_
∫_ : Functor C (SET ℓ) → Precategory ℓ (ℓ-max ℓ ℓ')
-- objects are (c , x) pairs where c ∈ C and x ∈ F c
(∫ F) .ob = Σ[ c ∈ C .ob ] fst (F ⟅ c ⟆)
-- morphisms are f : c → c' which take x to x'
(∫ F) .Hom[_,_] (c , x) (c' , x') = Σ[ f ∈ C [ c , c' ] ] x' ≡ (F ⟪ f ⟫) x
(∫ F) .id (c , x) = C .id c , sym (funExt⁻ (F .F-id) x ∙ refl)
(∫ F) ._⋆_ {c , x} {c₁ , x₁} {c₂ , x₂} (f , p) (g , q)
= (f ⋆⟨ C ⟩ g) , (x₂
≡⟨ q ⟩
(F ⟪ g ⟫) x₁ -- basically expanding out function composition
≡⟨ cong (F ⟪ g ⟫) p ⟩
(F ⟪ g ⟫) ((F ⟪ f ⟫) x)
≡⟨ funExt⁻ (sym (F .F-seq _ _)) _ ⟩
(F ⟪ f ⋆⟨ C ⟩ g ⟫) x
∎)
(∫ F) .⋆IdL o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdL i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS' x' ((F ⟪ a ⟫) x)) p' p cIdL i
where
isS = getIsSet F c
isS' = getIsSet F c'
cIdL = C .⋆IdL f
-- proof from composition with id
p' : x' ≡ (F ⟪ C .id c ⋆⟨ C ⟩ f ⟫) x
p' = snd ((∫ F) ._⋆_ ((∫ F) .id o) f')
(∫ F) .⋆IdR o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdR i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS' x' ((F ⟪ a ⟫) x)) p' p cIdR i
where
cIdR = C .⋆IdR f
isS' = getIsSet F c'
p' : x' ≡ (F ⟪ f ⋆⟨ C ⟩ C .id c' ⟫) x
p' = snd ((∫ F) ._⋆_ f' ((∫ F) .id o1))
(∫ F) .⋆Assoc o@{c , x} o1@{c₁ , x₁} o2@{c₂ , x₂} o3@{c₃ , x₃} f'@(f , p) g'@(g , q) h'@(h , r) i
= (cAssoc i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS₃ x₃ ((F ⟪ a ⟫) x)) p1 p2 cAssoc i
where
cAssoc = C .⋆Assoc f g h
isS₃ = getIsSet F c₃
p1 : x₃ ≡ (F ⟪ (f ⋆⟨ C ⟩ g) ⋆⟨ C ⟩ h ⟫) x
p1 = snd ((∫ F) ._⋆_ ((∫ F) ._⋆_ {o} {o1} {o2} f' g') h')
p2 : x₃ ≡ (F ⟪ f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ h) ⟫) x
p2 = snd ((∫ F) ._⋆_ f' ((∫ F) ._⋆_ {o1} {o2} {o3} g' h'))
-- same thing but for presheaves
∫ᴾ_ : Functor (C ^op) (SET ℓ) → Precategory ℓ (ℓ-max ℓ ℓ')
-- objects are (c , x) pairs where c ∈ C and x ∈ F c
(∫ᴾ F) .ob = Σ[ c ∈ C .ob ] fst (F ⟅ c ⟆)
-- morphisms are f : c → c' which take x to x'
(∫ᴾ F) .Hom[_,_] (c , x) (c' , x') = Σ[ f ∈ C [ c , c' ] ] x ≡ (F ⟪ f ⟫) x'
(∫ᴾ F) .id (c , x) = C .id c , sym (funExt⁻ (F .F-id) x ∙ refl)
(∫ᴾ F) ._⋆_ {c , x} {c₁ , x₁} {c₂ , x₂} (f , p) (g , q)
= (f ⋆⟨ C ⟩ g) , (x
≡⟨ p ⟩
(F ⟪ f ⟫) x₁ -- basically expanding out function composition
≡⟨ cong (F ⟪ f ⟫) q ⟩
(F ⟪ f ⟫) ((F ⟪ g ⟫) x₂)
≡⟨ funExt⁻ (sym (F .F-seq _ _)) _ ⟩
(F ⟪ f ⋆⟨ C ⟩ g ⟫) x₂
∎)
(∫ᴾ F) .⋆IdL o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdL i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x')) p' p cIdL i
where
isS = getIsSet F c
isS' = getIsSet F c'
cIdL = C .⋆IdL f
-- proof from composition with id
p' : x ≡ (F ⟪ C .id c ⋆⟨ C ⟩ f ⟫) x'
p' = snd ((∫ᴾ F) ._⋆_ ((∫ᴾ F) .id o) f')
(∫ᴾ F) .⋆IdR o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdR i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x')) p' p cIdR i
where
cIdR = C .⋆IdR f
isS = getIsSet F c
p' : x ≡ (F ⟪ f ⋆⟨ C ⟩ C .id c' ⟫) x'
p' = snd ((∫ᴾ F) ._⋆_ f' ((∫ᴾ F) .id o1))
(∫ᴾ F) .⋆Assoc o@{c , x} o1@{c₁ , x₁} o2@{c₂ , x₂} o3@{c₃ , x₃} f'@(f , p) g'@(g , q) h'@(h , r) i
= (cAssoc i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x₃)) p1 p2 cAssoc i
where
cAssoc = C .⋆Assoc f g h
isS = getIsSet F c
p1 : x ≡ (F ⟪ (f ⋆⟨ C ⟩ g) ⋆⟨ C ⟩ h ⟫) x₃
p1 = snd ((∫ᴾ F) ._⋆_ ((∫ᴾ F) ._⋆_ {o} {o1} {o2} f' g') h')
p2 : x ≡ (F ⟪ f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ h) ⟫) x₃
p2 = snd ((∫ᴾ F) ._⋆_ f' ((∫ᴾ F) ._⋆_ {o1} {o2} {o3} g' h'))
-- helpful results
module _ {F : Functor (C ^op) (SET ℓ)} where
-- morphisms are equal as long as the morphisms in C are equals
∫ᴾhomEq : ∀ {o1 o1' o2 o2'} (f : (∫ᴾ F) [ o1 , o2 ]) (g : (∫ᴾ F) [ o1' , o2' ])
→ (p : o1 ≡ o1') (q : o2 ≡ o2')
→ (eqInC : PathP (λ i → C [ fst (p i) , fst (q i) ]) (fst f) (fst g))
→ PathP (λ i → (∫ᴾ F) [ p i , q i ]) f g
∫ᴾhomEq (f , eqf) (g , eqg) p q eqInC
= ΣPathP (eqInC
, isOfHLevel→isOfHLevelDep 1 {A = Σ[ (o1 , o2) ∈ (∫ᴾ F) .ob × (∫ᴾ F) .ob ] (C [ fst o1 , fst o2 ])}
{B = λ ((o1 , o2) , f) → snd o1 ≡ (F ⟪ f ⟫) (snd o2)}
(λ ((o1 , o2) , f) → snd (F ⟅ (fst o1) ⟆) (snd o1) ((F ⟪ f ⟫) (snd o2)))
eqf
eqg
λ i → ((p i , q i) , eqInC i))
| 38.942029
| 114
| 0.433383
|
df01cb6aff978530ee26aa1d5bc4fbe11d2f1bc4
| 124
|
agda
|
Agda
|
test/Fail/TooManyFields.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/TooManyFields.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Fail/TooManyFields.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module TooManyFields where
postulate X : Set
record D : Set where
field x : X
d : X -> D
d x = record {x = x; y = x}
| 10.333333
| 27
| 0.596774
|
0b5650feda9536f355895609e2a4c1228a06b895
| 497
|
agda
|
Agda
|
test/Succeed/RecordFromModule.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/RecordFromModule.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/RecordFromModule.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
postulate
I : Set
D : I → Set
T : Set
record R : Set where
field
t0 : T
{i0} : I
t1 : T
d0 : D i0
{i1} : I
d1 : D i1
t2 : T
module M0 where
postulate
t0 t1 : T
module MI where
postulate
i1 : I
d1 : D i1
module MD {i0 : I} where
postulate
d0 : D i0
t0 : T
r : R
r = record { M0; t2 = M0.t0; MD hiding (t0); MI; i0 = i0 }
module My where postulate i0 : I
r' : R
r' = record { R r; t0 = R.t1 r }
where module Rr = R r
| 13.432432
| 58
| 0.496982
|
0e53000a716987c45387117c5f4d1b8e68f90007
| 454
|
agda
|
Agda
|
test/Succeed/Issue1584.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1584.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1584.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-06-24
open import Common.Equality
open import Common.Product
Sing : {A : Set} (a : A) → Set
Sing a = ∃ λ b → a ≡ b
works : {A : Set} (f : ∀{a : A} → Sing a) (a : A) → Sing a
works f a = let b , p = f {_} in b , p
test : {A : Set} (f : ∀{a : A} → Sing a) (a : A) → Sing a
test f a = let b , p = f in b , p
-- ERROR WAS:
-- Type mismatch
-- when checking that the pattern b , p has type
-- {a = a₁ : .A} → Sing a₁
-- should work now
| 21.619048
| 58
| 0.535242
|
c54eaa84a9747ab92e0f200ad2e627ea5969fd60
| 114
|
agda
|
Agda
|
test/Fail/Issue2935.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2935.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2935.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue2935 where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
bad : ℕ → ℕ
bad zero = zero
bad suc = zero
| 11.4
| 22
| 0.605263
|
20c425a205cc3557297aa94a7e5871f6f23bb428
| 630
|
agda
|
Agda
|
test/Succeed/InjectivityHITs.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/InjectivityHITs.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/InjectivityHITs.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path
open import Agda.Primitive
open import Agda.Primitive.Cubical
open import Agda.Builtin.Bool
variable
a p : Level
A : Set a
P : A → Set p
x y : A
refl : x ≡ x
refl {x = x} = λ _ → x
data Interval : Set where
left right : Interval
line : left ≡ right
h2 : Bool → Interval
h2 true = left
h2 false = right
-- `left` and `right` are distinct canonical forms,
-- so `h2 ? = left` imples `? = true`.
--
-- Added this test to make sure we do not always give up on
-- injectivity when targeting a HIT.
_ : h2 _ ≡ left
_ = refl
| 18.529412
| 59
| 0.625397
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.