Search is not available for this dataset
text
string | meta
dict |
---|---|
open import Common.Reflection
open import Common.Prelude
open import Common.Equality
open import Agda.Builtin.Sigma
pattern `Nat = def (quote Nat) []
pattern _`→_ a b = pi (vArg a) (abs "_" b)
pattern `Set = sort (lit 0)
pattern `⊥ = def (quote ⊥) []
pattern `zero = con (quote zero) []
pattern `suc n = con (quote suc) (vArg n ∷ [])
prDef : FunDef
prDef =
funDef (`Nat `→ `Nat)
( clause [] [] (extLam ( clause [] (vArg `zero ∷ []) `zero
∷ clause (("x" , vArg `Nat) ∷ []) (vArg (`suc (var 0)) ∷ []) (var 0 [])
∷ []) [])
∷ [] )
magicDef : FunDef
magicDef =
funDef (pi (hArg `Set) (abs "A" (`⊥ `→ var 1 [])))
( clause [] [] (extLam ( absurdClause (("()" , vArg `⊥) ∷ []) (vArg absurd ∷ [])
∷ []) [])
∷ [] )
unquoteDecl magic = define (vArg magic) magicDef
checkMagic : {A : Set} → ⊥ → A
checkMagic = magic
unquoteDecl pr = define (vArg pr) prDef
magic′ : {A : Set} → ⊥ → A
magic′ = unquote (give (extLam (absurdClause (("()" , vArg `⊥) ∷ []) (vArg absurd ∷ []) ∷ []) []))
module Pred (A : Set) where
unquoteDecl pr′ = define (vArg pr′) prDef
check : pr 10 ≡ 9
check = refl
check′ : Pred.pr′ ⊥ 10 ≡ 9
check′ = refl
|
{
"alphanum_fraction": 0.511517077,
"avg_line_length": 26.2291666667,
"ext": "agda",
"hexsha": "15170e75a845fccf29acde8443d184475635d913",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/UnquoteExtLam.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/UnquoteExtLam.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/UnquoteExtLam.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 436,
"size": 1259
}
|
{- 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.ImplShared.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import Util.PKCS
open import Util.Prelude
open import Yasm.Base
-- This module collects in one place the obligations an
-- implementation must meet in order to enjoy the properties
-- proved in Abstract.Properties.
module LibraBFT.Concrete.Obligations (iiah : SystemInitAndHandlers ℓ-RoundManager ConcSysParms) (𝓔 : EpochConfig) where
import LibraBFT.Concrete.Properties.PreferredRound iiah as PR
import LibraBFT.Concrete.Properties.VotesOnce iiah as VO
import LibraBFT.Concrete.Properties.Common iiah as Common
open SystemTypeParameters ConcSysParms
open SystemInitAndHandlers iiah
open ParamsWithInitAndHandlers iiah
open import Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms iiah
PeerCanSignForPK PeerCanSignForPK-stable
record ImplObligations : Set (ℓ+1 ℓ-RoundManager) where
field
-- Structural obligations:
sps-cor : StepPeerState-AllValidParts
-- Semantic obligations:
--
-- VotesOnce:
bsvc : Common.ImplObl-bootstrapVotesConsistent 𝓔
bsvr : Common.ImplObl-bootstrapVotesRound≡0 𝓔
v≢0 : Common.ImplObl-NewVoteRound≢0 𝓔
∈BI? : (sig : Signature) → Dec (∈BootstrapInfo bootstrapInfo sig)
v4rc : PR.ImplObligation-RC 𝓔
iro : Common.IncreasingRoundObligation 𝓔
vo₂ : VO.ImplObligation₂ 𝓔
-- PreferredRound:
pr₁ : PR.ImplObligation₁ 𝓔
pr₂ : PR.ImplObligation₂ 𝓔
|
{
"alphanum_fraction": 0.7361464159,
"avg_line_length": 37.1132075472,
"ext": "agda",
"hexsha": "e23c3ff48cf82582086fb852928bee209ea4676f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Concrete/Obligations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Concrete/Obligations.agda",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Concrete/Obligations.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 562,
"size": 1967
}
|
module _ where
open import Common.Prelude hiding (_>>=_)
open import Common.Reflection
open import Common.Equality
infix 0 case_of_
case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = f x
blockOnFresh : TC ⊤
blockOnFresh =
checkType unknown unknown >>= λ
{ (meta m _) → blockOnMeta m
; _ → typeError (strErr "impossible" ∷ []) }
macro
shouldNotCrash : Tactic
shouldNotCrash hole = blockOnFresh
-- Should leave some yellow and a constraint 'unquote shouldNotCrash : Nat'
n : Nat
n = shouldNotCrash
|
{
"alphanum_fraction": 0.6865671642,
"avg_line_length": 21.44,
"ext": "agda",
"hexsha": "32fe6f6609c93ea2a836e23e8f59acb921f432f4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/BlockOnFreshMeta.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/BlockOnFreshMeta.agda",
"max_line_length": 75,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/BlockOnFreshMeta.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 173,
"size": 536
}
|
-- There was a bug with the open M es syntax.
module Issue31 where
record M : Set1 where
field
A : Set
module MOps (m : M) where
open M m public
postulate m : M
open MOps m hiding (A)
open MOps m using (A)
postulate foo : A -> Set
module AnotherBug where
postulate Z : Set
module A (X : Set) where
postulate H : Set
module B (Y : Set) where
module C where
open A Z
open B Z public
postulate H : Set
open C
X = H
|
{
"alphanum_fraction": 0.6339869281,
"avg_line_length": 12.75,
"ext": "agda",
"hexsha": "1fd3ab9fe73e0df6b231ca6462da7e03ee700f7f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue31.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue31.agda",
"max_line_length": 45,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue31.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 150,
"size": 459
}
|
module Control.Monad.Reader where
open import Prelude
open import Control.Monad.Zero
open import Control.Monad.Identity
open import Control.Monad.Transformer
record ReaderT {a} (R : Set a) (M : Set a → Set a) (A : Set a) : Set a where
no-eta-equality
constructor readerT
field runReaderT : R → M A
open ReaderT public
module _ {a} {R : Set a} {M : Set a → Set a} where
instance
FunctorReaderT : {{_ : Functor M}} → Functor {a = a} (ReaderT R M)
runReaderT (fmap {{ FunctorReaderT }} f m) r = f <$> runReaderT m r
FunctorZeroReaderT : {{_ : FunctorZero M}} → FunctorZero {a = a} (ReaderT R M)
runReaderT (empty {{FunctorZeroReaderT}}) r = empty
AlternativeReaderT : {{_ : Alternative M}} → Alternative {a = a} (ReaderT R M)
runReaderT (_<|>_ {{AlternativeReaderT}} x y) r = runReaderT x r <|> runReaderT y r
module _ {{_ : Monad M}} where
private
bindReaderT : ∀ {A B} → ReaderT R M A → (A → ReaderT R M B) → ReaderT R M B
runReaderT (bindReaderT m f) r = runReaderT m r >>= λ x → runReaderT (f x) r
instance
ApplicativeReaderT : Applicative {a = a} (ReaderT R M)
runReaderT (pure {{ApplicativeReaderT}} x) r = pure x
_<*>_ {{ApplicativeReaderT}} = monadAp bindReaderT
MonadReaderT : Monad {a = a} (ReaderT R M)
_>>=_ {{MonadReaderT}} = bindReaderT
liftReaderT : {A : Set a} → M A → ReaderT R M A
runReaderT (liftReaderT m) r = m
asks : {A : Set a} → (R → A) → ReaderT R M A
runReaderT (asks f) r = return (f r)
ask : ReaderT R M R
ask = asks id
local : {A : Set a} → (R → R) → ReaderT R M A → ReaderT R M A
runReaderT (local f m) r = runReaderT m (f r)
instance
TransformerReaderT : ∀ {a} {R : Set a} → Transformer (ReaderT R)
lift {{TransformerReaderT}} = liftReaderT
Reader : ∀ {a} (R : Set a) (A : Set a) → Set a
Reader R = ReaderT R Identity
runReader : ∀ {a} {R : Set a} {A : Set a} → Reader R A → R → A
runReader m r = runIdentity (runReaderT m r)
|
{
"alphanum_fraction": 0.6208625878,
"avg_line_length": 31.6507936508,
"ext": "agda",
"hexsha": "ed9d8c08c13764fa0a4a4013c8bd292500bd22fa",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Control/Monad/Reader.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "t-more/agda-prelude",
"max_issues_repo_path": "src/Control/Monad/Reader.agda",
"max_line_length": 87,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Control/Monad/Reader.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 676,
"size": 1994
}
|
module BasicT.Metatheory.GentzenNormalForm-Unknown where
open import BasicT.Syntax.GentzenNormalForm public
-- Forcing. (In a particular model?)
infix 3 _⊩_
_⊩_ : Cx Ty → Ty → Set
Γ ⊩ α P = Γ ⊢ⁿᶠ α P
Γ ⊩ A ▻ B = Γ ⊢ⁿᵉ A ▻ B ⊎ ∀ {Γ′} → Γ ⊆ Γ′ → Γ′ ⊩ A → Γ′ ⊩ B
Γ ⊩ A ∧ B = Γ ⊢ⁿᵉ A ∧ B ⊎ Γ ⊩ A × Γ ⊩ B
Γ ⊩ ⊤ = Γ ⊢ⁿᶠ ⊤
Γ ⊩ BOOL = Γ ⊢ⁿᶠ BOOL
Γ ⊩ NAT = Γ ⊢ⁿᶠ NAT
infix 3 _⊩⋆_
_⊩⋆_ : Cx Ty → Cx Ty → Set
Γ ⊩⋆ ∅ = 𝟙
Γ ⊩⋆ Ξ , A = Γ ⊩⋆ Ξ × Γ ⊩ A
-- Monotonicity with respect to context inclusion.
mono⊩ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩ A → Γ′ ⊩ A
mono⊩ {α P} η t = mono⊢ⁿᶠ η t
mono⊩ {A ▻ B} η (ι₁ t) = ι₁ (mono⊢ⁿᵉ η t)
mono⊩ {A ▻ B} η (ι₂ s) = ι₂ (λ η′ a → s (trans⊆ η η′) a)
mono⊩ {A ∧ B} η (ι₁ t) = ι₁ (mono⊢ⁿᵉ η t)
mono⊩ {A ∧ B} η (ι₂ s) = ι₂ (mono⊩ {A} η (π₁ s) , mono⊩ {B} η (π₂ s))
mono⊩ {⊤} η t = mono⊢ⁿᶠ η t
mono⊩ {BOOL} η t = mono⊢ⁿᶠ η t
mono⊩ {NAT} η t = mono⊢ⁿᶠ η t
mono⊩⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩⋆ Ξ → Γ′ ⊩⋆ Ξ
mono⊩⋆ {∅} η ∙ = ∙
mono⊩⋆ {Ξ , A} η (γ , a) = mono⊩⋆ {Ξ} η γ , mono⊩ {A} η a
-- Soundness and completeness. (With respect to a particular model?)
reflect : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊩ A
reflect {α P} t = neⁿᶠ t
reflect {A ▻ B} t = ι₁ t
reflect {A ∧ B} t = ι₁ t
reflect {⊤} t = neⁿᶠ t
reflect {BOOL} t = neⁿᶠ t
reflect {NAT} t = neⁿᶠ t
reify : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ⁿᶠ A
reify {α P} t = t
reify {A ▻ B} (ι₁ t) = neⁿᶠ t
reify {A ▻ B} (ι₂ s) = lamⁿᶠ (reify (s weak⊆ (reflect {A} (varⁿᵉ top))))
reify {A ∧ B} (ι₁ t) = neⁿᶠ t
reify {A ∧ B} (ι₂ s) = pairⁿᶠ (reify (π₁ s)) (reify (π₂ s))
reify {⊤} t = t
reify {BOOL} t = t
reify {NAT} t = t
reflect⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ⁿᵉ Ξ → Γ ⊩⋆ Ξ
reflect⋆ {∅} ∙ = ∙
reflect⋆ {Ξ , A} (ts , t) = reflect⋆ ts , reflect t
reify⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ ⊢⋆ⁿᶠ Ξ
reify⋆ {∅} ∙ = ∙
reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t
-- Additional useful equipment.
_⟪$⟫_ : ∀ {A B w} → w ⊩ A ▻ B → w ⊩ A → w ⊩ B
ι₁ t ⟪$⟫ a = reflect (appⁿᵉ t (reify a))
ι₂ s ⟪$⟫ a = s refl⊆ a
⟪π₁⟫ : ∀ {A B w} → w ⊩ A ∧ B → w ⊩ A
⟪π₁⟫ (ι₁ t) = reflect (fstⁿᵉ t)
⟪π₁⟫ (ι₂ s) = π₁ s
⟪π₂⟫ : ∀ {A B w} → w ⊩ A ∧ B → w ⊩ B
⟪π₂⟫ (ι₁ t) = reflect (sndⁿᵉ t)
⟪π₂⟫ (ι₂ s) = π₂ s
⟪if⟫ : ∀ {C w} → w ⊩ BOOL → w ⊩ C → w ⊩ C → w ⊩ C
⟪if⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (ifⁿᵉ t (reify s₂) (reify s₃))
⟪if⟫ {C} trueⁿᶠ s₂ s₃ = s₂
⟪if⟫ {C} falseⁿᶠ s₂ s₃ = s₃
⟪it⟫ : ∀ {C w} → w ⊩ NAT → w ⊩ C ▻ C → w ⊩ C → w ⊩ C
⟪it⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (itⁿᵉ t (reify s₂) (reify s₃))
⟪it⟫ {C} zeroⁿᶠ s₂ s₃ = s₃
⟪it⟫ {C} (sucⁿᶠ t) s₂ s₃ = s₂ ⟪$⟫ ⟪it⟫ t s₂ s₃
⟪rec⟫ : ∀ {C w} → w ⊩ NAT → w ⊩ NAT ▻ C ▻ C → w ⊩ C → w ⊩ C
⟪rec⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (recⁿᵉ t (reify s₂) (reify s₃))
⟪rec⟫ {C} zeroⁿᶠ s₂ s₃ = s₃
⟪rec⟫ {C} (sucⁿᶠ t) s₂ s₃ = (s₂ ⟪$⟫ t) ⟪$⟫ ⟪rec⟫ t s₂ s₃
-- Forcing for sequents. (In a particular world of a particular model?)
infix 3 _⊩_⇒_
_⊩_⇒_ : Cx Ty → Cx Ty → Ty → Set
w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A
infix 3 _⊩_⇒⋆_
_⊩_⇒⋆_ : Cx Ty → Cx Ty → Cx Ty → Set
w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ
-- Entailment. (Forcing in all worlds of all models, for sequents?)
infix 3 _⊨_
_⊨_ : Cx Ty → Ty → Set
Γ ⊨ A = ∀ {w : Cx Ty} → w ⊩ Γ ⇒ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx Ty → Cx Ty → Set
Γ ⊨⋆ Ξ = ∀ {w : Cx Ty} → w ⊩ Γ ⇒⋆ Ξ
-- Additional useful equipment, for sequents.
lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
-- Evaluation. (Soundness with respect to all models?)
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = ι₂ (λ η a → eval t (mono⊩⋆ η γ , a))
eval (app t u) γ = eval t γ ⟪$⟫ eval u γ
eval (pair t u) γ = ι₂ (eval t γ , eval u γ)
eval (fst t) γ = ⟪π₁⟫ (eval t γ)
eval (snd t) γ = ⟪π₂⟫ (eval t γ)
eval unit γ = unitⁿᶠ
eval true γ = trueⁿᶠ
eval false γ = trueⁿᶠ
eval (if {C} t u v) γ = ⟪if⟫ {C} (eval t γ) (eval u γ) (eval v γ)
eval zero γ = zeroⁿᶠ
eval (suc t) γ = sucⁿᶠ (eval t γ)
eval (it {C} t u v) γ = ⟪it⟫ {C} (eval t γ) (eval u γ) (eval v γ)
eval (rec {C} t u v) γ = ⟪rec⟫ {C} (eval t γ) (eval u γ) (eval v γ)
eval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ
eval⋆ {∅} ∙ γ = ∙
eval⋆ {Ξ , A} (ts , t) γ = eval⋆ ts γ , eval t γ
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ
refl⊩⋆ = reflect⋆ refl⊢⋆ⁿᵉ
trans⊩⋆ : ∀ {Γ Γ′ Γ″} → Γ ⊩⋆ Γ′ → Γ′ ⊩⋆ Γ″ → Γ ⊩⋆ Γ″
trans⊩⋆ ts us = eval⋆ (trans⊢⋆ (nf→tm⋆ (reify⋆ ts)) (nf→tm⋆ (reify⋆ us))) refl⊩⋆
-- Quotation. (Completeness with respect to all models?)
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A
quot s = nf→tm (reify (s refl⊩⋆))
-- Normalisation by evaluation.
norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
|
{
"alphanum_fraction": 0.4814814815,
"avg_line_length": 27.4682080925,
"ext": "agda",
"hexsha": "4dd08a6a469b53f09b204d9e2045cefa41681e20",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicT/Metatheory/GentzenNormalForm-Unknown.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicT/Metatheory/GentzenNormalForm-Unknown.agda",
"max_line_length": 80,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicT/Metatheory/GentzenNormalForm-Unknown.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 2824,
"size": 4752
}
|
module Logics.And where
open import Function
------------------------------------------------------------------------
-- definitions
infixl 5 _∧_
infixl 4 _⇔_
data _∧_ (P Q : Set) : Set where
∧-intro : P → Q → P ∧ Q
_⇔_ : (P Q : Set) → Set
p ⇔ q = (p → q) ∧ (q → p)
------------------------------------------------------------------------
-- internal stuffs
private
∧-comm′ : ∀ {P Q} → (P ∧ Q) → (Q ∧ P)
∧-comm′ (∧-intro p q) = ∧-intro q p
∧-assoc₀ : ∀ {P Q R} → ((P ∧ Q) ∧ R) → (P ∧ (Q ∧ R))
∧-assoc₀ (∧-intro (∧-intro p q) r) = ∧-intro p $ ∧-intro q r
∧-assoc₁ : ∀ {P Q R} → (P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R)
∧-assoc₁ (∧-intro p (∧-intro q r)) = ∧-intro (∧-intro p q) r
∧-comm : ∀ {P Q} → (P ∧ Q) ⇔ (Q ∧ P)
∧-comm = ∧-intro ∧-comm′ ∧-comm′
∧-assoc : ∀ {P Q R} → (P ∧ (Q ∧ R)) ⇔ ((P ∧ Q) ∧ R)
∧-assoc = ∧-intro ∧-assoc₁ ∧-assoc₀
------------------------------------------------------------------------
-- public aliases
and-comm : ∀ {P Q} → (P ∧ Q) ⇔ (Q ∧ P)
and-comm = ∧-comm
and-assoc : ∀ {P Q R} → (P ∧ (Q ∧ R)) ⇔ ((P ∧ Q) ∧ R)
and-assoc = ∧-assoc
|
{
"alphanum_fraction": 0.3535911602,
"avg_line_length": 23.6086956522,
"ext": "agda",
"hexsha": "6c97c3591f3e96fc0336ece9cc7ab262f74172ee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Logics/And.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ice1k/Theorems",
"max_issues_repo_path": "src/Logics/And.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Logics/And.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 422,
"size": 1086
}
|
module NoQualifiedInstances.ParameterizedImport.A (T : Set) where
record I : Set where
postulate instance i : I
|
{
"alphanum_fraction": 0.7807017544,
"avg_line_length": 19,
"ext": "agda",
"hexsha": "dcc04e1544f126e424519c78ab8a07108ce45307",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/NoQualifiedInstances/ParameterizedImport/A.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/NoQualifiedInstances/ParameterizedImport/A.agda",
"max_line_length": 65,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/NoQualifiedInstances/ParameterizedImport/A.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 28,
"size": 114
}
|
module Data.Tuple.List{ℓ} where
import Lvl
open import Data using (Unit ; <>)
open import Data.Tuple using (_⨯_ ; _,_)
import Data.List
open Data.List using (List)
open import Type{ℓ}
-- Constructs a tuple from a list
Tuple : List(Type) → Type
Tuple(List.∅) = Unit
Tuple(T List.⊰ List.∅) = T
Tuple(T List.⊰ L) = (T ⨯ Tuple(L))
pattern ∅ = <>
pattern _⊰∅ a = a
pattern _⊰+_ a l = (a , l)
import Data.List.Functions as List
_⊰_ : ∀{T}{L} → T → Tuple(L) → Tuple(T List.⊰ L)
_⊰_ {_}{List.∅} a _ = a
_⊰_ {_}{_ List.⊰ _} a l = (a , l)
head : ∀{T}{L} → Tuple(T List.⊰ L) → T
head{_}{List.∅} (a ⊰∅) = a
head{_}{_ List.⊰ _}(a ⊰+ _) = a
tail : ∀{T}{L} → Tuple(T List.⊰ L) → Tuple(L)
tail{_}{List.∅} (_ ⊰∅) = ∅
tail{_}{_ List.⊰ _}(_ ⊰+ l) = l
module _ where
open import Data.List.Equiv.Id
open import Data.List.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Relator
open import Structure.Operator.Properties
_++_ : ∀{L₁ L₂} → Tuple(L₁) → Tuple(L₂) → Tuple(L₁ List.++ L₂)
_++_{L} {List.∅} (l)(_) = substitute₁ₗ(Tuple) {y = L} (identityᵣ(List._++_)(List.∅)) l
_++_{List.∅} {_} (_)(l) = l
_++_{A List.⊰ List.∅} {L₂} (a ⊰∅) (l₂) = _⊰_ {A}{L₂} (a) (l₂)
_++_{A List.⊰ B List.⊰ L₁}{L₂} (a ⊰+ l₁)(l₂) = _⊰_ {A}{(B Data.List.⊰ L₁) List.++ L₂} (a) (_++_ {B Data.List.⊰ L₁}{L₂} l₁ l₂)
module _ where
open import Numeral.Natural
length : ∀{L} → Tuple(L) → ℕ
length{L} (_) = List.length(L)
-- TODO: TupleRaise : Tuple(repeat(n)(T)) ≡ T ^ n
|
{
"alphanum_fraction": 0.5351851852,
"avg_line_length": 29.4545454545,
"ext": "agda",
"hexsha": "2cafc335918adbfd02ba4661f1b7d7e6b00fd942",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/Tuple/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/Tuple/List.agda",
"max_line_length": 131,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/Tuple/List.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 695,
"size": 1620
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Empty.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty.Base
isProp⊥ : isProp ⊥
isProp⊥ ()
isContr⊥→A : ∀ {ℓ} {A : Type ℓ} → isContr (⊥ → A)
fst isContr⊥→A ()
snd isContr⊥→A f i ()
|
{
"alphanum_fraction": 0.6918429003,
"avg_line_length": 20.6875,
"ext": "agda",
"hexsha": "fdc609563a0452c919bd941b47b1f88673b67f5b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Data/Empty/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Data/Empty/Properties.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Data/Empty/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 116,
"size": 331
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Impl.Consensus.EpochManagerTypes
import LibraBFT.Impl.Consensus.ConsensusProvider as ConsensusProvider
import LibraBFT.Impl.IO.OBM.GenKeyFile as GenKeyFile
import LibraBFT.Impl.IO.OBM.ObmNeedFetch as ObmNeedFetch
import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.Prelude
open import Optics.All
module LibraBFT.Impl.IO.OBM.Start where
{-
This only does the initialization steps from the Haskell version.
If initialization succeeds, it returns
- the EpochManager (for all epochs)
- note: this contains the initialized RoundManager for the current epoch (i.e., Epoch 0)
- any output from the RoundManager produced during initialization
The only output is (with info logging removed):
-- only the leader of round 1 will broadcast a proposal
BroadcastProposal; [ ... peer addresses ... ];
(ProposalMsg
(B 7194dca (BD 1 1 (Prop ("TX/1/1")) ...)) -- proposed block
(SI (hqc c66a132) (hcc N) (htc (TC N)))) -- SyncInfo
The Haskell code, after initialization, hooks up the communication channels and sockets
and starts threads that handle them. One of the threads is given to
EpochManager.obmStartLoop to get input and pass it through the EpochManager
and then (usually) on to the RoundMnager.
TODO-3: Replace 'Handle.initRM' with the initialized RoundManager obtained
through the following 'startViaConsensusProvider'.
TODO-3: Figure out how to handle the initial BroadcastProposal.
-}
startViaConsensusProvider
: Instant
→ GenKeyFile.NfLiwsVsVvPe
→ TxTypeDependentStuffForNetwork
→ Either ErrLog (EpochManager × List Output)
startViaConsensusProvider now (nf , liws , vs , vv , pe) txTDS = do
(nc , occp , _liws , sk , _pe) ← ConsensusProvider.obmInitialData (nf , liws , vs , vv , pe)
ConsensusProvider.startConsensus
nc now occp liws sk
(ObmNeedFetch∙new {- newNetwork -stps'-})
(txTDS ^∙ ttdsnProposalGenerator) (txTDS ^∙ ttdsnStateComputer)
|
{
"alphanum_fraction": 0.7425200169,
"avg_line_length": 43.1454545455,
"ext": "agda",
"hexsha": "7e96b8c7fc538c4290f4508423425c9913578658",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z",
"max_forks_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "oracle/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/IO/OBM/Start.agda",
"max_issues_count": 72,
"max_issues_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "oracle/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/IO/OBM/Start.agda",
"max_line_length": 111,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "oracle/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/IO/OBM/Start.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z",
"num_tokens": 638,
"size": 2373
}
|
{-# OPTIONS --without-K --safe #-}
module Dodo.Unary.Intersection where
-- Stdlib imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (refl; _≡_)
open import Level using (Level; _⊔_)
open import Function using (_∘₂_)
open import Data.Product using (_×_; _,_; swap; proj₁; proj₂)
open import Relation.Unary using (Pred)
open import Relation.Binary using (Rel; REL)
-- Local imports
open import Dodo.Unary.Equality
open import Dodo.Unary.Unique
-- # Definitions
infixr 30 _∩₁_
_∩₁_ : {a ℓ₁ ℓ₂ : Level} {A : Set a}
→ Pred A ℓ₁
→ Pred A ℓ₂
→ Pred A (ℓ₁ ⊔ ℓ₂)
_∩₁_ p q x = p x × q x
-- # Properties
module _ {a ℓ : Level} {A : Set a} {P : Pred A ℓ} where
∩₁-idem : (P ∩₁ P) ⇔₁ P
∩₁-idem = ⇔: (λ _ → proj₁) ⊇-proof
where
⊇-proof : P ⊆₁' (P ∩₁ P)
⊇-proof _ Px = (Px , Px)
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {Q : Pred A ℓ₂} where
∩₁-comm : (P ∩₁ Q) ⇔₁ (Q ∩₁ P)
∩₁-comm = ⇔: (λ _ → swap) (λ _ → swap)
module _ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}
{P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} where
∩₁-assoc : P ∩₁ (Q ∩₁ R) ⇔₁ (P ∩₁ Q) ∩₁ R
∩₁-assoc = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : P ∩₁ (Q ∩₁ R) ⊆₁' (P ∩₁ Q) ∩₁ R
⊆-proof _ (Px , Qx , Rx) = ((Px , Qx) , Rx)
⊇-proof : (P ∩₁ Q) ∩₁ R ⊆₁' P ∩₁ (Q ∩₁ R)
⊇-proof _ ((Px , Qx) , Rx) = (Px , Qx , Rx)
-- # Operations
-- ## Operations: General
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {Q : Pred A ℓ₂} where
∩₁-unique-pred :
UniquePred P
→ UniquePred Q
→ UniquePred (P ∩₁ Q)
∩₁-unique-pred uniqueP uniqueQ x (Px₁ , Qx₁) (Px₂ , Qx₂)
with uniqueP x Px₁ Px₂ | uniqueQ x Qx₁ Qx₂
... | refl | refl = refl
-- ## Operations: ⊆₁
module _ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}
{P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} where
∩₁-combine-⊆₁ : P ⊆₁ Q → P ⊆₁ R → P ⊆₁ (Q ∩₁ R)
∩₁-combine-⊆₁ (⊆: P⊆Q) (⊆: P⊆R) = ⊆: (λ x Px → (P⊆Q x Px , P⊆R x Px))
module _ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}
{P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} where
∩₁-introˡ-⊆₁ : (P ∩₁ Q) ⊆₁ P
∩₁-introˡ-⊆₁ = ⊆: (λ _ → proj₁)
∩₁-introʳ-⊆₁ : (P ∩₁ Q) ⊆₁ Q
∩₁-introʳ-⊆₁ = ⊆: (λ _ → proj₂)
∩₁-elimˡ-⊆₁ : P ⊆₁ (Q ∩₁ R) → P ⊆₁ R
∩₁-elimˡ-⊆₁ (⊆: P⊆[Q∩R]) = ⊆: (λ x Px → proj₂ (P⊆[Q∩R] x Px))
∩₁-elimʳ-⊆₁ : P ⊆₁ (Q ∩₁ R) → P ⊆₁ Q
∩₁-elimʳ-⊆₁ (⊆: P⊆[Q∩R]) = ⊆: (λ x Px → proj₁ (P⊆[Q∩R] x Px))
module _ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}
{P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} where
∩₁-substˡ-⊆₁ : P ⊆₁ Q → (P ∩₁ R) ⊆₁ (Q ∩₁ R)
∩₁-substˡ-⊆₁ (⊆: P⊆Q) = ⊆: lemma
where
lemma : (P ∩₁ R) ⊆₁' (Q ∩₁ R)
lemma x (Px , Rx) = (P⊆Q x Px , Rx)
∩₁-substʳ-⊆₁ : P ⊆₁ Q → (R ∩₁ P) ⊆₁ (R ∩₁ Q)
∩₁-substʳ-⊆₁ (⊆: P⊆Q) = ⊆: lemma
where
lemma : (R ∩₁ P) ⊆₁' (R ∩₁ Q)
lemma x (Rx , Px) = (Rx , P⊆Q x Px)
-- ## Operations: ⇔₂
module _ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}
{P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} where
∩₁-substˡ : P ⇔₁ Q → (P ∩₁ R) ⇔₁ (Q ∩₁ R)
∩₁-substˡ = ⇔₁-compose ∩₁-substˡ-⊆₁ ∩₁-substˡ-⊆₁
∩₁-substʳ : P ⇔₁ Q → (R ∩₁ P) ⇔₁ (R ∩₁ Q)
∩₁-substʳ = ⇔₁-compose ∩₁-substʳ-⊆₁ ∩₁-substʳ-⊆₁
|
{
"alphanum_fraction": 0.5079465989,
"avg_line_length": 25.3709677419,
"ext": "agda",
"hexsha": "254f41123241614b94da94e6c7d6c439f6a7bb81",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Unary/Intersection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Unary/Intersection.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Unary/Intersection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1711,
"size": 3146
}
|
{-# OPTIONS --cubical #-}
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Unit
data S : Set where
base : S
foo : ∀ i j k → Partial _ S
foo i j k (i = i0)(k = i1) = base
foo i j k (j = i1) = base
-- Testing that fallthrough patterns get expanded when compiling the
-- clauses of foo.
-- Just because (i = i0) matches the first clause doesn't mean we commit to it.
-- `foo i0 i1 k o` should still compute to base by the second clause.
testf : ∀ k (o : IsOne i1) → foo i0 i1 k o ≡ base
testf k o i = base
|
{
"alphanum_fraction": 0.6666666667,
"avg_line_length": 27,
"ext": "agda",
"hexsha": "f65357e3f10a375b43ed20ff2f2c3d30563cb1d9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3628.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3628.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3628.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 181,
"size": 567
}
|
module Relation.Unary.Membership {a} (A : Set a) where
open import Level
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Relation.Unary
open import Relation.Binary
infixl 4 _≋_
_≋_ : Rel (Pred A a) _
P ≋ Q = P ⊆′ Q × Q ⊆′ P
⊆-refl : Reflexive (_⊆′_ {a} {A} {a})
⊆-refl {pred} x P = P
≋-refl : Reflexive _≋_
≋-refl {pred} = (⊆-refl {pred}) , (⊆-refl {pred})
≋-sym : Symmetric _≋_
≋-sym x = (proj₂ x) , (proj₁ x)
≋-trans : Transitive _≋_
≋-trans f≋g g≋h =
(λ x z → proj₁ g≋h x (proj₁ f≋g x z)) , (λ x z → proj₂ f≋g x (proj₂ g≋h x z))
≋-isEquivalence : IsEquivalence _≋_
≋-isEquivalence = record
{ refl = ≋-refl
; sym = ≋-sym
; trans = ≋-trans
}
⊆-trans : Transitive (_⊆′_ {a} {A} {a})
⊆-trans A⊆B B⊆C x x∈A = B⊆C x (A⊆B x x∈A)
⊆-preorder : IsPreorder _≋_ _⊆′_
⊆-preorder = record
{ isEquivalence = ≋-isEquivalence
; reflexive = proj₁
; trans = ⊆-trans
}
⊆-partialOrder : IsPartialOrder _≋_ _⊆′_
⊆-partialOrder = record
{ isPreorder = ⊆-preorder
; antisym = λ A⊆B B⊆A → A⊆B , B⊆A
}
⊆-poset : Poset (suc a) a a
⊆-poset = record
{ Carrier = Pred A a
; _≈_ = _≋_
; _≤_ = _⊆′_
; isPartialOrder = ⊆-partialOrder
}
module ⊆-Reasoning where
import Relation.Binary.PartialOrderReasoning as PosetR
open PosetR ⊆-poset public
renaming (_≤⟨_⟩_ to _⊆⟨_⟩_)
infix 1 _∈⟨_⟩_
infixr 2 _→⟨_⟩_
_∈⟨_⟩_ : ∀ x {xs ys} → x ∈ xs → xs IsRelatedTo ys → x ∈ ys
x ∈⟨ x∈xs ⟩ xs⊆ys = begin_ xs⊆ys x x∈xs
_→⟨_⟩_ : ∀ A {B C} → (A ⊆ B) → B IsRelatedTo C → A IsRelatedTo C
A →⟨ f ⟩ B∼C = A ⊆⟨ (λ x x∈A → f x∈A) ⟩ B∼C
-- A ⊆[ f ] relTo B∼C = A ⊆⟨ f ⟩ relTo B∼C
--
--(begin xs⊆ys) x∈xs
|
{
"alphanum_fraction": 0.5506736965,
"avg_line_length": 23.3835616438,
"ext": "agda",
"hexsha": "46f863ac7f1129cb961fd30cf7fce6d11b3de91e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "063ae0ce03955b332c3edebae6b55a42209813d0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/formal-language",
"max_forks_repo_path": "src/Relation/Unary/Membership.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "063ae0ce03955b332c3edebae6b55a42209813d0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/formal-language",
"max_issues_repo_path": "src/Relation/Unary/Membership.agda",
"max_line_length": 81,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "063ae0ce03955b332c3edebae6b55a42209813d0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/formal-language",
"max_stars_repo_path": "src/Relation/Unary/Membership.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-22T12:48:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-01T11:24:15.000Z",
"num_tokens": 845,
"size": 1707
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Sums of binary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Sum.Relation.Binary.LeftOrder where
open import Data.Sum as Sum
open import Data.Sum.Relation.Binary.Pointwise as PW
using (Pointwise; inj₁; inj₂)
open import Data.Product
open import Data.Empty
open import Function
open import Level
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
----------------------------------------------------------------------
-- Definition
infixr 1 _⊎-<_
data _⊎-<_ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂}
{ℓ₁ ℓ₂} (_∼₁_ : Rel A₁ ℓ₁) (_∼₂_ : Rel A₂ ℓ₂) :
Rel (A₁ ⊎ A₂) (a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂) where
₁∼₂ : ∀ {x y} → (_∼₁_ ⊎-< _∼₂_) (inj₁ x) (inj₂ y)
₁∼₁ : ∀ {x y} (x∼₁y : x ∼₁ y) → (_∼₁_ ⊎-< _∼₂_) (inj₁ x) (inj₁ y)
₂∼₂ : ∀ {x y} (x∼₂y : x ∼₂ y) → (_∼₁_ ⊎-< _∼₂_) (inj₂ x) (inj₂ y)
----------------------------------------------------------------------
-- Some properties which are preserved by _⊎-<_
module _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂}
{ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂}
where
drop-inj₁ : ∀ {x y} → (∼₁ ⊎-< ∼₂) (inj₁ x) (inj₁ y) → ∼₁ x y
drop-inj₁ (₁∼₁ x∼₁y) = x∼₁y
drop-inj₂ : ∀ {x y} → (∼₁ ⊎-< ∼₂) (inj₂ x) (inj₂ y) → ∼₂ x y
drop-inj₂ (₂∼₂ x∼₂y) = x∼₂y
⊎-<-refl : Reflexive ∼₁ → Reflexive ∼₂ →
Reflexive (∼₁ ⊎-< ∼₂)
⊎-<-refl refl₁ refl₂ {inj₁ x} = ₁∼₁ refl₁
⊎-<-refl refl₁ refl₂ {inj₂ y} = ₂∼₂ refl₂
⊎-<-transitive : Transitive ∼₁ → Transitive ∼₂ →
Transitive (∼₁ ⊎-< ∼₂)
⊎-<-transitive trans₁ trans₂ ₁∼₂ (₂∼₂ x∼₂y) = ₁∼₂
⊎-<-transitive trans₁ trans₂ (₁∼₁ x∼₁y) ₁∼₂ = ₁∼₂
⊎-<-transitive trans₁ trans₂ (₁∼₁ x∼₁y) (₁∼₁ x∼₁y₁) = ₁∼₁ (trans₁ x∼₁y x∼₁y₁)
⊎-<-transitive trans₁ trans₂ (₂∼₂ x∼₂y) (₂∼₂ x∼₂y₁) = ₂∼₂ (trans₂ x∼₂y x∼₂y₁)
⊎-<-asymmetric : Asymmetric ∼₁ → Asymmetric ∼₂ →
Asymmetric (∼₁ ⊎-< ∼₂)
⊎-<-asymmetric asym₁ asym₂ ₁∼₂ ()
⊎-<-asymmetric asym₁ asym₂ (₁∼₁ x∼₁y) (₁∼₁ x∼₁y₁) = asym₁ x∼₁y x∼₁y₁
⊎-<-asymmetric asym₁ asym₂ (₂∼₂ x∼₂y) (₂∼₂ x∼₂y₁) = asym₂ x∼₂y x∼₂y₁
⊎-<-total : Total ∼₁ → Total ∼₂ → Total (∼₁ ⊎-< ∼₂)
⊎-<-total total₁ total₂ = total
where
total : Total (_ ⊎-< _)
total (inj₁ x) (inj₁ y) = Sum.map ₁∼₁ ₁∼₁ $ total₁ x y
total (inj₁ x) (inj₂ y) = inj₁ ₁∼₂
total (inj₂ x) (inj₁ y) = inj₂ ₁∼₂
total (inj₂ x) (inj₂ y) = Sum.map ₂∼₂ ₂∼₂ $ total₂ x y
⊎-<-decidable : Decidable ∼₁ → Decidable ∼₂ →
Decidable (∼₁ ⊎-< ∼₂)
⊎-<-decidable dec₁ dec₂ (inj₁ x) (inj₁ y) = Dec.map′ ₁∼₁ drop-inj₁ (dec₁ x y)
⊎-<-decidable dec₁ dec₂ (inj₁ x) (inj₂ y) = yes ₁∼₂
⊎-<-decidable dec₁ dec₂ (inj₂ x) (inj₁ y) = no λ()
⊎-<-decidable dec₁ dec₂ (inj₂ x) (inj₂ y) = Dec.map′ ₂∼₂ drop-inj₂ (dec₂ x y)
module _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂}
{ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {≈₁ : Rel A₁ ℓ₂}
{ℓ₃ ℓ₄} {∼₂ : Rel A₂ ℓ₃} {≈₂ : Rel A₂ ℓ₄}
where
⊎-<-reflexive : ≈₁ ⇒ ∼₁ → ≈₂ ⇒ ∼₂ →
(Pointwise ≈₁ ≈₂) ⇒ (∼₁ ⊎-< ∼₂)
⊎-<-reflexive refl₁ refl₂ (inj₁ x) = ₁∼₁ (refl₁ x)
⊎-<-reflexive refl₁ refl₂ (inj₂ x) = ₂∼₂ (refl₂ x)
⊎-<-irreflexive : Irreflexive ≈₁ ∼₁ → Irreflexive ≈₂ ∼₂ →
Irreflexive (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-irreflexive irrefl₁ irrefl₂ (inj₁ x) (₁∼₁ x∼₁y) = irrefl₁ x x∼₁y
⊎-<-irreflexive irrefl₁ irrefl₂ (inj₂ x) (₂∼₂ x∼₂y) = irrefl₂ x x∼₂y
⊎-<-antisymmetric : Antisymmetric ≈₁ ∼₁ → Antisymmetric ≈₂ ∼₂ →
Antisymmetric (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-antisymmetric antisym₁ antisym₂ (₁∼₁ x∼₁y) (₁∼₁ x∼₁y₁) = inj₁ (antisym₁ x∼₁y x∼₁y₁)
⊎-<-antisymmetric antisym₁ antisym₂ (₂∼₂ x∼₂y) (₂∼₂ x∼₂y₁) = inj₂ (antisym₂ x∼₂y x∼₂y₁)
-- Remove in Agda 2.6.0?
⊎-<-antisymmetric antisym₁ antisym₂ ₁∼₂ ()
⊎-<-respectsʳ : ∼₁ Respectsʳ ≈₁ → ∼₂ Respectsʳ ≈₂ →
(∼₁ ⊎-< ∼₂) Respectsʳ (Pointwise ≈₁ ≈₂)
⊎-<-respectsʳ resp₁ resp₂ (inj₁ x₁) (₁∼₁ x∼₁y) = ₁∼₁ (resp₁ x₁ x∼₁y)
⊎-<-respectsʳ resp₁ resp₂ (inj₂ x₁) ₁∼₂ = ₁∼₂
⊎-<-respectsʳ resp₁ resp₂ (inj₂ x₁) (₂∼₂ x∼₂y) = ₂∼₂ (resp₂ x₁ x∼₂y)
⊎-<-respectsˡ : ∼₁ Respectsˡ ≈₁ → ∼₂ Respectsˡ ≈₂ →
(∼₁ ⊎-< ∼₂) Respectsˡ (Pointwise ≈₁ ≈₂)
⊎-<-respectsˡ resp₁ resp₂ (inj₁ x) ₁∼₂ = ₁∼₂
⊎-<-respectsˡ resp₁ resp₂ (inj₁ x) (₁∼₁ x∼₁y) = ₁∼₁ (resp₁ x x∼₁y)
⊎-<-respectsˡ resp₁ resp₂ (inj₂ x) (₂∼₂ x∼₂y) = ₂∼₂ (resp₂ x x∼₂y)
⊎-<-respects₂ : ∼₁ Respects₂ ≈₁ → ∼₂ Respects₂ ≈₂ →
(∼₁ ⊎-< ∼₂) Respects₂ (Pointwise ≈₁ ≈₂)
⊎-<-respects₂ (r₁ , l₁) (r₂ , l₂) = ⊎-<-respectsʳ r₁ r₂ , ⊎-<-respectsˡ l₁ l₂
⊎-<-trichotomous : Trichotomous ≈₁ ∼₁ → Trichotomous ≈₂ ∼₂ →
Trichotomous (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-trichotomous tri₁ tri₂ (inj₁ x) (inj₂ y) = tri< ₁∼₂ (λ()) (λ())
⊎-<-trichotomous tri₁ tri₂ (inj₂ x) (inj₁ y) = tri> (λ()) (λ()) ₁∼₂
⊎-<-trichotomous tri₁ tri₂ (inj₁ x) (inj₁ y) with tri₁ x y
... | tri< x<y x≉y x≯y = tri< (₁∼₁ x<y) (x≉y ∘ PW.drop-inj₁) (x≯y ∘ drop-inj₁)
... | tri≈ x≮y x≈y x≯y = tri≈ (x≮y ∘ drop-inj₁) (inj₁ x≈y) (x≯y ∘ drop-inj₁)
... | tri> x≮y x≉y x>y = tri> (x≮y ∘ drop-inj₁) (x≉y ∘ PW.drop-inj₁) (₁∼₁ x>y)
⊎-<-trichotomous tri₁ tri₂ (inj₂ x) (inj₂ y) with tri₂ x y
... | tri< x<y x≉y x≯y = tri< (₂∼₂ x<y) (x≉y ∘ PW.drop-inj₂) (x≯y ∘ drop-inj₂)
... | tri≈ x≮y x≈y x≯y = tri≈ (x≮y ∘ drop-inj₂) (inj₂ x≈y) (x≯y ∘ drop-inj₂)
... | tri> x≮y x≉y x>y = tri> (x≮y ∘ drop-inj₂) (x≉y ∘ PW.drop-inj₂) (₂∼₂ x>y)
----------------------------------------------------------------------
-- Some collections of properties which are preserved
module _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂}
{ℓ₁ ℓ₂} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₂}
{ℓ₃ ℓ₄} {≈₂ : Rel A₂ ℓ₃} {∼₂ : Rel A₂ ℓ₄} where
⊎-<-isPreorder : IsPreorder ≈₁ ∼₁ → IsPreorder ≈₂ ∼₂ →
IsPreorder (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-isPreorder pre₁ pre₂ = record
{ isEquivalence = PW.⊎-isEquivalence (isEquivalence pre₁) (isEquivalence pre₂)
; reflexive = ⊎-<-reflexive (reflexive pre₁) (reflexive pre₂)
; trans = ⊎-<-transitive (trans pre₁) (trans pre₂)
}
where open IsPreorder
⊎-<-isPartialOrder : IsPartialOrder ≈₁ ∼₁ →
IsPartialOrder ≈₂ ∼₂ →
IsPartialOrder (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-isPartialOrder po₁ po₂ = record
{ isPreorder = ⊎-<-isPreorder (isPreorder po₁) (isPreorder po₂)
; antisym = ⊎-<-antisymmetric (antisym po₁) (antisym po₂)
}
where open IsPartialOrder
⊎-<-isStrictPartialOrder : IsStrictPartialOrder ≈₁ ∼₁ →
IsStrictPartialOrder ≈₂ ∼₂ →
IsStrictPartialOrder (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-isStrictPartialOrder spo₁ spo₂ = record
{ isEquivalence = PW.⊎-isEquivalence (isEquivalence spo₁) (isEquivalence spo₂)
; irrefl = ⊎-<-irreflexive (irrefl spo₁) (irrefl spo₂)
; trans = ⊎-<-transitive (trans spo₁) (trans spo₂)
; <-resp-≈ = ⊎-<-respects₂ (<-resp-≈ spo₁) (<-resp-≈ spo₂)
}
where open IsStrictPartialOrder
⊎-<-isTotalOrder : IsTotalOrder ≈₁ ∼₁ →
IsTotalOrder ≈₂ ∼₂ →
IsTotalOrder (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-isTotalOrder to₁ to₂ = record
{ isPartialOrder = ⊎-<-isPartialOrder (isPartialOrder to₁) (isPartialOrder to₂)
; total = ⊎-<-total (total to₁) (total to₂)
}
where open IsTotalOrder
⊎-<-isDecTotalOrder : IsDecTotalOrder ≈₁ ∼₁ →
IsDecTotalOrder ≈₂ ∼₂ →
IsDecTotalOrder (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-isDecTotalOrder to₁ to₂ = record
{ isTotalOrder = ⊎-<-isTotalOrder (isTotalOrder to₁) (isTotalOrder to₂)
; _≟_ = PW.⊎-decidable (_≟_ to₁) (_≟_ to₂)
; _≤?_ = ⊎-<-decidable (_≤?_ to₁) (_≤?_ to₂)
}
where open IsDecTotalOrder
⊎-<-isStrictTotalOrder : IsStrictTotalOrder ≈₁ ∼₁ →
IsStrictTotalOrder ≈₂ ∼₂ →
IsStrictTotalOrder (Pointwise ≈₁ ≈₂) (∼₁ ⊎-< ∼₂)
⊎-<-isStrictTotalOrder sto₁ sto₂ = record
{ isEquivalence = PW.⊎-isEquivalence (isEquivalence sto₁) (isEquivalence sto₂)
; trans = ⊎-<-transitive (trans sto₁) (trans sto₂)
; compare = ⊎-<-trichotomous (compare sto₁) (compare sto₂)
}
where open IsStrictTotalOrder
------------------------------------------------------------------------
-- "Packages" can also be combined.
module _ {a b c d e f} where
⊎-<-preorder : Preorder a b c →
Preorder d e f →
Preorder _ _ _
⊎-<-preorder p₁ p₂ = record
{ isPreorder =
⊎-<-isPreorder (isPreorder p₁) (isPreorder p₂)
} where open Preorder
⊎-<-poset : Poset a b c →
Poset a b c →
Poset _ _ _
⊎-<-poset po₁ po₂ = record
{ isPartialOrder =
⊎-<-isPartialOrder (isPartialOrder po₁) (isPartialOrder po₂)
} where open Poset
⊎-<-strictPartialOrder : StrictPartialOrder a b c →
StrictPartialOrder d e f →
StrictPartialOrder _ _ _
⊎-<-strictPartialOrder spo₁ spo₂ = record
{ isStrictPartialOrder =
⊎-<-isStrictPartialOrder (isStrictPartialOrder spo₁) (isStrictPartialOrder spo₂)
} where open StrictPartialOrder
⊎-<-totalOrder : TotalOrder a b c →
TotalOrder d e f →
TotalOrder _ _ _
⊎-<-totalOrder to₁ to₂ = record
{ isTotalOrder = ⊎-<-isTotalOrder (isTotalOrder to₁) (isTotalOrder to₂)
} where open TotalOrder
⊎-<-decTotalOrder : DecTotalOrder a b c →
DecTotalOrder d e f →
DecTotalOrder _ _ _
⊎-<-decTotalOrder to₁ to₂ = record
{ isDecTotalOrder = ⊎-<-isDecTotalOrder (isDecTotalOrder to₁) (isDecTotalOrder to₂)
} where open DecTotalOrder
⊎-<-strictTotalOrder : StrictTotalOrder a b c →
StrictTotalOrder a b c →
StrictTotalOrder _ _ _
⊎-<-strictTotalOrder sto₁ sto₂ = record
{ isStrictTotalOrder = ⊎-<-isStrictTotalOrder (isStrictTotalOrder sto₁) (isStrictTotalOrder sto₂)
} where open StrictTotalOrder
|
{
"alphanum_fraction": 0.5344431688,
"avg_line_length": 42.3157894737,
"ext": "agda",
"hexsha": "06edca09ccb86e4c1781107c3498239b51163964",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Relation/Binary/LeftOrder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Relation/Binary/LeftOrder.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Relation/Binary/LeftOrder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4516,
"size": 10452
}
|
module Golden where
open import Basics
open import Vec
open import Ix
open import Cutting
open import Interior
open import Tensor
open RECTANGLE
open INTERIOR RectCut
ind : (n : Nat)(P : Nat -> Set) -> P zero ->
((k : Nat) -> P k -> P (suc k)) -> P n
ind zero P pz ps = pz
ind (suc n) P pz ps = ps n (ind n P pz ps)
+N-zero : (x : Nat) -> (x +N zero) == x
+N-zero x = ind x (\ x -> (x +N zero) == x) (refl _) (\ _ h -> refl suc =$= h)
+N-suc : (x y : Nat) -> (x +N suc y) == suc (x +N y)
+N-suc x y = ind x (\ x -> (x +N suc y) == suc (x +N y))
(refl _) (\ _ h -> refl suc =$= h)
comm-+N : (x y : Nat) -> (x +N y) == (y +N x)
comm-+N x zero = +N-zero x
comm-+N x (suc y) rewrite +N-suc x y = refl suc =$= comm-+N x y
clockwise90 : {P : Nat * Nat -> Set}{w h : Nat} ->
({w h : Nat} -> P (w , h) -> P (h , w)) ->
Interior P (w , h) -> Interior P (h , w)
clockwise90 pc90 (tile p) = tile (pc90 p)
clockwise90 pc90 < inl (l , r , refl _) 8>< (il , ir , <>) >
= < inr (l , r , refl _) 8><
clockwise90 pc90 il , clockwise90 pc90 ir , <> >
clockwise90 pc90 < inr (t , b , refl _) 8>< it , ib , <> >
= < (inl (b , t , comm-+N b t)) 8><
clockwise90 pc90 ib , clockwise90 pc90 it , <> >
Square : Nat * Nat -> Set
Square (w , h) = w == h
c90Sq : {w h : Nat} -> Square (w , h) -> Square (h , w)
c90Sq (refl _) = refl _
golden : (n : Nat) -> Sg Nat \ w -> Sg Nat \ h -> Interior Square (w , h)
golden zero = 1 , 1 , tile (refl 1)
golden (suc n) with golden n
... | w , h , i = (w +N h) , w , < (inl (w , h , refl _)) 8><
tile (refl w) , clockwise90 c90Sq i , <> >
fill : {n : Nat}{X : Set} -> X -> X -> X -> Vec X (suc (suc n))
fill {n} first midst last rewrite comm-+N 1 (suc n) = first ,- (pure midst +V (last ,- []))
where open Applicative (VecAppl n)
border : {w h : Nat} -> Matrix Char (w , h)
border {w} {zero} = []
border {zero} {h} = pure [] where open Applicative (VecAppl _)
border {suc zero} {suc zero} = ('O' ,- []) ,- []
border {suc (suc w)} {suc zero} = fill '<' '-' '>' ,- []
border {suc zero} {suc (suc h)} = fill ('^' ,- []) ('|' ,- []) ('v' ,- [])
border {suc (suc w)} {suc (suc h)} =
fill (fill '/' '-' '\\')
(fill '|' ' ' '|')
(fill '\\' '-' '/')
goldenInterior : (n : Nat) -> Sg Nat \ w -> Sg Nat \ h -> Interior (Matrix Char) (w , h)
goldenInterior n with golden n
... | w , h , sqi = w , h , ifold (\ _ _ -> tile border) (\ _ -> <_>) (w , h) sqi
picture : [ Interior (Matrix Char) -:> Matrix Char ]
picture = ifold (\ _ -> id) NatCut2DMatAlg
goldenPicture : (n : Nat) -> Sg Nat \ w -> Sg Nat \ h -> Matrix Char (w , h)
goldenPicture n with goldenInterior n
... | w , h , mi = w , h , picture _ mi
|
{
"alphanum_fraction": 0.5066518847,
"avg_line_length": 33,
"ext": "agda",
"hexsha": "cfedca298ef3b6928c6b7f9756fb65e315421a92",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pigworker/InteriorDesign",
"max_forks_repo_path": "Golden.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pigworker/InteriorDesign",
"max_issues_repo_path": "Golden.agda",
"max_line_length": 91,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pigworker/InteriorDesign",
"max_stars_repo_path": "Golden.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z",
"num_tokens": 1019,
"size": 2706
}
|
{-# OPTIONS --without-K --safe #-}
module Experiment.Categories.Category.Monoidal.Strict where
|
{
"alphanum_fraction": 0.75,
"avg_line_length": 24,
"ext": "agda",
"hexsha": "1e5c9ea6b680509b76dbbc5f1ff37d06ff4f76c8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/Categories/Category/Monoidal/Strict.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/Categories/Category/Monoidal/Strict.agda",
"max_line_length": 59,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/Categories/Category/Monoidal/Strict.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 17,
"size": 96
}
|
{-# OPTIONS --rewriting --prop #-}
open import common
open import syntx as N
open import derivability as N2
open import typingrules
open import structuralrules
open import typetheories
open import examples
open import traditional as T
Σ : Signature
Σ = TTSig ΠUEl-TT
{- Maps between expressions -}
T→N : {n : ℕ} {k : SyntaxSort} → T.Expr k n → N.Expr Σ n k
T→N uu = sym 1 []
T→N (el v) = sym 0 ([] , T→N v)
T→N (pi A B) = sym 4 ([] , T→N A , T→N B)
T→N (var x) = var x
T→N (lam A B u) = sym 3 ([] , T→N A , T→N B , T→N u)
T→N (app A B f a) = sym 2 ([] , T→N A , T→N B , T→N f , T→N a)
N→T : {n : ℕ} {k : SyntaxSort} → N.Expr Σ n k → T.Expr k n
N→T (var x) = var x
N→T (sym (prev (prev (prev (prev new)))) ([] , A , B)) = pi (N→T A) (N→T B)
N→T (sym (prev (prev (prev new))) ([] , A , B , u)) = lam (N→T A) (N→T B) (N→T u)
N→T (sym (prev (prev new)) ([] , A , B , f , a)) = app (N→T A) (N→T B) (N→T f) (N→T a)
N→T (sym (prev new) []) = uu
N→T (sym new ([] , v)) = el (N→T v)
{- Equalities -}
TNT : {n : ℕ} {k : SyntaxSort} (e : N.Expr Σ n k) → T→N (N→T e) ≡ e
TNT (var x) = refl
TNT (sym (prev (prev (prev (prev new)))) ([] , A , B)) = ap2 (λ x y → sym 4 ([] , x , y)) (TNT A) (TNT B)
TNT (sym (prev (prev (prev new))) ([] , A , B , u)) = ap3 (λ x y z → sym 3 ([] , x , y , z)) (TNT A) (TNT B) (TNT u)
TNT (sym (prev (prev new)) ([] , A , B , f , a)) = ap4 (λ x y z t → sym 2 ([] , x , y , z , t)) (TNT A) (TNT B) (TNT f) (TNT a)
TNT (sym (prev new) []) = refl
TNT (sym new ([] , v)) = ap (λ v → sym 0 ([] , v)) (TNT v)
NTN : {n : ℕ} {k : SyntaxSort} (e : T.Expr k n) → N→T (T→N e) ≡ e
NTN uu = refl
NTN (el v) = ap el (NTN v)
NTN (pi A B) = ap2 pi (NTN A) (NTN B)
NTN (var x) = refl
NTN (lam A B u) = ap3 lam (NTN A) (NTN B) (NTN u)
NTN (app A B f a) = ap4 app (NTN A) (NTN B) (NTN f) (NTN a)
{- Derivability -}
data NJudgment : Set where
njudgment : {n : ℕ} (Γ : N.Ctx Σ n) {k : JudgmentSort} → N2.Judgment Σ Γ 0 k → NJudgment
NDerivable : NJudgment → Prop
NDerivable (njudgment Γ j) = N2.Derivable (TTDer ΠUEl-TT) j
-- record NJudgment : Set where
-- constructor njudgment
-- field
-- {NJn} : ℕ
-- NJΓ : N.Ctx (TTSig ΠUEl-TT4) NJn
-- {NJk} : JudgmentSort
-- NJj : N2.Judgment (TTSig ΠUEl-TT4) NJΓ 0 NJk
-- open NJudgment
-- record NDerivable (j : NJudgment) : Prop where
-- constructor ´_
-- field
-- `_ : N2.Derivable (TTDer ΠUEl-TT4) (NJj j)
-- open NDerivable
-- -- `_ : NDerivable (njudgment Γ j) → N2.Derivable (TTDer ΠUEl-TT) j
-- -- `_ d = d
-- -- ´_ : {n : ℕ} {Γ : N.Ctx Σ n} {k : JudgmentSort} {j : N2.Judgment Σ Γ 0 k} → N2.Derivable (TTDer ΠUEl-TT) j → NDerivable (njudgment Γ j)
-- -- ´_ d = d
NDerivable= : {j j' : NJudgment} (j= : j ≡ j') → NDerivable j' → NDerivable j
NDerivable= refl x = x
NDerivable=! : {j j' : NJudgment} (j= : j ≡ j') → NDerivable j → NDerivable j'
NDerivable=! refl x = x
T→NCtx : {n : ℕ} → T.Ctx n → N.Ctx Σ n
T→NCtx ◇ = ◇
T→NCtx (Γ , A) = (T→NCtx Γ , T→N A)
T→NJ : T.Judgment → NJudgment
T→NJ (Γ ⊢ A) = njudgment (T→NCtx Γ) (◇ ⊢ T→N A)
T→NJ (Γ ⊢ u :> A) = njudgment (T→NCtx Γ) (◇ ⊢ T→N u :> T→N A)
T→NJ (Γ ⊢ A == B) = njudgment (T→NCtx Γ) (◇ ⊢ T→N A == T→N B)
T→NJ (Γ ⊢ u == v :> A) = njudgment (T→NCtx Γ) (◇ ⊢ T→N u == T→N v :> T→N A)
weaken-comm : {k : SyntaxSort} {n : ℕ} {A : T.Expr k n} (p : WeakPos n) → N.weaken p (T→N A) ≡ T→N (T.weaken p A)
weaken-comm {A = uu} p = refl
weaken-comm {A = el v} p = ap (λ z → sym new ([] , z)) (weaken-comm p)
weaken-comm {A = pi A B} p = ap2 (λ z z' → sym (prev (prev (prev (prev new)))) ([] , z , z')) (weaken-comm p) (weaken-comm (prev p))
weaken-comm {A = var x} p = refl --ap var (weakenV-comm p x)
weaken-comm {A = lam A B u} p = ap3 (λ z z' z'' → sym (prev (prev (prev new))) ([] , z , z' , z'')) (weaken-comm p) (weaken-comm (prev p)) (weaken-comm (prev p))
weaken-comm {A = app A B f a} p = ap4 (λ z z' z'' z''' → sym (prev (prev new)) ([] , z , z' , z'' , z''')) (weaken-comm p) (weaken-comm (prev p)) (weaken-comm p) (weaken-comm p)
VarPos→ℕ : {n : ℕ} → VarPos n → ℕ
VarPos→ℕ last = 0
VarPos→ℕ (prev k) = suc (VarPos→ℕ k)
fst-VarPos→ℕ : {Σ : Signature} {n : ℕ} (k : VarPos n) (Γ : N.Ctx Σ n) {def : _} → fst (N.get (VarPos→ℕ k) Γ $ def) ≡ k
fst-VarPos→ℕ last (Γ , A) = refl
fst-VarPos→ℕ (prev k) (Γ , A) = ap prev (fst-VarPos→ℕ k Γ)
snd-VarPos→ℕ : {n : ℕ} (k : VarPos n) (Γ : T.Ctx n) {def : _} → snd (N.get (VarPos→ℕ k) (T→NCtx Γ) $ def) ≡ T→N (T.get k Γ)
snd-VarPos→ℕ last (Γ , A) = weaken-comm last
snd-VarPos→ℕ (prev k) (Γ , A) = ap (N.weaken last) (snd-VarPos→ℕ k Γ) ∙ weaken-comm last
get-def : {n : ℕ} (k : VarPos n) (Γ : T.Ctx n) → isDefined (N.get (VarPos→ℕ k) (T→NCtx Γ))
get-def last (Γ , A) = tt
get-def (prev k) (Γ , A) = (get-def k Γ , tt)
MorInsert : {Σ : Signature} (x : WeakPos m) (δ : N.Mor Σ n m) (u : N.TmExpr Σ n) → N.Mor Σ n (suc m)
MorInsert last δ u = (δ , u)
MorInsert (prev x) (δ , v) u = (MorInsert x δ u , v)
{-# REWRITE +O-rewrite #-}
{-# REWRITE +S-rewrite #-}
{-# REWRITE assoc #-}
weaken-MorInsert : {Σ : Signature} {n k : ℕ} {x : WeakPos n} {δ : N.Mor Σ k n} {u : N.TmExpr Σ k}
→ N.weakenMor (MorInsert x δ u) ≡ MorInsert x (N.weakenMor δ) (N.weaken last u)
weaken-MorInsert {x = last} = refl
weaken-MorInsert {x = prev x} {δ , u} = ap2 _,_ weaken-MorInsert refl
Impossible : {n k : ℕ} {A : Prop} → suc (n + k) ≤ n → A
Impossible {suc n} {k = zero} (≤S p) = Impossible p
Impossible {suc n} {k = suc k} p = Impossible (≤P p)
weakenV-η : (x : WeakPos n) (y : VarPos n) {p : n ≤ n} → y ≡ weakenV {{p}} x y
weakenV-η x y {≤r} = ! weakenV≤r
weakenV-η x y {≤S p} = Impossible p
weaken-η : {Σ : Signature} {k : _} {x : _} {p : n ≤ n} {u : N.Expr Σ n k} → u ≡ N.weaken {{p}} x u
weakenA-η : {Σ : Signature} {k : _} {x : _} {p : n ≤ n} {u : N.Args Σ n k} → u ≡ N.weakenA {{p}} x u
weaken-η {x = x} {u = var y} = ap var (weakenV-η x y)
weaken-η {u = sym s us} = ap (sym s) weakenA-η
weakenA-η {u = []} = refl
weakenA-η {u = u , x} = ap2 _,_ weakenA-η weaken-η
WeakPosIncl : {n m : ℕ} {{_ : n ≤ m}} → WeakPos n → WeakPos m
WeakPosIncl last = last
WeakPosIncl {m = suc m} {{p}} (prev x) = prev (WeakPosIncl {{≤P p}} x)
≤P-≤SS : {n m : ℕ} (p : n ≤ m) → p ≡ ≤P (≤SS {{p}})
≤P-≤SS ≤r = refl
≤P-≤SS (≤S p) = ap ≤S (≤P-≤SS _)
WeakPosIncl-comm : {n m k : ℕ} {{p : n ≤ m}} {x : WeakPos n} → weakenPos (≤-+ {m = k}) (WeakPosIncl {{p}} x) ≡ WeakPosIncl {{≤+ k {{p}}}} (weakenPos ≤-+ x)
WeakPosIncl-comm {k = zero} {x = last} = refl
WeakPosIncl-comm {k = suc k} {x = last} = ap prev (WeakPosIncl-comm {k = k} {x = last} ∙ ap (λ z → WeakPosIncl {{z}} (weakenPos ≤-+ last)) (≤P-≤SS _))
WeakPosIncl-comm {m = suc m} {zero} {x = prev x} = refl
WeakPosIncl-comm {m = suc m} {suc k} {x = prev x} = ap prev (WeakPosIncl-comm {m = suc m} {k = k} {x = prev x} ∙ ap (λ z → WeakPosIncl {{z}} (weakenPos ≤-+ (prev x))) (≤P-≤SS _))
≤-ishProp : {n m : ℕ} (p q : n ≤ m) → p ≡ q
≤-ishProp ≤r ≤r = refl
≤-ishProp ≤r (≤S q) = Impossible q
≤-ishProp (≤S p) ≤r = Impossible p
≤-ishProp (≤S p) (≤S q) = ap ≤S (≤-ishProp p q)
weakenV-μ : {n m k : ℕ} {{p : n ≤ m}} {{q : m ≤ k}} {{r : n ≤ k}} {x : VarPos n} {y : WeakPos n}
→ weakenV {{q}} (WeakPosIncl y) (weakenV {{p}} y x) ≡ weakenV {{r}} y x
weakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤r ⦄ ⦃ ≤r ⦄ = weakenV≤r
weakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤r ⦄ ⦃ ≤S r ⦄ = Impossible r
weakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤r ⦄ = Impossible q
weakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤S r ⦄ {x} {y = last} = ap2 (λ z z' → prev (weakenV ⦃ z ⦄ last z')) (≤-ishProp _ _) weakenV≤r
weakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤S r ⦄ {last} {y = prev y} = refl
weakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤S r ⦄ {prev x} {y = prev y} = ap prev (ap (weakenV {{≤P (≤S q)}} (WeakPosIncl y)) (! weakenV≤r) ∙ weakenV-μ {{≤r}} {{≤P (≤S q)}} {{≤P (≤S r)}} {x = x} {y})
weakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤r ⦄ ⦃ ≤r ⦄ = Impossible p
weakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤r ⦄ ⦃ ≤S r ⦄ {x} {y} = weakenV≤r {p = WeakPosIncl {{≤S p}} y} {v = weakenV {{≤S p}} y x} ∙ ap (λ z → weakenV ⦃ z ⦄ y x) (≤-ishProp _ _) --
weakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤r ⦄ = Impossible (≤tr {{≤S p}} {{q}})
weakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S ≤r ⦄ = Impossible (≤tr {{q}} {{p}})
weakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S (≤S r) ⦄ {x} {y = last} = ap prev (weakenV-μ {{≤S p}} {{q}} {{≤S r}} {x} {last})
weakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S (≤S r) ⦄ {last} {y = prev y} = refl
weakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S (≤S r) ⦄ {prev x} {y = prev y} = ap prev (weakenV-μ {{≤P (≤S p)}} {{≤P (≤S q)}} {{≤P (≤S (≤S r))}} {x} {y})
weaken-μ : {Σ : Signature} {k : _} {x : WeakPos n} {q : n ≤ m} {r : _} {u : N.Expr Σ n k} → N.weaken {{≤S ≤r}} (WeakPosIncl {{q}} x) (N.weaken {{q}} x u) ≡ N.weaken {{r}} x u
weakenA-μ : {Σ : Signature} {k : _} {x : WeakPos n} {q : n ≤ m} {r : _} {u : N.Args Σ n k} → N.weakenA {{≤S ≤r}} (WeakPosIncl {{q}} x) (N.weakenA {{q}} x u) ≡ N.weakenA {{r}} x u
weaken-μ {x = y} {q = p} {u = var x} = ap var ((weakenV-μ {{p}} {{≤S ≤r}} {{_}} {x = x} {y = y}))
weaken-μ {u = sym s x} = ap (sym s) weakenA-μ
weakenA-μ {u = []} = refl
weakenA-μ {q = q} {u = u , x} = ap2 _,_ weakenA-μ (ap2 (λ z z' → N.weaken {{z}} z' (N.weaken {{≤+ _ {{q}}}} _ x))
(≤-ishProp _ _)
(WeakPosIncl-comm {{q}})
∙ weaken-μ {q = ≤+ _ {{q}}})
weaken+-MorInsert : {Σ : Signature} (m : ℕ) {n k : ℕ} {x : WeakPos n} {δ : N.Mor Σ k n} {u : N.TmExpr Σ k}
→ N.weakenMor+ m (MorInsert x δ u) ≡ MorInsert (weakenPos ≤-+ x) (N.weakenMor+ m δ) (N.weaken last u)
weaken+-MorInsert zero = ap (MorInsert _ _) weaken-η
weaken+-MorInsert (suc m) = ap2 _,_ (ap N.weakenMor (weaken+-MorInsert m) ∙ weaken-MorInsert ∙ ap (MorInsert _ _) weaken-μ) refl
SubstV-insert : {n m : ℕ} {y : VarPos n} {x : WeakPos n} {u : N.TmExpr Σ m} {δ : N.Mor Σ m n} {p : n ≤ suc n}
→ SubstMor (var (weakenV {{p}} x y)) (MorInsert x δ u) ≡ SubstMor (var y) δ
SubstV-insert {x = last} {δ = δ} {p = ≤S ≤r} = ap (λ z → SubstMor (var z) δ) weakenV≤r
SubstV-insert {y = last} {x = prev x} {δ = δ , v} {p = ≤S ≤r} = refl
SubstV-insert {y = prev y} {x = prev x} {u} {δ = δ , v} {p = ≤S ≤r} = SubstV-insert {y = y} {x = x} {u = u} {δ = δ} {p = ≤S ≤r}
SubstV-insert {p = ≤S (≤S p)} = Impossible p
Subst-insert : {k : SyntaxSort} {n m : ℕ} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ m} {δ : N.Mor Σ m n} {p : _}
→ SubstMor (N.weaken {{p}} x e) (MorInsert x δ u) ≡ SubstMor e δ
SubstA-insert : {args : SyntaxArityArgs} {n m : ℕ} {es : N.Args Σ n args} {x : WeakPos n} {u : N.TmExpr Σ m} {δ : N.Mor Σ m n} {p : _}
→ SubstAMor (N.weakenA {{p}} x es) (MorInsert x δ u) ≡ SubstAMor es δ
Subst-insert {e = var x} {x = x'} {u} {p = p} = SubstV-insert {x = x'} {u} {p = p}
Subst-insert {e = sym s x} = ap (sym s) SubstA-insert
SubstA-insert {es = []} = refl
SubstA-insert {args} {n} {es = _,_ {m = m} es e} {x = x} {u = u} {p = p} =
ap2 _,_ SubstA-insert (ap (SubstMor (N.weaken {{≤+ m {n} {suc n} {{p}}}} (weakenPos ≤-+ x) e)) (weaken+-MorInsert m) ∙ Subst-insert {e = e} {x = weakenPos ≤-+ x})
weakenMor+-idMor : {n : ℕ} (m : ℕ) → N.weakenMor+ m (N.idMor {Σ = Σ} {n = n}) ≡ N.idMor
weakenMor+-idMor zero = refl
weakenMor+-idMor (suc m) = ap2 _,_ (ap N.weakenMor (weakenMor+-idMor m)) refl
SubstMor-weakenMor : {x : VarPos n} {δ : N.Mor Σ m n} → SubstMor (var x) (N.weakenMor δ) ≡ N.weaken last (SubstMor (var x) δ)
SubstMor-weakenMor {x = last} {δ , u} = refl
SubstMor-weakenMor {x = prev x} {δ , u} = SubstMor-weakenMor {x = x} {δ}
SubstMor-idMor : {n : ℕ} {k : _} (e : N.Expr Σ n k) → SubstMor e N.idMor ≡ e
SubstAMor-idMor : {n : ℕ} {k : _} (es : N.Args Σ n k) → SubstAMor es N.idMor ≡ es
SubstMor-idMor (var last) = refl
SubstMor-idMor (var (prev x)) = SubstMor-weakenMor {x = x} {δ = N.idMor} ∙ ap (N.weaken last) (SubstMor-idMor (var x)) ∙ ap var (ap prev weakenV≤r)
SubstMor-idMor (sym s es) = ap (sym s) (SubstAMor-idMor es)
SubstAMor-idMor [] = refl
SubstAMor-idMor (_,_ {m = m} es x) = ap2 _,_ (SubstAMor-idMor es) (ap (SubstMor x) (weakenMor+-idMor m) ∙ SubstMor-idMor x)
Subst-insert-idMor : {k : SyntaxSort} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ n} {p : _}
→ SubstMor (N.weaken {{p}} x e) (MorInsert x N.idMor u) ≡ e
Subst-insert-idMor {e = e} {x} {u} {p} = Subst-insert {e = e} {x} {u} {N.idMor} {p} ∙ SubstMor-idMor e
inj : WeakPos n → WeakPos (suc n)
inj last = last
inj (prev x) = prev (inj x)
weakenPos-inj : {m : ℕ} (x : WeakPos n) → weakenPos (≤-+ {m = m}) (inj x) ≡ inj (weakenPos ≤-+ x)
weakenPos-inj {m = zero} x = refl
weakenPos-inj {m = suc m} last = ap prev (weakenPos-inj last)
weakenPos-inj {m = suc m} (prev x) = ap prev (weakenPos-inj (prev x))
SubstV-insert2 : {n m : ℕ} {y : VarPos n} {x : WeakPos n} {u : N.TmExpr Σ (suc m)} {δ : N.Mor Σ (suc m) (suc n)} {p : _}
→ SubstMor (var (weakenV {{≤S p}} x y)) (MorInsert (inj x) δ u) ≡ SubstMor (var (weakenV {{p}} x y)) δ
SubstV-insert2 {y = last} {last} = refl
SubstV-insert2 {y = prev y} {last} = refl
SubstV-insert2 {y = last} {prev x} {δ = δ , u} = refl
SubstV-insert2 {y = prev y} {prev x} {δ = δ , u} {≤S ≤r} = SubstV-insert2 {y = y} {x = x} {δ = δ}
SubstV-insert2 {y = prev y} {prev x} {δ = δ , u} {≤S (≤S p)} = Impossible p
Subst-insert2 : {k : SyntaxSort} {n m : ℕ} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ (suc m)} {δ : N.Mor Σ (suc m) (suc n)} {p : _}
→ SubstMor (N.weaken {{≤S p}} x e) (MorInsert (inj x) δ u) ≡ SubstMor (N.weaken {{p}} x e) δ
SubstA-insert2 : {args : SyntaxArityArgs} {n m : ℕ} {es : N.Args Σ n args} {x : WeakPos n} {u : N.TmExpr Σ (suc m)} {δ : N.Mor Σ (suc m) (suc n)} {p : _}
→ SubstAMor (N.weakenA {{≤S p}} x es) (MorInsert (inj x) δ u) ≡ SubstAMor (N.weakenA {{p}} x es) δ
Subst-insert2 {e = var y} {x = x} = SubstV-insert2 {y = y} {x = x}
Subst-insert2 {e = sym s es} = ap (sym s) SubstA-insert2
SubstA-insert2 {es = []} = refl
SubstA-insert2 {n = n} {m = m'} {es = _,_ {m = m} es e} {x = x} {u = u} =
ap2 _,_ SubstA-insert2 ((ap (SubstMor (N.weaken {{_}} (weakenPos ≤-+ x) e)) (weaken+-MorInsert m ∙ ap3 MorInsert (weakenPos-inj x) refl refl)
∙ ap
(λ z →
SubstMor (N.weaken ⦃ z ⦄ (weakenPos ≤-+ x) e)
(MorInsert (inj (weakenPos ≤-+ x)) (N.weakenMor+ m {n = suc n} {m = suc m'} _)
(N.weaken last u)))
(≤-ishProp _ _) ∙ Subst-insert2 {e = e} {x = weakenPos ≤-+ x} {u = N.weaken last u}))
Subst-insert-idMor2 : {k : SyntaxSort} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ (suc n)}
→ SubstMor (N.weaken x e) (MorInsert (inj x) (N.idMor {n = suc n}) u) ≡ N.weaken {{≤S ≤r}} x e
Subst-insert-idMor2 {e = e} {x} {u} = Subst-insert2 {e = e} {x} {u} {N.idMor} ∙ SubstMor-idMor _
T→NMor : T.Mor n m → N.Mor Σ n m
T→NMor ◇ = ◇
T→NMor (δ , u) = (T→NMor δ , T→N u)
weakenMor-comm : {δ : T.Mor n m} → N.weakenMor (T→NMor δ) ≡ T→NMor (T.weakenMor δ)
weakenMor-comm {δ = ◇} = refl
weakenMor-comm {δ = δ , u} = ap2 _,_ weakenMor-comm (weaken-comm last)
substV-lemma : (x : VarPos n) {δ : T.Mor m n} → SubstMor (var x) (T→NMor δ) ≡ T→N (var x [ δ ])
substV-lemma last {δ , u} = refl
substV-lemma (prev x) {δ , u} = substV-lemma x
subst-lemma : {k : _} (B : T.Expr k n) {δ : T.Mor m n} → SubstMor (T→N B) (T→NMor δ) ≡ T→N (B [ δ ])
subst-lemma uu = refl
subst-lemma (el v) = ap (λ z → sym new ([] , z)) (subst-lemma v)
subst-lemma (pi A B) = ap2 (λ z z' → sym (prev (prev (prev (prev new)))) ([] , z , z')) (subst-lemma A) (ap (SubstMor (T→N B)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma B)
subst-lemma (var x) = substV-lemma x
subst-lemma (lam A B u) = ap3 (λ z z' z'' → sym (prev (prev (prev new))) ([] , z , z' , z''))
(subst-lemma A) (ap (SubstMor (T→N B)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma B) (ap (SubstMor (T→N u)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma u)
subst-lemma (app A B f a) = ap4
(λ z z' z'' z''' →
sym (prev (prev new)) ([] , z , z' , z'' , z'''))
(subst-lemma A) (ap (SubstMor (T→N B)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma B) (subst-lemma f) (subst-lemma a)
idMor-lemma : {n : ℕ} → N.idMor {n = n} ≡ T→NMor T.idMor
idMor-lemma {zero} = refl
idMor-lemma {suc n} = ap2 _,_ (ap N.weakenMor idMor-lemma ∙ weakenMor-comm) refl
Subst-T→N : {k : _} (B : T.Expr k (suc n)) (a : T.TmExpr n) → N.SubstMor (T→N B) (N.idMor , T→N a) ≡ T→N (T.subst B a)
Subst-T→N B a = ap (λ z → SubstMor (T→N B) (z , T→N a)) idMor-lemma ∙ subst-lemma B
-- T→NDer : {j : T.Judgment} → T.Derivable j → NDerivable (T→NJ j)
-- T→NDer (Var {Γ = Γ} k dA) = NDerivable=! (ap (λ x → njudgment (T→NCtx Γ) (◇ ⊢ var x :> T→N (T.get k Γ))) (fst-VarPos→ℕ k (T→NCtx Γ))) (´ apr S (var (VarPos→ℕ k)) ([] ,0Ty ` T→NDer dA) {{get-def k Γ , (snd-VarPos→ℕ k Γ , tt)}})
-- T→NDer (TyRefl dA) = ´ apr S tyRefl ([] , ` T→NDer dA)
-- T→NDer (TySymm dA=) = ´ apr S tySymm ([] , ` T→NDer dA=)
-- T→NDer (TyTran dA= dB=) = ´ apr S tyTran ([] , ` T→NDer dA= , ` T→NDer dB=)
-- T→NDer (TmRefl du) = ´ apr S tmRefl ([] , ` T→NDer du)
-- T→NDer (TmSymm du=) = ´ apr S tmSymm ([] , ` T→NDer du=)
-- -- T→NDer (TmTran du= dv=) = apr S tmTran ([] , T→NDer du= , T→NDer dv=)
-- -- T→NDer (Conv du dA=) = apr S conv ([] , T→NDer du , T→NDer dA=)
-- -- T→NDer (ConvEq du= dA=) = apr S convEq ([] , T→NDer du= , T→NDer dA=)
-- -- T→NDer UU = apr T 1 []
-- -- T→NDer UUCong = apr C 1 []
-- -- T→NDer (El dv) = apr T 0 ([] ,0Tm T→NDer dv)
-- -- T→NDer (ElCong dv=) = apr C 0 ([] ,0Tm= T→NDer dv=)
-- -- T→NDer (Pi dA dB) = apr T 4 ([] ,0Ty T→NDer dA ,1Ty T→NDer dB)
-- -- T→NDer (PiCong dA= dB=) = apr C 4 ([] ,0Ty= T→NDer dA= ,1Ty= T→NDer dB=)
-- -- T→NDer (Lam {A = A} {B = B} {u = u} dA dB du) =
-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev (prev new))) ([] , T→N _ , T→N _ , T→N _) :> sym (prev (prev (prev (prev new)))) ([] , T→N _ , z))) Subst-insert-idMor)
-- -- (apr T 3 ([] ,0Ty T→NDer dA ,1Ty T→NDer dB ,1Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N _ :> z)) Subst-insert-idMor) (T→NDer du)))
-- -- T→NDer (LamCong dA= dB= du=) =
-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev (prev new))) ([] , T→N _ , T→N _ , T→N _) == sym (prev (prev (prev new))) ([] , T→N _ , T→N _ , T→N _) :> sym (prev (prev (prev (prev new)))) ([] , T→N _ , z)))
-- -- Subst-insert-idMor)
-- -- (apr C 3 ([] ,0Ty= T→NDer dA= ,1Ty= T→NDer dB= ,1Tm= NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N _ == T→N _ :> z)) Subst-insert-idMor) (T→NDer du=)))
-- -- T→NDer (App {A = A} {B} {f} {a} dA dB df da) =
-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev new)) ([] , T→N A , T→N B , T→N f , T→N a) :> z)) (Subst-T→N B a))
-- -- (apr T 2 ([] ,0Ty T→NDer dA
-- -- ,1Ty T→NDer dB
-- -- ,0Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N f :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z))) Subst-insert-idMor) (T→NDer df)
-- -- ,0Tm T→NDer da))
-- -- T→NDer (AppCong {A = A} {A' = A'} {B = B} {B' = B'} {f = f} {f' = f'} {a = a} {a' = a'} dA= dB= df= da=) =
-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev new)) ([] , T→N A , T→N B , T→N f , T→N a) == sym (prev (prev new)) ([] , T→N A' , T→N B' , T→N f' , T→N a') :> z)) (Subst-T→N B a))
-- -- (apr C 2 ([] ,0Ty= T→NDer dA=
-- -- ,1Ty= T→NDer dB=
-- -- ,0Tm= NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N f == T→N f' :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z))) Subst-insert-idMor)
-- -- (T→NDer df=)
-- -- ,0Tm= T→NDer da=))
-- -- T→NDer (BetaPi {A = A} {B = B} {u = u} {a = a} dA dB du da) =
-- -- NDerivable=! (ap4
-- -- (λ z z' z'' z''' →
-- -- njudgment _
-- -- (◇ ⊢
-- -- sym (prev (prev new))
-- -- ([] , T→N A , z ,
-- -- sym (prev (prev (prev new))) ([] , T→N A , z , z')
-- -- , T→N a)
-- -- == z'' :> z'''))
-- -- Subst-insert-idMor Subst-insert-idMor (Subst-T→N u a) (Subst-T→N B a))
-- -- (apr Eq 1 ([] ,0Ty T→NDer dA ,1Ty T→NDer dB ,1Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N u :> z)) Subst-insert-idMor) (T→NDer du) ,0Tm T→NDer da))
-- -- T→NDer (EtaPi {n = n} {A = A} {B = B} {f = f} dA dB df) =
-- -- NDerivable=! (ap4
-- -- (λ z z' z'' z''' →
-- -- njudgment _
-- -- (◇ ⊢ T→N f ==
-- -- sym (prev (prev (prev new)))
-- -- ([] , T→N A , z ,
-- -- sym (prev (prev new)) ([] , z' , z'' , z''' , var last))
-- -- :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z)))
-- -- Subst-insert-idMor (weaken-comm last) (Subst-insert-idMor2 ∙ weaken-comm (prev last)) (weaken-comm last))
-- -- (apr Eq 0 ([] ,0Ty T→NDer dA
-- -- ,1Ty T→NDer dB
-- -- ,0Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N f :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z))) Subst-insert-idMor) (T→NDer df)))
N→TCtx : {n : ℕ} → N.Ctx Σ n → T.Ctx n
N→TCtx ◇ = ◇
N→TCtx (Γ , A) = (N→TCtx Γ , N→T A)
N→TMor : {n m : ℕ} → N.Mor Σ n m → T.Mor n m
N→TMor ◇ = ◇
N→TMor (δ , u) = (N→TMor δ , N→T u)
weaken-comm' : {k : SyntaxSort} {n : ℕ} {A : N.Expr Σ n k} (p : WeakPos n) → N→T (N.weaken p A) ≡ T.weaken p (N→T A)
weaken-comm' p = ap N→T (ap (N.weaken p) (! (TNT _))) ∙ ap N→T (weaken-comm p) ∙ NTN _
get-eq : {n : ℕ} (k : ℕ) (Γ : N.Ctx Σ n) {def : _} → N→T (snd (N.get k Γ $ def)) ≡ T.get (fst (N.get k Γ $ def)) (N→TCtx Γ)
get-eq zero (Γ , A) = weaken-comm' last
get-eq (suc k) (Γ , A) = weaken-comm' last ∙ ap (T.weaken last) (get-eq k Γ)
N→TJ : NJudgment → T.Judgment
N→TJ (njudgment Γ (◇ ⊢ A)) = N→TCtx Γ ⊢ N→T A
N→TJ (njudgment Γ (◇ ⊢ u :> A)) = N→TCtx Γ ⊢ N→T u :> N→T A
N→TJ (njudgment Γ (◇ ⊢ A == B)) = N→TCtx Γ ⊢ N→T A == N→T B
N→TJ (njudgment Γ (◇ ⊢ u == v :> A)) = N→TCtx Γ ⊢ N→T u == N→T v :> N→T A
congTy : {Γ : T.Ctx n} {A A' : T.TyExpr n} → A ≡ A' → T.Derivable (Γ ⊢ A) → T.Derivable (Γ ⊢ A')
congTy refl d = d
congTmTy : {Γ : T.Ctx n} {u : T.TmExpr n} {A A' : T.TyExpr n} → A ≡ A' → T.Derivable (Γ ⊢ u :> A) → T.Derivable (Γ ⊢ u :> A')
congTmTy refl d = d
congTmTy! : {Γ : T.Ctx n} {u : T.TmExpr n} {A A' : T.TyExpr n} → A' ≡ A → T.Derivable (Γ ⊢ u :> A) → T.Derivable (Γ ⊢ u :> A')
congTmTy! refl d = d
congTmEqTy : {Γ : T.Ctx n} {u u' : T.TmExpr n} {A A' : T.TyExpr n} → A ≡ A' → T.Derivable (Γ ⊢ u == u' :> A) → T.Derivable (Γ ⊢ u == u' :> A')
congTmEqTy refl d = d
congTmEqTy! : {Γ : T.Ctx n} {u u' : T.TmExpr n} {A A' : T.TyExpr n} → A' ≡ A → T.Derivable (Γ ⊢ u == u' :> A) → T.Derivable (Γ ⊢ u == u' :> A')
congTmEqTy! refl d = d
congTmEq : {Γ : T.Ctx n} {u u' v v' : T.TmExpr n} {A A' : T.TyExpr n} → A ≡ A' → u ≡ u' → v ≡ v' → T.Derivable (Γ ⊢ u == v :> A) → T.Derivable (Γ ⊢ u' == v' :> A')
congTmEq refl refl refl d = d
congTmEq! : {Γ : T.Ctx n} {u u' v v' : T.TmExpr n} {A A' : T.TyExpr n} → A' ≡ A → u' ≡ u → v' ≡ v → T.Derivable (Γ ⊢ u == v :> A) → T.Derivable (Γ ⊢ u' == v' :> A')
congTmEq! refl refl refl d = d
N→T-Subst : {k : _} (B : N.Expr Σ (suc n) k) (a : N.TmExpr Σ n) → N→T (SubstMor B (N.idMor , a)) ≡ T.subst (N→T B) (N→T a)
N→T-Subst B a = ap N→T (! (ap2 SubstMor (TNT B) (ap2 _,_ refl (TNT a))) ∙ Subst-T→N (N→T B) (N→T a)) ∙ NTN _
N→TDer : {j : NJudgment} → NDerivable j → T.Derivable (N→TJ j)
-- N→TDer {njudgment Γ _} (apr S (var k) {js = [] , ◇ ⊢ A} ([] , dA) {{xᵈ , (refl , tt)}}) = congTmTy! (get-eq k Γ) (Var (fst (N.get k Γ $ xᵈ)) (congTy (get-eq k Γ) (N→TDer dA)))
-- N→TDer {njudgment Γ _} (apr S conv {js = [] , ◇ ⊢ u :> A , ◇ ⊢ A == B} ([] , du , dA=) {{refl , tt}}) = Conv (N→TDer du) (N→TDer dA=)
-- N→TDer {njudgment Γ _} (apr S convEq {js = [] , ◇ ⊢ u == v :> A , ◇ ⊢ A == B} ([] , du= , dA=) {{refl , tt}}) = ConvEq (N→TDer du=) (N→TDer dA=)
-- N→TDer {njudgment Γ _} (apr S tyRefl {js = [] , ◇ ⊢ A} ([] , dA)) = TyRefl (N→TDer dA)
-- N→TDer {njudgment Γ _} (apr S tySymm {js = [] , ◇ ⊢ A == B} ([] , dA=)) = TySymm (N→TDer dA=)
-- N→TDer {njudgment Γ _} (apr S tyTran {js = [] , ◇ ⊢ A == B , ◇ ⊢ B == D} ([] , dA= , dB=) {{refl , tt}}) = TyTran (N→TDer dA=) (N→TDer dB=)
-- N→TDer {njudgment Γ _} (apr S tmRefl {js = [] , ◇ ⊢ u :> A} ([] , du)) = TmRefl (N→TDer du)
-- N→TDer {njudgment Γ _} (apr S tmSymm {js = [] , ◇ ⊢ u == v :> A} ([] , du=)) = TmSymm (N→TDer du=)
-- N→TDer {njudgment Γ _} (apr S tmTran {js = [] , ◇ ⊢ u == v :> A , ◇ ⊢ v == w :> A} ([] , du= , dv=) {{refl , (refl , tt)}}) = TmTran (N→TDer du=) (N→TDer dv=)
-- N→TDer {njudgment Γ _} (apr T typingrule {js = [] , (◇ ⊢ v :> _)} ([] , dv) {{(tt , (tt , (refl , tt))) , tt}}) = El (N→TDer dv)
-- N→TDer {njudgment Γ _} (apr T (prev typingrule) []) = UU
-- N→TDer {njudgment Γ _} (apr T (prev (prev typingrule)) {js = [] , ◇ ⊢ A , (◇ , _) ⊢ B , (◇ ⊢ f :> _) , (◇ ⊢ a :> _)} ([] , dA , dB , df , da)
-- {{(((((tt , (tt , tt)) , ((tt , refl) , tt)) , (tt , (refl , tt))) , (tt , (refl , tt))) , tt)}}) = congTmTy! (N→T-Subst B a) (App (N→TDer dA) (N→TDer dB) (congTmTy (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (N→TDer df)) (N→TDer da))
-- N→TDer {njudgment Γ _} (apr T (prev (prev (prev typingrule))) {js = [] , ◇ ⊢ A , ((◇ , A) ⊢ B) , ((◇ , A) ⊢ u :> B')} ([] , dA , dB , du) {{(((tt , (tt , tt)) , ((tt , refl) , tt)) , ((tt , refl) , (refl , tt)) ) , tt}})
-- = congTmTy! (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (Lam (N→TDer dA) (N→TDer dB) (congTmTy (ap N→T Subst-insert-idMor) (N→TDer du)))
-- N→TDer {njudgment Γ _} (apr T (prev (prev (prev (prev typingrule)))) {js = [] , ◇ ⊢ A , (◇ , ._) ⊢ B} ([] , dA , dB) {{((tt , (tt , tt)) , ((tt , refl) , tt)) , tt}}) = Pi (N→TDer dA) (N→TDer dB)
-- N→TDer {njudgment Γ _} (apr C congruencerule {js = [] , ◇ ⊢ v == v' :> _} ([] , dv=) {{((tt , (tt , (refl , tt))) , tt)}}) = ElCong (N→TDer dv=)
-- N→TDer {njudgment Γ _} (apr C (prev congruencerule) []) = UUCong
-- N→TDer {njudgment Γ _} (apr C (prev (prev congruencerule)) {js = [] , ◇ ⊢ A == A' , (◇ , _) ⊢ B == B' , (◇ ⊢ f == f' :> _) , (◇ ⊢ a == a' :> _)} ([] , dA= , dB= , df= , da=)
-- {{(((((tt , (tt , tt)) , ((tt , refl) , tt)) , (tt , (refl , tt))) , (tt , (refl , tt))) , tt)}})
-- = congTmEqTy! (N→T-Subst B a) (AppCong (N→TDer dA=) (N→TDer dB=) (congTmEqTy (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (N→TDer df=)) (N→TDer da=))
-- N→TDer {njudgment Γ _} (apr C (prev (prev (prev congruencerule))) {js = [] , ◇ ⊢ A == A' , ((◇ , A) ⊢ B == B') , ((◇ , A) ⊢ u == u' :> B'')} ([] , dA= , dB= , du=) {{(((tt , (tt , tt)) , ((tt , refl) , tt)) , ((tt , refl) , (refl , tt)) ) , tt}}) = congTmEqTy! (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (LamCong (N→TDer dA=) (N→TDer dB=) (congTmEqTy (ap N→T Subst-insert-idMor) (N→TDer du=)))
-- N→TDer {njudgment Γ _} (apr C (prev (prev (prev (prev congruencerule)))) {js = [] , ◇ ⊢ A == A' , (◇ , ._) ⊢ B == B'} ([] , dA= , dB=) {{(((tt , (tt , tt)) , ((tt , refl) , tt)) , tt)}}) = PiCong (N→TDer dA=) (N→TDer dB=)
-- N→TDer {njudgment Γ _} (apr Eq equalityrule js-der) = {!Eta!}
N→TDer {njudgment Γ _} (apr Eq (prev equalityrule) {js = [] , (◇ ⊢ A) , ((◇ , _) ⊢ B) , ((◇ , _) ⊢ u :> _) , (◇ ⊢ a :> _)} ([] , dA , dB , du , da)
{{(((((tt , (tt , tt)) , ((tt , refl) , tt)) , ((tt , refl) , (refl , tt))) , (tt , (refl , tt))) , tt)}})
= {!da --jdef --congTmEq! ? ? ? (BetaPi (N→TDer dA) (N→TDer dB) (congTmTy (ap N→T Subst-insert-idMor) (N→TDer du)) (N→TDer da))!}
|
{
"alphanum_fraction": 0.4903649478,
"avg_line_length": 59.4179104478,
"ext": "agda",
"hexsha": "c62a5543c82bdf364aa287006d9a1a5cce135df0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guillaumebrunerie/general-type-theories",
"max_forks_repo_path": "comparison.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guillaumebrunerie/general-type-theories",
"max_issues_repo_path": "comparison.agda",
"max_line_length": 399,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guillaumebrunerie/general-type-theories",
"max_stars_repo_path": "comparison.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 12910,
"size": 27867
}
|
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
variable
A B : Set
x y z : A
xs ys zs : List A
f : A → B
m n : Nat
cong : (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
trans : x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
+zero : m + zero ≡ m
+zero {zero} = refl
+zero {suc m} = cong suc +zero
suc+zero : suc m + zero ≡ suc m
suc+zero = +zero
+suc : m + (suc n) ≡ suc (m + n)
+suc {zero} = refl
+suc {suc m} = cong suc +suc
zero+suc : zero + (suc n) ≡ suc n
zero+suc = refl
suc+suc : (suc m) + (suc n) ≡ suc (suc (m + n))
suc+suc = cong suc +suc
{-# REWRITE +zero +suc suc+zero zero+suc suc+suc #-}
map : (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = (f x) ∷ (map f xs)
_++_ : List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
++-[] : xs ++ [] ≡ xs
++-[] {xs = []} = refl
++-[] {xs = x ∷ xs} = cong (_∷_ x) ++-[]
∷-++-[] : (x ∷ xs) ++ [] ≡ x ∷ xs
∷-++-[] = ++-[]
map-id : map (λ x → x) xs ≡ xs
map-id {xs = []} = refl
map-id {xs = x ∷ xs} = cong (_∷_ x) map-id
map-id-∷ : map (λ x → x) (x ∷ xs) ≡ x ∷ xs
map-id-∷ = map-id
{-# REWRITE ++-[] ∷-++-[] #-}
{-# REWRITE map-id map-id-∷ #-}
|
{
"alphanum_fraction": 0.5003903201,
"avg_line_length": 20.015625,
"ext": "agda",
"hexsha": "ad35f5c9419f1752354034e0ba2f2f86d29d14d2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/RewritingGlobalConfluenceWithClauses.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/RewritingGlobalConfluenceWithClauses.agda",
"max_line_length": 52,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/RewritingGlobalConfluenceWithClauses.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 565,
"size": 1281
}
|
module Luau.Var.ToString where
open import Agda.Builtin.String using (String)
open import Luau.Var using (Var)
varToString : Var → String
varToString x = x
|
{
"alphanum_fraction": 0.7672955975,
"avg_line_length": 17.6666666667,
"ext": "agda",
"hexsha": "10cd915b64022e094dcfc20eb593685faae7d609",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/Luau/Var/ToString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/Luau/Var/ToString.agda",
"max_line_length": 46,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/Luau/Var/ToString.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 40,
"size": 159
}
|
module Issue739 where
record ⊤ : Set where
constructor tt
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
uncurry : {A : Set} {B : A → Set} →
((x : A) → B x → Set) →
Σ A B → Set
uncurry f (x , y) = f x y
data U : Set₁
El : U → Set
infixl 5 _▻_
data U where
ε : U
_▻_ : (u : U) → (El u → Set) → U
El ε = ⊤
El (u ▻ P) = Σ (El u) P
Id : ∀ u → (El u → Set) → El u → Set
Id u P = P
-- Type-checks:
works : U
works =
ε
▻ (λ _ → ⊤)
▻ (λ { (_ , _) → ⊤ })
-- Type-checks:
works′ : U
works′ =
ε
▻ (λ _ → ⊤)
▻ Id (_ ▻ _) (λ { (_ , _) → ⊤ })
-- Type-checks:
works″ : U
works″ =
ε
▻ (λ _ → ⊤)
▻ Id _ (uncurry λ _ _ → ⊤)
-- Type-checks:
works‴ : U
works‴ =
ε
▻ (λ _ → ⊤)
▻ Id _ const-⊤
where
const-⊤ : _ → _
const-⊤ (_ , _) = ⊤
-- Type-checks:
works⁗ : U
works⁗ =
ε
▻ (λ _ → ⊤)
▻ Id _ const-⊤
where
const-⊤ : _ → _
const-⊤ = λ { (_ , _) → ⊤ }
-- Type-checks:
works′́ : U
works′́ =
ε
▻ (λ _ → ⊤)
▻ Id _ (λ { _ → ⊤ })
-- Doesn't type-check (but I want to write something like this):
fails : U
fails =
ε
▻ (λ _ → ⊤)
▻ Id _ (λ { (_ , _) → ⊤ })
-- Given all the working examples I'm led to believe that there is
-- something wrong with pattern-matching lambdas. Please correct me if
-- I'm wrong.
-- Andreas, 2012-10-29 should work now.
|
{
"alphanum_fraction": 0.4750542299,
"avg_line_length": 13.6930693069,
"ext": "agda",
"hexsha": "797e7796ebb4b5dad3a466c477b7126e9ca6cfe9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue739.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue739.agda",
"max_line_length": 70,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/Issue739.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 598,
"size": 1383
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Groups.Definition
open import Sets.EquivalenceRelations
open import Groups.Abelian.Definition
open import Groups.Homomorphisms.Definition
open import Groups.DirectSum.Definition
open import Groups.Isomorphisms.Definition
module Groups.Abelian.Lemmas where
directSumAbelianGroup : {m n o p : _} → {A : Set m} {S : Setoid {m} {o} A} {_·A_ : A → A → A} {B : Set n} {T : Setoid {n} {p} B} {_·B_ : B → B → B} {underG : Group S _·A_} {underH : Group T _·B_} (G : AbelianGroup underG) (h : AbelianGroup underH) → (AbelianGroup (directSumGroup underG underH))
AbelianGroup.commutative (directSumAbelianGroup {A = A} {B} G H) = AbelianGroup.commutative G ,, AbelianGroup.commutative H
subgroupOfAbelianIsAbelian : {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_+A_ : A → A → A} {_+B_ : B → B → B} {G : Group S _+A_} {H : Group T _+B_} {f : B → A} {fHom : GroupHom H G f} → SetoidInjection T S f → AbelianGroup G → AbelianGroup H
AbelianGroup.commutative (subgroupOfAbelianIsAbelian {S = S} {_+B_ = _+B_} {fHom = fHom} fInj record { commutative = commutative }) {x} {y} = SetoidInjection.injective fInj (transitive (GroupHom.groupHom fHom) (transitive commutative (symmetric (GroupHom.groupHom fHom))))
where
open Setoid S
open Equivalence eq
abelianIsGroupProperty : {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_+A_ : A → A → A} {_+B_ : B → B → B} {G : Group S _+A_} {H : Group T _+B_} → GroupsIsomorphic G H → AbelianGroup H → AbelianGroup G
abelianIsGroupProperty iso abH = subgroupOfAbelianIsAbelian {fHom = GroupIso.groupHom (GroupsIsomorphic.proof iso)} (SetoidBijection.inj (GroupIso.bij (GroupsIsomorphic.proof iso))) abH
|
{
"alphanum_fraction": 0.6913849509,
"avg_line_length": 73.36,
"ext": "agda",
"hexsha": "ce0f764ccaff81fc03a4466bc8412f4c2b22033f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/Abelian/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Abelian/Lemmas.agda",
"max_line_length": 295,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/Abelian/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 663,
"size": 1834
}
|
open import Agda.Primitive
variable
a : Level
postulate
works : Set a → {a : Set} → a
fails : Set a → {a : Set} → {!a!}
module _ (A : Set a) (a : A) where
x : A
x = a
|
{
"alphanum_fraction": 0.5359116022,
"avg_line_length": 12.9285714286,
"ext": "agda",
"hexsha": "1e50dba5e509ca01d213aa27fc9724b63be8fbe5",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue3735.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue3735.agda",
"max_line_length": 35,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue3735.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 73,
"size": 181
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.ZCohomology.KcompPrelims where
open import Cubical.ZCohomology.Base
open import Cubical.Homotopy.Connected
open import Cubical.HITs.Hopf
open import Cubical.Homotopy.Freudenthal hiding (encode)
open import Cubical.HITs.Sn
open import Cubical.HITs.S1
open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; map to trMap)
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Data.Int renaming (_+_ to +Int)
open import Cubical.Data.Nat
open import Cubical.HITs.Susp
open import Cubical.HITs.Nullification
open import Cubical.Data.Prod.Base
open import Cubical.Homotopy.Loopspace
open import Cubical.Data.Bool
open import Cubical.Data.Sum.Base
open import Cubical.Data.Sigma hiding (_×_)
open import Cubical.Foundations.Function
open import Cubical.Foundations.Pointed
open import Cubical.HITs.S3
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
{- We want to prove that Kn≃ΩKn+1. For this we use the map ϕ-}
ϕ : (pt a : A) → typ (Ω (Susp A , north))
ϕ pt a = (merid a) ∙ sym (merid pt)
{- To define the map for n=0 we use the λ k → loopᵏ map for S₊ 1. The loop is given by ϕ north south -}
loop* : Path (S₊ 1) north north
loop* = ϕ north south
looper : Int → Path (S₊ 1) north north
looper (pos zero) = refl
looper (pos (suc n)) = looper (pos n) ∙ loop*
looper (negsuc zero) = sym loop*
looper (negsuc (suc n)) = looper (negsuc n) ∙ sym loop*
private
{- The map of Kn≃ΩKn+1 is given as follows. -}
Kn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n)))
Kn→ΩKn+1 zero x = cong ∣_∣ (looper x)
Kn→ΩKn+1 (suc n) = trRec (isOfHLevelTrunc (2 + (suc (suc n))) ∣ north ∣ ∣ north ∣)
λ a → cong ∣_∣ ((merid a) ∙ (sym (merid north)))
{- We show that looper is a composition of intLoop with two other maps, all three being isos -}
sndcomp : ΩS¹ → Path (Susp Bool) north north
sndcomp = cong S¹→SuspBool
thrdcomp : Path (Susp Bool) north north → Path (S₊ 1) north north
thrdcomp = cong SuspBool→S1
looper2 : Int → Path (S₊ 1) north north
looper2 a = thrdcomp (sndcomp (intLoop a))
looper≡looper2 : (x : Int) → looper x ≡ looper2 x
looper≡looper2 (pos zero) = refl
looper≡looper2 (pos (suc n)) =
looper (pos n) ∙ loop* ≡⟨ (λ i → looper≡looper2 (pos n) i ∙ congFunct SuspBool→S1 (merid false) (sym (merid true)) (~ i)) ⟩
looper2 (pos n) ∙ cong SuspBool→S1 (ϕ true false) ≡⟨ sym (congFunct SuspBool→S1 (sndcomp (intLoop (pos n))) (ϕ true false)) ⟩
cong SuspBool→S1 (sndcomp (intLoop (pos n)) ∙ ϕ true false) ≡⟨ cong thrdcomp (sym (congFunct S¹→SuspBool (intLoop (pos n)) loop)) ⟩
looper2 (pos (suc n)) ∎
looper≡looper2 (negsuc zero) =
sym loop* ≡⟨ symDistr (merid south) (sym (merid north)) ⟩
merid north ∙ sym (merid south) ≡⟨ sym (congFunct SuspBool→S1 (merid true) (sym (merid false))) ⟩
cong SuspBool→S1 (merid true ∙ sym (merid false)) ≡⟨ cong thrdcomp (sym (symDistr (merid false) (sym (merid true)))) ⟩
looper2 (negsuc zero) ∎
looper≡looper2 (negsuc (suc n)) =
looper (negsuc n) ∙ sym loop* ≡⟨ ((λ i → looper≡looper2 (negsuc n) i ∙ symDistr (merid south) (sym (merid north)) i)) ⟩
looper2 (negsuc n) ∙ merid north ∙ sym (merid south) ≡⟨ cong (λ x → looper2 (negsuc n) ∙ x) (sym (congFunct SuspBool→S1 (merid true) (sym (merid false)))) ⟩
looper2 (negsuc n) ∙ cong SuspBool→S1 (ϕ false true) ≡⟨ cong (λ x → looper2 (negsuc n) ∙ x) (cong thrdcomp (sym (symDistr (merid false) (sym (merid true))))) ⟩
looper2 (negsuc n) ∙ cong SuspBool→S1 (sym (ϕ true false)) ≡⟨ sym (congFunct SuspBool→S1 (sndcomp (intLoop (negsuc n))) (sym (ϕ true false))) ⟩
thrdcomp (cong S¹→SuspBool (intLoop (negsuc n)) ∙ cong S¹→SuspBool (sym loop)) ≡⟨ cong thrdcomp (sym (congFunct S¹→SuspBool (intLoop (negsuc n)) (sym loop))) ⟩
looper2 (negsuc (suc n)) ∎
private
isolooper2 : Iso Int (Path (S₊ 1) north north)
isolooper2 = compIso (invIso ΩS¹IsoInt) (compIso iso2 iso1)
where
iso1 : Iso (Path (Susp Bool) north north) (Path (S₊ 1) north north)
iso1 = congIso SuspBoolIsoS1
iso2 : Iso ΩS¹ (Path (Susp Bool) north north)
iso2 = congIso S¹IsoSuspBool
isolooper : Iso Int (Path (S₊ 1) north north)
Iso.fun isolooper = looper
Iso.inv isolooper = Iso.inv isolooper2
Iso.rightInv isolooper a = (looper≡looper2 (Iso.inv isolooper2 a)) ∙ Iso.rightInv isolooper2 a
Iso.leftInv isolooper a = cong (Iso.inv isolooper2) (looper≡looper2 a) ∙ Iso.leftInv isolooper2 a
{- We want to show that this map is an equivalence. n ≥ 2 follows from Freudenthal, and -}
{-
We want to show that the function (looper : Int → S₊ 1) defined by λ k → loopᵏ is an equivalece. We already know that the corresponding function (intLoop : Int → S¹ is) an equivalence,
so the idea is to show that when intLoop is transported along a suitable path S₊ 1 ≡ S¹ we get looper. Instead of using S₊ 1 straight away, we begin by showing this for the equivalent Susp Bool.
-}
----------------------------------- n = 1 -----------------------------------------------------
{- We begin by stating some useful lemmas -}
S³≡SuspSuspS¹ : S³ ≡ Susp (Susp S¹)
S³≡SuspSuspS¹ = S³≡SuspS² ∙ λ i → Susp (S²≡SuspS¹ i)
S3≡SuspSuspS¹ : S₊ 3 ≡ Susp (Susp S¹)
S3≡SuspSuspS¹ = (λ i → Susp (Susp (Susp (ua Bool≃Susp⊥ (~ i))))) ∙ λ i → Susp (Susp (S¹≡SuspBool (~ i)))
sphereConnectedSpecCase : isConnected 4 (Susp (Susp S¹))
sphereConnectedSpecCase = transport (λ i → isConnected 4 (S3≡SuspSuspS¹ i)) (sphereConnected 3)
{- We give the following map and show that its truncation is an equivalence -}
d-map : typ (Ω ((Susp S¹) , north)) → S¹
d-map p = subst HopfSuspS¹ p base
d-mapId : (r : S¹) → d-map (ϕ base r) ≡ r
d-mapId r = substComposite HopfSuspS¹ (merid r) (sym (merid base)) base ∙
rotLemma r
where
rotLemma : (r : S¹) → rot r base ≡ r
rotLemma base = refl
rotLemma (loop i) = refl
d-mapComp : fiber d-map base ≡ Path (Susp (Susp S¹)) north north
d-mapComp = ΣPathTransport≡PathΣ {B = HopfSuspS¹} _ _ ∙ helper
where
helper : Path (Σ (Susp S¹) λ x → HopfSuspS¹ x) (north , base) (north , base) ≡ Path (Susp (Susp S¹)) north north
helper = (λ i → (Path (S³≡TotalHopf (~ i))
(transp (λ j → S³≡TotalHopf (~ i ∨ ~ j)) (~ i) (north , base))
((transp (λ j → S³≡TotalHopf (~ i ∨ ~ j)) (~ i) (north , base))))) ∙
(λ i → Path (S³≡SuspSuspS¹ i) (transp (λ j → S³≡SuspSuspS¹ (i ∧ j)) (~ i) base) ((transp (λ j → S³≡SuspSuspS¹ (i ∧ j)) (~ i) base)))
is1Connected-dmap : isConnectedFun 3 d-map
is1Connected-dmap = toPropElim (λ s → isPropIsOfHLevel 0) (transport (λ j → isContr (∥ d-mapComp (~ j) ∥ 3))
(transport (λ i → isContr (PathΩ {A = Susp (Susp S¹)} {a = north} 3 i))
(refl , isOfHLevelSuc 1 (isOfHLevelSuc 0 sphereConnectedSpecCase) ∣ north ∣ ∣ north ∣ (λ _ → ∣ north ∣))))
d-iso2 : Iso (hLevelTrunc 3 (typ (Ω (Susp S¹ , north)))) (hLevelTrunc 3 S¹)
d-iso2 = connectedTruncIso _ d-map is1Connected-dmap
{- We show that composing (λ a → ∣ ϕ base a ∣) and (λ x → ∣ d-map x ∣) gives us the identity function. -}
d-mapId2 : Iso.fun d-iso2 ∘ trMap (ϕ base) ≡ idfun (hLevelTrunc 3 S¹)
d-mapId2 = funExt (trElim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) (λ a → cong ∣_∣ (d-mapId a)))
{- This means that (λ a → ∣ ϕ base a ∣) is an equivalence -}
Iso∣ϕ-base∣ : Iso (hLevelTrunc 3 S¹) (hLevelTrunc 3 (typ (Ω (Susp S¹ , north))))
Iso∣ϕ-base∣ = composesToId→Iso d-iso2 (trMap (ϕ base)) d-mapId2
---------------------------------
-- We cheat when n = 1 and use J to prove the following lemmma. There is an obvious dependent path between ϕ base and ϕ north. Since the first one is an iso, so is the other.
-- So far this hasn't been an issue.
pointFunIso : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ} {C : (A : Type ℓ) (a1 : A) → Type ℓ'} (p : A ≡ B) (a : A) (b : B) →
(transport p a ≡ b) →
(f : (A : Type ℓ) →
(a1 : A) (a2 : hLevelTrunc 3 A) → C A a1) →
isIso (f A a) →
isIso (f B b)
pointFunIso {ℓ = ℓ}{A = A} {B = B} {C = C} =
J (λ B p → (a : A) (b : B) →
(transport p a ≡ b) →
(f : (A : Type ℓ) →
(a1 : A) (a2 : hLevelTrunc 3 A) → C A a1) →
isIso (f A a) →
isIso (f B b))
λ a b trefl f is → transport (λ i → isIso (f A ((sym (transportRefl a) ∙ trefl) i))) is
{- By pointFunIso, this gives that λ a → ∣ ϕ north a ∣ is an iso -}
isIso∣ϕ∣ : isIso {A = hLevelTrunc 3 (S₊ 1)} {B = hLevelTrunc 3 (typ (Ω (S₊ 2 , north)))} (trMap (ϕ north))
isIso∣ϕ∣ = pointFunIso {A = S¹} (λ i → S¹≡S1 (~ i)) base north refl (λ A a1 → trMap (ϕ a1)) ((Iso.inv Iso∣ϕ-base∣) , ((Iso.rightInv Iso∣ϕ-base∣) , (Iso.leftInv Iso∣ϕ-base∣)))
Iso∣ϕ∣ : Iso (hLevelTrunc 3 (S₊ 1)) (hLevelTrunc 3 (typ (Ω (S₊ 2 , north))))
Iso.fun Iso∣ϕ∣ = trMap (ϕ north)
Iso.inv Iso∣ϕ∣ = isIso∣ϕ∣ .fst
Iso.rightInv Iso∣ϕ∣ = isIso∣ϕ∣ .snd .fst
Iso.leftInv Iso∣ϕ∣ = isIso∣ϕ∣ .snd .snd
---------------------------------------------------- Finishing up ---------------------------------
-- We need ΩTrunc. It appears to compute better when restated for this particular case --
decode-fun2 : (n : HLevel) → (x : A) → hLevelTrunc n (x ≡ x) → Path (hLevelTrunc (suc n) A) ∣ x ∣ ∣ x ∣
decode-fun2 zero x = trElim (λ _ → isOfHLevelPath 0 (∣ x ∣ , isOfHLevelTrunc 1 ∣ x ∣) ∣ x ∣ ∣ x ∣) (λ p i → ∣ p i ∣)
decode-fun2 (suc n) x = trElim (λ _ → isOfHLevelPath' (suc n) (isOfHLevelTrunc (suc (suc n))) ∣ x ∣ ∣ x ∣) (cong ∣_∣)
funsAreSame : (n : HLevel) (x : A) (b : hLevelTrunc n (x ≡ x)) → (decode-fun2 n x b) ≡ (ΩTrunc.decode-fun ∣ x ∣ ∣ x ∣ b)
funsAreSame zero x = trElim (λ a → isOfHLevelPath 0 (refl , (isOfHLevelSuc 1 (isOfHLevelTrunc 1) ∣ x ∣ ∣ x ∣ refl)) _ _) λ a → refl
funsAreSame (suc n) x = trElim (λ a → isOfHLevelPath _ (isOfHLevelPath' (suc n) (isOfHLevelTrunc (suc (suc n))) ∣ x ∣ ∣ x ∣) _ _) λ a → refl
decodeIso : (n : HLevel) (x : A) → Iso (hLevelTrunc n (x ≡ x)) (Path (hLevelTrunc (suc n) A) ∣ x ∣ ∣ x ∣)
Iso.fun (decodeIso n x) = decode-fun2 n x
Iso.inv (decodeIso n x) = ΩTrunc.encode-fun ∣ x ∣ ∣ x ∣
Iso.rightInv (decodeIso n x) b = funsAreSame n x (ΩTrunc.encode-fun ∣ x ∣ ∣ x ∣ b) ∙ ΩTrunc.P-rinv ∣ x ∣ ∣ x ∣ b
Iso.leftInv (decodeIso n x) b = cong (ΩTrunc.encode-fun ∣ x ∣ ∣ x ∣) (funsAreSame n x b) ∙ ΩTrunc.P-linv ∣ x ∣ ∣ x ∣ b
Iso-Kn-ΩKn+1 : (n : HLevel) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n))))
Iso-Kn-ΩKn+1 zero = compIso isolooper (congIso (truncIdempotentIso _ isOfHLevelS1))
Iso-Kn-ΩKn+1 (suc zero) = compIso Iso∣ϕ∣ (decodeIso _ north)
Iso-Kn-ΩKn+1 (suc (suc n)) = compIso (connectedTruncIso2 (4 + n) _ (ϕ north) (n , helper)
(isConnectedσ (suc n) (sphereConnected _)))
(decodeIso _ north)
where
helper : n + (4 + n) ≡ 2 + (n + (2 + n))
helper = +-suc n (3 + n) ∙ (λ i → suc (+-suc n (2 + n) i))
mapId2 : (n : ℕ) → Kn→ΩKn+1 n ≡ Iso.fun (Iso-Kn-ΩKn+1 n)
mapId2 zero = refl
mapId2 (suc zero) = funExt (trElim (λ x → isOfHLevelPath 3 (isOfHLevelTrunc 4 ∣ north ∣ ∣ north ∣) _ _) λ a → refl)
mapId2 (suc (suc n)) = funExt (trElim (λ x → isOfHLevelPath (4 + n) (isOfHLevelTrunc (5 + n) ∣ north ∣ ∣ north ∣) _ _) λ a → refl)
-- Experiments with abstract definitions
Iso2-Kn-ΩKn+1 : (n : ℕ) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n))))
Iso.fun (Iso2-Kn-ΩKn+1 n) = Kn→ΩKn+1 n
Iso.inv (Iso2-Kn-ΩKn+1 n) = Iso.inv (Iso-Kn-ΩKn+1 n)
Iso.rightInv (Iso2-Kn-ΩKn+1 n) a = rinv
where
abstract
rinv : Kn→ΩKn+1 n (Iso.inv (Iso-Kn-ΩKn+1 n) a) ≡ a
rinv = funExt⁻ (mapId2 n) _ ∙ Iso.rightInv (Iso-Kn-ΩKn+1 n) a
Iso.leftInv (Iso2-Kn-ΩKn+1 n) a = linv
where
abstract
linv : Iso.inv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n a) ≡ a
linv = cong (Iso.inv (Iso-Kn-ΩKn+1 n)) (funExt⁻ (mapId2 n) a) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 n) a
--- even more abstract
abstract
absInv' : (n : ℕ) → typ (Ω (coHomK-ptd (2 + n))) → coHomK (1 + n)
absInv' n = Iso.inv (Iso-Kn-ΩKn+1 (1 + n))
absSect' : (n : ℕ) (a : typ (Ω (coHomK-ptd (2 + n)))) → Kn→ΩKn+1 (1 + n) (absInv' n a) ≡ a
absSect' n a = funExt⁻ (mapId2 (1 + n)) _ ∙ Iso.rightInv (Iso-Kn-ΩKn+1 (1 + n)) a
absRetr' : (n : ℕ) (a : coHomK (1 + n)) → absInv' n (Kn→ΩKn+1 (1 + n) a) ≡ a
absRetr' n a = cong (Iso.inv (Iso-Kn-ΩKn+1 (1 + n))) (funExt⁻ (mapId2 (1 + n)) a) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 (1 + n)) a
absInv : (n : ℕ) → typ (Ω (coHomK-ptd (1 + n))) → coHomK n
absInv zero = Iso.inv (Iso-Kn-ΩKn+1 zero)
absInv (suc n) = absInv' n
absSect : (n : ℕ) → section (Kn→ΩKn+1 n) (absInv n)
absSect zero a = funExt⁻ (mapId2 zero) (Iso.inv isolooper2 (Iso.inv (congIso (truncIdempotentIso _ isOfHLevelS1)) a)) ∙ Iso.rightInv (Iso-Kn-ΩKn+1 zero) a
absSect (suc n) = absSect' n
absRetr : (n : ℕ) → retract (Kn→ΩKn+1 n) (absInv n)
absRetr zero a = cong (Iso.inv (Iso-Kn-ΩKn+1 zero)) (funExt⁻ (mapId2 zero) a) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 zero) a
absRetr (suc n) = absRetr' n
Iso3-Kn-ΩKn+1 : (n : ℕ) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n))))
Iso.fun (Iso3-Kn-ΩKn+1 n) = Kn→ΩKn+1 n
Iso.inv (Iso3-Kn-ΩKn+1 n) = absInv n
Iso.rightInv (Iso3-Kn-ΩKn+1 n) = absSect n
Iso.leftInv (Iso3-Kn-ΩKn+1 n) = absRetr n
|
{
"alphanum_fraction": 0.5911798071,
"avg_line_length": 47.6486486486,
"ext": "agda",
"hexsha": "30c94aecd33299100ccbcd687356b2bcd5cc3d54",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "knrafto/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/KcompPrelims.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "knrafto/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/KcompPrelims.agda",
"max_line_length": 196,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "knrafto/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/KcompPrelims.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5617,
"size": 14104
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.types.Bool
open import lib.types.Int
module lib.types.List where
infixr 60 _::_
data List {i} (A : Type i) : Type i where
nil : List A
_::_ : A → List A → List A
module _ {i} {A : Type i} where
infixr 80 _++_
_++_ : List A → List A → List A
nil ++ l = l
(x :: l₁) ++ l₂ = x :: (l₁ ++ l₂)
snoc : List A → A → List A
snoc l a = l ++ (a :: nil)
++-unit-r : ∀ l → l ++ nil == l
++-unit-r nil = idp
++-unit-r (a :: l) = ap (a ::_) $ ++-unit-r l
++-assoc : ∀ l₁ l₂ l₃ → (l₁ ++ l₂) ++ l₃ == l₁ ++ (l₂ ++ l₃)
++-assoc nil l₂ l₃ = idp
++-assoc (x :: l₁) l₂ l₃ = ap (x ::_) (++-assoc l₁ l₂ l₃)
-- properties
module _ {j} (P : A → Type j) where
data Any : List A → Type (lmax i j) where
here : ∀ {a} {l} → P a → Any (a :: l)
there : ∀ {a} {l} → Any l → Any (a :: l)
data All : List A → Type (lmax i j) where
nil : All nil
_::_ : ∀ {a} {l} → P a → All l → All (a :: l)
Any-dec : (∀ a → Dec (P a)) → (∀ l → Dec (Any l))
Any-dec _ nil = inr λ{()}
Any-dec dec (a :: l) with dec a
... | inl p = inl $ here p
... | inr ¬p with Any-dec dec l
... | inl ∃p = inl $ there ∃p
... | inr ¬∃p = inr λ{(here p) → ¬p p; (there ∃p) → ¬∃p ∃p}
Any-++-l : ∀ l₁ l₂ → Any l₁ → Any (l₁ ++ l₂)
Any-++-l _ _ (here p) = here p
Any-++-l _ _ (there ∃p) = there (Any-++-l _ _ ∃p)
Any-++-r : ∀ l₁ l₂ → Any l₂ → Any (l₁ ++ l₂)
Any-++-r nil _ ∃p = ∃p
Any-++-r (a :: l) _ ∃p = there (Any-++-r l _ ∃p)
Any-++ : ∀ l₁ l₂ → Any (l₁ ++ l₂) → Any l₁ ⊔ Any l₂
Any-++ nil l₂ ∃p = inr ∃p
Any-++ (a :: l₁) l₂ (here p) = inl (here p)
Any-++ (a :: l₁) l₂ (there ∃p) with Any-++ l₁ l₂ ∃p
... | inl ∃p₁ = inl (there ∃p₁)
... | inr ∃p₂ = inr ∃p₂
infix 80 _∈_
_∈_ : A → List A → Type i
a ∈ l = Any (_== a) l
∈-dec : has-dec-eq A → ∀ a l → Dec (a ∈ l)
∈-dec dec a l = Any-dec (_== a) (λ a' → dec a' a) l
∈-++-l : ∀ a l₁ l₂ → a ∈ l₁ → a ∈ (l₁ ++ l₂)
∈-++-l a = Any-++-l (_== a)
∈-++-r : ∀ a l₁ l₂ → a ∈ l₂ → a ∈ (l₁ ++ l₂)
∈-++-r a = Any-++-r (_== a)
∈-++ : ∀ a l₁ l₂ → a ∈ (l₁ ++ l₂) → (a ∈ l₁) ⊔ (a ∈ l₂)
∈-++ a = Any-++ (_== a)
-- [foldr] in Haskell
foldr : ∀ {j} {B : Type j} → (A → B → B) → B → List A → B
foldr f b nil = b
foldr f b (a :: l) = f a (foldr f b l)
-- [length] in Haskell
length : List A → ℕ
length = foldr (λ _ n → S n) 0
-- [filter] in Haskell
-- Note that [Bool] is currently defined as a coproduct.
filter : ∀ {j k} {Keep : A → Type j} {Drop : A → Type k}
→ ((a : A) → Keep a ⊔ Drop a) → List A → List A
filter p nil = nil
filter p (a :: l) with p a
... | inl _ = a :: filter p l
... | inr _ = filter p l
-- [reverse] in Haskell
reverse : List A → List A
reverse nil = nil
reverse (x :: l) = snoc (reverse l) x
reverse-snoc : ∀ a l → reverse (snoc l a) == a :: reverse l
reverse-snoc a nil = idp
reverse-snoc a (b :: l) = ap (λ l → snoc l b) (reverse-snoc a l)
reverse-reverse : ∀ l → reverse (reverse l) == l
reverse-reverse nil = idp
reverse-reverse (a :: l) = reverse-snoc a (reverse l) ∙ ap (a ::_) (reverse-reverse l)
-- Reasoning about identifications
List= : ∀ (l₁ l₂ : List A) → Type i
List= nil nil = Lift ⊤
List= nil (y :: l₂) = Lift ⊥
List= (x :: l₁) nil = Lift ⊥
List= (x :: l₁) (y :: l₂) = (x == y) × (l₁ == l₂)
List=-in : ∀ {l₁ l₂ : List A} → l₁ == l₂ → List= l₁ l₂
List=-in {l₁ = nil} idp = lift unit
List=-in {l₁ = x :: l} idp = idp , idp
List=-out : ∀ {l₁ l₂ : List A} → List= l₁ l₂ → l₁ == l₂
List=-out {l₁ = nil} {l₂ = nil} _ = idp
List=-out {l₁ = nil} {l₂ = y :: l₂} (lift ())
List=-out {l₁ = x :: l₁} {l₂ = nil} (lift ())
List=-out {l₁ = x :: l₁} {l₂ = y :: l₂} (x=y , l₁=l₂) = ap2 _::_ x=y l₁=l₂
module _ {i j} {A : Type i} {B : Type j} (f : A → B) where
-- [map] in Haskell
map : List A → List B
map nil = nil
map (a :: l) = f a :: map l
map-++ : ∀ l₁ l₂ → map (l₁ ++ l₂) == map l₁ ++ map l₂
map-++ nil l₂ = idp
map-++ (x :: l₁) l₂ = ap (f x ::_) (map-++ l₁ l₂)
{-
reverse-map : ∀ l → reverse (map l) == map (reverse l)
reverse-map nil = idp
reverse-map (x :: l) = {! ! (map-++ (reverse l) (x :: nil)) !}
-}
-- These functions use different [A], [B] or [f].
module _ {i} {A : Type i} where
-- [concat] in Haskell
concat : List (List A) → List A
concat l = foldr _++_ nil l
|
{
"alphanum_fraction": 0.4710689046,
"avg_line_length": 30.1866666667,
"ext": "agda",
"hexsha": "073ff81fc654dc42e92daaa8b68852d6c045f8f6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/List.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1977,
"size": 4528
}
|
-- Andreas, 2016-01-18, Issue1778, reported by mechvel
-- record pattern elimination must preserve hiding information
-- {-# OPTIONS --show-implicit #-}
open import Common.Prelude using (⊤)
open import Common.Equality
open import Common.Product
-- assuming _×_ is a record type (not data type)
module _ (A : Set) (let T = ⊤ → {p : A × A} → A) (f : T) where
swap : T → T
swap f _ {x , y} = f _ {y , x}
-- becomes by record pattern elimination
-- WAS: swap f _ xy = f _ {proj₂ xy , proj₁ xy}
-- NOW: swap f _ {xy} = f _ {proj₂ xy , proj₁ xy}
test : f ≡ swap (swap f)
test with Set -- trigers internal checking of type
test | _ = refl
-- WAS:
-- Expected a hidden argument, but found a visible argument
-- when checking that the type
-- (w : Set₁) → f ≡ (λ _ xy → f (record {}))
-- of the generated with function is well-formed
-- NOW:
-- should succeed
|
{
"alphanum_fraction": 0.6511627907,
"avg_line_length": 27.7419354839,
"ext": "agda",
"hexsha": "c3e5beed387a45bf46b36f497c38f72693ef1001",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/Issue1778.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/Issue1778.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/Issue1778.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 262,
"size": 860
}
|
{-# OPTIONS --without-K --safe #-}
-- Given a predicate on the objects of a Category C, build another category
-- with just those that satisfy a pr
module Categories.Category.Construction.ObjectRestriction where
open import Level
open import Data.Product using (Σ; proj₁)
open import Relation.Unary using (Pred)
open import Function using (_on_) renaming (id to id→)
open import Categories.Category.Core
private
variable
o ℓ e ℓ′ : Level
ObjectRestriction : (C : Category o ℓ e) → Pred (Category.Obj C) ℓ′ → Category (o ⊔ ℓ′) ℓ e
ObjectRestriction C R = record
{ Obj = Σ Obj R
; _⇒_ = _⇒_ on proj₁
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = equiv
; ∘-resp-≈ = ∘-resp-≈
}
where open Category C
|
{
"alphanum_fraction": 0.6725768322,
"avg_line_length": 24.1714285714,
"ext": "agda",
"hexsha": "607556fd7a030f53147f8c6e636f47a84bd3c84c",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/ObjectRestriction.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/ObjectRestriction.agda",
"max_line_length": 91,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/ObjectRestriction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 279,
"size": 846
}
|
module Cats.Category.Setoids.Facts.Terminal where
open import Data.Unit using (⊤)
open import Level
open import Cats.Category
open import Cats.Category.Setoids using (Setoids)
module Build {l} {l≈} where
open Category (Setoids l l≈)
One : Obj
One = record
{ Carrier = Lift l ⊤
; _≈_ = λ _ _ → Lift l≈ ⊤
}
isTerminal : IsTerminal One
isTerminal X = ∃!-intro _ _ _
open Build
instance
hasTerminal : ∀ l l≈ → HasTerminal (Setoids l l≈)
hasTerminal l l≈ = record
{ One = One
; isTerminal = isTerminal
}
|
{
"alphanum_fraction": 0.6352313167,
"avg_line_length": 16.0571428571,
"ext": "agda",
"hexsha": "a586cdc46896716cd602e17b8c0d93d5b681afbf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Setoids/Facts/Terminal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Setoids/Facts/Terminal.agda",
"max_line_length": 51,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Setoids/Facts/Terminal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 176,
"size": 562
}
|
module BTA6 where
----------------------------------------------
-- Preliminaries: Imports and List-utilities
----------------------------------------------
open import Data.Nat hiding (_<_)
open import Data.Bool
open import Function using (_∘_)
open import Data.List
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Category.Functor
-- Pointer into a list. It is similar to list membership as defined in
-- Data.List.AnyMembership, rather than going through propositional
-- equality, it asserts the existence of the referenced element
-- directly.
module ListReference where
infix 4 _∈_
data _∈_ {A : Set} : A → List A → Set where
hd : ∀ {x xs} → x ∈ (x ∷ xs)
tl : ∀ {x y xs} → x ∈ xs → x ∈ (y ∷ xs)
open ListReference
mapIdx : {A B : Set} → (f : A → B) →
{x : A} {xs : List A} → x ∈ xs → f x ∈ map f xs
mapIdx f hd = hd
mapIdx f (tl x₁) = tl (mapIdx f x₁)
-- Extension of lists at the front and, as a generalization, extension
-- of lists somewhere in the middle.
module ListExtension where
open import Relation.Binary.PropositionalEquality
-- Extension of a list by consing elements at the front.
data _↝_ {A : Set} : List A → List A → Set where
↝-refl : ∀ {Γ} → Γ ↝ Γ
↝-extend : ∀ {Γ Γ' τ} → Γ ↝ Γ' → Γ ↝ (τ ∷ Γ')
-- Combining two transitive extensions.
↝-trans : ∀ {A : Set}{Γ Γ' Γ'' : List A} → Γ ↝ Γ' → Γ' ↝ Γ'' → Γ ↝ Γ''
↝-trans Γ↝Γ' ↝-refl = Γ↝Γ'
↝-trans Γ↝Γ' (↝-extend Γ'↝Γ'') = ↝-extend (↝-trans Γ↝Γ' Γ'↝Γ'')
-- Of course, ↝-refl is the identity for combining two extensions.
lem-↝-refl-id : ∀ {A : Set} {Γ Γ' : List A} →
(Γ↝Γ' : Γ ↝ Γ') →
Γ↝Γ' ≡ (↝-trans ↝-refl Γ↝Γ')
lem-↝-refl-id ↝-refl = refl
lem-↝-refl-id (↝-extend Γ↝Γ') =
cong ↝-extend (lem-↝-refl-id Γ↝Γ')
-- TODO: why does this work?
-- lem-↝-refl-id (↝-extend Γ↝Γ') = lem-↝-refl-id (↝-extend Γ↝Γ')
-- Extending a list in the middle:
data _↝_↝_ {A : Set} : List A → List A → List A → Set where
-- First prepend the extension list to the common suffix
↝↝-base : ∀ {Γ Γ''} → Γ ↝ Γ'' → Γ ↝ [] ↝ Γ''
-- ... and then add the common prefix
↝↝-extend : ∀ {Γ Γ' Γ'' τ} →
Γ ↝ Γ' ↝ Γ'' → (τ ∷ Γ) ↝ (τ ∷ Γ') ↝ (τ ∷ Γ'')
open ListExtension
---------------------------------------
-- Start of the development:
---------------------------------------
-- Intro/Objective:
-------------------
-- The following development defines a (verified) specializer/partial
-- evaluator for a simply typed lambda calculus embedded in Agda using
-- deBruijn indices.
-- The residual language.
-------------------------
-- The residual language is a standard simply typed λ-calculus. The
-- types are integers and functions.
data Type : Set where
Int : Type
Fun : Type → Type → Type
Ctx = List Type
-- The type Exp describes the typed residual expressions. Variables
-- are represented by deBruijn indices that form references into the
-- typing context. The constructors and typing constraints are
-- standard.
-- TODO: citations for ``as usual'' and ``standard''
data Exp (Γ : Ctx) : Type → Set where
EVar : ∀ {τ} → τ ∈ Γ → Exp Γ τ
EInt : ℕ → Exp Γ Int
EAdd : Exp Γ Int → Exp Γ Int -> Exp Γ Int
ELam : ∀ {τ τ'} → Exp (τ ∷ Γ) τ' → Exp Γ (Fun τ τ')
EApp : ∀ {τ τ'} → Exp Γ (Fun τ τ') → Exp Γ τ → Exp Γ τ'
-- The standard functional semantics of the residual expressions.
-- TODO: citations for ``as usual'' and ``standard''
module Exp-Eval where
-- interpretation of Exp types
EImp : Type → Set
EImp Int = ℕ
EImp (Fun τ₁ τ₂) = EImp τ₁ → EImp τ₂
-- Environments containing values for free variables. An environment
-- is indexed by a typing context that provides the types for the
-- contained values.
data Env : Ctx → Set where
[] : Env []
_∷_ : ∀ {τ Γ} → EImp τ → Env Γ → Env (τ ∷ Γ)
-- Lookup a value in the environment, given a reference into the
-- associated typing context.
lookupE : ∀ { τ Γ } → τ ∈ Γ → Env Γ → EImp τ
lookupE hd (x ∷ env) = x
lookupE (tl v) (x ∷ env) = lookupE v env
-- Evaluation of residual terms, given a suitably typed environment.
ev : ∀ {τ Γ} → Exp Γ τ → Env Γ → EImp τ
ev (EVar x) env = lookupE x env
ev (EInt x) env = x
ev (EAdd e f) env = ev e env + ev f env
ev (ELam e) env = λ x → ev e (x ∷ env)
ev (EApp e f) env = ev e env (ev f env)
-- The binding-time-annotated language.
---------------------------------------
-- The type of a term determines the term's binding time. The type
-- constructors with an A-prefix denote statically bound integers and
-- functions. Terms with dynamic binding time have a `D' type. The `D'
-- type constructor simply wraps up a residual type.
data AType : Set where
AInt : AType
AFun : AType → AType → AType
D : Type → AType
ACtx = List AType
-- The mapping from annotated types to residual types is straightforward.
typeof : AType → Type
typeof AInt = Int
typeof (AFun α₁ α₂) = Fun (typeof α₁) (typeof α₂)
typeof (D x) = x
-- ATypes are stratified such that that dynamically bound
-- functions can only have dynamically bound parameters.
-- TODO: why exactly is that necessary?
-- The following well-formedness relation as an alternative representation
-- for this constraint:
module AType-WF where
open import Relation.Binary.PropositionalEquality
-- Static and dynamic binding times
data BT : Set where
stat : BT
dyn : BT
-- Ordering on binding times: dynamic binding time subsumes static
-- binding time.
data _≤-bt_ : BT → BT → Set where
bt≤bt : ∀ bt → bt ≤-bt bt
stat≤bt : ∀ bt → stat ≤-bt bt
module WF (ATy : Set) (typeof : ATy → Type) (btof : ATy → BT) where
data wf : ATy → Set where
wf-int : ∀ α → typeof α ≡ Int → wf α
wf-fun : ∀ α α₁ α₂ →
typeof α ≡ Fun (typeof α₁) (typeof α₂) →
btof α ≤-bt btof α₁ →
btof α ≤-bt btof α₂ →
wf α₁ → wf α₂ →
wf α
-- It is easy to check that the stratification respects the
-- well-formedness, given the intended mapping from ATypes to
-- binding times expained above:
btof : AType → BT
btof AInt = stat
btof (AFun _ _) = stat
btof (D x) = dyn
open WF AType typeof btof using (wf-fun; wf-int) renaming (wf to wf-AType)
lem-wf-AType : ∀ α → wf-AType α
lem-wf-AType AInt = WF.wf-int AInt refl
lem-wf-AType (AFun α α₁) = WF.wf-fun (AFun α α₁) α α₁ refl (stat≤bt (btof α))
(stat≤bt (btof α₁))
(lem-wf-AType α)
(lem-wf-AType α₁)
lem-wf-AType (D Int) = WF.wf-int (D Int) refl
lem-wf-AType (D (Fun x x₁)) = WF.wf-fun (D (Fun x x₁))
(D x) (D x₁)
refl (bt≤bt dyn) (bt≤bt dyn)
(lem-wf-AType (D x))
(lem-wf-AType (D x₁))
-- The typed annotated terms: The binding times of variables is
-- determined by the corresponding type-binding in the context. In the
-- other cases, the A- and D-prefixes on term constructors inidicate
-- the corresponding binding times for the resulting terms.
data AExp (Δ : ACtx) : AType → Set where
Var : ∀ {α} → α ∈ Δ → AExp Δ α
AInt : ℕ → AExp Δ AInt
AAdd : AExp Δ AInt → AExp Δ AInt → AExp Δ AInt
ALam : ∀ {α₁ α₂} → AExp (α₁ ∷ Δ) α₂ → AExp Δ (AFun α₁ α₂)
AApp : ∀ {α₁ α₂} → AExp Δ (AFun α₂ α₁) → AExp Δ α₂ → AExp Δ α₁
DInt : ℕ → AExp Δ (D Int)
DAdd : AExp Δ (D Int) → AExp Δ (D Int) → AExp Δ (D Int)
DLam : ∀ {σ₁ σ₂} → AExp ((D σ₁) ∷ Δ) (D σ₂) → AExp Δ (D (Fun σ₁ σ₂))
DApp : ∀ {α₁ α₂} → AExp Δ (D (Fun α₂ α₁)) → AExp Δ (D α₂) → AExp Δ (D α₁)
Lift : AExp Δ AInt → AExp Δ (D Int)
-- The terms of AExp assign a binding time to each subterm. For
-- program specialization, we interpret terms with dynamic binding
-- time as the programs subject to specialization, and their subterms
-- with static binding time as statically known inputs. A partial
-- evaluation function (or specializer) then compiles the program into
-- a residual term for that is specialized for the static inputs. The
-- main complication when defining partial evaluation as a total,
-- primitively recursive function will be the treatment of the De
-- Bruijn variables of non-closed residual expressions.
-- Before diving into the precise definition, it is instructive to
-- investigate the expected result of partial evaluation on some
-- examples.
module ApplicativeMaybe where
open import Data.Maybe public
open import Category.Functor public
import Level
open RawFunctor {Level.zero} functor public
infixl 4 _⊛_
_⊛_ : {A B : Set} → Maybe (A → B) → Maybe A → Maybe B
just f ⊛ just x = just (f x)
_ ⊛ _ = nothing
liftA2 : {A B C : Set} → (A → B → C) → Maybe A → Maybe B → Maybe C
liftA2 f mx my = just f ⊛ mx ⊛ my
module AExp-Examples where
open import Data.Product hiding (map)
open ApplicativeMaybe
open import Data.Empty
open Relation.Binary.PropositionalEquality
-- (We pre-define some De Bruijn indices to improve
-- readability of the examples:)
x : ∀ {α Δ} → AExp (α ∷ Δ) α
x = Var hd
x' : ∀ {α Δ} → Exp (α ∷ Δ) α
x' = EVar hd
y : ∀ {α₁ α Δ} → AExp (α₁ ∷ α ∷ Δ) α
y = Var (tl hd)
z : ∀ {α₁ α₂ α Δ} → AExp (α₁ ∷ α₂ ∷ α ∷ Δ) α
z = Var (tl (tl hd))
-- A rather trivial case is the specialization of base-type
-- calulations. Here, we simply want to emit the result of a static
-- addition as a constant:
-- Lift (5S +S 5S) --specializes to --> 5E
ex0 : AExp [] (D Int)
ex0 = (Lift (AAdd (AInt 5) (AInt 5)))
ex0' : AExp [] (D Int)
ex0' = DAdd (DInt 6) (Lift (AAdd (AInt 5) (AInt 5)))
ex0-spec : Exp [] Int
ex0-spec = (EInt 10)
ex0'-spec : Exp [] Int
ex0'-spec = (EAdd (EInt 6) (EInt 10))
-- The partial evaluation for this case is of course
-- straightforward. We use Agda's ℕ as an implementation type for
-- static integers and residual expressions Exp for dynamic ones.
Imp0 : AType → Set
Imp0 AInt = ℕ
Imp0 (D σ) = Exp [] σ
Imp0 _ = ⊥
pe-ex0 : ∀ { α } → AExp [] α → Maybe (Imp0 α)
pe-ex0 (AInt x) = just (x)
pe-ex0 (DInt x) = just (EInt x)
pe-ex0 (AAdd e f) = liftA2 _+_ (pe-ex0 e) (pe-ex0 f)
pe-ex0 (DAdd e f) = liftA2 EAdd (pe-ex0 e) (pe-ex0 f)
pe-ex0 (Lift e) = EInt <$> (pe-ex0 e)
pe-ex0 _ = nothing
ex0-test : pe-ex0 ex0 ≡ just ex0-spec
ex0-test = refl
ex0'-test : pe-ex0 ex0' ≡ just ex0'-spec
ex0'-test = refl
-- Specializing open terms is also straightforward. This situation
-- typically arises when specializing the body of a lambda
-- abstraction.
-- (Dλ x → x +D Lift (5S + 5S)) ---specializes to--> Eλ x → EInt 10
ex1 : AExp [] (D (Fun Int Int))
ex1 = (DLam (DAdd x (Lift (AAdd (AInt 5) (AInt 5)))))
ex1-spec : Exp [] (Fun Int Int)
ex1-spec = ELam (EAdd x' (EInt 10))
ex1' : AExp (D Int ∷ []) (D Int)
ex1' = (Lift (AAdd (AInt 5) (AInt 5)))
ex1'-spec : Exp (Int ∷ []) Int
ex1'-spec = (EAdd x' (EInt 10))
-- The implementation type now also has to hold open residual terms,
-- which arise as the result of partially evaluating an open term
-- with with dynamic binding time. The calculation of the
-- implementation type thus requires a typing context as a
-- parameter.
Imp1 : Ctx → AType → Set
Imp1 _ AInt = ℕ
Imp1 Γ (D τ) = Exp Γ τ
Imp1 _ _ = ⊥
erase = typeof
-- Unsurprisingly, Partial evaluation of open terms emits
-- implementations that are typed under the erased context.
pe-ex1 : ∀ {α Δ} → AExp Δ α → Maybe (Imp1 (map erase Δ) α)
pe-ex1 (AInt x) = just (x)
pe-ex1 (DInt x) = just (EInt x)
pe-ex1 (AAdd e f) = liftA2 _+_ (pe-ex1 e) (pe-ex1 f)
pe-ex1 (DAdd e f) = liftA2 EAdd (pe-ex1 e) (pe-ex1 f)
pe-ex1 (Lift e) = EInt <$> (pe-ex1 e)
pe-ex1 (DLam {τ} e) = ELam <$> pe-ex1 e
-- Technical note: In the case for variables we can simply exploit
-- the fact that variables are functorial in the actual type of
-- their contexts' elements
pe-ex1 (Var {D _} x) = just (EVar (mapIdx typeof x))
pe-ex1 _ = nothing
ex1-test : pe-ex1 ex1 ≡ just ex1-spec
ex1-test = refl
data Static : AType → Set where
SInt : Static AInt
SFun : ∀ { α₁ α₂ } → Static α₂ → Static (AFun α₁ α₂)
is-static : (α : AType) → Dec (Static α)
is-static α = {!!}
Imp2 : Ctx → AType → Set
Imp2 _ AInt = ℕ
Imp2 Γ (D τ) = Exp Γ τ
Imp2 Γ (AFun α₁ α₂) = Imp2 Γ α₁ → Imp2 Γ α₂
-- The interpretation of annotated types.
Imp : Ctx → AType → Set
Imp Γ (AInt) = ℕ
Imp Γ (AFun α₁ α₂) = ∀ {Γ'} → Γ ↝ Γ' → (Imp Γ' α₁ → Imp Γ' α₂)
Imp Γ (D σ) = Exp Γ σ
elevate-var : ∀ {Γ Γ'} {τ : Type} → Γ ↝ Γ' → τ ∈ Γ → τ ∈ Γ'
elevate-var ↝-refl x = x
elevate-var (↝-extend Γ↝Γ') x = tl (elevate-var Γ↝Γ' x)
elevate-var2 : ∀ {Γ Γ' Γ'' τ} → Γ ↝ Γ' ↝ Γ'' → τ ∈ Γ → τ ∈ Γ''
elevate-var2 (↝↝-base x) x₁ = elevate-var x x₁
elevate-var2 (↝↝-extend Γ↝Γ'↝Γ'') hd = hd
elevate-var2 (↝↝-extend Γ↝Γ'↝Γ'') (tl x) = tl (elevate-var2 Γ↝Γ'↝Γ'' x)
elevate : ∀ {Γ Γ' Γ'' τ} → Γ ↝ Γ' ↝ Γ'' → Exp Γ τ → Exp Γ'' τ
elevate Γ↝Γ'↝Γ'' (EVar x) = EVar (elevate-var2 Γ↝Γ'↝Γ'' x)
elevate Γ↝Γ'↝Γ'' (EInt x) = EInt x
elevate Γ↝Γ'↝Γ'' (EAdd e e₁) = EAdd (elevate Γ↝Γ'↝Γ'' e) (elevate Γ↝Γ'↝Γ'' e₁)
elevate Γ↝Γ'↝Γ'' (ELam e) = ELam (elevate (↝↝-extend Γ↝Γ'↝Γ'') e)
elevate Γ↝Γ'↝Γ'' (EApp e e₁) = EApp (elevate Γ↝Γ'↝Γ'' e) (elevate Γ↝Γ'↝Γ'' e₁)
lift : ∀ {Γ Γ'} α → Γ ↝ Γ' → Imp Γ α → Imp Γ' α
lift AInt p v = v
lift (AFun x x₁) Γ↝Γ' v = λ Γ'↝Γ'' → v (↝-trans Γ↝Γ' Γ'↝Γ'')
lift (D x₁) Γ↝Γ' v = elevate (↝↝-base Γ↝Γ') v
module SimpleAEnv where
-- A little weaker, but much simpler
data AEnv (Γ : Ctx) : ACtx → Set where
[] : AEnv Γ []
cons : ∀ {Δ} (α : AType) → Imp Γ α → AEnv Γ Δ → AEnv Γ (α ∷ Δ)
lookup : ∀ {α Δ Γ} → AEnv Γ Δ → α ∈ Δ → Imp Γ α
lookup (cons α v env) hd = v
lookup (cons α₁ v env) (tl x) = lookup env x
liftEnv : ∀ {Γ Γ' Δ} → Γ ↝ Γ' → AEnv Γ Δ → AEnv Γ' Δ
liftEnv Γ↝Γ' [] = []
liftEnv Γ↝Γ' (cons α x env) = cons α (lift α Γ↝Γ' x) (liftEnv Γ↝Γ' env)
consD : ∀ {Γ Δ} σ → AEnv Γ Δ → AEnv (σ ∷ Γ) (D σ ∷ Δ)
consD σ env = (cons (D σ) (EVar hd) (liftEnv (↝-extend {τ = σ} ↝-refl) env))
pe : ∀ {α Δ Γ} → AExp Δ α → AEnv Γ Δ → Imp Γ α
pe (Var x) env = lookup env x
pe (AInt x) env = x
pe (AAdd e₁ e₂) env = pe e₁ env + pe e₂ env
pe (ALam {α} e) env = λ Γ↝Γ' → λ y → pe e (cons α y (liftEnv Γ↝Γ' env))
pe (AApp e₁ e₂) env = ((pe e₁ env) ↝-refl) (pe e₂ env)
pe (DInt x) env = EInt x
pe (DAdd e e₁) env = EAdd (pe e env) (pe e₁ env)
pe (DLam {σ} e) env = ELam (pe e (consD σ env))
pe (DApp e e₁) env = EApp (pe e env) (pe e₁ env)
pe (Lift e) env = EInt (pe e env)
module CheckExamples where
open import Relation.Binary.PropositionalEquality hiding ([_])
open SimpleAEnv
open AExp-Examples
check-ex1 : pe ex1 [] ≡ ex1-spec
check-ex1 = refl
check-ex0 : pe ex0 [] ≡ ex0-spec
check-ex0 = refl
check-ex0' : pe ex0' [] ≡ ex0'-spec
check-ex0' = refl
module Examples where
open SimpleAEnv
open import Relation.Binary.PropositionalEquality
x : ∀ {α Δ} → AExp (α ∷ Δ) α
x = Var hd
y : ∀ {α₁ α Δ} → AExp (α₁ ∷ α ∷ Δ) α
y = Var (tl hd)
z : ∀ {α₁ α₂ α Δ} → AExp (α₁ ∷ α₂ ∷ α ∷ Δ) α
z = Var (tl (tl hd))
-- Dλ y → let f = λ x → x D+ y in Dλ z → f z
term1 : AExp [] (D (Fun Int (Fun Int Int)))
term1 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DAdd x y))))
-- Dλ y → let f = λ x → (Dλ w → x D+ y) in Dλ z → f z
-- Dλ y → (λ f → Dλ z → f z) (λ x → (Dλ w → x D+ y))
term2 : AExp [] (D (Fun Int (Fun Int Int)))
term2 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DLam {σ₁ = Int} (DAdd y z)))))
-- closed pe. In contrast to BTA5, it is now not clear what Γ is
-- given an expression. So perhaps AEnv has it's merrits after all?
pe[] : ∀ {α} → AExp [] α → Imp [] α
pe[] e = pe e []
ex-pe-term1 : pe[] term1 ≡ ELam (ELam (EVar hd))
ex-pe-term1 = refl
ex-pe-term2 : pe[] term2 ≡ ELam (ELam (EVar hd))
ex-pe-term2 = refl
module Correctness where
open SimpleAEnv
open Exp-Eval
-- TODO: rename occurences of stripα to typeof
stripα = typeof
stripΔ : ACtx → Ctx
stripΔ = map stripα
strip-lookup : ∀ { α Δ} → α ∈ Δ → stripα α ∈ stripΔ Δ
strip-lookup hd = hd
strip-lookup (tl x) = tl (strip-lookup x)
strip : ∀ {α Δ} → AExp Δ α → Exp (stripΔ Δ) (stripα α)
strip (Var x) = EVar (strip-lookup x)
strip (AInt x) = EInt x
strip (AAdd e f) = EAdd (strip e) (strip f)
strip (ALam e) = ELam (strip e)
strip (AApp e f) = EApp (strip e) (strip f)
strip (DInt x) = EInt x
strip (DAdd e f) = EAdd (strip e) (strip f)
strip (DLam e) = ELam (strip e)
strip (DApp e f) = EApp (strip e) (strip f)
strip (Lift e) = strip e
liftE : ∀ {τ Γ Γ'} → Γ ↝ Γ' → Exp Γ τ → Exp Γ' τ
liftE Γ↝Γ' e = elevate (↝↝-base Γ↝Γ') e
stripLift : ∀ {α Δ Γ} → stripΔ Δ ↝ Γ → AExp Δ α → Exp Γ (stripα α)
stripLift Δ↝Γ = liftE Δ↝Γ ∘ strip
-- We want to show that pe preserves the semantics of the
-- program. Roughly, Exp-Eval.ev-ing a stripped program is
-- equivalent to first pe-ing a program and then Exp-Eval.ev-ing the
-- result. But as the pe-result of a static function ``can do more''
-- than the (ev ∘ strip)ped function we need somthing more refined.
module Equiv where
open import Relation.Binary.PropositionalEquality
-- Extending a value environment according to an extension of a
-- type environment
data _⊢_↝_ {Γ} : ∀ {Γ'} → Γ ↝ Γ' → Env Γ → Env Γ' → Set where
refl : ∀ env → ↝-refl ⊢ env ↝ env
extend : ∀ {τ Γ' env env'} → {Γ↝Γ' : Γ ↝ Γ'} →
(v : EImp τ) → (Γ↝Γ' ⊢ env ↝ env') →
↝-extend Γ↝Γ' ⊢ env ↝ (v ∷ env')
env↝trans : ∀ {Γ Γ' Γ''} {Γ↝Γ' : Γ ↝ Γ'} {Γ'↝Γ'' : Γ' ↝ Γ''}
{env env' env''} →
Γ↝Γ' ⊢ env ↝ env' →
Γ'↝Γ'' ⊢ env' ↝ env'' →
let Γ↝Γ'' = ↝-trans Γ↝Γ' Γ'↝Γ'' in
Γ↝Γ'' ⊢ env ↝ env''
-- env↝trans {Γ} {.Γ''} {Γ''} {Γ↝Γ'} {.↝-refl} {env} {.env''} {env''} env↝env' (refl .env'') = env↝env'
-- env↝trans env↝env' (extend v env'↝env'') = extend v (env↝trans env↝env' env'↝env'')
-- TODO: why does this work???
env↝trans {.Γ'} {Γ'} {Γ''} {.↝-refl} {Γ'↝Γ''} {.env'} {env'} (refl .env') env'↝env''
rewrite sym (lem-↝-refl-id Γ'↝Γ'') = env'↝env''
env↝trans (extend v env↝env') env'↝env'' = env↝trans (extend v env↝env') env'↝env''
-- Equivalent Imp Γ α and EImp τ values (where τ = stripα α). As
-- (v : Imp Γ α) is not necessarily closed, equivalence is defined for
-- the closure (Env Γ, ImpΓ α)
Equiv : ∀ {α Γ} → Env Γ → Imp Γ α → EImp (stripα α) → Set
Equiv {AInt} env av v = av ≡ v
Equiv {AFun α₁ α₂} {Γ} env af f = -- extensional equality, given -- an extended context
∀ {Γ' env' Γ↝Γ'} → (Γ↝Γ' ⊢ env ↝ env') →
{ax : Imp Γ' α₁} → {x : EImp (stripα α₁)} →
Equiv env' ax x → Equiv env' (af Γ↝Γ' ax) (f x)
Equiv {D x} {Γ} env av v = ev av env ≡ v -- actually we mean extensional equality
-- Equivalence of AEnv and Env environments. They need to provide
-- Equivalent bindings for a context Δ/stripΔ Δ. Again, the
-- equivalence is defined for a closure (Env Γ', AEnv Γ' Δ).
data Equiv-Env {Γ' : _} (env' : Env Γ') :
∀ {Δ} → let Γ = stripΔ Δ in
AEnv Γ' Δ → Env Γ → Set where
[] : Equiv-Env env' [] []
cons : ∀ {α Δ} → let τ = stripα α
Γ = stripΔ Δ in
{env : Env Γ} → {aenv : AEnv Γ' Δ} →
Equiv-Env env' aenv env →
(va : Imp (Γ') α) → (v : EImp τ) →
Equiv env' va v →
Equiv-Env env' (cons α va (aenv)) (v ∷ env)
-- Now for the proof...
module Proof where
open Equiv
open import Relation.Binary.PropositionalEquality
-- Extensional equality as an axiom to prove the Equivalence of
-- function values. We could (should?) define it locally for
-- Equiv.
postulate ext : ∀ {τ₁ τ₂} {f g : EImp τ₁ → EImp τ₂} →
(∀ x → f x ≡ g x) → f ≡ g
-- Ternary helper relation for environment extensions, analogous to _↝_↝_ for contexts
data _⊢_↝_↝_⊣ : ∀ { Γ Γ' Γ''} → Γ ↝ Γ' ↝ Γ'' → Env Γ → Env Γ' → Env Γ'' → Set where
refl : ∀ {Γ Γ''} {Γ↝Γ'' : Γ ↝ Γ''} { env env'' } →
Γ↝Γ'' ⊢ env ↝ env'' →
↝↝-base Γ↝Γ'' ⊢ env ↝ [] ↝ env'' ⊣
extend : ∀ {Γ Γ' Γ'' τ} {Γ↝Γ'↝Γ'' : Γ ↝ Γ' ↝ Γ''} { env env' env'' } →
Γ↝Γ'↝Γ'' ⊢ env ↝ env' ↝ env'' ⊣ →
(v : EImp τ) → ↝↝-extend Γ↝Γ'↝Γ'' ⊢ (v ∷ env) ↝ (v ∷ env') ↝ (v ∷ env'') ⊣
-- the following lemmas are strong versions of the shifting
-- functions, proving that consistent variable renaming preserves
-- equivalence (and not just typing).
lookup-elevate-≡ : ∀ {τ Γ Γ'} {Γ↝Γ' : Γ ↝ Γ'}
{env : Env Γ} {env' : Env Γ'} →
Γ↝Γ' ⊢ env ↝ env' →
(x : τ ∈ Γ) → lookupE x env ≡ lookupE (elevate-var Γ↝Γ' x) env'
lookup-elevate-≡ {τ} {.Γ'} {Γ'} {.↝-refl} {.env'} {env'} (refl .env') x = refl
lookup-elevate-≡ (extend v env↝env') x = lookup-elevate-≡ env↝env' x
lookup-elevate2-≡ : ∀ {τ Γ Γ' Γ''} {Γ↝Γ'↝Γ'' : Γ ↝ Γ' ↝ Γ''}
{env : Env Γ} {env' : Env Γ'} {env'' : Env Γ''} →
Γ↝Γ'↝Γ'' ⊢ env ↝ env' ↝ env'' ⊣ →
(x : τ ∈ Γ) → lookupE x env ≡ lookupE (elevate-var2 Γ↝Γ'↝Γ'' x) env''
lookup-elevate2-≡ (refl Γ↝Γ') x = lookup-elevate-≡ Γ↝Γ' x
lookup-elevate2-≡ (extend env↝env'↝env'' v) hd = refl
lookup-elevate2-≡ (extend env↝env'↝env'' _) (tl x)
rewrite lookup-elevate2-≡ env↝env'↝env'' x = refl
lem-elevate-≡ : ∀ {τ Γ Γ' Γ''}
{Γ↝Γ'↝Γ'' : Γ ↝ Γ' ↝ Γ''}
{env : Env Γ} {env' : Env Γ'} {env'' : Env Γ''} →
Γ↝Γ'↝Γ'' ⊢ env ↝ env' ↝ env'' ⊣ →
(e : Exp Γ τ) →
ev e env ≡ ev (elevate Γ↝Γ'↝Γ'' e) env''
lem-elevate-≡ env↝env' (EVar x) = lookup-elevate2-≡ env↝env' x
lem-elevate-≡ env↝env' (EInt x) = refl
lem-elevate-≡ env↝env' (EAdd e f) with lem-elevate-≡ env↝env' e | lem-elevate-≡ env↝env' f
... | IA1 | IA2 = cong₂ _+_ IA1 IA2
lem-elevate-≡ {Γ↝Γ'↝Γ'' = Γ↝Γ'↝Γ''}
{env = env}
{env'' = env''}
env↝env' (ELam e) = ext lem-elevate-≡-body
where lem-elevate-≡-body : ∀ x → ev e (x ∷ env) ≡ ev (elevate (↝↝-extend Γ↝Γ'↝Γ'') e) (x ∷ env'')
lem-elevate-≡-body x = lem-elevate-≡ (extend env↝env' x) e
lem-elevate-≡ env↝env' (EApp e f) with lem-elevate-≡ env↝env' e | lem-elevate-≡ env↝env' f
... | IA1 | IA2 = cong₂ (λ f₁ x → f₁ x) IA1 IA2
lem-lift-refl-id : ∀ {α Γ} → let τ = stripα α in
(env : Env Γ) →
(v : EImp τ) (va : Imp Γ α) →
Equiv env va v →
Equiv env (lift α ↝-refl va) v
lem-lift-refl-id {AInt} env v va eq = eq
lem-lift-refl-id {AFun α α₁} {Γ} env v va eq = body
where body : ∀ {Γ'} {env' : Env Γ'} {Γ↝Γ' : Γ ↝ Γ'} →
Γ↝Γ' ⊢ env ↝ env' →
{av' : Imp Γ' α} {v' : EImp (stripα α)} →
Equiv env' av' v' → Equiv env' (va (↝-trans ↝-refl Γ↝Γ') av') (v v')
body {Γ↝Γ' = Γ↝Γ'} env↝env' eq' rewrite sym (lem-↝-refl-id Γ↝Γ') = eq env↝env' eq'
lem-lift-refl-id {D x} env v e eq rewrite sym eq = sym (lem-elevate-≡ (refl (refl env)) e)
-- lifting an Imp does not affect equivalence
lem-lift-equiv : ∀ {α Γ Γ'} → let τ = stripα α in
{Γ↝Γ' : Γ ↝ Γ'} →
(va : Imp Γ α) (v : EImp τ) →
{env : Env Γ} {env' : Env Γ'} →
Γ↝Γ' ⊢ env ↝ env' →
Equiv env va v →
Equiv env' (lift α Γ↝Γ' va) v
lem-lift-equiv va v {.env'} {env'} (refl .env') eq = lem-lift-refl-id env' v va eq
lem-lift-equiv {AInt} va v (extend v₁ env↝env') eq = eq
lem-lift-equiv {AFun α α₁} va v (extend v₁ env↝env') eq =
λ v₁env₁↝env' eq₁ → eq (env↝trans (extend v₁ env↝env') v₁env₁↝env') eq₁
lem-lift-equiv {D x} va v (extend v₁ env↝env') eq
rewrite sym eq = sym (lem-elevate-≡ (refl (extend v₁ env↝env')) va)
lem-equiv-lookup : ∀ {α Δ Γ'} → let Γ = stripΔ Δ in
{ aenv : AEnv Γ' Δ } {env : Env Γ} →
(env' : Env Γ') →
Equiv-Env env' aenv env →
∀ x → Equiv {α} env' (lookup aenv x) (lookupE (strip-lookup x) env)
lem-equiv-lookup env' [] ()
lem-equiv-lookup env' (cons enveq va v eq) hd = eq
lem-equiv-lookup env' (cons enveq va v eq) (tl x) = lem-equiv-lookup env' enveq x
lem-equiv-env-lift-extend :
∀ {σ Γ' Δ} (env' : Env Γ') → let Γ = stripΔ Δ in
{env : Env Γ} {aenv : AEnv Γ' Δ} →
Equiv-Env env' aenv env → (x : EImp σ) →
Equiv-Env (x ∷ env') (liftEnv (↝-extend ↝-refl) aenv) env
lem-equiv-env-lift-extend _ [] x = []
lem-equiv-env-lift-extend env' (cons {α} eqenv va v x) x₁ =
cons (lem-equiv-env-lift-extend env' eqenv x₁)
(lift α (↝-extend ↝-refl) va) v (lem-lift-equiv va v (extend x₁ (refl env')) x)
lem-equiv-env-lift-lift :
∀ {Γ' Γ'' Δ} → let Γ = stripΔ Δ in
{Γ↝Γ' : Γ' ↝ Γ''}
{env' : Env Γ'} {env'' : Env Γ''}
(env'↝env'' : Γ↝Γ' ⊢ env' ↝ env'') →
{env : Env Γ} {aenv : AEnv Γ' Δ} →
Equiv-Env env' aenv env →
Equiv-Env env'' (liftEnv Γ↝Γ' aenv) env
lem-equiv-env-lift-lift env'↝env'' [] = []
lem-equiv-env-lift-lift {Γ↝Γ' = Γ↝Γ'} env'↝env'' (cons {α} eqenv va v x)
with lem-equiv-env-lift-lift env'↝env'' eqenv
... | IA = cons IA (lift α Γ↝Γ' va) v (lem-lift-equiv va v env'↝env'' x)
-- When we partially evaluate somthing under an environment , it
-- will give equivalent results to a ``complete'' evaluation under
-- an equivalent environment
pe-correct : ∀ { α Δ Γ' } → (e : AExp Δ α) →
let Γ = stripΔ Δ in
{aenv : AEnv Γ' Δ} → {env : Env Γ} →
(env' : Env Γ') →
Equiv-Env env' aenv env →
Equiv env' (pe e aenv) (ev (strip e) env)
pe-correct (Var x) env' eqenv = lem-equiv-lookup env' eqenv x
pe-correct (AInt x) env' eqenv = refl
pe-correct (AAdd e f) env' eqenv
rewrite pe-correct e env' eqenv | pe-correct f env' eqenv = refl
pe-correct (ALam e) env' eqenv =
λ {_} {env''} env'↝env'' {av'} {v'} eq →
let eqenv' = (lem-equiv-env-lift-lift env'↝env'' eqenv)
eqenv'' = (cons eqenv' av' v' eq)
in pe-correct e env'' eqenv''
pe-correct (AApp e f) env' eqenv
with pe-correct e env' eqenv | pe-correct f env' eqenv
... | IAe | IAf = IAe (refl env') IAf
pe-correct (DInt x) env' eqenv = refl
pe-correct (DAdd e f) env' eqenv
rewrite pe-correct e env' eqenv | pe-correct f env' eqenv = refl
pe-correct (DLam e) env' eqenv =
ext (λ x → let eqenv' = (lem-equiv-env-lift-extend env' eqenv x)
eqenv'' = (cons eqenv' (EVar hd) x refl)
in pe-correct e (x ∷ env') eqenv'')
pe-correct (DApp e f) {env = env} env' eqenv
with pe-correct f env' eqenv | pe-correct e env' eqenv
... | IA' | IA = cong₂ (λ f x → f x) IA IA'
pe-correct (Lift e) env' eqenv
with pe-correct e env' eqenv
... | IA = IA
-- module PreciseAEnv where
-- open Exp-Eval
-- open import Relation.Binary.PropositionalEquality
-- data AEnv : Ctx → ACtx → Set where
-- [] : AEnv [] []
-- cons : ∀ { Γ Γ' Δ } (α : AType) → Γ ↝ Γ' → Imp Γ' α → AEnv Γ Δ → AEnv Γ' (α ∷ Δ)
-- consD : ∀ {Γ Δ} σ → AEnv Γ Δ → AEnv (σ ∷ Γ) (D σ ∷ Δ)
-- consD σ env = (cons (D σ) (↝-extend {τ = σ} ↝-refl) (EVar hd) (env))
-- lookup : ∀ {α Δ Γ} → AEnv Γ Δ → α ∈ Δ → Imp Γ α
-- lookup (cons α _ v env) hd = v
-- lookup (cons α₁ Γ↝Γ' v env) (tl x) = lookup (cons α₁ Γ↝Γ' v env) (tl x)
-- pe : ∀ {α Δ Γ} → AExp Δ α → AEnv Γ Δ → Imp Γ α
-- pe (Var x) env = lookup env x
-- pe (AInt x) env = x
-- pe (AAdd e₁ e₂) env = pe e₁ env + pe e₂ env
-- pe (ALam {α} e) env = λ Γ↝Γ' → λ y → pe e (cons α Γ↝Γ' y env)
-- pe (AApp e₁ e₂) env = ((pe e₁ env) ↝-refl) (pe e₂ env)
-- pe (DInt x) env = EInt x
-- pe (DAdd e e₁) env = EAdd (pe e env) (pe e₁ env)
-- pe (DLam {σ} e) env = ELam (pe e (consD σ env))
-- pe (DApp e e₁) env = EApp (pe e env) (pe e₁ env)
-- -- What is a suitable environment to interpret an AExp without pe?
-- -- 1-1 mapping from AExp into Exp
-- stripα : AType → Type
-- stripα AInt = Int
-- stripα (AFun α₁ α₂) = Fun (stripα α₁) (stripα α₂)
-- stripα (D x) = x
-- stripΔ : ACtx → Ctx
-- stripΔ = map stripα
-- stripEnv : ∀ {Δ} →
-- let Γ = stripΔ Δ
-- in AEnv Γ Δ → Env Γ
-- stripEnv [] = []
-- stripEnv (cons AInt Γ↝Γ' v env) = v ∷ (stripEnv {!!})
-- stripEnv (cons (AFun α α₁) Γ↝Γ' v env) = {!!}
-- stripEnv (cons (D x) Γ↝Γ' v env) = {!!}
-- -- Extending a value environment according to an extension of a type environment
-- data _⊢_↝_ {Γ} : ∀ {Γ'} → Γ ↝ Γ' → Env Γ → Env Γ' → Set where
-- refl : ∀ env → ↝-refl ⊢ env ↝ env
-- extend : ∀ {τ Γ' env env'} → {Γ↝Γ' : Γ ↝ Γ'} →
-- (v : EImp τ) → (Γ↝Γ' ⊢ env ↝ env') →
-- ↝-extend Γ↝Γ' ⊢ env ↝ (v ∷ env')
-- -- It turns out that we have to shift Exp also
-- liftE : ∀ {τ Γ Γ'} → Γ ↝ Γ' → Exp Γ τ → Exp Γ' τ
-- liftE Γ↝Γ' e = elevate (↝↝-base Γ↝Γ') e
-- Equiv : ∀ {α Γ} → Env Γ → Imp Γ α → EImp (stripα α) → Set
-- Equiv {AInt} env av v = av ≡ v
-- Equiv {AFun α₁ α₂} {Γ} env av v = -- an pe-d static function is
-- -- equivalent to an EImp value
-- -- if given an suitably extended
-- -- environment, evaluating the
-- -- body yields something
-- -- equivalent to the EImp-value
-- ∀ {Γ' env' Γ↝Γ'} → (Γ↝Γ' ⊢ env ↝ env') →
-- {av' : Imp Γ' α₁} → {v' : EImp (stripα α₁)} →
-- Equiv env' av' v' → Equiv env' (av Γ↝Γ' av') (v v')
-- Equiv {D x} {Γ} env av v = ev av env ≡ v
-- data Equiv-Env : ∀ {Δ} → let Γ = stripΔ Δ in
-- AEnv Γ Δ → Env Γ → Set where
-- [] : Equiv-Env [] []
-- -- cons : ∀ {α Δ} → let Γ = stripΔ Δ in
-- -- (va : Imp Γ α) → (v : EImp (stripα α)) →
-- -- (env : Env Γ) → Equiv env v va →
-- -- (aenv : AEnv Γ Δ) →
-- -- Equiv-Env aenv env →
-- -- Equiv-Env {α ∷ Δ} (cons α (lift α (↝-extend ↝-refl) va)
-- -- (liftEnv (↝-extend ↝-refl) aenv))
-- -- (v ∷ env)
|
{
"alphanum_fraction": 0.5365696626,
"avg_line_length": 39.371356147,
"ext": "agda",
"hexsha": "12ec94499394b4a24e2b520bad5c3e2c0b00c284",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "luminousfennell/polybta",
"max_forks_repo_path": "BTA6.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "luminousfennell/polybta",
"max_issues_repo_path": "BTA6.agda",
"max_line_length": 107,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "luminousfennell/polybta",
"max_stars_repo_path": "BTA6.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-15T04:35:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-15T04:35:29.000Z",
"num_tokens": 11842,
"size": 31064
}
|
module Prelude where
id : {A : Set} -> A -> A
id x = x
_·_ : {A B C : Set} -> (B -> C) -> (A -> B) -> (A -> C)
f · g = \ x -> f (g x)
flip : {A B C : Set} -> (A -> B -> C) -> B -> A -> C
flip f x y = f y x
Rel : Set -> Set1
Rel X = X -> X -> Set
data False : Set where
record True : Set where
tt : True
tt = _
! : {A : Set} -> A -> True
! = _
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
subst : {A : Set}(P : A -> Set){x y : A} -> x == y -> P y -> P x
subst P refl p = p
cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
cong f refl = refl
sym : {A : Set}{x y : A} -> x == y -> y == x
sym refl = refl
trans : {A : Set}{x y z : A} -> x == y -> y == z -> x == z
trans refl yz = yz
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
infixr 10 _,_
record Σ (A : Set)(B : A -> Set) : Set where
field
fst : A
snd : B fst
_,,_ : {A : Set}{B : A -> Set}(x : A) -> B x -> Σ A B
x ,, y = record { fst = x; snd = y }
private module Σp {A : Set}{B : A -> Set} = Σ {A}{B}
open Σp public
data _∨_ (A B : Set) : Set where
inl : A -> A ∨ B
inr : B -> A ∨ B
data Bool : Set where
false : Bool
true : Bool
IsTrue : Bool -> Set
IsTrue false = False
IsTrue true = True
IsFalse : Bool -> Set
IsFalse true = False
IsFalse false = True
data Inspect (b : Bool) : Set where
itsTrue : IsTrue b -> Inspect b
itsFalse : IsFalse b -> Inspect b
inspect : (b : Bool) -> Inspect b
inspect true = itsTrue _
inspect false = itsFalse _
data LeqBool : Rel Bool where
ref : {b : Bool} -> LeqBool b b
up : LeqBool false true
One : Rel True
One _ _ = True
_[×]_ : {A B : Set} -> Rel A -> Rel B -> Rel (A × B)
(R [×] S) (a₁ , b₁) (a₂ , b₂) = R a₁ a₂ × S b₁ b₂
|
{
"alphanum_fraction": 0.495049505,
"avg_line_length": 19.2921348315,
"ext": "agda",
"hexsha": "95c9defc30a18b5b09df754ae9fc41378aa7b079",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/AIM6/Path/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/AIM6/Path/Prelude.agda",
"max_line_length": 64,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/AIM6/Path/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 701,
"size": 1717
}
|
postulate
@0 A : Set
_ : (@0 B : Set) .(C : Set) → Set
_ = λ B C → ?
|
{
"alphanum_fraction": 0.4305555556,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "853a95ce76a537792f82712059a8c8538f07caa4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue5341.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue5341.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue5341.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 34,
"size": 72
}
|
import Common.Level
open import Common.Equality
record Sigma (A : Set)(B : A -> Set) : Set where
constructor _,_
field
fst : A
snd : B fst
open Sigma
-- projected bound var
fail : (A : Set) (B : A -> Set) ->
let X : A -> Sigma A B
X = _
in (z : Sigma A B) -> X (fst z) ≡ z
fail A B z = refl
|
{
"alphanum_fraction": 0.5597484277,
"avg_line_length": 16.7368421053,
"ext": "agda",
"hexsha": "a9525b76e54ed104829ca1aa7c14452633011824",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue376Fail.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue376Fail.agda",
"max_line_length": 48,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue376Fail.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 110,
"size": 318
}
|
------------------------------------------------------------------------
-- Another definition of indexed containers
------------------------------------------------------------------------
-- Partly based on "Indexed containers" by Altenkirch, Ghani, Hancock,
-- McBride and Morris, and partly based on "Non-wellfounded trees in
-- Homotopy Type Theory" by Ahrens, Capriotti and Spadotti.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Container.Indexed.Variant
{e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
import Bijection eq as B
open import Container.Indexed eq as C
using (_⇾_; id⇾; _∘⇾_; Shape; Position; index)
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq as F hiding (id; _∘_)
open import H-level.Closure eq
open import Tactic.Sigma-cong eq
open import Univalence-axiom eq
private
variable
a ℓ p p₁ p₂ p′ q : Level
A I O : Type a
P Q R : A → Type p
ext f i k o s : A
------------------------------------------------------------------------
-- Containers
-- Doubly indexed containers.
record Container₂
(I : Type i) (O : Type o) s p :
Type (i ⊔ o ⊔ lsuc (s ⊔ p)) where
constructor _◁_
field
Shape : O → Type s
Position : ∀ {o} → Shape o → I → Type p
open Container₂ public
-- Singly indexed containers.
Container : Type i → ∀ s p → Type (i ⊔ lsuc (s ⊔ p))
Container I = Container₂ I I
private
variable
C : Container₂ I O s p
-- Container₂ can be expressed as a Σ-type.
Container≃Σ :
Container₂ I O s p ≃
(∃ λ (S : O → Type s) → ∀ {o} → S o → I → Type p)
Container≃Σ = Eq.↔→≃ (λ (S ◁ P) → S , P) (uncurry _◁_) refl refl
------------------------------------------------------------------------
-- Polynomial functors
-- The polynomial functor associated to a container.
⟦_⟧ :
{I : Type i} {O : Type o} →
Container₂ I O s p → (I → Type ℓ) → O → Type (ℓ ⊔ i ⊔ s ⊔ p)
⟦ S ◁ P ⟧ Q o = ∃ λ (s : S o) → P s ⇾ Q
-- A map function.
map : (C : Container₂ I O s p) → P ⇾ Q → ⟦ C ⟧ P ⇾ ⟦ C ⟧ Q
map C f _ (s , g) = s , f ∘⇾ g
-- Functor laws.
map-id : map C (id⇾ {P = P}) ≡ id⇾
map-id = refl _
map-∘ :
(f : Q ⇾ R) (g : P ⇾ Q) →
map C (f ∘⇾ g) ≡ map C f ∘⇾ map C g
map-∘ _ _ = refl _
-- A preservation lemma.
⟦⟧-cong :
{I : Type i} {P₁ : I → Type p₁} {P₂ : I → Type p₂} →
Extensionality? k (i ⊔ p) (p ⊔ p₁ ⊔ p₂) →
(C : Container₂ I O s p) →
(∀ i → P₁ i ↝[ k ] P₂ i) →
(∀ o → ⟦ C ⟧ P₁ o ↝[ k ] ⟦ C ⟧ P₂ o)
⟦⟧-cong {i = i} {k = k} {p = p} {P₁ = Q₁} {P₂ = Q₂}
ext (S ◁ P) Q₁↝Q₂ o =
(∃ λ (s : S o) → P s ⇾ Q₁) ↝⟨ (∃-cong λ _ →
∀-cong (lower-extensionality? k p lzero ext) λ _ →
∀-cong (lower-extensionality? k i p ext) λ _ →
Q₁↝Q₂ _) ⟩□
(∃ λ (s : S o) → P s ⇾ Q₂) □
-- The forward direction of ⟦⟧-cong is an instance of map (at least
-- when k is equivalence).
_ : _≃_.to (⟦⟧-cong ext C f o) ≡ map C (_≃_.to ∘ f) o
_ = refl _
-- The shapes of a container are pointwise equivalent to the
-- polynomial functor of the container applied to the constant
-- function yielding the unit type.
--
-- (This lemma was suggested to me by an anonymous reviewer of a
-- paper.)
Shape≃⟦⟧⊤ :
(C : Container₂ I O s p) →
Shape C o ≃ ⟦ C ⟧ (λ _ → ⊤) o
Shape≃⟦⟧⊤ {o = o} (S ◁ P) =
S o ↔⟨ inverse $ drop-⊤-right (λ _ → →-right-zero F.∘ inverse currying) ⟩□
(∃ λ (s : S o) → ∀ i → P s i → ⊤) □
------------------------------------------------------------------------
-- Coalgebras
-- The type of coalgebras for a (singly indexed) container.
Coalgebra : {I : Type i} → Container I s p → Type (lsuc (i ⊔ s ⊔ p))
Coalgebra {i = i} {s = s} {p = p} {I = I} C =
∃ λ (P : I → Type (i ⊔ s ⊔ p)) → P ⇾ ⟦ C ⟧ P
-- Coalgebra morphisms.
infix 4 _⇨_
_⇨_ :
{I : Type i} {C : Container I s p} →
Coalgebra C → Coalgebra C → Type (i ⊔ s ⊔ p)
(P , f) ⇨ (Q , g) = ∃ λ (h : P ⇾ Q) → g ∘⇾ h ≡ map _ h ∘⇾ f
private
variable
X Y Z : Coalgebra C
-- An identity morphism.
id⇨ : X ⇨ X
id⇨ = id⇾ , refl _
-- Composition for _⇨_.
infix 9 [_]_∘⇨_
[_]_∘⇨_ : ∀ Z → Y ⇨ Z → X ⇨ Y → X ⇨ Z
[_]_∘⇨_ {Y = _ , g} {X = _ , f} (_ , h) (f₁ , eq₁) (f₂ , eq₂) =
f₁ ∘⇾ f₂
, (h ∘⇾ (f₁ ∘⇾ f₂) ≡⟨⟩
(h ∘⇾ f₁) ∘⇾ f₂ ≡⟨ cong (_∘⇾ f₂) eq₁ ⟩
(map _ f₁ ∘⇾ g) ∘⇾ f₂ ≡⟨⟩
map _ f₁ ∘⇾ (g ∘⇾ f₂) ≡⟨ cong (map _ f₁ ∘⇾_) eq₂ ⟩
map _ f₁ ∘⇾ (map _ f₂ ∘⇾ f) ≡⟨⟩
map _ (f₁ ∘⇾ f₂) ∘⇾ f ∎)
-- The property of being a final coalgebra.
Final :
{I : Type i} {C : Container I s p} →
Coalgebra C → Type (lsuc (i ⊔ s ⊔ p))
Final X = ∀ Y → Contractible (Y ⇨ X)
-- A perhaps more traditional definition of what it means to be final.
Final′ :
{I : Type i} {C : Container I s p} →
Coalgebra C → Type (lsuc (i ⊔ s ⊔ p))
Final′ X =
∀ Y → ∃ λ (m : Y ⇨ X) → (m′ : Y ⇨ X) → proj₁ m ≡ proj₁ m′
-- Final X implies Final′ X.
Final→Final′ : (X : Coalgebra C) → Final X → Final′ X
Final→Final′ _ =
∀-cong _ λ _ → ∃-cong λ _ → ∀-cong _ λ _ → cong proj₁
-- Final is pointwise propositional (assumption extensionality).
Final-propositional :
{I : Type i} {C : Container I s p} →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
(X : Coalgebra C) →
Is-proposition (Final X)
Final-propositional ext _ =
Π-closure ext 1 λ _ →
Contractible-propositional (lower-extensionality _ lzero ext)
-- Final coalgebras.
Final-coalgebra :
{I : Type i} →
Container I s p → Type (lsuc (i ⊔ s ⊔ p))
Final-coalgebra C = ∃ λ (X : Coalgebra C) → Final X
-- Final coalgebras, defined using Final′.
Final-coalgebra′ :
{I : Type i} →
Container I s p → Type (lsuc (i ⊔ s ⊔ p))
Final-coalgebra′ C = ∃ λ (X : Coalgebra C) → Final′ X
-- Final-coalgebra C implies Final-coalgebra′ C.
Final-coalgebra→Final-coalgebra′ :
Final-coalgebra C → Final-coalgebra′ C
Final-coalgebra→Final-coalgebra′ =
∃-cong Final→Final′
-- Carriers of final coalgebras (defined using Final′) for a given
-- container are pointwise equivalent.
carriers-of-final-coalgebras-equivalent′ :
(((P₁ , _) , _) ((P₂ , _) , _) : Final-coalgebra′ C) →
∀ i → P₁ i ≃ P₂ i
carriers-of-final-coalgebras-equivalent′ (X₁ , final₁) (X₂ , final₂) i =
Eq.↔→≃ (proj₁ to i) (proj₁ from i) to∘from from∘to
where
to : X₁ ⇨ X₂
to = proj₁ (final₂ X₁)
from : X₂ ⇨ X₁
from = proj₁ (final₁ X₂)
to∘from : ∀ x → proj₁ ([ X₂ ] to ∘⇨ from) i x ≡ x
to∘from x =
proj₁ ([ X₂ ] to ∘⇨ from) i x ≡⟨ cong (λ f → f i x) $ sym $ proj₂ (final₂ X₂) $ [ X₂ ] to ∘⇨ from ⟩
proj₁ (proj₁ (final₂ X₂)) i x ≡⟨ cong (λ f → f i x) $ proj₂ (final₂ X₂) id⇨ ⟩
proj₁ (id⇨ {X = X₂}) i x ≡⟨⟩
x ∎
from∘to : ∀ x → proj₁ ([ X₁ ] from ∘⇨ to) i x ≡ x
from∘to x =
proj₁ ([ X₁ ] from ∘⇨ to) i x ≡⟨ cong (λ f → f i x) $ sym $ proj₂ (final₁ X₁) $ [ X₁ ] from ∘⇨ to ⟩
proj₁ (proj₁ (final₁ X₁)) i x ≡⟨ cong (λ f → f i x) $ proj₂ (final₁ X₁) id⇨ ⟩
proj₁ (id⇨ {X = X₁}) i x ≡⟨⟩
x ∎
-- The previous lemma relates the "out" functions of the two final
-- coalgebras in a certain way.
out-related′ :
{C : Container I s p}
(F₁@((_ , out₁) , _) F₂@((_ , out₂) , _) : Final-coalgebra′ C) →
map C (_≃_.to ∘ carriers-of-final-coalgebras-equivalent′ F₁ F₂) ∘⇾
out₁
≡
out₂ ∘⇾ (_≃_.to ∘ carriers-of-final-coalgebras-equivalent′ F₁ F₂)
out-related′ (X₁ , _) (_ , final₂) =
sym $ proj₂ (proj₁ (final₂ X₁))
-- Carriers of final coalgebras for a given container are pointwise
-- equivalent.
carriers-of-final-coalgebras-equivalent :
(((P₁ , _) , _) ((P₂ , _) , _) : Final-coalgebra C) →
∀ i → P₁ i ≃ P₂ i
carriers-of-final-coalgebras-equivalent =
carriers-of-final-coalgebras-equivalent′ on
Final-coalgebra→Final-coalgebra′
-- The previous lemma relates the "out" functions of the two final
-- coalgebras in a certain way.
out-related :
{C : Container I s p}
(F₁@((_ , out₁) , _) F₂@((_ , out₂) , _) : Final-coalgebra C) →
map C (_≃_.to ∘ carriers-of-final-coalgebras-equivalent F₁ F₂) ∘⇾ out₁
≡
out₂ ∘⇾ (_≃_.to ∘ carriers-of-final-coalgebras-equivalent F₁ F₂)
out-related = out-related′ on Final-coalgebra→Final-coalgebra′
-- If X and Y are final coalgebras (with finality defined using
-- Final′), then—assuming extensionality—finality of X (defined using
-- Final) is equivalent to finality of Y.
Final′→Final≃Final :
{I : Type i} {C : Container I s p}
((X , _) (Y , _) : Final-coalgebra′ C) →
Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p) →
Final X ↝[ lsuc (i ⊔ s ⊔ p) ∣ i ⊔ s ⊔ p ] Final Y
Final′→Final≃Final {i = i} {s = s} {p = p} {C = C}
((X₁ , out₁) , final₁) ((X₂ , out₂) , final₂) ext {k = k} ext′ =
∀-cong ext′ λ Y@(_ , f) →
H-level-cong
(lower-extensionality? k _ lzero ext′)
0
(Σ-cong (lemma₂ Y) λ g →
out₁ ∘⇾ g ≡ map C g ∘⇾ f ↝⟨ inverse $ Eq.≃-≡ (lemma₃ Y) ⟩
_≃_.to (lemma₃ Y) (out₁ ∘⇾ g) ≡
_≃_.to (lemma₃ Y) (map C g ∘⇾ f) ↔⟨⟩
map C (_≃_.to ∘ lemma₁) ∘⇾ out₁ ∘⇾ g ≡
map C (_≃_.to ∘ lemma₁) ∘⇾ map C g ∘⇾ f ↝⟨ ≡⇒↝ _ $ cong (λ h → h ∘⇾ g ≡ map C (_≃_.to ∘ lemma₁) ∘⇾ map C g ∘⇾ f) $
out-related′ ((X₁ , out₁) , final₁) ((X₂ , out₂) , final₂) ⟩
out₂ ∘⇾ (_≃_.to ∘ lemma₁) ∘⇾ g ≡
map C (_≃_.to ∘ lemma₁) ∘⇾ map C g ∘⇾ f ↔⟨⟩
out₂ ∘⇾ _≃_.to (lemma₂ Y) g ≡
map C (_≃_.to (lemma₂ Y) g) ∘⇾ f □)
where
ext₁ = lower-extensionality (s ⊔ p) lzero ext
ext₂ = lower-extensionality (i ⊔ s) lzero ext
lemma₁ : ∀ i → X₁ i ≃ X₂ i
lemma₁ =
carriers-of-final-coalgebras-equivalent′
((X₁ , out₁) , final₁)
((X₂ , out₂) , final₂)
lemma₂ : ((Y , _) : Coalgebra C) → (Y ⇾ X₁) ≃ (Y ⇾ X₂)
lemma₂ _ =
∀-cong ext₁ λ _ →
∀-cong ext λ _ →
lemma₁ _
lemma₃ : ((Y , _) : Coalgebra C) → (Y ⇾ ⟦ C ⟧ X₁) ≃ (Y ⇾ ⟦ C ⟧ X₂)
lemma₃ _ =
∀-cong ext₁ λ _ →
∀-cong ext λ _ →
⟦⟧-cong ext₂ C lemma₁ _
-- If there is a final C-coalgebra, and we have Final′ X for some
-- C-coalgebra X, then we also have Final X (assuming extensionality).
Final′→Final :
{I : Type i} {C : Container I s p} →
Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p) →
Final-coalgebra C →
((X , _) : Final-coalgebra′ C) →
Final X
Final′→Final ext F₁@(_ , final₁) F₂ =
Final′→Final≃Final
(Final-coalgebra→Final-coalgebra′ F₁) F₂
ext _ final₁
-- Final-coalgebra is pointwise propositional, assuming extensionality
-- and univalence.
--
-- This is a variant of Lemma 5 from "Non-wellfounded trees in
-- Homotopy Type Theory".
Final-coalgebra-propositional :
{I : Type i} {C : Container I s p} →
Extensionality (lsuc (i ⊔ s ⊔ p)) (lsuc (i ⊔ s ⊔ p)) →
Univalence (i ⊔ s ⊔ p) →
Is-proposition (Final-coalgebra C)
Final-coalgebra-propositional {I = I} {C = C@(S ◁ P)}
ext univ F₁@((P₁ , out₁) , _) F₂@(X₂@(P₂ , out₂) , _) =
block λ b →
Σ-≡,≡→≡ (Σ-≡,≡→≡ (lemma₁ b) (lemma₂ b))
(Final-propositional (lower-extensionality lzero _ ext) X₂ _ _)
where
ext₁′ = lower-extensionality _ lzero ext
ext₁ = Eq.good-ext ext₁′
lemma₀ : Block "lemma₀" → ∀ i → P₁ i ≃ P₂ i
lemma₀ ⊠ = carriers-of-final-coalgebras-equivalent F₁ F₂
lemma₀-lemma :
∀ b x →
map C (_≃_.to ∘ lemma₀ b) i (out₁ i (_≃_.from (lemma₀ b i) x)) ≡
out₂ i x
lemma₀-lemma {i = i} ⊠ x =
map C (_≃_.to ∘ lemma₀ ⊠) i (out₁ i (_≃_.from (lemma₀ ⊠ i) x)) ≡⟨ cong (λ f → f _ (_≃_.from (lemma₀ ⊠ i) x)) $
out-related F₁ F₂ ⟩
out₂ i (_≃_.to (lemma₀ ⊠ i) (_≃_.from (lemma₀ ⊠ i) x)) ≡⟨ cong (out₂ _) $
_≃_.right-inverse-of (lemma₀ ⊠ i) _ ⟩∎
out₂ i x ∎
lemma₁ : Block "lemma₀" → P₁ ≡ P₂
lemma₁ b =
apply-ext ext₁ λ i →
≃⇒≡ univ (lemma₀ b i)
lemma₁-lemma₁ = λ b i →
sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (subst-const _) ≡⟨ cong sym Σ-≡,≡→≡-subst-const-refl ⟩
sym $ cong₂ _,_ (sym (lemma₁ b)) (refl _) ≡⟨ sym cong₂-sym ⟩
cong₂ _,_ (sym (sym (lemma₁ b))) (sym (refl _)) ≡⟨ cong₂ (cong₂ _) (sym-sym _) sym-refl ⟩
cong₂ _,_ (lemma₁ b) (refl i) ≡⟨ cong₂-reflʳ _ ⟩∎
cong (_, i) (lemma₁ b) ∎
lemma₁-lemma₂ = λ b i x →
subst (_$ i) (sym (lemma₁ b)) x ≡⟨⟩
subst (_$ i) (sym (apply-ext ext₁ λ i → ≃⇒≡ univ (lemma₀ b i))) x ≡⟨ cong (flip (subst (_$ i)) _) $ sym $
Eq.good-ext-sym ext₁′ _ ⟩
subst (_$ i) (apply-ext ext₁ λ i → sym (≃⇒≡ univ (lemma₀ b i))) x ≡⟨ Eq.subst-good-ext ext₁′ _ _ ⟩
subst id (sym (≃⇒≡ univ (lemma₀ b i))) x ≡⟨ subst-id-in-terms-of-inverse∘≡⇒↝ equivalence ⟩
_≃_.from (≡⇒≃ (≃⇒≡ univ (lemma₀ b i))) x ≡⟨ cong (λ eq → _≃_.from eq _) $
_≃_.right-inverse-of (≡≃≃ univ) _ ⟩∎
_≃_.from (lemma₀ b i) x ∎
lemma₁-lemma₃ : ∀ b (f : P s ⇾ P₁) i p → _ ≡ _
lemma₁-lemma₃ b f i p =
subst (_$ i) (lemma₁ b) (f i p) ≡⟨⟩
subst (_$ i) (apply-ext ext₁ λ i → ≃⇒≡ univ (lemma₀ b i)) (f i p) ≡⟨ Eq.subst-good-ext ext₁′ _ _ ⟩
subst id (≃⇒≡ univ (lemma₀ b i)) (f i p) ≡⟨ subst-id-in-terms-of-≡⇒↝ equivalence ⟩
≡⇒→ (≃⇒≡ univ (lemma₀ b i)) (f i p) ≡⟨ cong (λ eq → _≃_.to eq _) $
_≃_.right-inverse-of (≡≃≃ univ) _ ⟩∎
_≃_.to (lemma₀ b i) (f i p) ∎
lemma₂ = λ b →
apply-ext (lower-extensionality _ _ ext) λ i →
apply-ext (lower-extensionality _ _ ext) λ x →
subst (λ P → P ⇾ ⟦ C ⟧ P) (lemma₁ b) out₁ i x ≡⟨⟩
subst (λ P → ∀ i → P i → ⟦ C ⟧ P i) (lemma₁ b) out₁ i x ≡⟨ cong (_$ x) subst-∀ ⟩
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (refl _))
(out₁ (subst (λ _ → I) (sym (lemma₁ b)) i)) x ≡⟨ elim¹
(λ {i′} eq →
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (refl _))
(out₁ (subst (λ _ → I) (sym (lemma₁ b)) i)) x ≡
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) eq)
(out₁ i′) x)
(refl _)
_ ⟩
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(sym $ Σ-≡,≡→≡ (sym (lemma₁ b)) (subst-const _))
(out₁ i) x ≡⟨ cong (λ eq → subst (uncurry λ P i → P i → ⟦ C ⟧ P i) eq _ _) $
lemma₁-lemma₁ b i ⟩
subst (uncurry λ P i → P i → ⟦ C ⟧ P i)
(cong (_, _) (lemma₁ b))
(out₁ i) x ≡⟨ cong (_$ x) $ sym $ subst-∘ _ _ _ ⟩
subst (λ P → P i → ⟦ C ⟧ P i) (lemma₁ b) (out₁ i) x ≡⟨ subst-→ ⟩
subst (λ P → ⟦ C ⟧ P i) (lemma₁ b)
(out₁ i (subst (_$ i) (sym (lemma₁ b)) x)) ≡⟨ cong (subst (λ P → ⟦ C ⟧ P i) _) $ cong (out₁ _) $
lemma₁-lemma₂ b i x ⟩
subst (λ P → ⟦ C ⟧ P i) (lemma₁ b)
(out₁ i (_≃_.from (lemma₀ b i) x)) ≡⟨⟩
subst (λ Q → ∃ λ (s : S i) → P s ⇾ Q) (lemma₁ b)
(out₁ i (_≃_.from (lemma₀ b i) x)) ≡⟨ push-subst-pair-× _ _ ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , subst (λ Q → P s ⇾ Q) (lemma₁ b) f) ≡⟨ (let s , _ = out₁ i (_≃_.from (lemma₀ b i) x) in
cong (s ,_) $
apply-ext (lower-extensionality _ _ ext) λ _ → sym $
push-subst-application _ _) ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , λ i → subst (λ Q → P s i → Q i) (lemma₁ b) (f i)) ≡⟨ (let s , _ = out₁ i (_≃_.from (lemma₀ b i) x) in
cong (s ,_) $
apply-ext (lower-extensionality _ _ ext) λ _ →
apply-ext (lower-extensionality _ _ ext) λ _ → sym $
push-subst-application _ _) ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , λ i p → subst (_$ i) (lemma₁ b) (f i p)) ≡⟨ (let _ , f = out₁ i (_≃_.from (lemma₀ b i) x) in
cong (_ ,_) $
apply-ext (lower-extensionality _ _ ext) λ i →
apply-ext (lower-extensionality _ _ ext) $
lemma₁-lemma₃ b f i) ⟩
(let s , f = out₁ i (_≃_.from (lemma₀ b i) x) in
s , λ i p → _≃_.to (lemma₀ b i) (f i p)) ≡⟨⟩
map C (_≃_.to ∘ lemma₀ b) i (out₁ i (_≃_.from (lemma₀ b i) x)) ≡⟨ lemma₀-lemma b x ⟩∎
out₂ i x ∎
------------------------------------------------------------------------
-- Conversion lemmas
-- A conversion lemma for Container. Note that the last index is not
-- unrestricted.
Container⇔Container :
∀ {I : Type i} {O : Type o} p →
Container₂ I O s (i ⊔ p) ⇔ C.Container₂ I O s (i ⊔ p)
Container⇔Container {i = iℓ} {s = s} {I = I} {O = O} p =
Container₂ I O s (iℓ ⊔ p) ↔⟨ Container≃Σ ⟩
(∃ λ (S : O → Type s) →
∀ {o} → S o → I → Type (iℓ ⊔ p)) ↔⟨ (∃-cong λ _ →
B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) → I → Type (iℓ ⊔ p)) ↝⟨ (∃-cong λ _ → ∀-cong _ λ _ → ∀-cong _ λ _ →
Pow⇔Fam p) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) →
∃ λ (P : Type (iℓ ⊔ p)) → P → I) ↝⟨ (∃-cong λ _ →
from-bijection ΠΣ-comm F.∘
∀-cong _ λ _ → from-bijection ΠΣ-comm) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ o → S o → Type (iℓ ⊔ p)) →
∀ o (s : S o) → P o s → I) ↝⟨ (∃-cong λ _ → inverse $
Σ-cong-refl {k₂ = logical-equivalence} B.implicit-Π↔Π λ _ →
(∀-cong _ λ _ →
from-bijection B.implicit-Π↔Π) F.∘
from-bijection B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ {o} → S o → Type (iℓ ⊔ p)) →
∀ {o} {s : S o} → P s → I) ↔⟨ inverse C.Container≃Σ ⟩□
C.Container₂ I O s (iℓ ⊔ p) □
-- Another conversion lemma for Container.
Container≃Container :
∀ {I : Type i} {O : Type o} p →
Extensionality (i ⊔ o ⊔ s) (lsuc i ⊔ s ⊔ lsuc p) →
Univalence (i ⊔ p) →
Container₂ I O s (i ⊔ p) ≃ C.Container₂ I O s (i ⊔ p)
Container≃Container {i = i} {o = o} {s = s} {I = I} {O = O} p ext univ =
Container₂ I O s (i ⊔ p) ↝⟨ Container≃Σ ⟩
(∃ λ (S : O → Type s) →
∀ {o} → S o → I → Type (i ⊔ p)) ↔⟨ (∃-cong λ _ →
B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) → I → Type (i ⊔ p)) ↔⟨ (∃-cong λ _ →
∀-cong (lower-extensionality l r ext) λ _ →
∀-cong (lower-extensionality l r ext) λ _ →
Pow↔Fam p (lower-extensionality l r ext) univ) ⟩
(∃ λ (S : O → Type s) →
∀ o (s : S o) →
∃ λ (P : Type (i ⊔ p)) → P → I) ↔⟨ (∃-cong λ _ →
ΠΣ-comm F.∘
∀-cong (lower-extensionality l r ext) λ _ → ΠΣ-comm) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ o → S o → Type (i ⊔ p)) →
∀ o (s : S o) → P o s → I) ↝⟨ (∃-cong λ _ → inverse $
Σ-cong-refl {k₂ = logical-equivalence} B.implicit-Π↔Π λ _ →
(∀-cong _ λ _ →
from-bijection B.implicit-Π↔Π) F.∘
from-bijection B.implicit-Π↔Π) ⟩
(∃ λ (S : O → Type s) →
∃ λ (P : ∀ {o} → S o → Type (i ⊔ p)) →
∀ {o} {s : S o} → P s → I) ↝⟨ inverse C.Container≃Σ ⟩□
C.Container₂ I O s (i ⊔ p) □
where
l = i ⊔ o ⊔ s
r = lsuc i ⊔ s ⊔ lsuc p
-- The two conversion lemmas for Container are related.
_ :
{I : Type i} {univ : Univalence (i ⊔ p)} →
_≃_.logical-equivalence
(Container≃Container {I = I} {O = O} p ext univ) ≡
Container⇔Container p
_ = refl _
-- A conversion lemma for ⟦_⟧.
⟦⟧≃⟦⟧ :
∀ p →
{I : Type i} (C : Container₂ I O s (i ⊔ p)) {P : I → Type ℓ} →
∀ o →
C.⟦ _⇔_.to (Container⇔Container p) C ⟧ P o ≃ ⟦ C ⟧ P o
⟦⟧≃⟦⟧ _ {I = I} C {P = P} o =
(∃ λ (s : Shape C o) → ((i , _) : Σ I (Position C s)) → P i) ↔⟨ (∃-cong λ _ → currying) ⟩□
(∃ λ (s : Shape C o) → (i : I) → Position C s i → P i) □
-- Another conversion lemma for ⟦_⟧.
⟦⟧≃⟦⟧′ :
∀ p →
{I : Type i} (C : C.Container₂ I O s (i ⊔ p)) {P : I → Type ℓ} →
∀ o →
⟦ _⇔_.from (Container⇔Container p) C ⟧ P o ↝[ i ⊔ p ∣ i ⊔ p ⊔ ℓ ]
C.⟦ C ⟧ P o
⟦⟧≃⟦⟧′ {i = i} {ℓ = ℓ} p {I = I} C {P = P} _ {k = k} ext =
∃-cong λ s →
((i : I) → (∃ λ (p : C .Position s) → C .index p ≡ i) → P i) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
from-bijection currying) ⟩
((i : I) (p : C .Position s) → C .index p ≡ i → P i) ↔⟨ Π-comm ⟩
((p : C .Position s) (i : I) → C .index p ≡ i → P i) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
∀-cong (lower-extensionality? k l r ext) λ _ →
∀-cong (lower-extensionality? k l r ext) λ eq →
≡⇒↝ _ $ cong P (sym eq)) ⟩
((p : C .Position s) (i : I) → C .index p ≡ i → P (C .index p)) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
from-bijection $ inverse currying) ⟩
((p : C .Position s) → (∃ λ (i : I) → C .index p ≡ i) →
P (C .index p)) ↝⟨ (∀-cong (lower-extensionality? k l r ext) λ _ →
drop-⊤-left-Π (lower-extensionality? k l r ext) $
_⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _) ⟩□
((p : C .Position s) → P (C .index p)) □
where
l = i ⊔ p
r = i ⊔ p ⊔ ℓ
-- The map functions commute with ⟦⟧≃⟦⟧ (in a certain sense).
_ :
map C f ∘⇾ (_≃_.to ∘ ⟦⟧≃⟦⟧ p C) ≡
(_≃_.to ∘ ⟦⟧≃⟦⟧ p C) ∘⇾ C.map (_⇔_.to (Container⇔Container p) C) f
_ = refl _
-- The map functions commute with ⟦⟧≃⟦⟧′ (in a certain sense, assuming
-- extensionality).
map≡map′ :
{I : Type i} {O : Type o} {P : I → Type p} {Q : I → Type q} →
∀ p′ →
Extensionality (i ⊔ o ⊔ p ⊔ s ⊔ p′) (i ⊔ p ⊔ q ⊔ s ⊔ p′) →
(C : C.Container₂ I O s (i ⊔ p′)) {f : P ⇾ Q} →
C.map C f ∘⇾ (λ o → ⟦⟧≃⟦⟧′ p′ C o _) ≡
(λ o → ⟦⟧≃⟦⟧′ p′ C o _) ∘⇾ map (_⇔_.from (Container⇔Container p′) C) f
map≡map′ {i = i} {o = o} {p = p} {q = q} {s = s} {P = P} {Q = Q}
p′ ext C {f = f} =
apply-ext (lower-extensionality l r ext) λ _ →
apply-ext (lower-extensionality l r ext) λ (_ , g) →
cong (_ ,_) $
apply-ext (lower-extensionality l r ext) λ p →
let i = C .index p in
f i (≡⇒↝ _ (cong P (sym (refl _))) (g i (p , refl _))) ≡⟨ cong (λ eq → f i (≡⇒↝ _ eq (g i (p , refl _)))) $
trans (cong (cong P) sym-refl) $
cong-refl _ ⟩
f i (≡⇒↝ _ (refl _) (g i (p , refl _))) ≡⟨ cong (f i) $ cong (_$ g i (p , refl _))
≡⇒↝-refl ⟩
f i (g i (p , refl _)) ≡⟨ cong (_$ f i (g i (p , refl _))) $ sym
≡⇒↝-refl ⟩
≡⇒↝ _ (refl _) (f i (g i (p , refl _))) ≡⟨ cong (λ eq → ≡⇒↝ _ eq (f i (g i (p , refl _)))) $ sym $
trans (cong (cong Q) sym-refl) $
cong-refl _ ⟩∎
≡⇒↝ _ (cong Q (sym (refl _))) (f i (g i (p , refl _))) ∎
where
l = i ⊔ o ⊔ p ⊔ s ⊔ p′
r = i ⊔ p ⊔ q ⊔ s ⊔ p′
-- A conversion lemma for Coalgebra.
Coalgebra≃Coalgebra :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Coalgebra C ↝[ i ⊔ s ⊔ p ∣ i ⊔ s ⊔ p ]
C.Coalgebra (_⇔_.to (Container⇔Container p) C)
Coalgebra≃Coalgebra {s = s} p C {k = k} ext =
(∃ λ P → P ⇾ ⟦ C ⟧ P) ↝⟨ (∃-cong λ _ →
∀-cong (lower-extensionality? k (s ⊔ p) lzero ext) λ _ →
∀-cong ext λ _ →
from-equivalence $ inverse $ ⟦⟧≃⟦⟧ p C _) ⟩□
(∃ λ P → P ⇾ C.⟦ _⇔_.to (Container⇔Container p) C ⟧ P) □
-- A conversion lemma for _⇨_.
⇨≃⇨ :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p) →
(X Y : Coalgebra C) →
(X ⇨ Y) ≃
(Coalgebra≃Coalgebra p C _ X C.⇨ Coalgebra≃Coalgebra p C _ Y)
⇨≃⇨ {s = s} p C ext (P , f) (Q , g) =
(∃ λ (h : P ⇾ Q) → g ∘⇾ h ≡ map _ h ∘⇾ f) ↝⟨ (∃-cong λ h → inverse $ Eq.≃-≡ $
∀-cong (lower-extensionality (s ⊔ p) lzero ext) λ _ →
∀-cong ext λ _ →
inverse $ ⟦⟧≃⟦⟧ p C _) ⟩□
(∃ λ (h : P ⇾ Q) →
((Σ-map id uncurry ∘_) ∘ g) ∘⇾ h ≡
C.map _ h ∘⇾ ((Σ-map id uncurry ∘_) ∘ f)) □
-- A conversion lemma for Final.
Final≃Final :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
(ext : Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p))
(X : Coalgebra C) →
Final X ≃ C.Final (_≃_.to (Coalgebra≃Coalgebra p C ext) X)
Final≃Final p C ext′ ext X =
(∀ Y → Contractible (Y ⇨ X)) ↝⟨ (Π-cong ext′ (Coalgebra≃Coalgebra p C {k = equivalence} ext) λ Y →
H-level-cong ext 0 $
⇨≃⇨ p C ext Y X) ⟩□
(∀ Y → Contractible (Y C.⇨ Coalgebra≃Coalgebra p C _ X)) □
-- A conversion lemma for Final′.
Final′≃Final′ :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
(ext : Extensionality (i ⊔ s ⊔ p) (i ⊔ s ⊔ p))
(X : Coalgebra C) →
Final′ X ≃ C.Final′ (_≃_.to (Coalgebra≃Coalgebra p C ext) X)
Final′≃Final′ p C ext′ ext X =
(∀ Y → ∃ λ (m : Y ⇨ X ) → (m′ : Y ⇨ X ) → proj₁ m ≡ proj₁ m′) ↝⟨ (Π-cong ext′ (Coalgebra≃Coalgebra p C {k = equivalence} ext) λ Y →
Σ-cong (⇨≃⇨ p C ext Y X) λ _ →
Π-cong ext (⇨≃⇨ p C ext Y X) λ _ →
F.id) ⟩□
(∀ Y → ∃ λ (m : Y C.⇨ X′) → (m′ : Y C.⇨ X′) → proj₁ m ≡ proj₁ m′) □
where
X′ = _≃_.to (Coalgebra≃Coalgebra p C ext) X
-- A conversion lemma for Final-coalgebra.
Final-coalgebra≃Final-coalgebra :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
Final-coalgebra C ≃
C.Final-coalgebra (_⇔_.to (Container⇔Container p) C)
Final-coalgebra≃Final-coalgebra p C ext =
(∃ λ (X : Coalgebra C ) → Final X) ↝⟨ Σ-cong {k₁ = equivalence}
(Coalgebra≃Coalgebra p C ext′)
(Final≃Final p C ext ext′) ⟩□
(∃ λ (X : C.Coalgebra C′) → C.Final X) □
where
C′ = _⇔_.to (Container⇔Container p) C
ext′ = lower-extensionality _ lzero ext
-- A conversion lemma for Final-coalgebra′.
Final-coalgebra′≃Final-coalgebra′ :
∀ p {I : Type i} (C : Container I s (i ⊔ p)) →
Extensionality (lsuc (i ⊔ s ⊔ p)) (i ⊔ s ⊔ p) →
Final-coalgebra′ C ≃
C.Final-coalgebra′ (_⇔_.to (Container⇔Container p) C)
Final-coalgebra′≃Final-coalgebra′ p C ext =
(∃ λ (X : Coalgebra C ) → Final′ X) ↝⟨ Σ-cong {k₁ = equivalence}
(Coalgebra≃Coalgebra p C ext′)
(Final′≃Final′ p C ext ext′) ⟩□
(∃ λ (X : C.Coalgebra C′) → C.Final′ X) □
where
C′ = _⇔_.to (Container⇔Container p) C
ext′ = lower-extensionality _ lzero ext
|
{
"alphanum_fraction": 0.4224859422,
"avg_line_length": 41.3351351351,
"ext": "agda",
"hexsha": "22e8a27442c92ee48072d4de492520c077fe99e1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Container/Indexed/Variant.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Container/Indexed/Variant.agda",
"max_line_length": 138,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Container/Indexed/Variant.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 11308,
"size": 30588
}
|
import Lvl
-- TODO: Just testing how it goes with creating an axiomatic system
module Geometry.Test (Point : Set(Lvl.𝟎)) where
open import Functional
open import Logic.Propositional{Lvl.𝟎}
open import Logic.Predicate{Lvl.𝟎}{Lvl.𝟎}
open import Relator.Equals{Lvl.𝟎}{Lvl.𝟎}
-- open import Structure.Setoid.Uniqueness{Lvl.𝟎}{Lvl.𝟎}{Lvl.𝟎} hiding (Theorems)
open import Structure.Relator.Equivalence{Lvl.𝟎}{Lvl.𝟎}
open import Structure.Relator.Ordering{Lvl.𝟎}{Lvl.𝟎}
-- open import Structure.Relator.Properties{Lvl.𝟎}{Lvl.𝟎} hiding (Theorems)
-- A line of infinite length
record Line : Set(Lvl.𝟎) where
constructor line
field
a : Point
b : Point
-- A line segment of finite length
record LineSegment : Set(Lvl.𝟎) where
constructor lineSegment
field
a : Point
b : Point
-- A circle
record Circle : Set(Lvl.𝟎) where
constructor circle
field
middle : Point
outer : Point
record Theory : Set(Lvl.𝐒(Lvl.𝟎)) where
-- Symbols
field
PointOnLine : Point → Line → Set(Lvl.𝟎) -- The point lies on the line
PointOnLineSegment : Point → LineSegment → Set(Lvl.𝟎) -- The point lies on the line segment
PointOnCircle : Point → Circle → Set(Lvl.𝟎) -- The point lies on the circle
_≾_ : LineSegment → LineSegment → Set(Lvl.𝟎) -- Comparison of line length
_≿_ : LineSegment → LineSegment → Set(Lvl.𝟎) -- Comparison of line length
_≿_ l₁ l₂ = l₂ ≾ l₁
_≋_ : LineSegment → LineSegment → Set(Lvl.𝟎) -- Equality of line length
_≋_ l₁ l₂ = (l₁ ≾ l₂) ∧ (l₁ ≿ l₂)
-- Axioms
field
[≾]-weak-total-order : Weak.TotalOrder(_≾_)(_≋_) -- (_≾_) is a weak total order
point-on-line-existence : ∀{l : Line} → ∃(p ↦ PointOnLine(p)(l)) -- There is a point on a line
point1-on-line : ∀{l : Line} → PointOnLine(Line.a(l))(l)
point2-on-line : ∀{l : Line} → PointOnLine(Line.b(l))(l)
point-on-lineSegment-existence : ∀{l : LineSegment} → ∃(p ↦ PointOnLineSegment(p)(l)) -- There is a point on a line
endpoint1-on-lineSegment : ∀{l : LineSegment} → PointOnLineSegment(Line.a(l))(l)
endpoint2-on-lineSegment : ∀{l : LineSegment} → PointOnLineSegment(Line.b(l))(l)
point-on-circle-existence : ∀{c : Circle} → ∃(p ↦ PointOnCircle(p)(c)) -- There is a point on a circle
outer-on-circle : ∀{c : Circle} → PointOnCircle(Circle.outer(c))(c)
single-point-circle : ∀{p : Point}{x : Point} → PointOnCircle(x) (circle(p)(p)) → (x ≡ p) -- There is only a simgle point on a circle of zero radius
line-equality : ∀{l : Line}{a : Point}{b : Point} → PointOnLine(a)(l) → PointOnLine(b)(l) → (l ≡ line(a)(b)) -- A line is non-directional
circle-equality : ∀{c : Circle}{o : Point} → PointOnCircle(o)(c) → (c ≡ circle(Circle.middle(c))(o))
lineSegment-equality : ∀{a : Point}{b : Point} → (lineSegment(a)(b) ≡ lineSegment(b)(a)) -- A line segment is non-directional
-- line-intersection : ∀{l₁ : Line}{l₂ : Line} → ∃!(p ↦ PointOnLine(p)(l₁) ∧ PointOnLine(p)(l₂))
circle-intersection : ∀{a : Point}{b : Point} → ∃(i ↦ PointOnCircle(i)(circle(a)(b)) ∧ PointOnCircle(i)(circle(b)(a))) ∧ ∃(i ↦ PointOnCircle(i)(circle(a)(b)) ∧ PointOnCircle(i)(circle(b)(a)))
module Theorems ⦃ _ : Theory ⦄ where
open Theory ⦃ ... ⦄
-- middlepoint : Line → Point
-- middlepoint(line(a)(b)) =
|
{
"alphanum_fraction": 0.6548971446,
"avg_line_length": 41.7564102564,
"ext": "agda",
"hexsha": "e9a148383668fee882e6d2277fa04ef5ceb321e1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Geometry/Test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Geometry/Test.agda",
"max_line_length": 195,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Geometry/Test.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1145,
"size": 3257
}
|
module Oscar.Data.Permutation where
--open import Data.Permutation public
import Data.Permutation as P
open import Data.Permutation renaming (delete to deleteP; _∘_ to _∘P_; enum to allInj)
open import Oscar.Data.Vec renaming (delete to deleteV; map to mapV)
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Data.Fin renaming (inject to injectF)
open ≡-Reasoning
open import Data.Permutation.Properties
open import Oscar.Data.Vec.Properties
open import Function
open import Data.Sum
open import Agda.Builtin.Nat
<>-inv : ∀ {n} (ps : Permutation n) i → i ≡ < ps > (< ps ⁻¹ > i)
<>-inv ps i =
trans
(sym (id-is-id i))
(subst (< P.id > _ ≡_)
(inj-correct (ps ⁻¹) ps i)
(cong (flip <_> _)
(sym (inv-left ps))))
_⋟_÷_ : ∀ {a m n} {A : Set a} → Vec A n → Vec A m → Inj m n → Set a
x ⋟ px ÷ p = ∀ i → lookup i px ≡ lookup (< p > i) x
lookup-ext : ∀ {a n} {A : Set a} {pv₁ pv₂ : Vec A n} → (∀ i → lookup i pv₁ ≡ lookup i pv₂) → pv₁ ≡ pv₂
lookup-ext {pv₁ = []} {[]} x = refl
lookup-ext {pv₁ = x₁ ∷ pv₁} {x₂ ∷ pv₂} x with lookup-ext {pv₁ = pv₁} {pv₂} (x ∘ suc) | x zero
… | refl | refl = refl
injected-inj : ∀ {a n m} {A : Set a} {v : Vec A m} {pv₁ pv₂ : Vec A n} {p : Inj n m} → v ⋟ pv₁ ÷ p → v ⋟ pv₂ ÷ p → pv₁ ≡ pv₂
injected-inj {pv₁ = pv₁} {pv₂} v⋟pv₁÷p v⋟pv₂÷p = lookup-ext foo where
foo : (i : Fin _) → lookup i pv₁ ≡ lookup i pv₂
foo i = trans (v⋟pv₁÷p i) (sym (v⋟pv₂÷p i))
permuted-inj : ∀ {a n} {A : Set a} {v : Vec A n} {pv₁ pv₂ : Vec A n} {p : Permutation n} → v ⋟ pv₁ ÷ p → v ⋟ pv₂ ÷ p → pv₁ ≡ pv₂
permuted-inj {pv₁ = pv₁} {pv₂} v⋟pv₁÷p v⋟pv₂÷p = lookup-ext foo where
foo : (i : Fin _) → lookup i pv₁ ≡ lookup i pv₂
foo i = trans (v⋟pv₁÷p i) (sym (v⋟pv₂÷p i))
permutedLookup : ∀ {a n} {A : Set a} → Permutation n → Vec A n → Fin n → A
permutedLookup p v = flip lookup v ∘ < p >
inject : ∀ {a n m} {A : Set a} → (p : Inj n m) → (v : Vec A m) → Vec A n
inject p v = tabulate (flip lookup v ∘ < p >)
permute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) → Vec A n
permute p v = tabulate (flip lookup v ∘ < p >)
inject-correct : ∀ {a n m} {A : Set a} → (p : Inj n m) → (v : Vec A m) →
v ⋟ inject p v ÷ p
inject-correct p v = lookup∘tabulate (flip lookup v ∘ < p >)
permute-correct : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →
v ⋟ permute p v ÷ p
permute-correct p v = lookup∘tabulate (flip lookup v ∘ < p >)
Permute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →
∃ (v ⋟_÷ p)
Permute p v = permute p v , permute-correct p v
_⋟_÷? : ∀ {a m n} {A : Set a} → Vec A n → Vec A m → Set a
_⋟_÷? x px = ∃ (x ⋟ px ÷_)
∈-allInj : ∀ {n m} (i : Inj n m) → i ∈ allInj n m
∈-allInj {zero} [] = here
∈-allInj {suc n} (i ∷ is) = ∈-map₂ _∷_ (∈-allFin i) (∈-allInj is)
tabulate₂ : ∀ {n m a} {A : Set a} → (Inj n m → A) → Vec A (size n m)
tabulate₂ f = mapV f (allInj _ _)
∈-tabulate₂ : ∀ {n m a} {A : Set a} (f : Inj n m → A) i → f i ∈ tabulate₂ f
∈-tabulate₂ f i = ∈-map f (∈-allInj i)
ENUM₂ : ∀ {a n} {A : Set a} → (v : Vec A n) → Vec (∃ (v ⋟_÷?)) (size n n)
ENUM₂ v = tabulate₂ (λ p → permute p v , p , permute-correct p v)
enumᵢ : ∀ {a n m} {A : Set a} → Vec A m → Vec (Vec A n) (size n m)
enumᵢ v = tabulate₂ (flip inject v)
enum₂ : ∀ {a n} {A : Set a} → Vec A n → Vec (Vec A n) (size n n)
enum₂ v = tabulate₂ (flip permute v)
enumᵢ-sound : ∀ {a} {A : Set a} {n m} (x : Vec A m) (px : Vec A n) → px ∈ enumᵢ x → x ⋟ px ÷?
enumᵢ-sound x _ px∈enum₂x with map-∈ px∈enum₂x
enumᵢ-sound x _ _ | p , refl = p , inject-correct p x
enum₂-sound : ∀ {a} {A : Set a} {n} (x px : Vec A n) → px ∈ enum₂ x → x ⋟ px ÷?
enum₂-sound x _ px∈enum₂x with map-∈ px∈enum₂x
enum₂-sound x _ _ | p , refl = p , permute-correct p x
remove-÷-zero : ∀ {n a} {A : Set a} {x : A} {xs : Vec A n} {px : A}
{pxs : Vec A n} {ps : Inj n n} →
(x ∷ xs) ⋟ px ∷ pxs ÷ (zero ∷ ps) →
xs ⋟ pxs ÷ ps
remove-÷-zero f i = f (suc i)
enumᵢ-complete : ∀ {a} {A : Set a} {n m} (x : Vec A m) (px : Vec A n) → x ⋟ px ÷? → px ∈ enumᵢ x
enumᵢ-complete x px (p , x⋟px÷p) = proof where
p∈allInj : p ∈ allInj _ _
p∈allInj = ∈-allInj p
permutepx∈enum₂x : inject p x ∈ enumᵢ x
permutepx∈enum₂x = ∈-map (flip inject x) p∈allInj
x⋟permutepx÷p : x ⋟ inject p x ÷ p
x⋟permutepx÷p = inject-correct p x
proof : px ∈ enumᵢ x
proof = subst (_∈ _) (injected-inj {p = p} x⋟permutepx÷p x⋟px÷p) permutepx∈enum₂x
enum₂-complete : ∀ {a} {A : Set a} {n} (x px : Vec A n) → x ⋟ px ÷? → px ∈ enum₂ x
enum₂-complete x px (p , x⋟px÷p) = proof where
p∈allInj : p ∈ allInj _ _
p∈allInj = ∈-allInj p
permutepx∈enum₂x : permute p x ∈ enum₂ x
permutepx∈enum₂x = ∈-map (flip permute x) p∈allInj
x⋟permutepx÷p : x ⋟ permute p x ÷ p
x⋟permutepx÷p = permute-correct p x
proof : px ∈ enum₂ x
proof = subst (_∈ _) (permuted-inj {p = p} x⋟permutepx÷p x⋟px÷p) permutepx∈enum₂x
Enum₂ : ∀ {a n} {A : Set a} → (x : Vec A n) → Σ[ pxs ∈ Vec (Vec A n) (size n n) ] (∀ px → (px ∈ pxs → x ⋟ px ÷?) × (x ⋟ px ÷? → px ∈ pxs))
Enum₂ x = enum₂ x , (λ px → enum₂-sound x px , enum₂-complete x px)
_∃⊎∀_ : ∀ {a} {A : Set a} {l r} (L : A → Set l) (R : A → Set r) {p} (P : A → Set p) → Set _
(L ∃⊎∀ R) P = (∃ λ x → P x × L x) ⊎ (∀ x → P x → R x)
open import Agda.Primitive
stepDecide∃⊎∀ : ∀ {a} {A : Set a} {l r} {L : A → Set l} {R : A → Set r} → (∀ y → L y ⊎ R y) → ∀ {p} (P : A → Set p) →
∀ {d} (done : Vec A d) {nd} (not-done : Vec A nd) →
(∀ y → y ∈ done ⊎ y ∈ not-done → P y) →
(∀ y → P y → y ∈ done ⊎ y ∈ not-done) →
(∀ y → y ∈ done → R y) →
(L ∃⊎∀ R) P
stepDecide∃⊎∀ dec P done {zero} not-done dnd-sound dnd-complete done-R = inj₂ (λ y Py → done-R y (dnd-done y Py)) where
dnd-done : ∀ y → P y → y ∈ done
dnd-done y Py with dnd-complete y Py
dnd-done y Py | inj₁ y∈done = y∈done
dnd-done y Py | inj₂ ()
stepDecide∃⊎∀ dec P done {suc nd} (step ∷ not-dones) dnd-sound dnd-complete done-R with dec step
… | inj₁ l = inj₁ (step , (dnd-sound step (inj₂ here)) , l)
… | inj₂ r = stepDecide∃⊎∀ dec P (step ∷ done) not-dones stepdnd-sound stepdnd-complete (stepdone-R r) where
stepdnd-sound : ∀ y → y ∈ step ∷ done ⊎ y ∈ not-dones → P y
stepdnd-sound _ (inj₁ here) = dnd-sound step (inj₂ here)
stepdnd-sound y (inj₁ (there y∈done)) = dnd-sound y (inj₁ y∈done)
stepdnd-sound y (inj₂ y∈not-dones) = dnd-sound y (inj₂ (there y∈not-dones))
stepdnd-complete : ∀ y → P y → y ∈ step ∷ done ⊎ y ∈ not-dones
stepdnd-complete y Py with dnd-complete y Py
stepdnd-complete y Py | inj₁ y∈done = inj₁ (there y∈done)
stepdnd-complete y Py | inj₂ here = inj₁ here
stepdnd-complete y Py | inj₂ (there y∈not-dones) = inj₂ y∈not-dones
stepdone-R : _ → ∀ y → y ∈ step ∷ done → _
stepdone-R Rstep _ here = Rstep
stepdone-R Rstep y (there y∈done) = done-R y y∈done
decide∃⊎∀ : ∀ {a} {A : Set a} {l r} {L : A → Set l} {R : A → Set r} → (∀ y → L y ⊎ R y) → ∀ {p} (P : A → Set p) →
∀ {nd} (not-done : Vec A nd) →
(∀ y → y ∈ not-done → P y) →
(∀ y → P y → y ∈ not-done) →
(L ∃⊎∀ R) P
decide∃⊎∀ dec P not-done nd-sound nd-complete = stepDecide∃⊎∀ dec P [] not-done []nd-sound []nd-complete (λ {_ ()}) where
[]nd-sound : ∀ y → y ∈ [] ⊎ y ∈ not-done → P y
[]nd-sound y (inj₁ ())
[]nd-sound y (inj₂ y∈not-done) = nd-sound y y∈not-done
[]nd-complete : ∀ y → P y → y ∈ [] ⊎ y ∈ not-done
[]nd-complete y Py = inj₂ (nd-complete y Py)
decidePermutations : ∀ {a n} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ x → (∀ y → L y ⊎ R y) →
(L ∃⊎∀ R) (x ⋟_÷?)
decidePermutations x f = decide∃⊎∀ f _ (enum₂ x) (enum₂-sound x) (enum₂-complete x)
decideInjections : ∀ {a n m} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ (x : Vec A m) → (∀ y → L y ⊎ R y) →
(L ∃⊎∀ R) (x ⋟_÷?)
decideInjections x f = decide∃⊎∀ f _ (enumᵢ x) (enumᵢ-sound x) (enumᵢ-complete x)
-- -- sym-⋟∣ : ∀ {a n} {A : Set a} → (y x : Vec A n) → (p : Permutation n) →
-- -- y ⋟ x ∣ p → x ⋟ y ∣ (p ⁻¹)
-- -- sym-⋟∣ y x ps y⋟x∣p i =
-- -- trans (cong (flip lookup x) {x = i} {y = < ps > (< ps ⁻¹ > i)} (<>-inv ps i)) (sym (y⋟x∣p (< ps ⁻¹ > i)))
-- -- open import Oscar.Data.Vec.Properties
-- -- Permute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →
-- -- ∃ λ w → w ⋟ v ∥ p
-- -- Permute [] v = v , λ ()
-- -- Permute p@(p' ∷ ps) v@(v' ∷ vs) =
-- -- let ws , [vs≡ws]ps = Permute ps (deleteV p' v)
-- -- w = lookup p' v ∷ ws
-- -- [v≡w]p : w ⋟ v ∥ p
-- -- [v≡w]p = {!!}
-- -- {-
-- -- [v≡w]p = λ
-- -- { zero → here
-- -- ; (suc f) → there (subst (ws [ f ]=_)
-- -- (lookup-delete-thin p' (< ps > f) v)
-- -- ([vs≡ws]ps f)) }
-- -- -}
-- -- in
-- -- w , [v≡w]p
-- -- -- permute : ∀ {a n} {A : Set a} → Permutation n → Vec A n → Vec A n
-- -- -- permute p v = proj₁ (Permute p v)
-- -- -- permute-correct : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) → v ⋟ permute p v ∥ p
-- -- -- permute-correct p v = proj₂ (Permute p v)
-- -- -- open import Function
-- -- -- --∈-map-proj₁ : mapV proj₁ (mapV (λ p → F p , G p) xs) ≡ mapV F xs
-- -- -- open import Data.Nat
-- -- -- ∈-enum : ∀ {n m} (i : Inj n m) → i ∈ enum n m
-- -- -- ∈-enum {zero} [] = here
-- -- -- ∈-enum {suc n} (i ∷ is) = ∈-map₂ _∷_ (∈-allFin i) (∈-enum is)
-- -- -- open import Data.Permutation.Properties
-- -- -- [thin]=→delete[]= : ∀ {a n} {A : Set a} {i j} {v : Vec A (suc n)} {x} → v [ thin i j ]= x → deleteV i v [ j ]= x
-- -- -- [thin]=→delete[]= {i = zero} {v = x ∷ v} (there x₂) = x₂
-- -- -- [thin]=→delete[]= {n = zero} {i = suc ()} x₁
-- -- -- [thin]=→delete[]= {n = suc n} {i = suc i} {zero} {x ∷ v} here = here
-- -- -- [thin]=→delete[]= {n = suc n} {i = suc i} {suc j} {x ∷ v} (there v[thinij]=?) = there ([thin]=→delete[]= {i = i} v[thinij]=?)
-- -- -- delete≡Permutation : ∀ {a n} {A : Set a} {v₀ : A} {v₊ : Vec A n} {w : Vec A (suc n)} {p : Permutation (suc n)} →
-- -- -- (v₀ ∷ v₊) ⋟ w ∥ p →
-- -- -- v₊ ⋟ deleteV (annihilator p) w ∥ delete (annihilator p) p
-- -- -- delete≡Permutation {v₀ = v₀} {v₊} {w} {p} [v₀∷v₊≡w]p f = [thin]=→delete[]= {i = annihilator p} {j = f} qux where
-- -- -- foo : thin (< p > (annihilator p)) (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)
-- -- -- foo = inj-thin p (annihilator p) f
-- -- -- foo2 : suc (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)
-- -- -- foo2 = subst (λ y → thin y (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)) (ann-correct p) foo
-- -- -- bar : w [ thin (annihilator p) f ]= lookup (< p > (thin (annihilator p) f)) (v₀ ∷ v₊)
-- -- -- bar = [v₀∷v₊≡w]p (thin (annihilator p) f)
-- -- -- qux : w [ thin (annihilator p) f ]= lookup (< delete (annihilator p) p > f) v₊
-- -- -- qux = subst (λ y → w [ thin (annihilator p) f ]= lookup y (v₀ ∷ v₊)) (sym foo2) bar
-- -- -- permute-complete-step : ∀ {a n} {A : Set a} {v₀ : A} {w : Vec A (suc n)} {v₊ : Vec A n} (x : Fin (suc n)) →
-- -- -- w [ x ]= v₀ →
-- -- -- deleteV x w ∈ mapV (flip permute v₊) (enum n n) →
-- -- -- w ∈ mapV (flip permute (v₀ ∷ v₊)) (enum (suc n) (suc n))
-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} zero here here = here
-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} zero x₁ (there ())
-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} (suc ()) x₁ x₂
-- -- -- permute-complete-step {n = suc n} {w = w ∷ ws} x w∷ws[x]=v₀ x₂ = {!!}
-- -- -- permute-lemma : ∀ {a n} {A : Set a} (v w : Vec A n) (p : Permutation n) →
-- -- -- v ⋟ w ∥ p →
-- -- -- w ≡ permute (p ⁻¹) v
-- -- -- permute-lemma v w p x = {!permute-correct p w!}
-- -- -- {-
-- -- -- permute-complete' : ∀ {a n} {A : Set a} (v w : Vec A n) (p : Permutation n) →
-- -- -- v ⋟ w ∥ p →
-- -- -- ∀ {m} {ps : Vec (Permutation n) m} → p ∈ ps →
-- -- -- w ≡ permute p v
-- -- -- w ∈ mapV (flip
-- -- -- -}
-- -- -- permute-complete : ∀ {a n} {A : Set a} (v w : Vec A n) →
-- -- -- v ∃≡Permutation w →
-- -- -- w ∈ mapV (flip permute v) (enum n n)
-- -- -- permute-complete [] [] (p , [v≡w]p) = here
-- -- -- permute-complete {n = suc n} v@(v₀ ∷ v₊) w (p , [v≡w]p) = permute-complete-step (annihilator p) w[ap]=v₀ pc' where
-- -- -- w[ap]=v₀ : w [ annihilator p ]= v₀
-- -- -- w[ap]=v₀ = {![v≡w]p (annihilator p)!}
-- -- -- pc' : deleteV (annihilator p) w ∈ mapV (flip permute v₊) (enum n n)
-- -- -- pc' = permute-complete v₊ (deleteV (annihilator p) w) (delete (annihilator p) p , delete≡Permutation {p = p} [v≡w]p)
-- -- -- EnumPermutations : ∀ {a n} {A : Set a} → (v : Vec A n) →
-- -- -- Σ (Vec (∃ (v ∃≡Permutation_)) (size n n)) λ ws
-- -- -- → ∀ w → (v ∃≡Permutation w → w ∈ mapV proj₁ ws)
-- -- -- EnumPermutations {n = n} v = mapV (λ p → permute p v , p , permute-correct p v) (enum n n) , (λ w v∃≡Pw → subst (w ∈_) (map-∘ proj₁ (λ p → permute p v , p , permute-correct p v) (enum n n)) (permute-complete v w v∃≡Pw))
-- -- -- enumPermutations : ∀ {a n} {A : Set a} → Vec A n → Vec (Vec A n) (size n n)
-- -- -- enumPermutations {n = n} xs = mapV (λ p → permute p xs) (enum n n)
-- -- -- tryPermutations : ∀ {a n} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ x → (f : ∀ y → L y ⊎ R y) → Vec (∃ λ y → x ∃≡Permutation y × L y ⊎ R y) (size n n)
-- -- -- tryPermutations x f = mapV (λ x₁ → x₁ , {!!}) (enumPermutations x)
|
{
"alphanum_fraction": 0.5015330705,
"avg_line_length": 46.4338983051,
"ext": "agda",
"hexsha": "0e9b90e1cff47752e8d5e3241056316a6623cde0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Data/Permutation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Data/Permutation.agda",
"max_line_length": 228,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Data/Permutation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6038,
"size": 13698
}
|
module Type.Quotient where
open import Logic
open import Relator.Equals
open import Type
open import Lvl
private variable ℓ₁ : Lvl.Level
private variable ℓ₂ : Lvl.Level
data _/_ (T : Type{ℓ₁}) (_≅_ : T → T → Stmt{ℓ₂}) : Type{ℓ₁ Lvl.⊔ ℓ₂} where
[_] : T → (T / (_≅_))
[/]-equiv-to-eq : ∀{x y : T} → (x ≅ y) → ([ x ] ≡ [ y ])
[/]-uip : ∀{X Y : (T / (_≅_))} → (proof₁ proof₂ : (X ≡ Y)) → (proof₁ ≡ proof₂)
-- TODO: [/]-eq-to-equiv : (x y : A) → (x ≅ y) ← ([ x ] ≡ [ y ])
|
{
"alphanum_fraction": 0.525,
"avg_line_length": 28.2352941176,
"ext": "agda",
"hexsha": "fdc8e6d10f86b9a195ec450754a3821f7a4f3565",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Mathematical/Type/Quotient.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Mathematical/Type/Quotient.agda",
"max_line_length": 80,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Mathematical/Type/Quotient.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 211,
"size": 480
}
|
module Issue292-27 where
postulate A : Set
data D : Set → Set where
d₁ : D A
d₂ : D (A → A)
data P : (B : Set) → B → D B → Set₁ where
p₁ : (x : A) → P A x d₁
p₂ : (f : A → A) → P (A → A) f d₂
Foo : (x : A) → P A x d₁ → Set₁
Foo x (p₁ .x) = Set
-- Cannot decide whether there should be a case for the constructor
-- p₂, since the unification gets stuck on unifying the inferred
-- indices
-- [A → A, f, d₂]
-- with the expected indices
-- [A, x, d₁]
-- when checking the definition of Foo
|
{
"alphanum_fraction": 0.5755813953,
"avg_line_length": 21.5,
"ext": "agda",
"hexsha": "877df5443c75707d475db564ec36b2b4168c58cd",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue292-27.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue292-27.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue292-27.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 193,
"size": 516
}
|
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.FromList where
open import Prelude
open import Algebra.Construct.Free.Semilattice.Definition
open import Algebra.Construct.Free.Semilattice.Eliminators
open import Algebra.Construct.Free.Semilattice.Relation.Unary
open import Data.List
import Data.List.Membership as ℰ
open import Data.Fin using (Fin; fs; f0)
open import HITs.PropositionalTruncation.Sugar
open import HITs.PropositionalTruncation.Properties
fromList : List A → 𝒦 A
fromList = foldr _∷_ []
∈List⇒∈𝒦 : ∀ xs {x : A} → ∥ x ℰ.∈ xs ∥ → x ∈ fromList xs
∈List⇒∈𝒦 [] ∣x∈xs∣ = ⊥-elim (refute-trunc (λ ()) ∣x∈xs∣)
∈List⇒∈𝒦 (x ∷ xs) ∣x∈xs∣ = do
(fs n , x∈xs) ← ∣x∈xs∣
where (f0 , x∈xs) → ∣ inl x∈xs ∣
∣ inr (∈List⇒∈𝒦 xs ∣ n , x∈xs ∣) ∣
|
{
"alphanum_fraction": 0.6906290116,
"avg_line_length": 32.4583333333,
"ext": "agda",
"hexsha": "2ebbccc32e64debc1c9e60087cdec51fcf3d12fc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice/FromList.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Algebra/Construct/Free/Semilattice/FromList.agda",
"max_line_length": 61,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Algebra/Construct/Free/Semilattice/FromList.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 325,
"size": 779
}
|
------------------------------------------------------------------------
-- Integers
------------------------------------------------------------------------
-- This module contains some basic definitions with few dependencies
-- (in particular, not Groupoid). See Integer for more definitions.
-- The definitions below are reexported from Integer.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Integer.Basics
{c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where
open Derived-definitions-and-properties eq
import Agda.Builtin.Int
open import Prelude renaming (_+_ to _⊕_)
open import Equality.Decidable-UIP eq
import Nat eq as Nat
-- Integers.
open Agda.Builtin.Int public
using ()
hiding (module Int)
renaming (Int to ℤ; pos to +_; negsuc to -[1+_])
module ℤ where
open Agda.Builtin.Int.Int public
using ()
renaming (pos to +_; negsuc to -[1+_])
private
variable
m n : ℕ
-- Turns natural numbers into the corresponding negative integers.
-[_] : ℕ → ℤ
-[ zero ] = + 0
-[ suc n ] = -[1+ n ]
-- Negation.
infix 8 -_
-_ : ℤ → ℤ
- + n = -[ n ]
- -[1+ n ] = + suc n
-- A helper function used to implement addition.
+_+-[1+_] : ℕ → ℕ → ℤ
+ m +-[1+ n ] =
if m Nat.<= n then -[1+ n ∸ m ] else + (m ∸ suc n)
private
-- An alternative implementation of +_+-[1+_].
+_+-[1+_]′ : ℕ → ℕ → ℤ
+ zero +-[1+ n ]′ = -[1+ n ]
+ suc m +-[1+ zero ]′ = + m
+ suc m +-[1+ suc n ]′ = + m +-[1+ n ]′
-- The alternative implementation of +_+-[1+_] is not optimised (it
-- does not use builtin functions), but it computes in the same way
-- as +_+-[1+_].
++-[1+]≡++-[1+]′ : ∀ m n → + m +-[1+ n ] ≡ + m +-[1+ n ]′
++-[1+]≡++-[1+]′ zero n = refl _
++-[1+]≡++-[1+]′ (suc m) zero = refl _
++-[1+]≡++-[1+]′ (suc m) (suc n) = ++-[1+]≡++-[1+]′ m n
-- Addition.
infixl 6 _+_
_+_ : ℤ → ℤ → ℤ
+ m + + n = + (m ⊕ n)
+ m + -[1+ n ] = + m +-[1+ n ]
-[1+ m ] + + n = + n +-[1+ m ]
-[1+ m ] + -[1+ n ] = -[1+ suc m ⊕ n ]
-- Subtraction.
infixl 6 _-_
_-_ : ℤ → ℤ → ℤ
i - j = i + - j
-- The +_ constructor is cancellative.
+-cancellative : + m ≡ + n → m ≡ n
+-cancellative = cong f
where
f : ℤ → ℕ
f (+ n) = n
f -[1+ n ] = n
-- The -[1+_] constructor is cancellative.
-[1+]-cancellative : -[1+ m ] ≡ -[1+ n ] → m ≡ n
-[1+]-cancellative = cong f
where
f : ℤ → ℕ
f (+ n) = n
f -[1+ n ] = n
-- Non-negative integers are not equal to negative integers.
+≢-[1+] : + m ≢ -[1+ n ]
+≢-[1+] +≡- = subst P +≡- tt
where
P : ℤ → Type
P (+ n) = ⊤
P -[1+ n ] = ⊥
-- Non-positive integers are not equal to positive integers.
+[1+]≢- : + suc m ≢ -[ n ]
+[1+]≢- {n = zero} = Nat.0≢+ ∘ sym ∘ +-cancellative
+[1+]≢- {n = suc _} = +≢-[1+]
-- Equality of integers is decidable.
infix 4 _≟_
_≟_ : Decidable-equality ℤ
+ m ≟ + n = ⊎-map (cong (+_)) (_∘ +-cancellative) (m Nat.≟ n)
+ m ≟ -[1+ n ] = no +≢-[1+]
-[1+ m ] ≟ + n = no (+≢-[1+] ∘ sym)
-[1+ m ] ≟ -[1+ n ] = ⊎-map (cong -[1+_]) (_∘ -[1+]-cancellative)
(m Nat.≟ n)
-- The integers form a set.
ℤ-set : Is-set ℤ
ℤ-set = decidable⇒set _≟_
-- Addition is commutative.
+-comm : ∀ i {j} → i + j ≡ j + i
+-comm (+ m) {j = + _} = cong (+_) $ Nat.+-comm m
+-comm (+ m) {j = -[1+ _ ]} = refl _
+-comm -[1+ m ] {j = + _} = refl _
+-comm -[1+ m ] {j = -[1+ _ ]} = cong (-[1+_] ∘ suc) $ Nat.+-comm m
|
{
"alphanum_fraction": 0.4735766423,
"avg_line_length": 22.5328947368,
"ext": "agda",
"hexsha": "afd8e5521271f7d43996283561b959048ff4c502",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Integer/Basics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Integer/Basics.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Integer/Basics.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 1343,
"size": 3425
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Categories.Limits.RightKan where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
open import Cubical.Categories.Morphism renaming (isIso to isIsoC)
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open import Cubical.Categories.Limits.Limits
module _ {ℓC ℓC' ℓM ℓM' ℓA ℓA' : Level}
{C : Category ℓC ℓC'}
{M : Category ℓM ℓM'}
{A : Category ℓA ℓA'}
(limitA : Limits {ℓ-max ℓC' ℓM} {ℓ-max ℓC' ℓM'} A)
(K : Functor M C)
(T : Functor M A)
where
open Category
open Functor
open Cone
open LimCone
_↓Diag : ob C → Category (ℓ-max ℓC' ℓM) (ℓ-max ℓC' ℓM')
ob (x ↓Diag) = Σ[ u ∈ ob M ] C [ x , K .F-ob u ]
Hom[_,_] (x ↓Diag) (u , f) (v , g) = Σ[ h ∈ M [ u , v ] ] f ⋆⟨ C ⟩ K .F-hom h ≡ g
id (x ↓Diag) {x = (u , f)} = id M , cong (seq' C f) (F-id K) ∙ ⋆IdR C f
_⋆_ (x ↓Diag) {x = (u , f)} (h , hComm) (k , kComm) = (h ⋆⟨ M ⟩ k)
, cong (seq' C f) (F-seq K h k)
∙ sym (⋆Assoc C _ _ _)
∙ cong (λ l → seq' C l (F-hom K k)) hComm
∙ kComm
⋆IdL (x ↓Diag) _ = Σ≡Prop (λ _ → isSetHom C _ _) (⋆IdL M _)
⋆IdR (x ↓Diag) _ = Σ≡Prop (λ _ → isSetHom C _ _) (⋆IdR M _)
⋆Assoc (x ↓Diag) _ _ _ = Σ≡Prop (λ _ → isSetHom C _ _) (⋆Assoc M _ _ _)
isSetHom (x ↓Diag) = isSetΣSndProp (isSetHom M) λ _ → isSetHom C _ _
private
i : (x : ob C) → Functor (x ↓Diag) M
F-ob (i x) = fst
F-hom (i x) = fst
F-id (i x) = refl
F-seq (i x) _ _ = refl
j : {x y : ob C} (f : C [ x , y ]) → Functor (y ↓Diag) (x ↓Diag)
F-ob (j f) (u , g) = u , f ⋆⟨ C ⟩ g
F-hom (j f) (h , hComm) = h , ⋆Assoc C _ _ _ ∙ cong (seq' C f) hComm
F-id (j f) = Σ≡Prop (λ _ → isSetHom C _ _) refl
F-seq (j f) _ _ = Σ≡Prop (λ _ → isSetHom C _ _) refl
T* : (x : ob C) → Functor (x ↓Diag) A
T* x = funcComp T (i x)
RanOb : ob C → ob A
RanOb x = limitA (x ↓Diag) (T* x) .lim
RanCone : {x y : ob C} → C [ x , y ] → Cone (T* y) (RanOb x)
coneOut (RanCone {x = x} f) v = limOut (limitA (x ↓Diag) (T* x)) (j f .F-ob v)
coneOutCommutes (RanCone {x = x} f) h = limOutCommutes (limitA (x ↓Diag) (T* x)) (j f .F-hom h)
-- technical lemmas for proving functoriality
RanConeRefl : ∀ {x} v →
limOut (limitA (x ↓Diag) (T* x)) v
≡ limOut (limitA (x ↓Diag) (T* x)) (j (id C) .F-ob v)
RanConeRefl {x = x} (v , f) =
cong (λ p → limOut (limitA (x ↓Diag) (T* x)) (v , p)) (sym (⋆IdL C f))
RanConeTrans : ∀ {x y z} (f : C [ x , y ]) (g : C [ y , z ]) v →
limOut (limitA (x ↓Diag) (T* x)) (j f .F-ob (j g .F-ob v))
≡ limOut (limitA (x ↓Diag) (T* x)) (j (f ⋆⟨ C ⟩ g) .F-ob v)
RanConeTrans {x = x} {y = y} {z = z} f g (v , h) =
cong (λ p → limOut (limitA (x ↓Diag) (T* x)) (v , p)) (sym (⋆Assoc C f g h))
-- the right Kan-extension
Ran : Functor C A
F-ob Ran = RanOb
F-hom Ran {y = y} f = limArrow (limitA (y ↓Diag) (T* y)) _ (RanCone f)
F-id Ran {x = x} =
limArrowUnique (limitA (x ↓Diag) (T* x)) _ _ _ (λ v → (⋆IdL A _) ∙ RanConeRefl v)
F-seq Ran {x = x} {y = y} {z = z} f g =
limArrowUnique (limitA (z ↓Diag) (T* z)) _ _ _ path
where
path : ∀ v →
(F-hom Ran f) ⋆⟨ A ⟩ (F-hom Ran g) ⋆⟨ A ⟩ (limOut (limitA (z ↓Diag) (T* z)) v)
≡ coneOut (RanCone (f ⋆⟨ C ⟩ g)) v
path v = (F-hom Ran f) ⋆⟨ A ⟩ (F-hom Ran g) ⋆⟨ A ⟩ (limOut (limitA (z ↓Diag) (T* z)) v)
≡⟨ ⋆Assoc A _ _ _ ⟩
(F-hom Ran f) ⋆⟨ A ⟩ ((F-hom Ran g) ⋆⟨ A ⟩ (limOut (limitA (z ↓Diag) (T* z)) v))
≡⟨ cong (seq' A (F-hom Ran f)) (limArrowCommutes _ _ _ _) ⟩
(F-hom Ran f) ⋆⟨ A ⟩ limOut (limitA (y ↓Diag) (T* y)) (j g .F-ob v)
≡⟨ limArrowCommutes _ _ _ _ ⟩
limOut (limitA (x ↓Diag) (T* x)) (j f .F-ob (j g .F-ob v))
≡⟨ RanConeTrans f g v ⟩
coneOut (RanCone (f ⋆⟨ C ⟩ g)) v ∎
open NatTrans
RanNatTrans : NatTrans (funcComp Ran K) T
N-ob RanNatTrans u = coneOut (RanCone (id C)) (u , id C)
N-hom RanNatTrans {x = u} {y = v} f =
Ran .F-hom (K .F-hom f) ⋆⟨ A ⟩ coneOut (RanCone (id C)) (v , id C)
≡⟨ cong (λ g → Ran .F-hom (K .F-hom f) ⋆⟨ A ⟩ g) (sym (RanConeRefl (v , id C))) ⟩
Ran .F-hom (K .F-hom f) ⋆⟨ A ⟩ limOut (limitA ((K .F-ob v) ↓Diag) (T* (K .F-ob v))) (v , id C)
≡⟨ limArrowCommutes _ _ _ _ ⟩
coneOut (RanCone (K .F-hom f)) (v , id C)
≡⟨ cong (λ g → limOut (limitA ((K .F-ob u) ↓Diag) (T* (K .F-ob u))) (v , g))
(⋆IdR C (K .F-hom f) ∙ sym (⋆IdL C (K .F-hom f))) ⟩
coneOut (RanCone (id C)) (v , K .F-hom f)
≡⟨ sym (coneOutCommutes (RanCone (id C)) (f , ⋆IdL C _)) ⟩
coneOut (RanCone (id C)) (u , id C) ⋆⟨ A ⟩ T .F-hom f ∎
-- TODO: show that this nat. trans. is a "universal arrow" and that is a nat. iso.
-- if K is full and faithful...
|
{
"alphanum_fraction": 0.5020095694,
"avg_line_length": 41.1417322835,
"ext": "agda",
"hexsha": "7dd85972e3e866fe6252b5b46e3110ee7aac3248",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Categories/Limits/RightKan.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Categories/Limits/RightKan.agda",
"max_line_length": 99,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Categories/Limits/RightKan.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 2296,
"size": 5225
}
|
-- Andreas, 2012-09-13
module RelevanceSubtyping where
-- this naturally type-checks:
one : {A B : Set} → (.A → B) → A → B
one f x = f x
-- this type-checks because of subtyping
one' : {A B : Set} → (.A → B) → A → B
one' f = f
|
{
"alphanum_fraction": 0.5895196507,
"avg_line_length": 20.8181818182,
"ext": "agda",
"hexsha": "1c3260ba57cb4256532dcd6fbd8b2d5d24d55e2b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/RelevanceSubtyping.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/RelevanceSubtyping.agda",
"max_line_length": 40,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/RelevanceSubtyping.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 87,
"size": 229
}
|
-- also importing warnings from A
import A
|
{
"alphanum_fraction": 0.75,
"avg_line_length": 11,
"ext": "agda",
"hexsha": "21bf38678c83efeff1e9340db8e84f4239ab967b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue2592/C.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue2592/C.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue2592/C.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 10,
"size": 44
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.S1.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1.Base
open import Cubical.HITs.PropositionalTruncation as PropTrunc
isConnectedS¹ : (s : S¹) → ∥ base ≡ s ∥
isConnectedS¹ base = ∣ refl ∣
isConnectedS¹ (loop i) =
squash ∣ (λ j → loop (i ∧ j)) ∣ ∣ (λ j → loop (i ∨ ~ j)) ∣ i
isGroupoidS¹ : isGroupoid S¹
isGroupoidS¹ s t =
PropTrunc.rec isPropIsSet
(λ p →
subst (λ s → isSet (s ≡ t)) p
(PropTrunc.rec isPropIsSet
(λ q → subst (λ t → isSet (base ≡ t)) q isSetΩS¹)
(isConnectedS¹ t)))
(isConnectedS¹ s)
toPropElim : ∀ {ℓ} {B : S¹ → Type ℓ} → ((s : S¹) → isProp (B s)) → B base → (s : S¹) → B s
toPropElim {B = B} isprop b base = b
toPropElim {B = B} isprop b (loop i) = hcomp (λ k → λ {(i = i0) → b
; (i = i1) → isprop base (subst B (loop) b) b k})
(transp (λ j → B (loop (i ∧ j))) (~ i) b)
|
{
"alphanum_fraction": 0.6004803843,
"avg_line_length": 35.6857142857,
"ext": "agda",
"hexsha": "c5c56ceae337d70b405a575d3a6bf46538fab515",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/HITs/S1/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/HITs/S1/Properties.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/HITs/S1/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 436,
"size": 1249
}
|
{-# OPTIONS --safe #-}
open import Data.List as List hiding ([_])
module JVM.Compiler.Monad (T : Set) (⟨_⇒_⟩ : T → T → List T → Set) (nop : ∀ {τ} → ⟨ τ ⇒ τ ⟩ []) where
open import Level
open import Function using (_∘_)
open import Data.Product hiding (_<*>_)
open import Relation.Unary
open import Relation.Unary.PredicateTransformer using (Pt)
open import Relation.Binary.PropositionalEquality using (refl)
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Monad
open import Relation.Ternary.Data.ReflexiveTransitive as Star
open import Relation.Ternary.Data.Bigplus as Bigplus
private
variable
τ₁ τ₂ τ : T
open import JVM.Model T; open Syntax
open import JVM.Syntax.Bytecode T ⟨_⇒_⟩
open import Relation.Ternary.Monad.Writer intf-rel
open WriterMonad (starMonoid {R = Code}) renaming
( Writer to Compiler
; execWriter to execCompiler)
public
-- Output a single, unlabeled instruction
code : ∀[ ⟨ τ₁ ⇒ τ₂ ⟩ ⇒ Down⁻ (Compiler τ₁ τ₂ Emp) ]
code i = tell Star.[ instr (↓ i) ]
-- We can label the start of a compiler computation
attachTo : ∀ {P} → ∀[ Up (One τ₁) ⇒ Compiler τ₁ τ₂ P ─✴ Compiler τ₁ τ₂ P ]
attachTo l = censor (label-start nop ⦇ Bigplus.[ l ] ⦈)
attach : ∀[ Up (One τ₁) ⇒ Compiler τ₁ τ₁ Emp ]
attach l = attachTo l ⟨ ∙-idʳ ⟩ return refl
-- Creating binders is pure in the model by means of hiding
freshLabel : ∀ {ψ} → ε[ Compiler τ τ (Up (Own List.[ ψ ]) ✴ Down (Own List.[ ψ ])) ]
freshLabel = return balance
|
{
"alphanum_fraction": 0.7045454545,
"avg_line_length": 33.2444444444,
"ext": "agda",
"hexsha": "625a2d6e8ef5f90ea6e201d9e88a781ec79c8d9c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/JVM/Compiler/Monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/JVM/Compiler/Monad.agda",
"max_line_length": 101,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/JVM/Compiler/Monad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 448,
"size": 1496
}
|
open import MLib.Prelude.FromStdlib
module MLib.Prelude.TransitiveProver {a p} {A : Set a} (_⇒_ : A → A → Set p) (trans : Transitive _⇒_) where
import MLib.Prelude.DFS as DFS
open import MLib.Prelude.Path
open List using ([]; _∷_)
open import Relation.Nullary using (yes; no)
open import Relation.Binary using (Decidable; IsStrictTotalOrder)
import Data.AVL as AVL
Database : Set (a ⊔ˡ p)
Database = List (∃₂ λ x y → x ⇒ y)
module Search {r} {_<_ : Rel A r} (isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_) where
private
module DFS′ = DFS _⇒_ isStrictTotalOrder
open DFS′
open DFS′ public using (Graph)
open IsStrictTotalOrder isStrictTotalOrder using (_≟_)
private
module Tree = AVL isStrictTotalOrder
open Tree using (Tree)
mkGraph : Database → Graph
mkGraph [] = Tree.empty
mkGraph ((x , y , p) ∷ ps) = Tree.insertWith x ((y , p) ∷ []) List._++_ (mkGraph ps)
private
findPath : Graph → ∀ x y → Maybe (Path _⇒_ x y)
findPath gr x y = findDest gr {y} (λ v → v ≟ y) x
tryProve′ : Graph → ∀ x y → Maybe (x ⇒ y)
tryProve′ gr x y = findPath gr x y >>=ₘ just ∘ transPath trans
findTransTargets′ : Graph → ∀ x → List (∃ λ y → x ⇒ y)
findTransTargets′ gr x = allTargetsFrom gr x >>=ₗ λ {(y , c) → return (y , transPath trans c)}
tryProve : Database → ∀ x y → Maybe (x ⇒ y)
tryProve = tryProve′ ∘ mkGraph
findTransTargets : Database → ∀ x → List (∃ λ y → x ⇒ y)
findTransTargets = findTransTargets′ ∘ mkGraph
|
{
"alphanum_fraction": 0.6542119565,
"avg_line_length": 30.0408163265,
"ext": "agda",
"hexsha": "b51be75a7a44fcd1a15db0e55bbead3d18422e9e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Prelude/TransitiveProver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Prelude/TransitiveProver.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Prelude/TransitiveProver.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 500,
"size": 1472
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The unit type and the total relation on unit
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Unit.Base where
------------------------------------------------------------------------
-- A unit type defined as a record type
-- Note that the name of this type is "\top", not T.
open import Agda.Builtin.Unit public using (⊤; tt)
record _≤_ (x y : ⊤) : Set where
|
{
"alphanum_fraction": 0.4018348624,
"avg_line_length": 28.6842105263,
"ext": "agda",
"hexsha": "1e7d2986664a627f370e5122c773cf31b5a2b717",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Unit/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Unit/Base.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Unit/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 96,
"size": 545
}
|
------------------------------------------------------------------------------
-- Agda-Prop Library.
-- Properties.
------------------------------------------------------------------------------
open import Data.Nat using ( ℕ )
module Data.PropFormula.Properties ( n : ℕ ) where
------------------------------------------------------------------------------
open import Data.Bool.Base using ( Bool; false; true; not; T )
open import Data.Fin using ( Fin ; suc; zero )
open import Data.PropFormula.Syntax n
open import Data.PropFormula.Dec n
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; cong )
------------------------------------------------------------------------------
suc-injective : ∀ {o} {m n : Fin o} → Fin.suc m ≡ Fin.suc n → m ≡ n
suc-injective refl = refl
var-injective : ∀ {x x₁} → Var x ≡ Var x₁ → x ≡ x₁
var-injective refl = refl
∧-injective₁ : ∀ {φ φ₁ ψ ψ₁} → (φ ∧ φ₁) ≡ (ψ ∧ ψ₁) → φ ≡ ψ
∧-injective₁ refl = refl
∧-injective₂ : ∀ {φ φ₁ ψ ψ₁} → (φ ∧ φ₁) ≡ (ψ ∧ ψ₁) → φ₁ ≡ ψ₁
∧-injective₂ refl = refl
∨-injective₁ : ∀ {φ φ₁ ψ ψ₁} → (φ ∨ φ₁) ≡ (ψ ∨ ψ₁) → φ ≡ ψ
∨-injective₁ refl = refl
∨-injective₂ : ∀ {φ φ₁ ψ ψ₁} → (φ ∨ φ₁) ≡ (ψ ∨ ψ₁) → φ₁ ≡ ψ₁
∨-injective₂ refl = refl
⊃-injective₁ : ∀ {φ φ₁ ψ ψ₁} → (φ ⊃ φ₁) ≡ (ψ ⊃ ψ₁) → φ ≡ ψ
⊃-injective₁ refl = refl
⊃-injective₂ : ∀ {φ φ₁ ψ ψ₁} → (φ ⊃ φ₁) ≡ (ψ ⊃ ψ₁) → φ₁ ≡ ψ₁
⊃-injective₂ refl = refl
⇔-injective₁ : ∀ {φ φ₁ ψ ψ₁} → (φ ⇔ φ₁) ≡ (ψ ⇔ ψ₁) → φ ≡ ψ
⇔-injective₁ refl = refl
⇔-injective₂ : ∀ {φ φ₁ ψ ψ₁} → (φ ⇔ φ₁) ≡ (ψ ⇔ ψ₁) → φ₁ ≡ ψ₁
⇔-injective₂ refl = refl
¬-injective : ∀ {φ ψ} → ¬ φ ≡ ¬ ψ → φ ≡ ψ
¬-injective refl = refl
-- Def.
_≟_ : {n : ℕ} → Decidable {A = Fin n} _≡_
zero ≟ zero = yes refl
zero ≟ suc y = no λ()
suc x ≟ zero = no λ()
suc x ≟ suc y with x ≟ y
... | yes x≡y = yes (cong Fin.suc x≡y)
... | no x≢y = no (λ r → x≢y (suc-injective r))
-- Def.
eq : (φ ψ : PropFormula) → Dec (φ ≡ ψ)
-- Equality with Var.
eq (Var x) ⊤ = no λ()
eq (Var x) ⊥ = no λ()
eq (Var x) (ψ ∧ ψ₁) = no λ()
eq (Var x) (ψ ∨ ψ₁) = no λ()
eq (Var x) (ψ ⊃ ψ₁) = no λ()
eq (Var x) (ψ ⇔ ψ₁) = no λ()
eq (Var x) (¬ ψ) = no λ()
eq (Var x) (Var x₁) with x ≟ x₁
... | yes refl = yes refl
... | no x≢x₁ = no (λ r → x≢x₁ (var-injective r))
-- Equality with ⊤.
eq ⊤ (Var x) = no λ()
eq ⊤ ⊥ = no λ()
eq ⊤ (ψ ∧ ψ₁) = no λ()
eq ⊤ (ψ ∨ ψ₁) = no λ()
eq ⊤ (ψ ⊃ ψ₁) = no λ()
eq ⊤ (ψ ⇔ ψ₁) = no λ()
eq ⊤ (¬ ψ) = no λ()
eq ⊤ ⊤ = yes refl
-- Equality with ⊥.
eq ⊥ (Var x) = no λ()
eq ⊥ ⊤ = no λ()
eq ⊥ (ψ ∧ ψ₁) = no λ()
eq ⊥ (ψ ∨ ψ₁) = no λ()
eq ⊥ (ψ ⊃ ψ₁) = no λ()
eq ⊥ (ψ ⇔ ψ₁) = no λ()
eq ⊥ (¬ ψ) = no λ()
eq ⊥ ⊥ = yes refl
-- Equality with ∧.
eq (φ ∧ φ₁) (Var x) = no λ()
eq (φ ∧ φ₁) ⊤ = no λ()
eq (φ ∧ φ₁) ⊥ = no λ()
eq (φ ∧ φ₁) (ψ ∨ ψ₁) = no λ()
eq (φ ∧ φ₁) (ψ ⊃ ψ₁) = no λ()
eq (φ ∧ φ₁) (ψ ⇔ ψ₁) = no λ()
eq (φ ∧ φ₁) (¬ ψ) = no λ()
eq (φ ∧ φ₁) (ψ ∧ ψ₁) with eq φ ψ | eq φ₁ ψ₁
... | yes refl | yes refl = yes refl
... | yes _ | no φ₁≢ψ₁ = no (λ r → φ₁≢ψ₁ (∧-injective₂ r))
... | no φ≢ψ | _ = no (λ r → φ≢ψ (∧-injective₁ r))
-- Equality with ∨.
eq (φ ∨ φ₁) (Var x) = no λ()
eq (φ ∨ φ₁) ⊤ = no λ()
eq (φ ∨ φ₁) ⊥ = no λ()
eq (φ ∨ φ₁) (ψ ∧ ψ₁) = no λ()
eq (φ ∨ φ₁) (ψ ⊃ ψ₁) = no λ()
eq (φ ∨ φ₁) (ψ ⇔ ψ₁) = no λ()
eq (φ ∨ φ₁) (¬ ψ) = no λ()
eq (φ ∨ φ₁) (ψ ∨ ψ₁) with eq φ ψ | eq φ₁ ψ₁
... | yes refl | yes refl = yes refl
... | yes _ | no φ₁≢ψ₁ = no (λ r → φ₁≢ψ₁ (∨-injective₂ r))
... | no φ≢ψ | _ = no (λ r → φ≢ψ (∨-injective₁ r))
-- Equality with ⊃.
eq (φ ⊃ φ₁) (Var x) = no λ()
eq (φ ⊃ φ₁) ⊤ = no λ()
eq (φ ⊃ φ₁) ⊥ = no λ()
eq (φ ⊃ φ₁) (ψ ∧ ψ₁) = no λ()
eq (φ ⊃ φ₁) (ψ ∨ ψ₁) = no λ()
eq (φ ⊃ φ₁) (ψ ⇔ ψ₁) = no λ()
eq (φ ⊃ φ₁) (¬ ψ) = no λ()
eq (φ ⊃ φ₁) (ψ ⊃ ψ₁) with eq φ ψ | eq φ₁ ψ₁
... | yes refl | yes refl = yes refl
... | yes _ | no φ₁≢ψ₁ = no (λ r → φ₁≢ψ₁ (⊃-injective₂ r))
... | no φ≢ψ | _ = no (λ r → φ≢ψ (⊃-injective₁ r))
-- Equality with ⇔.
eq (φ ⇔ φ₁) (Var x) = no λ()
eq (φ ⇔ φ₁) ⊤ = no λ()
eq (φ ⇔ φ₁) ⊥ = no λ()
eq (φ ⇔ φ₁) (ψ ∧ ψ₁) = no λ()
eq (φ ⇔ φ₁) (ψ ∨ ψ₁) = no λ()
eq (φ ⇔ φ₁) (ψ ⊃ ψ₁) = no λ()
eq (φ ⇔ φ₁) (¬ ψ) = no λ()
eq (φ ⇔ φ₁) (ψ ⇔ ψ₁) with eq φ ψ | eq φ₁ ψ₁
... | yes refl | yes refl = yes refl
... | yes _ | no φ₁≢ψ₁ = no (λ r → φ₁≢ψ₁ (⇔-injective₂ r))
... | no φ≢ψ | _ = no (λ r → φ≢ψ (⇔-injective₁ r))
-- Equality with ¬.
eq (¬ φ) (Var x) = no λ()
eq (¬ φ) ⊤ = no λ()
eq (¬ φ) ⊥ = no λ()
eq (¬ φ) (ψ ∧ ψ₁) = no λ()
eq (¬ φ) (ψ ∨ ψ₁) = no λ()
eq (¬ φ) (ψ ⊃ ψ₁) = no λ()
eq (¬ φ) (ψ ⇔ ψ₁) = no λ()
eq (¬ φ) (¬ ψ) with eq φ ψ
... | yes refl = yes refl
... | no φ≢ψ = no (λ r → φ≢ψ (¬-injective r))
-- Theorem.
subst
: ∀ {Γ} {φ ψ}
→ φ ≡ ψ
→ Γ ⊢ φ
→ Γ ⊢ ψ
subst refl o = o
-- Theorem.
substΓ
: ∀ {Γ₁ Γ₂} {φ}
→ Γ₁ ≡ Γ₂
→ Γ₁ ⊢ φ
→ Γ₂ ⊢ φ
substΓ refl o = o
|
{
"alphanum_fraction": 0.4171497102,
"avg_line_length": 27.9497206704,
"ext": "agda",
"hexsha": "41b34ddffd9f4acb7c6215f0d2752e44803d2d0d",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2017-12-01T17:01:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-03-30T16:41:56.000Z",
"max_forks_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jonaprieto/agda-prop",
"max_forks_repo_path": "src/Data/PropFormula/Properties.agda",
"max_issues_count": 18,
"max_issues_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_issues_repo_issues_event_max_datetime": "2017-12-18T16:34:21.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-08T14:33:10.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jonaprieto/agda-prop",
"max_issues_repo_path": "src/Data/PropFormula/Properties.agda",
"max_line_length": 78,
"max_stars_count": 13,
"max_stars_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jonaprieto/agda-prop",
"max_stars_repo_path": "src/Data/PropFormula/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T03:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-01T16:45:41.000Z",
"num_tokens": 2430,
"size": 5003
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use `Algebra` or
-- `Algebra.Definitions` instead.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core using (Rel)
module Algebra.FunctionProperties {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
{-# WARNING_ON_IMPORT
"Algebra.FunctionProperties was deprecated in v1.2.
Use Algebra.Definitions instead."
#-}
open import Algebra.Core public
open import Algebra.Definitions _≈_ public
|
{
"alphanum_fraction": 0.5604575163,
"avg_line_length": 29.1428571429,
"ext": "agda",
"hexsha": "0e0b30442d3498a0d2177ebb8aa17e203e178a2e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/FunctionProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/FunctionProperties.agda",
"max_line_length": 73,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/FunctionProperties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 127,
"size": 612
}
|
{-# OPTIONS --type-in-type #-}
module Lec6 where
open import Lec1Done
ListF : Set -> Set -> Set
ListF X T = One + (X * T)
data List (X : Set) : Set where
<_> : (ListF X) (List X) -> (List X)
infixr 4 _,-_
listF : {X T U : Set} -> (T -> U) -> (ListF X) T -> (ListF X) U
listF g (inl <>) = inl <>
listF g (inr (x , t)) = inr (x , g t)
pattern [] = < inl <> >
pattern _,-_ x xs = < inr (x , xs) >
{-(-}
mkList : {X : Set} -> (ListF X) (List X) -> List X
mkList = <_>
{-
mkList (inl <>) = []
mkList (inr (x , xs)) = x ,- xs
-}
{-)-}
{-(-}
foldr : {X T : Set} -> ((ListF X) T -> T) -> List X -> T
foldr alg [] = alg (inl <>)
foldr alg (x ,- xs) = alg (inr (x , foldr alg xs))
ex1 = foldr mkList (1 ,- 2 ,- 3 ,- [])
{-)-}
{-(-}
length : {X : Set} -> List X -> Nat
length = foldr \ { (inl <>) -> zero ; (inr (x , n)) -> suc n }
{-)-}
record CoList (X : Set) : Set where
coinductive
field
force : (ListF X) (CoList X)
open CoList
{-(-}
[]~ : {X : Set} -> CoList X
force []~ = inl <>
_,~_ : {X : Set} -> X -> CoList X -> CoList X
force (x ,~ xs) = inr (x , xs)
infixr 4 _,~_
{-)-}
{-(-}
unfoldr : {X S : Set} -> (S -> (ListF X) S) -> S -> CoList X
force (unfoldr coalg s) with coalg s
force (unfoldr coalg s) | inl <> = inl <>
force (unfoldr coalg s) | inr (x , s') = inr (x , unfoldr coalg s')
ex2 = unfoldr force (1 ,~ 2 ,~ 3 ,~ []~)
{-)-}
{-(-}
repeat : {X : Set} -> X -> CoList X
repeat = unfoldr \ x -> inr (x , x)
{-)-}
{-(-}
prefix : {X : Set} -> Nat -> CoList X -> List X
prefix zero xs = []
prefix (suc n) xs with force xs
prefix (suc n) xs | inl <> = []
prefix (suc n) xs | inr (x , xs') = x ,- prefix n xs'
ex2' = prefix 3 ex2
{-)-}
StreamF : Set -> Set -> Set
StreamF X S = X * S
data Funny (X : Set) : Set where
<_> : (StreamF X) (Funny X) -> Funny X
funny : {X : Set} -> Funny X -> Zero
funny < x , xf > = funny xf
record Stream (X : Set) : Set where
coinductive
field
hdTl : (StreamF X) (Stream X)
open Stream
{-(-}
forever : {X : Set} -> X -> Stream X
fst (hdTl (forever x)) = x
snd (hdTl (forever x)) = forever x
{-)-}
natsFrom : Nat -> Stream Nat
fst (hdTl (natsFrom n)) = n
snd (hdTl (natsFrom n)) = natsFrom (suc n)
sprefix : {X : Set} -> Nat -> Stream X -> List X -- could be Vec X n
sprefix zero xs = []
sprefix (suc n) xs with hdTl xs
sprefix (suc n) xs | x , xs' = x ,- sprefix n xs'
{-(-}
unfold : {X S : Set} -> (S -> X * S) -> S -> Stream X
hdTl (unfold coalg s) with coalg s
hdTl (unfold coalg s) | x , s' = x , unfold coalg s'
{-)-}
natsFrom' : Nat -> Stream Nat
natsFrom' = unfold \ n -> n , suc n
data Two : Set where tt ff : Two
So : Two -> Set
So tt = One
So ff = Zero
isSuc : Nat -> Two
isSuc zero = ff
isSuc (suc n) = tt
{-
div : (x y : Nat) -> So (isSuc y) -> Nat
div x zero ()
div x (suc y) p = {!!}
-}
data Poly (X : Set) : Set where
var' : X -> Poly X
konst' : Two -> Poly X
_+'_ _*'_ : Poly X -> Poly X -> Poly X
Eval : {X : Set} -> (X -> Set) -> Poly X -> Set
Eval var (var' x) = var x
Eval var (konst' b) = So b
Eval var (p +' q) = Eval var p + Eval var q
Eval var (p *' q) = Eval var p * Eval var q
eval : {X : Set}(u v : X -> Set)(p : Poly X) ->
((x : X) -> u x -> v x) ->
Eval u p -> Eval v p
eval u v (var' i) f x = f i x
eval u v (konst' b) f x = x
eval u v (p +' q) f (inl x) = inl (eval u v p f x)
eval u v (p +' q) f (inr x) = inr (eval u v q f x)
eval u v (p *' q) f (x , y) = eval u v p f x , eval u v q f y
data Mu (p : Poly One) : Set where
<_> : Eval (\ _ -> Mu p) p -> Mu p
NatP : Poly One
NatP = konst' tt +' var' <>
NAT = Mu NatP
ze : NAT
ze = < (inl <>) >
su : NAT -> NAT
su n = < (inr n) >
TreeP : Poly One
TreeP = konst' tt +' (var' <> *' var' <>)
-- What's a one-hole context in a Mu P?
Diff : Poly One -> Poly One
Diff (var' x) = konst' tt
Diff (konst' x) = konst' ff
Diff (p +' q) = Diff p +' Diff q
Diff (p *' q) = (Diff p *' q) +' (p *' Diff q)
plug : {X : Set}(p : Poly One) ->
X -> Eval (\ _ -> X) (Diff p) ->
Eval (\ _ -> X) p
plug (var' <>) x <> = x
plug (konst' b) x ()
plug (p +' q) x (inl xp') = inl (plug p x xp')
plug (p +' q) x (inr xq') = inr (plug q x xq')
plug (p *' q) x (inl (xp' , xq)) = plug p x xp' , xq
plug (p *' q) x (inr (xp , xq')) = xp , plug q x xq'
Context : Poly One -> Set
Context p = List (Eval (\ _ -> Mu p) (Diff p))
plugs : (p : Poly One) -> Mu p -> Context p -> Mu p
plugs p t [] = t
plugs p t (t' ,- t's) = plugs p < plug p t t' > t's
TernaryP : Poly One
TernaryP = konst' tt +' (var' <> *' (var' <> *' var' <>))
fold : (p : Poly One){T : Set}
-> (Eval (\ _ -> T) p -> T)
-> Mu p -> T
fold p {T} alg < x > = alg (evalFold p x)
where
evalFold : (q : Poly One) -> Eval (\ _ -> Mu p) q -> Eval (\ _ -> T) q
evalFold (var' <>) x = fold p alg x
evalFold (konst' b) x = x
evalFold (q +' r) (inl y) = inl (evalFold q y)
evalFold (q +' r) (inr y) = inr (evalFold r y)
evalFold (q *' r) (y , z) = evalFold q y , evalFold r z
record Nu (p : Poly One) : Set where
coinductive
field
out : Eval (\ _ -> Nu p) p
-- What's the connection between polynomials and containers?
_-:>_ : {I : Set} -> (I -> Set) -> (I -> Set) -> (I -> Set)
(S -:> T) i = S i -> T i
[_] : {I : Set} -> (I -> Set) -> Set
[ P ] = forall i -> P i -- [_] {I} P = (i : I) -> P i
All : {X : Set} -> (X -> Set) -> (List X -> Set)
All P [] = One
All P (x ,- xs) = P x * All P xs
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?
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><_
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
_+L_ : {X : Set} -> List X -> List X -> List X
[] +L ys = ys
(x ,- xs) +L ys = x ,- (xs +L ys)
polyCon : {I : Set} -> Poly I -> I |> One
_|>_.Cuts (polyCon p) <> = Eval (\ _ -> One) p
_|>_.inners (polyCon (var' i)) <> = i ,- []
_|>_.inners (polyCon (konst' x)) s = []
_|>_.inners (polyCon (p +' q)) (inl xp) = _|>_.inners (polyCon p) xp
_|>_.inners (polyCon (p +' q)) (inr xq) = _|>_.inners (polyCon q) xq
_|>_.inners (polyCon (p *' q)) (sp , sq) =
_|>_.inners (polyCon p) sp +L _|>_.inners (polyCon q) sq
Choose : {I J : Set} -> (I -> Set) -> (J -> Set) -> (I + J) -> Set
Choose X Y (inl i) = X i
Choose X Y (inr j) = Y j
data MU {I -- what sorts of "elements" do we store?
J -- what sorts of "nodes" do we have?
: Set}
(F : J -> Poly (I + J)) -- what is the structure of each sort of node?
(X : I -> Set) -- what are the elements?
(j : J) -- what sort is the outermost node?
: Set where
<_> : Eval (Choose X (MU F X)) -- subnodes in recursive positions
(F j)
-> MU F X j
VecF : Nat -> Poly (One + Nat)
VecF zero = konst' tt
VecF (suc n) = (var' (inl <>)) *' (var' (inr n))
VEC : Nat -> Set -> Set
VEC n X = MU VecF (\ _ -> X) n
vnil : {X : Set} -> VEC zero X
vnil = < <> >
vcons : {X : Set}{n : Nat} -> X -> VEC n X -> VEC (suc n) X
vcons x xs = < (x , xs) >
gmap : {I -- what sorts of "elements" do we store?
J -- what sorts of "nodes" do we have?
: Set}
{F : J -> Poly (I + J)} -- what is the structure of each sort of node?
{X Y : I -> Set} -> -- what are the elements?
((i : I) -> X i -> Y i) ->
(j : J) ->
MU F X j -> MU F Y j
gmapHelp : ∀ {I J} (F : J → Poly (I + J)) {X Y : I → Set}
(w : Poly (I + J)) →
((i : I) → X i → Y i) →
Eval (Choose X (MU F X)) w →
Eval (Choose Y (MU F Y)) w
gmap {F = F} f j < xt > = < gmapHelp F (F j) f xt >
gmapHelp F (var' (inl i)) f x = f i x
gmapHelp F (var' (inr j)) f t = gmap f j t
gmapHelp F (konst' x) f v = v
gmapHelp F (p +' q) f (inl xp) = inl (gmapHelp F p f xp)
gmapHelp F (p +' q) f (inr xq) = inr (gmapHelp F q f xq)
gmapHelp F (p *' q) f (xp , xq) = (gmapHelp F p f xp) , (gmapHelp F q f xq)
|
{
"alphanum_fraction": 0.4815202232,
"avg_line_length": 26.8037383178,
"ext": "agda",
"hexsha": "19534027526ee6c0d06cace1adfb2dc71022b2e9",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec6.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec6.agda",
"max_line_length": 81,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec6.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 3341,
"size": 8604
}
|
{-# OPTIONS --safe #-}
module Cubical.Functions.Surjection where
open import Cubical.Core.Everything
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Functions.Embedding
open import Cubical.HITs.PropositionalTruncation as PropTrunc
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
f : A → B
isSurjection : (A → B) → Type _
isSurjection f = ∀ b → ∥ fiber f b ∥
_↠_ : Type ℓ → Type ℓ' → Type (ℓ-max ℓ ℓ')
A ↠ B = Σ[ f ∈ (A → B) ] isSurjection f
section→isSurjection : {g : B → A} → section f g → isSurjection f
section→isSurjection {g = g} s b = ∣ g b , s b ∣
isPropIsSurjection : isProp (isSurjection f)
isPropIsSurjection = isPropΠ λ _ → squash
isEquiv→isSurjection : isEquiv f → isSurjection f
isEquiv→isSurjection e b = ∣ fst (equiv-proof e b) ∣
isEquiv→isEmbedding×isSurjection : isEquiv f → isEmbedding f × isSurjection f
isEquiv→isEmbedding×isSurjection e = isEquiv→isEmbedding e , isEquiv→isSurjection e
isEmbedding×isSurjection→isEquiv : isEmbedding f × isSurjection f → isEquiv f
equiv-proof (isEmbedding×isSurjection→isEquiv {f = f} (emb , sur)) b =
inhProp→isContr (PropTrunc.rec fib' (λ x → x) fib) fib'
where
hpf : hasPropFibers f
hpf = isEmbedding→hasPropFibers emb
fib : ∥ fiber f b ∥
fib = sur b
fib' : isProp (fiber f b)
fib' = hpf b
isEquiv≃isEmbedding×isSurjection : isEquiv f ≃ isEmbedding f × isSurjection f
isEquiv≃isEmbedding×isSurjection = isoToEquiv (iso
isEquiv→isEmbedding×isSurjection
isEmbedding×isSurjection→isEquiv
(λ _ → isOfHLevelΣ 1 isPropIsEmbedding (\ _ → isPropIsSurjection) _ _)
(λ _ → isPropIsEquiv _ _ _))
-- obs: for epi⇒surjective to go through we require a stronger
-- hypothesis that one would expect:
-- f must cancel functions from a higher universe.
rightCancellable : (f : A → B) → Type _
rightCancellable {ℓ} {A} {ℓ'} {B} f = ∀ {C : Type (ℓ-suc (ℓ-max ℓ ℓ'))}
→ ∀ (g g' : B → C) → (∀ x → g (f x) ≡ g' (f x)) → ∀ y → g y ≡ g' y
-- This statement is in Mac Lane & Moerdijk (page 143, corollary 5).
epi⇒surjective : (f : A → B) → rightCancellable f → isSurjection f
epi⇒surjective f rc y = transport (fact₂ y) tt*
where hasPreimage : (A → B) → B → _
hasPreimage f y = ∥ fiber f y ∥
fact₁ : ∀ x → Unit* ≡ hasPreimage f (f x)
fact₁ x = hPropExt isPropUnit*
propTruncIsProp
(λ _ → ∣ (x , refl) ∣)
(λ _ → tt*)
fact₂ : ∀ y → Unit* ≡ hasPreimage f y
fact₂ = rc _ _ fact₁
|
{
"alphanum_fraction": 0.660247093,
"avg_line_length": 33.975308642,
"ext": "agda",
"hexsha": "d03594b963e8cbc6124c80d32fe51e13c9f105a5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-03-12T20:08:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-03-12T20:08:45.000Z",
"max_forks_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "LuuBluum/cubical",
"max_forks_repo_path": "Cubical/Functions/Surjection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "LuuBluum/cubical",
"max_issues_repo_path": "Cubical/Functions/Surjection.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "LuuBluum/cubical",
"max_stars_repo_path": "Cubical/Functions/Surjection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 973,
"size": 2752
}
|
module Prelude where
-- Simple data
open import Data.Bool public
using (Bool ; false ; true ; not)
open import Data.Empty public
using (⊥ ; ⊥-elim)
open import Data.Nat public
using (
ℕ ; zero ; suc
; _+_ ; _*_
; _≤_ ; z≤n ; s≤s
; _<_ ; _≟_ ; pred
)
open import Data.Maybe public
using (Maybe ; just ; nothing)
open import Data.Unit public
using (⊤ ; tt)
open import Data.String public
using (String)
renaming (_++_ to _||_)
-- List-like modules
open import Data.List public
using (
List ; [] ; _∷_
; _++_ ; map ; drop
; reverse ; _∷ʳ_ ; length
)
open import Data.List.All public
using (All ; [] ; _∷_ ; lookup)
renaming (map to ∀map)
open import Membership public
using (
_∈_ ; S ; Z
; _⊆_ ; _∷_ ; []
; ⊆-refl ; ⊆-suc ; find-∈
; lookup-parallel ; lookup-parallel-≡ ; translate-∈
; translate-⊆ ; ⊆-trans ; All-⊆
; ⊆++-l-refl ; lookup-all
; ∈-inc ; ⊆++-refl ; ⊆++comm'
; ⊆++comm ; ⊆-move ; ⊆-inc
; ⊆-skip
)
open import Data.List.Any public
using (Any ; here ; there)
open import Singleton public
using ([_]ˡ ; [_]ᵃ ; [_]ᵐ)
-- Propositions and properties
open import Relation.Binary.PropositionalEquality public
using (
_≡_ ; refl ; sym
; cong ; cong₂ ; trans
; inspect ; [_]
)
open import Relation.Nullary public
using (Dec ; yes ; no ; ¬_)
open import Relation.Nullary.Decidable public
using (⌊_⌋)
-- Other
open import Level public
using (Level; _⊔_ ; Lift ; lift)
renaming (zero to lzero; suc to lsuc)
open import Size public
using (Size ; Size<_ ; ↑_ ; ∞)
|
{
"alphanum_fraction": 0.6119974474,
"avg_line_length": 22.3857142857,
"ext": "agda",
"hexsha": "dae94ab2595f98b00c47dffb2844cccbe08b71b6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "src/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "src/Prelude.agda",
"max_line_length": 56,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/thesis",
"max_stars_repo_path": "src/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z",
"num_tokens": 552,
"size": 1567
}
|
{-# OPTIONS --without-K #-}
module Model.Size where
open import Relation.Binary using (Rel ; Preorder ; IsPreorder)
import Data.Nat as ℕ
import Data.Nat.Induction as ℕ
import Data.Nat.Properties as ℕ
import Relation.Binary.Construct.On as On
open import Model.RGraph as RG using (RGraph)
open import Source.Size as S using (Δ ; Ω)
open import Source.Size.Substitution.Universe using (⟨_⟩ ; Sub⊢ᵤ)
open import Util.HoTT.HLevel
open import Util.Induction.WellFounded as WFInd using (Acc ; acc ; WellFounded)
open import Util.Prelude
import Source.Size.Substitution.Canonical as SC
import Source.Size.Substitution.Universe as S
open S.Ctx
open S.Size
open S.Sub
open S.Sub⊢ᵤ
open S.Var
open S._<_ hiding (<-trans)
infix 4 _<_ _≤_
private
variable
i j k : ℕ
{-
This is an encoding of the set of ordinals
ℕ ∪ { ω + i | i ∈ ℕ }
i.e. of the ordinals below ω*2.
-}
data Size : Set where
zero+ : (i : ℕ) → Size
∞+ : (i : ℕ) → Size
variable
n m o : Size
nat : ℕ → Size
nat = zero+
abstract
zero+-inj : zero+ i ≡ zero+ j → i ≡ j
zero+-inj refl = refl
zero+-≡-canon : (p : zero+ i ≡ zero+ j) → p ≡ cong zero+ (zero+-inj p)
zero+-≡-canon refl = refl
∞+-inj : ∞+ i ≡ ∞+ j → i ≡ j
∞+-inj refl = refl
∞+-≡-canon : (p : ∞+ i ≡ ∞+ j) → p ≡ cong ∞+ (∞+-inj p)
∞+-≡-canon refl = refl
Size-IsSet : IsSet Size
Size-IsSet {zero+ i} {zero+ j} p refl
= trans (zero+-≡-canon p) (cong (cong zero+) (ℕ.≡-irrelevant _ _))
Size-IsSet {∞+ i} {∞+ j} p refl
= trans (∞+-≡-canon p) (cong (cong ∞+) (ℕ.≡-irrelevant _ _))
data _<_ : (n m : Size) → Set where
zero+ : (i<j : i ℕ.< j) → zero+ i < zero+ j
∞+ : (i<j : i ℕ.< j) → ∞+ i < ∞+ j
zero<∞ : zero+ i < ∞+ j
data _≤_ (n m : Size) : Set where
reflexive : n ≡ m → n ≤ m
<→≤ : n < m → n ≤ m
pattern ≤-refl = reflexive refl
abstract
<-trans : n < m → m < o → n < o
<-trans (zero+ i<j) (zero+ j<k) = zero+ (ℕ.<-trans i<j j<k)
<-trans (zero+ i<j) zero<∞ = zero<∞
<-trans (∞+ i<j) (∞+ j<k) = ∞+ (ℕ.<-trans i<j j<k)
<-trans zero<∞ (∞+ i<j) = zero<∞
≤→<→< : n ≤ m → m < o → n < o
≤→<→< ≤-refl m<o = m<o
≤→<→< (<→≤ n<m) m<o = <-trans n<m m<o
<→≤→< : n < m → m ≤ o → n < o
<→≤→< n<m ≤-refl = n<m
<→≤→< n<m (<→≤ m<o) = <-trans n<m m<o
≤-trans : n ≤ m → m ≤ o → n ≤ o
≤-trans n≤m ≤-refl = n≤m
≤-trans n≤m (<→≤ m<o) = <→≤ (≤→<→< n≤m m<o)
⟦zero⟧ ⟦∞⟧ : Size
⟦zero⟧ = zero+ 0
⟦∞⟧ = ∞+ 0
⟦suc⟧ : Size → Size
⟦suc⟧ (zero+ i) = zero+ (suc i)
⟦suc⟧ (∞+ i) = ∞+ (suc i)
abstract
⟦zero⟧<⟦suc⟧ : ⟦zero⟧ < ⟦suc⟧ n
⟦zero⟧<⟦suc⟧ {zero+ i} = zero+ (ℕ.s≤s ℕ.z≤n)
⟦zero⟧<⟦suc⟧ {∞+ i} = zero<∞
⟦zero⟧<⟦∞⟧ : ⟦zero⟧ < ⟦∞⟧
⟦zero⟧<⟦∞⟧ = zero<∞
⟦suc⟧<⟦suc⟧ : n < m → ⟦suc⟧ n < ⟦suc⟧ m
⟦suc⟧<⟦suc⟧ (zero+ i<j) = zero+ (ℕ.s≤s i<j)
⟦suc⟧<⟦suc⟧ (∞+ i<j) = ∞+ (ℕ.s≤s i<j)
⟦suc⟧<⟦suc⟧ zero<∞ = zero<∞
⟦suc⟧<⟦∞⟧ : n < ⟦∞⟧ → ⟦suc⟧ n < ⟦∞⟧
⟦suc⟧<⟦∞⟧ zero<∞ = zero<∞
<⟦suc⟧ : n < ⟦suc⟧ n
<⟦suc⟧ {zero+ i} = zero+ (ℕ.s≤s ℕ.≤-refl)
<⟦suc⟧ {∞+ i} = ∞+ (ℕ.s≤s ℕ.≤-refl)
Size< : Size → Set
Size< n = ∃[ m ] (m < n)
mutual
⟦_⟧Δ′ : S.Ctx → Set
⟦ [] ⟧Δ′ = ⊤
⟦ Δ ∙ n ⟧Δ′ = Σ[ δ ∈ ⟦ Δ ⟧Δ′ ] (Size< (⟦ n ⟧n′ δ))
⟦_⟧x′ : S.Var Δ → ⟦ Δ ⟧Δ′ → Size
⟦ zero ⟧x′ (δ , n , _) = n
⟦ suc x ⟧x′ (δ , _ , _) = ⟦ x ⟧x′ δ
⟦_⟧n′ : S.Size Δ → ⟦ Δ ⟧Δ′ → Size
⟦ var x ⟧n′ = ⟦ x ⟧x′
⟦ ∞ ⟧n′ _ = ⟦∞⟧
⟦ zero ⟧n′ _ = ⟦zero⟧
⟦ suc n ⟧n′ = ⟦suc⟧ ∘ ⟦ n ⟧n′
abstract
⟦wk⟧ : ∀ (n m : S.Size Δ) {δ} → ⟦ S.wk {n = n} m ⟧n′ δ ≡ ⟦ m ⟧n′ (proj₁ δ)
⟦wk⟧ n (var x) = refl
⟦wk⟧ n ∞ = refl
⟦wk⟧ n zero = refl
⟦wk⟧ n (suc m) = cong ⟦suc⟧ (⟦wk⟧ n m)
⟦<⟧ₓ : ∀ (x : S.Var Δ) {δ}
→ ⟦ x ⟧x′ δ < ⟦ S.bound x ⟧n′ δ
⟦<⟧ₓ {Δ ∙ n} zero {δ , m , m<n} = subst (m <_) (sym (⟦wk⟧ n n)) m<n
⟦<⟧ₓ {Δ ∙ n} (suc x) {δ , m , m<n}
= subst (⟦ x ⟧x′ δ <_) (sym (⟦wk⟧ n (S.bound x))) (⟦<⟧ₓ x)
⟦<⟧ : ∀ {n m : S.Size Δ} {δ}
→ n S.< m
→ ⟦ n ⟧n′ δ < ⟦ m ⟧n′ δ
⟦<⟧ (var {x = x} refl) = ⟦<⟧ₓ x
⟦<⟧ zero<suc = ⟦zero⟧<⟦suc⟧
⟦<⟧ zero<∞ = ⟦zero⟧<⟦∞⟧
⟦<⟧ (suc<suc n<m) = ⟦suc⟧<⟦suc⟧ (⟦<⟧ n<m)
⟦<⟧ (suc<∞ n<m) = ⟦suc⟧<⟦∞⟧ (⟦<⟧ n<m)
⟦<⟧ (S.<-trans n<m m<o) = <-trans (⟦<⟧ n<m) (⟦<⟧ m<o)
⟦<⟧ <suc = <⟦suc⟧
<-irrefl : ¬ n < n
<-irrefl {zero+ i} (zero+ i<i) = ℕ.<⇒≢ i<i refl
<-irrefl {∞+ i} (∞+ i<i) = ℕ.<⇒≢ i<i refl
≤-antisym : n ≤ m → m ≤ n → n ≡ m
≤-antisym ≤-refl m≤n = refl
≤-antisym (<→≤ n<m) m≤n = ⊥-elim (<-irrefl (<→≤→< n<m m≤n))
<-IsProp : IsProp (n < m)
<-IsProp (zero+ i<j) (zero+ i<j₁) = cong zero+ (ℕ.<-irrelevant _ _)
<-IsProp (∞+ i<j) (∞+ i<j₁) = cong ∞+ (ℕ.<-irrelevant _ _)
<-IsProp zero<∞ zero<∞ = refl
≤-IsProp : IsProp (n ≤ m)
≤-IsProp (reflexive p) (reflexive q) = cong reflexive (Size-IsSet _ _)
≤-IsProp ≤-refl (<→≤ q) = ⊥-elim (<-irrefl q)
≤-IsProp (<→≤ p) ≤-refl = ⊥-elim (<-irrefl p)
≤-IsProp (<→≤ p) (<→≤ q) = cong <→≤ (<-IsProp p q)
Size<-≡⁺ : (m k : Size< n) → proj₁ m ≡ proj₁ k → m ≡ k
Size<-≡⁺ (m , _) (k , _) refl = cong (m ,_) (<-IsProp _ _)
Size<-IsSet : ∀ {n} → IsSet (Size< n)
Size<-IsSet = Σ-IsSet Size-IsSet λ _ → IsOfHLevel-suc 1 <-IsProp
⟦Δ⟧-IsSet : ∀ Δ → IsSet ⟦ Δ ⟧Δ′
⟦Δ⟧-IsSet [] = ⊤-IsSet
⟦Δ⟧-IsSet (Δ ∙ n) = Σ-IsSet (⟦Δ⟧-IsSet Δ) λ _ → Size<-IsSet
⟦Δ⟧-HSet : S.Ctx → HSet 0ℓ
⟦Δ⟧-HSet Δ = HLevel⁺ _ (⟦Δ⟧-IsSet Δ)
abstract
⟦Δ∙n⟧-≡⁺ : ∀ Δ (n : S.Size Δ) {δ δ′ : ⟦ Δ ⟧Δ′} {m m′ : Size}
→ (m<n : m < ⟦ n ⟧n′ δ)
→ (m′<n : m′ < ⟦ n ⟧n′ δ′)
→ δ ≡ δ′
→ m ≡ m′
→ (δ , m , m<n) ≡ (δ′ , m′ , m′<n)
⟦Δ∙n⟧-≡⁺ Δ n {δ} _ _ refl eq₂
= cong (δ ,_) (Size<-≡⁺ _ _ eq₂)
zero+-<ℕ-acc→<-acc : Acc ℕ._<_ i → Acc _<_ (zero+ i)
zero+-<ℕ-acc→<-acc (acc rs) = acc λ where
(zero+ i) (zero+ i<j) → zero+-<ℕ-acc→<-acc (rs i i<j)
zero+-acc : Acc _<_ (zero+ i)
zero+-acc = zero+-<ℕ-acc→<-acc (ℕ.<-wellFounded _)
∞+-<ℕ-acc→<-acc : Acc ℕ._<_ i → Acc _<_ (∞+ i)
∞+-<ℕ-acc→<-acc (acc rs) = acc λ where
(∞+ i) (∞+ i<j) → ∞+-<ℕ-acc→<-acc (rs i i<j)
(zero+ i) zero<∞ → zero+-acc
∞+-acc : Acc _<_ (∞+ i)
∞+-acc = ∞+-<ℕ-acc→<-acc (ℕ.<-wellFounded _)
<-wf : WellFounded _<_
<-wf m = acc λ where
_ (zero+ i<j) → zero+-acc
_ (∞+ i<j) → ∞+-acc
_ zero<∞ → zero+-acc
open WFInd.Build <-wf public using () renaming
( wfInd to <-ind
; wfRec to <-rec
; wfInd-unfold to <-ind-unfold
; wfRec-unfold to <-rec-unfold
; wfInd-ind to <-ind-ind
; wfIndΣ to <-indΣ
; wfIndΣ-unfold to <-indΣ-unfold
; wfIndΣ′ to <-indΣ′
)
<-ind-ind₂ = WFInd.wfInd-ind₂ <-wf
mutual
⟦_⟧σ′ : ∀ {σ} → σ ∶ Δ ⇒ᵤ Ω → ⟦ Δ ⟧Δ′ → ⟦ Ω ⟧Δ′
⟦ Id ⟧σ′ δ = δ
⟦ comp σ τ ⟧σ′ δ = ⟦ τ ⟧σ′ (⟦ σ ⟧σ′ δ)
⟦ Wk ⟧σ′ (δ , m) = δ
⟦ Lift {n = n} σ refl ⟧σ′ (δ , m , m<n)
= ⟦ σ ⟧σ′ δ , m , subst (m <_) (⟦sub⟧ σ n) m<n
⟦ Sing {n = n} n<m ⟧σ′ δ = δ , ⟦ n ⟧n′ δ , ⟦<⟧ n<m
⟦ Skip ⟧σ′ ((δ , m , m<n) , k , k<m) = δ , k , <-trans k<m m<n
abstract
⟦subV′⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (x : S.Var Ω) {δ}
→ ⟦ S.subV′ σ x ⟧n′ δ ≡ ⟦ x ⟧x′ (⟦ ⊢σ ⟧σ′ δ)
⟦subV′⟧ Id x = refl
⟦subV′⟧ (comp {σ = σ} {τ = τ} ⊢σ ⊢τ) x
= trans (⟦sub′⟧ ⊢σ (S.subV′ τ x)) (⟦subV′⟧ ⊢τ x)
⟦subV′⟧ Wk x = refl
⟦subV′⟧ (Lift ⊢σ refl) zero {δ , m} = refl
⟦subV′⟧ (Lift {σ = σ} {n = n} ⊢σ refl) (suc x) {δ , m}
rewrite ⟦wk⟧ (S.sub σ n) (S.subV′ σ x) {δ , m}
= ⟦subV′⟧ ⊢σ x
⟦subV′⟧ (Sing n<m) zero = refl
⟦subV′⟧ (Sing n<m) (suc x) = refl
⟦subV′⟧ Skip zero = refl
⟦subV′⟧ Skip (suc x) = refl
⟦sub′⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (n : S.Size Ω) {δ}
→ ⟦ S.sub′ σ n ⟧n′ δ ≡ ⟦ n ⟧n′ (⟦ ⊢σ ⟧σ′ δ)
⟦sub′⟧ σ (var x) = ⟦subV′⟧ σ x
⟦sub′⟧ σ ∞ = refl
⟦sub′⟧ σ zero = refl
⟦sub′⟧ σ (suc n) = cong ⟦suc⟧ (⟦sub′⟧ σ n)
⟦sub⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (n : S.Size Ω) {δ}
→ ⟦ S.sub σ n ⟧n′ δ ≡ ⟦ n ⟧n′ (⟦ ⊢σ ⟧σ′ δ)
⟦sub⟧ {σ = σ} ⊢σ n {δ}
= trans (cong (λ k → ⟦ k ⟧n′ δ) (sym (S.sub′≡sub σ n))) (⟦sub′⟧ ⊢σ n)
abstract
⟦subV⟧ : ∀ {σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (x : S.Var Ω) {δ}
→ ⟦ S.subV σ x ⟧n′ δ ≡ ⟦ x ⟧x′ (⟦ ⊢σ ⟧σ′ δ)
⟦subV⟧ {σ = σ} ⊢σ x {δ}
= trans (cong (λ k → ⟦ k ⟧n′ δ) (sym (S.subV′≡subV σ x))) (⟦subV′⟧ ⊢σ x)
⟦⟧σ-param : ∀ {σ} (p q : σ ∶ Δ ⇒ᵤ Ω) {δ}
→ ⟦ p ⟧σ′ δ ≡ ⟦ q ⟧σ′ δ
⟦⟧σ-param Id Id = refl
⟦⟧σ-param (comp p p′) (comp q q′)
= trans (⟦⟧σ-param p′ q′) (cong (⟦ q′ ⟧σ′) (⟦⟧σ-param p q))
⟦⟧σ-param Wk Wk = refl
⟦⟧σ-param {Ω = Ω ∙ m} (Lift p refl) (Lift q m≡n[σ]₁)
rewrite S.Size-IsSet m≡n[σ]₁ refl
= ⟦Δ∙n⟧-≡⁺ Ω m _ _ (⟦⟧σ-param p q) refl
⟦⟧σ-param {Δ = Δ} {σ = Sing {m = m} n} (Sing n<m) (Sing n<m₁)
= ⟦Δ∙n⟧-≡⁺ Δ m (⟦<⟧ n<m) (⟦<⟧ n<m₁) refl refl
⟦⟧σ-param Skip Skip = refl
⟦_⟧Δ : S.Ctx → RGraph
⟦ Δ ⟧Δ = record
{ ObjHSet = ⟦Δ⟧-HSet Δ
; eqHProp = λ _ _ → ⊤-HProp
}
Sizes : RGraph
Sizes = record
{ ObjHSet = HLevel⁺ Size Size-IsSet
; eqHProp = λ _ _ → ⊤-HProp
}
⟦_⟧n : ∀ {Δ} (n : S.Size Δ) → ⟦ Δ ⟧Δ RG.⇒ Sizes
⟦ n ⟧n = record
{ fobj = ⟦ n ⟧n′
}
⟦_⟧σ : ∀ {Δ Ω σ} → σ ∶ Δ ⇒ᵤ Ω → ⟦ Δ ⟧Δ RG.⇒ ⟦ Ω ⟧Δ
⟦ σ ⟧σ = record
{ fobj = ⟦ σ ⟧σ′
}
data _≤′_ : (n m : Size) → Set where
zero+ : (i≤j : i ℕ.≤ j) → zero+ i ≤′ zero+ j
∞+ : (i≤j : i ℕ.≤ j) → ∞+ i ≤′ ∞+ j
zero<∞ : zero+ i ≤′ ∞+ j
abstract
≤→≤′ : n ≤ m → n ≤′ m
≤→≤′ {zero+ i} ≤-refl = zero+ ℕ.≤-refl
≤→≤′ {∞+ i} ≤-refl = ∞+ ℕ.≤-refl
≤→≤′ (<→≤ (zero+ i<j)) = zero+ (ℕ.<⇒≤ i<j)
≤→≤′ (<→≤ (∞+ i<j)) = ∞+ (ℕ.<⇒≤ i<j)
≤→≤′ (<→≤ zero<∞) = zero<∞
≤′→≤ : n ≤′ m → n ≤ m
≤′→≤ (zero+ i≤j) with ℕ.≤⇒≤′ i≤j
... | ℕ.≤′-refl = ≤-refl
... | ℕ.≤′-step i≤′j = <→≤ (zero+ (ℕ.s≤s (ℕ.≤′⇒≤ i≤′j)))
≤′→≤ (∞+ i≤j) with ℕ.≤⇒≤′ i≤j
... | ℕ.≤′-refl = ≤-refl
... | ℕ.≤′-step i≤′j = <→≤ (∞+ (ℕ.s≤s (ℕ.≤′⇒≤ i≤′j)))
≤′→≤ zero<∞ = <→≤ zero<∞
0≤n : ⟦zero⟧ ≤ n
0≤n {zero+ zero} = ≤-refl
0≤n {zero+ (suc i)} = <→≤ (zero+ (ℕ.s≤s ℕ.z≤n))
0≤n {∞+ i} = <→≤ zero<∞
n<m→Sn≤m : n < m → ⟦suc⟧ n ≤ m
n<m→Sn≤m (zero+ (ℕ.s≤s i≤j)) = ≤′→≤ (zero+ (ℕ.s≤s i≤j))
n<m→Sn≤m (∞+ (ℕ.s≤s i≤j)) = ≤′→≤ (∞+ (ℕ.s≤s i≤j))
n<m→Sn≤m zero<∞ = <→≤ zero<∞
Sn≤m→n<m : ⟦suc⟧ n ≤ m → n < m
Sn≤m→n<m ≤-refl = <⟦suc⟧
Sn≤m→n<m (<→≤ Sn<m) = <-trans <⟦suc⟧ Sn<m
|
{
"alphanum_fraction": 0.4378064645,
"avg_line_length": 23.6241134752,
"ext": "agda",
"hexsha": "1cafa22d9efc9d5fceec345738804c4d675e3df8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/msc-thesis-code",
"max_forks_repo_path": "src/Model/Size.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/msc-thesis-code",
"max_issues_repo_path": "src/Model/Size.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/msc-thesis-code",
"max_stars_repo_path": "src/Model/Size.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z",
"num_tokens": 5810,
"size": 9993
}
|
open import Nat
open import Prelude
open import contexts
open import core
open import type-assignment-unicity
module canonical-indeterminate-forms where
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at base type
data cif-base : (Δ : hctx) (d : ihexp) → Set where
CIFBEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: b [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-base Δ d
CIFBNEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: b [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-base Δ d
CIFBAp : ∀ {Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2 ==> b) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-base Δ d
CIFBCast : ∀ {Δ d} →
Σ[ d' ∈ ihexp ]
((d == d' ⟨ ⦇-⦈ ⇒ b ⟩) ×
(Δ , ∅ ⊢ d' :: ⦇-⦈) ×
(d' indet) ×
((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩))
)
→ cif-base Δ d
CIFBFailedCast : ∀ {Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == d' ⟨ τ' ⇒⦇-⦈⇏ b ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ b)
)
→ cif-base Δ d
canonical-indeterminate-forms-base : ∀{Δ d} →
Δ , ∅ ⊢ d :: b →
d indet →
cif-base Δ d
canonical-indeterminate-forms-base TAConst ()
canonical-indeterminate-forms-base (TAVar x₁) ()
canonical-indeterminate-forms-base (TAAp wt wt₁) (IAp x ind x₁) = CIFBAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-base (TAEHole x x₁) IEHole = CIFBEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-base (TANEHole x wt x₁) (INEHole x₂) = CIFBNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-base (TACast wt x) (ICastHoleGround x₁ ind x₂) = CIFBCast (_ , refl , wt , ind , x₁)
canonical-indeterminate-forms-base (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = CIFBFailedCast (_ , _ , refl , x , x₅ , x₇)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at arrow type
data cif-arr : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CIFAEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-arr Δ d τ1 τ2
CIFANEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-arr Δ d τ1 τ2
CIFAAp : ∀{d Δ τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2' ∈ htyp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2' ==> (τ1 ==> τ2)) ×
(Δ , ∅ ⊢ d2 :: τ2') ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFACast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
((d == d' ⟨ (τ1' ==> τ2') ⇒ (τ1 ==> τ2) ⟩) ×
(Δ , ∅ ⊢ d' :: τ1' ==> τ2') ×
(d' indet) ×
((τ1' ==> τ2') ≠ (τ1 ==> τ2))
)
→ cif-arr Δ d τ1 τ2
CIFACastHole : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == (d' ⟨ ⦇-⦈ ⇒ ⦇-⦈ ==> ⦇-⦈ ⟩)) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: ⦇-⦈) ×
(d' indet) ×
((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFAFailedCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == (d' ⟨ τ' ⇒⦇-⦈⇏ ⦇-⦈ ==> ⦇-⦈ ⟩) ) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ (⦇-⦈ ==> ⦇-⦈))
)
→ cif-arr Δ d τ1 τ2
canonical-indeterminate-forms-arr : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d indet →
cif-arr Δ d τ1 τ2
canonical-indeterminate-forms-arr (TAVar x₁) ()
canonical-indeterminate-forms-arr (TALam _ wt) ()
canonical-indeterminate-forms-arr (TAAp wt wt₁) (IAp x ind x₁) = CIFAAp (_ , _ , _ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-arr (TAEHole x x₁) IEHole = CIFAEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-arr (TANEHole x wt x₁) (INEHole x₂) = CIFANEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-arr (TACast wt x) (ICastArr x₁ ind) = CIFACast (_ , _ , _ , _ , _ , refl , wt , ind , x₁)
canonical-indeterminate-forms-arr (TACast wt TCHole2) (ICastHoleGround x₁ ind GHole) = CIFACastHole (_ , refl , refl , refl , wt , ind , x₁)
canonical-indeterminate-forms-arr (TAFailedCast x x₁ GHole x₃) (IFailedCast x₄ x₅ GHole x₇) = CIFAFailedCast (_ , _ , refl , refl , refl , x , x₅ , x₇)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at hole type
data cif-hole : (Δ : hctx) (d : ihexp) → Set where
CIFHEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: ⦇-⦈ [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-hole Δ d
CIFHNEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: ⦇-⦈ [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-hole Δ d
CIFHAp : ∀ {Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: (τ2 ==> ⦇-⦈)) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-hole Δ d
CIFHCast : ∀ {Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == d' ⟨ τ' ⇒ ⦇-⦈ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(d' indet)
)
→ cif-hole Δ d
canonical-indeterminate-forms-hole : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇-⦈ →
d indet →
cif-hole Δ d
canonical-indeterminate-forms-hole (TAVar x₁) ()
canonical-indeterminate-forms-hole (TAAp wt wt₁) (IAp x ind x₁) = CIFHAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-hole (TAEHole x x₁) IEHole = CIFHEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-hole (TANEHole x wt x₁) (INEHole x₂) = CIFHNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-hole (TACast wt x) (ICastGroundHole x₁ ind) = CIFHCast (_ , _ , refl , wt , x₁ , ind)
canonical-indeterminate-forms-hole (TACast wt x) (ICastHoleGround x₁ ind ())
canonical-indeterminate-forms-hole (TAFailedCast x x₁ () x₃) (IFailedCast x₄ x₅ x₆ x₇)
canonical-indeterminate-forms-coverage : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d indet →
τ ≠ b →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) →
τ ≠ ⦇-⦈ →
⊥
canonical-indeterminate-forms-coverage TAConst () nb na nh
canonical-indeterminate-forms-coverage (TAVar x₁) () nb na nh
canonical-indeterminate-forms-coverage (TALam _ wt) () nb na nh
canonical-indeterminate-forms-coverage {τ = b} (TAAp wt wt₁) (IAp x ind x₁) nb na nh = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TAAp wt wt₁) (IAp x ind x₁) nb na nh = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAAp wt wt₁) (IAp x ind x₁) nb na nh = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = b} (TAEHole x x₁) IEHole nb na nh = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TAEHole x x₁) IEHole nb na nh = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAEHole x x₁) IEHole nb na nh = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = b} (TANEHole x wt x₁) (INEHole x₂) nb na nh = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TANEHole x wt x₁) (INEHole x₂) nb na nh = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TANEHole x wt x₁) (INEHole x₂) nb na nh = na τ τ₁ refl
canonical-indeterminate-forms-coverage (TACast wt x) (ICastArr x₁ ind) nb na nh = na _ _ refl
canonical-indeterminate-forms-coverage (TACast wt x) (ICastGroundHole x₁ ind) nb na nh = nh refl
canonical-indeterminate-forms-coverage {τ = b} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = b} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = λ z _ _₁ → z refl
canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = λ _ _₁ z → z refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = λ _ z _₁ → z τ τ₁ refl
|
{
"alphanum_fraction": 0.4695514407,
"avg_line_length": 46.7546296296,
"ext": "agda",
"hexsha": "88455b1b624fd998c168215cf3717ed355a3d69d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "canonical-indeterminate-forms.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "canonical-indeterminate-forms.agda",
"max_line_length": 153,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "canonical-indeterminate-forms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 4141,
"size": 10099
}
|
module Cats.Util.SetoidReasoning where
open import Relation.Binary.SetoidReasoning public
open import Relation.Binary using (Setoid)
open import Relation.Binary.EqReasoning as EqR using (_IsRelatedTo_)
infixr 2 _≡⟨⟩_
_≡⟨⟩_ : ∀ {c l} {S : Setoid c l} → ∀ x {y} → _IsRelatedTo_ S x y → _IsRelatedTo_ S x y
_≡⟨⟩_ {S = S} = EqR._≡⟨⟩_ S
triangle : ∀ {l l′} (S : Setoid l l′) →
let open Setoid S in
∀ m {x y}
→ x ≈ m
→ y ≈ m
→ x ≈ y
triangle S m x≈m y≈m = trans x≈m (sym y≈m)
where
open Setoid S
|
{
"alphanum_fraction": 0.6291262136,
"avg_line_length": 20.6,
"ext": "agda",
"hexsha": "1f3ba15e102866697103dc70ac2f31e0a5fb00f0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Util/SetoidReasoning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Util/SetoidReasoning.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Util/SetoidReasoning.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 218,
"size": 515
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
module Fragment.Extensions.CSemigroup.Base where
open import Fragment.Equational.Theory.Bundles
open import Fragment.Algebra.Signature
open import Fragment.Algebra.Free Σ-magma hiding (_~_)
open import Fragment.Algebra.Homomorphism Σ-magma
open import Fragment.Algebra.Algebra Σ-magma
using (Algebra; IsAlgebra; Interpretation; Congruence)
open import Fragment.Equational.FreeExtension Θ-csemigroup
using (FreeExtension; IsFreeExtension)
open import Fragment.Equational.Model Θ-csemigroup
open import Fragment.Extensions.CSemigroup.Monomial
open import Fragment.Setoid.Morphism using (_↝_)
open import Level using (Level; _⊔_)
open import Data.Nat using (ℕ)
open import Data.Fin using (#_)
open import Data.Vec using (Vec; []; _∷_; map)
open import Data.Vec.Relation.Binary.Pointwise.Inductive using ([]; _∷_)
import Relation.Binary.Reasoning.Setoid as Reasoning
open import Relation.Binary using (Setoid; IsEquivalence)
open import Relation.Binary.PropositionalEquality as PE using (_≡_)
private
variable
a ℓ : Level
module _ (A : Model {a} {ℓ}) (n : ℕ) where
private
open module A = Setoid ∥ A ∥/≈
_·_ : ∥ A ∥ → ∥ A ∥ → ∥ A ∥
x · y = A ⟦ • ⟧ (x ∷ y ∷ [])
·-cong : ∀ {x y z w} → x ≈ y → z ≈ w → x · z ≈ y · w
·-cong x≈y z≈w = (A ⟦ • ⟧-cong) (x≈y ∷ z≈w ∷ [])
·-comm : ∀ (x y : ∥ A ∥) → x · y ≈ y · x
·-comm x y = ∥ A ∥ₐ-models comm (env {A = ∥ A ∥ₐ} (x ∷ y ∷ []))
·-assoc : ∀ (x y z : ∥ A ∥) → (x · y) · z ≈ x · (y · z)
·-assoc x y z = ∥ A ∥ₐ-models assoc (env {A = ∥ A ∥ₐ} (x ∷ y ∷ z ∷ []))
data Blob : Set a where
sta : ∥ A ∥ → Blob
dyn : ∥ J' n ∥ → Blob
blob : ∥ J' n ∥ → ∥ A ∥ → Blob
infix 6 _≋_
data _≋_ : Blob → Blob → Set (a ⊔ ℓ) where
sta : ∀ {x y} → x ≈ y → sta x ≋ sta y
dyn : ∀ {xs ys} → xs ≡ ys → dyn xs ≋ dyn ys
blob : ∀ {x y xs ys} → xs ≡ ys → x ≈ y
→ blob xs x ≋ blob ys y
≋-refl : ∀ {x} → x ≋ x
≋-refl {x = sta x} = sta A.refl
≋-refl {x = dyn xs} = dyn PE.refl
≋-refl {x = blob xs x} = blob PE.refl A.refl
≋-sym : ∀ {x y} → x ≋ y → y ≋ x
≋-sym (sta p) = sta (A.sym p)
≋-sym (dyn ps) = dyn (PE.sym ps)
≋-sym (blob ps p) = blob (PE.sym ps) (A.sym p)
≋-trans : ∀ {x y z} → x ≋ y → y ≋ z → x ≋ z
≋-trans (sta p) (sta q) = sta (A.trans p q)
≋-trans (dyn ps) (dyn qs) = dyn (PE.trans ps qs)
≋-trans (blob ps p) (blob qs q) = blob (PE.trans ps qs) (A.trans p q)
≋-isEquivalence : IsEquivalence _≋_
≋-isEquivalence = record { refl = ≋-refl
; sym = ≋-sym
; trans = ≋-trans
}
Blob/≋ : Setoid _ _
Blob/≋ = record { Carrier = Blob
; _≈_ = _≋_
; isEquivalence = ≋-isEquivalence
}
_++_ : Blob → Blob → Blob
sta x ++ sta y = sta (x · y)
dyn xs ++ dyn ys = dyn (xs ⊗ ys)
sta x ++ dyn ys = blob ys x
sta x ++ blob ys y = blob ys (x · y)
dyn xs ++ sta y = blob xs y
dyn xs ++ blob ys y = blob (xs ⊗ ys) y
blob xs x ++ sta y = blob xs (x · y)
blob xs x ++ dyn ys = blob (xs ⊗ ys) x
blob xs x ++ blob ys y = blob (xs ⊗ ys) (x · y)
++-cong : ∀ {x y z w} → x ≋ y → z ≋ w → x ++ z ≋ y ++ w
++-cong (sta p) (sta q) = sta (·-cong p q)
++-cong (dyn ps) (dyn qs) = dyn (⊗-cong ps qs)
++-cong (sta p) (dyn qs) = blob qs p
++-cong (sta p) (blob qs q) = blob qs (·-cong p q)
++-cong (dyn ps) (sta q) = blob ps q
++-cong (dyn ps) (blob qs q) = blob (⊗-cong ps qs) q
++-cong (blob ps p) (sta q) = blob ps (·-cong p q)
++-cong (blob ps p) (dyn qs) = blob (⊗-cong ps qs) p
++-cong (blob ps p) (blob qs q) = blob (⊗-cong ps qs) (·-cong p q)
++-comm : ∀ x y → x ++ y ≋ y ++ x
++-comm (sta x) (sta y) = sta (·-comm x y)
++-comm (dyn xs) (dyn ys) = dyn (⊗-comm xs ys)
++-comm (sta x) (dyn ys) = ≋-refl
++-comm (sta x) (blob ys y) = blob PE.refl (·-comm x y)
++-comm (dyn xs) (sta y) = ≋-refl
++-comm (dyn xs) (blob ys y) = blob (⊗-comm xs ys) A.refl
++-comm (blob xs x) (sta y) = blob PE.refl (·-comm x y)
++-comm (blob xs x) (dyn ys) = blob (⊗-comm xs ys) A.refl
++-comm (blob xs x) (blob ys y) = blob (⊗-comm xs ys) (·-comm x y)
++-assoc : ∀ x y z → (x ++ y) ++ z ≋ x ++ (y ++ z)
++-assoc (sta x) (sta y) (sta z) = sta (·-assoc x y z)
++-assoc (dyn xs) (dyn ys) (dyn zs) = dyn (⊗-assoc xs ys zs)
++-assoc (sta x) (sta y) (dyn zs) = ≋-refl
++-assoc (sta x) (sta y) (blob zs z) = blob PE.refl (·-assoc x y z)
++-assoc (sta x) (dyn ys) (sta z) = ≋-refl
++-assoc (sta x) (dyn ys) (dyn zs) = ≋-refl
++-assoc (sta x) (dyn ys) (blob zs z) = ≋-refl
++-assoc (sta x) (blob ys y) (sta z) = blob PE.refl (·-assoc x y z)
++-assoc (sta x) (blob ys y) (dyn zs) = ≋-refl
++-assoc (sta x) (blob ys y) (blob zs z) = blob PE.refl (·-assoc x y z)
++-assoc (dyn xs) (sta y) (sta z) = ≋-refl
++-assoc (dyn xs) (sta y) (dyn zs) = ≋-refl
++-assoc (dyn xs) (sta y) (blob zs z) = ≋-refl
++-assoc (dyn xs) (dyn ys) (sta z) = ≋-refl
++-assoc (dyn xs) (dyn ys) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl
++-assoc (dyn xs) (blob ys y) (sta z) = ≋-refl
++-assoc (dyn xs) (blob ys y) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl
++-assoc (dyn xs) (blob ys y) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl
++-assoc (blob xs x) (sta y) (sta z) = blob PE.refl (·-assoc x y z)
++-assoc (blob xs x) (sta y) (dyn zs) = ≋-refl
++-assoc (blob xs x) (sta y) (blob zs z) = blob PE.refl (·-assoc x y z)
++-assoc (blob xs x) (dyn ys) (sta z) = ≋-refl
++-assoc (blob xs x) (dyn ys) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl
++-assoc (blob xs x) (dyn ys) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl
++-assoc (blob xs x) (blob ys y) (sta z) = blob PE.refl (·-assoc x y z)
++-assoc (blob xs x) (blob ys y) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl
++-assoc (blob xs x) (blob ys y) (blob zs z) = blob (⊗-assoc xs ys zs) (·-assoc x y z)
Blob⟦_⟧ : Interpretation Blob/≋
Blob⟦ • ⟧ (x ∷ y ∷ []) = x ++ y
Blob⟦_⟧-cong : Congruence Blob/≋ Blob⟦_⟧
Blob⟦ • ⟧-cong (p ∷ q ∷ []) = ++-cong p q
Blob/≋-isAlgebra : IsAlgebra Blob/≋
Blob/≋-isAlgebra = record { ⟦_⟧ = Blob⟦_⟧
; ⟦⟧-cong = Blob⟦_⟧-cong
}
Blob/≋-algebra : Algebra
Blob/≋-algebra =
record { ∥_∥/≈ = Blob/≋
; ∥_∥/≈-isAlgebra = Blob/≋-isAlgebra
}
Blob/≋-models : Models Blob/≋-algebra
Blob/≋-models comm θ = ++-comm (θ (# 0)) (θ (# 1))
Blob/≋-models assoc θ = ++-assoc (θ (# 0)) (θ (# 1)) (θ (# 2))
Blob/≋-isModel : IsModel Blob/≋
Blob/≋-isModel =
record { isAlgebra = Blob/≋-isAlgebra
; models = Blob/≋-models
}
Frex : Model
Frex = record { ∥_∥/≈ = Blob/≋
; isModel = Blob/≋-isModel
}
∣inl∣ : ∥ A ∥ → ∥ Frex ∥
∣inl∣ = sta
∣inl∣-cong : Congruent _≈_ _≋_ ∣inl∣
∣inl∣-cong = sta
∣inl∣⃗ : ∥ A ∥/≈ ↝ ∥ Frex ∥/≈
∣inl∣⃗ = record { ∣_∣ = ∣inl∣
; ∣_∣-cong = ∣inl∣-cong
}
∣inl∣-hom : Homomorphic ∥ A ∥ₐ ∥ Frex ∥ₐ ∣inl∣
∣inl∣-hom • (x ∷ y ∷ []) = ≋-refl
inl : ∥ A ∥ₐ ⟿ ∥ Frex ∥ₐ
inl = record { ∣_∣⃗ = ∣inl∣⃗
; ∣_∣-hom = ∣inl∣-hom
}
∣inr∣ : ∥ J n ∥ → ∥ Frex ∥
∣inr∣ x = dyn (∣ norm ∣ x)
∣inr∣-cong : Congruent ≈[ J n ] _≋_ ∣inr∣
∣inr∣-cong p = dyn (∣ norm ∣-cong p)
∣inr∣⃗ : ∥ J n ∥/≈ ↝ ∥ Frex ∥/≈
∣inr∣⃗ = record { ∣_∣ = ∣inr∣
; ∣_∣-cong = ∣inr∣-cong
}
∣inr∣-hom : Homomorphic ∥ J n ∥ₐ ∥ Frex ∥ₐ ∣inr∣
∣inr∣-hom • (x ∷ y ∷ []) = dyn (∣ norm ∣-hom • (x ∷ y ∷ []))
inr : ∥ J n ∥ₐ ⟿ ∥ Frex ∥ₐ
inr = record { ∣_∣⃗ = ∣inr∣⃗
; ∣_∣-hom = ∣inr∣-hom
}
module _ {b ℓ} (X : Model {b} {ℓ}) where
private
open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_)
_⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥
x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ [])
⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w
⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ [])
⊕-comm : ∀ (x y : ∥ X ∥) → x ⊕ y ~ y ⊕ x
⊕-comm x y = ∥ X ∥ₐ-models comm (env {A = ∥ X ∥ₐ} (x ∷ y ∷ []))
⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z)
⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ []))
module _
(f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ)
(g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ)
where
∣resid∣ : ∥ Frex ∥ → ∥ X ∥
∣resid∣ (sta x) = ∣ f ∣ x
∣resid∣ (dyn xs) = ∣ g ∣ (∣ syn ∣ xs)
∣resid∣ (blob xs x) = ∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x
∣resid∣-cong : Congruent _≋_ _~_ ∣resid∣
∣resid∣-cong (sta p) = ∣ f ∣-cong p
∣resid∣-cong (dyn ps) = ∣ g ∣-cong (∣ syn ∣-cong ps)
∣resid∣-cong (blob ps p) =
⊕-cong (∣ g ∣-cong (∣ syn ∣-cong ps)) (∣ f ∣-cong p)
open Reasoning ∥ X ∥/≈
∣resid∣-hom : Homomorphic ∥ Frex ∥ₐ ∥ X ∥ₐ ∣resid∣
∣resid∣-hom • (sta x ∷ sta y ∷ []) = ∣ f ∣-hom • (x ∷ y ∷ [])
∣resid∣-hom • (sta x ∷ dyn ys ∷ []) = ⊕-comm (∣ f ∣ x) _
∣resid∣-hom • (sta x ∷ blob ys y ∷ []) = begin
∣ f ∣ x ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y)
≈⟨ ⊕-cong X.refl (⊕-comm _ (∣ f ∣ y)) ⟩
∣ f ∣ x ⊕ (∣ f ∣ y ⊕ ∣ g ∣ (∣ syn ∣ ys))
≈⟨ X.sym (⊕-assoc (∣ f ∣ x) (∣ f ∣ y) _) ⟩
(∣ f ∣ x ⊕ ∣ f ∣ y) ⊕ ∣ g ∣ (∣ syn ∣ ys)
≈⟨ ⊕-cong (∣ f ∣-hom • (x ∷ y ∷ [])) X.refl ⟩
∣ f ∣ (x · y) ⊕ ∣ g ∣ (∣ syn ∣ ys)
≈⟨ ⊕-comm _ _ ⟩
∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ (x · y)
∎
∣resid∣-hom • (dyn xs ∷ sta y ∷ []) = X.refl
∣resid∣-hom • (dyn xs ∷ dyn ys ∷ []) = ∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])
∣resid∣-hom • (dyn xs ∷ blob ys y ∷ []) = begin
∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y)
≈⟨ X.sym (⊕-assoc _ _ (∣ f ∣ y)) ⟩
(∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ y
≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) X.refl ⟩
∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ y
∎
∣resid∣-hom • (blob xs x ∷ sta y ∷ []) = begin
(∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ ∣ f ∣ y
≈⟨ ⊕-assoc _ (∣ f ∣ x) (∣ f ∣ y) ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y)
≈⟨ ⊕-cong X.refl (∣ f ∣-hom • (x ∷ y ∷ [])) ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ (x · y)
∎
∣resid∣-hom • (blob xs x ∷ dyn ys ∷ []) = begin
(∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ ∣ g ∣ (∣ syn ∣ ys)
≈⟨ ⊕-assoc _ (∣ f ∣ x) _ ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ ∣ g ∣ (∣ syn ∣ ys))
≈⟨ ⊕-cong X.refl (⊕-comm (∣ f ∣ x) _) ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ x)
≈⟨ X.sym (⊕-assoc _ _ (∣ f ∣ x)) ⟩
(∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ x
≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) X.refl ⟩
∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ x
∎
∣resid∣-hom • (blob xs x ∷ blob ys y ∷ []) = begin
(∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y)
≈⟨ ⊕-assoc _ (∣ f ∣ x) _ ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y))
≈⟨ ⊕-cong X.refl (X.sym (⊕-assoc (∣ f ∣ x) _ _)) ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ ((∣ f ∣ x ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ y)
≈⟨ ⊕-cong X.refl (⊕-cong (⊕-comm (∣ f ∣ x) _) X.refl) ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ ((∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ x) ⊕ ∣ f ∣ y)
≈⟨ ⊕-cong X.refl (⊕-assoc _ (∣ f ∣ x) _) ⟩
∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y))
≈⟨ X.sym (⊕-assoc _ _ _) ⟩
(∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y)
≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) (∣ f ∣-hom • (x ∷ y ∷ [])) ⟩
∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ (x · y)
∎
∣resid∣⃗ : ∥ Frex ∥/≈ ↝ ∥ X ∥/≈
∣resid∣⃗ = record { ∣_∣ = ∣resid∣
; ∣_∣-cong = ∣resid∣-cong
}
_[_,_] : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ
_[_,_] = record { ∣_∣⃗ = ∣resid∣⃗
; ∣_∣-hom = ∣resid∣-hom
}
module _ {b ℓ} {X : Model {b} {ℓ}} where
private
open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_)
_⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥
x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ [])
⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w
⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ [])
⊕-comm : ∀ (x y : ∥ X ∥) → x ⊕ y ~ y ⊕ x
⊕-comm x y = ∥ X ∥ₐ-models comm (env {A = ∥ X ∥ₐ} (x ∷ y ∷ []))
⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z)
⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ []))
module _
{f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ}
{g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ}
where
commute₁ : X [ f , g ] ⊙ inl ≗ f
commute₁ = X.refl
commute₂ : X [ f , g ] ⊙ inr ≗ g
commute₂ {x} = ∣ g ∣-cong (syn⊙norm≗id {x = x})
module _ {h : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ}
(c₁ : h ⊙ inl ≗ f)
(c₂ : h ⊙ inr ≗ g)
where
open Reasoning ∥ X ∥/≈
universal : X [ f , g ] ≗ h
universal {sta x} = X.sym c₁
universal {dyn xs} = begin
∣ g ∣ (∣ syn ∣ xs)
≈⟨ X.sym c₂ ⟩
∣ h ∣ (dyn (∣ norm ∣ (∣ syn ∣ xs)))
≈⟨ ∣ h ∣-cong (dyn norm⊙syn≗id) ⟩
∣ h ∣ (dyn xs)
∎
universal {blob xs x} = begin
∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x
≈⟨ ⊕-cong universal universal ⟩
∣ h ∣ (dyn xs) ⊕ ∣ h ∣ (sta x)
≈⟨ ∣ h ∣-hom • (dyn xs ∷ sta x ∷ []) ⟩
∣ h ∣ (blob xs x)
∎
CSemigroupFrex : FreeExtension
CSemigroupFrex = record { _[_] = Frex
; _[_]-isFrex = isFrex
}
where isFrex : IsFreeExtension Frex
isFrex A n =
record { inl = inl A n
; inr = inr A n
; _[_,_] = _[_,_] A n
; commute₁ = λ {_ _ X f g} → commute₁ A n {X = X} {f} {g}
; commute₂ = λ {_ _ X f g} → commute₂ A n {X = X} {f} {g}
; universal = λ {_ _ X f g h} → universal A n {X = X} {f} {g} {h}
}
|
{
"alphanum_fraction": 0.4032755431,
"avg_line_length": 36.851010101,
"ext": "agda",
"hexsha": "6068c298befdbeb551e89782a061eb181585f3bd",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Extensions/CSemigroup/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Extensions/CSemigroup/Base.agda",
"max_line_length": 88,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Extensions/CSemigroup/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 6924,
"size": 14593
}
|
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
open import Light.Library.Data.Natural as ℕ using (ℕ ; predecessor ; zero)
open import Light.Package using (Package)
module Light.Literals.Level ⦃ natural‐package : Package record { ℕ } ⦄ where
open import Light.Literals.Definition.Natural using (FromNatural)
open FromNatural using (convert)
open import Light.Level using (Level ; 0ℓ ; ++_)
open import Light.Library.Relation.Decidable using (if_then_else_)
open import Light.Library.Relation.Binary.Equality using (_≈_)
open import Light.Library.Relation.Binary.Equality.Decidable using (DecidableEquality)
instance from‐natural : FromNatural Level
convert from‐natural n =
if n ≈ zero
then 0ℓ
else ++ convert from‐natural (predecessor n)
|
{
"alphanum_fraction": 0.762925599,
"avg_line_length": 39.65,
"ext": "agda",
"hexsha": "51a1fe974b67ec2f2130253588de5b24ff7b3fa3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Literals/Level.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Literals/Level.agda",
"max_line_length": 86,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Literals/Level.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 189,
"size": 793
}
|
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Unit
module lib.types.Circle where
{-
Idea :
data S¹ : Type₀ where
base : S¹
loop : base == base
I’m using Dan Licata’s trick to have a higher inductive type with definitional
reduction rule for [base]
-}
module _ where
private
data #S¹-aux : Type₀ where
#base : #S¹-aux
data #S¹ : Type₀ where
#s¹ : #S¹-aux → (Unit → Unit) → #S¹
S¹ : Type₀
S¹ = #S¹
base : S¹
base = #s¹ #base _
postulate -- HIT
loop : base == base
module S¹Elim {i} {P : S¹ → Type i} (base* : P base)
(loop* : base* == base* [ P ↓ loop ]) where
f : Π S¹ P
f = f-aux phantom where
f-aux : Phantom loop* → Π S¹ P
f-aux phantom (#s¹ #base _) = base*
postulate -- HIT
loop-β : apd f loop == loop*
open S¹Elim public using () renaming (f to S¹-elim)
module S¹Rec {i} {A : Type i} (base* : A) (loop* : base* == base*) where
private
module M = S¹Elim base* (↓-cst-in loop*)
f : S¹ → A
f = M.f
loop-β : ap f loop == loop*
loop-β = apd=cst-in {f = f} M.loop-β
module S¹RecType {i} (A : Type i) (e : A ≃ A) where
open S¹Rec A (ua e) public
coe-loop-β : (a : A) → coe (ap f loop) a == –> e a
coe-loop-β a =
coe (ap f loop) a =⟨ loop-β |in-ctx (λ u → coe u a) ⟩
coe (ua e) a =⟨ coe-β e a ⟩
–> e a ∎
coe!-loop-β : (a : A) → coe! (ap f loop) a == <– e a
coe!-loop-β a =
coe! (ap f loop) a =⟨ loop-β |in-ctx (λ u → coe! u a) ⟩
coe! (ua e) a =⟨ coe!-β e a ⟩
<– e a ∎
↓-loop-out : {a a' : A} → a == a' [ f ↓ loop ] → –> e a == a'
↓-loop-out {a} {a'} p =
–> e a =⟨ ! (coe-loop-β a) ⟩
coe (ap f loop) a =⟨ to-transp p ⟩
a' ∎
import lib.types.Generic1HIT as Generic1HIT
module S¹G = Generic1HIT Unit Unit (idf _) (idf _)
module P = S¹G.RecType (cst A) (cst e)
private
generic-S¹ : Σ S¹ f == Σ S¹G.T P.f
generic-S¹ = eqv-tot where
module To = S¹Rec (S¹G.cc tt) (S¹G.pp tt)
to = To.f
module From = S¹G.Rec (cst base) (cst loop)
from : S¹G.T → S¹
from = From.f
abstract
to-from : (x : S¹G.T) → to (from x) == x
to-from = S¹G.elim (λ _ → idp) (λ _ → ↓-∘=idf-in to from
(ap to (ap from (S¹G.pp tt)) =⟨ From.pp-β tt |in-ctx ap to ⟩
ap to loop =⟨ To.loop-β ⟩
S¹G.pp tt ∎))
from-to : (x : S¹) → from (to x) == x
from-to = S¹-elim idp (↓-∘=idf-in from to
(ap from (ap to loop) =⟨ To.loop-β |in-ctx ap from ⟩
ap from (S¹G.pp tt) =⟨ From.pp-β tt ⟩
loop ∎))
eqv : S¹ ≃ S¹G.T
eqv = equiv to from to-from from-to
eqv-fib : f == P.f [ (λ X → (X → Type _)) ↓ ua eqv ]
eqv-fib =
↓-app→cst-in (λ {t} p → S¹-elim {P = λ t → f t == P.f (–> eqv t)} idp
(↓-='-in
(ap (P.f ∘ (–> eqv)) loop =⟨ ap-∘ P.f to loop ⟩
ap P.f (ap to loop) =⟨ To.loop-β |in-ctx ap P.f ⟩
ap P.f (S¹G.pp tt) =⟨ P.pp-β tt ⟩
ua e =⟨ ! loop-β ⟩
ap f loop ∎))
t ∙ ap P.f (↓-idf-ua-out eqv p))
eqv-tot : Σ S¹ f == Σ S¹G.T P.f
eqv-tot = ap (uncurry Σ) (pair= (ua eqv) eqv-fib)
import lib.types.Flattening as Flattening
module FlatteningS¹ = Flattening
Unit Unit (idf _) (idf _) (cst A) (cst e)
open FlatteningS¹ public hiding (flattening-equiv; module P)
flattening-S¹ : Σ S¹ f == Wt
flattening-S¹ = generic-S¹ ∙ ua FlatteningS¹.flattening-equiv
|
{
"alphanum_fraction": 0.5051090859,
"avg_line_length": 26.4306569343,
"ext": "agda",
"hexsha": "4078e56ab4ecfa88a34e6a489a19cecbaea80711",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "lib/types/Circle.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "lib/types/Circle.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/Circle.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1458,
"size": 3621
}
|
-- Andreas, 2015-06-24
{-# OPTIONS --copatterns #-}
-- {-# OPTIONS -v tc.with.strip:20 #-}
module _ where
open import Common.Equality
open import Common.Product
module SynchronousIO (I O : Set) where
F : Set → Set
F S = I → O × S
record SyncIO : Set₁ where
field
St : Set
tr : St → F St
module Eq (A₁ A₂ : SyncIO) where
open SyncIO A₁ renaming (St to S₁; tr to tr₁)
open SyncIO A₂ renaming (St to S₂; tr to tr₂)
record BiSim (s₁ : S₁) (s₂ : S₂) : Set where
coinductive
field
force : ∀ (i : I) →
let (o₁ , t₁) = tr₁ s₁ i
(o₂ , t₂) = tr₂ s₂ i
in o₁ ≡ o₂ × BiSim t₁ t₂
module Trans (A₁ A₂ A₃ : SyncIO) where
open SyncIO A₁ renaming (St to S₁; tr to tr₁)
open SyncIO A₂ renaming (St to S₂; tr to tr₂)
open SyncIO A₃ renaming (St to S₃; tr to tr₃)
open Eq A₁ A₂ renaming (BiSim to _₁≅₂_; module BiSim to B₁₂)
open Eq A₂ A₃ renaming (BiSim to _₂≅₃_; module BiSim to B₂₃)
open Eq A₁ A₃ renaming (BiSim to _₁≅₃_; module BiSim to B₁₃)
open B₁₂ renaming (force to force₁₂)
open B₂₃ renaming (force to force₂₃)
open B₁₃ renaming (force to force₁₃)
transitivity : ∀{s₁ s₂ s₃} (p : s₁ ₁≅₂ s₂) (p' : s₂ ₂≅₃ s₃) → s₁ ₁≅₃ s₃
force₁₃ (transitivity p p') i with force₁₂ p i | force₂₃ p' i
force₁₃ (transitivity p p') i | (q , r) | (q' , r') = trans q q' , transitivity r r'
-- with-clause stripping failed for projections from module applications
-- should work now
|
{
"alphanum_fraction": 0.6112956811,
"avg_line_length": 27.3636363636,
"ext": "agda",
"hexsha": "7468c07907eeb1ebb504c27d641ecf2ed5526c8d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue1551a.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue1551a.agda",
"max_line_length": 88,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue1551a.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 575,
"size": 1505
}
|
-- MIT License
-- Copyright (c) 2021 Luca Ciccone and Luca Padovani
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
{-# OPTIONS --guardedness --sized-types #-}
open import Data.Empty
open import Data.Product
open import Data.Sum
open import Data.List using ([]; _∷_; _∷ʳ_; _++_)
open import Data.List.Properties using (∷-injective)
open import Relation.Nullary
open import Relation.Nullary.Negation using (contraposition)
open import Relation.Unary using (_∈_; _∉_; _⊆_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; subst; subst₂; cong)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_)
open import Function.Base using (case_of_)
open import Common
module Discriminator {ℙ : Set} (message : Message ℙ)
where
open import Trace message
open import SessionType message
open import HasTrace message
open import TraceSet message
open import Transitions message
open import Subtyping message
open import Divergence message
open import Session message
open import Semantics message
make-diverge-backward :
∀{T S α}
(tα : T HasTrace (α ∷ []))
(sα : S HasTrace (α ∷ [])) ->
T ↑ S ->
after tα ↑ after sα ->
DivergeBackward tα sα
make-diverge-backward tα sα divε divα none = divε
make-diverge-backward tα sα divε divα (some none) =
subst₂ (λ u v -> after u ↑ after v) (sym (⊑-has-trace-after tα)) (sym (⊑-has-trace-after sα)) divα
has-trace-after-split :
∀{T φ ψ} ->
(tφ : T HasTrace φ)
(tφψ : T HasTrace (φ ++ ψ)) ->
has-trace-after tφ (split-trace tφ tφψ) ≡ tφψ
has-trace-after-split (_ , tdef , refl) tφψ = refl
has-trace-after-split (_ , tdef , step inp tr) (_ , sdef , step inp sr)
rewrite has-trace-after-split (_ , tdef , tr) (_ , sdef , sr) = refl
has-trace-after-split (T , tdef , step (out fx) tr) (S , sdef , step (out gx) sr)
rewrite has-trace-after-split (_ , tdef , tr) (_ , sdef , sr) =
cong (S ,_) (cong (sdef ,_) (cong (λ z -> step z sr) (cong out (Defined-eq (transitions+defined->defined sr sdef) gx))))
disc-set-has-outputs :
∀{T S φ x} ->
T <: S ->
φ ∈ DiscSet T S ->
T HasTrace (φ ∷ʳ O x) ->
S HasTrace φ ->
φ ∷ʳ O x ∈ DiscSet T S
disc-set-has-outputs {_} {S} {φ} {x} sub (inc tφ sφ div←φ) tφx _ with S HasTrace? (φ ∷ʳ O x)
... | yes sφx =
let tφ/x = split-trace tφ tφx in
let sφ/x = split-trace sφ sφx in
let divφ = subst₂ (λ u v -> after u ↑ after v) (⊑-has-trace-after tφ) (⊑-has-trace-after sφ) (div←φ (⊑-refl φ)) in
let divx = _↑_.divergence divφ {[]} {x} none tφ/x sφ/x in
let divφ←x = make-diverge-backward tφ/x sφ/x divφ divx in
let div←φx = subst₂ DivergeBackward (has-trace-after-split tφ tφx) (has-trace-after-split sφ sφx) (append-diverge-backward tφ sφ tφ/x sφ/x div←φ divφ←x) in
inc tφx sφx div←φx
... | no nsφx = exc refl tφ sφ tφx nsφx div←φ
disc-set-has-outputs sub (exc eq tψ sψ tφ nsφ div←ψ) tφx sφ = ⊥-elim (nsφ sφ)
defined-becomes-nil :
∀{T φ S} ->
Defined T ->
¬ Defined S ->
Transitions T φ S ->
∃[ ψ ] ∃[ x ] (φ ≡ ψ ∷ʳ I x × T HasTrace ψ × ¬ T HasTrace φ)
defined-becomes-nil def ndef refl = ⊥-elim (ndef def)
defined-becomes-nil def ndef (step (inp {_} {x}) refl) =
[] , x , refl , (_ , inp , refl) , inp-has-no-trace λ { (_ , def , refl) → ⊥-elim (ndef def) }
defined-becomes-nil def ndef (step inp tr@(step t _)) with defined-becomes-nil (transition->defined t) ndef tr
... | ψ , x , eq , tψ , ntφ =
I _ ∷ ψ , x , cong (I _ ∷_) eq , inp-has-trace tψ , inp-has-no-trace ntφ
defined-becomes-nil def ndef (step (out fx) tr) with defined-becomes-nil fx ndef tr
... | ψ , x , refl , tψ , ntφ =
O _ ∷ ψ , x , refl , out-has-trace tψ , out-has-no-trace ntφ
sub+diverge->defined : ∀{T S} -> T <: S -> T ↑ S -> Defined T × Defined S
sub+diverge->defined nil<:any div with _↑_.with-trace div
... | _ , def , tr = ⊥-elim (contraposition (transitions+defined->defined tr) (λ ()) def)
sub+diverge->defined (end<:def (inp _) def) _ = inp , def
sub+diverge->defined (end<:def (out _) def) _ = out , def
sub+diverge->defined (inp<:inp _ _) _ = inp , inp
sub+diverge->defined (out<:out _ _ _) _ = out , out
sub+diverge->has-empty-trace : ∀{T S} -> T <: S -> T ↑ S -> DiscSet T S []
sub+diverge->has-empty-trace nil<:any div with _↑_.with-trace div
... | tφ = ⊥-elim (nil-has-no-trace tφ)
sub+diverge->has-empty-trace (end<:def e def) div with _↑_.with-trace div | _↑_.without-trace div
... | tφ | nsφ rewrite end-has-empty-trace e tφ = ⊥-elim (nsφ (defined->has-empty-trace def))
sub+diverge->has-empty-trace (inp<:inp _ _) div = inc (_ , inp , refl) (_ , inp , refl) λ { none → div }
sub+diverge->has-empty-trace (out<:out _ _ _) div = inc (_ , out , refl) (_ , out , refl) λ { none → div }
discriminator : SessionType -> SessionType -> SessionType
discriminator T S = decode (co-semantics (disc-set->semantics T S)) .force
discriminator-disc-set-sub : (T S : SessionType) -> CoSet ⟦ discriminator T S ⟧ ⊆ DiscSet T S
discriminator-disc-set-sub T S rφ =
co-inversion {DiscSet T S} (decode-sub (co-semantics (disc-set->semantics T S)) rφ)
discriminator-disc-set-sup : (T S : SessionType) -> DiscSet T S ⊆ CoSet ⟦ discriminator T S ⟧
discriminator-disc-set-sup T S dφ =
decode-sup (co-semantics (disc-set->semantics T S)) (co-definition {DiscSet T S} dφ)
sub+diverge->discriminator-defined : ∀{T S} -> T <: S -> T ↑ S -> Defined (discriminator T S)
sub+diverge->discriminator-defined {T} {S} sub div =
has-trace->defined (co-set-right->left {DiscSet T S} {⟦ discriminator T S ⟧} (discriminator-disc-set-sup T S) (co-definition {DiscSet T S} {[]} (sub+diverge->has-empty-trace sub div)))
input-does-not-win :
∀{T S φ x} (tφ : T HasTrace φ) -> Transitions T (φ ∷ʳ I x) S -> ¬ Win (after tφ)
input-does-not-win (_ , _ , refl) (step inp _) ()
input-does-not-win (_ , def , step inp tr) (step inp sr) w = input-does-not-win (_ , def , tr) sr w
input-does-not-win (_ , def , step (out _) tr) (step (out _) sr) w = input-does-not-win (_ , def , tr) sr w
ends-with-output->has-trace : ∀{T S φ x} -> Transitions T (φ ∷ʳ O x) S -> T HasTrace (φ ∷ʳ O x)
ends-with-output->has-trace tr = _ , output-transitions->defined tr , tr
co-trace-swap : ∀{φ ψ} -> co-trace φ ≡ ψ -> φ ≡ co-trace ψ
co-trace-swap {φ} eq rewrite sym eq rewrite co-trace-involution φ = refl
co-trace-swap-⊑ : ∀{φ ψ} -> co-trace φ ⊑ ψ -> φ ⊑ co-trace ψ
co-trace-swap-⊑ {[]} none = none
co-trace-swap-⊑ {α ∷ _} (some le) rewrite co-action-involution α = some (co-trace-swap-⊑ le)
co-maximal : ∀{X φ} -> φ ∈ Maximal X -> co-trace φ ∈ Maximal (CoSet X)
co-maximal {X} (maximal xφ F) =
maximal (co-definition {X} xφ) λ le xψ -> let le' = co-trace-swap-⊑ le in
let eq = F le' xψ in
co-trace-swap eq
co-maximal-2 : ∀{X φ} -> co-trace φ ∈ Maximal (CoSet X) -> φ ∈ Maximal X
co-maximal-2 {X} (maximal wit F) =
maximal (co-inversion {X} wit) λ le xψ -> let le' = ⊑-co-trace le in
let eq = F le' (co-definition {X} xψ) in
co-trace-injective eq
co-trace->co-set : ∀{X φ} -> co-trace φ ∈ Maximal X -> φ ∈ Maximal (CoSet X)
co-trace->co-set {_} {φ} cxφ with co-maximal cxφ
... | res rewrite co-trace-involution φ = res
discriminator-after-sync->defined :
∀{R T S T' φ} ->
T <: S ->
(rdef : Defined (discriminator T S))
(rr : Transitions (discriminator T S) (co-trace φ) R)
(tr : Transitions T φ T') ->
Defined R
discriminator-after-sync->defined {R} {T} {S} sub rdef rr tr with Defined? R
... | yes rdef' = rdef'
... | no nrdef' with defined-becomes-nil rdef nrdef' rr
... | ψ , x , eq , rψ , nrφ rewrite eq with input-does-not-win rψ rr
... | nwin with contraposition (decode+maximal->win (co-semantics (disc-set->semantics T S)) rψ) nwin
... | ncψ with decode-sub (co-semantics (disc-set->semantics T S)) rψ
... | dsψ with contraposition (disc-set-maximal-1 dsψ) (contraposition co-trace->co-set ncψ)
... | nnsψ with has-trace-double-negation nnsψ
... | sψ with (let tr' = subst (λ z -> Transitions _ z _) (co-trace-swap eq) tr in
let tr'' = subst (λ z -> Transitions _ z _) (co-trace-++ ψ (I x ∷ [])) tr' in
ends-with-output->has-trace tr'')
... | tψ with disc-set-has-outputs sub dsψ tψ sψ
... | dsφ with decode-sup (co-semantics (disc-set->semantics T S)) (co-definition {DiscSet T S} dsφ)
... | rφ = let rφ' = subst (_ HasTrace_) (co-trace-++ (co-trace ψ) (O x ∷ [])) rφ in
let rφ'' = subst (λ z -> _ HasTrace (z ++ _)) (co-trace-involution ψ) rφ' in
⊥-elim (nrφ rφ'')
after-trace-defined : ∀{T T' φ} -> T HasTrace φ -> Transitions T φ T' -> Defined T'
after-trace-defined (_ , def , refl) refl = def
after-trace-defined (_ , def , step inp tr) (step inp sr) = after-trace-defined (_ , def , tr) sr
after-trace-defined (_ , def , step (out _) tr) (step (out _) sr) = after-trace-defined (_ , def , tr) sr
after-trace-defined-2 : ∀{T φ} (tφ : T HasTrace φ) -> Defined (after tφ)
after-trace-defined-2 (_ , def , _) = def
⊑-after : ∀{φ ψ} -> φ ⊑ ψ -> Trace
⊑-after {_} {ψ} none = ψ
⊑-after (some le) = ⊑-after le
⊑-after-co-trace : ∀{φ ψ} (le : φ ⊑ ψ) -> ⊑-after (⊑-co-trace le) ≡ co-trace (⊑-after le)
⊑-after-co-trace none = refl
⊑-after-co-trace (some le) = ⊑-after-co-trace le
extend-transitions :
∀{T S φ ψ}
(le : φ ⊑ ψ)
(tr : Transitions T φ S)
(tψ : T HasTrace ψ) ->
Transitions S (⊑-after le) (after tψ)
extend-transitions none refl (_ , _ , sr) = sr
extend-transitions (some le) (step inp tr) (_ , sdef , step inp sr) = extend-transitions le tr (_ , sdef , sr)
extend-transitions (some le) (step (out _) tr) (_ , sdef , step (out _) sr) = extend-transitions le tr (_ , sdef , sr)
discriminator-compliant : ∀{T S} -> T <: S -> T ↑ S -> FairComplianceS (discriminator T S # T)
discriminator-compliant {T} {S} sub div {R' # T'} reds with unzip-red* reds
... | φ , rr , tr with sub+diverge->discriminator-defined sub div | sub+diverge->defined sub div
... | rdef | tdef , sdef with discriminator-after-sync->defined sub rdef rr tr
... | rdef' with decode-sub (co-semantics (disc-set->semantics T S)) (_ , rdef' , rr)
... | dsφ rewrite co-trace-involution φ =
case completion sub dsφ of
λ { (inj₁ (ψ , lt , cψ@(maximal dsψ _))) ->
let rψ = decode-sup (co-semantics (disc-set->semantics T S)) (co-definition {DiscSet T S} dsψ) in
let tψ = disc-set-subset dsψ in
let rr' = subst (λ z -> Transitions _ z _) (⊑-after-co-trace (⊏->⊑ lt)) (extend-transitions (⊑-co-trace (⊏->⊑ lt)) rr rψ) in
let tr' = extend-transitions (⊏->⊑ lt) tr tψ in
let winr = decode+maximal->win (co-semantics (disc-set->semantics T S)) rψ (co-maximal cψ) in
let reds' = zip-red* rr' tr' in
_ , reds' , win#def winr (after-trace-defined-2 tψ)
; (inj₂ (cφ , nsφ)) ->
let winr = decode+maximal->win (co-semantics (disc-set->semantics T S)) (_ , rdef' , rr) (co-maximal cφ) in
_ , ε , win#def winr (after-trace-defined (disc-set-subset dsφ) tr) }
discriminator-not-compliant : ∀{T S} -> T <: S -> T ↑ S -> ¬ FairComplianceS (discriminator T S # S)
discriminator-not-compliant {T} {S} sub div comp with comp ε
... | _ , reds , win#def w def with unzip-red* reds
... | φ , rr , sr with decode+win->maximal (co-semantics (disc-set->semantics T S)) (_ , win->defined w , rr) w
... | cφ with co-maximal-2 {DiscSet T S} cφ
... | csφ with disc-set-maximal-2 sub csφ
... | nsφ = nsφ (_ , def , sr)
|
{
"alphanum_fraction": 0.6372328459,
"avg_line_length": 49.1936758893,
"ext": "agda",
"hexsha": "619435d86b8eb31995758505e6aa6a507e99efa6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "src/Discriminator.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "src/Discriminator.agda",
"max_line_length": 186,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "src/Discriminator.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 4340,
"size": 12446
}
|
------------------------------------------------------------------------
-- A type for values that should be erased at run-time
------------------------------------------------------------------------
-- Most of the definitions in this module are reexported, in one way
-- or another, from Erased.
-- This module imports Function-universe, but not Equivalence.Erased.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Erased.Level-1
{e⁺} (eq-J : ∀ {a p} → Equality-with-J a p e⁺) where
open Derived-definitions-and-properties eq-J
hiding (module Extensionality)
open import Logical-equivalence using (_⇔_)
open import Prelude hiding ([_,_])
open import Bijection eq-J as Bijection using (_↔_; Has-quasi-inverse)
open import Embedding eq-J as Emb using (Embedding; Is-embedding)
open import Equality.Decidable-UIP eq-J
open import Equivalence eq-J as Eq using (_≃_; Is-equivalence)
import Equivalence.Contractible-preimages eq-J as CP
open import Equivalence.Erased.Basics eq-J as EEq
using (_≃ᴱ_; Is-equivalenceᴱ)
open import Equivalence-relation eq-J
open import Function-universe eq-J as F hiding (id; _∘_)
open import H-level eq-J as H-level
open import H-level.Closure eq-J
open import Injection eq-J using (_↣_; Injective)
open import Monad eq-J hiding (map; map-id; map-∘)
open import Preimage eq-J using (_⁻¹_)
open import Surjection eq-J as Surjection using (_↠_; Split-surjective)
open import Univalence-axiom eq-J as U using (≡⇒→; _²/≡)
private
variable
a b c d ℓ ℓ₁ ℓ₂ q r : Level
A B : Type a
eq k k′ p x y : A
P : A → Type p
f g : A → B
n : ℕ
------------------------------------------------------------------------
-- Some basic definitions
open import Erased.Basics public
------------------------------------------------------------------------
-- Stability
mutual
-- A type A is stable if Erased A implies A.
Stable : Type a → Type a
Stable = Stable-[ implication ]
-- A generalisation of Stable.
Stable-[_] : Kind → Type a → Type a
Stable-[ k ] A = Erased A ↝[ k ] A
-- A variant of Stable-[ equivalence ].
Very-stable : Type a → Type a
Very-stable A = Is-equivalence [ A ∣_]→
-- A variant of Stable-[ equivalenceᴱ ].
Very-stableᴱ : Type a → Type a
Very-stableᴱ A = Is-equivalenceᴱ [ A ∣_]→
-- Variants of the definitions above for equality.
Stable-≡ : Type a → Type a
Stable-≡ = For-iterated-equality 1 Stable
Stable-≡-[_] : Kind → Type a → Type a
Stable-≡-[ k ] = For-iterated-equality 1 Stable-[ k ]
Very-stable-≡ : Type a → Type a
Very-stable-≡ = For-iterated-equality 1 Very-stable
Very-stableᴱ-≡ : Type a → Type a
Very-stableᴱ-≡ = For-iterated-equality 1 Very-stableᴱ
------------------------------------------------------------------------
-- Erased is a monad
-- A universe-polymorphic variant of bind.
infixl 5 _>>=′_
_>>=′_ :
{@0 A : Type a} {@0 B : Type b} →
Erased A → (A → Erased B) → Erased B
x >>=′ f = [ erased (f (erased x)) ]
instance
-- Erased is a monad.
raw-monad : Raw-monad (λ (A : Type a) → Erased A)
Raw-monad.return raw-monad = [_]→
Raw-monad._>>=_ raw-monad = _>>=′_
monad : Monad (λ (A : Type a) → Erased A)
Monad.raw-monad monad = raw-monad
Monad.left-identity monad = λ _ _ → refl _
Monad.right-identity monad = λ _ → refl _
Monad.associativity monad = λ _ _ _ → refl _
------------------------------------------------------------------------
-- Erased preserves some kinds of functions
-- Erased is functorial for dependent functions.
map-id : {@0 A : Type a} → map id ≡ id {A = Erased A}
map-id = refl _
map-∘ :
{@0 A : Type a} {@0 P : A → Type b} {@0 Q : {x : A} → P x → Type c}
(@0 f : ∀ {x} (y : P x) → Q y) (@0 g : (x : A) → P x) →
map (f ∘ g) ≡ map f ∘ map g
map-∘ _ _ = refl _
-- Erased preserves logical equivalences.
Erased-cong-⇔ :
{@0 A : Type a} {@0 B : Type b} →
@0 A ⇔ B → Erased A ⇔ Erased B
Erased-cong-⇔ A⇔B = record
{ to = map (_⇔_.to A⇔B)
; from = map (_⇔_.from A⇔B)
}
-- Erased is functorial for logical equivalences.
Erased-cong-⇔-id :
{@0 A : Type a} →
Erased-cong-⇔ F.id ≡ F.id {A = Erased A}
Erased-cong-⇔-id = refl _
Erased-cong-⇔-∘ :
{@0 A : Type a} {@0 B : Type b} {@0 C : Type c}
(@0 f : B ⇔ C) (@0 g : A ⇔ B) →
Erased-cong-⇔ (f F.∘ g) ≡ Erased-cong-⇔ f F.∘ Erased-cong-⇔ g
Erased-cong-⇔-∘ _ _ = refl _
-- Erased preserves equivalences with erased proofs.
Erased-cong-≃ᴱ :
{@0 A : Type a} {@0 B : Type b} →
@0 A ≃ᴱ B → Erased A ≃ᴱ Erased B
Erased-cong-≃ᴱ A≃ᴱB = EEq.↔→≃ᴱ
(map (_≃ᴱ_.to A≃ᴱB))
(map (_≃ᴱ_.from A≃ᴱB))
(cong [_]→ ∘ _≃ᴱ_.right-inverse-of A≃ᴱB ∘ erased)
(cong [_]→ ∘ _≃ᴱ_.left-inverse-of A≃ᴱB ∘ erased)
------------------------------------------------------------------------
-- Some isomorphisms
-- In an erased context Erased A is always isomorphic to A.
Erased↔ : {@0 A : Type a} → Erased (Erased A ↔ A)
Erased↔ = [ record
{ surjection = record
{ logical-equivalence = record
{ to = erased
; from = [_]→
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
} ]
-- The following result is based on a result in Mishra-Linger's PhD
-- thesis (see Section 5.4.4).
-- Erased (Erased A) is isomorphic to Erased A.
Erased-Erased↔Erased :
{@0 A : Type a} →
Erased (Erased A) ↔ Erased A
Erased-Erased↔Erased = record
{ surjection = record
{ logical-equivalence = record
{ to = λ x → [ erased (erased x) ]
; from = [_]→
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
-- Erased ⊤ is isomorphic to ⊤.
Erased-⊤↔⊤ : Erased ⊤ ↔ ⊤
Erased-⊤↔⊤ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ _ → tt
; from = [_]→
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
-- Erased ⊥ is isomorphic to ⊥.
Erased-⊥↔⊥ : Erased (⊥ {ℓ = ℓ}) ↔ ⊥ {ℓ = ℓ}
Erased-⊥↔⊥ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { [ () ] }
; from = [_]→
}
; right-inverse-of = λ ()
}
; left-inverse-of = λ { [ () ] }
}
-- Erased commutes with Π A.
Erased-Π↔Π :
{@0 P : A → Type p} →
Erased ((x : A) → P x) ↔ ((x : A) → Erased (P x))
Erased-Π↔Π = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { [ f ] x → [ f x ] }
; from = λ f → [ (λ x → erased (f x)) ]
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
-- A variant of Erased-Π↔Π.
Erased-Π≃ᴱΠ :
{@0 A : Type a} {@0 P : A → Type p} →
Erased ((x : A) → P x) ≃ᴱ ((x : A) → Erased (P x))
Erased-Π≃ᴱΠ = EEq.[≃]→≃ᴱ (EEq.[proofs] $ from-isomorphism Erased-Π↔Π)
-- Erased commutes with Π.
Erased-Π↔Π-Erased :
{@0 A : Type a} {@0 P : A → Type p} →
Erased ((x : A) → P x) ↔ ((x : Erased A) → Erased (P (erased x)))
Erased-Π↔Π-Erased = record
{ surjection = record
{ logical-equivalence = record
{ to = λ ([ f ]) → map f
; from = λ f → [ (λ x → erased (f [ x ])) ]
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
-- Erased commutes with Σ.
Erased-Σ↔Σ :
{@0 A : Type a} {@0 P : A → Type p} →
Erased (Σ A P) ↔ Σ (Erased A) (λ x → Erased (P (erased x)))
Erased-Σ↔Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { [ p ] → [ proj₁ p ] , [ proj₂ p ] }
; from = λ { ([ x ] , [ y ]) → [ x , y ] }
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
-- Erased commutes with ↑ ℓ.
Erased-↑↔↑ :
{@0 A : Type a} →
Erased (↑ ℓ A) ↔ ↑ ℓ (Erased A)
Erased-↑↔↑ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { [ x ] → lift [ lower x ] }
; from = λ { (lift [ x ]) → [ lift x ] }
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
-- Erased commutes with ¬_ (assuming extensionality).
Erased-¬↔¬ :
{@0 A : Type a} →
Erased (¬ A) ↝[ a ∣ lzero ] ¬ Erased A
Erased-¬↔¬ {A = A} ext =
Erased (A → ⊥) ↔⟨ Erased-Π↔Π-Erased ⟩
(Erased A → Erased ⊥) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-⊥↔⊥) ⟩□
(Erased A → ⊥) □
-- Erased can be dropped under ¬_ (assuming extensionality).
¬-Erased↔¬ :
{A : Type a} →
¬ Erased A ↝[ a ∣ lzero ] ¬ A
¬-Erased↔¬ {a = a} {A = A} =
generalise-ext?-prop
(record
{ to = λ ¬[a] a → ¬[a] [ a ]
; from = λ ¬a ([ a ]) → _↔_.to Erased-⊥↔⊥ [ ¬a a ]
})
¬-propositional
¬-propositional
-- The following three results are inspired by a result in
-- Mishra-Linger's PhD thesis (see Section 5.4.1).
--
-- See also Π-Erased↔Π0[], Π-Erased≃Π0[], Π-Erased↔Π0 and Π-Erased≃Π0
-- in Erased.Cubical and Erased.With-K.
-- There is a logical equivalence between
-- (x : Erased A) → P (erased x) and (@0 x : A) → P x.
Π-Erased⇔Π0 :
{@0 A : Type a} {@0 P : A → Type p} →
((x : Erased A) → P (erased x)) ⇔ ((@0 x : A) → P x)
Π-Erased⇔Π0 = record
{ to = λ f x → f [ x ]
; from = λ f ([ x ]) → f x
}
-- There is an equivalence with erased proofs between
-- (x : Erased A) → P (erased x) and (@0 x : A) → P x.
Π-Erased≃ᴱΠ0 :
{@0 A : Type a} {@0 P : A → Type p} →
((x : Erased A) → P (erased x)) ≃ᴱ ((@0 x : A) → P x)
Π-Erased≃ᴱΠ0 = EEq.↔→≃ᴱ
(_⇔_.to Π-Erased⇔Π0)
(_⇔_.from Π-Erased⇔Π0)
refl
refl
-- There is an equivalence between (x : Erased A) → P (erased x) and
-- (@0 x : A) → P x.
Π-Erased≃Π0 :
{@0 A : Type a} {P : @0 A → Type p} →
((x : Erased A) → P (erased x)) ≃ ((@0 x : A) → P x)
Π-Erased≃Π0 {A = A} {P = P} =
Eq.↔→≃ {B = (@0 x : A) → P x}
(_⇔_.to Π-Erased⇔Π0)
(_⇔_.from Π-Erased⇔Π0)
(λ _ → refl {A = (@0 x : A) → P x} _)
(λ _ → refl _)
-- A variant of Π-Erased≃Π0.
Π-Erased≃Π0[] :
{@0 A : Type a} {P : Erased A → Type p} →
((x : Erased A) → P x) ≃ ((@0 x : A) → P [ x ])
Π-Erased≃Π0[] = Π-Erased≃Π0
-- Erased commutes with W up to logical equivalence.
Erased-W⇔W :
{@0 A : Type a} {@0 P : A → Type p} →
Erased (W A P) ⇔ W (Erased A) (λ x → Erased (P (erased x)))
Erased-W⇔W {A = A} {P = P} = record { to = to; from = from }
where
to : Erased (W A P) → W (Erased A) (λ x → Erased (P (erased x)))
to [ sup x f ] = sup [ x ] (λ ([ y ]) → to [ f y ])
from : W (Erased A) (λ x → Erased (P (erased x))) → Erased (W A P)
from (sup [ x ] f) = [ sup x (λ y → erased (from (f [ y ]))) ]
----------------------------------------------------------------------
-- Erased is a modality
-- Erased is the modal operator of a uniquely eliminating modality
-- with [_]→ as the modal unit.
--
-- The terminology here roughly follows that of "Modalities in
-- Homotopy Type Theory" by Rijke, Shulman and Spitters.
uniquely-eliminating-modality :
{@0 P : Erased A → Type p} →
Is-equivalence
(λ (f : (x : Erased A) → Erased (P x)) → f ∘ [ A ∣_]→)
uniquely-eliminating-modality {A = A} {P = P} =
_≃_.is-equivalence
(((x : Erased A) → Erased (P x)) ↔⟨ inverse Erased-Π↔Π-Erased ⟩
Erased ((x : A) → (P [ x ])) ↔⟨ Erased-Π↔Π ⟩
((x : A) → Erased (P [ x ])) □)
-- Two results that are closely related to
-- uniquely-eliminating-modality.
--
-- These results are based on the Coq source code accompanying
-- "Modalities in Homotopy Type Theory" by Rijke, Shulman and
-- Spitters.
-- Precomposition with [_]→ is injective for functions from Erased A
-- to Erased B.
∘-[]-injective :
{@0 B : Type b} →
Injective (λ (f : Erased A → Erased B) → f ∘ [_]→)
∘-[]-injective = _≃_.injective Eq.⟨ _ , uniquely-eliminating-modality ⟩
-- A rearrangement lemma for ext⁻¹ and ∘-[]-injective.
ext⁻¹-∘-[]-injective :
{@0 B : Type b} {f g : Erased A → Erased B} {p : f ∘ [_]→ ≡ g ∘ [_]→} →
ext⁻¹ (∘-[]-injective {x = f} {y = g} p) [ x ] ≡ ext⁻¹ p x
ext⁻¹-∘-[]-injective {x = x} {f = f} {g = g} {p = p} =
ext⁻¹ (∘-[]-injective p) [ x ] ≡⟨ elim₁
(λ p → ext⁻¹ p [ x ] ≡ ext⁻¹ (_≃_.from equiv p) x) (
ext⁻¹ (refl g) [ x ] ≡⟨ cong-refl (_$ [ x ]) ⟩
refl (g [ x ]) ≡⟨ sym $ cong-refl _ ⟩
ext⁻¹ (refl (g ∘ [_]→)) x ≡⟨ cong (λ p → ext⁻¹ p x) $ sym $ cong-refl _ ⟩∎
ext⁻¹ (_≃_.from equiv (refl g)) x ∎)
(∘-[]-injective p) ⟩
ext⁻¹ (_≃_.from equiv (∘-[]-injective p)) x ≡⟨ cong (flip ext⁻¹ x) $ _≃_.left-inverse-of equiv _ ⟩∎
ext⁻¹ p x ∎
where
equiv = Eq.≃-≡ Eq.⟨ _ , uniquely-eliminating-modality ⟩
----------------------------------------------------------------------
-- Some lemmas related to functions with erased domains
-- A variant of H-level.Π-closure for function spaces with erased
-- explicit domains. Note the type of P.
Πᴱ-closure :
{@0 A : Type a} {P : @0 A → Type p} →
Extensionality a p →
∀ n →
((@0 x : A) → H-level n (P x)) →
H-level n ((@0 x : A) → P x)
Πᴱ-closure {P = P} ext n =
(∀ (@0 x) → H-level n (P x)) →⟨ Eq._≃₀_.from Π-Erased≃Π0 ⟩
(∀ x → H-level n (P (x .erased))) →⟨ Π-closure ext n ⟩
H-level n (∀ x → P (x .erased)) →⟨ H-level-cong {B = ∀ (@0 x) → P x} _ n Π-Erased≃Π0 ⟩□
H-level n (∀ (@0 x) → P x) □
-- A variant of H-level.Π-closure for function spaces with erased
-- implicit domains. Note the type of P.
implicit-Πᴱ-closure :
{@0 A : Type a} {P : @0 A → Type p} →
Extensionality a p →
∀ n →
((@0 x : A) → H-level n (P x)) →
H-level n ({@0 x : A} → P x)
implicit-Πᴱ-closure {A = A} {P = P} ext n =
(∀ (@0 x) → H-level n (P x)) →⟨ Πᴱ-closure ext n ⟩
H-level n (∀ (@0 x) → P x) →⟨ H-level-cong {A = ∀ (@0 x) → P x} {B = ∀ {@0 x} → P x} _ n $
inverse {A = ∀ {@0 x} → P x} {B = ∀ (@0 x) → P x}
Bijection.implicit-Πᴱ↔Πᴱ′ ⟩□
H-level n (∀ {@0 x} → P x) □
-- Extensionality implies extensionality for some functions with
-- erased arguments (note the type of P).
apply-extᴱ :
{@0 A : Type a} {P : @0 A → Type p} {f g : (@0 x : A) → P x} →
Extensionality a p →
((@0 x : A) → f x ≡ g x) →
f ≡ g
apply-extᴱ {A = A} {P = P} {f = f} {g = g} ext =
((@0 x : A) → f x ≡ g x) →⟨ Eq._≃₀_.from Π-Erased≃Π0 ⟩
((x : Erased A) → f (x .erased) ≡ g (x .erased)) →⟨ apply-ext ext ⟩
(λ x → f (x .erased)) ≡ (λ x → g (x .erased)) →⟨ cong {B = (@0 x : A) → P x} (Eq._≃₀_.to Π-Erased≃Π0) ⟩□
f ≡ g □
-- Extensionality implies extensionality for some functions with
-- implicit erased arguments (note the type of P).
implicit-apply-extᴱ :
{@0 A : Type a} {P : @0 A → Type p} {f g : {@0 x : A} → P x} →
Extensionality a p →
((@0 x : A) → f {x = x} ≡ g {x = x}) →
_≡_ {A = {@0 x : A} → P x} f g
implicit-apply-extᴱ {A = A} {P = P} {f = f} {g = g} ext =
((@0 x : A) → f {x = x} ≡ g {x = x}) →⟨ apply-extᴱ ext ⟩
_≡_ {A = (@0 x : A) → P x} (λ x → f {x = x}) (λ x → g {x = x}) →⟨ cong {A = (@0 x : A) → P x} {B = {@0 x : A} → P x} (λ f {x = x} → f x) ⟩□
_≡_ {A = {@0 x : A} → P x} f g □
------------------------------------------------------------------------
-- A variant of Dec ∘ Erased
-- Dec-Erased A means that either we have A (erased), or we have ¬ A
-- (also erased).
Dec-Erased : @0 Type ℓ → Type ℓ
Dec-Erased A = Erased A ⊎ Erased (¬ A)
-- Dec A implies Dec-Erased A.
Dec→Dec-Erased :
{@0 A : Type a} → Dec A → Dec-Erased A
Dec→Dec-Erased (yes a) = yes [ a ]
Dec→Dec-Erased (no ¬a) = no [ ¬a ]
-- In erased contexts Dec-Erased A is equivalent to Dec A.
@0 Dec-Erased≃Dec :
{@0 A : Type a} → Dec-Erased A ≃ Dec A
Dec-Erased≃Dec {A = A} =
Eq.with-other-inverse
(Erased A ⊎ Erased (¬ A) ↔⟨ erased Erased↔ ⊎-cong erased Erased↔ ⟩□
A ⊎ ¬ A □)
Dec→Dec-Erased
Prelude.[ (λ _ → refl _) , (λ _ → refl _) ]
-- Dec-Erased A is isomorphic to Dec (Erased A) (assuming
-- extensionality).
Dec-Erased↔Dec-Erased :
{@0 A : Type a} →
Dec-Erased A ↝[ a ∣ lzero ] Dec (Erased A)
Dec-Erased↔Dec-Erased {A = A} ext =
Erased A ⊎ Erased (¬ A) ↝⟨ F.id ⊎-cong Erased-¬↔¬ ext ⟩□
Erased A ⊎ ¬ Erased A □
-- A map function for Dec-Erased.
Dec-Erased-map :
{@0 A : Type a} {@0 B : Type b} →
@0 A ⇔ B → Dec-Erased A → Dec-Erased B
Dec-Erased-map A⇔B =
⊎-map (map (_⇔_.to A⇔B))
(map (_∘ _⇔_.from A⇔B))
-- Dec-Erased preserves logical equivalences.
Dec-Erased-cong-⇔ :
{@0 A : Type a} {@0 B : Type b} →
@0 A ⇔ B → Dec-Erased A ⇔ Dec-Erased B
Dec-Erased-cong-⇔ A⇔B = record
{ to = Dec-Erased-map A⇔B
; from = Dec-Erased-map (inverse A⇔B)
}
-- If A and B are decided (with erased proofs), then A × B is.
Dec-Erased-× :
{@0 A : Type a} {@0 B : Type b} →
Dec-Erased A → Dec-Erased B → Dec-Erased (A × B)
Dec-Erased-× (no [ ¬a ]) _ = no [ ¬a ∘ proj₁ ]
Dec-Erased-× _ (no [ ¬b ]) = no [ ¬b ∘ proj₂ ]
Dec-Erased-× (yes [ a ]) (yes [ b ]) = yes [ a , b ]
-- If A and B are decided (with erased proofs), then A ⊎ B is.
Dec-Erased-⊎ :
{@0 A : Type a} {@0 B : Type b} →
Dec-Erased A → Dec-Erased B → Dec-Erased (A ⊎ B)
Dec-Erased-⊎ (yes [ a ]) _ = yes [ inj₁ a ]
Dec-Erased-⊎ (no [ ¬a ]) (yes [ b ]) = yes [ inj₂ b ]
Dec-Erased-⊎ (no [ ¬a ]) (no [ ¬b ]) = no [ Prelude.[ ¬a , ¬b ] ]
-- A variant of Equality.Decision-procedures.×.dec⇒dec⇒dec.
dec-erased⇒dec-erased⇒×-dec-erased :
{@0 A : Type a} {@0 B : Type b} {@0 x₁ x₂ : A} {@0 y₁ y₂ : B} →
Dec-Erased (x₁ ≡ x₂) →
Dec-Erased (y₁ ≡ y₂) →
Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂))
dec-erased⇒dec-erased⇒×-dec-erased = λ where
(no [ x₁≢x₂ ]) _ → no [ x₁≢x₂ ∘ cong proj₁ ]
_ (no [ y₁≢y₂ ]) → no [ y₁≢y₂ ∘ cong proj₂ ]
(yes [ x₁≡x₂ ]) (yes [ y₁≡y₂ ]) → yes [ cong₂ _,_ x₁≡x₂ y₁≡y₂ ]
-- A variant of Equality.Decision-procedures.Σ.set⇒dec⇒dec⇒dec.
--
-- See also set⇒dec-erased⇒dec-erased⇒Σ-dec-erased below.
set⇒dec⇒dec-erased⇒Σ-dec-erased :
{@0 A : Type a} {@0 P : A → Type p}
{@0 x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} →
@0 Is-set A →
Dec (x₁ ≡ x₂) →
(∀ eq → Dec-Erased (subst P eq y₁ ≡ y₂)) →
Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂))
set⇒dec⇒dec-erased⇒Σ-dec-erased _ (no x₁≢x₂) _ =
no [ x₁≢x₂ ∘ cong proj₁ ]
set⇒dec⇒dec-erased⇒Σ-dec-erased
{P = P} {y₁ = y₁} {y₂ = y₂} set₁ (yes x₁≡x₂) dec₂ =
⊎-map
(map (Σ-≡,≡→≡ x₁≡x₂))
(map λ cast-y₁≢y₂ eq →
$⟨ proj₂ (Σ-≡,≡←≡ eq) ⟩
subst P (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ subst (λ p → subst _ p _ ≡ _) (set₁ _ _) ⟩
subst P x₁≡x₂ y₁ ≡ y₂ ↝⟨ cast-y₁≢y₂ ⟩□
⊥ □)
(dec₂ x₁≡x₂)
-- A variant of Equality.Decision-procedures.Σ.decidable⇒dec⇒dec.
--
-- See also decidable-erased⇒dec-erased⇒Σ-dec-erased below.
decidable⇒dec-erased⇒Σ-dec-erased :
{@0 A : Type a} {@0 P : A → Type p}
{x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} →
Decidable-equality A →
(∀ eq → Dec-Erased (subst P eq y₁ ≡ y₂)) →
Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂))
decidable⇒dec-erased⇒Σ-dec-erased dec =
set⇒dec⇒dec-erased⇒Σ-dec-erased
(decidable⇒set dec)
(dec _ _)
------------------------------------------------------------------------
-- Decidable erased equality
-- A variant of Decidable-equality that is defined using Dec-Erased.
Decidable-erased-equality : Type ℓ → Type ℓ
Decidable-erased-equality A = (x y : A) → Dec-Erased (x ≡ y)
-- Decidable equality implies decidable erased equality.
Decidable-equality→Decidable-erased-equality :
{@0 A : Type a} →
Decidable-equality A →
Decidable-erased-equality A
Decidable-equality→Decidable-erased-equality dec x y =
Dec→Dec-Erased (dec x y)
-- In erased contexts Decidable-erased-equality A is equivalent to
-- Decidable-equality A (assuming extensionality).
@0 Decidable-erased-equality≃Decidable-equality :
{A : Type a} →
Decidable-erased-equality A ↝[ a ∣ a ] Decidable-equality A
Decidable-erased-equality≃Decidable-equality {A = A} ext =
((x y : A) → Dec-Erased (x ≡ y)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → from-equivalence Dec-Erased≃Dec) ⟩□
((x y : A) → Dec (x ≡ y)) □
-- A map function for Decidable-erased-equality.
Decidable-erased-equality-map :
A ↠ B →
Decidable-erased-equality A → Decidable-erased-equality B
Decidable-erased-equality-map A↠B _≟_ x y = $⟨ _↠_.from A↠B x ≟ _↠_.from A↠B y ⟩
Dec-Erased (_↠_.from A↠B x ≡ _↠_.from A↠B y) ↝⟨ Dec-Erased-map (_↠_.logical-equivalence $ Surjection.↠-≡ A↠B) ⟩□
Dec-Erased (x ≡ y) □
-- A variant of Equality.Decision-procedures.×.Dec._≟_.
decidable-erased⇒decidable-erased⇒×-decidable-erased :
{@0 A : Type a} {@0 B : Type b} →
Decidable-erased-equality A →
Decidable-erased-equality B →
Decidable-erased-equality (A × B)
decidable-erased⇒decidable-erased⇒×-decidable-erased decA decB _ _ =
dec-erased⇒dec-erased⇒×-dec-erased (decA _ _) (decB _ _)
-- A variant of Equality.Decision-procedures.Σ.Dec._≟_.
--
-- See also decidable-erased⇒decidable-erased⇒Σ-decidable-erased
-- below.
decidable⇒decidable-erased⇒Σ-decidable-erased :
Decidable-equality A →
({x : A} → Decidable-erased-equality (P x)) →
Decidable-erased-equality (Σ A P)
decidable⇒decidable-erased⇒Σ-decidable-erased
{P = P} decA decP (_ , x₂) (_ , y₂) =
decidable⇒dec-erased⇒Σ-dec-erased
decA
(λ eq → decP (subst P eq x₂) y₂)
------------------------------------------------------------------------
-- Erased binary relations
-- Lifts binary relations from A to Erased A.
Erasedᴾ :
{@0 A : Type a} {@0 B : Type b} →
@0 (A → B → Type r) →
(Erased A → Erased B → Type r)
Erasedᴾ R [ x ] [ y ] = Erased (R x y)
-- Erasedᴾ preserves Is-equivalence-relation.
Erasedᴾ-preserves-Is-equivalence-relation :
{@0 A : Type a} {@0 R : A → A → Type r} →
@0 Is-equivalence-relation R →
Is-equivalence-relation (Erasedᴾ R)
Erasedᴾ-preserves-Is-equivalence-relation equiv = λ where
.Is-equivalence-relation.reflexive →
[ equiv .Is-equivalence-relation.reflexive ]
.Is-equivalence-relation.symmetric →
map (equiv .Is-equivalence-relation.symmetric)
.Is-equivalence-relation.transitive →
zip (equiv .Is-equivalence-relation.transitive)
------------------------------------------------------------------------
-- Some results that hold in erased contexts
-- In an erased context there is an equivalence between equality of
-- "boxed" values and equality of values.
@0 []≡[]≃≡ : ([ x ] ≡ [ y ]) ≃ (x ≡ y)
[]≡[]≃≡ = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = cong erased
; from = cong [_]→
}
; right-inverse-of = λ eq →
cong erased (cong [_]→ eq) ≡⟨ cong-∘ _ _ _ ⟩
cong id eq ≡⟨ sym $ cong-id _ ⟩∎
eq ∎
}
; left-inverse-of = λ eq →
cong [_]→ (cong erased eq) ≡⟨ cong-∘ _ _ _ ⟩
cong id eq ≡⟨ sym $ cong-id _ ⟩∎
eq ∎
})
-- In an erased context [_]→ is always an embedding.
Erased-Is-embedding-[] :
{@0 A : Type a} → Erased (Is-embedding [ A ∣_]→)
Erased-Is-embedding-[] =
[ (λ x y → _≃_.is-equivalence (
x ≡ y ↝⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse $ erased Erased↔ ⟩□
[ x ] ≡ [ y ] □))
]
-- In an erased context [_]→ is always split surjective.
Erased-Split-surjective-[] :
{@0 A : Type a} → Erased (Split-surjective [ A ∣_]→)
Erased-Split-surjective-[] = [ (λ ([ x ]) → x , refl _) ]
------------------------------------------------------------------------
-- []-cong-axiomatisation
-- An axiomatisation for []-cong.
--
-- In addition to the results in this section, see
-- []-cong-axiomatisation-propositional below.
record []-cong-axiomatisation a : Type (lsuc a) where
field
[]-cong :
{@0 A : Type a} {@0 x y : A} →
Erased (x ≡ y) → [ x ] ≡ [ y ]
[]-cong-equivalence :
{@0 A : Type a} {@0 x y : A} →
Is-equivalence ([]-cong {x = x} {y = y})
[]-cong-[refl] :
{@0 A : Type a} {@0 x : A} →
[]-cong [ refl x ] ≡ refl [ x ]
-- The []-cong axioms can be instantiated in erased contexts.
@0 erased-instance-of-[]-cong-axiomatisation :
[]-cong-axiomatisation a
erased-instance-of-[]-cong-axiomatisation
.[]-cong-axiomatisation.[]-cong =
cong [_]→ ∘ erased
erased-instance-of-[]-cong-axiomatisation
.[]-cong-axiomatisation.[]-cong-equivalence {x = x} {y = y} =
_≃_.is-equivalence
(Erased (x ≡ y) ↔⟨ erased Erased↔ ⟩
x ≡ y ↝⟨ inverse []≡[]≃≡ ⟩□
[ x ] ≡ [ y ] □)
erased-instance-of-[]-cong-axiomatisation
.[]-cong-axiomatisation.[]-cong-[refl] {x = x} =
cong [_]→ (erased [ refl x ]) ≡⟨⟩
cong [_]→ (refl x) ≡⟨ cong-refl _ ⟩∎
refl [ x ] ∎
-- If the []-cong axioms can be implemented for a certain universe
-- level, then they can also be implemented for all smaller universe
-- levels.
lower-[]-cong-axiomatisation :
∀ a′ → []-cong-axiomatisation (a ⊔ a′) → []-cong-axiomatisation a
lower-[]-cong-axiomatisation {a = a} a′ ax = λ where
.[]-cong-axiomatisation.[]-cong → []-cong′
.[]-cong-axiomatisation.[]-cong-equivalence → []-cong′-equivalence
.[]-cong-axiomatisation.[]-cong-[refl] → []-cong′-[refl]
where
open []-cong-axiomatisation ax
lemma :
{@0 A : Type a} {@0 x y : A} →
Erased (lift {ℓ = a′} x ≡ lift y) ≃ ([ x ] ≡ [ y ])
lemma {x = x} {y = y} =
Erased (lift {ℓ = a′} x ≡ lift y) ↝⟨ Eq.⟨ _ , []-cong-equivalence ⟩ ⟩
[ lift x ] ≡ [ lift y ] ↝⟨ inverse $ Eq.≃-≡ (Eq.↔→≃ (map lower) (map lift) refl refl) ⟩□
[ x ] ≡ [ y ] □
[]-cong′ :
{@0 A : Type a} {@0 x y : A} →
Erased (x ≡ y) → [ x ] ≡ [ y ]
[]-cong′ {x = x} {y = y} =
Erased (x ≡ y) ↝⟨ map (cong lift) ⟩
Erased (lift {ℓ = a′} x ≡ lift y) ↔⟨ lemma ⟩□
[ x ] ≡ [ y ] □
[]-cong′-equivalence :
{@0 A : Type a} {@0 x y : A} →
Is-equivalence ([]-cong′ {x = x} {y = y})
[]-cong′-equivalence {x = x} {y = y} =
_≃_.is-equivalence
(Erased (x ≡ y) ↝⟨ Eq.↔→≃ (map (cong lift)) (map (cong lower))
(λ ([ eq ]) →
[ cong lift (cong lower eq) ] ≡⟨ []-cong [ cong-∘ _ _ _ ] ⟩
[ cong id eq ] ≡⟨ []-cong [ sym $ cong-id _ ] ⟩∎
[ eq ] ∎)
(λ ([ eq ]) →
[ cong lower (cong lift eq) ] ≡⟨ []-cong′ [ cong-∘ _ _ _ ] ⟩
[ cong id eq ] ≡⟨ []-cong′ [ sym $ cong-id _ ] ⟩∎
[ eq ] ∎) ⟩
Erased (lift {ℓ = a′} x ≡ lift y) ↝⟨ lemma ⟩□
[ x ] ≡ [ y ] □)
[]-cong′-[refl] :
{@0 A : Type a} {@0 x : A} →
[]-cong′ [ refl x ] ≡ refl [ x ]
[]-cong′-[refl] {x = x} =
cong (map lower) ([]-cong [ cong lift (refl x) ]) ≡⟨ cong (cong (map lower) ∘ []-cong) $ []-cong [ cong-refl _ ] ⟩
cong (map lower) ([]-cong [ refl (lift x) ]) ≡⟨ cong (cong (map lower)) []-cong-[refl] ⟩
cong (map lower) (refl [ lift x ]) ≡⟨ cong-refl _ ⟩∎
refl [ x ] ∎
------------------------------------------------------------------------
-- An alternative to []-cong-axiomatisation
-- Stable-≡-Erased-axiomatisation a is the property that equality is
-- stable for Erased A, for every erased type A : Type a, along with a
-- "computation" rule.
Stable-≡-Erased-axiomatisation : (a : Level) → Type (lsuc a)
Stable-≡-Erased-axiomatisation a =
∃ λ (Stable-≡-Erased : {@0 A : Type a} → Stable-≡ (Erased A)) →
{@0 A : Type a} {x : Erased A} →
Stable-≡-Erased x x [ refl x ] ≡ refl x
-- Some lemmas used to implement Extensionality→[]-cong as well as
-- Erased.Stability.[]-cong-axiomatisation≃Stable-≡-Erased-axiomatisation.
module Stable-≡-Erased-axiomatisation→[]-cong-axiomatisation
((Stable-≡-Erased , Stable-≡-Erased-[refl]) :
Stable-≡-Erased-axiomatisation a)
where
-- An implementation of []-cong.
[]-cong :
{@0 A : Type a} {@0 x y : A} →
Erased (x ≡ y) → [ x ] ≡ [ y ]
[]-cong {x = x} {y = y} =
Erased (x ≡ y) ↝⟨ map (cong [_]→) ⟩
Erased ([ x ] ≡ [ y ]) ↝⟨ Stable-≡-Erased _ _ ⟩□
[ x ] ≡ [ y ] □
-- A "computation rule" for []-cong.
[]-cong-[refl] :
{@0 A : Type a} {@0 x : A} →
[]-cong [ refl x ] ≡ refl [ x ]
[]-cong-[refl] {x = x} =
[]-cong [ refl x ] ≡⟨⟩
Stable-≡-Erased _ _ [ cong [_]→ (refl x) ] ≡⟨ cong (Stable-≡-Erased _ _) ([]-cong [ cong-refl _ ]) ⟩
Stable-≡-Erased _ _ [ refl [ x ] ] ≡⟨ Stable-≡-Erased-[refl] ⟩∎
refl [ x ] ∎
-- Equality is very stable for Erased A.
Very-stable-≡-Erased :
{@0 A : Type a} → Very-stable-≡ (Erased A)
Very-stable-≡-Erased x y =
_≃_.is-equivalence (Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ from = Stable-≡-Erased x y
}
; right-inverse-of = λ ([ eq ]) → []-cong [ lemma eq ]
}
; left-inverse-of = lemma
}))
where
lemma = elim¹
(λ eq → Stable-≡-Erased _ _ [ eq ] ≡ eq)
Stable-≡-Erased-[refl]
-- The following implementations of functions from Erased-cong
-- (below) are restricted to types in Type a (where a is the
-- universe level for which extensionality is assumed to hold).
module _ {@0 A B : Type a} where
Erased-cong-↠ : @0 A ↠ B → Erased A ↠ Erased B
Erased-cong-↠ A↠B = record
{ logical-equivalence = Erased-cong-⇔
(_↠_.logical-equivalence A↠B)
; right-inverse-of = λ { [ x ] →
[]-cong [ _↠_.right-inverse-of A↠B x ] }
}
Erased-cong-↔ : @0 A ↔ B → Erased A ↔ Erased B
Erased-cong-↔ A↔B = record
{ surjection = Erased-cong-↠ (_↔_.surjection A↔B)
; left-inverse-of = λ { [ x ] →
[]-cong [ _↔_.left-inverse-of A↔B x ] }
}
Erased-cong-≃ : @0 A ≃ B → Erased A ≃ Erased B
Erased-cong-≃ A≃B =
from-isomorphism (Erased-cong-↔ (from-isomorphism A≃B))
-- []-cong is an equivalence.
[]-cong-equivalence :
{@0 A : Type a} {@0 x y : A} →
Is-equivalence ([]-cong {x = x} {y = y})
[]-cong-equivalence {x = x} {y = y} = _≃_.is-equivalence (
Erased (x ≡ y) ↝⟨ inverse $ Erased-cong-≃ []≡[]≃≡ ⟩
Erased ([ x ] ≡ [ y ]) ↝⟨ inverse Eq.⟨ _ , Very-stable-≡-Erased _ _ ⟩ ⟩□
[ x ] ≡ [ y ] □)
-- The []-cong axioms can be instantiated.
instance-of-[]-cong-axiomatisation :
[]-cong-axiomatisation a
instance-of-[]-cong-axiomatisation = record
{ []-cong = []-cong
; []-cong-equivalence = []-cong-equivalence
; []-cong-[refl] = []-cong-[refl]
}
------------------------------------------------------------------------
-- In the presence of function extensionality the []-cong axioms can
-- be instantiated
-- Some lemmas used to implement
-- Extensionality→[]-cong-axiomatisation.
module Extensionality→[]-cong-axiomatisation
(ext′ : Extensionality a a)
where
private
ext = Eq.good-ext ext′
-- Equality is stable for Erased A.
--
-- The proof is based on the proof of Lemma 1.25 in "Modalities in
-- Homotopy Type Theory" by Rijke, Shulman and Spitters, and the
-- corresponding Coq source code.
Stable-≡-Erased : {@0 A : Type a} → Stable-≡ (Erased A)
Stable-≡-Erased x y eq =
x ≡⟨ flip ext⁻¹ eq (
(λ (_ : Erased (x ≡ y)) → x) ≡⟨ ∘-[]-injective (
(λ (_ : x ≡ y) → x) ≡⟨ apply-ext ext (λ (eq : x ≡ y) →
x ≡⟨ eq ⟩∎
y ∎) ⟩∎
(λ (_ : x ≡ y) → y) ∎) ⟩∎
(λ (_ : Erased (x ≡ y)) → y) ∎) ⟩∎
y ∎
-- A "computation rule" for Stable-≡-Erased.
Stable-≡-Erased-[refl] :
{@0 A : Type a} {x : Erased A} →
Stable-≡-Erased x x [ refl x ] ≡ refl x
Stable-≡-Erased-[refl] {x = [ x ]} =
Stable-≡-Erased [ x ] [ x ] [ refl [ x ] ] ≡⟨⟩
ext⁻¹ (∘-[]-injective (apply-ext ext id)) [ refl [ x ] ] ≡⟨ ext⁻¹-∘-[]-injective ⟩
ext⁻¹ (apply-ext ext id) (refl [ x ]) ≡⟨ cong (_$ refl _) $ _≃_.left-inverse-of (Eq.extensionality-isomorphism ext′) _ ⟩∎
refl [ x ] ∎
open Stable-≡-Erased-axiomatisation→[]-cong-axiomatisation
(Stable-≡-Erased , Stable-≡-Erased-[refl])
public
-- If we have extensionality, then []-cong can be implemented.
--
-- The idea for this result comes from "Modalities in Homotopy Type
-- Theory" in which Rijke, Shulman and Spitters state that []-cong can
-- be implemented for every modality, and that it is an equivalence
-- for lex modalities (Theorem 3.1 (ix)).
Extensionality→[]-cong-axiomatisation :
Extensionality a a →
[]-cong-axiomatisation a
Extensionality→[]-cong-axiomatisation ext =
instance-of-[]-cong-axiomatisation
where
open Extensionality→[]-cong-axiomatisation ext
------------------------------------------------------------------------
-- A variant of []-cong-axiomatisation
-- A variant of []-cong-axiomatisation where some erased arguments
-- have been replaced with non-erased ones.
record []-cong-axiomatisation′ a : Type (lsuc a) where
field
[]-cong :
{A : Type a} {x y : A} →
Erased (x ≡ y) → [ x ] ≡ [ y ]
[]-cong-equivalence :
Is-equivalence ([]-cong {x = x} {y = y})
[]-cong-[refl] :
[]-cong [ refl x ] ≡ refl [ x ]
-- When implementing the []-cong axioms it suffices to prove "weaker"
-- variants with fewer erased arguments.
--
-- See also
-- Erased.Stability.[]-cong-axiomatisation≃[]-cong-axiomatisation′.
[]-cong-axiomatisation′→[]-cong-axiomatisation :
[]-cong-axiomatisation′ a →
[]-cong-axiomatisation a
[]-cong-axiomatisation′→[]-cong-axiomatisation {a = a} ax = record
{ []-cong = []-cong₀
; []-cong-equivalence = []-cong₀-equivalence
; []-cong-[refl] = []-cong₀-[refl]
}
where
open []-cong-axiomatisation′ ax
[]-cong₀ :
{@0 A : Type a} {@0 x y : A} →
Erased (x ≡ y) → [ x ] ≡ [ y ]
[]-cong₀ {A = A} {x = x} {y = y} =
Erased (x ≡ y) →⟨ map (cong [_]→) ⟩
Erased ([ x ] ≡ [ y ]) →⟨ []-cong ⟩
[ [ x ] ] ≡ [ [ y ] ] →⟨ cong (map erased) ⟩□
[ x ] ≡ [ y ] □
[]-cong₀-[refl] :
{@0 A : Type a} {@0 x : A} →
[]-cong₀ [ refl x ] ≡ refl [ x ]
[]-cong₀-[refl] {x = x} =
cong (map erased) ([]-cong (map (cong [_]→) [ refl x ])) ≡⟨⟩
cong (map erased) ([]-cong [ cong [_]→ (refl x) ]) ≡⟨ cong (cong (map erased) ∘ []-cong) $
[]-cong₀ [ cong-refl _ ] ⟩
cong (map erased) ([]-cong [ refl [ x ] ]) ≡⟨ cong (cong (map erased)) []-cong-[refl] ⟩
cong (map erased) (refl [ [ x ] ]) ≡⟨ cong-refl _ ⟩∎
refl [ x ] ∎
[]-cong₀-equivalence :
{@0 A : Type a} {@0 x y : A} →
Is-equivalence ([]-cong₀ {x = x} {y = y})
[]-cong₀-equivalence =
_≃_.is-equivalence $
Eq.↔→≃
_
(λ [x]≡[y] → [ cong erased [x]≡[y] ])
(λ [x]≡[y] →
cong (map erased)
([]-cong (map (cong [_]→) [ cong erased [x]≡[y] ])) ≡⟨⟩
cong (map erased) ([]-cong [ cong [_]→ (cong erased [x]≡[y]) ]) ≡⟨ cong (cong (map erased) ∘ []-cong) $ []-cong₀
[ trans (cong-∘ _ _ _) $
sym $ cong-id _
] ⟩
cong (map erased) ([]-cong [ [x]≡[y] ]) ≡⟨ elim
(λ x≡y → cong (map erased) ([]-cong [ x≡y ]) ≡ x≡y)
(λ x →
cong (map erased) ([]-cong [ refl x ]) ≡⟨ cong (cong (map erased)) []-cong-[refl] ⟩
cong (map erased) (refl [ x ]) ≡⟨ cong-refl _ ⟩∎
refl x ∎)
_ ⟩
[x]≡[y] ∎)
(λ ([ x≡y ]) →
[ cong erased
(cong (map erased) ([]-cong (map (cong [_]→) [ x≡y ]))) ] ≡⟨⟩
[ cong erased (cong (map erased) ([]-cong [ cong [_]→ x≡y ])) ] ≡⟨ []-cong₀
[ elim
(λ x≡y →
cong erased
(cong (map erased) ([]-cong [ cong [_]→ x≡y ])) ≡
x≡y)
(λ x →
cong erased (cong (map erased) ([]-cong [ cong [_]→ (refl x) ])) ≡⟨ cong (cong erased ∘ cong (map erased) ∘ []-cong) $
[]-cong₀ [ cong-refl _ ] ⟩
cong erased (cong (map erased) ([]-cong [ refl [ x ] ])) ≡⟨ cong (cong erased ∘ cong (map erased)) []-cong-[refl] ⟩
cong erased (cong (map erased) (refl [ [ x ] ])) ≡⟨ trans (cong (cong erased) $ cong-refl _) $
cong-refl _ ⟩∎
refl x ∎)
_
] ⟩∎
[ x≡y ] ∎)
------------------------------------------------------------------------
-- Erased preserves some kinds of functions
-- The following definitions are parametrised by two implementations
-- of the []-cong axioms.
module Erased-cong
(ax₁ : []-cong-axiomatisation ℓ₁)
(ax₂ : []-cong-axiomatisation ℓ₂)
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂}
where
private
module BC₁ = []-cong-axiomatisation ax₁
module BC₂ = []-cong-axiomatisation ax₂
-- Erased preserves split surjections.
Erased-cong-↠ :
@0 A ↠ B → Erased A ↠ Erased B
Erased-cong-↠ A↠B = record
{ logical-equivalence = Erased-cong-⇔
(_↠_.logical-equivalence A↠B)
; right-inverse-of = λ { [ x ] →
BC₂.[]-cong [ _↠_.right-inverse-of A↠B x ] }
}
-- Erased preserves bijections.
Erased-cong-↔ : @0 A ↔ B → Erased A ↔ Erased B
Erased-cong-↔ A↔B = record
{ surjection = Erased-cong-↠ (_↔_.surjection A↔B)
; left-inverse-of = λ { [ x ] →
BC₁.[]-cong [ _↔_.left-inverse-of A↔B x ] }
}
-- Erased preserves equivalences.
Erased-cong-≃ : @0 A ≃ B → Erased A ≃ Erased B
Erased-cong-≃ A≃B =
from-isomorphism (Erased-cong-↔ (from-isomorphism A≃B))
-- A variant of Erased-cong (which is defined in Erased.Level-2).
Erased-cong? :
@0 A ↝[ c ∣ d ] B →
Erased A ↝[ c ∣ d ]ᴱ Erased B
Erased-cong? hyp = generalise-erased-ext?
(Erased-cong-⇔ (hyp _))
(λ ext → Erased-cong-↔ (hyp ext))
------------------------------------------------------------------------
-- Some results that follow if the []-cong axioms hold for a single
-- universe level
module []-cong₁ (ax : []-cong-axiomatisation ℓ) where
open []-cong-axiomatisation ax public
open Erased-cong ax ax
----------------------------------------------------------------------
-- Some definitions directly related to []-cong
-- There is an equivalence between erased equality proofs and
-- equalities between erased values.
Erased-≡≃[]≡[] :
{@0 A : Type ℓ} {@0 x y : A} →
Erased (x ≡ y) ≃ ([ x ] ≡ [ y ])
Erased-≡≃[]≡[] = Eq.⟨ _ , []-cong-equivalence ⟩
-- There is a bijection between erased equality proofs and
-- equalities between erased values.
Erased-≡↔[]≡[] :
{@0 A : Type ℓ} {@0 x y : A} →
Erased (x ≡ y) ↔ [ x ] ≡ [ y ]
Erased-≡↔[]≡[] = _≃_.bijection Erased-≡≃[]≡[]
-- The inverse of []-cong.
[]-cong⁻¹ :
{@0 A : Type ℓ} {@0 x y : A} →
[ x ] ≡ [ y ] → Erased (x ≡ y)
[]-cong⁻¹ = _≃_.from Erased-≡≃[]≡[]
-- Rearrangement lemmas for []-cong and []-cong⁻¹.
[]-cong-[]≡cong-[] :
{A : Type ℓ} {x y : A} {x≡y : x ≡ y} →
[]-cong [ x≡y ] ≡ cong [_]→ x≡y
[]-cong-[]≡cong-[] {x = x} {x≡y = x≡y} = elim¹
(λ x≡y → []-cong [ x≡y ] ≡ cong [_]→ x≡y)
([]-cong [ refl x ] ≡⟨ []-cong-[refl] ⟩
refl [ x ] ≡⟨ sym $ cong-refl _ ⟩∎
cong [_]→ (refl x) ∎)
x≡y
[]-cong⁻¹≡[cong-erased] :
{@0 A : Type ℓ} {@0 x y : A} {@0 x≡y : [ x ] ≡ [ y ]} →
[]-cong⁻¹ x≡y ≡ [ cong erased x≡y ]
[]-cong⁻¹≡[cong-erased] {x≡y = x≡y} = []-cong
[ erased ([]-cong⁻¹ x≡y) ≡⟨ cong erased (_↔_.from (from≡↔≡to Erased-≡≃[]≡[]) lemma) ⟩
erased [ cong erased x≡y ] ≡⟨⟩
cong erased x≡y ∎
]
where
@0 lemma : _
lemma =
x≡y ≡⟨ cong-id _ ⟩
cong id x≡y ≡⟨⟩
cong ([_]→ ∘ erased) x≡y ≡⟨ sym $ cong-∘ _ _ _ ⟩
cong [_]→ (cong erased x≡y) ≡⟨ sym []-cong-[]≡cong-[] ⟩∎
[]-cong [ cong erased x≡y ] ∎
-- A "computation rule" for []-cong⁻¹.
[]-cong⁻¹-refl :
{@0 A : Type ℓ} {@0 x : A} →
[]-cong⁻¹ (refl [ x ]) ≡ [ refl x ]
[]-cong⁻¹-refl {x = x} =
[]-cong⁻¹ (refl [ x ]) ≡⟨ []-cong⁻¹≡[cong-erased] ⟩
[ cong erased (refl [ x ]) ] ≡⟨ []-cong [ cong-refl _ ] ⟩∎
[ refl x ] ∎
-- []-cong and []-cong⁻¹ commute (kind of) with sym.
[]-cong⁻¹-sym :
{@0 A : Type ℓ} {@0 x y : A} {x≡y : [ x ] ≡ [ y ]} →
[]-cong⁻¹ (sym x≡y) ≡ map sym ([]-cong⁻¹ x≡y)
[]-cong⁻¹-sym = elim¹
(λ x≡y → []-cong⁻¹ (sym x≡y) ≡ map sym ([]-cong⁻¹ x≡y))
([]-cong⁻¹ (sym (refl _)) ≡⟨ cong []-cong⁻¹ sym-refl ⟩
[]-cong⁻¹ (refl _) ≡⟨ []-cong⁻¹-refl ⟩
[ refl _ ] ≡⟨ []-cong [ sym sym-refl ] ⟩
[ sym (refl _) ] ≡⟨⟩
map sym [ refl _ ] ≡⟨ cong (map sym) $ sym []-cong⁻¹-refl ⟩∎
map sym ([]-cong⁻¹ (refl _)) ∎)
_
[]-cong-[sym] :
{@0 A : Type ℓ} {@0 x y : A} {@0 x≡y : x ≡ y} →
[]-cong [ sym x≡y ] ≡ sym ([]-cong [ x≡y ])
[]-cong-[sym] {x≡y = x≡y} =
sym $ _↔_.to (from≡↔≡to $ Eq.↔⇒≃ Erased-≡↔[]≡[]) (
[]-cong⁻¹ (sym ([]-cong [ x≡y ])) ≡⟨ []-cong⁻¹-sym ⟩
map sym ([]-cong⁻¹ ([]-cong [ x≡y ])) ≡⟨ cong (map sym) $ _↔_.left-inverse-of Erased-≡↔[]≡[] _ ⟩∎
map sym [ x≡y ] ∎)
-- []-cong and []-cong⁻¹ commute (kind of) with trans.
[]-cong⁻¹-trans :
{@0 A : Type ℓ} {@0 x y z : A}
{x≡y : [ x ] ≡ [ y ]} {y≡z : [ y ] ≡ [ z ]} →
[]-cong⁻¹ (trans x≡y y≡z) ≡
[ trans (erased ([]-cong⁻¹ x≡y)) (erased ([]-cong⁻¹ y≡z)) ]
[]-cong⁻¹-trans {y≡z = y≡z} = elim₁
(λ x≡y → []-cong⁻¹ (trans x≡y y≡z) ≡
[ trans (erased ([]-cong⁻¹ x≡y)) (erased ([]-cong⁻¹ y≡z)) ])
([]-cong⁻¹ (trans (refl _) y≡z) ≡⟨ cong []-cong⁻¹ $ trans-reflˡ _ ⟩
[]-cong⁻¹ y≡z ≡⟨⟩
[ erased ([]-cong⁻¹ y≡z) ] ≡⟨ []-cong [ sym $ trans-reflˡ _ ] ⟩
[ trans (refl _) (erased ([]-cong⁻¹ y≡z)) ] ≡⟨⟩
[ trans (erased [ refl _ ]) (erased ([]-cong⁻¹ y≡z)) ] ≡⟨ []-cong [ cong (flip trans _) $ cong erased $ sym
[]-cong⁻¹-refl ] ⟩∎
[ trans (erased ([]-cong⁻¹ (refl _))) (erased ([]-cong⁻¹ y≡z)) ] ∎)
_
[]-cong-[trans] :
{@0 A : Type ℓ} {@0 x y z : A} {@0 x≡y : x ≡ y} {@0 y≡z : y ≡ z} →
[]-cong [ trans x≡y y≡z ] ≡
trans ([]-cong [ x≡y ]) ([]-cong [ y≡z ])
[]-cong-[trans] {x≡y = x≡y} {y≡z = y≡z} =
sym $ _↔_.to (from≡↔≡to $ Eq.↔⇒≃ Erased-≡↔[]≡[]) (
[]-cong⁻¹ (trans ([]-cong [ x≡y ]) ([]-cong [ y≡z ])) ≡⟨ []-cong⁻¹-trans ⟩
[ trans (erased ([]-cong⁻¹ ([]-cong [ x≡y ])))
(erased ([]-cong⁻¹ ([]-cong [ y≡z ]))) ] ≡⟨ []-cong [ cong₂ (λ p q → trans (erased p) (erased q))
(_↔_.left-inverse-of Erased-≡↔[]≡[] _)
(_↔_.left-inverse-of Erased-≡↔[]≡[] _) ] ⟩∎
[ trans x≡y y≡z ] ∎)
-- In an erased context there is an equivalence between equality of
-- values and equality of "boxed" values.
@0 ≡≃[]≡[] :
{A : Type ℓ} {x y : A} →
(x ≡ y) ≃ ([ x ] ≡ [ y ])
≡≃[]≡[] = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = []-cong ∘ [_]→
; from = cong erased
}
; right-inverse-of = λ eq →
[]-cong [ cong erased eq ] ≡⟨ []-cong-[]≡cong-[] ⟩
cong [_]→ (cong erased eq) ≡⟨ cong-∘ _ _ _ ⟩
cong id eq ≡⟨ sym $ cong-id _ ⟩∎
eq ∎
}
; left-inverse-of = λ eq →
cong erased ([]-cong [ eq ]) ≡⟨ cong (cong erased) []-cong-[]≡cong-[] ⟩
cong erased (cong [_]→ eq) ≡⟨ cong-∘ _ _ _ ⟩
cong id eq ≡⟨ sym $ cong-id _ ⟩∎
eq ∎
})
-- The left-to-right and right-to-left directions of the equivalence
-- are definitionally equal to certain functions.
_ : _≃_.to (≡≃[]≡[] {x = x} {y = y}) ≡ []-cong ∘ [_]→
_ = refl _
@0 _ : _≃_.from (≡≃[]≡[] {x = x} {y = y}) ≡ cong erased
_ = refl _
----------------------------------------------------------------------
-- Variants of subst, cong and the J rule that take erased equality
-- proofs
-- A variant of subst that takes an erased equality proof.
substᴱ :
{@0 A : Type ℓ} {@0 x y : A}
(P : @0 A → Type p) → @0 x ≡ y → P x → P y
substᴱ P eq = subst (λ ([ x ]) → P x) ([]-cong [ eq ])
-- A variant of elim₁ that takes an erased equality proof.
elim₁ᴱ :
{@0 A : Type ℓ} {@0 x y : A}
(P : {@0 x : A} → @0 x ≡ y → Type p) →
P (refl y) →
(@0 x≡y : x ≡ y) → P x≡y
elim₁ᴱ {x = x} {y = y} P p x≡y =
substᴱ
(λ p → P (proj₂ p))
(proj₂ (singleton-contractible y) (x , x≡y))
p
-- A variant of elim¹ that takes an erased equality proof.
elim¹ᴱ :
{@0 A : Type ℓ} {@0 x y : A}
(P : {@0 y : A} → @0 x ≡ y → Type p) →
P (refl x) →
(@0 x≡y : x ≡ y) → P x≡y
elim¹ᴱ {x = x} {y = y} P p x≡y =
substᴱ
(λ p → P (proj₂ p))
(proj₂ (other-singleton-contractible x) (y , x≡y))
p
-- A variant of elim that takes an erased equality proof.
elimᴱ :
{@0 A : Type ℓ} {@0 x y : A}
(P : {@0 x y : A} → @0 x ≡ y → Type p) →
((@0 x : A) → P (refl x)) →
(@0 x≡y : x ≡ y) → P x≡y
elimᴱ {y = y} P p = elim₁ᴱ P (p y)
-- A variant of cong that takes an erased equality proof.
congᴱ :
{@0 A : Type ℓ} {@0 x y : A}
(f : @0 A → B) → @0 x ≡ y → f x ≡ f y
congᴱ f = elimᴱ (λ {x y} _ → f x ≡ f y) (λ x → refl (f x))
-- A "computation rule" for substᴱ.
substᴱ-refl :
{@0 A : Type ℓ} {@0 x : A} {P : @0 A → Type p} {p : P x} →
substᴱ P (refl x) p ≡ p
substᴱ-refl {P = P} {p = p} =
subst (λ ([ x ]) → P x) ([]-cong [ refl _ ]) p ≡⟨ cong (flip (subst _) _) []-cong-[refl] ⟩
subst (λ ([ x ]) → P x) (refl [ _ ]) p ≡⟨ subst-refl _ _ ⟩∎
p ∎
-- If all arguments are non-erased, then one can replace substᴱ with
-- subst (if the first explicit argument is η-expanded).
substᴱ≡subst :
{P : @0 A → Type p} {p : P x} →
substᴱ P eq p ≡ subst (λ x → P x) eq p
substᴱ≡subst {eq = eq} {P = P} {p = p} = elim¹
(λ eq → substᴱ P eq p ≡ subst (λ x → P x) eq p)
(substᴱ P (refl _) p ≡⟨ substᴱ-refl ⟩
p ≡⟨ sym $ subst-refl _ _ ⟩∎
subst (λ x → P x) (refl _) p ∎)
eq
-- A computation rule for elim₁ᴱ.
elim₁ᴱ-refl :
∀ {@0 A : Type ℓ} {@0 y}
{P : {@0 x : A} → @0 x ≡ y → Type p}
{p : P (refl y)} →
elim₁ᴱ P p (refl y) ≡ p
elim₁ᴱ-refl {y = y} {P = P} {p = p} =
substᴱ
(λ p → P (proj₂ p))
(proj₂ (singleton-contractible y) (y , refl y))
p ≡⟨ congᴱ (λ q → substᴱ (λ p → P (proj₂ p)) q _)
(singleton-contractible-refl _) ⟩
substᴱ (λ p → P (proj₂ p)) (refl (y , refl y)) p ≡⟨ substᴱ-refl ⟩∎
p ∎
-- If all arguments are non-erased, then one can replace elim₁ᴱ with
-- elim₁ (if the first explicit argument is η-expanded).
elim₁ᴱ≡elim₁ :
{P : {@0 x : A} → @0 x ≡ y → Type p} {r : P (refl y)} →
elim₁ᴱ P r eq ≡ elim₁ (λ x → P x) r eq
elim₁ᴱ≡elim₁ {eq = eq} {P = P} {r = r} = elim₁
(λ eq → elim₁ᴱ P r eq ≡ elim₁ (λ x → P x) r eq)
(elim₁ᴱ P r (refl _) ≡⟨ elim₁ᴱ-refl ⟩
r ≡⟨ sym $ elim₁-refl _ _ ⟩∎
elim₁ (λ x → P x) r (refl _) ∎)
eq
-- A computation rule for elim¹ᴱ.
elim¹ᴱ-refl :
∀ {@0 A : Type ℓ} {@0 x}
{P : {@0 y : A} → @0 x ≡ y → Type p}
{p : P (refl x)} →
elim¹ᴱ P p (refl x) ≡ p
elim¹ᴱ-refl {x = x} {P = P} {p = p} =
substᴱ
(λ p → P (proj₂ p))
(proj₂ (other-singleton-contractible x) (x , refl x))
p ≡⟨ congᴱ (λ q → substᴱ (λ p → P (proj₂ p)) q _)
(other-singleton-contractible-refl _) ⟩
substᴱ (λ p → P (proj₂ p)) (refl (x , refl x)) p ≡⟨ substᴱ-refl ⟩∎
p ∎
-- If all arguments are non-erased, then one can replace elim¹ᴱ with
-- elim¹ (if the first explicit argument is η-expanded).
elim¹ᴱ≡elim¹ :
{P : {@0 y : A} → @0 x ≡ y → Type p} {r : P (refl x)} →
elim¹ᴱ P r eq ≡ elim¹ (λ x → P x) r eq
elim¹ᴱ≡elim¹ {eq = eq} {P = P} {r = r} = elim¹
(λ eq → elim¹ᴱ P r eq ≡ elim¹ (λ x → P x) r eq)
(elim¹ᴱ P r (refl _) ≡⟨ elim¹ᴱ-refl ⟩
r ≡⟨ sym $ elim¹-refl _ _ ⟩∎
elim¹ (λ x → P x) r (refl _) ∎)
eq
-- A computation rule for elimᴱ.
elimᴱ-refl :
{@0 A : Type ℓ} {@0 x : A} {P : {@0 x y : A} → @0 x ≡ y → Type p}
(r : (@0 x : A) → P (refl x)) →
elimᴱ P r (refl x) ≡ r x
elimᴱ-refl _ = elim₁ᴱ-refl
-- If all arguments are non-erased, then one can replace elimᴱ with
-- elim (if the first two explicit arguments are η-expanded).
elimᴱ≡elim :
{P : {@0 x y : A} → @0 x ≡ y → Type p}
{r : ∀ (@0 x) → P (refl x)} →
elimᴱ P r eq ≡ elim (λ x → P x) (λ x → r x) eq
elimᴱ≡elim {eq = eq} {P = P} {r = r} = elim
(λ eq → elimᴱ P r eq ≡ elim (λ x → P x) (λ x → r x) eq)
(λ x →
elimᴱ P r (refl _) ≡⟨ elimᴱ-refl r ⟩
r x ≡⟨ sym $ elim-refl _ _ ⟩∎
elim (λ x → P x) (λ x → r x) (refl _) ∎)
eq
-- A "computation rule" for congᴱ.
congᴱ-refl :
{@0 A : Type ℓ} {@0 x : A} {f : @0 A → B} →
congᴱ f (refl x) ≡ refl (f x)
congᴱ-refl {x = x} {f = f} =
elimᴱ (λ {x y} _ → f x ≡ f y) (λ x → refl (f x)) (refl x) ≡⟨ elimᴱ-refl (λ x → refl (f x)) ⟩∎
refl (f x) ∎
-- If all arguments are non-erased, then one can replace congᴱ with
-- cong (if the first explicit argument is η-expanded).
congᴱ≡cong :
{f : @0 A → B} →
congᴱ f eq ≡ cong (λ x → f x) eq
congᴱ≡cong {eq = eq} {f = f} = elim¹
(λ eq → congᴱ f eq ≡ cong (λ x → f x) eq)
(congᴱ f (refl _) ≡⟨ congᴱ-refl ⟩
refl _ ≡⟨ sym $ cong-refl _ ⟩∎
cong (λ x → f x) (refl _) ∎)
eq
----------------------------------------------------------------------
-- Some equalities
-- [_] can be "pushed" through subst.
push-subst-[] :
{@0 P : A → Type ℓ} {@0 p : P x} {x≡y : x ≡ y} →
subst (λ x → Erased (P x)) x≡y [ p ] ≡ [ subst P x≡y p ]
push-subst-[] {P = P} {p = p} = elim¹
(λ x≡y → subst (λ x → Erased (P x)) x≡y [ p ] ≡ [ subst P x≡y p ])
(subst (λ x → Erased (P x)) (refl _) [ p ] ≡⟨ subst-refl _ _ ⟩
[ p ] ≡⟨ []-cong [ sym $ subst-refl _ _ ] ⟩∎
[ subst P (refl _) p ] ∎)
_
-- []-cong kind of commutes with trans.
[]-cong-trans :
{@0 A : Type ℓ} {@0 x y z : A} {@0 p : x ≡ y} {@0 q : y ≡ z} →
[]-cong [ trans p q ] ≡ trans ([]-cong [ p ]) ([]-cong [ q ])
[]-cong-trans =
elim¹ᴱ
(λ p →
∀ (@0 q) →
[]-cong [ trans p q ] ≡ trans ([]-cong [ p ]) ([]-cong [ q ]))
(λ q →
[]-cong [ trans (refl _) q ] ≡⟨ cong []-cong $ []-cong [ trans-reflˡ _ ] ⟩
[]-cong [ q ] ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl [ _ ]) ([]-cong [ q ]) ≡⟨ cong (flip trans _) $ sym []-cong-[refl] ⟩∎
trans ([]-cong [ refl _ ]) ([]-cong [ q ]) ∎)
_ _
----------------------------------------------------------------------
-- All h-levels are closed under Erased
-- Erased commutes with H-level′ n (assuming extensionality).
Erased-H-level′↔H-level′ :
{@0 A : Type ℓ} →
∀ n → Erased (H-level′ n A) ↝[ ℓ ∣ ℓ ] H-level′ n (Erased A)
Erased-H-level′↔H-level′ {A = A} zero ext =
Erased (H-level′ zero A) ↔⟨⟩
Erased (∃ λ (x : A) → (y : A) → x ≡ y) ↔⟨ Erased-Σ↔Σ ⟩
(∃ λ (x : Erased A) → Erased ((y : A) → erased x ≡ y)) ↔⟨ (∃-cong λ _ → Erased-Π↔Π-Erased) ⟩
(∃ λ (x : Erased A) → (y : Erased A) → Erased (erased x ≡ erased y)) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → from-isomorphism Erased-≡↔[]≡[]) ⟩
(∃ λ (x : Erased A) → (y : Erased A) → x ≡ y) ↔⟨⟩
H-level′ zero (Erased A) □
Erased-H-level′↔H-level′ {A = A} (suc n) ext =
Erased (H-level′ (suc n) A) ↔⟨⟩
Erased ((x y : A) → H-level′ n (x ≡ y)) ↔⟨ Erased-Π↔Π-Erased ⟩
((x : Erased A) → Erased ((y : A) → H-level′ n (erased x ≡ y))) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩
((x y : Erased A) → Erased (H-level′ n (erased x ≡ erased y))) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → Erased-H-level′↔H-level′ n ext) ⟩
((x y : Erased A) → H-level′ n (Erased (erased x ≡ erased y))) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → H-level′-cong ext n Erased-≡↔[]≡[]) ⟩
((x y : Erased A) → H-level′ n (x ≡ y)) ↔⟨⟩
H-level′ (suc n) (Erased A) □
-- Erased commutes with H-level n (assuming extensionality).
Erased-H-level↔H-level :
{@0 A : Type ℓ} →
∀ n → Erased (H-level n A) ↝[ ℓ ∣ ℓ ] H-level n (Erased A)
Erased-H-level↔H-level {A = A} n ext =
Erased (H-level n A) ↝⟨ Erased-cong? H-level↔H-level′ ext ⟩
Erased (H-level′ n A) ↝⟨ Erased-H-level′↔H-level′ n ext ⟩
H-level′ n (Erased A) ↝⟨ inverse-ext? H-level↔H-level′ ext ⟩□
H-level n (Erased A) □
-- H-level n is closed under Erased.
H-level-Erased :
{@0 A : Type ℓ} →
∀ n → @0 H-level n A → H-level n (Erased A)
H-level-Erased n h = Erased-H-level↔H-level n _ [ h ]
----------------------------------------------------------------------
-- Some closure properties related to Is-proposition
-- If A is a proposition, then Dec-Erased A is a proposition
-- (assuming extensionality).
Is-proposition-Dec-Erased :
{@0 A : Type ℓ} →
Extensionality ℓ lzero →
@0 Is-proposition A →
Is-proposition (Dec-Erased A)
Is-proposition-Dec-Erased {A = A} ext p =
$⟨ Dec-closure-propositional ext (H-level-Erased 1 p) ⟩
Is-proposition (Dec (Erased A)) ↝⟨ H-level-cong _ 1 (inverse $ Dec-Erased↔Dec-Erased {k = equivalence} ext) ⦂ (_ → _) ⟩□
Is-proposition (Dec-Erased A) □
-- If A is a set, then Decidable-erased-equality A is a proposition
-- (assuming extensionality).
Is-proposition-Decidable-erased-equality :
{A : Type ℓ} →
Extensionality ℓ ℓ →
@0 Is-set A →
Is-proposition (Decidable-erased-equality A)
Is-proposition-Decidable-erased-equality ext s =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Is-proposition-Dec-Erased (lower-extensionality lzero _ ext) s
-- Erasedᴾ preserves Is-proposition.
Is-proposition-Erasedᴾ :
{@0 A : Type a} {@0 B : Type b} {@0 R : A → B → Type ℓ} →
@0 (∀ {x y} → Is-proposition (R x y)) →
∀ {x y} → Is-proposition (Erasedᴾ R x y)
Is-proposition-Erasedᴾ prop =
H-level-Erased 1 prop
----------------------------------------------------------------------
-- A property related to "Modalities in Homotopy Type Theory" by
-- Rijke, Shulman and Spitters
-- Erased is a lex modality (see Theorem 3.1, case (i) in
-- "Modalities in Homotopy Type Theory" for the definition used
-- here).
lex-modality :
{@0 A : Type ℓ} {@0 x y : A} →
Contractible (Erased A) → Contractible (Erased (x ≡ y))
lex-modality {A = A} {x = x} {y = y} =
Contractible (Erased A) ↝⟨ _⇔_.from (Erased-H-level↔H-level 0 _) ⟩
Erased (Contractible A) ↝⟨ map (⇒≡ 0) ⟩
Erased (Contractible (x ≡ y)) ↝⟨ Erased-H-level↔H-level 0 _ ⟩□
Contractible (Erased (x ≡ y)) □
----------------------------------------------------------------------
-- Erased "commutes" with various things
-- Erased "commutes" with _⁻¹_.
Erased-⁻¹ :
{@0 A : Type a} {@0 B : Type ℓ} {@0 f : A → B} {@0 y : B} →
Erased (f ⁻¹ y) ↔ map f ⁻¹ [ y ]
Erased-⁻¹ {f = f} {y = y} =
Erased (∃ λ x → f x ≡ y) ↝⟨ Erased-Σ↔Σ ⟩
(∃ λ x → Erased (f (erased x) ≡ y)) ↝⟨ (∃-cong λ _ → Erased-≡↔[]≡[]) ⟩□
(∃ λ x → map f x ≡ [ y ]) □
-- Erased "commutes" with Split-surjective.
Erased-Split-surjective↔Split-surjective :
{@0 A : Type a} {@0 B : Type ℓ} {@0 f : A → B} →
Erased (Split-surjective f) ↝[ ℓ ∣ a ⊔ ℓ ]
Split-surjective (map f)
Erased-Split-surjective↔Split-surjective {f = f} ext =
Erased (∀ y → ∃ λ x → f x ≡ y) ↔⟨ Erased-Π↔Π-Erased ⟩
(∀ y → Erased (∃ λ x → f x ≡ erased y)) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-Σ↔Σ) ⟩
(∀ y → ∃ λ x → Erased (f (erased x) ≡ erased y)) ↝⟨ (∀-cong ext λ _ → ∃-cong λ _ → from-isomorphism Erased-≡↔[]≡[]) ⟩
(∀ y → ∃ λ x → [ f (erased x) ] ≡ y) ↔⟨⟩
(∀ y → ∃ λ x → map f x ≡ y) □
----------------------------------------------------------------------
-- Some lemmas related to whether [_]→ is injective or an embedding
-- In erased contexts [_]→ is injective.
--
-- See also Erased.With-K.Injective-[].
@0 Injective-[] :
{A : Type ℓ} →
Injective {A = A} [_]→
Injective-[] = erased ∘ []-cong⁻¹
-- If A is a proposition, then [_]→ {A = A} is an embedding.
--
-- See also Erased-Is-embedding-[] and Erased-Split-surjective-[]
-- above as well as Very-stable→Is-embedding-[] and
-- Very-stable→Split-surjective-[] in Erased.Stability and
-- Injective-[] and Is-embedding-[] in Erased.With-K.
Is-proposition→Is-embedding-[] :
{A : Type ℓ} →
Is-proposition A → Is-embedding [ A ∣_]→
Is-proposition→Is-embedding-[] prop =
_⇔_.to (Emb.Injective⇔Is-embedding
set (H-level-Erased 2 set) [_]→)
(λ _ → prop _ _)
where
set = mono₁ 1 prop
----------------------------------------------------------------------
-- Variants of some functions from Equality.Decision-procedures
-- A variant of Equality.Decision-procedures.Σ.set⇒dec⇒dec⇒dec.
set⇒dec-erased⇒dec-erased⇒Σ-dec-erased :
{@0 A : Type ℓ} {@0 P : A → Type p}
{@0 x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} →
@0 Is-set A →
Dec-Erased (x₁ ≡ x₂) →
(∀ (@0 eq) → Dec-Erased (substᴱ (λ x → P x) eq y₁ ≡ y₂)) →
Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂))
set⇒dec-erased⇒dec-erased⇒Σ-dec-erased _ (no [ x₁≢x₂ ]) _ =
no [ x₁≢x₂ ∘ cong proj₁ ]
set⇒dec-erased⇒dec-erased⇒Σ-dec-erased
{P = P} {y₁ = y₁} {y₂ = y₂} set₁ (yes [ x₁≡x₂ ]) dec₂ =
⊎-map
(map λ cast-y₁≡y₂ →
Σ-≡,≡→≡ x₁≡x₂
(subst (λ x → P x) x₁≡x₂ y₁ ≡⟨ sym substᴱ≡subst ⟩
substᴱ (λ x → P x) x₁≡x₂ y₁ ≡⟨ cast-y₁≡y₂ ⟩∎
y₂ ∎))
(map λ cast-y₁≢y₂ eq → $⟨ proj₂ (Σ-≡,≡←≡ eq) ⟩
subst (λ x → P x) (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ ≡⇒↝ _ $ cong (_≡ _) $ sym substᴱ≡subst ⟩
substᴱ (λ x → P x) (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ subst (λ p → substᴱ _ p _ ≡ _) (set₁ _ _) ⟩
substᴱ (λ x → P x) x₁≡x₂ y₁ ≡ y₂ ↝⟨ cast-y₁≢y₂ ⟩□
⊥ □)
(dec₂ x₁≡x₂)
-- A variant of Equality.Decision-procedures.Σ.decidable⇒dec⇒dec.
decidable-erased⇒dec-erased⇒Σ-dec-erased :
{@0 A : Type ℓ} {@0 P : A → Type p}
{x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} →
Decidable-erased-equality A →
(∀ (@0 eq) → Dec-Erased (substᴱ (λ x → P x) eq y₁ ≡ y₂)) →
Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂))
decidable-erased⇒dec-erased⇒Σ-dec-erased dec =
set⇒dec-erased⇒dec-erased⇒Σ-dec-erased
(decidable⇒set
(Decidable-erased-equality≃Decidable-equality _ dec))
(dec _ _)
-- A variant of Equality.Decision-procedures.Σ.Dec._≟_.
decidable-erased⇒decidable-erased⇒Σ-decidable-erased :
{@0 A : Type ℓ} {P : @0 A → Type p} →
Decidable-erased-equality A →
({x : A} → Decidable-erased-equality (P x)) →
Decidable-erased-equality (Σ A λ x → P x)
decidable-erased⇒decidable-erased⇒Σ-decidable-erased
{P = P} decA decP (_ , x₂) (_ , y₂) =
decidable-erased⇒dec-erased⇒Σ-dec-erased
decA
(λ eq → decP (substᴱ P eq x₂) y₂)
------------------------------------------------------------------------
-- Erased commutes with W
-- Erased commutes with W (assuming extensionality and an
-- implementation of the []-cong axioms).
--
-- See also Erased-W↔W′ and Erased-W↔W below.
Erased-W↔W-[]-cong :
{@0 A : Type a} {@0 P : A → Type p} →
[]-cong-axiomatisation (a ⊔ p) →
Erased (W A P) ↝[ p ∣ a ⊔ p ]
W (Erased A) (λ x → Erased (P (erased x)))
Erased-W↔W-[]-cong {a = a} {p = p} {A = A} {P = P} ax =
generalise-ext?
Erased-W⇔W
(λ ext → to∘from ext , from∘to ext)
where
open []-cong-axiomatisation ax
open _⇔_ Erased-W⇔W
to∘from :
Extensionality p (a ⊔ p) →
(x : W (Erased A) (λ x → Erased (P (erased x)))) →
to (from x) ≡ x
to∘from ext (sup [ x ] f) =
cong (sup [ x ]) $
apply-ext ext λ ([ y ]) →
to∘from ext (f [ y ])
from∘to :
Extensionality p (a ⊔ p) →
(x : Erased (W A P)) → from (to x) ≡ x
from∘to ext [ sup x f ] =
[]-cong
[ (cong (sup x) $
apply-ext ext λ y →
cong erased (from∘to ext [ f y ]))
]
-- Erased commutes with W (assuming extensionality).
--
-- See also Erased-W↔W below: That property is defined assuming that
-- the []-cong axioms can be instantiated, but is stated using
-- _↝[ p ∣ a ⊔ p ]_ instead of _↝[ a ⊔ p ∣ a ⊔ p ]_.
Erased-W↔W′ :
{@0 A : Type a} {@0 P : A → Type p} →
Erased (W A P) ↝[ a ⊔ p ∣ a ⊔ p ]
W (Erased A) (λ x → Erased (P (erased x)))
Erased-W↔W′ {a = a} =
generalise-ext?
Erased-W⇔W
(λ ext →
let bij = Erased-W↔W-[]-cong
(Extensionality→[]-cong-axiomatisation ext)
(lower-extensionality a lzero ext)
in _↔_.right-inverse-of bij , _↔_.left-inverse-of bij)
------------------------------------------------------------------------
-- Some results that follow if the []-cong axioms hold for two
-- universe levels
module []-cong₂
(ax₁ : []-cong-axiomatisation ℓ₁)
(ax₂ : []-cong-axiomatisation ℓ₂)
where
private
module BC₁ = []-cong₁ ax₁
module BC₂ = []-cong₁ ax₂
----------------------------------------------------------------------
-- Some equalities
-- The function map (cong f) can be expressed in terms of
-- cong (map f) (up to pointwise equality).
map-cong≡cong-map :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 x y : A}
{@0 f : A → B} {x≡y : Erased (x ≡ y)} →
map (cong f) x≡y ≡ BC₂.[]-cong⁻¹ (cong (map f) (BC₁.[]-cong x≡y))
map-cong≡cong-map {f = f} {x≡y = [ x≡y ]} =
[ cong f x≡y ] ≡⟨⟩
[ cong (erased ∘ map f ∘ [_]→) x≡y ] ≡⟨ BC₂.[]-cong [ sym $ cong-∘ _ _ _ ] ⟩
[ cong (erased ∘ map f) (cong [_]→ x≡y) ] ≡⟨ BC₂.[]-cong [ cong (cong _) $ sym BC₁.[]-cong-[]≡cong-[] ] ⟩
[ cong (erased ∘ map f) (BC₁.[]-cong [ x≡y ]) ] ≡⟨ BC₂.[]-cong [ sym $ cong-∘ _ _ _ ] ⟩
[ cong erased (cong (map f) (BC₁.[]-cong [ x≡y ])) ] ≡⟨ sym BC₂.[]-cong⁻¹≡[cong-erased] ⟩∎
BC₂.[]-cong⁻¹ (cong (map f) (BC₁.[]-cong [ x≡y ])) ∎
-- []-cong kind of commutes with cong.
[]-cong-cong :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂}
{@0 f : A → B} {@0 x y : A} {@0 p : x ≡ y} →
BC₂.[]-cong [ cong f p ] ≡ cong (map f) (BC₁.[]-cong [ p ])
[]-cong-cong {f = f} =
BC₁.elim¹ᴱ
(λ p → BC₂.[]-cong [ cong f p ] ≡
cong (map f) (BC₁.[]-cong [ p ]))
(BC₂.[]-cong [ cong f (refl _) ] ≡⟨ cong BC₂.[]-cong (BC₂.[]-cong [ cong-refl _ ]) ⟩
BC₂.[]-cong [ refl _ ] ≡⟨ BC₂.[]-cong-[refl] ⟩
refl _ ≡⟨ sym $ cong-refl _ ⟩
cong (map f) (refl _) ≡⟨ sym $ cong (cong (map f)) BC₁.[]-cong-[refl] ⟩∎
cong (map f) (BC₁.[]-cong [ refl _ ]) ∎)
_
----------------------------------------------------------------------
-- Erased "commutes" with one thing
-- Erased "commutes" with Has-quasi-inverse.
Erased-Has-quasi-inverse↔Has-quasi-inverse :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} →
Erased (Has-quasi-inverse f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ]
Has-quasi-inverse (map f)
Erased-Has-quasi-inverse↔Has-quasi-inverse
{A = A} {B = B} {f = f} {k = k} ext =
Erased (∃ λ g → (∀ x → f (g x) ≡ x) × (∀ x → g (f x) ≡ x)) ↔⟨ Erased-Σ↔Σ ⟩
(∃ λ g →
Erased ((∀ x → f (erased g x) ≡ x) × (∀ x → erased g (f x) ≡ x))) ↝⟨ (∃-cong λ _ → from-isomorphism Erased-Σ↔Σ) ⟩
(∃ λ g →
Erased (∀ x → f (erased g x) ≡ x) ×
Erased (∀ x → erased g (f x) ≡ x)) ↝⟨ Σ-cong Erased-Π↔Π-Erased (λ g →
lemma₁ (erased g) ×-cong lemma₂ (erased g)) ⟩□
(∃ λ g → (∀ x → map f (g x) ≡ x) × (∀ x → g (map f x) ≡ x)) □
where
lemma₁ : (@0 g : B → A) → _ ↝[ k ] _
lemma₁ g =
Erased (∀ x → f (g x) ≡ x) ↔⟨ Erased-Π↔Π-Erased ⟩
(∀ x → Erased (f (g (erased x)) ≡ erased x)) ↝⟨ (∀-cong (lower-extensionality? k ℓ₁ ℓ₁ ext) λ _ →
from-isomorphism BC₂.Erased-≡↔[]≡[]) ⟩
(∀ x → [ f (g (erased x)) ] ≡ x) ↔⟨⟩
(∀ x → map (f ∘ g) x ≡ x) □
lemma₂ : (@0 g : B → A) → _ ↝[ k ] _
lemma₂ g =
Erased (∀ x → g (f x) ≡ x) ↔⟨ Erased-Π↔Π-Erased ⟩
(∀ x → Erased (g (f (erased x)) ≡ erased x)) ↝⟨ (∀-cong (lower-extensionality? k ℓ₂ ℓ₂ ext) λ _ →
from-isomorphism BC₁.Erased-≡↔[]≡[]) ⟩
(∀ x → [ g (f (erased x)) ] ≡ x) ↔⟨⟩
(∀ x → map (g ∘ f) x ≡ x) □
------------------------------------------------------------------------
-- Some results that follow if the []-cong axioms hold for the maximum
-- of two universe levels (as well as for the two universe levels)
-- It is possible to instantiate the first two arguments using the
-- third and lower-[]-cong-axiomatisation, but this is not what is
-- done in the module []-cong below.
module []-cong₂-⊔
(ax₁ : []-cong-axiomatisation ℓ₁)
(ax₂ : []-cong-axiomatisation ℓ₂)
(ax : []-cong-axiomatisation (ℓ₁ ⊔ ℓ₂))
where
private
module EC = Erased-cong ax ax
module BC₁ = []-cong₁ ax₁
module BC₂ = []-cong₁ ax₂
module BC = []-cong₁ ax
----------------------------------------------------------------------
-- A property related to "Modalities in Homotopy Type Theory" by
-- Rijke, Shulman and Spitters
-- A function f is Erased-connected in the sense of Rijke et al.
-- exactly when there is an erased proof showing that f is an
-- equivalence (assuming extensionality).
--
-- See also Erased-Is-equivalence↔Is-equivalence below.
Erased-connected↔Erased-Is-equivalence :
{@0 A : Type ℓ₁} {B : Type ℓ₂} {@0 f : A → B} →
(∀ y → Contractible (Erased (f ⁻¹ y))) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ]
Erased (Is-equivalence f)
Erased-connected↔Erased-Is-equivalence {f = f} {k = k} ext =
(∀ y → Contractible (Erased (f ⁻¹ y))) ↝⟨ (∀-cong (lower-extensionality? k ℓ₁ lzero ext) λ _ →
inverse-ext? (BC.Erased-H-level↔H-level 0) ext) ⟩
(∀ y → Erased (Contractible (f ⁻¹ y))) ↔⟨ inverse Erased-Π↔Π ⟩
Erased (∀ y → Contractible (f ⁻¹ y)) ↔⟨⟩
Erased (CP.Is-equivalence f) ↝⟨ inverse-ext? (λ ext → EC.Erased-cong? Is-equivalence≃Is-equivalence-CP ext) ext ⟩□
Erased (Is-equivalence f) □
----------------------------------------------------------------------
-- Erased "commutes" with various things
-- Erased "commutes" with Is-equivalence.
Erased-Is-equivalence↔Is-equivalence :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} →
Erased (Is-equivalence f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ]
Is-equivalence (map f)
Erased-Is-equivalence↔Is-equivalence {f = f} {k = k} ext =
Erased (Is-equivalence f) ↝⟨ EC.Erased-cong? Is-equivalence≃Is-equivalence-CP ext ⟩
Erased (∀ x → Contractible (f ⁻¹ x)) ↔⟨ Erased-Π↔Π-Erased ⟩
(∀ x → Erased (Contractible (f ⁻¹ erased x))) ↝⟨ (∀-cong ext′ λ _ → BC.Erased-H-level↔H-level 0 ext) ⟩
(∀ x → Contractible (Erased (f ⁻¹ erased x))) ↝⟨ (∀-cong ext′ λ _ → H-level-cong ext 0 BC₂.Erased-⁻¹) ⟩
(∀ x → Contractible (map f ⁻¹ x)) ↝⟨ inverse-ext? Is-equivalence≃Is-equivalence-CP ext ⟩□
Is-equivalence (map f) □
where
ext′ = lower-extensionality? k ℓ₁ lzero ext
-- Erased "commutes" with Injective.
Erased-Injective↔Injective :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} →
Erased (Injective f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Injective (map f)
Erased-Injective↔Injective {f = f} {k = k} ext =
Erased (∀ {x y} → f x ≡ f y → x ≡ y) ↔⟨ EC.Erased-cong-↔ Bijection.implicit-Π↔Π ⟩
Erased (∀ x {y} → f x ≡ f y → x ≡ y) ↝⟨ EC.Erased-cong?
(λ {k} ext →
∀-cong (lower-extensionality? k ℓ₂ lzero ext) λ _ →
from-isomorphism Bijection.implicit-Π↔Π)
ext ⟩
Erased (∀ x y → f x ≡ f y → x ≡ y) ↔⟨ Erased-Π↔Π-Erased ⟩
(∀ x → Erased (∀ y → f (erased x) ≡ f y → erased x ≡ y)) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩
(∀ x y →
Erased (f (erased x) ≡ f (erased y) → erased x ≡ erased y)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩
(∀ x y →
Erased (f (erased x) ≡ f (erased y)) →
Erased (erased x ≡ erased y)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ →
generalise-ext?-sym
(λ {k} ext → →-cong (lower-extensionality? ⌊ k ⌋-sym ℓ₁ ℓ₂ ext)
(from-isomorphism BC₂.Erased-≡↔[]≡[])
(from-isomorphism BC₁.Erased-≡↔[]≡[]))
ext) ⟩
(∀ x y → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism $ inverse Bijection.implicit-Π↔Π) ⟩
(∀ x {y} → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
(∀ {x y} → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) □
where
ext′ = lower-extensionality? k ℓ₂ lzero ext
-- Erased "commutes" with Is-embedding.
Erased-Is-embedding↔Is-embedding :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} →
Erased (Is-embedding f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Is-embedding (map f)
Erased-Is-embedding↔Is-embedding {f = f} {k = k} ext =
Erased (∀ x y → Is-equivalence (cong f)) ↔⟨ Erased-Π↔Π-Erased ⟩
(∀ x → Erased (∀ y → Is-equivalence (cong f))) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩
(∀ x y → Erased (Is-equivalence (cong f))) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ →
Erased-Is-equivalence↔Is-equivalence ext) ⟩
(∀ x y → Is-equivalence (map (cong f))) ↝⟨ (∀-cong ext′ λ x → ∀-cong ext′ λ y →
Is-equivalence-cong ext λ _ → []-cong₂.map-cong≡cong-map ax₁ ax₂) ⟩
(∀ x y →
Is-equivalence (BC₂.[]-cong⁻¹ ∘ cong (map f) ∘ BC₁.[]-cong)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ →
inverse-ext?
(Is-equivalence≃Is-equivalence-∘ʳ BC₁.[]-cong-equivalence)
ext) ⟩
(∀ x y → Is-equivalence (BC₂.[]-cong⁻¹ ∘ cong (map f))) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ →
inverse-ext?
(Is-equivalence≃Is-equivalence-∘ˡ
(_≃_.is-equivalence $ from-isomorphism $ inverse
BC₂.Erased-≡↔[]≡[]))
ext) ⟩□
(∀ x y → Is-equivalence (cong (map f))) □
where
ext′ = lower-extensionality? k ℓ₂ lzero ext
----------------------------------------------------------------------
-- Erased commutes with various type formers
-- Erased commutes with W (assuming extensionality).
Erased-W↔W :
{@0 A : Type ℓ₁} {@0 P : A → Type ℓ₂} →
Erased (W A P) ↝[ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ]
W (Erased A) (λ x → Erased (P (erased x)))
Erased-W↔W = Erased-W↔W-[]-cong ax
-- Erased commutes with _⇔_.
Erased-⇔↔⇔ :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂} →
Erased (A ⇔ B) ↔ (Erased A ⇔ Erased B)
Erased-⇔↔⇔ {A = A} {B = B} =
Erased (A ⇔ B) ↝⟨ EC.Erased-cong-↔ ⇔↔→×→ ⟩
Erased ((A → B) × (B → A)) ↝⟨ Erased-Σ↔Σ ⟩
Erased (A → B) × Erased (B → A) ↝⟨ Erased-Π↔Π-Erased ×-cong Erased-Π↔Π-Erased ⟩
(Erased A → Erased B) × (Erased B → Erased A) ↝⟨ inverse ⇔↔→×→ ⟩□
(Erased A ⇔ Erased B) □
-- Erased commutes with _↣_.
Erased-cong-↣ :
{@0 A : Type ℓ₁} {@0 B : Type ℓ₂} →
@0 A ↣ B → Erased A ↣ Erased B
Erased-cong-↣ A↣B = record
{ to = map (_↣_.to A↣B)
; injective = Erased-Injective↔Injective _ [ _↣_.injective A↣B ]
}
------------------------------------------------------------------------
-- Some results that follow if the []-cong axioms hold for all
-- universe levels
module []-cong (ax : ∀ {ℓ} → []-cong-axiomatisation ℓ) where
private
open module EC {ℓ₁ ℓ₂} =
Erased-cong (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂})
public
open module BC₁ {ℓ} =
[]-cong₁ (ax {ℓ = ℓ})
public
open module BC₂ {ℓ₁ ℓ₂} = []-cong₂ (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂})
public
open module BC₂-⊔ {ℓ₁ ℓ₂} =
[]-cong₂-⊔ (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂}) (ax {ℓ = ℓ₁ ⊔ ℓ₂})
public
------------------------------------------------------------------------
-- Some results that were proved assuming extensionality and also that
-- one or more instances of the []-cong axioms can be implemented,
-- reproved without the latter assumptions
module Extensionality where
-- Erased commutes with H-level′ n (assuming extensionality).
Erased-H-level′≃H-level′ :
{@0 A : Type a} →
Extensionality a a →
∀ n → Erased (H-level′ n A) ≃ H-level′ n (Erased A)
Erased-H-level′≃H-level′ ext n =
[]-cong₁.Erased-H-level′↔H-level′
(Extensionality→[]-cong-axiomatisation ext)
n
ext
-- Erased commutes with H-level n (assuming extensionality).
Erased-H-level≃H-level :
{@0 A : Type a} →
Extensionality a a →
∀ n → Erased (H-level n A) ≃ H-level n (Erased A)
Erased-H-level≃H-level ext n =
[]-cong₁.Erased-H-level↔H-level
(Extensionality→[]-cong-axiomatisation ext)
n
ext
-- If A is a set, then Decidable-erased-equality A is a proposition
-- (assuming extensionality).
Is-proposition-Decidable-erased-equality′ :
{A : Type a} →
Extensionality a a →
@0 Is-set A →
Is-proposition (Decidable-erased-equality A)
Is-proposition-Decidable-erased-equality′ ext =
[]-cong₁.Is-proposition-Decidable-erased-equality
(Extensionality→[]-cong-axiomatisation ext)
ext
-- Erased "commutes" with Split-surjective.
Erased-Split-surjective≃Split-surjective :
{@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →
Extensionality b (a ⊔ b) →
Erased (Split-surjective f) ≃ Split-surjective (map f)
Erased-Split-surjective≃Split-surjective {a = a} ext =
[]-cong₁.Erased-Split-surjective↔Split-surjective
(Extensionality→[]-cong-axiomatisation
(lower-extensionality lzero a ext))
ext
-- A function f is Erased-connected in the sense of Rijke et al.
-- exactly when there is an erased proof showing that f is an
-- equivalence (assuming extensionality).
Erased-connected≃Erased-Is-equivalence :
{@0 A : Type a} {B : Type b} {@0 f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
(∀ y → Contractible (Erased (f ⁻¹ y))) ≃ Erased (Is-equivalence f)
Erased-connected≃Erased-Is-equivalence {a = a} {b = b} ext =
[]-cong₂-⊔.Erased-connected↔Erased-Is-equivalence
(Extensionality→[]-cong-axiomatisation
(lower-extensionality b b ext))
(Extensionality→[]-cong-axiomatisation
(lower-extensionality a a ext))
(Extensionality→[]-cong-axiomatisation ext)
ext
-- Erased "commutes" with Is-equivalence (assuming extensionality).
Erased-Is-equivalence≃Is-equivalence :
{@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Erased (Is-equivalence f) ≃ Is-equivalence (map f)
Erased-Is-equivalence≃Is-equivalence {a = a} {b = b} ext =
[]-cong₂-⊔.Erased-Is-equivalence↔Is-equivalence
(Extensionality→[]-cong-axiomatisation
(lower-extensionality b b ext))
(Extensionality→[]-cong-axiomatisation
(lower-extensionality a a ext))
(Extensionality→[]-cong-axiomatisation ext)
ext
-- Erased "commutes" with Has-quasi-inverse (assuming
-- extensionality).
Erased-Has-quasi-inverse≃Has-quasi-inverse :
{@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Erased (Has-quasi-inverse f) ≃ Has-quasi-inverse (map f)
Erased-Has-quasi-inverse≃Has-quasi-inverse {a = a} {b = b} ext =
[]-cong₂.Erased-Has-quasi-inverse↔Has-quasi-inverse
(Extensionality→[]-cong-axiomatisation
(lower-extensionality b b ext))
(Extensionality→[]-cong-axiomatisation
(lower-extensionality a a ext))
ext
-- Erased "commutes" with Injective (assuming extensionality).
Erased-Injective≃Injective :
{@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Erased (Injective f) ≃ Injective (map f)
Erased-Injective≃Injective {a = a} {b = b} ext =
[]-cong₂-⊔.Erased-Injective↔Injective
(Extensionality→[]-cong-axiomatisation
(lower-extensionality b b ext))
(Extensionality→[]-cong-axiomatisation
(lower-extensionality a a ext))
(Extensionality→[]-cong-axiomatisation ext)
ext
-- Erased "commutes" with Is-embedding (assuming extensionality).
Erased-Is-embedding≃Is-embedding :
{@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Erased (Is-embedding f) ≃ Is-embedding (map f)
Erased-Is-embedding≃Is-embedding {a = a} {b = b} ext =
[]-cong₂-⊔.Erased-Is-embedding↔Is-embedding
(Extensionality→[]-cong-axiomatisation
(lower-extensionality b b ext))
(Extensionality→[]-cong-axiomatisation
(lower-extensionality a a ext))
(Extensionality→[]-cong-axiomatisation ext)
ext
------------------------------------------------------------------------
-- Some lemmas related to []-cong-axiomatisation
-- Any two implementations of []-cong are pointwise equal.
[]-cong-unique :
{@0 A : Type a} {@0 x y : A} {x≡y : Erased (x ≡ y)}
(ax₁ ax₂ : []-cong-axiomatisation a) →
[]-cong-axiomatisation.[]-cong ax₁ x≡y ≡
[]-cong-axiomatisation.[]-cong ax₂ x≡y
[]-cong-unique {x = x} ax₁ ax₂ =
BC₁.elim¹ᴱ
(λ x≡y → BC₁.[]-cong [ x≡y ] ≡ BC₂.[]-cong [ x≡y ])
(BC₁.[]-cong [ refl x ] ≡⟨ BC₁.[]-cong-[refl] ⟩
refl [ x ] ≡⟨ sym BC₂.[]-cong-[refl] ⟩∎
BC₂.[]-cong [ refl x ] ∎)
_
where
module BC₁ = []-cong₁ ax₁
module BC₂ = []-cong₁ ax₂
-- The type []-cong-axiomatisation a is propositional (assuming
-- extensionality).
--
-- The proof is based on a proof due to Nicolai Kraus that shows that
-- "J + its computation rule" is contractible, see
-- Equality.Instances-related.Equality-with-J-contractible.
[]-cong-axiomatisation-propositional :
Extensionality (lsuc a) a →
Is-proposition ([]-cong-axiomatisation a)
[]-cong-axiomatisation-propositional {a = a} ext =
[inhabited⇒contractible]⇒propositional λ ax →
let module BC = []-cong₁ ax
module EC = Erased-cong ax ax
in
_⇔_.from contractible⇔↔⊤
([]-cong-axiomatisation a ↔⟨ Eq.↔→≃
(λ (record { []-cong = c
; []-cong-equivalence = e
; []-cong-[refl] = r
})
_ →
(λ ([ _ , _ , x≡y ]) → c [ x≡y ])
, (λ _ → r)
, (λ _ _ → e))
(λ f → record
{ []-cong = λ ([ x≡y ]) →
f _ .proj₁ [ _ , _ , x≡y ]
; []-cong-equivalence = f _ .proj₂ .proj₂ _ _
; []-cong-[refl] = f _ .proj₂ .proj₁ _
})
refl
refl ⟩
((([ A ]) : Erased (Type a)) →
∃ λ (c : ((([ x , y , _ ]) : Erased (A ²/≡)) → [ x ] ≡ [ y ])) →
((([ x ]) : Erased A) → c [ x , x , refl x ] ≡ refl [ x ]) ×
((([ x ]) ([ y ]) : Erased A) →
Is-equivalence {A = Erased (x ≡ y)} {B = [ x ] ≡ [ y ]}
(λ ([ x≡y ]) → c [ x , y , x≡y ]))) ↝⟨ (∀-cong ext λ _ →
Σ-cong
(inverse $
Π-cong ext′ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ →
Bijection.id)
λ c →
∃-cong λ r → ∀-cong ext′ λ ([ x ]) → ∀-cong ext′ λ ([ y ]) →
Is-equivalence-cong ext′ λ ([ x≡y ]) →
c [ x , y , x≡y ] ≡⟨ BC.elim¹ᴱ
(λ x≡y → c [ _ , _ , x≡y ] ≡ BC.[]-cong [ x≡y ])
(
c [ x , x , refl x ] ≡⟨ r [ x ] ⟩
refl [ x ] ≡⟨ sym BC.[]-cong-[refl] ⟩∎
BC.[]-cong [ refl x ] ∎)
_ ⟩∎
BC.[]-cong [ x≡y ] ∎) ⟩
((([ A ]) : Erased (Type a)) →
∃ λ (c : ((x : Erased A) → x ≡ x)) →
((x : Erased A) → c x ≡ refl x) ×
((([ x ]) ([ y ]) : Erased A) →
Is-equivalence {A = Erased (x ≡ y)} {B = [ x ] ≡ [ y ]}
(λ ([ x≡y ]) → BC.[]-cong [ x≡y ]))) ↝⟨ (∀-cong ext λ _ → ∃-cong λ _ →
drop-⊤-right λ _ →
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(Π-closure ext′ 1 λ _ →
Π-closure ext′ 1 λ _ →
Eq.propositional ext′ _)
(λ _ _ → BC.[]-cong-equivalence)) ⟩
((([ A ]) : Erased (Type a)) →
∃ λ (c : ((x : Erased A) → x ≡ x)) →
((x : Erased A) → c x ≡ refl x)) ↝⟨ (∀-cong ext λ _ → inverse
ΠΣ-comm) ⟩
((([ A ]) : Erased (Type a)) (x : Erased A) →
∃ λ (c : x ≡ x) → c ≡ refl x) ↔⟨⟩
((([ A ]) : Erased (Type a)) (x : Erased A) → Singleton (refl x)) ↝⟨ _⇔_.to contractible⇔↔⊤ $
(Π-closure ext 0 λ _ →
Π-closure ext′ 0 λ _ →
singleton-contractible _) ⟩□
⊤ □)
where
ext′ : Extensionality a a
ext′ = lower-extensionality _ lzero ext
-- The type []-cong-axiomatisation a is contractible (assuming
-- extensionality).
[]-cong-axiomatisation-contractible :
Extensionality (lsuc a) a →
Contractible ([]-cong-axiomatisation a)
[]-cong-axiomatisation-contractible {a = a} ext =
propositional⇒inhabited⇒contractible
([]-cong-axiomatisation-propositional ext)
(Extensionality→[]-cong-axiomatisation
(lower-extensionality _ lzero ext))
------------------------------------------------------------------------
-- An alternative to []-cong-axiomatisation
-- An axiomatisation of substᴱ, restricted to a fixed universe, along
-- with its computation rule.
Substᴱ-axiomatisation : (ℓ : Level) → Type (lsuc ℓ)
Substᴱ-axiomatisation ℓ =
∃ λ (substᴱ :
{@0 A : Type ℓ} {@0 x y : A}
(P : @0 A → Type ℓ) → @0 x ≡ y → P x → P y) →
{@0 A : Type ℓ} {@0 x : A} {P : @0 A → Type ℓ} {p : P x} →
substᴱ P (refl x) p ≡ p
private
-- The type []-cong-axiomatisation ℓ is logically equivalent to
-- Substᴱ-axiomatisation ℓ.
[]-cong-axiomatisation⇔Substᴱ-axiomatisation :
[]-cong-axiomatisation ℓ ⇔ Substᴱ-axiomatisation ℓ
[]-cong-axiomatisation⇔Substᴱ-axiomatisation {ℓ = ℓ} =
record { to = to; from = from }
where
to : []-cong-axiomatisation ℓ → Substᴱ-axiomatisation ℓ
to ax = []-cong₁.substᴱ ax , []-cong₁.substᴱ-refl ax
from : Substᴱ-axiomatisation ℓ → []-cong-axiomatisation ℓ
from (substᴱ , substᴱ-refl) = λ where
.[]-cong-axiomatisation.[]-cong →
[]-cong
.[]-cong-axiomatisation.[]-cong-[refl] →
substᴱ-refl
.[]-cong-axiomatisation.[]-cong-equivalence {x = x} →
_≃_.is-equivalence $
Eq.↔→≃
_
(λ [x]≡[y] → [ cong erased [x]≡[y] ])
(elim¹
(λ [x]≡[y] →
substᴱ (λ y → [ x ] ≡ [ y ]) (cong erased [x]≡[y])
(refl [ x ]) ≡
[x]≡[y])
(substᴱ (λ y → [ x ] ≡ [ y ]) (cong erased (refl [ x ]))
(refl [ x ]) ≡⟨ substᴱ
(λ eq →
substᴱ (λ y → [ x ] ≡ [ y ]) eq (refl [ x ]) ≡
substᴱ (λ y → [ x ] ≡ [ y ]) (refl x) (refl [ x ]))
(sym $ cong-refl _)
(refl _) ⟩
substᴱ (λ y → [ x ] ≡ [ y ]) (refl x) (refl [ x ]) ≡⟨ substᴱ-refl ⟩∎
refl [ x ] ∎))
(λ ([ x≡y ]) →
[]-cong
[ elim¹
(λ x≡y → cong erased ([]-cong [ x≡y ]) ≡ x≡y)
(cong erased ([]-cong [ refl _ ]) ≡⟨ cong (cong erased) substᴱ-refl ⟩
cong erased (refl [ _ ]) ≡⟨ cong-refl _ ⟩∎
refl _ ∎)
x≡y
])
where
[]-cong :
{@0 A : Type ℓ} {@0 x y : A} →
Erased (x ≡ y) → [ x ] ≡ [ y ]
[]-cong {x = x} ([ x≡y ]) =
substᴱ (λ y → [ x ] ≡ [ y ]) x≡y (refl [ x ])
-- The type Substᴱ-axiomatisation ℓ is propositional (assuming
-- extensionality).
--
-- The proof is based on a proof due to Nicolai Kraus that shows that
-- "J + its computation rule" is contractible, see
-- Equality.Instances-related.Equality-with-J-contractible.
Substᴱ-axiomatisation-propositional :
Extensionality (lsuc ℓ) (lsuc ℓ) →
Is-proposition (Substᴱ-axiomatisation ℓ)
Substᴱ-axiomatisation-propositional {ℓ = ℓ} ext =
[inhabited⇒contractible]⇒propositional λ ax →
let ax′ = _⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation ax
module EC = Erased-cong ax′ ax′
in
_⇔_.from contractible⇔↔⊤
(Substᴱ-axiomatisation ℓ ↔⟨ Eq.↔→≃
(λ (substᴱ , substᴱ-refl) _ P →
(λ ([ _ , _ , x≡y ]) → substᴱ (λ A → P [ A ]) x≡y)
, (λ _ _ → substᴱ-refl))
(λ hyp →
(λ P x≡y p → hyp _ (λ ([ A ]) → P A) .proj₁ [ _ , _ , x≡y ] p)
, hyp _ _ .proj₂ _ _)
refl
refl ⟩
((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) →
∃ λ (s : ((([ x , y , _ ]) : Erased (A ²/≡)) →
P [ x ] → P [ y ])) →
((([ x ]) : Erased A) (p : P [ x ]) →
s [ x , x , refl x ] p ≡ p)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ →
Σ-cong
(inverse $
Π-cong ext″ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ →
Bijection.id)
(λ _ → Bijection.id)) ⟩
((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) →
∃ λ (s : ((([ x ]) : Erased A) → P [ x ] → P [ x ])) →
((([ x ]) : Erased A) (p : P [ x ]) → s [ x ] p ≡ p)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → inverse $
ΠΣ-comm F.∘
(∀-cong ext″ λ _ → ΠΣ-comm)) ⟩
((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ)
(x : Erased A) (p : P x) → ∃ λ (p′ : P x) → p′ ≡ p) ↔⟨⟩
((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ)
(x : Erased A) (p : P x) → Singleton p) ↝⟨ (_⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
Π-closure ext′ 0 λ _ →
Π-closure ext″ 0 λ _ →
Π-closure ext″ 0 λ _ →
singleton-contractible _) ⟩□
⊤ □)
where
ext′ : Extensionality (lsuc ℓ) ℓ
ext′ = lower-extensionality lzero _ ext
ext″ : Extensionality ℓ ℓ
ext″ = lower-extensionality _ _ ext
-- The type []-cong-axiomatisation ℓ is equivalent to
-- Substᴱ-axiomatisation ℓ (assuming extensionality).
[]-cong-axiomatisation≃Substᴱ-axiomatisation :
[]-cong-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Substᴱ-axiomatisation ℓ
[]-cong-axiomatisation≃Substᴱ-axiomatisation {ℓ = ℓ} =
generalise-ext?-prop
[]-cong-axiomatisation⇔Substᴱ-axiomatisation
([]-cong-axiomatisation-propositional ∘
lower-extensionality lzero _)
Substᴱ-axiomatisation-propositional
------------------------------------------------------------------------
-- Another alternative to []-cong-axiomatisation
-- An axiomatisation of elim¹ᴱ, restricted to a fixed universe, along
-- with its computation rule.
Elimᴱ-axiomatisation : (ℓ : Level) → Type (lsuc ℓ)
Elimᴱ-axiomatisation ℓ =
∃ λ (elimᴱ :
{@0 A : Type ℓ} {@0 x y : A}
(P : {@0 x y : A} → @0 x ≡ y → Type ℓ) →
((@0 x : A) → P (refl x)) →
(@0 x≡y : x ≡ y) → P x≡y) →
{@0 A : Type ℓ} {@0 x : A} {P : {@0 x y : A} → @0 x ≡ y → Type ℓ}
(r : (@0 x : A) → P (refl x)) →
elimᴱ P r (refl x) ≡ r x
private
-- The type Substᴱ-axiomatisation ℓ is logically equivalent to
-- Elimᴱ-axiomatisation ℓ.
Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation :
Substᴱ-axiomatisation ℓ ⇔ Elimᴱ-axiomatisation ℓ
Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation {ℓ = ℓ} =
record { to = to; from = from }
where
to : Substᴱ-axiomatisation ℓ → Elimᴱ-axiomatisation ℓ
to ax = elimᴱ , elimᴱ-refl
where
open
[]-cong₁
(_⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation ax)
from : Elimᴱ-axiomatisation ℓ → Substᴱ-axiomatisation ℓ
from (elimᴱ , elimᴱ-refl) =
(λ P x≡y p →
elimᴱ (λ {x = x} {y = y} _ → P x → P y) (λ _ → id) x≡y p)
, (λ {_ _ _ p} → cong (_$ p) $ elimᴱ-refl _)
-- The type Elimᴱ-axiomatisation ℓ is propositional (assuming
-- extensionality).
--
-- The proof is based on a proof due to Nicolai Kraus that shows that
-- "J + its computation rule" is contractible, see
-- Equality.Instances-related.Equality-with-J-contractible.
Elimᴱ-axiomatisation-propositional :
Extensionality (lsuc ℓ) (lsuc ℓ) →
Is-proposition (Elimᴱ-axiomatisation ℓ)
Elimᴱ-axiomatisation-propositional {ℓ = ℓ} ext =
[inhabited⇒contractible]⇒propositional λ ax →
let ax′ = _⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation $
_⇔_.from Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation ax
module EC = Erased-cong ax′ ax′
in
_⇔_.from contractible⇔↔⊤
(Elimᴱ-axiomatisation ℓ ↔⟨ Eq.↔→≃
(λ (elimᴱ , elimᴱ-refl) _ P r →
(λ ([ _ , _ , x≡y ]) →
elimᴱ (λ x≡y → P [ _ , _ , x≡y ]) (λ x → r [ x ]) x≡y)
, (λ _ → elimᴱ-refl _))
(λ hyp →
(λ P r x≡y →
hyp _ (λ ([ _ , _ , x≡y ]) → P x≡y) (λ ([ x ]) → r x)
.proj₁ [ _ , _ , x≡y ])
, (λ _ → hyp _ _ _ .proj₂ _))
refl
refl ⟩
((([ A ]) : Erased (Type ℓ))
(P : Erased (A ²/≡) → Type ℓ)
(r : (([ x ]) : Erased A) → P [ x , x , refl x ]) →
∃ λ (e : (x : Erased (A ²/≡)) → P x) →
((([ x ]) : Erased A) → e [ x , x , refl x ] ≡ r [ x ])) ↝⟨ (∀-cong ext λ _ →
Π-cong {k₁ = bijection} ext′
(→-cong₁ ext″ (EC.Erased-cong-↔ U.-²/≡↔-)) λ _ →
∀-cong ext‴ λ _ →
Σ-cong
(inverse $
Π-cong ext‴ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ →
Bijection.id)
(λ _ → Bijection.id)) ⟩
((([ A ]) : Erased (Type ℓ))
(P : Erased A → Type ℓ)
(r : (x : Erased A) → P x) →
∃ λ (e : (x : Erased A) → P x) →
(x : Erased A) → e x ≡ r x) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → ∀-cong ext‴ λ _ → inverse
ΠΣ-comm) ⟩
((([ A ]) : Erased (Type ℓ))
(P : Erased A → Type ℓ)
(r : (x : Erased A) → P x)
(x : Erased A) →
∃ λ (p : P x) → p ≡ r x) ↝⟨ (_⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
Π-closure ext′ 0 λ _ →
Π-closure ext‴ 0 λ _ →
Π-closure ext‴ 0 λ _ →
singleton-contractible _) ⟩□
⊤ □)
where
ext′ : Extensionality (lsuc ℓ) ℓ
ext′ = lower-extensionality lzero _ ext
ext″ : Extensionality ℓ (lsuc ℓ)
ext″ = lower-extensionality _ lzero ext
ext‴ : Extensionality ℓ ℓ
ext‴ = lower-extensionality _ _ ext
-- The type Substᴱ-axiomatisation ℓ is equivalent to
-- Elimᴱ-axiomatisation ℓ (assuming extensionality).
Substᴱ-axiomatisation≃Elimᴱ-axiomatisation :
Substᴱ-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Elimᴱ-axiomatisation ℓ
Substᴱ-axiomatisation≃Elimᴱ-axiomatisation =
generalise-ext?-prop
Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation
Substᴱ-axiomatisation-propositional
Elimᴱ-axiomatisation-propositional
-- The type []-cong-axiomatisation ℓ is equivalent to
-- Elimᴱ-axiomatisation ℓ (assuming extensionality).
[]-cong-axiomatisation≃Elimᴱ-axiomatisation :
[]-cong-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Elimᴱ-axiomatisation ℓ
[]-cong-axiomatisation≃Elimᴱ-axiomatisation {ℓ = ℓ} ext =
[]-cong-axiomatisation ℓ ↝⟨ []-cong-axiomatisation≃Substᴱ-axiomatisation ext ⟩
Substᴱ-axiomatisation ℓ ↝⟨ Substᴱ-axiomatisation≃Elimᴱ-axiomatisation ext ⟩□
Elimᴱ-axiomatisation ℓ □
|
{
"alphanum_fraction": 0.444066461,
"avg_line_length": 39.8701149425,
"ext": "agda",
"hexsha": "2324772ccbf95efab9de11df8f332af7ed2cb540",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Erased/Level-1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Erased/Level-1.agda",
"max_line_length": 147,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Erased/Level-1.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 37156,
"size": 104061
}
|
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.FunctorAlgebras where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism renaming (Iso to _≅_)
open import Cubical.Foundations.Univalence
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation.Base
open _≅_
private
variable ℓC ℓC' : Level
module _ {C : Category ℓC ℓC'} (F : Functor C C) where
open Category
open Functor
IsAlgebra : ob C → Type ℓC'
IsAlgebra x = C [ F-ob F x , x ]
record Algebra : Type (ℓ-max ℓC ℓC') where
constructor algebra
field
carrier : ob C
str : IsAlgebra carrier
open Algebra
IsAlgebraHom : (algA algB : Algebra) → C [ carrier algA , carrier algB ] → Type ℓC'
IsAlgebraHom algA algB f = (f ∘⟨ C ⟩ str algA) ≡ (str algB ∘⟨ C ⟩ F-hom F f)
record AlgebraHom (algA algB : Algebra) : Type ℓC' where
constructor algebraHom
field
carrierHom : C [ carrier algA , carrier algB ]
strHom : IsAlgebraHom algA algB carrierHom
open AlgebraHom
RepAlgebraHom : (algA algB : Algebra) → Type ℓC'
RepAlgebraHom algA algB = Σ[ f ∈ C [ carrier algA , carrier algB ] ] IsAlgebraHom algA algB f
isoRepAlgebraHom : (algA algB : Algebra) → AlgebraHom algA algB ≅ RepAlgebraHom algA algB
fun (isoRepAlgebraHom algA algB) (algebraHom f isalgF) = f , isalgF
inv (isoRepAlgebraHom algA algB) (f , isalgF) = algebraHom f isalgF
rightInv (isoRepAlgebraHom algA algB) (f , isalgF) = refl
leftInv (isoRepAlgebraHom algA algB) (algebraHom f isalgF)= refl
pathRepAlgebraHom : (algA algB : Algebra) → AlgebraHom algA algB ≡ RepAlgebraHom algA algB
pathRepAlgebraHom algA algB = ua (isoToEquiv (isoRepAlgebraHom algA algB))
AlgebraHom≡ : {algA algB : Algebra} {algF algG : AlgebraHom algA algB}
→ (carrierHom algF ≡ carrierHom algG) → algF ≡ algG
carrierHom (AlgebraHom≡ {algA} {algB} {algF} {algG} p i) = p i
strHom (AlgebraHom≡ {algA} {algB} {algF} {algG} p i) = idfun
(PathP (λ j → (p j ∘⟨ C ⟩ str algA) ≡ (str algB ∘⟨ C ⟩ F-hom F (p j)))
(strHom algF)
(strHom algG)
)
(fst (idfun (isContr _) (isOfHLevelPathP' 0
(isOfHLevelPath' 1 (isSetHom C) _ _)
(strHom algF) (strHom algG))))
i
idAlgebraHom : {algA : Algebra} → AlgebraHom algA algA
carrierHom (idAlgebraHom {algA}) = id C
strHom (idAlgebraHom {algA}) =
⋆IdR C (str algA) ∙∙ sym (⋆IdL C (str algA)) ∙∙ cong (λ φ → φ ⋆⟨ C ⟩ str algA) (sym (F-id F))
seqAlgebraHom : {algA algB algC : Algebra}
(algF : AlgebraHom algA algB) (algG : AlgebraHom algB algC)
→ AlgebraHom algA algC
carrierHom (seqAlgebraHom {algA} {algB} {algC} algF algG) = carrierHom algF ⋆⟨ C ⟩ carrierHom algG
strHom (seqAlgebraHom {algA} {algB} {algC} algF algG) =
str algA ⋆⟨ C ⟩ (carrierHom algF ⋆⟨ C ⟩ carrierHom algG)
≡⟨ sym (⋆Assoc C (str algA) (carrierHom algF) (carrierHom algG)) ⟩
(str algA ⋆⟨ C ⟩ carrierHom algF) ⋆⟨ C ⟩ carrierHom algG
≡⟨ cong (λ φ → φ ⋆⟨ C ⟩ carrierHom algG) (strHom algF) ⟩
(F-hom F (carrierHom algF) ⋆⟨ C ⟩ str algB) ⋆⟨ C ⟩ carrierHom algG
≡⟨ ⋆Assoc C (F-hom F (carrierHom algF)) (str algB) (carrierHom algG) ⟩
F-hom F (carrierHom algF) ⋆⟨ C ⟩ (str algB ⋆⟨ C ⟩ carrierHom algG)
≡⟨ cong (λ φ → F-hom F (carrierHom algF) ⋆⟨ C ⟩ φ) (strHom algG) ⟩
F-hom F (carrierHom algF) ⋆⟨ C ⟩ (F-hom F (carrierHom algG) ⋆⟨ C ⟩ str algC)
≡⟨ sym (⋆Assoc C (F-hom F (carrierHom algF)) (F-hom F (carrierHom algG)) (str algC)) ⟩
(F-hom F (carrierHom algF) ⋆⟨ C ⟩ F-hom F (carrierHom algG)) ⋆⟨ C ⟩ str algC
≡⟨ cong (λ φ → φ ⋆⟨ C ⟩ str algC) (sym (F-seq F (carrierHom algF) (carrierHom algG))) ⟩
F-hom F (carrierHom algF ⋆⟨ C ⟩ carrierHom algG) ⋆⟨ C ⟩ str algC ∎
AlgebrasCategory : Category (ℓ-max ℓC ℓC') ℓC'
ob AlgebrasCategory = Algebra
Hom[_,_] AlgebrasCategory = AlgebraHom
id AlgebrasCategory = idAlgebraHom
_⋆_ AlgebrasCategory = seqAlgebraHom
⋆IdL AlgebrasCategory algF = AlgebraHom≡ (⋆IdL C (carrierHom algF))
⋆IdR AlgebrasCategory algF = AlgebraHom≡ (⋆IdR C (carrierHom algF))
⋆Assoc AlgebrasCategory algF algG algH =
AlgebraHom≡ (⋆Assoc C (carrierHom algF) (carrierHom algG) (carrierHom algH))
isSetHom AlgebrasCategory = subst isSet (sym (pathRepAlgebraHom _ _))
(isSetΣ (isSetHom C) (λ f → isProp→isSet (isSetHom C _ _)))
ForgetAlgebra : Functor AlgebrasCategory C
F-ob ForgetAlgebra = carrier
F-hom ForgetAlgebra = carrierHom
F-id ForgetAlgebra = refl
F-seq ForgetAlgebra algF algG = refl
module _ {C : Category ℓC ℓC'} {F G : Functor C C} (τ : NatTrans F G) where
private
module C = Category C
open Functor
open NatTrans
open AlgebraHom
AlgebrasFunctor : Functor (AlgebrasCategory G) (AlgebrasCategory F)
F-ob AlgebrasFunctor (algebra a α) = algebra a (α C.∘ N-ob τ a)
carrierHom (F-hom AlgebrasFunctor (algebraHom f isalgF)) = f
strHom (F-hom AlgebrasFunctor {algebra a α} {algebra b β} (algebraHom f isalgF)) =
(N-ob τ a C.⋆ α) C.⋆ f
≡⟨ C.⋆Assoc (N-ob τ a) α f ⟩
N-ob τ a C.⋆ (α C.⋆ f)
≡⟨ cong (N-ob τ a C.⋆_) isalgF ⟩
N-ob τ a C.⋆ (F-hom G f C.⋆ β)
≡⟨ sym (C.⋆Assoc _ _ _) ⟩
(N-ob τ a C.⋆ F-hom G f) C.⋆ β
≡⟨ cong (C._⋆ β) (sym (N-hom τ f)) ⟩
(F-hom F f C.⋆ N-ob τ b) C.⋆ β
≡⟨ C.⋆Assoc _ _ _ ⟩
F-hom F f C.⋆ (N-ob τ b C.⋆ β) ∎
F-id AlgebrasFunctor = AlgebraHom≡ F refl
F-seq AlgebrasFunctor algΦ algΨ = AlgebraHom≡ F refl
|
{
"alphanum_fraction": 0.65606469,
"avg_line_length": 40.9191176471,
"ext": "agda",
"hexsha": "be02f448b469fe6949dc67d52847089c3dea1ba6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Categories/Instances/FunctorAlgebras.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Categories/Instances/FunctorAlgebras.agda",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/FunctorAlgebras.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 2276,
"size": 5565
}
|
module Prelude where
--------------------------------------------------------------------------------
open import Agda.Primitive public
using (Level ; _⊔_)
renaming (lzero to ℓ₀)
id : ∀ {ℓ} → {X : Set ℓ}
→ X → X
id x = x
_◎_ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {P : X → Set ℓ′} {Q : ∀ {x} → P x → Set ℓ″}
→ (g : ∀ {x} → (y : P x) → Q y) (f : (x : X) → P x) (x : X)
→ Q (f x)
(g ◎ f) x = g (f x)
const : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′}
→ X → Y → X
const x y = x
flip : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : X → Y → Set ℓ″}
→ (f : (x : X) (y : Y) → Z x y) (y : Y) (x : X)
→ Z x y
flip f y x = f x y
_∘_ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : Set ℓ″}
→ (g : Y → Z) (f : X → Y)
→ X → Z
g ∘ f = g ◎ f
_⨾_ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : Set ℓ″}
→ (f : X → Y) (g : Y → Z)
→ X → Z
_⨾_ = flip _∘_
--------------------------------------------------------------------------------
open import Agda.Builtin.Equality public
using (_≡_ ; refl)
_⁻¹≡ : ∀ {ℓ} → {X : Set ℓ} {x₁ x₂ : X}
→ x₁ ≡ x₂ → x₂ ≡ x₁
refl ⁻¹≡ = refl
_⦙≡_ : ∀ {ℓ} → {X : Set ℓ} {x₁ x₂ x₃ : X}
→ x₁ ≡ x₂ → x₂ ≡ x₃ → x₁ ≡ x₃
refl ⦙≡ refl = refl
record PER {ℓ}
(X : Set ℓ)
(_≈_ : X → X → Set ℓ)
: Set ℓ where
infix 9 _⁻¹
infixr 4 _⦙_
field
_⁻¹ : ∀ {x₁ x₂} → x₁ ≈ x₂
→ x₂ ≈ x₁
_⦙_ : ∀ {x₁ x₂ x₃} → x₁ ≈ x₂ → x₂ ≈ x₃
→ x₁ ≈ x₃
open PER {{…}} public
instance
per≡ : ∀ {ℓ} {X : Set ℓ} → PER X _≡_
per≡ =
record
{ _⁻¹ = _⁻¹≡
; _⦙_ = _⦙≡_
}
infixl 9 _&_
_&_ : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′} {x₁ x₂ : X}
→ (f : X → Y) → x₁ ≡ x₂
→ f x₁ ≡ f x₂
f & refl = refl
infixl 8 _⊗_
_⊗_ : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′} {f₁ f₂ : X → Y} {x₁ x₂ : X}
→ f₁ ≡ f₂ → x₁ ≡ x₂
→ f₁ x₁ ≡ f₂ x₂
refl ⊗ refl = refl
case_of_ : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′}
→ X → (X → Y) → Y
case x of f = f x
coe : ∀ {ℓ} → {X Y : Set ℓ}
→ X ≡ Y → X → Y
coe refl x = x
postulate
fext! : ∀ {ℓ ℓ′} → {X : Set ℓ} {P : X → Set ℓ′} {f₁ f₂ : (x : X) → P x}
→ ((x : X) → f₁ x ≡ f₂ x)
→ f₁ ≡ f₂
fext¡ : ∀ {ℓ ℓ′} → {X : Set ℓ} {P : X → Set ℓ′} {f₁ f₂ : {x : X} → P x}
→ ({x : X} → f₁ {x} ≡ f₂ {x})
→ (λ {x} → f₁ {x}) ≡ (λ {x} → f₂ {x})
--------------------------------------------------------------------------------
open import Agda.Builtin.Unit public
using (⊤ ; tt)
data ⊥ : Set where
elim⊥ : ∀ {ℓ} → {X : Set ℓ}
→ ⊥ → X
elim⊥ ()
¬_ : ∀ {ℓ} → Set ℓ → Set ℓ
¬ X = X → ⊥
Π : ∀ {ℓ ℓ′} → Set ℓ → Set ℓ′ → Set (ℓ ⊔ ℓ′)
Π X Y = X → Y
infixl 6 _,_
record Σ {ℓ ℓ′}
(X : Set ℓ) (P : X → Set ℓ′)
: Set (ℓ ⊔ ℓ′) where
instance
constructor _,_
field
proj₁ : X
proj₂ : P proj₁
open Σ public
infixl 5 _⁏_
pattern _⁏_ x y = x , y
infixl 2 _×_
_×_ : ∀ {ℓ ℓ′} → Set ℓ → Set ℓ′ → Set (ℓ ⊔ ℓ′)
X × Y = Σ X (λ x → Y)
mapΣ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {P : X → Set ℓ″} {Q : Y → Set ℓ‴}
→ (f : X → Y) (g : ∀ {x} → P x → Q (f x)) → Σ X P
→ Σ Y Q
mapΣ f g (x , y) = f x , g y
caseΣ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {P : X → Set ℓ″} {Q : Y → Set ℓ‴}
→ Σ X P → (f : X → Y) (g : ∀ {x} → P x → Q (f x))
→ Σ Y Q
caseΣ p f g = mapΣ f g p
infixl 1 _⊎_
data _⊎_ {ℓ ℓ′}
(X : Set ℓ) (Y : Set ℓ′)
: Set (ℓ ⊔ ℓ′) where
inj₁ : (x : X) → X ⊎ Y
inj₂ : (y : Y) → X ⊎ Y
elim⊎ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : Set ℓ″}
→ X ⊎ Y → (X → Z) → (Y → Z)
→ Z
elim⊎ (inj₁ x) f g = f x
elim⊎ (inj₂ y) f g = g y
map⊎ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {Z₁ : Set ℓ″} {Z₂ : Set ℓ‴}
→ (X → Z₁) → (Y → Z₂) → X ⊎ Y
→ Z₁ ⊎ Z₂
map⊎ f g s = elim⊎ s (inj₁ ∘ f) (inj₂ ∘ g)
case⊎ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {Z₁ : Set ℓ″} {Z₂ : Set ℓ‴}
→ X ⊎ Y → (X → Z₁) → (Y → Z₂)
→ Z₁ ⊎ Z₂
case⊎ s f g = map⊎ f g s
--------------------------------------------------------------------------------
open import Agda.Builtin.Bool public
using (Bool ; false ; true)
if_then_else_ : ∀ {ℓ} → {X : Set ℓ}
→ Bool → X → X
→ X
if_then_else_ true t f = t
if_then_else_ false t f = f
not : Bool → Bool
not true = false
not false = true
and : Bool → Bool → Bool
and true b = b
and false b = false
or : Bool → Bool → Bool
or true b = true
or false b = b
xor : Bool → Bool → Bool
xor true b = not b
xor false b = b
data True : Bool → Set
where
instance
yes : True true
--------------------------------------------------------------------------------
open import Agda.Builtin.Nat public
using (Nat ; zero ; suc)
open import Agda.Builtin.FromNat public
using (Number ; fromNat)
instance
numNat : Number Nat
numNat =
record
{ Constraint = λ n → ⊤
; fromNat = λ n → n
}
_>?_ : Nat → Nat → Bool
zero >? k = false
suc n >? zero = true
suc n >? suc k = n >? k
--------------------------------------------------------------------------------
data Fin : Nat → Set
where
zero : ∀ {n} → Fin (suc n)
suc : ∀ {n} → Fin n
→ Fin (suc n)
Nat→Fin : ∀ {n} → (k : Nat) {{_ : True (n >? k)}}
→ Fin n
Nat→Fin {n = zero} k {{()}}
Nat→Fin {n = suc n} zero {{is-true}} = zero
Nat→Fin {n = suc n} (suc k) {{p}} = suc (Nat→Fin k {{p}})
instance
numFin : ∀ {n} → Number (Fin n)
numFin {n} =
record
{ Constraint = λ k → True (n >? k)
; fromNat = Nat→Fin
}
--------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.3432147563,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "1531e68a14afbfb95f827dd7c15021ffa0e43636",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/coquand-kovacs",
"max_forks_repo_path": "src/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/coquand-kovacs",
"max_issues_repo_path": "src/Prelude.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/coquand-kovacs",
"max_stars_repo_path": "src/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2570,
"size": 6072
}
|
-- Andreas, 2013-11-23
-- checking that postulates are allowed in new-style mutual blocks
open import Common.Prelude
-- new style mutual block
even : Nat → Bool
postulate
odd : Nat → Bool
even zero = true
even (suc n) = odd n
-- No error
|
{
"alphanum_fraction": 0.6907630522,
"avg_line_length": 14.6470588235,
"ext": "agda",
"hexsha": "f94e615890b672472f91209551f43a41559b73db",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue977a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue977a.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue977a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 72,
"size": 249
}
|
module Data.Num.Bijective where
open import Data.Nat
open import Data.Fin as Fin using (Fin; #_; fromℕ≤)
open import Data.Fin.Extra
open import Data.Fin.Properties using (bounded)
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open import Level using () renaming (suc to lsuc)
open import Function
open import Relation.Nullary.Negation
open import Relation.Nullary.Decidable
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality as PropEq
infixr 5 _∷_
-- For a system to be bijective wrt ℕ:
-- * base ≥ 1
-- * digits = {1 .. base}
data Bij : ℕ → Set where
-- from the terminal object, which represents 0
∙ : ∀ {b} -- base
→ Bij (suc b) -- base ≥ 1
-- successors
_∷_ : ∀ {b}
→ Fin b -- digit = {1 .. b}
→ Bij b → Bij b
infixr 9 _/_
-- syntax sugar for chaining digits with ℕ
_/_ : ∀ {b} → (n : ℕ)
→ {lower-bound : True (suc zero ≤? n)} -- digit ≥ 1
→ {upper-bound : True (n ≤? b)} -- digit ≤ base
→ Bij b → Bij b
_/_ {b} zero {()} {ub} ns
_/_ {b} (suc n) {lb} {ub} ns = (# n) {b} {ub} ∷ ns
module _/_-Examples where
零 : Bij 2
零 = ∙
一 : Bij 2
一 = 1 / ∙
八 : Bij 3
八 = 2 / 2 / ∙
八 : Bij 3
八 = 2 / 2 / ∙
open import Data.Nat.DM
open import Data.Nat.Properties using (≰⇒>)
open import Relation.Binary
-- a digit at its largest
full : ∀ {b} (x : Fin (suc b)) → Dec (Fin.toℕ {suc b} x ≡ b)
full {b} x = Fin.toℕ x ≟ b
-- a digit at its largest (for ℕ)
full-ℕ : ∀ b n → Dec (n ≡ b)
full-ℕ b n = n ≟ b
------------------------------------------------------------------------
-- Digit
------------------------------------------------------------------------
digit-toℕ : ∀ {b} → Fin b → ℕ
digit-toℕ x = suc (Fin.toℕ x)
digit+1-lemma : ∀ a b → a < suc b → a ≢ b → a < b
digit+1-lemma zero zero a<1+b a≢b = contradiction refl a≢b
digit+1-lemma zero (suc b) a<1+b a≢b = s≤s z≤n
digit+1-lemma (suc a) zero (s≤s ()) a≢b
digit+1-lemma (suc a) (suc b) (s≤s a<1+b) a≢b = s≤s (digit+1-lemma a b a<1+b (λ z → a≢b (cong suc z)))
digit+1 : ∀ {b} → (x : Fin (suc b)) → Fin.toℕ x ≢ b → Fin (suc b)
digit+1 {b} x ¬p = fromℕ≤ {digit-toℕ x} (s≤s (digit+1-lemma (Fin.toℕ x) b (bounded x) ¬p))
------------------------------------------------------------------------
-- Bij
------------------------------------------------------------------------
1+ : ∀ {b} → Bij (suc b) → Bij (suc b)
1+ ∙ = Fin.zero ∷ ∙
1+ {b} (x ∷ xs) with full x
1+ {b} (x ∷ xs) | yes p = Fin.zero ∷ 1+ xs
1+ {b} (x ∷ xs) | no ¬p = digit+1 x ¬p ∷ xs
n+ : ∀ {b} → ℕ → Bij (suc b) → Bij (suc b)
n+ zero xs = xs
n+ (suc n) xs = 1+ (n+ n xs)
------------------------------------------------------------------------
-- From and to ℕ
------------------------------------------------------------------------
toℕ : ∀ {b} → Bij b → ℕ
toℕ ∙ = zero
toℕ {b} (x ∷ xs) = digit-toℕ x + (toℕ xs * b)
fromℕ : ∀ {b} → ℕ → Bij (suc b)
fromℕ zero = ∙
fromℕ (suc n) = 1+ (fromℕ n)
------------------------------------------------------------------------
-- Functions on Bij
------------------------------------------------------------------------
-- infixl 6 _⊹_
--
-- _⊹_ : ∀ {b} → Bij b → Bij b → Bij b
-- _⊹_ ∙ ys = ys
-- _⊹_ xs ∙ = xs
-- _⊹_ {zero} (() ∷ xs) (y ∷ ys)
-- _⊹_ {suc b} (x ∷ xs) (y ∷ ys) with (suc (Fin.toℕ x + Fin.toℕ y)) divMod (suc b)
-- _⊹_ {suc b} (x ∷ xs) (y ∷ ys) | result quotient remainder property div-eq mod-eq =
-- remainder ∷ n+ quotient (xs ⊹ ys)
-- old base = suc b
-- new base = suc (suc b)
increase-base : ∀ {b} → Bij (suc b) → Bij (suc (suc b))
increase-base {b} ∙ = ∙
increase-base {b} (x ∷ xs) with fromℕ {suc b} (toℕ (increase-base xs) * suc b)
| inspect (λ ws → fromℕ {suc b} (toℕ ws * suc b)) (increase-base xs)
increase-base {b} (x ∷ xs) | ∙ | [ eq ] = Fin.inject₁ x ∷ ∙
increase-base {b} (x ∷ xs) | y ∷ ys | [ eq ]
with suc (Fin.toℕ x + Fin.toℕ y) divMod (suc (suc b))
increase-base {b} (x ∷ xs) | y ∷ ys | [ eq ]
| result quotient remainder property div-eq mod-eq =
remainder ∷ n+ quotient ys
-- old base = suc (suc b)
-- new base = suc b
decrease-base : ∀ {b} → Bij (suc (suc b)) → Bij (suc b)
decrease-base {b} ∙ = ∙
decrease-base {b} (x ∷ xs) with fromℕ {b} (toℕ (decrease-base xs) * suc (suc b))
| inspect (λ ws → fromℕ {b} (toℕ ws * suc (suc b))) (decrease-base xs)
decrease-base {b} (x ∷ xs) | ∙ | [ eq ] with full x
decrease-base {b} (x ∷ xs) | ∙ | [ eq ] | yes p = Fin.zero ∷ Fin.zero ∷ ∙
decrease-base {b} (x ∷ xs) | ∙ | [ eq ] | no ¬p = inject-1 x ¬p ∷ ∙
decrease-base {b} (x ∷ xs) | y ∷ ys | [ eq ] with (suc (Fin.toℕ x + Fin.toℕ y)) divMod (suc b)
decrease-base (x ∷ xs) | y ∷ ys | [ eq ] | result quotient remainder property div-eq mod-eq
= remainder ∷ n+ quotient ys
|
{
"alphanum_fraction": 0.4694211495,
"avg_line_length": 33.0337837838,
"ext": "agda",
"hexsha": "bb4982935061721f6182e76ddc08e78b43140690",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Bijective.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Bijective.agda",
"max_line_length": 102,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Bijective.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 1847,
"size": 4889
}
|
module z-06 where
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _<?_; _<_; ≤-pred)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
import Relation.Binary.PropositionalEquality.Core as PE
{-
------------------------------------------------------------------------------
-- 267 p 6.2.2 Shortcuts.
C-c C-l typecheck and highlight the current file
C-c C-, get information about the hole under the cursor
C-c C-. show inferred type for proposed term for a hole
C-c C-space give a solution
C-c C-c case analysis on a variable
C-c C-r refine the hole
C-c C-a automatic fill
C-c C-n which normalizes a term (useful to test computations)
middle click definition of the term
SYMBOLS
∧ \and
⊤ \top
→ \to
∀ \all
Π \Pi
λ \Gl
∨ \or
⊥ \bot
¬ \neg
∃ \ex
Σ \Sigma
≡ \equiv
ℕ \bN
× \times
≤ \le
∈ \in
⊎ \uplus
∷ \::
∎ \qed
x₁ \_1
x¹ \^1
------------------------------------------------------------------------------
-- p 268 6.2.3 The standard library.
default path /usr/share/agda-stdlib
Data.Empty empty type (⊥)
Data.Unit unit type (⊤)
Data.Bool booleans
Data.Nat natural numbers (ℕ)
Data.List lists
Data.Vec vectors (lists of given length)
Data.Fin types with finite number of elements
Data.Integer integers
Data.Float floating point numbers
Data.Bin binary natural numbers
Data.Rational rational numbers
Data.String strings
Data.Maybe option types
Data.AVL balanced binary search trees
Data.Sum sum types (⊎, ∨)
Data.Product product types (×, ∧, ∃, Σ)
Relation.Nullary negation (¬)
Relation.Binary.PropositionalEquality equality (≡)
------------------------------------------------------------------------------
-- p 277 6.3.4 Postulates.
for axioms (no proof)
avoide as much as possible
e.g, to work in classical logic, assume law of excluded middle with
postulate
lem : (A : Set) → ¬ A ⊎ A
postulates do not compute:
- applying 'lem' to type A, will not reduce to ¬ A or A (as expected for a coproduct)
see section 6.5.6
------------------------------------------------------------------------------
-- p 277 6.3.5 Records.
-}
-- implementation of pairs using records
record Pair (A B : Set) : Set where
constructor mkPair
field
fst : A
snd : B
make-pair : {A B : Set} → A → B → Pair A B
make-pair a b = record { fst = a ; snd = b }
make-pair' : {A B : Set} → A → B → Pair A B
make-pair' a b = mkPair a b
proj1 : {A B : Set} → Pair A B → A
proj1 p = Pair.fst p
------------------------------------------------------------------------------
-- p 278 6.4 Inductive types: data
-- p 278 6.4.1 Natural numbers
{-
data ℕ : Set where
zero : ℕ -- base case
suc : ℕ → ℕ -- inductive case
-}
pred : ℕ → ℕ
pred zero = zero
pred (suc n) = n
_+'_ : ℕ → ℕ → ℕ
zero +' n = n
(suc m) +' n = suc (m +' n)
infixl 6 _+'_
_∸'_ : ℕ → ℕ → ℕ
zero ∸' n = zero
suc m ∸' zero = suc m
suc m ∸' suc n = m ∸' n
_*'_ : ℕ → ℕ → ℕ
zero *' n = zero
suc m *' n = (m *' n) + n
{-
_mod'_ : ℕ → ℕ → ℕ
m mod' n with m <? n
m mod' n | yes _ = m
m mod' n | no _ = (m ∸' n) mod' n
-}
-- TODO : what is going on here?
-- mod' : ℕ → ℕ → ℕ
-- mod' m n with m <? n
-- ... | x = {!!}
{-
------------------------------------------------------------------------------
-- p 280 Empty pattern matching.
there is no case to pattern match on elements of this type
use on types with no elements, e.g.,
-}
data ⊥' : Set where
-- given an element of type ⊥ then "produce" anything
-- uses pattern : () -- means that no such pattern can happen
⊥'-elim : {A : Set} → ⊥' → A
⊥'-elim ()
{-
since A is arbitrary, no way, in proof, to exhibit one.
Do not have to.
'()' states no cases to handle, so done
Useful in negation and other less obvious ways of constructing empty inductive types.
E.g., the type zero ≡ suc zero of equalities between 0 and 1 is also an empty inductive type.
-}
{-
------------------------------------------------------------------------------
-- p 281 Anonymous pattern matching.
-}
-- curly brackets before args, cases separated by semicolons:
-- e.g.,
pred' : ℕ → ℕ
pred' = λ { zero → zero ; (suc n) → n }
{-
------------------------------------------------------------------------------
-- p 281 6.4.3 The induction principle.
pattern matching corresponds to the presence of a recurrence or induction principle
e.g.,
f : → A
f zero = t
f (suc n) = u' -- u' might be 'n' or result of recursive call f n
recurrence principle expresses this as
-}
rec : {A : Set} → A → (ℕ → A → A) → ℕ → A
rec t u zero = t
rec t u (suc n) = u n (rec t u n)
-- same with differenct var names
recℕ : {A : Set} → A → (ℕ → A → A) → ℕ → A
recℕ a n→a→a zero = a
recℕ a n→a→a (suc n) = n→a→a n (recℕ a n→a→a n)
{-
Same as "recursor" for including nats to simply typed λ-calculus in section 4.3.6.
Any function of type ℕ → A defined using pattern matching can be redefined using this function.
This recurrence function encapsulates the expressive power of pattern matching.
e.g.,
-}
pred'' : ℕ → ℕ
pred'' = rec zero (λ n _ → n)
_ : pred'' 2 ≡ rec zero (λ n _ → n) 2
_ = refl
_ : rec zero (λ n _ → n) 2 ≡ 1
_ = refl
_ : pred'' 2 ≡ 1
_ = refl
{-
logical : recurrence principle corresponds to elimination rule, so aka "eliminator"
Pattern matching in Agda is more powerful
- can be used to define functions whose return type depends on argument
means must consider functions of the form
f : (n : ℕ) -> P n -- P : ℕ → Set
f zero = t -- : P zero
f (suc n) = u n (f n) -- : P (suc n)
corresponding dependent variant of the recurrence principle is called the induction principle:
-}
rec' : (P : ℕ → Set)
→ P zero
→ ((n : ℕ) → P n → P (suc n))
→ (n : ℕ)
→ P n
rec' P Pz Ps zero = Pz
rec' P Pz Ps (suc n) = Ps n (rec' P Pz Ps n)
{-
reading type as a logical formula, it says the recurrence principle over natural numbers:
P (0) ⇒ (∀n ∈ ℕ.P (n) ⇒ P (n + 1)) ⇒ ∀n ∈ ℕ.P (n)
-}
-- proof using recursion
+-zero' : (n : ℕ) → n + zero ≡ n
+-zero' zero = refl
+-zero' (suc n) = PE.cong suc (+-zero' n)
-- proof using dependent induction principle
+-zero'' : (n : ℕ) → n + zero ≡ n
+-zero'' = rec' (λ n → n + zero ≡ n) refl (λ n p → PE.cong suc p)
_ : +-zero'' 2 ≡ refl
_ = refl
_ : rec' (λ n → n + zero ≡ n) refl (λ n p → PE.cong suc p) ≡
λ n → rec' (λ z → z + zero ≡ z) refl (λ n → PE.cong (λ z → suc z)) n
_ = refl
------------------------------------------------------------------------------
-- p 282 Booleans
data Bool : Set where
false : Bool
true : Bool
-- induction principle for booleans
Bool-rec : (P : Bool → Set) → P false → P true → (b : Bool) → P b
Bool-rec P Pf Pt false = Pf
Bool-rec P Pf Pt true = Pt
------------------------------------------------------------------------------
-- p 283 Lists Data.List
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
length : {A : Set} → List A → ℕ
length [] = 0
length (_ ∷ xs) = 1 + length xs
_++_ : {A : Set} → List A → List A → List A
[] ++ l = l
(x ∷ xs) ++ l = x ∷ (xs ++ l)
List-rec
: {A : Set}
→ (P : List A → Set)
→ P []
→ ((x : A) → (xs : List A) → P xs → P (x ∷ xs))
→ (xs : List A)
→ P xs
List-rec P Pe Pc [] = Pe
List-rec P Pe Pc (x ∷ xs) = Pc x xs (List-rec P Pe Pc xs)
------------------------------------------------------------------------------
-- p 284 6.4.7 Vectors.
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_∷_ : {n : ℕ} → A → Vec A n → Vec A (suc n)
{-
------------------------------------------------------------------------------
-- p 284 Dependent types.
type Vec A n depends on term n : a defining feature of dependent types.
-}
-- also, functions whose result type depends on argument, e.g.,
replicate : {A : Set} → A → (n : ℕ) → Vec A n
replicate x zero = []
replicate x (suc n) = x ∷ replicate x n
------------------------------------------------------------------------------
-- p 285 Dependent pattern matching.
-- since input is type Vec A (suc n), infers never applied to empty
head : {n : ℕ} {A : Set} → Vec A (suc n) → A
head (x ∷ xs) = x
------------------------------------------------------------------------------
-- p 285 Convertibility.
-- Agda is able to compare types up to β-reduction on terms (zero + n reduces to n):
-- - never distinguishes between two β-convertible terms
_++'_ : {m n : ℕ} {A : Set}
→ Vec A m → Vec A n → Vec A (m + n)
[] ++' l = l -- Vec A (zero + n) ≡ Vec A n
(x ∷ xs) ++' l = x ∷ (xs ++' l)
------------------------------------------------------------------------------
-- p 285 Induction principle for Vec-rec
-- induction principle for vectors
Vec-rec : {A : Set}
→ (P : {n : ℕ} → Vec A n → Set)
→ P []
→ ({n : ℕ} → (x : A) → (xs : Vec A n) → P xs → P (x ∷ xs))
→ {n : ℕ}
→ (xs : Vec A n)
→ P xs
Vec-rec P Pe Pc [] = Pe
Vec-rec P Pe Pc (x ∷ xs) = Pc x xs (Vec-rec P Pe Pc xs)
------------------------------------------------------------------------------
-- p 285 Indices instead of parameters.
-- general : can always encode a parameter as an index
-- recommended using parameters whenever possible (Agda handles them more efficiently)
-- use an index for type A (instead of a parameter)
data VecI : Set → ℕ → Set where
[] : {A : Set} → VecI A zero
_∷_ : {A : Set} {n : ℕ} (x : A) (xs : VecI A n) → VecI A (suc n)
-- induction principle for index VecI
VecI-rec : (P : {A : Set} {n : ℕ} → VecI A n → Set)
→ ({A : Set} → P {A} [])
→ ({A : Set} {n : ℕ} (x : A) (xs : VecI A n) → P xs → P (x ∷ xs))
→ {A : Set}
→ {n : ℕ}
→ (xs : VecI A n)
→ P xs
VecI-rec P Pe Pc [] = Pe
VecI-rec P Pe Pc (x ∷ xs) = Pc x xs (VecI-rec P Pe Pc xs)
------------------------------------------------------------------------------
-- p 286 6.4.8 Finite sets.
-- has n elements
data Fin' : ℕ → Set where
fzero' : {n : ℕ} → Fin' (suc n)
fsuc' : {n : ℕ} → Fin' n → Fin' (suc n)
{-
Fin n is collection of ℕ restricted to Fin n = {0,...,n − 1}
above type corresponds to inductive set-theoretic definition:
Fin 0 = ∅
Fin (n + 1) = {0} ∪ {i + 1 | i ∈ Fin n}
-}
finToℕ : {n : ℕ} → Fin' n → ℕ
finToℕ fzero' = zero
finToℕ (fsuc' i) = suc (finToℕ i)
------------------------------------------------------------------------------
-- p 286 Vector lookup using Fin
-- Fin n typically used to index
-- type ensures index in bounds
lookup : {n : ℕ} {A : Set} → Fin' n → Vec A n → A
lookup fzero' (x ∷ xs) = x
lookup (fsuc' i) (x ∷ xs) = lookup i xs
-- where index can be out of bounds
open import Data.Maybe
lookup' : ℕ → {A : Set} {n : ℕ} → Vec A n → Maybe A
lookup' zero [] = nothing
lookup' zero (x ∷ l) = just x
lookup' (suc i) [] = nothing
lookup' (suc i) (x ∷ l) = lookup' i l
-- another option : add proof of i < n
lookupP : {i n : ℕ} {A : Set}
→ i < n
→ Vec A n
→ A
lookupP {i} {.0} () []
lookupP {zero} {.(suc _)} i<n (x ∷ l) = x
lookupP {suc i} {.(suc _)} i<n (x ∷ l) = lookupP (≤-pred i<n) l
{-
------------------------------------------------------------------------------
-- p 287 6.5 Inductive types: logic
Use inductive types to implement types used as logical formulas,
though the Curry-Howard correspondence.
What follows is a dictionary between the two.
------------------------------------------------------------------------------
-- 6.5.1 Implication : corresponds to arrow (→) in types
-}
-- constant function
-- classical formula A ⇒ B ⇒ A proved by
K : {A B : Set} → A → B → A
K x y = x
-- composition
-- classical formula (A ⇒ B ⇒ C) ⇒ (A ⇒ B) ⇒ A ⇒ C proved by
S : {A B C : Set} → (A → B → C) → (A → B) → A → C
S g f x = g x (f x)
{-
------------------------------------------------------------------------------
-- 6.5.2 Product : corresponds to conjunction
defined in Data.Product
-}
data _×_ (A B : Set) : Set where
_,_ : A → B → A × B
-- aka fst
proj₁ : {A B : Set} → A × B → A
proj₁ (a , b) = a
-- aka snd
proj₂ : {A B : Set} → A × B → B
proj₂ (a , b) = b
-- proof of A ∧ B ⇒ B ∧ A (commutativity of conjunction)
×-comm : {A B : Set} → A × B → B × A
×-comm (a , b) = (b , a)
-- proof of curryfication
×-→ : {A B C : Set} → (A × B → C) → (A → B → C)
×-→ f x y = f (x , y)
-- and
→-× : {A B C : Set} → (A → B → C) → (A × B → C)
→-× f (x , y) = f x y
{-
introduction rule for conjunction:
Γ ⊢ A Γ ⊢ B
-------------- (∧I)
Γ ⊢ A ∧ B
general : when logical connectives are defined with inductive types,
- CONSTRUCTORS CORRESPOND TO INTRODUCTION RULES
------------------------------------------------------------------------------
Induction principle : ELIMINATION RULE CORRESPONDS TO THE ASSOCIATED INDUCTION PRINCIPLE
-}
-- for case where P does not depend on its arg
×-rec : {A B : Set}
→ (P : Set)
→ (A → B → P)
→ A × B → P
×-rec P Pp (x , y) = Pp x y
{-
corresponds to elimination rule for conjunction:
Γ, A,B ⊢ P Γ ⊢ A ∧ B
------------------------- (∧E)
Γ ⊢ P
if the premises are true then the conclusion is also true
-}
-- dependent induction principle
-- corresponds to the elimination rule in dependent types
-- see 8.3.3
×-ind : {A B : Set}
→ (P : A × B → Set)
→ ((x : A) → (y : B) → P (x , y))
→ (p : A × B) → P p
×-ind P Pp (x , y) = Pp x y
{-
------------------------------------------------------------------------------
-- p 289 6.5.3 Unit type : corresponds to truth
Data.Unit
-}
data ⊤ : Set where
tt : ⊤ -- constructor is introduction rule
{-
----- (⊤I)
Γ ⊢ ⊤
-}
-- induction principle
⊤-rec
: (P : ⊤ → Set)
→ P tt
→ (t : ⊤)
→ P t
⊤-rec P Ptt tt = Ptt
{-
know from logic there is no elimination rule associated with truth
but can write rule that corresponds to induction principle:
Γ ⊢ P Γ ⊢ ⊤
--------------- (⊤E)
Γ ⊢ P
not interesting from a logical point of view:
if P holds and ⊤ holds
then can deduce that P holds, which was already known
------------------------------------------------------------------------------
-- 6.5.4 Empty type : corresponds to falsity
Data.Empty
-}
data ⊥ : Set where
-- no constructor, so no introduction rule
-- dependent induction principle
⊥-d-elim : (P : ⊥ → Set) → (x : ⊥) → P x
⊥-d-elim P ()
-- non-dependent variant of this principle
⊥-elim : (P : Set) → ⊥ → P
⊥-elim P () -- () is the empty pattern in Agda
-- indicates there are no cases to handle when matching on a value of type
{-
corresponds to explosion principle, which is the associated elimination rule
Γ ⊢ ⊥
---- (⊥E)
Γ ⊢ P
------------------------------------------------------------------------------
6.5.5 Negation
Relation.Nullary
-}
¬ : Set → Set
¬ A = A → ⊥
-- e.g., A ⇒ ¬¬A proved:
nni : {A : Set} → A → ¬ (¬ A)
nni A ¬A = ¬A A
{-
------------------------------------------------------------------------------
p 290 6.5.6 Coproduct : corresponds to disjunction
Data.Sum
-}
data _⊎_ (A : Set) (B : Set) : Set where
inj₁ : A → A ⊎ B -- called injection of A into A ⊎ B
inj₂ : B → A ⊎ B -- ditto B
{-
The two constructors correspond to the two introduction rules
Γ ⊢ A
--------- (∨ᴸI)
Γ ⊢ A ∨ B
Γ ⊢ B
--------- (∨ᴿI)
Γ ⊢ A ∨ B
-}
-- commutativity of disjunction
⊎-comm : (A B : Set) → A ⊎ B → B ⊎ A
⊎-comm A B (inj₁ x) = inj₂ x
⊎-comm A B (inj₂ y) = inj₁ y
{-
-- proof of (A ∨ ¬A) ⇒ ¬¬A ⇒ A
lem-raa : {A : Set}
→ A ⊎ ¬ A
→ ¬ (¬ A)
→ A
lem-raa (inj₁ a) _ = a
lem-raa (inj₂ ¬a) k = ⊥-elim (k ¬a) -- ⊥ !=< Set
-}
-- induction principle
⊎-rec : {A B : Set}
→ (P : A ⊎ B → Set)
→ ((x : A) → P (inj₁ x))
→ ((y : B) → P (inj₂ y))
→ (u : A ⊎ B)
→ P u
⊎-rec P P₁ P₂ (inj₁ x) = P₁ x
⊎-rec P P₁ P₂ (inj₂ y) = P₂ y
{-
non-dependent induction principle corresponds to the elimination rule
Γ, A ⊢ P Γ, B ⊢ P Γ ⊢ A ∨ B
----------------------------- (∨E)
Γ ⊢ P
------------------------------------------------------------------------------
Decidable types : A type A is decidable when it is known whether it is inhabited or not
i.e. a proof of A ∨ ¬A
could define predicate: Dec A is a proof that A is decidable
-}
Dec' : Set → Set
Dec' A = A ⊎ ¬ A -- by definition of the disjunction
{-
Agda convention
write yes/no instead of inj₁/inj₂
because it answers the question: is A provable?
defined in Relation.Nullary as
-- p 291
A type A is decidable when
-}
data Dec (A : Set) : Set where
yes : A → Dec A
no : ¬ A → Dec A
{-
logic of Agda is intuitionistic
therefore A ∨ ¬A not provable for any type A, and not every type is decidable
it can be proved that no type is not decidable (see 2.3.5 and 6.6.8)
-}
nndec : (A : Set) → ¬ (¬ (Dec A))
nndec A n = n (no (λ a → n (yes a)))
{-
------------------------------------------------------------------------------
-- p 291 6.5.7 Π-types : corresponds to universal quantification
dependent types : types that depend on terms
some connectives support dependent generalizations
e.g., generalization of function types
A → B
to dependent function types
(x : A) → B
where x might occur in B.
the type B of the returned value depends on arg x
e.g.,
replicate : {A : Set} → A → (n : ℕ) → Vec A n
Dependent function types are also called Π-types
often written
Π(x : A).B
can be define as (note: there is builtin notation in Agda)
-}
data Π {A : Set} (A : Set) (B : A → Set) : Set where
Λ : ((a : A) → B a) → Π A B
{-
an element of Π A B is a dependent function
(x : A) → B x
bound universal quantification bounded (the type A over which the variable ranges)
corresponds to
∀x ∈ A.B(x)
proof of that formula corresponds to a function which
- to every x in A
- associates a proof of B(x)
why Agda allows the notation
∀ x → B x
for the above type (leaves A implicit)
Exercise 6.5.7.1.
Show that the type
Π Bool (λ { false → A ; true → B })
is isomorphic to
A × B
------------------------------------------------------------------------------
-- p 292 6.5.8 Σ-types : corresponds to bounded existential quantification
Data.Product
-}
-- dependent variant of product types : a : A , b : B a
data Σ (A : Set) (B : A → Set) : Set where
_,_ : (a : A) → B a → Σ A B
-- actual Agda def is done using a record
dproj₁ : {A : Set} {B : A → Set} → Σ A B → A
dproj₁ (a , b) = a
dproj₂ : {A : Set} {B : A → Set} → (s : Σ A B) → B (dproj₁ s)
dproj₂ (a , b) = b
{-
Logical interpretation
type
Σ A B
is bounded existential quantification
∃x ∈ A.B(x)
set theoretic interpretation corresponds to constructing sets by comprehension
{x ∈ A | B(x)}
the set of elements x of A such that B(x) is satisfied
e.g., in set theory
- given a function f : A → B
- its image Im(f) is the subset of B consisting of elements in the image of f.
formally defined
Im(f) = {y ∈ B | ∃x ∈ A.f (x) = y}
translated to with two Σ types
- one for the comprehension
- one for the universal quantification
-}
Im : {A B : Set} (f : A → B) → Set
Im {A} {B} f = Σ B (λ y → Σ A (λ x → f x ≡ y))
-- e.g., can show that every function f : A → B has a right inverse (or section)
-- g : Im(f) → A
sec : {A B : Set} (f : A → B) → Im f → A
sec f (y , (x , p)) = x
{-
------------------------------------------------------------------------------
-- p 293 : the axiom of choice
for every relation R ⊆ A × B satisfying ∀x ∈ A.∃y ∈ B.(x, y) ∈ R
there is a function f : A → B such that ∀x ∈ A.(x, f (x)) ∈ R
section 6.5.9 defined type Rel A B
corresponding to relations between types A and B
using Rel, can prov axiom of choice
-}
-- AC : {A B : Set} (R : Rel A B) -- TODO
-- → ((x : A) → Σ B (λ y → R x y))
-- → Σ (A → B) (λ f → ∀ x → R x (f x))
-- AC R f = (λ x → proj₁ (f x)) , (λ x → proj₂ (f x))
{-
the arg that corresponds to the proof of (6.1), is constructive
a function which to every element x of type A
associates a pair of an element y of B
and a proof that (x, y) belongs to the relation.
By projecting it on the first component,
necessary function f is obtained (associates an element of B to each element of A)
use the second component to prove that it satisfies the required property
the "classical" variant of the axiom of choice
does not have access to the proof of (6.1) -- it only knows its existence.
another description is thus
where the double negation has killed the contents of the proof, see section 2.5.9
postulate CAC : {A B : Set} (R : Rel A B)
→ ¬ ¬ ((x : A) → Σ B (λ y → R x y))
→ ¬ ¬ Σ (A → B) (λ f → ∀ x → R x (f x))
see 9.3.4.
------------------------------------------------------------------------------
-- p 293 : 6.5.9 Predicates
In classical logic, the set Bool of booleans is the set of truth values:
- a predicate on a set A can either be false or true
- modeled as a function A → Bool
In Agda/intuitionistic logic
- not so much interested in truth value of predicate
- but rather in its proofs
- so the role of truth values is now played by Set
predicate P on a type A is term of type
A → Set
which to every element x of A associates the type of proofs of P x
------------------------------------------------------------------------------
-- p 294 Relations
Relation.Binary
In classical mathematics, a relation R on a set A is a subset of A × A (see A.1)
x of A is in relation with an element y when (x, y) ∈ R
relation on A can also be encoded as a function : A × A → 𝔹
or, curryfication, : A → A → 𝔹
in this representation, x is in relation with y when R(x, y) = 1
In Agda/intuitionistic
- relations between types A and B as type Rel A
- obtained by replacing the set 𝔹 of truth values with Set in the above description:
-}
Rel : Set → Set₁
Rel A = A → A → Set
-- e.g.
-- _≤_ : type Rel ℕ
-- _≡_ : type Rel A
{-
------------------------------------------------------------------------------
Inductive predicates (predicates defined by induction)
-}
data isEven : ℕ → Set where
even-z : isEven zero -- 0 is even
even-s : {n : ℕ} → isEven n → isEven (suc (suc n)) -- if n is even then n + 2 is even
{-
corresponds to def of set E ⊆ N of even numbers
as the smallest set of numbers such that
0 ∈ E
and
n ∈ E ⇒ n+2 ∈ E
-}
data _≤_ : ℕ → ℕ → Set where
z≤n : {n : ℕ} → zero ≤ n
s≤s : {m n : ℕ} (m≤n : m ≤ n) → suc m ≤ suc n
{-
smallest relation on ℕ such that
0 ≤ 0
and
m ≤ n implies m+1 ≤ n+1
inductive predicate definitions enable reasoning by induction over those predicates/relations
-}
≤-refl : {n : ℕ} → (n ≤ n)
≤-refl {zero} = z≤n
≤-refl {suc n} = s≤s ≤-refl
-- p 295
≤-trans : {m n p : ℕ} → (m ≤ n) → (n ≤ p) → (m ≤ p)
≤-trans z≤n n≤p = z≤n
≤-trans (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans m≤n n≤p)
{-
inductive defs good because of Agda's support for
reasoning by induction (and dependent pattern matching)
leading to simpler proofs
other defs possible
-- base on classical equivalence, for m, n ∈ N, m ≤ n ⇔ ∃m' ∈ N.m + m' = n
_≤'_ : ℕ → ℕ → Set
m ≤' n = Σ (λ m' → m + m' ≡eq n)
another:
-}
le : ℕ → ℕ → Bool
le zero n = true
le (suc m) zero = false
le (suc m) (suc n) = le m n
_≤'_ : ℕ → ℕ → Set
m ≤' n = le m n ≡ true
{-
EXERCISE : show reflexivity and transitivity with the alternate formalizations
involved example
implicational fragment of intuitionistic natural deduction is formalized in section 7.2
the relation Γ ⊢ A
between a context Γ and a type A
which is true when the sequent is provable
is defined inductively
------------------------------------------------------------------------------
-- p 295 6.6 Equality
Relation.Binary.PropositionalEquality
-- typed equality : compare elements of same type
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x -- only way to be equal is to be the same
------------------------------------------------------------------------------
6.6.1 Equality and pattern matching
example proof with equality : successor function on natural numbers is injective
- for every natural numbers m and n
- m + 1 = n + 1 ⇒ m = n
-}
-- p 296
suc-injective : {m n : ℕ} → suc m ≡ suc n → m ≡ n
-- suc-injective {m} {n} p -- Goal: m ≡ n; p : suc m ≡ suc n
-- case split on p : it can ONLY be refl
-- therefore m is equal to n
-- so agda provide .m - not really an arg - something equal to m
suc-injective {m} {.m} refl -- m ≡ m
= refl
{-
------------------------------------------------------------------------------
-- p 296 6.6.2 Main properties of equality: reflexive, congruence, symmetric, transitive
-}
sym : {A : Set} {x y : A}
→ x ≡ y
→ y ≡ x
sym refl = refl
trans : {A : Set} {x y z : A}
→ x ≡ y
→ y ≡ z
→ x ≡ z
trans refl refl = refl
cong : ∀ {A B : Set} (f : A → B) {x y : A}
→ x ≡ y
→ f x ≡ f y
cong f refl = refl
-- substitutivity : enables transporting the elements of a type along an equality
{-
subst : {A : Set} (P : A → Set) → {x y : A}
→ x ≡ y
→ P x
→ P y
subst P refl p = p
-}
-- https://stackoverflow.com/a/27789403
subst : ∀ {a p} {A : Set a} (P : A → Set p) {x y : A}
→ x ≡ y → P x → P y
subst P refl p = p
-- coercion : enables converting an element of type to another equal type
coe : {A B : Set}
→ A ≡ B
→ A
→ B
coe p x = subst (λ A → A) p x
-- see 9.1
{-
------------------------------------------------------------------------------
-- p 296 6.6.3 Half of even numbers : example every even number has a half
using proof strategy from 2.3
traditional notation : show ∀n ∈ N. isEven(n) ⇒ ∃m ∈ ℕ.m + m = n
-}
+-suc : ∀ (m n : ℕ)
→ m + suc n
≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = cong suc (+-suc m n)
-- even-half : {n : ℕ}
-- → isEven n
-- → Σ (λ m → m + m ≡ n) -- TODO (m : ℕ) → Set !=< Set
-- even-half even-z = zero , refl
-- even-half (even-s e) with even-half e
-- even-half (even-s e) | m , p =
-- suc m , cong suc (trans (+-suc m m) (cong suc p))
{-
second case : by induction have m such that m + m = n
need to construct a half for n + 2: m + 1
show that it is a half via
(m + 1) + (m + 1) = (m + (m + 1)) + 1 by definition of addition
= ((m + m) + 1) + 1 by +-suc
= (n + 1) + 1 since m + m = n
implemented using transitivity of equality and
fact that it is a congruence (m + 1 = n + 1 from m = n)
also use auxiliary lemma m + (n + 1) = (m + n) + 1
-}
{-
------------------------------------------------------------------------------
-- p 297 6.6.4 Reasoning
-}
--import Relation.Binary.PropositionalEquality as Eq
--open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
infix 3 _∎
infixr 2 _≡⟨⟩_ _≡⟨_⟩_
infix 1 begin_
begin_ : ∀ {ℓ} {A : Set ℓ} {x y : A} → x ≡ y → x ≡ y
begin_ x≡y = x≡y
_≡⟨⟩_ : ∀ {ℓ} {A : Set ℓ} (x {y} : A) → x ≡ y → x ≡ y
_ ≡⟨⟩ x≡y = x≡y
_≡⟨_⟩_ : {A : Set} (x {y z} : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
_∎ : ∀ {ℓ} {A : Set ℓ} (x : A) → x ≡ x
_∎ _ = refl
+-zero : ∀ (n : ℕ) → n + zero ≡ n
+-zero zero = refl
+-zero (suc n) rewrite +-zero n = refl
+-comm : (m n : ℕ) → m + n ≡ n + m
+-comm m zero = +-zero m
+-comm m (suc n) =
begin
(m + suc n) ≡⟨ +-suc m n ⟩ -- m + (n + 1) = (m + n) + 1 -- by +-suc
suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩ -- = (n + m) + 1 -- by induction hypothesis
suc (n + m)
∎
-- p 297
-- another proof using properties of equality
+-comm' : (m n : ℕ) → m + n ≡ n + m
+-comm' m zero = +-zero m
+-comm' m (suc n) = trans (+-suc m n) (cong suc (+-comm m n))
{-
------------------------------------------------------------------------------
-- p 298 6.6.5 Definitional equality
two terms which are convertible (i.e. re duce to a common term) are considered to be EQUAL.
not ≡, but equality internal to Agda, referred to as definitional equality
- cannot distinguish between two definitionally equal terms
- e.g., zero + n is definitionally equal to n (because addition defined that way)
- definitional equality implies equality by refl:
-}
+-zero''' : (n : ℕ) → zero + n ≡ n
+-zero''' n = refl
-- n + zero and n are not definitionally equal (because def of addition)
-- but can be proved
+-0 : (n : ℕ) → n + zero ≡ n
+-0 zero = refl
+-0 (suc n) = cong suc (+-zero n)
-- implies structure of definitions is important (and an art form)
------------------------------------------------------------------------------
-- p 298 6.6.6 More properties with equality
-- zero is NOT the successor of any NAT
zero-suc : {n : ℕ} → zero ≡ suc n → ⊥
zero-suc ()
+-assoc : (m n o : ℕ) → (m + n) + o ≡ m + (n + o)
+-assoc zero n o = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
-- p 299
*-+-dist-r : (m n o : ℕ)
→ (m + n) * o ≡ m * o + n * o
*-+-dist-r zero n o = refl
*-+-dist-r (suc m) n o
rewrite
+-comm n o
| *-+-dist-r m n o
| +-assoc o (m * o) (n * o)
= refl
*-assoc : (m n o : ℕ) → (m * n) * o ≡ m * (n * o)
*-assoc zero n o = refl
*-assoc (suc m) n o
rewrite
*-+-dist-r n (m * n) o
| *-assoc m n o
= refl
------------------------------------------------------------------------------
-- p 299 Lists
++-empty' : {A : Set}
→ (l : List A)
→ [] ++ l ≡ l
++-empty' l = refl
empty-++ : {A : Set}
→ (l : List A)
→ l ++ [] ≡ l
empty-++ [] = refl
empty-++ (x ∷ l) = cong (x ∷_) (empty-++ l)
++-assoc : {A : Set}
→ (l1 l2 l3 : List A)
→ ((l1 ++ l2) ++ l3) ≡ (l1 ++ (l2 ++ l3))
++-assoc [] l2 l3 = refl
++-assoc (x ∷ l1) l2 l3 = cong (x ∷_) (++-assoc l1 l2 l3)
-- TODO DOES NOT COMPILE: Set₁ != Set
-- ++-not-comm : ¬ ({A : Set} → (l1 l2 : List A)
-- → (l1 ++ l2) ≡ (l2 ++ l1))
-- ++-not-comm f with f (1 ∷ []) (2 ∷ [])
-- ... | ()
++-length : {A : Set}
→ (l1 l2 : List A)
→ length (l1 ++ l2) ≡ length l1 + length l2
++-length [] l2 = refl
++-length (x ∷ l1) l2 = cong (1 +_) (++-length l1 l2)
-- p 300
-- adds element to end of list
snoc : {A : Set} → List A → A → List A
snoc [] x = x ∷ []
snoc (y ∷ l) x = y ∷ (snoc l x)
-- reverse a list
rev : {A : Set} → List A → List A
rev [] = []
rev (x ∷ l) = snoc (rev l) x
-- reversing a list with x as the last element will prodice a list with x as the first element
rev-snoc : {A : Set}
→ (l : List A) → (x : A)
→ rev (snoc l x) ≡ x ∷ (rev l)
rev-snoc [] x = refl
rev-snoc (y ∷ l) x = cong (λ l → snoc l y) (rev-snoc l x)
-- reverse twice
rev-rev : {A : Set}
→ (l : List A)
→ rev (rev l) ≡ l
rev-rev [] = refl
rev-rev (x ∷ l) = trans (rev-snoc (rev l) x)
(cong (x ∷_) (rev-rev l))
--------------------------------------------------
-- p 300 6.6.7 The J rule.
-- equality
data _≡'_ {A : Set} : A → A → Set where
refl' : {x : A} → x ≡' x
-- has associated induction principle : J rule:
-- to prove P depending on equality proof p,
-- - prove it when this proof is refl
J : {A : Set} {x y : A}
(p : x ≡' y)
(P : (x y : A) → x ≡' y → Set)
(r : (x : A) → P x x refl')
→ P x y p
J {A} {x} {.x} refl' P r = r x
{-
section 6.6 shows that definition usually taken in Agda is different
(it uses a parameter instead of an index for the first argument of type A),
so that the resulting induction principle is a variant:
-}
J' : {A : Set}
(x : A)
(P : (y : A) → x ≡' y → Set)
(r : P x refl')
(y : A)
(p : x ≡' y)
→ P y p
J' x P r .x refl' = r
{-
--------------------------------------------------
p 301 6.6.8 Decidable equality.
A type A is decidable when either A or ¬A is provable.
Write Dec A for the type of proofs of decidability of A
- yes p, where p is a proof of A, or
- no q, where q is a proof of ¬A
A relation on a type A is decidable when
- the type R x y is decidable
- for every elements x and y of type A.
-}
-- in Relation.Binary
-- term of type Decidable R is proof that relation R is decidable
Decidable : {A : Set} (R : A → A → Set) → Set
Decidable {A} R = (x y : A) → Dec (R x y)
{-
A type A has decidable equality when equality relation _≡_ on A is decidable.
- means there is a function/algorithm able to determine,
given two elements of A,
whether they are equal or not
- return a PROOF (not a boolean)
-}
_≟_ : Decidable {A = Bool} _≡_
false ≟ false = yes refl
true ≟ true = yes refl
false ≟ true = no (λ ())
true ≟ false = no (λ ())
_≟ℕ_ : Decidable {A = ℕ} _≡_
zero ≟ℕ zero = yes refl
zero ≟ℕ suc n = no(λ())
suc m ≟ℕ zero = no(λ())
suc m ≟ℕ suc n with m ≟ℕ n
... | yes refl = yes refl
... | no ¬p = no (λ p → ¬p (suc-injective p))
{-
--------------------------------------------------
p 301 6.6.9 Heterogeneous equality : enables comparing (seemingly) distinct types
due to McBride [McB00]
p 302
e.g., show concatenation of vectors is associative
(l1 ++ l2) ++ l3 ≡ l1 ++ (l2 ++ l3) , where lengths are m, n and o
equality ≡ only used on terms of same type
- but types above are
- left Vec A ((m + n) + o)
- right Vec A (m + (n + o))
the two types are propositionally equal, can prove
Vec A ((m + n) + o) ≡ Vec A (m + (n + o))
by
cong (Vec A) (+-assoc m n o)
but the two types are not definitionally equal (required to compare terms with ≡)
PROOF WITH STANDARD EQUALITY.
To compare vecs, use above propositional equality
and'coe' to cast one of the members to the same type as other.
term
coe (cong (Vec A) (+-assoc m n o))
has type
Vec A ((m + n) + o) → Vec A (m + (n + o))
-}
-- lemma : if l and l’ are propositional equal vectors,
-- up to propositional equality of their types as above,
-- then x : l and x : l’ are also propositionally equal:
∷-cong : {A : Set} → {m n : ℕ} {l1 : Vec A m} {l2 : Vec A n}
→ (x : A)
→ (p : m ≡ n)
→ coe (PE.cong (Vec A) p) l1 ≡ l2
→ coe (PE.cong (Vec A) (PE.cong suc p)) (x ∷ l1) ≡ x ∷ l2
∷-cong x refl refl = refl
-- TODO this needs Vec ++ (only List ++ in scope)
-- ++-assoc' : {A : Set} {m n o : ℕ}
-- → (l1 : Vec A m)
-- → (l2 : Vec A n)
-- → (l3 : Vec A o)
-- → coe (PE.cong (Vec A) (+-assoc m n o))
-- ((l1 ++ l2) ++ l3) ≡ l1 ++ (l2 ++ l3)
-- ++-assoc' [] l2 l3 = refl
-- ++-assoc' {_} {suc m} {n} {o} (x ∷ l1) l2 l3 = ∷-cong x (+-assoc m n o) (++-assoc' l1 l2 l3)
{-
p 303 Proof with heterogeneous equality - TODO
------------------------------------------------------------------------------
p 303 6.7 Proving programs in practice
correctness means it agrees with a specification
correctness properties
- absence of errors : uses funs with args in correct domain (e.g., no divide by zero)
- invariants : properties always satisfied during execution
- functional properties : computes expected output on any given input
p 304 6.7.1 Extrinsic vs intrinsic proofs
extrinsic : first write program then prove properties about it (from "outside") e.g., sort : List ℕ → List ℕ
intrinsic : incorporate properties in types e.g., sort : List ℕ → SortList ℕ
example: length of concat of two lists is sum of their lengths
-}
-- extrinsic proof
++-length' : {A : Set}
→ (l1 l2 : List A)
→ length (l1 ++ l2) ≡ length l1 + length l2
++-length' [] l2 = refl
++-length' (x ∷ l1) l2 = PE.cong suc (++-length' l1 l2)
-- intrinsic
_V++_ : {m n : ℕ} {A : Set} → Vec A m → Vec A n → Vec A (m + n)
[] V++ l = l
(x ∷ l) V++ l' = x ∷ (l V++ l')
------------------------------------------------------------------------------
-- p 305 6.7.2 Insertion sort
|
{
"alphanum_fraction": 0.5076216968,
"avg_line_length": 26.8083519761,
"ext": "agda",
"hexsha": "789f702ba5816e10596c3e00db961eb8bc20c872",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/2019-Program_Proof-Samuel_Mimram/z-06.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/2019-Program_Proof-Samuel_Mimram/z-06.agda",
"max_line_length": 112,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/2019-Program_Proof-Samuel_Mimram/z-06.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 11806,
"size": 35950
}
|
module TrustMe where
open import Data.String
open import Data.String.Unsafe
open import Data.Unit.Polymorphic using (⊤)
open import IO
import IO.Primitive as Prim
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
-- Check that trustMe works.
testTrustMe : IO ⊤
testTrustMe with "apa" ≟ "apa"
... | yes refl = putStrLn "Yes!"
... | no _ = putStrLn "No."
main : Prim.IO ⊤
main = run testTrustMe
|
{
"alphanum_fraction": 0.7372093023,
"avg_line_length": 21.5,
"ext": "agda",
"hexsha": "862c17e1d3eafe036454fb7ca666aba9b7291ca1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Compiler/with-stdlib/TrustMe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/with-stdlib/TrustMe.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/with-stdlib/TrustMe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 118,
"size": 430
}
|
-- Mapping of Haskell types to Agda Types
module Foreign.Haskell.Types where
open import Prelude
open import Builtin.Float
{-# FOREIGN GHC import qualified GHC.Float #-}
{-# FOREIGN GHC import qualified Data.Text #-}
HSUnit = ⊤
HSBool = Bool
HSInteger = Int
HSList = List
HSChar = Char
HSString = HSList HSChar
HSText = String
postulate
HSFloat : Set
HSFloat=>Float : HSFloat → Float
lossyFloat=>HSFloat : Float → HSFloat
HSInt : Set
HSInt=>Int : HSInt → Int
lossyInt=>HSInt : Int → HSInt
{-# COMPILE GHC HSFloat = type Float #-}
{-# COMPILE GHC HSFloat=>Float = GHC.Float.float2Double #-}
{-# COMPILE GHC lossyFloat=>HSFloat = GHC.Float.double2Float #-}
{-# COMPILE GHC HSInt = type Int #-}
{-# COMPILE GHC HSInt=>Int = toInteger #-}
{-# COMPILE GHC lossyInt=>HSInt = fromInteger #-}
{-# FOREIGN GHC type AgdaTuple a b c d = (c, d) #-}
data HSTuple {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
_,_ : A → B → HSTuple A B
{-# COMPILE GHC HSTuple = data MAlonzo.Code.Foreign.Haskell.Types.AgdaTuple ((,)) #-}
|
{
"alphanum_fraction": 0.6727799228,
"avg_line_length": 25.2682926829,
"ext": "agda",
"hexsha": "1b80b2fabb82d4d0d34e210b82c80d0650c8bed6",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Foreign/Haskell/Types.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Foreign/Haskell/Types.agda",
"max_line_length": 85,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Foreign/Haskell/Types.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 312,
"size": 1036
}
|
open import Prelude
module Implicits.Resolution.Termination.Lemmas
where
open import Induction.WellFounded
open import Induction.Nat
open import Data.Fin.Substitution
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Data.Nat hiding (_<_)
open import Data.Nat.Properties
open import Relation.Binary using (module DecTotalOrder)
open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl)
open import Extensions.Nat
open import Implicits.Resolution.Termination.Lemmas.SizeMeasures public
-- open import Implicits.Resolution.Termination.Lemmas.Stack public
|
{
"alphanum_fraction": 0.8435672515,
"avg_line_length": 32.5714285714,
"ext": "agda",
"hexsha": "be2cc9ca4bffa43282636c1111f71f7106475be6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Termination/Lemmas.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Termination/Lemmas.agda",
"max_line_length": 71,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Termination/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 166,
"size": 684
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Groups.Definition
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Rings.Orders.Total.Definition {n m : _} {A : Set n} {S : Setoid {n} {m} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} where
open Ring R
open Group additiveGroup
open Setoid S
record TotallyOrderedRing {p : _} {_<_ : Rel {_} {p} A} {pOrder : SetoidPartialOrder S _<_} (pRing : PartiallyOrderedRing R pOrder) : Set (lsuc n ⊔ m ⊔ p) where
field
total : SetoidTotalOrder pOrder
open SetoidPartialOrder pOrder
|
{
"alphanum_fraction": 0.7222914072,
"avg_line_length": 34.9130434783,
"ext": "agda",
"hexsha": "15218ef80c28f9c1e549532768aa5d788de0d008",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Orders/Total/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Orders/Total/Definition.agda",
"max_line_length": 160,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Orders/Total/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 244,
"size": 803
}
|
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.FunctionOver
open import cohomology.FlipPushout
module cohomology.CofiberSequence {i} where
{- Lemma: pushing flip-susp through susp-fmap -}
flip-susp-fmap : {A B : Type i} (f : A → B)
→ ∀ σ → flip-susp (susp-fmap f σ) == susp-fmap f (flip-susp σ)
flip-susp-fmap f = Suspension-elim idp idp $ λ y → ↓-='-in $
ap-∘ (susp-fmap f) flip-susp (merid y)
∙ ap (ap (susp-fmap f)) (FlipSusp.merid-β y)
∙ ap-! (susp-fmap f) (merid y)
∙ ap ! (SuspFmap.merid-β f y)
∙ ! (FlipSusp.merid-β (f y))
∙ ! (ap (ap flip-susp) (SuspFmap.merid-β f y))
∙ ∘-ap flip-susp (susp-fmap f) (merid y)
{- Useful abbreviations -}
module _ {X Y : Ptd i} (f : fst (X ⊙→ Y)) where
⊙Cof² = ⊙Cof (⊙cfcod' f)
⊙cfcod² = ⊙cfcod' (⊙cfcod' f)
cfcod² = fst ⊙cfcod²
⊙Cof³ = ⊙Cof ⊙cfcod²
⊙cfcod³ = ⊙cfcod' ⊙cfcod²
cfcod³ = fst ⊙cfcod³
{- For [f : X → Y], the cofiber space [Cof(cfcod f)] is equivalent to
- [Suspension X]. This is essentially an application of the two pushouts
- lemma:
-
- f
- X ––––> Y ––––––––––––––> ∙
- | | |
- | |cfcod f |
- v v v
- ∙ ––> Cof f ––––––––––> Cof² f
- cfcod² f
-
- The map [cfcod² f : Cof f → Cof² f] becomes [ext-glue : Cof f → ΣX],
- and the map [ext-glue : Cof² f → ΣY] becomes [susp-fmap f : ΣX → ΣY].
-}
module Cof² {X Y : Ptd i} (f : fst (X ⊙→ Y)) where
module Equiv {X Y : Ptd i} (f : fst (X ⊙→ Y)) where
module Into = CofiberRec {f = cfcod' (fst f)} {C = fst (⊙Susp X)}
south ext-glue (λ _ → idp)
into = Into.f
⊙into : fst (⊙Cof² f ⊙→ ⊙Susp X)
⊙into = (into , ! (merid (snd X)))
module Out = SuspensionRec {C = fst (⊙Cof² f)}
(cfcod cfbase) cfbase
(λ x → ap cfcod (cfglue x) ∙ ! (cfglue (fst f x)))
out = Out.f
into-out : ∀ σ → into (out σ) == σ
into-out = Suspension-elim idp idp
(λ x → ↓-∘=idf-in into out $
ap (ap into) (Out.merid-β x)
∙ ap-∙ into (ap cfcod (cfglue x)) (! (cfglue (fst f x)))
∙ ap (λ w → ap into (ap cfcod (cfglue x)) ∙ w)
(ap-! into (cfglue (fst f x)) ∙ ap ! (Into.glue-β (fst f x)))
∙ ∙-unit-r _
∙ ∘-ap into cfcod (cfglue x) ∙ ExtGlue.glue-β x)
out-into : ∀ κ → out (into κ) == κ
out-into = Cofiber-elim {f = cfcod' (fst f)}
idp
(Cofiber-elim {f = fst f} idp cfglue
(λ x → ↓-='-from-square $
(ap-∘ out ext-glue (cfglue x)
∙ ap (ap out) (ExtGlue.glue-β x) ∙ Out.merid-β x)
∙v⊡ (vid-square {p = ap cfcod (cfglue x)}
⊡h rt-square (cfglue (fst f x)))
⊡v∙ ∙-unit-r _))
(λ y → ↓-∘=idf-from-square out into $
ap (ap out) (Into.glue-β y) ∙v⊡ connection)
eq = equiv into out into-out out-into
space-path : ⊙Cof² f == ⊙Susp X
space-path = ⊙ua (⊙≃-in eq (! (merid (snd X))))
cfcod²-over : cfcod² f == ext-glue
[ (λ U → fst (⊙Cof f) → fst U) ↓ Equiv.space-path f ]
cfcod²-over = ↓-cst2-in _ _ $ codomain-over-equiv (cfcod² f) _
cfcod³-over : ext-glue == flip-susp ∘ susp-fmap (fst f)
[ (λ U → fst U → fst (⊙Susp Y)) ↓ Equiv.space-path f ]
cfcod³-over = ↓-cst2-in _ _ $
domain!-over-equiv ext-glue _ ▹ λ= lemma
where
lemma : (σ : fst (⊙Susp X))
→ ext-glue (Equiv.out f σ) == flip-susp (susp-fmap (fst f) σ)
lemma = Suspension-elim idp idp
(λ x → ↓-='-in $
ap-∘ flip-susp (susp-fmap (fst f)) (merid x)
∙ ap (ap flip-susp) (SuspFmap.merid-β (fst f) x)
∙ FlipSusp.merid-β (fst f x)
∙ ! (ap-∘ ext-glue (Equiv.out f) (merid x)
∙ ap (ap ext-glue) (Equiv.Out.merid-β f x)
∙ ap-∙ ext-glue (ap cfcod (cfglue x))
(! (cfglue (fst f x)))
∙ (∘-ap ext-glue cfcod (cfglue x)
∙ ap-cst south (cfglue x))
∙2
(ap-! ext-glue (cfglue (fst f x))
∙ ap ! (ExtGlue.glue-β (fst f x)))))
open Equiv f public
cofiber-sequence : {X Y : Ptd i} (f : fst (X ⊙→ Y)) → Path
{A = Σ (Ptd i × Ptd i)
(λ {(U , V) → (fst (⊙Cof f) → fst U) × (fst U → fst V)})}
((⊙Cof² f , ⊙Cof³ f) , cfcod² f , cfcod³ f)
((⊙Susp X , ⊙Susp Y) , ext-glue , susp-fmap (fst f))
cofiber-sequence {X} {Y} f =
ap (λ {(Z , g) → ((⊙Cof² f , Z) , cfcod² f , g)})
(pair= (Cof².space-path (⊙cfcod' f)) (Cof².cfcod²-over (⊙cfcod' f)))
∙ ap (λ {(Z , g , h) → ((Z , ⊙Susp Y) , g , h)})
(pair= (Cof².space-path f)
(↓-×-in (Cof².cfcod²-over f) (Cof².cfcod³-over f)))
∙ ap (λ {(Z , g) → ((⊙Susp X , Z) , ext-glue , g)})
(pair= (flip-⊙pushout-path (suspension-⊙span Y))
(↓-cst2-in _ _ $ codomain!-over-equiv _ _))
|
{
"alphanum_fraction": 0.5021925245,
"avg_line_length": 35.7388059701,
"ext": "agda",
"hexsha": "8dea6683351008cf0caf894be9eef94a26a7dc98",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/CofiberSequence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/CofiberSequence.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/CofiberSequence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2020,
"size": 4789
}
|
-- Andreas, 2016-06-20
-- Issue #436 fixed by Ulf's instantiating parameters sprint
-- (Agda meeting April 2016 Strathclyde)
data _==_ {A : Set} (x : A) : A -> Set where
refl : x == x
foo : {A : Set} (x y : A) -> x == y -> A
foo x y = \ { eq → {!eq!} } -- load and do C-c C-c in the shed
-- Should work now (and is justified by new semantics).
|
{
"alphanum_fraction": 0.5902578797,
"avg_line_length": 29.0833333333,
"ext": "agda",
"hexsha": "47fd1f85b84e718f7ee914161be3fd5b380fbe16",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue436.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue436.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue436.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 123,
"size": 349
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
-- These are explicitly with-K, because we currently encode an element of Zn as
-- a natural together with a proof that it is small.
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Semirings.Definition
open import Orders.Total.Definition
open import Numbers.Modulo.Definition
open import Numbers.Modulo.ModuloFunction
open import Numbers.Naturals.Order.Lemmas
module Numbers.Modulo.Addition where
open TotalOrder ℕTotalOrder
_+n_ : {n : ℕ} .(pr : 0 <N n) → ℤn n pr → ℤn n pr → ℤn n pr
_+n_ {n} pr a b = record { x = mod n pr (ℤn.x a +N ℤn.x b) ; xLess = mod<N pr _ }
plusZnIdentityRight : {n : ℕ} → .(pr : 0 <N n) → (a : ℤn n pr) → (_+n_ pr a record { x = 0 ; xLess = pr }) ≡ a
plusZnIdentityRight 0<n record { x = x ; xLess = xLess } rewrite Semiring.sumZeroRight ℕSemiring x = equalityZn (modIsMod 0<n x (<NProp xLess))
plusZnIdentityLeft : {n : ℕ} → .(pr : 0 <N n) → (a : ℤn n pr) → _+n_ pr (record { x = 0 ; xLess = pr }) a ≡ a
plusZnIdentityLeft 0<n record { x = x ; xLess = xLess } = equalityZn (modIsMod 0<n x (<NProp xLess))
plusZnCommutative : {n : ℕ} → .(pr : 0 <N n) → (a b : ℤn n pr) → _+n_ pr a b ≡ _+n_ pr b a
plusZnCommutative {n} 0<n a b = equalityZn (applyEquality (mod n 0<n) (Semiring.commutative ℕSemiring (ℤn.x a) _))
plusZnAssociative' : {n : ℕ} → .(pr : 0 <N n) → {a b c : ℕ} → (a <N n) → (b <N n) → (c <N n) → mod n pr ((mod n pr (a +N b)) +N c) ≡ mod n pr (a +N (mod n pr (b +N c)))
plusZnAssociative' 0<n {a} {b} {c} a<n b<n c<n with modAddition 0<n a<n b<n
plusZnAssociative' {n} 0<n {a} {b} {c} a<n b<n c<n | inl a+b=mod with modAddition 0<n b<n c<n
... | inl b+c=mod rewrite equalityCommutative (a+b=mod) | equalityCommutative (b+c=mod) = applyEquality (mod _ 0<n) (equalityCommutative (Semiring.+Associative ℕSemiring a b c))
... | inr b+c=n+mod rewrite equalityCommutative (a+b=mod) | equalityCommutative (modAnd+n 0<n (a +N mod _ 0<n (b +N c))) | Semiring.+Associative ℕSemiring n a (mod _ 0<n (b +N c)) | Semiring.commutative ℕSemiring n a | equalityCommutative (Semiring.+Associative ℕSemiring a n (mod _ 0<n (b +N c))) | equalityCommutative b+c=n+mod = applyEquality (mod _ 0<n) (equalityCommutative (Semiring.+Associative ℕSemiring a b c))
plusZnAssociative' 0<n {a} {b} {c} a<n b<n c<n | inr a+b=n+mod with modAddition 0<n b<n c<n
plusZnAssociative' {n} 0<n {a} {b} {c} a<n b<n c<n | inr a+b=n+mod | inl b+c=mod rewrite equalityCommutative b+c=mod | equalityCommutative (modAnd+n 0<n (mod _ 0<n (a +N b) +N c)) | Semiring.+Associative ℕSemiring n (mod _ 0<n (a +N b)) c | equalityCommutative a+b=n+mod = applyEquality (mod _ 0<n) (equalityCommutative (Semiring.+Associative ℕSemiring a b c))
plusZnAssociative' {n} 0<n {a} {b} {c} a<n b<n c<n | inr a+b=n+mod | inr b+c=n+mod rewrite equalityCommutative (modAnd+n 0<n ((mod _ 0<n (a +N b)) +N c)) | equalityCommutative (modAnd+n 0<n (a +N mod _ 0<n (b +N c))) | Semiring.+Associative ℕSemiring n (mod _ 0<n (a +N b)) c | equalityCommutative (a+b=n+mod) | Semiring.commutative ℕSemiring a (mod n 0<n (b +N c)) | Semiring.+Associative ℕSemiring n (mod n 0<n (b +N c)) a | equalityCommutative b+c=n+mod | Semiring.commutative ℕSemiring (b +N c) a = applyEquality (mod _ 0<n) (equalityCommutative (Semiring.+Associative ℕSemiring a b c))
plusZnAssociative : {n : ℕ} → .(pr : 0 <N n) → (a b c : ℤn n pr) → _+n_ pr (_+n_ pr a b) c ≡ _+n_ pr a (_+n_ pr b c)
plusZnAssociative {succ n} 0<sn record { x = a ; xLess = aLess } record { x = b ; xLess = bLess } record { x = c ; xLess = cLess } = equalityZn t
where
ma = mod (succ n) 0<sn a
mb = mod (succ n) 0<sn b
mc = mod (succ n) 0<sn c
v : mod (succ n) 0<sn ((mod (succ n) 0<sn (ma +N mb)) +N mc) ≡ mod (succ n) 0<sn (ma +N mod (succ n) 0<sn (mb +N mc))
v = plusZnAssociative' 0<sn (mod<N 0<sn a) (mod<N 0<sn b) (mod<N 0<sn c)
u : mod (succ n) 0<sn ((mod (succ n) 0<sn (mod (succ n) 0<sn a +N (mod (succ n) 0<sn b))) +N c) ≡ mod (succ n) 0<sn (a +N mod (succ n) 0<sn ((mod (succ n) 0<sn b) +N (mod (succ n) 0<sn c)))
u rewrite equalityCommutative (modIsMod 0<sn c (<NProp cLess)) | equalityCommutative (modIsMod 0<sn a (<NProp aLess)) | modIdempotent 0<sn a | modIdempotent 0<sn c = v
t : mod (succ n) 0<sn (mod (succ n) 0<sn (a +N b) +N c) ≡ mod (succ n) 0<sn (a +N mod (succ n) 0<sn (b +N c))
t rewrite modExtracts {succ n} 0<sn a b | modExtracts {succ n} 0<sn b c = u
|
{
"alphanum_fraction": 0.6431293432,
"avg_line_length": 89.22,
"ext": "agda",
"hexsha": "2f0d3ee388ad2f7d5533ec83970bc8fc7eb05ad6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Modulo/Addition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Modulo/Addition.agda",
"max_line_length": 590,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Modulo/Addition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 1819,
"size": 4461
}
|
module Prelude where
infixr 90 _∘_
infixr 0 _$_
id : {A : Set} -> A -> A
id x = x
_∘_ : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C
(f ∘ g) x = f (g x)
_$_ : {A B : Set} -> (A -> B) -> A -> B
f $ x = f x
flip : {A B C : Set} -> (A -> B -> C) -> B -> A -> C
flip f x y = f y x
const : {A B : Set} -> A -> B -> A
const x _ = x
typeOf : {A : Set} -> A -> Set
typeOf {A} _ = A
typeOf1 : {A : Set1} -> A -> Set1
typeOf1 {A} _ = A
|
{
"alphanum_fraction": 0.4123006834,
"avg_line_length": 15.6785714286,
"ext": "agda",
"hexsha": "51cf6c419fc56933a5a2a013e7a2fa787eb4538a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Prelude.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Prelude.agda",
"max_line_length": 53,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 208,
"size": 439
}
|
{-# OPTIONS --without-K #-}
module HoTT.Sigma.Transport where
open import HoTT.Base
open import HoTT.Identity
open import HoTT.Identity.Sigma
Σ-transport : ∀ {i j k} {A : 𝒰 i} {P : A → 𝒰 j} {Q : (Σ A λ x → P x) → 𝒰 k} {x y : A} →
(p : x == y) (uz : Σ (P x) λ u → Q (x , u)) →
transport (λ x → Σ (P x) λ u → Q (x , u)) p uz ==
transport _ p (pr₁ uz) , transport Q (pair⁼ (p , refl)) (pr₂ uz)
Σ-transport refl (u , z) = refl
|
{
"alphanum_fraction": 0.5074626866,
"avg_line_length": 36.0769230769,
"ext": "agda",
"hexsha": "91add779fe72a988b30aae2560294174285bd861",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Sigma/Transport.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Sigma/Transport.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Sigma/Transport.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 181,
"size": 469
}
|
-- Andreas, 2015-01-19 Forced constructor arguments should not
-- give rise to unification constraints.
-- Andreas, 2015-02-27 Forcing analysis is too fragile to have
-- such a huge impact. The problem has to be addressed by
-- putting heterogeneous unification on a solid foundation.
-- Jesper, 2015-12-18 The new unifier now correctly rejects this example.
-- {-# OPTIONS -v tc.lhs.unify:15 #-}
-- {-# OPTIONS -v tc.force:10 #-}
open import Common.Equality
open import Common.Prelude
data HEq (A : Set) (a : A) : (B : Set) (b : B) → Set1 where
refl : HEq A a A a
-- Abstracting over suc disables forcing [Issue 1427]
module M (s : Nat → Nat) where
data Fin : (n : Nat) → Set where
zero : {n : Nat} → Fin (s n)
suc : {n : Nat} (i : Fin n) → Fin (s n)
open M suc
inj-Fin-≅ : ∀ {n m} {i : Fin n} {j : Fin m} → HEq (Fin n) i (Fin m) j → n ≡ m
inj-Fin-≅ {i = zero} {zero } refl = refl -- Expected to fail, as n /= m
inj-Fin-≅ {i = zero} {suc j} ()
inj-Fin-≅ {i = suc i} {zero } ()
inj-Fin-≅ {i = suc i} {suc .i} refl = refl -- Expected to fail, as n /= m
-- This should not be accepted, as the direct attempt also fails:
-- inj-Fin-≅' : ∀ {n m} {i : Fin n} {j : Fin m} → HEq (Fin n) i (Fin m) j → n ≡ m
-- inj-Fin-≅' refl = refl
|
{
"alphanum_fraction": 0.5981161695,
"avg_line_length": 33.5263157895,
"ext": "agda",
"hexsha": "ec433bc6ed57459ea890becad63f9537d45be6be",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1427b.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1427b.agda",
"max_line_length": 81,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1427b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 462,
"size": 1274
}
|
open import Relation.Binary.Core
module BBSTree.Properties {A : Set}
(_≤_ : A → A → Set)
(trans≤ : Transitive _≤_) where
open import BBSTree _≤_
open import Bound.Total A
open import Bound.Total.Order.Properties _≤_ trans≤
open import List.Order.Simple _≤_
open import List.Order.Simple.Properties _≤_ trans≤
open import List.Sorted _≤_
lemma-bbst-*≤ : {b : Bound}(x : A) → (t : BBSTree b (val x)) → flatten t *≤ x
lemma-bbst-*≤ x (bslf _) = lenx
lemma-bbst-*≤ x (bsnd {x = y} b≤y y≤x l r) = lemma-++-*≤ (lemma-LeB≤ y≤x) (lemma-bbst-*≤ y l) (lemma-bbst-*≤ x r)
lemma-bbst-≤* : {b : Bound}(x : A) → (t : BBSTree (val x) b) → x ≤* flatten t
lemma-bbst-≤* x (bslf _) = genx
lemma-bbst-≤* x (bsnd {x = y} x≤y y≤t l r) = lemma-≤*-++ (lemma-LeB≤ x≤y) (lemma-bbst-≤* x l) (lemma-bbst-≤* y r)
lemma-bbst-sorted : {b t : Bound}(t : BBSTree b t) → Sorted (flatten t)
lemma-bbst-sorted (bslf _) = nils
lemma-bbst-sorted (bsnd {x = x} b≤x x≤t l r) = lemma-sorted++ (lemma-bbst-*≤ x l) (lemma-bbst-≤* x r) (lemma-bbst-sorted l) (lemma-bbst-sorted r)
|
{
"alphanum_fraction": 0.6012891344,
"avg_line_length": 43.44,
"ext": "agda",
"hexsha": "4ad3c06cc886e1fccd72b9d044ff3379d6110948",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/BBSTree/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/BBSTree/Properties.agda",
"max_line_length": 145,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/BBSTree/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 445,
"size": 1086
}
|
{-# OPTIONS --without-K #-}
open import hott.core
open import hott.core.theorems
open import hott.functions
-- An important theorem in topology is to show the 2-dimensional loop
-- space is abelian. To avoid notational clutter we parameterize the
-- common variables as module parameters.
module hott.topology.loopspace.eckmann-hilton {ℓ : Level}{A : Type ℓ}{a : A}
where
-- Let us give a name to the trivial loop at a
reflₐ : a ≡ a
reflₐ = refl {ℓ}{A}{a}
open import hott.topology.loopspace
-- Eckmann-Hilton : (α β : Ω² (A , a)) → α ∙ β ≡ β ∙ α
-- This uses the wiskering technique. Consider the following paths
-- ____ p₀ ___ ____ p₁ ____
-- / \ / \
-- a₀ α₀ a₁ α₁ a₁
-- \ / \ /
-- --- q₀ ---- ---- q₁ ----
--
-- The 2-dimensional α₀ and α₀ paths cannot be composed in general
-- as the end point of α₀ (i.e. q₀) is not the starting point of α₁
-- (i.e. p₁). However, because the paths are 2-dimenional paths we
-- can compose them horizontally which we denote by ⋆. We
-- encapsulate this composition inside a module called wiskering.
--
module wiskering {x y : A}{p q : x ≡ y} where
_∙ᵣ_ : {z : A} (α : p ≡ q)(r : y ≡ z) → p ∙ r ≡ q ∙ r
α ∙ᵣ refl = p∙refl≡p p ∙ α ∙ p≡p∙refl q
_∙ₗ_ : {w : A}(r : w ≡ x)(β : p ≡ q) → r ∙ p ≡ r ∙ q
refl ∙ₗ β = refl∙p≡p p ∙ β ∙ p≡refl∙p q
open wiskering
-------- Lemmas on wiskering ------------------------------------
-- The next two lemma specialises the wiskering when one of the
-- paths is refl.
α∙ᵣrefl≡α : (α : reflₐ ≡ reflₐ) → α ∙ᵣ reflₐ ≡ α
α∙ᵣrefl≡α α =
begin α ∙ᵣ refl ≡ refl ∙ α ∙ refl by definition
≡ α ∙ refl by applying flip _∙_ refl
on refl∙p≡p α
≡ α by p∙refl≡p α
∎
refl∙ₗβ≡β : (β : reflₐ ≡ reflₐ) → reflₐ ∙ₗ β ≡ β
refl∙ₗβ≡β β =
begin refl ∙ₗ β ≡ refl ∙ β ∙ refl by definition
≡ β ∙ refl by applying flip _∙_ refl
on refl∙p≡p β
≡ β by p∙refl≡p β
∎
---------- End of lemma on wiskering -----------------------------
-- With wiskering we can now define two different horizontal
-- composition of higher order paths.
module horizontal {a₀ a₁ a₂ : A}{p q : a₀ ≡ a₁}{r s : a₁ ≡ a₂} where
_⋆_ : (α : p ≡ q)
→ (β : r ≡ s)
→ p ∙ r ≡ q ∙ s -- α₀ ⋆ α₁
α ⋆ β = (α ∙ᵣ r) ∙ (q ∙ₗ β)
_⋆′_ : (α : p ≡ q)
→ (β : r ≡ s)
→ p ∙ r ≡ q ∙ s
α ⋆′ β = (p ∙ₗ β) ∙ (α ∙ᵣ s)
open horizontal
-- The shows that either ways of horizontal composition gives the
-- same higher homotopy. Here we need to induct on all α β an
⋆≡⋆′ : {p : a ≡ a}{r : a ≡ a}
(α : p ≡ reflₐ) (β : reflₐ ≡ r )
→ α ⋆ β ≡ α ⋆′ β
⋆≡⋆′ refl refl = refl
-- The specialisation of the above lemma for elements in the second
-- loop space.
⋆≡⋆′-refl : {α β : Ω² (A , a)} → α ⋆ β ≡ α ⋆′ β
⋆≡⋆′-refl {α} {β} = ⋆≡⋆′ α β
-- When every path is refl horizontal compositions α ⋆ β and α ⋆′ β
-- reduce to α ∙ β and β ∙ α respectively. The proofs are given at
-- the end.
α⋆β≡α∙β : {α β : Ω² (A , a)} → α ⋆ β ≡ α ∙ β
α⋆′β≡β∙α : {α β : Ω² (A , a)} → α ⋆′ β ≡ β ∙ α
-- From which we get the Eckmann-Hilton theorem.
Eckmann-Hilton : (α β : Ω² (A , a)) → α ∙ β ≡ β ∙ α
Eckmann-Hilton α β = begin α ∙ β ≡ α ⋆ β by α⋆β≡α∙β ⁻¹
≡ α ⋆′ β by ⋆≡⋆′-refl
≡ β ∙ α by α⋆′β≡β∙α
-- Proofs.
α⋆β≡α∙β {α}{β} =
begin α ⋆ β ≡ (α ∙ᵣ refl) ∙ (refl ∙ₗ β)
by definition
≡ (α ∙ᵣ refl) ∙ β
by applying _∙_ (α ∙ᵣ refl) on refl∙ₗβ≡β β
≡ α ∙ β
by applying flip _∙_ β on α∙ᵣrefl≡α α
∎
α⋆′β≡β∙α {α}{β} =
begin α ⋆′ β ≡ (refl ∙ₗ β) ∙ (α ∙ᵣ refl)
by definition
≡ (refl ∙ₗ β) ∙ α
by applying _∙_ (refl ∙ₗ β) on α∙ᵣrefl≡α α
≡ β ∙ α
by applying flip _∙_ α on refl∙ₗβ≡β β
∎
|
{
"alphanum_fraction": 0.473897497,
"avg_line_length": 31.7803030303,
"ext": "agda",
"hexsha": "0ad6aa34e6d1a3055712f61d566ab0e98540e6a7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/hott/topology/loopspace/eckmann-hilton.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "piyush-kurur/hott",
"max_issues_repo_path": "agda/hott/topology/loopspace/eckmann-hilton.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/hott/topology/loopspace/eckmann-hilton.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1725,
"size": 4195
}
|
module Issue512 where
open import Common.Equality
data A : Set where
a b : A
proof : a ≡ a
proof = refl
f : A → A → A
f x y rewrite proof = {!!}
-- gave error below (now complains about LEVELZERO instead of STRING):
-- No binding for builtin thing STRING, use {-# BUILTIN STRING name #-} to bind it to 'name'
-- when checking that the type of the generated with function
-- (w : A) → _≡_ {"Max []"} {A} w w → (x y : A) → A is well-formed
-- Andreas, 2014-05-17: After fixing 1110, there is no error any more,
-- just an unsolved meta.
|
{
"alphanum_fraction": 0.65625,
"avg_line_length": 24.7272727273,
"ext": "agda",
"hexsha": "25cbd6a7d97ad7f838208c9e659ce54a9945202e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue512.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue512.agda",
"max_line_length": 92,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue512.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 165,
"size": 544
}
|
{-# OPTIONS --allow-unsolved-metas #-}
open import Tutorials.Monday-Complete
module Tutorials.Tuesday where
-----------
-- Pi and Sigma types
-----------
module Product where
-- The open keyword opens a given module in the current namespace
-- By default all of the public names of the module are opened
-- The using keyword limits the imported definitions to those explicitly listed
open Fin
open Vec using (Vec; []; _∷_)
open Simple using (¬_)
variable
P Q : A → Set
-- Pi types: dependent function types
-- For every x of type A, the predicate P x holds
Π : (A : Set) → (Pred A) → Set
Π A P = (x : A) → P x
infix 5 _,_
-- Sigma types: dependent product types, existential types
-- For this x of type A, the predicate P x holds
record Σ (A : Set) (P : Pred A) : Set where
-- In the type P fst, fst refers to a previously introduced field
constructor _,_
field
fst : A
snd : P fst
open Σ public
-- By depending on a boolean we can use pi types to represent product types
Π-× : Set → Set → Set
Π-× A B = Π Bool λ where
true → A
false → B
-- By depending on a boolean we can use sigma types to represent sum types
Σ-⊎ : Set → Set → Set
Σ-⊎ A B = Σ Bool λ where
true → A
false → B
-- Use pi types to recover function types
Π-→ : Set → Set → Set
Π-→ A B = Π A λ where
_ → B
-- Use sigma types to recover product types
Σ-× : Set → Set → Set
Σ-× A B = Σ A λ where
_ → B
infix 5 _×_
_×_ : Set → Set → Set
_×_ = Σ-×
-- 1) If we can transform the witness and
-- 2) transform the predicate as per the transformation on the witness
-- ⇒) then we can transform a sigma type
map : (f : A → B) → (∀ {x} → P x → Q (f x)) → (Σ A P → Σ B Q)
map f g (x , y) = (f x , g y)
-- The syntax keyword introduces notation that can include binders
infix 4 Σ-syntax
Σ-syntax : (A : Set) → (A → Set) → Set
Σ-syntax = Σ
syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
¬∘ : Pred A → Pred A
¬∘ P = ¬_ ∘ P
-- These can be proven regardless of A
¬∃⇒∀¬ : ¬ (Σ A P) → Π A (¬∘ P)
¬∃⇒∀¬ = {!!}
∃¬⇒¬∀ : Σ A (¬∘ P) → ¬ Π A P
∃¬⇒¬∀ = {!!}
∀¬⇒¬∃ : Π A (¬∘ P) → ¬ Σ A P
∀¬⇒¬∃ = {!!}
-- Works in classical, not in constructive mathematics
postulate ¬∀⇒∃¬ : ¬ Π A P → Σ A (¬∘ P)
-- Show that ≤ is antisymmetric
≤-≡ : n ≤ m → m ≤ n → n ≡ m
≤-≡ x y = {!!}
-- By using n ≤ m instead of Fin m we can mention n in the output
take : Vec A m → n ≤ m → Vec A n
take xs lte = {!!}
Fin-to-≤ : (i : Fin m) → to-ℕ i < m
Fin-to-≤ i = {!!}
-- Proof combining sigma types and equality
≤-to-Fin : n < m → Fin m
≤-to-Fin lt = {!!}
Fin-≤-inv : (i : Fin m) → ≤-to-Fin (Fin-to-≤ i) ≡ i
Fin-≤-inv i = {!!}
≤-Fin-inv : (lt : Σ[ n ∈ ℕ ] n < m)
→ (to-ℕ (≤-to-Fin (snd lt)) , Fin-to-≤ (≤-to-Fin (snd lt))) ≡ lt
≤-Fin-inv lt = {!!}
|
{
"alphanum_fraction": 0.5468695953,
"avg_line_length": 25.3596491228,
"ext": "agda",
"hexsha": "564f8167f1258e2ffa46bf5fbfb33ad66725075c",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-11-24T10:50:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-23T08:50:13.000Z",
"max_forks_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "poncev/agda-bcam",
"max_forks_repo_path": "Tutorials/Tuesday.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "poncev/agda-bcam",
"max_issues_repo_path": "Tutorials/Tuesday.agda",
"max_line_length": 81,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "poncev/agda-bcam",
"max_stars_repo_path": "Tutorials/Tuesday.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-03T22:53:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T17:59:21.000Z",
"num_tokens": 1099,
"size": 2891
}
|
{-# OPTIONS --no-termination-check #-}
module AC where
import Nat
import Bool
import List
import Fin
import Logic
import Vec
import EqProof
open Nat hiding (_<_) renaming (_==_ to _=Nat=_)
open Bool
open List hiding (module Eq)
open Fin renaming (_==_ to _=Fin=_)
open Logic
open Vec
infix 20 _○_
infix 10 _≡_
ForAll : {A : Set}(n : Nat) -> (Vec n A -> Set) -> Set
ForAll zero F = F ε
ForAll {A} (suc n) F = (x : A) -> ForAll _ \xs -> F (x ∷ xs)
apply : {n : Nat}{A : Set}(F : Vec n A -> Set) -> ForAll n F -> (xs : Vec n A) -> F xs
apply {zero} F t (vec vnil) = t
apply {suc n} F f (vec (vcons x xs)) = apply _ (f x) xs
lambda : {n : Nat}{A : Set}(F : Vec n A -> Set) -> ((xs : Vec n A) -> F xs) -> ForAll n F
lambda {zero } F f = f ε
lambda {suc n} F f = \x -> lambda _ (\xs -> f (x ∷ xs))
data Expr (n : Nat) : Set where
zro : Expr n
var : Fin n -> Expr n
_○_ : Expr n -> Expr n -> Expr n
data Theorem (n : Nat) : Set where
_≡_ : Expr n -> Expr n -> Theorem n
theorem : (n : Nat) -> ({m : Nat} -> ForAll {Expr m} n \_ -> Theorem m) -> Theorem n
theorem n thm = apply _ thm (map var (fzeroToN-1 n))
module Provable where
NF : Nat -> Set
NF n = List (Fin n)
infix 12 _⊕_
_⊕_ : {n : Nat} -> NF n -> NF n -> NF n
[] ⊕ ys = ys
x :: xs ⊕ [] = x :: xs
x :: xs ⊕ y :: ys = if x < y
then x :: (xs ⊕ y :: ys)
else y :: (x :: xs ⊕ ys)
normalise : {n : Nat} -> Expr n -> NF n
normalise zro = []
normalise (var n) = n :: []
normalise (a ○ b) = normalise a ⊕ normalise b
infix 30 _↓
_↓ : {n : Nat} -> NF n -> Expr n
(i :: is) ↓ = var i ○ is ↓
[] ↓ = zro
infix 10 _=Expr=_ _=NF=_
_=NF=_ : {n : Nat} -> NF n -> NF n -> Bool
_=NF=_ = ListEq._==_
where
module ListEq = List.Eq _=Fin=_
substNF : {n : Nat}{xs ys : NF n}(P : NF n -> Set) -> IsTrue (xs =NF= ys) -> P xs -> P ys
substNF = List.Subst.subst _=Fin=_ (subst {_})
_=Expr=_ : {n : Nat} -> Expr n -> Expr n -> Bool
a =Expr= b = normalise a =NF= normalise b
provable : {n : Nat} -> Theorem n -> Bool
provable (a ≡ b) = a =Expr= b
module Semantics
{A : Set}
(_==_ : A -> A -> Set)
(_*_ : A -> A -> A)
(one : A)
(refl : {x : A} -> x == x)
(sym : {x y : A} -> x == y -> y == x)
(trans : {x y z : A} -> x == y -> y == z -> x == z)
(idL : {x : A} -> (one * x) == x)
(idR : {x : A} -> (x * one) == x)
(comm : {x y : A} -> (x * y) == (y * x))
(assoc : {x y z : A} -> (x * (y * z)) == ((x * y) * z))
(congL : {x y z : A} -> y == z -> (x * y) == (x * z))
(congR : {x y z : A} -> x == y -> (x * z) == (y * z))
where
open Provable
module EqP = EqProof _==_ refl trans
open EqP
expr[_] : {n : Nat} -> Expr n -> Vec n A -> A
expr[ zro ] ρ = one
expr[ var i ] ρ = ρ ! i
expr[ a ○ b ] ρ = expr[ a ] ρ * expr[ b ] ρ
eq[_] : {n : Nat} -> Theorem n -> Vec n A -> Set
eq[ a ≡ b ] ρ = expr[ a ] ρ == expr[ b ] ρ
data CantProve (A : Set) : Set where
no-proof : CantProve A
Prf : {n : Nat} -> Theorem n -> Bool -> Set
Prf thm true = ForAll _ \ρ -> eq[ thm ] ρ
Prf thm false = CantProve (Prf thm true)
Proof : {n : Nat} -> Theorem n -> Set
Proof thm = Prf thm (provable thm)
lem0 : {n : Nat} -> (xs ys : NF n) -> (ρ : Vec n A) ->
eq[ xs ↓ ○ ys ↓ ≡ (xs ⊕ ys) ↓ ] ρ
lem0 [] ys ρ = idL
lem0 (x :: xs) [] ρ = idR
lem0 (x :: xs) (y :: ys) ρ = if' x < y then less else more
where
lhs = (var x ○ xs ↓) ○ (var y ○ ys ↓)
lbranch = x :: (xs ⊕ y :: ys)
rbranch = y :: (x :: xs ⊕ ys)
P = \z -> eq[ lhs ≡ (if z then lbranch else rbranch) ↓ ] ρ
less : IsTrue (x < y) -> _
less x<y = BoolEq.subst {true}{x < y} P x<y
(spine (lem0 xs (y :: ys) ρ))
where
spine : forall {x' xs' y' ys' zs} h -> _
spine {x'}{xs'}{y'}{ys'}{zs} h =
eqProof> (x' * xs') * (y' * ys')
=== x' * (xs' * (y' * ys')) by sym assoc
=== x' * zs by congL h
more : IsFalse (x < y) -> _
more x>=y = BoolEq.subst {false}{x < y} P x>=y
(spine (lem0 (x :: xs) ys ρ))
where
spine : forall {x' xs' y' ys' zs} h -> _
spine {x'}{xs'}{y'}{ys'}{zs} h =
eqProof> (x' * xs') * (y' * ys')
=== (y' * ys') * (x' * xs') by comm
=== y' * (ys' * (x' * xs')) by sym assoc
=== y' * ((x' * xs') * ys') by congL comm
=== y' * zs by congL h
lem1 : {n : Nat} -> (e : Expr n) -> (ρ : Vec n A) -> eq[ e ≡ normalise e ↓ ] ρ
lem1 zro ρ = refl
lem1 (var i) ρ = sym idR
lem1 (a ○ b) ρ = trans step1 (trans step2 step3)
where
step1 : eq[ a ○ b ≡ normalise a ↓ ○ b ] ρ
step1 = congR (lem1 a ρ)
step2 : eq[ normalise a ↓ ○ b ≡ normalise a ↓ ○ normalise b ↓ ] ρ
step2 = congL (lem1 b ρ)
step3 : eq[ normalise a ↓ ○ normalise b ↓ ≡ (normalise a ⊕ normalise b) ↓ ] ρ
step3 = lem0 (normalise a) (normalise b) ρ
lem2 : {n : Nat} -> (xs ys : NF n) -> (ρ : Vec n A) -> IsTrue (xs =NF= ys) -> eq[ xs ↓ ≡ ys ↓ ] ρ
lem2 xs ys ρ eq = substNF {_}{xs}{ys} (\z -> eq[ xs ↓ ≡ z ↓ ] ρ) eq refl
prove : {n : Nat} -> (thm : Theorem n) -> Proof thm
prove thm = proof (provable thm) thm (\h -> h)
where
proof : {n : Nat}(valid : Bool)(thm : Theorem n) -> (IsTrue valid -> IsTrue (provable thm)) -> Prf thm valid
proof false _ _ = no-proof
proof true (a ≡ b) isValid = lambda eq[ a ≡ b ] \ρ ->
trans (step-a ρ) (trans (step-ab ρ) (step-b ρ))
where
step-a : forall ρ -> eq[ a ≡ normalise a ↓ ] ρ
step-a ρ = lem1 a ρ
step-b : forall ρ -> eq[ normalise b ↓ ≡ b ] ρ
step-b ρ = sym (lem1 b ρ)
step-ab : forall ρ -> eq[ normalise a ↓ ≡ normalise b ↓ ] ρ
step-ab ρ = lem2 (normalise a) (normalise b) ρ (isValid tt)
|
{
"alphanum_fraction": 0.4527239609,
"avg_line_length": 31.1288659794,
"ext": "agda",
"hexsha": "7625729d648096f78cfa71988de638acf2efdd88",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "benchmark/ac/AC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "benchmark/ac/AC.agda",
"max_line_length": 114,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "benchmark/ac/AC.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 2399,
"size": 6039
}
|
{-# OPTIONS --type-in-type #-}
module _ where
Set' : ∀ i → Set _
Set' i = Set i
postulate
A : Set
a : A
T : Set → Set
comp : (P : A → Set) (g : (a : A) → P a) → P a
foo : ∀ i (Q : A → Set' i) → T (comp _ Q)
-- (no issue if Set' is replaced by Set)
bar : T {!_!} -- Try to give _
bar = foo _ _
-- WAS:
-- A !=< Agda.Primitive.Level of type Set
-- when checking that the expression _ has type Set
-- SHOULD: succeed (with unsolved meta)
|
{
"alphanum_fraction": 0.5530973451,
"avg_line_length": 19.652173913,
"ext": "agda",
"hexsha": "f221d2bc0b5916c77a21c625f887d91cc34359b6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue3073.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue3073.agda",
"max_line_length": 51,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue3073.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 160,
"size": 452
}
|
-- New NO_POSITIVITY_CHECK pragma for data definitions and mutual
-- blocks
-- Skipping a single data definition in an abstract block.
abstract
{-# NO_POSITIVITY_CHECK #-}
data D : Set where
lam : (D → D) → D
|
{
"alphanum_fraction": 0.7018348624,
"avg_line_length": 24.2222222222,
"ext": "agda",
"hexsha": "f9ac6fc7755eb5d3e9054c0127171e0d12328e15",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1614f.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1614f.agda",
"max_line_length": 65,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1614f.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 57,
"size": 218
}
|
-- Andreas, 2017-03-23, issue #2510
-- Error message in case of --no-pattern-matching
{-# OPTIONS --no-pattern-matching #-}
test : Set
test x = x
-- Expected error:
-- Cannot eliminate type Set with pattern x (did you supply too many arguments?)
|
{
"alphanum_fraction": 0.6947791165,
"avg_line_length": 22.6363636364,
"ext": "agda",
"hexsha": "4e3a1f8dd62ca165ffe24ae4b3f05f1e1daf8cf8",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2510.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2510.agda",
"max_line_length": 80,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2510.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 65,
"size": 249
}
|
record ⊤ : Set where
abstract
a : ⊤
a = {!!}
|
{
"alphanum_fraction": 0.48,
"avg_line_length": 8.3333333333,
"ext": "agda",
"hexsha": "30e23ef44b2be7036aa8b2d756b36dcb6d3807c2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue2162.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue2162.agda",
"max_line_length": 20,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue2162.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 20,
"size": 50
}
|
------------------------------------------------------------------------------
-- From ListP as the least fixed-point to ListP using data
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- We want to represent the polymorphic total lists data type
--
-- data ListP (A : D → Set) : D → Set where
-- lnil : ListP A []
-- lcons : ∀ {x xs} → A x → ListP A xs → ListP A (x ∷ xs)
--
-- using the representation of ListP as the least fixed-point.
module LFPs.ListP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Nat.Type
open import FOTC.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
-- ListP is a least fixed-point of a functor
-- The functor.
-- ListPF : (D → Set) → (D → Set) → D → Set
-- ListPF A B xs = xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] A x' ∧ xs ≡ x' ∷ xs' ∧ B xs')
-- ListP is the least fixed-point of ListPF.
postulate
ListP : (D → Set) → D → Set
-- ListP is a pre-fixed point of ListPF.
--
-- Peter: It corresponds to the introduction rules.
ListP-in :
(A : D → Set) →
∀ {xs} → xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] A x' ∧ xs ≡ x' ∷ xs' ∧ ListP A xs') →
ListP A xs
-- ListP is the least pre-fixed point of ListPF.
--
-- Peter: It corresponds to the elimination rule of an inductively
-- defined predicate.
ListP-ind :
(A B : D → Set) →
(∀ {xs} → xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] A x' ∧ xs ≡ x' ∷ xs' ∧ B xs') → B xs) →
∀ {xs} → ListP A xs → B xs
------------------------------------------------------------------------------
-- The data constructors of ListP.
lnil : (A : D → Set) → ListP A []
lnil A = ListP-in A (inj₁ refl)
lcons : (A : D → Set) → ∀ {x xs} → A x → ListP A xs → ListP A (x ∷ xs)
lcons A {n} {ns} An LPns = ListP-in A (inj₂ (n , ns , An , refl , LPns))
------------------------------------------------------------------------------
-- The induction principle for ListP.
ListP-ind' : (A B : D → Set) →
B [] →
(∀ x {xs} → A x → B xs → B (x ∷ xs)) →
∀ {xs} → ListP A xs → B xs
ListP-ind' A B B[] is = ListP-ind A B prf
where
prf : ∀ {xs} →
xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] A x' ∧ xs ≡ x' ∷ xs' ∧ B xs') →
B xs
prf (inj₁ xs≡[]) = subst B (sym xs≡[]) B[]
prf (inj₂ (x' , xs' , Ax' , h₁ , Bxs')) = subst B (sym h₁) (is x' Ax' Bxs')
------------------------------------------------------------------------------
-- Examples
-- "Heterogeneous" total lists
xs : D
xs = 0' ∷ true ∷ 1' ∷ false ∷ []
List : D → Set
List = ListP (λ d → d ≡ d)
xs-ListP : List xs
xs-ListP =
lcons A refl (lcons A refl (lcons A refl (lcons A refl (lnil A))))
where
A : D → Set
A d = d ≡ d
-- Total lists of total natural numbers
ys : D
ys = 0' ∷ 1' ∷ 2' ∷ []
ListN : D → Set
ListN = ListP N
ys-ListP : ListN ys
ys-ListP =
lcons N nzero (lcons N (nsucc nzero) (lcons N (nsucc (nsucc nzero)) (lnil N)))
|
{
"alphanum_fraction": 0.449117175,
"avg_line_length": 30.5392156863,
"ext": "agda",
"hexsha": "7d8d8f04d91a3ad233282e93288d8cee8b92d5a0",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/fixed-points/LFPs/ListP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/fixed-points/LFPs/ListP.agda",
"max_line_length": 81,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/fixed-points/LFPs/ListP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 1010,
"size": 3115
}
|
-- 2011-08-22 Andreas (reported and fixed by Dominique Devriese)
{-# OPTIONS --no-universe-polymorphism #-}
module Issue427 where
data ⊥ : Set where
postulate f : {I : ⊥} (B : _) → ⊥
data A : Set where a : {x y : ⊥} → A
test : A → Set
test (a {x = x} {y = y}) with f {_}
test (a {x = x} {y = y}) | _ = A
{- old error message:
⊥ should be a function type, but it isn't
when checking that {y} are valid arguments to a function of type ⊥
-}
-- new error message should be: Unresolved metas
|
{
"alphanum_fraction": 0.6222222222,
"avg_line_length": 27.5,
"ext": "agda",
"hexsha": "9f09a9836fd9c29fd22b860c964c93a747117d43",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue427.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/Issue427.agda",
"max_line_length": 68,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/Issue427.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 168,
"size": 495
}
|
module InstanceArgumentsSections where
postulate A : Set
module Basic where
record B : Set where
field bA : A
open B {{...}}
bA' : {{_ : B}} → A
bA' = bA
module Parameterised (a : A) where
record C : Set where
field cA : A
open C {{...}}
cA' : {{_ : C}} → A
cA' = cA
module RecordFromParameterised where
postulate a : A
open Parameterised a
open C {{...}}
cA'' : {{_ : C}} → A
cA'' = cA
module RecordFromParameterisedInParameterised (a : A) where
open Parameterised a
open C {{...}}
cA'' : {{_ : C}} → A
cA'' = cA
module RecordFromParameterised' (a : A) where
open Parameterised
open C {{...}}
cA'' : {{_ : C a}} → A
cA'' = cA {a}
module AppliedRecord (a : A) where
open Parameterised
D : Set
D = C a
module D = C
open D {{...}}
dA' : {{_ : D}} → A
dA' = cA {a}
|
{
"alphanum_fraction": 0.5513577332,
"avg_line_length": 14.3559322034,
"ext": "agda",
"hexsha": "f4b1d767200299f28e95351a8dd98cb5f6d9412c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/InstanceArgumentsSections.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/InstanceArgumentsSections.agda",
"max_line_length": 59,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/InstanceArgumentsSections.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 312,
"size": 847
}
|
open import Algebra.Bundles using (Group)
module GGT.Group.Facts
{a b ℓ}
(G : Group a ℓ)
where
open import Relation.Unary using (Pred)
open import Relation.Binary
open import GGT.Group.Structures
open import Algebra.Bundles using (Group)
open import Algebra.Properties.Group G
open Group G
open import Relation.Binary.Reasoning.Setoid setoid
⁻¹-anti-homo-- : ∀ (x y : Carrier) → (x - y)⁻¹ ≈ y - x
⁻¹-anti-homo-- x y = begin
(x - y)⁻¹ ≡⟨⟩
(x ∙ y ⁻¹)⁻¹ ≈⟨ ⁻¹-anti-homo-∙ _ _ ⟩
(y ⁻¹) ⁻¹ ∙ x ⁻¹ ≈⟨ ∙-congʳ (⁻¹-involutive _) ⟩
y ∙ x ⁻¹ ≡⟨⟩
y - x ∎
subgroup⁻¹-closed : {P : Pred Carrier b } →
IsSubGroup G P →
∀ x → P x → P (x ⁻¹)
subgroup⁻¹-closed iss x px =
-- e - x = x ⁻¹ → P e - x → P x ⁻¹
r (identityˡ (x ⁻¹)) (∙-⁻¹-closed ε∈ px)
where open IsSubGroup iss
-- -----
-- (Right) Coset Relation is Equivalenc
cosetRelRefl : {P : Pred Carrier b } →
(iss : IsSubGroup G P) → Reflexive (IsSubGroup._∼_ iss)
cosetRelRefl iss {x} = r (sym (inverseʳ x)) ε∈ where open IsSubGroup iss
-- (e = x - x) → P e → P x - x
cosetRelSym : {P : Pred Carrier b } →
(iss : IsSubGroup G P) → Symmetric (IsSubGroup._∼_ iss)
cosetRelSym iss {x} {y} x∼y = r u≈y-x Pu where
-- P e → P (x - y) → P (y - x)
open IsSubGroup iss
u≈y-x = begin
ε - (x - y) ≡⟨⟩
ε ∙ (x - y)⁻¹ ≈⟨ identityˡ ((x - y)⁻¹) ⟩
(x - y)⁻¹ ≈⟨ ⁻¹-anti-homo-- _ _ ⟩
y - x ∎
Pu = ∙-⁻¹-closed ε∈ x∼y
cosetRelTrans : {P : Pred Carrier b } →
(iss : IsSubGroup G P) → Transitive (IsSubGroup._∼_ iss)
cosetRelTrans iss {x} {y} {z} x∼y y∼z =
r x-y-[z-y]≈x-z Pu where
open IsSubGroup iss
-- P z - y
z∼y = cosetRelSym iss y∼z
x-y-[z-y]≈x-z = begin
(x - y) - (z - y) ≡⟨⟩
(x - y) ∙ (z - y) ⁻¹ ≈⟨ ∙-congˡ (⁻¹-anti-homo-- z y) ⟩
(x - y) ∙ (y - z) ≡⟨⟩
(x ∙ y ⁻¹) ∙ (y ∙ z ⁻¹) ≈⟨ assoc x (y ⁻¹) (y ∙ z ⁻¹) ⟩
x ∙ (y ⁻¹ ∙ (y ∙ z ⁻¹)) ≈˘⟨ ∙-congˡ (assoc (y ⁻¹) y (z ⁻¹)) ⟩
x ∙ ((y ⁻¹ ∙ y) ∙ z ⁻¹) ≈⟨ ∙-congˡ (∙-congʳ (inverseˡ _)) ⟩
x ∙ (ε ∙ z ⁻¹) ≈⟨ ∙-congˡ (identityˡ _) ⟩
x ∙ z ⁻¹ ≡⟨⟩
x - z ∎
Pu = ∙-⁻¹-closed {x - y} {z - y} x∼y z∼y
|
{
"alphanum_fraction": 0.4443991853,
"avg_line_length": 35.5797101449,
"ext": "agda",
"hexsha": "081b380f3bfceca946ef2c1d473bacfe0a4905a3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zampino/ggt",
"max_forks_repo_path": "src/ggt/group/Facts.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "zampino/ggt",
"max_issues_repo_path": "src/ggt/group/Facts.agda",
"max_line_length": 84,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zampino/ggt",
"max_stars_repo_path": "src/ggt/group/Facts.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-28T05:48:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-17T11:10:00.000Z",
"num_tokens": 1062,
"size": 2455
}
|
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.List.Extrema using (max)
open import Data.Maybe using (to-witness)
open import Data.Fin using (fromℕ; _-_; zero; Fin)
open import Data.Fin.Properties using (≤-totalOrder)
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)
open import Function using (_∘_)
open import Data.List.Extrema ℕₚ.≤-totalOrder
-- TODO add to std-lib
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
-- operations
-- AddTodo
-- DeleteTodo
-- CompleteTodo
-- ClearCompleted
-- CompleteAllTodos
-- horizontal properties
-- AddTodo
-- non-commutative
-- DeleteTodo
-- idempotent
-- CompleteTodo
-- idempotent
-- ClearCompleted
-- idempotent
-- CompleteAllTodos
-- idempotent
-- EditTodo
-- EditTodo - EditTodo Todo list length doesn't change
-- vertical properties
-- AddTodo
-- AddTodoSetsNewCompletedToFalse
-- AddTodoSetsNewIdToNonExistingId
-- AddTodoSetsNewTextToText
-- doesn't change id of other Todos
-- doesn't change text of other Todos
-- doesn't change completed of other Todos
-- DeleteTodo
-- DeleteTodoRemoveTodoWithId
-- DeleteTodoRemoves1Element
-- only way to add todo is with AddTodo and AddTodo gives non existing id to new todo
-- doesn't change id of other Todos
-- doesn't change text of other Todos
-- doesn't change completed of other Todos
-- CompleteTodo
-- CompleteTodoSetsTodoWithIdCompletedToTrue
-- doesn't touch any other Todo
-- doesn't change id of any Todo
-- doesn't change text of any Todo
-- ClearCompleted
-- doesn't remove Todos where completed = false
-- doesn't change id of any Todo
-- doesn't change completed of any Todo
-- doesn't change text of any Todo
-- CompleteAllTodos
-- all Todos have completed = true
-- doesn't change id of any Todo
-- doesn't change text of any Todo
-- EditTodo
-- modifies Todo with given id's text
-- doesn't change the id
-- doesn't change completed
-- doesn't modify other Todos
record Todo : Set where
field
text : String
completed : Bool
id : ℕ
AddTodo : ∀ {n : ℕ} → (Vec Todo n) → String → (Vec Todo (1 + n))
AddTodo todos text =
todos ∷ʳ
record
{ id = 1 -- argmax (λ todo → λ e → e) todos) + 1
; completed = false
; text = text
}
ListAddTodo : List Todo → String → List Todo
ListAddTodo todos text =
todos l.∷ʳ
record
{ id = (max 0 (l.map (λ e → Todo.id e) todos)) + 1
; completed = false
; text = text
}
ListAddTodoAddsNewListItem :
(todos : List Todo) (text : String) →
l.length (ListAddTodo todos text) ≡ l.length todos + 1
ListAddTodoAddsNewListItem todos text = length-++ todos
listVec : Vec ℕ 1
listVec = v.fromList (2 l.∷ l.[])
listLast : ℕ
listLast = v.last (v.fromList (2 l.∷ l.[]))
listLastIs2 : v.last (v.fromList (2 l.∷ l.[])) ≡ 2
listLastIs2 = refl
record Id : Set where
field
id : ℕ
natListToVec : (xs : List ℕ) → Vec ℕ (l.length xs)
natListToVec nats = v.fromList nats
-- natListLast : List ℕ → ℕ
-- natListLast nats = v.last {(l.length nats) ∸ 1} (v.fromList nats)
-- natListLast : List ℕ → ℕ
-- natListLast [] = 0
-- natListLast nats@(x ∷ xs) = v.last (v.fromList nats)
natListFromList : v.fromList (1 l.∷ l.[]) ≡ (1 v.∷ v.[])
natListFromList = refl
ListOf1sConcatFromList : v.fromList (1 l.∷ l.[] l.++ 1 l.∷ l.[]) ≡ (1 v.∷ v.[] v.++ 1 v.∷ v.[])
ListOf1sConcatFromList = refl
open import Data.Nat.Properties
{-# BUILTIN SIZE Size #-}
private
variable
a : Level
A : Set a
i : Size
vec-length-++ :
∀ {n : ℕ} (xs : Vec A n) {ys} →
v.length (xs v.++ ys) ≡ v.length xs + v.length ys
vec-length-++ xs {ys} = refl
-- vec-fromList-++ :
-- (as bs : List A) →
-- v.fromList (as l.++ bs) ≡ v.fromList as v.++ v.fromList bs
-- vec-fromList-++ [] bs = v.[]
-- vec-fromList-++ (a ∷ as) bs = ?
-- natListConcatFromList : (nats1 : List ℕ) → (nats2 : List ℕ) → v.fromList (nats1 l.++ nats2) ≡ (nats1 v.++ nats2)
-- natListConcatFromList nats = ?
-- natListConcatFromList : (nats : List ℕ) → v.fromList (nats l.++ (1 l.∷ l.[])) ≡ ((v.fromList nats) v.++ (1 v.∷ v.[]))
-- natListConcatFromList = {! !}
natListLast : List ℕ → ℕ
natListLast [] = 0
natListLast (x ∷ []) = x
natListLast (_ ∷ y ∷ l) = natListLast (y l.∷ l)
natListConcatLast : ∀ l → natListLast (l l.++ l.[ 1 ]) ≡ 1
natListConcatLast [] = refl
natListConcatLast (_ ∷ []) = refl
natListConcatLast (_ ∷ _ ∷ l) = natListConcatLast (_ l.∷ l)
TodoListConcatLast [] = refl
TodoListConcatLast (_ ∷ []) = refl
TodoListConcatLast (_ ∷ _ ∷ l) = TodoListConcatLast (_ l.∷ l)
TodoListConcatLast : ∀ l → (TodoListLast (l l.++ l.[
record
{ id = 1
; completed = false
; text = "text"
}
])) ≡
record
{ id = 1
; completed = false
; text = "text"
}
TodoListConcatLastCompleted :
∀ l →
Todo.completed (TodoListLast (l l.++ l.[
record
{ id = 1
; completed = false
; text = "text"
}
])) ≡ false
TodoListConcatLastCompleted [] = refl
TodoListConcatLastCompleted (_ ∷ []) = refl
TodoListConcatLastCompleted (_ ∷ _ ∷ l) = TodoListConcatLastCompleted (_ l.∷ l)
-- _ : v.last (v.fromList (2 l.∷ l.[] l.++ 1 l.∷ l.[])) ≡ 1
-- _ = refl
-- natListConcatLast : (nats : List ℕ) → natListLast (nats l.++ 1 l.∷ l.[]) ≡ 1
-- natListConcatLast [] = refl
-- natListConcatLast nats@(x ∷ xs) =
-- begin
-- natListLast (nats l.++ 1 l.∷ l.[])
-- ≡⟨⟩
-- v.last (v.fromList ((x l.∷ xs) l.++ 1 l.∷ l.[]))
-- ≡⟨⟩
-- ?
-- ≡⟨⟩
-- 1
-- ∎
-- TodoListLast : List Todo → Todo
-- TodoListLast [] = record {}
-- TodoListLast todos@(x ∷ xs) = v.last (v.fromList todos)
-- ListWith2ToVec : v.fromList (2 l.∷ l.[]) ≡ 2 v.∷ v.[]
-- ListWith2ToVec = refl
-- idListLastIdIs2 : Id.id (v.last (v.fromList (record {id = 2} l.∷ l.[]))) ≡ 2
-- idListLastIdIs2 = refl
-- todoListLastIdIs2 : Todo.id (v.last (v.fromList (record {id = 2; text = ""; completed = false} l.∷ l.[]))) ≡ 2
-- todoListLastIdIs2 = refl
-- ListTodoLastTextIsText :
-- (todos : List Todo) (text : String) →
-- Todo.text (v.last (v.fromList (
-- record
-- { text = text
-- ; completed = false
-- ; id = max 0 (l.map Todo.id todos) + 1
-- } l.∷ l.[]
-- ))) ≡ text
-- ListTodoLastTextIsText todos text = refl
-- -- ListAddTodoLastAddedElementIsTodo :
-- -- (todos : List Todo) (text : String) →
-- -- Todo.text (TodoListLast (ListAddTodo todos text)) ≡ text
-- -- ListAddTodoLastAddedElementIsTodo [] text = refl
-- -- ListAddTodoLastAddedElementIsTodo todos@(x ∷ xs) text =
-- -- begin
-- -- Todo.text (TodoListLast (ListAddTodo todos text))
-- -- ≡⟨⟩
-- -- Todo.text (
-- -- TodoListLast (
-- -- todos
-- -- l.++
-- -- (
-- -- record
-- -- { text = text
-- -- ; completed = false
-- -- ; id = max 0 (l.map Todo.id todos) + 1
-- -- }
-- -- l.∷
-- -- l.[]
-- -- )
-- -- )
-- -- )
-- -- ≡⟨⟩
-- -- Todo.text (
-- -- record
-- -- { text = text
-- -- ; completed = false
-- -- ; id = max 0 (l.map Todo.id todos) + 1
-- -- }
-- -- )
-- -- ≡⟨ ? ⟩
-- -- text
-- -- ∎
-- -- open import Data.Nat.Base
-- -- infixr 5 _vb∷ʳ_
-- -- _vb∷ʳ_ : ∀ {n} → Vec≤ A n → A → Vec≤ A (suc n)
-- -- (as , p) vb∷ʳ a = as , s≤s p v.∷ʳ a
-- -- Vec≤AddTodo : ∀ {n : ℕ} → (Vec≤ Todo n) → String → (Vec≤ Todo (1 + n))
-- -- Vec≤AddTodo todos text =
-- -- todos vb∷ʳ
-- -- record
-- -- { id = 1 -- argmax (λ todo → λ e → e) todos) + 1
-- -- ; completed = false
-- -- ; text = text
-- -- }
-- vecLength-++ :
-- ∀ {n m} (xs : Vec A n) {ys : Vec A m} →
-- v.length (xs ++ ys) ≡ v.length xs + v.length ys
-- vecLength-++ [] = refl
-- vecLength-++ (x ∷ xs) = cong suc (vecLength-++ xs)
-- AddTodoAddsNewListItem :
-- ∀ {n : ℕ} → (todos : Vec Todo n) (text : String) →
-- v.length (AddTodo todos text) ≡ v.length todos + 1
-- AddTodoAddsNewListItem [] text = refl
-- AddTodoAddsNewListItem (x v.∷ xs) text =
-- begin
-- v.length (AddTodo (x v.∷ xs) text)
-- ≡⟨⟩
-- 1 + v.length (x v.∷ xs)
-- ≡⟨ +-comm 1 (v.length (x v.∷ xs))⟩
-- v.length (x v.∷ xs) + 1
-- ∎
-- ListTodoAddTodoAddsNewListItem :
-- (todos : List Todo) (text : String) →
-- l.length (ListAddTodo todos text) ≡ l.length todos + 1
-- ListTodoAddTodoAddsNewListItem [] text = refl
-- ListTodoAddTodoAddsNewListItem todos text =
-- +-comm 1 (l.length todos)
-- AddTodoLastAddedElementIsTodo :
-- ∀ {n} (todos : Vec Todo n) (text : String) →
-- last (AddTodo todos text) ≡
-- record
-- { id = 1
-- ; completed = false
-- ; text = text
-- }
-- AddTodoLastAddedElementIsTodo todos text = vecLast todos
-- -- should set (new element).completed to false
-- AddTodoSetsNewCompletedToFalse :
-- ∀ {n} (todos : Vec Todo n) (text : String) →
-- Todo.completed (last (AddTodo todos text)) ≡ false
-- AddTodoSetsNewCompletedToFalse todos text
-- rewrite
-- (AddTodoLastAddedElementIsTodo todos text) =
-- refl
-- -- should set (new element).id to an id not existing already in the list
-- AddTodoSetsNewIdTo1 :
-- ∀ {n} (todos : Vec Todo n) (text : String) →
-- Todo.id (last (AddTodo todos text)) ≡ 1
-- AddTodoSetsNewIdTo1 todos text
-- rewrite
-- (AddTodoLastAddedElementIsTodo todos text) =
-- refl
-- -- TODO should not touch other elements in the list
-- {-# COMPILE JS AddTodo =
-- function (todos) {
-- return function (text) {
-- return [
-- ...todos,
-- {
-- id: todos.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,
-- completed: false,
-- text: text
-- }
-- ]
-- }
-- }
-- #-}
-- -- DeleteTodo : (List Todo) → ℕ → (List Todo)
-- -- DeleteTodo todos id' = filter (λ todo → Todo.id todo ≟ id') todos
-- open import Relation.Nullary
-- dec-¬ : ∀ {a} {P : Set a} → Dec P → Dec (¬ P)
-- dec-¬ (yes p) = no λ prf → prf p
-- dec-¬ (no ¬p) = yes ¬p
-- VecFilter : Vec≤.vec (v.filter (λ e → e ≟ 2) (2 v.∷ 1 v.∷ v.[])) ≡ (2 v.∷ v.[])
-- VecFilter = refl
-- -- VecFilter' : Vec≤.vec (v.filter (λ e → dec-¬ (e ≟ 2)) (2 v.∷ 1 v.∷ v.[])) ≡ (1 v.∷ v.[])
-- -- VecFilter' = refl
-- -- VecFilter'' : {n : ℕ} → Vec≤.vec (v.filter (λ e → e ≟ 2) (n v.∷ v.[])) ≡ 2 v.∷ v.[]
-- -- VecFilter'' = ?
-- -- VecFilter''' : {n : ℕ} → v.filter (λ e → e ≟ n) (n v.∷ v.[]) ≡ n vb.∷ vb.[]
-- -- VecFilter''' = {! !}
-- -- ListFilter : l.filter (λ e → e ≟ 2) (2 l.∷ l.[]) ≡ 2 l.∷ l.[]
-- -- ListFilter = refl
-- -- ListFilter' : {n : ℕ} → l.filter (λ e → e ≟ n) (n l.∷ l.[]) ≡ n l.∷ l.[]
-- -- ListFilter' = {! !}
-- -- DeleteNat : ∀ {n m} → (Vec ℕ n) → ℕ → (Vec ℕ m)
-- -- DeleteNat nats nat = Vec≤.vec (v.filter (λ e → e ≟ nat) nats)
-- DeleteNat : List ℕ → ℕ → List ℕ
-- DeleteNat nats nat = l.filter (λ e → dec-¬ (e ≟ nat)) nats
-- DeleteNat-idem :
-- (nats : List ℕ) →
-- (nat : ℕ) →
-- DeleteNat (DeleteNat nats nat) nat ≡ DeleteNat nats nat
-- DeleteNat-idem nats nat = filter-idem (λ e → dec-¬ (e ≟ nat)) nats
-- -- begin
-- -- DeleteNat (DeleteNat nats nat) nat
-- -- ≡⟨⟩
-- -- DeleteNat (l.filter (λ e → dec-¬ (e ≟ nat)) nats) nat
-- -- ≡⟨⟩
-- -- l.filter (λ e → dec-¬ (e ≟ nat)) (l.filter (λ e → dec-¬ (e ≟ nat)) nats)
-- -- ≡⟨⟩
-- -- (l.filter (λ e → dec-¬ (e ≟ nat)) ∘ l.filter (λ e → dec-¬ (e ≟ nat))) nats
-- -- ≡⟨ filter-idem (λ e → dec-¬ (e ≟ nat)) nats ⟩
-- -- l.filter (λ e → dec-¬ (e ≟ nat)) nats
-- -- ≡⟨⟩
-- -- DeleteNat nats nat
-- -- ∎
-- private
-- variable
-- p : Level
-- -- VecTodoDeleteTodo :
-- -- ∀ {n} →
-- -- (Vec Todo n)
-- -- → ℕ →
-- -- (Vec Todo n)
-- -- VecTodoDeleteTodo todos id' =
-- -- Vec≤.vec (v.filter (λ todo → dec-¬ (Todo.id todo ≟ id')) todos)
-- ListTodoDeleteTodo :
-- ∀ {n} →
-- (List Todo)
-- → ℕ →
-- (List Todo)
-- ListTodoDeleteTodo todos id' =
-- l.filter (λ todo → dec-¬ (Todo.id todo ≟ id')) todos
-- ListTodoDeleteTodo-idem :
-- (todos : List Todo) →
-- (id' : ℕ) →
-- ListTodoDeleteTodo (ListTodoDeleteTodo todos id') id' ≡ ListTodoDeleteTodo todos id'
-- ListTodoDeleteTodo-idem todos id' =
-- filter-idem (λ e → dec-¬ (Todo.id e ≟ id')) todos
-- -- Vec≤DeleteTodo : ∀ {n} → (Vec≤ Todo n) → ℕ → (Vec≤ Todo n)
-- -- Vec≤DeleteTodo todos id' = vb.filter (λ todo → Todo.id todo ≟ id') todos
DeleteNat : (List ℕ) → ℕ → (List ℕ)
DeleteNat nats id = filter' (λ n → not (n ≡ᵇ id)) nats
-- https://stackoverflow.com/questions/65622605/agda-std-lib-list-check-that-a-filtered-list-is-empty/65622709#65622709
DeleteNatRemoveNatWithId :
(nats : List ℕ) (id : ℕ) →
filter' (λ n → n ≡ᵇ id) (DeleteNat nats id) ≡ l.[]
DeleteNatRemoveNatWithId [] id = refl
DeleteNatRemoveNatWithId (x ∷ xs) id with (x ≡ᵇ id) | inspect (_≡ᵇ id) x
... | true | P.[ eq ] = DeleteNatRemoveNatWithId xs id
... | false | P.[ eq ] rewrite eq = DeleteNatRemoveNatWithId xs id
-- DONT WORK
-- DeleteNatRemoveNatWithId (x ∷ xs) id with x ≡ᵇ id | inspect (l._∷ (filter' (λ n → not (n ≡ᵇ id)) xs)) x
-- ... | true | P.[ eq ] = DeleteNatRemoveNatWithId xs id
-- ... | false | P.[ eq ] rewrite eq = {! !}
-- cong (x List.∷_) (DeleteNatRemoveNatWithId xs id)
-- x List.∷ filter' (λ n → n ≡ᵇ id) (DeleteNat xs id) ≡ x List.∷ List.[]
-- cong (List._∷_) (DeleteNatRemoveNatWithId xs id)
-- List._∷_ (filter' (λ n → n ≡ᵇ id) (DeleteNat xs id)) ≡ List._∷_ List.[]
-- cong₂ (List._∷_) refl (DeleteNatRemoveNatWithId xs id)
-- _x_1193 List.∷ filter' (λ n → n ≡ᵇ id) (DeleteNat xs id) ≡ _x_1193 List.∷ List.[]
-- cong₂ (x List.∷_) refl (DeleteNatRemoveNatWithId xs id)
-- cong (filter' (λ n → n ≡ᵇ id) (x List.∷_)) (DeleteNatRemoveNatWithId xs id)
-- cong (filter' (λ n → n ≡ᵇ id)) (DeleteNatRemoveNatWithId xs id)
-- filter' (λ n → n ≡ᵇ id) (filter' (λ n → n ≡ᵇ id) (DeleteNat xs id)) ≡ List.[]
-- DeleteTodo is well-defined
-- DeleteTodoRemoveTodoWithId :
-- (todos : List Todo) (id : ℕ) →
-- l.filter (λ todo → Todo.id todo ≟ id) (DeleteTodo todos id) ≡ l.[]
-- DeleteTodoRemoveTodoWithId [] id = refl
-- DeleteTodoRemoveTodoWithId (x ∷ xs) id with (Todo.id x ≟ id) | inspect (_≡ᵇ id) (Todo.id x)
-- ... | yes px | P.[ eq ] = DeleteTodoRemoveTodoWithId xs id
-- ... | no npx | P.[ eq ] rewrite eq = {! !}
-- -- filterProof : v.filter (λ e → e ≟ 2) (2 v.∷ v.[]) ≡ (2 vb.∷ vb.[])
-- -- filterProof = refl
-- -- filterProof' : v.filter (λ e → dec-¬ (e ≟ 2)) (2 v.∷ v.[]) ≡ vb.[]
-- -- filterProof' = refl
-- -- dropWhileProof : v.dropWhile (λ e → e ≟ 2) (2 v.∷ 3 v.∷ v.[]) ≡ 3 vb.∷ vb.[]
-- -- dropWhileProof = refl
-- -- dropWhileProof' : v.dropWhile (λ e → e ≟ 3) (2 v.∷ 3 v.∷ v.[]) ≡ (2 vb.∷ 3 vb.∷ vb.[])
-- -- dropWhileProof' = refl
-- -- todoFilterProof :
-- -- v.filter
-- -- (λ todo → dec-¬ ((Todo.id todo) ≟ 2))
-- -- (
-- -- record
-- -- { id = 2
-- -- ; completed = false
-- -- ; text = ""
-- -- }
-- -- v.∷
-- -- record
-- -- { id = 1
-- -- ; completed = false
-- -- ; text = ""
-- -- }
-- -- v.∷
-- -- v.[]
-- -- )
-- -- ≡
-- -- (
-- -- record
-- -- { id = 1
-- -- ; completed = false
-- -- ; text = ""
-- -- }
-- -- vb.∷
-- -- vb.[]
-- -- )
-- -- todoFilterProof = refl
-- -- should remove element from the list unless there are no elements
-- -- should remove element with given id
-- -- DeleteTodoRemoveTodoById :
-- -- ∀ {n : ℕ} (id' : ℕ) (todos : Vec Todo n) →
-- -- padRight
-- -- record
-- -- { id = 1 -- argmax (λ todo → λ e → e) todos) + 1
-- -- ; completed = false
-- -- ; text = ""
-- -- }
-- -- (v.filter (λ todo → dec-¬ ((Todo.id todo) ≟ id')) (DeleteTodo todos id'))
-- -- ≡ DeleteTodo todos id'
-- -- DeleteTodoRemoveTodoById id' v.[] = refl
-- -- DeleteTodoRemoveTodoById id' (x v.∷ xs) = {! !} (DeleteTodoRemoveTodoById xs)
-- -- {-# COMPILE JS DeleteTodo =
-- -- function (todos) {
-- -- return function (id) {
-- -- return todos.filter(function (todo) {
-- -- return todo.id !== id
-- -- });
-- -- }
-- -- }
-- -- #-}
-- -- EditTodo: can't use updateAt since id doesn't necessarily correspond to Vec index
-- VecTodoEditTodo : ∀ {n} → (Vec Todo n) → ℕ → String → (Vec Todo n)
-- VecTodoEditTodo todos id text =
-- v.map (λ todo →
-- if (⌊ Todo.id todo ≟ id ⌋)
-- then record todo { text = text }
-- else todo)
-- todos
-- ListTodoEditTodo : (List Todo) → ℕ → String → (List Todo)
-- ListTodoEditTodo todos id text =
-- l.map (λ todo →
-- if (⌊ Todo.id todo ≟ id ⌋)
-- then record todo { text = text }
-- else todo)
-- todos
-- ListTodoEditTodo-idem :
-- (todos : List Todo) →
-- (id' : ℕ) →
-- (text : String) →
-- ListTodoEditTodo (ListTodoEditTodo todos id' text) id' text ≡ ListTodoEditTodo todos id' text
-- ListTodoEditTodo-idem todos id' text =
-- begin
-- ListTodoEditTodo (ListTodoEditTodo todos id' text) id' text
-- ≡⟨ {! !} ⟩
-- ListTodoEditTodo todos id' text
-- ∎
-- -- {-# COMPILE JS EditTodo =
-- -- function (todos) {
-- -- return function (id) {
-- -- return function (text) {
-- -- return todos.map(function (todo) {
-- -- if (todo.id === id) {
-- -- todo.text = text;
-- -- }
-- -- return todo;
-- -- });
-- -- }
-- -- }
-- -- }
-- -- #-}
-- VecTodoCompleteTodo : ∀ {n} → (Vec Todo n) → ℕ → (Vec Todo n)
-- VecTodoCompleteTodo todos id =
-- v.map (λ todo →
-- if (⌊ Todo.id todo ≟ id ⌋)
-- then record todo { completed = true }
-- else todo)
-- todos
-- ListTodoCompleteTodo : (List Todo) → ℕ → (List Todo)
-- ListTodoCompleteTodo todos id =
-- l.map (λ todo →
-- if (⌊ Todo.id todo ≟ id ⌋)
-- then record todo { completed = true }
-- else todo)
-- todos
-- ListTodoCompleteTodo-idem :
-- (todos : List Todo) →
-- (id' : ℕ) →
-- ListTodoCompleteTodo (ListTodoCompleteTodo todos id') id' ≡ ListTodoCompleteTodo todos id'
-- ListTodoCompleteTodo-idem todos id' =
-- begin
-- ListTodoCompleteTodo (ListTodoCompleteTodo todos id') id'
-- ≡⟨ {! !} ⟩
-- ListTodoCompleteTodo todos id'
-- ∎
-- -- {-# COMPILE JS CompleteTodo =
-- -- function (todos) {
-- -- return function (id) {
-- -- return todos.map(function (todo) {
-- -- if (todo.id === id) {
-- -- todo.completed = true;
-- -- }
-- -- return todo;
-- -- });
-- -- }
-- -- }
-- -- #-}
-- CompleteAllTodos : ∀ {n} → (Vec Todo n) → (Vec Todo n)
-- CompleteAllTodos todos =
-- v.map (λ todo →
-- record todo { completed = true })
-- todos
-- ListTodoCompleteAllTodos : (List Todo) → (List Todo)
-- ListTodoCompleteAllTodos todos =
-- l.map (λ todo →
-- record todo { completed = true })
-- todos
-- ListTodoCompleteAllTodos-idem :
-- (todos : List Todo) →
-- ListTodoCompleteAllTodos (ListTodoCompleteAllTodos todos) ≡ ListTodoCompleteAllTodos todos
-- ListTodoCompleteAllTodos-idem todos = {! !}
-- -- {-# COMPILE JS CompleteAllTodos =
-- -- function (todos) {
-- -- return todos.map(function(todo) {
-- -- todo.completed = true;
-- -- return todo;
-- -- });
-- -- }
-- -- #-}
-- VecTodoClearCompleted : ∀ {n} → (Vec Todo n) → (Vec Todo n)
-- VecTodoClearCompleted todos =
-- padRight
-- record
-- { id = 1 -- argmax (λ todo → λ e → e) todos) + 1
-- ; completed = false
-- ; text = ""
-- }
-- (v.filter (λ todo → dec-¬ ((Todo.completed todo) Bool.≟ true)) todos)
-- ListTodoClearCompleted : (List Todo) → (List Todo)
-- ListTodoClearCompleted todos =
-- (l.filter (λ todo → dec-¬ ((Todo.completed todo) Bool.≟ true)) todos)
-- ListTodoClearCompleted-idem :
-- (todos : List Todo) →
-- ListTodoClearCompleted (ListTodoClearCompleted todos) ≡ ListTodoClearCompleted todos
-- ListTodoClearCompleted-idem todos =
-- filter-idem (λ e → dec-¬ (Todo.completed e Bool.≟ true)) todos
-- -- should remove all elements where completed = true
-- -- should not change other elements
-- -- should not change (all elements).text
-- -- should not change (all elements).id
-- -- {-# COMPILE JS ClearCompleted =
-- -- function (todos) {
-- -- return todos.filter(function(todo) {
-- -- return !todo.completed;
-- -- });
-- -- }
-- -- #-}
-- -- add-todos-length-increased-by-1 : ∀ (todos : List Todo) → length (AddTodo todos "test")
-- -- add-todos-length-increased-by-1 = ?
-- -- delete-todos-length-decreased-by-1-except-if-length-0 : ()
-- -- edit-todos-length-not-changed : ()
-- -- complete-todos-length-not-changed : ()
-- -- complete-all-todos-length-not-changed : ()
-- -- clear-completed-todos-not-have-completed : ()
-- -- should not generate duplicate ids after CLEAR_COMPLETE
-- -- data Action : Set where
-- -- ADD_TODO DELETE_TODO EDIT_TODO COMPLETE_TODO COMPLETE_ALL_TODOS CLEAR_COMPLETED : Action
-- -- Reducer : Todos → Action → Todos
-- -- Reducer todos ADD_TODO = AddTodo todos id
-- -- Reducer todos DELETE_TODO = DeleteTodo todos id
-- -- Reducer todos EDIT_TODO = EditTodo todos id
-- -- Reducer todos COMPLETE_TODO = CompleteTodo todos id
-- -- Reducer todos COMPLETE_ALL_TODOS = CompleteAllTodos todos id
-- -- Reducer todos CLEAR_COMPLETED = ClearCompleted todos id
|
{
"alphanum_fraction": 0.5540616489,
"avg_line_length": 31.2581081081,
"ext": "agda",
"hexsha": "15d67d67db7164ee357a04d20c932cc4ea33ca52",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "506fba1e27d8c1527f06c285762391b00ed03ced",
"max_forks_repo_licenses": [
"CC0-1.0",
"MIT"
],
"max_forks_repo_name": "frankymacster/redux",
"max_forks_repo_path": "examples/todomvc/src/logic/todos-archive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "506fba1e27d8c1527f06c285762391b00ed03ced",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0",
"MIT"
],
"max_issues_repo_name": "frankymacster/redux",
"max_issues_repo_path": "examples/todomvc/src/logic/todos-archive.agda",
"max_line_length": 132,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "506fba1e27d8c1527f06c285762391b00ed03ced",
"max_stars_repo_licenses": [
"CC0-1.0",
"MIT"
],
"max_stars_repo_name": "frankymacster/redux",
"max_stars_repo_path": "examples/todomvc/src/logic/todos-archive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7889,
"size": 23131
}
|
module AmbiguousConstructor where
module Foo where
data D : Set where
c0 : D
c1 : D
module Bar where
open Foo public
data B : Set where
tt : B
ff : B
open Foo renaming (c0 to c2)
open Bar renaming (c1 to c2)
foo : D -> B
-- c2 is ambiguous: it could refer to c0 or c1.
foo c2 = tt
foo _ = ff
|
{
"alphanum_fraction": 0.6485623003,
"avg_line_length": 14.2272727273,
"ext": "agda",
"hexsha": "de0b10b612ef75f7d6fd7c29c2a3d8a58d2a50c9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Fail/AmbiguousConstructor.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/AmbiguousConstructor.agda",
"max_line_length": 47,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/AmbiguousConstructor.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 107,
"size": 313
}
|
module List where
import Bool
open Bool
infixr 15 _::_
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
module Eq {A : Set}(_=A=_ : A -> A -> Bool) where
infix 10 _==_
_==_ : List A -> List A -> Bool
[] == [] = true
x :: xs == y :: ys = (x =A= y) && xs == ys
[] == _ :: _ = false
_ :: _ == [] = false
module Subst {A : Set}(_=A=_ : A -> A -> Bool)
(substA : {x y : A} -> (P : A -> Set) -> IsTrue (x =A= y) -> P x -> P y)
where
module EqA = Eq _=A=_
open EqA
subst : {xs ys : List A} -> (P : List A -> Set) -> IsTrue (xs == ys) -> P xs -> P ys
subst {[] } {_ :: _ } _ () _
subst {_ :: _ } {[] } _ () _
subst {[] } {[] } P eq pxs = pxs
subst {x :: xs} {y :: ys} P eq pxs =
substA (\z -> P (z :: ys)) x==y (
subst (\zs -> P (x :: zs)) xs==ys pxs
)
where
x==y : IsTrue (x =A= y)
x==y = isTrue&&₁ {x =A= y}{xs == ys} eq
xs==ys : IsTrue (xs == ys)
xs==ys = isTrue&&₂ {x =A= y}{xs == ys} eq
|
{
"alphanum_fraction": 0.4070543375,
"avg_line_length": 23.3111111111,
"ext": "agda",
"hexsha": "d2d631172ecc7f7cbbef6ba8020d7ba52661ae48",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "examples/tactics/ac/List.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "examples/tactics/ac/List.agda",
"max_line_length": 86,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/tactics/ac/List.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 418,
"size": 1049
}
|
-- Andreas, 2014-09-09
{-# TERMINATING #-}
Foo : Set
Foo = Foo
|
{
"alphanum_fraction": 0.59375,
"avg_line_length": 10.6666666667,
"ext": "agda",
"hexsha": "ce6ed6bdaa9c8ac2dae1d50fc11f361553131f7f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue586b.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue586b.agda",
"max_line_length": 22,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue586b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 23,
"size": 64
}
|
-- Reported by Nisse on 2018-03-13
-- The `x` in the parent pattern was eta-expanded to `record{}`,
-- but with-abstraction didn't like this.
open import Agda.Builtin.Equality
record R : Set where
postulate
easy : (A : Set) → A
F : (x : R) → Set₁
F x with easy (x ≡ x)
F x | refl with Set
F x | refl | _ = Set
-- OLD ERROR:
-- With clause pattern x is not an instance of its parent pattern
-- record {}
-- Fixed by allowing parent patterns to be replaced by variables
-- in the with clause (but checking that their instantiation is
-- type-correct).
|
{
"alphanum_fraction": 0.6833631485,
"avg_line_length": 22.36,
"ext": "agda",
"hexsha": "1813f877030cd6c9392d57e9d8f48bacd0c24969",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2998.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2998.agda",
"max_line_length": 65,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2998.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 158,
"size": 559
}
|
-- {-# OPTIONS -vtc.with.strip:60 -v tc.lhs.top:50 #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
postulate trustMe : {A : Set} (x y : A) → x ≡ y
data Fin : Nat → Set where
fzero : ∀ n → Fin (suc n)
fsuc : ∀{n} → Fin n → Fin (suc n)
test1 : ∀{n} → Fin n → Nat
test1 (fzero _) = 0
test1 {.(suc n)} (fsuc {n} i) with Fin zero
... | q = {!.!}
-- Current & expected expansion:
-- test1 {.(suc n)} (fsuc {n} i) | q = {!!}
test2 : ∀{n} → Fin n → Nat
test2 (fzero _) = 0
test2 {.(suc n)} (fsuc {n} i) with trustMe n zero
... | refl = {!.!}
-- Current & expected expansion:
-- test2 {.1} (fsuc {.0} i) | refl = {!!}
-- The test cases below do not yet work correctly, but are included
-- here as documentation of the current behaviour of Agda. does not
-- work correctly yet.
test3 : ∀{n} → Fin n → Nat
test3 (fzero _) = 0
test3 {m} (fsuc {n} i) with Fin zero
... | q = {!.!}
-- Current expansion:
-- test3 {.(suc _)} (fsuc {_} i) | q = {!!}
-- Expected expansion:
-- test3 {.(suc n)} (fsuc {n} i) | q = { }
test4 : ∀{n} → Fin n → Nat
test4 (fzero _) = 0
test4 {_} (fsuc {n} i) with Fin zero
... | q = {!.!}
-- Current expansion:
-- test4 {.(suc _)} (fsuc {_} i) | q = {!!}
-- Expected expansion:
-- test4 {_} (fsuc {n} i) | q = {!!}
test5 : ∀{n : Nat} → Fin n → Nat → Nat
test5 (fzero _) _ = 0
test5 {.(suc n)} (fsuc {n} i) m with trustMe m n
... | refl = {!.!}
-- Current expansion:
-- test5 {.(suc n)} (fsuc {n} i) n | refl = {!!}
-- Expected expansion: one of the following:
-- test5 {.(suc n)} (fsuc {n} i) .n | refl = {!!}
-- test5 {.(suc m)} (fsuc {.m} i) m | refl = {!!}
test6 : Nat → ∀{n : Nat} → Fin n → Nat
test6 _ (fzero _) = 0
test6 m {.(suc n)} (fsuc {n} i) with trustMe m n
... | refl = {!.!}
-- Current expansion:
-- test6 m {.(suc m)} (fsuc {.m} i) | refl = {!!}
-- This one is actually good, we should be sure fixing the above
-- examples doesn't change the output here!
|
{
"alphanum_fraction": 0.5495824635,
"avg_line_length": 28.5970149254,
"ext": "agda",
"hexsha": "02b1b01f73d00d883b332e6dd22492a0f2ff44c0",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue4778.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue4778.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue4778.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 737,
"size": 1916
}
|
open import Prelude
open import core
module grounding where
grounding : ∀{ τ1 τ2} →
τ1 ▸gnd τ2 →
((τ2 ground) × (τ1 ~ τ2) × (τ1 ≠ τ2))
grounding (MGArr x) = GHole , TCArr TCHole1 TCHole1 , x
grounding (MGProd x) = GProd , TCProd TCHole1 TCHole1 , x
|
{
"alphanum_fraction": 0.5382165605,
"avg_line_length": 31.4,
"ext": "agda",
"hexsha": "ba23a2f32888277d8374d605342a35177af46ecd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "grounding.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "grounding.agda",
"max_line_length": 66,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "grounding.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 106,
"size": 314
}
|
------------------------------------------------------------------------
-- The unit type
------------------------------------------------------------------------
module Data.Unit where
open import Data.Sum
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl)
------------------------------------------------------------------------
-- Types
-- Note that the name of this type is "\top", not T.
record ⊤ : Set where
tt : ⊤
tt = record {}
record _≤_ (x y : ⊤) : Set where
------------------------------------------------------------------------
-- Operations
_≟_ : Decidable {⊤} _≡_
_ ≟ _ = yes refl
_≤?_ : Decidable _≤_
_ ≤? _ = yes _
total : Total _≤_
total _ _ = inj₁ _
------------------------------------------------------------------------
-- Properties
preorder : Preorder
preorder = PropEq.preorder ⊤
setoid : Setoid
setoid = PropEq.setoid ⊤
decTotalOrder : DecTotalOrder
decTotalOrder = record
{ carrier = ⊤
; _≈_ = _≡_
; _≤_ = _≤_
; isDecTotalOrder = record
{ isTotalOrder = record
{ isPartialOrder = record
{ isPreorder = record
{ isEquivalence = PropEq.isEquivalence
; reflexive = λ _ → _
; trans = λ _ _ → _
; ∼-resp-≈ = PropEq.resp₂ _≤_
}
; antisym = antisym
}
; total = total
}
; _≟_ = _≟_
; _≤?_ = _≤?_
}
}
where
antisym : Antisymmetric _≡_ _≤_
antisym _ _ = refl
decSetoid : DecSetoid
decSetoid = DecTotalOrder.Eq.decSetoid decTotalOrder
poset : Poset
poset = DecTotalOrder.poset decTotalOrder
|
{
"alphanum_fraction": 0.443877551,
"avg_line_length": 22.9090909091,
"ext": "agda",
"hexsha": "a1683638be767ed9c73d9fc90c7fc417e81492e9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Unit.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Unit.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Unit.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 449,
"size": 1764
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Empty type
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Empty where
open import Level
data ⊥ : Set where
⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever
⊥-elim ()
|
{
"alphanum_fraction": 0.3579545455,
"avg_line_length": 20.7058823529,
"ext": "agda",
"hexsha": "43f99b82c1fc17c31d8414dd70d812f76b0f8607",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Empty.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Empty.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 68,
"size": 352
}
|
{-# OPTIONS --universe-polymorphism #-}
open import Categories.Category
open import Categories.Object.Terminal
open import Level
module Categories.Object.Terminal.Products {o ℓ e : Level}
(C : Category o ℓ e)
(T : Terminal C) where
open import Categories.Object.Product
open Category C
open Terminal T
[⊤×⊤] : Obj
[⊤×⊤] = ⊤
[⊤×⊤]-product : Product C ⊤ ⊤
[⊤×⊤]-product = record
{ A×B = [⊤×⊤]
; π₁ = !
; π₂ = !
; ⟨_,_⟩ = λ _ _ → !
; commute₁ = !-unique₂ _ _
; commute₂ = !-unique₂ _ _
; universal = λ _ _ → !-unique _
}
[⊤×_] : Obj → Obj
[⊤× X ] = X
[⊤×_]-product : (X : Obj) → Product C ⊤ X
[⊤×_]-product X = record
{ A×B = [⊤× X ]
; π₁ = !
; π₂ = id
; ⟨_,_⟩ = λ _ f → f
; commute₁ = !-unique₂ _ _
; commute₂ = identityˡ
; universal = λ {A}{f}{g}{i} _ id∘i≡g →
begin
g
↑⟨ id∘i≡g ⟩
id ∘ i
↓⟨ identityˡ ⟩
i
∎
} where open HomReasoning
[_×⊤] : Obj → Obj
[ X ×⊤] = X
[_×⊤]-product : (X : Obj) → Product C X ⊤
[_×⊤]-product X = record
{ A×B = [ X ×⊤]
; π₁ = id
; π₂ = !
; ⟨_,_⟩ = λ f _ → f
; commute₁ = identityˡ
; commute₂ = !-unique₂ _ _
; universal = λ {A}{f}{g}{i} id∘i≡f _ →
begin
f
↑⟨ id∘i≡f ⟩
id ∘ i
↓⟨ identityˡ ⟩
i
∎
} where open HomReasoning
|
{
"alphanum_fraction": 0.4361054767,
"avg_line_length": 20.5416666667,
"ext": "agda",
"hexsha": "99415c054f73e4e380d789290bac66abe8f477a1",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Object/Terminal/Products.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Object/Terminal/Products.agda",
"max_line_length": 58,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Object/Terminal/Products.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 595,
"size": 1479
}
|
module everything where
open import lib public
|
{
"alphanum_fraction": 0.8333333333,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "42af961bdd4824ac695d4ef0219a8c7799ad5705",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "everything.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "everything.agda",
"max_line_length": 23,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "everything.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 9,
"size": 48
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetQuotients where
open import Cubical.HITs.SetQuotients.Base public
open import Cubical.HITs.SetQuotients.Properties public
|
{
"alphanum_fraction": 0.7929292929,
"avg_line_length": 33,
"ext": "agda",
"hexsha": "5e6bf8236baee8836719fb21533e75513a26fe5d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/SetQuotients.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/SetQuotients.agda",
"max_line_length": 55,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/SetQuotients.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 55,
"size": 198
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.