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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
c75174167db3fd86e5e43b3f240946db3edc7bb4
| 5,881
|
agda
|
Agda
|
Definition/Conversion/Lift.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 30
|
2017-05-20T03:05:21.000Z
|
2022-03-30T18:01:07.000Z
|
Definition/Conversion/Lift.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 4
|
2017-06-22T12:49:23.000Z
|
2021-02-22T10:37:24.000Z
|
Definition/Conversion/Lift.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 8
|
2017-10-18T14:18:20.000Z
|
2021-11-27T15:58:33.000Z
|
{-# OPTIONS --without-K --safe #-}
module Definition.Conversion.Lift where
open import Definition.Untyped hiding (_∷_)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.Conversion
open import Definition.Conversion.Whnf
open import Definition.Conversion.Soundness
open import Definition.Conversion.Weakening
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Reduction
open import Tools.Fin
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
private
variable
n : Nat
Γ : Con Term n
-- Lifting of algorithmic equality of types from WHNF to generic types.
liftConv : ∀ {A B}
→ Γ ⊢ A [conv↓] B
→ Γ ⊢ A [conv↑] B
liftConv A<>B =
let ⊢A , ⊢B = syntacticEq (soundnessConv↓ A<>B)
whnfA , whnfB = whnfConv↓ A<>B
in [↑] _ _ (id ⊢A) (id ⊢B) whnfA whnfB A<>B
-- Lifting of algorithmic equality of terms from WHNF to generic terms.
liftConvTerm : ∀ {t u A}
→ Γ ⊢ t [conv↓] u ∷ A
→ Γ ⊢ t [conv↑] u ∷ A
liftConvTerm t<>u =
let ⊢A , ⊢t , ⊢u = syntacticEqTerm (soundnessConv↓Term t<>u)
whnfA , whnfT , whnfU = whnfConv↓Term t<>u
in [↑]ₜ _ _ _ (id ⊢A) (id ⊢t) (id ⊢u) whnfA whnfT whnfU t<>u
mutual
-- Helper function for lifting from neutrals to generic terms in WHNF.
lift~toConv↓′ : ∀ {t u A A′ l}
→ Γ ⊩⟨ l ⟩ A′
→ Γ ⊢ A′ ⇒* A
→ Γ ⊢ t ~ u ↓ A
→ Γ ⊢ t [conv↓] u ∷ A
lift~toConv↓′ (Uᵣ′ .⁰ 0<1 ⊢Γ) D ([~] A D₁ whnfB k~l)
rewrite PE.sym (whnfRed* D Uₙ) =
let _ , ⊢t , ⊢u = syntacticEqTerm (conv (soundness~↑ k~l) (subset* D₁))
in univ ⊢t ⊢u (ne ([~] A D₁ Uₙ k~l))
lift~toConv↓′ (ℕᵣ D) D₁ ([~] A D₂ whnfB k~l)
rewrite PE.sym (whrDet* (red D , ℕₙ) (D₁ , whnfB)) =
ℕ-ins ([~] A D₂ ℕₙ k~l)
lift~toConv↓′ (Emptyᵣ D) D₁ ([~] A D₂ whnfB k~l)
rewrite PE.sym (whrDet* (red D , Emptyₙ) (D₁ , whnfB)) =
Empty-ins ([~] A D₂ Emptyₙ k~l)
lift~toConv↓′ (Unitᵣ D) D₁ ([~] A D₂ whnfB k~l)
rewrite PE.sym (whrDet* (red D , Unitₙ) (D₁ , whnfB)) =
Unit-ins ([~] A D₂ Unitₙ k~l)
lift~toConv↓′ (ne′ K D neK K≡K) D₁ ([~] A D₂ whnfB k~l)
rewrite PE.sym (whrDet* (red D , ne neK) (D₁ , whnfB)) =
let _ , ⊢t , ⊢u = syntacticEqTerm (soundness~↑ k~l)
A≡K = subset* D₂
in ne-ins (conv ⊢t A≡K) (conv ⊢u A≡K) neK ([~] A D₂ (ne neK) k~l)
lift~toConv↓′ (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) D₁ ([~] A D₂ whnfB k~l)
rewrite PE.sym (whrDet* (red D , Πₙ) (D₁ , whnfB)) =
let ⊢ΠFG , ⊢t , ⊢u = syntacticEqTerm (soundness~↓ ([~] A D₂ Πₙ k~l))
⊢F , ⊢G = syntacticΠ ⊢ΠFG
neT , neU = ne~↑ k~l
⊢Γ = wf ⊢F
var0 = neuTerm ([F] (step id) (⊢Γ ∙ ⊢F)) (var x0) (var (⊢Γ ∙ ⊢F) here)
(refl (var (⊢Γ ∙ ⊢F) here))
0≡0 = lift~toConv↑′ ([F] (step id) (⊢Γ ∙ ⊢F)) (var-refl (var (⊢Γ ∙ ⊢F) here) PE.refl)
k∘0≡l∘0 = lift~toConv↑′ ([G] (step id) (⊢Γ ∙ ⊢F) var0)
(app-cong (wk~↓ (step id) (⊢Γ ∙ ⊢F) ([~] A D₂ Πₙ k~l))
0≡0)
in η-eq ⊢t ⊢u (ne neT) (ne neU)
(PE.subst (λ x → _ ⊢ _ [conv↑] _ ∷ x)
(wkSingleSubstId _)
k∘0≡l∘0)
lift~toConv↓′ (Σᵣ′ F G D ⊢F ⊢G Σ≡Σ [F] [G] G-ext) D₁ ([~] A″ D₂ whnfA t~u)
rewrite PE.sym (whrDet* (red D , Σₙ) (D₁ , whnfA)) {- Σ F ▹ G ≡ A -} =
let neT , neU = ne~↑ t~u
t~u↓ = [~] A″ D₂ Σₙ t~u
⊢ΣFG , ⊢t , ⊢u = syntacticEqTerm (soundness~↓ t~u↓)
⊢F , ⊢G = syntacticΣ ⊢ΣFG
⊢Γ = wf ⊢F
wkId = wk-id F
wkLiftId = PE.cong (λ x → x [ fst _ ]) (wk-lift-id G)
wk[F] = [F] id ⊢Γ
wk⊢fst = PE.subst (λ x → _ ⊢ _ ∷ x) (PE.sym wkId) (fstⱼ ⊢F ⊢G ⊢t)
wkfst≡ = PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x) (PE.sym wkId) (fst-cong ⊢F ⊢G (refl ⊢t))
wk[fst] = neuTerm wk[F] (fstₙ neT) wk⊢fst wkfst≡
wk[Gfst] = [G] id ⊢Γ wk[fst]
wkfst~ = PE.subst (λ x → _ ⊢ _ ~ _ ↑ x) (PE.sym wkId) (fst-cong t~u↓)
wksnd~ = PE.subst (λ x → _ ⊢ _ ~ _ ↑ x) (PE.sym wkLiftId) (snd-cong t~u↓)
in Σ-η ⊢t ⊢u (ne neT) (ne neU)
(PE.subst (λ x → _ ⊢ _ [conv↑] _ ∷ x) wkId
(lift~toConv↑′ wk[F] wkfst~))
(PE.subst (λ x → _ ⊢ _ [conv↑] _ ∷ x) wkLiftId
(lift~toConv↑′ wk[Gfst] wksnd~))
lift~toConv↓′ (emb 0<1 [A]) D t~u = lift~toConv↓′ [A] D t~u
-- Helper function for lifting from neutrals to generic terms.
lift~toConv↑′ : ∀ {t u A l}
→ Γ ⊩⟨ l ⟩ A
→ Γ ⊢ t ~ u ↑ A
→ Γ ⊢ t [conv↑] u ∷ A
lift~toConv↑′ [A] t~u =
let B , whnfB , D = whNorm′ [A]
t~u↓ = [~] _ (red D) whnfB t~u
neT , neU = ne~↑ t~u
_ , ⊢t , ⊢u = syntacticEqTerm (soundness~↓ t~u↓)
in [↑]ₜ _ _ _ (red D) (id ⊢t) (id ⊢u) whnfB
(ne neT) (ne neU) (lift~toConv↓′ [A] (red D) t~u↓)
-- Lifting of algorithmic equality of terms from neutrals to generic terms in WHNF.
lift~toConv↓ : ∀ {t u A}
→ Γ ⊢ t ~ u ↓ A
→ Γ ⊢ t [conv↓] u ∷ A
lift~toConv↓ ([~] A₁ D whnfB k~l) =
lift~toConv↓′ (reducible (proj₁ (syntacticRed D))) D ([~] A₁ D whnfB k~l)
-- Lifting of algorithmic equality of terms from neutrals to generic terms.
lift~toConv↑ : ∀ {t u A}
→ Γ ⊢ t ~ u ↑ A
→ Γ ⊢ t [conv↑] u ∷ A
lift~toConv↑ t~u =
lift~toConv↑′ (reducible (proj₁ (syntacticEqTerm (soundness~↑ t~u)))) t~u
| 41.125874
| 93
| 0.52168
|
294007603f07b216ddbc52a483c5464d7e58d3f1
| 3,143
|
agda
|
Agda
|
Lang/Size.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Lang/Size.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Lang/Size.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --sized-types #-}
module Lang.Size where
-- Some stuff about sizes that seems to :
-- • Types:
-- • SizeU : TYPE
-- • Size : TYPE
-- • <ˢⁱᶻᵉ_ : Size → TYPE
-- • 𝐒ˢⁱᶻᵉ : Size → Size
-- • ∞ˢⁱᶻᵉ : Size
-- • _⊔ˢⁱᶻᵉ_ : Size → Size → Size
-- • Subtyping : ∀s₁∀s₂. (s₁: <ˢⁱᶻᵉ s₂) → (s₁: Size)
-- • Almost irreflexivity: ∀(s: Size). (s ≠ ∞ˢⁱᶻᵉ) → ¬(s: <ˢⁱᶻᵉ s)
-- • Transitivity : ∀s₁∀s₂∀s₃. (s₁: <ˢⁱᶻᵉ s₂) → (s₂: <ˢⁱᶻᵉ s₃) → (s₁: <ˢⁱᶻᵉ s₃)
-- • Successor : ∀(s: Size). s: <ˢⁱᶻᵉ 𝐒ˢⁱᶻᵉ(s)
-- • Maximum : ∀(s: Size). s: <ˢⁱᶻᵉ ∞ˢⁱᶻᵉ
-- • Successor of maximum: 𝐒ˢⁱᶻᵉ(∞ˢⁱᶻᵉ) = ∞ˢⁱᶻᵉ
-- • Max function left : ∀(s₁: Size)∀(s₂: Size)∀(s₃: Size). ((s₁: <ˢⁱᶻᵉ s₃) ∧ (s₂: <ˢⁱᶻᵉ s₃)) → (((s₁ ⊔ˢⁱᶻᵉ s₂)): <ˢⁱᶻᵉ s₃)
-- • Max function right : ∀(s₁: Size)∀(s₂: Size)∀(s₃: Size). ((s₁: <ˢⁱᶻᵉ s₂) ∨ (s₁: <ˢⁱᶻᵉ s₃)) → (s₁: <ˢⁱᶻᵉ (s₂ ⊔ˢⁱᶻᵉ s₃))
-- • Max of maximum left : ∀(s: Size). s ⊔ˢⁱᶻᵉ ∞ˢⁱᶻᵉ = ∞ˢⁱᶻᵉ
-- • Max of maximum right: ∀(s: Size). ∞ˢⁱᶻᵉ ⊔ˢⁱᶻᵉ s = ∞ˢⁱᶻᵉ
-- TODO: What is SizeU? See https://github.com/agda/agda/blob/cabe234d3c784e20646636ad082cc1e04ddf007b/src/full/Agda/TypeChecking/Rules/Builtin.hs#L294 , https://github.com/agda/agda/blob/1eec63b1c5566b252c0a4a815ce1df99a772c475/src/full/Agda/TypeChecking/Primitive/Base.hs#L134
{-# BUILTIN SIZEUNIV SizeU #-}
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZELT <ˢⁱᶻᵉ_ #-}
{-# BUILTIN SIZESUC 𝐒ˢⁱᶻᵉ #-}
{-# BUILTIN SIZEINF ∞ˢⁱᶻᵉ #-}
{-# BUILTIN SIZEMAX _⊔ˢⁱᶻᵉ_ #-}
{-
private
module Test where
open import Relator.Equals
types-SizeU : TYPE
types-SizeU = SizeU
types-Size : TYPE
types-Size = Size
types-<ˢⁱᶻᵉ : Size → TYPE
types-<ˢⁱᶻᵉ = <ˢⁱᶻᵉ_
types-𝐒ˢⁱᶻᵉ : Size → Size
types-𝐒ˢⁱᶻᵉ = 𝐒ˢⁱᶻᵉ
types-∞ˢⁱᶻᵉ : Size
types-∞ˢⁱᶻᵉ = ∞ˢⁱᶻᵉ
types-_⊔ˢⁱᶻᵉ_ : Size → Size → Size
types-_⊔ˢⁱᶻᵉ_ = _⊔ˢⁱᶻᵉ_
subtyping : ∀{s₂ : Size}{s₁ : <ˢⁱᶻᵉ s₂} → Size
subtyping {s₁ = s₁} = s₁
reflexivity-of-maximum : <ˢⁱᶻᵉ ∞ˢⁱᶻᵉ
reflexivity-of-maximum = ∞ˢⁱᶻᵉ
transitivity : ∀{s₃ : Size}{s₂ : <ˢⁱᶻᵉ s₃}{s₁ : <ˢⁱᶻᵉ s₂} → (<ˢⁱᶻᵉ s₃)
transitivity {s₁ = s₁} = s₁
maximum : ∀{s : Size} → <ˢⁱᶻᵉ ∞ˢⁱᶻᵉ
maximum{s} = s
successor-of-maximum : 𝐒ˢⁱᶻᵉ ∞ˢⁱᶻᵉ ≡ ∞ˢⁱᶻᵉ
successor-of-maximum = [≡]-intro
max-of-maximumₗ : ∀{s : Size} → (∞ˢⁱᶻᵉ ⊔ˢⁱᶻᵉ s ≡ ∞ˢⁱᶻᵉ)
max-of-maximumₗ = [≡]-intro
max-of-maximumᵣ : ∀{s : Size} → (s ⊔ˢⁱᶻᵉ ∞ˢⁱᶻᵉ ≡ ∞ˢⁱᶻᵉ)
max-of-maximumᵣ = [≡]-intro
max-function-left : ∀{s₃ : Size}{s₁ : <ˢⁱᶻᵉ s₃}{s₂ : <ˢⁱᶻᵉ s₃} → (<ˢⁱᶻᵉ s₃)
max-function-left {s₁ = s₁}{s₂ = s₂} = s₁ ⊔ˢⁱᶻᵉ s₂
max-function-rightₗ : ∀{s₂ s₃ : Size}{s₁ : <ˢⁱᶻᵉ s₂} → (<ˢⁱᶻᵉ (s₂ ⊔ˢⁱᶻᵉ s₃))
max-function-rightₗ {s₁ = s₁} = s₁
max-function-rightᵣ : ∀{s₂ s₃ : Size}{s₁ : <ˢⁱᶻᵉ s₃} → (<ˢⁱᶻᵉ (s₂ ⊔ˢⁱᶻᵉ s₃))
max-function-rightᵣ {s₁ = s₁} = s₁
-- TODO: Is this supposed to not work? This is: ∀(sₗ₁ : Size)∀(sₗ₂ : Size)∀(sᵣ : Size) → (sₗ₁ <ˢⁱᶻᵉ sₗ₂) → ((sₗ₁ ⊔ˢⁱᶻᵉ sᵣ) <ˢⁱᶻᵉ (sₗ₂ ⊔ˢⁱᶻᵉ sᵣ))
max-should-work? : ∀{sₗ₂ sᵣ : Size}{sₗ₁ : <ˢⁱᶻᵉ sₗ₂} → (<ˢⁱᶻᵉ (sₗ₂ ⊔ˢⁱᶻᵉ sᵣ))
max-should-work? {sᵣ = sᵣ}{sₗ₁ = sₗ₁} = sₗ₁ ⊔ˢⁱᶻᵉ sᵣ
-}
| 35.314607
| 278
| 0.57111
|
10509db800b365b646bf6d6ecba5cb37e5fea90e
| 304
|
agda
|
Agda
|
Agda.agda
|
abt8601/one-two-three...infinity
|
aba4eb82bc37717b7dcac69277750dfe1067d054
|
[
"Unlicense"
] | 9
|
2017-01-02T18:14:51.000Z
|
2022-02-01T09:01:59.000Z
|
Agda.agda
|
abt8601/one-two-three...infinity
|
aba4eb82bc37717b7dcac69277750dfe1067d054
|
[
"Unlicense"
] | 23
|
2016-09-10T13:51:09.000Z
|
2022-01-23T21:18:50.000Z
|
Agda.agda
|
abt8601/one-two-three...infinity
|
aba4eb82bc37717b7dcac69277750dfe1067d054
|
[
"Unlicense"
] | 18
|
2016-09-09T19:39:43.000Z
|
2022-01-17T23:23:37.000Z
|
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Show using (show)
open import Function using (_$!_)
open import IO using (run; putStrLn)
sum : ℕ
sum = f 1000000000 0
where
f : ℕ → ℕ → ℕ
f zero acc = acc
f (suc n) acc = f n $! suc n + acc
main = run (putStrLn (show sum))
| 21.714286
| 46
| 0.634868
|
395c602a58c5147e2cac949a5c0d4eacfa9d956d
| 2,907
|
agda
|
Agda
|
Data/BitVector/Peano.agda
|
copumpkin/bitvector
|
6902f4bce0330f1b58f48395dac4406056713687
|
[
"BSD-3-Clause"
] | 3
|
2015-01-04T07:19:55.000Z
|
2021-11-12T01:41:07.000Z
|
Data/BitVector/Peano.agda
|
copumpkin/bitvector
|
6902f4bce0330f1b58f48395dac4406056713687
|
[
"BSD-3-Clause"
] | 1
|
2016-05-25T02:00:59.000Z
|
2016-05-25T02:00:59.000Z
|
Data/BitVector/Peano.agda
|
copumpkin/bitvector
|
6902f4bce0330f1b58f48395dac4406056713687
|
[
"BSD-3-Clause"
] | 3
|
2016-05-25T00:15:43.000Z
|
2021-11-12T01:40:57.000Z
|
module Data.BitVector.Peano where
open import Data.BitVector
open import Algebra.FunctionProperties.Core
open import Data.Nat hiding (pred) renaming (suc to Nsuc; zero to Nzero)
open import Data.Vec hiding (fromList)
open import Relation.Binary.PropositionalEquality
open import Data.Digit hiding (Bit)
open import Data.Fin using () renaming (zero to Fzero; suc to Fsuc)
open import Data.List
open import Data.Product
suc : ∀ {n} → Op₁ (BitVector n)
suc [] = []
suc (0# ∷ xs) = 1# ∷ xs
suc (1# ∷ xs) = 0# ∷ suc xs
pred-helper : ∀ {n} → BitVector n → BitVector (Nsuc n)
pred-helper [] = 1# ∷ []
pred-helper (0# ∷ xs) = 1# ∷ pred-helper xs
pred-helper (1# ∷ xs) = 1# ∷ 0# ∷ xs
pred : ∀ {n} → Op₁ (BitVector n)
pred [] = []
pred (1# ∷ xs) = 0# ∷ xs
pred (0# ∷ xs) = pred-helper xs
suc∘pred-helper≡0# : ∀ {n} (x : BitVector n) → suc (pred-helper x) ≡ 0# ∷ x
suc∘pred-helper≡0# [] = refl
suc∘pred-helper≡0# (0# ∷ xs) = cong (_∷_ 0#) (suc∘pred-helper≡0# xs)
suc∘pred-helper≡0# (1# ∷ xs) = refl
pred-helper∘suc≡1# : ∀ {n} (x : BitVector n) → pred-helper (suc x) ≡ 1# ∷ x
pred-helper∘suc≡1# [] = refl
pred-helper∘suc≡1# (0# ∷ xs) = refl
pred-helper∘suc≡1# (1# ∷ xs) = cong (_∷_ 1#) (pred-helper∘suc≡1# xs)
suc∘pred≡id : ∀ {n} (x : BitVector n) → suc (pred x) ≡ x
suc∘pred≡id [] = refl
suc∘pred≡id (0# ∷ xs) = suc∘pred-helper≡0# xs
suc∘pred≡id (1# ∷ xs) = refl
pred∘suc≡id : ∀ {n} (x : BitVector n) → pred (suc x) ≡ x
pred∘suc≡id [] = refl
pred∘suc≡id (0# ∷ xs) = refl
pred∘suc≡id (1# ∷ xs) = pred-helper∘suc≡1# xs
data Peano : ∀ {n} → BitVector n → Set where
Pzero : ∀ {n} → Peano (zero n)
Psuc : ∀ {n} {x : BitVector n} → (p : Peano x) → Peano (suc x)
Pdouble : ∀ {n} {x : BitVector n} → Peano x → Peano (0# ∷ x)
Pdouble Pzero = Pzero
Pdouble (Psuc p) = Psuc (Psuc (Pdouble p))
toPeano : ∀ {n} (x : BitVector n) → Peano x
toPeano [] = Pzero
toPeano (0# ∷ xs) = Pdouble (toPeano xs)
toPeano (1# ∷ xs) = Psuc (Pdouble (toPeano xs))
peanoInduction : ∀ {n} → (P : ∀ {x : BitVector n} → Peano x → Set) → P Pzero
→ (∀ {x : BitVector n} {m : Peano x} → P m → P (Psuc m))
→ ∀ {x : BitVector n} (q : Peano x) → P q
peanoInduction P z s Pzero = z
peanoInduction P z s (Psuc p) = s {_} {p} (peanoInduction P z s p)
induction : ∀ {n} (P : BitVector n → Set) → P (zero n)
→ (∀ {m} → P m → P (suc m)) → ∀ x → P x
induction P z s x = peanoInduction (λ {x} _ → P x) z s (toPeano x)
toℕ : ∀ {n} → BitVector n → ℕ
toℕ = induction _ 0 Nsuc
fromDigit : Digit 2 → Bit
fromDigit Fzero = 0#
fromDigit (Fsuc Fzero) = 1#
fromDigit (Fsuc (Fsuc ()))
fromList : ∀ {n} → List (Digit 2) → BitVector n
fromList [] = zero _
fromList {Nzero} (x ∷ xs) = []
fromList {Nsuc n} (x ∷ xs) = fromDigit x ∷ fromList xs
fromℕ : ∀ {n} → ℕ → BitVector n
fromℕ n with toDigits 2 n
fromℕ .(fromDigits ds) | ds , refl = fromList ds
-- TODO: the terrifying proofs that toℕ and fromℕ are inverses
| 31.597826
| 76
| 0.596491
|
50c4ae94e3bbc3d2030afadea35294a082fdc4f5
| 2,761
|
agda
|
Agda
|
Cubical/Algebra/NatSolver/HornerForms.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Algebra/NatSolver/HornerForms.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/NatSolver/HornerForms.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.NatSolver.HornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool using (Bool; true; false; if_then_else_)
private
variable
ℓ : Level
{-
This defines the type of multivariate Polynomials over ℕ.
The construction is based on the algebraic fact
ℕ[X₀][X₁]⋯[Xₙ] ≅ ℕ[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n k' is identified
with 'Xₖ', what we construct should rather be denoted with
ℕ[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((ℕ[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms : ℕ → Type ℓ-zero where
const : ℕ → IteratedHornerForms ℕ.zero
0H : {n : ℕ} → IteratedHornerForms (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms (ℕ.suc n) → IteratedHornerForms n
→ IteratedHornerForms (ℕ.suc n)
eval : {n : ℕ} (P : IteratedHornerForms n)
→ Vec ℕ n → ℕ
eval (const r) [] = r
eval 0H (_ ∷ _) = 0
eval (P ·X+ Q) (x ∷ xs) =
(eval P (x ∷ xs)) · x + eval Q xs
module IteratedHornerOperations where
private
1H' : (n : ℕ) → IteratedHornerForms n
1H' ℕ.zero = const 1
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms n
0H' ℕ.zero = const 0
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms n
→ IteratedHornerForms n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) = (P +ₕ Q) ·X+ (r +ₕ s)
isZero : {n : ℕ} → IteratedHornerForms (ℕ.suc n)
→ Bool
isZero 0H = true
isZero (P ·X+ P₁) = false
_⋆_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms (ℕ.suc n)
→ IteratedHornerForms (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms n
→ IteratedHornerForms n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) = (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
Variable : (n : ℕ) (k : Fin n) → IteratedHornerForms n
Variable n k = IteratedHornerOperations.X n k
Constant : (n : ℕ) (r : ℕ) → IteratedHornerForms n
Constant ℕ.zero r = const r
Constant (ℕ.suc n) r = IteratedHornerOperations.0ₕ ·X+ Constant n r
| 27.336634
| 75
| 0.59109
|
3dc38d2517537eaed7978fe2fde624ec9018db94
| 762
|
agda
|
Agda
|
examples/AIM6/Path/Examples.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/AIM6/Path/Examples.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/AIM6/Path/Examples.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Examples where
open import Prelude
open import Star
open import Modal
El : Set -> Rel True
El A _ _ = A
List : Set -> Set
List A = Star (El A) _ _
Nat = List True
zero : Nat
zero = ε
suc : Nat -> Nat
suc n = _ • n
-- Vectors
Vec : Set -> Nat -> Set
Vec A = All (\_ -> A)
infixr 40 _::_
_::_ : {A : Set}{n : Nat} -> A -> Vec A n -> Vec A (suc n)
x :: xs = check x • xs
-- Fin
Fin : Nat -> Set
Fin = Any (\_ -> True)
-- Turning a vector to a list
vecToList : {A : Set}{n : Nat} -> Vec A n -> List A
vecToList {A} = map ! uncheck
listToVec : {A : Set}(xs : List A) -> Vec A (length xs)
listToVec ε = ε
listToVec (x • xs) = x :: listToVec xs
-- span
test : Vec Nat (suc (suc (suc zero)))
test = zero :: suc zero :: suc (suc zero) :: ε
| 15.55102
| 58
| 0.562992
|
3ded0cc04f967c60aca92237cece5447eb5b14e0
| 1,357
|
agda
|
Agda
|
Cubical/HITs/Delooping/Two/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Delooping/Two/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Delooping/Two/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe --no-import-sorts #-}
module Cubical.HITs.Delooping.Two.Base where
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
-- Explicit construction of the delooping of the two-element group
data Bℤ₂ : Type₀ where
base : Bℤ₂
loop : base ≡ base
loop² : Square loop refl refl loop
trunc : isGroupoid Bℤ₂
private
variable
ℓ : Level
A : Type ℓ
module Elim where
rec : (x : A)
→ (p : x ≡ x)
→ (sq : Square p refl refl p)
→ isGroupoid A
→ Bℤ₂ → A
rec x p sq Agpd = go
where
go : _ → _
go base = x
go (loop i) = p i
go (loop² i j) = sq i j
go (trunc x y p q r s i j k)
= Agpd
(go x) (go y)
(cong go p) (cong go q)
(cong (cong go) r) (cong (cong go) s)
i j k
elim : (P : Bℤ₂ → Type ℓ)
→ (x : P base)
→ (p : PathP (λ i → P (loop i)) x x)
→ (sq : SquareP (λ i j → P (loop² i j)) p (λ i → x) (λ i → x) p)
→ isOfHLevelDep 3 P
→ (z : Bℤ₂) → P z
elim P x p sq Pgpd = go
where
go : (z : Bℤ₂) → P z
go base = x
go (loop i) = p i
go (loop² i j) = sq i j
go (trunc x y p q r s i j k)
= Pgpd (go x) (go y)
(cong go p) (cong go q)
(cong (cong go) r) (cong (cong go) s)
(trunc x y p q r s) i j k
| 24.232143
| 71
| 0.508475
|
595a2bd1f4cf569782a017b6fc64f368110792bb
| 2,764
|
agda
|
Agda
|
Univalence/Obsolete/Cauchy2.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/Obsolete/Cauchy2.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/Obsolete/Cauchy2.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
-- this is mostly reference for an unused intermediate step.
module Cauchy2 where
open import Data.Nat
open import Data.Vec renaming (map to mapV; _++_ to _++V_; concat to concatV)
open import Data.Fin using (Fin; inject+; raise; inject≤; fromℕ; toℕ)
open import Function using (id)
open import Relation.Binary.PropositionalEquality using (_≡_; subst)
open import VectorLemmas
open import LeqLemmas
open import Cauchy using (id+)
Cauchy : ℕ → ℕ → Set
Cauchy n₁ n₂ = Vec (Fin n₁) n₂
------------------------------------------------------------------------------
-- Elementary permutations in the Cauchy representation
emptycauchy : Cauchy 0 0
emptycauchy = []
idcauchy : (n : ℕ) → Cauchy n n
idcauchy = allFin
-- Sequential composition
scompcauchy : ∀ {n₀ n₁ n₂} → Cauchy n₁ n₀ → Cauchy n₂ n₁ → Cauchy n₂ n₀
scompcauchy {n} perm₁ perm₂ =
tabulate (λ i → lookup (lookup i perm₁) perm₂)
-- swap the first m elements with the last n elements
-- [ v₀ , v₁ , v₂ , ... , vm-1 , vm , vm₊₁ , ... , vm+n-1 ]
-- ==>
-- [ vm , vm₊₁ , ... , vm+n-1 , v₀ , v₁ , v₂ , ... , vm-1 ]
swap+cauchy : (m n : ℕ) → Cauchy (m + n) (n + m)
swap+cauchy m n = {!!} -- tabulate swapper
-- Parallel additive composition
-- append both permutations but adjust the indices in the second
-- permutation by the size of the first type so that it acts on the
-- second part of the vector
pcompcauchy : ∀ {m₁ n₁ m₂ n₂} → Cauchy m₁ m₂ → Cauchy n₁ n₂ → Cauchy (m₁ + n₁) (m₂ + n₂)
pcompcauchy {m} {n} α β = mapV (inject+ n) α ++V mapV (raise m) β
-- Tensor multiplicative composition
-- Transpositions in α correspond to swapping entire rows
-- Transpositions in β correspond to swapping entire columns
tcompcauchy : ∀ {m₁ n₁ m₂ n₂} → Cauchy m₁ m₂ → Cauchy n₁ n₂ → Cauchy (m₁ * n₁) (m₂ * n₂)
tcompcauchy {m} {n} α β =
concatV
(mapV
(λ b →
mapV (λ d → inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d)) β)
α)
-- swap⋆
--
-- This is essentially the classical problem of in-place matrix transpose:
-- "http://en.wikipedia.org/wiki/In-place_matrix_transposition"
-- Given m and n, the desired permutation in Cauchy representation is:
-- P(i) = m*n-1 if i=m*n-1
-- = m*i mod m*n-1 otherwise
transposeIndex : (m n : ℕ) →
(b : Fin m) → (d : Fin n) → Fin (n * m)
transposeIndex m n b d =
inject≤ (fromℕ (toℕ d * m + toℕ b))
(i*n+k≤m*n d b)
{- inject≤
(fromℕ (toℕ d * m + toℕ b))
(trans≤ (i*n+k≤m*n d b) (refl′ (*-comm n m))) -}
swap⋆cauchy : (m₁ n₁ m₂ n₂ : ℕ) → (meq : m₂ ≡ m₁) → (neq : n₂ ≡ n₁) → Cauchy (n₁ * m₁) (n₂ * m₂)
swap⋆cauchy m₁ n₁ m₂ n₂ meq neq =
concatV (mapV
(λ d → mapV (λ b → transposeIndex m₁ n₁ (subst Fin meq b) (subst Fin neq d)) (allFin m₂))
(allFin n₂))
| 33.301205
| 100
| 0.611795
|
12f2036241a98554bd0b799c77b7a89afa2a09c6
| 1,225
|
agda
|
Agda
|
src/scratch/Data/List/Relation/Helpers.agda
|
zampino/ggt
|
e2d6b5f9bea15dd67817bf67e273f6b9a14335af
|
[
"MIT"
] | 2
|
2020-04-17T11:10:00.000Z
|
2020-11-28T05:48:39.000Z
|
src/scratch/Data/List/Relation/Helpers.agda
|
zampino/ggt
|
e2d6b5f9bea15dd67817bf67e273f6b9a14335af
|
[
"MIT"
] | null | null | null |
src/scratch/Data/List/Relation/Helpers.agda
|
zampino/ggt
|
e2d6b5f9bea15dd67817bf67e273f6b9a14335af
|
[
"MIT"
] | null | null | null |
module Scratch.Data.List.Relation.Helpers where
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Unary
open import Relation.Binary hiding (Decidable)
open import Data.Product
open import Data.List.Base
open import Data.List.Relation.Unary.All as All
open import Data.List.Relation.Unary.All.Properties
open import Data.List.Relation.Unary.AllPairs
module _ {a ℓ ℓ₁ ℓ₂} {A : Set a}
{R : Rel A ℓ₁} {S : Rel A ℓ₂}
{P : Pred A ℓ} (P? : Decidable P) where
filter⁺⁺ : ∀ {xs} → (∀ {x y} → P x → P y → R x y → S x y) →
AllPairs R xs → AllPairs S (filter P? xs)
filter⁺⁺ {[]} _ _ = []
filter⁺⁺ {x ∷ xs} Δ (h ∷ t) with (P? x)
... | yes p = let
hf : All (R x) (filter P? xs)
hf = filter⁺ P? h
ap : All P (filter P? xs)
ap = all-filter P? xs
w : All (P ∩ R x) (filter P? xs)
w = All.zip ( ap , hf )
y : P ∩ R x ⊆ S x
y = λ z → Δ p (proj₁ z) (proj₂ z)
z : All (S x) (filter P? xs)
z = All.map y w
in z ∷ filter⁺⁺ {xs} Δ t
... | no ¬p = filter⁺⁺ {xs} Δ t
| 33.108108
| 61
| 0.505306
|
5815899853777d073c37474c5d7e46990eb8d533
| 266
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Char/Properties.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
src/data/lib/prim/Agda/Builtin/Char/Properties.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
src/data/lib/prim/Agda/Builtin/Char/Properties.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-}
module Agda.Builtin.Char.Properties where
open import Agda.Builtin.Char
open import Agda.Builtin.Equality
primitive
primCharToNatInjective : ∀ a b → primCharToNat a ≡ primCharToNat b → a ≡ b
| 24.181818
| 76
| 0.740602
|
2030025656da349e5cff7fe15c815afc7cf44d60
| 37,830
|
agda
|
Agda
|
src/Indexed-container/Combinators.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Indexed-container/Combinators.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Indexed-container/Combinators.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Container combinators
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Indexed-container.Combinators where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id; const) renaming (_∘_ to _⊚_)
open import Prelude.Size
open import Bijection equality-with-J as Bijection using (_↔_)
import Equivalence equality-with-J as Eq
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import Indexed-container
open import Relation
-- An identity combinator.
--
-- Taken from "Indexed containers" by Altenkirch, Ghani, Hancock,
-- McBride and Morris (JFP, 2015).
id : ∀ {i} {I : Type i} → Container I I
id = (λ _ → ↑ _ ⊤) ◁ λ {i} _ i′ → i ≡ i′
-- An unfolding lemma for ⟦ id ⟧.
⟦id⟧↔ : ∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} {i} →
Extensionality? k ℓ (ℓ ⊔ x) →
⟦ id ⟧ X i ↝[ k ] X i
⟦id⟧↔ {X = X} {i} ext =
↑ _ ⊤ × (λ i′ → i ≡ i′) ⊆ X ↔⟨ drop-⊤-left-× (λ _ → Bijection.↑↔) ⟩
(λ i′ → i ≡ i′) ⊆ X ↔⟨⟩
(∀ {i′} → i ≡ i′ → X i′) ↔⟨ Bijection.implicit-Π↔Π ⟩
(∀ i′ → i ≡ i′ → X i′) ↝⟨ inverse-ext? (λ ext → ∀-intro _ ext) ext ⟩□
X i □
-- An unfolding lemma for ⟦ id ⟧₂.
⟦id⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} →
Extensionality? k ℓ ℓ →
∀ (R : ∀ {i} → Rel₂ ℓ (X i)) {i} →
(x y : ⟦ id ⟧ X i) →
⟦ id ⟧₂ R (x , y)
↝[ k ]
proj₁ x ≡ proj₁ y × R (proj₂ x refl , proj₂ y refl)
⟦id⟧₂↔ ext R {i} x@(s , f) y@(t , g) =
⟦ id ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : i ≡ o) →
R (f p , g (subst (λ _ → i ≡ o) eq p))) ↔⟨ ∃-cong (λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ o (p : i ≡ o) →
R (f p , g (subst (λ _ → i ≡ o) eq p))) ↝⟨ ∃-cong (λ _ → inverse-ext? (λ ext → ∀-intro _ ext) ext) ⟩
(∃ λ (eq : s ≡ t) →
R (f refl , g (subst (λ _ → i ≡ i) eq refl))) ↝⟨ ∃-cong (λ eq → ≡⇒↝ _ (cong (λ eq → R (f refl , g eq)) (subst-const eq))) ⟩
s ≡ t × R (f refl , g refl) □
-- A second unfolding lemma for ⟦ id ⟧₂.
⟦id⟧₂≡↔ :
∀ {ℓ} {I : Type ℓ} {X : Rel ℓ I} {i} →
Extensionality ℓ ℓ →
(x y : ⟦ id ⟧ X i) →
⟦ id ⟧₂ (uncurry _≡_) (x , y) ↔ x ≡ y
⟦id⟧₂≡↔ ext x@(s , f) y@(t , g) =
⟦ id ⟧₂ (uncurry _≡_) (x , y) ↝⟨ ⟦id⟧₂↔ ext (uncurry _≡_) x y ⟩
s ≡ t × f refl ≡ g refl ↔⟨ ∃-cong (λ _ → Eq.≃-≡ (Eq.↔⇒≃ $ inverse $ ∀-intro _ ext)) ⟩
s ≡ t × (λ _ → f) ≡ (λ _ → g) ↔⟨ ∃-cong (λ _ → Eq.≃-≡ (Eq.↔⇒≃ Bijection.implicit-Π↔Π)) ⟩
s ≡ t × (λ {_} → f) ≡ g ↝⟨ ≡×≡↔≡ ⟩
x ≡ y □
-- A constant combinator.
const : ∀ {i} {I : Type i} → Rel i I → Container I I
const X = X ◁ λ _ _ → ⊥
-- An unfolding lemma for ⟦ const ⟧.
⟦const⟧↔ : ∀ {k ℓ y} {I : Type ℓ} X {Y : Rel y I} {i} →
Extensionality? k ℓ (ℓ ⊔ y) →
⟦ const X ⟧ Y i ↝[ k ] X i
⟦const⟧↔ {k} {ℓ} {I = I} X {Y} {i} ext =
X i × (∀ {i} → ⊥ → Y i) ↔⟨ ∃-cong (λ _ → Bijection.implicit-Π↔Π) ⟩
X i × (∀ i → ⊥ → Y i) ↝⟨ ∃-cong (λ _ → ∀-cong ext λ _ → Π⊥↔⊤ (lower-extensionality? k lzero ℓ ext)) ⟩
X i × (I → ⊤) ↔⟨ drop-⊤-right (λ _ → →-right-zero) ⟩
X i □
-- An unfolding lemma for ⟦ const ⟧₂.
⟦const⟧₂↔ :
∀ {k ℓ y} {I : Type ℓ} {X} {Y : Rel y I} →
Extensionality? k ℓ ℓ →
∀ (R : ∀ {i} → Rel₂ ℓ (Y i)) {i}
(x y : ⟦ const X ⟧ Y i) →
⟦ const X ⟧₂ R (x , y)
↝[ k ]
proj₁ x ≡ proj₁ y
⟦const⟧₂↔ {X = X} ext R x@(s , f) y@(t , g) =
⟦ const X ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : ⊥) → R (f p , g (subst (λ _ → ⊥) eq p))) ↔⟨ ∃-cong (λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ o (p : ⊥) → R (f p , g (subst (λ _ → ⊥) eq p))) ↝⟨ ∃-cong (λ _ → ∀-cong ext λ _ → Π⊥↔⊤ ext) ⟩
(∃ λ (eq : s ≡ t) → ∀ o → ⊤) ↔⟨ drop-⊤-right (λ _ → →-right-zero) ⟩
s ≡ t □
where
open Container
-- A composition combinator.
infixr 9 _∘_
_∘_ : ∀ {ℓ} {I J K : Type ℓ} →
Container J K → Container I J → Container I K
C ∘ D =
⟦ C ⟧ (Shape D)
◁
(λ { (s , f) i →
∃ λ j → ∃ λ (p : Position C s j) → Position D (f p) i })
where
open Container
-- An unfolding lemma for ⟦ C ∘ D ⟧.
⟦∘⟧↔ : ∀ {fk ℓ x} {I J K : Type ℓ} {X : Rel x I} →
Extensionality? fk ℓ (ℓ ⊔ x) →
∀ (C : Container J K) {D : Container I J} {k} →
⟦ C ∘ D ⟧ X k ↝[ fk ] ⟦ C ⟧ (⟦ D ⟧ X) k
⟦∘⟧↔ {X = X} ext C {D} {k} =
⟦ C ∘ D ⟧ X k ↔⟨⟩
(∃ λ { (s , f) →
∀ {i} →
(∃ λ j → ∃ λ (p : Position C s j) → Position D (f p) i) →
X i }) ↔⟨ inverse Σ-assoc ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ {i} →
(∃ λ j → ∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-∀-cong ext $
from-isomorphism currying) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ {i} j →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ i j →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Π-comm) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ j i →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → inverse Bijection.implicit-Π↔Π) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ {j} i →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → inverse implicit-ΠΣ-comm) ⟩
(∃ λ s → ∀ {j} →
∃ λ (f : Position C s j → Shape D j) →
∀ i →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∃-cong λ _ → ∀-cong ext λ _ →
from-isomorphism currying) ⟩
(∃ λ s → ∀ {j} →
∃ λ (f : Position C s j → Shape D j) →
∀ i → (p : Position C s j) → Position D (f p) i → X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∃-cong λ _ → from-isomorphism Π-comm) ⟩
(∃ λ s → ∀ {j} →
∃ λ (f : Position C s j → Shape D j) →
(p : Position C s j) → ∀ i → Position D (f p) i → X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ from-isomorphism $ inverse ΠΣ-comm) ⟩
(∃ λ s → ∀ {j} → Position C s j →
∃ λ (s′ : Shape D j) → ∀ i → Position D s′ i → X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∀-cong ext λ _ → ∃-cong λ _ →
from-isomorphism $ inverse Bijection.implicit-Π↔Π) ⟩
(∃ λ s → ∀ {j} → Position C s j →
∃ λ (s′ : Shape D j) → Position D s′ ⊆ X) ↔⟨⟩
⟦ C ⟧ (⟦ D ⟧ X) k □
where
open Container
-- TODO: Define ⟦∘⟧₂↔ (an unfolding lemma for ⟦ C ∘ D ⟧₂).
-- A reindexing combinator.
--
-- Taken from "Indexed containers".
reindex₂ : ∀ {ℓ} {I O₁ O₂ : Type ℓ} →
(O₂ → O₁) → Container I O₁ → Container I O₂
reindex₂ f (S ◁ P) = (S ⊚ f) ◁ P
-- An unfolding lemma for ⟦ reindex₂ f C ⟧.
⟦reindex₂⟧↔ : ∀ {ℓ x} {I O₁ O₂ : Type ℓ} (f : O₂ → O₁)
(C : Container I O₁) {X : Rel x I} {o} →
⟦ reindex₂ f C ⟧ X o ↔ ⟦ C ⟧ X (f o)
⟦reindex₂⟧↔ f C = Bijection.id
-- An unfolding lemma for ⟦ reindex₂ f C ⟧₂.
⟦reindex₂⟧₂↔ :
∀ {ℓ x} {I O : Type ℓ} {X : Rel x I}
(C : Container I O) (f : I → O) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ reindex₂ f C ⟧ X i) →
⟦ reindex₂ f C ⟧₂ R (x , y) ↔ ⟦ C ⟧₂ R (x , y)
⟦reindex₂⟧₂↔ C f R x@(s , g) y@(t , h) =
⟦ reindex₂ f C ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : Position (reindex₂ f C) s o) →
R (g p , h (subst (λ s → Position (reindex₂ f C) s o) eq p))) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : Position C s o) →
R (g p , h (subst (λ s → Position C s o) eq p))) ↔⟨⟩
⟦ C ⟧₂ R (x , y) □
where
open Container
-- Another reindexing combinator.
reindex₁ : ∀ {ℓ} {I₁ I₂ O : Type ℓ} →
(I₁ → I₂) → Container I₁ O → Container I₂ O
reindex₁ f C =
Shape C
◁
(λ s i → ∃ λ i′ → f i′ ≡ i × Position C s i′)
where
open Container
-- An unfolding lemma for ⟦ reindex₁ f C ⟧.
⟦reindex₁⟧↔ : ∀ {k ℓ x} {I₁ I₂ O : Type ℓ} {f : I₁ → I₂} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C : Container I₁ O) {X : Rel x I₂} {o} →
⟦ reindex₁ f C ⟧ X o ↝[ k ] ⟦ C ⟧ (X ⊚ f) o
⟦reindex₁⟧↔ {f = f} ext C {X} {o} =
⟦ reindex₁ f C ⟧ X o ↔⟨ (∃-cong λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ (s : Shape C o) →
∀ i → (∃ λ i′ → f i′ ≡ i × Position C s i′) → X i) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → from-isomorphism currying) ⟩
(∃ λ (s : Shape C o) →
∀ i i′ → f i′ ≡ i × Position C s i′ → X i) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → from-isomorphism currying) ⟩
(∃ λ (s : Shape C o) →
∀ i i′ → f i′ ≡ i → Position C s i′ → X i) ↔⟨ (∃-cong λ _ → Π-comm) ⟩
(∃ λ (s : Shape C o) →
∀ i i′ → f i ≡ i′ → Position C s i → X i′) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → inverse-ext? (λ ext → ∀-intro _ ext) ext) ⟩
(∃ λ (s : Shape C o) →
∀ i → Position C s i → X (f i)) ↔⟨ (∃-cong λ _ → inverse Bijection.implicit-Π↔Π) ⟩
⟦ C ⟧ (X ⊚ f) o □
where
open Container
-- An unfolding lemma for ⟦ reindex₁ f C ⟧₂.
⟦reindex₁⟧₂↔ :
∀ {k ℓ x} {I O : Type ℓ} {X : Rel x O} →
Extensionality? k ℓ ℓ →
∀ (C : Container I O) (f : I → O) (R : ∀ {o} → Rel₂ ℓ (X o)) {o}
(x y : ⟦ reindex₁ f C ⟧ X o) →
⟦ reindex₁ f C ⟧₂ R (x , y)
↝[ k ]
⟦ C ⟧₂ R ( (proj₁ x , λ p → proj₂ x (_ , refl , p))
, (proj₁ y , λ p → proj₂ y (_ , refl , p))
)
⟦reindex₁⟧₂↔ ext C f R x@(s , g) y@(t , h) =
⟦ reindex₁ f C ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : ∃ λ o′ → f o′ ≡ o × Position C s o′) →
R (g p , h (subst (λ s → ∃ λ o′ → f o′ ≡ o × Position C s o′) eq p))) ↝⟨ (∃-cong λ eq → implicit-∀-cong ext $ ∀-cong ext λ _ →
≡⇒↝ _ $ cong (R ⊚ (g _ ,_) ⊚ h) $
lemma eq) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : ∃ λ o′ → f o′ ≡ o × Position C s o′) →
R ( g p
, h ( proj₁ p
, proj₁ (proj₂ p)
, subst (λ s → Position C s (proj₁ p)) eq (proj₂ (proj₂ p))
)
)) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ from-isomorphism
currying) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} o′ (p : f o′ ≡ o × Position C s o′) →
R ( g (o′ , p)
, h (o′ , proj₁ p , subst (λ s → Position C s o′) eq (proj₂ p))
)) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∀-cong ext λ _ → from-isomorphism
currying) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} o′ (≡o : f o′ ≡ o) (p : Position C s o′) →
R ( g (o′ , ≡o , p)
, h (o′ , ≡o , subst (λ s → Position C s o′) eq p)
)) ↔⟨ (∃-cong λ _ →
Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ o o′ (≡o : f o′ ≡ o) (p : Position C s o′) →
R ( g (o′ , ≡o , p)
, h (o′ , ≡o , subst (λ s → Position C s o′) eq p)
)) ↔⟨ (∃-cong λ _ →
Π-comm) ⟩
(∃ λ (eq : s ≡ t) →
∀ o o′ (≡o′ : f o ≡ o′) (p : Position C s o) →
R ( g (o , ≡o′ , p)
, h (o , ≡o′ , subst (λ s → Position C s o) eq p)
)) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ →
inverse-ext? (λ ext → ∀-intro _ ext) ext) ⟩
(∃ λ (eq : s ≡ t) →
∀ o (p : Position C s o) →
R ( g (o , refl , p)
, h (o , refl , subst (λ s → Position C s o) eq p)
)) ↔⟨ (∃-cong λ _ → inverse
Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : Position C s o) →
R ( g (o , refl , p)
, h (o , refl , subst (λ s → Position C s o) eq p)
)) ↔⟨⟩
⟦ C ⟧₂ R ((s , λ p → g (_ , refl , p)) , (t , λ p → h (_ , refl , p))) □
where
open Container
lemma = λ (eq : s ≡ t) {o} {p : ∃ λ o′ → f o′ ≡ o × Position C s o′} →
subst (λ s → ∃ λ o′ → f o′ ≡ o × Position C s o′) eq p ≡⟨ push-subst-pair′ {y≡z = eq} _ _ (subst-const eq) ⟩
( proj₁ p
, subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
(Σ-≡,≡→≡ eq (subst-const eq)) (proj₂ p)
) ≡⟨⟩
( proj₁ p
, subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
(Σ-≡,≡→≡ eq (trans (subst-const eq) refl)) (proj₂ p)
) ≡⟨ cong (λ eq → _ , subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
eq (proj₂ p)) $
Σ-≡,≡→≡-subst-const eq refl ⟩
( proj₁ p
, subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
(cong₂ _,_ eq refl) (proj₂ p)
) ≡⟨ cong (_ ,_) $
push-subst-, {y≡z = cong₂ _,_ eq refl}
((_≡ o) ⊚ f ⊚ proj₂) (uncurry (Position C)) ⟩
( proj₁ p
, subst ((_≡ o) ⊚ f ⊚ proj₂) (cong₂ _,_ eq refl) (proj₁ (proj₂ p))
, subst (uncurry (Position C)) (cong₂ _,_ eq refl) (proj₂ (proj₂ p))
) ≡⟨ cong (λ eq′ → _ , eq′
, subst (uncurry (Position C)) (cong₂ _,_ eq refl) _) $
subst-∘ ((_≡ o) ⊚ f) proj₂ (cong₂ _,_ eq refl) ⟩
( proj₁ p
, subst ((_≡ o) ⊚ f)
(cong proj₂ (cong₂ _,_ eq refl)) (proj₁ (proj₂ p))
, subst (uncurry (Position C)) (cong (_, _) eq) (proj₂ (proj₂ p))
) ≡⟨ cong₂ (λ eq₁ eq₂ → _ , subst ((_≡ o) ⊚ f) eq₁ _ , eq₂)
(cong-proj₂-cong₂-, eq refl)
(sym $ subst-∘ (uncurry (Position C)) (_, _) eq) ⟩
( proj₁ p
, subst ((_≡ o) ⊚ f) refl (proj₁ (proj₂ p))
, subst (uncurry (Position C) ⊚ (_, _)) eq (proj₂ (proj₂ p))
) ≡⟨⟩
( proj₁ p
, proj₁ (proj₂ p)
, subst (λ s → Position C s (proj₁ p)) eq (proj₂ (proj₂ p))
) ∎
-- A combined reindexing combinator.
--
-- The application reindex swap is similar to the overline function
-- from Section 6.3.4.1 in Pous and Sangiorgi's "Enhancements of the
-- bisimulation proof method".
reindex : ∀ {ℓ} {I O : Type ℓ} →
(I → O) → Container I O → Container O I
reindex f = reindex₂ f ⊚ reindex₁ f
-- An unfolding lemma for ⟦ reindex f C ⟧.
⟦reindex⟧↔ : ∀ {k ℓ x} {I O : Type ℓ} {f : I → O} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C : Container I O) {X : Rel x O} {i} →
⟦ reindex f C ⟧ X i ↝[ k ] ⟦ C ⟧ (X ⊚ f) (f i)
⟦reindex⟧↔ {f = f} ext C {X} {i} =
⟦ reindex f C ⟧ X i ↔⟨⟩
⟦ reindex₂ f (reindex₁ f C) ⟧ X i ↔⟨⟩
⟦ reindex₁ f C ⟧ X (f i) ↝⟨ ⟦reindex₁⟧↔ ext C ⟩□
⟦ C ⟧ (X ⊚ f) (f i) □
-- An unfolding lemma for ⟦ reindex f C ⟧₂.
⟦reindex⟧₂↔ :
∀ {k ℓ x} {I O : Type ℓ} {X : Rel x O} →
Extensionality? k ℓ ℓ →
∀ (C : Container I O) (f : I → O) (R : ∀ {o} → Rel₂ ℓ (X o)) {i}
(x y : ⟦ reindex f C ⟧ X i) →
⟦ reindex f C ⟧₂ R (x , y)
↝[ k ]
⟦ C ⟧₂ R ( (proj₁ x , λ p → proj₂ x (_ , refl , p))
, (proj₁ y , λ p → proj₂ y (_ , refl , p))
)
⟦reindex⟧₂↔ ext C f R x y =
⟦ reindex f C ⟧₂ R (x , y) ↔⟨⟩
⟦ reindex₂ f (reindex₁ f C) ⟧₂ R (x , y) ↔⟨⟩
⟦ reindex₁ f C ⟧₂ R (x , y) ↝⟨ ⟦reindex₁⟧₂↔ ext C f R x y ⟩□
⟦ C ⟧₂ R ( (proj₁ x , λ p → proj₂ x (_ , refl , p))
, (proj₁ y , λ p → proj₂ y (_ , refl , p))
) □
-- If f is an involution, then ν (reindex f C) i is pointwise
-- logically equivalent to ν C i ⊚ f.
mutual
ν-reindex⇔ :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {f : I → I} →
f ⊚ f ≡ P.id →
∀ {i x} → ν (reindex f C) i x ⇔ ν C i (f x)
ν-reindex⇔ {C = C} {f} inv {i} {x} =
ν (reindex f C) i x ↔⟨⟩
⟦ reindex f C ⟧ (ν′ (reindex f C) i) x ↝⟨ ⟦reindex⟧↔ _ C ⟩
⟦ C ⟧ (ν′ (reindex f C) i ⊚ f) (f x) ↝⟨ ⟦⟧-cong _ C (ν′-reindex⇔ inv) ⟩
⟦ C ⟧ (ν′ C i ⊚ f ⊚ f) (f x) ↔⟨ ≡⇒↝ bijection $ cong (λ g → ⟦ C ⟧ (ν′ C i ⊚ g) (f x)) inv ⟩
⟦ C ⟧ (ν′ C i) (f x) ↔⟨⟩
ν C i (f x) □
ν′-reindex⇔ :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {f : I → I} →
f ⊚ f ≡ P.id →
∀ {i x} → ν′ (reindex f C) i x ⇔ ν′ C i (f x)
ν′-reindex⇔ {C = C} {f} inv = record { to = to; from = from }
where
to : ∀ {i} → ν′ (reindex f C) i ⊆ ν′ C i ⊚ f
force (to x) = _⇔_.to (ν-reindex⇔ inv) (force x)
from : ∀ {i} → ν′ C i ⊚ f ⊆ ν′ (reindex f C) i
force (from x) = _⇔_.from (ν-reindex⇔ inv) (force x)
-- A cartesian product combinator.
--
-- Similar to a construction in "Containers: Constructing strictly
-- positive types" by Abbott, Altenkirch and Ghani (see
-- Proposition 3.5).
infixr 2 _⊗_
_⊗_ : ∀ {ℓ} {I O : Type ℓ} →
Container I O → Container I O → Container I O
C₁ ⊗ C₂ =
(λ o → Shape C₁ o × Shape C₂ o)
◁
(λ { (s₁ , s₂) i → Position C₁ s₁ i ⊎ Position C₂ s₂ i })
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊗ C₂ ⟧.
⟦⊗⟧↔ : ∀ {k ℓ x} {I O : Type ℓ} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C₁ C₂ : Container I O) {X : Rel x I} {o} →
⟦ C₁ ⊗ C₂ ⟧ X o ↝[ k ] ⟦ C₁ ⟧ X o × ⟦ C₂ ⟧ X o
⟦⊗⟧↔ {k} {ℓ} ext C₁ C₂ {X} {o} =
⟦ C₁ ⊗ C₂ ⟧ X o ↔⟨⟩
(∃ λ (s : Shape C₁ o × Shape C₂ o) →
(λ i → Position C₁ (proj₁ s) i ⊎ Position C₂ (proj₂ s) i) ⊆ X) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (s₁ : Shape C₁ o) →
∃ λ (s₂ : Shape C₂ o) →
(λ i → Position C₁ s₁ i ⊎ Position C₂ s₂ i) ⊆ X) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-∀-cong ext $
Π⊎↔Π×Π (lower-extensionality? k lzero ℓ ext)) ⟩
(∃ λ (s₁ : Shape C₁ o) →
∃ λ (s₂ : Shape C₂ o) →
∀ {i} → (Position C₁ s₁ i → X i) × (Position C₂ s₂ i → X i)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-ΠΣ-comm) ⟩
(∃ λ (s₁ : Shape C₁ o) →
∃ λ (s₂ : Shape C₂ o) →
Position C₁ s₁ ⊆ X × Position C₂ s₂ ⊆ X) ↔⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ (s₁ : Shape C₁ o) →
Position C₁ s₁ ⊆ X
×
∃ λ (s₂ : Shape C₂ o) → Position C₂ s₂ ⊆ X) ↔⟨ Σ-assoc ⟩
(∃ λ (s : Shape C₁ o) → Position C₁ s ⊆ X) ×
(∃ λ (s : Shape C₂ o) → Position C₂ s ⊆ X) ↔⟨⟩
⟦ C₁ ⟧ X o × ⟦ C₂ ⟧ X o □
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊗ C₂ ⟧₂.
⟦⊗⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} →
Extensionality? k ℓ ℓ →
∀ (C₁ C₂ : Container I I) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ C₁ ⊗ C₂ ⟧ X i) →
let (x₁ , x₂) , f = x
(y₁ , y₂) , g = y
in
⟦ C₁ ⊗ C₂ ⟧₂ R (x , y)
↝[ k ]
⟦ C₁ ⟧₂ R ((x₁ , f ⊚ inj₁) , (y₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ((x₂ , f ⊚ inj₂) , (y₂ , g ⊚ inj₂))
⟦⊗⟧₂↔ ext C₁ C₂ R (x@(x₁ , x₂) , f) (y@(y₁ , y₂) , g) =
⟦ C₁ ⊗ C₂ ⟧₂ R ((x , f) , (y , g)) ↔⟨⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position (C₁ ⊗ C₂) x o) →
R (f p , g (subst (λ s → Position (C₁ ⊗ C₂) s o) eq p))) ↔⟨⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₁ x₁ o ⊎ Position C₂ x₂ o) →
R ( f p
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
eq p)
)) ↔⟨ inverse (Σ-cong ≡×≡↔≡ λ _ → Bijection.id) ⟩
(∃ λ (eq : x₁ ≡ y₁ × x₂ ≡ y₂) →
∀ {o} (p : Position C₁ x₁ o ⊎ Position C₂ x₂ o) →
R ( f p
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ (proj₁ eq) (proj₂ eq)) p)
)) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
∀ {o} (p : Position C₁ x₁ o ⊎ Position C₂ x₂ o) →
R ( f p
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) p)
)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-∀-cong ext $ Π⊎↔Π×Π ext) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
∀ {o} →
((p : Position C₁ x₁ o) →
R ( f (inj₁ p)
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₁ p))
))
×
((p : Position C₂ x₂ o) →
R ( f (inj₂ p)
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₂ p))
))) ↝⟨ (∃-cong λ eq₁ → ∃-cong λ eq₂ → implicit-∀-cong ext $
(∀-cong ext λ _ → ≡⇒↝ _ $ cong (R ⊚ (f _ ,_)) $
lemma₁ eq₁ eq₂)
×-cong
(∀-cong ext λ _ → ≡⇒↝ _ $ cong (R ⊚ (f _ ,_)) $
lemma₂ eq₁ eq₂)) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
∀ {o} →
((p : Position C₁ x₁ o) →
R (f (inj₁ p) , g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p))))
×
((p : Position C₂ x₂ o) →
R (f (inj₂ p) , g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p))))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-ΠΣ-comm) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
(∀ {o} (p : Position C₁ x₁ o) →
R (f (inj₁ p) , g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p))))
×
(∀ {o} (p : Position C₂ x₂ o) →
R (f (inj₂ p) , g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p))))) ↔⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
(∀ {o} (p : Position C₁ x₁ o) →
R (f (inj₁ p) , g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p))))
×
∃ λ (eq₂ : x₂ ≡ y₂) →
(∀ {o} (p : Position C₂ x₂ o) →
R (f (inj₂ p) , g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p))))) ↔⟨ Σ-assoc ⟩
(∃ λ (eq : x₁ ≡ y₁) →
(∀ {o} (p : Container.Position C₁ x₁ o) →
R ( f (inj₁ p)
, g (inj₁ (subst (λ s₁ → Container.Position C₁ s₁ o) eq p)))
))
×
(∃ λ (eq : x₂ ≡ y₂) →
(∀ {o} (p : Container.Position C₂ x₂ o) →
R ( f (inj₂ p)
, g (inj₂ (subst (λ s₂ → Container.Position C₂ s₂ o) eq p))
))) ↔⟨⟩
⟦ C₁ ⟧₂ R ((x₁ , f ⊚ inj₁) , (y₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ((x₂ , f ⊚ inj₂) , (y₂ , g ⊚ inj₂)) □
where
open Container
lemma₁ = λ (eq₁ : x₁ ≡ y₁) (eq₂ : x₂ ≡ y₂) {o p} →
g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₁ p)) ≡⟨ cong g $ push-subst-inj₁ {y≡z = cong₂ _,_ eq₁ eq₂} _ _ ⟩
g (inj₁ (subst (λ { (s₁ , s₂) → Position C₁ s₁ o })
(cong₂ _,_ eq₁ eq₂) p)) ≡⟨ cong (g ⊚ inj₁) $ subst-∘ _ _ (cong₂ _,_ eq₁ eq₂) ⟩
g (inj₁ (subst (λ s₁ → Position C₁ s₁ o)
(cong proj₁ (cong₂ _,_ eq₁ eq₂)) p)) ≡⟨ cong (g ⊚ inj₁) $ cong (flip (subst _) _) $ cong-proj₁-cong₂-, eq₁ eq₂ ⟩∎
g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p)) ∎
lemma₂ = λ (eq₁ : x₁ ≡ y₁) (eq₂ : x₂ ≡ y₂) {o p} →
g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₂ p)) ≡⟨ cong g $ push-subst-inj₂ {y≡z = cong₂ _,_ eq₁ eq₂} _ _ ⟩
g (inj₂ (subst (λ { (s₁ , s₂) → Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) p)) ≡⟨ cong (g ⊚ inj₂) $ subst-∘ _ _ (cong₂ _,_ eq₁ eq₂) ⟩
g (inj₂ (subst (λ s₂ → Position C₂ s₂ o)
(cong proj₂ (cong₂ _,_ eq₁ eq₂)) p)) ≡⟨ cong (g ⊚ inj₂) $ cong (flip (subst _) _) $ cong-proj₂-cong₂-, eq₁ eq₂ ⟩∎
g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p)) ∎
-- The greatest fixpoint ν (C₁ ⊗ C₂) i is contained in the
-- intersection ν C₁ i ∩ ν C₂ i.
ν-⊗⊆ :
∀ {ℓ} {I : Type ℓ} {C₁ C₂ : Container I I} {i} →
ν (C₁ ⊗ C₂) i ⊆ ν C₁ i ∩ ν C₂ i
ν-⊗⊆ {C₁ = C₁} {C₂} {i} =
ν (C₁ ⊗ C₂) i ⊆⟨⟩
⟦ C₁ ⊗ C₂ ⟧ (ν′ (C₁ ⊗ C₂) i) ⊆⟨ ⟦⊗⟧↔ _ C₁ C₂ ⟩
⟦ C₁ ⟧ (ν′ (C₁ ⊗ C₂) i) ∩ ⟦ C₂ ⟧ (ν′ (C₁ ⊗ C₂) i) ⊆⟨ Σ-map (map C₁ ν-⊗⊆₁′) (map C₂ ν-⊗⊆₂′) ⟩
⟦ C₁ ⟧ (ν′ C₁ i) ∩ ⟦ C₂ ⟧ (ν′ C₂ i) ⊆⟨ P.id ⟩∎
ν C₁ i ∩ ν C₂ i ∎
where
ν-⊗⊆₁′ : ν′ (C₁ ⊗ C₂) i ⊆ ν′ C₁ i
force (ν-⊗⊆₁′ x) = proj₁ (ν-⊗⊆ (force x))
ν-⊗⊆₂′ : ν′ (C₁ ⊗ C₂) i ⊆ ν′ C₂ i
force (ν-⊗⊆₂′ x) = proj₂ (ν-⊗⊆ (force x))
-- A disjoint union combinator.
--
-- Similar to a construction in "Containers: Constructing strictly
-- positive types" by Abbott, Altenkirch and Ghani (see
-- Proposition 3.5).
infixr 2 _⊕_
_⊕_ : ∀ {ℓ} {I O : Type ℓ} →
Container I O → Container I O → Container I O
C₁ ⊕ C₂ =
(λ o → Shape C₁ o ⊎ Shape C₂ o)
◁
[ Position C₁ , Position C₂ ]
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊕ C₂ ⟧.
⟦⊕⟧↔ : ∀ {ℓ x} {I O : Type ℓ}
(C₁ C₂ : Container I O) {X : Rel x I} {o} →
⟦ C₁ ⊕ C₂ ⟧ X o ↔ ⟦ C₁ ⟧ X o ⊎ ⟦ C₂ ⟧ X o
⟦⊕⟧↔ C₁ C₂ {X} {o} =
⟦ C₁ ⊕ C₂ ⟧ X o ↔⟨⟩
(∃ λ (s : Shape C₁ o ⊎ Shape C₂ o) →
[ Position C₁ , Position C₂ ] s ⊆ X) ↝⟨ ∃-⊎-distrib-right ⟩
(∃ λ (s : Shape C₁ o) → Position C₁ s ⊆ X) ⊎
(∃ λ (s : Shape C₂ o) → Position C₂ s ⊆ X) ↔⟨⟩
⟦ C₁ ⟧ X o ⊎ ⟦ C₂ ⟧ X o □
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊕ C₂ ⟧₂.
⟦⊕⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} →
Extensionality? k ℓ ℓ →
∀ (C₁ C₂ : Container I I) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ C₁ ⊕ C₂ ⟧ X i) →
⟦ C₁ ⊕ C₂ ⟧₂ R (x , y)
↝[ k ]
(curry (⟦ C₁ ⟧₂ R) ⊎-rel curry (⟦ C₂ ⟧₂ R))
(_↔_.to (⟦⊕⟧↔ C₁ C₂) x)
(_↔_.to (⟦⊕⟧↔ C₁ C₂) y)
⟦⊕⟧₂↔ ext C₁ C₂ R (inj₁ x , f) (inj₁ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₁ x , f) , (inj₁ y , g)) ↔⟨⟩
(∃ λ (eq : inj₁ x ≡ inj₁ y) →
∀ {o} (p : Position C₁ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o) eq p)
)) ↔⟨ inverse $ Σ-cong Bijection.≡↔inj₁≡inj₁ (λ _ → Bijection.id) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₁ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o)
(cong inj₁ eq) p)
)) ↝⟨ (∃-cong λ eq → implicit-∀-cong ext $ ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ x → R (_ , g x)) $ sym $
subst-∘ _ _ eq) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₁ x o) →
R ( f p
, g (subst (λ s → Position C₁ s o) eq p)
)) ↔⟨⟩
⟦ C₁ ⟧₂ R ((x , f) , (y , g)) □
where
open Container
⟦⊕⟧₂↔ _ C₁ C₂ R (inj₁ x , f) (inj₂ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₁ x , f) , (inj₂ y , g)) ↔⟨⟩
(∃ λ (eq : inj₁ x ≡ inj₂ y) → _) ↔⟨ inverse $ Σ-cong (inverse Bijection.≡↔⊎) (λ _ → Bijection.id) ⟩
(∃ λ (eq : ⊥) → _) ↔⟨ Σ-left-zero ⟩
⊥ □
⟦⊕⟧₂↔ _ C₁ C₂ R (inj₂ x , f) (inj₁ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₂ x , f) , (inj₁ y , g)) ↔⟨⟩
(∃ λ (eq : inj₂ x ≡ inj₁ y) → _) ↔⟨ inverse $ Σ-cong (inverse Bijection.≡↔⊎) (λ _ → Bijection.id) ⟩
(∃ λ (eq : ⊥) → _) ↔⟨ Σ-left-zero ⟩
⊥ □
⟦⊕⟧₂↔ ext C₁ C₂ R (inj₂ x , f) (inj₂ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₂ x , f) , (inj₂ y , g)) ↔⟨⟩
(∃ λ (eq : inj₂ x ≡ inj₂ y) →
∀ {o} (p : Position C₂ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o) eq p)
)) ↔⟨ inverse $ Σ-cong Bijection.≡↔inj₂≡inj₂ (λ _ → Bijection.id) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₂ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o)
(cong inj₂ eq) p)
)) ↝⟨ (∃-cong λ eq → implicit-∀-cong ext $ ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ x → R (_ , g x)) $ sym $
subst-∘ _ _ eq) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₂ x o) →
R ( f p
, g (subst (λ s → Position C₂ s o) eq p)
)) ↔⟨⟩
⟦ C₂ ⟧₂ R ((x , f) , (y , g)) □
where
open Container
mutual
-- A combinator that is similar to the function ⟷ from
-- Section 6.3.4.1 in Pous and Sangiorgi's "Enhancements of the
-- bisimulation proof method".
⟷[_] : ∀ {ℓ} {I : Type ℓ} →
Container (I × I) (I × I) → Container (I × I) (I × I)
⟷[ C ] = C ⟷ C
-- A generalisation of ⟷[_].
infix 1 _⟷_
_⟷_ : ∀ {ℓ} {I : Type ℓ} →
(_ _ : Container (I × I) (I × I)) → Container (I × I) (I × I)
C₁ ⟷ C₂ = C₁ ⊗ reindex swap C₂
-- An unfolding lemma for ⟦ C₁ ⟷ C₂ ⟧.
⟦⟷⟧↔ :
∀ {k ℓ x} {I : Type ℓ} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C₁ C₂ : Container (I × I) (I × I)) {X : Rel₂ x I} {i} →
⟦ C₁ ⟷ C₂ ⟧ X i
↝[ k ]
⟦ C₁ ⟧ X i × (⟦ C₂ ⟧ (X ⁻¹) ⁻¹) i
⟦⟷⟧↔ ext C₁ C₂ {X} {i} =
⟦ C₁ ⟷ C₂ ⟧ X i ↔⟨⟩
⟦ C₁ ⊗ reindex swap C₂ ⟧ X i ↝⟨ ⟦⊗⟧↔ ext C₁ (reindex swap C₂) ⟩
⟦ C₁ ⟧ X i × ⟦ reindex swap C₂ ⟧ X i ↝⟨ ∃-cong (λ _ → ⟦reindex⟧↔ ext C₂) ⟩□
⟦ C₁ ⟧ X i × (⟦ C₂ ⟧ (X ⁻¹) ⁻¹) i □
-- An unfolding lemma for ⟦ C₁ ⟷ C₂ ⟧₂.
⟦⟷⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel₂ x I} →
Extensionality? k ℓ ℓ →
∀ (C₁ C₂ : Container (I × I) (I × I)) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ C₁ ⟷ C₂ ⟧ X i) →
let (s₁ , s₂) , f = x
(t₁ , t₂) , g = y
in
⟦ C₁ ⟷ C₂ ⟧₂ R (x , y)
↝[ k ]
⟦ C₁ ⟧₂ R ((s₁ , f ⊚ inj₁) , (t₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ( (s₂ , λ p → f (inj₂ (_ , refl , p)))
, (t₂ , λ p → g (inj₂ (_ , refl , p)))
)
⟦⟷⟧₂↔ ext C₁ C₂ R x@((s₁ , s₂) , f) y@((t₁ , t₂) , g) =
⟦ C₁ ⟷ C₂ ⟧₂ R (x , y) ↔⟨⟩
⟦ C₁ ⊗ reindex swap C₂ ⟧₂ R (x , y) ↝⟨ ⟦⊗⟧₂↔ ext C₁ (reindex swap C₂) R _ (_ , g) ⟩
⟦ C₁ ⟧₂ R ((s₁ , f ⊚ inj₁) , (t₁ , g ⊚ inj₁))
×
⟦ reindex swap C₂ ⟧₂ R ((s₂ , f ⊚ inj₂) , (t₂ , g ⊚ inj₂)) ↝⟨ ∃-cong (λ _ → ⟦reindex⟧₂↔ ext C₂ _ R _ (_ , g ⊚ inj₂)) ⟩□
⟦ C₁ ⟧₂ R ((s₁ , f ⊚ inj₁) , (t₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ( (s₂ , λ p → f (inj₂ (_ , refl , p)))
, (t₂ , λ p → g (inj₂ (_ , refl , p)))
) □
-- The greatest fixpoint ν (C₁ ⟷ C₂) i is contained in the
-- intersection ν C₁ i ∩ ν C₂ i ⁻¹.
ν-↔⊆ : ∀ {ℓ} {I : Type ℓ} {C₁ C₂ : Container (I × I) (I × I)} {i} →
ν (C₁ ⟷ C₂) i ⊆ ν C₁ i ∩ ν C₂ i ⁻¹
ν-↔⊆ {C₁ = C₁} {C₂} {i} =
ν (C₁ ⟷ C₂) i ⊆⟨⟩
ν (C₁ ⊗ reindex swap C₂) i ⊆⟨ ν-⊗⊆ ⟩
ν C₁ i ∩ ν (reindex swap C₂) i ⊆⟨ Σ-map P.id (_⇔_.to (ν-reindex⇔ refl)) ⟩∎
ν C₁ i ∩ ν C₂ i ⁻¹ ∎
-- The following three lemmas correspond to the second part of
-- Exercise 6.3.24 in Pous and Sangiorgi's "Enhancements of the
-- bisimulation proof method".
-- Post-fixpoints of the container reindex₂ swap id ⊗ C are
-- post-fixpoints of ⟷[ C ].
⊆reindex₂-swap-⊗→⊆⟷ :
∀ {ℓ r} {I : Type ℓ} {C : Container (I × I) (I × I)} {R : Rel₂ r I} →
R ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ R → R ⊆ ⟦ ⟷[ C ] ⟧ R
⊆reindex₂-swap-⊗→⊆⟷ {C = C} {R} R⊆ =
R ⊆⟨ (λ x → lemma₁ x , lemma₂ x) ⟩
⟦ C ⟧ R ∩ R ⁻¹ ⊆⟨ Σ-map P.id lemma₃ ⟩
⟦ C ⟧ R ∩ ⟦ C ⟧ (R ⁻¹) ⁻¹ ⊆⟨ _⇔_.from (⟦⟷⟧↔ _ C C) ⟩∎
⟦ ⟷[ C ] ⟧ R ∎
where
lemma₀ =
R ⊆⟨ R⊆ ⟩
⟦ reindex₂ swap id ⊗ C ⟧ R ⊆⟨ ⟦⊗⟧↔ _ (reindex₂ swap id) C ⟩∎
⟦ reindex₂ swap id ⟧ R ∩ ⟦ C ⟧ R ∎
lemma₁ =
R ⊆⟨ lemma₀ ⟩
⟦ reindex₂ swap id ⟧ R ∩ ⟦ C ⟧ R ⊆⟨ proj₂ ⟩∎
⟦ C ⟧ R ∎
lemma₂ =
R ⊆⟨ lemma₀ ⟩
⟦ reindex₂ swap id ⟧ R ∩ ⟦ C ⟧ R ⊆⟨ proj₁ ⟩
⟦ reindex₂ swap id ⟧ R ⊆⟨ P.id ⟩
⟦ id ⟧ R ⁻¹ ⊆⟨ _⇔_.to (⟦id⟧↔ _) ⟩∎
R ⁻¹ ∎
lemma₃ =
R ⊆⟨ lemma₁ ⟩
⟦ C ⟧ R ⊆⟨ map C lemma₂ ⟩∎
⟦ C ⟧ (R ⁻¹) ∎
-- The symmetric closure of a post-fixpoint of ⟷[ C ] is a
-- post-fixpoint of reindex₂ swap id ⊗ C.
⊆⟷→∪-swap⊆reindex₂-swap-⊗ :
∀ {ℓ r} {I : Type ℓ} {C : Container (I × I) (I × I)} {R : Rel₂ r I} →
R ⊆ ⟦ ⟷[ C ] ⟧ R →
R ∪ R ⁻¹ ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ (R ∪ R ⁻¹)
⊆⟷→∪-swap⊆reindex₂-swap-⊗ {C = C} {R} R⊆ =
R ∪ R ⁻¹ ⊆⟨ (λ x → lemma₁ x , lemma₂ x) ⟩
⟦ reindex₂ swap id ⟧ (R ∪ R ⁻¹) ∩ ⟦ C ⟧ (R ∪ R ⁻¹) ⊆⟨ _⇔_.from (⟦⊗⟧↔ _ (reindex₂ swap id) C) ⟩∎
⟦ reindex₂ swap id ⊗ C ⟧ (R ∪ R ⁻¹) ∎
where
lemma₁ =
R ∪ R ⁻¹ ⊆⟨ [ inj₂ , inj₁ ] ⟩
R ⁻¹ ∪ R ⊆⟨ P.id ⟩
R ⁻¹ ∪ R ⁻¹ ⁻¹ ⊆⟨ P.id ⟩
(R ∪ R ⁻¹) ⁻¹ ⊆⟨ _⇔_.from (⟦id⟧↔ _) ⟩
⟦ id ⟧ (R ∪ R ⁻¹) ⁻¹ ⊆⟨ P.id ⟩∎
⟦ reindex₂ swap id ⟧ (R ∪ R ⁻¹) ∎
lemma₂ =
R ∪ R ⁻¹ ⊆⟨ ⊎-map R⊆ R⊆ ⟩
⟦ ⟷[ C ] ⟧ R ∪ ⟦ ⟷[ C ] ⟧ R ⁻¹ ⊆⟨ ⊎-map (_⇔_.to (⟦⟷⟧↔ _ C C)) (_⇔_.to (⟦⟷⟧↔ _ C C)) ⟩
⟦ C ⟧ R ∩ ⟦ C ⟧ (R ⁻¹) ⁻¹ ∪ ⟦ C ⟧ R ⁻¹ ∩ ⟦ C ⟧ (R ⁻¹) ⊆⟨ ⊎-map proj₁ proj₂ ⟩
⟦ C ⟧ R ∪ ⟦ C ⟧ (R ⁻¹) ⊆⟨ [ map C inj₁ , map C inj₂ ] ⟩∎
⟦ C ⟧ (R ∪ R ⁻¹) ∎
-- The greatest fixpoint of ⟷[ C ] is pointwise logically equivalent
-- to the greatest fixpoint of reindex₂ swap id ⊗ C.
--
-- Note that this proof is not necessarily size-preserving. TODO:
-- Figure out if the proof can be made size-preserving.
ν-⟷⇔ :
∀ {ℓ} {I : Type ℓ} {C : Container (I × I) (I × I)} {p} →
ν ⟷[ C ] ∞ p ⇔ ν (reindex₂ swap id ⊗ C) ∞ p
ν-⟷⇔ {C = C} = record
{ to =
let R = ν ⟷[ C ] ∞ in $⟨ (λ {_} → ν-out _) ⟩
R ⊆ ⟦ ⟷[ C ] ⟧ R ↝⟨ ⊆⟷→∪-swap⊆reindex₂-swap-⊗ ⟩
R ∪ R ⁻¹ ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ (R ∪ R ⁻¹) ↝⟨ unfold _ ⟩
R ∪ R ⁻¹ ⊆ ν (reindex₂ swap id ⊗ C) ∞ ↝⟨ (λ hyp {_} x → hyp (inj₁ x)) ⟩□
R ⊆ ν (reindex₂ swap id ⊗ C) ∞ □
; from =
let R = ν (reindex₂ swap id ⊗ C) ∞ in $⟨ (λ {_} → ν-out _) ⟩
R ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ R ↝⟨ ⊆reindex₂-swap-⊗→⊆⟷ ⟩
R ⊆ ⟦ ⟷[ C ] ⟧ R ↝⟨ unfold _ ⟩□
R ⊆ ν ⟷[ C ] ∞ □
}
| 37.381423
| 148
| 0.365741
|
c7bb4b6f07d71ba1311d519f8375b5b1b183c435
| 2,152
|
agda
|
Agda
|
agda/Number/Prelude/Int.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
agda/Number/Prelude/Int.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
agda/Number/Prelude/Int.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
module Number.Prelude.Int where
open import Cubical.Data.Int public using
( Int
; fromNatInt
; fromNegInt
; sucInt
; predInt
; sucInt+
; predInt+
; _+pos_
; _+negsuc_
) renaming
( isSetInt to isSetℤ
; _-_ to infix 7 _-ᶻ_
; _+_ to infix 5 _+ᶻ_
; pos to posᶻ
; negsuc to negsucᶻ
)
open import Number.Instances.Int public using
( +negsuc-identityˡ
; negsuc+negsuc≡+ⁿ
; sneg
; spos
) renaming
( _·_ to _·ᶻ_
; -_ to -ᶻ_
; _<_ to _<ᶻ_
; min to minᶻ
; max to maxᶻ
; is-min to is-minᶻ
; is-max to is-maxᶻ
; ·-reflects-< to ·ᶻ-reflects-<ᶻ
; is-LinearlyOrderedCommRing to is-LinearlyOrderedCommRingᶻ
)
-- Int≅Builtin
-- Int≡Builtin
-- Sign
-- spos
-- sneg
-- _·ˢ_
-- sign
-- signed
-- -_
-- -involutive
-- _·_
-- _·'_
-- _·''_
-- ·''-nullifiesʳ
-- _<_
-- min
-- max
-- <-irrefl
-- <-trans
-- <-asym
-- <-cotrans
-- +-identityʳ
-- +-identityˡ
-- -1·≡-
-- negsuc≡-pos
-- negsuc-reflects-≡
-- pos-reflects-≡
-- possuc+negsuc≡0
-- sucInt[negsuc+pos]≡0
-- +-inverseʳ
-- +-inverseˡ
-- +-inverse
-- pos+pos≡+ⁿ
-- negsuc+negsuc≡+ⁿ
-- +negsuc-identityˡ
-- pos+negsuc≡⊎
-- negsuc+pos≡⊎
-- pos+negsuc≡negsuc+pos
-- predInt-
-- pos+negsuc-swap
-- negsuc+pos-swap
-- +negsuc-assoc
-- sucInt[negsuc+pos]≡pos
-- +pos-inverse
-- +pos-assoc
-- Trichotomy
-- _≟_
-- MinTrichtotomy
-- MaxTrichtotomy
-- min-trichotomy
-- max-trichotomy
-- is-min
-- is-max
-- sucInt-reflects-<
-- predInt-reflects-<
-- sucInt-preserves-<
-- predInt-preserves-<
-- +-preserves-<
-- +-reflects-<
-- +-reflects-<ˡ
-- +-<-ext
-- ·≡·'
-- ·'-nullifiesʳ
-- ·'-nullifiesˡ
-- -distrˡ
-- ·-comm
-- -distrʳ
-- ·'-assoc
-- ·'-assoc≡
-- ·-assoc
-- ·-nullifiesˡ
-- ·-nullifiesʳ
-- ·-identityˡ
-- ·-identityʳ
-- ·-preserves-<
-- ·-reflects-<
-- ·-sucInt
-- ·-sucIntˡ
-- ·-predInt
-- ·-predIntˡ
-- -distrib
-- ·-distribˡ
-- ·-distribʳ
-- ·-Semigroup .IsSemigroup.is-assoc
-- +-Monoid .IsMonoid.is-identity
-- ·-Monoid .IsMonoid.is-identity
-- is-Semiring .IsSemiring.is-dist
-- <-StrictLinearOrder .IsStrictLinearOrder.is-tricho
| 16.8125
| 61
| 0.589684
|
581ce4a3dbdef65768b5ae81a1de780ee21768a3
| 2,546
|
agda
|
Agda
|
Cubical/HITs/FiniteMultiset/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/FiniteMultiset/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/FiniteMultiset/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.FiniteMultiset.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.HITs.FiniteMultiset.Base
private
variable
A : Type₀
infixr 30 _++_
_++_ : ∀ (xs ys : FMSet A) → FMSet A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ xs ++ ys
comm x y xs i ++ ys = comm x y (xs ++ ys) i
trunc xs zs p q i j ++ ys =
trunc (xs ++ ys) (zs ++ ys) (cong (_++ ys) p) (cong (_++ ys) q) i j
unitl-++ : ∀ (xs : FMSet A) → [] ++ xs ≡ xs
unitl-++ xs = refl
unitr-++ : ∀ (xs : FMSet A) → xs ++ [] ≡ xs
unitr-++ = ElimProp.f (trunc _ _)
refl
(λ x p → cong (_∷_ x) p)
assoc-++ : ∀ (xs ys zs : FMSet A) → xs ++ (ys ++ zs) ≡ (xs ++ ys) ++ zs
assoc-++ = ElimProp.f (isPropPi (λ _ → isPropPi (λ _ → trunc _ _)))
(λ ys zs → refl)
(λ x p ys zs → cong (_∷_ x) (p ys zs))
cons-++ : ∀ (x : A) (xs : FMSet A) → x ∷ xs ≡ xs ++ [ x ]
cons-++ x = ElimProp.f (trunc _ _)
refl
(λ y {xs} p → comm x y xs ∙ cong (_∷_ y) p)
comm-++ : ∀ (xs ys : FMSet A) → xs ++ ys ≡ ys ++ xs
comm-++ = ElimProp.f (isPropPi (λ _ → trunc _ _))
(λ ys → sym (unitr-++ ys))
(λ x {xs} p ys → cong (x ∷_) (p ys)
∙ cong (_++ xs) (cons-++ x ys)
∙ sym (assoc-++ ys [ x ] xs))
module FMSetUniversal {ℓ} {M : Type ℓ} (MSet : isSet M)
(e : M) (_⊗_ : M → M → M)
(comm-⊗ : ∀ x y → x ⊗ y ≡ y ⊗ x) (assoc-⊗ : ∀ x y z → x ⊗ (y ⊗ z) ≡ (x ⊗ y) ⊗ z)
(unit-⊗ : ∀ x → e ⊗ x ≡ x)
(f : A → M) where
f-extend : FMSet A → M
f-extend = Rec.f MSet e (λ x m → f x ⊗ m)
(λ x y m → comm-⊗ (f x) (f y ⊗ m) ∙ sym (assoc-⊗ (f y) m (f x)) ∙ cong (f y ⊗_) (comm-⊗ m (f x)))
f-extend-nil : f-extend [] ≡ e
f-extend-nil = refl
f-extend-cons : ∀ x xs → f-extend (x ∷ xs) ≡ f x ⊗ f-extend xs
f-extend-cons x xs = refl
f-extend-sing : ∀ x → f-extend [ x ] ≡ f x
f-extend-sing x = comm-⊗ (f x) e ∙ unit-⊗ (f x)
f-extend-++ : ∀ xs ys → f-extend (xs ++ ys) ≡ f-extend xs ⊗ f-extend ys
f-extend-++ = ElimProp.f (isPropPi λ _ → MSet _ _)
(λ ys → sym (unit-⊗ (f-extend ys)))
(λ x {xs} p ys → cong (f x ⊗_) (p ys) ∙ assoc-⊗ (f x) (f-extend xs) (f-extend ys))
module _ (h : FMSet A → M) (h-nil : h [] ≡ e) (h-sing : ∀ x → h [ x ] ≡ f x)
(h-++ : ∀ xs ys → h (xs ++ ys) ≡ h xs ⊗ h ys) where
f-extend-unique : h ≡ f-extend
f-extend-unique = funExt (ElimProp.f (MSet _ _)
h-nil
(λ x {xs} p → (h-++ [ x ] xs) ∙ cong (_⊗ h xs) (h-sing x) ∙ cong (f x ⊗_) p))
| 32.641026
| 107
| 0.480754
|
2f76432533f2092d06cd6b1aabc997e7afe7f086
| 554
|
agda
|
Agda
|
agda-stdlib/src/Data/Product/Relation/Lex/Strict.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Product/Relation/Lex/Strict.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Product/Relation/Lex/Strict.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
-- Data.Product.Relation.Binary.Lex.Strict directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Product.Relation.Lex.Strict where
open import Data.Product.Relation.Binary.Lex.Strict public
{-# WARNING_ON_IMPORT
"Data.Product.Relation.Lex.Strict was deprecated in v1.0.
Use Data.Product.Relation.Binary.Lex.Strict instead."
#-}
| 30.777778
| 72
| 0.559567
|
29f8cd23911db7cc8a26eeb8ac4916657e32c114
| 431
|
agda
|
Agda
|
src/Bools.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | 1
|
2020-04-15T15:28:03.000Z
|
2020-04-15T15:28:03.000Z
|
src/Bools.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | null | null | null |
src/Bools.agda
|
ice1k/Theorems
|
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
|
[
"Apache-2.0"
] | null | null | null |
module Bools where
open import Agda.Builtin.Bool public
renaming (Bool to 𝔹)
not : 𝔹 → 𝔹
not true = false
not false = true
-- T : 𝔹 → Set
-- T true = ⊤
-- T false = ⊥
if_then_else_ : ∀ {a} {A : Set a} → 𝔹 → A → A → A
if true then t else _ = t
if false then _ else f = f
_∧_ : 𝔹 → 𝔹 → 𝔹
true ∧ b = b
false ∧ _ = false
_∨_ : 𝔹 → 𝔹 → 𝔹
true ∨ _ = true
false ∨ b = b
_xor_ : 𝔹 → 𝔹 → 𝔹
true xor b = not b
false xor b = b
| 14.862069
| 49
| 0.552204
|
313fae0824ff8880d2d3733d5c9daa82d1a69595
| 171
|
agda
|
Agda
|
test/Fail/Issue3014.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue3014.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue3014.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
data Bool : Set where
true false : Bool
data Eq : Bool → Bool → Set where
refl : (x : Bool) → Eq x x
test : (x : Bool) → Eq true x → Set
test _ (refl false) = Bool
| 17.1
| 35
| 0.590643
|
41d86875d0acd80add3775408ad3929a8a751a2f
| 228
|
agda
|
Agda
|
Agda/Ag06.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | 2
|
2020-02-03T05:05:52.000Z
|
2020-03-11T10:35:42.000Z
|
Agda/Ag06.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | null | null | null |
Agda/Ag06.agda
|
Brethland/LEARNING-STUFF
|
eb2cef0556efb9a4ce11783f8516789ea48cc344
|
[
"MIT"
] | 1
|
2019-12-13T04:50:46.000Z
|
2019-12-13T04:50:46.000Z
|
module Ag06 where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; cong-app)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Properties using (+-comm)
| 22.8
| 50
| 0.75
|
22a0d1ac60da546333797c507869243bfa2e7c24
| 247
|
agda
|
Agda
|
test/Succeed/Issue1885.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1885.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1885.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# NO_POSITIVITY_CHECK #-}
data D : Set
data D where
d : (D → D) → D
data E : Set
{-# NO_POSITIVITY_CHECK #-}
data E where
e : (E → E) → E
{-# NO_POSITIVITY_CHECK #-}
data F : Set
{-# NO_POSITIVITY_CHECK #-}
data F where
e : (F → F) → F
| 14.529412
| 27
| 0.574899
|
2fcfa3f6ed97b0f21b28f47d89fa793270e01fdc
| 2,278
|
agda
|
Agda
|
Data/Collection/Equivalence.agda
|
banacorn/lambda-calculus
|
f81b116473582ab7956adc4bf1d7ebf1ae2a213a
|
[
"MIT"
] | null | null | null |
Data/Collection/Equivalence.agda
|
banacorn/lambda-calculus
|
f81b116473582ab7956adc4bf1d7ebf1ae2a213a
|
[
"MIT"
] | null | null | null |
Data/Collection/Equivalence.agda
|
banacorn/lambda-calculus
|
f81b116473582ab7956adc4bf1d7ebf1ae2a213a
|
[
"MIT"
] | null | null | null |
module Data.Collection.Equivalence where
open import Data.Collection.Core
open import Function using (id; _∘_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; equivalence)
open Function.Equivalence.Equivalence
open import Relation.Binary.PropositionalEquality
open import Level using (zero)
open import Relation.Nullary
open import Relation.Unary
open import Relation.Binary
nach : ∀ {f t} {A : Set f} {B : Set t} → (A ⇔ B) → A → B
nach = _⟨$⟩_ ∘ to
von : ∀ {f t} {A : Set f} {B : Set t} → (A ⇔ B) → B → A
von = _⟨$⟩_ ∘ from
infixr 5 _≋_
_≋_ : Rel Membership _
A ≋ B = {x : Element} → x ∈ A ⇔ x ∈ B
≋-Reflexive : Reflexive _≋_
≋-Reflexive = equivalence id id
≋-Symmetric : Symmetric _≋_
≋-Symmetric z = record
{ to = from z
; from = to z
}
≋-Transitive : Transitive _≋_
≋-Transitive P≋Q Q≋R = equivalence (nach Q≋R ∘ nach P≋Q) (von P≋Q ∘ von Q≋R)
≋-IsEquivalence : IsEquivalence _≋_
≋-IsEquivalence = record
{ refl = equivalence id id
; sym = ≋-Symmetric
; trans = ≋-Transitive
}
≋-Setoid : Setoid _ _
≋-Setoid = record
{ Carrier = Pred Element zero
; _≈_ = _≋_
; isEquivalence = ≋-IsEquivalence
}
--------------------------------------------------------------------------------
-- Conditional Equivalence
--------------------------------------------------------------------------------
_≋[_]_ : ∀ {a} → Membership → Pred Element a → Membership → Set a
A ≋[ P ] B = {x : Element} → P x → x ∈ A ⇔ x ∈ B
-- prefix version of _≋[_]_, with the predicate being the first argument
[_]≋ : ∀ {a} → Pred Element a → Membership → Membership → Set a
[_]≋ P A B = A ≋[ P ] B
≋[]-Reflexive : ∀ {a} {P : Pred Element a} → Reflexive [ P ]≋
≋[]-Reflexive A = equivalence id id
≋[]-Symmetric : ∀ {a} {P : Pred Element a} → Symmetric [ P ]≋
≋[]-Symmetric z ∈P = record
{ to = from (z ∈P)
; from = to (z ∈P)
}
≋[]-Transitive : ∀ {a} {P : Pred Element a} → Transitive [ P ]≋
≋[]-Transitive P≋Q Q≋R ∈P = equivalence (nach (Q≋R ∈P) ∘ nach (P≋Q ∈P)) (von (P≋Q ∈P) ∘ von (Q≋R ∈P))
≋[]-IsEquivalence : ∀ {a} {P : Pred Element a} → IsEquivalence [ P ]≋
≋[]-IsEquivalence {p} = record
{ refl = λ _ → equivalence id id
; sym = ≋[]-Symmetric
; trans = ≋[]-Transitive
}
| 26.8
| 101
| 0.559263
|
2263615d77ac4aac7066eb596bcd4691a43e1845
| 15,737
|
agda
|
Agda
|
prototyping/Luau/Syntax/FromJSON.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2021-11-06T08:03:00.000Z
|
2021-11-06T08:03:00.000Z
|
prototyping/Luau/Syntax/FromJSON.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/Luau/Syntax/FromJSON.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module Luau.Syntax.FromJSON where
open import Luau.Syntax using (Block; Stat ; Expr; _$_; val; nil; bool; number; var; var_∈_; function_is_end; _⟨_⟩; _⟨_⟩∈_; local_←_; return; done; _∙_; maybe; VarDec; binexp; BinaryOperator; +; -; *; /; ==; ~=; <; >; <=; >=; ··; string)
open import Luau.Type.FromJSON using (typeFromJSON)
open import Agda.Builtin.List using (List; _∷_; [])
open import Agda.Builtin.Bool using (true; false)
open import FFI.Data.Aeson using (Value; Array; Object; object; array; string; fromString; lookup)
open import FFI.Data.Either using (Either; Left; Right)
open import FFI.Data.Maybe using (Maybe; nothing; just)
open import FFI.Data.Scientific using (toFloat)
open import FFI.Data.String using (String; _++_)
open import FFI.Data.Vector using (head; tail; null; empty)
args = fromString "args"
body = fromString "body"
func = fromString "func"
lokal = fromString "local"
list = fromString "list"
name = fromString "name"
type = fromString "type"
value = fromString "value"
values = fromString "values"
vars = fromString "vars"
op = fromString "op"
left = fromString "left"
right = fromString "right"
returnAnnotation = fromString "returnAnnotation"
types = fromString "types"
data Lookup : Set where
_,_ : String → Value → Lookup
nil : Lookup
lookupIn : List String → Object → Lookup
lookupIn [] obj = nil
lookupIn (key ∷ keys) obj with lookup (fromString key) obj
lookupIn (key ∷ keys) obj | nothing = lookupIn keys obj
lookupIn (key ∷ keys) obj | just value = (key , value)
binOpFromJSON : Value → Either String BinaryOperator
binOpFromString : String → Either String BinaryOperator
varDecFromJSON : Value → Either String (VarDec maybe)
varDecFromObject : Object → Either String (VarDec maybe)
exprFromJSON : Value → Either String (Expr maybe)
exprFromObject : Object → Either String (Expr maybe)
statFromJSON : Value → Either String (Stat maybe)
statFromObject : Object → Either String (Stat maybe)
blockFromJSON : Value → Either String (Block maybe)
blockFromArray : Array → Either String (Block maybe)
binOpFromJSON (string s) = binOpFromString s
binOpFromJSON _ = Left "Binary operator not a string"
binOpFromString "Add" = Right +
binOpFromString "Sub" = Right -
binOpFromString "Mul" = Right *
binOpFromString "Div" = Right /
binOpFromString "CompareEq" = Right ==
binOpFromString "CompareNe" = Right ~=
binOpFromString "CompareLt" = Right <
binOpFromString "CompareLe" = Right <=
binOpFromString "CompareGt" = Right >
binOpFromString "CompareGe" = Right >=
binOpFromString "Concat" = Right ··
binOpFromString s = Left ("'" ++ s ++ "' is not a valid operator")
varDecFromJSON (object arg) = varDecFromObject arg
varDecFromJSON _ = Left "VarDec not an object"
varDecFromObject obj with lookup name obj | lookup type obj
varDecFromObject obj | just (string name) | nothing = Right (var name)
varDecFromObject obj | just (string name) | just Value.null = Right (var name)
varDecFromObject obj | just (string name) | just tyValue with typeFromJSON tyValue
varDecFromObject obj | just (string name) | just tyValue | Right ty = Right (var name ∈ ty)
varDecFromObject obj | just (string name) | just tyValue | Left err = Left err
varDecFromObject obj | just _ | _ = Left "AstLocal name is not a string"
varDecFromObject obj | nothing | _ = Left "AstLocal missing name"
exprFromJSON (object obj) = exprFromObject obj
exprFromJSON _ = Left "AstExpr not an object"
exprFromObject obj with lookup type obj
exprFromObject obj | just (string "AstExprCall") with lookup func obj | lookup args obj
exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) with head arr
exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 with exprFromJSON value | exprFromJSON value2
exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 | Right fun | Right arg = Right (fun $ arg)
exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 | Left err | _ = Left err
exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | just value2 | _ | Left err = Left err
exprFromObject obj | just (string "AstExprCall") | just value | just (array arr) | nothing = Left ("AstExprCall empty args")
exprFromObject obj | just (string "AstExprCall") | just value | just _ = Left ("AstExprCall args not an array")
exprFromObject obj | just (string "AstExprCall") | nothing | _ = Left ("AstExprCall missing func")
exprFromObject obj | just (string "AstExprCall") | _ | nothing = Left ("AstExprCall missing args")
exprFromObject obj | just (string "AstExprConstantNil") = Right (val nil)
exprFromObject obj | just (string "AstExprFunction") with lookup args obj | lookup body obj | lookup returnAnnotation obj
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | rtn with head arr | blockFromJSON blockValue
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | rtn | just argValue | Right B with varDecFromJSON argValue
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg with lookup types rtnObj
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg | just (array rtnTypes) with head rtnTypes
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg | just (array rtnTypes) | just rtnType with typeFromJSON rtnType
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg | just (array rtnTypes) | just rtnType | Left err = Left err
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg | just (array rtnTypes) | just rtnType | Right T = Right (function "" ⟨ arg ⟩∈ T is B end)
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg | just (array rtnTypes) | nothing = Right (function "" ⟨ arg ⟩ is B end)
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg | just _ = Left "returnAnnotation types not an array"
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just (object rtnObj) | just argValue | Right B | Right arg | nothing = Left "returnAnnotation missing types"
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | just _ | just argValue | Right B | Right arg = Left "returnAnnotation not an object"
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | nothing | just argValue | Right B | Right arg = Right (function "" ⟨ arg ⟩ is B end)
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | rtn | just argValue | Right B | Left err = Left err
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | rtn | nothing | Right B = Left "Unsupported AstExprFunction empty args"
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just blockValue | rtn | _ | Left err = Left err
exprFromObject obj | just (string "AstExprFunction") | just _ | just _ | rtn = Left "AstExprFunction args not an array"
exprFromObject obj | just (string "AstExprFunction") | nothing | _ | rtn = Left "AstExprFunction missing args"
exprFromObject obj | just (string "AstExprFunction") | _ | nothing | rtn = Left "AstExprFunction missing body"
exprFromObject obj | just (string "AstExprLocal") with lookup lokal obj
exprFromObject obj | just (string "AstExprLocal") | just x with varDecFromJSON x
exprFromObject obj | just (string "AstExprLocal") | just x | Right x′ = Right (var (Luau.Syntax.name x′))
exprFromObject obj | just (string "AstExprLocal") | just x | Left err = Left err
exprFromObject obj | just (string "AstExprLocal") | nothing = Left "AstExprLocal missing local"
exprFromObject obj | just (string "AstExprConstantNumber") with lookup value obj
exprFromObject obj | just (string "AstExprConstantNumber") | just (FFI.Data.Aeson.Value.number x) = Right (val (number (toFloat x)))
exprFromObject obj | just (string "AstExprConstantNumber") | just _ = Left "AstExprConstantNumber value is not a number"
exprFromObject obj | just (string "AstExprConstantNumber") | nothing = Left "AstExprConstantNumber missing value"
exprFromObject obj | just (string "AstExprConstantString") with lookup value obj
exprFromObject obj | just (string "AstExprConstantString") | just (string x) = Right (val (string x))
exprFromObject obj | just (string "AstExprConstantString") | just _ = Left "AstExprConstantString value is not a string"
exprFromObject obj | just (string "AstExprConstantString") | nothing = Left "AstExprConstantString missing value"
exprFromObject obj | just (string "AstExprConstantBool") with lookup value obj
exprFromObject obj | just (string "AstExprConstantBool") | just (FFI.Data.Aeson.Value.bool b) = Right (val (bool b))
exprFromObject obj | just (string "AstExprConstantBool") | just _ = Left "AstExprConstantBool value is not a bool"
exprFromObject obj | just (string "AstExprConstantBool") | nothing = Left "AstExprConstantBool missing value"
exprFromObject obj | just (string "AstExprBinary") with lookup op obj | lookup left obj | lookup right obj
exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r with binOpFromJSON o | exprFromJSON l | exprFromJSON r
exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | Right o′ | Right l′ | Right r′ = Right (binexp l′ o′ r′)
exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | Left err | _ | _ = Left err
exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | _ | Left err | _ = Left err
exprFromObject obj | just (string "AstExprBinary") | just o | just l | just r | _ | _ | Left err = Left err
exprFromObject obj | just (string "AstExprBinary") | nothing | _ | _ = Left "Missing 'op' in AstExprBinary"
exprFromObject obj | just (string "AstExprBinary") | _ | nothing | _ = Left "Missing 'left' in AstExprBinary"
exprFromObject obj | just (string "AstExprBinary") | _ | _ | nothing = Left "Missing 'right' in AstExprBinary"
exprFromObject obj | just (string ty) = Left ("TODO: Unsupported AstExpr " ++ ty)
exprFromObject obj | just _ = Left "AstExpr type not a string"
exprFromObject obj | nothing = Left "AstExpr missing type"
{-# NON_TERMINATING #-}
statFromJSON (object obj) = statFromObject obj
statFromJSON _ = Left "AstStat not an object"
statFromObject obj with lookup type obj
statFromObject obj | just(string "AstStatLocal") with lookup vars obj | lookup values obj
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) with head(arr1) | head(arr2)
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) with varDecFromJSON(x) | exprFromJSON(value)
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) | Right x′ | Right M = Right (local x′ ← M)
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) | Left err | _ = Left err
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | just(value) | _ | Left err = Left err
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(x) | nothing = Left "AstStatLocal empty values"
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | nothing | _ = Left "AstStatLocal empty vars"
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(_) = Left "AstStatLocal values not an array"
statFromObject obj | just(string "AstStatLocal") | just(_) | just(_) = Left "AstStatLocal vars not an array"
statFromObject obj | just(string "AstStatLocal") | just(_) | nothing = Left "AstStatLocal missing values"
statFromObject obj | just(string "AstStatLocal") | nothing | _ = Left "AstStatLocal missing vars"
statFromObject obj | just(string "AstStatLocalFunction") with lookup name obj | lookup func obj
statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value with varDecFromJSON fnName | exprFromJSON value
statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value | Right fnVar | Right (function "" ⟨ x ⟩ is B end) = Right (function (Luau.Syntax.name fnVar) ⟨ x ⟩ is B end)
statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value | Right fnVar | Right (function "" ⟨ x ⟩∈ T is B end) = Right (function (Luau.Syntax.name fnVar) ⟨ x ⟩∈ T is B end)
statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value | Left err | _ = Left err
statFromObject obj | just(string "AstStatLocalFunction") | just fnName | just value | _ | Left err = Left err
statFromObject obj | just(string "AstStatLocalFunction") | just _ | just _ | Right _ | Right _ = Left "AstStatLocalFunction func is not an AstExprFunction"
statFromObject obj | just(string "AstStatLocalFunction") | nothing | _ = Left "AstStatFunction missing name"
statFromObject obj | just(string "AstStatLocalFunction") | _ | nothing = Left "AstStatFunction missing func"
statFromObject obj | just(string "AstStatReturn") with lookup list obj
statFromObject obj | just(string "AstStatReturn") | just(array arr) with head arr
statFromObject obj | just(string "AstStatReturn") | just(array arr) | just value with exprFromJSON value
statFromObject obj | just(string "AstStatReturn") | just(array arr) | just value | Right M = Right (return M)
statFromObject obj | just(string "AstStatReturn") | just(array arr) | just value | Left err = Left err
statFromObject obj | just(string "AstStatReturn") | just(array arr) | nothing = Left "AstStatReturn empty list"
statFromObject obj | just(string "AstStatReturn") | just(_) = Left "AstStatReturn list not an array"
statFromObject obj | just(string "AstStatReturn") | nothing = Left "AstStatReturn missing list"
statFromObject obj | just (string ty) = Left ("TODO: Unsupported AstStat " ++ ty)
statFromObject obj | just _ = Left "AstStat type not a string"
statFromObject obj | nothing = Left "AstStat missing type"
blockFromJSON (array arr) = blockFromArray arr
blockFromJSON (object obj) with lookup type obj | lookup body obj
blockFromJSON (object obj) | just (string "AstStatBlock") | just value = blockFromJSON value
blockFromJSON (object obj) | just (string "AstStatBlock") | nothing = Left "AstStatBlock missing body"
blockFromJSON (object obj) | just (string ty) | _ = Left ("Unsupported AstBlock " ++ ty)
blockFromJSON (object obj) | just _ | _ = Left "AstStatBlock type not a string"
blockFromJSON (object obj) | nothing | _ = Left "AstStatBlock missing type"
blockFromJSON _ = Left "AstBlock not an array or AstStatBlock object"
blockFromArray arr with head arr
blockFromArray arr | nothing = Right done
blockFromArray arr | just value with statFromJSON value
blockFromArray arr | just value | Left err = Left err
blockFromArray arr | just value | Right S with blockFromArray(tail arr)
blockFromArray arr | just value | Right S | Left err = Left (err)
blockFromArray arr | just value | Right S | Right B = Right (S ∙ B)
| 77.905941
| 241
| 0.737434
|
582f1c0e39a01ddaf2ce3c66e514b82945826eae
| 446
|
agda
|
Agda
|
test/Compiler/simple/Issue2123.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/Issue2123.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/simple/Issue2123.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
open import Agda.Builtin.Nat
open import Agda.Builtin.String
open import Common.IO
open import Common.Unit
data ⊥ : Set where
record Pair : Set where
constructor _,_
field fst snd : String
open Pair
record ERing : Set where
constructor ering
field divRem : (⊥ → ⊥) → Pair
open ERing
eRing : ERing
eRing = ering λ _ → "fst" , "snd"
test : String
test = snd (divRem eRing (λ ()))
main : IO Unit
main = putStrLn test
| 14.866667
| 33
| 0.697309
|
582a8805d21c1938dc6eb42b87c5973e136db433
| 22,199
|
agda
|
Agda
|
complexity/Pilot2.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 2
|
2016-04-26T20:22:22.000Z
|
2019-08-08T12:27:18.000Z
|
complexity/Pilot2.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 1
|
2020-03-23T08:39:04.000Z
|
2020-05-12T00:32:45.000Z
|
complexity/Pilot2.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | null | null | null |
open import Preliminaries
module Pilot2 where
data CTp : Set where
unit : CTp
nat : CTp -- discrete natural numbers ♭nat, where we interpret ≤ as =
_->c_ : CTp → CTp → CTp
_×c_ : CTp → CTp → CTp
list : CTp → CTp
bool : CTp
C : CTp
rnat : CTp -- natural numbers with ≤ actually interpreted as ≤
data CTpM : CTp → Set where
runit : CTpM unit
rn : CTpM rnat
_×cm_ : ∀ {τ1 τ2} → CTpM τ1 → CTpM τ2 → CTpM (τ1 ×c τ2)
_->cm_ : ∀ {τ1 τ2} → CTpM τ2 → CTpM (τ1 ->c τ2)
-- represent a context as a list of types
Ctx = List CTp
-- de Bruijn indices (for free variables)
data _∈_ : CTp → Ctx → Set where
i0 : ∀ {Γ τ}
→ τ ∈ (τ :: Γ)
iS : ∀ {Γ τ τ1}
→ τ ∈ Γ
→ τ ∈ (τ1 :: Γ)
rctx : Ctx → Ctx → Set
rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ
r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ')
data _|-_ : Ctx → CTp → Set
sctx : Ctx → Ctx → Set
sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ
_∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C
_rs_ : ∀ {A B C} → rctx A B → sctx B C → sctx A C
ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ
subst : ∀ {Γ Γ' τ} → Γ' |- τ → sctx Γ Γ' → Γ |- τ
_ss_ : ∀ {A B C} → sctx A B → sctx B C → sctx A C
_sr_ : ∀ {A B C} → sctx A B → rctx B C → sctx A C
data _≤s_ : ∀ {Γ T} → Γ |- T → Γ |- T → Set
rename-var : ∀ {Γ Γ' τ} → rctx Γ Γ' → τ ∈ Γ' → τ ∈ Γ
idr : ∀ {Γ} → rctx Γ Γ
p∙ : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) Γ'
p : ∀ {Γ τ} → rctx (τ :: Γ) Γ
rename-var-ident : ∀ {Γ τ} → (x : τ ∈ Γ) → rename-var idr x == x
rename-var-∙ : ∀ {A B C τ} → (r1 : rctx A B) (r2 : rctx B C) (x : τ ∈ C) → rename-var r1 (rename-var r2 x) == rename-var (r1 ∙rr r2) x
∙rr-assoc : ∀ {A B C D} → (r1 : rctx A B) (r2 : rctx B C) (r3 : rctx C D) → _==_ {_} {rctx A D} (r1 ∙rr (r2 ∙rr r3)) ((r1 ∙rr r2) ∙rr r3)
extend-ren-comp-lemma : ∀ {Γ Γ' Γ'' τ τ'} → (x : τ ∈ τ' :: Γ'') (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'') → Id {_} {_} ((r-extend ρ1 ∙rr r-extend ρ2) x) (r-extend (ρ1 ∙rr ρ2) x)
extend-ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → Id {_} {rctx (τ :: Γ) (τ :: Γ'')} (r-extend ρ1 ∙rr r-extend ρ2) (r-extend (ρ1 ∙rr ρ2))
wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2
s-extend : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ')
ids : ∀ {Γ} → sctx Γ Γ
q∙ : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) Γ'
lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ')
q : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ)
svar : ∀ {Γ1 Γ2 τ} → sctx Γ1 Γ2 → τ ∈ Γ2 → Γ1 |- τ
lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ'))
lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ))
lem5' : ∀ {Γ Γ' τ1 τ2 τ3} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ')))
lem5 : ∀ {Γ τ1 τ2 τ3} → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ)))
data _|-_ where
unit : ∀ {Γ} → Γ |- unit
0C : ∀ {Γ} → Γ |- C
1C : ∀ {Γ}→ Γ |- C
plusC : ∀ {Γ} → Γ |- C → Γ |- C → Γ |- C
var : ∀ {Γ τ} → τ ∈ Γ → Γ |- τ
z : ∀ {Γ} → Γ |- nat
s : ∀ {Γ} → (e : Γ |- nat) → Γ |- nat
rec : ∀ {Γ τ} → Γ |- nat → Γ |- τ → (nat :: (τ :: Γ)) |- τ → Γ |- τ
lam : ∀ {Γ τ ρ} → (ρ :: Γ) |- τ → Γ |- (ρ ->c τ)
app : ∀ {Γ τ1 τ2} → Γ |- (τ2 ->c τ1) → Γ |- τ2 → Γ |- τ1
-- rz : ∀ {Γ} → Γ |- rnat
-- rsuc : ∀ {Γ} → Γ |- rnat → Γ |- rnat
-- rrec : ∀ {Γ τ} → Γ |- rnat → (Z' : Γ |- τ) → (S' : Γ |- (rnat ->c (τ ->c τ))) → (P : Z' ≤s (app (app S' rz) Z')) → Γ |- τ
--→ (S' : (nat≤ :: (τ :: Γ)) |- τ) → (P : Z' ≤s subst S' (lem3' (lem3' ids Z') z')) (what we're doing is the same but just avoids termination problems)
prod : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → Γ |- (τ1 ×c τ2)
l-proj : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×c τ2) → Γ |- τ1
r-proj : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×c τ2) → Γ |- τ2
nil : ∀ {Γ τ} → Γ |- list τ
_::c_ : ∀ {Γ τ} → Γ |- τ → Γ |- list τ → Γ |- list τ
listrec : ∀ {Γ τ τ'} → Γ |- list τ → Γ |- τ' → (τ :: (list τ :: (τ' :: Γ))) |- τ' → Γ |- τ'
true : ∀ {Γ} → Γ |- bool
false : ∀ {Γ} → Γ |- bool
max : ∀ {Γ τ} → CTpM τ → Γ |- τ → Γ |- τ → Γ |- τ
{-[ Θ ]s : Monotone [ Γ ] [ Γ' ]
[ ρ ]r : same
interpE ren e ρ k == interpE e (interpR ρ) k
interp commutes with renaming and substitution
equations that define ren and subst are true in the semantics-}
--also add axioms for max-l/r etc.
data _≤s_ where
refl-s : ∀ {Γ T} → {e : Γ |- T} → e ≤s e
trans-s : ∀ {Γ T} → {e e' e'' : Γ |- T} → e ≤s e' → e' ≤s e'' → e ≤s e''
cong-refl : ∀ {Γ τ} {e e' : Γ |- τ} → e == e' → e ≤s e'
+-unit-l : ∀ {Γ} {e : Γ |- C} → (plusC 0C e) ≤s e
+-unit-l' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC 0C e)
+-unit-r : ∀ {Γ} {e : Γ |- C} → (plusC e 0C) ≤s e
+-unit-r' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC e 0C)
+-assoc : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC e1 (plusC e2 e3)) ≤s (plusC (plusC e1 e2) e3)
+-assoc' : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC (plusC e1 e2) e3) ≤s (plusC e1 (plusC e2 e3))
refl-+ : ∀ {Γ} {e0 e1 : Γ |- C} → (plusC e0 e1) ≤s (plusC e1 e0)
cong-+ : ∀ {Γ} {e0 e1 e0' e1' : Γ |- C} → e0 ≤s e0' → e1 ≤s e1' → (plusC e0 e1) ≤s (plusC e0' e1')
cong-lproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (l-proj e) ≤s (l-proj e')
cong-rproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (r-proj e) ≤s (r-proj e')
cong-app : ∀ {Γ τ τ'} {e e' : Γ |- (τ ->c τ')} {e1 : Γ |- τ} → e ≤s e' → (app e e1) ≤s (app e' e1)
ren-cong : ∀ {Γ Γ' τ} {e1 e2 : Γ' |- τ} {ρ : rctx Γ Γ'} → e1 ≤s e2 → (ren e1 ρ) ≤s (ren e2 ρ)
subst-cong : ∀ {Γ Γ' τ} {e1 e2 : Γ' |- τ} {Θ : sctx Γ Γ'} → e1 ≤s e2 → (subst e1 Θ) ≤s (subst e2 Θ)
subst-cong2 : ∀ {Γ Γ' τ} {Θ Θ' : sctx Γ Γ'} {e : Γ' |- τ} → (∀ τ → (x : τ ∈ Γ') → Θ x ≤s Θ' x) → subst e Θ ≤s subst e Θ'
cong-rec : ∀ {Γ τ} {e e' : Γ |- nat} {e0 : Γ |- τ} {e1 : (nat :: (τ :: Γ)) |- τ}
→ e ≤s e' → rec e e0 e1 ≤s rec e' e0 e1
cong-listrec : ∀ {Γ τ τ'} {e e' : Γ |- list τ} {e0 : Γ |- τ'} {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ e ≤s e' → listrec e e0 e1 ≤s listrec e' e0 e1
lam-s : ∀ {Γ T T'} → {e : (T :: Γ) |- T'} → {e2 : Γ |- T} → subst e (q e2) ≤s app (lam e) e2
l-proj-s : ∀ {Γ T1 T2} → {e1 : Γ |- T1} {e2 : Γ |- T2} → e1 ≤s (l-proj (prod e1 e2))
r-proj-s : ∀ {Γ T1 T2} → {e1 : Γ |- T1} → {e2 : Γ |- T2} → e2 ≤s (r-proj (prod e1 e2))
rec-steps-z : ∀ {Γ T} → {e0 : Γ |- T} → {e1 : (nat :: (T :: Γ)) |- T} → e0 ≤s (rec z e0 e1)
rec-steps-s : ∀ {Γ T} → {e : Γ |- nat} → {e0 : Γ |- T} → {e1 : (nat :: (T :: Γ)) |- T} → subst e1 (lem4 e (rec e e0 e1)) ≤s (rec (s e) e0 e1)
listrec-steps-nil : ∀ {Γ τ τ'} → {e0 : Γ |- τ'} → {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ e0 ≤s (listrec nil e0 e1)
listrec-steps-cons : ∀ {Γ τ τ'} → {h : Γ |- τ} {t : Γ |- list τ}
→ {e0 : Γ |- τ'} → {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ subst e1 (lem5 h t (listrec t e0 e1)) ≤s (listrec (h ::c t) e0 e1)
ren-comp-l : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → (e : Γ'' |- τ) → (ren (ren e ρ2) ρ1) ≤s (ren e (ρ1 ∙rr ρ2))
ren-comp-r : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → (e : Γ'' |- τ) → (ren e (ρ1 ∙rr ρ2)) ≤s (ren (ren e ρ2) ρ1)
subst-id-l : ∀ {Γ τ} → (e : Γ |- τ) → e ≤s subst e ids
subst-id-r : ∀ {Γ τ} → (e : Γ |- τ) → subst e ids ≤s e
subst-rs-l : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ)
→ ren (subst e Θ) ρ ≤s subst e (ρ rs Θ)
subst-rs-r : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ)
→ subst e (ρ rs Θ) ≤s ren (subst e Θ) ρ
subst-sr-l : ∀ {Γ Γ' Γ'' τ} → (Θ : sctx Γ Γ') → (ρ : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ (subst (ren e ρ) Θ) ≤s subst e (Θ sr ρ)
subst-sr-r : ∀ {Γ Γ' Γ'' τ} → (Θ : sctx Γ Γ') → (ρ : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ subst e (Θ sr ρ) ≤s (subst (ren e ρ) Θ)
subst-ss-l : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ)
→ subst e (Θ1 ss Θ2) ≤s subst (subst e Θ2) Θ1
subst-ss-r : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ)
→ subst (subst e Θ2) Θ1 ≤s subst e (Θ1 ss Θ2)
subst-compose-l : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) )
→ subst (subst e (s-extend Θ)) (q v) ≤s subst e (lem3' Θ v)
subst-compose-r : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) )
→ subst e (lem3' Θ v) ≤s subst (subst e (s-extend Θ)) (q v)
subst-compose2-l : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2)
→ subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2) ≤s subst e1 (lem4' Θ v1 v2)
subst-compose2-r : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2)
→ subst e1 (lem4' Θ v1 v2) ≤s subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2)
subst-compose3-l : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2)
→ subst (subst e1 (lem4 v1 v2)) Θ ≤s subst e1 (lem4' Θ (subst v1 Θ) (subst v2 Θ))
subst-compose3-r : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2)
→ subst e1 (lem4' Θ (subst v1 Θ) (subst v2 Θ)) ≤s subst (subst e1 (lem4 v1 v2)) Θ
subst-compose4-l : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- τ) (e2 : (nat :: (τ :: Γ')) |- τ)
→ subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r) ≤s subst e2 (lem4' Θ v' r)
subst-compose4-r : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- τ) (e2 : (nat :: (τ :: Γ')) |- τ)
→ subst e2 (lem4' Θ v' r) ≤s subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r)
subst-compose5-l : ∀ {Γ Γ' τ τ1 τ2 τ3} (Θ : sctx Γ Γ') (e : (τ1 :: (τ2 :: (τ3 :: Γ'))) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3)
→ subst (subst e (s-extend (s-extend (s-extend (Θ))))) (lem5 v1 v2 v3) ≤s subst e (lem5' Θ v1 v2 v3)
subst-compose5-r : ∀ {Γ Γ' τ τ1 τ2 τ3} (Θ : sctx Γ Γ') (e : (τ1 :: (τ2 :: (τ3 :: Γ'))) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3)
→ subst e (lem5' Θ v1 v2 v3) ≤s subst (subst e (s-extend (s-extend (s-extend (Θ))))) (lem5 v1 v2 v3)
-- r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ')
r-extend ρ i0 = i0
r-extend ρ (iS x) = iS (ρ x)
-- _∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C
ρ1 ∙rr ρ2 = ρ1 o ρ2
rename-var ρ a = ρ a
idr x = x
p∙ ρ = λ x → iS (ρ x)
p = p∙ idr
--free stuff
rename-var-ident _ = Refl
rename-var-∙ _ _ _ = Refl
∙rr-assoc r1 r2 r3 = Refl
ren unit ρ = unit
ren 0C ρ = 0C
ren 1C ρ = 1C
ren (plusC e e₁) ρ = plusC (ren e ρ) (ren e₁ ρ)
ren (var x) ρ = var (ρ x)
ren z ρ = z
ren (s e) ρ = s (ren e ρ)
ren (rec e e₁ e₂) ρ = rec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend ρ)))
ren (lam e) ρ = lam (ren e (r-extend ρ))
ren (app e e₁) ρ = app (ren e ρ) (ren e₁ ρ)
ren (prod e1 e2) ρ = prod (ren e1 ρ) (ren e2 ρ)
ren (l-proj e) ρ = l-proj (ren e ρ)
ren (r-proj e) ρ = r-proj (ren e ρ)
ren nil ρ = nil
ren (x ::c xs) ρ = ren x ρ ::c ren xs ρ
ren true ρ = true
ren false ρ = false
ren (listrec e e₁ e₂) ρ = listrec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend (r-extend ρ))))
-- ren rz ρ = rz
-- ren (rsuc e) ρ = rsuc (ren e ρ)
-- ren (rrec e e₁ e₂ p) ρ = rrec (ren e ρ) (ren e₁ ρ) (ren e₂ ρ) (ren-cong p)
ren (max τ e1 e2) ρ = max τ (ren e1 ρ) (ren e2 ρ)
extend-ren-comp-lemma i0 ρ1 ρ2 = Refl
extend-ren-comp-lemma (iS x) ρ1 ρ2 = Refl
extend-ren-comp ρ1 ρ2 = λ=i (λ τ → λ= (λ x → extend-ren-comp-lemma x ρ1 ρ2))
-- weakening a context
wkn e = ren e iS
-- parallel extension
s-extend Θ i0 = var i0
s-extend Θ (iS x) = wkn (Θ x)
-- identity substitution
ids x = var x
-- weakening with substitution
q∙ Θ = λ x → wkn (Θ x)
lem3' Θ e i0 = e
lem3' Θ e (iS i) = Θ i
--lem3
q e = lem3' ids e
-- subst-var
svar Θ i = q (Θ i) i0
lem4' Θ a b = lem3' (lem3' Θ b) a
lem4 e1 e2 = lem4' ids e1 e2
lem5' Θ a b c = lem3' (lem3' (lem3' Θ c) b) a
lem5 e1 e2 e3 = lem5' ids e1 e2 e3
subst unit Θ = unit
subst 0C Θ = 0C
subst 1C Θ = 1C
subst (plusC e e₁) Θ = plusC (subst e Θ) (subst e₁ Θ)
subst (var x) Θ = Θ x
subst z Θ = z
subst (s e) Θ = s (subst e Θ)
subst (rec e e₁ e₂) Θ = rec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend Θ)))
subst (lam e) Θ = lam (subst e (s-extend Θ))
subst (app e e₁) Θ = app (subst e Θ) (subst e₁ Θ)
subst (prod e1 e2) Θ = prod (subst e1 Θ) (subst e2 Θ)
subst (l-proj e) Θ = l-proj (subst e Θ)
subst (r-proj e) Θ = r-proj (subst e Θ)
subst nil Θ = nil
subst (x ::c xs) Θ = subst x Θ ::c subst xs Θ
subst true Θ = true
subst false Θ = false
subst (listrec e e₁ e₂) Θ = listrec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend (s-extend Θ))))
-- subst rz Θ = rz
-- subst (rsuc e) Θ = rsuc (subst e Θ)
-- subst (rrec e e₁ e₂ p) Θ = rrec (subst e Θ) (subst e₁ Θ) (subst e₂ Θ) (subst-cong p)
subst (max τ e1 e2) Θ = max τ (subst e1 Θ) (subst e2 Θ)
subst1 : ∀ {Γ τ τ1} → Γ |- τ1 → (τ1 :: Γ) |- τ → Γ |- τ
subst1 e e' = subst e' (q e)
_rs_ ρ Θ x = ren (subst (var x) Θ) ρ
_ss_ Θ1 Θ2 x = subst (subst (var x) Θ2) Θ1
_sr_ Θ ρ x = subst (ren (var x) ρ) Θ
extend-id-once-lemma : ∀ {Γ τ τ'} → (x : τ ∈ τ' :: Γ) → _==_ {_} {τ' :: Γ |- τ}
(ids {τ' :: Γ} {τ} x) (s-extend {Γ} {Γ} {τ'} (ids {Γ}) {τ} x)
extend-id-once-lemma i0 = Refl
extend-id-once-lemma (iS x) = Refl
extend-id-once : ∀ {Γ τ} → Id {_} {sctx (τ :: Γ) (τ :: Γ)} (ids {τ :: Γ}) (s-extend ids)
extend-id-once = λ=i (λ τ → λ= (λ x → extend-id-once-lemma x))
extend-id-twice : ∀ {Γ τ1 τ2} → Id {_} {sctx (τ1 :: τ2 :: Γ) (τ1 :: τ2 :: Γ)} (ids {τ1 :: τ2 :: Γ}) (s-extend (s-extend ids))
extend-id-twice = ap s-extend extend-id-once ∘ extend-id-once
{- lemmas I may or may not need later
extend-rs-once-lemma : ∀ {A B C τ τ'} → (x : τ ∈ τ' :: B) (ρ : rctx C A) (Θ : sctx A B) → _==_ {_} {τ' :: C |- τ}
(_rs_ {τ' :: C} {τ' :: A} {τ' :: B} (r-extend {C} {A} {τ'} ρ)
(s-extend {A} {B} {τ'} Θ) {τ} x)
(s-extend {C} {B} {τ'} (_rs_ {C} {A} {B} ρ Θ) {τ} x)
extend-rs-once-lemma i0 ρ Θ = Refl
extend-rs-once-lemma (iS x) ρ Θ = ! (ren-comp iS ρ (Θ x)) ∘ ren-comp (r-extend ρ) iS (Θ x)
extend-rs-once : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: C) (τ :: B)} (r-extend ρ rs s-extend Θ) (s-extend (ρ rs Θ))
extend-rs-once ρ Θ = λ=i (λ τ → λ= (λ x → extend-rs-once-lemma x ρ Θ))
extend-rs-twice : ∀ {A B C τ τ'} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: τ' :: C) (τ :: τ' :: B)} ((r-extend (r-extend ρ)) rs (s-extend (s-extend Θ))) ((s-extend (s-extend (ρ rs Θ))))
extend-rs-twice ρ Θ = ap s-extend (extend-rs-once ρ Θ) ∘ extend-rs-once (r-extend ρ) (s-extend Θ)
extend-sr-once-lemma : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_sr_ Θ ρ) x) (_sr_ (s-extend Θ) (r-extend ρ) x)
extend-sr-once-lemma Θ ρ i0 = Refl
extend-sr-once-lemma Θ ρ (iS x) = Refl
extend-sr-once : ∀ {A B C τ} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ :: A) (τ :: C)} (s-extend Θ sr r-extend ρ) (s-extend (Θ sr ρ))
extend-sr-once Θ ρ = λ=i (λ τ → λ= (λ x → ! (extend-sr-once-lemma Θ ρ x)))
extend-sr-twice : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ' :: τ :: A) (τ' :: τ :: C)}
(s-extend (s-extend Θ) sr r-extend (r-extend ρ)) (s-extend (s-extend (Θ sr ρ)))
extend-sr-twice Θ ρ = ap s-extend (extend-sr-once Θ ρ) ∘ extend-sr-once (s-extend Θ) (r-extend ρ)
extend-ss-once-lemma : ∀ {A B C τ τ'} → (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_ss_ Θ1 Θ2) x) (_ss_ (s-extend Θ1) (s-extend Θ2) x)
extend-ss-once-lemma Θ1 Θ2 i0 = Refl
extend-ss-once-lemma Θ1 Θ2 (iS x) = ! (sr-comp (s-extend Θ1) iS (Θ2 x)) ∘ rs-comp iS Θ1 (Θ2 x)
extend-ss-once : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C)
→ _==_ {_} {sctx (τ :: A) (τ :: C)} (s-extend (Θ1 ss Θ2))
((s-extend Θ1) ss
(s-extend Θ2))
extend-ss-once Θ1 Θ2 = λ=i (λ τ → λ= (λ x → extend-ss-once-lemma Θ1 Θ2 x))
throw : ∀ {Γ Γ' τ} → sctx Γ (τ :: Γ') → sctx Γ Γ'
throw Θ x = Θ (iS x)
fuse1 : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ Γ') → (q v ss q∙ Θ) x == Θ x
fuse1 v Θ x = subst (ren (Θ x) iS) (q v) =⟨ sr-comp (q v) iS (Θ x) ⟩
subst (Θ x) (q v sr iS) =⟨ Refl ⟩
subst (Θ x) ids =⟨ ! (subst-id (Θ x)) ⟩
(Θ x ∎)
subst-compose-lemma-lemma : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ τ' :: Γ')
→ _==_ {_} {Γ |- τ} (_ss_ (q v) (s-extend Θ) x) (lem3' Θ v x)
subst-compose-lemma-lemma v Θ i0 = Refl
subst-compose-lemma-lemma v Θ (iS x) = fuse1 v Θ x
subst-compose-lemma : ∀ {Γ Γ' τ} (v : Γ |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ :: Γ')} ((q v) ss (s-extend Θ)) (lem3' Θ v)
subst-compose-lemma v Θ = λ=i (λ τ → λ= (λ x → subst-compose-lemma-lemma v Θ x))
fuse2 : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (Θ : sctx Γ Γ') (x : τ ∈ τ2 :: Γ')
→ (lem4 v1 v2 ss throw (s-extend (s-extend Θ))) x == (lem3' Θ v2) x
fuse2 v1 v2 Θ x = subst (ren (s-extend Θ x) iS) (lem4 v1 v2) =⟨ sr-comp (lem4 v1 v2) iS (s-extend Θ x) ⟩
subst (s-extend Θ x) (lem4 v1 v2 sr iS) =⟨ Refl ⟩
subst (s-extend Θ x) (lem3' ids v2) =⟨ subst-compose-lemma-lemma v2 Θ x ⟩
(lem3' Θ v2 x ∎)
subst-compose2-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ'} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ') (x : τ' ∈ τ1 :: τ2 :: Γ')
→ _==_ {_} {_} ((lem4 v1 v2 ss s-extend (s-extend Θ)) x) (lem4' Θ v1 v2 x)
subst-compose2-lemma-lemma v1 v2 e1 Θ i0 = Refl
subst-compose2-lemma-lemma v1 v2 e1 Θ (iS x) = fuse2 v1 v2 Θ x
subst-compose2-lemma : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: Γ')} (lem4 v1 v2 ss s-extend (s-extend Θ)) (lem4' Θ v1 v2)
subst-compose2-lemma v1 v2 e1 Θ = λ=i (λ τ → λ= (λ x → subst-compose2-lemma-lemma v1 v2 e1 Θ x))
fuse3 : ∀ {Γ Γ' τ1 τ2 τ'} (Θ : sctx Γ Γ') (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) (x : τ' ∈ τ2 :: Γ')
→ subst (lem3' ids v2 x) Θ == lem3' Θ (subst v2 Θ) x
fuse3 Θ v1 v2 i0 = Refl
fuse3 Θ v1 v2 (iS x) = Refl
subst-compose3-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ'} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) (x : τ' ∈ τ1 :: τ2 :: Γ')
→ _==_ {_} {_} ((Θ ss lem4 v1 v2) x) (lem4' Θ (subst v1 Θ) (subst v2 Θ) x)
subst-compose3-lemma-lemma Θ e1 v1 v2 i0 = Refl
subst-compose3-lemma-lemma Θ e1 v1 v2 (iS x) = fuse3 Θ v1 v2 x
subst-compose3-lemma : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2)
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: Γ')} (Θ ss lem4 v1 v2) (lem4' Θ (subst v1 Θ) (subst v2 Θ))
subst-compose3-lemma Θ e1 v1 v2 = λ=i (λ τ → λ= (λ x → subst-compose3-lemma-lemma Θ e1 v1 v2 x))
fuse4-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (Θ : sctx Γ Γ') (x : τ ∈ Γ')
→ (lem3' (lem3' ids v3) v2 ss q∙ (q∙ Θ)) x == Θ x
fuse4-lemma v1 v2 v3 Θ x = subst (ren (wkn (Θ x)) iS) (lem3' (q v3) v2) =⟨ sr-comp (lem3' (q v3) v2) iS (wkn (Θ x)) ⟩
subst (wkn (Θ x)) (lem3' (q v3) v2 sr iS) =⟨ Refl ⟩
subst (ren (Θ x) iS) (lem3' (q v3) v2 sr iS) =⟨ sr-comp (lem3' (q v3) v2 sr iS) iS (Θ x) ⟩
subst (Θ x) ((lem3' (q v3) v2 sr iS) sr iS) =⟨ Refl ⟩
subst (Θ x) ids =⟨ ! (subst-id (Θ x)) ⟩
(Θ x ∎)
fuse4 : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (Θ : sctx Γ Γ') (x : τ ∈ τ2 :: τ3 :: Γ')
→ subst (s-extend (s-extend Θ) x) (lem3' (lem3' ids v3) v2) == lem3' (lem3' Θ v3) v2 x
fuse4 v1 v2 v3 Θ i0 = Refl
fuse4 v1 v2 v3 Θ (iS i0) = Refl
fuse4 v1 v2 v3 Θ (iS (iS x)) = subst (wkn (wkn (Θ x))) (lem3' (lem3' ids v3) v2) =⟨ subst-ss (lem3' (lem3' ids v3) v2) (q∙ (q∙ Θ)) (var x) ⟩
subst (var x) (lem3' (lem3' ids v3) v2 ss q∙ (q∙ Θ)) =⟨ fuse4-lemma v1 v2 v3 Θ x ⟩
subst (var x) Θ =⟨ Refl ⟩
(Θ x ∎)
subst-compose5-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3 τ'} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (e1 : τ1 :: τ2 :: τ3 :: Γ' |- τ) (Θ : sctx Γ Γ') (x : τ' ∈ τ1 :: τ2 :: τ3 :: Γ')
→ _==_ {_} {_} ((lem5 v1 v2 v3 ss s-extend (s-extend (s-extend Θ))) x) (lem5' Θ v1 v2 v3 x)
subst-compose5-lemma-lemma v1 v2 v3 e Θ i0 = Refl
subst-compose5-lemma-lemma v1 v2 v3 e Θ (iS x) = (lem5 v1 v2 v3 ss s-extend (s-extend (s-extend Θ))) (iS x) =⟨ sr-comp (lem5 v1 v2 v3) iS (s-extend (s-extend Θ) x) ⟩
subst (s-extend (s-extend Θ) x) (lem3' (lem3' ids v3) v2) =⟨ fuse4 v1 v2 v3 Θ x ⟩
(lem3' (lem3' Θ v3) v2 x ∎)
subst-compose5-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (e : τ1 :: τ2 :: τ3 :: Γ' |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: τ3 :: Γ')} (lem5 v1 v2 v3 ss (s-extend (s-extend (s-extend Θ)))) (lem5' Θ v1 v2 v3)
subst-compose5-lemma v1 v2 v3 e Θ = λ=i (λ τ → λ= (λ x → subst-compose5-lemma-lemma v1 v2 v3 e Θ x))
-}
_+C_ : ∀ {Γ τ} → Γ |- C → Γ |- (C ×c τ)→ Γ |- (C ×c τ)
c +C e = prod (plusC c (l-proj e)) (r-proj e)
_trans_ : ∀ {Γ T}
→ {e e' e'' : Γ |- T}
→ e ≤s e' → e' ≤s e''
→ e ≤s e''
_trans_ = trans-s
infixr 10 _trans_
| 54.812346
| 179
| 0.446191
|
0ba30adffd837bede60bfd10363ef83916988542
| 2,380
|
agda
|
Agda
|
Cubical/Categories/Presheaves.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Presheaves.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Presheaves.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --postfix-projections #-}
module Cubical.Categories.Presheaves where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open import Cubical.Categories.Sets
module _ (ℓ ℓ' : Level) where
PSH : Precategory ℓ ℓ' → Precategory (ℓ-max (ℓ-suc ℓ) ℓ') (ℓ-max (ℓ-suc ℓ) ℓ')
PSH 𝒞 = FUNCTOR (𝒞 ^op) (SET ℓ)
private
variable
ℓ : Level
module Yoneda (𝒞 : Precategory ℓ ℓ) ⦃ 𝒞-cat : isCategory 𝒞 ⦄ where
open Functor
open NatTrans
yo : 𝒞 .ob → Functor (𝒞 ^op) (SET ℓ)
yo x .F-ob y .fst = 𝒞 .hom y x
yo x .F-ob y .snd = 𝒞-cat .homIsSet
yo x .F-hom f g = 𝒞 .seq f g
yo x .F-idn i f = 𝒞 .seq-λ f i
yo x .F-seq f g i h = 𝒞 .seq-α g f h i
YO : Functor 𝒞 (PSH ℓ ℓ 𝒞)
YO .F-ob = yo
YO .F-hom f .N-ob z g = 𝒞 .seq g f
YO .F-hom f .N-hom g i h = 𝒞 .seq-α g h f i
YO .F-idn = make-nat-trans-path λ i _ → λ f → 𝒞 .seq-ρ f i
YO .F-seq f g = make-nat-trans-path λ i _ → λ h → 𝒞 .seq-α h f g (~ i)
module _ {x} (F : Functor (𝒞 ^op) (SET ℓ)) where
yo-yo-yo : NatTrans (yo x) F → F .F-ob x .fst
yo-yo-yo α = α .N-ob _ (𝒞 .idn _)
no-no-no : F .F-ob x .fst → NatTrans (yo x) F
no-no-no a .N-ob y f = F .F-hom f a
no-no-no a .N-hom f = funExt λ g i → F .F-seq g f i a
yo-iso : Iso (NatTrans (yo x) F) (F .F-ob x .fst)
yo-iso .Iso.fun = yo-yo-yo
yo-iso .Iso.inv = no-no-no
yo-iso .Iso.rightInv b i = F .F-idn i b
yo-iso .Iso.leftInv a = make-nat-trans-path (funExt λ _ → funExt rem)
where
rem : ∀ {z} (x₁ : 𝒞 .hom z x) → F .F-hom x₁ (yo-yo-yo a) ≡ (a .N-ob z) x₁
rem g =
F .F-hom g (yo-yo-yo a)
≡[ i ]⟨ a .N-hom g (~ i) (𝒞 .idn x) ⟩
a .N-hom g i0 (𝒞 .idn x)
≡[ i ]⟨ a .N-ob _ (𝒞 .seq-ρ g i) ⟩
(a .N-ob _) g
∎
yo-equiv : NatTrans (yo x) F ≃ F .F-ob x .fst
yo-equiv = isoToEquiv yo-iso
YO-full : is-full YO
YO-full x y F[f] = ∣ yo-yo-yo _ F[f] , yo-iso {x} (yo y) .Iso.leftInv F[f] ∣
YO-faithful : is-faithful YO
YO-faithful x y f g p i =
hcomp
(λ j → λ{ (i = i0) → 𝒞 .seq-λ f j; (i = i1) → 𝒞 .seq-λ g j})
(yo-yo-yo _ (p i))
| 30.909091
| 81
| 0.565966
|
41ad61f508f7059e9c1db7b7f3f464a49a147574
| 1,313
|
agda
|
Agda
|
src/Categories/Category/Construction/StrictDiscrete.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Construction/StrictDiscrete.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Construction/StrictDiscrete.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.Category.Construction.StrictDiscrete where
-- This is not 'the' Discrete Category construction, but one of them.
-- In this case, what is built is a Category, but it's actually Strict (thus
-- the name).
open import Level
open import Data.Unit
open import Function
open import Relation.Binary.PropositionalEquality as ≡
open import Categories.Category
open import Categories.Functor
Discrete : ∀ {a} (A : Set a) → Category a a a
Discrete A = record
{ Obj = A
; _⇒_ = _≡_
; _≈_ = _≡_
; id = refl
; _∘_ = flip ≡.trans
; assoc = λ {_ _ _ _ g} → sym (trans-assoc g)
; sym-assoc = λ {_ _ _ _ g} → trans-assoc g
; identityˡ = λ {_ _ f} → trans-reflʳ f
; identityʳ = refl
; identity² = refl
; equiv = isEquivalence
; ∘-resp-≈ = λ where
refl refl → refl
}
module _ {a o ℓ e} {A : Set a} (C : Category o ℓ e) where
open Category C renaming (id to one)
module _ (f : A → Obj) where
lift-func : Functor (Discrete A) C
lift-func = record
{ F₀ = f
; F₁ = λ { refl → one }
; identity = Equiv.refl
; homomorphism = λ { {_} {_} {_} {refl} {refl} → Equiv.sym identity² }
; F-resp-≈ = λ { {_} {_} {refl} refl → Equiv.refl }
}
| 29.177778
| 76
| 0.581874
|
dc0f12b07f4201a08753371c60465b549eb80696
| 752
|
agda
|
Agda
|
test/interaction/Auto-EqualityReasoning.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Auto-EqualityReasoning.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Auto-EqualityReasoning.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Auto-EqualityReasoning where
-- equality reasoning, computation and induction
open import Auto.Prelude
module AdditionCommutative where
lemma : ∀ n m → (n + succ m) ≡ succ (n + m)
lemma n m = {!-c!} -- h0
{-
lemma zero m = refl
lemma (succ x) m = cong succ (lemma x m)
-}
lemma' : ∀ n m → (n + succ m) ≡ succ (n + m)
lemma' zero m = refl
lemma' (succ n) m = cong succ (lemma' n m)
addcommut : ∀ n m → (n + m) ≡ (m + n)
addcommut n m = {!-c lemma'!} -- h1
{-
addcommut zero zero = refl
addcommut zero (succ x) = sym (cong succ (addcommut x zero)) -- solution does not pass termination check
addcommut (succ x) m = begin (succ (x + m) ≡⟨ cong succ (addcommut x m) ⟩ (succ (m + x) ≡⟨ sym (lemma' m x) ⟩ ((m + succ x) ∎)))
-}
| 25.931034
| 129
| 0.599734
|
234e395f839aa66d3cc4a908bea8479525a63e7c
| 1,089
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/RingExpression.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/RingExpression.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/RingExpression.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.RingSolver.RingExpression 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.RingSolver.AlmostRing
open import Cubical.Algebra.RingSolver.RawRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
private
variable
ℓ : Level
infixl 6 _⊕_
infixl 7 _⊗_
-- Expression in a ring on A with n variables
data Expr {ℓ} (A : Type ℓ) (n : ℕ) : Type ℓ where
K : A → Expr A n
∣ : Fin n → Expr A n
_⊕_ : Expr A n → Expr A n → Expr A n
_⊗_ : Expr A n → Expr A n → Expr A n
-- _⊛_ : Expr A n → ℕ → Expr A n -- exponentiation
⊝_ : Expr A n → Expr A n
module Eval (R : RawRing {ℓ}) where
open import Cubical.Data.Vec
open RawRing R
⟦_⟧ : ∀ {n} → Expr ⟨ R ⟩ᵣ n → Vec ⟨ R ⟩ᵣ n → ⟨ R ⟩ᵣ
⟦ K r ⟧ v = r
⟦ ∣ k ⟧ v = lookup k v
⟦ x ⊕ y ⟧ v = ⟦ x ⟧ v + ⟦ y ⟧ v
⟦ x ⊗ y ⟧ v = ⟦ x ⟧ v · ⟦ y ⟧ v
-- ⟦ x ⊛ l ⟧ v = ⟦ x ⟧ v ^ l
⟦ ⊝ x ⟧ v = - ⟦ x ⟧ v
| 27.225
| 69
| 0.598714
|
41c16140220f0a87307b1a0f128bc4bf62e48aa5
| 409
|
agda
|
Agda
|
test/Succeed/Issue665.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue665.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue665.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue665 where
postulate
A : Set
record I : Set where
constructor i
field
f : A
data Wrap : (j : I) → Set where
con : ∀ {j} → Wrap j
postulate
C : Set
anything : C
works1 : ∀ {X} -> Wrap X -> C
works1 (con {i _}) with anything
... | z = z
works2 : ∀ {X} -> Wrap X -> C
works2 (con {_}) with anything
... | z = z
bugged : ∀ {X} -> Wrap X -> C
bugged con with anything
... | z = z
| 14.103448
| 32
| 0.552567
|
a1a5a5ef36eb236094446352e66a465a7635b9c2
| 4,984
|
agda
|
Agda
|
core/lib/NType.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
core/lib/NType.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
core/lib/NType.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Base
open import lib.PathGroupoid
open import lib.Relation
module lib.NType {i} where
{- Definition of contractible types and truncation levels -}
is-contr : Type i → Type i
is-contr A = Σ A (λ x → ((y : A) → x == y))
has-level : ℕ₋₂ → (Type i → Type i)
has-level ⟨-2⟩ A = is-contr A
has-level (S n) A = (x y : A) → has-level n (x == y)
is-prop = has-level -1
is-set = has-level 0
{- To be a mere proposition, it is sufficient that all points are equal -}
has-all-paths : Type i → Type i
has-all-paths A = (x y : A) → x == y
abstract
all-paths-is-prop : {A : Type i} → (has-all-paths A → is-prop A)
all-paths-is-prop {A} c x y = (c x y , canon-path) where
canon-path : {x y : A} (p : x == y) → c x y == p
canon-path {.y} {y} idp =
c y y =⟨ lemma (! (c y y)) ⟩
(! (c y y)) ∙ c y y =⟨ !-inv-l (c y y) ⟩
idp ∎ where
lemma : {x y : A} (p : x == y) → c x y == p ∙ c y y
lemma idp = idp
{- Truncation levels are cumulative -}
abstract
raise-level : {A : Type i} (n : ℕ₋₂)
→ (has-level n A → has-level (S n) A)
raise-level ⟨-2⟩ q =
all-paths-is-prop (λ x y → ! (snd q x) ∙ snd q y)
raise-level (S n) q =
λ x y → raise-level n (q x y)
{- Having decidable equality is stronger that being a set -}
has-dec-eq : Type i → Type i
has-dec-eq A = Decidable (_==_ :> Rel A i)
abstract
dec-eq-is-set : {A : Type i} → (has-dec-eq A → is-set A)
dec-eq-is-set {A} d x y = all-paths-is-prop UIP where
UIP : {x y : A} (p q : x == y) -> p == q
UIP {x} idp q with d x x | lemma q where
T : {x y : A} → x == y → Type i
T {x} {y} p =
match (d x y) withl (λ b → match (d x x) withl (λ b' → p == ! b' ∙ b)
withr (λ _ → Lift Empty))
withr (λ _ → Lift Empty)
lemma : {x y : A} → (p : x == y) -> T p
lemma {x} idp with (d x x)
lemma idp | inl a = ! (!-inv-l a)
lemma idp | inr r = lift (r idp)
UIP idp q | inl a | p' = ! (!-inv-l a) ∙ (! p')
UIP idp q | inr r | _ = Empty-elim (r idp)
{- Relationships between levels -}
module _ {A : Type i} where
abstract
contr-has-all-paths : is-contr A → has-all-paths A
contr-has-all-paths c x y = ! (snd c x) ∙ snd c y
prop-has-all-paths : is-prop A → has-all-paths A
prop-has-all-paths c x y = fst (c x y)
inhab-prop-is-contr : A → is-prop A → is-contr A
inhab-prop-is-contr x₀ p = (x₀ , λ y → fst (p x₀ y))
inhab-to-contr-is-prop : (A → is-contr A) → is-prop A
inhab-to-contr-is-prop c = all-paths-is-prop $
λ x y → ! (snd (c x) x) ∙ snd (c x) y
contr-has-level : {n : ℕ₋₂} → (is-contr A → has-level n A)
contr-has-level {n = ⟨-2⟩} p = p
contr-has-level {n = S n} p = raise-level n (contr-has-level p)
prop-has-level-S : {n : ℕ₋₂} → (is-prop A → has-level (S n) A)
prop-has-level-S {n = ⟨-2⟩} p = p
prop-has-level-S {n = S n} p = raise-level (S n) (prop-has-level-S p)
set-has-level-SS : {n : ℕ₋₂} → (is-set A → has-level (S (S n)) A)
set-has-level-SS {n = ⟨-2⟩} p = p
set-has-level-SS {n = S n} p = raise-level (S (S n)) (set-has-level-SS p)
contr-is-prop : is-contr A → is-prop A
contr-is-prop = contr-has-level
contr-is-set : is-contr A → is-set A
contr-is-set = contr-has-level
prop-is-set : is-prop A → is-set A
prop-is-set = prop-has-level-S
{- If [A] has level [n], then so does [x == y] for [x y : A] -}
=-preserves-level : (n : ℕ₋₂) {x y : A}
→ (has-level n A → has-level n (x == y))
=-preserves-level ⟨-2⟩ p = (contr-has-all-paths p _ _ , unique-path) where
unique-path : {u v : A} (q : u == v)
→ contr-has-all-paths p u v == q
unique-path idp = !-inv-l (snd p _)
=-preserves-level (S n) {x} {y} p = raise-level n (p x y)
=-preserves-set : {x y : A} → (is-set A → is-set (x == y))
=-preserves-set = =-preserves-level 0
=-preserves-prop : {x y : A} → (is-prop A → is-prop (x == y))
=-preserves-prop = =-preserves-level -1
{- The type of paths from a fixed point is contractible -}
pathfrom-is-contr : (x : A) → is-contr (Σ A (λ t → x == t))
pathfrom-is-contr x = ((x , idp) , pathfrom-unique-path) where
pathfrom-unique-path : {u : A} (pp : Σ A (λ t → u == t)) → (u , idp) == pp
pathfrom-unique-path (u , idp) = idp
{- The type of paths to a fixed point is contractible -}
pathto-is-contr : (x : A) → is-contr (Σ A (λ t → t == x))
pathto-is-contr x = ((x , idp) , pathto-unique-path) where
pathto-unique-path : {u : A} (pp : Σ A (λ t → t == u)) → (u , idp) == pp
pathto-unique-path (u , idp) = idp
{-
If [B] is a fibration over a contractible type [A], then any point in any
fiber of [B] gives a section
-}
contr-has-section : ∀ {j} {A : Type i} {B : A → Type j}
→ (is-contr A → (x : A) → (u : B x) → Π A B)
contr-has-section {B = B} (x , p) x₀ y₀ t = transport B (! (p x₀) ∙ p t) y₀
| 34.136986
| 78
| 0.530498
|
221f3e45ab635da08e3e32a812e1ffcc619b49f4
| 8,644
|
agda
|
Agda
|
src/STLC/Kovacs/Substitution.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
src/STLC/Kovacs/Substitution.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
src/STLC/Kovacs/Substitution.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
module STLC.Kovacs.Substitution where
open import STLC.Kovacs.Embedding public
open import Category
--------------------------------------------------------------------------------
-- Substitutions (Sub ; ∙ ; _,_)
infix 3 _⊢⋆_
data _⊢⋆_ : 𝒞 → 𝒞 → Set
where
∅ : ∀ {Γ} → Γ ⊢⋆ ∅
_,_ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ) (M : Γ ⊢ A)
→ Γ ⊢⋆ Ξ , A
-- (_ₛ∘ₑ_)
-- NOTE: _◐_ = ren⋆
_◐_ : ∀ {Γ Γ′ Ξ} → Γ ⊢⋆ Ξ → Γ′ ⊇ Γ → Γ′ ⊢⋆ Ξ
∅ ◐ η = ∅
(σ , M) ◐ η = σ ◐ η , ren η M
-- (_ₑ∘ₛ_)
_◑_ : ∀ {Γ Ξ Ξ′} → Ξ′ ⊇ Ξ → Γ ⊢⋆ Ξ′ → Γ ⊢⋆ Ξ
done ◑ σ = σ
wkₑ η ◑ (σ , M) = η ◑ σ
liftₑ η ◑ (σ , M) = η ◑ σ , M
--------------------------------------------------------------------------------
-- (dropₛ)
wkₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ
wkₛ σ = σ ◐ wkₑ idₑ
-- (keepₛ)
liftₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ , A
liftₛ σ = wkₛ σ , 0
-- (⌜_⌝ᵒᵖᵉ)
⌊_⌋ : ∀ {Γ Γ′} → Γ′ ⊇ Γ → Γ′ ⊢⋆ Γ
⌊ done ⌋ = ∅
⌊ wkₑ η ⌋ = wkₛ ⌊ η ⌋
⌊ liftₑ η ⌋ = liftₛ ⌊ η ⌋
-- (∈ₛ)
getₛ : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ∋ A → Γ ⊢ A
getₛ (σ , M) zero = M
getₛ (σ , M) (suc i) = getₛ σ i
-- (Tmₛ)
sub : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
sub σ (𝓋 i) = getₛ σ i
sub σ (ƛ M) = ƛ (sub (liftₛ σ) M)
sub σ (M ∙ N) = sub σ M ∙ sub σ N
-- (idₛ)
idₛ : ∀ {Γ} → Γ ⊢⋆ Γ
idₛ {∅} = ∅
idₛ {Γ , A} = liftₛ idₛ
cut : ∀ {Γ A B} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut M N = sub (idₛ , M) N
-- (_∘ₛ_)
-- NOTE: _●_ = sub⋆
_●_ : ∀ {Γ Ξ Φ} → Ξ ⊢⋆ Φ → Γ ⊢⋆ Ξ → Γ ⊢⋆ Φ
∅ ● σ₁ = ∅
(σ₂ , M) ● σ₁ = σ₂ ● σ₁ , sub σ₁ M
--------------------------------------------------------------------------------
-- (assₛₑₑ)
comp◐○ : ∀ {Γ Γ′ Γ″ Ξ} → (η₁ : Γ″ ⊇ Γ′) (η₂ : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ)
→ (σ ◐ η₂) ◐ η₁ ≡ σ ◐ (η₂ ○ η₁)
comp◐○ η₁ η₂ ∅ = refl
comp◐○ η₁ η₂ (σ , M) = _,_ & comp◐○ η₁ η₂ σ
⊗ (ren○ η₁ η₂ M ⁻¹)
-- (assₑₛₑ)
comp◑◐ : ∀ {Γ Γ′ Ξ Ξ′} → (η₁ : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ′) (η₂ : Ξ′ ⊇ Ξ)
→ (η₂ ◑ σ) ◐ η₁ ≡ η₂ ◑ (σ ◐ η₁)
comp◑◐ η₁ ∅ done = refl
comp◑◐ η₁ (σ , M) (wkₑ η₂) = comp◑◐ η₁ σ η₂
comp◑◐ η₁ (σ , M) (liftₑ η₂) = (_, ren η₁ M) & comp◑◐ η₁ σ η₂
--------------------------------------------------------------------------------
-- (idlₑₛ)
lid◑ : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)
→ idₑ ◑ σ ≡ σ
lid◑ ∅ = refl
lid◑ (σ , M) = (_, M) & lid◑ σ
-- (idlₛₑ)
lid◐ : ∀ {Γ Γ′} → (η : Γ′ ⊇ Γ)
→ idₛ ◐ η ≡ ⌊ η ⌋
lid◐ done = refl
lid◐ (wkₑ η) = ((idₛ ◐_) ∘ wkₑ) & rid○ η ⁻¹
⦙ comp◐○ (wkₑ idₑ) η idₛ ⁻¹
⦙ wkₛ & lid◐ η
lid◐ (liftₑ η) = (_, 0) & ( comp◐○ (liftₑ η) (wkₑ idₑ) idₛ
⦙ ((idₛ ◐_) ∘ wkₑ) & ( lid○ η
⦙ rid○ η ⁻¹
)
⦙ comp◐○ (wkₑ idₑ) η idₛ ⁻¹
⦙ (_◐ wkₑ idₑ) & lid◐ η
)
-- (idrₑₛ)
rid◑ : ∀ {Γ Γ′} → (η : Γ′ ⊇ Γ)
→ η ◑ idₛ ≡ ⌊ η ⌋
rid◑ done = refl
rid◑ (wkₑ η) = comp◑◐ (wkₑ idₑ) idₛ η ⁻¹
⦙ wkₛ & rid◑ η
rid◑ (liftₑ η) = (_, 0) & ( comp◑◐ (wkₑ idₑ) idₛ η ⁻¹
⦙ (_◐ wkₑ idₑ) & rid◑ η
)
--------------------------------------------------------------------------------
-- (∈-ₑ∘ₛ)
get◑ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (i : Ξ ∋ A)
→ getₛ (η ◑ σ) i ≡ (getₛ σ ∘ getₑ η) i
get◑ σ done i = refl
get◑ (σ , M) (wkₑ η) i = get◑ σ η i
get◑ (σ , M) (liftₑ η) zero = refl
get◑ (σ , M) (liftₑ η) (suc i) = get◑ σ η i
-- (Tm-ₑ∘ₛ)
mutual
sub◑ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (M : Ξ ⊢ A)
→ sub (η ◑ σ) M ≡ (sub σ ∘ ren η) M
sub◑ σ η (𝓋 i) = get◑ σ η i
sub◑ σ η (ƛ M) = ƛ & sublift◑ σ η M
sub◑ σ η (M ∙ N) = _∙_ & sub◑ σ η M
⊗ sub◑ σ η N
sublift◑ : ∀ {Γ Ξ Ξ′ A B} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (M : Ξ , B ⊢ A)
→ sub (liftₛ {B} (η ◑ σ)) M ≡
(sub (liftₛ σ) ∘ ren (liftₑ η)) M
sublift◑ σ η M = (λ σ′ → sub (σ′ , 0) M)
& comp◑◐ (wkₑ idₑ) σ η
⦙ sub◑ (liftₛ σ) (liftₑ η) M
--------------------------------------------------------------------------------
-- (∈-ₛ∘ₑ)
get◐ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (i : Ξ ∋ A)
→ getₛ (σ ◐ η) i ≡ (ren η ∘ getₛ σ) i
get◐ η (σ , M) zero = refl
get◐ η (σ , M) (suc i) = get◐ η σ i
-- (Tm-ₛ∘ₑ)
mutual
sub◐ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ ⊢ A)
→ sub (σ ◐ η) M ≡ (ren η ∘ sub σ) M
sub◐ η σ (𝓋 i) = get◐ η σ i
sub◐ η σ (ƛ M) = ƛ & sublift◐ η σ M
sub◐ η σ (M ∙ N) = _∙_ & sub◐ η σ M
⊗ sub◐ η σ N
sublift◐ : ∀ {Γ Γ′ Ξ A B} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ , B ⊢ A)
→ sub (liftₛ {B} (σ ◐ η)) M ≡
(ren (liftₑ η) ∘ sub (liftₛ σ)) M
sublift◐ η σ M = (λ σ′ → sub (σ′ , 0) M)
& ( comp◐○ (wkₑ idₑ) η σ
⦙ (σ ◐_) & (wkₑ & ( rid○ η
⦙ lid○ η ⁻¹
))
⦙ comp◐○ (liftₑ η) (wkₑ idₑ) σ ⁻¹
)
⦙ sub◐ (liftₑ η) (liftₛ σ) M
--------------------------------------------------------------------------------
-- (assₛₑₛ)
comp●◑ : ∀ {Γ Ξ Ξ′ Φ} → (σ₁ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (σ₂ : Ξ ⊢⋆ Φ)
→ (σ₂ ◐ η) ● σ₁ ≡ σ₂ ● (η ◑ σ₁)
comp●◑ σ₁ η ∅ = refl
comp●◑ σ₁ η (σ₂ , M) = _,_ & comp●◑ σ₁ η σ₂
⊗ (sub◑ σ₁ η M ⁻¹)
-- (assₛₛₑ)
comp●◐ : ∀ {Γ Γ′ Ξ Φ} → (η : Γ′ ⊇ Γ) (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ)
→ (σ₂ ● σ₁) ◐ η ≡ σ₂ ● (σ₁ ◐ η)
comp●◐ η σ₁ ∅ = refl
comp●◐ η σ₁ (σ₂ , M) = _,_ & comp●◐ η σ₁ σ₂
⊗ (sub◐ η σ₁ M ⁻¹)
--------------------------------------------------------------------------------
-- (∈-∘ₛ)
get● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (i : Φ ∋ A)
→ getₛ (σ₂ ● σ₁) i ≡ (sub σ₁ ∘ getₛ σ₂) i
get● σ₁ (σ₂ , M) zero = refl
get● σ₁ (σ₂ , M) (suc i) = get● σ₁ σ₂ i
-- (Tm-∘ₛ)
mutual
sub● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ ⊢ A)
→ sub (σ₂ ● σ₁) M ≡ (sub σ₁ ∘ sub σ₂) M
sub● σ₁ σ₂ (𝓋 i) = get● σ₁ σ₂ i
sub● σ₁ σ₂ (ƛ M) = ƛ & sublift● σ₁ σ₂ M
sub● σ₁ σ₂ (M ∙ N) = _∙_ & sub● σ₁ σ₂ M
⊗ sub● σ₁ σ₂ N
sublift● : ∀ {Γ Ξ Φ A B} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ , B ⊢ A)
→ sub (liftₛ {B} (σ₂ ● σ₁)) M ≡
(sub (liftₛ σ₁) ∘ sub (liftₛ σ₂)) M
sublift● σ₁ σ₂ M = (λ σ′ → sub (σ′ , 0) M)
& ( comp●◐ (wkₑ idₑ) σ₁ σ₂
⦙ (σ₂ ●_) & (lid◑ (wkₛ σ₁) ⁻¹)
⦙ comp●◑ (liftₛ σ₁) (wkₑ idₑ) σ₂ ⁻¹
)
⦙ sub● (liftₛ σ₁) (liftₛ σ₂) M
--------------------------------------------------------------------------------
-- (∈-idₛ)
idgetₛ : ∀ {Γ A} → (i : Γ ∋ A)
→ getₛ idₛ i ≡ 𝓋 i
idgetₛ zero = refl
idgetₛ (suc i) = get◐ (wkₑ idₑ) idₛ i
⦙ wk & idgetₛ i
⦙ 𝓋 ∘ suc & idgetₑ i
-- (Tm-idₛ)
idsub : ∀ {Γ A} → (M : Γ ⊢ A)
→ sub idₛ M ≡ M
idsub (𝓋 i) = idgetₛ i
idsub (ƛ M) = ƛ & idsub M
idsub (M ∙ N) = _∙_ & idsub M
⊗ idsub N
--------------------------------------------------------------------------------
-- (idrₛ)
rid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)
→ σ ● idₛ ≡ σ
rid● ∅ = refl
rid● (σ , M) = _,_ & rid● σ
⊗ idsub M
-- (idlₛ)
lid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)
→ idₛ ● σ ≡ σ
lid● ∅ = refl
lid● (σ , M) = (_, M) & ( comp●◑ (σ , M) (wkₑ idₑ) idₛ
⦙ lid● (idₑ ◑ σ)
⦙ lid◑ σ
)
-- (assₛ)
assoc● : ∀ {Γ Ξ Φ Ψ} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (σ₃ : Φ ⊢⋆ Ψ)
→ (σ₃ ● σ₂) ● σ₁ ≡ σ₃ ● (σ₂ ● σ₁)
assoc● σ₁ σ₂ ∅ = refl
assoc● σ₁ σ₂ (σ₃ , M) = _,_ & assoc● σ₁ σ₂ σ₃
⊗ (sub● σ₁ σ₂ M ⁻¹)
--------------------------------------------------------------------------------
𝗦𝗧𝗟𝗖 : Category 𝒞 _⊢⋆_
𝗦𝗧𝗟𝗖 =
record
{ idₓ = idₛ
; _⋄_ = _●_
; lid⋄ = lid●
; rid⋄ = rid●
; assoc⋄ = assoc●
}
subPsh : 𝒯 → Presheaf₀ 𝗦𝗧𝗟𝗖
subPsh A =
record
{ Fₓ = _⊢ A
; F = sub
; idF = fext! idsub
; F⋄ = λ σ₁ σ₂ → fext! (sub● σ₂ σ₁)
}
--------------------------------------------------------------------------------
| 28.156352
| 80
| 0.287367
|
397765a9f3b9bcde1a92a3afe4050b3502b87587
| 33,185
|
agda
|
Agda
|
Numbers/Naturals/EuclideanAlgorithm.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Numbers/Naturals/EuclideanAlgorithm.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Numbers/Naturals/EuclideanAlgorithm.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 Numbers.Naturals.Semiring
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Numbers.Naturals.Order.WellFounded
open import Orders.WellFounded.Induction
open import Orders.Total.Definition
open import Semirings.Definition
module Numbers.Naturals.EuclideanAlgorithm where
open TotalOrder ℕTotalOrder
open Semiring ℕSemiring
open import Decidable.Lemmas ℕDecideEquality
record divisionAlgResult (a : ℕ) (b : ℕ) : Set where
field
quot : ℕ
rem : ℕ
pr : a *N quot +N rem ≡ b
remIsSmall : (rem <N a) || (a ≡ 0)
quotSmall : (0 <N a) || ((0 ≡ a) && (quot ≡ 0))
record divisionAlgResult' (a : ℕ) (b : ℕ) : Set where
field
quot : ℕ
rem : ℕ
.pr : a *N quot +N rem ≡ b
remIsSmall : (rem <N' a) || (a =N' 0)
quotSmall : (0 <N' a) || ((0 =N' a) && (quot =N' 0))
collapseDivAlgResult : {a b : ℕ} → (divisionAlgResult a b) → divisionAlgResult' a b
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl y) } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inl (<NTo<N' x) ; quotSmall = inl (<NTo<N' y) }
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr y) } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inl (<NTo<N' x) ; quotSmall = inr (collapseN (_&&_.fst y) ,, collapseN (_&&_.snd y)) }
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inr x) ; quotSmall = inl y } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inr (collapseN x) ; quotSmall = inl (<NTo<N' y) }
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inr x) ; quotSmall = inr y } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inr (collapseN x) ; quotSmall = inr (collapseN (_&&_.fst y) ,, collapseN (_&&_.snd y)) }
squashDivAlgResult : {a b : ℕ} → divisionAlgResult' a b → divisionAlgResult a b
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inl (<N'To<N x) ; quotSmall = inl (<N'To<N y) }
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inl (<N'To<N x) ; quotSmall = inr (squashN (_&&_.fst y) ,, squashN (_&&_.snd y)) }
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inr (squashN x) ; quotSmall = inl (<N'To<N y) }
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inr (squashN x) ; quotSmall = inr (squashN (_&&_.fst y) ,, squashN (_&&_.snd y)) }
squashPreservesRem : {a b : ℕ} → (p : divisionAlgResult' a b) → divisionAlgResult.rem (squashDivAlgResult p) ≡ divisionAlgResult'.rem p
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
squashPreservesQuot : {a b : ℕ} → (p : divisionAlgResult' a b) → divisionAlgResult.quot (squashDivAlgResult p) ≡ divisionAlgResult'.quot p
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
collapsePreservesRem : {a b : ℕ} → (p : divisionAlgResult a b) → divisionAlgResult'.rem (collapseDivAlgResult p) ≡ divisionAlgResult.rem p
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
collapsePreservesQuot : {a b : ℕ} → (p : divisionAlgResult a b) → divisionAlgResult'.quot (collapseDivAlgResult p) ≡ divisionAlgResult.quot p
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
divAlgLessLemma : (a b : ℕ) → (0 <N a) → (r : divisionAlgResult a b) → (divisionAlgResult.quot r ≡ 0) || (divisionAlgResult.rem r <N b)
divAlgLessLemma zero b pr _ = exFalso (TotalOrder.irreflexive ℕTotalOrder pr)
divAlgLessLemma (succ a) b _ record { quot = zero ; rem = a%b ; pr = pr ; remIsSmall = remIsSmall } = inl refl
divAlgLessLemma (succ a) b _ record { quot = (succ a/b) ; rem = a%b ; pr = pr ; remIsSmall = remIsSmall } = inr record { x = a/b +N a *N succ (a/b) ; proof = pr }
modUniqueLemma : {rem1 rem2 a : ℕ} → (quot1 quot2 : ℕ) → rem1 <N a → rem2 <N a → a *N quot1 +N rem1 ≡ a *N quot2 +N rem2 → rem1 ≡ rem2
modUniqueLemma {rem1} {rem2} {a} zero zero rem1<a rem2<a pr rewrite Semiring.productZeroRight ℕSemiring a = pr
modUniqueLemma {rem1} {rem2} {a} zero (succ quot2) rem1<a rem2<a pr rewrite Semiring.productZeroRight ℕSemiring a | pr | multiplicationNIsCommutative a (succ quot2) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot2 *N a) rem2) = exFalso (cannotAddAndEnlarge' {a} {quot2 *N a +N rem2} rem1<a)
modUniqueLemma {rem1} {rem2} {a} (succ quot1) zero rem1<a rem2<a pr rewrite Semiring.productZeroRight ℕSemiring a | equalityCommutative pr | multiplicationNIsCommutative a (succ quot1) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot1 *N a) rem1) = exFalso (cannotAddAndEnlarge' {a} {quot1 *N a +N rem1} rem2<a)
modUniqueLemma {rem1} {rem2} {a} (succ quot1) (succ quot2) rem1<a rem2<a pr rewrite multiplicationNIsCommutative a (succ quot1) | multiplicationNIsCommutative a (succ quot2) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot1 *N a) rem1) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot2 *N a) rem2) = modUniqueLemma {rem1} {rem2} {a} quot1 quot2 rem1<a rem2<a (go {a}{quot1}{rem1}{quot2}{rem2} pr)
where
go : {a quot1 rem1 quot2 rem2 : ℕ} → (a +N (quot1 *N a +N rem1) ≡ a +N (quot2 *N a +N rem2)) → a *N quot1 +N rem1 ≡ a *N quot2 +N rem2
go {a} {quot1} {rem1} {quot2} {rem2} pr rewrite multiplicationNIsCommutative quot1 a | multiplicationNIsCommutative quot2 a = canSubtractFromEqualityLeft {a} pr
modIsUnique : {a b : ℕ} → (div1 div2 : divisionAlgResult a b) → divisionAlgResult.rem div1 ≡ divisionAlgResult.rem div2
modIsUnique {zero} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = remIsSmall1 } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall } = transitivity pr1 (equalityCommutative pr)
modIsUnique {succ a} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = (inl y) } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) } = modUniqueLemma {rem1} {rem} {succ a} quot1 quot y x (transitivity pr1 (equalityCommutative pr))
modIsUnique {succ a} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = (inr ()) } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) }
modIsUnique {succ a} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = remIsSmall1 } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr ()) }
transferAddition : (a b c : ℕ) → (a +N b) +N c ≡ (a +N c) +N b
transferAddition a b c rewrite equalityCommutative (Semiring.+Associative ℕSemiring a b c) = p a b c
where
p : (a b c : ℕ) → a +N (b +N c) ≡ (a +N c) +N b
p a b c = transitivity (applyEquality (a +N_) (Semiring.commutative ℕSemiring b c)) (Semiring.+Associative ℕSemiring a c b)
divisionAlgLemma : (x b : ℕ) → x *N zero +N b ≡ b
divisionAlgLemma x b rewrite (Semiring.productZeroRight ℕSemiring x) = refl
divisionAlgLemma2 : (x b : ℕ) → (x ≡ b) → x *N succ zero +N zero ≡ b
divisionAlgLemma2 x b pr rewrite (Semiring.productOneRight ℕSemiring x) = equalityCommutative (transitivity (equalityCommutative pr) (equalityCommutative (Semiring.sumZeroRight ℕSemiring x)))
divisionAlgLemma3 : {a x : ℕ} → (p : succ a <N succ x) → (subtractionNResult.result (-N (inl p))) <N (succ x)
divisionAlgLemma3 {a} {x} p = -NIsDecreasing {a} {succ x} p
divisionAlgLemma4 : (p a q : ℕ) → ((p +N a *N p) +N q) +N succ a ≡ succ ((p +N a *N succ p) +N q)
divisionAlgLemma4 p a q = ans
where
r : ((p +N a *N p) +N q) +N succ a ≡ succ (((p +N a *N p) +N q) +N a)
ans : ((p +N a *N p) +N q) +N succ a ≡ succ ((p +N a *N succ p) +N q)
s : ((p +N a *N p) +N q) +N a ≡ (p +N a *N succ p) +N q
t : (p +N a *N p) +N a ≡ p +N a *N succ p
s = transitivity (transferAddition (p +N a *N p) q a) (applyEquality (λ i → i +N q) t)
ans = identityOfIndiscernablesRight _≡_ r (applyEquality succ s)
r = succExtracts ((p +N a *N p) +N q) a
t = transitivity (equalityCommutative (Semiring.+Associative ℕSemiring p (a *N p) a)) (applyEquality (λ n → p +N n) (equalityCommutative (transitivity (multiplicationNIsCommutative a (succ p)) (transitivity (Semiring.commutative ℕSemiring a _) (applyEquality (_+N a) (multiplicationNIsCommutative p _))))))
divisionAlg : (a : ℕ) → (b : ℕ) → divisionAlgResult a b
divisionAlg zero = λ b → record { quot = zero ; rem = b ; pr = refl ; remIsSmall = inr refl ; quotSmall = inr (record { fst = refl ; snd = refl }) }
divisionAlg (succ a) = rec <NWellfounded (λ n → divisionAlgResult (succ a) n) go
where
go : (x : ℕ) (indHyp : (y : ℕ) (y<x : y <N x) → divisionAlgResult (succ a) y) →
divisionAlgResult (succ a) x
go zero prop = record { quot = zero ; rem = zero ; pr = divisionAlgLemma (succ a) zero ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }
go (succ x) indHyp with totality (succ a) (succ x)
go (succ x) indHyp | inl (inl sa<sx) with indHyp (subtractionNResult.result (-N (inl sa<sx))) (divisionAlgLemma3 sa<sx)
... | record { quot = prevQuot ; rem = prevRem ; pr = prevPr ; remIsSmall = smallRem } = p
where
p : divisionAlgResult (succ a) (succ x)
addedA : (succ a *N prevQuot +N prevRem) +N (succ a) ≡ subtractionNResult.result (-N (inl sa<sx)) +N (succ a)
addedA' : (succ a *N prevQuot +N prevRem) +N succ a ≡ succ x
addedA'' : (succ a *N succ prevQuot) +N prevRem ≡ succ x
addedA''' : succ ((prevQuot +N a *N succ prevQuot) +N prevRem) ≡ succ x
addedA''' = identityOfIndiscernablesLeft _≡_ addedA'' refl
p = record { quot = succ prevQuot ; rem = prevRem ; pr = addedA''' ; remIsSmall = smallRem ; quotSmall = inl (succIsPositive a) }
addedA = applyEquality (λ n → n +N succ a) prevPr
addedA' = identityOfIndiscernablesRight _≡_ addedA (addMinus {succ a} {succ x} (inl sa<sx))
addedA'' = identityOfIndiscernablesLeft _≡_ addedA' (divisionAlgLemma4 prevQuot a prevRem)
go (succ x) indHyp | inr (sa=sx) = record { quot = succ zero ; rem = zero ; pr = divisionAlgLemma2 (succ a) (succ x) sa=sx ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }
go (succ x) indHyp | inl (inr (sx<sa)) = record { quot = zero ; rem = succ x ; pr = divisionAlgLemma (succ a) (succ x) ; remIsSmall = inl sx<sa ; quotSmall = inl (succIsPositive a) }
data _∣_ : ℕ → ℕ → Set where
divides : {a b : ℕ} → (res : divisionAlgResult a b) → divisionAlgResult.rem res ≡ zero → a ∣ b
data _∣'_ : ℕ → ℕ → Set where
divides' : {a b : ℕ} → (res : divisionAlgResult' a b) → .(divisionAlgResult'.rem res ≡ zero) → a ∣' b
divToDiv' : {a b : ℕ} → a ∣ b → a ∣' b
divToDiv' (divides res x) = divides' (collapseDivAlgResult res) (transitivity (collapsePreservesRem res) x)
div'ToDiv : {a b : ℕ} → a ∣' b → a ∣ b
div'ToDiv (divides' res x) = divides (squashDivAlgResult res) (transitivity (squashPreservesRem res) (squashN record { eq = x }))
zeroDividesNothing : (a : ℕ) → zero ∣ succ a → False
zeroDividesNothing a (divides record { quot = quot ; rem = rem ; pr = pr } x) = naughtE p
where
p : zero ≡ succ a
p = transitivity (equalityCommutative x) pr
record hcfData (a b : ℕ) : Set where
field
c : ℕ
c|a : c ∣ a
c|b : c ∣ b
hcf : ∀ x → x ∣ a → x ∣ b → x ∣ c
positiveTimes : {a b : ℕ} → (succ a *N succ b <N succ a) → False
positiveTimes {a} {b} pr = zeroNeverGreater f'
where
g : succ a *N succ b <N succ a *N succ 0
g rewrite multiplicationNIsCommutative a 1 | Semiring.commutative ℕSemiring a 0 = pr
f : succ b <N succ 0
f = cancelInequalityLeft {succ a} {succ b} g
f' : b <N 0
f' = canRemoveSuccFrom<N f
biggerThanCantDivideLemma : {a b : ℕ} → (a <N b) → (b ∣ a) → a ≡ 0
biggerThanCantDivideLemma {zero} {b} a<b b|a = refl
biggerThanCantDivideLemma {succ a} {zero} a<b (divides record { quot = quot ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = (inl (le x ())) } refl)
biggerThanCantDivideLemma {succ a} {zero} a<b (divides record { quot = quot ; rem = .0 ; pr = () ; remIsSmall = remIsSmall ; quotSmall = (inr x) } refl)
biggerThanCantDivideLemma {succ a} {succ b} a<b (divides record { quot = zero ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.commutative ℕSemiring (b *N zero) 0 | multiplicationNIsCommutative b 0 = exFalso (naughtE pr)
biggerThanCantDivideLemma {succ a} {succ b} a<b (divides record { quot = (succ quot) ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.commutative ℕSemiring (quot +N b *N succ quot) 0 | equalityCommutative pr = exFalso (positiveTimes {b} {quot} a<b)
biggerThanCantDivide : {a b : ℕ} → (x : ℕ) → (TotalOrder.max ℕTotalOrder a b) <N x → (x ∣ a) → (x ∣ b) → (a ≡ 0) && (b ≡ 0)
biggerThanCantDivide {a} {b} x pr x|a x|b with totality a b
biggerThanCantDivide {a} {b} x pr x|a x|b | inl (inl a<b) = exFalso (zeroNeverGreater f')
where
f : b ≡ 0
f = biggerThanCantDivideLemma pr x|b
f' : a <N 0
f' rewrite equalityCommutative f = a<b
biggerThanCantDivide {a} {b} x pr x|a x|b | inl (inr b<a) = exFalso (zeroNeverGreater f')
where
f : a ≡ 0
f = biggerThanCantDivideLemma pr x|a
f' : b <N 0
f' rewrite equalityCommutative f = b<a
biggerThanCantDivide {a} {b} x pr x|a x|b | inr a=b = (transitivity a=b f ,, f)
where
f : b ≡ 0
f = biggerThanCantDivideLemma pr x|b
aDivA : (a : ℕ) → a ∣ a
aDivA zero = divides (record { quot = 0 ; rem = 0 ; pr = equalityCommutative (oneTimesPlusZero zero) ; remIsSmall = inr refl ; quotSmall = inr (refl ,, refl) }) refl
aDivA (succ a) = divides (record { quot = 1 ; rem = 0 ; pr = equalityCommutative (oneTimesPlusZero (succ a)) ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }) refl
aDivZero : (a : ℕ) → a ∣ zero
aDivZero zero = aDivA zero
aDivZero (succ a) = divides (record { quot = zero ; rem = zero ; pr = lemma (succ a) ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }) refl
where
lemma : (b : ℕ) → b *N zero +N zero ≡ zero
lemma b rewrite (Semiring.sumZeroRight ℕSemiring (b *N zero)) = Semiring.productZeroRight ℕSemiring b
record extendedHcf (a b : ℕ) : Set where
field
hcf : hcfData a b
c : ℕ
c = hcfData.c hcf
field
extended1 : ℕ
extended2 : ℕ
extendedProof : (a *N extended1 ≡ b *N extended2 +N c) || (a *N extended1 +N c ≡ b *N extended2)
divEqualityLemma1 : {a b c : ℕ} → b ≡ zero → b *N c +N 0 ≡ a → a ≡ b
divEqualityLemma1 {a} {.0} {c} refl pr = equalityCommutative pr
divEquality : {a b : ℕ} → a ∣ b → b ∣ a → a ≡ b
divEquality {a} {b} (divides record { quot = quotAB ; rem = .0 ; pr = prAB ; remIsSmall = _ ; quotSmall = quotSmallAB } refl) (divides record { quot = quot ; rem = .0 ; pr = pr ; remIsSmall = _ ; quotSmall = (inl x) } refl) rewrite Semiring.commutative ℕSemiring (b *N quot) 0 | Semiring.commutative ℕSemiring (a *N quotAB) 0 | equalityCommutative pr | equalityCommutative (Semiring.*Associative ℕSemiring b quot quotAB) = res
where
lem : {b r : ℕ} → b *N r ≡ b → (0 <N b) → r ≡ 1
lem {zero} {r} pr ()
lem {succ b} {zero} pr _ rewrite multiplicationNIsCommutative b 0 = exFalso (naughtE pr)
lem {succ b} {succ zero} pr _ = refl
lem {succ b} {succ (succ r)} pr _ rewrite multiplicationNIsCommutative b (succ (succ r)) | Semiring.commutative ℕSemiring (succ r) (b +N (b +N r *N b)) | equalityCommutative (Semiring.+Associative ℕSemiring b (b +N r *N b) (succ r)) | Semiring.commutative ℕSemiring (b +N r *N b) (succ r) = exFalso (cannotAddAndEnlarge'' {succ b} pr)
p : quot *N quotAB ≡ 1
p = lem prAB x
q : quot ≡ 1
q = _&&_.fst (productOneImpliesOperandsOne p)
res : b *N quot ≡ b
res rewrite q | multiplicationNIsCommutative b 1 | Semiring.commutative ℕSemiring b 0 = refl
divEquality {.0} {.0} (divides record { quot = quotAB ; rem = .0 ; pr = prAB ; remIsSmall = _ ; quotSmall = quotSmallAB } refl) (divides record { quot = quot ; rem = .0 ; pr = refl ; remIsSmall = _ ; quotSmall = (inr (refl ,, snd)) } refl) = refl
hcfWelldefined : {a b : ℕ} → (ab : hcfData a b) → (ab' : hcfData a b) → (hcfData.c ab ≡ hcfData.c ab')
hcfWelldefined {a} {b} record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } record { c = c' ; c|a = c|a' ; c|b = c|b' ; hcf = hcf' } with hcf c' c|a' c|b'
... | c'DivC with hcf' c c|a c|b
... | cDivC' = divEquality cDivC' c'DivC
reverseHCF : {a b : ℕ} → (ab : extendedHcf a b) → extendedHcf b a
reverseHCF {a} {b} record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = (inl x) } = record { hcf = record { c = c ; c|a = c|b ; c|b = c|a ; hcf = λ x z z₁ → hcf x z₁ z } ; extended1 = extended2 ; extended2 = extended1 ; extendedProof = inr (equalityCommutative x) }
reverseHCF {a} {b} record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = (inr x) } = record { hcf = record { c = c ; c|a = c|b ; c|b = c|a ; hcf = λ x z z₁ → hcf x z₁ z } ; extended1 = extended2 ; extended2 = extended1 ; extendedProof = inl (equalityCommutative x) }
oneDivN : (a : ℕ) → 1 ∣ a
oneDivN a = divides (record { quot = a ; rem = zero ; pr = pr ; remIsSmall = inl (succIsPositive zero) ; quotSmall = inl (le zero refl) }) refl
where
pr : (a +N zero) +N zero ≡ a
pr rewrite Semiring.sumZeroRight ℕSemiring (a +N zero) = Semiring.sumZeroRight ℕSemiring a
hcfZero : (a : ℕ) → extendedHcf zero a
hcfZero a = record { hcf = record { c = a ; c|a = aDivZero a ; c|b = aDivA a ; hcf = λ _ _ p → p } ; extended1 = 0 ; extended2 = 1 ; extendedProof = inr (equalityCommutative (Semiring.productOneRight ℕSemiring a))}
hcfOne : (a : ℕ) → extendedHcf 1 a
hcfOne a = record { hcf = record { c = 1 ; c|a = aDivA 1 ; c|b = oneDivN a ; hcf = λ _ z _ → z } ; extended1 = 1 ; extended2 = 0 ; extendedProof = inl g }
where
g : 1 ≡ a *N 0 +N 1
g rewrite multiplicationNIsCommutative a 0 = refl
zeroIsValidRem : (a : ℕ) → (0 <N a) || (a ≡ 0)
zeroIsValidRem zero = inr refl
zeroIsValidRem (succ a) = inl (succIsPositive a)
dividesBothImpliesDividesSum : {a x y : ℕ} → a ∣ x → a ∣ y → a ∣ (x +N y)
dividesBothImpliesDividesSum {a} {x} {y} (divides record { quot = xDivA ; rem = .0 ; pr = prA ; quotSmall = qsm1 } refl) (divides record { quot = quot ; rem = .0 ; pr = pr ; quotSmall = qsm2 } refl) = divides (record { quot = xDivA +N quot ; rem = 0 ; pr = go {a} {x} {y} {xDivA} {quot} pr prA ; remIsSmall = zeroIsValidRem a ; quotSmall = (quotSmall qsm1 qsm2) }) refl
where
go : {a x y quot quot2 : ℕ} → (a *N quot2 +N zero ≡ y) → (a *N quot +N zero ≡ x) → a *N (quot +N quot2) +N zero ≡ x +N y
go {a} {x} {y} {quot} {quot2} pr1 pr2 rewrite Semiring.sumZeroRight ℕSemiring (a *N quot) = identityOfIndiscernablesLeft _≡_ t (equalityCommutative (Semiring.sumZeroRight ℕSemiring (a *N (quot +N quot2))))
where
t : a *N (quot +N quot2) ≡ x +N y
t rewrite Semiring.sumZeroRight ℕSemiring (a *N quot2) = transitivity (Semiring.+DistributesOver* ℕSemiring a quot quot2) p
where
s : a *N quot +N a *N quot2 ≡ x +N a *N quot2
s = applyEquality (λ n → n +N a *N quot2) pr2
r : x +N a *N quot2 ≡ x +N y
r = applyEquality (λ n → x +N n) pr1
p : a *N quot +N a *N quot2 ≡ x +N y
p = transitivity s r
quotSmall : ((0 <N a) || ((0 ≡ a) && (xDivA ≡ 0))) → ((0 <N a) || ((0 ≡ a) && (quot ≡ 0))) → (0 <N a) || ((0 ≡ a) && (xDivA +N quot ≡ 0))
quotSmall (inl x1) (inl x2) = inl x1
quotSmall (inl x1) (inr x2) = inl x1
quotSmall (inr x1) (inl x2) = inl x2
quotSmall (inr (a=0 ,, bl)) (inr (_ ,, bl2)) = inr (a=0 ,, ans)
where
ans : xDivA +N quot ≡ 0
ans rewrite bl | bl2 = refl
dividesBothImpliesDividesDifference : {a b c : ℕ} → a ∣ b → a ∣ c → (c<b : c <N b) → a ∣ (subtractionNResult.result (-N (inl c<b)))
dividesBothImpliesDividesDifference {zero} {b} {.0} prab (divides record { quot = quot ; rem = .0 ; pr = refl } refl) c<b = prab
dividesBothImpliesDividesDifference {succ a} {b} {c} (divides record { quot = bDivSA ; rem = .0 ; pr = pr } refl) (divides record { quot = cDivSA ; rem = .0 ; pr = pr2 } refl) c<b rewrite (Semiring.sumZeroRight ℕSemiring (succ a *N cDivSA)) | (Semiring.sumZeroRight ℕSemiring (succ a *N bDivSA)) = divides (record { quot = subtractionNResult.result bDivSA-cDivSA ; rem = 0 ; pr = identityOfIndiscernablesLeft _≡_ (identityOfIndiscernablesLeft _≡_ s (equalityCommutative q)) (equalityCommutative (Semiring.sumZeroRight ℕSemiring _)) ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }) refl
where
p : cDivSA <N bDivSA
p rewrite (equalityCommutative pr2) | (equalityCommutative pr) = cancelInequalityLeft {succ a} {cDivSA} {bDivSA} c<b
bDivSA-cDivSA : subtractionNResult cDivSA bDivSA (inl p)
bDivSA-cDivSA = -N {cDivSA} {bDivSA} (inl p)
la-ka = subtractionNResult.result (-N {succ a *N cDivSA} {succ a *N bDivSA} (inl (lessRespectsMultiplicationLeft cDivSA bDivSA (succ a) p (succIsPositive a))))
q : (succ a *N (subtractionNResult.result bDivSA-cDivSA)) ≡ la-ka
q = subtractProduct {succ a} {cDivSA} {bDivSA} (succIsPositive a) p
s : la-ka ≡ subtractionNResult.result (-N {c} {b} (inl c<b))
s = equivalentSubtraction (succ a *N cDivSA) b (succ a *N bDivSA) c (lessRespectsMultiplicationLeft cDivSA bDivSA (succ a) p (succIsPositive a)) c<b g
where
g : (succ a *N cDivSA) +N b ≡ (succ a *N bDivSA) +N c
g rewrite equalityCommutative pr2 | equalityCommutative pr = Semiring.commutative ℕSemiring (cDivSA +N a *N cDivSA) (bDivSA +N a *N bDivSA)
euclidLemma1 : {a b : ℕ} → (a<b : a <N b) → (t : ℕ) → a +N b <N t → a +N (subtractionNResult.result (-N (inl a<b))) <N t
euclidLemma1 {zero} {b} zero<b t b<t = b<t
euclidLemma1 {succ a} {b} sa<b t sa+b<t = identityOfIndiscernablesLeft _<N_ q (Semiring.commutative ℕSemiring (subtractionNResult.result (-N (inl sa<b))) (succ a))
where
p : b <N t
p = TotalOrder.<Transitive ℕTotalOrder (le a refl) sa+b<t
q : (subtractionNResult.result (-N (inl sa<b))) +N succ a <N t
q = identityOfIndiscernablesLeft _<N_ p (equalityCommutative (addMinus (inl sa<b)))
euclidLemma2 : {a b max : ℕ} → (succ (a +N b) <N max) → b <N max
euclidLemma2 {a} {b} {max} pr = lessTransitive {b} {succ (a +N b)} {max} (lemma a b) pr
where
lemma : (a b : ℕ) → b <N succ (a +N b)
lemma a b rewrite Semiring.commutative ℕSemiring (succ a) b = addingIncreases b a
euclidLemma3 : {a b max : ℕ} → (succ (succ (a +N b)) <N max) → succ b <N max
euclidLemma3 {a} {b} {max} pr = euclidLemma2 {a} {succ b} {max} (identityOfIndiscernablesLeft _<N_ pr (applyEquality succ (equalityCommutative (succExtracts a b))))
euclidLemma4 : (a b c d h : ℕ) → (sa<b : (succ a) <N b) → (pr : subtractionNResult.result (-N (inl sa<b)) *N c ≡ (succ a) *N d +N h) → b *N c ≡ (succ a) *N (d +N c) +N h
euclidLemma4 a b zero d h sa<b pr rewrite Semiring.sumZeroRight ℕSemiring d | Semiring.productZeroRight ℕSemiring b | Semiring.productZeroRight ℕSemiring (subtractionNResult.result (-N (inl sa<b))) = pr
euclidLemma4 a b (succ c) d h sa<b pr rewrite subtractProduct' (succIsPositive c) sa<b = transitivity q' r'
where
q : (succ c) *N b ≡ succ (a +N c *N succ a) +N ((succ a) *N d +N h)
q = moveOneSubtraction {succ (a +N c *N succ a)} {b +N c *N b} {(succ a) *N d +N h} {inl _} pr
q' : b *N succ c ≡ succ (a +N c *N succ a) +N ((succ a) *N d +N h)
q' rewrite multiplicationNIsCommutative b (succ c) = q
r' : ((succ c) *N succ a) +N (((succ a) *N d) +N h) ≡ ((succ a) *N (d +N succ c)) +N h
r' rewrite Semiring.+Associative ℕSemiring ((succ c) *N succ a) ((succ a) *N d) h = applyEquality (λ t → t +N h) {((succ c) *N succ a) +N ((succ a) *N d)} {(succ a) *N (d +N succ c)} (go (succ c) (succ a) d)
where
go' : (a b c : ℕ) → b *N a +N b *N c ≡ b *N (c +N a)
go : (a b c : ℕ) → a *N b +N b *N c ≡ b *N (c +N a)
go a b c rewrite multiplicationNIsCommutative a b = go' a b c
go' a b c rewrite Semiring.commutative ℕSemiring (b *N a) (b *N c) = equalityCommutative (Semiring.+DistributesOver* ℕSemiring b c a)
euclidLemma5 : (a b c d h : ℕ) → (sa<b : (succ a) <N b) → (pr : subtractionNResult.result (-N (inl sa<b)) *N c +N h ≡ (succ a) *N d) → (succ a) *N (d +N c) ≡ b *N c +N h
euclidLemma5 a b c d h sa<b pr with (-N (inl sa<b))
euclidLemma5 a b zero d h sa<b pr | record { result = result ; pr = sub } rewrite Semiring.sumZeroRight ℕSemiring d | Semiring.productZeroRight ℕSemiring b | Semiring.productZeroRight ℕSemiring result = equalityCommutative pr
euclidLemma5 a b (succ c) d h sa<b pr | record { result = result ; pr = sub } rewrite subtractProduct' (succIsPositive c) sa<b | equalityCommutative sub = pv''
where
p : succ a *N d ≡ result *N succ c +N h
p = equalityCommutative pr
p' : a *N succ c +N succ a *N d ≡ (a *N succ c) +N ((result *N succ c) +N h)
p' = applyEquality (λ t → a *N succ c +N t) p
p'' : a *N succ c +N succ a *N d ≡ (a *N succ c +N result *N succ c) +N h
p'' rewrite equalityCommutative (Semiring.+Associative ℕSemiring (a *N succ c) (result *N succ c) h) = p'
p''' : a *N succ c +N succ a *N d ≡ (a +N result) *N succ c +N h
p''' rewrite multiplicationNIsCommutative (a +N result) (succ c) | Semiring.+DistributesOver* ℕSemiring (succ c) a result | multiplicationNIsCommutative (succ c) a | multiplicationNIsCommutative (succ c) result = p''
pv : c +N (a *N succ c +N succ a *N d) ≡ (c +N (a +N result) *N succ c) +N h
pv rewrite equalityCommutative (Semiring.+Associative ℕSemiring c ((a +N result) *N succ c) h) = applyEquality (λ t → c +N t) p'''
pv' : (succ c) +N (a *N succ c +N succ a *N d) ≡ succ ((c +N (a +N result) *N succ c) +N h)
pv' = applyEquality succ pv
pv'' : (succ a) *N (d +N succ c) ≡ succ ((c +N (a +N result) *N succ c) +N h)
pv'' = identityOfIndiscernablesLeft _≡_ pv' (go a c d)
where
go : (a c d : ℕ) → (succ c) +N (a *N succ c +N ((succ a) *N d)) ≡ (succ a) *N (d +N succ c)
go a c d rewrite Semiring.+Associative ℕSemiring (succ c) (a *N succ c) ((succ a) *N d) = go'
where
go' : (succ a) *N (succ c) +N (succ a) *N d ≡ (succ a) *N (d +N succ c)
go' rewrite Semiring.commutative ℕSemiring d (succ c) = equalityCommutative (Semiring.+DistributesOver* ℕSemiring (succ a) (succ c) d)
euclid : (a b : ℕ) → extendedHcf a b
euclid a b = inducted (succ a +N b) a b (a<SuccA (a +N b))
where
P : ℕ → Set
P sum = ∀ (a b : ℕ) → a +N b <N sum → extendedHcf a b
go'' : {a b : ℕ} → (maxsum : ℕ) → (a <N b) → (a +N b <N maxsum) → (∀ y → y <N maxsum → P y) → extendedHcf a b
go'' {zero} {b} maxSum zero<b b<maxsum indHyp = hcfZero b
go'' {1} {b} maxSum 1<b b<maxsum indHyp = hcfOne b
go'' {succ (succ a)} {b} maxSum ssa<b ssa+b<maxsum indHyp with (indHyp (succ b) (euclidLemma3 {a} {b} {maxSum} ssa+b<maxsum)) (subtractionNResult.result (-N (inl ssa<b))) (succ (succ a)) (identityOfIndiscernablesLeft _<N_ (a<SuccA b) (equalityCommutative (addMinus (inl ssa<b))))
go'' {succ (succ a)} {b} maxSum ssa<b ssa+b<maxsum indHyp | record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = inl extendedProof } = record { hcf = record { c = c ; c|a = c|b ; c|b = hcfDivB'' ; hcf = λ div prDivSSA prDivB → hcf div (dividesBothImpliesDividesDifference prDivB prDivSSA ssa<b) prDivSSA } ; extended2 = extended1; extended1 = extended2 +N extended1 ; extendedProof = inr (equalityCommutative (euclidLemma4 (succ a) b extended1 extended2 c ssa<b extendedProof)) }
where
hcfDivB : c ∣ ((succ (succ a)) +N (subtractionNResult.result (-N (inl ssa<b))))
hcfDivB = dividesBothImpliesDividesSum {c} {succ (succ a)} { subtractionNResult.result (-N (inl ssa<b))} c|b c|a
hcfDivB' : c ∣ ((subtractionNResult.result (-N (inl ssa<b))) +N (succ (succ a)))
hcfDivB' = identityOfIndiscernablesRight _∣_ hcfDivB (Semiring.commutative ℕSemiring (succ (succ a)) ( subtractionNResult.result (-N (inl ssa<b))))
hcfDivB'' : c ∣ b
hcfDivB'' = identityOfIndiscernablesRight _∣_ hcfDivB' (addMinus (inl ssa<b))
go'' {succ (succ a)} {b} maxSum ssa<b ssa+b<maxsum indHyp | record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = inr extendedProof } = record { hcf = record { c = c ; c|a = c|b ; c|b = hcfDivB'' ; hcf = λ div prDivSSA prDivB → hcf div (dividesBothImpliesDividesDifference prDivB prDivSSA ssa<b) prDivSSA } ; extended2 = extended1; extended1 = extended2 +N extended1 ; extendedProof = inl (euclidLemma5 (succ a) b extended1 extended2 c ssa<b extendedProof) }
where
hcfDivB : c ∣ ((succ (succ a)) +N (subtractionNResult.result (-N (inl ssa<b))))
hcfDivB = dividesBothImpliesDividesSum {c} {succ (succ a)} { subtractionNResult.result (-N (inl ssa<b))} c|b c|a
hcfDivB' : c ∣ ((subtractionNResult.result (-N (inl ssa<b))) +N (succ (succ a)))
hcfDivB' = identityOfIndiscernablesRight _∣_ hcfDivB (Semiring.commutative ℕSemiring (succ (succ a)) (subtractionNResult.result (-N (inl ssa<b))))
hcfDivB'' : c ∣ b
hcfDivB'' = identityOfIndiscernablesRight _∣_ hcfDivB' (addMinus (inl ssa<b))
go' : (maxSum a b : ℕ) → (a +N b <N maxSum) → (∀ y → y <N maxSum → P y) → extendedHcf a b
go' maxSum a b a+b<maxsum indHyp with totality a b
go' maxSum a b a+b<maxsum indHyp | inl (inl a<b) = go'' maxSum a<b a+b<maxsum indHyp
go' maxSum a b a+b<maxsum indHyp | inl (inr b<a) = reverseHCF (go'' maxSum b<a (identityOfIndiscernablesLeft _<N_ a+b<maxsum (Semiring.commutative ℕSemiring a b)) indHyp)
go' maxSum a .a _ indHyp | inr refl = record { hcf = record { c = a ; c|a = aDivA a ; c|b = aDivA a ; hcf = λ _ _ z → z } ; extended1 = 0 ; extended2 = 1 ; extendedProof = inr s}
where
s : a *N zero +N a ≡ a *N 1
s rewrite multiplicationNIsCommutative a zero | Semiring.productOneRight ℕSemiring a = refl
go : ∀ x → (∀ y → y <N x → P y) → P x
go maxSum indHyp = λ a b a+b<maxSum → go' maxSum a b a+b<maxSum indHyp
inducted : ∀ x → P x
inducted = rec <NWellfounded P go
divOneImpliesOne : {a : ℕ} → a ∣ 1 → a ≡ 1
divOneImpliesOne {zero} a|1 = exFalso (zeroDividesNothing _ a|1)
divOneImpliesOne {succ zero} a|1 = refl
divOneImpliesOne {succ (succ a)} (divides record { quot = zero ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.sumZeroRight ℕSemiring (a *N zero) | multiplicationNIsCommutative a 0 = exFalso (naughtE pr)
divOneImpliesOne {succ (succ a)} (divides record { quot = (succ quot) ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.commutative ℕSemiring quot (succ (quot +N a *N succ quot)) = exFalso (naughtE (equalityCommutative (succInjective pr)))
| 79.771635
| 614
| 0.63598
|
c71f7187418d5a8cfadb398adc1e6f6439e39e28
| 2,595
|
agda
|
Agda
|
Definition/Typed/Consequences/Reduction.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 30
|
2017-05-20T03:05:21.000Z
|
2022-03-30T18:01:07.000Z
|
Definition/Typed/Consequences/Reduction.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 4
|
2017-06-22T12:49:23.000Z
|
2021-02-22T10:37:24.000Z
|
Definition/Typed/Consequences/Reduction.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 8
|
2017-10-18T14:18:20.000Z
|
2021-11-27T15:58:33.000Z
|
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Consequences.Reduction where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.Typed.Consequences.Syntactic
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Tools.Nat
open import Tools.Product
private
variable
n : Nat
Γ : Con Term n
-- Helper function where all reducible types can be reduced to WHNF.
whNorm′ : ∀ {A l} ([A] : Γ ⊩⟨ l ⟩ A)
→ ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B
whNorm′ (Uᵣ′ .⁰ 0<1 ⊢Γ) = U , Uₙ , idRed:*: (Uⱼ ⊢Γ)
whNorm′ (ℕᵣ D) = ℕ , ℕₙ , D
whNorm′ (Emptyᵣ D) = Empty , Emptyₙ , D
whNorm′ (Unitᵣ D) = Unit , Unitₙ , D
whNorm′ (ne′ K D neK K≡K) = K , ne neK , D
whNorm′ (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = Π F ▹ G , Πₙ , D
whNorm′ (Σᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = Σ F ▹ G , Σₙ , D
whNorm′ (emb 0<1 [A]) = whNorm′ [A]
-- Well-formed types can all be reduced to WHNF.
whNorm : ∀ {A} → Γ ⊢ A → ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B
whNorm A = whNorm′ (reducible A)
-- Helper function where reducible all terms can be reduced to WHNF.
whNormTerm′ : ∀ {a A l} ([A] : Γ ⊩⟨ l ⟩ A) → Γ ⊩⟨ l ⟩ a ∷ A / [A]
→ ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A
whNormTerm′ (Uᵣ x) (Uₜ A d typeA A≡A [t]) = A , typeWhnf typeA , d
whNormTerm′ (ℕᵣ x) (ℕₜ n d n≡n prop) =
let natN = natural prop
in n , naturalWhnf natN , convRed:*: d (sym (subset* (red x)))
whNormTerm′ (Emptyᵣ x) (Emptyₜ n d n≡n prop) =
let emptyN = empty prop
in n , ne emptyN , convRed:*: d (sym (subset* (red x)))
whNormTerm′ (Unitᵣ x) (Unitₜ n d prop) =
n , prop , convRed:*: d (sym (subset* (red x)))
whNormTerm′ (ne (ne K D neK K≡K)) (neₜ k d (neNfₜ neK₁ ⊢k k≡k)) =
k , ne neK₁ , convRed:*: d (sym (subset* (red D)))
whNormTerm′ (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) =
f , functionWhnf funcF , convRed:*: d (sym (subset* (red D)))
whNormTerm′ (Σᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Σₜ p d pProd p≡p [fst] [snd]) =
p , productWhnf pProd , convRed:*: d (sym (subset* (red D)))
whNormTerm′ (emb 0<1 [A]) [a] = whNormTerm′ [A] [a]
-- Well-formed terms can all be reduced to WHNF.
whNormTerm : ∀ {a A} → Γ ⊢ a ∷ A → ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A
whNormTerm {a} {A} ⊢a =
let [A] , [a] = reducibleTerm ⊢a
in whNormTerm′ [A] [a]
redMany : ∀ {t u A} → Γ ⊢ t ⇒ u ∷ A → Γ ⊢ t ⇒* u ∷ A
redMany d =
let _ , _ , ⊢u = syntacticEqTerm (subsetTerm d)
in d ⇨ id ⊢u
| 38.161765
| 80
| 0.593834
|
41f95bfc3af1b5cbac34979aa5f1089da0c47191
| 3,862
|
agda
|
Agda
|
Structure/Category/Monad/Category.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Category/Monad/Category.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Category/Monad/Category.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
open import Structure.Category
open import Type
module Structure.Category.Monad.Category
{ℓₒ ℓₘ ℓₑ}
{cat : CategoryObject{ℓₒ}{ℓₘ}{ℓₑ}}
where
import Data.Tuple as Tuple
import Function.Equals
open Function.Equals.Dependent
import Lvl
open import Structure.Category.Functor
open import Structure.Category.Monad{cat = cat}
open import Structure.Category.Monad.ExtensionSystem{cat = cat}
open import Structure.Categorical.Properties
open import Structure.Function
open import Structure.Operator
open import Structure.Relator.Equivalence
open import Structure.Setoid
open import Syntax.Transitivity
open CategoryObject(cat)
open Category.ArrowNotation(category)
open Category(category)
private open module MorphismEquiv {x}{y} = Equivalence (Equiv-equivalence ⦃ morphism-equiv{x}{y} ⦄) using ()
module _ (T : Object → Object) ⦃ extSys : ExtensionSystem(T) ⦄ where
open ExtensionSystem(extSys)
open Functor(functor)
open Monad ⦃ functor ⦄ (monad) using (μ-functor-[∘]-identityₗ)
-- Also called: Kleisli category
categoryₑₓₜ : Category(\x y → (x ⟶ T(y)))
Category._∘_ categoryₑₓₜ = _∘ₑₓₜ_
Category.id categoryₑₓₜ = idₑₓₜ
BinaryOperator.congruence (Category.binaryOperator categoryₑₓₜ {x}{y}{z}) {f₁}{f₂} {g₁}{g₂} f₁f₂ g₁g₂ =
f₁ ∘ₑₓₜ g₁ 🝖[ _≡_ ]-[]
ext f₁ ∘ g₁ 🝖[ _≡_ ]-[ congruence₂(_∘_) (congruence₁(ext) f₁f₂) g₁g₂ ]
ext f₂ ∘ g₂ 🝖[ _≡_ ]-[]
f₂ ∘ₑₓₜ g₂ 🝖-end
Morphism.Associativity.proof (Category.associativity categoryₑₓₜ) {x} {y} {z} {w} {f} {g} {h} =
(f ∘ₑₓₜ g) ∘ₑₓₜ h 🝖[ _≡_ ]-[]
ext(ext(f) ∘ g) ∘ h 🝖[ _≡_ ]-[ congruence₂ₗ(_∘_)(_) ext-distribute ]
(ext(f) ∘ ext(g)) ∘ h 🝖[ _≡_ ]-[ Morphism.associativity(_∘_) ]
ext(f) ∘ (ext(g) ∘ h) 🝖[ _≡_ ]-[]
f ∘ₑₓₜ (g ∘ₑₓₜ h) 🝖-end
Morphism.Identityₗ.proof (Tuple.left (Category.identity categoryₑₓₜ)) {x} {y} {f} =
idₑₓₜ ∘ₑₓₜ f 🝖[ _≡_ ]-[]
ext(η(y)) ∘ f 🝖[ _≡_ ]-[ congruence₂ₗ(_∘_)(f) ext-inverse ]
id ∘ f 🝖[ _≡_ ]-[ Morphism.identityₗ(_∘_)(id) ]
f 🝖-end
Morphism.Identityᵣ.proof (Tuple.right (Category.identity categoryₑₓₜ)) {x} {y} {f} =
f ∘ₑₓₜ idₑₓₜ 🝖[ _≡_ ]-[]
ext(f) ∘ η(x) 🝖[ _≡_ ]-[ ext-identity ]
f 🝖-end
module _ (T : Object → Object) ⦃ functor : Functor(category)(category)(T) ⦄ ⦃ monad : Monad(T) ⦄ where
open Functor(functor)
open Monad(monad) hiding (ext)
open ExtensionSystem(monad-to-extensionSystem) hiding (η ; μ)
-- Note: This is the supposed to be the same as categoryₑₓₜ but proven from a monad directly.
monad-category : Category(\x y → (x ⟶ T(y)))
Category._∘_ monad-category f g = ext(f) ∘ g
Category.id monad-category {x} = η(x)
BinaryOperator.congruence (Category.binaryOperator monad-category {x}{y}{z}) {f₁}{f₂} {g₁}{g₂} f₁f₂ g₁g₂ =
ext(f₁) ∘ g₁ 🝖[ _≡_ ]-[]
(μ(z) ∘ map f₁) ∘ g₁ 🝖-[ Morphism.associativity(_∘_) ]
μ(z) ∘ (map f₁ ∘ g₁) 🝖-[ congruence₂ᵣ(_∘_)(μ(z)) (congruence₂(_∘_) (congruence₁(map) f₁f₂) g₁g₂) ]
μ(z) ∘ (map f₂ ∘ g₂) 🝖-[ Morphism.associativity(_∘_) ]-sym
(μ(z) ∘ map f₂) ∘ g₂ 🝖[ _≡_ ]-[]
ext(f₂) ∘ g₂ 🝖-end
Morphism.Associativity.proof (Category.associativity monad-category) {x} {y} {z} {w} {f} {g} {h} =
ext(ext(f) ∘ g) ∘ h 🝖-[ congruence₂ₗ(_∘_)(_) (ext-distribute) ]
(ext(f) ∘ ext(g)) ∘ h 🝖-[ Morphism.associativity(_∘_) ]
ext(f) ∘ (ext(g) ∘ h) 🝖-end
Morphism.Identityₗ.proof (Tuple.left (Category.identity monad-category)) {x} {y} {f} =
ext(η(y)) ∘ f 🝖[ _≡_ ]-[]
(μ(y) ∘ map(η(y))) ∘ f 🝖-[ congruence₂ₗ(_∘_)(f) (_⊜_.proof μ-functor-[∘]-identityₗ) ]
id ∘ f 🝖-[ Morphism.identityₗ(_∘_)(id) ]
f 🝖-end
Morphism.Identityᵣ.proof (Tuple.right (Category.identity monad-category)) {x} {y} {f} = ext-identity
| 45.97619
| 108
| 0.608752
|
31e6184cf1c46b422afb176373a3e5089f14bf9d
| 8
|
agda
|
Agda
|
test/interaction/HighlightMissingDefinition.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/HighlightMissingDefinition.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/HighlightMissingDefinition.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
A : Set
| 4
| 7
| 0.5
|
50cc4fb1407599a4a1d7aff5802a222c66bc8207
| 467
|
agda
|
Agda
|
test/Succeed/Issue2858-with.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2858-with.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2858-with.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Builtin.Nat
interleaved mutual
plus : Nat → Nat → Nat
mult : Nat → Nat → Nat
-- base case
mult 0 n = 0
plus 0 n = n
-- inductive case. The fun clauses with an ellipsis belong to mult
mult (suc m) n with mult m n
... | p with plus p n
... | q = q
plus (suc m) n = suc (plus m n)
open import Agda.Builtin.Equality
proof : ∀ m n → mult (suc m) n ≡ plus (mult m n) n
proof m n with mult m n
... | p with plus p n
... | q = refl
| 19.458333
| 68
| 0.599572
|
3d8bda788ae07461d412ebbe0c11e4a2757a5986
| 1,037
|
agda
|
Agda
|
test/succeed/Issue480.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/succeed/Issue480.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Issue480.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module Issue480 where
module Simple where
data Q : Set where
a : Q
f : _ → Q
f a = a
postulate helper : ∀ {T : Set} → (T → T) → Q
test₁ : Q → Q
test₁ = λ { a → a }
test₂ : Q
test₂ = helper test₁
-- Same as test₂ and test₁, but stuck together.
test₃ : Q
test₃ = helper λ { a → a } -- this says "Type mismatch when checking that the pattern a has type _45"
module Example where
infixr 5 _∷_
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
data List : Set₁ where
[] : List
_∷_ : Set → List → List
data Tree (L : Set) : List → Set₁ where
tip : Tree L []
node : ∀ {T Ts} → (cs : T → Tree L Ts) → Tree L (T ∷ Ts)
data Q (n : ℕ) : Set where
a : Q n
b : Q n
test₁ : Q zero → Tree ℕ (Q zero ∷ [])
test₁ = λ
{ a → node λ { a → tip ; b → tip }
; b → node λ { a → tip ; b → tip }
}
test₂ = node test₁
test₃ : Tree ℕ (Q zero ∷ Q zero ∷ [])
test₃ = node λ
{ a → node λ { a → tip ; b → tip }
; b → node λ { a → tip ; b → tip }
}
| 17.87931
| 103
| 0.499518
|
12eb95cf5943fc6e98e6fc1f65f1a368a6782c9b
| 11,437
|
agda
|
Agda
|
Definition/LogicalRelation/Properties/Neutral.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 30
|
2017-05-20T03:05:21.000Z
|
2022-03-30T18:01:07.000Z
|
Definition/LogicalRelation/Properties/Neutral.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 4
|
2017-06-22T12:49:23.000Z
|
2021-02-22T10:37:24.000Z
|
Definition/LogicalRelation/Properties/Neutral.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 8
|
2017-10-18T14:18:20.000Z
|
2021-11-27T15:58:33.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Neutral {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped hiding (_∷_)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
import Definition.Typed.Weakening as Wk
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties.Reflexivity
open import Definition.LogicalRelation.Properties.Escape
open import Definition.LogicalRelation.Properties.Symmetry
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
private
variable
m : Nat
Γ : Con Term m
-- Neutral reflexive types are reducible.
neu : ∀ {l A} (neA : Neutral A)
→ Γ ⊢ A
→ Γ ⊢ A ~ A ∷ U
→ Γ ⊩⟨ l ⟩ A
neu neA A A~A = ne′ _ (idRed:*: A) neA A~A
-- Helper function for reducible neutral equality of a specific type of derivation.
neuEq′ : ∀ {l A B} ([A] : Γ ⊩⟨ l ⟩ne A)
(neA : Neutral A)
(neB : Neutral B)
→ Γ ⊢ A → Γ ⊢ B
→ Γ ⊢ A ~ B ∷ U
→ Γ ⊩⟨ l ⟩ A ≡ B / ne-intr [A]
neuEq′ (noemb (ne K [ ⊢A , ⊢B , D ] neK K≡K)) neA neB A B A~B =
let A≡K = whnfRed* D (ne neA)
in ne₌ _ (idRed:*: B) neB (PE.subst (λ x → _ ⊢ x ~ _ ∷ _) A≡K A~B)
neuEq′ (emb 0<1 x) neB A:≡:B = neuEq′ x neB A:≡:B
-- Neutrally equal types are of reducible equality.
neuEq : ∀ {l A B} ([A] : Γ ⊩⟨ l ⟩ A)
(neA : Neutral A)
(neB : Neutral B)
→ Γ ⊢ A → Γ ⊢ B
→ Γ ⊢ A ~ B ∷ U
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
neuEq [A] neA neB A B A~B =
irrelevanceEq (ne-intr (ne-elim neA [A]))
[A]
(neuEq′ (ne-elim neA [A]) neA neB A B A~B)
mutual
-- Neutral reflexive terms are reducible.
neuTerm : ∀ {l A n} ([A] : Γ ⊩⟨ l ⟩ A) (neN : Neutral n)
→ Γ ⊢ n ∷ A
→ Γ ⊢ n ~ n ∷ A
→ Γ ⊩⟨ l ⟩ n ∷ A / [A]
neuTerm (Uᵣ′ .⁰ 0<1 ⊢Γ) neN n n~n =
Uₜ _ (idRedTerm:*: n) (ne neN) (~-to-≅ₜ n~n) (neu neN (univ n) n~n)
neuTerm (ℕᵣ [ ⊢A , ⊢B , D ]) neN n n~n =
let A≡ℕ = subset* D
n~n′ = ~-conv n~n A≡ℕ
n≡n = ~-to-≅ₜ n~n′
in ℕₜ _ (idRedTerm:*: (conv n A≡ℕ)) n≡n (ne (neNfₜ neN (conv n A≡ℕ) n~n′))
neuTerm (Emptyᵣ [ ⊢A , ⊢B , D ]) neN n n~n =
let A≡Empty = subset* D
n~n′ = ~-conv n~n A≡Empty
n≡n = ~-to-≅ₜ n~n′
in Emptyₜ _ (idRedTerm:*: (conv n A≡Empty)) n≡n (ne (neNfₜ neN (conv n A≡Empty) n~n′))
neuTerm (Unitᵣ [ ⊢A , ⊢B , D ]) neN n n~n =
let A≡Unit = subset* D
n~n′ = ~-conv n~n A≡Unit
in Unitₜ _ (idRedTerm:*: (conv n A≡Unit)) (ne neN)
neuTerm (ne′ K [ ⊢A , ⊢B , D ] neK K≡K) neN n n~n =
let A≡K = subset* D
in neₜ _ (idRedTerm:*: (conv n A≡K)) (neNfₜ neN (conv n A≡K)
(~-conv n~n A≡K))
neuTerm (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n =
let A≡ΠFG = subset* (red D)
in Πₜ _ (idRedTerm:*: (conv n A≡ΠFG)) (ne neN) (~-to-≅ₜ (~-conv n~n A≡ΠFG))
(λ {_} {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let A≡ΠFG = subset* (red D)
ρA≡ρΠFG = Wk.wkEq [ρ] ⊢Δ (subset* (red D))
G[a]≡G[b] = escapeEq ([G] [ρ] ⊢Δ [b])
(symEq ([G] [ρ] ⊢Δ [a]) ([G] [ρ] ⊢Δ [b])
(G-ext [ρ] ⊢Δ [a] [b] [a≡b]))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
b = escapeTerm ([F] [ρ] ⊢Δ) [b]
a≡b = escapeTermEq ([F] [ρ] ⊢Δ) [a≡b]
ρn = conv (Wk.wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG
neN∘a = ∘ₙ (wkNeutral ρ neN)
neN∘b = ∘ₙ (wkNeutral ρ neN)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∘a neN∘b
(ρn ∘ⱼ a)
(conv (ρn ∘ⱼ b) (≅-eq G[a]≡G[b]))
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡b))
(λ {_} {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = Wk.wkEq [ρ] ⊢Δ (subset* (red D))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ) (reflEqTerm ([F] [ρ] ⊢Δ) [a])
in neuTerm ([G] [ρ] ⊢Δ [a]) (∘ₙ (wkNeutral ρ neN))
(conv (Wk.wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡a))
neuTerm (Σᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN ⊢n n~n =
let A≡ΣFG = subset* (red D)
⊢Γ = wf ⊢F
⊢n = conv ⊢n A≡ΣFG
n~n = ~-conv n~n A≡ΣFG
[F] = [F] Wk.id ⊢Γ
[fst] = neuTerm [F] (fstₙ neN)
(PE.subst
(λ x → _ ⊢ fst _ ∷ x)
(PE.sym (wk-id F))
(fstⱼ ⊢F ⊢G ⊢n))
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n~n))
[Gfst] = [G] Wk.id ⊢Γ [fst]
[snd] = neuTerm [Gfst] (sndₙ neN)
(PE.subst
(λ x → _ ⊢ snd _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(sndⱼ ⊢F ⊢G ⊢n))
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(~-snd ⊢F ⊢G n~n))
in Σₜ _ (idRedTerm:*: ⊢n) (ne neN) (~-to-≅ₜ n~n)
[fst]
[snd]
neuTerm (emb 0<1 x) neN n = neuTerm x neN n
-- Neutrally equal terms are of reducible equality.
neuEqTerm : ∀ {l A n n′} ([A] : Γ ⊩⟨ l ⟩ A)
(neN : Neutral n) (neN′ : Neutral n′)
→ Γ ⊢ n ∷ A
→ Γ ⊢ n′ ∷ A
→ Γ ⊢ n ~ n′ ∷ A
→ Γ ⊩⟨ l ⟩ n ≡ n′ ∷ A / [A]
neuEqTerm (Uᵣ′ .⁰ 0<1 ⊢Γ) neN neN′ n n′ n~n′ =
let [n] = neu neN (univ n) (~-trans n~n′ (~-sym n~n′))
[n′] = neu neN′ (univ n′) (~-trans (~-sym n~n′) n~n′)
in Uₜ₌ _ _ (idRedTerm:*: n) (idRedTerm:*: n′) (ne neN) (ne neN′)
(~-to-≅ₜ n~n′) [n] [n′] (neuEq [n] neN neN′ (univ n) (univ n′) n~n′)
neuEqTerm (ℕᵣ [ ⊢A , ⊢B , D ]) neN neN′ n n′ n~n′ =
let A≡ℕ = subset* D
n~n′₁ = ~-conv n~n′ A≡ℕ
n≡n′ = ~-to-≅ₜ n~n′₁
in ℕₜ₌ _ _ (idRedTerm:*: (conv n A≡ℕ)) (idRedTerm:*: (conv n′ A≡ℕ))
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm (Emptyᵣ [ ⊢A , ⊢B , D ]) neN neN′ n n′ n~n′ =
let A≡Empty = subset* D
n~n′₁ = ~-conv n~n′ A≡Empty
n≡n′ = ~-to-≅ₜ n~n′₁
in Emptyₜ₌ _ _ (idRedTerm:*: (conv n A≡Empty)) (idRedTerm:*: (conv n′ A≡Empty))
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm (Unitᵣ [ ⊢A , ⊢B , D ]) neN neN′ n n′ n~n′ =
let A≡Unit = subset* D
in Unitₜ₌ (conv n A≡Unit) (conv n′ A≡Unit)
neuEqTerm (ne (ne K [ ⊢A , ⊢B , D ] neK K≡K)) neN neN′ n n′ n~n′ =
let A≡K = subset* D
in neₜ₌ _ _ (idRedTerm:*: (conv n A≡K)) (idRedTerm:*: (conv n′ A≡K))
(neNfₜ₌ neN neN′ (~-conv n~n′ A≡K))
neuEqTerm (Πᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let [ΠFG] = Πᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΠFG = subset* D
n~n′₁ = ~-conv n~n′ A≡ΠFG
n≡n′ = ~-to-≅ₜ n~n′₁
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
in Πₜ₌ _ _ (idRedTerm:*: (conv n A≡ΠFG)) (idRedTerm:*: (conv n′ A≡ΠFG))
(ne neN) (ne neN′) n≡n′
(neuTerm [ΠFG] neN n n~n) (neuTerm [ΠFG] neN′ n′ n′~n′)
(λ {_} {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = Wk.wkEq [ρ] ⊢Δ A≡ΠFG
ρn = Wk.wkTerm [ρ] ⊢Δ n
ρn′ = Wk.wkTerm [ρ] ⊢Δ n′
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ)
(reflEqTerm ([F] [ρ] ⊢Δ) [a])
neN∙a = ∘ₙ (wkNeutral ρ neN)
neN′∙a′ = ∘ₙ (wkNeutral ρ neN′)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∙a neN′∙a′
(conv ρn ρA≡ρΠFG ∘ⱼ a)
(conv ρn′ ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ n~n′₁) a≡a))
neuEqTerm (Σᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ ⊢n ⊢n′ n~n′ =
let [ΣFG] = Σᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΣFG = subset* D
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
⊢Γ = wf ⊢F
⊢nΣ = conv ⊢n A≡ΣFG
⊢n′Σ = conv ⊢n′ A≡ΣFG
n~n′Σ = ~-conv n~n′ A≡ΣFG
n~nΣ = ~-conv n~n A≡ΣFG
n′~n′Σ = ~-conv n′~n′ A≡ΣFG
[F] = [F] Wk.id ⊢Γ
⊢fstnΣ = (PE.subst
(λ x → _ ⊢ fst _ ∷ x)
(PE.sym (wk-id F))
(fstⱼ ⊢F ⊢G ⊢nΣ))
⊢fstn′Σ = (PE.subst
(λ x → _ ⊢ fst _ ∷ x)
(PE.sym (wk-id F))
(fstⱼ ⊢F ⊢G ⊢n′Σ))
[fstn] = neuTerm [F] (fstₙ neN)
⊢fstnΣ
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n~nΣ))
[fstn′] = neuTerm [F] (fstₙ neN′)
⊢fstn′Σ
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n′~n′Σ))
[fstn≡fstn′] = neuEqTerm [F] (fstₙ neN) (fstₙ neN′)
⊢fstnΣ
⊢fstn′Σ
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.sym (wk-id F))
(~-fst ⊢F ⊢G n~n′Σ))
[Gfstn] = [G] Wk.id ⊢Γ [fstn]
[Gfstn′] = PE.subst (λ x → _ ⊩⟨ _ ⟩ x [ fst _ ]) (wk-lift-id G) ([G] Wk.id ⊢Γ [fstn′])
[fstn′≡fstn] = symEqTerm [F] [fstn≡fstn′]
[Gfstn′≡Gfstn] = irrelevanceEq″
(PE.cong (λ x → x [ fst _ ]) (wk-lift-id G))
(PE.cong (λ x → x [ fst _ ]) (wk-lift-id G))
([G] Wk.id ⊢Γ [fstn′]) [Gfstn′]
(G-ext Wk.id ⊢Γ [fstn′] [fstn] [fstn′≡fstn])
Gfstn′≡Gfstn = ≅-eq (escapeEq [Gfstn′] [Gfstn′≡Gfstn])
[sndn≡sndn′] = neuEqTerm [Gfstn] (sndₙ neN) (sndₙ neN′)
(PE.subst
(λ x → _ ⊢ snd _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(sndⱼ ⊢F ⊢G ⊢nΣ))
(PE.subst
(λ x → _ ⊢ snd _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(conv (sndⱼ ⊢F ⊢G ⊢n′Σ) Gfstn′≡Gfstn))
(PE.subst
(λ x → _ ⊢ _ ~ _ ∷ x)
(PE.cong (λ x → x [ fst _ ]) (PE.sym (wk-lift-id G)))
(~-snd ⊢F ⊢G n~n′Σ))
in Σₜ₌ _ _ (idRedTerm:*: ⊢nΣ) (idRedTerm:*: ⊢n′Σ)
(ne neN) (ne neN′) (~-to-≅ₜ n~n′Σ)
(neuTerm [ΣFG] neN ⊢n n~n) (neuTerm [ΣFG] neN′ ⊢n′ n′~n′)
[fstn] [fstn′] [fstn≡fstn′] [sndn≡sndn′]
neuEqTerm (emb 0<1 x) neN neN′ n:≡:n′ = neuEqTerm x neN neN′ n:≡:n′
| 43.32197
| 94
| 0.397569
|
dc225caf35e9dd212e56f088263d129ae2e92d8e
| 1,040
|
agda
|
Agda
|
notes/FOT/FOTC/Data/Nat/MutualRecursiveFunctions.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Data/Nat/MutualRecursiveFunctions.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Data/Nat/MutualRecursiveFunctions.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Mutual recursive functions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Data.Nat.MutualRecursiveFunctions where
open import FOTC.Base
open import FOTC.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
postulate
even : D → D
odd : D → D
even-0 : even zero ≡ true
even-S : ∀ d → even (succ₁ d) ≡ odd d
odd-0 : odd zero ≡ false
odd-S : ∀ d → odd (succ₁ d) ≡ even d
{-# ATP axioms even-0 even-S odd-0 odd-S #-}
postulate even-2 : even 2' ≡ true
{-# ATP prove even-2 #-}
postulate even-3 : even 3' ≡ false
{-# ATP prove even-3 #-}
postulate odd-2 : odd 2' ≡ false
{-# ATP prove odd-2 #-}
postulate odd-3 : odd 3' ≡ true
{-# ATP prove odd-3 #-}
| 26.666667
| 78
| 0.445192
|
575ead3cdbc3d857a5a28553d6bd024f4cb976db
| 10,365
|
agda
|
Agda
|
LibraBFT/ImplShared/Interface/Output.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/ImplShared/Interface/Output.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/ImplShared/Interface/Output.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
-- This module defines Outputs produced by handlers, as well as functions and properties relating
-- these to Yasm Actions.
open import LibraBFT.Base.KVMap
open import LibraBFT.ImplShared.NetworkMsg
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.Prelude
open import LibraBFT.Yasm.Types
open import Optics.All
module LibraBFT.ImplShared.Interface.Output where
data Output : Set where
--BroadcastEpochChangeProof : EpochChangeProof → List Author → Output -- TODO-1
BroadcastProposal : ProposalMsg → List Author → Output
BroadcastSyncInfo : SyncInfo → List Author → Output
LogErr : ErrLog → Output
LogInfo : InfoLog → Output
SendBRP : Author → BlockRetrievalResponse → Output
SendVote : VoteMsg → List Author → Output
open Output public
SendVote-inj-v : ∀ {x1 x2 y1 y2} → SendVote x1 y1 ≡ SendVote x2 y2 → x1 ≡ x2
SendVote-inj-v refl = refl
SendVote-inj-si : ∀ {x1 x2 y1 y2} → SendVote x1 y1 ≡ SendVote x2 y2 → y1 ≡ y2
SendVote-inj-si refl = refl
IsSendVote : Output → Set
IsSendVote (BroadcastProposal _ _) = ⊥
IsSendVote (BroadcastSyncInfo _ _) = ⊥
IsSendVote (LogErr _) = ⊥
IsSendVote (LogInfo _) = ⊥
IsSendVote (SendBRP _ _) = ⊥
IsSendVote (SendVote _ _) = ⊤
IsBroadcastProposal : Output → Set
IsBroadcastProposal (BroadcastProposal _ _) = ⊤
IsBroadcastProposal (BroadcastSyncInfo _ _) = ⊥
IsBroadcastProposal (LogErr _) = ⊥
IsBroadcastProposal (LogInfo _) = ⊥
IsBroadcastProposal (SendBRP _ _) = ⊥
IsBroadcastProposal (SendVote _ _) = ⊥
IsBroadcastSyncInfo : Output → Set
IsBroadcastSyncInfo (BroadcastProposal _ _) = ⊥
IsBroadcastSyncInfo (BroadcastSyncInfo _ _) = ⊤
IsBroadcastSyncInfo (LogErr _) = ⊥
IsBroadcastSyncInfo (LogInfo _) = ⊥
IsBroadcastSyncInfo (SendBRP _ _) = ⊥
IsBroadcastSyncInfo (SendVote _ _) = ⊥
IsLogErr : Output → Set
IsLogErr (BroadcastProposal _ _) = ⊥
IsLogErr (BroadcastSyncInfo _ _) = ⊥
IsLogErr (LogErr _) = ⊤
IsLogErr (LogInfo _) = ⊥
IsLogErr (SendBRP _ _) = ⊥
IsLogErr (SendVote _ _) = ⊥
isSendVote? : (out : Output) → Dec (IsSendVote out)
isSendVote? (BroadcastProposal _ _) = no λ ()
isSendVote? (BroadcastSyncInfo _ _) = no λ ()
isSendVote? (LogErr _) = no λ ()
isSendVote? (LogInfo _) = no λ ()
isSendVote? (SendBRP _ _) = no λ ()
isSendVote? (SendVote mv pid) = yes tt
isBroadcastProposal? : (out : Output) → Dec (IsBroadcastProposal out)
isBroadcastProposal? (BroadcastProposal _ _) = yes tt
isBroadcastProposal? (BroadcastSyncInfo _ _) = no λ ()
isBroadcastProposal? (LogErr _) = no λ ()
isBroadcastProposal? (LogInfo _) = no λ ()
isBroadcastProposal? (SendBRP _ _) = no λ ()
isBroadcastProposal? (SendVote _ _) = no λ ()
isBroadcastSyncInfo? : (out : Output) → Dec (IsBroadcastSyncInfo out)
isBroadcastSyncInfo? (BroadcastProposal _ _) = no λ ()
isBroadcastSyncInfo? (BroadcastSyncInfo _ _) = yes tt
isBroadcastSyncInfo? (LogErr _) = no λ ()
isBroadcastSyncInfo? (LogInfo _) = no λ ()
isBroadcastSyncInfo? (SendBRP _ _) = no λ ()
isBroadcastSyncInfo? (SendVote _ _) = no λ ()
isLogErr? : (out : Output) → Dec (IsLogErr out)
isLogErr? (BroadcastProposal x _) = no λ ()
isLogErr? (BroadcastSyncInfo x _) = no λ ()
isLogErr? (LogErr x) = yes tt
isLogErr? (LogInfo x) = no λ ()
isLogErr? (SendBRP _ _) = no λ ()
isLogErr? (SendVote x x₁) = no λ ()
IsOutputMsg : Output → Set
IsOutputMsg = IsBroadcastProposal ∪ IsBroadcastSyncInfo ∪ IsSendVote
isOutputMsg? = isBroadcastProposal? ∪? (isBroadcastSyncInfo? ∪? isSendVote?)
data _Msg∈Out_ : NetworkMsg → Output → Set where
inBP : ∀ {pm pids} → P pm Msg∈Out BroadcastProposal pm pids
inSV : ∀ {vm pids} → V vm Msg∈Out SendVote vm pids
sendVote∉Output : ∀ {vm pid outs} → List-filter isSendVote? outs ≡ [] → ¬ (SendVote vm pid ∈ outs)
sendVote∉Output () (here refl)
sendVote∉Output{outs = x ∷ outs'} eq (there vm∈outs)
with isSendVote? x
... | no proof = sendVote∉Output eq vm∈outs
-- Note: the SystemModel allows anyone to receive any message sent, so intended recipient is ignored;
-- it is included in the model only to facilitate future work on liveness properties, when we will need
-- assumptions about message delivery between honest peers.
outputToActions : RoundManager → Output → List (Action NetworkMsg)
outputToActions rm (BroadcastProposal p rcvrs) = List-map (const (send (P p))) rcvrs
outputToActions _ (BroadcastSyncInfo _ _) = []
outputToActions _ (LogErr x) = []
outputToActions _ (LogInfo x) = []
outputToActions _ (SendVote vm rcvrs) = List-map (const (send (V vm))) rcvrs
outputToActions _ (SendBRP p brr) = [] -- TODO-1: Update `NetworkMsg`
outputsToActions : ∀ {State} → List Output → List (Action NetworkMsg)
outputsToActions {st} = concat ∘ List-map (outputToActions st)
-- Lemmas about `outputsToActions`
outputToActions-sendVote∉actions
: ∀ {out vm st} → ¬ (IsSendVote out) → ¬ (send (V vm) ∈ outputToActions st out)
outputToActions-sendVote∉actions {BroadcastProposal pm rcvrs}{vm}{st} ¬sv m∈acts =
help rcvrs m∈acts
where
help : ∀ xs → ¬ (send (V vm) ∈ List-map (const (send (P pm))) xs)
help (x ∷ xs) (there m∈acts) = help xs m∈acts
outputToActions-sendVote∉actions {SendVote _ _} ¬sv m∈acts = ¬sv tt
outputToActions-m∈sendVoteList
: ∀ {m vm rcvrs} → send m ∈ List-map (const $ send (V vm)) rcvrs
→ m Msg∈Out SendVote vm rcvrs
outputToActions-m∈sendVoteList {.(V vm)} {vm} {x ∷ rcvrs} (here refl) = inSV
outputToActions-m∈sendVoteList {m} {vm} {x ∷ rcvrs} (there m∈svl)
with outputToActions-m∈sendVoteList{rcvrs = rcvrs} m∈svl
... | inSV = inSV
outputToActions-m∈sendProposalList
: ∀ {m pm rcvrs} → send m ∈ List-map (const $ send (P pm)) rcvrs
→ m Msg∈Out BroadcastProposal pm rcvrs
outputToActions-m∈sendProposalList {.(P pm)} {pm} {x ∷ rcvrs} (here refl) = inBP
outputToActions-m∈sendProposalList {m} {pm} {x ∷ rcvrs} (there m∈spl)
with outputToActions-m∈sendProposalList {rcvrs = rcvrs} m∈spl
... | inBP = inBP
sendVote∉actions
: ∀ {outs vm st} → [] ≡ List-filter isSendVote? outs → ¬ (send (V vm) ∈ outputsToActions{st} outs)
sendVote∉actions {[]} {st = st} outs≡ ()
sendVote∉actions {x ∷ outs} {st = st} outs≡ m∈acts
with Any-++⁻ (outputToActions st x) m∈acts
... | Left m∈[]
with isSendVote? x
...| no proof = outputToActions-sendVote∉actions {st = st} proof m∈[]
sendVote∉actions {x ∷ outs} {st = st} outs≡ m∈acts | Right m∈acts'
with isSendVote? x
...| no proof = sendVote∉actions{outs = outs}{st = st} outs≡ m∈acts'
sendVote∈actions
: ∀ {vm vm' pids outs st} → SendVote vm pids ∷ [] ≡ List-filter isSendVote? outs
→ send (V vm') ∈ outputsToActions{st} outs
→ vm' ≡ vm
sendVote∈actions {outs = (BroadcastProposal x rcvrs) ∷ outs}{st = st} outs≡ m∈acts
with Any-++⁻ (outputToActions st (BroadcastProposal x rcvrs)) m∈acts
... | Left m∈[] = ⊥-elim (outputToActions-sendVote∉actions{out = BroadcastProposal x rcvrs}{st = st} id m∈[])
... | Right m∈acts' = sendVote∈actions{outs = outs}{st = st} outs≡ m∈acts'
sendVote∈actions {outs = (BroadcastSyncInfo x rcvrs) ∷ outs}{st = st} outs≡ m∈acts =
sendVote∈actions{outs = outs}{st = st} outs≡ m∈acts
sendVote∈actions {outs = LogErr x ∷ outs}{st = st} outs≡ m∈acts =
sendVote∈actions{outs = outs}{st = st} outs≡ m∈acts
sendVote∈actions {outs = LogInfo x ∷ outs}{st = st} outs≡ m∈acts =
sendVote∈actions{outs = outs}{st = st} outs≡ m∈acts
sendVote∈actions {vm}{vm'}{outs = SendBRP pid brr ∷ outs}{st = st} outs≡ m∈acts =
sendVote∈actions{outs = outs}{st = st} outs≡ m∈acts
sendVote∈actions {vm}{vm'}{outs = SendVote vm“ pids' ∷ outs}{st = st} outs≡ m∈acts
with ∷-injective outs≡
...| refl , tl≡
with Any-++⁻ (List-map (const (send (V vm“))) pids') m∈acts
... | Right m∈[] = ⊥-elim (sendVote∉actions{outs = outs}{st = st} tl≡ m∈[])
... | Left m∈acts' = help pids' m∈acts'
where
help : ∀ pids → send (V vm') ∈ List-map (const (send (V vm“))) pids → vm' ≡ vm“
help (_ ∷ pids) (here refl) = refl
help (_ ∷ pids) (there m∈acts) = help pids m∈acts
sendMsg∈actions
: ∀ {outs m st} → send m ∈ outputsToActions{st} outs
→ Σ[ out ∈ Output ] (out ∈ outs × m Msg∈Out out)
sendMsg∈actions {BroadcastProposal pm rcvrs ∷ outs} {m} {st} m∈acts
with Any-++⁻ (List-map (const $ send (P pm)) rcvrs) m∈acts
... | Left m∈bpl =
BroadcastProposal pm rcvrs , here refl , outputToActions-m∈sendProposalList m∈bpl
... | Right m∈acts'
with sendMsg∈actions{outs}{m}{st} m∈acts'
... | out , out∈outs , m∈out = out , there out∈outs , m∈out
-- NOTE: When we represent sending `BroadcastSyncInfo` as an action, this will require updating
sendMsg∈actions {BroadcastSyncInfo _ _ ∷ outs} {m} {st} m∈acts
with sendMsg∈actions{outs}{m}{st} m∈acts
...| out , out∈outs , m∈out = out , there out∈outs , m∈out
sendMsg∈actions {LogErr _ ∷ outs} {m} {st} m∈acts
with sendMsg∈actions{outs}{m}{st} m∈acts
...| out , out∈outs , m∈out = out , there out∈outs , m∈out
sendMsg∈actions {LogInfo _ ∷ outs} {m} {st} m∈acts
with sendMsg∈actions{outs}{m}{st} m∈acts
...| out , out∈outs , m∈out = out , there out∈outs , m∈out
sendMsg∈actions {SendBRP pid brr ∷ outs} {m} {st} m∈acts
with sendMsg∈actions{outs}{m}{st} m∈acts
...| out , out∈outs , m∈out = out , there out∈outs , m∈out
sendMsg∈actions {SendVote vm rcvrs ∷ outs} {m} {st} m∈acts
with Any-++⁻ (List-map (const (send (V vm))) rcvrs) m∈acts
... | Left m∈svl =
SendVote vm rcvrs , here refl , outputToActions-m∈sendVoteList m∈svl
... | Right m∈acts'
with sendMsg∈actions{outs}{m}{st} m∈acts'
... | out , out∈outs , m∈out = out , there out∈outs , m∈out
| 46.479821
| 111
| 0.640714
|
5810f36bef84e7575a68447fabfd24afd1956b71
| 45,918
|
agda
|
Agda
|
Agda/12-univalence.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/12-univalence.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/12-univalence.agda
|
tadejpetric/HoTT-Intro
|
f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}
module 12-univalence where
import 11-function-extensionality
open 11-function-extensionality public
-- Section 10.1 Type extensionality
equiv-eq : {i : Level} {A : UU i} {B : UU i} → Id A B → A ≃ B
equiv-eq {A = A} refl = pair id (is-equiv-id A)
UNIVALENCE : {i : Level} (A B : UU i) → UU (lsuc i)
UNIVALENCE A B = is-equiv (equiv-eq {A = A} {B = B})
is-contr-total-equiv-UNIVALENCE : {i : Level} (A : UU i) →
((B : UU i) → UNIVALENCE A B) → is-contr (Σ (UU i) (λ X → A ≃ X))
is-contr-total-equiv-UNIVALENCE A UA =
fundamental-theorem-id' A
( pair id (is-equiv-id A))
( λ B → equiv-eq {B = B})
( UA)
UNIVALENCE-is-contr-total-equiv : {i : Level} (A : UU i) →
is-contr (Σ (UU i) (λ X → A ≃ X)) → (B : UU i) → UNIVALENCE A B
UNIVALENCE-is-contr-total-equiv A c =
fundamental-theorem-id A
( pair id (is-equiv-id A))
( c)
( λ B → equiv-eq {B = B})
ev-id : {i j : Level} {A : UU i} (P : (B : UU i) → (A ≃ B) → UU j) →
((B : UU i) (e : A ≃ B) → P B e) → P A (pair id (is-equiv-id A))
ev-id {A = A} P f = f A (pair id (is-equiv-id A))
IND-EQUIV : {i j : Level} {A : UU i} → ((B : UU i) (e : A ≃ B) → UU j) → UU _
IND-EQUIV P = sec (ev-id P)
triangle-ev-id : {i j : Level} {A : UU i}
(P : (Σ (UU i) (λ X → A ≃ X)) → UU j) →
(ev-pt (Σ (UU i) (λ X → A ≃ X)) (pair A (pair id (is-equiv-id A))) P)
~ ((ev-id (λ X e → P (pair X e))) ∘ (ev-pair {A = UU i} {B = λ X → A ≃ X} {C = P}))
triangle-ev-id P f = refl
abstract
IND-EQUIV-is-contr-total-equiv : {i j : Level} (A : UU i) →
is-contr (Σ (UU i) (λ X → A ≃ X)) →
(P : (Σ (UU i) (λ X → A ≃ X)) → UU j) → IND-EQUIV (λ B e → P (pair B e))
IND-EQUIV-is-contr-total-equiv {i} {j} A c P =
section-comp
( ev-pt (Σ (UU i) (λ X → A ≃ X)) (pair A (pair id (is-equiv-id A))) P)
( ev-id (λ X e → P (pair X e)))
( ev-pair {A = UU i} {B = λ X → A ≃ X} {C = P})
( triangle-ev-id P)
( sec-ev-pair (UU i) (λ X → A ≃ X) P)
( is-sing-is-contr (Σ (UU i) (λ X → A ≃ X))
( pair
( pair A (pair id (is-equiv-id A)))
( λ t →
( inv (contraction c (pair A (pair id (is-equiv-id A))))) ∙
( contraction c t)))
( P)
( pair A (equiv-id A)))
abstract
is-contr-total-equiv-IND-EQUIV : {i : Level} (A : UU i) →
( {j : Level} (P : (Σ (UU i) (λ X → A ≃ X)) → UU j) →
IND-EQUIV (λ B e → P (pair B e))) →
is-contr (Σ (UU i) (λ X → A ≃ X))
is-contr-total-equiv-IND-EQUIV {i} A ind =
is-contr-is-sing
( Σ (UU i) (λ X → A ≃ X))
( pair A (pair id (is-equiv-id A)))
( λ P → section-comp'
( ev-pt (Σ (UU i) (λ X → A ≃ X)) (pair A (pair id (is-equiv-id A))) P)
( ev-id (λ X e → P (pair X e)))
( ev-pair {A = UU i} {B = λ X → A ≃ X} {C = P})
( triangle-ev-id P)
( sec-ev-pair (UU i) (λ X → A ≃ X) P)
( ind P))
-- The univalence axiom
postulate univalence : {i : Level} (A B : UU i) → UNIVALENCE A B
eq-equiv : {i : Level} (A B : UU i) → (A ≃ B) → Id A B
eq-equiv A B = inv-is-equiv (univalence A B)
abstract
is-contr-total-equiv : {i : Level} (A : UU i) →
is-contr (Σ (UU i) (λ X → A ≃ X))
is-contr-total-equiv A = is-contr-total-equiv-UNIVALENCE A (univalence A)
abstract
Ind-equiv : {i j : Level} (A : UU i) (P : (B : UU i) (e : A ≃ B) → UU j) →
sec (ev-id P)
Ind-equiv A P =
IND-EQUIV-is-contr-total-equiv A
( is-contr-total-equiv A)
( λ t → P (pr1 t) (pr2 t))
ind-equiv : {i j : Level} (A : UU i) (P : (B : UU i) (e : A ≃ B) → UU j) →
P A (pair id (is-equiv-id A)) → {B : UU i} (e : A ≃ B) → P B e
ind-equiv A P p {B} = pr1 (Ind-equiv A P) p B
-- Subuniverses
is-subuniverse :
{l1 l2 : Level} (P : UU l1 → UU l2) → UU ((lsuc l1) ⊔ l2)
is-subuniverse P = is-subtype P
subuniverse :
(l1 l2 : Level) → UU ((lsuc l1) ⊔ (lsuc l2))
subuniverse l1 l2 = Σ (UU l1 → UU l2) is-subuniverse
{- By univalence, subuniverses are closed under equivalences. -}
in-subuniverse-equiv :
{l1 l2 : Level} (P : UU l1 → UU l2) {X Y : UU l1} → X ≃ Y → P X → P Y
in-subuniverse-equiv P e = tr P (eq-equiv _ _ e)
in-subuniverse-equiv' :
{l1 l2 : Level} (P : UU l1 → UU l2) {X Y : UU l1} → X ≃ Y → P Y → P X
in-subuniverse-equiv' P e = tr P (inv (eq-equiv _ _ e))
total-subuniverse :
{l1 l2 : Level} (P : subuniverse l1 l2) → UU ((lsuc l1) ⊔ l2)
total-subuniverse {l1} P = Σ (UU l1) (pr1 P)
{- We also introduce the notion of 'global subuniverse'. The handling of
universe levels is a bit more complicated here, since (l : Level) → A l are
kinds but not types. -}
is-global-subuniverse :
(α : Level → Level) (P : (l : Level) → subuniverse l (α l)) →
(l1 l2 : Level) → UU _
is-global-subuniverse α P l1 l2 =
(X : UU l1) (Y : UU l2) → X ≃ Y → (pr1 (P l1)) X → (pr1 (P l2)) Y
{- Next we characterize the identity type of a subuniverse. -}
Eq-total-subuniverse :
{l1 l2 : Level} (P : subuniverse l1 l2) →
(s t : total-subuniverse P) → UU l1
Eq-total-subuniverse (pair P H) (pair X p) t = X ≃ (pr1 t)
Eq-total-subuniverse-eq :
{l1 l2 : Level} (P : subuniverse l1 l2) →
(s t : total-subuniverse P) → Id s t → Eq-total-subuniverse P s t
Eq-total-subuniverse-eq (pair P H) (pair X p) .(pair X p) refl = equiv-id X
abstract
is-contr-total-Eq-total-subuniverse :
{l1 l2 : Level} (P : subuniverse l1 l2)
(s : total-subuniverse P) →
is-contr (Σ (total-subuniverse P) (λ t → Eq-total-subuniverse P s t))
is-contr-total-Eq-total-subuniverse (pair P H) (pair X p) =
is-contr-total-Eq-substructure (is-contr-total-equiv X) H X (equiv-id X) p
abstract
is-equiv-Eq-total-subuniverse-eq :
{l1 l2 : Level} (P : subuniverse l1 l2)
(s t : total-subuniverse P) → is-equiv (Eq-total-subuniverse-eq P s t)
is-equiv-Eq-total-subuniverse-eq (pair P H) (pair X p) =
fundamental-theorem-id
( pair X p)
( equiv-id X)
( is-contr-total-Eq-total-subuniverse (pair P H) (pair X p))
( Eq-total-subuniverse-eq (pair P H) (pair X p))
eq-Eq-total-subuniverse :
{l1 l2 : Level} (P : subuniverse l1 l2) →
{s t : total-subuniverse P} → Eq-total-subuniverse P s t → Id s t
eq-Eq-total-subuniverse P {s} {t} =
inv-is-equiv (is-equiv-Eq-total-subuniverse-eq P s t)
-- Section 12.2 Univalence implies function extensionality
is-equiv-postcomp-univalence :
{l1 l2 : Level} {X Y : UU l1} (A : UU l2) (e : X ≃ Y) →
is-equiv (postcomp A (map-equiv e))
is-equiv-postcomp-univalence {X = X} A =
ind-equiv X
( λ Y e → is-equiv (postcomp A (map-equiv e)))
( is-equiv-id (A → X))
weak-funext-univalence :
{l : Level} {A : UU l} {B : A → UU l} → WEAK-FUNEXT A B
weak-funext-univalence {A = A} {B} is-contr-B =
is-contr-retract-of
( fib (postcomp A (pr1 {B = B})) id)
( pair
( λ f → pair (λ x → pair x (f x)) refl)
( pair
( λ h x → tr B (htpy-eq (pr2 h) x) (pr2 (pr1 h x)))
( htpy-refl)))
( is-contr-map-is-equiv
( is-equiv-postcomp-univalence A (equiv-pr1 is-contr-B))
( id))
funext-univalence :
{l : Level} {A : UU l} {B : A → UU l} (f : (x : A) → B x) → FUNEXT f
funext-univalence {A = A} {B} f =
FUNEXT-WEAK-FUNEXT (λ A B → weak-funext-univalence) A B f
-- Section 12.3 Groups in univalent mathematics
{- We first introduce semi-groups, and then groups. We do this because the
category of groups is a full subcategory of the category of semi-groups.
In particular, it is a proposition for a semi-group to be a group. Therefore
this approach gives us in a straightforward way that equality of groups is
equality of semi-groups. This will be useful in showing that group
isomorphisms are equivalent to identifications of groups. -}
has-associative-mul :
{l : Level} (X : UU-Set l) → UU l
has-associative-mul X =
Σ ( ( type-Set X) →
( ( type-Set X) → (type-Set X))) (λ μ →
( x y z : type-Set X) → Id (μ (μ x y) z) (μ x (μ y z)))
Semi-Group :
(l : Level) → UU (lsuc l)
Semi-Group l = Σ (UU-Set l) has-associative-mul
{- Bureaucracy of semi-groups. -}
set-Semi-Group :
{l : Level} → Semi-Group l → UU-Set l
set-Semi-Group G = pr1 G
type-Semi-Group :
{l : Level} → Semi-Group l → UU l
type-Semi-Group G = pr1 (set-Semi-Group G)
is-set-type-Semi-Group :
{l : Level} (G : Semi-Group l) → is-set (type-Semi-Group G)
is-set-type-Semi-Group G = pr2 (set-Semi-Group G)
associative-mul-Semi-Group :
{l : Level} (G : Semi-Group l) →
has-associative-mul (set-Semi-Group G)
associative-mul-Semi-Group G = pr2 G
mul-Semi-Group :
{l : Level} (G : Semi-Group l) →
type-Semi-Group G →
type-Semi-Group G → type-Semi-Group G
mul-Semi-Group G = pr1 (associative-mul-Semi-Group G)
is-associative-mul-Semi-Group :
{l : Level} (G : Semi-Group l) (x y z : type-Semi-Group G) →
Id ( mul-Semi-Group G (mul-Semi-Group G x y) z)
( mul-Semi-Group G x (mul-Semi-Group G y z))
is-associative-mul-Semi-Group G = pr2 (associative-mul-Semi-Group G)
{- The property that a semi-group is a monoid is just that the semi-group
possesses a unit that satisfies the left and right unit laws. -}
is-unital :
{l : Level} → Semi-Group l → UU l
is-unital G =
Σ ( type-Semi-Group G)
( λ e →
( (y : type-Semi-Group G) → Id (mul-Semi-Group G e y) y) ×
( (x : type-Semi-Group G) → Id (mul-Semi-Group G x e) x))
{- We show that is-unital is a proposition. -}
abstract
is-prop-is-unital' :
{l : Level} (G : Semi-Group l) → is-prop' (is-unital G)
is-prop-is-unital' (pair (pair X is-set-X) (pair μ assoc-μ))
(pair e (pair left-unit-e right-unit-e))
(pair e' (pair left-unit-e' right-unit-e')) =
eq-subtype
( λ e → is-prop-prod
( is-prop-Π (λ y → is-set-X (μ e y) y))
( is-prop-Π (λ x → is-set-X (μ x e) x)))
( (inv (left-unit-e' e)) ∙ (right-unit-e e'))
abstract
is-prop-is-unital :
{l : Level} (G : Semi-Group l) → is-prop (is-unital G)
is-prop-is-unital G = is-prop-is-prop' (is-prop-is-unital' G)
{- The property that a monoid is a group is just the property that the monoid
that every element is invertible, i.e., it comes equipped with an inverse
operation that satisfies the left and right inverse laws. -}
is-group' :
{l : Level} (G : Semi-Group l) → is-unital G → UU l
is-group' G is-unital-G =
Σ ( type-Semi-Group G → type-Semi-Group G)
( λ i →
( (x : type-Semi-Group G) →
Id (mul-Semi-Group G (i x) x) (pr1 is-unital-G)) ×
( (x : type-Semi-Group G) →
Id (mul-Semi-Group G x (i x)) (pr1 is-unital-G)))
is-group :
{l : Level} (G : Semi-Group l) → UU l
is-group G =
Σ (is-unital G) (is-group' G)
Group :
(l : Level) → UU (lsuc l)
Group l = Σ (Semi-Group l) is-group
{- Some bureaucracy of Groups. -}
semi-group-Group :
{l : Level} → Group l → Semi-Group l
semi-group-Group G = pr1 G
set-Group :
{l : Level} → Group l → UU-Set l
set-Group G = pr1 (semi-group-Group G)
type-Group :
{l : Level} → Group l → UU l
type-Group G = pr1 (set-Group G)
is-set-type-Group :
{l : Level} (G : Group l) → is-set (type-Group G)
is-set-type-Group G = pr2 (set-Group G)
associative-mul-Group :
{l : Level} (G : Group l) → has-associative-mul (set-Group G)
associative-mul-Group G = pr2 (semi-group-Group G)
mul-Group :
{l : Level} (G : Group l) →
type-Group G → type-Group G → type-Group G
mul-Group G = pr1 (associative-mul-Group G)
is-associative-mul-Group :
{l : Level} (G : Group l) (x y z : type-Group G) →
Id (mul-Group G (mul-Group G x y) z) (mul-Group G x (mul-Group G y z))
is-associative-mul-Group G = pr2 (associative-mul-Group G)
is-group-Group :
{l : Level} (G : Group l) → is-group (semi-group-Group G)
is-group-Group G = pr2 G
is-unital-Group :
{l : Level} (G : Group l) → is-unital (semi-group-Group G)
is-unital-Group G = pr1 (is-group-Group G)
unit-Group :
{l : Level} (G : Group l) → type-Group G
unit-Group G = pr1 (is-unital-Group G)
left-unit-law-Group :
{l : Level} (G : Group l) (x : type-Group G) →
Id (mul-Group G (unit-Group G) x) x
left-unit-law-Group G = pr1 (pr2 (is-unital-Group G))
right-unit-law-Group :
{l : Level} (G : Group l) (x : type-Group G) →
Id (mul-Group G x (unit-Group G)) x
right-unit-law-Group G = pr2 (pr2 (is-unital-Group G))
has-inverses-Group :
{l : Level} (G : Group l) →
is-group' (semi-group-Group G) (is-unital-Group G)
has-inverses-Group G = pr2 (is-group-Group G)
inv-Group :
{l : Level} (G : Group l) →
type-Group G → type-Group G
inv-Group G = pr1 (has-inverses-Group G)
left-inverse-law-Group :
{l : Level} (G : Group l) (x : type-Group G) →
Id (mul-Group G (inv-Group G x) x) (unit-Group G)
left-inverse-law-Group G = pr1 (pr2 (has-inverses-Group G))
right-inverse-law-Group :
{l : Level} (G : Group l) (x : type-Group G) →
Id (mul-Group G x (inv-Group G x)) (unit-Group G)
right-inverse-law-Group G = pr2 (pr2 (has-inverses-Group G))
{- We show that being a group is a proposition. -}
abstract
is-prop-is-group' :
{l : Level} (G : Semi-Group l) (e : is-unital G) → is-prop' (is-group' G e)
is-prop-is-group'
( pair (pair G is-set-G) (pair μ assoc-G))
( pair e (pair left-unit-G right-unit-G))
( pair i (pair left-inv-i right-inv-i))
( pair i' (pair left-inv-i' right-inv-i')) =
eq-subtype
( λ i →
is-prop-prod
( is-prop-Π (λ x → is-set-G (μ (i x) x) e))
( is-prop-Π (λ x → is-set-G (μ x (i x)) e)))
( eq-htpy
( λ x → -- ix
( inv (left-unit-G (i x))) ∙ -- = 1·(ix)
( ( ap (λ y → μ y (i x)) (inv (left-inv-i' x))) ∙ -- = (i'x·x)·(ix)
( ( assoc-G (i' x) x (i x)) ∙ -- = (i'x)·(x·i'x)
( ( ap (μ (i' x)) (right-inv-i x)) ∙ -- = (i'x)·1
( right-unit-G (i' x))))))) -- = i'x
abstract
is-prop-is-group :
{l : Level} (G : Semi-Group l) → is-prop (is-group G)
is-prop-is-group G =
is-prop-Σ
( is-prop-is-unital G)
( λ e → is-prop-is-prop' (is-prop-is-group' G e))
{- We give two examples of groups. The first is the group ℤ of integers. The
second is the loop space of a pointed 1-type. -}
{- The group of integers. -}
semi-group-ℤ : Semi-Group lzero
semi-group-ℤ = pair set-ℤ (pair add-ℤ associative-add-ℤ)
group-ℤ : Group lzero
group-ℤ =
pair
( semi-group-ℤ)
( pair
( pair zero-ℤ (pair left-unit-law-add-ℤ right-unit-law-add-ℤ))
( pair neg-ℤ (pair left-inverse-law-add-ℤ right-inverse-law-add-ℤ)))
{- The loop space of a 1-type as a group. -}
loop-space :
{l : Level} {A : UU l} → A → UU l
loop-space a = Id a a
set-loop-space :
{l : Level} (A : UU l) (a : A) (is-set-Ω : is-set (Id a a)) → UU-Set l
set-loop-space A a is-set-Ω = pair (Id a a) is-set-Ω
semi-group-loop-space :
{l : Level} (A : UU l) (a : A) (is-set-Ω : is-set (Id a a)) → Semi-Group l
semi-group-loop-space A a is-set-Ω =
pair
( set-loop-space A a is-set-Ω)
( pair (λ p q → p ∙ q) assoc)
group-loop-space :
{l : Level} (A : UU l) (a : A) (is-set-Ω : is-set (Id a a)) → Group l
group-loop-space A a is-set-Ω =
pair
( semi-group-loop-space A a is-set-Ω)
( pair
( pair refl (pair (λ q → left-unit) (λ p → right-unit)))
( pair inv (pair left-inv right-inv)))
set-loop-space-1-type :
{l : Level} (A : 1-type l) (a : pr1 A) → UU-Set l
set-loop-space-1-type (pair A is-1-type-A) a =
set-loop-space A a (is-1-type-A a a)
semi-group-loop-space-1-type :
{l : Level} (A : 1-type l) (a : pr1 A) → Semi-Group l
semi-group-loop-space-1-type (pair A is-1-type-A) a =
semi-group-loop-space A a (is-1-type-A a a)
group-loop-space-1-type :
{l : Level} (A : 1-type l) (a : pr1 A) → Group l
group-loop-space-1-type (pair A is-1-type-A) a =
group-loop-space A a (is-1-type-A a a)
{- We introduce the automorphism group on a set X. -}
aut-Set :
{l : Level} (X : UU-Set l) → UU-Set l
aut-Set X = set-equiv X X
associative-comp-equiv :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} →
(e : A ≃ B) (f : B ≃ C) (g : C ≃ D) →
Id ((g ∘e f) ∘e e) (g ∘e (f ∘e e))
associative-comp-equiv e f g = eq-htpy-equiv htpy-refl
has-associative-mul-aut-Set :
{l : Level} (X : UU-Set l) → has-associative-mul (aut-Set X)
has-associative-mul-aut-Set X =
pair
( λ e f → f ∘e e)
( λ e f g → inv (associative-comp-equiv e f g))
aut-Semi-Group :
{l : Level} (X : UU-Set l) → Semi-Group l
aut-Semi-Group X =
pair
( aut-Set X)
( has-associative-mul-aut-Set X)
left-unit-law-equiv :
{l1 l2 : Level} {X : UU l1} {Y : UU l2} (e : X ≃ Y) →
Id ((equiv-id Y) ∘e e) e
left-unit-law-equiv e = eq-htpy-equiv htpy-refl
right-unit-law-equiv :
{l1 l2 : Level} {X : UU l1} {Y : UU l2} (e : X ≃ Y) →
Id (e ∘e (equiv-id X)) e
right-unit-law-equiv e = eq-htpy-equiv htpy-refl
is-unital-aut-Semi-Group :
{l : Level} (X : UU-Set l) → is-unital (aut-Semi-Group X)
is-unital-aut-Semi-Group X =
pair
( equiv-id (type-Set X))
( pair
( right-unit-law-equiv)
( left-unit-law-equiv))
left-inverse-law-equiv :
{l1 l2 : Level} {X : UU l1} {Y : UU l2} (e : X ≃ Y) →
Id ((inv-equiv e) ∘e e) (equiv-id X)
left-inverse-law-equiv e =
eq-htpy-equiv (isretr-inv-is-equiv (is-equiv-map-equiv e))
right-inverse-law-equiv :
{l1 l2 : Level} {X : UU l1} {Y : UU l2} (e : X ≃ Y) →
Id (e ∘e (inv-equiv e)) (equiv-id Y)
right-inverse-law-equiv e =
eq-htpy-equiv (issec-inv-is-equiv (is-equiv-map-equiv e))
is-group-aut-Semi-Group' :
{l : Level} (X : UU-Set l) →
is-group' (aut-Semi-Group X) (is-unital-aut-Semi-Group X)
is-group-aut-Semi-Group' X =
pair
( inv-equiv)
( pair right-inverse-law-equiv left-inverse-law-equiv)
aut-Group :
{l : Level} → UU-Set l → Group l
aut-Group X =
pair
( aut-Semi-Group X)
( pair (is-unital-aut-Semi-Group X) (is-group-aut-Semi-Group' X))
{- Now we introduce homomorphisms of semi-groups. Group homomorphisms are just
homomorphisms between their underlying semi-groups. -}
preserves-mul :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
(type-Semi-Group G → type-Semi-Group H) → UU (l1 ⊔ l2)
preserves-mul G H f =
(x y : type-Semi-Group G) →
Id (f (mul-Semi-Group G x y)) (mul-Semi-Group H (f x) (f y))
abstract
is-prop-preserves-mul :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : type-Semi-Group G → type-Semi-Group H) →
is-prop (preserves-mul G H f)
is-prop-preserves-mul G (pair (pair H is-set-H) (pair μ-H assoc-H)) f =
is-prop-Π (λ x →
is-prop-Π (λ y →
is-set-H (f (mul-Semi-Group G x y)) (μ-H (f x) (f y))))
hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) → UU (l1 ⊔ l2)
hom-Semi-Group G H =
Σ ( type-Semi-Group G → type-Semi-Group H)
( preserves-mul G H)
{- Bureaucracy of homomorphisms of semi-groups. -}
map-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( hom-Semi-Group G H) →
( type-Semi-Group G) → (type-Semi-Group H)
map-hom-Semi-Group G H f = pr1 f
preserves-mul-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) →
preserves-mul G H (map-hom-Semi-Group G H f)
preserves-mul-hom-Semi-Group G H f = pr2 f
{- We characterize the identity type of the semi-group homomorphisms. -}
htpy-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2)
(f g : hom-Semi-Group G H) → UU (l1 ⊔ l2)
htpy-hom-Semi-Group G H f g =
(map-hom-Semi-Group G H f) ~ (map-hom-Semi-Group G H g)
reflexive-htpy-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) → htpy-hom-Semi-Group G H f f
reflexive-htpy-hom-Semi-Group G H f = htpy-refl
htpy-hom-Semi-Group-eq :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f g : hom-Semi-Group G H) → Id f g → htpy-hom-Semi-Group G H f g
htpy-hom-Semi-Group-eq G H f .f refl = reflexive-htpy-hom-Semi-Group G H f
abstract
is-contr-total-htpy-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) →
is-contr (Σ (hom-Semi-Group G H) (htpy-hom-Semi-Group G H f))
is-contr-total-htpy-hom-Semi-Group G H f =
is-contr-total-Eq-substructure
( is-contr-total-htpy (map-hom-Semi-Group G H f))
( is-prop-preserves-mul G H)
( map-hom-Semi-Group G H f)
( htpy-refl)
( preserves-mul-hom-Semi-Group G H f)
abstract
is-equiv-htpy-hom-Semi-Group-eq :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f g : hom-Semi-Group G H) → is-equiv (htpy-hom-Semi-Group-eq G H f g)
is-equiv-htpy-hom-Semi-Group-eq G H f =
fundamental-theorem-id f
( reflexive-htpy-hom-Semi-Group G H f)
( is-contr-total-htpy-hom-Semi-Group G H f)
( htpy-hom-Semi-Group-eq G H f)
eq-htpy-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
{ f g : hom-Semi-Group G H} → htpy-hom-Semi-Group G H f g → Id f g
eq-htpy-hom-Semi-Group G H {f} {g} =
inv-is-equiv (is-equiv-htpy-hom-Semi-Group-eq G H f g)
{- We show that the type of semi-group homomorphisms between two semi-groups is
a set. -}
is-set-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
is-set (hom-Semi-Group G H)
is-set-hom-Semi-Group G H (pair f μ-f) (pair g μ-g) =
is-prop-is-equiv
( htpy-hom-Semi-Group G H (pair f μ-f) (pair g μ-g))
( htpy-hom-Semi-Group-eq G H (pair f μ-f) (pair g μ-g))
( is-equiv-htpy-hom-Semi-Group-eq G H (pair f μ-f) (pair g μ-g))
( is-prop-Π (λ x → is-set-type-Semi-Group H (f x) (g x)))
{- We introduce group homomorphisms. -}
hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) → UU (l1 ⊔ l2)
hom-Group G H =
hom-Semi-Group
( semi-group-Group G)
( semi-group-Group H)
{- Bureaucracy of group homomorphisms. -}
map-hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( hom-Group G H) →
( type-Group G) → (type-Group H)
map-hom-Group G H f = pr1 f
preserves-mul-hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Group G H) →
preserves-mul
( semi-group-Group G)
( semi-group-Group H)
( map-hom-Group G H f)
preserves-mul-hom-Group G H f = pr2 f
{- We characterize the identity type of the group homomorphisms. -}
htpy-hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2)
(f g : hom-Group G H) → UU (l1 ⊔ l2)
htpy-hom-Group G H =
htpy-hom-Semi-Group
( semi-group-Group G)
( semi-group-Group H)
reflexive-htpy-hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Group G H) → htpy-hom-Group G H f f
reflexive-htpy-hom-Group G H =
reflexive-htpy-hom-Semi-Group
( semi-group-Group G)
( semi-group-Group H)
htpy-hom-Group-eq :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f g : hom-Group G H) → Id f g → htpy-hom-Group G H f g
htpy-hom-Group-eq G H =
htpy-hom-Semi-Group-eq
( semi-group-Group G)
( semi-group-Group H)
abstract
is-contr-total-htpy-hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Group G H) →
is-contr (Σ (hom-Group G H) (htpy-hom-Group G H f))
is-contr-total-htpy-hom-Group G H =
is-contr-total-htpy-hom-Semi-Group
( semi-group-Group G)
( semi-group-Group H)
abstract
is-equiv-htpy-hom-Group-eq :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f g : hom-Group G H) → is-equiv (htpy-hom-Group-eq G H f g)
is-equiv-htpy-hom-Group-eq G H =
is-equiv-htpy-hom-Semi-Group-eq
( semi-group-Group G)
( semi-group-Group H)
eq-htpy-hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
{ f g : hom-Group G H} → htpy-hom-Group G H f g → Id f g
eq-htpy-hom-Group G H =
eq-htpy-hom-Semi-Group (semi-group-Group G) (semi-group-Group H)
{- Next, we construct the identity group homomorphism, and we show that
compositions of group homomorphisms are again group homomorphisms. -}
preserves-mul-id :
{l : Level} (G : Semi-Group l) → preserves-mul G G id
preserves-mul-id (pair (pair G is-set-G) (pair μ-G assoc-G)) x y = refl
id-Semi-Group :
{l : Level} (G : Semi-Group l) → hom-Semi-Group G G
id-Semi-Group G =
pair id (preserves-mul-id G)
id-Group :
{l : Level} (G : Group l) → hom-Group G G
id-Group G = id-Semi-Group (semi-group-Group G)
composition-Semi-Group :
{l1 l2 l3 : Level} →
(G : Semi-Group l1) (H : Semi-Group l2) (K : Semi-Group l3) →
(hom-Semi-Group H K) → (hom-Semi-Group G H) → (hom-Semi-Group G K)
composition-Semi-Group G H K (pair g μ-g) (pair f μ-f) =
pair
( g ∘ f)
( λ x y → (ap g (μ-f x y)) ∙ (μ-g (f x) (f y)))
composition-Group :
{l1 l2 l3 : Level} (G : Group l1) (H : Group l2) (K : Group l3) →
(hom-Group H K) → (hom-Group G H) → (hom-Group G K)
composition-Group G H K =
composition-Semi-Group
( semi-group-Group G)
( semi-group-Group H)
( semi-group-Group K)
{- Next, we prove the that the laws for a category hold for group homomorphisms,
i.e., we show that composition is associative and satisfies the left and
right unit laws. Before we show that these laws hold, we will characterize
the identity type of the types of semi-group homomorphisms and group
homomorphisms. -}
associative-Semi-Group :
{ l1 l2 l3 l4 : Level} (G : Semi-Group l1) (H : Semi-Group l2)
( K : Semi-Group l3) (L : Semi-Group l4) (h : hom-Semi-Group K L) →
( g : hom-Semi-Group H K) (f : hom-Semi-Group G H) →
Id ( composition-Semi-Group G H L
( composition-Semi-Group H K L h g) f)
( composition-Semi-Group G K L h
( composition-Semi-Group G H K g f))
associative-Semi-Group G H K L (pair h μ-h) (pair g μ-g) (pair f μ-f) =
eq-htpy-hom-Semi-Group G L htpy-refl
left-unit-law-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2)
( f : hom-Semi-Group G H) →
Id ( composition-Semi-Group G H H (id-Semi-Group H) f) f
left-unit-law-Semi-Group G
(pair (pair H is-set-H) (pair μ-H assoc-H)) (pair f μ-f) =
eq-htpy-hom-Semi-Group G
( pair (pair H is-set-H) (pair μ-H assoc-H))
( htpy-refl)
right-unit-law-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2)
( f : hom-Semi-Group G H) →
Id ( composition-Semi-Group G G H f (id-Semi-Group G)) f
right-unit-law-Semi-Group
(pair (pair G is-set-G) (pair μ-G assoc-G)) H (pair f μ-f) =
eq-htpy-hom-Semi-Group
( pair (pair G is-set-G) (pair μ-G assoc-G)) H htpy-refl
{- Now we introduce the notion of group isomorphism. Finally, we will show that
isomorphic groups are equal. -}
is-iso-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) → UU (l1 ⊔ l2)
is-iso-Semi-Group G H f =
Σ ( hom-Semi-Group H G) (λ g →
( Id (composition-Semi-Group H G H f g) (id-Semi-Group H)) ×
( Id (composition-Semi-Group G H G g f) (id-Semi-Group G)))
iso-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) → UU (l1 ⊔ l2)
iso-Semi-Group G H =
Σ (hom-Semi-Group G H) (is-iso-Semi-Group G H)
abstract
is-prop-is-iso-Semi-Group' :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) → is-prop' (is-iso-Semi-Group G H f)
is-prop-is-iso-Semi-Group' G H f
(pair g (pair issec isretr)) (pair g' (pair issec' isretr')) =
eq-subtype
( λ h →
is-prop-prod
( is-set-hom-Semi-Group H H
( composition-Semi-Group H G H f h)
( id-Semi-Group H))
( is-set-hom-Semi-Group G G
( composition-Semi-Group G H G h f)
( id-Semi-Group G)))
( ( inv (left-unit-law-Semi-Group H G g)) ∙
( ( inv (ap (λ h → composition-Semi-Group H G G h g) isretr')) ∙
( ( associative-Semi-Group H G H G g' f g) ∙
( ( ap (composition-Semi-Group H H G g') issec) ∙
( right-unit-law-Semi-Group H G g')))))
abstract
is-prop-is-iso-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) → is-prop (is-iso-Semi-Group G H f)
is-prop-is-iso-Semi-Group G H f =
is-prop-is-prop' (is-prop-is-iso-Semi-Group' G H f)
abstract
preserves-mul-inv-is-equiv-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H)
( is-equiv-f : is-equiv (map-hom-Semi-Group G H f)) →
preserves-mul H G (inv-is-equiv is-equiv-f)
preserves-mul-inv-is-equiv-Semi-Group
( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair (pair H is-set-H) (pair μ-H assoc-H))
( pair f μ-f) is-equiv-f x y =
inv-is-equiv
( is-emb-is-equiv f is-equiv-f
( inv-is-equiv is-equiv-f (μ-H x y))
( μ-G (inv-is-equiv is-equiv-f x) (inv-is-equiv is-equiv-f y)))
( ( ( issec-inv-is-equiv is-equiv-f (μ-H x y)) ∙
( ( ap (λ t → μ-H t y) (inv (issec-inv-is-equiv is-equiv-f x))) ∙
( ap
( μ-H (f (inv-is-equiv is-equiv-f x)))
( inv (issec-inv-is-equiv is-equiv-f y))))) ∙
( inv (μ-f (inv-is-equiv is-equiv-f x) (inv-is-equiv is-equiv-f y))))
abstract
is-iso-is-equiv-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) (is-equiv-f : is-equiv (pr1 f)) →
is-iso-Semi-Group G H f
is-iso-is-equiv-hom-Semi-Group
( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair (pair H is-set-H) (pair μ-H assoc-H))
( pair f μ-f) is-equiv-f =
pair
( pair
( inv-is-equiv is-equiv-f)
( preserves-mul-inv-is-equiv-Semi-Group
( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair (pair H is-set-H) (pair μ-H assoc-H))
( pair f μ-f) is-equiv-f))
( pair
( eq-htpy-hom-Semi-Group
( pair (pair H is-set-H) (pair μ-H assoc-H))
( pair (pair H is-set-H) (pair μ-H assoc-H))
( issec-inv-is-equiv is-equiv-f))
( eq-htpy-hom-Semi-Group
( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair (pair G is-set-G) (pair μ-G assoc-G))
( isretr-inv-is-equiv is-equiv-f)))
abstract
is-equiv-hom-is-iso-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
( f : hom-Semi-Group G H) (is-iso-f : is-iso-Semi-Group G H f) →
( is-equiv (pr1 f))
is-equiv-hom-is-iso-Semi-Group
( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair (pair H is-set-H) (pair μ-H assoc-H))
( pair f μ-f)
( pair (pair g μ-g) (pair issec isretr)) =
is-equiv-has-inverse g
( htpy-eq (ap pr1 issec))
( htpy-eq (ap pr1 isretr))
equiv-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) → UU (l1 ⊔ l2)
equiv-Semi-Group G H =
Σ ( type-Semi-Group G ≃ type-Semi-Group H)
( λ e → preserves-mul G H (map-equiv e))
total-is-equiv-hom-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) → UU (l1 ⊔ l2)
total-is-equiv-hom-Semi-Group G H =
Σ (hom-Semi-Group G H) (λ f → is-equiv (map-hom-Semi-Group G H f))
preserves-mul' :
{ l1 l2 : Level} (G : Semi-Group l1) (H : UU-Set l2)
( μ-H : has-associative-mul H) →
( e : (type-Semi-Group G) ≃ (type-Set H)) →
UU (l1 ⊔ l2)
preserves-mul' G H μ-H e = preserves-mul G (pair H μ-H) (map-equiv e)
equiv-Semi-Group' :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) → UU (l1 ⊔ l2)
equiv-Semi-Group' G H = equiv-Semi-Group G (pair (pr1 H) (pr2 H))
abstract
equiv-iso-Semi-Group-equiv-Semi-Group :
{ l1 l2 : Level} (G : Semi-Group l1) (H : Semi-Group l2) →
equiv-Semi-Group' G H ≃ iso-Semi-Group G H
equiv-iso-Semi-Group-equiv-Semi-Group G H =
( ( ( equiv-total-subtype
( λ f → is-subtype-is-equiv (map-hom-Semi-Group G H f))
( is-prop-is-iso-Semi-Group G H)
( is-iso-is-equiv-hom-Semi-Group G H)
( is-equiv-hom-is-iso-Semi-Group G H)) ∘e
( ( inv-equiv
( equiv-Σ-assoc
( type-Semi-Group G → type-Semi-Group H)
( preserves-mul G H)
( λ f → is-equiv (map-hom-Semi-Group G H f)))) ∘e
( equiv-tot
( λ f → equiv-swap-prod (is-equiv f) (preserves-mul G H f))))) ∘e
( equiv-Σ-assoc
( type-Semi-Group G → type-Semi-Group H)
( is-equiv)
( λ e → preserves-mul G H (map-equiv e)))) ∘e
( equiv-tr (equiv-Semi-Group G) (η-pair H))
center-total-preserves-mul-id :
{ l1 : Level} (G : Semi-Group l1) →
Σ (has-associative-mul (pr1 G)) (λ μ → preserves-mul G (pair (pr1 G) μ) id)
center-total-preserves-mul-id (pair (pair G is-set-G) (pair μ-G assoc-G)) =
pair (pair μ-G assoc-G) (λ x y → refl)
contraction-total-preserves-mul-id :
{ l1 : Level} (G : Semi-Group l1) →
( t : Σ ( has-associative-mul (pr1 G))
( λ μ → preserves-mul G (pair (pr1 G) μ) id)) →
Id (center-total-preserves-mul-id G) t
contraction-total-preserves-mul-id
( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair (pair μ-G' assoc-G') μ-id) =
eq-subtype
( λ μ →
is-prop-preserves-mul
( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair (pair G is-set-G) μ) id)
( eq-subtype
( λ μ →
is-prop-Π (λ x →
is-prop-Π (λ y →
is-prop-Π (λ z →
is-set-G (μ (μ x y) z) (μ x (μ y z))))))
( eq-htpy (λ x → eq-htpy (λ y → μ-id x y))))
is-contr-total-preserves-mul-id :
{ l1 : Level} (G : Semi-Group l1) →
is-contr (Σ (has-associative-mul (pr1 G)) (λ μ → preserves-mul G (pair (pr1 G) μ) id))
is-contr-total-preserves-mul-id G =
pair
( center-total-preserves-mul-id G)
( contraction-total-preserves-mul-id G)
is-contr-total-equiv-Semi-Group :
{ l1 : Level} (G : Semi-Group l1) →
is-contr (Σ (Semi-Group l1) (λ H → equiv-Semi-Group' G H))
is-contr-total-equiv-Semi-Group {l1} G =
is-contr-total-Eq-structure
( preserves-mul' G)
( is-contr-total-Eq-substructure
( is-contr-total-equiv (type-Semi-Group G))
( is-prop-is-set)
( type-Semi-Group G)
( equiv-id (type-Semi-Group G))
( is-set-type-Semi-Group G))
( pair (pr1 G) (equiv-id (type-Semi-Group G)))
( is-contr-total-preserves-mul-id G)
is-contr-total-iso-Semi-Group :
{ l1 : Level} (G : Semi-Group l1) →
is-contr (Σ (Semi-Group l1) (iso-Semi-Group G))
is-contr-total-iso-Semi-Group {l1} G =
is-contr-equiv'
( Σ (Semi-Group l1) (λ H → equiv-Semi-Group' G H))
( equiv-tot (λ H → equiv-iso-Semi-Group-equiv-Semi-Group G H))
( is-contr-total-equiv-Semi-Group G)
iso-id-Semi-Group :
{ l1 : Level} (G : Semi-Group l1) → iso-Semi-Group G G
iso-id-Semi-Group G =
pair
( id-Semi-Group G)
( pair
( id-Semi-Group G)
( pair
( left-unit-law-Semi-Group G G (id-Semi-Group G))
( right-unit-law-Semi-Group G G (id-Semi-Group G))))
iso-eq-Semi-Group :
{ l1 : Level} (G H : Semi-Group l1) → Id G H → iso-Semi-Group G H
iso-eq-Semi-Group G .G refl = iso-id-Semi-Group G
is-equiv-iso-eq-Semi-Group :
{ l1 : Level} (G H : Semi-Group l1) → is-equiv (iso-eq-Semi-Group G H)
is-equiv-iso-eq-Semi-Group G =
fundamental-theorem-id G
( iso-id-Semi-Group G)
( is-contr-total-iso-Semi-Group G)
( iso-eq-Semi-Group G)
equiv-iso-eq-Semi-Group :
{ l1 : Level} (G H : Semi-Group l1) → Id G H ≃ iso-Semi-Group G H
equiv-iso-eq-Semi-Group G H =
pair (iso-eq-Semi-Group G H) (is-equiv-iso-eq-Semi-Group G H)
eq-iso-Semi-Group :
{ l1 : Level} (G H : Semi-Group l1) → iso-Semi-Group G H → Id G H
eq-iso-Semi-Group G H = inv-is-equiv (is-equiv-iso-eq-Semi-Group G H)
{- Finally we show that isomorphic groups are equal. -}
iso-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) → UU (l1 ⊔ l2)
iso-Group G H =
iso-Semi-Group
( semi-group-Group G)
( semi-group-Group H)
iso-id-Group :
{ l1 : Level} (G : Group l1) → iso-Group G G
iso-id-Group G = iso-id-Semi-Group (semi-group-Group G)
iso-eq-Group :
{ l1 : Level} (G H : Group l1) → Id G H → iso-Group G H
iso-eq-Group G .G refl = iso-id-Group G
abstract
equiv-iso-eq-Group' :
{ l1 : Level} (G H : Group l1) → Id G H ≃ iso-Group G H
equiv-iso-eq-Group' G H =
( equiv-iso-eq-Semi-Group
( semi-group-Group G)
( semi-group-Group H)) ∘e
( equiv-ap-pr1-is-subtype is-prop-is-group {s = G} {t = H})
abstract
is-contr-total-iso-Group :
{ l1 : Level} (G : Group l1) → is-contr (Σ (Group l1) (iso-Group G))
is-contr-total-iso-Group {l1} G =
is-contr-equiv'
( Σ (Group l1) (Id G))
( equiv-tot (λ H → equiv-iso-eq-Group' G H))
( is-contr-total-path G)
is-equiv-iso-eq-Group :
{ l1 : Level} (G H : Group l1) → is-equiv (iso-eq-Group G H)
is-equiv-iso-eq-Group G =
fundamental-theorem-id G
( iso-id-Group G)
( is-contr-total-iso-Group G)
( iso-eq-Group G)
eq-iso-Group :
{ l1 : Level} (G H : Group l1) → iso-Group G H → Id G H
eq-iso-Group G H = inv-is-equiv (is-equiv-iso-eq-Group G H)
-- Exercises
-- Exercise 10.1
tr-equiv-eq-ap : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} {x y : A}
(p : Id x y) → (map-equiv (equiv-eq (ap B p))) ~ tr B p
tr-equiv-eq-ap refl = htpy-refl
-- Exercise 10.2
subuniverse-is-contr :
{i : Level} → subuniverse i i
subuniverse-is-contr {i} = pair is-contr is-subtype-is-contr
unit' :
(i : Level) → UU i
unit' i = pr1 (Raise i unit)
abstract
is-contr-unit' :
(i : Level) → is-contr (unit' i)
is-contr-unit' i =
is-contr-equiv' unit (pr2 (Raise i unit)) is-contr-unit
abstract
center-UU-contr :
(i : Level) → total-subuniverse (subuniverse-is-contr {i})
center-UU-contr i =
pair (unit' i) (is-contr-unit' i)
contraction-UU-contr :
{i : Level} (A : Σ (UU i) is-contr) →
Id (center-UU-contr i) A
contraction-UU-contr (pair A is-contr-A) =
eq-Eq-total-subuniverse subuniverse-is-contr
( equiv-is-contr (is-contr-unit' _) is-contr-A)
abstract
is-contr-UU-contr : (i : Level) → is-contr (Σ (UU i) is-contr)
is-contr-UU-contr i =
pair (center-UU-contr i) (contraction-UU-contr)
is-trunc-UU-trunc :
(k : 𝕋) (i : Level) → is-trunc (succ-𝕋 k) (Σ (UU i) (is-trunc k))
is-trunc-UU-trunc k i X Y =
is-trunc-is-equiv k
( Id (pr1 X) (pr1 Y))
( ap pr1)
( is-emb-pr1-is-subtype
( is-prop-is-trunc k) X Y)
( is-trunc-is-equiv k
( (pr1 X) ≃ (pr1 Y))
( equiv-eq)
( univalence (pr1 X) (pr1 Y))
( is-trunc-equiv-is-trunc k (pr2 X) (pr2 Y)))
ev-true-false :
{l : Level} (A : UU l) → (f : bool → A) → A × A
ev-true-false A f = pair (f true) (f false)
map-universal-property-bool :
{l : Level} {A : UU l} →
A × A → (bool → A)
map-universal-property-bool (pair x y) true = x
map-universal-property-bool (pair x y) false = y
issec-map-universal-property-bool :
{l : Level} {A : UU l} →
((ev-true-false A) ∘ map-universal-property-bool) ~ id
issec-map-universal-property-bool (pair x y) =
eq-pair-triv (pair refl refl)
isretr-map-universal-property-bool' :
{l : Level} {A : UU l} (f : bool → A) →
(map-universal-property-bool (ev-true-false A f)) ~ f
isretr-map-universal-property-bool' f true = refl
isretr-map-universal-property-bool' f false = refl
isretr-map-universal-property-bool :
{l : Level} {A : UU l} →
(map-universal-property-bool ∘ (ev-true-false A)) ~ id
isretr-map-universal-property-bool f =
eq-htpy (isretr-map-universal-property-bool' f)
universal-property-bool :
{l : Level} (A : UU l) →
is-equiv (λ (f : bool → A) → pair (f true) (f false))
universal-property-bool A =
is-equiv-has-inverse
map-universal-property-bool
issec-map-universal-property-bool
isretr-map-universal-property-bool
ev-true :
{l : Level} {A : UU l} → (bool → A) → A
ev-true f = f true
triangle-ev-true :
{l : Level} (A : UU l) →
(ev-true) ~ (pr1 ∘ (ev-true-false A))
triangle-ev-true A = htpy-refl
aut-bool-bool :
bool → (bool ≃ bool)
aut-bool-bool true = equiv-id bool
aut-bool-bool false = equiv-neg-𝟚
bool-aut-bool :
(bool ≃ bool) → bool
bool-aut-bool e = map-equiv e true
decide-true-false :
(b : bool) → coprod (Id b true) (Id b false)
decide-true-false true = inl refl
decide-true-false false = inr refl
eq-false :
(b : bool) → (¬ (Id b true)) → (Id b false)
eq-false true p = ind-empty (p refl)
eq-false false p = refl
eq-true :
(b : bool) → (¬ (Id b false)) → Id b true
eq-true true p = refl
eq-true false p = ind-empty (p refl)
eq-false-equiv' :
(e : bool ≃ bool) → Id (map-equiv e true) true →
is-decidable (Id (map-equiv e false) false) → Id (map-equiv e false) false
eq-false-equiv' e p (inl q) = q
eq-false-equiv' e p (inr x) =
ind-empty
( Eq-𝟚-eq true false
( ap pr1
( is-prop-is-contr'
( is-contr-map-is-equiv (is-equiv-map-equiv e) true)
( pair true p)
( pair false (eq-true (map-equiv e false) x)))))
eq-false-equiv :
(e : bool ≃ bool) → Id (map-equiv e true) true → Id (map-equiv e false) false
eq-false-equiv e p =
eq-false-equiv' e p (has-decidable-equality-𝟚 (map-equiv e false) false)
{-
eq-true-equiv :
(e : bool ≃ bool) →
¬ (Id (map-equiv e true) true) → Id (map-equiv e false) true
eq-true-equiv e f = {!!}
issec-bool-aut-bool' :
( e : bool ≃ bool) (d : is-decidable (Id (map-equiv e true) true)) →
htpy-equiv (aut-bool-bool (bool-aut-bool e)) e
issec-bool-aut-bool' e (inl p) true =
( htpy-equiv-eq (ap aut-bool-bool p) true) ∙ (inv p)
issec-bool-aut-bool' e (inl p) false =
( htpy-equiv-eq (ap aut-bool-bool p) false) ∙
( inv (eq-false-equiv e p))
issec-bool-aut-bool' e (inr f) true =
( htpy-equiv-eq
( ap aut-bool-bool (eq-false (map-equiv e true) f)) true) ∙
( inv (eq-false (map-equiv e true) f))
issec-bool-aut-bool' e (inr f) false =
( htpy-equiv-eq (ap aut-bool-bool {!eq-true-equiv e ?!}) {!!}) ∙
( inv {!!})
issec-bool-aut-bool :
(aut-bool-bool ∘ bool-aut-bool) ~ id
issec-bool-aut-bool e =
eq-htpy-equiv
( issec-bool-aut-bool' e
( has-decidable-equality-𝟚 (map-equiv e true) true))
-}
-- Exercise
unit-classical-Prop : classical-Prop lzero
unit-classical-Prop =
pair (pair {!!} {!!}) {!!}
raise-unit-classical-Prop :
(l : Level) → classical-Prop l
raise-unit-classical-Prop l =
pair
( pair
( raise l unit)
( is-prop-is-equiv' unit
( map-raise l unit)
( is-equiv-map-raise l unit)
( is-prop-unit)))
( inl (map-raise l unit star))
bool-classical-Prop :
(l : Level) → classical-Prop l → bool
bool-classical-Prop l (pair P (inl x)) = true
bool-classical-Prop l (pair P (inr x)) = false
classical-Prop-bool :
(l : Level) → bool → classical-Prop l
classical-Prop-bool l true = raise-unit-classical-Prop l
classical-Prop-bool l false = {!!}
-- Exercise
{- We show that group homomorphisms preserve the unit. -}
preserves-unit :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Semi-Group
( semi-group-Group G)
( semi-group-Group H)) →
UU l2
preserves-unit G H f =
Id (map-hom-Group G H f (unit-Group G)) (unit-Group H)
abstract
preserves-unit-group-hom :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Group G H) → preserves-unit G H f
preserves-unit-group-hom
( pair ( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair ( pair e-G (pair left-unit-G right-unit-G))
( pair i-G (pair left-inv-G right-inv-G))))
( pair ( pair (pair H is-set-H) (pair μ-H assoc-H))
( pair ( pair e-H (pair left-unit-H right-unit-H))
( pair i-H (pair left-inv-H right-inv-H))))
( pair f μ-f) =
( inv (left-unit-H (f e-G))) ∙
( ( ap (λ x → μ-H x (f e-G)) (inv (left-inv-H (f e-G)))) ∙
( ( assoc-H (i-H (f e-G)) (f e-G) (f e-G)) ∙
( ( ap (μ-H (i-H (f e-G))) (inv (μ-f e-G e-G))) ∙
( ( ap (λ x → μ-H (i-H (f e-G)) (f x)) (left-unit-G e-G)) ∙
( left-inv-H (f e-G))))))
{- We show that group homomorphisms preserve inverses. -}
preserves-inverses :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Group G H) → UU (l1 ⊔ l2)
preserves-inverses G H f =
( x : type-Group G) →
Id ( map-hom-Group G H f (inv-Group G x))
( inv-Group H (map-hom-Group G H f x))
abstract
preserves-inverses-group-hom' :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Group G H) →
preserves-unit G H f → preserves-inverses G H f
preserves-inverses-group-hom'
( pair ( pair (pair G is-set-G) (pair μ-G assoc-G))
( pair ( pair e-G (pair left-unit-G right-unit-G))
( pair i-G (pair left-inv-G right-inv-G))))
( pair ( pair (pair H is-set-H) (pair μ-H assoc-H))
( pair ( pair e-H (pair left-unit-H right-unit-H))
( pair i-H (pair left-inv-H right-inv-H))))
( pair f μ-f) preserves-unit-f x =
( inv ( right-unit-H (f (i-G x)))) ∙
( ( ap (μ-H (f (i-G x))) (inv (right-inv-H (f x)))) ∙
( ( inv (assoc-H (f (i-G x)) (f x) (i-H (f x)))) ∙
( ( inv (ap (λ y → μ-H y (i-H (f x))) (μ-f (i-G x) x))) ∙
( ( ap (λ y → μ-H (f y) (i-H (f x))) (left-inv-G x)) ∙
( ( ap
( λ y → μ-H y (i-H (f x)))
( preserves-unit-f)) ∙
( left-unit-H (i-H (f x))))))))
abstract
preserves-inverses-group-hom :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
( f : hom-Group G H) → preserves-inverses G H f
preserves-inverses-group-hom G H f =
preserves-inverses-group-hom' G H f (preserves-unit-group-hom G H f)
hom-Group' :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) → UU (l1 ⊔ l2)
hom-Group' G H =
Σ ( hom-Group G H) (λ f →
( preserves-unit G H f) × (preserves-inverses G H f))
preserves-all-hom-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) →
hom-Group G H → hom-Group' G H
preserves-all-hom-Group G H f =
pair f
( pair
( preserves-unit-group-hom G H f)
( preserves-inverses-group-hom G H f))
-- Exercise
{-
hom-mul-Group :
{l : Level} (G : Group l) →
hom-Group G Aut
-}
| 33.394909
| 88
| 0.58182
|
dc408084b892ab26d6a41bfd1d46b7cd857746b1
| 4,945
|
agda
|
Agda
|
src/Data/Context.agda
|
sstucki/f-omega-int-agda
|
ae648c9520895a8428a7ad80f47bb55ecf4d50ea
|
[
"MIT"
] | 12
|
2017-06-13T16:05:35.000Z
|
2021-09-27T05:53:06.000Z
|
src/Data/Context.agda
|
sstucki/f-omega-int-agda
|
ae648c9520895a8428a7ad80f47bb55ecf4d50ea
|
[
"MIT"
] | 1
|
2021-05-14T08:09:40.000Z
|
2021-05-14T08:54:39.000Z
|
src/Data/Context.agda
|
sstucki/f-omega-int-agda
|
ae648c9520895a8428a7ad80f47bb55ecf4d50ea
|
[
"MIT"
] | 2
|
2021-05-13T22:29:48.000Z
|
2021-05-14T10:25:05.000Z
|
------------------------------------------------------------------------
-- Abstract typing contexts
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Data.Context where
open import Data.Fin using (Fin)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Extra using (Extension)
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Vec as Vec using (Vec; []; _∷_)
open import Relation.Unary using (Pred)
------------------------------------------------------------------------
-- Abstract typing contexts and context extensions.
infixr 5 _∷_
-- Typing contexts.
--
-- A |Ctx T n| is an indexed sequences of T-typed bindings mapping n
-- variables to T-types with 0 to (n - 1) free variables each. Like
-- lists (Data.List) and vectors (Data.Vec), contexts are cons
-- sequences, i.e. new bindings are added to the front (rather than
-- the back, as is more common in the literature). For example, a
-- typing context Γ represented in the usual notation as
--
-- Γ = xᵢ: Aᵢ, ..., x₁: A₁, x₀: A₀
--
-- is represented here by a term |Γ : Ctx Type i| of the form
--
-- Γ = A₀ ∷ A₁ ∷ ... ∷ Aᵢ
--
-- which is consistent with A₀ being the 0-th element of Γ, and with
-- the de Bruijn convention that the 0-th variable corresponds to the
-- closest binding.
data Ctx {ℓ} (T : Pred ℕ ℓ) : ℕ → Set ℓ where
[] : Ctx T zero
_∷_ : ∀ {n} → T n → Ctx T n → Ctx T (suc n)
module _ {ℓ} {T : Pred ℕ ℓ} where
head : ∀ {n} → Ctx T (suc n) → T n
head (t ∷ ts) = t
tail : ∀ {n} → Ctx T (suc n) → Ctx T n
tail (t ∷ ts) = ts
-- Drop the m innermost elements of a context Γ.
drop : ∀ {n} m → Ctx T (m + n) → Ctx T n
drop zero Γ = Γ
drop (suc m) (_ ∷ Γ) = drop m Γ
-- A map function that changes the entries in a context pointwise.
map : ∀ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {n} →
(∀ {k} → T₁ k → T₂ k) → Ctx T₁ n → Ctx T₂ n
map f [] = []
map f (t ∷ Γ) = f t ∷ map f Γ
-- Extensions of typing contexts.
--
-- Context extensions are indexed sequences of bindings that can be
-- concatenated to the front of a typing context. A |CtxExt T m n| is
-- an extension mapping n variables to T-types with m to (n + m - 1)
-- free variables each.
--
-- NOTE. It is tempting to define contexts as just a special case of
-- context extensions, i.e. as
--
-- Ctx T n = CtxExt T zero n
--
-- But this leads to problems when defining e.g. concatenation because
-- of the way context extensions are indexed. This could be remedied
-- by indexing context extensions differently, but then the definition
-- of |mapExt| below becomes difficult. An earlier version of this
-- module contained two different (but equivalent) representations for
-- context extensions, but this complicated (rather than simplified)
-- the development overall.
data CtxExt {ℓ} (T : Pred ℕ ℓ) (m : ℕ) : ℕ → Set ℓ where
[] : CtxExt T m zero
_∷_ : ∀ {l} → T (l + m) → CtxExt T m l → CtxExt T m (suc l)
infixr 5 _++_
-- Concatenation of context extensions with contexts.
_++_ : ∀ {ℓ} {T : Pred ℕ ℓ} {m n} → CtxExt T m n → Ctx T m → Ctx T (n + m)
[] ++ Γ = Γ
(t ∷ Δ) ++ Γ = t ∷ (Δ ++ Γ)
-- A map function that point-wise re-indexes and changes the entries
-- in a context extension.
mapExt : ∀ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {m n k} →
(∀ l → T₁ (l + m) → T₂ (l + n)) → CtxExt T₁ m k → CtxExt T₂ n k
mapExt f [] = []
mapExt f (_∷_ {l} t Γ) = f l t ∷ mapExt (λ l → f l) Γ
-- Operations on contexts that require weakening of types.
module WeakenOps {ℓ} {T : Pred ℕ ℓ} (extension : Extension T) where
-- Weakening of types.
open Extension extension public
-- Convert a context or context extension to its vector representation.
toVec : ∀ {n} → Ctx T n → Vec (T n) n
toVec [] = []
toVec (t ∷ Γ) = weaken t /∷ toVec Γ
extToVec : ∀ {k m n} → CtxExt T m n → Vec (T m) k → Vec (T (n + m)) (n + k)
extToVec [] ts = ts
extToVec (t ∷ Γ) ts = weaken t /∷ extToVec Γ ts
-- Lookup the type of a variable in a context or context extension.
lookup : ∀ {n} → Ctx T n → Fin n → T n
lookup Γ x = Vec.lookup (toVec Γ) x
extLookup : ∀ {k m n} → CtxExt T m n → Vec (T m) k → Fin (n + k) → T (n + m)
extLookup Δ ts x = Vec.lookup (extToVec Δ ts) x
-- Operations on contexts that require substitutions in types.
module SubstOps {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂}
(application : Application T₁ T₂)
(simple : Simple T₂)
where
open Application application public -- Application of T′ substitutions to Ts.
open Simple simple public -- Simple T′ substitutions.
-- Application of substitutions to context extensions.
infixl 8 _E/_
_E/_ : ∀ {k m n} → CtxExt T₁ m k → Sub T₂ m n → CtxExt T₁ n k
Γ E/ σ = mapExt (λ l t → t / σ ↑⋆ l) Γ
| 33.412162
| 79
| 0.584226
|
22b314237638ab5281e363d4e72efadb696b5b71
| 76
|
agda
|
Agda
|
Cubical/Codata/EverythingSafe.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Codata/EverythingSafe.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Codata/EverythingSafe.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Codata.EverythingSafe where
| 25.333333
| 42
| 0.736842
|
41df20bb6ad67269da7817e830c63500f684a81c
| 1,606
|
agda
|
Agda
|
TotalParserCombinators/Derivative/Corollaries.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
TotalParserCombinators/Derivative/Corollaries.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
TotalParserCombinators/Derivative/Corollaries.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some corollaries
------------------------------------------------------------------------
module TotalParserCombinators.Derivative.Corollaries where
open import Data.List
open import Function
open import Function.Inverse using (_↔_)
import Function.Related as Related
import Relation.Binary.PropositionalEquality as P
open import TotalParserCombinators.Derivative.Definition
open import TotalParserCombinators.Derivative.LeftInverse
open import TotalParserCombinators.Derivative.RightInverse
open import TotalParserCombinators.Derivative.SoundComplete
open import TotalParserCombinators.Parser
open import TotalParserCombinators.Semantics
-- D is correct.
correct : ∀ {Tok R xs x s} {t} {p : Parser Tok R xs} →
x ∈ D t p · s ↔ x ∈ p · t ∷ s
correct {p = p} = record
{ to = P.→-to-⟶ $ sound p
; from = P.→-to-⟶ complete
; inverse-of = record
{ left-inverse-of = complete∘sound p
; right-inverse-of = sound∘complete
}
}
-- D is monotone.
mono : ∀ {Tok R xs₁ xs₂ t}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ≲ p₂ → D t p₁ ≲ D t p₂
mono p₁≲p₂ = complete ∘ p₁≲p₂ ∘ sound _
-- D preserves parser and language equivalence.
cong : ∀ {k Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ] p₂ → ∀ {t} → D t p₁ ∼[ k ] D t p₂
cong {p₁ = p₁} {p₂} p₁≈p₂ {t} {x} {s} =
x ∈ D t p₁ · s ↔⟨ correct ⟩
x ∈ p₁ · t ∷ s ∼⟨ p₁≈p₂ ⟩
x ∈ p₂ · t ∷ s ↔⟨ sym correct ⟩
x ∈ D t p₂ · s ∎
where open Related.EquationalReasoning
| 31.490196
| 72
| 0.590909
|
1c5b3076987ef39b359ea606912f4b15f67108f8
| 7,328
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/On.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/On.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/On.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Many properties which hold for _∼_ also hold for _∼_ on f
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Construct.On where
open import Function
open import Data.Product
module _ {a b} {A : Set a} {B : Set b} (f : B → A) where
implies : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (∼ : Rel A ℓ₂) →
≈ ⇒ ∼ → (≈ on f) ⇒ (∼ on f)
implies _ _ impl = impl
reflexive : ∀ {ℓ} (∼ : Rel A ℓ) → Reflexive ∼ → Reflexive (∼ on f)
reflexive _ refl = refl
irreflexive : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (∼ : Rel A ℓ₂) →
Irreflexive ≈ ∼ → Irreflexive (≈ on f) (∼ on f)
irreflexive _ _ irrefl = irrefl
symmetric : ∀ {ℓ} (∼ : Rel A ℓ) → Symmetric ∼ → Symmetric (∼ on f)
symmetric _ sym = sym
transitive : ∀ {ℓ} (∼ : Rel A ℓ) → Transitive ∼ → Transitive (∼ on f)
transitive _ trans = trans
antisymmetric : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (≤ : Rel A ℓ₂) →
Antisymmetric ≈ ≤ → Antisymmetric (≈ on f) (≤ on f)
antisymmetric _ _ antisym = antisym
asymmetric : ∀ {ℓ} (< : Rel A ℓ) → Asymmetric < → Asymmetric (< on f)
asymmetric _ asym = asym
respects : ∀ {ℓ p} (∼ : Rel A ℓ) (P : A → Set p) →
P Respects ∼ → (P ∘ f) Respects (∼ on f)
respects _ _ resp = resp
respects₂ : ∀ {ℓ₁ ℓ₂} (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) →
∼₁ Respects₂ ∼₂ → (∼₁ on f) Respects₂ (∼₂ on f)
respects₂ _ _ (resp₁ , resp₂) =
((λ {_} {_} {_} → resp₁) , λ {_} {_} {_} → resp₂)
decidable : ∀ {ℓ} (∼ : Rel A ℓ) → Decidable ∼ → Decidable (∼ on f)
decidable _ dec = λ x y → dec (f x) (f y)
total : ∀ {ℓ} (∼ : Rel A ℓ) → Total ∼ → Total (∼ on f)
total _ tot = λ x y → tot (f x) (f y)
trichotomous : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (< : Rel A ℓ₂) →
Trichotomous ≈ < → Trichotomous (≈ on f) (< on f)
trichotomous _ _ compare = λ x y → compare (f x) (f y)
isEquivalence : ∀ {ℓ} {≈ : Rel A ℓ} →
IsEquivalence ≈ → IsEquivalence (≈ on f)
isEquivalence {≈ = ≈} eq = record
{ refl = reflexive ≈ Eq.refl
; sym = symmetric ≈ Eq.sym
; trans = transitive ≈ Eq.trans
}
where module Eq = IsEquivalence eq
isPreorder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {∼ : Rel A ℓ₂} →
IsPreorder ≈ ∼ → IsPreorder (≈ on f) (∼ on f)
isPreorder {≈ = ≈} {∼} pre = record
{ isEquivalence = isEquivalence Pre.isEquivalence
; reflexive = implies ≈ ∼ Pre.reflexive
; trans = transitive ∼ Pre.trans
}
where module Pre = IsPreorder pre
isDecEquivalence : ∀ {ℓ} {≈ : Rel A ℓ} →
IsDecEquivalence ≈ → IsDecEquivalence (≈ on f)
isDecEquivalence {≈ = ≈} dec = record
{ isEquivalence = isEquivalence Dec.isEquivalence
; _≟_ = decidable ≈ Dec._≟_
}
where module Dec = IsDecEquivalence dec
isPartialOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →
IsPartialOrder ≈ ≤ →
IsPartialOrder (≈ on f) (≤ on f)
isPartialOrder {≈ = ≈} {≤} po = record
{ isPreorder = isPreorder Po.isPreorder
; antisym = antisymmetric ≈ ≤ Po.antisym
}
where module Po = IsPartialOrder po
isDecPartialOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →
IsDecPartialOrder ≈ ≤ →
IsDecPartialOrder (≈ on f) (≤ on f)
isDecPartialOrder dpo = record
{ isPartialOrder = isPartialOrder DPO.isPartialOrder
; _≟_ = decidable _ DPO._≟_
; _≤?_ = decidable _ DPO._≤?_
}
where module DPO = IsDecPartialOrder dpo
isStrictPartialOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} →
IsStrictPartialOrder ≈ < →
IsStrictPartialOrder (≈ on f) (< on f)
isStrictPartialOrder {≈ = ≈} {<} spo = record
{ isEquivalence = isEquivalence Spo.isEquivalence
; irrefl = irreflexive ≈ < Spo.irrefl
; trans = transitive < Spo.trans
; <-resp-≈ = respects₂ < ≈ Spo.<-resp-≈
}
where module Spo = IsStrictPartialOrder spo
isTotalOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →
IsTotalOrder ≈ ≤ →
IsTotalOrder (≈ on f) (≤ on f)
isTotalOrder {≈ = ≈} {≤} to = record
{ isPartialOrder = isPartialOrder To.isPartialOrder
; total = total ≤ To.total
}
where module To = IsTotalOrder to
isDecTotalOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →
IsDecTotalOrder ≈ ≤ →
IsDecTotalOrder (≈ on f) (≤ on f)
isDecTotalOrder {≈ = ≈} {≤} dec = record
{ isTotalOrder = isTotalOrder Dec.isTotalOrder
; _≟_ = decidable ≈ Dec._≟_
; _≤?_ = decidable ≤ Dec._≤?_
}
where module Dec = IsDecTotalOrder dec
isStrictTotalOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} →
IsStrictTotalOrder ≈ < →
IsStrictTotalOrder (≈ on f) (< on f)
isStrictTotalOrder {≈ = ≈} {<} sto = record
{ isEquivalence = isEquivalence Sto.isEquivalence
; trans = transitive < Sto.trans
; compare = trichotomous ≈ < Sto.compare
}
where module Sto = IsStrictTotalOrder sto
preorder : ∀ {p₁ p₂ p₃ b} {B : Set b} (P : Preorder p₁ p₂ p₃) →
(B → Preorder.Carrier P) → Preorder _ _ _
preorder P f = record
{ isPreorder = isPreorder f (Preorder.isPreorder P)
}
setoid : ∀ {s₁ s₂ b} {B : Set b} (S : Setoid s₁ s₂) →
(B → Setoid.Carrier S) → Setoid _ _
setoid S f = record
{ isEquivalence = isEquivalence f (Setoid.isEquivalence S)
}
decSetoid : ∀ {d₁ d₂ b} {B : Set b} (D : DecSetoid d₁ d₂) →
(B → DecSetoid.Carrier D) → DecSetoid _ _
decSetoid D f = record
{ isDecEquivalence = isDecEquivalence f (DecSetoid.isDecEquivalence D)
}
poset : ∀ {p₁ p₂ p₃ b} {B : Set b} (P : Poset p₁ p₂ p₃) →
(B → Poset.Carrier P) → Poset _ _ _
poset P f = record
{ isPartialOrder = isPartialOrder f (Poset.isPartialOrder P)
}
decPoset : ∀ {d₁ d₂ d₃ b} {B : Set b} (D : DecPoset d₁ d₂ d₃) →
(B → DecPoset.Carrier D) → DecPoset _ _ _
decPoset D f = record
{ isDecPartialOrder =
isDecPartialOrder f (DecPoset.isDecPartialOrder D)
}
strictPartialOrder :
∀ {s₁ s₂ s₃ b} {B : Set b} (S : StrictPartialOrder s₁ s₂ s₃) →
(B → StrictPartialOrder.Carrier S) → StrictPartialOrder _ _ _
strictPartialOrder S f = record
{ isStrictPartialOrder =
isStrictPartialOrder f (StrictPartialOrder.isStrictPartialOrder S)
}
totalOrder : ∀ {t₁ t₂ t₃ b} {B : Set b} (T : TotalOrder t₁ t₂ t₃) →
(B → TotalOrder.Carrier T) → TotalOrder _ _ _
totalOrder T f = record
{ isTotalOrder = isTotalOrder f (TotalOrder.isTotalOrder T)
}
decTotalOrder :
∀ {d₁ d₂ d₃ b} {B : Set b} (D : DecTotalOrder d₁ d₂ d₃) →
(B → DecTotalOrder.Carrier D) → DecTotalOrder _ _ _
decTotalOrder D f = record
{ isDecTotalOrder = isDecTotalOrder f (DecTotalOrder.isDecTotalOrder D)
}
strictTotalOrder :
∀ {s₁ s₂ s₃ b} {B : Set b} (S : StrictTotalOrder s₁ s₂ s₃) →
(B → StrictTotalOrder.Carrier S) → StrictTotalOrder _ _ _
strictTotalOrder S f = record
{ isStrictTotalOrder =
isStrictTotalOrder f (StrictTotalOrder.isStrictTotalOrder S)
}
| 35.746341
| 73
| 0.556905
|
294f5ba694ae76e01ea1c4b1ee44f2c94d22993c
| 2,740
|
agda
|
Agda
|
src/STLCRef/Eval.agda
|
ajrouvoet/implicits.agda
|
ef2e347a4470e55083c83b743efbc2902ef1ad22
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/STLCRef/Eval.agda
|
ElessarWebb/implicits.agda
|
ef2e347a4470e55083c83b743efbc2902ef1ad22
|
[
"MIT"
] | null | null | null |
src/STLCRef/Eval.agda
|
ElessarWebb/implicits.agda
|
ef2e347a4470e55083c83b743efbc2902ef1ad22
|
[
"MIT"
] | null | null | null |
module STLCRef.Eval where
open import Prelude
open import Data.Product
open import Data.List
open import Data.List.Reverse
open import Data.Nat
open import Data.Fin hiding (_<_)
open import Extensions.List as L
open import STLCRef.Syntax
open import STLCRef.Welltyped
_!!_ : ∀ {n i} → (μ : Store n) → i < length μ → ∃ (Val {n})
_!!_ {i = i} [] ()
_!!_ {i = zero} (x ∷ μ) (s≤s p) = x
_!!_ {i = suc i} (x ∷ μ) (s≤s p) = μ !! p
Config : (n : ℕ) → Set
Config n = Exp n × Store n
infixl 1 _≻_
data _≻_ : ∀ {n} → Config n → Config n → Set where
---------------------------------------
-- Reduction rules
---------------------------------------
-- β
AppAbs : ∀ {n} {A x} {e : Exp (suc n)} {μ : Store n} →
---------------------------------
(ƛ A e) · x , μ ≻ e / (sub x) , μ
-- new
RefVal : ∀ {n e} {μ : Store n} →
(v : Val e) →
--------------------------------------------
(ref e , μ) ≻ (loc (length μ) , μ ∷ʳ (, v))
-- load
DerefLoc : ∀ {n i} {μ : Store n} →
(p : i < length μ) →
---------------------------------------------------
(! (loc i) , μ) ≻ (proj₁ (μ !! p) , μ)
-- store
Assign : ∀ {i n e} {μ : Store n} →
(p : i < length μ) →
(v : Val e) →
----------------------------------------------
loc i ≔ e , μ ≻ unit , (μ L.[ fromℕ≤ p ]≔ (, v))
---------------------------------------
-- contextual closure
---------------------------------------
Ref : ∀ {n e'} {e : Exp n} {μ μ'} →
(e , μ) ≻ (e' , μ') →
---------------------------------------
(ref e) , μ ≻ (ref e') , μ'
Appₗ : ∀ {n f' e} {f : Exp n} {μ μ'} →
(f , μ) ≻ (f' , μ') →
---------------------------------------
(f · e) , μ ≻ (f' · e) , μ'
Appᵣ : ∀ {n e' e} {f : Exp n} {μ μ'} →
(e , μ) ≻ (e' , μ') →
---------------------------------------
(f · e) , μ ≻ (f · e') , μ'
Deref : ∀ {n} {e : Exp n} {e'} {μ μ'} →
e , μ ≻ e' , μ' →
---------------------------------------
! e , μ ≻ ! e' , μ'
Assign₁ : ∀ {n} {e₁ : Exp n} {e₁' e₂} {μ μ'} →
e₁ , μ ≻ e₁' , μ' →
---------------------------------------
e₁ ≔ e₂ , μ ≻ e₁' ≔ e₂ , μ'
Assign₂ : ∀ {n} {e₁ : Exp n} {e₂' e₂} {μ μ'} →
e₂ , μ ≻ e₂' , μ' →
---------------------------------------
e₁ ≔ e₂ , μ ≻ e₁ ≔ e₂' , μ'
------------------------------------------------
-- Reflexive-transitive closure of step relation
------------------------------------------------
open import Data.Star
infixl 1 _≻*_
_≻*_ : ∀ {n} → Config n → Config n → Set
c ≻* c' = Star _≻_ c c'
| 28.247423
| 64
| 0.295985
|
1c7ae2295f991205521ae7739db4b609438af5f9
| 112
|
agda
|
Agda
|
test/Compiler/simple/Erased-cubical-Pattern-matching-Cubical.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/Erased-cubical-Pattern-matching-Cubical.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/simple/Erased-cubical-Pattern-matching-Cubical.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical #-}
module Erased-cubical-Pattern-matching-Cubical where
data D : Set where
c₁ c₂ : D
| 16
| 52
| 0.696429
|
20b6f65465cdb14baa846d7c92240a9d9c653790
| 13,062
|
agda
|
Agda
|
src/Numeric/Nat/Prime.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Numeric/Nat/Prime.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Numeric/Nat/Prime.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Numeric.Nat.Prime where
open import Prelude hiding (less-antirefl)
open import Numeric.Nat.GCD
open import Numeric.Nat.Divide
open import Numeric.Nat.Divide.Properties
open import Numeric.Nat.DivMod
open import Numeric.Nat.Sqrt
open import Numeric.Nat.Properties
open import Tactic.Nat
data Prime (n : Nat) : Set where
prime : n > 1 → (∀ k → k Divides n → Either (k ≡ 1) (k ≡ n)) → Prime n
private
lem : (a b : Nat) → b > 1 → suc a < suc a * b
lem a .(suc (k + 1)) (diff! k) = auto
data Composite (n : Nat) : Set where
composite : ∀ a b → a > 1 → b > 1 → a * b ≡ n → Composite n
pattern composite! a b 1<a 1<b = composite a b 1<a 1<b refl
composite-not-prime : ∀ {n} → Composite n → Prime n → ⊥
composite-not-prime (composite! 0 b (diff _ ()) _)
composite-not-prime (composite! (suc a) b sa>1 b>1) (prime _ f) =
case f (suc a) (divides-mul-l b divides-refl) of λ
{ (left sa=1) → less-antirefl sa>1 (sym sa=1)
; (right sa=sab) → less-antirefl (lem a b b>1) sa=sab
}
data Prime? n : Set where
yes : Prime n → Prime? n
no : Composite n → Prime? n
tiny : LessNat n 2 → Prime? n
private
less-inv : ∀ {a b} → ¬ LessNat a b → LessNat b (suc a)
less-inv {a} {b} a≮b with compare a b
less-inv a≮b | less a<b = ⊥-elim (a≮b a<b)
less-inv a≮b | equal refl = diff! 0
less-inv a≮b | greater a>b = by a>b
data _∈[_,_] (n a b : Nat) : Set where
in-range : a ≤ n → n ≤ b → n ∈[ a , b ]
empty-range : ∀ {n a b} → a > b → ¬ (n ∈[ a , b ])
empty-range a>b (in-range a≤n n≤b) = less-not-geq a>b (a≤n ⟨≤⟩ n≤b)
below-range : ∀ {n a b} → n < a → ¬ (n ∈[ a , b ])
below-range n<a (in-range a≤n _) = less-not-geq n<a a≤n
range-lower-bound : ∀ {n a b} → n ∈[ a , b ] → a ≤ n
range-lower-bound (in-range a<n _) = a<n
range-upper-bound : ∀ {n a b} → n ∈[ a , b ] → n ≤ b
range-upper-bound (in-range _ n<b) = n<b
singleton-range : ∀ {n a} → n ∈[ a , a ] → a ≡ n
singleton-range (in-range a<n n<a) = leq-antisym a<n n<a
suc-range-r : ∀ {n a b} → n ∈[ a , b ] → n ∈[ a , suc b ]
suc-range-r (in-range a<n n<b) = in-range a<n (by n<b)
suc-range-l : ∀ {n a b} → n ∈[ suc a , b ] → n ∈[ a , b ]
suc-range-l (in-range a<n n<b) = in-range (by a<n) n<b
in-range-l : ∀ {a b} → a ≤ b → a ∈[ a , b ]
in-range-l a<b = in-range (diff! 0) a<b
in-range-r : ∀ {a b} → a ≤ b → b ∈[ a , b ]
in-range-r a<b = in-range a<b (diff! 0)
non-zero-range : ∀ {n a b} → n ∈[ suc a , b ] → NonZero n
non-zero-range {zero} {a} (in-range (diff k eq) _) = refute eq
non-zero-range {suc _} _ = _
erase-in-range : ∀ {n a b} → n ∈[ a , b ] → n ∈[ a , b ]
erase-in-range r = in-range (fast-diff (range-lower-bound r))
(fast-diff (range-upper-bound r))
data _∈[_,_]? k a b : Set where
inside : k ∈[ a , b ] → k ∈[ a , b ]?
below : k < a → k ∈[ a , b ]?
above : k > b → k ∈[ a , b ]?
cmp-leq : (a b : Nat) → Either (a < b) (b ≤ a)
cmp-leq a b with compare a b
cmp-leq a b | less a<b = left a<b
cmp-leq a b | equal a=b = right (diff 0 (cong suc a=b))
cmp-leq a b | greater a>b = right (by a>b)
in-range? : ∀ k a b → k ∈[ a , b ]?
in-range? k a b with cmp-leq k a
in-range? k a b | left k<a = below k<a
in-range? k a b | right k≥a with cmp-leq b k
in-range? k a b | right k≥a | left k>b = above k>b
in-range? k a b | right k≥a | right k≤b = inside (in-range k≥a k≤b)
data FindInRange {ℓ} a b (P : Nat → Set ℓ) : Set ℓ where
here : ∀ k → k ∈[ a , b ] → P k → FindInRange a b P
none : (∀ k → k ∈[ a , b ] → ¬ P k) → FindInRange a b P
-- Version with less evidence. Faster to compute.
data FindInRange! {ℓ} (P : Nat → Set ℓ) : Set ℓ where
here : ∀ k → P k → FindInRange! P
none : FindInRange! P
private
not-first : ∀ {ℓ} {P : Nat → Set ℓ} {a b} →
¬ P a → (∀ k → k ∈[ suc a , b ] → ¬ P k) →
∀ k → k ∈[ a , b ] → ¬ P k
not-first {a = a} !pa !pa+ k k∈r pk with compare k a
not-first !pa !pa+ k k∈r pk | less k<a = below-range k<a k∈r
not-first !pa !pa+ k k∈r pk | equal refl = !pa pk
not-first !pa !pa+ k (in-range _ k≤b) pk | greater k>a = !pa+ k (in-range (by k>a) k≤b) pk
find! : ∀ {ℓ} {P : Nat → Set ℓ} (a d : Nat) → (∀ k → Dec (P k)) → FindInRange! P
find! a zero check = none
find! a (suc d) check with check a
find! a (suc d) check | yes pa = here a pa
find! a (suc d) check | no _ = force a λ a → find! (suc a) d check
found-in-range : ∀ {ℓ} {P : Nat → Set ℓ} a b d (eq : d + a ≡ suc b) (check : ∀ k → Dec (P k)) →
∀ k (pk : P k) → find! a d check ≡ here k pk → k ∈[ a , b ]
found-in-range a b zero eq check k pk ()
found-in-range a b (suc d) eq check k pk feq with check a
found-in-range a b (suc d) eq check .a pa refl | yes .pa = in-range-l (by eq)
found-in-range 0 b (suc d) eq check k pk feq | no !pa
with find! 1 d check | found-in-range 1 b d (by eq) check
found-in-range 0 b (suc d) eq check k pk refl | no !pa | here .k .pk | rec = suc-range-l (rec _ _ refl)
found-in-range 0 b (suc d) eq check k pk () | no !pa | none | rec
found-in-range (suc a) b (suc d) eq check k pk feq | no !pa
with find! (2 + a) d check | found-in-range (2 + a) b d (by eq) check
found-in-range (suc a) b (suc d) eq check k pk refl | no !pa | here .k .pk | rec = suc-range-l (rec _ _ refl)
found-in-range (suc a) b (suc d) eq check k pk () | no !pa | none | rec
not-found-in-range : ∀ {ℓ} {P : Nat → Set ℓ} a b d (eq : d + a ≡ suc b) (check : ∀ k → Dec (P k)) →
find! a d check ≡ none → ∀ k → k ∈[ a , b ] → ¬ P k
not-found-in-range 0 b zero eq check prf k k∈ab pk = empty-range (diff 0 eq) k∈ab
not-found-in-range (suc _) b zero eq check prf k k∈ab pk = empty-range (diff 0 eq) k∈ab
not-found-in-range a b (suc d) eq check prf k (in-range a<k k<b) pk with check a
not-found-in-range a b (suc d) eq check () k (in-range a<k k<b) pk | yes pa
not-found-in-range 0 b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa
with find! 1 d check | not-found-in-range 1 b d (by eq) check
not-found-in-range 0 b (suc d) eq check () k (in-range a<k k<b) pk | no !pa | here _ _ | rec
not-found-in-range 0 b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa | none | rec =
not-first !pa (rec refl) k (in-range a<k k<b) pk
not-found-in-range (suc a) b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa
with find! (suc (suc a)) d check | not-found-in-range (suc (suc a)) b d (by eq) check
not-found-in-range (suc a) b (suc d) eq check () k (in-range a<k k<b) pk | no !pa | here _ _ | rec
not-found-in-range (suc a) b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa | none | rec =
not-first !pa (rec refl) k (in-range a<k k<b) pk
find : ∀ {ℓ} {P : Nat → Set ℓ} a b d → d + a ≡ suc b → (∀ k → Dec (P k)) → FindInRange a b P
find a b d eq check with inspect (find! a d check)
... | here k pk with≡ prf = here k (erase-in-range (found-in-range a b d eq check k pk prf)) pk
... | none with≡ prf = none (not-found-in-range a b d eq check prf)
findInRange : ∀ {ℓ} {P : Nat → Set ℓ} a b → (∀ k → Dec (P k)) → FindInRange a b P
findInRange a b check with compare a b
findInRange a ._ check | less (diff! k) = find a _ (2 + k) refl check
findInRange a .a check | equal refl = find a _ 1 refl check
findInRange a b check | greater gt = none (λ k k∈ab _ → empty-range gt k∈ab)
--- Reducing the required search space to 2..√a ---
private
lem-less : {n r d q : Nat} → r ^ 2 ≥ n →
q * d ≡ n → r < d → suc r ≤ q → ⊥
lem-less (diff k eq) refl (diff j refl) (diff! i) = refute eq
non-zero-less : ∀ {a} {{_ : NonZero a}} → 0 < a
non-zero-less {0} {{}}
non-zero-less {suc a} = diff a auto
div-unique : ∀ q {a b} {{_ : NonZero b}} → q * b ≡ a → a div b ≡ q
div-unique q {a} {b} eq = quot-unique (qr (a div b) (a mod b) (mod-less b a) (divmod-sound b a))
(qr q 0 non-zero-less (by eq))
divide-smaller : ∀ n r d {{_ : NonZero d}} → n ≤ r ^ 2 → d Divides n → d > r → n div d ≤ r
divide-smaller n r d n<r² (factor q eq) d>r =
let n/d=q : n div d ≡ q
n/d=q = div-unique q eq
in less-raa (lem-less n<r² (cong (_* d) n/d=q ⟨≡⟩ eq) d>r)
divide-bigger : ∀ n k {{_ : NonZero k}} → k < n → k Divides n → n div k ≥ 2
divide-bigger ._ k (diff! k₁) (factor zero eq) = refute eq
divide-bigger n k k<n (factor 1 eq) = ⊥-elim (less-antirefl k<n (by eq))
divide-bigger n k k<n (factor (suc (suc q)) eq) = by (sym (div-unique (2 + q) {b = k} eq))
up-to-root : ∀ r n → r ≤ n → r ^ 2 ≥ suc n → FindInRange 2 r (_Divides suc n) → FindInRange 2 n (_Divides suc n)
up-to-root r n r<n r²>n (none k∤sn) =
none λ k k∈2n k|sn → erase-⊥ $
case in-range? k 2 r of λ
{ (inside k∈2r) → k∤sn k k∈2r k|sn
; (below k<2) → less-not-geq k<2 (range-lower-bound k∈2n)
; (above k>r) →
let instance k≠0 : NonZero k
k≠0 = non-zero-range k∈2n
hi : suc n div k ≤ r
hi = divide-smaller (suc n) r k r²>n k|sn k>r
lo : suc n div k ≥ 2
lo = divide-bigger (suc n) k (range-upper-bound k∈2n) k|sn
in k∤sn (suc n div k) (in-range lo hi) (factor k (by (div-divides k|sn)))
}
up-to-root 0 _ _ _ (here k k∈⊥ _) = ⊥-elim (empty-range (diff! 1) k∈⊥)
up-to-root (suc r) n r<n r²>n (here k (in-range 2<k k<r) pk) =
here k (in-range 2<k (k<r ⟨≤⟩ r<n)) pk
private
is-1-or-n : ∀ {n} → (∀ k → k ∈[ 2 , n ] → k Divides suc n → ⊥) →
∀ k → k Divides suc n → Either (k ≡ 1) (k ≡ suc n)
is-1-or-n {n} no-div k (factor q kq=n) with in-range? k 2 n
is-1-or-n no-div k (factor q kq=n) | inside inr = ⊥-elim (no-div k inr (factor q kq=n))
is-1-or-n no-div .1 (factor q kq=n) | below (diff! zero) = left refl
is-1-or-n {n} no-div k (factor q kq=n) | below (diff (suc k₁) eq) =
refute (divides-zero (transport (_Divides suc n) (by eq) (factor q kq=n)))
is-1-or-n {n} no-div k (factor q kq=n) | above k>n =
right (leq-antisym {A = Nat} (divides-less (factor q kq=n)) (by k>n))
lem₂ : ∀ {n d : Nat} q → q * d ≡ suc n → d < suc n → q > 1
lem₂ 0 eq d≤n = refute eq
lem₂ 1 eq d≤n = ⊥-elim (less-antirefl d≤n (by eq))
lem₂ (suc (suc q)) eq d≤n = auto
two-is-prime : ∀ k → k Divides 2 → Either (k ≡ 1) (k ≡ 2)
two-is-prime k k|2 with divides-less k|2
two-is-prime 0 (factor q eq) | k≤2 = refute eq
two-is-prime 1 k|2 | k≤2 = left refl
two-is-prime 2 k|2 | k≤2 = right refl
two-is-prime (suc (suc (suc k))) k|2 | lt = refute lt
lem-sqrt : (n r : Nat) → r ^ 2 < 4 + n → ¬ (suc n < r)
lem-sqrt n ._ lt (diff! c) = refute lt
sqrt-less : (n : Nat) → n > 2 → suc (sqrt! n) < n
sqrt-less 0 (diff k ())
sqrt-less 1 (diff k eq) = refute eq
sqrt-less 2 (diff k eq) = refute eq
sqrt-less (suc (suc (suc n))) _ with sqrt (3 + n)
sqrt-less (suc (suc (suc n))) _ | root r lt _ =
less-raa λ n<r → lem-sqrt n r lt (by n<r)
isPrimeAux : ∀ n → Comparison _<_ 2 n → Prime? n
isPrimeAux 0 _ = tiny (diff! 1)
isPrimeAux 1 _ = tiny (diff! 0)
isPrimeAux 2 _ = yes (prime (diff! 0) two-is-prime)
isPrimeAux (suc (suc (suc n))) (greater (diff k eq)) = refute eq
isPrimeAux (suc (suc (suc _))) (equal ())
isPrimeAux (suc n) (less n>2) with sqrt (suc n) | sqrt-less _ n>2
... | root r r²<n sr²>n | r<n with up-to-root (suc r) n r<n (by sr²>n) $
findInRange 2 (suc r) (λ k → k divides? suc n)
... | none p = yes (prime (by n>2) (is-1-or-n p))
... | here d (in-range 2≤d d≤n) (factor q eq) =
no (composite d q (by 2≤d) (lem₂ q eq d≤n) (by eq))
isPrime : ∀ n → Prime? n
isPrime n = isPrimeAux n (compare 2 n)
isPrime! : Nat → Bool
isPrime! n with isPrime n
... | yes _ = true
... | no _ = false
... | tiny _ = false
decPrime : ∀ p → Dec (Prime p)
decPrime p =
case isPrime p of λ where
(yes isp) → yes isp
(no comp) → no (composite-not-prime comp)
(tiny p<2) → no λ where (prime p>1 dp) → less-not-geq p>1 p<2
-- Benchmarking
-- Todo: test only odd numbers
-- Composite
-- 5.0s + isPrime 1927 (41 * 47)
-- 40ms recurse from below
-- 5.2s + isPrime (1021 * 1021)
-- 0.2s remove range argument from check
-- 0.8s + isPrime (3581 * 3581)
-- 0.3s don't compute in-range proof in find!
-- Prime (no proof)
-- 2.3s + isPrime! 1021
-- 5.0s recurse from below
-- 0.1s remove range argument from check
-- 0.7s + isPrime! 3581
-- Prime (run proof: cheap because we're not actually running the (negative) function computed by find)
-- 0.7s + testPrimeProof 3581
-- Prime (print proof)
-- 1.8s + isPrime 83
-- 3.4s recurse from below
-- 2.6s remove range argument from check
-- 0.1s split negative proof into separate function
-- 0.6s + isPrime 3581
-- 0.2s only check up to sqrt
-- 0.7s + isPrime 12823607
-- 2.3s + isPrime 234576373
-- 1.4s don't compute in-range proof in find!
| 42.686275
| 114
| 0.546624
|
313268fe40662385ea10e2e72b6c6aa67be00170
| 7,997
|
agda
|
Agda
|
HoTT/HLevel.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
HoTT/HLevel.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
HoTT/HLevel.agda
|
michaelforney/hott
|
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
|
[
"0BSD"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Identity
open import HoTT.Identity.Boolean
open import HoTT.Identity.Coproduct
open import HoTT.Identity.Sigma
open import HoTT.Identity.Identity
open import HoTT.Identity.Pi
open import HoTT.Identity.NaturalNumber
open import HoTT.Transport.Identity
open import HoTT.Equivalence
open import HoTT.Equivalence.Lift
open import HoTT.Equivalence.Transport
open import HoTT.Homotopy
module HoTT.HLevel where
open variables
private variable n : ℕ
isContr : 𝒰 i → 𝒰 i
isContr A = Σ[ a ∶ A ] Π[ x ∶ A ] (a == x)
-- Use a record so that we can use instances (technique from HoTT-Agda)
record hlevel (n : ℕ) (A : 𝒰 i) : 𝒰 i
hlevel-type : ℕ → 𝒰 i → 𝒰 i
hlevel-type zero = isContr
hlevel-type (succ n) A = {x y : A} → hlevel n (x == y)
record hlevel n A where
inductive
eta-equality
constructor hlevel-in
field hlevel-out : hlevel-type n A
open hlevel public
center : ⦃ hlevel 0 A ⦄ → A
center ⦃ hlevel-in (c , _) ⦄ = c
contr : ⦃ _ : hlevel 0 A ⦄ {x : A} → center == x
contr ⦃ hlevel-in (_ , p) ⦄ = p _
isProp : 𝒰 i → 𝒰 i
isProp A = (x y : A) → x == y
record hlevel𝒰 (n : ℕ) (i : _) : 𝒰 (lsuc i) where
constructor type
infix 90 _ty
field
_ty : 𝒰 i
⦃ h ⦄ : hlevel n _ty
open hlevel𝒰 using (_ty) public
Prop𝒰 = hlevel𝒰 1
Prop𝒰₀ = Prop𝒰 lzero
isSet : 𝒰 i → 𝒰 i
isSet A = {x y : A} → isProp (x == y)
Set𝒰 = hlevel𝒰 2
Set𝒰₀ = Set𝒰 lzero
instance
=-hlevel : {x y : A} → ⦃ hlevel (succ n) A ⦄ → hlevel n (x == y)
=-hlevel ⦃ hlevel-in h ⦄ = h
_◃_ : 𝒰 i → 𝒰 j → 𝒰 (i ⊔ j)
A ◃ B = Σ (A → B) rinv
infixr 5 _◃_
-- Theorem 7.1.4
retract-hlevel : A ◃ B → ⦃ hlevel n A ⦄ → hlevel n B
retract-hlevel {n = zero} (p , s , ε) = hlevel-in (p center , λ b → ap p contr ∙ ε b)
retract-hlevel {A = A} {B = B} {n = succ n} (p , s , ε) =
hlevel-in (retract-hlevel {n = n} r)
where
-- t =
r : {y y' : B} → (s y == s y') ◃ (y == y')
r {y} {y'} = t , ap s , λ u →
ε y ⁻¹ ∙ ap p (ap s u) ∙ ε y' =⟨ _ ∙ₗ ap-∘ p s u ⁻¹ ∙ᵣ _ ⟩
ε y ⁻¹ ∙ ap (p ∘ s) u ∙ ε y' =⟨ assoc ⁻¹ ⟩
ε y ⁻¹ ∙ (ap (p ∘ s) u ∙ ε y') =⟨ pivotₗ (~-natural-id ε u) ⁻¹ ⟩
u ∎
where
open =-Reasoning
t : _
t q = ε y ⁻¹ ∙ ap p q ∙ ε y'
equiv-hlevel : A ≃ B → ⦃ hlevel n A ⦄ → hlevel n B
equiv-hlevel e = retract-hlevel (pr₁ e , qinv→rinv (isequiv→qinv (pr₂ e)))
Π-implicit-equiv : ({x : A} → P x) ≃ Π A P
Π-implicit-equiv = iso→eqv λ{.f x _ → x ; .g h → h _ ; .η _ → refl ; .ε _ → refl}
where open Iso
raise : ⦃ {_ : A} → hlevel n A ⦄ → hlevel (succ n) A
raise {n = zero} ⦃ f ⦄ = hlevel-in λ {x} →
hlevel-in (contr ⦃ f {x} ⦄ ⁻¹ ∙ contr , λ{refl → invₗ})
raise {n = succ n} ⦃ f ⦄ = hlevel-in λ {x} →
raise ⦃ =-hlevel ⦃ f {x} ⦄ ⦄
add : ℕ → ℕ → ℕ
add n zero = n
add n (succ m) = succ (add n m)
raise* : {A : 𝒰 i} → ⦃ hlevel n A ⦄ → {m : ℕ} → hlevel (add n (succ m)) A
raise* {m = zero} = raise
raise* {m = succ m} = raise ⦃ raise* ⦄
instance
Lift-hlevel : ⦃ hlevel n A ⦄ → hlevel n (Lift {i} A)
Lift-hlevel = equiv-hlevel (Lift-equiv ⁻¹ₑ)
𝟎-hlevel : hlevel (succ n) (𝟎 {i})
𝟎-hlevel {zero} = hlevel-in λ where {()}
𝟎-hlevel {succ _} = raise
𝟏-hlevel : hlevel n (𝟏 {i})
𝟏-hlevel {zero} = hlevel-in (★ , λ where ★ → refl)
𝟏-hlevel {succ _} = raise
𝟐-hlevel : hlevel (succ (succ n)) 𝟐
𝟐-hlevel {n} = hlevel-in (equiv-hlevel (=𝟐-equiv ⁻¹ₑ))
where
code-hlevel : {x y : 𝟐} → hlevel (succ n) (x =𝟐 y)
code-hlevel {0₂} {0₂} = ⟨⟩
code-hlevel {0₂} {1₂} = ⟨⟩
code-hlevel {1₂} {0₂} = ⟨⟩
code-hlevel {1₂} {1₂} = ⟨⟩
instance _ = code-hlevel
Π-hlevel : ⦃ {x : A} → hlevel n (P x) ⦄ → hlevel n (Π A P)
Π-hlevel {n = zero} = hlevel-in ((λ _ → center) , (λ _ → funext λ _ → contr))
Π-hlevel {n = succ n} = hlevel-in (equiv-hlevel (=Π-equiv ⁻¹ₑ))
Π-implicit-hlevel : ⦃ {x : A} → hlevel n (P x) ⦄ → hlevel n ({x : A} → P x)
Π-implicit-hlevel = equiv-hlevel (Π-implicit-equiv ⁻¹ₑ)
+-hlevel : ⦃ hlevel (succ (succ n)) A ⦄ → ⦃ hlevel (succ (succ n)) B ⦄ →
hlevel (succ (succ n)) (A + B)
+-hlevel {n} {A = A} {B = B} = hlevel-in (equiv-hlevel (=+-equiv ⁻¹ₑ))
where
code-hlevel : {x y : A + B} → hlevel (succ n) (x =+ y)
code-hlevel {inl _} {inl _} = ⟨⟩
code-hlevel {inl _} {inr _} = ⟨⟩
code-hlevel {inr _} {inl _} = ⟨⟩
code-hlevel {inr _} {inr _} = ⟨⟩
instance _ = code-hlevel
ℕ-hlevel : hlevel 2 ℕ
hlevel-out ℕ-hlevel {x} = equiv-hlevel (=ℕ-equiv ⁻¹ₑ)
where
code-hlevel : {x y : ℕ} → hlevel 1 (x =ℕ y)
code-hlevel {zero} {zero} = ⟨⟩
code-hlevel {zero} {succ y} = ⟨⟩
code-hlevel {succ x} {zero} = ⟨⟩
code-hlevel {succ x} {succ y} = code-hlevel {x}
instance _ = code-hlevel {x}
-- Make Σ-hlevel a private instance so it can be installed as-needed.
-- There are too many cases where we want to use some other instance
-- instead.
Σ-hlevel : ⦃ h₁ : hlevel n A ⦄ → ⦃ h₂ : {x : A} → hlevel n (P x) ⦄ → hlevel n (Σ A P)
private instance _ = Σ-hlevel
Σ-hlevel {n = zero} = hlevel-in ((center , center) , λ x → pair⁼' (contr , contr))
Σ-hlevel {n = succ n} = hlevel-in (equiv-hlevel (=Σ-equiv ⁻¹ₑ))
→-hlevel : ⦃ hlevel n B ⦄ → hlevel n (A → B)
→-hlevel = ⟨⟩
×-hlevel : ⦃ h₁ : hlevel n A ⦄ → ⦃ h₂ : hlevel n B ⦄ → hlevel n (A × B)
×-hlevel = ⟨⟩
isContr-hlevel : hlevel 1 (isContr A)
hlevel-out (isContr-hlevel {A = A}) {h} = ⟨⟩
where instance _ = raise* ⦃ hlevel-in h ⦄
hlevel-equiv : hlevel-type n A ≃ hlevel n A
hlevel-equiv = hlevel-in , qinv→isequiv (hlevel-out , (λ _ → refl) , (λ _ → refl))
instance
hlevel-hlevel : hlevel 1 (hlevel n A)
hlevel-hlevel {zero} = equiv-hlevel hlevel-equiv ⦃ isContr-hlevel ⦄
hlevel-hlevel {succ n} = equiv-hlevel hlevel-equiv
hlevel⁼ : ⦃ h₁ : hlevel n A ⦄ ⦃ h₂ : hlevel n B ⦄ → A == B → type A == type B
hlevel⁼ ⦃ h₁ ⦄ ⦃ h₂ ⦄ refl rewrite center ⦃ =-hlevel {x = h₁} {h₂} ⦄ = refl
hlevel1→isProp : ⦃ hlevel 1 A ⦄ → isProp A
hlevel1→isProp = center
hlevel2→isSet : ⦃ hlevel 2 A ⦄ → isSet A
hlevel2→isSet = center
isProp→hlevel1 : isProp A → hlevel 1 A
hlevel-out (isProp→hlevel1 f) {x} {y} = ⟨⟩
where instance _ = raise ⦃ hlevel-in (x , f x) ⦄
isProp-hlevel1 : hlevel 1 (isProp A)
hlevel-out isProp-hlevel1 {f} = ⟨⟩
where instance _ = raise ⦃ isProp→hlevel1 f ⦄
isProp-prop : isProp (isProp A)
isProp-prop = hlevel1→isProp ⦃ isProp-hlevel1 ⦄
isProp→isSet : isProp A → isSet A
isProp→isSet A-prop {x} {y} p q = center
where instance _ = raise ⦃ isProp→hlevel1 A-prop ⦄
isContr-prop : isProp (isContr A)
isContr-prop (a , p) (a' , p') = pair⁼ (p a' , center)
where instance _ = raise* ⦃ hlevel-in (a , p) ⦄
prop-equiv : ⦃ h₁ : hlevel 1 A ⦄ → ⦃ h₂ : hlevel 1 B ⦄ →
(A → B) → (B → A) → A ≃ B
prop-equiv f g = f , qinv→isequiv (g , (λ _ → center) , (λ _ → center))
Σ-contr₁ : ⦃ _ : hlevel 0 A ⦄ → Σ A P ≃ P center
Σ-contr₁ {A = A} {P = P} ⦃ h ⦄ = let open Iso in iso→eqv λ where
.f → transport P (contr ⁻¹) ∘ pr₂
.g y → center , y
.η x → pair⁼ (contr , Eqv.ε (transport-equiv (contr {A = A})) _)
.ε y → ap {x = contr ⁻¹} (λ p → transport P p y)
let instance _ = raise* ⦃ h ⦄ in center
Σ-contr₂ : ⦃ {x : A} → hlevel 0 (P x) ⦄ → Σ A P ≃ A
Σ-contr₂ = let open Iso in iso→eqv λ where
.f → pr₁
.g x → x , center
.η _ → pair⁼ (refl , contr)
.ε _ → refl
×-contr₁ : ⦃ hlevel 0 A ⦄ → A × B ≃ B
×-contr₁ = Σ-contr₁
×-contr₂ : ⦃ hlevel 0 B ⦄ → A × B ≃ A
×-contr₂ = Σ-contr₂
Π-contr₁ : ⦃ _ : hlevel 0 A ⦄ → Π A P ≃ P center
Π-contr₁ {A = A} {P = P} ⦃ h ⦄ = let open Iso in iso→eqv λ where
.f h → h center
.g x _ → transport P contr x
.η h → funext (λ _ → apd h contr)
.ε x → ap {x = contr} (λ p → transport P p x)
let instance _ = raise* ⦃ h ⦄ in center
=-contrₗ : (a : A) → hlevel 0 (Σ A (a ==_))
=-contrₗ a = hlevel-in ((a , refl) , λ (_ , p) →
pair⁼ (p , transport=-const-id p a refl ∙ unitₗ ⁻¹))
=-contrᵣ : (a : A) → hlevel 0 (Σ A (_== a))
=-contrᵣ a = hlevel-in ((a , refl) , λ (_ , p) →
pair⁼ (p ⁻¹ , transport=-id-const a (p ⁻¹) refl ∙ unitᵣ ⁻¹ ∙ invinv))
| 31.360784
| 85
| 0.566462
|
1a1afcc01ab3d9596da8ef301c83e6bb363ee0ee
| 803
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/Hmap.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/Hmap.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Oscar/Class/Hmap.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class
module Oscar.Class.Hmap where
module Hmap
{𝔵₁} {𝔛₁ : Ø 𝔵₁}
{𝔵₂} {𝔛₂ : Ø 𝔵₂}
{𝔯₁} {𝔯₂}
(ℜ₁ : 𝔛₁ → 𝔛₂ → Ø 𝔯₁)
(ℜ₂ : 𝔛₁ → 𝔛₂ → Ø 𝔯₂)
= ℭLASS (ℜ₁ , ℜ₂)
(∀ x y
→ ℜ₁ x y → ℜ₂ x y)
module _
{𝔵₁} {𝔛₁ : Ø 𝔵₁}
{𝔵₂} {𝔛₂ : Ø 𝔵₂}
{𝔯₁} {𝔯₂}
{ℜ₁ : 𝔛₁ → 𝔛₂ → Ø 𝔯₁}
{ℜ₂ : 𝔛₁ → 𝔛₂ → Ø 𝔯₂}
where
hmap = Hmap.method ℜ₁ ℜ₂
module _
{𝔵} {𝔛 : Ø 𝔵}
{𝔯₁} {𝔯₂}
{ℜ₁ : 𝔛 → 𝔛 → Ø 𝔯₁}
{ℜ₂ : 𝔛 → 𝔛 → Ø 𝔯₂}
where
smap : ⦃ _ : Hmap.class ℜ₁ ℜ₂ ⦄ → ∀ {x y} → ℜ₁ x y → ℜ₂ x y
smap = Hmap.method ℜ₁ ℜ₂ _ _
§ = smap
module _
{𝔵} {𝔛 : Ø 𝔵}
{𝔯₁} {𝔯₂}
{ℜ₁ : 𝔛 → 𝔛 → Ø 𝔯₁}
(ℜ₂ : 𝔛 → 𝔛 → Ø 𝔯₂)
where
smap[_] : ⦃ _ : Hmap.class ℜ₁ ℜ₂ ⦄ → ∀ {x y} → ℜ₁ x y → ℜ₂ x y
smap[_] = Hmap.method ℜ₁ ℜ₂ _ _
§[_] = smap[_]
| 17.844444
| 64
| 0.465753
|
5992cb2243f111147c2a5930dff6166d30989518
| 790
|
agda
|
Agda
|
src/Categories/Functor/Construction/SubCategory.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Functor/Construction/SubCategory.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Functor/Construction/SubCategory.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Functor.Construction.SubCategory {o ℓ e} (C : Category o ℓ e) where
open import Categories.Category.SubCategory C
open Category C
open Equiv
open import Level
open import Function.Base using () renaming (id to id→)
open import Data.Product
open import Categories.Functor using (Functor)
private
variable
ℓ′ i : Level
I : Set i
U : I → Obj
Sub : ∀ (sub : SubCat {i} {ℓ′} I) → Functor (SubCategory sub) C
Sub (record {U = U}) = record
{ F₀ = U
; F₁ = proj₁
; identity = refl
; homomorphism = refl
; F-resp-≈ = id→
}
FullSub : Functor (FullSubCategory U) C
FullSub {U = U} = record
{ F₀ = U
; F₁ = id→
; identity = refl
; homomorphism = refl
; F-resp-≈ = id→
}
| 19.268293
| 85
| 0.64557
|
2975e9dbde598ba28e2d6fdc4db01c1c7581ef41
| 74
|
agda
|
Agda
|
test-lib/src/Test.agda
|
phile314/agda-build
|
fe6be7731e968c78aef73f4fc14bf7976a607c79
|
[
"BSD-3-Clause"
] | null | null | null |
test-lib/src/Test.agda
|
phile314/agda-build
|
fe6be7731e968c78aef73f4fc14bf7976a607c79
|
[
"BSD-3-Clause"
] | null | null | null |
test-lib/src/Test.agda
|
phile314/agda-build
|
fe6be7731e968c78aef73f4fc14bf7976a607c79
|
[
"BSD-3-Clause"
] | null | null | null |
module Test where
open import Agda.Primitive
f : Level -> Level
f x = x
| 10.571429
| 26
| 0.702703
|
41ace045c22719b170bc52d16bb68c3dcfa41862
| 19,545
|
agda
|
Agda
|
examples/AIM5/yoshiki/SET.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/AIM5/yoshiki/SET.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/AIM5/yoshiki/SET.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-------------------------------------------------------------------------------
--
-- SET (in Hedberg library) for agda2
-- as of 2006.9.29 morning
-- Yoshiki.
--
module SET where
----------------------------------------------------------------------------
-- Auxiliary.
----------------------------------------------------------------------------
-- no : (x : A) -> B : Set if A : Set B : Set
-- yes : (x : A) -> B type if A type B type
-- El M type if M : Set
data Unop (A : Set) : Set1 where
unopI : (A -> A) -> Unop A
data Pred (A : Set) : Set1 where
PredI : (A -> Set) -> Pred A
data Rel (A : Set) : Set1 where
RelI : (A -> A -> Set) -> Rel A
data Reflexive {A : Set} (R : A -> A -> Set) : Set where
reflexiveI : ((a : A) -> R a a) -> Reflexive R
data Symmetrical {A : Set} (R : A -> A -> Set) : Set where
symmetricalI : ({a b : A} -> R a b -> R a b) -> Symmetrical R
data Transitive {A : Set} (R : A -> A -> Set) : Set where
transitiveI : ({a b c : A} -> R a b -> R b c -> R a c) -> Transitive R
compositionalI :
{A : Set} -> (R : A -> A -> Set)
-> ({a b c : A} -> R b c -> R a b -> R a c) -> Transitive R
compositionalI {A} R f =
transitiveI (\{a b c : A} -> \(x : R a b) -> \(y : R b c) -> f y x)
data Substitutive {A : Set} (R : A -> A -> Set) : Set1 where
substitutiveI : ((P : A -> Set) -> {a b : A} -> R a b -> P a -> P b)
-> Substitutive R
data Collapsed (A : Set) : Set1 where
collapsedI : ((P : A -> Set) -> {a b : A} -> P a -> P b) -> Collapsed A
cmp : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C
cmp f g a = f (g a)
seq : {A B C : Set} -> (A -> B) -> (B -> C) -> A -> C
seq f g = cmp g f
S : {A B C : Set} -> (C -> B -> A) -> (C -> B) -> C -> A
S x y z = x z (y z)
K : {A B : Set} -> A -> B -> A
K x y = x
I : {A : Set} -> A -> A
I a = a
-- of course I = S K K
id = \{A : Set} -> I {A}
const = \{A B : Set} -> K {A}{B}
-- Set version
pS : {P Q R : Set} -> (R -> Q -> P) -> (R -> Q) -> R -> P
pS x y z = x z (y z)
pK : {P Q : Set} -> P -> Q -> P
pK x y = x
pI : {P : Set} -> P -> P
pI a = a
proj : {A : Set} -> (B : A -> Set) -> (a : A) -> (f : (aa : A) -> B aa) -> B a
proj B a f = f a
flip : {A B C : Set} (f : A -> B -> C) (b : B) (a : A) -> C
flip f b a = f a b
-- separate definition of FlipRel is necessary because it is not the case
-- that Set : Set.
FlipRel : {A : Set} -> (R : A -> A -> Set) -> (a b : A) -> Set
FlipRel R a b = R b a
----------------------------------------------------------------------------
-- Product sets.
----------------------------------------------------------------------------
-- Prod : (A : Set) -> (A -> Set) -> Set
-- Prod A B = (a : A) -> B a
-- The above is not type-correct since (a : A) -> B a is not well-formed
-- but the following works.
data Prod (A : Set) (B : A -> Set) : Set where
prodI : ((a : A) -> B a) -> Prod A B
mapProd : {A : Set} -> {B C : A -> Set} -> ((a : A) -> B a -> C a)
-> Prod A B -> Prod A C
mapProd {A} f (prodI g) = prodI (\(a : A) -> f a (g a))
-- data Fun (A B : Set) : Set1 where
-- funI : (A -> B) -> Fun A B
Fun : Set -> Set -> Set
Fun A B = Prod A (\(_ : A) -> B)
mapFun : {A B C D : Set} -> (B -> A) -> (C -> D) -> (A -> C) -> B -> D
mapFun {A} {B} {C} {D} f g h x = g (h (f x))
-- mapFun (|X1 |X2 |Y1 |Y2 :: Set)
-- :: (X2 -> X1) -> (Y1 -> Y2) -> (X1 -> Y1) -> X2 -> Y2
-- = \f -> \g -> \h -> \x ->
-- g (h (f x))
---------------------------------------------------------------------------
-- Identity proof sets.
---------------------------------------------------------------------------
-- to accept the following definition more general scheme of
-- inductive definition is required
-- data Id (A : Set) (a b : A) : Set1 where
-- ref : (a : A) -> Id A a a
--
-- elimId (|X :: Set)
-- (C :: (x1 x2 :: X) |-> Id x1 x2 -> Set)
-- (refC :: (x :: X) -> C (refId x))
-- (|x1 |x2 :: X)
-- (u :: Id x1 x2) ::
-- C u
-- = case u of { (ref x) -> refC x;}
--
-- abstract whenId (|X :: Set)(C :: Rel X)(c :: (x :: X) -> C x x)
-- :: (x1 x2 :: X) |-> Id x1 x2 -> C x1 x2
-- = elimId (\x1 x2 |-> \(u :: Id x1 x2) -> C x1 x2) c
--
-- abstract substId (|X :: Set) :: Substitutive Id
-- = \(C :: Pred X) ->
-- whenId (\x1 x2 -> C x1 -> C x2) (\x -> id)
--
-- abstract mapId (|X :: Set)(|Y :: Set)(f :: X -> Y)
-- :: (x1 x2 :: X) |-> Id x1 x2 -> Id (f x1) (f x2)
-- = whenId (\x1 x2 -> Id (f x1) (f x2)) (\(x :: X) -> refId (f x))
--
-- abstract symId (|X :: Set) :: Symmetrical Id
-- = whenId (\(x1 x2 :: X) -> Id x2 x1) refId
--
-- abstract cmpId (|X :: Set) :: Compositional Id
-- = let lem :: (x y :: X) |-> Id x y -> (z :: X) |-> Id z x -> Id z y
-- = whenId ( \(x y :: _) -> (z :: X) |-> Id z x -> Id z y)
-- ( \x -> \z |-> id)
-- in \(x1 x2 x3 :: _) |->
-- \(u :: Id x2 x3) ->
-- \(v :: Id x1 x2) ->
-- lem u v
--
-- abstract tranId (|X :: Set) :: Transitive Id
-- = \(x1 x2 x3 :: X) |->
-- \(u :: Id x1 x2) ->
-- \(v :: Id x2 x3) ->
-- cmpId v u
----------------------------------------------------------------------------
-- The empty set.
----------------------------------------------------------------------------
data Zero : Set where
-- --abstract whenZero (X :: Set)(z :: Zero) :: X
-- -- = case z of { }
-- do not know how to encode whenZero; the following does not work.
-- whenZero : (X : Set) -> (z : Zero) -> X
-- whenZero X z =
-- --elimZero (C :: Zero -> Set)(z :: Zero) :: C z
-- -- = case z of { }
-- elimZero either!
-- elimZero : (C : Zero -> Set) -> (z : Zero) -> C z
-- elimZero C z =
--
-- abstract collZero :: Collapsed Zero
-- = \(C :: Zero -> Set) ->
-- \(z1 z2 :: Zero) |->
-- \(c :: C z1) ->
-- case z1 of { }
--
----------------------------------------------------------------------------
-- The singleton set.
----------------------------------------------------------------------------
data Unit : Set where
uu : Unit
elUnit = uu
elimUnit : (C : Unit -> Set) -> C uu -> (u : Unit) -> C u
elimUnit C c uu = c
-- Do not know of the exact use of Collapse!
-- collUnit : (C : Unit -> Set) -> {u1 u2 : Unit} -> C u1 -> Collapsed Unit
-- collUnit C {uu} {uu} A = collapsedI (\(P : Unit -> Set) -> \{a b : Unit} -> \(y : P a) -> A)
-- abstract collUnit :: Collapsed Unit
-- = \(C :: Unit -> Set) ->
-- \(u1 u2 :: Unit) |->
-- \(c :: C u1) ->
-- case u1 of { (tt) -> case u2 of { (tt) -> c;};}
---------------------------------------------------------------------------
-- The successor set adds a new element.
---------------------------------------------------------------------------
data Succ (A : Set) : Set where
zerS : Succ A
sucS : A -> Succ A
zerSucc = \{A : Set} -> zerS {A}
sucSucc = \{A : Set} -> sucS {A}
elimSucc : {X : Set} -> (C : Succ X -> Set)
-> C zerS -> ((x : X) -> C (sucS x)) -> (xx : Succ X) -> (C xx)
elimSucc C c_z c_s zerS = c_z
elimSucc C c_z c_s (sucS x) = c_s x
whenSucc : {X Y : Set} -> Y -> (X -> Y) -> (Succ X) -> Y
whenSucc y_z y_s zerS = y_z
whenSucc y_z y_s (sucS x) = y_s x
mapSucc : {X Y : Set} -> (X -> Y) -> Succ X -> Succ Y
mapSucc {X} {_} f
= whenSucc zerS (\(x : X) -> sucS (f x))
---------------------------------------------------------------------------
-- The (binary) disjoint union.
---------------------------------------------------------------------------
data Plus (A B : Set) : Set where
inl : A -> Plus A B
inr : B -> Plus A B
elimPlus : {X Y : Set} ->
(C : Plus X Y -> Set) ->
((x : X) -> C (inl x)) ->
((y : Y) -> C (inr y)) ->
(z : Plus X Y) ->
C z
elimPlus {X} {Y} C c_lft c_rgt (inl x) = c_lft x
elimPlus {X} {Y} C c_lft c_rgt (inr x) = c_rgt x
when : {X Y Z : Set} -> (X -> Z) -> (Y -> Z) -> Plus X Y -> Z
when {X} {Y} {Z} f g (inl x) = f x
when {X} {Y} {Z} f g (inr y) = g y
whenplus : {X Y Z : Set} -> (X -> Z) -> (Y -> Z) -> Plus X Y -> Z
whenplus = when
mapPlus : {X1 X2 Y1 Y2 : Set} -> (X1 -> X2) -> (Y1 -> Y2)
-> Plus X1 Y1 -> Plus X2 Y2
mapPlus f g = when (\x1 -> inl (f x1)) (\y1 -> inr (g y1))
swapPlus : {X Y : Set} -> Plus X Y -> Plus Y X
swapPlus = when inr inl
----------------------------------------------------------------------------
-- Dependent pairs.
----------------------------------------------------------------------------
data Sum (A : Set) (B : A -> Set) : Set where
sumI : (fst : A) -> B fst -> Sum A B
depPair : {A : Set} -> {B : A -> Set} -> (a : A) -> B a -> Sum A B
depPair a b = sumI a b
depFst : {A : Set} -> {B : A -> Set} -> (c : Sum A B) -> A
depFst (sumI fst snd) = fst
depSnd : {A : Set} -> {B : A -> Set} -> (c : Sum A B) -> B (depFst c)
depSnd (sumI fst snd) = snd
depCur : {A : Set} -> {B : A -> Set} -> {C : Set} -> (f : Sum A B -> C)
-> (a : A) -> B a -> C
depCur f = \a -> \b -> f (depPair a b)
-- the above works but the below does not---why?
-- depCur : {X : Set} -> {Y : X -> Set} -> {Z : Set} -> (f : Sum X Y -> Z)
-- -> {x : X} -> Y x -> Z
-- depCur {X} {Y} {Z} f = \{x} -> \y -> f (depPair x y)
-- Error message :
-- When checking that the expression \{x} -> \y -> f (depPair x y)
-- has type Y _x -> Z
-- found an implicit lambda where an explicit lambda was expected
depUncur : {A : Set} -> {B : A -> Set} -> {C : Set}
-> ((a : A) -> B a -> C) -> Sum A B -> C
depUncur f ab = f (depFst ab) (depSnd ab)
depCurry : {A : Set} ->
{B : A -> Set} ->
{C : Sum A B -> Set} ->
(f : (ab : Sum A B) -> C ab) ->
(a : A) ->
(b : B a) ->
C (depPair a b)
depCurry f a b = f (depPair a b)
depUncurry : {A : Set} ->
{B : A -> Set} ->
{C : Sum A B -> Set} ->
(f : (a : A) -> (b : B a) -> C (depPair a b)) ->
(ab : Sum A B) ->
C ab
depUncurry f (sumI fst snd) = f fst snd
mapSum : {A : Set} -> {B1 : A -> Set} -> {B2 : A -> Set}
-> (f : (a : A) -> B1 a -> B2 a)
-> Sum A B1 -> Sum A B2
mapSum f (sumI fst snd) = depPair fst (f fst snd)
elimSum = \{A : Set}{B : A -> Set}{C : Sum A B -> Set} -> depUncurry{A}{B}{C}
---------------------------------------------------------------------------
-- Nondependent pairs (binary) cartesian product.
---------------------------------------------------------------------------
Times : Set -> Set -> Set
Times A B = Sum A (\(_ : A) -> B)
pair : {A : Set} -> {B : Set} -> A -> B -> Times A B
pair a b = sumI a b
fst : {A : Set} -> {B : Set} -> Times A B -> A
fst (sumI a _) = a
snd : {A : Set} -> {B : Set} -> Times A B -> B
snd (sumI _ b) = b
pairfun : {C : Set} -> {A : Set} -> {B : Set}
-> (C -> A) -> (C -> B) -> C -> Times A B
pairfun f g c = pair (f c) (g c)
mapTimes : {A1 : Set} -> {A2 : Set} -> {B1 : Set} -> {B2 : Set}
-> (A1 -> A2) -> (B1 -> B2) -> Times A1 B1 -> Times A2 B2
mapTimes f g (sumI a b) = pair (f a) (g b)
swapTimes : {A : Set} -> {B : Set} -> Times A B -> Times B A
swapTimes (sumI a b) = sumI b a
cur : {A : Set} -> {B : Set} -> {C : Set} -> (f : Times A B -> C) -> A -> B -> C
cur f a b = f (pair a b)
uncur : {A : Set} -> {B : Set} -> {C : Set} -> (A -> B -> C) -> Times A B -> C
uncur f (sumI a b) = f a b
curry : {A : Set} -> {B : Set} -> {C : Times A B -> Set}
-> ((p : Times A B) -> C p) -> (a : A) ->(b : B) -> C (pair a b)
curry f a b = f (pair a b)
uncurry : {A : Set} -> {B : Set} -> {C : Times A B -> Set}
-> ((a : A) -> (b : B) -> C (pair a b)) -> (p : Times A B) -> C p
uncurry f (sumI a b) = f a b
elimTimes = \{A B : Set}{C : Times A B -> Set} -> uncurry{A}{B}{C}
---------------------------------------------------------------------------
-- Natural numbers.
---------------------------------------------------------------------------
data Nat : Set where
zero : Nat
succ : Nat -> Nat
elimNat : (C : Nat -> Set)
-> (C zero) -> ((m : Nat) -> C m -> C (succ m)) -> (n : Nat) -> C n
elimNat C c_z c_s zero = c_z
elimNat C c_z c_s (succ m') = c_s m' (elimNat C c_z c_s m')
----------------------------------------------------------------------------
-- Linear universe of finite sets.
----------------------------------------------------------------------------
Fin : (m : Nat) -> Set
Fin zero = Zero
Fin (succ n) = Succ (Fin n)
{-
Fin 0 = {}
Fin 1 = { zerS }
Fin 2 = { zerS (sucS zerS) }
Fin 3 = { zerS (sucS zerS) (sucS (sucS zerS)) }
-}
valFin : (n' : Nat) -> Fin n' -> Nat
valFin zero ()
valFin (succ n) zerS = zero
valFin (succ n) (sucS x) = succ (valFin n x)
zeroFin : (n : Nat) -> Fin (succ n)
zeroFin n = zerS
succFin : (n : Nat) -> Fin n -> Fin (succ n)
succFin n N = sucS N
----------------------------------------------------------------------------
-- Do these really belong here?
----------------------------------------------------------------------------
HEAD : {A : Set} -> (n : Nat) -> (Fin (succ n) -> A) -> A
HEAD n f = f (zeroFin n)
TAIL : {A : Set} -> (n : Nat) -> (Fin (succ n) -> A) -> Fin n -> A
TAIL n f N = f (succFin n N)
----------------------------------------------------------------------------
-- Lists.
----------------------------------------------------------------------------
data List (A : Set) : Set where
nil : List A
con : A -> List A -> List A
elimList : {A : Set} ->
(C : List A -> Set) ->
(C nil) ->
((a : A) -> (as : List A) -> C as -> C (con a as)) ->
(as : List A) ->
C as
elimList _ c_nil _ nil = c_nil
elimList C c_nil c_con (con a as) = c_con a as (elimList C c_nil c_con as)
----------------------------------------------------------------------------
-- Tuples are "dependently typed vectors".
----------------------------------------------------------------------------
data Nill : Set where
nill : Nill
data Cons (A B : Set) : Set where
cons : A -> B -> Cons A B
Tuple : (n : Nat) -> (C : Fin n -> Set) -> Set
Tuple zero = \ C -> Nill
Tuple (succ n) = \ C -> Cons (C zerS) (Tuple n (\(N : Fin n) -> C (sucS N)))
----------------------------------------------------------------------------
-- Vectors homogeneously typed tuples.
----------------------------------------------------------------------------
Vec : Set -> Nat -> Set
Vec A m = Tuple m (\(n : Fin m) -> A)
----------------------------------------------------------------------------
-- Monoidal expressions.
----------------------------------------------------------------------------
data Mon (A : Set) : Set where
unit : Mon A
at : A -> Mon A
mul : Mon A -> Mon A -> Mon A
{-
-}
----------------------------------------------------------------------------
-- Propositions.
----------------------------------------------------------------------------
data Implies (A B : Set) : Set where
impliesI : (A -> B) -> Implies A B
data Absurd : Set where
data Taut : Set where
tt : Taut
data Not (P : Set) : Set where
notI : (P -> Absurd) -> Not P
-- encoding of Exists is unsatisfactory! Its type should be Set.
data Exists (A : Set) (P : A -> Set) : Set where
existsI : (evidence : A) -> P evidence -> Exists A P
data Forall (A : Set) (P : A -> Set) : Set where
forallI : ((a : A) -> P a) -> Forall A P
data And (A B : Set) : Set where
andI : A -> B -> And A B
Iff : Set -> Set -> Set
Iff A B = And (Implies A B) (Implies B A)
data Or (A B : Set) : Set where
orIl : (a : A) -> Or A B
orIr : (b : B) -> Or A B
Decidable : Set -> Set
Decidable P = Or P (Implies P Absurd)
data DecidablePred {A : Set} (P : A -> Set) : Set where
decidablepredIl : (a : A) -> (P a) -> DecidablePred P
decidablepredIr : (a : A) -> (Implies (P a) Absurd) -> DecidablePred P
data DecidableRel {A : Set} (R : A -> A -> Set) : Set where
decidablerelIl : (a b : A) -> (R a b) -> DecidableRel R
decidablerelIr : (a b : A) -> (Implies (R a b) Absurd) -> DecidableRel R
data Least {A : Set} (_<=_ : A -> A -> Set) (P : A -> Set) (a : A) : Set where
leastI : (P a) -> ((aa : A) -> P aa -> (a <= aa)) -> Least _<=_ P a
data Greatest {A : Set} (_<=_ : A -> A -> Set) (P : A -> Set) (a : A) : Set where
greatestI : (P a) -> ((aa : A) -> P aa -> (aa <= a)) -> Greatest _<=_ P a
----------------------------------------------------------------------------
-- Booleans.
----------------------------------------------------------------------------
data Bool : Set where
true : Bool
false : Bool
elimBool : (C : Bool -> Set) -> C true -> C false -> (b : Bool) -> C b
elimBool C c_t c_f true = c_t
elimBool C c_t c_f false = c_f
whenBool : (C : Set) -> C -> C -> Bool -> C
whenBool C c_t c_f b = elimBool (\(_ : Bool) -> C) c_t c_f b
data pred (A : Set) : Set where
predI : (A -> Bool) -> pred A
data rel (A : Set) : Set where
relI : (A -> A -> Bool) -> rel A
True : Bool -> Set
True true = Taut
True false = Absurd
bool2set = True
pred2Pred : {A : Set} -> pred A -> Pred A
pred2Pred (predI p) = PredI (\a -> True (p a))
rel2Rel : {A : Set} -> rel A -> Rel A
rel2Rel (relI r) = RelI (\a -> \b -> True (r a b))
-- decTrue : (p : Bool) -> Decidable (True p)
-- decTrue true = orIl tt
-- decTrue false = orIr (impliesI pI)
-- decTrue false = orIr (impliesI (\(p : (True false)) -> p))
-- dec_lem : {P : Set} -> (decP : Decidable P)
-- -> Exists A
{-
abstract dec_lem (|P :: Set)(decP :: Decidable P)
:: Exist |_ (\(b :: Bool) -> Iff (True b) P)
= case decP of {
(inl trueP) ->
struct {
fst = true@_;
snd =
struct {
fst = const |_ |_ trueP; -- (True true@_)
snd = const |_ |_ tt;};};
(inr notP) ->
struct {
fst = false@_;
snd =
struct {
fst = whenZero P;
snd = notP;};};}
dec2bool :: (P :: Set) |-> (decP :: Decidable P) -> Bool
= \(P :: Set) |-> \(decP :: Decidable P) -> (dec_lem |_ decP).fst
dec2bool_spec (|P :: Set)(decP :: Decidable P)
:: Iff (True (dec2bool |_ decP)) P
= (dec_lem |_ decP).snd
abstract collTrue :: (b :: Bool) -> Collapsed (True b)
= let aux (X :: Set)(C :: X -> Set)
:: (b :: Bool) ->
(f :: True b -> X) ->
(t1 :: True b) |->
(t2 :: True b) |->
C (f t1) -> C (f t2)
= \(b :: Bool) ->
case b of {
(true) ->
\(f :: (x :: True true@_) -> X) ->
\(t1 t2 :: True true@_) |->
\(c :: C (f t1)) ->
case t1 of { (tt) -> case t2 of { (tt) -> c;};};
(false) ->
\(f :: (x :: True false@_) -> X) ->
\(t1 t2 :: True false@_) |->
\(c :: C (f t1)) ->
case t1 of { };}
in \(b :: Bool) -> \(P :: True b -> Set) -> aux (True b) P b id
bool2nat (p :: Bool) :: Nat
= case p of {
(true) -> succ zero;
(false) -> zero;}
-}
| 39.246988
| 96
| 0.377846
|
c7cdb7ae88d13094ef05e49d5b874faa30dc20d2
| 2,935
|
agda
|
Agda
|
src/fot/FOTC/Relation/Binary/Bisimilarity/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Relation/Binary/Bisimilarity/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Relation/Binary/Bisimilarity/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Properties for the bisimilarity relation
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Relation.Binary.Bisimilarity.PropertiesATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Stream.Type
open import FOTC.Relation.Binary.Bisimilarity.Type
------------------------------------------------------------------------------
-- Because a greatest post-fixed point is a fixed-point, the
-- bisimilarity relation _≈_ on unbounded lists is also a pre-fixed
-- point of the bisimulation functional (see
-- FOTC.Relation.Binary.Bisimulation).
-- See Issue https://github.com/asr/apia/issues/81 .
≈-inB : D → D → Set
≈-inB xs ys = ∃[ x' ] ∃[ xs' ] ∃[ ys' ]
xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ xs' ≈ ys'
{-# ATP definition ≈-inB #-}
≈-in : ∀ {xs ys} →
∃[ x' ] ∃[ xs' ] ∃[ ys' ]
xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ xs' ≈ ys' →
xs ≈ ys
≈-in h = ≈-coind ≈-inB h' h
where
postulate
h' : ∀ {xs} {ys} → ≈-inB xs ys →
∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ ≈-inB xs' ys'
{-# ATP prove h' #-}
-- See Issue https://github.com/asr/apia/issues/81 .
≈-reflB : D → D → Set
≈-reflB xs ys = xs ≡ ys ∧ Stream xs
{-# ATP definition ≈-reflB #-}
≈-refl : ∀ {xs} → Stream xs → xs ≈ xs
≈-refl {xs} Sxs = ≈-coind ≈-reflB h₁ h₂
where
postulate
h₁ : ∀ {xs ys} → ≈-reflB xs ys →
∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ ≈-reflB xs' ys'
{-# ATP prove h₁ #-}
postulate h₂ : ≈-reflB xs xs
{-# ATP prove h₂ #-}
-- See Issue https://github.com/asr/apia/issues/81 .
≈-symB : D → D → Set
≈-symB xs ys = ys ≈ xs
{-# ATP definition ≈-symB #-}
≈-sym : ∀ {xs ys} → xs ≈ ys → ys ≈ xs
≈-sym {xs} {ys} xs≈ys = ≈-coind ≈-symB h₁ h₂
where
postulate
h₁ : ∀ {ys} {xs} → ≈-symB ys xs →
∃[ y' ] ∃[ ys' ] ∃[ xs' ] ys ≡ y' ∷ ys' ∧ xs ≡ y' ∷ xs' ∧ ≈-symB ys' xs'
{-# ATP prove h₁ #-}
postulate h₂ : ≈-symB ys xs
{-# ATP prove h₂ #-}
-- See Issue https://github.com/asr/apia/issues/81 .
≈-transB : D → D → Set
≈-transB xs zs = ∃[ ys ] xs ≈ ys ∧ ys ≈ zs
{-# ATP definition ≈-transB #-}
≈-trans : ∀ {xs ys zs} → xs ≈ ys → ys ≈ zs → xs ≈ zs
≈-trans {xs} {ys} {zs} xs≈ys ys≈zs = ≈-coind ≈-transB h₁ h₂
where
postulate
h₁ : ∀ {as} {cs} → ≈-transB as cs →
∃[ a' ] ∃[ as' ] ∃[ cs' ] as ≡ a' ∷ as' ∧ cs ≡ a' ∷ cs' ∧ ≈-transB as' cs'
{-# ATP prove h₁ #-}
postulate h₂ : ≈-transB xs zs
{-# ATP prove h₂ #-}
postulate ∷-injective≈ : ∀ {x xs ys} → x ∷ xs ≈ x ∷ ys → xs ≈ ys
{-# ATP prove ∷-injective≈ #-}
postulate ∷-rightCong≈ : ∀ {x xs ys} → xs ≈ ys → x ∷ xs ≈ x ∷ ys
{-# ATP prove ∷-rightCong≈ ≈-in #-}
| 31.55914
| 83
| 0.47632
|
22dbd04070eeb6cd04afb5ef4b81345777f96942
| 78
|
agda
|
Agda
|
test/Succeed/Issue2284.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2284.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2284.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS -WShadowingInTelescope #-}
bad : Set → Set → Set
bad = λ x x → x
| 15.6
| 38
| 0.602564
|
1d4f5ddf199bd80368cd82960d0308dfa51ee718
| 712
|
agda
|
Agda
|
test/Succeed/fol-theorems/Eta2.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Succeed/fol-theorems/Eta2.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Succeed/fol-theorems/Eta2.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
------------------------------------------------------------------------------
-- Testing the η-expansion
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Eta2 where
postulate
D : Set
∃ : (A : D → Set) → Set
_≡_ : D → D → Set
-- Due to η-contraction the Agda internal representation of foo and
-- bar are the same. We η-expand the internal types before the
-- translation to FOL.
postulate
foo : ∀ d → ∃ (λ e → d ≡ e)
bar : ∀ d → ∃ (_≡_ d)
{-# ATP prove foo #-}
{-# ATP prove bar #-}
| 27.384615
| 78
| 0.429775
|
23b3e61d701b71ac736c890f978366b1d139c9be
| 646
|
agda
|
Agda
|
test/Succeed/Issue2231sharp.agda
|
caryoscelus/agda
|
98d6f195fe672e54ef0389b4deb62e04e3e98327
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue2231sharp.agda
|
caryoscelus/agda
|
98d6f195fe672e54ef0389b4deb62e04e3e98327
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue2231sharp.agda
|
caryoscelus/agda
|
98d6f195fe672e54ef0389b4deb62e04e3e98327
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2016-10-03, re issue #2231
-- Termination checking a corecursive definition in abstract mode.
{-# OPTIONS --guardedness #-}
infix 1000 ♯_
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
abstract
data Functor : Set where
Id : Functor
_·_ : Functor → Set → Set
Id · A = A
data ν (F : Functor) : Set where
inn : ∞ (F · ν F) → ν F
-- Evaluation is required to see that Id · ν Id is a coinductive type.
foo : ∀ F → F · ν F
foo Id = inn (♯ foo Id)
-- The termination checker needs to treat the generated #-foo function
-- in abstract mode, to have constructor Id in scope.
| 22.275862
| 72
| 0.619195
|
c77649ea2f08c8d56df2b3341a10f5c1b32ec5c8
| 3,947
|
agda
|
Agda
|
src/Relation/Binary/Indexed/Extra.agda
|
banacorn/categories
|
9f6d933b227aecab338ecaef1d86566a54fdac68
|
[
"MIT"
] | 1
|
2018-01-04T23:19:30.000Z
|
2018-01-04T23:19:30.000Z
|
src/Relation/Binary/Indexed/Extra.agda
|
banacorn/categories
|
9f6d933b227aecab338ecaef1d86566a54fdac68
|
[
"MIT"
] | null | null | null |
src/Relation/Binary/Indexed/Extra.agda
|
banacorn/categories
|
9f6d933b227aecab338ecaef1d86566a54fdac68
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Extension The Agda standard library
--
-- Properties of indexed binary relations
------------------------------------------------------------------------
module Relation.Binary.Indexed.Extra where
open import Data.Product
open import Data.Sum
open import Function
open import Level
-- import Relation.Binary.PropositionalEquality.Core as PropEq
-- open import Relation.Binary.Consequences as Consequences
open import Relation.Binary.Core as Core using (_≡_)
open import Relation.Binary.Indexed.Core
open import Relation.Binary.Indexed
import Relation.Binary as B
------------------------------------------------------------------------
-- Simple properties and equivalence relations
-- open Core public hiding (_≡_; refl; _≢_)
--
-- open Consequences public using (Total)
------------------------------------------------------------------------
-- Simple properties of indexed binary relations
-- Implication/containment. Could also be written ⊆.
[_][_]_⇒_ : ∀ {i₁ i₂ a b ℓ₁ ℓ₂} {I₁ : Set i₁} {I₂ : Set i₂}
(A : I₁ → Set a) (B : I₂ → Set b)
→ REL A B ℓ₁ → REL A B ℓ₂ → Set _
[ A ][ B ] P ⇒ Q = ∀ {i₁ i₂} {x : A i₁} {y : B i₂} → P x y → Q x y
-- _Preserves_⟶_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : A → Set b} →
-- ((x : A) → B x) → B.Rel A ℓ₁ → Rel B ℓ₂ → Set (ℓ₂ ⊔ (ℓ₁ ⊔ a))
-- f Preserves P ⟶ Q = P =[ f ]⇒ Q
_Respects_ : ∀ {𝒾 a ℓ₁ ℓ₂} {I : Set 𝒾} {A : I → Set a} {i : I}
→ (A i → Set ℓ₁) → Rel A ℓ₂ → Set (ℓ₂ ⊔ (ℓ₁ ⊔ a))
P Respects _∼_ = ∀ {x y} → x ∼ y → P x → P y
[_]_Respects₂_ : ∀ {𝒾 a ℓ₁ ℓ₂} {I : Set 𝒾} (A : I → Set a)
→ Rel A ℓ₁ → Rel A ℓ₂ → Set (ℓ₂ ⊔ (ℓ₁ ⊔ (a ⊔ 𝒾)))
[ A ] P Respects₂ _∼_ =
(∀ {i} {x : A i} → _Respects_ {A = A} {i = i} (P x) _∼_) ×
(∀ {i} {y : A i} → _Respects_ {A = A} {i = i} (flip P y) _∼_)
------------------------------------------------------------------------
-- Preorders
record IsPreorder {𝒾 a ℓ₁ ℓ₂} {I : Set 𝒾} (A : I → Set a)
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_∼_ : Rel A ℓ₂) -- The relation.
: Set (𝒾 ⊔ a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isEquivalence : IsEquivalence A _≈_
-- Reflexivity is expressed in terms of an underlying equality:
reflexive : [ A ][ A ] _≈_ ⇒ _∼_
trans : Transitive A _∼_
module Eq = IsEquivalence isEquivalence
refl : Reflexive A _∼_
refl = reflexive Eq.refl
∼-resp-≈ : [ A ] _∼_ Respects₂ _≈_
∼-resp-≈ = (λ x≈y z∼x → trans z∼x (reflexive x≈y))
, (λ x≈y x∼z → trans (reflexive $ Eq.sym x≈y) x∼z)
record Preorder {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _∼_
field
Carrier : I → Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_∼_ : Rel Carrier ℓ₂ -- The relation.
isPreorder : IsPreorder Carrier _≈_ _∼_
open IsPreorder isPreorder public
SetoidIsPreorder : ∀ {𝒾} {I : Set 𝒾} {c ℓ} (S : Setoid I c ℓ) → IsPreorder (Setoid.Carrier S) (Setoid._≈_ S) (Setoid._≈_ S)
SetoidIsPreorder {𝒾} {I} S = record
{ isEquivalence = isEquivalence
; reflexive = id
; trans = IsEquivalence.trans isEquivalence
}
where
open Setoid S
Setoid⇒Preorder : ∀ {𝒾} {I : Set 𝒾} {c ℓ} (S : Setoid I c ℓ) → Preorder I c ℓ ℓ
Setoid⇒Preorder S = record { isPreorder = SetoidIsPreorder S }
-- record
-- { Carrier = {! !}
-- ; _≈_ = {! !}
-- ; _∼_ = {! !}
-- ; isPreorder = {! !}
-- }
-- IsEquivalence.reflexive (Setoid.isEquivalence S)
-- where open IsEquivalence {! !}
--
-- isPreorder : IsPreorder _≡_ _≈_
-- isPreorder = record
-- { isEquivalence = PropEq.isEquivalence
-- ; reflexive = reflexive
-- ; trans = trans
-- }
--
-- preorder : Preorder c c ℓ
-- preorder = record { isPreorder = isPreorder }
| 34.929204
| 123
| 0.505701
|
2997b43603b9db67aabedc18f5e7d64e5735278a
| 142
|
agda
|
Agda
|
test/Fail/PatternSynonymOverloaded.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/PatternSynonymOverloaded.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/PatternSynonymOverloaded.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module PatternSynonymOverloaded where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
pattern ss x = suc (suc x)
pattern ss x = suc x
| 15.777778
| 37
| 0.683099
|
297ec924917c7b4592ce37d2904220649feb7942
| 218
|
agda
|
Agda
|
Example/Test.agda
|
omelkonian/setup-agda
|
b987bcf8dbe1e1699405f26010273d562805258a
|
[
"MIT"
] | 2
|
2020-11-14T12:25:39.000Z
|
2022-03-05T19:15:16.000Z
|
Example/Test.agda
|
omelkonian/setup-agda
|
b987bcf8dbe1e1699405f26010273d562805258a
|
[
"MIT"
] | null | null | null |
Example/Test.agda
|
omelkonian/setup-agda
|
b987bcf8dbe1e1699405f26010273d562805258a
|
[
"MIT"
] | null | null | null |
module Example.Test where
open import Data.Maybe using (Is-just)
open import Prelude.Init
open import Prelude.DecEq
open import Prelude.Decidable
_ : (¬ ¬ ((true , true) ≡ (true , true)))
× (8 ≡ 18 ∸ 10)
_ = auto
| 18.166667
| 41
| 0.678899
|
59dec94f304a0ebcc557c96ca53eb8b19b428010
| 238
|
agda
|
Agda
|
test/Fail/NonTerminatingReduce.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/NonTerminatingReduce.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/NonTerminatingReduce.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
{-# NON_TERMINATING #-}
loop : Nat → Nat
loop n = loop n
thm : ∀ n → loop n ≡ 42
thm n = refl
| 14
| 42
| 0.542017
|
1c8e65494d3508ec43cd14d0c6dedd2ceab613ed
| 5,778
|
agda
|
Agda
|
src/Tactic/Reflection/Substitute.agda
|
L-TChen/agda-prelude
|
158d299b1b365e186f00d8ef5b8c6844235ee267
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Tactic/Reflection/Substitute.agda
|
L-TChen/agda-prelude
|
158d299b1b365e186f00d8ef5b8c6844235ee267
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Tactic/Reflection/Substitute.agda
|
L-TChen/agda-prelude
|
158d299b1b365e186f00d8ef5b8c6844235ee267
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Tactic.Reflection.Substitute where
open import Prelude hiding (abs)
open import Builtin.Reflection
open import Tactic.Reflection.DeBruijn
IsSafe : Term → Set
IsSafe (lam _ _) = ⊥
IsSafe _ = ⊤
data SafeTerm : Set where
safe : (v : Term) (p : IsSafe v) → SafeTerm
maybeSafe : Term → Maybe SafeTerm
maybeSafe (var x args) = just (safe (var x args) _)
maybeSafe (con c args) = just (safe (con c args) _)
maybeSafe (def f args) = just (safe (def f args) _)
maybeSafe (meta x args) = just (safe (meta x args) _)
maybeSafe (lam v t) = nothing
maybeSafe (pat-lam cs args) = just (safe (pat-lam cs args) _)
maybeSafe (pi a b) = just (safe (pi a b) _)
maybeSafe (agda-sort s) = just (safe (agda-sort s) _)
maybeSafe (lit l) = just (safe (lit l) _)
maybeSafe unknown = just (safe unknown _)
instance
DeBruijnSafeTerm : DeBruijn SafeTerm
strengthenFrom {{DeBruijnSafeTerm}} k n (safe v _) = do
-- Strengthening or weakening safe terms always results in safe terms,
-- but proving that is a bit of a bother, thus maybeSafe.
v₁ ← strengthenFrom k n v
maybeSafe v₁
weakenFrom {{DeBruijnSafeTerm}} k n (safe v p) =
maybe (safe unknown _) id (maybeSafe (weakenFrom k n v))
safe-term : SafeTerm → Term
safe-term (safe v _) = v
applyTerm : SafeTerm → List (Arg Term) → Term
applyTerm v [] = safe-term v
applyTerm (safe (var x args) _) args₁ = var x (args ++ args₁)
applyTerm (safe (con c args) _) args₁ = con c (args ++ args₁)
applyTerm (safe (def f args) _) args₁ = def f (args ++ args₁)
applyTerm (safe (meta x args) _) args₁ = meta x (args ++ args₁)
applyTerm (safe (lam v t) ()) args
applyTerm (safe (pat-lam cs args) _) args₁ = pat-lam cs (args ++ args₁)
applyTerm (safe (pi a b) _) _ = pi a b
applyTerm (safe (agda-sort s) _) _ = agda-sort s
applyTerm (safe (lit l) _) _ = lit l
applyTerm (safe unknown _) _ = unknown
Subst : Set → Set
Subst A = List SafeTerm → A → A
substTerm : Subst Term
substArgs : Subst (List (Arg Term))
substArg : Subst (Arg Term)
substAbs : Subst (Abs Term)
substSort : Subst Sort
substClauses : Subst (List Clause)
substClause : Subst Clause
substTerm σ (var x args) =
case index σ x of λ
{ nothing → var (x - length σ) (substArgs σ args)
; (just v) → applyTerm v (substArgs σ args) }
substTerm σ (con c args) = con c (substArgs σ args)
substTerm σ (def f args) = def f (substArgs σ args)
substTerm σ (meta x args) = meta x (substArgs σ args)
substTerm σ (lam v b) = lam v (substAbs σ b)
substTerm σ (pat-lam cs args) = pat-lam (substClauses σ cs) (substArgs σ args)
substTerm σ (pi a b) = pi (substArg σ a) (substAbs σ b)
substTerm σ (agda-sort s) = agda-sort (substSort σ s)
substTerm σ (lit l) = lit l
substTerm σ unknown = unknown
substSort σ (set t) = set (substTerm σ t)
substSort σ (lit n) = lit n
substSort σ (prop t) = prop (substTerm σ t)
substSort σ (propLit n) = propLit n
substSort σ (inf n) = inf n
substSort σ unknown = unknown
substClauses σ [] = []
substClauses σ (c ∷ cs) = substClause σ c ∷ substClauses σ cs
substClause σ (clause tel ps b) =
case length tel of λ
{ zero → clause tel ps (substTerm σ b)
; (suc n) → clause tel ps (substTerm (reverse (map (λ i → safe (var i []) _) (from 0 to n)) ++ weaken (suc n) σ) b)
}
substClause σ (absurd-clause tel ps) = absurd-clause tel ps
substArgs σ [] = []
substArgs σ (x ∷ args) = substArg σ x ∷ substArgs σ args
substArg σ (arg i x) = arg i (substTerm σ x)
substAbs σ (abs x v) = abs x $ substTerm (safe (var 0 []) _ ∷ weaken 1 σ) v
private
toArgs : Nat → List (Arg SafeTerm) → List (Arg Term)
toArgs k = map (λ x → weaken k (fmap safe-term x))
SafeApplyType : Set → Set
SafeApplyType A = List SafeTerm → Nat → A → List (Arg SafeTerm) → A
safeApplyAbs : SafeApplyType (Abs Term)
safeApplyArg : SafeApplyType (Arg Term)
safeApplySort : SafeApplyType Sort
-- safeApply′ env |Θ| v args = v′
-- where Γ, Δ, Θ ⊢ v
-- Γ ⊢ env : Δ
-- Γ ⊢ args
-- Γ, Θ ⊢ v′
safeApply′ : List SafeTerm → Nat → Term → List (Arg SafeTerm) → Term
safeApply′ env k (var x args) args₁ =
if x <? k then var x (args ++ toArgs k args₁)
else case index env (x - k) of λ
{ nothing → var (x - length env) (args ++ toArgs k args₁)
; (just v) → applyTerm v (args ++ toArgs k args₁) }
safeApply′ env k (con c args) args₁ = con c (args ++ toArgs k args₁)
safeApply′ env k (def f args) args₁ = def f (args ++ toArgs k args₁)
safeApply′ env k (lam v t) (a ∷ args₁) = safeApply′ (unArg a ∷ env) k (unAbs t) args₁
safeApply′ env k (lam v b) [] = lam v $ safeApplyAbs env k b []
safeApply′ env k (pat-lam cs args) args₁ = pat-lam cs (args ++ toArgs k args₁)
-- not right if applying to constructors
safeApply′ env k (pi a b) _ = pi (safeApplyArg env k a []) (safeApplyAbs env k b [])
safeApply′ env k (agda-sort s) args₁ = agda-sort (safeApplySort env k s [])
safeApply′ env k (lit l) args₁ = lit l
safeApply′ env k (meta x args) args₁ = meta x (args ++ toArgs k args₁)
safeApply′ env k unknown args₁ = unknown
safeApplyAbs env k (abs x b) _ = abs x (safeApply′ env (suc k) b [])
safeApplyArg env k (arg i v) args₁ = arg i (safeApply′ env k v args₁)
safeApplySort env k (set t) _ = set (safeApply′ env k t [])
safeApplySort env k (lit n) _ = lit n
safeApplySort env k (prop t) _ = set (safeApply′ env k t [])
safeApplySort env k (propLit n) _ = propLit n
safeApplySort env k (inf n) _ = inf n
safeApplySort env k unknown _ = unknown
safeApply : Term → List (Arg SafeTerm) → Term
safeApply v args = safeApply′ [] 0 v args
| 39.575342
| 117
| 0.630149
|
3d714f4877970224ac6f61abf6b5efa39c78f6c2
| 2,493
|
agda
|
Agda
|
examples/todomvc/src/logic/base-todos.agda
|
frankymacster/redux
|
506fba1e27d8c1527f06c285762391b00ed03ced
|
[
"CC0-1.0",
"MIT"
] | null | null | null |
examples/todomvc/src/logic/base-todos.agda
|
frankymacster/redux
|
506fba1e27d8c1527f06c285762391b00ed03ced
|
[
"CC0-1.0",
"MIT"
] | null | null | null |
examples/todomvc/src/logic/base-todos.agda
|
frankymacster/redux
|
506fba1e27d8c1527f06c285762391b00ed03ced
|
[
"CC0-1.0",
"MIT"
] | null | null | null |
open import Data.Bool as Bool using (Bool; false; true; if_then_else_; not)
open import Data.String using (String)
open import Data.Nat using (ℕ; _+_; _≟_; suc; _>_; _<_; _∸_)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Data.List as l using (List; filter; map; take; foldl; length)
open import Data.List.Properties
open import Data.Maybe using (to-witness)
open import Data.Fin using (fromℕ; _-_; zero)
open import Data.Product as Prod using (∃; ∃₂; _×_; _,_; Σ)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open Eq.≡-Reasoning
open import Level using (Level)
open import Data.Vec as v using (Vec; fromList; toList; last; length; []; _∷_; [_]; _∷ʳ_; _++_; lookup; head; initLast; filter; map)
open import Data.Vec.Bounded as vb using ([]; _∷_; fromVec; filter; Vec≤)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; refl; _≗_; cong₂)
open import Data.Nat.Properties using (+-comm)
open import Relation.Unary using (Pred; Decidable)
open import Relation.Nullary using (does)
open import Data.Vec.Bounded.Base using (padRight; ≤-cast)
import Data.Nat.Properties as ℕₚ
open import Relation.Nullary.Decidable.Core using (dec-false)
-- essentially a List String
record Todo : Set where
field
text : String
AddTodo :
∀ {n : ℕ} →
(Vec Todo n) →
String →
(Vec Todo (1 + n))
AddTodo todos text =
todos ∷ʳ
record
{ text = text
}
AddTodoAddsNewListItem :
∀ {n : ℕ} →
(todos : Vec Todo n) (text : String) →
v.length (AddTodo todos text) ≡ v.length todos + 1
AddTodoAddsNewListItem [] text = refl
AddTodoAddsNewListItem todos text = +-comm 1 (v.length todos)
AddTodoLastAddedElementIsTodo :
∀ {n} (todos : Vec Todo n) (text : String) →
last (AddTodo todos text) ≡
record
{ text = text
}
AddTodoLastAddedElementIsTodo todos text = vecLast todos
where
vecLast : ∀ {a} {A : Set a} {l} {n : ℕ} (xs : Vec A n) → last (xs ∷ʳ l) ≡ l
vecLast [] = refl
vecLast (_ ∷ xs) = P.trans (prop (xs ∷ʳ _)) (vecLast xs)
where
prop : ∀ {a} {A : Set a} {n x} (xs : Vec A (suc n)) → last (x v.∷ xs) ≡ last xs
prop xs with initLast xs
... | _ , _ , refl = refl
AddTodoAddedTodoHasGivenText :
∀ {n} (todos : Vec Todo n) (text : String) →
Todo.text (last (AddTodo todos text)) ≡ text
AddTodoAddedTodoHasGivenText todos text
rewrite
(AddTodoLastAddedElementIsTodo todos text) =
refl
| 35.112676
| 132
| 0.657842
|
5720c74bc6858a81f071c9c652789a8dc46eb324
| 16,083
|
agda
|
Agda
|
src/Semantics.agda
|
proglang/incorrectness
|
91a5ff5267089e6ed0d2f6d3998633ba1842b397
|
[
"BSD-3-Clause"
] | 1
|
2020-06-17T19:13:13.000Z
|
2020-06-17T19:13:13.000Z
|
src/Semantics.agda
|
proglang/incorrectness
|
91a5ff5267089e6ed0d2f6d3998633ba1842b397
|
[
"BSD-3-Clause"
] | null | null | null |
src/Semantics.agda
|
proglang/incorrectness
|
91a5ff5267089e6ed0d2f6d3998633ba1842b397
|
[
"BSD-3-Clause"
] | null | null | null |
module Semantics where
open import Data.Nat hiding (_⊔_; _⊓_)
open import Data.Product
open import Data.Sum
open import Data.String using (String)
open import Data.Unit hiding (_≟_)
open import Data.Empty
open import Relation.Nullary
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_;_≢_; refl)
open Eq.≡-Reasoning
open import Level hiding (_⊔_) renaming (zero to lzero; suc to lsuc)
{- TODO:
* subtyping of refinement types
* union types
* intersection types
-}
Id = String
variable
x y : Id
ℓ : Level
data Expr : Set where
Nat : ℕ → Expr
Var : Id → Expr
Lam : Id → Expr → Expr
App : Expr → Expr → Expr
Pair : Expr → Expr → Expr
Fst Snd : Expr → Expr
Inl Inr : Expr → Expr
Case : Expr → Id → Expr → Id → Expr → Expr
data RawType : Set where
Nat : RawType
_⇒_ _⋆_ _⊹_ : RawType → RawType → RawType
ss⇒tt : ∀ {S S₁ T T₁ : RawType} → (S ⇒ S₁) ≡ (T ⇒ T₁) → (S ≡ T × S₁ ≡ T₁)
ss⇒tt refl = refl , refl
ss⋆tt : ∀ {S S₁ T T₁ : RawType} → (S ⋆ S₁) ≡ (T ⋆ T₁) → (S ≡ T × S₁ ≡ T₁)
ss⋆tt refl = refl , refl
ss⊹tt : ∀ {S S₁ T T₁ : RawType} → (S ⊹ S₁) ≡ (T ⊹ T₁) → (S ≡ T × S₁ ≡ T₁)
ss⊹tt refl = refl , refl
data Type : Set₁ where
Base : (P : ℕ → Set) → Type -- refinement
Nat : Type
_⇒_ : Type → Type → Type
_⋆_ : Type → Type → Type
_⊹_ : Type → Type → Type
T-Nat = Base (λ n → ⊤) -- all natural numbers
data ne : Type → Set where
ne-base : ∀ {P} → (∃P : Σ ℕ P) → ne (Base P)
ne-nat : ne Nat
ne-⇒ : ∀ {S T} → ne S → ne T → ne (S ⇒ T)
ne-⋆ : ∀ {S T} → ne S → ne T → ne (S ⋆ T)
ne-⊹L : ∀ {S T} → ne S → ne (S ⊹ T)
ne-⊹R : ∀ {S T} → ne T → ne (S ⊹ T)
data Env (A : Set ℓ) : Set ℓ where
· : Env A
_,_⦂_ : Env A → (x : Id) → (a : A) → Env A
∥_∥ : Type → RawType
∥ Base P ∥ = Nat
∥ Nat ∥ = Nat
∥ S ⇒ S₁ ∥ = ∥ S ∥ ⇒ ∥ S₁ ∥
∥ S ⋆ S₁ ∥ = ∥ S ∥ ⋆ ∥ S₁ ∥
∥ S ⊹ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥
_∨_ : (P Q : ℕ → Set) → ℕ → Set
P ∨ Q = λ n → P n ⊎ Q n
_∧_ : (P Q : ℕ → Set) → ℕ → Set
P ∧ Q = λ n → P n × Q n
implies : ∀ {P Q : ℕ → Set} → (n : ℕ) → P n → (P n ⊎ Q n)
implies n Pn = inj₁ Pn
p*q->p : ∀ {P Q : ℕ → Set} → (n : ℕ) → (P n × Q n) → P n
p*q->p n (Pn , Qn) = Pn
_⊔_ _⊓_ : (S T : Type) {r : ∥ S ∥ ≡ ∥ T ∥} → Type
(Base P ⊔ Base P₁) {refl} = Base (P ∨ P₁)
(Base P ⊔ Nat) = Nat
(Nat ⊔ Base P) = Nat
(Nat ⊔ Nat) = Nat
((S ⇒ S₁) ⊔ (T ⇒ T₁)) {r} with ss⇒tt r
... | sss , ttt = (S ⊓ T){sss} ⇒ (S₁ ⊔ T₁){ttt}
((S ⋆ S₁) ⊔ (T ⋆ T₁)) {r} with ss⋆tt r
... | sss , ttt = (S ⊔ T){sss} ⋆ (S₁ ⊔ T₁){ttt}
((S ⊹ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r
... | sss , ttt = (S ⊔ T){sss} ⊹ (S₁ ⊔ T₁){ttt}
Base P ⊓ Base P₁ = Base (P ∧ P₁)
Base P ⊓ Nat = Base P
Nat ⊓ Base P = Base P
Nat ⊓ Nat = Nat
((S ⇒ S₁) ⊓ (T ⇒ T₁)){r} with ss⇒tt r
... | sss , ttt = (S ⊔ T){sss} ⇒ (S₁ ⊓ T₁){ttt}
((S ⋆ S₁) ⊓ (T ⋆ T₁)){r} with ss⋆tt r
... | sss , ttt = (S ⊓ T){sss} ⋆ (S₁ ⊓ T₁){ttt}
((S ⊹ S₁) ⊓ (T ⊹ T₁)){r} with ss⊹tt r
... | sss , ttt = (S ⊓ T){sss} ⊹ (S₁ ⊓ T₁){ttt}
variable
S T U S′ T′ U′ U″ : Type
Γ Γ₁ Γ₂ : Env Type
L M N : Expr
n : ℕ
P : ℕ → Set
data Split {A : Set ℓ} : Env A → Env A → Env A → Set ℓ where
nil : Split · · ·
lft : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) (Γ₁ , x ⦂ a) Γ₂
rgt : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) Γ₁ (Γ₂ , x ⦂ a)
data _⦂_∈_ {A : Set ℓ} : Id → A → Env A → Set ℓ where
found : ∀ {a : A}{E : Env A} →
x ⦂ a ∈ (E , x ⦂ a)
there : ∀ {a a' : A}{E : Env A} →
x ⦂ a ∈ E →
-- x ≢ y →
x ⦂ a ∈ (E , y ⦂ a')
data _<:_ : Type → Type → Set where
<:-refl :
T <: T
<:-base :
(P Q : ℕ → Set) →
(p→q : ∀ n → P n → Q n) →
Base P <: Base Q
<:-base-nat :
Base P <: Nat
<:-⇒ :
S′ <: S →
T <: T′ →
(S ⇒ T) <: (S′ ⇒ T′)
<:-⋆ :
S <: S′ →
T <: T′ →
(S ⋆ T) <: (S′ ⋆ T′)
<:-⊹ :
S <: S′ →
T <: T′ →
(S ⊹ T) <: (S′ ⊹ T′)
-- subtyping is compatible with raw types
<:-raw : S <: T → ∥ S ∥ ≡ ∥ T ∥
<:-raw <:-refl = refl
<:-raw (<:-base P Q p→q) = refl
<:-raw <:-base-nat = refl
<:-raw (<:-⇒ s<:t s<:t₁) = Eq.cong₂ _⇒_ (Eq.sym (<:-raw s<:t)) (<:-raw s<:t₁)
<:-raw (<:-⋆ s<:t s<:t₁) = Eq.cong₂ _⋆_ (<:-raw s<:t) (<:-raw s<:t₁)
<:-raw (<:-⊹ s<:t s<:t₁) = Eq.cong₂ _⊹_ (<:-raw s<:t) (<:-raw s<:t₁)
<:-⊔ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → S <: (S ⊔ T){c}
<:-⊓ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → (S ⊓ T){c} <: S
<:-⊔ (Base P) (Base P₁) {refl} = <:-base P (P ∨ P₁) implies
<:-⊔ (Base P) Nat = <:-base-nat
<:-⊔ Nat (Base P) = <:-refl
<:-⊔ Nat Nat = <:-refl
<:-⊔ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c
... | c1 , c2 = <:-⇒ (<:-⊓ S T) (<:-⊔ S₁ T₁)
<:-⊔ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c
... | c1 , c2 = <:-⋆ (<:-⊔ S T) (<:-⊔ S₁ T₁)
<:-⊔ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c
... | c1 , c2 = <:-⊹ (<:-⊔ S T) (<:-⊔ S₁ T₁)
<:-⊓ (Base P) (Base P₁) {refl} = <:-base (P ∧ P₁) P p*q->p
<:-⊓ (Base P) Nat = <:-refl
<:-⊓ Nat (Base P) = <:-base-nat
<:-⊓ Nat Nat = <:-refl
<:-⊓ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c
... | c1 , c2 = <:-⇒ (<:-⊔ S T) (<:-⊓ S₁ T₁)
<:-⊓ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c
... | c1 , c2 = <:-⋆ (<:-⊓ S T) (<:-⊓ S₁ T₁)
<:-⊓ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c
... | c1 , c2 = <:-⊹ (<:-⊓ S T) (<:-⊓ S₁ T₁)
-- should be in terms of RawType for evaluation
data _⊢_⦂_ : Env Type → Expr → Type → Set₁ where
nat' :
Γ ⊢ Nat n ⦂ Base (_≡_ n)
var :
(x∈ : x ⦂ T ∈ Γ) →
--------------------
Γ ⊢ Var x ⦂ T
lam :
(Γ , x ⦂ S) ⊢ M ⦂ T →
--------------------
Γ ⊢ Lam x M ⦂ (S ⇒ T)
app :
Γ ⊢ M ⦂ (S ⇒ T) →
Γ ⊢ N ⦂ S →
--------------------
Γ ⊢ App M N ⦂ T
pair :
Γ ⊢ M ⦂ S →
Γ ⊢ N ⦂ T →
--------------------
Γ ⊢ Pair M N ⦂ (S ⋆ T)
pair-E1 :
Γ ⊢ M ⦂ (S ⋆ T) →
--------------------
Γ ⊢ Fst M ⦂ S
pair-E2 :
Γ ⊢ M ⦂ (S ⋆ T) →
--------------------
Γ ⊢ Snd M ⦂ T
sum-I1 :
Γ ⊢ M ⦂ S →
--------------------
Γ ⊢ Inl M ⦂ (S ⊹ T)
sum-I2 :
Γ ⊢ N ⦂ T →
--------------------
Γ ⊢ Inl N ⦂ (S ⊹ T)
sum-E :
Γ ⊢ L ⦂ (S ⊹ T) →
(Γ , x ⦂ S) ⊢ M ⦂ U →
(Γ , y ⦂ T) ⊢ N ⦂ U →
--------------------
Γ ⊢ Case L x M y N ⦂ U
split-sym : Split Γ Γ₁ Γ₂ → Split Γ Γ₂ Γ₁
split-sym nil = nil
split-sym (lft sp) = rgt (split-sym sp)
split-sym (rgt sp) = lft (split-sym sp)
weaken-∈ : Split Γ Γ₁ Γ₂ → x ⦂ T ∈ Γ₁ → x ⦂ T ∈ Γ
weaken-∈ (lft sp) found = found
weaken-∈ (rgt sp) found = there (weaken-∈ sp found)
weaken-∈ (lft sp) (there x∈) = there (weaken-∈ sp x∈)
weaken-∈ (rgt sp) (there x∈) = there (weaken-∈ sp (there x∈))
weaken : Split Γ Γ₁ Γ₂ → Γ₁ ⊢ M ⦂ T → Γ ⊢ M ⦂ T
weaken sp (nat') = nat'
weaken sp (var x∈) = var (weaken-∈ sp x∈)
weaken sp (lam ⊢M) = lam (weaken (lft sp) ⊢M)
weaken sp (app ⊢M ⊢N) = app (weaken sp ⊢M) (weaken sp ⊢N)
weaken sp (pair ⊢M ⊢N) = pair (weaken sp ⊢M) (weaken sp ⊢N)
weaken sp (pair-E1 ⊢M) = pair-E1 (weaken sp ⊢M)
weaken sp (pair-E2 ⊢M) = pair-E2 (weaken sp ⊢M)
weaken sp (sum-I1 ⊢M) = sum-I1 (weaken sp ⊢M)
weaken sp (sum-I2 ⊢N) = sum-I2 (weaken sp ⊢N)
weaken sp (sum-E ⊢L ⊢M ⊢N) = sum-E (weaken sp ⊢L) (weaken (lft sp) ⊢M) (weaken (lft sp) ⊢N)
-- incorrectness typing
P=n : ℕ → ℕ → Set
P=n = λ n x → n ≡ x
data _⊢_÷_ : Env Type → Expr → Type → Set₁ where
nat' :
--------------------
· ⊢ Nat n ÷ Base (_≡_ n)
var1 :
( · , x ⦂ T) ⊢ Var x ÷ T
{-
var :
x ⦂ T ∈ Γ →
--------------------
Γ ⊢ Var x ÷ T
-}
lam :
(· , x ⦂ S) ⊢ M ÷ T →
--------------------
· ⊢ Lam x M ÷ (S ⇒ T)
pair :
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ M ÷ S →
Γ₂ ⊢ N ÷ T →
--------------------
Γ ⊢ Pair M N ÷ (S ⋆ T)
pair-E1 :
Γ ⊢ M ÷ (S ⋆ T) →
--------------------
Γ ⊢ Fst M ÷ S
pair-E2 :
Γ ⊢ M ÷ (S ⋆ T) →
--------------------
Γ ⊢ Snd M ÷ T
sum-E :
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ L ÷ (S ⊹ T) →
(Γ₂ , x ⦂ S) ⊢ M ÷ U →
(Γ₂ , y ⦂ T) ⊢ N ÷ U →
--------------------
Γ ⊢ Case L x M y N ÷ U
sum-E′ : ∀ {ru′=ru″} →
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ L ÷ (S ⊹ T) →
(Γ₂ , x ⦂ S) ⊢ M ÷ U′ →
(Γ₂ , y ⦂ T) ⊢ N ÷ U″ →
U ≡ (U′ ⊔ U″){ru′=ru″} →
--------------------
Γ ⊢ Case L x M y N ÷ U
{-
`sub` :
Γ ⊢ M ÷ S →
T <: S →
--------------------
Γ ⊢ M ÷ T
-}
record _←_ (A B : Set) : Set where
field
func : A → B
back : ∀ (b : B) → ∃ λ (a : A) → func a ≡ b
open _←_
T⟦_⟧ : Type → Set
T⟦ Base P ⟧ = Σ ℕ P
T⟦ Nat ⟧ = ℕ
T⟦ S ⇒ T ⟧ = T⟦ S ⟧ → T⟦ T ⟧
T⟦ S ⋆ T ⟧ = T⟦ S ⟧ × T⟦ T ⟧
T⟦ S ⊹ T ⟧ = T⟦ S ⟧ ⊎ T⟦ T ⟧
T'⟦_⟧ : Type → Set
T'⟦ Base P ⟧ = Σ ℕ P
T'⟦ Nat ⟧ = ℕ
T'⟦ S ⇒ T ⟧ = T'⟦ S ⟧ ← T'⟦ T ⟧
T'⟦ S ⋆ T ⟧ = T'⟦ S ⟧ × T'⟦ T ⟧
T'⟦ S ⊹ T ⟧ = T'⟦ S ⟧ ⊎ T'⟦ T ⟧
E⟦_⟧ : Env Type → Env Set
E⟦ · ⟧ = ·
E⟦ Γ , x ⦂ T ⟧ = E⟦ Γ ⟧ , x ⦂ T⟦ T ⟧
data iEnv : Env Set → Set where
· : iEnv ·
_,_⦂_ : ∀ {E}{A} → iEnv E → (x : Id) → (a : A) → iEnv (E , x ⦂ A)
lookup : (x ⦂ T ∈ Γ) → iEnv E⟦ Γ ⟧ → T⟦ T ⟧
lookup found (γ , _ ⦂ a) = a
lookup (there x∈) (γ , _ ⦂ a) = lookup x∈ γ
eval : Γ ⊢ M ⦂ T → iEnv E⟦ Γ ⟧ → T⟦ T ⟧
eval (nat'{n = n}) γ = n , refl
eval (var x∈) γ = lookup x∈ γ
eval (lam ⊢M) γ = λ s → eval ⊢M (γ , _ ⦂ s)
eval (app ⊢M ⊢N) γ = eval ⊢M γ (eval ⊢N γ)
eval (pair ⊢M ⊢N) γ = (eval ⊢M γ) , (eval ⊢N γ)
eval (pair-E1 ⊢M) γ = proj₁ (eval ⊢M γ)
eval (pair-E2 ⊢M) γ = proj₂ (eval ⊢M γ)
eval (sum-I1 ⊢M) γ = inj₁ (eval ⊢M γ)
eval (sum-I2 ⊢N) γ = inj₂ (eval ⊢N γ)
eval (sum-E{S = S}{T = T}{U = U} ⊢L ⊢M ⊢N) γ =
[ (λ s → eval ⊢M (γ , _ ⦂ s)) , (λ t → eval ⊢N (γ , _ ⦂ t)) ] (eval ⊢L γ)
corr : Γ ⊢ M ÷ T → Γ ⊢ M ⦂ T
corr (nat') = nat'
corr var1 = var found
-- corr (var x) = var x
corr (lam ⊢M) = lam (corr ⊢M)
corr (pair-E1 ÷M) = pair-E1 (corr ÷M)
corr (pair-E2 ÷M) = pair-E2 (corr ÷M)
corr (pair sp ÷M ÷N) = pair (weaken sp (corr ÷M)) (weaken (split-sym sp) (corr ÷N))
corr (sum-E sp ÷L ÷M ÷N) = sum-E (weaken sp (corr ÷L)) (weaken (lft (split-sym sp)) (corr ÷M)) (weaken (lft (split-sym sp)) (corr ÷N))
corr (sum-E′ sp ÷L ÷M ÷N U≡U′⊔U″) =
sum-E (weaken sp (corr ÷L)) (weaken (lft (split-sym sp)) (corr {!!})) (weaken (lft (split-sym sp)) (corr {!!}))
{-
corr (`sub` ÷M T<S) = {!÷M!}
-}
-- pick one element of a type to demonstrate non-emptiness
one : ∀ (T : Type) {net : ne T} → T⟦ T ⟧
one (Base P) {ne-base ∃P} = ∃P
one Nat = zero
one (T ⇒ T₁) {ne-⇒ ne-T ne-T₁} = λ x → one T₁ {ne-T₁}
one (T ⋆ T₁) {ne-⋆ ne-T ne-T₁} = (one T {ne-T}) , (one T₁ {ne-T₁})
one (T ⊹ T₁) {ne-⊹L ne-T} = inj₁ (one T {ne-T})
one (T ⊹ T₁) {ne-⊹R ne-T₁} = inj₂ (one T₁ {ne-T₁})
{- not needed
many : iEnv E⟦ Γ ⟧
many {·} = ·
many {Γ , x ⦂ T} = many , x ⦂ one T
gen : (x∈ : x ⦂ T ∈ Γ) (t : T⟦ T ⟧) → iEnv E⟦ Γ ⟧
gen found t = many , _ ⦂ t
gen (there x∈) t = (gen x∈ t) , _ ⦂ one {!!}
lookup-gen : (x∈ : x ⦂ T ∈ Γ) (t : T⟦ T ⟧) → lookup x∈ (gen x∈ t) ≡ t
lookup-gen found t = refl
lookup-gen (there x∈) t = lookup-gen x∈ t
-}
open Eq.≡-Reasoning
postulate
ext : ∀ {A B : Set}{f g : A → B} → (∀ x → f x ≡ g x) → f ≡ g
unsplit-env : Split Γ Γ₁ Γ₂ → iEnv E⟦ Γ₁ ⟧ → iEnv E⟦ Γ₂ ⟧ → iEnv E⟦ Γ ⟧
unsplit-env nil γ₁ γ₂ = ·
unsplit-env (lft sp) (γ₁ , _ ⦂ a) γ₂ = (unsplit-env sp γ₁ γ₂) , _ ⦂ a
unsplit-env (rgt sp) γ₁ (γ₂ , _ ⦂ a) = (unsplit-env sp γ₁ γ₂) , _ ⦂ a
unsplit-split : (sp : Split Γ Γ₁ Γ₂) (γ₁ : iEnv E⟦ Γ₁ ⟧) (γ₂ : iEnv E⟦ Γ₂ ⟧) →
unsplit-env sp γ₁ γ₂ ≡ unsplit-env (split-sym sp) γ₂ γ₁
unsplit-split nil γ₁ γ₂ = refl
unsplit-split (lft sp) (γ₁ , _ ⦂ a) γ₂ rewrite unsplit-split sp γ₁ γ₂ = refl
unsplit-split (rgt sp) γ₁ (γ₂ , _ ⦂ a) rewrite unsplit-split sp γ₁ γ₂ = refl
lookup-unsplit : (sp : Split Γ Γ₁ Γ₂) (γ₁ : iEnv E⟦ Γ₁ ⟧) (γ₂ : iEnv E⟦ Γ₂ ⟧) →
(x∈ : x ⦂ T ∈ Γ₁) →
lookup (weaken-∈ sp x∈) (unsplit-env sp γ₁ γ₂) ≡ lookup x∈ γ₁
lookup-unsplit (lft sp) (γ₁ , _ ⦂ a) γ₂ found = refl
lookup-unsplit (rgt sp) γ₁ (γ₂ , _ ⦂ a) found = lookup-unsplit sp γ₁ γ₂ found
lookup-unsplit (lft sp) (γ₁ , _ ⦂ a) γ₂ (there x∈) = lookup-unsplit sp γ₁ γ₂ x∈
lookup-unsplit (rgt sp) γ₁ (γ₂ , _ ⦂ a) (there x∈) = lookup-unsplit sp γ₁ γ₂ (there x∈)
eval-unsplit : (sp : Split Γ Γ₁ Γ₂) (γ₁ : iEnv E⟦ Γ₁ ⟧) (γ₂ : iEnv E⟦ Γ₂ ⟧) →
(⊢M : Γ₁ ⊢ M ⦂ T) →
eval (weaken sp ⊢M) (unsplit-env sp γ₁ γ₂) ≡ eval ⊢M γ₁
eval-unsplit sp γ₁ γ₂ (nat')= refl
eval-unsplit sp γ₁ γ₂ (var x∈) = lookup-unsplit sp γ₁ γ₂ x∈
eval-unsplit sp γ₁ γ₂ (lam ⊢M) = ext (λ s → eval-unsplit (lft sp) (γ₁ , _ ⦂ s) γ₂ ⊢M)
eval-unsplit sp γ₁ γ₂ (app ⊢M ⊢M₁)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M | eval-unsplit sp γ₁ γ₂ ⊢M₁ = refl
eval-unsplit sp γ₁ γ₂ (pair ⊢M ⊢M₁)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M | eval-unsplit sp γ₁ γ₂ ⊢M₁ = refl
eval-unsplit sp γ₁ γ₂ (pair-E1 ⊢M)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl
eval-unsplit sp γ₁ γ₂ (pair-E2 ⊢M)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl
eval-unsplit sp γ₁ γ₂ (sum-I1 ⊢M)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl
eval-unsplit sp γ₁ γ₂ (sum-I2 ⊢N)
rewrite eval-unsplit sp γ₁ γ₂ ⊢N = refl
eval-unsplit sp γ₁ γ₂ (sum-E ⊢L ⊢M ⊢N)
rewrite eval-unsplit sp γ₁ γ₂ ⊢L
| ext (λ s → eval-unsplit (lft sp) (γ₁ , _ ⦂ s) γ₂ ⊢M)
| ext (λ t → eval-unsplit (lft sp) (γ₁ , _ ⦂ t) γ₂ ⊢N)
= refl
-- soundness of the incorrectness rules
lave :
(÷M : Γ ⊢ M ÷ T) →
∀ (t : T⟦ T ⟧) →
∃ λ (γ : iEnv E⟦ Γ ⟧) →
eval (corr ÷M) γ ≡ t
lave nat' (n , refl) = · , refl
lave var1 t = (· , _ ⦂ t) , refl
-- lave (var x∈) t = (gen x∈ t) , lookup-gen x∈ t
lave (lam{x = x}{S = S} ÷M) t = · , ext aux
where
aux : (s : T⟦ S ⟧) → eval (corr ÷M) (· , x ⦂ s) ≡ t s
aux s with lave ÷M (t s)
... | (· , .x ⦂ a) , snd = {!!} -- impossible to complete!
lave (pair-E1 ÷M) t with lave ÷M (t , one {!!})
... | γ , ih = γ , Eq.cong proj₁ ih
lave (pair-E2 ÷M) t with lave ÷M (one {!!} , t)
... | γ , ih = γ , Eq.cong proj₂ ih
lave (pair sp ÷M ÷N) (s , t) with lave ÷M s | lave ÷N t
... | γ₁ , ih-M | γ₂ , ih-N =
unsplit-env sp γ₁ γ₂ ,
Eq.cong₂ _,_ (Eq.trans (eval-unsplit sp γ₁ γ₂ (corr ÷M)) ih-M)
(begin eval (weaken (split-sym sp) (corr ÷N)) (unsplit-env sp γ₁ γ₂)
≡⟨ Eq.cong (eval (weaken (split-sym sp) (corr ÷N))) (unsplit-split sp γ₁ γ₂) ⟩
eval (weaken (split-sym sp) (corr ÷N)) (unsplit-env (split-sym sp) γ₂ γ₁)
≡⟨ eval-unsplit (split-sym sp) γ₂ γ₁ (corr ÷N) ⟩
ih-N)
-- works, but unsatisfactory!
-- this proof uses only one branch of the case
-- this choice is possible because both branches ÷M and ÷N have the same type
-- in general, U could be the union of the types of ÷M and ÷N
lave (sum-E{S = S}{T = T}{U = U} sp ÷L ÷M ÷N) u
with lave ÷M u | lave ÷N u
... | (γ₁ , x ⦂ s) , ih-M | (γ₂ , y ⦂ t) , ih-N
with lave ÷L (inj₁ s)
... | γ₀ , ih-L
=
unsplit-env sp γ₀ γ₁ ,
(begin [
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
]
(eval (weaken sp (corr ÷L)) (unsplit-env sp γ₀ γ₁))
≡⟨ Eq.cong [
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
] (eval-unsplit sp γ₀ γ₁ (corr ÷L)) ⟩
[
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
]
(eval (corr ÷L) γ₀)
≡⟨ Eq.cong
[
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
]
ih-L ⟩
eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env sp γ₀ γ₁ , x ⦂ s)
≡⟨ Eq.cong (λ γ → eval (weaken (lft (split-sym sp)) (corr ÷M)) (γ , x ⦂ s)) (unsplit-split sp γ₀ γ₁) ⟩
eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env (split-sym sp) γ₁ γ₀ , x ⦂ s)
≡⟨⟩
eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env (lft (split-sym sp)) (γ₁ , x ⦂ s) γ₀)
≡⟨ eval-unsplit (lft (split-sym sp)) (γ₁ , x ⦂ s) γ₀ (corr ÷M) ⟩
ih-M)
lave (sum-E′{S = S}{T = T}{U = U} sp ÷L ÷M ÷N uuu) u = {!!}
| 27.921875
| 135
| 0.461295
|
a1c1f6c9018ccdd7cf1fe32c9045b45da4762624
| 25,443
|
agda
|
Agda
|
Ex2.agda
|
m-schmidt/CS410-17-Exercises
|
5db8e95bbcbe8dc0eec810f3e73130ecd78d207c
|
[
"BSD-3-Clause"
] | null | null | null |
Ex2.agda
|
m-schmidt/CS410-17-Exercises
|
5db8e95bbcbe8dc0eec810f3e73130ecd78d207c
|
[
"BSD-3-Clause"
] | null | null | null |
Ex2.agda
|
m-schmidt/CS410-17-Exercises
|
5db8e95bbcbe8dc0eec810f3e73130ecd78d207c
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --type-in-type #-} -- yes, I will let you cheat in this exercise
{-# OPTIONS --allow-unsolved-metas #-} -- allows import, unfinished
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- CS410 2017/18 Exercise 2 CATEGORIES AND MONADS (worth 25%)
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- NOTE (19/10/17) This file is currently incomplete: more will arrive on
-- GitHub.
-- NOTE (29/10/17) All components are now present.
------------------------------------------------------------------------------
-- Dependencies
------------------------------------------------------------------------------
open import CS410-Prelude
open import CS410-Categories
open import Ex1
------------------------------------------------------------------------------
-- Categorical Jigsaws (based on Ex1)
------------------------------------------------------------------------------
OPE : Category -- The category of order-preserving embeddings...
OPE = record
{ Obj = Nat -- ...has numbers as objects...
; _~>_ = _<=_ -- ...and "thinnings" as arrows.
; id~> = oi
; _>~>_ = _o>>_
; law-id~>>~> = idThen-o>>
; law->~>id~> = idAfter-o>>
; law->~>>~> = assoc-o>>
}
VEC : Nat -> SET => SET -- Vectors of length n...
VEC n = record
{ F-Obj = \ X -> Vec X n -- ...give a functor from SET to SET...
; F-map = \ f xs -> vMap f xs -- ...doing vMap to arrows.
-- Now prove the laws.
; F-map-id~> = extensionality \ xs -> {!!}
; F-map->~> = \ f g -> extensionality \ xs -> {!!}
}
Op : Category -> Category -- Every category has an opposite...
Op C = record
{ Obj = Obj -- ...with the same objects, but...
; _~>_ = \ S T -> T ~> S -- ...arrows that go backwards!
-- Now, find the rest!
; id~> = id~>
; _>~>_ = \ f g -> g >~> f
; law-id~>>~> = law->~>id~>
; law->~>id~> = law-id~>>~>
; law->~>>~> = {!!}
} where open Category C
CHOOSE : Set -> OPE => Op SET -- Show that thinnings from n to m...
CHOOSE X = record -- ...act by selection...
{ F-Obj = Vec X -- ...to cut vectors down from m to n.
; F-map = {!!}
; F-map-id~> = extensionality {!!}
; F-map->~> = \ f g -> extensionality {!!}
}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- The List Monad (a warm-up)
------------------------------------------------------------------------------
-- The declaration of List has been added to the CS410-Prelude file:
-- data List (X : Set) : Set where
-- [] : List X
-- _,-_ : (x : X)(xs : List X) -> List X
-- infixr 4 _,-_
-- Appending two lists is rather well known, so I'll not ask you to write it.
_+L_ : {X : Set} -> List X -> List X -> List X
[] +L ys = ys
(x ,- xs) +L ys = x ,- (xs +L ys)
infixr 4 _+L_
-- But I will ask you to find some structure for it.
--??--2.2---------------------------------------------------------------------
LIST-MONOID : Set -> Category
LIST-MONOID X = -- Show that _+L_ is the operation of a monoid,...
record
{ Obj = One -- ... i.e., a category with one object.
; _~>_ = {!!}
; id~> = {!!}
; _>~>_ = {!!}
; law-id~>>~> = {!!}
; law->~>id~> = {!!}
; law->~>>~> = {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- Next, functoriality of lists. Given a function on elements, show how to
-- apply that function to all the elements of a list. (Haskell calls this
-- operation "map".)
--??--2.3---------------------------------------------------------------------
list : {X Y : Set} -> (X -> Y) -> List X -> List Y
list f xs = {!!}
LIST : SET => SET
LIST = record
{ F-Obj = List
; F-map = list
; F-map-id~> = extensionality {!!}
; F-map->~> = \ f g -> extensionality {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- Moreover, applying a function elementwise should respect appending.
--??--2.4---------------------------------------------------------------------
LIST+L : {X Y : Set}(f : X -> Y) -> LIST-MONOID X => LIST-MONOID Y
LIST+L {X}{Y} f = record
{ F-Obj = id
; F-map = list f -- this yellow will go once LIST-MONOID has arrows!
; F-map-id~> = {!!}
; F-map->~> = {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- Next, we have two very important "natural transformations".
--??--2.5---------------------------------------------------------------------
SINGLE : ID ~~> LIST
SINGLE = record
{ xf = \ x -> x ,- [] -- turn a value into a singleton list
; naturality = \ f -> {!!}
}
--??--------------------------------------------------------------------------
-- Here, naturality means that it doesn't matter
-- whether you apply a function f, then make a singleton list
-- or you make a singleton list, then apply f to all (one of) its elements.
-- Now, define the operation that concatenates a whole list of lists, and
-- show that it, too, is natural. That is, it doesn't matter whether you
-- transform the elements (two layers inside) then concatenate, or you
-- concatenate, then transform the elements.
--??--2.6---------------------------------------------------------------------
concat : {X : Set} -> List (List X) -> List X
concat xss = {!!}
CONCAT : (LIST >=> LIST) ~~> LIST
CONCAT = record
{ xf = concat
; naturality = {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- You've nearly built your first monad! You just need to prove that
-- single and concat play nicely with each other.
--??--2.7---------------------------------------------------------------------
module LIST-MONAD where
open MONAD LIST public
ListMonad : Monad
ListMonad = record
{ unit = SINGLE
; mult = CONCAT
; unitMult = {!!}
; multUnit = {!!}
; multMult = {!!}
} where
-- useful helper proofs (lemmas) go here
-- open LIST-MONAD
--??--------------------------------------------------------------------------
-- More monads to come...
------------------------------------------------------------------------------
-- Categories of Indexed Sets
------------------------------------------------------------------------------
-- We can think of some
-- P : I -> Set
-- as a collection of sets indexed by I, such that
-- P i
-- means "exactly the P-things which fit with i".
-- You've met
-- Vec X : Nat -> Set
-- where
-- Vec X n
-- means "exactly the vectors which fit with n".
-- Now, given two such collections, S and T, we can make a collection
-- of function types: the functions which fit with i map the
-- S-things which fit with i to the T-things which fit with i.
_-:>_ : {I : Set} -> (I -> Set) -> (I -> Set) -> (I -> Set)
(S -:> T) i = S i -> T i
-- So, (Vec X -:> Vec Y) n contains the functions which turn
-- n Xs into n Ys.
-- Next, if we know such a collection of sets, we can claim to have
-- one for each index.
[_] : {I : Set} -> (I -> Set) -> Set
[ P ] = forall i -> P i -- [_] {I} P = (i : I) -> P i
-- E.g., [ Vec X -:> Vec Y ] is the type of functions from X-vectors
-- to Y-vectors which preserve length.
-- For any such I, we get a category of indexed sets with index-preserving
-- functions.
_->SET : Set -> Category
I ->SET = record
{ Obj = I -> Set -- I-indexed sets
; _~>_ = \ S T -> [ S -:> T ] -- index-respecting functions
; id~> = \ i -> id -- the identity at every index
; _>~>_ = \ f g i -> f i >> g i -- composition at every index
; law-id~>>~> = refl -- and the laws are very boring
; law->~>id~> = refl
; law->~>>~> = \ f g h -> refl _
}
-- In fact, we didn't need to choose SET here. We could do this construction
-- for any category: index the objects; index the morphisms.
-- But SET is plenty to be getting on with.
-- Now, let me define an operation that makes types from lists.
All : {X : Set} -> (X -> Set) -> (List X -> Set)
All P [] = One
All P (x ,- xs) = P x * All P xs
-- The idea is that we get a tuple of P-things: one for each list element.
-- So
-- All P (1 ,- 2 ,- 3 ,- [])
-- = P 1 * P 2 * P 3 * One
-- Note that if you think of List One as a version of Nat,
-- All becomes a lot like Vec.
copy : Nat -> List One
copy zero = []
copy (suc n) = <> ,- copy n
VecCopy : Set -> Nat -> Set
VecCopy X n = All (\ _ -> X) (copy n)
-- Now, your turn...
--??--2.8---------------------------------------------------------------------
-- Show that, for any X, All induces a functor
-- from (X ->SET) to (List X ->SET)
all : {X : Set}{S T : X -> Set} ->
[ S -:> T ] -> [ All S -:> All T ]
all f xs ss = {!!}
ALL : (X : Set) -> (X ->SET) => (List X ->SET)
ALL X = record
{ F-Obj = All
; F-map = all
; F-map-id~> = {!!}
; F-map->~> = {!!}
} where
-- useful helper facts go here
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Cutting Things Up
------------------------------------------------------------------------------
-- Next, we're going to develop a very general technique for building
-- data structures.
-- We may think of an I |> O as a way to "cut O-shapes into I-shaped pieces".
-- The pointy end points to the type being cut; the flat end to the type of
-- pieces.
record _|>_ (I O : Set) : Set where
field
Cuts : O -> Set -- given o : O, how may we cut it?
inners : {o : O} -> Cuts o -> List I -- given how we cut it, what are
-- the shapes of its pieces?
-- Let us have some examples right away!
VecCut : One |> Nat -- cut numbers into boring pieces
VecCut = record
{ Cuts = \ n -> One -- there is one way to cut n
; inners = \ {n} _ -> copy n -- and you get n pieces
}
-- Here's a less boring example. You can cut a number into *two* pieces
-- by finding two numbers that add to it.
NatCut : Nat |> Nat
NatCut = record
{ Cuts = \ mn -> Sg Nat \ m -> Sg Nat \ n -> (m +N n) == mn
; inners = \ { (m , n , _) -> m ,- n ,- [] }
}
-- The point is that we can make data structures that record how we
-- built an O-shaped thing from I-shaped pieces.
record Cutting {I O}(C : I |> O)(P : I -> Set)(o : O) : Set where
constructor _8><_ -- "scissors"
open _|>_ C
field
cut : Cuts o -- we decide how to cut o
pieces : All P (inners cut) -- then we give all the pieces.
infixr 3 _8><_
-- For example...
VecCutting : Set -> Nat -> Set
VecCutting X = Cutting VecCut (\ _ -> X)
myVecCutting : VecCutting Char 5
myVecCutting = <> 8>< 'h' , 'e' , 'l' , 'l' , 'o' , <>
-- Or, if you let me fiddle about with strings for a moment,...
length : {X : Set} -> List X -> Nat
length [] = zero
length (x ,- xs) = suc (length xs)
listVec : {X : Set}(xs : List X) -> Vec X (length xs)
listVec [] = []
listVec (x ,- xs) = x ,- listVec xs
strVec : (s : String) -> Vec Char (length (primStringToList s))
strVec s = listVec (primStringToList s)
-- ...an example of cutting a number in two, with vector pieces.
footprints : Cutting NatCut (Vec Char) 10
footprints = (4 , 6 , refl 10) 8>< strVec "foot"
, strVec "prints"
, <>
-- Now, let me direct you to the =$ operator, now in CS410-Prelude.agda,
-- which you may find helps with the proofs in the following.
--??--2.9---------------------------------------------------------------------
-- Using what you already built for ALL, show that every Cutting C gives us
-- a functor between categories of indexed sets.
CUTTING : {I O : Set}(C : I |> O) -> (I ->SET) => (O ->SET)
CUTTING {I}{O} C = record
{ F-Obj = Cutting C
; F-map = {!!}
; F-map-id~> = extensionality \ o -> extensionality \ { (c 8>< ps) ->
{!!} }
; F-map->~> = \ f g ->
extensionality \ o -> extensionality \ { (c 8>< ps) ->
{!!} }
} where
open _|>_ C
open _=>_ (ALL I)
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Interiors
------------------------------------------------------------------------------
-- Next, let me define the notion of an algebra for a given functor in C => C
module ALGEBRA {C : Category}(F : C => C) where
open Category C
open _=>_ F
Algebra : (X : Obj) -> Set -- we call X the "carrier" of the algebra...
Algebra X = F-Obj X ~> X -- ...and we explain how to turn a bunch of Xs
-- into one
open ALGEBRA
-- Some week, we'll build categories whose objects are algebras. Not this week.
-- Instead, let's work with them a bit.
-- If we know a way to cut I-shapes into I-shaped pieces, we can build the
-- ways to "tile" an I with I-shaped T-tiles.
data Interior {I}(C : I |> I)(T : I -> Set)(i : I) : Set where
-- either...
tile : T i -> Interior C T i -- we have a tile that fits, or...
<_> : Cutting C (Interior C T) i -> -- ...we cut, then tile the pieces.
Interior C T i
-- Let me give you an example of an interior.
subbookkeeper : Interior NatCut (Vec Char) 13
subbookkeeper = < (3 , 10 , refl _)
8>< tile (strVec "sub")
, < (4 , 6 , refl _)
8>< tile (strVec "book")
, tile (strVec "keeper")
, <> >
, <> >
-- We make a 13-interior from
-- a 3-tile and a 10-interior made from a 4-tile and a 6-tile.
-- Guess what? Interior C is always a Monad! We'll get there.
module INTERIOR {I : Set}{C : I |> I} where -- fix some C...
open _|>_ C -- ...and open it
open module I->SET {I : Set} = Category (I ->SET) -- work in I ->SET
-- tile gives us an arrow from T into Interior C T
tile' : {T : I -> Set} -> [ T -:> Interior C T ]
tile' i = tile
-- <_> gives us an algebra!
cut' : {T : I -> Set} -> Algebra (CUTTING C) (Interior C T)
cut' i = <_>
-- Now, other (CUTTING C) algebras give us operators on interiors.
module INTERIORFOLD {P Q : I -> Set} where
interiorFold :
[ P -:> Q ] -> -- if we can turn a P into a Q...
Algebra (CUTTING C) Q -> -- ...and a bunch of Qs into a Q...
[ Interior C P -:> Q ] -- ...we can turn an interior of Ps into a Q
allInteriorFold : -- annoyingly, we'll need a specialized "all"
[ P -:> Q ] ->
Algebra (CUTTING C) Q ->
[ All (Interior C P) -:> All Q ]
interiorFold pq qalg i (tile p) = pq i p
interiorFold pq qalg i < c 8>< pis > =
qalg i (c 8>< allInteriorFold pq qalg (inners c) pis)
-- recursively turn all the sub-interiors into Qs
allInteriorFold pq qalg [] <> = <>
allInteriorFold pq qalg (i ,- is) (pi , pis) =
interiorFold pq qalg i pi , allInteriorFold pq qalg is pis
-- The trouble is that if you use
-- all (interiorFold pq qalg)
-- to process the sub-interiors, the termination checker complains.
-- But if you've built "all" correctly, you should be able to prove this:
--??--2.10--------------------------------------------------------------------
allInteriorFoldLaw : (pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q) ->
allInteriorFold pq qalg == all (interiorFold pq qalg)
allInteriorFoldLaw pq qalg = extensionality \ is -> extensionality \ ps ->
{!!}
where
-- helper lemmas go here
--??--------------------------------------------------------------------------
-- Now, do me a favour and prove this extremely useful fact.
-- Its purpose is to bottle the inductive proof method for functions
-- built with interiorFold.
--??--2.11--------------------------------------------------------------------
interiorFoldLemma :
(pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q)
(f : [ Interior C P -:> Q ]) ->
((i : I)(p : P i) -> pq i p == f i (tile p)) ->
((i : I)(c : Cuts i)(ps : All (Interior C P) (inners c)) ->
qalg i (c 8>< all f (inners c) ps) == f i < c 8>< ps >) ->
(i : I)(pi : Interior C P i) -> interiorFold pq qalg i pi == f i pi
interiorFoldLemma pq qalg f base step i pi = {!!}
--??--------------------------------------------------------------------------
-- We'll use it in this form:
interiorFoldLaw : (pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q)
(f : [ Interior C P -:> Q ]) ->
((i : I)(p : P i) -> pq i p == f i (tile p)) ->
((i : I)(c : Cuts i)(ps : All (Interior C P) (inners c)) ->
qalg i (c 8>< all f (inners c) ps) == f i < c 8>< ps >) ->
interiorFold pq qalg == f
interiorFoldLaw pq qalg f base step =
extensionality \ i -> extensionality \ pi ->
interiorFoldLemma pq qalg f base step i pi
open INTERIORFOLD
-- Let me pay you back immediately!
-- An interiorBind is an interiorFold which computes an Interior,
-- rewrapping each layer with < ... >
interiorBind : {X Y : I -> Set} ->
[ X -:> Interior C Y ] -> [ Interior C X -:> Interior C Y ]
interiorBind f = interiorFold f (\ i -> <_>)
-- Because an interiorBind *makes* an interior, we can say something useful
-- about what happens if we follow it with an interiorFold.
interiorBindFusion : {X Y Z : I -> Set} ->
(f : [ X -:> Interior C Y ])
(yz : [ Y -:> Z ])(zalg : Algebra (CUTTING C) Z) ->
(interiorBind f >~> interiorFold yz zalg) ==
interiorFold (f >~> interiorFold yz zalg) zalg
-- That is, we can "fuse" the two together, making one interiorFold.
-- I'll do the proof as it's a bit hairy. You've given me all I need.
-- Note that I don't use extensionality, just laws that relate functions.
interiorBindFusion f yz zalg =
(interiorBind f >~> interiorFold yz zalg)
=< interiorFoldLaw
(f >~> interiorFold yz zalg) zalg
(interiorBind f >~> interiorFold yz zalg)
(\ i p -> refl (interiorFold yz zalg i (f i p)))
(\ i c ps -> refl (zalg i) =$= (refl (c 8><_) =$= (
((all (interiorBind f >~> interiorFold yz zalg)
=[ F-map->~> (interiorBind f) (interiorFold yz zalg) >=
(all (interiorBind f) >~> all (interiorFold yz zalg))
=< refl _>~>_
=$= allInteriorFoldLaw f cut'
=$= allInteriorFoldLaw yz zalg ]=
allInteriorFold f (\ i -> <_>) >~> allInteriorFold yz zalg [QED])
=$ inners c =$= refl ps))))
]=
interiorFold (f >~> interiorFold yz zalg) zalg [QED]
where open _=>_ (ALL I)
-- You should find that a very useful piece of kit. In fact, you should
-- not need extensionality, either.
-- We need Interior C to be a functor.
--??--2.12--------------------------------------------------------------------
-- using interiorBind, implement the "F-map" for Interiors as a one-liner
interior : {X Y : I -> Set} ->
[ X -:> Y ] -> [ Interior C X -:> Interior C Y ]
interior f = {!!}
-- using interiorBindFusion, prove the following law for "fold after map"
interiorFoldFusion : {P Q R : I -> Set}
(pq : [ P -:> Q ])(qr : [ Q -:> R ])(ralg : Algebra (CUTTING C) R) ->
(interior pq >~> interiorFold qr ralg) == interiorFold (pq >~> qr) ralg
interiorFoldFusion pq qr ralg =
interior pq >~> interiorFold qr ralg
=[ {!!} >=
interiorFold (pq >~> qr) ralg [QED]
where open _=>_ (ALL I)
-- and now, using interiorFoldFusion if it helps,
-- complete the functor construction
INTERIOR : (I ->SET) => (I ->SET)
INTERIOR = record
{ F-Obj = Interior C
; F-map = interior
; F-map-id~> = {!!}
; F-map->~> = {!!}
} where open _=>_ (ALL I)
--??--------------------------------------------------------------------------
-- Now let's build the Monad.
-- You should find that all the laws you have to prove follow from the
-- fusion laws you already have.
open MONAD INTERIOR
--??--2.13--------------------------------------------------------------------
WRAP : ID ~~> INTERIOR
WRAP = record
{ xf = {!!}
; naturality = {!!}
}
-- use interiorBind to define the following
FLATTEN : (INTERIOR >=> INTERIOR) ~~> INTERIOR
FLATTEN = record
{ xf = {!!}
; naturality = {!!}
}
INTERIOR-Monad : Monad
INTERIOR-Monad = record
{ unit = WRAP
; mult = FLATTEN
; unitMult = {!!}
; multUnit = {!!}
; multMult = {!!}
} where
open _=>_ INTERIOR
--??--------------------------------------------------------------------------
open INTERIOR
open INTERIORFOLD
-- You should be able to define an algebra on vectors for NatCut, using +V
--??--2.14--------------------------------------------------------------------
NatCutVecAlg : {X : Set} -> Algebra (CUTTING NatCut) (Vec X)
NatCutVecAlg n xsc = {!!}
--??--------------------------------------------------------------------------
-- Check that it puts things together suitably when you evaluate this:
test1 : Vec Char 13
test1 = interiorFold (\ _ -> id) NatCutVecAlg 13 subbookkeeper
------------------------------------------------------------------------------
-- Cutting Up Pairs
------------------------------------------------------------------------------
module CHOICE where
open _|>_
--??--2.15--------------------------------------------------------------------
-- Show that if you can cut up I and cut up J, then you can cut up I * J.
-- You now have two dimensions (I and J). The idea is that you choose one
-- dimension in which to make a cut, and keep everything in the other
-- dimension the same.
_+C_ : {I J : Set} -> I |> I -> J |> J -> (I * J) |> (I * J)
Cuts (P +C Q) (i , j) = Cuts P i + Cuts Q j
inners (P +C Q) = {!!}
--??--------------------------------------------------------------------------
open CHOICE
-- That should get us the ability to cut up *rectangules* by cutting either
-- vertically or horizontally.
NatCut2D : (Nat * Nat) |> (Nat * Nat)
NatCut2D = NatCut +C NatCut
Matrix : Set -> Nat * Nat -> Set
Matrix X (w , h) = Vec (Vec X w) h
-- If you've done it right, you should find that the following typechecks.
-- It's the interior of a rectangle, tiled with matrices of characters.
rectangle : Interior NatCut2D (Matrix Char) (15 , 6)
rectangle = < inr (4 , 2 , refl _)
8>< < inl (7 , 8 , refl _)
8>< tile (strVec "seventy"
,- strVec "kitchen"
,- strVec "program"
,- strVec "mistake"
,- [])
, tile (strVec "thousand"
,- strVec "soldiers"
,- strVec "probably"
,- strVec "undefine"
,- [])
, <> >
, tile (strVec "acknowledgement"
,- strVec "procrastination"
,- [])
, <> >
-- Later, we'll use rectangular interiors as the underlying data structure
-- for a window manager.
-- But for now, one last thing.
--??--2.16--------------------------------------------------------------------
-- Show that if you have a vector of n Ps for every element of a list,
-- then you can make a vector of n (All P)s .
-- Hint: Ex1 provides some useful equipment for this job.
vecAll : {I : Set}{P : I -> Set}{is : List I}{n : Nat} ->
All (\ i -> Vec (P i) n) is -> Vec (All P is) n
vecAll {is = is} pss = {!!}
-- Given vecAll, show that algebra for any cutting can be lifted
-- to an algebra on vectors.
VecLiftAlg : {I : Set}(C : I |> I){X : I -> Set}
(alg : Algebra (CUTTING C) X){n : Nat} ->
Algebra (CUTTING C) (\ i -> Vec (X i) n)
VecLiftAlg C alg i (c 8>< pss) = {!!}
-- Now show that you can build an algebra for matrices
-- which handles cuts in either dimension,
-- combining them either horizontally or vertically!
NatCut2DMatAlg : {X : Set} -> Algebra (CUTTING NatCut2D) (Matrix X)
NatCut2DMatAlg _ (inl c 8>< ms) = {!!}
NatCut2DMatAlg _ (inr c 8>< ms) = {!!}
--??--------------------------------------------------------------------------
-- And that should give you a way to glue pictures together from interiors.
picture : [ Interior NatCut2D (Matrix Char) -:> Matrix Char ]
picture = interiorFold (\ _ -> id) NatCut2DMatAlg
-- You should be able to check that the following gives you something
-- sensible:
test2 = picture _ rectangle
| 33.346003
| 79
| 0.471171
|
572c90db65bd126baad781d880f80a02d29f4ad2
| 7,322
|
agda
|
Agda
|
old/Complexity-lang.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 2
|
2016-04-26T20:22:22.000Z
|
2019-08-08T12:27:18.000Z
|
old/Complexity-lang.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | 1
|
2020-03-23T08:39:04.000Z
|
2020-05-12T00:32:45.000Z
|
old/Complexity-lang.agda
|
benhuds/Agda
|
2404a6ef2688f879bda89860bb22f77664ad813e
|
[
"MIT"
] | null | null | null |
{- Name: Bowornmet (Ben) Hudson
--Complexity : "Playing The Game"--
-}
open import Preliminaries
open import Preorder-withmax
module Complexity-lang where
data Typ : Set where
nat : Typ
_×'_ : Typ → Typ → Typ
_⇒_ : Typ → Typ → Typ
unit : Typ
------------------------------------------
-- represent a context as a list of types
Ctx = List Typ
-- de Bruijn indices (for free variables)
data _∈_ : Typ → Ctx → Set where
i0 : ∀ {Γ T}
→ T ∈ (T :: Γ)
iS : ∀ {Γ T T1}
→ T ∈ Γ
→ T ∈ (T1 :: Γ)
------------------------------------------
-- some syntax
data _|-_ : Ctx → Typ → Set where
var : ∀ {Γ T}
→ (x : T ∈ Γ) → Γ |- T
z : ∀ {Γ}
→ Γ |- nat
suc : ∀ {Γ}
→ (e : Γ |- nat)
→ Γ |- nat
rec : ∀ {Γ T}
→ (e : Γ |- nat)
→ (e0 : Γ |- T)
→ (e1 : (nat :: (T :: Γ)) |- T)
→ Γ |- T
lam : ∀ {Γ T Ρ}
→ (x : (Ρ :: Γ) |- T)
→ Γ |- (Ρ ⇒ T)
app : ∀ {Γ T1 T2}
→ (e1 : Γ |- (T2 ⇒ T1)) → (e2 : Γ |- T2)
→ Γ |- T1
unit : ∀ {Γ}
→ Γ |- unit
prod : ∀ {Γ T1 T2}
→ (e1 : Γ |- T1) → (e2 : Γ |- T2)
→ Γ |- (T1 ×' T2)
l-proj : ∀ {Γ T1 T2}
→ (e : Γ |- (T1 ×' T2))
→ Γ |- T1
r-proj : ∀ {Γ T1 T2}
→ (e : Γ |- (T1 ×' T2))
→ Γ |- T2
------------------------------------------
-- renaming function
rctx : Ctx → Ctx → Set
rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ
lem1 : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ')
lem1 d i0 = i0
lem1 d (iS x) = iS (d x)
ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ
ren (var x) d = var (d x)
ren z d = z
ren (suc e) d = suc (ren e d)
ren (rec e0 e1 e2) d = rec (ren e0 d) (ren e1 d) (ren e2 (lem1 (lem1 d)))
ren (lam x) d = lam (ren x (lem1 d))
ren (app e1 e2) d = app (ren e1 d) (ren e2 d)
ren unit d = unit
ren (prod e1 e2) d = prod (ren e1 d) (ren e2 d)
ren (l-proj e) d = l-proj (ren e d)
ren (r-proj e) d = r-proj (ren e d)
------------------------------------------
-- substitution
sctx : Ctx → Ctx → Set
sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ
-- weakening
wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2
wkn e = ren e iS
-- lemmas everywhere
wkn-s : ∀ {Γ τ1 Γ'} → sctx Γ Γ' → sctx (τ1 :: Γ) Γ'
wkn-s d = λ f → wkn (d f)
wkn-r : ∀ {Γ τ1 Γ'} → rctx Γ Γ' → rctx (τ1 :: Γ) Γ'
wkn-r d = λ x → iS (d x)
lem2 : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ')
lem2 d i0 = var i0
lem2 d (iS i) = wkn (d i)
lem3 : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ)
lem3 e i0 = e
lem3 e (iS i) = var i
lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ))
lem4 e1 e2 i0 = e1
lem4 e1 e2 (iS i0) = e2
lem4 e1 e2 (iS (iS i)) = var i
subst : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ' |- τ → Γ |- τ
subst d (var x) = d x
subst d z = z
subst d (suc e) = suc (subst d e)
subst d (rec e0 e1 e2) = rec (subst d e0) (subst d e1) (subst (lem2 (lem2 d)) e2)
subst d (lam e) = lam (subst (lem2 d) e)
subst d (app e1 e2) = app (subst d e1) (subst d e2)
subst d unit = unit
subst d (prod e1 e2) = prod (subst d e1) (subst d e2)
subst d (l-proj e) = l-proj (subst d e)
subst d (r-proj e) = r-proj (subst d e)
------------------------------------------
-- define 'stepping' as a datatype (fig. 1 of proof)
data _≤s_ : ∀ {Γ T} → Γ |- T → Γ |- T → Set where
refl-s : ∀ {Γ T}
→ (e : Γ |- T)
→ e ≤s e
trans-s : ∀ {Γ T}
→ (e e' e'' : Γ |- T)
→ e ≤s e' → e' ≤s e''
→ e ≤s e''
cong-s : ∀ {Γ T T'}
→ (e : (T :: Γ) |- T')
→ (e1 e2 : Γ |- T)
→ e1 ≤s e2
→ subst (lem3 e1) e ≤s subst (lem3 e2) e
lam-s : ∀ {Γ T T'}
→ (e : (T :: Γ) |- T')
→ (e2 : Γ |- T)
→ subst (lem3 e2) e ≤s app (lam e) e2
l-proj-s : ∀ {Γ T1 T2}
→ (e1 : Γ |- T1) → (e2 : Γ |- T2)
→ e1 ≤s (l-proj (prod e1 e2))
r-proj-s : ∀ {Γ T1 T2}
→ (e1 : Γ |- T1) → (e2 : Γ |- T2)
→ e2 ≤s (r-proj (prod e1 e2))
rec-steps-s : ∀ {Γ T}
→ (e : Γ |- nat)
→ (e0 : Γ |- T)
→ (e1 : (nat :: (T :: Γ)) |- T)
→ subst (lem4 e (rec e e0 e1)) e1 ≤s (rec (suc e) e0 e1)
rec-steps-z : ∀ {Γ T}
→ (e0 : Γ |- T)
→ (e1 : (nat :: (T :: Γ)) |- T)
→ e0 ≤s (rec z e0 e1)
------------------------------------------
el : PREORDER → Set
el = fst
PREORDER≤ : (PA : PREORDER) → el PA → el PA → Set
PREORDER≤ PA = Preorder-max-str.≤ (snd PA)
interp : Typ → PREORDER
interp nat = Nat , nat-p
interp (A ×' B) = interp A ×p interp B
interp (A ⇒ B) = interp A ->p interp B
interp unit = unit-p
interpC : Ctx → PREORDER
interpC [] = unit-p
interpC (A :: Γ) = interpC Γ ×p interp A
-- look up a variable in context
lookup : ∀{Γ τ} → τ ∈ Γ → el (interpC Γ ->p interp τ)
lookup (i0 {Γ} {τ}) = snd' {interpC (τ :: Γ)} {interpC Γ} {_} id
lookup (iS {Γ} {τ} {τ1} x) = comp {interpC (τ1 :: Γ)} {_} {_} (fst' {interpC (τ1 :: Γ)} {_} {interp τ1} id) (lookup x)
interpE : ∀{Γ τ} → Γ |- τ → el (interpC Γ ->p interp τ)
interpE (var x) = lookup x
interpE z = monotone (λ x → Z) (λ x y _ → <>)
interpE (suc e) = {!!} --monotone (λ x → S {!!}) {!!}
interpE {_} {τ} (rec e0 e1 e2) = {!!} --mnatrec {!!} (λ x x₁ → interpE e1) {!!}
interpE (lam e) = lam' (interpE e)
interpE (app e1 e2) = app' (interpE e1) (interpE e2)
interpE unit = monotone (λ _ → <>) (λ x y _ → <>)
interpE (prod e1 e2) = pair' (interpE e1) (interpE e2)
interpE (l-proj {Γ} {τ1} {τ2} e) = fst' {_} {_} {interp τ2} (interpE e)
interpE (r-proj {Γ} {τ1} {τ2} e) = snd' {_} {interp τ1} {_} (interpE e)
cong-lemma : ∀ {Γ τ τ'}
→ (e : (τ :: Γ) |- τ')
→ (e1 e2 : Γ |- τ)
→ e1 ≤s e2
→ (k : fst (interpC Γ))
→ Preorder-max-str.≤ (snd (interp τ)) {!!} {!!}
cong-lemma = {!!}
{-
Preorder-max-str.≤ (snd (interp .τ))
(Monotone.f (interpE (subst (lem3 e1) e)) k)
(Monotone.f (interpE (subst (lem3 e2) e)) k)
-}
sound : ∀ {Γ τ} (e e' : Γ |- τ) → e ≤s e' → PREORDER≤ (interpC Γ ->p interp τ) (interpE e) (interpE e')
sound {_} {τ} .e' e' (refl-s .e') k = Preorder-max-str.refl (snd (interp τ)) (Monotone.f (interpE e') k)
sound {_} {τ} e e' (trans-s .e e'' .e' p p₁) k = Preorder-max-str.trans (snd (interp τ)) (Monotone.f (interpE e) k)
(Monotone.f (interpE e'') k) (Monotone.f (interpE e') k)
(sound e e'' p k) (sound e'' e' p₁ k)
sound .(subst (lem3 e1) e) .(subst (lem3 e2) e) (cong-s e e1 e2 p) k = Monotone.is-monotone {!!} (subst (lem3 e1) e) (subst (lem3 e2) e) cong-s
sound .(subst (lem3 e2) e) .(app (lam e) e2) (lam-s e e2) k = {!!}
sound {_} {τ} e .(l-proj (prod e e2)) (l-proj-s .e e2) k = Preorder-max-str.refl (snd (interp τ)) (Monotone.f (interpE e) k)
sound {_} {τ} e .(r-proj (prod e1 e)) (r-proj-s e1 .e) k = Preorder-max-str.refl (snd (interp τ)) (Monotone.f (interpE e) k)
sound .(subst (lem4 e (rec e e0 e1)) e1) .(rec (suc e) e0 e1) (rec-steps-s e e0 e1) k = {!!}
sound e .(rec z e e1) (rec-steps-z .e e1) k = {!!}
| 32.542222
| 145
| 0.426386
|
fbbbc290bcf2c0b902ace760a56af51164378f1c
| 4,152
|
agda
|
Agda
|
src/Implicits/Resolution/Infinite/NormalFormEquiv.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/Implicits/Resolution/Infinite/NormalFormEquiv.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Implicits/Resolution/Infinite/NormalFormEquiv.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
module Implicits.Resolution.Infinite.NormalFormEquiv where
open import Prelude
open import Implicits.Syntax
open import Implicits.Resolution.Infinite.Resolution
open import Implicits.Resolution.Embedding
open import Implicits.Resolution.Embedding.Lemmas
open import SystemF.Everything as F using ()
open import SystemF.NormalForm
open import Data.Vec hiding ([_])
open import Relation.Binary.HeterogeneousEquality as H using ()
open import Data.List.Any
open import Data.List.Properties
open import Data.Vec.Properties as VP using ()
open import Extensions.Vec
open import Function.Equivalence using (_⇔_; equivalence)
mutual
from-⇓ : ∀ {ν n t a τ} {Γ : F.Ctx ν n} → Γ ⊢ t ⇓ a → ⟦ Γ ⟧ctx← ⊢ ⟦ a ⟧tp← ↓ τ →
∃ λ i → ⟦ Γ ⟧ctx← ⊢ ⟦ lookup i Γ ⟧tp← ↓ τ
from-⇓ {Γ = Γ} (nvar i) ↓τ = i , ↓τ
from-⇓ (napp p x) ↓τ = from-⇓ p (i-iabs (from-⇑ x) ↓τ)
from-⇓ {Γ = Γ} (ntapp {a = a} b p) ↓τ = from-⇓ p
(i-tabs ⟦ b ⟧tp← (subst (λ z → ⟦ Γ ⟧ctx← ⊢ z ↓ _) (⟦a/sub⟧tp← a b) ↓τ))
from-⇑ : ∀ {ν n t a} {Γ : F.Ctx ν n} → Γ ⊢ t ⇑ a → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ a ⟧tp←
from-⇑ (nbase b x) with ⟦base⟧tp← b
from-⇑ (nbase b x) | τ , eq with from-⇓ x (subst (λ z → _ ⊢ z ↓ τ) (sym $ eq) (i-simp τ))
from-⇑ (nbase b x) | τ , eq | i , lookup-i↓tc =
subst (λ z → _ ⊢ᵣ z) (sym $ eq) (r-simp (lookup-∈ i _) lookup-i↓tc)
from-⇑ (nabs p) = r-iabs (from-⇑ p)
from-⇑ (ntabs p) = r-tabs (subst (λ z → z ⊢ᵣ _) (⟦weaken⟧ctx← _) (from-⇑ p))
to-⇓ : ∀ {ν} {Δ : ICtx ν} {a τ t₁} → Δ ⊢ a ↓ τ → ⟦ Δ ⟧ctx→ ⊢ t₁ ⇓ ⟦ a ⟧tp→ →
∃ λ t₂ → ⟦ Δ ⟧ctx→ ⊢ t₂ ⇓ ⟦ simpl τ ⟧tp→
to-⇓ (i-simp a) q = , q
to-⇓ (i-iabs x p) q = to-⇓ p (napp q (proj₂ $ to-⇑ x))
to-⇓ {Δ = Δ} (i-tabs {ρ = a} b p) q =
to-⇓ p (subst (λ z → ⟦ Δ ⟧ctx→ ⊢ _ ⇓ z) (sym $ ⟦a/sub⟧tp→ a b) (ntapp ⟦ b ⟧tp→ q))
to-⇑ : ∀ {ν} {Δ : ICtx ν} {a} → Δ ⊢ᵣ a → ∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ a ⟧tp→
to-⇑ {Δ = Δ} (r-simp {r = a} r r↓τ) = , nbase (⟦simpl⟧tp→ _) (proj₂ $ to-⇓ r↓τ var⇓a)
where
var⇓a : ⟦ Δ ⟧ctx→ ⊢ _ ⇓ ⟦ a ⟧tp→
var⇓a = let (i , eq) = ∈⟶index (VP.List-∈⇒∈ r) in
let i' = (subst Fin (sym $ length-map _ Δ) i) in
subst (λ z → ⟦ Δ ⟧ctx→ ⊢ (F.var i') ⇓ z) (lookup⟦⟧ Δ i eq) (nvar i')
to-⇑ (r-iabs p) =
, nabs (proj₂ $ to-⇑ p)
to-⇑ {Δ = Δ} (r-tabs {ρ = a} p) =
, ntabs (⇑-subst-n (length-weaken-Δ Δ) (H.sym $ ⟦weaken⟧ctx→ Δ) (proj₂ (to-⇑ p)))
-- System F η-long-β-normal forms are isomorphic to infinite resolution derivations
equivalent : ∀ {ν} (Δ : ICtx ν) r → Δ ⊢ᵣ r ⇔ (∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ r ⟧tp→)
equivalent Δ r = equivalence
(λ x → to-⇑ x)
(λ x → subst₂ (λ Δ' r' → Δ' ⊢ᵣ r') (ctx→← _) (tp→← r) (from-⇑ (proj₂ x)))
{-}
open import Function.Inverse
open import Function.Equality
-- from-⇑ : ∀ {ν n t a} {Γ : F.Ctx ν n} → Γ ⊢ t ⇑ a → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ a ⟧tp←
from-⇑' : ∀ {ν a} {Δ : ICtx ν} → (∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ a ⟧tp→) → Δ ⊢ᵣ a
from-⇑' (_ , p) = subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (from-⇑ p)
-- from-⇓' : ∀ {ν a} {Δ : ICtx ν} {τ} → (∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇓ ⟦ a ⟧tp→) → Δ ⊢ Δ ⊢ a ↓ τ
-- from-⇓' {τ = τ} (_ , p) = subst₂ (λ Δ a → Δ ⊢ a ↓ τ) (ctx→← _) (tp→← _) (from-⇓ p)
-- from-to-⇓ : ∀ {ν a} {Δ : ICtx ν} {τ} → (p : Δ ⊢ a ↓ τ) → from-⇓' (to-⇓ p) ≡ p
-- from-to-⇓ p = ?
from-to-⇑ : ∀ {ν a} {Δ : ICtx ν} → (p : Δ ⊢ᵣ a) → from-⇑' (to-⇑ p) ≡ p
from-to-⇑ (r-simp x x₁) = {!!}
from-to-⇑ (r-iabs p) = begin
from-⇑' (, (nabs (proj₂ (to-⇑ p))))
≡⟨ refl ⟩
subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (from-⇑ (nabs (proj₂ (to-⇑ p))))
≡⟨ refl ⟩
subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (r-iabs (from-⇑ (proj₂ (to-⇑ p))))
≡⟨ {!!} ⟩
r-iabs (subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (from-⇑ (proj₂ (to-⇑ p))))
≡⟨ refl ⟩
r-iabs (from-⇑' (to-⇑ p))
≡⟨ Prelude.cong r-iabs (from-to-⇑ p) ⟩
r-iabs p ∎
from-to-⇑ (r-tabs p) with from-to-⇑ p
from-to-⇑ (r-tabs p) | x = {!x!}
where
lem : ∀ {ν a} {Δ : ICtx ν} →
to-from-⇑ : ∀ {ν a} {Δ : ICtx ν} → (p : ∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ a ⟧tp→) → to-⇑ (from-⇑' p) ≡ p
to-from-⇑ p = {!!}
iso' : ∀ {ν a} {Δ : ICtx ν} → (→-to-⟶ (to-⇑ {Δ = Δ} {a = a})) InverseOf (→-to-⟶ from-⇑')
iso' = record { left-inverse-of = to-from-⇑; right-inverse-of = from-to-⇑ }
-}
| 40.31068
| 96
| 0.490125
|
2f8794d8fab7d294569baa241020f5c96662dee2
| 1,911
|
agda
|
Agda
|
agda-stdlib/README/Data/Integer.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/README/Data/Integer.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/README/Data/Integer.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some examples showing where the integers and some related
-- operations and properties are defined, and how they can be used
------------------------------------------------------------------------
{-# OPTIONS --without-K #-}
module README.Data.Integer where
-- The integers and various arithmetic operations are defined in
-- Data.Integer.
open import Data.Integer
-- The +_ function converts natural numbers into integers.
ex₁ : ℤ
ex₁ = + 2
-- The -_ function negates an integer.
ex₂ : ℤ
ex₂ = - + 4
-- Some binary operators are also defined, including addition,
-- subtraction and multiplication.
ex₃ : ℤ
ex₃ = + 1 + + 3 * - + 2 - + 4
-- Propositional equality and some related properties can be found
-- in Relation.Binary.PropositionalEquality.
open import Relation.Binary.PropositionalEquality as P using (_≡_)
ex₄ : ex₃ ≡ - + 9
ex₄ = P.refl
-- Data.Integer.Properties contains a number of properties related to
-- integers. Algebra defines what a commutative ring is, among other
-- things.
import Data.Integer.Properties as ℤₚ
ex₅ : ∀ i j → i * j ≡ j * i
ex₅ i j = ℤₚ.*-comm i j
-- The module ≡-Reasoning in Relation.Binary.PropositionalEquality
-- provides some combinators for equational reasoning.
open P.≡-Reasoning
open import Data.Product
ex₆ : ∀ i j → i * (j + + 0) ≡ j * i
ex₆ i j = begin
i * (j + + 0) ≡⟨ P.cong (i *_) (ℤₚ.+-identityʳ j) ⟩
i * j ≡⟨ ℤₚ.*-comm i j ⟩
j * i ∎
-- The module RingSolver in Data.Integer.Solver contains a solver
-- for integer equalities involving variables, constants, _+_, _*_, -_
-- and _-_.
open import Data.Integer.Solver using (module +-*-Solver)
open +-*-Solver
ex₇ : ∀ i j → i * - j - j * i ≡ - + 2 * i * j
ex₇ = solve 2 (λ i j → i :* :- j :- j :* i := :- con (+ 2) :* i :* j)
P.refl
| 26.541667
| 72
| 0.603872
|
41ea9411d3aa8703445d85791a28a1a2da5e8f5d
| 5,101
|
agda
|
Agda
|
core/lib/types/Group.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
core/lib/types/Group.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
core/lib/types/Group.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pi
module lib.types.Group where
record GroupStructure {i} (El : Type i) --(El-level : has-level 0 El)
: Type i where
constructor group-structure
field
ident : El
inv : El → El
comp : El → El → El
unitl : ∀ a → comp ident a == a
unitr : ∀ a → comp a ident == a
assoc : ∀ a b c → comp (comp a b) c == comp a (comp b c)
invl : ∀ a → (comp (inv a) a) == ident
invr : ∀ a → (comp a (inv a)) == ident
record Group i : Type (lsucc i) where
constructor group
field
El : Type i
El-level : has-level 0 El
group-struct : GroupStructure El
open GroupStructure group-struct public
⊙El : Σ (Type i) (λ A → A)
⊙El = (El , ident)
Group₀ : Type (lsucc lzero)
Group₀ = Group lzero
is-abelian : ∀ {i} → Group i → Type i
is-abelian G = (a b : Group.El G) → Group.comp G a b == Group.comp G b a
module _ where
open GroupStructure
abstract
group-structure= : ∀ {i} {A : Type i} (pA : has-level 0 A)
{id₁ id₂ : A} {inv₁ inv₂ : A → A} {comp₁ comp₂ : A → A → A}
→ ∀ {unitl₁ unitl₂} → ∀ {unitr₁ unitr₂} → ∀ {assoc₁ assoc₂}
→ ∀ {invr₁ invr₂} → ∀ {invl₁ invl₂}
→ (id₁ == id₂) → (inv₁ == inv₂) → (comp₁ == comp₂)
→ Path {A = GroupStructure A}
(group-structure id₁ inv₁ comp₁ unitl₁ unitr₁ assoc₁ invl₁ invr₁)
(group-structure id₂ inv₂ comp₂ unitl₂ unitr₂ assoc₂ invl₂ invr₂)
group-structure= pA {id₁ = id₁} {inv₁ = inv₁} {comp₁ = comp₁} idp idp idp =
ap5 (group-structure id₁ inv₁ comp₁)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
(prop-has-all-paths
(Π-level (λ _ → Π-level (λ _ → Π-level (λ _ → pA _ _)))) _ _)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
where
ap5 : ∀ {j} {C D E F G H : Type j}
{c₁ c₂ : C} {d₁ d₂ : D} {e₁ e₂ : E} {f₁ f₂ : F} {g₁ g₂ : G}
(f : C → D → E → F → G → H)
→ (c₁ == c₂) → (d₁ == d₂) → (e₁ == e₂) → (f₁ == f₂) → (g₁ == g₂)
→ f c₁ d₁ e₁ f₁ g₁ == f c₂ d₂ e₂ f₂ g₂
ap5 f idp idp idp idp idp = idp
↓-group-structure= : ∀ {i} {A B : Type i}
(A-level : has-level 0 A)
{GS : GroupStructure A} {HS : GroupStructure B} (p : A == B)
→ (ident GS == ident HS [ (λ C → C) ↓ p ])
→ (inv GS == inv HS [ (λ C → C → C) ↓ p ])
→ (comp GS == comp HS [ (λ C → C → C → C) ↓ p ])
→ GS == HS [ GroupStructure ↓ p ]
↓-group-structure= A-level idp = group-structure= A-level
module _ {i} (G : Group i) where
private
open Group G
infix 80 _⊙_
_⊙_ = comp
group-inv-unique-l : (g h : El) → (g ⊙ h == ident) → inv h == g
group-inv-unique-l g h p =
inv h =⟨ ! (unitl (inv h)) ⟩
ident ⊙ inv h =⟨ ! p |in-ctx (λ w → w ⊙ inv h) ⟩
(g ⊙ h) ⊙ inv h =⟨ assoc g h (inv h) ⟩
g ⊙ (h ⊙ inv h) =⟨ invr h |in-ctx (λ w → g ⊙ w) ⟩
g ⊙ ident =⟨ unitr g ⟩
g ∎
group-inv-unique-r : (g h : El) → (g ⊙ h == ident) → inv g == h
group-inv-unique-r g h p =
inv g =⟨ ! (unitr (inv g)) ⟩
inv g ⊙ ident =⟨ ! p |in-ctx (λ w → inv g ⊙ w) ⟩
inv g ⊙ (g ⊙ h) =⟨ ! (assoc (inv g) g h) ⟩
(inv g ⊙ g) ⊙ h =⟨ invl g |in-ctx (λ w → w ⊙ h) ⟩
ident ⊙ h =⟨ unitl h ⟩
h ∎
group-inv-ident : inv ident == ident
group-inv-ident =
group-inv-unique-l ident ident (unitl ident)
group-inv-comp : (g₁ g₂ : El) → inv (g₁ ⊙ g₂) == inv g₂ ⊙ inv g₁
group-inv-comp g₁ g₂ =
group-inv-unique-r (g₁ ⊙ g₂) (inv g₂ ⊙ inv g₁) $
(g₁ ⊙ g₂) ⊙ (inv g₂ ⊙ inv g₁)
=⟨ assoc g₁ g₂ (inv g₂ ⊙ inv g₁) ⟩
g₁ ⊙ (g₂ ⊙ (inv g₂ ⊙ inv g₁))
=⟨ ! (assoc g₂ (inv g₂) (inv g₁)) |in-ctx (λ w → g₁ ⊙ w) ⟩
g₁ ⊙ ((g₂ ⊙ inv g₂) ⊙ inv g₁)
=⟨ invr g₂ |in-ctx (λ w → g₁ ⊙ (w ⊙ inv g₁)) ⟩
g₁ ⊙ (ident ⊙ inv g₁)
=⟨ unitl (inv g₁) |in-ctx (λ w → g₁ ⊙ w) ⟩
g₁ ⊙ inv g₁
=⟨ invr g₁ ⟩
ident ∎
group-inv-inv : (g : El) → inv (inv g) == g
group-inv-inv g = group-inv-unique-r (inv g) g (invl g)
group-cancel-l : (g : El) {h k : El} → g ⊙ h == g ⊙ k → h == k
group-cancel-l g {h} {k} p =
h =⟨ ! (unitl h) ⟩
ident ⊙ h =⟨ ap (λ w → w ⊙ h) (! (invl g)) ⟩
(inv g ⊙ g) ⊙ h =⟨ assoc (inv g) g h ⟩
inv g ⊙ (g ⊙ h) =⟨ ap (λ w → inv g ⊙ w) p ⟩
inv g ⊙ (g ⊙ k) =⟨ ! (assoc (inv g) g k) ⟩
(inv g ⊙ g) ⊙ k =⟨ ap (λ w → w ⊙ k) (invl g) ⟩
ident ⊙ k =⟨ unitl k ⟩
k ∎
group-cancel-r : (g : El) {h k : El} → h ⊙ g == k ⊙ g → h == k
group-cancel-r g {h} {k} p =
h =⟨ ! (unitr h) ⟩
h ⊙ ident =⟨ ap (λ w → h ⊙ w) (! (invr g)) ⟩
h ⊙ (g ⊙ inv g) =⟨ ! (assoc h g (inv g)) ⟩
(h ⊙ g) ⊙ inv g =⟨ ap (λ w → w ⊙ inv g) p ⟩
(k ⊙ g) ⊙ inv g =⟨ assoc k g (inv g) ⟩
k ⊙ (g ⊙ inv g) =⟨ ap (λ w → k ⊙ w) (invr g) ⟩
k ⊙ ident =⟨ unitr k ⟩
k ∎
| 35.922535
| 79
| 0.466575
|
3ddb757f359a80309cb2fbbf752151d0fdc2e531
| 5,814
|
agda
|
Agda
|
notes/FOT/LTC-PCF/Data/Nat/SubtractionFixedPointOperator.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/LTC-PCF/Data/Nat/SubtractionFixedPointOperator.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/LTC-PCF/Data/Nat/SubtractionFixedPointOperator.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Subtraction using the fixed-point operator
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.LTC-PCF.Data.Nat.SubtractionFixedPointOperator where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Base.Properties
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Data/Nat.agda).
infixl 9 _∸_
------------------------------------------------------------------------------
-- Subtraction's definition
∸-helper : D → D
∸-helper f = lam (λ m → lam (λ n →
if (iszero₁ n)
then m
else if (iszero₁ m)
then zero
else f · pred₁ m · pred₁ n))
_∸_ : D → D → D
_∸_ m n = fix ∸-helper · m · n
------------------------------------------------------------------------------
-- Conversion rules from the Agda standard library 0.8.1 (see
-- Data/Nat.agda) without use induction.
private
----------------------------------------------------------------------------
-- The steps
-- See doc in LTC-PCF.Program.GCD.Total.Equations.
-- Initially, the conversion rule fix-eq is applied.
∸-s₁ : D → D → D
∸-s₁ m n = ∸-helper (fix ∸-helper) · m · n
-- First argument application.
∸-s₂ : D → D
∸-s₂ m = lam (λ n →
if (iszero₁ n)
then m
else if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n)
-- Second argument application.
∸-s₃ : D → D → D
∸-s₃ m n = if (iszero₁ n)
then m
else if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n
-- First if_then_else_ iszero₁ n = b.
∸-s₄ : D → D → D → D
∸-s₄ m n b = if b
then m
else if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n
-- First if_then_else_ when if true ...
∸-s₅ : D → D
∸-s₅ m = m
-- First if_then_else_ when if false ...
∸-s₆ : D → D → D
∸-s₆ m n = if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n
-- Second if_then_else_ iszero₁ m = b.
∸-s₇ : D → D → D → D
∸-s₇ m n b = if b then zero else fix ∸-helper · pred₁ m · pred₁ n
-- Second if_then_else_ when if true ...
∸-s₈ : D
∸-s₈ = zero
-- Second if_then_else_ when if false ...
∸-s₉ : D → D → D
∸-s₉ m n = fix ∸-helper · pred₁ m · pred₁ n
----------------------------------------------------------------------------
-- Congruence properties
∸-s₄Cong₃ : ∀ {m n b₁ b₂} → b₁ ≡ b₂ → ∸-s₄ m n b₁ ≡ ∸-s₄ m n b₂
∸-s₄Cong₃ refl = refl
∸-s₇Cong₃ : ∀ {m n b₁ b₂} → b₁ ≡ b₂ → ∸-s₇ m n b₁ ≡ ∸-s₇ m n b₂
∸-s₇Cong₃ refl = refl
----------------------------------------------------------------------------
-- The execution steps
-- See doc in LTC-PCF.Program.GCD.Total.Equations.
proof₀₋₁ : ∀ m n → fix ∸-helper · m · n ≡ ∸-s₁ m n
proof₀₋₁ m n = subst (λ x → x · m · n ≡ ∸-helper (fix ∸-helper) · m · n)
(sym (fix-eq ∸-helper))
refl
proof₁₋₂ : ∀ m n → ∸-s₁ m n ≡ ∸-s₂ m · n
proof₁₋₂ m n = subst (λ x → x · n ≡ ∸-s₂ m · n)
(sym (beta ∸-s₂ m))
refl
proof₂₋₃ : ∀ m n → ∸-s₂ m · n ≡ ∸-s₃ m n
proof₂₋₃ m n = beta (∸-s₃ m) n
proof₃₋₄ : ∀ m n b → iszero₁ n ≡ b → ∸-s₃ m n ≡ ∸-s₄ m n b
proof₃₋₄ m n b = ∸-s₄Cong₃
proof₄₊ : ∀ m n → ∸-s₄ m n true ≡ ∸-s₅ m
proof₄₊ m _ = if-true (∸-s₅ m)
proof₄₋₆ : ∀ m n → ∸-s₄ m n false ≡ ∸-s₆ m n
proof₄₋₆ m n = if-false (∸-s₆ m n)
proof₆₋₇ : ∀ m n b → iszero₁ m ≡ b → ∸-s₆ m n ≡ ∸-s₇ m n b
proof₆₋₇ m n b = ∸-s₇Cong₃
proof₇₊ : ∀ m n → ∸-s₇ m n true ≡ ∸-s₈
proof₇₊ m n = if-true ∸-s₈
proof₇₋₉ : ∀ m n → ∸-s₇ m n false ≡ ∸-s₉ m n
proof₇₋₉ m n = if-false (∸-s₉ m n)
------------------------------------------------------------------------------
-- The equations for subtraction
∸-x0 : ∀ n → n ∸ zero ≡ n
∸-x0 n =
n ∸ zero ≡⟨ proof₀₋₁ n zero ⟩
∸-s₁ n zero ≡⟨ proof₁₋₂ n zero ⟩
∸-s₂ n · zero ≡⟨ proof₂₋₃ n zero ⟩
∸-s₃ n zero ≡⟨ proof₃₋₄ n zero true iszero-0 ⟩
∸-s₄ n zero true ≡⟨ proof₄₊ n zero ⟩
n ∎
∸-0S : ∀ n → zero ∸ succ₁ n ≡ zero
∸-0S n =
zero ∸ succ₁ n ≡⟨ proof₀₋₁ zero (succ₁ n) ⟩
∸-s₁ zero (succ₁ n) ≡⟨ proof₁₋₂ zero (succ₁ n) ⟩
∸-s₂ zero · (succ₁ n) ≡⟨ proof₂₋₃ zero (succ₁ n) ⟩
∸-s₃ zero (succ₁ n) ≡⟨ proof₃₋₄ zero (succ₁ n) false (iszero-S n) ⟩
∸-s₄ zero (succ₁ n) false ≡⟨ proof₄₋₆ zero (succ₁ n) ⟩
∸-s₆ zero (succ₁ n) ≡⟨ proof₆₋₇ zero (succ₁ n) true iszero-0 ⟩
∸-s₇ zero (succ₁ n) true ≡⟨ proof₇₊ zero (succ₁ n) ⟩
zero ∎
∸-SS : ∀ m n → succ₁ m ∸ succ₁ n ≡ m ∸ n
∸-SS m n =
succ₁ m ∸ succ₁ n
≡⟨ proof₀₋₁ (succ₁ m) (succ₁ n) ⟩
∸-s₁ (succ₁ m) (succ₁ n)
≡⟨ proof₁₋₂ (succ₁ m) (succ₁ n) ⟩
∸-s₂ (succ₁ m) · (succ₁ n)
≡⟨ proof₂₋₃ (succ₁ m) (succ₁ n) ⟩
∸-s₃ (succ₁ m) (succ₁ n)
≡⟨ proof₃₋₄ (succ₁ m) (succ₁ n) false (iszero-S n) ⟩
∸-s₄ (succ₁ m) (succ₁ n) false
≡⟨ proof₄₋₆ (succ₁ m) (succ₁ n) ⟩
∸-s₆ (succ₁ m) (succ₁ n)
≡⟨ proof₆₋₇ (succ₁ m) (succ₁ n) false (iszero-S m) ⟩
∸-s₇ (succ₁ m) (succ₁ n) false
≡⟨ proof₇₋₉ (succ₁ m) (succ₁ n) ⟩
fix ∸-helper · pred₁ (succ₁ m) · pred₁ (succ₁ n)
≡⟨ ·-rightCong (pred-S n) ⟩
fix ∸-helper · pred₁ (succ₁ m) · n
≡⟨ ·-leftCong (·-rightCong (pred-S m)) ⟩
fix ∸-helper · m · n ∎
| 31.427027
| 78
| 0.445992
|
572b55502a4608d220c6ff7cdb5a953f48c98fc7
| 19,139
|
agda
|
Agda
|
agda-stdlib/src/Codata/Musical/Colist.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Codata/Musical/Colist.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Codata/Musical/Colist.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Coinductive lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types --guardedness #-}
-- Disabled to prevent warnings from BoundedVec
{-# OPTIONS --warn=noUserWarning #-}
module Codata.Musical.Colist where
open import Category.Monad
open import Codata.Musical.Notation
open import Codata.Musical.Conat using (Coℕ; zero; suc)
open import Data.Bool.Base using (Bool; true; false)
open import Data.Empty using (⊥)
open import Data.Maybe using (Maybe; nothing; just; Is-just)
open import Data.Maybe.Relation.Unary.Any using (just)
open import Data.Nat.Base using (ℕ; zero; suc; _≥′_; ≤′-refl; ≤′-step)
open import Data.Nat.Properties using (s≤′s)
open import Data.List.Base using (List; []; _∷_)
open import Data.List.NonEmpty using (List⁺; _∷_)
open import Data.Product as Prod using (∃; _×_; _,_)
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Data.Vec.Bounded as Vec≤ using (Vec≤)
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (_↔_; _↔̇_; Inverse; inverse)
open import Level using (_⊔_)
open import Relation.Binary
import Relation.Binary.Construct.FromRel as Ind
import Relation.Binary.Reasoning.Preorder as PreR
import Relation.Binary.Reasoning.PartialOrder as POR
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary.Reflects using (invert)
open import Relation.Nullary
open import Relation.Nullary.Negation
module ¬¬Monad {p} where
open RawMonad (¬¬-Monad {p}) public
open ¬¬Monad -- we don't want the RawMonad content to be opened publicly
------------------------------------------------------------------------
-- The type
infixr 5 _∷_
data Colist {a} (A : Set a) : Set a where
[] : Colist A
_∷_ : (x : A) (xs : ∞ (Colist A)) → Colist A
{-# FOREIGN GHC
data AgdaColist a = Nil | Cons a (MAlonzo.RTE.Inf (AgdaColist a))
type AgdaColist' l a = AgdaColist a
#-}
{-# COMPILE GHC Colist = data AgdaColist' (Nil | Cons) #-}
{-# COMPILE UHC Colist = data __LIST__ (__NIL__ | __CONS__) #-}
module Colist-injective {a} {A : Set a} where
∷-injectiveˡ : ∀ {x y : A} {xs ys} → (Colist A ∋ x ∷ xs) ≡ y ∷ ys → x ≡ y
∷-injectiveˡ P.refl = P.refl
∷-injectiveʳ : ∀ {x y : A} {xs ys} → (Colist A ∋ x ∷ xs) ≡ y ∷ ys → xs ≡ ys
∷-injectiveʳ P.refl = P.refl
data Any {a p} {A : Set a} (P : A → Set p) :
Colist A → Set (a ⊔ p) where
here : ∀ {x xs} (px : P x) → Any P (x ∷ xs)
there : ∀ {x xs} (pxs : Any P (♭ xs)) → Any P (x ∷ xs)
module _ {a p} {A : Set a} {P : A → Set p} where
here-injective : ∀ {x xs p q} → (Any P (x ∷ xs) ∋ here p) ≡ here q → p ≡ q
here-injective P.refl = P.refl
there-injective : ∀ {x xs p q} → (Any P (x ∷ xs) ∋ there p) ≡ there q → p ≡ q
there-injective P.refl = P.refl
data All {a p} {A : Set a} (P : A → Set p) :
Colist A → Set (a ⊔ p) where
[] : All P []
_∷_ : ∀ {x xs} (px : P x) (pxs : ∞ (All P (♭ xs))) → All P (x ∷ xs)
module All-injective {a p} {A : Set a} {P : A → Set p} where
∷-injectiveˡ : ∀ {x xs} {px qx pxs qxs} →
(All P (x ∷ xs) ∋ px ∷ pxs) ≡ qx ∷ qxs → px ≡ qx
∷-injectiveˡ P.refl = P.refl
∷-injectiveʳ : ∀ {x xs} {px qx pxs qxs} →
(All P (x ∷ xs) ∋ px ∷ pxs) ≡ qx ∷ qxs → pxs ≡ qxs
∷-injectiveʳ P.refl = P.refl
------------------------------------------------------------------------
-- Some operations
null : ∀ {a} {A : Set a} → Colist A → Bool
null [] = true
null (_ ∷ _) = false
length : ∀ {a} {A : Set a} → Colist A → Coℕ
length [] = zero
length (x ∷ xs) = suc (♯ length (♭ xs))
map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → Colist A → Colist B
map f [] = []
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
fromList : ∀ {a} {A : Set a} → List A → Colist A
fromList [] = []
fromList (x ∷ xs) = x ∷ ♯ fromList xs
take : ∀ {a} {A : Set a} (n : ℕ) → Colist A → Vec≤ A n
take zero xs = Vec≤.[]
take (suc n) [] = Vec≤.[]
take (suc n) (x ∷ xs) = x Vec≤.∷ take n (♭ xs)
replicate : ∀ {a} {A : Set a} → Coℕ → A → Colist A
replicate zero x = []
replicate (suc n) x = x ∷ ♯ replicate (♭ n) x
lookup : ∀ {a} {A : Set a} → ℕ → Colist A → Maybe A
lookup n [] = nothing
lookup zero (x ∷ xs) = just x
lookup (suc n) (x ∷ xs) = lookup n (♭ xs)
infixr 5 _++_
_++_ : ∀ {a} {A : Set a} → Colist A → Colist A → Colist A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ ♯ (♭ xs ++ ys)
-- Interleaves the two colists (until the shorter one, if any, has
-- been exhausted).
infixr 5 _⋎_
_⋎_ : ∀ {a} {A : Set a} → Colist A → Colist A → Colist A
[] ⋎ ys = ys
(x ∷ xs) ⋎ ys = x ∷ ♯ (ys ⋎ ♭ xs)
concat : ∀ {a} {A : Set a} → Colist (List⁺ A) → Colist A
concat [] = []
concat ((x ∷ []) ∷ xss) = x ∷ ♯ concat (♭ xss)
concat ((x ∷ (y ∷ xs)) ∷ xss) = x ∷ ♯ concat ((y ∷ xs) ∷ xss)
[_] : ∀ {a} {A : Set a} → A → Colist A
[ x ] = x ∷ ♯ []
------------------------------------------------------------------------
-- Any lemmas
-- Any lemma for map.
Any-map : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
{f : A → B} {xs} →
Any P (map f xs) ↔ Any (P ∘ f) xs
Any-map {P = P} {f} {xs} = inverse to from from∘to to∘from
where
to : ∀ {xs} → Any P (map f xs) → Any (P ∘ f) xs
to {x ∷ xs} (here px) = here px
to {x ∷ xs} (there p) = there (to p)
from : ∀ {xs} → Any (P ∘ f) xs → Any P (map f xs)
from (here px) = here px
from (there p) = there (from p)
from∘to : ∀ {xs} (p : Any P (map f xs)) → from (to p) ≡ p
from∘to {x ∷ xs} (here px) = P.refl
from∘to {x ∷ xs} (there p) = P.cong there (from∘to p)
to∘from : ∀ {xs} (p : Any (P ∘ f) xs) → to (from p) ≡ p
to∘from (here px) = P.refl
to∘from (there p) = P.cong there (to∘from p)
-- Any lemma for _⋎_. This lemma implies that every member of xs or ys
-- is a member of xs ⋎ ys, and vice versa.
Any-⋎ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} →
Any P (xs ⋎ ys) ↔ (Any P xs ⊎ Any P ys)
Any-⋎ {P = P} = λ xs → record
{ to = P.→-to-⟶ (to xs)
; from = P.→-to-⟶ (from xs)
; inverse-of = record
{ left-inverse-of = from∘to xs
; right-inverse-of = to∘from xs
}
}
where
to : ∀ xs {ys} → Any P (xs ⋎ ys) → Any P xs ⊎ Any P ys
to [] p = inj₂ p
to (x ∷ xs) (here px) = inj₁ (here px)
to (x ∷ xs) (there p) = [ inj₂ , inj₁ ∘ there ]′ (to _ p)
mutual
from-left : ∀ {xs ys} → Any P xs → Any P (xs ⋎ ys)
from-left (here px) = here px
from-left {ys = ys} (there p) = there (from-right ys p)
from-right : ∀ xs {ys} → Any P ys → Any P (xs ⋎ ys)
from-right [] p = p
from-right (x ∷ xs) p = there (from-left p)
from : ∀ xs {ys} → Any P xs ⊎ Any P ys → Any P (xs ⋎ ys)
from xs = Sum.[ from-left , from-right xs ]
from∘to : ∀ xs {ys} (p : Any P (xs ⋎ ys)) → from xs (to xs p) ≡ p
from∘to [] p = P.refl
from∘to (x ∷ xs) (here px) = P.refl
from∘to (x ∷ xs) {ys = ys} (there p) with to ys p | from∘to ys p
from∘to (x ∷ xs) {ys = ys} (there .(from-left q)) | inj₁ q | P.refl = P.refl
from∘to (x ∷ xs) {ys = ys} (there .(from-right ys q)) | inj₂ q | P.refl = P.refl
mutual
to∘from-left : ∀ {xs ys} (p : Any P xs) →
to xs {ys = ys} (from-left p) ≡ inj₁ p
to∘from-left (here px) = P.refl
to∘from-left {ys = ys} (there p)
rewrite to∘from-right ys p = P.refl
to∘from-right : ∀ xs {ys} (p : Any P ys) →
to xs (from-right xs p) ≡ inj₂ p
to∘from-right [] p = P.refl
to∘from-right (x ∷ xs) {ys = ys} p
rewrite to∘from-left {xs = ys} {ys = ♭ xs} p = P.refl
to∘from : ∀ xs {ys} (p : Any P xs ⊎ Any P ys) → to xs (from xs p) ≡ p
to∘from xs = Sum.[ to∘from-left , to∘from-right xs ]
------------------------------------------------------------------------
-- Equality
-- xs ≈ ys means that xs and ys are equal.
infix 4 _≈_
data _≈_ {a} {A : Set a} : (xs ys : Colist A) → Set a where
[] : [] ≈ []
_∷_ : ∀ x {xs ys} (xs≈ : ∞ (♭ xs ≈ ♭ ys)) → x ∷ xs ≈ x ∷ ys
-- The equality relation forms a setoid.
setoid : ∀ {ℓ} → Set ℓ → Setoid _ _
setoid A = record
{ Carrier = Colist A
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {[]} = []
refl {x ∷ xs} = x ∷ ♯ refl
sym : Symmetric _≈_
sym [] = []
sym (x ∷ xs≈) = x ∷ ♯ sym (♭ xs≈)
trans : Transitive _≈_
trans [] [] = []
trans (x ∷ xs≈) (.x ∷ ys≈) = x ∷ ♯ trans (♭ xs≈) (♭ ys≈)
module ≈-Reasoning where
import Relation.Binary.Reasoning.Setoid as EqR
private
open module R {a} {A : Set a} = EqR (setoid A) public
-- map preserves equality.
map-cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) → _≈_ =[ map f ]⇒ _≈_
map-cong f [] = []
map-cong f (x ∷ xs≈) = f x ∷ ♯ map-cong f (♭ xs≈)
-- Any respects pointwise implication (for the predicate) and equality
-- (for the colist).
Any-resp : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{xs ys} → (∀ {x} → P x → Q x) → xs ≈ ys →
Any P xs → Any Q ys
Any-resp f (x ∷ xs≈) (here px) = here (f px)
Any-resp f (x ∷ xs≈) (there p) = there (Any-resp f (♭ xs≈) p)
-- Any maps pointwise isomorphic predicates and equal colists to
-- isomorphic types.
Any-cong : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{xs ys} → P ↔̇ Q → xs ≈ ys → Any P xs ↔ Any Q ys
Any-cong {A = A} {P} {Q} {xs} {ys} P↔Q = λ xs≈ys → record
{ to = P.→-to-⟶ (to xs≈ys)
; from = P.→-to-⟶ (from xs≈ys)
; inverse-of = record
{ left-inverse-of = from∘to _
; right-inverse-of = to∘from _
}
}
where
open Setoid (setoid _) using (sym)
to : ∀ {xs ys} → xs ≈ ys → Any P xs → Any Q ys
to xs≈ys = Any-resp (Inverse.to P↔Q ⟨$⟩_) xs≈ys
from : ∀ {xs ys} → xs ≈ ys → Any Q ys → Any P xs
from xs≈ys = Any-resp (Inverse.from P↔Q ⟨$⟩_) (sym xs≈ys)
to∘from : ∀ {xs ys} (xs≈ys : xs ≈ ys) (q : Any Q ys) →
to xs≈ys (from xs≈ys q) ≡ q
to∘from (x ∷ xs≈) (there q) = P.cong there (to∘from (♭ xs≈) q)
to∘from (x ∷ xs≈) (here qx) =
P.cong here (Inverse.right-inverse-of P↔Q qx)
from∘to : ∀ {xs ys} (xs≈ys : xs ≈ ys) (p : Any P xs) →
from xs≈ys (to xs≈ys p) ≡ p
from∘to (x ∷ xs≈) (there p) = P.cong there (from∘to (♭ xs≈) p)
from∘to (x ∷ xs≈) (here px) =
P.cong here (Inverse.left-inverse-of P↔Q px)
------------------------------------------------------------------------
-- Indices
-- Converts Any proofs to indices into the colist. The index can also
-- be seen as the size of the proof.
index : ∀ {a p} {A : Set a} {P : A → Set p} {xs} → Any P xs → ℕ
index (here px) = zero
index (there p) = suc (index p)
-- The position returned by index is guaranteed to be within bounds.
lookup-index : ∀ {a p} {A : Set a} {P : A → Set p} {xs} (p : Any P xs) →
Is-just (lookup (index p) xs)
lookup-index (here px) = just _
lookup-index (there p) = lookup-index p
-- Any-resp preserves the index.
index-Any-resp :
∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{f : ∀ {x} → P x → Q x} {xs ys}
(xs≈ys : xs ≈ ys) (p : Any P xs) →
index (Any-resp f xs≈ys p) ≡ index p
index-Any-resp (x ∷ xs≈) (here px) = P.refl
index-Any-resp (x ∷ xs≈) (there p) =
P.cong suc (index-Any-resp (♭ xs≈) p)
-- The left-to-right direction of Any-⋎ returns a proof whose size is
-- no larger than that of the input proof.
index-Any-⋎ :
∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P (xs ⋎ ys)) →
index p ≥′ [ index , index ]′ (Inverse.to (Any-⋎ xs) ⟨$⟩ p)
index-Any-⋎ [] p = ≤′-refl
index-Any-⋎ (x ∷ xs) (here px) = ≤′-refl
index-Any-⋎ (x ∷ xs) {ys = ys} (there p)
with Inverse.to (Any-⋎ ys) ⟨$⟩ p | index-Any-⋎ ys p
... | inj₁ q | q≤p = ≤′-step q≤p
... | inj₂ q | q≤p = s≤′s q≤p
------------------------------------------------------------------------
-- Memberships, subsets, prefixes
-- x ∈ xs means that x is a member of xs.
infix 4 _∈_
_∈_ : ∀ {a} → {A : Set a} → A → Colist A → Set a
x ∈ xs = Any (_≡_ x) xs
-- xs ⊆ ys means that xs is a subset of ys.
infix 4 _⊆_
_⊆_ : ∀ {a} → {A : Set a} → Colist A → Colist A → Set a
xs ⊆ ys = ∀ {x} → x ∈ xs → x ∈ ys
-- xs ⊑ ys means that xs is a prefix of ys.
infix 4 _⊑_
data _⊑_ {a} {A : Set a} : Colist A → Colist A → Set a where
[] : ∀ {ys} → [] ⊑ ys
_∷_ : ∀ x {xs ys} (p : ∞ (♭ xs ⊑ ♭ ys)) → x ∷ xs ⊑ x ∷ ys
-- Any can be expressed using _∈_ (and vice versa).
Any-∈ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} →
Any P xs ↔ ∃ λ x → x ∈ xs × P x
Any-∈ {P = P} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ (λ { (x , x∈xs , p) → from x∈xs p })
; inverse-of = record
{ left-inverse-of = from∘to
; right-inverse-of = λ { (x , x∈xs , p) → to∘from x∈xs p }
}
}
where
to : ∀ {xs} → Any P xs → ∃ λ x → x ∈ xs × P x
to (here p) = _ , here P.refl , p
to (there p) = Prod.map id (Prod.map there id) (to p)
from : ∀ {x xs} → x ∈ xs → P x → Any P xs
from (here P.refl) p = here p
from (there x∈xs) p = there (from x∈xs p)
to∘from : ∀ {x xs} (x∈xs : x ∈ xs) (p : P x) →
to (from x∈xs p) ≡ (x , x∈xs , p)
to∘from (here P.refl) p = P.refl
to∘from (there x∈xs) p =
P.cong (Prod.map id (Prod.map there id)) (to∘from x∈xs p)
from∘to : ∀ {xs} (p : Any P xs) →
let (x , x∈xs , px) = to p in from x∈xs px ≡ p
from∘to (here _) = P.refl
from∘to (there p) = P.cong there (from∘to p)
-- Prefixes are subsets.
⊑⇒⊆ : ∀ {a} → {A : Set a} → _⊑_ {A = A} ⇒ _⊆_
⊑⇒⊆ (x ∷ xs⊑ys) (here ≡x) = here ≡x
⊑⇒⊆ (_ ∷ xs⊑ys) (there x∈xs) = there (⊑⇒⊆ (♭ xs⊑ys) x∈xs)
-- The prefix relation forms a poset.
⊑-Poset : ∀ {ℓ} → Set ℓ → Poset _ _ _
⊑-Poset A = record
{ Carrier = Colist A
; _≈_ = _≈_
; _≤_ = _⊑_
; isPartialOrder = record
{ isPreorder = record
{ isEquivalence = Setoid.isEquivalence (setoid A)
; reflexive = reflexive
; trans = trans
}
; antisym = antisym
}
}
where
reflexive : _≈_ ⇒ _⊑_
reflexive [] = []
reflexive (x ∷ xs≈) = x ∷ ♯ reflexive (♭ xs≈)
trans : Transitive _⊑_
trans [] _ = []
trans (x ∷ xs≈) (.x ∷ ys≈) = x ∷ ♯ trans (♭ xs≈) (♭ ys≈)
tail : ∀ {x xs y ys} → x ∷ xs ⊑ y ∷ ys → ♭ xs ⊑ ♭ ys
tail (_ ∷ p) = ♭ p
antisym : Antisymmetric _≈_ _⊑_
antisym [] [] = []
antisym (x ∷ p₁) p₂ = x ∷ ♯ antisym (♭ p₁) (tail p₂)
module ⊑-Reasoning {a} {A : Set a} where
private module Base = POR (⊑-Poset A)
open Base public
hiding (step-<; begin-strict_; step-≤)
infixr 2 step-⊑
step-⊑ = Base.step-≤
syntax step-⊑ x ys⊑zs xs⊑ys = x ⊑⟨ xs⊑ys ⟩ ys⊑zs
-- The subset relation forms a preorder.
⊆-Preorder : ∀ {ℓ} → Set ℓ → Preorder _ _ _
⊆-Preorder A = Ind.preorder (setoid A) _∈_
(λ xs≈ys → ⊑⇒⊆ (⊑P.reflexive xs≈ys))
where module ⊑P = Poset (⊑-Poset A)
module ⊆-Reasoning {a} {A : Set a} where
private module Base = PreR (⊆-Preorder A)
open Base public
hiding (step-∼)
infixr 2 step-⊆
infix 1 step-∈
step-⊆ = Base.step-∼
step-∈ : ∀ (x : A) {xs ys} → xs IsRelatedTo ys → x ∈ xs → x ∈ ys
step-∈ x xs⊆ys x∈xs = (begin xs⊆ys) x∈xs
syntax step-⊆ xs ys⊆zs xs⊆ys = xs ⊆⟨ xs⊆ys ⟩ ys⊆zs
syntax step-∈ x xs⊆ys x∈xs = x ∈⟨ x∈xs ⟩ xs⊆ys
-- take returns a prefix.
take-⊑ : ∀ {a} {A : Set a} n (xs : Colist A) →
let toColist = fromList {a} ∘ Vec≤.toList in
toColist (take n xs) ⊑ xs
take-⊑ zero xs = []
take-⊑ (suc n) [] = []
take-⊑ (suc n) (x ∷ xs) = x ∷ ♯ take-⊑ n (♭ xs)
------------------------------------------------------------------------
-- Finiteness and infiniteness
-- Finite xs means that xs has finite length.
data Finite {a} {A : Set a} : Colist A → Set a where
[] : Finite []
_∷_ : ∀ x {xs} (fin : Finite (♭ xs)) → Finite (x ∷ xs)
module Finite-injective {a} {A : Set a} where
∷-injective : ∀ {x : A} {xs p q} → (Finite (x ∷ xs) ∋ x ∷ p) ≡ x ∷ q → p ≡ q
∷-injective P.refl = P.refl
-- Infinite xs means that xs has infinite length.
data Infinite {a} {A : Set a} : Colist A → Set a where
_∷_ : ∀ x {xs} (inf : ∞ (Infinite (♭ xs))) → Infinite (x ∷ xs)
module Infinite-injective {a} {A : Set a} where
∷-injective : ∀ {x : A} {xs p q} → (Infinite (x ∷ xs) ∋ x ∷ p) ≡ x ∷ q → p ≡ q
∷-injective P.refl = P.refl
-- Colists which are not finite are infinite.
not-finite-is-infinite :
∀ {a} {A : Set a} (xs : Colist A) → ¬ Finite xs → Infinite xs
not-finite-is-infinite [] hyp = contradiction [] hyp
not-finite-is-infinite (x ∷ xs) hyp =
x ∷ ♯ not-finite-is-infinite (♭ xs) (hyp ∘ _∷_ x)
-- Colists are either finite or infinite (classically).
finite-or-infinite :
∀ {a} {A : Set a} (xs : Colist A) → ¬ ¬ (Finite xs ⊎ Infinite xs)
finite-or-infinite xs = helper <$> excluded-middle
where
helper : Dec (Finite xs) → Finite xs ⊎ Infinite xs
helper ( true because [fin]) = inj₁ (invert [fin])
helper (false because [¬fin]) =
inj₂ $ not-finite-is-infinite xs (invert [¬fin])
-- Colists are not both finite and infinite.
not-finite-and-infinite :
∀ {a} {A : Set a} {xs : Colist A} → Finite xs → Infinite xs → ⊥
not-finite-and-infinite (x ∷ fin) (.x ∷ inf) =
not-finite-and-infinite fin (♭ inf)
------------------------------------------------------------------------
-- Legacy
import Codata.Colist as C
open import Codata.Thunk
import Size
module _ {a} {A : Set a} where
fromMusical : ∀ {i} → Colist A → C.Colist A i
fromMusical [] = C.[]
fromMusical (x ∷ xs) = x C.∷ λ where .force → fromMusical (♭ xs)
toMusical : C.Colist A Size.∞ → Colist A
toMusical C.[] = []
toMusical (x C.∷ xs) = x ∷ ♯ toMusical (xs .force)
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.3
open import Data.BoundedVec.Inefficient as BVec
using (BoundedVec; []; _∷_)
take′ : ∀ {a} {A : Set a} (n : ℕ) → Colist A → BoundedVec A n
take′ zero xs = []
take′ (suc n) [] = []
take′ (suc n) (x ∷ xs) = x ∷ take′ n (♭ xs)
{-# WARNING_ON_USAGE take′
"Warning: take′ (and Data.BoundedVec) was deprecated in v1.3.
Please use take (and Data.Vec.Bounded) instead."
#-}
take′-⊑ : ∀ {a} {A : Set a} n (xs : Colist A) →
let toColist = fromList {a} ∘ BVec.toList in
toColist (take′ n xs) ⊑ xs
take′-⊑ zero xs = []
take′-⊑ (suc n) [] = []
take′-⊑ (suc n) (x ∷ xs) = x ∷ ♯ take′-⊑ n (♭ xs)
{-# WARNING_ON_USAGE take′-⊑
"Warning: take′-⊑ (and Data.BoundedVec) was deprecated in v1.3.
Please use take-⊑ (and Data.Vec.Bounded) instead."
#-}
| 31.739635
| 83
| 0.506192
|
dc59f927a824f6ace91198525199a1459ab1b264
| 458
|
agda
|
Agda
|
test/Succeed/Issue333.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue333.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue333.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --universe-polymorphism #-}
module Issue333 where
open import Common.Level
data Σ a b (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
_,_ : (x : A) → B x → Σ a b A B
P : ∀ a b (A : Set a) (B : Set b) → Set (a ⊔ b)
P a b A B = Σ a b A (λ _ → B)
postulate
A B : Set
foo : Σ lzero lzero A λ (y : A) → P lzero lzero A B
bar : Set₁
bar = helper foo
where
helper : (Σ _ _ A λ (y : A) → P _ _ _ _) → Set₁
helper (y , (x⇓ , fy⇑)) = Set
| 20.818182
| 58
| 0.524017
|
1c46b5174cd33b800fe2484ecffa04fc19065a62
| 131
|
agda
|
Agda
|
test/succeed/Issue49.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/Issue49.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Issue49.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module Issue49 where
module Dummy {A : Set1} where
postulate D : Set
T : Set
T = Dummy.D {Set}
T' : Set
T' = Dummy.D {A = Set}
| 13.1
| 29
| 0.618321
|
586af86547cc5fa4a0337c1dedd4518949e8a40a
| 4,172
|
agda
|
Agda
|
out/TLC/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/TLC/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/TLC/Equality.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order equational theory was created from the following second-order syntax description:
syntax TLC | Λ
type
N : 0-ary
_↣_ : 2-ary | r30
𝟙 : 0-ary
_⊗_ : 2-ary | l40
𝟘 : 0-ary
_⊕_ : 2-ary | l30
term
app : α ↣ β α -> β | _$_ l20
lam : α.β -> α ↣ β | ƛ_ r10
unit : 𝟙
pair : α β -> α ⊗ β | ⟨_,_⟩
fst : α ⊗ β -> α
snd : α ⊗ β -> β
abort : 𝟘 -> α
inl : α -> α ⊕ β
inr : β -> α ⊕ β
case : α ⊕ β α.γ β.γ -> γ
ze : N
su : N -> N
nrec : N α (α,N).α -> α
theory
(ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]
(ƛη) f : α ↣ β |> lam (x. app(f, x)) = f
(𝟙η) u : 𝟙 |> u = unit
(fβ) a : α b : β |> fst (pair(a, b)) = a
(sβ) a : α b : β |> snd (pair(a, b)) = b
(pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p
(𝟘η) e : 𝟘 c : α |> abort(e) = c
(lβ) a : α f : α.γ g : β.γ |> case (inl(a), x.f[x], y.g[y]) = f[a]
(rβ) b : β f : α.γ g : β.γ |> case (inr(b), x.f[x], y.g[y]) = g[b]
(cη) s : α ⊕ β c : (α ⊕ β).γ |> case (s, x.c[inl(x)], y.c[inr(y)]) = c[s]
(zeβ) z : α s : (α,N).α |> nrec (ze, z, r m. s[r,m]) = z
(suβ) z : α s : (α,N).α n : N |> nrec (su (n), z, r m. s[r,m]) = s[nrec (n, z, r m. s[r,m]), n]
(ift) t f : α |> if (true, t, f) = t
(iff) t f : α |> if (false, t, f) = f
-}
module TLC.Equality where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Families.Build
open import SOAS.ContextMaps.Inductive
open import TLC.Signature
open import TLC.Syntax
open import SOAS.Metatheory.SecondOrder.Metasubstitution Λ:Syn
open import SOAS.Metatheory.SecondOrder.Equality Λ:Syn
private
variable
α β γ τ : ΛT
Γ Δ Π : Ctx
infix 1 _▹_⊢_≋ₐ_
-- Axioms of equality
data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ Λ) α Γ → (𝔐 ▷ Λ) α Γ → Set where
ƛβ : ⁅ α ⊩ β ⁆ ⁅ α ⁆̣ ▹ ∅ ⊢ (ƛ 𝔞⟨ x₀ ⟩) $ 𝔟 ≋ₐ 𝔞⟨ 𝔟 ⟩
ƛη : ⁅ α ↣ β ⁆̣ ▹ ∅ ⊢ ƛ (𝔞 $ x₀) ≋ₐ 𝔞
𝟙η : ⁅ 𝟙 ⁆̣ ▹ ∅ ⊢ 𝔞 ≋ₐ unit
fβ : ⁅ α ⁆ ⁅ β ⁆̣ ▹ ∅ ⊢ fst (⟨ 𝔞 , 𝔟 ⟩) ≋ₐ 𝔞
sβ : ⁅ α ⁆ ⁅ β ⁆̣ ▹ ∅ ⊢ snd (⟨ 𝔞 , 𝔟 ⟩) ≋ₐ 𝔟
pη : ⁅ α ⊗ β ⁆̣ ▹ ∅ ⊢ ⟨ (fst 𝔞) , (snd 𝔞) ⟩ ≋ₐ 𝔞
𝟘η : ⁅ 𝟘 ⁆ ⁅ α ⁆̣ ▹ ∅ ⊢ abort 𝔞 ≋ₐ 𝔟
lβ : ⁅ α ⁆ ⁅ α ⊩ γ ⁆ ⁅ β ⊩ γ ⁆̣ ▹ ∅ ⊢ case (inl 𝔞) (𝔟⟨ x₀ ⟩) (𝔠⟨ x₀ ⟩) ≋ₐ 𝔟⟨ 𝔞 ⟩
rβ : ⁅ β ⁆ ⁅ α ⊩ γ ⁆ ⁅ β ⊩ γ ⁆̣ ▹ ∅ ⊢ case (inr 𝔞) (𝔟⟨ x₀ ⟩) (𝔠⟨ x₀ ⟩) ≋ₐ 𝔠⟨ 𝔞 ⟩
cη : ⁅ α ⊕ β ⁆ ⁅ (α ⊕ β) ⊩ γ ⁆̣ ▹ ∅ ⊢ case 𝔞 (𝔟⟨ inl x₀ ⟩) (𝔟⟨ inr x₀ ⟩) ≋ₐ 𝔟⟨ 𝔞 ⟩
zeβ : ⁅ α ⁆ ⁅ α · N ⊩ α ⁆̣ ▹ ∅ ⊢ nrec ze 𝔞 (𝔟⟨ x₀ ◂ x₁ ⟩) ≋ₐ 𝔞
suβ : ⁅ α ⁆ ⁅ α · N ⊩ α ⁆ ⁅ N ⁆̣ ▹ ∅ ⊢ nrec (su 𝔠) 𝔞 (𝔟⟨ x₀ ◂ x₁ ⟩) ≋ₐ 𝔟⟨ (nrec 𝔠 𝔞 (𝔟⟨ x₀ ◂ x₁ ⟩)) ◂ 𝔠 ⟩
open EqLogic _▹_⊢_≋ₐ_
open ≋-Reasoning
-- Derived equations
ift : ⁅ α ⁆ ⁅ α ⁆̣ ▹ ∅ ⊢ if true 𝔞 𝔟 ≋ 𝔞
ift = ax lβ with《 unit ◃ 𝔞 ◃ 𝔟 》
iff : ⁅ α ⁆ ⁅ α ⁆̣ ▹ ∅ ⊢ if false 𝔞 𝔟 ≋ 𝔟
iff = ax rβ with《 unit ◃ 𝔞 ◃ 𝔟 》
-- Double beta reduction
ƛβ² : ⁅ β · α ⊩ γ ⁆ ⁅ α ⁆ ⁅ β ⁆̣ ▹ ∅ ⊢ (ƛ (ƛ 𝔞⟨ x₀ ◂ x₁ ⟩)) $ 𝔟 $ 𝔠 ≋ 𝔞⟨ 𝔠 ◂ 𝔟 ⟩
ƛβ² = begin
(ƛ (ƛ 𝔞⟨ x₀ ◂ x₁ ⟩)) $ 𝔟 $ 𝔠
≋⟨ cong[ ax ƛβ with《 (ƛ 𝔞⟨ x₀ ◂ x₁ ⟩) ◃ 𝔟 》 ]inside ◌ᵈ $ 𝔠 ⟩
(ƛ 𝔞⟨ x₀ ◂ 𝔟 ⟩) $ 𝔠
≋⟨ ax ƛβ with《 (𝔞⟨ x₀ ◂ 𝔟 ⟩) ◃ 𝔠 》 ⟩
𝔞⟨ 𝔠 ◂ 𝔟 ⟩
∎
-- Uncurrying and arithmetic
1+2 : ⁅⁆ ▹ ∅ ⊢ uncurry $ plus $ ⟨ su ze , su (su ze) ⟩ ≋ su (su (su ze))
1+2 = begin
uncurry $ plus $ ⟨ su ze , su (su ze) ⟩
≋⟨ thm ƛβ² with《 x₁ $ fst x₀ $ snd x₀ ◃ plus ◃ ⟨ su ze , su (su ze) ⟩ 》 ⟩
plus $ fst ⟨ su ze , su (su ze) ⟩ $ snd ⟨ su ze , su (su ze) ⟩
≋⟨ cong₂[ ax fβ with《 su ze ◃ su (su ze) 》 ][
ax sβ with《 su ze ◃ su (su ze) 》 ]inside plus $ ◌ᵃ $ ◌ᵇ ⟩
plus $ su ze $ su (su ze)
≋⟨ thm ƛβ² with《 nrec x₁ x₀ (su x₀) ◃ su ze ◃ su (su ze) 》 ⟩
nrec (su ze) (su (su ze)) (su x₀)
≋⟨ ax suβ with《 su (su ze) ◃ su x₀ ◃ ze 》 ⟩
su (nrec ze (su (su ze)) (su x₀))
≋⟨ cong[ ax zeβ with《 su (su ze) ◃ su x₀ 》 ]inside su ◌ᵃ ⟩
su (su (su ze))
∎
| 35.355932
| 113
| 0.405081
|
1d918aa871183874672880ce3d185400216d82f9
| 2,490
|
agda
|
Agda
|
examples/outdated-and-incorrect/AIM6/Cat/Slice.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/AIM6/Cat/Slice.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/AIM6/Cat/Slice.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Slice where
open import Logic.Relations
open import Logic.Equivalence
open import Logic.Base
open import Category
module SliceCat (ℂ : Cat)(Γ : Category.Obj ℂ) where
open module CC = Category.Category ℂ
record SlObj : Set1 where
field
dom : Obj
arr : dom ─→ Γ
record _Sl→_ (f f' : SlObj) : Set where
field
h : (SlObj.dom f) ─→ (SlObj.dom f')
π : (SlObj.arr f') ∘ h == (SlObj.arr f)
SlId : {f : SlObj} -> f Sl→ f
SlId = record
{ h = id
; π = idRight
}
_o_ : {f f' f'' : SlObj} -> f' Sl→ f'' -> f Sl→ f' -> f Sl→ f''
_o_ {F} {F'} {F''} F₁ F₂ =
let f = SlObj.arr F in
let f' = SlObj.arr F' in
let f'' = SlObj.arr F'' in
let h' = _Sl→_.h F₁ in
let h = _Sl→_.h F₂ in
record
{ h = (_Sl→_.h F₁) ∘ (_Sl→_.h F₂)
-- Proof of f'' ∘ (h' ∘ h) == f
; π = trans (trans (sym assoc)
(congL (_Sl→_.π F₁)))
(_Sl→_.π F₂)
}
SlRel : {A B : SlObj} -> Rel (A Sl→ B)
SlRel f f' = (_Sl→_.h f) == (_Sl→_.h f')
SlRefl : {A B : SlObj} -> Reflexive {A Sl→ B} SlRel
SlRefl = refl
SlSym : {A B : SlObj} -> Symmetric {A Sl→ B} SlRel
SlSym = sym
SlTrans : {A B : SlObj} -> Transitive {A Sl→ B} SlRel
SlTrans = trans
SlEq : {A B : SlObj} -> Equivalence (A Sl→ B)
SlEq {A} {B} = record
{ _==_ = SlRel {A} {B}
; refl = \{f : A Sl→ B} -> SlRefl {A}{B}{f}
; sym = \{f g : A Sl→ B} -> SlSym {A}{B}{f}{g}
; trans = \{f g h : A Sl→ B} -> SlTrans {A}{B}{f}{g}{h}
}
SlCong : {A B C : SlObj}{f f' : B Sl→ C}{g g' : A Sl→ B} ->
SlRel f f' -> SlRel g g' -> SlRel (f o g) (f' o g')
SlCong = cong
SlIdLeft : {A B : SlObj}{f : A Sl→ B} -> SlRel (SlId o f) f
SlIdLeft = idLeft
SlIdRight : {A B : SlObj}{f : A Sl→ B} -> SlRel (f o SlId) f
SlIdRight = idRight
SlAssoc : {A B C D : SlObj}{f : C Sl→ D}{g : B Sl→ C}{h : A Sl→ B} ->
SlRel ((f o g) o h) (f o (g o h))
SlAssoc = assoc
Slice : Cat
Slice = record
{ Obj = SlObj
; _─→_ = _Sl→_
; id = SlId
; _∘_ = _o_
; Eq = SlEq
; cong = \{A B C : SlObj}{f f' : B Sl→ C}{g g' : A Sl→ B} -> SlCong {A}{B}{C}{f}{f'}{g}{g'}
; idLeft = \{A B : SlObj}{f : A Sl→ B} -> SlIdLeft {A} {B} {f}
; idRight = \{A B : SlObj}{f : A Sl→ B} -> SlIdRight {A} {B} {f}
; assoc = \{A B C D : SlObj}{f : C Sl→ D}{g : B Sl→ C}{h : A Sl→ B} ->
SlAssoc {A}{B}{C}{D}{f}{g}{h}
}
| 27.065217
| 98
| 0.464659
|
06fc3ca2a0350411e0557e05155be397b87ed33c
| 6,958
|
agda
|
Agda
|
examples/outdated-and-incorrect/Termination/Example.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/Termination/Example.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/Termination/Example.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Example where
loop : Set
loop = loop
_∞_ : Set -> Set -> Set
x ∞ y = x ∞ y
data Nat : Set where
zero : Nat
succ : Nat -> Nat
id : Nat -> Nat
id zero = zero
id (succ n) = succ (id n)
bad : Nat -> Nat
bad n = bad n
_+_ : Nat -> Nat -> Nat
zero + n = n
(succ m) + n = succ (m + n)
bad2 : Nat -> Nat
bad2 (succ x) = bad2 x + bad2 (succ x)
bad2 x = bad2 x
data Bool : Set where
true : Bool
false : Bool
_&&_ : Bool -> Bool -> Bool
true && a = a
false && a = false
mutual
even : Nat -> Bool
even zero = true
even (succ n) = odd n
odd : Nat -> Bool
odd zero = false
odd (succ n) = even n
data Ty : {_ : Nat} -> Set where
Base : forall {n} -> Ty {succ n}
Arr : forall {n} -> Ty {n} -> Ty {n} -> Ty {succ n}
eqty : forall {n} -> Ty {n} -> Ty {n} -> Bool
eqty Base Base = true
eqty (Arr a b) (Arr a' b') = (eqty a a') && (eqty b b')
eqty _ _ = false
subty : forall {n} -> Ty {n} -> Ty {n} -> Bool
subty Base Base = true
subty (Arr a b) (Arr a' b') = (subty a' a) && (subty b b')
subty _ _ = false
-- the following is enough for making it termination check
subty' : forall {n} -> Ty {n} -> Ty {n} -> Bool
subty' Base Base = true
subty' {succ n} (Arr a b) (Arr a' b')
= (subty' a' a) && (subty' b b')
subty' _ _ = false
subty'' : forall {n} -> Ty {n} -> Ty {n} -> Bool
subty'' Base Base = true
subty'' {succ n} (Arr {.n} a b) (Arr .{n} a'' b'')
= (subty'' {n} a'' a) && (subty'' {n} b b'')
subty'' _ _ = false
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
add : Nat × Nat -> Nat
add (zero , m) = m
add (succ n , m) = succ (add (n , m))
eq : Nat × Nat -> Bool
eq (zero , zero ) = true
eq (succ n , succ m) = eq (n , m)
eq _ = false
-- the following should not termination check
mutual
f : Nat -> Nat -> Nat
f zero y = zero
f (succ x) zero = zero
f (succ x) (succ y) = (g x (succ y)) + (f (succ (succ x)) y)
g : Nat -> Nat -> Nat
g zero y = zero
g (succ x) zero = zero
g (succ x) (succ y) = (f (succ x) (succ y)) + (g x (succ (succ y)))
mutual
badf : Nat × Nat -> Nat
badf (zero , y) = zero
badf (succ x , zero) = zero
badf (succ x , succ y) = badg (x , succ y) + badf (succ (succ x) , y)
badg : Nat × Nat -> Nat
badg (zero , y) = zero
badg (succ x , zero) = zero
badg (succ x , succ y) = badf (succ x , succ y) + badg (x , succ (succ y))
-- these are ok, however
mutual
f' : Nat -> Nat -> Nat
f' zero y = zero
f' (succ x) zero = zero
f' (succ x) (succ y) = (g' x (succ y)) + (f' (succ (succ x)) y)
g' : Nat -> Nat -> Nat
g' zero y = zero
g' (succ x) zero = zero
g' (succ x) (succ y) = (f' (succ x) (succ y)) + (g' x (succ y))
-- these are ok, however
bla : Nat
bla = succ (succ zero)
mutual
f'' : Nat -> Nat -> Nat
f'' zero y = zero
f'' (succ x) zero = zero
f'' (succ x) (succ y) = (g'' x (succ y)) + (f'' bla y)
g'' : Nat -> Nat -> Nat
g'' zero y = zero
g'' (succ x) zero = zero
g'' (succ x) (succ y) = (f'' (succ x) (succ y)) + (g'' x (succ y))
-- Ackermann
ack : Nat -> Nat -> Nat
ack zero y = succ y
ack (succ x) zero = ack x (succ zero)
ack (succ x) (succ y) = ack x (ack (succ x) y)
ack' : Nat × Nat -> Nat
ack' (zero , y) = succ y
ack' (succ x , zero) = ack' (x , succ zero)
ack' (succ x , succ y) = ack' (x , ack' (succ x , y))
-- Maximum of 3 numbers
max3 : Nat -> Nat -> Nat -> Nat
max3 zero zero z = z
max3 zero y zero = y
max3 x zero zero = x
max3 (succ x) (succ y) zero = succ (max3 x y zero)
max3 (succ x) zero (succ z) = succ (max3 x zero z)
max3 zero (succ y) (succ z) = succ (max3 zero y z)
max3 (succ x) (succ y) (succ z) = succ (max3 x y z)
-- addition of Ordinals
data Ord : Set where
ozero : Ord
olim : (Nat -> Ord) -> Ord
addord : Ord -> Ord -> Ord
addord x ozero = x
addord x (olim f) = olim (\ n -> addord x (f n))
-- Higher-order example which should not pass the termination checker.
-- (Not the current one, anyway.)
foo : Ord -> (Nat -> Ord) -> Ord
foo ozero g = ozero
foo (olim f) g = olim (\n -> foo (g n) f)
-- Examples checking that a function can be used with several
-- different numbers of arguments on the right-hand side.
const : {a b : Set1} -> a -> b -> a
const x _ = x
ok : Nat -> Nat -> Set
ok zero y = Nat
ok (succ x) y = const Nat (const (ok x y) (ok x))
notOK : Set -> Set
notOK x = const (notOK Ord) notOK
-- An example which should fail (37 is an arbitrary number):
data ⊤ : Set where
tt : ⊤
mutual
foo37 : ⊤ -> ⊤
foo37 x = bar37 x
bar37 : ⊤ -> ⊤
bar37 tt = foo37 tt
-- Some examples involving with.
-- Not OK:
withNo : Nat -> Nat
withNo n with n
withNo n | m = withNo m
-- OK:
withYes : Nat -> Nat
withYes n with n
withYes n | zero = zero
withYes n | succ m = withYes m
-- Some rather convoluted examples.
-- OK:
number : Nat
number = zero
where
data Foo12 : Nat -> Set where
foo12 : Foo12 number
-- Should the occurrence of number' in the type signature of foo12
-- really be highlighted here?
number' : Nat
number' with zero
number' | x = g12 foo12
where
data Foo12 : Nat -> Set where
foo12 : Foo12 number'
abstract
g12 : {i : Nat} -> Foo12 i -> Nat
g12 foo12 = zero
-- Tests highlighting (but does not type check yet):
-- number'' : Nat
-- number'' with zero
-- number'' | x = g12 (foo12 x)
-- where
-- data Foo12 : Nat -> Set where
-- foo12 : (n : Nat) -> Foo12 (number'' | n)
-- abstract
-- g12 : {i : Nat} -> Foo12 i -> Nat
-- g12 (foo12 n) = n
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
infixr 50 _::_
-- butlast function
good1 : {A : Set} -> List A -> A
good1 (a :: []) = a
good1 (a :: b :: bs) = good1 (b :: bs)
infixl 10 _⊕_
postulate
_⊕_ : {A : Set} -> A -> A -> A -- non-deterministic choice
-- a funny formulation of insert
-- insert (a :: l) inserts a into l
insert : {A : Set} -> List A -> List A
insert [] = []
insert (a :: []) = a :: []
insert (a :: b :: bs) = a :: b :: bs ⊕ -- case a <= b
b :: insert (a :: bs) -- case a > b
-- list flattening
flat : {A : Set} -> List (List A) -> List A
flat [] = []
flat ([] :: ll) = flat ll
flat ((x :: l) :: ll) = x :: flat (l :: ll)
-- leaf-labelled trees
data Tree (A : Set) : Set where
leaf : A -> Tree A
node : Tree A -> Tree A -> Tree A
-- flattening (does not termination check)
tflat : {A : Set} -> Tree A -> List A
tflat (leaf a) = a :: []
tflat (node (leaf a) r) = a :: tflat r
tflat (node (node l1 l2) r) = tflat (node l1 (node l2 r))
-- Maximum of 3 numbers
-- mixing tupling and swapping: does not work with structured orders
max3' : Nat × Nat -> Nat -> Nat
max3' (zero , zero) z = z
max3' (zero , y) zero = y
max3' (x , zero) zero = x
max3' (succ x , succ y) zero = succ (max3' (x , y) zero)
max3' (succ x , zero) (succ z) = succ (max3' (x , z) zero)
max3' (zero , succ y) (succ z) = succ (max3' (y , z) zero)
max3' (succ x , succ y) (succ z) = succ (max3' (z , x) y)
| 21.676012
| 77
| 0.545559
|
1c2c9b38327b3d01409bf7985ebcf9324ad85509
| 1,071
|
agda
|
Agda
|
test/Succeed/Issue1551.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Succeed/Issue1551.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Issue1551.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- Andreas, 2015-06-11
{-# OPTIONS --copatterns #-}
open import Common.Size
module _ {C : Set} {R : C → Set} where
mutual
record IO (i : Size) (A : Set) : Set where
coinductive
constructor delay
field
force : {j : Size< i} → IO' j A
data IO' (i : Size) (A : Set) : Set where
act : (c : C) (f : R c → IO i A) → IO' i A
return : (a : A) → IO' i A
open IO
module Works where
_>>=_ : ∀{i A B} (m : IO i A) (k : A → IO i B) → IO i B
force (m >>= k) with force m
force (m >>= k) {j} | act c f = act c λ x → f x >>= k
force (m >>= k) {j} | return a = force (k a)
_>>=_ : ∀{i A B} (m : IO i A) (k : A → IO i B) → IO i B
force (m >>= k) with force m
force (m >>= k) | act c f = act c λ x → f x >>= k
force (m >>= k) | return a = force (k a)
-- Error WAS:
-- Too few arguments given in with-clause
-- when checking that the clause
-- force (m >>= k) with force m
-- force (m >>= k) | do c f = do c (λ x → f x >>= k)
-- force (m >>= k) | return a = force (k a)
-- has type {i : Size} {A B : Set} → IO i A → (A → IO i B) → IO i B
| 26.121951
| 67
| 0.500467
|
58593bb8c7bd3e16b24beea37c1141f1d01ce218
| 6,882
|
agda
|
Agda
|
Definition/Typed/Consequences/Inversion.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Definition/Typed/Consequences/Inversion.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Definition/Typed/Consequences/Inversion.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
{-# OPTIONS --safe #-}
module Definition.Typed.Consequences.Inversion where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Substitution
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Inversion of Universes
inversion-U : ∀ {Γ C rU lU r} → Γ ⊢ Univ rU lU ∷ C ^ r → Γ ⊢ C ≡ U ¹ ^ [ ! , next ¹ ] × r PE.≡ [ ! , next ¹ ] × lU PE.≡ ⁰
inversion-U (univ 0<1 x) = refl (Ugenⱼ x) , PE.refl , PE.refl
inversion-U (conv x x₁) with inversion-U x
... | [C≡U] , PE.refl , PE.refl = trans (sym x₁) [C≡U] , PE.refl , PE.refl
-- Inversion of natural number type.
inversion-ℕ : ∀ {Γ C r} → Γ ⊢ ℕ ∷ C ^ r → Γ ⊢ C ≡ U ⁰ ^ r × r PE.≡ [ ! , next ⁰ ]
inversion-ℕ (ℕⱼ x) = refl (Ugenⱼ x) , PE.refl
inversion-ℕ (conv x x₁) with inversion-ℕ x
... | [C≡U] , PE.refl = trans (sym x₁) [C≡U] , PE.refl
-- Inversion of Π-types.
inversion-Π : ∀ {F rF G r Γ C lF lG lΠ}
→ Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ∷ C ^ r
→ ∃ λ rG
→ lF ≤ lΠ
× lG ≤ lΠ
× Γ ⊢ F ∷ Univ rF lF ^ [ ! , next lF ]
× Γ ∙ F ^ [ rF , ι lF ] ⊢ G ∷ Univ rG lG ^ [ ! , next lG ]
× Γ ⊢ C ≡ Univ rG lΠ ^ [ ! , next lΠ ]
× r PE.≡ [ ! , next lΠ ]
inversion-Π (Πⱼ_▹_▹_▹_ {rF = rF} {r = rG} l< l<' x x₁) = rG , l< , l<' , x , x₁ , refl (Ugenⱼ (wfTerm x)) , PE.refl
inversion-Π (conv x x₁) = let rG , l< , l<' , a , b , c , r≡! = inversion-Π x
in rG , l< , l<' , a , b
, trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) r≡! x₁)) c
, r≡!
-- Inversion of ∃-types.
inversion-∃ : ∀ {F G Γ C r}
→ Γ ⊢ ∃ F ▹ G ∷ C ^ r
→ ∃ λ l∃
→ Γ ⊢ F ∷ Univ % l∃ ^ [ ! , next l∃ ]
× Γ ∙ F ^ [ % , ι l∃ ] ⊢ G ∷ Univ % l∃ ^ [ ! , next l∃ ]
× Γ ⊢ C ≡ Univ % l∃ ^ [ ! , next l∃ ]
× r PE.≡ [ ! , next l∃ ]
inversion-∃ (∃ⱼ_▹_ {l = l∃} x x₁) = l∃ , x , x₁ , refl (Ugenⱼ (wfTerm x)) , PE.refl
inversion-∃ (conv x x₁) = let l∃ , a , b , c , r≡! = inversion-∃ x
in l∃ , a , b , trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) r≡! x₁)) c , r≡!
inversion-Empty : ∀ {Γ C r l} → Γ ⊢ Empty l ∷ C ^ r → Γ ⊢ C ≡ SProp l ^ r × r PE.≡ [ ! , next l ]
inversion-Empty (Emptyⱼ x) = refl (Ugenⱼ x) , PE.refl
inversion-Empty (conv x x₁) =
let C≡SProp , r = inversion-Empty x
in trans (sym x₁) C≡SProp , r
-- Inversion of zero.
inversion-zero : ∀ {Γ C r} → Γ ⊢ zero ∷ C ^ r → Γ ⊢ C ≡ ℕ ^ [ ! , ι ⁰ ] × r PE.≡ [ ! , ι ⁰ ]
inversion-zero (zeroⱼ x) = univ (refl (ℕⱼ x)) , PE.refl
inversion-zero (conv x x₁) with inversion-zero x
... | [C≡ℕ] , PE.refl = trans (sym x₁) [C≡ℕ] , PE.refl
-- Inversion of successor.
inversion-suc : ∀ {Γ t C r} → Γ ⊢ suc t ∷ C ^ r → Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ] × Γ ⊢ C ≡ ℕ ^ [ ! , ι ⁰ ] × r PE.≡ [ ! , ι ⁰ ]
inversion-suc (sucⱼ x) = x , refl (univ (ℕⱼ (wfTerm x))) , PE.refl
inversion-suc (conv x x₁) with inversion-suc x
... | a , b , PE.refl = a , trans (sym x₁) b , PE.refl
-- Inversion of natural recursion.
inversion-natrec : ∀ {Γ c g n A C rlC lC} → Γ ⊢ natrec lC C c g n ∷ A ^ rlC
→ ∃ λ rC → (Γ ∙ ℕ ^ [ ! , ι ⁰ ]) ⊢ C ^ [ rC , ι lC ]
× Γ ⊢ c ∷ C [ zero ] ^ [ rC , ι lC ]
× Γ ⊢ g ∷ Π ℕ ^ ! ° ⁰ ▹ (C ^ rC ° lC ▹▹ C [ suc (var 0) ]↑ ° lC ° lC) ° lC ° lC ^ [ rC , ι lC ]
× Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]
× Γ ⊢ A ≡ C [ n ] ^ [ rC , ι lC ]
× rlC PE.≡ [ rC , ι lC ]
inversion-natrec (natrecⱼ x d d₁ n) = _ , x , d , d₁ , n , refl (substType x n) , PE.refl
inversion-natrec (conv d x) = let a' , a , b , c , d , e , e' = inversion-natrec d
in a' , a , b , c , d , trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) e' x)) e , e'
inversion-Emptyrec : ∀ {Γ e A C rlC lEmpty lC} → Γ ⊢ Emptyrec lC lEmpty C e ∷ A ^ rlC
→ ∃ λ rC → Γ ⊢ C ^ [ rC , ι lC ]
× Γ ⊢ e ∷ Empty lEmpty ^ [ % , ι lEmpty ]
× Γ ⊢ A ≡ C ^ [ rC , ι lC ]
× rlC PE.≡ [ rC , ι lC ]
inversion-Emptyrec (Emptyrecⱼ [C] [e]) = _ , [C] , [e] , refl [C] , PE.refl
inversion-Emptyrec (conv d x) = let r , a , b , c , e = inversion-Emptyrec d
in r , a , b , trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) e x)) c , e
-- Inversion of application.
inversion-app : ∀ {Γ f a A r lΠ} → Γ ⊢ (f ∘ a ^ lΠ) ∷ A ^ r →
∃₂ λ F rF → ∃₂ λ lF G → ∃₂ λ lG rG → Γ ⊢ f ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rG , ι lΠ ]
× Γ ⊢ a ∷ F ^ [ rF , ι lF ]
× Γ ⊢ A ≡ G [ a ] ^ [ rG , ι lG ]
× r PE.≡ [ rG , ι lG ]
inversion-app (d ∘ⱼ d₁) = _ , _ , _ , _ , _ , _ , d , d₁ , refl (substTypeΠ (syntacticTerm d) d₁) , PE.refl
inversion-app (conv d x) = let a , b , c , d , e , f , g , h , i , j = inversion-app d
in a , b , c , d , e , f , g , h , trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) j x)) i , j
-- Inversion of lambda.
inversion-lam : ∀ {t F A r lΠ Γ} → Γ ⊢ lam F ▹ t ^ lΠ ∷ A ^ r →
∃₂ λ rF lF → ∃₂ λ G rG → ∃ λ lG → Γ ⊢ F ^ [ rF , ι lF ]
× Γ ∙ F ^ [ rF , ι lF ] ⊢ t ∷ G ^ [ rG , ι lG ]
× Γ ⊢ A ≡ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rG , ι lΠ ]
× r PE.≡ [ rG , ι lΠ ]
inversion-lam (lamⱼ l< l<' x x₁) = _ , _ , _ , _ , _ , x , x₁ ,
refl (univ (Πⱼ l< ▹ l<' ▹ (un-univ x) ▹ un-univ (syntacticTerm x₁))) , PE.refl
inversion-lam (conv x x₁) = let a , b , c , d , e , f , g , h , i = inversion-lam x
in a , b , c , d , e , f , g , trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) i x₁)) h , i
-- Inversion of Id-types.
inversion-Id : ∀ {A t u C r Γ}
→ Γ ⊢ Id A t u ∷ C ^ r
→ ∃ λ l
→ Γ ⊢ A ∷ U l ^ [ ! , next l ]
× Γ ⊢ t ∷ A ^ [ ! , ι l ]
× Γ ⊢ u ∷ A ^ [ ! , ι l ]
× Γ ⊢ C ≡ SProp l ^ [ ! , next l ]
× r PE.≡ [ ! , next l ]
inversion-Id (Idⱼ {l = l} A t u) = l , A , t , u , refl (Ugenⱼ (wfTerm A)) , PE.refl
inversion-Id (conv x x₁) = let l , a , b , c , d , r≡! = inversion-Id x
in l , a , b , c , trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) r≡! x₁)) d , r≡!
-- Inversion of cast-types.
inversion-cast : ∀ {A B e t l C r Γ}
→ Γ ⊢ cast l A B e t ∷ C ^ r
→ ∃ λ rA
→ Γ ⊢ A ∷ Univ rA l ^ [ ! , next ⁰ ]
× Γ ⊢ B ∷ Univ rA l ^ [ ! , next ⁰ ]
× Γ ⊢ e ∷ Id (Univ rA l) A B ^ [ % , next ⁰ ]
× Γ ⊢ t ∷ A ^ [ rA , ι ⁰ ]
× Γ ⊢ C ≡ B ^ [ rA , ι ⁰ ]
× r PE.≡ [ rA , ι ⁰ ]
× l PE.≡ ⁰
inversion-cast (castⱼ X X₁ X₂ X₃) = _ , X , X₁ , X₂ , X₃ , refl (univ X₁) , PE.refl , PE.refl
inversion-cast (conv x x₁) = let r , a , b , c , d , e , r≡! , el = inversion-cast x
in r , a , b , c , d , trans (sym (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ rx) r≡! x₁)) e , r≡! , el
| 46.816327
| 121
| 0.439117
|
581307995d4d9804de484679a277db7a1105c718
| 240
|
agda
|
Agda
|
src/Calf/Types/Bool.agda
|
jonsterling/agda-calf
|
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
|
[
"Apache-2.0"
] | 29
|
2021-07-14T03:18:28.000Z
|
2022-03-22T20:35:11.000Z
|
src/Calf/Types/Bool.agda
|
jonsterling/agda-calf
|
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
|
[
"Apache-2.0"
] | null | null | null |
src/Calf/Types/Bool.agda
|
jonsterling/agda-calf
|
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
|
[
"Apache-2.0"
] | 2
|
2021-10-06T10:28:24.000Z
|
2022-01-29T08:12:01.000Z
|
{-# OPTIONS --prop --without-K --rewriting #-}
module Calf.Types.Bool where
open import Calf.Prelude
open import Calf.Metalanguage
open import Data.Bool public using (Bool; true; false; if_then_else_)
bool : tp pos
bool = U (meta Bool)
| 20
| 69
| 0.733333
|
1a41eb2d22eab4873c1c8d6605c0fb6a167cf87e
| 175
|
agda
|
Agda
|
test/Compiler/with-stdlib/HelloWorldPrim.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/with-stdlib/HelloWorldPrim.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/with-stdlib/HelloWorldPrim.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --guardedness #-}
module HelloWorldPrim where
open import IO.Primitive.Infinite
open import Codata.Musical.Costring
main = putStrLn (toCostring "Hello World!")
| 19.444444
| 43
| 0.771429
|
59a2f242b5fcfebae54c0ef110956b345a51c167
| 2,431
|
agda
|
Agda
|
Cubical/Data/Vec/OperationsNat.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Data/Vec/OperationsNat.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Data/Vec/OperationsNat.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Data.Vec.OperationsNat where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat renaming(_+_ to _+n_; _·_ to _·n_)
open import Cubical.Data.Vec.Base
open import Cubical.Data.Sigma
private variable
ℓ : Level
_+n-vec_ : {m : ℕ} → Vec ℕ m → Vec ℕ m → Vec ℕ m
_+n-vec_ {.zero} [] [] = []
_+n-vec_ {.(suc _)} (k ∷ v) (l ∷ v') = (k +n l) ∷ (v +n-vec v')
+n-vec-lid : {m : ℕ} → (v : Vec ℕ m) → replicate 0 +n-vec v ≡ v
+n-vec-lid {.zero} [] = refl
+n-vec-lid {.(suc _)} (k ∷ v) = cong (_∷_ k) (+n-vec-lid v)
+n-vec-rid : {m : ℕ} → (v : Vec ℕ m) → v +n-vec replicate 0 ≡ v
+n-vec-rid {.zero} [] = refl
+n-vec-rid {.(suc _)} (k ∷ v) = cong₂ _∷_ (+-zero k) (+n-vec-rid v)
+n-vec-assoc : {m : ℕ} → (v v' v'' : Vec ℕ m) → v +n-vec (v' +n-vec v'') ≡ (v +n-vec v') +n-vec v''
+n-vec-assoc [] [] [] = refl
+n-vec-assoc (k ∷ v) (l ∷ v') (p ∷ v'') = cong₂ _∷_ (+-assoc k l p) (+n-vec-assoc v v' v'')
+n-vec-comm : {m : ℕ} → (v v' : Vec ℕ m) → v +n-vec v' ≡ v' +n-vec v
+n-vec-comm {.zero} [] [] = refl
+n-vec-comm {.(suc _)} (k ∷ v) (l ∷ v') = cong₂ _∷_ (+-comm k l) (+n-vec-comm v v')
sep-vec : (k l : ℕ) → Vec ℕ (k +n l) → (Vec ℕ k) × (Vec ℕ l )
sep-vec zero l v = [] , v
sep-vec (suc k) l (x ∷ v) = (x ∷ fst (sep-vec k l v)) , (snd (sep-vec k l v))
sep-vec-fst : (k l : ℕ) → (v : Vec ℕ k) → (v' : Vec ℕ l) → fst (sep-vec k l (v ++ v')) ≡ v
sep-vec-fst zero l [] v' = refl
sep-vec-fst (suc k) l (x ∷ v) v' = cong (λ X → x ∷ X) (sep-vec-fst k l v v')
sep-vec-snd : (k l : ℕ) → (v : Vec ℕ k) → (v' : Vec ℕ l) → snd (sep-vec k l (v ++ v')) ≡ v'
sep-vec-snd zero l [] v' = refl
sep-vec-snd (suc k) l (x ∷ v) v' = sep-vec-snd k l v v'
sep-vec-id : (k l : ℕ) → (v : Vec ℕ (k +n l)) → fst (sep-vec k l v) ++ snd (sep-vec k l v) ≡ v
sep-vec-id zero l v = refl
sep-vec-id (suc k) l (x ∷ v) = cong (λ X → x ∷ X) (sep-vec-id k l v)
rep-concat : (k l : ℕ) → {B : Type ℓ} → (b : B) →
replicate {_} {k} {B} b ++ replicate {_} {l} {B} b ≡ replicate {_} {k +n l} {B} b
rep-concat zero l b = refl
rep-concat (suc k) l b = cong (λ X → b ∷ X) (rep-concat k l b)
+n-vec-concat : (k l : ℕ) → (v w : Vec ℕ k) → (v' w' : Vec ℕ l)
→ (v +n-vec w) ++ (v' +n-vec w') ≡ (v ++ v') +n-vec (w ++ w')
+n-vec-concat zero l [] [] v' w' = refl
+n-vec-concat (suc k) l (x ∷ v) (y ∷ w) v' w' = cong (λ X → x +n y ∷ X) (+n-vec-concat k l v w v' w')
| 41.913793
| 101
| 0.496503
|
3951b75a932227d7c1204412404f7cec8e983689
| 14,055
|
agda
|
Agda
|
core/lib/PathOver.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
core/lib/PathOver.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
core/lib/PathOver.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.PathFunctor
open import lib.PathGroupoid
open import lib.Equivalence
{- Structural lemmas about paths over paths
The lemmas here have the form
[↓-something-in] : introduction rule for the something
[↓-something-out] : elimination rule for the something
[↓-something-β] : β-reduction rule for the something
[↓-something-η] : η-reduction rule for the something
The possible somethings are:
[cst] : constant fibration
[cst2] : fibration constant in the second argument
[cst2×] : fibration constant and nondependent in the second argument
[ap] : the path below is of the form [ap f p]
[fst×] : the fibration is [fst] (nondependent product)
[snd×] : the fibration is [snd] (nondependent product)
The rule of prime: The above lemmas should choose
between [_∙_] and [_∙'_] in a way that, if the underlying path is [idp],
then the entire lemma reduces to an identity function.
Otherwise, the lemma would have the suffix [in'] or [out'], meaning that
all the choices of [_∙_] or [_∙'_] are exactly the opposite ones.
You can also go back and forth between dependent paths and homogeneous paths
with a transport on one side with the functions
[to-transp], [from-transp], [to-transp-β]
[to-transp!], [from-transp!], [to-transp!-β]
More lemmas about paths over paths are present in the lib.types.* modules
(depending on the type constructor of the fibration)
-}
module lib.PathOver where
{- Dependent paths in a constant fibration -}
module _ {i j} {A : Type i} {B : Type j} where
↓-cst-in : {x y : A} {p : x == y} {u v : B}
→ u == v
→ u == v [ (λ _ → B) ↓ p ]
↓-cst-in {p = idp} q = q
↓-cst-out : {x y : A} {p : x == y} {u v : B}
→ u == v [ (λ _ → B) ↓ p ]
→ u == v
↓-cst-out {p = idp} q = q
↓-cst-β : {x y : A} (p : x == y) {u v : B} (q : u == v)
→ (↓-cst-out (↓-cst-in {p = p} q) == q)
↓-cst-β idp q = idp
{- Interaction of [↓-cst-in] with [_∙_] -}
↓-cst-in-∙ : {x y z : A} (p : x == y) (q : y == z) {u v w : B}
(p' : u == v) (q' : v == w)
→ ↓-cst-in {p = p ∙ q} (p' ∙ q')
== ↓-cst-in {p = p} p' ∙ᵈ ↓-cst-in {p = q} q'
↓-cst-in-∙ idp idp p' q' = idp
{- Interaction of [↓-cst-in] with [_∙'_] -}
↓-cst-in-∙' : {x y z : A} (p : x == y) (q : y == z) {u v w : B}
(p' : u == v) (q' : v == w)
→ ↓-cst-in {p = p ∙' q} (p' ∙' q')
== ↓-cst-in {p = p} p' ∙'ᵈ ↓-cst-in {p = q} q'
↓-cst-in-∙' idp idp p' q' = idp
{- Introduction of an equality between [↓-cst-in]s (used to deduce the
recursor from the eliminator in HIT with 2-paths) -}
↓-cst-in2 : {a a' : A} {b b' : B}
{p₀ p₁ : a == a'} {q₀ q₁ : b == b'} {q : p₀ == p₁}
→ q₀ == q₁
→ ↓-cst-in {p = p₀} q₀ == ↓-cst-in {p = p₁} q₁
[ (λ p → b == b' [ (λ _ → B) ↓ p ]) ↓ q ]
↓-cst-in2 {p₀ = idp} {p₁ = .idp} {q = idp} k = k
↓-cst-out2 : {a a' : A} {b b' : B}
{p₀ p₁ : a == a'}
{q₀ : b == b' [ (λ _ → B) ↓ p₀ ]}
{q₁ : b == b' [ (λ _ → B) ↓ p₁ ]}
{q : p₀ == p₁}
→ (q₀ == q₁ [ (λ p → b == b' [ (λ _ → B) ↓ p ]) ↓ q ] )
→ ↓-cst-out q₀ == ↓-cst-out q₁
↓-cst-out2 {p₀ = idp} {p₁ = .idp} {q = idp} k = k
↓-cst-in2-idp : {a a' : A} {b b' : B}
(p : a == a') (q : b == b')
→ ↓-cst-in2 {q = idp {a = p}} (idp {a = q}) == idp {a = ↓-cst-in {p = p} q}
↓-cst-in2-idp idp q = idp
↓-cst-in2-∙ : {a a' : A} {b b' : B}
{p₀ p₁ p₂ : a == a'} {q₀ q₁ q₂ : b == b'} {p₀₁ : p₀ == p₁} {p₁₂ : p₁ == p₂}
→ (q₀₁ : q₀ == q₁) (q₁₂ : q₁ == q₂)
→ ↓-cst-in2 {q = p₀₁ ∙ p₁₂} (q₀₁ ∙ q₁₂) == ↓-cst-in2 {q = p₀₁} q₀₁ ∙ᵈ ↓-cst-in2 {q = p₁₂} q₁₂
↓-cst-in2-∙ {p₀ = idp} {p₁ = .idp} {p₂ = .idp} {q₀} {q₁} {q₂} {idp} {idp} q₀₁ q₀₂ = idp
↓-cst-in-assoc : {a a' a'' a''' : A}
{p₀ : a == a'} {p₁ : a' == a''} {p₂ : a'' == a'''}
{b b' b'' b''' : B}
(q₀ : b == b') (q₁ : b' == b'') (q₂ : b'' == b''')
→ ↓-cst-in2 {q = ∙-assoc p₀ p₁ p₂} (∙-assoc q₀ q₁ q₂) ▹
(↓-cst-in-∙ p₀ (p₁ ∙ p₂) q₀ (q₁ ∙ q₂) ∙ (↓-cst-in {p = p₀} q₀ ∙ᵈₗ ↓-cst-in-∙ p₁ p₂ q₁ q₂))
==
↓-cst-in-∙ (p₀ ∙ p₁) p₂ (q₀ ∙ q₁) q₂ ◃
(↓-cst-in-∙ p₀ p₁ q₀ q₁ ∙ᵈᵣ ↓-cst-in {p = p₂} q₂) ◃
∙ᵈ-assoc (↓-cst-in {p = p₀} q₀) (↓-cst-in {p = p₁} q₁) (↓-cst-in {p = p₂} q₂)
↓-cst-in-assoc {p₀ = idp} {p₁ = idp} {p₂ = idp} q₀ q₁ q₂ = idp
↓-cst-in2-whisker-right : {a a' a'' : A} {b b' b'' : B}
{p₀ p₁ : a == a'} {p' : a' == a''}
{q₀ q₁ : b == b'} {q' : b' == b''}
{p₀₁ : p₀ == p₁}
→ (q₀₁ : q₀ == q₁)
→ ↓-cst-in2 {q = ap (λ r → r ∙ p') p₀₁} (ap (λ r → r ∙ q') q₀₁) ▹
↓-cst-in-∙ p₁ p' q₁ q'
==
↓-cst-in-∙ p₀ p' q₀ q' ◃
(↓-cst-in2 {q = p₀₁} q₀₁ ∙ᵈᵣ ↓-cst-in {p = p'} q')
↓-cst-in2-whisker-right {p₀ = idp} {p₁ = .idp} {p' = idp} {p₀₁ = idp} idp = idp
↓-cst-in2-whisker-left : {a a' a'' : A} {b b' b'' : B}
{p : a == a'} {p₀' p₁' : a' == a''}
{q : b == b'} {q₀' q₁' : b' == b''}
{p₀₁' : p₀' == p₁'}
→ (q₀₁' : q₀' == q₁')
→ ↓-cst-in2 {q = ap (λ r → p ∙ r) p₀₁'} (ap (λ r → q ∙ r) q₀₁') ▹
↓-cst-in-∙ p p₁' q q₁'
==
↓-cst-in-∙ p p₀' q q₀' ◃
(↓-cst-in {p = p} q ∙ᵈₗ ↓-cst-in2 {q = p₀₁'} q₀₁')
↓-cst-in2-whisker-left {p = idp} {p₀' = idp} {p₁' = .idp} {p₀₁' = idp} idp = idp
-- Dependent paths in a fibration constant in the second argument
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where
↓-cst2-in : {x y : A} (p : x == y) {b : C x} {c : C y}
(q : b == c [ C ↓ p ]) {u : B x} {v : B y}
→ u == v [ B ↓ p ]
→ u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ]
↓-cst2-in idp idp r = r
↓-cst2-out : {x y : A} (p : x == y) {b : C x} {c : C y}
(q : b == c [ C ↓ p ]) {u : B x} {v : B y}
→ u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ]
→ u == v [ B ↓ p ]
↓-cst2-out idp idp r = r
-- Dependent paths in a fibration constant and non dependent in the
-- second argument
module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} where
↓-cst2×-in : {x y : A} (p : x == y) {b c : C}
(q : b == c) {u : B x} {v : B y}
→ u == v [ B ↓ p ]
→ u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ]
↓-cst2×-in idp idp r = r
↓-cst2×-out : {x y : A} (p : x == y) {b c : C}
(q : b == c) {u : B x} {v : B y}
→ u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ]
→ u == v [ B ↓ p ]
↓-cst2×-out idp idp r = r
-- Dependent paths in the universal fibration over the universe
↓-idf-out : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B}
→ u == v [ (λ X → X) ↓ p ]
→ coe p u == v
↓-idf-out idp = idf _
↓-idf-in : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B}
→ coe p u == v
→ u == v [ (λ X → X) ↓ p ]
↓-idf-in idp = idf _
-- Dependent paths over [ap f p]
module _ {i j k} {A : Type i} {B : Type j} (C : B → Type k) (f : A → B) where
↓-ap-in : {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)}
→ u == v [ C ∘ f ↓ p ]
→ u == v [ C ↓ ap f p ]
↓-ap-in {p = idp} q = q
↓-ap-out : {x y : A} (p : x == y) {u : C (f x)} {v : C (f y)}
→ u == v [ C ↓ ap f p ]
→ u == v [ C ∘ f ↓ p ]
↓-ap-out idp q = q
↓-ap-in-β : {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)}
→ ∀ q → ↓-ap-in {u = u} {v = v} (↓-ap-out p q) == q
↓-ap-in-β {p = idp} q = idp
↓-ap-in-η : {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)}
→ ∀ q → ↓-ap-out p (↓-ap-in {u = u} {v = v} q) == q
↓-ap-in-η {p = idp} q = idp
↓-ap-equiv : ∀ {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)}
→ (u == v [ C ∘ f ↓ p ]) ≃ (u == v [ C ↓ ap f p ])
↓-ap-equiv {p = p} = equiv ↓-ap-in (↓-ap-out p) ↓-ap-in-β ↓-ap-in-η
↓-cst-in2-ap : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
{a a' : A} {b b' : B} {c c' : C}
(f : C → a == a') (g : C → b == b') (r : c == c')
→ ↓-cst-in2 {q = ap f r} (ap g r)
==
↓-ap-in (λ p → b == b' [ (λ _ → B) ↓ p ])
f
(apd (λ c → ↓-cst-in {p = f c} (g c)) r)
↓-cst-in2-ap {c = c} {c' = .c} f g idp = ↓-cst-in2-idp (f c) (g c)
-- Dependent paths over [ap2 f p q]
module _ {i j k l} {A : Type i} {B : Type j} {C : Type k} (D : C → Type l)
(f : A → B → C) where
↓-ap2-in : {x y : A} {p : x == y} {w z : B} {q : w == z}
{u : D (f x w)} {v : D (f y z)}
→ u == v [ D ∘ uncurry f ↓ pair×= p q ]
→ u == v [ D ↓ ap2 f p q ]
↓-ap2-in {p = idp} {q = idp} α = α
↓-ap2-out : {x y : A} {p : x == y} {w z : B} {q : w == z}
{u : D (f x w)} {v : D (f y z)}
→ u == v [ D ↓ ap2 f p q ]
→ u == v [ D ∘ uncurry f ↓ pair×= p q ]
↓-ap2-out {p = idp} {q = idp} α = α
apd↓ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
(f : {a : A} (b : B a) → C a b) {x y : A} {p : x == y}
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ f u == f v [ (λ xy → C (fst xy) (snd xy)) ↓ pair= p q ]
apd↓ f {p = idp} idp = idp
apd↓=apd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A}
(p : x == y) → (apd f p == ↓-ap-out _ _ p (apd↓ {A = Unit} f {p = idp} p))
apd↓=apd f idp = idp
-- Paths in the fibrations [fst] and [snd]
module _ {i j} where
↓-fst×-out : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B')
{u : A} {v : A'}
→ u == v [ fst ↓ pair×= p q ]
→ u == v [ (λ X → X) ↓ p ]
↓-fst×-out idp idp h = h
↓-snd×-in : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B')
{u : B} {v : B'}
→ u == v [ (λ X → X) ↓ q ]
→ u == v [ snd ↓ pair×= p q ]
↓-snd×-in idp idp h = h
-- Mediating dependent paths with the transport version
module _ {i j} {A : Type i} where
from-transp : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'}
→ (transport B p u == v)
→ (u == v [ B ↓ p ])
from-transp B idp idp = idp
to-transp : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
→ (u == v [ B ↓ p ])
→ (transport B p u == v)
to-transp {p = idp} idp = idp
to-transp-β : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'}
(q : transport B p u == v)
→ to-transp (from-transp B p q) == q
to-transp-β B idp idp = idp
to-transp-η : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
(q : u == v [ B ↓ p ])
→ from-transp B p (to-transp q) == q
to-transp-η {p = idp} idp = idp
to-transp-equiv : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (transport B p u == v)
to-transp-equiv B p =
equiv to-transp (from-transp B p) (to-transp-β B p) (to-transp-η)
from-transp! : (B : A → Type j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
→ (u == transport! B p v)
→ (u == v [ B ↓ p ])
from-transp! B idp idp = idp
to-transp! : {B : A → Type j}
{a a' : A} {p : a == a'}
{u : B a} {v : B a'}
→ (u == v [ B ↓ p ])
→ (u == transport! B p v)
to-transp! {p = idp} idp = idp
to-transp!-β : (B : A → Type j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
(q : u == transport! B p v)
→ to-transp! (from-transp! B p q) == q
to-transp!-β B idp idp = idp
to-transp!-η : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
(q : u == v [ B ↓ p ])
→ from-transp! B p (to-transp! q) == q
to-transp!-η {p = idp} idp = idp
to-transp!-equiv : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (u == transport! B p v)
to-transp!-equiv B p =
equiv to-transp! (from-transp! B p) (to-transp!-β B p) (to-transp!-η)
{- Various other lemmas -}
module _ {i j} {A : Type i} {B : Type j} where
{- Used for defining the recursor from the eliminator for 1-HIT -}
apd=cst-in : ∀ {f : A → B} {a a' : A} {p : a == a'} {q : f a == f a'}
→ apd f p == ↓-cst-in q → ap f p == q
apd=cst-in {p = idp} x = x
ap=↓-cst-out-apd : ∀ (f : A → B) {a a' : A} (p : a == a')
→ ap f p == ↓-cst-out (apd f p)
ap=↓-cst-out-apd f idp = idp
↓-apd-out : ∀ {i j k} {A : Type i} {B : A → Type j} (C : (a : A) → B a → Type k)
{f : Π A B} {x y : A} {p : x == y}
{q : f x == f y [ B ↓ p ]} (r : apd f p == q)
{u : C x (f x)} {v : C y (f y)}
→ u == v [ uncurry C ↓ pair= p q ]
→ u == v [ (λ z → C z (f z)) ↓ p ]
↓-apd-out C {p = idp} idp idp = idp
↓-ap-out= : ∀ {i j k} {A : Type i} {B : Type j} (C : (b : B) → Type k)
(f : A → B) {x y : A} (p : x == y)
{q : f x == f y} (r : ap f p == q)
{u : C (f x)} {v : C (f y)}
→ u == v [ C ↓ q ]
→ u == v [ (λ z → C (f z)) ↓ p ]
↓-ap-out= C f idp idp idp = idp
-- No idea what that is
to-transp-weird : ∀ {i j} {A : Type i} {B : A → Type j}
{u v : A} {d : B u} {d' d'' : B v} {p : u == v}
(q : d == d' [ B ↓ p ]) (r : transport B p d == d'')
→ (from-transp B p r ∙'ᵈ (! r ∙ to-transp q)) == q
to-transp-weird {p = idp} idp idp = idp
-- Something not really clear yet
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → C) (g : B → C)
where
↓-swap : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
→ (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
→ (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
↓-swap {p = idp} {q = idp} r s t = (! t) ∙ ∙'-unit-l s ∙ ! (∙-unit-r s)
↓-swap! : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
→ (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
→ (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
↓-swap! {p = idp} {q = idp} r s t = ∙'-unit-l s ∙ ! (∙-unit-r s) ∙ (! t)
↓-swap-β : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
(t : ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
→ ↓-swap! r s (↓-swap r s t) == t
↓-swap-β {p = idp} {q = idp} r s t = coh (∙'-unit-l s) (∙-unit-r s) t where
coh : ∀ {i} {X : Type i} {x y z t : X} (p : x == y) (q : z == y) (r : x == t)
→ p ∙ ! q ∙ ! (! r ∙ p ∙ ! q) == r
coh idp idp idp = idp
transp-↓ : ∀ {i j} {A : Type i} (P : A → Type j) {a₁ a₂ : A}
(p : a₁ == a₂) (y : P a₂) → transport P (! p) y == y [ P ↓ p ]
transp-↓ _ idp _ = idp
transp-ap-↓ : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) (h : A → B)
{a₁ a₂ : A} (p : a₁ == a₂) (y : P (h a₂))
→ transport P (! (ap h p)) y == y [ P ∘ h ↓ p ]
transp-ap-↓ _ _ idp _ = idp
| 35.854592
| 97
| 0.421914
|
06383780fc7bb2802794d27643875873e98a68f1
| 196
|
agda
|
Agda
|
All.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | 4
|
2016-12-25T01:52:57.000Z
|
2021-03-22T00:28:03.000Z
|
All.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | null | null | null |
All.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | 3
|
2015-04-26T11:39:14.000Z
|
2021-05-04T22:37:18.000Z
|
module All where
open import Prelude
open import T
open import SubstTheory
open import DynTheory
open import Progress
open import HT
open import Examples
open import Eq
open import DenotCommutes
| 16.333333
| 25
| 0.841837
|
06eb29eddfe7b84a17a8a610df83b4aa81f2f066
| 410
|
agda
|
Agda
|
benchmark/Syntacticosmos/Syntacticosmos.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
benchmark/Syntacticosmos/Syntacticosmos.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
benchmark/Syntacticosmos/Syntacticosmos.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Syntacticosmos (Gnd : Set)(U : Set)(El : U -> Set) where
open import Basics
open import Pr
open import Nom
import Kind
open Kind Gnd U El public
import Cxt
open Cxt Kind public
import Loc
open Loc Kind public
import Term
open Term Gnd U El public
import Shift
open Shift Gnd U El public
import Eta
open Eta Gnd U El public
import Inst
open Inst Gnd U El public
import Subst
open Subst Gnd U El public
| 17.826087
| 63
| 0.770732
|
2e00de36f1d93b8fb9376fef886c1ab206489fb9
| 5,481
|
agda
|
Agda
|
notes/FOT/FOTC/Program/GCD/Total/CommutativeI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Program/GCD/Total/CommutativeI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Program/GCD/Total/CommutativeI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- The gcd is commutative
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.GCD.Total.CommutativeI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Induction.NonAcc.LexicographicI
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesI
open import FOTC.Data.Nat.Inequalities.PropertiesI
open import FOTC.Data.Nat.PropertiesI
open import FOTC.Program.GCD.Total.ConversionRulesI
open import FOTC.Program.GCD.Total.GCD
------------------------------------------------------------------------------
-- Informal proof:
-- 1. gcd 0 n = n -- gcd def
-- = gcd n 0 -- gcd def
-- 2. gcd n 0 = n -- gcd def
-- = gcd 0 n -- gcd def
-- 3.1. Case: S m > S n
-- gcd (S m) (S n) = gcd (S m - S n) (S n) -- gcd def
-- = gcd (S n) (S m - S n) -- IH
-- = gcd (S n) (S m) -- gcd def
-- 3.2. Case: S m ≮ S n
-- gcd (S m) (S n) = gcd (S m) (S n - S m) -- gcd def
-- = gcd (S n - S m) (S m) -- IH
-- = gcd (S n) (S m) -- gcd def
------------------------------------------------------------------------------
-- Commutativity property.
Comm : D → D → Set
Comm t t' = gcd t t' ≡ gcd t' t
{-# ATP definition Comm #-}
x>y→y≯x : ∀ {m n} → N m → N n → m > n → n ≯ m
x>y→y≯x nzero Nn 0>n = ⊥-elim (0>x→⊥ Nn 0>n)
{-# CATCHALL #-}
x>y→y≯x Nm nzero _ = 0≯x Nm
x>y→y≯x (nsucc {m} Nm) (nsucc {n} Nn) Sm>Sn =
trans (lt-SS m n) (x>y→y≯x Nm Nn (trans (sym (lt-SS n m)) Sm>Sn))
postulate x≯Sy→Sy>x : ∀ {m n} → N m → N n → m ≯ succ₁ n → succ₁ n > m
-- x≯Sy→Sy>x {n = n} nzero Nn _ = <-0S n
-- x≯Sy→Sy>x {n = n} (nsucc {m} Nm) Nn h = {!!}
------------------------------------------------------------------------------
-- gcd 0 0 is commutative.
gcd-00-comm : Comm zero zero
gcd-00-comm = refl
------------------------------------------------------------------------------
-- gcd (succ₁ n) 0 is commutative.
gcd-S0-comm : ∀ n → Comm (succ₁ n) zero
gcd-S0-comm n = trans (gcd-S0 n) (sym (gcd-0S n))
------------------------------------------------------------------------------
-- gcd (succ₁ m) (succ₁ n) when succ₁ m > succ₁ n is commutative.
gcd-S>S-comm : ∀ {m n} → N m → N n →
Comm (succ₁ m ∸ succ₁ n) (succ₁ n) →
succ₁ m > succ₁ n →
Comm (succ₁ m) (succ₁ n)
gcd-S>S-comm {m} {n} Nm Nn ih Sm>Sn =
gcd (succ₁ m) (succ₁ n)
≡⟨ gcd-S>S m n Sm>Sn ⟩
gcd (succ₁ m ∸ succ₁ n) (succ₁ n)
≡⟨ ih ⟩
gcd (succ₁ n) (succ₁ m ∸ succ₁ n)
≡⟨ sym (gcd-S≯S n m (x>y→y≯x (nsucc Nm) (nsucc Nn) Sm>Sn)) ⟩
gcd (succ₁ n) (succ₁ m) ∎
------------------------------------------------------------------------------
-- gcd (succ₁ m) (succ₁ n) when succ₁ m ≯ succ₁ n is commutative.
gcd-S≯S-comm : ∀ {m n} → N m → N n →
Comm (succ₁ m) (succ₁ n ∸ succ₁ m) →
succ₁ m ≯ succ₁ n →
Comm (succ₁ m) (succ₁ n)
gcd-S≯S-comm {m} {n} Nm Nn ih Sm≯Sn =
gcd (succ₁ m) (succ₁ n)
≡⟨ gcd-S≯S m n Sm≯Sn ⟩
gcd (succ₁ m) (succ₁ n ∸ succ₁ m)
≡⟨ ih ⟩
gcd (succ₁ n ∸ succ₁ m) (succ₁ m)
≡⟨ sym (gcd-S>S n m (x≯Sy→Sy>x (nsucc Nm) Nn Sm≯Sn)) ⟩
gcd (succ₁ n) (succ₁ m) ∎
------------------------------------------------------------------------------
-- gcd m n when m > n is commutative.
gcd-x>y-comm :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → Comm o p) →
m > n →
Comm m n
gcd-x>y-comm nzero Nn _ 0>n = ⊥-elim (0>x→⊥ Nn 0>n)
gcd-x>y-comm (nsucc {n} _) nzero _ _ = gcd-S0-comm n
gcd-x>y-comm (nsucc {m} Nm) (nsucc {n} Nn) ah Sm>Sn = gcd-S>S-comm Nm Nn ih Sm>Sn
where
-- Inductive hypothesis.
ih : Comm (succ₁ m ∸ succ₁ n) (succ₁ n)
ih = ah {succ₁ m ∸ succ₁ n}
{succ₁ n}
(∸-N (nsucc Nm) (nsucc Nn))
(nsucc Nn)
([Sx∸Sy,Sy]<[Sx,Sy] Nm Nn)
------------------------------------------------------------------------------
-- gcd m n when m ≯ n is commutative.
gcd-x≯y-comm :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → Comm o p) →
m ≯ n →
Comm m n
gcd-x≯y-comm nzero nzero _ _ = gcd-00-comm
gcd-x≯y-comm nzero (nsucc {n} _) _ _ = sym (gcd-S0-comm n)
gcd-x≯y-comm (nsucc _) nzero _ Sm≯0 = ⊥-elim (S≯0→⊥ Sm≯0)
gcd-x≯y-comm (nsucc {m} Nm) (nsucc {n} Nn) ah Sm≯Sn = gcd-S≯S-comm Nm Nn ih Sm≯Sn
where
-- Inductive hypothesis.
ih : Comm (succ₁ m) (succ₁ n ∸ succ₁ m)
ih = ah {succ₁ m}
{succ₁ n ∸ succ₁ m}
(nsucc Nm)
(∸-N (nsucc Nn) (nsucc Nm))
([Sx,Sy∸Sx]<[Sx,Sy] Nm Nn)
------------------------------------------------------------------------------
-- gcd is commutative.
gcd-comm : ∀ {m n} → N m → N n → Comm m n
gcd-comm = Lexi-wfind A h
where
A : D → D → Set
A i j = Comm i j
h : ∀ {i j} → N i → N j → (∀ {k l} → N k → N l → Lexi k l i j → A k l) →
A i j
h Ni Nj ah = case (gcd-x>y-comm Ni Nj ah)
(gcd-x≯y-comm Ni Nj ah)
(x>y∨x≯y Ni Nj)
| 36.298013
| 81
| 0.424193
|
58f0198d7491192df17ede548b8169334569fd42
| 4,837
|
agda
|
Agda
|
Cubical/Homotopy/MayerVietorisCofiber.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/MayerVietorisCofiber.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/MayerVietorisCofiber.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-
Mayer-Vietoris cofiber sequence:
Let X be a pointed type, and let a span B ←[f]- X -[g]→ C be given.
Then the mapping cone of the canonical map (B ⋁ C) → B ⊔_X C is equivalent to Susp X.
The sequence Susp X → (B ⋁ C) → B ⊔_X C therefore induces a long exact sequence in cohomology.
Proof is adapted from Evan Cavallo's master's thesis.
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Homotopy.MayerVietorisCofiber where
open import Cubical.Core.Everything
open import Cubical.Foundations.Everything
open import Cubical.Foundations.Pointed
open import Cubical.Data.Unit
open import Cubical.HITs.MappingCones
open import Cubical.HITs.Pushout
open import Cubical.HITs.Susp
open import Cubical.HITs.Wedge
module _ {ℓX ℓB ℓC} {X : Pointed ℓX} {B : Type ℓB} {C : Type ℓC} (f : X .fst → B) (g : X .fst → C)
where
private
Y : Pointed _
Y = (B , f (X .snd))
Z : Pointed _
Z = (C , g (X .snd))
wedgeToPushout : Y ⋁ Z → Pushout f g
wedgeToPushout (inl y) = inl y
wedgeToPushout (inr z) = inr z
wedgeToPushout (push _ i) = push (pt X) i
pushoutToSusp : Pushout f g → Susp (X .fst)
pushoutToSusp (inl y) = north
pushoutToSusp (inr z) = south
pushoutToSusp (push x i) = merid x i
{-
Coherence lemma:
To construct a function f : (c : Cone wedgeToPushout) → D c, we can always
adjust the definition of (f (spoke (inr z) i)) so that there is a canonical
choice for (f (spoke (push tt j) i))
-}
module Helper {ℓD} {D : Cone wedgeToPushout → Type ℓD}
(inj* : ∀ w → D (inj w))
(hub* : D hub)
(inl* : ∀ y → PathP (λ i → D (spoke (inl y) i)) hub* (inj* (inl y)))
(inr* : ∀ z → PathP (λ i → D (spoke (inr z) i)) hub* (inj* (inr z)))
where
cap : (i j : I) → D (spoke (push tt j) i)
cap i j =
fill
(λ i → D (spoke (push tt j) (~ i)))
(λ i → λ
{ (j = i0) → inl* (Y .snd) (~ i)
; (j = i1) → inr* (Z .snd) (~ i)
})
(inS (inj* (push (X .snd) j)))
(~ i)
cap0 : (j : I) → D hub
cap0 = cap i0
face-i≡0 : (k j : I) → D hub
face-i≡0 k j =
hfill
(λ j → λ
{ (k = i0) → cap0 j
; (k = i1) → hub*
})
(inS hub*)
j
inrFiller : ∀ z → (k i : I) → D (spoke (inr z) i)
inrFiller z k i =
hfill
(λ k → λ
{ (i = i0) → face-i≡0 k i1
; (i = i1) → inj* (inr z)
})
(inS (inr* z i))
k
fun : ∀ c → D c
fun (inj w) = inj* w
fun hub = hub*
fun (spoke (inl y) i) = inl* y i
fun (spoke (inr z) i) = inrFiller z i1 i
fun (spoke (push tt j) i) =
hcomp
(λ k → λ
{ (i = i0) → face-i≡0 k j
; (i = i1) → inj* (push (X .snd) j)
; (j = i0) → inl* (Y .snd) i
})
(cap i j)
equiv : Cone wedgeToPushout ≃ Susp (X .fst)
equiv = isoToEquiv (iso fwd bwd fwdBwd bwdFwd)
where
fwd : Cone wedgeToPushout → Susp (X .fst)
fwd (inj w) = pushoutToSusp w
fwd hub = north
fwd (spoke (inl y) i) = north
fwd (spoke (inr z) i) = merid (X .snd) i
fwd (spoke (push tt j) i) = merid (X .snd) (i ∧ j)
bwd : Susp (X .fst) → Cone wedgeToPushout
bwd north = hub
bwd south = hub
bwd (merid x i) =
hcomp
(λ k → λ
{ (i = i0) → spoke (inl (f x)) (~ k)
; (i = i1) → spoke (inr (g x)) (~ k)
})
(inj (push x i))
bwdPushout : (w : Pushout f g) → bwd (pushoutToSusp w) ≡ inj w
bwdPushout (inl y) = spoke (inl y)
bwdPushout (inr z) = spoke (inr z)
bwdPushout (push x i) k =
hfill
(λ k → λ
{ (i = i0) → spoke (inl (f x)) (~ k)
; (i = i1) → spoke (inr (g x)) (~ k)
})
(inS (inj (push x i)))
(~ k)
bwdMeridPt : refl ≡ cong bwd (merid (X .snd))
bwdMeridPt j i =
hcomp
(λ k → λ
{ (i = i0) → spoke (inl (Y .snd)) (~ k)
; (i = i1) → spoke (inr (Z .snd)) (~ k)
; (j = i0) → spoke (push _ i) (~ k)
})
(inj (push (X .snd) i))
bwdFwd : (c : Cone wedgeToPushout) → bwd (fwd c) ≡ c
bwdFwd =
Helper.fun
bwdPushout
refl
(λ y i k → spoke (inl y) (i ∧ k))
(λ z i k →
hcomp
(λ l → λ
{ (i = i0) → hub
; (i = i1) → spoke (inr z) k
; (k = i0) → bwdMeridPt l i
; (k = i1) → spoke (inr z) i
})
(spoke (inr z) (i ∧ k)))
fwdBwd : (s : Susp (X .fst)) → fwd (bwd s) ≡ s
fwdBwd north = refl
fwdBwd south = merid (X .snd)
fwdBwd (merid a i) j =
fill
(λ _ → Susp (X .fst))
(λ j → λ
{ (i = i0) → north
; (i = i1) → merid (X .snd) (~ j)
})
(inS (merid a i))
(~ j)
| 27.482955
| 98
| 0.479636
|
414838d16aa68b2f56100aaacc56b62b5bba0a47
| 728
|
agda
|
Agda
|
SDG/Extra/OrderedAlgebra/Structures.agda
|
wrrnhttn/agda-sdg
|
6814e6f0baffff35efe14ef70d469343cd9b3ba0
|
[
"MIT"
] | 1
|
2020-11-13T09:36:38.000Z
|
2020-11-13T09:36:38.000Z
|
SDG/Extra/OrderedAlgebra/Structures.agda
|
wrrnhttn/agda-sdg
|
6814e6f0baffff35efe14ef70d469343cd9b3ba0
|
[
"MIT"
] | 1
|
2019-07-18T20:00:23.000Z
|
2019-09-18T15:47:49.000Z
|
SDG/Extra/OrderedAlgebra/Structures.agda
|
wrrnhttn/agda-sdg
|
6814e6f0baffff35efe14ef70d469343cd9b3ba0
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Level hiding (zero)
open import Relation.Binary
module SDG.Extra.OrderedAlgebra.Structures {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
open import Algebra.Structures
open import Algebra.FunctionProperties
record IsOrderedCommutativeRing
(_<_ : Rel A ℓ)
(_+_ _*_ : Op₂ A)
(-_ : Op₁ A)
(0# 1# : A) : Set (a ⊔ ℓ) where
field
isCommutativeRing : IsCommutativeRing _≈_ _+_ _*_ -_ 0# 1#
<-isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_
<-+ : ∀ (a b c) → a < b → (a + c) < (b + c)
<-* : ∀ (a b) → 0# < a → 0# < b → 0# < (a * b)
open IsCommutativeRing isCommutativeRing public
--using (zero)
open IsStrictTotalOrder <-isStrictTotalOrder public
| 28
| 82
| 0.625
|
4d8add19d23b1f81a9cd28abfcd29b93abca4eab
| 1,509
|
agda
|
Agda
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-slist2-base.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-slist2-base.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-slist2-base.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
{-
https://mazzo.li/posts/AgdaSort.html
2013-04-01Agda by Example: Sorting
-}
module z05-01-hc-slist2-base where
data List (X : Set) : Set where
[] : List X
_∷_ : X → List X → List X
infixr 5 _∷_
foldr : ∀ {A} {B : Set} → (A → B → B) → B → List A → B
foldr f b [] = b
foldr f b (a ∷ as) = f a (foldr f b as)
data Either (A : Set) (B : Set) : Set where
left : A → Either A B
right : B → Either A B
[_,_] : ∀ {A B} {C : Set} → (A → C) → (B → C) → Either A B → C
[ f , g ] (left x) = f x
[ f , g ] (right x) = g x
-- Unhabited type
data Empty : Set where
absurd : {X : Set} → Empty → X
absurd ()
-- use Empty to define something close to negation in logic:
-- e.g., terms of type ¬ (3 > 4)
infix 3 ¬_
¬_ : Set → Set
¬ X = X → Empty
-- binary relation on a type X
Rel : Set → Set₁
Rel X = X → X → Set
-- decidable relations
Decidable : ∀ {X} → Rel X → Set
Decidable R = ∀ x y → Either (R x y) (¬ (R x y))
-- To sort a list, need two relations on elements of list:
-- equality
record Equivalence {X} (_≈_ : Rel X) : Set₁ where
field
refl : ∀ {x} → x ≈ x
sym : ∀ {x y} → x ≈ y → y ≈ x
trans : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z
-- and ordering
record TotalOrder {X} (_≈_ : Rel X) (_≤_ : Rel X) : Set₁ where
field
antisym : ∀ {x y} → x ≤ y → y ≤ x → x ≈ y
trans : ∀ {x y z} → x ≤ y → y ≤ z → x ≤ z
total : ∀ x y → Either (x ≤ y) (y ≤ x)
reflexive : ∀ {x y} → x ≈ y → x ≤ y
equivalence : Equivalence _≈_
| 24.33871
| 62
| 0.508284
|
22f39244a257302012a37762afefd41bf6a9de36
| 566
|
agda
|
Agda
|
Demos/Cantor.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Demos/Cantor.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Demos/Cantor.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe #-}
module Demos.Cantor where
open import Prelude
open import Data.Bool.Properties using (false≢true; true≢false)
Stream : Type a → Type a
Stream A = ℕ → A
_∈_ : ∀ {A : Type a} (x : A) → Stream A → Type a
x ∈ xs = ∃ i × (xs i ≡ x)
Countable : Type a → Type a
Countable A = Σ[ xs ⦂ Stream A ] × (∀ x → x ∈ xs)
x≢¬x : ∀ x → x ≢ not x
x≢¬x false = false≢true
x≢¬x true = true≢false
cantor : ¬ (Countable (Stream Bool))
cantor (support , cover) =
let p , ps = cover (λ i → not (support i i))
q = cong (_$ p) ps
in x≢¬x _ q
| 21.769231
| 63
| 0.579505
|
2232fb32ae995a926610a7800fc2b33394e655ea
| 14,770
|
agda
|
Agda
|
OutsideIn/Expressions.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | 2
|
2015-09-14T05:22:15.000Z
|
2020-11-19T14:30:07.000Z
|
OutsideIn/Expressions.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | null | null | null |
OutsideIn/Expressions.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | null | null | null |
open import OutsideIn.Prelude
open import OutsideIn.X
module OutsideIn.Expressions(x : X) where
import OutsideIn.TypeSchema as TS
open TS(x)
open X(x)
{- SYNTAX -}
data Name (n : Set) : NameType → Set where
N : n → Name n Regular
DC : ∀ {x} → dc x → Name n (Datacon x)
mutual
data Alternative (ev tv : Set) : Shape → Set where
_→′_ : ∀ {n : ℕ}{r : Shape}→ Name ev (Datacon n) → Expression (ev ⨁ n) tv r
→ Alternative ev tv (Unary r)
infixr 5 _∣_
data Alternatives (ev tv : Set) : Shape → Set where
esac : Alternatives ev tv Nullary
_∣_ : ∀ {r₁ r₂} → Alternative ev tv r₁ → Alternatives ev tv r₂
→ Alternatives ev tv (Binary r₁ r₂)
data Expression (ev tv : Set) : Shape → Set where
Var : ∀ {x} → Name ev x → Expression ev tv Nullary
λ′_ : ∀ {a} → Expression (Ⓢ ev) tv a → Expression ev tv (Unary a)
_·_ : ∀ {a a′} → Expression ev tv a → Expression ev tv a′ → Expression ev tv (Binary a a′)
let₁_in′_ : ∀ {a a′} → Expression ev tv a → Expression (Ⓢ ev) tv a′
→ Expression ev tv (Binary a a′)
let₂_∷_in′_ : ∀ {a a′} → Expression ev tv a → Type tv → Expression (Ⓢ ev) tv a′
→ Expression ev tv (Binary a a′)
let₃_·_∷_⇒_in′_ : ∀ {a a′} → (n : ℕ) → Expression ev (tv ⨁ n) a
→ QConstraint (tv ⨁ n)
→ Type (tv ⨁ n)
→ Expression (Ⓢ ev) tv a′
→ Expression ev tv (Binary a a′)
case_of_ : ∀ {r₁ r₂} → Expression ev tv r₁ → Alternatives ev tv r₂
→ Expression ev tv (Binary r₁ r₂)
private
module PlusN-f n = Functor (Monad.is-functor (PlusN-is-monad {n}))
module Ⓢ-f = Functor Ⓢ-is-functor
module Type-f = Functor (type-is-functor)
module TypeSchema-f {n} = Functor (type-schema-is-functor {n})
module QC-f = Functor (qconstraint-is-functor)
private
fmap-alt₁ : ∀ {a b tv}{r} → (a → b) → Alternative a tv r → Alternative b tv r
fmap-exp₁ : ∀ {a b tv}{r} → (a → b) → Expression a tv r → Expression b tv r
map-fmap-alt₁ : ∀ {a b tv}{r} → (a → b) → Alternatives a tv r → Alternatives b tv r
fmap-alt₁ f (_→′_ {n} (DC c) expr) = DC c →′ fmap-exp₁ (pn.map f) expr
where module pn = PlusN-f n
fmap-exp₁ f (Var (DC c)) = Var (DC c)
fmap-exp₁ f (Var (N x)) = Var (N (f x))
fmap-exp₁ f (λ′ x) = λ′ (fmap-exp₁ (Ⓢ-f.map f) x)
fmap-exp₁ f (x · y) = (fmap-exp₁ f x) · (fmap-exp₁ f y)
fmap-exp₁ f (let₁ x in′ y) = let₁ (fmap-exp₁ f x) in′ (fmap-exp₁ (Ⓢ-f.map f) y)
fmap-exp₁ f (let₂ x ∷ τ in′ y) = let₂ (fmap-exp₁ f x) ∷ τ in′ (fmap-exp₁ (Ⓢ-f.map f) y)
fmap-exp₁ f (let₃ n · x ∷ Q ⇒ τ in′ y) = let₃ n · fmap-exp₁ f x ∷ Q ⇒ τ
in′ fmap-exp₁ (Ⓢ-f.map f) y
fmap-exp₁ f (case x of alts) = case (fmap-exp₁ f x) of map-fmap-alt₁ f alts
map-fmap-alt₁ f esac = esac
map-fmap-alt₁ f (x ∣ xs) = fmap-alt₁ f x ∣ map-fmap-alt₁ f xs
private
fmap-alt₂ : ∀ {a b ev}{r} → (a → b) → Alternative ev a r → Alternative ev b r
fmap-exp₂ : ∀ {a b ev}{r} → (a → b) → Expression ev a r → Expression ev b r
map-fmap-alt₂ : ∀ {a b ev}{r} → (a → b) → Alternatives ev a r → Alternatives ev b r
fmap-alt₂ f (p →′ expr) = p →′ fmap-exp₂ f expr
fmap-exp₂ f (Var x) = Var x
fmap-exp₂ f (λ′ x) = λ′ (fmap-exp₂ f x)
fmap-exp₂ f (x · y) = fmap-exp₂ f x · fmap-exp₂ f y
fmap-exp₂ f (let₁ x in′ y) = let₁ fmap-exp₂ f x in′ fmap-exp₂ f y
fmap-exp₂ f (let₂ x ∷ τ in′ y) = let₂ fmap-exp₂ f x ∷ Type-f.map f τ in′ fmap-exp₂ f y
fmap-exp₂ f (let₃ n · x ∷ Q ⇒ τ in′ y) = let₃ n · fmap-exp₂ (pn.map f) x
∷ QC-f.map (pn.map f) Q ⇒ Type-f.map (pn.map f) τ
in′ fmap-exp₂ f y
where module pn = PlusN-f n
fmap-exp₂ f (case x of alts) = case (fmap-exp₂ f x) of map-fmap-alt₂ f alts
map-fmap-alt₂ f esac = esac
map-fmap-alt₂ f (x ∣ xs) = fmap-alt₂ f x ∣ map-fmap-alt₂ f xs
private
fmap-alt-id₁ : {A tv : Set} {f : A → A}{r : Shape}
→ isIdentity f → isIdentity (fmap-alt₁ {A}{A}{tv}{r} f)
map-fmap-alt-id₁ : ∀ {a}{tv}{f : a → a}{r : Shape}
→ isIdentity f → isIdentity (map-fmap-alt₁ {a}{a}{tv}{r} f)
fmap-exp-id₁ : ∀{A tv : Set}{r : Shape} {f : A → A} → isIdentity f
→ isIdentity (fmap-exp₁ {A}{A}{tv}{r} f)
fmap-alt-id₁ {A}{f} f-is-id {_→′_ {n} (DC p) x} = cong (_→′_ (DC p)) (fmap-exp-id₁ (pn.identity f-is-id))
where module pn = PlusN-f n
map-fmap-alt-id₁ {r = Unary _} f-is-id {}
map-fmap-alt-id₁ {r = Nullary} f-is-id {esac} = refl
map-fmap-alt-id₁ {r = Binary r₁ r₂} f-is-id {x ∣ xs} = cong₂ _∣_ (fmap-alt-id₁ f-is-id)
(map-fmap-alt-id₁ f-is-id)
fmap-exp-id₁ {r = Nullary} f-is-id {Var (DC x)} = refl
fmap-exp-id₁ {r = Nullary} f-is-id {Var (N x)} = cong Var (cong N f-is-id)
fmap-exp-id₁ {r = Unary r′} f-is-id {λ′ x} = cong λ′_ (fmap-exp-id₁ (Ⓢ-f.identity f-is-id))
fmap-exp-id₁ {r = Binary r₁ r₂} f-is-id {x · y} = cong₂ _·_ (fmap-exp-id₁ f-is-id)
(fmap-exp-id₁ f-is-id)
fmap-exp-id₁ {r = Binary r₁ r₂} f-is-id {let₁ x in′ y}
= cong₂ let₁_in′_ (fmap-exp-id₁ f-is-id) (fmap-exp-id₁ (Ⓢ-f.identity f-is-id))
fmap-exp-id₁ {r = Binary r₁ r₂} f-is-id {let₂ x ∷ τ in′ y}
= cong₂ (λ a b → let₂ a ∷ τ in′ b) (fmap-exp-id₁ f-is-id)
(fmap-exp-id₁ (Ⓢ-f.identity f-is-id))
fmap-exp-id₁ {r = Binary r₁ r₂} f-is-id {let₃ n · x ∷ Q ⇒ τ in′ y}
= cong₂ (λ a b → let₃ n · a ∷ Q ⇒ τ in′ b) (fmap-exp-id₁ f-is-id)
(fmap-exp-id₁ (Ⓢ-f.identity f-is-id))
fmap-exp-id₁ {r = Binary r₁ r₂} f-is-id {case x of alts}
= cong₂ case_of_ (fmap-exp-id₁ f-is-id) (map-fmap-alt-id₁ f-is-id)
private
fmap-alt-id₂ : {A ev : Set}{r : Shape}{f : A → A}
→ isIdentity f → isIdentity (fmap-alt₂ {A}{A}{ev}{r} f)
map-fmap-alt-id₂ : ∀ {a}{ev}{r : Shape}{f : a → a}
→ isIdentity f → isIdentity (map-fmap-alt₂ {a}{a}{ev}{r} f)
fmap-exp-id₂ : ∀{A ev : Set}{r : Shape} {f : A → A}
→ isIdentity f → isIdentity (fmap-exp₂ {A}{A}{ev}{r} f)
fmap-alt-id₂ f-is-id {_→′_ {n} p x} = cong (_→′_ p) (fmap-exp-id₂ f-is-id)
map-fmap-alt-id₂ f-is-id {esac} = refl
map-fmap-alt-id₂ f-is-id {x ∣ xs} = cong₂ _∣_ (fmap-alt-id₂ f-is-id) (map-fmap-alt-id₂ f-is-id)
fmap-exp-id₂ {r = Nullary} f-is-id {Var x} = refl
fmap-exp-id₂ {r = Unary r′} f-is-id {λ′ x} = cong λ′_ (fmap-exp-id₂ f-is-id)
fmap-exp-id₂ {r = Binary r₁ r₂} f-is-id {x · y} = cong₂ _·_ (fmap-exp-id₂ f-is-id)
(fmap-exp-id₂ f-is-id)
fmap-exp-id₂ {r = Binary r₁ r₂} f-is-id {let₁ x in′ y} = cong₂ let₁_in′_ (fmap-exp-id₂ f-is-id)
(fmap-exp-id₂ f-is-id)
fmap-exp-id₂ {r = Binary r₁ r₂} f-is-id {let₂ x ∷ τ in′ y} = cong₃ let₂_∷_in′_
(fmap-exp-id₂ f-is-id)
(Type-f.identity f-is-id)
(fmap-exp-id₂ f-is-id)
fmap-exp-id₂ {r = Binary r₁ r₂} f-is-id {let₃ n · x ∷ Q ⇒ τ in′ y}
= cong₄ (let₃_·_∷_⇒_in′_ n) (fmap-exp-id₂ (pn.identity f-is-id))
(QC-f.identity (pn.identity f-is-id))
(Type-f.identity (pn.identity f-is-id))
(fmap-exp-id₂ f-is-id)
where module pn = PlusN-f n
fmap-exp-id₂ {r = Binary r₁ r₂} f-is-id {case x of alts}
= cong₂ case_of_ (fmap-exp-id₂ f-is-id) (map-fmap-alt-id₂ f-is-id)
private
fmap-alt-comp₁ : {r : Shape} {A B C tv : Set} {f : A → B}{g : B → C} {x : Alternative A tv r}
→ fmap-alt₁ (g ∘ f) x ≡ fmap-alt₁ g (fmap-alt₁ f x)
fmap-exp-comp₁ : {r : Shape}{tv A B C : Set} {f : A → B} {g : B → C} {x : Expression A tv r}
→ fmap-exp₁ (g ∘ f) x ≡ fmap-exp₁ g (fmap-exp₁ f x)
map-fmap-alt-comp₁ : {r : Shape}{A B C tv : Set}{f : A → B}{g : B → C}{l : Alternatives A tv r}
→ map-fmap-alt₁ (g ∘ f) l ≡ map-fmap-alt₁ g (map-fmap-alt₁ f l)
fmap-alt-comp₁ {Nullary} {x = ()}
fmap-alt-comp₁ {Binary _ _}{x = ()}
fmap-alt-comp₁ {Unary r}{f = f}{g}{x = _→′_ {n} (DC p) expr}
= cong (_→′_ (DC p))
(combine-composite′ ⦃ Monad.is-functor (PlusN-is-monad {n}) ⦄ {expr}
fmap-exp₁
(fmap-exp-comp₁ {f = pn.map f}{g = pn.map g}{expr}))
where module pn = PlusN-f n
map-fmap-alt-comp₁ {l = esac} = refl
map-fmap-alt-comp₁ {Binary a b}{A}{B}{C}{tv}{l = x ∣ xs} = cong₂ _∣_ (fmap-alt-comp₁ {x = x}) (map-fmap-alt-comp₁)
fmap-exp-comp₁ {x = Var (N x)} = cong Var (cong N (refl))
fmap-exp-comp₁ {x = Var (DC x)} = refl
fmap-exp-comp₁ {f = f}{g}{x = λ′ x }
= cong λ′_ (combine-composite′ ⦃ Monad.is-functor (Ⓢ-is-monad) ⦄ {x}
fmap-exp₁
(fmap-exp-comp₁ {f = Ⓢ-f.map f}{g = Ⓢ-f.map g}{x}))
fmap-exp-comp₁ {f = f}{g}{x = x · y } = cong₂ _·_ (fmap-exp-comp₁ {f = f}{g}{x})
(fmap-exp-comp₁ {f = f}{g}{y})
fmap-exp-comp₁ {f = f}{g}{x = let₁ x in′ y }
= cong₂ let₁_in′_ (fmap-exp-comp₁ {f = f}{g}{x})
(combine-composite′ ⦃ Monad.is-functor (Ⓢ-is-monad) ⦄ {y}
fmap-exp₁
(fmap-exp-comp₁ {f = Ⓢ-f.map f}{g = Ⓢ-f.map g}{y}))
fmap-exp-comp₁ {f = f}{g}{x = let₂ x ∷ τ in′ y}
= cong₂ (λ a b → let₂ a ∷ τ in′ b) (fmap-exp-comp₁ {f = f}{g}{x})
(combine-composite′ ⦃ Monad.is-functor (Ⓢ-is-monad) ⦄ {y}
fmap-exp₁
(fmap-exp-comp₁ {f = Ⓢ-f.map f}
{g = Ⓢ-f.map g}{y}))
fmap-exp-comp₁ {f = f}{g}{x = let₃ n · x ∷ Q ⇒ τ in′ y}
= cong₂ (λ a b → let₃ n · a ∷ Q ⇒ τ in′ b)
(fmap-exp-comp₁ {f = f}{g}{x})
(combine-composite′ ⦃ Monad.is-functor (Ⓢ-is-monad) ⦄ {y}
fmap-exp₁
(fmap-exp-comp₁ {f = Ⓢ-f.map f}{g = Ⓢ-f.map g}{y}))
fmap-exp-comp₁ {f = f}{g}{x = case x of alts } = cong₂ case_of_
(fmap-exp-comp₁ {f = f}{g}{x})
map-fmap-alt-comp₁
private
fmap-alt-comp₂ : {A B C ev : Set}{r : Shape} {f : A → B} {g : B → C} {x : Alternative ev A r}
→ fmap-alt₂ (g ∘ f) x ≡ fmap-alt₂ g (fmap-alt₂ f x)
fmap-exp-comp₂ : {A B C ev : Set}{r : Shape} {f : A → B} {g : B → C} {x : Expression ev A r}
→ fmap-exp₂ (g ∘ f) x ≡ fmap-exp₂ g (fmap-exp₂ f x)
map-fmap-alt-comp₂ : ∀{r}{A B C ev : Set} {f : A → B} {g : B → C} {alts : Alternatives ev A r}
→ map-fmap-alt₂ (g ∘ f) alts ≡ map-fmap-alt₂ g (map-fmap-alt₂ f alts)
fmap-alt-comp₂ {x = _→′_ {n} p expr} = cong (_→′_ p) fmap-exp-comp₂
map-fmap-alt-comp₂ {alts = esac} = refl
map-fmap-alt-comp₂ {alts = x ∣ xs} = cong₂ _∣_ fmap-alt-comp₂ map-fmap-alt-comp₂
fmap-exp-comp₂ {x = Var a} = refl
fmap-exp-comp₂ {x = λ′ x } = cong λ′_ fmap-exp-comp₂
fmap-exp-comp₂ {x = x · y } = cong₂ _·_ fmap-exp-comp₂ fmap-exp-comp₂
fmap-exp-comp₂ {x = let₁ x in′ y } = cong₂ let₁_in′_ fmap-exp-comp₂ fmap-exp-comp₂
fmap-exp-comp₂ {x = let₂ x ∷ τ in′ y } = cong₃ let₂_∷_in′_ fmap-exp-comp₂ Type-f.composite fmap-exp-comp₂
fmap-exp-comp₂ {x = let₃ n · x ∷ Q ⇒ τ in′ y }
= cong₄ (λ a b c d → let₃ n · a ∷ b ⇒ c in′ d)
(combine-composite′ ⦃ pnf ⦄ fmap-exp₂ fmap-exp-comp₂)
(combine-composite ⦃ qconstraint-is-functor ⦄ ⦃ pnf ⦄)
(combine-composite ⦃ type-is-functor ⦄ ⦃ pnf ⦄)
fmap-exp-comp₂
where pnf = Monad.is-functor (PlusN-is-monad {n})
fmap-exp-comp₂ {x = case x of alts } = cong₂ case_of_ fmap-exp-comp₂ map-fmap-alt-comp₂
alternatives-is-functor₁ : ∀{tv}{r} → Functor (λ x → Alternatives x tv r)
alternatives-is-functor₁ = record { map = map-fmap-alt₁
; identity = map-fmap-alt-id₁
; composite = map-fmap-alt-comp₁
}
alternatives-is-functor₂ : ∀{ev}{r} → Functor (λ x → Alternatives ev x r)
alternatives-is-functor₂ = record { map = map-fmap-alt₂
; identity = map-fmap-alt-id₂
; composite = map-fmap-alt-comp₂
}
alternative-is-functor₁ : ∀{tv}{r} → Functor (λ x → Alternative x tv r)
alternative-is-functor₁ = record { map = fmap-alt₁
; identity = fmap-alt-id₁
; composite = λ { {x = x} → fmap-alt-comp₁ {x = x} }
}
alternative-is-functor₂ : ∀{ev}{r} → Functor (λ x → Alternative ev x r)
alternative-is-functor₂ = record { map = fmap-alt₂
; identity = fmap-alt-id₂
; composite = fmap-alt-comp₂
}
expression-is-functor₁ : ∀{tv}{r} → Functor (λ x → Expression x tv r)
expression-is-functor₁ {tv}{r} = record { map = fmap-exp₁
; identity = fmap-exp-id₁
; composite = λ {A}{B}{C}{f}{g}{x}
→ fmap-exp-comp₁ {r}{tv}{A}{B}{C}{f}{g}{x}
}
expression-is-functor₂ : ∀{ev}{r} → Functor (λ x → Expression ev x r)
expression-is-functor₂ = record { map = fmap-exp₂
; identity = fmap-exp-id₂
; composite = fmap-exp-comp₂
}
| 59.317269
| 118
| 0.466215
|
dc250396b149fee0aeb671fb6f0f386a732a8ac7
| 4,929
|
agda
|
Agda
|
src/Categories/Category/CartesianClosed/Locally.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 1
|
2021-04-18T18:21:47.000Z
|
2021-04-18T18:21:47.000Z
|
src/Categories/Category/CartesianClosed/Locally.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | null | null | null |
src/Categories/Category/CartesianClosed/Locally.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category.Core using (Category)
module Categories.Category.CartesianClosed.Locally {o ℓ e} (C : Category o ℓ e) where
open import Level using (levelOfTerm)
open import Categories.Category.CartesianClosed
open import Categories.Category.Cartesian
open import Categories.Category.Cartesian.Properties C
open import Categories.Category.Complete.Finitely C
open import Categories.Category.Slice C
open import Categories.Category.Slice.Properties C
open import Categories.Object.Product
open import Categories.Object.Exponential
open import Categories.Object.Terminal C
import Categories.Diagram.Pullback as P
import Categories.Diagram.Pullback.Properties C as Pₚ
import Categories.Morphism.Reasoning as MR
open Category C
record Locally : Set (levelOfTerm C) where
field
sliceCCC : ∀ A → CartesianClosed (Slice A)
-- only populate this module with some stuff, for space reasons
module sliceCCC A = CartesianClosed (sliceCCC A) using (product; products; exp)
pullbacks : ∀ {X A B} (f : A ⇒ X) (g : B ⇒ X) → P.Pullback C f g
pullbacks {X} _ _ = product⇒pullback (sliceCCC.product X)
-- the slice categories also have pullbacks, because slice of slice is slice.
slice-pullbacks : ∀ {A} {B X Y : SliceObj A} (f : Slice⇒ X B) (g : Slice⇒ Y B) → P.Pullback (Slice A) f g
slice-pullbacks {A} {B} {X} {Y} f g = record
{ P = sliceobj (X.arr ∘ p.p₁)
; p₁ = slicearr refl
; p₂ = slicearr comm
; isPullback = record
{ commute = p.commute
; universal = λ {Z} {h i} eq → slicearr {h = p.universal eq} (pullʳ p.p₁∘universal≈h₁ ○ Slice⇒.△ h)
; unique = λ eq₁ eq₂ → p.unique eq₁ eq₂
; p₁∘universal≈h₁ = p.p₁∘universal≈h₁
; p₂∘universal≈h₂ = p.p₂∘universal≈h₂
}
}
where open HomReasoning
open Equiv
module X = SliceObj X
module Y = SliceObj Y
module B = SliceObj B
module f = Slice⇒ f
module g = Slice⇒ g
module p = P.Pullback (pullbacks f.h g.h) using (p₁; p₂; commute; universal;
p₁∘universal≈h₁; p₂∘universal≈h₂; unique)
open MR C
comm : Y.arr ∘ p.p₂ ≈ X.arr ∘ p.p₁
comm = begin
Y.arr ∘ p.p₂ ≈˘⟨ g.△ ⟩∘⟨refl ⟩
(B.arr ∘ g.h) ∘ p.p₂ ≈˘⟨ pushʳ p.commute ⟩
B.arr ∘ f.h ∘ p.p₁ ≈⟨ pullˡ f.△ ⟩
X.arr ∘ p.p₁ ∎
module _ (LCCC : Locally) (t : Terminal) where
open Locally LCCC
open Terminal t
open HomReasoning
open Equiv
cartesian : Cartesian C
cartesian = record
{ terminal = t
; products = record { product = Pₚ.pullback-⊤⇒product t (product⇒pullback (sliceCCC.product ⊤)) }
}
cartesianClosed : CartesianClosed C
cartesianClosed = record
{ cartesian = cartesian
; exp = λ {A B} →
let open Exponential (exp {sliceobj (! {A})} {sliceobj (! {B})})
in record
{ B^A = Y B^A
; product =
-- this is tricky. how product is implemented requires special care. for example, the following
-- code also gives a product that type checks, but it is impossible to work with.
-- Pₚ.pullback-⊤⇒product t (Pₚ.pullback-resp-≈ (product⇒pullback product) !-unique₂ refl)
--
-- another quirk of proof relevance.
let open Product (Slice ⊤) (exp.product {sliceobj (! {A})} {sliceobj (! {B})})
in record
{ A×B = Y A×B
; π₁ = h π₁
; π₂ = h π₂
; ⟨_,_⟩ = λ f g → h ⟨ slicearr {h = f} (⟺ (!-unique _)) , slicearr {h = g} (⟺ (!-unique _)) ⟩
; project₁ = project₁
; project₂ = project₂
; unique = unique {h = slicearr (⟺ (!-unique _))}
}
; eval = h eval
; λg = λ {X} p f → h (λg (pullback⇒product′ t (Pₚ.product⇒pullback-⊤ t p)) (lift t f))
-- what looks like an identity proof below is not quite, as it is not
-- "proof relevant", the 2 underlying arrows contain different proofs.
; β = λ p → ∘-resp-≈ʳ (exp.product.⟨⟩-cong₂ refl refl) ○
β (pullback⇒product′ t (Pₚ.product⇒pullback-⊤ t p))
; λ-unique = λ p eq → λ-unique (pullback⇒product′ t (Pₚ.product⇒pullback-⊤ t p))
{h = slicearr (⟺ (!-unique _))}
(∘-resp-≈ʳ (exp.product.⟨⟩-cong₂ refl refl) ○ eq)
}
}
where open sliceCCC ⊤ using (exp)
open SliceObj
open Slice⇒
finitelyComplete : FinitelyComplete
finitelyComplete = record
{ cartesian = cartesian
; equalizer = λ f g → prods×pullbacks⇒equalizers (Cartesian.products cartesian)
(λ {_ _ X} h i → product⇒pullback (sliceCCC.product X))
}
| 40.073171
| 111
| 0.573139
|
123c0ad00c7eca54f9ad055ba6cb39860ce69eca
| 355
|
agda
|
Agda
|
test/Fail/Issue1652.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1652.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1652.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{- reported by Guillaume Brunerie on 2015-09-17 -}
{-# OPTIONS --rewriting #-}
data _==_ {A : Set} (a : A) : A → Set where
idp : a == a
{-# BUILTIN REWRITE _==_ #-}
postulate
A B : Set
f g : A → B
module M (x : A) where
postulate
rx : f x == g x
{-# REWRITE rx #-}
-- This shouldn't work
test : (y : A) → f y == g y
test y = idp
| 16.136364
| 50
| 0.521127
|
a14c5e4f4738a772a40baac94b0d98e05e90fc62
| 2,833
|
agda
|
Agda
|
src/Prelude/String.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Prelude/String.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Prelude/String.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Prelude.String where
open import Agda.Primitive
open import Prelude.Unit
open import Prelude.Char
open import Prelude.Bool
open import Prelude.Nat
open import Prelude.List
open import Prelude.Maybe
open import Prelude.Equality
open import Prelude.Equality.Unsafe
open import Prelude.Decidable
open import Prelude.Ord
open import Prelude.Function
open import Prelude.Monad
open import Prelude.Semiring
open import Agda.Builtin.String public
open import Agda.Builtin.FromString public
unpackString = primStringToList
packString = primStringFromList
unpackString-inj : ∀ {x y} → unpackString x ≡ unpackString y → x ≡ y
unpackString-inj {x} p with unpackString x
unpackString-inj refl | ._ = unsafeEqual
infixr 5 _&_
_&_ = primStringAppend
-- Eq --
instance
EqString : Eq String
_==_ {{EqString}} x y with primStringEquality x y
... | true = yes unsafeEqual
... | false = no unsafeNotEqual
-- Ord --
instance
OrdString : Ord String
OrdString = OrdBy unpackString-inj
OrdLawsString : Ord/Laws String
OrdLawsString = OrdLawsBy unpackString-inj
-- Overloaded literals --
instance
StringIsString : IsString String
IsString.Constraint StringIsString _ = ⊤
IsString.fromString StringIsString s = s
ListIsString : IsString (List Char)
IsString.Constraint ListIsString _ = ⊤
IsString.fromString ListIsString s = unpackString s
-- Monoid --
instance
open import Prelude.Monoid
SemigroupString : Semigroup String
_<>_ {{SemigroupString}} = primStringAppend
MonoidString : Monoid String
Monoid.super MonoidString = it
mempty {{MonoidString}} = ""
-- More functions --
parseNat : String → Maybe Nat
parseNat = parseNat′ ∘ unpackString
where
pDigit : Char → Maybe Nat
pDigit c =
if isDigit c then just (charToNat c - charToNat '0')
else nothing
pNat : Nat → List Char → Maybe Nat
pNat n [] = just n
pNat n (c ∷ s) = pDigit c >>= λ d → pNat (n * 10 + d) s
parseNat′ : List Char → Maybe Nat
parseNat′ [] = nothing
parseNat′ (c ∷ s) = pDigit c >>= λ d → pNat d s
onChars : (List Char → List Char) → String → String
onChars f = packString ∘ f ∘ unpackString
words : String → List String
words = map packString ∘ wordsBy isSpace ∘ unpackString
ltrim : String → String
ltrim = onChars (dropWhile isSpace)
rtrim : String → String
rtrim = onChars (reverse ∘ dropWhile isSpace ∘ reverse)
trim : String → String
trim = rtrim ∘ ltrim
strTake : Nat → String → String
strTake n = onChars (take n)
strDrop : Nat → String → String
strDrop n = onChars (drop n)
strLength : String → Nat
strLength = length ∘ unpackString
strIsPrefixOf? : String → String → Bool
strIsPrefixOf? = isPrefixOf? on unpackString
strCommonPrefix : String → String → String
strCommonPrefix s₁ s₂ = packString $ (commonPrefix! on unpackString) s₁ s₂
| 24.008475
| 74
| 0.719732
|
59b92e652db9b66bae3a455a577523fafda9c046
| 3,242
|
agda
|
Agda
|
Cubical/HITs/FreeComMonoids/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/HITs/FreeComMonoids/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/HITs/FreeComMonoids/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.HITs.FreeComMonoids.Properties where
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.GroupoidLaws hiding (assoc)
open import Cubical.Foundations.Univalence
open import Cubical.Data.Nat hiding (_·_ ; _^_)
open import Cubical.HITs.FreeComMonoids.Base as FCM
open import Cubical.HITs.AssocList as AL
private variable
ℓ : Level
A : Type ℓ
multi-· : A → ℕ → FreeComMonoid A → FreeComMonoid A
multi-· x zero xs = xs
multi-· x (suc n) xs = ⟦ x ⟧ · multi-· x n xs
_^_ : A → ℕ → FreeComMonoid A
x ^ n = multi-· x n ε
^+≡ : ∀ (p : A) m n → ((p ^ m) · (p ^ n)) ≡ (p ^ (m + n))
^+≡ p zero n = identityₗ _
^+≡ p (suc m) n = sym (assoc _ _ _) ∙ cong (_ ·_) (^+≡ _ _ _)
AL→FCM : AssocList A → FreeComMonoid A
AL→FCM = AL.Rec.f trunc ε (λ a n p → (a ^ n) · p)
per* agg* (const identityₗ)
where
per* : ∀ x y (mon : FreeComMonoid A) →
((⟦ x ⟧ · ε) · ((⟦ y ⟧ · ε) · mon)) ≡
((⟦ y ⟧ · ε) · ((⟦ x ⟧ · ε) · mon))
per* x y mon =
(⟦ x ⟧ · ε) · ((⟦ y ⟧ · ε) · mon)
≡⟨ assoc _ _ _ ⟩
((⟦ x ⟧ · ε) · (⟦ y ⟧ · ε)) · mon
≡⟨ cong (_· mon) (comm _ _) ⟩
(((⟦ y ⟧ · ε) · (⟦ x ⟧ · ε)) · mon)
≡⟨ sym (assoc _ _ _) ⟩
((⟦ y ⟧ · ε) · ((⟦ x ⟧ · ε) · mon)) ∎
agg* : ∀ a m n mon →
((a ^ m) · ((a ^ n) · mon)) ≡ ((a ^ (m + n)) · mon)
agg* a m n mon =
((a ^ m) · ((a ^ n) · mon))
≡⟨ assoc _ _ _ ⟩
(((a ^ m) · (a ^ n)) · mon)
≡⟨ cong (_· _) (^+≡ _ _ _) ⟩
((a ^ (m + n)) · mon) ∎
FCM→AL : FreeComMonoid A → AssocList A
FCM→AL = FCM.Rec.f trunc ⟨_⟩ ⟨⟩ _++_ comm-++ unitr-++ (λ _ → refl) assoc-++
^-id : (x : A) (m : ℕ) (u : FreeComMonoid A)
→ FCM→AL ((x ^ m) · u) ≡ ⟨ x , m ⟩∷ FCM→AL u
^-id x zero u = cong FCM→AL (identityₗ u) ∙ sym (del _ _)
^-id x (suc m) u =
FCM→AL ((⟦ x ⟧ · (x ^ m)) · u)
≡⟨ cong ⟨ x , 1 ⟩∷_ (^-id x m u) ⟩
⟨ x , 1 ⟩∷ ⟨ x , m ⟩∷ FCM→AL u
≡⟨ agg _ _ _ _ ⟩
⟨ x , suc m ⟩∷ FCM→AL u ∎
++-· : (x y : AssocList A)
→ AL→FCM (x ++ y) ≡ AL→FCM x · AL→FCM y
++-· = AL.ElimProp.f
(isPropΠ (λ _ → trunc _ _))
(λ _ → sym (identityₗ _))
λ x n {xs} p ys →
AL→FCM (((⟨ x , n ⟩∷ ⟨⟩) ++ xs) ++ ys)
≡⟨ cong AL→FCM (cong (_++ ys) (comm-++ (⟨ x , n ⟩∷ ⟨⟩) xs) ∙ sym (assoc-++ xs _ ys)) ⟩
AL→FCM (xs ++ (⟨ x , n ⟩∷ ys))
≡⟨ p _ ⟩
(AL→FCM xs · ((x ^ n) · AL→FCM ys))
≡⟨ assoc (AL→FCM xs) _ _ ⟩
((AL→FCM xs · (x ^ n)) · AL→FCM ys)
≡⟨ cong (_· AL→FCM ys) (comm _ _) ⟩
((x ^ n) · AL→FCM xs) · AL→FCM ys ∎
AL→FCM∘FCM→AL≡id : section {A = AssocList A} AL→FCM FCM→AL
AL→FCM∘FCM→AL≡id = FCM.ElimProp.f (trunc _ _) (λ x → identityᵣ _ ∙ identityᵣ _) refl
λ {x y} p q → ++-· (FCM→AL x) (FCM→AL y) ∙ cong₂ _·_ p q
FCM→AL∘AL→FCM≡id : retract {A = AssocList A} AL→FCM FCM→AL
FCM→AL∘AL→FCM≡id = AL.ElimProp.f (trunc _ _) refl
λ x n {xs} p → ^-id x n (AL→FCM xs) ∙ cong (⟨ _ , _ ⟩∷_) p
AssocList≃FreeComMonoid : AssocList A ≃ FreeComMonoid A
AssocList≃FreeComMonoid = isoToEquiv (iso AL→FCM FCM→AL AL→FCM∘FCM→AL≡id FCM→AL∘AL→FCM≡id)
AssocList≡FreeComMonoid : AssocList A ≡ FreeComMonoid A
AssocList≡FreeComMonoid = ua AssocList≃FreeComMonoid
| 31.784314
| 90
| 0.528994
|
2e0071bcacc977ad43d71862116b744dd5f7d0ff
| 984
|
agda
|
Agda
|
test/Succeed/Issue701-c.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue701-c.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue701-c.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas 2012-09-27, reported by Fredrik Forsberg
{-# OPTIONS --sized-types #-}
module Issue701-c where
open import Common.Size
{- If I understand correctly, unconstrained sizes should be resolved to \infty.
If I define -}
data U : {i : Size} -> Set where
c : {i : Size} -> U {↑ i}
data V : {i : Size} -> Set where
d : {i : Size} -> U {∞} -> V {↑ i}
works-with-explicit-infty : {i : Size} -> V {i} -> V {↑ i}
works-with-explicit-infty x = x
-- everything is fine. However, if I leave out {\infty}:
data V' : {i : Size} -> Set where
d : {i : Size} -> U -> V' {↑ i}
fails-if-no-infty : {i : Size} -> V' {i} -> V' {↑ i}
fails-if-no-infty x = x
--.i != ↑ .i of type Size
--when checking that the expression x has type V'
{- V' is not detected as a sized type anymore which seems to break the
promise about unconstrained sizes. Since U is just a non-inductive
argument to d, I wouldn't expect it to influence whether V is a sized
type or not? -}
| 29.818182
| 79
| 0.612805
|
1aab2919fe39b56e402401970a87216a05a86d19
| 140
|
agda
|
Agda
|
Cubical/HITs/Ints/IsoInt.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/IsoInt.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/Ints/IsoInt.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.IsoInt where
open import Cubical.HITs.Ints.IsoInt.Base public
| 23.333333
| 50
| 0.742857
|
31b43cb0999df2a176abfe86d0a48e71707942ca
| 4,823
|
agda
|
Agda
|
Definition/Conversion.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 30
|
2017-05-20T03:05:21.000Z
|
2022-03-30T18:01:07.000Z
|
Definition/Conversion.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 4
|
2017-06-22T12:49:23.000Z
|
2021-02-22T10:37:24.000Z
|
Definition/Conversion.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 8
|
2017-10-18T14:18:20.000Z
|
2021-11-27T15:58:33.000Z
|
-- Algorithmic equality.
{-# OPTIONS --without-K --safe #-}
module Definition.Conversion where
open import Definition.Untyped hiding (_∷_)
open import Definition.Typed
open import Tools.Fin
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
infix 10 _⊢_~_↑_
infix 10 _⊢_~_↓_
infix 10 _⊢_[conv↑]_
infix 10 _⊢_[conv↓]_
infix 10 _⊢_[conv↑]_∷_
infix 10 _⊢_[conv↓]_∷_
private
variable
n : Nat
Γ : Con Term n
mutual
-- Neutral equality.
data _⊢_~_↑_ (Γ : Con Term n) : (k l A : Term n) → Set where
var-refl : ∀ {x y A}
→ Γ ⊢ var x ∷ A
→ x PE.≡ y
→ Γ ⊢ var x ~ var y ↑ A
app-cong : ∀ {k l t v F G}
→ Γ ⊢ k ~ l ↓ Π F ▹ G
→ Γ ⊢ t [conv↑] v ∷ F
→ Γ ⊢ k ∘ t ~ l ∘ v ↑ G [ t ]
fst-cong : ∀ {p r F G}
→ Γ ⊢ p ~ r ↓ Σ F ▹ G
→ Γ ⊢ fst p ~ fst r ↑ F
snd-cong : ∀ {p r F G}
→ Γ ⊢ p ~ r ↓ Σ F ▹ G
→ Γ ⊢ snd p ~ snd r ↑ G [ fst p ]
natrec-cong : ∀ {k l h g a₀ b₀ F G}
→ Γ ∙ ℕ ⊢ F [conv↑] G
→ Γ ⊢ a₀ [conv↑] b₀ ∷ F [ zero ]
→ Γ ⊢ h [conv↑] g ∷ Π ℕ ▹ (F ▹▹ F [ suc (var x0) ]↑)
→ Γ ⊢ k ~ l ↓ ℕ
→ Γ ⊢ natrec F a₀ h k ~ natrec G b₀ g l ↑ F [ k ]
Emptyrec-cong : ∀ {k l F G}
→ Γ ⊢ F [conv↑] G
→ Γ ⊢ k ~ l ↓ Empty
→ Γ ⊢ Emptyrec F k ~ Emptyrec G l ↑ F
-- Neutral equality with types in WHNF.
record _⊢_~_↓_ (Γ : Con Term n) (k l B : Term n) : Set where
inductive
constructor [~]
field
A : Term n
D : Γ ⊢ A ⇒* B
whnfB : Whnf B
k~l : Γ ⊢ k ~ l ↑ A
-- Type equality.
record _⊢_[conv↑]_ (Γ : Con Term n) (A B : Term n) : Set where
inductive
constructor [↑]
field
A′ B′ : Term n
D : Γ ⊢ A ⇒* A′
D′ : Γ ⊢ B ⇒* B′
whnfA′ : Whnf A′
whnfB′ : Whnf B′
A′<>B′ : Γ ⊢ A′ [conv↓] B′
-- Type equality with types in WHNF.
data _⊢_[conv↓]_ (Γ : Con Term n) : (A B : Term n) → Set where
U-refl : ⊢ Γ → Γ ⊢ U [conv↓] U
ℕ-refl : ⊢ Γ → Γ ⊢ ℕ [conv↓] ℕ
Empty-refl : ⊢ Γ → Γ ⊢ Empty [conv↓] Empty
Unit-refl : ⊢ Γ → Γ ⊢ Unit [conv↓] Unit
ne : ∀ {K L}
→ Γ ⊢ K ~ L ↓ U
→ Γ ⊢ K [conv↓] L
Π-cong : ∀ {F G H E}
→ Γ ⊢ F
→ Γ ⊢ F [conv↑] H
→ Γ ∙ F ⊢ G [conv↑] E
→ Γ ⊢ Π F ▹ G [conv↓] Π H ▹ E
Σ-cong : ∀ {F G H E}
→ Γ ⊢ F
→ Γ ⊢ F [conv↑] H
→ Γ ∙ F ⊢ G [conv↑] E
→ Γ ⊢ Σ F ▹ G [conv↓] Σ H ▹ E
-- Term equality.
record _⊢_[conv↑]_∷_ (Γ : Con Term n) (t u A : Term n) : Set where
inductive
constructor [↑]ₜ
field
B t′ u′ : Term n
D : Γ ⊢ A ⇒* B
d : Γ ⊢ t ⇒* t′ ∷ B
d′ : Γ ⊢ u ⇒* u′ ∷ B
whnfB : Whnf B
whnft′ : Whnf t′
whnfu′ : Whnf u′
t<>u : Γ ⊢ t′ [conv↓] u′ ∷ B
-- Term equality with types and terms in WHNF.
data _⊢_[conv↓]_∷_ (Γ : Con Term n) : (t u A : Term n) → Set where
ℕ-ins : ∀ {k l}
→ Γ ⊢ k ~ l ↓ ℕ
→ Γ ⊢ k [conv↓] l ∷ ℕ
Empty-ins : ∀ {k l}
→ Γ ⊢ k ~ l ↓ Empty
→ Γ ⊢ k [conv↓] l ∷ Empty
Unit-ins : ∀ {k l}
→ Γ ⊢ k ~ l ↓ Unit
→ Γ ⊢ k [conv↓] l ∷ Unit
ne-ins : ∀ {k l M N}
→ Γ ⊢ k ∷ N
→ Γ ⊢ l ∷ N
→ Neutral N
→ Γ ⊢ k ~ l ↓ M
→ Γ ⊢ k [conv↓] l ∷ N
univ : ∀ {A B}
→ Γ ⊢ A ∷ U
→ Γ ⊢ B ∷ U
→ Γ ⊢ A [conv↓] B
→ Γ ⊢ A [conv↓] B ∷ U
zero-refl : ⊢ Γ → Γ ⊢ zero [conv↓] zero ∷ ℕ
suc-cong : ∀ {m n}
→ Γ ⊢ m [conv↑] n ∷ ℕ
→ Γ ⊢ suc m [conv↓] suc n ∷ ℕ
η-eq : ∀ {f g F G}
→ Γ ⊢ f ∷ Π F ▹ G
→ Γ ⊢ g ∷ Π F ▹ G
→ Function f
→ Function g
→ Γ ∙ F ⊢ wk1 f ∘ var x0 [conv↑] wk1 g ∘ var x0 ∷ G
→ Γ ⊢ f [conv↓] g ∷ Π F ▹ G
Σ-η : ∀ {p r F G}
→ Γ ⊢ p ∷ Σ F ▹ G
→ Γ ⊢ r ∷ Σ F ▹ G
→ Product p
→ Product r
→ Γ ⊢ fst p [conv↑] fst r ∷ F
→ Γ ⊢ snd p [conv↑] snd r ∷ G [ fst p ]
→ Γ ⊢ p [conv↓] r ∷ Σ F ▹ G
η-unit : ∀ {k l}
→ Γ ⊢ k ∷ Unit
→ Γ ⊢ l ∷ Unit
→ Whnf k
→ Whnf l
→ Γ ⊢ k [conv↓] l ∷ Unit
star-refl : ⊢ Γ → Γ ⊢ star [conv↓] star ∷ Unit
star-refl ⊢Γ = η-unit (starⱼ ⊢Γ) (starⱼ ⊢Γ) starₙ starₙ
| 29.771605
| 70
| 0.364089
|
1a9822574d16ee2584b0d476f83d60b10c660eea
| 4,983
|
agda
|
Agda
|
LibraBFT/Abstract/Properties.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Abstract/Properties.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Abstract/Properties.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Abstract.Types
open import LibraBFT.Abstract.Types.EpochConfig
open import LibraBFT.Lemmas
open import LibraBFT.Prelude
open WithAbsVote
-- For each desired property (VotesOnce and PreferredRoundRule), we have a
-- module containing a Type that defines a property that an implementation
-- should prove, and a proof that it implies the corresponding rule used by
-- the abstract proofs. Then, we use those proofs to instantiate thmS5,
-- and the use thmS5 to prove a number of correctness conditions.
--
-- TODO-1: refactor this file to separate the definitions and proofs of
-- VotesOnce and PreferredRoundRule from their use in proving the correctness
-- properties.
module LibraBFT.Abstract.Properties
(UID : Set)
(_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁))
(NodeId : Set)
(𝓔 : EpochConfig UID NodeId)
(𝓥 : VoteEvidence UID NodeId 𝓔)
where
open import LibraBFT.Abstract.Records UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.Records.Extends UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.RecordChain UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.RecordChain.Assumptions UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.System UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.RecordChain.Properties UID _≟UID_ NodeId 𝓔 𝓥
open EpochConfig 𝓔
module WithAssumptions {ℓ}
(InSys : Record → Set ℓ)
(no-collisions-InSys : NoCollisions InSys)
(votes-once : VotesOnlyOnceRule InSys)
(preferred-round : PreferredRoundRule InSys)
where
open All-InSys-props InSys
CommitsDoNotConflict : ∀{q q'}
→ {rc : RecordChain (Q q)} → All-InSys rc
→ {rc' : RecordChain (Q q')} → All-InSys rc'
→ {b b' : Block}
→ CommitRule rc b
→ CommitRule rc' b'
→ (B b) ∈RC rc' ⊎ (B b') ∈RC rc
CommitsDoNotConflict ais ais' cr cr'
with WithInvariants.thmS5 InSys votes-once preferred-round ais ais' cr cr'
-- We use the implementation-provided evidence that Block ids are injective among
-- Block actually in the system to dismiss the first possibility
...| inj₁ ((_ , neq , h≡) , (is1 , is2)) = ⊥-elim (neq (no-collisions-InSys is1 is2 h≡))
...| inj₂ corr = corr
-- When we are dealing with a /Complete/ InSys predicate, we can go a few steps
-- further and prove that commits do not conflict even if we have only partial
-- knowledge about Records represented in the system.
module _ (∈QC⇒AllSent : Complete InSys) where
-- For a /complete/ system (i.e., one in which peers vote for a Block only if
-- they know of a RecordChain up to that Block whose Records are all InSys), we
-- can prove that CommitRules based on RecordChainFroms similarly do not
-- conflict, provided all of the Records in the RecordChainFroms are InSys.
-- This enables peers not participating in consensus to confirm commits even if
-- they are sent only a "commit certificate" that contains enough of a
-- RecordChain to confirm the CommitRule. Note that it is this "sending" that
-- justfies the assumption that the RecordChainFroms on which the CommitRules
-- are based are All-InSys.
CommitsDoNotConflict'
: ∀{o o' q q'}
→ {rcf : RecordChainFrom o (Q q)} → All-InSys rcf
→ {rcf' : RecordChainFrom o' (Q q')} → All-InSys rcf'
→ {b b' : Block}
→ CommitRuleFrom rcf b
→ CommitRuleFrom rcf' b'
→ Σ (RecordChain (Q q')) ((B b) ∈RC_)
⊎ Σ (RecordChain (Q q)) ((B b') ∈RC_)
CommitsDoNotConflict' {cb} {q = q} {q'} {rcf} rcfAll∈sys {rcf'} rcf'All∈sys crf crf'
with bft-property (qVotes-C1 q) (qVotes-C1 q')
...| α , α∈qmem , α∈q'mem , hα
with Any-sym (Any-map⁻ α∈qmem) | Any-sym (Any-map⁻ α∈q'mem)
...| α∈q | α∈q'
with ∈QC⇒AllSent {q = q} hα α∈q (rcfAll∈sys here) | ∈QC⇒AllSent {q = q'} hα α∈q' (rcf'All∈sys here)
...| ab , (arc , ais) , ab←q | ab' , (arc' , ais') , ab←q'
with crf⇒cr rcf (step arc ab←q) crf | crf⇒cr rcf' (step arc' ab←q') crf'
...| inj₁ ((_ , neq , h≡) , (is1 , is2)) | _ = ⊥-elim (neq (no-collisions-InSys (rcfAll∈sys is1) (ais (∈RC-simple-¬here arc ab←q (λ ()) is2)) h≡))
...| inj₂ _ | inj₁ ((_ , neq , h≡) , (is1 , is2)) = ⊥-elim (neq (no-collisions-InSys (rcf'All∈sys is1) (ais' (∈RC-simple-¬here arc' ab←q' (λ ()) is2)) h≡))
...| inj₂ cr | inj₂ cr'
with CommitsDoNotConflict (All-InSys-step ais ab←q (rcfAll∈sys here)) (All-InSys-step ais' ab←q' (rcf'All∈sys here)) cr cr'
...| inj₁ b∈arc' = inj₁ (step arc' ab←q' , b∈arc')
...| inj₂ b'∈arc = inj₂ (step arc ab←q , b'∈arc)
| 50.333333
| 174
| 0.643388
|
c5e9d4b4bdce777d289c8df7c666a0d1072ac021
| 6,659
|
agda
|
Agda
|
Cubical/Relation/Binary/Base.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Base.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Base.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.HITs.SetQuotients.Base
open import Cubical.HITs.PropositionalTruncation.Base
open import Cubical.Foundations.Equiv.Fiberwise
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
private
variable
ℓA ℓA' ℓ ℓ' ℓ≅A ℓ≅A' ℓB : Level
-- Rel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
-- Rel A B ℓ' = A → B → Type ℓ'
Rel : (A : Type ℓA) (B : Type ℓB) (ℓ : Level) → Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℓA ℓB))
Rel A B ℓ = A → B → Type ℓ
PropRel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
PropRel A B ℓ' = Σ[ R ∈ Rel A B ℓ' ] ∀ a b → isProp (R a b)
idPropRel : ∀ {ℓ} (A : Type ℓ) → PropRel A A ℓ
idPropRel A .fst a a' = ∥ a ≡ a' ∥
idPropRel A .snd _ _ = squash
invPropRel : ∀ {ℓ ℓ'} {A B : Type ℓ}
→ PropRel A B ℓ' → PropRel B A ℓ'
invPropRel R .fst b a = R .fst a b
invPropRel R .snd b a = R .snd a b
compPropRel : ∀ {ℓ ℓ' ℓ''} {A B C : Type ℓ}
→ PropRel A B ℓ' → PropRel B C ℓ'' → PropRel A C (ℓ-max ℓ (ℓ-max ℓ' ℓ''))
compPropRel R S .fst a c = ∥ Σ[ b ∈ _ ] (R .fst a b × S .fst b c) ∥
compPropRel R S .snd _ _ = squash
graphRel : ∀ {ℓ} {A B : Type ℓ} → (A → B) → Rel A B ℓ
graphRel f a b = f a ≡ b
module _ {ℓ ℓ' : Level} {A : Type ℓ} (_R_ : Rel A A ℓ') where
-- R is reflexive
isRefl : Type (ℓ-max ℓ ℓ')
isRefl = (a : A) → a R a
-- R is symmetric
isSym : Type (ℓ-max ℓ ℓ')
isSym = (a b : A) → a R b → b R a
-- R is transitive
isTrans : Type (ℓ-max ℓ ℓ')
isTrans = (a b c : A) → a R b → b R c → a R c
record isEquivRel : Type (ℓ-max ℓ ℓ') where
constructor equivRel
field
reflexive : isRefl
symmetric : isSym
transitive : isTrans
isPropValued : Type (ℓ-max ℓ ℓ')
isPropValued = (a b : A) → isProp (a R b)
isEffective : Type (ℓ-max ℓ ℓ')
isEffective =
(a b : A) → isEquiv (eq/ {R = _R_} a b)
-- the total space corresponding to the binary relation w.r.t. a
relSinglAt : (a : A) → Type (ℓ-max ℓ ℓ')
relSinglAt a = Σ[ a' ∈ A ] (a R a')
-- the statement that the total space is contractible at any a
contrRelSingl : Type (ℓ-max ℓ ℓ')
contrRelSingl = (a : A) → isContr (relSinglAt a)
-- assume a reflexive binary relation
module _ (ρ : isRefl) where
-- identity is the least reflexive relation
≡→R : {a a' : A} → a ≡ a' → a R a'
-- ≡→R {a} {a'} p = subst (λ z → a R z) p (ρ a)
≡→R {a} {a'} p = J (λ z q → a R z) (ρ a) p
-- what it means for a reflexive binary relation to be univalent
isUnivalent : Type (ℓ-max ℓ ℓ')
isUnivalent = (a a' : A) → isEquiv (≡→R {a} {a'})
-- helpers for contrRelSingl→isUnivalent
private
module _ (a : A) where
-- wrapper for ≡→R
f = λ (a' : A) (p : a ≡ a') → ≡→R {a} {a'} p
-- the corresponding total map that univalence
-- of R will be reduced to
totf : singl a → Σ[ a' ∈ A ] (a R a')
totf (a' , p) = (a' , f a' p)
-- if the total space corresponding to R is contractible
-- then R is univalent
-- because the singleton at a is also contractible
contrRelSingl→isUnivalent : contrRelSingl → isUnivalent
contrRelSingl→isUnivalent c a = q
where
abstract
q = fiberEquiv (λ a' → a ≡ a')
(λ a' → a R a')
(f a)
(snd (propBiimpl→Equiv (isContr→isProp (isContrSingl a))
(isContr→isProp (c a))
(totf a)
(λ _ → fst (isContrSingl a))))
-- converse map. proof idea:
-- equivalences preserve contractability,
-- singletons are contractible
-- and by the univalence assumption the total map is an equivalence
isUnivalent→contrRelSingl : isUnivalent → contrRelSingl
isUnivalent→contrRelSingl u a = q
where
abstract
q = isContrRespectEquiv
(totf a , totalEquiv (a ≡_)
(a R_)
(f a)
λ a' → u a a')
(isContrSingl a)
isUnivalent' : Type (ℓ-max ℓ ℓ')
isUnivalent' = (a a' : A) → (a ≡ a') ≃ a R a'
private
module _ (e : isUnivalent') (a : A) where
-- wrapper for ≡→R
g = λ (a' : A) (p : a ≡ a') → e a a' .fst p
-- the corresponding total map that univalence
-- of R will be reduced to
totg : singl a → Σ[ a' ∈ A ] (a R a')
totg (a' , p) = (a' , g a' p)
isUnivalent'→contrRelSingl : isUnivalent' → contrRelSingl
isUnivalent'→contrRelSingl u a = q
where
abstract
q = isContrRespectEquiv
(totg u a , totalEquiv (a ≡_) (a R_) (g u a) λ a' → u a a' .snd)
(isContrSingl a)
isUnivalent'→isUnivalent : isUnivalent' → isUnivalent
isUnivalent'→isUnivalent u = contrRelSingl→isUnivalent (isUnivalent'→contrRelSingl u)
isUnivalent→isUnivalent' : isUnivalent → isUnivalent'
isUnivalent→isUnivalent' u a a' = ≡→R {a} {a'} , u a a'
record RelIso {A : Type ℓA} (_≅_ : Rel A A ℓ≅A)
{A' : Type ℓA'} (_≅'_ : Rel A' A' ℓ≅A') : Type (ℓ-max (ℓ-max ℓA ℓA') (ℓ-max ℓ≅A ℓ≅A')) where
constructor reliso
field
fun : A → A'
inv : A' → A
rightInv : (a' : A') → fun (inv a') ≅' a'
leftInv : (a : A) → inv (fun a) ≅ a
RelIso→Iso : {A : Type ℓA} {A' : Type ℓA'}
(_≅_ : Rel A A ℓ≅A) (_≅'_ : Rel A' A' ℓ≅A')
{ρ : isRefl _≅_} {ρ' : isRefl _≅'_}
(uni : isUnivalent _≅_ ρ) (uni' : isUnivalent _≅'_ ρ')
(f : RelIso _≅_ _≅'_)
→ Iso A A'
Iso.fun (RelIso→Iso _ _ _ _ f) = RelIso.fun f
Iso.inv (RelIso→Iso _ _ _ _ f) = RelIso.inv f
Iso.rightInv (RelIso→Iso _ _≅'_ {ρ' = ρ'} _ uni' f) a'
= invEquiv (≡→R _≅'_ ρ' , uni' (RelIso.fun f (RelIso.inv f a')) a') .fst (RelIso.rightInv f a')
Iso.leftInv (RelIso→Iso _≅_ _ {ρ = ρ} uni _ f) a
= invEquiv (≡→R _≅_ ρ , uni (RelIso.inv f (RelIso.fun f a)) a) .fst (RelIso.leftInv f a)
EquivRel : ∀ {ℓ} (A : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
EquivRel A ℓ' = Σ[ R ∈ Rel A A ℓ' ] isEquivRel R
EquivPropRel : ∀ {ℓ} (A : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
EquivPropRel A ℓ' = Σ[ R ∈ PropRel A A ℓ' ] isEquivRel (R .fst)
| 35.047368
| 106
| 0.533113
|
22a89f05142f5e36c4eabccf0a771db34960c2cc
| 3,271
|
agda
|
Agda
|
examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Vec.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Vec.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Vec.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module Data.Vec where
open import Prelude
open import Data.Nat
open import Data.Fin hiding (_==_; _<_)
open import Logic.Structure.Applicative
open import Logic.Identity
open import Logic.Base
infixl 90 _#_
infixr 50 _::_
infixl 45 _!_ _[!]_
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
-- Indexing
_!_ : {n : Nat}{A : Set} -> Vec A n -> Fin n -> A
x :: xs ! fzero = x
x :: xs ! fsuc i = xs ! i
-- Insertion
insert : {n : Nat}{A : Set} -> Fin (suc n) -> A -> Vec A n -> Vec A (suc n)
insert fzero y xs = y :: xs
insert (fsuc i) y (x :: xs) = x :: insert i y xs
-- Index view
data IndexView {A : Set} : {n : Nat}(i : Fin n) -> Vec A n -> Set where
ixV : {n : Nat}{i : Fin (suc n)}(x : A)(xs : Vec A n) ->
IndexView i (insert i x xs)
_[!]_ : {A : Set}{n : Nat}(xs : Vec A n)(i : Fin n) -> IndexView i xs
x :: xs [!] fzero = ixV x xs
x :: xs [!] fsuc i = aux xs i (xs [!] i)
where
aux : {n : Nat}(xs : Vec _ n)(i : Fin n) ->
IndexView i xs -> IndexView (fsuc i) (x :: xs)
aux .(insert i y xs) i (ixV y xs) = ixV y (x :: xs)
-- Build a vector from an indexing function (inverse of _!_)
build : {n : Nat}{A : Set} -> (Fin n -> A) -> Vec A n
build {zero } f = []
build {suc _} f = f fzero :: build (f ∘ fsuc)
-- Constant vectors
vec : {n : Nat}{A : Set} -> A -> Vec A n
vec {zero } _ = []
vec {suc m} x = x :: vec x
-- Vector application
_#_ : {n : Nat}{A B : Set} -> Vec (A -> B) n -> Vec A n -> Vec B n
[] # [] = []
(f :: fs) # (x :: xs) = f x :: fs # xs
-- Vectors of length n form an applicative structure
ApplicativeVec : {n : Nat} -> Applicative (\A -> Vec A n)
ApplicativeVec {n} = applicative (vec {n}) (_#_ {n})
-- Map
map : {n : Nat}{A B : Set} -> (A -> B) -> Vec A n -> Vec B n
map f xs = vec f # xs
-- Zip
zip : {n : Nat}{A B C : Set} -> (A -> B -> C) -> Vec A n -> Vec B n -> Vec C n
zip f xs ys = vec f # xs # ys
module Elem where
infix 40 _∈_ _∉_
data _∈_ {A : Set}(x : A) : {n : Nat}(xs : Vec A n) -> Set where
hd : {n : Nat} {xs : Vec A n} -> x ∈ x :: xs
tl : {n : Nat}{y : A}{xs : Vec A n} -> x ∈ xs -> x ∈ y :: xs
data _∉_ {A : Set}(x : A) : {n : Nat}(xs : Vec A n) -> Set where
nl : x ∉ []
cns : {n : Nat}{y : A}{xs : Vec A n} -> x ≢ y -> x ∉ xs -> x ∉ y :: xs
∉=¬∈ : {A : Set}{x : A}{n : Nat}{xs : Vec A n} -> x ∉ xs -> ¬ (x ∈ xs)
∉=¬∈ nl ()
∉=¬∈ {A} (cns x≠x _) hd = elim-False (x≠x refl)
∉=¬∈ {A} (cns _ ne) (tl e) = ∉=¬∈ ne e
∈=¬∉ : {A : Set}{x : A}{n : Nat}{xs : Vec A n} -> x ∈ xs -> ¬ (x ∉ xs)
∈=¬∉ e ne = ∉=¬∈ ne e
find : {A : Set}{n : Nat} -> ((x y : A) -> x ≡ y \/ x ≢ y) ->
(x : A)(xs : Vec A n) -> x ∈ xs \/ x ∉ xs
find _ _ [] = \/-IR nl
find eq y (x :: xs) = aux x y (eq y x) (find eq y xs) where
aux : forall x y -> y ≡ x \/ y ≢ x -> y ∈ xs \/ y ∉ xs -> y ∈ x :: xs \/ y ∉ x :: xs
aux x .x (\/-IL refl) _ = \/-IL hd
aux x y (\/-IR y≠x) (\/-IR y∉xs) = \/-IR (cns y≠x y∉xs)
aux x y (\/-IR _) (\/-IL y∈xs) = \/-IL (tl y∈xs)
delete : {A : Set}{n : Nat}(x : A)(xs : Vec A (suc n)) -> x ∈ xs -> Vec A n
delete .x (x :: xs) hd = xs
delete {A}{zero } _ ._ (tl ())
delete {A}{suc _} y (x :: xs) (tl p) = x :: delete y xs p
| 31.757282
| 88
| 0.466524
|
121515af7fd8dd0ff65a48c72007fa6d08d43022
| 39,090
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- List-related properties
------------------------------------------------------------------------
-- Note that the lemmas below could be generalised to work with other
-- equalities than _≡_.
{-# OPTIONS --without-K --safe #-}
module Data.List.Properties where
open import Algebra.Bundles
open import Algebra.Definitions as AlgebraicDefinitions using (Involutive)
import Algebra.Structures as AlgebraicStructures
open import Data.Bool.Base using (Bool; false; true; not; if_then_else_)
open import Data.Fin.Base using (Fin; zero; suc; cast; toℕ; inject₁)
open import Data.List.Base as List
open import Data.List.Relation.Unary.All using (All; []; _∷_)
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.Maybe.Base using (Maybe; just; nothing)
open import Data.Nat.Base
open import Data.Nat.Properties
open import Data.Product as Prod hiding (map; zip)
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
open import Data.These.Base as These using (These; this; that; these)
open import Function
open import Level using (Level)
open import Relation.Binary as B using (DecidableEquality)
import Relation.Binary.Reasoning.Setoid as EqR
open import Relation.Binary.PropositionalEquality as P hiding ([_])
open import Relation.Binary as B using (Rel)
open import Relation.Nullary.Reflects using (invert)
open import Relation.Nullary using (¬_; Dec; does; _because_; yes; no)
open import Relation.Nullary.Negation using (contradiction; ¬?)
open import Relation.Nullary.Decidable as Decidable using (isYes; map′; ⌊_⌋)
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Unary using (Pred; Decidable; ∁)
open import Relation.Unary.Properties using (∁?)
open ≡-Reasoning
private
variable
a b c d e p : Level
A : Set a
B : Set b
C : Set c
D : Set d
E : Set e
-----------------------------------------------------------------------
-- _∷_
module _ {x y : A} {xs ys : List A} where
∷-injective : x ∷ xs ≡ y List.∷ ys → x ≡ y × xs ≡ ys
∷-injective refl = (refl , refl)
∷-injectiveˡ : x ∷ xs ≡ y List.∷ ys → x ≡ y
∷-injectiveˡ refl = refl
∷-injectiveʳ : x ∷ xs ≡ y List.∷ ys → xs ≡ ys
∷-injectiveʳ refl = refl
∷-dec : Dec (x ≡ y) → Dec (xs ≡ ys) → Dec (x List.∷ xs ≡ y ∷ ys)
∷-dec x≟y xs≟ys = Decidable.map′ (uncurry (cong₂ _∷_)) ∷-injective (x≟y ×-dec xs≟ys)
≡-dec : DecidableEquality A → DecidableEquality (List A)
≡-dec _≟_ [] [] = yes refl
≡-dec _≟_ (x ∷ xs) [] = no λ()
≡-dec _≟_ [] (y ∷ ys) = no λ()
≡-dec _≟_ (x ∷ xs) (y ∷ ys) = ∷-dec (x ≟ y) (≡-dec _≟_ xs ys)
------------------------------------------------------------------------
-- map
map-id : map id ≗ id {A = List A}
map-id [] = refl
map-id (x ∷ xs) = cong (x ∷_) (map-id xs)
map-id₂ : ∀ {f : A → A} {xs} → All (λ x → f x ≡ x) xs → map f xs ≡ xs
map-id₂ [] = refl
map-id₂ (fx≡x ∷ pxs) = cong₂ _∷_ fx≡x (map-id₂ pxs)
map-++-commute : ∀ (f : A → B) xs ys →
map f (xs ++ ys) ≡ map f xs ++ map f ys
map-++-commute f [] ys = refl
map-++-commute f (x ∷ xs) ys = cong (f x ∷_) (map-++-commute f xs ys)
map-cong : ∀ {f g : A → B} → f ≗ g → map f ≗ map g
map-cong f≗g [] = refl
map-cong f≗g (x ∷ xs) = cong₂ _∷_ (f≗g x) (map-cong f≗g xs)
map-cong₂ : ∀ {f g : A → B} {xs} →
All (λ x → f x ≡ g x) xs → map f xs ≡ map g xs
map-cong₂ [] = refl
map-cong₂ (fx≡gx ∷ fxs≡gxs) = cong₂ _∷_ fx≡gx (map-cong₂ fxs≡gxs)
length-map : ∀ (f : A → B) xs → length (map f xs) ≡ length xs
length-map f [] = refl
length-map f (x ∷ xs) = cong suc (length-map f xs)
map-compose : {g : B → C} {f : A → B} → map (g ∘ f) ≗ map g ∘ map f
map-compose [] = refl
map-compose (x ∷ xs) = cong (_ ∷_) (map-compose xs)
------------------------------------------------------------------------
-- mapMaybe
mapMaybe-just : (xs : List A) → mapMaybe just xs ≡ xs
mapMaybe-just [] = refl
mapMaybe-just (x ∷ xs) = cong (x ∷_) (mapMaybe-just xs)
mapMaybe-nothing : (xs : List A) →
mapMaybe {B = A} (λ _ → nothing) xs ≡ []
mapMaybe-nothing [] = refl
mapMaybe-nothing (x ∷ xs) = mapMaybe-nothing xs
module _ (f : A → Maybe B) where
mapMaybe-concatMap : mapMaybe f ≗ concatMap (fromMaybe ∘ f)
mapMaybe-concatMap [] = refl
mapMaybe-concatMap (x ∷ xs) with f x
... | just y = cong (y ∷_) (mapMaybe-concatMap xs)
... | nothing = mapMaybe-concatMap xs
length-mapMaybe : ∀ xs → length (mapMaybe f xs) ≤ length xs
length-mapMaybe [] = z≤n
length-mapMaybe (x ∷ xs) with f x
... | just y = s≤s (length-mapMaybe xs)
... | nothing = ≤-step (length-mapMaybe xs)
------------------------------------------------------------------------
-- _++_
length-++ : ∀ (xs : List A) {ys} →
length (xs ++ ys) ≡ length xs + length ys
length-++ [] = refl
length-++ (x ∷ xs) = cong suc (length-++ xs)
module _ {A : Set a} where
open AlgebraicDefinitions {A = List A} _≡_
open AlgebraicStructures {A = List A} _≡_
++-assoc : Associative _++_
++-assoc [] ys zs = refl
++-assoc (x ∷ xs) ys zs = cong (x ∷_) (++-assoc xs ys zs)
++-identityˡ : LeftIdentity [] _++_
++-identityˡ xs = refl
++-identityʳ : RightIdentity [] _++_
++-identityʳ [] = refl
++-identityʳ (x ∷ xs) = cong (x ∷_) (++-identityʳ xs)
++-identity : Identity [] _++_
++-identity = ++-identityˡ , ++-identityʳ
++-identityʳ-unique : ∀ (xs : List A) {ys} → xs ≡ xs ++ ys → ys ≡ []
++-identityʳ-unique [] refl = refl
++-identityʳ-unique (x ∷ xs) eq =
++-identityʳ-unique xs (proj₂ (∷-injective eq))
++-identityˡ-unique : ∀ {xs} (ys : List A) → xs ≡ ys ++ xs → ys ≡ []
++-identityˡ-unique [] _ = refl
++-identityˡ-unique {xs = x ∷ xs} (y ∷ ys) eq
with ++-identityˡ-unique (ys ++ [ x ]) (begin
xs ≡⟨ proj₂ (∷-injective eq) ⟩
ys ++ x ∷ xs ≡⟨ sym (++-assoc ys [ x ] xs) ⟩
(ys ++ [ x ]) ++ xs ∎)
++-identityˡ-unique {xs = x ∷ xs} (y ∷ [] ) eq | ()
++-identityˡ-unique {xs = x ∷ xs} (y ∷ _ ∷ _) eq | ()
++-cancelˡ : ∀ xs {ys zs : List A} → xs ++ ys ≡ xs ++ zs → ys ≡ zs
++-cancelˡ [] ys≡zs = ys≡zs
++-cancelˡ (x ∷ xs) x∷xs++ys≡x∷xs++zs = ++-cancelˡ xs (∷-injectiveʳ x∷xs++ys≡x∷xs++zs)
++-cancelʳ : ∀ {xs : List A} ys zs → ys ++ xs ≡ zs ++ xs → ys ≡ zs
++-cancelʳ {_} [] [] _ = refl
++-cancelʳ {xs} [] (z ∷ zs) eq =
contradiction (trans (cong length eq) (length-++ (z ∷ zs))) (m≢1+n+m (length xs))
++-cancelʳ {xs} (y ∷ ys) [] eq =
contradiction (trans (sym (length-++ (y ∷ ys))) (cong length eq)) (m≢1+n+m (length xs) ∘ sym)
++-cancelʳ {_} (y ∷ ys) (z ∷ zs) eq =
cong₂ _∷_ (∷-injectiveˡ eq) (++-cancelʳ ys zs (∷-injectiveʳ eq))
++-cancel : Cancellative _++_
++-cancel = ++-cancelˡ , ++-cancelʳ
++-conicalˡ : ∀ (xs ys : List A) → xs ++ ys ≡ [] → xs ≡ []
++-conicalˡ [] _ refl = refl
++-conicalʳ : ∀ (xs ys : List A) → xs ++ ys ≡ [] → ys ≡ []
++-conicalʳ [] _ refl = refl
++-conical : Conical [] _++_
++-conical = ++-conicalˡ , ++-conicalʳ
++-isMagma : IsMagma _++_
++-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _++_
}
++-isSemigroup : IsSemigroup _++_
++-isSemigroup = record
{ isMagma = ++-isMagma
; assoc = ++-assoc
}
++-isMonoid : IsMonoid _++_ []
++-isMonoid = record
{ isSemigroup = ++-isSemigroup
; identity = ++-identity
}
module _ (A : Set a) where
++-semigroup : Semigroup a a
++-semigroup = record
{ Carrier = List A
; isSemigroup = ++-isSemigroup
}
++-monoid : Monoid a a
++-monoid = record
{ Carrier = List A
; isMonoid = ++-isMonoid
}
------------------------------------------------------------------------
-- alignWith
module _ {f g : These A B → C} where
alignWith-cong : f ≗ g → ∀ as → alignWith f as ≗ alignWith g as
alignWith-cong f≗g [] bs = map-cong (f≗g ∘ that) bs
alignWith-cong f≗g as@(_ ∷ _) [] = map-cong (f≗g ∘ this) as
alignWith-cong f≗g (a ∷ as) (b ∷ bs) =
cong₂ _∷_ (f≗g (these a b)) (alignWith-cong f≗g as bs)
length-alignWith : ∀ xs ys →
length (alignWith f xs ys) ≡ length xs ⊔ length ys
length-alignWith [] ys = length-map (f ∘′ that) ys
length-alignWith xs@(_ ∷ _) [] = length-map (f ∘′ this) xs
length-alignWith (x ∷ xs) (y ∷ ys) = cong suc (length-alignWith xs ys)
alignWith-map : (g : D → A) (h : E → B) →
∀ xs ys → alignWith f (map g xs) (map h ys) ≡
alignWith (f ∘′ These.map g h) xs ys
alignWith-map g h [] ys = sym (map-compose ys)
alignWith-map g h xs@(_ ∷ _) [] = sym (map-compose xs)
alignWith-map g h (x ∷ xs) (y ∷ ys) =
cong₂ _∷_ refl (alignWith-map g h xs ys)
map-alignWith : ∀ (g : C → D) → ∀ xs ys →
map g (alignWith f xs ys) ≡
alignWith (g ∘′ f) xs ys
map-alignWith g [] ys = sym (map-compose ys)
map-alignWith g xs@(_ ∷ _) [] = sym (map-compose xs)
map-alignWith g (x ∷ xs) (y ∷ ys) =
cong₂ _∷_ refl (map-alignWith g xs ys)
------------------------------------------------------------------------
-- zipWith
module _ (f : A → A → B) where
zipWith-comm : (∀ x y → f x y ≡ f y x) →
∀ xs ys → zipWith f xs ys ≡ zipWith f ys xs
zipWith-comm f-comm [] [] = refl
zipWith-comm f-comm [] (x ∷ ys) = refl
zipWith-comm f-comm (x ∷ xs) [] = refl
zipWith-comm f-comm (x ∷ xs) (y ∷ ys) =
cong₂ _∷_ (f-comm x y) (zipWith-comm f-comm xs ys)
module _ (f : A → B → C) where
zipWith-identityˡ : ∀ xs → zipWith f [] xs ≡ []
zipWith-identityˡ [] = refl
zipWith-identityˡ (x ∷ xs) = refl
zipWith-identityʳ : ∀ xs → zipWith f xs [] ≡ []
zipWith-identityʳ [] = refl
zipWith-identityʳ (x ∷ xs) = refl
length-zipWith : ∀ xs ys →
length (zipWith f xs ys) ≡ length xs ⊓ length ys
length-zipWith [] [] = refl
length-zipWith [] (y ∷ ys) = refl
length-zipWith (x ∷ xs) [] = refl
length-zipWith (x ∷ xs) (y ∷ ys) = cong suc (length-zipWith xs ys)
zipWith-map : ∀ {d e} {D : Set d} {E : Set e} (g : D → A) (h : E → B) →
∀ xs ys → zipWith f (map g xs) (map h ys) ≡
zipWith (λ x y → f (g x) (h y)) xs ys
zipWith-map g h [] [] = refl
zipWith-map g h [] (y ∷ ys) = refl
zipWith-map g h (x ∷ xs) [] = refl
zipWith-map g h (x ∷ xs) (y ∷ ys) =
cong₂ _∷_ refl (zipWith-map g h xs ys)
map-zipWith : ∀ {d} {D : Set d} (g : C → D) → ∀ xs ys →
map g (zipWith f xs ys) ≡
zipWith (λ x y → g (f x y)) xs ys
map-zipWith g [] [] = refl
map-zipWith g [] (y ∷ ys) = refl
map-zipWith g (x ∷ xs) [] = refl
map-zipWith g (x ∷ xs) (y ∷ ys) =
cong₂ _∷_ refl (map-zipWith g xs ys)
------------------------------------------------------------------------
-- unalignWith
unalignWith-this : unalignWith ((A → These A B) ∋ this) ≗ (_, [])
unalignWith-this [] = refl
unalignWith-this (a ∷ as) = cong (Prod.map₁ (a ∷_)) (unalignWith-this as)
unalignWith-that : unalignWith ((B → These A B) ∋ that) ≗ ([] ,_)
unalignWith-that [] = refl
unalignWith-that (b ∷ bs) = cong (Prod.map₂ (b ∷_)) (unalignWith-that bs)
module _ {f g : C → These A B} where
unalignWith-cong : f ≗ g → unalignWith f ≗ unalignWith g
unalignWith-cong f≗g [] = refl
unalignWith-cong f≗g (c ∷ cs) with f c | g c | f≗g c
... | this a | ._ | refl = cong (Prod.map₁ (a ∷_)) (unalignWith-cong f≗g cs)
... | that b | ._ | refl = cong (Prod.map₂ (b ∷_)) (unalignWith-cong f≗g cs)
... | these a b | ._ | refl = cong (Prod.map (a ∷_) (b ∷_)) (unalignWith-cong f≗g cs)
module _ (f : C → These A B) where
unalignWith-map : (g : D → C) → ∀ ds →
unalignWith f (map g ds) ≡ unalignWith (f ∘′ g) ds
unalignWith-map g [] = refl
unalignWith-map g (d ∷ ds) with f (g d)
... | this a = cong (Prod.map₁ (a ∷_)) (unalignWith-map g ds)
... | that b = cong (Prod.map₂ (b ∷_)) (unalignWith-map g ds)
... | these a b = cong (Prod.map (a ∷_) (b ∷_)) (unalignWith-map g ds)
map-unalignWith : (g : A → D) (h : B → E) →
Prod.map (map g) (map h) ∘′ unalignWith f ≗ unalignWith (These.map g h ∘′ f)
map-unalignWith g h [] = refl
map-unalignWith g h (c ∷ cs) with f c
... | this a = cong (Prod.map₁ (g a ∷_)) (map-unalignWith g h cs)
... | that b = cong (Prod.map₂ (h b ∷_)) (map-unalignWith g h cs)
... | these a b = cong (Prod.map (g a ∷_) (h b ∷_)) (map-unalignWith g h cs)
unalignWith-alignWith : (g : These A B → C) → f ∘′ g ≗ id → ∀ as bs →
unalignWith f (alignWith g as bs) ≡ (as , bs)
unalignWith-alignWith g g∘f≗id [] bs = begin
unalignWith f (map (g ∘′ that) bs) ≡⟨ unalignWith-map (g ∘′ that) bs ⟩
unalignWith (f ∘′ g ∘′ that) bs ≡⟨ unalignWith-cong (g∘f≗id ∘ that) bs ⟩
unalignWith that bs ≡⟨ unalignWith-that bs ⟩
[] , bs ∎
unalignWith-alignWith g g∘f≗id as@(_ ∷ _) [] = begin
unalignWith f (map (g ∘′ this) as) ≡⟨ unalignWith-map (g ∘′ this) as ⟩
unalignWith (f ∘′ g ∘′ this) as ≡⟨ unalignWith-cong (g∘f≗id ∘ this) as ⟩
unalignWith this as ≡⟨ unalignWith-this as ⟩
as , [] ∎
unalignWith-alignWith g g∘f≗id (a ∷ as) (b ∷ bs)
rewrite g∘f≗id (these a b) =
cong (Prod.map (a ∷_) (b ∷_)) (unalignWith-alignWith g g∘f≗id as bs)
------------------------------------------------------------------------
-- unzipWith
module _ (f : A → B × C) where
length-unzipWith₁ : ∀ xys →
length (proj₁ (unzipWith f xys)) ≡ length xys
length-unzipWith₁ [] = refl
length-unzipWith₁ (x ∷ xys) = cong suc (length-unzipWith₁ xys)
length-unzipWith₂ : ∀ xys →
length (proj₂ (unzipWith f xys)) ≡ length xys
length-unzipWith₂ [] = refl
length-unzipWith₂ (x ∷ xys) = cong suc (length-unzipWith₂ xys)
zipWith-unzipWith : (g : B → C → A) → uncurry′ g ∘ f ≗ id →
uncurry′ (zipWith g) ∘ (unzipWith f) ≗ id
zipWith-unzipWith g f∘g≗id [] = refl
zipWith-unzipWith g f∘g≗id (x ∷ xs) =
cong₂ _∷_ (f∘g≗id x) (zipWith-unzipWith g f∘g≗id xs)
------------------------------------------------------------------------
-- foldr
foldr-universal : ∀ (h : List A → B) f e → (h [] ≡ e) →
(∀ x xs → h (x ∷ xs) ≡ f x (h xs)) →
h ≗ foldr f e
foldr-universal h f e base step [] = base
foldr-universal h f e base step (x ∷ xs) = begin
h (x ∷ xs) ≡⟨ step x xs ⟩
f x (h xs) ≡⟨ cong (f x) (foldr-universal h f e base step xs) ⟩
f x (foldr f e xs) ∎
foldr-cong : ∀ {f g : A → B → B} {d e : B} →
(∀ x y → f x y ≡ g x y) → d ≡ e →
foldr f d ≗ foldr g e
foldr-cong f≗g refl [] = refl
foldr-cong f≗g d≡e (x ∷ xs) rewrite foldr-cong f≗g d≡e xs = f≗g x _
foldr-fusion : ∀ (h : B → C) {f : A → B → B} {g : A → C → C} (e : B) →
(∀ x y → h (f x y) ≡ g x (h y)) →
h ∘ foldr f e ≗ foldr g (h e)
foldr-fusion h {f} {g} e fuse =
foldr-universal (h ∘ foldr f e) g (h e) refl
(λ x xs → fuse x (foldr f e xs))
id-is-foldr : id {A = List A} ≗ foldr _∷_ []
id-is-foldr = foldr-universal id _∷_ [] refl (λ _ _ → refl)
++-is-foldr : (xs ys : List A) → xs ++ ys ≡ foldr _∷_ ys xs
++-is-foldr xs ys = begin
xs ++ ys ≡⟨ cong (_++ ys) (id-is-foldr xs) ⟩
foldr _∷_ [] xs ++ ys ≡⟨ foldr-fusion (_++ ys) [] (λ _ _ → refl) xs ⟩
foldr _∷_ ([] ++ ys) xs ≡⟨⟩
foldr _∷_ ys xs ∎
foldr-++ : ∀ (f : A → B → B) x ys zs →
foldr f x (ys ++ zs) ≡ foldr f (foldr f x zs) ys
foldr-++ f x [] zs = refl
foldr-++ f x (y ∷ ys) zs = cong (f y) (foldr-++ f x ys zs)
map-is-foldr : {f : A → B} → map f ≗ foldr (λ x ys → f x ∷ ys) []
map-is-foldr {f = f} xs = begin
map f xs ≡⟨ cong (map f) (id-is-foldr xs) ⟩
map f (foldr _∷_ [] xs) ≡⟨ foldr-fusion (map f) [] (λ _ _ → refl) xs ⟩
foldr (λ x ys → f x ∷ ys) [] xs ∎
foldr-∷ʳ : ∀ (f : A → B → B) x y ys →
foldr f x (ys ∷ʳ y) ≡ foldr f (f y x) ys
foldr-∷ʳ f x y [] = refl
foldr-∷ʳ f x y (z ∷ ys) = cong (f z) (foldr-∷ʳ f x y ys)
-- Interaction with predicates
module _ {P : Pred A p} {f : A → A → A} where
foldr-forcesᵇ : (∀ x y → P (f x y) → P x × P y) →
∀ e xs → P (foldr f e xs) → All P xs
foldr-forcesᵇ _ _ [] _ = []
foldr-forcesᵇ forces _ (x ∷ xs) Pfold with forces _ _ Pfold
... | (px , pfxs) = px ∷ foldr-forcesᵇ forces _ xs pfxs
foldr-preservesᵇ : (∀ {x y} → P x → P y → P (f x y)) →
∀ {e xs} → P e → All P xs → P (foldr f e xs)
foldr-preservesᵇ _ Pe [] = Pe
foldr-preservesᵇ pres Pe (px ∷ pxs) = pres px (foldr-preservesᵇ pres Pe pxs)
foldr-preservesʳ : (∀ x {y} → P y → P (f x y)) →
∀ {e} → P e → ∀ xs → P (foldr f e xs)
foldr-preservesʳ pres Pe [] = Pe
foldr-preservesʳ pres Pe (_ ∷ xs) = pres _ (foldr-preservesʳ pres Pe xs)
foldr-preservesᵒ : (∀ x y → P x ⊎ P y → P (f x y)) →
∀ e xs → P e ⊎ Any P xs → P (foldr f e xs)
foldr-preservesᵒ pres e [] (inj₁ Pe) = Pe
foldr-preservesᵒ pres e (x ∷ xs) (inj₁ Pe) =
pres _ _ (inj₂ (foldr-preservesᵒ pres e xs (inj₁ Pe)))
foldr-preservesᵒ pres e (x ∷ xs) (inj₂ (here px)) = pres _ _ (inj₁ px)
foldr-preservesᵒ pres e (x ∷ xs) (inj₂ (there pxs)) =
pres _ _ (inj₂ (foldr-preservesᵒ pres e xs (inj₂ pxs)))
------------------------------------------------------------------------
-- foldl
foldl-++ : ∀ (f : A → B → A) x ys zs →
foldl f x (ys ++ zs) ≡ foldl f (foldl f x ys) zs
foldl-++ f x [] zs = refl
foldl-++ f x (y ∷ ys) zs = foldl-++ f (f x y) ys zs
foldl-∷ʳ : ∀ (f : A → B → A) x y ys →
foldl f x (ys ∷ʳ y) ≡ f (foldl f x ys) y
foldl-∷ʳ f x y [] = refl
foldl-∷ʳ f x y (z ∷ ys) = foldl-∷ʳ f (f x z) y ys
------------------------------------------------------------------------
-- concat
concat-map : ∀ {f : A → B} → concat ∘ map (map f) ≗ map f ∘ concat
concat-map {f = f} xss = begin
concat (map (map f) xss) ≡⟨ cong concat (map-is-foldr xss) ⟩
concat (foldr (λ xs → map f xs ∷_) [] xss) ≡⟨ foldr-fusion concat [] (λ _ _ → refl) xss ⟩
foldr (λ ys → map f ys ++_) [] xss ≡⟨ sym (foldr-fusion (map f) [] (map-++-commute f) xss) ⟩
map f (concat xss) ∎
------------------------------------------------------------------------
-- sum
sum-++-commute : ∀ xs ys → sum (xs ++ ys) ≡ sum xs + sum ys
sum-++-commute [] ys = refl
sum-++-commute (x ∷ xs) ys = begin
x + sum (xs ++ ys) ≡⟨ cong (x +_) (sum-++-commute xs ys) ⟩
x + (sum xs + sum ys) ≡⟨ sym (+-assoc x _ _) ⟩
(x + sum xs) + sum ys ∎
------------------------------------------------------------------------
-- replicate
length-replicate : ∀ n {x : A} → length (replicate n x) ≡ n
length-replicate zero = refl
length-replicate (suc n) = cong suc (length-replicate n)
------------------------------------------------------------------------
-- scanr
scanr-defn : ∀ (f : A → B → B) (e : B) →
scanr f e ≗ map (foldr f e) ∘ tails
scanr-defn f e [] = refl
scanr-defn f e (x ∷ []) = refl
scanr-defn f e (x ∷ y ∷ xs)
with scanr f e (y ∷ xs) | scanr-defn f e (y ∷ xs)
... | [] | ()
... | z ∷ zs | eq with ∷-injective eq
... | z≡fy⦇f⦈xs , _ = cong₂ (λ z → f x z ∷_) z≡fy⦇f⦈xs eq
------------------------------------------------------------------------
-- scanl
scanl-defn : ∀ (f : A → B → A) (e : A) →
scanl f e ≗ map (foldl f e) ∘ inits
scanl-defn f e [] = refl
scanl-defn f e (x ∷ xs) = cong (e ∷_) (begin
scanl f (f e x) xs
≡⟨ scanl-defn f (f e x) xs ⟩
map (foldl f (f e x)) (inits xs)
≡⟨ refl ⟩
map (foldl f e ∘ (x ∷_)) (inits xs)
≡⟨ map-compose (inits xs) ⟩
map (foldl f e) (map (x ∷_) (inits xs))
∎)
------------------------------------------------------------------------
-- applyUpTo
length-applyUpTo : ∀ (f : ℕ → A) n → length (applyUpTo f n) ≡ n
length-applyUpTo f zero = refl
length-applyUpTo f (suc n) = cong suc (length-applyUpTo (f ∘ suc) n)
lookup-applyUpTo : ∀ (f : ℕ → A) n i → lookup (applyUpTo f n) i ≡ f (toℕ i)
lookup-applyUpTo f (suc n) zero = refl
lookup-applyUpTo f (suc n) (suc i) = lookup-applyUpTo (f ∘ suc) n i
------------------------------------------------------------------------
-- applyUpTo
module _ (f : ℕ → A) where
length-applyDownFrom : ∀ n → length (applyDownFrom f n) ≡ n
length-applyDownFrom zero = refl
length-applyDownFrom (suc n) = cong suc (length-applyDownFrom n)
lookup-applyDownFrom : ∀ n i → lookup (applyDownFrom f n) i ≡ f (n ∸ (suc (toℕ i)))
lookup-applyDownFrom (suc n) zero = refl
lookup-applyDownFrom (suc n) (suc i) = lookup-applyDownFrom n i
------------------------------------------------------------------------
-- upTo
length-upTo : ∀ n → length (upTo n) ≡ n
length-upTo = length-applyUpTo id
lookup-upTo : ∀ n i → lookup (upTo n) i ≡ toℕ i
lookup-upTo = lookup-applyUpTo id
------------------------------------------------------------------------
-- downFrom
length-downFrom : ∀ n → length (downFrom n) ≡ n
length-downFrom = length-applyDownFrom id
lookup-downFrom : ∀ n i → lookup (downFrom n) i ≡ n ∸ (suc (toℕ i))
lookup-downFrom = lookup-applyDownFrom id
------------------------------------------------------------------------
-- tabulate
tabulate-cong : ∀ {n} {f g : Fin n → A} →
f ≗ g → tabulate f ≡ tabulate g
tabulate-cong {n = zero} p = refl
tabulate-cong {n = suc n} p = cong₂ _∷_ (p zero) (tabulate-cong (p ∘ suc))
tabulate-lookup : ∀ (xs : List A) → tabulate (lookup xs) ≡ xs
tabulate-lookup [] = refl
tabulate-lookup (x ∷ xs) = cong (_ ∷_) (tabulate-lookup xs)
length-tabulate : ∀ {n} → (f : Fin n → A) →
length (tabulate f) ≡ n
length-tabulate {n = zero} f = refl
length-tabulate {n = suc n} f = cong suc (length-tabulate (λ z → f (suc z)))
lookup-tabulate : ∀ {n} → (f : Fin n → A) →
∀ i → let i′ = cast (sym (length-tabulate f)) i
in lookup (tabulate f) i′ ≡ f i
lookup-tabulate f zero = refl
lookup-tabulate f (suc i) = lookup-tabulate (f ∘ suc) i
map-tabulate : ∀ {n} (g : Fin n → A) (f : A → B) →
map f (tabulate g) ≡ tabulate (f ∘ g)
map-tabulate {n = zero} g f = refl
map-tabulate {n = suc n} g f = cong (_ ∷_) (map-tabulate (g ∘ suc) f)
------------------------------------------------------------------------
-- _[_]%=_
length-%= : ∀ xs k (f : A → A) → length (xs [ k ]%= f) ≡ length xs
length-%= (x ∷ xs) zero f = refl
length-%= (x ∷ xs) (suc k) f = cong suc (length-%= xs k f)
------------------------------------------------------------------------
-- _[_]∷=_
length-∷= : ∀ xs k (v : A) → length (xs [ k ]∷= v) ≡ length xs
length-∷= xs k v = length-%= xs k (const v)
map-∷= : ∀ xs k (v : A) (f : A → B) →
let eq = sym (length-map f xs) in
map f (xs [ k ]∷= v) ≡ map f xs [ cast eq k ]∷= f v
map-∷= (x ∷ xs) zero v f = refl
map-∷= (x ∷ xs) (suc k) v f = cong (f x ∷_) (map-∷= xs k v f)
------------------------------------------------------------------------
-- _─_
length-─ : ∀ (xs : List A) k → length (xs ─ k) ≡ pred (length xs)
length-─ (x ∷ xs) zero = refl
length-─ (x ∷ y ∷ xs) (suc k) = cong suc (length-─ (y ∷ xs) k)
map-─ : ∀ xs k (f : A → B) →
let eq = sym (length-map f xs) in
map f (xs ─ k) ≡ map f xs ─ cast eq k
map-─ (x ∷ xs) zero f = refl
map-─ (x ∷ xs) (suc k) f = cong (f x ∷_) (map-─ xs k f)
------------------------------------------------------------------------
-- take
length-take : ∀ n (xs : List A) → length (take n xs) ≡ n ⊓ (length xs)
length-take zero xs = refl
length-take (suc n) [] = refl
length-take (suc n) (x ∷ xs) = cong suc (length-take n xs)
------------------------------------------------------------------------
-- drop
length-drop : ∀ n (xs : List A) → length (drop n xs) ≡ length xs ∸ n
length-drop zero xs = refl
length-drop (suc n) [] = refl
length-drop (suc n) (x ∷ xs) = length-drop n xs
take++drop : ∀ n (xs : List A) → take n xs ++ drop n xs ≡ xs
take++drop zero xs = refl
take++drop (suc n) [] = refl
take++drop (suc n) (x ∷ xs) = cong (x ∷_) (take++drop n xs)
------------------------------------------------------------------------
-- splitAt
splitAt-defn : ∀ n → splitAt {A = A} n ≗ < take n , drop n >
splitAt-defn zero xs = refl
splitAt-defn (suc n) [] = refl
splitAt-defn (suc n) (x ∷ xs) with splitAt n xs | splitAt-defn n xs
... | (ys , zs) | ih = cong (Prod.map (x ∷_) id) ih
------------------------------------------------------------------------
-- takeWhile, dropWhile, and span
module _ {P : Pred A p} (P? : Decidable P) where
takeWhile++dropWhile : ∀ xs → takeWhile P? xs ++ dropWhile P? xs ≡ xs
takeWhile++dropWhile [] = refl
takeWhile++dropWhile (x ∷ xs) with does (P? x)
... | true = cong (x ∷_) (takeWhile++dropWhile xs)
... | false = refl
span-defn : span P? ≗ < takeWhile P? , dropWhile P? >
span-defn [] = refl
span-defn (x ∷ xs) with does (P? x)
... | true = cong (Prod.map (x ∷_) id) (span-defn xs)
... | false = refl
------------------------------------------------------------------------
-- filter
module _ {P : Pred A p} (P? : Decidable P) where
length-filter : ∀ xs → length (filter P? xs) ≤ length xs
length-filter [] = z≤n
length-filter (x ∷ xs) with does (P? x)
... | false = ≤-step (length-filter xs)
... | true = s≤s (length-filter xs)
filter-all : ∀ {xs} → All P xs → filter P? xs ≡ xs
filter-all {[]} [] = refl
filter-all {x ∷ xs} (px ∷ pxs) with P? x
... | no ¬px = contradiction px ¬px
... | true because _ = cong (x ∷_) (filter-all pxs)
filter-notAll : ∀ xs → Any (∁ P) xs → length (filter P? xs) < length xs
filter-notAll (x ∷ xs) (here ¬px) with P? x
... | false because _ = s≤s (length-filter xs)
... | yes px = contradiction px ¬px
filter-notAll (x ∷ xs) (there any) with does (P? x)
... | false = ≤-step (filter-notAll xs any)
... | true = s≤s (filter-notAll xs any)
filter-some : ∀ {xs} → Any P xs → 0 < length (filter P? xs)
filter-some {x ∷ xs} (here px) with P? x
... | true because _ = s≤s z≤n
... | no ¬px = contradiction px ¬px
filter-some {x ∷ xs} (there pxs) with does (P? x)
... | true = ≤-step (filter-some pxs)
... | false = filter-some pxs
filter-none : ∀ {xs} → All (∁ P) xs → filter P? xs ≡ []
filter-none {[]} [] = refl
filter-none {x ∷ xs} (¬px ∷ ¬pxs) with P? x
... | false because _ = filter-none ¬pxs
... | yes px = contradiction px ¬px
filter-complete : ∀ {xs} → length (filter P? xs) ≡ length xs →
filter P? xs ≡ xs
filter-complete {[]} eq = refl
filter-complete {x ∷ xs} eq with does (P? x)
... | false = contradiction eq (<⇒≢ (s≤s (length-filter xs)))
... | true = cong (x ∷_) (filter-complete (suc-injective eq))
filter-accept : ∀ {x xs} → P x → filter P? (x ∷ xs) ≡ x ∷ (filter P? xs)
filter-accept {x} Px with P? x
... | true because _ = refl
... | no ¬Px = contradiction Px ¬Px
filter-reject : ∀ {x xs} → ¬ P x → filter P? (x ∷ xs) ≡ filter P? xs
filter-reject {x} ¬Px with P? x
... | yes Px = contradiction Px ¬Px
... | false because _ = refl
filter-idem : filter P? ∘ filter P? ≗ filter P?
filter-idem [] = refl
filter-idem (x ∷ xs) with does (P? x) | inspect does (P? x)
... | false | _ = filter-idem xs
... | true | P.[ eq ] rewrite eq = cong (x ∷_) (filter-idem xs)
filter-++ : ∀ xs ys → filter P? (xs ++ ys) ≡ filter P? xs ++ filter P? ys
filter-++ [] ys = refl
filter-++ (x ∷ xs) ys with does (P? x)
... | true = cong (x ∷_) (filter-++ xs ys)
... | false = filter-++ xs ys
------------------------------------------------------------------------
-- derun and deduplicate
module _ {R : Rel A p} (R? : B.Decidable R) where
length-derun : ∀ xs → length (derun R? xs) ≤ length xs
length-derun [] = ≤-refl
length-derun (x ∷ []) = ≤-refl
length-derun (x ∷ y ∷ xs) with does (R? x y) | length-derun (y ∷ xs)
... | true | r = ≤-step r
... | false | r = s≤s r
length-deduplicate : ∀ xs → length (deduplicate R? xs) ≤ length xs
length-deduplicate [] = z≤n
length-deduplicate (x ∷ xs) = ≤-begin
1 + length (filter (¬? ∘ R? x) r) ≤⟨ s≤s (length-filter (¬? ∘ R? x) r) ⟩
1 + length r ≤⟨ s≤s (length-deduplicate xs) ⟩
1 + length xs ≤-∎
where
open ≤-Reasoning renaming (begin_ to ≤-begin_; _∎ to _≤-∎)
r = deduplicate R? xs
derun-reject : ∀ {x y} xs → R x y → derun R? (x ∷ y ∷ xs) ≡ derun R? (y ∷ xs)
derun-reject {x} {y} xs Rxy with R? x y
... | yes _ = refl
... | no ¬Rxy = contradiction Rxy ¬Rxy
derun-accept : ∀ {x y} xs → ¬ R x y → derun R? (x ∷ y ∷ xs) ≡ x ∷ derun R? (y ∷ xs)
derun-accept {x} {y} xs ¬Rxy with R? x y
... | yes Rxy = contradiction Rxy ¬Rxy
... | no _ = refl
------------------------------------------------------------------------
-- partition
module _ {P : Pred A p} (P? : Decidable P) where
partition-defn : partition P? ≗ < filter P? , filter (∁? P?) >
partition-defn [] = refl
partition-defn (x ∷ xs) with does (P? x)
... | true = cong (Prod.map (x ∷_) id) (partition-defn xs)
... | false = cong (Prod.map id (x ∷_)) (partition-defn xs)
------------------------------------------------------------------------
-- _ʳ++_
ʳ++-defn : ∀ (xs : List A) {ys} → xs ʳ++ ys ≡ reverse xs ++ ys
ʳ++-defn [] = refl
ʳ++-defn (x ∷ xs) {ys} = begin
(x ∷ xs) ʳ++ ys ≡⟨⟩
xs ʳ++ x ∷ ys ≡⟨⟩
xs ʳ++ [ x ] ++ ys ≡⟨ ʳ++-defn xs ⟩
reverse xs ++ [ x ] ++ ys ≡⟨ sym (++-assoc (reverse xs) _ _) ⟩
(reverse xs ++ [ x ]) ++ ys ≡⟨ cong (_++ ys) (sym (ʳ++-defn xs)) ⟩
(xs ʳ++ [ x ]) ++ ys ≡⟨⟩
reverse (x ∷ xs) ++ ys ∎
-- Reverse-append of append is reverse-append after reverse-append.
ʳ++-++ : ∀ (xs {ys zs} : List A) → (xs ++ ys) ʳ++ zs ≡ ys ʳ++ xs ʳ++ zs
ʳ++-++ [] = refl
ʳ++-++ (x ∷ xs) {ys} {zs} = begin
(x ∷ xs ++ ys) ʳ++ zs ≡⟨⟩
(xs ++ ys) ʳ++ x ∷ zs ≡⟨ ʳ++-++ xs ⟩
ys ʳ++ xs ʳ++ x ∷ zs ≡⟨⟩
ys ʳ++ (x ∷ xs) ʳ++ zs ∎
-- Reverse-append of reverse-append is commuted reverse-append after append.
ʳ++-ʳ++ : ∀ (xs {ys zs} : List A) → (xs ʳ++ ys) ʳ++ zs ≡ ys ʳ++ xs ++ zs
ʳ++-ʳ++ [] = refl
ʳ++-ʳ++ (x ∷ xs) {ys} {zs} = begin
((x ∷ xs) ʳ++ ys) ʳ++ zs ≡⟨⟩
(xs ʳ++ x ∷ ys) ʳ++ zs ≡⟨ ʳ++-ʳ++ xs ⟩
(x ∷ ys) ʳ++ xs ++ zs ≡⟨⟩
ys ʳ++ (x ∷ xs) ++ zs ∎
-- Length of reverse-append
length-ʳ++ : ∀ (xs {ys} : List A) →
length (xs ʳ++ ys) ≡ length xs + length ys
length-ʳ++ [] = refl
length-ʳ++ (x ∷ xs) {ys} = begin
length ((x ∷ xs) ʳ++ ys) ≡⟨⟩
length (xs ʳ++ x ∷ ys) ≡⟨ length-ʳ++ xs ⟩
length xs + length (x ∷ ys) ≡⟨ +-suc _ _ ⟩
length (x ∷ xs) + length ys ∎
-- map distributes over reverse-append.
map-ʳ++ : (f : A → B) (xs {ys} : List A) →
map f (xs ʳ++ ys) ≡ map f xs ʳ++ map f ys
map-ʳ++ f [] = refl
map-ʳ++ f (x ∷ xs) {ys} = begin
map f ((x ∷ xs) ʳ++ ys) ≡⟨⟩
map f (xs ʳ++ x ∷ ys) ≡⟨ map-ʳ++ f xs ⟩
map f xs ʳ++ map f (x ∷ ys) ≡⟨⟩
map f xs ʳ++ f x ∷ map f ys ≡⟨⟩
(f x ∷ map f xs) ʳ++ map f ys ≡⟨⟩
map f (x ∷ xs) ʳ++ map f ys ∎
-- A foldr after a reverse is a foldl.
foldr-ʳ++ : ∀ (f : A → B → B) b xs {ys} →
foldr f b (xs ʳ++ ys) ≡ foldl (flip f) (foldr f b ys) xs
foldr-ʳ++ f b [] {_} = refl
foldr-ʳ++ f b (x ∷ xs) {ys} = begin
foldr f b ((x ∷ xs) ʳ++ ys) ≡⟨⟩
foldr f b (xs ʳ++ x ∷ ys) ≡⟨ foldr-ʳ++ f b xs ⟩
foldl (flip f) (foldr f b (x ∷ ys)) xs ≡⟨⟩
foldl (flip f) (f x (foldr f b ys)) xs ≡⟨⟩
foldl (flip f) (foldr f b ys) (x ∷ xs) ∎
-- A foldl after a reverse is a foldr.
foldl-ʳ++ : ∀ (f : B → A → B) b xs {ys} →
foldl f b (xs ʳ++ ys) ≡ foldl f (foldr (flip f) b xs) ys
foldl-ʳ++ f b [] {_} = refl
foldl-ʳ++ f b (x ∷ xs) {ys} = begin
foldl f b ((x ∷ xs) ʳ++ ys) ≡⟨⟩
foldl f b (xs ʳ++ x ∷ ys) ≡⟨ foldl-ʳ++ f b xs ⟩
foldl f (foldr (flip f) b xs) (x ∷ ys) ≡⟨⟩
foldl f (f (foldr (flip f) b xs) x) ys ≡⟨⟩
foldl f (foldr (flip f) b (x ∷ xs)) ys ∎
------------------------------------------------------------------------
-- reverse
-- reverse of cons is snoc of reverse.
unfold-reverse : ∀ (x : A) xs → reverse (x ∷ xs) ≡ reverse xs ∷ʳ x
unfold-reverse x xs = ʳ++-defn xs
-- reverse is an involution with respect to append.
reverse-++-commute : (xs ys : List A) →
reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-++-commute xs ys = begin
reverse (xs ++ ys) ≡⟨⟩
(xs ++ ys) ʳ++ [] ≡⟨ ʳ++-++ xs ⟩
ys ʳ++ xs ʳ++ [] ≡⟨⟩
ys ʳ++ reverse xs ≡⟨ ʳ++-defn ys ⟩
reverse ys ++ reverse xs ∎
-- reverse is involutive.
reverse-involutive : Involutive {A = List A} _≡_ reverse
reverse-involutive xs = begin
reverse (reverse xs) ≡⟨⟩
(xs ʳ++ []) ʳ++ [] ≡⟨ ʳ++-ʳ++ xs ⟩
[] ʳ++ xs ++ [] ≡⟨⟩
xs ++ [] ≡⟨ ++-identityʳ xs ⟩
xs ∎
-- reverse preserves length.
length-reverse : ∀ (xs : List A) → length (reverse xs) ≡ length xs
length-reverse xs = begin
length (reverse xs) ≡⟨⟩
length (xs ʳ++ []) ≡⟨ length-ʳ++ xs ⟩
length xs + 0 ≡⟨ +-identityʳ _ ⟩
length xs ∎
reverse-map-commute : (f : A → B) → map f ∘ reverse ≗ reverse ∘ map f
reverse-map-commute f xs = begin
map f (reverse xs) ≡⟨⟩
map f (xs ʳ++ []) ≡⟨ map-ʳ++ f xs ⟩
map f xs ʳ++ [] ≡⟨⟩
reverse (map f xs) ∎
reverse-foldr : ∀ (f : A → B → B) b →
foldr f b ∘ reverse ≗ foldl (flip f) b
reverse-foldr f b xs = foldr-ʳ++ f b xs
reverse-foldl : ∀ (f : B → A → B) b xs →
foldl f b (reverse xs) ≡ foldr (flip f) b xs
reverse-foldl f b xs = foldl-ʳ++ f b xs
------------------------------------------------------------------------
-- _∷ʳ_
module _ {x y : A} where
∷ʳ-injective : ∀ xs ys → xs ∷ʳ x ≡ ys ∷ʳ y → xs ≡ ys × x ≡ y
∷ʳ-injective [] [] refl = (refl , refl)
∷ʳ-injective (x ∷ xs) (y ∷ ys) eq with ∷-injective eq
... | refl , eq′ = Prod.map (cong (x ∷_)) id (∷ʳ-injective xs ys eq′)
∷ʳ-injective [] (_ ∷ _ ∷ _) ()
∷ʳ-injective (_ ∷ _ ∷ _) [] ()
∷ʳ-injectiveˡ : ∀ (xs ys : List A) → xs ∷ʳ x ≡ ys ∷ʳ y → xs ≡ ys
∷ʳ-injectiveˡ xs ys eq = proj₁ (∷ʳ-injective xs ys eq)
∷ʳ-injectiveʳ : ∀ (xs ys : List A) → xs ∷ʳ x ≡ ys ∷ʳ y → x ≡ y
∷ʳ-injectiveʳ xs ys eq = proj₂ (∷ʳ-injective xs ys eq)
------------------------------------------------------------------------
-- DEPRECATED
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
gfilter-just = mapMaybe-just
{-# WARNING_ON_USAGE gfilter-just
"Warning: gfilter-just was deprecated in v0.15.
Please use mapMaybe-just instead."
#-}
gfilter-nothing = mapMaybe-nothing
{-# WARNING_ON_USAGE gfilter-nothing
"Warning: gfilter-nothing was deprecated in v0.15.
Please use mapMaybe-nothing instead."
#-}
gfilter-concatMap = mapMaybe-concatMap
{-# WARNING_ON_USAGE gfilter-concatMap
"Warning: gfilter-concatMap was deprecated in v0.15.
Please use mapMaybe-concatMap instead."
#-}
length-gfilter = length-mapMaybe
{-# WARNING_ON_USAGE length-gfilter
"Warning: length-gfilter was deprecated in v0.15.
Please use length-mapMaybe instead."
#-}
right-identity-unique = ++-identityʳ-unique
{-# WARNING_ON_USAGE right-identity-unique
"Warning: right-identity-unique was deprecated in v0.15.
Please use ++-identityʳ-unique instead."
#-}
left-identity-unique = ++-identityˡ-unique
{-# WARNING_ON_USAGE left-identity-unique
"Warning: left-identity-unique was deprecated in v0.15.
Please use ++-identityˡ-unique instead."
#-}
-- Version 0.16
module _ (p : A → Bool) where
boolTakeWhile++boolDropWhile : ∀ xs → boolTakeWhile p xs ++ boolDropWhile p xs ≡ xs
boolTakeWhile++boolDropWhile [] = refl
boolTakeWhile++boolDropWhile (x ∷ xs) with p x
... | true = cong (x ∷_) (boolTakeWhile++boolDropWhile xs)
... | false = refl
{-# WARNING_ON_USAGE boolTakeWhile++boolDropWhile
"Warning: boolTakeWhile and boolDropWhile were deprecated in v0.16.
Please use takeWhile and dropWhile instead."
#-}
boolSpan-defn : boolSpan p ≗ < boolTakeWhile p , boolDropWhile p >
boolSpan-defn [] = refl
boolSpan-defn (x ∷ xs) with p x
... | true = cong (Prod.map (x ∷_) id) (boolSpan-defn xs)
... | false = refl
{-# WARNING_ON_USAGE boolSpan-defn
"Warning: boolSpan, boolTakeWhile and boolDropWhile were deprecated in v0.16.
Please use span, takeWhile and dropWhile instead."
#-}
length-boolFilter : ∀ xs → length (boolFilter p xs) ≤ length xs
length-boolFilter xs =
length-mapMaybe (λ x → if p x then just x else nothing) xs
{-# WARNING_ON_USAGE length-boolFilter
"Warning: boolFilter was deprecated in v0.16.
Please use filter instead."
#-}
boolPartition-defn : boolPartition p ≗ < boolFilter p , boolFilter (not ∘ p) >
boolPartition-defn [] = refl
boolPartition-defn (x ∷ xs) with p x
... | true = cong (Prod.map (x ∷_) id) (boolPartition-defn xs)
... | false = cong (Prod.map id (x ∷_)) (boolPartition-defn xs)
{-# WARNING_ON_USAGE boolPartition-defn
"Warning: boolPartition and boolFilter were deprecated in v0.16.
Please use partition and filter instead."
#-}
module _ (P : A → Set p) (P? : Decidable P) where
boolFilter-filters : ∀ xs → All P (boolFilter (isYes ∘ P?) xs)
boolFilter-filters [] = []
boolFilter-filters (x ∷ xs) with P? x
... | true because [px] = invert [px] ∷ boolFilter-filters xs
... | false because _ = boolFilter-filters xs
{-# WARNING_ON_USAGE boolFilter-filters
"Warning: boolFilter was deprecated in v0.16.
Please use filter instead."
#-}
-- Version 0.17
idIsFold = id-is-foldr
{-# WARNING_ON_USAGE idIsFold
"Warning: idIsFold was deprecated in v0.17.
Please use id-is-foldr instead."
#-}
++IsFold = ++-is-foldr
{-# WARNING_ON_USAGE ++IsFold
"Warning: ++IsFold was deprecated in v0.17.
Please use ++-is-foldr instead."
#-}
mapIsFold = map-is-foldr
{-# WARNING_ON_USAGE mapIsFold
"Warning: mapIsFold was deprecated in v0.17.
Please use map-is-foldr instead."
#-}
| 36.842601
| 102
| 0.500128
|
315008bbec41dc6135d8089597aa90339d9d0d95
| 6,686
|
agda
|
Agda
|
old/Homotopy/VanKampen/Guide.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
old/Homotopy/VanKampen/Guide.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
old/Homotopy/VanKampen/Guide.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K #-}
open import Base
module Homotopy.VanKampen.Guide where
open import Homotopy.Truncation
open import Homotopy.Connected
record legend i (city : Set i) : Set (suc i) where
constructor leg_,_,_
field
name : Set i
loc : name → city
all-listed : ∀ c → [ hfiber loc c ]
id-legend : ∀ {i} (A : Set i) → legend i A
id-legend A = leg A , id A , λ x → proj $ x , refl
private
module Book {i} {city : Set i} {l : legend i city} where
open legend l
private
data #guide : Set i where
#point : name → #guide
guide : Set i
guide = #guide
point : name → guide
point = #point
postulate -- HIT
route : ∀ n₁ n₂ → loc n₁ ≡ loc n₂ → point n₁ ≡ point n₂
guide-rec : ∀ {l} (P : guide → Set l)
(point* : (n : name) → P (point n))
(route* : ∀ n₁ n₂ (p : loc n₁ ≡ loc n₂)
→ transport P (route n₁ n₂ p) (point* n₁) ≡ point* n₂)
→ (x : guide) → P x
guide-rec P point* route* (#point n) = point* n
postulate -- HIT
guide-β-route : ∀ {l} (P : guide → Set l)
(point* : (n : name) → P (point n))
(route* : ∀ n₁ n₂ (p : loc n₁ ≡ loc n₂)
→ transport P (route n₁ n₂ p) (point* n₁) ≡ point* n₂)
n₁ n₂ (p : loc n₁ ≡ loc n₂)
→ apd (guide-rec {l} P point* route*) (route n₁ n₂ p)
≡ route* n₁ n₂ p
guide-rec-nondep : ∀ {l} (P : Set l) (point* : name → P)
(route* : ∀ n₁ n₂ → loc n₁ ≡ loc n₂ → point* n₁ ≡ point* n₂)
→ (guide → P)
guide-rec-nondep P point* route* (#point n) = point* n
postulate -- HIT
guide-β-route-nondep : ∀ {l} (P : Set l) (point* : name → P)
(route* : ∀ n₁ n₂ → loc n₁ ≡ loc n₂ → point* n₁ ≡ point* n₂)
n₁ n₂ (p : loc n₁ ≡ loc n₂)
→ ap (guide-rec-nondep P point* route*) (route n₁ n₂ p)
≡ route* n₁ n₂ p
open Book public hiding (guide)
module _ {i} {city : Set i} (l : legend i city) where
open legend l
guide : Set i
guide = Book.guide {i} {city} {l}
visit : guide → city
visit = guide-rec-nondep city loc (λ _ _ p → p)
visit-β-route : ∀ n₁ n₂ (p : loc n₁ ≡ loc n₂) → ap visit (route n₁ n₂ p) ≡ p
visit-β-route = guide-β-route-nondep city loc (λ _ _ p → p)
private
drawn-as-one : ∀ c → is-contr (π₀ $ hfiber visit c)
drawn-as-one c = []-extend-nondep
⦃ is-connected-is-prop ⟨0⟩ ⦄
( λ {(n₁ , p₁) → proj (point n₁ , p₁) , π₀-extend
⦃ λ _ → ≡-is-set $ π₀-is-set $ hfiber visit c ⦄
( uncurry $ guide-rec
(λ x → ∀ p₂ → proj (x , p₂) ≡ proj (point n₁ , p₁))
(λ n₂ p₂ → ap proj let p₃ = p₂ ∘ ! p₁ in
Σ-eq (route n₂ n₁ p₃) $
transport (λ x → visit x ≡ c) (route n₂ n₁ p₃) p₂
≡⟨ trans-app≡cst visit c (route n₂ n₁ p₃) p₂ ⟩
! (ap visit (route n₂ n₁ p₃)) ∘ p₂
≡⟨ ap (λ x → ! x ∘ p₂) $ visit-β-route n₂ n₁ p₃ ⟩
! (p₂ ∘ ! p₁) ∘ p₂
≡⟨ ap (λ x → x ∘ p₂) $ opposite-concat p₂ (! p₁) ⟩
(! (! p₁) ∘ ! p₂) ∘ p₂
≡⟨ concat-assoc (! (! p₁)) (! p₂) p₂ ⟩
! (! p₁) ∘ (! p₂ ∘ p₂)
≡⟨ ap (λ x → ! (! p₁) ∘ x) $ opposite-left-inverse p₂ ⟩
! (! p₁) ∘ refl
≡⟨ refl-right-unit $ ! (! p₁) ⟩
! (! p₁)
≡⟨ opposite-opposite p₁ ⟩∎
p₁
∎)
(λ _ _ _ → funext λ _ → prop-has-all-paths (π₀-is-set _ _ _) _ _))})
(all-listed c)
private
visit-fiber-rec′ : ∀ {j} (P : city → Set j)
(h₀-point : ∀ n → P (loc n))
(h₁-route : ∀ n₁ n₂ r → transport P r (h₀-point n₁) ≡ h₀-point n₂)
→ (∀ c → hfiber visit c → P c)
visit-fiber-rec′ P h₀-p h₁-r c (pt , p₁) =
transport P p₁ $ guide-rec (P ◯ visit) h₀-p
(λ n₁ n₂ r →
transport (P ◯ visit) (route n₁ n₂ r) (h₀-p n₁)
≡⟨ ! $ trans-ap P visit (route n₁ n₂ r) $ h₀-p n₁ ⟩
transport P (ap visit $ route n₁ n₂ r) (h₀-p n₁)
≡⟨ ap (λ x → transport P x $ h₀-p n₁) $ visit-β-route n₁ n₂ r ⟩
transport P r (h₀-p n₁)
≡⟨ h₁-r n₁ n₂ r ⟩∎
h₀-p n₂
∎) pt
visit-fiber-rec : ∀ {j} (P : city → Set j)
⦃ _ : ∀ (c : city) → is-set $ P c ⦄
(h₀-point : ∀ n → P (loc n))
(h₁-route : ∀ n₁ n₂ r → transport P r (h₀-point n₁) ≡ h₀-point n₂)
→ (∀ c → P c)
visit-fiber-rec P ⦃ P-is-set ⦄ h₀-p h₁-r c =
π₀-extend-nondep ⦃ P-is-set c ⦄
(visit-fiber-rec′ P h₀-p h₁-r c)
(π₁ $ drawn-as-one c)
visit-fiber-β-loc : ∀ {j} (P : city → Set j)
⦃ P-is-set : ∀ (c : city) → is-set $ P c ⦄
(h₀-p : ∀ n → P (loc n))
(h₁-r : ∀ n₁ n₂ r → transport P r (h₀-p n₁) ≡ h₀-p n₂)
→ ∀ n → visit-fiber-rec P ⦃ P-is-set ⦄ h₀-p h₁-r (loc n) ≡ h₀-p n
visit-fiber-β-loc P ⦃ P-is-set ⦄ h₀-p h₁-r n =
visit-fiber-rec P ⦃ P-is-set ⦄ h₀-p h₁-r (loc n)
≡⟨ ap (π₀-extend-nondep ⦃ P-is-set $ loc n ⦄ (visit-fiber-rec′ P h₀-p h₁-r $ loc n))
$ ! $ π₂ (drawn-as-one $ loc n) (proj $ point n , refl) ⟩∎
h₀-p n
∎
private
loc-fiber-rec′ : ∀ {j} (P : city → Set j)
(h₀-point : ∀ n → P (loc n))
→ (∀ c → hfiber loc c → P c)
loc-fiber-rec′ P h₀-p c (n , p) = transport P p (h₀-p n)
loc-fiber-rec : ∀ {j} (P : city → Set j)
⦃ _ : ∀ c → is-prop $ P c ⦄
(h₀-point : ∀ n → P (loc n))
→ (∀ c → P c)
loc-fiber-rec P ⦃ P-is-prop ⦄ h₀-p c = []-extend-nondep ⦃ P-is-prop c ⦄
(loc-fiber-rec′ P h₀-p c) (all-listed c)
loc-fiber-β-loc : ∀ {j} (P : city → Set j)
⦃ P-is-prop : ∀ (c : city) → is-prop $ P c ⦄
(h₀-p : ∀ n → P (loc n))
→ ∀ n → loc-fiber-rec P ⦃ P-is-prop ⦄ h₀-p (loc n) ≡ h₀-p n
loc-fiber-β-loc P ⦃ P-is-prop ⦄ h₀-p n =
loc-fiber-rec P ⦃ P-is-prop ⦄ h₀-p (loc n)
≡⟨ ap ([]-extend-nondep ⦃ P-is-prop $ loc n ⦄ (loc-fiber-rec′ P h₀-p $ loc n))
$ prop-has-all-paths []-is-prop (all-listed $ loc n) $ proj $ n , refl ⟩∎
h₀-p n
∎
-- Did I preserve the computational contents for identity legend?
private
module IdTest {i} {city : Set i} where
open legend (id-legend city)
visit-fiber-β-id : ∀ {j} (P : city → Set j)
⦃ P-is-set : ∀ (c : city) → is-set $ P c ⦄
(h₀-p : ∀ n → P n)
(h₁-r : ∀ n₁ n₂ r → transport P r (h₀-p n₁) ≡ h₀-p n₂)
→ ∀ n → visit-fiber-rec (id-legend city) P ⦃ P-is-set ⦄ h₀-p h₁-r n ≡ h₀-p n
visit-fiber-β-id P ⦃ P-is-set ⦄ h₀-p h₁-r n = refl
loc-fiber-β-id : ∀ {j} (P : city → Set j)
⦃ P-is-prop : ∀ (c : city) → is-prop $ P c ⦄
(h₀-p : ∀ n → P n)
→ ∀ n → loc-fiber-rec (id-legend city) P ⦃ P-is-prop ⦄ h₀-p n ≡ h₀-p n
loc-fiber-β-id P ⦃ P-is-prop ⦄ h₀-p n = refl
| 35.56383
| 90
| 0.485343
|
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.