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
a0ec9c40a07d40c48c3b4572628734324adbe5bf
1,235
agda
Agda
theorems/cw/cohomology/TipCoboundary.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/cw/cohomology/TipCoboundary.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/cw/cohomology/TipCoboundary.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 open import groups.Cokernel open import groups.Exactness open import groups.ExactSequence open import cohomology.Theory open import cw.CW module cw.cohomology.TipCoboundary {i} (OT : OrdinaryTheory i) (⊙skel : ⊙Skeleton {i} 1) where open OrdinaryTheory OT open import cw.cohomology.TipAndAugment OT (⊙cw-init ⊙skel) open import cw.cohomology.WedgeOfCells OT ⊙skel open import cohomology.LongExactSequence cohomology-theory 0 (⊙cw-incl-last ⊙skel) CX₁/X₀-is-abelian = CXₙ/Xₙ₋₁-is-abelian 1 cw-co∂-head' : CX₀ 0 →ᴳ CXₙ/Xₙ₋₁ 1 cw-co∂-head' = co∂ cw-co∂-head : C2×CX₀ 0 →ᴳ CXₙ/Xₙ₋₁ 1 cw-co∂-head = record {f = GroupHom.f cw-co∂-head' ∘ snd; pres-comp = lemma} where abstract lemma = ∘-pres-comp cw-co∂-head' (×ᴳ-snd {G = C2 0} {H = CX₀ 0}) abstract -- This relies on the [lemma] above being non-abstract within this scope. co∂-head-incl-exact : is-exact cw-co∂-head (C-fmap 1 (⊙cfcod' (⊙cw-incl-last ⊙skel))) co∂-head-incl-exact = pre∘-is-exact (×ᴳ-snd {G = C2 0} {H = CX₀ 0}) (×ᴳ-snd-is-surj {G = C2 0} {H = CX₀ 0}) (exact-seq-index 1 C-cofiber-exact-seq) module CokerCo∂Head where grp = Coker cw-co∂-head CX₁/X₀-is-abelian open Group grp public
31.666667
87
0.689879
52305ac95c2fc6622421d94ed4097038de3f327a
1,527
agda
Agda
src/data/lib/prim/Agda/Builtin/String.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
src/data/lib/prim/Agda/Builtin/String.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
src/data/lib/prim/Agda/Builtin/String.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-} module Agda.Builtin.String where open import Agda.Builtin.Bool open import Agda.Builtin.Char open import Agda.Builtin.List open import Agda.Builtin.Maybe open import Agda.Builtin.Nat using (Nat) open import Agda.Builtin.Sigma postulate String : Set {-# BUILTIN STRING String #-} primitive primStringUncons : String → Maybe (Σ Char (λ _ → String)) primStringToList : String → List Char primStringFromList : List Char → String primStringAppend : String → String → String primStringEquality : String → String → Bool primShowChar : Char → String primShowString : String → String primShowNat : Nat → String {-# COMPILE JS primStringUncons = function(x) { if (x === "") { return z_jAgda_Agda_Builtin_Maybe["Maybe"]["nothing"]; }; return z_jAgda_Agda_Builtin_Maybe["Maybe"]["just"](z_jAgda_Agda_Builtin_Sigma["_,_"](x.charAt(0))(x.slice(1))); } #-} {-# COMPILE JS primStringToList = function(x) { return x.split(""); } #-} {-# COMPILE JS primStringFromList = function(x) { return x.join(""); } #-} {-# COMPILE JS primStringAppend = function(x) { return function(y) { return x+y; }; } #-} {-# COMPILE JS primStringEquality = function(x) { return function(y) { return x===y; }; } #-} {-# COMPILE JS primShowChar = function(x) { return JSON.stringify(x); } #-} {-# COMPILE JS primShowString = function(x) { return JSON.stringify(x); } #-} {-# COMPILE JS primShowNat = function(x) { return JSON.stringify(x); } #-}
41.27027
114
0.681074
436d12d82f5a7930af700e5958a419abefd98698
20,157
agda
Agda
bench/Bench.agda
zarybnicky/smalltt
783840e3444cbdc7927dd4a940d9c0ad5dc47223
[ "BSD-3-Clause" ]
null
null
null
bench/Bench.agda
zarybnicky/smalltt
783840e3444cbdc7927dd4a940d9c0ad5dc47223
[ "BSD-3-Clause" ]
null
null
null
bench/Bench.agda
zarybnicky/smalltt
783840e3444cbdc7927dd4a940d9c0ad5dc47223
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --type-in-type #-} U = Set id : {A : Set} → A → A id = λ x → x id2 : ∀ {A} → A → A id2 = id id id3 : ∀ {A} → A → A id3 = λ x → id x id4 : {A : Set} -> A -> A id4 = \x -> x the : (A : Set) → A → A the = λ _ x → x constTy = {A B : Set} → A → B → A const : constTy const = λ x y → x constU = const {Set} namedArgTest = const {B = U} U namedArgTest2 = the constTy (λ x y → x) {B = U} U -- Church bools -------------------------------------------------------------------------------- Bool = (B : U) → B → B → B true : Bool true = λ _ t f → t false : Bool false = λ _ t f → f and : Bool → Bool → Bool and = λ b1 b2 → b1 Bool true b2 -- Church natural numbers -------------------------------------------------------------------------------- Nat : U Nat = (n : U) → (n → n) → n → n zero : Nat zero = λ n s z → z suc : Nat → Nat suc = λ a n s z → s (a n s z) n2 : Nat n2 = λ n s z → s (s z) n5 : Nat n5 = λ n s z → s (s (s (s (s z)))) mul : Nat → Nat → Nat mul = λ a b n s z → a n (b n s) z add : Nat → Nat → Nat add = λ a b n s z → a n s (b n s z) n10 = mul n2 n5 n10b = mul n5 n2 n100 = mul n10 n10 n100b = mul n10b n10b n10k = mul n100 n100 n10kb = mul n100b n100b n100k = mul n10k n10 n100kb = mul n10kb n10b n1M = mul n10k n100 n1Mb = mul n10kb n100b n10M = mul n1M n10 n10Mb = mul n1Mb n10b n100M = mul n10M n10 n200M = mul n2 n100M -- Church lists -------------------------------------------------------------------------------- List : U → U List = λ a → (l : U) → (a → l → l) → l → l lnil : ∀{a} → List a lnil = λ l c n → n lcons : ∀{a} → a → List a → List a lcons = λ a as l c n → c a (as l c n) list1 = lcons true (lcons false (lcons false lnil)) map : ∀{a b} → (a → b) → List a → List b map = λ f as l c → as l (λ a → c (f a)) -- Church vectors -------------------------------------------------------------------------------- Vec : U → Nat → U Vec = λ a n → (V : Nat → U) → V zero → (∀{n} → a → V n → V (suc n)) → V n vnil : ∀{a} → Vec a zero vnil = λ V n c → n vcons : ∀{a n} → a → Vec a n → Vec a (suc n) vcons = λ a as V n c → c a (as V n c) vec1 = vcons true (vcons false (vcons true vnil)) vecStress = (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true (vcons true vnil)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))) -- Leibniz (Church) propositional equality, useful for testing conversion. -------------------------------------------------------------------------------- Eq : ∀{A : U} → A → A → U Eq {A} = λ x y → (P : A → U) → P x → P y refl : ∀{A}{x : A} → Eq x x refl = λ P px → px trans : ∀{A}{x y z : A} → Eq x y → Eq y z → Eq x z trans = λ p q → q _ p sym : ∀{A}{x y : A} → Eq x y → Eq y x sym {_}{x}{y} = λ p → p (λ y → Eq y x) refl ap : ∀{A B}(f : A → B){x y : A} → Eq x y → Eq (f x) (f y) ap = λ f {x}{y} p → p (λ y → Eq (f x) (f y)) refl -- Pairs, Top, Bot -------------------------------------------------------------------------------- Pair : U → U → U Pair = λ A B → (Pair : U)(pair : A → B → Pair) → Pair pair : ∀{A B} → A → B → Pair A B pair = λ a b Pair pair → pair a b proj1 : ∀{A B} → Pair A B → A proj1 = λ p → p _ (λ x y → x) proj2 : ∀{A B} → Pair A B → B proj2 = λ p → p _ (λ x y → y) Top : U Top = (Top : U)(tt : Top) → Top tt : Top tt = λ Top tt → tt Bot : U Bot = (Bot : U) → Bot -- Dependent function composition -------------------------------------------------------------------------------- comp : ∀ {A : U} {B : A → U} {C : ∀{a} → B a → U} (f : ∀{a}(b : B a) → C b) (g : (a : A) → B a) (x : A) → C (g x) comp = λ f g a → f (g a) compTest1 : Nat → Nat compTest1 = comp suc suc compTest2 : ∀{m A} → A → Vec A m → Vec A (suc (suc m)) compTest2 = λ a → comp (vcons a) (vcons a) -- Some stress tests -------------------------------------------------------------------------------- nfun : Nat → U nfun n = n U (λ A → U → A) U -- OK synEqTest1 : Eq n1M n1M synEqTest1 = refl -- fail -- synEqTest2 : nfun n10k → nfun n10k -- synEqTest2 = λ x → x -- OK idStress : ∀{A} → A → A idStress = id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id id -- fail -- pairStress : Top -- pairStress = -- let x0 = pair tt tt -- x1 = pair x0 x0 -- x2 = pair x1 x1 -- x3 = pair x2 x2 -- x4 = pair x3 x3 -- x5 = pair x4 x4 -- x6 = pair x5 x5 -- x7 = pair x6 x6 -- x8 = pair x7 x7 -- x9 = pair x8 x8 -- x10 = pair x9 x9 -- x11 = pair x10 x10 -- x12 = pair x11 x11 -- x13 = pair x12 x12 -- x14 = pair x13 x13 -- x15 = pair x14 x14 -- x16 = pair x15 x15 -- x17 = pair x16 x16 -- x18 = pair x17 x17 -- x19 = pair x18 x18 -- x20 = pair x19 x19 -- in tt forceNat : Nat → Bool forceNat n = n _ (λ b → b) true computeTest = forceNat n10M -- Conversion checking tests -------------------------------------------------------------------------------- -- conv100k : Eq n100k n100kb -- conv100k = refl -- conv1M : Eq n1M n1Mb -- conv1M = refl -- OOM -- conv10M : Eq n10M n1M0b -- conv10M = refl -- convNfun1M : Eq (nfun n1M) (nfun n1Mb) -- convNfun1M = refl -- conv10kmeta : Eq n10k (add n10kb _) -- conv10kmeta = refl -- OOM -- conv1Mmeta : Eq n1M (add n1Mb _) -- conv1Mmeta = refl -------------------------------------------------------------------------------- -- normalized instantly lazyU = const U (forceNat n10M) localCBN : Nat → Bool localCBN = λ n → let m = forceNat (mul n n100k) in n _ (λ b → and m b) true cbnReference = forceNat (mul n10 n100k) localCBNtest = localCBN n10 -- Church-coded simply typed lambda calculus -------------------------------------------------------------------------------- Ty : U Ty = (Ty : U) (ι : Ty) (fun : Ty → Ty → Ty) → Ty ι : Ty ι = λ _ ι _ → ι fun : Ty → Ty → Ty fun = λ A B Ty ι fun → fun (A Ty ι fun) (B Ty ι fun) Con : U Con = (Con : U) (nil : Con) (cons : Con → Ty → Con) → Con nil : Con nil = λ Con nil cons → nil cons : Con → Ty → Con cons = λ Γ A Con nil cons → cons (Γ Con nil cons) A Var : Con → Ty → U Var = λ Γ A → (Var : Con → Ty → U) (vz : ∀{Γ A} → Var (cons Γ A) A) (vs : ∀{Γ B A} → Var Γ A → Var (cons Γ B) A) → Var Γ A vz : ∀{Γ A} → Var (cons Γ A) A vz = λ Var vz vs → vz vs : ∀{Γ B A} → Var Γ A → Var (cons Γ B) A vs = λ x Var vz vs → vs (x Var vz vs) Tm : Con → Ty → U Tm = λ Γ A → (Tm : Con → Ty → U) (var : ∀{Γ A} → Var Γ A → Tm Γ A) (lam : ∀{Γ A B} → Tm (cons Γ A) B → Tm Γ (fun A B)) (app : ∀{Γ A B} → Tm Γ (fun A B) → Tm Γ A → Tm Γ B) → Tm Γ A var : ∀{Γ A} → Var Γ A → Tm Γ A var = λ x Tm var lam app → var x lam : ∀{Γ A B} → Tm (cons Γ A) B → Tm Γ (fun A B) lam = λ t Tm var lam app → lam (t Tm var lam app) app : ∀{Γ A B} → Tm Γ (fun A B) → Tm Γ A → Tm Γ B app = λ t u Tm var lam app → app (t Tm var lam app) (u Tm var lam app) -- Well-typed interpreter for Church-coded STLC -------------------------------------------------------------------------------- EvalTy : Ty → U EvalTy = λ A → A _ Bot (λ A B → A → B) EvalCon : Con → U EvalCon = λ Γ → Γ _ Top (λ Δ A → Pair Δ (EvalTy A)) EvalVar : ∀{Γ A} → Var Γ A → EvalCon Γ → EvalTy A EvalVar = λ x → x (λ Γ A → EvalCon Γ → EvalTy A) (λ env → proj2 env) (λ rec env → rec (proj1 env)) EvalTm : ∀{Γ A} → Tm Γ A → EvalCon Γ → EvalTy A EvalTm = λ t → t (λ Γ A → EvalCon Γ → EvalTy A) EvalVar (λ t env α → t (pair env α)) (λ t u env → t env (u env)) -- Large embedded STLC term -------------------------------------------------------------------------------- t1 : Tm nil (fun (fun ι ι) (fun ι ι)) t1 = lam (lam ( app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (app (var (vs vz)) (var vz)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) )))))))))))))))))))))))))))))))))))))) )) -- test evaluation evalTest = EvalTm t1 tt
37.121547
80
0.52359
4d59644e80600bd6b8bf4fea1e511c6667957982
277
agda
Agda
src/PosNat.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
1
2020-04-15T15:28:03.000Z
2020-04-15T15:28:03.000Z
src/PosNat.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
null
null
null
src/PosNat.agda
ice1k/Theorems
7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc
[ "Apache-2.0" ]
null
null
null
module PosNat where open import Nats open import Data.Product open import Equality data ℕ⁺ : Set where psuc : ℕ → ℕ⁺ _→ℕ : ℕ⁺ → ℕ psuc zero →ℕ = suc zero psuc (suc x) →ℕ = suc (psuc x →ℕ) _⟨_⟩→ℕ⁺ : (a : ℕ) → ∃ (λ x → a ≡ suc x) → ℕ⁺ .(suc x) ⟨ x , refl ⟩→ℕ⁺ = psuc x
17.3125
44
0.559567
0d6e21c50f1e25fe9dd3845937da1611332f8b0d
4,710
agda
Agda
Cubical/HITs/KleinBottle/Properties.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/HITs/KleinBottle/Properties.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
Cubical/HITs/KleinBottle/Properties.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
{- Definition of the Klein bottle as a HIT -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.KleinBottle.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.HLevels open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Data.Nat open import Cubical.Data.Int public renaming (_+_ to _+Int_ ; +-assoc to +Int-assoc; +-comm to +Int-comm) open import Cubical.Data.Sigma open import Cubical.HITs.S1 open import Cubical.HITs.PropositionalTruncation as PropTrunc open import Cubical.HITs.KleinBottle.Base loop1 : S¹ → KleinBottle loop1 base = point loop1 (loop i) = line1 i invS¹Loop : S¹ → Set invS¹Loop base = S¹ invS¹Loop (loop i) = invS¹Path i loop1Inv : (s : S¹) → loop1 (inv s) ≡ loop1 s loop1Inv base = line2 loop1Inv (loop i) = square i twist : (s : S¹) → PathP (λ i → invS¹Path i) s (inv s) twist s i = glue (λ {(i = i0) → s; (i = i1) → inv s}) (inv s) twistBaseLoop : (s : S¹) → invS¹Loop s twistBaseLoop base = base twistBaseLoop (loop i) = twist base i kleinBottle≃Σ : KleinBottle ≃ Σ S¹ invS¹Loop kleinBottle≃Σ = isoToEquiv (iso fro to froTo toFro) where fro : KleinBottle → Σ S¹ invS¹Loop fro point = (base , base) fro (line1 i) = (base , loop i) fro (line2 j) = (loop (~ j) , twist base (~ j)) fro (square i j) = (loop (~ j) , twist (loop i) (~ j)) toLoopFiller : (j : I) → ua invS¹Equiv j → I → KleinBottle toLoopFiller j g l = hfill (λ l → λ { (j = i0) → loop1Inv g l ; (j = i1) → loop1 g }) (inS (loop1 (unglue (j ∨ ~ j) g))) l to : Σ S¹ invS¹Loop → KleinBottle to (base , s) = loop1 s to (loop j , g) = toLoopFiller j g i1 toFro : (a : KleinBottle) → to (fro a) ≡ a toFro point = refl toFro (line1 i) = refl toFro (line2 j) k = lUnit line2 (~ k) j toFro (square i j) k = lUnit (square i) (~ k) j froLoop1 : (s : S¹) → fro (loop1 s) ≡ (base , s) froLoop1 base = refl froLoop1 (loop i) = refl froLoop1Inv : PathP (λ k → (s : S¹) → froLoop1 (inv s) k ≡ froLoop1 s k) (λ s l → fro (loop1Inv s l)) (λ s l → loop (~ l) , twist s (~ l)) froLoop1Inv k base l = loop (~ l) , twist base (~ l) froLoop1Inv k (loop i) l = loop (~ l) , twist (loop i) (~ l) froTo : (a : Σ S¹ invS¹Loop) → fro (to a) ≡ a froTo (base , s) = froLoop1 s froTo (loop j , g) k = hcomp (λ l → λ { (j = i0) → froLoop1Inv k g l ; (j = i1) → froLoop1 g k ; (k = i0) → fro (toLoopFiller j g l) ; (k = i1) → ( loop (j ∨ ~ l) , glue (λ { (j = i0) (l = i1) → g ; (j = i1) → g ; (l = i0) → unglue (j ∨ ~ j) g }) (unglue (j ∨ ~ j) g) ) }) (froLoop1 (unglue (j ∨ ~ j) g) k) isGroupoidKleinBottle : isGroupoid KleinBottle isGroupoidKleinBottle = transport (λ i → isGroupoid (ua kleinBottle≃Σ (~ i))) (isOfHLevelΣ 3 isGroupoidS¹ (λ s → PropTrunc.rec (isPropIsOfHLevel 3) (λ p → subst (λ s → isGroupoid (invS¹Loop s)) p isGroupoidS¹) (isConnectedS¹ s))) -- Transport across the following is too slow :( ΩKlein≡Int² : Path KleinBottle point point ≡ Int × Int ΩKlein≡Int² = Path KleinBottle point point ≡⟨ (λ i → basePath i ≡ basePath i) ⟩ Path (Σ S¹ invS¹Loop) (base , base) (base , base) ≡⟨ sym Σ≡ ⟩ Σ ΩS¹ (λ p → PathP (λ j → invS¹Loop (p j)) base base) ≡⟨ (λ i → Σ ΩS¹ (λ p → PathP (λ j → invS¹Loop (p (j ∨ i))) (twistBaseLoop (p i)) base)) ⟩ ΩS¹ × ΩS¹ ≡⟨ (λ i → ΩS¹≡Int i × ΩS¹≡Int i) ⟩ Int × Int ∎ where basePath : PathP (λ i → ua kleinBottle≃Σ i) point (base , base) basePath i = glue (λ {(i = i0) → point; (i = i1) → base , base}) (base , base) -- We can at least define the winding function directly and get results on small examples windingKlein : Path KleinBottle point point → Int × Int windingKlein p = (z₀ , z₁) where step₀ : Path (Σ S¹ invS¹Loop) (base , base) (base , base) step₀ = (λ i → kleinBottle≃Σ .fst (p i)) z₀ : Int z₀ = winding (λ i → kleinBottle≃Σ .fst (p i) .fst) z₁ : Int z₁ = winding (transport (λ i → PathP (λ j → invS¹Loop (step₀ (j ∨ i) .fst)) (twistBaseLoop (step₀ i .fst)) base) (cong snd step₀)) _ : windingKlein line1 ≡ (pos 0 , pos 1) _ = refl _ : windingKlein line2 ≡ (negsuc 0 , pos 0) _ = refl _ : windingKlein (line1 ∙ line2) ≡ (negsuc 0 , negsuc 0) _ = refl _ : windingKlein (line1 ∙ line2 ∙ line1) ≡ (negsuc 0 , pos 0) _ = refl
29.254658
105
0.594692
4e46b3a6ba5ffde39fd34151e06639028c537ed3
18,031
agda
Agda
LibraBFT/Lemmas.agda
cwjnkins/bft-consensus-agda
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
[ "UPL-1.0" ]
null
null
null
LibraBFT/Lemmas.agda
cwjnkins/bft-consensus-agda
71aa2168e4875ffdeece9ba7472ee3cee5fa9084
[ "UPL-1.0" ]
null
null
null
LibraBFT/Lemmas.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 LibraBFT.Prelude open import Level using (0ℓ) -- This module incldes various Agda lemmas that are independent of the project's domain module LibraBFT.Lemmas where cong₃ : ∀{a b c d}{A : Set a}{B : Set b}{C : Set c}{D : Set d} → (f : A → B → C → D) → ∀{x y u v m n} → x ≡ y → u ≡ v → m ≡ n → f x u m ≡ f y v n cong₃ f refl refl refl = refl ≡-pi : ∀{a}{A : Set a}{x y : A}(p q : x ≡ y) → p ≡ q ≡-pi refl refl = refl Unit-pi : {u1 u2 : Unit} → u1 ≡ u2 Unit-pi {unit} {unit} = refl ++-inj : ∀{a}{A : Set a}{m n o p : List A} → length m ≡ length n → m ++ o ≡ n ++ p → m ≡ n × o ≡ p ++-inj {m = []} {x ∷ n} () hip ++-inj {m = x ∷ m} {[]} () hip ++-inj {m = []} {[]} lhip hip = refl , hip ++-inj {m = m ∷ ms} {n ∷ ns} lhip hip with ++-inj {m = ms} {ns} (suc-injective lhip) (proj₂ (∷-injective hip)) ...| (mn , op) rewrite proj₁ (∷-injective hip) = cong (n ∷_) mn , op ++-abs : ∀{a}{A : Set a}{n : List A}(m : List A) → 1 ≤ length m → [] ≡ m ++ n → ⊥ ++-abs [] () ++-abs (x ∷ m) imp () data All-vec {ℓ} {A : Set ℓ} (P : A → Set ℓ) : ∀ {n} → Vec {ℓ} A n → Set (Level.suc ℓ) where [] : All-vec P [] _∷_ : ∀ {x n} {xs : Vec A n} (px : P x) (pxs : All-vec P xs) → All-vec P (x ∷ xs) ≤-unstep : ∀{m n} → suc m ≤ n → m ≤ n ≤-unstep (s≤s ss) = ≤-step ss ≡⇒≤ : ∀{m n} → m ≡ n → m ≤ n ≡⇒≤ refl = ≤-refl ∈-cong : ∀{a b}{A : Set a}{B : Set b}{x : A}{l : List A} → (f : A → B) → x ∈ l → f x ∈ List-map f l ∈-cong f (here px) = here (cong f px) ∈-cong f (there hyp) = there (∈-cong f hyp) All-self : ∀{a}{A : Set a}{xs : List A} → All (_∈ xs) xs All-self = All-tabulate (λ x → x) All-reduce⁺ : ∀{a b}{A : Set a}{B : Set b}{Q : A → Set}{P : B → Set} → { xs : List A } → (f : ∀{x} → Q x → B) → (∀{x} → (prf : Q x) → P (f prf)) → (all : All Q xs) → All P (All-reduce f all) All-reduce⁺ f hyp [] = [] All-reduce⁺ f hyp (ax ∷ axs) = (hyp ax) ∷ All-reduce⁺ f hyp axs All-reduce⁻ : ∀{a b}{A : Set a}{B : Set b} {Q : A → Set} → { xs : List A } → ∀ {vdq} → (f : ∀{x} → Q x → B) → (all : All Q xs) → vdq ∈ All-reduce f all → ∃[ v ] ∃[ v∈xs ] (vdq ≡ f {v} v∈xs) All-reduce⁻ {Q = Q} {(h ∷ _)} {vdq} f (px ∷ pxs) (here refl) = h , px , refl All-reduce⁻ {Q = Q} {(_ ∷ t)} {vdq} f (px ∷ pxs) (there vdq∈) = All-reduce⁻ {xs = t} f pxs vdq∈ List-index : ∀ {A : Set} → (_≟A_ : (a₁ a₂ : A) → Dec (a₁ ≡ a₂)) → A → (l : List A) → Maybe (Fin (length l)) List-index _≟A_ x l with break (_≟A x) l ...| not≡ , _ with length not≡ <? length l ...| no _ = nothing ...| yes found = just ( fromℕ< {length not≡} {length l} found) nats : ℕ → List ℕ nats 0 = [] nats (suc n) = (nats n) ++ (n ∷ []) _ : nats 4 ≡ 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] _ = refl _ : Maybe-map toℕ (List-index _≟_ 2 (nats 4)) ≡ just 2 _ = refl _ : Maybe-map toℕ (List-index _≟_ 4 (nats 4)) ≡ nothing _ = refl allDistinct : ∀ {A : Set} → List A → Set allDistinct l = ∀ (i j : Σ ℕ (_< length l)) → proj₁ i ≡ proj₁ j ⊎ List-lookup l (fromℕ< (proj₂ i)) ≢ List-lookup l (fromℕ< (proj₂ j)) postulate -- TODO-1: currently unused; prove it, if needed allDistinct? : ∀ {A : Set} → {≟A : (a₁ a₂ : A) → Dec (a₁ ≡ a₂)} → (l : List A) → Dec (allDistinct l) -- Extends an arbitrary relation to work on the head of -- the supplied list, if any. data OnHead {A : Set}(P : A → A → Set) (x : A) : List A → Set where [] : OnHead P x [] on-∷ : ∀{y ys} → P x y → OnHead P x (y ∷ ys) -- Establishes that a list is sorted according to the supplied -- relation. data IsSorted {A : Set}(_<_ : A → A → Set) : List A → Set where [] : IsSorted _<_ [] _∷_ : ∀{x xs} → OnHead _<_ x xs → IsSorted _<_ xs → IsSorted _<_ (x ∷ xs) OnHead-prop : ∀{A}(P : A → A → Set)(x : A)(l : List A) → Irrelevant P → isPropositional (OnHead P x l) OnHead-prop P x [] hyp [] [] = refl OnHead-prop P x (x₁ ∷ l) hyp (on-∷ x₂) (on-∷ x₃) = cong on-∷ (hyp x₂ x₃) IsSorted-prop : ∀{A}(_<_ : A → A → Set)(l : List A) → Irrelevant _<_ → isPropositional (IsSorted _<_ l) IsSorted-prop _<_ [] hyp [] [] = refl IsSorted-prop _<_ (x ∷ l) hyp (x₁ ∷ a) (x₂ ∷ b) = cong₂ _∷_ (OnHead-prop _<_ x l hyp x₁ x₂) (IsSorted-prop _<_ l hyp a b) IsSorted-map⁻ : {A : Set}{_≤_ : A → A → Set} → {B : Set}(f : B → A)(l : List B) → IsSorted (λ x y → f x ≤ f y) l → IsSorted _≤_ (List-map f l) IsSorted-map⁻ f .[] [] = [] IsSorted-map⁻ f .(_ ∷ []) (x ∷ []) = [] ∷ [] IsSorted-map⁻ f .(_ ∷ _ ∷ _) (on-∷ x ∷ (x₁ ∷ is)) = (on-∷ x) ∷ IsSorted-map⁻ f _ (x₁ ∷ is) transOnHead : ∀ {A} {l : List A} {y x : A} {_<_ : A → A → Set} → Transitive _<_ → OnHead _<_ y l → x < y → OnHead _<_ x l transOnHead _ [] _ = [] transOnHead trans (on-∷ y<f) x<y = on-∷ (trans x<y y<f) ++-OnHead : ∀ {A} {xs ys : List A} {y : A} {_<_ : A → A → Set} → OnHead _<_ y xs → OnHead _<_ y ys → OnHead _<_ y (xs ++ ys) ++-OnHead [] y<y₁ = y<y₁ ++-OnHead (on-∷ y<x) _ = on-∷ y<x h∉t : ∀ {A} {t : List A} {h : A} {_<_ : A → A → Set} → Irreflexive _<_ _≡_ → Transitive _<_ → IsSorted _<_ (h ∷ t) → h ∉ t h∉t irfl trans (on-∷ h< ∷ sxs) (here refl) = ⊥-elim (irfl h< refl) h∉t irfl trans (on-∷ h< ∷ (x₁< ∷ sxs)) (there h∈t) = h∉t irfl trans ((transOnHead trans x₁< h<) ∷ sxs) h∈t ≤-head : ∀ {A} {l : List A} {x y : A} {_<_ : A → A → Set} {_≤_ : A → A → Set} → Reflexive _≤_ → Trans _<_ _≤_ _≤_ → y ∈ (x ∷ l) → IsSorted _<_ (x ∷ l) → _≤_ x y ≤-head ref≤ trans (here refl) _ = ref≤ ≤-head ref≤ trans (there y∈) (on-∷ x<x₁ ∷ sl) = trans x<x₁ (≤-head ref≤ trans y∈ sl) -- TODO-1 : Better name and/or replace with library property Any-sym : ∀ {a b}{A : Set a}{B : Set b}{tgt : B}{l : List A}{f : A → B} → Any (λ x → tgt ≡ f x) l → Any (λ x → f x ≡ tgt) l Any-sym (here x) = here (sym x) Any-sym (there x) = there (Any-sym x) Any-lookup-correct : ∀ {a b}{A : Set a}{B : Set b}{tgt : B}{l : List A}{f : A → B} → (p : Any (λ x → f x ≡ tgt) l) → Any-lookup p ∈ l Any-lookup-correct (here px) = here refl Any-lookup-correct (there p) = there (Any-lookup-correct p) Any-lookup-correctP : ∀ {a}{A : Set a}{l : List A}{P : A → Set} → (p : Any P l) → Any-lookup p ∈ l Any-lookup-correctP (here px) = here refl Any-lookup-correctP (there p) = there (Any-lookup-correctP p) Any-witness : ∀ {a b} {A : Set a} {l : List A} {P : A → Set b} → (p : Any P l) → P (Any-lookup p) Any-witness (here px) = px Any-witness (there x) = Any-witness x -- TODO-1: there is probably a library property for this. ∈⇒Any : ∀ {A : Set}{x : A} → {xs : List A} → x ∈ xs → Any (_≡ x) xs ∈⇒Any {x = x} (here refl) = here refl ∈⇒Any {x = x} {h ∷ t} (there xxxx) = there (∈⇒Any {xs = t} xxxx) false≢true : false ≢ true false≢true () witness : {A : Set}{P : A → Set}{x : A}{xs : List A} → x ∈ xs → All P xs → P x witness x y = All-lookup y x maybe-⊥ : ∀{a}{A : Set a}{x : A}{y : Maybe A} → y ≡ just x → y ≡ nothing → ⊥ maybe-⊥ () refl Maybe-map-cool : ∀ {S S₁ : Set} {f : S → S₁} {x : Maybe S} {z} → Maybe-map f x ≡ just z → x ≢ nothing Maybe-map-cool {x = nothing} () Maybe-map-cool {x = just y} prf = λ x → ⊥-elim (maybe-⊥ (sym x) refl) Maybe-map-cool-1 : ∀ {S S₁ : Set} {f : S → S₁} {x : Maybe S} {z} → Maybe-map f x ≡ just z → Σ S (λ x' → f x' ≡ z) Maybe-map-cool-1 {x = nothing} () Maybe-map-cool-1 {x = just y} {z = z} refl = y , refl Maybe-map-cool-2 : ∀ {S S₁ : Set} {f : S → S₁} {x : S} {z} → f x ≡ z → Maybe-map f (just x) ≡ just z Maybe-map-cool-2 {S}{S₁}{f}{x}{z} prf rewrite prf = refl T⇒true : ∀ {a : Bool} → T a → a ≡ true T⇒true {true} _ = refl isJust : ∀ {A : Set}{aMB : Maybe A}{a : A} → aMB ≡ just a → Is-just aMB isJust refl = just tt to-witness-isJust-≡ : ∀ {A : Set}{aMB : Maybe A}{a prf} → to-witness (isJust {aMB = aMB} {a} prf) ≡ a to-witness-isJust-≡ {aMB = just a'} {a} {prf} with to-witness-lemma (isJust {aMB = just a'} {a} prf) refl ...| xxx = just-injective (trans (sym xxx) prf) deMorgan : ∀ {A B : Set} → (¬ A) ⊎ (¬ B) → ¬ (A × B) deMorgan (inj₁ ¬a) = λ a×b → ¬a (proj₁ a×b) deMorgan (inj₂ ¬b) = λ a×b → ¬b (proj₂ a×b) ¬subst : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {P : A → Set ℓ₂} → {x y : A} → ¬ (P x) → y ≡ x → ¬ (P y) ¬subst px refl = px ∸-suc-≤ : ∀ (x w : ℕ) → suc x ∸ w ≤ suc (x ∸ w) ∸-suc-≤ x zero = ≤-refl ∸-suc-≤ zero (suc w) rewrite 0∸n≡0 w = z≤n ∸-suc-≤ (suc x) (suc w) = ∸-suc-≤ x w m∸n≤o⇒m∸o≤n : ∀ (x z w : ℕ) → x ∸ z ≤ w → x ∸ w ≤ z m∸n≤o⇒m∸o≤n x zero w p≤ rewrite m≤n⇒m∸n≡0 p≤ = z≤n m∸n≤o⇒m∸o≤n zero (suc z) w p≤ rewrite 0∸n≡0 w = z≤n m∸n≤o⇒m∸o≤n (suc x) (suc z) w p≤ = ≤-trans (∸-suc-≤ x w) (s≤s (m∸n≤o⇒m∸o≤n x z w p≤)) tail-⊆ : ∀ {A : Set} {x} {xs ys : List A} → (x ∷ xs) ⊆List ys → xs ⊆List ys tail-⊆ xxs⊆ys x∈xs = xxs⊆ys (there x∈xs) allDistinctTail : ∀ {A : Set} {x} {xs : List A} → allDistinct (x ∷ xs) → allDistinct xs allDistinctTail allDist (i , i<l) (j , j<l) with allDist (suc i , s≤s i<l) (suc j , s≤s j<l) ...| inj₁ 1+i≡1+j = inj₁ (cong pred 1+i≡1+j) ...| inj₂ lookup≢ = inj₂ lookup≢ ∈-Any-Index-elim : ∀ {A : Set} {x y} {ys : List A} (x∈ys : x ∈ ys) → x ≢ y → y ∈ ys → y ∈ ys ─ Any-index x∈ys ∈-Any-Index-elim (here refl) x≢y (here refl) = ⊥-elim (x≢y refl) ∈-Any-Index-elim (here refl) _ (there y∈ys) = y∈ys ∈-Any-Index-elim (there _) _ (here refl) = here refl ∈-Any-Index-elim (there x∈ys) x≢y (there y∈ys) = there (∈-Any-Index-elim x∈ys x≢y y∈ys) ∉∧⊆List⇒∉ : ∀ {A : Set} {x} {xs ys : List A} → x ∉ xs → ys ⊆List xs → x ∉ ys ∉∧⊆List⇒∉ x∉xs ys∈xs x∈ys = ⊥-elim (x∉xs (ys∈xs x∈ys)) allDistinctʳʳ : ∀ {A : Set} {x x₁ : A} {xs : List A} → allDistinct (x ∷ x₁ ∷ xs) → allDistinct (x ∷ xs) allDistinctʳʳ _ (zero , _) (zero , _) = inj₁ refl allDistinctʳʳ allDist (zero , i<l) (suc j , j<l) with allDist (0 , s≤s z≤n) (suc (suc j) , s≤s j<l) ...| inj₂ x≢lookup = inj₂ λ x≡lkpxs → ⊥-elim (x≢lookup x≡lkpxs) allDistinctʳʳ allDist (suc i , i<l) (zero , j<l) with allDist (suc (suc i) , s≤s i<l) (0 , s≤s z≤n) ...| inj₂ x≢lookup = inj₂ λ x≡lkpxs → ⊥-elim (x≢lookup x≡lkpxs) allDistinctʳʳ allDist (suc i , i<l) (suc j , j<l) with allDist (2 + i , (s≤s i<l)) (2 + j , s≤s j<l) ...| inj₁ si≡sj = inj₁ (cong pred si≡sj) ...| inj₂ lookup≡ = inj₂ lookup≡ allDistinct⇒∉ : ∀ {A : Set} {x} {xs : List A} → allDistinct (x ∷ xs) → x ∉ xs allDistinct⇒∉ allDist (here x≡x₁) with allDist (0 , s≤s z≤n) (1 , s≤s (s≤s z≤n)) ... | inj₂ x≢x₁ = ⊥-elim (x≢x₁ x≡x₁) allDistinct⇒∉ allDist (there x∈xs) = allDistinct⇒∉ (allDistinctʳʳ allDist) x∈xs sumListMap : ∀ {A : Set} {x} {xs : List A} (f : A → ℕ) → (x∈xs : x ∈ xs) → f-sum f xs ≡ f x + f-sum f (xs ─ Any-index x∈xs) sumListMap _ (here refl) = refl sumListMap {_} {x} {x₁ ∷ xs} f (there x∈xs) rewrite sumListMap f x∈xs | sym (+-assoc (f x) (f x₁) (f-sum f (xs ─ Any-index x∈xs))) | +-comm (f x) (f x₁) | +-assoc (f x₁) (f x) (f-sum f (xs ─ Any-index x∈xs)) = refl lookup⇒Any : ∀ {A : Set} {xs : List A} {P : A → Set} (i : Fin (length xs)) → P (List-lookup xs i) → Any P xs lookup⇒Any {_} {_ ∷ _} zero px = here px lookup⇒Any {_} {_ ∷ _} (suc i) px = there (lookup⇒Any i px) x∉→AllDistinct : ∀ {A : Set} {x} {xs : List A} → allDistinct xs → x ∉ xs → allDistinct (x ∷ xs) x∉→AllDistinct _ _ (0 , _) (0 , _) = inj₁ refl x∉→AllDistinct _ x∉xs (0 , _) (suc j , j<l) = inj₂ (λ x≡lkp → x∉xs (lookup⇒Any (fromℕ< (≤-pred j<l)) x≡lkp)) x∉→AllDistinct _ x∉xs (suc i , i<l) (0 , _) = inj₂ (λ x≡lkp → x∉xs (lookup⇒Any (fromℕ< (≤-pred i<l)) (sym x≡lkp))) x∉→AllDistinct allDist x∉xs (suc i , i<l) (suc j , j<l) with allDist (i , (≤-pred i<l)) (j , (≤-pred j<l)) ...| inj₁ i≡j = inj₁ (cong suc i≡j) ...| inj₂ lkup≢ = inj₂ lkup≢ module DecLemmas {A : Set} (_≟D_ : Decidable {A = A} (_≡_)) where _∈?_ : ∀ (x : A) → (xs : List A) → Dec (Any (x ≡_) xs) x ∈? xs = Any-any (x ≟D_) xs y∉xs⇒Allxs≢y : ∀ {xs : List A} {x y} → y ∉ (x ∷ xs) → x ≢ y × y ∉ xs y∉xs⇒Allxs≢y {xs} {x} {y} y∉ with y ∈? xs ...| yes y∈xs = ⊥-elim (y∉ (there y∈xs)) ...| no y∉xs with x ≟D y ...| yes x≡y = ⊥-elim (y∉ (here (sym x≡y))) ...| no x≢y = x≢y , y∉xs ⊆List-Elim : ∀ {x} {xs ys : List A} (x∈ys : x ∈ ys) → x ∉ xs → xs ⊆List ys → xs ⊆List ys ─ Any-index x∈ys ⊆List-Elim (here refl) x∉xs xs∈ys x₂∈xs with xs∈ys x₂∈xs ...| here refl = ⊥-elim (x∉xs x₂∈xs) ...| there x∈xs = x∈xs ⊆List-Elim (there x∈ys) x∉xs xs∈ys x₂∈xxs with x₂∈xxs ...| there x₂∈xs = ⊆List-Elim (there x∈ys) (proj₂ (y∉xs⇒Allxs≢y x∉xs)) (tail-⊆ xs∈ys) x₂∈xs ...| here refl with xs∈ys x₂∈xxs ...| here refl = here refl ...| there x₂∈ys = there (∈-Any-Index-elim x∈ys (≢-sym (proj₁ (y∉xs⇒Allxs≢y x∉xs))) x₂∈ys) sum-⊆-≤ : ∀ {ys} (xs : List A) (f : A → ℕ) → allDistinct xs → xs ⊆List ys → f-sum f xs ≤ f-sum f ys sum-⊆-≤ [] _ _ _ = z≤n sum-⊆-≤ (x ∷ xs) f dxs xs⊆ys rewrite sumListMap f (xs⊆ys (here refl)) = let x∉xs = allDistinct⇒∉ dxs xs⊆ysT = tail-⊆ xs⊆ys xs⊆ys-x = ⊆List-Elim (xs⊆ys (here refl)) x∉xs xs⊆ysT disTail = allDistinctTail dxs in +-monoʳ-≤ (f x) (sum-⊆-≤ xs f disTail xs⊆ys-x) intersect : List A → List A → List A intersect xs [] = [] intersect xs (y ∷ ys) with y ∈? xs ...| yes _ = y ∷ intersect xs ys ...| no _ = intersect xs ys union : List A → List A → List A union xs [] = xs union xs (y ∷ ys) with y ∈? xs ...| yes _ = union xs ys ...| no _ = y ∷ union xs ys ∈-intersect : ∀ (xs ys : List A) {α} → α ∈ intersect xs ys → α ∈ xs × α ∈ ys ∈-intersect xs (y ∷ ys) α∈int with y ∈? xs | α∈int ...| no y∉xs | α∈ = ×-map₂ there (∈-intersect xs ys α∈) ...| yes y∈xs | here refl = y∈xs , here refl ...| yes y∈xs | there α∈ = ×-map₂ there (∈-intersect xs ys α∈) x∉⇒x∉intersect : ∀ {x} {xs ys : List A} → x ∉ xs ⊎ x ∉ ys → x ∉ intersect xs ys x∉⇒x∉intersect {x} {xs} {ys} x∉ x∈int = contraposition (∈-intersect xs ys) (deMorgan x∉) x∈int intersectDistinct : ∀ (xs ys : List A) → allDistinct xs → allDistinct ys → allDistinct (intersect xs ys) intersectDistinct xs (y ∷ ys) dxs dys with y ∈? xs ...| yes y∈xs = let distTail = allDistinctTail dys intDTail = intersectDistinct xs ys dxs distTail y∉intTail = x∉⇒x∉intersect (inj₂ (allDistinct⇒∉ dys)) in x∉→AllDistinct intDTail y∉intTail ...| no y∉xs = intersectDistinct xs ys dxs (allDistinctTail dys) x∉⇒x∉union : ∀ {x} {xs ys : List A} → x ∉ xs × x ∉ ys → x ∉ union xs ys x∉⇒x∉union {_} {_} {[]} (x∉xs , _) x∈∪ = ⊥-elim (x∉xs x∈∪) x∉⇒x∉union {x} {xs} {y ∷ ys} (x∉xs , x∉ys) x∈union with y ∈? xs | x∈union ...| yes y∈xs | x∈∪ = ⊥-elim (x∉⇒x∉union (x∉xs , (proj₂ (y∉xs⇒Allxs≢y x∉ys))) x∈∪) ...| no y∉xs | here refl = ⊥-elim (proj₁ (y∉xs⇒Allxs≢y x∉ys) refl) ...| no y∉xs | there x∈∪ = ⊥-elim (x∉⇒x∉union (x∉xs , (proj₂ (y∉xs⇒Allxs≢y x∉ys))) x∈∪) unionDistinct : ∀ (xs ys : List A) → allDistinct xs → allDistinct ys → allDistinct (union xs ys) unionDistinct xs [] dxs dys = dxs unionDistinct xs (y ∷ ys) dxs dys with y ∈? xs ...| yes y∈xs = unionDistinct xs ys dxs (allDistinctTail dys) ...| no y∉xs = let distTail = allDistinctTail dys uniDTail = unionDistinct xs ys dxs distTail y∉intTail = x∉⇒x∉union (y∉xs , allDistinct⇒∉ dys) in x∉→AllDistinct uniDTail y∉intTail sumIntersect≤ : ∀ (xs ys : List A) (f : A → ℕ) → f-sum f (intersect xs ys) ≤ f-sum f (xs ++ ys) sumIntersect≤ _ [] _ = z≤n sumIntersect≤ xs (y ∷ ys) f with y ∈? xs ...| yes y∈xs rewrite map-++-commute f xs (y ∷ ys) | sum-++-commute (List-map f xs) (List-map f (y ∷ ys)) | sym (+-assoc (f-sum f xs) (f y) (f-sum f ys)) | +-comm (f-sum f xs) (f y) | +-assoc (f y) (f-sum f xs) (f-sum f ys) | sym (sum-++-commute (List-map f xs) (List-map f ys)) | sym (map-++-commute f xs ys) = +-monoʳ-≤ (f y) (sumIntersect≤ xs ys f) ...| no y∉xs rewrite map-++-commute f xs (y ∷ ys) | sum-++-commute (List-map f xs) (List-map f (y ∷ ys)) | +-comm (f y) (f-sum f ys) | sym (+-assoc (f-sum f xs) (f-sum f ys) (f y)) | sym (sum-++-commute (List-map f xs) (List-map f ys)) | sym (map-++-commute f xs ys) = ≤-stepsʳ (f y) (sumIntersect≤ xs ys f)
37.331263
111
0.472852
37f9ba530bd3701fc2bc101df3843a8e2cb411fc
4,520
agda
Agda
proofs/AKS/Modular/Equivalence.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
1
2020-12-01T22:38:27.000Z
2020-12-01T22:38:27.000Z
proofs/AKS/Modular/Equivalence.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
null
null
null
proofs/AKS/Modular/Equivalence.agda
mckeankylej/thesis
ddad4c0d5f384a0219b2177461a68dae06952dde
[ "MIT" ]
null
null
null
open import Level using (_⊔_) open import Function using (_$_) open import Algebra using (CommutativeRing) module AKS.Modular.Equivalence {c ℓ} (R : CommutativeRing c ℓ) where open CommutativeRing R using (0#; 1#; _+_; _*_; -_; _-_) renaming (Carrier to C) open CommutativeRing R using (+-cong; +-congˡ; +-congʳ; +-identityʳ; +-assoc; +-comm) open CommutativeRing R using (-‿inverseʳ; -‿inverseˡ; -‿cong) open CommutativeRing R using (zeroˡ; distribʳ; distribˡ; *-congˡ; *-assoc; *-comm) open CommutativeRing R using (_≈_; isEquivalence; setoid; ring) renaming (refl to ≈-refl; sym to ≈-sym) open import Relation.Binary.Reasoning.Setoid setoid open import Algebra.Properties.Ring ring using (-‿distribˡ-*; -‿+-comm; -‿involutive; -0#≈0#) infix 4 _≈_[mod_] record _≈_[mod_] (x : C) (y : C) (n : C) : Set (c ⊔ ℓ) where constructor modulo field k : C x-y≈k*n : x - y ≈ k * n refl : ∀ {x} {y} {n} → x ≈ y → x ≈ y [mod n ] refl {x} {y} {n} x≈y = modulo 0# $ begin x - y ≈⟨ +-congˡ (-‿cong (≈-sym x≈y)) ⟩ x - x ≈⟨ -‿inverseʳ x ⟩ 0# ≈⟨ ≈-sym (zeroˡ n) ⟩ 0# * n ∎ sym : ∀ {x y} {n} → x ≈ y [mod n ] → y ≈ x [mod n ] sym {x} {y} {n} (modulo k x-y≈k*n) = modulo (- k) $ begin y - x ≈⟨ +-congʳ (≈-sym (-‿involutive y)) ⟩ - (- y) - x ≈⟨ -‿+-comm (- y) x ⟩ - (- y + x) ≈⟨ -‿cong (+-comm (- y) x) ⟩ - (x - y) ≈⟨ -‿cong x-y≈k*n ⟩ - (k * n) ≈⟨ -‿distribˡ-* k n ⟩ - k * n ∎ trans : ∀ {x y z} {n} → x ≈ y [mod n ] → y ≈ z [mod n ] → x ≈ z [mod n ] trans {x} {y} {z} {n} (modulo k₁ x-y≈k₁*n) (modulo k₂ y-z≈k₂*n) = modulo (k₁ + k₂) $ begin x - z ≈⟨ +-congʳ (≈-sym (+-identityʳ x)) ⟩ x + 0# - z ≈⟨ +-congʳ (+-congˡ (≈-sym (-‿inverseˡ y))) ⟩ x + (- y + y) - z ≈⟨ +-congʳ (≈-sym (+-assoc x (- y) y)) ⟩ (x - y) + y - z ≈⟨ +-assoc (x - y) y (- z) ⟩ (x - y) + (y - z) ≈⟨ +-cong x-y≈k₁*n y-z≈k₂*n ⟩ (k₁ * n) + (k₂ * n) ≈⟨ ≈-sym (distribʳ n k₁ k₂) ⟩ (k₁ + k₂) * n ∎ +-compat : ∀ {a₁ a₂ b₁ b₂} {n} → a₁ ≈ b₁ [mod n ] → a₂ ≈ b₂ [mod n ] → a₁ + a₂ ≈ b₁ + b₂ [mod n ] +-compat {a₁} {a₂} {b₁} {b₂} {n} (modulo k₁ a₁-b₁≈k₁*n) (modulo k₂ a₂-b₂≈k₂*n) = modulo (k₁ + k₂) $ begin a₁ + a₂ - (b₁ + b₂) ≈⟨ +-assoc a₁ a₂ (- (b₁ + b₂)) ⟩ a₁ + (a₂ - (b₁ + b₂)) ≈⟨ +-congˡ (+-congˡ (≈-sym (-‿+-comm b₁ b₂))) ⟩ a₁ + (a₂ + (- b₁ - b₂)) ≈⟨ +-congˡ (≈-sym (+-assoc a₂ (- b₁) (- b₂))) ⟩ a₁ + (a₂ - b₁ - b₂) ≈⟨ +-congˡ (+-congʳ (+-comm a₂ (- b₁))) ⟩ a₁ + (- b₁ + a₂ - b₂) ≈⟨ +-congˡ (+-assoc (- b₁) a₂ (- b₂)) ⟩ a₁ + (- b₁ + (a₂ - b₂)) ≈⟨ ≈-sym (+-assoc a₁ (- b₁) (a₂ - b₂)) ⟩ (a₁ - b₁) + (a₂ - b₂) ≈⟨ +-cong a₁-b₁≈k₁*n a₂-b₂≈k₂*n ⟩ (k₁ * n) + (k₂ * n) ≈⟨ ≈-sym (distribʳ n k₁ k₂) ⟩ (k₁ + k₂) * n ∎ *-compat : ∀ {a₁ a₂ b₁ b₂} {n} → a₁ ≈ b₁ [mod n ] → a₂ ≈ b₂ [mod n ] → a₁ * a₂ ≈ b₁ * b₂ [mod n ] *-compat {a₁} {a₂} {b₁} {b₂} {n} (modulo k₁ a₁-b₁≈k₁*n) (modulo k₂ a₂-b₂≈k₂*n) = modulo (a₂ * k₁ + b₁ * k₂) $ begin a₁ * a₂ - b₁ * b₂ ≈⟨ +-congˡ (-‿cong (*-comm b₁ b₂)) ⟩ a₁ * a₂ - b₂ * b₁ ≈⟨ +-congʳ (≈-sym (+-identityʳ (a₁ * a₂))) ⟩ a₁ * a₂ + 0# - b₂ * b₁ ≈⟨ +-congʳ (+-congˡ lemma) ⟩ a₁ * a₂ + (- (b₁ * a₂) + a₂ * b₁) - b₂ * b₁ ≈⟨ +-congʳ (≈-sym (+-assoc (a₁ * a₂) (- (b₁ * a₂)) (a₂ * b₁))) ⟩ a₁ * a₂ - b₁ * a₂ + a₂ * b₁ - b₂ * b₁ ≈⟨ +-assoc (a₁ * a₂ - b₁ * a₂) (a₂ * b₁) (- (b₂ * b₁)) ⟩ (a₁ * a₂ - b₁ * a₂) + (a₂ * b₁ - b₂ * b₁) ≈⟨ +-cong (+-congˡ (-‿distribˡ-* b₁ a₂)) (+-congˡ (-‿distribˡ-* b₂ b₁)) ⟩ (a₁ * a₂ + (- b₁) * a₂) + (a₂ * b₁ + (- b₂) * b₁) ≈⟨ +-cong (≈-sym (distribʳ a₂ a₁ (- b₁))) (≈-sym (distribʳ b₁ a₂ (- b₂))) ⟩ (a₁ - b₁) * a₂ + (a₂ - b₂) * b₁ ≈⟨ +-cong (*-comm (a₁ - b₁) a₂) (*-comm (a₂ - b₂) b₁) ⟩ a₂ * (a₁ - b₁) + b₁ * (a₂ - b₂) ≈⟨ +-cong (*-congˡ a₁-b₁≈k₁*n) (*-congˡ a₂-b₂≈k₂*n) ⟩ a₂ * (k₁ * n) + b₁ * (k₂ * n) ≈⟨ +-cong (≈-sym (*-assoc a₂ k₁ n)) (≈-sym (*-assoc b₁ k₂ n)) ⟩ a₂ * k₁ * n + b₁ * k₂ * n ≈⟨ ≈-sym (distribʳ n (a₂ * k₁) (b₁ * k₂)) ⟩ (a₂ * k₁ + b₁ * k₂) * n ∎ where lemma : 0# ≈ - (b₁ * a₂) + a₂ * b₁ lemma = begin 0# ≈⟨ ≈-sym (-‿inverseˡ (b₁ * a₂)) ⟩ - (b₁ * a₂) + b₁ * a₂ ≈⟨ +-congˡ (*-comm b₁ a₂) ⟩ - (b₁ * a₂) + a₂ * b₁ ∎ n*x≈0 : ∀ {x} {n} → n * x ≈ 0# [mod n ] n*x≈0 {x} {n} = modulo x $ begin n * x - 0# ≈⟨ +-congˡ -0#≈0# ⟩ n * x + 0# ≈⟨ +-identityʳ (n * x) ⟩ n * x ≈⟨ *-comm n x ⟩ x * n ∎
50.786517
127
0.434513
527339568a03fa0663812b7fb47dfd35f000bbea
3,310
agda
Agda
test/Succeed/Issue1544.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1544.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1544.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-07-16 issue reported by G.Allais -- This ought to pass, ideally, but the lack of positivity polymorphism -- does not allow for a precise analysis of the composition operator. -- -- Subsequently, the positivity analysis for tabulate returns no -- positivity info for all arguments, leading to a rejection of -- Command₃. -- {-# OPTIONS -v tc.pos:10 #-} open import Common.Product open import Common.List record ⊤ {a} : Set a where _∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} → (∀ {x} (y : B x) → C y) → (g : (x : A) → B x) → ((x : A) → C (g x)) f ∘ g = λ x → f (g x) postulate String : Set USL = List String data _∈_ a : USL → Set where z : ∀ {xs} → a ∈ (a ∷ xs) s : ∀ {b xs} → a ∈ xs → a ∈ (b ∷ xs) [Fields] : (args : USL) → Set₁ [Fields] [] = ⊤ [Fields] (_ ∷ args) = Set × [Fields] args [tabulate] : (args : USL) (ρ : {arg : _} (pr : arg ∈ args) → Set) → [Fields] args [tabulate] [] ρ = _ [tabulate] (arg ∷ args) ρ = ρ z , [tabulate] args (λ x → ρ (s x)) [Record] : (args : USL) (f : [Fields] args) → Set [Record] [] _ = ⊤ [Record] (hd ∷ args) (f , fs) = f × [Record] args fs record Fields (args : USL) : Set₁ where constructor mkFields field fields : [Fields] args open Fields public record Record (args : USL) (f : Fields args) : Set where constructor mkRecord field content : [Record] args (fields f) open Record public module WORKS where tabulate : {args : USL} (ρ : {arg : _} (pr : arg ∈ args) → Set) → Fields args tabulate {args = args} ρ = mkFields ([tabulate] args ρ) -- WORKS -- tabulate {args = args} = mkFields ∘ [tabulate] args -- FAILS mutual data Command₁ : Set where mkCommand : (modifierNames : USL) → Record modifierNames (tabulate (λ {s} _ → Modifier s)) → Command₁ record Command₂ : Set where inductive field modifierNames : USL modifiers : [Record] modifierNames ([tabulate] _ (λ {s} _ → Modifier s)) record Command₃ : Set where inductive field modifierNames : USL modifiers : Record modifierNames (tabulate (λ {s} _ → Modifier s)) data Modifier (name : String) : Set where command₁ : Command₁ → Modifier name command₂ : Command₂ → Modifier name command₃ : Command₃ → Modifier name module FAILS where tabulate : {args : USL} (ρ : {arg : _} (pr : arg ∈ args) → Set) → Fields args -- tabulate {args = args} ρ = mkFields ([tabulate] args ρ) -- WORKS tabulate {args = args} = mkFields ∘ [tabulate] args -- FAILS mutual data Command₁ : Set where mkCommand : (modifierNames : USL) → Record modifierNames (tabulate (λ {s} _ → Modifier s)) → Command₁ record Command₂ : Set where inductive field modifierNames : USL modifiers : [Record] modifierNames ([tabulate] _ (λ {s} _ → Modifier s)) record Command₃ : Set where inductive field modifierNames : USL modifiers : Record modifierNames (tabulate (λ {s} _ → Modifier s)) data Modifier (name : String) : Set where command₁ : Command₁ → Modifier name command₂ : Command₂ → Modifier name command₃ : Command₃ → Modifier name
28.782609
84
0.586103
1b931f8ffe5ab413a9fc40bf5daa62f3bb437db9
7,543
agda
Agda
TotalParserCombinators/Congruence.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
1
2020-07-03T08:56:13.000Z
2020-07-03T08:56:13.000Z
TotalParserCombinators/Congruence.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
TotalParserCombinators/Congruence.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- A language of parser equivalence proofs ------------------------------------------------------------------------ -- This module defines yet another set of equivalence relations and -- preorders for parsers. For symmetric kinds these relations are -- equalities (compatible equivalence relations) by construction, and -- they are sound and complete with respect to the previously defined -- equivalences (see TotalParserCombinators.Congruence.Sound for the -- soundness proof). This means that parser and language equivalence -- are also equalities. The related orderings are compatible -- preorders. module TotalParserCombinators.Congruence where open import Codata.Musical.Notation open import Data.List open import Data.List.Relation.Binary.BagAndSetEquality using (bag) renaming (_∼[_]_ to _List-∼[_]_) open import Data.Maybe hiding (_>>=_) open import Data.Nat hiding (_^_) open import Data.Product open import Data.Vec.Recursive open import Function open import Function.Related using (Symmetric-kind; ⌊_⌋) open import Relation.Binary.PropositionalEquality using (_≡_; _≗_) open import TotalParserCombinators.Derivative using (D) open import TotalParserCombinators.CoinductiveEquality as CE using (_∼[_]c_; _∷_) open import TotalParserCombinators.Parser open import TotalParserCombinators.Semantics hiding ([_-_]_⊛_; [_-_]_>>=_) infixl 50 [_-_]_⊛_ [_-_-_-_]_⊛_ _<$>_ infix 10 [_-_]_>>=_ [_-_-_-_]_>>=_ infixl 5 _∣_ infix 5 _∷_ infix 4 _∼[_]P_ ∞⟨_⟩_∼[_]P_ _≅P_ _≈P_ infix 3 _∎ infixr 2 _∼⟨_⟩_ _≅⟨_⟩_ ------------------------------------------------------------------------ -- Helper functions flatten₁ : {A : Set} → Maybe (Maybe A ^ 2) → Maybe A flatten₁ nothing = nothing flatten₁ (just (m , _)) = m flatten₂ : {A : Set} → Maybe (Maybe A ^ 2) → Maybe A flatten₂ nothing = nothing flatten₂ (just (_ , m)) = m ------------------------------------------------------------------------ -- Equivalence proof programs mutual _≅P_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁ p₁ ≅P p₂ = p₁ ∼[ parser ]P p₂ _≈P_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁ p₁ ≈P p₂ = p₁ ∼[ language ]P p₂ data _∼[_]P_ {Tok} : ∀ {R xs₁ xs₂} → Parser Tok R xs₁ → Kind → Parser Tok R xs₂ → Set₁ where -- This constructor, which corresponds to CE._∷_, ensures that the -- relation is complete. _∷_ : ∀ {k R xs₁ xs₂} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} (xs₁≈xs₂ : xs₁ List-∼[ k ] xs₂) (Dp₁≈Dp₂ : ∀ t → ∞ (D t p₁ ∼[ k ]P D t p₂)) → p₁ ∼[ k ]P p₂ -- Equational reasoning. _∎ : ∀ {k R xs} (p : Parser Tok R xs) → p ∼[ k ]P p _∼⟨_⟩_ : ∀ {k R xs₁ xs₂ xs₃} (p₁ : Parser Tok R xs₁) {p₂ : Parser Tok R xs₂} {p₃ : Parser Tok R xs₃} (p₁≈p₂ : p₁ ∼[ k ]P p₂) (p₂≈p₃ : p₂ ∼[ k ]P p₃) → p₁ ∼[ k ]P p₃ _≅⟨_⟩_ : ∀ {k R xs₁ xs₂ xs₃} (p₁ : Parser Tok R xs₁) {p₂ : Parser Tok R xs₂} {p₃ : Parser Tok R xs₃} (p₁≅p₂ : p₁ ≅P p₂) (p₂≈p₃ : p₂ ∼[ k ]P p₃) → p₁ ∼[ k ]P p₃ sym : ∀ {k : Symmetric-kind} {R xs₁ xs₂} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} (p₁≈p₂ : p₁ ∼[ ⌊ k ⌋ ]P p₂) → p₂ ∼[ ⌊ k ⌋ ]P p₁ -- Congruences. return : ∀ {k R} {x₁ x₂ : R} (x₁≡x₂ : x₁ ≡ x₂) → return x₁ ∼[ k ]P return x₂ fail : ∀ {k R} → fail {R = R} ∼[ k ]P fail {R = R} token : ∀ {k} → token ∼[ k ]P token _∣_ : ∀ {k R xs₁ xs₂ xs₃ xs₄} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} {p₃ : Parser Tok R xs₃} {p₄ : Parser Tok R xs₄} (p₁≈p₃ : p₁ ∼[ k ]P p₃) (p₂≈p₄ : p₂ ∼[ k ]P p₄) → p₁ ∣ p₂ ∼[ k ]P p₃ ∣ p₄ _<$>_ : ∀ {k R₁ R₂} {f₁ f₂ : R₁ → R₂} {xs₁ xs₂} {p₁ : Parser Tok R₁ xs₁} {p₂ : Parser Tok R₁ xs₂} (f₁≗f₂ : f₁ ≗ f₂) (p₁≈p₂ : p₁ ∼[ k ]P p₂) → f₁ <$> p₁ ∼[ k ]P f₂ <$> p₂ [_-_]_⊛_ : ∀ {k R₁ R₂} xs₁xs₂ fs₁fs₂ → let xs₁ = flatten₁ xs₁xs₂; xs₂ = flatten₂ xs₁xs₂ fs₁ = flatten₁ fs₁fs₂; fs₂ = flatten₂ fs₁fs₂ in {p₁ : ∞⟨ xs₁ ⟩Parser Tok (R₁ → R₂) (flatten fs₁)} {p₂ : ∞⟨ fs₁ ⟩Parser Tok R₁ (flatten xs₁)} {p₃ : ∞⟨ xs₂ ⟩Parser Tok (R₁ → R₂) (flatten fs₂)} {p₄ : ∞⟨ fs₂ ⟩Parser Tok R₁ (flatten xs₂)} (p₁≈p₃ : ∞⟨ xs₁xs₂ ⟩ p₁ ∼[ k ]P p₃) (p₂≈p₄ : ∞⟨ fs₁fs₂ ⟩ p₂ ∼[ k ]P p₄) → p₁ ⊛ p₂ ∼[ k ]P p₃ ⊛ p₄ [_-_]_>>=_ : ∀ {k R₁ R₂} (f₁f₂ : Maybe (Maybe (R₁ → List R₂) ^ 2)) xs₁xs₂ → let f₁ = flatten₁ f₁f₂; f₂ = flatten₂ f₁f₂ xs₁ = flatten₁ xs₁xs₂; xs₂ = flatten₂ xs₁xs₂ in {p₁ : ∞⟨ f₁ ⟩Parser Tok R₁ (flatten xs₁)} {p₂ : (x : R₁) → ∞⟨ xs₁ ⟩Parser Tok R₂ (apply f₁ x)} {p₃ : ∞⟨ f₂ ⟩Parser Tok R₁ (flatten xs₂)} {p₄ : (x : R₁) → ∞⟨ xs₂ ⟩Parser Tok R₂ (apply f₂ x)} (p₁≈p₃ : ∞⟨ f₁f₂ ⟩ p₁ ∼[ k ]P p₃) (p₂≈p₄ : ∀ x → ∞⟨ xs₁xs₂ ⟩ p₂ x ∼[ k ]P p₄ x) → p₁ >>= p₂ ∼[ k ]P p₃ >>= p₄ nonempty : ∀ {k R xs₁ xs₂} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} (p₁≈p₂ : p₁ ∼[ k ]P p₂) → nonempty p₁ ∼[ k ]P nonempty p₂ cast : ∀ {k R xs₁ xs₂ xs₁′ xs₂′} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} {xs₁≈xs₁′ : xs₁ List-∼[ bag ] xs₁′} {xs₂≈xs₂′ : xs₂ List-∼[ bag ] xs₂′} (p₁≈p₂ : p₁ ∼[ k ]P p₂) → cast xs₁≈xs₁′ p₁ ∼[ k ]P cast xs₂≈xs₂′ p₂ -- Certain proofs can be coinductive if both sides are delayed. ∞⟨_⟩_∼[_]P_ : ∀ {Tok R xs₁ xs₂} {A : Set} (m₁m₂ : Maybe (Maybe A ^ 2)) → ∞⟨ flatten₁ m₁m₂ ⟩Parser Tok R xs₁ → Kind → ∞⟨ flatten₂ m₁m₂ ⟩Parser Tok R xs₂ → Set₁ ∞⟨ nothing ⟩ p₁ ∼[ k ]P p₂ = ∞ (♭ p₁ ∼[ k ]P ♭ p₂) ∞⟨ just _ ⟩ p₁ ∼[ k ]P p₂ = ♭? p₁ ∼[ k ]P ♭? p₂ ------------------------------------------------------------------------ -- Some derived combinators [_-_-_-_]_⊛_ : ∀ {k Tok R₁ R₂} xs₁ xs₂ fs₁ fs₂ {p₁ : ∞⟨ xs₁ ⟩Parser Tok (R₁ → R₂) (flatten fs₁)} {p₂ : ∞⟨ fs₁ ⟩Parser Tok R₁ (flatten xs₁)} {p₃ : ∞⟨ xs₂ ⟩Parser Tok (R₁ → R₂) (flatten fs₂)} {p₄ : ∞⟨ fs₂ ⟩Parser Tok R₁ (flatten xs₂)} → ♭? p₁ ∼[ k ]P ♭? p₃ → ♭? p₂ ∼[ k ]P ♭? p₄ → p₁ ⊛ p₂ ∼[ k ]P p₃ ⊛ p₄ [ xs₁ - xs₂ - fs₁ - fs₂ ] p₁≈p₃ ⊛ p₂≈p₄ = [ just (xs₁ , xs₂) - just (fs₁ , fs₂) ] p₁≈p₃ ⊛ p₂≈p₄ [_-_-_-_]_>>=_ : ∀ {k Tok R₁ R₂} (f₁ f₂ : Maybe (R₁ → List R₂)) xs₁ xs₂ {p₁ : ∞⟨ f₁ ⟩Parser Tok R₁ (flatten xs₁)} {p₂ : (x : R₁) → ∞⟨ xs₁ ⟩Parser Tok R₂ (apply f₁ x)} {p₃ : ∞⟨ f₂ ⟩Parser Tok R₁ (flatten xs₂)} {p₄ : (x : R₁) → ∞⟨ xs₂ ⟩Parser Tok R₂ (apply f₂ x)} → ♭? p₁ ∼[ k ]P ♭? p₃ → (∀ x → ♭? (p₂ x) ∼[ k ]P ♭? (p₄ x)) → p₁ >>= p₂ ∼[ k ]P p₃ >>= p₄ [ f₁ - f₂ - xs₁ - xs₂ ] p₁≈p₃ >>= p₂≈p₄ = [ just (f₁ , f₂) - just (xs₁ , xs₂) ] p₁≈p₃ >>= p₂≈p₄ ------------------------------------------------------------------------ -- Completeness complete : ∀ {k Tok R xs₁ xs₂} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} → p₁ ∼[ k ] p₂ → p₁ ∼[ k ]P p₂ complete = complete′ ∘ CE.complete where complete′ : ∀ {k Tok R xs₁ xs₂} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} → p₁ ∼[ k ]c p₂ → p₁ ∼[ k ]P p₂ complete′ (xs₁≈xs₂ ∷ Dp₁≈Dp₂) = xs₁≈xs₂ ∷ λ t → ♯ complete′ (♭ (Dp₁≈Dp₂ t))
36.264423
72
0.489195
fd34188eadde1857a4df4c2aba2f8916a14cacdf
520
agda
Agda
Groups/Polynomials/Examples.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Groups/Polynomials/Examples.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Groups/Polynomials/Examples.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Integers.Integers open import Numbers.Integers.Definition open import Lists.Lists open import Maybe module Groups.Polynomials.Examples where open import Groups.Polynomials.Definition ℤGroup private decide : _ decide = (λ a → ℤDecideEquality a (nonneg 0)) p1 : degree decide [] ≡ no p1 = refl p2 : degree decide (nonneg 0 :: []) ≡ no p2 = refl p3 : degree decide (nonneg 1 :: []) ≡ yes 0 p3 = refl
20
50
0.701923
3606fd92fe49378abd16c062c2d35651572e58bc
22,446
agda
Agda
Ex3.agda
clarkdm/CS410
523a8749f49c914bcd28402116dcbe79a78dbbf4
[ "CC0-1.0" ]
null
null
null
Ex3.agda
clarkdm/CS410
523a8749f49c914bcd28402116dcbe79a78dbbf4
[ "CC0-1.0" ]
null
null
null
Ex3.agda
clarkdm/CS410
523a8749f49c914bcd28402116dcbe79a78dbbf4
[ "CC0-1.0" ]
null
null
null
module Ex3 where -- Conor: 5.5/15 (marked in sem 1 for 3.1-3.4) -- really 5.5/7 then another 3/8 in sem 2, giving 8.5/15 ---------------------------------------------------------------------------- -- EXERCISE 3 -- MONADS FOR HUTTON'S RAZOR -- -- VALUE: 15% -- DEADLINE: 5pm, Friday 20 November (week 9) -- -- DON'T SUBMIT, COMMIT! -- -- The purpose of this exercise is to introduce you to some useful -- mathematical structures and build good tools for working with -- vectors ---------------------------------------------------------------------------- open import CS410-Prelude open import CS410-Monoid open import CS410-Nat open import CS410-Vec open import CS410-Functor -- HINT: your tasks are heralded with the eminently searchable tag, "???" ---------------------------------------------------------------------------- -- HUTTON'S RAZOR ---------------------------------------------------------------------------- HVal : Set -- the set of *values* for Hutton's Razor HVal = Two + Nat -- Booleans or natural numbers data HExp (X : Set) : Set where var : X -> HExp X -- variables val : HVal -> HExp X -- values _+H_ _>=H_ : (e1 e2 : HExp X) -> HExp X -- addition, comparison ifH_then_else_ : (e1 e2 e3 : HExp X) -> HExp X -- conditional _>=2_ : Nat -> Nat -> Two x >=2 zero = tt zero >=2 suc _ = ff suc m >=2 suc n = m >=2 n ---------------------------------------------------------------------------- -- ??? 3.1 the HExp syntax-with-substitution monad (score: 2 / 2) ---------------------------------------------------------------------------- -- Show that HExp is a monad, where the "bind" operation performs -- simultaneous substitution (transforming all the variables in a term). hExpMonad : Monad HExp hExpMonad = record { return = λ x → var x ; _>>=_ = λ x f → hExpMonad>>= x f ; law1 = λ x f → refl ; law2 = λ t → hExpMonadLaw2 t ; law3 = λ f g t → hExpMonadLaw3 t g f } where hExpMonad>>= : {X Y : Set} → HExp X → (X → HExp Y) → HExp Y hExpMonad>>= (var x) f = f x hExpMonad>>= (val x) f = val x hExpMonad>>= (x +H y) f = hExpMonad>>= x f +H hExpMonad>>= y f hExpMonad>>= (x >=H y) f = hExpMonad>>= x f >=H hExpMonad>>= y f hExpMonad>>= (ifH x then y else z) f = ifH hExpMonad>>= x f then hExpMonad>>= y f else hExpMonad>>= z f hExpMonadLaw2 : {X : Set} → (t : HExp X) → hExpMonad>>= t (λ x → var x) == t hExpMonadLaw2 (var x) = refl hExpMonadLaw2 (val x) = refl hExpMonadLaw2 (x +H y) rewrite hExpMonadLaw2 x | hExpMonadLaw2 y = refl hExpMonadLaw2 (x >=H y) rewrite hExpMonadLaw2 x | hExpMonadLaw2 y = refl hExpMonadLaw2 (ifH x then y else z) rewrite hExpMonadLaw2 x | hExpMonadLaw2 y | hExpMonadLaw2 z = refl hExpMonadLaw3 : {X Y Z : Set} → (t : HExp X) → (g : Y → HExp Z) → (f : X → HExp Y) → hExpMonad>>= (hExpMonad>>= t f) g == hExpMonad>>= t (λ x → hExpMonad>>= (f x) g) hExpMonadLaw3 (var x) g t = refl hExpMonadLaw3 (val x) g t = refl hExpMonadLaw3 (f +H f₁) g t rewrite hExpMonadLaw3 f g t | hExpMonadLaw3 f₁ g t = refl hExpMonadLaw3 (f >=H f₁) g t rewrite hExpMonadLaw3 f g t | hExpMonadLaw3 f₁ g t = refl hExpMonadLaw3 (ifH f then f₁ else f₂) g t rewrite hExpMonadLaw3 f g t | hExpMonadLaw3 f₁ g t | hExpMonadLaw3 f₂ g t = refl ---------------------------------------------------------------------------- -- ??? 3.2 the error management monad (score: 1 / 1) ---------------------------------------------------------------------------- -- show that "+ E" is monadic, generalising the "Maybe" monad by allowing -- some sort of error report errorMonad : (E : Set) -> Monad \ V -> V + E -- "value or error" errorMonad E = record { return = λ x → tt , x ; _>>=_ = errorMonad>>= ; law1 = λ x f → refl ; law2 = errorMonadLaw2 ; law3 = errorMonadLaw3 } where errorMonad>>= : {X Y : Set} → X + E → (X → Y + E) → Y + E errorMonad>>= (tt , snd) y = y snd errorMonad>>= (ff , snd) y = ff , snd errorMonadLaw2 : {X : Set} (t : X + E) → errorMonad>>= t (λ x → tt , x) == t errorMonadLaw2 (tt , snd) = refl errorMonadLaw2 (ff , snd) = refl errorMonadLaw3 : {X Y Z : Set} (f : X → Y + E) (g : Y → Z + E) (t : X + E) → errorMonad>>= (errorMonad>>= t f) g == errorMonad>>= t (λ x → errorMonad>>= (f x) g) errorMonadLaw3 f g (tt , snd) = refl errorMonadLaw3 f g (ff , snd) = refl ---------------------------------------------------------------------------- -- ??? 3.3 the environment monad transformer (score: 1 / 1) ---------------------------------------------------------------------------- -- show that any monad can be adapted to thread some environment information -- as well as whatever else it already managed envMonad : (G : Set){M : Set -> Set} -> Monad M -> Monad \ V -> G -> M V -- "computation in an environment" envMonad G {M} MM = record { return = λ {X} z _ → Monad.return MM z ; _>>=_ = λ {X} {Y} z z₁ z₂ → (MM Monad.>>= z z₂) (λ z₃ → z₁ z₃ z₂) ; law1 = λ {X Y} x f → envMonadLaw1 f x ; law2 = envMonadLaw2 ; law3 = envMonadLaw3 } where open Monad MM envMonadLaw1 : {X Y : Set} (f : X → G → M Y) -> (x : X) -> (λ z₂ → return x >>= (λ z₃ → f z₃ z₂)) == f x envMonadLaw1 f x = ext (λ g → Monad.law1 MM x (λ z → f z g)) envMonadLaw2 : {X : Set} (t : G → M X) → (λ z₂ → t z₂ >>= (λ z₃ → return z₃)) == t envMonadLaw2 x = ext (λ a → Monad.law2 MM (x a)) envMonadLaw3 : {X Y Z : Set} (f : X → G → M Y) (g : Y → G → M Z) (t : G → M X) →(λ z₂ → (t z₂ >>= (λ z₃ → f z₃ z₂)) >>= (λ z₃ → g z₃ z₂)) == (λ z₂ → t z₂ >>= (λ z₃ → f z₃ z₂ >>= (λ z₄ → g z₄ z₂))) envMonadLaw3 f g t = ext (λ a → Monad.law3 MM (λ z → f z a) (λ z → g z a) (t a)) ---------------------------------------------------------------------------- -- ??? 3.4 interpreting Hutton's Razor (score: 1.5 / 3) ---------------------------------------------------------------------------- -- Implement an interpreter for Hutton's Razor. -- You will need to construct a type to represent possible run-time errors. -- Ensure that addition and comparison act on numbers, not Booleans. -- Ensure that the condition in an "if" is a Boolean, not a number. data InterpretError : Set where NotTwo : InterpretError NotNat : InterpretError -- helpful things to build Env : Set -> Set -- an environment for a given set of variables Env X = X -> HVal Compute : Set{- variables -} -> Set{- values -} -> Set Compute X V = Env X -> V + InterpretError -- how to compute a V computeMonad : {Z : Set} -> Monad (Compute Z) computeMonad {Z} = envMonad (Env Z) (errorMonad InterpretError) -- build this from the above parts -- This operation should explain how to get the value of a variable -- from the environment. varVal : {X : Set} -> X -> Compute X HVal varVal x y = tt , (y x) -- tt , (y x) -- These operations should ensure that you get the sort of value -- that you want, in order to ensure that you don't do bogus -- computation. mustBeNat : {X : Set} -> HVal -> Compute X Nat mustBeNat (tt , tt) x = ff , NotNat -- Conor: more case analysis than needed mustBeNat (tt , ff) x = ff , NotNat mustBeNat (ff , zero) x = tt , zero -- Conor: more case analysis than needed mustBeNat (ff , suc snd) x = tt , suc snd mustBeTwo : {X : Set} -> HVal -> Compute X Two mustBeTwo (tt , tt) x = tt , tt -- Conor: more case analysis than needed mustBeTwo (tt , ff) x = tt , ff mustBeTwo (ff , zero) x = ff , NotTwo -- Conor: more case analysis than needed mustBeTwo (ff , suc snd) x = ff , NotTwo -- Now, you're ready to go. Don't introduce the environment explicitly. -- Use the monad to thread it. interpret : {X : Set} -> HExp X -> Compute X HVal interpret {X} = go where open Monad (computeMonad {X}) go : HExp X -> Compute X HVal -- Conor: you already have the right kit, so it's counterproductive to go down to this detail go (var x) E = tt , (E x) -- Conor: go (var x) = varVal x go (val x) E = tt , x go (t +H t₁) E = {!!} -- Conor: go (l +H r) = -- go l >>= \ lv -> -- lv : HVal -- mustBeNat lv >>= \ ln -> -- ln : Nat -- go r >>= \ rv -> -- rv : HVal -- mustBeNat rv >>= \ rn -> -- rn : Nat -- return (ln +N rn) go (t >=H t₁) E = {!!} go (ifH t then t₁ else t₂) E = {!!} ---------------------------------------------------------------------------- -- ??? 3.5 Typed Hutton's Razor (score: 0.5 / 1) ---------------------------------------------------------------------------- -- Labelling the expressions with their types gives strong guarantees -- sooner (we can make it grammatically incorrect to add a bool to a -- nat) and makes some things easier as (if we're adding them then we -- know they are nats). -- some names for the types we will use in our typed syntax. data HType : Set where hTwo hNat : HType -- mapping names for types to real types. THVal : HType -> Set THVal hTwo = Two THVal hNat = Nat -- A syntax for types expressions, indexed by typed variables. Compare -- with the untyped HExp and fill in the missing expression formers, -- we have shown you the way with _+H_. think: what can be guaranteed? data THExp (X : HType -> Set) : HType -> Set where var : forall {T} -> X T -> THExp X T val : forall {T} -> THVal T -> THExp X T _+H_ : THExp X hNat -> THExp X hNat -> THExp X hNat _>=H_ : THExp X hNat -> THExp X hTwo {- Conor: hNat here! -} -> THExp X hTwo ifH_then_else_ : forall {T} -> THExp X hTwo -> THExp X T -> THExp X T -> THExp X T -- ??? fill in the other two constructs, typed appropriately -- (remember that "if then else" can compute values at any type) ---------------------------------------------------------------------------- -- ??? 3.6 Well Typed Programs Don't Go Wrong (score: 0 / 1) ---------------------------------------------------------------------------- -- notation for functions betweeen indexed sets (e.g. indexed by types) _-:>_ : {I : Set}(S T : I -> Set) -> I -> Set (S -:> T) i = S i -> T i infixr 3 _-:>_ -- notation for indexed sets [_] : {I : Set}(X : I -> Set) -> Set [ X ] = forall {i} -> X i -- We can put the two together to make types like -- [ S -:> T ] -- = forall {i} -> S i -> T i -- which is the type of functions which work at any index -- and respect that index. That'll be very useful in just a moment. -- An evaluator for typed terms, it takes an environment for -- variables (a function mapping variables to values) and a expression -- and returns a value). Written as below it looks like it lifts a -- function from variables to values to a function from terms to -- values. eval : {X : HType -> Set} -> [ X -:> THVal ] -> [ THExp X -:> THVal ] eval g (var x) = g x eval g (val x) = x eval g (t +H t1) = eval g t +N eval g t eval g (t >=H t1) = eval g t >=2 eval g t eval g (ifH t then t1 else t2) = if eval g t then eval g t1 else eval g t1 -- Conor: all three step cases get the wrong answers -- Note that the environment is an *index-respecting* function from -- variables to values. The index is the type of the variable: you're -- making sure that when you look up a variable of a given type, you -- get a value of that type. As a result, you can deliver a *type-safe* -- evaluator: when an expression has a given type, its value must have -- that type. ---------------------------------------------------------------------------- -- ??? 3.7 Variable Contexts (score: 1 / 1) ---------------------------------------------------------------------------- -- backwards lists. data Bwd (X : Set) : Set where [] : Bwd X _/_ : Bwd X -> X -> Bwd X -- Our datatype for type indexed expressions is very liberal about -- variables, they can be any set indexed by types. Here we build -- something more structured, that nevertheless satisfies the specification -- We will not use names for variables only numbers. -- Hence, a context is just a list of types. Context : Set Context = Bwd HType -- Well scoped and well typed variables, top = 0, pop = suc. -- top is the variable on the right hand end of a non-empty context. -- pop takes a variable and extends puts it into a longer context. data Var : (G : Context)(T : HType) -> Set where top : {G : Context}{T : HType} -> Var (G / T) T pop : {G : Context}{T S : HType} -> Var G T -> Var (G / S) T -- We can also represent environments as stacks, as opposed to functions. -- You can read a variable as the sequence of instructions for extracting -- a value from a stack: you keep popping stuff off until the value you -- want is the the one at the top. Stack : Context -> Set Stack [] = One Stack (G / S) = Stack G * THVal S -- Looking up a value for a variable in an an environment or fetching -- something from a stack given a sequence of pop and top -- instructions. It's all the same to us! fetch : {G : Context} -> Stack G -> [ Var G -:> THVal ] fetch g top = snd g fetch g (pop v) = fetch (fst g) v -- An evaluator for expression with more structured variables. We -- already know how to evaluate, we just have to explain how to deal -- with manage the different style of environment. evalStack : {G : Context}{T : HType} -> Stack G -> [ THExp (Var G) -:> THVal ] evalStack g = eval (fetch g) ---------------------------------------------------------------------------- -- ??? 3.8 Terms-With-One-Hole (score: 1 / 1) ---------------------------------------------------------------------------- -- Next, we build some kit that we'll use to present type errors. -- Here we represent an expression with a bit missing. Addition can have -- have a bit missing (a hole) on the right or on the left. What about -- the other expression formers? data HExp' (X : Set) : Set where []+H_ _+H[] : HExp X -> HExp' X []>=H_ _>=H[] : HExp X -> HExp' X ifH[]then_else_ ifH_then[]else_ ifH_then_else[] : HExp X -> HExp X -> HExp' X -- ??? more constructors here -- specifically, you will need a constructor for each way that a -- subexpression can fit inside an expression; -- we use the naming convention of showing where the "hole" is -- by putting [] in the corresponding place in the name. -- take a expression with a hole, and a expression to plug in and plug -- it in! _[]<-_ : forall {X} -> HExp' X -> HExp X -> HExp X ([]+H r) []<- t = t +H r (l +H[]) []<- t = l +H t ([]>=H r) []<- t = t >=H r (l >=H[]) []<- t = l >=H t (ifH[]then l else r) []<- t = ifH t then l else r (ifH e then[]else r) []<- t = ifH e then t else r (ifH e then l else[]) []<- t = ifH e then l else t -- ??? more cases here {- data List (X : Set) : Set where -- X scopes over the whole declaration... [] : List X -- ...so you can use it here... _::_ : X -> List X -> List X -- ...and here. infixr 3 _::_ -} -- As we descend down into a term we can keep the pieces we pass along -- the way in a list, this is a zipper. For example, given the -- expression 3 + (4 + 5) we could go down by going right and right -- again to reach 5. In our list we would have [ 4 + [] , 3 + [] ]. -- we need an operation that takes us back up to the root of the tree, -- restoring the expression to its former state (e.g. 3 + (4 + 5)). rootToHole : forall {X} -> List (HExp' X) -> HExp X -> HExp X rootToHole [] t = t rootToHole (t' :: t's) t = t' []<- rootToHole t's t -- The idea is that the pair of a List (HExp' X) and a single -- HExp X together represent a term with a designated subterm "in focus". -- The list of one-hole terms represents the *path* to the designated -- subterm, together with the *other stuff* hanging off to either side -- of that path. ---------------------------------------------------------------------------- -- ??? 3.9 Forgetting Types (score: 0.5 / 1) ---------------------------------------------------------------------------- -- SUSPICION: why would we want to? -- Given a typed term (THEXP X T) we can forget the types to obtain an -- untyped term (HExp Y) if we know how to forget types from variables -- (varFog). termFog : {X : HType -> Set}{Y : Set}(varFog : {T : HType} -> X T -> Y) -> {T : HType} -> THExp X T -> HExp Y termFog vF (var x) = var (vF x) termFog vF (val x) = {!x!} -- Conor: need to find the type termFog vF (t +H t1) = (termFog vF t) +H (termFog vF t1) termFog vF (t >=H t1) = (termFog vF t) >=H (termFog vF t1) termFog vF (ifH t then t1 else t2) = ifH (termFog vF t) then (termFog vF t1) else (termFog vF t2) -- Note that it's a local naming convention to call functions which -- forget information "fog". When it is foggy, you can see less. -- Our purpose in writing a function to throw away information is to -- *specify* what it means to *obtain* information. ---------------------------------------------------------------------------- -- ??? 3.10 A Typechecking View (score: 0 / 3) ---------------------------------------------------------------------------- -- We finish by building a typechecker which will allow us to detect -- when an untyped Hutton's Razor term can be converted into a typed -- term (and evaluated safely without rechecking). We make use of -- your solution to part 3.9 to express the idea that -- an untyped term is the forgetful image of a typed term we know -- and your solution to part 3.8 to express the idea that -- an untyped term can be focused at a place where there is a type error -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- But first, we need to build you a wee bit more kit. Typechecking relies -- on checking that the type you want is the type you've got, which sometimes -- means testing *equality* of types. It's not enough to have a function -- htypeEq : HType -> HType -> Two -- because we need to convince *Agda* of the equality, not just write a function -- that happens to say yes to equal things. -- a set with one element removed, i.e. X -[ x ] is the pair of some y in X and -- a proof that y isn't x _-[_] : (X : Set) -> X -> Set X -[ x ] = Sg X \ y -> x == y -> Zero -- a view for comparing types for equality data HTypeComparable (T : HType) : HType -> Set where same : HTypeComparable T T diff : (SnT : HType -[ T ]) -> HTypeComparable T (fst SnT) -- the above view type presents is two options, and in both of them, we -- have to come through with enough evidence to convince Agda -- implementing the view hTypeCompare : (S T : HType) -> HTypeComparable S T hTypeCompare hTwo hTwo = same hTypeCompare hTwo hNat = diff (hNat , \ ()) hTypeCompare hNat hTwo = diff (hTwo , \ ()) hTypeCompare hNat hNat = same -- we write the obvious four cases; in the "same" cases, the types really -- do match; in the "diff" cases, Agda can rule out the equation hTwo == hNat -- (or vice versa) because it knows the constructors of datatypes differ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- But back to our typechecker. To make things easier, we'll assume -- that our supplier has already been kind enough to do *scope* checking, -- so that all the variables written by the programmer have been looked -- up and turned into typed references. -- a reference: a pair of a type and a variable of that type. Ref : Context -> Set Ref G = Sg HType (Var G) -- making a reference ref : forall {G S} -> Var G S -> Ref G ref {G}{S} v = S , v -- ??? At last, your bit! Show that the following view type covers all -- untyped terms: -- either things go well and get the 'ok' and a well typed term -- or something went wrong down in the expression tree somewhere, -- so we can explain where that is. data Checkable (G : Context) -- the context of typed variables in scope (T : HType) -- the type we expect : HExp (Ref G) -- the untyped term we hope has type T -> Set where -- one of two situations applies -- either ok : (t : THExp (Var G) T) -- we have a term of type T -> Checkable G T (termFog ref t) -- and it's what we're checking -- or err : (t's : List (HExp' (Ref G))) -- there's some surroundings (s : HExp (Ref G)) -- and a subterm of interest -> Checkable G T (rootToHole t's s) -- in what we're checking check : (G : Context)(T : HType)(h : HExp (Ref G)) -> Checkable G T h check G T h = {!!} -- Now, this isn't quite the whole story, but it's pretty good. We've -- guaranteed that -- * if we say yes, it's because we've found the typed version -- of the untyped input -- * if we say no, we can point to a place where (we say that) there's a -- problem -- So we're *sound* (we never say yes to bad things), but not necessarily -- *complete* (we can say no to good things). Nothing stops us reporting a -- bogus type error at the subterm of our choosing! We could work harder -- and define, in the same way as the typed terms, the "terrors", being -- the terms containing at least one type error. The canny way to do that -- is to try writing the typechecker, then grow the datatype that describes -- all the failure cases. ------------------------------------------------------------------------------ -- -- If you want to read around this topic, you may be interested in -- -- The Zipper -- Gerard Huet -- Journal of Functional Programming, 1997. -- -- Monadic presentations of lambda terms using generalized inductive types -- Thorsten Altenkirch and Bernhard Reus -- Computer Science Logic, 1999. -- -- An exercise in dependent types: A well-typed interpreter -- Lennart Augustsson and Magnus Carlsson -- Workshop on Dependent Types in Programming, Gothenburg, 1999. -- -- The view from the left -- Conor McBride and James McKinna -- Journal of Functional Programming, 2004.
41.337017
198
0.556179
1bb0ce1b708d94069f5c7cec134dff49c00b7cd8
1,629
agda
Agda
test/succeed/FlexibleFunArity.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/FlexibleFunArity.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
test/succeed/FlexibleFunArity.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
-- {-# OPTIONS --no-coverage-check #-} -- {-# OPTIONS -v tc.lhs:40 #-} module FlexibleFunArity where open import Common.Equality data Bool : Set where true false : Bool data Maybe (A : Set) : Set where nothing : Maybe A just : A → Maybe A Case : {A : Set} → Maybe A → Set → Set → Set Case nothing B C = B Case (just _) B C = C sample : {A : Set} (m : Maybe A) → Case m Bool (Maybe A → Bool) sample (just a) (just b) = true sample (just a) nothing = false sample nothing = true g : Bool -> Bool -> Bool g false true = false g true = \ x -> true g false false = true -- g true false = false -- Unreachable clause testg1 : ∀ {x} → g true x ≡ true testg1 = refl testg2 : g false true ≡ false testg2 = refl testg3 : g false false ≡ true testg3 = refl T : Bool -> Set T true = Bool T false = Bool -> Bool f : (b : Bool) -> T b f false true = false f false false = true f true = true testf1 : f true ≡ true testf1 = refl testf2 : f false true ≡ false testf2 = refl testf3 : f false false ≡ true testf3 = refl {- checking clause f false true starts with f (b : Bool) : T b splits on b f true -- no match, discard f false -- matches instantiate type f false : T false = Bool -> Bool extend clause f false (y : Bool) : Bool split on y f false true -- matches f false false -- no match, discard done -} {- coverage check starts with f (x : Bool) splits on x f true -- finds clause 1 f false NEW: remaing clauses have bigger arity, so expands to f false (y : Bool) splits on y f false true -- finds clause 2 f false false -- finds clause 3 done -}
15.224299
63
0.624923
1e5d9d95a62d3a8e52ae99df85540cc64bd7c11a
632
agda
Agda
Cubical/Data/Nat/Literals.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Data/Nat/Literals.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Data/Nat/Literals.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{- Importing and re-exporting this module allows for (constrained) natural number and negative integer literals for any type (e.g. Int, ℕ₋₁, ℕ₋₂, ℕ₊₁). -} {-# OPTIONS --cubical --no-exact-split --safe #-} module Cubical.Data.Nat.Literals where open import Agda.Builtin.FromNat public renaming (Number to HasFromNat) open import Agda.Builtin.FromNeg public renaming (Negative to HasFromNeg) open import Cubical.Data.Unit.Base public -- Natural number literals for ℕ open import Agda.Builtin.Nat renaming (Nat to ℕ) instance fromNatℕ : HasFromNat ℕ fromNatℕ = record { Constraint = λ _ → Unit ; fromNat = λ n → n }
27.478261
80
0.732595
03e3495f88bf43678951313e2dfaa03c5ad9e29d
1,102
agda
Agda
src/HIT/Interval.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
src/HIT/Interval.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
src/HIT/Interval.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K #-} module HIT.Interval where open import PathOperations open import PathStructure.Id.Tr open import Types module I-Definition where private data #I : Set where #0 : #I #1 : #I I : Set I = #I 0ᵢ : I 0ᵢ = #0 1ᵢ : I 1ᵢ = #1 postulate seg : 0ᵢ ≡ 1ᵢ I-ind : ∀ {p} (P : I → Set p) (x₀ : P 0ᵢ) (x₁ : P 1ᵢ) (p : tr P seg x₀ ≡ x₁) → ∀ i → P i I-ind P x₀ x₁ p #0 = x₀ I-ind P x₀ x₁ p #1 = x₁ postulate I-β-i : ∀ {p} (P : I → Set p) (x₀ : P 0ᵢ) (x₁ : P 1ᵢ) (p : tr P seg x₀ ≡ x₁) → apd (I-ind P x₀ x₁ p) seg ≡ p I-rec : ∀ {p} {P : Set p} (x₀ x₁ : P) (p : x₀ ≡ x₁) (i : I) → P I-rec x₀ x₁ p #0 = x₀ I-rec x₀ x₁ p #1 = x₁ postulate I-β-r : ∀ {p} {P : Set p} (x₀ x₁ : P) (p : x₀ ≡ x₁) → ap (I-rec x₀ x₁ p) seg ≡ p open I-Definition public from-path-space : ∀ {a} {A : Set a} → (Σ A λ x → Σ A λ y → x ≡ y) → I → A from-path-space (x , y , p) = I-rec x y p to-path-space : ∀ {a} {A : Set a} → (I → A) → Σ A λ x → Σ A λ y → x ≡ y to-path-space f = f 0ᵢ , f 1ᵢ , ap f seg
19
52
0.470962
37484354d2a350654a543753807f9ab8e0e9ee92
14,059
agda
Agda
Cubical/HITs/S1/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/S1/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/S1/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{- Definition of the circle as a HIT with a proof that Ω(S¹) ≡ ℤ -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.S1.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Data.Nat hiding (_+_ ; _*_ ; +-assoc ; +-comm) open import Cubical.Data.Int data S¹ : Type₀ where base : S¹ loop : base ≡ base -- Check that transp is the identity function for S¹ module _ where transpS¹ : ∀ (φ : I) (u0 : S¹) → transp (λ _ → S¹) φ u0 ≡ u0 transpS¹ φ u0 = refl compS1 : ∀ (φ : I) (u : ∀ i → Partial φ S¹) (u0 : S¹ [ φ ↦ u i0 ]) → comp (λ _ → S¹) u (outS u0) ≡ hcomp u (outS u0) compS1 φ u u0 = refl helix : S¹ → Type₀ helix base = Int helix (loop i) = sucPathInt i ΩS¹ : Type₀ ΩS¹ = base ≡ base encode : ∀ x → base ≡ x → helix x encode x p = subst helix p (pos zero) winding : ΩS¹ → Int winding = encode base intLoop : Int → ΩS¹ intLoop (pos zero) = refl intLoop (pos (suc n)) = intLoop (pos n) ∙ loop intLoop (negsuc zero) = sym loop intLoop (negsuc (suc n)) = intLoop (negsuc n) ∙ sym loop decodeSquare : (n : Int) → PathP (λ i → base ≡ loop i) (intLoop (predInt n)) (intLoop n) decodeSquare (pos zero) i j = loop (i ∨ ~ j) decodeSquare (pos (suc n)) i j = hfill (λ k → λ { (j = i0) → base ; (j = i1) → loop k } ) (inS (intLoop (pos n) j)) i decodeSquare (negsuc n) i j = hcomp (λ k → λ { (i = i1) → intLoop (negsuc n) j ; (j = i0) → base ; (j = i1) → loop (i ∨ ~ k) }) (intLoop (negsuc n) j) decode : (x : S¹) → helix x → base ≡ x decode base = intLoop decode (loop i) y j = let n : Int n = unglue (i ∨ ~ i) y in hcomp (λ k → λ { (i = i0) → intLoop (predSuc y k) j ; (i = i1) → intLoop y j ; (j = i0) → base ; (j = i1) → loop i }) (decodeSquare n i j) decodeEncode : (x : S¹) (p : base ≡ x) → decode x (encode x p) ≡ p decodeEncode x p = J (λ y q → decode y (encode y q) ≡ q) (λ _ → refl) p isSetΩS¹ : isSet ΩS¹ isSetΩS¹ p q r s j i = hcomp (λ k → λ { (i = i0) → decodeEncode base p k ; (i = i1) → decodeEncode base q k ; (j = i0) → decodeEncode base (r i) k ; (j = i1) → decodeEncode base (s i) k }) (decode base (isSetInt (winding p) (winding q) (cong winding r) (cong winding s) j i)) -- This proof does not rely on rewriting hcomp with empty systems in -- Int as ghcomp has been implemented! windingIntLoop : (n : Int) → winding (intLoop n) ≡ n windingIntLoop (pos zero) = refl windingIntLoop (pos (suc n)) = cong sucInt (windingIntLoop (pos n)) windingIntLoop (negsuc zero) = refl windingIntLoop (negsuc (suc n)) = cong predInt (windingIntLoop (negsuc n)) ΩS¹≡Int : ΩS¹ ≡ Int ΩS¹≡Int = isoToPath (iso winding intLoop windingIntLoop (decodeEncode base)) -- intLoop and winding are group homomorphisms private intLoop-sucInt : (z : Int) → intLoop (sucInt z) ≡ intLoop z ∙ loop intLoop-sucInt (pos n) = refl intLoop-sucInt (negsuc zero) = sym (lCancel loop) intLoop-sucInt (negsuc (suc n)) = rUnit (intLoop (negsuc n)) ∙ (λ i → intLoop (negsuc n) ∙ lCancel loop (~ i)) ∙ assoc (intLoop (negsuc n)) (sym loop) loop intLoop-predInt : (z : Int) → intLoop (predInt z) ≡ intLoop z ∙ sym loop intLoop-predInt (pos zero) = lUnit (sym loop) intLoop-predInt (pos (suc n)) = rUnit (intLoop (pos n)) ∙ (λ i → intLoop (pos n) ∙ (rCancel loop (~ i))) ∙ assoc (intLoop (pos n)) loop (sym loop) intLoop-predInt (negsuc n) = refl intLoop-hom : (a b : Int) → (intLoop a) ∙ (intLoop b) ≡ intLoop (a + b) intLoop-hom a (pos zero) = sym (rUnit (intLoop a)) intLoop-hom a (pos (suc n)) = assoc (intLoop a) (intLoop (pos n)) loop ∙ (λ i → (intLoop-hom a (pos n) i) ∙ loop) ∙ sym (intLoop-sucInt (a + pos n)) intLoop-hom a (negsuc zero) = sym (intLoop-predInt a) intLoop-hom a (negsuc (suc n)) = assoc (intLoop a) (intLoop (negsuc n)) (sym loop) ∙ (λ i → (intLoop-hom a (negsuc n) i) ∙ (sym loop)) ∙ sym (intLoop-predInt (a + negsuc n)) winding-hom : (a b : ΩS¹) → winding (a ∙ b) ≡ (winding a) + (winding b) winding-hom a b i = hcomp (λ t → λ { (i = i0) → winding (decodeEncode base a t ∙ decodeEncode base b t) ; (i = i1) → windingIntLoop (winding a + winding b) t }) (winding (intLoop-hom (winding a) (winding b) i)) -- Based homotopy group basedΩS¹ : (x : S¹) → Type₀ basedΩS¹ x = x ≡ x -- Proof that the homotopy group is actually independent on the basepoint -- first, give a quasi-inverse to the basechange basedΩS¹→ΩS¹ for any loop i -- (which does *not* match at endpoints) private ΩS¹→basedΩS¹-filler : I → I → ΩS¹ → I → S¹ ΩS¹→basedΩS¹-filler l i x j = hfill (λ t → λ { (j = i0) → loop (i ∧ t) ; (j = i1) → loop (i ∧ t) }) (inS (x j)) l basedΩS¹→ΩS¹-filler : (_ i : I) → basedΩS¹ (loop i) → I → S¹ basedΩS¹→ΩS¹-filler l i x j = hfill (λ t → λ { (j = i0) → loop (i ∧ (~ t)) ; (j = i1) → loop (i ∧ (~ t)) }) (inS (x j)) l ΩS¹→basedΩS¹ : (i : I) → ΩS¹ → basedΩS¹ (loop i) ΩS¹→basedΩS¹ i x j = ΩS¹→basedΩS¹-filler i1 i x j basedΩS¹→ΩS¹ : (i : I) → basedΩS¹ (loop i) → ΩS¹ basedΩS¹→ΩS¹ i x j = basedΩS¹→ΩS¹-filler i1 i x j basedΩS¹→ΩS¹→basedΩS¹ : (i : I) → (x : basedΩS¹ (loop i)) → ΩS¹→basedΩS¹ i (basedΩS¹→ΩS¹ i x) ≡ x basedΩS¹→ΩS¹→basedΩS¹ i x j k = hcomp (λ t → λ { (j = i1) → basedΩS¹→ΩS¹-filler (~ t) i x k ; (j = i0) → ΩS¹→basedΩS¹ i (basedΩS¹→ΩS¹ i x) k ; (k = i0) → loop (i ∧ (t ∨ (~ j))) ; (k = i1) → loop (i ∧ (t ∨ (~ j))) }) (ΩS¹→basedΩS¹-filler (~ j) i (basedΩS¹→ΩS¹ i x) k) ΩS¹→basedΩS¹→ΩS¹ : (i : I) → (x : ΩS¹) → basedΩS¹→ΩS¹ i (ΩS¹→basedΩS¹ i x) ≡ x ΩS¹→basedΩS¹→ΩS¹ i x j k = hcomp (λ t → λ { (j = i1) → ΩS¹→basedΩS¹-filler (~ t) i x k ; (j = i0) → basedΩS¹→ΩS¹ i (ΩS¹→basedΩS¹ i x) k ; (k = i0) → loop (i ∧ ((~ t) ∧ j)) ; (k = i1) → loop (i ∧ ((~ t) ∧ j)) }) (basedΩS¹→ΩS¹-filler (~ j) i (ΩS¹→basedΩS¹ i x) k) -- from the existence of our quasi-inverse, we deduce that the basechange is an equivalence -- for all loop i basedΩS¹→ΩS¹-isequiv : (i : I) → isEquiv (basedΩS¹→ΩS¹ i) basedΩS¹→ΩS¹-isequiv i = isoToIsEquiv (iso (basedΩS¹→ΩS¹ i) (ΩS¹→basedΩS¹ i) (ΩS¹→basedΩS¹→ΩS¹ i) (basedΩS¹→ΩS¹→basedΩS¹ i)) -- now extend the basechange so that both ends match -- (and therefore we get a basechange for any x : S¹) private loop-conjugation : basedΩS¹→ΩS¹ i1 ≡ λ x → x loop-conjugation i x = let p = (doubleCompPath-elim loop x (sym loop)) ∙ (λ i → (lUnit loop i ∙ x) ∙ sym loop) in ((sym (decodeEncode base (basedΩS¹→ΩS¹ i1 x))) ∙ (λ t → intLoop (winding (p t))) ∙ (λ t → intLoop (winding-hom (intLoop (pos (suc zero)) ∙ x) (intLoop (negsuc zero)) t)) ∙ (λ t → intLoop ((winding-hom (intLoop (pos (suc zero))) x t) + (windingIntLoop (negsuc zero) t))) ∙ (λ t → intLoop (((windingIntLoop (pos (suc zero)) t) + (winding x)) + (negsuc zero))) ∙ (λ t → intLoop ((+-comm (pos (suc zero)) (winding x) t) + (negsuc zero))) ∙ (λ t → intLoop (+-assoc (winding x) (pos (suc zero)) (negsuc zero) (~ t))) ∙ (decodeEncode base x)) i refl-conjugation : basedΩS¹→ΩS¹ i0 ≡ λ x → x refl-conjugation i x j = hfill (λ t → λ { (j = i0) → base ; (j = i1) → base }) (inS (x j)) (~ i) basechange : (x : S¹) → basedΩS¹ x → ΩS¹ basechange base y = y basechange (loop i) y = hcomp (λ t → λ { (i = i0) → refl-conjugation t y ; (i = i1) → loop-conjugation t y }) (basedΩS¹→ΩS¹ i y) -- for any loop i, the old basechange is equal to the new one basedΩS¹→ΩS¹≡basechange : (i : I) → basedΩS¹→ΩS¹ i ≡ basechange (loop i) basedΩS¹→ΩS¹≡basechange i j y = hfill (λ t → λ { (i = i0) → refl-conjugation t y ; (i = i1) → loop-conjugation t y }) (inS (basedΩS¹→ΩS¹ i y)) j -- so for any loop i, the extended basechange is an equivalence basechange-isequiv-aux : (i : I) → isEquiv (basechange (loop i)) basechange-isequiv-aux i = transport (λ j → isEquiv (basedΩS¹→ΩS¹≡basechange i j)) (basedΩS¹→ΩS¹-isequiv i) -- as being an equivalence is contractible, basechange is an equivalence for all x : S¹ basechange-isequiv : (x : S¹) → isEquiv (basechange x) basechange-isequiv base = basechange-isequiv-aux i0 basechange-isequiv (loop i) = hcomp (λ t → λ { (i = i0) → basechange-isequiv-aux i0 ; (i = i1) → isPropIsEquiv (basechange base) (basechange-isequiv-aux i1) (basechange-isequiv-aux i0) t }) (basechange-isequiv-aux i) basedΩS¹≡ΩS¹ : (x : S¹) → basedΩS¹ x ≡ ΩS¹ basedΩS¹≡ΩS¹ x = ua (basechange x , basechange-isequiv x) basedΩS¹≡Int : (x : S¹) → basedΩS¹ x ≡ Int basedΩS¹≡Int x = (basedΩS¹≡ΩS¹ x) ∙ ΩS¹≡Int -- Some tests module _ where private test-winding-pos : winding (intLoop (pos 5)) ≡ pos 5 test-winding-pos = refl test-winding-neg : winding (intLoop (negsuc 5)) ≡ negsuc 5 test-winding-neg = refl -- the inverse when S¹ is seen as a group inv : S¹ → S¹ inv base = base inv (loop i) = loop (~ i) invInvolutive : section inv inv invInvolutive base = refl invInvolutive (loop i) = refl invS¹Equiv : S¹ ≃ S¹ invS¹Equiv = isoToEquiv (iso inv inv invInvolutive invInvolutive) invS¹Path : S¹ ≡ S¹ invS¹Path = ua invS¹Equiv -- rot, used in the Hopf fibration rotLoop : (a : S¹) → a ≡ a rotLoop base = loop rotLoop (loop i) j = hcomp (λ k → λ { (i = i0) → loop (j ∨ ~ k) ; (i = i1) → loop (j ∧ k) ; (j = i0) → loop (i ∨ ~ k) ; (j = i1) → loop (i ∧ k)}) base rot : S¹ → S¹ → S¹ rot base x = x rot (loop i) x = rotLoop x i _*_ : S¹ → S¹ → S¹ a * b = rot a b infixl 30 _*_ -- rot i j = filler-rot i j i1 filler-rot : I → I → I → S¹ filler-rot i j = hfill (λ k → λ { (i = i0) → loop (j ∨ ~ k) ; (i = i1) → loop (j ∧ k) ; (j = i0) → loop (i ∨ ~ k) ; (j = i1) → loop (i ∧ k) }) (inS base) isPropFamS¹ : ∀ {ℓ} (P : S¹ → Type ℓ) (pP : (x : S¹) → isProp (P x)) (b0 : P base) → PathP (λ i → P (loop i)) b0 b0 isPropFamS¹ P pP b0 i = pP (loop i) (transp (λ j → P (loop (i ∧ j))) (~ i) b0) (transp (λ j → P (loop (i ∨ ~ j))) i b0) i rotIsEquiv : (a : S¹) → isEquiv (rot a) rotIsEquiv base = idIsEquiv S¹ rotIsEquiv (loop i) = isPropFamS¹ (λ x → isEquiv (rot x)) (λ x → isPropIsEquiv (rot x)) (idIsEquiv _) i -- more direct definition of the rot (loop i) equivalence rotLoopInv : (a : S¹) → PathP (λ i → rotLoop (rotLoop a (~ i)) i ≡ a) refl refl rotLoopInv a i j = hcomp (λ k → λ { (i = i0) → a; (i = i1) → rotLoop a (j ∧ ~ k); (j = i0) → rotLoop (rotLoop a (~ i)) i; (j = i1) → rotLoop a (i ∧ ~ k)}) (rotLoop (rotLoop a (~ i ∨ j)) i) rotLoopEquiv : (i : I) → S¹ ≃ S¹ rotLoopEquiv i = isoToEquiv (iso (λ a → rotLoop a i) (λ a → rotLoop a (~ i)) (λ a → rotLoopInv a i) (λ a → rotLoopInv a (~ i))) -- some cancellation laws, used in the Hopf fibration private rotInv-aux-1 : I → I → I → I → S¹ rotInv-aux-1 j k i = hfill (λ l → λ { (k = i0) → (loop (i ∧ ~ l)) * loop j ; (k = i1) → loop j ; (i = i0) → (loop k * loop j) * loop (~ k) ; (i = i1) → loop (~ k ∧ ~ l) * loop j }) (inS ((loop (k ∨ i) * loop j) * loop (~ k))) rotInv-aux-2 : I → I → I → S¹ rotInv-aux-2 i j k = hcomp (λ l → λ { (k = i0) → inv (filler-rot (~ i) (~ j) l) ; (k = i1) → loop (j ∧ l) ; (i = i0) → filler-rot k j l ; (i = i1) → loop (j ∧ l) ; (j = i0) → loop (i ∨ k ∨ (~ l)) ; (j = i1) → loop ((i ∨ k) ∧ l) }) (base) rotInv-aux-3 : I → I → I → I → S¹ rotInv-aux-3 j k i = hfill (λ l → λ { (k = i0) → rotInv-aux-2 i j l ; (k = i1) → loop j ; (i = i0) → loop (k ∨ l) * loop j ; (i = i1) → loop k * (inv (loop (~ j) * loop k)) }) (inS (loop k * (inv (loop (~ j) * loop (k ∨ ~ i))))) rotInv-aux-4 : I → I → I → I → S¹ rotInv-aux-4 j k i = hfill (λ l → λ { (k = i0) → rotInv-aux-2 i j l ; (k = i1) → loop j ; (i = i0) → loop j * loop (k ∨ l) ; (i = i1) → (inv (loop (~ j) * loop k)) * loop k }) (inS ((inv (loop (~ j) * loop (k ∨ ~ i))) * loop k)) rotInv-1 : (a b : S¹) → b * a * inv b ≡ a rotInv-1 base base i = base rotInv-1 base (loop k) i = rotInv-aux-1 i0 k i i1 rotInv-1 (loop j) base i = loop j rotInv-1 (loop j) (loop k) i = rotInv-aux-1 j k i i1 rotInv-2 : (a b : S¹) → inv b * a * b ≡ a rotInv-2 base base i = base rotInv-2 base (loop k) i = rotInv-aux-1 i0 (~ k) i i1 rotInv-2 (loop j) base i = loop j rotInv-2 (loop j) (loop k) i = rotInv-aux-1 j (~ k) i i1 rotInv-3 : (a b : S¹) → b * (inv (inv a * b)) ≡ a rotInv-3 base base i = base rotInv-3 base (loop k) i = rotInv-aux-3 i0 k (~ i) i1 rotInv-3 (loop j) base i = loop j rotInv-3 (loop j) (loop k) i = rotInv-aux-3 j k (~ i) i1 rotInv-4 : (a b : S¹) → inv (b * inv a) * b ≡ a rotInv-4 base base i = base rotInv-4 base (loop k) i = rotInv-aux-4 i0 k (~ i) i1 rotInv-4 (loop j) base i = loop j rotInv-4 (loop j) (loop k) i = rotInv-aux-4 j k (~ i) i1
36.328165
94
0.529625
4e1f3f00928961253468a264e16499a12ade9f34
380
agda
Agda
test/Succeed/Issue1550.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Succeed/Issue1550.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/Issue1550.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2021-06-14T11:07:38.000Z
2021-06-14T11:07:38.000Z
-- Andreas, 2015-08-27 Allow rewrite rules for symbols defined in other file {-# OPTIONS --rewriting --confluence-check #-} open import Common.Nat open import Common.Equality {-# BUILTIN REWRITE _≡_ #-} x+0 : ∀ x → x + 0 ≡ x x+0 zero = refl x+0 (suc x) rewrite x+0 x = refl {-# REWRITE x+0 #-} -- adding rewrite rule for + is ok x+0+0 : ∀{x} → (x + 0) + 0 ≡ x x+0+0 = refl
21.111111
76
0.615789
0d3fa289a73778f14a3a1bb7a3a7f21e341a7672
1,514
agda
Agda
src/finiteSet.agda
shinji-kono/automaton-in-agda
eba0538f088f3d0c0fedb19c47c081954fbc69cb
[ "MIT" ]
null
null
null
src/finiteSet.agda
shinji-kono/automaton-in-agda
eba0538f088f3d0c0fedb19c47c081954fbc69cb
[ "MIT" ]
null
null
null
src/finiteSet.agda
shinji-kono/automaton-in-agda
eba0538f088f3d0c0fedb19c47c081954fbc69cb
[ "MIT" ]
null
null
null
{-# OPTIONS --allow-unsolved-metas #-} module finiteSet where open import Data.Nat hiding ( _≟_ ) open import Data.Fin renaming ( _<_ to _<<_ ) hiding (_≤_) -- open import Data.Fin.Properties hiding ( ≤-refl ) open import Data.Empty open import Relation.Nullary open import Relation.Binary.Definitions open import Relation.Binary.PropositionalEquality open import logic open import nat open import Data.Nat.Properties hiding ( _≟_ ) open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) record FiniteSet ( Q : Set ) : Set where field finite : ℕ Q←F : Fin finite → Q F←Q : Q → Fin finite finiso→ : (q : Q) → Q←F ( F←Q q ) ≡ q finiso← : (f : Fin finite ) → F←Q ( Q←F f ) ≡ f exists1 : (m : ℕ ) → m Data.Nat.≤ finite → (Q → Bool) → Bool exists1 zero _ _ = false exists1 ( suc m ) m<n p = p (Q←F (fromℕ< {m} {finite} m<n)) \/ exists1 m (<to≤ m<n) p exists : ( Q → Bool ) → Bool exists p = exists1 finite ≤-refl p open import Data.List list1 : (m : ℕ ) → m Data.Nat.≤ finite → (Q → Bool) → List Q list1 zero _ _ = [] list1 ( suc m ) m<n p with bool-≡-? (p (Q←F (fromℕ< {m} {finite} m<n))) true ... | yes _ = Q←F (fromℕ< {m} {finite} m<n) ∷ list1 m (<to≤ m<n) p ... | no _ = list1 m (<to≤ m<n) p to-list : ( Q → Bool ) → List Q to-list p = list1 finite ≤-refl p equal? : Q → Q → Bool equal? q0 q1 with F←Q q0 ≟ F←Q q1 ... | yes p = true ... | no ¬p = false
35.209302
90
0.564729
34c45ea53c53a159b7b0cfc3b6881733a27ee31b
116
agda
Agda
test/fail/Issue332.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/fail/Issue332.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/Issue332.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module Issue332 where id : {A : Set} → A → A id x = x syntax id x = id x -- This makes parsing id x ambiguous
10.545455
55
0.612069
d1cb049d27fd95ad9df82051238a3da9be6d62be
3,806
agda
Agda
old/Spaces/FlatteningTypes.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/Spaces/FlatteningTypes.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/Spaces/FlatteningTypes.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import BaseOver module Spaces.FlatteningTypes {i j k} (A : Set i) (B : Set j) (f g : B → A) (C : A → Set k) (D : (b : B) → C (f b) ≃ C (g b)) where ijk = max i (max j k) module BaseHIT where {- data W : Set where cc : A → W pp : (b : B) → cc (f b) ≡ cc (g b) -} private data #W : Set ijk where #cc : A → #W W : Set ijk W = #W cc : A → W cc = #cc postulate pp : (b : B) → cc (f b) ≡ cc (g b) W-rec : ∀ {ℓ} (P : W → Set ℓ) (cc* : (a : A) → P (cc a)) (pp* : (b : B) → cc* (f b) == cc* (g b) [ P ↓ pp b ]) → ((w : W) → P w) W-rec P cc* pp* (#cc a) = cc* a postulate W-rec-β : ∀ {ℓ} (P : W → Set ℓ) (cc* : (a : A) → P (cc a)) (pp* : (b : B) → cc* (f b) == cc* (g b) [ P ↓ pp b ]) → ((b : B) → apd (W-rec P cc* pp*) (pp b) ≡ pp* b) W-rec-nondep : ∀ {ℓ} (P : Set ℓ) (cc* : A → P) (pp* : (b : B) → cc* (f b) ≡ cc* (g b)) → (W → P) W-rec-nondep P cc* pp* (#cc a) = cc* a postulate W-rec-nondep-β : ∀ {ℓ} (P : Set ℓ) (cc* : A → P) (pp* : (b : B) → cc* (f b) ≡ cc* (g b)) → ((b : B) → ap (W-rec-nondep P cc* pp*) (pp b) ≡ pp* b) open BaseHIT public module FlattenedHIT where {- data Wt : Set where cct : (a : A) → C a → Wt pp : (b : B) (d : C (f b)) → cct (f b) d ≡ cct (g b) (π₁ (D b) d) -} private data #Wt : Set ijk where #cct : (a : A) (c : C a) → #Wt Wt : Set ijk Wt = #Wt cct : (a : A) → C a → Wt cct = #cct postulate ppt : (b : B) (d : C (f b)) → cct (f b) d ≡ cct (g b) (π₁ (D b) d) Wt-rec : ∀ {ℓ} (P : Wt → Set ℓ) (cct* : (a : A) (c : C a) → P (cct a c)) (ppt* : (b : B) (d : C (f b)) → cct* (f b) d == cct* (g b) (π₁ (D b) d) [ P ↓ ppt b d ]) → ((w : Wt) → P w) Wt-rec P cct* ppt* (#cct a c) = cct* a c postulate Wt-rec-β : ∀ {ℓ} (P : Wt → Set ℓ) (cct* : (a : A) (c : C a) → P (cct a c)) (ppt* : (b : B) (d : C (f b)) → cct* (f b) d == cct* (g b) (π₁ (D b) d) [ P ↓ ppt b d ]) → ((b : B) (d : C (f b)) → apd (Wt-rec P cct* ppt*) (ppt b d) ≡ ppt* b d) Wt-rec-nondep : ∀ {ℓ} (P : Set ℓ) (cct* : (a : A) → C a → P) (ppt* : (b : B) (d : C (f b)) → cct* (f b) d ≡ cct* (g b) (π₁ (D b) d)) → (Wt → P) Wt-rec-nondep P cct* ppt* (#cct a c) = cct* a c postulate Wt-rec-nondep-β : ∀ {ℓ} (P : Set ℓ) (cct* : (a : A) → C a → P) (ppt* : (b : B) (d : C (f b)) → cct* (f b) d ≡ cct* (g b) (π₁ (D b) d)) → ((b : B) (d : C (f b)) → ap (Wt-rec-nondep P cct* ppt*) (ppt b d) ≡ ppt* b d) open FlattenedHIT public -- Here is the fibration D-eq : (b : B) → C (f b) ≡ C (g b) D-eq b = ua-in (D b) P : W → Set k P = W-rec-nondep _ C D-eq pp-path : (b : B) (d : C (f b)) → π₁ (ua-out (ap P (pp b))) d ≡ π₁ (D b) d pp-path b d = π₁ (ua-out (ap P (pp b))) d ≡⟨ W-rec-nondep-β _ C D-eq _ |in-ctx (λ u → π₁ (ua-out u) d) ⟩ π₁ (ua-out (ua-in (D b))) d ≡⟨ ua-β (D b) |in-ctx (λ u → π₁ u d) ⟩ π₁ (D b) d ∎ lem : ∀ {i} {A : Set i} {x y z : A} (p : x ≡ y) (q : y ≡ z) → ! p ∘ (p ∘' q) ≡ q lem refl refl = refl -- Dependent path in [P] over [pp b] module _ {b : B} {d : C (f b)} {d' : C (g b)} where ↓-pp-in : (π₁ (D b) d ≡ d' → d == d' [ P ↓ pp b ]) ↓-pp-in p = to-transp-in P (pp b) (pp-path b d ∘' p) ↓-pp-out : (d == d' [ P ↓ pp b ] → π₁ (D b) d ≡ d') ↓-pp-out p = ! (pp-path b d) ∘ to-transp-out p ↓-pp-β : (q : π₁ (D b) d ≡ d') → ↓-pp-out (↓-pp-in q) ≡ q ↓-pp-β q = ↓-pp-out (↓-pp-in q) ≡⟨ refl ⟩ ! (pp-path b d) ∘ to-transp-out (to-transp-in P (pp b) (pp-path b d ∘' q)) ≡⟨ to-transp-β P (pp b) (pp-path b d ∘' q) |in-ctx (λ u → ! (pp-path b d) ∘ u) ⟩ ! (pp-path b d) ∘ (pp-path b d ∘' q) ≡⟨ lem (pp-path b d) q ⟩ q ∎
28.192593
95
0.401471
0dbc17d8be3077d445ac130cd7e0b82ea1b23fb5
763
agda
Agda
RefactorAgdaEngine/Test/Tests/input/ExtractDependent.agda
omega12345/RefactorAgda
52d1034aed14c578c9e077fb60c3db1d0791416b
[ "BSD-3-Clause" ]
5
2019-01-31T14:10:18.000Z
2019-05-03T10:03:36.000Z
RefactorAgdaEngine/Test/Tests/input/ExtractDependent.agda
omega12345/RefactorAgda
52d1034aed14c578c9e077fb60c3db1d0791416b
[ "BSD-3-Clause" ]
3
2019-01-31T08:03:07.000Z
2019-02-05T12:53:36.000Z
RefactorAgdaEngine/Test/Tests/input/ExtractDependent.agda
omega12345/RefactorAgda
52d1034aed14c578c9e077fb60c3db1d0791416b
[ "BSD-3-Clause" ]
1
2019-01-31T08:40:41.000Z
2019-01-31T08:40:41.000Z
{-# OPTIONS --allow-unsolved-metas #-} module ExtractDependent where open import Agda.Builtin.Nat open import Agda.Builtin.Bool open import Agda.Builtin.String apply : (A : Set) -> (B : A -> Set) -> ((x : A) -> B x) -> (a : A) -> B a apply A B f a = f a applySameName : (A : Set) -> (A : Set) -> (B : A -> Set) -> (h : Set) -> (h : (x : A) -> B x) -> (a : A) -> B a applySameName C A B g f a = f a -- TODO : Try same test with {A} {B} once the parser can handle that. applyImp : {A : Set} -> {B : A -> Set} -> ((x : A) -> B x) -> (y : A) -> B y applyImp f a = f a applyImpSameName : {A : Set} -> {A : Set} -> {B : A -> Set} -> (h : Set) -> (h : (x : A) -> B x) -> (a : A) -> B a applyImpSameName A B h = B h
31.791667
69
0.482307
362481033b2350d9db1c8e385489e4acaeb9998b
7,918
agda
Agda
Fields/CauchyCompletion/EquivalentMonotone.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Fields/CauchyCompletion/EquivalentMonotone.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Fields/CauchyCompletion/EquivalentMonotone.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K --guardedness #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Setoids.Setoids open import Rings.Definition open import Rings.Lemmas open import Rings.Orders.Partial.Definition open import Rings.Orders.Total.Definition open import Groups.Definition open import Groups.Groups open import Fields.Fields open import Sets.EquivalenceRelations open import Sequences open import Setoids.Orders.Partial.Definition open import Setoids.Orders.Total.Definition open import Functions.Definition open import LogicalFormulae open import Numbers.Naturals.Naturals module Fields.CauchyCompletion.EquivalentMonotone {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {tOrder : SetoidTotalOrder {_<_ = _<_} pOrder} {R : Ring S _+_ _*_} (order : TotallyOrderedRing R tOrder) (F : Field R) (charNot2 : Setoid._∼_ S ((Ring.1R R) + (Ring.1R R)) (Ring.0R R) → False) where open Setoid S open SetoidTotalOrder tOrder open SetoidPartialOrder pOrder open Equivalence eq open TotallyOrderedRing order open Field F open Group (Ring.additiveGroup R) open Ring R open import Fields.Lemmas F open import Fields.Orders.Lemmas {F = F} record { oRing = order } open import Rings.Orders.Lemmas(order) open import Fields.CauchyCompletion.Definition order F open import Fields.CauchyCompletion.Multiplication order F charNot2 open import Fields.CauchyCompletion.Addition order F charNot2 open import Fields.CauchyCompletion.Setoid order F charNot2 open import Fields.CauchyCompletion.Group order F charNot2 open import Fields.CauchyCompletion.Ring order F charNot2 open import Fields.CauchyCompletion.Comparison order F charNot2 open import Fields.CauchyCompletion.Approximation order F charNot2 halvingSequence : (start : A) → Sequence A Sequence.head (halvingSequence start) = start Sequence.tail (halvingSequence start) with halve charNot2 start Sequence.tail (halvingSequence start) | start/2 , _ = halvingSequence start/2 halvingSequenceMultiple : (start : A) → {n : ℕ} → index (halvingSequence start) n ∼ index (map (start *_) (halvingSequence (Ring.1R R))) n halvingSequenceMultiple start {zero} = Equivalence.symmetric eq (Equivalence.transitive eq *Commutative identIsIdent) halvingSequenceMultiple start {succ n} with halve charNot2 start ... | start/2 , _ with allInvertible (1R + 1R) charNot2 halvingSequenceMultiple start {succ n} | start/2 , b | 1/2 , pr1/2 rewrite equalityCommutative (mapAndIndex (halvingSequence (1R * 1/2)) (_*_ start) n) = Equivalence.transitive eq (halvingSequenceMultiple start/2 {n}) f where g : (start * (1/2 * index (halvingSequence 1R) n)) ∼ (start * index (map (_*_ (1R * 1/2)) (halvingSequence 1R)) n) g rewrite equalityCommutative (mapAndIndex (halvingSequence 1R) (_*_ (1R * 1/2)) n) = *WellDefined (Equivalence.reflexive eq) (*WellDefined (Equivalence.symmetric eq identIsIdent) (Equivalence.reflexive eq)) f : index (map (_*_ start/2) (halvingSequence 1R)) n ∼ (start * index (halvingSequence (1R * 1/2)) n) f rewrite equalityCommutative (mapAndIndex (halvingSequence 1R) (_*_ start/2) n) = Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.transitive eq (*WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq (*WellDefined (Equivalence.symmetric eq b) (Equivalence.reflexive eq)) (halfHalves 1/2 (Equivalence.transitive eq (Equivalence.transitive eq (+WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq *Commutative identIsIdent)) (Equivalence.symmetric eq (Equivalence.transitive eq *Commutative identIsIdent))) (Equivalence.symmetric eq *DistributesOver+)) pr1/2)))) (Equivalence.reflexive eq)) (Equivalence.symmetric eq *Associative)) g) (Equivalence.symmetric eq (*WellDefined (Equivalence.reflexive eq) (halvingSequenceMultiple (1R * 1/2) {n}))) Decreasing : Sequence A → Set o Decreasing seq = ∀ (N : ℕ) → (index seq (succ N)) < (index seq N) halvingSequencePositive : (n : ℕ) → 0G < index (halvingSequence 1R) n halvingSequencePositive zero = 0<1 (charNot2ImpliesNontrivial charNot2) halvingSequencePositive (succ n) with halve charNot2 1R halvingSequencePositive (succ n) | 1/2 , pr1/2 = <WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq (Equivalence.transitive eq (halvingSequenceMultiple 1/2 {n}) (Equivalence.transitive eq (identityOfIndiscernablesLeft _∼_ (Equivalence.reflexive eq) (mapAndIndex (halvingSequence 1R) (_*_ 1/2) n)) *Commutative))) (orderRespectsMultiplication (halvingSequencePositive n) (halvePositive 1/2 (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq pr1/2) (0<1 (charNot2ImpliesNontrivial charNot2))))) decreasingHalving : Decreasing (halvingSequence 1R) decreasingHalving N with halve charNot2 1R decreasingHalving N | 1/2 , pr1/2 with (halfLess 1/2 1R (0<1 (charNot2ImpliesNontrivial charNot2)) pr1/2) ... | 1/2<1 = <WellDefined (Equivalence.transitive eq (identityOfIndiscernablesLeft _∼_ (Equivalence.reflexive eq) (equalityCommutative (mapAndIndex (halvingSequence 1R) (_*_ 1/2) N))) (Equivalence.symmetric eq (halvingSequenceMultiple 1/2 {N}))) identIsIdent (ringCanMultiplyByPositive {c = index (halvingSequence 1R) N} (halvingSequencePositive N) 1/2<1) imageOfN : ℕ → A imageOfN zero = 0R imageOfN (succ x) = 1R + imageOfN x nextImageOfN : (a : A) → 0R < a → ℕ nextImageOfN a 0<a = ? halvingToZero : (a : A) → (0G < a) → Sg ℕ (λ N → (index (halvingSequence 1R) N) < a) halvingToZero a 0<a with SetoidTotalOrder.totality tOrder a 1R halvingToZero a 0<a | inl (inl a<1) = {!!} halvingToZero a 0<a | inl (inr 1<a) = 0 , 1<a halvingToZero a 0<a | inr a=1 with halve charNot2 1R ... | 1/2 , pr1/2 = 1 , <WellDefined ans (Equivalence.symmetric eq a=1) (halfLess 1/2 1R (0<1 (charNot2ImpliesNontrivial charNot2)) pr1/2) where ans : 1/2 ∼ Sequence.head (Sequence.tail (halvingSequence 1R)) ans with halve charNot2 1R ans | 1/2' , pr1/2' = halvesEqual charNot2 1/2 1/2' pr1/2 pr1/2' halvesCauchy : cauchy (halvingSequence 1R) halvesCauchy e 0<e = {!!} multipleOfCauchyIsCauchy : (mult : A) → (seq : Sequence A) → cauchy seq → cauchy (map (mult *_) seq) multipleOfCauchyIsCauchy mult seq seqCauchy e 0<e with SetoidTotalOrder.totality tOrder 0R mult multipleOfCauchyIsCauchy mult seq seqCauchy e 0<e | inl (inl x) with allInvertible mult λ pr → irreflexive (<WellDefined (Equivalence.reflexive eq) pr x) ... | 1/mult , pr1/mult = {!!} multipleOfCauchyIsCauchy mult seq seqCauchy e 0<e | inl (inr x) with allInvertible mult λ pr → irreflexive (<WellDefined pr (Equivalence.reflexive eq) x) ... | 1/mult , pr1/mult = {!!} multipleOfCauchyIsCauchy mult seq seqCauchy e 0<e | inr 0=mult = 0 , ans where ans : {m n : ℕ} → (0 <N m) → (0 <N n) → abs (index (map (_*_ mult) seq) m + inverse (index (map (_*_ mult) seq) n)) < e ans {m} {n} _ _ rewrite equalityCommutative (mapAndIndex seq (_*_ mult) m) | equalityCommutative (mapAndIndex seq (_*_ mult) n) = <WellDefined {!!} (Equivalence.reflexive eq) 0<e halvingSequenceCauchy : (start : A) → cauchy (halvingSequence start) halvingSequenceCauchy start = {!!} sequenceAllAbove : (a : CauchyCompletion) → Sequence A sequenceAllAbove a = go (Ring.1R R) (0<1 (charNot2ImpliesNontrivial charNot2)) where go : (e : A) → (0G < e) → Sequence A Sequence.head (go e 0<e) = rationalApproximatelyAbove a e 0<e Sequence.tail (go e 0<e) with halve charNot2 e ... | e/2 , prE/2 = go e/2 (halvePositive e/2 (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq prE/2) 0<e)) sequenceAllAboveCauchy : (a : CauchyCompletion) → cauchy (sequenceAllAbove a) sequenceAllAboveCauchy a e 0<e = {!!} -- find N such that 1/2^N < e -- show that this N is enough -- show that sequenceAllAbove ∼ a -- monotonify sequenceAllAbove -- show that monotonify of a sequence which is all above its limit still converges to that limit
64.373984
789
0.74438
7c1eedfcce12f476181a7cda32455f92904568c9
2,869
agda
Agda
TypeTheory/HoTT/Functions.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/HoTT/Functions.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/HoTT/Functions.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
{- A possible implementation of the following HIT arr. Note that this type is mutually defined with App, that is to say, they are defined by induction-recursion! Inductive arr (A,B:Set) : Set := | base : B -> arr A B | step : (A -> arr A B) -> arr A B. | path : (forall x : A, App f x = App g x) -> f = g. where App is defined by Fixpoint App (f : arr A B)(a : A) := match f with | base b => b | step g => App (g a) a end. Due to the fact that arr and App are defined by induction-recuriosn, the recursion principle for arr needs to make extra assumptions, see the parameters of the arr-Rec module. Effectively, we see the function space A → B as algebra for the functor (-) × A and App is an algebra homomorphism from arr A B to A → B. This is reflected in the extra assumption in the recursion principle. -} {-# OPTIONS --without-K #-} open import lib.Basics open import lib.PathGroupoid open import lib.types.Paths open import lib.Funext module _ where private data #arr-aux (A B : Set) : Set where #base : B → #arr-aux A B #step : (A → #arr-aux A B) → #arr-aux A B #App : ∀{A B} → #arr-aux A B → A → B #App (#base b) a = b #App (#step g) a = #App (g a) a _~>_ : Set → Set → Set _~>_ = #arr-aux base : ∀{A B} → B → A ~> B base = #base step : ∀{A B} → (A → A ~> B) → A ~> B step = #step App : ∀{A B} → A ~> B → A → B App = #App Abstr : ∀{A B} → (A → B) → A ~> B Abstr f = step (λ x → base (f x)) postulate path : ∀{A B} (f g : A ~> B) (a : A) → App f a == App g a → f == g module arr-Rec {A B X : Set} (base* : B → X) (step* : (A → X) → X) (App* : X → A → B) -- Here we need to make the assumption that App* is an algebra homomorphism -- from X into the function space. (App*-β₂ : (a : A) (f : A → X) → App* (step* f) a == App* (f a) a) (path* : (x y : X) (a : A) → App* x a == App* y a → x == y) where rec : A ~> B → X rec = rec-aux phantom where rec-aux : Phantom path* → A ~> B → X rec-aux ph (#base b) = base* b rec-aux ph (#step f) = step* (λ a → rec-aux ph (f a)) lem : (f g : A ~> B) (a : A) → App f a == App g a → App* (rec f) a == App* (rec g) a lem (#base b) (#base .b) a idp = idp lem (#base b) (#step g) a p = let β-red* = App*-β₂ a (rec ∘ g) IH = lem (#base b) (g a) a p in IH ∙ ! β-red* lem (#step f) (#base b) a p = let β-red* = App*-β₂ a (rec ∘ f) IH = lem (f a) (#base b) a p in β-red* ∙ IH lem (#step f) (#step g) a p = let IH = lem (f a) (g a) a p β-red-f = App*-β₂ a (rec ∘ f) β-red-g = App*-β₂ a (rec ∘ g) in β-red-f ∙ IH ∙ ! β-red-g postulate path-β : (f g : A ~> B) (a : A) (p : App f a == App g a) → ap rec (path f g a p) == path* (rec f) (rec g) a (lem f g a p)
28.405941
79
0.515511
5e6b420205cef42344186a2b5a0bfd0a5f20226d
8,474
agda
Agda
src/Categories/Category/Complete/Properties.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Complete/Properties.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Complete/Properties.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Category.Complete.Properties {o ℓ e} (C : Category o ℓ e) where open import Level open import Data.Product open import Relation.Binary open import Categories.Category.Complete open import Categories.Category.Complete.Finitely open import Categories.Category.Construction.Functors open import Categories.Diagram.Limit as Lim open import Categories.Diagram.Limit.Properties open import Categories.Diagram.Equalizer.Limit C open import Categories.Diagram.Cone.Properties open import Categories.Object.Product.Limit C open import Categories.Object.Terminal.Limit C open import Categories.Functor open import Categories.Functor.Continuous open import Categories.Functor.Properties open import Categories.NaturalTransformation open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_) import Categories.Category.Construction.Cones as Co import Categories.Morphism.Reasoning as MR import Categories.Morphism as Mor import Categories.Morphism.Properties as Morₚ private variable o′ ℓ′ e′ o″ ℓ″ e″ : Level module C = Category C module _ (Com : Complete o′ ℓ′ e′ C) where Complete⇒FinitelyComplete : FinitelyComplete C Complete⇒FinitelyComplete = record { cartesian = record { terminal = limit⇒⊥ (Com (⊥⇒limit-F _ _ _)) ; products = record { product = λ {A B} → limit⇒product (Com (product⇒limit-F _ _ _ A B)) } } ; equalizer = λ f g → limit⇒equalizer (Com (equalizer⇒limit-F _ _ _ f g)) } module _ {D : Category o′ ℓ′ e′} (Com : Complete o″ ℓ″ e″ D) where private D^C = Functors C D module D^C = Category D^C module D = Category D module _ {J : Category o″ ℓ″ e″} (F : Functor J D^C) where private module J = Category J module F = Functor F open F module F₀ j = Functor (F₀ j) module F₁ {a b} (f : a J.⇒ b) = NaturalTransformation (F₁ f) F[-,_] : C.Obj → Functor J D F[-, X ] = record { F₀ = λ j → F₀.₀ j X ; F₁ = λ f → F₁.η f X ; identity = identity ; homomorphism = homomorphism ; F-resp-≈ = λ eq → F-resp-≈ eq -- this application cannot be eta reduced } F[-,-] : Functor C (Functors J D) F[-,-] = record { F₀ = F[-,_] ; F₁ = λ f → ntHelper record { η = λ j → F₀.₁ j f ; commute = λ g → F₁.sym-commute g f } ; identity = F₀.identity _ ; homomorphism = F₀.homomorphism _ ; F-resp-≈ = λ eq → F₀.F-resp-≈ _ eq } module F[-,-] = Functor F[-,-] module LimFX X = Limit (Com F[-, X ]) open LimFX hiding (commute) K⇒lim : ∀ {X Y} (f : X C.⇒ Y) K → Co.Cones F[-, Y ] [ nat-map-Cone (F[-,-].₁ f) K , limit Y ] K⇒lim f K = rep-cone _ (nat-map-Cone (F[-,-].₁ f) K) lim⇒lim : ∀ {X Y} (f : X C.⇒ Y) → Co.Cones F[-, Y ] [ nat-map-Cone (F[-,-].₁ f) (limit X) , limit Y ] lim⇒lim f = K⇒lim f (limit _) module lim⇒lim {X Y} (f : X C.⇒ Y) = Co.Cone⇒ F[-, Y ] (lim⇒lim f) module FCone (K : Co.Cone F) where open Co.Cone F K public module N = Functor N module ψ j = NaturalTransformation (ψ j) module FCone⇒ {K K′ : Co.Cone F} (K⇒K′ : Co.Cone⇒ F K K′) where open Co.Cone⇒ F K⇒K′ public module arr = NaturalTransformation arr FXcone : ∀ X → (K : Co.Cone F) → Co.Cone F[-, X ] FXcone X K = record { N = N.₀ X ; apex = record { ψ = λ j → ψ.η j X ; commute = λ f → commute f -- this application cannot be eta reduced } } where open FCone K ⊤ : Co.Cone F ⊤ = record { N = record { F₀ = λ X → apex X ; F₁ = λ {A B} f → lim⇒lim.arr f ; identity = λ {X} → terminal.!-unique X record { arr = D.id ; commute = D.identityʳ ○ ⟺ (elimˡ (F₀.identity _)) } ; homomorphism = λ {X Y Z} {f g} → terminal.!-unique₂ Z {nat-map-Cone (F[-,-].₁ (g C.∘ f)) (limit X)} {terminal.! Z} {record { commute = λ {j} → begin proj Z j ∘ lim⇒lim.arr g ∘ lim⇒lim.arr f ≈⟨ pullˡ (lim⇒lim.commute g) ⟩ (F₀.₁ j g ∘ proj Y j) ∘ lim⇒lim.arr f ≈⟨ pullʳ (lim⇒lim.commute f) ⟩ F₀.₁ j g ∘ F₀.₁ j f ∘ proj X j ≈˘⟨ pushˡ (F₀.homomorphism j) ⟩ F₀.₁ j (g C.∘ f) ∘ proj X j ∎ }} ; F-resp-≈ = λ {A B} {f g} eq → terminal.!-unique B record { commute = lim⇒lim.commute g ○ ∘-resp-≈ˡ (F₀.F-resp-≈ _ (C.Equiv.sym eq)) } } ; apex = record { ψ = λ j → ntHelper record { η = λ X → proj X j ; commute = λ _ → LimFX.commute _ } ; commute = λ f {X} → limit-commute X f } } where open D open D.HomReasoning open MR D K⇒⊤′ : ∀ X {K} → Co.Cones F [ K , ⊤ ] → Co.Cones F[-, X ] [ FXcone X K , LimFX.limit X ] K⇒⊤′ X {K} K⇒⊤ = record { arr = arr.η X ; commute = comm } where open FCone⇒ K⇒⊤ renaming (commute to comm) complete : Limit F complete = record { terminal = record { ⊤ = ⊤ ; ! = λ {K} → let module K = FCone K in record { arr = ntHelper record { η = λ X → rep X (FXcone X K) ; commute = λ {X Y} f → terminal.!-unique₂ Y {nat-map-Cone (F[-,-].₁ f) (FXcone X K)} {record { commute = λ {j} → begin proj Y j ∘ rep Y (FXcone Y K) ∘ K.N.₁ f ≈⟨ pullˡ (LimFX.commute Y) ⟩ K.ψ.η j Y ∘ K.N.F₁ f ≈⟨ K.ψ.commute j f ⟩ F₀.₁ j f ∘ K.ψ.η j X ∎ }} {record { commute = λ {j} → begin proj Y j ∘ lim⇒lim.arr f ∘ rep X (FXcone X K) ≈⟨ pullˡ (lim⇒lim.commute f) ⟩ (F₀.₁ j f ∘ proj X j) ∘ rep X (FXcone X K) ≈⟨ pullʳ (LimFX.commute X) ⟩ F₀.₁ j f ∘ K.ψ.η j X ∎ }} } ; commute = λ {_} {X} → LimFX.commute X } ; !-unique = λ K⇒⊤ {X} → terminal.!-unique X (K⇒⊤′ X K⇒⊤) } } where open D open D.HomReasoning open MR D ev : C.Obj → Functor D^C D ev = evalF C D module _ (L : Limit F) (X : C.Obj) where private module ev = Functor (ev X) open Mor D^C module DM = Mor D open Morₚ D open D.HomReasoning open MR D L′ : Limit (ev X ∘F F) L′ = Com (ev X ∘F F) Fiso : F[-, X ] ≃ ev X ∘F F Fiso = record { F⇒G = ntHelper record { η = λ _ → D.id ; commute = λ _ → id-comm-sym ○ D.∘-resp-≈ˡ (introʳ (F₀.identity _)) } ; F⇐G = ntHelper record { η = λ _ → D.id ; commute = λ _ → D.∘-resp-≈ʳ (elimʳ (F₀.identity _)) ○ id-comm-sym } ; iso = λ _ → record { isoˡ = D.identity² ; isoʳ = D.identity² } } apex-iso : Limit.apex L ≅ Limit.apex complete apex-iso = up-to-iso F L complete apex-iso′ : Limit.apex (Com F[-, X ]) DM.≅ Limit.apex L′ apex-iso′ = ≃⇒lim≅ Fiso (Com F[-, X ]) L′ project-iso : Functor.F₀ (Limit.apex L) X DM.≅ Limit.apex L′ project-iso = record { from = ai.from D.∘ from.η X ; to = to.η X D.∘ ai.to ; iso = Iso-∘ (record { isoˡ = isoˡ ; isoʳ = isoʳ }) ai.iso } where open _≅_ apex-iso module from = NaturalTransformation from module to = NaturalTransformation to module ai = DM._≅_ apex-iso′ Functors-Complete : Complete o″ ℓ″ e″ D^C Functors-Complete F = complete F evalF-Continuous : ∀ X → Continuous o″ ℓ″ e″ (evalF C D X) evalF-Continuous X {J} {F} L = Com (evalF C D X ∘F F) , project-iso F L X
34.307692
107
0.481591
37c3fe2c621bdeb38f25f58b2a76de826d73567d
6,375
agda
Agda
agda-stdlib/src/Data/Container/Indexed.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Container/Indexed.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Container/Indexed.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Indexed containers aka interaction structures aka polynomial -- functors. The notation and presentation here is closest to that of -- Hancock and Hyvernat in "Programming interfaces and basic topology" -- (2006/9). ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --guardedness #-} module Data.Container.Indexed where open import Level open import Codata.Musical.M.Indexed open import Data.Product as Prod hiding (map) open import Data.W.Indexed open import Function.Base renaming (id to ⟨id⟩; _∘_ to _⟨∘⟩_) open import Function.Equality using (_⟨$⟩_) open import Function.Inverse using (_↔_; module Inverse) open import Relation.Unary using (Pred; _⊆_) import Relation.Binary as B open import Relation.Binary.PropositionalEquality as P using (_≡_; _≗_; refl) ------------------------------------------------------------------------ -- The type and its semantics ("extension"). open import Data.Container.Indexed.Core public open Container public -- Abbreviation for the commonly used level one version of indexed -- containers. _▷_ : Set → Set → Set₁ I ▷ O = Container I O zero zero -- The least and greatest fixpoint. μ ν : ∀ {o c r} {O : Set o} → Container O O c r → Pred O _ μ = W ν = M -- An equivalence relation is defined in Data.Container.Indexed.WithK. ------------------------------------------------------------------------ -- Functoriality -- Indexed containers are functors. map : ∀ {i o c r ℓ₁ ℓ₂} {I : Set i} {O : Set o} (C : Container I O c r) {X : Pred I ℓ₁} {Y : Pred I ℓ₂} → X ⊆ Y → ⟦ C ⟧ X ⊆ ⟦ C ⟧ Y map _ f = Prod.map ⟨id⟩ (λ g → f ⟨∘⟩ g) -- Some properties are proved in Data.Container.Indexed.WithK. ------------------------------------------------------------------------ -- Container morphisms module _ {i₁ i₂ o₁ o₂} {I₁ : Set i₁} {I₂ : Set i₂} {O₁ : Set o₁} {O₂ : Set o₂} where -- General container morphism. record ContainerMorphism {c₁ c₂ r₁ r₂ ℓ₁ ℓ₂} (C₁ : Container I₁ O₁ c₁ r₁) (C₂ : Container I₂ O₂ c₂ r₂) (f : I₁ → I₂) (g : O₁ → O₂) (_∼_ : B.Rel I₂ ℓ₁) (_≈_ : B.REL (Set r₂) (Set r₁) ℓ₂) (_·_ : ∀ {A B} → A ≈ B → A → B) : Set (i₁ ⊔ i₂ ⊔ o₁ ⊔ o₂ ⊔ c₁ ⊔ c₂ ⊔ r₁ ⊔ r₂ ⊔ ℓ₁ ⊔ ℓ₂) where field command : Command C₁ ⊆ Command C₂ ⟨∘⟩ g response : ∀ {o} {c₁ : Command C₁ o} → Response C₂ (command c₁) ≈ Response C₁ c₁ coherent : ∀ {o} {c₁ : Command C₁ o} {r₂ : Response C₂ (command c₁)} → f (next C₁ c₁ (response · r₂)) ∼ next C₂ (command c₁) r₂ open ContainerMorphism public -- Plain container morphism. _⇒[_/_]_ : ∀ {c₁ c₂ r₁ r₂} → Container I₁ O₁ c₁ r₁ → (I₁ → I₂) → (O₁ → O₂) → Container I₂ O₂ c₂ r₂ → Set _ C₁ ⇒[ f / g ] C₂ = ContainerMorphism C₁ C₂ f g _≡_ (λ R₂ R₁ → R₂ → R₁) _$_ -- Linear container morphism. _⊸[_/_]_ : ∀ {c₁ c₂ r₁ r₂} → Container I₁ O₁ c₁ r₁ → (I₁ → I₂) → (O₁ → O₂) → Container I₂ O₂ c₂ r₂ → Set _ C₁ ⊸[ f / g ] C₂ = ContainerMorphism C₁ C₂ f g _≡_ _↔_ (λ r₂↔r₁ r₂ → Inverse.to r₂↔r₁ ⟨$⟩ r₂) -- Cartesian container morphism. _⇒C[_/_]_ : ∀ {c₁ c₂ r} → Container I₁ O₁ c₁ r → (I₁ → I₂) → (O₁ → O₂) → Container I₂ O₂ c₂ r → Set _ C₁ ⇒C[ f / g ] C₂ = ContainerMorphism C₁ C₂ f g _≡_ (λ R₂ R₁ → R₂ ≡ R₁) (λ r₂≡r₁ r₂ → P.subst ⟨id⟩ r₂≡r₁ r₂) -- Degenerate cases where no reindexing is performed. module _ {i o c r} {I : Set i} {O : Set o} where _⇒_ : B.Rel (Container I O c r) _ C₁ ⇒ C₂ = C₁ ⇒[ ⟨id⟩ / ⟨id⟩ ] C₂ _⊸_ : B.Rel (Container I O c r) _ C₁ ⊸ C₂ = C₁ ⊸[ ⟨id⟩ / ⟨id⟩ ] C₂ _⇒C_ : B.Rel (Container I O c r) _ C₁ ⇒C C₂ = C₁ ⇒C[ ⟨id⟩ / ⟨id⟩ ] C₂ ------------------------------------------------------------------------ -- Plain morphisms -- Interpretation of _⇒_. ⟪_⟫ : ∀ {i o c r ℓ} {I : Set i} {O : Set o} {C₁ C₂ : Container I O c r} → C₁ ⇒ C₂ → (X : Pred I ℓ) → ⟦ C₁ ⟧ X ⊆ ⟦ C₂ ⟧ X ⟪ m ⟫ X (c , k) = command m c , λ r₂ → P.subst X (coherent m) (k (response m r₂)) module PlainMorphism {i o c r} {I : Set i} {O : Set o} where -- Identity. id : (C : Container I O c r) → C ⇒ C id _ = record { command = ⟨id⟩ ; response = ⟨id⟩ ; coherent = refl } -- Composition. infixr 9 _∘_ _∘_ : {C₁ C₂ C₃ : Container I O c r} → C₂ ⇒ C₃ → C₁ ⇒ C₂ → C₁ ⇒ C₃ f ∘ g = record { command = command f ⟨∘⟩ command g ; response = response g ⟨∘⟩ response f ; coherent = coherent g ⟨ P.trans ⟩ coherent f } -- Identity commutes with ⟪_⟫. id-correct : ∀ {ℓ} {C : Container I O c r} → ∀ {X : Pred I ℓ} {o} → ⟪ id C ⟫ X {o} ≗ ⟨id⟩ id-correct _ = refl -- More properties are proved in Data.Container.Indexed.WithK. ------------------------------------------------------------------------ -- Linear container morphisms module LinearMorphism {i o c r} {I : Set i} {O : Set o} {C₁ C₂ : Container I O c r} (m : C₁ ⊸ C₂) where morphism : C₁ ⇒ C₂ morphism = record { command = command m ; response = _⟨$⟩_ (Inverse.to (response m)) ; coherent = coherent m } ⟪_⟫⊸ : ∀ {ℓ} (X : Pred I ℓ) → ⟦ C₁ ⟧ X ⊆ ⟦ C₂ ⟧ X ⟪_⟫⊸ = ⟪ morphism ⟫ open LinearMorphism public using (⟪_⟫⊸) ------------------------------------------------------------------------ -- Cartesian morphisms module CartesianMorphism {i o c r} {I : Set i} {O : Set o} {C₁ C₂ : Container I O c r} (m : C₁ ⇒C C₂) where morphism : C₁ ⇒ C₂ morphism = record { command = command m ; response = P.subst ⟨id⟩ (response m) ; coherent = coherent m } ⟪_⟫C : ∀ {ℓ} (X : Pred I ℓ) → ⟦ C₁ ⟧ X ⊆ ⟦ C₂ ⟧ X ⟪_⟫C = ⟪ morphism ⟫ open CartesianMorphism public using (⟪_⟫C) ------------------------------------------------------------------------ -- All and any -- □ and ◇ are defined in the core module. module _ {i o c r ℓ₁ ℓ₂} {I : Set i} {O : Set o} (C : Container I O c r) {X : Pred I ℓ₁} {P Q : Pred (Σ I X) ℓ₂} where -- All. □-map : P ⊆ Q → □ C P ⊆ □ C Q □-map P⊆Q = _⟨∘⟩_ P⊆Q -- Any. ◇-map : P ⊆ Q → ◇ C P ⊆ ◇ C Q ◇-map P⊆Q = Prod.map ⟨id⟩ P⊆Q -- Membership is defined in Data.Container.Indexed.WithK.
29.37788
77
0.502118
fd8657e7bdf36f4b0607b6baacbaad737b5300f7
406
agda
Agda
Groups/Abelian/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Groups/Abelian/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Groups/Abelian/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import Setoids.Setoids open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Groups.Definition module Groups.Abelian.Definition where record AbelianGroup {a} {b} {A : Set a} {S : Setoid {a} {b} A} {_·_ : A → A → A} (G : Group S _·_) : Set (lsuc a ⊔ b) where open Setoid S field commutative : {a b : A} → (a · b) ∼ (b · a)
31.230769
123
0.630542
1b399f27ebc5ca1b7e3f7facc8e663cd46355bc4
4,223
agda
Agda
test/asset/agda-stdlib-1.0/Data/Table/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Table/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Table/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Table-related properties ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Table.Properties where open import Data.Table open import Data.Table.Relation.Binary.Equality open import Data.Bool using (true; false; if_then_else_) open import Data.Nat using (zero; suc) open import Data.Empty using (⊥-elim) open import Data.Fin using (Fin; suc; zero; _≟_; punchIn) import Data.Fin.Properties as FP open import Data.Fin.Permutation as Perm using (Permutation; _⟨$⟩ʳ_; _⟨$⟩ˡ_) open import Data.List as L using (List; _∷_; []) open import Data.List.Relation.Unary.Any using (here; there; index) open import Data.List.Membership.Propositional using (_∈_) open import Data.Product as Product using (Σ; ∃; _,_; proj₁; proj₂) open import Data.Vec as V using (Vec; _∷_; []) import Data.Vec.Properties as VP open import Function using (_∘_; flip) open import Function.Inverse using (Inverse) open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; refl; sym; cong) open import Relation.Nullary using (yes; no) open import Relation.Nullary.Negation using (contradiction) ------------------------------------------------------------------------ -- select module _ {a} {A : Set a} where -- Selecting from any table is the same as selecting from a constant table. select-const : ∀ {n} (z : A) (i : Fin n) t → select z i t ≗ select z i (replicate (lookup t i)) select-const z i t j with j ≟ i ... | yes _ = refl ... | no _ = refl -- Selecting an element from a table then looking it up is the same as looking -- up the index in the original table select-lookup : ∀ {n x i} (t : Table A n) → lookup (select x i t) i ≡ lookup t i select-lookup {i = i} t with i ≟ i ... | yes _ = refl ... | no i≢i = contradiction refl i≢i -- Selecting an element from a table then removing the same element produces a -- constant table select-remove : ∀ {n x} i (t : Table A (suc n)) → remove i (select x i t) ≗ replicate {n = n} x select-remove i t j with punchIn i j ≟ i ... | yes p = contradiction p (FP.punchInᵢ≢i _ _) ... | no ¬p = refl ------------------------------------------------------------------------ -- permute -- Removing an index 'i' from a table permuted with 'π' is the same as -- removing the element, then permuting with 'π' minus 'i'. remove-permute : ∀ {m n} (π : Permutation (suc m) (suc n)) i (t : Table A (suc n)) → remove (π ⟨$⟩ˡ i) (permute π t) ≗ permute (Perm.remove (π ⟨$⟩ˡ i) π) (remove i t) remove-permute π i t j = P.cong (lookup t) (Perm.punchIn-permute′ π i j) ------------------------------------------------------------------------ -- fromList module _ {a} {A : Set a} where fromList-∈ : ∀ {xs : List A} (i : Fin (L.length xs)) → lookup (fromList xs) i ∈ xs fromList-∈ {[]} () fromList-∈ {x ∷ xs} zero = here refl fromList-∈ {x ∷ xs} (suc i) = there (fromList-∈ i) index-fromList-∈ : ∀ {xs i} → index (fromList-∈ {xs} i) ≡ i index-fromList-∈ {[]} {()} index-fromList-∈ {x ∷ xs} {zero} = refl index-fromList-∈ {x ∷ xs} {suc i} = cong suc index-fromList-∈ fromList-index : ∀ {xs} {x : A} (x∈xs : x ∈ xs) → lookup (fromList xs) (index x∈xs) ≡ x fromList-index (here px) = sym px fromList-index (there x∈xs) = fromList-index x∈xs ------------------------------------------------------------------------ -- There exists an isomorphism between tables and vectors. module _ {a n} {A : Set a} where ↔Vec : Inverse (≡-setoid A n) (P.setoid (Vec A n)) ↔Vec = record { to = record { _⟨$⟩_ = toVec ; cong = VP.tabulate-cong } ; from = P.→-to-⟶ fromVec ; inverse-of = record { left-inverse-of = VP.lookup∘tabulate ∘ lookup ; right-inverse-of = VP.tabulate∘lookup } } ------------------------------------------------------------------------ -- Other module _ {a} {A : Set a} where lookup∈ : ∀ {xs : List A} (i : Fin (L.length xs)) → ∃ λ x → x ∈ xs lookup∈ i = _ , fromList-∈ i
35.191667
89
0.542979
fdc21dd616b081ad1e600072502c2076620baa98
1,830
agda
Agda
test/Succeed/SizedNatNew.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/SizedNatNew.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/SizedNatNew.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- {-# OPTIONS --sized-types --show-implicit #-} module _ where open import Common.Size data Either (A B : Set) : Set where left : A → Either A B right : B → Either A B caseEither : ∀{A B C : Set} → Either A B → (A → C) → (B → C) → C caseEither (left a) l r = l a caseEither (right b) l r = r b data Nat {i : Size} : Set where zero : Nat suc : {i' : Size< i} → Nat {i'} → Nat -- subtraction is non size increasing sub : {size : Size} → Nat {size} → Nat {∞} → Nat {size} sub zero n = zero sub (suc m) zero = suc m sub (suc m) (suc n) = sub m n -- div' m n computes ceiling(m/(n+1)) div' : {size : Size} → Nat {size} → Nat → Nat {size} div' zero n = zero div' (suc m) n = suc (div' (sub m n) n) -- one can use sized types as if they were not sized -- sizes default to ∞ add : Nat → Nat → Nat add (zero ) n = n add (suc m) n = suc (add m n) nisse : {i : Size} → Nat {i} → Nat {i} nisse zero = zero nisse (suc zero) = suc zero nisse (suc (suc n)) = suc zero -- symmetric difference -- @diff n m@ returns @left (n - m)@ if @n@ is bigger, otherwise @right (m - n)@ diff : ∀{i j} → Nat {i} → Nat {j} → Either (Nat {i}) (Nat {j}) diff zero m = right m diff (suc n) zero = left (suc n) diff (suc n) (suc m) = diff n m module Case where gcd : ∀{i j} → Nat {i} → Nat {j} → Nat gcd zero m = m gcd (suc n) zero = suc n gcd (suc n) (suc m) = caseEither (diff n m) (λ n' → gcd n' (suc m)) (λ m' → gcd (suc n) m') module With where gcd : ∀{i j} → Nat {i} → Nat {j} → Nat gcd zero m = m gcd (suc n) zero = suc n gcd (suc n) (suc m) with diff n m ... | left n' = gcd n' (suc m) ... | right m' = gcd (suc n) m' NatInfty = Nat {∞} {-# BUILTIN NATURAL NatInfty #-} -- {-# BUILTIN NATPLUS add #-} -- not accepted
24.4
80
0.53388
43238f6610951cbe639a7b8863bd9e148a7f45c0
99
agda
Agda
test/tests/assets/GotoDefinition.agda
EdNutting/agda-mode-vscode
7628c254e87374a924a781cf15ea3abd715fd2d3
[ "MIT" ]
98
2020-05-29T07:46:51.000Z
2022-03-18T09:35:55.000Z
test/tests/assets/GotoDefinition.agda
Code-distancing/agda-mode-vscode
7628c254e87374a924a781cf15ea3abd715fd2d3
[ "MIT" ]
84
2020-06-03T13:16:16.000Z
2022-03-26T11:43:19.000Z
test/tests/assets/GotoDefinition.agda
Code-distancing/agda-mode-vscode
7628c254e87374a924a781cf15ea3abd715fd2d3
[ "MIT" ]
22
2020-05-29T12:07:13.000Z
2022-03-15T11:37:47.000Z
module GotoDefinition where data ℕ : Set where Z : ℕ S : ℕ → ℕ _+_ : ℕ → ℕ → ℕ x + y = {! !}
14.142857
27
0.505051
19a8a25724487f2160f1a039e860666c860c1c68
618
agda
Agda
demo/agda/FRP/JS/Demo/Geolocation.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
63
2015-04-20T21:47:00.000Z
2022-02-28T09:46:14.000Z
demo/agda/FRP/JS/Demo/Geolocation.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
null
null
null
demo/agda/FRP/JS/Demo/Geolocation.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
7
2016-11-07T21:50:58.000Z
2022-03-12T11:39:38.000Z
open import FRP.JS.Behaviour using ( Beh ; map ; [_] ) open import FRP.JS.DOM using ( DOM ; text ; _++_ ) open import FRP.JS.RSet using ( ⟦_⟧ ) open import FRP.JS.Maybe using ( Maybe ; just ; nothing ) open import FRP.JS.String using ( String ) open import FRP.JS.Geolocation using ( geolocation ) open import FRP.JS.Geolocation.Coords using ( Coords ; toString ) module FRP.JS.Demo.Geolocation where show : Maybe Coords → String show nothing = "unknown" show (just coords) = toString coords main : ∀ {w} → ⟦ Beh (DOM w) ⟧ main = text ["Current location: "] ++ text (map show geolocation) ++ text ["."]
32.526316
65
0.676375
370dc712a9c8c14c45094a8eb263e146e68ab246
1,826
agda
Agda
test/Fail/Issue5891.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Fail/Issue5891.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Fail/Issue5891.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
-- AIM XXXV, 2022-05-06, issue #5891: -- SizeUniv : SizeUniv was causing non-termination and inhabitation of Size< 0. -- This is inconsistent; proof by Jonathan Chan. {-# OPTIONS --sized-types #-} open import Agda.Primitive open import Agda.Builtin.Size data ⊥ : Set where -- Original exploit: -- data False : SizeUniv where False : SizeUniv False = (X : SizeUniv) → X -- Should fail. -- Expected error: -- Setω != SizeUniv -- when checking that the expression (X : SizeUniv) → X has type SizeUniv -- Step 1: Hurken's Paradox with SizeUniv : SizeUniv. ℘ : SizeUniv → SizeUniv ℘ S = S → SizeUniv U : SizeUniv U = ∀ (X : SizeUniv) → (℘ (℘ X) → X) → ℘ (℘ X) τ : ℘ (℘ U) → U τ t = λ X f p → t (λ x → p (f (x X f))) σ : U → ℘ (℘ U) σ s = s U τ Δ : ℘ U Δ y = (∀ p → σ y p → p (τ (σ y))) → False Ω : U Ω = τ (λ p → (∀ x → σ x p → p x)) R : ∀ p → (∀ x → σ x p → p x) → p Ω R _ 𝟙 = 𝟙 Ω (λ x → 𝟙 (τ (σ x))) M : ∀ x → σ x Δ → Δ x M _ 𝟚 𝟛 = 𝟛 Δ 𝟚 (λ p → 𝟛 (λ y → p (τ (σ y)))) L : (∀ p → (∀ x → σ x p → p x) → p Ω) → False L 𝟘 = 𝟘 Δ M (λ p → 𝟘 (λ y → p (τ (σ y)))) -- Prevent unfolding, as this term has no whnf. -- Stops Agda from looping. abstract false : False false = L R -- This gives us a predecessor on Size. size-pred : ∀ i → Size< i size-pred i = false (Size< i) -- Step 2: Size predecessor is inconsistent. -- Jonathan Chan: -- I managed to do so using ∞ but only because it's the only closed -- size expression, not using the ∞ < ∞ property, although the -- principle is the same as for #3026: data _>_ (s : Size) : Size → Set where lt : (r : Size< s) → s > r data Acc (s : Size) : Set where acc : (∀ {r} → s > r → Acc r) → Acc s wf : ∀ s → Acc s wf s = acc λ{ (lt r) → wf r } ¬wf : ∀ s → Acc s → ⊥ ¬wf s (acc p) = ¬wf (size-pred s) (p (lt (size-pred s))) absurd : ⊥ absurd = (¬wf ∞) (wf ∞)
21.232558
79
0.556407
7c93b93f4bda6a98141cc8fd48f41532e4269051
3,115
agda
Agda
Control/Comonad/IntervalHeap.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Control/Comonad/IntervalHeap.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Control/Comonad/IntervalHeap.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe --postfix-projections --guardedness #-} open import Algebra open import Prelude open import Relation.Binary open import WellFounded open import Algebra.Monus open import Data.Maybe module Control.Comonad.IntervalHeap {s} (mon : TMAPOM s) (wf : WellFounded (TMAPOM._<_ mon)) (cancel : Cancellativeˡ (TMAPOM._∙_ mon)) where open TMAPOM mon mutual record Heap (A : Type a) : Type (s ℓ⊔ a) where inductive; constructor _◃_ field hd : A tl : Next A record Next {a} (A : Type a) : Type (s ℓ⊔ a) where coinductive; constructor ⟪_⟫ field next : Span A data Span {a} (A : Type a) : Type (s ℓ⊔ a) where [] : Span A until : (s : 𝑆) → (s≢ε : s ≢ ε) → (xs : Heap A) → Span A open Heap public open Next public State : Type a → Type _ State A = 𝑆 → A × 𝑆 pop′ : (s : 𝑆) → Acc _<_ s → Heap A → A × 𝑆 pop′ s₂ a xs with xs .tl .next pop′ s₂ a xs | [] = xs .hd , ε pop′ s₂ a xs | until s₁ s₁≢ε ys with s₁ ≤? s₂ pop′ s₂ a xs | until s₁ s₁≢ε ys | no s₁≰s₂ = xs .hd , fst (<⇒≤ s₁≰s₂) pop′ s₂ (acc wf) xs | until s₁ s₁≢ε ys | yes (k₁ , s₂≡s₁∙k₁) = pop′ k₁ (wf k₁ lemma) ys where lemma : k₁ < s₂ lemma (k₂ , k₁≡s₂∙k₂) = s₁≢ε (zeroSumFree s₁ k₂ (sym (cancel k₁ _ _ p))) where p : k₁ ∙ ε ≡ k₁ ∙ (s₁ ∙ k₂) p = ∙ε k₁ ; k₁≡s₂∙k₂ ; cong (_∙ k₂) s₂≡s₁∙k₁ ; cong (_∙ k₂) (comm s₁ k₁) ; assoc k₁ s₁ k₂ pop : Heap A → State A pop xs s = pop′ s (wf s) xs mutual stepFrom : State A → (s : 𝑆) → Dec (s ≡ ε) → Span A stepFrom f s (yes p) = [] stepFrom f s (no ¬p) = until s ¬p (tabulate (f ∘ (s ∙_))) tabulate : State A → Heap A tabulate f = let x , s = f ε in x ◃ λ where .next → stepFrom f s (s ≟ ε) pop-ε : (xs : Heap A) (a : Acc _<_ ε) → pop′ ε a xs .fst ≡ xs .hd pop-ε xs _ with xs .tl .next pop-ε xs _ | [] = refl pop-ε xs _ | until s s≢ε ys with s ≤? ε pop-ε xs _ | until s s≢ε ys | no s≰ε = refl pop-ε xs _ | until s s≢ε ys | yes s≤ε = ⊥-elim (s≢ε (antisym s≤ε (positive s))) -- slide : Heap A → Heap A -- slide xs with xs .tl .next -- slide xs | [] = xs -- slide xs | [] = [] -- pop-tl : ∀ (x : A) s₁ (s₁≢ε : s₁ ≢ ε) xs s₂ → pop (x ◃ ⟪ until s₁ s₁≢ε xs ⟫) (s₁ ∙ s₂) ≡ pop xs s₂ -- pop-tl x s₁ s₁≢ε xs s₂ with s₁ ≤? (s₁ ∙ s₂) -- pop-tl x s₁ s₁≢ε xs s₂ | no s₁≰s₁∙s₂ = ⊥-elim (s₁≰s₁∙s₂ (s₂ , refl)) -- pop-tl x s₁ s₁≢ε xs s₂ | yes (k , s₁≤s₁∙s₂) = -- let p = cancel s₁ s₂ k s₁≤s₁∙s₂ -- in {!!} ; cong (λ w → pop′ s₂ w xs) (isPropAcc {!!} (wf s₂)) -- seg-leftInv′ : (x : Heap A) → tabulate (pop x) ≡ x -- seg-leftInv′ x = {!!} -- mutual -- seg-leftInv′ : (xs : Heap A) → stepFrom (pop xs) (pop xs ε .snd) (pop xs ε .snd ≟ ε) ≡ xs .tl .next -- seg-leftInv′ (x ◃ xs) with pop (x ◃ xs) ε .snd ≟ ε -- seg-leftInv′ (x ◃ xs) | yes s≡ε = {!!} -- seg-leftInv′ (x ◃ xs) | no s≢ε = {!!} -- seg-leftInv : (x : Heap A) → tabulate (pop x) ≡ x -- seg-leftInv (x ◃ xs) i .hd = pop-ε (x ◃ xs) (wf ε) i -- seg-leftInv (x ◃ xs) i .tl .next = seg-leftInv′ (x ◃ xs) i -- state-iso : Heap A ⇔ State A -- state-iso .fun = pop -- state-iso .inv = tabulate -- state-iso .rightInv = {!!} -- state-iso .leftInv = {!!}
30.841584
104
0.549599
7c71c8f99af71397eccfcb44fefe1b7d28dec256
5,929
agda
Agda
test/epic/Prelude/File.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/epic/Prelude/File.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/epic/Prelude/File.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{- An adaptation of Edwin Brady and Kevin Hammond's paper Scrapping your inefficient engine ... -} {-# OPTIONS --type-in-type #-} module File where open import Bool open import Bot open import IO open import Fin open import Eq open import Nat open import Product open import String open import Unit open import Vec data Ty : Set where TyUnit : Ty TyBool : Ty TyLift : Set -> Ty TyHandle : Nat -> Ty interpTy : Ty -> Set interpTy TyUnit = Unit interpTy TyBool = Bool interpTy (TyLift A) = A interpTy (TyHandle n) = Fin n data Purpose : Set where Reading : Purpose Writing : Purpose getMode : Purpose -> String getMode Reading = "r" getMode Writing = "w" data FileState : Set where Open : Purpose -> FileState Closed : FileState postulate EpicFile : Set FileVec : Nat -> Set FileVec n = Vec FileState n data FileHandle : FileState -> Set where OpenFile : ∀{p} -> EpicFile -> FileHandle (Open p) ClosedFile : FileHandle Closed data Env : ∀{n} -> FileVec n -> Set where Empty : Env [] Extend : {n : Nat}{T : FileState}{G : FileVec n} -> (res : FileHandle T) -> Env G -> Env (T :: G) addEnd : ∀{n T}{G : FileVec n} -> Env G -> FileHandle T -> Env (snoc G T) addEnd Empty fh = Extend fh Empty addEnd (Extend x xs) fh = Extend x (addEnd xs fh) updateEnv : ∀{n T}{G : FileVec n} -> Env G -> (i : Fin n) -> (fh : FileHandle T) -> Env (G [ i ]= T) updateEnv (Extend x xs) fz e = Extend e xs updateEnv (Extend x xs) (fs n) e = Extend x (updateEnv xs n e) updateEnv Empty () e bound : ∀{n : Nat} -> Fin (S n) bound {Z} = fz bound {S n} = fs (bound {n}) data OpenH : ∀{n} -> Fin n -> Purpose -> FileVec n -> Set where nil : ∀{p n}{as : FileVec n} -> OpenH fz p (Open p :: as) suc : ∀{p n a}{as : FileVec n}{i : Fin n} -> OpenH i p as -> OpenH (fs i) p (a :: as) getFile : ∀{n}{i : Fin n}{p : Purpose}{ts : FileVec n} -> OpenH i p ts -> Env ts -> EpicFile getFile nil (Extend (OpenFile f) env) = f getFile (suc p) (Extend _ env) = getFile p env getPurpose : {n : Nat} -> Fin n -> FileVec n -> Purpose getPurpose f ts with ts ! f ... | Open p = p ... | Closed = Reading -- Should not happen right? FilePath : Set FilePath = String data File : ∀{n n'} -> FileVec n -> FileVec n' -> Ty -> Set where ACTION : ∀{a l}{ts : FileVec l} -> IO (interpTy a) -> File ts ts a RETURN : ∀{a l}{ts : FileVec l} -> interpTy a -> File ts ts a WHILE : ∀{l}{ts : FileVec l} -> File ts ts TyBool -> File ts ts TyUnit -> File ts ts TyUnit IF : ∀{a l}{ts : FileVec l} -> Bool -> File ts ts a -> File ts ts a -> File ts ts a BIND : ∀{a b l l' l''}{ts : FileVec l}{ts' : FileVec l'}{ts'' : FileVec l''} -> File ts ts' a -> (interpTy a -> File ts' ts'' b) -> File ts ts'' b OPEN : ∀{l}{ts : FileVec l} -> (p : Purpose) -> (fd : FilePath) -> File ts (snoc ts (Open p)) (TyHandle (S l)) CLOSE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> (OpenH i (getPurpose i ts) ts) -> File ts (ts [ i ]= Closed) TyUnit GETLINE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> (p : OpenH i Reading ts) -> File ts ts (TyLift String) EOF : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> (p : OpenH i Reading ts) -> File ts ts TyBool PUTLINE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> (str : String) -> (p : OpenH i Writing ts) -> File ts ts TyUnit postulate while : IO Bool -> IO Unit -> IO Unit fopen : FilePath -> String -> IO EpicFile fclose : EpicFile -> IO Unit fread : EpicFile -> IO String feof : EpicFile -> IO Bool fwrite : EpicFile -> String -> IO Unit {-# COMPILED_EPIC while (add : Any, body : Any, u : Unit) -> Any = %while (add(u), body(u)) #-} {-# COMPILED_EPIC fopen (fp : String, mode : String, u : Unit) -> Ptr = foreign Ptr "fopen" (fp : String, mode : String) #-} {-# COMPILED_EPIC fclose (file : Ptr, u : Unit) -> Unit = foreign Int "fclose" (file : Ptr); unit #-} {-# COMPILED_EPIC fread (file : Ptr, u : Unit) -> Any = foreign Any "freadStr" (file : Ptr) #-} {-# COMPILED_EPIC feof (file : Ptr, u : Unit) -> Bool = foreign Int "feof" (file : Ptr) #-} {-# COMPILED_EPIC fwrite (file : Ptr, str : String, u : Unit) -> Unit = foreign Unit "fputStr" (file : Ptr, str : String) #-} fmap : {A B : Set} -> (A -> B) -> IO A -> IO B fmap f io = x <- io , return (f x) interp : ∀{n n' T}{ts : FileVec n}{ts' : FileVec n'} -> Env ts -> File ts ts' T -> IO (Env ts' × interpTy T) interp env (ACTION io) = fmap (_,_ env) io interp env (RETURN val) = return (env , val) interp env (WHILE add body) = while (fmap snd (interp env add)) (fmap snd (interp env body)) ,, return (env , unit) interp env (IF b t f) = if b then interp env t else interp env f interp env (BIND code k) = v <- interp env code , interp (fst v) (k (snd v)) interp env (OPEN p fpath) = fh <- fopen fpath (getMode p), return (addEnd env (OpenFile fh), bound) interp env (CLOSE i p) = fclose (getFile p env) ,, return (updateEnv env i ClosedFile , unit) interp env (GETLINE i p) = fmap (_,_ env) (fread (getFile p env)) interp env (EOF i p) = e <- feof (getFile p env) , return (env , e) interp env (PUTLINE i str p) = fmap (_,_ env) (fwrite (getFile p env) str ,, fwrite (getFile p env) "\n") printBool : Bool -> IO Unit printBool b = putStr (if b then "true" else "false") allClosed : (n : Nat) -> FileVec n allClosed Z = [] allClosed (S n) = Closed :: allClosed n cat : File [] (Closed :: []) TyUnit cat = BIND (OPEN Reading "hej") cont where cont : Fin 1 -> File (Open Reading :: []) (Closed :: []) TyUnit cont (fs ()) cont fz = BIND (WHILE (BIND (EOF fz nil) (\b -> RETURN (not b))) (BIND (GETLINE fz nil) (\str -> ACTION (putStrLn str)) ) ) (λ x → CLOSE fz nil) main : IO Unit main = fmap snd (interp Empty cat)
36.152439
126
0.576488
d1893206262ff42db0b49dd1af9b6ebba3dc227f
891
agda
Agda
test/Succeed/LineEndings/LexASCII.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/LineEndings/LexASCII.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/LineEndings/LexASCII.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- All 256 ASCII characters module LineEndings.LexASCII where {- In Block comment: Control characters 0-31   Rest of 7-bit ASCII !"#$%&'()*+,-./0123456789:;<=>? @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ `abcdefghijklmnopqrstuvwxyz{|}~ 8-Bit ASCII €‚ƒ„…†‡ ˆ‰Š‹ŒŽ ‘’“”•–— ˜™š›œžŸ  ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ -} -- In line comments --  -- --  -- !"#$%&'()*+,-./0123456789:;<=>? -- @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ -- `abcdefghijklmnopqrstuvwxyz{|}~ -- €‚ƒ„ -- Note: Agda translates the following character (decimal: 133 xd: x85) -- into a new line, see function convertLineEndings. -- … -- †‡ -- ˆ‰Š‹ŒŽ -- ‘’“”•–— -- ˜™š›œžŸ --  ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ -- ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß -- àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ -- -}
15.362069
71
0.545455
2ee133b4ac50973972be1f78b4a3a31291d02746
36
agda
Agda
src/Generics/Mu/Conversion.agda
flupe/generics
db764f858d908aa39ea4901669a6bbce1525f757
[ "MIT" ]
11
2021-04-08T15:10:20.000Z
2022-02-05T09:35:17.000Z
src/Generics/Mu/Conversion.agda
flupe/generics
db764f858d908aa39ea4901669a6bbce1525f757
[ "MIT" ]
4
2021-09-13T07:33:50.000Z
2022-01-14T10:48:30.000Z
src/Generics/Mu/Conversion.agda
flupe/generics
db764f858d908aa39ea4901669a6bbce1525f757
[ "MIT" ]
3
2021-04-08T08:32:42.000Z
2022-01-14T10:35:16.000Z
module Generics.Mu.Conversion where
18
35
0.861111
0dd49c7af1a9fcf296cd396f15174030f5c79f78
273
agda
Agda
test/Fail/NonUniqueInstance1.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/NonUniqueInstance1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/NonUniqueInstance1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Common.Prelude hiding (tt) instance tt : ⊤ tt = record{} NonZero : Nat → Set NonZero zero = ⊥ NonZero (suc _) = ⊤ pred′ : (n : Nat) {{_ : NonZero n}} → Nat pred′ zero {{}} pred′ (suc n) = n test : (n : Nat) {{x y : NonZero n}} → Nat test n = pred′ n
16.058824
42
0.556777
37fea119c1eb7de4bf2d50dd705999ec5bc6ae9a
2,147
agda
Agda
LibraBFT/Impl/Handle/InitProperties.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
4
2020-12-16T19:43:41.000Z
2021-12-18T19:24:05.000Z
LibraBFT/Impl/Handle/InitProperties.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
72
2021-02-04T05:04:33.000Z
2022-03-25T05:36:11.000Z
LibraBFT/Impl/Handle/InitProperties.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
6
2020-12-16T19:43:52.000Z
2022-02-18T01:04:32.000Z
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Impl.Consensus.EpochManagerTypes open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Interface.Output open import LibraBFT.ImplShared.Util.Dijkstra.EitherD import LibraBFT.Impl.Properties.Util as Util open import LibraBFT.Prelude open import Optics.All module LibraBFT.Impl.Handle.InitProperties where module initHandlerSpec (pid : Author) (bsi : BootstrapInfo) where import LibraBFT.Yasm.Types as LYT record ContractOk (rm : RoundManager) (acts : List (LYT.Action NetworkMsg)) : Set where constructor mkContractOk field rmInv : Util.Invariants.RoundManagerInv rm sigs∈bs : ∀ {vs qc} → vs ∈ qcVotes qc → qc Util.QCProps.∈RoundManager rm → ∈BootstrapInfo-impl bsi (proj₂ vs) -- During epoch initialisation, no messages are sent -- EXCEPT the leader of Round 1 SENDS a ProposalMsg during initialization. -- Rust/Haskell impls do not include signatures in the genesis QC's LIWS. -- The initial proposal for (Epoch N) (Round 1) is built on a QC with empty signatures. isInitPM : ∀ {m} → LYT.send m ∈ acts → ∃[ pm ] ( m ≡ P pm × ∀ {vs qc} → vs ∈ qcVotes qc → qc QC∈NM m → ⊥) sdLVNothing : rm ^∙ rmSafetyRules ∙ srPersistentStorage ∙ pssSafetyData ∙ sdLastVote ≡ nothing Contract : Maybe (RoundManager × List (LYT.Action NetworkMsg)) → Set Contract nothing = ⊤ Contract (just (rm , acts)) = ContractOk rm acts import LibraBFT.Impl.Handle as Handle open Handle.InitHandler postulate contract : ∀ {x} → initHandler pid bsi ≡ x → Contract x -- contract = EitherD-contract {!!} Contract contract'
37.666667
111
0.632045
03fae44ca65fd5709e84b994e88f7f22798180c2
4,961
agda
Agda
Cubical/Codata/Conat/Properties.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Codata/Conat/Properties.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Codata/Conat/Properties.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{- Conatural number properties (Tesla Ice Zhang et al., Feb. 2019) This file defines operations and properties on conatural numbers: - Infinity (∞). - Proof that ∞ + 1 is equivalent to ∞. - Proof that conatural is an hSet. - Bisimulation on conatural - Proof that bisimulation is equivalent to equivalence (Coinductive Proof Principle). - Proof that this bisimulation is prop valued The standard library also defines bisimulation on conaturals: https://github.com/agda/agda-stdlib/blob/master/src/Codata/Conat/Bisimilarity.agda -} {-# OPTIONS --cubical --no-import-sorts --safe --guardedness #-} module Cubical.Codata.Conat.Properties where open import Cubical.Data.Unit open import Cubical.Data.Sum open import Cubical.Data.Empty as ⊥ open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Path open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Relation.Nullary open import Cubical.Codata.Conat.Base Unwrap-prev : Conat′ → Type₀ Unwrap-prev zero = Unit Unwrap-prev (suc _) = Conat unwrap-prev : (n : Conat′) -> Unwrap-prev n unwrap-prev zero = _ unwrap-prev (suc x) = x private -- tests 𝟘 = conat zero 𝟙 = succ 𝟘 𝟚 = succ 𝟙 succ𝟙≡𝟚 : succ 𝟙 ≡ 𝟚 succ𝟙≡𝟚 i = 𝟚 pred𝟚≡𝟙 : unwrap-prev (force 𝟚) ≡ 𝟙 pred𝟚≡𝟙 i = 𝟙 ∞ : Conat force ∞ = suc ∞ ∞+1≡∞ : succ ∞ ≡ ∞ force (∞+1≡∞ _) = suc ∞ ∞+2≡∞ : succ (succ ∞) ≡ ∞ ∞+2≡∞ = (cong succ ∞+1≡∞) ∙ ∞+1≡∞ _+_ : Conat → Conat → Conat _+′_ : Conat′ → Conat → Conat′ force (x + y) = force x +′ y zero +′ y = force y suc x +′ y = suc (x + y) n+∞≡∞ : ∀ n → n + ∞ ≡ ∞ n+′∞≡∞′ : ∀ n → n +′ ∞ ≡ suc ∞ force (n+∞≡∞ n i) = n+′∞≡∞′ (force n) i n+′∞≡∞′ zero = refl n+′∞≡∞′ (suc n) = λ i → suc (n+∞≡∞ n i) ∞+∞≡∞ : ∞ + ∞ ≡ ∞ force (∞+∞≡∞ i) = suc (∞+∞≡∞ i) +-zeroˡ : ∀ n → 𝟘 + n ≡ n force (+-zeroˡ n _) = force n +-zeroʳ : ∀ n → n + 𝟘 ≡ n +′-zeroʳ : ∀ n → n +′ 𝟘 ≡ n force (+-zeroʳ n i) = +′-zeroʳ (force n) i +′-zeroʳ zero _ = zero +′-zeroʳ (suc n) i = suc (+-zeroʳ n i) +-assoc : ∀ m n p → (m + n) + p ≡ m + (n + p) +′-assoc : ∀ m n p → (m +′ n) +′ p ≡ m +′ (n + p) force (+-assoc m n p i) = +′-assoc (force m) n p i +′-assoc zero _ _ = refl +′-assoc (suc m) n p i = suc (+-assoc m n p i) conat-absurd : ∀ {y : Conat} {ℓ} {Whatever : Type ℓ} → zero ≡ suc y → Whatever conat-absurd eq = ⊥.rec (transport (cong diag eq) tt) where diag : Conat′ → Type₀ diag zero = Unit diag (suc _) = ⊥ module IsSet where ≡-stable : {x y : Conat} → Stable (x ≡ y) ≡′-stable : {x y : Conat′} → Stable (x ≡ y) force (≡-stable ¬¬p i) = ≡′-stable (λ ¬p → ¬¬p (λ p → ¬p (cong force p))) i ≡′-stable {zero} {zero} ¬¬p′ = refl ≡′-stable {suc x} {suc y} ¬¬p′ = cong′ suc (≡-stable λ ¬p → ¬¬p′ λ p → ¬p (cong pred′′ p)) ≡′-stable {zero} {suc y} ¬¬p′ = ⊥.rec (¬¬p′ conat-absurd) ≡′-stable {suc x} {zero} ¬¬p′ = ⊥.rec (¬¬p′ λ p → conat-absurd (sym p)) isSetConat : isSet Conat isSetConat _ _ = Separated→isSet (λ _ _ → ≡-stable) _ _ isSetConat′ : isSet Conat′ isSetConat′ m n p′ q′ = cong (cong force) (isSetConat (conat m) (conat n) p q) where p = λ where i .force → p′ i q = λ where i .force → q′ i module Bisimulation where open IsSet using (isSetConat) record _≈_ (x y : Conat) : Type₀ data _≈′_ (x y : Conat′) : Type₀ _≈′′_ : Conat′ → Conat′ → Type₀ zero ≈′′ zero = Unit suc x ≈′′ suc y = x ≈ y -- So impossible proofs are preserved x ≈′′ y = ⊥ record _≈_ x y where coinductive field prove : force x ≈′ force y data _≈′_ x y where con : x ≈′′ y → x ≈′ y open _≈_ public bisim : ∀ {x y} → x ≈ y → x ≡ y bisim′ : ∀ {x y} → x ≈′ y → x ≡ y bisim′ {zero} {zero} (con tt) = refl bisim′ {zero} {suc x} (con ()) bisim′ {suc x} {zero} (con ()) bisim′ {suc x} {suc y} (con eq) i = suc (bisim eq i) force (bisim eq i) = bisim′ (prove eq) i misib : ∀ {x y} → x ≡ y → x ≈ y misib′ : ∀ {x y} → x ≡ y → x ≈′ y misib′ {zero} {zero} _ = con tt misib′ {zero} {suc x} = conat-absurd misib′ {suc x} {zero} p = conat-absurd (sym p) -- misib′ {suc x} {suc y} p = con λ where .prove → misib′ (cong pred′ p) misib′ {suc x} {suc y} p = con (misib (cong pred′′ p)) prove (misib x≡y) = misib′ (cong force x≡y) iso″ : ∀ {x y} → (p : x ≈ y) → misib (bisim p) ≡ p iso′ : ∀ {x y} → (p : x ≈′ y) → misib′ (bisim′ p) ≡ p iso′ {zero} {zero} (con p) = refl iso′ {zero} {suc x} (con ()) iso′ {suc x} {zero} (con ()) iso′ {suc x} {suc y} (con p) = cong con (iso″ p) prove (iso″ p i) = iso′ (prove p) i osi : ∀ {x y} → (p : x ≡ y) → bisim (misib p) ≡ p osi p = isSetConat _ _ _ p path≃bisim : ∀ {x y} → (x ≡ y) ≃ (x ≈ y) path≃bisim = isoToEquiv (iso misib bisim iso″ osi) path≡bisim : ∀ {x y} → (x ≡ y) ≡ (x ≈ y) path≡bisim = ua path≃bisim isProp≈ : ∀ {x y} → isProp (x ≈ y) isProp≈ = subst isProp path≡bisim (isSetConat _ _)
26.248677
82
0.564402
d1c18552d98ed4f91d8bcb14983165a76b6ca8f7
1,165
agda
Agda
test/asset/agda-stdlib-1.0/Debug/Trace.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/Debug/Trace.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Debug/Trace.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Printing Strings During Evaluation ------------------------------------------------------------------------ {-# OPTIONS --without-K --rewriting #-} -- see README.Debug.Trace for a use-case module Debug.Trace where open import Agda.Builtin.String open import Agda.Builtin.Equality -- Postulating the `trace` function and explaining how to compile it postulate trace : ∀ {a} {A : Set a} → String → A → A {-# FOREIGN GHC import qualified Debug.Trace as Debug #-} {-# FOREIGN GHC import qualified Data.Text as Text #-} {-# COMPILE GHC trace = const (const (Debug.trace . Text.unpack)) #-} -- Because expressions involving postulates get stuck during evaluation, -- we also postulate an equality characterising `trace`'s behaviour. By -- declaring it as a rewrite rule we internalise that evaluation rule. postulate trace-eq : ∀ {a} {A : Set a} (a : A) str → trace str a ≡ a {-# BUILTIN REWRITE _≡_ #-} {-# REWRITE trace-eq #-} -- Specialised version of `trace` returning the traced message. traceId : String → String traceId str = trace str str
29.871795
72
0.619742
0de1b7d667091678af3d8e53c1408bcc8ef18b27
16,762
agda
Agda
Cubical/Algebra/CommRing/Localisation/UniversalProperty.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/UniversalProperty.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/UniversalProperty.agda
apabepa10/cubical
3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05
[ "MIT" ]
null
null
null
-- We define what it means to satisfy the universal property -- of localisation and show that the localisation in Base satisfies -- it. We will also show that the localisation is uniquely determined -- by the universal property, and give sufficient criteria for -- satisfying the universal property. {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.CommRing.Localisation.UniversalProperty where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset open import Cubical.Foundations.Transport open import Cubical.Functions.FunExtEquiv open import Cubical.Functions.Surjection open import Cubical.Functions.Embedding import Cubical.Data.Empty as ⊥ open import Cubical.Data.Bool open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Data.Vec open import Cubical.Data.Sigma.Base open import Cubical.Data.Sigma.Properties open import Cubical.Data.FinData open import Cubical.Relation.Nullary open import Cubical.Relation.Binary open import Cubical.Algebra.Group open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Localisation.Base open import Cubical.HITs.SetQuotients as SQ open import Cubical.HITs.PropositionalTruncation as PT open Iso private variable ℓ ℓ' : Level module _ (R' : CommRing {ℓ}) (S' : ℙ (R' .fst)) (SMultClosedSubset : isMultClosedSubset R' S') where open isMultClosedSubset private R = R' .fst open CommRingStr (R' .snd) hiding (is-set) open Theory (CommRing→Ring R') open RingHom hasLocUniversalProp : (A : CommRing {ℓ}) (φ : CommRingHom R' A) → (∀ s → s ∈ S' → f φ s ∈ A ˣ) → Type (ℓ-suc ℓ) hasLocUniversalProp A φ _ = (B : CommRing {ℓ}) (ψ : CommRingHom R' B) → (∀ s → s ∈ S' → f ψ s ∈ B ˣ) → ∃![ χ ∈ CommRingHom A B ] (f χ) ∘ (f φ) ≡ (f ψ) UniversalPropIsProp : (A : CommRing {ℓ}) (φ : CommRingHom R' A) → (φS⊆Aˣ : ∀ s → s ∈ S' → f φ s ∈ A ˣ) → isProp (hasLocUniversalProp A φ φS⊆Aˣ) UniversalPropIsProp A φ φS⊆Aˣ = isPropΠ3 (λ _ _ _ → isPropIsContr) -- S⁻¹R has the universal property module S⁻¹RUniversalProp where open Loc R' S' SMultClosedSubset _/1 : R → S⁻¹R r /1 = [ r , 1r , SMultClosedSubset .containsOne ] /1AsCommRingHom : CommRingHom R' S⁻¹RAsCommRing f /1AsCommRingHom = _/1 pres1 /1AsCommRingHom = refl isHom+ /1AsCommRingHom r r' = cong [_] (≡-× (cong₂ (_+_) (sym (·Rid r)) (sym (·Rid r'))) (Σ≡Prop (λ x → S' x .snd) (sym (·Lid 1r)))) isHom· /1AsCommRingHom r r' = cong [_] (≡-× refl (Σ≡Prop (λ x → S' x .snd) (sym (·Lid 1r)))) S⁻¹Rˣ = S⁻¹RAsCommRing ˣ S/1⊆S⁻¹Rˣ : ∀ s → s ∈ S' → (s /1) ∈ S⁻¹Rˣ S/1⊆S⁻¹Rˣ s s∈S' = [ 1r , s , s∈S' ] , eq/ _ _ ((1r , SMultClosedSubset .containsOne) , path) where path : 1r · (s · 1r) · 1r ≡ 1r · 1r · (1r · s) path = 1r · (s · 1r) · 1r ≡⟨ (λ i → ·Rid (·Lid (·Rid s i) i) i) ⟩ s ≡⟨ (λ i → ·Lid (·Lid s (~ i)) (~ i)) ⟩ 1r · (1r · s) ≡⟨ cong (_· (1r · s)) (sym (·Lid _)) ⟩ 1r · 1r · (1r · s) ∎ S⁻¹RHasUniversalProp : hasLocUniversalProp S⁻¹RAsCommRing /1AsCommRingHom S/1⊆S⁻¹Rˣ S⁻¹RHasUniversalProp B' ψ ψS⊆Bˣ = (χ , funExt χcomp) , χunique where B = B' .fst open CommRingStr (B' .snd) renaming ( is-set to Bset ; _·_ to _·B_ ; 1r to 1b ; _+_ to _+B_ ; ·Assoc to ·B-assoc ; ·-comm to ·B-comm ; ·Lid to ·B-lid ; ·Rid to ·B-rid ; ·Ldist+ to ·B-ldist-+) open Units B' renaming (Rˣ to Bˣ ; RˣMultClosed to BˣMultClosed ; RˣContainsOne to BˣContainsOne) open Theory (CommRing→Ring B') renaming (·-assoc2 to ·B-assoc2) open CommTheory B' renaming (·-commAssocl to ·B-commAssocl ; ·-commAssocSwap to ·B-commAssocSwap) χ : CommRingHom S⁻¹RAsCommRing B' f χ = SQ.rec Bset fχ fχcoh where fχ : R × S → B fχ (r , s , s∈S') = (f ψ r) ·B ((f ψ s) ⁻¹) ⦃ ψS⊆Bˣ s s∈S' ⦄ fχcoh : (a b : R × S) → a ≈ b → fχ a ≡ fχ b fχcoh (r , s , s∈S') (r' , s' , s'∈S') ((u , u∈S') , p) = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦃ ψS⊆Bˣ (u · s · s') (SMultClosedSubset .multClosed (SMultClosedSubset .multClosed u∈S' s∈S') s'∈S') ⦄ ⦃ BˣMultClosed _ _ ⦃ ψS⊆Bˣ (u · s) (SMultClosedSubset .multClosed u∈S' s∈S') ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦄ ⦃ ψS⊆Bˣ (u · s) (SMultClosedSubset .multClosed u∈S' s∈S') ⦄ where instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (u · s · s') ∈ Bˣ ⦄ ⦃ _ : f ψ (u · s) ·B f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (u · s) ∈ Bˣ ⦄ → f ψ r ·B f ψ s ⁻¹ ≡ f ψ r' ·B f ψ s' ⁻¹ instancepath = f ψ r ·B f ψ s ⁻¹ ≡⟨ sym (·B-rid _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B 1b ≡⟨ cong (f ψ r ·B f ψ s ⁻¹ ·B_) (sym (·-rinv _)) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ (u · s · s') ·B f ψ (u · s · s') ⁻¹) ≡⟨ ·B-assoc _ _ _ ⟩ f ψ r ·B f ψ s ⁻¹ ·B f ψ (u · s · s') ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ r ·B f ψ s ⁻¹ ·B x ·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ (u · s) ·B f ψ s') ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (·B-assoc _ _ _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B f ψ (u · s) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ r ·B f ψ s ⁻¹ ·B x ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ u ·B f ψ s) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → x ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) (·B-commAssocSwap _ _ _ _) ⟩ f ψ r ·B f ψ u ·B (f ψ s ⁻¹ ·B f ψ s) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ (λ i → ·B-comm (f ψ r) (f ψ u) i ·B (·-linv (f ψ s) i) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) ⟩ f ψ u ·B f ψ r ·B 1b ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ (λ i → (·B-rid (sym (isHom· ψ u r) i) i) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) ⟩ f ψ (u · r) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (sym (isHom· ψ _ _)) ⟩ f ψ (u · r · s') ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ x ·B f ψ (u · s · s') ⁻¹) p ⟩ f ψ (u · r' · s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ (u · r') ·B f ψ s ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → x ·B f ψ s ·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ u ·B f ψ r' ·B f ψ s ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (sym (·B-assoc _ _ _)) ⟩ f ψ u ·B (f ψ r' ·B f ψ s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (·B-commAssocl _ _ _) ⟩ f ψ r' ·B (f ψ u ·B f ψ s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ r' ·B x ·B f ψ (u · s · s') ⁻¹) (sym (isHom· ψ _ _)) ⟩ f ψ r' ·B f ψ (u · s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (f ψ r' ·B f ψ (u · s) ·B_) (unitCong (isHom· ψ _ _)) ⟩ f ψ r' ·B f ψ (u · s) ·B (f ψ (u · s) ·B f ψ s') ⁻¹ ≡⟨ cong (f ψ r' ·B f ψ (u · s) ·B_) (⁻¹-dist-· _ _) ⟩ f ψ r' ·B f ψ (u · s) ·B (f ψ (u · s) ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ ·B-assoc2 _ _ _ _ ⟩ f ψ r' ·B (f ψ (u · s) ·B f ψ (u · s) ⁻¹) ·B f ψ s' ⁻¹ ≡⟨ cong (λ x → f ψ r' ·B x ·B f ψ s' ⁻¹) (·-rinv _) ⟩ f ψ r' ·B 1b ·B f ψ s' ⁻¹ ≡⟨ cong (_·B f ψ s' ⁻¹) (·B-rid _) ⟩ f ψ r' ·B f ψ s' ⁻¹ ∎ pres1 χ = instancepres1χ ⦃ ψS⊆Bˣ 1r (SMultClosedSubset .containsOne) ⦄ ⦃ BˣContainsOne ⦄ where instancepres1χ : ⦃ _ : f ψ 1r ∈ Bˣ ⦄ ⦃ _ : 1b ∈ Bˣ ⦄ → f ψ 1r ·B (f ψ 1r) ⁻¹ ≡ 1b instancepres1χ = (λ i → (pres1 ψ i) ·B (unitCong (pres1 ψ) i)) ∙ (λ i → ·B-lid (1⁻¹≡1 i) i) isHom+ χ = elimProp2 (λ _ _ _ _ → Bset _ _ _ _) isHom+[] where isHom+[] : (a b : R × S) → f χ ([ a ] +ₗ [ b ]) ≡ (f χ [ a ]) +B (f χ [ b ]) isHom+[] (r , s , s∈S') (r' , s' , s'∈S') = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦃ ψS⊆Bˣ (s · s') (SMultClosedSubset .multClosed s∈S' s'∈S') ⦄ ⦃ BˣMultClosed _ _ ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦄ where instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (s · s') ∈ Bˣ ⦄ ⦃ _ : f ψ s ·B f ψ s' ∈ Bˣ ⦄ → f ψ (r · s' + r' · s) ·B f ψ (s · s') ⁻¹ ≡ f ψ r ·B f ψ s ⁻¹ +B f ψ r' ·B f ψ s' ⁻¹ instancepath = f ψ (r · s' + r' · s) ·B f ψ (s · s') ⁻¹ ≡⟨ (λ i → isHom+ ψ (r · s') (r' · s) i ·B unitCong (isHom· ψ s s') i) ⟩ (f ψ (r · s') +B f ψ (r' · s)) ·B (f ψ s ·B f ψ s') ⁻¹ ≡⟨ (λ i → (isHom· ψ r s' i +B isHom· ψ r' s i) ·B ⁻¹-dist-· (f ψ s) (f ψ s') i) ⟩ (f ψ r ·B f ψ s' +B f ψ r' ·B f ψ s) ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ ·B-ldist-+ _ _ _ ⟩ f ψ r ·B f ψ s' ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) +B f ψ r' ·B f ψ s ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ (λ i → ·B-commAssocSwap (f ψ r) (f ψ s') (f ψ s ⁻¹) (f ψ s' ⁻¹) i +B ·B-assoc2 (f ψ r') (f ψ s) (f ψ s ⁻¹) (f ψ s' ⁻¹) i) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ s' ·B f ψ s' ⁻¹) +B f ψ r' ·B (f ψ s ·B f ψ s ⁻¹) ·B f ψ s' ⁻¹ ≡⟨ (λ i → f ψ r ·B f ψ s ⁻¹ ·B (·-rinv (f ψ s') i) +B f ψ r' ·B (·-rinv (f ψ s) i) ·B f ψ s' ⁻¹) ⟩ f ψ r ·B f ψ s ⁻¹ ·B 1b +B f ψ r' ·B 1b ·B f ψ s' ⁻¹ ≡⟨ (λ i → ·B-rid (f ψ r ·B f ψ s ⁻¹) i +B ·B-rid (f ψ r') i ·B f ψ s' ⁻¹) ⟩ f ψ r ·B f ψ s ⁻¹ +B f ψ r' ·B f ψ s' ⁻¹ ∎ isHom· χ = elimProp2 (λ _ _ _ _ → Bset _ _ _ _) isHom·[] where isHom·[] : (a b : R × S) → f χ ([ a ] ·ₗ [ b ]) ≡ (f χ [ a ]) ·B (f χ [ b ]) isHom·[] (r , s , s∈S') (r' , s' , s'∈S') = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦃ ψS⊆Bˣ (s · s') (SMultClosedSubset .multClosed s∈S' s'∈S') ⦄ ⦃ BˣMultClosed _ _ ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦄ where instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (s · s') ∈ Bˣ ⦄ ⦃ _ : f ψ s ·B f ψ s' ∈ Bˣ ⦄ → f ψ (r · r') ·B f ψ (s · s') ⁻¹ ≡ (f ψ r ·B f ψ s ⁻¹) ·B (f ψ r' ·B f ψ s' ⁻¹) instancepath = f ψ (r · r') ·B f ψ (s · s') ⁻¹ ≡⟨ (λ i → isHom· ψ r r' i ·B unitCong (isHom· ψ s s') i) ⟩ f ψ r ·B f ψ r' ·B (f ψ s ·B f ψ s') ⁻¹ ≡⟨ cong (f ψ r ·B f ψ r' ·B_) (⁻¹-dist-· _ _) ⟩ f ψ r ·B f ψ r' ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ ·B-commAssocSwap _ _ _ _ ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ r' ·B f ψ s' ⁻¹) ∎ χcomp : (r : R) → f χ (r /1) ≡ f ψ r χcomp = instanceχcomp ⦃ ψS⊆Bˣ 1r (SMultClosedSubset .containsOne) ⦄ ⦃ Units.RˣContainsOne B' ⦄ where instanceχcomp : ⦃ _ : f ψ 1r ∈ Bˣ ⦄ ⦃ _ : 1b ∈ Bˣ ⦄ (r : R) → f ψ r ·B (f ψ 1r) ⁻¹ ≡ f ψ r instanceχcomp r = f ψ r ·B (f ψ 1r) ⁻¹ ≡⟨ cong (f ψ r ·B_) (unitCong (pres1 ψ)) ⟩ f ψ r ·B 1b ⁻¹ ≡⟨ cong (f ψ r ·B_) 1⁻¹≡1 ⟩ f ψ r ·B 1b ≡⟨ ·B-rid _ ⟩ f ψ r ∎ χunique : (y : Σ[ χ' ∈ CommRingHom S⁻¹RAsCommRing B' ] f χ' ∘ _/1 ≡ f ψ) → (χ , funExt χcomp) ≡ y χunique (χ' , χ'/1≡ψ) = Σ≡Prop (λ x → isSetΠ (λ _ → Bset) _ _) (RingHom≡f _ _ fχ≡fχ') where open RingHomRespUnits {A' = S⁻¹RAsCommRing} {B' = B'} χ' renaming (φ[x⁻¹]≡φ[x]⁻¹ to χ'[x⁻¹]≡χ'[x]⁻¹) []-path : (a : R × S) → f χ [ a ] ≡ f χ' [ a ] []-path (r , s , s∈S') = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ S/1⊆S⁻¹Rˣ s s∈S' ⦄ ⦃ RingHomRespInv _ ⦃ S/1⊆S⁻¹Rˣ s s∈S' ⦄ ⦄ where open Units S⁻¹RAsCommRing renaming (_⁻¹ to _⁻¹ˡ ; inverseUniqueness to S⁻¹RInverseUniqueness) hiding (unitCong) s-inv : ⦃ s/1∈S⁻¹Rˣ : s /1 ∈ S⁻¹Rˣ ⦄ → s /1 ⁻¹ˡ ≡ [ 1r , s , s∈S' ] s-inv ⦃ s/1∈S⁻¹Rˣ ⦄ = PathPΣ (S⁻¹RInverseUniqueness (s /1) s/1∈S⁻¹Rˣ (_ , eq/ _ _ ((1r , SMultClosedSubset .containsOne) , path))) .fst where path : 1r · (s · 1r) · 1r ≡ 1r · 1r · (1r · s) path = 1r · (s · 1r) · 1r ≡⟨ (λ i → ·Rid (·Lid (·Rid s i) i) i) ⟩ s ≡⟨ (λ i → ·Lid (·Lid s (~ i)) (~ i)) ⟩ 1r · (1r · s) ≡⟨ cong (_· (1r · s)) (sym (·Lid _)) ⟩ 1r · 1r · (1r · s) ∎ ·ₗ-path : [ r , s , s∈S' ] ≡ [ r , 1r , SMultClosedSubset .containsOne ] ·ₗ [ 1r , s , s∈S' ] ·ₗ-path = cong [_] (≡-× (sym (·Rid r)) (Σ≡Prop (λ x → S' x .snd) (sym (·Lid s)))) instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : s /1 ∈ S⁻¹Rˣ ⦄ ⦃ _ : f χ' (s /1) ∈ Bˣ ⦄ → f ψ r ·B f ψ s ⁻¹ ≡ f χ' [ r , s , s∈S' ] instancepath = f ψ r ·B f ψ s ⁻¹ ≡⟨ cong (f ψ r ·B_) (unitCong (cong (λ φ → φ s) (sym χ'/1≡ψ))) ⟩ f ψ r ·B f χ' (s /1) ⁻¹ ≡⟨ cong (f ψ r ·B_) (sym (χ'[x⁻¹]≡χ'[x]⁻¹ _)) ⟩ f ψ r ·B f χ' (s /1 ⁻¹ˡ) ≡⟨ cong (λ x → f ψ r ·B f χ' x) s-inv ⟩ f ψ r ·B f χ' [ 1r , s , s∈S' ] ≡⟨ cong (_·B f χ' [ 1r , s , s∈S' ]) (cong (λ φ → φ r) (sym χ'/1≡ψ)) ⟩ f χ' [ r , 1r , SMultClosedSubset .containsOne ] ·B f χ' [ 1r , s , s∈S' ] ≡⟨ sym (isHom· χ' _ _) ⟩ f χ' ([ r , 1r , SMultClosedSubset .containsOne ] ·ₗ [ 1r , s , s∈S' ]) ≡⟨ cong (f χ') (sym ·ₗ-path) ⟩ f χ' [ r , s , s∈S' ] ∎ fχ≡fχ' : f χ ≡ f χ' fχ≡fχ' = funExt (SQ.elimProp (λ _ → Bset _ _) []-path) -- sufficient conditions for having the universal property -- used as API in the leanprover-community/mathlib -- Corollary 3.2 in Atiyah-McDonald open S⁻¹RUniversalProp record PathToS⁻¹R (A' : CommRing {ℓ}) (φ : CommRingHom R' A') : Type ℓ where constructor pathtoS⁻¹R open Units A' renaming (Rˣ to Aˣ) open CommRingStr (A' .snd) renaming (is-set to Aset ; 0r to 0a ; _·_ to _·A_) field φS⊆Aˣ : ∀ s → s ∈ S' → f φ s ∈ Aˣ kerφ⊆annS : ∀ r → f φ r ≡ 0a → ∃[ s ∈ S ] (s .fst) · r ≡ 0r surχ : ∀ a → ∃[ x ∈ R × S ] f φ (x .fst) ·A (f φ (x .snd .fst) ⁻¹) ⦃ φS⊆Aˣ _ (x .snd .snd) ⦄ ≡ a S⁻¹RChar : (A' : CommRing {ℓ}) (φ : CommRingHom R' A') → PathToS⁻¹R A' φ → S⁻¹RAsCommRing ≡ A' S⁻¹RChar A' φ cond = CommRingPath S⁻¹RAsCommRing A' .fst (S⁻¹R≃A , record { pres1 = pres1 χ ; isHom+ = isHom+ χ ; isHom· = isHom· χ }) where open CommRingStr (A' .snd) renaming ( is-set to Aset ; 0r to 0a ; _·_ to _·A_ ; 1r to 1a ; ·Rid to ·A-rid) open Units A' renaming (Rˣ to Aˣ ; RˣInvClosed to AˣInvClosed) open PathToS⁻¹R ⦃...⦄ private A = A' .fst instance _ = cond χ = (S⁻¹RHasUniversalProp A' φ φS⊆Aˣ .fst .fst) open HomTheory χ S⁻¹R≃A : S⁻¹R ≃ A S⁻¹R≃A = f χ , isEmbedding×isSurjection→isEquiv (Embχ , Surχ) where Embχ : isEmbedding (f χ) Embχ = injEmbedding squash/ Aset (ker≡0→inj λ {x} → kerχ≡0 x) where kerχ≡0 : (r/s : S⁻¹R) → f χ r/s ≡ 0a → r/s ≡ 0ₗ kerχ≡0 = SQ.elimProp (λ _ → isPropΠ λ _ → squash/ _ _) kerχ≡[] where kerχ≡[] : (a : R × S) → f χ [ a ] ≡ 0a → [ a ] ≡ 0ₗ kerχ≡[] (r , s , s∈S') p = PT.rec (squash/ _ _) Σhelper (kerφ⊆annS r (UnitsAreNotZeroDivisors _ _ p)) where instance _ : f φ s ∈ Aˣ _ = φS⊆Aˣ s s∈S' _ : f φ s ⁻¹ ∈ Aˣ _ = AˣInvClosed _ Σhelper : Σ[ s ∈ S ] (s .fst) · r ≡ 0r → [ r , s , s∈S' ] ≡ 0ₗ Σhelper ((u , u∈S') , q) = eq/ _ _ ((u , u∈S') , path) where path : u · r · 1r ≡ u · 0r · s path = (λ i → ·Rid (q i) i) ∙∙ sym (0LeftAnnihilates _) ∙∙ cong (_· s) (sym (0RightAnnihilates _)) Surχ : isSurjection (f χ) Surχ a = PT.rec propTruncIsProp (λ x → ∣ [ x .fst ] , x .snd ∣) (surχ a)
48.868805
101
0.445532
35bb8eb45ef58aa65e00bd17313a559c3a1fcd7e
1,320
agda
Agda
Cubical/Algebra/CommRing/Instances/MultivariatePoly.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Instances/MultivariatePoly.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Instances/MultivariatePoly.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.CommRing.Instances.MultivariatePoly where open import Cubical.Foundations.Prelude open import Cubical.Data.Nat renaming(_+_ to _+n_; _·_ to _·n_) open import Cubical.Data.Vec open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.Polynomials.Multivariate.Base open import Cubical.Algebra.Polynomials.Multivariate.Properties private variable ℓ ℓ' : Level module _ (A' : CommRing ℓ) (n : ℕ) where private A = fst A' Ar = CommRing→Ring A' open CommRingStr open RingTheory Ar open Nth-Poly-structure A' n PolyCommRing : CommRing ℓ fst PolyCommRing = Poly A' n 0r (snd PolyCommRing) = 0P 1r (snd PolyCommRing) = 1P _+_ (snd PolyCommRing) = _Poly+_ _·_ (snd PolyCommRing) = _Poly*_ - snd PolyCommRing = Poly-inv isCommRing (snd PolyCommRing) = makeIsCommRing trunc Poly+-assoc Poly+-Rid Poly+-rinv Poly+-comm Poly*-assoc Poly*-Rid Poly*-Rdist Poly*-comm
28.695652
64
0.570455
35bf861a11eef20e0b78f7f464aa1e5300f88156
1,191
agda
Agda
test/js/TestBool.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/js/TestBool.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/js/TestBool.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
open import Common.Prelude open import TestHarness module TestBool where not : Bool → Bool not true = false not false = true {-# COMPILED_JS not function (x) { return !x; } #-} _∧_ : Bool → Bool → Bool true ∧ x = x false ∧ x = false {-# COMPILED_JS _∧_ function (x) { return function (y) { return x && y; }; } #-} _∨_ : Bool → Bool → Bool true ∨ x = true false ∨ x = x {-# COMPILED_JS _∨_ function (x) { return function (y) { return x || y; }; } #-} _↔_ : Bool → Bool → Bool true ↔ true = true false ↔ false = true _ ↔ _ = false {-# COMPILED_JS _↔_ function (x) { return function (y) { return x === y; }; } #-} tests : Tests tests _ = ( assert true "tt" , assert (not false) "!ff" , assert (true ∧ true) "tt∧tt" , assert (not (true ∧ false)) "!(tt∧ff)" , assert (not (false ∧ false)) "!(ff∧ff)" , assert (not (false ∧ true)) "!(ff∧tt)" , assert (true ∨ true) "tt∨tt" , assert (true ∨ false) "tt∨ff" , assert (false ∨ true) "ff∨tt" , assert (not (false ∨ false)) "!(ff∧ff)" , assert (true ↔ true) "tt=tt" , assert (not (true ↔ false)) "tt≠ff" , assert (not (false ↔ true)) "ff≠tt" , assert (false ↔ false) "ff=ff" )
27.068182
81
0.554996
fd05e5f006236d4957b00dc8515c44b0e3d46b2a
1,137
agda
Agda
src/Fragment/Setoid/Morphism/Base.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
18
2021-06-15T15:45:39.000Z
2022-01-17T17:26:09.000Z
src/Fragment/Setoid/Morphism/Base.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
1
2021-06-16T09:44:31.000Z
2021-06-16T10:24:15.000Z
src/Fragment/Setoid/Morphism/Base.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
3
2021-06-15T15:34:50.000Z
2021-06-16T08:04:31.000Z
{-# OPTIONS --without-K --exact-split --safe #-} module Fragment.Setoid.Morphism.Base where open import Level using (Level; _⊔_) open import Function using (_∘_; Congruent) import Relation.Binary.PropositionalEquality as PE open import Relation.Binary using (Setoid) private variable a b c ℓ₁ ℓ₂ ℓ₃ : Level module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂) where open Setoid S renaming (Carrier to A; _≈_ to _≈₁_) open Setoid T renaming (Carrier to B; _≈_ to _≈₂_) infixr 1 _↝_ record _↝_ : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field ∣_∣ : A → B ∣_∣-cong : Congruent _≈₁_ _≈₂_ ∣_∣ open _↝_ public lift : ∀ {A : Set a} {B : Setoid b ℓ₂} → (A → Setoid.Carrier B) → (PE.setoid A ↝ B) lift {B = B} f = record { ∣_∣ = f ; ∣_∣-cong = reflexive ∘ (PE.cong f) } where open Setoid B id : ∀ {A : Setoid a ℓ₁} → A ↝ A id = record { ∣_∣ = λ x → x ; ∣_∣-cong = λ x → x } _·_ : ∀ {A : Setoid a ℓ₁} {B : Setoid b ℓ₂} {C : Setoid c ℓ₃} → B ↝ C → A ↝ B → A ↝ C g · f = record { ∣_∣ = ∣ g ∣ ∘ ∣ f ∣ ; ∣_∣-cong = ∣ g ∣-cong ∘ ∣ f ∣-cong }
24.717391
61
0.532982
7cf942c36ee00733c05c086819bddcea8d6c5cc2
1,997
agda
Agda
test/asset/agda-stdlib-1.0/Data/Container/Indexed/FreeMonad.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Container/Indexed/FreeMonad.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Container/Indexed/FreeMonad.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- The free monad construction on indexed containers ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --guardedness #-} module Data.Container.Indexed.FreeMonad where open import Level open import Function hiding (const) open import Category.Monad.Predicate open import Data.Container.Indexed open import Data.Container.Indexed.Combinator hiding (id; _∘_) open import Data.Empty open import Data.Sum using (inj₁; inj₂) open import Data.Product open import Data.W.Indexed open import Relation.Unary open import Relation.Unary.PredicateTransformer open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ infixl 9 _⋆C_ infix 9 _⋆_ _⋆C_ : ∀ {i o c r} {I : Set i} {O : Set o} → Container I O c r → Pred O c → Container I O _ _ C ⋆C X = const X ⊎ C _⋆_ : ∀ {ℓ} {O : Set ℓ} → Container O O ℓ ℓ → Pt O ℓ C ⋆ X = μ (C ⋆C X) pattern returnP x = (inj₁ x , _) pattern doP c k = (inj₂ c , k) inn : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {X} → ⟦ C ⟧ (C ⋆ X) ⊆ C ⋆ X inn (c , k) = sup (doP c k) rawPMonad : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} → RawPMonad {ℓ = ℓ} (_⋆_ C) rawPMonad {C = C} = record { return? = return ; _=<?_ = _=<<_ } where return : ∀ {X} → X ⊆ C ⋆ X return x = sup (inj₁ x , ⊥-elim ∘ lower) _=<<_ : ∀ {X Y} → X ⊆ C ⋆ Y → C ⋆ X ⊆ C ⋆ Y f =<< sup (returnP x) = f x f =<< sup (doP c k) = inn (c , λ r → f =<< k r) leaf : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {X : Pred O ℓ} → ⟦ C ⟧ X ⊆ C ⋆ X leaf (c , k) = inn (c , return? ∘ k) where open RawPMonad rawPMonad generic : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {o} (c : Command C o) → o ∈ C ⋆ (⋃[ r ∶ Response C c ] { next C c r }) generic c = inn (c , λ r → return? (r , refl)) where open RawPMonad rawPMonad
28.942029
72
0.515774
4ea42d201de8c6d9727bcf83986fe00c4e1eea55
284
agda
Agda
Type.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Type.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Type.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Type{ℓ} where open import Agda.Primitive public using () renaming (Set to TYPE ; Setω to Typeω) Type : TYPE(_) Type = TYPE(ℓ) {-# INLINE Type #-} module Type where -- Returns the type of a certain value of : ∀{T : Type} → T → Type of {T} _ = T {-# INLINE of #-}
17.75
40
0.616197
372824fc0dfa715cd1833e5e29970ad92f580457
490
agda
Agda
test/Succeed/Issue1886-omit-hidden.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1886-omit-hidden.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1886-omit-hidden.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-12-30, issues #555 and #1886, reported by nad -- Hidden parameters can be omitted in the repetition -- of the parameter list. record R {a} (A : Set a) : Set a record R A where constructor c field f : A testR : ∀{a}{A : Set a}(x : A) → R A testR x = c x data D {a} (A : Set a) : Set a data D A where c : A → D A testD : ∀{a}{A : Set a}(x : A) → D A testD x = c x -- Now, c is overloaded, should still work. testR' : ∀{a}{A : Set a}(x : A) → R A testR' x = c x
18.846154
62
0.579592
0d9c7ff85e13e708ae5e8e13f07ea68c7fc70884
2,955
agda
Agda
notes/FOT/FOTC/Program/Mirror/Tree/TotalityNonTerminationI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/FOTC/Program/Mirror/Tree/TotalityNonTerminationI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/FOTC/Program/Mirror/Tree/TotalityNonTerminationI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Properties related with the totality of the rose tree type ------------------------------------------------------------------------------ {-# OPTIONS --injective-type-constructors #-} {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Program.Mirror.Tree.TotalityNonTerminationI where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.List open import FOTC.Program.Mirror.Mirror open import FOTC.Program.Mirror.Type open import FOTC.Program.Mirror.Forest.TotalityI open import FOTC.Program.Mirror.Forest.PropertiesI ------------------------------------------------------------------------------ -- Requires --injective-type-constructors -- Peter: To use injectivity of type constructors means asking for -- trouble. The logic behind this is very unclear. node-Forest : ∀ {d ts} → Tree (node d ts) → Forest ts node-Forest {d} (tree .d Fts) = Fts postulate reverse-∷' : ∀ x ys → reverse (x ∷ ys) ≡ reverse ys ++ (x ∷ []) -- The termination checker can not determine that the function mirror-Tree -- defined by -- -- mirror-Tree (tree d (fcons {t} {ts} Tt Fts)) = -- ... mirror-Tree (tree d Fts) ... mirror-Tree Tt ... -- -- is structurally recursive. -- Andreas Abel: The function does not terminate because we are using -- postulates (i.e. D, _∷_, etc). In particular, x is not structurally -- smaller than x ∷ xs. {-# TERMINATING #-} mirror-Tree : ∀ {t} → Tree t → Tree (mirror · t) mirror-Tree (tree d fnil) = subst Tree (sym (mirror-eq d [])) (tree d helper₂) where helper₁ : rev (map mirror []) [] ≡ [] helper₁ = rev (map mirror []) [] ≡⟨ subst (λ x → rev (map mirror []) [] ≡ rev x []) (map-[] mirror) refl ⟩ rev [] [] ≡⟨ rev-[] [] ⟩ [] ∎ helper₂ : Forest (rev (map mirror []) []) helper₂ = subst Forest (sym helper₁) fnil mirror-Tree (tree d (fcons {t} {ts} Tt Fts)) = subst Tree (sym (mirror-eq d (t ∷ ts))) (tree d helper) where h₁ : Tree (node d (reverse (map mirror ts))) h₁ = subst Tree (mirror-eq d ts) (mirror-Tree (tree d Fts)) h₂ : Forest (reverse (map mirror ts)) h₂ = node-Forest h₁ h₃ : Forest ((reverse (map mirror ts)) ++ (mirror · t ∷ [])) h₃ = ++-Forest h₂ (fcons (mirror-Tree Tt) fnil) h₄ : Forest (reverse (mirror · t ∷ map mirror ts)) h₄ = subst Forest (sym (reverse-∷' (mirror · t) (map mirror ts))) h₃ helper : Forest (reverse (map mirror (t ∷ ts))) helper = subst Forest (subst (λ x → reverse x ≡ reverse (map mirror (t ∷ ts))) (map-∷ mirror t ts) refl) h₄
34.360465
78
0.544501
1e1a544f3dfedd2ee6a4ab914362189772f30fab
5,859
agda
Agda
Type/Cubical/Path/Equality.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Type/Cubical/Path/Equality.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Type/Cubical/Path/Equality.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical #-} module Type.Cubical.Path.Equality where open import Functional open import Function.Axioms import Lvl open import Type open import Type.Cubical open import Type.Cubical.Path open import Type.Cubical.Path.Proofs as Path open import Structure.Function open import Structure.Operator open import Structure.Relator.Equivalence open import Structure.Relator.Properties open import Structure.Relator open import Structure.Setoid using (Equiv ; intro) open import Structure.Type.Identity private variable ℓ ℓ₁ ℓ₂ ℓₚ : Lvl.Level private variable T A B C : Type{ℓ} private variable f : A → B private variable _▫_ : A → B → C private variable P : T → Type{ℓ} private variable x y : T _≡_ : T → T → Type _≡_ = Path instance Path-reflexivity : Reflexivity{T = T}(Path) Path-reflexivity = intro Path.point instance Path-symmetry : Symmetry{T = T}(Path) Path-symmetry = intro Path.reverse instance Path-transitivity : Transitivity{T = T}(Path) Path-transitivity = intro Path.concat instance Path-equivalence : Equivalence{T = T}(Path) Path-equivalence = intro instance Path-equiv : Equiv(T) Path-equiv = intro(Path) ⦃ Path-equivalence ⦄ instance Path-congruence₁ : Function(f) Path-congruence₁ {f = f} = intro(Path.map f) instance Path-congruence₂ : BinaryOperator(_▫_) Path-congruence₂ {_▫_ = _▫_} = intro(Path.map₂(_▫_)) instance Path-substitution₁ : UnaryRelator(P) Path-substitution₁ {P = P} = intro(Path.liftedSpaceMap P) instance Path-substitution₂ : BinaryRelator(_▫_) Path-substitution₂ {_▫_ = _▫_} = intro(Path.liftedSpaceMap₂(_▫_)) instance Path-coercion : Path ⊆₂ (_→ᶠ_ {ℓ}{ℓ}) Path-coercion = intro(Path.spaceMap) Path-sub-of-reflexive : ⦃ refl : Reflexivity(_▫_) ⦄ → (Path ⊆₂ (_▫_)) Path-sub-of-reflexive {_▫_ = _▫_} = intro(\{a b} → ab ↦ sub₂(Path)(_→ᶠ_) ⦃ Path-coercion ⦄ (congruence₂ᵣ(_▫_)(a) ab) (reflexivity(_▫_) {a})) instance Path-function-extensionality : FunctionExtensionality A B Path-function-extensionality = intro Path.mapping instance Path-dependent-function-extensionality : ∀{A : Type{ℓ₁}}{B : (a : A) → Type{ℓ₂}} → DependentFunctionExtensionality A B Path-dependent-function-extensionality = intro Path.mapping instance Path-function-application : FunctionApplication A B Path-function-application = intro Path.mappingPoint Path-identity-eliminator : IdentityEliminator{ℓₚ = ℓₚ}(Path{P = T}) IdentityEliminator.elim Path-identity-eliminator P prefl eq = sub₂(Path)(_→ᶠ_) ⦃ Path-coercion ⦄ (\i → P(\j → eq(Interval.min i j))) prefl -- TODO: Organize and move everything below open import Type.Properties.MereProposition open import Type.Properties.Singleton prop-is-prop-unit : ⦃ proof : MereProposition(A) ⦄ → IsUnit(MereProposition(A)) MereProposition.uniqueness (IsUnit.unit prop-is-prop-unit) {x} {y} = uniqueness _ MereProposition.uniqueness (IsUnit.uniqueness (prop-is-prop-unit {A = A}) {intro p} i) {x}{y} j = Interval.hComp d x where d : Interval → Interval.Partial (Interval.max (Interval.max (Interval.flip i) i) (Interval.max (Interval.flip j) j)) A d k (i = Interval.𝟎) = uniqueness(A) {x}{p{x}{y} j} k d k (i = Interval.𝟏) = uniqueness(A) {x}{uniqueness(A) {x}{y} j} k d k (j = Interval.𝟎) = uniqueness(A) {x}{x} k d k (j = Interval.𝟏) = uniqueness(A) {x}{y} k {- Path-isUnit : ∀{ℓ}{A : Type{ℓ}} → ⦃ _ : MereProposition(A) ⦄ → (∀{x y : A} → IsUnit(x ≡ y)) IsUnit.unit (Path-isUnit {A = A}) = uniqueness(A) IsUnit.uniqueness (Path-isUnit {A = A} ⦃ mere-A ⦄ {x = x} {y = y}) {p} i = Interval.hComp d p where d : Interval → Interval.Partial (Interval.max (Interval.flip i) i) (Path x y) d j (i = Interval.𝟎) = p d j (i = Interval.𝟏) = {!uniqueness(A) {x}{y}!} -- congruence₁ (prop ↦ MereProposition.uniqueness prop {x}{y}) (IsUnit.uniqueness prop-is-prop-unit {intro (\{x y} → {!p!})}) -} {- open import Structure.Setoid.Uniqueness open import Type.Dependent -} -- TODO -- ∀{eu₁ eu₂ : ∃!{Obj = Obj}(Pred)} → () → (eu₁ ≡ eu₂) {- Unique-MereProposition-equivalence : ⦃ prop : ∀{x} → MereProposition(P(x)) ⦄ → (Unique(P) ↔ MereProposition(∃ P)) Unique-MereProposition-equivalence {P = P} = [↔]-intro l r where l : Unique(P) ← MereProposition(∃ P) l (intro p) {x} {y} px py = mapP([∃]-witness) (p{[∃]-intro x ⦃ px ⦄} {[∃]-intro y ⦃ py ⦄}) r : Unique(P) → MereProposition(∃ P) MereProposition.uniqueness (r p) {[∃]-intro w₁ ⦃ p₁ ⦄} {[∃]-intro w₂ ⦃ p₂ ⦄} i = mapP (mapP (\w p → [∃]-intro w ⦃ p ⦄) (p p₁ p₂) i) {!!} i -- mapP [∃]-intro (p p₁ p₂) i ⦃ {!!} ⦄ Unique-prop : ⦃ prop : ∀{x} → MereProposition(P(x)) ⦄ → MereProposition(Unique(P)) MereProposition.uniqueness Unique-prop {u₁} {u₂} i {x} {y} px py j = Interval.hComp d x where d : Interval → Interval.Partial (Interval.max (Interval.max (Interval.flip i) i) (Interval.max (Interval.flip j) j)) A d k (i = Interval.𝟎) = {!!} d k (i = Interval.𝟏) = {!!} d k (j = Interval.𝟎) = {!!} d k (j = Interval.𝟏) = {!!} [∃!trunc]-to-existence : ⦃ prop : ∀{x} → MereProposition(Pred(x)) ⦄ → HTrunc₁(∃!{Obj = Obj}(Pred)) → HomotopyLevel(0)(∃{Obj = Obj}(Pred)) [∃!trunc]-to-existence {Pred = Pred} (trunc ([∧]-intro e u)) = intro e (\{e₂} i → [∃]-intro (u ([∃]-proof e₂) ([∃]-proof e) i) ⦃ {!!} ⦄) -- MereProposition.uniqueness test) {u _ _ _} -- sub₂(_≡_)(_→ᶠ_) ⦃ [≡][→]-sub ⦄ (congruence₁(Pred) ?) ? [∃!trunc]-to-existence (trunc-proof i) = {!!} -} {- [∃!]-squashed-witness : HTrunc₁(∃!{Obj = Obj}(Pred)) → Obj [∃!]-squashed-witness (trunc eu) = [∃]-witness([∧]-elimₗ eu) [∃!]-squashed-witness (trunc-proof {trunc ([∧]-intro e₁ u₁)} {trunc ([∧]-intro e₂ u₂)} i) = u₁ ([∃]-proof e₁) ([∃]-proof e₂) i [∃!]-squashed-witness (trunc-proof {trunc ([∧]-intro e₁ u₁)} {trunc-proof j} i) = {!!} [∃!]-squashed-witness (trunc-proof {trunc-proof i₁} {trunc x} i) = {!!} [∃!]-squashed-witness (trunc-proof {trunc-proof i₁} {trunc-proof i₂} i) = {!!} -}
38.546053
140
0.657621
349123ca2825c2d18b3b229dc363b12af3f67e68
2,925
agda
Agda
Rings/Ideals/FirstIsomorphismTheorem.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Rings/Ideals/FirstIsomorphismTheorem.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Rings/Ideals/FirstIsomorphismTheorem.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Groups.Homomorphisms.Definition open import Groups.Definition open import Groups.Lemmas open import Setoids.Setoids open import Sets.EquivalenceRelations open import Rings.Definition open import Rings.Homomorphisms.Definition open import Groups.Homomorphisms.Lemmas open import Rings.Subrings.Definition open import Rings.Cosets open import Rings.Isomorphisms.Definition open import Groups.Isomorphisms.Definition module Rings.Ideals.FirstIsomorphismTheorem {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_+A_ _*A_ : A → A → A} {_+B_ _*B_ : B → B → B} {R1 : Ring S _+A_ _*A_} {R2 : Ring T _+B_ _*B_} {f : A → B} (hom : RingHom R1 R2 f) where open import Rings.Quotients.Definition R1 R2 hom open import Rings.Homomorphisms.Image hom open import Rings.Homomorphisms.Kernel hom open Setoid T open Equivalence eq open import Groups.FirstIsomorphismTheorem (RingHom.groupHom hom) ringFirstIsomorphismTheorem : RingsIsomorphic (cosetRing R1 ringKernelIsIdeal) (subringIsRing R2 imageGroupSubring) RingsIsomorphic.f ringFirstIsomorphismTheorem = GroupsIsomorphic.isomorphism groupFirstIsomorphismTheorem RingHom.preserves1 (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem)) = RingHom.preserves1 hom RingHom.ringHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem)) = RingHom.ringHom hom GroupHom.groupHom (RingHom.groupHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem))) = GroupHom.groupHom (RingHom.groupHom hom) GroupHom.wellDefined (RingHom.groupHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem))) {x} {y} x=y = transferToRight (Ring.additiveGroup R2) t where t : f x +B Group.inverse (Ring.additiveGroup R2) (f y) ∼ Ring.0R R2 t = transitive (Ring.groupIsAbelian R2) (transitive (Group.+WellDefined (Ring.additiveGroup R2) (symmetric (homRespectsInverse (RingHom.groupHom hom))) reflexive) (transitive (symmetric (GroupHom.groupHom (RingHom.groupHom hom))) x=y)) RingIso.bijective (RingsIsomorphic.iso ringFirstIsomorphismTheorem) = GroupIso.bij (GroupsIsomorphic.proof groupFirstIsomorphismTheorem) ringFirstIsomorphismTheorem' : RingsIsomorphic quotientByRingHom (subringIsRing R2 imageGroupSubring) RingsIsomorphic.f ringFirstIsomorphismTheorem' a = f a , (a , reflexive) RingHom.preserves1 (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem')) = RingHom.preserves1 hom RingHom.ringHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem')) {r} {s} = RingHom.ringHom hom RingHom.groupHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem')) = GroupIso.groupHom (GroupsIsomorphic.proof (groupFirstIsomorphismTheorem')) RingIso.bijective (RingsIsomorphic.iso ringFirstIsomorphismTheorem') = GroupIso.bij (GroupsIsomorphic.proof groupFirstIsomorphismTheorem')
66.477273
265
0.807521
3533999d8617d140398b95d93f0dcf80214b8177
393
agda
Agda
test/Succeed/Issue3382.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3382.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3382.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --cubical --rewriting --confluence-check #-} open import Agda.Primitive.Cubical public postulate Int : Set _↦_ : {A : Set} → A → A → Set id↦ : {A : Set} {a : A} → a ↦ a {-# BUILTIN REWRITE _↦_ #-} postulate hcompIntEmpty : (n : Int) → primHComp (λ _ → isOneEmpty) n ↦ n {-# REWRITE hcompIntEmpty #-} test : (n : Int) → primHComp (λ _ → isOneEmpty) n ↦ n test n = id↦
20.684211
64
0.592875
7cf02157f7bb5befdaaddd48cf5334428efec4d4
3,304
agda
Agda
Cubical/HITs/Join/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/HITs/Join/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/HITs/Join/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Join.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.HITs.S1 open import Cubical.HITs.S3 -- redtt version : https://github.com/RedPRL/redtt/blob/master/library/cool/s3-to-join.red data join {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') : Type (ℓ-max ℓ ℓ') where inl : A → join A B inr : B → join A B push : ∀ a b → inl a ≡ inr b facek01 : I → I → I → join S¹ S¹ facek01 i j k = hfill (λ l → λ { (j = i0) → push base base (~ l ∧ ~ k) ; (j = i1) → push base base (~ l ∧ ~ k) ; (k = i0) → push (loop j) base (~ l) ; (k = i1) → inl base }) (inS (push base base (~ k))) i border-contraction : I → I → I → I → join S¹ S¹ border-contraction i j k m = hfill (λ l → λ { (i = i0) → facek01 i1 j l ; (i = i1) → push base (loop k) (~ l) ; (j = i0) → push base (loop k) (i ∧ ~ l) ; (j = i1) → push base (loop k) (i ∧ ~ l) ; (k = i0) → facek01 (~ i) j l ; (k = i1) → facek01 (~ i) j l }) (inS (push (loop j) (loop k) i)) m S³→joinS¹S¹ : S³ → join S¹ S¹ S³→joinS¹S¹ base = inl base S³→joinS¹S¹ (surf j k i) = border-contraction i j k i1 joinS¹S¹→S³ : join S¹ S¹ → S³ joinS¹S¹→S³ (inl x) = base joinS¹S¹→S³ (inr x) = base joinS¹S¹→S³ (push base b i) = base joinS¹S¹→S³ (push (loop x) base i) = base joinS¹S¹→S³ (push (loop i) (loop j) k) = surf i j k connection : I → I → I → I → S³ connection i j k l = hfill (λ m → λ { (k = i0) → joinS¹S¹→S³ (facek01 m i j) ; (k = i1) → base ; (j = i0) → base ; (j = i1) → base ; (i = i0) → base ; (i = i1) → base }) (inS base) l S³→joinS¹S¹→S³ : ∀ x → joinS¹S¹→S³ (S³→joinS¹S¹ x) ≡ x S³→joinS¹S¹→S³ base l = base S³→joinS¹S¹→S³ (surf j k i) l = hcomp (λ m → λ { (l = i0) → joinS¹S¹→S³ (border-contraction i j k m) ; (l = i1) → surf j k i ; (i = i0) → connection j m l i1 ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base ; (k = i0) → connection j m l (~ i) ; (k = i1) → connection j m l (~ i) }) (surf j k i) joinS¹S¹→S³→joinS¹S¹ : ∀ x → S³→joinS¹S¹ (joinS¹S¹→S³ x) ≡ x joinS¹S¹→S³→joinS¹S¹ (inl base) l = inl base joinS¹S¹→S³→joinS¹S¹ (inl (loop i)) l = facek01 i1 i (~ l) joinS¹S¹→S³→joinS¹S¹ (inr base) l = push base base l joinS¹S¹→S³→joinS¹S¹ (inr (loop i)) l = push base (loop i) l joinS¹S¹→S³→joinS¹S¹ (push base base i) l = push base base (i ∧ l) joinS¹S¹→S³→joinS¹S¹ (push base (loop k) i) l = push base (loop k) (i ∧ l) joinS¹S¹→S³→joinS¹S¹ (push (loop k) base i) l = facek01 (~ i) k (~ l) joinS¹S¹→S³→joinS¹S¹ (push (loop j) (loop k) i) l = border-contraction i j k (~ l) S³IsojoinS¹S¹ : Iso S³ (join S¹ S¹) Iso.fun S³IsojoinS¹S¹ = S³→joinS¹S¹ Iso.inv S³IsojoinS¹S¹ = joinS¹S¹→S³ Iso.rightInv S³IsojoinS¹S¹ = joinS¹S¹→S³→joinS¹S¹ Iso.leftInv S³IsojoinS¹S¹ = S³→joinS¹S¹→S³ S³≡joinS¹S¹ : S³ ≡ join S¹ S¹ S³≡joinS¹S¹ = isoToPath S³IsojoinS¹S¹
37.545455
90
0.534806
7c7cb96c2924fd820fd9922937398180d9722527
1,371
agda
Agda
src/Prelude/Monad/Indexed.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Prelude/Monad/Indexed.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Prelude/Monad/Indexed.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Prelude.Monad.Indexed {i} {I : Set i} where open import Agda.Primitive open import Prelude.Function open import Prelude.Functor open import Prelude.Applicative.Indexed {I = I} record IMonad {a b} (M : I → I → Set a → Set b) : Set (i ⊔ lsuc a ⊔ b) where infixr 1 _=<<_ infixl 1 _>>=_ _>>_ field _>>=_ : ∀ {A B i j k} → M i j A → (A → M j k B) → M i k B overlap {{super}} : IApplicative M _>>_ : ∀ {A B i j k} → M i j A → M j k B → M i k B m₁ >> m₂ = m₁ >>= λ _ → m₂ _=<<_ : ∀ {A B i j k} → (A → M j k B) → M i j A → M i k B _=<<_ = flip _>>=_ return : ∀ {a b} {A : Set a} {M : I → I → Set a → Set b} {{_ : IMonad M}} {i : I} → A → M i i A return = pure open IMonad {{...}} public {-# DISPLAY IMonad._>>=_ _ = _>>=_ #-} {-# DISPLAY IMonad._=<<_ _ = _=<<_ #-} {-# DISPLAY IMonad._>>_ _ = _>>_ #-} join : ∀ {a} {M : I → I → Set a → Set a} {{_ : IMonad M}} {A : Set a} {i j k} → M i j (M j k A) → M i k A join = _=<<_ id -- Level polymorphic monads record IMonad′ {a b} (M : ∀ {a} → I → I → Set a → Set a) : Set (i ⊔ lsuc (a ⊔ b)) where field _>>=′_ : {A : Set a} {B : Set b} {i j k : I} → M i j A → (A → M j k B) → M i k B overlap {{super}} : IApplicative′ {a} {b} M _>>′_ : {A : Set a} {B : Set b} {i j k : I} → M i j A → M j k B → M i k B m >>′ m′ = m >>=′ λ _ → m′ open IMonad′ {{...}} public
29.804348
87
0.478483
2e73b18f34c7f4da0f5e1ffc8217e8faa71b7a31
154
agda
Agda
src/sets/nat/ordering/lt.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
20
2015-06-12T12:20:17.000Z
2022-02-01T11:25:54.000Z
src/sets/nat/ordering/lt.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/sets/nat/ordering/lt.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T12:17:00.000Z
2019-05-04T19:31:00.000Z
{-# OPTIONS --without-K #-} module sets.nat.ordering.lt where open import sets.nat.ordering.lt.core public open import sets.nat.ordering.lt.level public
25.666667
45
0.766234
37c2730fd7d308a7a1e4b3db83fc85078df3336b
15,938
agda
Agda
Everything.agda
iblech/agda-categories
8cd50f92ce3c91dbb325b4b0a66d231df809d0a9
[ "MIT" ]
null
null
null
Everything.agda
iblech/agda-categories
8cd50f92ce3c91dbb325b4b0a66d231df809d0a9
[ "MIT" ]
null
null
null
Everything.agda
iblech/agda-categories
8cd50f92ce3c91dbb325b4b0a66d231df809d0a9
[ "MIT" ]
null
null
null
import Categories.2-Category import Categories.2-Functor import Categories.Adjoint import Categories.Adjoint.AFT import Categories.Adjoint.AFT.SolutionSet import Categories.Adjoint.Alternatives import Categories.Adjoint.Compose import Categories.Adjoint.Construction.EilenbergMoore import Categories.Adjoint.Construction.Kleisli import Categories.Adjoint.Equivalence import Categories.Adjoint.Equivalence.Properties import Categories.Adjoint.Equivalents import Categories.Adjoint.Instance.0-Truncation import Categories.Adjoint.Instance.01-Truncation import Categories.Adjoint.Instance.Core import Categories.Adjoint.Instance.Discrete import Categories.Adjoint.Instance.PosetCore import Categories.Adjoint.Instance.StrictCore import Categories.Adjoint.Mate import Categories.Adjoint.Monadic import Categories.Adjoint.Monadic.Crude import Categories.Adjoint.Monadic.Properties import Categories.Adjoint.Properties import Categories.Adjoint.RAPL import Categories.Adjoint.Relative import Categories.Adjoint.TwoSided import Categories.Adjoint.TwoSided.Compose import Categories.Bicategory import Categories.Bicategory.Bigroupoid import Categories.Bicategory.Construction.1-Category import Categories.Bicategory.Construction.Spans import Categories.Bicategory.Construction.Spans.Properties import Categories.Bicategory.Extras import Categories.Bicategory.Instance.Cats import Categories.Bicategory.Instance.EnrichedCats import Categories.Bicategory.Monad import Categories.Bicategory.Monad.Properties import Categories.Bicategory.Opposite import Categories.Category import Categories.Category.BicartesianClosed import Categories.Category.CMonoidEnriched import Categories.Category.Cartesian import Categories.Category.Cartesian.Properties import Categories.Category.Cartesian.Structure import Categories.Category.CartesianClosed import Categories.Category.CartesianClosed.Canonical import Categories.Category.CartesianClosed.Locally import Categories.Category.CartesianClosed.Locally.Properties import Categories.Category.CartesianClosed.Properties import Categories.Category.Closed import Categories.Category.Cocartesian import Categories.Category.Cocomplete import Categories.Category.Cocomplete.Finitely import Categories.Category.Cocomplete.Finitely.Properties import Categories.Category.Cocomplete.Properties import Categories.Category.Complete import Categories.Category.Complete.Finitely import Categories.Category.Complete.Finitely.Properties import Categories.Category.Complete.Properties import Categories.Category.Complete.Properties.Construction import Categories.Category.Complete.Properties.SolutionSet import Categories.Category.Concrete import Categories.Category.Concrete.Properties import Categories.Category.Construction.0-Groupoid import Categories.Category.Construction.Adjoints import Categories.Category.Construction.Arrow import Categories.Category.Construction.Cocones import Categories.Category.Construction.Comma import Categories.Category.Construction.Cones import Categories.Category.Construction.Coproduct import Categories.Category.Construction.Core import Categories.Category.Construction.Cowedges import Categories.Category.Construction.EilenbergMoore import Categories.Category.Construction.Elements import Categories.Category.Construction.EnrichedFunctors import Categories.Category.Construction.F-Algebras import Categories.Category.Construction.Fin import Categories.Category.Construction.Functors import Categories.Category.Construction.Graphs import Categories.Category.Construction.Grothendieck import Categories.Category.Construction.GroupAsCategory import Categories.Category.Construction.Kleisli import Categories.Category.Construction.MonoidAsCategory import Categories.Category.Construction.Monoids import Categories.Category.Construction.ObjectRestriction import Categories.Category.Construction.Path import Categories.Category.Construction.Presheaves import Categories.Category.Construction.Properties.Comma import Categories.Category.Construction.Properties.EilenbergMoore import Categories.Category.Construction.Properties.Functors import Categories.Category.Construction.Properties.Kleisli import Categories.Category.Construction.Properties.Presheaves import Categories.Category.Construction.Properties.Presheaves.Cartesian import Categories.Category.Construction.Properties.Presheaves.CartesianClosed import Categories.Category.Construction.Properties.Presheaves.Complete import Categories.Category.Construction.Properties.Presheaves.FromCartesianCCC import Categories.Category.Construction.Pullbacks import Categories.Category.Construction.Spans import Categories.Category.Construction.Thin import Categories.Category.Construction.TwistedArrow import Categories.Category.Construction.Wedges import Categories.Category.Core import Categories.Category.Dagger import Categories.Category.Dagger.Construction.Discrete import Categories.Category.Dagger.Instance.Rels import Categories.Category.Diagram.Span import Categories.Category.Discrete import Categories.Category.Duality import Categories.Category.Equivalence import Categories.Category.Equivalence.Preserves import Categories.Category.Equivalence.Properties import Categories.Category.Finite import Categories.Category.Finite.Fin import Categories.Category.Finite.Fin.Construction.Discrete import Categories.Category.Finite.Fin.Construction.Poset import Categories.Category.Finite.Fin.Instance.Parallel import Categories.Category.Finite.Fin.Instance.Span import Categories.Category.Finite.Fin.Instance.Triangle import Categories.Category.Groupoid import Categories.Category.Groupoid.Properties import Categories.Category.Helper import Categories.Category.Indiscrete import Categories.Category.Instance.Cartesians import Categories.Category.Instance.Cats import Categories.Category.Instance.EmptySet import Categories.Category.Instance.FamilyOfSetoids import Categories.Category.Instance.FamilyOfSets import Categories.Category.Instance.FinCatShapes import Categories.Category.Instance.FinSetoids import Categories.Category.Instance.Globe import Categories.Category.Instance.Groupoids import Categories.Category.Instance.LawvereTheories import Categories.Category.Instance.Monoidals import Categories.Category.Instance.One import Categories.Category.Instance.PointedSets import Categories.Category.Instance.Posets import Categories.Category.Instance.Properties.Cats import Categories.Category.Instance.Properties.Posets import Categories.Category.Instance.Properties.Setoids import Categories.Category.Instance.Properties.Setoids.CCC import Categories.Category.Instance.Properties.Setoids.Cocomplete import Categories.Category.Instance.Properties.Setoids.Complete import Categories.Category.Instance.Properties.Setoids.LCCC import Categories.Category.Instance.Properties.Setoids.Limits.Canonical import Categories.Category.Instance.Rels import Categories.Category.Instance.Setoids import Categories.Category.Instance.Sets import Categories.Category.Instance.Simplex import Categories.Category.Instance.SimplicialSet import Categories.Category.Instance.SingletonSet import Categories.Category.Instance.Span import Categories.Category.Instance.StrictCats import Categories.Category.Instance.StrictGroupoids import Categories.Category.Instance.Zero import Categories.Category.Inverse import Categories.Category.Lift import Categories.Category.Monoidal import Categories.Category.Monoidal.Braided import Categories.Category.Monoidal.Braided.Properties import Categories.Category.Monoidal.Closed import Categories.Category.Monoidal.Closed.IsClosed import Categories.Category.Monoidal.Closed.IsClosed.Diagonal import Categories.Category.Monoidal.Closed.IsClosed.Dinatural import Categories.Category.Monoidal.Closed.IsClosed.Identity import Categories.Category.Monoidal.Closed.IsClosed.L import Categories.Category.Monoidal.Closed.IsClosed.Pentagon import Categories.Category.Monoidal.CompactClosed import Categories.Category.Monoidal.Construction.Minus2 import Categories.Category.Monoidal.Core import Categories.Category.Monoidal.Instance.Cats import Categories.Category.Monoidal.Instance.One import Categories.Category.Monoidal.Instance.Rels import Categories.Category.Monoidal.Instance.Setoids import Categories.Category.Monoidal.Instance.Sets import Categories.Category.Monoidal.Instance.StrictCats import Categories.Category.Monoidal.Properties import Categories.Category.Monoidal.Reasoning import Categories.Category.Monoidal.Rigid import Categories.Category.Monoidal.Star-Autonomous import Categories.Category.Monoidal.Structure import Categories.Category.Monoidal.Symmetric import Categories.Category.Monoidal.Traced import Categories.Category.Monoidal.Utilities import Categories.Category.Product import Categories.Category.Product.Properties import Categories.Category.Regular import Categories.Category.RigCategory import Categories.Category.SetoidDiscrete import Categories.Category.Site import Categories.Category.Slice import Categories.Category.Slice.Properties import Categories.Category.Species import Categories.Category.Species.Constructions import Categories.Category.SubCategory import Categories.Category.Topos import Categories.Category.WithFamilies import Categories.CoYoneda import Categories.Comonad import Categories.Comonad.Relative import Categories.Diagram.Cocone import Categories.Diagram.Cocone.Properties import Categories.Diagram.Coend import Categories.Diagram.Coend.Properties import Categories.Diagram.Coequalizer import Categories.Diagram.Coequalizer.Properties import Categories.Diagram.Colimit import Categories.Diagram.Colimit.DualProperties import Categories.Diagram.Colimit.Lan import Categories.Diagram.Colimit.Properties import Categories.Diagram.Cone import Categories.Diagram.Cone.Properties import Categories.Diagram.Cowedge import Categories.Diagram.Cowedge.Properties import Categories.Diagram.Duality import Categories.Diagram.End import Categories.Diagram.End.Properties import Categories.Diagram.Equalizer import Categories.Diagram.Equalizer.Indexed import Categories.Diagram.Equalizer.Limit import Categories.Diagram.Equalizer.Properties import Categories.Diagram.Finite import Categories.Diagram.KernelPair import Categories.Diagram.Limit import Categories.Diagram.Limit.Properties import Categories.Diagram.Limit.Ran import Categories.Diagram.Pullback import Categories.Diagram.Pullback.Limit import Categories.Diagram.Pullback.Properties import Categories.Diagram.Pushout import Categories.Diagram.Pushout.Properties import Categories.Diagram.ReflexivePair import Categories.Diagram.SubobjectClassifier import Categories.Diagram.Wedge import Categories.Diagram.Wedge.Properties import Categories.Enriched.Category import Categories.Enriched.Category.Opposite import Categories.Enriched.Category.Underlying import Categories.Enriched.Functor import Categories.Enriched.NaturalTransformation import Categories.Enriched.NaturalTransformation.NaturalIsomorphism import Categories.Enriched.Over.One import Categories.Enriched.Over.Setoids import Categories.Functor import Categories.Functor.Algebra import Categories.Functor.Bifunctor import Categories.Functor.Bifunctor.Properties import Categories.Functor.Cartesian import Categories.Functor.Cartesian.Properties import Categories.Functor.Coalgebra import Categories.Functor.Construction.Constant import Categories.Functor.Construction.Diagonal import Categories.Functor.Construction.FromDiscrete import Categories.Functor.Construction.LiftSetoids import Categories.Functor.Construction.Limit import Categories.Functor.Construction.ObjectRestriction import Categories.Functor.Construction.SubCategory import Categories.Functor.Construction.SubCategory.Properties import Categories.Functor.Construction.Zero import Categories.Functor.Core import Categories.Functor.Duality import Categories.Functor.Equivalence import Categories.Functor.Fibration import Categories.Functor.Groupoid import Categories.Functor.Hom import Categories.Functor.Hom.Properties import Categories.Functor.Hom.Properties.Contra import Categories.Functor.Hom.Properties.Covariant import Categories.Functor.Instance.0-Truncation import Categories.Functor.Instance.01-Truncation import Categories.Functor.Instance.Core import Categories.Functor.Instance.Discrete import Categories.Functor.Instance.SetoidDiscrete import Categories.Functor.Instance.StrictCore import Categories.Functor.Instance.Twisted import Categories.Functor.Limits import Categories.Functor.Monoidal import Categories.Functor.Monoidal.Properties import Categories.Functor.Monoidal.Symmetric import Categories.Functor.Power import Categories.Functor.Power.Functorial import Categories.Functor.Power.NaturalTransformation import Categories.Functor.Presheaf import Categories.Functor.Profunctor import Categories.Functor.Properties import Categories.Functor.Representable import Categories.Functor.Slice import Categories.GlobularSet import Categories.Kan import Categories.Kan.Duality import Categories.Minus2-Category import Categories.Minus2-Category.Construction.Indiscrete import Categories.Minus2-Category.Instance.One import Categories.Minus2-Category.Properties import Categories.Monad import Categories.Monad.Duality import Categories.Monad.Idempotent import Categories.Monad.Relative import Categories.Monad.Strong import Categories.Morphism import Categories.Morphism.Cartesian import Categories.Morphism.Duality import Categories.Morphism.HeterogeneousIdentity import Categories.Morphism.HeterogeneousIdentity.Properties import Categories.Morphism.IsoEquiv import Categories.Morphism.Isomorphism import Categories.Morphism.Normal import Categories.Morphism.Notation import Categories.Morphism.Properties import Categories.Morphism.Reasoning import Categories.Morphism.Reasoning.Core import Categories.Morphism.Reasoning.Iso import Categories.Morphism.Regular import Categories.Morphism.Universal import Categories.Multi.Category.Indexed import Categories.NaturalTransformation import Categories.NaturalTransformation.Core import Categories.NaturalTransformation.Dinatural import Categories.NaturalTransformation.Equivalence import Categories.NaturalTransformation.Extranatural import Categories.NaturalTransformation.Hom import Categories.NaturalTransformation.Monoidal import Categories.NaturalTransformation.NaturalIsomorphism import Categories.NaturalTransformation.NaturalIsomorphism.Equivalence import Categories.NaturalTransformation.NaturalIsomorphism.Functors import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal import Categories.NaturalTransformation.NaturalIsomorphism.Properties import Categories.NaturalTransformation.Properties import Categories.Object.Biproduct import Categories.Object.Cokernel import Categories.Object.Coproduct import Categories.Object.Duality import Categories.Object.Exponential import Categories.Object.Initial import Categories.Object.Kernel import Categories.Object.Kernel.Properties import Categories.Object.Monoid import Categories.Object.NaturalNumber import Categories.Object.NaturalNumber.Properties.F-Algebras import Categories.Object.Product import Categories.Object.Product.Construction import Categories.Object.Product.Core import Categories.Object.Product.Indexed import Categories.Object.Product.Indexed.Properties import Categories.Object.Product.Limit import Categories.Object.Product.Morphisms import Categories.Object.Subobject import Categories.Object.Subobject.Properties import Categories.Object.Terminal import Categories.Object.Terminal.Limit import Categories.Object.Zero import Categories.Pseudofunctor import Categories.Pseudofunctor.Composition import Categories.Pseudofunctor.Hom import Categories.Pseudofunctor.Identity import Categories.Pseudofunctor.Instance.EnrichedUnderlying import Categories.Tactic.Category import Categories.Theory.Lawvere import Categories.Utils.EqReasoning import Categories.Utils.Product import Categories.Yoneda import Categories.Yoneda.Continuous import Categories.Yoneda.Properties
43.906336
78
0.891454
1923dd637390c9ea86a47261e3d01595686d9dcd
570
agda
Agda
src/Quasigroup/Bundles.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
2
2021-08-15T06:16:13.000Z
2021-08-17T09:14:03.000Z
src/Quasigroup/Bundles.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
2
2021-10-04T05:30:30.000Z
2021-10-09T08:24:56.000Z
src/Quasigroup/Bundles.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Quasigroup.Bundles where open import Algebra.Core open import Quasigroup.Structures open import Relation.Binary open import Level open import Algebra.Bundles open import Algebra.Structures record Pique c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infixl 7 _\\_ infixl 7 _//_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier _\\_ : Op₂ Carrier _//_ : Op₂ Carrier ε : Carrier isPique : IsPique _≈_ _∙_ _\\_ _//_ ε open IsPique isPique public
19.655172
42
0.647368
fd9b082e0f91e02e72240ee7557f367a4a9c3313
2,191
agda
Agda
src/Holes/Test/General.agda
bch29/agda-holes
b5537c29e69febd7e89580398fac38d619aab3b4
[ "MIT" ]
24
2017-01-28T10:56:46.000Z
2021-11-03T15:02:41.000Z
src/Holes/Test/General.agda
bch29/agda-holes
b5537c29e69febd7e89580398fac38d619aab3b4
[ "MIT" ]
2
2019-01-16T10:47:58.000Z
2020-08-31T20:58:33.000Z
src/Holes/Test/General.agda
bch29/agda-holes
b5537c29e69febd7e89580398fac38d619aab3b4
[ "MIT" ]
2
2017-01-27T14:57:39.000Z
2021-02-02T18:57:17.000Z
module Holes.Test.General where open import Holes.Prelude open PropEq using (_≡_; refl; cong; sym; trans) open import Holes.Term using (⌞_⌟) open import Holes.Cong.Propositional private +-zero : ∀ x → x + 0 ≡ x +-zero zero = refl +-zero (suc x) = cong suc (+-zero x) +-suc : ∀ x y → suc (x + y) ≡ x + suc y +-suc zero y = refl +-suc (suc x) y = cong suc (+-suc x y) +-comm : ∀ x y → x + y ≡ y + x +-comm zero y = sym (+-zero y) +-comm (suc x) y = trans (cong suc (+-comm x y)) (+-suc y x) data Fin : ℕ → Set where zero : ∀ {n} → Fin (suc n) suc : ∀ {n} → Fin n → Fin (suc n) -- Expressions with free variables test1 : ∀ x y z → ⌞ x + y ⌟ + z ≡ (y + x) + z test1 x y z = cong! (+-comm x y) -- NOTE: This works, but if you replace `y` by `_` in the above, there are -- unsolved metas! test1′ : ∀ x y z → x + y + z ≡ y + x + z test1′ x y z = cong (λ h → h + z) (+-comm x _) -- Multiple holes test2 : ∀ x y z → x + ⌞ y + z ⌟ * ⌞ y + z ⌟ + y * z ≡ x + (z + y) * (z + y) + y * z test2 x y z = cong! (+-comm y z) -- Picking out one instance of a group of identical sub-expressions test3 : ∀ x y z → x + ⌞ y + z ⌟ * (y + z) + y * z ≡ x + (z + y) * (y + z) + y * z test3 x y z = cong! (+-comm y z) -- Automatic symmetry test4 : ∀ x y z → x + ⌞ y + z ⌟ * (y + z) + y * z ≡ x + (z + y) * (y + z) + y * z test4 x y z = cong! (+-comm z y) -- No hole on the LHS ⇒ hole around everything (notice automatic symmetry application) test5 : ∀ x y → x + y ≡ y + x test5 x y = cong! (+-comm y x) -- Works in Π types test6 : ∀ x y → (Fin ⌞ x + y ⌟ → ℕ) ≡ (Fin ⌞ y + x ⌟ → ℕ) test6 x y = cong! (+-comm x y) -- Constructors on the path test7 : ∀ x y → ℕ.suc ⌞ x + y ⌟ ≡ suc (y + x) test7 x y = cong! (+-comm x y) -- -- Fails with a nice error message when holes contain different terms -- fail1 : ∀ x y z → y ≡ x → ⌞ x ⌟ + ⌞ y ⌟ + z ≡ x + x + z -- fail1 x y z eq = cong! eq -- -- This is only provable in the presence of functional extensionality, so the -- -- macro should obviously fail here. It would be nice if the error message -- -- were improved though. -- fail2 : ∀ (x y : ℕ) → (λ (f : ℕ → ℕ) → ⌞ f x + f y ⌟) ≡ (λ f → f y + f x) -- fail2 x y = cong! (+-comm _ _)
32.220588
86
0.531264
21ac19de552de4a3588a86e161ea144b5a45ee72
330
agda
Agda
Cats/Category/Constructions/Mono.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
Cats/Category/Constructions/Mono.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
Cats/Category/Constructions/Mono.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
module Cats.Category.Constructions.Mono where open import Level open import Cats.Category.Base module Build {lo la l≈} (Cat : Category lo la l≈) where private open module Cat = Category Cat open Cat.≈-Reasoning IsMono : ∀ {A B} → A ⇒ B → Set (lo ⊔ la ⊔ l≈) IsMono {A} f = ∀ {C} {g h : C ⇒ A} → f ∘ g ≈ f ∘ h → g ≈ h
22
60
0.612121
37d2b2326533017a620ddc363c565c735dbd0a6b
154
agda
Agda
test/interaction/Issue1494/Helper.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1494/Helper.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1494/Helper.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue1494.Helper where record Record : Set₁ where field _≡_ : {A : Set} → A → A → Set module Module (r : Record) where open Record r public
17.111111
37
0.675325
0d41c817c6dd01f37c037d8d912c8399f58bfb70
215
agda
Agda
prototyping/Properties/Product.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
1
2021-12-05T21:53:03.000Z
2021-12-05T21:53:03.000Z
prototyping/Properties/Product.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
prototyping/Properties/Product.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
module Properties.Product where infixr 5 _×_ _,_ record Σ {A : Set} (B : A → Set) : Set where constructor _,_ field fst : A field snd : B fst open Σ public _×_ : Set → Set → Set A × B = Σ (λ (a : A) → B)
14.333333
44
0.586047
30c94aecd33299100ccbcd687356b2bcd5cc3d54
14,104
agda
Agda
Cubical/ZCohomology/KcompPrelims.agda
knrafto/cubical
f6771617374bfe65a7043d00731fed5a673aa729
[ "MIT" ]
null
null
null
Cubical/ZCohomology/KcompPrelims.agda
knrafto/cubical
f6771617374bfe65a7043d00731fed5a673aa729
[ "MIT" ]
null
null
null
Cubical/ZCohomology/KcompPrelims.agda
knrafto/cubical
f6771617374bfe65a7043d00731fed5a673aa729
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.ZCohomology.KcompPrelims where open import Cubical.ZCohomology.Base open import Cubical.Homotopy.Connected open import Cubical.HITs.Hopf open import Cubical.Homotopy.Freudenthal hiding (encode) open import Cubical.HITs.Sn open import Cubical.HITs.S1 open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; map to trMap) open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Univalence open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Data.Int renaming (_+_ to +Int) open import Cubical.Data.Nat open import Cubical.HITs.Susp open import Cubical.HITs.Nullification open import Cubical.Data.Prod.Base open import Cubical.Homotopy.Loopspace open import Cubical.Data.Bool open import Cubical.Data.Sum.Base open import Cubical.Data.Sigma hiding (_×_) open import Cubical.Foundations.Function open import Cubical.Foundations.Pointed open import Cubical.HITs.S3 private variable ℓ ℓ' : Level A : Type ℓ B : Type ℓ' {- We want to prove that Kn≃ΩKn+1. For this we use the map ϕ-} ϕ : (pt a : A) → typ (Ω (Susp A , north)) ϕ pt a = (merid a) ∙ sym (merid pt) {- To define the map for n=0 we use the λ k → loopᵏ map for S₊ 1. The loop is given by ϕ north south -} loop* : Path (S₊ 1) north north loop* = ϕ north south looper : Int → Path (S₊ 1) north north looper (pos zero) = refl looper (pos (suc n)) = looper (pos n) ∙ loop* looper (negsuc zero) = sym loop* looper (negsuc (suc n)) = looper (negsuc n) ∙ sym loop* private {- The map of Kn≃ΩKn+1 is given as follows. -} Kn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n))) Kn→ΩKn+1 zero x = cong ∣_∣ (looper x) Kn→ΩKn+1 (suc n) = trRec (isOfHLevelTrunc (2 + (suc (suc n))) ∣ north ∣ ∣ north ∣) λ a → cong ∣_∣ ((merid a) ∙ (sym (merid north))) {- We show that looper is a composition of intLoop with two other maps, all three being isos -} sndcomp : ΩS¹ → Path (Susp Bool) north north sndcomp = cong S¹→SuspBool thrdcomp : Path (Susp Bool) north north → Path (S₊ 1) north north thrdcomp = cong SuspBool→S1 looper2 : Int → Path (S₊ 1) north north looper2 a = thrdcomp (sndcomp (intLoop a)) looper≡looper2 : (x : Int) → looper x ≡ looper2 x looper≡looper2 (pos zero) = refl looper≡looper2 (pos (suc n)) = looper (pos n) ∙ loop* ≡⟨ (λ i → looper≡looper2 (pos n) i ∙ congFunct SuspBool→S1 (merid false) (sym (merid true)) (~ i)) ⟩ looper2 (pos n) ∙ cong SuspBool→S1 (ϕ true false) ≡⟨ sym (congFunct SuspBool→S1 (sndcomp (intLoop (pos n))) (ϕ true false)) ⟩ cong SuspBool→S1 (sndcomp (intLoop (pos n)) ∙ ϕ true false) ≡⟨ cong thrdcomp (sym (congFunct S¹→SuspBool (intLoop (pos n)) loop)) ⟩ looper2 (pos (suc n)) ∎ looper≡looper2 (negsuc zero) = sym loop* ≡⟨ symDistr (merid south) (sym (merid north)) ⟩ merid north ∙ sym (merid south) ≡⟨ sym (congFunct SuspBool→S1 (merid true) (sym (merid false))) ⟩ cong SuspBool→S1 (merid true ∙ sym (merid false)) ≡⟨ cong thrdcomp (sym (symDistr (merid false) (sym (merid true)))) ⟩ looper2 (negsuc zero) ∎ looper≡looper2 (negsuc (suc n)) = looper (negsuc n) ∙ sym loop* ≡⟨ ((λ i → looper≡looper2 (negsuc n) i ∙ symDistr (merid south) (sym (merid north)) i)) ⟩ looper2 (negsuc n) ∙ merid north ∙ sym (merid south) ≡⟨ cong (λ x → looper2 (negsuc n) ∙ x) (sym (congFunct SuspBool→S1 (merid true) (sym (merid false)))) ⟩ looper2 (negsuc n) ∙ cong SuspBool→S1 (ϕ false true) ≡⟨ cong (λ x → looper2 (negsuc n) ∙ x) (cong thrdcomp (sym (symDistr (merid false) (sym (merid true))))) ⟩ looper2 (negsuc n) ∙ cong SuspBool→S1 (sym (ϕ true false)) ≡⟨ sym (congFunct SuspBool→S1 (sndcomp (intLoop (negsuc n))) (sym (ϕ true false))) ⟩ thrdcomp (cong S¹→SuspBool (intLoop (negsuc n)) ∙ cong S¹→SuspBool (sym loop)) ≡⟨ cong thrdcomp (sym (congFunct S¹→SuspBool (intLoop (negsuc n)) (sym loop))) ⟩ looper2 (negsuc (suc n)) ∎ private isolooper2 : Iso Int (Path (S₊ 1) north north) isolooper2 = compIso (invIso ΩS¹IsoInt) (compIso iso2 iso1) where iso1 : Iso (Path (Susp Bool) north north) (Path (S₊ 1) north north) iso1 = congIso SuspBoolIsoS1 iso2 : Iso ΩS¹ (Path (Susp Bool) north north) iso2 = congIso S¹IsoSuspBool isolooper : Iso Int (Path (S₊ 1) north north) Iso.fun isolooper = looper Iso.inv isolooper = Iso.inv isolooper2 Iso.rightInv isolooper a = (looper≡looper2 (Iso.inv isolooper2 a)) ∙ Iso.rightInv isolooper2 a Iso.leftInv isolooper a = cong (Iso.inv isolooper2) (looper≡looper2 a) ∙ Iso.leftInv isolooper2 a {- We want to show that this map is an equivalence. n ≥ 2 follows from Freudenthal, and -} {- We want to show that the function (looper : Int → S₊ 1) defined by λ k → loopᵏ is an equivalece. We already know that the corresponding function (intLoop : Int → S¹ is) an equivalence, so the idea is to show that when intLoop is transported along a suitable path S₊ 1 ≡ S¹ we get looper. Instead of using S₊ 1 straight away, we begin by showing this for the equivalent Susp Bool. -} ----------------------------------- n = 1 ----------------------------------------------------- {- We begin by stating some useful lemmas -} S³≡SuspSuspS¹ : S³ ≡ Susp (Susp S¹) S³≡SuspSuspS¹ = S³≡SuspS² ∙ λ i → Susp (S²≡SuspS¹ i) S3≡SuspSuspS¹ : S₊ 3 ≡ Susp (Susp S¹) S3≡SuspSuspS¹ = (λ i → Susp (Susp (Susp (ua Bool≃Susp⊥ (~ i))))) ∙ λ i → Susp (Susp (S¹≡SuspBool (~ i))) sphereConnectedSpecCase : isConnected 4 (Susp (Susp S¹)) sphereConnectedSpecCase = transport (λ i → isConnected 4 (S3≡SuspSuspS¹ i)) (sphereConnected 3) {- We give the following map and show that its truncation is an equivalence -} d-map : typ (Ω ((Susp S¹) , north)) → S¹ d-map p = subst HopfSuspS¹ p base d-mapId : (r : S¹) → d-map (ϕ base r) ≡ r d-mapId r = substComposite HopfSuspS¹ (merid r) (sym (merid base)) base ∙ rotLemma r where rotLemma : (r : S¹) → rot r base ≡ r rotLemma base = refl rotLemma (loop i) = refl d-mapComp : fiber d-map base ≡ Path (Susp (Susp S¹)) north north d-mapComp = ΣPathTransport≡PathΣ {B = HopfSuspS¹} _ _ ∙ helper where helper : Path (Σ (Susp S¹) λ x → HopfSuspS¹ x) (north , base) (north , base) ≡ Path (Susp (Susp S¹)) north north helper = (λ i → (Path (S³≡TotalHopf (~ i)) (transp (λ j → S³≡TotalHopf (~ i ∨ ~ j)) (~ i) (north , base)) ((transp (λ j → S³≡TotalHopf (~ i ∨ ~ j)) (~ i) (north , base))))) ∙ (λ i → Path (S³≡SuspSuspS¹ i) (transp (λ j → S³≡SuspSuspS¹ (i ∧ j)) (~ i) base) ((transp (λ j → S³≡SuspSuspS¹ (i ∧ j)) (~ i) base))) is1Connected-dmap : isConnectedFun 3 d-map is1Connected-dmap = toPropElim (λ s → isPropIsOfHLevel 0) (transport (λ j → isContr (∥ d-mapComp (~ j) ∥ 3)) (transport (λ i → isContr (PathΩ {A = Susp (Susp S¹)} {a = north} 3 i)) (refl , isOfHLevelSuc 1 (isOfHLevelSuc 0 sphereConnectedSpecCase) ∣ north ∣ ∣ north ∣ (λ _ → ∣ north ∣)))) d-iso2 : Iso (hLevelTrunc 3 (typ (Ω (Susp S¹ , north)))) (hLevelTrunc 3 S¹) d-iso2 = connectedTruncIso _ d-map is1Connected-dmap {- We show that composing (λ a → ∣ ϕ base a ∣) and (λ x → ∣ d-map x ∣) gives us the identity function. -} d-mapId2 : Iso.fun d-iso2 ∘ trMap (ϕ base) ≡ idfun (hLevelTrunc 3 S¹) d-mapId2 = funExt (trElim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) (λ a → cong ∣_∣ (d-mapId a))) {- This means that (λ a → ∣ ϕ base a ∣) is an equivalence -} Iso∣ϕ-base∣ : Iso (hLevelTrunc 3 S¹) (hLevelTrunc 3 (typ (Ω (Susp S¹ , north)))) Iso∣ϕ-base∣ = composesToId→Iso d-iso2 (trMap (ϕ base)) d-mapId2 --------------------------------- -- We cheat when n = 1 and use J to prove the following lemmma. There is an obvious dependent path between ϕ base and ϕ north. Since the first one is an iso, so is the other. -- So far this hasn't been an issue. pointFunIso : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ} {C : (A : Type ℓ) (a1 : A) → Type ℓ'} (p : A ≡ B) (a : A) (b : B) → (transport p a ≡ b) → (f : (A : Type ℓ) → (a1 : A) (a2 : hLevelTrunc 3 A) → C A a1) → isIso (f A a) → isIso (f B b) pointFunIso {ℓ = ℓ}{A = A} {B = B} {C = C} = J (λ B p → (a : A) (b : B) → (transport p a ≡ b) → (f : (A : Type ℓ) → (a1 : A) (a2 : hLevelTrunc 3 A) → C A a1) → isIso (f A a) → isIso (f B b)) λ a b trefl f is → transport (λ i → isIso (f A ((sym (transportRefl a) ∙ trefl) i))) is {- By pointFunIso, this gives that λ a → ∣ ϕ north a ∣ is an iso -} isIso∣ϕ∣ : isIso {A = hLevelTrunc 3 (S₊ 1)} {B = hLevelTrunc 3 (typ (Ω (S₊ 2 , north)))} (trMap (ϕ north)) isIso∣ϕ∣ = pointFunIso {A = S¹} (λ i → S¹≡S1 (~ i)) base north refl (λ A a1 → trMap (ϕ a1)) ((Iso.inv Iso∣ϕ-base∣) , ((Iso.rightInv Iso∣ϕ-base∣) , (Iso.leftInv Iso∣ϕ-base∣))) Iso∣ϕ∣ : Iso (hLevelTrunc 3 (S₊ 1)) (hLevelTrunc 3 (typ (Ω (S₊ 2 , north)))) Iso.fun Iso∣ϕ∣ = trMap (ϕ north) Iso.inv Iso∣ϕ∣ = isIso∣ϕ∣ .fst Iso.rightInv Iso∣ϕ∣ = isIso∣ϕ∣ .snd .fst Iso.leftInv Iso∣ϕ∣ = isIso∣ϕ∣ .snd .snd ---------------------------------------------------- Finishing up --------------------------------- -- We need ΩTrunc. It appears to compute better when restated for this particular case -- decode-fun2 : (n : HLevel) → (x : A) → hLevelTrunc n (x ≡ x) → Path (hLevelTrunc (suc n) A) ∣ x ∣ ∣ x ∣ decode-fun2 zero x = trElim (λ _ → isOfHLevelPath 0 (∣ x ∣ , isOfHLevelTrunc 1 ∣ x ∣) ∣ x ∣ ∣ x ∣) (λ p i → ∣ p i ∣) decode-fun2 (suc n) x = trElim (λ _ → isOfHLevelPath' (suc n) (isOfHLevelTrunc (suc (suc n))) ∣ x ∣ ∣ x ∣) (cong ∣_∣) funsAreSame : (n : HLevel) (x : A) (b : hLevelTrunc n (x ≡ x)) → (decode-fun2 n x b) ≡ (ΩTrunc.decode-fun ∣ x ∣ ∣ x ∣ b) funsAreSame zero x = trElim (λ a → isOfHLevelPath 0 (refl , (isOfHLevelSuc 1 (isOfHLevelTrunc 1) ∣ x ∣ ∣ x ∣ refl)) _ _) λ a → refl funsAreSame (suc n) x = trElim (λ a → isOfHLevelPath _ (isOfHLevelPath' (suc n) (isOfHLevelTrunc (suc (suc n))) ∣ x ∣ ∣ x ∣) _ _) λ a → refl decodeIso : (n : HLevel) (x : A) → Iso (hLevelTrunc n (x ≡ x)) (Path (hLevelTrunc (suc n) A) ∣ x ∣ ∣ x ∣) Iso.fun (decodeIso n x) = decode-fun2 n x Iso.inv (decodeIso n x) = ΩTrunc.encode-fun ∣ x ∣ ∣ x ∣ Iso.rightInv (decodeIso n x) b = funsAreSame n x (ΩTrunc.encode-fun ∣ x ∣ ∣ x ∣ b) ∙ ΩTrunc.P-rinv ∣ x ∣ ∣ x ∣ b Iso.leftInv (decodeIso n x) b = cong (ΩTrunc.encode-fun ∣ x ∣ ∣ x ∣) (funsAreSame n x b) ∙ ΩTrunc.P-linv ∣ x ∣ ∣ x ∣ b Iso-Kn-ΩKn+1 : (n : HLevel) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n)))) Iso-Kn-ΩKn+1 zero = compIso isolooper (congIso (truncIdempotentIso _ isOfHLevelS1)) Iso-Kn-ΩKn+1 (suc zero) = compIso Iso∣ϕ∣ (decodeIso _ north) Iso-Kn-ΩKn+1 (suc (suc n)) = compIso (connectedTruncIso2 (4 + n) _ (ϕ north) (n , helper) (isConnectedσ (suc n) (sphereConnected _))) (decodeIso _ north) where helper : n + (4 + n) ≡ 2 + (n + (2 + n)) helper = +-suc n (3 + n) ∙ (λ i → suc (+-suc n (2 + n) i)) mapId2 : (n : ℕ) → Kn→ΩKn+1 n ≡ Iso.fun (Iso-Kn-ΩKn+1 n) mapId2 zero = refl mapId2 (suc zero) = funExt (trElim (λ x → isOfHLevelPath 3 (isOfHLevelTrunc 4 ∣ north ∣ ∣ north ∣) _ _) λ a → refl) mapId2 (suc (suc n)) = funExt (trElim (λ x → isOfHLevelPath (4 + n) (isOfHLevelTrunc (5 + n) ∣ north ∣ ∣ north ∣) _ _) λ a → refl) -- Experiments with abstract definitions Iso2-Kn-ΩKn+1 : (n : ℕ) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n)))) Iso.fun (Iso2-Kn-ΩKn+1 n) = Kn→ΩKn+1 n Iso.inv (Iso2-Kn-ΩKn+1 n) = Iso.inv (Iso-Kn-ΩKn+1 n) Iso.rightInv (Iso2-Kn-ΩKn+1 n) a = rinv where abstract rinv : Kn→ΩKn+1 n (Iso.inv (Iso-Kn-ΩKn+1 n) a) ≡ a rinv = funExt⁻ (mapId2 n) _ ∙ Iso.rightInv (Iso-Kn-ΩKn+1 n) a Iso.leftInv (Iso2-Kn-ΩKn+1 n) a = linv where abstract linv : Iso.inv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n a) ≡ a linv = cong (Iso.inv (Iso-Kn-ΩKn+1 n)) (funExt⁻ (mapId2 n) a) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 n) a --- even more abstract abstract absInv' : (n : ℕ) → typ (Ω (coHomK-ptd (2 + n))) → coHomK (1 + n) absInv' n = Iso.inv (Iso-Kn-ΩKn+1 (1 + n)) absSect' : (n : ℕ) (a : typ (Ω (coHomK-ptd (2 + n)))) → Kn→ΩKn+1 (1 + n) (absInv' n a) ≡ a absSect' n a = funExt⁻ (mapId2 (1 + n)) _ ∙ Iso.rightInv (Iso-Kn-ΩKn+1 (1 + n)) a absRetr' : (n : ℕ) (a : coHomK (1 + n)) → absInv' n (Kn→ΩKn+1 (1 + n) a) ≡ a absRetr' n a = cong (Iso.inv (Iso-Kn-ΩKn+1 (1 + n))) (funExt⁻ (mapId2 (1 + n)) a) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 (1 + n)) a absInv : (n : ℕ) → typ (Ω (coHomK-ptd (1 + n))) → coHomK n absInv zero = Iso.inv (Iso-Kn-ΩKn+1 zero) absInv (suc n) = absInv' n absSect : (n : ℕ) → section (Kn→ΩKn+1 n) (absInv n) absSect zero a = funExt⁻ (mapId2 zero) (Iso.inv isolooper2 (Iso.inv (congIso (truncIdempotentIso _ isOfHLevelS1)) a)) ∙ Iso.rightInv (Iso-Kn-ΩKn+1 zero) a absSect (suc n) = absSect' n absRetr : (n : ℕ) → retract (Kn→ΩKn+1 n) (absInv n) absRetr zero a = cong (Iso.inv (Iso-Kn-ΩKn+1 zero)) (funExt⁻ (mapId2 zero) a) ∙ Iso.leftInv (Iso-Kn-ΩKn+1 zero) a absRetr (suc n) = absRetr' n Iso3-Kn-ΩKn+1 : (n : ℕ) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n)))) Iso.fun (Iso3-Kn-ΩKn+1 n) = Kn→ΩKn+1 n Iso.inv (Iso3-Kn-ΩKn+1 n) = absInv n Iso.rightInv (Iso3-Kn-ΩKn+1 n) = absSect n Iso.leftInv (Iso3-Kn-ΩKn+1 n) = absRetr n
47.648649
196
0.59118
0d697237a50883761d0f55a990562f27694c173d
3,242
agda
Agda
BFFPlug.agda
jvoigtlaender/bidiragda
a5abbd177f032523d1d9d3fa4b9137aefe88dee0
[ "MIT" ]
null
null
null
BFFPlug.agda
jvoigtlaender/bidiragda
a5abbd177f032523d1d9d3fa4b9137aefe88dee0
[ "MIT" ]
null
null
null
BFFPlug.agda
jvoigtlaender/bidiragda
a5abbd177f032523d1d9d3fa4b9137aefe88dee0
[ "MIT" ]
null
null
null
open import Level using () renaming (zero to ℓ₀) open import Relation.Binary using (DecSetoid) module BFFPlug (A : DecSetoid ℓ₀ ℓ₀) where open import Data.Nat using (ℕ ; _≟_ ; _+_ ; zero ; suc ; ⌈_/2⌉) open import Data.Maybe using (Maybe ; just ; nothing) open import Data.Vec using (Vec) open import Data.Product using (∃ ; _,_) open import Relation.Binary using (module DecSetoid) open import Relation.Binary.PropositionalEquality using (refl ; cong ; subst ; sym ; module ≡-Reasoning) renaming (setoid to PropEq) open import Relation.Nullary using (yes ; no) open import Function using (flip ; id ; _∘_) open import Function.LeftInverse using (_RightInverseOf_) import Category.Monad open Category.Monad.RawMonad {ℓ₀} Data.Maybe.monad using (_>>=_) open import Generic using (sequenceV ; ≡-to-Π) import BFF import GetTypes import Examples open DecSetoid A using (Carrier) open GetTypes.PartialVecVec public using (Get) open BFF.PartialVecBFF A public using (sbff ; bff) bffsameshape : (G : Get) → {i : Get.I G} → Vec Carrier (Get.gl₁ G i) → Vec Carrier (Get.gl₂ G i) → Maybe (Vec Carrier (Get.gl₁ G i)) bffsameshape G {i} = sbff G i bffplug : (G : Get) → (Get.I G → ℕ → Maybe (Get.I G)) → {i : Get.I G} → {m : ℕ} → Vec Carrier (Get.gl₁ G i) → Vec Carrier m → Maybe (∃ λ j → Vec (Maybe Carrier) (Get.gl₁ G j)) bffplug G sput {i} {m} s v with sput i m ... | nothing = nothing ... | just j with Get.gl₂ G j ≟ m ... | no gl₂j≢m = nothing bffplug G sput {i} s v | just j | yes refl with bff G j s v ... | nothing = nothing ... | just s′ = just (j , s′) _SimpleRightInvOf_ : {A B : Set} → (A → B) → (B → A) → Set f SimpleRightInvOf g = ≡-to-Π f RightInverseOf ≡-to-Π g bffinv : (G : Get) → (nelteg : ℕ → Get.I G) → nelteg SimpleRightInvOf Get.gl₂ G → {i : Get.I G} → {m : ℕ} → Vec Carrier (Get.gl₁ G i) → Vec Carrier m → Maybe (Vec (Maybe Carrier) (Get.gl₁ G (nelteg m))) bffinv G nelteg inv {m = m} s v = bff G (nelteg m) s (subst (Vec Carrier) (sym (inv m)) v) module InvExamples where open Examples using (reverse' ; drop' ; sieve' ; tail' ; take') reverse-put : {n m : ℕ} → Vec Carrier n → Vec Carrier m → Maybe (Vec Carrier m) reverse-put s v = bffinv reverse' id (λ _ → refl) s v >>= sequenceV drop-put : (k : ℕ) → {n m : ℕ} → Vec Carrier (k + n) → Vec Carrier m → Maybe (Vec (Maybe Carrier) (k + m)) drop-put k = bffinv (drop' k) id (λ _ → refl) double : ℕ → ℕ double zero = zero double (suc n) = suc (suc (double n)) sieve-inv-len : double SimpleRightInvOf ⌈_/2⌉ sieve-inv-len zero = refl sieve-inv-len (suc zero) = refl sieve-inv-len (suc (suc x)) = cong (suc ∘ suc) (sieve-inv-len x) sieve-put : {n m : ℕ} → Vec Carrier n → Vec Carrier m → Maybe (Vec (Maybe Carrier) (double m)) sieve-put = bffinv sieve' double sieve-inv-len tail-put : {n m : ℕ} → Vec Carrier (suc n) → Vec Carrier m → Maybe (Vec (Maybe Carrier) (suc m)) tail-put = bffinv tail' id (λ _ → refl) take-put : (k : ℕ) → {n : ℕ} → Vec Carrier (k + n) → Vec Carrier k → Maybe (Vec Carrier (k + n)) take-put k = bffsameshape (take' k)
45.661972
202
0.6095
0dee53a0240d0e12611ed56c29e8f11cac048c0b
306
agda
Agda
Chapter1/#13.agda
CodaFi/HoTT-Exercises
3411b253b0a49a5f9c3301df175ae8ecdc563b12
[ "MIT" ]
null
null
null
Chapter1/#13.agda
CodaFi/HoTT-Exercises
3411b253b0a49a5f9c3301df175ae8ecdc563b12
[ "MIT" ]
null
null
null
Chapter1/#13.agda
CodaFi/HoTT-Exercises
3411b253b0a49a5f9c3301df175ae8ecdc563b12
[ "MIT" ]
null
null
null
module #13 where {- Using propositions-as-types, derive the double negation of the principle of excluded middle, i.e. prove not (not (P or not P)). -} open import Data.Sum open import Relation.Nullary excluded-middle : (P : Set) → ¬ (¬ (P ⊎ (¬ P))) excluded-middle P z = z (inj₂ (λ x → z (inj₁ x)))
23.538462
86
0.656863
36f51438b9fb0465105b3715bf0aadb841a967fb
23
agda
Agda
src/bstd/bash.agda
semenov-vladyslav/bstd
fe95ba440099f9cf086096469133576a9652c122
[ "MIT" ]
1
2019-06-29T10:40:15.000Z
2019-06-29T10:40:15.000Z
src/bstd/bash.agda
semenov-vladyslav/bstd
fe95ba440099f9cf086096469133576a9652c122
[ "MIT" ]
null
null
null
src/bstd/bash.agda
semenov-vladyslav/bstd
fe95ba440099f9cf086096469133576a9652c122
[ "MIT" ]
null
null
null
module bstd.bash where
11.5
22
0.826087
4384d9fd3e260f6748c22b7b2c9be7590058a890
519
agda
Agda
test/Succeed/SameMeta.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/SameMeta.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/SameMeta.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2011-04-15 -- {-# OPTIONS -v tc.meta:20 #-} module SameMeta where infix 10 _≡_ data _≡_ {A : Set}(a : A) : A -> Set where refl : a ≡ a infixr 5 _×_ _,_ data _×_ (A B : Set) : Set where _,_ : A -> B -> A × B postulate A : Set same : let X : A -> A -> A -> A × A X = _ in {x y z : A} -> X x y y ≡ (x , y) × X x x y ≡ X x y y same = refl , refl -- second equation triggers pruning of second variable of X -- which makes the first equation linear and solvable
21.625
59
0.526012
03e717d570ce2c93c6998feb759dfdffb1dbb1c5
1,540
agda
Agda
Cubical/Reflection/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Reflection/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Reflection/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{- Some basic utilities for reflection -} {-# OPTIONS --cubical --no-exact-split --safe #-} module Cubical.Reflection.Base where open import Cubical.Foundations.Prelude open import Cubical.Data.List.Base open import Cubical.Data.Nat.Base import Agda.Builtin.Reflection as R open import Agda.Builtin.String _>>=_ = R.bindTC _<|>_ = R.catchTC _$_ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (A → B) → A → B f $ a = f a _>>_ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → R.TC A → R.TC B → R.TC B f >> g = f >>= λ _ → g infixl 4 _>>=_ _>>_ _<|>_ infixr 3 _$_ liftTC : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (A → B) → R.TC A → R.TC B liftTC f ta = ta >>= λ a → R.returnTC (f a) v : ℕ → R.Term v n = R.var n [] pattern varg t = R.arg (R.arg-info R.visible (R.modality R.relevant R.quantity-ω)) t pattern harg t = R.arg (R.arg-info R.hidden (R.modality R.relevant R.quantity-ω)) t pattern _v∷_ a l = varg a ∷ l pattern _h∷_ a l = harg a ∷ l infixr 5 _v∷_ _h∷_ vlam : String → R.Term → R.Term vlam str t = R.lam R.visible (R.abs str t) hlam : String → R.Term → R.Term hlam str t = R.lam R.hidden (R.abs str t) newMeta = R.checkType R.unknown extend*Context : ∀ {ℓ} {A : Type ℓ} → List (R.Arg R.Type) → R.TC A → R.TC A extend*Context [] tac = tac extend*Context (a ∷ as) tac = R.extendContext a (extend*Context as tac) makeAuxiliaryDef : String → R.Type → R.Term → R.TC R.Term makeAuxiliaryDef s ty term = R.freshName s >>= λ name → R.declareDef (varg name) ty >> R.defineFun name [ R.clause [] [] term ] >> R.returnTC (R.def name [])
26.101695
84
0.618831
1937ed508e03fd865675c6bd3c795b24e3c589e2
8,416
agda
Agda
Basic/Axiomatic/Total.agda
AndrasKovacs/SemanticsWithApplications
05200d60b4a4b2c6fa37806ced9247055d24db94
[ "MIT" ]
8
2016-09-12T04:25:39.000Z
2020-02-02T10:01:52.000Z
Basic/Axiomatic/Total.agda
AndrasKovacs/SemanticsWithApplications
05200d60b4a4b2c6fa37806ced9247055d24db94
[ "MIT" ]
null
null
null
Basic/Axiomatic/Total.agda
AndrasKovacs/SemanticsWithApplications
05200d60b4a4b2c6fa37806ced9247055d24db94
[ "MIT" ]
null
null
null
module Basic.Axiomatic.Total where open import Data.Bool hiding (not; if_then_else_; _∧_) open import Data.Vec hiding ([_]; _++_; split) open import Function open import Relation.Binary.PropositionalEquality open import Data.Product renaming (map to prodMap) open import Data.Nat open import Relation.Nullary open import Data.Empty import Level as L open import Utils.Decidable open import Basic.AST open import Basic.BigStep {- Total axiomatic correctness (The first part of chapter 6.4). For general notes on axiomatic correctness see Partial.agda The most interesting part is here is the proof of completeness (exercise 6.33). -} _∧_ : ∀ {α β γ}{A : Set α} → (A → Set β) → (A → Set γ) → (A → Set _) _∧_ f g x = f x × g x _==>_ : ∀ {α β γ}{A : Set α} → (A → Set β) → (A → Set γ) → Set _ _==>_ f g = ∀ {x} → f x → g x infixr 4 _,_ data 〈_〉_〈_〉 {n} : (State n → Set) → St n → (State n → Set) → Set₁ where skip : ∀ {P} → ----------------- 〈 P 〉 skip 〈 P 〉 ass : ∀ {x a P} → ---------------------------------------------- 〈 (λ s → P (s [ x ]≔ ⟦ a ⟧ᵉ s)) 〉 x := a 〈 P 〉 _,_ : ∀ {P Q R S₁ S₂} → 〈 P 〉 S₁ 〈 Q 〉 → 〈 Q 〉 S₂ 〈 R 〉 → -------------------------------- 〈 P 〉 S₁ , S₂ 〈 R 〉 if : ∀ {P Q b S₁ S₂} → 〈 (T ∘ ⟦ b ⟧ᵉ) ∧ P 〉 S₁ 〈 Q 〉 → 〈 (F ∘ ⟦ b ⟧ᵉ) ∧ P 〉 S₂ 〈 Q 〉 → -------------------------------------------------------------- 〈 P 〉 if b then S₁ else S₂ 〈 Q 〉 {- This is the only difference between the partial and total system. The definition is exactly the same as in the book. -} while : ∀ {b S} → (P : ℕ → State n → Set) → (∀ n → P (suc n) ==> (T ∘ ⟦ b ⟧ᵉ)) → (P 0 ==> (F ∘ ⟦ b ⟧ᵉ)) → (∀ n → 〈 P (suc n) 〉 S 〈 P n 〉) → --------------------------------- 〈 (λ s → ∃ λ n → P n s) 〉 while b do S 〈 P 0 〉 cons : ∀ {P' Q' P Q S} → P ==> P' → 〈 P' 〉 S 〈 Q' 〉 → Q' ==> Q → ----------------------------------------- 〈 P 〉 S 〈 Q 〉 -- Weakest precondition ------------------------------------------------------------ wp : ∀ {n} → St n → (State n → Set) → State n → Set wp S Q s = ∃ λ s' → ⟨ S , s ⟩⟱ s' × Q s' -- Soundness ------------------------------------------------------------ {- This is more complicated than the soundess proof for the partial system, because we have to construct an actual big-step derivation. In the "if" case we have to evaluate the branch condition to see whether we should return an "if-true" or an "if-false" derivation. In the "while" case we recurse on the natural number "measure" of the loop, building an appropriately sized derivation for the loop -} sound : ∀ {n}{S : St n}{P Q} → 〈 P 〉 S 〈 Q 〉 → (P ==> wp S Q) sound skip ps = _ , skip , ps sound ass ps = _ , ass , ps sound (p , p₁) ps with sound p ps ... | s' , runp , qs' with sound p₁ qs' ... | s'' , runp₁ , qs'' = s'' , (runp , runp₁) , qs'' sound (if {b = b} p p₁) {s} ps with ⟦ b ⟧ᵉ s | inspect ⟦ b ⟧ᵉ s ... | true | [ b≡true ] = let Tb = ≡true→T b≡true in prodMap id (λ x₁ → (if-true Tb (proj₁ x₁)) , (proj₂ x₁)) (sound p {s} (Tb , ps)) ... | false | [ b≡false ] = let Fb = ≡false→F b≡false in prodMap id (λ x₁ → (if-false Fb (proj₁ x₁)) , (proj₂ x₁)) (sound p₁ {s} (Fb , ps)) sound (while{b = b}{S = S} P pre post decr) {s} (start , ps) = go s start ps where go : ∀ s n → P n s → wp (while b do S) (P 0) s go s zero ps = s , while-false (post ps) , ps go s (suc n) ps with sound (decr n) ps ... | s' , runS , ps' with go s' n ps' ... | s'' , runW , ps'' = s'' , while-true (pre n ps) runS runW , ps'' sound (cons x p x₁) ps with sound p (x ps) ... | s' , runp , qs' = s' , runp , x₁ qs' -- Completeness ------------------------------------------------------------ complete : ∀ {n}(S : St n){P Q} → (P ==> wp S Q) → 〈 P 〉 S 〈 Q 〉 complete (x := exp) {P}{Q} f = cons go ass id where go : P ==> (λ s → Q (s [ x ]≔ ⟦ exp ⟧ᵉ s)) go {s} ps with f ps go ps | ._ , ass , qs' = qs' complete skip {P}{Q} f = cons go skip id where go : P ==> Q go {s} ps with f ps go ps | x , skip , qs' = qs' complete (S , S₁){P}{Q} f = complete S {P} {wp S₁ Q} go , complete S₁ id where go : P ==> wp S (wp S₁ Q) go {s} ps with f ps go {s} ps | s' , (run , run₂) , qs' = _ , run , s' , run₂ , qs' complete (if b then S else S₁){P}{Q} f = if (complete S {(T ∘ ⟦ b ⟧ᵉ) ∧ P} {Q} go1) (complete S₁ {(F ∘ ⟦ b ⟧ᵉ) ∧ P} {Q} go2) where go1 : ((T ∘ ⟦ b ⟧ᵉ) ∧ P) ==> wp S Q go1 {s} (pb , ps) with f ps go1 (pb , ps) | s' , if-true pb' run , qs' = s' , run , qs' go1 (pb , ps) | s' , if-false pb' run , qs' with trans (sym (F→≡false pb')) (T→≡true pb) ... | () go2 : ((F ∘ ⟦ b ⟧ᵉ) ∧ P) ==> wp S₁ Q go2 {s} (pb , ps) with f ps go2 (pb , ps) | s' , if-true pb' run , qs' with trans (sym $ F→≡false pb) (T→≡true pb') ... | () go2 (pb , ps) | s' , if-false pb' run , qs' = s' , run , qs' {- This is the interesting part. I needed to do quite a bit of thinking to get this right. So, we'd like to construct a proof of total corectness given the validity of a Hoare triple. We're much less constrained here than in pretty much all of the other proofs, because our objective is to construct a suitable P *predicate* for the loop body. Recall the axiom for "while" while : ∀ {b S} → (P : ℕ → State n → Set) → (∀ n → P (suc n) ==> (T ∘ ⟦ b ⟧ᵉ)) → (P 0 ==> (F ∘ ⟦ b ⟧ᵉ)) → (∀ n → 〈 P (suc n) 〉 S 〈 P n 〉) → --------------------------------- 〈 (λ s → ∃ λ n → P n s) 〉 while b do S 〈 P 0 〉 -} complete {n}(while b do S){P}{Q} f = cons pre-loop loop post-loop where {- P must decrease on each iteration, and P 0 must imply that the loop has finished, and P (suc n) must imply that the loop's still running. The only sensible choice for the decreasing loop variant is the length of the derivation of the loop: -} loop-size : ∀ {n b s s'}{S : St n} → ⟨ while b do S , s ⟩⟱ s' → ℕ loop-size (while-true x runS runW) = suc (loop-size runW) loop-size (while-false x) = zero {- And now the loop predicate can be defined as: -} P' : ℕ → State n → Set P' n s = ∃₂ λ s' (runW : ⟨ while b do S , s ⟩⟱ s') → (loop-size runW ≡ n) × Q s' {- The construction of the loop body proof is slightly complicated by the fact that if we want to recurse on the measure "n" argument, then we have to unfold the loop derivation two layers deep (because the successor case for indction on "n" implies "(suc (suc n))" value for the derivation length -} body : ∀ n → 〈 P' (suc n) 〉 S 〈 P' n 〉 body n = complete S (go n) where go : ∀ n → P' (suc n) ==> wp S (P' n) go zero (x , while-false x₁ , () , qs') go zero (s''' , while-true x₁ runW (while-true x₂ runW₁ runW₂) , () , qs') go (suc n₂) (x , while-false x₁ , () , qs') go (suc n₂) (s' , while-true x₁ runW (while-false x₂) , () , qs') go zero (s' , while-true x₁ runW (while-false x₂) , psize , qs') = s' , runW , s' , while-false x₂ , refl , qs' go (suc n) {s1} (slast , while-true pb1 runS1 (while-true pb2 runS2 runW2) , psize1 , qslast) with go n (slast , while-true pb2 runS2 runW2 , cong pred psize1 , qslast) ... | s2 , runS3 , s3 , runW3 , psize3 , q3 = _ , runS1 , s3 , (while-true pb2 runS3 runW3) , cong suc psize3 , q3 pre-loop : P ==> (λ s → ∃ λ n → P' n s) pre-loop {s} ps with f ps ... | s' , runW , qs' = loop-size runW , s' , runW , refl , qs' post-loop : P' 0 ==> Q post-loop (s' , while-false pb , psize , qs') = qs' post-loop (s' , while-true pb x₁ x₂ , () , qs') loop : 〈 (λ s → ∃ λ n → P' n s) 〉 while b do S 〈 P' 0 〉 loop = while P' pre post body where pre : ∀ n → P' (suc n) ==> (T ∘ ⟦ b ⟧ᵉ) pre n (s' , while-true pb _ _ , _) = pb pre n (s' , while-false _ , () , qs') post : P' 0 ==> (F ∘ ⟦ b ⟧ᵉ) post (s' , while-true pb runS runW , () , qs') post (s' , while-false pb , refl , qs') = pb
33.264822
101
0.476711
35ec84909b70d5aef2db1c4028e71d599fe3babd
1,322
agda
Agda
src/data/lib/prim/Agda/Builtin/Float.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2016-05-20T13:58:52.000Z
2016-05-20T13:58:52.000Z
src/data/lib/prim/Agda/Builtin/Float.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T15:49:15.000Z
2015-09-15T15:49:15.000Z
src/data/lib/prim/Agda/Builtin/Float.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness --no-subtyping #-} module Agda.Builtin.Float where open import Agda.Builtin.Bool open import Agda.Builtin.Nat open import Agda.Builtin.Int open import Agda.Builtin.Word open import Agda.Builtin.String postulate Float : Set {-# BUILTIN FLOAT Float #-} primitive primFloatToWord64 : Float → Word64 primFloatEquality : Float → Float → Bool primFloatLess : Float → Float → Bool primFloatNumericalEquality : Float → Float → Bool primFloatNumericalLess : Float → Float → Bool primNatToFloat : Nat → Float primFloatPlus : Float → Float → Float primFloatMinus : Float → Float → Float primFloatTimes : Float → Float → Float primFloatNegate : Float → Float primFloatDiv : Float → Float → Float primFloatSqrt : Float → Float primRound : Float → Int primFloor : Float → Int primCeiling : Float → Int primExp : Float → Float primLog : Float → Float primSin : Float → Float primCos : Float → Float primTan : Float → Float primASin : Float → Float primACos : Float → Float primATan : Float → Float primATan2 : Float → Float → Float primShowFloat : Float → String
32.243902
64
0.631619
7cba805cb6b52e05639e887f96e35e4e78639cf5
475
agda
Agda
test/succeed/InferrableFields.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/InferrableFields.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/InferrableFields.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module InferrableFields where data ℕ : Set where zero : ℕ suc : ℕ → ℕ data Vec A : ℕ → Set where [] : Vec A zero _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) record SomeVec A : Set where field n : ℕ unpack : Vec A n open SomeVec using (unpack) pack : ∀ {A n} → Vec A n -> SomeVec A pack xs = record { unpack = xs } data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x lemPack : ∀ {A}(xs : SomeVec A) → pack (unpack xs) ≡ xs lemPack xs = refl
19
55
0.557895
5e4a1cc95ee348a497145f02f736474e7c48a505
3,391
agda
Agda
src/MultiSorted/SyntacticCategory.agda
cilinder/formaltt
0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb
[ "MIT" ]
21
2021-02-16T14:07:06.000Z
2021-11-19T15:50:08.000Z
src/MultiSorted/SyntacticCategory.agda
andrejbauer/formaltt
2aaf850bb1a262681c5a232cdefae312f921b9d4
[ "MIT" ]
1
2021-04-30T14:18:25.000Z
2021-05-14T16:15:17.000Z
src/MultiSorted/SyntacticCategory.agda
andrejbauer/formaltt
2aaf850bb1a262681c5a232cdefae312f921b9d4
[ "MIT" ]
6
2021-02-16T13:43:07.000Z
2021-05-24T02:51:43.000Z
open import Agda.Primitive using (lzero; lsuc; _⊔_) open import Relation.Binary.PropositionalEquality import Relation.Binary.Reasoning.Setoid as SetoidR import Categories.Category as Category import Categories.Category.Cartesian as Cartesian open import Categories.Object.Terminal using (Terminal) open import Categories.Object.Product using (Product) open import MultiSorted.AlgebraicTheory import MultiSorted.Substitution as Substitution import MultiSorted.Product as Product module MultiSorted.SyntacticCategory {ℓt} {𝓈 ℴ} {Σ : Signature {𝓈} {ℴ}} (T : Theory ℓt Σ) where open Theory T open Substitution T -- The syntactic category 𝒮 : Category.Category 𝓈 (lsuc ℴ) (lsuc (ℓt ⊔ 𝓈 ⊔ ℴ)) 𝒮 = record { Obj = Context ; _⇒_ = _⇒s_ ; _≈_ = _≈s_ ; id = id-s ; _∘_ = _∘s_ ; assoc = λ {_ _ _ _ _ _ σ} x → subst-∘s (σ x) ; sym-assoc = λ {_ _ _ _ _ _ σ} x → eq-symm (subst-∘s (σ x)) ; identityˡ = λ x → eq-refl ; identityʳ = λ {A B f} x → tm-var-id ; identity² = λ x → eq-refl ; equiv = record { refl = λ x → eq-refl ; sym = λ ξ y → eq-symm (ξ y) ; trans = λ ζ ξ y → eq-tran (ζ y) (ξ y)} ; ∘-resp-≈ = ∘s-resp-≈s } -- We use the product structure which gives back the context directly prod-𝒮 : Context → Context prod-𝒮 Γ = Γ π-𝒮 : ∀ {Γ} (x : var Γ) → Γ ⇒s ctx-slot (sort-of Γ x) π-𝒮 x _ = tm-var x tuple-𝒮 : ∀ Γ {Δ} → (∀ (x : var Γ) → Δ ⇒s ctx-slot (sort-of Γ x)) → Δ ⇒s Γ tuple-𝒮 Γ ts = λ x → ts x var-var project-𝒮 : ∀ {Γ Δ} {x : var Γ} {ts : ∀ (y : var Γ) → Δ ⇒s ctx-slot (sort-of Γ y)} → π-𝒮 x ∘s tuple-𝒮 Γ ts ≈s ts x project-𝒮 {Γ} {Δ} {x} {ts} var-var = eq-refl unique-𝒮 : ∀ {Γ Δ} {ts : ∀ (x : var Γ) → Δ ⇒s ctx-slot (sort-of Γ x)} {g : Δ ⇒s Γ} → (∀ x → π-𝒮 x ∘s g ≈s ts x) → tuple-𝒮 Γ ts ≈s g unique-𝒮 ξ x = eq-symm (ξ x var-var) producted-𝒮 : Product.Producted 𝒮 {Σ = Σ} ctx-slot producted-𝒮 = record { prod = prod-𝒮 ; π = π-𝒮 ; tuple = tuple-𝒮 ; project = λ {Γ Δ x ts} → project-𝒮 {ts = ts} ; unique = unique-𝒮 } -- The terminal object is the empty context ⊤-𝒮 : Context ⊤-𝒮 = ctx-empty !-𝒮 : ∀ {Γ} → Γ ⇒s ⊤-𝒮 !-𝒮 () !-unique-𝒮 : ∀ {Γ} (σ : Γ ⇒s ⊤-𝒮) → !-𝒮 ≈s σ !-unique-𝒮 σ () terminal-𝒮 : Terminal 𝒮 terminal-𝒮 = record { ⊤ = ⊤-𝒮 ; ⊤-is-terminal = record { ! = !-𝒮 ; !-unique = !-unique-𝒮 } } -- Binary product is context contatenation product-𝒮 : ∀ {Γ Δ} → Product 𝒮 Γ Δ product-𝒮 {Γ} {Δ} = record { A×B = ctx-concat Γ Δ ; π₁ = λ x → tm-var (var-inl x) ; π₂ = λ x → tm-var (var-inr x) ; ⟨_,_⟩ = ⟨_,_⟩s ; project₁ = λ x → eq-refl ; project₂ = λ x → eq-refl ; unique = λ {Θ σ σ₁ σ₂} ξ₁ ξ₂ z → u Θ σ σ₁ σ₂ ξ₁ ξ₂ z } where u : ∀ Θ (σ : Θ ⇒s ctx-concat Γ Δ) (σ₁ : Θ ⇒s Γ) (σ₂ : Θ ⇒s Δ) → ((λ x → σ (var-inl x)) ≈s σ₁) → ((λ y → σ (var-inr y)) ≈s σ₂) → ⟨ σ₁ , σ₂ ⟩s ≈s σ u Θ σ σ₁ σ₂ ξ₁ ξ₂ (var-inl z) = eq-symm (ξ₁ z) u Θ σ σ₁ σ₂ ξ₁ ξ₂ (var-inr z) = eq-symm (ξ₂ z) -- The cartesian structure of the syntactic category cartesian-𝒮 : Cartesian.Cartesian 𝒮 cartesian-𝒮 = record { terminal = terminal-𝒮 ; products = record { product = product-𝒮 } }
29.232759
99
0.527573
303d8ae18477d9b9f49912bf83212655d9b3fc02
2,752
agda
Agda
Categories/Functor/Product.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Functor/Product.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Functor/Product.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.Functor.Product where open import Categories.Category open import Categories.Functor using (Functor) import Categories.Object.Product as Product import Categories.Object.BinaryProducts as BinaryProducts -- Ugh, we should start bundling things (categories with binary products, in this case) up consistently _[_][_×-] : ∀ {o ℓ e} → (C : Category o ℓ e) → BinaryProducts.BinaryProducts C → Category.Obj C → Functor C C C [ P ][ O ×-] = record { F₀ = λ x → Product.A×B (product {O} {x}) ; F₁ = λ f → ⟨ π₁ , f ∘ π₂ ⟩ ; identity = λ {x} → identity′ {x} ; homomorphism = λ {x} {y} {z} {f} {g} → homomorphism′ {x} {y} {z} {f} {g} ; F-resp-≡ = λ f≡g → ⟨⟩-cong₂ refl (∘-resp-≡ˡ f≡g) } where open Category C open Equiv open Product C open BinaryProducts.BinaryProducts P .identity′ : {A : Obj} → ⟨ π₁ , id ∘ π₂ ⟩ ≡ id identity′ = begin ⟨ π₁ , id ∘ π₂ ⟩ ≈⟨ ⟨⟩-cong₂ refl identityˡ ⟩ ⟨ π₁ , π₂ ⟩ ≈⟨ η ⟩ id ∎ where open HomReasoning .homomorphism′ : {X Y Z : Obj} {f : X ⇒ Y} {g : Y ⇒ Z} → ⟨ π₁ , (g ∘ f) ∘ π₂ ⟩ ≡ ⟨ π₁ , g ∘ π₂ ⟩ ∘ ⟨ π₁ , f ∘ π₂ ⟩ homomorphism′ {f = f} {g} = begin ⟨ π₁ , (g ∘ f) ∘ π₂ ⟩ ↓⟨ ⟨⟩-cong₂ refl assoc ⟩ ⟨ π₁ , g ∘ (f ∘ π₂) ⟩ ↑⟨ ⟨⟩-cong₂ refl (∘-resp-≡ʳ commute₂) ⟩ ⟨ π₁ , g ∘ (π₂ ∘ ⟨ π₁ , f ∘ π₂ ⟩) ⟩ ↑⟨ ⟨⟩-cong₂ commute₁ assoc ⟩ ⟨ π₁ ∘ ⟨ π₁ , f ∘ π₂ ⟩ , (g ∘ π₂) ∘ ⟨ π₁ , f ∘ π₂ ⟩ ⟩ ↑⟨ ⟨⟩∘ ⟩ ⟨ π₁ , g ∘ π₂ ⟩ ∘ ⟨ π₁ , f ∘ π₂ ⟩ ∎ where open HomReasoning _[_][-×_] : ∀ {o ℓ e} → (C : Category o ℓ e) → BinaryProducts.BinaryProducts C → Category.Obj C → Functor C C C [ P ][-× O ] = record { F₀ = λ x → Product.A×B (product {x} {O}) ; F₁ = λ f → ⟨ f ∘ π₁ , π₂ ⟩ ; identity = λ {x} → identity′ {x} ; homomorphism = λ {x} {y} {z} {f} {g} → homomorphism′ {x} {y} {z} {f} {g} ; F-resp-≡ = λ f≡g → ⟨⟩-cong₂ (∘-resp-≡ˡ f≡g) refl } where open Category C open Equiv open Product C open BinaryProducts.BinaryProducts P .identity′ : {A : Obj} → ⟨ id ∘ π₁ , π₂ ⟩ ≡ id identity′ = begin ⟨ id ∘ π₁ , π₂ ⟩ ≈⟨ ⟨⟩-cong₂ identityˡ refl ⟩ ⟨ π₁ , π₂ ⟩ ≈⟨ η ⟩ id ∎ where open HomReasoning .homomorphism′ : {X Y Z : Obj} {f : X ⇒ Y} {g : Y ⇒ Z} → ⟨ (g ∘ f) ∘ π₁ , π₂ ⟩ ≡ ⟨ g ∘ π₁ , π₂ ⟩ ∘ ⟨ f ∘ π₁ , π₂ ⟩ homomorphism′ {f = f} {g} = begin ⟨ (g ∘ f) ∘ π₁ , π₂ ⟩ ↓⟨ ⟨⟩-cong₂ assoc refl ⟩ ⟨ g ∘ (f ∘ π₁) , π₂ ⟩ ↑⟨ ⟨⟩-cong₂ (∘-resp-≡ʳ commute₁) refl ⟩ ⟨ g ∘ (π₁ ∘ ⟨ f ∘ π₁ , π₂ ⟩) , π₂ ⟩ ↑⟨ ⟨⟩-cong₂ assoc commute₂ ⟩ ⟨ (g ∘ π₁) ∘ ⟨ f ∘ π₁ , π₂ ⟩ , π₂ ∘ ⟨ f ∘ π₁ , π₂ ⟩ ⟩ ↑⟨ ⟨⟩∘ ⟩ ⟨ g ∘ π₁ , π₂ ⟩ ∘ ⟨ f ∘ π₁ , π₂ ⟩ ∎ where open HomReasoning
30.921348
117
0.490916
fd70874560bc00a40c56b69fa3cce6398e73f079
544
agda
Agda
test/interaction/CaseSplitAndImplicits.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/CaseSplitAndImplicits.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/CaseSplitAndImplicits.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Equality -- Case splitting should not remove implicit arguments record ⊤ : Set where constructor tt test₁ : {A : Set} → ⊤ → ⊤ test₁ {A} x = {!x!} -- Case splitting on an implicit argument should make it visible test₂ : {x : ⊤} → ⊤ test₂ = {!x!} -- Implicit variables in dot patterns should be replaced by _ postulate A B : Set f : A → B test₃ : {x : A} (y : B) → f x ≡ y → B test₃ y e = {!e!} -- .. but not if they are bound inside the dot pattern test₄ : (f : A → A) → f ≡ (λ x → x) → Set test₄ f e = {!e!}
21.76
64
0.608456
0d57c9422e7a15f5d563e0211aa00bb06827b162
2,054
agda
Agda
Data/Vec/Iterated.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Vec/Iterated.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Vec/Iterated.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --without-K --safe #-} module Data.Vec.Iterated where open import Data.Unit.UniversePolymorphic open import Level open import Data.Nat.Base open import Function private variable n m : ℕ mutual Vec : Type a → ℕ → Type a Vec A zero = Vec⁰ Vec A (suc n) = Vec⁺ A n record Vec⁰ {a} : Type a where eta-equality constructor [] infixr 5 _∷_ record Vec⁺ {a} (A : Type a) (n : ℕ) : Type a where eta-equality inductive constructor _∷_ field head : A tail : Vec A n open Vec⁺ public foldr : ∀ {p} (P : ℕ → Type p) → (∀ {n} → A → P n → P (suc n)) → P zero → Vec A n → P n foldr {n = zero} P f b _ = b foldr {n = suc n} P f b (x ∷ xs) = f x (foldr P f b xs) foldl : ∀ {p} (P : ℕ → Type p) → (∀ {n} → A → P n → P (suc n)) → P zero → Vec A n → P n foldl {n = zero } P f b _ = b foldl {n = suc n} P f b (x ∷ xs) = foldl (P ∘ suc) f (f x b) xs foldlN : ∀ {p} (P : ℕ → Type p) → (∀ {n} → A → P (suc n) → P n) → P n → Vec A n → P zero foldlN P f b xs = foldr (λ n → P n → P zero) (λ x k xs → k (f x xs)) id xs b module _ (f : A → B → B) (e : B) where foldr′ : Vec A n → B foldr′ {n = zero } xs = e foldr′ {n = suc n} (x ∷ xs) = f x (foldr′ xs) foldl′ : (A → B → B) → B → Vec A n → B foldl′ {n = zero} f b xs = b foldl′ {n = suc n} f b (x ∷ xs) = foldl′ f (f x b) xs -- vecFromList : (xs : List A) → Vec A (length xs) -- vecFromList List.[] = [] -- vecFromList (x List.∷ xs) = x ∷ vecFromList xs -- vecToList : Vec A n → List A -- vecToList = foldr′ List._∷_ List.[] open import Data.Fin.Indexed infixl 4 lookup lookup : Fin n → Vec A n → A lookup f0 = head lookup (fs i) xs = lookup i (tail xs) syntax lookup i xs = xs [ i ] infixl 4 replace replace : Fin n → A → Vec A n → Vec A n replace f0 x xs .head = x replace f0 x xs .tail = xs .tail replace (fs i) x xs .head = xs .head replace (fs i) x xs .tail = replace i x (xs .tail) syntax replace i x xs = xs [ i ]≔ x
23.609195
76
0.522882
34070f53a3f5c932abaac107e269a0ad0f93b9a9
1,150
agda
Agda
test/Succeed/Issue3052-simplified.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
1
2016-03-17T01:45:59.000Z
2016-03-17T01:45:59.000Z
test/Succeed/Issue3052-simplified.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue3052-simplified.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas & Jesper, 2018-05-11, issue #3052 reported by identicalsnowflake -- -- The problem here was that free variable collection had the standard -- monoid instance of IntMap, which is just "randomly" picking one variant. -- Thus, if we have both irrelevant and relevant occurrences of a variable, -- we get whatever. -- Now we keep the stronger information (relevant, see maxVarOcc). {-# OPTIONS --show-irrelevant #-} -- {-# OPTIONS -v tc.meta.assign:100 -v tc.meta.occurs:45 #-} -- {-# OPTIONS -v tc.lhs:100 #-} postulate A : Set B : A → Set record Σ : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public record Foo : Set where constructor foo field .theFoo : Σ test : Foo → Foo test (foo (a , b)) = foo (a , thm a b) -- Error at b -- Constraint: a, b ⊢ ?0 .a .b a = B a : Set -- Note the irrelevant occurrence .a and the relevant occurrence a -- on the lhs of this constraint! where -- Meta ?0 : [.a, .b, x] Set postulate thm : (x : A) (y : _) → B x -- Underscore should solved by B x -- thm x y = y -- WAS: Worked only if definition is given (which -- Should succeed.
28.04878
75
0.646087
19a1a01616e4514f971bdf3298f40a5f75a272d3
577
agda
Agda
test/succeed/RewriteAndUniversePolymorphism.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/succeed/RewriteAndUniversePolymorphism.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/RewriteAndUniversePolymorphism.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} module RewriteAndUniversePolymorphism where postulate Level : Set lzero : Level lsuc : (i : Level) → Level _⊔_ : Level -> Level -> Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO lzero #-} {-# BUILTIN LEVELSUC lsuc #-} {-# BUILTIN LEVELMAX _⊔_ #-} infixl 6 _⊔_ data ℕ : Set where zero : ℕ suc : ℕ → ℕ infix 4 _≡_ data _≡_ {a}{A : Set a} (x : A) : A → Set a where refl : x ≡ x {-# BUILTIN EQUALITY _≡_ #-} {-# BUILTIN REFL refl #-} test : (a b : ℕ) → a ≡ b → b ≡ a test a b eq rewrite eq = refl
18.03125
49
0.580589
7cb9d2ff6f2263b28b72f312a8982a610d0d1907
118
agda
Agda
test/Fail/Issue4638-1.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue4638-1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue4638-1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Unit data D : Set where c₁ c₂ : D @0 c₃ : D f : @0 D → ⊤ f c₁ = tt f c₂ = tt f c₃ = tt
10.727273
29
0.550847
7caa042aede0d5fb2f2811146f9e0bab2a3fc5ba
2,493
agda
Agda
BasicIPC/Metatheory/Hilbert-TarskiGluedClosedHilbert.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIPC/Metatheory/Hilbert-TarskiGluedClosedHilbert.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIPC/Metatheory/Hilbert-TarskiGluedClosedHilbert.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module BasicIPC.Metatheory.Hilbert-TarskiGluedClosedHilbert where open import BasicIPC.Syntax.Hilbert public open import BasicIPC.Semantics.TarskiGluedClosedHilbert public -- Internalisation of syntax as syntax representation in a particular model, for closed terms only. module _ {{_ : Model}} where [_]₀ : ∀ {A} → ∅ ⊢ A → [⊢] A [ var () ]₀ [ app t u ]₀ = [app] [ t ]₀ [ u ]₀ [ ci ]₀ = [ci] [ ck ]₀ = [ck] [ cs ]₀ = [cs] [ cpair ]₀ = [cpair] [ cfst ]₀ = [cfst] [ csnd ]₀ = [csnd] [ unit ]₀ = [unit] -- Soundness with respect to all models, or evaluation. eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A eval (var i) γ = lookup i γ eval (app t u) γ = eval t γ ⟪$⟫ eval u γ eval ci γ = [ci] ⅋ I eval ck γ = [ck] ⅋ ⟪K⟫ eval cs γ = [cs] ⅋ ⟪S⟫′ eval cpair γ = [cpair] ⅋ _⟪,⟫′_ eval cfst γ = [cfst] ⅋ π₁ eval csnd γ = [csnd] ⅋ π₂ eval unit γ = ∙ -- Correctness of evaluation with respect to conversion. eval✓ : ∀ {{_ : Model}} {A Γ} {t t′ : Γ ⊢ A} → t ⋙ t′ → eval t ≡ eval t′ eval✓ refl⋙ = refl eval✓ (trans⋙ p q) = trans (eval✓ p) (eval✓ q) eval✓ (sym⋙ p) = sym (eval✓ p) eval✓ (congapp⋙ p q) = cong² _⟦$⟧_ (eval✓ p) (eval✓ q) eval✓ (congi⋙ p) = cong I (eval✓ p) eval✓ (congk⋙ p q) = cong² K (eval✓ p) (eval✓ q) eval✓ (congs⋙ p q r) = cong³ ⟦S⟧ (eval✓ p) (eval✓ q) (eval✓ r) eval✓ (congpair⋙ {A} {B} p q) = cong² (_⟦,⟧_ {A} {B}) (eval✓ p) (eval✓ q) eval✓ (congfst⋙ {A} {B} p) = cong (⟦π₁⟧ {A} {B}) (eval✓ p) eval✓ (congsnd⋙ {A} {B} p) = cong (⟦π₂⟧ {A} {B}) (eval✓ p) eval✓ beta▻ₖ⋙ = refl eval✓ beta▻ₛ⋙ = refl eval✓ beta∧₁⋙ = refl eval✓ beta∧₂⋙ = refl eval✓ eta∧⋙ = refl eval✓ eta⊤⋙ = refl -- The canonical model. private instance canon : Model canon = record { ⊩ᵅ_ = λ P → ∅ ⊢ α P ; [⊢]_ = ∅ ⊢_ ; [app] = app ; [ci] = ci ; [ck] = ck ; [cs] = cs ; [cpair] = cpair ; [cfst] = cfst ; [csnd] = csnd ; [unit] = unit } -- Completeness with respect to all models, or quotation, for closed terms only. quot₀ : ∀ {A} → ∅ ⊨ A → ∅ ⊢ A quot₀ t = reifyʳ (t ∙) -- Normalisation by evaluation, for closed terms only. norm₀ : ∀ {A} → ∅ ⊢ A → ∅ ⊢ A norm₀ = quot₀ ∘ eval -- TODO: Correctness of normalisation with respect to conversion.
28.011236
99
0.490172
21e86a57b65ec3e64990676d6c847b0568a64d94
5,772
agda
Agda
Globular-TT/Disks.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
Globular-TT/Disks.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
Globular-TT/Disks.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting --without-K #-} open import Agda.Primitive open import Prelude import GSeTT.Typed-Syntax import Globular-TT.Syntax {- Disk and Sphere contexts - properties -} module Globular-TT.Disks {l} (index : Set l) (rule : index → GSeTT.Typed-Syntax.Ctx × (Globular-TT.Syntax.Pre-Ty index)) (eqdec-index : eqdec index) where open import Globular-TT.Syntax index open import Globular-TT.Rules index rule open import Globular-TT.CwF-Structure index rule open import Globular-TT.Uniqueness-Derivations index rule eqdec-index open import Globular-TT.Typed-Syntax index rule eqdec-index {- Definition of "universal source and target variables" -} n-src : ℕ → ℕ n-tgt : ℕ → ℕ n⇒ : ℕ → Pre-Ty n-src O = O n-src (S n) = S (n-tgt n) n-tgt n = S (n-src n) n⇒ O = ∗ n⇒ (S n) = ⇒ (n⇒ n) (Var (n-src n)) (Var (n-tgt n)) dim⇒ : ∀ (n : ℕ) → dim (n⇒ n) == n dim⇒ O = idp dim⇒ (S n) = S= (dim⇒ n) {- Syntactic definition of disks and spheres -} Pre-𝕊 : ℕ → Pre-Ctx Pre-𝔻 : ℕ → Pre-Ctx Pre-𝕊 O = ⊘ Pre-𝕊 (S n) = (Pre-𝔻 n) ∙ C-length (Pre-𝔻 n) # n⇒ n Pre-𝔻 n = (Pre-𝕊 n) ∙ C-length (Pre-𝕊 n) # n⇒ n 𝕊-length : ∀ n → C-length (Pre-𝕊 n) == n-src n 𝕊-length O = idp 𝕊-length (S n) = S= (S= (𝕊-length n)) {-# REWRITE 𝕊-length #-} {- Disk and Sphere context are valid -} 𝕊⊢ : ∀ n → Pre-𝕊 n ⊢C 𝔻⊢ : ∀ n → Pre-𝔻 n ⊢C 𝕊⊢⇒ : ∀ n → Pre-𝕊 n ⊢T n⇒ n 𝕊⊢ O = ec 𝕊⊢ (S n) = cc (𝔻⊢ n) (wkT (𝕊⊢⇒ n) (𝔻⊢ n)) idp 𝔻⊢ n = cc (𝕊⊢ n) (𝕊⊢⇒ n) idp 𝕊⊢⇒ O = ob ec 𝕊⊢⇒ (S n) = ar (wkT (wkT (𝕊⊢⇒ n) (𝔻⊢ n)) (𝕊⊢ (S n))) (wkt (var (𝔻⊢ n) (inr (((𝕊-length n) ^) , idp))) (𝕊⊢ (S n))) (var (𝕊⊢ (S n)) (inr ((S= (𝕊-length n) ^) , idp))) 𝕊 : ℕ → Ctx 𝕊 n = Pre-𝕊 n , 𝕊⊢ n 𝔻 : ℕ → Ctx 𝔻 n = Pre-𝔻 n , 𝔻⊢ n Ty-n : ∀ {Γ} → Σ ℕ (λ n → Sub Γ (𝕊 n)) → Ty Γ Ty-n {Γ} (n , (γ , Γ⊢γ:Sn) ) = ((n⇒ n)[ γ ]Pre-Ty) , ([]T (𝕊⊢⇒ n) Γ⊢γ:Sn) private Pre-χ : Pre-Ty → Pre-Sub Pre-χ ∗ = <> Pre-χ (⇒ A t u) = < < Pre-χ A , n-src (dim A) ↦ t > , n-tgt (dim A) ↦ u > χ_⊢ : ∀ {Γ A} → (Γ⊢A : Γ ⊢T A) → Γ ⊢S (Pre-χ A) > Pre-𝕊 (dim A) ⇒[χ_] : ∀ {Γ A} → (Γ⊢A : Γ ⊢T A) → A == ((n⇒ (dim A))[ Pre-χ A ]Pre-Ty) χ ob Γ⊢ ⊢ = es Γ⊢ χ_⊢ {Γ} {⇒ A t u} (ar Γ⊢A Γ⊢t:A Γ⊢u:A) = let Γ⊢χt = sc χ Γ⊢A ⊢ (𝔻⊢ (dim A)) (trT (⇒[χ Γ⊢A ]) Γ⊢t:A) idp in sc Γ⊢χt (𝕊⊢ (S (dim A))) (trT (⇒[χ Γ⊢A ] >> (wk[]T (𝕊⊢⇒ (dim A)) Γ⊢χt ^)) Γ⊢u:A) idp ⇒[χ_] {Γ} {.∗} (ob _) = idp ⇒[χ_] {Γ} {(⇒ A t u)} (ar Γ⊢A Γ⊢t:A Γ⊢u:A) with eqdecℕ (n-src (dim A)) (n-tgt (dim A)) | eqdecℕ (n-src (dim A)) (n-src (dim A)) | eqdecℕ (S (n-src (dim A))) (S (n-src (dim A))) ... | inl contra | _ | _ = ⊥-elim (n≠Sn _ contra) ... | inr _ | inr n≠n | _ = ⊥-elim (n≠n idp) ... | inr _ | inl _ | inr n≠n = ⊥-elim (n≠n idp) ... | inr _ | inl _ | inl _ = let Γ⊢χt = (sc χ Γ⊢A ⊢ (𝔻⊢(dim A)) (trT ⇒[χ Γ⊢A ] Γ⊢t:A) idp) in let A=⇒[γt] = ⇒[χ Γ⊢A ] >> (wk[]T (𝕊⊢⇒ (dim A)) Γ⊢χt ^) in ⇒= (A=⇒[γt] >> (wk[]T (wkT (𝕊⊢⇒ (dim A)) (𝔻⊢ (dim A))) (sc Γ⊢χt (𝕊⊢ (S (dim A))) (trT A=⇒[γt] Γ⊢u:A) idp) ^)) idp idp χ : ∀ {Γ} → Ty Γ → Σ ℕ λ n → Sub Γ (𝕊 n) χ (A , Γ⊢A) = dim A , (Pre-χ A , χ Γ⊢A ⊢) dim-Ty-n : ∀ {Γ} (n : ℕ) → (γ : Sub Γ (𝕊 n)) → dim (fst (Ty-n {Γ} (n , γ))) == n dim-Ty-n n (γ , Γ⊢γ:Sn) = dim[] (n⇒ n) γ >> (dim⇒ n) trS-sph : ∀ {Γ n m} → (p : n == m) → {γ : Sub Γ (𝕊 n)} → {δ : Sub Γ (𝕊 m)} → fst γ == fst δ → transport p γ == δ trS-sph {Γ} {n} {m} idp {γ} {δ} x = eqS {Γ} {𝕊 m} γ δ x lemma1 : ∀ t u γ n → (if n-src n ≡ S (n-src n) then u else (if n-src n ≡ n-src n then t else (Var (n-src n) [ γ ]Pre-Tm))) == t lemma1 t u γ n with eqdecℕ (n-src n) (S (n-src n)) ... | inl n=Sn = ⊥-elim (n≠Sn _ (n=Sn)) ... | inr _ with eqdecℕ (n-src n) (n-src n) ... | inl _ = idp ... | inr n≠n = ⊥-elim (n≠n idp) lemma2 : ∀ t u γ n → (if S (n-src n) ≡ S (n-src n) then u else (if S (n-src n) ≡ n-src n then t else (Var (S (n-src n)) [ γ ]Pre-Tm))) == u lemma2 t u γ n with eqdecℕ (S (n-src n)) (S (n-src n)) ... | inl _ = idp ... | inr n≠n = ⊥-elim (n≠n idp) Pre-χTy-n : ∀ {Γ} (n : ℕ) → (γ : Sub Γ (𝕊 n)) → Pre-χ (fst (Ty-n {Γ} (n , γ))) == fst γ Pre-χTy-n O (.<> , (es _)) = idp Pre-χTy-n {Γ} (S n) (< < γ , _ ↦ t > , _ ↦ u > , (sc (sc Γ⊢γ:Sn _ Γ⊢t:A idp) _ Γ⊢u:A idp)) with eqdecℕ (n-src n) (S (n-src n)) | eqdecℕ (n-src n) (n-src n) | eqdecℕ (S (n-src n)) (S (n-src n)) ... | inl contra | _ | _ = ⊥-elim (n≠Sn _ contra) ... | inr _ | inr n≠n | _ = ⊥-elim (n≠n idp) ... | inr _ | inl _ | inr n≠n = ⊥-elim (n≠n idp) ... | inr _ | inl _ | inl _ = let χTm-n = (sc Γ⊢γ:Sn (𝔻⊢ n) Γ⊢t:A idp) in <,>= (<,>= (ap Pre-χ (wk[]T (wkT (𝕊⊢⇒ n) (𝔻⊢ n)) (sc χTm-n (𝕊⊢ (S n)) Γ⊢u:A idp) >> wk[]T (𝕊⊢⇒ n) χTm-n) >> Pre-χTy-n {Γ} n (γ , Γ⊢γ:Sn)) (ap n-src (dim[] (n⇒ n) _ >> (dim⇒ n))) (lemma1 t u γ n)) (S= (ap n-src (dim[] (n⇒ n) _ >> (dim⇒ n)))) (lemma2 t u γ n) χTy-n : ∀ {Γ} (n : ℕ) → (γ : Sub Γ (𝕊 n)) → χ {Γ} (Ty-n {Γ} (n , γ)) == (n , γ) χTy-n {Γ} n γ = Σ= (dim-Ty-n {Γ} n γ) (trS-sph {Γ} (dim-Ty-n {Γ} n γ) {snd (χ {Γ} (Ty-n {Γ} (n , γ)))} {γ} (Pre-χTy-n {Γ} n γ)) Ty-classifier : ∀ Γ → is-equiv (Ty-n {Γ}) is-equiv.g (Ty-classifier Γ) (A , Γ⊢A) = χ {Γ} (A , Γ⊢A) is-equiv.f-g (Ty-classifier Γ) (A , Γ⊢A) = Σ= (⇒[χ Γ⊢A ] ^) (has-all-paths-⊢T _ _) is-equiv.g-f (Ty-classifier Γ) (n , γ) = χTy-n {Γ} n γ is-equiv.adj (Ty-classifier Γ) (n , γ) = (is-prop-has-all-paths (is-set-Ty Γ _ _)) _ _
42.755556
196
0.437976
35077b0bf60002b445a1c6cc16fd55efa3d8140d
2,974
agda
Agda
src/plfa/working/Naturals.agda
kaychaks/plfa.github.io
5365a4ba8ba0dc80cb77ab73aee92c645d0787d9
[ "CC-BY-4.0" ]
null
null
null
src/plfa/working/Naturals.agda
kaychaks/plfa.github.io
5365a4ba8ba0dc80cb77ab73aee92c645d0787d9
[ "CC-BY-4.0" ]
null
null
null
src/plfa/working/Naturals.agda
kaychaks/plfa.github.io
5365a4ba8ba0dc80cb77ab73aee92c645d0787d9
[ "CC-BY-4.0" ]
null
null
null
module plfa.working.Naturals where data ℕ : Set where zero : ℕ suc : ℕ → ℕ seven : ℕ seven = suc(suc(suc(suc(suc(suc(suc(zero))))))) {-# BUILTIN NATURAL ℕ #-} import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) _+_ : ℕ → ℕ → ℕ zero + n = n (suc m) + n = suc(m + n) _ : 2 + 3 ≡ 5 _ = begin 2 + 3 ≡⟨⟩ (suc (suc zero)) + (suc (suc (suc zero))) ≡⟨⟩ suc( (suc zero) + (suc (suc (suc zero)))) ≡⟨⟩ (suc(suc (zero + (suc (suc (suc zero)))))) ≡⟨⟩ (suc (suc (suc (suc (suc zero))))) ≡⟨⟩ 5 ∎ _ : 2 + 3 ≡ 5 _ = begin 2 + 3 ≡⟨⟩ suc (1 + 3) ≡⟨⟩ suc (suc (0 + 3)) ≡⟨⟩ suc (suc 3) ≡⟨⟩ 5 ∎ _ : 3 + 4 ≡ 7 _ = begin 3 + 4 ≡⟨⟩ suc (2 + 4) ≡⟨⟩ suc (2 + (suc 3)) ≡⟨⟩ suc (suc (2 + 3)) ≡⟨⟩ suc (suc 5) ≡⟨⟩ 7 ∎ _*_ : ℕ → ℕ → ℕ zero * n = zero (suc m) * n = n + (n * m) _ : 3 * 4 ≡ 12 _ = begin 3 * 4 ≡⟨⟩ (suc 2) * 4 ≡⟨⟩ 4 + (4 * 2) ≡⟨⟩ 4 + ((suc 3) * 2) ≡⟨⟩ 4 + (2 + (2 * 3)) ≡⟨⟩ 4 + (2 + (suc 1 * 3)) ≡⟨⟩ 4 + (2 + (3 + (3 * 1))) ≡⟨⟩ 4 + (2 + (3 + (suc 2 * 1))) ≡⟨⟩ 4 + (2 + (3 + (1 + (1 * 2)))) ≡⟨⟩ 12 ∎ _^_ : ℕ → ℕ → ℕ n ^ zero = suc zero n ^ (suc m) = n * (n ^ m) _ : 3 ^ 4 ≡ 81 _ = begin 3 ^ 4 ≡⟨⟩ 3 ^ (1 + 3) ≡⟨⟩ 3 * (3 ^ 3) ≡⟨⟩ 3 * (3 * (3 ^ 2)) ≡⟨⟩ 3 * (3 * (3 * (3 ^ 1))) ≡⟨⟩ 3 * (3 * (3 * 3)) ≡⟨⟩ 81 ∎ _∸_ : ℕ → ℕ → ℕ m ∸ zero = m zero ∸ suc n = zero suc m ∸ suc n = m ∸ n _ : 5 ∸ 3 ≡ 2 _ = begin 5 ∸ 3 ≡⟨⟩ (1 + 4) ∸ (1 + 2) ≡⟨⟩ 4 ∸ 2 ≡⟨⟩ 3 ∸ 1 ≡⟨⟩ 2 ∸ 0 ≡⟨⟩ 2 ∎ _ : 2 ∸ 5 ≡ 0 _ = begin 2 ∸ 5 ≡⟨⟩ 1 ∸ 4 ≡⟨⟩ 0 ∸ 3 ≡⟨⟩ 0 ∎ data Bin : Set where ⟨⟩ : Bin _O : Bin → Bin _I : Bin → Bin inc : Bin → Bin inc ⟨⟩ = ⟨⟩ I inc (p O) = p I inc (p I) = (inc p) O _ : inc (⟨⟩ O O O O) ≡ ⟨⟩ O O O I _ = refl _ : inc (⟨⟩ O O O I) ≡ ⟨⟩ O O I O _ = refl _ : inc (⟨⟩ O O I O) ≡ ⟨⟩ O O I I _ = refl _ : inc (⟨⟩ O O I I) ≡ ⟨⟩ O I O O _ = refl _ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O _ = refl to : ℕ → Bin to zero = ⟨⟩ O to (suc n) = inc (to n) from : Bin → ℕ from ⟨⟩ = zero from (p O) = from p * 2 from (p I) = suc ((from p) * 2) _ : to 3 ≡ ⟨⟩ I I _ = refl _ : from (⟨⟩ I I) ≡ 3 _ = refl
15.570681
54
0.284129
36d44bc9addbd662f4bc0d951e44b84078e4fcfc
334
agda
Agda
test/Common/Coinduction.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/Common/Coinduction.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/Common/Coinduction.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Common.Coinduction where open import Common.Level infix 1000 ♯_ postulate ∞ : ∀ {a} (A : Set a) → Set a ♯_ : ∀ {a} {A : Set a} → A → ∞ A ♭ : ∀ {a} {A : Set a} → ∞ A → A {-# BUILTIN INFINITY ∞ #-} {-# BUILTIN SHARP ♯_ #-} {-# BUILTIN FLAT ♭ #-} private my-♯ : ∀ {a} {A : Set a} → A → ∞ A my-♯ x = ♯ x
16.7
36
0.464072
372e0990b099f4a09925de0a0d17c09b9a334b5b
5,732
agda
Agda
src/Linear.agda
zaklogician/linear-constructive
168d99745260049051bf0a53f2f6627e652e6ace
[ "BSD-3-Clause" ]
16
2018-05-22T23:36:18.000Z
2022-03-10T17:31:57.000Z
src/Linear.agda
zaklogician/linear-constructive
168d99745260049051bf0a53f2f6627e652e6ace
[ "BSD-3-Clause" ]
1
2019-07-02T13:25:58.000Z
2019-07-02T13:25:58.000Z
src/Linear.agda
zaklogician/linear-constructive
168d99745260049051bf0a53f2f6627e652e6ace
[ "BSD-3-Clause" ]
1
2019-06-27T15:40:16.000Z
2019-06-27T15:40:16.000Z
module Linear where open import Data.Product open import Data.Sum open import Data.Empty -- 1. PROPOSITIONAL FRAGMENT infixr 0 _⊸_ infixr 1 _⊕_ _⅋_ infixr 2 _&_ _⊗_ -- Linear propositions consist of a positive part (affirmation, φ₊) and a negative -- part (refutation, φ₋). We prove a linear proposition by proving its affirmation. -- If we have a refutation then we cannot have an affirmation, on pain of contra- -- diction. data LProp : Set₁ where lprop : (φ₊ : Set) → (φ₋ : Set) → (φ₋ → φ₊ → ⊥) → LProp -- Linear negation exchanges affirmations and refutations. ~ : LProp → LProp ~ (lprop φ₊ φ₋ p) = lprop φ₋ φ₊ (λ a b → p b a) -- Additive conjunction _&_ : LProp → LProp → LProp (lprop φ₊ φ₋ p) & (lprop ψ₊ ψ₋ q) = lprop (φ₊ × ψ₊) (φ₋ ⊎ ψ₋) pq where pq : (φ₋ ⊎ ψ₋) → (φ₊ × ψ₊) → ⊥ pq (inj₁ ~a) (a , b) = p ~a a pq (inj₂ ~b) (a , b) = q ~b b -- Additive disjunction: notice the symmetry between the proofs `pq` between -- additive conjunctions and additive disjunctions. _⊕_ : LProp → LProp → LProp (lprop φ₊ φ₋ p) ⊕ (lprop ψ₊ ψ₋ q) = lprop (φ₊ ⊎ ψ₊) (φ₋ × ψ₋) pq where pq : (φ₋ × ψ₋) → (φ₊ ⊎ ψ₊) → ⊥ pq (~a , ~b) (inj₁ a) = p ~a a pq (~a , ~b) (inj₂ b) = q ~b b -- Multiplicative conjunction _⊗_ : LProp → LProp → LProp (lprop φ₊ φ₋ p) ⊗ (lprop ψ₊ ψ₋ q) = lprop (φ₊ × ψ₊) ((φ₊ → ψ₋) × (ψ₊ → φ₋)) pq where pq : ((φ₊ → ψ₋) × (ψ₊ → φ₋)) → (φ₊ × ψ₊) → ⊥ pq (f , g) (a , b) = q (f a) b -- Multiplicative disjunction _⅋_ : LProp → LProp → LProp (lprop φ₊ φ₋ p) ⅋ (lprop ψ₊ ψ₋ q) = lprop ((ψ₋ → φ₊) × (φ₋ → ψ₊)) (φ₋ × ψ₋) pq where pq : (φ₋ × ψ₋) → ((ψ₋ → φ₊) × (φ₋ → ψ₊)) → ⊥ pq (~a , ~b) (f , g) = q ~b (g ~a) -- Linear implication _⊸_ : LProp → LProp → LProp p ⊸ q = (~ p) ⅋ q ⟦_⟧ : LProp → Set ⟦ lprop φ₊ _ _ ⟧ = φ₊ _⊢_ : LProp → LProp → Set Γ ⊢ P = ⟦ Γ ⊸ P ⟧ ---------- -- Here we prove that these connectives satisfy Hesselink's axioms and rules -- for the multiplicative fragment of linear logic. See also: -- W. H. Hesselink: Axioms and models of linear logic, in Formal Aspects of Computing, 1990 -- Identity axiom. axiom-1 : (P : LProp) → ⟦ P ⊸ P ⟧ axiom-1 (lprop φ₊ φ₋ p) = (λ x → x) , (λ x → x) -- Commutativity of ⅋. axiom-2 : (P Q : LProp) → ⟦ (P ⅋ Q) ⊸ (Q ⅋ P) ⟧ axiom-2 (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) = (λ x → proj₂ x , proj₁ x) , (λ x → proj₂ x , proj₁ x) -- Associativity of ⅋: the proof looks ugly, but we really just re-associate ×. axiom-3 : (P Q R : LProp) → ⟦ ((P ⅋ Q) ⅋ R) ⊸ (P ⅋ (Q ⅋ R)) ⟧ axiom-3 (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) (lprop ρ₊ ρ₋ r) = (λ x → (proj₁ x , proj₁ (proj₂ x)) , proj₂ (proj₂ x)) , (λ x → (λ y → proj₁ (proj₁ x (proj₂ y)) (proj₁ y)) , (λ y → (λ (z : ρ₋) → proj₂ (proj₁ x z) y) , (λ z → proj₂ x (y , z)))) -- Finally, the analogues of the rules of inferece work as expected. mp-rule : (P Q : LProp) → ⟦ P ⟧ → ⟦ P ⊸ Q ⟧ → ⟦ Q ⟧ mp-rule (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) a ab = proj₂ ab a mp-rule-ctx : (Γ P Q : LProp) → ⟦ Γ ⅋ P ⟧ → ⟦ P ⊸ Q ⟧ → ⟦ Γ ⅋ Q ⟧ mp-rule-ctx (lprop γ₊ γ₋ g) (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) a ab = (λ x → proj₁ a (proj₁ ab x)) , (λ x → proj₂ ab (proj₂ a x)) -- A deduction-like variant of the same result. deduction : (Γ P Q : LProp) → (Γ ⅋ P) ⊢ Q → Γ ⊢ (P ⊸ Q) deduction (lprop γ₊ γ₋ _) (lprop φ₊ φ₋ _) (lprop ψ₊ ψ₋ _) gpq = (λ pq → helper1 (proj₂ pq)) , (λ g → helper2 , (λ p → helper3 (λ _ → g) (λ _ → p))) where helper1 : ψ₋ → γ₋ helper1 x = proj₁ (proj₁ gpq x) helper2 : ψ₋ → φ₋ helper2 x = proj₂ (proj₁ gpq x) helper3 : (φ₋ → γ₊) → (γ₋ → φ₊) → ψ₊ helper3 x y = proj₂ gpq (x , y) ---------- -- We verify the usual dualities, along with the involutive property of negation. tensor-par-duality : (P Q : LProp) → ⟦ (~ (P ⊗ Q)) ⊸ ((~ P) ⅋ (~ Q)) ⟧ tensor-par-duality (lprop φ₊ φ₋ x) (lprop ψ₊ ψ₋ y) = (λ z → z) , λ z → proj₂ z , proj₁ z par-tensor-duality : (P Q : LProp) → ⟦ ~ (P ⅋ Q) ⊸ (~ P ⊗ ~ Q) ⟧ par-tensor-duality (lprop φ₊ φ₋ x) (lprop ψ₊ ψ₋ y) = (λ z → proj₂ z , proj₁ z) , λ z → z plus-with-duality : (P Q : LProp) → ⟦ ~ (P ⊕ Q) ⊸ (~ P & ~ Q) ⟧ plus-with-duality (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) = (λ z → z) , λ z → z with-plus-duality : (P Q : LProp) → ⟦ ~ (P & Q) ⊸ (~ P ⊕ ~ Q) ⟧ with-plus-duality (lprop φ₊ φ₋ x) (lprop ψ₊ ψ₋ y) = (λ z → z) , λ z → z open import Relation.Binary.PropositionalEquality -- The involutive property holds up to equality. involutive-negation : (P : LProp) → ~ (~ P) ≡ P involutive-negation (lprop φ₊ φ₋ x) = refl -- 2. PROPOSITIONAL-EXPONENTIAL FRAGMENT -- The "of course!" modality ! : LProp → LProp ! (lprop φ₊ φ₋ _) = lprop φ₊ (φ₊ → ⊥) λ z → z -- The "why not?" modality ⁇ : LProp → LProp ⁇ (lprop φ₊ φ₋ _) = lprop (φ₋ → ⊥) φ₋ λ x y → y x ---------- -- Here we verify that the H-CLL axioms hold for the modalities. -- A weakening axiom axiom-1! : (P Q : LProp) → ⟦ P ⊸ (! Q ⊸ P) ⟧ axiom-1! (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) = proj₂ , λ y → (λ x _ → p x y) , (λ _ → y) axiom-2! : (P Q : LProp) → ⟦ ! (P ⊸ Q) ⊸ (! P ⊸ ! Q) ⟧ axiom-2! (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) = (λ x y → proj₂ x (proj₂ y (proj₁ x))) , (λ x → (λ y z → y (proj₂ x z)) , proj₂ x) axiom-3! : (P : LProp) → ⟦ ! P ⊸ P ⟧ axiom-3! (lprop φ₊ φ₋ p) = p , (λ x → x) axiom-4! : (P : LProp) → ⟦ ! P ⊸ ! (! P) ⟧ axiom-4! (lprop φ₊ φ₋ p) = (λ x → x) , (λ x → x) -- A contraction axiom axiom-5! : (P Q : LProp) → ⟦ (! P ⊸ (! P ⊸ Q)) ⊸ (! P ⊸ Q) ⟧ axiom-5! (lprop φ₊ φ₋ p) (lprop ψ₊ ψ₋ q) = (λ pq → proj₁ pq , proj₁ pq , proj₂ pq) , (λ x → (λ y z → proj₁ x (z , y) z) , (λ y → proj₂ (proj₂ x y) y)) -- Fortunately, the modal inference rule is trivially verified. modal-rule : (P : LProp) → ⟦ P ⟧ → ⟦ ! P ⟧ modal-rule (lprop φ₊ φ₋ p) x = x
26.785047
91
0.520412
8b10379c64f7c196751bb45a1e5384869199ac8d
182
agda
Agda
test/Succeed/Issue3694.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Succeed/Issue3694.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/Issue3694.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2021-06-14T11:07:38.000Z
2021-06-14T11:07:38.000Z
import Agda.Builtin.Size postulate F : (A : Set) (B : A → Set) → ((x : A) → B x) → Set variable A : Set P : A → Set postulate f : (r : (x : _) → P x) → F _ P (λ x → r x)
14
53
0.472527
03d316118abfec781b83d461bc01c1ecc86f4cae
9,885
agda
Agda
Cubical/Foundations/RelationalStructure.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Foundations/RelationalStructure.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Foundations/RelationalStructure.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{- Definition of what it means to be a notion of relational structure -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.RelationalStructure where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Structure open import Cubical.Foundations.Univalence open import Cubical.Functions.FunExtEquiv open import Cubical.Data.Sigma open import Cubical.HITs.PropositionalTruncation as Trunc open import Cubical.HITs.SetQuotients open import Cubical.Relation.Binary.Base open import Cubical.Relation.ZigZag.Base open BinaryRelation open isEquivRel open isQuasiEquivRel private variable ℓ ℓ' ℓ'' ℓ''' : Level -- A notion of structured relation for a structure S assigns a relation on S X and S Y to every relation on X -- and Y. We require the output to be proposition-valued when the input is proposition-valued. StrRel : (S : Type ℓ → Type ℓ') (ℓ'' : Level) → Type (ℓ-max (ℓ-suc (ℓ-max ℓ ℓ'')) ℓ') StrRel {ℓ = ℓ} S ℓ'' = ∀ {A B} (R : Rel A B ℓ) → Rel (S A) (S B) ℓ'' -- Given a type A and relation R, a quotient structure is a structure on the set quotient A/R such that -- the graph of [_] : A → A/R is a structured relation InducedQuotientStr : (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'') (A : TypeWithStr ℓ S) (R : Rel (typ A) (typ A) ℓ) → Type (ℓ-max ℓ' ℓ'') InducedQuotientStr S ρ A R = Σ[ s ∈ S (typ A / R) ] ρ (graphRel [_]) (A .snd) s -- A structured equivalence relation R on a structured type A should induce a structure on A/R InducesQuotientStr : (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'') → Type _ InducesQuotientStr {ℓ = ℓ} S ρ = (A : TypeWithStr ℓ S) (R : EquivPropRel (typ A) ℓ) → ρ (R .fst .fst) (A .snd) (A .snd) → ∃![ s ∈ S (typ A / R .fst .fst) ] ρ (graphRel [_]) (A .snd) s -- The identity should be a structured relation isReflexiveStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _ isReflexiveStrRel {ℓ = ℓ} {S = S} ρ = {X : Type ℓ} → (s : S X) → ρ (idPropRel X .fst) s s -- The inverse of a structured relation should be structured isSymmetricStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _ isSymmetricStrRel {ℓ = ℓ} {S = S} ρ = {X Y : Type ℓ} (R : PropRel X Y ℓ) {sx : S X} {sy : S Y} → ρ (R .fst) sx sy → ρ (invPropRel R .fst) sy sx -- The composite of structured relations should be structured isTransitiveStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _ isTransitiveStrRel {ℓ = ℓ} {S = S} ρ = {X Y Z : Type ℓ} (R : PropRel X Y ℓ) (R' : PropRel Y Z ℓ) {sx : S X} {sy : S Y} {sz : S Z} → ρ (R .fst) sx sy → ρ (R' .fst) sy sz → ρ (compPropRel R R' .fst) sx sz -- The type of structures on a set should be a set preservesSetsStr : (S : Type ℓ → Type ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ') preservesSetsStr S = ∀ {X} → isSet X → isSet (S X) -- The type of structures on a prop-valued relation should be a prop preservesPropsStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _ preservesPropsStrRel {ℓ = ℓ} {S = S} ρ = {X Y : Type ℓ} {R : Rel X Y ℓ} → (∀ x y → isProp (R x y)) → (sx : S X) (sy : S Y) → isProp (ρ R sx sy) record SuitableStrRel (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'') : Type (ℓ-max (ℓ-max (ℓ-suc ℓ) ℓ') ℓ'') where field quo : InducesQuotientStr S ρ symmetric : isSymmetricStrRel ρ transitive : isTransitiveStrRel ρ set : preservesSetsStr S prop : preservesPropsStrRel ρ open SuitableStrRel public quotientPropRel : ∀ {ℓ} {A : Type ℓ} (R : Rel A A ℓ) → PropRel A (A / R) ℓ quotientPropRel R .fst a t = [ a ] ≡ t quotientPropRel R .snd _ _ = squash/ _ _ -- We can also ask for a notion of structured relations to agree with some notion of structured equivalences. StrRelMatchesEquiv : {S : Type ℓ → Type ℓ'} → StrRel S ℓ'' → StrEquiv S ℓ''' → Type _ StrRelMatchesEquiv {S = S} ρ ι = (A B : TypeWithStr _ S) (e : typ A ≃ typ B) → ρ (graphRel (e .fst)) (A .snd) (B .snd) ≃ ι A B e -- Additional conditions for a "positive" notion of structured relation isDetransitiveStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _ isDetransitiveStrRel {ℓ = ℓ} {S = S} ρ = {X Y Z : Type ℓ} (R : PropRel X Y ℓ) (R' : PropRel Y Z ℓ) {sx : S X} {sz : S Z} → ρ (compPropRel R R' .fst) sx sz → ∃[ sy ∈ S Y ] ρ (R .fst) sx sy × ρ (R' .fst) sy sz record StrRelAction {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℓ' ℓ'')) where field actStr : ∀ {X Y} → (X → Y) → S X → S Y actStrId : ∀ {X} (s : S X) → actStr (idfun X) s ≡ s actRel : ∀ {X₀ Y₀ X₁ Y₁} {f : X₀ → X₁} {g : Y₀ → Y₁} {R₀ : X₀ → Y₀ → Type ℓ} {R₁ : X₁ → Y₁ → Type ℓ} → (∀ x y → R₀ x y → R₁ (f x) (g y)) → ∀ sx sy → ρ R₀ sx sy → ρ R₁ (actStr f sx) (actStr g sy) open StrRelAction public strRelQuotientComparison : {S : Type ℓ → Type ℓ'} {ρ : StrRel S ℓ''} (θ : SuitableStrRel S ρ) (α : StrRelAction ρ) {X : Type ℓ} (R : EquivPropRel X ℓ) → (S X / ρ (R .fst .fst)) → S (X / R .fst .fst) strRelQuotientComparison θ α R [ s ] = α .actStr [_] s strRelQuotientComparison {ρ = ρ} θ α R (eq/ s t r i) = (sym leftEq ∙ rightEq) i where ρs : ρ (R .fst .fst) s s ρs = subst (λ R' → ρ R' s s) (funExt₂ λ x x' → hPropExt squash (R .fst .snd x x') (Trunc.rec (R .fst .snd x x') (λ {(_ , r , r') → R .snd .transitive _ _ _ r (R .snd .symmetric _ _ r')})) (λ r → ∣ x' , r , R .snd .reflexive x' ∣)) (θ .transitive (R .fst) (invPropRel (R .fst)) r (θ .symmetric (R .fst) r)) leftEq : θ .quo (_ , s) R ρs .fst .fst ≡ α .actStr [_] s leftEq = cong fst (θ .quo (_ , s) R ρs .snd ( α .actStr [_] s , subst (λ s' → ρ (graphRel [_]) s' (α .actStr [_] s)) (α .actStrId s) (α .actRel eq/ s s ρs) )) rightEq : θ .quo (_ , s) R ρs .fst .fst ≡ α .actStr [_] t rightEq = cong fst (θ .quo (_ , s) R ρs .snd ( α .actStr [_] t , subst (λ s' → ρ (graphRel [_]) s' (α .actStr [_] t)) (α .actStrId s) (α .actRel eq/ s t r) )) strRelQuotientComparison θ α R (squash/ _ _ p q i j) = θ .set squash/ _ _ (cong (strRelQuotientComparison θ α R) p) (cong (strRelQuotientComparison θ α R) q) i j record PositiveStrRel {S : Type ℓ → Type ℓ'} {ρ : StrRel S ℓ''} (θ : SuitableStrRel S ρ) : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℓ' ℓ'')) where field act : StrRelAction ρ reflexive : isReflexiveStrRel ρ detransitive : isDetransitiveStrRel ρ quo : {X : Type ℓ} (R : EquivPropRel X ℓ) → isEquiv (strRelQuotientComparison θ act R) open PositiveStrRel public posRelReflexive : {S : Type ℓ → Type ℓ'} {ρ : StrRel S ℓ''} {θ : SuitableStrRel S ρ} → PositiveStrRel θ → {X : Type ℓ} (R : EquivPropRel X ℓ) → (s : S X) → ρ (R .fst .fst) s s posRelReflexive {ρ = ρ} σ R s = subst (uncurry (ρ (R .fst .fst))) (ΣPathP (σ .act .actStrId s , σ .act .actStrId s)) (σ .act .actRel (λ x y → Trunc.rec (R .fst .snd _ _) (λ p → subst (R .fst .fst x) p (R .snd .reflexive x))) s s (σ .reflexive s)) -- Given a suitable notion of structured relation, if we have a structured quasi equivalence relation R -- between structured types A and B, we get induced structures on the quotients A/(R ∙ R⁻¹) and B/(R⁻¹ ∙ R), -- and the induced equivalence e : A/(R ∙ R⁻¹) ≃ B/(R⁻¹ ∙ R) is structured with respect to those quotient -- structures. record QERDescends (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'') (A B : TypeWithStr ℓ S) (R : QuasiEquivRel (typ A) (typ B) ℓ) : Type (ℓ-max ℓ' ℓ'') where private module E = QER→Equiv R field quoᴸ : InducedQuotientStr S ρ A E.Rᴸ quoᴿ : InducedQuotientStr S ρ B E.Rᴿ rel : ρ (graphRel (E.Thm .fst)) (quoᴸ .fst) (quoᴿ .fst) open QERDescends structuredQER→structuredEquiv : {S : Type ℓ → Type ℓ'} {ρ : StrRel S ℓ''} (θ : SuitableStrRel S ρ) (A B : TypeWithStr ℓ S) (R : QuasiEquivRel (typ A) (typ B) ℓ) → ρ (R .fst .fst) (A .snd) (B .snd) → QERDescends S ρ A B R structuredQER→structuredEquiv {ρ = ρ} θ (X , s) (Y , t) R r .quoᴸ = θ .quo (X , s) (QER→EquivRel R) (θ .transitive (R .fst) (invPropRel (R .fst)) r (θ .symmetric (R .fst) r)) .fst structuredQER→structuredEquiv {ρ = ρ} θ (X , s) (Y , t) R r .quoᴿ = θ .quo (Y , t) (QER→EquivRel (invQER R)) (θ .transitive (invPropRel (R .fst)) (R .fst) (θ .symmetric (R .fst) r) r) .fst structuredQER→structuredEquiv {ρ = ρ} θ (X , s) (Y , t) R r .rel = subst (λ R' → ρ R' (quol .fst) (quor .fst)) correction (θ .transitive (compPropRel (invPropRel (quotientPropRel E.Rᴸ)) (R .fst)) (quotientPropRel E.Rᴿ) (θ .transitive (invPropRel (quotientPropRel E.Rᴸ)) (R .fst) (θ .symmetric (quotientPropRel E.Rᴸ) (quol .snd)) r) (quor .snd)) where module E = QER→Equiv R quol = structuredQER→structuredEquiv {ρ = ρ} θ (X , s) (Y , t) R r .quoᴸ quor = structuredQER→structuredEquiv {ρ = ρ} θ (X , s) (Y , t) R r .quoᴿ [R] = compPropRel (compPropRel (invPropRel (quotientPropRel E.Rᴸ)) (R .fst)) (quotientPropRel E.Rᴿ) correction : [R] .fst ≡ graphRel (E.Thm .fst) correction = funExt₂ λ qx qy → (hPropExt squash (squash/ _ _) (Trunc.rec (squash/ _ _) (λ {(y , qr , py) → Trunc.rec (squash/ _ _) (λ {(x , px , r) → (cong (E.Thm .fst) (sym px) ∙ E.relToFwd≡ r) ∙ py}) qr})) (elimProp {B = λ qx → E.Thm .fst qx ≡ qy → [R] .fst qx qy} (λ _ → isPropΠ λ _ → squash) (λ x → elimProp {B = λ qy → E.Thm .fst [ x ] ≡ qy → [R] .fst [ x ] qy} (λ _ → isPropΠ λ _ → squash) (λ y p → ∣ _ , ∣ _ , refl , E.fwd≡ToRel p ∣ , refl ∣) qy) qx))
36.747212
109
0.582398
1b0280427b861381b4e19af707ee83599f900707
5,266
agda
Agda
prototyping/Luau/StrictMode.agda
saga/luau
5bb9f379b07e378db0a170e7c4030e3a943b2f14
[ "MIT" ]
null
null
null
prototyping/Luau/StrictMode.agda
saga/luau
5bb9f379b07e378db0a170e7c4030e3a943b2f14
[ "MIT" ]
null
null
null
prototyping/Luau/StrictMode.agda
saga/luau
5bb9f379b07e378db0a170e7c4030e3a943b2f14
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting #-} module Luau.StrictMode where open import Agda.Builtin.Equality using (_≡_) open import FFI.Data.Maybe using (just; nothing) open import Luau.Syntax using (Expr; Stat; Block; BinaryOperator; yes; nil; addr; var; binexp; var_∈_; _⟨_⟩∈_; function_is_end; _$_; block_is_end; local_←_; _∙_; done; return; name; +; -; *; /; <; >; <=; >=; ··) open import Luau.Type using (Type; nil; number; string; boolean; _⇒_; _∪_; _∩_; src; tgt) open import Luau.Subtyping using (_≮:_) open import Luau.Heap using (Heap; function_is_end) renaming (_[_] to _[_]ᴴ) open import Luau.VarCtxt using (VarCtxt; ∅; _⋒_; _↦_; _⊕_↦_; _⊝_) renaming (_[_] to _[_]ⱽ) open import Luau.TypeCheck using (_⊢ᴮ_∈_; _⊢ᴱ_∈_; ⊢ᴴ_; ⊢ᴼ_; _⊢ᴴᴱ_▷_∈_; _⊢ᴴᴮ_▷_∈_; var; addr; app; binexp; block; return; local; function; srcBinOp) open import Properties.Contradiction using (¬) open import Properties.TypeCheck using (typeCheckᴮ) open import Properties.Product using (_,_) data Warningᴱ (H : Heap yes) {Γ} : ∀ {M T} → (Γ ⊢ᴱ M ∈ T) → Set data Warningᴮ (H : Heap yes) {Γ} : ∀ {B T} → (Γ ⊢ᴮ B ∈ T) → Set data Warningᴱ H {Γ} where UnallocatedAddress : ∀ {a T} → (H [ a ]ᴴ ≡ nothing) → --------------------- Warningᴱ H (addr {a} T) UnboundVariable : ∀ {x T p} → (Γ [ x ]ⱽ ≡ nothing) → ------------------------ Warningᴱ H (var {x} {T} p) FunctionCallMismatch : ∀ {M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} → (U ≮: src T) → ----------------- Warningᴱ H (app D₁ D₂) app₁ : ∀ {M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} → Warningᴱ H D₁ → ----------------- Warningᴱ H (app D₁ D₂) app₂ : ∀ {M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} → Warningᴱ H D₂ → ----------------- Warningᴱ H (app D₁ D₂) BinOpMismatch₁ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} → (T ≮: srcBinOp op) → ------------------------------ Warningᴱ H (binexp {op} D₁ D₂) BinOpMismatch₂ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} → (U ≮: srcBinOp op) → ------------------------------ Warningᴱ H (binexp {op} D₁ D₂) bin₁ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} → Warningᴱ H D₁ → ------------------------------ Warningᴱ H (binexp {op} D₁ D₂) bin₂ : ∀ {op M N T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴱ N ∈ U} → Warningᴱ H D₂ → ------------------------------ Warningᴱ H (binexp {op} D₁ D₂) FunctionDefnMismatch : ∀ {f x B T U V} {D : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} → (V ≮: U) → ------------------------- Warningᴱ H (function {f} {U = U} D) function₁ : ∀ {f x B T U V} {D : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} → Warningᴮ H D → ------------------------- Warningᴱ H (function {f} {U = U} D) BlockMismatch : ∀ {b B T U} {D : Γ ⊢ᴮ B ∈ U} → (U ≮: T) → ------------------------------ Warningᴱ H (block {b} {T = T} D) block₁ : ∀ {b B T U} {D : Γ ⊢ᴮ B ∈ U} → Warningᴮ H D → ------------------------------ Warningᴱ H (block {b} {T = T} D) data Warningᴮ H {Γ} where return : ∀ {M B T U} {D₁ : Γ ⊢ᴱ M ∈ T} {D₂ : Γ ⊢ᴮ B ∈ U} → Warningᴱ H D₁ → ------------------ Warningᴮ H (return D₁ D₂) LocalVarMismatch : ∀ {x M B T U V} {D₁ : Γ ⊢ᴱ M ∈ U} {D₂ : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} → (U ≮: T) → -------------------- Warningᴮ H (local D₁ D₂) local₁ : ∀ {x M B T U V} {D₁ : Γ ⊢ᴱ M ∈ U} {D₂ : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} → Warningᴱ H D₁ → -------------------- Warningᴮ H (local D₁ D₂) local₂ : ∀ {x M B T U V} {D₁ : Γ ⊢ᴱ M ∈ U} {D₂ : (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V} → Warningᴮ H D₂ → -------------------- Warningᴮ H (local D₁ D₂) FunctionDefnMismatch : ∀ {f x B C T U V W} {D₁ : (Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V} {D₂ : (Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W} → (V ≮: U) → ------------------------------------- Warningᴮ H (function D₁ D₂) function₁ : ∀ {f x B C T U V W} {D₁ : (Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V} {D₂ : (Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W} → Warningᴮ H D₁ → -------------------- Warningᴮ H (function D₁ D₂) function₂ : ∀ {f x B C T U V W} {D₁ : (Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V} {D₂ : (Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W} → Warningᴮ H D₂ → -------------------- Warningᴮ H (function D₁ D₂) data Warningᴼ (H : Heap yes) : ∀ {V} → (⊢ᴼ V) → Set where FunctionDefnMismatch : ∀ {f x B T U V} {D : (x ↦ T) ⊢ᴮ B ∈ V} → (V ≮: U) → --------------------------------- Warningᴼ H (function {f} {U = U} D) function₁ : ∀ {f x B T U V} {D : (x ↦ T) ⊢ᴮ B ∈ V} → Warningᴮ H D → --------------------------------- Warningᴼ H (function {f} {U = U} D) data Warningᴴ H (D : ⊢ᴴ H) : Set where addr : ∀ a {O} → (p : H [ a ]ᴴ ≡ O) → Warningᴼ H (D a p) → --------------- Warningᴴ H D data Warningᴴᴱ H {Γ M T} : (Γ ⊢ᴴᴱ H ▷ M ∈ T) → Set where heap : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴱ M ∈ T} → Warningᴴ H D₁ → ----------------- Warningᴴᴱ H (D₁ , D₂) expr : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴱ M ∈ T} → Warningᴱ H D₂ → --------------------- Warningᴴᴱ H (D₁ , D₂) data Warningᴴᴮ H {Γ B T} : (Γ ⊢ᴴᴮ H ▷ B ∈ T) → Set where heap : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴮ B ∈ T} → Warningᴴ H D₁ → ----------------- Warningᴴᴮ H (D₁ , D₂) block : ∀ {D₁ : ⊢ᴴ H} {D₂ : Γ ⊢ᴮ B ∈ T} → Warningᴮ H D₂ → --------------------- Warningᴴᴮ H (D₁ , D₂)
27.14433
211
0.430308
4bd4ace5a4c41a4c34215bbaf70a484a50a7f6a6
7,054
agda
Agda
Cubical/Categories/TypesOfCategories/TypeCategory.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Categories/TypesOfCategories/TypeCategory.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Categories/TypesOfCategories/TypeCategory.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --postfix-projections --safe #-} module Cubical.Categories.TypesOfCategories.TypeCategory where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Data.Sigma import Cubical.Functions.Fibration as Fibration open import Cubical.Categories.Category open import Cubical.Categories.Functor open import Cubical.Categories.Presheaf open import Cubical.Categories.Limits.Pullback open import Cubical.Categories.NaturalTransformation open import Cubical.Categories.Instances.Sets open Fibration.ForSets record isTypeCategory {ℓ ℓ' ℓ''} (C : Precategory ℓ ℓ') : Type (ℓ-max ℓ (ℓ-max ℓ' (ℓ-suc ℓ''))) where open Precategory C open Cospan open PullbackLegs open isPullback field -- a Type of types over a context Ty[_] : ob → Type ℓ'' -- extend a context with a type cext : ∀ (Γ : _) → (A : Ty[ Γ ]) → Σ[ ΓA ∈ ob ] (C [ ΓA , Γ ]) -- the new object from a context extension _⍮_ : (Γ : _) → (A : Ty[ Γ ]) → ob Γ ⍮ A = fst (cext Γ A) -- the projection from the extended context to the original π : (Γ : _) → (A : Ty[ Γ ]) → C [ Γ ⍮ A , Γ ] π Γ A = snd (cext Γ A) field -- pullback over context extentions reindex : ∀ {Γ' Γ} → C [ Γ' , Γ ] → (Ty[ Γ ] → Ty[ Γ' ]) q⟨_,_⟩ : ∀ {Γ' Γ} → (f : C [ Γ' , Γ ]) → (A : Ty[ Γ ]) → C [ Γ' ⍮ (reindex f A) , Γ ⍮ A ] isPB : ∀ {Γ' Γ : ob} (f : C [ Γ' , Γ ]) (A : Ty[ Γ ]) → isPullback {C = C} (cospan Γ' Γ (Γ ⍮ A) f (π Γ A)) (pblegs (π Γ' (reindex f A)) q⟨ f , A ⟩) -- presheaves are type contexts module _ {ℓ ℓ' ℓ'' : Level} (C : Precategory ℓ ℓ') where open isTypeCategory open Precategory open Functor open NatTrans open isPullback private -- types over Γ are types with a "projection" (aka surjection) to Γ PSTy[_] : PreShv C ℓ'' .ob → Type _ PSTy[ Γ ] = Σ[ ΓA ∈ PreShv C ℓ'' .ob ] Σ[ π ∈ ΓA ⇒ Γ ] (∀ (c : C .ob) → isSurjSET {A = ΓA ⟅ c ⟆} {Γ ⟅ c ⟆} (π ⟦ c ⟧)) -- just directly use types from above as context extensions PSCext : (Γ : _) → PSTy[ Γ ] → Σ[ ΓA ∈ PreShv C ℓ'' .ob ] ΓA ⇒ Γ PSCext Γ (ΓA , π , _) = ΓA , π -- the pullback or reindexed set is the disjoint union of the fibers -- from the projection module _ {Δ Γ : PreShv C ℓ'' .ob} (γ : Δ ⇒ Γ) (A'@(ΓA , π , isSurjπ) : PSTy[ Γ ]) where ΔA : PreShv C ℓ'' .ob ΔA .F-ob c = ΔATy , isSetΔA where ΔATy = (Σ[ x ∈ fst (Δ ⟅ c ⟆) ] fiber (π ⟦ c ⟧) ((γ ⟦ c ⟧) x)) isSetΔA : isSet ΔATy isSetΔA = isOfHLevelΣ 2 (snd (Δ ⟅ c ⟆)) λ Γc → isOfHLevelΣ 2 (snd (ΓA ⟅ c ⟆)) λ ΓAc → isProp→isSet (snd (Γ ⟅ c ⟆) _ _) -- for morphisms, we apply Δ ⟪ f ⟫ to the first component -- and ΓA ⟪ f ⟫ to the second -- the fiber rule ΔA .F-hom {c} {d} f (δax , γax , eq) = ((Δ ⟪ f ⟫) δax) , (((ΓA ⟪ f ⟫) γax) , ((π ⟦ d ⟧) ((ΓA ⟪ f ⟫) γax) ≡[ i ]⟨ π .N-hom f i γax ⟩ (Γ ⟪ f ⟫) ((π ⟦ c ⟧) γax) ≡[ i ]⟨ (Γ ⟪ f ⟫) (eq i) ⟩ (Γ ⟪ f ⟫) ((γ ⟦ c ⟧) δax) ≡[ i ]⟨ γ .N-hom f (~ i) δax ⟩ (γ ⟦ d ⟧) ((Δ ⟪ f ⟫) δax) ∎)) ΔA .F-id {x = c} = funExt λ (δax , γax , eq) → ΣPathP ((λ i → Δ .F-id i δax) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ (λ i → ΓA .F-id i γax)) ΔA .F-seq {a} {b} {c} f g = funExt λ (δax , γax , eq) → ΣPathP ((λ i → Δ .F-seq f g i δax) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ λ i → ΓA .F-seq f g i γax) π' : ΔA ⇒ Δ π' .N-ob c (x , snd) = x π' .N-hom f = refl PSReindex : PSTy[ Δ ] PSReindex = ΔA , (π' , isSurj) where isSurj : ∀ (c : C .ob) → isSurjSET {A = ΔA ⟅ c ⟆} {B = Δ ⟅ c ⟆} (π' ⟦ c ⟧) isSurj c δx = (δx , isSurjπ c ((γ ⟦ c ⟧) δx)) , refl PSq : ΔA ⇒ ΓA PSq .N-ob c (δax , γax , eq) = γax PSq .N-hom {c} {d} f = funExt λ (δax , γax , eq) → refl PSIsPB : isPullback {C = PreShv C ℓ''} (cospan Δ Γ (fst (PSCext Γ A')) γ (snd (PSCext Γ A'))) (pblegs (snd (PSCext Δ PSReindex)) (PSq)) PSIsPB .sq = makeNatTransPath (funExt sqExt) where sqExt : ∀ (c : C .ob) → _ sqExt c = funExt λ (δax , γax , eq) → sym eq PSIsPB .up {Θ} (cone (pblegs p₁ p₂) sq) = ((α , eq) , unique) where α : Θ ⇒ ΔA α .N-ob c t = ((p₁ ⟦ c ⟧) t) , (((p₂ ⟦ c ⟧) t) , (λ i → (sq (~ i) ⟦ c ⟧) t)) α .N-hom {d} {c} f = funExt αHomExt where αHomExt : ∀ (t : fst (Θ ⟅ d ⟆)) → ((p₁ ⟦ c ⟧) ((Θ ⟪ f ⟫) t) , (p₂ ⟦ c ⟧) ((Θ ⟪ f ⟫) t), _) ≡ ((Δ ⟪ f ⟫) ((p₁ ⟦ d ⟧) t) , (ΓA ⟪ f ⟫) ((p₂ ⟦ d ⟧) t) , _) αHomExt t = ΣPathP ((λ i → p₁ .N-hom f i t) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ (λ i → p₂ .N-hom f i t)) eq : _ eq = makeNatTransPath (funExt (λ _ → funExt λ _ → refl)) , makeNatTransPath (funExt (λ _ → funExt λ _ → refl)) unique : ∀ (βeq : Σ[ β ∈ Θ ⇒ ΔA ] _) → (α , eq) ≡ βeq unique (β , eqβ) = ΣPathP (α≡β , eq≡eqβ) where α≡β : α ≡ β α≡β = makeNatTransPath (funExt λ c → funExt λ t → eqExt c t) where eqβ1 = eqβ .fst eqβ2 = eqβ .snd eqExt : ∀ (c : C .ob) → (t : fst (Θ ⟅ c ⟆)) → (α ⟦ c ⟧) t ≡ (β ⟦ c ⟧) t eqExt c t = ΣPathP ((λ i → (eqβ1 i ⟦ c ⟧) t) , fibersEqIfRepsEq {isSetB = snd (Γ ⟅ c ⟆)} _ (λ i → (eqβ2 i ⟦ c ⟧) t)) eq≡eqβ : PathP (λ i → (p₁ ≡ (α≡β i) ●ᵛ π') × (p₂ ≡ (α≡β i) ●ᵛ PSq)) eq eqβ eq≡eqβ = ΣPathP ( isPropNatP1 (eq .fst) (eqβ .fst) α≡β , isPropNatP2 (eq .snd) (eqβ .snd) α≡β) where isPropNatP1 : isOfHLevelDep 1 (λ γ → p₁ ≡ γ ●ᵛ π') isPropNatP1 = isOfHLevel→isOfHLevelDep 1 (λ _ → isSetNat _ _) isPropNatP2 : isOfHLevelDep 1 (λ γ → p₂ ≡ γ ●ᵛ PSq) isPropNatP2 = isOfHLevel→isOfHLevelDep 1 (λ _ → isSetNat _ _) -- putting everything together isTypeCategoryPresheaf : isTypeCategory (PreShv C ℓ'') isTypeCategoryPresheaf .Ty[_] Γ = PSTy[ Γ ] isTypeCategoryPresheaf .cext = PSCext isTypeCategoryPresheaf .reindex = PSReindex isTypeCategoryPresheaf .q⟨_,_⟩ = PSq isTypeCategoryPresheaf .isPB = PSIsPB
37.521277
128
0.44939
2fd544c333ac3d344d816ff501483389687d6405
651
agda
Agda
agda-stdlib/src/Data/List/Relation/Permutation/Inductive/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Relation/Permutation/Inductive/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Relation/Permutation/Inductive/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Permutation.Inductive.Properties directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Permutation.Inductive.Properties where open import Data.List.Relation.Binary.Permutation.Inductive.Properties public {-# WARNING_ON_IMPORT "Data.List.Relation.Permutation.Inductive.Properties was deprecated in v1.0. Use Data.List.Relation.Binary.Permutation.Inductive.Properties instead." #-}
34.263158
76
0.614439
2e124e727dbab591acc5c9bd88eee2f76a81254d
220
agda
Agda
test/Fail/Issue2927.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2927.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2927.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --sized-types #-} open import Agda.Builtin.Equality open import Agda.Builtin.Size postulate P : (A : Set₁) → A → Set₁ p : (i : Size) (f : {_ : Size< i} → Set) (x : _) → P ({_ : Size< i} → Set) f
20
52
0.545455
38bb94518fce804cb7ef45c3a1e14e1ce5c39657
19,943
agda
Agda
Categories/Category/Construction/Graphs.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Categories/Category/Construction/Graphs.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Categories/Category/Construction/Graphs.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Categories.Category.Construction.Graphs where -- The "Underlying Graph" <-> "Free Category on a Graph" Adjunction. -- Lots of surprises here, of various level of surprisingness -- 1. The Free Category rises universe levels of arrows (and equivalences); the Underlying Graph does not -- (due to the Transitive Closure "Star" construction) -- 2. As a consequence of (1), the eventual Adjunction will be for all Levels being the same -- 3. If you want a Functor Categories Graph, then the object/hom levels are straightforward, -- but if you use "Categories" with NaturalIsomorphism, then the 2-point Groupoid is contractible -- (thus equivalent to the 1-point Category), and yet those two Graphs shouldn't be considered to -- be the same! So _≡F_ must be used so that we have no wiggle room when mapping Graphs around. -- Interestingly, this only shows up when trying to prove that the Underlying Functor respects -- _≈_, which is not traditionally a requirement of a Functor! This requirement is usually left -- implicit. If we were to allow Functor to not respect _≈_, things would be fine. But of course -- we couldn't do any reasonable equational reasoning anymore. Of course, if _≈_ were the global -- _≡_, this isn't an issue, but that is definitely not wanted here. -- 4. A lot of weird little lemmas about _≡_ and subst/transport are needed, because we're in a mixed -- reasoning situation with both ≡ and ≈ present. These could probably be generalized and factored -- into a separate module (or into the standard library). open import Level open import Function using (_$_; flip) renaming (id to idFun; _∘_ to _⊚_) open import Relation.Binary hiding (_⇒_) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_) import Relation.Binary.EqReasoning as EqR open import Relation.Binary.Construct.Closure.ReflexiveTransitive open import Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties hiding (trans) open import Data.Product using (proj₁; proj₂; _,_) open import Categories.Category open import Categories.Functor using (Functor) open import Categories.Functor.Equivalence open import Categories.Category.Instance.StrictCats open import Categories.Utils.EqReasoning open import Categories.NaturalTransformation hiding (id) open import Categories.NaturalTransformation.NaturalIsomorphism hiding (refl; sym; trans; isEquivalence) open import Categories.Adjoint import Categories.Morphism.HeterogeneousIdentity as HId -- a graph has vertices Obj and edges _⇒_, where edges form a setoid over _≈_. record Graph o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where infix 4 _≈_ _⇒_ field Obj : Set o _⇒_ : Rel Obj ℓ _≈_ : ∀ {A B} → Rel (A ⇒ B) e equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B}) setoid : {A B : Obj} → Setoid _ _ setoid {A} {B} = record { Carrier = A ⇒ B ; _≈_ = _≈_ ; isEquivalence = equiv } module Equiv {A} {B} = IsEquivalence (equiv {A} {B}) module EdgeReasoning {A B : Obj} = EqR (setoid {A} {B}) private variable o o′ ℓ ℓ′ e e′ : Level -- This doesn't belong here... but will do for now module PathEquiv {o ℓ e : Level} {Obj : Set o} {_⇒_ : Obj → Obj → Set ℓ} (_≈_ : {A B : Obj} → Rel (A ⇒ B) e) (equiv : {A B : Obj} → IsEquivalence ( _≈_ {A} {B})) where private module E {A} {B} = IsEquivalence (equiv {A} {B}) open E renaming (refl to ≈refl; sym to ≈sym; trans to ≈trans) infix 4 _≈*_ data _≈*_ : {A B : Obj} (p q : Star _⇒_ A B) → Set (o ⊔ ℓ ⊔ e) where ε : {A : Obj} → _≈*_ {A} ε ε _◅_ : {A B C : Obj} {x y : A ⇒ B} {p q : Star _⇒_ B C} (x≈y : x ≈ y) (p≈q : p ≈* q) → x ◅ p ≈* y ◅ q refl : {A B : Obj} {p : Star _⇒_ A B} → p ≈* p refl {p = ε} = ε refl {p = x ◅ p} = ≈refl ◅ refl sym : {A B : Obj} {p q : Star _⇒_ A B} → p ≈* q → q ≈* p sym ε = ε sym (x≈y ◅ eq) = ≈sym x≈y ◅ sym eq ≡⇒≈* : {A B : Obj} {p q : Star _⇒_ A B} → p ≡ q → p ≈* q ≡⇒≈* ≡.refl = refl ≡⇒≈ : {A B : Obj} → {p q : A ⇒ B} → p ≡ q → p ≈ q ≡⇒≈ ≡.refl = ≈refl trans : {A B : Obj} {p q r : Star _⇒_ A B} → p ≈* q → q ≈* r → p ≈* r trans ε ε = ε trans (x≈y ◅ ss) (y≈z ◅ tt) = ≈trans x≈y y≈z ◅ trans ss tt isEquivalence : {A B : Obj} → IsEquivalence (λ (p q : Star _⇒_ A B) → p ≈* q) isEquivalence = record { refl = refl ; sym = sym ; trans = trans } setoid : Obj → Obj → Setoid (o ⊔ ℓ) (o ⊔ ℓ ⊔ e) setoid A B = record { _≈_ = _≈*_ ; isEquivalence = isEquivalence {A} {B} } -- convenient to define here -- -- FIXME: this should go into the standard library at -- Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties ◅◅-identityʳ : {A B : Obj} → (f : Star _⇒_ A B) → f ◅◅ ε ≈* f ◅◅-identityʳ ε = ε ◅◅-identityʳ (x ◅ f) = ≈refl ◅ ◅◅-identityʳ f module PathEqualityReasoning {A B} where open EqR (setoid A B) public module _ (G : Graph o ℓ e) where open Graph G private module P = PathEquiv {o} {ℓ} {e} {Obj} {_⇒_} _≈_ equiv open P Free : Category o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e) Free = record { Obj = Obj ; _⇒_ = Star _⇒_ ; _≈_ = _≈*_ ; id = ε ; _∘_ = _▻▻_ ; assoc = λ {_ _ _ _} {f g h} → sym $ ≡⇒≈* $ ◅◅-assoc f g h ; sym-assoc = λ {_ _ _ _} {f g h} → ≡⇒≈* $ ◅◅-assoc f g h ; identityˡ = λ {_ _ f} → ◅◅-identityʳ f ; identityʳ = refl ; identity² = refl ; equiv = isEquivalence ; ∘-resp-≈ = resp } where resp : ∀ {A B C} {f h : Star _⇒_ B C} {g i : Star _⇒_ A B} → f ≈* h → g ≈* i → (f ▻▻ g) ≈* (h ▻▻ i) resp eq ε = eq resp eq (eq₁ ◅ eq₂) = eq₁ ◅ (resp eq eq₂) open P public renaming (_≈*_ to [_]_≈*_) record GraphMorphism (G : Graph o ℓ e) (G′ : Graph o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where private module G = Graph G module G′ = Graph G′ field M₀ : G.Obj → G′.Obj M₁ : ∀ {A B} → A G.⇒ B → M₀ A G′.⇒ M₀ B M-resp-≈ : ∀ {A B} {f g : A G.⇒ B} → f G.≈ g → M₁ f G′.≈ M₁ g idGHom : {G : Graph o ℓ e} → GraphMorphism G G idGHom = record { M₀ = idFun ; M₁ = idFun ; M-resp-≈ = idFun } _∘GM_ : {G₁ G₂ G₃ : Graph o ℓ e} (m₁ : GraphMorphism G₂ G₃) (m₂ : GraphMorphism G₁ G₂) → GraphMorphism G₁ G₃ m₁ ∘GM m₂ = record { M₀ = M₀ m₁ ⊚ M₀ m₂ ; M₁ = M₁ m₁ ⊚ M₁ m₂ ; M-resp-≈ = M-resp-≈ m₁ ⊚ M-resp-≈ m₂ } where open GraphMorphism module Trsp (G : Graph o ℓ e) where open Graph G -- Two shorthands that will be useful for the definition of morphism -- equality: transport the domain or codomain of an edge along an -- equality. infixr 9 _◂_ infixl 9 _▸_ _◂_ : ∀ {A B C} → A ≡ B → B ⇒ C → A ⇒ C p ◂ f = ≡.subst (_⇒ _) (≡.sym p) f _▸_ : ∀ {A B C} → A ⇒ B → B ≡ C → A ⇒ C f ▸ p = ≡.subst (_ ⇒_) p f -- Some simple properties of transports ◂-▸-comm : ∀ {A B C D} (p : A ≡ B) (f : B ⇒ C) (q : C ≡ D) → p ◂ (f ▸ q) ≡ (p ◂ f) ▸ q ◂-▸-comm ≡.refl f ≡.refl = ≡.refl ◂-trans : ∀ {A B C D} (p : A ≡ B) (q : B ≡ C) (f : C ⇒ D) → p ◂ q ◂ f ≡ (≡.trans p q) ◂ f ◂-trans ≡.refl ≡.refl f = ≡.refl ▸-trans : ∀ {A B C D} (f : A ⇒ B) (p : B ≡ C) (q : C ≡ D) → f ▸ p ▸ q ≡ f ▸ ≡.trans p q ▸-trans f ≡.refl ≡.refl = ≡.refl ◂-resp-≈ : ∀ {A B C} (p : A ≡ B) {f g : B ⇒ C} → f ≈ g → p ◂ f ≈ p ◂ g ◂-resp-≈ ≡.refl f≈g = f≈g ▸-resp-≈ : ∀ {A B C} {f g : A ⇒ B} → f ≈ g → (p : B ≡ C) → f ▸ p ≈ g ▸ p ▸-resp-≈ f≈g ≡.refl = f≈g module TrspGM {G : Graph o ℓ e} {H : Graph o′ ℓ′ e′} (m : GraphMorphism G H) where module G = Graph G module H = Graph H open GraphMorphism m open Trsp G open Trsp H using () renaming (_◂_ to _◃_; _▸_ to _▹_) M-resp-▸ : ∀ {A B C} (f : A G.⇒ B) (p : B ≡ C) → M₁ (f ▸ p) ≡ M₁ f ▹ ≡.cong M₀ p M-resp-▸ f ≡.refl = ≡.refl M-resp-◂ : ∀ {A B C} (p : A ≡ B) (f : B G.⇒ C) → M₁ (p ◂ f) ≡ ≡.cong M₀ p ◃ M₁ f M-resp-◂ ≡.refl f = ≡.refl record GraphMorphism≈ {G : Graph o ℓ e} {G′ : Graph o′ ℓ′ e′} (M M′ : GraphMorphism G G′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where private module G = Graph G module G′ = Graph G′ module M = GraphMorphism M module M′ = GraphMorphism M′ open Trsp G′ -- Pick a presentation of equivalence for graph morphisms that works -- well with functor equality. field M₀≡ : ∀ {X} → M.M₀ X ≡ M′.M₀ X M₁≡ : ∀ {A B} {f : A G.⇒ B} → M.M₁ f ▸ M₀≡ G′.≈ M₀≡ ◂ M′.M₁ f Graphs : ∀ o ℓ e → Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e) Graphs o ℓ e = record { Obj = Graph o ℓ e ; _⇒_ = GraphMorphism ; _≈_ = GraphMorphism≈ ; id = idGHom ; _∘_ = _∘GM_ ; assoc = λ {_ _ _ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G } ; sym-assoc = λ {_ _ _ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G } ; identityˡ = λ {_ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G } ; identityʳ = λ {_ G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G } ; identity² = λ {G} → record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G } ; equiv = λ {_ G} → record { refl = record { M₀≡ = ≡.refl ; M₁≡ = Equiv.refl G } ; sym = λ {i j} eq → record { M₀≡ = ≡.sym (M₀≡ eq) ; M₁≡ = λ {_ _ f} → let open EdgeReasoning G open Trsp G in begin M₁ j f ▸ ≡.sym (M₀≡ eq) ≡˘⟨ ≡.cong (_◂ (M₁ j f ▸ _)) (≡.trans-symˡ (M₀≡ eq)) ⟩ ≡.trans (≡.sym $ M₀≡ eq) (M₀≡ eq) ◂ (M₁ j f ▸ ≡.sym (M₀≡ eq)) ≡˘⟨ ◂-trans (≡.sym $ M₀≡ eq) (M₀≡ eq) _ ⟩ ≡.sym (M₀≡ eq) ◂ M₀≡ eq ◂ (M₁ j f ▸ ≡.sym (M₀≡ eq)) ≡⟨ ≡.cong (≡.sym (M₀≡ eq) ◂_) (◂-▸-comm (M₀≡ eq) (M₁ j f) (≡.sym $ M₀≡ eq)) ⟩ ≡.sym (M₀≡ eq) ◂ ((M₀≡ eq ◂ M₁ j f) ▸ ≡.sym (M₀≡ eq)) ≈˘⟨ ◂-resp-≈ (≡.sym (M₀≡ eq)) (▸-resp-≈ (M₁≡ eq) (≡.sym (M₀≡ eq))) ⟩ ≡.sym (M₀≡ eq) ◂ (M₁ i f ▸ M₀≡ eq ▸ ≡.sym (M₀≡ eq)) ≡⟨ ≡.cong (≡.sym (M₀≡ eq) ◂_) (▸-trans (M₁ i f) (M₀≡ eq) (≡.sym (M₀≡ eq))) ⟩ ≡.sym (M₀≡ eq) ◂ (M₁ i f ▸ ≡.trans (M₀≡ eq) (≡.sym (M₀≡ eq))) ≡⟨ ≡.cong (λ p → ≡.sym (M₀≡ eq) ◂ (M₁ i f ▸ p)) (≡.trans-symʳ (M₀≡ eq)) ⟩ ≡.sym (M₀≡ eq) ◂ M₁ i f ∎ } ; trans = λ {i j k} eq eq′ → record { M₀≡ = ≡.trans (M₀≡ eq) (M₀≡ eq′) ; M₁≡ = λ {_ _ f} → let open EdgeReasoning G open Trsp G in begin M₁ i f ▸ ≡.trans (M₀≡ eq) (M₀≡ eq′) ≡˘⟨ ▸-trans (M₁ i f) (M₀≡ eq) (M₀≡ eq′) ⟩ (M₁ i f ▸ M₀≡ eq) ▸ M₀≡ eq′ ≈⟨ ▸-resp-≈ (M₁≡ eq) (M₀≡ eq′) ⟩ (M₀≡ eq ◂ M₁ j f) ▸ M₀≡ eq′ ≡˘⟨ ◂-▸-comm (M₀≡ eq) (M₁ j f) (M₀≡ eq′) ⟩ M₀≡ eq ◂ (M₁ j f ▸ M₀≡ eq′) ≈⟨ ◂-resp-≈ (M₀≡ eq) (M₁≡ eq′) ⟩ M₀≡ eq ◂ (M₀≡ eq′ ◂ M₁ k f) ≡⟨ ◂-trans (M₀≡ eq) (M₀≡ eq′) (M₁ k f) ⟩ ≡.trans (M₀≡ eq) (M₀≡ eq′) ◂ M₁ k f ∎ } } ; ∘-resp-≈ = λ {_ G H} {f g h i} eq eq′ → record { M₀≡ = ≡.trans (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq) ; M₁≡ = λ {_ _ j} → let open EdgeReasoning H open Trsp H open Trsp G using () renaming (_▸_ to _▹_; _◂_ to _◃_) open TrspGM in begin M₁ (f ∘GM h) j ▸ ≡.trans (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq) ≡˘⟨ ▸-trans (M₁ f (M₁ h j)) (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq) ⟩ M₁ f (M₁ h j) ▸ ≡.cong (M₀ f) (M₀≡ eq′) ▸ M₀≡ eq ≡˘⟨ ≡.cong (_▸ M₀≡ eq) (M-resp-▸ f (M₁ h j) (M₀≡ eq′)) ⟩ M₁ f (M₁ h j ▹ M₀≡ eq′) ▸ M₀≡ eq ≈⟨ M₁≡ eq ⟩ M₀≡ eq ◂ M₁ g (M₁ h j ▹ M₀≡ eq′) ≈⟨ ◂-resp-≈ (M₀≡ eq) (M-resp-≈ g (M₁≡ eq′)) ⟩ M₀≡ eq ◂ M₁ g (M₀≡ eq′ ◃ M₁ i j) ≡⟨ ≡.cong (M₀≡ eq ◂_) (M-resp-◂ g (M₀≡ eq′) (M₁ i j)) ⟩ M₀≡ eq ◂ ≡.cong (M₀ g) (M₀≡ eq′) ◂ M₁ g (M₁ i j) ≡⟨ ◂-trans (M₀≡ eq) (≡.cong (M₀ g) (M₀≡ eq′)) (M₁ g (M₁ i j)) ⟩ ≡.trans (M₀≡ eq) (≡.cong (M₀ g) (M₀≡ eq′)) ◂ M₁ g (M₁ i j) ≡˘⟨ ≡.cong (_◂ M₁ g (M₁ i j)) (≡.naturality (λ _ → M₀≡ eq)) ⟩ ≡.trans (≡.cong (M₀ f) (M₀≡ eq′)) (M₀≡ eq) ◂ M₁ g (M₁ i j) ∎ } } where open Graph open GraphMorphism open GraphMorphism≈ open _≡F_ -- Put the rest of the Graph stuff here too: Underlying₀ : Category o ℓ e → Graph o ℓ e Underlying₀ C = record { Obj = C.Obj ; _⇒_ = C._⇒_ ; _≈_ = C._≈_ ; equiv = C.equiv } where module C = Category C Underlying₁ : {C : Category o ℓ e} {D : Category o′ ℓ′ e′} → Functor C D → GraphMorphism (Underlying₀ C) (Underlying₀ D) Underlying₁ F = record { M₀ = F.F₀ ; M₁ = F.F₁ ; M-resp-≈ = F.F-resp-≈ } where module F = Functor F Underlying : Functor (Cats o ℓ e) (Graphs o ℓ e) Underlying = record { F₀ = Underlying₀ ; F₁ = Underlying₁ ; identity = λ {A} → record { M₀≡ = ≡.refl ; M₁≡ = Category.Equiv.refl A } ; homomorphism = λ where {Z = Z} → record { M₀≡ = ≡.refl ; M₁≡ = Category.Equiv.refl Z } ; F-resp-≈ = λ {A} {B} {F} {G} F≈G → record { M₀≡ = λ {X} → eq₀ F≈G X ; M₁≡ = λ {x} {y} {f} → let open Category B open HId B open Trsp (Underlying₀ B) open Functor open Graph.EdgeReasoning (Underlying₀ B) in begin F₁ F f ▸ eq₀ F≈G y ≈⟨ hid-subst-cod (F₁ F f) (eq₀ F≈G y) ⟩ hid (eq₀ F≈G y) ∘ F₁ F f ≈⟨ eq₁ F≈G f ⟩ F₁ G f ∘ hid (eq₀ F≈G x) ≈˘⟨ hid-subst-dom (eq₀ F≈G x) (F₁ G f) ⟩ eq₀ F≈G x ◂ F₁ G f ∎ } } where open NaturalTransformation open NaturalIsomorphism -- Transports on paths module TrspStar (G : Graph o ℓ e) where open Graph G open Trsp (Underlying₀ (Free G)) public using () renaming ( _◂_ to _◂*_ ; _▸_ to _▸*_ ) open Trsp G -- Lemmas relating transports to path operations. ◂*-▸*-ε : ∀ {A B : Obj} (p : A ≡ B) → ε ▸* p ≡ p ◂* ε ◂*-▸*-ε ≡.refl = ≡.refl ◂*-◅ : ∀ {A B C D : Obj} (p : A ≡ B) (f : B ⇒ C) (fs : Star _⇒_ C D) → p ◂* (f ◅ fs) ≡ (p ◂ f) ◅ fs ◂*-◅ ≡.refl f fs = ≡.refl ◅-▸* : ∀ {A B C D : Obj} (f : A ⇒ B) (fs : Star _⇒_ B C) (p : C ≡ D) → (f ◅ fs) ▸* p ≡ f ◅ (fs ▸* p) ◅-▸* f fs ≡.refl = ≡.refl ◅-◂*-▸ : ∀ {A B C D : Obj} (f : A ⇒ B) (p : B ≡ C) (fs : Star _⇒_ C D) → _≡_ {_} {Star _⇒_ A D} (f ◅ (p ◂* fs)) ((f ▸ p) ◅ fs) ◅-◂*-▸ f ≡.refl fs = ≡.refl -- define these ahead of time module _ {G₁ G₂ : Graph o ℓ e} (G⇒ : GraphMorphism G₁ G₂) where open Graph G₁ renaming (_⇒_ to _⇒₁_; Obj to Obj₁) open Graph G₂ renaming (_⇒_ to _⇒₂_; Obj to Obj₂; module Equiv to Equiv₂) open GraphMorphism G⇒ mapGraph : {A B : Obj₁} → Star _⇒₁_ A B → Star _⇒₂_ (M₀ A) (M₀ B) mapGraph ε = ε mapGraph (x ◅ y) = M₁ x ◅ mapGraph y map-hom : {X Y Z : Graph.Obj G₁} (f : Star _⇒₁_ X Y) {g : Star _⇒₁_ Y Z} → [ G₂ ] mapGraph (f ◅◅ g) ≈* (mapGraph f ◅◅ mapGraph g) map-hom ε {g} = refl G₂ map-hom (x ◅ f) {g} = Equiv₂.refl ◅ map-hom f map-resp : {A B : Obj₁} (f : Star _⇒₁_ A B) {g : Star _⇒₁_ A B} → [ G₁ ] f ≈* g → [ G₂ ] mapGraph f ≈* mapGraph g map-resp ε ε = ε map-resp (x ◅ f) (f≈* ◅ eq) = M-resp-≈ f≈* ◅ map-resp f eq -- don't want a single global GraphMorphism module _ {G : Graph o ℓ e} where open Graph G map-id : {A B : Obj} (f : Star _⇒_ A B) → [ G ] mapGraph (idGHom {G = G}) f ≈* f map-id ε = ε map-id (fs ◅ f) = Equiv.refl ◅ map-id f module _ {X Y Z : Graph o ℓ e} {G₁ : GraphMorphism X Y} {G₂ : GraphMorphism Y Z} where open Graph X map-∘ : {A B : Obj} (f : Star _⇒_ A B) → [ Z ] (mapGraph (G₂ ∘GM G₁) f) ≈* mapGraph G₂ (mapGraph G₁ f) map-∘ ε = ε map-∘ (fs ◅ f) = Graph.Equiv.refl Z ◅ map-∘ f module _ {G H : Graph o ℓ e} {f g : GraphMorphism G H} (f≈g : GraphMorphism≈ f g) where open Graph G open GraphMorphism open GraphMorphism≈ f≈g open TrspStar H open Trsp H map-M₁≡ : {A B : Obj} (hs : Star _⇒_ A B) → [ H ] mapGraph f hs ▸* M₀≡ ≈* M₀≡ ◂* mapGraph g hs map-M₁≡ ε = ≡⇒≈* H (◂*-▸*-ε M₀≡) map-M₁≡ (hs ◅ h) = begin (M₁ f hs ◅ mapGraph f h) ▸* M₀≡ ≡⟨ ◅-▸* (M₁ f hs) _ M₀≡ ⟩ M₁ f hs ◅ (mapGraph f h ▸* M₀≡) ≈⟨ Graph.Equiv.refl H ◅ map-M₁≡ h ⟩ M₁ f hs ◅ (M₀≡ ◂* mapGraph g h) ≡⟨ ◅-◂*-▸ (M₁ f hs) M₀≡ _ ⟩ (M₁ f hs ▸ M₀≡) ◅ mapGraph g h ≈⟨ M₁≡ ◅ (refl H) ⟩ (M₀≡ ◂ M₁ g hs) ◅ mapGraph g h ≡˘⟨ ◂*-◅ M₀≡ (M₁ g hs) _ ⟩ M₀≡ ◂* (M₁ g hs ◅ mapGraph g h) ∎ where open PathEqualityReasoning H module _ (C : Category o ℓ e) where open Category C open HomReasoning -- A helper that should probably go into Categories.Morphism.Reasoning... toSquare : ∀ {A B} {f g : A ⇒ B} → f ≈ g → CommutativeSquare f id id g toSquare {_} {_} {f} {g} f≈g = begin id ∘ f ≈⟨ identityˡ ⟩ f ≈⟨ f≈g ⟩ g ≈˘⟨ identityʳ ⟩ g ∘ id ∎ CatF : Functor (Graphs o ℓ e) (Cats o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e)) CatF = record { F₀ = Free ; F₁ = λ {G₁} {G₂} G⇒ → record { F₀ = M₀ G⇒ ; F₁ = mapGraph G⇒ ; identity = refl G₂ ; homomorphism = λ {_} {_} {_} {f} → map-hom G⇒ f ; F-resp-≈ = λ { {f = f} → map-resp G⇒ f} } ; identity = λ {G} → record { eq₀ = λ _ → ≡.refl ; eq₁ = λ f → toSquare (Free G) (map-id f) } ; homomorphism = λ {_} {_} {G} → record { eq₀ = λ _ → ≡.refl ; eq₁ = λ h → toSquare (Free G) (map-∘ h) } ; F-resp-≈ = λ {_} {G} {f} {g} f≈g → record { eq₀ = λ _ → M₀≡ f≈g ; eq₁ = λ h → let open Category (Free G) open HId (Free G) open TrspStar G open HomReasoning in begin mapGraph f h ◅◅ (hid $ M₀≡ f≈g) ≈˘⟨ hid-subst-cod (mapGraph f h) (M₀≡ f≈g) ⟩ mapGraph f h ▸* M₀≡ f≈g ≈⟨ map-M₁≡ f≈g h ⟩ M₀≡ f≈g ◂* mapGraph g h ≈⟨ hid-subst-dom (M₀≡ f≈g) (mapGraph g h) ⟩ (hid $ M₀≡ f≈g) ◅◅ mapGraph g h ∎ } } where open GraphMorphism open GraphMorphism≈ -- Because of the Level changes in CatF, sizes must all be same: CatF-is-Free : (o : Level) → Adjoint (CatF {o} {o} {o}) (Underlying) CatF-is-Free o = record { unit = ntHelper record { η = GM ; commute = λ {X} {Y} f → record { M₀≡ = ≡.refl ; M₁≡ = Graph.Equiv.refl Y ◅ ε } } ; counit = ntHelper record { η = λ X → record { F₀ = idFun ; F₁ = unwind X ; identity = Category.Equiv.refl X ; homomorphism = λ { {f = f} {g} → unwind-◅◅ X {f = f} {g} } ; F-resp-≈ = unwind-resp-≈ X } ; commute = λ {_} {Y} F → record { eq₀ = λ _ → ≡.refl ; eq₁ = λ f → toSquare Y (comm F f) } } ; zig = λ {G} → record { eq₀ = λ _ → ≡.refl ; eq₁ = λ f → toSquare (Free G) (zig′ G f) } ; zag = λ {B} → record { M₀≡ = ≡.refl ; M₁≡ = Category.identityˡ B } } where GM : (X : Graph o o o) → GraphMorphism X (Underlying₀ (Free X)) GM _ = record { M₀ = idFun ; M₁ = return ; M-resp-≈ = λ f≈g → f≈g ◅ ε } module _ (X : Category o o o) where open Category X open HomReasoning unwind : {A B : Obj} → Star _⇒_ A B → A ⇒ B unwind = fold _⇒_ (flip _∘_) id unwind-◅◅ : {A B C : Obj} {f : Star _⇒_ A B} {g : Star _⇒_ B C} → unwind (f ◅◅ g) ≈ (unwind g) ∘ (unwind f) unwind-◅◅ {f = ε} {g} = Equiv.sym identityʳ unwind-◅◅ {f = x ◅ f} {g} = ∘-resp-≈ˡ (unwind-◅◅ {f = f} {g}) ○ assoc unwind-resp-≈ : {A B : Obj} {f g : Star _⇒_ A B} → [ Underlying₀ X ] f ≈* g → unwind f ≈ unwind g unwind-resp-≈ ε = Equiv.refl unwind-resp-≈ (x ◅ eq) = ∘-resp-≈ (unwind-resp-≈ eq) x zig′ : (X : Graph o o o) → {A B : Graph.Obj X} → (f : Star (Graph._⇒_ X) A B) → let Y = Free X in [ X ] (unwind Y) (mapGraph (GM X) f) ≈* f zig′ A ε = ε zig′ A (fs ◅ f) = Graph.Equiv.refl A ◅ zig′ A f module _ {X Y : Category o o o} (F : Functor X Y) where open Category X renaming (Obj to Obj₁; _⇒_ to _⇒₁_) open Category Y renaming (_≈_ to _≈₂_; module Equiv to EY) open Category.HomReasoning Y open Functor F comm : {A B : Obj₁} (f : Star _⇒₁_ A B) → unwind Y (mapGraph (Underlying₁ F) f) ≈₂ F₁ (unwind X f) comm ε = EY.sym identity comm (x ◅ f) = EY.sym (homomorphism ○ Category.∘-resp-≈ˡ Y (EY.sym (comm f)))
36.592661
120
0.511959
0db9815b03eaa345c56133957f13c28b77c61950
3,194
agda
Agda
agda-stdlib/src/Data/Fin/Substitution/Example.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Fin/Substitution/Example.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Fin/Substitution/Example.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- An example of how Data.Fin.Substitution can be used: a definition -- of substitution for the untyped λ-calculus, along with some lemmas ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Fin.Substitution.Example where open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Nat.Base open import Data.Fin.Base using (Fin) open import Data.Vec.Base open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong; cong₂) open PropEq.≡-Reasoning open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (Star; ε; _◅_) -- A representation of the untyped λ-calculus. Uses de Bruijn indices. infixl 9 _·_ data Tm (n : ℕ) : Set where var : (x : Fin n) → Tm n ƛ : (t : Tm (suc n)) → Tm n _·_ : (t₁ t₂ : Tm n) → Tm n -- Code for applying substitutions. module TmApp {ℓ} {T : ℕ → Set ℓ} (l : Lift T Tm) where open Lift l hiding (var) -- Applies a substitution to a term. infix 8 _/_ _/_ : ∀ {m n} → Tm m → Sub T m n → Tm n var x / ρ = lift (lookup ρ x) ƛ t / ρ = ƛ (t / ρ ↑) t₁ · t₂ / ρ = (t₁ / ρ) · (t₂ / ρ) open Application (record { _/_ = _/_ }) using (_/✶_) -- Some lemmas about _/_. ƛ-/✶-↑✶ : ∀ k {m n t} (ρs : Subs T m n) → ƛ t /✶ ρs ↑✶ k ≡ ƛ (t /✶ ρs ↑✶ suc k) ƛ-/✶-↑✶ k ε = refl ƛ-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (ƛ-/✶-↑✶ k ρs) refl ·-/✶-↑✶ : ∀ k {m n t₁ t₂} (ρs : Subs T m n) → t₁ · t₂ /✶ ρs ↑✶ k ≡ (t₁ /✶ ρs ↑✶ k) · (t₂ /✶ ρs ↑✶ k) ·-/✶-↑✶ k ε = refl ·-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (·-/✶-↑✶ k ρs) refl tmSubst : TermSubst Tm tmSubst = record { var = var; app = TmApp._/_ } open TermSubst tmSubst hiding (var) -- Substitution lemmas. tmLemmas : TermLemmas Tm tmLemmas = record { termSubst = tmSubst ; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ } where module Lemma {T₁ T₂} {lift₁ : Lift T₁ Tm} {lift₂ : Lift T₂ Tm} where open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_) open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_) /✶-↑✶ : ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) → (∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) → ∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k /✶-↑✶ ρs₁ ρs₂ hyp k (var x) = hyp k x /✶-↑✶ ρs₁ ρs₂ hyp k (ƛ t) = begin ƛ t /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.ƛ-/✶-↑✶ _ k ρs₁ ⟩ ƛ (t /✶₁ ρs₁ ↑✶₁ suc k) ≡⟨ cong ƛ (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) t) ⟩ ƛ (t /✶₂ ρs₂ ↑✶₂ suc k) ≡⟨ sym (TmApp.ƛ-/✶-↑✶ _ k ρs₂) ⟩ ƛ t /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (t₁ · t₂) = begin t₁ · t₂ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.·-/✶-↑✶ _ k ρs₁ ⟩ (t₁ /✶₁ ρs₁ ↑✶₁ k) · (t₂ /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _·_ (/✶-↑✶ ρs₁ ρs₂ hyp k t₁) (/✶-↑✶ ρs₁ ρs₂ hyp k t₂) ⟩ (t₁ /✶₂ ρs₂ ↑✶₂ k) · (t₂ /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (TmApp.·-/✶-↑✶ _ k ρs₂) ⟩ t₁ · t₂ /✶₂ ρs₂ ↑✶₂ k ∎ open TermLemmas tmLemmas public hiding (var)
33.270833
86
0.488103
8be305ca0b36255f7e57d9ad7a689688614b00af
201
agda
Agda
test/Succeed/Issue1337.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1337.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1337.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2014-11-01, reported by Andrea Vezzosi -- Non-printable characters in line comments -- Soft hyphen in comment creates lexical error: -- ­ (SOFT HYPHEN \- 0xAD) -- Or parse error: -- A ­
20.1
50
0.691542
4e83f102543c445b0bbc437a1ee4cf429a955af1
836
agda
Agda
test/epic/tests/Nat.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/epic/tests/Nat.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/epic/tests/Nat.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
-- Moved from the successfull test-suite. See Issue 1481. module tests.Nat where data Nat : Set where Z : Nat S : Nat → Nat {-# BUILTIN NATURAL Nat #-} _+_ : Nat → Nat → Nat Z + m = m S n + m = S (n + m) {-# BUILTIN NATPLUS _+_ #-} _*_ : Nat → Nat → Nat Z * m = Z S n * m = m + (n * m) {-# BUILTIN NATTIMES _*_ #-} data Unit : Set where unit : Unit postulate IO : Set → Set String : Set natToString : Nat → String putStr : String → IO Unit printNat : Nat → IO Unit printNat n = putStr (natToString n) {-# COMPILED_TYPE IO IO #-} {-# COMPILED_EPIC natToString (n : Any) -> String = bigToStr(n) #-} {-# COMPILED_EPIC putStr (a : String, u : Unit) -> Unit = foreign Int "wputStr" (a : String); primUnit #-} main : IO Unit main = printNat (7 * 191) -- should print 1337
18.173913
73
0.572967
0dff71551a8f703241ea80b3564e09232bf02802
6,564
agda
Agda
benchmark/monad/Monad.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
benchmark/monad/Monad.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
benchmark/monad/Monad.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
------------------------------------------------------------------------ -- Parser monad ------------------------------------------------------------------------ open import Relation.Binary open import Relation.Binary.OrderMorphism open import Relation.Binary.PropositionalEquality import Relation.Binary.Props.StrictTotalOrder as STOProps open import Data.Product open import Level module Monad -- Input string positions. {Position : Set} {_<P_ : Rel Position zero} (posOrdered : IsStrictTotalOrder _≡_ _<P_) -- Input strings. (Input : Position -> Set) -- In order to be able to store results in a memo table (and avoid -- having to lift the table code to Set1) the result types have to -- come from the following universe: {Result : Set} (⟦_⟧ : Result -> Set) -- Memoisation keys. These keys must uniquely identify the -- computation that they are associated with, when paired up with -- the current input string position. {Key : let PosPoset = STOProps.poset (record { Carrier = _ ; _≈_ = _; _<_ = _ ; isStrictTotalOrder = posOrdered }) MonoFun = PosPoset ⇒-Poset PosPoset in MonoFun -> Result -> Set} {_≈_ _<_ : Rel (∃₂ Key) zero} (keyOrdered : IsStrictTotalOrder _≈_ _<_) -- Furthermore the underlying equality needs to be strong enough. (funsEqual : _≈_ =[ proj₁ ]⇒ _≡_) (resultsEqual : _≈_ =[ (\rfk -> proj₁ (proj₂ rfk)) ]⇒ _≡_) where open _⇒-Poset_ open STOProps (record { Carrier = _ ; _≈_ = _; _<_ = _ ; isStrictTotalOrder = posOrdered }) import IndexedMap as Map -- renaming (Map to MemoTable) open import Category.Monad open import Category.Monad.State import Data.List as List; open List using (List) open import Data.Unit hiding (poset; _≤_) open import Function open import Data.Maybe hiding (Eq) open import Relation.Binary.Product.StrictLex open import Relation.Binary.Product.Pointwise import Relation.Binary.On as On ------------------------------------------------------------------------ -- Monotone functions MonoFun : Set MonoFun = poset ⇒-Poset poset ------------------------------------------------------------------------ -- Memo tables -- Indices and keys used by the memo table. Index : Set Index = Position × MonoFun × Result data MemoTableKey : Index -> Set where key : forall {f r} (key : Key f r) pos -> MemoTableKey (pos , f , r) -- Input strings of a certain maximum length. Input≤ : Position -> Set Input≤ pos = ∃ \pos′ -> pos′ ≤ pos × Input pos′ -- Memo table values. Value : Index -> Set Value (pos , f , r) = List (⟦ r ⟧ × Input≤ (fun f pos)) -- Shuffles the elements to simplify defining equality and order -- relations for the keys. shuffle : ∃ MemoTableKey -> Position × ∃₂ Key shuffle ((pos , f , r) , key k .pos) = (pos , f , r , k) -- Equality and order. Eq : Rel (∃ MemoTableKey) _ Eq = _≡_ ×-Rel _≈_ on shuffle Lt : Rel (∃ MemoTableKey) _ Lt = ×-Lex _≡_ _<P_ _<_ on shuffle isOrdered : IsStrictTotalOrder Eq Lt isOrdered = On.isStrictTotalOrder shuffle (posOrdered ×-isStrictTotalOrder keyOrdered) indicesEqual′ : Eq =[ proj₁ ]⇒ _≡_ indicesEqual′ {((_ , _ , _) , key _ ._)} {((_ , _ , _) , key _ ._)} (eq₁ , eq₂) = cong₂ _,_ eq₁ (cong₂ _,_ (funsEqual eq₂) (resultsEqual eq₂)) open Map isOrdered (\{k₁} {k₂} -> indicesEqual′ {k₁} {k₂}) Value {- ------------------------------------------------------------------------ -- Parser monad -- The parser monad is built upon a list monad, for backtracking, and -- two state monads. One of the state monads stores a memo table, and -- is unaffected by backtracking. The other state monad, which /is/ -- affected by backtracking, stores the remaining input string. -- The memo table state monad. module MemoState = RawMonadState (StateMonadState MemoTable) -- The list monad. module List = RawMonadPlus List.ListMonadPlus -- The inner monad (memo table plus list). module IM where Inner : Set -> Set Inner R = State MemoTable (List R) InnerMonadPlus : RawMonadPlus Inner InnerMonadPlus = record { monadZero = record { monad = record { return = \x -> return (List.return x) ; _>>=_ = \m f -> List.concat <$> (List.mapM monad f =<< m) } ; ∅ = return List.∅ } ; _∣_ = \m₁ m₂ -> List._∣_ <$> m₁ ⊛ m₂ } where open MemoState InnerMonadState : RawMonadState MemoTable Inner InnerMonadState = record { monad = RawMonadPlus.monad InnerMonadPlus ; get = List.return <$> get ; put = \s -> List.return <$> put s } where open MemoState open RawMonadPlus InnerMonadPlus public open RawMonadState InnerMonadState public using (get; put; modify) -- The complete parser monad. module PM where P : MonoFun -> Set -> Set P f A = forall {n} -> Input n -> IM.Inner (A × Input≤ (fun f n)) -- Memoises the computation, assuming that the key is sufficiently -- unique. memoise : forall {f r} -> Key f r -> P f ⟦ r ⟧ -> P f ⟦ r ⟧ memoise k p {pos} xs = let open IM in helper =<< lookup k′ <$> get where i = (pos , _) k′ : MemoTableKey i k′ = key k pos helper : Maybe (Value i) -> State MemoTable (Value i) helper (just ris) = return ris where open MemoState helper nothing = p xs >>= \ris -> modify (insert k′ ris) >> return ris where open MemoState -- Other monadic operations. return : forall {A} -> A -> P idM A return a = \xs -> IM.return (a , _ , refl , xs) _>>=_ : forall {A B f g} -> P f A -> (A -> P g B) -> P (g ∘M f) B _>>=_ {g = g} m₁ m₂ xs = m₁ xs ⟨ IM._>>=_ ⟩ \ays -> let a = proj₁ ays le = proj₁ $ proj₂ $ proj₂ ays ys = proj₂ $ proj₂ $ proj₂ ays in fix le ⟨ IM._<$>_ ⟩ m₂ a ys where lemma : forall {i j k} -> j ≤ k -> i ≤ fun g j -> i ≤ fun g k lemma j≤k i≤gj = trans i≤gj (monotone g j≤k) fix : forall {A i j} -> i ≤ j -> A × Input≤ (fun g i) -> A × Input≤ (fun g j) fix le = map-× id (map-Σ id (map-× (lemma le) id)) ∅ : forall {A} -> P idM A ∅ = const IM.∅ _∣_ : forall {A f} -> P f A -> P f A -> P f A m₁ ∣ m₂ = \xs -> IM._∣_ (m₁ xs) (m₂ xs) put : forall {n} -> Input n -> P (constM n) ⊤ put xs = \_ -> IM.return (_ , _ , refl , xs) modify : forall {A f} -> (forall {n} -> Input n -> A × Input (fun f n)) -> P f A modify g xs = IM.return (proj₁ gxs , _ , refl , proj₂ gxs) where gxs = g xs -}
28.9163
72
0.573278
d16e8a77750c9c89f39b03ea7940dbb574d1cb43
1,448
agda
Agda
src/Loop/Bundles.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
2
2021-08-15T06:16:13.000Z
2021-08-17T09:14:03.000Z
src/Loop/Bundles.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
2
2021-10-04T05:30:30.000Z
2021-10-09T08:24:56.000Z
src/Loop/Bundles.agda
Akshobhya1234/agda-NonAssociativeAlgebra
443e831e536b756acbd1afd0d6bae7bc0d288048
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Loop.Bundles where open import Algebra.Core open import Relation.Binary open import Level open import Loop.Structures open import Algebra.Bundles open import Algebra.Structures record LeftBolLoop c ℓ : Set (suc (c ⊔ ℓ)) where field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier _\\_ : Op₂ Carrier _//_ : Op₂ Carrier ε : Carrier isLeftBolLoop : IsLeftBolLoop _≈_ _∙_ _\\_ _//_ ε open IsLeftBolLoop isLeftBolLoop public loop : Loop _ _ loop = record { isLoop = isLoop } open Loop loop public using (quasigroup) record RightBolLoop c ℓ : Set (suc (c ⊔ ℓ)) where field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier _\\_ : Op₂ Carrier _//_ : Op₂ Carrier ε : Carrier isRightBolLoop : IsRightBolLoop _≈_ _∙_ _\\_ _//_ ε open IsRightBolLoop isRightBolLoop public loop : Loop _ _ loop = record { isLoop = isLoop } open Loop loop public using (quasigroup) record MoufangLoop c ℓ : Set (suc (c ⊔ ℓ)) where field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier _\\_ : Op₂ Carrier _//_ : Op₂ Carrier ε : Carrier isMoufangLoop : IsMoufangLoop _≈_ _∙_ _\\_ _//_ ε open IsMoufangLoop isMoufangLoop public loop : Loop _ _ loop = record { isLoop = isLoop } open Loop loop public using (quasigroup)
21.939394
56
0.624309
367511754563ec9c403a496b57ef44096870a8b5
3,300
agda
Agda
src/Categories/Category/Monoidal/Instance/StrictCats.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Monoidal/Instance/StrictCats.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Category/Monoidal/Instance/StrictCats.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- The category of Cats is Monoidal module Categories.Category.Monoidal.Instance.StrictCats where open import Level open import Data.Product using (Σ; _×_; _,_; proj₁; proj₂; uncurry) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_; refl; cong₂; sym; module ≡-Reasoning; subst₂; cong) open import Function using (_$_) open import Data.Unit using (⊤; tt) open import Categories.Category open import Categories.Functor using (Functor; _∘F_) renaming (id to idF) open import Categories.Category.Instance.StrictCats open import Categories.Category.Instance.One using (One) open import Categories.Category.Monoidal open import Categories.Functor.Bifunctor open import Categories.Functor.Construction.Constant open import Categories.Functor.Equivalence open import Categories.Category.Product open import Categories.Category.Product.Properties import Categories.Category.Cartesian as Cartesian import Categories.Morphism.HeterogeneousIdentity as HId import Categories.Morphism.HeterogeneousIdentity.Properties as HIdProps import Categories.Morphism.Reasoning as MR open import Categories.Object.Terminal open import Categories.Utils.Product using (zipWith) open import Categories.Utils.EqReasoning -- (Strict) Cats is a (strict) Monoidal Category with Product as Bifunctor module Product {o ℓ e : Level} where private C = Cats o ℓ e open Cartesian C open _≡F_ Cats-has-all : BinaryProducts Cats-has-all = record { product = λ {A} {B} → record { A×B = Product A B ; π₁ = πˡ ; π₂ = πʳ ; ⟨_,_⟩ = _※_ ; project₁ = record { eq₀ = λ _ → ≡.refl ; eq₁ = λ _ → MR.id-comm-sym A } ; project₂ = record { eq₀ = λ _ → ≡.refl ; eq₁ = λ _ → MR.id-comm-sym B } ; unique = λ {hA} {h} {i} {j} left right → let unique-eq₀ X = cong₂ _,_ (≡.sym $ eq₀ left X) (≡.sym $ eq₀ right X) in record { eq₀ = unique-eq₀ ; eq₁ = λ {a} {b} f → let module A = Category A module B = Category B module C = Category C module A×B = Category (Product A B) open A×B.HomReasoning open HId open HIdProps open Functor leq a = ≡.sym $ eq₀ left a req a = ≡.sym $ eq₀ right a in begin hid (Product A B) (unique-eq₀ b) A×B.∘ F₁ (i ※ j) f ≈˘⟨ A×B.∘-resp-≈ˡ (×-hid A B (leq b) (req b)) ⟩ (hid A (leq b) A.∘ F₁ i f , hid B (req b) B.∘ F₁ j f) ≈⟨ eq₁⁻¹ left f , eq₁⁻¹ right f ⟩ F₁ (πˡ C.∘ h) f A.∘ hid A (leq a) , F₁ (πʳ C.∘ h) f B.∘ hid B (req a) ≈⟨ A×B.∘-resp-≈ʳ (×-hid A B (leq a) (req a)) ⟩ (F₁ h f) A×B.∘ (hid (Product A B) (unique-eq₀ a)) ∎ } } } private unique-One : {l : Level} (x : Lift l ⊤) → lift tt ≡ x unique-One (lift tt) = refl One-⊤ : Terminal C One-⊤ = record { ⊤ = One ; ! = const (lift tt) ; !-unique = λ f → record { eq₀ = λ _ → unique-One _ ; eq₁ = λ _ → lift tt } } Cats-is : Cartesian Cats-is = record { terminal = One-⊤ ; products = Cats-has-all } private module Cart = Cartesian.Cartesian Cats-is Cats-Monoidal : Monoidal C Cats-Monoidal = Cart.monoidal
35.106383
80
0.607879
142abe1c55651a113c9f37d52e2bfa1147ebb0a4
175
agda
Agda
agda/PLRTree/Compound.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/PLRTree/Compound.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/PLRTree/Compound.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
module PLRTree.Compound {A : Set} where open import PLRTree {A} data Compound : PLRTree → Set where compound : {t : Tag}{x : A}{l r : PLRTree} → Compound (node t x l r)
25
70
0.651429
4e5ca69ac85377ebe74c629cc27caa542b5d5ce6
11,142
agda
Agda
Univalence/Obsolete/CauchyProofs.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
Univalence/Obsolete/CauchyProofs.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
Univalence/Obsolete/CauchyProofs.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 CauchyProofs where -- Proofs about permutations defined in module Cauchy (everything -- except the multiplicative ones which are defined in CauchyProofsT and -- CauchyProofsS open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; subst; subst₂; cong; cong₂; setoid; proof-irrelevance; module ≡-Reasoning) open import Data.Nat.Properties using (m≤m+n; n≤m+n; n≤1+n; cancel-*-right-≤; ≰⇒>; ¬i+1+j≤i) open import Data.Nat.Properties.Simple using (+-right-identity; +-suc; +-assoc; +-comm; *-assoc; *-comm; *-right-zero; distribʳ-*-+; +-*-suc) open import Data.Nat using (ℕ; suc; _+_; _∸_; _*_; _<_; _≮_; _≤_; _≰_; _≥_; z≤n; s≤s; _≟_; _≤?_; ≤-pred; module ≤-Reasoning) open import Data.Fin using (Fin; zero; suc; toℕ; fromℕ; fromℕ≤; _ℕ-_; _≺_; reduce≥; raise; inject+; inject₁; inject≤; _≻toℕ_) renaming (_+_ to _F+_) open import Data.Fin.Properties using (bounded; inject+-lemma; to-from) open import Data.Vec.Properties using (lookup∘tabulate; tabulate∘lookup; lookup-allFin; tabulate-∘; tabulate-allFin; allFin-map; lookup-++-inject+; lookup-++-≥) open import Data.Vec using (Vec; tabulate; []; _∷_; tail; lookup; zip; zipWith; splitAt; _[_]≔_; allFin; toList) renaming (_++_ to _++V_; map to mapV; concat to concatV) open import Function using (id; _∘_; _$_; _∋_; flip) open import Proofs open import Cauchy ------------------------------------------------------------------------------ -- Proofs about sequential composition -- sequential composition with id on the right is identity scomprid : ∀ {n} → (perm : Cauchy n) → scompcauchy perm (idcauchy n) ≡ perm scomprid {n} perm = begin (scompcauchy perm (idcauchy n) ≡⟨ refl ⟩ tabulate (λ i → lookup (lookup i perm) (allFin n)) ≡⟨ finext (λ i → lookup-allFin (lookup i perm)) ⟩ tabulate (λ i → lookup i perm) ≡⟨ tabulate∘lookup perm ⟩ perm ∎) where open ≡-Reasoning -- sequential composition with id on the left is identity scomplid : ∀ {n} → (perm : Cauchy n) → scompcauchy (idcauchy n) perm ≡ perm scomplid {n} perm = trans (finext (λ i → cong (λ x → lookup x perm) (lookup-allFin i))) (tabulate∘lookup perm) -- sequential composition is associative scompassoc : ∀ {n} → (π₁ π₂ π₃ : Cauchy n) → scompcauchy π₁ (scompcauchy π₂ π₃) ≡ scompcauchy (scompcauchy π₁ π₂) π₃ scompassoc π₁ π₂ π₃ = finext (lookupassoc π₁ π₂ π₃) ------------------------------------------------------------------------------ -- Proofs about additive permutations lookup-subst2 : ∀ {m m'} (i : Fin m) (xs : Vec (Fin m) m) (eq : m ≡ m') → lookup (subst Fin eq i) (subst Cauchy eq xs) ≡ subst Fin eq (lookup i xs) lookup-subst2 i xs refl = refl allFin+ : (m n : ℕ) → allFin (m + n) ≡ mapV (inject+ n) (allFin m) ++V mapV (raise m) (allFin n) allFin+ m n = trans (tabulate-split {m} {n}) (cong₂ _++V_ (tabulate-allFin {m} (inject+ n)) (tabulate-allFin {n} (raise m))) -- swap+ is idempotent -- -- outline of swap+idemp proof -- -- allFin (m + n) ≡ mapV (inject+ n) (allFin m) ++V mapV (raise m) (allFin n) -- zero-m : Vec (Fin (m + n)) m ≡ mapV (inject+ n) (allFin m) -- m-sum : Vec (Fin (m + n)) n ≡ mapV (raise m) (allFin n) -- allFin (n + m) ≡ mapV (inject+ m) (allFin n) ++V mapV (raise n) (allFin m) -- zero-n : Vec (Fin (n + m)) n ≡ mapV (inject+ m) (allFin n) -- n-sum : Vec (Fin (n + m)) m ≡ mapV (raise n) (allFin m) -- -- first swap re-arranges allFin (n + m) to n-sum ++V zero-n -- second swap re-arranges allfin (m + n) to m-sum ++V zero-m -- -- for i = 0, ..., m-1, we have inject+ n i : Fin (m + n) -- lookup (lookup (inject+ n i) (n-sum ++V zero-n)) (m-sum ++V zero-m) ==> -- lookup (lookup i n-sum) (m-sum ++V zero-m) ==> -- lookup (raise n i) (m-sum ++V zero-m) ==> -- lookup i zero-m ==> -- inject+ n i -- -- for i = m, ..., m+n-1, we have raise m i : Fin (m + n) -- lookup (lookup (raise m i) (n-sum ++V zero-n)) (m-sum ++V zero-m) ==> -- lookup (lookup i zero-n) (m-sum ++V zero-m) ==> -- lookup (inject+ m i) (m-sum ++V zero-m) ==> -- lookup i m-sum ==> -- raise m i swap+-left : (m n : ℕ) → ∀ (i : Fin m) → let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in lookup (lookup (inject+ n i) (swap+cauchy m n)) q ≡ inject+ n i swap+-left m n i = let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in begin ( lookup (lookup (inject+ n i) (swap+cauchy m n)) q ≡⟨ cong (flip lookup q) ( (lookup-++-inject+ (tabulate {m} (id+ {m} {n} ∘ raise n)) (tabulate {n} (id+ {m} {n} ∘ inject+ m)) i)) ⟩ lookup (lookup i (tabulate (λ x → subst Fin (+-comm n m) (raise n x)))) q ≡⟨ cong (flip lookup q) (lookup∘tabulate (λ x → subst Fin (+-comm n m) (raise n x)) i) ⟩ lookup (subst Fin (+-comm n m) (raise n i)) q ≡⟨ lookup-subst2 (raise n i) (swap+cauchy n m) (+-comm n m) ⟩ subst Fin (+-comm n m) (lookup (raise n i) (swap+cauchy n m)) ≡⟨ cong (subst Fin (+-comm n m)) (lookup-++-raise (tabulate {n} (id+ {n} ∘ raise m)) (tabulate {m} (id+ {n} ∘ inject+ n)) i) ⟩ subst Fin (+-comm n m) (lookup i (tabulate (λ z → subst Fin (+-comm m n) (inject+ n z)))) ≡⟨ subst-lookup-tabulate-inject+ i ⟩ inject+ n i ∎) where open ≡-Reasoning swap+-right : (m n : ℕ) → (i : Fin n) → let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in lookup (lookup (raise m i) (swap+cauchy m n)) q ≡ raise m i swap+-right m n i = let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in begin ( lookup (lookup (raise m i) (swap+cauchy m n)) q ≡⟨ cong (flip lookup q) ( (lookup-++-raise (tabulate {m} (id+ {m} {n} ∘ raise n)) (tabulate {n} (id+ {m} {n} ∘ inject+ m)) i)) ⟩ lookup (lookup i (tabulate (λ x → subst Fin (+-comm n m) (inject+ m x)))) q ≡⟨ cong (flip lookup q) (lookup∘tabulate (λ x → subst Fin (+-comm n m) (inject+ m x)) i) ⟩ lookup (subst Fin (+-comm n m) (inject+ m i)) q ≡⟨ lookup-subst2 (inject+ m i) (swap+cauchy n m) (+-comm n m) ⟩ subst Fin (+-comm n m) (lookup (inject+ m i) (swap+cauchy n m)) ≡⟨ cong (subst Fin (+-comm n m)) (lookup-++-inject+ (tabulate {n} (id+ {n} ∘ raise m)) (tabulate {m} (id+ {n} ∘ inject+ n)) i) ⟩ subst Fin (+-comm n m) (lookup i (tabulate (λ z → subst Fin (+-comm m n) (raise m z)))) ≡⟨ subst-lookup-tabulate-raise i ⟩ raise m i ∎) where open ≡-Reasoning swap+idemp : (m n : ℕ) → scompcauchy (swap+cauchy m n) (subst Cauchy (+-comm n m) (swap+cauchy n m)) ≡ allFin (m + n) swap+idemp m n = let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in begin (tabulate (λ i → lookup (lookup i (swap+cauchy m n)) q) ≡⟨ tabulate-split {m} {n} ⟩ tabulate {m} (λ i → lookup (lookup (inject+ n i) (swap+cauchy m n)) q) ++V tabulate {n} (λ i → lookup (lookup (raise m i) (swap+cauchy m n)) q) ≡⟨ cong₂ _++V_ (finext (swap+-left m n)) (finext (swap+-right m n)) ⟩ tabulate {m} (inject+ n) ++V tabulate {n} (raise m) ≡⟨ unSplit {m} {n} id ⟩ allFin (m + n) ∎) where open ≡-Reasoning -- Behaviour of parallel additive composition wrt sequential -- a direct proof is hard, but this is really a statement about vectors lookup-left : ∀ {m n} → (i : Fin m) → (pm : Cauchy m) → (pn : Cauchy n) → lookup (inject+ n i) (mapV (inject+ n) pm ++V mapV (raise m) pn) ≡ inject+ n (lookup i pm) lookup-left {m} {n} i pm pn = look-left i (inject+ n) (raise m) pm pn -- as is this lookup-right : ∀ {m n} → (i : Fin n) → (pm : Cauchy m) → (pn : Cauchy n) → lookup (raise m i) (mapV (inject+ n) pm ++V mapV (raise m) pn) ≡ raise m (lookup i pn) lookup-right {m} {n} i pm pn = look-right i (inject+ n) (raise m) pm pn --- find a better name look-left' : ∀ {m n} → (pm qm : Cauchy m) → (pn qn : Cauchy n) → (i : Fin m) → (lookup (lookup (inject+ n i) (pcompcauchy pm pn)) (pcompcauchy qm qn)) ≡ inject+ n (lookup (lookup i pm) qm) look-left' {m} {n} pm qm pn qn i = let pp = pcompcauchy pm pn in let qq = pcompcauchy qm qn in begin ( lookup (lookup (inject+ n i) pp) qq ≡⟨ cong (flip lookup qq) (lookup-++-inject+ (mapV (inject+ n) pm) (mapV (raise m) pn) i) ⟩ lookup (lookup i (mapV (inject+ n) pm)) qq ≡⟨ cong (flip lookup qq) (lookup-map i (inject+ n) pm) ⟩ lookup (inject+ n (lookup i pm)) qq ≡⟨ lookup-left (lookup i pm) qm qn ⟩ inject+ n (lookup (lookup i pm) qm) ∎) where open ≡-Reasoning look-right' : ∀ {m n} → (pm qm : Cauchy m) → (pn qn : Cauchy n) → (i : Fin n) → (lookup (lookup (raise m i) (pcompcauchy pm pn)) (pcompcauchy qm qn)) ≡ raise m (lookup (lookup i pn) qn) look-right' {m} {n} pm qm pn qn i = let pp = pcompcauchy pm pn in let qq = pcompcauchy qm qn in begin ( lookup (lookup (raise m i) pp) qq ≡⟨ cong (flip lookup qq) (lookup-++-raise (mapV (inject+ n) pm) (mapV (raise m) pn) i) ⟩ lookup (lookup i (mapV (raise m) pn)) qq ≡⟨ cong (flip lookup qq) (lookup-map i (raise m) pn) ⟩ lookup (raise m (lookup i pn)) qq ≡⟨ lookup-right (lookup i pn) qm qn ⟩ raise m (lookup (lookup i pn) qn) ∎) where open ≡-Reasoning pcomp-dist : ∀ {m n} → (pm qm : Cauchy m) → (pn qn : Cauchy n) → scompcauchy (pcompcauchy pm pn) (pcompcauchy qm qn) ≡ pcompcauchy (scompcauchy pm qm) (scompcauchy pn qn) pcomp-dist {m} {n} pm qm pn qn = let pp = pcompcauchy pm pn in let qq = pcompcauchy qm qn in let look = λ i → lookup (lookup i pp) qq in begin (scompcauchy pp qq ≡⟨ refl ⟩ tabulate look ≡⟨ tabulate-split {m} {n} ⟩ splitV+ {m} {n} {f = look} ≡⟨ cong₂ _++V_ (finext {m} (look-left' pm qm pn qn)) (finext {n} (look-right' pm qm pn qn)) ⟩ tabulate (λ i → (inject+ n) (lookup (lookup i pm) qm)) ++V tabulate (λ i → (raise m) (lookup (lookup i pn) qn)) ≡⟨ cong₂ _++V_ (tabulate-∘ (inject+ n) (λ i → lookup (lookup i pm) qm)) (tabulate-∘ (raise m) (λ i → lookup (lookup i pn) qn)) ⟩ mapV (inject+ n) (tabulate (λ i → lookup (lookup i pm) qm)) ++V mapV (raise m) (tabulate (λ i → lookup (lookup i pn) qn)) ≡⟨ refl ⟩ pcompcauchy (scompcauchy pm qm) (scompcauchy pn qn) ∎) where open ≡-Reasoning pcomp-id : ∀ {m n} → pcompcauchy (idcauchy m) (idcauchy n) ≡ idcauchy (m + n) pcomp-id {m} {n} = begin (mapV (inject+ n) (idcauchy m) ++V (mapV (raise m) (idcauchy n)) ≡⟨ refl ⟩ mapV (inject+ n) (allFin m) ++V mapV (raise m) (allFin n) ≡⟨ cong₂ _++V_ (sym (tabulate-allFin {m} (inject+ n))) (sym (tabulate-allFin (raise m))) ⟩ tabulate {m} (inject+ n) ++V tabulate {n} (raise m) ≡⟨ unSplit {m} {n} id ⟩ idcauchy (m + n) ∎) where open ≡-Reasoning ------------------------------------------------------------------------------
42.365019
120
0.551786
292c830abb899876b30072a04e35ddcba3c72600
752
agda
Agda
HoTT/Homotopy.agda
michaelforney/hott
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
[ "0BSD" ]
null
null
null
HoTT/Homotopy.agda
michaelforney/hott
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
[ "0BSD" ]
null
null
null
HoTT/Homotopy.agda
michaelforney/hott
ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508
[ "0BSD" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT.Base open import HoTT.Identity module HoTT.Homotopy where open variables private variable f g : A → B -- Lemma 2.4.3 ~-natural : (α : f ~ g) {x y : A} (p : x == y) → α x ∙ ap g p == ap f p ∙ α y ~-natural α {x} refl rewrite α x = refl ~-natural-id : (α : f ~ id) {x y : A} (p : x == y) → α x ∙ p == ap f p ∙ α y ~-natural-id α {x} refl rewrite α x = refl -- Corollary 2.4.4 ~-natural-comm : {f : A → A} (α : f ~ id) → α ∘ f ~ ap f ∘ α ~-natural-comm {f = f} α x = cancelᵣ (α (f x) ∙ₗ ap-id (α x) ⁻¹ ∙ ~-natural α (α x)) module ~-Reasoning where _~⟨_⟩_ : (f : Π A P) {g h : Π A P} → f ~ g → g ~ h → f ~ h x ~⟨ α ⟩ β = α ∙ₕ β infixr 2 _~⟨_⟩_ _∎ : (f : Π A P) → f ~ f _ ∎ = reflₕ infix 3 _∎
25.931034
84
0.506649
a009141f1fdee63453fe067d4d1394dd86a5b39f
12,499
agda
Agda
Lecture5.agda
glangmead/hott_cmu80818
af64d808630f4f1498a75201b6ca4d74d662516b
[ "Unlicense" ]
4
2018-05-03T20:32:19.000Z
2018-09-04T02:52:25.000Z
Lecture5.agda
glangmead/hott_cmu80818
af64d808630f4f1498a75201b6ca4d74d662516b
[ "Unlicense" ]
3
2018-02-22T21:01:16.000Z
2018-03-25T14:44:31.000Z
Lecture5.agda
glangmead/hott_cmu80818
af64d808630f4f1498a75201b6ca4d74d662516b
[ "Unlicense" ]
2
2018-02-22T19:58:46.000Z
2018-06-25T15:05:21.000Z
{-# OPTIONS --without-K #-} module Lecture5 where open import Lecture4 public -- Section 5.1 Homotopies _~_ : {i j : Level} {A : UU i} {B : A → UU j} (f g : (x : A) → B x) → UU (i ⊔ j) f ~ g = (x : _) → Id (f x) (g x) htpy-refl : {i j : Level} {A : UU i} {B : A → UU j} (f : (x : A) → B x) → f ~ f htpy-refl f x = refl htpy-inv : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} → (f ~ g) → (g ~ f) htpy-inv H x = inv (H x) htpy-concat : {i j : Level} {A : UU i} {B : A → UU j} {f : (x : A) → B x} (g : (x : A) → B x) {h : (x : A) → B x} → (f ~ g) → (g ~ h) → (f ~ h) htpy-concat g H K x = concat _ (H x) (K x) htpy-assoc : {i j : Level} {A : UU i} {B : A → UU j} {f g h k : (x : A) → B x} → (H : f ~ g) → (K : g ~ h) → (L : h ~ k) → htpy-concat _ H (htpy-concat _ K L) ~ htpy-concat _ (htpy-concat _ H K) L htpy-assoc H K L x = assoc (H x) (K x) (L x) htpy-left-unit : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} (H : f ~ g) → (htpy-concat _ (htpy-refl f) H) ~ H htpy-left-unit H x = left-unit (H x) htpy-right-unit : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} (H : f ~ g) → (htpy-concat _ H (htpy-refl g)) ~ H htpy-right-unit H x = right-unit (H x) htpy-left-inv : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} (H : f ~ g) → htpy-concat _ (htpy-inv H) H ~ htpy-refl g htpy-left-inv H x = left-inv (H x) htpy-right-inv : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} (H : f ~ g) → htpy-concat _ H (htpy-inv H) ~ htpy-refl f htpy-right-inv H x = right-inv (H x) htpy-left-whisk : {i j k : Level} {A : UU i} {B : UU j} {C : UU k} (h : B → C) {f g : A → B} → (f ~ g) → ((h ∘ f) ~ (h ∘ g)) htpy-left-whisk h H x = ap h (H x) htpy-right-whisk : {i j k : Level} {A : UU i} {B : UU j} {C : UU k} {g h : B → C} (H : g ~ h) (f : A → B) → ((g ∘ f) ~ (h ∘ f)) htpy-right-whisk H f x = H (f x) -- Section 5.2 Bi-invertible maps sec : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j) sec {_} {_} {A} {B} f = Σ (B → A) (λ g → (f ∘ g) ~ id) retr : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j) retr {_} {_} {A} {B} f = Σ (B → A) (λ g → (g ∘ f) ~ id) _retract-of_ : {i j : Level} → UU i → UU j → UU (i ⊔ j) A retract-of B = Σ (A → B) retr is-equiv : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j) is-equiv f = sec f × retr f -- this equivalence symbol is \simeq _≃_ : {i j : Level} (A : UU i) (B : UU j) → UU (i ⊔ j) A ≃ B = Σ (A → B) (λ f → is-equiv f) eqv-sec : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-equiv f → sec f eqv-sec e = pr1 e eqv-secf : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-equiv f → B → A eqv-secf e = pr1 (eqv-sec e) eqv-sech : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → (e : is-equiv f) → ((f ∘ eqv-secf e) ~ id) eqv-sech e = pr2 (eqv-sec e) eqv-retr : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-equiv f → retr f eqv-retr e = pr2 e eqv-retrf : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-equiv f → B → A eqv-retrf e = pr1 (eqv-retr e) eqv-retrh : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → (e : is-equiv f) → (((eqv-retrf e) ∘ f) ~ id) eqv-retrh e = pr2 (eqv-retr e) is-invertible : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j) is-invertible {_} {_} {A} {B} f = Σ (B → A) (λ g → ((f ∘ g) ~ id) × ((g ∘ f) ~ id)) is-equiv-is-invertible : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-invertible f → is-equiv f is-equiv-is-invertible (dpair g (dpair H K)) = pair (dpair g H) (dpair g K) htpy-secf-retrf : {i j : Level} {A : UU i} {B : UU j} {f : A → B} (e : is-equiv f) → (eqv-secf e ~ eqv-retrf e) htpy-secf-retrf {_} {_} {_} {_} {f} (dpair (dpair g issec) (dpair h isretr)) = htpy-concat (h ∘ (f ∘ g)) (htpy-inv (htpy-right-whisk isretr g)) (htpy-left-whisk h issec) is-invertible-is-equiv : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-equiv f → is-invertible f is-invertible-is-equiv {_} {_} {_} {_} {f} (dpair (dpair g issec) (dpair h isretr)) = dpair g (pair issec (htpy-concat (h ∘ f) (htpy-right-whisk (htpy-secf-retrf (dpair (dpair g issec) (dpair h isretr))) f) isretr)) inv-is-equiv : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-equiv f → B → A inv-is-equiv E = pr1 (is-invertible-is-equiv E) issec-inv-is-equiv : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → (E : is-equiv f) → (f ∘ (inv-is-equiv E)) ~ id issec-inv-is-equiv E = pr1 (pr2 (is-invertible-is-equiv E)) isretr-inv-is-equiv : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → (E : is-equiv f) → ((inv-is-equiv E) ∘ f) ~ id isretr-inv-is-equiv E = pr2 (pr2 (is-invertible-is-equiv E)) is-equiv-inv-is-equiv : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → (E : is-equiv f) → is-equiv (inv-is-equiv E) is-equiv-inv-is-equiv {_} {_} {_} {_} {f} E = pair (dpair f (isretr-inv-is-equiv E)) (dpair f (issec-inv-is-equiv E)) is-equiv-id : {i : Level} (A : UU i) → is-equiv (id {_} {A}) is-equiv-id A = pair (dpair id (htpy-refl id)) (dpair id (htpy-refl id)) inv-Pi-swap : {i j k : Level} {A : UU i} {B : UU j} (C : A → B → UU k) → ((y : B) (x : A) → C x y) → ((x : A) (y : B) → C x y) inv-Pi-swap C g x y = g y x is-equiv-swap : {i j k : Level} {A : UU i} {B : UU j} (C : A → B → UU k) → is-equiv (Pi-swap {_} {_} {_} {A} {B} {C}) is-equiv-swap C = pair (dpair (inv-Pi-swap C) (htpy-refl id)) (dpair (inv-Pi-swap C) (htpy-refl id)) -- Section 5.3 The identity type of a Σ-type eq-pair' : {i j : Level} {A : UU i} {B : A → UU j} (s t : Σ A B) → (Σ (Id (pr1 s) (pr1 t)) (λ α → Id (tr B α (pr2 s)) (pr2 t))) → Id s t eq-pair' (dpair x y) (dpair x' y') (dpair refl refl) = refl eq-pair : {i j : Level} {A : UU i} {B : A → UU j} {s t : Σ A B} → (Σ (Id (pr1 s) (pr1 t)) (λ α → Id (tr B α (pr2 s)) (pr2 t))) → Id s t eq-pair {i} {j} {A} {B} {s} {t} = eq-pair' s t pair-eq' : {i j : Level} {A : UU i} {B : A → UU j} (s t : Σ A B) → (Id s t) → Σ (Id (pr1 s) (pr1 t)) (λ α → Id (tr B α (pr2 s)) (pr2 t)) pair-eq' s t refl = dpair refl refl pair-eq : {i j : Level} {A : UU i} {B : A → UU j} {s t : Σ A B} → (Id s t) → Σ (Id (pr1 s) (pr1 t)) (λ α → Id (tr B α (pr2 s)) (pr2 t)) pair-eq {i} {j} {A} {B} {s} {t} = pair-eq' s t isretr-pair-eq : {i j : Level} {A : UU i} {B : A → UU j} (s t : Σ A B) → (((pair-eq' s t) ∘ (eq-pair' s t)) ~ id) isretr-pair-eq (dpair x y) (dpair x' y') (dpair refl refl) = refl issec-pair-eq : {i j : Level} {A : UU i} {B : A → UU j} (s t : Σ A B) → (((eq-pair' s t) ∘ (pair-eq' s t)) ~ id) issec-pair-eq (dpair x y) .(dpair x y) refl = refl is-equiv-eq-pair' : {i j : Level} {A : UU i} {B : A → UU j} (s t : Σ A B) → is-equiv (eq-pair' s t) is-equiv-eq-pair' s t = pair (dpair (pair-eq' s t) (issec-pair-eq s t)) (dpair (pair-eq' s t) (isretr-pair-eq s t)) is-equiv-eq-pair : {i j : Level} {A : UU i} {B : A → UU j} (s t : Σ A B) → is-equiv (eq-pair {i} {j} {A} {B} {s} {t}) is-equiv-eq-pair = is-equiv-eq-pair' -- Exercises below -- Exercise 5.1 singleton-ind-const-htpy : {i : Level} {A : UU i} (a : A) → (const 𝟙 A a) ~ (ind-unit a) singleton-ind-const-htpy a star = refl -- Exercise 5.2 ap-const-is-const-refl : {i j : Level} {A : UU i} {B : UU j} (b : B) {x y : A} → (ap (const A B b)) ~ (const (Id x y) (Id b b) refl) ap-const-is-const-refl b refl = refl -- Exercise 5.3 inv-inv-htpy : {i : Level} {A : UU i} {x y : A} (p : Id x y) → Id (inv (inv p)) p inv-inv-htpy refl = refl is-equiv-inv : {i : Level} {A : UU i} (x y : A) → is-equiv (λ (p : Id x y) → inv p) is-equiv-inv x y = pair (dpair inv inv-inv-htpy) (dpair inv inv-inv-htpy) concat-inv-left-htpy : {i : Level} {A : UU i} {x y z : A} (p : Id x y) → (q : Id y z) → Id ((inv p) · (p · q)) q concat-inv-left-htpy refl q = refl concat-inv-right-htpy : {i : Level} {A : UU i} {x y z : A} (p : Id x y) → (r : Id x z) → Id (p · ((inv p) · r)) r concat-inv-right-htpy refl r = refl is-equiv-concat : {i : Level} {A : UU i} (x y z : A) (p : Id x y) → (is-equiv λ (q : Id y z) → p · q) is-equiv-concat x y z p = pair (dpair (λ (r : Id x z) → ((inv p) · r)) (λ (r : Id x z) → concat-inv-right-htpy p r)) (dpair (λ (r : Id x z) → (inv p) · r) (λ (q : Id y z) → concat-inv-left-htpy p q)) tr-inv-htpy : {i j : Level} {A : UU i} {B : A → UU j} {x y : A} (p : Id x y) (b : B x) → Id (tr B (inv p) (tr B p b)) b tr-inv-htpy refl b = refl tr-inv-htpy' : {i j : Level} {A : UU i} {B : A → UU j} {x y : A} (p : Id x y) (b : B y) → Id (tr B p (tr B (inv p) b)) b tr-inv-htpy' refl b = refl is-equiv-tr : {i j : Level} {A : UU i} (B : A → UU j) {x y : A} (p : Id x y) → is-equiv (λ b → (tr B p b)) is-equiv-tr B p = pair (dpair (tr B (inv p)) (tr-inv-htpy' p)) (dpair (tr B (inv p)) (tr-inv-htpy p)) -- Exercise 5.4 is-equiv-htpy : {i j : Level} {A : UU i} {B : UU j} {f g : A → B} → f ~ g → is-equiv g → is-equiv f is-equiv-htpy H (dpair (dpair gs issec) (dpair gr isretr)) = pair (dpair gs (htpy-concat _ (htpy-right-whisk H gs) issec)) (dpair gr (htpy-concat (gr ∘ _) (htpy-left-whisk gr H) isretr)) -- Exercise 5.5 is-equiv-comp : {i j k : Level} {A : UU i} {B : UU j} {X : UU k} {f : A → X} {g : B → X} {h : A → B} (H : f ~ (g ∘ h)) → is-equiv h → is-equiv g → is-equiv f is-equiv-comp {i} {j} {k} {A} {B} {X} {f} {g} {h} H (dpair (dpair hs hs-issec) (dpair hr hr-isretr)) (dpair (dpair gs gs-issec) (dpair gr gr-isretr)) = is-equiv-htpy H (pair (dpair (hs ∘ gs) (htpy-concat (g ∘ gs) (htpy-left-whisk g (htpy-right-whisk hs-issec gs)) gs-issec)) (dpair (hr ∘ gr) (htpy-concat (hr ∘ h) (htpy-left-whisk hr (htpy-right-whisk gr-isretr h)) hr-isretr))) -- Exercise 5.6 not-not-x-is-x : (x : bool) → Id (not (not x)) x not-not-x-is-x true = refl not-not-x-is-x false = refl is-equiv-not : is-equiv not is-equiv-not = pair (dpair not not-not-x-is-x) (dpair not not-not-x-is-x) path-true-to-false-is-contra : (Id true false) → 𝟘 path-true-to-false-is-contra p = tr (ind-bool 𝟙 𝟘) p star same-image-not-equiv : (f : bool → bool) → (p : Id (f true) (f false)) → (is-equiv f) → 𝟘 same-image-not-equiv f p (dpair f-is-sec (dpair g htpy)) = path-true-to-false-is-contra (true ==⟨ inv (htpy true) ⟩ g(f(true)) ==⟨ (ap g p) ⟩ g(f(false)) ==⟨ htpy false ⟩ false ==∎) -- NOTE: ap g p is a path from g(f(true)) to g(f(false)) -- Exercise 5.7 zpred-zsucc-x-is-x : (x : ℤ) → Id (Zpred (Zsucc x)) x zpred-zsucc-x-is-x (inl Nzero) = refl zpred-zsucc-x-is-x (inl (Nsucc x)) = refl zpred-zsucc-x-is-x (inr (inl star)) = refl zpred-zsucc-x-is-x (inr (inr x)) = refl zsucc-zpred-x-is-x : (x : ℤ) → Id (Zsucc (Zpred x)) x zsucc-zpred-x-is-x (inl x) = refl zsucc-zpred-x-is-x (inr (inl star)) = refl zsucc-zpred-x-is-x (inr (inr Nzero)) = refl zsucc-zpred-x-is-x (inr (inr (Nsucc x))) = refl is-equiv-zsucc : is-equiv Zsucc is-equiv-zsucc = dpair (dpair Zpred zsucc-zpred-x-is-x) (dpair Zpred zpred-zsucc-x-is-x) -- Exercise 5.8 -- construct equivalences A + B <-> B + A and A x B <-> B x A coprod-rev : {i j : Level} (A : UU i) (B : UU j) → (coprod A B) → (coprod B A) coprod-rev A B (inl a) = inr a coprod-rev A B (inr b) = inl b coprod-rev-squared-is-id : {i j : Level} (A : UU i) (B : UU j) → (coprod-rev B A ∘ coprod-rev A B) ~ id coprod-rev-squared-is-id A B (inl a) = refl coprod-rev-squared-is-id A B (inr b) = refl is-equiv-coprod-rev : {i j : Level} (A : UU i) (B : UU j) → is-equiv (coprod-rev A B) is-equiv-coprod-rev A B = dpair (dpair (coprod-rev B A) (coprod-rev-squared-is-id B A)) (dpair (coprod-rev B A) (coprod-rev-squared-is-id A B)) prod-rev : {i j : Level} (A : UU i) (B : UU j) → (prod A B) → (prod B A) prod-rev A B x = pair (pr2 x) (pr1 x) prod-rev-squared-is-id : {i j : Level} (A : UU i) (B : UU j) → (prod-rev B A ∘ prod-rev A B) ~ id prod-rev-squared-is-id A B (dpair a b) = refl is-equiv-prod-rev : {i j : Level} (A : UU i) (B : UU j) → is-equiv (prod-rev A B) is-equiv-prod-rev A B = dpair (dpair (prod-rev B A) (prod-rev-squared-is-id B A)) (dpair (prod-rev B A) (prod-rev-squared-is-id A B)) -- Exercise 5.9 -- i r -- Consider a sec/retr pair A ---> B ---> A with H : r ∘ i ~ id. Show that x = y is a retr of i(x) = i(y) -- path-is-retr-of-apsec : {j k : Level} {A : UU j} {B : UU k} (x : A) (y : A) → (i : A → B) → (r : B → A) → ((r ∘ i) ~ id) → ((Id x y) retract-of (Id (i x) (i y))) -- path-is-retr-of-apsec x y i r H = dpair (ap i) ((dpair (( λ p → x ==⟨ inv (H x) ⟩ r (i x) ==⟨ (ap r p) ⟩ r (i y) ==⟨ (H y) ⟩ y ==∎ )) λ p → {! !}) -- Exercise 5.10 -- Exercise 5.11 -- Exercise 5.12 -- Exercise 5.13
42.084175
215
0.521002
7c3e5f2d3ff69f0d7ba9811b9ef629e08b4947a6
1,509
agda
Agda
src/Tactic/Reflection/Meta.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Reflection/Meta.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Reflection/Meta.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
module Tactic.Reflection.Meta where open import Prelude open import Builtin.Reflection open import Tactic.Reflection.DeBruijn ensureNoMetas : Term → TC ⊤ noMetaArg : Arg Term → TC ⊤ noMetaArg (arg _ v) = ensureNoMetas v noMetaArgs : List (Arg Term) → TC ⊤ noMetaArgs [] = pure _ noMetaArgs (v ∷ vs) = noMetaArg v *> noMetaArgs vs noMetaTel : List (String × Arg Type) → TC ⊤ noMetaTel [] = pure _ noMetaTel ((x , arg _ a) ∷ tel) = ensureNoMetas a *> noMetaTel tel noMetaClause : Clause → TC ⊤ noMetaClause (clause tel ps t) = noMetaTel tel *> ensureNoMetas t noMetaClause (absurd-clause tel ps) = pure _ noMetaClauses : List Clause → TC ⊤ noMetaClauses [] = pure _ noMetaClauses (c ∷ cs) = noMetaClause c *> noMetaClauses cs noMetaAbs : Abs Term → TC ⊤ noMetaAbs (abs _ v) = ensureNoMetas v noMetaSort : Sort → TC ⊤ noMetaSort (set t) = ensureNoMetas t noMetaSort (lit n) = pure _ noMetaSort unknown = pure _ ensureNoMetas (var x args) = noMetaArgs args ensureNoMetas (con c args) = noMetaArgs args ensureNoMetas (def f args) = noMetaArgs args ensureNoMetas (lam v (abs _ t)) = ensureNoMetas t ensureNoMetas (pat-lam cs args) = noMetaClauses cs *> noMetaArgs args ensureNoMetas (pi a b) = noMetaArg a *> noMetaAbs b ensureNoMetas (agda-sort s) = noMetaSort s ensureNoMetas (lit l) = pure _ ensureNoMetas (meta x x₁) = blockOnMeta x ensureNoMetas unknown = pure _ normaliseNoMetas : Term → TC Term normaliseNoMetas a = do a ← normalise a stripBoundNames a <$ ensureNoMetas a
29.588235
69
0.719019
5ec00190515975ad679243188b2b5aaf2e76a26a
5,252
agda
Agda
Function/DomainRaise.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Function/DomainRaise.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Function/DomainRaise.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Function.DomainRaise where open import Data open import Data.Boolean import Functional as Fn import Lvl open import Numeral.Natural open import Numeral.Natural.Oper.Comparisons open import Syntax.Number open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable T X Y Z : Type{ℓ} private variable n : ℕ -- Repeated function type like an n-ary operator. -- Examples: -- (a →̂ b)(0) = (b) -- (a →̂ b)(1) = (a → b) -- (a →̂ b)(2) = (a → a → b) -- (a →̂ b)(3) = (a → a → a → b) -- (a →̂ b)(4) = (a → a → a → a → b) _→̂_ : Type{ℓ₁} → Type{ℓ₂} → (n : ℕ) → Type{if positive?(n) then (ℓ₁ Lvl.⊔ ℓ₂) else ℓ₂} -- TODO: Is the level thing really working? (A →̂ B)(𝟎) = B (A →̂ B)(𝐒(𝟎)) = A → B (A →̂ B)(𝐒(𝐒(n))) = A → (A →̂ B)(𝐒(n)) open import Data.Tuple open import Data.Tuple.Raise apply₁ : let _ = n in X → (X →̂ Y)(𝐒(n)) → (X →̂ Y)(n) apply₁ {𝟎} = Fn.apply apply₁ {𝐒 _} = Fn.apply apply₊ : let _ = n in (X ^ n) → (X →̂ Y)(n) → Y apply₊ {𝟎} <> f = f apply₊ {𝐒(𝟎)} x f = f(x) apply₊ {𝐒(𝐒(n))} (x , xs) f = apply₊ {𝐒(n)} xs (f(x)) -- Applies the same argument on all arguments. -- Examples: -- f : (a →̂ b)(5) -- applyRepeated{0} f(x) = f -- applyRepeated{1} f(x) = f(x) -- applyRepeated{2} f(x) = f(x)(x) -- applyRepeated{3} f(x) = f(x)(x)(x) -- applyRepeated{2}(applyRepeated{3} f(x)) (y) = f(x)(x)(y)(y)(y) applyRepeated : let _ = n in (X →̂ Y)(n) → (X → Y) applyRepeated{𝟎} f(x) = f applyRepeated{𝐒(𝟎)} f(x) = f(x) applyRepeated{𝐒(𝐒(n))} f(x) = applyRepeated{𝐒(n)} (f(x)) (x) {- -- Applies arguments from a function. -- Almost (not really) like a composition operation. -- Examples: -- f : (a →̂ b)(3) -- applyFn f g = f (g(2)) (g(1)) (g(0)) applyFn : ∀{n}{T₁}{T₂} → (T₁ →̂ T₂)(n) → (𝕟(n) → T₁) → T₂ applyFn{𝟎} f g = f applyFn{𝐒(n)} f g = applyFn{n} (f(g(ℕ-to-𝕟 (n) {𝐒(n)} ⦃ [<?]-𝐒 {n} ⦄))) (g ∘ (bound-𝐒{n})) -- TODO: Examples: -- swapReverse {3} f (y₂) (y₁) (y₀) -- = swapReverse {2} (f(y₂)) (y₁) (y₀) -- = swapReverse {1} (f(y₂) (y₁)) (y₀) -- = swapReverse {0} (f(y₂) (y₁) (y₀)) -- = f(y₂) (y₁) (y₀) -- swapReverse : ∀{n}{T₁}{T₂} → (T₁ →̂ T₂)(n) → (T₁ →̂ T₂)(n) -- swapReverse {𝟎} y₀ = y₀ -- swapReverse {𝐒(n)} f(yₙ) = (swapReverse {n} f) ∘ (f(yₙ)) -- directOp : ∀{n}{X}{Y} → ((X → Y) →̂ ((X ^ n) → (Y ^ n)))(n) -} -- Function composition on a multi-argument function (Like PrimitiveRecursion.Composition). -- Examples: -- (f ∘₄ g) x₁ x₂ x₃ x₄ -- = (f ∘₃ g x₁) x₂ x₃ x₄ -- = (f ∘₂ g x₁ x₂) x₃ x₄ -- = (f ∘₁ g x₁ x₂ x₃) x₄ -- = (f ∘ g x₁ x₂ x₃) x₄ -- = f(g x₁ x₂ x₃ x₄) _∘_ : let _ = n ; _ = X ; _ = Y ; _ = Z in (Y → Z) → (X →̂ Y)(n) → (X →̂ Z)(n) _∘_ {𝟎} = Fn.id _∘_ {𝐒(𝟎)} = Fn._∘_ _∘_ {𝐒(𝐒(n))} = Fn._∘_ Fn.∘ (_∘_) -- (f ∘ₙ₊₂ g)(x) = f ∘ₙ₊₁ g(x) _∘[_]_ : let _ = X ; _ = Y ; _ = Z in (Y → Z) → (n : ℕ) → (X →̂ Y)(n) → (X →̂ Z)(n) f ∘[ n ] g = _∘_ {n = n} f g _∘₀_ = _∘_ {0} _∘₁_ = _∘_ {1} _∘₂_ = _∘_ {2} _∘₃_ = _∘_ {3} _∘₄_ = _∘_ {4} _∘₅_ = _∘_ {5} _∘₆_ = _∘_ {6} _∘₇_ = _∘_ {7} _∘₈_ = _∘_ {8} _∘₉_ = _∘_ {9} -- TODO: Flip the arguments and make n explicit -- Single function composition on every argument. -- (f on g)(y₁)(y₂).. = g (f(y₁)) (f(y₂)) .. -- Examples: -- _on_ {3} f g (y₂) (y₁) (y₀) -- = _on_ {2} f (g (f(y₂))) (y₁) (y₀) -- = _on_ {1} f (g (f(y₂)) (f(y₁))) (y₀) -- = _on_ {0} f (g (f(y₂)) (f(y₁)) (f(y₀))) -- = g (f(y₂)) (f(y₁)) (f(y₀)) on : let _ = n ; _ = X ; _ = Y ; _ = Z in (Y →̂ Z)(n) → (X → Y) → (X →̂ Z)(n) on {n = 𝟎} = Fn.const on {n = 𝐒(𝟎)} = Fn._∘_ on {n = 𝐒(𝐒(n))} f g(yₙ) = on {n = 𝐒(n)} (f(g(yₙ))) g -- applyOnFn : ∀{n}{X}{Y} → (Y →̂ Y)(n) → ((X → Y) →̂ (X → Y))(n) -- applyOnFn -- Constructs a left-associated n-ary operator from a binary operator. -- Example: -- naryₗ{3} (_▫_) x₁ x₂ x₃ x₄ x₅ -- = ((naryₗ{2} (_▫_)) Fn.∘ (x₁ ▫_)) x₂ x₃ x₄ -- = (naryₗ{2} (_▫_) (x₁ ▫ x₂)) x₃ x₄ x₅ -- = ((naryₗ{1} (_▫_)) Fn.∘ ((x₁ ▫ x₂) ▫_)) x₃ x₄ x₅ -- = (naryₗ{1} (_▫_) ((x₁ ▫ x₂) ▫ x₃)) x₄ x₅ -- = ((naryₗ{0} (_▫_)) Fn.∘ (((x₁ ▫ x₂) ▫ x₃) ▫_)) x₃ x₄ x₅ -- = (naryₗ{0} (_▫_) (((x₁ ▫ x₂) ▫ x₃) ▫ x₄)) x₅ -- = ((_▫_) (((x₁ ▫ x₂) ▫ x₃) ▫ x₄)) x₅ -- = ((((x₁ ▫ x₂) ▫ x₃) ▫ x₄) ▫_) x₅ -- = (((x₁ ▫ x₂) ▫ x₃) ▫ x₄) x₅ naryₗ : (n : ℕ) → (X → X → X) → (X →̂ X)(𝐒(𝐒(n))) naryₗ(𝟎) (_▫_) = (_▫_) naryₗ(𝐒(n)) (_▫_) x = (naryₗ(n) (_▫_)) Fn.∘ (x ▫_) -- Constructs a right-associated n-ary operator from a binary operator. -- Example: -- naryᵣ{3} (_▫_) x₁ x₂ x₃ x₄ x₅ -- = ((x₁ ▫_) ∘[ 4 ] (naryᵣ{2} (_▫_))) x₂ x₃ x₄ x₅ -- = x₁ ▫ (naryᵣ{2} (_▫_) x₂ x₃ x₄ x₅) -- = x₁ ▫ (((x₂ ▫_) ∘[ 3 ] (naryᵣ{1} (_▫_))) x₃ x₄ x₅) -- = x₁ ▫ (x₂ ▫ (naryᵣ{1} (_▫_) x₃ x₄ x₅)) -- = x₁ ▫ (x₂ ▫ (((x₃ ▫_) ∘[ 2 ] (naryᵣ{0} (_▫_))) x₄ x₅)) -- = x₁ ▫ (x₂ ▫ (x₃ ▫ (naryᵣ{0} (_▫_) x₄ x₅))) -- = x₁ ▫ (x₂ ▫ (x₃ ▫ ((_▫_) x₄ x₅))) -- = x₁ ▫ (x₂ ▫ (x₃ ▫ (x₄ ▫ x₅))) naryᵣ : (n : ℕ) → (X → X → X) → (X →̂ X)(𝐒(𝐒(n))) naryᵣ(𝟎) (_▫_) = (_▫_) naryᵣ(𝐒(n)) (_▫_) x = (x ▫_) ∘[ 𝐒(𝐒(n)) ] (naryᵣ(n) (_▫_)) {- [→̂]-to-[⇉] : (n : ℕ) → ∀{X : Type{ℓ₁}}{Y : Type{ℓ₂}} → (X →̂ Y)(n) → (RaiseType.repeat(n) X ⇉ Y) [→̂]-to-[⇉] 0 f = f [→̂]-to-[⇉] 1 f = f [→̂]-to-[⇉] (𝐒(𝐒(n))) f = [→̂]-to-[⇉] (𝐒(n)) ∘ f -}
33.452229
131
0.450876
0d80a72c3e331c3d1ecefcfb36b263056abfbb00
3,197
agda
Agda
Numeral/Natural/Sequence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Numeral/Natural/Sequence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Numeral/Natural/Sequence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Numeral.Natural.Sequence where import Lvl open import Data open import Data.Either as Either using (_‖_) open import Data.Tuple as Tuple using (_⨯_ ; _,_) import Data.Tuple.Raise as Tuple open import Functional open import Numeral.Natural open import Numeral.Natural.Oper open import Numeral.Natural.Oper.FlooredDivision open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable n : ℕ private variable A : Type{ℓ} private variable B : Type{ℓ} -- Alternates between the two sides, starting with the left. -- A countable bijection for the Either type. -- Examples: -- alternate₂(0) = Left(0) -- alternate₂(2) = Left(1) -- alternate₂(4) = Left(2) -- alternate₂(6) = Left(3) -- alternate₂(1) = Right(0) -- alternate₂(3) = Right(1) -- alternate₂(5) = Right(2) -- alternate₂(7) = Right(3) alternate₂ : ℕ → (ℕ ‖ ℕ) alternate₂(0) = Either.Left 0 alternate₂(1) = Either.Right 0 alternate₂(𝐒(𝐒(n))) = Either.map 𝐒 𝐒 (alternate₂ n) -- The inverse of `alternate₂`. unalternate₂ : (ℕ ‖ ℕ) → ℕ unalternate₂(Either.Left n) = n ⋅ 2 unalternate₂(Either.Right n) = 𝐒(n ⋅ 2) -- Maps two natural numbers to a single one without overlaps by following the inverse diagonals downwards. -- A countable bijection for the tuple pairing type. -- Alternative forms: -- pairIndexing a b = a + (∑(𝕟(a + b)) (i ↦ 𝕟-to-ℕ(i))) -- pairIndexing a b = a + ((a + b) * (a + b + 1) / 2) -- Example: -- Horizontal axis is `a` starting from 0. -- Vertical axis is `b` starting from 0. -- Cells are `pairIndexing a b`. -- 0, 1, 3, 6,10,15 -- 2, 4, 7,11,16,.. -- 5, 8,12,17, .. -- 9,13,18, .. -- 14,19, .. -- 20,.. .. .. .. .. -- Termination: -- Decreases `a` until 0 while at the same time increases `b` (So `b` is at most `a`). -- Then the arguments is swapped, but using the predecessor of `b`. -- This means that `b` will eventually reach 0. {-# TERMINATING #-} pairIndexing : ℕ → ℕ → ℕ pairIndexing 𝟎 𝟎 = 𝟎 pairIndexing (𝐒 a) 𝟎 = 𝐒(pairIndexing 𝟎 a) {-# CATCHALL #-} pairIndexing a (𝐒 b) = 𝐒(pairIndexing (𝐒 a) b) -- A sequence which fills a discrete two dimensional grid (a space bounded in two directions and infinite in the other two). -- It is the inverse of an uncurried `pairIndexing`. -- Example: -- •-→-• ↗→• ↗→• -- ↙ ↗ ↙ ↗ ↙ -- •→↗ • ↗ • • -- ↙ ↗ ↙ -- •→↗ • • • diagonalFilling : ℕ → (ℕ ⨯ ℕ) diagonalFilling 𝟎 = (𝟎 , 𝟎) diagonalFilling (𝐒(n)) with diagonalFilling n ... | (𝟎 , b) = (𝐒(b) , 0) ... | (𝐒(a) , b) = (a , 𝐒(b)) tupleIndexing : (ℕ Tuple.^ n) → ℕ tupleIndexing {𝟎} <> = 𝟎 tupleIndexing {𝐒(𝟎)} x = x tupleIndexing {𝐒(𝐒(n))} (x , y) = pairIndexing x (tupleIndexing {𝐒(n)} y) spaceFilling : ℕ → (ℕ Tuple.^ n) spaceFilling {𝟎} _ = <> spaceFilling {𝐒(𝟎)} i = i spaceFilling {𝐒(𝐒(n))} i = Tuple.mapRight (spaceFilling {𝐒(n)}) (diagonalFilling i) -- Interleaves two sequences into one, alternating between the elements from each sequence. interleave : (ℕ → A) → (ℕ → B) → (ℕ → (A ‖ B)) interleave af bf = Either.map af bf ∘ alternate₂ pair : (ℕ → A) → (ℕ → B) → (ℕ → (A ⨯ B)) pair af bf = Tuple.map af bf ∘ diagonalFilling
32.622449
124
0.611198
2ee421578a38b40ded6688817307ecd0a91916ab
19,340
agda
Agda
src/Rices-theorem.agda
nad/chi
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
[ "MIT" ]
2
2020-05-21T22:58:07.000Z
2020-10-20T16:27:00.000Z
src/Rices-theorem.agda
nad/chi
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
[ "MIT" ]
1
2020-05-21T23:29:54.000Z
2020-06-08T11:08:25.000Z
src/Rices-theorem.agda
nad/chi
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Rice's theorem ------------------------------------------------------------------------ open import Equality.Propositional open import Prelude hiding (const; Decidable) -- To simplify the development, let's work with actual natural numbers -- as variables and constants (see -- Atom.one-can-restrict-attention-to-χ-ℕ-atoms). open import Atom open import Chi χ-ℕ-atoms open import Coding χ-ℕ-atoms open import Free-variables χ-ℕ-atoms import Coding.Instances.Nat -- The theorem is stated and proved under the assumption that a -- correct self-interpreter can be implemented. module Rices-theorem (eval : Exp) (cl-eval : Closed eval) (eval₁ : ∀ p v → Closed p → p ⇓ v → apply eval ⌜ p ⌝ ⇓ ⌜ v ⌝) (eval₂ : ∀ p v → Closed p → apply eval ⌜ p ⌝ ⇓ v → ∃ λ v′ → p ⇓ v′ × v ≡ ⌜ v′ ⌝) where open import H-level.Truncation.Propositional as Trunc hiding (rec) open import Logical-equivalence using (_⇔_) open import Tactic.By.Propositional open import Double-negation equality-with-J open import Equality.Decision-procedures equality-with-J open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import Monad equality-with-J open import Cancellation χ-ℕ-atoms open import Compatibility χ-ℕ-atoms open import Computability χ-ℕ-atoms hiding (_∘_) open import Constants χ-ℕ-atoms open import Deterministic χ-ℕ-atoms open import Propositional χ-ℕ-atoms open import Reasoning χ-ℕ-atoms open import Termination χ-ℕ-atoms open import Values χ-ℕ-atoms open χ-atoms χ-ℕ-atoms open import Combinators as χ hiding (id; if_then_else_) open import Halting-problem open import Internal-coding ------------------------------------------------------------------------ -- The theorem -- Definition of "pointwise semantically equivalent". Pointwise-semantically-equivalent : Closed-exp → Closed-exp → Type Pointwise-semantically-equivalent e₁ e₂ = ∀ e v → semantics [ apply-cl e₁ e ]= v ⇔ semantics [ apply-cl e₂ e ]= v -- This relation is symmetric. symmetric : ∀ e₁ e₂ → Pointwise-semantically-equivalent e₁ e₂ → Pointwise-semantically-equivalent e₂ e₁ symmetric _ _ eq = λ e v → inverse (eq e v) -- Rice's theorem. module _ (P : Closed-exp →Bool) (let P′ = proj₁ P) (e∈ : Closed-exp) (Pe∈ : P′ [ e∈ ]= true) (e∉ : Closed-exp) (¬Pe∉ : P′ [ e∉ ]= false) (resp : ∀ e₁ e₂ {b} → Pointwise-semantically-equivalent e₁ e₂ → P′ [ e₁ ]= b → P′ [ e₂ ]= b) where private module Helper (p : Exp) (cl-p : Closed p) (hyp : ∀ e b → P′ [ e ]= b → apply p ⌜ e ⌝ ⇓ ⌜ b ⌝) where arg : Closed-exp → Closed-exp → Closed-exp arg e p = lambda v-x (apply (lambda v-underscore (apply (proj₁ e) (var v-x))) (apply eval (proj₁ p))) , (Closed′-closed-under-lambda $ Closed′-closed-under-apply (Closed′-closed-under-lambda $ Closed′-closed-under-apply (Closed→Closed′ $ proj₂ e) (Closed′-closed-under-var (inj₂ (inj₁ refl)))) (Closed′-closed-under-apply (Closed→Closed′ cl-eval) (Closed→Closed′ (proj₂ p)))) coded-arg : Closed-exp → Exp coded-arg e = const c-lambda (⌜ v-x ⌝ ∷ const c-apply ( ⌜ Exp.lambda v-underscore (apply (proj₁ e) (var v-x)) ⌝ ∷ const c-apply ( ⌜ eval ⌝ ∷ apply internal-code (var v-p) ∷ []) ∷ []) ∷ []) branches : List Br branches = branch c-false [] (apply p (coded-arg e∈)) ∷ branch c-true [] (χ.not (apply p (coded-arg e∉))) ∷ [] const-loop : Closed-exp const-loop = lambda v-underscore loop , (Closed′-closed-under-lambda $ Closed→Closed′ loop-closed) ⌜const-loop⌝ : Closed-exp ⌜const-loop⌝ = ⌜ proj₁ const-loop ⌝ halts : Exp halts = lambda v-p (case (apply p (proj₁ ⌜const-loop⌝)) branches) cl-coded-arg : ∀ e → Closed′ (v-p ∷ []) (coded-arg e) cl-coded-arg e = Closed′-closed-under-const λ where _ (inj₂ (inj₂ ())) _ (inj₁ refl) → Closed→Closed′ (rep-closed v-x) _ (inj₂ (inj₁ refl)) → Closed′-closed-under-const λ where _ (inj₂ (inj₂ ())) _ (inj₁ refl) → Closed→Closed′ $ rep-closed (Exp.lambda v-underscore (apply (proj₁ e) (var v-x))) _ (inj₂ (inj₁ refl)) → Closed′-closed-under-const λ where _ (inj₂ (inj₂ ())) _ (inj₁ refl) → Closed→Closed′ $ rep-closed eval _ (inj₂ (inj₁ refl)) → Closed′-closed-under-apply (Closed→Closed′ internal-code-closed) (Closed′-closed-under-var (inj₁ refl)) cl-halts : Closed halts cl-halts = Closed′-closed-under-lambda $ Closed′-closed-under-case (Closed′-closed-under-apply (Closed→Closed′ cl-p) (Closed→Closed′ $ proj₂ ⌜const-loop⌝)) (λ where (inj₁ refl) → Closed′-closed-under-apply (Closed→Closed′ cl-p) (cl-coded-arg e∈) (inj₂ (inj₁ refl)) → not-closed $ Closed′-closed-under-apply (Closed→Closed′ cl-p) (cl-coded-arg e∉) (inj₂ (inj₂ ()))) coded-arg⇓⌜arg⌝ : (e p : Closed-exp) → coded-arg e [ v-p ← ⌜ p ⌝ ] ⇓ ⌜ arg e ⌜ p ⌝ ⌝ coded-arg⇓⌜arg⌝ e p = coded-arg e [ v-p ← ⌜ p ⌝ ] ⟶⟨⟩ const c-lambda (⌜ v-x ⌝ ∷ const c-apply ( ⌜ Exp.lambda v-underscore (apply (proj₁ e) (var v-x)) ⌝ [ v-p ← ⌜ p ⌝ ] ∷ const c-apply ( ⌜ eval ⌝ [ v-p ← ⌜ p ⌝ ] ∷ apply (internal-code [ v-p ← ⌜ p ⌝ ]) ⌜ p ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ cong (λ e → const _ (_ ∷ const _ (const _ (_ ∷ const _ (e ∷ _) ∷ _) ∷ _) ∷ _)) (subst-rep (proj₁ e)) ⟩⟶ const c-lambda (⌜ v-x ⌝ ∷ const c-apply ( ⌜ Exp.lambda v-underscore (apply (proj₁ e) (var v-x)) ⌝ ∷ const c-apply ( ⟨ ⌜ eval ⌝ [ v-p ← ⌜ p ⌝ ] ⟩ ∷ apply (internal-code [ v-p ← ⌜ p ⌝ ]) ⌜ p ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep eval) ⟩⟶ const c-lambda (⌜ v-x ⌝ ∷ const c-apply ( ⌜ Exp.lambda v-underscore (apply (proj₁ e) (var v-x)) ⌝ ∷ const c-apply ( ⌜ eval ⌝ ∷ apply ⟨ internal-code [ v-p ← ⌜ p ⌝ ] ⟩ ⌜ p ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-closed _ _ internal-code-closed) ⟩⟶ const c-lambda (⌜ v-x ⌝ ∷ const c-apply ( ⌜ Exp.lambda v-underscore (apply (proj₁ e) (var v-x)) ⌝ ∷ const c-apply ( ⌜ eval ⌝ ∷ apply internal-code ⌜ p ⌝ ∷ []) ∷ []) ∷ []) ⟶⟨ []⇓ (const (there (here (const (there (here (const (there (here ∙))))))))) (internal-code-correct (proj₁ p)) ⟩ const c-lambda (⌜ v-x ⌝ ∷ const c-apply ( ⌜ Exp.lambda v-underscore (apply (proj₁ e) (var v-x)) ⌝ ∷ const c-apply ( ⌜ eval ⌝ ∷ ⌜ ⌜ p ⌝ ⦂ Exp ⌝ ∷ []) ∷ []) ∷ []) ⟶⟨⟩ ⌜ arg e ⌜ p ⌝ ⌝ ■⟨ rep-value (arg e ⌜ p ⌝) ⟩ arg-lemma-⇓ : (e p : Closed-exp) → Terminates (proj₁ p) → Pointwise-semantically-equivalent (arg e ⌜ p ⌝) e arg-lemma-⇓ (e , cl-e) (p , cl-p) (vp , p⇓vp) (e′ , cl-e′) (v , _) = record { to = λ where (apply {v₂ = ve′} lambda q₁ (apply {v₂ = vp} lambda _ (apply {x = x} {e = e-body} {v₂ = ve″} q₂ q₃ q₄))) → apply ⟨ e ⟩ e′ ≡⟨ ⟨by⟩ (substs-closed e cl-e ((v-underscore , vp) ∷ (v-x , ve′) ∷ [])) ⟩⟶ apply (e [ v-x ← ve′ ] [ v-underscore ← vp ]) e′ ⟶⟨ apply q₂ q₁ ⟩ e-body [ x ← ⟨ ve′ ⟩ ] ≡⟨ ⟨by⟩ (values-only-compute-to-themselves (⇓-Value q₁) ( ve′ ≡⟨ sym $ subst-closed _ _ (closed⇓closed q₁ cl-e′) ⟩⟶ ve′ [ v-underscore ← vp ] ⇓⟨ q₃ ⟩■ ve″ )) ⟩⟶ e-body [ x ← ve″ ] ⇓⟨ q₄ ⟩■ v ; from = λ where (apply {v₂ = ve′} q₁ q₂ q₃) → proj₁ (apply-cl (arg (e , cl-e) ⌜ p ⌝) (e′ , cl-e′)) ⟶⟨ apply lambda q₂ ⟩ apply (lambda v-underscore (apply ⟨ e [ v-x ← ve′ ] ⟩ ve′)) (apply eval ⌜ p ⌝ [ v-x ← ve′ ]) ≡⟨ ⟨by⟩ (subst-closed _ _ cl-e) ⟩⟶ apply (lambda v-underscore (apply e ve′)) ⟨ apply eval ⌜ p ⌝ [ v-x ← ve′ ] ⟩ ≡⟨ ⟨by⟩ (subst-closed _ _ $ Closed′-closed-under-apply cl-eval (rep-closed p)) ⟩⟶ apply (lambda v-underscore (apply e ve′)) (apply eval ⌜ p ⌝) ⟶⟨ apply lambda (eval₁ p _ cl-p p⇓vp) ⟩ apply e ve′ [ v-underscore ← ⌜ vp ⌝ ] ≡⟨ subst-closed _ _ $ Closed′-closed-under-apply cl-e (closed⇓closed q₂ cl-e′) ⟩⟶ apply e ve′ ⇓⟨ apply q₁ (values-compute-to-themselves (⇓-Value q₂)) q₃ ⟩■ v } arg-lemma-⇓-true : (e : Closed-exp) → Terminates (proj₁ e) → P′ [ arg e∈ ⌜ e ⌝ ]= true arg-lemma-⇓-true e e⇓ = $⟨ Pe∈ ⟩ P′ [ e∈ ]= true ↝⟨ resp _ _ (symmetric (arg e∈ ⌜ e ⌝) e∈ (arg-lemma-⇓ e∈ e e⇓)) ⟩□ P′ [ arg e∈ ⌜ e ⌝ ]= true □ arg-lemma-⇓-false : (e : Closed-exp) → Terminates (proj₁ e) → P′ [ arg e∉ ⌜ e ⌝ ]= false arg-lemma-⇓-false e e⇓ = $⟨ ¬Pe∉ ⟩ P′ [ e∉ ]= false ↝⟨ resp _ _ (symmetric (arg e∉ ⌜ e ⌝) e∉ (arg-lemma-⇓ e∉ e e⇓)) ⟩□ P′ [ arg e∉ ⌜ e ⌝ ]= false □ arg-lemma-¬⇓′ : (e p : Closed-exp) → ¬ Terminates (proj₁ p) → Pointwise-semantically-equivalent (arg e ⌜ p ⌝) const-loop arg-lemma-¬⇓′ (e , cl-e) (p , cl-p) ¬p⇓ (e′ , cl-e′) (v , _) = record { to = λ where (apply {v₂ = ve′} lambda _ (apply {v₂ = vp} _ q _)) → ⊥-elim $ ¬p⇓ $ Σ-map id proj₁ $ eval₂ p vp cl-p ( apply eval ⌜ p ⌝ ≡⟨ sym $ subst-closed _ _ $ Closed′-closed-under-apply cl-eval (rep-closed p) ⟩⟶ apply eval ⌜ p ⌝ [ v-x ← ve′ ] ⇓⟨ q ⟩■ vp) ; from = λ where (apply lambda _ loop⇓) → ⊥-elim $ ¬loop⇓ (_ , loop⇓) } arg-lemma-¬⇓ : ∀ {b} (e₀ e : Closed-exp) → ¬ Terminates (proj₁ e) → P′ [ const-loop ]= b → P′ [ arg e₀ ⌜ e ⌝ ]= b arg-lemma-¬⇓ {b} e₀ e ¬e⇓ = P′ [ const-loop ]= b ↝⟨ resp _ _ (symmetric (arg e₀ ⌜ e ⌝) const-loop (arg-lemma-¬⇓′ e₀ e ¬e⇓)) ⟩□ P′ [ arg e₀ ⌜ e ⌝ ]= b □ ∃Bool : Type ∃Bool = ∃ λ (b : Bool) → apply p (proj₁ ⌜const-loop⌝) ⇓ ⌜ b ⌝ × P′ [ const-loop ]= b ¬¬∃ : ¬¬ ∃Bool ¬¬∃ = excluded-middle {A = P′ [ const-loop ]= true} >>= λ where (inj₁ P-const-loop) → return ( true , hyp const-loop true P-const-loop , P-const-loop ) (inj₂ ¬P-const-loop) → proj₂ P const-loop >>= λ where (true , P-const-loop) → ⊥-elim (¬P-const-loop P-const-loop) (false , ¬P-const-loop) → return ( false , hyp const-loop false ¬P-const-loop , ¬P-const-loop ) halts⇓-lemma : ∀ {v} → ∃Bool → (e : Closed-exp) → (P′ [ const-loop ]= false → apply p (⌜ arg e∈ ⌜ e ⌝ ⌝) ⇓ v) → (P′ [ const-loop ]= true → χ.not (apply p (⌜ arg e∉ ⌜ e ⌝ ⌝)) ⇓ v) → apply halts ⌜ e ⌝ ⇓ v halts⇓-lemma {v} ∃bool e e∈⇓v e∉⇓v = apply halts ⌜ e ⌝ ⟶⟨ apply lambda (rep⇓rep e) ⟩ case (apply ⟨ p [ v-p ← ⌜ e ⌝ ] ⟩ (proj₁ ⌜const-loop⌝)) (branches [ v-p ← ⌜ e ⌝ ]B⋆) ≡⟨ ⟨by⟩ (subst-closed _ _ cl-p) ⟩⟶ case (apply p (proj₁ ⌜const-loop⌝)) (branches [ v-p ← ⌜ e ⌝ ]B⋆) ⇓⟨ lemma ∃bool ⟩■ v where lemma : ∃Bool → _ lemma (true , p⌜const-loop⌝⇓true , P-const-loop) = case (apply p (proj₁ ⌜const-loop⌝)) (branches [ v-p ← ⌜ e ⌝ ]B⋆) ⟶⟨ case p⌜const-loop⌝⇓true (there (λ ()) here) [] ⟩ χ.not (apply ⟨ p [ v-p ← ⌜ e ⌝ ] ⟩ (coded-arg e∉ [ v-p ← ⌜ e ⌝ ])) ≡⟨ ⟨by⟩ (subst-closed _ _ cl-p) ⟩⟶ χ.not (apply p (coded-arg e∉ [ v-p ← ⌜ e ⌝ ])) ⟶⟨ []⇓ (case (apply→ ∙)) (coded-arg⇓⌜arg⌝ e∉ e) ⟩ χ.not (apply p (⌜ arg e∉ ⌜ e ⌝ ⌝)) ⇓⟨ e∉⇓v P-const-loop ⟩■ v lemma (false , p⌜const-loop⌝⇓false , ¬P-const-loop) = case (apply p (proj₁ ⌜const-loop⌝)) (branches [ v-p ← ⌜ e ⌝ ]B⋆) ⟶⟨ case p⌜const-loop⌝⇓false here [] ⟩ apply ⟨ p [ v-p ← ⌜ e ⌝ ] ⟩ (coded-arg e∈ [ v-p ← ⌜ e ⌝ ]) ≡⟨ ⟨by⟩ (subst-closed _ _ cl-p) ⟩⟶ apply p (coded-arg e∈ [ v-p ← ⌜ e ⌝ ]) ⟶⟨ []⇓ (apply→ ∙) (coded-arg⇓⌜arg⌝ e∈ e) ⟩ apply p (⌜ arg e∈ ⌜ e ⌝ ⌝) ⇓⟨ e∈⇓v ¬P-const-loop ⟩■ v ⇓-lemma : ∃Bool → (e : Closed-exp) → Terminates (proj₁ e) → apply halts ⌜ e ⌝ ⇓ ⌜ true ⦂ Bool ⌝ ⇓-lemma ∃bool e e⇓ = halts⇓-lemma ∃bool e (λ _ → apply p (⌜ arg e∈ ⌜ e ⌝ ⌝) ⇓⟨ hyp (arg e∈ ⌜ e ⌝) true (arg-lemma-⇓-true e e⇓) ⟩■ ⌜ true ⦂ Bool ⌝) (λ _ → χ.not (apply p (⌜ arg e∉ ⌜ e ⌝ ⌝)) ⟶⟨ []⇓ (case ∙) (hyp (arg e∉ ⌜ e ⌝) false (arg-lemma-⇓-false e e⇓)) ⟩ χ.not ⌜ false ⦂ Bool ⌝ ⇓⟨ not-correct false (rep⇓rep (false ⦂ Bool)) ⟩■ ⌜ true ⦂ Bool ⌝) ¬⇓-lemma : ∃Bool → (e : Closed-exp) → ¬ Terminates (proj₁ e) → apply halts ⌜ e ⌝ ⇓ ⌜ false ⦂ Bool ⌝ ¬⇓-lemma ∃bool e ¬e⇓ = halts⇓-lemma ∃bool e (λ ¬P-const-loop → apply p (⌜ arg e∈ ⌜ e ⌝ ⌝) ⇓⟨ hyp (arg e∈ ⌜ e ⌝) false (arg-lemma-¬⇓ e∈ e ¬e⇓ ¬P-const-loop) ⟩■ ⌜ false ⦂ Bool ⌝) (λ P-const-loop → χ.not (apply p (⌜ arg e∉ ⌜ e ⌝ ⌝)) ⟶⟨ []⇓ (case ∙) (hyp (arg e∉ ⌜ e ⌝) true (arg-lemma-¬⇓ e∉ e ¬e⇓ P-const-loop)) ⟩ χ.not ⌜ true ⦂ Bool ⌝ ⇓⟨ not-correct true (rep⇓rep (true ⦂ Bool)) ⟩■ ⌜ false ⦂ Bool ⌝) rice's-theorem : ¬ Decidable P rice's-theorem (p , cl-p , hyp , _) = ¬¬¬⊥ $ ¬¬∃ >>= λ ∃bool → return (intensional-halting-problem₀ ( halts , cl-halts , λ e cl-e → ⇓-lemma ∃bool (e , cl-e) , ¬⇓-lemma ∃bool (e , cl-e) )) where open Helper p cl-p hyp -- A variant of the theorem. rice's-theorem′ : (P : Closed-exp → Type) (e∈ : Closed-exp) → P e∈ → (e∉ : Closed-exp) → ¬ P e∉ → (∀ e₁ e₂ → Pointwise-semantically-equivalent e₁ e₂ → P e₁ → P e₂) → ¬ Decidable (as-function-to-Bool₁ P) rice's-theorem′ P e∈ Pe∈ e∉ ¬Pe∉ resp = rice's-theorem (as-function-to-Bool₁ P) e∈ ((λ _ → refl) , ⊥-elim ∘ (_$ Pe∈)) e∉ (⊥-elim ∘ ¬Pe∉ , (λ _ → refl)) (λ e₁ e₂ eq → Σ-map (_∘ resp e₂ e₁ (symmetric e₁ e₂ eq)) (_∘ (_∘ resp e₁ e₂ eq))) ------------------------------------------------------------------------ -- Examples -- The problem of deciding whether an expression implements the -- successor function is undecidable. Equal-to-suc : Closed-exp →Bool Equal-to-suc = as-function-to-Bool₁ λ e → (n : ℕ) → apply (proj₁ e) ⌜ n ⌝ ⇓ ⌜ suc n ⌝ equal-to-suc-not-decidable : ¬ Decidable Equal-to-suc equal-to-suc-not-decidable = rice's-theorem′ _ (s , from-⊎ (closed? s)) (λ n → apply lambda (rep⇓rep n) (rep⇓rep (suc n))) (z , from-⊎ (closed? z)) (λ z⌜n⌝⇓ → case z⌜n⌝⇓ 0 of λ { (apply () _ _) }) (λ e₁ e₂ e₁∼e₂ Pe₁ n → apply (proj₁ e₂) ⌜ n ⌝ ⇓⟨ _⇔_.to (e₁∼e₂ ⌜ n ⌝ ⌜ suc n ⌝) (Pe₁ n) ⟩■ ⌜ suc n ⌝) where z = const c-zero [] s = lambda v-n (const c-suc (var v-n ∷ [])) -- The problem of deciding whether an expression always terminates -- with the same value when applied to an arbitrary argument is -- undecidable. Is-constant : Closed-exp →Bool Is-constant = as-function-to-Bool₁ λ e → ∃ λ v → (n : ℕ) → apply (proj₁ e) ⌜ n ⌝ ⇓ v is-constant-not-decidable : ¬ Decidable Is-constant is-constant-not-decidable = rice's-theorem′ _ (c , from-⊎ (closed? c)) ((⌜ 0 ⌝ ⦂ Exp) , λ n → apply c ⌜ n ⌝ ⇓⟨ apply lambda (rep⇓rep n) (const []) ⟩■ ⌜ 0 ⌝) (f , from-⊎ (closed? f)) not-constant (λ e₁ e₂ e₁∼e₂ → Σ-map id λ {v} ⇓v n → let v-closed : Closed v v-closed = closed⇓closed (⇓v n) $ Closed′-closed-under-apply (proj₂ e₁) (rep-closed n) in apply (proj₁ e₂) ⌜ n ⌝ ⇓⟨ _⇔_.to (e₁∼e₂ ⌜ n ⌝ (v , v-closed)) (⇓v n) ⟩■ v) where c = lambda v-underscore ⌜ 0 ⌝ f = lambda v-n (var v-n) not-constant : ¬ ∃ λ v → (n : ℕ) → apply f ⌜ n ⌝ ⇓ v not-constant (v , constant) = impossible where v≡0 : v ≡ ⌜ 0 ⌝ v≡0 with constant 0 ... | apply lambda (const []) (const []) = refl v≡1 : v ≡ ⌜ 1 ⌝ v≡1 with constant 1 ... | apply lambda (const (const [] ∷ [])) (const (const [] ∷ [])) = refl 0≡1 = ⌜ 0 ⌝ ≡⟨ sym v≡0 ⟩ v ≡⟨ v≡1 ⟩∎ ⌜ 1 ⌝ ∎ impossible : ⊥ impossible with 0≡1 ... | ()
36.908397
138
0.422544