hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0ba399540897dcbde387e3ca1b1d243171286248
| 730
|
agda
|
Agda
|
test/Compiler/simple/BuiltinInt.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/BuiltinInt.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/simple/BuiltinInt.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
open import Common.Prelude renaming (_+_ to _+N_)
open import Common.Integer
diff : Nat → Nat → Integer
diff a zero = pos a
diff zero (suc b) = negsuc b
diff (suc a) (suc b) = diff a b
_+_ : Integer → Integer → Integer
pos a + pos b = pos (a +N b)
pos a + negsuc b = diff a (suc b)
negsuc a + pos b = diff b (suc a)
negsuc a + negsuc b = negsuc (suc a +N b)
printInt : Integer → IO Unit
printInt n = putStrLn (intToString n)
main : IO Unit
main = printInt (pos 42 + pos 58) ,,
printInt (pos 42 + negsuc 141) ,,
printInt (pos 42 + negsuc 31) ,,
printInt (negsuc 42 + pos 143) ,,
printInt (negsuc 42 + pos 33) ,,
printInt (negsuc 42 + negsuc 56)
| 26.071429
| 49
| 0.59589
|
5949acd28b8c81e2bb167c3e6d585f9a53914789
| 7,642
|
agda
|
Agda
|
weakening.agda
|
hazelgrove/hazel-palette-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | 4
|
2020-10-04T06:45:06.000Z
|
2021-12-19T15:38:31.000Z
|
weakening.agda
|
hazelgrove/hazel-palette-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | 9
|
2020-09-30T20:27:56.000Z
|
2020-10-20T20:44:13.000Z
|
weakening.agda
|
hazelgrove/hazelnut-livelits-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | null | null | null |
open import Nat
open import Prelude
open import core
open import contexts
open import lemmas-disjointness
open import exchange
open import lemmas-freshG
-- this module contains all the proofs of different weakening structural
-- properties that we use for the hypothetical judgements
module weakening where
mutual
weaken-subst-Δ : ∀{Δ1 Δ2 Γ σ Γ'} → Δ1 ## Δ2
→ Δ1 , Γ ⊢ σ :s: Γ'
→ (Δ1 ∪ Δ2) , Γ ⊢ σ :s: Γ'
weaken-subst-Δ disj (STAId x) = STAId x
weaken-subst-Δ disj (STASubst subst x) = STASubst (weaken-subst-Δ disj subst) (weaken-ta-Δ1 disj x)
weaken-ta-Δ1 : ∀{Δ1 Δ2 Γ d τ} → Δ1 ## Δ2
→ Δ1 , Γ ⊢ d :: τ
→ (Δ1 ∪ Δ2) , Γ ⊢ d :: τ
weaken-ta-Δ1 disj TAConst = TAConst
weaken-ta-Δ1 disj (TAVar x₁) = TAVar x₁
weaken-ta-Δ1 disj (TALam x₁ wt) = TALam x₁ (weaken-ta-Δ1 disj wt)
weaken-ta-Δ1 disj (TAAp wt wt₁) = TAAp (weaken-ta-Δ1 disj wt) (weaken-ta-Δ1 disj wt₁)
weaken-ta-Δ1 {Δ1} {Δ2} {Γ} disj (TAEHole {u = u} {Γ' = Γ'} x x₁) = TAEHole (x∈∪l Δ1 Δ2 u _ x ) (weaken-subst-Δ disj x₁)
weaken-ta-Δ1 {Δ1} {Δ2} {Γ} disj (TANEHole {Γ' = Γ'} {u = u} x wt x₁) = TANEHole (x∈∪l Δ1 Δ2 u _ x) (weaken-ta-Δ1 disj wt) (weaken-subst-Δ disj x₁)
weaken-ta-Δ1 disj (TACast wt x) = TACast (weaken-ta-Δ1 disj wt) x
weaken-ta-Δ1 disj (TAFailedCast wt x x₁ x₂) = TAFailedCast (weaken-ta-Δ1 disj wt) x x₁ x₂
weaken-ta-Δ1 disj (TAFst wt) = TAFst (weaken-ta-Δ1 disj wt)
weaken-ta-Δ1 disj (TASnd wt) = TASnd (weaken-ta-Δ1 disj wt)
weaken-ta-Δ1 disj (TAPair wt wt₁) = TAPair (weaken-ta-Δ1 disj wt) (weaken-ta-Δ1 disj wt₁)
-- this is a little bit of a time saver. since ∪ is commutative on
-- disjoint contexts, and we need that premise anyway in both positions,
-- there's no real reason to repeat the inductive argument above
weaken-ta-Δ2 : ∀{Δ1 Δ2 Γ d τ} → Δ1 ## Δ2
→ Δ2 , Γ ⊢ d :: τ
→ (Δ1 ∪ Δ2) , Γ ⊢ d :: τ
weaken-ta-Δ2 {Δ1} {Δ2} {Γ} {d} {τ} disj D = tr (λ q → q , Γ ⊢ d :: τ) (∪comm Δ2 Δ1 (##-comm disj)) (weaken-ta-Δ1 (##-comm disj) D)
-- note that these statements are somewhat stronger than usual. this is
-- because we don't have implcit α-conversion. this reifies the
-- often-silent on paper assumption that if you collide with a bound
-- variable you can just α-convert it away and not worry.
-- used in both cases below, so factored into a lemma to save repeated code
lem-reassoc : {A : Set} {Γ Γ' : A ctx} {x : Nat} {τ : A} → (x # Γ') → (Γ ,, (x , τ)) ∪ Γ' == (Γ ∪ Γ') ,, (x , τ)
lem-reassoc {A} {Γ} {Γ'} {x} {τ} apt with lem-apart-sing-disj apt
... | disj = (∪assoc Γ (■ (x , τ)) Γ' disj) ·
(ap1 (λ qq → Γ ∪ qq) (∪comm (■ (x , τ)) (Γ') disj) ·
! (∪assoc Γ Γ' (■ (x , τ)) (##-comm disj)))
-- first we prove a general form of weakening, that you can add any
-- context Γ as long as it's fresh with respect to e
mutual
weaken-synth-∪ : ∀{e τ Γ Γ'} → freshΓ Γ' e → Γ ⊢ e => τ → (Γ ∪ Γ') ⊢ e => τ
weaken-synth-∪ frsh SConst = SConst
weaken-synth-∪ frsh (SAsc x) = SAsc (weaken-ana-∪ (freshΓ-asc frsh) x)
weaken-synth-∪ {Γ = Γ} {Γ' = Γ'} frsh (SVar {x = x} x₁) = SVar (x∈∪l Γ Γ' x _ x₁)
weaken-synth-∪ frsh (SAp x wt x₁ x₂) = SAp x (weaken-synth-∪ (freshΓ-ap1 frsh) wt)
x₁
(weaken-ana-∪ (freshΓ-ap2 frsh) x₂)
weaken-synth-∪ frsh SEHole = SEHole
weaken-synth-∪ frsh (SNEHole x wt) = SNEHole x (weaken-synth-∪ (freshΓ-nehole frsh) wt)
weaken-synth-∪ {Γ = Γ} {Γ' = Γ'} frsh (SLam {e = e} {τ2 = τ2} {x = x} x₁ wt)
with ctxindirect Γ' x
... | Inl qq = abort (lem-fresh-lam2 (frsh x qq))
... | Inr qq = SLam (apart-parts Γ Γ' x x₁ qq)
(tr (λ qq → qq ⊢ e => τ2) (lem-reassoc {Γ = Γ} qq)
(weaken-synth-∪ (freshΓ-lam2 frsh) wt))
weaken-synth-∪ frsh (SFst wt x) = SFst (weaken-synth-∪ (freshΓ-fst frsh) wt) x
weaken-synth-∪ frsh (SSnd wt x) = SSnd (weaken-synth-∪ (freshΓ-snd frsh) wt) x
weaken-synth-∪ frsh (SPair hd wt wt₁) = SPair hd (weaken-synth-∪ (freshΓ-pair1 frsh) wt) (weaken-synth-∪ (freshΓ-pair2 frsh) wt₁)
weaken-ana-∪ : ∀{e τ Γ Γ'} → freshΓ Γ' e → Γ ⊢ e <= τ → (Γ ∪ Γ') ⊢ e <= τ
weaken-ana-∪ frsh (ASubsume x x₁) = ASubsume (weaken-synth-∪ frsh x) x₁
weaken-ana-∪ {Γ = Γ} {Γ' = Γ'} frsh (ALam {e = e} {τ2 = τ2} {x = x} x₁ x₂ wt)
with ctxindirect Γ' x
... | Inl qq = abort (lem-fresh-lam1 (frsh x qq))
... | Inr qq = ALam (apart-parts Γ Γ' x x₁ qq)
x₂
(tr (λ qq → qq ⊢ e <= τ2) (lem-reassoc {Γ = Γ} qq)
(weaken-ana-∪ (freshΓ-lam1 frsh) wt))
-- it follows from this that if the term is closed, you can weaken with
-- any context that's fresh in e
weaken-synth-closed : ∀{e τ Γ} → freshΓ Γ e → ∅ ⊢ e => τ → Γ ⊢ e => τ
weaken-synth-closed {e} {τ} {Γ} f wt = tr (λ qq → qq ⊢ e => τ) ∅∪1 (weaken-synth-∪ f wt)
weaken-ana-closed : ∀{e τ Γ} → freshΓ Γ e → ∅ ⊢ e <= τ → Γ ⊢ e <= τ
weaken-ana-closed {e} {τ} {Γ} f wt = tr (λ qq → qq ⊢ e <= τ) ∅∪1 (weaken-ana-∪ f wt)
-- the very structural forms also follow from the union weakening, since
-- ,, is defined by ∪
weaken-synth : ∀{ x Γ e τ τ'} → freshe x e
→ Γ ⊢ e => τ
→ (Γ ,, (x , τ')) ⊢ e => τ
weaken-synth f wt = weaken-synth-∪ (fresh-freshΓ f) wt
weaken-ana : ∀{x Γ e τ τ'} → freshe x e
→ Γ ⊢ e <= τ
→ (Γ ,, (x , τ')) ⊢ e <= τ
weaken-ana f wt = weaken-ana-∪ (fresh-freshΓ f) wt
mutual
weaken-subst-Γ : ∀{ x Γ Δ σ Γ' τ} →
envfresh x σ →
Δ , Γ ⊢ σ :s: Γ' →
Δ , (Γ ,, (x , τ)) ⊢ σ :s: Γ'
weaken-subst-Γ {Γ = Γ} (EFId x₁) (STAId x₂) = STAId (λ x τ x₃ → x∈∪l Γ _ x τ (x₂ x τ x₃) )
weaken-subst-Γ {x = x} {Γ = Γ} (EFSubst x₁ efrsh x₂) (STASubst {y = y} {τ = τ'} subst x₃) =
STASubst (exchange-subst-Γ {Γ = Γ} (flip x₂) (weaken-subst-Γ {Γ = Γ ,, (y , τ')} efrsh subst))
(weaken-ta x₁ x₃)
weaken-ta : ∀{x Γ Δ d τ τ'} →
fresh x d →
Δ , Γ ⊢ d :: τ →
Δ , Γ ,, (x , τ') ⊢ d :: τ
weaken-ta _ TAConst = TAConst
weaken-ta {x} {Γ} {_} {_} {τ} {τ'} (FVar x₂) (TAVar x₃) = TAVar (x∈∪l Γ (■ (x , τ')) _ _ x₃)
weaken-ta {x = x} frsh (TALam {x = y} x₂ wt) with natEQ x y
weaken-ta (FLam x₁ x₂) (TALam x₃ wt) | Inl refl = abort (x₁ refl)
weaken-ta {Γ = Γ} {τ' = τ'} (FLam x₁ x₃) (TALam {x = y} x₄ wt) | Inr x₂ = TALam (apart-extend1 Γ (flip x₁) x₄) (exchange-ta-Γ {Γ = Γ} (flip x₁) (weaken-ta x₃ wt))
weaken-ta (FAp frsh frsh₁) (TAAp wt wt₁) = TAAp (weaken-ta frsh wt) (weaken-ta frsh₁ wt₁)
weaken-ta (FHole x₁) (TAEHole x₂ x₃) = TAEHole x₂ (weaken-subst-Γ x₁ x₃)
weaken-ta (FNEHole x₁ frsh) (TANEHole x₂ wt x₃) = TANEHole x₂ (weaken-ta frsh wt) (weaken-subst-Γ x₁ x₃)
weaken-ta (FCast frsh) (TACast wt x₁) = TACast (weaken-ta frsh wt) x₁
weaken-ta (FFailedCast frsh) (TAFailedCast wt x₁ x₂ x₃) = TAFailedCast (weaken-ta frsh wt) x₁ x₂ x₃
weaken-ta (FFst frsh) (TAFst wt) = TAFst (weaken-ta frsh wt)
weaken-ta (FSnd frsh) (TASnd wt) = TASnd (weaken-ta frsh wt)
weaken-ta (FPair frsh frsh₁) (TAPair wt wt₁) = TAPair (weaken-ta frsh wt) (weaken-ta frsh₁ wt₁)
| 56.607407
| 166
| 0.528527
|
4a48984c7523257967d806e0ce874e7f5c18adbb
| 6,010
|
agda
|
Agda
|
BasicIS4/Semantics/TarskiOvergluedDyadicHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIS4/Semantics/TarskiOvergluedDyadicHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIS4/Semantics/TarskiOvergluedDyadicHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.
-- Tarski-style semantics with context pairs as concrete worlds, and glueing for α, ▻, and □.
-- Hilbert-style syntax.
module BasicIS4.Semantics.TarskiOvergluedDyadicHilbert where
open import BasicIS4.Syntax.Common public
open import Common.Semantics public
-- Intuitionistic Tarski models.
record Model : Set₁ where
infix 3 _⊩ᵅ_ _[⊢]_
field
-- Forcing for atomic propositions; monotonic.
_⊩ᵅ_ : Cx² Ty Ty → Atom → Set
mono²⊩ᵅ : ∀ {P Π Π′} → Π ⊆² Π′ → Π ⊩ᵅ P → Π′ ⊩ᵅ P
-- Hilbert-style syntax representation; monotonic.
_[⊢]_ : Cx² Ty Ty → Ty → Set
mono²[⊢] : ∀ {A Π Π′} → Π ⊆² Π′ → Π [⊢] A → Π′ [⊢] A
[var] : ∀ {A Γ Δ} → A ∈ Γ → Γ ⁏ Δ [⊢] A
[app] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B → Γ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] B
[ci] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] A ▻ A
[ck] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B ▻ A
[cs] : ∀ {A B C Γ Δ} → Γ ⁏ Δ [⊢] (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
[mvar] : ∀ {A Γ Δ} → A ∈ Δ → Γ ⁏ Δ [⊢] A
[box] : ∀ {A Γ Δ} → ∅ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] □ A
[cdist] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] □ (A ▻ B) ▻ □ A ▻ □ B
[cup] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A ▻ □ □ A
[cdown] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A ▻ A
[cpair] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B ▻ A ∧ B
[cfst] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B ▻ A
[csnd] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B ▻ B
[unit] : ∀ {Γ Δ} → Γ ⁏ Δ [⊢] ⊤
-- NOTE: [mlam] is necessary for [mmulticut], which is necessary for eval.
[mlam] : ∀ {A B Γ Δ} → Γ ⁏ Δ , A [⊢] B → Γ ⁏ Δ [⊢] □ A ▻ B
infix 3 _[⊢]⋆_
_[⊢]⋆_ : Cx² Ty Ty → Cx Ty → Set
Π [⊢]⋆ ∅ = 𝟙
Π [⊢]⋆ Ξ , A = Π [⊢]⋆ Ξ × Π [⊢] A
open Model {{…}} public
-- Forcing in a particular model.
module _ {{_ : Model}} where
infix 3 _⊩_
_⊩_ : Cx² Ty Ty → Ty → Set
Π ⊩ α P = Glue (Π [⊢] α P) (Π ⊩ᵅ P)
Π ⊩ A ▻ B = ∀ {Π′} → Π ⊆² Π′ → Glue (Π′ [⊢] A ▻ B) (Π′ ⊩ A → Π′ ⊩ B)
Π ⊩ □ A = ∀ {Π′} → Π ⊆² Π′ → Glue (Π′ [⊢] □ A) (Π′ ⊩ A)
Π ⊩ A ∧ B = Π ⊩ A × Π ⊩ B
Π ⊩ ⊤ = 𝟙
infix 3 _⊩⋆_
_⊩⋆_ : Cx² Ty Ty → Cx Ty → Set
Π ⊩⋆ ∅ = 𝟙
Π ⊩⋆ Ξ , A = Π ⊩⋆ Ξ × Π ⊩ A
-- Monotonicity with respect to context inclusion.
module _ {{_ : Model}} where
mono²⊩ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊩ A → Π′ ⊩ A
mono²⊩ {α P} ψ s = mono²[⊢] ψ (syn s) ⅋ mono²⊩ᵅ ψ (sem s)
mono²⊩ {A ▻ B} ψ s = λ ψ′ → s (trans⊆² ψ ψ′)
mono²⊩ {□ A} ψ s = λ ψ′ → s (trans⊆² ψ ψ′)
mono²⊩ {A ∧ B} ψ s = mono²⊩ {A} ψ (π₁ s) , mono²⊩ {B} ψ (π₂ s)
mono²⊩ {⊤} ψ s = ∙
mono²⊩⋆ : ∀ {Ξ Π Π′} → Π ⊆² Π′ → Π ⊩⋆ Ξ → Π′ ⊩⋆ Ξ
mono²⊩⋆ {∅} ψ ∙ = ∙
mono²⊩⋆ {Ξ , A} ψ (ts , t) = mono²⊩⋆ ψ ts , mono²⊩ {A} ψ t
-- Extraction of syntax representation in a particular model.
module _ {{_ : Model}} where
reifyʳ : ∀ {A Π} → Π ⊩ A → Π [⊢] A
reifyʳ {α P} s = syn s
reifyʳ {A ▻ B} s = syn (s refl⊆²)
reifyʳ {□ A} s = syn (s refl⊆²)
reifyʳ {A ∧ B} s = [app] ([app] [cpair] (reifyʳ {A} (π₁ s))) (reifyʳ {B} (π₂ s))
reifyʳ {⊤} s = [unit]
reifyʳ⋆ : ∀ {Ξ Π} → Π ⊩⋆ Ξ → Π [⊢]⋆ Ξ
reifyʳ⋆ {∅} ∙ = ∙
reifyʳ⋆ {Ξ , A} (ts , t) = reifyʳ⋆ ts , reifyʳ t
-- Useful theorems in functional form.
module _ {{_ : Model}} where
[mmulticut] : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ [⊢]⋆ □⋆ Ξ → Γ ⁏ Ξ [⊢] A → Γ ⁏ Δ [⊢] A
[mmulticut] {∅} ∙ u = mono²[⊢] (refl⊆ , bot⊆) u
[mmulticut] {Ξ , B} (ts , t) u = [app] ([mmulticut] ts ([mlam] u)) t
-- Additional useful equipment.
module _ {{_ : Model}} where
_⟪$⟫_ : ∀ {A B Π} → Π ⊩ A ▻ B → Π ⊩ A → Π ⊩ B
s ⟪$⟫ a = sem (s refl⊆²) a
⟪K⟫ : ∀ {A B Π} → Π ⊩ A → Π ⊩ B ▻ A
⟪K⟫ {A} a ψ = let a′ = mono²⊩ {A} ψ a
in [app] [ck] (reifyʳ a′) ⅋ K a′
⟪S⟫ : ∀ {A B C Π} → Π ⊩ A ▻ B ▻ C → Π ⊩ A ▻ B → Π ⊩ A → Π ⊩ C
⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a)
⟪S⟫′ : ∀ {A B C Π} → Π ⊩ A ▻ B ▻ C → Π ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ {A} {B} {C} s₁ ψ = let s₁′ = mono²⊩ {A ▻ B ▻ C} ψ s₁
t = syn (s₁′ refl⊆²)
in [app] [cs] t ⅋ λ s₂ ψ′ →
let s₁″ = mono²⊩ {A ▻ B ▻ C} (trans⊆² ψ ψ′) s₁
s₂′ = mono²⊩ {A ▻ B} ψ′ s₂
t′ = syn (s₁″ refl⊆²)
u = syn (s₂′ refl⊆²)
in [app] ([app] [cs] t′) u ⅋ ⟪S⟫ s₁″ s₂′
_⟪D⟫_ : ∀ {A B Π} → Π ⊩ □ (A ▻ B) → Π ⊩ □ A → Π ⊩ □ B
(s₁ ⟪D⟫ s₂) ψ = let t ⅋ s₁′ = s₁ ψ
u ⅋ a = s₂ ψ
in [app] ([app] [cdist] t) u ⅋ s₁′ ⟪$⟫ a
_⟪D⟫′_ : ∀ {A B Π} → Π ⊩ □ (A ▻ B) → Π ⊩ □ A ▻ □ B
_⟪D⟫′_ {A} {B} s₁ ψ = let s₁′ = mono²⊩ {□ (A ▻ B)} ψ s₁
in [app] [cdist] (reifyʳ (λ {_} ψ′ → s₁′ ψ′)) ⅋ _⟪D⟫_ s₁′
⟪↑⟫ : ∀ {A Π} → Π ⊩ □ A → Π ⊩ □ □ A
⟪↑⟫ {A} s ψ = [app] [cup] (syn (s ψ)) ⅋ λ ψ′ → s (trans⊆² ψ ψ′)
⟪↓⟫ : ∀ {A Π} → Π ⊩ □ A → Π ⊩ A
⟪↓⟫ s = sem (s refl⊆²)
_⟪,⟫′_ : ∀ {A B Π} → Π ⊩ A → Π ⊩ B ▻ A ∧ B
_⟪,⟫′_ {A} a ψ = let a′ = mono²⊩ {A} ψ a
in [app] [cpair] (reifyʳ a′) ⅋ _,_ a′
-- Forcing in a particular world of a particular model, for sequents.
module _ {{_ : Model}} where
infix 3 _⊩_⇒_
_⊩_⇒_ : Cx² Ty Ty → Cx² Ty Ty → Ty → Set
Π ⊩ Γ ⁏ Δ ⇒ A = Π ⊩⋆ Γ → Π ⊩⋆ □⋆ Δ → Π ⊩ A
infix 3 _⊩_⇒⋆_
_⊩_⇒⋆_ : Cx² Ty Ty → Cx² Ty Ty → Cx Ty → Set
Π ⊩ Γ ⁏ Δ ⇒⋆ Ξ = Π ⊩⋆ Γ → Π ⊩⋆ □⋆ Δ → Π ⊩⋆ Ξ
-- Entailment, or forcing in all worlds of all models, for sequents.
infix 3 _⊨_
_⊨_ : Cx² Ty Ty → Ty → Set₁
Π ⊨ A = ∀ {{_ : Model}} {w : Cx² Ty Ty} → w ⊩ Π ⇒ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx² Ty Ty → Cx Ty → Set₁
Π ⊨⋆ Ξ = ∀ {{_ : Model}} {w : Cx² Ty Ty} → w ⊩ Π ⇒⋆ Ξ
-- Additional useful equipment, for sequents.
module _ {{_ : Model}} where
lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩⋆ Γ → w ⊩ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
mlookup : ∀ {A Δ w} → A ∈ Δ → w ⊩⋆ □⋆ Δ → w ⊩ A
mlookup top (γ , s) = sem (s refl⊆²)
mlookup (pop i) (γ , s) = mlookup i γ
-- TODO: More equipment.
| 33.021978
| 93
| 0.403328
|
4d36d98f70f50eed27c9bc8012e52707d644bf75
| 4,756
|
agda
|
Agda
|
examples/vfl/Typechecker.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/vfl/Typechecker.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/vfl/Typechecker.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Typechecker where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
data Fin : Nat -> Set where
f0 : {n : Nat} -> Fin (suc n)
fs : {n : Nat} -> Fin n -> Fin (suc n)
infixl 30 _::_ _++_
data Vect (A : Set) : Nat -> Set where
ε : Vect A zero
_::_ : {n : Nat} -> Vect A n -> A -> Vect A (suc n)
fs^ : {n : Nat}(m : Nat) -> Fin n -> Fin (m + n)
fs^ zero i = i
fs^ (suc m) i = fs (fs^ m i)
_++_ : {A : Set}{n m : Nat} -> Vect A n -> Vect A m -> Vect A (m + n)
xs ++ ε = xs
xs ++ (ys :: y) = (xs ++ ys) :: y
data Chop {A : Set} : {n : Nat} -> Vect A n -> Fin n -> Set where
chopGlue : {m n : Nat}(xs : Vect A n)(x : A)(ys : Vect A m) ->
Chop (xs :: x ++ ys) (fs^ m f0)
chop : {A : Set}{n : Nat}(xs : Vect A n)(i : Fin n) -> Chop xs i
chop ε ()
chop (xs :: x) f0 = chopGlue xs x ε
chop (xs :: y) (fs i) with chop xs i
chop (.(xs :: x ++ ys) :: y) (fs .(fs^ m f0))
| chopGlue {m} xs x ys = chopGlue xs x (ys :: y)
infixr 40 _⊃_
data Simp : Set where
o : Simp
_⊃_ : Simp -> Simp -> Simp
infix 20 Simp-_
data Simp-_ : Simp -> Set where
neqo : Simp -> Simp -> Simp- o
neq⊃ : {S T : Simp} -> Simp- (S ⊃ T)
neqT : {S T : Simp}(T' : Simp- T) -> Simp- (S ⊃ T)
neqS : {S : Simp}{T₁ : Simp}(S' : Simp- S)(T₂ : Simp) -> Simp- (S ⊃ T₁)
infixl 60 _∖_
_∖_ : (S : Simp) -> Simp- S -> Simp
.o ∖ neqo S T = S ⊃ T
.(_ ⊃ _) ∖ neq⊃ = o
.(S ⊃ T) ∖ neqT {S}{T} T' = S ⊃ T ∖ T'
.(S ⊃ _) ∖ neqS {S} S' T₂ = S ∖ S' ⊃ T₂
data SimpEq? (S : Simp) : Simp -> Set where
simpSame : SimpEq? S S
simpDiff : (T : Simp- S) -> SimpEq? S (S ∖ T)
simpEq? : (S T : Simp) -> SimpEq? S T
simpEq? o o = simpSame
simpEq? o (S ⊃ T) = simpDiff (neqo S T)
simpEq? (S ⊃ T) o = simpDiff neq⊃
simpEq? (S₁ ⊃ T₁) (S₂ ⊃ T₂) with simpEq? S₁ S₂
simpEq? (S ⊃ T₁) (.S ⊃ T₂) | simpSame with simpEq? T₁ T₂
simpEq? (S ⊃ T) (.S ⊃ .T) | simpSame | simpSame = simpSame
simpEq? (S ⊃ T) (.S ⊃ .(T ∖ T')) | simpSame | simpDiff T' = simpDiff (neqT T')
simpEq? (S ⊃ T₁) (.(S ∖ S') ⊃ T₂) | simpDiff S' = simpDiff (neqS S' T₂)
data Term : Nat -> Set where
var : {n : Nat} -> Fin n -> Term n
app : {n : Nat} -> Term n -> Term n -> Term n
lam : {n : Nat} -> Simp -> Term (suc n) -> Term n
data Good : {n : Nat} -> Vect Simp n -> Simp -> Set where
gVar : {n m : Nat}(Γ : Vect Simp n)(T : Simp)(Δ : Vect Simp m) ->
Good (Γ :: T ++ Δ) T
gApp : {n : Nat}{Γ : Vect Simp n}{S T : Simp} ->
Good Γ (S ⊃ T) -> Good Γ S -> Good Γ T
gLam : {n : Nat}{Γ : Vect Simp n}(S : Simp){T : Simp} ->
Good (Γ :: S) T -> Good Γ (S ⊃ T)
g : {n : Nat}{Γ : Vect Simp n}(T : Simp) -> Good Γ T -> Term n
g T (gVar{n}{m} Γ .T Δ) = var (fs^ m f0)
g T (gApp f s) = app (g _ f) (g _ s)
g .(S ⊃ _) (gLam S t) = lam S (g _ t)
data Bad {n : Nat}(Γ : Vect Simp n) : Set where
bNonFun : Good Γ o -> Term n -> Bad Γ
bMismatch : {S T : Simp}(S' : Simp- S) ->
Good Γ (S ⊃ T) -> Good Γ (S ∖ S') -> Bad Γ
bArg : {S T : Simp} -> Good Γ (S ⊃ T) -> Bad Γ -> Bad Γ
bFun : Bad Γ -> Term n -> Bad Γ
bLam : (S : Simp) -> Bad (Γ :: S) -> Bad Γ
b : {n : Nat}{Γ : Vect Simp n} -> Bad Γ -> Term n
b (bNonFun f s) = app (g o f) s
b (bMismatch _ f s) = app (g _ f) (g _ s)
b (bArg f s) = app (g _ f) (b s)
b (bFun f s) = app (b f) s
b (bLam S t) = lam S (b t)
data TypeCheck? {n : Nat}(Γ : Vect Simp n) : Term n -> Set where
good : (T : Simp)(t : Good Γ T) -> TypeCheck? Γ (g T t)
bad : (t : Bad Γ) -> TypeCheck? Γ (b t)
typeCheck? : {n : Nat}(Γ : Vect Simp n)(t : Term n) -> TypeCheck? Γ t
typeCheck? Γ (var i) with chop Γ i
typeCheck? .(Γ :: T ++ Δ) (var ._) | chopGlue Γ T Δ = good T (gVar Γ T Δ)
typeCheck? Γ (app f s) with typeCheck? Γ f
typeCheck? Γ (app .(g (S ⊃ T) f) s) | good (S ⊃ T) f with typeCheck? Γ s
typeCheck? Γ (app .(g (S ⊃ T) f) .(g S' s))
| good (S ⊃ T) f | good S' s with simpEq? S S'
typeCheck? Γ (app .(g (S ⊃ T) f) .(g S s))
| good (S ⊃ T) f | good .S s | simpSame = good T (gApp f s)
typeCheck? Γ (app .(g (S ⊃ T) f) .(g (S ∖ S') s))
| good (S ⊃ T) f | good .(S ∖ S') s | simpDiff S' = bad (bMismatch S' f s)
typeCheck? Γ (app .(g (S ⊃ T) f) .(b s))
| good (S ⊃ T) f | bad s = bad (bArg f s)
typeCheck? Γ (app .(g o f) s) | good o f = bad (bNonFun f s)
typeCheck? Γ (app .(b f) s) | bad f = bad (bFun f s)
typeCheck? Γ (lam S t) with typeCheck? (Γ :: S) t
typeCheck? Γ (lam S .(g T t)) | good T t = good (S ⊃ T) (gLam S t)
typeCheck? Γ (lam S .(b t)) | bad t = bad (bLam S t)
| 34.970588
| 87
| 0.472246
|
29c09ffb6a1d071fff48de56e1f0144e69b23537
| 8,314
|
agda
|
Agda
|
Cubical/Foundations/Equiv/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Foundations/Equiv/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Equiv/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-
A couple of general facts about equivalences:
- if f is an equivalence then (cong f) is an equivalence ([equivCong])
- if f is an equivalence then pre- and postcomposition with f are equivalences ([preCompEquiv], [postCompEquiv])
- if f is an equivalence then (Σ[ g ] section f g) and (Σ[ g ] retract f g) are contractible ([isContr-section], [isContr-retract])
- isHAEquiv is a proposition [isPropIsHAEquiv]
(these are not in 'Equiv.agda' because they need Univalence.agda (which imports Equiv.agda))
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.Equiv.Properties where
open import Cubical.Core.Everything
open import Cubical.Data.Sigma
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.HLevels
open import Cubical.Functions.FunExtEquiv
private
variable
ℓ ℓ′ : Level
A B C : Type ℓ
isEquivInvEquiv : isEquiv (λ (e : A ≃ B) → invEquiv e)
isEquivInvEquiv = isoToIsEquiv goal where
open Iso
goal : Iso (A ≃ B) (B ≃ A)
goal .fun = invEquiv
goal .inv = invEquiv
goal .rightInv g = equivEq refl
goal .leftInv f = equivEq refl
invEquivEquiv : (A ≃ B) ≃ (B ≃ A)
invEquivEquiv = _ , isEquivInvEquiv
isEquivCong : {x y : A} (e : A ≃ B) → isEquiv (λ (p : x ≡ y) → cong (equivFun e) p)
isEquivCong e = isoToIsEquiv (congIso (equivToIso e))
congEquiv : {x y : A} (e : A ≃ B) → (x ≡ y) ≃ (equivFun e x ≡ equivFun e y)
congEquiv e = isoToEquiv (congIso (equivToIso e))
equivAdjointEquiv : (e : A ≃ B) → ∀ {a b} → (a ≡ invEq e b) ≃ (equivFun e a ≡ b)
equivAdjointEquiv e = compEquiv (congEquiv e) (compPathrEquiv (secEq e _))
invEq≡→equivFun≡ : (e : A ≃ B) → ∀ {a b} → invEq e b ≡ a → equivFun e a ≡ b
invEq≡→equivFun≡ e = equivFun (equivAdjointEquiv e) ∘ sym
isEquivPreComp : (e : A ≃ B) → isEquiv (λ (φ : B → C) → φ ∘ equivFun e)
isEquivPreComp e = snd (equiv→ (invEquiv e) (idEquiv _))
preCompEquiv : (e : A ≃ B) → (B → C) ≃ (A → C)
preCompEquiv e = (λ φ → φ ∘ fst e) , isEquivPreComp e
isEquivPostComp : (e : A ≃ B) → isEquiv (λ (φ : C → A) → e .fst ∘ φ)
isEquivPostComp e = snd (equivΠCod (λ _ → e))
postCompEquiv : (e : A ≃ B) → (C → A) ≃ (C → B)
postCompEquiv e = _ , isEquivPostComp e
-- see also: equivΠCod for a dependent version of postCompEquiv
hasSection : (A → B) → Type _
hasSection {A = A} {B = B} f = Σ[ g ∈ (B → A) ] section f g
hasRetract : (A → B) → Type _
hasRetract {A = A} {B = B} f = Σ[ g ∈ (B → A) ] retract f g
isEquiv→isContrHasSection : {f : A → B} → isEquiv f → isContr (hasSection f)
fst (isEquiv→isContrHasSection isEq) = invIsEq isEq , secIsEq isEq
snd (isEquiv→isContrHasSection isEq) (f , ε) i = (λ b → fst (p b i)) , (λ b → snd (p b i))
where p : ∀ b → (invIsEq isEq b , secIsEq isEq b) ≡ (f b , ε b)
p b = isEq .equiv-proof b .snd (f b , ε b)
isEquiv→hasSection : {f : A → B} → isEquiv f → hasSection f
isEquiv→hasSection = fst ∘ isEquiv→isContrHasSection
isContr-hasSection : (e : A ≃ B) → isContr (hasSection (fst e))
isContr-hasSection e = isEquiv→isContrHasSection (snd e)
isEquiv→isContrHasRetract : {f : A → B} → isEquiv f → isContr (hasRetract f)
fst (isEquiv→isContrHasRetract isEq) = invIsEq isEq , retIsEq isEq
snd (isEquiv→isContrHasRetract {f = f} isEq) (g , η) =
λ i → (λ b → p b i) , (λ a → q a i)
where p : ∀ b → invIsEq isEq b ≡ g b
p b = sym (η (invIsEq isEq b)) ∙' cong g (secIsEq isEq b)
-- one square from the definition of invIsEq
ieSq : ∀ a → Square (cong g (secIsEq isEq (f a)))
refl
(cong (g ∘ f) (retIsEq isEq a))
refl
ieSq a k j = g (commSqIsEq isEq a k j)
-- one square from η
ηSq : ∀ a → Square (η (invIsEq isEq (f a)))
(η a)
(cong (g ∘ f) (retIsEq isEq a))
(retIsEq isEq a)
ηSq a i j = η (retIsEq isEq a i) j
-- and one last square from the definition of p
pSq : ∀ b → Square (η (invIsEq isEq b))
refl
(cong g (secIsEq isEq b))
(p b)
pSq b i j = compPath'-filler (sym (η (invIsEq isEq b))) (cong g (secIsEq isEq b)) j i
q : ∀ a → Square (retIsEq isEq a) (η a) (p (f a)) refl
q a i j = hcomp (λ k → λ { (i = i0) → ηSq a j k
; (i = i1) → η a (j ∧ k)
; (j = i0) → pSq (f a) i k
; (j = i1) → η a k
})
(ieSq a j i)
isEquiv→hasRetract : {f : A → B} → isEquiv f → hasRetract f
isEquiv→hasRetract = fst ∘ isEquiv→isContrHasRetract
isContr-hasRetract : (e : A ≃ B) → isContr (hasRetract (fst e))
isContr-hasRetract e = isEquiv→isContrHasRetract (snd e)
cong≃ : (F : Type ℓ → Type ℓ′) → (A ≃ B) → F A ≃ F B
cong≃ F e = pathToEquiv (cong F (ua e))
cong≃-char : (F : Type ℓ → Type ℓ′) {A B : Type ℓ} (e : A ≃ B) → ua (cong≃ F e) ≡ cong F (ua e)
cong≃-char F e = ua-pathToEquiv (cong F (ua e))
cong≃-idEquiv : (F : Type ℓ → Type ℓ′) (A : Type ℓ) → cong≃ F (idEquiv A) ≡ idEquiv (F A)
cong≃-idEquiv F A = cong≃ F (idEquiv A) ≡⟨ cong (λ p → pathToEquiv (cong F p)) uaIdEquiv ⟩
pathToEquiv refl ≡⟨ pathToEquivRefl ⟩
idEquiv (F A) ∎
isPropIsHAEquiv : {f : A → B} → isProp (isHAEquiv f)
isPropIsHAEquiv {f = f} ishaef = goal ishaef where
equivF : isEquiv f
equivF = isHAEquiv→isEquiv ishaef
rCoh1 : (sec : hasSection f) → Type _
rCoh1 (g , ε) = Σ[ η ∈ retract f g ] ∀ x → cong f (η x) ≡ ε (f x)
rCoh2 : (sec : hasSection f) → Type _
rCoh2 (g , ε) = Σ[ η ∈ retract f g ] ∀ x → Square (ε (f x)) refl (cong f (η x)) refl
rCoh3 : (sec : hasSection f) → Type _
rCoh3 (g , ε) = ∀ x → Σ[ ηx ∈ g (f x) ≡ x ] Square (ε (f x)) refl (cong f ηx) refl
rCoh4 : (sec : hasSection f) → Type _
rCoh4 (g , ε) = ∀ x → Path (fiber f (f x)) (g (f x) , ε (f x)) (x , refl)
characterization : isHAEquiv f ≃ Σ _ rCoh4
characterization =
isHAEquiv f
-- first convert between Σ and record
≃⟨ isoToEquiv (iso (λ e → (e .g , e .rinv) , (e .linv , e .com))
(λ e → record { g = e .fst .fst ; rinv = e .fst .snd
; linv = e .snd .fst ; com = e .snd .snd })
(λ _ → refl) λ _ → refl) ⟩
Σ _ rCoh1
-- secondly, convert the path into a dependent path for later convenience
≃⟨ Σ-cong-equiv-snd (λ s → Σ-cong-equiv-snd
λ η → equivΠCod
λ x → compEquiv (flipSquareEquiv {a₀₀ = f x}) (invEquiv slideSquareEquiv)) ⟩
Σ _ rCoh2
≃⟨ Σ-cong-equiv-snd (λ s → invEquiv Σ-Π-≃) ⟩
Σ _ rCoh3
≃⟨ Σ-cong-equiv-snd (λ s → equivΠCod λ x → ΣPath≃PathΣ) ⟩
Σ _ rCoh4
■
where open isHAEquiv
goal : isProp (isHAEquiv f)
goal = subst isProp (sym (ua characterization))
(isPropΣ (isContr→isProp (isEquiv→isContrHasSection equivF))
λ s → isPropΠ λ x → isProp→isSet (isContr→isProp (equivF .equiv-proof (f x))) _ _)
-- loop spaces connected by a path are equivalent
conjugatePathEquiv : {A : Type ℓ} {a b : A} (p : a ≡ b) → (a ≡ a) ≃ (b ≡ b)
conjugatePathEquiv p = compEquiv (compPathrEquiv p) (compPathlEquiv (sym p))
-- composition on the right induces an equivalence of path types
compr≡Equiv : {A : Type ℓ} {a b c : A} (p q : a ≡ b) (r : b ≡ c) → (p ≡ q) ≃ (p ∙ r ≡ q ∙ r)
compr≡Equiv p q r = congEquiv ((λ s → s ∙ r) , compPathr-isEquiv r)
-- composition on the left induces an equivalence of path types
compl≡Equiv : {A : Type ℓ} {a b c : A} (p : a ≡ b) (q r : b ≡ c) → (q ≡ r) ≃ (p ∙ q ≡ p ∙ r)
compl≡Equiv p q r = congEquiv ((λ s → p ∙ s) , (compPathl-isEquiv p))
isEquivFromIsContr : {A : Type ℓ} {B : Type ℓ′}
→ (f : A → B) → isContr A → isContr B
→ isEquiv f
isEquivFromIsContr f isContrA isContrB =
subst isEquiv (λ i x → isContr→isProp isContrB (fst B≃A x) (f x) i) (snd B≃A)
where B≃A = isContr→Equiv isContrA isContrB
| 41.363184
| 131
| 0.572649
|
12c889a0470cec8f09f26fca7873ef56ed979d18
| 1,292
|
agda
|
Agda
|
src/fot/FOL/ExclusiveDisjunction/TheoremsATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOL/ExclusiveDisjunction/TheoremsATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOL/ExclusiveDisjunction/TheoremsATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Exclusive disjunction theorems
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOL.ExclusiveDisjunction.TheoremsATP where
-- The theorems below are valid on intuitionistic logic and with an
-- empty domain.
open import FOL.Base hiding ( D≢∅ ; pem )
open import FOL.ExclusiveDisjunction.Base
------------------------------------------------------------------------------
-- We postulate some propositional formulae (which are translated as
-- 0-ary predicates).
postulate P Q : Set
-- We do not use the _⊻_ operator because its definition is not a
-- FOL-definition.
postulate
p⊻q→p→¬q : ((P ∨ Q) ∧ ¬ (P ∧ Q)) → P → ¬ Q
{-# ATP prove p⊻q→p→¬q #-}
postulate
p⊻q→q→¬p : ((P ∨ Q) ∧ ¬ (P ∧ Q)) → Q → ¬ P
{-# ATP prove p⊻q→q→¬p #-}
postulate
p⊻q→¬p→q : ((P ∨ Q) ∧ ¬ (P ∧ Q)) → ¬ P → Q
{-# ATP prove p⊻q→¬p→q #-}
postulate
p⊻q→¬q→p : ((P ∨ Q) ∧ ¬ (P ∧ Q)) → ¬ Q → P
{-# ATP prove p⊻q→¬q→p #-}
postulate
¬[p⊻q] : ¬ ((P ∨ Q) ∧ ¬ (P ∧ Q)) → ((P ∧ Q) ∨ (¬ P ∧ ¬ Q))
{-# ATP prove ¬[p⊻q] #-}
| 29.363636
| 78
| 0.44969
|
31d0b7fb9d7a9680187d82108ac74af9cbca9a60
| 2,878
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Relation/Unary/AllPairs.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Relation/Unary/AllPairs.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Relation/Unary/AllPairs.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists where every pair of elements are related (symmetrically)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel)
module Data.List.Relation.Unary.AllPairs
{a ℓ} {A : Set a} {R : Rel A ℓ} where
open import Data.List.Base using (List; []; _∷_)
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
open import Data.Product as Prod using (_,_; _×_; uncurry; <_,_>)
open import Function using (id; _∘_)
open import Level using (_⊔_)
open import Relation.Binary as B using (Rel; _⇒_)
open import Relation.Binary.Construct.Intersection renaming (_∩_ to _∩ᵇ_)
open import Relation.Binary.PropositionalEquality
open import Relation.Unary as U renaming (_∩_ to _∩ᵘ_) hiding (_⇒_)
open import Relation.Nullary using (yes; no)
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Product using (_×-dec_)
------------------------------------------------------------------------
-- Definition
open import Data.List.Relation.Unary.AllPairs.Core public
------------------------------------------------------------------------
-- Operations
head : ∀ {x xs} → AllPairs R (x ∷ xs) → All (R x) xs
head (px ∷ pxs) = px
tail : ∀ {x xs} → AllPairs R (x ∷ xs) → AllPairs R xs
tail (px ∷ pxs) = pxs
uncons : ∀ {x xs} → AllPairs R (x ∷ xs) → All (R x) xs × AllPairs R xs
uncons = < head , tail >
module _ {q} {S : Rel A q} where
map : R ⇒ S → AllPairs R ⊆ AllPairs S
map ~₁⇒~₂ [] = []
map ~₁⇒~₂ (x~xs ∷ pxs) = All.map ~₁⇒~₂ x~xs ∷ (map ~₁⇒~₂ pxs)
module _ {s t} {S : Rel A s} {T : Rel A t} where
zipWith : R ∩ᵇ S ⇒ T → AllPairs R ∩ᵘ AllPairs S ⊆ AllPairs T
zipWith f ([] , []) = []
zipWith f (px ∷ pxs , qx ∷ qxs) = All.zipWith f (px , qx) ∷ zipWith f (pxs , qxs)
unzipWith : T ⇒ R ∩ᵇ S → AllPairs T ⊆ AllPairs R ∩ᵘ AllPairs S
unzipWith f [] = [] , []
unzipWith f (rx ∷ rxs) = Prod.zip _∷_ _∷_ (All.unzipWith f rx) (unzipWith f rxs)
module _ {s} {S : Rel A s} where
zip : AllPairs R ∩ᵘ AllPairs S ⊆ AllPairs (R ∩ᵇ S)
zip = zipWith id
unzip : AllPairs (R ∩ᵇ S) ⊆ AllPairs R ∩ᵘ AllPairs S
unzip = unzipWith id
------------------------------------------------------------------------
-- Properties of predicates preserved by AllPairs
allPairs? : B.Decidable R → U.Decidable (AllPairs R)
allPairs? R? [] = yes []
allPairs? R? (x ∷ xs) =
Dec.map′ (uncurry _∷_) uncons (All.all (R? x) xs ×-dec allPairs? R? xs)
irrelevant : B.Irrelevant R → U.Irrelevant (AllPairs R)
irrelevant irr [] [] = refl
irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
cong₂ _∷_ (All.irrelevant irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
satisfiable : U.Satisfiable (AllPairs R)
satisfiable = [] , []
| 34.674699
| 83
| 0.556637
|
106267de5a732725944dce5b45735e41ac08c5c7
| 4,817
|
agda
|
Agda
|
Cubical/Homotopy/Freudenthal.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Freudenthal.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Freudenthal.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
{-
Freudenthal suspension theorem
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Homotopy.Freudenthal where
open import Cubical.Foundations.Everything
open import Cubical.Data.HomotopyGroup
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.HITs.Nullification
open import Cubical.HITs.Susp
open import Cubical.HITs.Truncation as Trunc renaming (rec to trRec)
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.WedgeConnectivity
open import Cubical.Homotopy.Loopspace
module _ {ℓ} (n : HLevel) {A : Pointed ℓ} (connA : isConnected (suc (suc n)) (typ A)) where
σ : typ A → typ (Ω (∙Susp (typ A)))
σ a = merid a ∙ merid (pt A) ⁻¹
private
2n+2 = suc n + suc n
module WC (p : north ≡ north) =
WedgeConnectivity (suc n) (suc n) A connA A connA
(λ a b →
( (σ b ≡ p → hLevelTrunc 2n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p))
, isOfHLevelΠ 2n+2 λ _ → isOfHLevelTrunc 2n+2
))
(λ a r → ∣ a , (rCancel' (merid a) ∙ rCancel' (merid (pt A)) ⁻¹) ∙ r ∣)
(λ b r → ∣ b , r ∣)
(funExt λ r →
cong′ (λ w → ∣ pt A , w ∣)
(cong (_∙ r) (rCancel' (rCancel' (merid (pt A))))
∙ lUnit r ⁻¹))
fwd : (p : north ≡ north) (a : typ A)
→ hLevelTrunc 2n+2 (fiber σ p)
→ hLevelTrunc 2n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p)
fwd p a = Trunc.rec (isOfHLevelTrunc 2n+2) (uncurry (WC.extension p a))
isEquivFwd : (p : north ≡ north) (a : typ A) → isEquiv (fwd p a)
isEquivFwd p a .equiv-proof =
elim.isEquivPrecompose (λ _ → pt A) (suc n)
(λ a →
( (∀ t → isContr (fiber (fwd p a) t))
, isProp→isOfHLevelSuc n (isPropΠ λ _ → isPropIsContr)
))
(isConnectedPoint (suc n) connA (pt A))
.equiv-proof
(λ _ → Trunc.elim
(λ _ → isProp→isOfHLevelSuc (n + suc n) isPropIsContr)
(λ fib →
subst (λ k → isContr (fiber k ∣ fib ∣))
(cong (Trunc.rec (isOfHLevelTrunc 2n+2) ∘ uncurry)
(funExt (WC.right p) ⁻¹))
(subst isEquiv
(funExt (Trunc.mapId) ⁻¹)
(idIsEquiv _)
.equiv-proof ∣ fib ∣)
))
.fst .fst a
interpolate : (a : typ A)
→ PathP (λ i → typ A → north ≡ merid a i) (λ x → merid x ∙ merid a ⁻¹) merid
interpolate a i x j = compPath-filler (merid x) (merid a ⁻¹) (~ i) j
Code : (y : Susp (typ A)) → north ≡ y → Type ℓ
Code north p = hLevelTrunc 2n+2 (fiber σ p)
Code south q = hLevelTrunc 2n+2 (fiber merid q)
Code (merid a i) p =
Glue
(hLevelTrunc 2n+2 (fiber (interpolate a i) p))
(λ
{ (i = i0) → _ , (fwd p a , isEquivFwd p a)
; (i = i1) → _ , idEquiv _
})
encode : (y : Susp (typ A)) (p : north ≡ y) → Code y p
encode y = J Code ∣ pt A , rCancel' (merid (pt A)) ∣
encodeMerid : (a : typ A) → encode south (merid a) ≡ ∣ a , refl ∣
encodeMerid a =
cong (transport (λ i → gluePath i))
(funExt⁻ (WC.left refl a) _ ∙ cong ∣_∣ (cong (a ,_) (lem _ _)))
∙ transport (PathP≡Path gluePath _ _)
(λ i → ∣ a , (λ j k → rCancel-filler' (merid a) i j k) ∣)
where
gluePath : I → Type _
gluePath i = hLevelTrunc 2n+2 (fiber (interpolate a i) (λ j → merid a (i ∧ j)))
lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y) → (p ∙ q ⁻¹) ∙ q ≡ p
lem p q = assoc p (q ⁻¹) q ⁻¹ ∙ cong (p ∙_) (lCancel q) ∙ rUnit p ⁻¹
contractCodeSouth : (p : north ≡ south) (c : Code south p) → encode south p ≡ c
contractCodeSouth p =
Trunc.elim
(λ _ → isOfHLevelPath 2n+2 (isOfHLevelTrunc 2n+2) _ _)
(uncurry λ a →
J (λ p r → encode south p ≡ ∣ a , r ∣) (encodeMerid a))
isConnectedMerid : isConnectedFun 2n+2 (merid {A = typ A})
isConnectedMerid p = encode south p , contractCodeSouth p
isConnectedσ : isConnectedFun 2n+2 σ
isConnectedσ =
transport (λ i → isConnectedFun 2n+2 (interpolate (pt A) (~ i))) isConnectedMerid
FreudenthalEquiv : ∀ {ℓ} (n : HLevel) (A : Pointed ℓ)
→ isConnected (2 + n) (typ A)
→ hLevelTrunc ((suc n) + (suc n)) (typ A)
≃ hLevelTrunc ((suc n) + (suc n)) (typ (Ω (Susp (typ A) , north)))
FreudenthalEquiv n A iscon = connectedTruncEquiv _
(σ n {A = A} iscon)
(isConnectedσ _ iscon)
FreudenthalIso : ∀ {ℓ} (n : HLevel) (A : Pointed ℓ)
→ isConnected (2 + n) (typ A)
→ Iso (hLevelTrunc ((suc n) + (suc n)) (typ A))
(hLevelTrunc ((suc n) + (suc n)) (typ (Ω (Susp (typ A) , north))))
FreudenthalIso n A iscon = connectedTruncIso _ (σ n {A = A} iscon) (isConnectedσ _ iscon)
| 37.929134
| 91
| 0.542039
|
20a716b5169235a1e32906050c1546f021c710a7
| 174
|
agda
|
Agda
|
test/fail/Issue203.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
test/fail/Issue203.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/Issue203.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module Issue203 where
open import Imports.Level
-- shouldn't work
data Bad {a b} (A : Set a) : Set b where
[_] : (x : A) → Bad A
| 17.4
| 40
| 0.632184
|
59045dfe6dcea80e5ae093880090ac94356c9e58
| 5,980
|
agda
|
Agda
|
misc/RecursiveDescent/InductiveWithFix/Lib.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
misc/RecursiveDescent/InductiveWithFix/Lib.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
misc/RecursiveDescent/InductiveWithFix/Lib.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some defined parsers
------------------------------------------------------------------------
-- Note that the fixpoint combinator ensures that _⋆ can be defined
-- without any need for library grammars (c.f.
-- RecursiveDescent.Inductive.Lib). However, use of the fixpoint
-- combinator can lead to code which is hard to understand, and should
-- be kept at a minimum.
-- This module also provides an example of a parser for which the
-- Index cannot be inferred.
module RecursiveDescent.InductiveWithFix.Lib where
open import RecursiveDescent.Index
open import RecursiveDescent.InductiveWithFix
open import Utilities
open import Data.Nat hiding (_≟_)
import Data.Vec as V; open V using (Vec)
import Data.Vec1 as V₁; open V₁ using (Vec₁)
import Data.List as L ; open L using (List)
open import Relation.Nullary
open import Data.Product.Record
open import Data.Product renaming (_,_ to pair)
open import Data.Bool hiding (_≟_)
open import Data.Function
open import Data.Maybe
open import Data.Unit hiding (_≟_)
------------------------------------------------------------------------
-- Applicative functor parsers
-- We could get these for free with better library support.
infixl 50 _⊛_ _<⊛_ _⊛>_ _<$>_ _<$_
_⊛_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ (r₁ -> r₂) ->
Parser tok nt i₂ r₁ ->
Parser tok nt _ r₂
p₁ ⊛ p₂ = p₁ >>= \f -> p₂ >>= \x -> return (f x)
_<$>_ : forall {tok nt i r₁ r₂} ->
(r₁ -> r₂) ->
Parser tok nt i r₁ ->
Parser tok nt _ r₂
f <$> x = return f ⊛ x
_<⊛_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ ->
Parser tok nt i₂ r₂ ->
Parser tok nt _ r₁
x <⊛ y = const <$> x ⊛ y
_⊛>_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ ->
Parser tok nt i₂ r₂ ->
Parser tok nt _ r₂
x ⊛> y = flip const <$> x ⊛ y
_<$_ : forall {tok nt i r₁ r₂} ->
r₁ ->
Parser tok nt i r₂ ->
Parser tok nt _ r₁
x <$ y = const x <$> y
------------------------------------------------------------------------
-- Parsing sequences
infix 55 _⋆ _+
_⋆ : forall {tok nt c r} ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
p ⋆ = fix (return L.[] ∣ L._∷_ <$> lift p ⊛ ! fresh)
_+ : forall {tok nt c r} ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
p + = L._∷_ <$> p ⊛ p ⋆
chain₁ : forall {tok nt c₁ i₂ r}
-> Assoc
-> Parser tok nt (false , c₁) r
-> Parser tok nt i₂ (r -> r -> r)
-> Parser tok nt _ r
chain₁ a p op = chain₁-combine a <$> (pair <$> p ⊛ op) ⋆ ⊛ p
chain : forall {tok nt c₁ i₂ r}
-> Assoc
-> Parser tok nt (false , c₁) r
-> Parser tok nt i₂ (r -> r -> r)
-> r
-> Parser tok nt _ r
chain a p op x = return x ∣ chain₁ a p op
-- Note that the resulting index here cannot be inferred...
private
exactly'-corners : Corners -> ℕ -> Corners
exactly'-corners c zero = _
exactly'-corners c (suc n) = _
exactly' : forall {tok nt c r} n ->
Parser tok nt (false , c) r ->
Parser tok nt (false , exactly'-corners c n)
(Vec r (suc n))
exactly' zero p = V.[_] <$> p
exactly' (suc n) p = V._∷_ <$> p ⊛ exactly' n p
-- ...so we might as well generalise the function a little.
-- exactly n p parses n occurrences of p.
exactly-index : Index -> ℕ -> Index
exactly-index i zero = _
exactly-index i (suc n) = _
exactly : forall {tok nt i r} n ->
Parser tok nt i r ->
Parser tok nt (exactly-index i n) (Vec r n)
exactly zero p = return V.[]
exactly (suc n) p = V._∷_ <$> p ⊛ exactly n p
-- A function with a similar type:
sequence : forall {tok nt i r n} ->
Vec₁ (Parser tok nt i r) n ->
Parser tok nt (exactly-index i n) (Vec r n)
sequence V₁.[] = return V.[]
sequence (V₁._∷_ p ps) = V._∷_ <$> p ⊛ sequence ps
------------------------------------------------------------------------
-- sat and friends
sat : forall {tok nt r} ->
(tok -> Maybe r) -> Parser tok nt (0I ·I 1I) r
sat {tok} {nt} {r} p = symbol !>>= \c -> ok (p c)
where
okIndex : Maybe r -> Index
okIndex nothing = _
okIndex (just _) = _
ok : (x : Maybe r) -> Parser tok nt (okIndex x) r
ok nothing = fail
ok (just x) = return x
sat' : forall {tok nt} -> (tok -> Bool) -> Parser tok nt _ ⊤
sat' p = sat (boolToMaybe ∘ p)
any : forall {tok nt} -> Parser tok nt _ tok
any = sat just
------------------------------------------------------------------------
-- Some parsers which require a decidable token equality
open import Relation.Binary
module Token (D : DecSetoid) where
open DecSetoid D using (_≟_) renaming (carrier to tok)
open import Data.Vec1
-- Parsing a given token (or, really, a given equivalence class of
-- tokens).
sym : forall {nt} -> tok -> Parser tok nt _ tok
sym c = sat p
where
p : tok -> Maybe tok
p x with c ≟ x
... | yes _ = just x
... | no _ = nothing
-- Parsing a sequence of tokens.
string : forall {nt n} -> Vec tok n -> Parser tok nt _ (Vec tok n)
string cs = sequence (map₀₁ sym cs)
------------------------------------------------------------------------
-- Character parsers
import Data.Char as C
open C using (Char; _==_)
open Token C.decSetoid
digit : forall {nt} -> Parser Char nt _ ℕ
digit = 0 <$ sym '0'
∣ 1 <$ sym '1'
∣ 2 <$ sym '2'
∣ 3 <$ sym '3'
∣ 4 <$ sym '4'
∣ 5 <$ sym '5'
∣ 6 <$ sym '6'
∣ 7 <$ sym '7'
∣ 8 <$ sym '8'
∣ 9 <$ sym '9'
number : forall {nt} -> Parser Char nt _ ℕ
number = toNum <$> digit +
where toNum = L.foldr (\n x -> 10 * x + n) 0 ∘ L.reverse
-- whitespace recognises an incomplete but useful list of whitespace
-- characters.
whitespace : forall {nt} -> Parser Char nt _ ⊤
whitespace = sat' isSpace
where
isSpace = \c -> (c == ' ') ∨ (c == '\t') ∨ (c == '\n') ∨ (c == '\r')
| 28.207547
| 72
| 0.532107
|
dccfbc9684780eaf89d2a589c3c7c51c97c0c419
| 3,328
|
agda
|
Agda
|
test/Succeed/ReflectTC.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/ReflectTC.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/ReflectTC.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- Building some simple tactics using the reflected type checking monad.
module _ where
open import Common.Reflection
open import Common.Prelude hiding (_>>=_)
open import Common.Equality
-- Some helpers --
quotegoal : (Type → Tactic) → Tactic
quotegoal tac hole =
inferType hole >>= λ goal →
reduce goal >>= λ goal →
tac goal hole
case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = f x
replicateTC : {A : Set} → Nat → TC A → TC (List A)
replicateTC zero m = returnTC []
replicateTC (suc n) m = m >>= λ x → replicateTC n m >>= λ xs → returnTC (x ∷ xs)
mapTC! : ∀ {A : Set} → (A → TC ⊤) → List A → TC ⊤
mapTC! f [] = returnTC _
mapTC! f (x ∷ xs) = f x >>= λ _ → mapTC! f xs
mapTC!r : ∀ {A} → (A → TC ⊤) → List A → TC ⊤
mapTC!r f [] = returnTC _
mapTC!r f (x ∷ xs) = mapTC! f xs >>= λ _ → f x
visibleArity : QName → TC Nat
visibleArity q = getType q >>= λ t → returnTC (typeArity t)
where
typeArity : Type → Nat
typeArity (pi (arg (argInfo visible _) _) (abs _ b)) = suc (typeArity b)
typeArity (pi _ (abs _ b)) = typeArity b
typeArity _ = 0
newMeta! : TC Term
newMeta! = newMeta unknown
absurdLam : Term
absurdLam = extLam (absurdClause (arg (argInfo visible relevant) absurd ∷ []) ∷ []) []
-- Simple assumption tactic --
assumption-tac : Nat → Nat → Tactic
assumption-tac x 0 _ = typeError (strErr "No assumption matched" ∷ [])
assumption-tac x (suc n) hole =
catchTC (unify hole (var x []))
(assumption-tac (suc x) n hole)
macro
assumption : Tactic
assumption hole = getContext >>= λ Γ → assumption-tac 0 (length Γ) hole
test-assumption : ∀ {A B : Set} → A → B → A
test-assumption x y = assumption
test-assumption₂ : ∀ {A B : Set} → A → B → _
test-assumption₂ x y = assumption -- will pick y
-- Solving a goal using only constructors --
tryConstructors : Nat → List QName → Tactic
constructors-tac : Nat → Type → Tactic
constructors-tac zero _ _ = typeError (strErr "Search depth exhausted" ∷ [])
constructors-tac (suc n) (def d vs) hole =
getDefinition d >>= λ def →
case def of λ
{ (dataDef _ cs) → tryConstructors n cs hole
; _ → returnTC _ }
constructors-tac _ (pi a b) hole = give absurdLam hole
constructors-tac _ _ hole = returnTC _
tryConstructors n [] hole = typeError (strErr "No matching constructor term" ∷ [])
tryConstructors n (c ∷ cs) hole =
visibleArity c >>= λ ar →
catchTC (replicateTC ar newMeta! >>= λ vs →
unify hole (con c (map (arg (argInfo visible relevant)) vs)) >>= λ _ →
mapTC!r (quotegoal (constructors-tac n)) vs)
(tryConstructors n cs hole)
macro
constructors : Tactic
constructors = quotegoal (constructors-tac 10)
data Any {A : Set} (P : A → Set) : List A → Set where
zero : ∀ {x xs} → P x → Any P (x ∷ xs)
suc : ∀ {x xs} → Any P xs → Any P (x ∷ xs)
infix 1 _∈_
_∈_ : ∀ {A : Set} → A → List A → Set
x ∈ xs = Any (x ≡_) xs
data Dec (A : Set) : Set where
yes : A → Dec A
no : (A → ⊥) → Dec A
test₁ : 3 ∈ 1 ∷ 2 ∷ 3 ∷ []
test₁ = constructors
test₂ : Dec (2 + 3 ≡ 5)
test₂ = constructors
test₃ : Dec (2 + 2 ≡ 5)
test₃ = constructors
data Singleton (n : Nat) : Set where
it : (m : Nat) → m ≡ n → Singleton n
test₄ : Singleton 5
test₄ = constructors -- this works because we solve goals right to left (picking refl before m)
| 28.93913
| 95
| 0.61899
|
0efbcf3feb24d59c1841cd80f4772e8a788e0226
| 206
|
agda
|
Agda
|
test/Fail/Issue998c.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/Issue998c.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue998c.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
postulate
A : Set
f : (B : Set) → B → A
f A a = a
-- Expected error:
-- A !=< A of type Set
-- (because one is a variable and one a defined identifier)
-- when checking that the expression a has type A
| 18.727273
| 59
| 0.635922
|
598d98bf11ae318e93dc49470be5fcd15ce3ff48
| 2,156
|
agda
|
Agda
|
test/Succeed/HigherOrderRewriting.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/HigherOrderRewriting.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/HigherOrderRewriting.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting #-}
open import Common.Prelude
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
postulate is-id : ∀ {A : Set} → (A → A) → Bool
postulate is-id-true : ∀ {A} → is-id {A} (λ x → x) ≡ true
{-# REWRITE is-id-true #-}
test₁ : is-id {Nat} (λ x → x) ≡ true
test₁ = refl
postulate is-const : ∀ {A : Set} → (A → A) → Bool
postulate is-const-true : ∀ {A} (x : A) → is-const (λ _ → x) ≡ true
{-# REWRITE is-const-true #-}
test₂ : is-const {Nat} (λ _ → 42) ≡ true
test₂ = refl
ap : {A B : Set} (f : A → B) {x y : A} →
x ≡ y → f x ≡ f y
ap f refl = refl
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
open _×_
{- Cartesian product -}
module _ {A B : Set} where
_,=_ : {a a' : A} (p : a ≡ a') {b b' : B} (q : b ≡ b') → (a , b) ≡ (a' , b')
refl ,= refl = refl
ap-,-l : (b : B) {a a' : A} (p : a ≡ a') →
ap (λ z → z , b) p ≡ (p ,= refl)
ap-,-l b refl = refl
{-# REWRITE ap-,-l #-}
test₃ : (b : B) {a a' : A} (p : a ≡ a') →
ap (λ z → z , b) p ≡ (p ,= refl)
test₃ _ _ = refl
ap-,-r : (a : A) {b b' : B} (p : b ≡ b') →
ap (λ z → a , z) p ≡ (refl ,= p)
ap-,-r a refl = refl
{-# REWRITE ap-,-r #-}
test₄ : (a : A) {b b' : B} (p : b ≡ b') →
ap (λ z → a , z) p ≡ (refl ,= p)
test₄ a _ = refl
ap-idf : {A : Set} {x y : A} (p : x ≡ y) → ap (λ x → x) p ≡ p
ap-idf refl = refl
{-# REWRITE ap-idf #-}
{- Function extensionality -}
module _ {A B : Set} {f g : A → B} where
postulate
funext : ((x : A) → f x ≡ g x) → f ≡ g
postulate
ap-app-funext : (a : A) (h : (x : A) → f x ≡ g x) →
ap (λ f → f a) (funext h) ≡ h a
{-# REWRITE ap-app-funext #-}
test₅ : (a : A) (h : (x : A) → f x ≡ g x) →
ap (λ f → f a) (funext h) ≡ h a
test₅ a h = refl
{- Dependent paths -}
module _ where
PathOver : {A : Set} (B : A → Set)
{x y : A} (p : x ≡ y) (u : B x) (v : B y) → Set
PathOver B refl u v = (u ≡ v)
postulate
PathOver-triv : {A B : Set} {x y : A} (p : x ≡ y) (u v : B) →
(PathOver (λ _ → B) p u v) ≡ (u ≡ v)
{-# REWRITE PathOver-triv #-}
test₆ : (p : 1 ≡ 1) → PathOver (λ _ → Nat) p 2 2
test₆ p = refl
| 22.93617
| 78
| 0.459184
|
dc5a5bd85c61671e3b00a528ca64d81c3f0c1517
| 525
|
agda
|
Agda
|
test/Succeed/fol-theorems/Existential.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Succeed/fol-theorems/Existential.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Succeed/fol-theorems/Existential.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
------------------------------------------------------------------------------
-- Testing the existential quantifier
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Existential where
postulate
D : Set
A : D → Set
∃ : (A : D → Set) → Set
postulate foo : (∃ λ x → A x) → (∃ λ x → A x)
{-# ATP prove foo #-}
| 27.631579
| 78
| 0.361905
|
1dbdd8a4d6360858ff393c9639482c0f12657c9e
| 1,194
|
agda
|
Agda
|
notes/FOT/FOTC/Program/Min/Min.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/FOTC/Program/Min/Min.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/FOTC/Program/Min/Min.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Example of a partial function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- From (Bove, A. and Capretta, V. (2001)).
module FOT.FOTC.Program.Min.Min where
open import Data.Nat renaming ( suc to succ )
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------------
-- Note: Although the function is partial the problem is that it is
-- rejected by Agda's termination checker.
{-# NON_TERMINATING #-}
min : (ℕ → ℕ) → ℕ
min f with f 0
... | 0 = 0
... | succ x = succ (min (λ n → f (succ n)))
------------------------------------------------------------------------------
-- References
--
-- Bove, A. and Capretta, V. (2001). Nested General Recursion and
-- Partiality in Type Theory. In: Theorem Proving in Higher Order
-- Logics (TPHOLs 2001). Ed. by Boulton, R. J. and Jackson,
-- P. B. Vol. 2152. LNCS. Springer, pp. 121–135.
| 35.117647
| 78
| 0.463149
|
12908a9a77f51da4c388fe1ad04eb6c12f577e22
| 5,909
|
agda
|
Agda
|
src/MLib/Finite/Properties.agda
|
bch29/agda-matrices
|
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
|
[
"MIT"
] | null | null | null |
src/MLib/Finite/Properties.agda
|
bch29/agda-matrices
|
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
|
[
"MIT"
] | null | null | null |
src/MLib/Finite/Properties.agda
|
bch29/agda-matrices
|
e26ae2e0aa7721cb89865aae78625a2f3fd2b574
|
[
"MIT"
] | null | null | null |
open import MLib.Finite
module MLib.Finite.Properties {c ℓ} (finiteSet : FiniteSet c ℓ) where
open import MLib.Prelude
import Data.Fin.Permutation as Perm
import Relation.Binary as B
open FE using (cong)
open LeftInverse using () renaming (_∘_ to _ⁱ∘_)
open Algebra using (IdempotentCommutativeMonoid)
open Table hiding (setoid)
open FiniteSet finiteSet renaming (Carrier to A)
private
enumₜAt : ∀ {N} → OntoFin N → Table A N
enumₜAt = tabulate ∘ _⟨$⟩_ ∘ LeftInverse.from
module _ {c ℓ} (icMonoid : IdempotentCommutativeMonoid c ℓ) where
module S = IdempotentCommutativeMonoid icMonoid
open S using (_∙_; ∙-cong) renaming (Carrier to S; _≈_ to _≈′_)
open import Algebra.Operations.CommutativeMonoid S.commutativeMonoid
open import Algebra.Properties.CommutativeMonoid S.commutativeMonoid
foldMap : (A → S) → S
foldMap f = sumₜ (Table.map f enumₜ)
foldMap-cong : ∀ {f g} → (∀ x → f x ≈′ g x) → foldMap f ≈′ foldMap g
foldMap-cong p = sumₜ-cong-≈ (p ∘ lookup enumₜ)
private
inhabited : ∀ {N} (i : Fin N) → ∃ λ n → N ≡ Nat.suc n
inhabited Fin.zero = _ , ≡.refl
inhabited (Fin.suc i) = _ , ≡.refl
-- Folding with a constant function produces the constant.
foldMap-const : ∀ {x} → x ∙ foldMap (λ _ → x) ≈′ x
foldMap-const {x} =
begin
x ∙ foldMap (λ _ → x) ≡⟨⟩
x ∙ sumₜ (Table.map (λ _ → x) enumₜ) ≡⟨⟩
x ∙ sumₜ (Table.replicate {N} x) ≡⟨⟩
sumₜ (Table.replicate {Nat.suc N} x) ≈⟨ sumₜ-idem-replicate N (S.idem x) ⟩
x ∎
where open EqReasoning S.setoid
private
module _ {n : ℕ} (ontoFin′ : OntoFin (Nat.suc n)) where
from = LeftInverse.from ontoFin′ ⟨$⟩_
to = LeftInverse.to ontoFin′ ⟨$⟩_
from-to = LeftInverse.left-inverse-of ontoFin′
enumₜ′ : Table A (Nat.suc n)
enumₜ′ = enumₜAt ontoFin′
ap : setoid ⟶ S.setoid → A → S
ap = _⟨$⟩_
enumₜ-complete′ : ∀ (func : setoid ⟶ S.setoid) x → (func ⟨$⟩ x) ∙ sumₜ (map (ap func) enumₜ′) ≈′ sumₜ (map (ap func) enumₜ′)
enumₜ-complete′ func x =
begin
f x ∙ sumₜ (map f enumₜ′) ≈⟨ ∙-cong S.refl (sumₜ-permute (map f enumₜ′) (Perm.transpose Fin.zero i)) ⟩
f x ∙ sumₜ (permute (Perm.transpose Fin.zero i) (map f enumₜ′)) ≡⟨⟩
f x ∙ (f (from (to x)) ∙ _) ≈⟨ ∙-cong S.refl (∙-cong (cong func (from-to _)) S.refl) ⟩
f x ∙ (f x ∙ _) ≈⟨ S.sym (S.assoc _ _ _) ⟩
(f x ∙ f x) ∙ _ ≈⟨ ∙-cong (S.idem _) S.refl ⟩
f x ∙ _ ≈⟨ ∙-cong (cong func (sym (from-to _))) S.refl ⟩
f (from (to x)) ∙ _ ≡⟨⟩
sumₜ (permute (Perm.transpose Fin.zero i) (map f enumₜ′)) ≈⟨ S.sym (sumₜ-permute (map f enumₜ′) (Perm.transpose Fin.zero i)) ⟩
sumₜ (map f enumₜ′) ∎
where
f = ap func
i = to x
open EqReasoning S.setoid
private
enumₜ-complete′′ :
∀ {N} (ontoFin′ : OntoFin N) (f : setoid ⟶ S.setoid) x
→ (f ⟨$⟩ x) ∙ sumₜ (Table.map (f ⟨$⟩_) (enumₜAt ontoFin′))
≈′ sumₜ (Table.map (f ⟨$⟩_) (enumₜAt ontoFin′))
enumₜ-complete′′ ontoFin′ f x with inhabited (LeftInverse.to ontoFin′ ⟨$⟩ x)
enumₜ-complete′′ ontoFin′ f x | n , ≡.refl = enumₜ-complete′ ontoFin′ f x
sum/map-hom : ∀ {n} {a}{A : Set a} (f : A → S) (t : Table A n) → sumₗ (List.map f (toList t)) ≡ sumₜ (map f t)
sum/map-hom f t =
begin
sumₗ (List.map f (toList t)) ≡⟨ ≡.cong sumₗ (Table.map-toList-hom t) ⟩
sumₗ (toList (map f t)) ≡⟨ ≡.sym (sumₜ-toList (map f t)) ⟩
sumₜ (map f t) ∎
where
open ≡.Reasoning
-- Enumeration is complete: in any idempotent commutative monoid, adding one
-- more element to the sum won't change it. In particular, this works in the
-- powerset monoid, where 'f' is the singleton at its argument and addition
-- is set union. This shows that every member of 'A' is present in the
-- enumeration (even though the powerset monoid is quite difficult to
-- implement in Agda so this proof is not present).
enumₜ-complete : ∀ f x → (f ⟨$⟩ x) ∙ foldMap (f ⟨$⟩_) ≈′ foldMap (f ⟨$⟩_)
enumₜ-complete = enumₜ-complete′′ ontoFin
enumₗ-complete : ∀ (f : setoid ⟶ S.setoid) x → (f ⟨$⟩ x) ∙ sumₗ (List.map (f ⟨$⟩_) enumₗ) ≈′ sumₗ (List.map (f ⟨$⟩_) enumₗ)
enumₗ-complete func x =
begin
f x ∙ sumₗ (List.map f enumₗ) ≡⟨⟩
f x ∙ sumₗ (List.map f (toList enumₜ)) ≡⟨ ≡.cong₂ _∙_ ≡.refl (sum/map-hom f enumₜ) ⟩
f x ∙ sumₜ (map f enumₜ) ≈⟨ enumₜ-complete func x ⟩
sumₜ (map f enumₜ) ≡⟨ ≡.sym (sum/map-hom f enumₜ) ⟩
sumₗ (List.map f enumₗ) ∎
where
f = func ⟨$⟩_
open EqReasoning S.setoid
-- A finite set can be strictly totally ordered by its elements' indices
Ixorder : B.StrictTotalOrder _ _ _
Ixorder = record
{ _≈_ = _≈_
; _<_ = λ x y → toIx x Fin.< toIx y
; isStrictTotalOrder = record
{ isEquivalence = isEquivalence
; trans = Fin.<-trans
; compare = compare
}
}
where
compare : Trichotomous _≈_ (λ x y → toIx x Fin.< toIx y)
compare x y with B.StrictTotalOrder.compare (Fin.<-strictTotalOrder N) (toIx x) (toIx y)
compare x y | B.tri< a ¬b ¬c = B.tri< a (¬b ∘ cong (LeftInverse.to ontoFin)) ¬c
compare x y | B.tri≈ ¬a b ¬c = B.tri≈ ¬a (LeftInverse.injective ontoFin b) ¬c
compare x y | B.tri> ¬a ¬b c = B.tri> ¬a (¬b ∘ cong (LeftInverse.to ontoFin)) c
-- Equality between members of a finite set is decidable.
_≟_ : B.Decidable _≈_
_≟_ = B.StrictTotalOrder._≟_ Ixorder
| 40.197279
| 151
| 0.550685
|
1ce9ce65247c14a87e97442423f90c31899308ed
| 3,543
|
agda
|
Agda
|
agda-stdlib-0.9/src/Data/Nat/DivMod.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | 1
|
2016-10-20T15:52:05.000Z
|
2016-10-20T15:52:05.000Z
|
agda-stdlib-0.9/src/Data/Nat/DivMod.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Data/Nat/DivMod.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Integer division
------------------------------------------------------------------------
module Data.Nat.DivMod where
open import Data.Nat as Nat
open import Data.Nat.Properties
open SemiringSolver
open import Data.Fin as Fin using (Fin; zero; suc; toℕ; fromℕ)
import Data.Fin.Properties as Fin
open import Induction.Nat
open import Relation.Nullary.Decidable
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Function
------------------------------------------------------------------------
-- Some boring lemmas
private
lem₁ : (m k : ℕ) →
Nat.suc m ≡ suc (toℕ (Fin.inject+ k (fromℕ m)) + 0)
lem₁ m k = cong suc $ begin
m
≡⟨ sym $ Fin.to-from m ⟩
toℕ (fromℕ m)
≡⟨ Fin.inject+-lemma k (fromℕ m) ⟩
toℕ (Fin.inject+ k (fromℕ m))
≡⟨ solve 1 (λ x → x := x :+ con 0) refl _ ⟩
toℕ (Fin.inject+ k (fromℕ m)) + 0
∎
lem₂ : ∀ n → _
lem₂ = solve 1 (λ n → con 1 :+ n := con 1 :+ (n :+ con 0)) refl
lem₃ : ∀ n k q (r : Fin n) eq → suc n + k ≡ toℕ r + suc q * n
lem₃ n k q r eq = begin
suc n + k
≡⟨ solve 2 (λ n k → con 1 :+ n :+ k := n :+ (con 1 :+ k))
refl n k ⟩
n + suc k
≡⟨ cong (_+_ n) eq ⟩
n + (toℕ r + q * n)
≡⟨ solve 3 (λ n r q → n :+ (r :+ q :* n) :=
r :+ (con 1 :+ q) :* n)
refl n (toℕ r) q ⟩
toℕ r + suc q * n
∎
------------------------------------------------------------------------
-- Division
-- A specification of integer division.
record DivMod (dividend divisor : ℕ) : Set where
constructor result
field
quotient : ℕ
remainder : Fin divisor
property : dividend ≡ toℕ remainder + quotient * divisor
-- Integer division with remainder.
-- Note that Induction.Nat.<-rec is used to establish termination of
-- division. The run-time complexity of this implementation of integer
-- division should be linear in the size of the dividend, assuming
-- that well-founded recursion and the equality type are optimised
-- properly (see "Inductive Families Need Not Store Their Indices"
-- (Brady, McBride, McKinna, TYPES 2003)).
_divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
_divMod_ m n {≢0} = <-rec Pred dm m n {≢0}
where
Pred : ℕ → Set
Pred dividend = (divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
1+_ : ∀ {k n} → DivMod (suc k) n → DivMod (suc n + k) n
1+_ {k} {n} (result q r eq) = result (1 + q) r (lem₃ n k q r eq)
dm : (dividend : ℕ) → <-Rec Pred dividend → Pred dividend
dm m rec zero {≢0 = ()}
dm zero rec (suc n) = result 0 zero refl
dm (suc m) rec (suc n) with compare m n
dm (suc m) rec (suc .(suc m + k)) | less .m k = result 0 r (lem₁ m k)
where r = suc (Fin.inject+ k (fromℕ m))
dm (suc m) rec (suc .m) | equal .m = result 1 zero (lem₂ m)
dm (suc .(suc n + k)) rec (suc n) | greater .n k =
1+ rec (suc k) le (suc n)
where le = s≤′s (s≤′s (n≤′m+n n k))
-- Integer division.
_div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
_div_ m n {≢0} = DivMod.quotient $ _divMod_ m n {≢0}
-- The remainder after integer division.
_mod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → Fin divisor
_mod_ m n {≢0} = DivMod.remainder $ _divMod_ m n {≢0}
| 33.424528
| 79
| 0.518769
|
50b8352825106b5e804d0de7128705ec9cf5af8b
| 227
|
agda
|
Agda
|
test/Succeed/Issue3667.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3667.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3667.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
data Unit : Set where
unit : Unit
P : Unit → Set
P unit = Unit
postulate
Q : (u : Unit) → P u → Set
variable
u : Unit
p : P u
postulate
q : P u → Q u p
q' : (u : Unit) (p : P u) → P u → Q u p
q' u p = q {u} {p}
| 11.35
| 39
| 0.493392
|
a1faad9bcffd8fb4ac9dd34073bae31d434acbad
| 63
|
agda
|
Agda
|
test/epic/Prelude/Unit.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/epic/Prelude/Unit.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
test/epic/Prelude/Unit.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | null | null | null |
module Prelude.Unit where
data Unit : Set where
unit : Unit
| 12.6
| 25
| 0.730159
|
416becf895a38ad44c9d7aa9c062750a6f2ae9e5
| 4,408
|
agda
|
Agda
|
core/lib/types/Wedge.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Wedge.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Wedge.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Coproduct
open import lib.types.Paths
open import lib.types.Pointed
open import lib.types.Pushout
open import lib.types.PushoutFlattening
open import lib.types.PushoutFmap
open import lib.types.Span
open import lib.types.Unit
-- Wedge of two pointed types is defined as a particular case of pushout
module lib.types.Wedge where
module _ {i j} (X : Ptd i) (Y : Ptd j) where
wedge-span : Span
wedge-span = span (de⊙ X) (de⊙ Y) Unit (λ _ → pt X) (λ _ → pt Y)
Wedge : Type (lmax i j)
Wedge = Pushout wedge-span
infix 80 _∨_
_∨_ = Wedge
module _ {i j} {X : Ptd i} {Y : Ptd j} where
winl : de⊙ X → X ∨ Y
winl x = left x
winr : de⊙ Y → X ∨ Y
winr y = right y
wglue : winl (pt X) == winr (pt Y)
wglue = glue tt
module _ {i j} (X : Ptd i) (Y : Ptd j) where
⊙Wedge : Ptd (lmax i j)
⊙Wedge = ⊙[ Wedge X Y , winl (pt X) ]
infix 80 _⊙∨_
_⊙∨_ = ⊙Wedge
module _ {i j} {X : Ptd i} {Y : Ptd j} where
⊙winl : X ⊙→ X ⊙∨ Y
⊙winl = (winl , idp)
⊙winr : Y ⊙→ X ⊙∨ Y
⊙winr = (winr , ! wglue)
module _ {i j} {X : Ptd i} {Y : Ptd j} where
module WedgeElim {k} {P : X ∨ Y → Type k}
(inl* : (x : de⊙ X) → P (winl x)) (inr* : (y : de⊙ Y) → P (winr y))
(glue* : inl* (pt X) == inr* (pt Y) [ P ↓ wglue ]) where
private
module M = PushoutElim inl* inr* (λ _ → glue*)
f = M.f
glue-β = M.glue-β unit
open WedgeElim public using () renaming (f to Wedge-elim)
module WedgeRec {k} {C : Type k} (inl* : de⊙ X → C) (inr* : de⊙ Y → C)
(glue* : inl* (pt X) == inr* (pt Y)) where
private
module M = PushoutRec {d = wedge-span X Y} inl* inr* (λ _ → glue*)
f = M.f
glue-β = M.glue-β unit
open WedgeRec public using () renaming (f to Wedge-rec)
module ⊙WedgeRec {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(g : X ⊙→ Z) (h : Y ⊙→ Z) where
open WedgeRec (fst g) (fst h) (snd g ∙ ! (snd h)) public
⊙f : X ⊙∨ Y ⊙→ Z
⊙f = (f , snd g)
⊙winl-β : ⊙f ⊙∘ ⊙winl == g
⊙winl-β = idp
⊙winr-β : ⊙f ⊙∘ ⊙winr == h
⊙winr-β = ⊙λ= (λ _ → idp) $
ap (_∙ snd g)
(ap-! f wglue ∙ ap ! glue-β ∙ !-∙ (snd g) (! (snd h)))
∙ ∙-assoc (! (! (snd h))) (! (snd g)) (snd g)
∙ ap (! (! (snd h)) ∙_) (!-inv-l (snd g))
∙ ∙-unit-r (! (! (snd h)))
∙ !-! (snd h)
⊙Wedge-rec = ⊙WedgeRec.⊙f
⊙Wedge-rec-post∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(k : Z ⊙→ W) (g : X ⊙→ Z) (h : Y ⊙→ Z)
→ k ⊙∘ ⊙Wedge-rec g h == ⊙Wedge-rec (k ⊙∘ g) (k ⊙∘ h)
⊙Wedge-rec-post∘ k g h = ⊙λ=
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in' $ ⊙WedgeRec.glue-β (k ⊙∘ g) (k ⊙∘ h)
∙ lemma (fst k) (snd g) (snd h) (snd k)
∙ ! (ap (ap (fst k)) (⊙WedgeRec.glue-β g h))
∙ ∘-ap (fst k) (fst (⊙Wedge-rec g h)) wglue))
idp
where
lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y z : A} {w : B}
(p : x == z) (q : y == z) (r : f z == w)
→ (ap f p ∙ r) ∙ ! (ap f q ∙ r) == ap f (p ∙ ! q)
lemma f idp idp idp = idp
⊙Wedge-rec-η : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ ⊙Wedge-rec ⊙winl ⊙winr == ⊙idf (X ⊙∨ Y)
⊙Wedge-rec-η = ⊙λ=
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in' $ ap-idf wglue
∙ ! (!-! wglue)
∙ ! (⊙WedgeRec.glue-β ⊙winl ⊙winr)))
idp
module _ {i j} {X : Ptd i} {Y : Ptd j} where
add-wglue : de⊙ (X ⊙⊔ Y) → X ∨ Y
add-wglue (inl x) = winl x
add-wglue (inr y) = winr y
⊙add-wglue : X ⊙⊔ Y ⊙→ X ⊙∨ Y
⊙add-wglue = add-wglue , idp
module Fold {i} {X : Ptd i} = ⊙WedgeRec (⊙idf X) (⊙idf X)
fold = Fold.f
⊙fold = Fold.⊙f
module _ {i j} (X : Ptd i) (Y : Ptd j) where
module Projl = ⊙WedgeRec (⊙idf X) (⊙cst {X = Y})
module Projr = ⊙WedgeRec (⊙cst {X = X}) (⊙idf Y)
projl = Projl.f
projr = Projr.f
⊙projl = Projl.⊙f
⊙projr = Projr.⊙f
module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}
(eqX : X ⊙≃ X') (eqY : Y ⊙≃ Y') where
wedge-span-emap : SpanEquiv (wedge-span X Y) (wedge-span X' Y')
wedge-span-emap = ( span-map (fst (fst eqX)) (fst (fst eqY)) (idf _)
(comm-sqr λ _ → snd (fst eqX))
(comm-sqr λ _ → snd (fst eqY))
, snd eqX , snd eqY , idf-is-equiv _)
∨-emap : X ∨ Y ≃ X' ∨ Y'
∨-emap = Pushout-emap wedge-span-emap
⊙∨-emap : X ⊙∨ Y ⊙≃ X' ⊙∨ Y'
⊙∨-emap = ≃-to-⊙≃ ∨-emap (ap winl (snd (fst eqX)))
| 26.878049
| 78
| 0.495463
|
df844e17a2b8271ec4ac9fba2fce7f5b6ecc8d8a
| 2,431
|
agda
|
Agda
|
theorems/homotopy/WedgeExtension.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/WedgeExtension.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/WedgeExtension.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module homotopy.WedgeExtension
{i j} {A : Type i} {a₀ : A} {B : Type j} {b₀ : B} where
-- easier to keep track of than a long list of arguments
record args : Type (lmax (lsucc i) (lsucc j)) where
field
n m : ℕ₋₂
cA : is-connected (S n) A
cB : is-connected (S m) B
P : A → B → (n +2+ m) -Type (lmax i j)
f : (a : A) → fst (P a b₀)
g : (b : B) → fst (P a₀ b)
p : f a₀ == g b₀
private
module _ (r : args) where
open args r
Q : A → n -Type (lmax i j)
Q a = ((Σ (∀ b → fst (P a b)) (λ k → (k ∘ cst b₀) == cst (f a)) ,
conn-elim-general (pointed-conn-out B b₀ cB)
(P a) (cst (f a))))
l : Π A (fst ∘ Q)
l = conn-elim (pointed-conn-out A a₀ cA)
Q (λ (_ : Unit) → (g , ap cst (! p)))
module _ (r : args) where
open args r
ext : ∀ a → ∀ b → fst (P a b)
ext a = fst (l r a)
module _ {r : args} where
open args r
abstract
β-l : ∀ a → ext r a b₀ == f a
β-l a = ap (λ t → t unit) (snd (l r a))
abstract
β-r-aux : fst (l r a₀) == g
β-r-aux = fst= (conn-elim-β
(pointed-conn-out A a₀ cA)
(Q r) (λ (_ : Unit) → (g , ap cst (! p))) unit)
abstract
β-r : ∀ b → ext r a₀ b == g b
β-r = app= β-r-aux
abstract
coh : ! (β-l a₀) ∙ β-r b₀ == p
coh =
! (β-l a₀) ∙ β-r b₀
=⟨ ! lemma₂ |in-ctx (λ w → ! w ∙ β-r b₀) ⟩
! (β-r b₀ ∙ ! p) ∙ β-r b₀
=⟨ !-∙ (β-r b₀) (! p) |in-ctx (λ w → w ∙ β-r b₀) ⟩
(! (! p) ∙ ! (β-r b₀)) ∙ β-r b₀
=⟨ !-! p |in-ctx (λ w → (w ∙ ! (β-r b₀)) ∙ β-r b₀) ⟩
(p ∙ ! (β-r b₀)) ∙ β-r b₀
=⟨ ∙-assoc p (! (β-r b₀)) (β-r b₀) ⟩
p ∙ ! (β-r b₀) ∙ β-r b₀
=⟨ ap (λ w → p ∙ w) (!-inv-l (β-r b₀)) ∙ ∙-unit-r p ⟩
p ∎
where
lemma₁ : β-l a₀ == ap (λ s → s unit) (ap cst (! p))
[ (λ k → k b₀ == f a₀) ↓ β-r-aux ]
lemma₁ = ap↓ (ap (λ s → s unit)) $
snd= (conn-elim-β (pointed-conn-out A a₀ cA)
(Q r) (λ (_ : Unit) → (g , ap cst (! p))) unit)
lemma₂ : β-r b₀ ∙ ! p == β-l a₀
lemma₂ = ap (λ w → β-r b₀ ∙ w)
(! (ap-idf (! p)) ∙ ap-∘ (λ s → s unit) cst (! p))
∙ (! (↓-app=cst-out lemma₁))
| 29.646341
| 74
| 0.393665
|
12fdb2b52721fb5010c8eabd62f2f95bb8652185
| 3,186
|
agda
|
Agda
|
Graph/Category.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Graph/Category.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Graph/Category.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
open import Type
module Graph.Category {ℓ₁ ℓ₂} {V : Type{ℓ₁}} where
open import Data.Tuple as Tuple using ()
open import Functional
open import Logic.Propositional
import Lvl
open import Graph{ℓ₁}{ℓ₂}(V)
open import Graph.Walk{ℓ₁}{ℓ₂}{V}
open import Graph.Walk.Proofs{ℓ₁}{ℓ₂}{V}
open import Relator.Equals
open import Relator.Equals.Proofs
open import Relator.Equals.Proofs.Equiv
open import Structure.Category
import Structure.Categorical.Names as Names
open import Structure.Categorical.Properties
open import Structure.Function
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Transitivity
module _ (_⟶_ : Graph) where
private variable a b c d : V
private variable e e₁ e₂ e₃ : a ⟶ b
private variable w w₁ w₂ w₃ : Walk(_⟶_) a b
Walk-transitivity-raw-identityₗ-raw : (Walk-transitivity-raw at w ≡ w)
Walk-transitivity-raw-identityₗ-raw = [≡]-intro
Walk-transitivity-raw-identityᵣ-raw : (Walk-transitivity-raw w at ≡ w)
Walk-transitivity-raw-identityᵣ-raw {a}{.a} {Walk.at} = [≡]-intro
Walk-transitivity-raw-identityᵣ-raw {a}{c} {Walk.prepend {b = b} e w} = congruence₁(prepend e) (Walk-transitivity-raw-identityᵣ-raw {b}{c} {w})
Walk-transitivity-raw-associativity-raw : Names.Morphism.Associativity{Obj = V}(\{w} → Walk-transitivity-raw{_⟶_ = _⟶_}{z = w})
Walk-transitivity-raw-associativity-raw {a}{b}{c}{d} {Walk.at} {w₂}{w₃} = [≡]-intro
Walk-transitivity-raw-associativity-raw {a}{b}{c}{d} {Walk.prepend e w₁}{w₂}{w₃} = congruence₁(prepend e) (Walk-transitivity-raw-associativity-raw {a}{b}{c}{_} {w₁}{w₂}{w₃})
instance
Walk-transitivity-raw-identityₗ : Morphism.Identityₗ{Obj = V}(\{w} → Walk-transitivity-raw{z = w})(at)
Walk-transitivity-raw-identityₗ = Morphism.intro Walk-transitivity-raw-identityₗ-raw
instance
Walk-transitivity-raw-identityᵣ : Morphism.Identityᵣ{Obj = V}(\{w} → Walk-transitivity-raw{z = w})(at)
Walk-transitivity-raw-identityᵣ = Morphism.intro Walk-transitivity-raw-identityᵣ-raw
instance
Walk-transitivity-raw-identity : Morphism.Identity{Obj = V}(\{w} → Walk-transitivity-raw{_⟶_ = _⟶_}{z = w})(at)
Walk-transitivity-raw-identity = [∧]-intro Walk-transitivity-raw-identityₗ Walk-transitivity-raw-identityᵣ
-- The category arising from a graph by its vertices and walks.
-- Note that `Walk` is defined so that every sequence of edges have an unique walk. For example `ReflexitiveTransitiveClosure` (a relation equivalent to a walk) would not work.
free-category : Category(Walk(_⟶_))
Category._∘_ free-category = swap(transitivity(Walk(_⟶_)))
Category.id free-category = reflexivity(Walk(_⟶_))
BinaryOperator.congruence (Category.binaryOperator free-category) [≡]-intro [≡]-intro = [≡]-intro
Morphism.Associativity.proof (Category.associativity free-category) {a}{b}{c}{d} {w₁}{w₂}{w₃} = symmetry(_≡_) (Walk-transitivity-raw-associativity-raw {d}{c}{b}{a} {w₃}{w₂}{w₁})
Morphism.Identityₗ.proof (Tuple.left (Category.identity free-category)) = Walk-transitivity-raw-identityᵣ-raw
Morphism.Identityᵣ.proof (Tuple.right (Category.identity free-category)) = Walk-transitivity-raw-identityₗ-raw
| 53.1
| 179
| 0.728186
|
1d396f4e6e39820424ea6917f7d8c62aac654572
| 883
|
agda
|
Agda
|
part1/lists/map-is-foldr.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | 1
|
2020-07-07T09:42:22.000Z
|
2020-07-07T09:42:22.000Z
|
part1/lists/map-is-foldr.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
part1/lists/map-is-foldr.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
module map-is-foldr where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; cong)
open Eq.≡-Reasoning
open import lists using (List; []; _∷_; map; foldr)
postulate
-- 外延性の公理
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
-- 外延性の公理を利用した証明のための補題
lemma : ∀ {A B : Set} → (f : A → B) → (xs : List A)
→ map f xs ≡ foldr (λ x xs → f x ∷ xs) [] xs
lemma f [] =
begin
map f []
≡⟨⟩
[]
≡⟨⟩
foldr (λ x xs → f x ∷ xs) [] []
∎
lemma f (x ∷ xs) =
begin
map f (x ∷ xs)
≡⟨⟩
f x ∷ map f xs
≡⟨ cong (f x ∷_) (lemma f xs) ⟩
f x ∷ foldr (λ x xs → f x ∷ xs) [] xs
≡⟨⟩
foldr (λ x xs → f x ∷ xs) [] (x ∷ xs)
∎
-- mapが畳み込みで表現できることの証明
map-is-foldr : ∀ {A B : Set} → (f : A → B)
→ map f ≡ foldr (λ x xs → f x ∷ xs) []
map-is-foldr f = extensionality (lemma f)
| 21.536585
| 51
| 0.484711
|
cb8cd4ebb79c39065810aae2219ed875a9ece805
| 439
|
agda
|
Agda
|
test/Succeed/RewriteQualified.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/RewriteQualified.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/RewriteQualified.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-08-01, issue #2125, qualified names in pragmas
{-# OPTIONS --rewriting --confluence-check #-}
import Common.Equality as Eq
{-# BUILTIN REWRITE Eq._≡_ #-} -- qualified name, should be accepted
postulate
A : Set
a b : A
module M where
open Eq
postulate
rule : a ≡ b
{-# REWRITE M.rule #-} -- qualified name, should be accepted
-- ERROR WAS: in the name M.rule, the part M.rule is not valid
-- NOW: works
| 19.954545
| 68
| 0.66287
|
5972e0b99fab564766e43d1e09f5a451afc063ff
| 566
|
agda
|
Agda
|
test/Succeed/Issue5291.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue5291.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue5291.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2021-08-19, issue #5291 reported by gergoerdi
-- https://stackoverflow.com/q/66816547/477476
open import Agda.Builtin.Char
open import Agda.Builtin.String
works : Char
works = '\SOH'
-- This used to fail as the matcher was committed to finding SOH after SO.
-- (Worked only for prefix-free matching.)
test : Char
test = '\SO'
-- Here, all the silly legacy ASCII escape sequences in their glorious detail...
all : String
all = "\NUL\SOH\STX\ETX\EOT\ENQ\ACK\BEL\BS\HT\LF\VT\FF\CR\SO\SI\DEL\DLE\DC1\DC2\DC3\DC4\NAK\SYN\ETB\CAN\EM\SUB\ESC\FS\GS\RS\US"
| 28.3
| 127
| 0.724382
|
dfa8f69e4fa80281f406f53bd4f7e7dd6a6bfd7a
| 4,695
|
agda
|
Agda
|
agda/sn-calculus-confluence.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/sn-calculus-confluence.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/sn-calculus-confluence.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
module _ where
open import Data.Nat using (_+_)
open import Data.Nat.Properties.Simple using ( +-comm ; +-assoc)
open import utility
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Environment as Env
open import Esterel.Context
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.List
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Data.Empty
open import sn-calculus
open import context-properties
open import Esterel.Lang.Binding
open import Data.Maybe using ( just )
open import Function using (_$_)
open import Data.FiniteMap
import Data.OrderedListMap as OMap
open import Data.Nat as Nat using (ℕ)
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
open import sn-calculus-confluence.helper
open import sn-calculus-confluence.rec
open import sn-calculus-confluence.potrec
open import sn-calculus-confluence.potpot
ρ-conf : ∀{p FV BV ql qr θ qi A} → CorrectBinding p FV BV → p sn⟶₁ ql → p sn⟶₁ qr → p ≡ (ρ⟨ θ , A ⟩· qi)
→ ql ≡ qr
⊎ (∃ (λ o → ql sn⟶₁ o × qr sn⟶₁ o))
⊎ ql sn⟶₁ qr
⊎ qr sn⟶₁ ql
ρ-conf {(ρ⟨ θ , .A ⟩· qi)}{ql = ql}{qr = qr}{A = A} cb redl redr refl with ρ-stays-ρ-sn⟶₁ redl | ρ-stays-ρ-sn⟶₁ redr
... | (θl , qlin , Al , refl) | (θr , qrin , Ar , refl) with get-view redl | get-view redr
ρ-conf {(ρ⟨ θ , .A ⟩· qi)}{ql = ql}{qr = qr}{A = A} cb redl redr refl | (θl , qlin , Al , refl) | (θr , qrin , Ar , refl) | inj₁ (_ , _ , _ , _ , _ , viewl) | inj₁ (_ , _ , _ , _ , _ , viewr)
with E-view-main-bind viewl viewr
... | inj₁ (e= , q= , θ= , A=) rewrite e= | q= | θ= | A= = inj₁ refl
... | inj₂ ~a with ρ-conf-rec cb _ _ ~a redl redr _ _ viewl viewr
... | (θo , Ao , so , _ , _ , _ , _ , _ , _ , redol , redor , _) = inj₂ $ inj₁ ((ρ⟨ θo , Ao ⟩· so) , redol , redor)
ρ-conf {(ρ⟨ θ , .A ⟩· qi)}{ql = ql}{qr = qr}{A = A} cb redl redr refl | (θl , qlin , Al , refl) | (θr , qrin , Ar , refl) | inj₁ (_ , _ , _ , _ , _ , viewl) | inj₂ (_ , _ , viewr)
with ρ-pot-conf-rec cb viewr viewl
... | inj₁ redo = inj₂ (inj₂ (inj₂ redo))
... | inj₂ (s , env , Ao , redol , redor) = inj₂ $ inj₁ (ρ⟨ env , Ao ⟩· s , redor , redol)
ρ-conf {(ρ⟨ θ , .A ⟩· qi)}{ql = ql}{qr = qr}{A = A} cb redl redr refl | (θl , qlin , Al , refl) | (θr , qrin , Ar , refl) | inj₂ (_ , _ , viewl) | inj₁ (_ , _ , _ , _ , _ , viewr)
with ρ-pot-conf-rec cb viewl viewr
... | inj₁ redo = inj₂ (inj₂ (inj₁ redo))
... | inj₂ (s , env , Ao , redol , redor) = inj₂ $ inj₁ ((ρ⟨ env , Ao ⟩· s) , redol , redor)
ρ-conf {(ρ⟨ θ , .A ⟩· qi)}{ql = ql}{qr = qr}{A = A} cb redl redr refl | (θl , qlin , Al , refl) | (θr , qrin , Ar , refl) | inj₂ (_ , _ , viewl) | inj₂ (_ , _ , viewr)
with pot-pot-conf-rec viewl viewr
... | inj₁ eq = inj₁ eq
... | inj₂ (env , redol , redor) = inj₂ $ inj₁ (ρ⟨ env , A ⟩· qi , redol , redor)
R-confluent : ∀{p q r BV FV} → CorrectBinding p BV FV → p sn⟶₁ q → p sn⟶₁ r
→ q ≡ r
⊎ (∃ (λ s → q sn⟶₁ s × r sn⟶₁ s))
⊎ q sn⟶₁ r
⊎ r sn⟶₁ q
R-confluent {.(_ ∥ _)} cb (rpar-done-right p'' q'') (rpar-done-right p' q') = inj₁ ( value-max-unique{d1 = (dhalted p'')}{d2 = q''}{d3 = (dhalted p')}{d4 = q'} )
R-confluent {.(_ ∥ _)} cb (rpar-done-right p'' q'') (rpar-done-left p' q') = inj₁ ( value-max-unique{d1 = (dhalted p'')}{d2 = q''}{d3 = p'}{d4 = (dhalted q')} )
R-confluent {.(_ ∥ _)} cb (rpar-done-left p'' q'') (rpar-done-right p' q') = inj₁ (value-max-unique{d1 = (p'')}{d2 =(dhalted q'')}{d3 = (dhalted p')}{d4 = (q')})
R-confluent {.(_ ∥ _)} cb (rpar-done-left p'' q'') (rpar-done-left p' q') = inj₁ (value-max-unique{d1 = p''}{d2 = (dhalted q'')}{d3 = p'}{d4 = (dhalted q')})
R-confluent {.(loop _)} cb rloop-unroll rloop-unroll = inj₁ refl
R-confluent {.(nothin >> _)} cb rseq-done rseq-done = inj₁ refl
R-confluent {.(exit _ >> _)} cb rseq-exit rseq-exit = inj₁ refl
R-confluent {.(loopˢ (exit _) _)} cb rloopˢ-exit rloopˢ-exit = inj₁ refl
R-confluent {.(suspend nothin _)} cb (rsuspend-done hnothin) (rsuspend-done hnothin) = inj₁ refl
R-confluent {.(suspend (exit n) _)} cb (rsuspend-done (hexit n)) (rsuspend-done (hexit .n)) = inj₁ refl
R-confluent {.(trap nothin)} cb (rtrap-done hnothin) (rtrap-done hnothin) = inj₁ refl
R-confluent {.(trap (exit n))} cb (rtrap-done (hexit n)) (rtrap-done (hexit .n)) = inj₁ refl
R-confluent {.(signl _ _)} cb rraise-signal rraise-signal = inj₁ refl
R-confluent {p@(ρ⟨ _ , _ ⟩· _)} cb redl redr = ρ-conf cb redl redr refl
| 57.962963
| 191
| 0.592332
|
184b4eca0530faea9a8d3070bbfc9352582289b8
| 1,270
|
agda
|
Agda
|
test/Succeed/Issue2045.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2045.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2045.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-06-16 Issue #2045
-- Size solver should be called before checking extended lambda
-- {-# OPTIONS -v tc.term.exlam:100 #-}
{-# OPTIONS --sized-types #-}
open import Common.Size
postulate anything : ∀{a}{A : Set a} → A
data Exp : Size → Set where
abs : ∀ i (t : Exp i) → Exp (↑ i)
data Val : ∀ i (t : Exp i) → Set where
valAbs : ∀ i (t : Exp i) → Val (↑ i) (abs i t)
data Whnf i (t : Exp i) : Set where
immed : (v : Val i t) → Whnf i t
postulate
Evaluate : ∀ i (t : Exp i) (P : (w : Whnf i t) → Set) → Set
worksE : ∀ i (fa : Exp i) → Set
worksE i fa = Evaluate i fa λ{ (immed (valAbs _ _)) → anything }
works : ∀ i (fa : Exp i) → Set
works i fa = Evaluate i fa aux
where
aux : Whnf i fa → Set
aux (immed (valAbs _ _)) = anything
test : ∀ i (fa : Exp i) → Set
test i fa = Evaluate _ fa λ{ (immed (valAbs _ _)) → anything }
-- Should work.
-- WAS:
-- extended lambda's implementation ".extendedlambda1" has type:
-- (Whnf (_38 i fa) fa → Set)
-- Cannot instantiate the metavariable _38 to solution (↑ i₁) since it
-- contains the variable i₁ which is not in scope of the metavariable
-- or irrelevant in the metavariable but relevant in the solution
-- when checking that the pattern (valAbs _ _) has type
-- (Val (_38 i fa) fa)
| 27.021277
| 70
| 0.624409
|
29d73f48434ddea7c78094de5c31cc0de9e18924
| 496
|
agda
|
Agda
|
test/succeed/Issue300.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
test/succeed/Issue300.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Issue300.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --sized-types --show-implicit #-}
-- {-# OPTIONS -v tc.size.solve:20 #-}
module Issue300 where
open import Common.Size
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {↑ size}
suc : {size : Size} -> Nat {size} -> Nat {↑ size}
-- Size meta used in a different context than the one created in
A : Set1
A = (Id : {i : Size} -> Nat {_} -> Set)
(k : Size)(m : Nat {↑ k}) -> Id {k} m
->
(j : Size)(n : Nat {j}) -> Id {j} n
-- should solve _ with ↑ i
| 26.105263
| 64
| 0.546371
|
59842f91863e220e366db52b56e599686291d95c
| 183
|
agda
|
Agda
|
Cubical/HITs/SmashProduct.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/SmashProduct.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SmashProduct.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.SmashProduct where
open import Cubical.HITs.SmashProduct.Base public
-- open import Cubical.HITs.SmashProduct.Properties public
| 26.142857
| 58
| 0.786885
|
4aae168fc47de7fd746f4de0142808776d3e4b23
| 130
|
agda
|
Agda
|
test/Fail/Issue3420-Identity.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
test/Fail/Issue3420-Identity.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Fail/Issue3420-Identity.agda
|
antoinevanmuylder/agda
|
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --cubical-compatible #-}
open import Agda.Primitive
data _≡_ {a} {A : Set a} (x : A) : A → Set where
refl : x ≡ x
| 18.571429
| 48
| 0.584615
|
4a50f51267200cd912fedd98b875686e7cc7c648
| 775
|
agda
|
Agda
|
univ.agda
|
hjorthjort/IdrisToAgda
|
a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1
|
[
"MIT"
] | 2
|
2020-02-16T23:22:50.000Z
|
2020-06-29T20:42:43.000Z
|
univ.agda
|
hjorthjort/IdrisToAgda
|
a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1
|
[
"MIT"
] | 1
|
2019-11-28T17:52:42.000Z
|
2019-11-28T17:52:42.000Z
|
univ.agda
|
hjorthjort/IdrisToAgda
|
a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1
|
[
"MIT"
] | 1
|
2019-11-27T16:25:18.000Z
|
2019-11-27T16:25:18.000Z
|
open import Agda.Primitive
open import Data.List
-- f1 : {l : Level} -> (a : Set l) -> (x : a) -> (y : x) -> x
-- f1 : (a : Set2) -> (x : a) -> (y : x) -> x
-- f1 a x y = ?
f0 : (a : Set) -> (x : a) -> a
f0 a x = x
f1 : (a : Set1) -> (x : a) -> a
f1 a x = x
myprod : (As : List Set) -> Set
myprod = {!!}
mysum : (As : List Set) -> Set
mysum = {!!}
hej : (tyOp : List Set -> Set) -> Set
hej = {!!}
test1 = hej myprod
test2 = hej mysum
Type = Set
data Dummy : Set where Dum : Dummy
-- Start of example
hej2 : List Type -> Type -- Is universe-monomorphic in Agda, but polymorphic in Idris
hej2 (t ∷ ts) = t
hej2 _ = ?
test21 : Type
test21 = hej2 [ Type ] -- test21 == Type in Idris, but Agda complains
test22 : Type
test22 = hej2 [ Dummy ] -- test22 == Dummy
| 19.375
| 89
| 0.538065
|
39e679ffb1b06aa589bb716e887bee6ab30aec6c
| 807
|
agda
|
Agda
|
Categories/Product/Projections.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Product/Projections.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Product/Projections.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
{-# OPTIONS --universe-polymorphism #-}
open import Level
open import Categories.Category
open import Categories.Product
module Categories.Product.Projections
{o ℓ e o′ ℓ′ e′}
(C : Category o ℓ e)
(D : Category o′ ℓ′ e′)
where
open import Categories.Functor
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂; zip; map; <_,_>; swap)
∏₁ : Functor (Product C D) C
∏₁ = record
{ F₀ = proj₁
; F₁ = proj₁
; identity = refl
; homomorphism = refl
; F-resp-≡ = proj₁
} where
open Category.Equiv C
∏₂ : Functor (Product C D) D
∏₂ = record
{ F₀ = proj₂
; F₁ = proj₂
; identity = refl
; homomorphism = refl
; F-resp-≡ = proj₂
} where
open Category.Equiv D
| 22.416667
| 81
| 0.552664
|
50a498bd6b2c040c503cfee4bf5f4a5561799bc5
| 3,355
|
agda
|
Agda
|
ProcessProgress.agda
|
danelahman/aeff-agda
|
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
|
[
"MIT"
] | 4
|
2020-07-17T00:15:00.000Z
|
2021-03-22T22:48:48.000Z
|
ProcessProgress.agda
|
danelahman/aeff-agda
|
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
|
[
"MIT"
] | null | null | null |
ProcessProgress.agda
|
danelahman/aeff-agda
|
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
|
[
"MIT"
] | null | null | null |
open import Data.Empty
open import Data.List renaming (_∷_ to _∷ₗ_ ; [_] to [_]ₗ)
open import Data.Maybe
open import Data.Product
open import Data.Sum
open import Data.Unit
open import AEff
open import AwaitingComputations
open import EffectAnnotations
open import Preservation
open import ProcessPreservation
open import Progress
open import Renamings
open import Substitutions
open import Types
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary
open import Relation.Nullary.Negation
module ProcessProgress where
-- PROCESS RESULTS
data ParResult⟨_⟩ : {o : O} {PP : PType o} → [] ⊢P⦂ PP → Set where
run : {X : VType}
{o : O}
{i : I} →
{M : [] ⊢M⦂ X ! (o , i)} →
RunResult⟨ [] ∣ M ⟩ →
--------------------------
ParResult⟨ run M ⟩
par : {o o' : O}
{PP : PType o}
{QQ : PType o'}
{P : [] ⊢P⦂ PP}
{Q : [] ⊢P⦂ QQ} →
ParResult⟨ P ⟩ →
ParResult⟨ Q ⟩ →
------------------
ParResult⟨ P ∥ Q ⟩
data ProcResult⟨_⟩ : {o : O} {PP : PType o} → [] ⊢P⦂ PP → Set where
proc : {o : O}
{PP : PType o}
{P : [] ⊢P⦂ PP} →
ParResult⟨ P ⟩ →
-----------------
ProcResult⟨ P ⟩
signal : {o : O}
{PP : PType o}
{op : Σₛ}
{p : op ∈ₒ o}
{V : [] ⊢V⦂ ``(payload op)}
{P : [] ⊢P⦂ PP} →
ProcResult⟨ P ⟩ →
---------------------------
ProcResult⟨ ↑ op p V P ⟩
-- PROGRESS THEOREM FOR PROCESSES
{- THEOREM 4.3 -}
proc-progress : {o : O}
{PP : PType o} →
(P : [] ⊢P⦂ PP) →
-------------------------------------------------------------------------------
(Σ[ o' ∈ O ] Σ[ QQ ∈ PType o' ] Σ[ r ∈ PP ⇝ QQ ] Σ[ Q ∈ [] ⊢P⦂ QQ ] (P [ r ]↝ Q)
⊎
ProcResult⟨ P ⟩)
proc-progress (run {X} {o} {i} M) with progress M
... | inj₁ (M' , r) =
inj₁ (_ , _ , _ , _ , run r)
... | inj₂ (comp R) =
inj₂ (proc (run R))
... | inj₂ (signal {_} {_} {_} {_} {p} {V} {Q} R) =
inj₁ (_ , _ , _ , _ , ↑ p V Q)
proc-progress (P ∥ Q) with proc-progress P
... | inj₁ (o' , PP' , r , P' , r') =
inj₁ (_ , _ , _ , _ , context ([-] ∥ₗ Q) r')
... | inj₂ R with proc-progress Q
... | inj₁ (o' , QQ' , r , Q' , r') =
inj₁ (_ , _ , _ , _ , context (P ∥ᵣ [-]) r')
proc-progress (P ∥ Q) | inj₂ (proc R) | inj₂ (proc R') =
inj₂ (proc (par R R'))
proc-progress (P ∥ .(↑ _ _ _ _)) | inj₂ R | inj₂ (signal {_} {_} {_} {p} {V} {Q} R') =
inj₁ (_ , _ , _ , _ , ↑-∥ᵣ p V P Q)
proc-progress (.(↑ _ _ _ _) ∥ Q) | inj₂ (signal {_} {_} {_} {p} {V} {P} R) | inj₂ R' =
inj₁ (_ , _ , _ , _ , ↑-∥ₗ p V P Q)
proc-progress (↑ op p V P) with proc-progress P
... | inj₁ (o' , PP' , r , P' , r') =
inj₁ (_ , _ , _ , _ , context (↑ op p V [-]) r')
... | inj₂ R =
inj₂ (signal R)
proc-progress (↓ op V P) with proc-progress P
... | inj₁ (o' , OO' , r , P' , r') =
inj₁ (_ , _ , _ , _ , context (↓ op V [-]) r')
... | inj₂ (proc (run {_} {_} {_} {M} R)) =
inj₁ (_ , _ , _ , _ , ↓-run V M)
... | inj₂ (proc (par {_} {_} {_} {_} {Q} {Q'} R R')) =
inj₁ (_ , _ , _ , _ , ↓-∥ V Q Q')
... | inj₂ (signal {_} {_} {_} {p} {W} {Q} R) =
inj₁ (_ , _ , _ , _ , ↓-↑ p V W Q)
| 30.225225
| 96
| 0.430402
|
10088c6888bc6db111fe4d5bc49ad4efaf1630f4
| 434
|
agda
|
Agda
|
src/PathStructure/Empty.agda
|
vituscze/HoTT-lectures
|
7730385adfdbdda38ee8b124be3cdeebb7312c65
|
[
"BSD-3-Clause"
] | null | null | null |
src/PathStructure/Empty.agda
|
vituscze/HoTT-lectures
|
7730385adfdbdda38ee8b124be3cdeebb7312c65
|
[
"BSD-3-Clause"
] | null | null | null |
src/PathStructure/Empty.agda
|
vituscze/HoTT-lectures
|
7730385adfdbdda38ee8b124be3cdeebb7312c65
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module PathStructure.Empty where
open import Equivalence
open import Types
split-path : {x y : ⊥} → x ≡ y → ⊥
split-path = J (λ _ _ _ → ⊥) id _ _
merge-path : {x y : ⊥} → ⊥ → x ≡ y
merge-path = 0-elim
split-merge-eq : {x y : ⊥} → (x ≡ y) ≃ ⊥
split-merge-eq
= split-path
, (merge-path , λ b → 0-elim b)
, (merge-path , J
(λ _ _ p → merge-path (split-path p) ≡ p)
(λ b → 0-elim b) _ _)
| 21.7
| 47
| 0.543779
|
310dde3d3b482ad31915f9c7bcd69bafcea192ef
| 6,999
|
agda
|
Agda
|
formalization/Data/Bit.agda
|
brunoczim/Celeste
|
9f5129d97ee7b89fb8e43136779a78806b7506ab
|
[
"MIT"
] | 1
|
2020-09-16T17:31:57.000Z
|
2020-09-16T17:31:57.000Z
|
formalization/Data/Bit.agda
|
brunoczim/Celeste
|
9f5129d97ee7b89fb8e43136779a78806b7506ab
|
[
"MIT"
] | null | null | null |
formalization/Data/Bit.agda
|
brunoczim/Celeste
|
9f5129d97ee7b89fb8e43136779a78806b7506ab
|
[
"MIT"
] | null | null | null |
module Data.Bit where
open import Data.Nat.Literal using (Number; ℕ-num; Fin-num)
open import Data.Nat using (ℕ ; suc; zero; ⌊_/2⌋)
renaming (_*_ to ℕ*; _+_ to ℕ+; _≤_ to ℕ≤; _^_ to ℕ^)
open import Data.Int.Literal using (Negative)
open import Data.Fin using (Fin; suc; zero; raise)
renaming (toℕ to finToℕ; fromℕ to finFromℕ)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Data.Vec using (Vec; []; _∷_; _++_; replicate; insert; head; tail)
renaming (map to mapVec)
open import Data.Unit using (⊤)
open import Data.Empty using (⊥)
open import Level using (_⊔_)
open import Data.Bool using (Bool; false; true) renaming (_∧_ to Bool-∧)
open import Data.Maybe using (Maybe; just; nothing; map)
record WithCarry {a} {c} (A : Set a) (C : Set c) : Set (a ⊔ c) where
constructor _with-carry:_
field
result : A
carry : C
open WithCarry public
record Overflowing {a} (A : Set a) : Set a where
constructor _overflow:_
field
result : A
overflow : Bool
open Overflowing public
data Bit : Set where
b0 : Bit
b1 : Bit
infixl 8 _-_ _+_
infixl 7 _<<_ _>>_
infixl 6 _∧_ _&_
infixl 5 _⊕_ _^_
infixl 4 _∨_ _~|_
infixl 3 _↔_ _==_
infixl 1 _with-carry:_
fromBool : Bool → Bit
fromBool false = b0
fromBool true = b1
toBool : Bit → Bool
toBool b0 = false
toBool b1 = true
! : Bit → Bit
! b0 = b1
! b1 = b0
_∧_ : Bit → Bit → Bit
b0 ∧ _ = b0
b1 ∧ q = q
_∨_ : Bit → Bit → Bit
b0 ∨ q = q
b1 ∨ _ = b1
_⊕_ : Bit → Bit → Bit
b0 ⊕ q = q
b1 ⊕ q = ! q
_↔_ : Bit → Bit → Bit
b0 ↔ q = ! q
b1 ↔ q = q
maj3 : Bit → Bit → Bit → Bit
maj3 p q r = p ∧ q ∨ p ∧ r ∨ q ∧ r
half-add : Bit → Bit → WithCarry Bit Bit
half-add p q = p ⊕ q with-carry: p ∧ q
full-add : Bit → Bit → Bit → WithCarry Bit Bit
full-add p q r = p ⊕ q ⊕ r with-carry: maj3 p q r
full-addₙ : {n : ℕ} →
Vec Bit n →
Vec Bit n →
Bit →
WithCarry (Vec Bit n) (Vec Bit 2)
full-addₙ [] [] r = [] with-carry: b0 ∷ r ∷ []
full-addₙ (p ∷ []) (q ∷ []) r = result s ∷ [] with-carry: r ∷ carry s ∷ [] where
s = full-add p q r
full-addₙ (p ∷ ps) (q ∷ qs) r = result s ∷ result ss with-carry: carry ss where
s = full-add p q r
ss = full-addₙ ps qs (carry s)
!ₙ : {n : ℕ} → Vec Bit n → Vec Bit n
!ₙ = mapVec !
_+_ : {n : ℕ} → Vec Bit n → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
ps + qs = full-addₙ ps qs b0
_-_ : {n : ℕ} → Vec Bit n → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
ps - qs = full-addₙ ps (!ₙ qs) b1
inc : {n : ℕ} → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
inc ps = full-addₙ ps (replicate b0) b1
dec : {n : ℕ} → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
dec ps = full-addₙ ps (replicate b1) b0
_>>_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
ps >> zero = ps with-carry: replicate b0
_>>_ {suc m} (p ∷ ps) (suc i) = new-result with-carry: new-carry
where
qs : WithCarry (Vec Bit m) (Vec Bit m)
qs = ps >> i
new-result : Vec Bit (suc m)
new-result = insert (result qs) (finFromℕ m) b0
new-carry : Vec Bit (suc m)
new-carry = insert (carry qs) (finFromℕ m) p
_<<_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
_<<_ {m} ps i = proj₂ (do-shift ps) where
do-shift : {n : ℕ} → Vec Bit n → Fin m × WithCarry (Vec Bit n) (Vec Bit n)
do-shift [] = i , ([] with-carry: [])
do-shift {suc n} (p ∷ ps) = ret (proj₁ pair) where
pair : Fin m × WithCarry (Vec Bit n) (Vec Bit n)
pair = do-shift ps
qs : WithCarry (Vec Bit n) (Vec Bit n)
qs = proj₂ pair
ret : Fin m → Fin m × WithCarry (Vec Bit (suc n)) (Vec Bit (suc n))
ret zero = zero , (b0 ∷ result qs with-carry: p ∷ carry qs)
ret (suc j) = raise 1 j , (p ∷ result qs with-carry: b0 ∷ carry qs)
_>>>_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
ps >>> zero = ps with-carry: replicate b0
_>>>_ {suc m} (p ∷ ps) (suc i) = new-result with-carry: new-carry where
qs : WithCarry (Vec Bit m) (Vec Bit m)
qs = ps >> i
new-result : Vec Bit (suc m)
new-result = insert (result qs) (finFromℕ m) p
new-carry : Vec Bit (suc m)
new-carry = b0 ∷ carry qs
_<<<_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
ps <<< zero = ps with-carry: replicate b0
_<<<_ {suc m} (p ∷ ps) (suc i) = new-result with-carry: new-carry where
qs : WithCarry (Vec Bit m) (Vec Bit m)
qs = ps << i
new-result : Vec Bit (suc m)
new-result = p ∷ result qs
new-carry : Vec Bit (suc m)
new-carry = insert (result qs) (finFromℕ m) b0
_&_ : {n : ℕ} → Vec Bit n → Vec Bit n → Vec Bit n
[] & [] = []
(p ∷ ps) & (q ∷ qs) = p ∧ q ∷ ps & qs
_~|_ : {n : ℕ} → Vec Bit n → Vec Bit n → Vec Bit n
[] ~| [] = []
(p ∷ ps) ~| (q ∷ qs) = (p ∨ q) ∷ (ps ~| qs)
_^_ : {n : ℕ} → Vec Bit n → Vec Bit n → Vec Bit n
[] ^ [] = []
(p ∷ ps) ^ (q ∷ qs) = (p ⊕ q) ∷ (ps ^ qs)
~ : {n : ℕ} → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
~ n = inc (!ₙ n)
toℕ : Bit → ℕ
toℕ b0 = 0
toℕ b1 = 1
toFin : {n : ℕ} → Bit → Fin (suc (suc n))
toFin b0 = 0
toFin b1 = 1
toℕₙ : {n : ℕ} → Vec Bit n → ℕ
toℕₙ [] = 0
toℕₙ (p ∷ ps) = ℕ+ (toℕ p) (ℕ* 2 (toℕₙ ps))
tryToFinₙ : {m n : ℕ} → Vec Bit m → Maybe (Fin n)
tryToFinₙ {_} {n} ps = tryℕ n (toℕₙ ps) where
tryℕ : (k : ℕ) → ℕ → Maybe (Fin k)
tryℕ zero _ = nothing
tryℕ (suc _) zero = just zero
tryℕ (suc m) (suc n) = map suc (tryℕ m n)
ℕ-mod2 : ℕ → Bit
ℕ-mod2 zero = b0
ℕ-mod2 (suc zero) = b1
ℕ-mod2 (suc (suc n)) = ℕ-mod2 n
instance
Bit-num : Number Bit
Bit-num .Number.Constraint n = constrain n where
constrain : ℕ → Set
constrain zero = ⊤
constrain (suc zero) = ⊤
constrain _ = ⊥
Bit-num .Number.fromNat n ⦃ p ⦄ = fromNat n p where
fromNat : (m : ℕ) → (Number.Constraint Bit-num) m → Bit
fromNat zero _ = b0
fromNat (suc zero) _ = b1
fromNat (suc (suc _)) ()
instance
Bits-num : {m : ℕ} → Number (Vec Bit m)
Bits-num {m} .Number.Constraint n = ℕ≤ (suc n) (ℕ^ 2 m)
Bits-num {m} .Number.fromNat n = fromNat m n where
fromNat : (m : ℕ) → ℕ → Vec Bit m
fromNat zero _ = []
fromNat (suc m) n = ℕ-mod2 n ∷ fromNat m ⌊ n /2⌋
instance
Bits-neg : {m : ℕ} → Negative (Vec Bit (suc m))
Bits-neg {m} .Negative.Constraint n = ℕ≤ n (ℕ^ 2 m)
Bits-neg {m} .Negative.fromNeg n = number where
iterateBits : (m : ℕ) → ℕ → Vec Bit m × Bit
iterateBits zero _ = [] , b0 where
iterateBits (suc m) n = newVec , newSign where
subRes : Vec Bit m × Bit
subRes = iterateBits m ⌊ n /2⌋
newVec : Vec Bit (suc m)
newVec = ℕ-mod2 n ∷ proj₁ subRes
newSign : Bit
newSign = ℕ-mod2 n ∨ proj₂ subRes
iteration : Vec Bit (suc m) × Bit
iteration = iterateBits (suc m) n
preNumber : Vec Bit (suc m)
preNumber = proj₁ iteration
signBit : Bit
signBit = proj₂ iteration
number : Vec Bit (suc m)
number = (head preNumber ∨ signBit) ∷ tail preNumber
_==_ : {n : ℕ} → Vec Bit n → Vec Bit n → Bool
[] == [] = true
p ∷ ps == q ∷ qs = Bool-∧ (toBool (p ↔ q)) (ps == qs)
| 29.041494
| 80
| 0.567367
|
29c090a6a134659ca3bdf7c886571a4b76fcb8b8
| 28
|
agda
|
Agda
|
test/interaction/Issue2447b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue2447b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue2447b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
import Issue2447.Type-error
| 14
| 27
| 0.857143
|
4a2e9785b8f0222171d8e00c5fdcaad00dfbf05a
| 1,586
|
agda
|
Agda
|
agda-stdlib-0.9/README/Nat.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | 1
|
2016-10-20T15:52:05.000Z
|
2016-10-20T15:52:05.000Z
|
agda-stdlib-0.9/README/Nat.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/README/Nat.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some examples showing where the natural numbers and some related
-- operations and properties are defined, and how they can be used
------------------------------------------------------------------------
module README.Nat where
-- The natural numbers and various arithmetic operations are defined
-- in Data.Nat.
open import Data.Nat
ex₁ : ℕ
ex₁ = 1 + 3
-- Propositional equality and some related properties can be found
-- in Relation.Binary.PropositionalEquality.
open import Relation.Binary.PropositionalEquality
ex₂ : 3 + 5 ≡ 2 * 4
ex₂ = refl
-- Data.Nat.Properties contains a number of properties about natural
-- numbers. Algebra defines what a commutative semiring is, among
-- other things.
open import Algebra
import Data.Nat.Properties as Nat
private
module CS = CommutativeSemiring Nat.commutativeSemiring
ex₃ : ∀ m n → m * n ≡ n * m
ex₃ m n = CS.*-comm m n
-- The module ≡-Reasoning in Relation.Binary.PropositionalEquality
-- provides some combinators for equational reasoning.
open ≡-Reasoning
open import Data.Product
ex₄ : ∀ m n → m * (n + 0) ≡ n * m
ex₄ m n = begin
m * (n + 0) ≡⟨ cong (_*_ m) (proj₂ CS.+-identity n) ⟩
m * n ≡⟨ CS.*-comm m n ⟩
n * m ∎
-- The module SemiringSolver in Data.Nat.Properties contains a solver
-- for natural number equalities involving variables, constants, _+_
-- and _*_.
open Nat.SemiringSolver
ex₅ : ∀ m n → m * (n + 0) ≡ n * m
ex₅ = solve 2 (λ m n → m :* (n :+ con 0) := n :* m) refl
| 27.344828
| 72
| 0.629256
|
203a6d2bb61fc92a9aabf8b2979038f2351bfff7
| 1,461
|
agda
|
Agda
|
test/Succeed/TelescopingLet.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/TelescopingLet.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/TelescopingLet.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module TelescopingLet where
module Star where
★ : Set₁
★ = Set
★₁ : Set₂
★₁ = Set₁
module MEndo (open Star) (A : ★) where
Endo : ★
Endo = A → A
module Batch1 where
f : (let ★ = Set) (A : ★) → A → A
f A x = x
g : (let ★ = Set
Endo = λ A → A → A) (A : ★) → Endo A
g = f
h : (open Star) (A : ★) → A → A
h = g
module N (open Star) (A : ★) (open MEndo A) (f : Endo) where
B : ★
B = A
f' : Endo
f' = f
-- module N can be desugared as follows:
module _ where
open Star
module _ (A : ★) where
open MEndo A
module N' (f : Endo) where
B : ★
B = A
f' : Endo
f' = f
-- Here are instantiations of N and its desugaring:
f'1 = f'
where
postulate A : Set
f : A → A
open N A f
f'2 = f'
where
postulate A : Set
f : A → A
open N' A f
data ⊥ : Set where
module Batch2 where
f = λ (let ★ = Set) (A : ★) (x : A) → x
g = λ (open Star) (A : ★) (x : A) → x
h0 = let open Star in
λ (A : ★) →
let module MA = MEndo A in
let open MA in
λ (f : Endo) →
f
h1 = let open Star in
λ (A : ★) →
let open MEndo A in
λ (f : Endo) →
f
h = λ (open Star) (A : ★) (open MEndo A) (f : Endo) → f
module Batch3 where
e1 : (let ★ = Set) → ★
e1 = ⊥
e2 = λ (let ★ = Set) → ★
e3 = λ (open Star) → ★
-- "λ (open M es) → e" is an edge case which behaves like "let open M es in e"
| 16.602273
| 80
| 0.465435
|
1045dd402bb102577a0fae564818b46b50e49630
| 5,201
|
agda
|
Agda
|
core/lib/types/TLevel.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
core/lib/types/TLevel.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
core/lib/types/TLevel.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Base
open import lib.PathGroupoid
open import lib.types.Empty
open import lib.types.Nat
module lib.types.TLevel where
⟨_⟩₋₁ : ℕ → ℕ₋₂
⟨ n ⟩₋₁ = S ⟨ n ⟩₋₂
⟨_⟩ : ℕ → ℕ₋₂
⟨ n ⟩ = from-nat n
infixl 80 _+2+_
_+2+_ : ℕ₋₂ → ℕ₋₂ → ℕ₋₂
⟨-2⟩ +2+ n = n
S m +2+ n = S (m +2+ n)
+2+-unit-r : (m : ℕ₋₂) → m +2+ ⟨-2⟩ == m
+2+-unit-r ⟨-2⟩ = idp
+2+-unit-r (S m) = ap S (+2+-unit-r m)
+2+-βr : (m n : ℕ₋₂) → m +2+ (S n) == S (m +2+ n)
+2+-βr ⟨-2⟩ n = idp
+2+-βr (S m) n = ap S (+2+-βr m n)
+2+-comm : (m n : ℕ₋₂) → m +2+ n == n +2+ m
+2+-comm m ⟨-2⟩ = +2+-unit-r m
+2+-comm m (S n) = +2+-βr m n ∙ ap S (+2+-comm m n)
+2+0 : (n : ℕ₋₂) → n +2+ 0 == S (S n)
+2+0 n = +2+-comm n 0
{- Inequalities -}
infix 40 _<T_
infix 40 _≤T_
data _<T_ : ℕ₋₂ → ℕ₋₂ → Type₀ where
ltS : {m : ℕ₋₂} → m <T (S m)
ltSR : {m n : ℕ₋₂} → m <T n → m <T (S n)
_≤T_ : ℕ₋₂ → ℕ₋₂ → Type₀
m ≤T n = Coprod (m == n) (m <T n)
-2<T : (m : ℕ₋₂) → ⟨-2⟩ <T S m
-2<T ⟨-2⟩ = ltS
-2<T (S m) = ltSR (-2<T m)
-2≤T : (m : ℕ₋₂) → ⟨-2⟩ ≤T m
-2≤T ⟨-2⟩ = inl idp
-2≤T (S m) = inr (-2<T m)
<T-trans : {m n k : ℕ₋₂} → m <T n → n <T k → m <T k
<T-trans lt₁ ltS = ltSR lt₁
<T-trans lt₁ (ltSR lt₂) = ltSR (<T-trans lt₁ lt₂)
≤T-refl : {m : ℕ₋₂} → m ≤T m
≤T-refl = inl idp
≤T-trans : {m n k : ℕ₋₂} → m ≤T n → n ≤T k → m ≤T k
≤T-trans {k = k} (inl p₁) lte₂ = transport (λ t → t ≤T k) (! p₁) lte₂
≤T-trans {m = m} lte₁ (inl p₂) = transport (λ t → m ≤T t) p₂ lte₁
≤T-trans (inr lt₁) (inr lt₂) = inr (<T-trans lt₁ lt₂)
<T-ap-S : {m n : ℕ₋₂} → m <T n → S m <T S n
<T-ap-S ltS = ltS
<T-ap-S (ltSR lt) = ltSR (<T-ap-S lt)
≤T-ap-S : {m n : ℕ₋₂} → m ≤T n → S m ≤T S n
≤T-ap-S (inl p) = inl (ap S p)
≤T-ap-S (inr lt) = inr (<T-ap-S lt)
<T-cancel-S : {m n : ℕ₋₂} → S m <T S n → m <T n
<T-cancel-S ltS = ltS
<T-cancel-S (ltSR lt) = <T-trans ltS lt
<T-+2+-l : {m n : ℕ₋₂} (k : ℕ₋₂) → m <T n → (k +2+ m) <T (k +2+ n)
<T-+2+-l ⟨-2⟩ lt = lt
<T-+2+-l (S k) lt = <T-ap-S (<T-+2+-l k lt)
≤T-+2+-l : {m n : ℕ₋₂} (k : ℕ₋₂) → m ≤T n → (k +2+ m) ≤T (k +2+ n)
≤T-+2+-l k (inl p) = inl (ap (λ t → k +2+ t) p)
≤T-+2+-l k (inr lt) = inr (<T-+2+-l k lt)
<T-+2+-r : {m n : ℕ₋₂} (k : ℕ₋₂) → m <T n → (m +2+ k) <T (n +2+ k)
<T-+2+-r k ltS = ltS
<T-+2+-r k (ltSR lt) = ltSR (<T-+2+-r k lt)
≤T-+2+-r : {m n : ℕ₋₂} (k : ℕ₋₂) → m ≤T n → (m +2+ k) ≤T (n +2+ k)
≤T-+2+-r k (inl p) = inl (ap (λ t → t +2+ k) p)
≤T-+2+-r k (inr lt) = inr (<T-+2+-r k lt)
private
T-get-S : ℕ₋₂ → ℕ₋₂
T-get-S ⟨-2⟩ = ⟨ 42 ⟩
T-get-S (S n) = n
T-S≠⟨-2⟩-type : ℕ₋₂ → Type₀
T-S≠⟨-2⟩-type ⟨-2⟩ = Empty
T-S≠⟨-2⟩-type (S n) = Unit
T-S≠⟨-2⟩ : (n : ℕ₋₂) → S n ≠ ⟨-2⟩
T-S≠⟨-2⟩ n p = transport T-S≠⟨-2⟩-type p unit
T-S≠ : (n : ℕ₋₂) → S n ≠ n
T-S≠ ⟨-2⟩ p = T-S≠⟨-2⟩ ⟨-2⟩ p
T-S≠ (S n) p = T-S≠ n (ap T-get-S p)
T-S+2+≠ : (n k : ℕ₋₂) → S (k +2+ n) ≠ n
T-S+2+≠ ⟨-2⟩ k p = T-S≠⟨-2⟩ (k +2+ ⟨-2⟩) p
T-S+2+≠ (S n) k p = T-S+2+≠ n k (ap T-get-S (ap S (! (+2+-βr k n)) ∙ p))
<T-witness : {m n : ℕ₋₂} → (m <T n) → Σ ℕ₋₂ (λ k → S k +2+ m == n)
<T-witness ltS = (⟨-2⟩ , idp)
<T-witness (ltSR lt) = let w' = <T-witness lt in (S (fst w') , ap S (snd w'))
≤T-witness : {m n : ℕ₋₂} → (m ≤T n) → Σ ℕ₋₂ (λ k → k +2+ m == n)
≤T-witness (inl p) = (⟨-2⟩ , p)
≤T-witness (inr lt) = let w' = <T-witness lt in (S (fst w') , snd w')
<T-to-≤T : {m n : ℕ₋₂} → m <T S n → m ≤T n
<T-to-≤T ltS = inl idp
<T-to-≤T (ltSR lt) = inr lt
<T-to-≠ : {m n : ℕ₋₂} → (m <T n) → m ≠ n
<T-to-≠ {m} {n} lt p = T-S+2+≠ m (fst w) (snd w ∙ ! p)
where w = <T-witness lt
=-to-≮T : {m n : ℕ₋₂} → (m == n) → ¬ (m <T n)
=-to-≮T p lt = <T-to-≠ lt p
<T-to-≯T : {m n : ℕ₋₂} → (m <T n) → ¬ (n <T m)
<T-to-≯T lt gt = =-to-≮T idp (<T-trans lt gt)
<T-to-≱T : {m n : ℕ₋₂} → (m <T n) → ¬ (n ≤T m)
<T-to-≱T lt (inl p) = <T-to-≠ lt (! p)
<T-to-≱T lt (inr gt) = <T-to-≯T lt gt
{-
-2-monotone-< : {m n : ℕ} → (m < n) → (m -2 <T n -2)
-2-monotone-< ltS = ltS
-2-monotone-< (ltSR lt) = ltSR (-2-monotone-< lt)
-2-monotone-≤ : {m n : ℕ} → (m ≤ n) → (m -2 ≤T n -2)
-2-monotone-≤ (inl p) = inl (ap _-2 p)
-2-monotone-≤ (inr lt) = inr (-2-monotone-< lt)
-}
⟨⟩-monotone-< : {m n : ℕ} → (m < n) → (⟨ m ⟩ <T ⟨ n ⟩)
⟨⟩-monotone-< ltS = ltS
⟨⟩-monotone-< (ltSR lt) = ltSR (⟨⟩-monotone-< lt)
⟨⟩-monotone-≤ : {m n : ℕ} → (m ≤ n) → (⟨ m ⟩ ≤T ⟨ n ⟩)
⟨⟩-monotone-≤ (inl p) = inl (ap ⟨_⟩ p)
⟨⟩-monotone-≤ (inr lt) = inr (⟨⟩-monotone-< lt)
minT : ℕ₋₂ → ℕ₋₂ → ℕ₋₂
minT ⟨-2⟩ n = ⟨-2⟩
minT (S m) ⟨-2⟩ = ⟨-2⟩
minT (S m) (S n) = S (minT m n)
minT≤l : (m n : ℕ₋₂) → minT m n ≤T m
minT≤l ⟨-2⟩ n = inl idp
minT≤l (S m) ⟨-2⟩ = -2≤T (S m)
minT≤l (S m) (S n) = ≤T-ap-S (minT≤l m n)
minT≤r : (m n : ℕ₋₂) → minT m n ≤T n
minT≤r ⟨-2⟩ n = -2≤T n
minT≤r (S m) ⟨-2⟩ = inl idp
minT≤r (S m) (S n) = ≤T-ap-S (minT≤r m n)
minT-out : (m n : ℕ₋₂) → Coprod (minT m n == m) (minT m n == n)
minT-out ⟨-2⟩ _ = inl idp
minT-out (S _) ⟨-2⟩ = inr idp
minT-out (S m) (S n) with minT-out m n
minT-out (S m) (S n) | inl p = inl (ap S p)
minT-out (S m) (S n) | inr q = inr (ap S q)
minT-out-l : {m n : ℕ₋₂} → (m ≤T n) → minT m n == m
minT-out-l {m} {n} lte with minT-out m n
minT-out-l lte | inl eqm = eqm
minT-out-l (inl p) | inr eqn = eqn ∙ ! p
minT-out-l {m} {n} (inr lt) | inr eq =
⊥-rec (<T-to-≱T (transport (λ k → m <T k) (! eq) lt) (minT≤l m n))
| 27.812834
| 77
| 0.44453
|
cbda26e3165bb31bc38a08ca87d23206509b5683
| 746
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/Simple.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/Simple.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/Simple.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Instantiates the ring solver with two copies of the same ring with
-- decidable equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra.Solver.Ring.AlmostCommutativeRing
open import Relation.Binary
open import Relation.Binary.Consequences using (dec⟶weaklyDec)
module Algebra.Solver.Ring.Simple
{r₁ r₂} (R : AlmostCommutativeRing r₁ r₂)
(_≟_ : Decidable (AlmostCommutativeRing._≈_ R))
where
open AlmostCommutativeRing R
import Algebra.Solver.Ring as RS
open RS rawRing R (-raw-almostCommutative⟶ R) (dec⟶weaklyDec _≟_) public
| 33.909091
| 72
| 0.596515
|
0e7b043b31a0fbc508be481c404df50f09496096
| 23,966
|
agda
|
Agda
|
huffman/huffman.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
huffman/huffman.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
huffman/huffman.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
module huffman where
open import lib
open import huffman-types public
----------------------------------------------------------------------------------
-- Run-rewriting rules
----------------------------------------------------------------------------------
data gratr2-nt : Set where
_ws-plus-10 : gratr2-nt
_ws : gratr2-nt
_words : gratr2-nt
_word : gratr2-nt
_start : gratr2-nt
_posinfo : gratr2-nt
_ows-star-11 : gratr2-nt
_ows : gratr2-nt
_digit : gratr2-nt
_codes : gratr2-nt
_code : gratr2-nt
_cmd : gratr2-nt
_character-range-2 : gratr2-nt
_character-range-1 : gratr2-nt
_character-bar-7 : gratr2-nt
_character-bar-6 : gratr2-nt
_character-bar-5 : gratr2-nt
_character-bar-4 : gratr2-nt
_character-bar-3 : gratr2-nt
_character : gratr2-nt
_bvlit : gratr2-nt
_aws-bar-9 : gratr2-nt
_aws-bar-8 : gratr2-nt
_aws : gratr2-nt
gratr2-nt-eq : gratr2-nt → gratr2-nt → 𝔹
gratr2-nt-eq _ws-plus-10 _ws-plus-10 = tt
gratr2-nt-eq _ws _ws = tt
gratr2-nt-eq _words _words = tt
gratr2-nt-eq _word _word = tt
gratr2-nt-eq _start _start = tt
gratr2-nt-eq _posinfo _posinfo = tt
gratr2-nt-eq _ows-star-11 _ows-star-11 = tt
gratr2-nt-eq _ows _ows = tt
gratr2-nt-eq _digit _digit = tt
gratr2-nt-eq _codes _codes = tt
gratr2-nt-eq _code _code = tt
gratr2-nt-eq _cmd _cmd = tt
gratr2-nt-eq _character-range-2 _character-range-2 = tt
gratr2-nt-eq _character-range-1 _character-range-1 = tt
gratr2-nt-eq _character-bar-7 _character-bar-7 = tt
gratr2-nt-eq _character-bar-6 _character-bar-6 = tt
gratr2-nt-eq _character-bar-5 _character-bar-5 = tt
gratr2-nt-eq _character-bar-4 _character-bar-4 = tt
gratr2-nt-eq _character-bar-3 _character-bar-3 = tt
gratr2-nt-eq _character _character = tt
gratr2-nt-eq _bvlit _bvlit = tt
gratr2-nt-eq _aws-bar-9 _aws-bar-9 = tt
gratr2-nt-eq _aws-bar-8 _aws-bar-8 = tt
gratr2-nt-eq _aws _aws = tt
gratr2-nt-eq _ _ = ff
open import rtn gratr2-nt
huffman-start : gratr2-nt → 𝕃 gratr2-rule
huffman-start _ws-plus-10 = (just "P71" , nothing , just _ws-plus-10 , inj₁ _aws :: inj₁ _ws-plus-10 :: []) :: (just "P70" , nothing , just _ws-plus-10 , inj₁ _aws :: []) :: []
huffman-start _ws = (just "P72" , nothing , just _ws , inj₁ _ws-plus-10 :: []) :: []
huffman-start _words = (just "WordsStart" , nothing , just _words , inj₁ _word :: []) :: (just "WordsNext" , nothing , just _words , inj₁ _word :: inj₁ _ws :: inj₁ _words :: []) :: []
huffman-start _word = (just "P1" , nothing , just _word , inj₁ _character :: inj₁ _word :: []) :: (just "P0" , nothing , just _word , inj₁ _character :: []) :: []
huffman-start _start = (just "File" , nothing , just _start , inj₁ _ows :: inj₁ _cmd :: inj₁ _ows :: []) :: []
huffman-start _posinfo = (just "Posinfo" , nothing , just _posinfo , []) :: []
huffman-start _ows-star-11 = (just "P74" , nothing , just _ows-star-11 , inj₁ _aws :: inj₁ _ows-star-11 :: []) :: (just "P73" , nothing , just _ows-star-11 , []) :: []
huffman-start _ows = (just "P75" , nothing , just _ows , inj₁ _ows-star-11 :: []) :: []
huffman-start _digit = (just "Zero" , nothing , just _digit , inj₂ '0' :: []) :: (just "One" , nothing , just _digit , inj₂ '1' :: []) :: []
huffman-start _codes = (just "CodesStart" , nothing , just _codes , inj₁ _code :: []) :: (just "CodesNext" , nothing , just _codes , inj₁ _code :: inj₁ _ws :: inj₁ _codes :: []) :: []
huffman-start _code = (just "Code" , nothing , just _code , inj₁ _word :: inj₁ _ws :: inj₂ '<' :: inj₂ '-' :: inj₁ _ws :: inj₁ _bvlit :: []) :: []
huffman-start _cmd = (just "Encode" , nothing , just _cmd , inj₁ _words :: []) :: (just "Decode" , nothing , just _cmd , inj₂ '!' :: inj₁ _ws :: inj₁ _codes :: inj₁ _ws :: inj₁ _bvlit :: []) :: []
huffman-start _character-range-2 = (just "P53" , nothing , just _character-range-2 , inj₂ 'Z' :: []) :: (just "P52" , nothing , just _character-range-2 , inj₂ 'Y' :: []) :: (just "P51" , nothing , just _character-range-2 , inj₂ 'X' :: []) :: (just "P50" , nothing , just _character-range-2 , inj₂ 'W' :: []) :: (just "P49" , nothing , just _character-range-2 , inj₂ 'V' :: []) :: (just "P48" , nothing , just _character-range-2 , inj₂ 'U' :: []) :: (just "P47" , nothing , just _character-range-2 , inj₂ 'T' :: []) :: (just "P46" , nothing , just _character-range-2 , inj₂ 'S' :: []) :: (just "P45" , nothing , just _character-range-2 , inj₂ 'R' :: []) :: (just "P44" , nothing , just _character-range-2 , inj₂ 'Q' :: []) :: (just "P43" , nothing , just _character-range-2 , inj₂ 'P' :: []) :: (just "P42" , nothing , just _character-range-2 , inj₂ 'O' :: []) :: (just "P41" , nothing , just _character-range-2 , inj₂ 'N' :: []) :: (just "P40" , nothing , just _character-range-2 , inj₂ 'M' :: []) :: (just "P39" , nothing , just _character-range-2 , inj₂ 'L' :: []) :: (just "P38" , nothing , just _character-range-2 , inj₂ 'K' :: []) :: (just "P37" , nothing , just _character-range-2 , inj₂ 'J' :: []) :: (just "P36" , nothing , just _character-range-2 , inj₂ 'I' :: []) :: (just "P35" , nothing , just _character-range-2 , inj₂ 'H' :: []) :: (just "P34" , nothing , just _character-range-2 , inj₂ 'G' :: []) :: (just "P33" , nothing , just _character-range-2 , inj₂ 'F' :: []) :: (just "P32" , nothing , just _character-range-2 , inj₂ 'E' :: []) :: (just "P31" , nothing , just _character-range-2 , inj₂ 'D' :: []) :: (just "P30" , nothing , just _character-range-2 , inj₂ 'C' :: []) :: (just "P29" , nothing , just _character-range-2 , inj₂ 'B' :: []) :: (just "P28" , nothing , just _character-range-2 , inj₂ 'A' :: []) :: []
huffman-start _character-range-1 = (just "P9" , nothing , just _character-range-1 , inj₂ 'h' :: []) :: (just "P8" , nothing , just _character-range-1 , inj₂ 'g' :: []) :: (just "P7" , nothing , just _character-range-1 , inj₂ 'f' :: []) :: (just "P6" , nothing , just _character-range-1 , inj₂ 'e' :: []) :: (just "P5" , nothing , just _character-range-1 , inj₂ 'd' :: []) :: (just "P4" , nothing , just _character-range-1 , inj₂ 'c' :: []) :: (just "P3" , nothing , just _character-range-1 , inj₂ 'b' :: []) :: (just "P27" , nothing , just _character-range-1 , inj₂ 'z' :: []) :: (just "P26" , nothing , just _character-range-1 , inj₂ 'y' :: []) :: (just "P25" , nothing , just _character-range-1 , inj₂ 'x' :: []) :: (just "P24" , nothing , just _character-range-1 , inj₂ 'w' :: []) :: (just "P23" , nothing , just _character-range-1 , inj₂ 'v' :: []) :: (just "P22" , nothing , just _character-range-1 , inj₂ 'u' :: []) :: (just "P21" , nothing , just _character-range-1 , inj₂ 't' :: []) :: (just "P20" , nothing , just _character-range-1 , inj₂ 's' :: []) :: (just "P2" , nothing , just _character-range-1 , inj₂ 'a' :: []) :: (just "P19" , nothing , just _character-range-1 , inj₂ 'r' :: []) :: (just "P18" , nothing , just _character-range-1 , inj₂ 'q' :: []) :: (just "P17" , nothing , just _character-range-1 , inj₂ 'p' :: []) :: (just "P16" , nothing , just _character-range-1 , inj₂ 'o' :: []) :: (just "P15" , nothing , just _character-range-1 , inj₂ 'n' :: []) :: (just "P14" , nothing , just _character-range-1 , inj₂ 'm' :: []) :: (just "P13" , nothing , just _character-range-1 , inj₂ 'l' :: []) :: (just "P12" , nothing , just _character-range-1 , inj₂ 'k' :: []) :: (just "P11" , nothing , just _character-range-1 , inj₂ 'j' :: []) :: (just "P10" , nothing , just _character-range-1 , inj₂ 'i' :: []) :: []
huffman-start _character-bar-7 = (just "P63" , nothing , just _character-bar-7 , inj₁ _character-bar-6 :: []) :: (just "P62" , nothing , just _character-bar-7 , inj₁ _character-range-1 :: []) :: []
huffman-start _character-bar-6 = (just "P61" , nothing , just _character-bar-6 , inj₁ _character-bar-5 :: []) :: (just "P60" , nothing , just _character-bar-6 , inj₁ _character-range-2 :: []) :: []
huffman-start _character-bar-5 = (just "P59" , nothing , just _character-bar-5 , inj₁ _character-bar-4 :: []) :: (just "P58" , nothing , just _character-bar-5 , inj₂ '(' :: []) :: []
huffman-start _character-bar-4 = (just "P57" , nothing , just _character-bar-4 , inj₁ _character-bar-3 :: []) :: (just "P56" , nothing , just _character-bar-4 , inj₂ ')' :: []) :: []
huffman-start _character-bar-3 = (just "P55" , nothing , just _character-bar-3 , inj₂ '.' :: []) :: (just "P54" , nothing , just _character-bar-3 , inj₂ ',' :: []) :: []
huffman-start _character = (just "P64" , nothing , just _character , inj₁ _character-bar-7 :: []) :: []
huffman-start _bvlit = (just "BvlitStart" , nothing , just _bvlit , inj₁ _digit :: []) :: (just "BvlitCons" , nothing , just _bvlit , inj₁ _digit :: inj₁ _bvlit :: []) :: []
huffman-start _aws-bar-9 = (just "P68" , nothing , just _aws-bar-9 , inj₁ _aws-bar-8 :: []) :: (just "P67" , nothing , just _aws-bar-9 , inj₂ '\n' :: []) :: []
huffman-start _aws-bar-8 = (just "P66" , nothing , just _aws-bar-8 , inj₂ ' ' :: []) :: (just "P65" , nothing , just _aws-bar-8 , inj₂ '\t' :: []) :: []
huffman-start _aws = (just "P69" , nothing , just _aws , inj₁ _aws-bar-9 :: []) :: []
huffman-return : maybe gratr2-nt → 𝕃 gratr2-rule
huffman-return _ = []
huffman-rtn : gratr2-rtn
huffman-rtn = record { start = _start ; _eq_ = gratr2-nt-eq ; gratr2-start = huffman-start ; gratr2-return = huffman-return }
open import run ptr
open noderiv
------------------------------------------
-- Length-decreasing rules
------------------------------------------
len-dec-rewrite : Run → maybe (Run × ℕ)
len-dec-rewrite {- BvlitCons-} ((Id "BvlitCons") :: (ParseTree (parsed-digit x0)) :: _::_(ParseTree (parsed-bvlit x1)) rest) = just (ParseTree (parsed-bvlit (norm-bvlit (BvlitCons x0 x1))) ::' rest , 3)
len-dec-rewrite {- BvlitStart-} ((Id "BvlitStart") :: _::_(ParseTree (parsed-digit x0)) rest) = just (ParseTree (parsed-bvlit (norm-bvlit (BvlitStart x0))) ::' rest , 2)
len-dec-rewrite {- Code-} ((Id "Code") :: (ParseTree (parsed-word x0)) :: (ParseTree parsed-ws) :: (InputChar '<') :: (InputChar '-') :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-bvlit x1)) rest) = just (ParseTree (parsed-code (norm-code (Code x0 x1))) ::' rest , 7)
len-dec-rewrite {- CodesNext-} ((Id "CodesNext") :: (ParseTree (parsed-code x0)) :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-codes x1)) rest) = just (ParseTree (parsed-codes (norm-codes (CodesNext x0 x1))) ::' rest , 4)
len-dec-rewrite {- CodesStart-} ((Id "CodesStart") :: _::_(ParseTree (parsed-code x0)) rest) = just (ParseTree (parsed-codes (norm-codes (CodesStart x0))) ::' rest , 2)
len-dec-rewrite {- Decode-} ((Id "Decode") :: (InputChar '!') :: (ParseTree parsed-ws) :: (ParseTree (parsed-codes x0)) :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-bvlit x1)) rest) = just (ParseTree (parsed-cmd (norm-cmd (Decode x0 x1))) ::' rest , 6)
len-dec-rewrite {- Encode-} ((Id "Encode") :: _::_(ParseTree (parsed-words x0)) rest) = just (ParseTree (parsed-cmd (norm-cmd (Encode x0))) ::' rest , 2)
len-dec-rewrite {- File-} ((Id "File") :: (ParseTree parsed-ows) :: (ParseTree (parsed-cmd x0)) :: _::_(ParseTree parsed-ows) rest) = just (ParseTree (parsed-start (norm-start (File x0))) ::' rest , 4)
len-dec-rewrite {- One-} ((Id "One") :: _::_(InputChar '1') rest) = just (ParseTree (parsed-digit (norm-digit One)) ::' rest , 2)
len-dec-rewrite {- P0-} ((Id "P0") :: _::_(ParseTree (parsed-character x0)) rest) = just (ParseTree (parsed-word (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P1-} ((Id "P1") :: (ParseTree (parsed-character x0)) :: _::_(ParseTree (parsed-word x1)) rest) = just (ParseTree (parsed-word (string-append 1 x0 x1)) ::' rest , 3)
len-dec-rewrite {- P10-} ((Id "P10") :: _::_(InputChar 'i') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'i'))) ::' rest , 2)
len-dec-rewrite {- P11-} ((Id "P11") :: _::_(InputChar 'j') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'j'))) ::' rest , 2)
len-dec-rewrite {- P12-} ((Id "P12") :: _::_(InputChar 'k') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'k'))) ::' rest , 2)
len-dec-rewrite {- P13-} ((Id "P13") :: _::_(InputChar 'l') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'l'))) ::' rest , 2)
len-dec-rewrite {- P14-} ((Id "P14") :: _::_(InputChar 'm') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'm'))) ::' rest , 2)
len-dec-rewrite {- P15-} ((Id "P15") :: _::_(InputChar 'n') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'n'))) ::' rest , 2)
len-dec-rewrite {- P16-} ((Id "P16") :: _::_(InputChar 'o') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'o'))) ::' rest , 2)
len-dec-rewrite {- P17-} ((Id "P17") :: _::_(InputChar 'p') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'p'))) ::' rest , 2)
len-dec-rewrite {- P18-} ((Id "P18") :: _::_(InputChar 'q') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'q'))) ::' rest , 2)
len-dec-rewrite {- P19-} ((Id "P19") :: _::_(InputChar 'r') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'r'))) ::' rest , 2)
len-dec-rewrite {- P2-} ((Id "P2") :: _::_(InputChar 'a') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'a'))) ::' rest , 2)
len-dec-rewrite {- P20-} ((Id "P20") :: _::_(InputChar 's') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 's'))) ::' rest , 2)
len-dec-rewrite {- P21-} ((Id "P21") :: _::_(InputChar 't') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 't'))) ::' rest , 2)
len-dec-rewrite {- P22-} ((Id "P22") :: _::_(InputChar 'u') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'u'))) ::' rest , 2)
len-dec-rewrite {- P23-} ((Id "P23") :: _::_(InputChar 'v') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'v'))) ::' rest , 2)
len-dec-rewrite {- P24-} ((Id "P24") :: _::_(InputChar 'w') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'w'))) ::' rest , 2)
len-dec-rewrite {- P25-} ((Id "P25") :: _::_(InputChar 'x') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'x'))) ::' rest , 2)
len-dec-rewrite {- P26-} ((Id "P26") :: _::_(InputChar 'y') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'y'))) ::' rest , 2)
len-dec-rewrite {- P27-} ((Id "P27") :: _::_(InputChar 'z') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'z'))) ::' rest , 2)
len-dec-rewrite {- P28-} ((Id "P28") :: _::_(InputChar 'A') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'A'))) ::' rest , 2)
len-dec-rewrite {- P29-} ((Id "P29") :: _::_(InputChar 'B') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'B'))) ::' rest , 2)
len-dec-rewrite {- P3-} ((Id "P3") :: _::_(InputChar 'b') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'b'))) ::' rest , 2)
len-dec-rewrite {- P30-} ((Id "P30") :: _::_(InputChar 'C') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'C'))) ::' rest , 2)
len-dec-rewrite {- P31-} ((Id "P31") :: _::_(InputChar 'D') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'D'))) ::' rest , 2)
len-dec-rewrite {- P32-} ((Id "P32") :: _::_(InputChar 'E') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'E'))) ::' rest , 2)
len-dec-rewrite {- P33-} ((Id "P33") :: _::_(InputChar 'F') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'F'))) ::' rest , 2)
len-dec-rewrite {- P34-} ((Id "P34") :: _::_(InputChar 'G') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'G'))) ::' rest , 2)
len-dec-rewrite {- P35-} ((Id "P35") :: _::_(InputChar 'H') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'H'))) ::' rest , 2)
len-dec-rewrite {- P36-} ((Id "P36") :: _::_(InputChar 'I') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'I'))) ::' rest , 2)
len-dec-rewrite {- P37-} ((Id "P37") :: _::_(InputChar 'J') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'J'))) ::' rest , 2)
len-dec-rewrite {- P38-} ((Id "P38") :: _::_(InputChar 'K') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'K'))) ::' rest , 2)
len-dec-rewrite {- P39-} ((Id "P39") :: _::_(InputChar 'L') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'L'))) ::' rest , 2)
len-dec-rewrite {- P4-} ((Id "P4") :: _::_(InputChar 'c') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'c'))) ::' rest , 2)
len-dec-rewrite {- P40-} ((Id "P40") :: _::_(InputChar 'M') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'M'))) ::' rest , 2)
len-dec-rewrite {- P41-} ((Id "P41") :: _::_(InputChar 'N') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'N'))) ::' rest , 2)
len-dec-rewrite {- P42-} ((Id "P42") :: _::_(InputChar 'O') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'O'))) ::' rest , 2)
len-dec-rewrite {- P43-} ((Id "P43") :: _::_(InputChar 'P') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'P'))) ::' rest , 2)
len-dec-rewrite {- P44-} ((Id "P44") :: _::_(InputChar 'Q') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'Q'))) ::' rest , 2)
len-dec-rewrite {- P45-} ((Id "P45") :: _::_(InputChar 'R') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'R'))) ::' rest , 2)
len-dec-rewrite {- P46-} ((Id "P46") :: _::_(InputChar 'S') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'S'))) ::' rest , 2)
len-dec-rewrite {- P47-} ((Id "P47") :: _::_(InputChar 'T') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'T'))) ::' rest , 2)
len-dec-rewrite {- P48-} ((Id "P48") :: _::_(InputChar 'U') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'U'))) ::' rest , 2)
len-dec-rewrite {- P49-} ((Id "P49") :: _::_(InputChar 'V') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'V'))) ::' rest , 2)
len-dec-rewrite {- P5-} ((Id "P5") :: _::_(InputChar 'd') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'd'))) ::' rest , 2)
len-dec-rewrite {- P50-} ((Id "P50") :: _::_(InputChar 'W') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'W'))) ::' rest , 2)
len-dec-rewrite {- P51-} ((Id "P51") :: _::_(InputChar 'X') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'X'))) ::' rest , 2)
len-dec-rewrite {- P52-} ((Id "P52") :: _::_(InputChar 'Y') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'Y'))) ::' rest , 2)
len-dec-rewrite {- P53-} ((Id "P53") :: _::_(InputChar 'Z') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'Z'))) ::' rest , 2)
len-dec-rewrite {- P54-} ((Id "P54") :: _::_(InputChar ',') rest) = just (ParseTree (parsed-character-bar-3 (string-append 0 (char-to-string ','))) ::' rest , 2)
len-dec-rewrite {- P55-} ((Id "P55") :: _::_(InputChar '.') rest) = just (ParseTree (parsed-character-bar-3 (string-append 0 (char-to-string '.'))) ::' rest , 2)
len-dec-rewrite {- P56-} ((Id "P56") :: _::_(InputChar ')') rest) = just (ParseTree (parsed-character-bar-4 (string-append 0 (char-to-string ')'))) ::' rest , 2)
len-dec-rewrite {- P57-} ((Id "P57") :: _::_(ParseTree (parsed-character-bar-3 x0)) rest) = just (ParseTree (parsed-character-bar-4 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P58-} ((Id "P58") :: _::_(InputChar '(') rest) = just (ParseTree (parsed-character-bar-5 (string-append 0 (char-to-string '('))) ::' rest , 2)
len-dec-rewrite {- P59-} ((Id "P59") :: _::_(ParseTree (parsed-character-bar-4 x0)) rest) = just (ParseTree (parsed-character-bar-5 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P6-} ((Id "P6") :: _::_(InputChar 'e') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'e'))) ::' rest , 2)
len-dec-rewrite {- P60-} ((Id "P60") :: _::_(ParseTree (parsed-character-range-2 x0)) rest) = just (ParseTree (parsed-character-bar-6 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P61-} ((Id "P61") :: _::_(ParseTree (parsed-character-bar-5 x0)) rest) = just (ParseTree (parsed-character-bar-6 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P62-} ((Id "P62") :: _::_(ParseTree (parsed-character-range-1 x0)) rest) = just (ParseTree (parsed-character-bar-7 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P63-} ((Id "P63") :: _::_(ParseTree (parsed-character-bar-6 x0)) rest) = just (ParseTree (parsed-character-bar-7 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P64-} ((Id "P64") :: _::_(ParseTree (parsed-character-bar-7 x0)) rest) = just (ParseTree (parsed-character (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P65-} ((Id "P65") :: _::_(InputChar '\t') rest) = just (ParseTree parsed-aws-bar-8 ::' rest , 2)
len-dec-rewrite {- P66-} ((Id "P66") :: _::_(InputChar ' ') rest) = just (ParseTree parsed-aws-bar-8 ::' rest , 2)
len-dec-rewrite {- P67-} ((Id "P67") :: _::_(InputChar '\n') rest) = just (ParseTree parsed-aws-bar-9 ::' rest , 2)
len-dec-rewrite {- P68-} ((Id "P68") :: _::_(ParseTree parsed-aws-bar-8) rest) = just (ParseTree parsed-aws-bar-9 ::' rest , 2)
len-dec-rewrite {- P69-} ((Id "P69") :: _::_(ParseTree parsed-aws-bar-9) rest) = just (ParseTree parsed-aws ::' rest , 2)
len-dec-rewrite {- P7-} ((Id "P7") :: _::_(InputChar 'f') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'f'))) ::' rest , 2)
len-dec-rewrite {- P70-} ((Id "P70") :: _::_(ParseTree parsed-aws) rest) = just (ParseTree parsed-ws-plus-10 ::' rest , 2)
len-dec-rewrite {- P71-} ((Id "P71") :: (ParseTree parsed-aws) :: _::_(ParseTree parsed-ws-plus-10) rest) = just (ParseTree parsed-ws-plus-10 ::' rest , 3)
len-dec-rewrite {- P72-} ((Id "P72") :: _::_(ParseTree parsed-ws-plus-10) rest) = just (ParseTree parsed-ws ::' rest , 2)
len-dec-rewrite {- P74-} ((Id "P74") :: (ParseTree parsed-aws) :: _::_(ParseTree parsed-ows-star-11) rest) = just (ParseTree parsed-ows-star-11 ::' rest , 3)
len-dec-rewrite {- P75-} ((Id "P75") :: _::_(ParseTree parsed-ows-star-11) rest) = just (ParseTree parsed-ows ::' rest , 2)
len-dec-rewrite {- P8-} ((Id "P8") :: _::_(InputChar 'g') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'g'))) ::' rest , 2)
len-dec-rewrite {- P9-} ((Id "P9") :: _::_(InputChar 'h') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'h'))) ::' rest , 2)
len-dec-rewrite {- WordsNext-} ((Id "WordsNext") :: (ParseTree (parsed-word x0)) :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-words x1)) rest) = just (ParseTree (parsed-words (norm-words (WordsNext x0 x1))) ::' rest , 4)
len-dec-rewrite {- WordsStart-} ((Id "WordsStart") :: _::_(ParseTree (parsed-word x0)) rest) = just (ParseTree (parsed-words (norm-words (WordsStart x0))) ::' rest , 2)
len-dec-rewrite {- Zero-} ((Id "Zero") :: _::_(InputChar '0') rest) = just (ParseTree (parsed-digit (norm-digit Zero)) ::' rest , 2)
len-dec-rewrite {- P73-} (_::_(Id "P73") rest) = just (ParseTree parsed-ows-star-11 ::' rest , 1)
len-dec-rewrite {- Posinfo-} (_::_(Posinfo n) rest) = just (ParseTree (parsed-posinfo (ℕ-to-string n)) ::' rest , 1)
len-dec-rewrite x = nothing
rrs : rewriteRules
rrs = record { len-dec-rewrite = len-dec-rewrite }
| 118.643564
| 1,831
| 0.615163
|
319fab7307486b5f7d0c380e712db663f2813f0f
| 11,070
|
agda
|
Agda
|
Cubical/Algebra/Group/MorphismProperties.agda
|
MatthiasHu/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Algebra/Group/MorphismProperties.agda
|
snu-development/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/MorphismProperties.agda
|
snu-development/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | null | null | null |
{-
This file contains:
- Elementary properties of homomorphisms
- H-level results for the properties of morphisms
- Special homomorphisms and operations (id, composition, inversion)
- Conversion functions between different notions of group morphisms
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.MorphismProperties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Functions.Embedding
open import Cubical.Data.Sigma
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.DirProd
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphisms
open import Cubical.HITs.PropositionalTruncation renaming (map to pMap)
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
F G H : Group ℓ
open Iso
open GroupStr
open IsGroupHom
open BijectionIso
-- Elementary properties of homomorphisms
module _ {A : Type ℓ} {B : Type ℓ'} (G : GroupStr A) (f : A → B) (H : GroupStr B)
(pres : (x y : A) → f (G ._·_ x y) ≡ H ._·_ (f x) (f y))
where
private
module G = GroupStr G
module H = GroupStr H
-- ϕ(1g) ≡ 1g
hom1g : f G.1g ≡ H.1g
hom1g =
f G.1g ≡⟨ sym (H.rid _) ⟩
f G.1g H.· H.1g ≡⟨ (λ i → f G.1g H.· H.invr (f G.1g) (~ i)) ⟩
f G.1g H.· (f G.1g H.· H.inv (f G.1g)) ≡⟨ H.assoc _ _ _ ⟩
(f G.1g H.· f G.1g) H.· H.inv (f G.1g) ≡⟨ sym (cong (λ x → x H.· _)
(sym (cong f (G.lid _)) ∙ pres G.1g G.1g)) ⟩
f G.1g H.· H.inv (f G.1g) ≡⟨ H.invr _ ⟩
H.1g ∎
-- ϕ(- x) = - ϕ(x)
homInv : ∀ g → f (G.inv g) ≡ H.inv (f g)
homInv g =
f (G.inv g) ≡⟨ sym (H.rid _) ⟩
f (G.inv g) H.· H.1g ≡⟨ cong (_ H.·_) (sym (H.invr _)) ⟩
f (G.inv g) H.· (f g H.· H.inv (f g)) ≡⟨ H.assoc _ _ _ ⟩
(f (G.inv g) H.· f g) H.· H.inv (f g) ≡⟨ cong (H._· _) (sym (pres _ g) ∙∙ cong f (G.invl g) ∙∙ hom1g) ⟩
H.1g H.· H.inv (f g) ≡⟨ H.lid _ ⟩
H.inv (f g) ∎
module _ {A : Type ℓ} {B : Type ℓ'} {G : GroupStr A} {f : A → B} {H : GroupStr B}
(pres : (x y : A) → f (G ._·_ x y) ≡ H ._·_ (f x) (f y))
where
makeIsGroupHom : IsGroupHom G f H
makeIsGroupHom .pres· = pres
makeIsGroupHom .pres1 = hom1g G f H pres
makeIsGroupHom .presinv = homInv G f H pres
-- H-level results
isPropIsGroupHom : (G : Group ℓ) (H : Group ℓ') {f : ⟨ G ⟩ → ⟨ H ⟩}
→ isProp (IsGroupHom (G .snd) f (H .snd))
isPropIsGroupHom G H =
isOfHLevelRetractFromIso 1 IsGroupHomIsoΣ
(isProp×
(isPropΠ2 λ _ _ → GroupStr.is-set (snd H) _ _)
(isProp×
(GroupStr.is-set (snd H) _ _)
(isPropΠ λ _ → GroupStr.is-set (snd H) _ _)))
isSetGroupHom : isSet (GroupHom G H)
isSetGroupHom {G = G} {H = H} =
isSetΣ (isSetΠ λ _ → is-set (snd H)) λ _ → isProp→isSet (isPropIsGroupHom G H)
isPropIsInIm : (f : GroupHom G H) (x : ⟨ H ⟩) → isProp (isInIm f x)
isPropIsInIm f x = squash
isSetIm : (f : GroupHom G H) → isSet (Im f)
isSetIm {H = H} f = isSetΣ (is-set (snd H)) λ x → isProp→isSet (isPropIsInIm f x)
isPropIsInKer : (f : GroupHom G H) (x : ⟨ G ⟩) → isProp (isInKer f x)
isPropIsInKer {H = H} f x = is-set (snd H) _ _
isSetKer : (f : GroupHom G H) → isSet (Ker f)
isSetKer {G = G} f = isSetΣ (is-set (snd G)) λ x → isProp→isSet (isPropIsInKer f x)
isPropIsSurjective : (f : GroupHom G H) → isProp (isSurjective f)
isPropIsSurjective f = isPropΠ (λ x → isPropIsInIm f x)
isPropIsInjective : (f : GroupHom G H) → isProp (isInjective f)
isPropIsInjective {G = G} _ = isPropΠ2 (λ _ _ → is-set (snd G) _ _)
isPropIsMono : (f : GroupHom G H) → isProp (isMono f)
isPropIsMono {G = G} f = isPropImplicitΠ2 λ _ _ → isPropΠ (λ _ → is-set (snd G) _ _)
-- Logically equivalent versions of isInjective
isMono→isInjective : (f : GroupHom G H) → isMono f → isInjective f
isMono→isInjective f h x p = h (p ∙ sym (f .snd .pres1))
isInjective→isMono : (f : GroupHom G H) → isInjective f → isMono f
isInjective→isMono {G = G} {H = H} f h {x = x} {y = y} p =
x ≡⟨ sym (G.rid _) ⟩
x G.· G.1g ≡⟨ cong (x G.·_) (sym (G.invl _)) ⟩
x G.· (G.inv y G.· y) ≡⟨ G.assoc _ _ _ ⟩
(x G.· G.inv y) G.· y ≡⟨ cong (G._· y) idHelper ⟩
G.1g G.· y ≡⟨ G.lid _ ⟩
y ∎
where
module G = GroupStr (snd G)
module H = GroupStr (snd H)
idHelper : x G.· G.inv y ≡ G.1g
idHelper = h _ (f .snd .pres· _ _ ∙
cong (λ a → f .fst x H.· a) (f .snd .presinv y) ∙
cong (H._· H.inv (f .fst y)) p ∙
H.invr _)
-- TODO: maybe it would be better to take this as the definition of isInjective?
isInjective→isContrKer : (f : GroupHom G H) → isInjective f → isContr (Ker f)
fst (isInjective→isContrKer {G = G} f hf) = 1g (snd G) , f .snd .pres1
snd (isInjective→isContrKer {G = G} f hf) k =
Σ≡Prop (isPropIsInKer f) (sym (isInjective→isMono f hf (k .snd ∙ sym (f .snd .pres1))))
isContrKer→isInjective : (f : GroupHom G H) → isContr (Ker f) → isInjective f
isContrKer→isInjective {G = G} f ((a , b) , c) x y = cong fst (sym (c (x , y)) ∙ rem)
where
rem : (a , b) ≡ (1g (snd G) , pres1 (snd f))
rem = c (1g (snd G) , pres1 (snd f))
-- Special homomorphisms and operations (id, composition...)
idGroupHom : GroupHom G G
idGroupHom .fst x = x
idGroupHom .snd = makeIsGroupHom λ _ _ → refl
isGroupHomComp : (f : GroupHom F G) → (g : GroupHom G H) → IsGroupHom (F .snd) (fst g ∘ fst f) (H .snd)
isGroupHomComp f g = makeIsGroupHom λ _ _ → cong (fst g) (f .snd .pres· _ _) ∙ (g .snd .pres· _ _)
compGroupHom : GroupHom F G → GroupHom G H → GroupHom F H
fst (compGroupHom f g) = fst g ∘ fst f
snd (compGroupHom f g) = isGroupHomComp f g
GroupHomDirProd : {A : Group ℓ} {B : Group ℓ'} {C : Group ℓ''} {D : Group ℓ'''}
→ GroupHom A C → GroupHom B D → GroupHom (DirProd A B) (DirProd C D)
fst (GroupHomDirProd mf1 mf2) = map-× (fst mf1) (fst mf2)
snd (GroupHomDirProd mf1 mf2) = makeIsGroupHom λ _ _ → ≡-× (mf1 .snd .pres· _ _) (mf2 .snd .pres· _ _)
GroupHom≡ : {f g : GroupHom G H} → (fst f ≡ fst g) → f ≡ g
fst (GroupHom≡ p i) = p i
snd (GroupHom≡ {G = G} {H = H} {f = f} {g = g} p i) = p-hom i
where
p-hom : PathP (λ i → IsGroupHom (G .snd) (p i) (H .snd)) (f .snd) (g .snd)
p-hom = toPathP (isPropIsGroupHom G H _ _)
-- The composition of surjective maps is surjective
compSurjective : ∀ {ℓ ℓ' ℓ''} {G : Group ℓ} {H : Group ℓ'} {L : Group ℓ''}
→ (G→H : GroupHom G H) (H→L : GroupHom H L)
→ isSurjective G→H → isSurjective H→L
→ isSurjective (compGroupHom G→H H→L)
compSurjective G→H H→L surj1 surj2 l =
rec squash
(λ {(h , p)
→ pMap (λ {(g , q) → g , (cong (fst H→L) q ∙ p)})
(surj1 h)})
(surj2 l)
-- GroupEquiv identity, composition and inversion
idGroupEquiv : GroupEquiv G G
fst (idGroupEquiv {G = G}) = idEquiv ⟨ G ⟩
snd idGroupEquiv = makeIsGroupHom λ _ _ → refl
compGroupEquiv : GroupEquiv F G → GroupEquiv G H → GroupEquiv F H
fst (compGroupEquiv f g) = compEquiv (fst f) (fst g)
snd (compGroupEquiv f g) = isGroupHomComp (_ , f .snd) (_ , g .snd)
isGroupHomInv : (f : GroupEquiv G H) → IsGroupHom (H .snd) (invEq (fst f)) (G .snd)
isGroupHomInv {G = G} {H = H} f = makeIsGroupHom λ h h' →
isInj-f _ _
(f' (g (h ⋆² h')) ≡⟨ secEq (fst f) _ ⟩
(h ⋆² h') ≡⟨ sym (cong₂ _⋆²_ (secEq (fst f) h) (secEq (fst f) h')) ⟩
(f' (g h) ⋆² f' (g h')) ≡⟨ sym (pres· (snd f) _ _) ⟩
f' (g h ⋆¹ g h') ∎)
where
f' = fst (fst f)
_⋆¹_ = _·_ (snd G)
_⋆²_ = _·_ (snd H)
g = invEq (fst f)
isInj-f : (x y : ⟨ G ⟩) → f' x ≡ f' y → x ≡ y
isInj-f x y = invEq (_ , isEquiv→isEmbedding (snd (fst f)) x y)
invGroupEquiv : GroupEquiv G H → GroupEquiv H G
fst (invGroupEquiv f) = invEquiv (fst f)
snd (invGroupEquiv f) = isGroupHomInv f
GroupEquivDirProd : {A : Group ℓ} {B : Group ℓ'} {C : Group ℓ''} {D : Group ℓ'''}
→ GroupEquiv A C → GroupEquiv B D
→ GroupEquiv (DirProd A B) (DirProd C D)
fst (GroupEquivDirProd eq1 eq2) = ≃-× (fst eq1) (fst eq2)
snd (GroupEquivDirProd eq1 eq2) = GroupHomDirProd (_ , eq1 .snd) (_ , eq2 .snd) .snd
GroupEquiv≡ : {f g : GroupEquiv G H} → fst f ≡ fst g → f ≡ g
fst (GroupEquiv≡ p i) = p i
snd (GroupEquiv≡ {G = G} {H = H} {f} {g} p i) = p-hom i
where
p-hom : PathP (λ i → IsGroupHom (G .snd) (p i .fst) (H .snd)) (snd f) (snd g)
p-hom = toPathP (isPropIsGroupHom G H _ _)
-- GroupIso identity, composition and inversion
idGroupIso : GroupIso G G
fst idGroupIso = idIso
snd idGroupIso = makeIsGroupHom λ _ _ → refl
compGroupIso : GroupIso G H → GroupIso H F → GroupIso G F
fst (compGroupIso iso1 iso2) = compIso (fst iso1) (fst iso2)
snd (compGroupIso iso1 iso2) = isGroupHomComp (_ , snd iso1) (_ , snd iso2)
invGroupIso : GroupIso G H → GroupIso H G
fst (invGroupIso iso1) = invIso (fst iso1)
snd (invGroupIso iso1) = isGroupHomInv (isoToEquiv (fst iso1) , snd iso1)
GroupIsoDirProd : {G : Group ℓ} {H : Group ℓ'} {A : Group ℓ''} {B : Group ℓ'''}
→ GroupIso G H → GroupIso A B → GroupIso (DirProd G A) (DirProd H B)
fun (fst (GroupIsoDirProd iso1 iso2)) prod =
fun (fst iso1) (fst prod) , fun (fst iso2) (snd prod)
inv (fst (GroupIsoDirProd iso1 iso2)) prod =
inv (fst iso1) (fst prod) , inv (fst iso2) (snd prod)
rightInv (fst (GroupIsoDirProd iso1 iso2)) a =
ΣPathP (rightInv (fst iso1) (fst a) , (rightInv (fst iso2) (snd a)))
leftInv (fst (GroupIsoDirProd iso1 iso2)) a =
ΣPathP (leftInv (fst iso1) (fst a) , (leftInv (fst iso2) (snd a)))
snd (GroupIsoDirProd iso1 iso2) = makeIsGroupHom λ a b →
ΣPathP (pres· (snd iso1) (fst a) (fst b) , pres· (snd iso2) (snd a) (snd b))
-- Conversion functions between different notions of group morphisms
GroupIso→GroupEquiv : GroupIso G H → GroupEquiv G H
fst (GroupIso→GroupEquiv i) = isoToEquiv (fst i)
snd (GroupIso→GroupEquiv i) = snd i
GroupEquiv→GroupIso : GroupEquiv G H → GroupIso G H
fst (GroupEquiv→GroupIso e) = equivToIso (fst e)
snd (GroupEquiv→GroupIso e) = snd e
-- TODO: prove the converse
BijectionIso→GroupIso : BijectionIso G H → GroupIso G H
BijectionIso→GroupIso {G = G} {H = H} i = grIso
where
f = fst (fun i)
helper : (b : _) → isProp (Σ[ a ∈ ⟨ G ⟩ ] f a ≡ b)
helper _ (a , ha) (b , hb) =
Σ≡Prop (λ _ → is-set (snd H) _ _)
(isInjective→isMono (fun i) (inj i) (ha ∙ sym hb) )
grIso : GroupIso G H
fun (fst grIso) = f
inv (fst grIso) b = rec (helper b) (λ a → a) (surj i b) .fst
rightInv (fst grIso) b = rec (helper b) (λ a → a) (surj i b) .snd
leftInv (fst grIso) b j = rec (helper (f b)) (λ a → a)
(isPropPropTrunc (surj i (f b)) ∣ b , refl ∣ j) .fst
snd grIso = snd (fun i)
BijectionIsoToGroupEquiv : BijectionIso G H → GroupEquiv G H
BijectionIsoToGroupEquiv i = GroupIso→GroupEquiv (BijectionIso→GroupIso i)
| 38.172414
| 108
| 0.596206
|
4116818782299afad087fcbf76c80000ee323824
| 1,088
|
agda
|
Agda
|
test/Succeed/Issue1652-3.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1652-3.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1652-3.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{- Example by Guillaume Brunerie, 17-11-2015 -}
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Primitive
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
idr : ∀ {i} {A : Set i} {a : A} → a ↦ a
{-# BUILTIN REWRITE _↦_ #-}
infixr 3 _==_
data _==_ {i} {A : Set i} (a : A) : A → Set i where
idp : a == a
PathOver : ∀ {i j} {A : Set i} (B : A → Set j)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set j
PathOver B idp u v = (u == v)
syntax PathOver B p u v =
u == v [ B ↓ p ]
postulate
PathOver-rewr : ∀ {i j} {A : Set i} {B : Set j} {x y : A} (p : x == y) (u v : B) →
(PathOver (λ _ → B) p u v) ↦ (u == v)
{-# REWRITE PathOver-rewr #-}
ap : ∀ {i j} {A : Set i} {B : A → Set j} (f : (a : A) → B a) {x y : A}
→ (p : x == y) → PathOver B p (f x) (f y)
ap f idp = idp
module _ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B) where
∘ap : {x y : A} (p : x == y) →
ap g (ap f p) ↦ ap (λ x → g (f x)) p
∘ap idp = idr
{-# REWRITE ∘ap #-}
ap∘ : {x y : A} (p : x == y) →
ap (λ x → g (f x)) p ↦ ap g (ap f p)
ap∘ p = idr
| 24.727273
| 84
| 0.438419
|
185ff58fbf22fac284855fa63fd4c78bb1676ae6
| 2,292
|
agda
|
Agda
|
agda/SNat/Order/Properties.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/SNat/Order/Properties.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/SNat/Order/Properties.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --sized-types #-}
module SNat.Order.Properties where
open import Data.Sum renaming (_⊎_ to _∨_)
open import Relation.Binary.PropositionalEquality
open import Size
open import SNat
open import SNat.Order
tot≤ : {ι ι' : Size} → (m : SNat {ι}) → (n : SNat {ι'}) → m ≤ n ∨ n ≤ m
tot≤ zero n = inj₁ (z≤n n)
tot≤ m zero = inj₂ (z≤n m)
tot≤ (succ m) (succ n)
with tot≤ m n
...| inj₁ m≤n = inj₁ (s≤s m≤n)
...| inj₂ n≤m = inj₂ (s≤s n≤m)
refl≤ : {n : SNat} → n ≤ n
refl≤ {n}
with tot≤ n n
... | inj₁ n≤n = n≤n
... | inj₂ n≤n = n≤n
trans≤ : {ι ι' ι'' : Size}{n : SNat {ι}}{n' : SNat {ι'}}{n'' : SNat {ι''}} → n ≤ n' → n' ≤ n'' → n ≤ n''
trans≤ {n'' = n''} (z≤n n') _ = z≤n n''
trans≤ (s≤s n≤n') (s≤s n'≤n'') = s≤s (trans≤ n≤n' n'≤n'')
refl≅ : {n : SNat} → n ≅ n
refl≅ {zero} = z≅z
refl≅ {succ _} = s≅s refl≅
trans≅ : {ι ι' ι'' : Size}{n : SNat {ι}}{n' : SNat {ι'}}{n'' : SNat {ι''}} → n ≅ n' → n' ≅ n'' → n ≅ n''
trans≅ z≅z z≅z = z≅z
trans≅ (s≅s n≅n') (s≅s n'≅n'') = s≅s (trans≅ n≅n' n'≅n'')
lemma-z≤′n : {ι ι' : Size}(n : SNat {ι}) → zero {ι'} ≤′ n
lemma-z≤′n zero = ≤′-eq z≅z
lemma-z≤′n (succ n) = ≤′-step (lemma-z≤′n n)
lemma-s≤′s : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤′ n → succ m ≤′ succ n
lemma-s≤′s (≤′-eq m≅n) = ≤′-eq (s≅s m≅n)
lemma-s≤′s (≤′-step m≤′n) = ≤′-step (lemma-s≤′s m≤′n)
lemma-≤-≤′ : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤ n → m ≤′ n
lemma-≤-≤′ (z≤n n) = lemma-z≤′n n
lemma-≤-≤′ (s≤s m≤n) = lemma-s≤′s (lemma-≤-≤′ m≤n)
lemma-≅-≤ : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≅ n → m ≤ n
lemma-≅-≤ z≅z = z≤n zero
lemma-≅-≤ (s≅s m≅n) = s≤s (lemma-≅-≤ m≅n)
lemma-≡-≤′ : {a b c : SNat} → b ≡ a → a ≤′ c → b ≤′ c
lemma-≡-≤′ b≡a a≤′c rewrite b≡a = a≤′c
lemma-n≤sn : {ι : Size}(n : SNat {ι}) → n ≤ succ n
lemma-n≤sn zero = z≤n (succ zero)
lemma-n≤sn (succ n) = s≤s (lemma-n≤sn n)
lemma-≤′-≤ : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤′ n → m ≤ n
lemma-≤′-≤ (≤′-eq m≅n) = lemma-≅-≤ m≅n
lemma-≤′-≤ (≤′-step {n = n} m≤′n) = trans≤ (lemma-≤′-≤ m≤′n) (lemma-n≤sn n)
refl≤′ : {n : SNat} → n ≤′ n
refl≤′ = lemma-≤-≤′ refl≤
trans≤′ : {ι ι' ι'' : Size}{n : SNat {ι}}{n' : SNat {ι'}}{n'' : SNat {ι''}} → n ≤′ n' → n' ≤′ n'' → n ≤′ n''
trans≤′ n≤′n' n'≤′n'' = lemma-≤-≤′ (trans≤ (lemma-≤′-≤ n≤′n') (lemma-≤′-≤ n'≤′n''))
| 33.705882
| 109
| 0.455497
|
4d71244f16761b1c4f425a2a119b29c1aa9362ba
| 1,209
|
agda
|
Agda
|
cohomology/SphereProduct.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
cohomology/SphereProduct.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
cohomology/SphereProduct.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.SuspProduct
open import homotopy.SuspSmash
open import homotopy.JoinSusp
open import cohomology.Theory
module cohomology.SphereProduct {i} (CT : CohomologyTheory i) where
open CohomologyTheory CT
open import cohomology.Wedge CT
module _ (n : ℤ) (m : ℕ) (X : Ptd i) where
private
space-path : ⊙Susp (⊙Sphere {i} m ⊙× X)
== ⊙Sphere {i} (S m) ⊙∨ (⊙Susp X ⊙∨ ⊙Susp^ (S m) X)
space-path =
SuspProduct.⊙path (⊙Sphere m) X
∙ ap (λ Z → ⊙Sphere (S m) ⊙∨ (⊙Susp X ⊙∨ Z))
(SuspSmash.⊙path (⊙Sphere m) X
∙ ⊙join-sphere X m)
C-Sphere× : C n (⊙Sphere {i} m ⊙× X)
== C n (⊙Sphere m) ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X))
C-Sphere× =
! (group-ua (C-Susp n (⊙Sphere m ⊙× X)))
∙ ap (C (succ n)) space-path
∙ CWedge.path (succ n) (⊙Sphere (S m)) (⊙Susp X ⊙∨ ⊙Susp^ (S m) X)
∙ ap (λ H → C (succ n) (⊙Sphere (S m)) ×ᴳ H)
(CWedge.path (succ n) (⊙Susp X) (⊙Susp^ (S m) X)
∙ ap2 _×ᴳ_ (group-ua (C-Susp n X))
(group-ua (C-Susp n (⊙Susp^ m X))))
∙ ap (λ H → H ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X)))
(group-ua (C-Susp n (⊙Sphere m)))
| 31.815789
| 70
| 0.527709
|
591105af40ae94e331e3e8a703eb0ec97c3f6187
| 4,326
|
agda
|
Agda
|
agda-stdlib/src/Reflection/Definition.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Reflection/Definition.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Reflection/Definition.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Definitions used in the reflection machinery
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Reflection.Definition where
open import Data.List.Base using (map)
import Data.List.Properties as Listₚ
import Data.Nat.Properties as ℕₚ
import Data.Nat.Show as NatShow
open import Data.Product using (_×_; <_,_>; uncurry)
open import Data.String as String using (String; _<+>_; intersperse; braces)
open import Function using (_∘′_)
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Binary using (DecidableEquality)
open import Relation.Binary.PropositionalEquality
import Reflection.Argument as Arg
import Reflection.Name as Name
import Reflection.Term as Term
------------------------------------------------------------------------
-- Re-exporting type publically
open import Agda.Builtin.Reflection public
using ( Definition
; function
; data-type
; axiom
)
renaming ( record-type to record′
; data-cons to constructor′
; prim-fun to primitive′ )
------------------------------------------------------------------------
-- Decidable equality
function-injective : ∀ {cs cs′} → function cs ≡ function cs′ → cs ≡ cs′
function-injective refl = refl
data-type-injective₁ : ∀ {pars pars′ cs cs′} → data-type pars cs ≡ data-type pars′ cs′ → pars ≡ pars′
data-type-injective₁ refl = refl
data-type-injective₂ : ∀ {pars pars′ cs cs′} → data-type pars cs ≡ data-type pars′ cs′ → cs ≡ cs′
data-type-injective₂ refl = refl
data-type-injective : ∀ {pars pars′ cs cs′} → data-type pars cs ≡ data-type pars′ cs′ → pars ≡ pars′ × cs ≡ cs′
data-type-injective = < data-type-injective₁ , data-type-injective₂ >
record′-injective₁ : ∀ {c c′ fs fs′} → record′ c fs ≡ record′ c′ fs′ → c ≡ c′
record′-injective₁ refl = refl
record′-injective₂ : ∀ {c c′ fs fs′} → record′ c fs ≡ record′ c′ fs′ → fs ≡ fs′
record′-injective₂ refl = refl
record′-injective : ∀ {c c′ fs fs′} → record′ c fs ≡ record′ c′ fs′ → c ≡ c′ × fs ≡ fs′
record′-injective = < record′-injective₁ , record′-injective₂ >
constructor′-injective : ∀ {c c′} → constructor′ c ≡ constructor′ c′ → c ≡ c′
constructor′-injective refl = refl
_≟_ : DecidableEquality Definition
function cs ≟ function cs′ =
Dec.map′ (cong function) function-injective (cs Term.≟-Clauses cs′)
data-type pars cs ≟ data-type pars′ cs′ =
Dec.map′ (uncurry (cong₂ data-type)) data-type-injective
(pars ℕₚ.≟ pars′ ×-dec Listₚ.≡-dec Name._≟_ cs cs′)
record′ c fs ≟ record′ c′ fs′ =
Dec.map′ (uncurry (cong₂ record′)) record′-injective
(c Name.≟ c′ ×-dec Listₚ.≡-dec (Arg.≡-dec Name._≟_) fs fs′)
constructor′ d ≟ constructor′ d′ =
Dec.map′ (cong constructor′) constructor′-injective (d Name.≟ d′)
axiom ≟ axiom = yes refl
primitive′ ≟ primitive′ = yes refl
-- antidiagonal
function cs ≟ data-type pars cs₁ = no (λ ())
function cs ≟ record′ c fs = no (λ ())
function cs ≟ constructor′ d = no (λ ())
function cs ≟ axiom = no (λ ())
function cs ≟ primitive′ = no (λ ())
data-type pars cs ≟ function cs₁ = no (λ ())
data-type pars cs ≟ record′ c fs = no (λ ())
data-type pars cs ≟ constructor′ d = no (λ ())
data-type pars cs ≟ axiom = no (λ ())
data-type pars cs ≟ primitive′ = no (λ ())
record′ c fs ≟ function cs = no (λ ())
record′ c fs ≟ data-type pars cs = no (λ ())
record′ c fs ≟ constructor′ d = no (λ ())
record′ c fs ≟ axiom = no (λ ())
record′ c fs ≟ primitive′ = no (λ ())
constructor′ d ≟ function cs = no (λ ())
constructor′ d ≟ data-type pars cs = no (λ ())
constructor′ d ≟ record′ c fs = no (λ ())
constructor′ d ≟ axiom = no (λ ())
constructor′ d ≟ primitive′ = no (λ ())
axiom ≟ function cs = no (λ ())
axiom ≟ data-type pars cs = no (λ ())
axiom ≟ record′ c fs = no (λ ())
axiom ≟ constructor′ d = no (λ ())
axiom ≟ primitive′ = no (λ ())
primitive′ ≟ function cs = no (λ ())
primitive′ ≟ data-type pars cs = no (λ ())
primitive′ ≟ record′ c fs = no (λ ())
primitive′ ≟ constructor′ d = no (λ ())
primitive′ ≟ axiom = no (λ ())
| 38.283186
| 111
| 0.594313
|
0b6618e346c7bec43d51edbc4a7adfd510d21142
| 463
|
agda
|
Agda
|
examples/outdated-and-incorrect/univ/Example.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/univ/Example.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/univ/Example.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Example where
open import Base
open import Nat
open import univ
-- Application
_#_ : {A : S}{F : El A -> S}{pF : Map _==_ _=S_ F} ->
El (pi A F pF) -> (x : El A) -> El (F x)
el < f , pf > # x = f x
-- Projection
π₀ : {A : S}{F : El A -> S}{pF : Map _==_ _=S_ F} ->
El (sigma A F pF) -> El A
π₀ (el < x , Fx >) = x
π₁ : {A : S}{F : El A -> S}{pF : Map _==_ _=S_ F} ->
(p : El (sigma A F pF)) -> El (F (π₀ p))
π₁ (el < x , Fx >) = Fx
| 19.291667
| 53
| 0.460043
|
064149d637e90631ddec02d70989c01173305b56
| 1,816
|
agda
|
Agda
|
Thesis/SIRelBigStep/SemEquiv.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 10
|
2015-03-04T06:09:20.000Z
|
2019-07-19T07:06:59.000Z
|
Thesis/SIRelBigStep/SemEquiv.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 6
|
2015-07-01T18:09:31.000Z
|
2017-05-04T13:53:59.000Z
|
Thesis/SIRelBigStep/SemEquiv.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 1
|
2016-02-18T12:26:44.000Z
|
2016-02-18T12:26:44.000Z
|
module Thesis.SIRelBigStep.SemEquiv where
open import Data.Nat
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Thesis.SIRelBigStep.Syntax public
open import Thesis.SIRelBigStep.OpSem
open import Thesis.SIRelBigStep.DenSem
⟦_⟧Val : ∀ {τ} → Val τ → ⟦ τ ⟧Type
⟦_⟧Env : ∀ {Γ} → ⟦ Γ ⟧Context → Den.⟦ Γ ⟧Context
⟦ ∅ ⟧Env = ∅
⟦ v • ρ ⟧Env = ⟦ v ⟧Val • ⟦ ρ ⟧Env
⟦ closure t ρ ⟧Val = λ v → (⟦ t ⟧Term) (v • ⟦ ρ ⟧Env)
⟦ natV n ⟧Val = n
⟦ pairV v1 v2 ⟧Val = ⟦ v1 ⟧Val , ⟦ v2 ⟧Val
↦-sound : ∀ {Γ τ} ρ (x : Var Γ τ) →
Den.⟦ x ⟧Var ⟦ ρ ⟧Env ≡ ⟦ ⟦ x ⟧Var ρ ⟧Val
↦-sound (px • ρ) this = refl
↦-sound (px • ρ) (that x) = ↦-sound ρ x
eval-const-sound : ∀ {τ} (c : Const τ) → ⟦ c ⟧Const ≡ ⟦ eval-const c ⟧Val
eval-const-sound (lit n) = refl
eval-primitive-sound : ∀ {σ τ} (p : Primitive (σ ⇒ τ)) v → ⟦ p ⟧Primitive ⟦ v ⟧Val ≡ ⟦ eval-primitive p v ⟧Val
eval-primitive-sound succ (natV n) = refl
eval-primitive-sound add (pairV (natV n1) (natV n2)) = refl
eval-sound : ∀ {Γ τ} ρ (sv : SVal Γ τ) →
⟦ sv ⟧SVal ⟦ ρ ⟧Env ≡ ⟦ eval sv ρ ⟧Val
eval-sound ρ (var x) = ↦-sound ρ x
eval-sound ρ (abs t) = refl
eval-sound ρ (cons sv1 sv2) rewrite eval-sound ρ sv1 | eval-sound ρ sv2 = refl
eval-sound ρ (const c) = eval-const-sound c
-- Check it's fine to use i 0 in the derivations for app
↓-sv-1-step : ∀ {Γ τ ρ v} {n} {sv : SVal Γ τ} →
ρ ⊢ val sv ↓[ i' n ] v →
n ≡ 0
↓-sv-1-step (val sv) = refl
↓-sound : ∀ {Γ τ ρ v hasIdx} {n : Idx hasIdx} {t : Term Γ τ} →
ρ ⊢ t ↓[ n ] v →
⟦ t ⟧Term ⟦ ρ ⟧Env ≡ ⟦ v ⟧Val
↓-sound (val sv) = eval-sound _ sv
↓-sound (app _ _ ↓₁ ↓₂ ↓′) rewrite ↓-sound ↓₁ | ↓-sound ↓₂ | ↓-sound ↓′ = refl
↓-sound (lett n1 n2 vsv s t ↓ ↓₁) rewrite ↓-sound ↓ | ↓-sound ↓₁ = refl
↓-sound {ρ = ρ} (primapp p sv) rewrite eval-sound ρ sv = eval-primitive-sound p (eval sv ρ)
| 34.264151
| 110
| 0.59196
|
50b6d0335bf8f5a4728a84025943c1217162cabc
| 79
|
agda
|
Agda
|
test/interaction/HighlightSafePostulate.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/HighlightSafePostulate.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/HighlightSafePostulate.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2020-03-21, issue #4456
{-# OPTIONS --safe #-}
postulate A : Set
| 13.166667
| 35
| 0.607595
|
4144d0fb36f20e537c2318e4c3bbd5f3287f4fe8
| 534
|
agda
|
Agda
|
Computability/Prelude.agda
|
jesyspa/computability-in-agda
|
1b5cf338eb0adb90c1897383e05251ddd954efff
|
[
"MIT"
] | 2
|
2020-09-19T15:51:22.000Z
|
2021-04-30T11:15:51.000Z
|
Computability/Prelude.agda
|
jesyspa/computability-in-agda
|
1b5cf338eb0adb90c1897383e05251ddd954efff
|
[
"MIT"
] | null | null | null |
Computability/Prelude.agda
|
jesyspa/computability-in-agda
|
1b5cf338eb0adb90c1897383e05251ddd954efff
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
module Computability.Prelude where
open import Data.Bool public using (Bool; false; true)
open import Data.Empty public using (⊥; ⊥-elim)
open import Data.Nat public using (ℕ; zero; suc; _+_; _*_)
open import Data.Product public using (Σ; Σ-syntax; _×_; _,_; proj₁; proj₂)
open import Data.Sum public using (_⊎_)
open import Data.Unit public using (⊤)
open import Relation.Binary.PropositionalEquality public using (_≡_; refl)
open import Level public using (Level) renaming (zero to lzero; suc to lsuc)
| 41.076923
| 76
| 0.741573
|
397e18f416d53b4cd22aff028f81f8e1735ffddc
| 18,507
|
agda
|
Agda
|
Univalence/Obsolete/PiLevel0.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/Obsolete/PiLevel0.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/Obsolete/PiLevel0.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
module PiLevel0 where
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; cong₂; module ≡-Reasoning)
-- using (_≡_; refl; sym; trans; cong₂; proof-irrelevance; module ≡-Reasoning)
--open import Data.Nat.Properties.Simple
-- using (+-right-identity; +-suc; +-assoc; +-comm;
-- *-assoc; *-comm; *-right-zero; distribʳ-*-+)
--open import Data.Bool using (Bool; false; true; _∧_; _∨_)
open import Data.Nat using (ℕ) -- ; _+_; _*_)
--open import Data.Vec
-- using (Vec; []; _∷_)
-- renaming (_++_ to _++V_; map to mapV; concat to concatV)
--open import Data.Empty using (⊥; ⊥-elim)
--open import Data.Unit using (⊤; tt)
--open import Data.Sum using (_⊎_; inj₁; inj₂)
--open import Data.Product using (_×_; _,_; proj₁; proj₂)
--open import Proofs using (
-- FinNatLemmas
-- distribˡ-*-+; *-right-identity
-- )
open import PiU using (U; ZERO; ONE; PLUS; TIMES; toℕ)
------------------------------------------------------------------------------
-- Level 0 of Pi
--
{--
⟦_⟧ : U → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS t₁ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
-- Abbreviations for examples
BOOL : U
BOOL = PLUS ONE ONE
BOOL² : U
BOOL² = TIMES BOOL BOOL
-- false⟷ true⟷ : ⟦ BOOL ⟧
-- false⟷ = inj₁ tt
-- true⟷ = inj₂ tt
-- For any finite type (t : U) there is no non-trivial path structure
-- between the elements of t. All such finite types are discrete
-- groupoids
--
-- For U, there are non-trivial paths between its points. In the
-- conventional HoTT presentation, a path between t₁ and t₂ is
-- postulated by univalence for each equivalence between t₁ and t₂. In
-- the context of finite types, an equivalence corresponds to a
-- permutation as each permutation has a unique inverse
-- permutation. Thus instead of the detour using univalence, we can
-- give an inductive definition of all possible permutations between
-- finite types which naturally induces paths between the points of U,
-- i.e., the finite types. More precisely, two types t₁ and t₂ have a
-- path between them if there is a permutation (c : t₁ ⟷ t₂). The fact
-- that c is a permutation guarantees, by construction, that (c ◎ ! c
-- ∼ id⟷) and (! c ◎ c ∼ id⟷). A complete set of generators for all
-- possible permutations between finite types is given by the
-- following definition. Note that these permutations do not reach
-- inside the types and hence do not generate paths between the points
-- within the types. The paths are just between the types themselves.
--}
size : U → ℕ
size = toℕ
infix 30 _⟷_
infixr 50 _◎_
-- Combinators, permutations, or paths depending on the perspective
data _⟷_ : U → U → Set where
unite₊l : {t : U} → PLUS ZERO t ⟷ t
uniti₊l : {t : U} → t ⟷ PLUS ZERO t
unite₊r : {t : U} → PLUS t ZERO ⟷ t
uniti₊r : {t : U} → t ⟷ PLUS t ZERO
swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁
assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃
assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃)
unite⋆l : {t : U} → TIMES ONE t ⟷ t
uniti⋆l : {t : U} → t ⟷ TIMES ONE t
unite⋆r : {t : U} → TIMES t ONE ⟷ t
uniti⋆r : {t : U} → t ⟷ TIMES t ONE
swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁
assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃
assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃)
absorbr : {t : U} → TIMES ZERO t ⟷ ZERO
absorbl : {t : U} → TIMES t ZERO ⟷ ZERO
factorzr : {t : U} → ZERO ⟷ TIMES t ZERO
factorzl : {t : U} → ZERO ⟷ TIMES ZERO t
dist : {t₁ t₂ t₃ : U} →
TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)
factor : {t₁ t₂ t₃ : U} →
PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃
distl : {t₁ t₂ t₃ : U } →
TIMES t₁ (PLUS t₂ t₃) ⟷ PLUS (TIMES t₁ t₂) (TIMES t₁ t₃)
factorl : {t₁ t₂ t₃ : U } →
PLUS (TIMES t₁ t₂) (TIMES t₁ t₃) ⟷ TIMES t₁ (PLUS t₂ t₃)
id⟷ : {t : U} → t ⟷ t
_◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄)
{--
-- Syntactic equality of combinators
comb= : {t₁ t₂ t₃ t₄ : U} → (t₁ ⟷ t₂) → (t₃ ⟷ t₄) → Bool
comb= unite₊l unite₊l = true
comb= uniti₊l uniti₊l = true
comb= swap₊ swap₊ = true
comb= assocl₊ assocl₊ = true
comb= assocr₊ assocr₊ = true
comb= unite⋆l unite⋆l = true
comb= unite⋆r unite⋆r = true
comb= uniti⋆l uniti⋆l = true
comb= uniti⋆r uniti⋆r = true
comb= swap⋆ swap⋆ = true
comb= assocl⋆ assocl⋆ = true
comb= assocr⋆ assocr⋆ = true
comb= absorbl absorbl = true
comb= absorbr absorbr = true
comb= factorzl factorzl = true
comb= factorzr factorzr = true
comb= dist dist = true
comb= factor factor = true
comb= id⟷ id⟷ = true
comb= (c₁ ◎ c₂) (c₃ ◎ c₄) = comb= c₁ c₃ ∧ comb= c₂ c₄
comb= (c₁ ⊕ c₂) (c₃ ⊕ c₄) = comb= c₁ c₃ ∧ comb= c₂ c₄
comb= (c₁ ⊗ c₂) (c₃ ⊗ c₄) = comb= c₁ c₃ ∧ comb= c₂ c₄
comb= _ _ = false
-- Extensional evaluator for testing: serves as a specification
-- A canonical representation of each type as a vector of values. This
-- fixes a canonical order for the elements of the types: each value
-- has a canonical index.
utoVec : (t : U) → Vec ⟦ t ⟧ (size t)
utoVec ZERO = []
utoVec ONE = tt ∷ []
utoVec (PLUS t₁ t₂) = mapV inj₁ (utoVec t₁) ++V mapV inj₂ (utoVec t₂)
utoVec (TIMES t₁ t₂) =
concatV (mapV (λ v₁ → mapV (λ v₂ → (v₁ , v₂)) (utoVec t₂)) (utoVec t₁))
-- Combinators are always between types of the same size
-- Paths preserve sizes
size≡ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (size t₁ ≡ size t₂)
-- the composition case must be the first one
-- otherwise Agda will not unfold (c ◎ id⟷)
-- See "inconclusive matching" at
-- http://wiki.portal.chalmers.se/agda/
-- pmwiki.php?n=ReferenceManual.PatternMatching
size≡ (c₁ ◎ c₂) = trans (size≡ c₁) (size≡ c₂)
size≡ {PLUS ZERO t} {.t} unite₊l = refl
size≡ {t} {PLUS ZERO .t} uniti₊l = refl
size≡ {PLUS t ZERO} unite₊r = +-right-identity (size t)
size≡ {t} uniti₊r = sym (+-right-identity (size t))
size≡ {PLUS t₁ t₂} {PLUS .t₂ .t₁} swap₊ = +-comm (size t₁) (size t₂)
size≡ {PLUS t₁ (PLUS t₂ t₃)} {PLUS (PLUS .t₁ .t₂) .t₃} assocl₊ =
sym (+-assoc (size t₁) (size t₂) (size t₃))
size≡ {PLUS (PLUS t₁ t₂) t₃} {PLUS .t₁ (PLUS .t₂ .t₃)} assocr₊ =
+-assoc (size t₁) (size t₂) (size t₃)
size≡ {TIMES ONE t} {.t} unite⋆l = +-right-identity (size t)
size≡ {t} {TIMES ONE .t} uniti⋆l = sym (+-right-identity (size t))
size≡ {TIMES t ONE} {.t} unite⋆r = *-right-identity (size t)
size≡ {t} {TIMES .t ONE} uniti⋆r = sym (*-right-identity (size t))
size≡ {TIMES t₁ t₂} {TIMES .t₂ .t₁} swap⋆ = *-comm (size t₁) (size t₂)
size≡ {TIMES t₁ (TIMES t₂ t₃)} {TIMES (TIMES .t₁ .t₂) .t₃} assocl⋆ =
sym (*-assoc (size t₁) (size t₂) (size t₃))
size≡ {TIMES (TIMES t₁ t₂) t₃} {TIMES .t₁ (TIMES .t₂ .t₃)} assocr⋆ =
*-assoc (size t₁) (size t₂) (size t₃)
size≡ {TIMES .ZERO t} {ZERO} absorbr = refl
size≡ {TIMES t .ZERO} {ZERO} absorbl = *-right-zero (size t)
size≡ {ZERO} {TIMES ZERO t} factorzl = refl
size≡ {ZERO} {TIMES t ZERO} factorzr = sym (*-right-zero (size t))
size≡ {TIMES (PLUS t₁ t₂) t₃} {PLUS (TIMES .t₁ .t₃) (TIMES .t₂ .t₃)} dist =
distribʳ-*-+ (size t₃) (size t₁) (size t₂)
size≡ {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} {TIMES (PLUS .t₁ .t₂) .t₃} factor =
sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂))
size≡ {TIMES t₁ (PLUS t₂ t₃)} distl = distribˡ-*-+ (size t₁) (size t₂) (size t₃)
size≡ {PLUS (TIMES t₁ t₂) (TIMES .t₁ t₃)} factorl =
sym (distribˡ-*-+ (size t₁) (size t₂) (size t₃))
size≡ {t} {.t} id⟷ = refl
size≡ {PLUS t₁ t₂} {PLUS t₃ t₄} (c₁ ⊕ c₂) = cong₂ _+_ (size≡ c₁) (size≡ c₂)
size≡ {TIMES t₁ t₂} {TIMES t₃ t₄} (c₁ ⊗ c₂) = cong₂ _*_ (size≡ c₁) (size≡ c₂)
-- All proofs about sizes are "the same"
size∼ : {t₁ t₂ : U} → (c₁ c₂ : t₁ ⟷ t₂) → (size≡ c₁ ≡ size≡ c₂)
size∼ c₁ c₂ = proof-irrelevance (size≡ c₁) (size≡ c₂)
------------------------------------------------------------------------------
-- Examples of Pi programs
-- Nicer syntax that shows intermediate values instead of the above
-- point-free notation of permutations
infixr 2 _⟷⟨_⟩_
infix 2 _□
_⟷⟨_⟩_ : (t₁ : U) {t₂ : U} {t₃ : U} →
(t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_ ⟷⟨ α ⟩ β = α ◎ β
_□ : (t : U) → {t : U} → (t ⟷ t)
_□ t = id⟷
-- calculate and print specification of a combinator
spec : {t₁ t₂ : U} → (t₁ ⟷ t₂) → Vec (⟦ t₁ ⟧ × ⟦ t₂ ⟧) (size t₁)
spec {t₁} {t₂} c = mapV (λ v₁ → (v₁ , eval c v₁)) (utoVec t₁)
-- For easier manipulation of Bool
foldBool unfoldBool : BOOL ⟷ BOOL
foldBool = id⟷
unfoldBool = id⟷
-- Many ways of negating a BOOL. Again, it is absolutely critical that there
-- is NO path between false⟷ and true⟷. These permutations instead are based
-- on paths between x and neg (neg x) which are the trivial paths on each of
-- the two points in BOOL.
NOT : BOOL ⟷ BOOL
NOT = unfoldBool ◎ swap₊ ◎ foldBool
-- spec: (false , true) ∷ (true , false) ∷ []
NEG1 NEG2 NEG3 NEG4 NEG5 : BOOL ⟷ BOOL
NEG1 = unfoldBool ◎ swap₊ ◎ foldBool
-- spec: (false , true) ∷ (true , false) ∷ []
NEG2 = id⟷ ◎ NOT
-- spec: (false , true) ∷ (true , false) ∷ []
NEG3 = NOT ◎ NOT ◎ NOT
-- spec: (false , true) ∷ (true , false) ∷ []
NEG4 = NOT ◎ id⟷
-- spec: (false , true) ∷ (true , false) ∷ []
NEG5 = uniti⋆l ◎ swap⋆ ◎ (NOT ⊗ id⟷) ◎ swap⋆ ◎ unite⋆l
-- spec: (false , true) ∷ (true , false) ∷ []
NEG6 = uniti⋆r ◎ (NOT ⊗ id⟷) ◎ unite⋆r -- same as above, but shorter
-- CNOT
CNOT : BOOL² ⟷ BOOL²
CNOT = TIMES BOOL BOOL
⟷⟨ unfoldBool ⊗ id⟷ ⟩
TIMES (PLUS x y) BOOL
⟷⟨ dist ⟩
PLUS (TIMES x BOOL) (TIMES y BOOL)
⟷⟨ id⟷ ⊕ (id⟷ ⊗ NOT) ⟩
PLUS (TIMES x BOOL) (TIMES y BOOL)
⟷⟨ factor ⟩
TIMES (PLUS x y) BOOL
⟷⟨ foldBool ⊗ id⟷ ⟩
TIMES BOOL BOOL □
where x = ONE; y = ONE
-- spec:
-- ((false , false) , false , false) ∷
-- ((false , true) , false , true) ∷
-- ((true , false) , true , true) ∷
-- ((true , true) , true , false) ∷ []
-- TOFFOLI
TOFFOLI : TIMES BOOL BOOL² ⟷ TIMES BOOL BOOL²
TOFFOLI = TIMES BOOL BOOL²
⟷⟨ unfoldBool ⊗ id⟷ ⟩
TIMES (PLUS x y) BOOL²
⟷⟨ dist ⟩
PLUS (TIMES x BOOL²) (TIMES y BOOL²)
⟷⟨ id⟷ ⊕ (id⟷ ⊗ CNOT) ⟩
PLUS (TIMES x BOOL²) (TIMES y BOOL²)
⟷⟨ factor ⟩
TIMES (PLUS x y) BOOL²
⟷⟨ foldBool ⊗ id⟷ ⟩
TIMES BOOL BOOL² □
where x = ONE; y = ONE
-- spec:
-- ((false , false , false) , false , false , false) ∷
-- ((false , false , true) , false , false , true) ∷
-- ((false , true , false) , false , true , false) ∷
-- ((false , true , true) , false , true , true) ∷
-- ((true , false , false) , true , false , false) ∷
-- ((true , false , true) , true , false , true) ∷
-- ((true , true , false) , true , true , true) ∷
-- ((true , true , true) , true , true , false) ∷ []
-- Swaps for the type 1+(1+1)
-- We have three values in the type 1+(1+1)
-- Let's call them a, b, and c
-- There 6 permutations. Using the swaps below we can express every permutation:
-- a b c id⟷
-- a c b SWAP23
-- b a c SWAP12
-- b c a ROTL
-- c a b ROTR
-- c b a SWAP13
SWAP12 SWAP23 SWAP13 ROTL ROTR :
PLUS ONE (PLUS ONE ONE) ⟷ PLUS ONE (PLUS ONE ONE)
SWAP12 = assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊
-- spec:
-- (inj₁ tt , inj₂ (inj₁ tt)) ∷
-- (inj₂ (inj₁ tt) , inj₁ tt) ∷
-- (inj₂ (inj₂ tt) , inj₂ (inj₂ tt)) ∷ []
SWAP23 = id⟷ ⊕ swap₊
-- spec:
-- (inj₁ tt , inj₁ tt) ∷
-- (inj₂ (inj₁ tt) , inj₂ (inj₂ tt)) ∷
-- (inj₂ (inj₂ tt) , inj₂ (inj₁ tt)) ∷ []
SWAP13 = SWAP23 ◎ SWAP12 ◎ SWAP23
-- spec:
-- (inj₁ tt , inj₂ (inj₂ tt)) ∷
-- (inj₂ (inj₁ tt) , inj₂ (inj₁ tt)) ∷
-- (inj₂ (inj₂ tt) , inj₁ tt) ∷ []
ROTR = SWAP12 ◎ SWAP23
-- spec:
-- (inj₁ tt , inj₂ (inj₂ tt)) ∷
-- (inj₂ (inj₁ tt) , inj₁ tt) ∷
-- (inj₂ (inj₂ tt) , inj₂ (inj₁ tt)) ∷ []
ROTL = SWAP13 ◎ SWAP23
-- spec:
-- (inj₁ tt , inj₂ (inj₁ tt)) ∷
-- (inj₂ (inj₁ tt) , inj₂ (inj₂ tt)) ∷
-- (inj₂ (inj₂ tt) , inj₁ tt) ∷ []
-- The Peres gate is a universal gate: it takes three inputs a, b, and c, and
-- produces a, a xor b, (a and b) xor c
PERES : TIMES (TIMES BOOL BOOL) BOOL ⟷ TIMES (TIMES BOOL BOOL) BOOL
PERES = (id⟷ ⊗ NOT) ◎ assocr⋆ ◎ (id⟷ ⊗ swap⋆) ◎
TOFFOLI ◎
(id⟷ ⊗ (NOT ⊗ id⟷)) ◎
TOFFOLI ◎
(id⟷ ⊗ swap⋆) ◎ (id⟷ ⊗ (NOT ⊗ id⟷)) ◎
TOFFOLI ◎
(id⟷ ⊗ (NOT ⊗ id⟷)) ◎ assocl⋆
-- spec:
-- (((false , false) , false) , (false , false) , false) ∷
-- (((false , false) , true) , (false , false) , true) ∷
-- (((false , true) , false) , (false , true) , false) ∷
-- (((false , true) , true) , (false , true) , true) ∷
-- (((true , false) , false) , (true , true) , false) ∷
-- (((true , false) , true) , (true , true) , true) ∷
-- (((true , true) , false) , (true , false) , true) ∷
-- (((true , true) , true) , (true , false) , false) ∷ []
-- A reversible full adder: See http://arxiv.org/pdf/1008.3533.pdf
-- Input: (z, ((n1, n2), cin)))
-- Output (g1, (g2, (sum, cout)))
-- where sum = n1 xor n2 xor cin
-- and cout = ((n1 xor n2) and cin) xor (n1 and n2) xor z
FULLADDER : TIMES BOOL (TIMES (TIMES BOOL BOOL) BOOL) ⟷
TIMES BOOL (TIMES BOOL (TIMES BOOL BOOL))
FULLADDER =
-- (z,((n1,n2),cin))
swap⋆ ◎
-- (((n1,n2),cin),z)
(swap⋆ ⊗ id⟷) ◎
-- ((cin,(n1,n2)),z)
assocr⋆ ◎
-- (cin,((n1,n2),z))
swap⋆ ◎
-- (((n1,n2),z),cin)
(PERES ⊗ id⟷) ◎
-- (((n1,n1 xor n2),(n1 and n2) xor z),cin)
assocr⋆ ◎
-- ((n1,n1 xor n2),((n1 and n2) xor z,cin))
(id⟷ ⊗ swap⋆) ◎
-- ((n1,n1 xor n2),(cin,(n1 and n2) xor z))
assocr⋆ ◎
-- (n1,(n1 xor n2,(cin,(n1 and n2) xor z)))
(id⟷ ⊗ assocl⋆) ◎
-- (n1,((n1 xor n2,cin),(n1 and n2) xor z))
(id⟷ ⊗ PERES) ◎
-- (n1,((n1 xor n2,n1 xor n2 xor cin),
-- ((n1 xor n2) and cin) xor (n1 and n2) xor z))
(id⟷ ⊗ assocr⋆)
-- (n1,(n1 xor n2,
-- (n1 xor n2 xor cin,((n1 xor n2) and cin) xor (n1 and n2) xor z)))
-- spec:
-- ((false , (false , false) , false) , false , false , false , false) ∷
-- ((false , (false , false) , true) , false , false , true , false) ∷
-- ((false , (false , true) , false) , false , true , true , false) ∷
-- ((false , (false , true) , true) , false , true , false , true) ∷
-- ((false , (true , false) , false) , true , true , true , false) ∷
-- ((false , (true , false) , true) , true , true , false , true) ∷
-- ((false , (true , true) , false) , true , false , false , true) ∷
-- ((false , (true , true) , true) , true , false , true , true) ∷
-- ((true , (false , false) , false) , false , false , false , true) ∷
-- ((true , (false , false) , true) , false , false , true , true) ∷
-- ((true , (false , true) , false) , false , true , true , true) ∷
-- ((true , (false , true) , true) , false , true , false , false) ∷
-- ((true , (true , false) , false) , true , true , true , true) ∷
-- ((true , (true , false) , true) , true , true , false , false) ∷
-- ((true , (true , true) , false) , true , false , false , false) ∷
-- ((true , (true , true) , true) , true , false , true , false) ∷ []
--}
------------------------------------------------------------------------------
-- Every permutation has an inverse. There are actually many syntactically
-- different inverses but they are all equivalent.
-- Alternative view: this corresponds to Lemma 2.1.1 In our notation,
-- for every path t₁ ⟷ t₂, we have a path t₂ ⟷ t₁ such that (! id⟷)
-- reduces to id⟷.
! : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
! unite₊l = uniti₊l
! uniti₊l = unite₊l
! unite₊r = uniti₊r
! uniti₊r = unite₊r
! swap₊ = swap₊
! assocl₊ = assocr₊
! assocr₊ = assocl₊
! unite⋆l = uniti⋆l
! uniti⋆l = unite⋆l
! unite⋆r = uniti⋆r
! uniti⋆r = unite⋆r
! swap⋆ = swap⋆
! assocl⋆ = assocr⋆
! assocr⋆ = assocl⋆
! absorbl = factorzr
! absorbr = factorzl
! factorzl = absorbr
! factorzr = absorbl
! dist = factor
! factor = dist
! distl = factorl
! factorl = distl
! id⟷ = id⟷
! (c₁ ◎ c₂) = ! c₂ ◎ ! c₁
! (c₁ ⊕ c₂) = (! c₁) ⊕ (! c₂)
! (c₁ ⊗ c₂) = (! c₁) ⊗ (! c₂)
!! : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → ! (! c) ≡ c
!! {c = unite₊l} = refl
!! {c = uniti₊l} = refl
!! {c = unite₊r} = refl
!! {c = uniti₊r} = refl
!! {c = swap₊} = refl
!! {c = assocl₊} = refl
!! {c = assocr₊} = refl
!! {c = unite⋆l} = refl
!! {c = uniti⋆l} = refl
!! {c = unite⋆r} = refl
!! {c = uniti⋆r} = refl
!! {c = swap⋆} = refl
!! {c = assocl⋆} = refl
!! {c = assocr⋆} = refl
!! {c = absorbr} = refl
!! {c = absorbl} = refl
!! {c = factorzl} = refl
!! {c = factorzr} = refl
!! {c = dist} = refl
!! {c = factor} = refl
!! {c = distl} = refl
!! {c = factorl} = refl
!! {c = id⟷} = refl
!! {c = c₁ ◎ c₂} =
begin (! (! (c₁ ◎ c₂))
≡⟨ refl ⟩
! (! c₂ ◎ ! c₁)
≡⟨ refl ⟩
! (! c₁) ◎ ! (! c₂)
≡⟨ cong₂ _◎_ (!! {c = c₁}) (!! {c = c₂}) ⟩
c₁ ◎ c₂ ∎)
where open ≡-Reasoning
!! {c = c₁ ⊕ c₂} =
begin (! (! (c₁ ⊕ c₂))
≡⟨ refl ⟩
! (! c₁) ⊕ ! (! c₂)
≡⟨ cong₂ _⊕_ (!! {c = c₁}) (!! {c = c₂}) ⟩
c₁ ⊕ c₂ ∎)
where open ≡-Reasoning
!! {c = c₁ ⊗ c₂} =
begin (! (! (c₁ ⊗ c₂))
≡⟨ refl ⟩
! (! c₁) ⊗ ! (! c₂)
≡⟨ cong₂ _⊗_ (!! {c = c₁}) (!! {c = c₂}) ⟩
c₁ ⊗ c₂ ∎)
where open ≡-Reasoning
{--
-- size≡ and !
size≡! : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (size t₂ ≡ size t₁)
size≡! c = sym (size≡ c)
------------------------------------------------------------------------------
ttt : {t₁ t₂ t₃ t₄ : U} →
(TIMES (PLUS t₁ t₂) (PLUS t₃ t₄)) ⟷
(PLUS (PLUS (PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)) (TIMES t₁ t₄))) (TIMES t₂ t₄)
ttt {t₁} {t₂} {t₃} {t₄} =
(distl ◎ (dist {t₁} {t₂} {t₃} ⊕ dist {t₁} {t₂} {t₄})) ◎ assocl₊
------------------------------------------------------------------------------
-- generalized CNOT
gcnot : {A B C : U} → (TIMES (PLUS A B) (PLUS C C)) ⟷ (TIMES (PLUS A B) (PLUS C C))
gcnot = dist ◎ (id⟷ ⊕ (id⟷ ⊗ swap₊)) ◎ factor
-- Generalized Toffolli gate. See what 'arithmetic' it performs.
GToffoli : {A B C D E : U} → TIMES (PLUS A B) (TIMES (PLUS C D) (PLUS E E)) ⟷ TIMES (PLUS A B) (TIMES (PLUS C D) (PLUS E E))
GToffoli = dist ◎ (id⟷ ⊕ (id⟷ ⊗ gcnot)) ◎ factor
------------------------------------------------------------------------------
--}
| 35.184411
| 124
| 0.5345
|
cbef682b7bca326b7ed0bf44fe1b7869519fe899
| 3,896
|
agda
|
Agda
|
lemmas-freshness.agda
|
hazelgrove/hazel-palette-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | 4
|
2020-10-04T06:45:06.000Z
|
2021-12-19T15:38:31.000Z
|
lemmas-freshness.agda
|
hazelgrove/hazel-palette-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | 9
|
2020-09-30T20:27:56.000Z
|
2020-10-20T20:44:13.000Z
|
lemmas-freshness.agda
|
hazelgrove/hazelnut-livelits-agda
|
c3225acc3c94c56376c6842b82b8b5d76912df2a
|
[
"MIT"
] | null | null | null |
open import Prelude
open import Nat
open import core
open import contexts
open import lemmas-disjointness
module lemmas-freshness where
-- if x is fresh in an eexp, it's fresh in its expansion
mutual
fresh-elab-synth1 : ∀{x e τ d Γ Δ} →
x # Γ →
freshe x e →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
fresh x d
fresh-elab-synth1 _ FRHConst ESConst = FConst
fresh-elab-synth1 apt (FRHAsc frsh) (ESAsc x₁) = FCast (fresh-elab-ana1 apt frsh x₁)
fresh-elab-synth1 _ (FRHVar x₂) (ESVar x₃) = FVar x₂
fresh-elab-synth1 {Γ = Γ} apt (FRHLam2 x₂ frsh) (ESLam x₃ exp) = FLam x₂ (fresh-elab-synth1 (apart-extend1 Γ x₂ apt) frsh exp)
fresh-elab-synth1 apt FRHEHole ESEHole = FHole (EFId apt)
fresh-elab-synth1 apt (FRHNEHole frsh) (ESNEHole x₁ exp) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh exp)
fresh-elab-synth1 apt (FRHAp frsh frsh₁) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) =
FAp (FCast (fresh-elab-ana1 apt frsh x₅))
(FCast (fresh-elab-ana1 apt frsh₁ x₆))
fresh-elab-synth1 apt (FRHLam1 x₁ frsh) ()
fresh-elab-synth1 apt (FRHFst frsh) (ESFst s m esana) = FFst (FCast (fresh-elab-ana1 apt frsh esana))
fresh-elab-synth1 apt (FRHSnd frsh) (ESSnd s m esana) = FSnd (FCast (fresh-elab-ana1 apt frsh esana))
fresh-elab-synth1 apt (FRHPair frsh frsh₁) (ESPair x₁ x₂ exp exp₁) = FPair (fresh-elab-synth1 apt frsh exp)
(fresh-elab-synth1 apt frsh₁ exp₁)
fresh-elab-ana1 : ∀{ x e τ d τ' Γ Δ} →
x # Γ →
freshe x e →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
fresh x d
fresh-elab-ana1 {Γ = Γ} apt (FRHLam1 x₁ frsh) (EALam x₂ x₃ exp) = FLam x₁ (fresh-elab-ana1 (apart-extend1 Γ x₁ apt) frsh exp )
fresh-elab-ana1 apt frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth1 apt frsh x₃
fresh-elab-ana1 apt FRHEHole EAEHole = FHole (EFId apt)
fresh-elab-ana1 apt (FRHNEHole frsh) (EANEHole x₁ x₂) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh x₂)
-- if x is fresh in the expansion of an eexp, it's fresh in that eexp
mutual
fresh-elab-synth2 : ∀{x e τ d Γ Δ} →
fresh x d →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
freshe x e
fresh-elab-synth2 FConst ESConst = FRHConst
fresh-elab-synth2 (FVar x₂) (ESVar x₃) = FRHVar x₂
fresh-elab-synth2 (FLam x₂ frsh) (ESLam x₃ exp) = FRHLam2 x₂ (fresh-elab-synth2 frsh exp)
fresh-elab-synth2 (FHole x₁) ESEHole = FRHEHole
fresh-elab-synth2 (FNEHole x₁ frsh) (ESNEHole x₂ exp) = FRHNEHole (fresh-elab-synth2 frsh exp)
fresh-elab-synth2 (FAp (FCast frsh) (FCast frsh₁)) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) =
FRHAp (fresh-elab-ana2 frsh x₅)
(fresh-elab-ana2 frsh₁ x₆)
fresh-elab-synth2 (FCast frsh) (ESAsc x₁) = FRHAsc (fresh-elab-ana2 frsh x₁)
fresh-elab-synth2 (FFailedCast frsh) ()
fresh-elab-synth2 (FFst (FCast frsh)) (ESFst s m esana) = FRHFst (fresh-elab-ana2 frsh esana)
fresh-elab-synth2 (FSnd (FCast frsh)) (ESSnd s m esana) = FRHSnd (fresh-elab-ana2 frsh esana)
fresh-elab-synth2 (FPair frsh frsh₁) (ESPair x₁ x₂ exp exp₁) = FRHPair (fresh-elab-synth2 frsh exp) (fresh-elab-synth2 frsh₁ exp₁)
fresh-elab-ana2 : ∀{ x e τ d τ' Γ Δ} →
fresh x d →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
freshe x e
fresh-elab-ana2 (FLam x₁ frsh) (EALam x₂ x₃ exp) = FRHLam1 x₁ (fresh-elab-ana2 frsh exp)
fresh-elab-ana2 frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth2 frsh x₃
fresh-elab-ana2 (FHole x₁) EAEHole = FRHEHole
fresh-elab-ana2 (FNEHole x₁ frsh) (EANEHole x₂ x₃) = FRHNEHole (fresh-elab-synth2 frsh x₃)
| 57.294118
| 134
| 0.587526
|
59eb7a227e447678cd6b2aa0c90dba3030897a0e
| 2,439
|
agda
|
Agda
|
Cubical/Categories/Functor/Base.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Categories/Functor/Base.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Categories/Functor/Base.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Categories.Functor.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
private
variable
ℓC ℓC' ℓD ℓD' : Level
record Functor (C : Precategory ℓC ℓC') (D : Precategory ℓD ℓD') : Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where
no-eta-equality
open Precategory
field
F-ob : C .ob → D .ob
F-hom : {x y : C .ob} → C [ x , y ] → D [(F-ob x) , (F-ob y)]
F-id : {x : C .ob} → F-hom (C .id x) ≡ D .id (F-ob x)
F-seq : {x y z : C .ob} (f : C [ x , y ]) (g : C [ y , z ]) → F-hom (f ⋆⟨ C ⟩ g) ≡ (F-hom f) ⋆⟨ D ⟩ (F-hom g)
isFull = (x y : _) (F[f] : D [(F-ob x) , (F-ob y)]) → ∃ (C [ x , y ]) (λ f → F-hom f ≡ F[f])
isFaithful = (x y : _) (f g : C [ x , y ]) → F-hom f ≡ F-hom g → f ≡ g
isEssentiallySurj = ∀ (d : D .ob) → Σ[ c ∈ C .ob ] CatIso {C = D} (F-ob c) d
private
variable
ℓ ℓ' : Level
C D E : Precategory ℓ ℓ'
open Precategory
open Functor
-- Helpful notation
-- action on objects
infix 30 _⟅_⟆
_⟅_⟆ : (F : Functor C D)
→ C .ob
→ D .ob
_⟅_⟆ = F-ob
-- action on morphisms
infix 30 _⟪_⟫ -- same infix level as on objects since these will never be used in the same context
_⟪_⟫ : (F : Functor C D)
→ ∀ {x y}
→ C [ x , y ]
→ D [(F ⟅ x ⟆) , (F ⟅ y ⟆)]
_⟪_⟫ = F-hom
-- Functor constructions
𝟙⟨_⟩ : ∀ (C : Precategory ℓ ℓ') → Functor C C
𝟙⟨ C ⟩ .F-ob x = x
𝟙⟨ C ⟩ .F-hom f = f
𝟙⟨ C ⟩ .F-id = refl
𝟙⟨ C ⟩ .F-seq _ _ = refl
-- functor composition
funcComp : ∀ (G : Functor D E) (F : Functor C D) → Functor C E
(funcComp G F) .F-ob c = G ⟅ F ⟅ c ⟆ ⟆
(funcComp G F) .F-hom f = G ⟪ F ⟪ f ⟫ ⟫
(funcComp {D = D} {E = E} {C = C} G F) .F-id {c}
= (G ⟪ F ⟪ C .id c ⟫ ⟫)
≡⟨ cong (G ⟪_⟫) (F .F-id) ⟩
G .F-id
-- (G ⟪ D .id (F ⟅ c ⟆) ⟫) -- deleted this cause the extra refl composition was annoying
-- ≡⟨ G .F-id ⟩
-- E .id (G ⟅ F ⟅ c ⟆ ⟆)
-- ∎
(funcComp {D = D} {E = E} {C = C} G F) .F-seq {x} {y} {z} f g
= (G ⟪ F ⟪ f ⋆⟨ C ⟩ g ⟫ ⟫)
≡⟨ cong (G ⟪_⟫) (F .F-seq _ _) ⟩
G .F-seq _ _
-- (G ⟪ (F ⟪ f ⟫) ⋆⟨ D ⟩ (F ⟪ g ⟫) ⟫) -- deleted for same reason as above
-- ≡⟨ G .F-seq _ _ ⟩
-- (G ⟪ F ⟪ f ⟫ ⟫) ⋆⟨ E ⟩ (G ⟪ F ⟪ g ⟫ ⟫)
-- ∎
infixr 30 funcComp
syntax funcComp G F = G ∘F F
_^opF : Functor C D → Functor (C ^op) (D ^op)
(F ^opF) .F-ob = F .F-ob
(F ^opF) .F-hom = F .F-hom
(F ^opF) .F-id = F .F-id
(F ^opF) .F-seq f g = F .F-seq g f
| 27.1
| 115
| 0.493235
|
311000f5d7bb38d4c19654ca1c51dae8f808fe9e
| 666
|
agda
|
Agda
|
agda/ExtInterface/Data/Maybe.agda
|
RPI-WCL/safety-envelopes-sentinels
|
896e67a2ad21041a1c9ef5f3ad6318c67d730341
|
[
"BSD-3-Clause"
] | null | null | null |
agda/ExtInterface/Data/Maybe.agda
|
RPI-WCL/safety-envelopes-sentinels
|
896e67a2ad21041a1c9ef5f3ad6318c67d730341
|
[
"BSD-3-Clause"
] | null | null | null |
agda/ExtInterface/Data/Maybe.agda
|
RPI-WCL/safety-envelopes-sentinels
|
896e67a2ad21041a1c9ef5f3ad6318c67d730341
|
[
"BSD-3-Clause"
] | 1
|
2020-09-20T00:36:09.000Z
|
2020-09-20T00:36:09.000Z
|
module ExtInterface.Data.Maybe where
open import Function using (_∘_)
open import Level using (Level)
private
variable
a b c : Level
A : Set a
B : Set b
C : Set c
data Maybe (A : Set) : Set where
nothing : Maybe A
just : (x : A) → Maybe A
maybe : ∀ {A : Set} {B : Maybe A → Set} →
((x : A) → B (just x)) → B nothing → (x : Maybe A) → B x
maybe j n (just x) = j x
maybe j n nothing = n
map : (A → B) → Maybe A → Maybe B
map f = maybe (just ∘ f) nothing
-- Monad: bind
infixl 1 _>>=_
_>>=_ : Maybe A → (A → Maybe B) → Maybe B
nothing >>= f = nothing
just a >>= f = f a
{-# COMPILE GHC Maybe = data Maybe (Nothing | Just) #-}
| 20.181818
| 64
| 0.561562
|
1dda8aab2e493903d2c933061c4328d63f7f9156
| 2,653
|
agda
|
Agda
|
examples/SummerSchool07/Lecture/Records.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/SummerSchool07/Lecture/Records.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/SummerSchool07/Lecture/Records.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-
Types Summer School 2007
Bertinoro
Aug 19 - 31, 2007
Agda
Ulf Norell
-}
-- Records are labeled sigma types.
module Records where
open import Nat
open import Bool
{-
A very simple record.
-}
record Point : Set where
field
x : Nat
y : Nat
-- A record can be seen as a one constructor datatype. In this case:
data Point' : Set where
mkPoint : (x : Nat)(y : Nat) -> Point'
-- There are a few differences, though:
-- To construct a record you use the syntax record { ..; x = e; .. }
origin : Point
origin = record { x = 0; y = 0 }
-- instead of
origin' : Point'
origin' = mkPoint 0 0
-- What's more interesting is that you get projection functions
-- for free when you declare a record. More precisely, you get a module
-- parameterised over a record, containing functions corresponding to the
-- fields. In the Point example you get:
{-
module Point (p : Point) where
x : Nat
y : Nat
-}
-- So Point.x : Point -> Nat is the projection function for the field x.
getX : Point -> Nat
getX = Point.x
-- A nifty thing with having the projection functions in a module is that
-- you can apply the module to a record value, in effect opening the record.
sum : Point -> Nat
sum p = x + y
where
open module Pp = Point p
-- The final difference between records and datatypes is that we have
-- η-equality on records.
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
η-Point : (p : Point) -> p == record { x = Point.x p; y = Point.y p }
η-Point p = refl
{-
The empty record
-}
-- One interesting benefit of this is that we get a unit type with
-- η-equality.
record True : Set where
tt : True
tt = record{}
-- Now, since any element of True is equal to tt, metavariables of
-- type True will simply disappear. The following cute example exploits
-- this:
data False : Set where
NonZero : Nat -> Set
NonZero zero = False
NonZero (suc _) = True
-- We make the proof that m is non-zero implicit.
_/_ : (n m : Nat){p : NonZero m} -> Nat
(n / zero) {}
zero / suc m = zero
suc n / suc m = div (suc n) (suc m) m
where
div : Nat -> Nat -> Nat -> Nat
div zero zero c = suc zero
div zero (suc y) c = zero
div (suc x) zero c = suc (div x c c)
div (suc x) (suc y) c = div x y c
-- Now, as long as we're dividing by things which are obviously
-- NonZero we can completely ignore the proof.
five = 17 / 3
{-
A dependent record
-}
-- Of course, records can be dependent, and have parameters.
record ∃ {A : Set}(P : A -> Set) : Set where
field
witness : A
proof : P witness
| 20.565891
| 76
| 0.626838
|
2973970ade6dfc1cbc34ef4885b82121e01651be
| 674
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Instances/Int.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Algebra/CommRing/Instances/Int.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Instances/Int.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Instances.Int where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.CommRing
open import Cubical.Data.Int as Int
renaming ( ℤ to ℤType ; _+_ to _+ℤ_; _·_ to _·ℤ_; -_ to -ℤ_)
open CommRingStr
ℤ : CommRing ℓ-zero
fst ℤ = ℤType
0r (snd ℤ) = 0
1r (snd ℤ) = 1
_+_ (snd ℤ) = _+ℤ_
_·_ (snd ℤ) = _·ℤ_
- snd ℤ = -ℤ_
isCommRing (snd ℤ) = isCommRingℤ
where
abstract
isCommRingℤ : IsCommRing 0 1 _+ℤ_ _·ℤ_ -ℤ_
isCommRingℤ = makeIsCommRing isSetℤ Int.+Assoc (λ _ → refl)
-Cancel Int.+Comm Int.·Assoc
Int.·Rid ·DistR+ Int.·Comm
| 24.962963
| 63
| 0.617211
|
29709ceb873a0f857c7966f6e231c7009946c328
| 1,086
|
agda
|
Agda
|
prototyping/Luau/Run.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | 1
|
2022-02-11T21:30:17.000Z
|
2022-02-11T21:30:17.000Z
|
prototyping/Luau/Run.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | null | null | null |
prototyping/Luau/Run.agda
|
FreakingBarbarians/luau
|
5187e64f88953f34785ffe58acd0610ee5041f5f
|
[
"MIT"
] | null | null | null |
module Luau.Run where
open import Agda.Builtin.Equality using (_≡_; refl)
open import Luau.Heap using (Heap; emp)
open import Luau.Syntax using (Block; return; _∙_; done)
open import Luau.OpSem using (_⊢_⟶*_⊣_; refl; step)
open import Luau.Value using (val)
open import Properties.Step using (stepᴮ; step; return; done; error)
open import Luau.RuntimeError using (RuntimeErrorᴮ)
data RunResult (H : Heap) (B : Block) : Set where
return : ∀ V {B′ H′} → (H ⊢ B ⟶* (return (val V) ∙ B′) ⊣ H′) → RunResult H B
done : ∀ {H′} → (H ⊢ B ⟶* done ⊣ H′) → RunResult H B
error : ∀ {B′ H′} → (RuntimeErrorᴮ H′ B′) → (H ⊢ B ⟶* B′ ⊣ H′) → RunResult H B
{-# TERMINATING #-}
run′ : ∀ H B → RunResult H B
run′ H B with stepᴮ H B
run′ H B | step H′ B′ D with run′ H′ B′
run′ H B | step H′ B′ D | return V D′ = return V (step D D′)
run′ H B | step H′ B′ D | done D′ = done (step D D′)
run′ H B | step H′ B′ D | error E D′ = error E (step D D′)
run′ H _ | return V refl = return V refl
run′ H _ | done refl = done refl
run′ H B | error E = error E refl
run : ∀ B → RunResult emp B
run = run′ emp
| 37.448276
| 80
| 0.61326
|
a146f89ccc858025434b05890c50382f0b9766e6
| 1,623
|
agda
|
Agda
|
Cubical/Algebra/Ring/Kernel.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Ring/Kernel.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Algebra/Ring/Kernel.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Ring.Kernel where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Structure
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Algebra.Ring.Base
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.Ring.Ideal
private
variable
ℓ : Level
module _ {{R S : Ring {ℓ}}} (f′ : RingHom R S) where
open RingHom f′
open HomTheory f′
open RingStr ⦃...⦄
open isIdeal
open Theory
private
instance
_ = R
_ = S
_ = snd R
_ = snd S
kernel : ⟨ R ⟩ → hProp ℓ
kernel x = (f x ≡ 0r) , isSetRing S _ _
kernelIsIdeal : isIdeal R kernel
+-closed kernelIsIdeal =
λ fx≡0 fy≡0 → f (_ + _) ≡⟨ isHom+ _ _ ⟩
f _ + f _ ≡⟨ cong (λ u → u + f _) fx≡0 ⟩
0r + f _ ≡⟨ cong (λ u → 0r + u) fy≡0 ⟩
0r + 0r ≡⟨ 0-idempotent S ⟩
0r ∎
-closed kernelIsIdeal =
λ fx≡0 → f (- _) ≡⟨ -commutesWithHom _ ⟩
- f _ ≡⟨ cong -_ fx≡0 ⟩
- 0r ≡⟨ 0-selfinverse S ⟩
0r ∎
0r-closed kernelIsIdeal = f 0r ≡⟨ homPres0 ⟩ 0r ∎
·-closedLeft kernelIsIdeal = λ r fx≡0 →
f (r · _) ≡⟨ isHom· _ _ ⟩
f r · f (_) ≡⟨ cong (λ u → f r · u) fx≡0 ⟩
f r · 0r ≡⟨ 0-rightNullifies S _ ⟩
0r ∎
·-closedRight kernelIsIdeal = λ r fx≡0 →
f (_ · r) ≡⟨ isHom· _ _ ⟩
f _ · f r ≡⟨ cong (λ u → u · f r) fx≡0 ⟩
0r · f r ≡⟨ 0-leftNullifies S _ ⟩
0r ∎
| 28.473684
| 59
| 0.546519
|
c51f085ccd9a85d570391448ad8b05dfbbb740ea
| 617
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Nullary/Implication.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Nullary/Implication.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Nullary/Implication.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Implications of nullary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Implication where
open import Relation.Nullary
open import Data.Empty
-- Some properties which are preserved by _→_.
infixr 2 _→-dec_
_→-dec_ : ∀ {p q} {P : Set p} {Q : Set q} →
Dec P → Dec Q → Dec (P → Q)
yes p →-dec no ¬q = no (λ f → ¬q (f p))
yes p →-dec yes q = yes (λ _ → q)
no ¬p →-dec _ = yes (λ p → ⊥-elim (¬p p))
| 26.826087
| 72
| 0.455429
|
cb97ab7df7144d679da0e56ea8767fe498691d78
| 17,133
|
agda
|
Agda
|
Cubical/HITs/Truncation/FromNegTwo/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/HITs/Truncation/FromNegTwo/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Truncation/FromNegTwo/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.HITs.Truncation.FromNegTwo.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Equiv.PathSplit
open isPathSplitEquiv
open import Cubical.Modalities.Modality
open Modality
open import Cubical.Data.Empty as ⊥ using (⊥)
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.NatMinusOne as ℕ₋₁
open import Cubical.Data.Sigma
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.Susp.Base
open import Cubical.HITs.Nullification as Null hiding (rec; elim)
open import Cubical.HITs.Truncation.FromNegTwo.Base
open import Cubical.HITs.PropositionalTruncation as PropTrunc
renaming (∥_∥ to ∥_∥₁; ∣_∣ to ∣_∣₁; squash to squash₁) using ()
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂; ∣_∣₂; squash₂)
open import Cubical.HITs.GroupoidTruncation as GpdTrunc using (∥_∥₃; ∣_∣₃; squash₃)
open import Cubical.HITs.2GroupoidTruncation as 2GpdTrunc using (∥_∥₄; ∣_∣₄; squash₄)
private
variable
ℓ ℓ' : Level
A B : Type ℓ
sphereFill : (n : ℕ₋₁) (f : S n → A) → Type _
sphereFill {A = A} n f = Σ[ top ∈ A ] ((x : S n) → top ≡ f x)
isSphereFilled : ℕ₋₁ → Type ℓ → Type ℓ
isSphereFilled n A = (f : S n → A) → sphereFill n f
isSphereFilledTrunc : {n : HLevel} → isSphereFilled (-1+ n) (hLevelTrunc n A)
isSphereFilledTrunc {n = zero} f = hub f , ⊥.elim
isSphereFilledTrunc {n = suc n} f = hub f , spoke f
isSphereFilled→isOfHLevelSuc : {n : HLevel} → isSphereFilled (ℕ→ℕ₋₁ n) A → isOfHLevel (suc n) A
isSphereFilled→isOfHLevelSuc {A = A} {zero} h x y = sym (snd (h f) north) ∙ snd (h f) south
where
f : Susp ⊥ → A
f north = x
f south = y
isSphereFilled→isOfHLevelSuc {A = A} {suc n} h x y = isSphereFilled→isOfHLevelSuc (helper h x y)
where
helper : isSphereFilled (ℕ→ℕ₋₁ (suc n)) A → (x y : A) → isSphereFilled (ℕ→ℕ₋₁ n) (x ≡ y)
helper h x y f = sym p ∙ q , r
where
f' : Susp (S (ℕ→ℕ₋₁ n)) → A
f' north = x
f' south = y
f' (merid u i) = f u i
p = snd (h f') north
q = snd (h f') south
r : (s : S (ℕ→ℕ₋₁ n)) → sym p ∙ q ≡ f s
r s i j = hcomp (λ k → λ { (i = i0) → compPath-filler (sym p) q k j
; (i = i1) → snd (h f') (merid s j) k
; (j = i0) → p (k ∨ ~ i)
; (j = i1) → q k })
(p (~ i ∧ ~ j))
isOfHLevel→isSphereFilled : {n : HLevel} → isOfHLevel n A → isSphereFilled (-1+ n) A
isOfHLevel→isSphereFilled {n = zero} h f = fst h , λ _ → snd h _
isOfHLevel→isSphereFilled {n = suc zero} h f = f north , λ _ → h _ _
isOfHLevel→isSphereFilled {A = A} {suc (suc n)} h = helper λ x y → isOfHLevel→isSphereFilled (h x y)
where
helper : {n : HLevel} → ((x y : A) → isSphereFilled (-1+ n) (x ≡ y)) → isSphereFilled (suc₋₁ (-1+ n)) A
helper {n} h f = l , r
where
l : A
l = f north
f' : S (-1+ n) → f north ≡ f south
f' x i = f (merid x i)
h' : sphereFill (-1+ n) f'
h' = h (f north) (f south) f'
r : (x : S (suc₋₁ (-1+ n))) → l ≡ f x
r north = refl
r south = h' .fst
r (merid x i) j = hcomp (λ k → λ { (i = i0) → f north
; (i = i1) → h' .snd x (~ k) j
; (j = i0) → f north
; (j = i1) → f (merid x i) })
(f (merid x (i ∧ j)))
-- isNull (S n) A ≃ (isSphereFilled n A) × (∀ (x y : A) → isSphereFilled n (x ≡ y))
isOfHLevel→isSnNull : {n : HLevel} → isOfHLevel n A → isNull (S (-1+ n)) A
fst (sec (isOfHLevel→isSnNull h)) f = fst (isOfHLevel→isSphereFilled h f)
snd (sec (isOfHLevel→isSnNull h)) f i s = snd (isOfHLevel→isSphereFilled h f) s i
fst (secCong (isOfHLevel→isSnNull h) x y) p = fst (isOfHLevel→isSphereFilled (isOfHLevelPath _ h x y) (funExt⁻ p))
snd (secCong (isOfHLevel→isSnNull h) x y) p i j s = snd (isOfHLevel→isSphereFilled (isOfHLevelPath _ h x y) (funExt⁻ p)) s i j
isSnNull→isOfHLevel : {n : HLevel} → isNull (S (-1+ n)) A → isOfHLevel n A
isSnNull→isOfHLevel {n = zero} nA = fst (sec nA) ⊥.rec , λ y → fst (secCong nA _ y) (funExt ⊥.elim)
isSnNull→isOfHLevel {n = suc n} nA = isSphereFilled→isOfHLevelSuc (λ f → fst (sec nA) f , λ s i → snd (sec nA) f i s)
isOfHLevelTrunc : (n : HLevel) → isOfHLevel n (hLevelTrunc n A)
isOfHLevelTrunc zero = hub ⊥.rec , λ _ → ≡hub ⊥.rec
isOfHLevelTrunc (suc n) = isSphereFilled→isOfHLevelSuc isSphereFilledTrunc
-- isOfHLevelTrunc n = isSnNull→isOfHLevel isNull-Null
-- hLevelTrunc n is a modality
rec : {n : HLevel}
{B : Type ℓ'} →
isOfHLevel n B →
(A → B) →
hLevelTrunc n A →
B
rec h = Null.rec (isOfHLevel→isSnNull h)
elim : {n : HLevel}
{B : hLevelTrunc n A → Type ℓ'}
(hB : (x : hLevelTrunc n A) → isOfHLevel n (B x))
(g : (a : A) → B (∣ a ∣))
(x : hLevelTrunc n A) →
B x
elim hB = Null.elim (λ x → isOfHLevel→isSnNull (hB x))
elim2 : {n : HLevel}
{B : hLevelTrunc n A → hLevelTrunc n A → Type ℓ'}
(hB : ((x y : hLevelTrunc n A) → isOfHLevel n (B x y)))
(g : (a b : A) → B ∣ a ∣ ∣ b ∣)
(x y : hLevelTrunc n A) →
B x y
elim2 {n = n} hB g =
elim (λ _ → isOfHLevelΠ n (λ _ → hB _ _))
(λ a → elim (λ _ → hB _ _) (λ b → g a b))
elim3 : {n : HLevel}
{B : (x y z : hLevelTrunc n A) → Type ℓ'}
(hB : ((x y z : hLevelTrunc n A) → isOfHLevel n (B x y z)))
(g : (a b c : A) → B (∣ a ∣) ∣ b ∣ ∣ c ∣)
(x y z : hLevelTrunc n A) →
B x y z
elim3 {n = n} hB g =
elim2 (λ _ _ → isOfHLevelΠ n (hB _ _))
(λ a b → elim (λ _ → hB _ _ _) (λ c → g a b c))
HLevelTruncModality : ∀ {ℓ} (n : HLevel) → Modality ℓ
isModal (HLevelTruncModality n) = isOfHLevel n
isPropIsModal (HLevelTruncModality n) = isPropIsOfHLevel n
◯ (HLevelTruncModality n) = hLevelTrunc n
◯-isModal (HLevelTruncModality n) = isOfHLevelTrunc n
η (HLevelTruncModality n) = ∣_∣
◯-elim (HLevelTruncModality n) = elim
◯-elim-β (HLevelTruncModality n) = λ _ _ _ → refl
◯-=-isModal (HLevelTruncModality n) = isOfHLevelPath n (isOfHLevelTrunc n)
truncIdempotentIso : (n : HLevel) → isOfHLevel n A → Iso A (hLevelTrunc n A)
truncIdempotentIso n hA = isModalToIso (HLevelTruncModality n) hA
truncIdempotent≃ : (n : HLevel) → isOfHLevel n A → A ≃ hLevelTrunc n A
truncIdempotent≃ n hA = ∣_∣ , isModalToIsEquiv (HLevelTruncModality n) hA
truncIdempotent : (n : HLevel) → isOfHLevel n A → hLevelTrunc n A ≡ A
truncIdempotent n hA = ua (invEquiv (truncIdempotent≃ n hA))
-- universal property
univTrunc : ∀ {ℓ} (n : HLevel) {B : TypeOfHLevel ℓ n} → Iso (hLevelTrunc n A → B .fst) (A → B .fst)
Iso.fun (univTrunc n {B , lev}) g a = g ∣ a ∣
Iso.inv (univTrunc n {B , lev}) = elim λ _ → lev
Iso.rightInv (univTrunc n {B , lev}) b = refl
Iso.leftInv (univTrunc n {B , lev}) b = funExt (elim (λ x → isOfHLevelPath _ lev _ _)
λ a → refl)
-- functorial action
map : {n : HLevel} {B : Type ℓ'} (g : A → B)
→ hLevelTrunc n A → hLevelTrunc n B
map g = rec (isOfHLevelTrunc _) (λ a → ∣ g a ∣)
mapCompIso : {n : HLevel} {B : Type ℓ'} → (Iso A B) → Iso (hLevelTrunc n A) (hLevelTrunc n B)
Iso.fun (mapCompIso g) = map (Iso.fun g)
Iso.inv (mapCompIso g) = map (Iso.inv g)
Iso.rightInv (mapCompIso g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ b → cong ∣_∣ (Iso.rightInv g b)
Iso.leftInv (mapCompIso g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ a → cong ∣_∣ (Iso.leftInv g a)
mapId : {n : HLevel} → ∀ t → map {n = n} (idfun A) t ≡ t
mapId {n = n} =
elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) (λ _ → refl)
-- equivalences to prop/set/groupoid truncations
propTruncTrunc1Iso : Iso ∥ A ∥₁ (∥ A ∥ 1)
Iso.fun propTruncTrunc1Iso = PropTrunc.elim (λ _ → isOfHLevelTrunc 1) ∣_∣
Iso.inv propTruncTrunc1Iso = elim (λ _ → squash₁) ∣_∣₁
Iso.rightInv propTruncTrunc1Iso = elim (λ _ → isOfHLevelPath 1 (isOfHLevelTrunc 1) _ _) (λ _ → refl)
Iso.leftInv propTruncTrunc1Iso = PropTrunc.elim (λ _ → isOfHLevelPath 1 squash₁ _ _) (λ _ → refl)
propTrunc≃Trunc1 : ∥ A ∥₁ ≃ ∥ A ∥ 1
propTrunc≃Trunc1 = isoToEquiv propTruncTrunc1Iso
propTrunc≡Trunc1 : ∥ A ∥₁ ≡ ∥ A ∥ 1
propTrunc≡Trunc1 = ua propTrunc≃Trunc1
setTruncTrunc2Iso : Iso ∥ A ∥₂ (∥ A ∥ 2)
Iso.fun setTruncTrunc2Iso = SetTrunc.elim (λ _ → isOfHLevelTrunc 2) ∣_∣
Iso.inv setTruncTrunc2Iso = elim (λ _ → squash₂) ∣_∣₂
Iso.rightInv setTruncTrunc2Iso = elim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _) (λ _ → refl)
Iso.leftInv setTruncTrunc2Iso = SetTrunc.elim (λ _ → isOfHLevelPath 2 squash₂ _ _) (λ _ → refl)
setTrunc≃Trunc2 : ∥ A ∥₂ ≃ ∥ A ∥ 2
setTrunc≃Trunc2 = isoToEquiv setTruncTrunc2Iso
propTrunc≡Trunc2 : ∥ A ∥₂ ≡ ∥ A ∥ 2
propTrunc≡Trunc2 = ua setTrunc≃Trunc2
groupoidTrunc≃Trunc3Iso : Iso ∥ A ∥₃ (∥ A ∥ 3)
Iso.fun groupoidTrunc≃Trunc3Iso = GpdTrunc.elim (λ _ → isOfHLevelTrunc 3) ∣_∣
Iso.inv groupoidTrunc≃Trunc3Iso = elim (λ _ → squash₃) ∣_∣₃
Iso.rightInv groupoidTrunc≃Trunc3Iso = elim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) (λ _ → refl)
Iso.leftInv groupoidTrunc≃Trunc3Iso = GpdTrunc.elim (λ _ → isOfHLevelPath 3 squash₃ _ _) (λ _ → refl)
groupoidTrunc≃Trunc3 : ∥ A ∥₃ ≃ ∥ A ∥ 3
groupoidTrunc≃Trunc3 = isoToEquiv groupoidTrunc≃Trunc3Iso
groupoidTrunc≡Trunc3 : ∥ A ∥₃ ≡ ∥ A ∥ 3
groupoidTrunc≡Trunc3 = ua groupoidTrunc≃Trunc3
2GroupoidTrunc≃Trunc4Iso : Iso ∥ A ∥₄ (∥ A ∥ 4)
Iso.fun 2GroupoidTrunc≃Trunc4Iso = 2GpdTrunc.elim (λ _ → isOfHLevelTrunc 4) ∣_∣
Iso.inv 2GroupoidTrunc≃Trunc4Iso = elim (λ _ → squash₄) ∣_∣₄
Iso.rightInv 2GroupoidTrunc≃Trunc4Iso = elim (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _) (λ _ → refl)
Iso.leftInv 2GroupoidTrunc≃Trunc4Iso = 2GpdTrunc.elim (λ _ → isOfHLevelPath 4 squash₄ _ _) (λ _ → refl)
2GroupoidTrunc≃Trunc4 : ∥ A ∥₄ ≃ ∥ A ∥ 4
2GroupoidTrunc≃Trunc4 =
isoToEquiv
(iso
(2GpdTrunc.elim (λ _ → isOfHLevelTrunc 4) ∣_∣)
(elim (λ _ → squash₄) ∣_∣₄)
(elim (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _) (λ _ → refl))
(2GpdTrunc.elim (λ _ → isOfHLevelPath 4 squash₄ _ _) (λ _ → refl)))
2GroupoidTrunc≡Trunc4 : ∥ A ∥₄ ≡ ∥ A ∥ 4
2GroupoidTrunc≡Trunc4 = ua 2GroupoidTrunc≃Trunc4
isContr→isContrTrunc : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isContr A → isContr (hLevelTrunc n A)
isContr→isContrTrunc n contr = ∣ fst contr ∣ , (elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) λ a → cong ∣_∣ (snd contr a))
truncOfProdIso : (n : ℕ) → Iso (hLevelTrunc n (A × B)) (hLevelTrunc n A × hLevelTrunc n B)
Iso.fun (truncOfProdIso n) = rec (isOfHLevelΣ n (isOfHLevelTrunc n) (λ _ → isOfHLevelTrunc n)) λ {(a , b) → ∣ a ∣ , ∣ b ∣}
Iso.inv (truncOfProdIso n) (a , b) = rec (isOfHLevelTrunc n)
(λ a → rec (isOfHLevelTrunc n)
(λ b → ∣ a , b ∣)
b)
a
Iso.rightInv (truncOfProdIso n) (a , b) =
elim {B = λ a → Iso.fun (truncOfProdIso n) (Iso.inv (truncOfProdIso n) (a , b)) ≡ (a , b)}
(λ _ → isOfHLevelPath n (isOfHLevelΣ n (isOfHLevelTrunc n) (λ _ → isOfHLevelTrunc n)) _ _)
(λ a → elim {B = λ b → Iso.fun (truncOfProdIso n) (Iso.inv (truncOfProdIso n) (∣ a ∣ , b)) ≡ (∣ a ∣ , b)}
(λ _ → isOfHLevelPath n (isOfHLevelΣ n (isOfHLevelTrunc n) (λ _ → isOfHLevelTrunc n)) _ _)
(λ b → refl) b) a
Iso.leftInv (truncOfProdIso n) = elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) λ a → refl
---- ∥ Ω A ∥ ₙ ≡ Ω ∥ A ∥ₙ₊₁ ----
isOfHLevelTypeOfHLevel2 : ∀ n → isOfHLevel (suc n) (TypeOfHLevel ℓ n)
isOfHLevelTypeOfHLevel2 n = isOfHLevelTypeOfHLevel n
{- Proofs of Theorem 7.3.12. and Corollary 7.3.13. in the HoTT book -}
module ΩTrunc where
{- We define the fibration P to show a more general result -}
P : {X : Type ℓ} {n : HLevel} → ∥ X ∥ (suc n) → ∥ X ∥ (suc n) → Type ℓ
P {n = n} x y = elim2 (λ _ _ → isOfHLevelTypeOfHLevel2 (n))
(λ a b → ∥ a ≡ b ∥ n , isOfHLevelTrunc (n)) x y .fst
{- We will need P to be of hLevel n + 3 -}
hLevelP : {n : HLevel} (a b : ∥ B ∥ (suc n)) → isOfHLevel ((suc n)) (P a b)
hLevelP {n = n} =
elim2 (λ x y → isProp→isOfHLevelSuc (n) (isPropIsOfHLevel (suc n)))
(λ a b → isOfHLevelSuc (n) (isOfHLevelTrunc (n)))
{- decode function from P x y to x ≡ y -}
decode-fun : {n : HLevel} (x y : ∥ B ∥ (suc n)) → P x y → x ≡ y
decode-fun {n = n} =
elim2 (λ u v → isOfHLevelΠ (suc n)
(λ _ → isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n)) u v))
decode*
where
decode* : ∀ {n : HLevel} (u v : B)
→ P {n = n} ∣ u ∣ ∣ v ∣ → Path (∥ B ∥ (suc n)) ∣ u ∣ ∣ v ∣
decode* {B = B} {n = zero} u v =
rec ( isOfHLevelTrunc 1 ∣ u ∣ ∣ v ∣
, λ _ → isOfHLevelSuc 1 (isOfHLevelTrunc 1) _ _ _ _) (cong ∣_∣)
decode* {n = suc n} u v =
rec (isOfHLevelTrunc (suc (suc n)) ∣ u ∣ ∣ v ∣) (cong ∣_∣)
{- auxiliary function r used to define encode -}
r : {m : HLevel} (u : ∥ B ∥ (suc m)) → P u u
r = elim (λ x → hLevelP x x) (λ a → ∣ refl ∣)
{- encode function from x ≡ y to P x y -}
encode-fun : {n : HLevel} (x y : ∥ B ∥ (suc n)) → x ≡ y → P x y
encode-fun x y p = transport (λ i → P x (p i)) (r x)
{- We need the following two lemmas on the functions behaviour for refl -}
dec-refl : {n : HLevel} (x : ∥ B ∥ (suc n)) → decode-fun x x (r x) ≡ refl
dec-refl {n = zero} =
elim (λ x → isOfHLevelSuc 1 (isOfHLevelSuc 1 (isOfHLevelTrunc 1) x x) _ _) (λ _ → refl)
dec-refl {n = suc n} =
elim (λ x → isOfHLevelSuc (suc n)
(isOfHLevelSuc (suc n)
(isOfHLevelTrunc (suc (suc n)) x x)
(decode-fun x x (r x)) refl))
(λ _ → refl)
enc-refl : {n : HLevel} (x : ∥ B ∥ (suc n)) → encode-fun x x refl ≡ r x
enc-refl x j = transp (λ _ → P x x) j (r x)
{- decode-fun is a right-inverse -}
P-rinv : {n : HLevel} (u v : ∥ B ∥ (suc n)) (x : Path (∥ B ∥ (suc n)) u v)
→ decode-fun u v (encode-fun u v x) ≡ x
P-rinv u v = J (λ y p → decode-fun u y (encode-fun u y p) ≡ p)
(cong (decode-fun u u) (enc-refl u) ∙ dec-refl u)
{- decode-fun is a left-inverse -}
P-linv : {n : HLevel} (u v : ∥ B ∥ (suc n )) (x : P u v)
→ encode-fun u v (decode-fun u v x) ≡ x
P-linv {n = n} =
elim2 (λ x y → isOfHLevelΠ (suc n)
(λ z → isOfHLevelSuc (suc n) (hLevelP x y) _ _))
helper
where
helper : {n : HLevel} (a b : B) (p : P {n = n} ∣ a ∣ ∣ b ∣)
→ encode-fun _ _ (decode-fun ∣ a ∣ ∣ b ∣ p) ≡ p
helper {n = zero} a b =
elim (λ x → ( sym (isOfHLevelTrunc 0 .snd _) ∙ isOfHLevelTrunc 0 .snd x
, λ y → isOfHLevelSuc 1 (isOfHLevelSuc 0 (isOfHLevelTrunc 0)) _ _ _ _))
(J (λ y p → encode-fun ∣ a ∣ ∣ y ∣ (decode-fun _ _ ∣ p ∣) ≡ ∣ p ∣)
(enc-refl ∣ a ∣))
helper {n = suc n} a b =
elim (λ x → hLevelP {n = suc n} ∣ a ∣ ∣ b ∣ _ _)
(J (λ y p → encode-fun {n = suc n} ∣ a ∣ ∣ y ∣ (decode-fun _ _ ∣ p ∣) ≡ ∣ p ∣)
(enc-refl ∣ a ∣))
{- The final Iso established -}
IsoFinal : (n : HLevel) (x y : ∥ B ∥ (suc n)) → Iso (x ≡ y) (P x y)
Iso.fun (IsoFinal _ x y) = encode-fun x y
Iso.inv (IsoFinal _ x y) = decode-fun x y
Iso.rightInv (IsoFinal _ x y) = P-linv x y
Iso.leftInv (IsoFinal _ x y) = P-rinv x y
PathIdTrunc : {a b : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ b ∣) ≡ (∥ a ≡ b ∥ n)
PathIdTrunc n = isoToPath (ΩTrunc.IsoFinal n _ _)
PathΩ : {a : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ a ∣) ≡ (∥ a ≡ a ∥ n)
PathΩ n = PathIdTrunc n
{- Special case using direct defs of truncations -}
PathIdTrunc₀Iso : {a b : A} → Iso (∣ a ∣₂ ≡ ∣ b ∣₂) ∥ a ≡ b ∥₁
PathIdTrunc₀Iso = compIso (congIso setTruncTrunc2Iso)
(compIso (ΩTrunc.IsoFinal _ ∣ _ ∣ ∣ _ ∣)
(invIso propTruncTrunc1Iso))
-------------------------
truncOfTruncIso : (n m : HLevel) → Iso (hLevelTrunc n A) (hLevelTrunc n (hLevelTrunc (m + n) A))
Iso.fun (truncOfTruncIso n m) = elim (λ _ → isOfHLevelTrunc n) λ a → ∣ ∣ a ∣ ∣
Iso.inv (truncOfTruncIso {A = A} n m) =
elim (λ _ → isOfHLevelTrunc n)
(elim (λ _ → (isOfHLevelPlus m (isOfHLevelTrunc n )))
λ a → ∣ a ∣)
Iso.rightInv (truncOfTruncIso {A = A} n m) =
elim (λ x → isOfHLevelPath n (isOfHLevelTrunc n) _ _ )
(elim (λ x → isOfHLevelPath (m + n) (isOfHLevelPlus m (isOfHLevelTrunc n)) _ _ )
λ a → refl)
Iso.leftInv (truncOfTruncIso n m) = elim (λ x → isOfHLevelPath n (isOfHLevelTrunc n) _ _) λ a → refl
truncOfTruncEq : (n m : ℕ) → (hLevelTrunc n A) ≃ (hLevelTrunc n (hLevelTrunc (m + n) A))
truncOfTruncEq n m = isoToEquiv (truncOfTruncIso n m)
| 43.156171
| 131
| 0.578941
|
1d3b91efac9fafc4ca7da5b723e211a23550949f
| 42
|
agda
|
Agda
|
test/interaction/Issue2575/M.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue2575/M.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue2575/M.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue2575.M where
A : Set
A = Set
| 8.4
| 24
| 0.690476
|
c550636fac3ae484d68797d417661df18de1d718
| 26,076
|
agda
|
Agda
|
agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex2.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex2.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex2.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
{-# OPTIONS --type-in-type #-} -- yes, I will let you cheat in this exercise
{-# OPTIONS --allow-unsolved-metas #-} -- allows import, unfinished
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- CS410 2017/18 Exercise 2 CATEGORIES AND MONADS (worth 50%)
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- NOTE (19/10/17) This file is currently incomplete: more will arrive on
-- GitHub.
-- NOTE (29/10/17) All components are now present.
-- REFLECTION: When I started setting this exercise, I intended it as a
-- normal size 25% exercise, but it grew and grew, as did the struggles of
-- the students. I accepted that I had basically set two exercises in one
-- file and revalued it as such.
------------------------------------------------------------------------------
-- Dependencies
------------------------------------------------------------------------------
open import CS410-Prelude
open import CS410-Categories
open import Ex1
------------------------------------------------------------------------------
-- Categorical Jigsaws (based on Ex1)
------------------------------------------------------------------------------
-- In this section, most of the work has already happened. All you have to do
-- is assemble the collection of things you did into Ex1 into neat categorical
-- packaging.
--??--2.1-(4)-----------------------------------------------------------------
OPE : Category -- The category of order-preserving embeddings...
OPE = record
{ Obj = Nat -- ...has numbers as objects...
; _~>_ = _<=_ -- ...and "thinnings" as arrows.
-- Now, assemble the rest of the components.
; id~> = {!!}
; _>~>_ = {!!}
; law-id~>>~> = {!!}
; law->~>id~> = {!!}
; law->~>>~> = {!!}
}
VEC : Nat -> SET => SET -- Vectors of length n...
VEC n = record
{ F-Obj = \ X -> Vec X n -- ...give a functor from SET to SET...
; F-map = \ f xs -> vMap f xs -- ...doing vMap to arrows.
-- Now prove the laws.
; F-map-id~> = extensionality \ xs -> {!!}
; F-map->~> = \ f g -> extensionality \ xs -> {!!}
}
Op : Category -> Category -- Every category has an opposite...
Op C = record
{ Obj = Obj -- ...with the same objects, but...
; _~>_ = \ S T -> T ~> S -- ...arrows that go backwards!
-- Now, find the rest!
; id~> = {!!}
; _>~>_ = {!!}
; law-id~>>~> = {!!}
; law->~>id~> = {!!}
; law->~>>~> = {!!}
} where open Category C
CHOOSE : Set -> OPE => Op SET -- Show that thinnings from n to m...
CHOOSE X = record -- ...act by selection...
{ F-Obj = Vec X -- ...to cut vectors down from m to n.
; F-map = {!!}
; F-map-id~> = extensionality {!!}
; F-map->~> = \ f g -> extensionality {!!}
}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- The List Monad (a warm-up)
------------------------------------------------------------------------------
-- The declaration of List has been added to the CS410-Prelude file:
-- data List (X : Set) : Set where
-- [] : List X
-- _,-_ : (x : X)(xs : List X) -> List X
-- infixr 4 _,-_
-- Appending two lists is rather well known, so I'll not ask you to write it.
_+L_ : {X : Set} -> List X -> List X -> List X
[] +L ys = ys
(x ,- xs) +L ys = x ,- (xs +L ys)
infixr 4 _+L_
-- But I will ask you to find some structure for it.
--??--2.2-(3)-----------------------------------------------------------------
LIST-MONOID : Set -> Category
LIST-MONOID X = -- Show that _+L_ is the operation of a monoid,...
record
{ Obj = One -- ... i.e., a category with one object.
; _~>_ = {!!}
; id~> = {!!}
; _>~>_ = {!!}
; law-id~>>~> = {!!}
; law->~>id~> = {!!}
; law->~>>~> = {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- Next, functoriality of lists. Given a function on elements, show how to
-- apply that function to all the elements of a list. (Haskell calls this
-- operation "map".)
--??--2.3-(3)-----------------------------------------------------------------
list : {X Y : Set} -> (X -> Y) -> List X -> List Y
list f xs = {!!}
LIST : SET => SET
LIST = record
{ F-Obj = List
; F-map = list
; F-map-id~> = extensionality {!!}
; F-map->~> = \ f g -> extensionality {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- Moreover, applying a function elementwise should respect appending.
--??--2.4-(3)-----------------------------------------------------------------
LIST+L : {X Y : Set}(f : X -> Y) -> LIST-MONOID X => LIST-MONOID Y
LIST+L {X}{Y} f = record
{ F-Obj = id
; F-map = list f -- this yellow will go once LIST-MONOID has arrows!
; F-map-id~> = {!!}
; F-map->~> = {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- Next, we have two very important "natural transformations".
--??--2.5-(1)-----------------------------------------------------------------
SINGLE : ID ~~> LIST
SINGLE = record
{ xf = \ x -> x ,- [] -- turn a value into a singleton list
; naturality = \ f -> {!!}
}
--??--------------------------------------------------------------------------
-- Here, naturality means that it doesn't matter
-- whether you apply a function f, then make a singleton list
-- or you make a singleton list, then apply f to all (one of) its elements.
-- Now, define the operation that concatenates a whole list of lists, and
-- show that it, too, is natural. That is, it doesn't matter whether you
-- transform the elements (two layers inside) then concatenate, or you
-- concatenate, then transform the elements.
--??--2.6-(3)-----------------------------------------------------------------
concat : {X : Set} -> List (List X) -> List X
concat xss = {!!}
CONCAT : (LIST >=> LIST) ~~> LIST
CONCAT = record
{ xf = concat
; naturality = {!!}
} where
-- useful helper proofs (lemmas) go here
--??--------------------------------------------------------------------------
-- You've nearly built your first monad! You just need to prove that
-- single and concat play nicely with each other.
--??--2.7-(4)-----------------------------------------------------------------
module LIST-MONAD where
open MONAD LIST public
ListMonad : Monad
ListMonad = record
{ unit = SINGLE
; mult = CONCAT
; unitMult = {!!}
; multUnit = {!!}
; multMult = {!!}
} where
-- useful helper proofs (lemmas) go here
-- open LIST-MONAD
--??--------------------------------------------------------------------------
-- More monads to come...
------------------------------------------------------------------------------
-- Categories of Indexed Sets
------------------------------------------------------------------------------
-- We can think of some
-- P : I -> Set
-- as a collection of sets indexed by I, such that
-- P i
-- means "exactly the P-things which fit with i".
-- You've met
-- Vec X : Nat -> Set
-- where
-- Vec X n
-- means "exactly the vectors which fit with n".
-- Now, given two such collections, S and T, we can make a collection
-- of function types: the functions which fit with i map the
-- S-things which fit with i to the T-things which fit with i.
_-:>_ : {I : Set} -> (I -> Set) -> (I -> Set) -> (I -> Set)
(S -:> T) i = S i -> T i
-- So, (Vec X -:> Vec Y) n contains the functions which turn
-- n Xs into n Ys.
-- Next, if we know such a collection of sets, we can claim to have
-- one for each index.
[_] : {I : Set} -> (I -> Set) -> Set
[ P ] = forall i -> P i -- [_] {I} P = (i : I) -> P i
-- E.g., [ Vec X -:> Vec Y ] is the type of functions from X-vectors
-- to Y-vectors which preserve length.
-- For any such I, we get a category of indexed sets with index-preserving
-- functions.
_->SET : Set -> Category
I ->SET = record
{ Obj = I -> Set -- I-indexed sets
; _~>_ = \ S T -> [ S -:> T ] -- index-respecting functions
; id~> = \ i -> id -- the identity at every index
; _>~>_ = \ f g i -> f i >> g i -- composition at every index
; law-id~>>~> = refl -- and the laws are very boring
; law->~>id~> = refl
; law->~>>~> = \ f g h -> refl _
}
-- In fact, we didn't need to choose SET here. We could do this construction
-- for any category: index the objects; index the morphisms.
-- But SET is plenty to be getting on with.
-- Now, let me define an operation that makes types from lists.
All : {X : Set} -> (X -> Set) -> (List X -> Set)
All P [] = One
All P (x ,- xs) = P x * All P xs
-- The idea is that we get a tuple of P-things: one for each list element.
-- So
-- All P (1 ,- 2 ,- 3 ,- [])
-- = P 1 * P 2 * P 3 * One
-- Note that if you think of List One as a version of Nat,
-- All becomes a lot like Vec.
copy : Nat -> List One
copy zero = []
copy (suc n) = <> ,- copy n
VecCopy : Set -> Nat -> Set
VecCopy X n = All (\ _ -> X) (copy n)
-- Now, your turn...
--??--2.8-(4)-----------------------------------------------------------------
-- Show that, for any X, All induces a functor
-- from (X ->SET) to (List X ->SET)
all : {X : Set}{S T : X -> Set} ->
[ S -:> T ] -> [ All S -:> All T ]
all f xs ss = {!!}
ALL : (X : Set) -> (X ->SET) => (List X ->SET)
ALL X = record
{ F-Obj = All
; F-map = all
; F-map-id~> = {!!}
; F-map->~> = {!!}
} where
-- useful helper facts go here
--??--------------------------------------------------------------------------
-- ABOVE THIS LINE, 25%
-- BELOW THIS LINE, 25%
------------------------------------------------------------------------------
-- Cutting Things Up
------------------------------------------------------------------------------
-- Next, we're going to develop a very general technique for building
-- data structures.
-- We may think of an I |> O as a way to "cut O-shapes into I-shaped pieces".
-- The pointy end points to the type being cut; the flat end to the type of
-- pieces.
record _|>_ (I O : Set) : Set where
field
Cuts : O -> Set -- given o : O, how may we cut it?
inners : {o : O} -> Cuts o -> List I -- given how we cut it, what are
-- the shapes of its pieces?
-- Let us have some examples right away!
VecCut : One |> Nat -- cut numbers into boring pieces
VecCut = record
{ Cuts = \ n -> One -- there is one way to cut n
; inners = \ {n} _ -> copy n -- and you get n pieces
}
-- Here's a less boring example. You can cut a number into *two* pieces
-- by finding two numbers that add to it.
NatCut : Nat |> Nat
NatCut = record
{ Cuts = \ mn -> Sg Nat \ m -> Sg Nat \ n -> (m +N n) == mn
; inners = \ { (m , n , _) -> m ,- n ,- [] }
}
-- The point is that we can make data structures that record how we
-- built an O-shaped thing from I-shaped pieces.
record Cutting {I O}(C : I |> O)(P : I -> Set)(o : O) : Set where
constructor _8><_ -- "scissors"
open _|>_ C
field
cut : Cuts o -- we decide how to cut o
pieces : All P (inners cut) -- then we give all the pieces.
infixr 3 _8><_
-- For example...
VecCutting : Set -> Nat -> Set
VecCutting X = Cutting VecCut (\ _ -> X)
myVecCutting : VecCutting Char 5
myVecCutting = <> 8>< 'h' , 'e' , 'l' , 'l' , 'o' , <>
-- Or, if you let me fiddle about with strings for a moment,...
length : {X : Set} -> List X -> Nat
length [] = zero
length (x ,- xs) = suc (length xs)
listVec : {X : Set}(xs : List X) -> Vec X (length xs)
listVec [] = []
listVec (x ,- xs) = x ,- listVec xs
strVec : (s : String) -> Vec Char (length (primStringToList s))
strVec s = listVec (primStringToList s)
-- ...an example of cutting a number in two, with vector pieces.
footprints : Cutting NatCut (Vec Char) 10
footprints = (4 , 6 , refl 10) 8>< strVec "foot"
, strVec "prints"
, <>
-- Now, let me direct you to the =$ operator, now in CS410-Prelude.agda,
-- which you may find helps with the proofs in the following.
--??--2.9-(3)-----------------------------------------------------------------
-- Using what you already built for ALL, show that every Cutting C gives us
-- a functor between categories of indexed sets.
CUTTING : {I O : Set}(C : I |> O) -> (I ->SET) => (O ->SET)
CUTTING {I}{O} C = record
{ F-Obj = Cutting C
; F-map = {!!}
; F-map-id~> = extensionality \ o -> extensionality \ { (c 8>< ps) ->
{!!} }
; F-map->~> = \ f g ->
extensionality \ o -> extensionality \ { (c 8>< ps) ->
{!!} }
} where
open _|>_ C
open _=>_ (ALL I)
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Interiors
------------------------------------------------------------------------------
-- Next, let me define the notion of an algebra for a given functor in C => C
module ALGEBRA {C : Category}(F : C => C) where
open Category C
open _=>_ F
Algebra : (X : Obj) -> Set -- we call X the "carrier" of the algebra...
Algebra X = F-Obj X ~> X -- ...and we explain how to turn a bunch of Xs
-- into one
open ALGEBRA
-- Some week, we'll build categories whose objects are algebras. Not this week.
-- Instead, let's work with them a bit.
-- If we know a way to cut I-shapes into I-shaped pieces, we can build the
-- ways to "tile" an I with I-shaped T-tiles.
data Interior {I}(C : I |> I)(T : I -> Set)(i : I) : Set where
-- either...
tile : T i -> Interior C T i -- we have a tile that fits, or...
<_> : Cutting C (Interior C T) i -> -- ...we cut, then tile the pieces.
Interior C T i
-- Let me give you an example of an interior.
subbookkeeper : Interior NatCut (Vec Char) 13
subbookkeeper = < (3 , 10 , refl _)
8>< tile (strVec "sub")
, < (4 , 6 , refl _)
8>< tile (strVec "book")
, tile (strVec "keeper")
, <> >
, <> >
-- We make a 13-interior from
-- a 3-tile and a 10-interior made from a 4-tile and a 6-tile.
-- Guess what? Interior C is always a Monad! We'll get there.
module INTERIOR {I : Set}{C : I |> I} where -- fix some C...
open _|>_ C -- ...and open it
open module I->SET {I : Set} = Category (I ->SET) -- work in I ->SET
-- tile gives us an arrow from T into Interior C T
tile' : {T : I -> Set} -> [ T -:> Interior C T ]
tile' i = tile
-- <_> gives us an algebra!
cut' : {T : I -> Set} -> Algebra (CUTTING C) (Interior C T)
cut' i = <_>
-- Now, other (CUTTING C) algebras give us operators on interiors.
module INTERIORFOLD {P Q : I -> Set} where
interiorFold :
[ P -:> Q ] -> -- if we can turn a P into a Q...
Algebra (CUTTING C) Q -> -- ...and a bunch of Qs into a Q...
[ Interior C P -:> Q ] -- ...we can turn an interior of Ps into a Q
allInteriorFold : -- annoyingly, we'll need a specialized "all"
[ P -:> Q ] ->
Algebra (CUTTING C) Q ->
[ All (Interior C P) -:> All Q ]
interiorFold pq qalg i (tile p) = pq i p
interiorFold pq qalg i < c 8>< pis > =
qalg i (c 8>< allInteriorFold pq qalg (inners c) pis)
-- recursively turn all the sub-interiors into Qs
allInteriorFold pq qalg [] <> = <>
allInteriorFold pq qalg (i ,- is) (pi , pis) =
interiorFold pq qalg i pi , allInteriorFold pq qalg is pis
-- The trouble is that if you use
-- all (interiorFold pq qalg)
-- to process the sub-interiors, the termination checker complains.
-- But if you've built "all" correctly, you should be able to prove this:
--??--2.10-(2)----------------------------------------------------------------
allInteriorFoldLaw : (pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q) ->
allInteriorFold pq qalg == all (interiorFold pq qalg)
allInteriorFoldLaw pq qalg = extensionality \ is -> extensionality \ ps ->
{!!}
where
-- helper lemmas go here
--??--------------------------------------------------------------------------
-- Now, do me a favour and prove this extremely useful fact.
-- Its purpose is to bottle the inductive proof method for functions
-- built with interiorFold.
--??--2.11-(3)----------------------------------------------------------------
interiorFoldLemma :
(pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q)
(f : [ Interior C P -:> Q ]) ->
((i : I)(p : P i) -> pq i p == f i (tile p)) ->
((i : I)(c : Cuts i)(ps : All (Interior C P) (inners c)) ->
qalg i (c 8>< all f (inners c) ps) == f i < c 8>< ps >) ->
(i : I)(pi : Interior C P i) -> interiorFold pq qalg i pi == f i pi
interiorFoldLemma pq qalg f base step i pi = {!!}
--??--------------------------------------------------------------------------
-- We'll use it in this form:
interiorFoldLaw : (pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q)
(f : [ Interior C P -:> Q ]) ->
((i : I)(p : P i) -> pq i p == f i (tile p)) ->
((i : I)(c : Cuts i)(ps : All (Interior C P) (inners c)) ->
qalg i (c 8>< all f (inners c) ps) == f i < c 8>< ps >) ->
interiorFold pq qalg == f
interiorFoldLaw pq qalg f base step =
extensionality \ i -> extensionality \ pi ->
interiorFoldLemma pq qalg f base step i pi
open INTERIORFOLD
-- Let me pay you back immediately!
-- An interiorBind is an interiorFold which computes an Interior,
-- rewrapping each layer with < ... >
interiorBind : {X Y : I -> Set} ->
[ X -:> Interior C Y ] -> [ Interior C X -:> Interior C Y ]
interiorBind f = interiorFold f (\ i -> <_>)
-- Because an interiorBind *makes* an interior, we can say something useful
-- about what happens if we follow it with an interiorFold.
interiorBindFusion : {X Y Z : I -> Set} ->
(f : [ X -:> Interior C Y ])
(yz : [ Y -:> Z ])(zalg : Algebra (CUTTING C) Z) ->
(interiorBind f >~> interiorFold yz zalg) ==
interiorFold (f >~> interiorFold yz zalg) zalg
-- That is, we can "fuse" the two together, making one interiorFold.
-- I'll do the proof as it's a bit hairy. You've given me all I need.
-- Note that I don't use extensionality, just laws that relate functions.
interiorBindFusion f yz zalg =
(interiorBind f >~> interiorFold yz zalg)
=< interiorFoldLaw
(f >~> interiorFold yz zalg) zalg
(interiorBind f >~> interiorFold yz zalg)
(\ i p -> refl (interiorFold yz zalg i (f i p)))
(\ i c ps -> refl (zalg i) =$= (refl (c 8><_) =$= (
((all (interiorBind f >~> interiorFold yz zalg)
=[ F-map->~> (interiorBind f) (interiorFold yz zalg) >=
(all (interiorBind f) >~> all (interiorFold yz zalg))
=< refl _>~>_
=$= allInteriorFoldLaw f cut'
=$= allInteriorFoldLaw yz zalg ]=
allInteriorFold f (\ i -> <_>) >~> allInteriorFold yz zalg [QED])
=$ inners c =$= refl ps))))
]=
interiorFold (f >~> interiorFold yz zalg) zalg [QED]
where open _=>_ (ALL I)
-- You should find that a very useful piece of kit. In fact, you should
-- not need extensionality, either.
-- We need Interior C to be a functor.
--??--2.12-(5)----------------------------------------------------------------
-- using interiorBind, implement the "F-map" for Interiors as a one-liner
interior : {X Y : I -> Set} ->
[ X -:> Y ] -> [ Interior C X -:> Interior C Y ]
interior f = {!!}
-- using interiorBindFusion, prove the following law for "fold after map"
interiorFoldFusion : {P Q R : I -> Set}
(pq : [ P -:> Q ])(qr : [ Q -:> R ])(ralg : Algebra (CUTTING C) R) ->
(interior pq >~> interiorFold qr ralg) == interiorFold (pq >~> qr) ralg
interiorFoldFusion pq qr ralg =
interior pq >~> interiorFold qr ralg
=[ {!!} >=
interiorFold (pq >~> qr) ralg [QED]
where open _=>_ (ALL I)
-- and now, using interiorFoldFusion if it helps,
-- complete the functor construction
INTERIOR : (I ->SET) => (I ->SET)
INTERIOR = record
{ F-Obj = Interior C
; F-map = interior
; F-map-id~> = {!!}
; F-map->~> = {!!}
} where open _=>_ (ALL I)
--??--------------------------------------------------------------------------
-- Now let's build the Monad.
-- You should find that all the laws you have to prove follow from the
-- fusion laws you already have.
open MONAD INTERIOR
--??--2.13-(5)----------------------------------------------------------------
WRAP : ID ~~> INTERIOR
WRAP = record
{ xf = {!!}
; naturality = {!!}
}
-- use interiorBind to define the following
FLATTEN : (INTERIOR >=> INTERIOR) ~~> INTERIOR
FLATTEN = record
{ xf = {!!}
; naturality = {!!}
}
INTERIOR-Monad : Monad
INTERIOR-Monad = record
{ unit = WRAP
; mult = FLATTEN
; unitMult = {!!}
; multUnit = {!!}
; multMult = {!!}
} where
open _=>_ INTERIOR
--??--------------------------------------------------------------------------
open INTERIOR
open INTERIORFOLD
-- You should be able to define an algebra on vectors for NatCut, using +V
--??--2.14-(2)----------------------------------------------------------------
NatCutVecAlg : {X : Set} -> Algebra (CUTTING NatCut) (Vec X)
NatCutVecAlg n xsc = {!!}
--??--------------------------------------------------------------------------
-- Check that it puts things together suitably when you evaluate this:
test1 : Vec Char 13
test1 = interiorFold (\ _ -> id) NatCutVecAlg 13 subbookkeeper
------------------------------------------------------------------------------
-- Cutting Up Pairs
------------------------------------------------------------------------------
module CHOICE where
open _|>_
--??--2.15-(2)----------------------------------------------------------------
-- Show that if you can cut up I and cut up J, then you can cut up I * J.
-- You now have two dimensions (I and J). The idea is that you choose one
-- dimension in which to make a cut, and keep everything in the other
-- dimension the same.
_+C_ : {I J : Set} -> I |> I -> J |> J -> (I * J) |> (I * J)
Cuts (P +C Q) (i , j) = Cuts P i + Cuts Q j
inners (P +C Q) = {!!}
--??--------------------------------------------------------------------------
open CHOICE
-- That should get us the ability to cut up *rectangules* by cutting either
-- vertically or horizontally.
NatCut2D : (Nat * Nat) |> (Nat * Nat)
NatCut2D = NatCut +C NatCut
Matrix : Set -> Nat * Nat -> Set
Matrix X (w , h) = Vec (Vec X w) h
-- If you've done it right, you should find that the following typechecks.
-- It's the interior of a rectangle, tiled with matrices of characters.
rectangle : Interior NatCut2D (Matrix Char) (15 , 6)
rectangle = < inr (4 , 2 , refl _)
8>< < inl (7 , 8 , refl _)
8>< tile (strVec "seventy"
,- strVec "kitchen"
,- strVec "program"
,- strVec "mistake"
,- [])
, tile (strVec "thousand"
,- strVec "soldiers"
,- strVec "probably"
,- strVec "undefine"
,- [])
, <> >
, tile (strVec "acknowledgement"
,- strVec "procrastination"
,- [])
, <> >
-- Later, we'll use rectangular interiors as the underlying data structure
-- for a window manager.
-- But for now, one last thing.
--??--2.16-(4)----------------------------------------------------------------
-- Show that if you have a vector of n Ps for every element of a list,
-- then you can make a vector of n (All P)s .
-- Hint: Ex1 provides some useful equipment for this job.
vecAll : {I : Set}{P : I -> Set}{is : List I}{n : Nat} ->
All (\ i -> Vec (P i) n) is -> Vec (All P is) n
vecAll {is = is} pss = {!!}
-- Given vecAll, show that algebra for any cutting can be lifted
-- to an algebra on vectors.
VecLiftAlg : {I : Set}(C : I |> I){X : I -> Set}
(alg : Algebra (CUTTING C) X){n : Nat} ->
Algebra (CUTTING C) (\ i -> Vec (X i) n)
VecLiftAlg C alg i (c 8>< pss) = {!!}
-- Now show that you can build an algebra for matrices
-- which handles cuts in either dimension,
-- combining them either horizontally or vertically!
NatCut2DMatAlg : {X : Set} -> Algebra (CUTTING NatCut2D) (Matrix X)
NatCut2DMatAlg _ (inl c 8>< ms) = {!!}
NatCut2DMatAlg _ (inr c 8>< ms) = {!!}
--??--------------------------------------------------------------------------
-- And that should give you a way to glue pictures together from interiors.
picture : [ Interior NatCut2D (Matrix Char) -:> Matrix Char ]
picture = interiorFold (\ _ -> id) NatCut2DMatAlg
-- You should be able to check that the following gives you something
-- sensible:
test2 = picture _ rectangle
| 33.559846
| 79
| 0.473501
|
0e37a2bd81294b6183406c3c34359903c19ee33a
| 12,799
|
agda
|
Agda
|
Cubical/Algebra/Group/MorphismProperties.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/MorphismProperties.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/MorphismProperties.agda
|
knrafto/cubical
|
f6771617374bfe65a7043d00731fed5a673aa729
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Group.MorphismProperties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Functions.Embedding
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Structures.Pointed
open import Cubical.Algebra.Semigroup hiding (⟨_⟩)
open import Cubical.Algebra.Monoid hiding (⟨_⟩)
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphism
private
variable
ℓ ℓ' ℓ'' : Level
open Iso
open Group
open GroupHom
isPropIsGroupHom : (G : Group {ℓ}) (H : Group {ℓ'}) {f : ⟨ G ⟩ → ⟨ H ⟩} → isProp (isGroupHom G H f)
isPropIsGroupHom G H {f} = isPropΠ2 λ a b → Group.is-set H _ _
isSetGroupHom : {G : Group {ℓ}} {H : Group {ℓ'}} → isSet (GroupHom G H)
isSetGroupHom {G = G} {H = H} = isOfHLevelRespectEquiv 2 equiv (isSetΣ (isSetΠ λ _ → is-set H) λ _ → isProp→isSet (isPropIsGroupHom G H)) where
equiv : (Σ[ g ∈ (Carrier G → Carrier H) ] (isGroupHom G H g)) ≃ (GroupHom G H)
equiv = isoToEquiv (iso (λ (g , m) → grouphom g m) (λ hom → fun hom , isHom hom) (λ a → η-hom _) λ _ → refl)
-- Morphism composition
isGroupHomComp : {F : Group {ℓ}} {G : Group {ℓ'}} {H : Group {ℓ''}} →
(f : GroupHom F G) → (g : GroupHom G H) → isGroupHom F H (fun g ∘ fun f)
isGroupHomComp f g x y = cong (fun g) (isHom f _ _) ∙ isHom g _ _
compGroupHom : {F : Group {ℓ}} {G : Group {ℓ'}} {H : Group {ℓ''}} → GroupHom F G → GroupHom G H → GroupHom F H
fun (compGroupHom f g) = fun g ∘ fun f
isHom (compGroupHom f g) = isGroupHomComp f g
open GroupEquiv
compGroupEquiv : {F : Group {ℓ}} {G : Group {ℓ'}} {H : Group {ℓ''}} → GroupEquiv F G → GroupEquiv G H → GroupEquiv F H
eq (compGroupEquiv f g) = compEquiv (eq f) (eq g)
isHom (compGroupEquiv f g) = isHom (compGroupHom (hom f) (hom g))
idGroupEquiv : (G : Group {ℓ}) → GroupEquiv G G
eq (idGroupEquiv G) = idEquiv ⟨ G ⟩
isHom (idGroupEquiv G) = λ _ _ → refl
-- Isomorphism inversion
isGroupHomInv : {G : Group {ℓ}} {H : Group {ℓ'}} (f : GroupEquiv G H) → isGroupHom H G (invEq (GroupEquiv.eq f))
isGroupHomInv {G = G} {H = H} f h h' = isInj-f _ _ (
f' (g (h ⋆² h')) ≡⟨ retEq (eq f) _ ⟩
(h ⋆² h') ≡⟨ sym (cong₂ _⋆²_ (retEq (eq f) h) (retEq (eq f) h')) ⟩
(f' (g h) ⋆² f' (g h')) ≡⟨ sym (isHom (hom f) _ _) ⟩
f' (g h ⋆¹ g h') ∎)
where
f' = fst (eq f)
_⋆¹_ = _+_ G
_⋆²_ = _+_ H
g = invEq (eq f)
isInj-f : (x y : ⟨ G ⟩) → f' x ≡ f' y → x ≡ y
isInj-f x y = invEq (_ , isEquiv→isEmbedding (snd (eq f)) x y)
invGroupEquiv : {G : Group {ℓ}} {H : Group {ℓ'}} → GroupEquiv G H → GroupEquiv H G
eq (invGroupEquiv f) = invEquiv (eq f)
isHom (invGroupEquiv f) = isGroupHomInv f
dirProdEquiv : ∀ {ℓ ℓ' ℓ'' ℓ'''} {A : Group {ℓ}} {B : Group {ℓ'}} {C : Group {ℓ''}} {D : Group {ℓ'''}}
→ GroupEquiv A C → GroupEquiv B D
→ GroupEquiv (dirProd A B) (dirProd C D)
eq (dirProdEquiv eq1 eq2) = ≃-× (eq eq1) (eq eq2)
isHom (dirProdEquiv eq1 eq2) = isHom (×hom (GroupEquiv.hom eq1) (GroupEquiv.hom eq2))
groupHomEq : {G : Group {ℓ}} {H : Group {ℓ'}} {f g : GroupHom G H} → (fun f ≡ fun g) → f ≡ g
fun (groupHomEq p i) = p i
isHom (groupHomEq {G = G} {H = H} {f = f} {g = g} p i) = p-hom i
where
p-hom : PathP (λ i → isGroupHom G H (p i)) (isHom f) (isHom g)
p-hom = toPathP (isPropIsGroupHom G H _ _)
groupEquivEq : {G : Group {ℓ}} {H : Group {ℓ'}} {f g : GroupEquiv G H} → (eq f ≡ eq g) → f ≡ g
eq (groupEquivEq {G = G} {H = H} {f} {g} p i) = p i
isHom (groupEquivEq {G = G} {H = H} {f} {g} p i) = p-hom i
where
p-hom : PathP (λ i → isGroupHom G H (p i .fst)) (isHom f) (isHom g)
p-hom = toPathP (isPropIsGroupHom G H _ _)
module GroupΣTheory {ℓ} where
RawGroupStructure : Type ℓ → Type ℓ
RawGroupStructure = SemigroupΣTheory.RawSemigroupStructure
RawGroupEquivStr : StrEquiv RawGroupStructure _
RawGroupEquivStr = SemigroupΣTheory.RawSemigroupEquivStr
rawGroupUnivalentStr : UnivalentStr RawGroupStructure _
rawGroupUnivalentStr = SemigroupΣTheory.rawSemigroupUnivalentStr
-- The neutral element and the inverse function will be derived from the
-- axioms, instead of being defined in the RawGroupStructure in order
-- to have that group equivalences are equivalences that preserves
-- multiplication (so we don't have to show that they also preserve inversion
-- and neutral element, although they will preserve them).
GroupAxioms : (G : Type ℓ) → RawGroupStructure G → Type ℓ
GroupAxioms G _·_ =
IsSemigroup _·_
× (Σ[ e ∈ G ] ((x : G) → (x · e ≡ x) × (e · x ≡ x))
× ((x : G) → Σ[ x' ∈ G ] (x · x' ≡ e) × (x' · x ≡ e)))
GroupStructure : Type ℓ → Type ℓ
GroupStructure = AxiomsStructure RawGroupStructure GroupAxioms
GroupΣ : Type (ℓ-suc ℓ)
GroupΣ = TypeWithStr ℓ GroupStructure
-- Structured equivalences for groups are those for monoids (but different axioms)
GroupEquivStr : StrEquiv GroupStructure ℓ
GroupEquivStr = AxiomsEquivStr RawGroupEquivStr GroupAxioms
open MonoidTheory
isSetGroupΣ : (G : GroupΣ)
→ isSet _
isSetGroupΣ (_ , _ , (isSemigroup-G , _ , _)) = IsSemigroup.is-set isSemigroup-G
isPropGroupAxioms : (G : Type ℓ)
→ (s : RawGroupStructure G)
→ isProp (GroupAxioms G s)
isPropGroupAxioms G _+_ = isPropΣ (isPropIsSemigroup _) γ
where
γ : (h : IsSemigroup _+_) →
isProp (Σ[ e ∈ G ] ((x : G) → (x + e ≡ x) × (e + x ≡ x))
× ((x : G) → Σ[ x' ∈ G ] (x + x' ≡ e) × (x' + x ≡ e)))
γ h (e , P , _) (e' , Q , _) =
Σ≡Prop (λ x → isPropΣ (isPropΠ λ _ → isProp× ((IsSemigroup.is-set h) _ _) ((IsSemigroup.is-set h) _ _)) (β x))
(sym (fst (Q e)) ∙ snd (P e'))
where
β : (e : G) → ((x : G) → (x + e ≡ x) × (e + x ≡ x))
→ isProp ((x : G) → Σ[ x' ∈ G ] (x + x' ≡ e) × (x' + x ≡ e))
β e He =
isPropΠ λ { x (x' , _ , P) (x'' , Q , _) →
Σ≡Prop (λ _ → isProp× ((IsSemigroup.is-set h) _ _) ((IsSemigroup.is-set h) _ _))
(inv-lemma ℳ x x' x'' P Q) }
where
ℳ : Monoid
ℳ = makeMonoid e _+_ (IsSemigroup.is-set h) (IsSemigroup.assoc h) (λ x → He x .fst) (λ x → He x .snd)
Group→GroupΣ : Group → GroupΣ
Group→GroupΣ G = _ , _ ,
((isSemigroup G)
, _
, (identity G)
, λ x → (- G) x
, inverse G x)
GroupΣ→Group : GroupΣ → Group
GroupΣ→Group (G , _ , SG , _ , H0g , invertible ) =
group _ _ _ (λ x → invertible x .fst) (isgroup (ismonoid SG H0g) λ x → invertible x .snd)
GroupIsoGroupΣ : Iso Group GroupΣ
GroupIsoGroupΣ = iso Group→GroupΣ GroupΣ→Group (λ _ → refl) helper
where
open MonoidΣTheory
monoid-helper : retract (Monoid→MonoidΣ {ℓ}) MonoidΣ→Monoid
monoid-helper = Iso.leftInv MonoidIsoMonoidΣ
helper : retract (λ z → Group→GroupΣ z) GroupΣ→Group
Carrier (helper a i) = ⟨ a ⟩
0g (helper a i) = 0g a
_+_ (helper a i) = (_+_) a
- helper a i = - a
IsGroup.isMonoid (isGroup (helper a i)) =
Monoid.isMonoid (monoid-helper (monoid (Carrier a) (0g a) (_+_ a) (isMonoid a)) i)
IsGroup.inverse (isGroup (helper a i)) = inverse a
groupUnivalentStr : UnivalentStr GroupStructure GroupEquivStr
groupUnivalentStr = axiomsUnivalentStr _ isPropGroupAxioms rawGroupUnivalentStr
GroupΣPath : (G H : GroupΣ) → (G ≃[ GroupEquivStr ] H) ≃ (G ≡ H)
GroupΣPath = SIP groupUnivalentStr
GroupEquivΣ : (G H : Group) → Type ℓ
GroupEquivΣ G H = Group→GroupΣ G ≃[ GroupEquivStr ] Group→GroupΣ H
GroupIsoΣPath : {G H : Group} → Iso (GroupEquiv G H) (GroupEquivΣ G H)
fun GroupIsoΣPath f = (eq f) , isHom f
inv GroupIsoΣPath (e , h) = groupequiv e h
rightInv GroupIsoΣPath _ = refl
leftInv GroupIsoΣPath _ = η-equiv _
GroupPath : (G H : Group) → (GroupEquiv G H) ≃ (G ≡ H)
GroupPath G H =
GroupEquiv G H ≃⟨ isoToEquiv GroupIsoΣPath ⟩
GroupEquivΣ G H ≃⟨ GroupΣPath _ _ ⟩
Group→GroupΣ G ≡ Group→GroupΣ H ≃⟨ isoToEquiv (invIso (congIso GroupIsoGroupΣ)) ⟩
G ≡ H ■
RawGroupΣ : Type (ℓ-suc ℓ)
RawGroupΣ = TypeWithStr ℓ RawGroupStructure
open Group
Group→RawGroupΣ : Group → RawGroupΣ
Group→RawGroupΣ G = ⟨ G ⟩ , (_+_ G)
InducedGroup : (G : Group) (H : RawGroupΣ) (e : G .Carrier ≃ H .fst)
→ RawGroupEquivStr (Group→RawGroupΣ G) H e → Group
InducedGroup G H e r =
GroupΣ→Group (transferAxioms rawGroupUnivalentStr (Group→GroupΣ G) H (e , r))
InducedGroupPath : (G : Group {ℓ}) (H : RawGroupΣ) (e : G .Carrier ≃ H .fst)
(E : RawGroupEquivStr (Group→RawGroupΣ G) H e)
→ G ≡ InducedGroup G H e E
InducedGroupPath G H e E =
GroupPath G (InducedGroup G H e E) .fst (groupequiv e E)
-- Extract the characterization of equality of groups
GroupPath : (G H : Group {ℓ}) → (GroupEquiv G H) ≃ (G ≡ H)
GroupPath = GroupΣTheory.GroupPath
InducedGroup : (G : Group {ℓ}) (H : GroupΣTheory.RawGroupΣ) (e : G .Carrier ≃ H .fst)
→ GroupΣTheory.RawGroupEquivStr (GroupΣTheory.Group→RawGroupΣ G) H e
→ Group
InducedGroup = GroupΣTheory.InducedGroup
InducedGroupPath : (G : Group {ℓ}) (H : GroupΣTheory.RawGroupΣ) (e : G .Carrier ≃ H .fst)
(E : GroupΣTheory.RawGroupEquivStr (GroupΣTheory.Group→RawGroupΣ G) H e)
→ G ≡ InducedGroup G H e E
InducedGroupPath = GroupΣTheory.InducedGroupPath
uaGroup : {G H : Group {ℓ}} → GroupEquiv G H → G ≡ H
uaGroup {G = G} {H = H} = equivFun (GroupPath G H)
carac-uaGroup : {G H : Group {ℓ}} (f : GroupEquiv G H) → cong Carrier (uaGroup f) ≡ ua (GroupEquiv.eq f)
carac-uaGroup f = ua (eq f) ∙ refl ≡⟨ sym (rUnit _) ⟩
ua (eq f) ∎
-- Group-ua functoriality
Group≡ : (G H : Group {ℓ}) → (
Σ[ p ∈ Carrier G ≡ Carrier H ]
Σ[ q ∈ PathP (λ i → p i) (0g G) (0g H) ]
Σ[ r ∈ PathP (λ i → p i → p i → p i) (_+_ G) (_+_ H) ]
Σ[ s ∈ PathP (λ i → p i → p i) (-_ G) (-_ H) ]
PathP (λ i → IsGroup (q i) (r i) (s i)) (isGroup G) (isGroup H))
≃ (G ≡ H)
Group≡ G H = isoToEquiv theIso
where
theIso : Iso _ _
Carrier (fun theIso (p , q , r , s , t) i) = p i
0g (fun theIso (p , q , r , s , t) i) = q i
_+_ (fun theIso (p , q , r , s , t) i) = r i
- fun theIso (p , q , r , s , t) i = s i
isGroup (fun theIso (p , q , r , s , t) i) = t i
inv theIso p = cong ⟨_⟩ p , cong 0g p , cong _+_ p , cong -_ p , cong isGroup p
Carrier (rightInv theIso a i i₁) = ⟨ a i₁ ⟩
0g (rightInv theIso a i i₁) = 0g (a i₁)
_+_ (rightInv theIso a i i₁) = _+_ (a i₁)
- rightInv theIso a i i₁ = -_ (a i₁)
isGroup (rightInv theIso a i i₁) = isGroup (a i₁)
leftInv theIso _ = refl
caracGroup≡ : {G H : Group {ℓ}} (p q : G ≡ H) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q
caracGroup≡ {G = G} {H = H} p q P = sym (transportTransport⁻ (ua (Group≡ G H)) p)
∙∙ cong (transport (ua (Group≡ G H))) helper
∙∙ transportTransport⁻ (ua (Group≡ G H)) q
where
helper : transport (sym (ua (Group≡ G H))) p ≡ transport (sym (ua (Group≡ G H))) q
helper = Σ≡Prop
(λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set H) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set H) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set H) _ _)
λ _ → isOfHLevelPathP 1 (isPropIsGroup _ _ _) _ _)
(transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))
uaGroupId : (G : Group {ℓ}) → uaGroup (idGroupEquiv G) ≡ refl
uaGroupId G = caracGroup≡ _ _ (carac-uaGroup (idGroupEquiv G) ∙ uaIdEquiv)
uaCompGroupEquiv : {F G H : Group {ℓ}} (f : GroupEquiv F G) (g : GroupEquiv G H) → uaGroup (compGroupEquiv f g) ≡ uaGroup f ∙ uaGroup g
uaCompGroupEquiv f g = caracGroup≡ _ _ (
cong Carrier (uaGroup (compGroupEquiv f g))
≡⟨ carac-uaGroup (compGroupEquiv f g) ⟩
ua (eq (compGroupEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
ua (eq f) ∙ ua (eq g)
≡⟨ cong (_∙ ua (eq g)) (sym (carac-uaGroup f)) ⟩
cong Carrier (uaGroup f) ∙ ua (eq g)
≡⟨ cong (cong Carrier (uaGroup f) ∙_) (sym (carac-uaGroup g)) ⟩
cong Carrier (uaGroup f) ∙ cong Carrier (uaGroup g)
≡⟨ sym (cong-∙ Carrier (uaGroup f) (uaGroup g)) ⟩
cong Carrier (uaGroup f ∙ uaGroup g) ∎) where
open GroupEquiv
| 41.287097
| 143
| 0.600438
|
d0271493f68d06ae5f5f3b0db7e9184d84d290ea
| 466
|
agda
|
Agda
|
Tools/Nullary.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2018-06-21T08:39:01.000Z
|
2022-01-17T16:13:53.000Z
|
Tools/Nullary.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | null | null | null |
Tools/Nullary.agda
|
CoqHott/logrel-mltt
|
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
|
[
"MIT"
] | 2
|
2022-01-26T14:55:51.000Z
|
2022-02-15T19:42:19.000Z
|
-- Some proposition constructors.
{-# OPTIONS --safe #-}
module Tools.Nullary where
open import Tools.Empty
-- Negation.
infix 3 ¬_
¬_ : Set → Set
¬ P = P → ⊥
-- Decidable propositions.
data Dec (P : Set) : Set where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
-- If A and B are logically equivalent, then so are Dec A and Dec B.
map : ∀ {A B} → (A → B) → (B → A) → Dec A → Dec B
map f g (yes p) = yes (f p)
map f g (no ¬p) = no (λ x → ¬p (g x))
| 17.259259
| 68
| 0.551502
|
318c164701914e2387cd07a394605d514538b9a1
| 2,281
|
agda
|
Agda
|
src/Prelude/Maybe.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
src/Prelude/Maybe.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
src/Prelude/Maybe.agda
|
jespercockx/agda-prelude
|
1984cf0341835b2f7bfe678098bd57cfe16ea11f
|
[
"MIT"
] | null | null | null |
module Prelude.Maybe where
open import Prelude.Unit
open import Prelude.Empty
open import Prelude.Function
open import Prelude.Functor
open import Prelude.Applicative
open import Prelude.Monad
open import Prelude.Equality
open import Prelude.Decidable
data Maybe {a} (A : Set a) : Set a where
nothing : Maybe A
just : A → Maybe A
{-# FOREIGN GHC type AgdaMaybe l = Maybe #-}
{-# COMPILE GHC Maybe = data MAlonzo.Code.Prelude.Maybe.AgdaMaybe (Nothing | Just) #-}
maybe : ∀ {a b} {A : Set a} {B : Set b} → B → (A → B) → Maybe A → B
maybe z f nothing = z
maybe z f (just x) = f x
{-# INLINE maybe #-}
fromMaybe : ∀ {a} {A : Set a} → A → Maybe A → A
fromMaybe z = maybe z id
{-# INLINE fromMaybe #-}
IsJust : ∀ {a} {A : Set a} → Maybe A → Set
IsJust = maybe ⊥ (const ⊤)
FromJust : ∀ {a} {A : Set a} → Maybe A → Set a
FromJust {A = A} = maybe ⊤′ (const A)
fromJust : ∀ {a} {A : Set a} (m : Maybe A) → FromJust m
fromJust nothing = _
fromJust (just x) = x
maybeYes : ∀ {a} {A : Set a} → Dec A → Maybe A
maybeYes (yes x) = just x
maybeYes (no _) = nothing
--- Equality ---
just-inj : ∀ {a} {A : Set a} {x y : A} → just x ≡ just y → x ≡ y
just-inj refl = refl
instance
EqMaybe : ∀ {a} {A : Set a} {{EqA : Eq A}} → Eq (Maybe A)
_==_ {{EqMaybe}} nothing nothing = yes refl
_==_ {{EqMaybe}} nothing (just x) = no λ ()
_==_ {{EqMaybe}} (just x) nothing = no λ ()
_==_ {{EqMaybe}} (just x) (just y) with x == y
... | yes eq = yes (just $≡ eq)
... | no neq = no (λ eq → neq (just-inj eq))
--- Monad ---
instance
FunctorMaybe : ∀ {a} → Functor (Maybe {a})
fmap {{FunctorMaybe}} f m = maybe nothing (just ∘ f) m
ApplicativeMaybe : ∀ {a} → Applicative (Maybe {a})
pure {{ApplicativeMaybe}} = just
_<*>_ {{ApplicativeMaybe}} mf mx = maybe nothing (λ f → fmap f mx) mf
MonadMaybe : ∀ {a} → Monad {a} Maybe
_>>=_ {{MonadMaybe}} m f = maybe nothing f m
FunctorMaybe′ : ∀ {a b} → Functor′ {a} {b} Maybe
fmap′ {{FunctorMaybe′}} f m = maybe nothing (just ∘ f) m
ApplicativeMaybe′ : ∀ {a b} → Applicative′ {a} {b} Maybe
_<*>′_ {{ApplicativeMaybe′}} (just f) (just x) = just (f x)
_<*>′_ {{ApplicativeMaybe′}} _ _ = nothing
MonadMaybe′ : ∀ {a b} → Monad′ {a} {b} Maybe
_>>=′_ {{MonadMaybe′}} m f = maybe nothing f m
| 28.873418
| 86
| 0.589654
|
298bf8bb9386e6c32b50edfa4f53c4bed2cea165
| 1,849
|
agda
|
Agda
|
theorems/stash/modalities/PushoutProduct.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/stash/modalities/PushoutProduct.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/stash/modalities/PushoutProduct.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module stash.modalities.PushoutProduct {i j k l}
{A : Type i} {B : Type j}
{A' : Type k} {B' : Type l}
where
□-span : (f : A → B) (g : A' → B') → Span
□-span f g = span (B × A') (A × B') (A × A')
(λ { (a , a') → f a , a'})
(λ { (a , a') → a , g a' })
module PshoutProd (f : A → B) (g : A' → B') =
PushoutRec {d = □-span f g}
(λ { (b , a') → b , g a' })
(λ { (a , b') → f a , b' })
(λ { (a , a') → idp })
_□_ : (f : A → B) (g : A' → B') → Pushout (□-span f g) → B × B'
f □ g = PshoutProd.f f g
□-glue-β : (f : A → B) (g : A' → B') (a : A) (a' : A') → ap (f □ g) (glue (a , a')) == idp
□-glue-β f g a a' = PshoutProd.glue-β f g (a , a')
module _ (f : A → B) (g : A' → B') where
private
abstract
↓-□=cst-out : ∀ {a a' b b'} {p p' : (f a , g a') == (b , b')}
→ p == p' [ (λ w → (f □ g) w == (b , b')) ↓ glue (a , a') ]
→ p == p'
↓-□=cst-out {p' = idp} q = ↓-app=cst-out' q ∙ □-glue-β f g _ _
↓-□=cst-in : ∀ {a a' b b'} {p p' : (f a , g a') == (b , b')}
→ p == p'
→ p == p' [ (λ w → (f □ g) w == (b , b')) ↓ glue (a , a') ]
↓-□=cst-in {p' = idp} q = ↓-app=cst-in' (q ∙ ! (□-glue-β f g _ _))
↓-□=cst-β : ∀ {a a' b b'} {p p' : (f a , g a') == (b , b')}
(q : p == p')
→ ↓-□=cst-out (↓-□=cst-in q) == q
↓-□=cst-β {a} {a'} {p' = idp} idp = {!!} ∙ !-inv-l (□-glue-β f g a a')
□-hfiber-to : (b : B) (b' : B')
→ hfiber (f □ g) (b , b') → hfiber f b * hfiber g b'
□-hfiber-to b b' = uncurry $ Pushout-elim
(λ { (_ , a') → λ p → right (a' , snd×= p) })
(λ { (a , _) → λ p → left (a , fst×= p) }) {!!}
--
-- Here is the main theorem
--
□-hfiber : (b : B) (b' : B')
→ hfiber (f □ g) (b , b') ≃ hfiber f b * hfiber g b'
□-hfiber b b' = {!!}
| 29.822581
| 90
| 0.365603
|
0629f93ac4df9c419d77e21c5840f2507c979818
| 2,152
|
agda
|
Agda
|
src/Data/ByteString/Primitive.agda
|
semenov-vladyslav/bytes-agda
|
98a53f35fca27e3379cf851a9a6bdfe5bd8c9626
|
[
"MIT"
] | null | null | null |
src/Data/ByteString/Primitive.agda
|
semenov-vladyslav/bytes-agda
|
98a53f35fca27e3379cf851a9a6bdfe5bd8c9626
|
[
"MIT"
] | null | null | null |
src/Data/ByteString/Primitive.agda
|
semenov-vladyslav/bytes-agda
|
98a53f35fca27e3379cf851a9a6bdfe5bd8c9626
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
module Data.ByteString.Primitive where
open import Data.Word8.Primitive using (Word8)
open import Data.Nat using (ℕ; _<_)
open import Data.Colist using (Colist)
open import Data.List using (List; length)
open import Agda.Builtin.String using (String)
open import Agda.Builtin.Bool using (Bool)
open import Agda.Builtin.IO using (IO)
open import Data.Tuple.Base using (Pair)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Relation.Binary.PropositionalEquality.TrustMe using (trustMe)
{-# FOREIGN GHC import qualified Data.ByteString.Lazy #-}
open import Data.ByteString.Primitive.Int
open import Data.ByteString.Primitive.Lazy
open import Data.ByteString.Primitive.Strict
-- properties
module _ where
List→Strict→List : (l : List Word8) → List←Strict (List→Strict l) ≡ l
List→Strict→List l = trustMe
Strict→List→Strict : (bs : ByteStringStrict) → List→Strict (List←Strict bs) ≡ bs
Strict→List→Strict bs = trustMe
∣Strict∣≡∣List∣ : (bs : ByteStringStrict) → IntToℕ (lengthStrict bs) ≡ length (List←Strict bs)
∣Strict∣≡∣List∣ bs = trustMe
2³¹ = 2147483648
∣List∣≡∣Strict∣ : (l : List Word8) → (l-small : length l < 2³¹) → IntToℕ (lengthStrict (List→Strict l)) ≡ length l
∣List∣≡∣Strict∣ l l-small = trustMe
postulate
toLazy : ByteStringStrict → ByteStringLazy
toStrict : ByteStringLazy → ByteStringStrict
lazy≟lazy : ByteStringLazy → ByteStringLazy → Bool
strict≟strict : ByteStringStrict → ByteStringStrict → Bool
{-# COMPILE GHC toLazy = (Data.ByteString.Lazy.fromStrict) #-}
{-# COMPILE GHC toStrict = (Data.ByteString.Lazy.toStrict) #-}
{-# COMPILE GHC lazy≟lazy = (==) #-}
{-# COMPILE GHC strict≟strict = (==) #-}
lazy≟strict : ByteStringLazy → ByteStringStrict → Bool
lazy≟strict l s = lazy≟lazy l (toLazy s)
strict≟lazy : ByteStringStrict → ByteStringLazy → Bool
strict≟lazy s l = lazy≟lazy (toLazy s) l
postulate
fromChunks : List ByteStringStrict → ByteStringLazy
toChunks : ByteStringLazy → List ByteStringStrict
{-# COMPILE GHC fromChunks = (Data.ByteString.Lazy.fromChunks) #-}
{-# COMPILE GHC toChunks = (Data.ByteString.Lazy.toChunks) #-}
| 36.474576
| 116
| 0.733271
|
31b93ad213106ff9ec3fa3361bb4f97def23250c
| 263
|
agda
|
Agda
|
test/Succeed/WithAbstractTwiceInApplication.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/WithAbstractTwiceInApplication.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/WithAbstractTwiceInApplication.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-02-07
postulate
X Y : Set
fix : (X → X) → X
g : Y → X → X
y : Y
P : X → Set
yes : (f : X → X) → P (f (fix f))
test : P (g y (fix (g y)))
test with g y
test | f = yes f
-- should be able to abstract (g y) twice
-- and succeed
| 15.470588
| 41
| 0.486692
|
29874568e00bdf675569ddca04e03eb7ed8a6f47
| 611
|
agda
|
Agda
|
src/Categories/Morphism/Universal.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Morphism/Universal.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Morphism/Universal.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Morphism.Universal where
open import Level
open import Categories.Category
open import Categories.Category.Construction.Comma
open import Categories.Functor
open import Categories.Object.Initial
record UniversalMorphism {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(X : Category.Obj C) (F : Functor D C) : Set (e ⊔ ℓ ⊔ o′ ⊔ ℓ′ ⊔ e′) where
X↙F : Category _ _ _
X↙F = X ↙ F
private
module X↙F = Category X↙F
field
initial : Initial X↙F
module initial = Initial initial
open initial public
| 25.458333
| 98
| 0.656301
|
29548e97f750f206911d0df3732af7df022c235c
| 12,661
|
agda
|
Agda
|
TotalRecognisers/LeftRecursion/ExpressiveStrength.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
TotalRecognisers/LeftRecursion/ExpressiveStrength.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
TotalRecognisers/LeftRecursion/ExpressiveStrength.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- This module establishes that the recognisers are as expressive as
-- possible when the alphabet is Bool (this could be generalised to
-- arbitrary finite alphabets), whereas this is not the case when the
-- alphabet is ℕ
------------------------------------------------------------------------
module TotalRecognisers.LeftRecursion.ExpressiveStrength where
open import Algebra
open import Coinduction
open import Data.Bool as Bool hiding (_∧_)
open import Data.Empty
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence
using (_⇔_; equivalence; module Equivalence)
open import Data.List
import Data.List.Properties as ListProp
open import Data.List.Reverse
open import Data.Nat as Nat
open import Data.Nat.InfinitelyOften as Inf
import Data.Nat.Properties as NatProp
open import Data.Product
open import Data.Sum
open import Relation.Binary
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Nullary.Negation
private
module ListMonoid {A : Set} = Monoid (ListProp.++-monoid A)
module NatOrder = DecTotalOrder NatProp.≤-decTotalOrder
import TotalRecognisers.LeftRecursion
open TotalRecognisers.LeftRecursion Bool using (_∧_; left-zero)
private
open module LR {Tok : Set} = TotalRecognisers.LeftRecursion Tok
hiding (P; ∞⟨_⟩P; _∧_; left-zero; _∷_)
P : Set → Bool → Set
P Tok = LR.P {Tok}
∞⟨_⟩P : Bool → Set → Bool → Set
∞⟨ b ⟩P Tok n = LR.∞⟨_⟩P {Tok} b n
open import TotalRecognisers.LeftRecursion.Lib Bool hiding (_∷_)
------------------------------------------------------------------------
-- A boring lemma
private
lemma : (f : List Bool → Bool) →
(false ∧ f [ true ] ∨ false ∧ f [ false ]) ∨ f [] ≡ f []
lemma f = cong₂ (λ b₁ b₂ → (b₁ ∨ b₂) ∨ f [])
(left-zero (f [ true ]))
(left-zero (f [ false ]))
------------------------------------------------------------------------
-- Expressive strength
-- For every grammar there is an equivalent decidable predicate.
grammar⇒pred : ∀ {Tok n} (p : P Tok n) →
∃ λ (f : List Tok → Bool) → ∀ {s} → s ∈ p ⇔ T (f s)
grammar⇒pred p =
((λ s → ⌊ s ∈? p ⌋) , λ {_} → equivalence fromWitness toWitness)
-- When the alphabet is Bool the other direction holds: for every
-- decidable predicate there is a corresponding grammar.
--
-- Note that the grammars constructed by the proof are all "infinite
-- LL(1)".
pred⇒grammar : (f : List Bool → Bool) →
∃ λ (p : P Bool (f [])) → ∀ {s} → s ∈ p ⇔ T (f s)
pred⇒grammar f =
(p f , λ {s} → equivalence (p-sound f) (p-complete f s))
where
p : (f : List Bool → Bool) → P Bool (f [])
p f = cast (lemma f)
( ♯? (sat id ) · ♯ p (f ∘ _∷_ true )
∣ ♯? (sat not) · ♯ p (f ∘ _∷_ false)
∣ accept-if-true (f [])
)
p-sound : ∀ f {s} → s ∈ p f → T (f s)
p-sound f (cast (∣-right s∈)) with AcceptIfTrue.sound (f []) s∈
... | (refl , ok) = ok
p-sound f (cast (∣-left (∣-left (t∈ · s∈)))) with drop-♭♯ (f [ true ]) t∈
... | sat {t = true} _ = p-sound (f ∘ _∷_ true ) s∈
... | sat {t = false} ()
p-sound f (cast (∣-left (∣-right (t∈ · s∈)))) with drop-♭♯ (f [ false ]) t∈
... | sat {t = false} _ = p-sound (f ∘ _∷_ false) s∈
... | sat {t = true} ()
p-complete : ∀ f s → T (f s) → s ∈ p f
p-complete f [] ok =
cast (∣-right {n₁ = false ∧ f [ true ] ∨ false ∧ f [ false ]} $
AcceptIfTrue.complete ok)
p-complete f (true ∷ bs) ok =
cast (∣-left $ ∣-left $
add-♭♯ (f [ true ]) (sat _) ·
p-complete (f ∘ _∷_ true ) bs ok)
p-complete f (false ∷ bs) ok =
cast (∣-left $ ∣-right {n₁ = false ∧ f [ true ]} $
add-♭♯ (f [ false ]) (sat _) ·
p-complete (f ∘ _∷_ false) bs ok)
-- An alternative proof which uses a left recursive definition of the
-- grammar to avoid the use of a cast.
pred⇒grammar′ : (f : List Bool → Bool) →
∃ λ (p : P Bool (f [])) → ∀ {s} → s ∈ p ⇔ T (f s)
pred⇒grammar′ f =
(p f , λ {s} → equivalence (p-sound f) (p-complete f s))
where
extend : {A B : Set} → (List A → B) → A → (List A → B)
extend f x = λ xs → f (xs ∷ʳ x)
p : (f : List Bool → Bool) → P Bool (f [])
p f = ♯ p (extend f true ) · ♯? (sat id )
∣ ♯ p (extend f false) · ♯? (sat not)
∣ accept-if-true (f [])
p-sound : ∀ f {s} → s ∈ p f → T (f s)
p-sound f (∣-right s∈) with AcceptIfTrue.sound (f []) s∈
... | (refl , ok) = ok
p-sound f (∣-left (∣-left (s∈ · t∈))) with drop-♭♯ (f [ true ]) t∈
... | sat {t = true} _ = p-sound (extend f true ) s∈
... | sat {t = false} ()
p-sound f (∣-left (∣-right (s∈ · t∈))) with drop-♭♯ (f [ false ]) t∈
... | sat {t = false} _ = p-sound (extend f false) s∈
... | sat {t = true} ()
p-complete′ : ∀ f {s} → Reverse s → T (f s) → s ∈ p f
p-complete′ f [] ok =
∣-right {n₁ = false} $ AcceptIfTrue.complete ok
p-complete′ f (bs ∶ rs ∶ʳ true ) ok =
∣-left {n₁ = false} $ ∣-left {n₁ = false} $
p-complete′ (extend f true ) rs ok ·
add-♭♯ (f [ true ]) (sat _)
p-complete′ f (bs ∶ rs ∶ʳ false) ok =
∣-left {n₁ = false} $ ∣-right {n₁ = false} $
p-complete′ (extend f false) rs ok ·
add-♭♯ (f [ false ]) (sat _)
p-complete : ∀ f s → T (f s) → s ∈ p f
p-complete f s = p-complete′ f (reverseView s)
-- If infinite alphabets are allowed the result is different: there
-- are decidable predicates which cannot be realised as grammars. The
-- proof below shows that a recogniser for natural number strings
-- cannot accept exactly the strings of the form "nn".
module NotExpressible where
-- A "pair" is a string containing two equal elements.
pair : ℕ → List ℕ
pair n = n ∷ n ∷ []
-- OnlyPairs p is inhabited iff p only accepts pairs and empty
-- strings. (Empty strings are allowed due to the presence of the
-- nonempty combinator.)
OnlyPairs : ∀ {n} → P ℕ n → Set
OnlyPairs p = ∀ {n s} → n ∷ s ∈ p → s ≡ [ n ]
-- ManyPairs p is inhabited iff p accepts infinitely many pairs.
ManyPairs : ∀ {n} → P ℕ n → Set
ManyPairs p = Inf (λ n → pair n ∈ p)
-- AcceptsNonEmptyString p is inhabited iff p accepts a non-empty
-- string.
AcceptsNonEmptyString : ∀ {Tok n} → P Tok n → Set
AcceptsNonEmptyString p = ∃₂ λ t s → t ∷ s ∈ p
-- If a recogniser does not accept any non-empty string, then it
-- either accepts the empty string or no string at all.
nullable-or-fail : ∀ {Tok n} {p : P Tok n} →
¬ AcceptsNonEmptyString p →
[] ∈ p ⊎ (∀ s → ¬ s ∈ p)
nullable-or-fail {p = p} ¬a with [] ∈? p
... | yes []∈p = inj₁ []∈p
... | no []∉p = inj₂ helper
where
helper : ∀ s → ¬ s ∈ p
helper [] = []∉p
helper (t ∷ s) = ¬a ∘ _,_ t ∘ _,_ s
-- If p₁ · p₂ accepts infinitely many pairs, and nothing but pairs
-- (or the empty string), then at most one of p₁ and p₂ accepts a
-- non-empty string. This follows because p₁ and p₂ are independent
-- of each other. For instance, if p₁ accepted n and p₂ accepted i
-- and j, then p₁ · p₂ would accept both ni and nj, and if p₁
-- accepted mm and p₂ accepted n then p₁ · p₂ would accept mmn.
at-most-one : ∀ {n₁ n₂} {p₁ : ∞⟨ n₂ ⟩P ℕ n₁} {p₂ : ∞⟨ n₁ ⟩P ℕ n₂} →
OnlyPairs (p₁ · p₂) →
ManyPairs (p₁ · p₂) →
AcceptsNonEmptyString (♭? p₁) →
AcceptsNonEmptyString (♭? p₂) → ⊥
at-most-one op mp (n₁ , s₁ , n₁s₁∈p₁) (n₂ , s₂ , n₂s₂∈p₂)
with op (n₁s₁∈p₁ · n₂s₂∈p₂)
at-most-one _ _ (_ , _ ∷ [] , _) (_ , _ , _) | ()
at-most-one _ _ (_ , _ ∷ _ ∷ _ , _) (_ , _ , _) | ()
at-most-one {p₁ = p₁} {p₂} op mp
(n , [] , n∈p₁) (.n , .[] , n∈p₂) | refl =
twoDifferentWitnesses mp helper
where
¬pair : ∀ {i s} → s ∈ p₁ · p₂ → n ≢ i → s ≢ pair i
¬pair (_·_ {s₁ = []} _ ii∈p₂) n≢i refl with op (n∈p₁ · ii∈p₂)
... | ()
¬pair (_·_ {s₁ = i ∷ []} i∈p₁ _) n≢i refl with op (i∈p₁ · n∈p₂)
¬pair (_·_ {s₁ = .n ∷ []} n∈p₁ _) n≢n refl | refl = n≢n refl
¬pair (_·_ {s₁ = i ∷ .i ∷ []} ii∈p₁ _) n≢i refl with op (ii∈p₁ · n∈p₂)
... | ()
¬pair (_·_ {s₁ = _ ∷ _ ∷ _ ∷ _} _ _) _ ()
helper : ¬ ∃₂ λ i j → i ≢ j × pair i ∈ p₁ · p₂ × pair j ∈ p₁ · p₂
helper (i , j , i≢j , ii∈ , jj∈) with Nat._≟_ n i
helper (.n , j , n≢j , nn∈ , jj∈) | yes refl = ¬pair jj∈ n≢j refl
helper (i , j , i≢j , ii∈ , jj∈) | no n≢i = ¬pair ii∈ n≢i refl
-- OnlyPairs and ManyPairs are mutually exclusive.
¬pairs : ∀ {n} (p : P ℕ n) → OnlyPairs p → ManyPairs p → ⊥
¬pairs fail op mp = witness mp (helper ∘ proj₂)
where
helper : ∀ {t} → ¬ pair t ∈ fail
helper ()
¬pairs empty op mp = witness mp (helper ∘ proj₂)
where
helper : ∀ {t} → ¬ pair t ∈ empty
helper ()
¬pairs (sat f) op mp = witness mp (helper ∘ proj₂)
where
helper : ∀ {t} → ¬ pair t ∈ sat f
helper ()
¬pairs (nonempty p) op mp =
¬pairs p (op ∘ nonempty) (Inf.map helper mp)
where
helper : ∀ {n} → pair n ∈ nonempty p → pair n ∈ p
helper (nonempty pr) = pr
¬pairs (cast eq p) op mp = ¬pairs p (op ∘ cast) (Inf.map helper mp)
where
helper : ∀ {n} → pair n ∈ cast eq p → pair n ∈ p
helper (cast pr) = pr
-- The most interesting cases are _∣_ and _·_. For the choice
-- combinator we make use of the fact that if p₁ ∣ p₂ accepts
-- infinitely many pairs, then at least one of p₁ and p₂ do. (We are
-- deriving a contradiction, so the use of classical reasoning is
-- unproblematic.)
¬pairs (p₁ ∣ p₂) op mp = commutes-with-∪ (Inf.map split mp) helper
where
helper : ¬ (ManyPairs p₁ ⊎ ManyPairs p₂)
helper (inj₁ mp₁) = ¬pairs p₁ (op ∘ ∣-left) mp₁
helper (inj₂ mp₂) = ¬pairs p₂ (op ∘ ∣-right {p₁ = p₁}) mp₂
split : ∀ {s} → s ∈ p₁ ∣ p₂ → s ∈ p₁ ⊎ s ∈ p₂
split (∣-left s∈p₁) = inj₁ s∈p₁
split (∣-right s∈p₂) = inj₂ s∈p₂
-- For the sequencing combinator we make use of the fact that the
-- argument recognisers cannot both accept non-empty strings.
¬pairs (p₁ · p₂) op mp =
excluded-middle λ a₁? →
excluded-middle λ a₂? →
helper a₁? a₂?
where
continue : {n n′ : Bool} (p : ∞⟨ n′ ⟩P ℕ n) → n′ ≡ true →
OnlyPairs (♭? p) → ManyPairs (♭? p) → ⊥
continue p eq with forced? p
continue p refl | true = ¬pairs p
continue p () | false
helper : Dec (AcceptsNonEmptyString (♭? p₁)) →
Dec (AcceptsNonEmptyString (♭? p₂)) → ⊥
helper (yes a₁) (yes a₂) = at-most-one op mp a₁ a₂
helper (no ¬a₁) _ with nullable-or-fail ¬a₁
... | inj₁ []∈p₁ =
continue p₂ (⇒ []∈p₁) (op ∘ _·_ []∈p₁) (Inf.map right mp)
where
right : ∀ {s} → s ∈ p₁ · p₂ → s ∈ ♭? p₂
right (_·_ {s₁ = []} _ ∈p₂) = ∈p₂
right (_·_ {s₁ = _ ∷ _} ∈p₁ _) = ⊥-elim (¬a₁ (, , ∈p₁))
... | inj₂ is-fail = witness mp (∉ ∘ proj₂)
where
∉ : ∀ {s} → ¬ s ∈ p₁ · p₂
∉ (∈p₁ · _) = is-fail _ ∈p₁
helper _ (no ¬a₂) with nullable-or-fail ¬a₂
... | inj₁ []∈p₂ =
continue p₁ (⇒ []∈p₂)
(op ∘ (λ ∈p₁ → cast∈ (proj₂ ListMonoid.identity _) refl
(∈p₁ · []∈p₂)))
(Inf.map left mp)
where
left : ∀ {s} → s ∈ p₁ · p₂ → s ∈ ♭? p₁
left (_·_ {s₂ = _ ∷ _} _ ∈p₂) = ⊥-elim (¬a₂ (, , ∈p₂))
left (_·_ {s₁ = s₁} {s₂ = []} ∈p₁ _) =
cast∈ (sym $ proj₂ ListMonoid.identity s₁) refl ∈p₁
... | inj₂ is-fail = witness mp (∉ ∘ proj₂)
where
∉ : ∀ {s} → ¬ s ∈ p₁ · p₂
∉ (_ · ∈p₂) = is-fail _ ∈p₂
-- Note that it is easy to decide whether a string is a pair or not.
pair? : List ℕ → Bool
pair? (m ∷ n ∷ []) = ⌊ Nat._≟_ m n ⌋
pair? _ = false
-- This means that there are decidable predicates over token strings
-- which cannot be realised using the recogniser combinators.
not-realisable :
¬ ∃₂ (λ n (p : P ℕ n) → ∀ {s} → s ∈ p ⇔ T (pair? s))
not-realisable (_ , p , hyp) = ¬pairs p op mp
where
op : OnlyPairs p
op {n} {[]} s∈p = ⊥-elim (Equivalence.to hyp ⟨$⟩ s∈p)
op {n} { m ∷ []} s∈p with toWitness (Equivalence.to hyp ⟨$⟩ s∈p)
op {n} {.n ∷ []} s∈p | refl = refl
op {n} {_ ∷ _ ∷ _} s∈p = ⊥-elim (Equivalence.to hyp ⟨$⟩ s∈p)
mp : ManyPairs p
mp (i , ¬pair) =
¬pair i NatOrder.refl $ Equivalence.from hyp ⟨$⟩ fromWitness refl
not-expressible :
∃₂ λ (Tok : Set) (f : List Tok → Bool) →
¬ ∃₂ (λ n (p : P Tok n) → ∀ {s} → s ∈ p ⇔ T (f s))
not-expressible = (ℕ , pair? , not-realisable)
where open NotExpressible
| 36.698551
| 77
| 0.53495
|
315e509ac62ab88dbb411c87ff8a978479ac3aca
| 1,804
|
agda
|
Agda
|
src/Basics.agda
|
jstolarek/dep-typed-wbl-heaps
|
57db566cb840dc70331c29eb7bf3a0c849f8b27e
|
[
"BSD-3-Clause"
] | 1
|
2018-05-02T21:48:43.000Z
|
2018-05-02T21:48:43.000Z
|
src/Basics.agda
|
jstolarek/dep-typed-wbl-heaps
|
57db566cb840dc70331c29eb7bf3a0c849f8b27e
|
[
"BSD-3-Clause"
] | null | null | null |
src/Basics.agda
|
jstolarek/dep-typed-wbl-heaps
|
57db566cb840dc70331c29eb7bf3a0c849f8b27e
|
[
"BSD-3-Clause"
] | null | null | null |
----------------------------------------------------------------------
-- 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 --
-- --
-- This module re-exports all Basics/* modules for convenience. --
-- Note that both Basics.Nat and Basics.Ordering define ≥ operator. --
-- Here we re-export the one from Basics.Ordering as it will be --
-- used most of the time. --
-- This module also defines two type synonyms that will be helpful --
-- when working on heaps: Rank and Priority. --
----------------------------------------------------------------------
module Basics where
open import Basics.Bool public
open import Basics.Nat public hiding (_≥_)
open import Basics.Ordering public
open import Basics.Reasoning public
-- Rank of a weight biased leftist heap is defined as number of nodes
-- in a heap. In other words it is size of a tree used to represent a
-- heap.
Rank : Set
Rank = Nat
-- Priority assigned to elements stored in a Heap.
--
-- CONVENTION: Lower number means higher Priority. Therefore the
-- highest Priority is zero. It will sometimes be more convenient not
-- to use this inversed terminology. We will then use terms "smaller"
-- and "greater" (in contrast to "lower" and "higher"). Example:
-- Priority 3 is higher than 5, but 3 is smaller than 5.
Priority : Set
Priority = Nat
-- Note that both Rank and Priority are Nat, which allows us to
-- operate on them with functions that work for Nat.
| 45.1
| 70
| 0.575942
|
10662b02868e1d6bc108be2d4eded6d818cf0c57
| 982
|
agda
|
Agda
|
notes/thesis/report/Verification/CorruptFormalisations.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/thesis/report/Verification/CorruptFormalisations.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/thesis/report/Verification/CorruptFormalisations.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Verification.CorruptFormalisations where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Base.Loop
open import FOTC.Program.ABP.Terms
------------------------------------------------------------------------------
-- Corrupt as a constant.
module Constant where
postulate
corrupt : D
corrupt-T : ∀ os x xs →
corrupt · (T ∷ os) · (x ∷ xs) ≡ ok x ∷ corrupt · os · xs
corrupt-F : ∀ os x xs →
corrupt · (F ∷ os) · (x ∷ xs) ≡ error ∷ corrupt · os · xs
-- Corrupt as a binary function.
module BinaryFunction where
postulate
corrupt : D → D → D
corrupt-T : ∀ os x xs →
corrupt (T ∷ os) (x ∷ xs) ≡ ok x ∷ corrupt os xs
corrupt-F : ∀ os x xs →
corrupt (F ∷ os) (x ∷ xs) ≡ error ∷ corrupt os xs
| 30.6875
| 78
| 0.510183
|
4db605e7a49696e44e77fee9258f806a495a14b4
| 625
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Instances/BiInvInt.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/CommRing/Instances/BiInvInt.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/CommRing/Instances/BiInvInt.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
-- It is recommended to use Cubical.Algebra.CommRing.Instances.Int
-- instead of this file.
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Instances.BiInvInt where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.CommRing
open import Cubical.Data.Int.MoreInts.BiInvInt
renaming (
_+_ to _+ℤ_;
-_ to _-ℤ_;
+-assoc to +ℤ-assoc;
+-comm to +ℤ-comm
)
BiInvℤAsCommRing : CommRing ℓ-zero
BiInvℤAsCommRing =
makeCommRing
zero (suc zero) _+ℤ_ _·_ _-ℤ_
isSetBiInvℤ
+ℤ-assoc +-zero +-invʳ +ℤ-comm
·-assoc ·-identityʳ
(λ x y z → sym (·-distribˡ x y z))
·-comm
| 23.148148
| 66
| 0.6816
|
1c9db04abbaa28623110c1337874ec7005a8135f
| 819
|
agda
|
Agda
|
src/fot/PA/Axiomatic/Standard/Base/Consistency/Axioms.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/PA/Axiomatic/Standard/Base/Consistency/Axioms.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/PA/Axiomatic/Standard/Base/Consistency/Axioms.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Test the consistency of PA.Axiomatic.Standard.Base
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- In the module PA.Axiomatic.Standard.Base we declare Agda postulates
-- as first-order logic axioms. We test if it is possible to prove an
-- unprovable theorem from these axioms.
module PA.Axiomatic.Standard.Base.Consistency.Axioms where
open import PA.Axiomatic.Standard.Base
------------------------------------------------------------------------------
postulate impossible : (m n : ℕ) → m ≡ n
{-# ATP prove impossible #-}
| 37.227273
| 78
| 0.47619
|
10b2b04ff0e356bcfbfd3d1a4170eeae244b6cc9
| 13,845
|
agda
|
Agda
|
lib/Explore/Old/Sum/sum-properties-setoid.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | 2
|
2016-06-05T09:25:32.000Z
|
2017-06-28T19:19:29.000Z
|
lib/Explore/Old/Sum/sum-properties-setoid.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | 1
|
2019-03-16T14:24:04.000Z
|
2019-03-16T14:24:04.000Z
|
lib/Explore/Old/Sum/sum-properties-setoid.agda
|
crypto-agda/explore
|
16bc8333503ff9c00d47d56f4ec6113b9269a43e
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module sum-properties-setoid where
open import Type
import Level as L
open import Algebra
import Algebra.FunctionProperties as FP
open import Data.Zero using (𝟘)
open import Data.Bool.NP
open Data.Bool.NP.Indexed
open import Data.Fin using (Fin)
open import Data.Nat.NP
open import Data.Nat.Properties
open import Data.Product renaming (map to pmap)
open import Data.Sum
open import Data.One using (𝟙)
open import Function.NP
import Function.Inverse as Inv
open Inv using (_↔_)
open import Function.Related
open import Function.Related.TypeIsomorphisms.NP
import Function.Equality as FE
open FE using (_⟨$⟩_)
import Function.Injection as FInj
open import sum-setoid
open import Relation.Binary
open import Relation.Binary.Sum.NP
open import Relation.Binary.Product.Pointwise
import Relation.Binary.PropositionalEquality.NP as ≡
open ≡ using (_≡_ ; _≗_ ; _≗₂_)
module _ {A : ★} (μA : SumProp A) (f g : A → ℕ) where
open ≡.≡-Reasoning
sum-⊓-∸ : sum μA f ≡ sum μA (f ⊓° g) + sum μA (f ∸° g)
sum-⊓-∸ = sum μA f ≡⟨ sum-ext μA (f ⟨ a≡a⊓b+a∸b ⟩° g) ⟩
sum μA ((f ⊓° g) +° (f ∸° g)) ≡⟨ sum-hom μA (f ⊓° g) (f ∸° g) ⟩
sum μA (f ⊓° g) + sum μA (f ∸° g) ∎
sum-⊔-⊓ : sum μA f + sum μA g ≡ sum μA (f ⊔° g) + sum μA (f ⊓° g)
sum-⊔-⊓ = sum μA f + sum μA g ≡⟨ ≡.sym (sum-hom μA f g) ⟩
sum μA (f +° g) ≡⟨ sum-ext μA (f ⟨ a+b≡a⊔b+a⊓b ⟩° g) ⟩
sum μA (f ⊔° g +° f ⊓° g) ≡⟨ sum-hom μA (f ⊔° g) (f ⊓° g) ⟩
sum μA (f ⊔° g) + sum μA (f ⊓° g) ∎
sum-⊔ : sum μA (f ⊔° g) ≤ sum μA f + sum μA g
sum-⊔ = ℕ≤.trans (sum-mono μA (f ⟨ ⊔≤+ ⟩° g)) (ℕ≤.reflexive (sum-hom μA f g))
module _M2 {A : ★} (μA : SumProp A) (f g : A → Bool) where
count-∧-not : count μA f ≡ count μA (f ∧° g) + count μA (f ∧° not° g)
count-∧-not rewrite sum-⊓-∸ μA (toℕ ∘ f) (toℕ ∘ g)
| sum-ext μA (f ⟨ toℕ-⊓ ⟩° g)
| sum-ext μA (f ⟨ toℕ-∸ ⟩° g)
= ≡.refl
count-∨-∧ : count μA f + count μA g ≡ count μA (f ∨° g) + count μA (f ∧° g)
count-∨-∧ rewrite sum-⊔-⊓ μA (toℕ ∘ f) (toℕ ∘ g)
| sum-ext μA (f ⟨ toℕ-⊔ ⟩° g)
| sum-ext μA (f ⟨ toℕ-⊓ ⟩° g)
= ≡.refl
count-∨≤+ : count μA (f ∨° g) ≤ count μA f + count μA g
count-∨≤+ = ℕ≤.trans (ℕ≤.reflexive (sum-ext μA (≡.sym ∘ (f ⟨ toℕ-⊔ ⟩° g))))
(sum-⊔ μA (toℕ ∘ f) (toℕ ∘ g))
sum-ext₂ : ∀ {A B}{f g : A → B → ℕ}(μA : SumProp A)(μB : SumProp B) → f ≗₂ g → sum μA (sum μB ∘ f) ≡ sum μA (sum μB ∘ g)
sum-ext₂ μA μB f≗g = sum-ext μA (sum-ext μB ∘ f≗g)
Injective : ∀ {a b}{A : Set a}{B : Set b}(f : A → B) → Set (a L.⊔ b)
Injective f = ∀ {x y} → f x ≡ f y → x ≡ y
Injectivoid : ∀ {A B : SEToid} → (Setoid.Carrier A → Setoid.Carrier B) → Set
Injectivoid {A}{B} f = ∀ {x y} → Setoid._≈_ B (f x) (f y) → Setoid._≈_ A x y
StableUnderInjection : ∀ {A} → SumPropoid A → Set
StableUnderInjection {A} μ = ∀ p → SumStableUnder μ (FInj.Injection.to p)
CountStableUnderInjection : ∀ {A} → SumPropoid A → Set
CountStableUnderInjection μ = ∀ p → CountStableUnder μ (FInj.Injection.to p)
{-
#-StableUnderInjection : ∀ {A}{μ : SumPropoid A} → StableUnderInjection μ
→ ∀ f p → Injective p → count μ f ≡ count μ (f ∘ p)
#-StableUnderInjection sui f p p-inj = {!sui p p-inj (toℕ ∘ f)!}
-}
sum$ : ∀ {As} → SumPropoid As → (As FE.⟶ ≡.setoid ℕ) → ℕ
sum$ μA f = sum μA (_⟨$⟩_ f)
infix 4 _≈_ -- _≈'_
record _≈_ {As Bs : SEToid}(μA : SumPropoid As)(μB : SumPropoid Bs): Set where
constructor mk
field
iso : Inv.Inverse As Bs
private
A = Setoid.Carrier As
B = Setoid.Carrier Bs
from : Bs FE.⟶ As
from = Inv.Inverse.from iso
from$ : B → A
from$ = _⟨$⟩_ from
to : As FE.⟶ Bs
to = Inv.Inverse.to iso
to$ : A → B
to$ = _⟨$⟩_ to
from-inj : FInj.Injection Bs As -- Injectivoid {Bs} {As} from$
from-inj = Inv.Inverse.injection (Inv.sym iso)
to-inj : FInj.Injection As Bs -- Injectivoid {As} {Bs} to$
to-inj = Inv.Inverse.injection iso
field
sums-ok : ∀ f → sum$ μA f ≡ sum$ μB (f FE.∘ from)
sums-ok' : ∀ f → sum$ μB f ≡ sum$ μA (f FE.∘ to)
sums-ok' f
= sum$ μB f
≡⟨ search-extoid μB _+_ {f = f}
{g = f FE.∘ to FE.∘ from}
(λ {x}{y} x≈y → FE.cong f (SB.trans x≈y (SB.sym (Inv.Inverse.right-inverse-of iso y)))) ⟩
sum$ μB (f FE.∘ to FE.∘ from)
≡⟨ ≡.sym (sums-ok (f FE.∘ to)) ⟩
sum$ μA (f FE.∘ to)
∎
where open ≡.≡-Reasoning
module SB = Setoid Bs
module SA = Setoid As
StableUnder≈ : StableUnderInjection μA → StableUnderInjection μB
StableUnder≈ μA-SUI p f
= sum$ μB f
≡⟨ sums-ok' f ⟩
sum$ μA (f FE.∘ to)
≡⟨ μA-SUI (from-inj FInj.∘ p FInj.∘ to-inj) (f FE.∘ to) ⟩
sum$ μA (f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p FE.∘ to)
≡⟨ ≡.sym (sums-ok' (f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p)) ⟩
sum$ μB (f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p)
≡⟨ search-extoid μB _+_
{f = f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p}
{g = f FE.∘ FInj.Injection.to p} (FE.cong f ∘ Setoid.trans Bs (Inv.Inverse.right-inverse-of iso _) ∘ FE.cong (FInj.Injection.to p)) ⟩
sum$ μB (f FE.∘ FInj.Injection.to p)
∎
where open ≡.≡-Reasoning
_≈'_ : ∀ {A B} (μA : SumProp A)(μB : SumProp B) → Set
_≈'_ = _≈_
≈-refl : ∀ {A} (μA : SumPropoid A) → μA ≈ μA
≈-refl μA = mk Inv.id (λ f → ≡.refl)
≈-id : ∀ {A} {μA : SumPropoid A} → μA ≈ μA
≈-id = ≈-refl _
≈-sym : ∀ {A B}{μA : SumPropoid A}{μB : SumPropoid B} → μA ≈ μB → μB ≈ μA
≈-sym A≈B = mk (Inv.sym iso) sums-ok'
where open _≈_ A≈B
≈-trans : ∀ {A B C}{μA : SumPropoid A}{μB : SumPropoid B}{μC : SumPropoid C} → μA ≈ μB → μB ≈ μC → μA ≈ μC
≈-trans A≈B B≈C = mk (iso B≈C Inv.∘ iso A≈B) (λ f → ≡.trans (sums-ok A≈B f) (sums-ok B≈C (f FE.∘ from A≈B)))
where open _≈_
infix 2 _≈∎
infixr 2 _≈⟨_⟩_
_≈∎ : ∀ {A} (μA : SumPropoid A) → μA ≈ μA
_≈∎ = ≈-refl
_≈⟨_⟩_ : ∀ {A B C} (μA : SumPropoid A){μB : SumPropoid B}{μC : SumPropoid C} → μA ≈ μB → μB ≈ μC → μA ≈ μC
_ ≈⟨ A≈B ⟩ B≈C = ≈-trans A≈B B≈C
lift-⊎ : ∀ {A B : Set} → Inv.Inverse (≡.setoid (A ⊎ B)) ((≡.setoid A) ⊎-setoid (≡.setoid B))
lift-⊎ {A} {B} = record { to = to; from = from; inverse-of = inverse-of } where
to : _
to = record { _⟨$⟩_ = id; cong = cong } where
cong : ∀ {i j} → i ≡ j → _
cong ≡.refl = Setoid.refl (≡.setoid (A) ⊎-setoid (≡.setoid B))
from : _
from = record { _⟨$⟩_ = id; cong = cong } where
cong : ∀ {i j} → ⊎ʳ 𝟘 _≡_ _≡_ i j → i ≡ j
cong (₁∼₂ ())
cong (₁∼₁ x∼₁y) = ≡.cong inj₁ x∼₁y
cong (₂∼₂ x∼₂y) = ≡.cong inj₂ x∼₂y
inverse-of : _
inverse-of = record { left-inverse-of = left-inverse-of; right-inverse-of = right-inverse-of } where
left-inverse-of : (_ : _) → _
left-inverse-of x = Setoid.refl (≡.setoid (A ⊎ B))
right-inverse-of : (_ : _) → _
right-inverse-of x = Setoid.refl ((≡.setoid A) ⊎-setoid (≡.setoid B))
Fin0≈𝟙 : μFinSuc zero ≈ μ𝟙
Fin0≈𝟙 = mk iso sums-ok where
open import Relation.Binary.Sum
iso : _
iso = (A⊎𝟘↔A Inv.∘ Inv.id ⊎-cong Fin0↔𝟘) Inv.∘ Fin∘suc↔𝟙⊎Fin
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
𝟙+Fin : ∀ {n} → μ𝟙 +μ μFinSuc n ≈ μFinSuc (suc n)
𝟙+Fin {n} = mk iso sums-ok where
iso : _
iso = Inv.sym (Inv._∘_ (lift-⊎ {𝟙} {Fin (suc n)}) Fin∘suc↔𝟙⊎Fin)
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
𝟙×A≈A : ∀ {A}{μA : SumProp A} → μ𝟙 ×μ μA ≈ μA
𝟙×A≈A {A} = mk iso sums-ok where
iso : _
iso = ×-ICMon.identityˡ _
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
μFinPres : ∀ {m n} → m ≡ n → μFinSuc m ≈ μFinSuc n
μFinPres eq rewrite eq = ≈-refl _
_+μ-cong_ : ∀ {A B C D}{μA : SumPropoid A}{μB : SumPropoid B}{μC : SumPropoid C}{μD : SumPropoid D}
→ μA ≈ μC → μB ≈ μD → μA +μ μB ≈ μC +μ μD
A≈C +μ-cong B≈D = mk iso sums-ok where
iso : _
iso = (_≈_.iso A≈C) ⊎-inverse (_≈_.iso B≈D) -- (_≈_.iso A≈C) ⊎-cong (_≈_.iso B≈D)
sums-ok : (_ : _) → _
sums-ok f = ≡.cong₂ _+_ (_≈_.sums-ok A≈C (f FE.∘ inj₁-setoid)) -- (λ x≈y → f-resp (₁∼₁ x≈y)))
(_≈_.sums-ok B≈D (f FE.∘ inj₂-setoid)) -- (λ x≈y → f-resp (₂∼₂ x≈y)))
+μ-assoc : ∀ {A B C}(μA : SumPropoid A)(μB : SumPropoid B)(μC : SumPropoid C)
→ (μA +μ μB) +μ μC ≈ μA +μ (μB +μ μC)
+μ-assoc μA μB μC = mk iso sums-ok where
iso : _
iso = ⊎-ICMon.assoc _ _ _
sums-ok : (_ : _) → _
sums-ok f = ℕ°.+-assoc (sum μA (_⟨$⟩_ f ∘ inj₁ ∘ inj₁)) (sum μB (_⟨$⟩_ f ∘ inj₁ ∘ inj₂)) (sum μC (_⟨$⟩_ f ∘ inj₂))
+μ-comm : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B)
→ μA +μ μB ≈ μB +μ μA
+μ-comm μA μB = mk iso sums-ok where
iso : _
iso = ⊎-ICMon.comm _ _
sums-ok : (_ : _) → _
sums-ok f = ℕ°.+-comm (sum$ μA (f FE.∘ inj₁-setoid)) (sum$ μB (f FE.∘ inj₂-setoid))
_×μ-cong_ : ∀ {A B C D}{μA : SumPropoid A}{μB : SumPropoid B}{μC : SumPropoid C}{μD : SumPropoid D}
→ μA ≈ μC → μB ≈ μD → μA ×μ μB ≈ μC ×μ μD
_×μ-cong_ {A}{B}{C}{D}{μA}{μB}{μC}{μD} A≈C B≈D = mk iso sums-ok where
open import Relation.Binary.Product.Pointwise
iso : _
iso = _≈_.iso A≈C ×-inverse _≈_.iso B≈D
sums-ok : (_ : (A ×-setoid B) FE.⟶ ≡.setoid ℕ) → _
sums-ok f = sum$ (μA ×μ μB) f
≡⟨ sum-ext μA (λ xa → _≈_.sums-ok B≈D (record
{ _⟨$⟩_ = λ x → f ⟨$⟩ (xa , x)
; cong = λ x → FE.cong f (Setoid.refl A , x) })) ⟩
sum$ (μA ×μ μD) (f FE.∘ FE.id {A = A} ×-⟶ _≈_.from B≈D)
≡⟨ _≈_.sums-ok A≈C (record { _⟨$⟩_ = _; cong = λ x → search-ext μD _+_ (λ y → FE.cong f (x , Setoid.refl B)) }) ⟩
sum$ (μC ×μ μD) (f FE.∘ Inv.Inverse.from iso)
∎ where open ≡.≡-Reasoning
×μ-assoc : ∀ {A B C}(μA : SumPropoid A)(μB : SumPropoid B)(μC : SumPropoid C)
→ (μA ×μ μB) ×μ μC ≈ μA ×μ (μB ×μ μC)
×μ-assoc {A}{B}{C} μA μB μC = mk iso sums-ok where
iso : _
iso = ×-ICMon.assoc A B C
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
×μ-comm : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B)
→ μA ×μ μB ≈ μB ×μ μA
×μ-comm {A}{B} μA μB = mk iso sums-ok where
iso : _
iso = ×-ICMon.comm A B
sums-ok : (_ : _) → _
sums-ok f = sum-swap μA μB (curry (_⟨$⟩_ f))
×+-distrib : ∀ {A B C}(μA : SumPropoid A)(μB : SumPropoid B)(μC : SumPropoid C)
→ (μA +μ μB) ×μ μC ≈ (μA ×μ μC) +μ (μB ×μ μC)
×+-distrib {A}{B}{C} μA μB μC = mk iso sums-ok where
iso : _
iso = ×⊎°I.distribʳ C A B
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
+-≈ : ∀ m n → (μFinSuc m) +μ (μFinSuc n) ≈ μFinSuc (m + suc n)
+-≈ zero n = μFinSuc zero +μ μFinSuc n
≈⟨ Fin0≈𝟙 +μ-cong ≈-refl (μFinSuc n) ⟩
μ𝟙 +μ μFinSuc n
≈⟨ 𝟙+Fin ⟩
μFinSuc (suc n)
≈∎
+-≈ (suc m) n = μFinSuc (suc m) +μ μFinSuc n
≈⟨ ≈-sym 𝟙+Fin +μ-cong ≈-refl (μFinSuc n) ⟩
(μ𝟙 +μ μFinSuc m) +μ μFinSuc n
≈⟨ +μ-assoc μ𝟙 (μFinSuc m) (μFinSuc n) ⟩
μ𝟙 +μ (μFinSuc m +μ μFinSuc n)
≈⟨ ≈-refl μ𝟙 +μ-cong +-≈ m n ⟩
μ𝟙 +μ μFinSuc (m + suc n)
≈⟨ 𝟙+Fin ⟩
μFinSuc (suc m + suc n)
≈∎
×-≈ : ∀ m n → μFinSuc m ×μ μFinSuc n ≈ μFinSuc (n + m * suc n)
×-≈ zero n = μFinSuc 0 ×μ μFinSuc n
≈⟨ Fin0≈𝟙 ×μ-cong (≈-refl (μFinSuc n)) ⟩
μ𝟙 ×μ μFinSuc n
≈⟨ 𝟙×A≈A ⟩
μFinSuc n
≈⟨ μFinPres (ℕ°.+-comm 0 n) ⟩
μFinSuc (n + 0)
≈∎
×-≈ (suc m) n = μFinSuc (suc m) ×μ μFinSuc n
≈⟨ ≈-sym 𝟙+Fin ×μ-cong ≈-refl (μFinSuc n) ⟩
(μ𝟙 +μ μFinSuc m) ×μ μFinSuc n
≈⟨ ×+-distrib μ𝟙 (μFinSuc m) (μFinSuc n) ⟩
(μ𝟙 ×μ μFinSuc n) +μ (μFinSuc m ×μ μFinSuc n)
≈⟨ 𝟙×A≈A {μA = μFinSuc n} +μ-cong ×-≈ m n ⟩
μFinSuc n +μ μFinSuc (n + m * suc n)
≈⟨ +-≈ n (n + m * suc n) ⟩
μFinSuc (n + suc m * suc n)
≈∎
open import Data.Fin using (Fin ; zero ; suc)
Finable : ∀ {A} → SumPropoid A → Set
Finable μA = Σ ℕ λ FinCard → μA ≈ μFinSuc FinCard
𝟙-Finable : Finable μ𝟙
𝟙-Finable = 0 , ≈-sym Fin0≈𝟙
Fin-Finable : ∀ {n} → Finable (μFinSuc n)
Fin-Finable {n} = n , ≈-refl (μFinSuc n)
+-Finable : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B) → Finable μA → Finable μB → Finable (μA +μ μB)
+-Finable μA μB (|A| , A≈) (|B| , B≈) = (|A| + suc |B|) ,
( μA +μ μB
≈⟨ A≈ +μ-cong B≈ ⟩
μFinSuc |A| +μ μFinSuc |B|
≈⟨ +-≈ |A| |B| ⟩
μFinSuc (|A| + suc |B|) ≈∎)
×-Finable : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B) → Finable μA → Finable μB → Finable (μA ×μ μB)
×-Finable μA μB (|A| , A≈) (|B| , B≈) = (|B| + |A| * suc |B|) ,
( μA ×μ μB
≈⟨ A≈ ×μ-cong B≈ ⟩
μFinSuc |A| ×μ μFinSuc |B|
≈⟨ ×-≈ |A| |B| ⟩
μFinSuc (|B| + |A| * suc |B|)
≈∎)
module _ where
open import bijection-fin
open import Data.Fin using (Fin; zero; suc)
open import Data.Vec.NP renaming (sum to vsum)
sumFin : ∀ n → Sum (Fin n)
sumFin n f = vsum (tabulate f)
sumFin-spec : ∀ n → sumFin (suc n) ≗ sum (μFinSuc n)
sumFin-spec zero f = ℕ°.+-comm (f zero) 0
sumFin-spec (suc n) f = ≡.cong (_+_ (f zero)) (sumFin-spec n (f ∘ suc))
sumFinSUI : ∀ n f p → Injective p → sumFin n f ≡ sumFin n (f ∘ p)
sumFinSUI n f p p-inj = count-perm f p (λ _ _ → p-inj)
μFinSUI : ∀ {n} → StableUnderInjection (μFinSuc n)
μFinSUI {n} p f
rewrite ≡.sym (sumFin-spec n (_⟨$⟩_ f))
| ≡.sym (sumFin-spec n (_⟨$⟩_ (f FE.∘ FInj.Injection.to p)))
= sumFinSUI (suc n) (_⟨$⟩_ f) (_⟨$⟩_ (FInj.Injection.to p)) (FInj.Injection.injective p)
StableIfFinable : ∀ {A} (μA : SumProp A) → Finable μA → StableUnderInjection μA
StableIfFinable μA (_ , A≈Fin)
= _≈_.StableUnder≈ (≈-sym A≈Fin) μFinSUI
-- -}
-- -}
| 33.768293
| 142
| 0.513615
|
0be0019e0ebec34d51030a4feee2222104abff7b
| 4,918
|
agda
|
Agda
|
BasicIS4/Semantics/TarskiGluedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIS4/Semantics/TarskiGluedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIS4/Semantics/TarskiGluedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.
-- Tarski-style semantics with contexts as concrete worlds, and glueing for □ only.
-- Hilbert-style syntax.
module BasicIS4.Semantics.TarskiGluedHilbert where
open import BasicIS4.Syntax.Common public
open import Common.Semantics public
-- Intuitionistic Tarski models.
record Model : Set₁ where
infix 3 _⊩ᵅ_ _[⊢]_
field
-- Forcing for atomic propositions; monotonic.
_⊩ᵅ_ : Cx Ty → Atom → Set
mono⊩ᵅ : ∀ {P Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩ᵅ P → Γ′ ⊩ᵅ P
-- Hilbert-style syntax representation; monotonic.
_[⊢]_ : Cx Ty → Ty → Set
mono[⊢] : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ [⊢] A → Γ′ [⊢] A
[var] : ∀ {A Γ} → A ∈ Γ → Γ [⊢] A
[app] : ∀ {A B Γ} → Γ [⊢] A ▻ B → Γ [⊢] A → Γ [⊢] B
[ci] : ∀ {A Γ} → Γ [⊢] A ▻ A
[ck] : ∀ {A B Γ} → Γ [⊢] A ▻ B ▻ A
[cs] : ∀ {A B C Γ} → Γ [⊢] (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
[box] : ∀ {A Γ} → ∅ [⊢] A → Γ [⊢] □ A
[cdist] : ∀ {A B Γ} → Γ [⊢] □ (A ▻ B) ▻ □ A ▻ □ B
[cup] : ∀ {A Γ} → Γ [⊢] □ A ▻ □ □ A
[cdown] : ∀ {A Γ} → Γ [⊢] □ A ▻ A
[cpair] : ∀ {A B Γ} → Γ [⊢] A ▻ B ▻ A ∧ B
[cfst] : ∀ {A B Γ} → Γ [⊢] A ∧ B ▻ A
[csnd] : ∀ {A B Γ} → Γ [⊢] A ∧ B ▻ B
[unit] : ∀ {Γ} → Γ [⊢] ⊤
open Model {{…}} public
-- Forcing in a particular model.
module _ {{_ : Model}} where
infix 3 _⊩_
_⊩_ : Cx Ty → Ty → Set
Γ ⊩ α P = Γ ⊩ᵅ P
Γ ⊩ A ▻ B = ∀ {Γ′} → Γ ⊆ Γ′ → Γ′ ⊩ A → Γ′ ⊩ B
Γ ⊩ □ A = ∀ {Γ′} → Γ ⊆ Γ′ → Glue (Γ′ [⊢] □ A) (Γ′ ⊩ A)
Γ ⊩ A ∧ B = Γ ⊩ A × Γ ⊩ B
Γ ⊩ ⊤ = 𝟙
infix 3 _⊩⋆_
_⊩⋆_ : Cx Ty → Cx Ty → Set
Γ ⊩⋆ ∅ = 𝟙
Γ ⊩⋆ Ξ , A = Γ ⊩⋆ Ξ × Γ ⊩ A
-- Monotonicity with respect to context inclusion.
module _ {{_ : Model}} where
mono⊩ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩ A → Γ′ ⊩ A
mono⊩ {α P} η s = mono⊩ᵅ η s
mono⊩ {A ▻ B} η s = λ η′ → s (trans⊆ η η′)
mono⊩ {□ A} η s = λ η′ → s (trans⊆ η η′)
mono⊩ {A ∧ B} η s = mono⊩ {A} η (π₁ s) , mono⊩ {B} η (π₂ s)
mono⊩ {⊤} η s = ∙
mono⊩⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩⋆ Ξ → Γ′ ⊩⋆ Ξ
mono⊩⋆ {∅} η ∙ = ∙
mono⊩⋆ {Ξ , A} η (ts , t) = mono⊩⋆ {Ξ} η ts , mono⊩ {A} η t
-- Additional useful equipment.
module _ {{_ : Model}} where
_⟪$⟫_ : ∀ {A B Γ} → Γ ⊩ A ▻ B → Γ ⊩ A → Γ ⊩ B
s ⟪$⟫ a = s refl⊆ a
⟪K⟫ : ∀ {A B Γ} → Γ ⊩ A → Γ ⊩ B ▻ A
⟪K⟫ {A} a η = K (mono⊩ {A} η a)
⟪S⟫ : ∀ {A B C Γ} → Γ ⊩ A ▻ B ▻ C → Γ ⊩ A ▻ B → Γ ⊩ A → Γ ⊩ C
⟪S⟫ {A} {B} {C} s₁ s₂ a = _⟪$⟫_ {B} {C} (_⟪$⟫_ {A} {B ▻ C} s₁ a) (_⟪$⟫_ {A} {B} s₂ a)
⟪S⟫′ : ∀ {A B C Γ} → Γ ⊩ A ▻ B ▻ C → Γ ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ {A} {B} {C} s₁ η s₂ η′ a = let s₁′ = mono⊩ {A ▻ B ▻ C} (trans⊆ η η′) s₁
s₂′ = mono⊩ {A ▻ B} η′ s₂
in ⟪S⟫ {A} {B} {C} s₁′ s₂′ a
_⟪D⟫_ : ∀ {A B Γ} → Γ ⊩ □ (A ▻ B) → Γ ⊩ □ A → Γ ⊩ □ B
_⟪D⟫_ {A} {B} s₁ s₂ η = let t ⅋ s₁′ = s₁ η
u ⅋ a = s₂ η
in [app] ([app] [cdist] t) u ⅋ _⟪$⟫_ {A} {B} s₁′ a
_⟪D⟫′_ : ∀ {A B Γ} → Γ ⊩ □ (A ▻ B) → Γ ⊩ □ A ▻ □ B
_⟪D⟫′_ {A} {B} s₁ η = _⟪D⟫_ (mono⊩ {□ (A ▻ B)} η s₁)
⟪↑⟫ : ∀ {A Γ} → Γ ⊩ □ A → Γ ⊩ □ □ A
⟪↑⟫ s η = [app] [cup] (syn (s η)) ⅋ λ η′ → s (trans⊆ η η′)
⟪↓⟫ : ∀ {A Γ} → Γ ⊩ □ A → Γ ⊩ A
⟪↓⟫ s = sem (s refl⊆)
_⟪,⟫′_ : ∀ {A B Γ} → Γ ⊩ A → Γ ⊩ B ▻ A ∧ B
_⟪,⟫′_ {A} {B} a η = _,_ (mono⊩ {A} η a)
-- Forcing in a particular world of a particular model, for sequents.
module _ {{_ : Model}} where
infix 3 _⊩_⇒_
_⊩_⇒_ : Cx Ty → Cx Ty → Ty → Set
w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A
infix 3 _⊩_⇒⋆_
_⊩_⇒⋆_ : Cx Ty → Cx Ty → Cx Ty → Set
w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ
-- Entailment, or forcing in all worlds of all models, for sequents.
infix 3 _⊨_
_⊨_ : Cx Ty → Ty → Set₁
Γ ⊨ A = ∀ {{_ : Model}} {w : Cx Ty} → w ⊩ Γ ⇒ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx Ty → Cx Ty → Set₁
Γ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : Cx Ty} → w ⊩ Γ ⇒⋆ Ξ
-- Additional useful equipment, for sequents.
module _ {{_ : Model}} where
lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
_⟦$⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B
_⟦$⟧_ {A} {B} s₁ s₂ γ = _⟪$⟫_ {A} {B} (s₁ γ) (s₂ γ)
⟦K⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B ▻ A
⟦K⟧ {A} {B} a γ = ⟪K⟫ {A} {B} (a γ)
⟦S⟧ : ∀ {A B C Γ w} → w ⊩ Γ ⇒ A ▻ B ▻ C → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ C
⟦S⟧ {A} {B} {C} s₁ s₂ a γ = ⟪S⟫ {A} {B} {C} (s₁ γ) (s₂ γ) (a γ)
_⟦D⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ □ (A ▻ B) → w ⊩ Γ ⇒ □ A → w ⊩ Γ ⇒ □ B
(s₁ ⟦D⟧ s₂) γ = (s₁ γ) ⟪D⟫ (s₂ γ)
⟦↑⟧ : ∀ {A Γ w} → w ⊩ Γ ⇒ □ A → w ⊩ Γ ⇒ □ □ A
⟦↑⟧ s γ = ⟪↑⟫ (s γ)
⟦↓⟧ : ∀ {A Γ w} → w ⊩ Γ ⇒ □ A → w ⊩ Γ ⇒ A
⟦↓⟧ s γ = ⟪↓⟫ (s γ)
_⟦,⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B → w ⊩ Γ ⇒ A ∧ B
(a ⟦,⟧ b) γ = a γ , b γ
⟦π₁⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ A
⟦π₁⟧ s γ = π₁ (s γ)
⟦π₂⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ B
⟦π₂⟧ s γ = π₂ (s γ)
| 30.171779
| 87
| 0.375356
|
4ddf0f5570945680f97f490fc3691cee7b02c8e5
| 121
|
agda
|
Agda
|
notes/papers/implicit/examples/Simple.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
notes/papers/implicit/examples/Simple.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
notes/papers/implicit/examples/Simple.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Simple where
postulate
Nat : Set
zero : Nat
-- we want
-- ?0 zero = zero
-- and then
-- ?0 x = x
| 9.307692
| 19
| 0.528926
|
417a03ff6f157e5c75ee1074c38d2a30e945a741
| 415
|
agda
|
Agda
|
src/Debug.agda
|
Zalastax/singly-typed-actors
|
ae541df13d069df4eb1464f29fbaa9804aad439f
|
[
"MIT"
] | 1
|
2019-10-29T09:30:26.000Z
|
2019-10-29T09:30:26.000Z
|
src/Debug.agda
|
Zalastax/singly-typed-actors
|
ae541df13d069df4eb1464f29fbaa9804aad439f
|
[
"MIT"
] | null | null | null |
src/Debug.agda
|
Zalastax/singly-typed-actors
|
ae541df13d069df4eb1464f29fbaa9804aad439f
|
[
"MIT"
] | null | null | null |
module Debug where
open import Data.String using (String) public
open import Level public
{-# FOREIGN GHC import qualified Data.Text #-}
{-# FOREIGN GHC import qualified Debug.Trace as Trace #-}
{-# FOREIGN GHC
debug' :: Data.Text.Text -> c -> c
debug' txt c = Trace.trace (Data.Text.unpack txt) c
#-}
postulate debug : {a : Level} {A : Set a} → String → A → A
{-# COMPILE GHC debug = (\x -> (\y -> debug')) #-}
| 27.666667
| 58
| 0.650602
|
39529018339db884ed4bb6615840b16f8a3642a8
| 1,226
|
agda
|
Agda
|
src/fot/PA/Inductive/Relation/Binary/PropositionalEquality.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/PA/Inductive/Relation/Binary/PropositionalEquality.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/PA/Inductive/Relation/Binary/PropositionalEquality.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Propositional equality on inductive PA
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This file contains some definitions which are reexported by
-- PA.Inductive.Base.
module PA.Inductive.Relation.Binary.PropositionalEquality where
open import Common.FOL.FOL using ( ¬_ )
open import PA.Inductive.Base.Core
infix 4 _≡_ _≢_
------------------------------------------------------------------------------
-- The identity type on PA.
data _≡_ (x : ℕ) : ℕ → Set where
refl : x ≡ x
-- Inequality.
_≢_ : ℕ → ℕ → Set
x ≢ y = ¬ x ≡ y
{-# ATP definition _≢_ #-}
-- Identity properties
sym : ∀ {x y} → x ≡ y → y ≡ x
sym refl = refl
trans : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z
trans refl h = h
subst : (A : ℕ → Set) → ∀ {x y} → x ≡ y → A x → A y
subst A refl Ax = Ax
cong : (f : ℕ → ℕ) → ∀ {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
cong₂ : (f : ℕ → ℕ → ℕ) → ∀ {x x' y y'} → x ≡ y → x' ≡ y' → f x x' ≡ f y y'
cong₂ f refl refl = refl
| 26.652174
| 78
| 0.445351
|
120fa9396e7562912731a14c1bf4f3535500c7b5
| 11,024
|
agda
|
Agda
|
Numbers/Naturals/Order.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Numbers/Naturals/Order.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Numbers/Naturals/Order.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Semirings.Definition
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Semiring
open import Orders.Total.Definition
open import Orders.Partial.Definition
module Numbers.Naturals.Order where
open Semiring ℕSemiring
open import Decidable.Lemmas ℕDecideEquality
private
infix 5 _<NLogical_
_<NLogical_ : ℕ → ℕ → Set
zero <NLogical zero = False
zero <NLogical (succ n) = True
(succ n) <NLogical zero = False
(succ n) <NLogical (succ m) = n <NLogical m
infix 5 _<N_
record _<N_ (a : ℕ) (b : ℕ) : Set where
constructor le
field
x : ℕ
proof : (succ x) +N a ≡ b
infix 5 _<N'_
record _<N'_ (a : ℕ) (b : ℕ) : Set where
constructor le'
field
x : ℕ
.proof : (succ x) +N a ≡ b
infix 5 _≤N_
_≤N_ : ℕ → ℕ → Set
a ≤N b = (a <N b) || (a ≡ b)
succIsPositive : (a : ℕ) → zero <N succ a
succIsPositive a = le a (applyEquality succ (Semiring.commutative ℕSemiring a 0))
aLessSucc : (a : ℕ) → (a <NLogical succ a)
aLessSucc zero = record {}
aLessSucc (succ a) = aLessSucc a
private
succPreservesInequalityLogical : {a b : ℕ} → (a <NLogical b) → (succ a <NLogical succ b)
succPreservesInequalityLogical {a} {b} prAB = prAB
lessTransitiveLogical : {a b c : ℕ} → (a <NLogical b) → (b <NLogical c) → (a <NLogical c)
lessTransitiveLogical {a} {zero} {zero} prAB prBC = prAB
lessTransitiveLogical {a} {(succ b)} {zero} prAB ()
lessTransitiveLogical {zero} {zero} {(succ c)} prAB prBC = record {}
lessTransitiveLogical {(succ a)} {zero} {(succ c)} () prBC
lessTransitiveLogical {zero} {(succ b)} {(succ c)} prAB prBC = record {}
lessTransitiveLogical {(succ a)} {(succ b)} {(succ c)} prAB prBC = lessTransitiveLogical {a} {b} {c} prAB prBC
aLessXPlusSuccA : (a x : ℕ) → (a <NLogical x +N succ a)
aLessXPlusSuccA a zero = aLessSucc a
aLessXPlusSuccA zero (succ x) = record {}
aLessXPlusSuccA (succ a) (succ x) = lessTransitiveLogical {a} {succ a} {x +N succ (succ a)} (aLessXPlusSuccA a zero) (aLessXPlusSuccA (succ a) x)
leImpliesLogical<N : {a b : ℕ} → (a <N b) → (a <NLogical b)
leImpliesLogical<N {zero} {zero} (le x ())
leImpliesLogical<N {zero} {(succ b)} (le x proof) = record {}
leImpliesLogical<N {(succ a)} {zero} (le x ())
leImpliesLogical<N {(succ a)} {(succ .(succ a))} (le zero refl) = aLessSucc a
leImpliesLogical<N {(succ a)} {(succ .(succ (x +N succ a)))} (le (succ x) refl) = succPreservesInequalityLogical {a} {succ (x +N succ a)} (lessTransitiveLogical {a} {succ a} {succ (x +N succ a)} (aLessSucc a) (aLessXPlusSuccA a x))
logical<NImpliesLe : {a b : ℕ} → (a <NLogical b) → (a <N b)
logical<NImpliesLe {zero} {zero} ()
_<N_.x (logical<NImpliesLe {zero} {succ b} prAB) = b
_<N_.proof (logical<NImpliesLe {zero} {succ b} prAB) = applyEquality succ (sumZeroRight b)
logical<NImpliesLe {(succ a)} {zero} ()
logical<NImpliesLe {(succ a)} {(succ b)} prAB with logical<NImpliesLe {a} prAB
logical<NImpliesLe {(succ a)} {(succ .(succ (x +N a)))} prAB | le x refl = le x (applyEquality succ (transitivity (commutative x _) (applyEquality succ (commutative a _))))
lessTransitive : {a b c : ℕ} → (a <N b) → (b <N c) → (a <N c)
lessTransitive {a} {b} {c} prab prbc = logical<NImpliesLe (lessTransitiveLogical {a} {b} {c} (leImpliesLogical<N prab) (leImpliesLogical<N prbc))
lessIrreflexive : {a : ℕ} → (a <N a) → False
lessIrreflexive {zero} pr = leImpliesLogical<N pr
lessIrreflexive {succ a} pr = lessIrreflexive {a} (logical<NImpliesLe {a} {a} (leImpliesLogical<N {succ a} {succ a} pr))
succPreservesInequality : {a b : ℕ} → (a <N b) → (succ a <N succ b)
succPreservesInequality {a} {b} prAB = logical<NImpliesLe (succPreservesInequalityLogical {a} {b} (leImpliesLogical<N prAB))
canRemoveSuccFrom<N : {a b : ℕ} → (succ a <N succ b) → (a <N b)
canRemoveSuccFrom<N {a} {b} (le x proof) rewrite commutative x (succ a) | commutative a x = le x (succInjective proof)
a<SuccA : (a : ℕ) → a <N succ a
a<SuccA a = le zero refl
<NWellDefined : {a b : ℕ} → (p1 : a <N b) → (p2 : a <N b) → _<N_.x p1 ≡ _<N_.x p2
<NWellDefined {a} {b} (le x proof) (le y proof1) = equalityCommutative r
where
q : y +N a ≡ x +N a
q = succInjective {y +N a} {x +N a} (transitivity proof1 (equalityCommutative proof))
r : y ≡ x
r = canSubtractFromEqualityRight q
canAddToOneSideOfInequality : {a b : ℕ} (c : ℕ) → a <N b → a <N (b +N c)
canAddToOneSideOfInequality {a} {b} c (le x proof) = le (x +N c) (transitivity (applyEquality succ (equalityCommutative (+Associative x c a))) (transitivity (applyEquality (λ i → (succ x) +N i) (commutative c a)) (transitivity (applyEquality succ (+Associative x a c)) (applyEquality (_+N c) proof))))
canAddToOneSideOfInequality' : {a b : ℕ} (c : ℕ) → a <N b → a <N (c +N b)
canAddToOneSideOfInequality' {a} {b} c (le x proof) = le (x +N c) ans
where
ans : succ ((x +N c) +N a) ≡ c +N b
ans rewrite (equalityCommutative (+Associative x c a)) | commutative c a | (+Associative x a c) = transitivity (applyEquality (_+N c) proof) (commutative b c)
addingIncreases : (a b : ℕ) → a <N a +N succ b
addingIncreases zero b = succIsPositive b
addingIncreases (succ a) b = succPreservesInequality (addingIncreases a b)
zeroNeverGreater : {a : ℕ} → (a <N zero) → False
zeroNeverGreater {a} (le x ())
noIntegersBetweenXAndSuccX : {a : ℕ} (x : ℕ) → (x <N a) → (a <N succ x) → False
noIntegersBetweenXAndSuccX {zero} x x<a a<sx = zeroNeverGreater x<a
noIntegersBetweenXAndSuccX {succ a} x (le y proof) (le z proof1) with succInjective proof1
... | ah rewrite (equalityCommutative proof) | (succExtracts z (y +N x)) | +Associative (succ z) y x | commutative (succ (z +N y)) x = lessIrreflexive {x} (le (z +N y) (transitivity (commutative _ x) ah))
private
orderIsTotal : (a b : ℕ) → ((a <N b) || (b <N a)) || (a ≡ b)
orderIsTotal zero zero = inr refl
orderIsTotal zero (succ b) = inl (inl (logical<NImpliesLe (record {})))
orderIsTotal (succ a) zero = inl (inr (logical<NImpliesLe (record {})))
orderIsTotal (succ a) (succ b) with orderIsTotal a b
orderIsTotal (succ a) (succ b) | inl (inl x) = inl (inl (logical<NImpliesLe (leImpliesLogical<N x)))
orderIsTotal (succ a) (succ b) | inl (inr x) = inl (inr (logical<NImpliesLe (leImpliesLogical<N x)))
orderIsTotal (succ a) (succ b) | inr x = inr (applyEquality succ x)
orderIsIrreflexive : {a b : ℕ} → (a <N b) → (b <N a) → False
orderIsIrreflexive {zero} {b} prAB (le x ())
orderIsIrreflexive {(succ a)} {zero} (le x ()) prBA
orderIsIrreflexive {(succ a)} {(succ b)} prAB prBA = orderIsIrreflexive {a} {b} (logical<NImpliesLe (leImpliesLogical<N prAB)) (logical<NImpliesLe (leImpliesLogical<N prBA))
orderIsTransitive : {a b c : ℕ} → (a <N b) → (b <N c) → (a <N c)
orderIsTransitive {a} {.(succ (x +N a))} {.(succ (y +N succ (x +N a)))} (le x refl) (le y refl) = le (y +N succ x) (applyEquality succ (equalityCommutative (+Associative y (succ x) a)))
ℕTotalOrder : TotalOrder ℕ
PartialOrder._<_ (TotalOrder.order ℕTotalOrder) = _<N_
PartialOrder.irreflexive (TotalOrder.order ℕTotalOrder) = lessIrreflexive
PartialOrder.<Transitive (TotalOrder.order ℕTotalOrder) = orderIsTransitive
TotalOrder.totality ℕTotalOrder = orderIsTotal
cannotAddAndEnlarge : (a b : ℕ) → a <N succ (a +N b)
cannotAddAndEnlarge a b = le b (applyEquality succ (commutative b a))
cannotAddAndEnlarge' : {a b : ℕ} → a +N b <N a → False
cannotAddAndEnlarge' {a} {zero} pr rewrite sumZeroRight a = lessIrreflexive pr
cannotAddAndEnlarge' {a} {succ b} pr rewrite (succExtracts a b) = lessIrreflexive {a} (lessTransitive {a} {succ (a +N b)} {a} (cannotAddAndEnlarge a b) pr)
cannotAddAndEnlarge'' : {a b : ℕ} → a +N succ b ≡ a → False
cannotAddAndEnlarge'' {a} {b} pr = naughtE (equalityCommutative inter)
where
inter : succ b ≡ 0
inter rewrite commutative a (succ b) = canSubtractFromEqualityRight pr
naturalsAreNonnegative : (a : ℕ) → (a <N zero) → False
naturalsAreNonnegative zero ()
naturalsAreNonnegative (succ x) ()
lessRespectsAddition : {a b : ℕ} (c : ℕ) → (a <N b) → ((a +N c) <N (b +N c))
lessRespectsAddition {a} {b} zero prAB rewrite commutative a 0 | commutative b 0 = prAB
lessRespectsAddition {a} {b} (succ c) prAB rewrite commutative a (succ c) | commutative b (succ c) | commutative c a | commutative c b = succPreservesInequality (lessRespectsAddition c prAB)
lessRespectsMultiplicationLeft : (a b c : ℕ) → (a <N b) → (zero <N c) → (c *N a <N c *N b)
lessRespectsMultiplicationLeft zero zero c (le x ()) cPos
lessRespectsMultiplicationLeft zero (succ b) zero prAB (le x ())
lessRespectsMultiplicationLeft zero (succ b) (succ c) prAB cPos = i
where
productNonzeroIsNonzero : {a b : ℕ} → zero <N a → zero <N b → zero <N a *N b
productNonzeroIsNonzero {zero} {b} prA prB = prA
productNonzeroIsNonzero {succ a} {zero} prA ()
productNonzeroIsNonzero {succ a} {succ b} prA prB = le (b +N a *N succ b) (applyEquality succ (Semiring.sumZeroRight ℕSemiring _))
j : zero <N succ c *N succ b
j = productNonzeroIsNonzero cPos prAB
i : succ c *N zero <N succ c *N succ b
i = identityOfIndiscernablesLeft _<N_ j (equalityCommutative (productZeroRight c))
lessRespectsMultiplicationLeft (succ a) zero c (le x ()) cPos
lessRespectsMultiplicationLeft (succ a) (succ b) c prAB cPos = m
where
h : c *N a <N c *N b
h = lessRespectsMultiplicationLeft a b c (canRemoveSuccFrom<N prAB) cPos
j : c *N a +N c <N c *N b +N c
j = lessRespectsAddition c h
i : c *N succ a <N c *N b +N c
i = identityOfIndiscernablesLeft _<N_ j (equalityCommutative (transitivity (multiplicationNIsCommutative c _) (transitivity (applyEquality (c +N_) (multiplicationNIsCommutative a _)) (commutative c _))))
m : c *N succ a <N c *N succ b
m = identityOfIndiscernablesRight _<N_ i (equalityCommutative (transitivity (multiplicationNIsCommutative c _) (transitivity (commutative c _) (applyEquality (_+N c) (multiplicationNIsCommutative b _)))))
canFlipMultiplicationsInIneq : {a b c d : ℕ} → (a *N b <N c *N d) → b *N a <N d *N c
canFlipMultiplicationsInIneq {a} {b} {c} {d} pr = identityOfIndiscernablesRight _<N_ (identityOfIndiscernablesLeft _<N_ pr (multiplicationNIsCommutative a b)) (multiplicationNIsCommutative c d)
lessRespectsMultiplication : (a b c : ℕ) → (a <N b) → (zero <N c) → (a *N c <N b *N c)
lessRespectsMultiplication a b c prAB cPos = canFlipMultiplicationsInIneq {c} {a} {c} {b} (lessRespectsMultiplicationLeft a b c prAB cPos)
squash<N : {a b : ℕ} → .(a <N b) → a <N b
squash<N {a} {b} a<b with orderIsTotal a b
... | inl (inl x) = x
... | inl (inr x) = exFalso (lessIrreflexive (orderIsTransitive x a<b))
squash<N {a} {b} a<b | inr refl = exFalso (lessIrreflexive a<b)
<NTo<N' : {a b : ℕ} → a <N b → a <N' b
<NTo<N' (le x proof) = le' x proof
<N'To<N : {a b : ℕ} → a <N' b → a <N b
<N'To<N {a} {b} (le' x proof) = le x (squash proof)
<N'Refl : {a b : ℕ} → (p1 p2 : a <N' b) → p1 ≡ p2
<N'Refl p1 p2 with <NWellDefined (<N'To<N p1) (<N'To<N p2)
... | refl = refl
| 51.037037
| 301
| 0.669267
|
5903026568cb11255c60d117dc35ff26299aea13
| 11,355
|
agda
|
Agda
|
LibraBFT/Concrete/Properties/VotesOnce.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/Properties/VotesOnce.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/Properties/VotesOnce.agda
|
cwjnkins/bft-consensus-agda
|
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Handle
open import LibraBFT.Impl.Handle.Properties
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Concrete.System
open EpochConfig
open import LibraBFT.Yasm.Types
open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms PeerCanSignForPK (λ {st} {part} {pk} → PeerCanSignForPK-stable {st} {part} {pk})
-- In this module, we define two "implementation obligations"
-- (ImplObligationᵢ for i ∈ {1 , 2}), which are predicates over
-- reachable states of a system defined by
-- 'LibraBFT.Concrete.System.Parameters'. These two properties relate
-- votes sent by the same sender, ensuring that if they are for the
-- same epoch and round, then they vote for the same blockID; the
-- first relates a vote output by the handler to a vote sent
-- previously, and the second relates two votes both sent by the
-- handler.
--
-- We then prove that, if an implementation satisfies these two
-- semantic obligations, along with a structural one about messages
-- sent by honest peers in the implementation, then the implemenation
-- satisfies the LibraBFT.Abstract.Properties.VotesOnce invariant.
module LibraBFT.Concrete.Properties.VotesOnce where
-- TODO-3: This may not be the best way to state the implementation obligation. Why not reduce
-- this as much as possible before giving the obligation to the implementation? For example, this
-- will still require the implementation to deal with hash collisons (v and v' could be different,
-- but yield the same bytestring and therefore same signature). Also, avoid the need for the
-- implementation to reason about messages sent by step-cheat, or give it something to make this
-- case easy to eliminate.
ImplObligation₁ : Set (ℓ+1 ℓ-RoundManager)
ImplObligation₁ =
∀{pid pid' s' outs pk}{pre : SystemState}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs))
→ ∀{v m v' m'} → Meta-Honest-PK pk
-- For signed every vote v of every outputted message
→ v ⊂Msg m → send m ∈ outs
→ (sig : WithVerSig pk v) → ¬ (∈GenInfo (ver-signature sig))
-- If v is really new and valid
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v pid pk
-- And if there exists another v' that has been sent before
→ v' ⊂Msg m' → (pid' , m') ∈ (msgPool pre)
→ (sig' : WithVerSig pk v') → ¬ (∈GenInfo (ver-signature sig'))
-- If v and v' share the same epoch and round
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
----------------------------------------------------------
-- Then an honest implemenation promises v and v' vote for the same blockId.
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
ImplObligation₂ : Set (ℓ+1 ℓ-RoundManager)
ImplObligation₂ =
∀{pid s' outs pk}{pre : SystemState}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs))
→ ∀{v m v' m'}
→ Meta-Honest-PK pk
-- For every vote v represented in a message output by the call
→ v ⊂Msg m → send m ∈ outs
→ (sig : WithVerSig pk v) → ¬ (∈GenInfo (ver-signature sig))
-- If v is really new and valid
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v pid pk
-- And if there exists another v' that is also new and valid
→ v' ⊂Msg m' → send m' ∈ outs
→ (sig' : WithVerSig pk v') → ¬ (∈GenInfo (ver-signature sig'))
→ ¬ (MsgWithSig∈ pk (ver-signature sig') (msgPool pre)) → PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v' pid pk
-- If v and v' share the same epoch and round
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
----------------------------------------------------------
-- Then, an honest implemenation promises v and v' vote for the same blockId.
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
-- Next, we prove that, given the necessary obligations,
module Proof
(sps-corr : StepPeerState-AllValidParts)
(Impl-VO1 : ImplObligation₁)
(Impl-VO2 : ImplObligation₂)
where
-- Any reachable state satisfies the VO rule for any epoch in the system.
module _ (st : SystemState)(r : ReachableSystemState st)(𝓔 : EpochConfig) where
open Structural sps-corr
-- Bring in IntSystemState
open WithSPS sps-corr
open PerState st r
open PerEpoch 𝓔
open import LibraBFT.Concrete.Obligations.VotesOnce 𝓔 (ConcreteVoteEvidence 𝓔) as VO
-- The VO proof is done by induction on the execution trace leading to 'st'. In
-- Agda, this is 'r : RechableSystemState st' above.
private
-- From this point onwards, it might be easier to read this proof starting at 'voo'
-- at the end of the file. Next, we provide an overview the proof.
--
-- We wish to prove that, for any two votes v and v' cast by an honest α in the message
-- pool of a state st, if v and v' have equal rounds and epochs, then they vote for the
-- same block.
--
-- The base case and the case for a new epoch in the system are trivial. For the base case
-- we get to a contradiction because it's not possible to have any message in the msgpool.
--
-- Regarding the PeerStep case. The induction hypothesis tells us that the property holds
-- in the pre-state. Next, we reason about the post-state. We start by analyzing whether
-- v and v' have been sent as outputs of the PeerStep under scrutiny or were already in
-- the pool before.
--
-- There are four possibilities:
--
-- i) v and v' were aleady present in the msgPool before: use induction hypothesis.
-- ii) v and v' are both in the output produced by the PeerStep under scrutiny.
-- iii) v was present before, but v' is new.
-- iv) v' was present before, but v is new.
--
-- In order to obtain this four possiblities we invoke newMsg⊎msgSent4 lemma, which
-- receives proof that some vote is in a message that is in the msgPool of the post state
-- and returns evidence that either the vote is new or that some message with the same
-- signature was sent before.
--
-- Case (i) is trivial; cases (iii) and (iv) are symmetric and reduce to an implementation
-- obligation (Impl-VO1) and case (ii) reduces to a different implementation obligation
-- (Impl-VO2).
VotesOnceProof :
∀ {v v' pk} {st : SystemState}
→ ReachableSystemState st
→ Meta-Honest-PK pk
→ (vv : WithVerSig pk v) → MsgWithSig∈ pk (ver-signature vv) (msgPool st)
→ (vv' : WithVerSig pk v') → MsgWithSig∈ pk (ver-signature vv') (msgPool st)
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
VotesOnceProof step-0 _ _ msv _ _ _ _ = ⊥-elim (¬Any[] (msg∈pool msv))
VotesOnceProof {v} {v'} (step-s r theStep) pkH vv msv vv' msv' eid≡ r≡
with msgSameSig msv | msgSameSig msv'
...| refl | refl
with sameSig⇒sameVoteDataNoCol (msgSigned msv) vv (msgSameSig msv )
| sameSig⇒sameVoteDataNoCol (msgSigned msv') vv' (msgSameSig msv')
...| refl | refl
with ∈GenInfo? (₋vSignature (msgPart msv)) | ∈GenInfo? (₋vSignature (msgPart msv'))
...| yes init | yes init' = genVotesConsistent (msgPart msv) (msgPart msv') init init'
-- A signature in GenInfo is for a vote with round 0, and a signature for which we have a
-- MsgWithSig∈ that is not in GenInfo and is for an honest PK is for a round ≢ 0, so we can
-- derive a contradiction using r≡.
...| yes init | no ¬init = ⊥-elim (¬genVotesRound≢0 (step-s r theStep) pkH msv' ¬init ((trans (sym r≡) (genVotesRound≡0 vv init))))
...| no ¬init | yes init = ⊥-elim (¬genVotesRound≢0 (step-s r theStep) pkH msv ¬init ((trans r≡ (genVotesRound≡0 vv' init))))
...| no ¬init | no ¬init'
with theStep
...| step-peer cheat@(step-cheat c)
with ¬cheatForgeNew cheat refl unit pkH msv ¬init
| ¬cheatForgeNew cheat refl unit pkH msv' ¬init'
...| msb4 | m'sb4
with msgSameSig msb4 | msgSameSig m'sb4
...| refl | refl = VotesOnceProof r pkH vv msb4 vv' m'sb4 eid≡ r≡
VotesOnceProof (step-s r theStep) pkH vv msv vv' msv' eid≡ r≡
| refl | refl
| refl | refl
| no ¬init | no ¬init'
| step-peer (step-honest stPeer)
with newMsg⊎msgSentB4 r stPeer pkH (msgSigned msv) ¬init (msg⊆ msv) (msg∈pool msv)
| newMsg⊎msgSentB4 r stPeer pkH (msgSigned msv') ¬init' (msg⊆ msv') (msg∈pool msv')
...| inj₂ msb4 | inj₂ m'sb4
= VotesOnceProof r pkH vv msb4 vv' m'sb4 eid≡ r≡
...| inj₁ (m∈outs , vspk , newV) | inj₁ (m'∈outs , v'spk , newV')
= Impl-VO2 r stPeer pkH (msg⊆ msv) m∈outs (msgSigned msv) ¬init newV vspk
(msg⊆ msv') m'∈outs (msgSigned msv') ¬init' newV' v'spk eid≡ r≡
...| inj₁ (m∈outs , vspk , newV) | inj₂ m'sb4
with sameSig⇒sameVoteData (msgSigned m'sb4) vv' (msgSameSig m'sb4)
...| inj₁ hb = ⊥-elim (meta-sha256-cr hb)
...| inj₂ refl rewrite sym (msgSameSig msv')
= Impl-VO1 r stPeer pkH (msg⊆ msv) m∈outs (msgSigned msv) ¬init newV vspk
(msg⊆ m'sb4) (msg∈pool m'sb4) (msgSigned m'sb4) (¬subst ¬init' (msgSameSig m'sb4)) eid≡ r≡
VotesOnceProof (step-s r theStep) pkH vv msv vv' msv' eid≡ r≡
| refl | refl
| refl | refl
| no ¬init | no ¬init'
| step-peer (step-honest stPeer)
| inj₂ msb4 | inj₁ (m'∈outs , v'spk , newV')
with sameSig⇒sameVoteData (msgSigned msb4) vv (msgSameSig msb4)
...| inj₁ hb = ⊥-elim (meta-sha256-cr hb)
...| inj₂ refl
= sym (Impl-VO1 r stPeer pkH (msg⊆ msv') m'∈outs (msgSigned msv') ¬init' newV' v'spk
(msg⊆ msb4) (msg∈pool msb4) (msgSigned msb4) (¬subst ¬init (msgSameSig msb4)) (sym eid≡) (sym r≡))
voo : VO.Type IntSystemState
voo hpk refl sv refl sv' round≡
with vmsg≈v (vmFor sv) | vmsg≈v (vmFor sv')
...| refl | refl
= let ver = vmsgSigned (vmFor sv)
mswsv = mkMsgWithSig∈ (nm (vmFor sv)) (cv (vmFor sv)) (cv∈nm (vmFor sv))
_ (nmSentByAuth sv) (vmsgSigned (vmFor sv)) refl
ver' = vmsgSigned (vmFor sv')
mswsv' = mkMsgWithSig∈ (nm (vmFor sv')) (cv (vmFor sv')) (cv∈nm (vmFor sv'))
_ (nmSentByAuth sv') (vmsgSigned (vmFor sv')) refl
epoch≡ = trans (vmsgEpoch (vmFor sv)) (sym (vmsgEpoch (vmFor sv')))
in VotesOnceProof r hpk ver mswsv ver' mswsv' epoch≡ round≡
| 50.466667
| 146
| 0.644562
|
1cf2e974757279808ed2b1771fdbaa98afe5afeb
| 99
|
agda
|
Agda
|
Cubical/HITs/Wedge.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/HITs/Wedge.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/HITs/Wedge.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.HITs.Wedge where
open import Cubical.HITs.Wedge.Base public
| 19.8
| 42
| 0.747475
|
dcb7eaaa01f5b2e84e78ec50127ee0b84bc04f30
| 2,003
|
agda
|
Agda
|
src/Similarity/Equational-reasoning-instances.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Similarity/Equational-reasoning-instances.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Similarity/Equational-reasoning-instances.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- "Equational" reasoning combinator setup
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude.Size
open import Labelled-transition-system
module Similarity.Equational-reasoning-instances
{ℓ} {lts : LTS ℓ} {i : Size} where
open import Prelude
open import Bisimilarity lts
open import Equational-reasoning
open import Similarity lts
instance
reflexive≤ : Reflexive [ i ]_≤_
reflexive≤ = is-reflexive reflexive-≤
reflexive≤′ : Reflexive [ i ]_≤′_
reflexive≤′ = is-reflexive reflexive-≤′
convert≤≤ : Convertible [ i ]_≤_ [ i ]_≤_
convert≤≤ = is-convertible id
convert≤′≤ : Convertible _≤′_ [ i ]_≤_
convert≤′≤ = is-convertible λ p≤′q → force p≤′q
convert≤≤′ : Convertible [ i ]_≤_ [ i ]_≤′_
convert≤≤′ = is-convertible lemma
where
lemma : ∀ {p q} → [ i ] p ≤ q → [ i ] p ≤′ q
force (lemma p≤q) = p≤q
convert≤′≤′ : Convertible [ i ]_≤′_ [ i ]_≤′_
convert≤′≤′ = is-convertible id
convert∼≤ : Convertible [ i ]_∼_ [ i ]_≤_
convert∼≤ = is-convertible ∼⇒≤
convert∼′≤ : Convertible _∼′_ [ i ]_≤_
convert∼′≤ = is-convertible (convert ∘ ∼⇒≤′)
convert∼≤′ : ∀ {i} → Convertible [ i ]_∼_ [ i ]_≤′_
convert∼≤′ {i} = is-convertible lemma
where
lemma : ∀ {p q} → [ i ] p ∼ q → [ i ] p ≤′ q
force (lemma p∼q) = ∼⇒≤ p∼q
convert∼′≤′ : ∀ {i} → Convertible [ i ]_∼′_ [ i ]_≤′_
convert∼′≤′ = is-convertible ∼⇒≤′
trans≤≤ : Transitive [ i ]_≤_ [ i ]_≤_
trans≤≤ = is-transitive transitive-≤
trans≤′≤ : Transitive _≤′_ [ i ]_≤_
trans≤′≤ = is-transitive λ p≤′q → transitive (force p≤′q)
trans≤′≤′ : Transitive [ i ]_≤′_ [ i ]_≤′_
trans≤′≤′ = is-transitive transitive-≤′
trans≤≤′ : Transitive [ i ]_≤_ [ i ]_≤′_
trans≤≤′ = is-transitive lemma
where
lemma : ∀ {p q r} → [ i ] p ≤ q → [ i ] q ≤′ r → [ i ] p ≤′ r
force (lemma p≤q q≤′r) = transitive-≤ p≤q (force q≤′r)
| 27.819444
| 72
| 0.533699
|
c567557fed7a03962899d8717d698129ec1d0313
| 6,429
|
agda
|
Agda
|
Cubical/Core/Primitives.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Core/Primitives.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Core/Primitives.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-
This file document and export the main primitives of Cubical Agda. It
also defines some basic derived operations (composition and filling).
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Core.Primitives where
open import Agda.Builtin.Cubical.Path public
open import Agda.Builtin.Cubical.Sub public
renaming ( inc to inS
; primSubOut to outS
)
open import Agda.Primitive.Cubical public
renaming ( primIMin to _∧_ -- I → I → I
; primIMax to _∨_ -- I → I → I
; primINeg to ~_ -- I → I
; isOneEmpty to empty
; primComp to comp
; primHComp to hcomp
; primTransp to transp
; itIsOne to 1=1 )
-- These two are to make sure all the primitives are loaded and ready
-- to compute hcomp/transp for the universe.
import Agda.Builtin.Cubical.Glue
-- HCompU is already imported from Glue, and older Agda versions do
-- not have it. So we comment it out for now.
-- import Agda.Builtin.Cubical.HCompU
open import Agda.Primitive public
using ( Level )
renaming ( lzero to ℓ-zero
; lsuc to ℓ-suc
; _⊔_ to ℓ-max
; Set to Type
; Setω to Typeω )
open import Agda.Builtin.Sigma public
-- This file document the Cubical Agda primitives. The primitives
-- themselves are bound by the Agda files imported above.
-- * The Interval
-- I : Typeω
-- Endpoints, Connections, Reversal
-- i0 i1 : I
-- _∧_ _∨_ : I → I → I
-- ~_ : I → I
-- * Dependent path type. (Path over Path)
-- Introduced with lambda abstraction and eliminated with application,
-- just like function types.
-- PathP : ∀ {ℓ} (A : I → Type ℓ) → A i0 → A i1 → Type ℓ
infix 4 _[_≡_]
_[_≡_] : ∀ {ℓ} (A : I → Type ℓ) → A i0 → A i1 → Type ℓ
_[_≡_] = PathP
-- Non dependent path types
Path : ∀ {ℓ} (A : Type ℓ) → A → A → Type ℓ
Path A a b = PathP (λ _ → A) a b
-- PathP (λ i → A) x y gets printed as x ≡ y when A does not mention i.
-- _≡_ : ∀ {ℓ} {A : Type ℓ} → A → A → Type ℓ
-- _≡_ {A = A} = PathP (λ _ → A)
-- * @IsOne r@ represents the constraint "r = i1".
-- Often we will use "φ" for elements of I, when we intend to use them
-- with IsOne (or Partial[P]).
-- IsOne : I → Typeω
-- i1 is indeed equal to i1.
-- 1=1 : IsOne i1
-- * Types of partial elements, and their dependent version.
-- "Partial φ A" is a special version of "IsOne φ → A" with a more
-- extensional judgmental equality.
-- "PartialP φ A" allows "A" to be defined only on "φ".
-- Partial : ∀ {ℓ} → I → Type ℓ → Typeω
-- PartialP : ∀ {ℓ} → (φ : I) → Partial φ (Type ℓ) → Typeω
-- Partial elements are introduced by pattern matching with (r = i0)
-- or (r = i1) constraints, like so:
private
sys : ∀ i → Partial (i ∨ ~ i) Type₁
sys i (i = i0) = Type₀
sys i (i = i1) = Type₀ → Type₀
-- It also works with pattern matching lambdas:
-- http://wiki.portal.chalmers.se/agda/pmwiki.php?n=ReferenceManual.PatternMatchingLambdas
sys' : ∀ i → Partial (i ∨ ~ i) Type₁
sys' i = λ { (i = i0) → Type₀
; (i = i1) → Type₀ → Type₀
}
-- When the cases overlap they must agree.
sys2 : ∀ i j → Partial (i ∨ (i ∧ j)) Type₁
sys2 i j = λ { (i = i1) → Type₀
; (i = i1) (j = i1) → Type₀
}
-- (i0 = i1) is actually absurd.
sys3 : Partial i0 Type₁
sys3 = λ { () }
-- * There are cubical subtypes as in CCHM. Note that these are not
-- fibrant (hence in Typeω):
_[_↦_] : ∀ {ℓ} (A : Type ℓ) (φ : I) (u : Partial φ A) → _
A [ φ ↦ u ] = Sub A φ u
infix 4 _[_↦_]
-- Any element u : A can be seen as an element of A [ φ ↦ u ] which
-- agrees with u on φ:
-- inS : ∀ {ℓ} {A : Type ℓ} {φ} (u : A) → A [ φ ↦ (λ _ → u) ]
-- One can also forget that an element agrees with u on φ:
-- outS : ∀ {ℓ} {A : Type ℓ} {φ : I} {u : Partial φ A} → A [ φ ↦ u ] → A
-- * Composition operation according to [CCHM 18].
-- When calling "comp A φ u a" Agda makes sure that "a" agrees with "u i0" on "φ".
-- compCCHM : ∀ {ℓ} (A : (i : I) → Type ℓ) (φ : I) (u : ∀ i → Partial φ (A i)) (a : A i0) → A i1
-- Note: this is not recommended to use, instead use the CHM
-- primitives! The reason is that these work with HITs and produce
-- fewer empty systems.
-- * Generalized transport and homogeneous composition [CHM 18].
-- When calling "transp A φ a" Agda makes sure that "A" is constant on "φ" (see below).
-- transp : ∀ {ℓ} (A : I → Type ℓ) (φ : I) (a : A i0) → A i1
-- "A" being constant on "φ" means that "A" should be a constant function whenever the
-- constraint "φ = i1" is satisfied. For example:
-- - If "φ" is "i0" then "A" can be anything, since this condition is vacuously true.
-- - If "φ" is "i1" then "A" must be a constant function.
-- - If "φ" is some in-scope variable "i" then "A" only needs to be a constant function
-- when substituting "i1" for "i".
-- When calling "hcomp A φ u a" Agda makes sure that "a" agrees with "u i0" on "φ".
-- hcomp : ∀ {ℓ} {A : Type ℓ} {φ : I} (u : I → Partial φ A) (a : A) → A
private
variable
ℓ : Level
ℓ′ : I → Level
-- Homogeneous filling
hfill : {A : Type ℓ}
{φ : I}
(u : ∀ i → Partial φ A)
(u0 : A [ φ ↦ u i0 ])
-----------------------
(i : I) → A
hfill {φ = φ} u u0 i =
hcomp (λ j → λ { (φ = i1) → u (i ∧ j) 1=1
; (i = i0) → outS u0 })
(outS u0)
-- Heterogeneous composition can defined as in CHM, however we use the
-- builtin one as it doesn't require u0 to be a cubical subtype. This
-- reduces the number of inS's a lot.
-- comp : (A : ∀ i → Type (ℓ′ i))
-- {φ : I}
-- (u : ∀ i → Partial φ (A i))
-- (u0 : A i0 [ φ ↦ u i0 ])
-- → ---------------------------
-- A i1
-- comp A {φ = φ} u u0 =
-- hcomp (λ i → λ { (φ = i1) → transp (λ j → A (i ∨ j)) i (u _ 1=1) })
-- (transp A i0 (outS u0))
-- Heterogeneous filling defined using comp
fill : (A : ∀ i → Type (ℓ′ i))
{φ : I}
(u : ∀ i → Partial φ (A i))
(u0 : A i0 [ φ ↦ u i0 ])
---------------------------
(i : I) → A i
fill A {φ = φ} u u0 i =
comp (λ j → A (i ∧ j))
(λ j → λ { (φ = i1) → u (i ∧ j) 1=1
; (i = i0) → outS u0 })
(outS u0)
-- Σ-types
infix 2 Σ-syntax
Σ-syntax : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
Σ-syntax = Σ
syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
| 30.325472
| 96
| 0.551097
|
cb7314e796f78563e843f66e36e23e79879e9d6c
| 2,932
|
agda
|
Agda
|
OldBasicILP/Syntax/ClosedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
OldBasicILP/Syntax/ClosedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
OldBasicILP/Syntax/ClosedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Hilbert-style formalisation of closed syntax.
-- Nested terms.
module OldBasicILP.Syntax.ClosedHilbert where
open import OldBasicILP.Syntax.Common public
-- Types parametrised by closed derivations.
mutual
infixr 10 _⦂_
infixl 9 _∧_
infixr 7 _▻_
data Ty : Set where
α_ : Atom → Ty
_▻_ : Ty → Ty → Ty
_⦂_ : ∀ {A} → Proof A → Ty → Ty
_∧_ : Ty → Ty → Ty
⊤ : Ty
-- Anti-bug wrappers.
record Proof (A : Ty) : Set where
inductive
constructor [_]
field
der : ⊢ A
-- Derivations.
infix 3 ⊢_
data ⊢_ : Ty → Set where
app : ∀ {A B} → ⊢ A ▻ B → ⊢ A → ⊢ B
ci : ∀ {A} → ⊢ A ▻ A
ck : ∀ {A B} → ⊢ A ▻ B ▻ A
cs : ∀ {A B C} → ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
box : ∀ {A} → (d : ⊢ A)
→ ⊢ [ d ] ⦂ A
cdist : ∀ {A B} → {d₁ : ⊢ A ▻ B} {d₂ : ⊢ A}
→ ⊢ [ d₁ ] ⦂ (A ▻ B) ▻ [ d₂ ] ⦂ A ▻ [ app d₁ d₂ ] ⦂ B
cup : ∀ {A} → {d : ⊢ A}
→ ⊢ [ d ] ⦂ A ▻ [ box d ] ⦂ [ d ] ⦂ A
cdown : ∀ {A} → {d : ⊢ A}
→ ⊢ [ d ] ⦂ A ▻ A
cpair : ∀ {A B} → ⊢ A ▻ B ▻ A ∧ B
cfst : ∀ {A B} → ⊢ A ∧ B ▻ A
csnd : ∀ {A B} → ⊢ A ∧ B ▻ B
unit : ⊢ ⊤
infix 3 ⊢⋆_
⊢⋆_ : Cx Ty → Set
⊢⋆ ∅ = 𝟙
⊢⋆ Ξ , A = ⊢⋆ Ξ × ⊢ A
-- Additional useful types.
infixr 7 _▻⋯▻_
_▻⋯▻_ : Cx Ty → Ty → Ty
∅ ▻⋯▻ B = B
(Ξ , A) ▻⋯▻ B = Ξ ▻⋯▻ (A ▻ B)
-- Cut and multicut.
cut : ∀ {A B} → ⊢ A → ⊢ A ▻ B → ⊢ B
cut d₁ d₂ = app d₂ d₁
multicut : ∀ {Ξ A} → ⊢⋆ Ξ → ⊢ Ξ ▻⋯▻ A → ⊢ A
multicut {∅} ∙ d₂ = d₂
multicut {Ξ , B} (ds , d₁) d₂ = app (multicut ds d₂) d₁
-- Contraction.
ccont : ∀ {A B} → ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = app (app cs cs) (app ck ci)
cont : ∀ {A B} → ⊢ A ▻ A ▻ B → ⊢ A ▻ B
cont d = app ccont d
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C} → ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = app (app cs (app (app cs (app ck cs))
(app (app cs (app ck ck)) cs)))
(app ck ck)
exch : ∀ {A B C} → ⊢ A ▻ B ▻ C → ⊢ B ▻ A ▻ C
exch d = app cexch d
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C} → ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = app (app cs (app ck cs)) ck
comp : ∀ {A B C} → ⊢ B ▻ C → ⊢ A ▻ B → ⊢ A ▻ C
comp d₁ d₂ = app (app ccomp d₁) d₂
-- Useful theorems in functional form.
dist : ∀ {A B r₁ r₂} → ⊢ [ r₁ ] ⦂ (A ▻ B) → ⊢ [ r₂ ] ⦂ A → ⊢ [ app r₁ r₂ ] ⦂ B
dist d₁ d₂ = app (app cdist d₁) d₂
up : ∀ {A r} → ⊢ [ r ] ⦂ A → ⊢ [ box r ] ⦂ [ r ] ⦂ A
up d = app cup d
down : ∀ {A r} → ⊢ [ r ] ⦂ A → ⊢ A
down d = app cdown d
distup : ∀ {A B} → {r₀ : ⊢ A} {r₁ : ⊢ [ r₀ ] ⦂ A ▻ B}
→ ⊢ [ r₁ ] ⦂ ([ r₀ ] ⦂ A ▻ B) → ⊢ [ r₀ ] ⦂ A → ⊢ [ app r₁ (box r₀) ] ⦂ B
distup d₁ d₂ = dist d₁ (up d₂)
pair : ∀ {A B} → ⊢ A → ⊢ B → ⊢ A ∧ B
pair d₁ d₂ = app (app cpair d₁) d₂
fst : ∀ {A B} → ⊢ A ∧ B → ⊢ A
fst d = app cfst d
snd : ∀ {A B} → ⊢ A ∧ B → ⊢ B
snd d = app csnd d
| 21.880597
| 81
| 0.409959
|
2f3beba717ddf80935dac0bf41e1380191d37dad
| 3,245
|
agda
|
Agda
|
Categories/Category/Construction/F-Algebras.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Construction/F-Algebras.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Construction/F-Algebras.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Category.Construction.F-Algebras where
open import Level
open import Data.Product using (proj₁; proj₂)
open import Categories.Category
open import Categories.Functor hiding (id)
open import Categories.Functor.Algebra
open import Categories.Object.Initial
import Categories.Morphism.Reasoning as MR
import Categories.Morphism as Mor using (_≅_)
private
variable
o ℓ e : Level
𝒞 : Category o ℓ e
F-Algebras : {𝒞 : Category o ℓ e} → Endofunctor 𝒞 → Category (ℓ ⊔ o) (e ⊔ ℓ) e
F-Algebras {𝒞 = 𝒞} F = record
{ Obj = F-Algebra F
; _⇒_ = F-Algebra-Morphism
; _≈_ = λ α₁ α₂ → f α₁ ≈ f α₂
; _∘_ = λ α₁ α₂ → record { f = f α₁ ∘ f α₂ ; commutes = commut α₁ α₂ }
; id = record { f = id ; commutes = identityˡ ○ ⟺ identityʳ ○ ⟺ (∘-resp-≈ʳ identity) }
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≈ = ∘-resp-≈
}
where
open Category 𝒞
open Equiv
open HomReasoning using (⟺; _○_; begin_; _≈⟨_⟩_; _∎)
open Functor F
open F-Algebra-Morphism
open F-Algebra
commut : {A B C : F-Algebra F} (α₁ : F-Algebra-Morphism B C) (α₂ : F-Algebra-Morphism A B) →
(f α₁ ∘ f α₂) ∘ α A ≈ α C ∘ F₁ (f α₁ ∘ f α₂)
commut {A} {B} {C} α₁ α₂ = begin
(f α₁ ∘ f α₂) ∘ α A ≈⟨ assoc ○ ∘-resp-≈ʳ (commutes α₂) ⟩
f α₁ ∘ (α B ∘ F₁ (f α₂)) ≈⟨ ⟺ assoc ○ ∘-resp-≈ˡ (commutes α₁) ⟩
(α C ∘ F₁ (f α₁)) ∘ F₁ (f α₂) ≈⟨ assoc ○ ∘-resp-≈ʳ (⟺ homomorphism) ⟩
α C ∘ F₁ (f α₁ ∘ f α₂) ∎
module Lambek {𝒞 : Category o ℓ e} {F : Endofunctor 𝒞} (I : Initial (F-Algebras F)) where
open Category 𝒞
open Functor F
open F-Algebra using (α)
open MR 𝒞 using (glue)
open Mor 𝒞
open Initial I -- so ⊥ is an F-Algebra, which is initial
-- While an expert might be able to decipher the proof at the nLab
-- (https://ncatlab.org/nlab/show/initial+algebra+of+an+endofunctor)
-- I (JC) have found that the notes at
-- http://www.cs.ru.nl/~jrot/coalgebra/ak-algebras.pdf
-- are easier to follow, and lead to the full proof below.
private
module ⊥ = F-Algebra ⊥
A = ⊥.A
a : F₀ A ⇒ A
a = ⊥.α
-- The F-Algebra structure that will make things work
F⊥ : F-Algebra F
F⊥ = iterate ⊥
-- By initiality, we get the following morphism
f : F-Algebra-Morphism ⊥ F⊥
f = !
module FAM = F-Algebra-Morphism f
i : A ⇒ F₀ A
i = FAM.f
a∘f : F-Algebra-Morphism ⊥ ⊥
a∘f = record
{ f = a ∘ i
; commutes = glue triv FAM.commutes ○ ∘-resp-≈ʳ (⟺ homomorphism)
}
where
open HomReasoning using (_○_; ⟺)
triv : CommutativeSquare (α F⊥) (α F⊥) a a
triv = Equiv.refl
lambek : A ≅ F₀ A
lambek = record
{ from = i
; to = a
; iso = record
{ isoˡ = ⊥-id a∘f
; isoʳ = begin
i ∘ a ≈⟨ F-Algebra-Morphism.commutes f ⟩
F₁ a ∘ F₁ i ≈˘⟨ homomorphism ⟩
F₁ (a ∘ i) ≈⟨ F-resp-≈ (⊥-id a∘f) ⟩
F₁ id ≈⟨ identity ⟩
id ∎
}
}
where
open HomReasoning
| 28.716814
| 96
| 0.565177
|
18636541a0d72e261485a1bbfa5ef4155be69f59
| 1,211
|
agda
|
Agda
|
homotopy/Hopf.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
homotopy/Hopf.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/Hopf.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
import homotopy.HopfConstruction
open import homotopy.CircleHSpace
open import homotopy.SuspensionJoin using () renaming (e to suspension-join)
open import homotopy.S1SuspensionS0 using () renaming (e to S¹≃SuspensionS⁰)
import homotopy.JoinAssoc
module homotopy.Hopf where
-- To move
S⁰ = Bool
S² = Suspension S¹
S³ = Suspension S²
-- To move
S¹-connected : is-connected ⟨0⟩ S¹
S¹-connected =
([ base ] , Trunc-elim (λ x → =-preserves-level ⟨0⟩ Trunc-level)
(S¹-elim idp (prop-has-all-paths-↓ ((Trunc-level :> is-set (Trunc ⟨0⟩ S¹)) _ _))))
module Hopf = homotopy.HopfConstruction S¹ S¹-connected S¹-hSpace
Hopf : S² → Type₀
Hopf = Hopf.H.f
Hopf-fiber : Hopf (north _) == S¹
Hopf-fiber = idp
Hopf-total : Σ _ Hopf == S³
Hopf-total =
Σ _ Hopf =⟨ Hopf.theorem ⟩
S¹ * S¹ =⟨ ua S¹≃SuspensionS⁰ |in-ctx (λ u → u * S¹) ⟩
(Suspension S⁰) * S¹ =⟨ ua (suspension-join S⁰) |in-ctx (λ u → u * S¹) ⟩
(S⁰ * S⁰) * S¹ =⟨ ua (homotopy.JoinAssoc.*-assoc S⁰ S⁰ S¹) ⟩
S⁰ * (S⁰ * S¹) =⟨ ! (ua (suspension-join S¹)) |in-ctx (λ u → S⁰ * u) ⟩
S⁰ * S² =⟨ ! (ua (suspension-join S²)) ⟩
S³ ∎
| 30.275
| 95
| 0.617671
|
39d9c884e82badb77a535bca2a2e4dd2be835e34
| 365
|
agda
|
Agda
|
test/Fail/WithoutK-PatternMatchingLambdas2.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
test/Fail/WithoutK-PatternMatchingLambdas2.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Fail/WithoutK-PatternMatchingLambdas2.agda
|
antoinevanmuylder/agda
|
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --cubical-compatible #-}
module WithoutK-PatternMatchingLambdas2 where
-- Equality defined with two indices.
data _≡_ {A : Set} : A → A → Set where
refl : ∀ x → x ≡ x
-- The --cubical-compatible option works with pattern matching lambdas.
K : (A : Set) (x : A) (P : x ≡ x → Set) → P (refl x) → (p : x ≡ x ) → P p
K = λ { A .x P pr (refl x) → pr }
| 30.416667
| 74
| 0.594521
|
18a36a364d7407f549da703df573d1a574d353af
| 4,244
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.RingSolver.CommRingHornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool using (Bool; true; false; if_then_else_; _and_)
open import Cubical.Algebra.RingSolver.RawRing
open import Cubical.Algebra.RingSolver.RawAlgebra renaming (⟨_⟩ to ⟨_⟩ₐ)
open import Cubical.Algebra.RingSolver.AlmostRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
private
variable
ℓ ℓ′ : Level
{-
This defines the type of multivariate Polynomials over the RawRing R.
The construction is based on the algebraic fact
R[X₀][X₁]⋯[Xₙ] ≅ R[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n R k' is identified
with 'Xₖ', then the RawRing we construct should rather be denoted with
R[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((R[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms (A : RawAlgebra ℤAsRawRing ℓ) : ℕ → Type ℓ where
const : ℤ → IteratedHornerForms A ℕ.zero
0H : {n : ℕ} → IteratedHornerForms A (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms A (ℕ.suc n) → IteratedHornerForms A n
→ IteratedHornerForms A (ℕ.suc n)
module _ (A : RawAlgebra ℤAsRawRing ℓ′) where
open RawRing ℤAsRawRing
isZero : {n : ℕ} → IteratedHornerForms A n
→ Bool
isZero (const (pos ℕ.zero)) = true
isZero (const (pos (ℕ.suc _))) = false
isZero (const (negsuc _)) = false
isZero 0H = true
isZero (P ·X+ P₁) = false
eval : {A : RawAlgebra ℤAsRawRing ℓ′}
(n : ℕ) (P : IteratedHornerForms A n)
→ Vec ⟨ A ⟩ₐ n → ⟨ A ⟩ₐ
eval {A = A} ℕ.zero (const r) [] = RawAlgebra.scalar A r
eval {A = A} .(ℕ.suc _) 0H (_ ∷ _) = RawAlgebra.0r A
eval {A = A} (ℕ.suc n) (P ·X+ Q) (x ∷ xs) =
let open RawAlgebra A
P' = (eval (ℕ.suc n) P (x ∷ xs))
Q' = eval n Q xs
in if (isZero A P)
then Q'
else P' · x + Q'
module IteratedHornerOperations (A : RawAlgebra ℤAsRawRing ℓ) where
open RawRing ℤAsRawRing
private
1H' : (n : ℕ) → IteratedHornerForms A n
1H' ℕ.zero = const 1r
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms A n
0H' ℕ.zero = const 0r
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms A n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms A n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms A n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) =
let left = (P +ₕ Q)
right = (r +ₕ s)
in if ((isZero A left) and (isZero A right))
then 0ₕ
else left ·X+ right
-ₕ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
-ₕ (const x) = const (- x)
-ₕ 0H = 0H
-ₕ (P ·X+ Q) = (-ₕ P) ·X+ (-ₕ Q)
_⋆_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A (ℕ.suc n)
→ IteratedHornerForms A (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) =
if (isZero A r)
then 0ₕ
else (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero A z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
asRawRing : (n : ℕ) → RawRing {ℓ}
RawRing.Carrier (asRawRing n) = IteratedHornerForms A n
RawRing.0r (asRawRing n) = 0ₕ
RawRing.1r (asRawRing n) = 1ₕ
RawRing._+_ (asRawRing n) = _+ₕ_
RawRing._·_ (asRawRing n) = _·ₕ_
RawRing.- (asRawRing n) = -ₕ
Variable : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (k : Fin n) → IteratedHornerForms R n
Variable n R k = IteratedHornerOperations.X R n k
Constant : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (r : ℤ) → IteratedHornerForms R n
Constant ℕ.zero R r = const r
Constant (ℕ.suc n) R r = IteratedHornerOperations.0ₕ R ·X+ Constant n R r
| 30.753623
| 87
| 0.601084
|
29ae8f05ca9b3ba37c038091a58c8ed01a64b7fc
| 1,426
|
agda
|
Agda
|
RMonads/REM/Functors.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 21
|
2015-07-30T01:25:12.000Z
|
2021-02-13T18:02:18.000Z
|
RMonads/REM/Functors.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 3
|
2019-01-13T13:12:33.000Z
|
2019-05-29T09:50:26.000Z
|
RMonads/REM/Functors.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 1
|
2019-11-04T21:33:13.000Z
|
2019-11-04T21:33:13.000Z
|
open import Functors
open import Categories
open import RMonads
module RMonads.REM.Functors {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}
(J : Fun C D)(M : RMonad J) where
open import Library
open import RMonads.REM M
open Cat
open Fun
open RAlg
open RAlgMorph
open RMonad M
REML : Fun C EM
REML = record {
OMap = λ X → record {
acar = T X;
astr = bind;
alaw1 = sym law2;
alaw2 = law3};
HMap = λ f → record {
amor = bind (comp D η (HMap J f));
ahom = sym law3};
fid = RAlgMorphEq (
proof
bind (comp D η (HMap J (iden C)))
≅⟨ cong (bind ∘ comp D η) (fid J) ⟩
bind (comp D η (iden D))
≅⟨ cong bind (idr D) ⟩
bind η
≅⟨ law1 ⟩
iden D ∎);
fcomp = λ{_ _ _ f g} → RAlgMorphEq (
proof
bind (comp D η (HMap J (comp C f g)))
≅⟨ cong (bind ∘ comp D η) (fcomp J) ⟩
bind (comp D η (comp D (HMap J f) (HMap J g)))
≅⟨ cong bind (sym (ass D)) ⟩
bind (comp D (comp D η (HMap J f)) (HMap J g))
≅⟨ cong (λ f₁ → bind (comp D f₁ (HMap J g))) (sym law2) ⟩
bind (comp D (comp D (bind (comp D η (HMap J f))) η) (HMap J g))
≅⟨ cong bind (ass D) ⟩
bind (comp D (bind (comp D η (HMap J f))) (comp D η (HMap J g)))
≅⟨ law3 ⟩
comp D (bind (comp D η (HMap J f))) (bind (comp D η (HMap J g)))
∎)}
REMR : Fun EM D
REMR = record {
OMap = acar;
HMap = amor;
fid = refl;
fcomp = refl}
| 25.017544
| 69
| 0.528752
|
1d23485fd36364e58e2fb2eb654c6a432d307f5e
| 853
|
agda
|
Agda
|
out/Sub/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/Sub/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/Sub/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order signature was created from the following second-order syntax description:
syntax Sub | S
type
L : 0-ary
T : 0-ary
term
vr : L -> T
sb : L.T T -> T
theory
(C) x y : T |> sb (a. x[], y[]) = x[]
(L) x : T |> sb (a. vr(a), x[]) = x[]
(R) a : L x : L.T |> sb (b. x[b], vr(a[])) = x[a[]]
(A) x : (L,L).T y : L.T z : T |> sb (a. sb (b. x[a,b], y[a]), z[]) = sb (b. sb (a. x[a, b], z[]), sb (a. y[a], z[]))
-}
module Sub.Signature where
open import SOAS.Context
-- Type declaration
data ST : Set where
L : ST
T : ST
open import SOAS.Syntax.Signature ST public
open import SOAS.Syntax.Build ST public
-- Operator symbols
data Sₒ : Set where
vrₒ sbₒ : Sₒ
-- Term signature
S:Sig : Signature Sₒ
S:Sig = sig λ
{ vrₒ → (⊢₀ L) ⟼₁ T
; sbₒ → (L ⊢₁ T) , (⊢₀ T) ⟼₂ T
}
open Signature S:Sig public
| 18.148936
| 120
| 0.538101
|
c576fef6a38cf9fcf13635156427a0568895b2d2
| 667
|
agda
|
Agda
|
src/constants.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/constants.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/constants.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
module constants where
open import lib
cedille-extension : string
cedille-extension = "ced"
self-name : string
self-name = "self"
pattern ignored-var = "_"
pattern meta-var-pfx = '?'
pattern qual-local-chr = '@'
pattern qual-global-chr = '.'
meta-var-pfx-str = 𝕃char-to-string [ meta-var-pfx ]
qual-local-str = 𝕃char-to-string [ qual-local-chr ]
qual-global-str = 𝕃char-to-string [ qual-global-chr ]
options-file-name : string
options-file-name = "options"
global-error-string : string → string
global-error-string msg = "{\"error\":\"" ^ msg ^ "\"" ^ "}"
dot-cedille-directory : string → string
dot-cedille-directory dir = combineFileNames dir ".cedille"
| 22.233333
| 60
| 0.697151
|
dcbc27b23f2db53addda787c56f12ff98cde16bf
| 764
|
agda
|
Agda
|
src/Categories/Diagram/Colimit/Lan.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Diagram/Colimit/Lan.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Diagram/Colimit/Lan.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Diagram.Colimit.Lan where
open import Level
open import Categories.Category
open import Categories.Category.Cocomplete
open import Categories.Diagram.Duality
open import Categories.Diagram.Limit.Ran
open import Categories.Functor
open import Categories.Kan
open import Categories.Kan.Duality
private
variable
o ℓ e : Level
C D E : Category o ℓ e
module _ {o ℓ e o′ ℓ′ e′} {C : Category o′ ℓ′ e′} {D : Category o ℓ e}
(F : Functor C D) (X : Functor C E) (Com : Cocomplete (o′ ⊔ ℓ) (ℓ′ ⊔ e) e′ E) where
private
module F = Functor F
module X = Functor X
colimit-is-lan : Lan F X
colimit-is-lan = coRan⇒Lan (limit-is-ran F.op X.op λ G → Colimit⇒coLimit E (Com (Functor.op G)))
| 28.296296
| 98
| 0.687173
|
cbf373ad226fb21e4df7281a23ce9395b4e3b953
| 464
|
agda
|
Agda
|
test/Fail/Issue1946-5.agda
|
caryoscelus/agda
|
98d6f195fe672e54ef0389b4deb62e04e3e98327
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue1946-5.agda
|
caryoscelus/agda
|
98d6f195fe672e54ef0389b4deb62e04e3e98327
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue1946-5.agda
|
caryoscelus/agda
|
98d6f195fe672e54ef0389b4deb62e04e3e98327
|
[
"BSD-3-Clause"
] | null | null | null |
-- This test case was reported by Andrea Vezzosi.
open import Agda.Builtin.Size
data Σ (A : Set) (B : A → Set) : Set where
_,_ : (x : A) → B x → Σ A B
data ⊥ : Set where
record T (i : Size) : Set where
constructor con
coinductive
field
force : Σ (Size< i) \ { j → T j }
open T public
empty : ∀ i → T i → ⊥
empty i x with force x
... | j , y = empty j y
inh : T ∞
inh = \ { .force → ∞ , inh } -- using oo < oo here
false : ⊥
false = empty ∞ inh
| 17.185185
| 50
| 0.5625
|
4d72918e7e7a2dbbd5e749b9501ed6eab8e85678
| 10,695
|
agda
|
Agda
|
Categories/Grothendieck.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Grothendieck.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Grothendieck.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Grothendieck where
open import Relation.Binary using (Rel)
open import Data.Product using (Σ; _,_; proj₁; proj₂; _×_)
open import Categories.Support.Experimental
open import Categories.Support.PropositionalEquality
open import Categories.Support.IProduct
import Categories.Category as CCat
open CCat hiding (module Heterogeneous)
open import Categories.Functor using (Functor; module Functor; ≡⇒≣)
open import Categories.Agda
open import Categories.Categories
open import Categories.Congruence
-- TODO: don't use sigmas
-- Break into modules Strict and Weak using Sets and Setoids?
Elements : ∀ {o ℓ e o′} {C : Category o ℓ e} → Functor C (Sets o′) → Category _ _ _
Elements {o′ = o′} {C = C} F = record
{ Obj = Obj′
; _⇒_ = Hom′
; _≡_ = _≡′_
; _∘_ = _∘′_
; id = id , identity
; assoc = assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≡ = ∘-resp-≡
}
where
open Category C
open Equiv
open Functor F
Obj′ = Σ Obj F₀
Hom′ : Rel Obj′ _
Hom′ (c₁ , x₁) (c₂ , x₂) = Σ′ (c₁ ⇒ c₂) (λ f → F₁ f x₁ ≣ x₂)
_≡′_ : ∀ {X Y} → Rel (Hom′ X Y) _
(f , pf₁) ≡′ (g , pf₂) = f ≡ g
_∘′_ : ∀ {X Y Z} → Hom′ Y Z → Hom′ X Y → Hom′ X Z
_∘′_ {X} {Y} {Z} (f , pf₁) (g , pf₂) = (f ∘ g) , pf
where
-- This could be a lot prettier...
.pf : F₁ (f ∘ g) (proj₂ X) ≣ proj₂ Z
pf = ≣-trans homomorphism (≣-sym (≣-trans (≣-sym pf₁) (≣-cong (F₁ f) (≣-sym pf₂))))
Dom : ∀ {o ℓ e o′} {C : Category o ℓ e} → (F : Functor C (Sets o′)) -> Functor (Elements F) C
Dom {C = C} F = record {
F₀ = proj₁;
F₁ = proj₁′;
identity = Equiv.refl;
homomorphism = Equiv.refl;
F-resp-≡ = λ x → x }
where
open Category C
-- because we want the following function to reduce all the time, define it globally
private
module _ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} (F : Functor C (Categories o′ ℓ′ e′)) where
private
module C = Category C
module F = Functor F
module Cat = Category (Categories o′ ℓ′ e′)
∘-eq : ∀ {cx xx cy cz} -> (f : cy C.⇒ cz) (g : cx C.⇒ cy) -> Functor.F₀ (F.F₁ f Cat.∘ F.F₁ g) xx ≣ Functor.F₀ (F.F₁ (f C.∘ g)) xx
∘-eq {cx} {xx} {cy} {cz} f g = ≣-relevant (≣-sym (≡⇒≣ (F.F₁ (f C.∘ g)) (F.F₁ f Cat.∘ F.F₁ g) (F.homomorphism {f = g} {g = f}) xx))
Grothendieck : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} → Functor C (Categories o′ ℓ′ e′) → Category _ _ _
Grothendieck {o′ = o′} {ℓ′} {e′} {C = C} F = record
{ Obj = Obj′
; _⇒_ = Hom′
; _≡_ = _≡′_
; _∘_ = _∘′_
; id = id′
; assoc = assoc′
; identityˡ = identityˡ′
; identityʳ = identityʳ′
; equiv = record {
refl = refl , Het.refl;
sym = λ { (eq₁ , eq₂) → sym eq₁ , Het.sym eq₂};
trans = λ { (xeq₁ , xeq₂) (yeq₁ , yeq₂) → trans xeq₁ yeq₁ , Het.trans xeq₂ yeq₂} }
; ∘-resp-≡ = ∘-resp-≡′
}
module Groth where
open Functor F
module Fc {c} where
open Category (F₀ c) public
open Equiv public
open Category C
open Equiv
module Cat = Category (Categories o′ ℓ′ e′)
module Cong {c} where
open Congruence (TrivialCongruence (F₀ c)) public
open Cong public using () renaming (coerce to coe)
module Het {c} = Heterogeneous (TrivialCongruence (F₀ c))
open Het using (▹_)
module OHet {c} where
open CCat.Heterogeneous (F₀ c) public
ohet⇒het : ∀ {A B} {f : A Fc.⇒ B} -> ∀ {X Y} → {g : X Fc.⇒ Y} → f ∼ g -> f Het.∼ g
ohet⇒het (≡⇒∼ x) = Het.≡⇒∼ ≣-refl ≣-refl x
Obj′ = Σ Obj (\ c -> Category.Obj (F₀ c))
Hom′ : Rel Obj′ _
Hom′ (c₁ , x₁) (c₂ , x₂) = Σ (c₁ ⇒ c₂) (λ f → Functor.F₀ (F₁ f) x₁ Fc.⇒ x₂)
_≡′_ : ∀ {X Y} → Rel (Hom′ X Y) _
_≡′_ {c₁ , x₁} {c₂ , x₂} (f , α) (g , β) = f ≡ g × α Het.∼ β
_∘′_ : ∀ {X Y Z} → Hom′ Y Z → Hom′ X Y → Hom′ X Z
_∘′_ {cx , xx} {Y} {cz , xz} (f , α) (g , β) = (f ∘ g) , α Fc.∘ Cong.coerce (∘-eq F f g) ≣-refl (Functor.F₁ (F₁ f) β)
id-eq : ∀ {c x} -> Functor.F₀ (Cat.id {F₀ c}) x ≣ Functor.F₀ (F₁ id) x
id-eq {c} {x} = ≣-relevant (≣-sym (≡⇒≣ (F₁ id) Cat.id (identity {c}) x))
id′ : {A : Obj′} → Hom′ A A
id′ {c , x} = id , Cong.coerce id-eq ≣-refl Fc.id
F-resp-∼ : ∀ {b c} -> (H : Functor (F₀ b) (F₀ c)) -> {A B A' B' : Category.Obj (F₀ b)} {α : A Fc.⇒ B }{β : A' Fc.⇒ B'} →
(α Het.∼ β) → (Functor.F₁ H α Het.∼ Functor.F₁ H β)
F-resp-∼ H (Heterogeneous.≡⇒∼ ≣-refl ≣-refl x) = Heterogeneous.≡⇒∼ ≣-refl ≣-refl (Functor.F-resp-≡ H x)
.identityˡ′ : {A B : Obj′} {f : Hom′ A B} → (id′ ∘′ f) ≡′ f
identityˡ′ {ca , xa} {cb , xb} {f , α} = identityˡ , (begin
▹ coe id-eq ≣-refl Fc.id Fc.∘ coe (∘-eq F id f) ≣-refl (Functor.F₁ (F₁ id) α)
↓⟨ Het.∘-resp-∼ (Het.sym (Het.coerce-resp-∼ id-eq ≣-refl)) F₁id[α]~α ⟩
▹ Fc.id Fc.∘ α
↓⟨ Het.≡⇒∼ ≣-refl ≣-refl Fc.identityˡ ⟩
▹ α
∎)
where
open Het.HetReasoning
F₁id[α]~α : coe (∘-eq F id f) ≣-refl (Functor.F₁ (F₁ id) α) Het.∼ α
F₁id[α]~α = begin
▹ coe (∘-eq F id f) ≣-refl (Functor.F₁ (F₁ id) α)
↑⟨ Het.coerce-resp-∼ (∘-eq F id f) ≣-refl ⟩
▹ Functor.F₁ (F₁ id) α
↓⟨ OHet.ohet⇒het (identity α) ⟩
▹ α
∎
.identityʳ′ : {A B : Obj′} {f : Hom′ A B} → (f ∘′ id′) ≡′ f
identityʳ′ {ca , xa} {cb , xb} {f , α} = identityʳ , (begin
▹ α Fc.∘ coe (∘-eq F f id) ≣-refl (Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id))
↓⟨ Het.∘-resp-∼ʳ F₁f[id]~id ⟩
▹ α Fc.∘ Fc.id
↓⟨ Het.≡⇒∼ ≣-refl ≣-refl Fc.identityʳ ⟩
▹ α
∎)
where
open Het.HetReasoning
F₁f[id]~id : coe (∘-eq F f id) ≣-refl (Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id)) Het.∼ Fc.id
F₁f[id]~id = begin
▹ coe (∘-eq F f id) ≣-refl (Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id))
↑⟨ Het.coerce-resp-∼ (∘-eq F f id) ≣-refl ⟩
▹ Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id)
↓⟨ F-resp-∼ (F₁ f) (Het.sym (Het.coerce-resp-∼ id-eq ≣-refl)) ⟩
▹ Functor.F₁ (F₁ f) (Category.id (F₀ ca))
↓⟨ Het.≡⇒∼ ≣-refl ≣-refl (Functor.identity (F₁ f)) ⟩
▹ Fc.id
∎
.assoc′ : {A B C₁ D : Obj′} {f : Hom′ A B} {g : Hom′ B C₁} {h : Hom′ C₁ D} →
((h ∘′ g) ∘′ f) ≡′ (h ∘′ (g ∘′ f))
assoc′ {ca , xa} {cb , xb} {cc , xc} {cd , xd} {f , α} {g , β} {h , γ}
= assoc , Het.trans (Het.≡⇒∼ ≣-refl ≣-refl Fc.assoc) (Het.∘-resp-∼ʳ F₁h[β]∘F₁h∘g[α]~F₁h[β∘F₁g[α]])
where
open Het.HetReasoning
eq : Functor.F₀ (F₁ ((h ∘ g) ∘ f)) xa ≣ Functor.F₀ (F₁ (h ∘ g ∘ f)) xa
eq = ≡⇒≣ (F₁ ((h ∘ g) ∘ f)) (F₁ (h ∘ g ∘ f)) (F-resp-≡ (assoc {f = f})) xa
F₁h[β]∘F₁h∘g[α]~F₁h[β∘F₁g[α]] : (coe (∘-eq F h g) ≣-refl (Functor.F₁ (F₁ h) β) Fc.∘ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α))
Het.∼ (coe (∘-eq F h (g ∘ f)) ≣-refl (Functor.F₁ (F₁ h) (proj₂ ((g , β) ∘′ (f , α)))))
F₁h[β]∘F₁h∘g[α]~F₁h[β∘F₁g[α]] = Het.sym (begin
▹ coe (∘-eq F h (g ∘ f)) ≣-refl (Functor.F₁ (F₁ h) (β Fc.∘ coe(∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α)))
↑⟨ Het.coerce-resp-∼ (∘-eq F h (g ∘ f)) ≣-refl ⟩
▹ Functor.F₁ (F₁ h) (β Fc.∘ coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α))
↓⟨ Het.≡⇒∼ ≣-refl ≣-refl (Functor.homomorphism (F₁ h)) ⟩
▹ Functor.F₁ (F₁ h) β Fc.∘ (Functor.F₁ (F₁ h) (coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α)))
↓⟨ Het.∘-resp-∼ (Het.coerce-resp-∼ (∘-eq F h g) ≣-refl) F₁h[β]~F₁h∘g[α] ⟩
▹ coe (∘-eq F h g) ≣-refl (Functor.F₁ (F₁ h) β) Fc.∘ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α)
∎)
where
F₁h[β]~F₁h∘g[α] : (Functor.F₁ (F₁ h) (coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α))) Het.∼ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α)
F₁h[β]~F₁h∘g[α] = begin
▹ Functor.F₁ (F₁ h) (coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α))
↓⟨ F-resp-∼ (F₁ h) (Het.sym (Het.coerce-resp-∼ (∘-eq F g f) ≣-refl)) ⟩
▹ Functor.F₁ (F₁ h) (Functor.F₁ (F₁ g) α)
↑⟨ OHet.ohet⇒het (homomorphism α) ⟩
▹ Functor.F₁ (F₁ (h ∘ g)) α
↓⟨ Het.coerce-resp-∼ (∘-eq F (h ∘ g) f) ≣-refl ⟩
▹ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α)
∎
.∘-resp-≡′ : {A B C₁ : Obj′} {f h : Hom′ B C₁} {g i : Hom′ A B} →
f ≡′ h → g ≡′ i → (f ∘′ g) ≡′ (h ∘′ i)
∘-resp-≡′ {a , ax} {b , bx} {c , cx} {f = f , α} {h , η} {g , γ} {i , ι} (f≡h , α~η) (g≡i , γ~ι) = ∘-resp-≡ f≡h g≡i , Het.∘-resp-∼ α~η
(begin
▹ coe (∘-eq F f g) ≣-refl (Functor.F₁ (F₁ f) γ) ↑⟨ Het.coerce-resp-∼ (∘-eq F f g) ≣-refl ⟩
▹ Functor.F₁ (F₁ f) γ ↓⟨ OHet.ohet⇒het (F-resp-≡ f≡h γ) ⟩
▹ Functor.F₁ (F₁ h) γ ↓⟨ F-resp-∼ (F₁ h) γ~ι ⟩
▹ Functor.F₁ (F₁ h) ι ↓⟨ Het.coerce-resp-∼ (∘-eq F h i) ≣-refl ⟩
▹ coe (∘-eq F h i) ≣-refl (Functor.F₁ (F₁ h) ι) ∎)
where
open Het.HetReasoning
Gr = Grothendieck
DomGr : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} → (F : Functor C (Categories o′ ℓ′ e′)) → Functor (Grothendieck F) C
DomGr {C = C} F = record {
F₀ = proj₁;
F₁ = proj₁;
identity = C.Equiv.refl;
homomorphism = C.Equiv.refl;
F-resp-≡ = proj₁ }
where
module C = Category C
inGr : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} (F : Functor C (Categories o′ ℓ′ e′)) → ∀ c -> Functor (Functor.F₀ F c) (Gr F)
inGr {C = C} F c = record {
F₀ = _,_ c;
F₁ = λ f → C.id , GrF.coe GrF.id-eq ≣-refl f;
identity = Category.Equiv.refl (Grothendieck F);
homomorphism = C.Equiv.sym C.identityʳ , Het.trans (Het.sym (Het.coerce-resp-∼ GrF.id-eq ≣-refl))
(Het.∘-resp-∼ (Het.coerce-resp-∼ GrF.id-eq ≣-refl)
(Het.trans
(Het.trans (Het.coerce-resp-∼ GrF.id-eq ≣-refl)
(Het.sym (GrF.OHet.ohet⇒het (F.identity _))))
(Het.coerce-resp-∼ (∘-eq F C.id C.id) ≣-refl)));
F-resp-≡ = λ x → C.Equiv.refl , (Het.trans (Het.trans (Het.sym (Het.coerce-resp-∼ GrF.id-eq ≣-refl))
(Heterogeneous.≡⇒∼ ≣-refl ≣-refl x)) (Het.coerce-resp-∼ GrF.id-eq ≣-refl)) }
where
module C = Category C
module F = Functor F
module GrF = Groth F
open GrF using (module Het; module Cong)
| 43.299595
| 155
| 0.478074
|
39174043bf8a41d70679e75671305037aaaffd6e
| 5,207
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Codata/Musical/Stream.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
test/asset/agda-stdlib-1.0/Codata/Musical/Stream.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Codata/Musical/Stream.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Streams
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types --guardedness #-}
module Codata.Musical.Stream where
open import Codata.Musical.Notation
open import Codata.Musical.Colist using (Colist; []; _∷_)
open import Data.Vec using (Vec; []; _∷_)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- The type
infixr 5 _∷_
data Stream {a} (A : Set a) : Set a where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
{-# FOREIGN GHC
data AgdaStream a = Cons a (MAlonzo.RTE.Inf (AgdaStream a))
type AgdaStream' l a = AgdaStream a
#-}
{-# COMPILE GHC Stream = data AgdaStream' (Cons) #-}
------------------------------------------------------------------------
-- Some operations
head : ∀ {a} {A : Set a} → Stream A → A
head (x ∷ xs) = x
tail : ∀ {a} {A : Set a} → Stream A → Stream A
tail (x ∷ xs) = ♭ xs
map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → Stream A → Stream B
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
zipWith : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(A → B → C) → Stream A → Stream B → Stream C
zipWith _∙_ (x ∷ xs) (y ∷ ys) = (x ∙ y) ∷ ♯ zipWith _∙_ (♭ xs) (♭ ys)
take : ∀ {a} {A : Set a} n → Stream A → Vec A n
take zero xs = []
take (suc n) (x ∷ xs) = x ∷ take n (♭ xs)
drop : ∀ {a} {A : Set a} → ℕ → Stream A → Stream A
drop zero xs = xs
drop (suc n) (x ∷ xs) = drop n (♭ xs)
repeat : ∀ {a} {A : Set a} → A → Stream A
repeat x = x ∷ ♯ repeat x
iterate : ∀ {a} {A : Set a} → (A → A) → A → Stream A
iterate f x = x ∷ ♯ iterate f (f x)
-- Interleaves the two streams.
infixr 5 _⋎_
_⋎_ : ∀ {a} {A : Set a} → Stream A → Stream A → Stream A
(x ∷ xs) ⋎ ys = x ∷ ♯ (ys ⋎ ♭ xs)
mutual
-- Takes every other element from the stream, starting with the
-- first one.
evens : ∀ {a} {A : Set a} → Stream A → Stream A
evens (x ∷ xs) = x ∷ ♯ odds (♭ xs)
-- Takes every other element from the stream, starting with the
-- second one.
odds : ∀ {a} {A : Set a} → Stream A → Stream A
odds (x ∷ xs) = evens (♭ xs)
toColist : ∀ {a} {A : Set a} → Stream A → Colist A
toColist (x ∷ xs) = x ∷ ♯ toColist (♭ xs)
lookup : ∀ {a} {A : Set a} → ℕ → Stream A → A
lookup zero (x ∷ xs) = x
lookup (suc n) (x ∷ xs) = lookup n (♭ xs)
infixr 5 _++_
_++_ : ∀ {a} {A : Set a} → Colist A → Stream A → Stream A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ ♯ (♭ xs ++ ys)
------------------------------------------------------------------------
-- Equality and other relations
-- xs ≈ ys means that xs and ys are equal.
infix 4 _≈_
data _≈_ {a} {A : Set a} : Stream A → Stream A → Set a where
_∷_ : ∀ {x y xs ys}
(x≡ : x ≡ y) (xs≈ : ∞ (♭ xs ≈ ♭ ys)) → x ∷ xs ≈ y ∷ ys
-- x ∈ xs means that x is a member of xs.
infix 4 _∈_
data _∈_ {a} {A : Set a} : A → Stream A → Set a where
here : ∀ {x xs} → x ∈ x ∷ xs
there : ∀ {x y xs} (x∈xs : x ∈ ♭ xs) → x ∈ y ∷ xs
-- xs ⊑ ys means that xs is a prefix of ys.
infix 4 _⊑_
data _⊑_ {a} {A : Set a} : Colist A → Stream A → Set a where
[] : ∀ {ys} → [] ⊑ ys
_∷_ : ∀ x {xs ys} (p : ∞ (♭ xs ⊑ ♭ ys)) → x ∷ xs ⊑ x ∷ ys
------------------------------------------------------------------------
-- Some proofs
setoid : ∀ {a} → Set a → Setoid _ _
setoid A = record
{ Carrier = Stream A
; _≈_ = _≈_ {A = A}
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {_ ∷ _} = P.refl ∷ ♯ refl
sym : Symmetric _≈_
sym (x≡ ∷ xs≈) = P.sym x≡ ∷ ♯ sym (♭ xs≈)
trans : Transitive _≈_
trans (x≡ ∷ xs≈) (y≡ ∷ ys≈) = P.trans x≡ y≡ ∷ ♯ trans (♭ xs≈) (♭ ys≈)
head-cong : ∀ {a} {A : Set a} {xs ys : Stream A} → xs ≈ ys → head xs ≡ head ys
head-cong (x≡ ∷ _) = x≡
tail-cong : ∀ {a} {A : Set a} {xs ys : Stream A} → xs ≈ ys → tail xs ≈ tail ys
tail-cong (_ ∷ xs≈) = ♭ xs≈
map-cong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {xs ys} →
xs ≈ ys → map f xs ≈ map f ys
map-cong f (x≡ ∷ xs≈) = P.cong f x≡ ∷ ♯ map-cong f (♭ xs≈)
zipWith-cong : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
(_∙_ : A → B → C) {xs xs′ ys ys′} →
xs ≈ xs′ → ys ≈ ys′ →
zipWith _∙_ xs ys ≈ zipWith _∙_ xs′ ys′
zipWith-cong _∙_ (x≡ ∷ xs≈) (y≡ ∷ ys≈) =
P.cong₂ _∙_ x≡ y≡ ∷ ♯ zipWith-cong _∙_ (♭ xs≈) (♭ ys≈)
infixr 5 _⋎-cong_
_⋎-cong_ : ∀ {a} {A : Set a} {xs xs′ ys ys′ : Stream A} →
xs ≈ xs′ → ys ≈ ys′ → xs ⋎ ys ≈ xs′ ⋎ ys′
(x ∷ xs≈) ⋎-cong ys≈ = x ∷ ♯ (ys≈ ⋎-cong ♭ xs≈)
------------------------------------------------------------------------
-- Legacy
import Codata.Stream as S
open import Codata.Thunk
import Size
module _ {a} {A : Set a} where
fromMusical : ∀ {i} → Stream A → S.Stream A i
fromMusical (x ∷ xs) = x S.∷ λ where .force → fromMusical (♭ xs)
toMusical : S.Stream A Size.∞ → Stream A
toMusical (x S.∷ xs) = x ∷ ♯ toMusical (xs .force)
| 28.453552
| 78
| 0.459574
|
0b9f1c284565ff4bae82b4696351fe1a6c9b4c95
| 1,845
|
agda
|
Agda
|
Univalence/Obsolete/SubstLemmas.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
Univalence/Obsolete/SubstLemmas.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
Univalence/Obsolete/SubstLemmas.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K #-}
module SubstLemmas where
open import Level using (Level)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; subst; cong₂)
open import Data.Nat using (ℕ; _+_; _*_)
------------------------------------------------------------------------------
-- Lemmas about subst (and a couple about trans)
subst-dist :
{a b : Level} {A : Set a} {B : A → Set b}
(f : {x : A} → B x → B x → B x) →
{x₁ x₂ : A} → (x₂≡x₁ : x₂ ≡ x₁) → (v₁ v₂ : B x₂) →
subst B x₂≡x₁ (f v₁ v₂) ≡ f (subst B x₂≡x₁ v₁) (subst B x₂≡x₁ v₂)
subst-dist f refl v₁ v₂ = refl
subst-trans :
{a b : Level} {A : Set a} {B : A → Set b} {x₁ x₂ x₃ : A} →
(x₂≡x₁ : x₂ ≡ x₁) → (x₃≡x₂ : x₃ ≡ x₂) → (v : B x₃) →
subst B x₂≡x₁ (subst B x₃≡x₂ v) ≡ subst B (trans x₃≡x₂ x₂≡x₁) v
subst-trans refl refl v = refl
subst₂+ : {b : Level} {B : ℕ → Set b} {x₁ x₂ x₃ x₄ : ℕ} →
(x₂≡x₁ : x₂ ≡ x₁) → (x₄≡x₃ : x₄ ≡ x₃) → (v₁ : B x₂) → (v₂ : B x₄) →
(f : {x₁ x₂ : ℕ} → B x₁ → B x₂ → B (x₁ + x₂)) →
subst B (cong₂ _+_ x₂≡x₁ x₄≡x₃) (f v₁ v₂) ≡
f (subst B x₂≡x₁ v₁) (subst B x₄≡x₃ v₂)
subst₂+ refl refl v₁ v₂ f = refl
subst₂* : {b : Level} {B : ℕ → Set b} {x₁ x₂ x₃ x₄ : ℕ} →
(x₂≡x₁ : x₂ ≡ x₁) → (x₄≡x₃ : x₄ ≡ x₃) → (v₁ : B x₂) → (v₂ : B x₄) →
(f : {x₁ x₂ : ℕ} → B x₁ → B x₂ → B (x₁ * x₂)) →
subst B (cong₂ _*_ x₂≡x₁ x₄≡x₃) (f v₁ v₂) ≡
f (subst B x₂≡x₁ v₁) (subst B x₄≡x₃ v₂)
subst₂* refl refl v₁ v₂ f = refl
trans-syml : {A : Set} {x y : A} → (p : x ≡ y) → trans (sym p) p ≡ refl
trans-syml refl = refl
trans-symr : {A : Set} {x y : A} → (p : x ≡ y) → trans p (sym p) ≡ refl
trans-symr refl = refl
subst-subst :
{a b : Level} {A : Set a} {B : A → Set b}
{x y : A} → (eq : x ≡ y) → (eq' : y ≡ x) → (irr : sym eq ≡ eq') → (v : B y) →
subst B eq (subst B eq' v) ≡ v
subst-subst refl .refl refl v = refl
| 36.176471
| 79
| 0.499187
|
41f62ef709d3b05ef63a8bf2b20616547562bc5d
| 496
|
agda
|
Agda
|
Cubical/Categories/Instances/TypePrecategory.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Categories/Instances/TypePrecategory.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Instances/TypePrecategory.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.TypePrecategory where
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Category.Precategory
open Precategory
-- TYPE precategory has types as objects
module _ ℓ where
TYPE : Precategory (ℓ-suc ℓ) ℓ
TYPE .ob = Type ℓ
TYPE .Hom[_,_] A B = A → B
TYPE .id = λ x → x
TYPE ._⋆_ f g = λ x → g (f x)
TYPE .⋆IdL f = refl
TYPE .⋆IdR f = refl
TYPE .⋆Assoc f g h = refl
| 24.8
| 57
| 0.627016
|
39cdf6005bd27621b0f7ee0cc918f49e691b5df9
| 2,319
|
agda
|
Agda
|
Categories/Morphism.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Morphism.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Morphism.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
{-
Properties and definitions regarding Morphisms of a category:
- Monomorphism
- Epimorphism
- Isomorphism
- (object) equivalence ('spelled' _≅_ ). Exported as the module ≅
-}
open import Categories.Category
module Categories.Morphism {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level
open import Relation.Binary hiding (_⇒_)
open import Categories.Morphism.Reasoning.Core 𝒞
open Category 𝒞
private
variable
A B C : Obj
Mono : ∀ (f : A ⇒ B) → Set (o ⊔ ℓ ⊔ e)
Mono {A = A} f = ∀ {C} → (g₁ g₂ : C ⇒ A) → f ∘ g₁ ≈ f ∘ g₂ → g₁ ≈ g₂
Epi : ∀ (f : A ⇒ B) → Set (o ⊔ ℓ ⊔ e)
Epi {B = B} f = ∀ {C} → (g₁ g₂ : B ⇒ C) → g₁ ∘ f ≈ g₂ ∘ f → g₁ ≈ g₂
record Iso (from : A ⇒ B) (to : B ⇒ A) : Set e where
field
isoˡ : to ∘ from ≈ id
isoʳ : from ∘ to ≈ id
infix 4 _≅_
record _≅_ (A B : Obj) : Set (ℓ ⊔ e) where
field
from : A ⇒ B
to : B ⇒ A
iso : Iso from to
open Iso iso public
-- don't pollute the name space too much
private
≅-refl : Reflexive _≅_
≅-refl = record
{ from = id
; to = id
; iso = record
{ isoˡ = identityˡ
; isoʳ = identityʳ
}
}
≅-sym : Symmetric _≅_
≅-sym A≅B = record
{ from = to
; to = from
; iso = record
{ isoˡ = isoʳ
; isoʳ = isoˡ
}
}
where open _≅_ A≅B
≅-trans : Transitive _≅_
≅-trans A≅B B≅C = record
{ from = from B≅C ∘ from A≅B
; to = to A≅B ∘ to B≅C
; iso = record
{ isoˡ = begin
(to A≅B ∘ to B≅C) ∘ from B≅C ∘ from A≅B ≈⟨ cancelInner (isoˡ B≅C) ⟩
to A≅B ∘ from A≅B ≈⟨ isoʳ (≅-sym A≅B) ⟩
id ∎
; isoʳ = begin
(from B≅C ∘ from A≅B) ∘ to A≅B ∘ to B≅C ≈⟨ cancelInner (isoʳ A≅B) ⟩
from B≅C ∘ to B≅C ≈⟨ isoˡ (≅-sym B≅C) ⟩
id ∎
}
}
where open _≅_
open HomReasoning
open Equiv
≅-isEquivalence : IsEquivalence _≅_
≅-isEquivalence = record
{ refl = ≅-refl
; sym = ≅-sym
; trans = ≅-trans
}
-- But make accessing it easy:
module ≅ = IsEquivalence ≅-isEquivalence
≅-setoid : Setoid _ _
≅-setoid = record
{ Carrier = Obj
; _≈_ = _≅_
; isEquivalence = ≅-isEquivalence
}
| 22.514563
| 75
| 0.499784
|
29197dd72afd681d132a35c9cc34bef69b0dceec
| 3,145
|
agda
|
Agda
|
homotopy/HopfJunior.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
homotopy/HopfJunior.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/HopfJunior.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
module homotopy.HopfJunior where
-- We define the negation function and prove that it’s an equivalence
not : Bool → Bool
not true = false
not false = true
not-not : (b : Bool) → not (not b) == b
not-not true = idp
not-not false = idp
not-equiv : Bool ≃ Bool
not-equiv = equiv not not not-not not-not
-- Definition of the junior Hopf fibration
module HopfJunior = S¹RecType Bool not-equiv
open HopfJunior using (module Wt; Wt; cct; ppt; flattening-S¹)
HopfJunior : S¹ → Type₀
HopfJunior = HopfJunior.f
-- We get that the total space is the type Wt defined in the flattening lemma.
tot-is-Wt : Σ S¹ HopfJunior == Wt
tot-is-Wt = flattening-S¹
-- Now we prove that Wt is equivalent to S¹
private
-- Map from [Wt] to [S¹]
to-cct : Unit × Bool → S¹
to-cct _ = base
to-ppt : (x : Unit × Bool) → to-cct x == to-cct x
to-ppt (_ , true) = loop
to-ppt (_ , false) = idp
module To = Wt.Rec to-cct to-ppt
to : Wt → S¹
to = To.f
-- Map from [S¹] to [Wt]
from-base : Wt
from-base = cct tt true
from-loop : from-base == from-base
from-loop = ppt tt true ∙ ppt tt false
module From = S¹Rec from-base from-loop
from : S¹ → Wt
from = From.f
-- First composite
abstract
to-from : (x : S¹) → to (from x) == x
to-from = S¹-elim idp (↓-∘=idf-in to from
(ap to (ap from loop) =⟨ From.loop-β |in-ctx ap to ⟩
ap to (ppt tt true ∙ ppt tt false) =⟨ ap-∙ to (ppt tt true) (ppt tt false) ⟩
ap to (ppt tt true) ∙ ap to (ppt tt false) =⟨ To.pp-β (tt , true) |in-ctx (λ u → u ∙ ap to (ppt tt false)) ⟩
loop ∙ ap to (ppt tt false) =⟨ To.pp-β (tt , false) |in-ctx (λ u → loop ∙ u) ⟩
loop ∙ idp =⟨ ∙-unit-r loop ⟩
loop ∎))
-- Second composite
from-to-cct : (b : Bool) → from (to (cct tt b)) == cct tt b
from-to-cct true = idp
from-to-cct false = ! (ppt tt false)
abstract
from-to-ppt : (b : Bool) → ap from (ap to (ppt tt b)) ∙' from-to-cct (not b) == from-to-cct b ∙ ppt tt b
from-to-ppt true =
ap from (ap to (ppt tt true)) ∙' ! (ppt tt false) =⟨ To.pp-β (tt , true) |in-ctx (λ u → ap from u ∙' ! (ppt tt false)) ⟩
ap from loop ∙' ! (ppt tt false) =⟨ From.loop-β |in-ctx (λ u → u ∙' ! (ppt tt false)) ⟩
(ppt tt true ∙ ppt tt false) ∙' ! (ppt tt false) =⟨ lemma (ppt tt true) (ppt tt false) ⟩
ppt tt true ∎ where
lemma : ∀ {i} {A : Type i} {a b c : A} (p : a == b) (q : b == c) → (p ∙ q) ∙' (! q) == p
lemma idp idp = idp
from-to-ppt false =
ap from (ap to (ppt tt false)) =⟨ To.pp-β (tt , false) |in-ctx ap from ⟩
ap from (idp {a = base}) =⟨ ! (!-inv-l (ppt tt false)) ⟩
! (ppt tt false) ∙ ppt tt false ∎
from-to : (x : Wt) → from (to x) == x
from-to = Wt.elim (from-to-cct ∘ snd) (λ b → ↓-∘=idf-in from to (from-to-ppt (snd b)))
-- Conclusion
subresult : Wt ≃ S¹
subresult = equiv to from to-from from-to
-- Conclusion
result : Σ S¹ HopfJunior ≃ S¹
result = subresult ∘e (coe-equiv tot-is-Wt)
| 31.767677
| 126
| 0.553577
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.