Search is not available for this dataset
text
string | meta
dict |
---|---|
infixr 2 _×_
infixr 2 _,_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
_×_ : Set → Set → Set
A × B = Σ A λ _ → B
syntax Σ A (λ x → B) = Σ[ x ∶ A ] B
data W (A : Set) (B : A → Set) : Set where
sup : (x : A) → ((p : B x) → W A B) → W A B
-- Should be able to get φ (λ x → (k x) , rec φ (k x)))
-- just using refine.
rec : ∀ {S P}{X : Set} → (Σ[ s ∶ S ] (P s → W S P × X) → X) → W S P → X
rec φ (sup s k) = {!!}
postulate
A : Set
a : A
-- Refine hole as far as possible.
-- Should get: (? , ?) , (λ x → ?) , λ x → ?
test-refine : (A × A) × (A → A) × (A → A)
test-refine = {!!}
| {
"alphanum_fraction": 0.4586583463,
"avg_line_length": 20.6774193548,
"ext": "agda",
"hexsha": "d6699a04d2c34fa2a06ef32bbb99a4901f5b7161",
"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/Issue737.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/Issue737.agda",
"max_line_length": 71,
"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/Issue737.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": 286,
"size": 641
} |
-- Raw terms, weakening (renaming) and substitution.
{-# OPTIONS --safe #-}
module Definition.Untyped where
open import Tools.Nat
open import Tools.Product
open import Tools.List
import Tools.PropositionalEquality as PE
import Data.Fin as Fin
import Data.Nat as Nat
infixl 30 _∙_^_
infix 30 Π_^_°_▹_°_°_
infixr 22 _^_°_▹▹_°_°_
infixl 30 _ₛ•ₛ_ _•ₛ_ _ₛ•_
infix 25 _[_]
infix 25 _[_]↑
data Relevance : Set where
! : Relevance -- proof-relevant
% : Relevance -- proof-irrelevant
!≢% : ! PE.≢ %
!≢% ()
-- two levels of small types
data Level : Set where
⁰ : Level
¹ : Level
⁰≢¹ : ⁰ PE.≢ ¹
⁰≢¹ ()
data _<_ : (i j : Level) → Set where
0<1 : ⁰ < ¹
data _≤_ (i j : Level) : Set where
<is≤ : i < j → i ≤ j
≡is≤ : i PE.≡ j → i ≤ j
-- Large type levels : ι ⁰, ι ¹, ∞
data TypeLevel : Set where
ι : Level → TypeLevel
∞ : TypeLevel
data _<∞_ : (i j : TypeLevel) → Set where
emb< : ι ⁰ <∞ ι ¹
∞< : ι ¹ <∞ ∞
-- ∞<⁰ : ι ⁰ <∞ ∞
data _≤∞_ (i j : TypeLevel) : Set where
<∞is≤∞ : i <∞ j → i ≤∞ j
≡is≤∞ : i PE.≡ j → i ≤∞ j
next : Level → TypeLevel
next ⁰ = ι ¹
next ¹ = ∞
toLevel : TypeLevel → Level
toLevel (ι ⁰) = ⁰
toLevel (ι ¹) = ¹
toLevel ∞ = ¹
predLevel : TypeLevel → Level
predLevel (ι ⁰) = ⁰
predLevel (ι ¹) = ⁰
predLevel ∞ = ¹
maxLevel : (i : Level) → (j : Level) → Σ Level λ k → i ≤ k × j ≤ k
maxLevel ⁰ ⁰ = ⁰ , ((≡is≤ PE.refl) , (≡is≤ PE.refl))
maxLevel ⁰ ¹ = ¹ , ((<is≤ 0<1) , (≡is≤ PE.refl))
maxLevel ¹ ⁰ = ¹ , ((≡is≤ PE.refl) , (<is≤ 0<1))
maxLevel ¹ ¹ = ¹ , ((≡is≤ PE.refl) , (≡is≤ PE.refl))
⁰min : (i : Level) → ⁰ ≤ i
⁰min ⁰ = ≡is≤ PE.refl
⁰min ¹ = <is≤ 0<1
<next : ∀ {l} → ι l <∞ next l
<next {⁰} = emb<
<next {¹} = ∞<
levelBounded : (i : Level) → Σ TypeLevel λ k → ι i <∞ k
levelBounded i = next i , <next
ιinj : ∀ {l l'} → ι l PE.≡ ι l' → l PE.≡ l'
ιinj {⁰} {⁰} e = PE.refl
ιinj {¹} {¹} e = PE.refl
next-inj : ∀ {l l'} → next l PE.≡ next l' → l PE.≡ l'
next-inj {⁰} {⁰} e = PE.refl
next-inj {¹} {¹} e = PE.refl
-- In a typing judgment, a type is generally annotated with a pair of a relevance and a level
record TypeInfo : Set where
constructor [_,_]
field
r : Relevance
l : TypeLevel
toTypeInfo : Relevance × Level → TypeInfo
toTypeInfo ( r , l ) = [ r , ι l ]
-- Typing contexts (snoc-lists, isomorphic to lists).
data Con (A : Set) : Set where
ε : Con A -- Empty context.
_∙_^_ : Con A → A → TypeInfo → Con A -- Context extension.
record GenT (A : Set) : Set where
inductive
constructor ⟦_,_⟧
field
l : Nat
t : A
data Kind : Set where
Ukind : Relevance → Level → Kind
Pikind : Relevance → Level → Level → Level → Kind
Natkind : Kind
Lamkind : Level → Kind
Appkind : Level → Kind
Zerokind : Kind
Suckind : Kind
Natreckind : Level → Kind
Emptykind : Level → Kind
Emptyreckind : Level → Level → Kind
Idkind : Kind
Idreflkind : Kind
Transpkind : Kind
Castkind : Level → Kind
Castreflkind : Kind
Sigmakind : Kind
Pairkind : Kind
Fstkind : Kind
Sndkind : Kind
data Term : Set where
var : (x : Nat) → Term
gen : (k : Kind) (c : List (GenT Term)) → Term
-- The Grammar of our language.
-- We represent the expressions of our language as de Bruijn terms.
-- Variables are natural numbers interpreted as de Bruijn indices.
-- Π, lam, ∃ , transp and natrec are binders.
-- Type constructors.
-- Universes of proof-relevant types
U : Level → Term
U l = gen (Ukind ! l) []
-- Universes of proof-irrelevant types
SProp : Level → Term
SProp l = gen (Ukind % l) []
pattern Univ r l = gen (Ukind r l) []
-- Dependent product, with level annotations for the domain, codomain, and resulting type
Π_^_°_▹_°_°_ : Term → Relevance → Level → Term → Level → Level → Term -- Dependent function type (B is a binder).
Π A ^ r ° lA ▹ B ° lB ° lΠ = gen (Pikind r lA lB lΠ) (⟦ 0 , A ⟧ ∷ ⟦ 1 , B ⟧ ∷ [])
-- Existential type : dependent pairs of proof-irrelevant terms
∃_▹_ : Term → Term → Term
∃ A ▹ B = gen Sigmakind (⟦ 0 , A ⟧ ∷ ⟦ 1 , B ⟧ ∷ [])
-- Natural numbers
ℕ : Term
ℕ = gen Natkind []
-- Lambda-calculus.
-- var : (x : Nat) → Term -- Variable (de Bruijn index).
-- var = var
lam_▹_^_ : Term → Term → Level → Term -- Function abstraction (binder).
lam A ▹ t ^ l = gen (Lamkind l) (⟦ 0 , A ⟧ ∷ ⟦ 1 , t ⟧ ∷ [])
_∘_^_ : (t u : Term) (l : Level) → Term -- Application.
t ∘ u ^ l = gen (Appkind l) (⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ [])
⦅_,_,_⦆ : Term → Term → Term → Term -- Dependent pair formation
⦅ G , t , u ⦆ = gen Pairkind (⟦ 1 , G ⟧ ∷ ⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ [])
fst : (t : Term) → Term -- Dependent pair elimination
fst t = gen Fstkind (⟦ 0 , t ⟧ ∷ [])
snd : (t : Term) → Term -- Dependent pair elimination
snd t = gen Sndkind (⟦ 0 , t ⟧ ∷ [])
-- Introduction and elimination of natural numbers.
zero : Term -- Natural number zero.
zero = gen Zerokind []
suc : (t : Term) → Term -- Successor.
suc t = gen Suckind (⟦ 0 , t ⟧ ∷ [])
natrec : (l : Level) (A t u v : Term) → Term -- Recursor (A is a binder).
natrec l A t u v = gen (Natreckind l) (⟦ 1 , A ⟧ ∷ ⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ ⟦ 0 , v ⟧ ∷ [])
-- Empty type
Empty : Level → Term
Empty l = gen (Emptykind l) []
-- Eliminator for the empty type
Emptyrec : (l lEmpty : Level) (A e : Term) -> Term
Emptyrec l lEmpty A e = gen (Emptyreckind l lEmpty) (⟦ 0 , A ⟧ ∷ ⟦ 0 , e ⟧ ∷ [])
-- Identity type
Id : (A t u : Term) → Term
Id A t u = gen Idkind (⟦ 0 , A ⟧ ∷ ⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ [])
-- witness of reflexivity of equality
Idrefl : (A t : Term) → Term
Idrefl A t = gen Idreflkind (⟦ 0 , A ⟧ ∷ ⟦ 0 , t ⟧ ∷ [])
-- transport on propositions
transp : (A P t s u e : Term) → Term
transp A P t s u e = gen Transpkind (⟦ 0 , A ⟧ ∷ ⟦ 1 , P ⟧ ∷ ⟦ 0 , t ⟧ ∷ ⟦ 0 , s ⟧ ∷ ⟦ 0 , u ⟧ ∷ ⟦ 0 , e ⟧ ∷ [])
-- cast between types, used to implement transport
cast : Level → (A B e t : Term) → Term
cast l A B e t = gen (Castkind l) (⟦ 0 , A ⟧ ∷ ⟦ 0 , B ⟧ ∷ ⟦ 0 , e ⟧ ∷ ⟦ 0 , t ⟧ ∷ [])
-- propositional proof that casting with reflexivity is the identity
castrefl : (A t : Term) → Term
castrefl A t = gen Castreflkind (⟦ 0 , A ⟧ ∷ ⟦ 0 , t ⟧ ∷ [])
-- Injectivity of term constructors w.r.t. propositional equality.
-- If Π F G = Π H E then F = H and G = E.
Π-PE-injectivity : ∀ {F rF lF G lG lΠ H rH lH E lE lΠ'} → Π F ^ rF ° lF ▹ G ° lG ° lΠ PE.≡ Π H ^ rH ° lH ▹ E ° lE ° lΠ'
→ F PE.≡ H × rF PE.≡ rH × lF PE.≡ lH × G PE.≡ E × lG PE.≡ lE × lΠ PE.≡ lΠ'
Π-PE-injectivity PE.refl = PE.refl , PE.refl , PE.refl , PE.refl , PE.refl , PE.refl
∃-PE-injectivity : ∀ {F G H E} → ∃ F ▹ G PE.≡ ∃ H ▹ E
→ F PE.≡ H × G PE.≡ E
∃-PE-injectivity PE.refl = PE.refl , PE.refl
-- If suc n = suc m then n = m.
suc-PE-injectivity : ∀ {n m} → suc n PE.≡ suc m → n PE.≡ m
suc-PE-injectivity PE.refl = PE.refl
Univ-PE-injectivity : ∀ {r r' l l'} → Univ r l PE.≡ Univ r' l' → r PE.≡ r' × l PE.≡ l'
Univ-PE-injectivity PE.refl = PE.refl , PE.refl
-- Neutral terms.
-- A term is neutral if
-- either it has a variable in head position that blocks reduction.
-- either it is of the form Emptyrec (or terms that should reduce to emptyrec, such as incompatible casts)
data Neutral : Term → Set where
var : ∀ n → Neutral (var n)
∘ₙ : ∀ {k u l} → Neutral k → Neutral (k ∘ u ^ l)
natrecₙ : ∀ {l C c g k} → Neutral k → Neutral (natrec l C c g k)
Idₙ : ∀ {A t u} → Neutral A → Neutral (Id A t u)
Idℕₙ : ∀ {t u} → Neutral t → Neutral (Id ℕ t u)
Idℕ0ₙ : ∀ {u} → Neutral u → Neutral (Id ℕ zero u)
IdℕSₙ : ∀ {t u} → Neutral u → Neutral (Id ℕ (suc t) u)
IdUₙ : ∀ {t u l} → Neutral t → Neutral (Id (U l) t u)
IdUℕₙ : ∀ {u l} → Neutral u → Neutral (Id (U l) ℕ u)
IdUΠₙ : ∀ {A rA lA B lB l u} → Neutral u → Neutral (Id (U l) (Π A ^ rA ° lA ▹ B ° lB ° l) u)
castₙ : ∀ {l A B e t} → Neutral A → Neutral (cast l A B e t)
castℕₙ : ∀ {l B e t} → Neutral B → Neutral (cast l ℕ B e t)
castΠₙ : ∀ {l A rA lA P lP B e t} → Neutral B → Neutral (cast l (Π A ^ rA ° lA ▹ P ° lP ° l) B e t)
castℕℕₙ : ∀ {l e t} → Neutral t → Neutral (cast l ℕ ℕ e t)
castℕΠₙ : ∀ {l A rA B e t} → Neutral (cast l ℕ (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° l) e t)
castΠℕₙ : ∀ {l A rA B e t} → Neutral (cast l (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° l) ℕ e t)
castΠΠ%!ₙ : ∀ {l A B A' B' e t} → Neutral (cast l (Π A ^ % ° ⁰ ▹ B ° ⁰ ° l) (Π A' ^ ! ° ⁰ ▹ B' ° ⁰ ° l) e t)
castΠΠ!%ₙ : ∀ {l A B A' B' e t} → Neutral (cast l (Π A ^ ! ° ⁰ ▹ B ° ⁰ ° l) (Π A' ^ % ° ⁰ ▹ B' ° ⁰ ° l) e t)
Emptyrecₙ : ∀ {l lEmpty A e} -> Neutral (Emptyrec l lEmpty A e)
-- Weak head normal forms (whnfs).
-- These are the (lazy) values of our language.
data Whnf : Term → Set where
-- Type constructors are whnfs.
Uₙ : ∀ {r l} → Whnf (Univ r l)
Πₙ : ∀ {A r lA B lB l} → Whnf (Π A ^ r ° lA ▹ B ° lB ° l)
∃ₙ : ∀ {A B} → Whnf (∃ A ▹ B)
ℕₙ : Whnf ℕ
Emptyₙ : ∀ {l} → Whnf (Empty l)
-- Introductions are whnfs.
lamₙ : ∀ {A t l} → Whnf (lam A ▹ t ^ l)
zeroₙ : Whnf zero
sucₙ : ∀ {t} → Whnf (suc t)
-- Neutrals are whnfs.
ne : ∀ {n} → Neutral n → Whnf n
-- Whnf inequalities.
-- Different whnfs are trivially distinguished by propositional equality.
-- (The following statements are sometimes called "no-confusion theorems".)
U≢ℕ : ∀ {r l} → Univ r l PE.≢ ℕ
U≢ℕ ()
U≢Empty : ∀ {r l l'} → Univ r l PE.≢ Empty l'
U≢Empty ()
U≢Π : ∀ {r r' l F lF G lG l'} → Univ r l PE.≢ Π F ^ r' ° lF ▹ G ° lG ° l'
U≢Π ()
U≢∃ : ∀ {r l F G} → Univ r l PE.≢ ∃ F ▹ G
U≢∃ ()
U≢ne : ∀ {r l K} → Neutral K → Univ r l PE.≢ K
U≢ne () PE.refl
ℕ≢Π : ∀ {F r lF G lG l} → ℕ PE.≢ Π F ^ r ° lF ▹ G ° lG ° l
ℕ≢Π ()
ℕ≢∃ : ∀ {F G} → ℕ PE.≢ ∃ F ▹ G
ℕ≢∃ ()
ℕ≢Empty : ∀ {l} → ℕ PE.≢ Empty l
ℕ≢Empty ()
Empty≢ℕ : ∀ {l} → Empty l PE.≢ ℕ
Empty≢ℕ ()
ℕ≢ne : ∀ {K} → Neutral K → ℕ PE.≢ K
ℕ≢ne () PE.refl
Empty≢ne : ∀ {l K} → Neutral K → Empty l PE.≢ K
Empty≢ne () PE.refl
Empty≢Π : ∀ {F r lF G lG l l'} → Empty l' PE.≢ Π F ^ r ° lF ▹ G ° lG ° l
Empty≢Π ()
Empty≢∃ : ∀ {l F G} → Empty l PE.≢ ∃ F ▹ G
Empty≢∃ ()
Π≢ne : ∀ {F r lF G lG K l} → Neutral K → Π F ^ r ° lF ▹ G ° lG ° l PE.≢ K
Π≢ne () PE.refl
Π≢∃ : ∀ {F r lF G lG F' G' l} → Π F ^ r ° lF ▹ G ° lG ° l PE.≢ ∃ F' ▹ G'
Π≢∃ ()
∃≢ne : ∀ {F G K} → Neutral K → ∃ F ▹ G PE.≢ K
∃≢ne () PE.refl
zero≢suc : ∀ {n} → zero PE.≢ suc n
zero≢suc ()
zero≢ne : ∀ {k} → Neutral k → zero PE.≢ k
zero≢ne () PE.refl
suc≢ne : ∀ {n k} → Neutral k → suc n PE.≢ k
suc≢ne () PE.refl
-- Several views on whnfs (note: not recursive).
-- A whnf of type ℕ is either zero, suc t, or neutral.
data Natural : Term → Set where
zeroₙ : Natural zero
sucₙ : ∀ {t} → Natural (suc t)
ne : ∀ {n} → Neutral n → Natural n
-- A type in whnf is either Π A B, ℕ, or neutral.
-- Large types could also be U.
data Type : Term → Set where
Πₙ : ∀ {A r lA B lB l} → Type (Π A ^ r ° lA ▹ B ° lB ° l)
ℕₙ : Type ℕ
Uₙ : ∀ {r l} → Type (Univ r l)
Emptyₙ : ∀ {l} → Type (Empty l)
∃ₙ : ∀ {A B} → Type (∃ A ▹ B)
ne : ∀{n} → Neutral n → Type n
-- A whnf of type Π A B is either lam t or neutral.
data Function : Term → Set where
lamₙ : ∀{A t l} → Function (lam A ▹ t ^ l)
ne : ∀{n} → Neutral n → Function n
-- These views classify only whnfs.
-- Natural, Type, and Function are a subsets of Whnf.
naturalWhnf : ∀ {n} → Natural n → Whnf n
naturalWhnf sucₙ = sucₙ
naturalWhnf zeroₙ = zeroₙ
naturalWhnf (ne x) = ne x
typeWhnf : ∀ {A} → Type A → Whnf A
typeWhnf Πₙ = Πₙ
typeWhnf ℕₙ = ℕₙ
typeWhnf Uₙ = Uₙ
typeWhnf ∃ₙ = ∃ₙ
typeWhnf Emptyₙ = Emptyₙ
typeWhnf (ne x) = ne x
functionWhnf : ∀ {f} → Function f → Whnf f
functionWhnf lamₙ = lamₙ
functionWhnf (ne x) = ne x
------------------------------------------------------------------------
-- Weakening
-- In the following we define untyped weakenings η : Wk.
-- The typed form could be written η : Γ ≤ Δ with the intention
-- that η transport a term t living in context Δ to a context Γ
-- that can bind additional variables (which cannot appear in t).
-- Thus, if Δ ⊢ t : A and η : Γ ≤ Δ then Γ ⊢ wk η t : wk η A.
--
-- Even though Γ is "larger" than Δ we write Γ ≤ Δ to be conformant
-- with subtyping A ≤ B. With subtyping, relation Γ ≤ Δ could be defined as
-- ``for all x ∈ dom(Δ) have Γ(x) ≤ Δ(x)'' (in the sense of subtyping)
-- and this would be the natural extension of weakenings.
data Wk : Set where
id : Wk -- η : Γ ≤ Γ.
step : Wk → Wk -- If η : Γ ≤ Δ then step η : Γ∙A ≤ Δ.
lift : Wk → Wk -- If η : Γ ≤ Δ then lift η : Γ∙A ≤ Δ∙A.
-- Composition of weakening.
-- If η : Γ ≤ Δ and η′ : Δ ≤ Φ then η • η′ : Γ ≤ Φ.
infixl 30 _•_
_•_ : Wk → Wk → Wk
id • η′ = η′
step η • η′ = step (η • η′)
lift η • id = lift η
lift η • step η′ = step (η • η′)
lift η • lift η′ = lift (η • η′)
repeat : {A : Set} → (A → A) → A → Nat → A
repeat f a 0 = a
repeat f a (1+ n) = f (repeat f a n)
-- Weakening of variables.
-- If η : Γ ≤ Δ and x ∈ dom(Δ) then wkVar ρ x ∈ dom(Γ).
wkVar : (ρ : Wk) (n : Nat) → Nat
wkVar id n = n
wkVar (step ρ) n = 1+ (wkVar ρ n)
wkVar (lift ρ) 0 = 0
wkVar (lift ρ) (1+ n) = 1+ (wkVar ρ n)
-- Weakening of terms.
-- If η : Γ ≤ Δ and Δ ⊢ t : A then Γ ⊢ wk η t : wk η A.
mutual
wkGen : (ρ : Wk) (g : List (GenT Term)) → List (GenT Term)
wkGen ρ [] = []
wkGen ρ (⟦ l , t ⟧ ∷ g) = ⟦ l , (wk (repeat lift ρ l) t) ⟧ ∷ wkGen ρ g
wk : (ρ : Wk) (t : Term) → Term
wk ρ (var x) = var (wkVar ρ x)
wk ρ (gen x c) = gen x (wkGen ρ c)
-- Adding one variable to the context requires wk1.
-- If Γ ⊢ t : B then Γ∙A ⊢ wk1 t : wk1 B.
wk1 : Term → Term
wk1 = wk (step id)
wk1d : Term → Term
wk1d = wk (lift (step id))
-- Weakening of a neutral term.
wkNeutral : ∀ {t} ρ → Neutral t → Neutral (wk ρ t)
wkNeutral ρ (var n) = var (wkVar ρ n)
wkNeutral ρ (∘ₙ n) = ∘ₙ (wkNeutral ρ n)
wkNeutral ρ (natrecₙ n) = natrecₙ (wkNeutral ρ n)
wkNeutral ρ Emptyrecₙ = Emptyrecₙ
wkNeutral ρ (Idₙ A) = Idₙ (wkNeutral ρ A)
wkNeutral ρ (Idℕₙ t) = Idℕₙ (wkNeutral ρ t)
wkNeutral ρ (Idℕ0ₙ t) = Idℕ0ₙ (wkNeutral ρ t)
wkNeutral ρ (IdℕSₙ t) = IdℕSₙ (wkNeutral ρ t)
wkNeutral ρ (IdUₙ t) = IdUₙ (wkNeutral ρ t)
wkNeutral ρ (IdUℕₙ t) = IdUℕₙ (wkNeutral ρ t)
wkNeutral ρ (IdUΠₙ t) = IdUΠₙ (wkNeutral ρ t)
wkNeutral ρ (castₙ A) = castₙ (wkNeutral ρ A)
wkNeutral ρ (castℕₙ A) = castℕₙ (wkNeutral ρ A)
wkNeutral ρ (castΠₙ A) = castΠₙ (wkNeutral ρ A)
wkNeutral ρ (castℕℕₙ t) = castℕℕₙ (wkNeutral ρ t)
wkNeutral ρ castℕΠₙ = castℕΠₙ
wkNeutral ρ castΠℕₙ = castΠℕₙ
wkNeutral ρ castΠΠ%!ₙ = castΠΠ%!ₙ
wkNeutral ρ castΠΠ!%ₙ = castΠΠ!%ₙ
-- Weakening can be applied to our whnf views.
wkNatural : ∀ {t} ρ → Natural t → Natural (wk ρ t)
wkNatural ρ sucₙ = sucₙ
wkNatural ρ zeroₙ = zeroₙ
wkNatural ρ (ne x) = ne (wkNeutral ρ x)
wkType : ∀ {t} ρ → Type t → Type (wk ρ t)
wkType ρ Πₙ = Πₙ
wkType ρ ℕₙ = ℕₙ
wkType ρ Uₙ = Uₙ
wkType ρ ∃ₙ = ∃ₙ
wkType ρ Emptyₙ = Emptyₙ
wkType ρ (ne x) = ne (wkNeutral ρ x)
wkFunction : ∀ {t} ρ → Function t → Function (wk ρ t)
wkFunction ρ lamₙ = lamₙ
wkFunction ρ (ne x) = ne (wkNeutral ρ x)
wkWhnf : ∀ {t} ρ → Whnf t → Whnf (wk ρ t)
wkWhnf ρ Uₙ = Uₙ
wkWhnf ρ Πₙ = Πₙ
wkWhnf ρ ∃ₙ = ∃ₙ
wkWhnf ρ ℕₙ = ℕₙ
wkWhnf ρ Emptyₙ = Emptyₙ
wkWhnf ρ lamₙ = lamₙ
wkWhnf ρ zeroₙ = zeroₙ
wkWhnf ρ sucₙ = sucₙ
wkWhnf ρ (ne x) = ne (wkNeutral ρ x)
-- Non-dependent version of Π.
_^_°_▹▹_°_°_ : Term → Relevance → Level → Term → Level → Level → Term
A ^ r ° lA ▹▹ B ° lB ° l = Π A ^ r ° lA ▹ wk1 B ° lB ° l
-- Non-dependent version of ∃.
_××_ : Term → Term → Term
A ×× B = ∃ A ▹ wk1 B
------------------------------------------------------------------------
-- Substitution
-- The substitution operation subst σ t replaces the free de Bruijn indices
-- of term t by chosen terms as specified by σ.
-- The substitution σ itself is a map from natural numbers to terms.
Subst : Set
Subst = Nat → Term
-- Given closed contexts ⊢ Γ and ⊢ Δ,
-- substitutions may be typed via Γ ⊢ σ : Δ meaning that
-- Γ ⊢ σ(x) : (subst σ Δ)(x) for all x ∈ dom(Δ).
--
-- The substitution operation is then typed as follows:
-- If Γ ⊢ σ : Δ and Δ ⊢ t : A, then Γ ⊢ subst σ t : subst σ A.
--
-- Although substitutions are untyped, typing helps us
-- to understand the operation on substitutions.
-- We may view σ as the infinite stream σ 0, σ 1, ...
-- Extract the substitution of the first variable.
--
-- If Γ ⊢ σ : Δ∙A then Γ ⊢ head σ : subst σ A.
head : Subst → Term
head σ = σ 0
-- Remove the first variable instance of a substitution
-- and shift the rest to accommodate.
--
-- If Γ ⊢ σ : Δ∙A then Γ ⊢ tail σ : Δ.
tail : Subst → Subst
tail σ n = σ (1+ n)
-- Substitution of a variable.
--
-- If Γ ⊢ σ : Δ then Γ ⊢ substVar σ x : (subst σ Δ)(x).
substVar : (σ : Subst) (x : Nat) → Term
substVar σ x = σ x
-- Identity substitution.
-- Replaces each variable by itself.
--
-- Γ ⊢ idSubst : Γ.
idSubst : Subst
idSubst = var
-- Weaken a substitution by one.
--
-- If Γ ⊢ σ : Δ then Γ∙A ⊢ wk1Subst σ : Δ.
wk1Subst : Subst → Subst
wk1Subst σ x = wk1 (σ x)
-- Lift a substitution.
--
-- If Γ ⊢ σ : Δ then Γ∙A ⊢ liftSubst σ : Δ∙A.
liftSubst : (σ : Subst) → Subst
liftSubst σ 0 = var 0
liftSubst σ (1+ x) = wk1Subst σ x
-- Transform a weakening into a substitution.
--
-- If ρ : Γ ≤ Δ then Γ ⊢ toSubst ρ : Δ.
toSubst : Wk → Subst
toSubst pr x = var (wkVar pr x)
-- Apply a substitution to a term.
--
-- If Γ ⊢ σ : Δ and Δ ⊢ t : A then Γ ⊢ subst σ t : subst σ A.
mutual
substGen : (σ : Subst) (g : List (GenT Term)) → List (GenT Term)
substGen σ [] = []
substGen σ (⟦ l , t ⟧ ∷ g) = ⟦ l , (subst (repeat liftSubst σ l) t) ⟧ ∷ substGen σ g
subst : (σ : Subst) (t : Term) → Term
subst σ (var x) = substVar σ x
subst σ (gen x c) = gen x (substGen σ c)
-- Extend a substitution by adding a term as
-- the first variable substitution and shift the rest.
--
-- If Γ ⊢ σ : Δ and Γ ⊢ t : subst σ A then Γ ⊢ consSubst σ t : Δ∙A.
consSubst : Subst → Term → Subst
consSubst σ t 0 = t
consSubst σ t (1+ n) = σ n
-- Singleton substitution.
--
-- If Γ ⊢ t : A then Γ ⊢ sgSubst t : Γ∙A.
sgSubst : Term → Subst
sgSubst = consSubst idSubst
-- Compose two substitutions.
--
-- If Γ ⊢ σ : Δ and Δ ⊢ σ′ : Φ then Γ ⊢ σ ₛ•ₛ σ′ : Φ.
_ₛ•ₛ_ : Subst → Subst → Subst
_ₛ•ₛ_ σ σ′ x = subst σ (σ′ x)
-- Composition of weakening and substitution.
--
-- If ρ : Γ ≤ Δ and Δ ⊢ σ : Φ then Γ ⊢ ρ •ₛ σ : Φ.
_•ₛ_ : Wk → Subst → Subst
_•ₛ_ ρ σ x = wk ρ (σ x)
-- If Γ ⊢ σ : Δ and ρ : Δ ≤ Φ then Γ ⊢ σ ₛ• ρ : Φ.
_ₛ•_ : Subst → Wk → Subst
_ₛ•_ σ ρ x = σ (wkVar ρ x)
-- Substitute the first variable of a term with an other term.
--
-- If Γ∙A ⊢ t : B and Γ ⊢ s : A then Γ ⊢ t[s] : B[s].
_[_] : (t : Term) (s : Term) → Term
t [ s ] = subst (sgSubst s) t
-- Substitute the first variable of a term with an other term,
-- but let the two terms share the same context.
--
-- If Γ∙A ⊢ t : B and Γ∙A ⊢ s : A then Γ∙A ⊢ t[s]↑ : B[s]↑.
_[_]↑ : (t : Term) (s : Term) → Term
t [ s ]↑ = subst (consSubst (wk1Subst idSubst) s) t
_[_]↑↑ : (t : Term) (s : Term) → Term
t [ s ]↑↑ = subst (consSubst (wk1Subst (wk1Subst idSubst)) s) t
-- Definition of syntaxic sugar
Unit : ∀ {l} → Term
Unit {l} = Π Empty l ^ % ° l ▹ Empty l ° l ° l
Idsym : (A x y e : Term) → Term
Idsym A x y e = transp A (Id (wk1 A) (var 0) (wk1 x)) x (Idrefl A x) y e
| {
"alphanum_fraction": 0.5616374147,
"avg_line_length": 28.1127379209,
"ext": "agda",
"hexsha": "e9ca9daaa39ae62d792f6a023d01fc0a4b16fc62",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Untyped.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"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": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Untyped.agda",
"max_line_length": 119,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Untyped.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 8284,
"size": 19201
} |
{-# OPTIONS --cubical --safe #-}
module Data.List.Membership where
open import Data.List
open import Data.Fin
open import Data.Fin.Properties
open import Prelude
open import Relation.Nullary
open import Path.Reasoning
open import Data.List.Relation.Unary as Relation using (module Exists; module Congruence; ◇; ◇!)
import Data.Nat as ℕ
import Data.Nat.Properties as ℕ
open import Data.Maybe.Properties using (just-inj)
module _ {a} {A : Type a} {x : A} where
open Exists (_≡ x)
using (push; pull; push!; pull!; here!; _◇++_; _++◇_)
renaming (◇? to _∈?_)
public
infixr 5 _∈_ _∈!_ _∉_
_∈_ : A → List A → Type _
x ∈ xs = ◇ (_≡ x) xs
_∉_ : {A : Type a} → A → List A → Type a
x ∉ xs = ¬ (x ∈ xs)
_∈!_ : A → List A → Type _
x ∈! xs = ◇! (_≡ x) xs
cong-∈ : ∀ (f : A → B) {x : A} xs → x ∈ xs → f x ∈ map f xs
cong-∈ f {x} = Congruence.cong-◇ (_≡ x) (_≡ (f x)) (cong f)
fin∈tabulate : ∀ {n}
(f : Fin n → A)
(i : Fin n) →
f i ∈ tabulate n f
fin∈tabulate {n = suc _} f f0 = f0 , refl
fin∈tabulate {n = suc _} f (fs i) =
push (fin∈tabulate (f ∘ fs) i)
open import Function.Injective
at : ∀ {xs : List A} (n : Fin (length xs)) → (xs ! n) ∈ xs
at n = n , refl
module _ {a} {A : Set a} (_≟_ : Discrete A) where
isSet⟨A⟩ : isSet A
isSet⟨A⟩ = Discrete→isSet _≟_
infixl 6 _\\_
_\\_ : List A → A → List A
xs \\ x = foldr f [] xs
where
f : A → List A → List A
f y xs with x ≟ y
... | yes p = xs
... | no p = y ∷ xs
uniques : List A → List A
uniques = foldr f []
where
f : A → List A → List A
f x xs = x ∷ (xs \\ x)
x∉xs\\x : ∀ x xs → x ∉ xs \\ x
x∉xs\\x x (y ∷ xs) (n , x∈xs) with x ≟ y
x∉xs\\x x (y ∷ xs) (n , x∈xs) | yes p = x∉xs\\x x xs (n , x∈xs)
x∉xs\\x x (y ∷ xs) (f0 , y≡x) | no ¬p = ¬p (sym y≡x)
x∉xs\\x x (y ∷ xs) (fs n , x∈xs) | no ¬p = x∉xs\\x x xs (n , x∈xs)
x∈!x∷xs\\x : ∀ x xs → x ∈! x ∷ xs \\ x
x∈!x∷xs\\x x xs = here! (refl , isSet⟨A⟩ _ _ refl) (x∉xs\\x x xs)
x∉xs⇒x∉xs\\y : ∀ (x : A) y xs → x ∉ xs → x ∉ xs \\ y
x∉xs⇒x∉xs\\y x y (z ∷ xs) x∉xs x∈xs\\y with y ≟ z
x∉xs⇒x∉xs\\y x y (z ∷ xs) x∉xs x∈xs\\y | yes p =
x∉xs⇒x∉xs\\y x y xs (x∉xs ∘ push) x∈xs\\y
x∉xs⇒x∉xs\\y x y (z ∷ xs) x∉xs (f0 , x∈xs\\y) | no ¬p =
x∉xs (f0 , x∈xs\\y)
x∉xs⇒x∉xs\\y x y (z ∷ xs) x∉xs (fs n , x∈xs\\y) | no ¬p =
x∉xs⇒x∉xs\\y x y xs (x∉xs ∘ push) (n , x∈xs\\y)
x∈!xs⇒x∈!xs\\y : ∀ (x : A) y xs → y ≢ x → x ∈! xs → x ∈! xs \\ y
x∈!xs⇒x∈!xs\\y x y (z ∷ xs) y≢x x∈!xs with y ≟ z
x∈!xs⇒x∈!xs\\y x y (z ∷ xs) y≢x x∈!xs | yes p =
x∈!xs⇒x∈!xs\\y x y xs y≢x (pull! (y≢x ∘ p ;_) x∈!xs)
x∈!xs⇒x∈!xs\\y x y (z ∷ xs) y≢x ((f0 , x∈xs) , uniq) | no ¬p =
here! (x∈xs , isSet⟨A⟩ _ _ _) (x∉xs⇒x∉xs\\y x y xs (ℕ.znots ∘ cong FinToℕ ∘ cong fst ∘ uniq ∘ push))
x∈!xs⇒x∈!xs\\y x y (z ∷ xs) y≢x ((fs n , x∈xs) , uniq) | no ¬p =
push! z≢x (x∈!xs⇒x∈!xs\\y x y xs y≢x (pull! z≢x ((fs n , x∈xs) , uniq)))
where z≢x = ℕ.snotz ∘ cong FinToℕ ∘ cong fst ∘ uniq ∘ (f0 ,_)
∈⇒∈! : (x : A) (xs : List A) → x ∈ xs → x ∈! uniques xs
∈⇒∈! x (y ∷ xs) (f0 , x∈xs) =
subst (_∈! (y ∷ uniques xs \\ y)) x∈xs (x∈!x∷xs\\x y (uniques xs))
∈⇒∈! x (y ∷ xs) (fs n , x∈xs) with y ≟ x
... | yes p = subst (_∈! (y ∷ uniques xs \\ y)) p (x∈!x∷xs\\x y (uniques xs))
... | no ¬p = push! ¬p (x∈!xs⇒x∈!xs\\y x y (uniques xs) ¬p (∈⇒∈! x xs (n , x∈xs)))
infixr 5 _∈²_
_∈²_ : A → List (List A) → Type _
x ∈² xs = ◇ (x ∈_) xs
∈²→∈ : ∀ {x : A} xs → x ∈² xs → x ∈ concat xs
∈²→∈ = Relation.◇-concat (_≡ _)
| {
"alphanum_fraction": 0.4824957651,
"avg_line_length": 32.7962962963,
"ext": "agda",
"hexsha": "0fe1470cc2e48d5476942912d80ce01391a998ab",
"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/Data/List/Membership.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/Data/List/Membership.agda",
"max_line_length": 104,
"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/Data/List/Membership.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": 1860,
"size": 3542
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Monoidal
module Experiment.Categories.Category.Monoidal.Coherence
{o ℓ e} {𝒞 : Category o ℓ e} (M : Monoidal 𝒞) where
open import Level
open import Data.Product using (Σ)
open import Categories.Morphism 𝒞
open import Categories.Functor
open Category 𝒞
open Monoidal M
𝒞′ : Category (o ⊔ ℓ ⊔ e) (ℓ ⊔ o) e
𝒞′ = categoryHelper record
{ Obj = Σ (Endofunctor 𝒞) λ E →
∀ {A B} → Functor.F₀ E A ⊗₀ B ≅ Functor.F₀ E (A ⊗₀ B)
-- TODO and more coherence
; _⇒_ = {! !}
; _≈_ = {! !}
; id = {! !}
; _∘_ = {! !}
; assoc = {! !}
; identityˡ = {! !}
; identityʳ = {! !}
; equiv = {! !}
; ∘-resp-≈ = {! !}
}
| {
"alphanum_fraction": 0.5449936629,
"avg_line_length": 23.9090909091,
"ext": "agda",
"hexsha": "c4a18a6f58466d7b7e4b10e01d2e886eb9cf7139",
"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/Coherence.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/Coherence.agda",
"max_line_length": 58,
"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/Coherence.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": 289,
"size": 789
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
{-
This file defines
sucPred : ∀ (i : Int) → sucInt (predInt i) ≡ i
predSuc : ∀ (i : Int) → predInt (sucInt i) ≡ i
discreteInt : discrete Int
isSetInt : isSet Int
addition of Int is defined _+_ : Int → Int → Int
as well as its commutativity and associativity
+-comm : ∀ (m n : Int) → m + n ≡ n + m
+-assoc : ∀ (m n o : Int) → m + (n + o) ≡ (m + n) + o
An alternate definition of _+_ is defined via ua,
namely _+'_, which helps us to easily prove
isEquivAddInt : (m : Int) → isEquiv (λ n → n + m)
-}
module Cubical.Data.Int.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Unit renaming (Unit to ⊤)
open import Cubical.Data.Nat as ℕ using (ℕ; zero; suc; discreteℕ) renaming
( _·_ to _·ⁿ_
; _+_ to _+ⁿ_
; _⊓_ to _⊓ⁿ_
; _⊔_ to _⊔ⁿ_
)
open import Cubical.Data.Nat.Order as ℕᵒ using () renaming ( _<_ to _<ⁿ_ )
open import Cubical.Data.Bool hiding (_≟_)
open import Cubical.Data.Sum
open import Cubical.Data.Int.Base
open import Cubical.Functions.Logic using (pathTo⇒; ⊔-comm)
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (propTruncIsProp)
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Reflection.Base using (_$_) -- TODO: add this to Foundation.Function
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
abs : Int → ℕ
abs (pos n) = n
abs (negsuc n) = suc n
Sign : Type₀
Sign = Bool
pattern spos = Bool.false
pattern sneg = Bool.true
_·ˢ_ : Sign → Sign → Sign
_·ˢ_ = _⊕_
sgn : Int → Bool
sgn (pos n) = spos
sgn (negsuc n) = sneg
signed : Sign → ℕ → Int
signed spos x = pos x
signed sneg zero = pos 0
signed sneg (suc x) = neg (suc x)
sgn-signed : ∀ s n → sgn (signed s (suc n)) ≡ s
sgn-signed spos n = refl
sgn-signed sneg n = refl
abs-signed : ∀ s n → abs (signed s n) ≡ n
abs-signed spos n = refl
abs-signed sneg zero = refl
abs-signed sneg (suc n) = refl
signed-inv : ∀ a → signed (sgn a) (abs a) ≡ a
signed-inv (pos n) = refl
signed-inv (negsuc n) = refl
signed-zero : ∀ s → signed s 0 ≡ 0
signed-zero spos = refl
signed-zero sneg = refl
signed-reflects-sgn : ∀ s₁ s₂ n m → signed s₁ (suc n) ≡ signed s₂ (suc m) → s₁ ≡ s₂
signed-reflects-sgn s₁ s₂ n m p = sym (sgn-signed s₁ n) ∙ (λ i → sgn (p i)) ∙ sgn-signed s₂ m
signed-reflects-abs : ∀ s₁ s₂ n m → signed s₁ n ≡ signed s₂ m → n ≡ m
signed-reflects-abs s₁ s₂ n m p = sym (abs-signed s₁ n) ∙ (λ i → abs (p i)) ∙ abs-signed s₂ m
sign-abs-≡ : ∀ a b → sgn a ≡ sgn b → abs a ≡ abs b → a ≡ b
sign-abs-≡ a b p q = transport (λ i → signed-inv a i ≡ signed-inv b i) λ i → signed (p i) (q i)
sucPred : ∀ i → sucInt (predInt i) ≡ i
sucPred (pos zero) = refl
sucPred (pos (suc n)) = refl
sucPred (negsuc n) = refl
predSuc : ∀ i → predInt (sucInt i) ≡ i
predSuc (pos n) = refl
predSuc (negsuc zero) = refl
predSuc (negsuc (suc n)) = refl
predInt-inj : ∀ a b → predInt a ≡ predInt b → a ≡ b
predInt-inj a b p = sym (sucPred a) ∙ cong sucInt p ∙ sucPred b
injPos : ∀ {a b : ℕ} → pos a ≡ pos b → a ≡ b
injPos {a} h = subst T h refl
where
T : Int → Type₀
T (pos x) = a ≡ x
T (negsuc _) = ⊥
injNegsuc : ∀ {a b : ℕ} → negsuc a ≡ negsuc b → a ≡ b
injNegsuc {a} h = subst T h refl
where
T : Int → Type₀
T (pos _) = ⊥
T (negsuc x) = a ≡ x
posNotnegsuc : ∀ (a b : ℕ) → ¬ (pos a ≡ negsuc b)
posNotnegsuc a b h = subst T h 0
where
T : Int → Type₀
T (pos _) = ℕ
T (negsuc _) = ⊥
negsucNotpos : ∀ (a b : ℕ) → ¬ (negsuc a ≡ pos b)
negsucNotpos a b h = subst T h 0
where
T : Int → Type₀
T (pos _) = ⊥
T (negsuc _) = ℕ
discreteInt : Discrete Int
discreteInt (pos n) (pos m) with discreteℕ n m
... | yes p = yes (cong pos p)
... | no p = no (λ x → p (injPos x))
discreteInt (pos n) (negsuc m) = no (posNotnegsuc n m)
discreteInt (negsuc n) (pos m) = no (negsucNotpos n m)
discreteInt (negsuc n) (negsuc m) with discreteℕ n m
... | yes p = yes (cong negsuc p)
... | no p = no (λ x → p (injNegsuc x))
isSetInt : isSet Int
isSetInt = Discrete→isSet discreteInt
_ℕ-_ : ℕ → ℕ → Int
a ℕ- 0 = pos a
0 ℕ- suc b = negsuc b
suc a ℕ- suc b = a ℕ- b
_+pos_ : Int → ℕ → Int
z +pos 0 = z
z +pos (suc n) = sucInt (z +pos n)
_+negsuc_ : Int → ℕ → Int
z +negsuc 0 = predInt z
z +negsuc (suc n) = predInt (z +negsuc n)
infix 8 -_
infixl 7 _·_ _⊓_
infixl 6 _+_ _-_ _⊔_
infix 4 _<_ -- _≤_
_+_ : Int → Int → Int
m + pos n = m +pos n
m + negsuc n = m +negsuc n
-- TODO: in `Cubical.Papers.RepresentationIndependence` we have
-- -_ : ℤ → ℤ
-- - x = 0 - x
-- there might be an advantage of defining -_ by _-_ and not the other way around
-- e.g. in Cubical.HITs.QuoInt we have
-- -_ : ℤ → ℤ
-- - signed s n = signed (not s) n
-- - posneg i = posneg (~ i)
-_ : Int → Int
- pos zero = pos zero
- pos (suc n) = negsuc n
- negsuc n = pos (suc n)
_-_ : Int → Int → Int
m - n = m + (- n)
_·_ : Int → Int → Int
x · y = signed (sgn x ⊕ sgn y) (abs x ·ⁿ abs y)
_<_ : ∀(x y : Int) → Type₀
pos x < pos y = x <ⁿ y
pos x < negsuc y = ⊥
negsuc x < pos y = ⊤
negsuc x < negsuc y = y <ⁿ x
_⊓_ : Int → Int → Int
(pos x) ⊓ (pos y) = pos (x ⊓ⁿ y)
(pos x) ⊓ (negsuc y) = negsuc y
(negsuc x) ⊓ (pos y) = negsuc x
(negsuc x) ⊓ (negsuc y) = negsuc (x ⊔ⁿ y)
_⊔_ : Int → Int → Int
(pos x) ⊔ (pos y) = pos (x ⊔ⁿ y)
(pos x) ⊔ (negsuc y) = pos x
(negsuc x) ⊔ (pos y) = pos y
(negsuc x) ⊔ (negsuc y) = negsuc (x ⊓ⁿ y)
neg-involutive : ∀ n → - - n ≡ n
neg-involutive (pos zero ) = refl
neg-involutive (pos (suc n)) = refl
neg-involutive (negsuc n ) = refl
neg-signed-not : ∀ s n → - signed s n ≡ signed (not s) n
neg-signed-not spos zero = refl
neg-signed-not sneg zero = refl
neg-signed-not spos (suc n) = refl
neg-signed-not sneg (suc n) = refl
neg-abs : ∀ a → abs (- a) ≡ abs a
neg-abs (pos zero) = refl
neg-abs (pos (suc n)) = refl
neg-abs (negsuc n) = refl
neg-reflects-≡ : ∀ a b → - a ≡ - b → a ≡ b
neg-reflects-≡ a b p = sym (neg-involutive a) ∙ (λ i → - p i) ∙ neg-involutive b
abs-preserves-· : ∀ a b → abs (a · b) ≡ abs a ℕ.· abs b
abs-preserves-· a b = abs-signed (sgn a ⊕ sgn b) _
sucInt+pos : ∀ n m → sucInt (m +pos n) ≡ (sucInt m) +pos n
sucInt+pos zero m = refl
sucInt+pos (suc n) m = cong sucInt (sucInt+pos n m)
predInt+negsuc : ∀ n m → predInt (m +negsuc n) ≡ (predInt m) +negsuc n
predInt+negsuc zero m = refl
predInt+negsuc (suc n) m = cong predInt (predInt+negsuc n m)
sucInt+negsuc : ∀ n m → sucInt (m +negsuc n) ≡ (sucInt m) +negsuc n
sucInt+negsuc zero m = (sucPred _) ∙ (sym (predSuc _))
sucInt+negsuc (suc n) m = _ ≡⟨ sucPred _ ⟩
m +negsuc n ≡[ i ]⟨ predSuc m (~ i) +negsuc n ⟩
(predInt (sucInt m)) +negsuc n ≡⟨ sym (predInt+negsuc n (sucInt m)) ⟩
predInt (sucInt m +negsuc n) ∎
predInt+pos : ∀ n m → predInt (m +pos n) ≡ (predInt m) +pos n
predInt+pos zero m = refl
predInt+pos (suc n) m = _ ≡⟨ predSuc _ ⟩
m +pos n ≡[ i ]⟨ sucPred m (~ i) + pos n ⟩
(sucInt (predInt m)) +pos n ≡⟨ sym (sucInt+pos n (predInt m))⟩
(predInt m) +pos (suc n) ∎
predInt+ : ∀ m n → predInt (m + n) ≡ (predInt m) + n
predInt+ m (pos n) = predInt+pos n m
predInt+ m (negsuc n) = predInt+negsuc n m
+predInt : ∀ m n → predInt (m + n) ≡ m + (predInt n)
+predInt m (pos zero) = refl
+predInt m (pos (suc n)) = (predSuc (m + pos n)) ∙ (cong (_+_ m) (sym (predSuc (pos n))))
+predInt m (negsuc n) = refl
sucInt+ : ∀ m n → sucInt (m + n) ≡ (sucInt m) + n
sucInt+ m (pos n) = sucInt+pos n m
sucInt+ m (negsuc n) = sucInt+negsuc n m
+sucInt : ∀ m n → sucInt (m + n) ≡ m + (sucInt n)
+sucInt m (pos n) = refl
+sucInt m (negsuc zero) = sucPred _
+sucInt m (negsuc (suc n)) = (sucPred (m +negsuc n)) ∙ (cong (_+_ m) (sym (sucPred (negsuc n))))
pos0+ : ∀ z → z ≡ pos 0 + z
pos0+ (pos zero) = refl
pos0+ (pos (suc n)) = cong sucInt (pos0+ (pos n))
pos0+ (negsuc zero) = refl
pos0+ (negsuc (suc n)) = cong predInt (pos0+ (negsuc n))
negsuc0+ : ∀ z → predInt z ≡ negsuc 0 + z
negsuc0+ (pos zero) = refl
negsuc0+ (pos (suc n)) = (sym (sucPred (pos n))) ∙ (cong sucInt (negsuc0+ _))
negsuc0+ (negsuc zero) = refl
negsuc0+ (negsuc (suc n)) = cong predInt (negsuc0+ (negsuc n))
ind-comm : {A : Type₀} (_∙_ : A → A → A) (f : ℕ → A) (g : A → A)
(p : ∀ {n} → f (suc n) ≡ g (f n))
(g∙ : ∀ a b → g (a ∙ b) ≡ g a ∙ b)
(∙g : ∀ a b → g (a ∙ b) ≡ a ∙ g b)
(base : ∀ z → z ∙ f 0 ≡ f 0 ∙ z)
→ ∀ z n → z ∙ f n ≡ f n ∙ z
ind-comm _∙_ f g p g∙ ∙g base z 0 = base z
ind-comm _∙_ f g p g∙ ∙g base z (suc n) =
z ∙ f (suc n) ≡[ i ]⟨ z ∙ p {n} i ⟩
z ∙ g (f n) ≡⟨ sym ( ∙g z (f n)) ⟩
g (z ∙ f n) ≡⟨ cong g IH ⟩
g (f n ∙ z) ≡⟨ g∙ (f n) z ⟩
g (f n) ∙ z ≡[ i ]⟨ p {n} (~ i) ∙ z ⟩
f (suc n) ∙ z ∎
where
IH = ind-comm _∙_ f g p g∙ ∙g base z n
ind-assoc : {A : Type₀} (_·_ : A → A → A) (f : ℕ → A)
(g : A → A) (p : ∀ a b → g (a · b) ≡ a · (g b))
(q : ∀ {c} → f (suc c) ≡ g (f c))
(base : ∀ m n → (m · n) · (f 0) ≡ m · (n · (f 0)))
(m n : A) (o : ℕ)
→ m · (n · (f o)) ≡ (m · n) · (f o)
ind-assoc _·_ f g p q base m n 0 = sym (base m n)
ind-assoc _·_ f g p q base m n (suc o) =
m · (n · (f (suc o))) ≡[ i ]⟨ m · (n · q {o} i) ⟩
m · (n · (g (f o))) ≡[ i ]⟨ m · (p n (f o) (~ i)) ⟩
m · (g (n · (f o))) ≡⟨ sym (p m (n · (f o)))⟩
g (m · (n · (f o))) ≡⟨ cong g IH ⟩
g ((m · n) · (f o)) ≡⟨ p (m · n) (f o) ⟩
(m · n) · (g (f o)) ≡[ i ]⟨ (m · n) · q {o} (~ i) ⟩
(m · n) · (f (suc o)) ∎
where
IH = ind-assoc _·_ f g p q base m n o
+-comm : ∀ m n → m + n ≡ n + m
+-comm m (pos n) = ind-comm _+_ pos sucInt refl sucInt+ +sucInt pos0+ m n
+-comm m (negsuc n) = ind-comm _+_ negsuc predInt refl predInt+ +predInt negsuc0+ m n
+-assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o
+-assoc m n (pos o) = ind-assoc _+_ pos sucInt +sucInt refl (λ _ _ → refl) m n o
+-assoc m n (negsuc o) = ind-assoc _+_ negsuc predInt +predInt refl +predInt m n o
·-nullifiesʳ : ∀ x → x · 0 ≡ 0
·-nullifiesʳ (pos n) i = signed spos (ℕ.·-nullifiesʳ n i)
·-nullifiesʳ (negsuc n) i = signed sneg (ℕ.·-nullifiesʳ n i)
·-nullifiesˡ : ∀ x → 0 · x ≡ 0
·-nullifiesˡ (pos n) i = pos (ℕ.·-nullifiesˡ n i)
·-nullifiesˡ (negsuc n) = refl
+-identityʳ : ∀ x → x + 0 ≡ x
+-identityʳ x = refl
+-identityˡ : ∀ x → 0 + x ≡ x
+-identityˡ x = +-comm 0 x
·-identityʳ : ∀ x → x · 1 ≡ x
·-identityʳ x = cong₂ signed (⊕-comm (sgn x) spos) (ℕ.·-identityʳ (abs x)) ∙ signed-inv x
·-identityˡ : ∀ x → 1 · x ≡ x
·-identityˡ x = (λ i → signed (sgn x) (ℕ.+-comm (abs x) 0 i)) ∙ signed-inv x
·-comm : ∀ m n → m · n ≡ n · m
·-comm (pos m) n = cong₂ signed (⊕-comm spos (sgn n)) (ℕ.·-comm m (abs n))
·-comm (negsuc m) n = cong₂ signed (⊕-comm sneg (sgn n)) (ℕ.·-comm (suc m) (abs n))
predInt-neg : ∀ a → predInt (- a) ≡ - (sucInt a)
predInt-neg (pos zero ) = refl
predInt-neg (pos (suc n)) = refl
predInt-neg (negsuc zero ) = refl
predInt-neg (negsuc (suc n)) = refl
sucInt-neg : ∀ a → sucInt (- a) ≡ - (predInt a)
sucInt-neg (pos zero ) = refl
sucInt-neg (pos (suc zero) ) = refl
sucInt-neg (pos (suc (suc n))) = refl
sucInt-neg (negsuc zero ) = refl
sucInt-neg (negsuc (suc n) ) = refl
private
lem : ∀ n → -(0 + n) ≡ 0 - n
lem n i = +-identityˡ (- +-identityˡ n i) (~ i)
negate-+ : ∀ m n → - (m + n) ≡ (- m) + (- n)
negate-+ (pos zero) = lem
negate-+ (pos (suc m)) n = (λ i → - sucInt+ (pos m) n (~ i)) ∙ sym (predInt-neg (pos m + n)) ∙ (λ i → predInt (negate-+ (pos m) n i)) ∙ predInt+ (- pos m) (- n) ∙ λ i → predInt-neg (pos m) i + - n
negate-+ (negsuc zero) n = predInt-inj (- (negsuc zero + n)) (pos 1 + - n) $ predInt-neg (negsuc 0 + n) ∙ (λ i → - sucInt+ (negsuc 0) n i) ∙ lem n ∙ sym (predInt+ (pos 1) (- n))
negate-+ (negsuc (suc m)) n = (λ i → - predInt+ (negsuc m) n (~ i)) ∙ sym (sucInt-neg (negsuc m + n)) ∙ (λ i → sucInt (negate-+ (negsuc m) n i)) ∙ sucInt+ (pos (suc m)) (- n)
negate-·ˡ : ∀ a b → -(a · b) ≡ (- a) · b
negate-·ˡ (pos zero) b = neg-signed-not (sgn b) 0 ∙ signed-zero (not (sgn b)) ∙ sym (signed-zero (sgn b))
negate-·ˡ (pos (suc n)) b = neg-signed-not (sgn b) _
negate-·ˡ (negsuc n) b = neg-signed-not (not (sgn b)) _ ∙ cong₂ signed (notnot (sgn b)) refl
negate-·ʳ : ∀ a b → -(a · b) ≡ a · (- b)
negate-·ʳ a b = (λ i → - ·-comm a b i) ∙ negate-·ˡ b a ∙ ·-comm (- b) a
negsuc+negsuc : ∀ a x → (negsuc a +negsuc x) ≡ negsuc (suc (a +ⁿ x))
negsuc+negsuc a zero = λ i → negsuc $ suc $ ℕ.+-comm 0 a i
negsuc+negsuc a (suc x) = let r = negsuc+negsuc a x in
predInt (negsuc a +negsuc x) ≡⟨ (λ i → predInt (r i)) ⟩
predInt (negsuc (suc (a +ⁿ x))) ≡⟨ refl ⟩
negsuc (suc (suc (a +ⁿ x))) ≡⟨ (λ i → negsuc $ suc $ ℕ.+-suc a x (~ i)) ⟩
negsuc (suc (a +ⁿ suc x)) ∎
signed-distrib : ∀ s m n → signed s (m +ⁿ n) ≡ signed s m + signed s n
signed-distrib s zero n = (sym $ +-identityˡ (signed s n)) ∙ λ i → signed-zero s (~ i) + signed s n
signed-distrib spos (suc m) n = cong sucInt (signed-distrib spos m n) ∙ sucInt+pos n (pos m)
signed-distrib sneg (suc m) zero i = negsuc (ℕ.+-comm m 0 i)
signed-distrib sneg (suc m) (suc n) = (λ i → negsuc (ℕ.+-suc m n i)) ∙ sym (negsuc+negsuc m n)
·-pos-suc : ∀ m n → pos (suc m) · n ≡ n + pos m · n
·-pos-suc m n = signed-distrib (sgn n) (abs n) (m ℕ.· abs n) ∙ λ i → signed-inv n i + signed (sgn n) (m ·ⁿ abs n)
·-negsuc-suc : ∀ m n → negsuc (suc m) · n ≡ - n + negsuc m · n
·-negsuc-suc m n = signed-distrib (not (sgn n)) (abs n) (suc m ℕ.· abs n) ∙ λ i → γ i + negsuc m · n
where γ = sym (neg-signed-not (sgn n) (abs n)) ∙ cong -_ (signed-inv n)
-- this is a similar proof to the one in Cubical.HITs.QuoInt.Properties
-- but we have less definitional equalities
-- ·-assoc : ∀ m n o → m · (n · o) ≡ m · n · o
-- ·-assoc m n o with abs m | signed-inv m
-- ... | zero | pm = {! !}
-- ... | suc mⁿ | pm with abs n | signed-inv n
-- ... | zero | pn = (λ i → signed s₁ (γ₁ i)) ∙ signed-zero s₁ ∙ sym (signed-zero s₂) ∙ (λ i → signed s₂ (γ₂ i)) where
-- s₁ = sgn m ⊕ sgn (signed (sgn n ⊕ sgn o) 0)
-- s₂ = sgn (signed (sgn m ⊕ sgn n) (mⁿ ·ⁿ 0)) ⊕ sgn o
-- γ₁ = suc mⁿ ·ⁿ abs (signed (sgn n ⊕ sgn o) 0) ≡⟨ {! !} ⟩
-- suc mⁿ ·ⁿ 0 ≡⟨ {! !} ⟩
-- 0 ∎
-- γ₂ = 0 ≡⟨ {! !} ⟩
-- 0 ·ⁿ abs o ≡⟨ {! !} ⟩
-- (mⁿ ·ⁿ 0) ·ⁿ abs o ≡⟨ {! !} ⟩
-- abs (signed (sgn m ⊕ sgn n) (mⁿ ·ⁿ 0)) ·ⁿ abs o ∎
-- ... | suc nⁿ | pn with abs o | signed-inv o
-- ... | zero | po = (λ i → signed s₁ (γ₁ i)) ∙ signed-zero s₁ ∙ sym (signed-zero s₂) ∙ (λ i → signed s₂ (γ₂ i)) where
-- s₁ = sgn m ⊕ sgn (signed (sgn n ⊕ sgn o) (nⁿ ·ⁿ zero))
-- s₂ = sgn (signed (sgn m ⊕ sgn n) (suc mⁿ ·ⁿ suc nⁿ)) ⊕ sgn o
-- γ₁ = suc mⁿ ·ⁿ abs (signed (sgn n ⊕ sgn o) (nⁿ ·ⁿ 0)) ≡[ i ]⟨ suc mⁿ ·ⁿ abs-signed (sgn n ⊕ sgn o) (nⁿ ·ⁿ 0) i ⟩
-- suc mⁿ ·ⁿ (nⁿ ·ⁿ 0) ≡[ i ]⟨ suc mⁿ ·ⁿ (ℕ.·-nullifiesʳ nⁿ i) ⟩
-- suc mⁿ ·ⁿ 0 ≡⟨ ℕ.·-nullifiesʳ (suc mⁿ) ⟩
-- 0 ∎
-- γ₂ = 0 ≡⟨ sym $ ℕ.·-nullifiesʳ (abs (signed (sgn m ⊕ sgn n) (suc mⁿ ·ⁿ suc nⁿ))) ⟩
-- abs (signed (sgn m ⊕ sgn n) (suc mⁿ ·ⁿ suc nⁿ)) ·ⁿ 0 ∎
-- ... | suc oⁿ | po = cong₂ signed γ₁ γ₂ where
-- γ₁ = sgn m ⊕ sgn (signed (sgn n ⊕ sgn o) (suc nⁿ ·ⁿ suc oⁿ)) ≡[ i ]⟨ sgn m ⊕ sgn-signed (sgn n ⊕ sgn o) (oⁿ +ⁿ nⁿ ·ⁿ suc oⁿ) i ⟩
-- sgn m ⊕ (sgn n ⊕ sgn o) ≡⟨ ⊕-assoc (sgn m) (sgn n) (sgn o) ⟩
-- (sgn m ⊕ sgn n) ⊕ sgn o ≡[ i ]⟨ sgn-signed (sgn m ⊕ sgn n) (nⁿ +ⁿ mⁿ ·ⁿ suc nⁿ) (~ i) ⊕ sgn o ⟩
-- sgn (signed (sgn m ⊕ sgn n) (suc mⁿ ·ⁿ suc nⁿ)) ⊕ sgn o ∎
-- γ₂ = suc mⁿ ·ⁿ abs (signed (sgn n ⊕ sgn o) (suc nⁿ ·ⁿ suc oⁿ)) ≡[ i ]⟨ suc mⁿ ·ⁿ abs-signed (sgn n ⊕ sgn o) (suc nⁿ ·ⁿ suc oⁿ) i ⟩
-- suc mⁿ ·ⁿ (suc nⁿ ·ⁿ suc oⁿ) ≡⟨ ℕ.·-assoc (suc mⁿ) (suc nⁿ) (suc oⁿ) ⟩
-- (suc mⁿ ·ⁿ suc nⁿ) ·ⁿ suc oⁿ ≡[ i ]⟨ abs-signed (sgn m ⊕ sgn n) (suc mⁿ ·ⁿ suc nⁿ) (~ i) ·ⁿ suc oⁿ ⟩
-- abs (signed (sgn m ⊕ sgn n) (suc mⁿ ·ⁿ suc nⁿ)) ·ⁿ suc oⁿ ∎
private
lemma2 : ∀ a b c → c +ⁿ (b +ⁿ a ·ⁿ suc b) ·ⁿ suc c
≡ (c +ⁿ b ·ⁿ suc c) +ⁿ a ·ⁿ suc (c +ⁿ b ·ⁿ suc c)
lemma2 a b c =
c +ⁿ (b +ⁿ a ·ⁿ suc b) ·ⁿ suc c ≡⟨ (λ i → c +ⁿ ℕ.·-distribʳ b (a ·ⁿ suc b) (suc c) (~ i)) ⟩
c +ⁿ (b ·ⁿ suc c +ⁿ (a ·ⁿ suc b) ·ⁿ suc c) ≡⟨ ℕ.+-assoc c _ _ ⟩
(c +ⁿ b ·ⁿ suc c) +ⁿ (a ·ⁿ suc b) ·ⁿ suc c ≡⟨ (λ i → (c +ⁿ b ·ⁿ suc c) +ⁿ ℕ.·-assoc a (suc b) (suc c) (~ i)) ⟩
(c +ⁿ b ·ⁿ suc c) +ⁿ a ·ⁿ (suc b ·ⁿ suc c) ≡⟨ refl ⟩
(c +ⁿ b ·ⁿ suc c) +ⁿ a ·ⁿ suc (c +ⁿ b ·ⁿ suc c) ∎
-- this is a proof ported from the non-cubical standard library
·-assoc : ∀ x y z → (x · y) · z ≡ x · (y · z)
·-assoc (pos 0) y z = (λ i → ·-nullifiesˡ y i · z) ∙ ·-nullifiesˡ z ∙ sym (·-nullifiesˡ (y · z))
·-assoc x (pos 0) z = (λ i → ·-nullifiesʳ x i · z) ∙ ·-nullifiesˡ z ∙ sym (·-nullifiesʳ x) ∙ (λ i → x · ·-nullifiesˡ z (~ i))
·-assoc x y (pos 0) = ·-nullifiesʳ (x · y) ∙ sym (·-nullifiesʳ x) ∙ (λ i → x · ·-nullifiesʳ y (~ i))
·-assoc (negsuc a ) (negsuc b ) (pos (suc c)) i = (pos (suc (lemma2 a b c i)))
·-assoc (negsuc a ) (pos (suc b)) (negsuc c ) i = (pos (suc (lemma2 a b c i)))
·-assoc (pos (suc a)) (pos (suc b)) (pos (suc c)) i = (pos (suc (lemma2 a b c i)))
·-assoc (pos (suc a)) (negsuc b ) (negsuc c ) i = (pos (suc (lemma2 a b c i)))
·-assoc (negsuc a ) (negsuc b ) (negsuc c ) i = (negsuc (lemma2 a b c i) )
·-assoc (negsuc a ) (pos (suc b)) (pos (suc c)) i = (negsuc (lemma2 a b c i) )
·-assoc (pos (suc a)) (negsuc b ) (pos (suc c)) i = (negsuc (lemma2 a b c i) )
·-assoc (pos (suc a)) (pos (suc b)) (negsuc c ) i = (negsuc (lemma2 a b c i) )
-- this is a similar proof to the one in Cubical.HITs.QuoInt.Properties
·-distribˡ-pos : ∀ o m n → (pos o · m) + (pos o · n) ≡ pos o · (m + n)
·-distribˡ-pos zero m n = (λ i → ·-nullifiesˡ m i + ·-nullifiesˡ n i) ∙ sym (·-nullifiesˡ (m + n))
·-distribˡ-pos (suc o) m n =
pos (suc o) · m + pos (suc o) · n ≡[ i ]⟨ ·-pos-suc o m i + ·-pos-suc o n i ⟩
m + pos o · m + (n + pos o · n) ≡⟨ +-assoc (m + pos o · m) n (pos o · n) ⟩
m + pos o · m + n + pos o · n ≡[ i ]⟨ +-assoc m (pos o · m) n (~ i) + pos o · n ⟩
m + (pos o · m + n) + pos o · n ≡[ i ]⟨ m + +-comm (pos o · m) n i + pos o · n ⟩
m + (n + pos o · m) + pos o · n ≡[ i ]⟨ +-assoc m n (pos o · m) i + pos o · n ⟩
m + n + pos o · m + pos o · n ≡⟨ sym (+-assoc (m + n) (pos o · m) (pos o · n)) ⟩
m + n + (pos o · m + pos o · n) ≡⟨ cong ((m + n) +_) (·-distribˡ-pos o m n) ⟩
m + n + pos o · (m + n) ≡⟨ sym (·-pos-suc o (m + n)) ⟩
pos (suc o) · (m + n) ∎
neg-pos-neg : ∀ x → - pos x ≡ neg x
neg-pos-neg zero = refl
neg-pos-neg (suc x) = refl
·-distribˡ-neg : ∀ o m n → (neg o · m) + (neg o · n) ≡ neg o · (m + n)
·-distribˡ-neg o m n =
neg o · m + neg o · n ≡[ i ]⟨ neg-pos-neg o (~ i) · m + neg-pos-neg o (~ i) · n ⟩
- pos o · m + - pos o · n ≡[ i ]⟨ negate-·ˡ (pos o) m (~ i) + negate-·ˡ (pos o) n (~ i) ⟩
- (pos o · m) + - (pos o · n) ≡⟨ sym (negate-+ (pos o · m) (pos o · n)) ⟩
- (pos o · m + pos o · n) ≡⟨ cong -_ (·-distribˡ-pos o m n) ⟩
- (pos o · (m + n)) ≡⟨ negate-·ˡ (pos o) (m + n) ⟩
- pos o · (m + n) ≡[ i ]⟨ neg-pos-neg o i · (m + n) ⟩
neg o · (m + n) ∎
·-distribˡ : ∀ o m n → (o · m) + (o · n) ≡ o · (m + n)
·-distribˡ (pos o) m n = ·-distribˡ-pos o m n
·-distribˡ (negsuc o) m n = ·-distribˡ-neg (suc o) m n
·-distribʳ : ∀ m n o → (m · o) + (n · o) ≡ (m + n) · o
·-distribʳ m n o = (λ i → ·-comm m o i + ·-comm n o i) ∙ ·-distribˡ o m n ∙ ·-comm o (m + n)
·-neg1 : ∀ x → -1 · x ≡ - x
·-neg1 x = sym (neg-signed-not (sgn x) (abs x +ⁿ 0)) ∙ (λ i → - signed (sgn x) (ℕ.+-comm (abs x) 0 i)) ∙ cong -_ (signed-inv x)
private
possuc+negsuc≡0 : ∀ n → (pos (suc n) +negsuc n) ≡ pos 0
possuc+negsuc≡0 zero = refl
possuc+negsuc≡0 (suc n) = sym ind ∙ possuc+negsuc≡0 n where
ind = pos (suc n) +negsuc n ≡⟨ refl ⟩
predInt (pos (suc (suc n))) +negsuc n ≡⟨ sym $ predInt+negsuc n (pos (suc (suc n))) ⟩
predInt (pos (suc (suc n)) +negsuc n) ∎
sucInt[negsuc+pos]≡0 : ∀ n → sucInt (negsuc n +pos n) ≡ pos 0
sucInt[negsuc+pos]≡0 zero = refl
sucInt[negsuc+pos]≡0 (suc n) = let r = sucInt[negsuc+pos]≡0 n in sym ind ∙ r where
ind = sucInt ( negsuc n +pos n ) ≡⟨ refl ⟩
sucInt (sucInt (negsuc (suc n)) +pos n ) ≡⟨ (λ i → sucInt $ sucInt+pos n (negsuc (suc n)) (~ i)) ⟩
sucInt (sucInt (negsuc (suc n) +pos n)) ∎
+-inverseʳ : ∀ a → a + (- a) ≡ 0
+-inverseʳ (pos zero ) = refl
+-inverseʳ (pos (suc n)) = possuc+negsuc≡0 n
+-inverseʳ (negsuc n ) = sucInt[negsuc+pos]≡0 n
+-inverseˡ : ∀ a → (- a) + a ≡ 0
+-inverseˡ a = +-comm (- a) a ∙ +-inverseʳ a
-- Compose sucPathInt with itself n times. Transporting along this
-- will be addition, transporting with it backwards will be subtraction.
-- Use this to define _+'_ for which is easier to prove
-- isEquiv (λ n → n +' m) since _+'_ is defined by transport
sucPathInt : Int ≡ Int
sucPathInt = ua (sucInt , isoToIsEquiv (iso sucInt predInt sucPred predSuc))
addEq : ℕ → Int ≡ Int
addEq zero = refl
addEq (suc n) = (addEq n) ∙ sucPathInt
predPathInt : Int ≡ Int
predPathInt = ua (predInt , isoToIsEquiv (iso predInt sucInt predSuc sucPred))
subEq : ℕ → Int ≡ Int
subEq zero = refl
subEq (suc n) = (subEq n) ∙ predPathInt
_+'_ : Int → Int → Int
m +' pos n = transport (addEq n) m
m +' negsuc n = transport (subEq (suc n)) m
+'≡+ : _+'_ ≡ _+_
+'≡+ i m (pos zero) = m
+'≡+ i m (pos (suc n)) = sucInt (+'≡+ i m (pos n))
+'≡+ i m (negsuc zero) = predInt m
+'≡+ i m (negsuc (suc n)) = predInt (+'≡+ i m (negsuc n)) --
-- compPath (λ i → (+'≡+ i (predInt m) (negsuc n))) (sym (predInt+negsuc n m)) i
isEquivAddInt' : (m : Int) → isEquiv (λ n → n +' m)
isEquivAddInt' (pos n) = isEquivTransport (addEq n)
isEquivAddInt' (negsuc n) = isEquivTransport (subEq (suc n))
isEquivAddInt : (m : Int) → isEquiv (λ n → n + m)
isEquivAddInt = subst (λ add → (m : Int) → isEquiv (λ n → add n m)) +'≡+ isEquivAddInt'
-- below is an alternate proof of isEquivAddInt for comparison
-- We also have two useful lemma here.
minusPlus : ∀ m n → (n - m) + m ≡ n
minusPlus (pos zero) n = refl
minusPlus (pos 1) = sucPred
minusPlus (pos (suc (suc m))) n =
sucInt ((n +negsuc (suc m)) +pos (suc m)) ≡⟨ sucInt+pos (suc m) _ ⟩
sucInt (n +negsuc (suc m)) +pos (suc m) ≡[ i ]⟨ sucPred (n +negsuc m) i +pos (suc m) ⟩
(n - pos (suc m)) +pos (suc m) ≡⟨ minusPlus (pos (suc m)) n ⟩
n ∎
minusPlus (negsuc zero) = predSuc
minusPlus (negsuc (suc m)) n =
predInt (sucInt (sucInt (n +pos m)) +negsuc m) ≡⟨ predInt+negsuc m _ ⟩
predInt (sucInt (sucInt (n +pos m))) +negsuc m ≡[ i ]⟨ predSuc (sucInt (n +pos m)) i +negsuc m ⟩
sucInt (n +pos m) +negsuc m ≡⟨ minusPlus (negsuc m) n ⟩
n ∎
plusMinus : ∀ m n → (n + m) - m ≡ n
plusMinus (pos zero) n = refl
plusMinus (pos (suc m)) = minusPlus (negsuc m)
plusMinus (negsuc m) = minusPlus (pos (suc m))
private
alternateProof : (m : Int) → isEquiv (λ n → n + m)
alternateProof m = isoToIsEquiv (iso (λ n → n + m)
(λ n → n - m)
(minusPlus m)
(plusMinus m))
<-irrefl : ∀ a → ¬ (a < a)
<-irrefl (pos zero ) = ℕᵒ.<-irrefl 0
<-irrefl (pos (suc n)) = ℕᵒ.<-irrefl (suc n)
<-irrefl (negsuc n ) = ℕᵒ.<-irrefl n
<-trans : ∀ a b c → a < b → b < c → a < c
<-trans (pos a) (pos b) (pos c) a<b b<c = ℕᵒ.<-trans a<b b<c
<-trans (negsuc a) (pos b) (pos c) a<b b<c = tt
<-trans (negsuc a) (negsuc b) (pos c) a<b b<c = tt
<-trans (negsuc a) (negsuc b) (negsuc c) a<b b<c = ℕᵒ.<-trans b<c a<b
<-asym : ∀ a b → a < b → ¬(b < a)
<-asym a b p q = <-irrefl _ (<-trans _ _ _ p q)
private
swap-∥⊎∥ : ∀{ℓ ℓ'} (a : Type ℓ) (b : Type ℓ') → ∥ a ⊎ b ∥ → ∥ b ⊎ a ∥
swap-∥⊎∥ a b = PropTrunc.elim (λ _ → propTruncIsProp) λ{ (inl p) → ∣ inr p ∣ ; (inr p) → ∣ inl p ∣ }
<-cotrans : ∀ a b x → a < b → ∥ (a < x) ⊎ (x < b) ∥
<-cotrans (pos a) (pos b) (pos x) a<b = ℕᵒ.<-cotrans _ _ x a<b
<-cotrans (pos a) (pos b) (negsuc x) a<b = ∣ inr tt ∣
<-cotrans (negsuc a) (pos b) (pos x) a<b = ∣ inl tt ∣
<-cotrans (negsuc a) (pos b) (negsuc x) a<b = ∣ inr tt ∣
<-cotrans (negsuc a) (negsuc b) (pos x) a<b = ∣ inl tt ∣
<-cotrans (negsuc a) (negsuc b) (negsuc x) a<b = swap-∥⊎∥ _ _ (ℕᵒ.<-cotrans _ _ x a<b)
data Trichotomy (m n : Int) : Type₀ where
lt : m < n → Trichotomy m n
eq : m ≡ n → Trichotomy m n
gt : n < m → Trichotomy m n
_≟_ : ∀ m n → Trichotomy m n
pos a ≟ pos b with a ℕᵒ.≟ b
... | ℕᵒ.lt p = lt p
... | ℕᵒ.eq p = eq λ i → pos (p i)
... | ℕᵒ.gt p = gt p
pos a ≟ negsuc b = gt tt
negsuc a ≟ pos b = lt tt
negsuc a ≟ negsuc b with a ℕᵒ.≟ b
... | ℕᵒ.lt p = gt p
... | ℕᵒ.eq p = eq λ i → negsuc (p i)
... | ℕᵒ.gt p = lt p
sucInt-reflects-< : ∀ x y → sucInt x < sucInt y → x < y
sucInt-reflects-< (pos x ) (pos y ) p = ℕᵒ.suc-reflects-< x y p
sucInt-reflects-< (pos x ) (negsuc zero ) p = ℕᵒ.¬-<-zero p
sucInt-reflects-< (negsuc x ) (pos y ) p = tt
sucInt-reflects-< (negsuc zero ) (negsuc zero ) p = p
sucInt-reflects-< (negsuc (suc x)) (negsuc zero ) p = ℕᵒ.zero-<-suc x
sucInt-reflects-< (negsuc (suc x)) (negsuc (suc y)) p = ℕᵒ.suc-preserves-< y x p
predInt-reflects-< : ∀ x y → predInt x < predInt y → x < y
predInt-reflects-< (pos zero ) (pos zero ) p = p
predInt-reflects-< (pos zero ) (pos (suc y)) p = ℕᵒ.zero-<-suc y
predInt-reflects-< (pos (suc x)) (pos (suc y)) p = ℕᵒ.suc-preserves-< x y p
predInt-reflects-< (pos zero ) (negsuc y ) p = ℕᵒ.¬-<-zero p
predInt-reflects-< (negsuc x ) (pos y ) p = tt
predInt-reflects-< (negsuc x ) (negsuc y ) p = ℕᵒ.suc-reflects-< y x p
sucInt-preserves-< : ∀ x y → x < y → sucInt x < sucInt y
sucInt-preserves-< (pos x ) (pos y ) p = ℕᵒ.suc-preserves-< x y p
sucInt-preserves-< (negsuc zero ) (pos y ) p = ℕᵒ.zero-<-suc y
sucInt-preserves-< (negsuc (suc x)) (pos y ) p = tt
sucInt-preserves-< (negsuc zero ) (negsuc zero ) p = p
sucInt-preserves-< (negsuc zero ) (negsuc (suc y)) p = ℕᵒ.¬-<-zero p
sucInt-preserves-< (negsuc (suc x)) (negsuc zero ) p = tt
sucInt-preserves-< (negsuc (suc x)) (negsuc (suc y)) p = ℕᵒ.suc-reflects-< y x p
predInt-preserves-< : ∀ x y → x < y → predInt x < predInt y
predInt-preserves-< (pos zero ) (pos zero ) p = p
predInt-preserves-< (pos zero ) (pos (suc y)) p = tt
predInt-preserves-< (pos (suc x)) (pos zero ) p = ℕᵒ.¬-<-zero p
predInt-preserves-< (pos (suc x)) (pos (suc y)) p = ℕᵒ.suc-reflects-< x y p
predInt-preserves-< (negsuc x ) (pos zero ) p = ℕᵒ.zero-<-suc x
predInt-preserves-< (negsuc x ) (pos (suc y)) p = tt
predInt-preserves-< (negsuc x ) (negsuc y ) p = ℕᵒ.suc-preserves-< y x p
+-preserves-<ʳ : ∀ a b x → a < b → (a + x) < (b + x)
+-preserves-<ʳ a b (pos zero ) a<b = a<b
+-preserves-<ʳ a b (pos (suc n)) a<b = sucInt-preserves-< (a +pos n) (b +pos n) (+-preserves-<ʳ a b (pos n) a<b)
+-preserves-<ʳ a b (negsuc zero ) a<b = predInt-preserves-< a b a<b
+-preserves-<ʳ a b (negsuc (suc n)) a<b = predInt-preserves-< (a +negsuc n) (b +negsuc n) (+-preserves-<ʳ a b (negsuc n) a<b)
+-reflects-<ʳ : ∀ a b x → (a + x) < (b + x) → a < b
+-reflects-<ʳ a b x =
a + x < b + x →⟨ +-preserves-<ʳ (a + x) (b + x) (- x) ⟩
a + x - x < b + x - x →⟨ transp (λ i → +-assoc a x (- x) (~ i) < +-assoc b x (- x) (~ i)) i0 ⟩
a + (x - x) < b + (x - x) →⟨ transp (λ i → (a + +-inverseʳ x i) < (b + +-inverseʳ x i)) i0 ⟩
a + 0 < b + 0 →⟨⟩
a < b ◼
+-reflects-<ˡ : ∀ a b x → (x + a) < (x + b) → a < b
+-reflects-<ˡ a b x p = +-reflects-<ʳ a b x (transport (λ i → +-comm x a i < +-comm x b i) p)
+-<-extensional : ∀ w x y z → (w + x) < (y + z) → ∥ (w < y) ⊎ (x < z) ∥
+-<-extensional w x y z r with w ≟ y | x ≟ z
... | lt w<y | q = ∣ inl w<y ∣
... | eq w≡y | q = ∣ inr $ +-reflects-<ˡ x z y (transport (λ i → (w≡y i + x) < (y + z)) r) ∣
... | gt y<w | q = PropTrunc.elim (λ _ → propTruncIsProp) γ (<-cotrans (w + x) (y + z) (y + x) r)
where γ : _ ⊎ _ → _
γ (inl p) = ∣ inr (⊥.elim {A = λ _ → x < z} (<-asym y w y<w (+-reflects-<ʳ w y x p))) ∣
γ (inr p) = ∣ inr (+-reflects-<ˡ x z y p) ∣
| {
"alphanum_fraction": 0.5229209065,
"avg_line_length": 41.2389758179,
"ext": "agda",
"hexsha": "cb987957c6a6f310a18aebe2450a5bf498d659cc",
"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": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/cubical",
"max_forks_repo_path": "Cubical/Data/Int/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/cubical",
"max_issues_repo_path": "Cubical/Data/Int/Properties.agda",
"max_line_length": 196,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/cubical",
"max_stars_repo_path": "Cubical/Data/Int/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 13410,
"size": 28991
} |
module UniDB.Examples.Lc where
open import UniDB
data Tm (γ : Dom) : Set where
var : (i : Ix γ) → Tm γ
abs : (t : Tm (suc γ)) → Tm γ
app : (t₁ t₂ : Tm γ) → Tm γ
instance
iVrTm : Vr Tm
vr {{iVrTm}} = var
vr-inj {{iVrTm}} refl = refl
iApTm : Ap Tm Tm
ap {{iApTm}} ξ (var i) = lk ξ i
ap {{iApTm}} ξ (abs t) = abs (ap {Tm} (ξ ↑₁) t )
ap {{iApTm}} ξ (app t t₁) = app (ap {Tm} ξ t) (ap {Tm} ξ t₁)
iApVrTm : ApVr Tm
ap-vr {{iApVrTm}} ξ i = refl
iApIdmTm : ApIdm Tm Tm
ap-idm {{iApIdmTm}} {Ξ} (var i) = lk-idm {Tm} {Ξ} i
ap-idm {{iApIdmTm}} {Ξ} (abs t) = cong abs (begin
ap {Tm} (idm {Ξ} _ ↑₁) t ≡⟨ cong₂ (ap {Tm}) (idm-↑₁ {Ξ}) (refl {x = t}) ⟩
ap {Tm} (idm {Ξ} _) t ≡⟨ ap-idm {Tm} t ⟩
t ∎)
ap-idm {{iApIdmTm}} {Ξ} (app t t₁) =
cong₂ app (ap-idm {Tm} t) (ap-idm {Tm} t₁)
iApPairTm : ApPair Tm Tm
ap-pair {{iApPairTm}} ξ ζ (var i) = refl
ap-pair {{iApPairTm}} ξ ζ (abs x) = cong abs (ap-pair {Tm} (ξ ↑₁) (ζ ↑₁) x)
ap-pair {{iApPairTm}} ξ ζ (app x₁ x₂) = cong₂ app (ap-pair {Tm} ξ ζ x₁) (ap-pair {Tm} ξ ζ x₂)
iApRelTm : ApRel Tm Tm
ap-rel≅ {{iApRelTm}} hyp (var i) = lk≃ (≅-to-≃ hyp) i
ap-rel≅ {{iApRelTm}} hyp (abs t) = cong abs (ap-rel≅ {Tm} {Tm} (≅-↑₁ hyp) t)
ap-rel≅ {{iApRelTm}} hyp (app t₁ t₂) = cong₂ app (ap-rel≅ {Tm} {Tm} hyp t₁) (ap-rel≅ {Tm} {Tm} hyp t₂)
postulate
Ρ : MOR
instance
iIdmΡ : Idm Ρ
iWkmΡ : Wkm Ρ
iUpΡ : Up Ρ
iUpIdmΡ : UpIdm Ρ
iCompΡ : Comp Ρ
iWkmHomΡ : WkmHom Ρ
iLkΡ : {T : STX} {{vrT : Vr T}} → Lk T Ρ
iLkIdmΡ : {T : STX} {{vrT : Vr T}} → LkIdm T Ρ
iLkWkmΡ : {T : STX} {{vrT : Vr T}} → LkWkm T Ρ
iLkCompAp : {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} → LkCompAp T Ρ
iLkUpΡ : {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} → LkUp T Ρ
iLkRenΡ : {T : STX} {{vrT : Vr T}} → LkRen T Ρ
instance
iWkTm : Wk Tm
wk₁ {{iWkTm}} = ap {Tm} (wkm {Ρ} 1)
wk {{iWkTm}} δ t = ap {Tm} (wkm {Ρ} δ) t
wk-zero {{iWkTm}} t = begin
ap {Tm} (wkm {Ρ} 0) t ≡⟨ ap-rel≅ {Tm} (Ix≅-to-≅ {Tm} (≃-to-≅` (≃-↑ {Ix} (record { lk≃ = λ i → begin
lk (wkm {Ρ} 0) i ≡⟨ lk-wkm {Ix} {Ρ} 0 i ⟩
i ≡⟨ sym (lk-idm {Ix} {Ρ} i) ⟩
lk (idm {Ρ} _) i ∎
})))) t ⟩
ap {Tm} (idm {Ρ} _) t ≡⟨ ap-idm {Tm} {Tm} {Ρ} t ⟩
t ∎
wk-suc {{iWkTm}} δ t = begin
ap {Tm} (wkm {Ρ} (suc δ)) t ≡⟨ cong (λ ζ → ap {Tm} {Tm} {Ρ} ζ t) (wkm-suc {Ρ} δ) ⟩
ap {Tm} (wkm {Ρ} δ ⊙ wkm {Ρ} 1) t ≡⟨ ap-rel≅ {Tm} (Ix≅-to-≅ {Tm} {Ρ} {Pair Ρ Ρ} (≃-to-≅`
(≃-↑ {Ix} {Ρ} {Pair Ρ Ρ} {ξ = wkm {Ρ} δ ⊙ wkm {Ρ} 1} {wkm {Ρ} δ ⊗ wkm {Ρ} 1} (record { lk≃ =
lk-⊙-ap {Ix} {Ρ} (wkm {Ρ} δ) (wkm {Ρ} 1) })))) t ⟩
ap {Tm} (wkm {Ρ} δ ⊗ wkm {Ρ} 1) t ≡⟨ ap-pair {Tm} (wkm {Ρ} δ) (wkm {Ρ} 1) t ⟩
ap {Tm} (wkm {Ρ} 1) (ap {Tm} (wkm {Ρ} δ) t) ∎
instance
iWkVrTm : WkVr Tm
wk₁-vr {{iWkVrTm}} i = lk-wkm {Tm} {Ρ} 1 i
wk-vr {{iWkVrTm}} δ i = lk-wkm {Tm} {Ρ} δ i
iApWkmWkTm : ApWkmWk Tm Tm
ap-wkm-wk₁ {{iApWkmWkTm}} {Ξ} = ap-wkm-rel Tm Tm Ξ Ρ 1
ap-wkm-wk {{iApWkmWkTm}} {Ξ} = ap-wkm-rel Tm Tm Ξ Ρ
-- iApCompTm : ApComp Tm Tm
-- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (var i) = lk-⊙-ap {Tm} {Ξ} ξ₁ ξ₂ i
-- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (abs t) rewrite ⊙-↑₁ {Ξ} ξ₁ ξ₂ =
-- cong abs (ap-⊙ {Tm} (ξ₁ ↑₁) (ξ₂ ↑₁) t)
-- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (app t₁ t₂) =
-- cong₂ app (ap-⊙ {Tm} {Tm} {Ξ} ξ₁ ξ₂ t₁) (ap-⊙ {Tm} {Tm} {Ξ} ξ₁ ξ₂ t₂)
iApCompTm : ApComp Tm Tm
iApCompTm = iApComp Tm Tm
iApWkTm : ApWk Tm Tm
iApWkTm = iApWk Tm Tm
{-}
--------------------------------------------------------------------------------
subTm : {X : STX} {{apTmX : Ap Tm X}} {γ : Dom} (s : Tm γ) (x : X (suc γ)) → X γ
subTm {X} s x = ap Tm X (Sub Tm) (beta Tm (Sub Tm) s) x
data Eval {γ : Dom} : Tm γ → Tm γ → Set where
e-app₁ : {t₁ t₁' t₂ : Tm γ} → Eval t₁ t₁' → Eval (app t₁ t₂) (app t₁' t₂)
e-app₂ : {t₁ t₂ t₂' : Tm γ} → Eval t₂ t₂' → Eval (app t₁ t₂) (app t₁ t₂')
e-abs : {t t' : Tm (suc γ)} → Eval t t' → Eval (abs t) (abs t')
e-beta : {s : Tm γ} {t : Tm (suc γ)} → Eval (app (abs t) s) (subTm s t)
--------------------------------------------------------------------------------
-}
| {
"alphanum_fraction": 0.4568277804,
"avg_line_length": 36.1186440678,
"ext": "agda",
"hexsha": "2ec5319c219b37239858cb674a90d7ba70c190fc",
"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": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Examples/Lc.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"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": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Examples/Lc.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Examples/Lc.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2406,
"size": 4262
} |
-- Andreas, 2018-10-18, re #2757
-- Runtime-irrelevance analogue to issue #2640
-- {-# OPTIONS -v tc.lhs.unify:65 #-}
-- {-# OPTIONS -v tc.irr:20 #-}
-- {-# OPTIONS -v tc:30 #-}
-- {-# OPTIONS -v treeless:20 #-}
open import Common.Prelude
data D : (n : Nat) → Set where
c : (m : Nat) → D m
test : (@0 n : Nat) → D n → Nat
test n (c m) = m
-- Should be rejected (projecting a forced argument).
main = printNat (test 142 (c _))
-- The generated Haskell program segfaults.
| {
"alphanum_fraction": 0.6033402923,
"avg_line_length": 21.7727272727,
"ext": "agda",
"hexsha": "6077f98b274d7bda9712325bdcd85c24da150fbe",
"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/Compiler/simple/Erasure-Issue2640.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/Compiler/simple/Erasure-Issue2640.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": "test/Compiler/simple/Erasure-Issue2640.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": 161,
"size": 479
} |
-- Fast exponentiation
module Numeric.Nat.Pow where
open import Prelude
open import Numeric.Nat.DivMod
open import Control.WellFounded
open import Tactic.Nat
open import Tactic.Cong
module _ {a} {A : Set a} {{_ : Semiring A}} where
private
expAcc : A → (n : Nat) → Acc _<_ n → A
expAcc a zero wf = one
expAcc a (suc n) (acc wf) with n divmod 2
... | qr q 0 _ eq = force (a * a) λ a² → expAcc a² q (wf q (by eq)) * a
... | qr q 1 _ eq = force (a * a) λ a² → expAcc a² (suc q) (wf (suc q) (by eq))
... | qr q (suc (suc _)) lt _ = refute lt
infixr 8 _^′_
_^′_ : A → Nat → A
a ^′ n = expAcc a n (wfNat n)
module _ (assoc : (a b c : A) → a * (b * c) ≡ (a * b) * c)
(idr : (a : A) → a * one ≡ a)
(idl : (a : A) → one * a ≡ a) where
private
force-eq : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) {f : ∀ x → B x} {y : B x} →
f x ≡ y → force x f ≡ y
force-eq x eq = forceLemma x _ ⟨≡⟩ eq
on-assoc-l : {a b c a₁ b₁ c₁ : A} → (a * b) * c ≡ (a₁ * b₁) * c₁ → a * (b * c) ≡ a₁ * (b₁ * c₁)
on-assoc-l eq = assoc _ _ _ ⟨≡⟩ eq ⟨≡⟩ʳ assoc _ _ _
on-assoc-r : {a b c a₁ b₁ c₁ : A} → a * (b * c) ≡ a₁ * (b₁ * c₁) → (a * b) * c ≡ (a₁ * b₁) * c₁
on-assoc-r eq = assoc _ _ _ ʳ⟨≡⟩ eq ⟨≡⟩ assoc _ _ _
lem-pow-mul-l : (a : A) (n : Nat) → a * a ^ n ≡ a ^ n * a
lem-pow-mul-l a zero = idr _ ⟨≡⟩ʳ idl _
lem-pow-mul-l a (suc n) = assoc _ _ _ ⟨≡⟩ (_* a) $≡ lem-pow-mul-l a n
lem-pow-mul-distr : (a : A) (n : Nat) → (a * a) ^ n ≡ a ^ n * a ^ n
lem-pow-mul-distr a zero = sym (idl _)
lem-pow-mul-distr a (suc n) =
(_* (a * a)) $≡ lem-pow-mul-distr a n ⟨≡⟩ʳ
on-assoc-r (((a ^ n) *_) $≡ (on-assoc-l ((_* a) $≡ lem-pow-mul-l a n)))
lem-pow-add-distr : (a : A) (n m : Nat) → a ^ (n + m) ≡ a ^ n * a ^ m
lem-pow-add-distr a zero m = sym (idl _)
lem-pow-add-distr a (suc n) m =
(_* a) $≡ lem-pow-add-distr a n m ⟨≡⟩ʳ
on-assoc-r (((a ^ n) *_) $≡ lem-pow-mul-l a m)
lem : ∀ a n (wf : Acc _<_ n) → expAcc a n wf ≡ a ^ n
lem a zero wf = refl
lem a (suc n) (acc wf) with n divmod 2
lem a (suc ._) (acc wf) | qr q 0 _ refl =
force-eq (a * a) (cong (_* a) (
lem (a * a) q (wf q (diff _ auto)) ⟨≡⟩
lem-pow-mul-distr a q ⟨≡⟩
lem-pow-add-distr a q q ʳ⟨≡⟩
cong (_^_ a) {x = q + q} {y = q * 2 + 0} auto))
lem a (suc ._) (acc wf) | qr q 1 _ refl =
force-eq (a * a) $
lem (a * a) (suc q) (wf (suc q) (diff _ auto)) ⟨≡⟩
(a * a) ^ q * (a * a)
≡⟨ by-cong (lem-pow-mul-distr a q ⟨≡⟩ʳ lem-pow-add-distr a q q) ⟩
a ^ (q + q) * (a * a)
≡⟨ by-cong {x = q + q} {y = q * 2} auto ⟩
a ^ (q * 2) * (a * a)
≡⟨ by-cong (idl a) ⟩
a ^ (q * 2) * (a ^ 1 * a)
≡⟨ assoc _ _ _ ⟩
a ^ (q * 2) * a ^ 1 * a
≡⟨ by-cong (lem-pow-add-distr a (q * 2) 1) ⟩
a ^ (q * 2 + 1) * a ∎
... | qr _ (suc (suc _)) lt _ = refute lt
lem-^′-sound : ∀ a n → a ^′ n ≡ a ^ n
lem-^′-sound a n = lem a n (wfNat n)
{-# DISPLAY expAcc a n _ = a ^′ n #-}
| {
"alphanum_fraction": 0.4286602425,
"avg_line_length": 37.8470588235,
"ext": "agda",
"hexsha": "f84046363ac562c485aa605a95989b88df0e4a43",
"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/Numeric/Nat/Pow.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/Numeric/Nat/Pow.agda",
"max_line_length": 101,
"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/Numeric/Nat/Pow.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": 1437,
"size": 3217
} |
module BTree.Complete.Alternative.Correctness {A : Set} where
open import BTree {A}
open import BTree.Equality {A}
open import BTree.Equality.Properties {A}
open import BTree.Complete.Base {A}
open import BTree.Complete.Base.Properties {A}
open import BTree.Complete.Alternative {A} renaming (Complete to Complete' ; _⋘_ to _⋘'_ ; _⋙_ to _⋙'_ ; _⋗_ to _⋗'_)
open import Data.Sum renaming (_⊎_ to _∨_)
lemma-⋗'-⋗ : {l r : BTree} → l ⋗' r → l ⋗ r
lemma-⋗'-⋗ (⋗lf x) = ⋗lf x
lemma-⋗'-⋗ (⋗nd {r = r} {l' = l'} x x' _ l'≃r' l⋗'l') = ⋗nd x x' r l' (lemma-⋗-≃ (lemma-⋗'-⋗ l⋗'l') l'≃r')
lemma-⋙'-⋗ : {l r : BTree} → l ⋙' r → l ⋗ r
lemma-⋙'-⋗ (⋙lf x) = ⋗lf x
lemma-⋙'-⋗ (⋙rl {r = r} {l' = l'} x x' l≃r l'⋘'r' l⋗'r') = ⋗nd x x' r l' (lemma-⋗'-⋗ l⋗'r')
lemma-⋙'-⋗ (⋙rr {r = r} {l' = l'} x x' l≃r l'⋙'r' l≃l') = ⋗nd x x' r l' (lemma-≃-⋗ l≃l' (lemma-⋙'-⋗ l'⋙'r'))
lemma-⋘'-⋗ : {l r : BTree} → l ⋘' r → l ≃ r ∨ l ⋗ r
lemma-⋘'-⋗ lf⋘ = inj₁ ≃lf
lemma-⋘'-⋗ (ll⋘ {r = r} {l' = l'} x x' l⋘'r l'≃r' r≃l')
with lemma-⋘'-⋗ l⋘'r
... | inj₁ l≃r = inj₁ (≃nd x x' l≃r (trans≃ l≃r r≃l') l'≃r')
... | inj₂ l⋗r = inj₂ (⋗nd x x' r l' (lemma-⋗-≃ l⋗r (trans≃ r≃l' l'≃r')))
lemma-⋘'-⋗ (lr⋘ {r = r} {l' = l'} x x' _ l'≃r' l⋗'l') = inj₂ (⋗nd x x' r l' (lemma-⋗-≃ (lemma-⋗'-⋗ l⋗'l') l'≃r'))
lemma-⋘'-⋘ : {l r : BTree} → l ⋘' r → l ⋘ r
lemma-⋘'-⋘ lf⋘ = eq⋘ ≃lf
lemma-⋘'-⋘ (ll⋘ {r = r} {l' = l'} x x' l⋘'r l'≃r' r≃l')
with lemma-⋘'-⋗ l⋘'r
... | inj₁ l≃r = eq⋘ (≃nd x x' l≃r (trans≃ l≃r r≃l') l'≃r')
... | inj₂ l⋗r = gt⋘ (np⋗ x l⋗r) (p≃ x' l'≃r') (⋗nd x x' r l' (lemma-⋗-≃ l⋗r (trans≃ r≃l' l'≃r')))
lemma-⋘'-⋘ (lr⋘ {r = r} {l' = l'} x x' l⋙'r l'≃r' l⋗'l') = gt⋘ (np⋗ x (lemma-⋙'-⋗ l⋙'r)) (p≃ x' l'≃r') (⋗nd x x' r l' (lemma-⋗-≃ (lemma-⋗'-⋗ l⋗'l') l'≃r'))
lemma-⋙'-⋙ : {l r : BTree} → l ⋙' r → l ⋙ r
lemma-⋙'-⋙ l⋙'r = ⋙gt (lemma-⋙'-⋗ l⋙'r)
lemma-complete'-complete : {t : BTree} → Complete' t → Complete t
lemma-complete'-complete leaf = leaf
lemma-complete'-complete (left x c'l c'r l⋘'r) = left x (lemma-complete'-complete c'l) (lemma-complete'-complete c'r) (lemma-⋘'-⋘ l⋘'r)
lemma-complete'-complete (right x c'l c'r l⋙'r) = right x (lemma-complete'-complete c'l) (lemma-complete'-complete c'r) (lemma-⋙'-⋙ l⋙'r)
| {
"alphanum_fraction": 0.493877551,
"avg_line_length": 50.1136363636,
"ext": "agda",
"hexsha": "70fceb0ed30faadb49c88849c54b6dcbc1b8b6a8",
"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/BTree/Complete/Alternative/Correctness.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/BTree/Complete/Alternative/Correctness.agda",
"max_line_length": 155,
"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/BTree/Complete/Alternative/Correctness.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": 1363,
"size": 2205
} |
import Bundles
import Construct.DirectProduct
import Definitions
import Definitions.Semiring
import Morphism.Structures
import Properties.RingWithoutOne
import Structures
| {
"alphanum_fraction": 0.8947368421,
"avg_line_length": 21.375,
"ext": "agda",
"hexsha": "cc65c54f81945e68c6df42ea1f3c4b08c7795669",
"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": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/Agda-Algebra",
"max_forks_repo_path": "Everything.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_issues_repo_issues_event_max_datetime": "2022-01-31T18:19:52.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-02T20:50:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/Agda-Algebra",
"max_issues_repo_path": "Everything.agda",
"max_line_length": 32,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/Agda-Algebra",
"max_stars_repo_path": "Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 34,
"size": 171
} |
{-# OPTIONS --show-irrelevant #-}
-- {-# OPTIONS -v tc:20 #-}
open import Agda.Primitive
open import Issue2408.LevelDependentOnIrrelevant
-- Provoke error message mentioning (ℓ a)
provokeError : Set₁
provokeError = X
where
X = _
F' : (a : A) → X
F' = F
-- If #2408 is solved by replacing irrelevant vars in levels by Prop,
-- we get a horrible error like:
--
-- Set (.Agda.Primitive.lsuc (l .(Prop))) != Set₁
-- when checking that the expression X has type Set₁
-- Expected error:
-- Set (lsuc (l a)) != Set₁
-- when checking that the expression F has type A → X
| {
"alphanum_fraction": 0.6626506024,
"avg_line_length": 22.3461538462,
"ext": "agda",
"hexsha": "17f1344cda3ab153511f7fe110b62359b1db015a",
"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/Fail/Issue2408-error.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue2408-error.agda",
"max_line_length": 69,
"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/Fail/Issue2408-error.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": 174,
"size": 581
} |
module HasSalvation where
open import OscarPrelude
record HasSalvation (A : Set) : Set₁
where
field
▷_ : A → Set
open HasSalvation ⦃ … ⦄ public
{-# DISPLAY HasSalvation.▷_ _ = ▷_ #-}
record HasDecidableSalvation (A : Set) : Set₁
where
field
⦃ hasSalvation ⦄ : HasSalvation A
▷?_ : (x : A) → Dec $ ▷ x
open HasDecidableSalvation ⦃ … ⦄ public
{-# DISPLAY HasDecidableSalvation.▷?_ _ = ▷?_ #-}
| {
"alphanum_fraction": 0.6450839329,
"avg_line_length": 17.375,
"ext": "agda",
"hexsha": "7bc3efcd9c991a081b3634df073078b220759a3e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/HasSalvation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/HasSalvation.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/HasSalvation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 156,
"size": 417
} |
-- Andreas, 2014-04-23 test case by Andrea Vezzosi
{-# OPTIONS --sized-types --copatterns #-}
-- {-# OPTIONS --show-implicit -v term:60 #-}
module _ where
open import Common.Size
-- Invalid coinductive record, since not recursive.
record ▸ (A : Size → Set) (i : Size) : Set where
coinductive -- This should be an error, since non-recursive.
constructor delay_
field
force : ∀ {j : Size< i} → A j
open ▸
-- This fixed-point combinator should not pass the termination checker.
∞fix : ∀ {A : Size → Set} → (∀ {i} → ▸ A i → A i) → ∀ {i} → ▸ A i
force (∞fix {A} f {i}) {j} = f {j} (∞fix {A} f {j})
-- The following fixed-point combinator is not strongly normalizing!
fix : ∀ {A : Size → Set} → (∀ {i} → (∀ {j : Size< i} → A j) → A i) → ∀ {i} {j : Size< i} → A j
fix f = force (∞fix (λ {i} x → f {i} (force x)))
-- test = fix {!!}
-- C-c C-n test gives me a stack overflow
| {
"alphanum_fraction": 0.5836139169,
"avg_line_length": 33,
"ext": "agda",
"hexsha": "2589fee08031b16c8d90138779e17d0a34a4a4cd",
"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/Bugs/NonRecursiveCoinductiveRecord.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/Bugs/NonRecursiveCoinductiveRecord.agda",
"max_line_length": 94,
"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/Bugs/NonRecursiveCoinductiveRecord.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": 309,
"size": 891
} |
{-# OPTIONS --allow-unsolved-metas #-}
module _ where
open import Agda.Builtin.Equality
module Case₀ where
postulate
I : Set
P : I → Set
variable
p : P _
postulate
D : P _ → Set
d : D p
module Case₁ where
postulate
I : Set
P : I → Set
Q : ∀ n → P n → Set
variable
q : Q _ _
postulate
D : ∀ {p} → Q _ p → Set
d : D q
module Case₂ where
postulate
I : Set
P : I → Set
Q : ∀ n → P n → Set
record R n (p : P n) : Set where
constructor c
field
f : Q _ p
variable
q : Q _ _
data D {p} : R _ p → Set where
d : D (c q)
module Case₃ where
variable
A : Set
a : A
record B : Set where
id = λ x → x ≡ x
field
b : id a
| {
"alphanum_fraction": 0.5040214477,
"avg_line_length": 12.2295081967,
"ext": "agda",
"hexsha": "192c5246872183b9704ff61b8df89584db7b730c",
"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/Issue3390.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/Issue3390.agda",
"max_line_length": 38,
"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/Issue3390.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": 272,
"size": 746
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra using (Monoid)
module Data.FingerTree.MonoidSolver {ℓ₁ ℓ₂} (mon : Monoid ℓ₁ ℓ₂) where
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.List as List using (List; _∷_; []; foldr; _++_)
open import Data.Vec as Vec using (Vec; _∷_; [])
open import Data.Fin as Fin using (Fin)
open import Data.String as String using (String)
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Relation.Nullary using (Dec; yes; no)
open import Data.Unit using (⊤; tt)
open import Relation.Binary using (Setoid)
open import Function
open import Reflection
open import Agda.Builtin.Reflection
open Monoid mon
data Expr : Set ℓ₁ where
K : Carrier → Expr
_⊕_ : Expr → Expr → Expr
E : Expr
⟦_⟧ : Expr → Carrier
⟦ K x ⟧ = x
⟦ x ⊕ y ⟧ = ⟦ x ⟧ ∙ ⟦ y ⟧
⟦ E ⟧ = ε
Normal : Set ℓ₁
Normal = List Carrier
norm : Expr → Normal
norm (K x) = x ∷ []
norm (x ⊕ y) = norm x ++ norm y
norm E = []
⟦_,_⟧⁺⇓ : Carrier → Normal → Carrier
⟦ x , [] ⟧⁺⇓ = x
⟦ x₁ , x₂ ∷ xs ⟧⁺⇓ = x₁ ∙ ⟦ x₂ , xs ⟧⁺⇓
⟦_⟧⇓ : Normal → Carrier
⟦ [] ⟧⇓ = ε
⟦ x ∷ xs ⟧⇓ = ⟦ x , xs ⟧⁺⇓
++-homo : (xs ys : Normal) → ⟦ xs ++ ys ⟧⇓ ≈ ⟦ xs ⟧⇓ ∙ ⟦ ys ⟧⇓
++-homo [] ys = sym (identityˡ ⟦ ys ⟧⇓)
++-homo (x ∷ xs) ys = go x xs ys
where
go : ∀ x xs ys → ⟦ x , xs ++ ys ⟧⁺⇓ ≈ ⟦ x , xs ⟧⁺⇓ ∙ ⟦ ys ⟧⇓
go x [] [] = sym (identityʳ x)
go x [] (y ∷ ys) = refl
go x₁ (x₂ ∷ xs) ys = ∙-cong refl (go x₂ xs ys) ⟨ trans ⟩ sym (assoc _ _ _)
open import Data.FingerTree.Relation.Binary.Reasoning.FasterInference.Setoid setoid
correct : (e : Expr) → ⟦ norm e ⟧⇓ ≈ ⟦ e ⟧
correct (K x) = refl
correct (x ⊕ y) = ++-homo (norm x) (norm y) ⟨ trans ⟩ (correct x ⟨ ∙-cong ⟩ correct y )
correct E = refl
infixr 5 _⟨∷⟩_ _⟅∷⟆_
pattern _⟨∷⟩_ x xs = arg (arg-info visible relevant) x ∷ xs
pattern _⟅∷⟆_ x xs = arg (arg-info hidden relevant) x ∷ xs
mutual
E₂ : List (Arg Term) → Term
E₂ (x ⟨∷⟩ y ⟨∷⟩ []) = quote _⊕_ ⟨ con ⟩ E′ x ⟨∷⟩ E′ y ⟨∷⟩ []
E₂ (x ∷ xs) = E₂ xs
E₂ _ = unknown
E′ : Term → Term
E′ (def (quote Monoid._∙_) xs) = E₂ xs
E′ (def (quote Monoid.ε) _) = quote E ⟨ con ⟩ []
E′ t = quote K ⟨ con ⟩ (t ⟨∷⟩ [])
getVisible : Arg Term → Maybe Term
getVisible (arg (arg-info visible relevant) x) = just x
getVisible (arg (arg-info visible irrelevant) x) = nothing
getVisible (arg (arg-info hidden r) x) = nothing
getVisible (arg (arg-info instance′ r) x) = nothing
getArgs : ∀ n → Term → Maybe (Vec Term n)
getArgs n (def _ xs) = Maybe.map Vec.reverse (List.foldl f b (List.mapMaybe getVisible xs) n)
where
f : (∀ n → Maybe (Vec Term n)) → Term → ∀ n → Maybe (Vec Term n)
f xs x zero = just Vec.[]
f xs x (suc n) = Maybe.map (x Vec.∷_) (xs n)
b : ∀ n → Maybe (Vec Term n)
b zero = just Vec.[]
b (suc _ ) = nothing
getArgs _ _ = nothing
infixr 5 _⋯⟅∷⟆_
_⋯⟅∷⟆_ : ℕ → List (Arg Term) → List (Arg Term)
zero ⋯⟅∷⟆ xs = xs
suc i ⋯⟅∷⟆ xs = unknown ⟅∷⟆ i ⋯⟅∷⟆ xs
constructSoln : Term → Term → Term → Term
constructSoln mon lhs rhs =
quote Monoid.trans ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩
(quote Monoid.sym ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩ (quote correct ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩ E′ lhs ⟨∷⟩ []) ⟨∷⟩ [])
⟨∷⟩
(quote correct ⟨ def ⟩ 2 ⋯⟅∷⟆ mon ⟨∷⟩ E′ rhs ⟨∷⟩ []) ⟨∷⟩
[]
_>>=_ : ∀ {a b} {A : Set a} {B : Set b} → TC A → (A → TC B) → TC B
_>>=_ = bindTC
_>>_ : ∀ {a b} {A : Set a} {B : Set b} → TC A → TC B → TC B
xs >> ys = xs >>= λ _ → ys
solve-macro : Term → Term → TC ⊤
solve-macro mon hole = do
hole′ ← inferType hole >>= normalise
just (lhs ∷ rhs ∷ []) ← returnTC (getArgs 2 hole′)
where nothing → typeError (termErr hole′ ∷ [])
let soln = constructSoln mon lhs rhs
unify hole soln
| {
"alphanum_fraction": 0.5700164745,
"avg_line_length": 29.136,
"ext": "agda",
"hexsha": "a7b3714e63ef321d2a1f69be5c093cf3ab69cb92",
"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": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-indexed-fingertree",
"max_forks_repo_path": "src/Data/FingerTree/MonoidSolver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-indexed-fingertree",
"max_issues_repo_path": "src/Data/FingerTree/MonoidSolver.agda",
"max_line_length": 105,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-indexed-fingertree",
"max_stars_repo_path": "src/Data/FingerTree/MonoidSolver.agda",
"max_stars_repo_stars_event_max_datetime": "2019-02-26T07:04:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-26T07:04:54.000Z",
"num_tokens": 1561,
"size": 3642
} |
{-# OPTIONS --cubical --safe #-}
module Data.Pi where
open import Data.Pi.Base public
| {
"alphanum_fraction": 0.6931818182,
"avg_line_length": 14.6666666667,
"ext": "agda",
"hexsha": "12457290036376d25e45faa2b1952ab9a96c4573",
"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/Data/Pi.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/Data/Pi.agda",
"max_line_length": 32,
"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/Data/Pi.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": 23,
"size": 88
} |
------------------------------------------------------------------------------
-- The Agda standard library
--
-- Additional properties for setoids
------------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Properties.Setoid {a ℓ} (S : Setoid a ℓ) where
open Setoid S
open import Data.Product using (_,_)
open import Function using (_∘_; _$_)
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------------
-- Every setoid is a preorder with respect to propositional equality
isPreorder : IsPreorder _≡_ _≈_
isPreorder = record
{ isEquivalence = P.isEquivalence
; reflexive = reflexive
; trans = trans
}
preorder : Preorder a a ℓ
preorder = record
{ isPreorder = isPreorder
}
------------------------------------------------------------------------------
-- Properties of _≉_
≉-sym : Symmetric _≉_
≉-sym x≉y = x≉y ∘ sym
≉-respˡ : _≉_ Respectsˡ _≈_
≉-respˡ x≈x' x≉y = x≉y ∘ trans x≈x'
≉-respʳ : _≉_ Respectsʳ _≈_
≉-respʳ y≈y' x≉y x≈y' = x≉y $ trans x≈y' (sym y≈y')
≉-resp₂ : _≉_ Respects₂ _≈_
≉-resp₂ = ≉-respʳ , ≉-respˡ
| {
"alphanum_fraction": 0.5073815074,
"avg_line_length": 26.2653061224,
"ext": "agda",
"hexsha": "2559f8a8531292cf40ed92db99769aa32f1f182d",
"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/Relation/Binary/Properties/Setoid.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/Relation/Binary/Properties/Setoid.agda",
"max_line_length": 78,
"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/Relation/Binary/Properties/Setoid.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": 377,
"size": 1287
} |
module cedille-options where
open import general-util
open import options-types public
open import cedille-types
record options : Set where
constructor mk-options
field include-path : 𝕃 string × stringset
use-cede-files : 𝔹
make-rkt-files : 𝔹
generate-logs : 𝔹
show-qualified-vars : 𝔹
erase-types : 𝔹
datatype-encoding : maybe (filepath × maybe file)
pretty-print-columns : ℕ
-- Internal use only
during-elaboration : 𝔹
pretty-print : 𝔹
show-progress-updates : 𝔹
default-options : options
default-options = record {
include-path = [] , empty-stringset;
use-cede-files = tt;
make-rkt-files = ff;
generate-logs = ff;
show-qualified-vars = ff;
erase-types = tt;
datatype-encoding = nothing;
pretty-print-columns = 80;
during-elaboration = ff;
pretty-print = ff ;
show-progress-updates = ff}
include-path-insert : string → 𝕃 string × stringset → 𝕃 string × stringset
include-path-insert s (l , ss) =
if stringset-contains ss s
then l , ss
else s :: l , stringset-insert ss s
options-to-rope : options → rope
options-to-rope ops =
comment "Cedille Options File" ⊹⊹ [[ "\n" ]] ⊹⊹
comment "List of directories to search for imported files in" ⊹⊹
comment "Each directory should be space-delimited and inside double quotes" ⊹⊹
comment "The current file's directory is automatically searched first, before import-directories" ⊹⊹
comment "If a filepath is relative, it is considered relative to this options file" ⊹⊹
option "import-directories"
(𝕃-to-string (λ fp → "\"" ^ fp ^ "\"") " " (fst (options.include-path ops))) ⊹⊹
comment "Cache navigation spans for performance" ⊹⊹
option "use-cede-files" (𝔹-s options.use-cede-files) ⊹⊹
-- comment "Compile Cedille files to Racket after they are checked"⊹⊹
-- option "make-rkt-files" (𝔹-s options.make-rkt-files) ⊹⊹
comment "Write logs to ~/.cedille/log" ⊹⊹
option "generate-logs" (𝔹-s options.generate-logs) ⊹⊹
comment "Print variables fully qualified" ⊹⊹
option "show-qualified-vars" (𝔹-s options.show-qualified-vars) ⊹⊹
comment "Print types erased" ⊹⊹
option "erase-types" (𝔹-s options.erase-types) ⊹⊹
comment "Preferred number of columns to pretty print elaborated files with" ⊹⊹
option "pretty-print-columns" (ℕ-to-string (options.pretty-print-columns ops)) ⊹⊹
comment "Encoding to use when elaborating datatypes to Cedille Core" ⊹⊹
option "datatype-encoding" (maybe-else' (options.datatype-encoding ops) "" λ fp → "\"" ^ fst fp ^ "\"")
where
𝔹-s : (options → 𝔹) → string
𝔹-s f = if f ops then "true" else "false"
comment : string → rope
comment s = [[ "-- " ]] ⊹⊹ [[ s ]] ⊹⊹ [[ "\n" ]]
option : (name : string) → (value : string) → rope
option name value = [[ name ]] ⊹⊹ [[ " = " ]] ⊹⊹ [[ value ]] ⊹⊹ [[ ".\n\n" ]]
| {
"alphanum_fraction": 0.6568317527,
"avg_line_length": 37.96,
"ext": "agda",
"hexsha": "2edcbecd537dea0c8536015ce14f5cebf75614a0",
"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": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ice1k/cedille",
"max_forks_repo_path": "src/cedille-options.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"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": "ice1k/cedille",
"max_issues_repo_path": "src/cedille-options.agda",
"max_line_length": 106,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ice1k/cedille",
"max_stars_repo_path": "src/cedille-options.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 899,
"size": 2847
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Duality where
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Category
open import Categories.Category.Construction.Cones as Con
open import Categories.Category.Construction.Cocones as Coc
open import Categories.Functor
open import Categories.Functor.Continuous
open import Categories.Functor.Cocontinuous
open import Categories.Diagram.Limit as Lim
open import Categories.Diagram.Colimit as Col
open import Categories.Diagram.Duality
open import Categories.Morphism.Duality as MorD
private
variable
o ℓ e : Level
C D E J : Category o ℓ e
module _ (G : Functor C D) {J : Category o ℓ e} where
private
module C = Category C
module D = Category D
module G = Functor G
module J = Category J
coLimitPreserving⇒ColimitPreserving : ∀ {F : Functor J C} (L : Limit (Functor.op F)) →
LimitPreserving G.op L →
ColimitPreserving G (coLimit⇒Colimit C L)
coLimitPreserving⇒ColimitPreserving L (L′ , iso) = coLimit⇒Colimit D L′ , op-≅⇒≅ D iso
ColimitPreserving⇒coLimitPreserving : ∀ {F : Functor J C} (L : Colimit F) →
ColimitPreserving G L →
LimitPreserving G.op (Colimit⇒coLimit C L)
ColimitPreserving⇒coLimitPreserving L (L′ , iso) = Colimit⇒coLimit D L′ , op-≅⇒≅ D.op iso
module _ {o ℓ e} (G : Functor C D) where
private
module G = Functor G
coContinuous⇒Cocontinuous : Continuous o ℓ e G.op → Cocontinuous o ℓ e G
coContinuous⇒Cocontinuous Con L =
coLimitPreserving⇒ColimitPreserving G (Colimit⇒coLimit C L) (Con (Colimit⇒coLimit C L))
Cocontinuous⇒coContinuous : Cocontinuous o ℓ e G → Continuous o ℓ e G.op
Cocontinuous⇒coContinuous Coc L =
ColimitPreserving⇒coLimitPreserving G (coLimit⇒Colimit C L) (Coc (coLimit⇒Colimit C L))
| {
"alphanum_fraction": 0.6772540984,
"avg_line_length": 37.5384615385,
"ext": "agda",
"hexsha": "495c876bc556ea466abc9f53c8264398b5afd8b0",
"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": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Duality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"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": "laMudri/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Duality.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Duality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 578,
"size": 1952
} |
open import Data.Product using ( _,_ ; proj₁ ; proj₂ )
open import Data.Sum using ( inj₁ ; inj₂ )
open import Relation.Unary using ( _⊆_ )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; sym ; cong )
open import Web.Semantic.DL.ABox using ( ε ; _,_ ; _∼_ ; _∈₁_ ; _∈₂_ ; ⟨ABox⟩ ; Assertions )
open import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind )
open import Web.Semantic.DL.ABox.Model using ( ⊨a-impl-⊨b ; ⟨ABox⟩-Assertions )
open import Web.Semantic.DL.Category.Composition using ( _∙_ )
open import Web.Semantic.DL.Category.Object using ( Object ; _,_ ; IN ; fin ; iface )
open import Web.Semantic.DL.Category.Morphism using ( _⇒_ ; _⊑_ ; _≣_ ; _,_ )
open import Web.Semantic.DL.Category.Properties.Composition.RespectsEquiv using ( compose-resp-≣ )
open import Web.Semantic.DL.Category.Properties.Composition.RespectsWiring using ( compose-resp-wiring )
open import Web.Semantic.DL.Category.Properties.Equivalence using ( ≣-refl ; ≣-sym ; ≣-trans )
open import Web.Semantic.DL.Category.Properties.Tensor.RespectsEquiv using ( tensor-resp-≣ )
open import Web.Semantic.DL.Category.Properties.Tensor.RespectsWiring using ( tensor-resp-wiring )
open import Web.Semantic.DL.Category.Tensor using ( _⊗_ ; _⟨⊗⟩_ )
open import Web.Semantic.DL.Category.Unit using ( I )
open import Web.Semantic.DL.Category.Wiring using
( wiring ; wires ; wires-≈ ; wires-≈⁻¹
; identity ; symm ; assoc ; assoc⁻¹ ; unit₁ ; unit₁⁻¹ ; unit₂ ; unit₂⁻¹
; id✓ ; ⊎-swap✓ ; ⊎-assoc✓ ; ⊎-assoc⁻¹✓ ; inj₁✓ ; inj₂✓ ; ⊎-unit₁✓ ; ⊎-unit₂✓ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
open import Web.Semantic.DL.TBox.Interp using ( ≈-refl′ ; ≈-trans )
open import Web.Semantic.Util using
( id ; _∘_ ; inode ; _⟨⊎⟩_ ; ⊎-swap ; ⊎-assoc ; ⊎-assoc⁻¹ ; ⊎-unit₁ ; ⊎-unit₂ )
module Web.Semantic.DL.Category.Properties.Wiring
{Σ : Signature} {S T : TBox Σ} where
wiring-⊑-refl : ∀ (A B : Object S T) (f g : IN B → IN A)
(f✓ : Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A))
(g✓ : Assertions (⟨ABox⟩ g (iface B)) ⊆ Assertions (iface A)) →
(∀ x → f x ≡ g x) → (wiring A B f f✓ ⊑ wiring A B g g✓)
wiring-⊑-refl A B f g f✓ g✓ f≡g I I⊨STA I⊨F =
⊨a-impl-⊨b I (wires g (proj₁ (fin B)))
(wires-≈⁻¹ g
(λ x → ≈-trans ⌊ I ⌋
(≈-refl′ ⌊ I ⌋ (cong (ind I ∘ inode) (sym (f≡g x))))
(wires-≈ f (proj₂ (fin B) x) I⊨F))
(proj₁ (fin B)))
wiring-≣-refl : ∀ (A B : Object S T) (f g : IN B → IN A)
(f✓ : Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A))
(g✓ : Assertions (⟨ABox⟩ g (iface B)) ⊆ Assertions (iface A)) →
(∀ x → f x ≡ g x) → (wiring A B f f✓ ≣ wiring A B g g✓)
wiring-≣-refl A B f g f✓ g✓ f≡g =
( wiring-⊑-refl A B f g f✓ g✓ f≡g
, wiring-⊑-refl A B g f g✓ f✓ (λ x → sym (f≡g x)) )
∘✓ : (A B C : Object S T) →
(f : IN B → IN A) → (g : IN C → IN B) →
(Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)) →
(Assertions (⟨ABox⟩ g (iface C)) ⊆ Assertions (iface B)) →
(Assertions (⟨ABox⟩ (f ∘ g) (iface C)) ⊆ Assertions (iface A))
∘✓ A B (X , X∈Fin , ε) f g f✓ g✓ ()
∘✓ A B (X , X∈Fin , C₁ , C₂) f g f✓ g✓ (inj₁ a∈C₁) = ∘✓ A B (X , X∈Fin , C₁) f g f✓ (g✓ ∘ inj₁) a∈C₁
∘✓ A B (X , X∈Fin , C₁ , C₂) f g f✓ g✓ (inj₂ a∈C₂) = ∘✓ A B (X , X∈Fin , C₂) f g f✓ (g✓ ∘ inj₂) a∈C₂
∘✓ A B (X , X∈Fin , x ∼ y) f g f✓ g✓ refl = f✓ (⟨ABox⟩-Assertions f (iface B) (g✓ refl))
∘✓ A B (X , X∈Fin , x ∈₁ c) f g f✓ g✓ refl = f✓ (⟨ABox⟩-Assertions f (iface B) (g✓ refl))
∘✓ A B (X , X∈Fin , (x , y) ∈₂ r) f g f✓ g✓ refl = f✓ (⟨ABox⟩-Assertions f (iface B) (g✓ refl))
⟨⊎⟩✓ : (A₁ A₂ B₁ B₂ : Object S T) →
(f₁ : IN B₁ → IN A₁) → (f₂ : IN B₂ → IN A₂) →
(Assertions (⟨ABox⟩ f₁ (iface B₁)) ⊆ Assertions (iface A₁)) →
(Assertions (⟨ABox⟩ f₂ (iface B₂)) ⊆ Assertions (iface A₂)) →
(Assertions (⟨ABox⟩ (f₁ ⟨⊎⟩ f₂) (iface (B₁ ⊗ B₂))) ⊆ Assertions (iface (A₁ ⊗ A₂)))
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , ε) B₂ f₁ f₂ f₁✓ f₂✓ (inj₁ ())
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , B₁₁ , B₁₂) B₂ f₁ f₂ f₁✓ f₂✓ (inj₁ (inj₁ b∈B₁₁)) =
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , B₁₁) B₂ f₁ f₂ (f₁✓ ∘ inj₁) f₂✓ (inj₁ b∈B₁₁)
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , B₁₁ , B₁₂) B₂ f₁ f₂ f₁✓ f₂✓ (inj₁ (inj₂ b∈B₁₂)) =
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , B₁₂) B₂ f₁ f₂ (f₁✓ ∘ inj₂) f₂✓ (inj₁ b∈B₁₂)
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , x ∼ y) B₂ f₁ f₂ f₁✓ f₂✓ (inj₁ refl) =
inj₁ (⟨ABox⟩-Assertions inj₁ (iface A₁) (f₁✓ refl))
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , x ∈₁ c) B₂ f₁ f₂ f₁✓ f₂✓ (inj₁ refl) =
inj₁ (⟨ABox⟩-Assertions inj₁ (iface A₁) (f₁✓ refl))
⟨⊎⟩✓ A₁ A₂ (X₁ , X₁∈Fin , (x , y) ∈₂ r) B₂ f₁ f₂ f₁✓ f₂✓ (inj₁ refl) =
inj₁ (⟨ABox⟩-Assertions inj₁ (iface A₁) (f₁✓ refl))
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , ε) f₁ f₂ f₁✓ f₂✓ (inj₂ ())
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , B₂₁ , B₂₂) f₁ f₂ f₁✓ f₂✓ (inj₂ (inj₁ b∈B₂₁)) =
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , B₂₁) f₁ f₂ f₁✓ (f₂✓ ∘ inj₁) (inj₂ b∈B₂₁)
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , B₂₁ , B₂₂) f₁ f₂ f₁✓ f₂✓ (inj₂ (inj₂ b∈B₂₂)) =
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , B₂₂) f₁ f₂ f₁✓ (f₂✓ ∘ inj₂) (inj₂ b∈B₂₂)
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , x ∼ y) f₁ f₂ f₁✓ f₂✓ (inj₂ refl) =
inj₂ (⟨ABox⟩-Assertions inj₂ (iface A₂) (f₂✓ refl))
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , x ∈₁ c) f₁ f₂ f₁✓ f₂✓ (inj₂ refl) =
inj₂ (⟨ABox⟩-Assertions inj₂ (iface A₂) (f₂✓ refl))
⟨⊎⟩✓ A₁ A₂ B₁ (X₂ , X₂∈Fin , (x , y) ∈₂ r) f₁ f₂ f₁✓ f₂✓ (inj₂ refl) =
inj₂ (⟨ABox⟩-Assertions inj₂ (iface A₂) (f₂✓ refl))
data Rewrite : (A B : Object S T) (F : A ⇒ B) (f : IN B → IN A) →
(Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)) → Set₁ where
rewrite-wiring : ∀ A B f (f✓ : Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)) →
Rewrite A B (wiring A B f f✓) f f✓
rewrite-compose : ∀ {A B C F G f g}
{f✓ : Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)}
{g✓ : Assertions (⟨ABox⟩ g (iface C)) ⊆ Assertions (iface B)} →
Rewrite A B F f f✓ → Rewrite B C G g g✓ → Rewrite A C (F ∙ G) (f ∘ g) (∘✓ A B C f g f✓ g✓)
rewrite-tensor : ∀ {A₁ A₂ B₁ B₂ F₁ F₂ f₁ f₂}
{f₁✓ : Assertions (⟨ABox⟩ f₁ (iface B₁)) ⊆ Assertions (iface A₁)}
{f₂✓ : Assertions (⟨ABox⟩ f₂ (iface B₂)) ⊆ Assertions (iface A₂)} →
Rewrite A₁ B₁ F₁ f₁ f₁✓ → Rewrite A₂ B₂ F₂ f₂ f₂✓ →
Rewrite (A₁ ⊗ A₂) (B₁ ⊗ B₂) (F₁ ⟨⊗⟩ F₂) (f₁ ⟨⊎⟩ f₂) (⟨⊎⟩✓ A₁ A₂ B₁ B₂ f₁ f₂ f₁✓ f₂✓)
rewrite-identity : ∀ A → Rewrite A A (identity A) id (id✓ A)
rewrite-identity A = rewrite-wiring A A id (id✓ A)
rewrite-symm : ∀ A B → Rewrite (A ⊗ B) (B ⊗ A) (symm A B) ⊎-swap (⊎-swap✓ A B)
rewrite-symm A B = rewrite-wiring (A ⊗ B) (B ⊗ A) ⊎-swap (⊎-swap✓ A B)
rewrite-assoc : ∀ A B C → Rewrite ((A ⊗ B) ⊗ C) (A ⊗ (B ⊗ C)) (assoc A B C) ⊎-assoc⁻¹ (⊎-assoc⁻¹✓ A B C)
rewrite-assoc A B C = rewrite-wiring ((A ⊗ B) ⊗ C) (A ⊗ (B ⊗ C)) ⊎-assoc⁻¹ (⊎-assoc⁻¹✓ A B C)
rewrite-assoc⁻¹ : ∀ A B C → Rewrite (A ⊗ (B ⊗ C)) ((A ⊗ B) ⊗ C) (assoc⁻¹ A B C) ⊎-assoc (⊎-assoc✓ A B C)
rewrite-assoc⁻¹ A B C = rewrite-wiring (A ⊗ (B ⊗ C)) ((A ⊗ B) ⊗ C) ⊎-assoc (⊎-assoc✓ A B C)
rewrite-unit₁ : ∀ A → Rewrite (I ⊗ A) A (unit₁ A) inj₂ (inj₂✓ A)
rewrite-unit₁ A = rewrite-wiring (I ⊗ A) A inj₂ (inj₂✓ A)
rewrite-unit₁⁻¹ : ∀ A → Rewrite A (I ⊗ A) (unit₁⁻¹ A) ⊎-unit₁ (⊎-unit₁✓ A)
rewrite-unit₁⁻¹ A = rewrite-wiring A (I ⊗ A) ⊎-unit₁ (⊎-unit₁✓ A)
rewrite-unit₂ : ∀ A → Rewrite (A ⊗ I) A (unit₂ A) inj₁ (inj₁✓ A)
rewrite-unit₂ A = rewrite-wiring (A ⊗ I) A inj₁ (inj₁✓ A)
rewrite-unit₂⁻¹ : ∀ A → Rewrite A (A ⊗ I) (unit₂⁻¹ A) ⊎-unit₂ (⊎-unit₂✓ A)
rewrite-unit₂⁻¹ A = rewrite-wiring A (A ⊗ I) ⊎-unit₂ (⊎-unit₂✓ A)
rewriting : ∀ {A B F G f g}
{f✓ : Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)}
{g✓ : Assertions (⟨ABox⟩ g (iface B)) ⊆ Assertions (iface A)} →
(Rewrite A B F f f✓) → (∀ x → f x ≡ g x) → (Rewrite A B G g g✓) →
(F ≣ G)
rewriting {A} {B} {F} {G} {f} {g} {f✓} {g✓} F⇓f f≡g G⇓g =
≣-trans (lemma F⇓f)
(≣-trans (wiring-≣-refl A B f g f✓ g✓ f≡g)
(≣-sym (lemma G⇓g))) where
lemma : ∀ {A B F f}
{f✓ : Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)} →
(Rewrite A B F f f✓) →
(F ≣ wiring A B f f✓)
lemma (rewrite-wiring A B f f✓) = ≣-refl (wiring A B f f✓)
lemma (rewrite-compose {A} {B} {C} {F} {G} {f} {g} {f✓} {g✓} F⇓f G⇓g) =
≣-trans (compose-resp-≣ (lemma F⇓f) (lemma G⇓g))
(compose-resp-wiring A B C f f✓ g g✓ (f ∘ g)
(∘✓ A B C f g f✓ g✓) (λ x → refl))
lemma (rewrite-tensor {A₁} {A₂} {B₁} {B₂} {F₁} {F₂} {f₁} {f₂} {f₁✓} {f₂✓} F₁⇓f₁ F₂⇓f₂) =
≣-trans (tensor-resp-≣ (lemma F₁⇓f₁) (lemma F₂⇓f₂))
(tensor-resp-wiring A₁ A₂ B₁ B₂ f₁ f₁✓ f₂ f₂✓ (f₁ ⟨⊎⟩ f₂)
(⟨⊎⟩✓ A₁ A₂ B₁ B₂ f₁ f₂ f₁✓ f₂✓) (λ x → refl) (λ x → refl))
| {
"alphanum_fraction": 0.556851312,
"avg_line_length": 56.4144736842,
"ext": "agda",
"hexsha": "373ee4b22eac419d19e96121a23510ee5c90a7be",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Category/Properties/Wiring.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Category/Properties/Wiring.agda",
"max_line_length": 104,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties/Wiring.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 4361,
"size": 8575
} |
{-# OPTIONS --erased-cubical #-}
-- Modules that use --cubical can be imported when --erased-cubical is
-- used.
import Erased-cubical-Module-application.Cubical
module EC = Erased-cubical-Module-application.Cubical Set
-- However, definitions from such modules can only be used in erased
-- contexts.
_ : {A : Set} → A → EC.∥ A ∥
_ = EC.∣_∣
| {
"alphanum_fraction": 0.7023121387,
"avg_line_length": 24.7142857143,
"ext": "agda",
"hexsha": "adde4aca29a803bf16228c42d7f2b6ff59f47484",
"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/Fail/Erased-cubical-Module-application.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/Fail/Erased-cubical-Module-application.agda",
"max_line_length": 70,
"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/Fail/Erased-cubical-Module-application.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": 106,
"size": 346
} |
------------------------------------------------------------------------
-- Definition of the size of an expression, along with some properties
------------------------------------------------------------------------
module Expression-size where
open import Equality.Propositional
open import Prelude hiding (const)
open import List equality-with-J
open import Nat equality-with-J
-- To simplify the development, let's work with actual natural numbers
-- as variables and constants (see
-- Atom.one-can-restrict-attention-to-χ-ℕ-atoms).
open import Atom
open import Chi χ-ℕ-atoms
open import Combinators
open import Free-variables χ-ℕ-atoms
open import Termination χ-ℕ-atoms
open χ-atoms χ-ℕ-atoms
------------------------------------------------------------------------
-- A definition
mutual
-- The size of an expression.
size : Exp → ℕ
size (apply e₁ e₂) = 1 + size e₁ + size e₂
size (lambda x e) = 1 + size e
size (case e bs) = 1 + size e + size-B⋆ bs
size (rec x e) = 1 + size e
size (var x) = 1
size (const c es) = 1 + size-⋆ es
size-B : Br → ℕ
size-B (branch c xs e) = 1 + length xs + size e
size-⋆ : List Exp → ℕ
size-⋆ [] = 1
size-⋆ (e ∷ es) = 1 + size e + size-⋆ es
size-B⋆ : List Br → ℕ
size-B⋆ [] = 1
size-B⋆ (b ∷ bs) = 1 + size-B b + size-B⋆ bs
------------------------------------------------------------------------
-- Properties
-- Every expression has size at least one.
1≤size : ∀ e → 1 ≤ size e
1≤size (apply e₁ e₂) = suc≤suc (zero≤ _)
1≤size (lambda x e) = suc≤suc (zero≤ _)
1≤size (case e bs) = suc≤suc (zero≤ _)
1≤size (rec x e) = suc≤suc (zero≤ _)
1≤size (var x) = suc≤suc (zero≤ _)
1≤size (const c es) = suc≤suc (zero≤ _)
1≤size-⋆ : ∀ es → 1 ≤ size-⋆ es
1≤size-⋆ [] = suc≤suc (zero≤ _)
1≤size-⋆ (_ ∷ _) = suc≤suc (zero≤ _)
1≤size-B⋆ : ∀ bs → 1 ≤ size-B⋆ bs
1≤size-B⋆ [] = suc≤suc (zero≤ _)
1≤size-B⋆ (_ ∷ _) = suc≤suc (zero≤ _)
-- Closed expressions have size at least two.
closed→2≤size : ∀ e → Closed e → 2 ≤ size e
closed→2≤size (apply e₁ e₂) cl =
2 ≤⟨ m≤m+n _ _ ⟩
2 + size e₂ ≤⟨ (1 ∎≤) +-mono 1≤size e₁ +-mono (size e₂ ∎≤) ⟩∎
1 + size e₁ + size e₂ ∎≤
closed→2≤size (lambda x e) cl =
2 ≤⟨ (1 ∎≤) +-mono 1≤size e ⟩∎
1 + size e ∎≤
closed→2≤size (case e bs) cl =
2 ≤⟨ m≤m+n _ _ ⟩
2 + size-B⋆ bs ≤⟨ (1 ∎≤) +-mono 1≤size e +-mono (size-B⋆ bs ∎≤) ⟩∎
1 + size e + size-B⋆ bs ∎≤
closed→2≤size (rec x e) cl =
2 ≤⟨ (1 ∎≤) +-mono 1≤size e ⟩∎
1 + size e ∎≤
closed→2≤size (var x) cl = ⊥-elim (cl x (λ ()) (var refl))
closed→2≤size (const c es) cl =
2 ≤⟨ (1 ∎≤) +-mono 1≤size-⋆ es ⟩∎
1 + size-⋆ es ∎≤
-- Closed, non-terminating expressions of size two must have the form
-- "rec x = x" (for some x).
data Is-loop : Exp → Type where
rec : ∀ {x y} → x ≡ y → Is-loop (rec x (var y))
closed-non-terminating-size≡2→loop :
∀ e → Closed e → ¬ Terminates e → size e ≡ 2 → Is-loop e
closed-non-terminating-size≡2→loop (rec x e) cl _ size≡2 with e
... | apply e₁ e₂ = ⊥-elim $ +≮ 1 (4 ≤⟨ (2 ∎≤) +-mono 1≤size e₁ +-mono 1≤size e₂ ⟩
2 + size e₁ + size e₂ ≡⟨ size≡2 ⟩≤
2 ∎≤)
... | lambda _ e′ = ⊥-elim $ +≮ 0 (3 ≤⟨ (2 ∎≤) +-mono 1≤size e′ ⟩
2 + size e′ ≡⟨ size≡2 ⟩≤
2 ∎≤)
... | case e′ bs = ⊥-elim $ +≮ 0 (3 ≤⟨ (2 ∎≤) +-mono 1≤size e′ +-mono zero≤ _ ⟩
2 + size e′ + size-B⋆ bs ≡⟨ size≡2 ⟩≤
2 ∎≤)
... | rec _ e′ = ⊥-elim $ +≮ 0 (3 ≤⟨ (2 ∎≤) +-mono 1≤size e′ ⟩
2 + size e′ ≡⟨ size≡2 ⟩≤
2 ∎≤)
... | const _ es = ⊥-elim $ +≮ 0 (3 ≤⟨ (2 ∎≤) +-mono 1≤size-⋆ es ⟩
2 + size-⋆ es ≡⟨ size≡2 ⟩≤
2 ∎≤)
... | var y with x V.≟ y
... | yes x≡y = rec x≡y
... | no x≢y = ⊥-elim (cl y (λ ()) (rec (x≢y ∘ sym) (var refl)))
closed-non-terminating-size≡2→loop (apply e₁ e₂) _ _ size≡2 =
⊥-elim $ +≮ 0 (3 ≤⟨ (1 ∎≤) +-mono 1≤size e₁ +-mono 1≤size e₂ ⟩
1 + size e₁ + size e₂ ≡⟨ size≡2 ⟩≤
2 ∎≤)
closed-non-terminating-size≡2→loop (lambda x e) _ ¬⇓ _ =
⊥-elim (¬⇓ (_ , lambda))
closed-non-terminating-size≡2→loop (case e bs) _ _ size≡2 =
⊥-elim $ +≮ 0 (3 ≤⟨ (1 ∎≤) +-mono 1≤size e +-mono 1≤size-B⋆ bs ⟩
1 + size e + size-B⋆ bs ≡⟨ size≡2 ⟩≤
2 ∎≤)
closed-non-terminating-size≡2→loop (var x) cl _ _ =
⊥-elim (cl x (λ ()) (var refl))
closed-non-terminating-size≡2→loop (const c []) _ ¬⇓ _ =
⊥-elim (¬⇓ (_ , const []))
closed-non-terminating-size≡2→loop (const c (e ∷ es)) _ _ size≡2 =
⊥-elim $ +≮ 1 (4 ≤⟨ (2 ∎≤) +-mono 1≤size e +-mono 1≤size-⋆ es ⟩
2 + size e + size-⋆ es ≡⟨ size≡2 ⟩≤
2 ∎≤)
-- Closed, non-terminating expressions of minimal size must have the
-- form "rec x = x" (for some x).
minimal-closed-non-terminating→loop :
let P : Exp → Type
P e = Closed e × ¬ Terminates e
in
∀ e → P e → (∀ e′ → P e′ → size e ≤ size e′) → Is-loop e
minimal-closed-non-terminating→loop e (cl , ¬⇓) minimal =
closed-non-terminating-size≡2→loop e cl ¬⇓ (
≤-antisymmetric
(minimal loop (loop-closed , ¬loop⇓))
(closed→2≤size e cl))
| {
"alphanum_fraction": 0.4414930556,
"avg_line_length": 34.9090909091,
"ext": "agda",
"hexsha": "8e372045175b7162d1c75b84559307a64d78ca8a",
"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": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Expression-size.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Expression-size.agda",
"max_line_length": 104,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Expression-size.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 2274,
"size": 5760
} |
-- Andreas, 2020-04-12, issue #4580
-- Highlighting for builtins FROMNAT, FROMNEG, FROMSTRING
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
record Number (A : Set) : Set where
field fromNat : Nat → A
record Negative (A : Set) : Set where
field fromNeg : Nat → A
open Number {{...}} public
open Negative {{...}} public
{-# BUILTIN FROMNAT fromNat #-} -- Should be highlighted.
{-# BUILTIN FROMNEG fromNeg #-} -- Jump to definition should work.
instance
NumberNat : Number Nat
NumberNat = record { fromNat = λ n → n }
data Int : Set where
pos : Nat → Int
neg : Nat → Int
instance
NumberInt : Number Int
NumberInt = record { fromNat = pos }
NegativeInt : Negative Int
NegativeInt = record { fromNeg = λ { zero → pos 0 ; (suc n) → neg n } }
minusFive : Int
minusFive = -5
thm : -5 ≡ neg 4
thm = refl
| {
"alphanum_fraction": 0.6643026005,
"avg_line_length": 21.6923076923,
"ext": "agda",
"hexsha": "34622c93be234000908e38352a25ff6a87b7e7c8",
"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/LaTeXAndHTML/succeed/Issue4580NegativeLiterals.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/LaTeXAndHTML/succeed/Issue4580NegativeLiterals.agda",
"max_line_length": 73,
"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/LaTeXAndHTML/succeed/Issue4580NegativeLiterals.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": 261,
"size": 846
} |
-- Andreas, 2016-11-19 issue #2308
-- Since fix of #2197, in mutual blocks, records are no-eta-equality
-- until the positivity checker has run.
-- Thus, the record pattern translation might not kick in.
-- Now, there is another pass of record pattern translation
-- after the mutual block has finished.
data Unit : Set where
unit : Unit
mutual -- needed to trigger issue
record R : Set where -- needs to be in mutual block
constructor wrap
field f : Unit
G : R → Set
G (wrap _) = Unit -- match on wrap needed
test : (x : R) → G x → Set₁
test _ unit = Set
-- ERROR WAS:
-- Type mismatch
-- when checking that the pattern unit has type G x
-- Should succeed.
| {
"alphanum_fraction": 0.6842105263,
"avg_line_length": 22.8,
"ext": "agda",
"hexsha": "9699692ac49d3b2d22e87e688401fbc0d148d372",
"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/Issue2308.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/Issue2308.agda",
"max_line_length": 68,
"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/Issue2308.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": 183,
"size": 684
} |
open import Oscar.Prelude
open import Oscar.Class.HasEquivalence
import Oscar.Data.Constraint
module Oscar.Class.Properthing where
record Properthing {𝔬} ℓ (𝔒 : Ø 𝔬) : Ø 𝔬 ∙̂ ↑̂ ℓ where
infixr 15 _∧_
field
➊ : 𝔒
_∧_ : 𝔒 → 𝔒 → 𝔒
⦃ ⌶HasEquivalence ⦄ : HasEquivalence 𝔒 ℓ
Nothing : 𝔒 → Ø ℓ
fact2 : ∀ {P Q} → P ≈ Q → Nothing P → Nothing Q
∧-leftIdentity : ∀ P → ➊ ∧ P ≈ P
open Properthing ⦃ … ⦄ public
| {
"alphanum_fraction": 0.6209302326,
"avg_line_length": 22.6315789474,
"ext": "agda",
"hexsha": "55a80ec5efd6207ebe7075355187966c9c770a92",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Properthing.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Properthing.agda",
"max_line_length": 54,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Properthing.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 188,
"size": 430
} |
-- Andreas, 2016-07-21
-- Test case to ensure postfix printing of projections.
{-# OPTIONS --postfix-projections #-}
open import Common.Product
open import Common.Equality
testProj : {A : Set}{B : A → Set}(y z : Σ A B) →
let X : Σ A B
X = _
in X .proj₁ ≡ y .proj₁ → X .proj₂ ≡ z .proj₂
testProj y z = _ , _
| {
"alphanum_fraction": 0.625,
"avg_line_length": 22.8571428571,
"ext": "agda",
"hexsha": "739656bf74f388efdd1c86d3ab2cc8e7c25354de",
"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/Issue1963I380.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/Issue1963I380.agda",
"max_line_length": 55,
"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/Issue1963I380.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": 109,
"size": 320
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Unsafe String operations and proofs
------------------------------------------------------------------------
{-# OPTIONS --with-K #-}
module Data.String.Unsafe where
import Data.List.Base as List
import Data.List.Properties as Listₚ
open import Data.Nat.Base using (_+_)
open import Data.String.Base
open import Relation.Binary.PropositionalEquality; open ≡-Reasoning
open import Relation.Binary.PropositionalEquality.TrustMe using (trustMe)
------------------------------------------------------------------------
-- Properties of conversion functions
toList∘fromList : ∀ s → toList (fromList s) ≡ s
toList∘fromList s = trustMe
fromList∘toList : ∀ s → fromList (toList s) ≡ s
fromList∘toList s = trustMe
toList-++ : ∀ s t → toList (s ++ t) ≡ toList s List.++ toList t
toList-++ s t = trustMe
length-++ : ∀ s t → length (s ++ t) ≡ length s + length t
length-++ s t = begin
length (s ++ t) ≡⟨⟩
List.length (toList (s ++ t)) ≡⟨ cong List.length (toList-++ s t) ⟩
List.length (toList s List.++ toList t) ≡⟨ Listₚ.length-++ (toList s) ⟩
length s + length t ∎
length-replicate : ∀ n {c} → length (replicate n c) ≡ n
length-replicate n {c} = let cs = List.replicate n c in begin
length (replicate n c) ≡⟨ cong List.length (toList∘fromList cs) ⟩
List.length cs ≡⟨ Listₚ.length-replicate n ⟩
n ∎
| {
"alphanum_fraction": 0.5442448436,
"avg_line_length": 34.9534883721,
"ext": "agda",
"hexsha": "c9648d07806de475357bfc98626e52d813b75625",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/String/Unsafe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/String/Unsafe.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/String/Unsafe.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": 405,
"size": 1503
} |
module Formalization.ClassicalPropositionalLogic.Semantics where
import Lvl
open import Data.Boolean
open import Data.Boolean.Stmt
open import Formalization.ClassicalPropositionalLogic.Syntax
open import Functional
open import Logic
import Logic.Propositional as Logic
import Logic.Predicate as Logic
import Sets.PredicateSet
open Sets.PredicateSet.BoundedQuantifiers
open import Type
private variable ℓₚ ℓ ℓ₁ ℓ₂ : Lvl.Level
module _ where
private variable P : Type{ℓₚ}
-- Model.
-- A model decides which propositional constants that are true or false.
Model : Type{ℓₚ} → Type{ℓₚ}
Model(P) = (P → Bool)
-- Satisfication relation.
-- (𝔐 ⊧ φ) means that the formula φ is satisfied in the model 𝔐.
-- Or in other words: A formula is true in the model 𝔐.
_⊧_ : Model(P) → Formula(P) → Stmt
𝔐 ⊧ (• p) = IsTrue(𝔐(p)) -- A model decides whether a propositional constant is satisifed.
𝔐 ⊧ ⊤ = Logic.⊤ -- Any model satisfies top.
𝔐 ⊧ ⊥ = Logic.⊥ -- No model satisfies bottom.
𝔐 ⊧ (¬ φ) = Logic.¬(𝔐 ⊧ φ) -- A model satisfies a negated proposition when it does not satisfy the proposition.
𝔐 ⊧ (φ ∧ ψ) = (𝔐 ⊧ φ) Logic.∧ (𝔐 ⊧ ψ) -- A model satisfies a conjunction when it satisfies both of the propositions.
𝔐 ⊧ (φ ∨ ψ) = (𝔐 ⊧ φ) Logic.∨ (𝔐 ⊧ ψ) -- A model satisfies a disjunction when it satisfies any one of the propositions.
𝔐 ⊧ (φ ⟶ ψ) = Logic.¬(𝔐 ⊧ φ) Logic.∨ (𝔐 ⊧ ψ)
𝔐 ⊧ (φ ⟷ ψ) = ((𝔐 ⊧ φ) Logic.∧ (𝔐 ⊧ ψ)) Logic.∨ (Logic.¬(𝔐 ⊧ φ) Logic.∧ Logic.¬(𝔐 ⊧ ψ))
-- Satisfication of a set of formulas.
-- This means that a model satisfies all formulas at the same time.
_⊧₊_ : Model(P) → Formulas(P){ℓ} → Stmt
𝔐 ⊧₊ Γ = ∀ₛ(Γ) (𝔐 ⊧_)
-- Validity of a formula.
-- A formula is valid when it is true independent of any model.
Valid : Formula(P) → Stmt
Valid(φ) = Logic.∀ₗ(_⊧ φ)
-- Satisfiability of sets of formulas.
-- A set of formulas is valid when there is a model that satisfies all of them at the same time.
Satisfiable : Formulas(P){ℓ} → Stmt
Satisfiable(Γ) = Logic.∃(_⊧₊ Γ)
-- Unsatisfiability of sets of formulas.
Unsatisfiable : Formulas(P){ℓ} → Stmt
Unsatisfiable{ℓ} = Logic.¬_ ∘ Satisfiable{ℓ}
-- Semantic entailment of a formula.
-- A hypothetical statement. If a model would satisfy all formulas in Γ, then this same model satisifes the formula φ.
_⊨_ : Formulas(P){ℓ} → Formula(P) → Stmt
Γ ⊨ φ = ∀{𝔐} → (𝔐 ⊧₊ Γ) → (𝔐 ⊧ φ)
_⊭_ : Formulas(P){ℓ} → Formula(P) → Stmt
_⊭_ = Logic.¬_ ∘₂ _⊨_
-- Axiomatization of a theory by a set of axioms.
-- A set of axioms is a set of formulas.
-- A theory is the closure of a set of axioms.
-- An axiomatization is a subset of formulas of the theory which entails all formulas in the axiomatized theory.
_axiomatizes_ : Formulas(P){ℓ₁} → Formulas(P){ℓ₂} → Stmt
Γ₁ axiomatizes Γ₂ = ∀{φ} → (Γ₁ ⊨ φ) → Γ₂(φ)
-- A set of formulas is closed when it includes all formulas that it entails.
Closed : Formulas(P){ℓ} → Stmt
Closed(Γ) = Γ axiomatizes Γ
_⊨₊_ : Formulas(P){ℓ} → Formulas(P){ℓ} → Stmt
Γ₁ ⊨₊ Γ₂ = ∀{𝔐} → (𝔐 ⊧₊ Γ₁) → (𝔐 ⊧₊ Γ₂)
_⊭₊_ : Formulas(P){ℓ} → Formulas(P){ℓ} → Stmt
_⊭₊_ = Logic.¬_ ∘₂ _⊨₊_
| {
"alphanum_fraction": 0.6457748675,
"avg_line_length": 39.5925925926,
"ext": "agda",
"hexsha": "9c731a96d6568b2fe8227fe765d45e11486e7018",
"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": "Formalization/ClassicalPropositionalLogic/Semantics.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": "Formalization/ClassicalPropositionalLogic/Semantics.agda",
"max_line_length": 121,
"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": "Formalization/ClassicalPropositionalLogic/Semantics.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": 1212,
"size": 3207
} |
{-# OPTIONS --safe --without-K #-}
module Generics.Mu.All where
open import Generics.Prelude hiding (lookup)
open import Generics.Telescope
open import Generics.Desc
open import Generics.Mu
private
variable
P : Telescope ⊤
p : ⟦ P ⟧tel tt
V I : ExTele P
ℓ c : Level
n : ℕ
AllIndArgωω
: {X : ⟦ P , I ⟧xtel → Setω}
(Pr : ∀ {i} → X (p , i) → Setω)
(C : ConDesc P V I)
→ ∀ {v} → ⟦ C ⟧IndArgω X (p , v) → Setω
AllIndArgωω Pr (var _) x = Pr x
AllIndArgωω Pr (π (n , ai) S C) x = (s : < relevance ai > S _) → AllIndArgωω Pr C (x s)
AllIndArgωω Pr (A ⊗ B) (xa , xb) = AllIndArgωω Pr A xa ×ω AllIndArgωω Pr B xb
AllConωω
: {X : ⟦ P , I ⟧xtel → Setω}
(Pr : ∀ {i} → X (p , i) → Setω)
(C : ConDesc P V I)
→ ∀ {v i} → ⟦ C ⟧Conω X (p , v , i) → Setω
AllConωω Pr (var f) x = ⊤ω
AllConωω Pr (π ia S C) (_ , x) = AllConωω Pr C x
AllConωω Pr (A ⊗ B) (xa , xb) = AllIndArgωω Pr A xa ×ω AllConωω Pr B xb
AllDataωω : {X : ⟦ P , I ⟧xtel → Setω}
(Pr : ∀ {i} → X (p , i) → Setω)
(D : DataDesc P I n)
→ ∀ {i} (x : ⟦ D ⟧Dataω X (p , i))
→ Setω
AllDataωω Pr D (k , x) = AllConωω Pr (lookupCon D k) x
All : ∀ (D : DataDesc P I n) {c}
(Pr : ∀ {i} → μ D (p , i) → Set c)
→ ∀ {i} → μ D (p , i) → Setω
All D Pr ⟨ x ⟩ = AllDataωω (λ x → Liftω (Pr x)) D x
| {
"alphanum_fraction": 0.5115931189,
"avg_line_length": 25.7115384615,
"ext": "agda",
"hexsha": "30b140163a13dc8e738e56c788aa8a379fdb0fb6",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Mu/All.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Mu/All.agda",
"max_line_length": 87,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Mu/All.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 594,
"size": 1337
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of All predicate transformer for fresh lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Fresh.Relation.Unary.All.Properties where
open import Level using (Level; _⊔_; Lift)
open import Data.Empty
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Product using (_,_)
open import Function using (_∘′_)
open import Relation.Nullary
open import Relation.Unary as U
open import Relation.Binary as B using (Rel)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
open import Data.List.Fresh using (List#; []; cons; _∷#_; _#_)
open import Data.List.Fresh.Relation.Unary.All
private
variable
a p r : Level
A : Set a
module _ {R : Rel A r} where
fromAll : ∀ {x} {xs : List# A R} → All (R x) xs → x # xs
fromAll [] = _
fromAll (p ∷ ps) = p , fromAll ps
toAll : ∀ {x} {xs : List# A R} → x # xs → All (R x) xs
toAll {xs = []} _ = []
toAll {xs = a ∷# as} (p , ps) = p ∷ toAll ps
module _ {R : Rel A r} {P : Pred A p} where
append⁺ : {xs ys : List# A R} {ps : All (_# ys) xs} →
All P xs → All P ys → All P (append xs ys ps)
append⁺ [] pys = pys
append⁺ (px ∷ pxs) pys = px ∷ append⁺ pxs pys
| {
"alphanum_fraction": 0.555316092,
"avg_line_length": 30.9333333333,
"ext": "agda",
"hexsha": "25e8cd006ddb7c84fa1085cf95b10041dd2a7ea9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Fresh/Relation/Unary/All/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Fresh/Relation/Unary/All/Properties.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/Data/List/Fresh/Relation/Unary/All/Properties.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": 410,
"size": 1392
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on machine words
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Word.Properties where
import Data.Nat.Base as ℕ
open import Data.Bool.Base using (Bool)
open import Data.Word.Base
import Data.Nat.Properties as ℕₚ
open import Function
open import Relation.Nullary.Decidable using (map′; ⌊_⌋)
open import Relation.Binary
using ( _⇒_; Reflexive; Symmetric; Transitive; Substitutive
; Decidable; DecidableEquality; IsEquivalence; IsDecEquivalence
; Setoid; DecSetoid; StrictTotalOrder)
import Relation.Binary.Construct.On as On
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Primitive properties
open import Agda.Builtin.Word.Properties
renaming (primWord64ToNatInjective to toℕ-injective)
public
------------------------------------------------------------------------
-- Properties of _≈_
≈⇒≡ : _≈_ ⇒ _≡_
≈⇒≡ = toℕ-injective _ _
≈-reflexive : _≡_ ⇒ _≈_
≈-reflexive = cong toℕ
≈-refl : Reflexive _≈_
≈-refl = refl
≈-sym : Symmetric _≈_
≈-sym = sym
≈-trans : Transitive _≈_
≈-trans = trans
≈-subst : ∀ {ℓ} → Substitutive _≈_ ℓ
≈-subst P x≈y p = subst P (≈⇒≡ x≈y) p
infix 4 _≈?_
_≈?_ : Decidable _≈_
x ≈? y = toℕ x ℕₚ.≟ toℕ y
≈-isEquivalence : IsEquivalence _≈_
≈-isEquivalence = record
{ refl = λ {i} → ≈-refl {i}
; sym = λ {i j} → ≈-sym {i} {j}
; trans = λ {i j k} → ≈-trans {i} {j} {k}
}
≈-setoid : Setoid _ _
≈-setoid = record
{ isEquivalence = ≈-isEquivalence
}
≈-isDecEquivalence : IsDecEquivalence _≈_
≈-isDecEquivalence = record
{ isEquivalence = ≈-isEquivalence
; _≟_ = _≈?_
}
≈-decSetoid : DecSetoid _ _
≈-decSetoid = record
{ isDecEquivalence = ≈-isDecEquivalence
}
------------------------------------------------------------------------
-- Properties of _≡_
infix 4 _≟_
_≟_ : DecidableEquality Word64
x ≟ y = map′ ≈⇒≡ ≈-reflexive (x ≈? y)
≡-setoid : Setoid _ _
≡-setoid = setoid Word64
≡-decSetoid : DecSetoid _ _
≡-decSetoid = decSetoid _≟_
------------------------------------------------------------------------
-- Boolean equality test.
infix 4 _==_
_==_ : Word64 → Word64 → Bool
w₁ == w₂ = ⌊ w₁ ≟ w₂ ⌋
------------------------------------------------------------------------
-- Properties of _<_
infix 4 _<?_
_<?_ : Decidable _<_
_<?_ = On.decidable toℕ ℕ._<_ ℕₚ._<?_
<-strictTotalOrder-≈ : StrictTotalOrder _ _ _
<-strictTotalOrder-≈ = On.strictTotalOrder ℕₚ.<-strictTotalOrder toℕ
| {
"alphanum_fraction": 0.5409466566,
"avg_line_length": 24.8785046729,
"ext": "agda",
"hexsha": "42b6dadc0353b58340c0d243603ac90e1068304d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Word/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Word/Properties.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Word/Properties.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": 857,
"size": 2662
} |
{-# OPTIONS --without-K #-}
module function.extensionality.proof where
open import level
open import sum
open import equality
open import function.extensionality.core
open import hott.univalence
open import hott.level.core
open import hott.level.closure.core
open import hott.equivalence.core
open import sets.unit
top : ∀ {i} → Set i
top = ↑ _ ⊤
⊤-contr' : ∀ {i} → contr (↑ i ⊤)
⊤-contr' {i} = lift tt , λ { (lift tt) → refl }
-- this uses definitional η for ⊤
contr-exp-⊤ : ∀ {i j}{A : Set i} → contr (A → top {j})
contr-exp-⊤ = (λ _ → lift tt) , (λ f → refl)
module Weak where
→-contr : ∀ {i j}{A : Set i}{B : Set j}
→ contr B
→ contr (A → B)
→-contr {A = A}{B = B} hB = subst contr p contr-exp-⊤
where
p : (A → top) ≡ (A → B)
p = ap (λ X → A → X) (unique-contr ⊤-contr' hB)
funext : ∀ {i j}{A : Set i}{B : Set j}
→ (f : A → B)(b : B)(h : (x : A) → b ≡ f x)
→ (λ _ → b) ≡ f
funext f b h =
ap (λ u x → proj₁ (u x))
(contr⇒prop (→-contr (singl-contr b))
(λ _ → (b , refl))
(λ x → f x , h x))
abstract
Π-contr : ∀ {i j}{A : Set i}{B : A → Set j}
→ ((x : A) → contr (B x))
→ contr ((x : A) → B x)
Π-contr {i}{j}{A}{B} hB = subst contr p contr-exp-⊤
where
p₀ : (λ _ → top) ≡ B
p₀ = Weak.funext B top (λ x → unique-contr ⊤-contr' (hB x))
p : (A → top {j}) ≡ ((x : A) → B x)
p = ap (λ Z → (x : A) → Z x) p₀
private
funext₀ : ∀ {i j} → Extensionality' i j
funext₀ {i}{j}{X = X}{Y = Y}{f = f}{g = g} h = ap (λ u x → proj₁ (u x)) lem
where
C : X → Set j
C x = Σ (Y x) λ y → f x ≡ y
f' g' : (x : X) → C x
f' x = (f x , refl)
g' x = (g x , h x)
lem : f' ≡ g'
lem = contr⇒prop (Π-contr (λ x → singl-contr (f x))) f' g'
abstract
funext : ∀ {i j} → Extensionality' i j
funext h = funext₀ h · sym (funext₀ (λ _ → refl))
funext-id : ∀ {i j}{X : Set i}{Y : X → Set j}
→ (f : (x : X) → Y x)
→ funext (λ x → refl {x = f x}) ≡ refl
funext-id _ = left-inverse (funext₀ (λ _ → refl))
| {
"alphanum_fraction": 0.4738317757,
"avg_line_length": 28.1578947368,
"ext": "agda",
"hexsha": "e0736ddd514f059bf5e59e35d35dc87b168048bc",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "function/extensionality/proof.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "function/extensionality/proof.agda",
"max_line_length": 79,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "function/extensionality/proof.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 843,
"size": 2140
} |
module Oscar.AgdaPatternSyntaxTrick where
record ⊤ : Set where
constructor tt
data List (A : Set) : Set where
∅ : List A
_∷_ : A → List A → List A
Nat = List ⊤
pattern ‼ xs = tt ∷ xs
syntax ‼ xs = ! xs
data Fin : Nat → Set where
∅ : ∀ {n} → Fin (! n)
! : ∀ {n} → Fin n → Fin (! n)
test : Fin (! (! ∅)) -- OOPS
test = ! ∅
-- record ⊤ : Set where
-- constructor tt
-- data List (A : Set) : Set where
-- ∅ : List A
-- _∷_ : A → List A → List A
-- Nat = List ⊤
-- pattern ‼ xs = tt ∷ xs
-- data Fin : Nat → Set where
-- ∅ : ∀ {n} → Fin (‼ n) -- BOO!
-- ! : ∀ {n} → Fin n → Fin (‼ n)
| {
"alphanum_fraction": 0.4926108374,
"avg_line_length": 17.4,
"ext": "agda",
"hexsha": "c3fb233a19e5806d2fc7292a681fee94ab48718d",
"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/AgdaPatternSyntaxTrick.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/AgdaPatternSyntaxTrick.agda",
"max_line_length": 41,
"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/AgdaPatternSyntaxTrick.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 245,
"size": 609
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module groups.CoefficientExtensionality where
module _ {i} {A : Type i} (dec : has-dec-eq A) where
Word-coef : Word A → (A → ℤ)
Word-coef nil a = 0
Word-coef (inl a' :: w) a with dec a' a
Word-coef (inl a' :: w) a | inl a'=a = succ $ Word-coef w a
Word-coef (inl a' :: w) a | inr a'≠a = Word-coef w a
Word-coef (inr a' :: w) a with dec a' a
Word-coef (inr a' :: w) a | inl a'=a = pred $ Word-coef w a
Word-coef (inr a' :: w) a | inr a'≠a = Word-coef w a
abstract
Word-coef-++ : ∀ w₁ w₂ a → Word-coef (w₁ ++ w₂) a
== Word-coef w₁ a ℤ+ Word-coef w₂ a
Word-coef-++ nil w₂ a = idp
Word-coef-++ (inl a' :: w₁) w₂ a with dec a' a
Word-coef-++ (inl a' :: w₁) w₂ a | inl a'=a =
ap succ (Word-coef-++ w₁ w₂ a)
∙ ! (succ-+ (Word-coef w₁ a) (Word-coef w₂ a))
Word-coef-++ (inl a' :: w₁) w₂ a | inr a'≠a = Word-coef-++ w₁ w₂ a
Word-coef-++ (inr a' :: w₁) w₂ a with dec a' a
Word-coef-++ (inr a' :: w₁) w₂ a | inl a'=a =
ap pred (Word-coef-++ w₁ w₂ a)
∙ ! (pred-+ (Word-coef w₁ a) (Word-coef w₂ a))
Word-coef-++ (inr a' :: w₁) w₂ a | inr a'≠a = Word-coef-++ w₁ w₂ a
Word-coef-flip : ∀ w a → Word-coef (Word-flip w) a == ℤ~ (Word-coef w a)
Word-coef-flip nil a = idp
Word-coef-flip (inl a' :: w) a with dec a' a
Word-coef-flip (inl a' :: w) a | inl a'=a =
ap pred (Word-coef-flip w a) ∙ ! (ℤ~-succ (Word-coef w a))
Word-coef-flip (inl a' :: w) a | inr a'≠a = Word-coef-flip w a
Word-coef-flip (inr a' :: w) a with dec a' a
Word-coef-flip (inr a' :: w) a | inl a'=a =
ap succ (Word-coef-flip w a) ∙ ! (ℤ~-pred (Word-coef w a))
Word-coef-flip (inr a' :: w) a | inr a'≠a = Word-coef-flip w a
private
abstract
FormalSum-coef-rel : {w₁ w₂ : Word A} → FormalSumRel w₁ w₂
→ ∀ a → Word-coef w₁ a == Word-coef w₂ a
FormalSum-coef-rel (fsr-refl p) a = ap (λ w → Word-coef w a) p
FormalSum-coef-rel (fsr-trans fwr₁ fwr₂) a = (FormalSum-coef-rel fwr₁ a) ∙ (FormalSum-coef-rel fwr₂ a)
FormalSum-coef-rel (fsr-sym fsr) a = ! $ FormalSum-coef-rel fsr a
FormalSum-coef-rel (fsr-cons x fwr) a =
Word-coef-++ (x :: nil) _ a
∙ ap (Word-coef (x :: nil) a ℤ+_) (FormalSum-coef-rel fwr a)
∙ ! (Word-coef-++ (x :: nil) _ a)
FormalSum-coef-rel (fsr-swap x y w) a =
Word-coef-++ (x :: y :: nil) _ a
∙ ap (_ℤ+ Word-coef w a)
( Word-coef-++ (x :: nil) (y :: nil) a
∙ ℤ+-comm (Word-coef (x :: nil) a) (Word-coef (y :: nil) a)
∙ ! (Word-coef-++ (y :: nil) (x :: nil) a))
∙ ! (Word-coef-++ (y :: x :: nil) _ a)
FormalSum-coef-rel (fsr-flip x w) a =
Word-coef-++ (x :: flip x :: nil) w a
∙ ap (_ℤ+ Word-coef w a)
( Word-coef-++ (x :: nil) (flip x :: nil) a
∙ ap (Word-coef (x :: nil) a ℤ+_) (Word-coef-flip (x :: nil) a)
∙ ℤ~-inv-r (Word-coef (x :: nil) a) )
∙ ℤ+-unit-l (Word-coef w a)
FormalSum-coef : FormalSum A → (A → ℤ)
FormalSum-coef = FormalSum-rec Word-coef (λ r → λ= $ FormalSum-coef-rel r)
-- Theorem : if coef w a == 0 then FormalSumRel w nil
private
abstract
Word-exp-succ : ∀ (a : A) z → FormalSumRel (inl a :: Word-exp a z) (Word-exp a (succ z))
Word-exp-succ a (pos _) = fsr-refl idp
Word-exp-succ a (negsucc 0) = fsr-flip (inl a) nil
Word-exp-succ a (negsucc (S n)) = fsr-flip (inl a) (Word-exp a (negsucc n))
Word-exp-pred : ∀ (a : A) z → FormalSumRel (inr a :: Word-exp a z) (Word-exp a (pred z))
Word-exp-pred a (pos 0) = fsr-refl idp
Word-exp-pred a (pos (S n)) = fsr-flip (inr a) (Word-exp a (pos n))
Word-exp-pred a (negsucc _) = fsr-refl idp
Word-coef-inl-eq : ∀ {a b} (p : b == a) w
→ Word-coef (inl b :: w) a == succ (Word-coef w a)
Word-coef-inl-eq {a} {b} p w with dec b a
Word-coef-inl-eq {a} {b} p w | inl _ = idp
Word-coef-inl-eq {a} {b} p w | inr ¬p = ⊥-rec (¬p p)
Word-coef-inr-eq : ∀ {a b} (p : b == a) w
→ Word-coef (inr b :: w) a == pred (Word-coef w a)
Word-coef-inr-eq {a} {b} p w with dec b a
Word-coef-inr-eq {a} {b} p w | inl _ = idp
Word-coef-inr-eq {a} {b} p w | inr ¬p = ⊥-rec (¬p p)
Word-coef-inl-neq : ∀ {a b} (p : b ≠ a) w
→ Word-coef (inl b :: w) a == Word-coef w a
Word-coef-inl-neq {a} {b} ¬p w with dec b a
Word-coef-inl-neq {a} {b} ¬p w | inl p = ⊥-rec (¬p p)
Word-coef-inl-neq {a} {b} ¬p w | inr _ = idp
Word-coef-inr-neq : ∀ {a b} (p : b ≠ a) w
→ Word-coef (inr b :: w) a == Word-coef w a
Word-coef-inr-neq {a} {b} ¬p w with dec b a
Word-coef-inr-neq {a} {b} ¬p w | inl p = ⊥-rec (¬p p)
Word-coef-inr-neq {a} {b} ¬p w | inr _ = idp
-- TODO maybe there is a better way to prove the final theorem?
-- Here we are collecting all elements [inl a] and [inr a], and recurse on the rest.
-- The [right-shorter] field makes sure that it is terminating.
record CollectSplitIH (a : A) {n : ℕ} (w : Word A) (len : length w == n) : Type i where
field
left-exponent : ℤ
left-captures-all : Word-coef w a == left-exponent
right-list : Word A
right-shorter : length right-list ≤ n
fsr : FormalSumRel w (Word-exp a left-exponent ++ right-list)
abstract
collect-split : ∀ a {n} w (len=n : length w == n) → CollectSplitIH a w len=n
collect-split a nil idp = record {
left-exponent = 0;
left-captures-all = idp;
right-list = nil;
right-shorter = inl idp;
fsr = fsr-refl idp}
collect-split a (inl b :: w) idp with dec b a
... | inl b=a = record {
left-exponent = succ left-exponent;
left-captures-all = Word-coef-inl-eq b=a w ∙ ap succ left-captures-all;
right-list = right-list;
right-shorter = ≤-trans right-shorter (inr ltS);
fsr = fsr-trans (fsr-refl (ap (λ a → inl a :: w) b=a)) $
fsr-trans (fsr-cons (inl a) fsr) $
(FormalSumRel-cong-++-l (Word-exp-succ a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
... | inr b≠a = record {
left-exponent = left-exponent;
left-captures-all = Word-coef-inl-neq b≠a w ∙ left-captures-all;
right-list = inl b :: right-list;
right-shorter = ≤-ap-S right-shorter;
fsr = fsr-trans (fsr-cons (inl b) fsr) $
fsr-sym (FormalSumRel-swap1 (inl b) (Word-exp a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
collect-split a (inr b :: w) idp with dec b a
... | inl b=a = record {
left-exponent = pred left-exponent;
left-captures-all = Word-coef-inr-eq b=a w ∙ ap pred left-captures-all;
right-list = right-list;
right-shorter = ≤-trans right-shorter (inr ltS);
fsr = fsr-trans (fsr-refl (ap (λ a → inr a :: w) b=a)) $
fsr-trans (fsr-cons (inr a) fsr) $
(FormalSumRel-cong-++-l (Word-exp-pred a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
... | inr b≠a = record {
left-exponent = left-exponent;
left-captures-all = Word-coef-inr-neq b≠a w ∙ left-captures-all;
right-list = inr b :: right-list;
right-shorter = ≤-ap-S right-shorter;
fsr = fsr-trans (fsr-cons (inr b) fsr) $
fsr-sym (FormalSumRel-swap1 (inr b) (Word-exp a left-exponent) right-list)}
where open CollectSplitIH (collect-split a w idp)
-- We simulate strong induction by recursing on both [m] and [n≤m].
-- We could develop a general framework for strong induction but I am lazy. -Favonia
zero-coef-is-ident' : ∀ {m n} (n≤m : n ≤ m) (w : Word A) (len : length w == n)
→ (∀ a → Word-coef w a == 0) → FormalSumRel w nil
zero-coef-is-ident' (inr ltS) w len zero-coef
= zero-coef-is-ident' (inl idp) w len zero-coef
zero-coef-is-ident' (inr (ltSR lt)) w len zero-coef
= zero-coef-is-ident' (inr lt) w len zero-coef
zero-coef-is-ident' {m = O} (inl idp) nil _ _ = fsr-refl idp
zero-coef-is-ident' {m = O} (inl idp) (_ :: _) len _ = ⊥-rec $ ℕ-S≠O _ len
zero-coef-is-ident' {m = S m} (inl idp) nil len _ = ⊥-rec $ ℕ-S≠O _ (! len)
zero-coef-is-ident' {m = S m} (inl idp) (inl a :: w) len zero-coef =
fsr-trans whole-is-right (zero-coef-is-ident' right-shorter right-list idp right-zero-coef)
where
open CollectSplitIH (collect-split a w (ℕ-S-is-inj _ _ len))
left-exponent-is-minus-one : left-exponent == -1
left-exponent-is-minus-one = succ-is-inj left-exponent -1 $
ap succ (! left-captures-all) ∙ ! (Word-coef-inl-eq idp w) ∙ zero-coef a
whole-is-right : FormalSumRel (inl a :: w) right-list
whole-is-right =
fsr-trans (fsr-cons (inl a) fsr) $
fsr-trans (fsr-refl (ap (λ e → inl a :: Word-exp a e ++ right-list) left-exponent-is-minus-one)) $
fsr-flip (inl a) right-list
right-zero-coef : ∀ a' → Word-coef right-list a' == 0
right-zero-coef a' = ! (FormalSum-coef-rel whole-is-right a') ∙ zero-coef a'
zero-coef-is-ident' {m = S m} (inl idp) (inr a :: w) len zero-coef =
fsr-trans whole-is-right (zero-coef-is-ident' right-shorter right-list idp right-zero-coef)
where
open CollectSplitIH (collect-split a w (ℕ-S-is-inj _ _ len))
left-exponent-is-one : left-exponent == 1
left-exponent-is-one = pred-is-inj left-exponent 1 $
ap pred (! left-captures-all) ∙ ! (Word-coef-inr-eq idp w) ∙ zero-coef a
whole-is-right : FormalSumRel (inr a :: w) right-list
whole-is-right =
fsr-trans (fsr-cons (inr a) fsr) $
fsr-trans (fsr-refl (ap (λ e → inr a :: Word-exp a e ++ right-list) left-exponent-is-one)) $
fsr-flip (inr a) right-list
right-zero-coef : ∀ a' → Word-coef right-list a' == 0
right-zero-coef a' = ! (FormalSum-coef-rel whole-is-right a') ∙ zero-coef a'
zero-coef-is-ident : ∀ (w : Word A)
→ (∀ a → Word-coef w a == 0)
→ FormalSumRel w nil
zero-coef-is-ident w = zero-coef-is-ident' (inl idp) w idp
abstract
FormalSum-coef-ext' : ∀ w₁ w₂
→ (∀ a → Word-coef w₁ a == Word-coef w₂ a)
→ fs[ w₁ ] == fs[ w₂ ]
FormalSum-coef-ext' w₁ w₂ same-coef = G.inv-is-inj fs[ w₁ ] fs[ w₂ ] $
G.inv-unique-l (G.inv fs[ w₂ ]) fs[ w₁ ] $ quot-rel $
zero-coef-is-ident (Word-flip w₂ ++ w₁)
(λ a → Word-coef-++ (Word-flip w₂) w₁ a
∙ ap2 _ℤ+_ (Word-coef-flip w₂ a) (same-coef a)
∙ ℤ~-inv-l (Word-coef w₂ a))
where module G = FreeAbGroup A
FormalSum-coef-ext : ∀ fs₁ fs₂
→ (∀ a → FormalSum-coef fs₁ a == FormalSum-coef fs₂ a)
→ fs₁ == fs₂
FormalSum-coef-ext = FormalSum-elim
(λ w₁ → FormalSum-elim
(λ w₂ → FormalSum-coef-ext' w₁ w₂)
(λ _ → prop-has-all-paths-↓))
(λ _ → prop-has-all-paths-↓)
has-finite-support : (A → ℤ) → Type i
has-finite-support f = Σ (FormalSum A) λ fs → ∀ a → f a == FormalSum-coef fs a
module _ {i} {A : Type i} {dec : has-dec-eq A} where
abstract
has-finite-support-is-prop : ∀ f → is-prop (has-finite-support dec f)
has-finite-support-is-prop f = all-paths-is-prop
λ{(fs₁ , match₁) (fs₂ , match₂) → pair=
(FormalSum-coef-ext dec fs₁ fs₂ λ a → ! (match₁ a) ∙ match₂ a)
prop-has-all-paths-↓}
module _ where
private
abstract
Word-coef-exp-diag-pos : ∀ {I} (<I : Fin I) n →
Word-coef Fin-has-dec-eq (Word-exp <I (pos n)) <I == pos n
Word-coef-exp-diag-pos <I O = idp
Word-coef-exp-diag-pos <I (S n) with Fin-has-dec-eq <I <I
... | inl _ = ap succ (Word-coef-exp-diag-pos <I n)
... | inr ¬p = ⊥-rec (¬p idp)
Word-coef-exp-diag-negsucc : ∀ {I} (<I : Fin I) n →
Word-coef Fin-has-dec-eq (Word-exp <I (negsucc n)) <I == negsucc n
Word-coef-exp-diag-negsucc <I O with Fin-has-dec-eq <I <I
... | inl _ = idp
... | inr ¬p = ⊥-rec (¬p idp)
Word-coef-exp-diag-negsucc <I (S n) with Fin-has-dec-eq <I <I
... | inl _ = ap pred (Word-coef-exp-diag-negsucc <I n)
... | inr ¬p = ⊥-rec (¬p idp)
Word-coef-exp-diag : ∀ {I} (<I : Fin I) z →
Word-coef Fin-has-dec-eq (Word-exp <I z) <I == z
Word-coef-exp-diag <I (pos n) = Word-coef-exp-diag-pos <I n
Word-coef-exp-diag <I (negsucc n) = Word-coef-exp-diag-negsucc <I n
Word-coef-exp-≠-pos : ∀ {I} {<I <I' : Fin I} (_ : <I ≠ <I') n →
Word-coef Fin-has-dec-eq (Word-exp <I (pos n)) <I' == 0
Word-coef-exp-≠-pos _ O = idp
Word-coef-exp-≠-pos {<I = <I} {<I'} neq (S n) with Fin-has-dec-eq <I <I'
... | inl p = ⊥-rec (neq p)
... | inr ¬p = Word-coef-exp-≠-pos neq n
Word-coef-exp-≠-negsucc : ∀ {I} {<I <I' : Fin I} (_ : <I ≠ <I') n →
Word-coef Fin-has-dec-eq (Word-exp <I (negsucc n)) <I' == 0
Word-coef-exp-≠-negsucc {<I = <I} {<I'} neq O with Fin-has-dec-eq <I <I'
... | inl p = ⊥-rec (neq p)
... | inr ¬p = idp
Word-coef-exp-≠-negsucc {<I = <I} {<I'} neq (S n) with Fin-has-dec-eq <I <I'
... | inl p = ⊥-rec (neq p)
... | inr ¬p = Word-coef-exp-≠-negsucc neq n
Word-coef-exp-≠ : ∀ {I} {<I <I' : Fin I} (_ : <I ≠ <I') z →
Word-coef Fin-has-dec-eq (Word-exp <I z) <I' == 0
Word-coef-exp-≠ neq (pos n) = Word-coef-exp-≠-pos neq n
Word-coef-exp-≠ neq (negsucc n) = Word-coef-exp-≠-negsucc neq n
Word-sum' : ∀ (I : ℕ) {A : Type₀} (F : Fin I → A) (f : Fin I → ℤ) → Word A
Word-sum' 0 F f = nil
Word-sum' (S I) F f = Word-sum' I (F ∘ Fin-S) (f ∘ Fin-S) ++ Word-exp (F (I , ltS)) (f (I , ltS))
Word-sum : ∀ {I : ℕ} (f : Fin I → ℤ) → Word (Fin I)
Word-sum {I} f = Word-sum' I (idf (Fin I)) f
abstract
Word-coef-sum'-late : ∀ n m (I : ℕ) (f : Fin I → ℤ)
→ Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' m) f) (Fin-S^' n (ℕ-S^' m I , ltS)) == 0
Word-coef-sum'-late n m 0 f = idp
Word-coef-sum'-late n m (S I) f =
Word-coef Fin-has-dec-eq
(Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' (S m)) (f ∘ Fin-S) ++ Word-exp (Fin-S^' (S n) (Fin-S^' m (I , ltS))) (f (I , ltS)))
(Fin-S^' n (ℕ-S^' (S m) I , ltS))
=⟨ Word-coef-++ Fin-has-dec-eq
(Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' (S m)) (f ∘ Fin-S))
(Word-exp (Fin-S^' (S n) (Fin-S^' m (I , ltS))) (f (I , ltS)))
(Fin-S^' n (ℕ-S^' (S m) I , ltS)) ⟩
Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' (S m)) (f ∘ Fin-S)) (Fin-S^' n (ℕ-S^' (S m) I , ltS))
ℤ+
Word-coef Fin-has-dec-eq (Word-exp (Fin-S^' (S n) (Fin-S^' m (I , ltS))) (f (I , ltS))) (Fin-S^' n (ℕ-S^' (S m) I , ltS))
=⟨ ap2 _ℤ+_
(Word-coef-sum'-late n (S m) I (f ∘ Fin-S))
(Word-coef-exp-≠ (Fin-S^'-≠ n (ltSR≠ltS _)) (f (I , ltS))) ⟩
0
=∎
Word-coef-sum' : ∀ n {I} (f : Fin I → ℤ) <I
→ Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' n) f) (Fin-S^' n <I) == f <I
Word-coef-sum' n f (I , ltS) =
Word-coef Fin-has-dec-eq
(Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S) ++ Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS)))
(Fin-S^' n (I , ltS))
=⟨ Word-coef-++ Fin-has-dec-eq
(Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S))
(Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS)))
(Fin-S^' n (I , ltS)) ⟩
Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S)) (Fin-S^' n (I , ltS))
ℤ+
Word-coef Fin-has-dec-eq (Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' n (I , ltS))
=⟨ ap2 _ℤ+_
(Word-coef-sum'-late n 0 I (f ∘ Fin-S))
(Word-coef-exp-diag (Fin-S^' n (I , ltS)) (f (I , ltS))) ⟩
f (I , ltS)
=∎
Word-coef-sum' n {I = S I} f (m , ltSR m<I) =
Word-coef Fin-has-dec-eq
(Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S) ++ Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS)))
(Fin-S^' (S n) (m , m<I))
=⟨ Word-coef-++ Fin-has-dec-eq
(Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S))
(Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS)))
(Fin-S^' (S n) (m , m<I)) ⟩
Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S)) (Fin-S^' (S n) (m , m<I))
ℤ+
Word-coef Fin-has-dec-eq (Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' (S n) (m , m<I))
=⟨ ap2 _ℤ+_
(Word-coef-sum' (S n) {I} (f ∘ Fin-S) (m , m<I))
(Word-coef-exp-≠ (Fin-S^'-≠ n (ltS≠ltSR (m , m<I))) (f (I , ltS))) ⟩
f (m , ltSR m<I) ℤ+ 0
=⟨ ℤ+-unit-r _ ⟩
f (m , ltSR m<I)
=∎
FormalSum-sum' : ∀ n (I : ℕ) (f : Fin I → ℤ) → FormalSum (Fin (ℕ-S^' n I))
FormalSum-sum' n I f =
Group.sum (FreeAbGroup.grp (Fin (ℕ-S^' n I)))
(λ <I → Group.exp (FreeAbGroup.grp (Fin (ℕ-S^' n I))) fs[ inl (Fin-S^' n <I) :: nil ] (f <I))
FormalSum-sum : ∀ {I : ℕ} (f : Fin I → ℤ) → FormalSum (Fin I)
FormalSum-sum {I} = FormalSum-sum' 0 I
private
abstract
FormalSum-sum'-β : ∀ n (I : ℕ) (f : Fin I → ℤ)
→ FormalSum-sum' n I f == fs[ Word-sum' I (Fin-S^' n) f ]
FormalSum-sum'-β n O f = idp
FormalSum-sum'-β n (S I) f =
ap2 (Group.comp (FreeAbGroup.grp (Fin (ℕ-S^' (S n) I))))
(FormalSum-sum'-β (S n) I (f ∘ Fin-S))
(! (FormalSumRel-pres-exp (Fin-S^' n (I , ltS)) (f (I , ltS))))
Fin→-has-finite-support : ∀ {I} (f : Fin I → ℤ) → has-finite-support Fin-has-dec-eq f
Fin→-has-finite-support {I} f = FormalSum-sum f , lemma
where abstract lemma = λ <I → ! (ap (λ fs → FormalSum-coef Fin-has-dec-eq fs <I) (FormalSum-sum'-β 0 I f) ∙ Word-coef-sum' 0 f <I)
| {
"alphanum_fraction": 0.5142083149,
"avg_line_length": 47.4750656168,
"ext": "agda",
"hexsha": "50f15a7215fe5a8e7823dbd33d1781c354776919",
"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": "theorems/groups/CoefficientExtensionality.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": "theorems/groups/CoefficientExtensionality.agda",
"max_line_length": 134,
"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": "theorems/groups/CoefficientExtensionality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7039,
"size": 18088
} |
open import Agda.Primitive
_∘_ : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
data D {a} (A : Set a) : Set a where
d : D A → D A
data E {a} (A : Set a) : Set a where
e : A → E A
F : ∀ {a} {A : Set a} → A → D A → Set a
F x (d ys) = E (F x ys)
G : ∀ {a} {A : Set a} → D A → D A → Set a
G xs ys = ∀ x → F x xs → F x ys
postulate
H : ∀ {a} {A : Set a} {xs ys : D A} → G xs ys → Set
variable
a : Level
A : Set a
P : A → Set a
x : A
xs : D A
postulate
h : {f : G xs xs} (_ : P x) → F x xs → H (λ _ → e ∘ f _)
| {
"alphanum_fraction": 0.3943028486,
"avg_line_length": 19.6176470588,
"ext": "agda",
"hexsha": "8ddc65d7898f67bb5a6b8c63ad04563bba57f432",
"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/Issue3672b.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/Issue3672b.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/Fail/Issue3672b.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": 327,
"size": 667
} |
module Data.Char where
postulate Char : Set
{-# BUILTIN CHAR Char #-}
| {
"alphanum_fraction": 0.6756756757,
"avg_line_length": 9.25,
"ext": "agda",
"hexsha": "2877dd924ec94b13557c0ad5509ae76365af0b75",
"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/Data/Char.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/Data/Char.agda",
"max_line_length": 25,
"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/Data/Char.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": 18,
"size": 74
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import groups.Cokernel
open import cohomology.Theory
open import cw.CW
module cw.cohomology.ZerothCohomologyGroup {i} (OT : OrdinaryTheory i)
(⊙skel : ⊙Skeleton {i} 1) (ac : ⊙has-cells-with-choice 0 ⊙skel i) where
open OrdinaryTheory OT
open import cw.cohomology.TipCoboundary OT ⊙skel
open import cw.cohomology.TipAndAugment OT (⊙cw-init ⊙skel)
open import cw.cohomology.TipGrid OT ⊙skel ac
{-
C(X₀)<------C(X₁) = C(X)
^
|
|
C(X₁/X₀)
WoC
WoC := Wedges of Cells
-}
open import groups.KernelSndImageInl (C2 0) {H = CX₀ 0}
{K = C 1 (⊙Cofiber (⊙cw-incl-last ⊙skel))}
cw-co∂-head' cw-co∂-head (λ _ → idp)
(C2×CX₀-is-abelian 0)
module CokerCoε = Coker cw-coε (C2×CX₀-is-abelian 0)
open import groups.KernelImage cw-co∂-head cw-coε (C2×CX₀-is-abelian 0)
C-cw-iso-ker/im : C 0 ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker/Im
C-cw-iso-ker/im = Ker-φ-snd-quot-Im-inl ∘eᴳ Ker-cw-co∂-head'
| {
"alphanum_fraction": 0.6222005842,
"avg_line_length": 25.675,
"ext": "agda",
"hexsha": "bfa4e86f2da4f3aa573b1dae605acb45c3c0cadb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/ZerothCohomologyGroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/ZerothCohomologyGroup.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/ZerothCohomologyGroup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 407,
"size": 1027
} |
{-
Definitions for functions
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Function where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
-- The identity function
idfun : ∀ {ℓ} → (A : Type ℓ) → A → A
idfun _ x = x
infixr 9 _∘_
_∘_ : ∀ {ℓ ℓ′ ℓ″} {A : Type ℓ} {B : A → Type ℓ′} {C : (a : A) → B a → Type ℓ″}
(g : {a : A} → (b : B a) → C a b) → (f : (a : A) → B a) → (a : A) → C a (f a)
g ∘ f = λ x → g (f x)
∘-assoc : ∀ {ℓ ℓ′ ℓ″ ℓ‴} {A : Type ℓ} {B : A → Type ℓ′} {C : (a : A) → B a → Type ℓ″} {D : (a : A) (b : B a) → C a b → Type ℓ‴}
(h : {a : A} {b : B a} → (c : C a b) → D a b c) (g : {a : A} → (b : B a) → C a b) (f : (a : A) → B a)
→ (h ∘ g) ∘ f ≡ h ∘ (g ∘ f)
∘-assoc h g f i x = h (g (f x))
∘-idˡ : ∀ {ℓ ℓ′} {A : Type ℓ} {B : A → Type ℓ′} (f : (a : A) → B a) → f ∘ idfun A ≡ f
∘-idˡ f i x = f x
∘-idʳ : ∀ {ℓ ℓ′} {A : Type ℓ} {B : A → Type ℓ′} (f : (a : A) → B a) → (λ {a} → idfun (B a)) ∘ f ≡ f
∘-idʳ f i x = f x
const : ∀ {ℓ ℓ′} {A : Type ℓ} {B : Type ℓ′} → A → B → A
const x = λ _ → x
case_of_ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} → (x : A) → (∀ x → B x) → B x
case x of f = f x
case_return_of_ : ∀ {ℓ ℓ'} {A : Type ℓ} (x : A) (B : A → Type ℓ') → (∀ x → B x) → B x
case x return P of f = f x
uncurry
: ∀{ℓ ℓ′ ℓ″} {A : Type ℓ} {B : A → Type ℓ′} {C : (a : A) → B a → Type ℓ″}
→ ((x : A) → (y : B x) → C x y)
→ (p : Σ A B) → C (fst p) (snd p)
uncurry f (x , y) = f x y
module _ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where
-- Notions of 'coherently constant' functions for low dimensions.
-- These are the properties of functions necessary to e.g. eliminate
-- from the propositional truncation.
-- 2-Constant functions are coherently constant if B is a set.
2-Constant : (A → B) → Type _
2-Constant f = ∀ x y → f x ≡ f y
2-Constant-isProp : isSet B → (f : A → B) → isProp (2-Constant f)
2-Constant-isProp Bset f link1 link2 i x y j
= Bset (f x) (f y) (link1 x y) (link2 x y) i j
-- 3-Constant functions are coherently constant if B is a groupoid.
record 3-Constant (f : A → B) : Type (ℓ-max ℓ ℓ') where
field
link : 2-Constant f
coh₁ : ∀ x y z → Square refl (link x y) (link x z) (link y z)
coh₂ : ∀ x y z → Square (link x y) (link x z) (link y z) refl
coh₂ x y z i j
= hcomp (λ k → λ
{ (j = i0) → link x y i
; (i = i0) → link x z (j ∧ k)
; (j = i1) → link x z (i ∨ k)
; (i = i1) → link y z j
})
(coh₁ x y z j i)
link≡refl : ∀ x → refl ≡ link x x
link≡refl x i j
= hcomp (λ k → λ
{ (i = i0) → link x x (j ∧ ~ k)
; (i = i1) → link x x j
; (j = i0) → f x
; (j = i1) → link x x (~ i ∧ ~ k)
})
(coh₁ x x x (~ i) j)
downleft : ∀ x y → Square refl (link x y) refl (link y x)
downleft x y i j
= hcomp (λ k → λ
{ (i = i0) → link x y j
; (i = i1) → link≡refl x (~ k) j
; (j = i0) → f x
; (j = i1) → link y x i
})
(coh₁ x y x i j)
link≡symlink : ∀ x y → link x y ≡ sym (link y x)
link≡symlink x y i j
= hcomp (λ k → λ
{ (i = i0) → link x y j
; (i = i1) → link y x (~ j ∨ ~ k)
; (j = i0) → f x
; (j = i1) → link y x (i ∧ ~ k)
})
(downleft x y i j)
| {
"alphanum_fraction": 0.429396477,
"avg_line_length": 32.3644859813,
"ext": "agda",
"hexsha": "e21564bdcf697d6b2db92747eb16e3c09ac67636",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Foundations/Function.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Foundations/Function.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Foundations/Function.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1505,
"size": 3463
} |
{-# OPTIONS --without-K --rewriting #-}
open import PathInduction
open import Pushout
module JamesFirstComposite {i} (A : Type i) (⋆A : A) where
open import JamesTwoMaps A ⋆A
ap-from-αJ-δJ : (a : A) (x : JA) → ap from (ap (αJ a) (δJ x)) == ap (α∞ a) (δ∞ (from x))
ap-from-αJ-δJ a x = ap-from-αJ a (δJ x) ∙ ap (ap (α∞ a)) (δJ-β x)
ap-from-γ : (a : A) (x : JA) → ap from (γJ a x) == γ∞ a (from x)
ap-from-γ = λ a x → ap-!∙ from (ap (αJ a) (δJ x)) (δJ (αJ a x)) ∙ & coh (ap-from-αJ-δJ a x) (δJ-β (αJ a x)) module ApFromγ where
coh : Coh ({A : Type i} {a b : A} {p p' : b == a} (p= : p == p') {c : A} {q q' : b == c} (q= : q == q') → ! p ∙ q == ! p' ∙ q')
coh = path-induction
ap-from-η : (x : JA) → Square (ap (ap from) (ηJ x)) (ap-from-γ ⋆A x) idp (η∞ (from x))
ap-from-η x = & (η-ify-coh from) (ap-δJ (δJ x)) ∙□ & η-coh-homotopy from-δJ-δJ where
-- [ap] commutes with [ηIfy.coh]
-- This lemma would also be true for arbitrary [αJ], [δJ], [α∞] and [δ∞], but for simplicity
-- we do not abstract over them. We do abstract over [from] because otherwise Agda uses a
-- crazy amount of memory.
η-ify-coh : (from : JA → J∞A) → Coh ({a b : JA} {p : a == b} {c : JA} {q r : b == c} (sq : Square p p q r)
→ Square (ap (ap from) (& (ηIfy.coh αJ δJ) sq)) (ap-!∙ from q r) idp (& (ηIfy.coh α∞ δ∞) (ap-square from sq)))
η-ify-coh = path-induction
from-δJ-δJ : FlatCube (ap-square from (natural-square δJ (δJ x) (ap-idf (δJ x)) idp))
(natural-square δ∞ (δ∞ (from x)) (ap-idf (δ∞ (from x))) idp)
(δJ-β x)
(δJ-β x)
(ap-from-αJ-δJ ⋆A x)
(δJ-β (αJ ⋆A x))
from-δJ-δJ = adapt-flatcube ∙idp idp∙ idp∙ ∙idp
(& (ap-square-natural-square from) (δJ x) δJ (& coh) ∙idp
/∙³ & natural-square-homotopy (δJ-β) (δJ x)
∙fc & (natural-square-∘ (δJ x) from) δ∞ (& coh') idp
/∙³ & natural-square= δ∞ (δJ-β x) (& ap2-idf) (& coh'')) where
coh : {A B : Type i} {f : A → B} → Coh ({x y : A} {p : x == y} → ap-∘ f (λ z → z) p ∙ ap (ap f) (ap-idf p) == idp)
coh = path-induction
coh' : {A B : Type i} {f : A → B} → Coh ({x y : A} {p : x == y} → ∘-ap (λ z → z) f p ∙ idp == ap-idf _)
coh' = path-induction
coh'' : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q : c == a} {d : A} {r : c == d}
→ Square p (! q ∙ r) idp ((! r ∙ q) ∙ p))
coh'' = path-induction
-- If [sq] and [sq'] are equal (via a FlatCube), then applying [ηIfy.coh] to them give equal terms
-- (via a Square).
η-coh-homotopy : Coh ({a b : J∞A} {p : a == b} {c : J∞A} {q : b == c} {r : b == c} {sq : Square p p q r}
{p' : a == b} {p= : p == p'} {q' : b == c} {q= : q == q'} {r' : b == c} {r= : r == r'}
{sq' : Square p' p' q' r'} (cube : FlatCube sq sq' p= p= q= r=)
→ Square (& (ηIfy.coh α∞ δ∞) sq) (& ApFromγ.coh q= r=) idp (& (ηIfy.coh α∞ δ∞) sq'))
η-coh-homotopy = path-induction
comp-square2 : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q : b == c} → Square p idp q (p ∙ q))
comp-square2 = path-induction
ap-square-comp-square2 : {A B : Type i} (f : A → B) → Coh ({a b : A} {p : a == b} {c : A} {q : b == c}
→ FlatCube (ap-square f (& comp-square2 {p = p} {q = q})) (& comp-square2) idp idp idp (ap-∙ f p q))
ap-square-comp-square2 f = path-induction
{- First composite -}
-- As for [inJ], we need both [from-inJ] and [from-inJS] for the termination checker
from-inJ : (n : ℕ) (x : J n) → from (inJ n x) == in∞ n x
from-inJS : (n : ℕ) (x : J (S n)) → from (inJS n x) == in∞ (S n) x
-- Those three describe [from ∘ inJS] applied to [ι], [α] and [β], in the case [S n] as it is
-- the only one we need.
from-inJSS-ι : (n : ℕ) (x : J (S n)) → from (inJS (S n) (ι (S n) x)) == in∞ (S (S n)) (ι (S n) x)
from-inJSS-ι n x = ap (α∞ ⋆A) (from-inJS n x) ∙ ap (in∞ (S (S n))) (β (S n) x)
from-inJSS-α : (n : ℕ) (a : A) (x : J (S n)) → from (inJS (S n) (α (S n) a x)) == in∞ (S (S n)) (α (S n) a x)
from-inJSS-α n a x = ap (α∞ a) (from-inJS n x)
from-inJSS-β : (n : ℕ) (x : J (S n)) → Square (ap from (ap (inJS (S n)) (β (S n) x))) (from-inJSS-α n ⋆A x) (from-inJSS-ι n x) (ap (in∞ (S (S n))) (β (S n) x))
from-inJSS-β n x = ap (ap from) (inJS-βS n x) |∙ comp-square
-- Those three terms describe what happens when we apply [from-inJS] to [ι], [α] or [β].
-- Note that the naming scheme is slightly ambiguous, they do *not* describe [from (inJS (ι _ _))] as above.
-- They are defined later, as we need to know the definition of [from-inJS].
from-inJS-ι : (n : ℕ) (x : J n) → Square (from-inJS n (ι n x)) (ap from (inJS-ι n x)) idp (ap (α∞ ⋆A) (from-inJ n x) ∙ ap (in∞ (S n)) (β n x))
from-inJS-α : (n : ℕ) (a : A) (x : J n) → Square (from-inJS n (α n a x)) (ap from (inJS-α n a x)) idp (ap (α∞ a) (from-inJ n x))
from-inJS-β : (n : ℕ) (x : J n) → Cube (natural-square (from-inJS n) (β n x) (ap-∘ from (inJS n) (β n x)) idp) (& comp-square2) (from-inJS-α n ⋆A x) (ap-square from (inJS-β n x)) hid-square (from-inJS-ι n x)
-- The following three terms show that the two ways of reducing [from ∘ inJS (S n) ∘ (ι (S n) | α (S n) a) ∘ (ι n | α n a)]
-- are equal. For some reason, we don’t need it with α twice
side1 : (n : ℕ) (a : A) (x : J n) → ap (α∞ a) (ap from (inJS-ι n x)) ∙
ap (α∞ a) (ap (α∞ ⋆A) (from-inJ n x)) ∙
ap (in∞ (S (S n))) (ap (α (S n) a) (β n x))
== from-inJSS-α n a (ι n x)
side1 n = λ a x → & coh (ap-∙ _ _ _) (ap-square (α∞ a) (from-inJS-ι n x)) (ap-α∞-in∞ (S n) a (β n x)) module Side1 where
coh : Coh ({A : Type i} {a c : A} {q : a == c} {d : A} {s1 : c == d} {b : A} {s2 : d == b} {s : c == b} (s= : s == s1 ∙ s2)
{p : a == b} (sq : Square p q idp s) {s2' : d == b} (s2= : s2 == s2')
→ q ∙ s1 ∙ s2' == p)
coh = path-induction
side2 : (n : ℕ) (a : A) (x : J n) → ap (α∞ ⋆A) (ap from (inJS-α n a x)) ∙
ap (α∞ ⋆A) (ap (α∞ a) (from-inJ n x)) ∙
ap (in∞ (S (S n))) (β (S n) (α n a x))
== from-inJSS-ι n (α n a x)
side2 n = λ a x → & coh (ap-square (α∞ ⋆A) (from-inJS-α n a x)) module Side2 where
coh : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q : a == c} {s : c == b} (sq : Square p q idp s) {e : A} {t : b == e}
→ q ∙ s ∙ t == p ∙ t)
coh = path-induction
side3 : (n : ℕ) (x : J n) → ap (α∞ ⋆A) (ap from (inJS-ι n x)) ∙
ap (α∞ ⋆A) (ap (α∞ ⋆A) (from-inJ n x)) ∙
ap (in∞ (S (S n))) (β (S n) (α n ⋆A x)) ∙
ap (in∞ (S (S n))) (ap (ι (S n)) (β n x))
== from-inJSS-ι n (ι n x)
side3 n = λ x → & coh (ap-∙ _ _ _) (ap-α∞-in∞ (S n) ⋆A (β n x)) (ap-square (α∞ ⋆A) (from-inJS-ι n x))
(ap-square (in∞ (S (S n))) (natural-square (β (S n)) (β n x) idp idp)) module Side3 where
coh : Coh ({A : Type i} {a c : A} {q : a == c} {d : A} {s : c == d} {b : A} {r : d == b} {rs : c == b} (rs= : rs == s ∙ r)
{r' : d == b} (r= : r == r') {p : a == b} (sq : Square p q idp rs)
{e : A} {t : d == e} {f : A} {u : e == f} {v : b == f} (sq2 : Square t r' u v)
→ q ∙ s ∙ t ∙ u == p ∙ v)
coh = path-induction
piece1 : (n : ℕ) (a : A) (x : J n) → Square (ap from (ap (inJS (S n)) (γ n a x)))
(ap (α∞ a) (ap from (inJS-ι n x)))
(ap (α∞ ⋆A) (ap from (inJS-α n a x)))
(ap from (γJ a (inJ n x)))
piece1 n a x = adapt-square (ap-square from (inJSS-γ n a x)) (ap-from-αJ a (inJS-ι n x)) (ap-from-αJ ⋆A (inJS-α n a x))
from-inJSS-γ : (n : ℕ) (a : A) (x : J n) → Square (ap from (ap (inJS (S n)) (γ n a x))) (from-inJSS-α n a (ι n x)) (from-inJSS-ι n (α n a x)) (ap (in∞ (S (S n))) (γ n a x))
from-inJSS-γ n a x = adapt-square (piece1 n a x
∙□ ap-from-γ a (inJ n x)
|∙ natural-square (γ∞ a) (from-inJ n x) (ap-∘ (α∞ a) (α∞ ⋆A) (from-inJ n x)) (ap-∘ (α∞ ⋆A) (α∞ a) (from-inJ n x))
∙□ γ∞-in a n x)
(side1 n a x) (side2 n a x)
adapt-eq : Coh ({A : Type i} {a b : A} {q : a == b} {sq : Square idp q q idp} (sq= : sq == vid-square) {q' : a == b} {p : q == q'} → adapt-square sq p p == vid-square)
adapt-eq = path-induction
natural-square-idp : {A B : Type i} {f : A → B} {x y : A} {p : x == y} {fp : f x == f y} {fp= : ap f p == fp} → natural-square (λ a → idp {a = f a}) p fp= fp= == vid-square
natural-square-idp {p = idp} {fp= = idp} = idp
vid-square∙□vid-square∙□vid-square : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q : b == c} {d : A} {r : c == d} → vid-square {p = p} ∙□ vid-square {p = q} ∙□ vid-square {p = r} == vid-square {p = p ∙ q ∙ r})
vid-square∙□vid-square∙□vid-square = path-induction
adapt-square-natural-square : ∀ {i j} {A : Type i} {B : Type j} → Coh ({f g : A → B} {h : (a : A) → f a == g a}
{x y : A} {p : x == y} {pf' : f x == f y} {q : ap f p == pf'} {pg' : g x == g y} {r : ap g p == pg'}
→ adapt-square (natural-square h p idp idp) q r == natural-square h p q r)
adapt-square-natural-square = path-induction
piece1-η : (n : ℕ) (x : J n) → Cube (ap-square from (ap-square (inJS (S n)) (η n x)))
(horiz-degen-square (ap (ap from) (ηJ (inJ n x))))
(piece1 n ⋆A x) vid-square _ _
piece1-η n x = & (ap-shapeInJSη from) {to = ηJ (inJ n x)} (inJSS-η n x) (ap-from-αJ ⋆A (inJS-α n ⋆A x)) (ap-from-αJ ⋆A (inJS-ι n x))
coh-blip : {A B : Type i} {a b : A} (p : a == b)
→ Coh ({f g : A → B} {k : (a : A) → f a == g a} {h : A → B} {l : (a : A) → g a == h a}
{fp : _} {fp= : ap f p == fp}
{gp : _} (gp= : ap g p == gp)
{hp : _} {hp= : ap h p == hp}
→ square-symmetry (natural-square (λ x → k x ∙ l x) p fp= hp=) == square-symmetry (natural-square k p fp= gp=) ∙□ square-symmetry (natural-square l p gp= hp=))
coh-blip {a = a} idp = path-induction
ap-square-hid : {A B : Type i} {f : A → B} {x y : A} {p : x == y} → ap-square f (hid-square {p = p}) == hid-square
ap-square-hid {p = idp} = idp
from-inJSS-η : (n : ℕ) (x : J n) → Cube (ap-square from (ap-square (inJS (S n)) (η n x)))
(ap-square (in∞ (S (S n))) (η n x))
(from-inJSS-γ n ⋆A x)
vid-square
(square-symmetry (natural-square (from-inJSS-ι n) (β n x) (ap-∘ _ _ _ ∙ ap-∘ _ _ _) (ap-∘ _ _ _)))
(from-inJSS-β n (ι n x))
from-inJSS-η n x =
adapt-cube (piece1-η n x
∙³x ap-from-η (inJ n x)
-|∙³ natural-cube-η∞ η∞ (from-inJ n x)
∙³x η∞-in n x)
(side1 n ⋆A x) (side2 n ⋆A x) (side1 n ⋆A x) (side3 n x)
idp
(& adapt-eq (& vid-square∙□vid-square∙□vid-square))
(& coh4 (ap-square-from-αJ ⋆A (inJS-β n x)) (& (ap-square-comp-square2 (α∞ ⋆A))) ap-square-hid (ap-cube (α∞ ⋆A) (from-inJS-β n x))
eq1
eq2
∙ ! (& (coh-blip (β n x)) (ap-∘ (in∞ (S (S n))) (α (S n) ⋆A) (β n x))))
(& coh (ap (ap from) (inJS-βS n (ι n x)))) where
coh : {A : Type i} {a : A} → Coh ({p : a == a} (sq : p == idp) {b : A} {s : a == b}
{c : A} {q : b == c} {d : A} {u u'' : c == d} {u= : u'' == u} {u' : b == d} {u'= : u' == q ∙ u''}
{e : A} {t : c == e} {f : A} {v : e == f} {w : d == f} {ββ : Square t u v w} {k : a == d} {X : Square k s idp u'}
→ adapt-square ((sq |∙ vid-square {p = s}) ∙□ idp |∙ vid-square {p = q} ∙□ skew ββ) (& (Side1.coh n) u'= X u=) (& (Side3.coh n) u'= u= X ββ)
== sq |∙ comp-square)
coh = path-induction
eq1 : natural-square (λ a₁ → ap (α∞ ⋆A) (from-inJS n a₁)) (β n x)
(ap-∘ (from ∘ inJS (S n)) inr (β n x) ∙
ap-∘ from (inJS (S n)) (ap inr (β n x)))
(ap-∘ (in∞ (S (S n))) (α (S n) ⋆A) (β n x))
== adapt-square (ap-square (α∞ ⋆A) (natural-square (from-inJS n) (β n x) (ap-∘ from (inJS n) (β n x)) idp)) (! (ap-from-αJ ⋆A (ap (inJS n) (β n x))) ∙ ! (ap (ap from) (ap-inJSS-ι n (β n x)))) (ap-α∞-in∞ (S n) ⋆A (β n x))
eq1 = & (natural-square-ap (α∞ ⋆A)) (β n x) (from-inJS n) (coh' (β n x)) (coh'' (β n x)) where
coh' : {x y : _} (p : x == y)
→ Square (∘-ap (α∞ ⋆A) (λ z → from (inJS n z)) p)
(ap (ap (α∞ ⋆A)) (ap-∘ from (inJS n) p))
(ap-∘ (from ∘ inJS (S n)) inr p
∙ ap-∘ from (inJS (S n)) (ap inr p))
(! (ap-from-αJ ⋆A (ap (inJS n) p))
∙ ! (ap (ap from) (ap-inJSS-ι n p)))
coh' idp = ids
coh'' : {x y : _} (p : x == y)
→ Square (∘-ap (α∞ ⋆A) (λ z → in∞ (S n) z) p)
idp
(ap-∘ (in∞ (S (S n))) (α (S n) ⋆A) p)
(ap-α∞-in∞ (S n) ⋆A p)
coh'' idp = ids
eq2 : ap-square (in∞ (S (S n))) (natural-square (β (S n)) (β n x) idp idp)
== natural-square (λ a₁ → ap (in∞ (S (S n))) (β (S n) a₁)) (β n x)
(ap-∘ (in∞ (S (S n))) (α (S n) ⋆A) (β n x))
(ap-∘ (in∞ (S (S n))) inr (β n x))
eq2 = & (ap-square-natural-square (in∞ (S (S n)))) (β n x) (β (S n)) ∙idp ∙idp
coh4 : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q q'' : a == c} {q''= : q'' == q} {q' : a == c}
{q'= : q' == q''} {d : A} {r r' : b == d} {r= : r == r'}
{s : c == d} {sq1 : Square p q r s} {e : A} {t : b == e} {f : A} {u : e == f} {v : d == f}
{sqββ : Square t r' u v} {g : A} {k k' : a == g} {k= : k == k'} {l : c == g}
{sq2 : Square q'' k l idp} {l' : c == g} {l= : l == l'} {u : g == b} {sqα : Square p k' idp u}
{ur : g == d} {ur= : ur == u ∙ r} {sq3 : Square q k' l' idp}
(cube-right : FlatCube sq2 sq3 q''= k= l= idp)
{comp-square2' : _} (comp-square2'= : FlatCube comp-square2' (& comp-square2) idp idp idp ur=)
{hid' : _} (hid'= : hid' == hid-square)
{sqι : Square s l' idp ur} (cube-left : Cube sq1 comp-square2' sqα sq3 hid' sqι)
{sqx : _} (eq1 : sqx == adapt-square sq1 (! q''= ∙ ! q'=) r=)
{sqy : _} (eq2 : sqββ == sqy)
→ adapt-square (adapt-square (q'= |∙ sq2) k= l= ∙□ vid-square {p = u} ∙□ comp-square) (& (Side2.coh n) sqα) (& (Side3.coh n) ur= r= sqι sqββ)
== square-symmetry sqx ∙□ square-symmetry sqy)
coh4 = path-induction
from-inJ O ε = idp
from-inJ (S n) x = from-inJS n x
hdpssvs : Coh ({A : Type i} {x y : A} {p : x == y} → idp == horiz-degen-path (square-symmetry (vid-square {p = p})))
hdpssvs = path-induction
from-inJS O a = idp
from-inJS (S n) =
JSS-elim n (from-inJSS-ι n)
(from-inJSS-α n)
(λ x → ↓-='-from-square (ap-∘ from (inJS (S n)) (β (S n) x)) idp (square-symmetry (from-inJSS-β n x)))
(λ a x → ↓-='-from-square (ap-∘ from (inJS (S n)) (γ n a x)) idp (square-symmetry (from-inJSS-γ n a x)))
(λ x → cube-to-↓-square (from-inJSS-γ n ⋆A x)
(& hdpssvs)
(↓-ap-in-=' (ι (S n)) (from-inJSS-ι n))
(from-inJSS-β n (ι n x))
(ap-square-∘ from (inJS (S n)) (η n x) |∙³ from-inJSS-η n x))
from-inJS-ι O ε = ids
from-inJS-ι (S n) x = hid-square
from-inJS-α O a ε = ids
from-inJS-α (S n) a x = hid-square
from-inJS-β O ε = idc
from-inJS-β (S n) x = & coh (ap-square-horiz-degen-square (inJS-βS n x))
(natural-square-β (from-inJS (S n)) (β (S n) x) (push-βd _)) where
coh : Coh ({A : Type i} {a b : A} {p : a == b} {q : a == a} {k : q == idp}
{k' : Square q idp idp idp} (k= : k' == horiz-degen-square k)
{c : A} {r : b == c} {sq : Square p q r (p ∙ r)} → sq == square-symmetry (k |∙ comp-square)
→ Cube sq (& comp-square2) hid-square k' hid-square hid-square)
coh = path-induction
from-pushJ : (n : ℕ) (x : J n) → Square (ap from (pushJ n x)) (from-inJ n x) (from-inJ (S n) (ι n x)) (push∞ n x)
from-pushJ n x = & coh (δJ-β (inJ n x)) (ap from (inJS-ι n x)) (ap-∙! from _ _)
(natural-square δ∞ (from-inJ n x) (ap-idf (from-inJ n x)) idp) (from-inJS-ι n x) where
coh : Coh ({A : Type i} {a d : A} {p p' : a == d} (p= : p == p')
{b : A} (q : b == d) {pq : a == b} (pq= : pq == p ∙ ! q)
{c : A} {r : a == c} {f : A} {u : c == f} {e : A} {v : e == f}
{s : d == e} (sq : Square p' r s (u ∙ ! v)) {t : b == f} (sq2 : Square t q idp (s ∙ v))
→ Square pq r t u)
coh = path-induction
from-to : (x : J∞A) → from (to x) == x
from-to = J∞A-elim from-inJ (λ n x → ↓-='-from-square (ap-∘ from to (push∞ n x) ∙ ap (ap from) (push∞-β n x)) (ap-idf (push∞ n x)) (square-symmetry (from-pushJ n x)))
| {
"alphanum_fraction": 0.4381989748,
"avg_line_length": 56.6600660066,
"ext": "agda",
"hexsha": "73a5f0f6cb2a9795768a93b3de077e31615073b0",
"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": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guillaumebrunerie/JamesConstruction",
"max_forks_repo_path": "JamesFirstComposite.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b",
"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/JamesConstruction",
"max_issues_repo_path": "JamesFirstComposite.agda",
"max_line_length": 229,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guillaumebrunerie/JamesConstruction",
"max_stars_repo_path": "JamesFirstComposite.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-16T22:10:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-07T04:34:52.000Z",
"num_tokens": 7308,
"size": 17168
} |
-- A binding to a Haskell natural numbers type
open import Data.Nat using ( ℕ ) renaming ( zero to zero' ; suc to suc' )
module Data.Natural where
open import Data.Natural.Primitive public
using ( Natural ; zero ; suc ; _+_ ; toString ; foldl ; foldl' ; foldr )
renaming ( fromℕ to # )
% : Natural → ℕ
% = foldr suc' zero'
| {
"alphanum_fraction": 0.670694864,
"avg_line_length": 25.4615384615,
"ext": "agda",
"hexsha": "22382a51ee783fd27c8efcabd325d58d64eb48de",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:40:14.000Z",
"max_forks_repo_head_hexsha": "84d51967e20bf248e9f73af37f52972922ffc77c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-data-bindings",
"max_forks_repo_path": "src/Data/Natural.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84d51967e20bf248e9f73af37f52972922ffc77c",
"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": "agda/agda-data-bindings",
"max_issues_repo_path": "src/Data/Natural.agda",
"max_line_length": 74,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "84d51967e20bf248e9f73af37f52972922ffc77c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-data-bindings",
"max_stars_repo_path": "src/Data/Natural.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T13:51:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-02T23:17:59.000Z",
"num_tokens": 93,
"size": 331
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
module cw.cohomology.InnerGrid {i} (OT : OrdinaryTheory i)
(n : ℤ) {X Y Z W : Ptd i} (f : X ⊙→ Y) (g : Y ⊙→ Z) (h : Z ⊙→ W) where
open OrdinaryTheory OT
open import cohomology.PtdMapSequence cohomology-theory
{-
X --> Y ---> Z ---> W
| | | |
v | v v
1 ----+---> Z/X -> W/X
| | this |
v v one v
1 --> Z/Y -> W/Y
-}
import cw.cohomology.GridPtdMap
open cw.cohomology.GridPtdMap (g ⊙∘ f) h using ()
renaming (Y/X-to-Z/X to Z/X-to-W/X; B/A-to-C/A to C/A-to-D/A;
module B/AToC/A to C/AToD/A)
open cw.cohomology.GridPtdMap f g
using (Z/X-to-Z/Y; C/A-to-C/B; module C/AToC/B)
open cw.cohomology.GridPtdMap f (h ⊙∘ g) using ()
renaming (Z/X-to-Z/Y to W/X-to-W/Y; C/A-to-C/B to D/A-to-D/B;
module C/AToC/B to D/AToD/B)
open cw.cohomology.GridPtdMap g h using ()
renaming (Y/X-to-Z/X to Z/Y-to-W/Y; B/A-to-C/A to C/B-to-D/B;
module B/AToC/A to C/BToD/B)
inner-grid-comm-sqr : CommSquare C/A-to-D/A C/B-to-D/B C/A-to-C/B D/A-to-D/B
inner-grid-comm-sqr = comm-sqr $ Cofiber-elim idp (λ _ → idp)
(λ a → ↓-='-in' $ ap-∘ C/B-to-D/B C/A-to-C/B (glue a)
∙ ap (ap C/B-to-D/B) (C/AToC/B.glue-β a)
∙ C/BToD/B.glue-β ((fst f) a)
∙ ! (D/AToD/B.glue-β a)
∙ ap (ap D/A-to-D/B) (! (C/AToD/A.glue-β a))
∙ ∘-ap D/A-to-D/B C/A-to-D/A (glue a))
C-inner-grid-commutes : CommSquareᴳ
(C-fmap n Z/Y-to-W/Y) (C-fmap n Z/X-to-W/X) (C-fmap n W/X-to-W/Y) (C-fmap n Z/X-to-Z/Y)
C-inner-grid-commutes = C-comm-square n inner-grid-comm-sqr
| {
"alphanum_fraction": 0.5256188831,
"avg_line_length": 32.7735849057,
"ext": "agda",
"hexsha": "7b0a7c756f9ae911376ea3a381f52e5f2006339d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/InnerGrid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/InnerGrid.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/InnerGrid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 679,
"size": 1737
} |
-- {-# OPTIONS -v tc.meta:50 #-}
-- Andreas 2012-03-27, record pattern unification
{-# OPTIONS --irrelevant-projections #-}
module Issue376-irrelevant-projections where
open import Common.Equality
open import Common.Irrelevance
bla4 : (A : Set) ->
let A' = Squash (Squash A) in
let X : .(z : A') -> (C : .A' -> Set) -> (.(z : A') -> C z) -> C z
X = _
in (a : A)(C : .A' -> Set)(k : .(z : A') -> C z) ->
X (squash (squash a)) C k ≡ k (squash (squash a))
bla4 A a C k = refl
| {
"alphanum_fraction": 0.5575757576,
"avg_line_length": 29.1176470588,
"ext": "agda",
"hexsha": "4bb182a70bafad623e18c24a7e8d861855197ab1",
"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/Issue376-irrelevant-projections.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/Issue376-irrelevant-projections.agda",
"max_line_length": 68,
"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/Issue376-irrelevant-projections.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": 182,
"size": 495
} |
{- 1. Booleans -}
data Bool : Set where
true : Bool
false : Bool
not : Bool → Bool
not true = false
not false = true
_∧_ : Bool → Bool → Bool
true ∧ true = true
true ∧ false = false
false ∧ true = false
false ∧ false = false
_∨_ : Bool → Bool → Bool
true ∨ true = true
true ∨ false = true
false ∨ true = true
false ∨ false = false
{- 2. Equality -}
data _≡_ {A : Set} (x : A) : (y : A) → Set where
refl : x ≡ x
infix 4 _≡_
not-inv : (b : Bool) → not (not b) ≡ b
not-inv true = refl
not-inv false = refl
f : (b : Bool) → (not b) ∧ b ≡ false
f true = refl
f false = refl
| {
"alphanum_fraction": 0.5829059829,
"avg_line_length": 15.3947368421,
"ext": "agda",
"hexsha": "b6f61cc449028916401ed577c8f3181101912d89",
"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": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "erwinkn/program-eq-proof",
"max_forks_repo_path": "TD6/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"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": "erwinkn/program-eq-proof",
"max_issues_repo_path": "TD6/Bool.agda",
"max_line_length": 48,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "erwinkn/program-eq-proof",
"max_stars_repo_path": "TD6/Bool.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 220,
"size": 585
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of left-scaling
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
-- The properties are parameterised by the two carriers and
-- the result equality.
module Algebra.Module.Definitions.Left
{a b ℓb} (A : Set a) {B : Set b} (_≈_ : Rel B ℓb)
where
open import Data.Sum
open import Data.Product
------------------------------------------------------------------------
-- Binary operations
open import Algebra.Core
------------------------------------------------------------------------
-- Properties of operations
LeftIdentity : A → Opₗ A B → Set _
LeftIdentity a _∙ᴮ_ = ∀ m → (a ∙ᴮ m) ≈ m
Associative : Op₂ A → Opₗ A B → Set _
Associative _∙ᴬ_ _∙ᴮ_ = ∀ x y m → ((x ∙ᴬ y) ∙ᴮ m) ≈ (x ∙ᴮ (y ∙ᴮ m))
_DistributesOverˡ_ : Opₗ A B → Op₂ B → Set _
_*_ DistributesOverˡ _+_ =
∀ x m n → (x * (m + n)) ≈ ((x * m) + (x * n))
_DistributesOverʳ_⟶_ : Opₗ A B → Op₂ A → Op₂ B → Set _
_*_ DistributesOverʳ _+ᴬ_ ⟶ _+ᴮ_ =
∀ x m n → ((m +ᴬ n) * x) ≈ ((m * x) +ᴮ (n * x))
LeftZero : A → B → Opₗ A B → Set _
LeftZero zᴬ zᴮ _∙_ = ∀ x → (zᴬ ∙ x) ≈ zᴮ
RightZero : B → Opₗ A B → Set _
RightZero z _∙_ = ∀ x → (x ∙ z) ≈ z
Commutative : Opₗ A B → Set _
Commutative _∙_ = ∀ x y m → (x ∙ (y ∙ m)) ≈ (y ∙ (x ∙ m))
LeftCongruent : Opₗ A B → Set _
LeftCongruent _∙_ = ∀ {x} → (x ∙_) Preserves _≈_ ⟶ _≈_
RightCongruent : ∀ {ℓa} → Rel A ℓa → Opₗ A B → Set _
RightCongruent ≈ᴬ _∙_ = ∀ {m} → (_∙ m) Preserves ≈ᴬ ⟶ _≈_
Congruent : ∀ {ℓa} → Rel A ℓa → Opₗ A B → Set _
Congruent ≈ᴬ ∙ = ∙ Preserves₂ ≈ᴬ ⟶ _≈_ ⟶ _≈_
| {
"alphanum_fraction": 0.4838520258,
"avg_line_length": 28.3833333333,
"ext": "agda",
"hexsha": "409344ec96accd42862e35e64bd7c49aec9d696f",
"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/Module/Definitions/Left.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/Module/Definitions/Left.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Module/Definitions/Left.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": 664,
"size": 1703
} |
------------------------------------------------------------------------------
-- Discussion about the inductive approach
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Andrés: From our discussion about the inductive approach, can I
-- conclude that it is possible to rewrite the proofs using pattern
-- matching on _≡_, by proofs using only subst, because the types
-- associated with these proofs haven't proof terms?
-- Peter: Yes, provided the RHS of the definition does not refer to the
-- function defined, i e, there is no recursion.
module FOT.FOTC.InductiveApproach.Recursion where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.PropertiesI
open import FOTC.Data.Nat
open import FOTC.Data.Nat.PropertiesI
------------------------------------------------------------------------------
-- foo is recursive and we pattern matching on _≡_.
foo : ∀ {m n} → N m → m ≡ n → N (m + n)
foo nzero refl = subst N (sym (+-leftIdentity zero)) nzero
foo (nsucc {m} Nm) refl = subst N helper (nsucc (nsucc (foo Nm refl)))
where
helper : succ₁ (succ₁ (m + m)) ≡ succ₁ m + succ₁ m
helper =
succ₁ (succ₁ (m + m)) ≡⟨ succCong (sym (+-Sx m m)) ⟩
succ₁ (succ₁ m + m) ≡⟨ succCong (+-comm (nsucc Nm) Nm) ⟩
succ₁ (m + succ₁ m) ≡⟨ sym (+-Sx m (succ₁ m)) ⟩
succ₁ m + succ₁ m ∎
-- foo' is recursive and we only use subst.
foo' : ∀ {m n} → N m → m ≡ n → N (m + n)
foo' {n = n} nzero h = subst N (sym (+-leftIdentity n)) (subst N h nzero)
foo' {n = n} (nsucc {m} Nm) h = subst N helper (nsucc (nsucc (foo' Nm refl)))
where
helper : succ₁ (succ₁ (m + m)) ≡ succ₁ m + n
helper =
succ₁ (succ₁ (m + m)) ≡⟨ succCong (sym (+-Sx m m)) ⟩
succ₁ (succ₁ m + m) ≡⟨ succCong (+-comm (nsucc Nm) Nm) ⟩
succ₁ (m + succ₁ m) ≡⟨ sym (+-Sx m (succ₁ m)) ⟩
succ₁ m + succ₁ m ≡⟨ +-rightCong h ⟩
succ₁ m + n ∎
| {
"alphanum_fraction": 0.5439429929,
"avg_line_length": 39.7169811321,
"ext": "agda",
"hexsha": "da14393a4f912cd00ae5048a3d40de0db4612ec8",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/InductiveApproach/Recursion.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/InductiveApproach/Recursion.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/InductiveApproach/Recursion.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": 652,
"size": 2105
} |
{-# OPTIONS --safe --without-K #-}
module Generics.Telescope where
open import Data.String using (String)
open import Generics.Prelude hiding (curry)
private variable
l : Level
A B : Set l
a x y : A
data Telescope (A : Set l) : Setω
private variable T : Telescope A
levelOfTel : Telescope A → Level
⟦_⟧tel : (T : Telescope A) → A → Set (levelOfTel T)
infixl 7 _⊢<_>_ _⊢_
data Telescope A where
ε : Telescope A
_⊢<_>_ : ∀ (T : Telescope A) (ai : String × ArgInfo) {ℓ} (f : Σ A ⟦ T ⟧tel → Set ℓ) → Telescope A
_⊢_ : ∀ (T : Telescope A) {ℓ} (f : Σ A ⟦ T ⟧tel → Set ℓ) → Telescope A
T ⊢ f = T ⊢< "_" , arg-info visible (modality relevant quantity-ω) > f
extendTel : (T : Telescope A) (f : ∀ {x} → ⟦ T ⟧tel x → Set l) → Telescope A
extendTel T f = T ⊢ f ∘ proj₂
infixr 3 extendTel
syntax extendTel A (λ x → B) = x ∶ A , B
levelOfTel ε = lzero
levelOfTel (_⊢<_>_ T _ {ℓ} f) = levelOfTel T ⊔ ℓ
⟦ ε ⟧tel x = ⊤
⟦ T ⊢< n , i > f ⟧tel x = Σ[ t ∈ ⟦ T ⟧tel x ] < relevance i > f (x , t)
hideInfo : ArgInfo → ArgInfo
hideInfo i = arg-info hidden (getModality i)
ExTele : Telescope ⊤ → Setω
ExTele T = Telescope (⟦ T ⟧tel tt)
⟦_,_⟧xtel : (P : Telescope ⊤) (I : ExTele P) → Set (levelOfTel P ⊔ levelOfTel I)
⟦ P , V ⟧xtel = Σ (⟦ P ⟧tel tt) ⟦ V ⟧tel
⟦_,_&_⟧xtel : (P : Telescope ⊤) (V I : ExTele P) → Set (levelOfTel P ⊔ levelOfTel V ⊔ levelOfTel I)
⟦ P , V & I ⟧xtel = Σ[ p ∈ ⟦ P ⟧tel tt ] ⟦ V ⟧tel p × ⟦ I ⟧tel p
----------------------
-- Telescope currying
Curried′ : (T : Telescope A) → (⟦ T ⟧tel x → Set l) → Set (l ⊔ levelOfTel T)
Curried′ ε P = P tt
Curried′ (T ⊢< ai > g) P = Curried′ T λ t → Π< ai > (g (_ , t)) λ y → P (t , y)
Pred′ : (T : Telescope A) → (⟦ T ⟧tel x → Set l) → Set (l ⊔ levelOfTel T)
Pred′ ε P = P tt
Pred′ (T ⊢< n , i > g) P = Pred′ T λ t → Π< n , hideInfo i > (g (_ , t)) λ y → P (t , y)
uncurry′ : (T : Telescope A) (P : ⟦ T ⟧tel x → Set l) (B : Curried′ T P) → (y : ⟦ T ⟧tel x) → P y
uncurry′ ε P B tt = B
uncurry′ (T ⊢< i > f) P B (tx , gx) =
app< i > (uncurry′ T (λ p → Π< i > (f (_ , p)) (λ y → P (p , y))) B tx) _
curry′ : (T : Telescope A) (P : ⟦ T ⟧tel x → Set l) → ((y : ⟦ T ⟧tel x) → P y) → Curried′ T P
curry′ ε P f = f tt
curry′ (T ⊢< i > S) P f =
curry′ T _ λ t → fun< i > λ s → f (t , s)
unpred′ : (T : Telescope A) (P : ⟦ T ⟧tel x → Set l) (B : Pred′ T P) → (y : ⟦ T ⟧tel x) → P y
unpred′ ε P B tt = B
unpred′ (T ⊢< n , i > f) P B (tx , gx) =
app< n , hideInfo i > (unpred′ T (λ p → Π< n , hideInfo i > (f (_ , p)) λ y → P (p , y)) B tx) _
pred′ : (T : Telescope A) (P : ⟦ T ⟧tel x → Set l) → ((y : ⟦ T ⟧tel x) → P y) → Pred′ T P
pred′ ε P f = f tt
pred′ (T ⊢< n , i > S) P f =
pred′ T _ λ t → fun< n , hideInfo i > λ s → f (t , s)
Curried : ∀ P (I : ExTele P) {ℓ} (Pr : ⟦ P , I ⟧xtel → Set ℓ) → Set (levelOfTel P ⊔ levelOfTel I ⊔ ℓ)
Curried P I {ℓ} Pr = Curried′ P λ p → Curried′ I λ i → Pr (p , i)
curry : ∀ {P} {I : ExTele P} {ℓ} {Pr : ⟦ P , I ⟧xtel → Set ℓ}
→ ((pi : ⟦ P , I ⟧xtel) → Pr pi) → Curried P I Pr
curry f = curry′ _ _ λ p → curry′ _ _ λ i → f (p , i)
uncurry : ∀ P (I : ExTele P) {ℓ} {Pr : ⟦ P , I ⟧xtel → Set ℓ} → Curried P I Pr → (pi : ⟦ P , I ⟧xtel) → Pr pi
uncurry P I C (p , i) = uncurry′ I _ (uncurry′ P _ C p) i
-- Type of parametrized, indexed sets: (p₁ : A₁) ... (pₙ : Aₙ) (i₁ : B₁) ... (iₚ : Bₚ) → Set ℓ
Indexed : ∀ P (I : ExTele P) ℓ → Set (levelOfTel P ⊔ levelOfTel I ⊔ lsuc ℓ)
Indexed P I ℓ = Curried P I (const (Set ℓ))
unindexed : ∀ P (I : ExTele P) ℓ → Indexed P I ℓ → ⟦ P , I ⟧xtel → Set ℓ
unindexed P I ℓ = uncurry P I
-- Type of predicates on parametrized & indexed families:
-- {p₁ : A₁} ... {pₙ : Aₙ} {i₁ : B₁} ... {iₚ : Bₚ} → X (p₁ ... iₚ) → Set ℓ
Pred : ∀ P (I : ExTele P) {a} (X : ⟦ P , I ⟧xtel → Set a) ℓ
→ Set (levelOfTel P ⊔ levelOfTel I ⊔ a ⊔ lsuc ℓ)
Pred P I X ℓ = Pred′ P λ p → Pred′ I λ i → X (p , i) → Set ℓ
unpred : ∀ P (I : ExTele P) {a} {X : ⟦ P , I ⟧xtel → Set a} ℓ → Pred P I X ℓ
→ (pi : ⟦ P , I ⟧xtel) → X pi → Set ℓ
unpred P I ℓ C (p , i) = unpred′ I _ (unpred′ P _ C p) i
| {
"alphanum_fraction": 0.5171817058,
"avg_line_length": 34.8706896552,
"ext": "agda",
"hexsha": "82b089c9bff2f1023e98500dfaac51e09149fbce",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Telescope.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Telescope.agda",
"max_line_length": 109,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Telescope.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 1854,
"size": 4045
} |
{-
Basic properties of the Can function and utilities used in the reasoning.
The basic properties of the Can function include
- Can-θ function shadows the environment
canθ-shadowing-irr' : ∀ sigs' S'' p S status θ θo →
S ∈ map (_+_ S'') (SigMap.keys sigs') →
Canθ sigs' S'' p ((θ ← [ (S ₛ) ↦ status ]) ← θo) ≡
Canθ sigs' S'' p (θ ← θo)
canθ-shadowing-irr : ∀ sigs' S'' p S status θ →
Signal.unwrap S ∈ map (_+_ S'') (SigMap.keys sigs') →
Canθ sigs' S'' p θ ≡
Canθ sigs' S'' p (θ ← [ S ↦ status ])
- Can only look at signals in the environment. Actually, if we define Can on top
of SigMap instead of the whole Env, this would be unnecessary:
can-shr-var-irr : ∀ p θ θ' →
Env.sig θ ≡ Env.sig θ' →
Can p θ ≡ Can p θ'
- term-nothing captures those terms that cause a side-effect and reduce to nothin.
canₖ-term-nothin : ∀ {r} θ → term-nothin r → Canₖ r θ ≡ (Code.nothin ∷ [])
So the result of the Can function will not change:
canₖ-term-nothin-lemma : ∀ {r₁ r₂} θ E →
term-nothin r₁ → term-nothin r₂ →
∀ k →
k ∈ Canₖ (E ⟦ r₁ ⟧e) θ →
k ∈ Canₖ (E ⟦ r₂ ⟧e) θ
- paused terms have return code pause.
canₖ-paused : ∀ {p} θ → paused p → Canₖ p θ ≡ (Code.pause ∷ [])
- done terms basically do nothing -- their Canₛ and Canₛₕ are empty.
canₛ-done : ∀ {p} θ → done p → Canₛ p θ ≡ []
- Canₛ and Canₛₕ only captures free variables -- bound variables are removed. This
property has a weaker converse: emit S and s ⇐ e in some *evaluation context*
will be captured by Can.
canₛ-⊆-FV-lemma : ∀ {p BV FV} θ →
CorrectBinding p BV FV →
∀ S →
S ∈ Canₛ p θ →
S ∈ proj₁ FV
(and its canₛₕ counterpart)
canₛ-capture-emit-signal : ∀ {p S E} θ →
p ≐ E ⟦ emit S ⟧e →
Signal.unwrap S ∈ Canₛ p θ
canₛₕ-capture-set-shared : ∀ {p s e E} θ →
p ≐ E ⟦ s ⇐ e ⟧e →
SharedVar.unwrap s ∈ Canₛₕ p θ
- Subset relation of Can bubbles up through Canθ (a weaker version). Note that
the lemmas for codes and shared variables requires subset relation of the
signals as well.
canθₛ-subset : ∀ sigs S'' p q θ →
(∀ θ' S →
Signal.unwrap S ∈ Canₛ p θ' →
Signal.unwrap S ∈ Canₛ q θ') →
∀ S →
Signal.unwrap S ∈ Canθₛ sigs S'' p θ →
Signal.unwrap S ∈ Canθₛ sigs S'' q θ
canθₛₕ-subset : ∀ sigs S'' p q θ →
(∀ θ' S →
Signal.unwrap S ∈ Canₛ p θ' →
Signal.unwrap S ∈ Canₛ q θ') →
(∀ θ' s →
SharedVar.unwrap s ∈ Canₛₕ p θ' →
SharedVar.unwrap s ∈ Canₛₕ q θ') →
∀ s →
SharedVar.unwrap s ∈ Canθₛₕ sigs S'' p θ →
SharedVar.unwrap s ∈ Canθₛₕ sigs S'' q θ
canθ'ₛ-subset-lemma : ∀ sigs S'' κ κ' θ →
(∀ θ' S → S ∈ proj₁ (κ θ') → S ∈ proj₁ (κ' θ')) →
(∀ θ S status S' →
S' ∈ proj₁ (κ' (θ ← Θ SigMap.[ S ↦ status ] ShrMap.empty VarMap.empty)) →
S' ∈ proj₁ (κ' (θ ← [S]-env S))) →
∀ S → S ∈ proj₁ (Canθ' sigs S'' κ θ) → S ∈ proj₁ (Canθ' sigs S'' κ' θ)
- Certain type of mootonicity relationship between the Can-θ function
and the evaluation context
canθₛ-p⊆canθₛ-E₁⟦p⟧ : ∀ sigs S'' θ E₁ pin →
∀ S' →
Signal.unwrap S' ∈ Canθₛ sigs S'' pin θ →
Signal.unwrap S' ∈ Canθₛ sigs S'' ((E₁ ∷ []) ⟦ pin ⟧e) θ
canθₛ-E₁⟦p⟧⊆canθₛ-p : ∀ {pin E₁ E₁⟦nothin⟧ BV FV} sigs S'' θ →
E₁⟦nothin⟧ ≐ (E₁ ∷ []) ⟦ nothin ⟧e →
CorrectBinding E₁⟦nothin⟧ BV FV →
distinct' (map (_+_ S'') (SigMap.keys sigs)) (proj₁ FV) →
∀ S' →
Signal.unwrap S' ∉ proj₁ FV →
Signal.unwrap S' ∈ Canθₛ sigs S'' ((E₁ ∷ []) ⟦ pin ⟧e) θ →
Signal.unwrap S' ∈ Canθₛ sigs S'' pin θ
-}
module Esterel.Lang.CanFunction.Base where
open import utility
renaming (_U̬_ to _∪_ ; _|̌_ to _-_)
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.SetSigMonotonic public -- weird dependency here
open import Esterel.Lang.Properties
using (halted ; paused ; done)
open import Esterel.Context
using (EvaluationContext1 ; EvaluationContext ; _⟦_⟧e ; _≐_⟦_⟧e)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open EvaluationContext1
open _≐_⟦_⟧e
open import Data.Bool
using (Bool ; not ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; [] ; _∷_ ; _++_ ; map)
open import Data.List.Properties
using (map-id)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using (++⁻)
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _≟_ ; _+_)
open import Data.Nat.Properties.Simple
using (+-comm ; +-right-identity)
open import Data.Product
using (Σ ; proj₁ ; proj₂ ; ∃ ; _,_ ; _,′_ ; _×_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function
using (_∘_ ; id ; _∋_)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; trans ; sym ; cong ; subst)
open halted
open paused
open done
open ListSet Data.Nat._≟_
using (set-subtract ; set-subtract-[] ; set-subtract-merge ; set-subtract-split ;
set-remove ; set-remove-removed ; set-remove-mono-∈ ; set-remove-not-removed ;
set-subtract-[a]≡set-remove)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
-- Shorter local notation used in Can lemmas
[_↦_] : Signal → Signal.Status → Env
[ S ↦ status ] = Θ SigMap.[ S ↦ status ] ShrMap.empty VarMap.empty
data term-nothin : Term → Set where
tnothin : term-nothin nothin
temit : ∀ S → term-nothin (emit S)
tset-shr : ∀ s e → term-nothin (s ⇐ e)
tset-var : ∀ x e → term-nothin (x ≔ e)
data term-raise : ShrMap.Map (SharedVar.Status × ℕ) → VarMap.Map ℕ → Term → Term → Set where
tshared : ∀ n s e p →
term-raise ShrMap.[ s ↦ (SharedVar.old ,′ n) ]
VarMap.empty
(shared s ≔ e in: p) p
tvar : ∀ n x e p →
term-raise ShrMap.empty
VarMap.[ x ↦ n ]
(var x ≔ e in: p) p
canₖ-term-nothin : ∀ {r} θ → term-nothin r → Canₖ r θ ≡ (Code.nothin ∷ [])
canₖ-term-nothin θ tnothin = refl
canₖ-term-nothin θ (temit S) = refl
canₖ-term-nothin θ (tset-shr s e) = refl
canₖ-term-nothin θ (tset-var x e) = refl
canₖ-paused : ∀ {p} θ → paused p → Canₖ p θ ≡ (Code.pause ∷ [])
canₖ-paused θ ppause = refl
canₖ-paused θ (psuspend p/paused) rewrite canₖ-paused θ p/paused = refl
canₖ-paused θ (ptrap p/paused) rewrite canₖ-paused θ p/paused = refl
canₖ-paused θ (ppar p/paused q/paused)
rewrite canₖ-paused θ p/paused | canₖ-paused θ q/paused
= refl
canₖ-paused {p >> q} θ (pseq p/paused) with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | no nothin∉can-p rewrite canₖ-paused θ p/paused = refl
... | yes nothin∈can-p rewrite canₖ-paused θ p/paused with nothin∈can-p
... | here ()
... | there ()
canₖ-paused {loopˢ p q} θ (ploopˢ p/paused) = canₖ-paused θ p/paused
canₛ-done : ∀ {p} θ → done p → Canₛ p θ ≡ []
canₛ-done θ (dhalted hnothin) = refl
canₛ-done θ (dhalted (hexit _)) = refl
canₛ-done θ (dpaused ppause) = refl
canₛ-done θ (dpaused (ppar p/paused q/paused))
rewrite canₛ-done θ (dpaused p/paused) | canₛ-done θ (dpaused q/paused)
= refl
canₛ-done θ (dpaused (psuspend p/paused))
rewrite canₛ-done θ (dpaused p/paused)
= refl
canₛ-done θ (dpaused (ptrap p/paused))
rewrite canₛ-done θ (dpaused p/paused)
= refl
canₛ-done {loopˢ p q} θ (dpaused (ploopˢ p/paused)) = canₛ-done θ (dpaused p/paused)
canₛ-done {p >> q} θ (dpaused (pseq p/paused)) with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | no nothin∉can-p rewrite canₛ-done θ (dpaused p/paused) = refl
... | yes nothin∈can-p rewrite canₖ-paused θ p/paused with nothin∈can-p
... | here ()
... | there ()
canₛₕ-done : ∀ {p} θ → done p → Canₛₕ p θ ≡ []
canₛₕ-done θ (dhalted hnothin) = refl
canₛₕ-done θ (dhalted (hexit _)) = refl
canₛₕ-done θ (dpaused ppause) = refl
canₛₕ-done θ (dpaused (ppar p/paused q/paused))
rewrite canₛₕ-done θ (dpaused p/paused) | canₛₕ-done θ (dpaused q/paused)
= refl
canₛₕ-done θ (dpaused (psuspend p/paused))
rewrite canₛₕ-done θ (dpaused p/paused)
= refl
canₛₕ-done θ (dpaused (ptrap p/paused))
rewrite canₛₕ-done θ (dpaused p/paused)
= refl
canₛₕ-done {loopˢ p q} θ (dpaused (ploopˢ p/paused)) = canₛₕ-done θ (dpaused p/paused)
canₛₕ-done {p >> q} θ (dpaused (pseq p/paused)) with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | no nothin∉can-p rewrite canₛₕ-done θ (dpaused p/paused) = refl
... | yes nothin∈can-p rewrite canₖ-paused θ p/paused with nothin∈can-p
... | here ()
... | there ()
can-shr-var-irr : ∀ p θ θ' →
Env.sig θ ≡ Env.sig θ' →
Can p θ ≡ Can p θ'
canθ-shr-var-irr : ∀ sigs S'' p θ θ' →
Env.sig θ ≡ Env.sig θ' →
Canθ sigs S'' p θ ≡ Canθ sigs S'' p θ'
canθ-shr-var-irr [] S'' p θ θ' θₛ≡θ'ₛ = can-shr-var-irr p θ θ' θₛ≡θ'ₛ
canθ-shr-var-irr (just Signal.present ∷ sigs) S'' p θ θ' θₛ≡θ'ₛ
rewrite canθ-shr-var-irr sigs (suc S'') p
(θ ← [S]-env-present (S'' ₛ))
(θ' ← [S]-env-present (S'' ₛ))
(cong (λ sig* → SigMap.union sig* (Env.sig ([S]-env-present (S'' ₛ)))) θₛ≡θ'ₛ)
= refl
canθ-shr-var-irr (just Signal.absent ∷ sigs) S'' p θ θ' θₛ≡θ'ₛ
rewrite canθ-shr-var-irr sigs (suc S'') p
(θ ← [S]-env-absent (S'' ₛ))
(θ' ← [S]-env-absent (S'' ₛ))
(cong (λ sig* → SigMap.union sig* (Env.sig ([S]-env-absent (S'' ₛ)))) θₛ≡θ'ₛ)
= refl
canθ-shr-var-irr (just Signal.unknown ∷ sigs) S'' p θ θ' θₛ≡θ'ₛ
with any (S'' ≟_) (proj₁ (Canθ sigs (suc S'') p (θ ← [S]-env (S'' ₛ))))
| any (S'' ≟_) (proj₁ (Canθ sigs (suc S'') p (θ' ← [S]-env (S'' ₛ))))
... | yes S''∈canθ-θ←[S] | yes S''∈canθ-θ'←[S]
rewrite canθ-shr-var-irr sigs (suc S'') p
(θ ← [S]-env (S'' ₛ))
(θ' ← [S]-env (S'' ₛ))
(cong (λ sig* → SigMap.union sig* (Env.sig ([S]-env (S'' ₛ)))) θₛ≡θ'ₛ)
= refl
... | no S''∉canθ-θ←[S] | no S''∉canθ-θ'←[S]
rewrite canθ-shr-var-irr sigs (suc S'') p
(θ ← [S]-env-absent (S'' ₛ))
(θ' ← [S]-env-absent (S'' ₛ))
(cong (λ sig* → SigMap.union sig* (Env.sig ([S]-env-absent (S'' ₛ)))) θₛ≡θ'ₛ)
= refl
... | no S''∉canθ-θ←[S] | yes S''∈canθ-θ'←[S]
rewrite canθ-shr-var-irr sigs (suc S'') p
(θ ← [S]-env (S'' ₛ))
(θ' ← [S]-env (S'' ₛ))
(cong (λ sig* → SigMap.union sig* (Env.sig ([S]-env (S'' ₛ)))) θₛ≡θ'ₛ)
= ⊥-elim (S''∉canθ-θ←[S] S''∈canθ-θ'←[S])
... | yes S''∈canθ-θ←[S] | no S''∉canθ-θ'←[S]
rewrite canθ-shr-var-irr sigs (suc S'') p
(θ ← [S]-env (S'' ₛ))
(θ' ← [S]-env (S'' ₛ))
(cong (λ sig* → SigMap.union sig* (Env.sig ([S]-env (S'' ₛ)))) θₛ≡θ'ₛ)
= ⊥-elim (S''∉canθ-θ'←[S] S''∈canθ-θ←[S])
canθ-shr-var-irr (nothing ∷ sigs) S'' p θ θ' θₛ≡θ'ₛ
rewrite canθ-shr-var-irr sigs (suc S'') p θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr nothin θ θ' θₛ≡θ'ₛ = refl
can-shr-var-irr pause θ θ' θₛ≡θ'ₛ = refl
can-shr-var-irr (signl S p) θ θ' θₛ≡θ'ₛ
rewrite canθ-shr-var-irr (Env.sig ([S]-env S)) 0 p θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr (present S ∣⇒ p ∣⇒ q) (Θ Ss ss xs) (Θ .Ss ss' xs') refl
with Env.Sig∈ S (Θ Ss ss xs)
... | yes S∈
rewrite can-shr-var-irr p (Θ Ss ss xs) (Θ Ss ss' xs') refl
| can-shr-var-irr q (Θ Ss ss xs) (Θ Ss ss' xs') refl
= refl
... | no S∉
rewrite can-shr-var-irr p (Θ Ss ss xs) (Θ Ss ss' xs') refl
| can-shr-var-irr q (Θ Ss ss xs) (Θ Ss ss' xs') refl
= refl
can-shr-var-irr (emit S) θ θ' θₛ≡θ'ₛ = refl
can-shr-var-irr (p ∥ q) θ θ' θₛ≡θ'ₛ
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
| can-shr-var-irr q θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr (loop p) θ θ' θₛ≡θ'ₛ =
can-shr-var-irr p θ θ' θₛ≡θ'ₛ
can-shr-var-irr (loopˢ p q) θ θ' θₛ≡θ'ₛ = can-shr-var-irr p θ θ' θₛ≡θ'ₛ
can-shr-var-irr (p >> q) θ θ' θₛ≡θ'ₛ
with any (Code._≟_ Code.nothin) (Canₖ p θ)
| any (Code._≟_ Code.nothin) (Canₖ p θ')
... | yes nothin∈can-p-θ | yes nothin∈can-p-θ'
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
| can-shr-var-irr q θ θ' θₛ≡θ'ₛ
= refl
... | yes nothin∈can-p-θ | (no nothin∉can-p-θ')
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
= ⊥-elim (nothin∉can-p-θ' nothin∈can-p-θ)
... | no nothin∉can-p-θ | yes nothin∈can-p-θ'
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
= ⊥-elim (nothin∉can-p-θ nothin∈can-p-θ')
... | no nothin∉can-p-θ | no nothin∉can-p-θ'
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr (suspend p S) θ θ' θₛ≡θ'ₛ =
can-shr-var-irr p θ θ' θₛ≡θ'ₛ
can-shr-var-irr (trap p) θ θ' θₛ≡θ'ₛ
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr (exit x) θ θ' θₛ≡θ'ₛ = refl
can-shr-var-irr (shared s ≔ e in: p) θ θ' θₛ≡θ'ₛ
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr (s ⇐ e) θ θ' θₛ≡θ'ₛ = refl
can-shr-var-irr (var x ≔ e in: p) θ θ' θₛ≡θ'ₛ
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr (x ≔ e) θ θ' θₛ≡θ'ₛ = refl
can-shr-var-irr (if x ∣⇒ p ∣⇒ q) θ θ' θₛ≡θ'ₛ
rewrite can-shr-var-irr p θ θ' θₛ≡θ'ₛ
| can-shr-var-irr q θ θ' θₛ≡θ'ₛ
= refl
can-shr-var-irr (ρ⟨ θ'' , A ⟩· p) θ θ' θₛ≡θ'ₛ
rewrite canθ-shr-var-irr (Env.sig θ'') 0 p θ θ' θₛ≡θ'ₛ
= refl
canₛ-capture-emit-signal : ∀ {p S E} θ →
p ≐ E ⟦ emit S ⟧e →
Signal.unwrap S ∈ Canₛ p θ
canₛ-capture-emit-signal θ dehole = here refl
canₛ-capture-emit-signal θ (depar₁ p≐E⟦emit⟧) =
++ˡ (canₛ-capture-emit-signal θ p≐E⟦emit⟧)
canₛ-capture-emit-signal {p ∥ _} θ (depar₂ p≐E⟦emit⟧) =
++ʳ (Canₛ p θ) (canₛ-capture-emit-signal θ p≐E⟦emit⟧)
canₛ-capture-emit-signal {loopˢ p _} θ (deloopˢ p≐E⟦emit⟧) = canₛ-capture-emit-signal θ p≐E⟦emit⟧
canₛ-capture-emit-signal {p >> _} θ (deseq p≐E⟦emit⟧)
with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | yes nothin∈can-p = ++ˡ (canₛ-capture-emit-signal θ p≐E⟦emit⟧)
... | no nothin∉can-p = canₛ-capture-emit-signal θ p≐E⟦emit⟧
canₛ-capture-emit-signal θ (desuspend p≐E⟦emit⟧) =
canₛ-capture-emit-signal θ p≐E⟦emit⟧
canₛ-capture-emit-signal θ (detrap p≐E⟦emit⟧) =
canₛ-capture-emit-signal θ p≐E⟦emit⟧
canₛₕ-capture-set-shared : ∀ {p s e E} θ →
p ≐ E ⟦ s ⇐ e ⟧e →
SharedVar.unwrap s ∈ Canₛₕ p θ
canₛₕ-capture-set-shared θ dehole = here refl
canₛₕ-capture-set-shared θ (depar₁ p≐E⟦s⇐e⟧) =
++ˡ (canₛₕ-capture-set-shared θ p≐E⟦s⇐e⟧)
canₛₕ-capture-set-shared {p ∥ _} θ (depar₂ q≐E⟦s⇐e⟧) =
++ʳ (Canₛₕ p θ) (canₛₕ-capture-set-shared θ q≐E⟦s⇐e⟧)
canₛₕ-capture-set-shared {loopˢ p _} θ (deloopˢ p≐E⟦s⇐e⟧) = canₛₕ-capture-set-shared θ p≐E⟦s⇐e⟧
canₛₕ-capture-set-shared {p >> _} θ (deseq p≐E⟦s⇐e⟧)
with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | yes nothin∈can-p = ++ˡ (canₛₕ-capture-set-shared θ p≐E⟦s⇐e⟧)
... | no nothin∉can-p = canₛₕ-capture-set-shared θ p≐E⟦s⇐e⟧
canₛₕ-capture-set-shared θ (desuspend p≐E⟦s⇐e⟧) =
canₛₕ-capture-set-shared θ p≐E⟦s⇐e⟧
canₛₕ-capture-set-shared θ (detrap p≐E⟦s⇐e⟧) =
canₛₕ-capture-set-shared θ p≐E⟦s⇐e⟧
canθₛ-membership : ∀ sigs S'' p θ S →
(∀ θ' → Signal.unwrap S ∈ Canₛ p θ') →
Signal.unwrap S ∈ Canθₛ sigs S'' p θ
canθₛ-membership [] S'' p θ S S∈can-p = S∈can-p θ
canθₛ-membership (nothing ∷ sigs) S'' p θ S S∈can-p =
canθₛ-membership sigs (suc S'') p θ S S∈can-p
canθₛ-membership (just Signal.present ∷ sigs) S'' p θ S S∈can-p =
canθₛ-membership sigs (suc S'') p (θ ← [S]-env-present (S'' ₛ)) S S∈can-p
canθₛ-membership (just Signal.absent ∷ sigs) S'' p θ S S∈can-p =
canθₛ-membership sigs (suc S'') p (θ ← [S]-env-absent (S'' ₛ)) S S∈can-p
canθₛ-membership (just Signal.unknown ∷ sigs) S'' p θ S S∈can-p
with any (_≟_ S'') (Canθₛ sigs (suc S'') p (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-p-θ←[S''] =
canθₛ-membership sigs (suc S'') p (θ ← [S]-env (S'' ₛ)) S S∈can-p
... | no S''∉canθ-p-θ←[S''] =
canθₛ-membership sigs (suc S'') p (θ ← [S]-env-absent (S'' ₛ)) S S∈can-p
canθₛₕ-membership : ∀ sigs S'' p θ s →
(∀ θ' → SharedVar.unwrap s ∈ Canₛₕ p θ') →
SharedVar.unwrap s ∈ Canθₛₕ sigs S'' p θ
canθₛₕ-membership [] S'' p θ s s∈can-p = s∈can-p θ
canθₛₕ-membership (nothing ∷ sigs) S'' p θ s s∈can-p =
canθₛₕ-membership sigs (suc S'') p θ s s∈can-p
canθₛₕ-membership (just Signal.present ∷ sigs) S'' p θ s s∈can-p =
canθₛₕ-membership sigs (suc S'') p (θ ← [S]-env-present (S'' ₛ)) s s∈can-p
canθₛₕ-membership (just Signal.absent ∷ sigs) S'' p θ s s∈can-p =
canθₛₕ-membership sigs (suc S'') p (θ ← [S]-env-absent (S'' ₛ)) s s∈can-p
canθₛₕ-membership (just Signal.unknown ∷ sigs) S'' p θ s s∈can-p
with any (_≟_ S'') (Canθₛ sigs (suc S'') p (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-p-θ←[S''] =
canθₛₕ-membership sigs (suc S'') p (θ ← [S]-env (S'' ₛ)) s s∈can-p
... | no S''∉canθ-p-θ←[S''] =
canθₛₕ-membership sigs (suc S'') p (θ ← [S]-env-absent (S'' ₛ)) s s∈can-p
canₛ-⊆-FV-lemma : ∀ {p BV FV} θ →
CorrectBinding p BV FV →
∀ S →
S ∈ Canₛ p θ →
S ∈ proj₁ FV
canθₛ-⊆-FV-lemma : ∀ {p BV FV} sigs S'' θ →
CorrectBinding p BV FV →
∀ S →
S ∈ proj₁ (Canθ sigs S'' p θ) →
S ∈ proj₁ FV
canθₛ-⊆-FV-lemma {FV = FV} [] S'' θ cb S S∈canθ-p-θ =
canₛ-⊆-FV-lemma θ cb S S∈canθ-p-θ
canθₛ-⊆-FV-lemma (just Signal.present ∷ sigs) S'' θ cb S S∈canθ-p-θ =
canθₛ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env-present (S'' ₛ)) cb S S∈canθ-p-θ
canθₛ-⊆-FV-lemma (just Signal.absent ∷ sigs) S'' θ cb S S∈canθ-p-θ =
canθₛ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) cb S S∈canθ-p-θ
canθₛ-⊆-FV-lemma {p} (just Signal.unknown ∷ sigs) S'' θ cb S S∈canθ-p-θ
with any (S'' ≟_) (proj₁ (Canθ sigs (suc S'') p (θ ← [S]-env (S'' ₛ))))
... | yes S''∈canθ-p-θ←[S] =
canθₛ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env (S'' ₛ)) cb S S∈canθ-p-θ
... | no S''∉canθ-p-θ←[S] =
canθₛ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) cb S S∈canθ-p-θ
canθₛ-⊆-FV-lemma (nothing ∷ sigs) S'' θ cb S S∈canθ-p-θ =
canθₛ-⊆-FV-lemma sigs (suc S'') θ cb S S∈canθ-p-θ
canₛ-⊆-FV-lemma θ CBnothing S ()
canₛ-⊆-FV-lemma θ CBpause S ()
canₛ-⊆-FV-lemma {signl S' p} θ (CBsig {FV = FV} cb) S S∈can-sig-p
with Signal.unwrap S' Data.Nat.≟ S
... | yes refl =
⊥-elim (set-remove-removed {S} {Canθₛ (Env.sig ([S]-env S')) 0 p θ} S∈can-sig-p)
... | no S'≢S
rewrite set-subtract-[a]≡set-remove (proj₁ FV) (Signal.unwrap S')
= set-remove-not-removed S'≢S
(canθₛ-⊆-FV-lemma (Env.sig ([S]-env S')) 0 θ cb S
(set-remove-mono-∈ (Signal.unwrap S') S∈can-sig-p))
canₛ-⊆-FV-lemma {present S' ∣⇒ p ∣⇒ q} θ (CBpresent {FVp = FVp} cbp cbq) S S∈can-S'?p:q
with Env.Sig∈ S' θ
canₛ-⊆-FV-lemma {present S' ∣⇒ p ∣⇒ q} θ (CBpresent {FVp = FVp} cbp cbq) S S∈can-S'ᵘ?p:q
| no S'∉Domθ with ++⁻ (Canₛ p θ) S∈can-S'ᵘ?p:q
... | inj₁ S∈can-p = ++ʳ (Signal.unwrap S' ∷ []) (++ˡ (canₛ-⊆-FV-lemma θ cbp S S∈can-p))
... | inj₂ S∈can-q = ++ʳ (Signal.unwrap S' ∷ proj₁ FVp) (canₛ-⊆-FV-lemma θ cbq S S∈can-q)
canₛ-⊆-FV-lemma {present S' ∣⇒ p ∣⇒ q} θ (CBpresent {FVp = FVp} cbp cbq) S S∈can-S'ᵘ?p:q
| yes S'∈Domθ with Env.sig-stats {S'} θ S'∈Domθ
... | Signal.present = ++ʳ (Signal.unwrap S' ∷ []) (++ˡ (canₛ-⊆-FV-lemma θ cbp S S∈can-S'ᵘ?p:q))
... | Signal.absent = ++ʳ (Signal.unwrap S' ∷ proj₁ FVp) (canₛ-⊆-FV-lemma θ cbq S S∈can-S'ᵘ?p:q)
... | Signal.unknown with ++⁻ (Canₛ p θ) S∈can-S'ᵘ?p:q
... | inj₁ S∈can-p = ++ʳ (Signal.unwrap S' ∷ []) (++ˡ (canₛ-⊆-FV-lemma θ cbp S S∈can-p))
... | inj₂ S∈can-q = ++ʳ (Signal.unwrap S' ∷ proj₁ FVp) (canₛ-⊆-FV-lemma θ cbq S S∈can-q)
canₛ-⊆-FV-lemma θ CBemit S S∈can-p = S∈can-p
canₛ-⊆-FV-lemma {p ∥ q} θ (CBpar {FVp = FVp} cbp cbq BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) S S∈can-p∥q
with ++⁻ (Canₛ p θ) S∈can-p∥q
... | inj₁ S∈can-p = ++ˡ (canₛ-⊆-FV-lemma θ cbp S S∈can-p)
... | inj₂ S∈can-q = ++ʳ (proj₁ FVp) (canₛ-⊆-FV-lemma θ cbq S S∈can-q)
canₛ-⊆-FV-lemma θ (CBloop cb BV≠FV) S S∈can-p =
canₛ-⊆-FV-lemma θ cb S S∈can-p
canₛ-⊆-FV-lemma θ (CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) S S∈can-loopˢp
with canₛ-⊆-FV-lemma θ CBp S S∈can-loopˢp
... | sub = ++ˡ sub
canₛ-⊆-FV-lemma {p >> q} θ (CBseq {FVp = FVp} cbp cbq BVp≠FVq) S S∈can-p>>q
with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | no nothin∉can-p = ++ˡ (canₛ-⊆-FV-lemma θ cbp S S∈can-p>>q)
... | yes nothin∈can-p with ++⁻ (Canₛ p θ) S∈can-p>>q
... | inj₁ S∈can-p = ++ˡ (canₛ-⊆-FV-lemma θ cbp S S∈can-p)
... | inj₂ S∈can-q = ++ʳ (proj₁ FVp) (canₛ-⊆-FV-lemma θ cbq S S∈can-q)
canₛ-⊆-FV-lemma θ (CBsusp cb [S]≠BVp) S S∈can-p =
there (canₛ-⊆-FV-lemma θ cb S S∈can-p)
canₛ-⊆-FV-lemma θ CBexit S ()
canₛ-⊆-FV-lemma θ (CBtrap cb) S S∈can-p =
canₛ-⊆-FV-lemma θ cb S S∈can-p
canₛ-⊆-FV-lemma {shared _ ≔ e in: _} θ (CBshared {FV = FV} cb) S S∈can-p
rewrite set-subtract-[] (proj₁ FV)
= ++ʳ (proj₁ (FVₑ e)) (canₛ-⊆-FV-lemma θ cb S S∈can-p)
canₛ-⊆-FV-lemma θ CBsset S ()
canₛ-⊆-FV-lemma {var _ ≔ e in: _} θ (CBvar {FV = FV} cb) S S∈can-p
rewrite set-subtract-[] (proj₁ FV)
= ++ʳ (proj₁ (FVₑ e)) (canₛ-⊆-FV-lemma θ cb S S∈can-p)
canₛ-⊆-FV-lemma θ CBvset S ()
canₛ-⊆-FV-lemma {if _ ∣⇒ p ∣⇒ q} θ (CBif {FVp = FVp} cbp cbq) S S∈can-if-p-q
with ++⁻ (Canₛ p θ) S∈can-if-p-q
... | inj₁ S∈can-p = ++ˡ (canₛ-⊆-FV-lemma θ cbp S S∈can-p)
... | inj₂ S∈can-q = ++ʳ (proj₁ FVp) (canₛ-⊆-FV-lemma θ cbq S S∈can-q)
canₛ-⊆-FV-lemma {ρ⟨ θ' , A ⟩· p} θ (CBρ cb) S S∈can-ρθp
with set-subtract-merge {proj₁ (Canθ (Env.sig θ') 0 p θ)} {proj₁ (Dom θ')} S∈can-ρθp
... | S∈can-p-θ←θ' , S∉Domθ'
with set-subtract-split (canθₛ-⊆-FV-lemma (Env.sig θ') 0 θ cb S S∈can-p-θ←θ')
... | inj₁ S∈FV = S∈FV
... | inj₂ S∈Domθ' = ⊥-elim (S∉Domθ' S∈Domθ')
canₛ-⊆-FV : ∀ {p BV FV} θ →
CorrectBinding p BV FV →
∀ S →
Signal.unwrap S ∈ Canₛ p θ →
Signal.unwrap S ∈ proj₁ FV
canₛ-⊆-FV θ cb S = canₛ-⊆-FV-lemma θ cb (Signal.unwrap S)
canₛₕ-⊆-FV-lemma : ∀ {p BV FV} θ →
CorrectBinding p BV FV →
∀ s →
s ∈ Canₛₕ p θ →
s ∈ proj₁ (proj₂ FV)
canθₛₕ-⊆-FV-lemma : ∀ {p BV FV} sigs S'' θ →
CorrectBinding p BV FV →
∀ s →
s ∈ proj₂ (proj₂ (Canθ sigs S'' p θ)) →
s ∈ proj₁ (proj₂ FV)
canθₛₕ-⊆-FV-lemma {FV = FV} [] S'' θ cb s s∈canθ-p-θ =
canₛₕ-⊆-FV-lemma θ cb s s∈canθ-p-θ
canθₛₕ-⊆-FV-lemma (just Signal.present ∷ sigs) S'' θ cb s s∈canθ-p-θ =
canθₛₕ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env-present (S'' ₛ)) cb s s∈canθ-p-θ
canθₛₕ-⊆-FV-lemma (just Signal.absent ∷ sigs) S'' θ cb s s∈canθ-p-θ =
canθₛₕ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) cb s s∈canθ-p-θ
canθₛₕ-⊆-FV-lemma {p} (just Signal.unknown ∷ sigs) S'' θ cb s s∈canθ-p-θ
with any (S'' ≟_) (proj₁ (Canθ sigs (suc S'') p (θ ← [S]-env (S'' ₛ))))
... | yes S''∈canθ-p-θ←[S] =
canθₛₕ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env (S'' ₛ)) cb s s∈canθ-p-θ
... | no S''∉canθ-p-θ←[S] =
canθₛₕ-⊆-FV-lemma sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) cb s s∈canθ-p-θ
canθₛₕ-⊆-FV-lemma (nothing ∷ sigs) S'' θ cb s s∈canθ-p-θ =
canθₛₕ-⊆-FV-lemma sigs (suc S'') θ cb s s∈canθ-p-θ
canₛₕ-⊆-FV-lemma θ CBnothing s ()
canₛₕ-⊆-FV-lemma θ CBpause s ()
canₛₕ-⊆-FV-lemma {signl S' p} θ (CBsig {FV = FV} cb) s s∈can-p
rewrite set-subtract-[] (proj₁ (proj₂ FV))
= canθₛₕ-⊆-FV-lemma (Env.sig ([S]-env S')) 0 θ cb s s∈can-p
canₛₕ-⊆-FV-lemma {present S' ∣⇒ p ∣⇒ q} θ (CBpresent {FVp = FVp} cbp cbq) s s∈can-S'?p:q
with Env.Sig∈ S' θ
canₛₕ-⊆-FV-lemma {present S' ∣⇒ p ∣⇒ q} θ (CBpresent {FVp = FVp} cbp cbq) s s∈can-S'ᵘ?p:q
| no S'∉Domθ with ++⁻ (Canₛₕ p θ) s∈can-S'ᵘ?p:q
... | inj₁ s∈can-p = ++ˡ (canₛₕ-⊆-FV-lemma θ cbp s s∈can-p)
... | inj₂ s∈can-q = ++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV-lemma θ cbq s s∈can-q)
canₛₕ-⊆-FV-lemma {present S' ∣⇒ p ∣⇒ q} θ (CBpresent {FVp = FVp} cbp cbq) s s∈can-S'ᵘ?p:q
| yes S'∈Domθ with Env.sig-stats {S'} θ S'∈Domθ
... | Signal.present = ++ˡ (canₛₕ-⊆-FV-lemma θ cbp s s∈can-S'ᵘ?p:q)
... | Signal.absent = ++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV-lemma θ cbq s s∈can-S'ᵘ?p:q)
... | Signal.unknown with ++⁻ (Canₛₕ p θ) s∈can-S'ᵘ?p:q
... | inj₁ s∈can-p = ++ˡ (canₛₕ-⊆-FV-lemma θ cbp s s∈can-p)
... | inj₂ s∈can-q = ++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV-lemma θ cbq s s∈can-q)
canₛₕ-⊆-FV-lemma θ CBemit s ()
canₛₕ-⊆-FV-lemma {p ∥ q} θ (CBpar {FVp = FVp} cbp cbq BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) s s∈can-p∥q
with ++⁻ (Canₛₕ p θ) s∈can-p∥q
... | inj₁ s∈can-p = ++ˡ (canₛₕ-⊆-FV-lemma θ cbp s s∈can-p)
... | inj₂ s∈can-q = ++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV-lemma θ cbq s s∈can-q)
canₛₕ-⊆-FV-lemma θ (CBloop cb BV≠FV) s s∈can-p =
canₛₕ-⊆-FV-lemma θ cb s s∈can-p
canₛₕ-⊆-FV-lemma θ (CBloopˢ CBp CBq BVp≠FVq BVq≠FVq) s s∈can-loopˢpq
with canₛₕ-⊆-FV-lemma θ CBp s s∈can-loopˢpq
... | sub = ++ˡ sub
canₛₕ-⊆-FV-lemma {p >> q} θ (CBseq {FVp = FVp} cbp cbq BVp≠FVq) s s∈can-p>>q
with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | no nothin∉can-p = ++ˡ (canₛₕ-⊆-FV-lemma θ cbp s s∈can-p>>q)
... | yes nothin∈can-p with ++⁻ (Canₛₕ p θ) s∈can-p>>q
... | inj₁ s∈can-p = ++ˡ (canₛₕ-⊆-FV-lemma θ cbp s s∈can-p)
... | inj₂ s∈can-q = ++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV-lemma θ cbq s s∈can-q)
canₛₕ-⊆-FV-lemma θ (CBsusp cb [S]≠BVp) s s∈can-p =
canₛₕ-⊆-FV-lemma θ cb s s∈can-p
canₛₕ-⊆-FV-lemma θ CBexit s ()
canₛₕ-⊆-FV-lemma θ (CBtrap cb) s s∈can-p =
canₛₕ-⊆-FV-lemma θ cb s s∈can-p
canₛₕ-⊆-FV-lemma {shared s' ≔ e in: p} θ (CBshared {FV = FV} cb) s s∈can-shared-p
with SharedVar.unwrap s' Data.Nat.≟ s
... | yes refl = ⊥-elim (set-remove-removed {s} {Canₛₕ p θ} s∈can-shared-p)
... | no s'≢s
rewrite set-subtract-[a]≡set-remove (proj₁ (proj₂ FV)) (SharedVar.unwrap s')
= ++ʳ (proj₁ (proj₂ (FVₑ e)))
(set-remove-not-removed s'≢s
(canₛₕ-⊆-FV-lemma θ cb s
(set-remove-mono-∈ (SharedVar.unwrap s') s∈can-shared-p)))
canₛₕ-⊆-FV-lemma {s' ⇐ e} θ CBsset s s∈can-p = ++ˡ s∈can-p
canₛₕ-⊆-FV-lemma {var _ ≔ e in: _} θ (CBvar {FV = FV} cb) s s∈can-p
rewrite set-subtract-[] (proj₁ (proj₂ FV))
= ++ʳ (proj₁ (proj₂ (FVₑ e))) (canₛₕ-⊆-FV-lemma θ cb s s∈can-p)
canₛₕ-⊆-FV-lemma θ CBvset s ()
canₛₕ-⊆-FV-lemma {if _ ∣⇒ p ∣⇒ q} θ (CBif {FVp = FVp} cbp cbq) s s∈can-if-p-q
with ++⁻ (Canₛₕ p θ) s∈can-if-p-q
... | inj₁ s∈can-p = ++ˡ (canₛₕ-⊆-FV-lemma θ cbp s s∈can-p)
... | inj₂ s∈can-q = ++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV-lemma θ cbq s s∈can-q)
canₛₕ-⊆-FV-lemma {ρ⟨ θ' , A ⟩· p} θ (CBρ cb) s s∈can-ρθp
with set-subtract-merge
{proj₂ (proj₂ (Canθ (Env.sig θ') 0 p θ))}
{proj₁ (proj₂ (Dom θ'))}
s∈can-ρθp
... | s∈can-p-θ←θ' , s∉Domθ'
with set-subtract-split (canθₛₕ-⊆-FV-lemma (Env.sig θ') 0 θ cb s s∈can-p-θ←θ')
... | inj₁ s∈FV = s∈FV
... | inj₂ s∈Domθ' = ⊥-elim (s∉Domθ' s∈Domθ')
canₛₕ-⊆-FV : ∀ {p BV FV} θ →
CorrectBinding p BV FV →
∀ s →
SharedVar.unwrap s ∈ Canₛₕ p θ →
SharedVar.unwrap s ∈ proj₁ (proj₂ FV)
canₛₕ-⊆-FV θ cb s = canₛₕ-⊆-FV-lemma θ cb (SharedVar.unwrap s)
canₖ-term-nothin-lemma : ∀ {r₁ r₂} θ E →
term-nothin r₁ → term-nothin r₂ →
∀ k →
k ∈ Canₖ (E ⟦ r₁ ⟧e) θ →
k ∈ Canₖ (E ⟦ r₂ ⟧e) θ
canₖ-term-nothin-lemma θ [] r₁' r₂' k k∈can-E⟦r2⟧-θ'
rewrite canₖ-term-nothin θ r₁' | canₖ-term-nothin θ r₂' = k∈can-E⟦r2⟧-θ'
canₖ-term-nothin-lemma θ (epar₁ q ∷ E) r₁' r₂' k k∈can-E⟦r2⟧-θ' =
map-mono² Code._⊔_
(canₖ-term-nothin-lemma θ E r₁' r₂')
(λ _ → id)
k k∈can-E⟦r2⟧-θ'
canₖ-term-nothin-lemma θ (epar₂ p ∷ E) r₁' r₂' k k∈can-E⟦r2⟧-θ' =
map-mono² {xs = Canₖ p θ} Code._⊔_
(λ _ → id)
(canₖ-term-nothin-lemma θ E r₁' r₂')
k
k∈can-E⟦r2⟧-θ'
canₖ-term-nothin-lemma {r₁} {r₂} θ (eloopˢ q ∷ E) r₁' r₂' k k∈can-E⟦r2⟧-θ' = canₖ-term-nothin-lemma θ E r₁' r₂' k k∈can-E⟦r2⟧-θ'
canₖ-term-nothin-lemma {r₁} {r₂} θ (eseq q ∷ E) r₁' r₂' k k∈can-E⟦r2⟧-θ'
with any (Code._≟_ Code.nothin) (Canₖ (E ⟦ r₁ ⟧e) θ)
| any (Code._≟_ Code.nothin) (Canₖ (E ⟦ r₂ ⟧e) θ)
... | yes nothin∈can-E⟦r₁⟧ | no nothin∉can-E⟦r₂⟧ =
⊥-elim (nothin∉can-E⟦r₂⟧ (canₖ-term-nothin-lemma θ E r₁' r₂' Code.nothin nothin∈can-E⟦r₁⟧))
... | no nothin∉can-E⟦r₁⟧ | yes nothin∈can-E⟦r₂⟧ =
⊥-elim (nothin∉can-E⟦r₁⟧ (canₖ-term-nothin-lemma θ E r₂' r₁' Code.nothin nothin∈can-E⟦r₂⟧))
... | no nothin∉can-E⟦r₁⟧ | no nothin∉can-E⟦r₂⟧ =
canₖ-term-nothin-lemma θ E r₁' r₂' k k∈can-E⟦r2⟧-θ'
... | yes nothin∈can-E⟦r₁⟧ | yes nothin∈can-E⟦r₂⟧
with ++⁻ (CodeSet.set-remove (Canₖ (E ⟦ r₁ ⟧e) θ) Code.nothin) k∈can-E⟦r2⟧-θ'
... | inj₂ k∈can-q =
++ʳ (CodeSet.set-remove (Canₖ (E ⟦ r₂ ⟧e) θ) Code.nothin) k∈can-q
... | inj₁ k∈can-E⟦r1⟧-nothin with Code.nothin Code.≟ k
... | yes refl =
⊥-elim (CodeSet.set-remove-removed {Code.nothin} {Canₖ (E ⟦ r₁ ⟧e) θ} k∈can-E⟦r1⟧-nothin)
... | no nothin≢k =
++ˡ (CodeSet.set-remove-not-removed nothin≢k
(canₖ-term-nothin-lemma θ E r₁' r₂' k
(CodeSet.set-remove-mono-∈ Code.nothin k∈can-E⟦r1⟧-nothin)))
canₖ-term-nothin-lemma θ (esuspend S' ∷ E) r₁' r₂' k k∈can-E⟦r2⟧-θ' =
canₖ-term-nothin-lemma θ E r₁' r₂' k k∈can-E⟦r2⟧-θ'
canₖ-term-nothin-lemma θ (etrap ∷ E) r₁' r₂' k k∈can-E⟦r2⟧-θ' =
map-mono Code.↓* (canₖ-term-nothin-lemma θ E r₁' r₂') k k∈can-E⟦r2⟧-θ'
canθₛ-subset-lemma : ∀ sigs S'' p q θ →
(∀ θ' S → S ∈ Canₛ p θ' → S ∈ Canₛ q θ') →
∀ S → S ∈ Canθₛ sigs S'' p θ → S ∈ Canθₛ sigs S'' q θ
canθₛ-subset-lemma [] S'' p q θ canₛ-p⊆canₛ-q S S∈canθ-p-θ =
canₛ-p⊆canₛ-q θ S S∈canθ-p-θ
canθₛ-subset-lemma (nothing ∷ sigs) S'' p q θ canₛ-p⊆canₛ-q S S∈canθ-p-θ =
canθₛ-subset-lemma sigs (suc S'') p q θ canₛ-p⊆canₛ-q S S∈canθ-p-θ
canθₛ-subset-lemma (just Signal.present ∷ sigs) S'' p q θ canₛ-p⊆canₛ-q S S∈canθ-p-θ =
canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-present (S'' ₛ)) canₛ-p⊆canₛ-q S S∈canθ-p-θ
canθₛ-subset-lemma (just Signal.absent ∷ sigs) S'' p q θ canₛ-p⊆canₛ-q S S∈canθ-p-θ =
canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ)) canₛ-p⊆canₛ-q S S∈canθ-p-θ
canθₛ-subset-lemma (just Signal.unknown ∷ sigs) S'' p q θ canₛ-p⊆canₛ-q S S∈canθ-p-θ
with any (_≟_ S'') (Canθₛ sigs (suc S'') p (θ ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs (suc S'') q (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-p-θ' | yes S''∈canθ-q-θ' =
canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env (S'' ₛ)) canₛ-p⊆canₛ-q S S∈canθ-p-θ
... | no S''∉canθ-p-θ' | no S''∉canθ-q-θ' =
canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ)) canₛ-p⊆canₛ-q S S∈canθ-p-θ
... | yes S''∈canθ-p-θ' | no S''∉canθ-q-θ' =
⊥-elim
(S''∉canθ-q-θ'
(canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env (S'' ₛ)) canₛ-p⊆canₛ-q
S'' S''∈canθ-p-θ'))
... | no S''∉canθ-p-θ' | yes S''∈canθ-q-θ' =
canθₛ-add-sig-monotonic sigs (suc S'') q θ (S'' ₛ) Signal.absent S
(canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ)) canₛ-p⊆canₛ-q
S S∈canθ-p-θ)
canθₛ-subset : ∀ sigs S'' p q θ →
(∀ θ' S →
Signal.unwrap S ∈ Canₛ p θ' →
Signal.unwrap S ∈ Canₛ q θ') →
∀ S →
Signal.unwrap S ∈ Canθₛ sigs S'' p θ →
Signal.unwrap S ∈ Canθₛ sigs S'' q θ
canθₛ-subset sigs S'' p q θ canₛ-p⊆canₛ-q S S∈canθ-p-θ =
canθₛ-subset-lemma sigs S'' p q θ
(λ θ' S → canₛ-p⊆canₛ-q θ' (S ₛ))
(Signal.unwrap S) S∈canθ-p-θ
canθₛₕ-subset-lemma : ∀ sigs S'' p q θ →
(∀ θ' S → S ∈ Canₛ p θ' → S ∈ Canₛ q θ') →
(∀ θ' s → s ∈ Canₛₕ p θ' → s ∈ Canₛₕ q θ') →
∀ s → s ∈ Canθₛₕ sigs S'' p θ → s ∈ Canθₛₕ sigs S'' q θ
canθₛₕ-subset-lemma [] S'' p q θ
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ =
canₛₕ-p⊆canₛₕ-q θ s s∈canθ-p-θ
canθₛₕ-subset-lemma (nothing ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ =
canθₛₕ-subset-lemma sigs (suc S'') p q θ
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ
canθₛₕ-subset-lemma (just Signal.present ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ =
canθₛₕ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-present (S'' ₛ))
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ
canθₛₕ-subset-lemma (just Signal.absent ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ =
canθₛₕ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ))
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ
canθₛₕ-subset-lemma (just Signal.unknown ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ
with any (_≟_ S'') (Canθₛ sigs (suc S'') p (θ ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs (suc S'') q (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-p-θ' | yes S''∈canθ-q-θ' =
canθₛₕ-subset-lemma sigs (suc S'') p q (θ ← [S]-env (S'' ₛ))
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ
... | no S''∉canθ-p-θ' | no S''∉canθ-q-θ' =
canθₛₕ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ))
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ
... | yes S''∈canθ-p-θ' | no S''∉canθ-q-θ' =
⊥-elim
(S''∉canθ-q-θ'
(canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env (S'' ₛ)) canₛ-p⊆canₛ-q
S'' S''∈canθ-p-θ'))
... | no S''∉canθ-p-θ' | yes S''∈canθ-q-θ' =
canθₛₕ-add-sig-monotonic sigs (suc S'') q θ (S'' ₛ) Signal.absent s
(canθₛₕ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ))
canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ)
canθₛₕ-subset : ∀ sigs S'' p q θ →
(∀ θ' S →
Signal.unwrap S ∈ Canₛ p θ' →
Signal.unwrap S ∈ Canₛ q θ') →
(∀ θ' s →
SharedVar.unwrap s ∈ Canₛₕ p θ' →
SharedVar.unwrap s ∈ Canₛₕ q θ') →
∀ s →
SharedVar.unwrap s ∈ Canθₛₕ sigs S'' p θ →
SharedVar.unwrap s ∈ Canθₛₕ sigs S'' q θ
canθₛₕ-subset sigs S'' p q θ canₛ-p⊆canₛ-q canₛₕ-p⊆canₛₕ-q s s∈canθ-p-θ =
canθₛₕ-subset-lemma sigs S'' p q θ
(λ θ' S → canₛ-p⊆canₛ-q θ' (S ₛ)) (λ θ' s → canₛₕ-p⊆canₛₕ-q θ' (s ₛₕ))
(SharedVar.unwrap s) s∈canθ-p-θ
canθₖ-subset-lemma : ∀ sigs S'' p q θ →
(∀ θ' S → S ∈ Canₛ p θ' → S ∈ Canₛ q θ') →
(∀ θ' k → k ∈ Canₖ p θ' → k ∈ Canₖ q θ') →
∀ k → k ∈ Canθₖ sigs S'' p θ → k ∈ Canθₖ sigs S'' q θ
canθₖ-subset-lemma [] S'' p q θ
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ =
canₖ-p⊆canₖ-q θ k k∈canθ-p-θ
canθₖ-subset-lemma (nothing ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ =
canθₖ-subset-lemma sigs (suc S'') p q θ
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ
canθₖ-subset-lemma (just Signal.present ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ =
canθₖ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-present (S'' ₛ))
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ
canθₖ-subset-lemma (just Signal.absent ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ =
canθₖ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ))
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ
canθₖ-subset-lemma (just Signal.unknown ∷ sigs) S'' p q θ
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ
with any (_≟_ S'') (Canθₛ sigs (suc S'') p (θ ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs (suc S'') q (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-p-θ' | yes S''∈canθ-q-θ' =
canθₖ-subset-lemma sigs (suc S'') p q (θ ← [S]-env (S'' ₛ))
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ
... | no S''∉canθ-p-θ' | no S''∉canθ-q-θ' =
canθₖ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ))
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ
... | yes S''∈canθ-p-θ' | no S''∉canθ-q-θ' =
⊥-elim
(S''∉canθ-q-θ'
(canθₛ-subset-lemma sigs (suc S'') p q (θ ← [S]-env (S'' ₛ)) canₛ-p⊆canₛ-q
S'' S''∈canθ-p-θ'))
... | no S''∉canθ-p-θ' | yes S''∈canθ-q-θ' =
canθₖ-add-sig-monotonic sigs (suc S'') q θ (S'' ₛ) Signal.absent k
(canθₖ-subset-lemma sigs (suc S'') p q (θ ← [S]-env-absent (S'' ₛ))
canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ)
canθₖ-subset : ∀ sigs S'' p q θ →
(∀ θ' S →
Signal.unwrap S ∈ Canₛ p θ' →
Signal.unwrap S ∈ Canₛ q θ') →
(∀ θ' k →
k ∈ Canₖ p θ' →
k ∈ Canₖ q θ') →
∀ k →
k ∈ Canθₖ sigs S'' p θ →
k ∈ Canθₖ sigs S'' q θ
canθₖ-subset sigs S'' p q θ canₛ-p⊆canₛ-q canₖ-p⊆canₖ-q k k∈canθ-p-θ =
canθₖ-subset-lemma sigs S'' p q θ
(λ θ' S → canₛ-p⊆canₛ-q θ' (S ₛ)) canₖ-p⊆canₖ-q
k k∈canθ-p-θ
canθₛ-E₁⟦p⟧⊆canθₛ-p : ∀ {pin E₁ E₁⟦nothin⟧ BV FV} sigs S'' θ →
-- distinct (Dom sigs) (FV (E₁ ⟦ nothin ⟧))
E₁⟦nothin⟧ ≐ (E₁ ∷ []) ⟦ nothin ⟧e →
CorrectBinding E₁⟦nothin⟧ BV FV →
distinct' (map (_+_ S'') (SigMap.keys sigs)) (proj₁ FV) →
∀ S' →
Signal.unwrap S' ∉ proj₁ FV →
Signal.unwrap S' ∈ Canθₛ sigs S'' ((E₁ ∷ []) ⟦ pin ⟧e) θ →
Signal.unwrap S' ∈ Canθₛ sigs S'' pin θ
canθₛ-E₁⟦p⟧⊆canθₛ-p {pin} [] S'' θ (depar₁ pin≐E₁⟦nothin⟧) cb@(CBpar {FVp = FVp} cbp cbq _ _ _ _)
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
with ++⁻ (Canₛ pin θ) S'∈canθ-E₁⟦pin⟧-θ
... | inj₁ S'∈can-pin-θ = S'∈can-pin-θ
... | inj₂ S'∈can-q-θ = ⊥-elim (S'∉FV (++ʳ (proj₁ FVp) (canₛ-⊆-FV θ cbq S' S'∈can-q-θ)))
canθₛ-E₁⟦p⟧⊆canθₛ-p {pin} {epar₂ p} [] S'' θ (depar₂ pin≐E₁⟦nothin⟧) cb@(CBpar cbp cbq _ _ _ _)
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
with ++⁻ (Canₛ p θ) S'∈canθ-E₁⟦pin⟧-θ
... | inj₂ S'∈can-pin-θ = S'∈can-pin-θ
... | inj₁ S'∈can-p-θ = ⊥-elim (S'∉FV (++ˡ (canₛ-⊆-FV θ cbp S' S'∈can-p-θ)))
canθₛ-E₁⟦p⟧⊆canθₛ-p {pin} [] S'' θ (deloopˢ pin≐E₁⟦nothin⟧) cb@(CBloopˢ {FVp = FVp} cbp cbq _ _) = λ _ S' _ z → z
canθₛ-E₁⟦p⟧⊆canθₛ-p {pin} [] S'' θ (deseq pin≐E₁⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _)
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
with any (Code._≟_ Code.nothin) (Canₖ pin θ)
... | no nothin∉can-pin = S'∈canθ-E₁⟦pin⟧-θ
... | yes nothin∈can-pin with ++⁻ (Canₛ pin θ) S'∈canθ-E₁⟦pin⟧-θ
... | inj₁ S∈can-pin-θ = S∈can-pin-θ
... | inj₂ S∈can-q-θ = ⊥-elim (S'∉FV (++ʳ (proj₁ FVp) (canₛ-⊆-FV θ cbq S' S∈can-q-θ)))
canθₛ-E₁⟦p⟧⊆canθₛ-p {pin} [] S'' θ (desuspend pin≐E₁⟦nothin⟧) cb@(CBsusp cb' _)
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ = S'∈canθ-E₁⟦pin⟧-θ
canθₛ-E₁⟦p⟧⊆canθₛ-p {pin} [] S'' θ (detrap pin≐E₁⟦nothin⟧) cb@(CBtrap cb')
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ = S'∈canθ-E₁⟦pin⟧-θ
canθₛ-E₁⟦p⟧⊆canθₛ-p (nothing ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV
S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
canθₛ-E₁⟦p⟧⊆canθₛ-p (just Signal.present ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') (θ ← [S]-env-present (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
canθₛ-E₁⟦p⟧⊆canθₛ-p (just Signal.absent ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)) )
S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
canθₛ-E₁⟦p⟧⊆canθₛ-p {pin} {E₁} (just Signal.unknown ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
with any (_≟_ S'') (Canθₛ sigs (suc S'') pin (θ ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs (suc S'') ((E₁ ∷ []) ⟦ pin ⟧e) (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-p-θ←[S] | yes S''∈canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') (θ ← [S]-env (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
... | no S''∉canθ-p-θ←[S] | no S''∉canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ
... | yes S''∈canθ-p-θ←[S] | no S''∉canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛ-add-sig-monotonic sigs (suc S'') pin θ (S'' ₛ) Signal.absent (Signal.unwrap S')
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
S' S'∉FV S'∈canθ-E₁⟦pin⟧-θ)
... | no S''∉canθ-p-θ←[S] | yes S''∈canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
| +-comm S'' 0
= ⊥-elim
(S''∉canθ-p-θ←[S]
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') (θ ← [S]-env (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
(S'' ₛ) (map-S''-+-sigs≠FV S'' (here refl)) S''∈canθ-E₁⟦p⟧-θ←[S]))
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p : ∀ {pin E₁ E₁⟦nothin⟧ BV FV} sigs S'' θ →
-- distinct (Dom sigs) (FV (E₁ ⟦ nothin ⟧))
E₁⟦nothin⟧ ≐ (E₁ ∷ []) ⟦ nothin ⟧e →
CorrectBinding E₁⟦nothin⟧ BV FV →
distinct' (map (_+_ S'') (SigMap.keys sigs)) (proj₁ FV) →
∀ s →
SharedVar.unwrap s ∉ proj₁ (proj₂ FV) →
SharedVar.unwrap s ∈ Canθₛₕ sigs S'' ((E₁ ∷ []) ⟦ pin ⟧e) θ →
SharedVar.unwrap s ∈ Canθₛₕ sigs S'' pin θ
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p {pin} [] S'' θ (depar₁ pin≐E₁⟦nothin⟧) cb@(CBpar {FVp = FVp} cbp cbq _ _ _ _)
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ
with ++⁻ (Canₛₕ pin θ) s∈canθ-E₁⟦pin⟧-θ
... | inj₁ s∈can-pin-θ = s∈can-pin-θ
... | inj₂ s∈can-q-θ = ⊥-elim (s∉FV (++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV θ cbq s s∈can-q-θ)))
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p {pin} {epar₂ p} [] S'' θ (depar₂ pin≐E₁⟦nothin⟧) cb@(CBpar cbp cbq _ _ _ _)
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ
with ++⁻ (Canₛₕ p θ) s∈canθ-E₁⟦pin⟧-θ
... | inj₂ s∈can-pin-θ = s∈can-pin-θ
... | inj₁ s∈can-p-θ = ⊥-elim (s∉FV (++ˡ (canₛₕ-⊆-FV θ cbp s s∈can-p-θ)))
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p {pin} [] S'' θ (deloopˢ pin≐E₁⟦nothin⟧) cb@(CBloopˢ {FVp = FVp} cbp cbq _ _) = λ _ s _ z → z
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p {pin} [] S'' θ (deseq pin≐E₁⟦nothin⟧) cb@(CBseq {FVp = FVp} cbp cbq _)
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ
with any (Code._≟_ Code.nothin) (Canₖ pin θ)
... | no nothin∉can-pin = s∈canθ-E₁⟦pin⟧-θ
... | yes nothin∈can-pin with ++⁻ (Canₛₕ pin θ) s∈canθ-E₁⟦pin⟧-θ
... | inj₁ s∈can-pin-θ = s∈can-pin-θ
... | inj₂ s∈can-q-θ = ⊥-elim (s∉FV (++ʳ (proj₁ (proj₂ FVp)) (canₛₕ-⊆-FV θ cbq s s∈can-q-θ)))
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p {pin} [] S'' θ (desuspend pin≐E₁⟦nothin⟧) cb@(CBsusp cb' _)
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ = s∈canθ-E₁⟦pin⟧-θ
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p {pin} [] S'' θ (detrap pin≐E₁⟦nothin⟧) cb@(CBtrap cb')
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ = s∈canθ-E₁⟦pin⟧-θ
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (nothing ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p sigs (suc S'') θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV
s s∉FV s∈canθ-E₁⟦pin⟧-θ
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (just Signal.present ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p sigs (suc S'') (θ ← [S]-env-present (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
s s∉FV s∈canθ-E₁⟦pin⟧-θ
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (just Signal.absent ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)) )
s s∉FV s∈canθ-E₁⟦pin⟧-θ
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p {pin} {E₁} (just Signal.unknown ∷ sigs) S'' θ pin≐E₁⟦nothin⟧ cb
map-S''-+-sigs≠FV s s∉FV s∈canθ-E₁⟦pin⟧-θ
with any (_≟_ S'') (Canθₛ sigs (suc S'') pin (θ ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs (suc S'') ((E₁ ∷ []) ⟦ pin ⟧e) (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-p-θ←[S] | yes S''∈canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p sigs (suc S'') (θ ← [S]-env (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
s s∉FV s∈canθ-E₁⟦pin⟧-θ
... | no S''∉canθ-p-θ←[S] | no S''∉canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
s s∉FV s∈canθ-E₁⟦pin⟧-θ
... | yes S''∈canθ-p-θ←[S] | no S''∉canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
= canθₛₕ-add-sig-monotonic sigs (suc S'') pin θ (S'' ₛ) Signal.absent (SharedVar.unwrap s)
(canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
s s∉FV s∈canθ-E₁⟦pin⟧-θ)
... | no S''∉canθ-p-θ←[S] | yes S''∈canθ-E₁⟦p⟧-θ←[S]
rewrite map-+-compose-suc S'' (SigMap.keys sigs)
| +-comm S'' 0
= ⊥-elim
(S''∉canθ-p-θ←[S]
(canθₛ-E₁⟦p⟧⊆canθₛ-p sigs (suc S'') (θ ← [S]-env (S'' ₛ)) pin≐E₁⟦nothin⟧ cb
(distinct'-sym (dist':: (distinct'-sym map-S''-+-sigs≠FV)))
(S'' ₛ) (map-S''-+-sigs≠FV S'' (here refl)) S''∈canθ-E₁⟦p⟧-θ←[S]))
canθₛ-p⊆canθₛ-E₁⟦p⟧ : ∀ sigs S'' θ E₁ pin →
∀ S' →
Signal.unwrap S' ∈ Canθₛ sigs S'' pin θ →
Signal.unwrap S' ∈ Canθₛ sigs S'' ((E₁ ∷ []) ⟦ pin ⟧e) θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ [] S'' θ (epar₁ q) pin S' S'∈canθ-sigs-pin-θ =
++ˡ S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ [] S'' θ (epar₂ p) pin S' S'∈canθ-sigs-pin-θ =
++ʳ (Canₛ p θ) S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ [] S'' θ (eloopˢ q) pin S' S'∈canθ-sigs-pin-θ = S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ [] S'' θ (eseq q) pin S' S'∈canθ-sigs-pin-θ
with any (Code._≟_ Code.nothin) (Canₖ pin θ)
... | yes nothin∈can-pin = ++ˡ S'∈canθ-sigs-pin-θ
... | no nothin∉can-pin = S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ [] S'' θ (esuspend S) pin S' S'∈canθ-sigs-pin-θ =
S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ [] S'' θ etrap pin S' S'∈canθ-sigs-pin-θ =
S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ (nothing ∷ sigs) S'' θ E₁ pin S' S'∈canθ-sigs-pin-θ =
canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') θ E₁ pin S' S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ (just Signal.present ∷ sigs) S'' θ E₁ pin S' S'∈canθ-sigs-pin-θ =
canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-present (S'' ₛ)) E₁ pin
S' S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ (just Signal.absent ∷ sigs) S'' θ E₁ pin S' S'∈canθ-sigs-pin-θ =
canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) E₁ pin
S' S'∈canθ-sigs-pin-θ
canθₛ-p⊆canθₛ-E₁⟦p⟧ (just Signal.unknown ∷ sigs) S'' θ E₁ pin S' S'∈canθ-sigs-pin-θ
with any (_≟_ S'') (Canθₛ sigs (suc S'') ((E₁ ∷ []) ⟦ pin ⟧e) (θ ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs (suc S'') pin (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-sigs-E₁⟦pin⟧-θ | yes S''∈canθ-sigs-pin-θ =
canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env (S'' ₛ)) E₁ pin
S' S'∈canθ-sigs-pin-θ
... | no S''∉canθ-sigs-E₁⟦pin⟧ | no S''∉canθ-sigs-pin-θ =
canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) E₁ pin
S' S'∈canθ-sigs-pin-θ
... | yes S''∈canθ-sigs-E₁⟦pin⟧ | no S''∉canθ-sigs-pin-θ =
canθₛ-add-sig-monotonic sigs (suc S'') ((E₁ ∷ []) ⟦ pin ⟧e)
θ (S'' ₛ) Signal.absent (Signal.unwrap S')
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) E₁ pin
S' S'∈canθ-sigs-pin-θ)
... | no S''∉canθ-sigs-E₁⟦pin⟧ | yes S''∈canθ-sigs-pin-θ =
⊥-elim
(S''∉canθ-sigs-E₁⟦pin⟧
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env (S'' ₛ)) E₁ pin
(S'' ₛ) S''∈canθ-sigs-pin-θ))
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ : ∀ sigs S'' θ E₁ pin →
∀ s →
SharedVar.unwrap s ∈ Canθₛ sigs S'' pin θ →
SharedVar.unwrap s ∈ Canθₛ sigs S'' ((E₁ ∷ []) ⟦ pin ⟧e) θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ [] S'' θ (epar₁ q) pin s s∈canθ-sigs-pin-θ =
++ˡ s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ [] S'' θ (epar₂ p) pin s s∈canθ-sigs-pin-θ =
++ʳ (Canₛ p θ) s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ [] S'' θ (eloopˢ q) pin s s∈canθ-sigs-pin-θ = s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ [] S'' θ (eseq q) pin s s∈canθ-sigs-pin-θ
with any (Code._≟_ Code.nothin) (Canₖ pin θ)
... | yes nothin∈can-pin = ++ˡ s∈canθ-sigs-pin-θ
... | no nothin∉can-pin = s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ [] S'' θ (esuspend S) pin s s∈canθ-sigs-pin-θ =
s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ [] S'' θ etrap pin s s∈canθ-sigs-pin-θ =
s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ (nothing ∷ sigs) S'' θ E₁ pin s s∈canθ-sigs-pin-θ =
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ sigs (suc S'') θ E₁ pin s s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ (just Signal.present ∷ sigs) S'' θ E₁ pin s s∈canθ-sigs-pin-θ =
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-present (S'' ₛ)) E₁ pin
s s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ (just Signal.absent ∷ sigs) S'' θ E₁ pin s s∈canθ-sigs-pin-θ =
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) E₁ pin
s s∈canθ-sigs-pin-θ
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ (just Signal.unknown ∷ sigs) S'' θ E₁ pin s s∈canθ-sigs-pin-θ
with any (_≟_ S'') (Canθₛ sigs (suc S'') ((E₁ ∷ []) ⟦ pin ⟧e) (θ ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs (suc S'') pin (θ ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-sigs-E₁⟦pin⟧-θ | yes S''∈canθ-sigs-pin-θ =
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env (S'' ₛ)) E₁ pin
s s∈canθ-sigs-pin-θ
... | no S''∉canθ-sigs-E₁⟦pin⟧ | no S''∉canθ-sigs-pin-θ =
canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) E₁ pin
s s∈canθ-sigs-pin-θ
... | yes S''∈canθ-sigs-E₁⟦pin⟧ | no S''∉canθ-sigs-pin-θ =
canθₛ-add-sig-monotonic sigs (suc S'') ((E₁ ∷ []) ⟦ pin ⟧e)
θ (S'' ₛ) Signal.absent (SharedVar.unwrap s)
(canθₛₕ-p⊆canθₛₕ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env-absent (S'' ₛ)) E₁ pin
s s∈canθ-sigs-pin-θ)
... | no S''∉canθ-sigs-E₁⟦pin⟧ | yes S''∈canθ-sigs-pin-θ =
⊥-elim
(S''∉canθ-sigs-E₁⟦pin⟧
(canθₛ-p⊆canθₛ-E₁⟦p⟧ sigs (suc S'') (θ ← [S]-env (S'' ₛ)) E₁ pin
(S'' ₛ) S''∈canθ-sigs-pin-θ))
canθ-shadowing-irr' : ∀ sigs' S'' p S status θ θo →
S ∈ map (_+_ S'') (SigMap.keys sigs') →
Canθ sigs' S'' p ((θ ← [ (S ₛ) ↦ status ]) ← θo) ≡
Canθ sigs' S'' p (θ ← θo)
canθ-shadowing-irr' [] S'' p S status θ θo ()
canθ-shadowing-irr' (nothing ∷ sigs') S'' p S status θ θo S∈map-+-S''-sigs'
rewrite map-+-compose-suc S'' (SigMap.keys sigs')
= canθ-shadowing-irr' sigs' (suc S'') p S status θ θo S∈map-+-S''-sigs'
canθ-shadowing-irr' (just Signal.present ∷ sigs') S'' p S status θ θo (here refl)
rewrite +-comm S'' 0
| Env.sig-set-inner-clobber θ θo ([S]-env-present (S'' ₛ)) (S'' ₛ) status (Env.sig-∈-single (S'' ₛ) Signal.present)
= refl
canθ-shadowing-irr' (just Signal.absent ∷ sigs') S'' p S status θ θo (here refl)
rewrite +-comm S'' 0
| Env.sig-set-inner-clobber θ θo ([S]-env-absent (S'' ₛ)) (S'' ₛ) status (Env.sig-∈-single (S'' ₛ) Signal.absent)
= refl
canθ-shadowing-irr' (just Signal.unknown ∷ sigs') S'' p S status θ θo (here refl)
with any (_≟_ S'') (Canθₛ sigs' (suc S'') p (((θ ← [ (S ₛ) ↦ status ]) ← θo) ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs' (suc S'') p ((θ ← θo) ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-sigs-θ←[S]-absent←θo←[S''] | yes S''∈canθ-sigs-θ←[S]←θo←[S'']
rewrite +-comm S'' 0
| Env.sig-set-inner-clobber θ θo ([S]-env (S'' ₛ)) (S'' ₛ) status (Env.sig-∈-single (S'' ₛ) Signal.unknown)
= refl
... | no S''∉canθ-sigs-θ←[S]-absent←θo←[S''] | no S''∉canθ-sigs-θ←[S]←θo←[S'']
rewrite +-comm S'' 0
| Env.sig-set-inner-clobber θ θo ([S]-env-absent (S'' ₛ)) (S'' ₛ) status (Env.sig-∈-single (S'' ₛ) Signal.absent)
= refl
... | yes S''∈canθ-sigs-θ←[S]-absent←θo←[S''] | no S''∉canθ-sigs-θ←[S]←θo←[S'']
rewrite +-comm S'' 0
| Env.sig-set-inner-clobber θ θo ([S]-env (S'' ₛ)) (S'' ₛ) status (Env.sig-∈-single (S'' ₛ) Signal.unknown)
= ⊥-elim (S''∉canθ-sigs-θ←[S]←θo←[S''] S''∈canθ-sigs-θ←[S]-absent←θo←[S''])
... | no S''∉canθ-sigs-θ←[S]-absent←θo←[S''] | yes S''∈canθ-sigs-θ←[S]←θo←[S'']
rewrite +-comm S'' 0
| Env.sig-set-inner-clobber θ θo ([S]-env (S'' ₛ)) (S'' ₛ) status (Env.sig-∈-single (S'' ₛ) Signal.unknown)
= ⊥-elim (S''∉canθ-sigs-θ←[S]-absent←θo←[S''] S''∈canθ-sigs-θ←[S]←θo←[S''])
canθ-shadowing-irr' (just Signal.present ∷ sigs') S'' p S status θ θo (there S∈map-+-S''-sigs')
rewrite map-+-compose-suc S'' (SigMap.keys sigs')
| sym (Env.←-assoc (θ ← [ (S ₛ) ↦ status ]) θo ([S]-env-present (S'' ₛ)))
| sym (Env.←-assoc θ θo ([S]-env-present (S'' ₛ)))
= canθ-shadowing-irr' sigs' (suc S'') p S status θ (θo ← [S]-env-present (S'' ₛ)) S∈map-+-S''-sigs'
canθ-shadowing-irr' (just Signal.absent ∷ sigs') S'' p S status θ θo (there S∈map-+-S''-sigs')
rewrite map-+-compose-suc S'' (SigMap.keys sigs')
| sym (Env.←-assoc (θ ← [ (S ₛ) ↦ status ]) θo ([S]-env-absent (S'' ₛ)))
| sym (Env.←-assoc θ θo ([S]-env-absent (S'' ₛ)))
= canθ-shadowing-irr' sigs' (suc S'') p S status θ (θo ← [S]-env-absent (S'' ₛ)) S∈map-+-S''-sigs'
canθ-shadowing-irr' (just Signal.unknown ∷ sigs') S'' p S status θ θo (there S∈map-+-S''-sigs')
with any (_≟_ S'') (Canθₛ sigs' (suc S'') p (((θ ← [ (S ₛ) ↦ status ]) ← θo) ← [S]-env (S'' ₛ)))
| any (_≟_ S'') (Canθₛ sigs' (suc S'') p ((θ ← θo) ← [S]-env (S'' ₛ)))
... | yes S''∈canθ-sigs-θ←[S]-absent←θo←[S''] | yes S''∈canθ-sigs-θ←[S]←θo←[S'']
rewrite map-+-compose-suc S'' (SigMap.keys sigs')
| sym (Env.←-assoc (θ ← [ (S ₛ) ↦ status ]) θo ([S]-env (S'' ₛ)))
| sym (Env.←-assoc θ θo ([S]-env (S'' ₛ)))
= canθ-shadowing-irr' sigs' (suc S'') p S status θ (θo ← [S]-env (S'' ₛ)) S∈map-+-S''-sigs'
... | no S''∉canθ-sigs-θ←[S]-absent←θo←[S''] | no S''∉canθ-sigs-θ←[S]←θo←[S'']
rewrite map-+-compose-suc S'' (SigMap.keys sigs')
| sym (Env.←-assoc (θ ← [ (S ₛ) ↦ status ]) θo ([S]-env-absent (S'' ₛ)))
| sym (Env.←-assoc θ θo ([S]-env-absent (S'' ₛ)))
= canθ-shadowing-irr' sigs' (suc S'') p S status θ (θo ← [S]-env-absent (S'' ₛ)) S∈map-+-S''-sigs'
... | yes S''∈canθ-sigs-θ←[S]-absent←θo←[S''] | no S''∉canθ-sigs-θ←[S]←θo←[S'']
rewrite map-+-compose-suc S'' (SigMap.keys sigs')
| sym (Env.←-assoc (θ ← [ (S ₛ) ↦ status ]) θo ([S]-env (S'' ₛ)))
| sym (Env.←-assoc θ θo ([S]-env (S'' ₛ)))
| canθ-shadowing-irr' sigs' (suc S'') p S status θ (θo ← [S]-env (S'' ₛ)) S∈map-+-S''-sigs'
= ⊥-elim (S''∉canθ-sigs-θ←[S]←θo←[S''] S''∈canθ-sigs-θ←[S]-absent←θo←[S''])
... | no S''∉canθ-sigs-θ←[S]-absent←θo←[S''] | yes S''∈canθ-sigs-θ←[S]←θo←[S'']
rewrite map-+-compose-suc S'' (SigMap.keys sigs')
| sym (Env.←-assoc (θ ← [ (S ₛ) ↦ status ]) θo ([S]-env (S'' ₛ)))
| sym (Env.←-assoc θ θo ([S]-env (S'' ₛ)))
| canθ-shadowing-irr' sigs' (suc S'') p S status θ (θo ← [S]-env (S'' ₛ)) S∈map-+-S''-sigs'
= ⊥-elim (S''∉canθ-sigs-θ←[S]-absent←θo←[S''] S''∈canθ-sigs-θ←[S]←θo←[S''])
canθ-shadowing-irr : ∀ sigs' S'' p S status θ →
Signal.unwrap S ∈ map (_+_ S'') (SigMap.keys sigs') →
Canθ sigs' S'' p θ ≡
Canθ sigs' S'' p (θ ← [ S ↦ status ])
canθ-shadowing-irr sigs' S'' p S status θ S∈map-+-S''-sigs'
rewrite Env.←-comm Env.[]env (θ ← [ S ↦ status ]) distinct-empty-left
| cong (Canθ sigs' S'' p) (Env.←-comm Env.[]env θ distinct-empty-left)
= sym (canθ-shadowing-irr' sigs' S'' p (Signal.unwrap S) status
θ Env.[]env S∈map-+-S''-sigs')
Canθₛunknown->Canₛunknown-help : ∀ S S' p →
(S + S') ∈ Canθₛ SigMap.[ (S ₛ) ↦ Signal.unknown ] S' p Env.[]env →
(S + S') ∈ Canₛ p [ ((S + S') ₛ) ↦ Signal.unknown ]
Canθₛunknown->Canₛunknown-help zero S' p S+S'∈canθ-[S↦unknown]-S'
with any (S' ≟_) (Canₛ p [ (S' ₛ) ↦ Signal.unknown ])
... | yes S'∈can-p-[S↦unknown] = S+S'∈canθ-[S↦unknown]-S'
... | no S'∉can-p-[S↦unknown] =
Data.Empty.⊥-elim
(S'∉can-p-[S↦unknown]
(Esterel.Lang.CanFunction.SetSigMonotonic.canθₛ-add-sig-monotonic
[] 0 p Env.[]env (S' ₛ) Signal.absent S'
S+S'∈canθ-[S↦unknown]-S'))
Canθₛunknown->Canₛunknown-help (suc S) S' p S+S'∈canθ-[S↦unknown]-S'
-- trans (cong suc (+-comm S S')) (+-comm (suc S') S) : suc (S + S') ≡ S + (suc S')
rewrite cong (λ n → Canₛ p [ (n ₛ) ↦ Signal.unknown ])
(trans (cong suc (+-comm S S')) (+-comm (suc S') S))
| trans (cong suc (+-comm S S')) (+-comm (suc S') S)
= Canθₛunknown->Canₛunknown-help S (suc S') p S+S'∈canθ-[S↦unknown]-S'
Canθₛunknown->Canₛunknown : ∀ S p ->
(Signal.unwrap S) ∈ Canθₛ SigMap.[ S ↦ Signal.unknown ] 0 p Env.[]env →
(Signal.unwrap S) ∈ Canₛ p [ S ↦ Signal.unknown ]
Canθₛunknown->Canₛunknown S p fact
rewrite +-right-identity (Signal.unwrap S)
with Canθₛunknown->Canₛunknown-help
(Signal.unwrap S) zero p (add-zero (Signal.unwrap S) _ fact)
where
add-zero : ∀ s x -> s ∈ x -> (s + 0) ∈ x
add-zero s x s+0∈x rewrite +-right-identity s = s+0∈x
... | thing rewrite +-right-identity (Signal.unwrap S) = thing
| {
"alphanum_fraction": 0.5723517643,
"avg_line_length": 45.7706645057,
"ext": "agda",
"hexsha": "6df277c3b3891413f5bf3e26fc5b7a553b61f2ce",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/Esterel/Lang/CanFunction/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"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": "florence/esterel-calculus",
"max_issues_repo_path": "agda/Esterel/Lang/CanFunction/Base.agda",
"max_line_length": 128,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/Esterel/Lang/CanFunction/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 30384,
"size": 56481
} |
{-# OPTIONS --allow-unsolved-metas #-}
-- Andreas, 2014-12-06
-- Reported by sanzhiyan, Dec 4 2014
open import Data.Vec
open import Data.Fin
open import Data.Nat renaming (_+_ to _+N_)
open import Data.Nat.Solver
open import Relation.Binary.PropositionalEquality hiding ([_])
open +-*-Solver using (prove; solve; _:=_; con; var; _:+_; _:*_; :-_; _:-_)
data prop : Set where
F T : prop
_∧_ _∨_ : prop → prop → prop
infixl 4 _∧_ _∨_
Γ : (n : ℕ) → Set
Γ n = Vec prop n
infix 1 _⊢_
data _⊢_ : ∀ {n} → Γ n → prop → Set where
hyp : ∀ {n}(C : Γ n)(v : Fin n) → C ⊢ (lookup v C)
andI : ∀ {n}{C : Γ n}{p p' : prop} → C ⊢ p → C ⊢ p' → C ⊢ p ∧ p'
andEL : ∀ {n}{C : Γ n}{p p' : prop} → C ⊢ p ∧ p' → C ⊢ p
andER : ∀ {n}{C : Γ n}{p p' : prop} → C ⊢ p ∧ p' → C ⊢ p'
orIL : ∀ {n}{C : Γ n}{p : prop}(p' : prop) → C ⊢ p → C ⊢ p ∨ p'
orIR : ∀ {n}{C : Γ n}{p' : prop}(p : prop) → C ⊢ p' → C ⊢ p ∨ p'
orE : ∀ {n}{C : Γ n}{p p' c : prop} → C ⊢ p ∨ p' → p ∷ C ⊢ c → p' ∷ C ⊢ c → C ⊢ c
-- WAS:
-- The first two _ could not be solved before today's (2014-12-06) improvement of pruning.
-- Except for variables, they were applied to a huge neutral proof term coming from the ring solver.
-- Agda could not prune before the improved neutrality check implemented by Andrea(s) 2014-12-05/06.
--
-- As a consequence, Agda would often reattempt solving, each time doing the expensive
-- occurs check. This would extremely slow down Agda.
weakening : ∀ {n m p p'}(C : Γ n)(C' : Γ m) → C ++ C' ⊢ p → C ++ [ p' ] ++ C' ⊢ p
weakening {n} {m} {p' = p'} C C' (hyp .(C ++ C') v) = subst (λ R → C ++ (_ ∷ C') ⊢ R) {!!}
(hyp (C ++ (_ ∷ C')) (subst (λ x → Fin x) proof (inject₁ v))) where
proof : suc (n +N m) ≡ n +N suc m
proof = (solve 2 (λ n₁ m₁ → con 1 :+ (n₁ :+ m₁) := n₁ :+ (con 1 :+ m₁)) refl n m)
weakening C C' (andI prf prf') = andI (weakening C C' prf) (weakening C C' prf')
weakening C C' (andEL prf) = andEL (weakening C C' prf)
weakening C C' (andER prf) = andER (weakening C C' prf)
weakening C C' (orIL p'' prf) = orIL p'' (weakening C C' prf)
weakening C C' (orIR p prf) = orIR p (weakening C C' prf)
weakening C C' (orE prf prf₁ prf₂) = orE (weakening C C' prf) (weakening (_ ∷ C) C' prf₁) (weakening (_ ∷ C) C' prf₂)
-- Should check fast now and report the ? as unsolved meta.
| {
"alphanum_fraction": 0.5588865096,
"avg_line_length": 43.2407407407,
"ext": "agda",
"hexsha": "29d8ea9310c99795cfde7ce2d245a4681a3aa6e2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/LibSucceed/Issue1382.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/LibSucceed/Issue1382.agda",
"max_line_length": 117,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/LibSucceed/Issue1382.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 954,
"size": 2335
} |
{-# OPTIONS --without-K #-}
-- Inspired by Thorsten Altenkirch's definition of Groupoids
-- see his OmegaCats repo on github. And copumpkin's definition of
-- Category (see his categories repo, also on github).
module Groupoid where
open import Level using (zero)
open import Data.Empty using (⊥)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; proj₁; proj₂; _,_)
open import Function using (flip)
open import Relation.Binary
using (Rel; IsEquivalence; Reflexive; Symmetric; Transitive;
module IsEquivalence)
------------------------------------------------------------------------------
-- Useful
Rel0 : Set → Set₁
Rel0 A = Rel A zero
-- 1-groupoids are those where the various laws hold up to ≈.
record 1Groupoid : Set₁ where
infixr 9 _∘_
infixr 5 _↝_
infix 4 _≈_
field
set : Set₀
_↝_ : set → set → Set
_≈_ : ∀ {A B} → A ↝ B → A ↝ B → Set
id : ∀ {x} → x ↝ x
_∘_ : ∀ {x y z} → y ↝ z → x ↝ y → x ↝ z
_⁻¹ : ∀ {x y} → x ↝ y → y ↝ x
lneutr : ∀ {x y} (α : x ↝ y) → id ∘ α ≈ α
rneutr : ∀ {x y} (α : x ↝ y) → α ∘ id ≈ α
assoc : ∀ {w x y z} (α : y ↝ z) (β : x ↝ y) (δ : w ↝ x) →
(α ∘ β) ∘ δ ≈ α ∘ (β ∘ δ)
equiv : ∀ {x y} → IsEquivalence (_≈_ {x} {y})
linv : ∀ {x y}(α : x ↝ y) → α ⁻¹ ∘ α ≈ id {x}
rinv : ∀ {x y}(α : x ↝ y) → α ∘ α ⁻¹ ≈ id {y}
∘-resp-≈ : ∀ {x y z} {f h : y ↝ z} {g i : x ↝ y} → f ≈ h → g ≈ i →
f ∘ g ≈ h ∘ i
_[_,_] : (C : 1Groupoid) → 1Groupoid.set C → 1Groupoid.set C → Set
_[_,_] = 1Groupoid._↝_
open 1Groupoid
_⊎G_ : 1Groupoid → 1Groupoid → 1Groupoid
A ⊎G B = record
{ set = A.set ⊎ B.set
; _↝_ = _⇛_
; _≈_ = λ {x} → mk≈ {x}
; id = λ {x} → id⇛ {x}
; _∘_ = λ {x} → _∙G_ {x = x}
; _⁻¹ = λ {x} → inv {x = x}
; lneutr = λ {x} → lid⇛ {x}
; rneutr = λ {x} → rid⇛ {x}
; assoc = λ {x} a b g → assoc∙ {x} a b g
; equiv = λ {x} → equiv≈ {x}
; linv = λ {x} → linv⇛ {x}
; rinv = λ {x} → rinv⇛ {x}
; ∘-resp-≈ = λ {x} → resp {x} }
where
module A = 1Groupoid A
module B = 1Groupoid B
C : Set
C = set A ⊎ set B
_⇛_ : set A ⊎ set B → set A ⊎ set B → Set
_⇛_ (inj₁ x) (inj₁ y) = A._↝_ x y
_⇛_ (inj₁ _) (inj₂ _) = ⊥
_⇛_ (inj₂ _) (inj₁ _) = ⊥
_⇛_ (inj₂ x) (inj₂ y) = B._↝_ x y
mk≈ : {x y : set A ⊎ set B} → x ⇛ y → x ⇛ y → Set
mk≈ {inj₁ z} {inj₁ z'} a b = A._≈_ a b
mk≈ {inj₁ x} {inj₂ y} () ()
mk≈ {inj₂ y} {inj₁ x} () ()
mk≈ {inj₂ y} {inj₂ y'} a b = B._≈_ a b
id⇛ : {x : set A ⊎ set B} → x ⇛ x
id⇛ {inj₁ _} = id A
id⇛ {inj₂ _} = id B
_∙G_ : {x y z : set A ⊎ set B} → y ⇛ z → x ⇛ y → x ⇛ z
_∙G_ {inj₁ _} {inj₁ _} {inj₁ _} a b = A._∘_ a b
_∙G_ {inj₁ _} {inj₁ _} {inj₂ _} () b
_∙G_ {inj₁ x} {inj₂ y} a ()
_∙G_ {inj₂ y} {inj₁ x} a ()
_∙G_ {inj₂ y} {inj₂ y₁} {inj₁ x} () b
_∙G_ {inj₂ _} {inj₂ _} {inj₂ _} a b = B._∘_ a b
inv : {x y : set A ⊎ set B} → x ⇛ y → y ⇛ x
inv {inj₁ _} {inj₁ _} a = A._⁻¹ a
inv {inj₁ _} {inj₂ _} ()
inv {inj₂ _} {inj₁ _} ()
inv {inj₂ _} {inj₂ _} a = B._⁻¹ a
lid⇛ : {x y : C} (α : x ⇛ y) → mk≈ {x} (_∙G_ {x} (id⇛ {y}) α) α
lid⇛ {inj₁ _} {inj₁ _} a = A.lneutr a
lid⇛ {inj₁ _} {inj₂ _} ()
lid⇛ {inj₂ _} {inj₁ _} ()
lid⇛ {inj₂ _} {inj₂ _} a = B.lneutr a
rid⇛ : {x y : A.set ⊎ B.set} (α : x ⇛ y) → mk≈ {x} (_∙G_ {x} α (id⇛ {x})) α
rid⇛ {inj₁ _} {inj₁ _} α = A.rneutr α
rid⇛ {inj₁ _} {inj₂ _} ()
rid⇛ {inj₂ _} {inj₁ _} ()
rid⇛ {inj₂ _} {inj₂ _} α = B.rneutr α
assoc∙ : {w x y z : C} (α : y ⇛ z) (β : x ⇛ y) (δ : w ⇛ x) →
mk≈ {w} {z} (_∙G_ {w} (_∙G_ {x} α β) δ) (_∙G_ {w} α (_∙G_ {w} β δ))
assoc∙ {inj₁ x} {inj₁ x₁} {inj₁ x₂} {inj₁ x₃} α β γ = A.assoc α β γ
assoc∙ {inj₁ x} {inj₁ x₁} {inj₁ x₂} {inj₂ y} () _ _
assoc∙ {inj₁ x} {inj₁ x₁} {inj₂ y} _ () _
assoc∙ {inj₁ x} {inj₂ y} _ _ ()
assoc∙ {inj₂ y} {inj₁ x} _ _ ()
assoc∙ {inj₂ y} {inj₂ y₁} {inj₁ x} _ () _
assoc∙ {inj₂ y} {inj₂ y₁} {inj₂ y₂} {inj₁ x} () _ _
assoc∙ {inj₂ y} {inj₂ y₁} {inj₂ y₂} {inj₂ y₃} α β γ = B.assoc α β γ
linv⇛ : {x y : C} (α : x ⇛ y) → mk≈ {x} (_∙G_ {x} (inv {x} α) α) (id⇛ {x})
linv⇛ {inj₁ _} {inj₁ _} α = A.linv α
linv⇛ {inj₁ x} {inj₂ y} ()
linv⇛ {inj₂ y} {inj₁ x} ()
linv⇛ {inj₂ _} {inj₂ _} α = B.linv α
rinv⇛ : {x y : C} (α : x ⇛ y) → mk≈ {y} (_∙G_ {y} α (inv {x} α)) (id⇛ {y})
rinv⇛ {inj₁ _} {inj₁ _} α = A.rinv α
rinv⇛ {inj₁ x} {inj₂ y} ()
rinv⇛ {inj₂ y} {inj₁ x} ()
rinv⇛ {inj₂ _} {inj₂ _} α = B.rinv α
refl≈ : {x y : C} → Reflexive (mk≈ {x} {y})
refl≈ {inj₁ _} {inj₁ _} = IsEquivalence.refl A.equiv
refl≈ {inj₁ _} {inj₂ _} {()}
refl≈ {inj₂ _} {inj₁ _} {()}
refl≈ {inj₂ y} {inj₂ y₁} = IsEquivalence.refl B.equiv
sym≈ : {x y : C} → Symmetric (mk≈ {x} {y})
sym≈ {inj₁ _} {inj₁ _} = IsEquivalence.sym A.equiv
sym≈ {inj₁ _} {inj₂ _} {()}
sym≈ {inj₂ _} {inj₁ _} {()}
sym≈ {inj₂ y} {inj₂ y₁} = IsEquivalence.sym B.equiv
trans≈ : {x y : C} → Transitive (mk≈ {x} {y})
trans≈ {inj₁ _} {inj₁ _} = IsEquivalence.trans A.equiv
trans≈ {inj₁ _} {inj₂ _} {()}
trans≈ {inj₂ _} {inj₁ _} {()}
trans≈ {inj₂ _} {inj₂ _} = IsEquivalence.trans B.equiv
equiv≈ : {x y : C} → IsEquivalence (mk≈ {x} {y})
equiv≈ {x} =
record { refl = refl≈ {x}; sym = sym≈ {x}; trans = trans≈ {x} }
resp : {x y z : C} {f h : y ⇛ z} {g i : x ⇛ y} →
mk≈ {y} f h → mk≈ {x} g i → mk≈ {x} (_∙G_ {x} f g) (_∙G_ {x} h i)
resp {inj₁ _} {inj₁ _} {inj₁ _} = A.∘-resp-≈
resp {inj₁ _} {inj₁ _} {inj₂ _} {()}
resp {inj₁ _} {inj₂ _} {_} {_} {_} {()}
resp {inj₂ _} {inj₁ _} {_} {_} {_} {()}
resp {inj₂ _} {inj₂ _} {inj₁ _} {()}
resp {inj₂ _} {inj₂ _} {inj₂ _} = B.∘-resp-≈
_×G_ : 1Groupoid → 1Groupoid → 1Groupoid
A ×G B = record
{ set = A.set × B.set
; _↝_ = liftG A._↝_ B._↝_
; _≈_ = liftG A._≈_ B._≈_
; id = A.id , B.id
; _∘_ = liftOp2 {Z₁ = A._↝_} {B._↝_} A._∘_ B._∘_
; _⁻¹ = λ x₁ → A._⁻¹ (proj₁ x₁) , B._⁻¹ (proj₂ x₁)
; lneutr = λ α → A.lneutr (proj₁ α) , B.lneutr (proj₂ α)
; rneutr = λ α → A.rneutr (proj₁ α) , B.rneutr (proj₂ α)
; assoc = λ α β δ →
A.assoc (proj₁ α) (proj₁ β) (proj₁ δ) ,
B.assoc (proj₂ α) (proj₂ β) (proj₂ δ)
; equiv = λ {x} {y} →
let module W = IsEquivalence (A.equiv {proj₁ x} {proj₁ y})
module Z = IsEquivalence (B.equiv {proj₂ x} {proj₂ y}) in
record { refl = W.refl , Z.refl
; sym = λ i≈j → W.sym (proj₁ i≈j) , Z.sym (proj₂ i≈j)
; trans = λ i≈j j≈k →
(W.trans (proj₁ i≈j) (proj₁ j≈k)) ,
((Z.trans (proj₂ i≈j) (proj₂ j≈k))) }
; linv = λ α → A.linv (proj₁ α) , B.linv (proj₂ α)
; rinv = λ α → A.rinv (proj₁ α) , B.rinv (proj₂ α)
; ∘-resp-≈ = λ x₁ x₂ →
(A.∘-resp-≈ (proj₁ x₁) (proj₁ x₂)) ,
B.∘-resp-≈ (proj₂ x₁) (proj₂ x₂) }
where
module A = 1Groupoid A
module B = 1Groupoid B
C : Set
C = A.set × B.set
liftG : {X Y : Set} → Rel0 X → Rel0 Y → X × Y → X × Y → Set
liftG F G = λ x y → F (proj₁ x) (proj₁ y) × G (proj₂ x) (proj₂ y)
liftOp2 : {A₁ A₂ : Set} {x y z : A₁ × A₂} {Z₁ : Rel0 A₁} {Z₂ : Rel0 A₂} →
let _⇛_ = liftG Z₁ Z₂ in
let _↝₁_ : (a b : A₁ × A₂) → Set
_↝₁_ = λ a b → Z₁ (proj₁ a) (proj₁ b)
_↝₂_ : (a b : A₁ × A₂) → Set
_↝₂_ = λ a b → Z₂ (proj₂ a) (proj₂ b) in
(y ↝₁ z → x ↝₁ y → x ↝₁ z) → (y ↝₂ z → x ↝₂ y → x ↝₂ z)
→ y ⇛ z → x ⇛ y → x ⇛ z
liftOp2 F G = λ x y → F (proj₁ x) (proj₁ y) , G (proj₂ x) (proj₂ y)
-- Discrete paths. Essentially ≡.
data DPath {A : Set} (x : A) : A → Set where
reflD : DPath x x
transD : {A : Set} {x y z : A} → DPath y z → DPath x y → DPath x z
transD reflD reflD = reflD
symD : {A : Set} {x y : A} → DPath x y → DPath y x
symD reflD = reflD
lidD : {A : Set} {x y : A} (α : DPath x y) → DPath (transD reflD α) α
lidD reflD = reflD
ridD : {A : Set} {x y : A} (α : DPath x y) → DPath (transD α reflD) α
ridD reflD = reflD
assocD : {A : Set} {w x y z : A}
(α : DPath y z) (β : DPath x y) (δ : DPath w x) →
DPath (transD (transD α β) δ) (transD α (transD β δ))
assocD reflD reflD reflD = reflD
linvD : {A : Set} {x y : A} (α : DPath x y) → DPath (transD (symD α) α) reflD
linvD reflD = reflD
rinvD : {A : Set} {x y : A} (α : DPath x y) → DPath (transD α (symD α)) reflD
rinvD reflD = reflD
equivD : {A : Set} {x y : A} → IsEquivalence {_} {_} {DPath x y} DPath
equivD = λ {A} {x} {y} → record
{ refl = reflD
; sym = symD
; trans = flip transD }
respD : {A : Set} {x y z : A} {f h : DPath y z} {g i : DPath x y} →
DPath f h → DPath g i → DPath (transD f g) (transD h i)
respD reflD reflD = reflD
discrete : Set → 1Groupoid
discrete a = record
{ set = a
; _↝_ = DPath
; _≈_ = DPath -- or could use _≡_ .
; id = reflD
; _∘_ = transD
; _⁻¹ = symD
; lneutr = lidD
; rneutr = ridD
; assoc = assocD
; linv = linvD
; rinv = rinvD
; equiv = equivD
; ∘-resp-≈ = respD }
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4530380942,
"avg_line_length": 35.2925925926,
"ext": "agda",
"hexsha": "98d4c9589542d6f1cc8fc03b006ab85b4bee8ee1",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Groupoid.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Groupoid.agda",
"max_line_length": 79,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Groupoid.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 4594,
"size": 9529
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Instance.Discrete where
-- Discrete Functor
-- from Sets to Cats. This works, unlike in the previous version of the library,
-- because the equality in Cats is properly NaturalIsomorphism instead of something stricter,
-- no need for that pesky Heterogeneous anything.
open import Categories.Category
open import Categories.Functor
open import Categories.Category.Instance.Sets
open import Categories.Category.Instance.Cats
open import Categories.NaturalTransformation using (ntHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism
import Categories.Category.Discrete as D
import Relation.Binary.PropositionalEquality as ≡
open import Function renaming (id to idf; _∘_ to _●_)
Discrete : ∀ {o} → Functor (Sets o) (Cats o o o)
Discrete {o} = record
{ F₀ = D.Discrete
; F₁ = DiscreteFunctor
; identity = DiscreteId
; homomorphism = PointwiseHom
; F-resp-≈ = ExtensionalityNI
}
where
DiscreteFunctor : {A B : Set o} → (A → B) → Cats o o o [ D.Discrete A , D.Discrete B ]
DiscreteFunctor f = record
{ F₀ = f
; F₁ = ≡.cong f
; identity = ≡.refl
; homomorphism = λ { {_} {_} {_} {≡.refl} {≡.refl} → ≡.refl}
; F-resp-≈ = λ g≡h → ≡.cong (≡.cong f) g≡h -- marvel at the weirdness involved
}
DiscreteId : {A : Set o} → NaturalIsomorphism (DiscreteFunctor {A} idf) id
DiscreteId = record
{ F⇒G = record { η = λ X → ≡.refl ; commute = λ { ≡.refl → ≡.refl } ; sym-commute = λ { ≡.refl → ≡.refl} }
; F⇐G = record { η = λ _ → ≡.refl ; commute = λ { ≡.refl → ≡.refl } ; sym-commute = λ { ≡.refl → ≡.refl} }
; iso = λ X → record { isoˡ = ≡.refl ; isoʳ = ≡.refl }
}
PointwiseHom : {X Y Z : Set o} {g : X → Y} {h : Y → Z} →
NaturalIsomorphism (DiscreteFunctor (h ● g)) (DiscreteFunctor h ∘F DiscreteFunctor g)
PointwiseHom = record
{ F⇒G = record { η = λ _ → ≡.refl ; commute = λ { ≡.refl → ≡.refl} ; sym-commute = λ { ≡.refl → ≡.refl} }
; F⇐G = record { η = λ _ → ≡.refl ; commute = λ { ≡.refl → ≡.refl} ; sym-commute = λ { ≡.refl → ≡.refl} }
; iso = λ X → record { isoˡ = ≡.refl ; isoʳ = ≡.refl }
}
ExtensionalityNI : {A B : Set o} {g h : A → B} →
({x : A} → g x ≡.≡ h x) → NaturalIsomorphism (DiscreteFunctor g) (DiscreteFunctor h)
ExtensionalityNI g≡h = record
{ F⇒G = ntHelper record { η = λ X → g≡h {X} ; commute = λ { ≡.refl → ≡.sym (≡.trans-reflʳ g≡h)} }
; F⇐G = ntHelper record { η = λ X → ≡.sym (g≡h {X}) ; commute = λ { ≡.refl → ≡.sym (≡.trans-reflʳ _)} }
; iso = λ X → record { isoˡ = ≡.trans-symʳ g≡h ; isoʳ = ≡.trans-symˡ g≡h }
}
| {
"alphanum_fraction": 0.5935887988,
"avg_line_length": 47.6140350877,
"ext": "agda",
"hexsha": "022ddf4d99362acf2208275c70eb2356a106a6aa",
"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": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Instance/Discrete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"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": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Instance/Discrete.agda",
"max_line_length": 113,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Instance/Discrete.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": 1017,
"size": 2714
} |
-- Andreas, 2018-06-14, issue #2513, surviving shape-irrelevance annotations.
data Wrap (A : Set) : Set where
@shape-irrelevant wrap : A → Wrap A
| {
"alphanum_fraction": 0.7046979866,
"avg_line_length": 29.8,
"ext": "agda",
"hexsha": "1735b9c7460fd14086364e5d6abbb761dd09e057",
"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/ShapeIrrelevantConstructor.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/ShapeIrrelevantConstructor.agda",
"max_line_length": 77,
"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/ShapeIrrelevantConstructor.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": 48,
"size": 149
} |
module Lec2 where
data Zero : Set where
{-
cannaeMake : Zero
cannaeMake = cannaeMake
-}
magic : {X : Set} -> Zero -> X
magic ()
record One : Set where
constructor <>
tryit : One
tryit = <>
tryit2 : One
tryit2 = record {}
data List (X : Set) : Set where
[] : List X
_::_ : X -> List X -> List X
NonEmpty : {X : Set} -> List X -> Set
NonEmpty [] = Zero
NonEmpty (x :: xs) = One
head : {X : Set} -> (xs : List X) -> NonEmpty xs -> X
head [] ()
head (x :: xs) _ = x
{-
examples : List Zero
examples = {!-l!}
examples2 : List One
examples2 = {!-l!}
-}
data Two : Set where
tt : Two
ff : Two
if_then_else_ : {X : Set} -> Two -> X -> X -> X
if b then t else e = e
-- if ff then t else e = t
caseTwo : {P : Two -> Set} -> P tt -> P ff -> (b : Two) -> P b
caseTwo pt pf tt = pt
caseTwo pt pf ff = pf
not : Two -> Two
not tt = ff
not ff = tt
xor : Two -> Two -> Two
xor x y with not y
xor tt y | tt = tt
xor ff y | tt = ff
xor tt y | ff = ff
xor ff y | ff = tt
| {
"alphanum_fraction": 0.5537359263,
"avg_line_length": 15.265625,
"ext": "agda",
"hexsha": "5332e341e88900b0e4609923d1dafe770025c266",
"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": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "Lec2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "clarkdm/CS410",
"max_issues_repo_path": "Lec2.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "Lec2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 361,
"size": 977
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.DirectSum.DirectSumHIT.UniversalProperty where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.AbGroup.Instances.DirectSumHIT
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
private variable
ℓ ℓ' ℓ'' : Level
open AbGroupStr
open IsGroupHom
-----------------------------------------------------------------------------
-- Definition
module _
(Idx : Type ℓ)
(G : (k : Idx) → Type ℓ')
(Gstr : (k : Idx) → AbGroupStr (G k))
(HAbGr@(H , Hstr) : AbGroup ℓ'')
(fHhom : (k : Idx) → AbGroupHom ((G k) , (Gstr k)) HAbGr)
where
private
fH : (k : Idx) → G k → H
fH = λ k → fst (fHhom k)
fHstr : (k : Idx) → _
fHstr = λ k → snd (fHhom k)
injₖ : (k : Idx) → G k → ⊕HIT Idx G Gstr
injₖ k a = base k a
injₖ-hom : (k : Idx) → AbGroupHom ((G k) , (Gstr k)) (⊕HIT-AbGr Idx G Gstr)
injₖ-hom k = injₖ k , (makeIsGroupHom λ a b → sym (base-add _ _ _) )
-- universalProperty :
⊕HIT→H : ⊕HIT Idx G Gstr → H
⊕HIT→H = DS-Rec-Set.f _ _ _ _ (is-set Hstr)
(0g Hstr)
(λ k a → fH k a)
(Hstr ._+_)
(+Assoc Hstr)
(+IdR Hstr)
(+Comm Hstr)
(λ k → pres1 (fHstr k))
λ k a b → sym (pres· (fHstr k) _ _)
⊕HIT→H-hom : AbGroupHom (⊕HIT-AbGr Idx G Gstr) HAbGr
⊕HIT→H-hom = ⊕HIT→H , (makeIsGroupHom (λ _ _ → refl))
-- Universal Property
up∃⊕HIT : (k : Idx) → fHhom k ≡ compGroupHom (injₖ-hom k) ⊕HIT→H-hom
up∃⊕HIT k = ΣPathTransport→PathΣ _ _
((funExt (λ _ → refl))
, isPropIsGroupHom _ _ _ _)
upUnicity⊕HIT : (hhom : AbGroupHom (⊕HIT-AbGr Idx G Gstr) HAbGr) →
(eqInj : (k : Idx) → fHhom k ≡ compGroupHom (injₖ-hom k) hhom)
→ hhom ≡ ⊕HIT→H-hom
upUnicity⊕HIT (h , hstr) eqInj = ΣPathTransport→PathΣ _ _
(helper , isPropIsGroupHom _ _ _ _)
where
helper : _
helper = funExt (DS-Ind-Prop.f _ _ _ _ (λ _ → is-set Hstr _ _)
(pres1 hstr)
(λ k a → sym (funExt⁻ (cong fst (eqInj k)) a))
λ {U V} ind-U ind-V → pres· hstr _ _ ∙ cong₂ (_+_ Hstr) ind-U ind-V)
| {
"alphanum_fraction": 0.5398946942,
"avg_line_length": 31.253164557,
"ext": "agda",
"hexsha": "26cb53b7c27bd6593ffd9595432af989a9c73630",
"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/Algebra/DirectSum/DirectSumHIT/UniversalProperty.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/Algebra/DirectSum/DirectSumHIT/UniversalProperty.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/DirectSum/DirectSumHIT/UniversalProperty.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 911,
"size": 2469
} |
module Nat where
open import Eq
data ℕ : Set where
Z : ℕ
S : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
infixl 6 _+_
infixl 7 _×_
_+_ : ℕ → ℕ → ℕ
Z + n = n
(S k) + n = S(k + n)
{-# BUILTIN NATPLUS _+_ #-}
_×_ : ℕ → ℕ → ℕ
Z × n = Z
S m × n = n + m × n
{-# BUILTIN NATTIMES _×_ #-}
*-right-zero : ∀ (n : ℕ) → n × Z ≡ Z
*-right-zero Z = Refl
*-right-zero (S n) = *-right-zero n
testEq : (x : ℕ) → (y : ℕ) → (p : x ≡ y) → ℕ
testEq x _ Refl = x
| {
"alphanum_fraction": 0.4776785714,
"avg_line_length": 14,
"ext": "agda",
"hexsha": "ffc4b0dc474cb23a87b07dbd2407312cb81c3008",
"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": "76743baacba0f07992bac5234ba8045d18706893",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "mjhopkins/PowerOfPi",
"max_forks_repo_path": "Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76743baacba0f07992bac5234ba8045d18706893",
"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": "mjhopkins/PowerOfPi",
"max_issues_repo_path": "Nat.agda",
"max_line_length": 44,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76743baacba0f07992bac5234ba8045d18706893",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "mjhopkins/PowerOfPi",
"max_stars_repo_path": "Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-25T13:12:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-25T13:12:15.000Z",
"num_tokens": 197,
"size": 448
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Monoid.Instances.NatVec where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ ; isSetℕ)
open import Cubical.Data.Vec
open import Cubical.Data.Vec.OperationsNat
open import Cubical.Algebra.Monoid
NatVecMonoid : (n : ℕ) → Monoid ℓ-zero
fst (NatVecMonoid n) = Vec ℕ n
MonoidStr.ε (snd (NatVecMonoid n)) = replicate 0
MonoidStr._·_ (snd (NatVecMonoid n)) = _+n-vec_
MonoidStr.isMonoid (snd (NatVecMonoid n)) = makeIsMonoid (VecPath.isOfHLevelVec 0 n isSetℕ)
+n-vec-assoc +n-vec-rid +n-vec-lid
| {
"alphanum_fraction": 0.688,
"avg_line_length": 32.8947368421,
"ext": "agda",
"hexsha": "ff2a19041e3af9025ac1b31295ae66a8304a1639",
"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/Algebra/Monoid/Instances/NatVec.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/Algebra/Monoid/Instances/NatVec.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/Monoid/Instances/NatVec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 201,
"size": 625
} |
{-# OPTIONS --without-K --rewriting --exact-split #-}
open import lib.Basics
open import lib.types.Paths
open import lib.types.Coproduct
open import Graphs.Definition
open import Coequalizers.Definition
module Coequalizers.TrivialExtension where
module TExtensionCoeq-l {i : ULevel} {V : Type i} (v : V) where
instance
tegph : Graph ⊤ (V ⊔ ⊤)
tegph = record { π₀ = λ _ → inl v ; π₁ = λ _ → inr unit }
extn-equiv : V ≃ ((V ⊔ ⊤) / ⊤)
extn-equiv = equiv ((c[_] ∘ inl)) (((Coeq-rec (⊔-rec (idf V) (λ _ → v)) λ e → idp))) ((Coeq-elim _ (λ { (inl v') → idp ; (inr x) → quot x}) λ {unit → ↓-app=idf-in (∙'-unit-l _ ∙ ! lem ∙ᵣ quot unit)}))
λ _ → idp
where
lem : ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit) == idp
lem =
ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit)
=⟨ ap-∘ (c[_] ∘ inl) (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit) ⟩
ap (c[_] ∘ inl) (ap (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit))
=⟨ ap (ap (c[_] ∘ inl)) (Coeq-rec-β= _ _ _) ⟩
ap (c[_] ∘ inl) idp
=⟨ idp ⟩
idp
=∎
module TExtensionCoeq-r {i : ULevel} {V : Type i} (v : V) where
instance
tegph : Graph ⊤ (V ⊔ ⊤)
tegph = record { π₀ = λ _ → inr unit ; π₁ = λ _ → inl v }
extn-equiv : V ≃ ((V ⊔ ⊤) / ⊤)
extn-equiv = equiv ((c[_] ∘ inl)) (((Coeq-rec (⊔-rec (idf V) (λ _ → v)) λ e → idp))) ((Coeq-elim _ (λ { (inl v') → idp ; (inr x) → ! (quot x)}) λ {unit → ↓-app=idf-in ((!-inv'-l (quot unit) ∙ ! lem ∙ ! (∙-unit-r _)))}))
λ _ → idp
where
lem : ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit) == idp
lem =
ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit)
=⟨ ap-∘ (c[_] ∘ inl) (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit) ⟩
ap (c[_] ∘ inl) (ap (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit))
=⟨ ap (ap (c[_] ∘ inl)) (Coeq-rec-β= _ _ _) ⟩
ap (c[_] ∘ inl) idp
=⟨ idp ⟩
idp
=∎
| {
"alphanum_fraction": 0.4552882433,
"avg_line_length": 42.3653846154,
"ext": "agda",
"hexsha": "bfde01ddda97276041b3c86b3862933a10f2c5d5",
"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": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "awswan/nielsenschreier-hott",
"max_forks_repo_path": "main/Coequalizers/TrivialExtension.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"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": "awswan/nielsenschreier-hott",
"max_issues_repo_path": "main/Coequalizers/TrivialExtension.agda",
"max_line_length": 221,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "awswan/nielsenschreier-hott",
"max_stars_repo_path": "main/Coequalizers/TrivialExtension.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 987,
"size": 2203
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Instance.Properties.Setoids.Exact where
open import Categories.Category using (Category)
open import Categories.Category.Exact using (Exact)
open import Categories.Category.Instance.Properties.Setoids.Limits.Canonical using (pullback; FiberProduct; mk-×; FP-≈)
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Category.Monoidal.Instance.Setoids using (Setoids-Cartesian)
open import Categories.Category.Regular using (Regular)
open import Categories.Diagram.Coequalizer using (Coequalizer; IsCoequalizer; Coequalizer⇒Epi)
open import Categories.Diagram.Coequalizer.Properties
open import Categories.Diagram.KernelPair using (KernelPair)
open import Categories.Diagram.Pullback using (Pullback; up-to-iso)
open import Categories.Diagram.Pullback.Properties
open import Categories.Morphism using (_≅_; Epi)
open import Categories.Morphism.Regular using (RegularEpi)
open import Categories.Object.InternalRelation using (Equivalence; EqSpan; KP⇒Relation; KP⇒EqSpan; KP⇒Equivalence; module Relation; rel)
open import Data.Bool.Base using (Bool; true; false; T)
open import Data.Empty.Polymorphic using (⊥)
open import Data.Fin using (Fin; zero) renaming (suc to nzero)
open import Data.Product using (∃; proj₁; proj₂; _,_; Σ-syntax; _×_; -,_; map; zip; swap; map₂)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Unit.Polymorphic.Base using (⊤; tt)
open import Function using (flip) renaming (id to id→; _∘′_ to _∘→_)
open import Function.Equality as SΠ using (Π; _⇨_) renaming (id to ⟶-id; _∘_ to _∘⟶_)
open import Function.Definitions using (Surjective)
open import Level
open import Relation.Binary using (Setoid; Rel; IsEquivalence)
import Relation.Binary.Reasoning.Setoid as SR
open import Categories.Category.Instance.SingletonSet
open Setoid renaming (_≈_ to [_][_≈_]; Carrier to ∣_∣) using (isEquivalence; refl; sym; trans)
open Π using (_⟨$⟩_; cong)
module _ ℓ where
private
S = Setoids ℓ ℓ
open Category S hiding (_≈_)
module S = Category S
open Pullback using (P; p₁; p₂)
-- the next bits all depend on a Setoid X and an Equivalence E, factor those out
module _ {X : Setoid ℓ ℓ} (E : Equivalence S X) where
-- let some things have short names
open Equivalence E using (R; module R; eqspan)
module ES = EqSpan eqspan
private
module X = Setoid X using (refl; sym; trans; _≈_)
-- convenient inline versions
infix 2 ⟺
infixr 3 _○_
⟺ : {x₁ x₂ : ∣ X ∣} → x₁ X.≈ x₂ → x₂ X.≈ x₁
⟺ = Setoid.sym X
_○_ : {x₁ x₂ x₃ : ∣ X ∣} → x₁ X.≈ x₂ → x₂ X.≈ x₃ → x₁ X.≈ x₃
_○_ = Setoid.trans X
record Equation (x₁ x₂ : ∣ X ∣) : Set ℓ where
constructor eqn
open Setoid X using (_≈_)
field
name : ∣ R.dom ∣
x₁≈ : R.p₁ ⟨$⟩ name ≈ x₁
≈x₂ : R.p₂ ⟨$⟩ name ≈ x₂
open Equation
-- is re-used below, so make it easier to do so by exposing directly
quotient-trans : {x₁ x₂ y₁ y₂ : ∣ X ∣} →
(p : Equation x₁ y₁) → (q : Equation x₂ y₂) →
[ X ][ x₁ ≈ x₂ ] → [ X ][ y₁ ≈ y₂ ] → [ R.dom ][ name p ≈ name q ]
quotient-trans {x₁} {x₂} {y₁} {y₂} (eqn eq x₁≈ ≈y₁) (eqn eq′ x₂≈ ≈y₂) x₁≈x₂ y₁≈y₂ =
R.relation {SingletonSetoid}
(record { _⟨$⟩_ = λ _ → eq ; cong = λ _ → refl R.dom})
(record { _⟨$⟩_ = λ _ → eq′ ; cong = λ _ → refl R.dom})
(λ { zero _ → x₁≈ ○ x₁≈x₂ ○ ⟺ x₂≈
; (nzero _) _ → ≈y₁ ○ y₁≈y₂ ○ ⟺ ≈y₂}) tt
Quotient-Equivalence : IsEquivalence Equation
Quotient-Equivalence = record
{
refl = eqn _ (ES.is-refl₁ X.refl) (ES.is-refl₂ X.refl)
; sym = λ { (eqn r eq₁ eq₂) → eqn (ES.sym ⟨$⟩ r) (ES.is-sym₁ D.refl ○ eq₂) (ES.is-sym₂ D.refl ○ eq₁) }
; trans = λ { (eqn r x≈ ≈y) (eqn s y≈ ≈z) →
let t = record { elem₁ = _ ; elem₂ = _ ; commute = y≈ ○ ⟺ ≈y } in
eqn
(ES.trans ∘⟶ P₀⇒P₁ ⟨$⟩ t)
(ES.is-trans₁ R×R.refl ○ (cong R.p₁ (p₂-≈ {t} {t} (D.refl , D.refl)) ○ x≈))
(ES.is-trans₂ R×R.refl ○ (cong R.p₂ (p₁-≈ {t} {t} (D.refl , D.refl)) ○ ≈z))
}
}
where
module D = Setoid R.dom using (refl)
module R×R = Setoid ES.R×R.dom using (refl)
fp : Pullback S R.p₁ R.p₂
fp = pullback ℓ ℓ R.p₁ R.p₂
open IsoPb S fp ES.R×R using (P₀⇒P₁; p₁-≈; p₂-≈)
Quotient-Setoid : Setoid ℓ ℓ
Quotient-Setoid = record { Carrier = ∣ X ∣ ; _≈_ = Equation; isEquivalence = Quotient-Equivalence }
Quotient-Coequalizer : Coequalizer S (Equivalence.R.p₁ E) (Equivalence.R.p₂ E)
Quotient-Coequalizer = record
{ obj = X∼
; arr = inj
; isCoequalizer = record
{ equality = inj-≈
; coequalize = λ {_}{h} → quotient h
; universal = λ {_}{h} → cong h
; unique = λ {_}{h}{i}{eq′} → unique {_}{h}{i}{eq′}
}
}
where
X∼ : Setoid ℓ ℓ
X∼ = Quotient-Setoid
inj : X ⇒ X∼
inj = record
{ _⟨$⟩_ = id→
; cong = λ {x₁} eq → eqn (ES.refl ⟨$⟩ x₁) (ES.is-refl₁ X.refl) (ES.is-refl₂ X.refl ○ eq)
}
inj-≈ : inj ∘ R.p₁ S.≈ inj ∘ R.p₂
inj-≈ {x} x≈y = eqn x X.refl (cong R.p₂ x≈y)
-- coEqualizer wants the 'h' to be implicit, but can't figure it out, so make it explicit here
quotient : {C : Obj} (h : X ⇒ C) → h ∘ R.p₁ S.≈ h ∘ R.p₂ → X∼ ⇒ C
quotient {C} h eq = record
{ _⟨$⟩_ = h ⟨$⟩_
; cong = λ { (eqn r x≈ ≈y) → trans C (cong h (X.sym x≈)) (trans C (eq (refl R.dom)) (cong h ≈y))}
}
unique : {C : Obj} {h : X ⇒ C} {i : X∼ ⇒ C} {eq : h ∘ R.p₁ S.≈ h ∘ R.p₂} → h S.≈ i ∘ inj → i S.≈ quotient h eq
unique {C} {h} {i} {eq′} eq {x} {y} (eqn r x≈ ≈y) = begin
i ⟨$⟩ x ≈˘⟨ eq X.refl ⟩
h ⟨$⟩ x ≈˘⟨ cong h x≈ ⟩
h ⟨$⟩ (R.p₁ ⟨$⟩ r) ≈⟨ eq′ (refl R.dom) ⟩
h ⟨$⟩ (R.p₂ ⟨$⟩ r) ≈⟨ cong h ≈y ⟩
h ⟨$⟩ y ∎
where open SR C
-- Setoid Surjectivity
SSurj : {A B : Setoid ℓ ℓ} (f : A ⇒ B) → Set ℓ
SSurj {A} {B} f = Surjective (Setoid._≈_ A) (Setoid._≈_ B) (f ⟨$⟩_)
-- Proposition 1 from "Olov Wilander, Setoids and universes"
Epi⇒Surjective : ∀ {A B : Setoid ℓ ℓ} (f : A ⇒ B) → Epi S f → SSurj f
Epi⇒Surjective {A}{B} f epi y = g≈h (refl B {y}) .proj₁ (λ ()) _
where
infix 3 _↔_
_↔_ : Set ℓ → Set ℓ → Set ℓ
A ↔ B = (A → B) × (B → A)
B′ : Setoid ℓ ℓ
B′ = record
{ Carrier = Bool × ∣ B ∣
; _≈_ = λ { (a , x) (b , y) → ((T a → Σ[ z ∈ ∣ A ∣ ] [ B ][ f ⟨$⟩ z ≈ x ]) ↔ (T b → Σ[ z ∈ ∣ A ∣ ] [ B ][ f ⟨$⟩ z ≈ y ])) }
; isEquivalence = record
{ refl = id→ , id→
; sym = swap
; trans = zip (flip _∘→_) _∘→_
}
}
g : B ⇒ B′
g = record { _⟨$⟩_ = λ x → false , x ; cong = λ _ → (λ _ ()) , (λ _ ()) }
h : B ⇒ B′
h = record
{ _⟨$⟩_ = true ,_
; cong = λ x≈y →
(λ eq _ → map₂ (λ z → trans B z x≈y) (eq _))
, (λ eq _ → let (a , eq′) = eq _ in a , (trans B eq′ (sym B x≈y)))
}
g≈h : [ B ⇨ B′ ][ g ≈ h ]
g≈h = epi g h λ {x}{y} x≈y → (λ u _ → x , cong f x≈y) , λ _ ()
-- not needed for exactness, but worthwhile
Surjective⇒RegularEpi : ∀ {A B : Setoid ℓ ℓ} (f : A ⇒ B) → ((y : ∣ B ∣) → Σ[ x ∈ ∣ A ∣ ] [ B ][ f ⟨$⟩ x ≈ y ]) → RegularEpi S f
Surjective⇒RegularEpi {A}{B} f surj = record
{ h = p₁ kp
; g = p₂ kp
; coequalizer = record
{ equality = λ {x} {y} → commute kp {x} {y}
; coequalize = λ {_} {h} → Coeq.coeq {h = h}
; universal = λ {C} {h} {eq} → Coeq.universal′ {C} {h} (λ {x} {y} → eq {x} {y})
; unique = λ {_}{h}{i}{eq} h≈i∘f x≈y → Coeq.unique″ {_} {h} (λ {x} {y} → eq {x} {y}) {i} h≈i∘f x≈y
}
}
where
kp = pullback ℓ ℓ f f
open Pullback
module Coeq {C : S.Obj} {h : A S.⇒ C} where
open SR C
f⁻¹∘h : ∣ B ∣ → ∣ C ∣
f⁻¹∘h b = h ⟨$⟩ proj₁ (surj b)
module _ (h∘p₁≈h∘p₂ : h S.∘ p₁ kp S.≈ h S.∘ p₂ kp) where
cong′ : {i j : ∣ B ∣} → [ B ][ i ≈ j ] → [ C ][ h ⟨$⟩ proj₁ (surj i) ≈ h ⟨$⟩ proj₁ (surj j) ]
cong′ {y₁}{y₂} y₁≈y₂ = h∘p₁≈h∘p₂ {pt₁} {pt₁} (refl A , refl A)
where
x₁ x₂ : ∣ A ∣
x₁ = surj y₁ .proj₁
x₂ = surj y₂ .proj₁
eq₁ : [ B ][ f ⟨$⟩ x₁ ≈ y₁ ]
eq₁ = surj y₁ .proj₂
eq₂ : [ B ][ f ⟨$⟩ x₂ ≈ y₂ ]
eq₂ = surj y₂ .proj₂
pt₁ : FiberProduct f f
pt₁ = mk-× x₁ x₂ (trans B eq₁ (trans B y₁≈y₂ (sym B eq₂)))
coeq : B S.⇒ C
coeq = record { _⟨$⟩_ = f⁻¹∘h ; cong = cong′ }
universal′ : h S.≈ coeq S.∘ f
universal′ {x} {y} x≈y = begin
h ⟨$⟩ x ≈⟨ cong h x≈y ⟩
h ⟨$⟩ y ≈⟨ h∘p₁≈h∘p₂ {mk-× y x₁ (sym B eq₁)} {mk-× x x₁ (trans B (cong f x≈y) (sym B eq₁))} (sym A x≈y , refl A) ⟩
h ⟨$⟩ proj₁ (surj (f ⟨$⟩ y)) ≡⟨⟩ -- by definition of f⁻¹∘h
f⁻¹∘h (f ⟨$⟩ y) ≡⟨⟩ -- by definition of coeq
coeq S.∘ f ⟨$⟩ y ∎
where
x₁ : ∣ A ∣
x₁ = surj (f ⟨$⟩ y) .proj₁
eq₁ : [ B ][ f ⟨$⟩ x₁ ≈ f ⟨$⟩ y ]
eq₁ = surj (f ⟨$⟩ y) .proj₂
unique″ : {i : B S.⇒ C} → h S.≈ i S.∘ f → i S.≈ coeq
unique″ {i} h≈i∘f {x} {y} x≈y = begin
i ⟨$⟩ x ≈⟨ cong i x≈y ⟩
i ⟨$⟩ y ≈⟨ cong i (sym B eq₁) ⟩
i ∘ f ⟨$⟩ x₁ ≈⟨ sym C (h≈i∘f (refl A)) ⟩
h ⟨$⟩ x₁ ≡⟨⟩ -- by definition of f⁻¹∘h
f⁻¹∘h y ∎
where
x₁ : ∣ A ∣
x₁ = surj y .proj₁
eq₁ : [ B ][ f ⟨$⟩ x₁ ≈ y ]
eq₁ = surj y .proj₂
Setoids-Regular : Regular (Setoids ℓ ℓ)
Setoids-Regular = record
{ finitely-complete = record
{ cartesian = Setoids-Cartesian
; equalizer = λ _ _ → pullback×cartesian⇒equalizer S (pullback ℓ ℓ) Setoids-Cartesian
}
; coeq-of-kernelpairs = λ f kp → Quotient-Coequalizer record
{ R = KP⇒Relation S f kp
; eqspan = KP⇒EqSpan S f kp (pb kp)
}
; pullback-of-regularepi-is-regularepi = pb-of-re-is-re
}
where
pb : ∀ {A B} {f : A ⇒ B} (kp : KernelPair S f) → Pullback S (p₁ kp) (p₂ kp)
pb kp = pullback ℓ ℓ (p₁ kp) (p₂ kp)
pb-of-re-is-re : {A B D : Setoid ℓ ℓ} (f : B ⇒ A) {u : D ⇒ A} →
RegularEpi S f → (pb : Pullback S f u) → RegularEpi S (p₂ pb)
pb-of-re-is-re {A}{B}{D} f {u} record { C = C ; h = _ ; g = _ ; coequalizer = coeq } pb =
Surjective⇒RegularEpi (p₂ pb) λ y →
let (x , eq) = Epi⇒Surjective f (Coequalizer⇒Epi S record { arr = f ; isCoequalizer = coeq }) (u ⟨$⟩ y) in
let pt = mk-× x y eq in
P₀⇒P₁ ⟨$⟩ pt , p₂-≈ {pt} {pt} (refl B , refl D)
where
pb-fu : Pullback S f u
pb-fu = pullback ℓ ℓ f u
pb-ff : Pullback S f f
pb-ff = pullback ℓ ℓ f f
module B = Setoid B
module C = Setoid C
module D = Setoid D
open IsoPb S pb-fu pb
Setoids-Exact : Exact (Setoids ℓ ℓ)
Setoids-Exact = record
{ regular = Setoids-Regular
; quotient = Quotient-Coequalizer
; effective = λ {X} E → record
{ commute = λ eq → eqn _ (refl X) (cong (Relation.p₂ (R E)) eq)
; universal = λ { {Z}{h₁}{h₂} → universal E h₁ h₂ }
; unique = λ {Z}{h₁}{h₂}{u}{eq} eq₁ eq₂ {x}{y} → Relation.relation (R E) u (universal E h₁ h₂ eq)
λ { zero {x}{y} eq′ → trans X (eq₁ eq′) (sym X (p₁∘universal≈h₁ E h₁ h₂ eq (refl Z)))
; (nzero _) {x}{y} eq′ → trans X (eq₂ eq′) (sym X (p₂∘universal≈h₂ E h₁ h₂ eq (refl Z)))
}
; p₁∘universal≈h₁ = λ {Z}{h₁}{h₂}{eq} → p₁∘universal≈h₁ E h₁ h₂ eq
; p₂∘universal≈h₂ = λ {Z}{h₁}{h₂}{eq} → p₂∘universal≈h₂ E h₁ h₂ eq
}
}
where
open Equivalence
open Setoid
open Coequalizer using (arr)
universal : {X Z : Setoid ℓ ℓ} → (E : Equivalence S X) → (h₁ h₂ : Z ⇒ X) →
(eq : [ Z ⇨ Quotient-Setoid E ][ arr (Quotient-Coequalizer E) ∘ h₁ ≈ arr (Quotient-Coequalizer E) ∘ h₂ ]) →
Z ⇒ Relation.dom (R E)
universal {X}{Z} E h₁ h₂ eq = record
{ _⟨$⟩_ = λ z → let (eqn eq _ _) = eq {z}{z} (refl Z) in eq
; cong = λ {z}{z′} z≈z′ → quotient-trans E (eq {z}{z} (refl Z)) (eq {z′}{z′} (refl Z)) (cong h₁ z≈z′) (cong h₂ z≈z′)
}
p₁∘universal≈h₁ : {X Z : Setoid ℓ ℓ} → (E : Equivalence S X) → (h₁ h₂ : Z ⇒ X) →
(eq : [ Z ⇨ Quotient-Setoid E ][ arr (Quotient-Coequalizer E) ∘ h₁ ≈ arr (Quotient-Coequalizer E) ∘ h₂ ]) →
[ Z ⇨ X ][ Relation.p₁ (R E) ∘ (universal E h₁ h₂ eq) ≈ h₁ ]
p₁∘universal≈h₁ {X}{Z} _ h₁ h₂ eq x≈y = let (eqn _ p₁z≈ _) = eq (refl Z) in trans X p₁z≈ (cong h₁ x≈y)
p₂∘universal≈h₂ : {X Z : Setoid ℓ ℓ} → (E : Equivalence S X) → (h₁ h₂ : Z ⇒ X) →
(eq : [ Z ⇨ Quotient-Setoid E ][ arr (Quotient-Coequalizer E) ∘ h₁ ≈ arr (Quotient-Coequalizer E) ∘ h₂ ]) →
[ Z ⇨ X ][ Relation.p₂ (R E) ∘ (universal E h₁ h₂ eq) ≈ h₂ ]
p₂∘universal≈h₂ {X}{Z} _ h₁ h₂ eq x≈y = let (eqn _ _ p₂z≈) = eq (refl Z) in trans X p₂z≈ (cong h₂ x≈y)
| {
"alphanum_fraction": 0.4984458259,
"avg_line_length": 42.6246056782,
"ext": "agda",
"hexsha": "0a8353e4a8b7ea4c98451875819d5f4eb654ca57",
"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": "8f3c844d929508040dfa21f681fa260056214b73",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "maxsnew/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Exact.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8f3c844d929508040dfa21f681fa260056214b73",
"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": "maxsnew/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Exact.agda",
"max_line_length": 146,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8f3c844d929508040dfa21f681fa260056214b73",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "maxsnew/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Exact.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5460,
"size": 13512
} |
open import Data.List renaming (_∷_ to _∷ₗ_ ; [_] to [_]ₗ)
open import Data.Maybe
open import Data.Product
open import Data.Sum
open import AEff
open import EffectAnnotations
open import Preservation
open import Renamings
open import Substitutions
open import Types
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary
module ProcessPreservation where
-- REDUCTION OF PROCESS TYPES
infix 10 _⇝_
data _⇝_ : {o o' : O} → PType o → PType o' → Set where
id : {X : VType}
{o : O}
{i : I} →
----------------------
X ‼ o , i ⇝ X ‼ o , i
act : {X : VType}
{o o' o'' : O}
{i i' i'' : I} →
(ops : List Σₛ) →
(op : Σₛ) →
(o' , i') ≡ ops ↓↓ₑ (o , i) →
(o'' , i'') ≡ ((ops ++ [ op ]ₗ) ↓↓ₑ (o , i)) →
----------------------------------------------
(X ‼ o' , i') ⇝ (X ‼ o'' , i'')
par : {o o' o'' o''' : O}
{PP : PType o}
{QQ : PType o'}
{PP' : PType o''}
{QQ' : PType o'''} →
PP ⇝ PP' →
QQ ⇝ QQ' →
----------------------
(PP ∥ QQ) ⇝ (PP' ∥ QQ')
-- REDUCTION OF PROCESS TYPES IS REFLEXIVE
{- LEMMA 4.4 (1) -}
⇝-refl : {o : O} {PP : PType o} → PP ⇝ PP
⇝-refl {o} {X ‼ o , i} =
id
⇝-refl {.(_ ∪ₒ _)} {PP ∥ QQ} =
par ⇝-refl ⇝-refl
-- ACTION OF INTERRUPTS ON GENERAL PROCESS TYPES IS A REDUCTION
{- LEMMA 4.4 (2) -}
⇝-↓ₚ : {o : O}
{PP : PType o}
{op : Σₛ} →
--------------
PP ⇝ op ↓ₚ PP
⇝-↓ₚ {.o} {X ‼ o , i} {op} =
act [] op refl refl
⇝-↓ₚ {.(_ ∪ₒ _)} {PP ∥ QQ} {op} =
par ⇝-↓ₚ ⇝-↓ₚ
-- ACTION OF INTERRUPTS PRESERVES PROCESS TYPE REDUCTION
{- LEMMA 4.4 (3) -}
⇝-↓ₚ-cong : {o o' : O}
{PP : PType o}
{QQ : PType o'}
{op : Σₛ} →
PP ⇝ QQ →
--------------------
op ↓ₚ PP ⇝ op ↓ₚ QQ
⇝-↓ₚ-cong id =
id
⇝-↓ₚ-cong {_} {_} {_} {_} {op} (act {_} {o} {o'} {o''} {i} {i'} {i''} ops op' p q) =
act {o = o} {i = i} (op ∷ₗ ops) op' (cong (λ oi → op ↓ₑ oi) p) (cong (λ oi → op ↓ₑ oi) q)
⇝-↓ₚ-cong (par p q) =
par (⇝-↓ₚ-cong p) (⇝-↓ₚ-cong q)
-- PROCESS TYPE REDUCTION INCREASES SIGNAL INDEX
{- LEMMA 4.4 (4) -}
inj-proj₁ : {X Y : Set} {xy xy' : X × Y} → xy ≡ xy' → proj₁ xy ≡ proj₁ xy'
inj-proj₁ refl = refl
⇝-⊑ₒ : {o o' : O}
{PP : PType o}
{QQ : PType o'} →
PP ⇝ QQ →
------------------
o ⊑ₒ o'
⇝-⊑ₒ id =
⊑ₒ-refl
⇝-⊑ₒ (act {_} {o} {o'} {o''} {i} ops op p q) with inj-proj₁ p | inj-proj₁ q
... | r | s =
subst (λ o → o ⊑ₒ o'')
(sym r)
(subst (λ o'' → proj₁ (ops ↓↓ₑ (o , i)) ⊑ₒ o'')
(sym s)
(subst (λ v → proj₁ (ops ↓↓ₑ (o , i)) ⊑ₒ proj₁ v)
(sym (↓↓ₑ-act ops [ op ]ₗ))
(↓↓ₑ-⊑ₒ-act ops op)))
⇝-⊑ₒ (par p q) =
∪ₒ-fun (⇝-⊑ₒ p) (⇝-⊑ₒ q)
-- EVALUATION CONTEXTS FOR PROCESSES
infix 10 _⊢F⦂_
data _⊢F⦂_ (Γ : Ctx) : {o : O} → PType o → Set where
[-] : {o : O} →
{PP : PType o} →
--------------
Γ ⊢F⦂ PP
_∥ₗ_ : {o o' : O}
{PP : PType o}
{QQ : PType o'} →
Γ ⊢F⦂ PP →
Γ ⊢P⦂ QQ →
------------------
Γ ⊢F⦂ (PP ∥ QQ)
_∥ᵣ_ : {o o' : O}
{PP : PType o}
{QQ : PType o'} →
Γ ⊢P⦂ PP →
Γ ⊢F⦂ QQ →
------------------
Γ ⊢F⦂ (PP ∥ QQ)
↑ : {o : O}
{PP : PType o} →
(op : Σₛ) →
op ∈ₒ o →
Γ ⊢V⦂ ``(payload op) →
Γ ⊢F⦂ PP →
----------------------
Γ ⊢F⦂ PP
↓ : {o : O}
{PP : PType o}
(op : Σₛ) →
Γ ⊢V⦂ ``(payload op) →
Γ ⊢F⦂ PP →
----------------------
Γ ⊢F⦂ op ↓ₚ PP
-- FINDING THE TYPE OF THE HOLE OF A WELL-TYPED PROCESS EVALUATION CONTEXT
hole-ty-f : {Γ : Ctx} {o : O} {PP : PType o} → Γ ⊢F⦂ PP → Σ[ o' ∈ O ] (PType o')
hole-ty-f {_} {o} {PP} [-] =
o , PP
hole-ty-f (_∥ₗ_ {o} {o'} {PP} {QQ} F Q) =
proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F)
hole-ty-f (_∥ᵣ_ {o} {o'} {PP} {QQ} P F) =
proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F)
hole-ty-f (↑ op p V F) =
proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F)
hole-ty-f (↓ op V F) =
proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F)
-- FILLING A WELL-TYPED PROCESS EVALUATION CONTEXT
infix 30 _[_]f
_[_]f : {Γ : Ctx} {o : O} {PP : PType o} → (F : Γ ⊢F⦂ PP) → (P : Γ ⊢P⦂ proj₂ (hole-ty-f F)) → Γ ⊢P⦂ PP
[-] [ P ]f =
P
(F ∥ₗ Q) [ P ]f =
(F [ P ]f) ∥ Q
(Q ∥ᵣ F) [ P ]f =
Q ∥ (F [ P ]f)
(↑ op p V F) [ P ]f =
↑ op p V (F [ P ]f)
(↓ op V F) [ P ]f =
↓ op V (F [ P ]f)
-- TYPES OF WELL-TYPED PROCESS EVALUATION CONTEXTS ALSO REDUCE
⇝-f-⇝ : {Γ : Ctx}
{o o' : O}
{PP : PType o}
{QQ : PType o'} →
(F : Γ ⊢F⦂ PP) →
proj₂ (hole-ty-f F) ⇝ QQ →
------------------------------------------
Σ[ o'' ∈ O ] Σ[ RR ∈ PType o'' ] (PP ⇝ RR)
⇝-f-⇝ {_} {_} {o'} {_} {QQ} [-] p =
o' , QQ , p
⇝-f-⇝ (_∥ₗ_ {o} {o'} {PP} {QQ} F Q) p with ⇝-f-⇝ F p
... | o'' , RR , q =
(o'' ∪ₒ o') , (RR ∥ QQ) , par q ⇝-refl
⇝-f-⇝ (_∥ᵣ_ {o} {o'} {PP} {QQ} P F) p with ⇝-f-⇝ F p
... | o'' , RR , q =
(o ∪ₒ o'') , (PP ∥ RR) , par ⇝-refl q
⇝-f-⇝ (↑ op p V F) q with ⇝-f-⇝ F q
... | o'' , RR , r =
o'' , RR , r
⇝-f-⇝ (↓ op V F) p with ⇝-f-⇝ F p
... | o'' , RR , q =
proj₁ (op ↓ₚₚ RR) , (op ↓ₚ RR) , ⇝-↓ₚ-cong q
⇝-f-∈ₒ : {Γ : Ctx}
{o o' : O}
{PP : PType o}
{QQ : PType o'}
(F : Γ ⊢F⦂ PP) →
(p : proj₂ (hole-ty-f F) ⇝ QQ) →
--------------------------------
o ⊑ₒ proj₁ (⇝-f-⇝ F p)
⇝-f-∈ₒ [-] p =
⇝-⊑ₒ p
⇝-f-∈ₒ (F ∥ₗ Q) p =
∪ₒ-fun (⇝-f-∈ₒ F p) ⊑ₒ-refl
⇝-f-∈ₒ (P ∥ᵣ F) p =
∪ₒ-fun ⊑ₒ-refl (⇝-f-∈ₒ F p)
⇝-f-∈ₒ (↑ op p V F) q =
⇝-f-∈ₒ F q
⇝-f-∈ₒ (↓ {o} {PP} op V F) p =
⇝-f-∈ₒ-aux (⇝-f-⇝ F p) refl
where
⇝-f-∈ₒ-aux : (orp : Σ[ o'' ∈ O ] Σ[ RR ∈ PType o'' ] (PP ⇝ RR)) →
orp ≡ ⇝-f-⇝ F p →
----------------------------------------------------
proj₁ (op ↓ₚₚ PP) ⊑ₒ proj₁ (op ↓ₚₚ proj₁ (proj₂ orp))
⇝-f-∈ₒ-aux (o'' , RR , r) q =
⇝-⊑ₒ (⇝-↓ₚ-cong r)
{- LEMMA 4.6 -}
⇝-f : {Γ : Ctx}
{o o' : O}
{PP : PType o}
{QQ : PType o'} →
(F : Γ ⊢F⦂ PP) →
(p : proj₂ (hole-ty-f F) ⇝ QQ) →
---------------------------------
Γ ⊢F⦂ (proj₁ (proj₂ (⇝-f-⇝ F p)))
⇝-f [-] p =
[-]
⇝-f (F ∥ₗ Q) p with ⇝-f F p
... | q =
q ∥ₗ Q
⇝-f (Q ∥ᵣ F) p with ⇝-f F p
... | q =
Q ∥ᵣ q
⇝-f (↑ op p V F) q with ⇝-f F q
... | r =
↑ op (⇝-f-∈ₒ F q op p) V r
⇝-f (↓ op V F) p with ⇝-f F p
... | q =
↓ op V q
⇝-f-tyₒ : {Γ : Ctx}
{o o' : O}
{PP : PType o}
{QQ : PType o'} →
(F : Γ ⊢F⦂ PP) →
(p : proj₂ (hole-ty-f F) ⇝ QQ) →
--------------------------------
o' ≡ proj₁ (hole-ty-f (⇝-f F p))
⇝-f-tyₒ [-] p =
refl
⇝-f-tyₒ (F ∥ₗ Q) p =
⇝-f-tyₒ F p
⇝-f-tyₒ (P ∥ᵣ F) p =
⇝-f-tyₒ F p
⇝-f-tyₒ (↑ op p V F) q =
⇝-f-tyₒ F q
⇝-f-tyₒ (↓ op V F) p =
⇝-f-tyₒ F p
⇝-f-ty : {Γ : Ctx}
{o o' : O}
{PP : PType o}
{QQ : PType o'} →
(F : Γ ⊢F⦂ PP) →
(p : proj₂ (hole-ty-f F) ⇝ QQ) →
--------------------------------------
subst (λ o → PType o) (⇝-f-tyₒ F p) QQ
≡
proj₂ (hole-ty-f (⇝-f F p))
⇝-f-ty [-] p =
refl
⇝-f-ty (F ∥ₗ Q) p =
⇝-f-ty F p
⇝-f-ty (P ∥ᵣ F) p =
⇝-f-ty F p
⇝-f-ty (↑ op p V F) q =
⇝-f-ty F q
⇝-f-ty (↓ op V F) p =
⇝-f-ty F p
-- AUXILIARY TWO-LEVEL INDEXED SUBSTITUTION
subst-i : {X : Set} {x x' : X} → (Y : X → Set) → {y : Y x} {y' : Y x'} →
(Z : (x : X) → Y x → Set) → (p : x ≡ x') → subst Y p y ≡ y' → Z x y → Z x' y'
subst-i Y Z refl refl z = z
-- SMALL-STEP OPERATIONAL SEMANTICS FOR WELL-TYPED PROCESSES
-- (ADDITIONALLY SERVES AS THE PRESERVATION THEOREM)
{- THEOREM 4.7 -}
infix 10 _[_]↝_
data _[_]↝_ {Γ : Ctx} : {o o' : O} {PP : PType o} {QQ : PType o'} → Γ ⊢P⦂ PP → PP ⇝ QQ → Γ ⊢P⦂ QQ → Set where
-- RUNNING INDIVIDUAL COMPUTATIONS
run : {X : VType}
{o : O}
{i : I}
{M N : Γ ⊢M⦂ X ! (o , i)} →
M ↝ N →
---------------------------
(run M) [ id ]↝ (run N)
-- BROADCAST RULES
↑-∥ₗ : {o o' : O}
{PP : PType o}
{QQ : PType o'}
{op : Σₛ} →
(p : op ∈ₒ o) →
(V : Γ ⊢V⦂ `` (payload op)) →
(P : Γ ⊢P⦂ PP) →
(Q : Γ ⊢P⦂ QQ) →
------------------------------------------
((↑ op p V P) ∥ Q)
[ par ⇝-refl (⇝-↓ₚ {op = op}) ]↝
↑ op (∪ₒ-inl op p) V (P ∥ ↓ op V Q)
↑-∥ᵣ : {o o' : O}
{PP : PType o}
{QQ : PType o'}
{op : Σₛ} →
(p : op ∈ₒ o') →
(V : Γ ⊢V⦂ `` (payload op)) →
(P : Γ ⊢P⦂ PP) →
(Q : Γ ⊢P⦂ QQ) →
------------------------------------------
(P ∥ (↑ op p V Q))
[ par (⇝-↓ₚ {op = op}) ⇝-refl ]↝
↑ op (∪ₒ-inr op p) V (↓ op V P ∥ Q)
-- INTERRUPT PROPAGATION RULES
↓-run : {X : VType}
{o : O}
{i : I}
{op : Σₛ} →
(V : Γ ⊢V⦂ `` (payload op)) →
(M : Γ ⊢M⦂ X ! (o , i)) →
-----------------------------
↓ op V (run M)
[ id ]↝
run (↓ op V M)
↓-∥ : {o o' : O}
{PP : PType o}
{QQ : PType o'}
{op : Σₛ}
(V : Γ ⊢V⦂ `` (payload op)) →
(P : Γ ⊢P⦂ PP) →
(Q : Γ ⊢P⦂ QQ) →
-----------------------------
↓ op V (P ∥ Q)
[ ⇝-refl ]↝
((↓ op V P) ∥ (↓ op V Q))
↓-↑ : {o : O}
{PP : PType o}
{op : Σₛ}
{op' : Σₛ} →
(p : op' ∈ₒ o) →
(V : Γ ⊢V⦂ ``(payload op)) →
(W : Γ ⊢V⦂ ``(payload op')) →
(P : Γ ⊢P⦂ PP) →
-----------------------------------
↓ op V (↑ op' p W P)
[ ⇝-refl ]↝
↑ op' (↓ₚₚ-⊑ₒ PP op' p) W (↓ op V P)
-- SIGNAL HOISTING RULE
↑ : {X : VType}
{o : O}
{i : I} →
{op : Σₛ} →
(p : op ∈ₒ o) →
(V : Γ ⊢V⦂ `` (payload op)) →
(M : Γ ⊢M⦂ X ! (o , i)) →
-----------------------------
run (↑ op p V M)
[ id ]↝
↑ op p V (run M)
-- EVALUATION CONTEXT RULE
context : {o o' : O}
{PP : PType o}
{QQ : PType o'}
(F : Γ ⊢F⦂ PP) →
{P : Γ ⊢P⦂ proj₂ (hole-ty-f F)}
{Q : Γ ⊢P⦂ QQ}
{r : proj₂ (hole-ty-f F) ⇝ QQ} →
P [ r ]↝ Q →
-----------------------------------------------------------------------------
F [ P ]f
[ proj₂ (proj₂ (⇝-f-⇝ F r)) ]↝
(⇝-f F r) [ subst-i PType (λ o QQ → Γ ⊢P⦂ QQ) (⇝-f-tyₒ F r) (⇝-f-ty F r) Q ]f
| {
"alphanum_fraction": 0.3299496946,
"avg_line_length": 24.6829268293,
"ext": "agda",
"hexsha": "3fa97512ec559f42d4b2f28624a2cbf8c1f157d1",
"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": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danelahman/aeff-agda",
"max_forks_repo_path": "ProcessPreservation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"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": "danelahman/aeff-agda",
"max_issues_repo_path": "ProcessPreservation.agda",
"max_line_length": 109,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danelahman/aeff-agda",
"max_stars_repo_path": "ProcessPreservation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T22:48:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-17T00:15:00.000Z",
"num_tokens": 5000,
"size": 11132
} |
{-# OPTIONS --without-K #-}
module TheSame where
open import Level using (_⊔_) renaming (zero to l0; suc to lsuc)
open import Universe using (Universe)
open import Categories.Category using (Category)
open import Categories.Groupoid using (Groupoid)
open import Categories.Functor using (Functor)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum hiding ([_,_])
open import Data.Product
open import Relation.Binary.PropositionalEquality as P
open import Function using (flip)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Integer using (+_)
open import Categories.Groupoid.Sum using () renaming (Sum to GSum)
open import Categories.Groupoid.Product using () renaming (Product to GProduct)
open import PiU using (U; ZERO; ONE; PLUS; TIMES; toℕ)
open import PiLevel0
open import PiLevel1
open import PiEquiv
open import Equiv
open import PiIter
-- our values come in three flavours, base, up and down (i.e. #p and 1/# p)
data Flavour : Set where
base up down : Flavour
-- all our values will be 'subtypes' of this:
record V (fl : Flavour) (t₀ t₁ : U) (p : t₁ ⟷ t₁) : Set where
constructor v
field
pt : ⟦ t₀ ⟧
auto : Iter p
-- we need t₀ and t₁ to potentially be different to embed
-- #p and 1/#p. The values of these are the same, but
-- the homomorphisms will be different, and thus how to count them.
-- We can embed our (current) values into V easily:
embedBase : {t : U} → ⟦ t ⟧ → V base t ONE id⟷
embedBase w = v w (iter (+ 0) id⟷ id⇔)
embed#p : {t : U} → {p : t ⟷ t} → Iter p → V up ONE t p
embed#p it = v tt it
embed1/#p : {t : U} → {p : t ⟷ t} → Iter p → V down ONE t p
embed1/#p it = v tt it
-- We can then define combinators on V as two actions, one on each part
record C (s₀ s₁ t₀ t₁ : U) : Set where
constructor cc
field
comb : s₀ ⟷ t₀
transp : s₁ ⟷ t₁
-- evaluation is then straightforward, just follow the types:
evalV : {s₀ s₁ t₀ t₁ : U} {fl : Flavour} {p₀ : s₁ ⟷ s₁} →
(c : C s₀ s₁ t₀ t₁) → (val : V fl s₀ s₁ p₀) →
V fl t₀ t₁ (! (C.transp c) ◎ p₀ ◎ (C.transp c))
evalV {p₀ = p} (cc comb transp) (v pt (iter i q α)) =
v (eval comb pt) (iter i (! transp ◎ (q ◎ transp)) {!!}) --
-- we should go backwards too
evalVB : {s₀ s₁ t₀ t₁ : U} {fl : Flavour} {p₁ : t₁ ⟷ t₁} →
(c : C s₀ s₁ t₀ t₁) → (val : V fl t₀ t₁ p₁) →
V fl s₀ s₁ ((C.transp c) ◎ p₁ ◎ ! (C.transp c))
evalVB (cc comb transp) (v pt (iter i q α)) =
v (evalB comb pt) (iter (+ 1) (transp ◎ (q ◎ ! transp)) {!!})
-- Next comes the (generic) type of morphisms. Note that this type is
-- 'too big', in practice we use particular sub-types.
record H {s₀ s₁ t₀ t₁ : U} {fl : Flavour} {p : s₁ ⟷ s₁} {q : t₁ ⟷ t₁}
(a : V fl s₀ s₁ p) (b : V fl t₀ t₁ q) : Set where
constructor mor
open V
field
combi : C s₀ s₁ t₀ t₁
vb = evalV combi a
field
pt-eq : pt vb P.≡ pt b
t-eq : Iter.p' (auto vb) ⇔ Iter.p' (auto b)
-- should p transport to ⇔ q ?
-- The above gives, implicitly, a notion of equality, which can
-- be extracted as below. Note how we insist on the types being
-- the same. This is basically the same as H when combi is id⟷ id⟷
record _≡V_ {s₀ s₁ : U} {fl : Flavour} {p q : s₁ ⟷ s₁}
(a : V fl s₀ s₁ p) (b : V fl s₀ s₁ q) : Set where
constructor veq
open V
field
pt-eq : pt a P.≡ pt b
t-eq : Iter.p' (auto a) ⇔ Iter.p' (auto b)
p⇔q : p ⇔ q
-- And now we can say what back-and-forth do:
evBF : {s₀ s₁ t₀ t₁ : U} {fl : Flavour} {p₀ : s₁ ⟷ s₁} →
(c : C s₀ s₁ t₀ t₁) → (val : V fl s₀ s₁ p₀) →
evalVB c (evalV c val) ≡V val
evBF (cc comb transp) (v pt (iter i p' α)) =
veq (P.trans (lemma1 comb (eval comb pt)) (
P.trans (P.cong (proj₁ (sym≃ (c2equiv comb))) (lemma0 comb pt))
(isqinv.β (proj₂ (c2equiv comb)) pt)))
{!!} {!!}
-- and Homs. Note how the range of this is quite restricted
embedBaseHom : {τ : U} → (s t : ⟦ τ ⟧) → s ≡ t → H (embedBase s) (embedBase t)
embedBaseHom s .s P.refl = mor (cc id⟷ id⟷) P.refl (trans⇔ idl◎l idr◎l )
-- for #p. The only Homs are when p ^ i ⇔ p ^ j
embed#pHom : {τ : U} → {p : τ ⟷ τ} → (v₀ v₁ : Iter p) → (Iter.p' v₀) ⇔ (Iter.p' v₁) →
H (embed#p v₀) (embed#p v₁)
embed#pHom {_} {p} (iter i q α) (iter j r β) iso = mor (cc id⟷ p) P.refl (
trans⇔ (id⇔ ⊡ (α ⊡ id⇔)) (trans⇔ (trans⇔ (id⇔ ⊡ (2! (assoc1g i)))
(trans⇔ assoc◎l (trans⇔ (rinv◎l ⊡ (2! α)) idl◎l))) iso))
-- for 1/#p; a bit lazy here, q should be Iter p, but the core of the
-- idea remains the same.
embed1/#pHom : {τ : U} → (p : τ ⟷ τ) → (q : Iter p) →
H (embed1/#p q) (embed1/#p q)
embed1/#pHom p (iter i q α) = mor (cc id⟷ p) P.refl (trans⇔
(id⇔ ⊡ (α ⊡ id⇔)) (trans⇔ (id⇔ ⊡ 2! (assoc1g i)) (trans⇔
assoc◎l (trans⇔ (rinv◎l ⊡ id⇔) (trans⇔ idl◎l (2! α))))))
-- infix 40 _⇿_
infixl 50 ↑_
-- let's make the relationship much clearer
data U↑ : Set where
↑_ : U → U↑
-- we need to do a more complicated lift of 1
𝟙 : {t : U} → (p : t ⟷ t) → U↑
#p : {t : U} → (p : t ⟷ t) → U↑
1/#p : {t : U} → (p : t ⟷ t) → U↑
-- This corresponds exactly to Obj (proj₁ ⟦ t ⟧ ) from 2D/Frac.agda
⟦_⟧↑ : U↑ → Set
⟦ ↑ x ⟧↑ = ⟦ x ⟧
⟦ 𝟙 p ⟧↑ = {!!}
⟦ #p p ⟧↑ = Iter p
⟦ 1/#p p ⟧↑ = ⊤
flavour : U↑ → Flavour
flavour (↑ _) = base
flavour (𝟙 p) = {!!}
flavour (#p _) = up
flavour (1/#p _) = down
t₀↑ : U↑ → U
t₀↑ (↑ t) = t
t₀↑ (𝟙 p) = {!!}
t₀↑ (#p p) = ONE
t₀↑ (1/#p p) = ONE
t₁↑ : U↑ → U
t₁↑ (↑ t) = ONE
t₁↑ (𝟙 p) = {!!}
t₁↑ (#p {t} _) = t
t₁↑ (1/#p {t} _) = t
auto↑ : (t : U↑) → (t₁↑ t ⟷ t₁↑ t)
auto↑ (↑ x) = id⟷
auto↑ (𝟙 p) = {!!}
auto↑ (#p p) = p
auto↑ (1/#p p) = id⟷
iter↑ : (t : U↑) → Iter (auto↑ t)
iter↑ (↑ x) = iter (+ 0) id⟷ id⇔
iter↑ (𝟙 p) = {!!}
iter↑ (#p p) = iter (+ 1) p idr◎r
iter↑ (1/#p p) = iter (+ 0) id⟷ id⇔
⟦_⟧V : (t : U↑) → Set
⟦ t ⟧V = V (flavour t) (t₀↑ t) (t₁↑ t) (auto↑ t)
fwd : {t : U↑} → ⟦ t ⟧↑ → ⟦ t ⟧V
fwd {↑ x} val = embedBase val
fwd {𝟙 p} val = {!!}
fwd {#p p} val = embed#p val
fwd {1/#p p} tt = embed1/#p (iter (+ 0) id⟷ id⇔)
bwd : {t : U↑} → ⟦ t ⟧V → ⟦ t ⟧↑
bwd {↑ x} val = V.pt val
bwd {𝟙 p} val = {!!}
bwd {#p p} val = V.auto val
bwd {1/#p p} val = tt
-- (This should be packed up to use ≡V)
fwdbwd≈id : {t : U↑} → (x : ⟦ t ⟧V) → V.pt (fwd {t} (bwd x)) P.≡ V.pt x
fwdbwd≈id {↑ x} (v pt auto) = P.refl
fwdbwd≈id {𝟙 p} (v pt auto) = {!!}
fwdbwd≈id {#p p} (v tt auto) = P.refl
fwdbwd≈id {1/#p p} (v tt auto) = P.refl
fb-auto : {t : U↑} → (x : ⟦ t ⟧V) → Iter.p' (V.auto (fwd {t} (bwd x))) ⇔ Iter.p' (V.auto x)
fb-auto {↑ x} (v pt (iter i p' α)) = 2! (trans⇔ α (id^i≡id i))
fb-auto {𝟙 p} vv = {!!}
fb-auto {#p p} (v pt (iter i p' α)) = id⇔
fb-auto {1/#p p} (v pt (iter i p' α)) = 2! (trans⇔ α (id^i≡id i))
bf-x : {t : U↑} → (x : ⟦ t ⟧↑) → bwd (fwd {t} x) P.≡ x
bf-x {↑ x} x₁ = P.refl
bf-x {𝟙 p} x = {!!}
bf-x {#p p} x = P.refl
bf-x {1/#p p} tt = P.refl
{-
data _⇿_ : U↑ → U↑ → Set where
prim : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (↑ t₁ ⇿ ↑ t₂)
-}
| {
"alphanum_fraction": 0.5557661467,
"avg_line_length": 30.8963963964,
"ext": "agda",
"hexsha": "56e372fe1f7ea6cff7534d8f3dc89b24301924d5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/TheSame.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/TheSame.agda",
"max_line_length": 91,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/TheSame.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 3058,
"size": 6859
} |
open import Data.List
open import Data.Product
open import Relation.Unary hiding (_∈_)
open import Relation.Ternary.Separation
module Relation.Ternary.Separation.Monad.State where
open import Level hiding (Lift)
open import Function using (_∘_; case_of_)
open import Relation.Binary.PropositionalEquality using (refl; _≡_)
import Relation.Binary.HeterogeneousEquality as HEq
open import Relation.Unary.PredicateTransformer hiding (_⊔_; [_])
open import Relation.Ternary.Separation.Construct.List
open import Relation.Ternary.Separation.Construct.Product
open import Relation.Ternary.Separation.Construct.Market
open import Relation.Ternary.Separation.Morphisms
open import Relation.Ternary.Separation.Monad
open import Data.Unit
open import Data.Product
open import Data.List.Relation.Ternary.Interleaving.Propositional as I
open Monads
module _ {ℓ} {C : Set ℓ} {{r : RawSep C}} {u} {{s : IsUnitalSep r u}} where
open Morphism (market {A = C}) public
STATET : (M : Pt (Market C) ℓ) → (l r : Pred (C × C) ℓ) → Pt C ℓ
STATET M St St' P = (● St ─✴ M (J P ✴ ● St')) ∘ demand
StateT : (M : Pt (Market C) ℓ) → Pred (C × C) ℓ → Pt C ℓ
StateT M St = STATET M St St
open import Relation.Ternary.Separation.Monad.Identity
State : Pred (C × C) ℓ → Pt C ℓ
State St = STATET Identity.Id St St
module StateTransformer {ℓ}
{C : Set ℓ} {u}
{{r : RawSep C}}
{{s : IsUnitalSep r u}}
(M : Pt (Market C) ℓ)
{{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }}
{St : Pred (C × C) ℓ}
where
instance
state-monad : Monad ⊤ _ (λ _ _ → StateT M St)
app (Monad.return state-monad px) st σ₂ = return (inj px ×⟨ σ₂ ⟩ st )
app (app (Monad.bind state-monad {P = P} {Q = Q} f) m σ₁) st@(lift _ _) σ₂@(offerᵣ σ₅) with ⊎-assoc (demand σ₁) σ₂
... | _ , σ₃ , σ₄ = app (bind bound) (app m st σ₄) σ₃
where
bound : ((J P ✴ ● St) ─✴ M (J Q ✴ ● St)) (demand _)
app bound (inj px ×⟨ offerᵣ σ₅ ⟩ st') (offerᵣ σ₆) with ⊎-unassoc σ₅ σ₆
... | _ , τ₁ , τ₂ = let mq = app f px (⊎-comm τ₁) in app mq st' (offerᵣ τ₂)
{- Lift an M computation into a transformed state operation -}
liftM : ∀ {Φ P} → M P (demand Φ) → StateT M St (P ∘ demand) Φ
app (liftM mp) (lift μ k) σ@(offerᵣ _) =
app (mapM′ (wand λ where px σ@(offerₗ _) → inj px ×⟨ ⊎-comm σ ⟩ (lift μ k))) mp (⊎-comm σ)
{- Lift a state computation into a transformed state operation -}
liftState : ∀ {P} → ∀[ State St P ⇒ StateT M St P ]
app (liftState mp) st σ = Monad.return monad (app mp st σ)
module StateWithErr {ℓ}
{C : Set ℓ} {u}
{{r : RawSep C}}
{{s : IsUnitalSep r u}}
(Exc : Set ℓ) where
open import Relation.Ternary.Separation.Monad.Error
open ExceptMonad {A = Market C} Exc public
open StateTransformer {C = C} (Except Exc) {{ monad = except-monad }} public
open import Data.Sum
State? : ∀ (S : Pred (C × C) ℓ) → Pt C ℓ
State? = StateT (Except Exc)
_orElse_ : ∀ {S P} {M : Pt (Market C) ℓ} {{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }}
→ ∀[ State? S P ⇒ (⋂[ _ ∶ Exc ] StateT M S P) ⇒ StateT M S P ]
app (mp orElse mq) μ σ with app mp μ σ
... | error e = app (mq e) μ σ
... | ✓ px = return px
try : ∀ {S P} → ε[ State? S P ] → ε[ State S (Emp ∪ P) ]
app (try mp?) st σ with app mp? st σ
... | error e = inj (inj₁ empty) ×⟨ σ ⟩ st
... | ✓ (inj px ×⟨ σ' ⟩ st') = inj (inj₂ px) ×⟨ σ' ⟩ st'
raise : ∀ {S P} → Exc → ∀[ State? S P ]
app (raise {P} e) μ σ = partial (inj₁ e)
| {
"alphanum_fraction": 0.6130057803,
"avg_line_length": 36.0416666667,
"ext": "agda",
"hexsha": "eeaeaeed1b3b6aa108cbd4bf2711ec2f1112e874",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Relation/Ternary/Separation/Monad/State.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"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": "laMudri/linear.agda",
"max_issues_repo_path": "src/Relation/Ternary/Separation/Monad/State.agda",
"max_line_length": 118,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Relation/Ternary/Separation/Monad/State.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 1276,
"size": 3460
} |
module Formalization.Monoid where
import Lvl
open import Numeral.Finite using (𝕟)
open import Numeral.Natural using (ℕ)
open import Type
open import Type.Dependent
open import Syntax.Function
private variable ℓ ℓₑ : Lvl.Level
private variable T : Type{ℓ}
private variable n n₁ n₂ : ℕ
module Semigroup where
-- A term in the language of a semigroup.
-- It consists of a finite number of variables and a binary operator on its elements.
data Term (n : ℕ) : Type{Lvl.𝟎} where
var : 𝕟(n) → Term(n)
_▫_ : Term(n) → Term(n) → Term(n)
module Monoid where
open import Data.List
open import Data.List.Functions
-- A term in the language of a monoid.
-- It consists of a finite number of variables, an identity element, and a binary operator on its elements.
data Term (n : ℕ) : Type{Lvl.𝟎} where
var : 𝕟(n) → Term(n)
_▫_ : Term(n) → Term(n) → Term(n)
id : Term(n)
-- A fully normalised term in the language of a monoid is always able to be represented as a list of variables.
-- See `normalize` for how a term is represented as a list.
NormalForm : ℕ → Type
NormalForm(n) = List(𝕟(n))
-- Normalizes a term to its normal form.
normalize : Term(n) → NormalForm(n)
normalize (var v) = singleton v
normalize (x ▫ y) = normalize x ++ normalize y
normalize id = ∅
open import Structure.Function
open import Structure.Function.Multi
open import Structure.Operator
open import Structure.Operator.Monoid
open import Structure.Operator.Properties
open import Structure.Relator.Properties
open import Structure.Setoid
open import Syntax.Transitivity
module Semantics ⦃ equiv : Equiv{ℓₑ}(T) ⦄ (_∙_ : T → T → T) ⦃ monoid : Monoid(_∙_) ⦄ where
open Structure.Operator.Monoid.Monoid(monoid) using () renaming (id to 𝑒)
-- The environment for evaluating an expression is just a mapping from its variables to the values.
Env : ℕ → Type
Env(n) = (𝕟(n) → T)
-- The semantics of the terms.
eval : Env(n) → Term(n) → T
eval env (var n) = env n
eval env (x ▫ y) = eval env x ∙ eval env y
eval env id = 𝑒
-- The semantics of the normal form.
evalNormal : Env(n) → NormalForm(n) → T
evalNormal env ∅ = 𝑒
evalNormal env (v ⊰ l) = env v ∙ evalNormal env l
module Proofs where
private variable env : Env(n)
private variable e : Term(n)
instance
eval-preserves : Preserving₂(eval env)(_▫_)(_∙_)
eval-preserves = intro(reflexivity(_≡_))
instance
evalNormal-preserves : Preserving₂(evalNormal env)(_++_)(_∙_)
evalNormal-preserves {env = env} = intro(\{x y} → proof{x}{y}) where
proof : Names.Preserving₂(evalNormal env)(_++_)(_∙_)
proof {∅} {ys} = symmetry(_≡_) (identityₗ(_∙_)(𝑒))
proof {x ⊰ xs} {ys} =
evalNormal env ((x ⊰ xs) ++ ys) 🝖[ _≡_ ]-[]
evalNormal env (x ⊰ (xs ++ ys)) 🝖[ _≡_ ]-[]
env x ∙ evalNormal env (xs ++ ys) 🝖[ _≡_ ]-[ congruence₂ᵣ(_∙_)(_) (proof {xs}{ys}) ]
env x ∙ (evalNormal env xs ∙ evalNormal env ys) 🝖[ _≡_ ]-[ associativity(_∙_) ]-sym
(env x ∙ evalNormal env xs) ∙ evalNormal env ys 🝖[ _≡_ ]-[]
evalNormal env (x ⊰ xs) ∙ evalNormal env ys 🝖-end
normalize-eval-correctness : (evalNormal env (normalize e) ≡ eval env e)
normalize-eval-correctness {env = env} {var v} = identityᵣ(_∙_)(𝑒)
normalize-eval-correctness {env = env} {x ▫ y} =
evalNormal env (normalize (x ▫ y)) 🝖[ _≡_ ]-[]
evalNormal env (normalize x ++ normalize y) 🝖[ _≡_ ]-[ preserving₂(evalNormal env)(_++_)(_∙_) {normalize x}{normalize y} ]
evalNormal env (normalize x) ∙ evalNormal env (normalize y) 🝖[ _≡_ ]-[ congruence₂(_∙_) (normalize-eval-correctness{env = env}{x}) (normalize-eval-correctness{env = env}{y}) ]
eval env x ∙ eval env y 🝖[ _≡_ ]-[]
eval env (x ▫ y) 🝖-end
normalize-eval-correctness {env = env} {id} = reflexivity(_≡_)
module CommutativeMonoid where
module CommutativeRig where
open import Data.ListSized
open import Formalization.Polynomial as Polynomial using (Polynomial)
-- A term in the language of a commutative rig.
-- It consists of a finite number of variables and a binary operator on its elements.
data Term (n : ℕ) : Type{Lvl.𝟎} where
var : 𝕟(n) → Term(n)
_➕_ : Term(n) → Term(n) → Term(n)
_✖_ : Term(n) → Term(n) → Term(n)
𝟎 : Term(n)
𝟏 : Term(n)
NormalForm : ℕ → Type
NormalForm = Polynomial
{-
normalize : Term(n) → NormalForm(n)
normalize (var x) = {!!}
normalize (t ➕ t₁) = {!!}
normalize (t ✖ t₁) = {!!}
normalize 𝟎 = {!!}
normalize 𝟏 = {!!}
-}
| {
"alphanum_fraction": 0.6049866062,
"avg_line_length": 38.2125984252,
"ext": "agda",
"hexsha": "2a8ec93bc8b2b816e3bb242519b8653d94a18c7e",
"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": "Formalization/Monoid.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": "Formalization/Monoid.agda",
"max_line_length": 183,
"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": "Formalization/Monoid.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": 1521,
"size": 4853
} |
module Issue452 where
data Bool : Set where
true false : Bool
data ⊥ : Set where
record ⊤ : Set where
constructor tt
abstract
id : Bool → Bool
id b = b
If_then_else_ : Bool → Set → Set → Set
If true then t else f = t
If false then t else f = f
data D : (b : Bool) → If b then ⊤ else ⊥ → Set where
d : D (id true) _ -- this meta variable (type If (id true) ...) is unsolvable
foo : D true tt → ⊥
foo ()
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Rules/LHS/Unify.hs:402
{- Trying to unify
D true tt = D (id true) _
true = id true is postponed, but then tt is handled of type
If (id true)...
which is not a data or record type, causing the panic
Solution: do not postpone but fail, since in D : (b : Bool) -> X
X depends on b
-}
| {
"alphanum_fraction": 0.6507177033,
"avg_line_length": 19.4418604651,
"ext": "agda",
"hexsha": "d18d83f9402acd97a2e18779ef14fdcc756e13b3",
"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/Issue452.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/Issue452.agda",
"max_line_length": 80,
"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/Issue452.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": 258,
"size": 836
} |
module Delta (K : Set) \{\{bij : bij K Nat\}\} where
DL : (V : Set) \altRArr Set
DL V = List (Nat \altAnd V)
data DD (V : Set) : Set where
DD : DL V \altRArr DD V
delta
: \altFAll\{n m\} \altRArr n < m \altRArr Nat
delta n<m =
difference (n<m\altRArr1+n\ensuremath{\leq}m n<m) -- i.e. m - n - 1
-- lookup
_\altLAng_\altRAng
: \altFAll\{V\} \altRArr DD V \altRArr K \altRArr Maybe V
(DD dd) \altLAng k \altRAng =
lkup dd (toNat k)
where
lkup : \altFAll\{V\} \altRArr DL V \altRArr Nat \altRArr Maybe V
lkup [] n = None
lkup ((hn , ha) :: t) n
with <dec n hn
\fourChars{}... | Inl n<hn = None
\fourChars{}... | Inr (Inl refl) = Some ha
\fourChars{}... | Inr (Inr hn<n) = lkup t (delta hn<n)
-- insert/extend
_,,_
: \altFAll\{V\} \altRArr DD V \altRArr (K \altAnd V) \altRArr DD V
(DD dd) ,, (k , v) =
DD (ins dd (toNat k , v))
where
ins : \altFAll\{V\} \altRArr DL V \altRArr (Nat \altAnd V) \altRArr DL V
ins [] (n , v) = (n , v) :: []
ins ((hn , hv) :: t) (n , v)
with <dec n hn
\fourChars{}... | Inl n<hn =
(n , v) :: (delta n<hn , hv) :: t
\fourChars{}... | Inr (Inl refl) =
(n , v) :: t
\fourChars{}... | Inr (Inr hn<n) =
(hn , hv) :: ins t (delta hn<n , v)
destruct
: \altFAll\{V\} \altRArr DD V \altRArr Maybe ((K \altAnd V) \altAnd DD V)
destruct (DD []) = None
destruct (DD ((n , v) :: [])) =
Some ((fromNat n , v) , DD [])
destruct (DD ((n , v) :: (m , v') :: t)) =
Some ((fromNat n , v) , DD ((n + m + 1 , v') :: t))
| {
"alphanum_fraction": 0.5215968586,
"avg_line_length": 29.3846153846,
"ext": "agda",
"hexsha": "e142c7d96074e6f2cd0446f9a8045b686ca3a4d5",
"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": "1ae15eb2f3a3eac6d30ba55ebb1ed65bc15aa0a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nickcollins/dependent-dicts",
"max_forks_repo_path": "code/Delta.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "1ae15eb2f3a3eac6d30ba55ebb1ed65bc15aa0a6",
"max_issues_repo_issues_event_max_datetime": "2020-09-15T21:24:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-10T22:57:49.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nickcollins/dependent-dicts",
"max_issues_repo_path": "code/Delta.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1ae15eb2f3a3eac6d30ba55ebb1ed65bc15aa0a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nickcollins/dependent-dicts",
"max_stars_repo_path": "code/Delta.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 649,
"size": 1528
} |
{-# OPTIONS --prop --rewriting #-}
open import Calf.CostMonoid
module Calf.Types.BoundedFunction (costMonoid : CostMonoid) where
open CostMonoid costMonoid
open import Calf.Prelude
open import Calf.Metalanguage
open import Calf.Step costMonoid
open import Calf.Types.Bounded costMonoid
open import Level using (_⊔_)
open import Relation.Binary
open import Data.Product
bounded : (A : tp pos) → cmp cost → tp neg
bounded A n = Σ+- (U (F A)) λ u → IsBounded⁻ A u n
Ψ : (A : tp pos) → (B : val A → tp pos) → (val A → ℂ) → tp neg
Ψ A B p =
Σ+- (U(Π A (λ a → F (B a)))) λ f →
Π A λ a → IsBounded⁻ (B a) (f a) (p a)
dom : ∀ {ℓ} {a} {A : Set a} {B : Set a} → Rel B ℓ → Rel (A → B) (a ⊔ ℓ)
dom {A = A} r f1 f2 = ∀ (a : A) → r (f1 a) (f2 a)
Ψ/relax : ∀ A B {p p'} → dom _≤_ p p' →
(f : cmp (Ψ A B p)) →
cmp (Ψ A B p')
Ψ/relax A B h (func , prf) = func ,
λ a → bound/relax (λ _ → h a) (prf a)
| {
"alphanum_fraction": 0.5695931478,
"avg_line_length": 27.4705882353,
"ext": "agda",
"hexsha": "07965b66f9ddac2d8ac942dab979e7ecbe2bbccf",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Calf/Types/BoundedFunction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Calf/Types/BoundedFunction.agda",
"max_line_length": 71,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Calf/Types/BoundedFunction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 376,
"size": 934
} |
{-# OPTIONS --without-K --rewriting #-}
{-
Adapted from Ulrik's work in Lean (released under Apache License 2.0)
https://github.com/leanprover/lean/blob/master/hott/homotopy/cellcomplex.hlean
-}
open import HoTT renaming (pt to pt⊙)
open import homotopy.DisjointlyPointedSet
module cw.CW {i} where
open import cw.Attached public
{-
Naming convention: most of them have the "cw-" prefix
-}
-- skeleton
{-
Disadvantages of alternative definitions:
[Skeleton] as a data type: No η. ([Skeleton (S n)] does not expand.)
[Skeleton] as a recursive record type: No η.
[Skeleton] as a recursive fuction giving recursive Σ types:
the current Agda sees that [Skeleton 0] and [Skeleton (S n)]
have the same head symbol [Σ] and will not invert [Skeleton]
during unification.
The following is combines a recursive funcition and a non-recursive
record type which should strike a good balance.
-}
record AttachedSkeleton n (Skel : Type (lsucc i)) (Real : Skel → Type i)
: Type (lsucc i) where
constructor attached-skeleton
field
skel : Skel
cells : hSet i
attaching : Attaching (Real skel) (fst cells) (Sphere n)
Skeleton : ℕ → Type (lsucc i)
Realizer : {n : ℕ} → Skeleton n → Type i
Skeleton O = hSet i
Skeleton (S n) = AttachedSkeleton n (Skeleton n) Realizer
Realizer {n = O} A = fst A
Realizer {n = S n} (attached-skeleton _ _ α) = Attached α
⟦_⟧ = Realizer
-- Pointedness
-- this function is needed for pointedness
cw-head : ∀ {n : ℕ} → Skeleton n → Type i
cw-head {n = O} cells = fst cells
cw-head {n = S n} (attached-skeleton skel _ _) = cw-head skel
-- this function is needed for pointedness
incl^ : ∀ {n : ℕ} (skel : Skeleton n)
→ cw-head skel → ⟦ skel ⟧
incl^ {n = O} cells a = a
incl^ {n = S n} (attached-skeleton skel _ _) a = incl (incl^ skel a)
-- disjointly pointed skeletons
record ⊙Skeleton (n : ℕ) : Type (lsucc i) where
constructor ⊙skeleton
field
skel : Skeleton n
pt : cw-head skel
pt-dec : is-separable ⊙[ cw-head skel , pt ]
⊙Realizer : {n : ℕ} → ⊙Skeleton n → Ptd i
⊙Realizer (⊙skeleton skel pt _) = ⊙[ ⟦ skel ⟧ , incl^ skel pt ]
⊙⟦_⟧ = ⊙Realizer
-- Take a prefix of a skeleton
cw-init : ∀ {n} → Skeleton (S n) → Skeleton n
cw-init (attached-skeleton skel _ _) = skel
⊙cw-init : ∀ {n} → ⊙Skeleton (S n) → ⊙Skeleton n
⊙cw-init (⊙skeleton skel pt dec) = ⊙skeleton (cw-init skel) pt dec
cw-take : ∀ {m n : ℕ} (m≤n : m ≤ n) → Skeleton n → Skeleton m
cw-take (inl idp) skel = skel
cw-take (inr ltS) skel = cw-init skel
cw-take (inr (ltSR m<n)) skel = cw-take (inr m<n) (cw-init skel)
cw-init-take : ∀ {m n : ℕ} (Sm≤n : S m ≤ n) skel
→ cw-init (cw-take Sm≤n skel) == cw-take (≤-trans lteS Sm≤n) skel
cw-init-take (inl idp) skel = idp
cw-init-take (inr ltS) skel = idp
cw-init-take (inr (ltSR lt)) skel = cw-init-take (inr lt) (cw-init skel)
⊙cw-take : ∀ {m n : ℕ} (m≤n : m ≤ n) → ⊙Skeleton n → ⊙Skeleton m
⊙cw-take (inl idp) ⊙skel = ⊙skel
⊙cw-take (inr ltS) ⊙skel = ⊙cw-init ⊙skel
⊙cw-take (inr (ltSR m<n)) ⊙skel = ⊙cw-take (inr m<n) (⊙cw-init ⊙skel)
⊙cw-head : ∀ {n : ℕ} → ⊙Skeleton n → Ptd i
⊙cw-head (⊙skeleton skel pt _) = ⊙[ cw-head skel , pt ]
⊙cw-init-take : ∀ {m n : ℕ} (Sm≤n : S m ≤ n) ⊙skel
→ ⊙cw-init (⊙cw-take Sm≤n ⊙skel) == ⊙cw-take (≤-trans lteS Sm≤n) ⊙skel
⊙cw-init-take (inl idp) ⊙skel = idp
⊙cw-init-take (inr ltS) ⊙skel = idp
⊙cw-init-take (inr (ltSR lt)) ⊙skel = ⊙cw-init-take (inr lt) (⊙cw-init ⊙skel)
-- Access the [m]th cells
cells-last : ∀ {n : ℕ} → Skeleton n → Type i
cells-last {n = O} cells = fst cells
cells-last {n = S n} (attached-skeleton _ cells _) = fst cells
⊙cells-last : ∀ {n : ℕ} → ⊙Skeleton n → Type i
⊙cells-last (⊙skeleton skel _ _) = cells-last skel
cells-nth : ∀ {m n : ℕ} (m≤n : m ≤ n) → Skeleton n → Type i
cells-nth m≤n = cells-last ∘ cw-take m≤n
⊙cells-nth : ∀ {m n : ℕ} (m≤n : m ≤ n) → ⊙Skeleton n → Type i
⊙cells-nth m≤n = ⊙cells-last ∘ ⊙cw-take m≤n
-- Access the [m]th dimensional attaching map
Realizer₋₁ : ∀ {n : ℕ} → Skeleton (S n) → Type i
Realizer₋₁ = ⟦_⟧ ∘ cw-init
⟦_⟧₋₁ = Realizer₋₁
⊙Realizer₋₁ : ∀ {n : ℕ} → ⊙Skeleton (S n) → Ptd i
⊙Realizer₋₁ = ⊙⟦_⟧ ∘ ⊙cw-init
⊙⟦_⟧₋₁ = ⊙Realizer₋₁
attaching-last : ∀ {n : ℕ} (skel : Skeleton (S n))
→ cells-last skel → (Sphere n → ⟦ skel ⟧₋₁)
attaching-last (attached-skeleton _ _ attaching) = attaching
⊙attaching-last : ∀ {n : ℕ} (⊙skel : ⊙Skeleton (S n))
→ ⊙cells-last ⊙skel → (Sphere n → de⊙ ⊙⟦ ⊙skel ⟧₋₁)
⊙attaching-last = attaching-last ∘ ⊙Skeleton.skel
attaching-nth : ∀ {m n : ℕ} (Sm≤n : S m ≤ n) (skel : Skeleton n)
→ cells-nth Sm≤n skel → (Sphere m → ⟦ cw-take Sm≤n skel ⟧₋₁)
attaching-nth Sm≤n = attaching-last ∘ cw-take Sm≤n
⊙attaching-nth : ∀ {m n : ℕ} (Sm≤n : S m ≤ n) (⊙skel : ⊙Skeleton n)
→ ⊙cells-nth Sm≤n ⊙skel → Sphere m → de⊙ ⊙⟦ ⊙cw-take Sm≤n ⊙skel ⟧₋₁
⊙attaching-nth Sm≤n = ⊙attaching-last ∘ ⊙cw-take Sm≤n
-- Access the [m]th dimensional inclusion map
cw-incl-last : ∀ {n} (skel : Skeleton (S n))
→ (⟦ skel ⟧₋₁ → ⟦ skel ⟧)
cw-incl-last _ = incl
⊙cw-incl-last : ∀ {n} (⊙skel : ⊙Skeleton (S n))
→ (⊙⟦ ⊙skel ⟧₋₁ ⊙→ ⊙⟦ ⊙skel ⟧)
⊙cw-incl-last _ = incl , idp
cw-incl-nth : ∀ {m n : ℕ} (Sm≤n : S m ≤ n) (skel : Skeleton n)
→ ⟦ cw-take Sm≤n skel ⟧₋₁ → ⟦ cw-take Sm≤n skel ⟧
cw-incl-nth Sm≤n = cw-incl-last ∘ cw-take Sm≤n
⊙cw-incl-nth : ∀ {m n : ℕ} (Sm≤n : S m ≤ n) (⊙skel : ⊙Skeleton n)
→ (⊙⟦ ⊙cw-take Sm≤n ⊙skel ⟧₋₁ ⊙→ ⊙⟦ ⊙cw-take Sm≤n ⊙skel ⟧)
⊙cw-incl-nth Sm≤n = ⊙cw-incl-last ∘ ⊙cw-take Sm≤n
cw-incl-tail : ∀ {m n : ℕ} (m≤n : m ≤ n) (skel : Skeleton n)
→ (⟦ cw-take m≤n skel ⟧ → ⟦ skel ⟧)
cw-incl-tail (inl idp) skel = idf ⟦ skel ⟧
cw-incl-tail (inr ltS) skel = cw-incl-last skel
cw-incl-tail (inr (ltSR lt)) skel =
cw-incl-last skel ∘ cw-incl-tail (inr lt) (cw-init skel)
⊙cw-incl-tail : ∀ {m n : ℕ} (m≤n : m ≤ n) (⊙skel : ⊙Skeleton n)
→ (⊙⟦ ⊙cw-take m≤n ⊙skel ⟧ ⊙→ ⊙⟦ ⊙skel ⟧)
⊙cw-incl-tail (inl idp) ⊙skel = ⊙idf ⊙⟦ ⊙skel ⟧
⊙cw-incl-tail (inr ltS) ⊙skel = ⊙cw-incl-last ⊙skel
⊙cw-incl-tail (inr (ltSR lt)) ⊙skel =
⊙cw-incl-last ⊙skel ⊙∘ ⊙cw-incl-tail (inr lt) (⊙cw-init ⊙skel)
-- Extra conditions on CW complexes
-- 1. decidable equalities
has-cells-with-dec-eq : ∀ {n} → Skeleton n → Type i
has-cells-with-dec-eq {n = O} skel = has-dec-eq (cells-last skel)
has-cells-with-dec-eq {n = S n} skel =
has-cells-with-dec-eq (cw-init skel) × has-dec-eq (cells-last skel)
⊙has-cells-with-dec-eq : ∀ {n} → ⊙Skeleton n → Type i
⊙has-cells-with-dec-eq = has-cells-with-dec-eq ∘ ⊙Skeleton.skel
cells-last-has-dec-eq : ∀ {n} (skel : Skeleton n)
→ has-cells-with-dec-eq skel → has-dec-eq (cells-last skel)
cells-last-has-dec-eq {n = O} skel dec = dec
cells-last-has-dec-eq {n = S n} skel dec = snd dec
init-has-cells-with-dec-eq : ∀ {n} (skel : Skeleton (S n))
→ has-cells-with-dec-eq skel
→ has-cells-with-dec-eq (cw-init skel)
init-has-cells-with-dec-eq skel dec = fst dec
take-has-cells-with-dec-eq : ∀ {m n} (m≤n : m ≤ n) (skel : Skeleton n)
→ has-cells-with-dec-eq skel
→ has-cells-with-dec-eq (cw-take m≤n skel)
take-has-cells-with-dec-eq (inl idp) skel dec = dec
take-has-cells-with-dec-eq (inr ltS) skel dec = init-has-cells-with-dec-eq skel dec
take-has-cells-with-dec-eq (inr (ltSR lt)) skel dec
= take-has-cells-with-dec-eq (inr lt) (cw-init skel) (init-has-cells-with-dec-eq skel dec)
cells-nth-has-dec-eq : ∀ {m n} (m≤n : m ≤ n) (skel : Skeleton n)
→ has-cells-with-dec-eq skel → has-dec-eq (cells-nth m≤n skel)
cells-nth-has-dec-eq m≤n skel dec =
cells-last-has-dec-eq (cw-take m≤n skel)
(take-has-cells-with-dec-eq m≤n skel dec)
has-cells-with-dec-eq-is-prop : ∀ {n} {skel : Skeleton n}
→ is-prop (has-cells-with-dec-eq skel)
has-cells-with-dec-eq-is-prop {n = O} = has-dec-eq-is-prop
has-cells-with-dec-eq-is-prop {n = S n} =
×-level has-cells-with-dec-eq-is-prop has-dec-eq-is-prop
-- 2. choice
has-cells-with-choice : TLevel → {n : ℕ} → Skeleton n → (j : ULevel) → Type (lmax i (lsucc j))
has-cells-with-choice t {n = O} skel j = has-choice t (cells-last skel) j
has-cells-with-choice t {n = S n} skel j =
has-cells-with-choice t (cw-init skel) j × has-choice t (cells-last skel) j
⊙has-cells-with-choice : TLevel → {n : ℕ} → ⊙Skeleton n → (j : ULevel) → Type (lmax i (lsucc j))
⊙has-cells-with-choice t ⊙skel j = has-cells-with-choice t (⊙Skeleton.skel ⊙skel) j
⊙cells-last-has-choice : {t : TLevel} {n : ℕ} (⊙skel : ⊙Skeleton n) {j : ULevel}
→ ⊙has-cells-with-choice t ⊙skel j
→ has-choice t (⊙cells-last ⊙skel) j
⊙cells-last-has-choice {n = O} ⊙skel ac = ac
⊙cells-last-has-choice {n = S n} ⊙skel ac = snd ac
⊙init-has-cells-with-choice : {t : TLevel} {n : ℕ} (⊙skel : ⊙Skeleton (S n)) {j : ULevel}
→ ⊙has-cells-with-choice t ⊙skel j
→ ⊙has-cells-with-choice t (⊙cw-init ⊙skel) j
⊙init-has-cells-with-choice ⊙skel ac = fst ac
⊙take-has-cells-with-choice : {t : TLevel} {m n : ℕ} (m≤n : m ≤ n) (⊙skel : ⊙Skeleton n) {j : ULevel}
→ ⊙has-cells-with-choice t ⊙skel j
→ ⊙has-cells-with-choice t (⊙cw-take m≤n ⊙skel) j
⊙take-has-cells-with-choice (inl idp) ⊙skel ac = ac
⊙take-has-cells-with-choice (inr ltS) ⊙skel ac = ⊙init-has-cells-with-choice ⊙skel ac
⊙take-has-cells-with-choice (inr (ltSR lt)) ⊙skel ac
= ⊙take-has-cells-with-choice (inr lt) (⊙cw-init ⊙skel) (⊙init-has-cells-with-choice ⊙skel ac)
⊙cells-nth-has-choice : {t : TLevel} {m n : ℕ} (m≤n : m ≤ n) (⊙skel : ⊙Skeleton n) {j : ULevel}
→ ⊙has-cells-with-choice t ⊙skel j
→ has-choice t (⊙cells-nth m≤n ⊙skel) j
⊙cells-nth-has-choice m≤n ⊙skel ac = ⊙cells-last-has-choice (⊙cw-take m≤n ⊙skel)
(⊙take-has-cells-with-choice m≤n ⊙skel ac)
{-
The following are not needed.
-- Dimensional lifting
cw-lift₁ : ∀ {n : ℕ} → Skeleton n → Skeleton (S n)
cw-lift₁ skel = attached-skeleton skel
(Lift Empty , Lift-level Empty-is-set)
λ{(lift ()) _}
-- This slightly stretches the naming convension
-- to two skeletons being extensionally equal.
cw-lift₁-equiv : ∀ {n} (skel : Skeleton n)
→ ⟦ cw-lift₁ skel ⟧ ≃ ⟦ skel ⟧
cw-lift₁-equiv skel = equiv to incl to-incl incl-to
where
to : ⟦ cw-lift₁ skel ⟧ → ⟦ skel ⟧
to = Attached-rec (idf ⟦ skel ⟧) (λ{(lift ())}) (λ{(lift ()) _})
to-incl : ∀ x → to (incl x) == x
to-incl _ = idp
incl-to : ∀ x → incl (to x) == x
incl-to = Attached-elim (λ _ → idp) (λ{(lift ())}) (λ{(lift ()) _})
cw-lift : ∀ {n m : ℕ} → n < m → Skeleton n → Skeleton m
cw-lift ltS = cw-lift₁
cw-lift (ltSR lt) = cw-lift₁ ∘ cw-lift lt
-}
| {
"alphanum_fraction": 0.6189238618,
"avg_line_length": 35.7010309278,
"ext": "agda",
"hexsha": "002d630c0cd8ca1732e7ef2032796362d2116195",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/CW.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/CW.agda",
"max_line_length": 101,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/CW.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 4444,
"size": 10389
} |
module MLib.Finite where
open import MLib.Prelude
import MLib.Fin.Parts as P
import MLib.Fin.Parts.Simple as PS
open import MLib.Prelude.RelProps
open import Data.List.All as All using (All; []; _∷_) hiding (module All)
open import Data.List.Any as Any using (Any; here; there) hiding (module Any)
import Data.List.Membership.Setoid as Membership
import Data.List.Membership.Propositional as PropMembership
import Relation.Binary.Indexed as I
import Relation.Unary as U using (Decidable)
open LeftInverse using () renaming (_∘_ to _ⁱ∘_)
open FE using (_⇨_; cong)
open import Function.Related using () renaming (module EquationalReasoning to RelReasoning)
import Data.Product.Relation.SigmaPropositional as OverΣ
open Algebra using (IdempotentCommutativeMonoid)
--------------------------------------------------------------------------------
-- Main Definition
--------------------------------------------------------------------------------
record IsFiniteSetoid {c ℓ} (setoid : Setoid c ℓ) (N : ℕ) : Set (c ⊔ˡ ℓ) where
open Setoid setoid public
open Setoid setoid using () renaming (Carrier to A)
OntoFin : ℕ → Set _
OntoFin N = LeftInverse setoid (≡.setoid (Fin N))
field
ontoFin : OntoFin N
fromIx : Fin N → A
fromIx i = LeftInverse.from ontoFin ⟨$⟩ i
toIx : A → Fin N
toIx x = LeftInverse.to ontoFin ⟨$⟩ x
fromIx-toIx : ∀ x → fromIx (toIx x) ≈ x
fromIx-toIx = LeftInverse.left-inverse-of ontoFin
enumₜ : Table A N
enumₜ = tabulate fromIx
enumₗ : List A
enumₗ = Table.toList enumₜ
IsFiniteSet : ∀ {a} → Set a → ℕ → Set a
IsFiniteSet = IsFiniteSetoid ∘ ≡.setoid
record FiniteSet c ℓ : Set (sucˡ (c ⊔ˡ ℓ)) where
field
setoid : Setoid c ℓ
N : ℕ
isFiniteSetoid : IsFiniteSetoid setoid N
open IsFiniteSetoid isFiniteSetoid public
--------------------------------------------------------------------------------
-- Combinators
--------------------------------------------------------------------------------
-- An enumerable setoid is finite
module _ {c ℓ} (setoid : Setoid c ℓ) where
open Setoid setoid
open Membership setoid
Any-cong : ∀ {xs} → (∀ x → x ∈ xs) → Set _
Any-cong f = ∀ {x y} → x ≈ y → Any.index (f x) ≡ Any.index (f y)
private
from : ∀ xs → Fin (List.length xs) → Carrier
from List.[] ()
from (x List.∷ xs) Fin.zero = x
from (x List.∷ xs) (Fin.suc i) = from xs i
left-inverse-of : ∀ {xs} (f : ∀ x → x ∈ xs) x → from xs (Any.index (f x)) ≈ x
left-inverse-of f x = go (f x)
where
go : ∀ {xs} (p : x ∈ xs) → from xs (Any.index p) ≈ x
go (here px) = sym px
go (there p) = go p
enumerable-isFiniteSetoid : ∀ {xs} (f : ∀ x → x ∈ xs) → Any-cong f → IsFiniteSetoid setoid (List.length xs)
enumerable-isFiniteSetoid {xs} f f-cong = record
{ ontoFin = record
{ to = record
{ _⟨$⟩_ = Any.index ∘ f
; cong = f-cong
}
; from = ≡.→-to-⟶ (from xs)
; left-inverse-of = left-inverse-of f
}
}
-- As a special case of the previous theorem requiring fewer conditions, an
-- enumerable set is finite.
module _ {a} {A : Set a} where
open PropMembership
enumerable-isFiniteSet : (xs : List A) (f : ∀ x → x ∈ xs) → IsFiniteSet A (List.length xs)
enumerable-isFiniteSet _ f = enumerable-isFiniteSetoid (≡.setoid _) f (≡.cong (Any.index ∘ f))
-- Given a function with a left inverse from some 'A' to a finite set, 'A' must also be finite.
extendedIsFinite : ∀ {c ℓ c′ ℓ′} {S : Setoid c ℓ} (F : FiniteSet c′ ℓ′) → LeftInverse S (FiniteSet.setoid F) → IsFiniteSetoid S (FiniteSet.N F)
extendedIsFinite finiteSet ontoF = record
{ ontoFin = ontoFin ⁱ∘ ontoF
}
where
open FiniteSet finiteSet using (ontoFin)
extendFinite : ∀ {c ℓ c′ ℓ′} {S : Setoid c ℓ} (F : FiniteSet c′ ℓ′) → LeftInverse S (FiniteSet.setoid F) → FiniteSet c ℓ
extendFinite finiteSet ontoF = record
{ isFiniteSetoid = extendedIsFinite finiteSet ontoF
}
module _ {c ℓ c′ ℓ′} {S : Setoid c ℓ} (F : FiniteSet c′ ℓ′) where
extendedIsFinite′N : (¬ Setoid.Carrier S) ⊎ LeftInverse S (FiniteSet.setoid F) → ℕ
extendedIsFinite′N (inj₁ x) = 0
extendedIsFinite′N (inj₂ y) = FiniteSet.N F
extendedIsFinite′ : (inj : (¬ Setoid.Carrier S) ⊎ LeftInverse S (FiniteSet.setoid F)) → IsFiniteSetoid S (extendedIsFinite′N inj)
extendedIsFinite′ (inj₂ f) = extendedIsFinite F f
extendedIsFinite′ (inj₁ p) = record
{ ontoFin = record
{ to = record { _⟨$⟩_ = ⊥-elim ∘ p ; cong = λ {i} → ⊥-elim (p i) }
; from = ≡.→-to-⟶ λ ()
; left-inverse-of = ⊥-elim ∘ p
}
}
-- Given a family of finite sets, indexed by a finite set, the sum over the entire family is finite.
module _ {c} {A : Set c} {N} (isFiniteSet : IsFiniteSet A N) where
private
finiteSet : FiniteSet c c
finiteSet = record { isFiniteSetoid = isFiniteSet }
module F = FiniteSet finiteSet
Σᶠ : ∀ {p} → (A → Set p) → Set p
Σᶠ P = ∃ (P ∘ lookup F.enumₜ)
module _ {p ℓ} (finiteAt : A → FiniteSet p ℓ) where
private
module PW x = FiniteSet (finiteAt x)
open PW using () renaming (Carrier to P)
parts : P.Parts A PW.N
parts = record
{ numParts = N
; parts = F.enumₜ
}
open P.Parts parts hiding (parts)
Σ-isFiniteSetoid : IsFiniteSetoid (OverΣ.setoid PW.setoid) totalSize
Σ-isFiniteSetoid = record
{ ontoFin
= Inverse.left-inverse (Inverse.sym asParts)
ⁱ∘ intoCoords
ⁱ∘ Σ-↞′ {B-setoid = PW.setoid} F.ontoFin
}
where
P-setoidᶠ : Fin N → Setoid _ _
P-setoidᶠ i = record
{ Carrier = P (F.fromIx i)
; _≈_ = PW._≈_ _
; isEquivalence = record
{ refl = PW.refl _
; sym = PW.sym _
; trans = PW.trans _
}
}
ΣᶠP-setoid = OverΣ.setoid P-setoidᶠ
open Setoid ΣᶠP-setoid using ()
renaming (_≈_ to _≈ᶠ_)
to : Σᶠ P → Σ (Fin N) (Fin ∘ sizeAt)
to (_ , px) = _ , PW.toIx _ px
to-cong : ∀ {x y} → x ≈ᶠ y → to x ≡ to y
to-cong (≡.refl , q) = OverΣ.to-≡ (≡.refl , cong (LeftInverse.to (PW.ontoFin _)) q)
from : Σ (Fin N) (Fin ∘ sizeAt) → Σᶠ P
from (i , j) = _ , PW.fromIx _ j
left-inverse-of : ∀ x → from (to x) ≈ᶠ x
left-inverse-of (i , x) = ≡.refl , PW.fromIx-toIx _ _
intoCoords : LeftInverse ΣᶠP-setoid (≡.setoid (Σ (Fin N) (Fin ∘ sizeAt)))
intoCoords = record
{ to = record { _⟨$⟩_ = to ; cong = to-cong }
; from = ≡.→-to-⟶ from
; left-inverse-of = left-inverse-of
}
Σ-finiteSet : FiniteSet _ _
Σ-finiteSet = record { isFiniteSetoid = Σ-isFiniteSetoid }
module All′ {a} {A : Set a} where
module _ {p ℓ} (setoid : A → Setoid p ℓ) where
module P′ x = Setoid (setoid x)
module P′′ {x} = P′ x
open P′ using () renaming (Carrier to P)
open P′′ using (_≈_)
data PW : {xs : List A} → All P xs → All P xs → Set (p ⊔ˡ ℓ) where
[] : PW [] []
_∷_ : ∀ {x xs} {px py : P x} {apx apy : All P xs} → px ≈ py → PW apx apy → PW (px ∷ apx) (py ∷ apy)
PW-setoid : List A → Setoid _ _
Setoid.Carrier (PW-setoid xs) = All P xs
Setoid._≈_ (PW-setoid xs) = PW
IsEquivalence.refl (Setoid.isEquivalence (PW-setoid .[])) {[]} = []
IsEquivalence.refl (Setoid.isEquivalence (PW-setoid .(_ ∷ _))) {px ∷ ap} =
P′′.refl ∷ IsEquivalence.refl (Setoid.isEquivalence (PW-setoid _))
IsEquivalence.sym (Setoid.isEquivalence (PW-setoid .[])) [] = []
IsEquivalence.sym (Setoid.isEquivalence (PW-setoid .(_ ∷ _))) (p ∷ q) =
P′′.sym p ∷ IsEquivalence.sym (Setoid.isEquivalence (PW-setoid _)) q
IsEquivalence.trans (Setoid.isEquivalence (PW-setoid .[])) [] [] = []
IsEquivalence.trans (Setoid.isEquivalence (PW-setoid .(_ ∷ _))) (p ∷ q) (p′ ∷ q′) =
P′′.trans p p′ ∷ IsEquivalence.trans (Setoid.isEquivalence (PW-setoid _)) q q′
module _ {p} (P : A → Set p) where
PW-≡ : ∀ {xs} {apx apy : All P xs} → PW (≡.setoid ∘ P) apx apy → apx ≡ apy
PW-≡ [] = ≡.refl
PW-≡ (p ∷ q) = ≡.cong₂ _∷_ p (PW-≡ q)
-- module _ {c ℓ} (finiteSet : FiniteSet c ℓ) where
-- private
-- module A = FiniteSet finiteSet
-- open A using (_≈_) renaming (Carrier to A)
-- open IsFiniteSetoid
-- open LeftInverse
-- private
-- boolToFin : Bool → Fin 2
-- boolToFin false = Fin.zero
-- boolToFin true = Fin.suc Fin.zero
-- open Nat using (_^_; _+_; _*_)
-- _ℕ+_ : ∀ {n} (m : ℕ) → Fin n → Fin (m + n)
-- zero ℕ+ i = i
-- suc m ℕ+ i = Fin.suc (m ℕ+ i)
-- -- ℕ*-+ m "i" "k" = "i + m * k"
-- ℕ*-+′ : ∀ {n} (m : ℕ) → Fin m → Fin n → Fin (n * m)
-- ℕ*-+′ {zero} m i ()
-- ℕ*-+′ {suc n} m i Fin.zero = Fin.inject+ (n * m) i
-- ℕ*-+′ {suc n} m i (Fin.suc k) = m ℕ+ (ℕ*-+′ m i k)
-- -- ℕ*-+ m "i" "k" = "i + m * k"
-- ℕ*-+ : ∀ {n} m → Fin m → Fin n → Fin (m * n)
-- ℕ*-+ m i k = ≡.subst Fin (Nat.*-comm _ m) (ℕ*-+′ m i k)
-- from-n-ary : ∀ {n m} → Table (Fin n) m → Fin (n ^ m)
-- from-n-ary {m = zero} _ = Fin.zero -- an empty table represents an empty n-ary string
-- from-n-ary {n} {suc m} t = ℕ*-+ n (Table.lookup t Fin.zero) (from-n-ary (Table.tail t))
-- from-n-ary-cong : ∀ {n m} (t t′ : Table (Fin n) m) → t Table.≗ t′ → from-n-ary t ≡ from-n-ary t′
-- from-n-ary-cong {m = zero} t t′ eq = ≡.refl
-- from-n-ary-cong {n} {suc m} t t′ eq = ≡.cong₂ (ℕ*-+ n) (eq Fin.zero) (from-n-ary-cong (Table.tail t) (Table.tail t′) (eq ∘ Fin.suc))
-- -- div-rem m i = "i % m" , "i / m"
-- div-rem : ∀ {n} m → Fin (m * n) → Fin m × Fin n
-- div-rem zero ()
-- div-rem {zero} (suc m) i with ≡.subst Fin (Nat.*-zeroʳ m) i
-- div-rem {zero} (suc m) i | ()
-- div-rem {suc n} (suc m) Fin.zero = Fin.zero , Fin.zero
-- div-rem {suc n} (suc m) (Fin.suc i) = {!!}
-- to-n-ary : ∀ {n m} → Fin (n ^ m) → Table (Fin n) m
-- to-n-ary {m = zero} _ = tabulate λ ()
-- to-n-ary {n} {suc m} k =
-- let r , d = div-rem n k
-- ind = to-n-ary {n} {m} d
-- in tabulate λ
-- { Fin.zero → r
-- ; (Fin.suc i) → lookup ind i
-- }
-- boolF-isFiniteSetoid : IsFiniteSetoid (A.setoid ⇨ ≡.setoid Bool) (2 Nat.^ A.N)
-- _⟨$⟩_ (to (ontoFin boolF-isFiniteSetoid)) f =
-- let digits = Table.map (boolToFin ∘ (f ⟨$⟩_)) A.enumₜ
-- in from-n-ary digits
-- cong (to (ontoFin boolF-isFiniteSetoid)) {f} {f′} p =
-- let t = Table.map (boolToFin ∘ (f ⟨$⟩_)) A.enumₜ
-- in from-n-ary-cong t _ λ _ → ≡.cong boolToFin (p A.refl)
-- _⟨$⟩_ (_⟨$⟩_ (from (ontoFin boolF-isFiniteSetoid)) i) x = {!!}
-- cong (_⟨$⟩_ (from (ontoFin boolF-isFiniteSetoid)) i) = {!!}
-- cong (from (ontoFin boolF-isFiniteSetoid)) ≡.refl = {!≡.cong ?!}
-- left-inverse-of (ontoFin boolF-isFiniteSetoid) = {!!}
-- module _ {c₁ ℓ₁ c₂ ℓ₂} (A-finiteSet : FiniteSet c₁ ℓ₁) (B-finiteSet : FiniteSet c₂ ℓ₂) where
-- private
-- module A = FiniteSet A-finiteSet
-- module B = FiniteSet B-finiteSet
-- open A using (_≈_) renaming (Carrier to A)
-- open B using () renaming (Carrier to B; _≈_ to _≈′_)
-- open IsFiniteSetoid
-- open LeftInverse
-- function-isFiniteSetoid : IsFiniteSetoid (A.setoid ⇨ B.setoid) (B.N Nat.^ A.N)
-- _⟨$⟩_ (to (ontoFin function-isFiniteSetoid)) f = {!!}
-- cong (to (ontoFin function-isFiniteSetoid)) = {!!}
-- _⟨$⟩_ (from (ontoFin function-isFiniteSetoid)) i = {!!}
-- cong (from (ontoFin function-isFiniteSetoid)) = {!!}
-- left-inverse-of (ontoFin function-isFiniteSetoid) = {!!}
-- TODO: Prove dependent function spaces with finite domain and codomain are
-- finite sets, and recast as an instance of that.
module _ {a p ℓ} {A : Set a} (finiteAt : A → FiniteSet p ℓ) where
private
module PW x = FiniteSet (finiteAt x)
module PW′ {x} = PW x
open PW using () renaming (Carrier to P; N to boundAt)
open PW′ using (_≈_)
All≈ = All′.PW PW.setoid
All-setoid = All′.PW-setoid PW.setoid
open All′.PW PW.setoid
finiteAllSize : List A → ℕ
finiteAllSize = List.product ∘ List.map boundAt
All-isFiniteSetoid : (xs : List A) → IsFiniteSetoid (All-setoid xs) _
All-isFiniteSetoid _ = record
{ ontoFin = record
{ to = record { _⟨$⟩_ = to ; cong = to-cong }
; from = ≡.→-to-⟶ from
; left-inverse-of = left-inverse-of
}
}
where
to : ∀ {xs} → All P xs → Fin (finiteAllSize xs)
to [] = Fin.zero
to (_∷_ {x} {xs} px ap) = PS.fromParts (PW.toIx _ px , to ap)
to-cong : ∀ {xs}{apx apy : All P xs} → All≈ apx apy → to apx ≡ to apy
to-cong [] = ≡.refl
to-cong (p ∷ q) = ≡.cong₂ (curry PS.fromParts) (cong (LeftInverse.to PW′.ontoFin) p) (to-cong q)
from : ∀ {xs} → Fin (finiteAllSize xs) → All P xs
from {List.[]} _ = []
from {x List.∷ xs} i =
(PW.fromIx _ (proj₁ (PS.toParts i))) ∷
from {xs} (proj₂ (PS.toParts {boundAt x} i))
left-inverse-of : ∀ {xs} (ap : All P xs) → All≈ (from (to ap)) ap
left-inverse-of [] = Setoid.refl (All-setoid _)
left-inverse-of (px ∷ ap) rewrite Inverse.right-inverse-of PS.asParts (PW.toIx _ px , to ap) =
PW′.fromIx-toIx px ∷ left-inverse-of ap
All-finiteSet : List A → FiniteSet _ _
All-finiteSet xs = record { isFiniteSetoid = All-isFiniteSetoid xs }
1-Truncate : ∀ {c ℓ} (setoid : Setoid c ℓ) → Setoid _ _
1-Truncate setoid = record
{ Carrier = Carrier
; _≈_ = λ _ _ → ⊤
; isEquivalence = record { refl = _ ; sym = _ ; trans = _ }
}
where open Setoid setoid
module DecFinite {a p} {A : Set a} {P : A → Set p} (decP : U.Decidable P) where
P-setoid : A → Setoid _ _
P-setoid = 1-Truncate ∘ ≡.setoid ∘ P
P-size : A → ℕ
P-size x = if ⌊ decP x ⌋ then 1 else 0
P-isFinite : ∀ x → IsFiniteSetoid (P-setoid x) (P-size x)
P-isFinite x with decP x
P-isFinite x | yes p = record
{ ontoFin = record
{ to = record
{ _⟨$⟩_ = λ _ → Fin.zero ; cong = λ _ → ≡.refl }
; from = ≡.→-to-⟶ λ _ → p
; left-inverse-of = _
}
}
P-isFinite x | no ¬p = record
{ ontoFin = record
{ to = record { _⟨$⟩_ = ⊥-elim ∘ ¬p ; cong = λ {x} → ⊥-elim (¬p x) }
; from = ≡.→-to-⟶ λ ()
; left-inverse-of = _
}
}
Decidable-finite : A → FiniteSet p _
Decidable-finite x = record { isFiniteSetoid = P-isFinite x }
module _ {c} {A : Set c} {N} (isFiniteSet : IsFiniteSet A N) {p} {P : A → Set p} (decP : U.Decidable P) where
open IsFiniteSetoid isFiniteSet
subsetFinite : FiniteSet _ _
subsetFinite = Σ-finiteSet isFiniteSet (DecFinite.Decidable-finite decP)
subset-isFiniteSet : ∀ {a′} {A′ : Set a′} → LeftInverse (≡.setoid A′) (FiniteSet.setoid subsetFinite) → IsFiniteSet A′ _
subset-isFiniteSet = extendedIsFinite subsetFinite
| {
"alphanum_fraction": 0.5649790172,
"avg_line_length": 34.8443396226,
"ext": "agda",
"hexsha": "a66072515c35affe17acc503378ed562dc83308b",
"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/Finite.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/Finite.agda",
"max_line_length": 143,
"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/Finite.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5341,
"size": 14774
} |
open import Prelude
open import MJ.Classtable.Core
module MJ.LexicalScope c where
open import Data.List
open import Data.List.Membership.Propositional
open import MJ.Types
Ctx : Set
Ctx = List (Ty c)
Var : Ctx → Ty c → Set
Var Γ a = a ∈ Γ
_+local_ : Ctx → Ty c → Ctx
_+local_ Γ a = a ∷ Γ
| {
"alphanum_fraction": 0.7064846416,
"avg_line_length": 16.2777777778,
"ext": "agda",
"hexsha": "f137caaccb425cbcc67f3aa6bab14d942197f489",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/LexicalScope.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/LexicalScope.agda",
"max_line_length": 46,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/LexicalScope.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 96,
"size": 293
} |
{-# OPTIONS --no-qualified-instances #-}
module JVM.Printer.Printer {t} (T : Set t) where
open import Function using (_$_; _∘_)
open import Data.Unit
open import Data.Nat
open import Data.Nat.Show as Nat
open import Data.Product
open import Data.List as List
open import Data.List.Relation.Unary.All
open import Relation.Unary hiding (Empty)
open import Relation.Unary.PredicateTransformer using (Pt)
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax
open import JVM.Model T
open Disjoint using (bags; bags-isMonoid)
open import Relation.Ternary.Data.Bigstar
open import Relation.Ternary.Construct.Market intf-rel
open import Relation.Ternary.Monad.Identity as Id hiding (id-monad; id-functor)
open import Relation.Ternary.Monad.State intf-rel
open import JVM.Syntax.Labeling T public
open import JVM.Printer.Jasmin
Names : List T → Set _
Names = All (λ _ → ℕ)
LabelNames : Pred Intf _
LabelNames (u ⇅ d) = Names u × Names d
PState : Pred Intf _
PState = (λ _ → ℕ × List Stat) ∩ LabelNames
counter : ∀ {Φ} → PState Φ → ℕ
counter = proj₁ ∘ proj₁
Printer : Pt Intf _
Printer = StateT Id PState
open StateTransformer Id {{Id.id-strong}} {PState} public
open import Relation.Ternary.Construct.Bag.Properties
open import Level
module Envs where
open import Category.Monad
open import Category.Monad.State as S
Fresh : Set t → Set _
Fresh = S.State (Lift t ℕ)
open RawMonadState (StateMonadState (Lift t ℕ)) public
open import Relation.Ternary.Construct.List duplicate as L
open import Data.List.Relation.Binary.Permutation.Propositional
open import Data.List.Relation.Binary.Permutation.Propositional.Properties
fresh : Fresh (Lift _ ℕ)
fresh (lift n) = let n' = ℕ.suc n in lift n , lift n'
freshNames : ∀ xs → Fresh (Names xs)
freshNames [] = return []
freshNames (x ∷ xs) = do
lift n ← fresh
ns ← freshNames xs
return (n ∷ ns)
env-split-list : ∀ {xs ys zs} → Names xs → L.Split xs ys zs → Fresh (Names ys × Names zs)
env-split-list nxs [] = return ([] , [])
env-split-list nxs (consʳ σ) = do
lift n ← fresh
nys , nzs ← env-split-list nxs σ
return (n ∷ nys , n ∷ nzs)
env-split-list (nx ∷ nxs) (divide x σ) = do
nys , nzs ← env-split-list nxs σ
return (nx ∷ nys , nx ∷ nzs)
env-split-list (nx ∷ nxs) (consˡ σ) = do
nys , nzs ← env-split-list nxs σ
return (nys , nx ∷ nzs)
env-split-bag : ∀ {xs ys zs} → Names xs → Overlap.BagSplit xs ys zs → Fresh (Names ys × Names zs)
env-split-bag nxs (Overlap.hustle ρx ρy ρz σ) = do
let nxs' = All-resp-↭ (↭-sym ρx) nxs
(nys , nzs) ← env-split-list nxs' σ
return (All-resp-↭ ρy nys , All-resp-↭ ρz nzs)
splitEnv : ∀ {xs ys zs} → xs ∙ ys ≣ zs → LabelNames zs → Fresh (LabelNames xs × LabelNames ys)
splitEnv (ex (sub {e = e} x x₁) (sub {e = e'} x₄ x₅) σ↑ σ↓) (unv , dnv) = do
let nu₁' , nu₂' = splitAll (λ ()) σ↑ unv
let nd₁' , nd₂' = splitAll (λ dup px → px , px ) σ↓ dnv
nse , nu₂ ← env-split-bag nu₂' x₁
nse' , nu₁ ← env-split-bag nu₁' x₅
let nd₁ = joinAll (λ ()) x nd₂' nse
let nd₂ = joinAll (λ ()) x₄ nd₁' nse'
return ((nu₁ , nd₁) , (nu₂ , nd₂))
module _ where
open import Relation.Ternary.Monad
lookUp : ∀ {τ} → ∀[ Up (One τ) ⇒ Printer (Empty ℕ) ]
lookUp (↑ u) ⟨ supplyᵣ σ ⟩ lift ((n , st) , env) with Envs.splitEnv σ env (lift n)
... | ((lab ∷ [] , []) , env₂) , lift n' = lift (emp lab) ∙⟨ ∙-idˡ ⟩ lift ((n' , st) , env₂)
lookDown : ∀ {τ} → ∀[ Down (One τ) ⇒ Printer (Empty ℕ) ]
lookDown (↓ u) ⟨ supplyᵣ σ ⟩ lift ((n , st) , env) with Envs.splitEnv σ env (lift n)
... | (([] , lab ∷ []) , env₂) , lift n' = lift (emp lab) ∙⟨ ∙-idˡ ⟩ lift ((n' , st) , env₂)
print : Stat → ε[ Printer Emp ]
print s ⟨ σ ⟩ lift ((n , st) , env) = lift refl ∙⟨ σ ⟩ lift ((n , s ∷ st) , env)
print-label : ∀ {τ} → ∀[ Up (One τ) ⇒ Printer Emp ]
print-label l = do
emp n ← lookUp l
print (label (Nat.show n))
{-# TERMINATING #-}
print-labels' : ∀ {τ} → ∀[ Up (Bigstar (One τ)) ⇒ Printer Emp ]
print-labels' (↑ emp) = return refl
print-labels' (↑ (cons (x ∙⟨ σ ⟩ xs))) = do
xs ← ✴-id⁻ʳ ⟨$⟩ (print-label (↑ x) &⟨ ∙-comm $ liftUp σ ⟩ ↑ xs)
print-labels' xs
where open Disjoint using (bags; bags-isMonoid)
print-labels : ∀ {τ} → ∀[ Up (Labeling τ) ⇒ Printer Emp ]
print-labels (↑ (x ∙⟨ σ ⟩ xs)) = do
xs ← ✴-id⁻ʳ ⟨$⟩ (print-label (↑ x) &⟨ ∙-comm $ liftUp σ ⟩ ↑ xs)
print-labels' xs
-- give it a kick
execPrinter : ∀ {P Φ} → Printer P Φ → List Stat
execPrinter pr with pr ⟨ supplyᵣ ∙-idʳ ⟩ proj₁ (initState (lift 0))
where
open Envs
initState : ∀ {Φ} → Envs.Fresh (● PState (supply Φ))
initState {Φ↑ ⇅ Φ↓} = do
ns↑ ← freshNames Φ↑
ns↓ ← freshNames Φ↓
lift n ← get
return (lift ((n , []) , (ns↑ , ns↓)))
... | (lift px ∙⟨ σ ⟩ lift ((_ , st) , _)) = reverse st
| {
"alphanum_fraction": 0.614203072,
"avg_line_length": 33.42,
"ext": "agda",
"hexsha": "7a1b3868afded9834c68d2405467b034e337a3a9",
"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/Printer/Printer.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/Printer/Printer.agda",
"max_line_length": 99,
"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/Printer/Printer.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": 1770,
"size": 5013
} |
{-# OPTIONS --without-K -v 2 #-}
module Leftovers.Monad where
open import Category.Functor
open import Category.Applicative
open import Category.Monad
open import Level
open import Data.Unit
open import Data.List
import Reflection as TC
open import Reflection.TypeChecking.Monad.Instances
open import Reflection.Abstraction as Abstraction public
using (Abs; abs)
open import Reflection.Argument as Argument public
using (Arg; arg; Args; vArg; hArg; iArg)
open import Reflection.Definition as Definition public
using (Definition)
open import Reflection.Meta as Meta public
using (Meta)
open import Reflection.Name as Name public
using (Name; Names)
open import Reflection.Literal as Literal public
using (Literal)
open import Reflection.Pattern as Pattern public
using (Pattern)
open import Reflection.Term as Term public
using (Term; Type; Clause; Clauses; Sort)
open import Reflection using (ErrorPart ; strErr; termErr ; nameErr) public
open import Data.Bool
import Reflection.Argument.Relevance as Relevance
import Reflection.Argument.Visibility as Visibility
import Reflection.Argument.Information as Information
open Definition.Definition public
open Information.ArgInfo public
open Literal.Literal public
open Relevance.Relevance public
open Term.Term public
open Visibility.Visibility public
private
variable
ℓ : Level
A : Set ℓ
B : Set ℓ
record Hole : Set where
constructor mkHole
field
holeMeta : Meta
hole : Term
context : List (Arg Type)
import Relation.Binary.PropositionalEquality as Eq
import Relation.Binary.Definitions as D
open import Data.Empty using (⊥)
EquivHole : ∀ (x y : Hole) → Set
EquivHole (mkHole x _ _ ) (mkHole y _ _) = x Eq.≡ y
open import Relation.Nullary using (yes ; no)
equivDec : D.Decidable EquivHole
equivDec (mkHole x _ _) (mkHole y _ _) = x Meta.≟ y
where import Reflection.Meta as Meta
-- equivDec (mkHole (var x args) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (con c args) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (def f args) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (lam v t) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (pat-lam cs args) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (pi a b) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (Term.sort s) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (lit l) _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole unknown _) (mkHole y _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (var x₂ args) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (con c args) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (def f args) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (lam v t) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (pat-lam cs args) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (pi a b) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (Term.sort s) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole (lit l) _) = no (λ z → z)
-- equivDec (mkHole (meta x x₁) _) (mkHole unknown _) = no (λ z → z)
open import Category.Monad.State
open import Category.Monad.Indexed using (RawIMonad ; RawIMonadPlus)
open import Category.Applicative.Indexed using (RawIApplicative ; RawIAlternative)
open import Data.Product using (_×_ ; _,_)
Leftovers : Set ℓ → Set ℓ
Leftovers = StateT (Lift _ (List Hole)) TC.TC
leftoversMonad : RawMonad {f = ℓ} Leftovers
leftoversMonad = StateTMonad _ tcMonad
leftoversApplicative : RawApplicative {f = ℓ} Leftovers
leftoversApplicative = RawIMonad.rawIApplicative leftoversMonad
leftoversFunctor : RawFunctor {ℓ = ℓ} Leftovers
leftoversFunctor = RawIApplicative.rawFunctor leftoversApplicative
leftoversMonadZero : RawMonadZero {f = ℓ} Leftovers
leftoversMonadZero = StateTMonadZero _ tcMonadZero
leftoversMonadPlus : RawMonadPlus {f = ℓ} Leftovers
leftoversMonadPlus = StateTMonadPlus _ tcMonadPlus
private
-- Lift a TC operation into the Leftovers Monad
-- WARNING: this will *NOT* track metas declared in the TC operation
-- and should only be used for primitive operations
liftTC : TC.TC A → Leftovers A
liftTC comp s = TC.bindTC comp λ a → TC.return (a , s)
liftTCA1 : (B → TC.TC A) → B → Leftovers A
liftTCA1 comp x = liftTC (comp x)
liftTCA2 : ∀ {A B C : Set ℓ} → (C → B → TC.TC A) → C → B → Leftovers A
liftTCA2 comp x y = liftTC (comp x y)
------------------------------------------------------------------------
-- Monad syntax
returnLeftovers : A → Leftovers A
returnLeftovers = RawMonad.return leftoversMonad
bindLeftovers : ∀ {A B : Set ℓ } -> Leftovers A → (A → Leftovers B) → Leftovers B
bindLeftovers a f = RawMonad._=<<_ leftoversMonad f a
pure : A → Leftovers A
pure = returnLeftovers
{-# INLINE pure #-}
infixl 3 _<|>_
_<|>_ : Leftovers A → Leftovers A → Leftovers A
_<|>_ = RawIAlternative._∣_ (RawIMonadPlus.alternative leftoversMonadPlus)
{-# INLINE _<|>_ #-}
infixl 1 _>>=_ _>>_ _<&>_
_>>=_ : ∀ {A B : Set ℓ} → Leftovers A → (A → Leftovers B) → Leftovers B
_>>=_ = bindLeftovers
{-# INLINE _>>=_ #-}
_>>_ : ∀ {A B : Set ℓ} → Leftovers A → Leftovers B → Leftovers B
xs >> ys = bindLeftovers xs (λ _ → ys)
{-# INLINE _>>_ #-}
infixl 4 _<$>_ _<*>_ _<$_
_<*>_ : ∀ {A B : Set ℓ} → Leftovers (A → B) → Leftovers A → Leftovers B
fs <*> xs = bindLeftovers fs (λ f → bindLeftovers xs (λ x → returnLeftovers (f x)))
{-# INLINE _<*>_ #-}
_<$>_ : ∀ {A B : Set ℓ} →(A → B) → Leftovers A → Leftovers B
f <$> xs = bindLeftovers xs (λ x → returnLeftovers (f x))
{-# INLINE _<$>_ #-}
_<$_ : ∀ {A B : Set ℓ} →A → Leftovers B → Leftovers A
x <$ xs = bindLeftovers xs (λ _ → returnLeftovers x)
{-# INLINE _<$_ #-}
_<&>_ : ∀ {A B : Set ℓ} → Leftovers A → (A → B) → Leftovers B
xs <&> f = bindLeftovers xs (λ x → returnLeftovers (f x))
{-# INLINE _<&>_ #-}
logHole : Hole → Leftovers ⊤
logHole hole = do
RawMonadState.modify (StateTMonadState _ tcMonad) λ { (lift lst) → lift (hole ∷ lst)}
pure tt
-- logHole hole = RawMonadState.modify (StateTMonadState _ tcMonad)
-- (λ {lst → ?})
-- pure tt
freshMeta : Type → Leftovers Term
freshMeta t = do
theMeta ← liftTC (TC.newMeta t)
liftTC (TC.debugPrint "freshMeta" 2 (strErr "Fresh meta " ∷ termErr theMeta ∷ strErr " with type " ∷ termErr t ∷ []))
ctx ← liftTC TC.getContext
m ← liftTC (getMeta theMeta)
logHole (mkHole m theMeta ctx)
pure theMeta
where
getMeta : Term → TC.TC Meta
getMeta (meta m _ ) = TC.return m
getMeta t = (TC.typeError (strErr "Foo" ∷ []))
open import Data.String
-- Re-export all of the TC functions
unify : Term → Term → Leftovers ⊤
unify = liftTCA2 TC.unify
typeError : ∀ {A : Set ℓ} → List TC.ErrorPart → Leftovers A
typeError x = liftTC (TC.typeError x)
inferType : Term → Leftovers Type
inferType = liftTCA1 TC.inferType
checkType : Term → Type → Leftovers Term
checkType = liftTCA2 TC.checkType
normalise : Term → Leftovers Term
normalise = liftTCA1 TC.normalise
reduce : Term → Leftovers Term
reduce = liftTCA1 TC.reduce
catchLeftovers : ∀ {A : Set ℓ} → Leftovers A → Leftovers A → Leftovers A
catchLeftovers comp fallback s =
--We revert any state changes if we have to go to the fallback
TC.catchTC (comp s) (fallback s)
quoteLeftovers : ∀ {A : Set ℓ} → A → Leftovers Term
quoteLeftovers = liftTCA1 TC.quoteTC
unquoteLeftovers : ∀ {A : Set ℓ} → Term → Leftovers A
unquoteLeftovers = liftTCA1 TC.unquoteTC
getContext : Leftovers (List (Arg Type))
getContext = liftTC TC.getContext
extendContext : ∀ {A : Set ℓ} → Arg Type → Leftovers A → Leftovers A
extendContext x comp s = TC.extendContext x (comp s)
extendContexts : ∀ {A : Set ℓ} → List (Arg Type) → Leftovers A → Leftovers A
extendContexts [] x = x
extendContexts (h ∷ t) x = extendContext h (extendContexts t x)
inContext : ∀ {A : Set ℓ} → List (Arg Type) → Leftovers A → Leftovers A
inContext ctx comp s = TC.inContext ctx (comp s)
freshName : String → Leftovers Name
freshName = liftTCA1 TC.freshName
declareDef : Arg Name → Type → Leftovers ⊤
declareDef = liftTCA2 TC.declareDef
declarePostulate : Arg Name → Type → Leftovers ⊤
declarePostulate = liftTCA2 TC.declarePostulate
defineFun : Name → List Clause → Leftovers ⊤
defineFun = liftTCA2 TC.defineFun
getType : Name → Leftovers Type
getType = liftTCA1 TC.getType
getDefinition : Name → Leftovers Definition
getDefinition = liftTCA1 TC.getDefinition
blockOnMeta : ∀ {A : Set ℓ} → Meta → Leftovers A
blockOnMeta = liftTCA1 TC.blockOnMeta
--TODO: is there state stuff to do here?
commitLeftovers : Leftovers ⊤
commitLeftovers = liftTC TC.commitTC
isMacro : Name → Leftovers Bool
isMacro = liftTCA1 TC.isMacro
open import Data.Nat
-- If the argument is 'true' makes the following primitives also normalise
-- their results: inferType, checkType, quoteLeftovers, getType, and getContext
withNormalisation : ∀ {a} {A : Set a} → Bool → Leftovers A → Leftovers A
withNormalisation flag comp s = TC.withNormalisation flag (comp s)
-- Prints the third argument if the corresponding verbosity level is turned
-- on (with the -v flag to Agda).
debugPrint : String → ℕ → List TC.ErrorPart → Leftovers ⊤
debugPrint s n err = liftTC (TC.debugPrint s n err)
-- Fail if the given computation gives rise to new, unsolved
-- "blocking" constraints.
noConstraints : ∀ {a} {A : Set a} → Leftovers A → Leftovers A
noConstraints comp s = TC.noConstraints (comp s)
-- Run the given Leftovers action and return the first component. Resets to
-- the old Leftovers state if the second component is 'false', or keep the
-- new Leftovers state if it is 'true'.
runSpeculative : ∀ {a} {A : Set a} → Leftovers (A × Bool) → Leftovers A
runSpeculative comp oldState =
TC.bindTC
(TC.runSpeculative (TC.bindTC (comp oldState) λ{((a , flag) , midState) → TC.return (((a , flag) , midState) , flag)}))
λ {
-- Only keep state if the computation succeeds
((a , false) , newState) → TC.return ((a , oldState)) ;
((a , true) , newState) → TC.return (a , newState)}
runLeftovers : Leftovers A → TC.TC (A × List Hole)
runLeftovers comp = TC.bindTC (comp (lift []))
((λ { (a , lift holes) → TC.return (a , holes) }) )
| {
"alphanum_fraction": 0.6749588617,
"avg_line_length": 33.7614379085,
"ext": "agda",
"hexsha": "dba5c723a1974fe7b18dce8e7889f947ecfb631c",
"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": "01b60b405009feaada181af175f019ceb89e42b2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "JoeyEremondi/AgdaLeftovers",
"max_forks_repo_path": "src/Leftovers/Monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2",
"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": "JoeyEremondi/AgdaLeftovers",
"max_issues_repo_path": "src/Leftovers/Monad.agda",
"max_line_length": 123,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "JoeyEremondi/AgdaLeftovers",
"max_stars_repo_path": "src/Leftovers/Monad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3226,
"size": 10331
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Structures.Higher where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Univalence
open import Cubical.Functions.FunExtEquiv
open import Cubical.Homotopy.Base
open import Cubical.Homotopy.Connected
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Higher
open import Cubical.Algebra.Group.EilenbergMacLane1
open import Cubical.HITs.EilenbergMacLane1
open import Cubical.DStructures.Base
open import Cubical.DStructures.Meta.Properties
open import Cubical.DStructures.Meta.Isomorphism
open import Cubical.DStructures.Structures.Universe
open import Cubical.DStructures.Structures.Type
open import Cubical.DStructures.Structures.Group
open import Cubical.DStructures.Structures.Constant
private
variable
ℓ ℓ' : Level
𝒮ᴰ-connected : {ℓ : Level} (k : ℕ) → URGStrᴰ (𝒮-universe {ℓ}) (isConnected k) ℓ-zero
𝒮ᴰ-connected k =
Subtype→Sub-𝒮ᴰ (λ A → isConnected k A , isPropIsContr)
𝒮-universe
𝒮ᴰ-truncated : {ℓ : Level} (n : ℕ) → URGStrᴰ (𝒮-universe {ℓ}) (isOfHLevel n) ℓ-zero
𝒮ᴰ-truncated n =
Subtype→Sub-𝒮ᴰ (λ A → isOfHLevel n A , isPropIsOfHLevel n)
𝒮-universe
𝒮ᴰ-BGroup : (n k : ℕ)
→ URGStrᴰ (𝒮-universe {ℓ})
(λ A → A × (isConnected (k + 1) A) × (isOfHLevel (n + k + 2) A))
ℓ
𝒮ᴰ-BGroup n k =
combine-𝒮ᴰ 𝒮ᴰ-pointed
(combine-𝒮ᴰ (𝒮ᴰ-connected (k + 1))
(𝒮ᴰ-truncated (n + k + 2)))
𝒮-BGroup : (n k : ℕ) → URGStr (Σ[ A ∈ Type ℓ ] A × (isConnected (k + 1) A) × (isOfHLevel (n + k + 2) A)) ℓ
𝒮-BGroup n k = ∫⟨ 𝒮-universe ⟩ 𝒮ᴰ-BGroup n k
𝒮-1BGroup : URGStr 1BGroupΣ ℓ
𝒮-1BGroup = 𝒮-BGroup 0 1
𝒮-Iso-BGroup-Group : {ℓ : Level} → 𝒮-PIso (𝒮-group ℓ) 𝒮-1BGroup
RelIso.fun 𝒮-Iso-BGroup-Group G = EM₁ G , embase , EM₁Connected G , EM₁Groupoid G
RelIso.inv 𝒮-Iso-BGroup-Group = π₁-1BGroupΣ
RelIso.leftInv 𝒮-Iso-BGroup-Group = π₁EM₁≃
RelIso.rightInv 𝒮-Iso-BGroup-Group BG = basetype-≅ , basepoint-≅ , tt , tt
where
-- notation
type = fst BG
* = fst (snd BG)
conn = fst (snd (snd BG))
trunc = snd (snd (snd BG))
BG' = (bgroup (type , *) conn trunc)
π₁BG : Group
π₁BG = π₁-1BGroupΣ BG
EM₁π₁BG : 1BGroupΣ
EM₁π₁BG = EM₁ π₁BG , embase , EM₁Connected π₁BG , EM₁Groupoid π₁BG
-- equivalences
basetype-≅ : EM₁ π₁BG ≃ type
fst basetype-≅ = EM₁-functor-lInv-function π₁BG BG' (GroupEquiv.hom (π₁EM₁≃ π₁BG))
snd basetype-≅ = EM₁-functor-lInv-onIso-isEquiv π₁BG BG' (π₁EM₁≃ π₁BG)
basepoint-≅ : * ≡ *
basepoint-≅ = refl
𝒮ᴰ-BGroupHom : (n k : ℕ) → URGStrᴰ (𝒮-BGroup {ℓ} n k ×𝒮 𝒮-BGroup {ℓ'} n k)
(λ (BG , BH) → BGroupHomΣ BG BH)
(ℓ-max ℓ ℓ')
𝒮ᴰ-BGroupHom n k =
make-𝒮ᴰ
(λ {(BG , BH)} {(BG' , BH')} f (((eᴳ , _) , eᴳ-pt , _), ((eᴴ , _) , eᴴ-pt , _)) f'
→ ((eᴴ , eᴴ-pt) ∘∙ f) ∙∼ (f' ∘∙ (eᴳ , eᴳ-pt)))
(λ {(BG , BH)} f → q {(BG , BH)} f)
contrSingl
where
module _ {(BG , BH) : BGroupΣ n k × BGroupΣ n k} (f : BGroupHomΣ BG BH) where
q : (id∙ (baseΣ BH) ∘∙ f) ∙∼ (f ∘∙ id∙ (baseΣ BG))
q = funExt∙⁻ (id∙ (baseΣ BH) ∘∙ f
≡⟨ ∘∙-idʳ f ⟩
f
≡⟨ sym (∘∙-idˡ f) ⟩
(f ∘∙ id∙ (baseΣ BG)) ∎)
module _ ((BG , BH) : BGroupΣ n k × BGroupΣ n k) (f : BGroupHomΣ BG BH) where
contrSingl : isContr (Σ[ f' ∈ BGroupHomΣ BG BH ] ((id∙ (baseΣ BH) ∘∙ f) ∙∼ (f' ∘∙ id∙ (baseΣ BG))))
contrSingl =
isContrRespectEquiv (Σ-cong-equiv-snd (λ f' → f ≡ f'
≃⟨ invEquiv (funExt∙≃ f f') ⟩
f ∙∼ f'
≃⟨ pathToEquiv (cong (_∙∼ f')
(sym (∘∙-idʳ f))
∙ cong ((id∙ (baseΣ BH) ∘∙ f) ∙∼_)
(sym (∘∙-idˡ f'))) ⟩
(id∙ (baseΣ BH) ∘∙ f) ∙∼ (f' ∘∙ id∙ (baseΣ BG)) ■))
(isContrSingl f)
| {
"alphanum_fraction": 0.5324015248,
"avg_line_length": 37.776,
"ext": "agda",
"hexsha": "0e03e0a0b8e1f38f380d61fc2c5d20885d97859e",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/DStructures/Structures/Higher.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/DStructures/Structures/Higher.agda",
"max_line_length": 113,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/DStructures/Structures/Higher.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1773,
"size": 4722
} |
open import Agda.Primitive using (lzero; lsuc; _⊔_ ;Level)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; setoid; cong; trans)
import Function.Equality
open import Relation.Binary using (Setoid)
import Categories.Category
import Categories.Functor
import Categories.Category.Instance.Setoids
import Categories.Monad.Relative
import Categories.Category.Equivalence
import Categories.Category.Cocartesian
import Categories.Category.Construction.Functors
import Categories.NaturalTransformation.Equivalence
import Relation.Binary.Core
import SecondOrder.Arity
import SecondOrder.Signature
import SecondOrder.Metavariable
import SecondOrder.VRenaming
import SecondOrder.MRenaming
import SecondOrder.Term
import SecondOrder.IndexedCategory
import SecondOrder.RelativeKleisli
import SecondOrder.Substitution
module SecondOrder.VRelativeMonad
{ℓ}
{𝔸 : SecondOrder.Arity.Arity}
(Σ : SecondOrder.Signature.Signature ℓ 𝔸)
where
open SecondOrder.Signature.Signature Σ
open SecondOrder.Metavariable Σ
open SecondOrder.Term Σ
open SecondOrder.VRenaming Σ
open SecondOrder.MRenaming Σ
open SecondOrder.Substitution Σ
-- TERMS FORM A RELATIVE MONAD
-- (FOR A FUNCTOR WHOSE DOMAIN IS THE
-- CATEGORY OF VARIABLE CONTEXTS AND RENAMINGS)
module _ where
open Categories.Category
open Categories.Functor using (Functor)
open Categories.Category.Instance.Setoids
open Categories.Monad.Relative
open Function.Equality using () renaming (setoid to Π-setoid)
open Categories.Category.Equivalence using (StrongEquivalence)
open import SecondOrder.IndexedCategory
open import SecondOrder.RelativeKleisli
open Categories.Category.Construction.Functors
open Categories.NaturalTransformation.Equivalence
open Relation.Binary.Core hiding (_⇒_)
-- The carrier of the codomain of Jⱽ (morally ∀ Γ → A ∈ Δ ,, Γ)
record Codomain-Jⱽ-Elt : Set ((lsuc ℓ)) where
open Category (Setoids ℓ ℓ)
open Setoid
field
F₀ : VContext → MContext → Obj
F₁ : ∀ {Θ ψ Δ Ξ} (ρ : Δ ⇒ᵛ Ξ) (ι : Θ ⇒ᵐ ψ)
→ (F₀ Δ Θ) ⇒ (F₀ Ξ ψ)
identity : ∀ {Θ Δ}
→ Category._≈_ (Setoids ℓ ℓ) (F₁ (idᵛ {Δ}) (idᵐ {Θ})) (id {F₀ Δ Θ})
homomorphism : ∀ {Θ ψ Ω Γ Δ Ξ} {ρ : Γ ⇒ᵛ Δ} {ι : Θ ⇒ᵐ ψ} {τ : Δ ⇒ᵛ Ξ} {μ : ψ ⇒ᵐ Ω}
→ Category._≈_ (Setoids ℓ ℓ) (F₁ (τ ∘ᵛ ρ) (μ ∘ᵐ ι)) ((F₁ τ μ) ∘ (F₁ ρ ι))
F-resp-≈ : ∀ {Θ ψ Γ Δ} {ρ τ : Γ ⇒ᵛ Δ} {ι μ : Θ ⇒ᵐ ψ}
→ (ρ ≡ᵛ τ) → (ι ≡ᵐ μ) → (Category._≈_ (Setoids ℓ ℓ) (F₁ ρ ι) (F₁ τ μ))
-- Transformation for Codomain-Jⱽ (analogue to natural transformations)
record NaturalTransformation-Jⱽ (Fⱽ Gⱽ : Codomain-Jⱽ-Elt) : Set (lsuc ℓ)
where
private
module Fⱽ = Codomain-Jⱽ-Elt Fⱽ
module Gⱽ = Codomain-Jⱽ-Elt Gⱽ
open Fⱽ using (F₀; F₁)
open Category (Setoids ℓ ℓ)
field
η : ∀ Θ Γ → (F₀ Γ Θ) ⇒ (Gⱽ.F₀ Γ Θ)
commute : ∀ {Θ ψ Γ Δ} (ρ : Γ ⇒ᵛ Δ) (ι : Θ ⇒ᵐ ψ)
→ Category._≈_ (Setoids ℓ ℓ) ((η ψ Δ) ∘ (F₁ ρ ι)) ((Gⱽ.F₁ ρ ι) ∘ (η Θ Γ))
-- ignore-MCtx : ∀ Θ Ω Γ → (∀ (x : F₀ Γ Θ))
open NaturalTransformation-Jⱽ
-- Equivalence of NaturalTransformation-Jⱽ (analogue to the one
-- of the natural transformations)
infix 4 _≃Jⱽ_
_≃Jⱽ_ : ∀ {Fⱽ Gⱽ : Codomain-Jⱽ-Elt} → Rel (NaturalTransformation-Jⱽ Fⱽ Gⱽ) ℓ
𝒩 ≃Jⱽ ℳ = ∀ {Θ Γ} → Category._≈_ (Setoids ℓ ℓ)
(η 𝒩 Θ Γ)
(η ℳ Θ Γ)
-- Identity transformation analogue to the one
-- of the natural transformations, for NaturalTransformation-Jⱽ
idN-Jⱽ : ∀ {Fⱽ : Codomain-Jⱽ-Elt} → NaturalTransformation-Jⱽ Fⱽ Fⱽ
idN-Jⱽ {Fⱽ} =
record
{ η = λ Θ Γ →
record
{ _⟨$⟩_ = λ x → x
; cong = λ x → x }
; commute = λ {Θ} {ψ} {Γ} {Δ} ρ ι ξ
→ Codomain-Jⱽ-Elt.F-resp-≈ Fⱽ {Θ} {ψ} {Γ} {Δ} {ρ} {ρ} {ι} {ι}
(λ x₁ → refl) (λ M → refl) ξ }
-- Composition of NaturalTransformation-Jⱽ (analogue to the one
-- of the natural transformations)
_∘-Jⱽ_ : ∀ {Fⱽ Gⱽ Hⱽ : Codomain-Jⱽ-Elt} (𝒩 : NaturalTransformation-Jⱽ Gⱽ Hⱽ) (ℳ : NaturalTransformation-Jⱽ Fⱽ Gⱽ) → NaturalTransformation-Jⱽ Fⱽ Hⱽ
_∘-Jⱽ_ {Fⱽ} {Gⱽ} {Hⱽ} 𝒩 ℳ =
let open Category (Setoids ℓ ℓ) in
let open NaturalTransformation-Jⱽ in
let open Codomain-Jⱽ-Elt in
record
{ η = λ Θ Γ → η 𝒩 Θ Γ ∘ η ℳ Θ Γ
; commute = λ {Θ} {ψ} {Γ} {Δ} ρ ι →
let open HomReasoning {F₀ Fⱽ Γ Θ} {F₀ Hⱽ Δ ψ} in
begin
(Category._∘_ (Setoids ℓ ℓ) (η {Gⱽ} {Hⱽ} 𝒩 ψ Δ) ((η {Fⱽ} {Gⱽ} ℳ ψ Δ) ∘ (F₁ Fⱽ ρ ι))) ≈⟨ assoc {f = F₁ Fⱽ ρ ι} {g = η ℳ ψ Δ} {h = η 𝒩 ψ Δ} ⟩
(η 𝒩 ψ Δ ∘ (η ℳ ψ Δ) ∘ (F₁ Fⱽ ρ ι)) ≈⟨ refl⟩∘⟨_
{f = η 𝒩 ψ Δ} {g = (η ℳ ψ Δ) ∘ (F₁ Fⱽ ρ ι)}
{i = (F₁ Gⱽ ρ ι) ∘ (η ℳ Θ Γ)}
(commute ℳ ρ ι) ⟩
(η 𝒩 ψ Δ ∘ ((F₁ Gⱽ ρ ι) ∘ (η ℳ Θ Γ))) ≈⟨ sym-assoc {f = η ℳ Θ Γ} {g = F₁ Gⱽ ρ ι} {h = η 𝒩 ψ Δ}⟩
((η 𝒩 ψ Δ) ∘ (F₁ Gⱽ ρ ι)) ∘ (η ℳ Θ Γ) ≈⟨ _⟩∘⟨refl
{f = (η 𝒩 ψ Δ) ∘ (F₁ Gⱽ ρ ι)} {h = (F₁ Hⱽ ρ ι) ∘ (η 𝒩 Θ Γ)}
{g = η ℳ Θ Γ}
(commute 𝒩 ρ ι) ⟩
(((F₁ Hⱽ ρ ι) ∘ (η 𝒩 Θ Γ)) ∘ (η ℳ Θ Γ)) ≈⟨ assoc {f = η ℳ Θ Γ} {g = η 𝒩 Θ Γ} {h = F₁ Hⱽ ρ ι} ⟩
(((F₁ Hⱽ ρ ι) ∘ (η 𝒩 Θ Γ)) ∘ (η ℳ Θ Γ)) ∎}
-- Proof that the category of Codomain-Jⱽ and NaturalTransformation-Jⱽ is indeed a category
-- associativity of composition
-- (surprisingly enough, the proof of "sym-assoc-Jⱽ" is exactly the same :
-- Is there a problem in the definitions ?)
assoc-Jⱽ : {A B C D : Codomain-Jⱽ-Elt}
{ℒ : NaturalTransformation-Jⱽ A B}
{ℳ : NaturalTransformation-Jⱽ B C}
{𝒩 : NaturalTransformation-Jⱽ C D}
→ ((𝒩 ∘-Jⱽ ℳ) ∘-Jⱽ ℒ) ≃Jⱽ (𝒩 ∘-Jⱽ (ℳ ∘-Jⱽ ℒ))
assoc-Jⱽ {A} {B} {C} {D} {ℒ} {ℳ} {𝒩} {Θ} {Γ} ξ = Function.Equality.Π.cong (η 𝒩 Θ Γ)
(Function.Equality.Π.cong (η ℳ Θ Γ)
(Function.Equality.cong (η ℒ Θ Γ) ξ))
-- identity is identity
identityˡ-Jⱽ : {A B : Codomain-Jⱽ-Elt}
{𝒩 : NaturalTransformation-Jⱽ A B}
→ (idN-Jⱽ ∘-Jⱽ 𝒩) ≃Jⱽ 𝒩
identityˡ-Jⱽ {𝒩 = 𝒩} {Θ = Θ} {Γ = Γ} ξ = Function.Equality.cong (η 𝒩 Θ Γ) ξ
-- Codomain of Jⱽ (the category with Codomain-Jⱽ-Elt as objects and NaturalTransformation-Jⱽ as maps)
Codomain-Jⱽ : Category (lsuc ℓ) (lsuc ℓ) ℓ
Codomain-Jⱽ = record
{ Obj = Codomain-Jⱽ-Elt
; _⇒_ = NaturalTransformation-Jⱽ
; _≈_ = _≃Jⱽ_
; id = idN-Jⱽ
; _∘_ = _∘-Jⱽ_
; assoc = λ {Fⱽ} {Gⱽ} {Hⱽ} {Kⱽ} {𝒩} {ℳ} {ℒ} → assoc-Jⱽ {ℒ = 𝒩} {ℳ = ℳ} {𝒩 = ℒ}
; sym-assoc = λ {Fⱽ} {Gⱽ} {Hⱽ} {Kⱽ} {𝒩} {ℳ} {ℒ} → assoc-Jⱽ {ℒ = 𝒩} {ℳ = ℳ} {𝒩 = ℒ}
; identityˡ = λ {Fⱽ} {Gⱽ} {𝒩} → identityˡ-Jⱽ {𝒩 = 𝒩}
; identityʳ = λ {Fⱽ} {Gⱽ} {𝒩} → identityˡ-Jⱽ {𝒩 = 𝒩}
; identity² = λ {Fⱽ} ξ → ξ
; equiv = λ {Fⱽ} {Gⱽ}
→ record
{ refl = λ {𝒩 = 𝒩} {Θ = Θ} {Γ = Γ} {x} {y} ξ
→ Function.Equality.cong (η 𝒩 Θ Γ) ξ
; sym = λ {𝒩} {ℳ} ξᴺ {Θ} {Γ} ξ
→ Category.Equiv.sym (Setoids ℓ ℓ)
{_} {_} {η 𝒩 Θ Γ} {η ℳ Θ Γ} ξᴺ ξ
; trans = λ {𝒩} {ℳ} {ℒ} ξᴺ₂ ξᴺ₁ {Θ} {Γ} ξ
→ Category.Equiv.trans (Setoids ℓ ℓ)
{_} {_} {η 𝒩 Θ Γ} {η ℳ Θ Γ} {η ℒ Θ Γ} ξᴺ₂ ξᴺ₁ ξ}
; ∘-resp-≈ = λ {Fⱽ} {Gⱽ} {Hⱽ} {𝒩} {ℳ} {ℒ} {𝒦} ξᴺ₁ ξᴺ₂ {Θ} {Γ} ξ
→ Category.∘-resp-≈ (Setoids ℓ ℓ)
{_} {_} {_}
{η 𝒩 Θ Γ} {η ℳ Θ Γ} {η ℒ Θ Γ} {η 𝒦 Θ Γ}
ξᴺ₁ ξᴺ₂ ξ
}
-- The embedding of contexts into setoids indexed by sorts, metavariable telescope and variable telescope
Jⱽ : Functor VContexts (IndexedCategory sort Codomain-Jⱽ)
Jⱽ = record
{ F₀ = λ Γ A →
record
{ F₀ = λ Δ Θ → setoid (A ∈ (Γ ,, Δ))
; F₁ = λ ρ ι → record
{ _⟨$⟩_ = [ inlᵛ , inrᵛ ∘ᵛ ρ ]ᵛ
; cong = λ {x} {y} ξ → ρ-resp-≡ {ρ = [ var-inl , var-inr ∘ᵛ ρ ]ᵛ} ξ}
; identity = λ {Θ} {Δ} {x} ξ → trans (idᵛ+idᵛ x) ξ
; homomorphism = λ {Θ} {ψ} {Ω} {Δ} {Ξ} {Λ} {ρ} {ι} {τ} {μ} {x} {y} ξ
→ trans
(ʳ⇑ᵛ-resp-∘ᵛ x)
(ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ}
(ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (ρ x₁)) ]ᵛ} ξ))
; F-resp-≈ = λ {Θ} {ψ} {Δ} {Ξ} {ρ} {τ} {ι} {μ} ξᵛ ξᵐ {x} {y} ξ
→ trans
([,]ᵛ-resp-≡ᵛ (λ x₁ → refl) (∘ᵛ-resp-≡ᵛ {τ₁ = λ x₁ → var-inr x₁} (λ x₁ → refl) λ x₁ → ξᵛ x₁) x)
(ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ} ξ)
}
; F₁ = λ ρ A → record
{ η = λ Θ Γ → record { _⟨$⟩_ = ⇑ᵛ ρ ; cong = cong (⇑ᵛ ρ) }
; commute = λ τ ι {x} ξ
→ trans
(uniqueᵛ²
{τ = [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ ∘ᵛ [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ}
{σ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ} (λ x₁ → refl) (λ x₁ → refl) x)
(ρ-resp-≡
{ρ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ} ξ)}
; identity = λ A {Θ} {Γ} {x} ξ → trans (idᵛ+idᵛ x) ξ
; homomorphism = λ {Δ} {Ξ} {Λ} {ρ} {τ} A {_} {_} {x} ξ
→ trans
(uniqueᵛ²
{τ = [ (λ x₁ → var-inl (τ (ρ x₁))) , (λ x₁ → var-inr x₁) ]ᵛ}
{σ = [ (λ x₁ → var-inl (τ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ}
(λ x₁ → refl) (λ x₁ → refl) x)
(ρ-resp-≡
{ρ = [ (λ x₁ → var-inl (τ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ } ξ)
; F-resp-≈ = λ {_} {_} {ρ} {τ} ξρ A {_} {_} {x} {y} ξ
→ trans
(([,]ᵛ-resp-≡ᵛ {ρ₁ = λ x₁ → var-inl (ρ x₁)} {τ₁ = var-inr} (λ x₁ → ∘ᵛ-resp-≡ᵛ {τ₁ = var-inl} (λ x₃ → refl) ξρ x₁) (λ x₁ → refl) x))
(ρ-resp-≡ {ρ = ⇑ᵛ τ} ξ)
}
factor-empty-ctx : ∀ {Θ Ω Γ Δ A} (x : Setoid.Carrier ((Codomain-Jⱽ-Elt.F₀((Categories.Functor.Functor.F₀ Jⱽ) Γ A)) Δ Θ)) → x ≡ ( Function.Equality._⟨$⟩_ ((NaturalTransformation-Jⱽ.η ((Categories.Functor.Functor.F₁ Jⱽ) idᵛ A)) Ω Δ) x)
factor-empty-ctx (var-inl x) = refl
factor-empty-ctx (var-inr x) = refl
-- The relative monad over Jⱽ
module _ {Θ : MContext} where
open Categories.Category
open Categories.Functor using (Functor)
open Categories.Category.Instance.Setoids
open Categories.Category.Category (Setoids ℓ ℓ)
open Categories.Monad.Relative
open Function.Equality using () renaming (setoid to Π-setoid)
open Categories.Category.Equivalence using (StrongEquivalence)
open import SecondOrder.IndexedCategory
open import SecondOrder.RelativeKleisli
open NaturalTransformation-Jⱽ
open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong)
open import Relation.Binary.Reasoning.MultiSetoid
-- Setoids≈-⟨$⟩ : ∀ {From To} (f g : From Function.Equality.⟶ To) → (Category._≈_ (Setoids ℓ ℓ) f g) → (∀ (x : Setoid.Carrier From) → Setoid._≈_ To (f ⟨$⟩ x) (g ⟨$⟩ x))
-- Setoids≈-⟨$⟩ = {!!}
VMonad : Monad Jⱽ
Codomain-Jⱽ-Elt.F₀ (Monad.F₀ VMonad Γ A) Δ ψ = Term-setoid Θ (Γ ,, Δ) A
_⟨$⟩_ (Codomain-Jⱽ-Elt.F₁ (Monad.F₀ VMonad Γ A) ρ ι) = [ ʳ⇑ᵛ ρ ]ᵛ_
func-cong (Codomain-Jⱽ-Elt.F₁ (Monad.F₀ VMonad Γ A) ρ ι) ξ = []ᵛ-resp-≈ ξ
Codomain-Jⱽ-Elt.identity (Monad.F₀ VMonad Γ A) ξ = ≈-trans ([]ᵛ-resp-≡ᵛ idᵛ+idᵛ) (≈-trans [idᵛ] ξ)
Codomain-Jⱽ-Elt.homomorphism (Monad.F₀ VMonad Γ A) {ρ = ρ} {ι = ι} {τ = τ} {μ = μ} {x = x} {y = y} ξ
= begin⟨ Term-setoid Θ _ _ ⟩
[ ʳ⇑ᵛ (τ ∘ᵛ ρ) ]ᵛ x ≈⟨ []ᵛ-resp-≈ ξ ⟩
[ ʳ⇑ᵛ (τ ∘ᵛ ρ) ]ᵛ y ≈⟨ []ᵛ-resp-≡ᵛ (λ x₁ →
uniqueᵛ² {τ = [ (λ x₂ → var-inl x₂) , (λ x₂ → var-inr (τ (ρ x₂))) ]ᵛ}
{σ = σ' }
(λ x₂ → refl) (λ x₂ → refl) x₁) ⟩
[ σ' ]ᵛ y ≈⟨ [∘ᵛ] ⟩
((Codomain-Jⱽ-Elt.F₁ (Monad.F₀ VMonad Γ A) τ μ ∘
Codomain-Jⱽ-Elt.F₁ (Monad.F₀ VMonad Γ A) ρ ι) ⟨$⟩ y)
∎
where
σ' : (Γ ,, _) ⇒ᵛ Γ ,, _
σ' = [ var-inl
, (λ x₁ → var-inr (τ x₁))
]ᵛ ∘ᵛ [ var-inl
, (λ x₁ → var-inr (ρ x₁))
]ᵛ
Codomain-Jⱽ-Elt.F-resp-≈ (Monad.F₀ VMonad Γ A) {ψ} {Ω} {Δ} {Ξ} {ρ} {τ} {ι} {μ} ξᵛ ξᵐ {t} {u} ξ =
begin⟨ Term-setoid Θ _ _ ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛ ]ᵛ t) ≈⟨ []ᵛ-resp-≈ ξ ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛ ]ᵛ u)
≈⟨ []ᵛ-resp-≡ᵛ ([,]ᵛ-resp-≡ᵛ (λ x → refl) λ x → ρ-resp-≡ {ρ = var-inr} (ξᵛ x)) ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (τ x₁)) ]ᵛ ]ᵛ u) ∎
_⟨$⟩_ (η (Monad.unit VMonad A) ψ Γ) = tm-var
func-cong (η (Monad.unit VMonad A) ψ Γ) ξ = congˢ-var {σ = tm-var} ξ
commute (Monad.unit VMonad A) ρ ι ξ = congˢ-var {σ = tm-var} (ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (ρ x₁)) ]ᵛ} ξ)
_⟨$⟩_ (η (Monad.extend VMonad {Δ} {Ξ} σ A) ψ Γ) t = [ (λ {B} x → η (σ B) ψ Γ ⟨$⟩ x) ]ˢ t
func-cong (η (Monad.extend VMonad σ A) ψ Γ) = []ˢ-resp-≈ ((λ {B} x → η (σ B) ψ Γ ⟨$⟩ x) )
commute (Monad.extend VMonad {Υ} {Ω} σ A) {Ξ} {Ψ} {Γ} {Δ} ρ ι {x} {y} x≈y
= begin⟨ Term-setoid Θ _ _ ⟩
([ (λ {B} → _⟨$⟩_ (η (σ B) Ψ Δ)) ]ˢ ([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛ ]ᵛ x)) ≈⟨ ≈-sym ([ˢ∘ᵛ] x) ⟩
([(λ {B} → _⟨$⟩_ (η (σ B) Ψ Δ)) ˢ∘ᵛ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛ ]ˢ x) ≈⟨ {!!} ⟩
{!!} ≈⟨ {!!} ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛ ]ᵛ ([ (λ {B} → _⟨$⟩_ (η (σ B) Ξ Γ)) ]ˢ y)) ∎
-- where
-- is-subst : ∀ (𝒩 : NaturalTransformation-Jⱽ (Jⱽ Γ A) (Monad.F₀ VMonad Ω i)) → Σ
-- begin⟨ Term-setoid Θ _ _ ⟩
-- (η (Monad.extend VMonad σ A) Ψ Δ ∘
-- Codomain-Jⱽ-Elt.F₁ (Monad.F₀ VMonad Υ A) ρ ι
-- ⟨$⟩ x)
-- ≈⟨ ≈-sym ([ˢ∘ᵛ] x) ⟩
-- ([ (λ {B} x₁ → η (σ B) Θ Δ ⟨$⟩ x₁) ˢ∘ᵛ (ʳ⇑ᵛ ρ) ]ˢ x) ≈⟨ []ˢ-resp-≈ ((λ {B} → _⟨$⟩_ (η (σ B) Θ Δ)) ˢ∘ᵛ(ʳ⇑ᵛ ρ)) x≈y ⟩
-- ([ (λ {B} → _⟨$⟩_ (η (σ B) Θ Δ)) ˢ∘ᵛ (ʳ⇑ᵛ ρ) ]ˢ y) ≈⟨ []ˢ-resp-≈ˢ y (η-ˢ∘ᵛ ρ ι) ⟩
-- ([ ʳ⇑ᵛ ρ ᵛ∘ˢ (λ {B} x₁ → η (σ B) Θ Γ ⟨$⟩ x₁) ]ˢ y) ≈⟨ [ᵛ∘ˢ] y ⟩
-- (Codomain-Jⱽ-Elt.F₁ (Monad.F₀ VMonad Ω A) ρ ι ∘
-- η (Monad.extend VMonad σ A) Ξ Γ
-- ⟨$⟩ y)
-- ∎
where
𝒩-to-subst : ∀ {Γ Δ Ξ} (𝒩 : ∀ A → NaturalTransformation-Jⱽ (Categories.Functor.Functor.F₀ Jⱽ Γ A) (Monad.F₀ VMonad Ξ A)) → (Θ ⊕ (Γ ,, Δ) ⇒ˢ (Ξ ,, Δ))
𝒩-to-subst 𝒩 {A} (var-inl z) = η (𝒩 A) _ _ ⟨$⟩ (var-inl z)
𝒩-to-subst 𝒩 {A} (var-inr z) = tm-var (var-inr z)
𝒩-is-subst : ∀ {Ω Γ Ξ} (𝒩 : ∀ A → NaturalTransformation-Jⱽ (Categories.Functor.Functor.F₀ Jⱽ Γ A) (Monad.F₀ VMonad Ξ A)) x → SecondOrder.Term._≈_ Σ ((NaturalTransformation-Jⱽ.η (𝒩 A) Ω Γ) ⟨$⟩ x) (𝒩-to-subst 𝒩 x)
𝒩-is-subst 𝒩 (var-inl z) = {!!}
𝒩-is-subst 𝒩 (var-inr z) = {!!}
η-ˢ∘ᵛ : ∀ {Ξ} {ψ} {Γ} {Δ} (ρ : Γ ⇒ᵛ Δ) (ι : Ξ ⇒ᵐ ψ)
→ (λ {B} → _⟨$⟩_ (η (σ B) ψ Δ)) ˢ∘ᵛ (ʳ⇑ᵛ ρ)
≈ˢ ʳ⇑ᵛ ρ ᵛ∘ˢ (λ {B} x₁ → η (σ B) Ψ Γ ⟨$⟩ x₁)
η-ˢ∘ᵛ {Ξ = Ξ′} {ψ = ψ} {Γ = Γ′} {Δ′} ρ ι (var-inl x) =
begin⟨ Term-setoid Θ _ _ ⟩
((λ {B} → _⟨$⟩_ (η (σ B) ψ Δ′)) ˢ∘ᵛ (ʳ⇑ᵛ ρ)) (var-inl x) ≈⟨ {!!} ⟩
{![]!} ≈⟨ {!!} ⟩
{!!} ≈⟨ {! ˢ∘ᵛ-η (σ A₁) Θ Γ₁η (σ A₁) Θ Γ₁ᵛ∘ˢ-disjoint ˢ∘ᵛ-ᵛ∘uˢ-disjoint!} ⟩
(ʳ⇑ᵛ ρ ᵛ∘ˢ (λ {B} → _⟨$⟩_ (η (σ B) Ψ _))) (var-inl x) ∎
where
ˢ∘ᵛ-ᵛ∘ˢ-disjoint : ∀ {ψ} {Γ Ξ Δ Λ} (σ : ψ ⊕ Ξ ⇒ˢ Λ) (ρ : Γ ⇒ᵛ Δ)
→ ⇑ˢ σ ˢ∘ᵛ ʳ⇑ᵛ ρ ≈ˢ ʳ⇑ᵛ ρ ᵛ∘ˢ ⇑ˢ σ
ˢ∘ᵛ-ᵛ∘ˢ-disjoint σ τ (var-inl x) =
begin⟨ Term-setoid _ _ _ ⟩
([ var-inl ]ᵛ σ x) ≈⟨ []ᵛ-resp-≡ᵛ (λ x₃ → refl) ⟩
([ [ (λ x₃ → var-inl x₃) , (λ x₃ → var-inr (τ x₃)) ]ᵛ ∘ᵛ var-inl ]ᵛ σ x) ≈⟨ [∘ᵛ] ⟩
([ [ (λ x₃ → var-inl x₃) , (λ x₃ → var-inr (τ x₃)) ]ᵛ ]ᵛ ([ var-inl ]ᵛ σ x)) ∎
ˢ∘ᵛ-ᵛ∘ˢ-disjoint σ τ (var-inr x) = ≈-refl
η-ˢ∘ᵛ ρ ι (var-inr x) = begin⟨ Term-setoid Θ _ _ ⟩ {!!}
Monad.identityʳ VMonad {_} {_} {𝒩s} =
λ i {k = Ω} {Γ = Γ} {x = x} {y = y} x≈y → (func-cong (η (𝒩s i) Ω Γ) (x≈y))
Monad.identityˡ VMonad = λ i x≈y → ≈-trans [idˢ] x≈y
Monad.assoc VMonad {Γ} {Δ} {Ξ} {k} {l} = λ A {ψ} {Λ} {x} {y} ξ
→ begin⟨ Term-setoid Θ _ _ ⟩
([ (λ {B} x₁ → [ (λ {B = B₁} → _⟨$⟩_ (η (l B₁) ψ Λ)) ]ˢ (η (k B) ψ Λ ⟨$⟩ x₁)) ]ˢ x)
≈⟨ []ˢ-resp-≈ (λ {B} x₁ → [ (λ {B = B₁} → _⟨$⟩_ (η (l B₁) ψ Λ)) ]ˢ (η (k B) ψ Λ ⟨$⟩ x₁)) ξ ⟩
([ (λ {B} x₁ → [ (λ {B = B₁} → _⟨$⟩_ (η (l B₁) ψ Λ)) ]ˢ (η (k B) ψ Λ ⟨$⟩ x₁)) ]ˢ y) ≈⟨ [∘ˢ] y ⟩
([ (λ {B} → _⟨$⟩_ (η (l B) ψ Λ)) ]ˢ ([ (λ {B} → _⟨$⟩_ (η (k B) ψ Λ)) ]ˢ y)) ∎
Monad.extend-≈ VMonad {Γ} {Δ} {k} {h} = λ ξ A {ψ} {Λ} {t} {u} ξᵗ
→ begin⟨ Term-setoid Θ _ _ ⟩
([ (λ {B} → _⟨$⟩_ (η (k B) ψ Λ)) ]ˢ t) ≈⟨ []ˢ-resp-≈ (λ {B} → _⟨$⟩_ (η (k B) ψ Λ)) ξᵗ ⟩
([ (λ {B} → _⟨$⟩_ (η (k B) ψ Λ)) ]ˢ u) ≈⟨ []ˢ-resp-≈ˢ u (λ {A = C} x → ξ C refl) ⟩
([ (λ {B} → _⟨$⟩_ (η (h B) ψ Λ)) ]ˢ u) ∎
-- *************************************************************************************
-- open import Agda.Primitive using (lzero; lsuc; _⊔_ ;Level)
-- open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; setoid; cong; trans)
-- import Function.Equality
-- open import Relation.Binary using (Setoid)
-- import Categories.Category
-- import Categories.Functor
-- import Categories.Category.Instance.Setoids
-- import Categories.Monad.Relative
-- import Categories.Category.Equivalence
-- import Categories.Category.Cocartesian
-- import Categories.Category.Construction.Functors
-- import Categories.NaturalTransformation.Equivalence
-- import Relation.Binary.Core
-- import SecondOrder.Arity
-- import SecondOrder.Signature
-- import SecondOrder.Metavariable
-- import SecondOrder.VRenaming
-- import SecondOrder.MRenaming
-- import SecondOrder.Term
-- import SecondOrder.IndexedCategory
-- import SecondOrder.RelativeKleisli
-- import SecondOrder.Substitution
-- module SecondOrder.VRelMon
-- {ℓ}
-- {𝔸 : SecondOrder.Arity.Arity}
-- (Σ : SecondOrder.Signature.Signature ℓ 𝔸)
-- where
-- open SecondOrder.Signature.Signature Σ
-- open SecondOrder.Metavariable Σ
-- open SecondOrder.Term Σ
-- open SecondOrder.VRenaming Σ
-- open SecondOrder.MRenaming Σ
-- open SecondOrder.Substitution Σ
-- -- TERMS FORM A RELATIVE MONAD
-- -- (FOR A FUNCTOR WHOSE DOMAIN IS THE
-- -- CATEGORY OF VARIABLE CONTEXTS AND RENAMINGS)
-- module _ where
-- open Categories.Category
-- open Categories.Functor using (Functor)
-- open Categories.Category.Instance.Setoids
-- open Categories.Monad.Relative
-- open Function.Equality using () renaming (setoid to Π-setoid)
-- open Categories.Category.Equivalence using (StrongEquivalence)
-- open import SecondOrder.IndexedCategory
-- open import SecondOrder.RelativeKleisli
-- open Categories.Category.Construction.Functors
-- open Categories.NaturalTransformation.Equivalence
-- open Relation.Binary.Core hiding (_⇒_)
-- -- The carrier of the codomain of Jⱽ (morally ∀ Γ → A ∈ Δ ,, Γ)
-- record Codomain-Jⱽ-Elt : Set ((lsuc ℓ)) where
-- open Category (Setoids ℓ ℓ)
-- open Setoid
-- field
-- F₀ : VContext → MContext → Obj
-- F₁ : ∀ {Θ ψ Δ Ξ} (ρ : Δ ⇒ᵛ Ξ) (ι : Θ ⇒ᵐ ψ)
-- → (F₀ Δ Θ) ⇒ (F₀ Ξ ψ)
-- identity : ∀ {Θ Δ}
-- → Category._≈_ (Setoids ℓ ℓ) (F₁ (idᵛ {Δ}) (idᵐ {Θ})) (id {F₀ Δ Θ})
-- homomorphism : ∀ {Θ ψ Ω Γ Δ Ξ} {ρ : Γ ⇒ᵛ Δ} {ι : Θ ⇒ᵐ ψ} {τ : Δ ⇒ᵛ Ξ} {μ : ψ ⇒ᵐ Ω}
-- → Category._≈_ (Setoids ℓ ℓ) (F₁ (τ ∘ᵛ ρ) (μ ∘ᵐ ι)) ((F₁ τ μ) ∘ (F₁ ρ ι))
-- F-resp-≈ : ∀ {Θ ψ Γ Δ} {ρ τ : Γ ⇒ᵛ Δ} {ι μ : Θ ⇒ᵐ ψ}
-- → (ρ ≡ᵛ τ) → (ι ≡ᵐ μ) → (Category._≈_ (Setoids ℓ ℓ) (F₁ ρ ι) (F₁ τ μ))
-- -- Transformation for Codomain-Jⱽ (analogue to natural transformations)
-- record NaturalTransformation-Jⱽ (Fⱽ Gⱽ : Codomain-Jⱽ-Elt) : Set (lsuc ℓ)
-- where
-- private
-- module Fⱽ = Codomain-Jⱽ-Elt Fⱽ
-- module Gⱽ = Codomain-Jⱽ-Elt Gⱽ
-- open Fⱽ using (F₀; F₁)
-- open Category (Setoids ℓ ℓ)
-- field
-- η : ∀ Θ Γ → (F₀ Γ Θ) ⇒ (Gⱽ.F₀ Γ Θ)
-- commute : ∀ {Θ ψ Γ Δ} (ρ : Γ ⇒ᵛ Δ) (ι : Θ ⇒ᵐ ψ)
-- → Category._≈_ (Setoids ℓ ℓ) ((η ψ Δ) ∘ (F₁ ρ ι)) ((Gⱽ.F₁ ρ ι) ∘ (η Θ Γ))
-- open NaturalTransformation-Jⱽ
-- -- Equivalence of NaturalTransformation-Jⱽ (analogue to the one
-- -- of the natural transformations)
-- infix 4 _≃Jⱽ_
-- _≃Jⱽ_ : ∀ {Fⱽ Gⱽ : Codomain-Jⱽ-Elt} → Rel (NaturalTransformation-Jⱽ Fⱽ Gⱽ) ℓ
-- 𝒩 ≃Jⱽ ℳ = ∀ {Θ Γ} → Category._≈_ (Setoids ℓ ℓ)
-- (η 𝒩 Θ Γ)
-- (η ℳ Θ Γ)
-- -- Identity transformation analogue to the one
-- -- of the natural transformations, for NaturalTransformation-Jⱽ
-- idN-Jⱽ : ∀ {Fⱽ : Codomain-Jⱽ-Elt} → NaturalTransformation-Jⱽ Fⱽ Fⱽ
-- idN-Jⱽ {Fⱽ} =
-- record
-- { η = λ Θ Γ →
-- record
-- { _⟨$⟩_ = λ x → x
-- ; cong = λ x → x }
-- ; commute = λ {Θ} {ψ} {Γ} {Δ} ρ ι ξ
-- → Codomain-Jⱽ-Elt.F-resp-≈ Fⱽ {Θ} {ψ} {Γ} {Δ} {ρ} {ρ} {ι} {ι}
-- (λ x₁ → refl) (λ M → refl) ξ }
-- -- Composition of NaturalTransformation-Jⱽ (analogue to the one
-- -- of the natural transformations)
-- _∘-Jⱽ_ : ∀ {Fⱽ Gⱽ Hⱽ : Codomain-Jⱽ-Elt} (𝒩 : NaturalTransformation-Jⱽ Gⱽ Hⱽ) (ℳ : NaturalTransformation-Jⱽ Fⱽ Gⱽ) → NaturalTransformation-Jⱽ Fⱽ Hⱽ
-- _∘-Jⱽ_ {Fⱽ} {Gⱽ} {Hⱽ} 𝒩 ℳ =
-- let open Category (Setoids ℓ ℓ) in
-- let open NaturalTransformation-Jⱽ in
-- let open Codomain-Jⱽ-Elt in
-- record
-- { η = λ Θ Γ → η 𝒩 Θ Γ ∘ η ℳ Θ Γ
-- ; commute = λ {Θ} {ψ} {Γ} {Δ} ρ ι →
-- let open HomReasoning {F₀ Fⱽ Γ Θ} {F₀ Hⱽ Δ ψ} in
-- begin
-- (Category._∘_ (Setoids ℓ ℓ) (η {Gⱽ} {Hⱽ} 𝒩 ψ Δ) ((η {Fⱽ} {Gⱽ} ℳ ψ Δ) ∘ (F₁ Fⱽ ρ ι))) ≈⟨ assoc {f = F₁ Fⱽ ρ ι} {g = η ℳ ψ Δ} {h = η 𝒩 ψ Δ} ⟩
-- (η 𝒩 ψ Δ ∘ (η ℳ ψ Δ) ∘ (F₁ Fⱽ ρ ι)) ≈⟨ refl⟩∘⟨_
-- {f = η 𝒩 ψ Δ} {g = (η ℳ ψ Δ) ∘ (F₁ Fⱽ ρ ι)}
-- {i = (F₁ Gⱽ ρ ι) ∘ (η ℳ Θ Γ)}
-- (commute ℳ ρ ι) ⟩
-- (η 𝒩 ψ Δ ∘ ((F₁ Gⱽ ρ ι) ∘ (η ℳ Θ Γ))) ≈⟨ sym-assoc {f = η ℳ Θ Γ} {g = F₁ Gⱽ ρ ι} {h = η 𝒩 ψ Δ}⟩
-- ((η 𝒩 ψ Δ) ∘ (F₁ Gⱽ ρ ι)) ∘ (η ℳ Θ Γ) ≈⟨ _⟩∘⟨refl
-- {f = (η 𝒩 ψ Δ) ∘ (F₁ Gⱽ ρ ι)} {h = (F₁ Hⱽ ρ ι) ∘ (η 𝒩 Θ Γ)}
-- {g = η ℳ Θ Γ}
-- (commute 𝒩 ρ ι) ⟩
-- (((F₁ Hⱽ ρ ι) ∘ (η 𝒩 Θ Γ)) ∘ (η ℳ Θ Γ)) ≈⟨ assoc {f = η ℳ Θ Γ} {g = η 𝒩 Θ Γ} {h = F₁ Hⱽ ρ ι} ⟩
-- (((F₁ Hⱽ ρ ι) ∘ (η 𝒩 Θ Γ)) ∘ (η ℳ Θ Γ)) ∎}
-- -- Proof that the category of Codomain-Jⱽ and NaturalTransformation-Jⱽ is indeed a category
-- -- associativity of composition
-- -- (surprisingly enough, the proof of "sym-assoc-Jⱽ" is exactly the same :
-- -- Is there a problem in the definitions ?)
-- assoc-Jⱽ : {A B C D : Codomain-Jⱽ-Elt}
-- {ℒ : NaturalTransformation-Jⱽ A B}
-- {ℳ : NaturalTransformation-Jⱽ B C}
-- {𝒩 : NaturalTransformation-Jⱽ C D}
-- → ((𝒩 ∘-Jⱽ ℳ) ∘-Jⱽ ℒ) ≃Jⱽ (𝒩 ∘-Jⱽ (ℳ ∘-Jⱽ ℒ))
-- assoc-Jⱽ {A} {B} {C} {D} {ℒ} {ℳ} {𝒩} {Θ} {Γ} ξ = Function.Equality.Π.cong (η 𝒩 Θ Γ)
-- (Function.Equality.Π.cong (η ℳ Θ Γ)
-- (Function.Equality.cong (η ℒ Θ Γ) ξ))
-- -- identity is identity
-- identityˡ-Jⱽ : {A B : Codomain-Jⱽ-Elt}
-- {𝒩 : NaturalTransformation-Jⱽ A B}
-- → (idN-Jⱽ ∘-Jⱽ 𝒩) ≃Jⱽ 𝒩
-- identityˡ-Jⱽ {𝒩 = 𝒩} {Θ = Θ} {Γ = Γ} ξ = Function.Equality.cong (η 𝒩 Θ Γ) ξ
-- -- Codomain of Jⱽ (the category with Codomain-Jⱽ-Elt as objects and NaturalTransformation-Jⱽ as maps)
-- Codomain-Jⱽ : Category (lsuc ℓ) (lsuc ℓ) ℓ
-- Codomain-Jⱽ = record
-- { Obj = Codomain-Jⱽ-Elt
-- ; _⇒_ = NaturalTransformation-Jⱽ
-- ; _≈_ = _≃Jⱽ_
-- ; id = idN-Jⱽ
-- ; _∘_ = _∘-Jⱽ_
-- ; assoc = λ {Fⱽ} {Gⱽ} {Hⱽ} {Kⱽ} {𝒩} {ℳ} {ℒ} → assoc-Jⱽ {ℒ = 𝒩} {ℳ = ℳ} {𝒩 = ℒ}
-- ; sym-assoc = λ {Fⱽ} {Gⱽ} {Hⱽ} {Kⱽ} {𝒩} {ℳ} {ℒ} → assoc-Jⱽ {ℒ = 𝒩} {ℳ = ℳ} {𝒩 = ℒ}
-- ; identityˡ = λ {Fⱽ} {Gⱽ} {𝒩} → identityˡ-Jⱽ {𝒩 = 𝒩}
-- ; identityʳ = λ {Fⱽ} {Gⱽ} {𝒩} → identityˡ-Jⱽ {𝒩 = 𝒩}
-- ; identity² = λ {Fⱽ} ξ → ξ
-- ; equiv = λ {Fⱽ} {Gⱽ}
-- → record
-- { refl = λ {𝒩 = 𝒩} {Θ = Θ} {Γ = Γ} {x} {y} ξ
-- → Function.Equality.cong (η 𝒩 Θ Γ) ξ
-- ; sym = λ {𝒩} {ℳ} ξᴺ {Θ} {Γ} ξ
-- → Category.Equiv.sym (Setoids ℓ ℓ)
-- {_} {_} {η 𝒩 Θ Γ} {η ℳ Θ Γ} ξᴺ ξ
-- ; trans = λ {𝒩} {ℳ} {ℒ} ξᴺ₂ ξᴺ₁ {Θ} {Γ} ξ
-- → Category.Equiv.trans (Setoids ℓ ℓ)
-- {_} {_} {η 𝒩 Θ Γ} {η ℳ Θ Γ} {η ℒ Θ Γ} ξᴺ₂ ξᴺ₁ ξ}
-- ; ∘-resp-≈ = λ {Fⱽ} {Gⱽ} {Hⱽ} {𝒩} {ℳ} {ℒ} {𝒦} ξᴺ₁ ξᴺ₂ {Θ} {Γ} ξ
-- → Category.∘-resp-≈ (Setoids ℓ ℓ)
-- {_} {_} {_}
-- {η 𝒩 Θ Γ} {η ℳ Θ Γ} {η ℒ Θ Γ} {η 𝒦 Θ Γ}
-- ξᴺ₁ ξᴺ₂ ξ
-- }
-- -- The embedding of contexts into setoids indexed by sorts, metavariable telescope and variable telescope
-- Jⱽ : Functor VContexts (IndexedCategory sort Codomain-Jⱽ)
-- Jⱽ = record
-- { F₀ = λ Γ A →
-- record
-- { F₀ = λ Δ Θ → setoid (A ∈ (Γ ,, Δ))
-- ; F₁ = λ ρ ι → record
-- { _⟨$⟩_ = [ inlᵛ , inrᵛ ∘ᵛ ρ ]ᵛ
-- ; cong = λ {x} {y} ξ → ρ-resp-≡ {ρ = [ var-inl , var-inr ∘ᵛ ρ ]ᵛ} ξ}
-- ; identity = λ {Θ} {Δ} {x} ξ → trans (idᵛ+idᵛ x) ξ
-- ; homomorphism = λ {Θ} {ψ} {Ω} {Δ} {Ξ} {Λ} {ρ} {ι} {τ} {μ} {x} {y} ξ
-- → trans
-- (ʳ⇑ᵛ-resp-∘ᵛ x)
-- (ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ}
-- (ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (ρ x₁)) ]ᵛ} ξ))
-- ; F-resp-≈ = λ {Θ} {ψ} {Δ} {Ξ} {ρ} {τ} {ι} {μ} ξᵛ ξᵐ {x} {y} ξ
-- → trans
-- ([,]ᵛ-resp-≡ᵛ (λ x₁ → refl) (∘ᵛ-resp-≡ᵛ {τ₁ = λ x₁ → var-inr x₁} (λ x₁ → refl) λ x₁ → ξᵛ x₁) x)
-- (ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ} ξ)
-- }
-- ; F₁ = λ ρ A → record
-- { η = λ Θ Γ → record { _⟨$⟩_ = ⇑ᵛ ρ ; cong = cong (⇑ᵛ ρ) }
-- ; commute = λ τ ι {x} ξ
-- → trans
-- (uniqueᵛ²
-- {τ = [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ ∘ᵛ [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ}
-- {σ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ} (λ x₁ → refl) (λ x₁ → refl) x)
-- (ρ-resp-≡
-- {ρ = [ var-inl , (λ x₁ → var-inr (τ x₁)) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ} ξ)}
-- ; identity = λ A {Θ} {Γ} {x} ξ → trans (idᵛ+idᵛ x) ξ
-- ; homomorphism = λ {Δ} {Ξ} {Λ} {ρ} {τ} A {_} {_} {x} ξ
-- → trans
-- (uniqueᵛ²
-- {τ = [ (λ x₁ → var-inl (τ (ρ x₁))) , (λ x₁ → var-inr x₁) ]ᵛ}
-- {σ = [ (λ x₁ → var-inl (τ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ}
-- (λ x₁ → refl) (λ x₁ → refl) x)
-- (ρ-resp-≡
-- {ρ = [ (λ x₁ → var-inl (τ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl (ρ x₁)) , (λ x₁ → var-inr x₁) ]ᵛ } ξ)
-- ; F-resp-≈ = λ {_} {_} {ρ} {τ} ξρ A {_} {_} {x} {y} ξ
-- → trans
-- (([,]ᵛ-resp-≡ᵛ {ρ₁ = λ x₁ → var-inl (ρ x₁)} {τ₁ = var-inr} (λ x₁ → ∘ᵛ-resp-≡ᵛ {τ₁ = var-inl} (λ x₃ → refl) ξρ x₁) (λ x₁ → refl) x))
-- (ρ-resp-≡ {ρ = ⇑ᵛ τ} ξ)
-- }
-- -- The relative monad over Jⱽ
-- module _ {Θ : MContext} where
-- open Categories.Category
-- open Categories.Functor using (Functor)
-- open Categories.Category.Instance.Setoids
-- open Categories.Monad.Relative
-- open Function.Equality using () renaming (setoid to Π-setoid)
-- open Categories.Category.Equivalence using (StrongEquivalence)
-- open import SecondOrder.IndexedCategory
-- open import SecondOrder.RelativeKleisli
-- open NaturalTransformation-Jⱽ
-- VMonad : Monad Jⱽ
-- VMonad =
-- let open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong) in
-- record
-- { F₀ = λ Γ A → record
-- { F₀ = λ Δ ψ → Term-setoid Θ (Γ ,, Δ) A
-- ; F₁ = λ ρ ι → record { _⟨$⟩_ = [_]ᵛ_ (ʳ⇑ᵛ ρ) ; cong = λ ξ → []ᵛ-resp-≈ ξ }
-- ; identity = λ ξ → ≈-trans ([]ᵛ-resp-≡ᵛ idᵛ+idᵛ) (≈-trans [idᵛ] ξ)
-- ; homomorphism = λ {_} {_} {_} {_} {_} {_} {ρ} {_} {τ} ξ
-- → ≈-trans
-- ([]ᵛ-resp-≈ ξ)
-- (≈-trans
-- ([]ᵛ-resp-≡ᵛ λ x₁
-- → uniqueᵛ²
-- {τ = [ (λ x₂ → var-inl x₂) , (λ x₂ → var-inr (τ (ρ x₂))) ]ᵛ}
-- {σ = [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (τ x₁)) ]ᵛ ∘ᵛ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛ }
-- (λ x₂ → refl) (λ x₂ → refl) x₁)
-- [∘ᵛ])
-- ; F-resp-≈ = λ ξᵛ ξᵐ ξ → ≈-trans ([]ᵛ-resp-≈ ξ) ([]ᵛ-resp-≡ᵛ λ x → [,]ᵛ-resp-≡ᵛ (λ x₁ → refl) (λ x₁ → ρ-resp-≡ {ρ = var-inr} (ξᵛ x₁)) x )
-- }
-- ; unit = λ A
-- → record
-- { η = λ ψ Γ
-- → record
-- { _⟨$⟩_ = λ x → tm-var x
-- ; cong = λ ξ → congˢ-var {σ = tm-var} ξ }
-- ; commute = λ ρ ι ξ → congˢ-var {σ = tm-var} (ρ-resp-≡ {ρ = [ var-inl , (λ x₁ → var-inr (ρ x₁)) ]ᵛ} ξ) }
-- ; extend = {!!}
-- ; identityʳ = λ A ξ → {!!}
-- ; identityˡ = {!!}
-- ; assoc = {!!}
-- ; extend-≈ = {!!}
-- }
-- -- Other possibility, if the above doesn't work :
-- -- Jⱽ′ : Functor VContexts (Functors MContexts (Functors VContexts (IndexedCategory sort (Setoids ℓ ℓ))))
-- -- Jⱽ′ = record
-- -- { F₀ = {!!} -- λ Γ A → setoid (A ∈ Γ)
-- -- ; F₁ = {!!} -- λ ρ A → record { _⟨$⟩_ = ρ ; cong = cong ρ }
-- -- ; identity = {!!} -- λ A ξ → ξ
-- -- ; homomorphism = {!!} -- λ {_} {_} {_} {ρ} {σ} A {_} {_} ξ → cong σ (cong ρ ξ)
-- -- ; F-resp-≈ = {!!} -- λ ξ A ζ → trans (ξ _) (cong _ ζ)
-- -- }
| {
"alphanum_fraction": 0.405308167,
"avg_line_length": 51.544935806,
"ext": "agda",
"hexsha": "6656c3a09a4b03f8696f2a5f988b2f865eb51fb8",
"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": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/SecondOrder/VRelativeMonad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"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": "andrejbauer/formaltt",
"max_issues_repo_path": "src/SecondOrder/VRelativeMonad.agda",
"max_line_length": 235,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejbauer/formal",
"max_stars_repo_path": "src/SecondOrder/VRelativeMonad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-18T18:21:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-18T18:21:00.000Z",
"num_tokens": 14751,
"size": 36133
} |
module Issue759a where
import Common.Level
abstract
record Wrap (A : Set) : Set where
field wrapped : A
open Wrap public
wrap : {A : Set} → A → Wrap A
wrap a = record { wrapped = a }
-- WAS: Broken error message:
-- Not in scope:
-- Issue759a.recCon-NOT-PRINTED at
-- when checking the definition of wrap
-- NOW:
-- Expected non-abstract record type, found Wrap
-- when checking that the expression record { wrapped = a } has type
-- Wrap .A
| {
"alphanum_fraction": 0.6782608696,
"avg_line_length": 18.4,
"ext": "agda",
"hexsha": "7736557b3d33c4eb2e6f196b9bdc74296c59a0e5",
"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/Issue759a.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/Issue759a.agda",
"max_line_length": 68,
"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/Issue759a.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": 126,
"size": 460
} |
open import SOAS.Common
-- Free construction with respect to a forgetful functor between categories
module SOAS.Construction.Free {ℂ 𝕊 : Category 1ℓ 0ℓ 0ℓ}
(U : Functor 𝕊 ℂ) where
open import Categories.Adjoint
import Categories.Morphism.Reasoning as MR
open import Categories.Category.Equivalence using (WeakInverse; StrongEquivalence)
open import Categories.Adjoint.Properties
open import Categories.Monad
private module ℂ = Category ℂ
private module 𝕊 = Category 𝕊
private module U = Functor U
-- Mapping from an object of the carrier category to the carrier of an object
-- from the structure category
_↪_ : ℂ.Obj → 𝕊.Obj → Set
C ↪ S = ℂ [ C , U.₀ S ]
-- Definition of F being a free structure over a carrier C:
-- any carrier map c : C → S into the carrier of a structure S factorises
-- through a unique extension of c to a structure homomorphism ĉ : F C → S:
--
-- ⌊-⌋
-- C ────────────── FC
-- ╰─────── S ───────╯
-- c ĉ
record FreeConstruction (F : ℂ.Obj → 𝕊.Obj)
(C : ℂ.Obj)
(embed : C ↪ F C)
(S : 𝕊.Obj)
(c : C ↪ S)
: Set₁ where
field
-- Given another structure S, any mapping from C to the carrier of S can be
-- extended into a structure homomorphism from F C to S.
extend : 𝕊 [ F C , S ]
-- Any map from C to the carrier of a structure S factors through the
-- embedding and extension
factor : U.₁ extend ℂ.∘ embed ℂ.≈ c
-- Extension is the unique factorising morphism
unique : (e : 𝕊 [ F C , S ])
→ (p : (U.₁ e ℂ.∘ embed) ℂ.≈ c)
→ 𝕊 [ e ≈ extend ]
record FreeMapping (F : ℂ.Obj → 𝕊.Obj) : Set₁ where
field
embed : {C : ℂ.Obj} → C ↪ F C
univ : (C : ℂ.Obj) (S : 𝕊.Obj)(c : C ↪ S)
→ FreeConstruction F C embed S c
module Universal C S c = FreeConstruction (univ C S c)
module _ {C : ℂ.Obj} {S : 𝕊.Obj}(c : C ↪ S) where
open Universal C S c public
open MR ℂ
open ℂ.HomReasoning
private module 𝕊R = 𝕊.HomReasoning
open NT
-- The uniqueness of the factors means that any two morphisms
-- that factorise the same arrow must be equal
equate : {C : ℂ.Obj}{S : 𝕊.Obj}
→ (f g : 𝕊 [ F C , S ])
→ (p : U.₁ f ℂ.∘ embed ℂ.≈ U.₁ g ℂ.∘ embed)
→ 𝕊 [ f ≈ g ]
equate f g p = unique _ f p 𝕊R.○ 𝕊R.⟺ (unique _ g ℂ.Equiv.refl)
-- Infix shorthand
[_≋_]! : {C : ℂ.Obj}{S : 𝕊.Obj}
→ (f g : 𝕊 [ F C , S ])
→ (p : U.₁ f ℂ.∘ embed ℂ.≈ U.₁ g ℂ.∘ embed)
→ 𝕊 [ f ≈ g ]
[ f ≋ g ]! p = equate f g p
-- Extensions of equal embeddings are equal
extend-cong : {C : ℂ.Obj}{S : 𝕊.Obj}(c₁ c₂ : C ↪ S)
→ ℂ [ c₁ ≈ c₂ ] → 𝕊 [ extend c₁ ≈ extend c₂ ]
extend-cong {C}{S} c₁ c₂ p = unique _ (extend c₁) (factor c₁ ○ p)
-- | Freeness makes F into a functor
map : {C D : ℂ.Obj} → C ℂ.⇒ D → F C 𝕊.⇒ F D
map {C}{D} f = extend (embed ℂ.∘ f)
embed-commute : {C D : ℂ.Obj}(f : C ℂ.⇒ D)
→ embed ℂ.∘ f ℂ.≈ (U.₁ (map f) ℂ.∘ embed)
embed-commute {C}{D} f = ⟺ (factor (embed ℂ.∘ f))
identity : {C : ℂ.Obj} → map (ℂ.id {C}) 𝕊.≈ 𝕊.id
identity {C} = 𝕊R.⟺ $ᶠ unique _ 𝕊.id (begin
U.₁ 𝕊.id ℂ.∘ embed ≈⟨ U.identity ⟩∘⟨refl ⟩
ℂ.id ℂ.∘ embed ≈⟨ id-comm-sym ⟩
embed ℂ.∘ ℂ.id ∎)
homomorphism : {C D E : ℂ.Obj} {f : ℂ [ C , D ]} {g : ℂ [ D , E ]}
→ 𝕊 [ map (ℂ [ g ∘ f ])
≈ 𝕊 [ map g ∘ map f ] ]
homomorphism {C}{D}{E}{f}{g} = 𝕊R.⟺ $ᶠ unique _ (𝕊 [ map g ∘ map f ]) (begin
U.₁ (map g 𝕊.∘ map f) ℂ.∘ embed ≈⟨ pushˡ U.homomorphism ⟩
U.₁ (map g) ℂ.∘ U.₁ (map f) ℂ.∘ embed ≈⟨ pushʳ (⟺ (embed-commute f)) ⟩
(U.₁ (map g) ℂ.∘ embed) ℂ.∘ f ≈⟨ pushˡ (⟺ (embed-commute g)) ⟩
embed ℂ.∘ g ℂ.∘ f ∎)
-- Free functor from ℂ to 𝕊
Free : Functor ℂ 𝕊
Free = record
{ F₀ = F
; F₁ = map
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = λ {C}{D}{f}{g} p →
extend-cong (embed ℂ.∘ f) (embed ℂ.∘ g) (ℂ.∘-resp-≈ʳ p)
}
module F = Functor Free
-- | Freeness also induces a free-forgetful adjunction
-- Embedding is a natural transformation
embed-NT : NT idF (U ∘F Free)
embed-NT = ntHelper record
{ η = λ C → embed
; commute = embed-commute
}
-- Extension of the identity on US is a natural transformation
extract : (S : 𝕊.Obj) → F (U.₀ S) 𝕊.⇒ S
extract S = extend ℂ.id
-- Extraction is a natural transformation
extract-NT : NT (Free ∘F U) idF
extract-NT = ntHelper record
{ η = extract
; commute = λ {S}{T} f → [ extract T 𝕊.∘ F.₁ (U.₁ f) ≋ f 𝕊.∘ extract S ]!
(begin
U.₁ (extract T 𝕊.∘ F.₁ (U.₁ f)) ℂ.∘ embed
≈⟨ pushˡ U.homomorphism ⟩
U.₁ (extract T) ℂ.∘ U.₁ (F.₁ (U.₁ f)) ℂ.∘ embed
≈⟨ refl⟩∘⟨ sym-commute embed-NT (U.₁ f) ⟩
U.₁ (extract T) ℂ.∘ embed ℂ.∘ U.₁ f
≈⟨ pullˡ (factor ℂ.id) ○ ℂ.identityˡ ⟩
U.₁ f
≈˘⟨ (refl⟩∘⟨ factor ℂ.id) ○ ℂ.identityʳ ⟩
U.₁ f ℂ.∘ U.₁ (extract S) ℂ.∘ embed
≈˘⟨ pushˡ U.homomorphism ⟩
U.₁ (f 𝕊.∘ extract S) ℂ.∘ embed
∎)
}
-- The free-forgetful adjunction arising from the universal morphisms
Free⊣Forgetful : Free ⊣ U
Free⊣Forgetful = record
{ unit = embed-NT
; counit = extract-NT
; zig = λ {C} → [ extract (F.₀ C) 𝕊.∘ F.₁ embed ≋ 𝕊.id ]!
(begin
U.₁ (extract (F.₀ C) 𝕊.∘ F.₁ embed) ℂ.∘ embed
≈⟨ pushˡ U.homomorphism ⟩
U.₁ (extract (F.₀ C)) ℂ.∘ U.₁ (F.₁ embed) ℂ.∘ embed
≈⟨ refl⟩∘⟨ (sym-commute embed-NT embed) ⟩
U.₁ (extract (F.₀ C)) ℂ.∘ (embed ℂ.∘ embed)
≈⟨ pullˡ (factor (ℂ.id)) ⟩
ℂ.id ℂ.∘ embed
≈˘⟨ U.identity ⟩∘⟨refl ⟩
U.₁ 𝕊.id ℂ.∘ embed
∎)
; zag = factor ℂ.id
}
FreeMonad : Monad ℂ
FreeMonad = adjoint⇒monad Free⊣Forgetful
| {
"alphanum_fraction": 0.5208885942,
"avg_line_length": 32.6054054054,
"ext": "agda",
"hexsha": "d34fec2a022092a6f01f5d9812bbac369cc96bb6",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "SOAS/Construction/Free.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "SOAS/Construction/Free.agda",
"max_line_length": 83,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "SOAS/Construction/Free.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 2423,
"size": 6032
} |
-- The following deeply left-nested expression illustrates both a
-- problem in a previous implementation of the occurrence machinery,
-- and a problem in the one that is current at the time of writing.
F : Set → Set
F X = (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((X → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X)) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X) → X
| {
"alphanum_fraction": 0.171728972,
"avg_line_length": 3546.2857142857,
"ext": "agda",
"hexsha": "0968ea29ca2b4e23507100d1fbdb2240a7dc7b2f",
"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": "benchmark/misc/SlowOccurrences.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": "benchmark/misc/SlowOccurrences.agda",
"max_line_length": 24605,
"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": "benchmark/misc/SlowOccurrences.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": 13357,
"size": 24824
} |
------------------------------------------------------------------------
-- Function setoids and related constructions
------------------------------------------------------------------------
module Relation.Binary.FunctionSetoid where
open import Data.Function
open import Relation.Binary
infixr 0 _↝_ _⟶_ _⇨_ _≡⇨_
-- A logical relation (i.e. a relation which relates functions which
-- map related things to related things).
_↝_ : ∀ {A B} → (∼₁ : Rel A) (∼₂ : Rel B) → Rel (A → B)
_∼₁_ ↝ _∼₂_ = λ f g → ∀ {x y} → x ∼₁ y → f x ∼₂ g y
-- Functions which preserve equality.
record _⟶_ (From To : Setoid) : Set where
open Setoid
infixl 5 _⟨$⟩_
field
_⟨$⟩_ : carrier From → carrier To
pres : _⟨$⟩_ Preserves _≈_ From ⟶ _≈_ To
open _⟶_ public
↝-isEquivalence : ∀ {A B C} {∼₁ : Rel A} {∼₂ : Rel B}
(fun : C → (A → B)) →
(∀ f → fun f Preserves ∼₁ ⟶ ∼₂) →
IsEquivalence ∼₁ → IsEquivalence ∼₂ →
IsEquivalence ((∼₁ ↝ ∼₂) on₁ fun)
↝-isEquivalence _ pres eq₁ eq₂ = record
{ refl = λ {f} x∼₁y → pres f x∼₁y
; sym = λ f∼g x∼y → sym eq₂ (f∼g (sym eq₁ x∼y))
; trans = λ f∼g g∼h x∼y → trans eq₂ (f∼g (refl eq₁)) (g∼h x∼y)
} where open IsEquivalence
-- Function setoids.
_⇨_ : Setoid → Setoid → Setoid
S₁ ⇨ S₂ = record
{ carrier = S₁ ⟶ S₂
; _≈_ = (_≈_ S₁ ↝ _≈_ S₂) on₁ _⟨$⟩_
; isEquivalence =
↝-isEquivalence _⟨$⟩_ pres (isEquivalence S₁) (isEquivalence S₂)
} where open Setoid; open _⟶_
-- A generalised variant of (_↝_ _≡_).
≡↝ : ∀ {A} {B : A → Set} → (∀ x → Rel (B x)) → Rel ((x : A) → B x)
≡↝ R = λ f g → ∀ x → R x (f x) (g x)
≡↝-isEquivalence : {A : Set} {B : A → Set} {R : ∀ x → Rel (B x)} →
(∀ x → IsEquivalence (R x)) → IsEquivalence (≡↝ R)
≡↝-isEquivalence eq = record
{ refl = λ _ → refl
; sym = λ f∼g x → sym (f∼g x)
; trans = λ f∼g g∼h x → trans (f∼g x) (g∼h x)
} where open module Eq {x} = IsEquivalence (eq x)
_≡⇨_ : (A : Set) → (A → Setoid) → Setoid
A ≡⇨ S = record
{ carrier = (x : A) → carrier (S x)
; _≈_ = ≡↝ (λ x → _≈_ (S x))
; isEquivalence = ≡↝-isEquivalence (λ x → isEquivalence (S x))
} where open Setoid
| {
"alphanum_fraction": 0.4993209597,
"avg_line_length": 32.0144927536,
"ext": "agda",
"hexsha": "c7f9f404c7d6ad394e8c10391f94aa9aa444e723",
"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/Relation/Binary/FunctionSetoid.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/Relation/Binary/FunctionSetoid.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/Relation/Binary/FunctionSetoid.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": 896,
"size": 2209
} |
------------------------------------------------------------------------
-- A binary representation of natural numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
import Erased.Without-box-cong
module Nat.Binary
{c⁺}
(eq : ∀ {a p} → Equality-with-J a p c⁺)
-- An instantiation of the []-cong axioms.
(ax : ∀ {a} → Erased.Without-box-cong.[]-cong-axiomatisation eq a)
where
open Derived-definitions-and-properties eq
open import Dec
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (suc; _^_) renaming (_+_ to _⊕_; _*_ to _⊛_)
open import Bijection eq using (_↔_)
open import Equality.Decision-procedures eq
open import Erased eq ax
open import Function-universe eq hiding (id; _∘_)
open import List eq
open import Nat.Solver eq
import Nat.Wrapper eq as Wrapper
open import Surjection eq using (_↠_)
private
module N where
open import Nat eq public
open Prelude public using (zero; suc; _^_)
variable
A : Type
inv n : A
b : Bool
bs : List Bool
------------------------------------------------------------------------
-- The underlying representation
private
module Bin′ where
abstract
-- The underlying representation of binary natural numbers. The
-- least significant digit comes first; true stands for one and
-- false for zero. Leading zeros (at the end of the lists) are
-- not allowed.
--
-- The type is abstract to ensure that a change to a different
-- representation does not break code that uses this module.
mutual
infixr 5 _∷_
data Bin′ : Type where
[] : Bin′
_∷_ : (b : Bool) (n : Bin′)
{ @0 invariant : Invariant b n } → Bin′
private
Invariant : Bool → Bin′ → Type
Invariant true _ = ⊤
Invariant false (_ ∷ _) = ⊤
Invariant false [] = ⊥
-- A variant of _∷_ with three explicit arguments.
pattern _∷_⟨_⟩ b n inv = _∷_ b n {invariant = inv}
-- Synonyms that can be used in type signatures (Bin′ is
-- abstract, so the constructors cannot be used there).
[]′ : Bin′
[]′ = []
_∷_⟨_⟩′ : (b : Bool) (n : Bin′) → @0 Invariant b n → Bin′
_∷_⟨_⟩′ = _∷_⟨_⟩
private
-- The underlying list.
to-List : Bin′ → List Bool
to-List [] = []
to-List (b ∷ bs) = b ∷ to-List bs
-- The invariant implies that the last element in the
-- underlying list, if any, is not false, so there are no
-- leading zeros in the number.
invariant-correct : ∀ n bs → ¬ to-List n ≡ bs ++ false ∷ []
invariant-correct [] bs =
[] ≡ bs ++ false ∷ [] ↝⟨ []≢++∷ bs ⟩□
⊥ □
invariant-correct (true ∷ n) [] =
true ∷ to-List n ≡ false ∷ [] ↝⟨ List.cancel-∷-head ⟩
true ≡ false ↝⟨ Bool.true≢false ⟩□
⊥ □
invariant-correct (false ∷ n@(_ ∷ _)) [] =
false ∷ to-List n ≡ false ∷ [] ↝⟨ List.cancel-∷-tail ⟩
to-List n ≡ [] ↝⟨ List.[]≢∷ ∘ sym ⟩□
⊥ □
invariant-correct (b ∷ n) (b′ ∷ bs) =
b ∷ to-List n ≡ b′ ∷ bs ++ false ∷ [] ↝⟨ List.cancel-∷-tail ⟩
to-List n ≡ bs ++ false ∷ [] ↝⟨ invariant-correct n bs ⟩□
⊥ □
-- The invariant is propositional.
Invariant-propositional :
{b : Bool} {n : Bin′} → Is-proposition (Invariant b n)
Invariant-propositional {b = true} _ _ = refl _
Invariant-propositional {b = false} {n = _ ∷ _} _ _ = refl _
-- Converts from Bool to ℕ.
from-Bool : Bool → ℕ
from-Bool = if_then 1 else 0
-- Converts from List Bool to ℕ.
List-to-ℕ : List Bool → ℕ
List-to-ℕ = foldr (λ b n → from-Bool b ⊕ 2 ⊛ n) 0
-- Converts from Bin′ to ℕ.
to-ℕ′ : Bin′ → ℕ
to-ℕ′ = List-to-ℕ ∘ to-List
private
-- A smart constructor.
infixr 5 _∷ˢ_
_∷ˢ_ : Bool → Bin′ → Bin′
true ∷ˢ n = true ∷ n
false ∷ˢ [] = []
false ∷ˢ n@(_ ∷ _) = false ∷ n
-- A lemma relating to-ℕ′ and _∷ˢ_.
to-ℕ′-∷ˢ : ∀ b n → to-ℕ′ (b ∷ˢ n) ≡ from-Bool b ⊕ 2 ⊛ to-ℕ′ n
to-ℕ′-∷ˢ true _ = refl _
to-ℕ′-∷ˢ false [] = refl _
to-ℕ′-∷ˢ false (_ ∷ _) = refl _
-- Zero.
zero′ : Bin′
zero′ = []
-- A lemma relating zero′ and N.zero.
to-ℕ′-zero′ : to-ℕ′ zero′ ≡ N.zero
to-ℕ′-zero′ = refl _
-- The number's successor.
suc′ : Bin′ → Bin′
suc′ [] = true ∷ˢ []
suc′ (false ∷ n) = true ∷ˢ n
suc′ (true ∷ n) = false ∷ˢ suc′ n
private
-- The successor of the smart cons constructor applied to
-- false and n is the smart cons constructor applied to true
-- and n.
suc′-false-∷ˢ : ∀ n → suc′ (false ∷ˢ n) ≡ true ∷ˢ n
suc′-false-∷ˢ [] = refl _
suc′-false-∷ˢ (_ ∷ _) = refl _
-- A lemma relating suc′ and N.suc.
to-ℕ′-suc′ : ∀ bs → to-ℕ′ (suc′ bs) ≡ N.suc (to-ℕ′ bs)
to-ℕ′-suc′ [] = refl _
to-ℕ′-suc′ n@(false ∷ n′) =
to-ℕ′ (suc′ n) ≡⟨⟩
to-ℕ′ (true ∷ˢ n′) ≡⟨ to-ℕ′-∷ˢ true n′ ⟩
1 ⊕ 2 ⊛ to-ℕ′ n′ ≡⟨⟩
N.suc (to-ℕ′ n) ∎
to-ℕ′-suc′ n@(true ∷ n′) =
to-ℕ′ (suc′ n) ≡⟨⟩
to-ℕ′ (false ∷ˢ suc′ n′) ≡⟨ to-ℕ′-∷ˢ false (suc′ n′) ⟩
2 ⊛ to-ℕ′ (suc′ n′) ≡⟨ cong (2 ⊛_) (to-ℕ′-suc′ n′) ⟩
2 ⊛ N.suc (to-ℕ′ n′) ≡⟨ solve 1 (λ n → con 2 :* (con 1 :+ n) := con 2 :+ con 2 :* n) (refl _) _ ⟩
2 ⊕ 2 ⊛ to-ℕ′ n′ ≡⟨⟩
N.suc (to-ℕ′ n) ∎
private
-- Converts from ℕ to Bin′.
from-ℕ′ : ℕ → Bin′
from-ℕ′ zero = []
from-ℕ′ (N.suc n) = suc′ (from-ℕ′ n)
-- The function from-ℕ′ commutes with "multiplication by two".
from-ℕ′-2-⊛ : ∀ n → from-ℕ′ (2 ⊛ n) ≡ false ∷ˢ from-ℕ′ n
from-ℕ′-2-⊛ zero = refl _
from-ℕ′-2-⊛ (N.suc n) =
from-ℕ′ (2 ⊛ N.suc n) ≡⟨⟩
suc′ (from-ℕ′ (n ⊕ N.suc (n ⊕ 0))) ≡⟨ cong (suc′ ∘ from-ℕ′) $ sym $ N.suc+≡+suc n ⟩
suc′ (from-ℕ′ (N.suc (2 ⊛ n))) ≡⟨⟩
suc′ (suc′ (from-ℕ′ (2 ⊛ n))) ≡⟨ cong (suc′ ∘ suc′) (from-ℕ′-2-⊛ n) ⟩
suc′ (suc′ (false ∷ˢ from-ℕ′ n)) ≡⟨ cong suc′ (suc′-false-∷ˢ (from-ℕ′ n)) ⟩
suc′ (true ∷ˢ from-ℕ′ n) ≡⟨⟩
false ∷ˢ suc′ (from-ℕ′ n) ≡⟨⟩
false ∷ˢ from-ℕ′ (N.suc n) ∎
-- There is a bijection from Bin′ to ℕ.
Bin′↔ℕ : Bin′ ↔ ℕ
Bin′↔ℕ = record
{ surjection = record
{ logical-equivalence = record
{ to = to-ℕ′
; from = from-ℕ′
}
; right-inverse-of = to-ℕ′∘from-ℕ′
}
; left-inverse-of = from-ℕ′∘to-ℕ′
}
where
abstract
to-ℕ′∘from-ℕ′ : ∀ n → to-ℕ′ (from-ℕ′ n) ≡ n
to-ℕ′∘from-ℕ′ zero = refl _
to-ℕ′∘from-ℕ′ (N.suc n) =
to-ℕ′ (from-ℕ′ (N.suc n)) ≡⟨⟩
to-ℕ′ (suc′ (from-ℕ′ n)) ≡⟨ to-ℕ′-suc′ (from-ℕ′ n) ⟩
N.suc (to-ℕ′ (from-ℕ′ n)) ≡⟨ cong N.suc (to-ℕ′∘from-ℕ′ n) ⟩∎
N.suc n ∎
from-ℕ′∘to-ℕ′ : ∀ n → from-ℕ′ (to-ℕ′ n) ≡ n
from-ℕ′∘to-ℕ′ [] = refl _
from-ℕ′∘to-ℕ′ n@(true ∷ n′) =
from-ℕ′ (to-ℕ′ n) ≡⟨⟩
from-ℕ′ (1 ⊕ 2 ⊛ to-ℕ′ n′) ≡⟨⟩
suc′ (from-ℕ′ (2 ⊛ to-ℕ′ n′)) ≡⟨ cong suc′ (from-ℕ′-2-⊛ (to-ℕ′ n′)) ⟩
suc′ (false ∷ˢ from-ℕ′ (to-ℕ′ n′)) ≡⟨ cong (suc′ ∘ (false ∷ˢ_)) (from-ℕ′∘to-ℕ′ n′) ⟩
suc′ (false ∷ˢ n′) ≡⟨ suc′-false-∷ˢ n′ ⟩
true ∷ˢ n′ ≡⟨⟩
n ∎
from-ℕ′∘to-ℕ′ n@(false ∷ n′@(_ ∷ _)) =
from-ℕ′ (to-ℕ′ n) ≡⟨⟩
from-ℕ′ (2 ⊛ to-ℕ′ n′) ≡⟨ from-ℕ′-2-⊛ (to-ℕ′ n′) ⟩
false ∷ˢ from-ℕ′ (to-ℕ′ n′) ≡⟨ cong (false ∷ˢ_) (from-ℕ′∘to-ℕ′ n′) ⟩
false ∷ˢ n′ ≡⟨⟩
n ∎
abstract
private
-- Helper functions used to implement addition.
add-with-carryᴮ : Bool → Bool → Bool → Bool × Bool
add-with-carryᴮ false false false = false , false
add-with-carryᴮ false false true = true , false
add-with-carryᴮ false true false = true , false
add-with-carryᴮ false true true = false , true
add-with-carryᴮ true false false = true , false
add-with-carryᴮ true false true = false , true
add-with-carryᴮ true true false = false , true
add-with-carryᴮ true true true = true , true
add-with-carry₁ : Bool → Bin′ → Bin′
add-with-carry₁ false = id
add-with-carry₁ true = suc′
add-with-carry₂ : Bool → Bin′ → Bin′ → Bin′
add-with-carry₂ b [] n = add-with-carry₁ b n
add-with-carry₂ b m@(_ ∷ _) [] = add-with-carry₁ b m
add-with-carry₂ b (c ∷ m) (d ∷ n) =
case add-with-carryᴮ b c d of λ where
(e , f) → e ∷ˢ add-with-carry₂ f m n
to-ℕ′-add-with-carry₁ :
∀ b cs →
to-ℕ′ (add-with-carry₁ b cs) ≡
from-Bool b ⊕ to-ℕ′ cs
to-ℕ′-add-with-carry₁ false n = refl _
to-ℕ′-add-with-carry₁ true n = to-ℕ′-suc′ n
to-ℕ′-add-with-carry₂ :
∀ b m n →
to-ℕ′ (add-with-carry₂ b m n) ≡
from-Bool b ⊕ (to-ℕ′ m ⊕ to-ℕ′ n)
to-ℕ′-add-with-carry₂ b [] n = to-ℕ′-add-with-carry₁ b n
to-ℕ′-add-with-carry₂ b m@(_ ∷ _) [] =
to-ℕ′ (add-with-carry₁ b m) ≡⟨ to-ℕ′-add-with-carry₁ b m ⟩
from-Bool b ⊕ to-ℕ′ m ≡⟨ solve 2 (λ b c → b :+ c := b :+ (c :+ con 0)) (refl _) (from-Bool b) _ ⟩
from-Bool b ⊕ (to-ℕ′ m ⊕ 0) ≡⟨⟩
from-Bool b ⊕ (to-ℕ′ m ⊕ to-ℕ′ []) ∎
to-ℕ′-add-with-carry₂ false m@(false ∷ m′) n@(false ∷ n′) =
to-ℕ′ (false ∷ˢ add-with-carry₂ false m′ n′) ≡⟨ to-ℕ′-∷ˢ false (add-with-carry₂ false m′ n′) ⟩
2 ⊛ to-ℕ′ (add-with-carry₂ false m′ n′) ≡⟨ cong (2 ⊛_) (to-ℕ′-add-with-carry₂ false m′ n′) ⟩
2 ⊛ (to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 2 :* (c :+ d) :=
con 2 :* c :+ con 2 :* d)
(refl _) (to-ℕ′ m′) _ ⟩
2 ⊛ to-ℕ′ m′ ⊕ 2 ⊛ to-ℕ′ n′ ≡⟨⟩
to-ℕ′ m ⊕ to-ℕ′ n ∎
to-ℕ′-add-with-carry₂ false m@(false ∷ m′) n@(true ∷ n′) =
to-ℕ′ (true ∷ˢ add-with-carry₂ false m′ n′) ≡⟨ to-ℕ′-∷ˢ true (add-with-carry₂ false m′ n′) ⟩
1 ⊕ 2 ⊛ to-ℕ′ (add-with-carry₂ false m′ n′) ≡⟨ cong ((1 ⊕_) ∘ (2 ⊛_)) (to-ℕ′-add-with-carry₂ false m′ n′) ⟩
1 ⊕ 2 ⊛ (to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 1 :+ con 2 :* (c :+ d) :=
con 2 :* c :+ (con 1 :+ con 2 :* d))
(refl _) (to-ℕ′ m′) _ ⟩
2 ⊛ to-ℕ′ m′ ⊕ (1 ⊕ 2 ⊛ to-ℕ′ n′) ≡⟨⟩
to-ℕ′ m ⊕ to-ℕ′ n ∎
to-ℕ′-add-with-carry₂ false m@(true ∷ m′) n@(false ∷ n′) =
to-ℕ′ (true ∷ˢ add-with-carry₂ false m′ n′) ≡⟨ to-ℕ′-∷ˢ true (add-with-carry₂ false m′ n′) ⟩
1 ⊕ 2 ⊛ to-ℕ′ (add-with-carry₂ false m′ n′) ≡⟨ cong ((1 ⊕_) ∘ (2 ⊛_)) (to-ℕ′-add-with-carry₂ false m′ n′) ⟩
1 ⊕ 2 ⊛ (to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 1 :+ con 2 :* (c :+ d) :=
con 1 :+ con 2 :* c :+ con 2 :* d)
(refl _) (to-ℕ′ m′) _ ⟩
1 ⊕ 2 ⊛ to-ℕ′ m′ ⊕ 2 ⊛ to-ℕ′ n′ ≡⟨⟩
to-ℕ′ m ⊕ to-ℕ′ n ∎
to-ℕ′-add-with-carry₂ false m@(true ∷ m′) n@(true ∷ n′) =
to-ℕ′ (false ∷ˢ add-with-carry₂ true m′ n′) ≡⟨ to-ℕ′-∷ˢ false (add-with-carry₂ true m′ n′) ⟩
2 ⊛ to-ℕ′ (add-with-carry₂ true m′ n′) ≡⟨ cong (2 ⊛_) (to-ℕ′-add-with-carry₂ true m′ n′) ⟩
2 ⊛ (1 ⊕ to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 2 :* (con 1 :+ c :+ d) :=
con 1 :+ con 2 :* c :+ (con 1 :+ con 2 :* d))
(refl _) (to-ℕ′ m′) _ ⟩
1 ⊕ 2 ⊛ to-ℕ′ m′ ⊕ (1 ⊕ 2 ⊛ to-ℕ′ n′) ≡⟨⟩
to-ℕ′ m ⊕ to-ℕ′ n ∎
to-ℕ′-add-with-carry₂ true m@(false ∷ m′) n@(false ∷ n′) =
to-ℕ′ (true ∷ˢ add-with-carry₂ false m′ n′) ≡⟨ to-ℕ′-∷ˢ true (add-with-carry₂ false m′ n′) ⟩
1 ⊕ 2 ⊛ to-ℕ′ (add-with-carry₂ false m′ n′) ≡⟨ cong ((1 ⊕_) ∘ (2 ⊛_)) (to-ℕ′-add-with-carry₂ false m′ n′) ⟩
1 ⊕ 2 ⊛ (to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 1 :+ con 2 :* (c :+ d) :=
con 1 :+ con 2 :* c :+ con 2 :* d)
(refl _) (to-ℕ′ m′) _ ⟩
1 ⊕ 2 ⊛ to-ℕ′ m′ ⊕ 2 ⊛ to-ℕ′ n′ ≡⟨⟩
1 ⊕ to-ℕ′ m ⊕ to-ℕ′ n ∎
to-ℕ′-add-with-carry₂ true m@(false ∷ m′) n@(true ∷ n′) =
to-ℕ′ (false ∷ˢ add-with-carry₂ true m′ n′) ≡⟨ to-ℕ′-∷ˢ false (add-with-carry₂ true m′ n′) ⟩
2 ⊛ to-ℕ′ (add-with-carry₂ true m′ n′) ≡⟨ cong (2 ⊛_) (to-ℕ′-add-with-carry₂ true m′ n′) ⟩
2 ⊛ (1 ⊕ to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 2 :* (con 1 :+ c :+ d) :=
con 1 :+ con 2 :* c :+ (con 1 :+ con 2 :* d))
(refl _) (to-ℕ′ m′) _ ⟩
1 ⊕ 2 ⊛ to-ℕ′ m′ ⊕ (1 ⊕ 2 ⊛ to-ℕ′ n′) ≡⟨⟩
1 ⊕ to-ℕ′ m ⊕ to-ℕ′ n ∎
to-ℕ′-add-with-carry₂ true m@(true ∷ m′) n@(false ∷ n′) =
to-ℕ′ (false ∷ˢ add-with-carry₂ true m′ n′) ≡⟨ to-ℕ′-∷ˢ false (add-with-carry₂ true m′ n′) ⟩
2 ⊛ to-ℕ′ (add-with-carry₂ true m′ n′) ≡⟨ cong (2 ⊛_) (to-ℕ′-add-with-carry₂ true m′ n′) ⟩
2 ⊛ (1 ⊕ to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 2 :* (con 1 :+ c :+ d) :=
con 2 :+ con 2 :* c :+ con 2 :* d)
(refl _) (to-ℕ′ m′) _ ⟩
2 ⊕ 2 ⊛ to-ℕ′ m′ ⊕ 2 ⊛ to-ℕ′ n′ ≡⟨⟩
1 ⊕ to-ℕ′ m ⊕ to-ℕ′ n ∎
to-ℕ′-add-with-carry₂ true m@(true ∷ m′) n@(true ∷ n′) =
to-ℕ′ (true ∷ˢ add-with-carry₂ true m′ n′) ≡⟨ to-ℕ′-∷ˢ true (add-with-carry₂ true m′ n′) ⟩
1 ⊕ 2 ⊛ to-ℕ′ (add-with-carry₂ true m′ n′) ≡⟨ cong ((1 ⊕_) ∘ (2 ⊛_)) (to-ℕ′-add-with-carry₂ true m′ n′) ⟩
1 ⊕ 2 ⊛ (1 ⊕ to-ℕ′ m′ ⊕ to-ℕ′ n′) ≡⟨ solve 2 (λ c d → con 1 :+ con 2 :* (con 1 :+ c :+ d) :=
con 2 :+ con 2 :* c :+ (con 1 :+ con 2 :* d))
(refl _) (to-ℕ′ m′) _ ⟩
2 ⊕ 2 ⊛ to-ℕ′ m′ ⊕ (1 ⊕ 2 ⊛ to-ℕ′ n′) ≡⟨⟩
1 ⊕ to-ℕ′ m ⊕ to-ℕ′ n ∎
-- Addition.
add-with-carry : Bin′ → Bin′ → Bin′
add-with-carry = add-with-carry₂ false
to-ℕ′-add-with-carry :
∀ m n →
to-ℕ′ (add-with-carry m n) ≡
to-ℕ′ m ⊕ to-ℕ′ n
to-ℕ′-add-with-carry = to-ℕ′-add-with-carry₂ false
-- Division by two, rounded downwards.
⌊_/2⌋ : Bin′ → Bin′
⌊ [] /2⌋ = []
⌊ _ ∷ n /2⌋ = n
to-ℕ′-⌊/2⌋ : ∀ n → to-ℕ′ ⌊ n /2⌋ ≡ N.⌊ to-ℕ′ n /2⌋
to-ℕ′-⌊/2⌋ [] = refl _
to-ℕ′-⌊/2⌋ (false ∷ n) =
to-ℕ′ n ≡⟨ sym $ N.⌊2*/2⌋≡ _ ⟩∎
N.⌊ 2 ⊛ to-ℕ′ n /2⌋ ∎
to-ℕ′-⌊/2⌋ (true ∷ n) =
to-ℕ′ n ≡⟨ sym $ N.⌊1+2*/2⌋≡ _ ⟩∎
N.⌊ 1 ⊕ 2 ⊛ to-ℕ′ n /2⌋ ∎
-- Division by two, rounded upwards.
⌈_/2⌉ : Bin′ → Bin′
⌈ [] /2⌉ = []
⌈ false ∷ n /2⌉ = n
⌈ true ∷ n /2⌉ = suc′ n
to-ℕ′-⌈/2⌉ : ∀ n → to-ℕ′ ⌈ n /2⌉ ≡ N.⌈ to-ℕ′ n /2⌉
to-ℕ′-⌈/2⌉ [] = refl _
to-ℕ′-⌈/2⌉ (false ∷ n) =
to-ℕ′ n ≡⟨ sym $ N.⌈2*/2⌉≡ _ ⟩∎
N.⌈ 2 ⊛ to-ℕ′ n /2⌉ ∎
to-ℕ′-⌈/2⌉ (true ∷ n) =
to-ℕ′ (suc′ n) ≡⟨ to-ℕ′-suc′ n ⟩
1 ⊕ to-ℕ′ n ≡⟨ sym $ N.⌈1+2*/2⌉≡ _ ⟩∎
N.⌈ 1 ⊕ 2 ⊛ to-ℕ′ n /2⌉ ∎
-- Multiplication.
infixl 7 _*_
_*_ : Bin′ → Bin′ → Bin′
[] * n = zero′
(b ∷ m) * n =
(if b then add-with-carry n else id)
(false ∷ˢ m * n)
to-ℕ′-* : ∀ m n → to-ℕ′ (m * n) ≡ to-ℕ′ m ⊛ to-ℕ′ n
to-ℕ′-* [] n = refl _
to-ℕ′-* (false ∷ m ⟨ inv ⟩) n =
to-ℕ′ (false ∷ˢ m * n) ≡⟨ to-ℕ′-∷ˢ false (m * n) ⟩
2 ⊛ to-ℕ′ (m * n) ≡⟨ cong (2 ⊛_) (to-ℕ′-* m _) ⟩
2 ⊛ (to-ℕ′ m ⊛ to-ℕ′ n) ≡⟨ N.*-assoc 2 {n = to-ℕ′ m} ⟩
(2 ⊛ to-ℕ′ m) ⊛ to-ℕ′ n ≡⟨⟩
to-ℕ′ (false ∷ m ⟨ inv ⟩) ⊛ to-ℕ′ n ∎
to-ℕ′-* (true ∷ m) n =
to-ℕ′ (add-with-carry n (false ∷ˢ m * n)) ≡⟨ to-ℕ′-add-with-carry n _ ⟩
to-ℕ′ n ⊕ to-ℕ′ (false ∷ˢ m * n) ≡⟨ cong (to-ℕ′ n ⊕_) (to-ℕ′-∷ˢ false (m * n)) ⟩
to-ℕ′ n ⊕ 2 ⊛ to-ℕ′ (m * n) ≡⟨ cong (λ x → to-ℕ′ n ⊕ 2 ⊛ x) (to-ℕ′-* m _) ⟩
to-ℕ′ n ⊕ 2 ⊛ (to-ℕ′ m ⊛ to-ℕ′ n) ≡⟨ solve 2 (λ m n → n :+ con 2 :* (m :* n) :=
(con 1 :+ con 2 :* m) :* n)
(refl _) (to-ℕ′ m) _ ⟩
(1 ⊕ 2 ⊛ to-ℕ′ m) ⊛ to-ℕ′ n ≡⟨⟩
to-ℕ′ (true ∷ m) ⊛ to-ℕ′ n ∎
-- Exponentiation.
infixr 8 _^_
_^_ : Bin′ → Bin′ → Bin′
m ^ [] = suc′ zero′
m ^ (b ∷ n) =
(if b then (m *_) else id)
((m * m) ^ n)
to-ℕ′-^ : ∀ m n → to-ℕ′ (m ^ n) ≡ to-ℕ′ m N.^ to-ℕ′ n
to-ℕ′-^ m [] = refl _
to-ℕ′-^ m (false ∷ n ⟨ inv ⟩) =
to-ℕ′ (m ^ (false ∷ n ⟨ inv ⟩)) ≡⟨⟩
to-ℕ′ ((m * m) ^ n) ≡⟨ to-ℕ′-^ (m * m) n ⟩
to-ℕ′ (m * m) N.^ to-ℕ′ n ≡⟨ cong (N._^ to-ℕ′ n) (to-ℕ′-* m m) ⟩
(to-ℕ′ m ⊛ to-ℕ′ m) N.^ to-ℕ′ n ≡⟨ cong (λ x → (to-ℕ′ m ⊛ x) N.^ to-ℕ′ n) (sym (N.*-right-identity (to-ℕ′ m))) ⟩
(to-ℕ′ m N.^ 2) N.^ to-ℕ′ n ≡⟨ N.^^≡^* 2 {k = to-ℕ′ n} ⟩
to-ℕ′ m N.^ (2 ⊛ to-ℕ′ n) ≡⟨⟩
to-ℕ′ m N.^ to-ℕ′ (false ∷ n ⟨ inv ⟩) ∎
to-ℕ′-^ m (true ∷ n) =
to-ℕ′ (m ^ (true ∷ n)) ≡⟨⟩
to-ℕ′ (m * (m * m) ^ n) ≡⟨ to-ℕ′-* m ((m * m) ^ n) ⟩
to-ℕ′ m ⊛ to-ℕ′ ((m * m) ^ n) ≡⟨ cong (to-ℕ′ m ⊛_) (to-ℕ′-^ (m * m) n) ⟩
to-ℕ′ m ⊛ to-ℕ′ (m * m) N.^ to-ℕ′ n ≡⟨ cong (λ x → to-ℕ′ m ⊛ x N.^ to-ℕ′ n) (to-ℕ′-* m m) ⟩
to-ℕ′ m ⊛ (to-ℕ′ m ⊛ to-ℕ′ m) N.^ to-ℕ′ n ≡⟨ cong (λ x → to-ℕ′ m ⊛ (to-ℕ′ m ⊛ x) N.^ to-ℕ′ n) (sym (N.*-right-identity (to-ℕ′ m))) ⟩
to-ℕ′ m ⊛ (to-ℕ′ m N.^ 2) N.^ to-ℕ′ n ≡⟨ cong₂ _⊛_ (sym (N.^-right-identity {n = to-ℕ′ m})) (N.^^≡^* 2 {k = to-ℕ′ n}) ⟩
to-ℕ′ m N.^ 1 ⊛ to-ℕ′ m N.^ (2 ⊛ to-ℕ′ n) ≡⟨ sym $ N.^+≡^*^ {m = to-ℕ′ m} 1 {k = 2 ⊛ to-ℕ′ n} ⟩
to-ℕ′ m N.^ (1 ⊕ 2 ⊛ to-ℕ′ n) ≡⟨⟩
to-ℕ′ m N.^ to-ℕ′ (true ∷ n) ∎
-- "Left shift".
infixl 8 _*2^_
_*2^_ : Bin′ → ℕ → Bin′
m *2^ zero = m
m *2^ N.suc n = (false ∷ˢ m) *2^ n
to-ℕ′-*2^ :
∀ m n →
to-ℕ′ (m *2^ n) ≡
to-ℕ′ m ⊛ 2 N.^ n
to-ℕ′-*2^ m zero =
to-ℕ′ m ≡⟨ sym $ N.*-right-identity _ ⟩∎
to-ℕ′ m ⊛ 1 ∎
to-ℕ′-*2^ m (N.suc n) =
to-ℕ′ ((false ∷ˢ m) *2^ n) ≡⟨ to-ℕ′-*2^ (false ∷ˢ m) n ⟩
to-ℕ′ (false ∷ˢ m) ⊛ 2 N.^ n ≡⟨ cong (_⊛ _) $ to-ℕ′-∷ˢ false m ⟩
2 ⊛ to-ℕ′ m ⊛ 2 N.^ n ≡⟨ cong (_⊛ (2 N.^ n)) $ N.*-comm 2 {n = to-ℕ′ m} ⟩
to-ℕ′ m ⊛ 2 ⊛ 2 N.^ n ≡⟨ sym $ N.*-assoc (to-ℕ′ m) ⟩∎
to-ℕ′ m ⊛ 2 N.^ N.suc n ∎
private
-- The empty list is not equal to any non-empty list.
[]≢∷ : []′ ≢ b ∷ n ⟨ inv ⟩′
[]≢∷ {b = b} {n = n} =
[] ≡ b ∷ n ↝⟨ cong to-List ⟩
[] ≡ b ∷ to-List n ↝⟨ List.[]≢∷ ⟩□
⊥ □
-- Equality is decidable for Bin′.
--
-- This definition uses Dec-Erased instead of Dec ∘ Erased
-- because I thought this made the code a little less
-- complicated.
equal? : (m n : Bin′) → Dec-Erased (m ≡ n)
equal? [] [] = yes [ refl _ ]
equal? [] (b ∷ n) = no [ []≢∷ ]
equal? (b ∷ n) [] = no [ []≢∷ ∘ sym ]
equal? (b₁ ∷ n₁) (b₂ ∷ n₂) =
helper₁ _ _ (b₁ Bool.≟ b₂)
where
helper₂ :
∀ n₁ n₂
(@0 inv₁ : Invariant b₁ n₁) (@0 inv₂ : Invariant b₂ n₂) →
b₁ ≡ b₂ →
Dec-Erased (n₁ ≡ n₂) →
Dec-Erased ((b₁ ∷ n₁ ⟨ inv₁ ⟩′) ≡ (b₂ ∷ n₂ ⟨ inv₂ ⟩′))
helper₂ n₁ n₂ _ _ _ (no [ n₁≢n₂ ]) = no [
(b₁ ∷ n₁ ⟨ _ ⟩) ≡ (b₂ ∷ n₂ ⟨ _ ⟩) ↝⟨ cong to-List ⟩
b₁ ∷ to-List n₁ ≡ b₂ ∷ to-List n₂ ↝⟨ List.cancel-∷-tail ⟩
to-List n₁ ≡ to-List n₂ ↝⟨ cong List-to-ℕ ⟩
to-ℕ′ n₁ ≡ to-ℕ′ n₂ ↝⟨ _↔_.injective Bin′↔ℕ ⟩
n₁ ≡ n₂ ↝⟨ n₁≢n₂ ⟩□
⊥ □ ]
helper₂ n₁ n₂ inv₁ inv₂ b₁≡b₂ (yes [ n₁≡n₂ ]) = yes [ $⟨ b₁≡b₂ , n₁≡n₂ ⟩
b₁ ≡ b₂ × n₁ ≡ n₂ ↝⟨ Σ-map id (cong to-List) ⟩
b₁ ≡ b₂ × to-List n₁ ≡ to-List n₂ ↔⟨ inverse ∷≡∷↔≡×≡ ⟩
b₁ ∷ to-List n₁ ≡ b₂ ∷ to-List n₂ ↝⟨ cong List-to-ℕ ⟩
to-ℕ′ (b₁ ∷ n₁ ⟨ inv₁ ⟩) ≡ to-ℕ′ (b₂ ∷ n₂ ⟨ inv₂ ⟩) ↝⟨ _↔_.injective Bin′↔ℕ ⟩□
b₁ ∷ n₁ ≡ b₂ ∷ n₂ □ ]
helper₁ :
∀ n₁ n₂
{@0 inv₁ : Invariant b₁ n₁} {@0 inv₂ : Invariant b₂ n₂} →
Dec (b₁ ≡ b₂) →
Dec-Erased ((b₁ ∷ n₁ ⟨ inv₁ ⟩′) ≡ (b₂ ∷ n₂ ⟨ inv₂ ⟩′))
helper₁ n₁ n₂ (yes b₁≡b₂) =
helper₂ _ _ _ _ b₁≡b₂ (equal? n₁ n₂)
helper₁ n₁ n₂ (no b₁≢b₂) = no [
b₁ ∷ n₁ ≡ b₂ ∷ n₂ ↝⟨ cong to-List ⟩
b₁ ∷ to-List n₁ ≡ b₂ ∷ to-List n₂ ↝⟨ List.cancel-∷-head ⟩
b₁ ≡ b₂ ↝⟨ b₁≢b₂ ⟩□
⊥ □ ]
-- An equality test.
infix 4 _≟_
_≟_ : (m n : Bin′) → Dec (Erased (to-ℕ′ m ≡ to-ℕ′ n))
m ≟ n = $⟨ equal? m n ⟩
Dec-Erased (m ≡ n) ↝⟨ Dec-Erased-map lemma ⟩
Dec-Erased (to-ℕ′ m ≡ to-ℕ′ n) ↝⟨ Dec-Erased↔Dec-Erased _ ⟩□
Dec (Erased (to-ℕ′ m ≡ to-ℕ′ n)) □
where
lemma : m ≡ n ⇔ to-ℕ′ m ≡ to-ℕ′ n
lemma = record { to = cong to-ℕ′; from = _↔_.injective Bin′↔ℕ }
private
-- A lemma used to prove that from-bits and to-bits are
-- correct.
to-ℕ′-foldr-∷ˢ-[] :
∀ bs →
to-ℕ′ (foldr _∷ˢ_ []′ bs) ≡
foldr (λ b n → from-Bool b ⊕ 2 ⊛ n) 0 bs
to-ℕ′-foldr-∷ˢ-[] [] = refl _
to-ℕ′-foldr-∷ˢ-[] (b ∷ bs) =
to-ℕ′ (foldr _∷ˢ_ [] (b ∷ bs)) ≡⟨⟩
to-ℕ′ (b ∷ˢ foldr _∷ˢ_ [] bs) ≡⟨ to-ℕ′-∷ˢ b _ ⟩
from-Bool b ⊕ 2 ⊛ to-ℕ′ (foldr _∷ˢ_ [] bs) ≡⟨ cong (λ n → from-Bool b ⊕ 2 ⊛ n) (to-ℕ′-foldr-∷ˢ-[] bs) ⟩
from-Bool b ⊕ 2 ⊛ foldr (λ b n → from-Bool b ⊕ 2 ⊛ n) 0 bs ≡⟨⟩
foldr (λ b n → from-Bool b ⊕ 2 ⊛ n) 0 (b ∷ bs) ∎
-- Converts from lists of bits. (The most significant bit comes
-- first.)
from-bits : List Bool → Bin′
from-bits = foldr _∷ˢ_ [] ∘ reverse
to-ℕ′-from-bits :
∀ bs →
to-ℕ′ (from-bits bs) ≡
foldl (λ n b → (if b then 1 else 0) ⊕ 2 ⊛ n) 0 bs
to-ℕ′-from-bits bs =
to-ℕ′ (from-bits bs) ≡⟨⟩
to-ℕ′ (foldr _∷ˢ_ [] (reverse bs)) ≡⟨ to-ℕ′-foldr-∷ˢ-[] (reverse bs) ⟩
foldr (λ b n → from-Bool b ⊕ 2 ⊛ n) 0 (reverse bs) ≡⟨ foldr-reverse bs ⟩∎
foldl (λ n b → from-Bool b ⊕ 2 ⊛ n) 0 bs ∎
-- Converts to lists of bits. (The most significant bit comes
-- first.)
to-bits : Bin′ → List Bool
to-bits = reverse ∘ to-List
to-ℕ′-from-bits-to-bits :
∀ n → to-ℕ′ (from-bits (to-bits n)) ≡ to-ℕ′ n
to-ℕ′-from-bits-to-bits n =
to-ℕ′ (foldr _∷ˢ_ [] (reverse (reverse (to-List n)))) ≡⟨ cong (to-ℕ′ ∘ foldr _∷ˢ_ []) (reverse-reverse (to-List n)) ⟩
to-ℕ′ (foldr _∷ˢ_ [] (to-List n)) ≡⟨ to-ℕ′-foldr-∷ˢ-[] (to-List n) ⟩
foldr (λ b n → from-Bool b ⊕ 2 ⊛ n) 0 (to-List n) ≡⟨⟩
to-ℕ′ n ∎
------------------------------------------------------------------------
-- Binary natural numbers
private
module Bin-wrapper = Wrapper Bin′.Bin′ Bin′.Bin′↔ℕ
open Bin-wrapper using (Operations)
-- Some definitions from Nat.Wrapper are reexported.
open Bin-wrapper public
using (⌊_⌋; ⌈_⌉; ≡⌊⌋;
nullary-[]; nullary; nullary-correct;
unary-[]; unary; unary-correct;
binary-[]; binary; binary-correct;
n-ary-[]; n-ary; n-ary-correct)
renaming
( Nat-[_] to Bin-[_]
; Nat to Bin
; Nat-[]↔Σℕ to Bin-[]↔Σℕ
)
open Bin-wrapper.[]-cong ax public
using (≡-for-indices↔≡)
renaming
( Nat-[]-propositional to Bin-[]-propositional
; Nat↔ℕ to Bin↔ℕ
)
private
-- An implementation of some operations for Bin′.
Operations-for-Bin′ : Operations
Operations-for-Bin′ = λ where
.Operations.zero → Bin′.zero′
.Operations.to-ℕ-zero → Bin′.to-ℕ′-zero′
.Operations.suc → Bin′.suc′
.Operations.to-ℕ-suc → Bin′.to-ℕ′-suc′
.Operations._+_ → Bin′.add-with-carry
.Operations.to-ℕ-+ → Bin′.to-ℕ′-add-with-carry
.Operations._*_ → Bin′._*_
.Operations.to-ℕ-* → Bin′.to-ℕ′-*
.Operations._^_ → Bin′._^_
.Operations.to-ℕ-^ → Bin′.to-ℕ′-^
.Operations.⌊_/2⌋ → Bin′.⌊_/2⌋
.Operations.to-ℕ-⌊/2⌋ → Bin′.to-ℕ′-⌊/2⌋
.Operations.⌈_/2⌉ → Bin′.⌈_/2⌉
.Operations.to-ℕ-⌈/2⌉ → Bin′.to-ℕ′-⌈/2⌉
.Operations._*2^_ → Bin′._*2^_
.Operations.to-ℕ-*2^ → Bin′.to-ℕ′-*2^
.Operations._≟_ → Bin′._≟_
.Operations.from-bits → Bin′.from-bits
.Operations.to-ℕ-from-bits → Bin′.to-ℕ′-from-bits
.Operations.to-bits → Bin′.to-bits
.Operations.to-ℕ-from-bits-to-bits → Bin′.to-ℕ′-from-bits-to-bits
-- Operations for Bin-[_].
module Operations-for-Bin-[] =
Bin-wrapper.Operations-for-Nat-[] Operations-for-Bin′
-- Operations for Bin.
module Operations-for-Bin =
Bin-wrapper.Operations-for-Nat Operations-for-Bin′
------------------------------------------------------------------------
-- Some examples
private
module Bin-[]-examples where
open Operations-for-Bin-[]
-- Converts unary natural numbers to binary natural numbers.
from-ℕ : ∀ n → Bin-[ n ]
from-ℕ = proj₂ ∘ _↔_.from Bin↔ℕ
-- Bin n is a proposition, so it is easy to prove that two values
-- of this type are equal.
example₁ : from-ℕ 4 + ⌊ from-ℕ 12 /2⌋ ≡ from-ℕ 10
example₁ = Bin-[]-propositional _ _
-- However, stating that two values of type Bin m and Bin n are
-- equal, for equal natural numbers m and n, can be awkward.
@0 example₂ :
{@0 m n : ℕ}
(b : Bin-[ m ]) (c : Bin-[ n ]) →
subst (λ n → Bin-[ n ]) (N.+-comm m) (b + c) ≡ c + b
example₂ _ _ = Bin-[]-propositional _ _
module Bin-examples where
open Operations-for-Bin
-- If Bin is used instead of Bin-[_], then it can be easier to
-- state that two values are equal.
example₁ : ⌈ 4 ⌉ + ⌊ ⌈ 12 ⌉ /2⌋ ≡ ⌈ 10 ⌉
example₁ = _↔_.to ≡-for-indices↔≡ [ refl _ ]
example₂ : ∀ m n → m + n ≡ n + m
example₂ m n = _↔_.to ≡-for-indices↔≡
[ ⌊ m ⌋ ⊕ ⌊ n ⌋ ≡⟨ N.+-comm ⌊ m ⌋ ⟩∎
⌊ n ⌋ ⊕ ⌊ m ⌋ ∎
]
-- One can construct a proof showing that ⌈ 5 ⌉ is either equal or
-- not equal to ⌈ 2 ⌉ + ⌈ 3 ⌉, but the proof does not compute to
-- "inj₁ something" at compile-time.
example₃ : Dec (⌈ 5 ⌉ ≡ ⌈ 2 ⌉ + ⌈ 3 ⌉)
example₃ =
Dec-map (_↔_.logical-equivalence ≡-for-indices↔≡)
(⌈ 5 ⌉ ≟ ⌈ 2 ⌉ + ⌈ 3 ⌉)
| {
"alphanum_fraction": 0.3922590625,
"avg_line_length": 39.335978836,
"ext": "agda",
"hexsha": "da6b98a927728a8319996acccb0bb800e57d73eb",
"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/Nat/Binary.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/Nat/Binary.agda",
"max_line_length": 141,
"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/Nat/Binary.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": 12539,
"size": 29738
} |
module Structure.Operator.Monoid.Submonoid where
import Lvl
open import Logic
open import Logic.Predicate
open import Logic.Predicate.Equiv
open import Sets.PredicateSet renaming (_≡_ to _≡ₛ_)
open import Structure.Setoid
open import Structure.Operator.Monoid
open import Structure.Operator.Properties
open import Structure.Operator
open import Type
private variable ℓ ℓₑ : Lvl.Level
private variable T : Type{ℓ}
module _ {ℓₛ} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ {_▫_ : T → T → T} (M : Monoid(_▫_)) where
record Submonoid (S : PredSet{ℓₛ}(T)) : Stmt{Lvl.of(T) Lvl.⊔ ℓₛ} where
constructor intro
open Monoid(M) using (id)
field
⦃ contains-identity ⦄ : (id ∈ S)
⦃ operator-closure ⦄ : ∀{x y} → ⦃ x ∈ S ⦄ → ⦃ y ∈ S ⦄ → ((x ▫ y) ∈ S)
Object = ∃(S)
_▫ₛ_ : Object → Object → Object
([∃]-intro x) ▫ₛ ([∃]-intro y) = [∃]-intro (x ▫ y)
instance
monoid : Monoid(_▫ₛ_)
BinaryOperator.congruence (Monoid.binary-operator monoid) = congruence₂(_▫_)
Associativity.proof (Monoid.associativity monoid) = associativity(_▫_)
∃.witness (Monoid.identity-existence monoid) = [∃]-intro id
Identityₗ.proof (Identity.left (∃.proof (Monoid.identity-existence monoid))) = identityₗ(_▫_)(id)
Identityᵣ.proof (Identity.right (∃.proof (Monoid.identity-existence monoid))) = identityᵣ(_▫_)(id)
| {
"alphanum_fraction": 0.6289529164,
"avg_line_length": 38.4594594595,
"ext": "agda",
"hexsha": "b517a8701263d5282d4a0d84dcb147fdebac5978",
"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": "Structure/Operator/Monoid/Submonoid.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": "Structure/Operator/Monoid/Submonoid.agda",
"max_line_length": 104,
"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": "Structure/Operator/Monoid/Submonoid.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": 479,
"size": 1423
} |
open import Structures
open import SacTy
module ExtractSac where
open import Data.String as S hiding (_++_) renaming (_≟_ to _≟s_)
open import Data.List as L hiding (_++_)
open import Data.List.Categorical
open import Data.List.Properties as L
open import Data.Nat as N
open import Agda.Builtin.Nat using (div-helper; mod-helper)
open import Data.Nat.Properties as N
open import Data.Nat.Show renaming (show to showNat)
open import Data.Product as Σ hiding (map)
open import Data.Sum hiding (map)
open import Data.Vec as V using (Vec; [] ; _∷_)
open import Data.Char using (Char) renaming (_≈?_ to _c≈?_)
open import Data.Bool
open import Data.Fin as F using (Fin; zero; suc; inject₁; fromℕ<; #_)
open import Data.Maybe as M using (Maybe; just; nothing)
open import Data.Unit
open import Category.Monad
open import Category.Monad.State
open import Relation.Binary.PropositionalEquality as Eq hiding ([_])
open import Relation.Nullary
open import Relation.Nullary.Decidable hiding (map)
open import Reflection hiding (return; _>>=_; _>>_)
open import Reflection.Term
import Reflection.Name as RN
open import Reflection.Annotated
open import Reflection.Universe
open import Reflection.Annotated.Free
open import Function
open import Array.Base
open import Array.Properties
open import APL2 using (reduce-1d; _↑_; _↓_; ▴_; ▾_; _-↑⟨_⟩_; _↑⟨_⟩_)
open import Agda.Builtin.Float
open RawMonad ⦃ ... ⦄
-- Glorified sigma type for variable-type pairs
record VarTy : Set where
constructor _∈_~_
field v : String
s : Err SacTy
t : Arg Type
-- Glorified sigma type for variable-assertion pairs
record Assrt : Set where
constructor mk
field v : String
a : String
Assrts = List Assrt
-- The state used when traversing a Pi type.
record PS : Set where
field
cnt : ℕ -- The source of unique variable names
cur : String -- Current variable name (used to collect assertions from its type)
ctx : List VarTy -- Names in the telscopes to resolve deBruijn indices
ret : String -- Variable that the function returns as a result.
-- We assume that there is always a single variable and its name
-- is known upfront. We need this to generate assertions from the
-- return type.
assrts : Assrts -- Assertions that we generate per each variable.
kst : KS -- Compilation state (in case we have to extract some functions used in types)
defaultPS : PS
defaultPS = record { cnt = 1
; cur = ""
; ctx = []
; ret = "__ret"
; assrts = []
; kst = defaultKS
}
-- Pack the information about new variables generated
-- by patterns in the clause, assignments to these,
-- and the list of conditions for "getting into" the
-- clause. E.g.
-- foo : List ℕ → ℕ
-- foo (x ∷ xs) 2 = ...
--
-- Assume that we named top-level arguments [a, b]
-- Then, new variables for this clause are going to be
-- [x, xs]
-- Assignments are:
-- [x = hd a, xs = tl a]
-- Conditions are:
-- [is-cons a, b == 2]
--
-- `cnt` is merely a source of fresh variables.
record PatSt : Set where
constructor mk
field
vars : List (String × ℕ) --Strings
assigns : Strings
conds : Strings
cnt : ℕ
defaultPatSt : PatSt
defaultPatSt = mk [] [] [] 1
SPS = State PS
-- The main function kit to extract sac functions.
kompile-fun : Type → Term → Name → SKS Prog
kompile-pi : Type → SPS (Err SacTy) --Prog
kompile-cls : Clauses → (vars : Strings) → (ret : String) → SKS Prog
kompile-clpats : Telescope → (pats : List $ Arg Pattern) → (vars : Strings) → PatSt → Err PatSt
{-# TERMINATING #-}
kompile-term : Term → {- (varctx : Strings) -} {- List VarTy -} Telescope → SKS Prog
-- Normalise the name of the symbols (functions, constructors, ...)
-- that we obtain from showName, i.e. remove dots, replace weird
-- symbols with ascii.
nnorm : String → String
nnorm s = replace '.' "_"
$ replace '-' "_"
$ replace '+' "plus"
$ replace 'α' "alpha"
$ replace 'ω' "omega"
$ replace '→' "to"
$ s
where
repchar : (from : Char) (to : String) (x : Char) → String
repchar from to x with does $ x c≈? from
... | true = to
... | false = fromList (x ∷ [])
replace : (from : Char) (to : String) → String → String
replace f t s = "" ++/ L.map (repchar f t) (toList s)
private
kf : String → Prog
kf x = error $ "kompile-fun: " ++ x
validate-ty : Err SacTy → Prog
validate-ty (error x) = error x
validate-ty (ok τ) = let τ′ = sacty-normalise τ in
case nested? τ′ of λ where
hom → ok $ sacty-to-string τ′
nes → error $ "sac does not support nested types, but `"
++ sacty-to-string τ′ ++ "` found"
module R = RawMonadState (StateMonadState KS)
kompile-fun ty (pat-lam [] []) n =
return $ kf "got zero clauses in a lambda term"
kompile-fun ty (pat-lam cs []) n = do
kst ← R.get
let (rt , ps) = kompile-pi ty $ record defaultPS{ kst = kst }
rt = validate-ty rt
rv = PS.ret ps
ns = showName n
args = ok ", " ++/ L.map (λ where (v ∈ t ~ _) → validate-ty t ⊕ " " ⊕ v) (PS.ctx ps)
ret-assrts = list-filter (λ where (mk v _) → v ≈? rv) $ PS.assrts ps
arg-assrts = list-filter (dec-neg λ where (mk v _) → v ≈? rv) $ PS.assrts ps
assrt-to-code = ("/* " ++_) ∘ (_++ " */") ∘ Assrt.a
R.put $ PS.kst ps
--b ← if does (showName n S.≟ "Example-02.testn") then kompile-cls cs (L.map (λ where (v ∈ _ ~ _) → v) $ PS.ctx ps) rv else (return $ ok "XX")
b ← kompile-cls cs (L.map (λ where (v ∈ _ ~ _) → v) $ PS.ctx ps) rv
return $ "// Function " ⊕ ns ⊕ "\n"
⊕ rt ⊕ "\n"
⊕ nnorm ns ⊕ "(" ⊕ args ⊕ ") {\n"
⊕ "\n" ++/ L.map assrt-to-code arg-assrts
⊕ rt ⊕ " " ⊕ rv ⊕ ";\n"
⊕ b -- function body
⊕ "\n" ++/ L.map assrt-to-code ret-assrts
⊕ "return " ⊕ rv ⊕ ";\n"
⊕ "}\n\n"
kompile-fun _ _ _ =
return $ kf "expected pattern-matching lambda"
private
kp : ∀ {X} → String → SPS (Err X)
kp x = return $ error $ "kompile-pi: " ++ x
ke : ∀ {X} → String → SPS (Err X)
ke x = return $ error x
module P = RawMonadState (StateMonadState PS)
infixl 10 _p+=c_ _p+=a_
_p+=c_ : PS → ℕ → PS
ps p+=c n = record ps{ cnt = PS.cnt ps + n }
_p+=a_ : PS → Assrt → PS
ps p+=a a = record ps{ assrts = a ∷ PS.assrts ps }
ps-fresh : String → SPS String
ps-fresh x = do
ps ← P.get
P.modify (_p+=c 1)
return $ x ++ showNat (PS.cnt ps)
lift-ks : ∀ {X} → SKS X → SPS X
lift-ks xf sps = let (x , sks) = xf (PS.kst sps) in x , record sps {kst = sks}
sps-kompile-term : Term → SPS Prog
sps-kompile-term t = do
ps ← P.get
lift-ks $ kompile-term t $ (L.map (λ where (v ∈ _ ~ t) → (v , t)) $ PS.ctx ps)
kompile-ty : Type → (pi-ok : Bool) → SPS (Err SacTy)
kompile-ty (Π[ s ∶ arg i x ] y) false = kp "higher-order functions are not supported"
kompile-ty (Π[ s ∶ arg i x ] y) true = do
v ← ps-fresh "x_"
P.modify λ k → record k { cur = v }
(ok t) ← kompile-ty x false
where e → return e
P.modify λ k → record k { cur = PS.ret k -- In case this is a return type
; ctx = PS.ctx k ++ [ v ∈ ok t ~ arg i x ] }
kompile-ty y true
kompile-ty (con c args) pi-ok =
kp $ "don't know how to handle `" ++ showName c ++ "` constructor"
kompile-ty (def (quote ℕ) args) _ = return $ ok int
kompile-ty (def (quote Bool) args) _ = return $ ok bool
kompile-ty (def (quote Float) args) _ = return $ ok float
kompile-ty (def (quote Fin) (arg _ x ∷ [])) _ = do
ok p ← sps-kompile-term x where error x → ke x
v ← PS.cur <$> P.get
P.modify $ _p+=a (mk v $′ "assert (" ++ v ++ " < " ++ p ++ ")")
return $ ok int
kompile-ty (def (quote L.List) (_ ∷ arg _ ty ∷ _)) _ = do
el ← ps-fresh "el_"
v , as ← < PS.cur , PS.assrts > <$> P.get
-- Any constraints that the subsequent call would
-- generate will be constraints about the elements
-- of the list.
P.modify λ k → record k { cur = el ; assrts = [] }
ok τ ← kompile-ty ty false where e → return e
P.modify λ k → record k {
cur = v;
assrts = as ++ (L.map {B = Assrt} (λ where (mk _ a) → mk v ("foreach-v " ++ el ++ " in " ++ v ++ ": " ++ a)) $ PS.assrts k)
-- No need to modify context, as we don't allow higher order functions, so it stays the same.
}
return $ ok $ akd nes τ (error "lists do not have static shape") 1
kompile-ty (def (quote V.Vec) (_ ∷ arg _ ty ∷ arg _ n ∷ [])) _ = do
el ← ps-fresh "el_"
v , as ← < PS.cur , PS.assrts > <$> P.get
ok p ← sps-kompile-term n where error x → ke x
P.modify λ k → record k { cur = el ; assrts = [] }
ok τ ← kompile-ty ty false where e → return e
P.modify λ k → record k {
cur = v;
assrts = as ++ (L.map {B = Assrt} (λ where (mk _ a) → mk v ("foreach-v " ++ el ++ " in " ++ v ++ ": " ++ a)) $ PS.assrts k)
++ [ mk v $′ "assert (shape (" ++ v ++ ")[[0]] == " ++ p ++ ")" ]
}
let sh = "[" ⊕ p ⊕ "]"
case n of λ where
-- XXX can we possibly miss on any constant expressions?
(lit (nat n′)) → return $ ok $ aks hom τ sh 1 V.[ n′ ]
_ → return $ ok $ akd hom τ sh 1
kompile-ty (def (quote Ar) (_ ∷ arg _ el-ty ∷ arg _ dim ∷ arg _ sh ∷ [])) _ = do
el ← ps-fresh "el_"
v , as ← < PS.cur , PS.assrts > <$> P.get
ok d ← sps-kompile-term dim where error x → ke x
ok s ← sps-kompile-term sh where error x → ke x
P.modify λ k → record k { cur = el ; assrts = [] }
ok τ ← kompile-ty el-ty false where e → return e
P.modify λ k → record k {
cur = v;
assrts = as ++ (L.map {B = Assrt} (λ where (mk _ a) → mk v ("foreach-a sh=" ++ s ++ " " ++ el ++ " in " ++ v ++ ": " ++ a)) $ PS.assrts k)
++ [ mk v $′ "assert (take (" ++ d ++ ", shape (" ++ v ++ ")) == " ++ s ++ ")" ]
-- XXX do we want to assert stuff about rank?
}
case dim of λ where
-- XXX can we possibly miss on any constant expressions?
-- FIXME consider AKS case here!
(lit (nat d′)) → return $ ok $ akd hom τ (ok s) d′
_ → return $ ok $ aud hom τ (ok s)
kompile-ty (def (quote Ix) (arg _ dim ∷ arg _ s ∷ [])) _ = do
v ← PS.cur <$> P.get
ok d ← sps-kompile-term dim where error x → ke x
ok s ← sps-kompile-term s where error x → ke x
P.modify $ _p+=a (mk v $′ "assert (dim (" ++ v ++ ") == " ++ d ++ ")")
∘ _p+=a (mk v $′ "assert (" ++ v ++ " < " ++ s ++ ")")
case dim of λ where
(lit (nat d′)) → return $ ok $ aks hom int (ok s) 1 V.[ d′ ]
_ → return $ ok $ akd hom int (ok s) 1
kompile-ty (def (quote _≡_) (_ ∷ arg _ ty ∷ arg _ x ∷ arg _ y ∷ [])) _ = do
ok x ← sps-kompile-term x where error x → ke x
ok y ← sps-kompile-term y where error x → ke x
v ← PS.cur <$> P.get
P.modify $ _p+=a (mk v $′ "assert (" ++ x ++ " == " ++ y ++ ")")
return $ ok unit
kompile-ty (def (quote _≥a_) (_ ∷ _ ∷ arg _ x ∷ arg _ y ∷ [])) _ = do
ok x ← sps-kompile-term x where error x → ke x
ok y ← sps-kompile-term y where error x → ke x
v ← PS.cur <$> P.get
P.modify $ _p+=a (mk v $′ "assert (" ++ x ++ " >= " ++ y ++ ")")
return $ ok unit
kompile-ty (def (quote _<a_) (_ ∷ _ ∷ arg _ x ∷ arg _ y ∷ [])) _ = do
ok x ← sps-kompile-term x where error x → ke x
ok y ← sps-kompile-term y where error x → ke x
v ← PS.cur <$> P.get
P.modify $ _p+=a (mk v $′ "assert (" ++ x ++ " < " ++ y ++ ")")
return $ ok unit
kompile-ty (def (quote Dec) (_ ∷ arg _ p ∷ [])) _ = do
_ ← kompile-ty p false
return $ ok bool
kompile-ty (def n _) _ = kp $ "cannot handle `" ++ showName n ++ "` type"
kompile-ty t _ =
kp $ "failed with the term `" ++ showTerm t ++ "`"
kompile-pi x = kompile-ty x true
-- The names in the telescopes very oftern are not unique, which
-- would be pretty disasterous if the code generation relies on them.
-- see https://github.com/agda/agda/issues/5048 for more details.
--
-- This function simply ensures that variable names are unique in
-- in the telescope.
tel-rename : Telescope → (db : List (String × ℕ)) → Telescope
tel-rename [] db = []
tel-rename ((v , ty) ∷ tel) db with list-find-el ((_≟s v) ∘ proj₁) db
... | just (_ , n) = (v ++ "_" ++ showNat n , ty)
∷ tel-rename tel (list-update-fst ((_≟s v) ∘ proj₁) db (Σ.map₂ suc))
... | nothing = (v , ty)
∷ tel-rename tel ((v , 1) ∷ db)
private
kc : String → SKS Prog
kc x = return $ error $ "kompile-cls: " ++ x
_>>=e_ : ∀ {a}{X : Set a} → Err X → (X → SKS Prog) → SKS Prog
(error s) >>=e _ = return $ error s
(ok x) >>=e f = f x
-- sort in increasing order
list-sort : ∀ {a}{X : Set a} → (acc l : List (X × ℕ)) → List (X × ℕ)
list-sort acc [] = acc
list-sort acc (x ∷ l) = list-sort (insert acc x) l
where
insert : _ → _ → _
insert [] y = y ∷ []
insert (x ∷ xs) y with proj₂ y N.<? proj₂ x
... | yes y<x = y ∷ x ∷ xs
... | no y≥x = x ∷ insert xs y
isperm : ∀ {a}{X : Set a} → (n max : ℕ) → (db : List ℕ) → List (X × ℕ) → Bool
isperm 0 0 [] [] = true
isperm n max db [] = does (1 + max N.≟ n) ∧ does (L.length db N.≟ n)
isperm n max db ((_ , x) ∷ xs) with list-has-el (N._≟ x) db
... | true = false
... | false = isperm n (max N.⊔ x) (x ∷ db) xs
perm : Telescope → List (String × ℕ) → Err (List String)
perm tel vs with isperm (L.length tel) 0 [] vs
... | false = error $ ", " ++/ L.map (λ where (x , y) → "(" ++ x ++ ", " ++ showNat y ++ ")") vs
++ " is not a permutation of the telescope "
++ showTel tel
... | true = ok $ L.reverse $ L.map proj₁ $ list-sort [] vs
module test-perm where
test₀ : isperm {X = ℕ} 0 0 [] [] ≡ true
test₀ = refl
test₁ : isperm 1 0 [] (("" , 0) ∷ []) ≡ true
test₁ = refl
test₂′ : isperm 2 0 [] (("" , 1) ∷ ("" , 0) ∷ []) ≡ true
test₂′ = refl
test₃ : isperm 3 0 [] (("" , 2) ∷ ("" , 0) ∷ ("" , 1) ∷ []) ≡ true
test₃ = refl
test₄ : isperm 4 0 [] (("" , 2) ∷ ("" , 2) ∷ ("" , 1) ∷ ("" , 3) ∷ []) ≡ false
test₄ = refl
kompile-tel : Telescope → SPS (Err ⊤)
kompile-tel [] = return $ ok tt
kompile-tel ((v , t@(arg i x)) ∷ tel) = do
--(ok τ) ← kompile-ty x false where (error x) → return $ error x
P.modify λ k → record k{ ctx = PS.ctx k ++ [ v ∈ error "?" ~ t ] }
kompile-tel tel
kompile-cls [] ctx ret = kc "zero clauses found"
kompile-cls (clause tel ps t ∷ []) ctx ret =
-- Make telscope names unique.
let tel = (tel-rename $! tel) $! [] in
kompile-clpats tel ps ctx defaultPatSt >>=e λ pst → do
let (mk vars assgns _ _) = pst --in
t ← kompile-term t $! tel
let as = "\n" ++/ assgns
return $ as ⊕ "\n"
⊕ ret ⊕ " = " ⊕ t ⊕ ";\n"
kompile-cls (absurd-clause tel ps ∷ []) ctx ret =
-- Exactly the same as above
-- We don't really need to make this call, but we keep it
-- for sanity checks. I.e. if we'll get an error in the
-- patterns, it will bubble up to the caller.
kompile-clpats ((tel-rename $! tel) $! []) ps ctx defaultPatSt >>=e λ pst → do
return $ ok "unreachable ();"
kompile-cls (absurd-clause tel ps ∷ ts@(_ ∷ _)) ctx ret =
kompile-clpats ((tel-rename $! tel) $! []) ps ctx defaultPatSt >>=e λ pst → do
let (mk vars _ conds _) = pst
cs = " && " ++/ (if L.length conds N.≡ᵇ 0 then [ "true" ] else conds)
r ← kompile-cls ts ctx ret
return $ "if (" ⊕ cs ⊕ ") {\n"
⊕ "unreachable();\n"
⊕ "} else {\n"
⊕ r ⊕ "\n"
⊕ "}\n"
kompile-cls (clause tel ps t ∷ ts@(_ ∷ _)) ctx ret =
kompile-clpats ((tel-rename $! tel) $! []) ps ctx defaultPatSt >>=e λ pst → do
let (mk vars assgns conds _) = pst
cs = " && " ++/ (if L.length conds N.≡ᵇ 0 then [ "true" ] else conds)
as = "\n" ++/ assgns
t ← kompile-term t $! tel --telv --{!!} --PS.ctx ps
r ← kompile-cls ts ctx ret
return $ "if (" ⊕ cs ⊕ ") {\n"
⊕ as ⊕ "\n"
⊕ ret ⊕ " = " ⊕ t ⊕ ";\n"
⊕ "} else {\n"
⊕ r ⊕ "\n"
⊕ "}\n"
tel-lookup-name : Telescope → ℕ → Prog
tel-lookup-name tel n with n N.<? L.length (reverse tel)
... | yes n<l = ok $ proj₁ $ lookup (reverse tel) $ fromℕ< n<l
... | no _ = error "Variable lookup in telescope failed"
private
kcp : String → Err PatSt
kcp x = error $ "kompile-clpats: " ++ x
infixl 10 _+=c_ _+=a_ _+=v_ _+=n_
_+=c_ : PatSt → String → PatSt
p +=c c = record p { conds = PatSt.conds p ++ [ c ] }
_+=a_ : PatSt → String → PatSt
p +=a a = record p { assigns = PatSt.assigns p ++ [ a ] }
_+=v_ : PatSt → String × ℕ → PatSt
p +=v v = record p { vars = PatSt.vars p ++ [ v ] }
_+=n_ : PatSt → ℕ → PatSt
p +=n n = record p { cnt = PatSt.cnt p + 1 }
pst-fresh : PatSt → String → Err $ String × PatSt
pst-fresh pst x =
return $ x ++ showNat (PatSt.cnt pst) , pst +=n 1
kompile-clpats tel (arg i (con (quote true) ps) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel l ctx $ pst +=c (v {- == true -})
kompile-clpats tel (arg i (con (quote false) ps) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel l ctx $ pst +=c ("!" ++ v)
kompile-clpats tel (arg i (con (quote N.zero) ps) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel l ctx $ pst +=c (v ++ " == 0")
kompile-clpats tel (arg i (con (quote N.suc) ps) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel (ps ++ l) ((v ++ " - 1") ∷ ctx) $ pst +=c (v ++ " > 0")
kompile-clpats tel (arg i (con (quote F.zero) ps) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel l ctx $ pst +=c (v ++ " == 0")
kompile-clpats tel (arg i (con (quote F.suc) ps@(_ ∷ _ ∷ [])) ∷ l) (v ∷ ctx) pst = do
(ub , pst) ← pst-fresh pst "ub_"
-- XXX here we are not using `ub` in conds. For two reasons:
-- 1) as we have assertions, we should check the upper bound on function entry
-- 2) typically, the value of this argument would be Pat.dot, which we ignore
-- right now. It is possible to capture the value of the dot-patterns, as
-- they carry the value when reconstructed.
kompile-clpats tel (ps ++ l) (ub ∷ (v ++ " - 1") ∷ ctx) $ pst +=c (v ++ " > 0")
kompile-clpats tel (arg i (con (quote L.List.[]) []) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel l ctx $ pst +=c ("emptyvec_p (" ++ v ++ ")")
kompile-clpats tel (arg i (con (quote L.List._∷_) ps@(_ ∷ _ ∷ [])) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel (ps ++ l) (("hd (" ++ v ++ ")") ∷ ("tl (" ++ v ++ ")") ∷ ctx)
$ pst +=c ("nonemptyvec_p (" ++ v ++ ")")
-- Almost the same as List (extra parameter in cons)
kompile-clpats tel (arg i (con (quote V.Vec.[]) []) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel l ctx $ pst +=c ("emptyvec_p (" ++ v ++ ")")
kompile-clpats tel (arg i (con (quote V.Vec._∷_) ps@(_ ∷ _ ∷ _ ∷ [])) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel (ps ++ l) (("len (" ++ v ++ ") - 1") ∷ ("hd (" ++ v ++ ")") ∷ ("tl (" ++ v ++ ")") ∷ ctx)
$ pst +=c ("nonemptyvec_p (" ++ v ++ ")")
-- Patterns for Ix constructors
kompile-clpats tel (arg i (con (quote Ix.[]) []) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel l ctx $ pst +=c ("emptyvec_p (" ++ v ++ ")")
kompile-clpats tel (arg i (con (quote Ix._∷_) ps@(d ∷ arg _ (dot s) ∷ arg _ (dot x) ∷ finx ∷ tailix ∷ [])) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel (d ∷ finx ∷ tailix ∷ l) (("len (" ++ v ++ ") - 1") ∷ ("hd (" ++ v ++ ")") ∷ ("tl (" ++ v ++ ")") ∷ ctx)
$ pst +=c ("nonemptyvec_p (" ++ v ++ ")")
kompile-clpats tel (arg i (con (quote Ix._∷_) _) ∷ l) (v ∷ ctx) pst =
kcp $ "matching on `s` and `x` in the Ix._∷_ is not supported, please rewrite the pattern"
kompile-clpats tel (arg _ (con (quote imap) (arg _ (var i) ∷ [])) ∷ l) (v ∷ ctx) pst = do
(ub , pst) ← pst-fresh pst $ "IMAP_" ++ v ++ "_"
-- The only thing that `x` could be is a variable, and since
-- we don't have higher-order functions in sac, we define a local
-- macro. Note that we do not pass x further, to avoid assignment.
kompile-clpats tel l ctx $ pst +=v (ub , i) +=a ("#define " ++ ub ++ "(__x) (" ++ v ++ ")[__x]")
kompile-clpats tel (arg i (con (quote imap) (arg _ (dot _) ∷ [])) ∷ l) (v ∷ ctx) pst =
-- We simply ignore this inner function entirely.
kompile-clpats tel l ctx $ pst
kompile-clpats tel (arg i (con (quote imap) (arg _ (absurd _) ∷ [])) ∷ l) (v ∷ ctx) pst =
kcp "don't know how to handle absurd pattern as an argument to imap"
kompile-clpats tel (arg i (con (quote refl) ps) ∷ l) (v ∷ ctx) pst =
-- No constraints, as there could only be a single value.
kompile-clpats tel l ctx pst
kompile-clpats tel (arg i (con (quote _because_) ps) ∷ l) (v ∷ ctx) pst = do
pf , pst ← pst-fresh pst $ "pf_"
kompile-clpats tel (ps ++ l) (v ∷ pf ∷ ctx) pst
kompile-clpats tel (arg i (con (quote Reflects.ofʸ) ps) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel (ps ++ l) ("true" ∷ ctx) pst
kompile-clpats tel (arg i (con (quote Reflects.ofⁿ) ps) ∷ l) (v ∷ ctx) pst =
kompile-clpats tel (ps ++ l) ("false" ∷ ctx) pst
-- End of constructors here.
kompile-clpats tel (arg (arg-info _ r) (var i) ∷ l) (v ∷ vars) pst = do
-- Note that we do not distinguish between hidden and visible variables
s ← tel-lookup-name tel i
let s = nnorm s
-- If the order of variable binding doesn't match the order
-- of the variables in the telescope, we have to consider `i` as well.
-- This changed with https://github.com/agda/agda/issues/5075
let pst = pst +=v (s , i)
let pst = if does (s ≈? "_")
then pst
else pst +=a (s ++ " = " ++ v ++ ";")
{-
-- XXX If I replace the above if with this one, I end up with
-- the unsolved meta in the test₂ in Example.agda. Is this a bug?
let pst = case (s ≈? "_") of λ where
(yes _) → pst
(no _) → pst +=a (s ++ " = " ++ v ++ ";")
-}
kompile-clpats tel l vars pst
kompile-clpats tel (arg i (dot t) ∷ l) (v ∷ vars) pst =
-- For now we just skip dot patterns.
kompile-clpats tel l vars pst
kompile-clpats tel (arg i (absurd _) ∷ l) (v ∷ ctx) pst =
-- If have met the absurd pattern, we are done, as
-- we have accumulated enough conditions to derive
-- impossibility. So we are simply done.
ok pst
kompile-clpats _ [] [] pst = ok pst
kompile-clpats tel ps ctx patst = kcp $ "failed on pattern: ["
++ (", " ++/ L.map (λ where (arg _ x) → showPattern x) ps)
++ "], ctx: [" ++ (", " ++/ ctx) ++ "]"
private
kt : String → SKS Prog
kt x = return $ error $ "kompile-term: " ++ x
kt-fresh : String → SKS String
kt-fresh x = do
ps ← R.get
R.modify λ k → record k{ cnt = 1 + KS.cnt k }
return $ x ++ showNat (KS.cnt ps)
var-lookup : List VarTy → ℕ → SKS Prog
var-lookup [] _ = kt "Variable lookup failed"
var-lookup (v ∈ _ ~ _ ∷ xs) zero = return $ ok v
var-lookup (x ∷ xs) (suc n) = var-lookup xs n
vty-lookup : List VarTy → ℕ → Err (VarTy)
vty-lookup [] _ = error "Variable lookup failed"
vty-lookup (x ∷ xs) zero = ok x
vty-lookup (x ∷ xs) (suc n) = vty-lookup xs n
mk-mask : (n : ℕ) → List $ Fin n
mk-mask zero = []
mk-mask (suc n) = L.reverse $ go n (suc n) N.≤-refl
where
sa<b⇒a<b : ∀ a b → suc a N.< b → a N.< b
sa<b⇒a<b zero (suc b) _ = s≤s z≤n
sa<b⇒a<b (suc a) (suc n) (s≤s pf) = s≤s $ sa<b⇒a<b a n pf
go : (m n : ℕ) → m N.< n → List $ Fin n
go 0 (suc _) _ = zero ∷ []
go (suc m) n pf = F.fromℕ< pf ∷ go m n (sa<b⇒a<b m n pf)
te-to-lvt : Telescope → List VarTy
te-to-lvt tel = L.map (λ where (v , t) → v ∈ error "?" ~ t) tel
-- TODO lift it up
SAC-funs : List (Name × String)
SAC-funs = (quote _+_ , "_add_SxS_")
∷ (quote _*_ , "_mul_SxS_")
∷ (quote primFloatPlus , "_add_SxS_")
∷ (quote primFloatMinus , "_sub_SxS_")
∷ (quote primFloatTimes , "_mul_SxS_")
∷ (quote primFloatDiv , "_div_SxS_")
∷ (quote primFloatExp , "Math::exp")
∷ (quote primFloatNegate , "_neg_S_")
∷ []
private
module mask-tests where
test-mk-mask₁ : mk-mask 0 ≡ []
test-mk-mask₁ = refl
test-mk-mask₂ : mk-mask 1 ≡ # 0 ∷ []
test-mk-mask₂ = refl
test-mk-mask₃ : mk-mask 2 ≡ # 0 ∷ # 1 ∷ []
test-mk-mask₃ = refl
kompile-arglist : (n : ℕ) → List $ Arg Term → List $ Fin n → Telescope → SKS Prog
kompile-arglist n args mask varctx with L.length args N.≟ n | V.fromList args
... | yes p | vargs rewrite p = do
l ← mapM (λ where (arg _ x) → kompile-term x varctx)
$ L.map (V.lookup vargs) mask
return $ ok ", " ++/ l
where open TraversableM (StateMonad KS)
... | no ¬p | _ = kt "Incorrect argument mask"
kompile-term (var x []) vars =
return $ tel-lookup-name vars x
kompile-term (var x args@(_ ∷ _)) vars = do
let f = tel-lookup-name vars x
l = L.length args
args ← kompile-arglist l args (mk-mask l) vars
return $ f ⊕ "(" ⊕ args ⊕ ")"
kompile-term (lit l@(float _)) vars = return $ showLiteral l ⊕ "f"
kompile-term (lit l) vars = return $ ok $ showLiteral l
kompile-term (con (quote N.zero) _) _ =
return $ ok "0"
kompile-term (con (quote N.suc) args) vars = do
args ← kompile-arglist 1 args [ # 0 ] vars
return $ "(1 + " ⊕ args ⊕ ")"
kompile-term (con (quote Fin.zero) _) _ =
return $ ok "0"
kompile-term (con (quote Fin.suc) args) vars = do
args ← kompile-arglist 2 args [ # 1 ] vars
return $ "(1 + " ⊕ args ⊕ ")"
kompile-term (con (quote L.List.[]) (_ ∷ (arg _ ty) ∷ [])) vars = do
-- We want to call kompile-ty, and we need a context that "should"
-- contain vars with their types. But, we never actually access these
-- types in the context, we only refer to variables, therefore the
-- following hack is justified.
kst ← R.get
let ctx = L.map (λ where (v , t) → v ∈ error "?" ~ t) $ vars
(rt , ps) = kompile-ty ty false $ record defaultPS{ kst = kst; ctx = ctx }
in-sh = sacty-shape =<< rt
--R.put (PS.kst ps)
return $ "empty (" ⊕ in-sh ⊕ ")" --ok "[]"
kompile-term (con (quote L.List._∷_) args) vars = do
args ← kompile-arglist 4 args (# 2 ∷ # 3 ∷ []) vars
return $ "cons (" ⊕ args ⊕ ")"
-- Almost the same as List
kompile-term (con (quote V.Vec.[]) (_ ∷ (arg _ ty) ∷ [])) vars = do
kst ← R.get
let ctx = L.map (λ where (v , t) → v ∈ error "?" ~ t) $ vars
(rt , ps) = kompile-ty ty false $ record defaultPS{ kst = kst; ctx = ctx }
in-sh = sacty-shape =<< rt
R.put (PS.kst ps)
return $ "empty (" ⊕ in-sh ⊕ ")"
kompile-term (con (quote V.Vec._∷_) args) vars = do
args ← kompile-arglist 5 args (# 3 ∷ # 4 ∷ []) vars
return $ "cons (" ⊕ args ⊕ ")"
-- Ix constructors
kompile-term (con (quote Ix.[]) []) vars =
return $ ok "[]"
kompile-term (con (quote Ix._∷_) args) vars = do
args ← kompile-arglist 5 args (# 3 ∷ # 4 ∷ []) vars
return $ "cons (" ⊕ args ⊕ ")"
kompile-term (con (quote refl) _) _ =
return $ ok "tt"
-- Imaps with explicit lambdas
kompile-term (con (quote Array.Base.imap) (_ ∷ arg _ ty ∷ arg _ d ∷ X@(arg _ s) ∷ arg _ (vLam x e) ∷ [])) vars = do
kst ← R.get
let ctx = L.map (λ where (v , t) → v ∈ error "?" ~ t) $ vars
(rt , ps) = kompile-ty ty false $ record defaultPS{ kst = kst; ctx = ctx }
in-sh = sacty-shape =<< rt
bt = bt <$> rt
R.put (PS.kst ps)
iv ← kt-fresh "iv_"
let iv-type = vArg (def (quote Ix) ((vArg d) ∷ vArg s ∷ []))
s ← kompile-term s vars
b ← kompile-term e $! vars ++ [ (iv , iv-type) ]
return $! "with { (. <= " ⊕ iv ⊕ " <= .): " ⊕ b ⊕ "; }: genarray (" ⊕ s ⊕ ", zero_" ⊕ bt ⊕ " (" ⊕ in-sh ⊕ "))"
-- Imaps with an expression
kompile-term (con (quote Array.Base.imap) (_ ∷ arg _ ty ∷ _ ∷ arg _ s ∷ arg _ e ∷ [])) vars = do
kst ← R.get
let ctx = L.map (λ where (v , t) → v ∈ error "?" ~ t) $ vars
(rt , ps) = kompile-ty ty false $ record defaultPS{ kst = kst; ctx = ctx }
in-sh = sacty-shape =<< rt
bt = bt <$> rt
R.put (PS.kst ps)
iv ← kt-fresh "iv_"
s ← kompile-term s vars
b ← kompile-term e $ vars
return $ "with { (. <= " ⊕ iv ⊕ " <= .): " ⊕ b ⊕ " (" ⊕ iv ⊕ "); }: genarray (" ⊕ s ⊕ ", zero_" ⊕ bt ⊕ " (" ⊕ in-sh ⊕ "))"
kompile-term (con c _) vars = kt $ "don't know constructor " ++ (showName c)
-- Definitions
-- From Agda.Builtin.Nat: div-helper k m n j = k + (n + m - j) div (1 + m)
kompile-term (def (quote div-helper) (arg _ k ∷ arg _ m ∷ arg _ n ∷ arg _ j ∷ [])) vars = do
k ← kompile-term k vars
m ← kompile-term m vars
n ← kompile-term n vars
j ← kompile-term j vars
return $ "_div_SxS_ (" ⊕ k ⊕ " + (" ⊕ n ⊕ " + " ⊕ m ⊕ " - " ⊕ j ⊕ "), 1 + " ⊕ m ⊕ ")"
kompile-term (def (quote N._≟_) (arg _ a ∷ arg _ b ∷ [])) vars = do
a ← kompile-term a vars
b ← kompile-term b vars
return $ a ⊕ " == " ⊕ b
kompile-term (def (quote V._++_) args) vars = do
args ← kompile-arglist 6 args (# 4 ∷ # 5 ∷ []) vars
return $ "concat (" ⊕ args ⊕ ")"
kompile-term (def (quote V.tabulate) (_ ∷ arg _ ty ∷ X@(arg _ l) ∷ arg _ (vLam x e) ∷ [])) vars = do
kst ← R.get
let ctx = te-to-lvt vars --L.map (λ where (v , t) → v ∈ error "?" ~ t) $ TelView.tel vars
(rt , ps) = kompile-ty ty false $ record defaultPS{ kst = kst; ctx = ctx }
in-sh = sacty-shape =<< rt
bt = bt <$> rt
R.put (PS.kst ps)
iv ← kt-fresh "iv_"
let iv-type = vArg (def (quote Fin) (vArg l ∷ []))
l ← kompile-term l vars
b ← kompile-term e $ vars ++ [(iv , iv-type)]
return $ "with { (. <= " ⊕ iv ⊕ " <= .): " ⊕ b ⊕ "; }: genarray ([" ⊕ l ⊕ "], zero_" ⊕ bt ⊕ " (" ⊕ in-sh ⊕ "))"
kompile-term (def (quote ix-tabulate) (arg _ d ∷ X ∷ arg _ (vLam x e) ∷ [])) vars = do
iv ← kt-fresh "iv_"
let iv-type = vArg (def (quote Fin) (vArg d ∷ []))
d ← kompile-term d vars
b ← kompile-term e $ vars ++ [(iv , iv-type)]
return $ "with { (. <= " ⊕ iv ⊕ " <= .): " ⊕ b ⊕ "; }: genarray ([" ⊕ d ⊕ "], 0)"
-- Array stuff
kompile-term (def (quote sel) (_ ∷ _ ∷ _ ∷ _ ∷ arg _ a ∷ arg _ iv ∷ [])) vars = do
a ← kompile-term a vars
iv ← kompile-term iv vars
return $ a ⊕ "[" ⊕ iv ⊕ "]"
kompile-term (def (quote ix-lookup) (_ ∷ _ ∷ arg _ iv ∷ arg _ el ∷ [])) vars = do
iv ← kompile-term iv vars
el ← kompile-term el vars
return $ iv ⊕ "[" ⊕ el ⊕ "]"
kompile-term (def (quote V.lookup) (_ ∷ _ ∷ _ ∷ arg _ v ∷ arg _ i ∷ [])) vars = do
v ← kompile-term v vars
i ← kompile-term i vars
return $ v ⊕ "[" ⊕ i ⊕ "]"
kompile-term (def (quote V.foldr) (_ ∷ _ ∷ ty₁ ∷ arg _ (vLam _ ty₂) ∷ arg _ len ∷ arg _ (hLam _ (def f args)) ∷ arg _ neut ∷ arg _ arr ∷ [])) vars = do
let f = case list-find-el ((RN._≟ f) ∘ proj₁) SAC-funs of λ where
(just (_ , f)) → f
_ → nnorm $ showName f
len ← kompile-term len vars
neut ← kompile-term neut vars
arr ← kompile-term arr vars
iv ← kt-fresh "iv_"
return $ "with { ([0] <= " ⊕ iv ⊕ " < [" ⊕ len ⊕ "]): " ⊕ arr ⊕ "[" ⊕ iv ⊕ "]; }: fold (" ⊕ f ⊕ ", " ⊕ neut ⊕ ")"
kompile-term (def (quote reduce-1d) (_ ∷ _ ∷ arg _ s ∷ arg _ (def f args) ∷ arg _ ε ∷ arg _ a ∷ [])) vars = do
let f = case list-find-el ((RN._≟ f) ∘ proj₁) SAC-funs of λ where
(just (_ , f)) → f
_ → nnorm $ showName f
ε ← kompile-term ε vars
a ← kompile-term a vars
s ← kompile-term s vars
iv ← kt-fresh "iv_"
return $ "with { ([0] <= " ⊕ iv ⊕ " < " ⊕ s ⊕ "): " ⊕ a ⊕ "[" ⊕ iv ⊕ "]; }: fold (" ⊕ f ⊕ ", " ⊕ ε ⊕ ")"
kompile-term (def (quote reduce-1d) (Xa@(arg _ X) ∷ Ya@(arg _ Y) ∷ arg _ s ∷ arg _ L@(vLam a (vLam b e)) ∷ arg _ ε ∷ arg _ arr ∷ [])) vars = do
a ← kt-fresh "a"
b ← kt-fresh "b"
kst ← R.get
let (Xs , ps) = kompile-ty X false $ record defaultPS{ kst = kst; ctx = te-to-lvt vars }
(Ys , ps) = kompile-ty Y false $ record ps { ctx = PS.ctx ps ++ [ a ∈ Xs ~ Xa ] }
R.put $ PS.kst ps
t ← kompile-term e $ vars ++ (a , Xa) ∷ (b , Ya) ∷ [] -- (PS.ctx ps ++ [ b ∈ Ys ~ Ya ])
kst ← R.get
fname ← kt-fresh "lifted_"
let e , ps = kompile-ctx vars $ record defaultPS{ kst = kst }
vs = L.map {B = String × Prog} (λ where (v ∈ τ ~ _) → (v , (sacty-to-string <$> τ))) $′ PS.ctx ps
vs = vs ++ ((a , (sacty-to-string <$> Xs)) ∷ (b , (sacty-to-string <$> Ys)) ∷ [])
vs = ok ", " ++/ L.map (λ where (v , τ) → τ ⊕ " " ⊕ v) vs
fun = (sacty-to-string <$> Ys) ⊕ " " ⊕ fname ⊕ "(" ⊕ vs ⊕ ") "
⊕ "{ return " ⊕ t ⊕ "; }"
-- error out in case our current context was broken
(ok _) ← return e where (error x) → return (error x)
--R.modify $! λ k → record k{ defs = (KS.defs k ⊕_) $! fun }
kst ← R.get
R.put $! record kst{ defs = KS.defs kst ⊕ fun }
let part-app = fname ⊕ "(" ⊕ ", " ++/ L.map proj₁ vars ⊕ ")"
ε ← kompile-term ε vars
arr ← kompile-term arr vars
s ← kompile-term s vars
iv ← kt-fresh "iv_"
return $! "with { ([0] <= " ⊕ iv ⊕ " < " ⊕ s ⊕ "): " ⊕ arr ⊕ "[" ⊕ iv ⊕ "]; }: fold (" ⊕ part-app ⊕ ", " ⊕ ε ⊕ ")"
where
kompile-ctx : Telescope → SPS (Err ⊤)
kompile-ctx [] = return $ ok tt
kompile-ctx ((v , t@(arg i x)) ∷ ctx) = do
(ok τ) ← kompile-ty x false where (error x) → return $ error x
P.modify λ k → record k{ ctx = PS.ctx k ++ [ v ∈ ok τ ~ t ] }
kompile-ctx ctx
-- A bunch of functions that are mapped to id in sac
-- XXX get rid of id call, only keeping for debugging purposes.
kompile-term (def (quote F.fromℕ<) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 3 args (# 0 ∷ []) vars
kompile-term (def (quote F.toℕ) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 2 args (# 1 ∷ []) vars
kompile-term (def (quote subst-ar) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 7 args (# 6 ∷ []) vars
kompile-term (def (quote subst-ix) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 5 args (# 4 ∷ []) vars
kompile-term (def (quote ▾_) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 6 args (# 5 ∷ []) vars
kompile-term (def (quote ▴_) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 6 args (# 5 ∷ []) vars
kompile-term (def (quote a→ix) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 4 args (# 1 ∷ []) vars
kompile-term (def (quote a→s) args) vars = ("id (" ⊕_) ∘ (_⊕ ")") <$> kompile-arglist 2 args (# 1 ∷ []) vars
kompile-term (def (quote Array.Base.magic-fin) args) vars = return $ ok "unreachable ()"
kompile-term (def (quote Array.Base.off→idx) args) vars = do
args ← kompile-arglist 3 args (# 1 ∷ # 2 ∷ []) vars
return $ "off_to_idx (" ⊕ args ⊕ ")"
kompile-term (def (quote _↑_) args) vars = do
args ← kompile-arglist 7 args (# 4 ∷ # 5 ∷ []) vars
return $ "take (" ⊕ args ⊕ ")"
kompile-term (def (quote _↓_) args) vars = do
args ← kompile-arglist 7 args (# 4 ∷ # 5 ∷ []) vars
return $ "drop (" ⊕ args ⊕ ")"
kompile-term (def (quote _↑⟨_⟩_) args) vars = do
args ← kompile-arglist 7 args (# 4 ∷ # 5 ∷ # 6 ∷ []) vars
return $ "overtake (" ⊕ args ⊕ ")"
kompile-term (def (quote _-↑⟨_⟩_) args) vars = do
args ← kompile-arglist 7 args (# 4 ∷ # 5 ∷ # 6 ∷ []) vars
return $ "overtake_back (" ⊕ args ⊕ ")"
-- The last pattern in the list of `def` matches
kompile-term (def n []) _ =
kt $ "attempting to compile `" ++ showName n ++ "` as function with 0 arguments"
kompile-term (def n args@(_ ∷ _)) vars with list-find-el ((RN._≟ n) ∘ proj₁) SAC-funs
... | just (_ , f) = do
let l = L.length args
args ← kompile-arglist l args (mk-mask l) vars
return $ f ⊕ " (" ⊕ args ⊕ ")"
... | nothing = do
R.modify λ k → record k { funs = KS.funs k ++ [ n ] }
let n = nnorm $ showName n
l = L.length args
args ← kompile-arglist l args (mk-mask l) vars
return $ n ⊕ " (" ⊕ args ⊕ ")"
kompile-term t vctx = kt $ "failed to compile term `" ++ showTerm t ++ "`"
| {
"alphanum_fraction": 0.5436640238,
"avg_line_length": 38.052238806,
"ext": "agda",
"hexsha": "fc80c9e9e5af7dc98d0354eaa7f0d90414086e0e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-extractor",
"max_forks_repo_path": "ExtractSac.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "ashinkarov/agda-extractor",
"max_issues_repo_path": "ExtractSac.agda",
"max_line_length": 151,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-extractor",
"max_stars_repo_path": "ExtractSac.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z",
"num_tokens": 12859,
"size": 35693
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by strict partial orders
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.Properties.StrictPartialOrder
{s₁ s₂ s₃} (SPO : StrictPartialOrder s₁ s₂ s₃) where
open Relation.Binary.StrictPartialOrder SPO
renaming (trans to <-trans)
import Relation.Binary.StrictToNonStrict as Conv
open Conv _≈_ _<_
------------------------------------------------------------------------
-- Strict partial orders can be converted to posets
poset : Poset _ _ _
poset = record
{ isPartialOrder = record
{ isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = reflexive
; trans = trans isEquivalence <-resp-≈ <-trans
}
; antisym = antisym isEquivalence <-trans irrefl
}
}
open Poset poset public
| {
"alphanum_fraction": 0.5398963731,
"avg_line_length": 29.2424242424,
"ext": "agda",
"hexsha": "d62d245e11a916e1317fd67bcf04514c96faf230",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/StrictPartialOrder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/StrictPartialOrder.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/StrictPartialOrder.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 203,
"size": 965
} |
module Function.DomainRaise where
open import Data
open import Data.Boolean
import Functional as Fn
import Lvl
open import Numeral.Natural
open import Numeral.Natural.Oper.Comparisons
open import Syntax.Number
open import Type
private variable ℓ ℓ₁ ℓ₂ : Lvl.Level
private variable T X Y Z : Type{ℓ}
private variable n : ℕ
-- Repeated function type like an n-ary operator.
-- Examples:
-- (a →̂ b)(0) = (b)
-- (a →̂ b)(1) = (a → b)
-- (a →̂ b)(2) = (a → a → b)
-- (a →̂ b)(3) = (a → a → a → b)
-- (a →̂ b)(4) = (a → a → a → a → b)
_→̂_ : Type{ℓ₁} → Type{ℓ₂} → (n : ℕ) → Type{if positive?(n) then (ℓ₁ Lvl.⊔ ℓ₂) else ℓ₂} -- TODO: Is the level thing really working?
(A →̂ B)(𝟎) = B
(A →̂ B)(𝐒(𝟎)) = A → B
(A →̂ B)(𝐒(𝐒(n))) = A → (A →̂ B)(𝐒(n))
open import Data.Tuple
open import Data.Tuple.Raise
apply₁ : let _ = n in X → (X →̂ Y)(𝐒(n)) → (X →̂ Y)(n)
apply₁ {𝟎} = Fn.apply
apply₁ {𝐒 _} = Fn.apply
apply₊ : let _ = n in (X ^ n) → (X →̂ Y)(n) → Y
apply₊ {𝟎} <> f = f
apply₊ {𝐒(𝟎)} x f = f(x)
apply₊ {𝐒(𝐒(n))} (x , xs) f = apply₊ {𝐒(n)} xs (f(x))
-- Applies the same argument on all arguments.
-- Examples:
-- f : (a →̂ b)(5)
-- applyRepeated{0} f(x) = f
-- applyRepeated{1} f(x) = f(x)
-- applyRepeated{2} f(x) = f(x)(x)
-- applyRepeated{3} f(x) = f(x)(x)(x)
-- applyRepeated{2}(applyRepeated{3} f(x)) (y) = f(x)(x)(y)(y)(y)
applyRepeated : let _ = n in (X →̂ Y)(n) → (X → Y)
applyRepeated{𝟎} f(x) = f
applyRepeated{𝐒(𝟎)} f(x) = f(x)
applyRepeated{𝐒(𝐒(n))} f(x) = applyRepeated{𝐒(n)} (f(x)) (x)
{-
-- Applies arguments from a function.
-- Almost (not really) like a composition operation.
-- Examples:
-- f : (a →̂ b)(3)
-- applyFn f g = f (g(2)) (g(1)) (g(0))
applyFn : ∀{n}{T₁}{T₂} → (T₁ →̂ T₂)(n) → (𝕟(n) → T₁) → T₂
applyFn{𝟎} f g = f
applyFn{𝐒(n)} f g = applyFn{n} (f(g(ℕ-to-𝕟 (n) {𝐒(n)} ⦃ [<?]-𝐒 {n} ⦄))) (g ∘ (bound-𝐒{n}))
-- TODO: Examples:
-- swapReverse {3} f (y₂) (y₁) (y₀)
-- = swapReverse {2} (f(y₂)) (y₁) (y₀)
-- = swapReverse {1} (f(y₂) (y₁)) (y₀)
-- = swapReverse {0} (f(y₂) (y₁) (y₀))
-- = f(y₂) (y₁) (y₀)
-- swapReverse : ∀{n}{T₁}{T₂} → (T₁ →̂ T₂)(n) → (T₁ →̂ T₂)(n)
-- swapReverse {𝟎} y₀ = y₀
-- swapReverse {𝐒(n)} f(yₙ) = (swapReverse {n} f) ∘ (f(yₙ))
-- directOp : ∀{n}{X}{Y} → ((X → Y) →̂ ((X ^ n) → (Y ^ n)))(n)
-}
-- Function composition on a multi-argument function (Like PrimitiveRecursion.Composition).
-- Examples:
-- (f ∘₄ g) x₁ x₂ x₃ x₄
-- = (f ∘₃ g x₁) x₂ x₃ x₄
-- = (f ∘₂ g x₁ x₂) x₃ x₄
-- = (f ∘₁ g x₁ x₂ x₃) x₄
-- = (f ∘ g x₁ x₂ x₃) x₄
-- = f(g x₁ x₂ x₃ x₄)
_∘_ : let _ = n ; _ = X ; _ = Y ; _ = Z in (Y → Z) → (X →̂ Y)(n) → (X →̂ Z)(n)
_∘_ {𝟎} = Fn.id
_∘_ {𝐒(𝟎)} = Fn._∘_
_∘_ {𝐒(𝐒(n))} = Fn._∘_ Fn.∘ (_∘_) -- (f ∘ₙ₊₂ g)(x) = f ∘ₙ₊₁ g(x)
_∘[_]_ : let _ = X ; _ = Y ; _ = Z in (Y → Z) → (n : ℕ) → (X →̂ Y)(n) → (X →̂ Z)(n)
f ∘[ n ] g = _∘_ {n = n} f g
_∘₀_ = _∘_ {0}
_∘₁_ = _∘_ {1}
_∘₂_ = _∘_ {2}
_∘₃_ = _∘_ {3}
_∘₄_ = _∘_ {4}
_∘₅_ = _∘_ {5}
_∘₆_ = _∘_ {6}
_∘₇_ = _∘_ {7}
_∘₈_ = _∘_ {8}
_∘₉_ = _∘_ {9}
-- TODO: Flip the arguments and make n explicit
-- Single function composition on every argument.
-- (f on g)(y₁)(y₂).. = g (f(y₁)) (f(y₂)) ..
-- Examples:
-- _on_ {3} f g (y₂) (y₁) (y₀)
-- = _on_ {2} f (g (f(y₂))) (y₁) (y₀)
-- = _on_ {1} f (g (f(y₂)) (f(y₁))) (y₀)
-- = _on_ {0} f (g (f(y₂)) (f(y₁)) (f(y₀)))
-- = g (f(y₂)) (f(y₁)) (f(y₀))
on : let _ = n ; _ = X ; _ = Y ; _ = Z in (Y →̂ Z)(n) → (X → Y) → (X →̂ Z)(n)
on {n = 𝟎} = Fn.const
on {n = 𝐒(𝟎)} = Fn._∘_
on {n = 𝐒(𝐒(n))} f g(yₙ) = on {n = 𝐒(n)} (f(g(yₙ))) g
-- applyOnFn : ∀{n}{X}{Y} → (Y →̂ Y)(n) → ((X → Y) →̂ (X → Y))(n)
-- applyOnFn
-- Constructs a left-associated n-ary operator from a binary operator.
-- Example:
-- naryₗ{3} (_▫_) x₁ x₂ x₃ x₄ x₅
-- = ((naryₗ{2} (_▫_)) Fn.∘ (x₁ ▫_)) x₂ x₃ x₄
-- = (naryₗ{2} (_▫_) (x₁ ▫ x₂)) x₃ x₄ x₅
-- = ((naryₗ{1} (_▫_)) Fn.∘ ((x₁ ▫ x₂) ▫_)) x₃ x₄ x₅
-- = (naryₗ{1} (_▫_) ((x₁ ▫ x₂) ▫ x₃)) x₄ x₅
-- = ((naryₗ{0} (_▫_)) Fn.∘ (((x₁ ▫ x₂) ▫ x₃) ▫_)) x₃ x₄ x₅
-- = (naryₗ{0} (_▫_) (((x₁ ▫ x₂) ▫ x₃) ▫ x₄)) x₅
-- = ((_▫_) (((x₁ ▫ x₂) ▫ x₃) ▫ x₄)) x₅
-- = ((((x₁ ▫ x₂) ▫ x₃) ▫ x₄) ▫_) x₅
-- = (((x₁ ▫ x₂) ▫ x₃) ▫ x₄) x₅
naryₗ : (n : ℕ) → (X → X → X) → (X →̂ X)(𝐒(𝐒(n)))
naryₗ(𝟎) (_▫_) = (_▫_)
naryₗ(𝐒(n)) (_▫_) x = (naryₗ(n) (_▫_)) Fn.∘ (x ▫_)
-- Constructs a right-associated n-ary operator from a binary operator.
-- Example:
-- naryᵣ{3} (_▫_) x₁ x₂ x₃ x₄ x₅
-- = ((x₁ ▫_) ∘[ 4 ] (naryᵣ{2} (_▫_))) x₂ x₃ x₄ x₅
-- = x₁ ▫ (naryᵣ{2} (_▫_) x₂ x₃ x₄ x₅)
-- = x₁ ▫ (((x₂ ▫_) ∘[ 3 ] (naryᵣ{1} (_▫_))) x₃ x₄ x₅)
-- = x₁ ▫ (x₂ ▫ (naryᵣ{1} (_▫_) x₃ x₄ x₅))
-- = x₁ ▫ (x₂ ▫ (((x₃ ▫_) ∘[ 2 ] (naryᵣ{0} (_▫_))) x₄ x₅))
-- = x₁ ▫ (x₂ ▫ (x₃ ▫ (naryᵣ{0} (_▫_) x₄ x₅)))
-- = x₁ ▫ (x₂ ▫ (x₃ ▫ ((_▫_) x₄ x₅)))
-- = x₁ ▫ (x₂ ▫ (x₃ ▫ (x₄ ▫ x₅)))
naryᵣ : (n : ℕ) → (X → X → X) → (X →̂ X)(𝐒(𝐒(n)))
naryᵣ(𝟎) (_▫_) = (_▫_)
naryᵣ(𝐒(n)) (_▫_) x = (x ▫_) ∘[ 𝐒(𝐒(n)) ] (naryᵣ(n) (_▫_))
{-
[→̂]-to-[⇉] : (n : ℕ) → ∀{X : Type{ℓ₁}}{Y : Type{ℓ₂}} → (X →̂ Y)(n) → (RaiseType.repeat(n) X ⇉ Y)
[→̂]-to-[⇉] 0 f = f
[→̂]-to-[⇉] 1 f = f
[→̂]-to-[⇉] (𝐒(𝐒(n))) f = [→̂]-to-[⇉] (𝐒(n)) ∘ f
-}
| {
"alphanum_fraction": 0.4508758568,
"avg_line_length": 33.4522292994,
"ext": "agda",
"hexsha": "5ec00190515975ad679243188b2b5aaf2e76a26a",
"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": "Function/DomainRaise.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": "Function/DomainRaise.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": "Function/DomainRaise.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": 2971,
"size": 5252
} |
data Unit : Set where
tt : Unit
f : Unit
mutual
f = tt
| {
"alphanum_fraction": 0.5901639344,
"avg_line_length": 7.625,
"ext": "agda",
"hexsha": "db0d97da195d3096dbdf9236e2e8ae46d12dd165",
"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/Issue3932-2.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/Issue3932-2.agda",
"max_line_length": 21,
"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/Issue3932-2.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": 61
} |
{-# OPTIONS --without-K --exact-split --rewriting #-}
module index where
-- An organised list of modules:
import Pi.Everything
-- An exhaustive list of all modules:
| {
"alphanum_fraction": 0.7142857143,
"avg_line_length": 18.6666666667,
"ext": "agda",
"hexsha": "d87f2ae4b5001660ae1c58a2144e03aecb0c0941",
"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": "9626b9f570f248158ee14024c53831a4068109bf",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "vikraman/popl22-symmetries-artifact",
"max_forks_repo_path": "index.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "9626b9f570f248158ee14024c53831a4068109bf",
"max_issues_repo_issues_event_max_datetime": "2021-10-23T00:49:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-02T00:20:40.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "vikraman/popl22-symmetries-artifact",
"max_issues_repo_path": "index.agda",
"max_line_length": 53,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "9626b9f570f248158ee14024c53831a4068109bf",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "vikraman/popl22-symmetries-artifact",
"max_stars_repo_path": "index.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-09T01:49:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-20T03:36:59.000Z",
"num_tokens": 37,
"size": 168
} |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Transitivity
module Oscar.Class.Transassociativity where
module Transassociativity
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
{ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ) (let infix 4 _∼̇_ ; _∼̇_ = _∼̇_)
(transitivity : Transitivity.type _∼_) (let infixr 9 _∙_ ; _∙_ : FlipTransitivity.type _∼_; _∙_ g f = transitivity f g)
= ℭLASS (λ {x y} → _∼̇_ {x} {y} , (λ {x y z} → transitivity {x} {y} {z}))
(∀ {w x y z} (f : w ∼ x) (g : x ∼ y) (h : y ∼ z) → (h ∙ g) ∙ f ∼̇ h ∙ g ∙ f)
module _
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
{ℓ} {_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ}
{transitivity : Transitivity.type _∼_}
where
transassociativity = Transassociativity.method _∼_ _∼̇_ transitivity
syntax transassociativity f g h = h ⟨∙ g ⟨∙ f
module Transassociativity!
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯)
{ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ)
⦃ _ : Transitivity.class _∼_ ⦄
= Transassociativity (_∼_) (_∼̇_) transitivity
module _
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
{ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ)
⦃ _ : Transitivity.class _∼_ ⦄
where
transassociativity![_] = Transassociativity.method _∼_ _∼̇_ transitivity
| {
"alphanum_fraction": 0.5427419355,
"avg_line_length": 31.7948717949,
"ext": "agda",
"hexsha": "7ef49ea357b3fdbfa23d8e9612047fca5ccad215",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Transassociativity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Transassociativity.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Transassociativity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 639,
"size": 1240
} |
{-# OPTIONS --universe-polymorphism #-}
-- {-# OPTIONS --verbose tc.records.ifs:15 #-}
-- {-# OPTIONS --verbose tc.constr.findInScope:15 #-}
-- {-# OPTIONS --verbose tc.term.args.ifs:15 #-}
-- {-# OPTIONS --verbose cta.record.ifs:15 #-}
-- {-# OPTIONS --verbose tc.section.apply:25 #-}
-- {-# OPTIONS --verbose tc.mod.apply:100 #-}
-- {-# OPTIONS --verbose scope.rec:15 #-}
-- {-# OPTIONS --verbose tc.rec.def:15 #-}
module 07-subclasses where
open import Data.Bool hiding (_≟_)
open import Data.Nat hiding (_<_)
open import Relation.Nullary.Decidable
open import Function using (_$_; id)
record Eq (A : Set) : Set where
field eq : A → A → Bool
primEqBool : Bool → Bool → Bool
primEqBool true = id
primEqBool false = not
eqBool : Eq Bool
eqBool = record { eq = primEqBool }
primEqNat : ℕ → ℕ → Bool
primEqNat a b = ⌊ a ≟ b ⌋
primLtNat : ℕ → ℕ → Bool
primLtNat 0 _ = true
primLtNat (suc a) (suc b) = primLtNat a b
primLtNat _ _ = false
neq : {t : Set} → {{eqT : Eq t}} → t → t → Bool
neq a b = not $ eq a b
where open Eq {{...}}
record Ord₁ (A : Set) : Set where
field _<_ : A → A → Bool
eqA : Eq A
ord₁Nat : Ord₁ ℕ
ord₁Nat = record { _<_ = primLtNat; eqA = eqNat }
where eqNat : Eq ℕ
eqNat = record { eq = primEqNat }
record Ord₂ {A : Set} (eqA : Eq A) : Set where
field _<_ : A → A → Bool
ord₂Nat : Ord₂ (record { eq = primEqNat })
ord₂Nat = record { _<_ = primLtNat }
record Ord₃ (A : Set) : Set where
field _<_ : A → A → Bool
eqA : Eq A
open Eq eqA public
ord₃Nat : Ord₃ ℕ
ord₃Nat = record { _<_ = primLtNat; eqA = eqNat }
where eqNat : Eq ℕ
eqNat = record { eq = primEqNat }
record Ord₄ {A : Set} (eqA : Eq A) : Set where
field _<_ : A → A → Bool
open Eq eqA public
ord₄Nat : Ord₄ (record { eq = primEqNat })
ord₄Nat = record { _<_ = primLtNat }
module test₁ where
open Ord₁ {{...}}
open Eq {{...}}
eqNat = eqA
test₁ = 5 < 3
test₂ = eq 5 3
test₃ = eq true false
test₄ : {A : Set} → {{ ordA : Ord₁ A }} → A → A → Bool
test₄ a b = a < b ∨ eq a b
where eqA' = eqA
module test₂ where
open Ord₂ {{...}}
open Eq {{...}}
eqNat : Eq ℕ
eqNat = record { eq = primEqNat }
test₁ = 5 < 3
test₂ = eq 5 3
test₃ = eq true false
test₄ : {A : Set} → {eqA : Eq A} → {{ ordA : Ord₂ eqA }} → A → A → Bool
test₄ a b = a < b ∨ eq a b
module test₃ where
open Ord₃ {{...}}
open Eq {{...}} renaming (eq to eq')
test₁ = 5 < 3
test₂ = eq 5 3
test₃ = eq' true false
test₄ : {A : Set} → {{ ordA : Ord₃ A }} → A → A → Bool
test₄ a b = a < b ∨ eq a b
module test₄ where
open Ord₄ {{...}}
open Eq {{...}} renaming (eq to eq')
test₁ = 5 < 3
test₂ = eq 5 3
test₃ = eq' true false
test₄ : {A : Set} → {eqA : Eq A} → {{ ordA : Ord₄ eqA }} → A → A → Bool
test₄ a b = a < b ∨ eq a b
module test₄′ where
open Ord₄ {{...}} hiding (eq)
open Eq {{...}}
eqNat : Eq ℕ
eqNat = record { eq = primEqNat }
test₁ = 5 < 3
test₂ = eq 5 3
test₃ = eq true false
test₄ : {A : Set} → {eqA : Eq A} → {{ ordA : Ord₄ eqA }} → A → A → Bool
test₄ a b = a < b ∨ eq a b
| {
"alphanum_fraction": 0.5657809462,
"avg_line_length": 22.8592592593,
"ext": "agda",
"hexsha": "a9541a57d7c9990c191a58a727e7ca7ce8699df9",
"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": "4383a3d20328a6c43689161496cee8eb479aca08",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dagit/agda",
"max_forks_repo_path": "examples/instance-arguments/07-subclasses.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08",
"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": "dagit/agda",
"max_issues_repo_path": "examples/instance-arguments/07-subclasses.agda",
"max_line_length": 73,
"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/instance-arguments/07-subclasses.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T07:26:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T07:26:06.000Z",
"num_tokens": 1177,
"size": 3086
} |
module QualifiedConstructors where
data Nat₁ : Set where
zero : Nat₁
suc : Nat₁ → Nat₁
data Nat₂ : Set where
zero : Nat₂
suc : Nat₂ → Nat₂
zero₁ = Nat₁.zero
one₂ = Nat₂.suc Nat₂.zero
record Suc : Set where
constructor suc
field n : Nat₁
one₃ = Suc.suc zero₁
pred : Suc → Nat₁
pred s = Suc.n s
conv : Nat₂ → Nat₁
conv Nat₂.zero = Nat₁.zero
conv (Nat₂.suc n) = Nat₁.suc (conv n)
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
inj : (n m : Nat₁) → Nat₁.suc n ≡ suc m → n ≡ m
inj .m m refl = refl
| {
"alphanum_fraction": 0.6214689266,
"avg_line_length": 16.0909090909,
"ext": "agda",
"hexsha": "1744dcf992da82c2f80b2f7024b41e5b4f7f276c",
"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": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/Succeed/QualifiedConstructors.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Succeed/QualifiedConstructors.agda",
"max_line_length": 47,
"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/QualifiedConstructors.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": 211,
"size": 531
} |
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Weight biased leftist heap that proves rank invariant and uses --
-- a single-pass merging algorithm. --
----------------------------------------------------------------------
module SinglePassMerge.RankProof where
open import Basics
-- We import rank proofs conducted earlier - they will be re-used.
open import TwoPassMerge.RankProof
using ( makeT-lemma )
renaming ( proof-1 to proof-1a; proof-2 to proof-2a )
data Heap : Nat → Set where
empty : Heap zero
node : Priority → {l r : Nat} → l ≥ r → Heap l → Heap r → Heap (suc (l + r))
-- Note [Privoving rank invariant in single-pass merge]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- Recall that in TwoPassMerge.RankProof we need to prove that:
--
-- 1) makeT constructs node of correct size. There were two cases:
--
-- a) constructing a node without swapping l and r subtrees passed
-- to makeT. No extra proof was required as everything followed
-- from definitions.
--
-- b) constructing a node by swapping l and r subtrees (when rank
-- of r was greater than rank of l). We had to prove that:
--
-- suc (a + b) ≡ suc (b + a)
--
-- This proof is supplied by a function makeT-lemma.
--
-- 2) resulting heap produced by merge has correct size. Merge has 4
-- cases (see [Two-pass merging algorithm]):
--
-- a) h1 is empty. No extra proof required (everything follows
-- from definition of +). See [merge, proof 0a].
--
-- b) h2 is empty. We had to prove that:
--
-- h1 ≡ h1 + 0
--
-- This proof is supplied by +0 (in Basics.Reasoning) and is
-- inlined in the definition of merge. See [merge, proof 0b].
--
-- c) priority p1 is higher than p2. We had to prove:
--
-- suc (l1 + (r1 + suc (l2 + r2)))
-- ≡ suc ((l1 + r1) + suc (l2 + r2))
--
-- This proof is supplied by proof-1 (renamed to proof-1a in
-- this module). See [merge, proof 1] for details.
--
-- d) priority p2 is higher than p1. We had to prove:
--
-- suc (l2 + (r2 + suc (l1 + r1)))
-- ≡ suc ((l1 + r1) + suc (l2 + r2))
--
-- This proof is supplied by proof-2 (renamed to proof-2a in
-- this module). See [merge, proof 2] for details.
--
-- Now that we inline makeT into merge and we will have to construct
-- new proofs of merge that take into account the fact that makeT has
-- been inlinined. Let's take a detailed look into the problem and
-- analyze possible solutions.
--
-- First of all let us note that we only made calls to makeT in
-- inductive cases of merge (points 2c and 2d above). This means that
-- implementation of base cases of merge (2a and 2b above) remains
-- unchanged. Let's take a look at proofs we need to supply for each
-- of four inductive cases of merge (see [Single-pass merging
-- algorithm] for description of each case):
--
-- 1) case c described in [Single-pass merging algorithm]. Call to
-- makeT would not swap left and right when creating a node from
-- parameters passed to it. Required proof is:
--
-- suc (l1 + (r1 + suc (l2 + r2)))
-- ≡ suc ((l1 + r1) + suc (l2 + r2))
--
-- 2) case d described in [Single-pass merging algorithm]. Call to
-- makeT would swap left and right when creating a node from
-- parameters passed to it. Required proof is:
--
-- suc ((r1 + suc (l2 + r2)) + l1)
-- ≡ suc ((l1 + r1) + suc (l2 + r2))
--
-- 3) case e described in [Single-pass merging algorithm]. Call to
-- makeT would not swap left and right when creating a node from
-- parameters passed to it. Required proof is:
--
-- suc (l2 + (r2 + suc (l1 + r1)))
-- ≡ suc ((l1 + r1) + suc (l2 + r2))
--
-- 4) case f described in [Single-pass merging algorithm]. Call to
-- makeT would swap left and right when creating a node from
-- parameters passed to it. Required proof is:
--
-- suc ((r2 + suc (l1 + r1)) + l2)
-- ≡ suc ((l1 + r1) + suc (l2 + r2))
--
-- First of all we must note that proofs required in cases 1 and 3 are
-- exactly the same as in the two-pass merging algorithm. This allows
-- us to re-use the old proofs (renamed to proof-1a and proof-2a
-- here). What about proofs of cases 2 and 4? One thing we could do is
-- construct proofs of these properties using technique described in
-- Note [Constructing equality proofs using transitivity]. This is
-- left as an exercise to the reader. Here we will proceed in a
-- different way. Notice that properties we have to prove in cases for
-- 2 and 4 are very similar to properties 1 and 3 (we omit the RHS
-- since it is always the same):
--
-- 1: suc (l1 + (r1 + suc (l2 + r2)))
-- 2: suc ((r1 + suc (l2 + r2)) + l1)
--
-- 3: suc (l2 + (r2 + suc (l1 + r1)))
-- 4: suc ((r2 + suc (l1 + r1)) + l2)
--
-- The only difference between 1 and 2 and between 3 and 4 is the
-- order of parameters inside outer suc. This is expected: in cases 2
-- and 4 we swap left and right subtree passed to node and this is
-- reflected in the types. Now, if we could prove that:
--
-- suc ((r1 + suc (l2 + r2)) + l1)
-- ≡ suc (l1 + (r1 + suc (l2 + r2)))
--
-- and
--
-- suc ((r2 + suc (l1 + r1)) + l2)
-- ≡ suc (l2 + (r2 + suc (l1 + r1)))
--
-- then we could use transitivity to combine these new proofs with old
-- proof-1a and proof-2a. If we abstract the parameters in the above
-- equalities we see that the property we need to prove is:
--
-- suc (a + b) ≡ suc (b + a)
--
-- And that happens to be makeT-lemma! New version of merge was
-- created by inlining calls to make and now it turns out we can
-- construct proofs of that implementation by using proofs of
-- makeT. This leads us to very elegant solutions presented below.
proof-1b : (l1 r1 l2 r2 : Nat) → suc ((r1 + suc (l2 + r2)) + l1)
≡ suc ((l1 + r1) + suc (l2 + r2))
proof-1b l1 r1 l2 r2 = trans (makeT-lemma (r1 + suc (l2 + r2)) l1)
(proof-1a l1 r1 l2 r2)
proof-2b : (l1 r1 l2 r2 : Nat) → suc ((r2 + suc (l1 + r1)) + l2)
≡ suc ((l1 + r1) + suc (l2 + r2))
proof-2b l1 r1 l2 r2 = trans (makeT-lemma (r2 + suc (l1 + r1)) l2)
(proof-2a l1 r1 l2 r2)
-- We can now use proof-1a, proof-1b, proof-2a and proof-2b in
-- definition of merge.
merge : {l r : Nat} → Heap l → Heap r → Heap (l + r)
merge {zero} {_} empty h2 = h2
merge {suc l} {zero} h1 empty = subst Heap (sym (+0 (suc l))) h1
merge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)
with p1 < p2
| order l1-rank (r1-rank + suc (l2-rank + r2-rank))
| order l2-rank (r2-rank + suc (l1-rank + r1-rank))
merge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)
| true
| ge l1≥r1+h2
| _
= subst Heap
(proof-1a l1-rank r1-rank l2-rank r2-rank)
(node p1 l1≥r1+h2 l1 (merge r1 (node p2 l2≥r2 l2 r2)))
merge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)
| true
| le l1≤r1+h2
| _
= subst Heap
(proof-1b l1-rank r1-rank l2-rank r2-rank)
(node p1 l1≤r1+h2 (merge r1 (node p2 l2≥r2 l2 r2)) l1)
merge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)
| false
| _
| ge l2≥r2+h1
= subst Heap
(proof-2a l1-rank r1-rank l2-rank r2-rank)
(node p2 l2≥r2+h1 l2 (merge r2 (node p1 l1≥r1 l1 r1)))
merge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)
| false
| _
| le l2≤r2+h1
= subst Heap
(proof-2b l1-rank r1-rank l2-rank r2-rank)
(node p2 l2≤r2+h1 (merge r2 (node p1 l1≥r1 l1 r1)) l2)
| {
"alphanum_fraction": 0.5639494834,
"avg_line_length": 41.875,
"ext": "agda",
"hexsha": "d5e00bbf93142864f4d6ef41175f416092cfaca2",
"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": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_forks_repo_path": "src/SinglePassMerge/RankProof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"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": "jstolarek/dep-typed-wbl-heaps",
"max_issues_repo_path": "src/SinglePassMerge/RankProof.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_stars_repo_path": "src/SinglePassMerge/RankProof.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z",
"num_tokens": 2841,
"size": 8710
} |
{-# OPTIONS --without-K --safe --overlapping-instances #-}
module Examples where
open import Data.Nat
-- local imports
open import Interpreter
pf : y' ∈ y' ::: `ℕ , (x' ::: `ℕ , ·)
pf = H
pf2 : x' ∈ y' ::: `ℕ , (x' ::: `ℕ , ·)
pf2 = TH
testSimpleLambda : · ⊢ `ℕ
testSimpleLambda = (`λ x' `: `ℕ ⇨ (`v x' `+ `v x')) `₋ `n 10
testSimpleLambda2 : · ⊢ `ℕ `⇨ `ℕ
testSimpleLambda2 = `λ x' `: `ℕ ⇨ (`v x') `+ (`v x')
testNestedLambda : · ⊢ `ℕ
testNestedLambda = (`λ x' `: `ℕ ⇨ (`λ_`:_⇨_ y' `ℕ (`v x' `* `v y'))) `₋ `n 10 `₋ `n 15
testNestedLambda2 : · ⊢ `ℕ `⇨ `ℕ `⇨ `ℕ
testNestedLambda2 = (`λ x' `: `ℕ ⇨ (`λ_`:_⇨_ y' `ℕ (`v x' `* `v y')))
-- The following definitions do not type check. They are a relic from
-- when the interpreter still had some bugs. Uncomment them to verify
-- they don't type check
-- testNamingNotWorking : · ⊢ `Bool
-- testNamingNotWorking = (`λ x' `: `Bool ⇨ (`λ x' `: `⊤ ⇨ `v x')) `₋ `true `₋ `tt
-- testNamingNotWorking2 : · ⊢ `Bool `⇨ `⊤ `⇨ `Bool -- incorrect type!
-- testNamingNotWorking2 = `λ x' `: `Bool ⇨ (`λ x' `: `⊤ ⇨ `v x')
testNamingWorking : · ⊢ `⊤
testNamingWorking = (`λ x' `: `Bool ⇨ (`λ x' `: `⊤ ⇨ `v x')) `₋ `true `₋ `tt
testNamingWorking2 : · ⊢ `Bool `⇨ `⊤ `⇨ `⊤
testNamingWorking2 = `λ x' `: `Bool ⇨ (`λ x' `: `⊤ ⇨ `v x')
testSum1 : · ⊢ `ℕ
testSum1 = `let z' `= `case `left (`n 10) `of
`λ z' `: `ℕ ⇨ `v z'
|| `λ x' `: `Bool ⇨ `if `v x' `then `n 1 `else `n 0
`in `v z'
testSum2 : · ⊢ `ℕ
testSum2 = `let z' `= `case `right `true `of
`λ z' `: `ℕ ⇨ `v z'
|| `λ x' `: `Bool ⇨ `if `v x' `then `n 1 `else `n 0
`in `v z'
testProduct1 : · ⊢ `Bool
testProduct1 = `fst (`true `, (`n 10 `, `tt ))
testProduct2 : · ⊢ `ℕ `× `⊤
testProduct2 = `snd (`true `, (`n 10 `, `tt ))
testDeMorganFullOr : · ⊢ `Bool
testDeMorganFullOr = `let z' `= `λ x' `: `Bool ⇨ `λ y' `: `Bool ⇨ `¬ (`v x' `∨ `v y')
`in `v z' `₋ `true `₋ `true
testDeMorganBrokenAnd : · ⊢ `Bool
testDeMorganBrokenAnd = `let z' `= `λ x' `: `Bool ⇨ `λ y' `: `Bool ⇨ `¬ `v x' `∧ `¬ `v y'
`in `v z' `₋ `true `₋ `true
tester : Set
tester = {! interpret testSimpleLambda2 !}
| {
"alphanum_fraction": 0.4782608696,
"avg_line_length": 31.3055555556,
"ext": "agda",
"hexsha": "2cea4ed3e8ddad15d1d3c7e98c02fb21ee56c6bb",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-06-18T12:31:11.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-18T06:14:18.000Z",
"max_forks_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sseefried/well-typed-agda-interpreter",
"max_forks_repo_path": "Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c",
"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": "sseefried/well-typed-agda-interpreter",
"max_issues_repo_path": "Examples.agda",
"max_line_length": 89,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sseefried/well-typed-agda-interpreter",
"max_stars_repo_path": "Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-18T12:37:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-18T12:06:14.000Z",
"num_tokens": 975,
"size": 2254
} |
module Data.Bin.Rec where
open import Data.Bin hiding (suc; fromℕ)
open import Induction.WellFounded
open import Data.Nat using (ℕ; zero; suc) renaming (_<_ to _ℕ<_)
open import Data.Nat.Properties
open import Relation.Binary.PropositionalEquality
open import Data.Bin.Bijection
import Induction.Nat
wf : Well-founded _<_
wf x = go' x where
P : ℕ → Set
P x = Acc _<_ (fromℕ x)
podgon : ∀ {y} → P (toℕ y) → Acc _<_ y
podgon = subst (λ q → Acc _<_ q) (fromToℕ-inverse _)
go'' : (x : ℕ) → ((y : ℕ) → y ℕ< x → P y) → P x
go'' x rec = acc (λ { y (less ty<tfx) → podgon (rec (toℕ y) (subst (λ q → toℕ y ℕ< q) (toFromℕ-inverse x) ty<tfx ) )})
go : (x : ℕ) → P x
go = Induction.Nat.<-rec P go''
go' : (x : Bin) → Acc _<_ x
go' x = podgon (go (toℕ x))
open All wf
rec : ∀ (P : Bin → Set) → ((a : Bin) → ((a' : Bin) → (a' < a) → P a') → P a) → (a : Bin) → P a
rec P f = wfRec _ P f
| {
"alphanum_fraction": 0.578539823,
"avg_line_length": 25.1111111111,
"ext": "agda",
"hexsha": "8d0f1a07fc3fca664bd82c6b246b6f3acb32d888",
"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": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "Rotsor/BinDivMod",
"max_forks_repo_path": "Data/Bin/Rec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"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": "Rotsor/BinDivMod",
"max_issues_repo_path": "Data/Bin/Rec.agda",
"max_line_length": 120,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Rotsor/BinDivMod",
"max_stars_repo_path": "Data/Bin/Rec.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-18T13:58:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-18T13:58:14.000Z",
"num_tokens": 364,
"size": 904
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Core lemmas needed to make list argmin/max functions work
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Trans; TotalOrder; Setoid)
module Data.List.Extrema.Core
{b ℓ₁ ℓ₂} (totalOrder : TotalOrder b ℓ₁ ℓ₂) where
open import Algebra.Core
open import Algebra.Definitions
import Algebra.Construct.NaturalChoice.Min as Min
import Algebra.Construct.NaturalChoice.Max as Max
open import Data.Product using (_×_; _,_)
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
open import Level using (Level)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Algebra.Construct.LiftedChoice
open TotalOrder totalOrder renaming (Carrier to B)
open import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_
using (_<_; <-≤-trans; ≤-<-trans)
------------------------------------------------------------------------
-- Setup
-- open NonStrictToStrict totalOrder using (_<_; ≤-<-trans; <-≤-trans)
open Max totalOrder
open Min totalOrder
private
variable
a : Level
A : Set a
<-transʳ : Trans _≤_ _<_ _<_
<-transʳ = ≤-<-trans trans antisym ≤-respˡ-≈
<-transˡ : Trans _<_ _≤_ _<_
<-transˡ = <-≤-trans Eq.sym trans antisym ≤-respʳ-≈
module _ (f : A → B) where
lemma₁ : ∀ {x y v} → f x ≤ v → f x ⊓ f y ≈ f y → f y ≤ v
lemma₁ fx≤v fx⊓fy≈fy = trans (x⊓y≈y⇒y≤x fx⊓fy≈fy) fx≤v
lemma₂ : ∀ {x y v} → f y ≤ v → f x ⊓ f y ≈ f x → f x ≤ v
lemma₂ fy≤v fx⊓fy≈fx = trans (x⊓y≈x⇒x≤y fx⊓fy≈fx) fy≤v
lemma₃ : ∀ {x y v} → f x < v → f x ⊓ f y ≈ f y → f y < v
lemma₃ fx<v fx⊓fy≈fy = <-transʳ (x⊓y≈y⇒y≤x fx⊓fy≈fy) fx<v
lemma₄ : ∀ {x y v} → f y < v → f x ⊓ f y ≈ f x → f x < v
lemma₄ fx<v fx⊓fy≈fy = <-transʳ (x⊓y≈x⇒x≤y fx⊓fy≈fy) fx<v
------------------------------------------------------------------------
-- Definition of lifted max and min
⊓ᴸ : (A → B) → Op₂ A
⊓ᴸ = Lift _≈_ _⊓_ ⊓-sel
⊔ᴸ : (A → B) → Op₂ A
⊔ᴸ = Lift _≈_ _⊔_ ⊔-sel
------------------------------------------------------------------------
-- Properties of ⊓ᴸ
⊓ᴸ-sel : ∀ f → Selective {A = A} _≡_ (⊓ᴸ f)
⊓ᴸ-sel f = sel-≡ ⊓-isSelectiveMagma f
⊓ᴸ-presᵒ-≤v : ∀ f {v} (x y : A) → f x ≤ v ⊎ f y ≤ v → f (⊓ᴸ f x y) ≤ v
⊓ᴸ-presᵒ-≤v f = preservesᵒ ⊓-isSelectiveMagma f (lemma₁ f) (lemma₂ f)
⊓ᴸ-presᵒ-<v : ∀ f {v} (x y : A) → f x < v ⊎ f y < v → f (⊓ᴸ f x y) < v
⊓ᴸ-presᵒ-<v f = preservesᵒ ⊓-isSelectiveMagma f (lemma₃ f) (lemma₄ f)
⊓ᴸ-presᵇ-v≤ : ∀ f {v} {x y : A} → v ≤ f x → v ≤ f y → v ≤ f (⊓ᴸ f x y)
⊓ᴸ-presᵇ-v≤ f {v} = preservesᵇ ⊓-isSelectiveMagma {P = λ x → v ≤ f x} f
⊓ᴸ-presᵇ-v< : ∀ f {v} {x y : A} → v < f x → v < f y → v < f (⊓ᴸ f x y)
⊓ᴸ-presᵇ-v< f {v} = preservesᵇ ⊓-isSelectiveMagma {P = λ x → v < f x} f
⊓ᴸ-forcesᵇ-v≤ : ∀ f {v} (x y : A) → v ≤ f (⊓ᴸ f x y) → v ≤ f x × v ≤ f y
⊓ᴸ-forcesᵇ-v≤ f {v} = forcesᵇ ⊓-isSelectiveMagma f
(λ v≤fx fx⊓fy≈fx → trans v≤fx (x⊓y≈x⇒x≤y fx⊓fy≈fx))
(λ v≤fy fx⊓fy≈fy → trans v≤fy (x⊓y≈y⇒y≤x fx⊓fy≈fy))
------------------------------------------------------------------------
-- Properties of ⊔ᴸ
⊔ᴸ-sel : ∀ f → Selective {A = A} _≡_ (⊔ᴸ f)
⊔ᴸ-sel f = sel-≡ ⊔-isSelectiveMagma f
⊔ᴸ-presᵒ-v≤ : ∀ f {v} (x y : A) → v ≤ f x ⊎ v ≤ f y → v ≤ f (⊔ᴸ f x y)
⊔ᴸ-presᵒ-v≤ f {v} = preservesᵒ ⊔-isSelectiveMagma f
(λ v≤fx fx⊔fy≈fy → trans v≤fx (x⊔y≈y⇒x≤y fx⊔fy≈fy))
(λ v≤fy fx⊔fy≈fx → trans v≤fy (x⊔y≈x⇒y≤x fx⊔fy≈fx))
⊔ᴸ-presᵒ-v< : ∀ f {v} (x y : A) → v < f x ⊎ v < f y → v < f (⊔ᴸ f x y)
⊔ᴸ-presᵒ-v< f {v} = preservesᵒ ⊔-isSelectiveMagma f
(λ v<fx fx⊔fy≈fy → <-transˡ v<fx (x⊔y≈y⇒x≤y fx⊔fy≈fy))
(λ v<fy fx⊔fy≈fx → <-transˡ v<fy (x⊔y≈x⇒y≤x fx⊔fy≈fx))
⊔ᴸ-presᵇ-≤v : ∀ f {v} {x y : A} → f x ≤ v → f y ≤ v → f (⊔ᴸ f x y) ≤ v
⊔ᴸ-presᵇ-≤v f {v} = preservesᵇ ⊔-isSelectiveMagma {P = λ x → f x ≤ v} f
⊔ᴸ-presᵇ-<v : ∀ f {v} {x y : A} → f x < v → f y < v → f (⊔ᴸ f x y) < v
⊔ᴸ-presᵇ-<v f {v} = preservesᵇ ⊔-isSelectiveMagma {P = λ x → f x < v} f
⊔ᴸ-forcesᵇ-≤v : ∀ f {v} (x y : A) → f (⊔ᴸ f x y) ≤ v → f x ≤ v × f y ≤ v
⊔ᴸ-forcesᵇ-≤v f {v} = forcesᵇ ⊔-isSelectiveMagma f
(λ fx≤v fx⊔fy≈fx → trans (x⊔y≈x⇒y≤x fx⊔fy≈fx) fx≤v)
(λ fy≤v fx⊔fy≈fy → trans (x⊔y≈y⇒x≤y fx⊔fy≈fy) fy≤v)
| {
"alphanum_fraction": 0.5043601226,
"avg_line_length": 35.0661157025,
"ext": "agda",
"hexsha": "845582cfcd468b1ec9f5a46785b6fcfd45d11fcd",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Extrema/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Extrema/Core.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Extrema/Core.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": 2158,
"size": 4243
} |
{-# OPTIONS -W error #-}
module Issue2596a where
{-# REWRITE #-}
-- We will never encounter this, because the harmless warning above
-- has been turned into an error
f : Set
f = f
| {
"alphanum_fraction": 0.6868131868,
"avg_line_length": 18.2,
"ext": "agda",
"hexsha": "c8a3d76d925d402755d337bba4fd9ad0553a21ea",
"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/Issue2596a.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/Issue2596a.agda",
"max_line_length": 67,
"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/Issue2596a.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": 46,
"size": 182
} |
module Issue450 where
open import Common.Level
open import Common.Coinduction
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
data Wrap (A : Set) : Set where
con : A -> Wrap A
out : forall {A} -> Wrap A -> A
out (con x) = x
out' : forall {A} -> ∞ (Wrap A) -> A
out' y = out (♭ y)
inn : forall {A} -> A -> ∞ (Wrap A)
inn y = ♯ (con y)
prf : (A : Set)(x : A) → out' (inn x) ≡ x
prf A x = refl
test : forall {A : Set}{x : A} -> out (con x) ≡ x
test = refl
-- these work
test1 : forall {A}{x : A} -> out' (inn x) ≡ x
test1 {A} {x} = test
test2 : forall {A}{x : A} -> out' (inn x) ≡ x
test2 {A} {x} = test {A}
-- but the following ones won't typecheck
test3 : forall {A}{x : A} -> out' (inn x) ≡ x
test3 {A} {x} = test {A} {x}
test4 : forall {A}{x : A} -> out' (inn x) ≡ x
test4 {A} {x} = refl
| {
"alphanum_fraction": 0.5263803681,
"avg_line_length": 19.4047619048,
"ext": "agda",
"hexsha": "731d4f62d17502b2854eea6208f48efb4f79585c",
"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/Issue450.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"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": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue450.agda",
"max_line_length": 49,
"max_stars_count": 3,
"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/Issue450.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": 346,
"size": 815
} |
-- Andreas, 2017-09-09, re issue #2732
-- eta-contraction needed in termination checker
-- {-# OPTIONS -v term:30 #-}
open import Agda.Builtin.Equality
data O (A : Set) : Set where
leaf : O A
node : (A → O A) → O A
postulate
A : Set
a : A
test1 : (t u : O A) → O A
test1 leaf leaf = leaf
test1 leaf (node g) = test1 leaf (g a)
test1 (node f) leaf = test1 (f a) (node f)
test1 (node f) (node g) = test1 (node λ x → f x) (g a)
-- Should pass even with the eta-expansion.
data Q (A : Set) : Set where
leaf : Q A
node : (f g : A → Q A) (p : f ≡ g) → Q A
-- Having various call arguments in eta-expanded form.
test : (t u : Q A) → Q A
test leaf leaf = leaf
test leaf (node f g p) = test leaf (f a)
test (node f g p) leaf = test (g a) (node f g p)
test (node f .f refl) (node g g' p) = test (node (λ x → f x) _ refl) (g' a)
| {
"alphanum_fraction": 0.5826494725,
"avg_line_length": 25.8484848485,
"ext": "agda",
"hexsha": "f589490310bf7a82fefec302e8ec05725580b1a4",
"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/Issue2732-termination.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/Issue2732-termination.agda",
"max_line_length": 75,
"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/Issue2732-termination.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": 321,
"size": 853
} |
-- Andreas, 2017-10-11, issue #2796
-- A failed check for projection-likeness
-- made the overloaded projection not resolve.
-- {-# OPTIONS -v tc.proj.like:100 #-}
-- {-# OPTIONS -v tc.proj.amb:100 #-}
postulate
L : Set
lzero : L
Type : L → Set
El : ∀{l} → Type l → Set
record Pred (A : Set) l : Set where -- Works without l
field
app : A → Type l
record Sub l : Set1 where
field
Carrier : Set
pred : Pred Carrier l
open Pred pred public
open Pred -- Works without this (of course)
open Sub
test : (S T : Sub lzero) → (f : S .Carrier → T .Carrier) → Set
test S T f = (a : S .Carrier) → El (S .app a) → El (T .app (f a))
-- Problem WAS:
-- Cannot resolve overloaded projection app because no matching candidate found
-- when checking that the expression S .app a has type
-- Type (_l_22 S T f a)
-- Should succeed.
| {
"alphanum_fraction": 0.6245654693,
"avg_line_length": 23.3243243243,
"ext": "agda",
"hexsha": "de905e89be317b58b8a62ec110f5b00ddcbc67e4",
"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/Issue2796.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/Issue2796.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/Issue2796.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": 267,
"size": 863
} |
-- Andreas, 2012-01-13, error reported by Rob Simmons
module Issue555 where
data Exp : Set
data Exp Γ where -- internal error
| {
"alphanum_fraction": 0.7421875,
"avg_line_length": 18.2857142857,
"ext": "agda",
"hexsha": "f54cc8014c386789dbed7e347988dd5a65f42d6b",
"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/Issue555.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/Issue555.agda",
"max_line_length": 53,
"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/Issue555.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 35,
"size": 128
} |
open import Oscar.Prelude
open import Oscar.Data.𝟘
module Oscar.Data.Decidable where
data Decidable {a} (A : Ø a) : Ø a where
↑_ : A → Decidable A
↓_ : ¬ A → Decidable A
| {
"alphanum_fraction": 0.6723163842,
"avg_line_length": 17.7,
"ext": "agda",
"hexsha": "51983468e78936d23fd3079b722c0870e9ed9964",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Data/Decidable.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Data/Decidable.agda",
"max_line_length": 40,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Data/Decidable.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 61,
"size": 177
} |
open import Relation.Binary hiding (_⇒_)
module Category.Monad.Monotone.Error {i}(pre : Preorder i i i)(Exc : Set i) where
open Preorder pre renaming (Carrier to I; _∼_ to _≤_; refl to ≤-refl)
open import Function
open import Level hiding (lift)
open import Data.Sum
open import Relation.Unary
open import Relation.Unary.Monotone pre
open import Relation.Unary.PredicateTransformer
open import Category.Monad.Monotone pre
open import Category.Monad.Monotone.Identity pre
pattern left x = inj₁ x
pattern right x = inj₂ x
ErrorT : Pt I i → Pt I i
ErrorT M P = M (λ i → Exc ⊎ P i)
Error = ErrorT Identity
record ErrorMonad (M : Pt I i) : Set (suc i) where
field
throw : ∀ {P i} → Exc → M P i
try_catch_ : ∀ {P} → M P ⊆ ((const Exc ↗ M P) ⇒ M P)
module _ {M} ⦃ Mon : RawMPMonad M ⦄ where
private module M = RawMPMonad Mon
open RawMPMonad
errorT-monad : RawMPMonad (ErrorT M)
return errorT-monad px = M.return (right px)
_≥=_ errorT-monad {P}{Q} px f = px M.≥= λ where
_ (left e) → M.return (left e)
w (right x) → f w x
open ErrorMonad
errorT-monad-ops : ErrorMonad (ErrorT M)
throw errorT-monad-ops e = M.return (left e)
try_catch_ errorT-monad-ops c f = c M.≥= λ where
w (left e) → f w e
w (right x) → M.return (right x)
lift-error : ∀ {P} → M P ⊆ ErrorT M P
lift-error x = x M.>>= (λ z → M.return (right z))
module Instances where
-- Defining instances for the transformer
-- leads to divergence of instance search,
-- because M is on the outside.
instance
open RawMPMonad
error-monad : RawMPMonad Error
error-monad = errorT-monad
open ErrorMonad
error-monad-ops : ErrorMonad Error
error-monad-ops = errorT-monad-ops
| {
"alphanum_fraction": 0.67112922,
"avg_line_length": 27.2698412698,
"ext": "agda",
"hexsha": "36fbd50dda712bf553063904008c34931aee35d5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/Category/Monad/Monotone/Error.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/Category/Monad/Monotone/Error.agda",
"max_line_length": 81,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/Category/Monad/Monotone/Error.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 561,
"size": 1718
} |
{-# OPTIONS --cubical-compatible --sized-types #-}
------------------------------------------------------------------------
-- From the Agda standard library
--
-- Sizes for Agda's sized types
------------------------------------------------------------------------
module Common.Size where
open import Agda.Builtin.Size public
| {
"alphanum_fraction": 0.4090909091,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "cff04195bfe81bb74229a17ea1513f607e956753",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Common/Size.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Common/Size.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Common/Size.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 48,
"size": 330
} |
{-# OPTIONS --experimental-irrelevance #-}
-- Andreas, 2015-05-18 Irrelevant module parameters
-- should not be resurrected in module body.
postulate
A : Set
module M .(a : A) where
bad : (..(_ : A) -> Set) -> Set
bad f = f a
-- SHOULD FAIL: variable a is declared irrelevant,
-- so it cannot be used here.
-- This fails of course:
-- fail : .(a : A) -> (..(_ : A) -> Set) -> Set
-- fail a f = f a
| {
"alphanum_fraction": 0.5909090909,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "d0f3fcada2a1b2eb4693ccf9aeb5c9e83bdf41fe",
"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/Issue1114.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/Issue1114.agda",
"max_line_length": 54,
"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/Issue1114.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": 131,
"size": 418
} |
module Capability where
open import Relation.Nullary
using (yes; no)
open import Data.List
using (List; []; [_]; _∷_; _++_)
open import Data.String
using (String; _≟_)
open import Relation.Binary.PropositionalEquality
using (_≢_; refl; _≡_)
-- Local modules ---------------------------------------------------------------
open import Common
using (Id)
-- Capabilities Definition -----------------------------------------------------
infix 50 `_
infixr 15 _∙_
data Capability : Set where
`_ : Id → Capability -- Name
In : Id → Capability -- Can enter
Out : Id → Capability -- Can exit
Open : Id → Capability -- Can open
ε : Capability -- Null
_∙_ : Capability → Capability → Capability -- Path
-- Free variable ---------------------------------------------------------------
freeVar : Capability -> List Id
freeVar (` a) = [ a ]
freeVar (a ∙ b) = (freeVar a) ++ (freeVar b)
freeVar _ = []
-- Capability substitution -----------------------------------------------------
_[_/_] : Capability -> Id -> Capability -> Capability
` x [ y / M ] with x ≟ y
... | yes _ = M
... | no _ = ` x
(N ∙ R) [ y / M ] = N [ y / M ] ∙ R [ y / M ]
C [ _ / _ ] = C
module Test where
a = "a"
b = "b"
------------------------------------------------------------------------------
_ : freeVar (` a) ≡ [ a ]
_ = refl
_ : freeVar (` a ∙ ` b) ≡ a ∷ b ∷ []
_ = refl
------------------------------------------------------------------------------
_ : ∀ {M} → ` a [ a / M ] ≡ M
_ = refl
_ : ∀ {M} → ` b [ a / M ] ≡ ` b
_ = refl
| {
"alphanum_fraction": 0.3707929264,
"avg_line_length": 25.0428571429,
"ext": "agda",
"hexsha": "5182e4c3ac71acfe844884283fbeb4a7026f6aec",
"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": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "d-plaindoux/colca",
"max_forks_repo_path": "src/Capability.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"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": "d-plaindoux/colca",
"max_issues_repo_path": "src/Capability.agda",
"max_line_length": 80,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "d-plaindoux/colca",
"max_stars_repo_path": "src/Capability.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-04T09:35:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-03-12T18:31:14.000Z",
"num_tokens": 438,
"size": 1753
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Identity
module HoTT.Transport.Identity where
open variables
unitₗᵣ : {x y : A} {p : x == y} → p == refl ∙ p ∙ refl
unitₗᵣ {p = refl} = refl
-- Theorem 2.11.3
transport= : {a a' : A} (f g : A → B) (p : a == a') (q : f a == g a) →
transport (λ x → f x == g x) p q == ap f p ⁻¹ ∙ q ∙ ap g p
transport= _ _ refl _ = unitₗᵣ
transport=-id-const : (a : A) {x₁ x₂ : A} (p : x₁ == x₂) (q : x₁ == a) →
transport (λ x → x == a) p q == p ⁻¹ ∙ q
transport=-id-const _ refl refl = refl
transport=-const-id : {x₁ x₂ : A} (p : x₁ == x₂) (a : A) (q : a == x₁) →
transport (λ x → a == x) p q == q ∙ p
transport=-const-id refl _ refl = refl
transport=-id-id : {x₁ x₂ : A} (p : x₁ == x₂) (q : x₁ == x₁) →
transport (λ x → x == x) p q == p ⁻¹ ∙ q ∙ p
transport=-id-id refl _ = unitₗᵣ
transport=-constₗ : (b : B) (f : A → B) {x₁ x₂ : A} (p : x₁ == x₂) (q : b == f x₁) →
transport (λ x → b == f x) p q == q ∙ ap f p
transport=-constₗ _ _ refl _ = unitᵣ
transport=-constᵣ : (f : A → B) (b : B) {x₁ x₂ : A} (p : x₁ == x₂) (q : f x₁ == b) →
transport (λ x → f x == b) p q == ap f p ⁻¹ ∙ q
transport=-constᵣ _ _ refl refl = refl
transport=-idₗ : (f : A → A) {x₁ x₂ : A} (p : x₁ == x₂) (q : x₁ == f x₁) →
transport (λ x → x == f x) p q == p ⁻¹ ∙ q ∙ ap f p
transport=-idₗ _ refl _ = unitₗᵣ
transport=-idᵣ : (f : A → A) {x₁ x₂ : A} (p : x₁ == x₂) (q : f x₁ == x₁) →
transport (λ x → f x == x) p q == ap f p ⁻¹ ∙ q ∙ p
transport=-idᵣ _ refl _ = unitₗᵣ
| {
"alphanum_fraction": 0.4688067838,
"avg_line_length": 37.5227272727,
"ext": "agda",
"hexsha": "e1a5c1360686c88b29a2eae694da8f4575dadf98",
"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/Transport/Identity.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/Transport/Identity.agda",
"max_line_length": 84,
"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/Transport/Identity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 707,
"size": 1651
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.