Search is not available for this dataset
text
string
meta
dict
module TLP01 where open import Data.Bool open import Data.Nat open import Data.String open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong; cong₂; trans) _==ℕ_ : ℕ → ℕ → Bool zero ==ℕ zero = true suc n ==ℕ suc m = n ==ℕ m _ ==ℕ _ = false _<ℕ_ : ℕ → ℕ → Bool _ <ℕ zero = false zero <ℕ suc _ = true suc n <ℕ suc m = n <ℕ m -- ----- Star型の定義と同値性 ----- data Star : Set where NIL : Star TRU : Star N : ℕ → Star S : String → Star C : Star → Star → Star eqStar : Star → Star → Bool eqStar NIL NIL = true eqStar NIL _ = false eqStar TRU TRU = true eqStar TRU _ = false eqStar (N x) (N y) = x ==ℕ y eqStar (N _) _ = false eqStar (S x) (S y) = x == y eqStar (S _) _ = false eqStar (C x x₁) (C y y₁) = eqStar x y ∧ eqStar x₁ y₁ eqStar (C _ _) _ = false -- ----- 組込関数の定義 ----- CONS : Star → Star → Star CONS = C CAR : Star → Star CAR (C x _) = x CAR _ = NIL CDR : Star → Star CDR (C _ x₁) = x₁ CDR _ = NIL ATOM : Star → Star ATOM (C _ _) = NIL ATOM _ = TRU IF : Star → Star → Star → Star IF TRU a _ = a IF q a e = if eqStar q NIL then e else a EQUAL : Star → Star → Star EQUAL x y = if eqStar x y then TRU else NIL s-size : Star → ℕ s-size (C a b) = s-size a + s-size b + 1 s-size _ = 0 SIZE : Star → Star SIZE x = N (s-size x) s2n : Star → ℕ s2n (N x) = x s2n _ = 0 LT : Star → Star → Star LT x y = if s2n x <ℕ s2n y then TRU else NIL -- ----- Starから≡に ----- postulate ts : Star → Set ~ : Star → Star equal-eq : {x y : Star} → ts (EQUAL x y) → x ≡ y ifAP : {q x y : Star} → ts (IF q (EQUAL x y) TRU) → (ts q → x ≡ y) ifEP : {q x y : Star} → ts (IF q TRU (EQUAL x y)) → (ts (~ q) → x ≡ y) -- ----- 公理 ----- equal-same : (x : Star) → ts (EQUAL x x) equal-swap : (x y : Star) → ts (EQUAL (EQUAL x y) (EQUAL y x)) equal-if : (x y : Star) → ts (IF (EQUAL x y) (EQUAL x y) TRU) atom/cons : (x y : Star) → ts (EQUAL (ATOM (CONS x y)) NIL) car/cons : (x y : Star) → ts (EQUAL (CAR (CONS x y)) x) cdr/cons : (x y : Star) → ts (EQUAL (CDR (CONS x y)) y) cons/car+cdr : (x : Star) → ts (IF (ATOM x) TRU (EQUAL (CONS (CAR x) (CDR x)) x)) if-true : (x y : Star) → ts (EQUAL (IF TRU x y) x) if-false : (x y : Star) → ts (EQUAL (IF NIL x y) y) if-same : (x y : Star) → ts (EQUAL (IF x y y) y) if-nest-A : (x y z : Star) → ts (IF x (EQUAL (IF x y z) y) TRU) if-nest-E : (x y z : Star) → ts (IF x TRU (EQUAL (IF x y z) z)) size/car : (x : Star) → ts (IF (ATOM x) TRU (EQUAL (LT (SIZE (CAR x)) (SIZE x)) TRU)) size/cdr : (x : Star) → ts (IF (ATOM x) TRU (EQUAL (LT (SIZE (CDR x)) (SIZE x)) TRU)) -- ----- 練習 ----- postulate -- a b : Star foo : ts (EQUAL TRU NIL) hoge6 : (a b : Star) → (IF (EQUAL TRU NIL) TRU TRU) ≡ (IF (EQUAL TRU NIL) NIL TRU) hoge6 a b = ifAP (equal-if TRU NIL) foo hoge2 : (ATOM (CONS TRU TRU)) ≡ NIL hoge2 = equal-eq (atom/cons TRU TRU) -- hoge2' : (ATOM (CONS TRU TRU)) ≡ NIL -- hoge2' rewrite (equal-eq (atom-cons TRU TRU)) = {!!} hoge3 : (C TRU NIL) ≡ (C TRU NIL) hoge3 = equal-eq (equal-same (C TRU NIL)) hoge4 : (EQUAL TRU TRU) ≡ TRU hoge4 = begin (if eqStar TRU TRU then TRU else NIL) ≡⟨ refl ⟩ TRU ∎ where open PropEq.≡-Reasoning hoge5 : (EQUAL NIL NIL) ≡ TRU hoge5 = refl postulate j : (x : Star) → ts (~ (ATOM x)) hoge7 : (x : ℕ) → (IF (ATOM (N x)) TRU (LT (SIZE (CDR (N x))) (SIZE (N x)))) ≡ (IF (ATOM (N x)) TRU TRU) hoge7 x = ifEP (size/cdr (N x)) (j (N x)) -- ----- {- -- ----- 停止性で引っかかる ----- memb?' : Star → Star memb?' xs = (IF (ATOM xs) NIL (IF (EQUAL (CAR xs) (S "?")) TRU (memb?' (CDR xs)))) -} -- ----- memb?の停止性 ----- -- ----- SIZEを使う時はℕを引数にとる postulate premise : (xs : Star) → ts (~ (ATOM xs)) measure-memb? : (x : ℕ) → (IF (ATOM (N x)) TRU (IF (EQUAL (CAR (N x)) (S "?")) TRU (LT (SIZE (CDR (N x))) (SIZE (N x))))) ≡ TRU measure-memb? x = begin (IF (ATOM (N x)) TRU (IF (EQUAL (CAR (N x)) (S "?")) TRU (LT (SIZE (CDR (N x))) (SIZE (N x))))) ≡⟨ ifEP (size/cdr (N x)) (premise (N x)) ⟩ (IF (ATOM (N x)) TRU (IF (EQUAL (CAR (N x)) (S "?")) TRU TRU)) ≡⟨ equal-eq (if-same (EQUAL (CAR (N x)) (S "?")) TRU) ⟩ (IF (ATOM (N x)) TRU TRU) ≡⟨ equal-eq (if-same (ATOM (N x)) TRU) ⟩ TRU ∎ where open PropEq.≡-Reasoning -- ----- memb?の定義 ----- postulate memb? : Star → Star def-memb? : (xs : Star) → memb? xs ≡ (IF (ATOM xs) NIL (IF (EQUAL (CAR xs) (S "?")) TRU (memb? (CDR xs)))) -- ----- rembの定義 ----- postulate remb : Star → Star def-remb : (xs : Star) → remb xs ≡ (IF (ATOM xs) (S "'()") (IF (EQUAL (CAR xs) (S "?")) (remb (CDR xs)) (CONS (CAR xs) (remb (CDR xs))))) -- ----- 帰納的な証明(未完) ----- -- ----- ATOMを使う時はC x yを引数にとる postulate premise2 : (xs : Star) → ts (ATOM xs) atomt : (ATOM (S "'()")) ≡ TRU atomt = refl memb?/remb : (x y : Star) → (IF (ATOM (C x y)) (EQUAL (memb? (remb (C x y))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡ (IF (ATOM (C x y)) (EQUAL (IF TRU NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) memb?/remb x y = begin (IF (ATOM (C x y)) (EQUAL (memb? (remb (C x y))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ cong (λ t → ((IF (ATOM (C x y)) (EQUAL (memb? t) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)))) (def-remb (C x y)) ⟩ (IF (ATOM (C x y)) (EQUAL (memb? (IF (ATOM (C x y)) (S "'()") (IF (EQUAL (CAR (C x y)) (S "?")) (remb (CDR (C x y))) (CONS (CAR (C x y)) (remb (CDR (C x y))))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ ifAP (if-nest-A (ATOM (C x y)) (S "'()") ((IF (EQUAL (CAR (C x y)) (S "?")) (remb (CDR (C x y))) (CONS (CAR (C x y)) (remb (CDR (C x y))))))) (premise2 (C x y)) ⟩ (IF (ATOM (C x y)) (EQUAL (memb? (S "'()")) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ cong ((λ t → (IF (ATOM (C x y)) (EQUAL t NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)))) (def-memb? ((S "'()"))) ⟩ (IF (ATOM (C x y)) (EQUAL (IF (ATOM (S "'()")) NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ cong ((λ t → (IF (ATOM (C x y)) (EQUAL (IF t NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)))) atomt ⟩ (IF (ATOM (C x y)) (EQUAL (IF TRU NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ∎ where open PropEq.≡-Reasoning
{ "alphanum_fraction": 0.4171677868, "avg_line_length": 29.1443298969, "ext": "agda", "hexsha": "19813df46404caefbf31fb4bb6bc3684e95492d1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "righ1113/Agda", "max_forks_repo_path": "TLP01.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "righ1113/Agda", "max_issues_repo_path": "TLP01.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "righ1113/Agda", "max_stars_repo_path": "TLP01.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3168, "size": 8481 }
-- Andreas, 2012-05-09 module DontPrune where open import Common.Equality open import Common.Product data Bool : Set where true false : Bool test : (A : Set) → let IF : Bool → A → A → A IF = _ in (a b : A) → (IF true a b ≡ a) × (IF false a b ≡ b) test A a b = refl , refl -- Expected result: unsolved metas -- -- (unless someone implemented unification that produces definitions by case). -- -- The test case should prevent overzealous pruning: -- If the first equation pruned away the b, then the second -- would have an unbound rhs.
{ "alphanum_fraction": 0.6666666667, "avg_line_length": 23.25, "ext": "agda", "hexsha": "1c3b99907c9998a7665c70ecac7691fcb03fb23b", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/DontPrune.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/DontPrune.agda", "max_line_length": 78, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/DontPrune.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 163, "size": 558 }
------------------------------------------------------------------------------ -- Testing various arguments in the ATP pragmas ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module VariousArguments where postulate D : Set _≡_ : D → D → Set a b c d : D a≡b : a ≡ b b≡c : b ≡ c c≡d : c ≡ d {-# ATP axioms a≡b b≡c c≡d #-} postulate a≡d : a ≡ d {-# ATP prove a≡d #-}
{ "alphanum_fraction": 0.3636363636, "avg_line_length": 26.3043478261, "ext": "agda", "hexsha": "98f549c687bcb8a8deb8808fc8db228055bf5618", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "test/Succeed/fol-theorems/VariousArguments.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "test/Succeed/fol-theorems/VariousArguments.agda", "max_line_length": 78, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "test/Succeed/fol-theorems/VariousArguments.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 154, "size": 605 }
{-# OPTIONS --universe-polymorphism #-} module Categories.Colimit where open import Level open import Categories.Category open import Categories.Functor open import Categories.NaturalTransformation open import Categories.Functor.Constant open import Categories.Cocones open import Categories.Cocone open import Categories.Object.Initial -- Isomorphic to an terminal object, but worth keeping distinct in case we change its definition record Colimit {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where field initial : Initial (Cocones F) module I = Initial initial module Ic = Cocone I.⊥ private module C = Category C ∃F : C.Obj ∃F = Ic.N ι : NaturalTransformation F (Constant ∃F) ι = record { η = Ic.ψ; commute = λ f → C.Equiv.trans (C.Equiv.sym (Ic.commute f)) (C.Equiv.sym C.identityˡ) } <_> : ∀ {Q} → NaturalTransformation F (Constant Q) → ∃F C.⇒ Q <_> {Q} η = CoconeMorphism.f (I.! {record { N = Q ; ψ = η.η ; commute = λ f → C.Equiv.trans (C.Equiv.sym C.identityˡ) (C.Equiv.sym (η.commute f)) }}) where module η = NaturalTransformation η record Cocomplete (o ℓ e : Level) {o′ ℓ′ e′} (C : Category o′ ℓ′ e′) : Set (suc o ⊔ suc ℓ ⊔ suc e ⊔ o′ ⊔ ℓ′ ⊔ e′) where field colimit : ∀ {J : Category o ℓ e} (F : Functor J C) → Colimit F
{ "alphanum_fraction": 0.639108555, "avg_line_length": 34.775, "ext": "agda", "hexsha": "d6163f38fcaff15bb06f70cb1534c0dc341b2ab7", "lang": "Agda", "max_forks_count": 23, "max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z", "max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "p-pavel/categories", "max_forks_repo_path": "Categories/Colimit.agda", "max_issues_count": 19, "max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z", "max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "p-pavel/categories", "max_issues_repo_path": "Categories/Colimit.agda", "max_line_length": 135, "max_stars_count": 98, "max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "copumpkin/categories", "max_stars_repo_path": "Categories/Colimit.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z", "num_tokens": 481, "size": 1391 }
module Esterel.Variable.Sequential where open import Data.Nat using (ℕ) renaming (_≟_ to _≟ℕ_) open import Function using (_∘_) open import Relation.Nullary using (Dec ; yes ; no ; ¬_) open import Relation.Binary using (Decidable) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; cong ; trans ; sym) data SeqVar : Set where _ᵥ : ℕ → SeqVar unwrap : SeqVar → ℕ unwrap (n ᵥ) = n unwrap-inverse : ∀ {s} → (unwrap s) ᵥ ≡ s unwrap-inverse {_ ᵥ} = refl unwrap-injective : ∀ {s t} → unwrap s ≡ unwrap t → s ≡ t unwrap-injective s'≡t' = trans (sym unwrap-inverse) (trans (cong _ᵥ s'≡t') unwrap-inverse) -- for backward compatibility unwrap-neq : ∀{k1 : SeqVar} → ∀{k2 : SeqVar} → ¬ k1 ≡ k2 → ¬ (unwrap k1) ≡ (unwrap k2) unwrap-neq = (_∘ unwrap-injective) wrap : ℕ → SeqVar wrap = _ᵥ bijective : ∀{x} → unwrap (wrap x) ≡ x bijective = refl _≟_ : Decidable {A = SeqVar} _≡_ (s ᵥ) ≟ (t ᵥ) with s ≟ℕ t ... | yes p = yes (cong _ᵥ p) ... | no ¬p = no (¬p ∘ cong unwrap)
{ "alphanum_fraction": 0.6383616384, "avg_line_length": 23.2790697674, "ext": "agda", "hexsha": "c311a36536ad96e75db175e9eb60212594ab3656", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "florence/esterel-calculus", "max_forks_repo_path": "agda/Esterel/Variable/Sequential.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "florence/esterel-calculus", "max_issues_repo_path": "agda/Esterel/Variable/Sequential.agda", "max_line_length": 90, "max_stars_count": 3, "max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "florence/esterel-calculus", "max_stars_repo_path": "agda/Esterel/Variable/Sequential.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z", "num_tokens": 377, "size": 1001 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Functions ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Function where open import Function.Core public open import Function.Base public open import Function.Definitions public open import Function.Structures public open import Function.Bundles public
{ "alphanum_fraction": 0.5208333333, "avg_line_length": 27, "ext": "agda", "hexsha": "706099d2757fe4841014867a0ff9ebf59acf3a50", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Function.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Function.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Function.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 61, "size": 432 }
{-# OPTIONS --without-K #-} open import Base open import Homotopy.Pushout open import Homotopy.VanKampen.Guide module Homotopy.VanKampen.Code.LemmaPackA {i} (d : pushout-diag i) (l : legend i (pushout-diag.C d)) where open import Homotopy.Truncation open import Homotopy.PathTruncation private module PackA1 (d : pushout-diag i) (l : legend i (pushout-diag.C d)) (n : legend.name l) where open pushout-diag d open legend l -- Code from A. open import Homotopy.VanKampen.SplitCode d l (f $ loc n) -- Code from B. F for `flipped'. import Homotopy.VanKampen.SplitCode (pushout-diag-flip d) l (g $ loc n) as F private ap⇒bp-split : (∀ {a₂} → code-a a₂ → F.code-b a₂) × (∀ {b₂} → code-b b₂ → F.code-a b₂) ap⇒bp-split = code-rec-nondep F.code-b ⦃ λ _ → F.code-b-is-set _ ⦄ F.code-a ⦃ λ _ → F.code-a-is-set _ ⦄ (λ p → F.⟧a refl₀ F.a⟦ n ⟧b p) (λ n₁ pco p → pco F.a⟦ n₁ ⟧b p) (λ n₁ pco p → pco F.b⟦ n₁ ⟧a p) (λ n₁ pco → F.code-b-refl-refl n₁ pco) (λ n₁ pco → F.code-a-refl-refl n₁ pco) (λ n₁ pco n₂ r → F.code-ba-swap n₁ pco n₂ r) aa⇒ba : ∀ {a₂} → code-a a₂ → F.code-b a₂ aa⇒ba = π₁ ap⇒bp-split ab⇒bb : ∀ {b₂} → code-b b₂ → F.code-a b₂ ab⇒bb = π₂ ap⇒bp-split private module PackA2 (d : pushout-diag i) (l : legend i (pushout-diag.C d)) (n : legend.name l) where open pushout-diag d open legend l -- Code from A. open import Homotopy.VanKampen.SplitCode d l (f $ loc n) open PackA1 d l n public -- Code from B. F for `flipped'. private module F where open import Homotopy.VanKampen.SplitCode (pushout-diag-flip d) l (g $ loc n) public open PackA1 (pushout-diag-flip d) l n public private aba-glue-code-split : (∀ {a₂} (co : code-a a₂) → F.ab⇒bb (aa⇒ba co) ≡ co) × (∀ {b₂} (co : code-b b₂) → F.aa⇒ba (ab⇒bb co) ≡ co) abstract aba-glue-code-split = code-rec (λ {a} co → F.ab⇒bb (aa⇒ba co) ≡ co) ⦃ λ _ → ≡-is-set $ code-a-is-set _ ⦄ (λ {b} co → F.aa⇒ba (ab⇒bb co) ≡ co) ⦃ λ _ → ≡-is-set $ code-b-is-set _ ⦄ (λ p → ⟧a refl₀ a⟦ n ⟧b refl₀ b⟦ n ⟧a p ≡⟨ code-a-merge n refl₀ p ⟩ ⟧a refl₀ ∘₀ p ≡⟨ ap (λ x → ⟧a x) $ refl₀-left-unit p ⟩∎ ⟧a p ∎) (λ n₁ {co} eq p → ap (λ x → x b⟦ n₁ ⟧a p) eq) (λ n₁ {co} eq p → ap (λ x → x a⟦ n₁ ⟧b p) eq) (λ _ _ → code-has-all-cells₂-a _ _) (λ _ _ → code-has-all-cells₂-b _ _) (λ _ _ _ _ → code-has-all-cells₂-a _ _) aba-glue-code-a : ∀ {a₂} (co : code-a a₂) → F.ab⇒bb (aa⇒ba co) ≡ co aba-glue-code-a = π₁ aba-glue-code-split aba-glue-code-b : ∀ {b₂} (co : code-b b₂) → F.aa⇒ba (ab⇒bb co) ≡ co aba-glue-code-b = π₂ aba-glue-code-split private module PackA3 (d : pushout-diag i) (l : legend i (pushout-diag.C d)) (n : legend.name l) where open pushout-diag d open legend l -- Code from A. open import Homotopy.VanKampen.SplitCode d l (f $ loc n) open PackA2 d l n public -- Code from B. F for `flipped'. private module F where open import Homotopy.VanKampen.SplitCode (pushout-diag-flip d) l (g $ loc n) public open PackA2 (pushout-diag-flip d) l n public flipped-code : P → Set i flipped-code = F.code ◯ pushout-flip private ap⇒bp-glue : ∀ c → transport (λ p → code p → flipped-code p) (glue c) aa⇒ba ≡ ab⇒bb abstract ap⇒bp-glue = loc-fiber-rec l (λ c → transport (λ p → code p → flipped-code p) (glue c) aa⇒ba ≡ ab⇒bb) ⦃ λ _ → Π-is-set (λ _ → F.code-a-is-set _) _ _ ⦄ (λ n → funext λ co → transport (λ p → code p → flipped-code p) (glue $ loc n) aa⇒ba co ≡⟨ trans-→ code flipped-code (glue $ loc n) aa⇒ba co ⟩ transport flipped-code (glue $ loc n) (aa⇒ba $ transport code (! $ glue $ loc n) co) ≡⟨ ap (λ x → transport flipped-code (glue $ loc n) $ aa⇒ba x) $ trans-code-!glue-loc n co ⟩ transport flipped-code (glue $ loc n) (aa⇒ba $ b⇒a n co) ≡⟨ refl ⟩ transport flipped-code (glue $ loc n) (F.a⇒b n $ ab⇒bb co) ≡⟨ ! $ trans-ap F.code pushout-flip (glue $ loc n) $ F.a⇒b n $ ab⇒bb co ⟩ transport F.code (ap pushout-flip $ glue $ loc n) (F.a⇒b n $ ab⇒bb co) ≡⟨ ap (λ x → transport F.code x $ F.a⇒b n $ ab⇒bb co) $ pushout-β-glue-nondep _ right left (! ◯ glue) $ loc n ⟩ transport F.code (! $ glue $ loc n) (F.a⇒b n $ ab⇒bb co) ≡⟨ F.trans-code-!glue-loc n (F.a⇒b n $ ab⇒bb co) ⟩ F.b⇒a n (F.a⇒b n $ ab⇒bb co) ≡⟨ F.code-a-refl-refl n $ ab⇒bb co ⟩∎ ab⇒bb co ∎) ap⇒bp : ∀ {p} → code p → flipped-code p ap⇒bp {p} = pushout-rec (λ x → code x → flipped-code x) (λ _ → aa⇒ba) (λ _ → ab⇒bb) ap⇒bp-glue p open PackA3 d l public
{ "alphanum_fraction": 0.502735333, "avg_line_length": 38.1366906475, "ext": "agda", "hexsha": "e647224e58f34601a85507abe84699a5f116923b", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/Homotopy/VanKampen/Code/LemmaPackA.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/Homotopy/VanKampen/Code/LemmaPackA.agda", "max_line_length": 93, "max_stars_count": 294, "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_path": "old/Homotopy/VanKampen/Code/LemmaPackA.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 2031, "size": 5301 }
module Cats.Functor.Yoneda where open import Data.Product using (_,_) open import Relation.Binary using (Rel ; Setoid ; IsEquivalence) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl) open import Cats.Bifunctor using (transposeBifunctor₂) open import Cats.Category open import Cats.Category.Cat.Facts.Exponential using (Eval) open import Cats.Category.Cat.Facts.Product using (First ; Swap) open import Cats.Category.Fun using (Fun ; Trans ; ≈-intro ; ≈-elim) open import Cats.Category.Fun.Facts using (NatIso→≅) open import Cats.Category.Op using (_ᵒᵖ) open import Cats.Category.Product.Binary using (_×_) open import Cats.Category.Setoids using (Setoids ; ≈-intro ; ≈-elim ; ≈-elim′) open import Cats.Functor using ( Functor ; _∘_ ; IsFull ; IsFaithful ; IsEmbedding ; Embedding→Full ; Embedding→Faithful ) open import Cats.Functor.Op using (Op) open import Cats.Functor.Representable using (Hom[_]) open import Cats.Util.SetoidMorphism.Iso using (IsIso-resp) import Cats.Util.SetoidReasoning as SetoidReasoning import Cats.Category.Constructions.Iso open Functor open Trans open Cats.Category.Setoids._⇒_ open Setoid using (Carrier) -- We force C to be at l/l/l. Can we generalise to lo/la/l≈? module _ {l} {C : Category l l l} where private Sets : Category _ _ _ Sets = Setoids l l Presheaves : Category _ _ _ Presheaves = Fun (C ᵒᵖ) Sets Funs : Category _ _ _ Funs = Fun ((C ᵒᵖ) × Presheaves) Sets module C = Category C module Sets = Category Sets module Pre = Category Presheaves module Funs = Category Funs y : Functor C Presheaves y = transposeBifunctor₂ Hom[ C ] module _ (c : C.Obj) (F : Functor (C ᵒᵖ) (Sets)) where private module ycc≈ = Setoid (fobj (fobj y c) c) module Fc≈ = Setoid (fobj F c) forth : Pre.Hom (fobj y c) F Sets.⇒ fobj F c forth = record { arr = λ f → arr (component f c) C.id ; resp = λ f≈g → ≈-elim′ (≈-elim f≈g) } back-θ-component : Carrier (fobj F c) → (c′ : C.Obj) → C.Hom c′ c Sets.⇒ fobj F c′ back-θ-component a c′ = record { arr = λ h → arr (fmap F h) a ; resp = λ f≈g → ≈-elim′ (fmap-resp F f≈g) } back-θ : Carrier (fobj F c) → fobj y c Pre.⇒ F back-θ a = record { component = back-θ-component a ; natural = λ {c′} {d′} {f} → ≈-intro λ {g} {g′} g≈g′ → let open Setoid (fobj F d′) using (sym) in begin⟨ fobj F d′ ⟩ arr (back-θ-component a d′ Sets.∘ fmap (fobj y c) f) g ≡⟨⟩ arr (fmap F (C.id C.∘ g C.∘ f)) a ≈⟨ ≈-elim′ (fmap-resp F (C.≈.trans C.id-l (C.∘-resp-l g≈g′))) ⟩ arr (fmap F (g′ C.∘ f)) a ≈⟨ sym (≈-elim′ (fmap-∘ F)) ⟩ arr (fmap F f Sets.∘ fmap F g′) a ≡⟨⟩ arr (fmap F f Sets.∘ back-θ-component a c′) g′ ∎ } where open SetoidReasoning back : fobj F c Sets.⇒ Pre.Hom (fobj y c) F back = record { arr = back-θ ; resp = λ f≈g → ≈-intro (≈-intro λ x≈y → ≈-elim (fmap-resp F x≈y) f≈g) } back-forth : back Sets.∘ forth Sets.≈ Sets.id back-forth = ≈-intro λ {θ} {θ′} θ≈θ′ → ≈-intro λ {c′} → ≈-intro λ {f} {g} f≈g → begin⟨ fobj F c′ ⟩ arr (component (arr (back Sets.∘ forth) θ) c′) f ≡⟨⟩ arr (fmap F f Sets.∘ component θ c) C.id ≈⟨ ≈-elim′ (Sets.≈.sym (natural θ)) ⟩ arr (component θ c′ Sets.∘ fmap (fobj y c) f) C.id ≡⟨⟩ arr (component θ c′) (C.id C.∘ C.id C.∘ f) ≈⟨ resp (component θ c′) (C.≈.trans C.id-l C.id-l) ⟩ arr (component θ c′) f ≈⟨ ≈-elim (≈-elim θ≈θ′) f≈g ⟩ arr (component θ′ c′) g ∎ where open SetoidReasoning forth-back : forth Sets.∘ back Sets.≈ Sets.id forth-back = ≈-intro λ x≈y → ≈-elim (fmap-id F) x≈y iso : fobj Hom[ Presheaves ] (fobj y c , F) Sets.≅ fobj F c iso = record { forth = forth ; back = back ; back-forth = back-forth ; forth-back = forth-back } yoneda : (Hom[ Presheaves ] ∘ First (Op y)) Funs.≅ (Eval ∘ Swap) yoneda = NatIso→≅ record { iso = λ { {c , F} → iso c F } ; forth-natural = λ where {c , F} {c′ , F′} {f , θ} → ≈-intro λ {ι} {τ} ι≈τ → let module S = Setoid (fobj F′ c′) in triangle (fobj F′ c′) (arr (component (θ Pre.∘ ι) c′) f) ( begin⟨ fobj F′ c′ ⟩ arr (forth c′ F′ Sets.∘ fmap Hom[ Presheaves ] (fmap (First {D = Presheaves ᵒᵖ} (Op y)) (f , θ))) ι ≡⟨⟩ arr (component (Pre.id Pre.∘ θ Pre.∘ ι) c′) (f C.∘ C.id C.∘ C.id) ≈⟨ ≈-elim (≈-elim (Pre.id-l {f = θ Pre.∘ ι})) (C.≈.trans (C.∘-resp-r C.id-r) C.id-r) ⟩ arr (component (θ Pre.∘ ι) c′) f ∎ ) ( begin⟨ fobj F′ c′ ⟩ arr (fmap F′ f Sets.∘ component θ c Sets.∘ forth c F) τ ≡⟨⟩ arr (fmap F′ f Sets.∘ component (θ Pre.∘ τ) c) C.id ≈⟨ S.sym (≈-elim′ (natural (θ Pre.∘ τ))) ⟩ arr (component (θ Pre.∘ τ) c′ Sets.∘ fmap (fobj y c) f) C.id ≡⟨⟩ arr (component (θ Pre.∘ τ) c′) (C.id C.∘ C.id C.∘ f) ≈⟨ ≈-elim (≈-elim (Pre.∘-resp-r {f = θ} (Pre.≈.sym {i = ι} {τ} ι≈τ))) (C.≈.trans C.id-l C.id-l) ⟩ arr (component (θ Pre.∘ ι) c′) f ∎ ) } where open SetoidReasoning back≈sfmap : ∀ {a b} → back a (fobj y b) Sets.≈ sfmap y back≈sfmap {a} {b} = ≈-intro λ {f} {g} f≈g → ≈-intro (≈-intro λ {x} {y} x≈y → begin C.id C.∘ f C.∘ x ≈⟨ C.id-l ⟩ f C.∘ x ≈⟨ C.∘-resp f≈g x≈y ⟩ g C.∘ y ≈⟨ C.≈.sym C.id-r ⟩ (g C.∘ y) C.∘ C.id ≈⟨ C.assoc ⟩ g C.∘ y C.∘ C.id ∎) where open C.≈-Reasoning y-Embedding : IsEmbedding y y-Embedding {a} {b} = IsIso-resp back≈sfmap record { back = forth a (fobj y b) ; forth-back = back-forth a (fobj y b) ; back-forth = forth-back a (fobj y b) } y-Full : IsFull y y-Full = Embedding→Full y y-Embedding y-Faithful : IsFaithful y y-Faithful = Embedding→Faithful y y-Embedding
{ "alphanum_fraction": 0.510340538, "avg_line_length": 31.5245098039, "ext": "agda", "hexsha": "44d87800046a57921f8c7b9113c6f004ba151b1e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "alessio-b-zak/cats", "max_forks_repo_path": "Cats/Functor/Yoneda.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "alessio-b-zak/cats", "max_issues_repo_path": "Cats/Functor/Yoneda.agda", "max_line_length": 86, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "alessio-b-zak/cats", "max_stars_repo_path": "Cats/Functor/Yoneda.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2485, "size": 6431 }
module Automata.Composition.Union (Σ : Set) where -- Standard libraries imports ---------------------------------------- open import Data.Empty using (⊥ ; ⊥-elim) open import Data.Nat using (ℕ) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) open import Data.Product using (_,_) open import Data.Vec using (Vec ; [] ; _∷_) open import Relation.Nullary using (¬_) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl) ---------------------------------------------------------------------- -- Thesis imports ---------------------------------------------------- open import Automata.Nondeterministic ---------------------------------------------------------------------- _∪_ : (M : NDA Σ) → (N : NDA Σ) → NDA Σ ⟨ Q₁ , S₁ , F₁ , Δ₁ ⟩ ∪ ⟨ Q₂ , S₂ , F₂ , Δ₂ ⟩ = ⟨ Q , S , F , Δ ⟩ where Q : Set _ Q = Q₁ ⊎ Q₂ S : Q → Set _ S (inj₁ q) = S₁ q S (inj₂ q) = S₂ q F : Q → Set F (inj₁ q) = F₁ q F (inj₂ q) = F₂ q Δ : Q → Σ → Q → Set Δ (inj₁ q) c (inj₁ q′) = Δ₁ q c q′ Δ (inj₂ q) c (inj₂ q′) = Δ₂ q c q′ {-# CATCHALL #-} Δ _ _ _ = ⊥ -- No connections between the machines M-Δ*⇒M∪N-Δ* : {M N : NDA Σ} → let Q₁ = NDA.Q M Δ₁* = NDA.Δ* M Δ* = NDA.Δ* (M ∪ N) in (q : Q₁) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₁) → Δ₁* q xs q′ → Δ* (inj₁ q) xs (inj₁ q′) M-Δ*⇒M∪N-Δ* q [] .q refl = refl M-Δ*⇒M∪N-Δ* q (x ∷ xs) q′ (q₀ , Δ₁-q-x-q₀ , Δ₁*-q₀-xs-q′) = inj₁ q₀ , Δ₁-q-x-q₀ , M-Δ*⇒M∪N-Δ* q₀ xs q′ Δ₁*-q₀-xs-q′ N-Δ*⇒M∪N-Δ* : {M N : NDA Σ} → let Q₂ = NDA.Q N Δ₂* = NDA.Δ* N Δ* = NDA.Δ* (M ∪ N) in (q : Q₂) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₂) → Δ₂* q xs q′ → Δ* (inj₂ q) xs (inj₂ q′) N-Δ*⇒M∪N-Δ* q [] .q refl = refl N-Δ*⇒M∪N-Δ* q (x ∷ xs) q′ (q₀ , Δ₂-q-x-q₀ , Δ₂*-q₀-xs-q′) = inj₂ q₀ , Δ₂-q-x-q₀ , N-Δ*⇒M∪N-Δ* q₀ xs q′ Δ₂*-q₀-xs-q′ M∪N-Δ*⇒M-Δ* : {M N : NDA Σ} → let Q₁ = NDA.Q M Δ₁* = NDA.Δ* M Δ* = NDA.Δ* (M ∪ N) in (q : Q₁) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₁) → Δ* (inj₁ q) xs (inj₁ q′) → Δ₁* q xs q′ M∪N-Δ*⇒M-Δ* q [] .q refl = refl M∪N-Δ*⇒M-Δ* q (x ∷ xs) q′ (inj₁ q₀ , Δ-q-x-q₀ , Δ*-q₀-xs-q′) = q₀ , Δ-q-x-q₀ , M∪N-Δ*⇒M-Δ* q₀ xs q′ Δ*-q₀-xs-q′ M∪N-Δ*⇒N-Δ* : {M N : NDA Σ} → let Q₂ = NDA.Q N Δ₂* = NDA.Δ* N Δ* = NDA.Δ* (M ∪ N) in (q : Q₂) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₂) → Δ* (inj₂ q) xs (inj₂ q′) → Δ₂* q xs q′ M∪N-Δ*⇒N-Δ* q [] .q refl = refl M∪N-Δ*⇒N-Δ* q (x ∷ xs) q′ (inj₂ q₀ , Δ-q-x-q₀ , Δ*-q₀-xs-q′) = q₀ , Δ-q-x-q₀ , M∪N-Δ*⇒N-Δ* q₀ xs q′ Δ*-q₀-xs-q′ M∪N-Δ*-disconnectedˡ : {M N : NDA Σ} → let Q₁ = NDA.Q M Q₂ = NDA.Q N Δ* = NDA.Δ* (M ∪ N) in (q : Q₁) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₂) → ¬ (Δ* (inj₁ q) xs (inj₂ q′)) M∪N-Δ*-disconnectedˡ q (x ∷ xs) q′ (inj₁ q₀ , _ , Δ*-q₀-xs-q′) = M∪N-Δ*-disconnectedˡ q₀ xs q′ Δ*-q₀-xs-q′ M∪N-Δ*-disconnectedʳ : {M N : NDA Σ} → let Q₁ = NDA.Q M Q₂ = NDA.Q N Δ* = NDA.Δ* (M ∪ N) in (q : Q₂) → {n : ℕ} → (xs : Vec Σ n) → (q′ : Q₁) → ¬ (Δ* (inj₂ q) xs (inj₁ q′)) M∪N-Δ*-disconnectedʳ q (x ∷ xs) q′ (inj₂ q₀ , _ , Δ*-q₀-xs-q′) = M∪N-Δ*-disconnectedʳ q₀ xs q′ Δ*-q₀-xs-q′ M-Accepts⇒M∪N-Accepts : {M N : NDA Σ} → {n : ℕ} → (xs : Vec Σ n) → NDA.Accepts M xs → NDA.Accepts (M ∪ N) xs M-Accepts⇒M∪N-Accepts [] (q , S-q , .q , F-q , refl) = inj₁ q , S-q , inj₁ q , F-q , refl M-Accepts⇒M∪N-Accepts (x ∷ xs) ( q , S-q -- The beginning state , q′ , F-q′ -- The ending state , q₀ , Δ₁-q-x-q₀ -- The first step , Δ₁*-q₀-xs-q′) = -- The remaining steps -- Translate to the union: (inj₁ q , S-q -- The beginning state , inj₁ q′ , F-q′ -- The ending state , inj₁ q₀ , Δ₁-q-x-q₀ -- The first step , M-Δ*⇒M∪N-Δ* q₀ xs q′ Δ₁*-q₀-xs-q′) -- The remaining steps (applying I.H.) N-Accepts⇒M∪N-Accepts : {M N : NDA Σ} → {n : ℕ} → (xs : Vec Σ n) → NDA.Accepts N xs → NDA.Accepts (M ∪ N) xs N-Accepts⇒M∪N-Accepts [] (q , S-q , .q , F-q , refl) = inj₂ q , S-q , inj₂ q , F-q , refl N-Accepts⇒M∪N-Accepts (x ∷ xs) ( q , S-q , q′ , F-q′ , q₀ , Δ-q-x-q₀ , Δ*-q₀-xs-q′) = ( inj₂ q , S-q , inj₂ q′ , F-q′ , inj₂ q₀ , Δ-q-x-q₀ , N-Δ*⇒M∪N-Δ* q₀ xs q′ Δ*-q₀-xs-q′ ) ---------------------------------------------------------------------- M∪N-Accepts⇒M-Accepts∨N-Accepts : {M N : NDA Σ} → {n : ℕ} → (xs : Vec Σ n) → NDA.Accepts (M ∪ N) xs → NDA.Accepts M xs ⊎ NDA.Accepts N xs -- Base cases. M∪N-Accepts⇒M-Accepts∨N-Accepts [] (inj₁ q , S-q , .(inj₁ q) , F-q , refl) = inj₁ (q , S-q , q , F-q , refl) M∪N-Accepts⇒M-Accepts∨N-Accepts [] (inj₂ q , S-q , .(inj₂ q) , F-q , refl) = inj₂ (q , S-q , q , F-q , refl) -- Induction step 1: both the start and final state are in M. M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs) ( inj₁ q , S-q , inj₁ q′ , F-q′ , inj₁ q₀ , Δ-q-x-q₀ , Δ*-q₀-xs-q′) = inj₁ ( q , S-q , q′ , F-q′ , q₀ , Δ-q-x-q₀ , M∪N-Δ*⇒M-Δ* q₀ xs q′ Δ*-q₀-xs-q′) -- Induction step 2: both the start and final state are in N. M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs) ( inj₂ q , S-q , inj₂ q′ , F-q′ , inj₂ q₀ , Δ-q-x-q₀ , Δ*-q₀-xs-q′) = inj₂ ( q , S-q , q′ , F-q′ , q₀ , Δ-q-x-q₀ , M∪N-Δ*⇒N-Δ* q₀ xs q′ Δ*-q₀-xs-q′) -- Unreachable cases: the proof of “Accepts (M ∪ N) xs” -- asserts M and N are connected. M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs) (inj₁ q , _ , inj₂ q′ , _ , inj₁ q₀ , _ , Δ*-q₀-xs-q′) = ⊥-elim (M∪N-Δ*-disconnectedˡ q₀ xs q′ Δ*-q₀-xs-q′) M∪N-Accepts⇒M-Accepts∨N-Accepts (x ∷ xs) (inj₂ q , _ , inj₁ q′ , _ , inj₂ q₀ , _ , Δ*-q₀-xs-q′) = ⊥-elim (M∪N-Δ*-disconnectedʳ q₀ xs q′ Δ*-q₀-xs-q′) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.4017508207, "avg_line_length": 34.5783783784, "ext": "agda", "hexsha": "30d715821f429608ac859b8acb6d3f5c50f127b0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "armkeh/agda-computability", "max_forks_repo_path": "src/Automata/Composition/Union.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "armkeh/agda-computability", "max_issues_repo_path": "src/Automata/Composition/Union.agda", "max_line_length": 81, "max_stars_count": null, "max_stars_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "armkeh/agda-computability", "max_stars_repo_path": "src/Automata/Composition/Union.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2905, "size": 6397 }
{- This file contains the classic isomorphism theorems for groups (so far only the first theorem) -} {-# OPTIONS --safe #-} module Cubical.Algebra.Group.IsomorphismTheorems where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Structure open import Cubical.Foundations.Powerset open import Cubical.Foundations.Function open import Cubical.Data.Sigma open import Cubical.HITs.SetQuotients renaming (_/_ to _/s_ ; rec to recS ; elim to elimS) open import Cubical.HITs.PropositionalTruncation open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Subgroup open import Cubical.Algebra.Group.QuotientGroup open import Cubical.Algebra.Group.GroupPath private variable ℓ : Level -- The first isomorphism theorem: im ϕ ≃ G / ker ϕ module _ {G H : Group ℓ} (ϕ : GroupHom G H) where open isSubgroup open Iso open GroupTheory kerNormalSubgroup : NormalSubgroup G kerNormalSubgroup = kerSubgroup ϕ , isNormalKer ϕ private imϕ : Group ℓ imϕ = imGroup ϕ -- for completeness: imNormalSubgroup : ((x y : ⟨ H ⟩) → GroupStr._·_ (snd H) x y ≡ GroupStr._·_ (snd H) y x) → NormalSubgroup H imNormalSubgroup comm = imSubgroup ϕ , isNormalIm ϕ comm private module G = GroupStr (snd G) module H = GroupStr (snd H) module imG = GroupStr (snd imϕ) module kerG = GroupStr (snd (G / kerNormalSubgroup)) module ϕ = IsGroupHom (ϕ .snd) f1 : ⟨ imϕ ⟩ → ⟨ G / kerNormalSubgroup ⟩ f1 (x , Hx) = rec→Set ( squash/) (λ { (y , hy) → [ y ]}) (λ { (y , hy) (z , hz) → eq/ y z (rem y z hy hz) }) Hx where rem : (y z : ⟨ G ⟩) → ϕ .fst y ≡ x → ϕ .fst z ≡ x → ϕ .fst (y G.· G.inv z) ≡ H.1g rem y z hy hz = ϕ .fst (y G.· G.inv z) ≡⟨ ϕ.pres· _ _ ⟩ ϕ .fst y H.· ϕ .fst (G.inv z) ≡⟨ cong (ϕ .fst y H.·_) (ϕ.presinv _) ⟩ ϕ .fst y H.· H.inv (ϕ .fst z) ≡⟨ (λ i → hy i H.· H.inv (hz i)) ⟩ x H.· H.inv x ≡⟨ H.·InvR x ⟩ H.1g ∎ f2 : ⟨ G / kerNormalSubgroup ⟩ → ⟨ imϕ ⟩ f2 = recS imG.is-set (λ y → ϕ .fst y , ∣ y , refl ∣₁) (λ x y r → Σ≡Prop (λ _ → squash₁) (rem x y r)) where rem : (x y : ⟨ G ⟩) → ϕ .fst (x G.· G.inv y) ≡ H.1g → ϕ .fst x ≡ ϕ .fst y rem x y r = ϕ .fst x ≡⟨ sym (H.·IdR _) ⟩ ϕ .fst x H.· H.1g ≡⟨ cong (ϕ .fst x H.·_) (sym (H.·InvL _)) ⟩ ϕ .fst x H.· H.inv (ϕ .fst y) H.· ϕ .fst y ≡⟨ (λ i → ϕ .fst x H.· ϕ.presinv y (~ i) H.· ϕ .fst y) ⟩ ϕ .fst x H.· ϕ .fst (G.inv y) H.· ϕ .fst y ≡⟨ H.·Assoc _ _ _ ⟩ (ϕ .fst x H.· ϕ .fst (G.inv y)) H.· ϕ .fst y ≡⟨ cong (H._· _) (sym (ϕ.pres· _ _)) ⟩ ϕ .fst (x G.· G.inv y) H.· ϕ .fst y ≡⟨ cong (H._· ϕ .fst y) r ⟩ H.1g H.· ϕ .fst y ≡⟨ H.·IdL _ ⟩ ϕ .fst y ∎ f12 : (x : ⟨ G / kerNormalSubgroup ⟩) → f1 (f2 x) ≡ x f12 = elimProp (λ _ → squash/ _ _) (λ _ → refl) f21 : (x : ⟨ imϕ ⟩) → f2 (f1 x) ≡ x f21 (x , hx) = elim {P = λ hx → f2 (f1 (x , hx)) ≡ (x , hx)} (λ _ → imG.is-set _ _) (λ {(x , hx) → Σ≡Prop (λ _ → squash₁) hx}) hx f1-isHom : (x y : ⟨ imϕ ⟩) → f1 (x imG.· y) ≡ f1 x kerG.· f1 y f1-isHom (x , hx) (y , hy) = elim2 {P = λ hx hy → f1 ((x , hx) imG.· (y , hy)) ≡ f1 (x , hx) kerG.· f1 (y , hy)} (λ _ _ → kerG.is-set _ _) (λ _ _ → refl) hx hy -- The first isomorphism theorem for groups isoThm1 : GroupIso imϕ (G / kerNormalSubgroup) fun (fst isoThm1) = f1 inv (fst isoThm1) = f2 rightInv (fst isoThm1) = f12 leftInv (fst isoThm1) = f21 snd isoThm1 = makeIsGroupHom f1-isHom -- The SIP lets us turn the isomorphism theorem into a path pathThm1 : imϕ ≡ G / kerNormalSubgroup pathThm1 = uaGroup (GroupIso→GroupEquiv isoThm1) surjImIso : isSurjective ϕ → GroupIso imϕ H surjImIso surj = BijectionIso→GroupIso (bijIso indHom (uncurry (λ h → elim (λ _ → isPropΠ (λ _ → imG.is-set _ _)) (uncurry λ g y → λ inker → Σ≡Prop (λ _ → squash₁) inker))) λ b → map (λ x → (b , ∣ x ∣₁) , refl) (surj b)) where indHom : GroupHom imϕ H fst indHom = fst snd indHom = makeIsGroupHom λ _ _ → refl
{ "alphanum_fraction": 0.5434173669, "avg_line_length": 35.976744186, "ext": "agda", "hexsha": "00504cd4c50c2c2db05ac539275372114eefcf7c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Algebra/Group/IsomorphismTheorems.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Algebra/Group/IsomorphismTheorems.agda", "max_line_length": 108, "max_stars_count": null, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Algebra/Group/IsomorphismTheorems.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1793, "size": 4641 }
{-# OPTIONS --universe-polymorphism #-} module Categories.Bicategory where open import Level -- open import Data.Product using (curry; _,_) -- open import Function using () renaming (_∘_ to _·_) open import Categories.Support.PropositionalEquality open import Categories.Category open import Categories.Categories open import Categories.Object.Terminal open import Categories.Terminal open import Categories.Functor using (Functor) renaming (_∘_ to _∘F_; _≡_ to _≡F_; id to idF) open import Categories.Functor.Constant using (Constant) open import Categories.Bifunctor using (Bifunctor; reduce-×) open import Categories.Product using (assocʳ; πˡ; πʳ) open import Categories.NaturalIsomorphism open import Categories.Bicategory.Helpers using (module BicategoryHelperFunctors) record Bicategory (o ℓ t e : Level) : Set (suc (o ⊔ ℓ ⊔ t ⊔ e)) where open Terminal (One {ℓ} {t} {e}) field Obj : Set o _⇒_ : (A B : Obj) → Category ℓ t e id : {A : Obj} → Functor ⊤ (A ⇒ A) —∘— : {A B C : Obj} → Bifunctor (B ⇒ C) (A ⇒ B) (A ⇒ C) _∘_ : {A B C : Obj} {L R : Category ℓ t e} → Functor L (B ⇒ C) → Functor R (A ⇒ B) → Bifunctor L R (A ⇒ C) _∘_ {A} {B} {C} F G = reduce-× {D₁ = B ⇒ C} {D₂ = A ⇒ B} —∘— F G field λᵤ : {A B : Obj} → NaturalIsomorphism (id ∘ idF {C = A ⇒ B}) (πʳ {C = ⊤} {A ⇒ B}) ρᵤ : {A B : Obj} → NaturalIsomorphism (idF {C = A ⇒ B} ∘ id) (πˡ {C = A ⇒ B} {⊤}) α : {A B C D : Obj} → NaturalIsomorphism (idF ∘ —∘—) (((—∘— ∘ idF) ∘F assocʳ (C ⇒ D) (B ⇒ C) (A ⇒ B))) private module BHF = BicategoryHelperFunctors(Obj)(_⇒_)(—∘—)(id) private module EQ = BHF.Coherence(λᵤ)(ρᵤ)(α) private module _⇒_ (A B : Obj) = Category (A ⇒ B) open _⇒_ public using () renaming (Obj to _⇒₁_) field .triangle : {A B C : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) → EQ.Triangle f g .pentagon : {A B C D E : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) (h : C ⇒₁ D) (i : D ⇒₁ E) → EQ.Pentagon f g h i -- do note that most of the "convenience" definitions in the Helpers module should really -- be here (but usable in both places). Clean that up later.
{ "alphanum_fraction": 0.6212847555, "avg_line_length": 41.72, "ext": "agda", "hexsha": "5e308edefbf35f5bdbba869cef999860b2576509", "lang": "Agda", "max_forks_count": 23, "max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z", "max_forks_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "copumpkin/categories", "max_forks_repo_path": "Categories/Bicategory.agda", "max_issues_count": 19, "max_issues_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z", "max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "copumpkin/categories", "max_issues_repo_path": "Categories/Bicategory.agda", "max_line_length": 108, "max_stars_count": 98, "max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "copumpkin/categories", "max_stars_repo_path": "Categories/Bicategory.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z", "num_tokens": 787, "size": 2086 }
{-# OPTIONS --safe #-} module Definition.Typed.Consequences.PiNorm where open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.Typed.Properties open import Definition.Typed.Weakening open import Definition.Typed.EqRelInstance open import Definition.LogicalRelation open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Fundamental.Reducibility open import Definition.Typed.Consequences.Inversion open import Definition.Typed.Consequences.Injectivity open import Definition.Typed.Consequences.Syntactic open import Definition.Conversion.Stability open import Tools.Product open import Tools.Empty import Tools.PropositionalEquality as PE -- reduction including in the codomain of Pis -- useful to get unicity of relevance -- there are 2 kinds of fat arrows!!! -- the constructor for transitivity closure is closed on the left ⇨ -- the ones in types aren't ⇒ data ΠNorm : Term → Set where Uₙ : ∀ {r l} → ΠNorm (Univ r l) Πₙ : ∀ {F rF lF G lG lΠ} → ΠNorm G → ΠNorm (Π F ^ rF ° lF ▹ G ° lG ° lΠ) ∃ₙ : ∀ {F G} → ΠNorm F → ΠNorm (∃ F ▹ G) ℕₙ : ΠNorm ℕ Emptyₙ : ∀ {lEmpty} → ΠNorm (Empty lEmpty) ne : ∀ {n} → Neutral n → ΠNorm n ΠNorm-Π : ∀ {F rF lF G lG lΠ} → ΠNorm (Π F ^ rF ° lF ▹ G ° lG ° lΠ) → ΠNorm G ΠNorm-Π (Πₙ x) = x ΠNorm-Π (ne ()) data _⊢_⇒Π_∷_^_ (Γ : Con Term) : Term → Term → Term → TypeLevel → Set where regular : ∀ {t u A l} → Γ ⊢ t ⇒ u ∷ A ^ l → Γ ⊢ t ⇒Π u ∷ A ^ l deepΠ : ∀ {F rF lF G G′ lG rG lΠ} → Γ ∙ F ^ [ rF , ι lF ] ⊢ G ⇒Π G′ ∷ Univ rG lG ^ next lG → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ⇒Π Π F ^ rF ° lF ▹ G′ ° lG ° lΠ ∷ Univ rG lΠ ^ next lΠ deep∃ : ∀ {F G F′ l∃} → Γ ⊢ F ⇒Π F′ ∷ Univ % l∃ ^ next l∃ → Γ ⊢ ∃ F ▹ G ⇒Π ∃ F′ ▹ G ∷ Univ % l∃ ^ next l∃ data _⊢_⇒Π_^_ (Γ : Con Term) : Term → Term → TypeInfo → Set where univ : ∀ {A B r l} → Γ ⊢ A ⇒Π B ∷ (Univ r l) ^ next l → Γ ⊢ A ⇒Π B ^ [ r , ι l ] data _⊢_⇒*Π_∷_^_ (Γ : Con Term) : Term → Term → Term → TypeLevel → Set where id : ∀ {t T l} → Γ ⊢ t ⇒*Π t ∷ T ^ l _⇨_ : ∀ {t t' u T l} → Γ ⊢ t ⇒Π t' ∷ T ^ l → Γ ⊢ t' ⇒*Π u ∷ T ^ l → Γ ⊢ t ⇒*Π u ∷ T ^ l data _⊢_⇒*Π_^_ (Γ : Con Term) : Term → Term → TypeInfo → Set where id : ∀ {A r} → Γ ⊢ A ⇒*Π A ^ r _⇨_ : ∀ {t t' u r} → Γ ⊢ t ⇒Π t' ^ r → Γ ⊢ t' ⇒*Π u ^ r → Γ ⊢ t ⇒*Π u ^ r _⇨*_ : ∀ {Γ A B C r} → Γ ⊢ A ⇒*Π B ^ r → Γ ⊢ B ⇒*Π C ^ r → Γ ⊢ A ⇒*Π C ^ r id ⇨* y = y (x ⇨ x₁) ⇨* y = x ⇨ (x₁ ⇨* y) regular* : ∀ {Γ t u r} → Γ ⊢ t ⇒* u ^ r → Γ ⊢ t ⇒*Π u ^ r regular* (id _) = id regular* (univ x ⇨ x₁) = univ (regular x) ⇨ regular* x₁ deep* : ∀ {Γ F rF lF G G′ lG rG lΠ} → Γ ∙ F ^ [ rF , ι lF ] ⊢ G ⇒*Π G′ ^ [ rG , ι lG ] → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ⇒*Π Π F ^ rF ° lF ▹ G′ ° lG ° lΠ ^ [ rG , ι lΠ ] deep* id = id deep* (univ (regular x) ⇨ x₁) = univ (deepΠ (regular x)) ⇨ deep* x₁ deep* (univ (deepΠ x) ⇨ x₁) = univ (deepΠ (deepΠ x)) ⇨ deep* x₁ deep* (univ (deep∃ x) ⇨ x₁) = univ (deepΠ (deep∃ x)) ⇨ deep* x₁ deep∃* : ∀ {Γ F G F′ l∃} → Γ ⊢ F ⇒*Π F′ ^ [ % , ι l∃ ] → Γ ⊢ ∃ F ▹ G ⇒*Π ∃ F′ ▹ G ^ [ % , ι l∃ ] deep∃* id = id deep∃* (univ (regular x) ⇨ x₁) = univ (deep∃ (regular x)) ⇨ deep∃* x₁ deep∃* (univ (deepΠ x) ⇨ x₁) = univ (deep∃ (deepΠ x)) ⇨ deep∃* x₁ deep∃* (univ (deep∃ x) ⇨ x₁) = univ (deep∃ (deep∃ x)) ⇨ deep∃* x₁ deep-correct-term : ∀ {Γ t u T l} → Γ ⊢ t ∷ T ^ [ ! , l ] → Γ ⊢ t ⇒Π u ∷ T ^ l → Γ ⊢ u ∷ T ^ [ ! , l ] × Γ ⊢ t ≡ u ∷ T ^ [ ! , l ] deep-correct-term ⊢t (regular x) = let t≡u = subsetTerm x _ , _ , ⊢u = syntacticEqTerm t≡u in ⊢u , t≡u deep-correct-term ⊢t (deepΠ X) = let _ , l< , l<' , ⊢F , ⊢G , e , _ = inversion-Π ⊢t erG , _ = Uinjectivity e ⊢G' , G≡G' = deep-correct-term (PE.subst (λ rr → _ ⊢ _ ∷ Univ rr _ ^ _ ) (PE.sym erG) ⊢G) X in Πⱼ l< ▹ l<' ▹ ⊢F ▹ ⊢G' , Π-cong l< l<' (univ ⊢F) (refl ⊢F) G≡G' deep-correct-term ⊢t (deep∃ X) = let l , ⊢F , ⊢G , e , _ = inversion-∃ ⊢t _ , el = Uinjectivity e ⊢Fl = PE.subst (λ ll → _ ⊢ _ ∷ SProp ll ^ [ ! , next ll ] ) (PE.sym el) ⊢F ⊢F' , F≡F' = deep-correct-term ⊢Fl X ⊢Gl = PE.subst (λ ll → _ ∙ _ ^ [ % , ι ll ] ⊢ _ ∷ SProp ll ^ [ ! , next ll ] ) (PE.sym el) ⊢G in ∃ⱼ ⊢F' ▹ stabilityTerm (reflConEq (wfTerm ⊢F) ∙ (univ F≡F')) ⊢Gl , ∃-cong (univ ⊢Fl) F≡F' (refl ⊢Gl) deep-correct : ∀ {Γ A B r} → Γ ⊢ A ^ r → Γ ⊢ A ⇒Π B ^ r → Γ ⊢ B ^ r × Γ ⊢ A ≡ B ^ r deep-correct ⊢A (univ x) = let ⊢B , A≡B = deep-correct-term (un-univ ⊢A) x in univ ⊢B , univ A≡B deep*-correct-term : ∀ {Γ t u T l} → Γ ⊢ t ∷ T ^ [ ! , l ] → Γ ⊢ t ⇒*Π u ∷ T ^ l → Γ ⊢ t ≡ u ∷ T ^ [ ! , l ] deep*-correct-term ⊢t id = refl ⊢t deep*-correct-term ⊢t (x ⇨ X) = let ⊢u , t≡u = deep-correct-term ⊢t x in trans t≡u (deep*-correct-term ⊢u X) deep*-correct : ∀ {Γ A B r} → Γ ⊢ A ^ r → Γ ⊢ A ⇒*Π B ^ r → Γ ⊢ A ≡ B ^ r deep*-correct ⊢A id = refl ⊢A deep*-correct ⊢A (x ⇨ X) = let ⊢B , A≡B = deep-correct ⊢A x in trans A≡B (deep*-correct ⊢B X) doΠNorm′ : ∀ {A rA Γ l} ([A] : Γ ⊩⟨ l ⟩ A ^ rA) → ∃ λ B → ΠNorm B × Γ ⊢ B ^ rA × Γ ⊢ A ⇒*Π B ^ rA doΠNorm′ (Uᵣ (Uᵣ r l′ l< PE.refl [[ A , U , d ]])) = Univ r l′ , Uₙ , Ugenⱼ (wf A) , regular* d doΠNorm′ (ℕᵣ [[ ⊢A , ⊢B , D ]]) = ℕ , ℕₙ , ⊢B , regular* D doΠNorm′ (Emptyᵣ {l = l} [[ ⊢A , ⊢B , D ]]) = Empty l , Emptyₙ , ⊢B , regular* D doΠNorm′ (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) = K , ne neK , ⊢B , regular* D doΠNorm′ (Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) = let redF₀ , red₀ = reducibleTerm (var (wf ⊢G) here) [F]′ = irrelevanceTerm redF₀ ([F] (step id) (wf ⊢G)) red₀ G′ , nG′ , ⊢G′ , D′ = PE.subst (λ G′ → ∃ λ B → ΠNorm B × _ ⊢ B ^ _ × _ ⊢ G′ ⇒*Π B ^ _) (wkSingleSubstId _) (doΠNorm′ ([G] (step id) (wf ⊢G) [F]′)) in Π F ^ rF ° lF ▹ G′ ° lG ° _ , Πₙ nG′ , univ (Πⱼ lF≤ ▹ lG≤ ▹ (un-univ ⊢F) ▹ (un-univ ⊢G′)) , regular* D ⇨* deep* D′ doΠNorm′ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = let F′ , nF′ , ⊢F′ , D′ = doΠNorm′ ([F] id (wf ⊢F)) DD = (PE.subst (λ FF → _ ⊢ FF ⇒*Π F′ ^ _ ) (wk-id _) D′) F≡F′ = deep*-correct ⊢F DD in ∃ F′ ▹ G , ∃ₙ nF′ , univ (∃ⱼ un-univ ⊢F′ ▹ un-univ (stability (reflConEq (wf ⊢F) ∙ F≡F′) ⊢G)) , regular* (red D) ⇨* deep∃* DD doΠNorm′ (emb emb< [A]) = doΠNorm′ [A] doΠNorm′ (emb ∞< [A]) = doΠNorm′ [A] doΠNorm : ∀ {A rA Γ} → Γ ⊢ A ^ rA → ∃ λ B → ΠNorm B × Γ ⊢ B ^ rA × Γ ⊢ A ⇒*Π B ^ rA doΠNorm ⊢A = doΠNorm′ (reducible ⊢A) ΠNorm-whnf : ∀ {A} → ΠNorm A → Whnf A ΠNorm-whnf Uₙ = Uₙ ΠNorm-whnf (Πₙ _) = Πₙ ΠNorm-whnf (∃ₙ _) = ∃ₙ ΠNorm-whnf ℕₙ = ℕₙ ΠNorm-whnf Emptyₙ = Emptyₙ ΠNorm-whnf (ne x) = ne x ΠNorm-noredTerm : ∀ {Γ A B T r} → Γ ⊢ A ⇒Π B ∷ T ^ r → ΠNorm A → ⊥ ΠNorm-noredTerm (regular x) w = whnfRedTerm x (ΠNorm-whnf w) ΠNorm-noredTerm (deepΠ x) (Πₙ w) = ΠNorm-noredTerm x w ΠNorm-noredTerm (deepΠ x) (ne ()) ΠNorm-noredTerm (deep∃ x) (∃ₙ w) = ΠNorm-noredTerm x w ΠNorm-noredTerm (deep∃ x) (ne ()) ΠNorm-nored : ∀ {Γ A B r} → Γ ⊢ A ⇒Π B ^ r → ΠNorm A → ⊥ ΠNorm-nored (univ x) w = ΠNorm-noredTerm x w detΠRedTerm : ∀ {Γ A B B′ T T′ r r'} → Γ ⊢ A ⇒Π B ∷ T ^ r → Γ ⊢ A ⇒Π B′ ∷ T′ ^ r' → B PE.≡ B′ detΠRedTerm (regular x) (regular x₁) = whrDetTerm x x₁ detΠRedTerm (regular x) (deepΠ y) = ⊥-elim (whnfRedTerm x Πₙ) detΠRedTerm (deepΠ x) (regular x₁) = ⊥-elim (whnfRedTerm x₁ Πₙ) detΠRedTerm (deepΠ x) (deepΠ y) = PE.cong _ (detΠRedTerm x y) detΠRedTerm (regular x) (deep∃ y) = ⊥-elim (whnfRedTerm x ∃ₙ) detΠRedTerm (deep∃ x) (regular x₁) = ⊥-elim (whnfRedTerm x₁ ∃ₙ) detΠRedTerm (deep∃ x) (deep∃ y) = PE.cong _ (detΠRedTerm x y) detΠRed : ∀ {Γ A B B′ r r′} → Γ ⊢ A ⇒Π B ^ r → Γ ⊢ A ⇒Π B′ ^ r′ → B PE.≡ B′ detΠRed (univ x) (univ y) = detΠRedTerm x y detΠNorm* : ∀ {Γ A B B′ r r′} → ΠNorm B → ΠNorm B′ → Γ ⊢ A ⇒*Π B ^ r → Γ ⊢ A ⇒*Π B′ ^ r′ → B PE.≡ B′ detΠNorm* w w′ id id = PE.refl detΠNorm* w w′ id (x ⇨ b) = ⊥-elim (ΠNorm-nored x w) detΠNorm* w w′ (x ⇨ a) id = ⊥-elim (ΠNorm-nored x w′) detΠNorm* w w′ (x ⇨ a) (x₁ ⇨ b) = detΠNorm* w w′ a (PE.subst (λ t → _ ⊢ t ⇒*Π _ ^ _) (detΠRed x₁ x) b)
{ "alphanum_fraction": 0.5190792713, "avg_line_length": 41.0303030303, "ext": "agda", "hexsha": "dd03fc827b5ebe0dc4e6d52eee918f575cad50bf", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_path": "Definition/Typed/Consequences/PiNorm.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CoqHott/logrel-mltt", "max_issues_repo_path": "Definition/Typed/Consequences/PiNorm.agda", "max_line_length": 130, "max_stars_count": 2, "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_path": "Definition/Typed/Consequences/PiNorm.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z", "num_tokens": 4117, "size": 8124 }
{-# OPTIONS --universe-polymorphism #-} module Categories.Grothendieck where open import Relation.Binary using (Rel) open import Data.Product using (Σ; _,_; proj₁; proj₂; _×_) open import Categories.Support.Experimental open import Categories.Support.PropositionalEquality open import Categories.Support.IProduct import Categories.Category as CCat open CCat hiding (module Heterogeneous) open import Categories.Functor using (Functor; module Functor; ≡⇒≣) open import Categories.Agda open import Categories.Categories open import Categories.Congruence -- TODO: don't use sigmas -- Break into modules Strict and Weak using Sets and Setoids? Elements : ∀ {o ℓ e o′} {C : Category o ℓ e} → Functor C (Sets o′) → Category _ _ _ Elements {o′ = o′} {C = C} F = record { Obj = Obj′ ; _⇒_ = Hom′ ; _≡_ = _≡′_ ; _∘_ = _∘′_ ; id = id , identity ; assoc = assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; equiv = record { refl = refl ; sym = sym ; trans = trans } ; ∘-resp-≡ = ∘-resp-≡ } where open Category C open Equiv open Functor F Obj′ = Σ Obj F₀ Hom′ : Rel Obj′ _ Hom′ (c₁ , x₁) (c₂ , x₂) = Σ′ (c₁ ⇒ c₂) (λ f → F₁ f x₁ ≣ x₂) _≡′_ : ∀ {X Y} → Rel (Hom′ X Y) _ (f , pf₁) ≡′ (g , pf₂) = f ≡ g _∘′_ : ∀ {X Y Z} → Hom′ Y Z → Hom′ X Y → Hom′ X Z _∘′_ {X} {Y} {Z} (f , pf₁) (g , pf₂) = (f ∘ g) , pf where -- This could be a lot prettier... .pf : F₁ (f ∘ g) (proj₂ X) ≣ proj₂ Z pf = ≣-trans homomorphism (≣-sym (≣-trans (≣-sym pf₁) (≣-cong (F₁ f) (≣-sym pf₂)))) Dom : ∀ {o ℓ e o′} {C : Category o ℓ e} → (F : Functor C (Sets o′)) -> Functor (Elements F) C Dom {C = C} F = record { F₀ = proj₁; F₁ = proj₁′; identity = Equiv.refl; homomorphism = Equiv.refl; F-resp-≡ = λ x → x } where open Category C -- because we want the following function to reduce all the time, define it globally private module _ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} (F : Functor C (Categories o′ ℓ′ e′)) where private module C = Category C module F = Functor F module Cat = Category (Categories o′ ℓ′ e′) ∘-eq : ∀ {cx xx cy cz} -> (f : cy C.⇒ cz) (g : cx C.⇒ cy) -> Functor.F₀ (F.F₁ f Cat.∘ F.F₁ g) xx ≣ Functor.F₀ (F.F₁ (f C.∘ g)) xx ∘-eq {cx} {xx} {cy} {cz} f g = ≣-relevant (≣-sym (≡⇒≣ (F.F₁ (f C.∘ g)) (F.F₁ f Cat.∘ F.F₁ g) (F.homomorphism {f = g} {g = f}) xx)) Grothendieck : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} → Functor C (Categories o′ ℓ′ e′) → Category _ _ _ Grothendieck {o′ = o′} {ℓ′} {e′} {C = C} F = record { Obj = Obj′ ; _⇒_ = Hom′ ; _≡_ = _≡′_ ; _∘_ = _∘′_ ; id = id′ ; assoc = assoc′ ; identityˡ = identityˡ′ ; identityʳ = identityʳ′ ; equiv = record { refl = refl , Het.refl; sym = λ { (eq₁ , eq₂) → sym eq₁ , Het.sym eq₂}; trans = λ { (xeq₁ , xeq₂) (yeq₁ , yeq₂) → trans xeq₁ yeq₁ , Het.trans xeq₂ yeq₂} } ; ∘-resp-≡ = ∘-resp-≡′ } module Groth where open Functor F module Fc {c} where open Category (F₀ c) public open Equiv public open Category C open Equiv module Cat = Category (Categories o′ ℓ′ e′) module Cong {c} where open Congruence (TrivialCongruence (F₀ c)) public open Cong public using () renaming (coerce to coe) module Het {c} = Heterogeneous (TrivialCongruence (F₀ c)) open Het using (▹_) module OHet {c} where open CCat.Heterogeneous (F₀ c) public ohet⇒het : ∀ {A B} {f : A Fc.⇒ B} -> ∀ {X Y} → {g : X Fc.⇒ Y} → f ∼ g -> f Het.∼ g ohet⇒het (≡⇒∼ x) = Het.≡⇒∼ ≣-refl ≣-refl x Obj′ = Σ Obj (\ c -> Category.Obj (F₀ c)) Hom′ : Rel Obj′ _ Hom′ (c₁ , x₁) (c₂ , x₂) = Σ (c₁ ⇒ c₂) (λ f → Functor.F₀ (F₁ f) x₁ Fc.⇒ x₂) _≡′_ : ∀ {X Y} → Rel (Hom′ X Y) _ _≡′_ {c₁ , x₁} {c₂ , x₂} (f , α) (g , β) = f ≡ g × α Het.∼ β _∘′_ : ∀ {X Y Z} → Hom′ Y Z → Hom′ X Y → Hom′ X Z _∘′_ {cx , xx} {Y} {cz , xz} (f , α) (g , β) = (f ∘ g) , α Fc.∘ Cong.coerce (∘-eq F f g) ≣-refl (Functor.F₁ (F₁ f) β) id-eq : ∀ {c x} -> Functor.F₀ (Cat.id {F₀ c}) x ≣ Functor.F₀ (F₁ id) x id-eq {c} {x} = ≣-relevant (≣-sym (≡⇒≣ (F₁ id) Cat.id (identity {c}) x)) id′ : {A : Obj′} → Hom′ A A id′ {c , x} = id , Cong.coerce id-eq ≣-refl Fc.id F-resp-∼ : ∀ {b c} -> (H : Functor (F₀ b) (F₀ c)) -> {A B A' B' : Category.Obj (F₀ b)} {α : A Fc.⇒ B }{β : A' Fc.⇒ B'} → (α Het.∼ β) → (Functor.F₁ H α Het.∼ Functor.F₁ H β) F-resp-∼ H (Heterogeneous.≡⇒∼ ≣-refl ≣-refl x) = Heterogeneous.≡⇒∼ ≣-refl ≣-refl (Functor.F-resp-≡ H x) .identityˡ′ : {A B : Obj′} {f : Hom′ A B} → (id′ ∘′ f) ≡′ f identityˡ′ {ca , xa} {cb , xb} {f , α} = identityˡ , (begin ▹ coe id-eq ≣-refl Fc.id Fc.∘ coe (∘-eq F id f) ≣-refl (Functor.F₁ (F₁ id) α) ↓⟨ Het.∘-resp-∼ (Het.sym (Het.coerce-resp-∼ id-eq ≣-refl)) F₁id[α]~α ⟩ ▹ Fc.id Fc.∘ α ↓⟨ Het.≡⇒∼ ≣-refl ≣-refl Fc.identityˡ ⟩ ▹ α ∎) where open Het.HetReasoning F₁id[α]~α : coe (∘-eq F id f) ≣-refl (Functor.F₁ (F₁ id) α) Het.∼ α F₁id[α]~α = begin ▹ coe (∘-eq F id f) ≣-refl (Functor.F₁ (F₁ id) α) ↑⟨ Het.coerce-resp-∼ (∘-eq F id f) ≣-refl ⟩ ▹ Functor.F₁ (F₁ id) α ↓⟨ OHet.ohet⇒het (identity α) ⟩ ▹ α ∎ .identityʳ′ : {A B : Obj′} {f : Hom′ A B} → (f ∘′ id′) ≡′ f identityʳ′ {ca , xa} {cb , xb} {f , α} = identityʳ , (begin ▹ α Fc.∘ coe (∘-eq F f id) ≣-refl (Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id)) ↓⟨ Het.∘-resp-∼ʳ F₁f[id]~id ⟩ ▹ α Fc.∘ Fc.id ↓⟨ Het.≡⇒∼ ≣-refl ≣-refl Fc.identityʳ ⟩ ▹ α ∎) where open Het.HetReasoning F₁f[id]~id : coe (∘-eq F f id) ≣-refl (Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id)) Het.∼ Fc.id F₁f[id]~id = begin ▹ coe (∘-eq F f id) ≣-refl (Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id)) ↑⟨ Het.coerce-resp-∼ (∘-eq F f id) ≣-refl ⟩ ▹ Functor.F₁ (F₁ f) (coe id-eq ≣-refl Fc.id) ↓⟨ F-resp-∼ (F₁ f) (Het.sym (Het.coerce-resp-∼ id-eq ≣-refl)) ⟩ ▹ Functor.F₁ (F₁ f) (Category.id (F₀ ca)) ↓⟨ Het.≡⇒∼ ≣-refl ≣-refl (Functor.identity (F₁ f)) ⟩ ▹ Fc.id ∎ .assoc′ : {A B C₁ D : Obj′} {f : Hom′ A B} {g : Hom′ B C₁} {h : Hom′ C₁ D} → ((h ∘′ g) ∘′ f) ≡′ (h ∘′ (g ∘′ f)) assoc′ {ca , xa} {cb , xb} {cc , xc} {cd , xd} {f , α} {g , β} {h , γ} = assoc , Het.trans (Het.≡⇒∼ ≣-refl ≣-refl Fc.assoc) (Het.∘-resp-∼ʳ F₁h[β]∘F₁h∘g[α]~F₁h[β∘F₁g[α]]) where open Het.HetReasoning eq : Functor.F₀ (F₁ ((h ∘ g) ∘ f)) xa ≣ Functor.F₀ (F₁ (h ∘ g ∘ f)) xa eq = ≡⇒≣ (F₁ ((h ∘ g) ∘ f)) (F₁ (h ∘ g ∘ f)) (F-resp-≡ (assoc {f = f})) xa F₁h[β]∘F₁h∘g[α]~F₁h[β∘F₁g[α]] : (coe (∘-eq F h g) ≣-refl (Functor.F₁ (F₁ h) β) Fc.∘ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α)) Het.∼ (coe (∘-eq F h (g ∘ f)) ≣-refl (Functor.F₁ (F₁ h) (proj₂ ((g , β) ∘′ (f , α))))) F₁h[β]∘F₁h∘g[α]~F₁h[β∘F₁g[α]] = Het.sym (begin ▹ coe (∘-eq F h (g ∘ f)) ≣-refl (Functor.F₁ (F₁ h) (β Fc.∘ coe(∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α))) ↑⟨ Het.coerce-resp-∼ (∘-eq F h (g ∘ f)) ≣-refl ⟩ ▹ Functor.F₁ (F₁ h) (β Fc.∘ coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α)) ↓⟨ Het.≡⇒∼ ≣-refl ≣-refl (Functor.homomorphism (F₁ h)) ⟩ ▹ Functor.F₁ (F₁ h) β Fc.∘ (Functor.F₁ (F₁ h) (coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α))) ↓⟨ Het.∘-resp-∼ (Het.coerce-resp-∼ (∘-eq F h g) ≣-refl) F₁h[β]~F₁h∘g[α] ⟩ ▹ coe (∘-eq F h g) ≣-refl (Functor.F₁ (F₁ h) β) Fc.∘ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α) ∎) where F₁h[β]~F₁h∘g[α] : (Functor.F₁ (F₁ h) (coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α))) Het.∼ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α) F₁h[β]~F₁h∘g[α] = begin ▹ Functor.F₁ (F₁ h) (coe (∘-eq F g f) ≣-refl (Functor.F₁ (F₁ g) α)) ↓⟨ F-resp-∼ (F₁ h) (Het.sym (Het.coerce-resp-∼ (∘-eq F g f) ≣-refl)) ⟩ ▹ Functor.F₁ (F₁ h) (Functor.F₁ (F₁ g) α) ↑⟨ OHet.ohet⇒het (homomorphism α) ⟩ ▹ Functor.F₁ (F₁ (h ∘ g)) α ↓⟨ Het.coerce-resp-∼ (∘-eq F (h ∘ g) f) ≣-refl ⟩ ▹ coe (∘-eq F (h ∘ g) f) ≣-refl (Functor.F₁ (F₁ (h ∘ g)) α) ∎ .∘-resp-≡′ : {A B C₁ : Obj′} {f h : Hom′ B C₁} {g i : Hom′ A B} → f ≡′ h → g ≡′ i → (f ∘′ g) ≡′ (h ∘′ i) ∘-resp-≡′ {a , ax} {b , bx} {c , cx} {f = f , α} {h , η} {g , γ} {i , ι} (f≡h , α~η) (g≡i , γ~ι) = ∘-resp-≡ f≡h g≡i , Het.∘-resp-∼ α~η (begin ▹ coe (∘-eq F f g) ≣-refl (Functor.F₁ (F₁ f) γ) ↑⟨ Het.coerce-resp-∼ (∘-eq F f g) ≣-refl ⟩ ▹ Functor.F₁ (F₁ f) γ ↓⟨ OHet.ohet⇒het (F-resp-≡ f≡h γ) ⟩ ▹ Functor.F₁ (F₁ h) γ ↓⟨ F-resp-∼ (F₁ h) γ~ι ⟩ ▹ Functor.F₁ (F₁ h) ι ↓⟨ Het.coerce-resp-∼ (∘-eq F h i) ≣-refl ⟩ ▹ coe (∘-eq F h i) ≣-refl (Functor.F₁ (F₁ h) ι) ∎) where open Het.HetReasoning Gr = Grothendieck DomGr : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} → (F : Functor C (Categories o′ ℓ′ e′)) → Functor (Grothendieck F) C DomGr {C = C} F = record { F₀ = proj₁; F₁ = proj₁; identity = C.Equiv.refl; homomorphism = C.Equiv.refl; F-resp-≡ = proj₁ } where module C = Category C inGr : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} (F : Functor C (Categories o′ ℓ′ e′)) → ∀ c -> Functor (Functor.F₀ F c) (Gr F) inGr {C = C} F c = record { F₀ = _,_ c; F₁ = λ f → C.id , GrF.coe GrF.id-eq ≣-refl f; identity = Category.Equiv.refl (Grothendieck F); homomorphism = C.Equiv.sym C.identityʳ , Het.trans (Het.sym (Het.coerce-resp-∼ GrF.id-eq ≣-refl)) (Het.∘-resp-∼ (Het.coerce-resp-∼ GrF.id-eq ≣-refl) (Het.trans (Het.trans (Het.coerce-resp-∼ GrF.id-eq ≣-refl) (Het.sym (GrF.OHet.ohet⇒het (F.identity _)))) (Het.coerce-resp-∼ (∘-eq F C.id C.id) ≣-refl))); F-resp-≡ = λ x → C.Equiv.refl , (Het.trans (Het.trans (Het.sym (Het.coerce-resp-∼ GrF.id-eq ≣-refl)) (Heterogeneous.≡⇒∼ ≣-refl ≣-refl x)) (Het.coerce-resp-∼ GrF.id-eq ≣-refl)) } where module C = Category C module F = Functor F module GrF = Groth F open GrF using (module Het; module Cong)
{ "alphanum_fraction": 0.4780738663, "avg_line_length": 43.2995951417, "ext": "agda", "hexsha": "4d72918e7e7a2dbbd5e749b9501ed6eab8e85678", "lang": "Agda", "max_forks_count": 23, "max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z", "max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "p-pavel/categories", "max_forks_repo_path": "Categories/Grothendieck.agda", "max_issues_count": 19, "max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z", "max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "p-pavel/categories", "max_issues_repo_path": "Categories/Grothendieck.agda", "max_line_length": 155, "max_stars_count": 98, "max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "copumpkin/categories", "max_stars_repo_path": "Categories/Grothendieck.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z", "num_tokens": 4943, "size": 10695 }
------------------------------------------------------------------------ -- The Agda standard library -- -- A bunch of properties ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Bool.Properties where open import Algebra open import Data.Bool.Base open import Data.Empty open import Data.Product open import Data.Sum open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence using (_⇔_; equivalence; module Equivalence) open import Level using (0ℓ) open import Relation.Binary.Core using (Decidable) open import Relation.Binary.PropositionalEquality hiding ([_]) open import Relation.Nullary using (yes; no) open import Relation.Nullary.Decidable using (True) open import Relation.Unary as U using (Irrelevant) open import Algebra.FunctionProperties (_≡_ {A = Bool}) open import Algebra.Structures (_≡_ {A = Bool}) open ≡-Reasoning ------------------------------------------------------------------------ -- Queries infix 4 _≟_ _≟_ : Decidable {A = Bool} _≡_ true ≟ true = yes refl false ≟ false = yes refl true ≟ false = no λ() false ≟ true = no λ() ------------------------------------------------------------------------ -- Properties of _∨_ ∨-assoc : Associative _∨_ ∨-assoc true y z = refl ∨-assoc false y z = refl ∨-comm : Commutative _∨_ ∨-comm true true = refl ∨-comm true false = refl ∨-comm false true = refl ∨-comm false false = refl ∨-identityˡ : LeftIdentity false _∨_ ∨-identityˡ _ = refl ∨-identityʳ : RightIdentity false _∨_ ∨-identityʳ false = refl ∨-identityʳ true = refl ∨-identity : Identity false _∨_ ∨-identity = ∨-identityˡ , ∨-identityʳ ∨-zeroˡ : LeftZero true _∨_ ∨-zeroˡ _ = refl ∨-zeroʳ : RightZero true _∨_ ∨-zeroʳ false = refl ∨-zeroʳ true = refl ∨-zero : Zero true _∨_ ∨-zero = ∨-zeroˡ , ∨-zeroʳ ∨-inverseˡ : LeftInverse true not _∨_ ∨-inverseˡ false = refl ∨-inverseˡ true = refl ∨-inverseʳ : RightInverse true not _∨_ ∨-inverseʳ x = ∨-comm x (not x) ⟨ trans ⟩ ∨-inverseˡ x ∨-inverse : Inverse true not _∨_ ∨-inverse = ∨-inverseˡ , ∨-inverseʳ ∨-idem : Idempotent _∨_ ∨-idem false = refl ∨-idem true = refl ∨-sel : Selective _∨_ ∨-sel false y = inj₂ refl ∨-sel true y = inj₁ refl ∨-isMagma : IsMagma _∨_ ∨-isMagma = record { isEquivalence = isEquivalence ; ∙-cong = cong₂ _∨_ } ∨-magma : Magma 0ℓ 0ℓ ∨-magma = record { isMagma = ∨-isMagma } ∨-isSemigroup : IsSemigroup _∨_ ∨-isSemigroup = record { isMagma = ∨-isMagma ; assoc = ∨-assoc } ∨-semigroup : Semigroup 0ℓ 0ℓ ∨-semigroup = record { isSemigroup = ∨-isSemigroup } ∨-isBand : IsBand _∨_ ∨-isBand = record { isSemigroup = ∨-isSemigroup ; idem = ∨-idem } ∨-band : Band 0ℓ 0ℓ ∨-band = record { isBand = ∨-isBand } ∨-isSemilattice : IsSemilattice _∨_ ∨-isSemilattice = record { isBand = ∨-isBand ; comm = ∨-comm } ∨-semilattice : Semilattice 0ℓ 0ℓ ∨-semilattice = record { isSemilattice = ∨-isSemilattice } ∨-isCommutativeMonoid : IsCommutativeMonoid _∨_ false ∨-isCommutativeMonoid = record { isSemigroup = ∨-isSemigroup ; identityˡ = ∨-identityˡ ; comm = ∨-comm } ∨-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ ∨-commutativeMonoid = record { isCommutativeMonoid = ∨-isCommutativeMonoid } ∨-isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid _∨_ false ∨-isIdempotentCommutativeMonoid = record { isCommutativeMonoid = ∨-isCommutativeMonoid ; idem = ∨-idem } ∨-idempotentCommutativeMonoid : IdempotentCommutativeMonoid 0ℓ 0ℓ ∨-idempotentCommutativeMonoid = record { isIdempotentCommutativeMonoid = ∨-isIdempotentCommutativeMonoid } ------------------------------------------------------------------------ -- Properties of _∧_ ∧-assoc : Associative _∧_ ∧-assoc true y z = refl ∧-assoc false y z = refl ∧-comm : Commutative _∧_ ∧-comm true true = refl ∧-comm true false = refl ∧-comm false true = refl ∧-comm false false = refl ∧-identityˡ : LeftIdentity true _∧_ ∧-identityˡ _ = refl ∧-identityʳ : RightIdentity true _∧_ ∧-identityʳ false = refl ∧-identityʳ true = refl ∧-identity : Identity true _∧_ ∧-identity = ∧-identityˡ , ∧-identityʳ ∧-zeroˡ : LeftZero false _∧_ ∧-zeroˡ _ = refl ∧-zeroʳ : RightZero false _∧_ ∧-zeroʳ false = refl ∧-zeroʳ true = refl ∧-zero : Zero false _∧_ ∧-zero = ∧-zeroˡ , ∧-zeroʳ ∧-inverseˡ : LeftInverse false not _∧_ ∧-inverseˡ false = refl ∧-inverseˡ true = refl ∧-inverseʳ : RightInverse false not _∧_ ∧-inverseʳ x = ∧-comm x (not x) ⟨ trans ⟩ ∧-inverseˡ x ∧-inverse : Inverse false not _∧_ ∧-inverse = ∧-inverseˡ , ∧-inverseʳ ∧-idem : Idempotent _∧_ ∧-idem false = refl ∧-idem true = refl ∧-sel : Selective _∧_ ∧-sel false y = inj₁ refl ∧-sel true y = inj₂ refl ∧-distribˡ-∨ : _∧_ DistributesOverˡ _∨_ ∧-distribˡ-∨ true y z = refl ∧-distribˡ-∨ false y z = refl ∧-distribʳ-∨ : _∧_ DistributesOverʳ _∨_ ∧-distribʳ-∨ x y z = begin (y ∨ z) ∧ x ≡⟨ ∧-comm (y ∨ z) x ⟩ x ∧ (y ∨ z) ≡⟨ ∧-distribˡ-∨ x y z ⟩ x ∧ y ∨ x ∧ z ≡⟨ cong₂ _∨_ (∧-comm x y) (∧-comm x z) ⟩ y ∧ x ∨ z ∧ x ∎ ∧-distrib-∨ : _∧_ DistributesOver _∨_ ∧-distrib-∨ = ∧-distribˡ-∨ , ∧-distribʳ-∨ ∨-distribˡ-∧ : _∨_ DistributesOverˡ _∧_ ∨-distribˡ-∧ true y z = refl ∨-distribˡ-∧ false y z = refl ∨-distribʳ-∧ : _∨_ DistributesOverʳ _∧_ ∨-distribʳ-∧ x y z = begin (y ∧ z) ∨ x ≡⟨ ∨-comm (y ∧ z) x ⟩ x ∨ (y ∧ z) ≡⟨ ∨-distribˡ-∧ x y z ⟩ (x ∨ y) ∧ (x ∨ z) ≡⟨ cong₂ _∧_ (∨-comm x y) (∨-comm x z) ⟩ (y ∨ x) ∧ (z ∨ x) ∎ ∨-distrib-∧ : _∨_ DistributesOver _∧_ ∨-distrib-∧ = ∨-distribˡ-∧ , ∨-distribʳ-∧ ∧-abs-∨ : _∧_ Absorbs _∨_ ∧-abs-∨ true y = refl ∧-abs-∨ false y = refl ∨-abs-∧ : _∨_ Absorbs _∧_ ∨-abs-∧ true y = refl ∨-abs-∧ false y = refl ∨-∧-absorptive : Absorptive _∨_ _∧_ ∨-∧-absorptive = ∨-abs-∧ , ∧-abs-∨ ∧-isMagma : IsMagma _∧_ ∧-isMagma = record { isEquivalence = isEquivalence ; ∙-cong = cong₂ _∧_ } ∧-magma : Magma 0ℓ 0ℓ ∧-magma = record { isMagma = ∧-isMagma } ∧-isSemigroup : IsSemigroup _∧_ ∧-isSemigroup = record { isMagma = ∧-isMagma ; assoc = ∧-assoc } ∧-semigroup : Semigroup 0ℓ 0ℓ ∧-semigroup = record { isSemigroup = ∧-isSemigroup } ∧-isBand : IsBand _∧_ ∧-isBand = record { isSemigroup = ∧-isSemigroup ; idem = ∧-idem } ∧-band : Band 0ℓ 0ℓ ∧-band = record { isBand = ∧-isBand } ∧-isSemilattice : IsSemilattice _∧_ ∧-isSemilattice = record { isBand = ∧-isBand ; comm = ∧-comm } ∧-semilattice : Semilattice 0ℓ 0ℓ ∧-semilattice = record { isSemilattice = ∧-isSemilattice } ∧-isCommutativeMonoid : IsCommutativeMonoid _∧_ true ∧-isCommutativeMonoid = record { isSemigroup = ∧-isSemigroup ; identityˡ = ∧-identityˡ ; comm = ∧-comm } ∧-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ ∧-commutativeMonoid = record { isCommutativeMonoid = ∧-isCommutativeMonoid } ∧-isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid _∧_ true ∧-isIdempotentCommutativeMonoid = record { isCommutativeMonoid = ∧-isCommutativeMonoid ; idem = ∧-idem } ∧-idempotentCommutativeMonoid : IdempotentCommutativeMonoid 0ℓ 0ℓ ∧-idempotentCommutativeMonoid = record { isIdempotentCommutativeMonoid = ∧-isIdempotentCommutativeMonoid } ∨-∧-isCommutativeSemiring : IsCommutativeSemiring _∨_ _∧_ false true ∨-∧-isCommutativeSemiring = record { +-isCommutativeMonoid = ∨-isCommutativeMonoid ; *-isCommutativeMonoid = ∧-isCommutativeMonoid ; distribʳ = ∧-distribʳ-∨ ; zeroˡ = ∧-zeroˡ } ∨-∧-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ ∨-∧-commutativeSemiring = record { _+_ = _∨_ ; _*_ = _∧_ ; 0# = false ; 1# = true ; isCommutativeSemiring = ∨-∧-isCommutativeSemiring } ∧-∨-isCommutativeSemiring : IsCommutativeSemiring _∧_ _∨_ true false ∧-∨-isCommutativeSemiring = record { +-isCommutativeMonoid = ∧-isCommutativeMonoid ; *-isCommutativeMonoid = ∨-isCommutativeMonoid ; distribʳ = ∨-distribʳ-∧ ; zeroˡ = ∨-zeroˡ } ∧-∨-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ ∧-∨-commutativeSemiring = record { _+_ = _∧_ ; _*_ = _∨_ ; 0# = true ; 1# = false ; isCommutativeSemiring = ∧-∨-isCommutativeSemiring } ∨-∧-isLattice : IsLattice _∨_ _∧_ ∨-∧-isLattice = record { isEquivalence = isEquivalence ; ∨-comm = ∨-comm ; ∨-assoc = ∨-assoc ; ∨-cong = cong₂ _∨_ ; ∧-comm = ∧-comm ; ∧-assoc = ∧-assoc ; ∧-cong = cong₂ _∧_ ; absorptive = ∨-∧-absorptive } ∨-∧-lattice : Lattice 0ℓ 0ℓ ∨-∧-lattice = record { isLattice = ∨-∧-isLattice } ∨-∧-isDistributiveLattice : IsDistributiveLattice _∨_ _∧_ ∨-∧-isDistributiveLattice = record { isLattice = ∨-∧-isLattice ; ∨-∧-distribʳ = ∨-distribʳ-∧ } ∨-∧-distributiveLattice : DistributiveLattice 0ℓ 0ℓ ∨-∧-distributiveLattice = record { isDistributiveLattice = ∨-∧-isDistributiveLattice } ∨-∧-isBooleanAlgebra : IsBooleanAlgebra _∨_ _∧_ not true false ∨-∧-isBooleanAlgebra = record { isDistributiveLattice = ∨-∧-isDistributiveLattice ; ∨-complementʳ = ∨-inverseʳ ; ∧-complementʳ = ∧-inverseʳ ; ¬-cong = cong not } ∨-∧-booleanAlgebra : BooleanAlgebra 0ℓ 0ℓ ∨-∧-booleanAlgebra = record { isBooleanAlgebra = ∨-∧-isBooleanAlgebra } ------------------------------------------------------------------------ -- Properties of _xor_ xor-is-ok : ∀ x y → x xor y ≡ (x ∨ y) ∧ not (x ∧ y) xor-is-ok true y = refl xor-is-ok false y = sym (∧-identityʳ _) xor-∧-commutativeRing : CommutativeRing 0ℓ 0ℓ xor-∧-commutativeRing = commutativeRing where import Algebra.Properties.BooleanAlgebra as BA open BA ∨-∧-booleanAlgebra open XorRing _xor_ xor-is-ok ------------------------------------------------------------------------ -- Miscellaneous other properties not-involutive : Involutive not not-involutive true = refl not-involutive false = refl not-¬ : ∀ {x y} → x ≡ y → x ≢ not y not-¬ {true} refl () not-¬ {false} refl () ¬-not : ∀ {x y} → x ≢ y → x ≡ not y ¬-not {true} {true} x≢y = ⊥-elim (x≢y refl) ¬-not {true} {false} _ = refl ¬-not {false} {true} _ = refl ¬-not {false} {false} x≢y = ⊥-elim (x≢y refl) ⇔→≡ : {b₁ b₂ b : Bool} → b₁ ≡ b ⇔ b₂ ≡ b → b₁ ≡ b₂ ⇔→≡ {true } {true } hyp = refl ⇔→≡ {true } {false} {true } hyp = sym (Equivalence.to hyp ⟨$⟩ refl) ⇔→≡ {true } {false} {false} hyp = Equivalence.from hyp ⟨$⟩ refl ⇔→≡ {false} {true } {true } hyp = Equivalence.from hyp ⟨$⟩ refl ⇔→≡ {false} {true } {false} hyp = sym (Equivalence.to hyp ⟨$⟩ refl) ⇔→≡ {false} {false} hyp = refl T-≡ : ∀ {b} → T b ⇔ b ≡ true T-≡ {false} = equivalence (λ ()) (λ ()) T-≡ {true} = equivalence (const refl) (const _) T-not-≡ : ∀ {b} → T (not b) ⇔ b ≡ false T-not-≡ {false} = equivalence (const refl) (const _) T-not-≡ {true} = equivalence (λ ()) (λ ()) T-∧ : ∀ {b₁ b₂} → T (b₁ ∧ b₂) ⇔ (T b₁ × T b₂) T-∧ {true} {true} = equivalence (const (_ , _)) (const _) T-∧ {true} {false} = equivalence (λ ()) proj₂ T-∧ {false} {_} = equivalence (λ ()) proj₁ T-∨ : ∀ {b₁ b₂} → T (b₁ ∨ b₂) ⇔ (T b₁ ⊎ T b₂) T-∨ {true} {b₂} = equivalence inj₁ (const _) T-∨ {false} {true} = equivalence inj₂ (const _) T-∨ {false} {false} = equivalence inj₁ [ id , id ] T-irrelevant : Irrelevant T T-irrelevant {true} _ _ = refl T-irrelevant {false} () () T? : U.Decidable T T? true = yes _ T? false = no (λ ()) T?-diag : ∀ b → T b → True (T? b) T?-diag true _ = _ T?-diag false () push-function-into-if : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) x {y z} → f (if x then y else z) ≡ (if x then f y else f z) push-function-into-if _ true = refl push-function-into-if _ false = refl ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.15 ∧-∨-distˡ = ∧-distribˡ-∨ {-# WARNING_ON_USAGE ∧-∨-distˡ "Warning: ∧-∨-distˡ was deprecated in v0.15. Please use ∧-distribˡ-∨ instead." #-} ∧-∨-distʳ = ∧-distribʳ-∨ {-# WARNING_ON_USAGE ∧-∨-distʳ "Warning: ∧-∨-distʳ was deprecated in v0.15. Please use ∧-distribʳ-∨ instead." #-} distrib-∧-∨ = ∧-distrib-∨ {-# WARNING_ON_USAGE distrib-∧-∨ "Warning: distrib-∧-∨ was deprecated in v0.15. Please use ∧-distrib-∨ instead." #-} ∨-∧-distˡ = ∨-distribˡ-∧ {-# WARNING_ON_USAGE ∨-∧-distˡ "Warning: ∨-∧-distˡ was deprecated in v0.15. Please use ∨-distribˡ-∧ instead." #-} ∨-∧-distʳ = ∨-distribʳ-∧ {-# WARNING_ON_USAGE ∨-∧-distʳ "Warning: ∨-∧-distʳ was deprecated in v0.15. Please use ∨-distribʳ-∧ instead." #-} ∨-∧-distrib = ∨-distrib-∧ {-# WARNING_ON_USAGE ∨-∧-distrib "Warning: ∨-∧-distrib was deprecated in v0.15. Please use ∨-distrib-∧ instead." #-} ∨-∧-abs = ∨-abs-∧ {-# WARNING_ON_USAGE ∨-∧-abs "Warning: ∨-∧-abs was deprecated in v0.15. Please use ∨-abs-∧ instead." #-} ∧-∨-abs = ∧-abs-∨ {-# WARNING_ON_USAGE ∧-∨-abs "Warning: ∧-∨-abs was deprecated in v0.15. Please use ∧-abs-∨ instead." #-} not-∧-inverseˡ = ∧-inverseˡ {-# WARNING_ON_USAGE not-∧-inverseˡ "Warning: not-∧-inverseˡ was deprecated in v0.15. Please use ∧-inverseˡ instead." #-} not-∧-inverseʳ = ∧-inverseʳ {-# WARNING_ON_USAGE not-∧-inverseʳ "Warning: not-∧-inverseʳ was deprecated in v0.15. Please use ∧-inverseʳ instead." #-} not-∧-inverse = ∧-inverse {-# WARNING_ON_USAGE not-∧-inverse "Warning: not-∧-inverse was deprecated in v0.15. Please use ∧-inverse instead." #-} not-∨-inverseˡ = ∨-inverseˡ {-# WARNING_ON_USAGE not-∨-inverseˡ "Warning: not-∨-inverseˡ was deprecated in v0.15. Please use ∨-inverseˡ instead." #-} not-∨-inverseʳ = ∨-inverseʳ {-# WARNING_ON_USAGE not-∨-inverseʳ "Warning: not-∨-inverseʳ was deprecated in v0.15. Please use ∨-inverseʳ instead." #-} not-∨-inverse = ∨-inverse {-# WARNING_ON_USAGE not-∨-inverse "Warning: not-∨-inverse was deprecated in v0.15. Please use ∨-inverse instead." #-} isCommutativeSemiring-∨-∧ = ∨-∧-isCommutativeSemiring {-# WARNING_ON_USAGE isCommutativeSemiring-∨-∧ "Warning: isCommutativeSemiring-∨-∧ was deprecated in v0.15. Please use ∨-∧-isCommutativeSemiring instead." #-} commutativeSemiring-∨-∧ = ∨-∧-commutativeSemiring {-# WARNING_ON_USAGE commutativeSemiring-∨-∧ "Warning: commutativeSemiring-∨-∧ was deprecated in v0.15. Please use ∨-∧-commutativeSemiring instead." #-} isCommutativeSemiring-∧-∨ = ∧-∨-isCommutativeSemiring {-# WARNING_ON_USAGE isCommutativeSemiring-∧-∨ "Warning: isCommutativeSemiring-∧-∨ was deprecated in v0.15. Please use ∧-∨-isCommutativeSemiring instead." #-} commutativeSemiring-∧-∨ = ∧-∨-commutativeSemiring {-# WARNING_ON_USAGE commutativeSemiring-∧-∨ "Warning: commutativeSemiring-∧-∨ was deprecated in v0.15. Please use ∧-∨-commutativeSemiring instead." #-} isBooleanAlgebra = ∨-∧-isBooleanAlgebra {-# WARNING_ON_USAGE isBooleanAlgebra "Warning: isBooleanAlgebra was deprecated in v0.15. Please use ∨-∧-isBooleanAlgebra instead." #-} booleanAlgebra = ∨-∧-booleanAlgebra {-# WARNING_ON_USAGE booleanAlgebra "Warning: booleanAlgebra was deprecated in v0.15. Please use ∨-∧-booleanAlgebra instead." #-} commutativeRing-xor-∧ = xor-∧-commutativeRing {-# WARNING_ON_USAGE commutativeRing-xor-∧ "Warning: commutativeRing-xor-∧ was deprecated in v0.15. Please use xor-∧-commutativeRing instead." #-} proof-irrelevance = T-irrelevant {-# WARNING_ON_USAGE proof-irrelevance "Warning: proof-irrelevance was deprecated in v0.15. Please use T-irrelevant instead." #-} -- Version 1.0 T-irrelevance = T-irrelevant {-# WARNING_ON_USAGE T-irrelevance "Warning: T-irrelevance was deprecated in v1.0. Please use T-irrelevant instead." #-}
{ "alphanum_fraction": 0.6190143529, "avg_line_length": 26.3752093802, "ext": "agda", "hexsha": "dbe74a96bc24e03eedbe07963368af5c998822b1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Bool/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Bool/Properties.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Bool/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6447, "size": 15746 }
module STLCSF.Examples where open import Data.Fin hiding (_+_) open import Data.Product open import Data.List open import Data.List.Membership.Propositional open import Data.List.Relation.Unary.Any open import Data.List.Relation.Unary.All open import Data.Maybe open import Data.Integer hiding (suc) -- This file contains a few example programs for the definitional -- interpreter for STLC using scopes and frames in Section 4. open import Agda.Builtin.Nat hiding (_+_) open import Relation.Binary.PropositionalEquality hiding ([_]) -- The identity function: λ x . x module Id where open import STLCSF.Semantics 2 open import ScopesFrames.ScopesFrames 2 Ty -- Whereas Agda can infer the structure of ordinary type contexts, -- the scope graph library represents scope graphs as "lookup -- tables". Agda cannot straightforwardly infer the structure of a -- lookup table. We spell it out. g : Graph g zero = [] , [] -- root scope g (suc n) = [ unit ] , [ zero ] -- lexical scope for lambda -- Had we used the structural representation discussed in Section -- 4.2 ("A Note on Scope Representation"), Agda could infer the -- structure of scope graphs for STLC for us. As summarized in that -- discussion, such a representation has other shortcomings, e.g., -- when it comes to dealing with scope graphs that has actual graph -- structure (i.e. cyclic paths). -- -- We assume that programs have been analyzed using the scope graph -- resolution calculus to construct scope graphs and replace named -- references with paths in programs. In future work, we will -- explore how to automate this. For now, we construct scope graphs -- manually. -- We load the syntax definition, specialized to our scope graph: open Syntax g open UsesGraph g idexpr : Expr zero (unit ⇒ unit) idexpr = ƛ {s' = suc zero} (var (path ([]) (here refl))) open UsesVal Val val-weaken -- Initial heap with an empty frame that is typed by the root scope: init-h : Heap [ zero ] init-h = ([] , []) ∷ [] -- id () = () test-idexpr : eval 2 (idexpr · unit) (here refl) init-h ≡ just (_ , _ , unit , _) test-idexpr = refl module Curry where open import STLCSF.Semantics 3 open import ScopesFrames.ScopesFrames 3 Ty -- Whereas Agda can infer the structure of ordinary type contexts, -- the scope graph library represents scope graphs as "lookup -- tables". Agda cannot straightforwardly infer the structure of a -- lookup table. We spell it out. g : Graph g zero = [] , [] -- root scope g (suc (suc n)) = [ int ] , [ suc zero ] -- lexical scope for inner lambda g (suc n) = [ int ] , [ zero ] -- lexical scope for outer -- Had we used the structural representation discussed in Section -- 4.2 ("A Note on Scope Representation"), Agda could infer the -- structure of scope graphs for STLC for us. As summarized in that -- discussion, such a representation has other shortcomings, e.g., -- when it comes to dealing with scope graphs that has actual graph -- structure (i.e. cyclic paths). -- -- We assume that programs have been analyzed using the scope graph -- resolution calculus to construct scope graphs and replace named -- references with paths in programs. In future work, we will -- explore how to automate this. For now, we construct scope graphs -- manually. -- We load the syntax definition, specialized to our scope graph: open Syntax g open UsesGraph g -- curried addition: λ x . λ y . y + x curry+ : Expr zero (int ⇒ (int ⇒ int)) curry+ = ƛ {s' = suc zero} (ƛ {s' = suc (suc zero)} (iop _+_ (var (path [] (here refl))) (var (path ((here refl) ∷ []) (here refl))))) open UsesVal Val val-weaken -- Initial heap with an empty frame that is typed by the root scope: init-h : Heap [ zero ] init-h = ([] , []) ∷ [] -- 1 + 1 = 2 test-curry+ : eval 3 ((curry+ · (num (+ 1))) · (num (+ 1))) (here refl) init-h ≡ just (_ , _ , num (+ 2) , _) test-curry+ = refl
{ "alphanum_fraction": 0.6660983926, "avg_line_length": 36.0175438596, "ext": "agda", "hexsha": "8494d83f0f4a4a9740226fe9aa9723a59f3f100e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/STLCSF/Examples.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/STLCSF/Examples.agda", "max_line_length": 83, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/STLCSF/Examples.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 1084, "size": 4106 }
{- 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.OBM.Rust.RustTypes module LibraBFT.Impl.OBM.Rust.Duration where record Duration : Set where constructor Duration∙new postulate -- TODO-1 : fromMillis, asMillis fromMillis : U64 → Duration asMillis : Duration → U128
{ "alphanum_fraction": 0.7636363636, "avg_line_length": 29.1176470588, "ext": "agda", "hexsha": "8f4cfb632cfdc4ca810f6c6ca606f5f29d6daf71", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z", "max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z", "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Impl/OBM/Rust/Duration.agda", "max_issues_count": 72, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z", "max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z", "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/OBM/Rust/Duration.agda", "max_line_length": 111, "max_stars_count": 4, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Impl/OBM/Rust/Duration.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z", "num_tokens": 137, "size": 495 }
module Category.Diagram where open import Level renaming (suc to lsuc) open import Equality.Eq open import Setoid.Total open import Category.Category open import Category.Funct open import Category.Preorder -- Diagrams are functors from an index category J to a category ℂ. We -- think of J as the scheme of the diagram in ℂ. record Diagram {l₁ l₂ : Level} (J : Cat {l₁}) (ℂ : Cat {l₂}) : Set (l₁ ⊔ l₂) where field diag : Functor J ℂ -- A commutative diagram is a diagram from a preorder to a category ℂ. -- The preorder axiom garauntees that any diagram must commute because -- there is only one composition. Mixing this with the fact that -- functors preserve composition implies that there can only be one -- composition in ℂ. This definition goes against the references -- -- nLab and Awedoy's book -- that comm. diagrams must be functors from -- posets. In fact we can prove that a PO is enough. See the next -- module. record Comm-Diagram {l₁ l₂ : Level} (J : PO {l₁}) (ℂ : Cat {l₂}) : Set (l₁ ⊔ l₂) where field diag : Diagram (po-cat J) ℂ open Comm-Diagram -- The underlying functor of a diagram. UFunc : {l l' : Level}{J : PO {l}}{ℂ : Cat {l'}} → Comm-Diagram J ℂ → Functor (po-cat J) ℂ UFunc D = Diagram.diag (diag D) -- This module shows that comm. squares can be modeled by POs. module Commutative-Squares where open 4PO record Comm-Square' {l : Level} (ℂ : Cat {l}) (om : 4Obj → Obj ℂ) (g : el (Hom ℂ (om i₁) (om i₂))) (h : el (Hom ℂ (om i₂) (om i₄))) (j : el (Hom ℂ (om i₁) (om i₃))) (k : el (Hom ℂ (om i₃) (om i₄))) : Set l where field Sq : {a b : 4Obj {l}} → SetoidFun (4Hom a b) (Hom ℂ (om a) (om b)) sq-max₁ : ⟨ Hom ℂ (om i₁) (om i₂) ⟩[ appT Sq f₁ ≡ g ] sq-max₂ : ⟨ Hom ℂ (om i₁) (om i₃) ⟩[ appT Sq f₂ ≡ j ] sq-max₃ : ⟨ Hom ℂ (om i₂) (om i₄) ⟩[ appT Sq f₃ ≡ h ] sq-max₄ : ⟨ Hom ℂ (om i₃) (om i₄) ⟩[ appT Sq f₄ ≡ k ] sq-funct-id : {i : 4Obj} → ⟨ Hom ℂ (om i) (om i) ⟩[ appT Sq (4Id {_}{i}) ≡ id ℂ ] sq-funct-comp : ∀{i j k : 4Obj {l}}{a : el (4Hom i j)}{b : el (4Hom j k)} → ⟨ Hom ℂ (om i) (om k) ⟩[ appT Sq (a ○[ 4Comp {l}{i}{j}{k} ] b) ≡ (appT Sq a) ○[ comp ℂ ] (appT Sq b) ] open Comm-Square' -- A default function from the objects of the 4PO to the objects of -- a square in ℂ. sq-default-om : {l : Level}{ℂ : Cat {l}} → Obj ℂ → Obj ℂ → Obj ℂ → Obj ℂ → (4Obj {l} → Obj ℂ) sq-default-om A B D C i₁ = A sq-default-om A B D C i₂ = B sq-default-om A B D C i₃ = D sq-default-om A B D C i₄ = C -- Commutative squares in ℂ. Comm-Square : {l : Level}{ℂ : Cat {l}} → (A B D C : Obj ℂ) → (g : el (Hom ℂ A B)) → (h : el (Hom ℂ B C)) → (j : el (Hom ℂ A D)) → (k : el (Hom ℂ D C)) → Set l Comm-Square {_} {ℂ} A B D C g h j k = Comm-Square' ℂ (sq-default-om {_} {ℂ} A B D C) g h j k -- Commutative squares are functors. Comm-Square-is-Functor : ∀{l}{ℂ : Cat {l}}{A B D C} → {g : el (Hom ℂ A B)} → {h : el (Hom ℂ B C)} → {j : el (Hom ℂ A D)} → {k : el (Hom ℂ D C)} → Comm-Square {_} {ℂ} A B D C g h j k → Functor {l} 4cat ℂ Comm-Square-is-Functor {_} {ℂ} {A} {B} {D} {C} {g} {h} {j} {k} sq = record { omap = sq-default-om {_}{ℂ} A B D C; fmap = λ {A₁} {B₁} → Sq sq {A₁} {B₁}; idPF = sq-funct-id sq; compPF = λ {A₁} {B₁} {C₁} {f} {g₁} → sq-funct-comp sq {A₁}{B₁}{C₁}{f}{g₁} } -- The former now implies that we have a commutative diagram. Comm-Square-is-Comm-Diagram : ∀{l}{ℂ : Cat {l}}{A B D C} → {g : el (Hom ℂ A B)} → {h : el (Hom ℂ B C)} → {j : el (Hom ℂ A D)} → {k : el (Hom ℂ D C)} → Comm-Square {_} {ℂ} A B D C g h j k → Comm-Diagram {l}{l} 4po ℂ Comm-Square-is-Comm-Diagram {l}{ℂ}{g}{h}{j}{k} sq = record { diag = record { diag = Comm-Square-is-Functor sq } } -- If we have a commutative square, then it commutes in ℂ. Comm-Square-Commutes : ∀{l}{ℂ : Cat {l}}{A B D C} → {g : el (Hom ℂ A B)} → {h : el (Hom ℂ B C)} → {j : el (Hom ℂ A D)} → {k : el (Hom ℂ D C)} → Comm-Square {_} {ℂ} A B D C g h j k → ⟨ Hom ℂ A C ⟩[ g ○[ comp ℂ ] h ≡ j ○[ comp ℂ ] k ] Comm-Square-Commutes {l}{ℂ}{A}{B}{D}{C}{g}{h}{j}{k} sq with sq-funct-comp sq {i₁}{i₂}{i₄}{f₁}{f₃} | sq-funct-comp sq {i₁}{i₃}{i₄}{f₂}{f₄} ... | sq-eq₁ | sq-eq₂ with transPf (parEqPf (eqRpf (Hom ℂ A C))) (symPf (parEqPf (eqRpf (Hom ℂ A C))) sq-eq₁) sq-eq₂ ... | sq-eq₃ with eq-comp-all {_}{ℂ}{A}{B}{C}{g} {appT {_}{_}{4Hom i₁ i₂} {Hom ℂ A B} (Sq sq {i₁}{i₂}) f₁} {h} {appT (Sq sq {i₂}{i₄}) f₃} (symPf (parEqPf (eqRpf (Hom ℂ A B))) (sq-max₁ sq)) (symPf (parEqPf (eqRpf (Hom ℂ B C))) (sq-max₃ sq)) ... | sq-eq₄ with eq-comp-all {_}{ℂ}{A}{D}{C} {appT {_}{_}{4Hom i₁ i₃} {Hom ℂ A D} (Sq sq {i₁}{i₃}) f₂} {j} {appT (Sq sq {i₃}{i₄}) f₄} {k} (sq-max₂ sq) (sq-max₄ sq) ... | sq-eq₅ with transPf (parEqPf (eqRpf (Hom ℂ A C))) sq-eq₄ sq-eq₃ ... | sq-eq₆ = transPf (parEqPf (eqRpf (Hom ℂ A C))) sq-eq₆ sq-eq₅
{ "alphanum_fraction": 0.5042016807, "avg_line_length": 40.5481481481, "ext": "agda", "hexsha": "5e6f310438245bc5887aac29443b899b6c0f040e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heades/AUGL", "max_forks_repo_path": "setoid-cats/Category/Diagram.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "heades/AUGL", "max_issues_repo_path": "setoid-cats/Category/Diagram.agda", "max_line_length": 139, "max_stars_count": null, "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heades/AUGL", "max_stars_repo_path": "setoid-cats/Category/Diagram.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2188, "size": 5474 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Ring where open import Cubical.Algebra.Ring.Base public open import Cubical.Algebra.Ring.Properties public open import Cubical.Algebra.Ring.Ideal public open import Cubical.Algebra.Ring.Kernel public
{ "alphanum_fraction": 0.8036363636, "avg_line_length": 34.375, "ext": "agda", "hexsha": "7168cab3b15f156bf92dc652a99e8924d766e3b2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Algebra/Ring.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Algebra/Ring.agda", "max_line_length": 50, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Algebra/Ring.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 69, "size": 275 }
{-# OPTIONS --cubical-compatible #-} module Common.Product where open import Common.Level infixr 4 _,_ _,′_ infixr 2 _×_ ------------------------------------------------------------------------ -- Definition record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public syntax Σ A (λ x → B) = Σ[ x ∶ A ] B ∃ : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b) ∃ = Σ _ _×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b) A × B = Σ[ x ∶ A ] B _,′_ : ∀ {a b} {A : Set a} {B : Set b} → A → B → A × B _,′_ = _,_
{ "alphanum_fraction": 0.4346349745, "avg_line_length": 19.6333333333, "ext": "agda", "hexsha": "adecd5911e729fce8fbb9dc353b6bdc1f99df86b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Common/Product.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Common/Product.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Common/Product.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 233, "size": 589 }
-- Andreas, 2011-10-02 module NotApplyingInDontCareTriggersInternalError where import Common.Irrelevance postulate Val : Set App : Val -> Val -> Val -> Set Rel = Val -> Val -> Set Transitive : Rel → Set Transitive R = ∀ {t1 t2 t3} → R t1 t2 → R t2 t3 → R t1 t3 postulate LeftReflexive : Rel → Set RightReflexive : Rel → Set record PP (R : Rel) : Set where constructor pp field .leftRefl : LeftReflexive R .rightRefl : RightReflexive R .trans : Transitive R open PP public record Those (P : Val → Set)(R : Rel)(P' : Val → Set) : Set where constructor those field B : Val B' : Val PB : P B PB' : P' B' RBB' : R B B' Fam : Rel → Set1 Fam AA = ∀ {a a'} → .(AA a a') → Rel FamTrans : {AA : Rel}.(TA : Transitive AA)(FF : Fam AA) → Set FamTrans {AA = AA} TA FF = ∀ {a1 a2 a3}(a12 : AA a1 a2)(a23 : AA a2 a3) → ∀ {b1 b2 b3}(b12 : FF a12 b1 b2)(b23 : FF a23 b2 b3) → FF (TA a12 a23) b1 b3 Π : (AA : Rel) → Fam AA → Rel Π AA FF g g' = ∀ {a a'} → .(a≼a' : AA a a') → Those (App g a) (FF a≼a') (App g' a') ΠTrans : {AA : Rel}(PA : PP AA){FF : Fam AA}(TF : FamTrans {AA = AA} (trans PA) FF) → Transitive (Π AA FF) ΠTrans (pp leftRefl rightRefl trans) TF f12 f23 a≼a' with (leftRefl a≼a') ... | a≼a with f12 a≼a | f23 a≼a' ΠTrans (pp leftRefl rightRefl trans) TF f12 f23 a≼a' | a≼a | those b1 b2 app1 app2 b1≼b2 | those b2' b3 app2' app3 b2'≼b3 = those b1 b3 app1 app3 ? -- This should not give the internal error: -- -- An internal error has occurred. Please report this as a bug. -- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:50 -- -- Instead it should complain that -- -- Variable leftRefl is declared irrelevant, so it cannot be used here -- when checking that the expression leftRefl a≼a' has type -- _141 leftRefl rightRefl trans TF f12 f23 a≼a'
{ "alphanum_fraction": 0.6205405405, "avg_line_length": 29.3650793651, "ext": "agda", "hexsha": "4710d17e2df971a0734d86f3fc1e6698bd82e234", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/Fail/NotApplyingInDontCareTriggersInternalError.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_path": "test/Fail/NotApplyingInDontCareTriggersInternalError.agda", "max_line_length": 147, "max_stars_count": 3, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Fail/NotApplyingInDontCareTriggersInternalError.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 731, "size": 1850 }
{- Proof of the Universal Property of Our Fold -} module FoldUniv where open import Function using (id) open import Data.Unit using (⊤ ; tt) public open import Data.Empty using (⊥) public open import Data.Sum using (_⊎_; [_,_]; inj₁ ; inj₂) public open import Data.Product open import Data.Nat using (ℕ) open import Data.Bool using (Bool) open import Data.List open import Data.List.Any as Any open import Data.Product open Any.Membership-≡ hiding (_⊆_) open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong) data PolyF : Set where Id : PolyF K1 : PolyF Kℕ : PolyF KB : PolyF _∔_ : (F : PolyF) → (G : PolyF) → PolyF _⋆_ : (F : PolyF) → (G : PolyF) → PolyF infixr 30 _⋆_ infixr 20 _∔_ ⟦_⟧ : PolyF → Set → Set ⟦_⟧ Id A = A ⟦_⟧ K1 A = ⊤ ⟦_⟧ Kℕ A = ℕ ⟦_⟧ KB A = Bool ⟦_⟧ (F ∔ G) A = ⟦ F ⟧ A ⊎ ⟦ G ⟧ A ⟦_⟧ (F ⋆ G) A = ⟦ F ⟧ A × ⟦ G ⟧ A fmap : ∀ {A B} F → (A → B) → ⟦ F ⟧ A → ⟦ F ⟧ B fmap Id f = f fmap K1 f = id fmap Kℕ f = id fmap KB f = id fmap (F ∔ G) f = Data.Sum.map (fmap F f) (fmap G f) fmap (F ⋆ G) f = Data.Product.map (fmap F f) (fmap G f) Algebras : List PolyF → Set → Set Algebras [] A = ⊤ Algebras (F ∷ Fs) A = (⟦ F ⟧ A → A) × Algebras Fs A extract : {F : PolyF} {Fs : List PolyF} {A : Set} → F ∈ Fs → Algebras Fs A → (⟦ F ⟧ A → A) extract (here refl) (f , _ ) = f extract (there f∈ ) (f , fs) = extract f∈ fs data μ (Fs : List PolyF) : Set where In : ∀ {F} → F ∈ Fs → ⟦ F ⟧ (μ Fs) → μ Fs mutual fold : ∀ Fs {A} → Algebras Fs A → μ Fs → A fold Fs fs (In {F} F∈ x) = extract F∈ fs (mapFold Fs fs F x) mapFold : (Fs : List PolyF) {A : Set} → Algebras Fs A → (G : PolyF) → ⟦ G ⟧ (μ Fs) → ⟦ G ⟧ A mapFold Fs fs Id x = fold Fs fs x mapFold Fs fs K1 b = b mapFold Fs fs Kℕ b = b mapFold Fs fs KB b = b mapFold Fs fs (G ∔ G') (inj₁ xs) = inj₁ (mapFold Fs fs G xs) mapFold Fs fs (G ∔ G') (inj₂ xs) = inj₂ (mapFold Fs fs G' xs) mapFold Fs fs (G ⋆ G') (xs , xs') = mapFold Fs fs G xs , mapFold Fs fs G' xs' mutual fold-universal : (Fs : List PolyF) → {A : Set} → (h : μ Fs → A) → (fs : Algebras Fs A) → (∀ F → (F∈ : F ∈ Fs) → ∀ xs → h (In F∈ xs) ≡ extract F∈ fs (fmap F h xs)) → (∀ xs → h xs ≡ fold Fs fs xs) fold-universal Fs h fs hom (In {F} F∈ xs) rewrite hom F F∈ xs = cong (extract F∈ fs) (mapFold-univ Fs F h fs hom xs) mapFold-univ : (Fs : List PolyF) (G : PolyF) → ∀ {A : Set} → (h : μ Fs → A) → (fs : Algebras Fs A) → (∀ F → (F∈ : F ∈ Fs) → ∀ xs → h (In F∈ xs) ≡ extract F∈ fs (fmap F h xs)) → (Gxs : ⟦ G ⟧ (μ Fs)) → fmap G h Gxs ≡ mapFold Fs fs G Gxs mapFold-univ Fs Id h fs hom xs = fold-universal Fs h fs hom xs mapFold-univ Fs K1 h fs hom tt = refl mapFold-univ Fs Kℕ h fs hom n = refl mapFold-univ Fs KB h fs hom b = refl mapFold-univ Fs (G₁ ∔ G₂) h fs hom (inj₁ x) = cong inj₁ (mapFold-univ Fs G₁ h fs hom x) mapFold-univ Fs (G₁ ∔ G₂) h fs hom (inj₂ y) = cong inj₂ (mapFold-univ Fs G₂ h fs hom y) mapFold-univ Fs (G₁ ⋆ G₂) h fs hom (x , y) rewrite mapFold-univ Fs G₁ h fs hom x | mapFold-univ Fs G₂ h fs hom y = refl
{ "alphanum_fraction": 0.5318567961, "avg_line_length": 33.6326530612, "ext": "agda", "hexsha": "614e289481b829188c5722d459438c403e453e37", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-06-23T16:31:02.000Z", "max_forks_repo_forks_event_min_datetime": "2017-04-08T15:45:08.000Z", "max_forks_repo_head_hexsha": "e3706dec65e186c64489ad45572d813daebddd3f", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "k0001/mrm", "max_forks_repo_path": "FoldUniv.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e3706dec65e186c64489ad45572d813daebddd3f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "k0001/mrm", "max_issues_repo_path": "FoldUniv.agda", "max_line_length": 88, "max_stars_count": 10, "max_stars_repo_head_hexsha": "e3706dec65e186c64489ad45572d813daebddd3f", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "k0001/mrm", "max_stars_repo_path": "FoldUniv.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-25T00:14:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-07T15:26:33.000Z", "num_tokens": 1342, "size": 3296 }
module Structures where open import Category.Functor using (RawFunctor ; module RawFunctor) open import Category.Monad using (module RawMonad) open import Data.Maybe using (Maybe) renaming (monad to MaybeMonad) open import Data.Nat using (ℕ) open import Data.Vec as V using (Vec) import Data.Vec.Properties as VP open import Function using (_∘_ ; flip ; id) open import Function.Equality using (_⟶_ ; _⇨_ ; _⟨$⟩_) open import Relation.Binary using (_Preserves_⟶_) open import Relation.Binary.PropositionalEquality as P using (_≗_ ; _≡_ ; refl ; module ≡-Reasoning) open import Generic using (sequenceV) record IsFunctor (F : Set → Set) (f : {α β : Set} → (α → β) → F α → F β) : Set₁ where field cong : {α β : Set} → f {α} {β} Preserves _≗_ ⟶ _≗_ identity : {α : Set} → f {α} id ≗ id composition : {α β γ : Set} → (g : β → γ) → (h : α → β) → f (g ∘ h) ≗ f g ∘ f h isCongruence : {α β : Set} → (P.setoid α ⇨ P.setoid β) ⟶ P.setoid (F α) ⇨ P.setoid (F β) isCongruence {α} {β} = record { _⟨$⟩_ = λ g → record { _⟨$⟩_ = f (_⟨$⟩_ g) ; cong = P.cong (f (_⟨$⟩_ g)) } ; cong = λ {g} {h} g≗h {x} x≡y → P.subst (λ z → f (_⟨$⟩_ g) x ≡ f (_⟨$⟩_ h) z) x≡y (cong (λ _ → g≗h refl) x) } record Functor (f : Set → Set) : Set₁ where field rawfunctor : RawFunctor f isFunctor : IsFunctor f (RawFunctor._<$>_ rawfunctor) open RawFunctor rawfunctor public open IsFunctor isFunctor public record IsShaped (S : Set) (C : Set → S → Set) (arity : S → ℕ) (content : {α : Set} {s : S} → C α s → Vec α (arity s)) (fill : {α : Set} → (s : S) → Vec α (arity s) → C α s) : Set₁ where field content-fill : {α : Set} {s : S} → (c : C α s) → fill s (content c) ≡ c fill-content : {α : Set} → (s : S) → (v : Vec α (arity s)) → content (fill s v) ≡ v fmap : {α β : Set} → (f : α → β) → {s : S} → C α s → C β s fmap f {s} c = fill s (V.map f (content c)) isFunctor : (s : S) → IsFunctor (flip C s) (λ f → fmap f) isFunctor s = record { cong = λ g≗h c → P.cong (fill s) (VP.map-cong g≗h (content c)) ; identity = λ c → begin fill s (V.map id (content c)) ≡⟨ P.cong (fill s) (VP.map-id (content c)) ⟩ fill s (content c) ≡⟨ content-fill c ⟩ c ∎ ; composition = λ g h c → P.cong (fill s) (begin V.map (g ∘ h) (content c) ≡⟨ VP.map-∘ g h (content c) ⟩ V.map g (V.map h (content c)) ≡⟨ P.cong (V.map g) (P.sym (fill-content s (V.map h (content c)))) ⟩ V.map g (content (fill s (V.map h (content c)))) ∎) } where open ≡-Reasoning fmap-content : {α β : Set} → (f : α → β) → {s : S} → content {β} {s} ∘ fmap f ≗ V.map f ∘ content fmap-content f c = fill-content _ (V.map f (content c)) fill-fmap : {α β : Set} → (f : α → β) → (s : S) → fmap f ∘ fill s ≗ fill s ∘ V.map f fill-fmap f s v = P.cong (fill s ∘ V.map f) (fill-content s v) sequence : {α : Set} {s : S} → C (Maybe α) s → Maybe (C α s) sequence {s = s} c = fill s <$> sequenceV (content c) where open RawMonad MaybeMonad record Shaped (S : Set) (C : Set → S → Set) : Set₁ where field arity : S → ℕ content : {α : Set} {s : S} → C α s → Vec α (arity s) fill : {α : Set} → (s : S) → Vec α (arity s) → C α s isShaped : IsShaped S C arity content fill open IsShaped isShaped public
{ "alphanum_fraction": 0.5392930178, "avg_line_length": 38.8977272727, "ext": "agda", "hexsha": "10abd42e1b9a5e13c6cad07fdedf912952c1a4cb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jvoigtlaender/bidiragda", "max_forks_repo_path": "Structures.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jvoigtlaender/bidiragda", "max_issues_repo_path": "Structures.agda", "max_line_length": 112, "max_stars_count": null, "max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jvoigtlaender/bidiragda", "max_stars_repo_path": "Structures.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1296, "size": 3423 }
{-# OPTIONS --cubical --safe #-} module Control.Monad.Levels where open import Control.Monad.Levels.Definition public
{ "alphanum_fraction": 0.7520661157, "avg_line_length": 17.2857142857, "ext": "agda", "hexsha": "33f74bef966f3a5384cde3ae0a9fcac1c7573ca7", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Control/Monad/Levels.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Control/Monad/Levels.agda", "max_line_length": 50, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Control/Monad/Levels.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 26, "size": 121 }
open import Agda.Builtin.Nat open import Agda.Builtin.FromNat open import Agda.Builtin.Unit instance NumberNat : Number Nat Number.Constraint NumberNat _ = ⊤ fromNat {{NumberNat}} n = n open import Issue2641.Import
{ "alphanum_fraction": 0.7678571429, "avg_line_length": 18.6666666667, "ext": "agda", "hexsha": "41aded02493931cc30dcbfac387ad894a7d6a1a2", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue2641.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue2641.agda", "max_line_length": 35, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue2641.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 64, "size": 224 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Sets.EquivalenceRelations open import Rings.Definition module Rings.Units.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} (R : Ring S _+_ _*_) where open import Rings.Units.Definition R open import Rings.Ideals.Definition R open Ring R open Setoid S open Equivalence eq unitImpliesGeneratedIdealEverything : {x : A} → Unit x → {y : A} → generatedIdealPred x y unitImpliesGeneratedIdealEverything {x} (a , xa=1) {y} = (a * y) , transitive *Associative (transitive (*WellDefined xa=1 reflexive) identIsIdent)
{ "alphanum_fraction": 0.7203647416, "avg_line_length": 32.9, "ext": "agda", "hexsha": "0b1dfbb1991d9ca6211a1be6f28d42678048a95c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Rings/Units/Lemmas.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Rings/Units/Lemmas.agda", "max_line_length": 146, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Rings/Units/Lemmas.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 202, "size": 658 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Functions.FunExtEquiv where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Data.Vec open import Cubical.Data.Nat private variable ℓ ℓ₁ ℓ₂ ℓ₃ : Level -- Function extensionality is an equivalence module _ {A : Type ℓ} {B : A → I → Type ℓ₁} {f : (x : A) → B x i0} {g : (x : A) → B x i1} where private fib : (p : PathP (λ i → ∀ x → B x i) f g) → fiber funExt p fib p = (funExt⁻ p , refl) funExt-fiber-isContr : ∀ p → (fi : fiber funExt p) → fib p ≡ fi funExt-fiber-isContr p (h , eq) i = (funExt⁻ (eq (~ i)) , λ j → eq (~ i ∨ j)) funExt-isEquiv : isEquiv funExt equiv-proof funExt-isEquiv p = (fib p , funExt-fiber-isContr p) funExtEquiv : (∀ x → PathP (B x) (f x) (g x)) ≃ PathP (λ i → ∀ x → B x i) f g funExtEquiv = (funExt , funExt-isEquiv) funExtPath : (∀ x → PathP (B x) (f x) (g x)) ≡ PathP (λ i → ∀ x → B x i) f g funExtPath = ua funExtEquiv funExtIso : Iso (∀ x → PathP (B x) (f x) (g x)) (PathP (λ i → ∀ x → B x i) f g) funExtIso = iso funExt funExt⁻ (λ x → refl {x = x}) (λ x → refl {x = x}) -- Function extensionality for binary functions funExt₂ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → I → Type ℓ₂} {f : (x : A) → (y : B x) → C x y i0} {g : (x : A) → (y : B x) → C x y i1} → ((x : A) (y : B x) → PathP (C x y) (f x y) (g x y)) → PathP (λ i → ∀ x y → C x y i) f g funExt₂ p i x y = p x y i -- Function extensionality for binary functions is an equivalence module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → I → Type ℓ₂} {f : (x : A) → (y : B x) → C x y i0} {g : (x : A) → (y : B x) → C x y i1} where private appl₂ : PathP (λ i → ∀ x y → C x y i) f g → ∀ x y → PathP (C x y) (f x y) (g x y) appl₂ eq x y i = eq i x y fib : (p : PathP (λ i → ∀ x y → C x y i) f g) → fiber funExt₂ p fib p = (appl₂ p , refl) funExt₂-fiber-isContr : ∀ p → (fi : fiber funExt₂ p) → fib p ≡ fi funExt₂-fiber-isContr p (h , eq) i = (appl₂ (eq (~ i)) , λ j → eq (~ i ∨ j)) funExt₂-isEquiv : isEquiv funExt₂ equiv-proof funExt₂-isEquiv p = (fib p , funExt₂-fiber-isContr p) funExt₂Equiv : (∀ x y → PathP (C x y) (f x y) (g x y)) ≃ (PathP (λ i → ∀ x y → C x y i) f g) funExt₂Equiv = (funExt₂ , funExt₂-isEquiv) funExt₂Path : (∀ x y → PathP (C x y) (f x y) (g x y)) ≡ (PathP (λ i → ∀ x y → C x y i) f g) funExt₂Path = ua funExt₂Equiv -- Function extensionality for ternary functions funExt₃ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂} {D : (x : A) → (y : B x) → C x y → I → Type ℓ₃} {f : (x : A) → (y : B x) → (z : C x y) → D x y z i0} {g : (x : A) → (y : B x) → (z : C x y) → D x y z i1} → ((x : A) (y : B x) (z : C x y) → PathP (D x y z) (f x y z) (g x y z)) → PathP (λ i → ∀ x y z → D x y z i) f g funExt₃ p i x y z = p x y z i -- Function extensionality for ternary functions is an equivalence module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂} {D : (x : A) → (y : B x) → C x y → I → Type ℓ₃} {f : (x : A) → (y : B x) → (z : C x y) → D x y z i0} {g : (x : A) → (y : B x) → (z : C x y) → D x y z i1} where private appl₃ : PathP (λ i → ∀ x y z → D x y z i) f g → ∀ x y z → PathP (D x y z) (f x y z) (g x y z) appl₃ eq x y z i = eq i x y z fib : (p : PathP (λ i → ∀ x y z → D x y z i) f g) → fiber funExt₃ p fib p = (appl₃ p , refl) funExt₃-fiber-isContr : ∀ p → (fi : fiber funExt₃ p) → fib p ≡ fi funExt₃-fiber-isContr p (h , eq) i = (appl₃ (eq (~ i)) , λ j → eq (~ i ∨ j)) funExt₃-isEquiv : isEquiv funExt₃ equiv-proof funExt₃-isEquiv p = (fib p , funExt₃-fiber-isContr p) funExt₃Equiv : (∀ x y z → PathP (D x y z) (f x y z) (g x y z)) ≃ (PathP (λ i → ∀ x y z → D x y z i) f g) funExt₃Equiv = (funExt₃ , funExt₃-isEquiv) funExt₃Path : (∀ x y z → PathP (D x y z) (f x y z) (g x y z)) ≡ (PathP (λ i → ∀ x y z → D x y z i) f g) funExt₃Path = ua funExt₃Equiv -- n-ary non-dependent funext nAryFunExt : (n : ℕ) {X : Type ℓ} {Y : I → Type ℓ₁} (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1)) → ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs)) → PathP (λ i → nAryOp n X (Y i)) fX fY nAryFunExt zero fX fY p = p [] nAryFunExt (suc n) fX fY p i x = nAryFunExt n (fX x) (fY x) (λ xs → p (x ∷ xs)) i -- n-ary funext⁻ nAryFunExt⁻ : (n : ℕ) {X : Type ℓ} {Y : I → Type ℓ₁} (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1)) → PathP (λ i → nAryOp n X (Y i)) fX fY → ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs)) nAryFunExt⁻ zero fX fY p [] = p nAryFunExt⁻ (suc n) fX fY p (x ∷ xs) = nAryFunExt⁻ n (fX x) (fY x) (λ i → p i x) xs nAryFunExtEquiv : (n : ℕ) {X : Type ℓ} {Y : I → Type ℓ₁} (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1)) → ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs)) ≃ PathP (λ i → nAryOp n X (Y i)) fX fY nAryFunExtEquiv n {X} {Y} fX fY = isoToEquiv (iso (nAryFunExt n fX fY) (nAryFunExt⁻ n fX fY) (linv n fX fY) (rinv n fX fY)) where linv : (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1)) (p : PathP (λ i → nAryOp n X (Y i)) fX fY) → nAryFunExt n fX fY (nAryFunExt⁻ n fX fY p) ≡ p linv zero fX fY p = refl linv (suc n) fX fY p i j x = linv n (fX x) (fY x) (λ k → p k x) i j rinv : (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1)) (p : (xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs)) → nAryFunExt⁻ n fX fY (nAryFunExt n fX fY p) ≡ p rinv zero fX fY p i [] = p [] rinv (suc n) fX fY p i (x ∷ xs) = rinv n (fX x) (fY x) (λ ys i → p (x ∷ ys) i) i xs
{ "alphanum_fraction": 0.5119228818, "avg_line_length": 43.8, "ext": "agda", "hexsha": "42ec8f7af384fd7e893cfe09a409f0b3c0d7b963", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "RobertHarper/cubical", "max_forks_repo_path": "Cubical/Functions/FunExtEquiv.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "RobertHarper/cubical", "max_issues_repo_path": "Cubical/Functions/FunExtEquiv.agda", "max_line_length": 106, "max_stars_count": null, "max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "RobertHarper/cubical", "max_stars_repo_path": "Cubical/Functions/FunExtEquiv.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2715, "size": 5913 }
{-# OPTIONS --without-K #-} module Examples.New where open import Data.Empty using (⊥) open import Data.Unit using (⊤; tt) open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]′) open import Data.Product using (_×_; _,_; proj₁; proj₂) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; subst) open import Singleton open import PiPointedFrac ------------------------------------------------------------------------------ -- Conventional PI examples 𝔹 : 𝕌 𝔹 = 𝟙 +ᵤ 𝟙 𝔹² : 𝕌 𝔹² = 𝔹 ×ᵤ 𝔹 𝔽 𝕋 : ⟦ 𝔹 ⟧ 𝔽 = inj₁ tt 𝕋 = inj₂ tt NOT : 𝔹 ⟷ 𝔹 NOT = swap₊ NEG1 NEG2 NEG3 NEG4 NEG5 : 𝔹 ⟷ 𝔹 NEG1 = swap₊ NEG2 = id⟷ ⊚ NOT NEG3 = NOT ⊚ NOT ⊚ NOT NEG4 = NOT ⊚ id⟷ NEG5 = uniti⋆l ⊚ swap⋆ ⊚ (NOT ⊗ id⟷) ⊚ swap⋆ ⊚ unite⋆l NEG6 = uniti⋆r ⊚ (NOT ⊗ id⟷) ⊚ unite⋆r CONTROL : {A : 𝕌} → (A ⟷ A) → (𝔹 ×ᵤ A ⟷ 𝔹 ×ᵤ A) CONTROL f = dist ⊚ (id⟷ ⊕ (id⟷ ⊗ f)) ⊚ factor CNOT : 𝔹² ⟷ 𝔹² CNOT = CONTROL NOT TOFFOLI : 𝔹 ×ᵤ 𝔹² ⟷ 𝔹 ×ᵤ 𝔹² TOFFOLI = CONTROL (CONTROL NOT) PERES : (𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹 ⟷ (𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹 PERES = (id⟷ ⊗ NOT) ⊚ assocr⋆ ⊚ (id⟷ ⊗ swap⋆) ⊚ TOFFOLI ⊚ (id⟷ ⊗ (NOT ⊗ id⟷)) ⊚ TOFFOLI ⊚ (id⟷ ⊗ swap⋆) ⊚ (id⟷ ⊗ (NOT ⊗ id⟷)) ⊚ TOFFOLI ⊚ (id⟷ ⊗ (NOT ⊗ id⟷)) ⊚ assocl⋆ SWAP12 SWAP23 SWAP13 ROTL ROTR : 𝟙 +ᵤ 𝟙 +ᵤ 𝟙 ⟷ 𝟙 +ᵤ 𝟙 +ᵤ 𝟙 SWAP12 = assocl₊ ⊚ (swap₊ ⊕ id⟷) ⊚ assocr₊ SWAP23 = id⟷ ⊕ swap₊ SWAP13 = SWAP23 ⊚ SWAP12 ⊚ SWAP23 ROTR = SWAP12 ⊚ SWAP23 ROTL = SWAP13 ⊚ SWAP23 ------------------------------------------------------------------------------ -- Pointed versions ∙TOFFOLI-1 : ∀ {b₁ b₂} → (𝔹 ×ᵤ 𝔹²) # (𝔽 , (b₁ , b₂)) ∙⟶ (𝔹 ×ᵤ 𝔹²) # (𝔽 , (b₁ , b₂)) ∙TOFFOLI-1 = ∙c TOFFOLI ∙TOFFOLI-2 : ∀ {b} → (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝔽 , b)) ∙⟶ (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝔽 , b)) ∙TOFFOLI-2 = ∙c TOFFOLI ∙TOFFOLI-3 : ∀ {b} → (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝕋 , b)) ∙⟶ (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝕋 , eval swap₊ b)) ∙TOFFOLI-3 = ∙c TOFFOLI -- Ancilla examples from literature -- Fig. 2 in Ricercar fig2a : 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ⟷ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 fig2a = CONTROL (CONTROL (CONTROL NOT)) -- first write the circuit with the additional ancilla fig2b' : ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) ⟷ ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) fig2b' = (swap⋆ ⊗ id⟷) ⊚ assocr⋆ ⊚ (swap⋆ ⊗ id⟷) ⊚ assocr⋆ ⊚ (id⟷ ⊗ CONTROL (CONTROL NOT)) -- first ccnot ⊚ assocl⋆ ⊚ (swap⋆ ⊗ id⟷) ⊚ assocl⋆ ⊚ (swap⋆ ⊗ id⟷) -- move it back ⊚ (assocl⋆ ⊗ id⟷) ⊚ assocr⋆ ⊚ (id⟷ ⊗ swap⋆) ⊚ (id⟷ ⊗ CONTROL (CONTROL NOT)) -- second ccnot ⊚ (id⟷ ⊗ swap⋆) ⊚ assocl⋆ ⊚ (assocr⋆ ⊗ id⟷) -- move it back ⊚ (swap⋆ ⊗ id⟷) ⊚ assocr⋆ ⊚ (swap⋆ ⊗ id⟷) ⊚ assocr⋆ ⊚ (id⟷ ⊗ CONTROL (CONTROL NOT)) -- third ccnot ⊚ assocl⋆ ⊚ (swap⋆ ⊗ id⟷) ⊚ assocl⋆ ⊚ (swap⋆ ⊗ id⟷) -- move it back -- then prove a theorem that specifies its semantics fig2b'≡ : (a b c d : ⟦ 𝔹 ⟧) → proj₂ (eval fig2b' ((a , b , c , d) , 𝔽)) ≡ 𝔽 fig2b'≡ a (inj₁ tt) c d = refl fig2b'≡ (inj₁ tt) (inj₂ tt) c d = refl fig2b'≡ (inj₂ tt) (inj₂ tt) c d = refl -- generalize above? Method: -- for 'dist' to evaluate, need to split on b first -- in first case, split on e (same reason) -- in second case, split on a (same reason) -- split on e -- split on e foo : (a b c d e : ⟦ 𝔹 ⟧) → proj₂ (eval fig2b' ((a , b , c , d) , e)) ≡ e foo a (inj₁ x) c d (inj₁ x₁) = refl foo a (inj₁ x) c d (inj₂ y) = refl foo (inj₁ x) (inj₂ y) c d (inj₁ x₁) = refl foo (inj₁ x) (inj₂ y) c d (inj₂ y₁) = refl foo (inj₂ y₁) (inj₂ y) c d (inj₁ x) = refl foo (inj₂ y₁) (inj₂ y) c d (inj₂ y₂) = refl {-- postulate -- boring... tensor4 : ∀ {a b c d e} → (● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ]) ×ᵤ ● 𝔹 [ e ] ⟷ ● ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) [ (a , b , c , d) , e ] itensor4 : ∀ {a b c d e} → ● ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) [ (a , b , c , d) , e ] ⟷ (● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ]) ×ᵤ ● 𝔹 [ e ] --} -- now lift it {-- fig2b : ∀ {a b c d e} → let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e) in ● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ] ⟷ ● 𝔹 [ x ] ×ᵤ ● 𝔹 [ y ] ×ᵤ ● 𝔹 [ z ] ×ᵤ ● 𝔹 [ w ] fig2b {a} {b} {c} {d} {e} = let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e) in uniti⋆r ⊚ -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝟙[e] (id⟷ ⊗ η e) ⊚ -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × (●𝔹[e] x ●1/𝔹[e]) assocl⋆ ⊚ -- ((●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝔹[e) x ●1/𝔹[e] (tensor4 ⊗ id⟷) ⊚ -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (a,b,c,d),e ] x ●1/𝔹[e] (lift fig2b' ⊗ id⟷) ⊚ -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e] (((== id⟷ (cong (λ H → ((x , y , z , w)) , H) (foo a b c d e))) ⊗ id⟷)) ⊚ -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e] (itensor4 ⊗ id⟷) ⊚ -- ((●𝔹[x] × ●𝔹[y] × ●𝔹[z] × ●𝔹[w]) × ●𝔹[e]) x ●1/𝔹[e] assocr⋆ ⊚ (id⟷ ⊗ ε e) ⊚ unite⋆r --} {-- -- This is mostly to show that == is really 'subst' in hiding. fig2b₂ : ∀ {a b c d e} → let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e) in ● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ] ⟷ ● 𝔹 [ x ] ×ᵤ ● 𝔹 [ y ] ×ᵤ ● 𝔹 [ z ] ×ᵤ ● 𝔹 [ w ] fig2b₂ {a} {b} {c} {d} {e} = let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e) in uniti⋆r ⊚ -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝟙[e] (id⟷ ⊗ η e) ⊚ -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × (●𝔹[e] x ●1/𝔹[e]) assocl⋆ ⊚ -- ((●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝔹[e) x ●1/𝔹[e] (tensor4 ⊗ id⟷) ⊚ -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (a,b,c,d),e ] x ●1/𝔹[e] (lift fig2b' ⊗ id⟷) ⊚ -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e] (itensor4 ⊗ id⟷) ⊚ -- ((●𝔹[x] × ●𝔹[y] × ●𝔹[z] × ●𝔹[w]) × ●𝔹[e]) x ●1/𝔹[e] assocr⋆ ⊚ (id⟷ ⊗ (subst (λ ee → ● 𝔹 [ ee ] ×ᵤ 𝟙/● 𝔹 [ e ] ⟷ 𝟙) (sym (foo a b c d e)) (ε e))) ⊚ unite⋆r --} -- Examples infixr 2 _→⟨_⟩_ infix 3 _□ _→⟨_⟩_ : (T₁ : ∙𝕌) → {T₂ T₃ : ∙𝕌} → (T₁ ∙⟶ T₂) → (T₂ ∙⟶ T₃) → (T₁ ∙⟶ T₃) _ →⟨ α ⟩ β = α ∙⊚ β _□ : (T : ∙𝕌) → {T : ∙𝕌} → (T ∙⟶ T) _□ T = ∙id⟷ zigzag : ∀ b → 𝔹 # b ∙⟶ 𝔹 # b zigzag b = (𝔹 # b) →⟨ (∙c uniti⋆l) ⟩ (𝟙 ×ᵤ 𝔹) # (tt , b) →⟨ ∙times# ⟩ (𝟙 # tt) ∙×ᵤ (𝔹 # b) →⟨ ∙id⟷ ∙⊗ return (𝔹 # b) ⟩ (𝟙 # tt) ∙×ᵤ (Singᵤ (𝔹 # b)) →⟨ η (𝔹 # b) ∙⊗ ∙id⟷ ⟩ ((Singᵤ (𝔹 # b)) ∙×ᵤ (Recipᵤ (𝔹 # b))) ∙×ᵤ (Singᵤ (𝔹 # b)) →⟨ ∙assocr⋆ ⟩ Singᵤ (𝔹 # b) ∙×ᵤ (Recipᵤ (𝔹 # b) ∙×ᵤ (Singᵤ (𝔹 # b))) →⟨ ∙id⟷ ∙⊗ ∙swap⋆ ⟩ Singᵤ (𝔹 # b) ∙×ᵤ ((Singᵤ (𝔹 # b)) ∙×ᵤ (Recipᵤ (𝔹 # b))) →⟨ ∙id⟷ ∙⊗ ε (𝔹 # b) ⟩ Singᵤ (𝔹 # b) ∙×ᵤ (𝟙 # tt) →⟨ extract (𝔹 # b) ∙⊗ ∙id⟷ ⟩ (𝔹 # b) ∙×ᵤ (𝟙 # tt) →⟨ ∙#times ⟩ (𝔹 ×ᵤ 𝟙) # (b , tt) →⟨ ∙c unite⋆r ⟩ (𝔹 # b) □ test1 : proj₁ (∙eval (zigzag 𝔽)) 𝔽 ≡ 𝔽 test1 = proj₂ (∙eval (zigzag 𝔽)) test2 : proj₁ (∙eval (zigzag 𝕋)) 𝕋 ≡ 𝕋 test2 = proj₂ (∙eval (zigzag 𝕋)) ------------------------------------------------------------------------------
{ "alphanum_fraction": 0.3937526264, "avg_line_length": 28.4422310757, "ext": "agda", "hexsha": "96b2706510fd44e19a74590ac66951ea6ad32504", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "fracGC/Examples/New.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "fracGC/Examples/New.agda", "max_line_length": 92, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "fracGC/Examples/New.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 4231, "size": 7139 }
------------------------------------------------------------------------ -- Terminating parser "combinator" interface ------------------------------------------------------------------------ -- Use RecursiveDescent.Hybrid.Simple to actually run the parsers. module RecursiveDescent.Hybrid where open import RecursiveDescent.Index import RecursiveDescent.Hybrid.Type as P open P public using (Parser; Grammar) open import Data.Bool open import Data.Product.Record open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- Exported combinators infix 60 !_ infixl 40 _∣_ infixl 10 _>>=_ _!>>=_ !_ : forall {tok nt e c r} -> nt (e , c) r -> Parser tok nt (e , step c) r !_ = P.!_ symbol : forall {tok nt} -> Parser tok nt 0I tok symbol = P.symbol return : forall {tok nt r} -> r -> Parser tok nt 1I r return = P.return fail : forall {tok nt r} -> Parser tok nt 0I r fail = P.fail _>>=_ : forall {tok nt e₁ c₁ i₂ r₁ r₂} -> let i₁ = (e₁ , c₁) in Parser tok nt i₁ r₁ -> (r₁ -> Parser tok nt i₂ r₂) -> Parser tok nt (i₁ ·I i₂) r₂ _>>=_ {e₁ = true } = P._?>>=_ _>>=_ {e₁ = false} = P._!>>=_ -- If the first parser is guaranteed to consume something, then the -- second parser's index can depend on the result of the first parser. _!>>=_ : forall {tok nt c₁ r₁ r₂} {i₂ : r₁ -> Index} -> let i₁ = (false , c₁) in Parser tok nt i₁ r₁ -> ((x : r₁) -> Parser tok nt (i₂ x) r₂) -> Parser tok nt (i₁ ·I 1I) r₂ _!>>=_ = P._!>>=_ _∣_ : forall {tok nt e₁ c₁ i₂ r} -> let i₁ = (e₁ , c₁) in Parser tok nt i₁ r -> Parser tok nt i₂ r -> Parser tok nt (i₁ ∣I i₂) r _∣_ = P.alt _ _ cast : forall {tok nt e₁ e₂ c₁ c₂ r} -> e₁ ≡ e₂ -> c₁ ≡ c₂ -> Parser tok nt (e₁ , c₁) r -> Parser tok nt (e₂ , c₂) r cast refl refl p = p
{ "alphanum_fraction": 0.5351812367, "avg_line_length": 29.3125, "ext": "agda", "hexsha": "87f21ff8cee819bb52bacfdeacff21ee8fb52d57", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "misc/RecursiveDescent/Hybrid.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_path": "misc/RecursiveDescent/Hybrid.agda", "max_line_length": 72, "max_stars_count": 7, "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_path": "misc/RecursiveDescent/Hybrid.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "num_tokens": 586, "size": 1876 }
------------------------------------------------------------------------------ -- Testing Agda internal term: @Lam@ ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- The following conjecture uses the internal Agda term @Lam@. module Agda.InternalTerms.LamTerm where postulate D : Set ∃ : (D → Set) → Set -- The existential quantifier type on D. A : D → Set postulate ∃-intro : (t : D) → A t → ∃ A {-# ATP prove ∃-intro #-}
{ "alphanum_fraction": 0.4334898279, "avg_line_length": 30.4285714286, "ext": "agda", "hexsha": "a835695c722be983b033c561fa96399078cdcd9b", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "test/Succeed/fol-theorems/Agda/InternalTerms/LamTerm.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "test/Succeed/fol-theorems/Agda/InternalTerms/LamTerm.agda", "max_line_length": 78, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "test/Succeed/fol-theorems/Agda/InternalTerms/LamTerm.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 137, "size": 639 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Lexicographic products of binary relations ------------------------------------------------------------------------ -- The definition of lexicographic product used here is suitable if -- the left-hand relation is a strict partial order. module Relation.Binary.Product.StrictLex where open import Function open import Data.Product open import Data.Sum open import Data.Empty open import Level open import Relation.Nullary.Product open import Relation.Nullary.Sum open import Relation.Binary open import Relation.Binary.Consequences open import Relation.Binary.Product.Pointwise as Pointwise using (_×-Rel_) open import Relation.Nullary module _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂} where ×-Lex : (_≈₁_ _<₁_ : Rel A₁ ℓ₁) → (_≤₂_ : Rel A₂ ℓ₂) → Rel (A₁ × A₂) _ ×-Lex _≈₁_ _<₁_ _≤₂_ = (_<₁_ on proj₁) -⊎- (_≈₁_ on proj₁) -×- (_≤₂_ on proj₂) -- Some properties which are preserved by ×-Lex (under certain -- assumptions). ×-reflexive : ∀ _≈₁_ _∼₁_ {_≈₂_ : Rel A₂ ℓ₂} _≤₂_ → _≈₂_ ⇒ _≤₂_ → (_≈₁_ ×-Rel _≈₂_) ⇒ (×-Lex _≈₁_ _∼₁_ _≤₂_) ×-reflexive _ _ _ refl₂ = λ x≈y → inj₂ (proj₁ x≈y , refl₂ (proj₂ x≈y)) _×-irreflexive_ : ∀ {_≈₁_ _<₁_} → Irreflexive _≈₁_ _<₁_ → ∀ {_≈₂_ _<₂_ : Rel A₂ ℓ₂} → Irreflexive _≈₂_ _<₂_ → Irreflexive (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_) (ir₁ ×-irreflexive ir₂) x≈y (inj₁ x₁<y₁) = ir₁ (proj₁ x≈y) x₁<y₁ (ir₁ ×-irreflexive ir₂) x≈y (inj₂ x≈<y) = ir₂ (proj₂ x≈y) (proj₂ x≈<y) ×-transitive : ∀ {_≈₁_ _<₁_} → IsEquivalence _≈₁_ → _<₁_ Respects₂ _≈₁_ → Transitive _<₁_ → ∀ {_≤₂_} → Transitive _≤₂_ → Transitive (×-Lex _≈₁_ _<₁_ _≤₂_) ×-transitive {_≈₁_ = _≈₁_} {_<₁_ = _<₁_} eq₁ resp₁ trans₁ {_≤₂_ = _≤₂_} trans₂ {x} {y} {z} = trans {x} {y} {z} where module Eq₁ = IsEquivalence eq₁ trans : Transitive (×-Lex _≈₁_ _<₁_ _≤₂_) trans (inj₁ x₁<y₁) (inj₁ y₁<z₁) = inj₁ (trans₁ x₁<y₁ y₁<z₁) trans (inj₁ x₁<y₁) (inj₂ y≈≤z) = inj₁ (proj₁ resp₁ (proj₁ y≈≤z) x₁<y₁) trans (inj₂ x≈≤y) (inj₁ y₁<z₁) = inj₁ (proj₂ resp₁ (Eq₁.sym $ proj₁ x≈≤y) y₁<z₁) trans (inj₂ x≈≤y) (inj₂ y≈≤z) = inj₂ ( Eq₁.trans (proj₁ x≈≤y) (proj₁ y≈≤z) , trans₂ (proj₂ x≈≤y) (proj₂ y≈≤z) ) ×-antisymmetric : ∀ {_≈₁_ _<₁_} → Symmetric _≈₁_ → Irreflexive _≈₁_ _<₁_ → Asymmetric _<₁_ → ∀ {_≈₂_ _≤₂_ : Rel A₂ ℓ₂} → Antisymmetric _≈₂_ _≤₂_ → Antisymmetric (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _≤₂_) ×-antisymmetric {_≈₁_ = _≈₁_} {_<₁_ = _<₁_} sym₁ irrefl₁ asym₁ {_≈₂_ = _≈₂_} {_≤₂_ = _≤₂_} antisym₂ {x} {y} = antisym {x} {y} where antisym : Antisymmetric (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _≤₂_) antisym (inj₁ x₁<y₁) (inj₁ y₁<x₁) = ⊥-elim $ asym₁ x₁<y₁ y₁<x₁ antisym (inj₁ x₁<y₁) (inj₂ y≈≤x) = ⊥-elim $ irrefl₁ (sym₁ $ proj₁ y≈≤x) x₁<y₁ antisym (inj₂ x≈≤y) (inj₁ y₁<x₁) = ⊥-elim $ irrefl₁ (sym₁ $ proj₁ x≈≤y) y₁<x₁ antisym (inj₂ x≈≤y) (inj₂ y≈≤x) = proj₁ x≈≤y , antisym₂ (proj₂ x≈≤y) (proj₂ y≈≤x) ×-asymmetric : ∀ {_≈₁_ _<₁_} → Symmetric _≈₁_ → _<₁_ Respects₂ _≈₁_ → Asymmetric _<₁_ → ∀ {_<₂_} → Asymmetric _<₂_ → Asymmetric (×-Lex _≈₁_ _<₁_ _<₂_) ×-asymmetric {_≈₁_ = _≈₁_} {_<₁_ = _<₁_} sym₁ resp₁ asym₁ {_<₂_ = _<₂_} asym₂ {x} {y} = asym {x} {y} where irrefl₁ : Irreflexive _≈₁_ _<₁_ irrefl₁ = asym⟶irr resp₁ sym₁ asym₁ asym : Asymmetric (×-Lex _≈₁_ _<₁_ _<₂_) asym (inj₁ x₁<y₁) (inj₁ y₁<x₁) = asym₁ x₁<y₁ y₁<x₁ asym (inj₁ x₁<y₁) (inj₂ y≈<x) = irrefl₁ (sym₁ $ proj₁ y≈<x) x₁<y₁ asym (inj₂ x≈<y) (inj₁ y₁<x₁) = irrefl₁ (sym₁ $ proj₁ x≈<y) y₁<x₁ asym (inj₂ x≈<y) (inj₂ y≈<x) = asym₂ (proj₂ x≈<y) (proj₂ y≈<x) ×-≈-respects₂ : ∀ {_≈₁_ _<₁_} → IsEquivalence _≈₁_ → _<₁_ Respects₂ _≈₁_ → {_≈₂_ _<₂_ : Rel A₂ ℓ₂} → _<₂_ Respects₂ _≈₂_ → (×-Lex _≈₁_ _<₁_ _<₂_) Respects₂ (_≈₁_ ×-Rel _≈₂_) ×-≈-respects₂ {_≈₁_ = _≈₁_} {_<₁_ = _<₁_} eq₁ resp₁ {_≈₂_ = _≈₂_} {_<₂_ = _<₂_} resp₂ = (λ {x y z} → resp¹ {x} {y} {z}) , (λ {x y z} → resp² {x} {y} {z}) where _<_ = ×-Lex _≈₁_ _<₁_ _<₂_ open IsEquivalence eq₁ renaming (sym to sym₁; trans to trans₁) resp¹ : ∀ {x} → (_<_ x) Respects (_≈₁_ ×-Rel _≈₂_) resp¹ y≈y' (inj₁ x₁<y₁) = inj₁ (proj₁ resp₁ (proj₁ y≈y') x₁<y₁) resp¹ y≈y' (inj₂ x≈<y) = inj₂ ( trans₁ (proj₁ x≈<y) (proj₁ y≈y') , proj₁ resp₂ (proj₂ y≈y') (proj₂ x≈<y) ) resp² : ∀ {y} → (flip _<_ y) Respects (_≈₁_ ×-Rel _≈₂_) resp² x≈x' (inj₁ x₁<y₁) = inj₁ (proj₂ resp₁ (proj₁ x≈x') x₁<y₁) resp² x≈x' (inj₂ x≈<y) = inj₂ ( trans₁ (sym₁ $ proj₁ x≈x') (proj₁ x≈<y) , proj₂ resp₂ (proj₂ x≈x') (proj₂ x≈<y) ) ×-decidable : ∀ {_≈₁_ _<₁_} → Decidable _≈₁_ → Decidable _<₁_ → ∀ {_≤₂_} → Decidable _≤₂_ → Decidable (×-Lex _≈₁_ _<₁_ _≤₂_) ×-decidable dec-≈₁ dec-<₁ dec-≤₂ = λ x y → dec-<₁ (proj₁ x) (proj₁ y) ⊎-dec (dec-≈₁ (proj₁ x) (proj₁ y) ×-dec dec-≤₂ (proj₂ x) (proj₂ y)) ×-total : ∀ {_≈₁_ _<₁_} → Total _<₁_ → ∀ {_≤₂_} → Total (×-Lex _≈₁_ _<₁_ _≤₂_) ×-total {_≈₁_ = _≈₁_} {_<₁_ = _<₁_} total₁ {_≤₂_ = _≤₂_} = total where total : Total (×-Lex _≈₁_ _<₁_ _≤₂_) total x y with total₁ (proj₁ x) (proj₁ y) ... | inj₁ x₁<y₁ = inj₁ (inj₁ x₁<y₁) ... | inj₂ x₁>y₁ = inj₂ (inj₁ x₁>y₁) ×-compare : {_≈₁_ _<₁_ : Rel A₁ ℓ₁} → Symmetric _≈₁_ → Trichotomous _≈₁_ _<₁_ → {_≈₂_ _<₂_ : Rel A₂ ℓ₂} → Trichotomous _≈₂_ _<₂_ → Trichotomous (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_) ×-compare {_≈₁_} {_<₁_} sym₁ compare₁ {_≈₂_} {_<₂_} compare₂ = cmp where cmp″ : ∀ {x₁ y₁ x₂ y₂} → ¬ (x₁ <₁ y₁) → x₁ ≈₁ y₁ → ¬ (y₁ <₁ x₁) → Tri (x₂ <₂ y₂) (x₂ ≈₂ y₂) (y₂ <₂ x₂) → Tri (×-Lex _≈₁_ _<₁_ _<₂_ (x₁ , x₂) (y₁ , y₂)) ((_≈₁_ ×-Rel _≈₂_) (x₁ , x₂) (y₁ , y₂)) (×-Lex _≈₁_ _<₁_ _<₂_ (y₁ , y₂) (x₁ , x₂)) cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (tri< x₂<y₂ x₂≉y₂ x₂≯y₂) = tri< (inj₂ (x₁≈y₁ , x₂<y₂)) (x₂≉y₂ ∘ proj₂) [ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ] cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (tri> x₂≮y₂ x₂≉y₂ x₂>y₂) = tri> [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ] (x₂≉y₂ ∘ proj₂) (inj₂ (sym₁ x₁≈y₁ , x₂>y₂)) cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (tri≈ x₂≮y₂ x₂≈y₂ x₂≯y₂) = tri≈ [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ] (x₁≈y₁ , x₂≈y₂) [ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ] cmp′ : ∀ {x₁ y₁} → Tri (x₁ <₁ y₁) (x₁ ≈₁ y₁) (y₁ <₁ x₁) → ∀ x₂ y₂ → Tri (×-Lex _≈₁_ _<₁_ _<₂_ (x₁ , x₂) (y₁ , y₂)) ((_≈₁_ ×-Rel _≈₂_) (x₁ , x₂) (y₁ , y₂)) (×-Lex _≈₁_ _<₁_ _<₂_ (y₁ , y₂) (x₁ , x₂)) cmp′ (tri< x₁<y₁ x₁≉y₁ x₁≯y₁) x₂ y₂ = tri< (inj₁ x₁<y₁) (x₁≉y₁ ∘ proj₁) [ x₁≯y₁ , x₁≉y₁ ∘ sym₁ ∘ proj₁ ] cmp′ (tri> x₁≮y₁ x₁≉y₁ x₁>y₁) x₂ y₂ = tri> [ x₁≮y₁ , x₁≉y₁ ∘ proj₁ ] (x₁≉y₁ ∘ proj₁) (inj₁ x₁>y₁) cmp′ (tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁) x₂ y₂ = cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (compare₂ x₂ y₂) cmp : Trichotomous (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_) cmp (x₁ , x₂) (y₁ , y₂) = cmp′ (compare₁ x₁ y₁) x₂ y₂ -- Some collections of properties which are preserved by ×-Lex. _×-isPreorder_ : ∀ {_≈₁_ _∼₁_} → IsPreorder _≈₁_ _∼₁_ → ∀ {_≈₂_ _∼₂_} → IsPreorder _≈₂_ _∼₂_ → IsPreorder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _∼₁_ _∼₂_) _×-isPreorder_ {_≈₁_ = _≈₁_} {_∼₁_ = _∼₁_} pre₁ {_∼₂_ = _∼₂_} pre₂ = record { isEquivalence = Pointwise._×-isEquivalence_ (isEquivalence pre₁) (isEquivalence pre₂) ; reflexive = λ {x y} → ×-reflexive _≈₁_ _∼₁_ _∼₂_ (reflexive pre₂) {x} {y} ; trans = λ {x y z} → ×-transitive (isEquivalence pre₁) (∼-resp-≈ pre₁) (trans pre₁) {_≤₂_ = _∼₂_} (trans pre₂) {x} {y} {z} } where open IsPreorder _×-isStrictPartialOrder_ : ∀ {_≈₁_ _<₁_} → IsStrictPartialOrder _≈₁_ _<₁_ → ∀ {_≈₂_ _<₂_} → IsStrictPartialOrder _≈₂_ _<₂_ → IsStrictPartialOrder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_) _×-isStrictPartialOrder_ {_<₁_ = _<₁_} spo₁ {_<₂_ = _<₂_} spo₂ = record { isEquivalence = Pointwise._×-isEquivalence_ (isEquivalence spo₁) (isEquivalence spo₂) ; irrefl = λ {x y} → _×-irreflexive_ {_<₁_ = _<₁_} (irrefl spo₁) {_<₂_ = _<₂_} (irrefl spo₂) {x} {y} ; trans = λ {x y z} → ×-transitive {_<₁_ = _<₁_} (isEquivalence spo₁) (<-resp-≈ spo₁) (trans spo₁) {_≤₂_ = _<₂_} (trans spo₂) {x} {y} {z} ; <-resp-≈ = ×-≈-respects₂ (isEquivalence spo₁) (<-resp-≈ spo₁) (<-resp-≈ spo₂) } where open IsStrictPartialOrder _×-isStrictTotalOrder_ : ∀ {_≈₁_ _<₁_} → IsStrictTotalOrder _≈₁_ _<₁_ → ∀ {_≈₂_ _<₂_} → IsStrictTotalOrder _≈₂_ _<₂_ → IsStrictTotalOrder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_) _×-isStrictTotalOrder_ {_<₁_ = _<₁_} spo₁ {_<₂_ = _<₂_} spo₂ = record { isEquivalence = Pointwise._×-isEquivalence_ (isEquivalence spo₁) (isEquivalence spo₂) ; trans = λ {x y z} → ×-transitive {_<₁_ = _<₁_} (isEquivalence spo₁) (<-resp-≈ spo₁) (trans spo₁) {_≤₂_ = _<₂_} (trans spo₂) {x} {y} {z} ; compare = ×-compare (Eq.sym spo₁) (compare spo₁) (compare spo₂) ; <-resp-≈ = ×-≈-respects₂ (isEquivalence spo₁) (<-resp-≈ spo₁) (<-resp-≈ spo₂) } where open IsStrictTotalOrder -- "Packages" (e.g. preorders) can also be combined. _×-preorder_ : ∀ {p₁ p₂ p₃ p₄} → Preorder p₁ p₂ _ → Preorder p₃ p₄ _ → Preorder _ _ _ p₁ ×-preorder p₂ = record { isPreorder = isPreorder p₁ ×-isPreorder isPreorder p₂ } where open Preorder _×-strictPartialOrder_ : ∀ {s₁ s₂ s₃ s₄} → StrictPartialOrder s₁ s₂ _ → StrictPartialOrder s₃ s₄ _ → StrictPartialOrder _ _ _ s₁ ×-strictPartialOrder s₂ = record { isStrictPartialOrder = isStrictPartialOrder s₁ ×-isStrictPartialOrder isStrictPartialOrder s₂ } where open StrictPartialOrder _×-strictTotalOrder_ : ∀ {s₁ s₂ s₃ s₄} → StrictTotalOrder s₁ s₂ _ → StrictTotalOrder s₃ s₄ _ → StrictTotalOrder _ _ _ s₁ ×-strictTotalOrder s₂ = record { isStrictTotalOrder = isStrictTotalOrder s₁ ×-isStrictTotalOrder isStrictTotalOrder s₂ } where open StrictTotalOrder
{ "alphanum_fraction": 0.5056721751, "avg_line_length": 39.9821428571, "ext": "agda", "hexsha": "92c2a12239460832b65131b3179e0f4ebd1d1313", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Product/StrictLex.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Product/StrictLex.agda", "max_line_length": 82, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Product/StrictLex.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 5073, "size": 11195 }
record R : Set₁ where field A : Set {B} : Set {{C}} : Set open R r : R r = {!!} -- C-c C-c produced -- A r = {!!} -- B {r} = {!!} -- C {{r}} = {!!}
{ "alphanum_fraction": 0.3450292398, "avg_line_length": 10.6875, "ext": "agda", "hexsha": "7c45011ea3d36832d463288884ca2a84f7599a58", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Issue2287.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Issue2287.agda", "max_line_length": 21, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Issue2287.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 72, "size": 171 }
module Example where open import Bool open import Nat hiding (_==_; _+_) open import AC open Provable infix 40 _+_ infix 30 _==_ postulate X : Set _==_ : X -> X -> Set |0| : X _+_ : X -> X -> X refl : forall {x} -> x == x sym : forall {x y} -> x == y -> y == x trans : forall {x y z} -> x == y -> y == z -> x == z idL : forall {x} -> |0| + x == x idR : forall {x} -> x + |0| == x comm : forall {x y} -> x + y == y + x assoc : forall {x y z} -> x + (y + z) == (x + y) + z congL : forall {x y z} -> y == z -> x + y == x + z congR : forall {x y z} -> x == y -> x + z == y + z open Semantics _==_ _+_ |0| refl sym trans idL idR comm assoc congL congR thm = theorem 11 \a b c d e f g h i j k -> j ○ (k ○ (((((h ○ (e ○ ((e ○ (a ○ (a ○ (b ○ ((c ○ (((c ○ (d ○ d)) ○ (((d ○ (d ○ ((d ○ ((e ○ k) ○ ((((a ○ b) ○ (((h ○ (k ○ f)) ○ (((d ○ ((j ○ (h ○ (a ○ (((g ○ (k ○ g)) ○ ((b ○ (i ○ (i ○ ((i ○ ((k ○ (d ○ (b ○ ((b ○ ((h ○ k) ○ e)) ○ a)))) ○ j)) ○ a)))) ○ i)) ○ h)))) ○ (g ○ h))) ○ f) ○ h)) ○ b)) ○ f) ○ f))) ○ (e ○ d)))) ○ d) ○ c)) ○ c)) ○ b))))) ○ (((a ○ a) ○ k) ○ e)))) ○ c) ○ h) ○ (d ○ a)) ○ (c ○ a))) ≡ (j ○ (k ○ (((h ○ (h ○ e)) ○ ((((e ○ (((a ○ (b ○ ((b ○ c) ○ (((d ○ d) ○ ((d ○ d) ○ ((((e ○ (e ○ (f ○ f))) ○ (((a ○ ((b ○ (h ○ (k ○ (h ○ ((f ○ ((h ○ ((h ○ (a ○ ((k ○ (g ○ (b ○ (k ○ ((((a ○ (((e ○ h) ○ k) ○ b)) ○ b) ○ d) ○ j))))) ○ ((((a ○ i) ○ i) ○ i) ○ i)))) ○ ((g ○ h) ○ g))) ○ (j ○ d))) ○ f))))) ○ b)) ○ k) ○ d)) ○ d) ○ d))) ○ ((c ○ c) ○ c))))) ○ (a ○ a)) ○ a)) ○ (k ○ e)) ○ c) ○ d)) ○ a))) ○ (c ○ a) test = prove thm
{ "alphanum_fraction": 0.3003003003, "avg_line_length": 33.3, "ext": "agda", "hexsha": "2b89bb9e7c04dedf14871c9d39dc793325d59a53", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "benchmark/ac/Example.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "benchmark/ac/Example.agda", "max_line_length": 79, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "benchmark/ac/Example.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 884, "size": 1665 }
open import Level open import Ordinals module filter {n : Level } (O : Ordinals {n}) where open import zf open import logic import OD open import Relation.Nullary open import Data.Empty open import Relation.Binary.Core open import Relation.Binary.PropositionalEquality import BAlgbra open BAlgbra O open inOrdinal O open OD O open OD.OD open ODAxiom odAxiom import OrdUtil import ODUtil open Ordinals.Ordinals O open Ordinals.IsOrdinals isOrdinal open Ordinals.IsNext isNext open OrdUtil O open ODUtil O import ODC open ODC O open _∧_ open _∨_ open Bool -- Kunen p.76 and p.53, we use ⊆ record Filter ( L : HOD ) : Set (suc n) where field filter : HOD f⊆PL : filter ⊆ Power L filter1 : { p q : HOD } → q ⊆ L → filter ∋ p → p ⊆ q → filter ∋ q filter2 : { p q : HOD } → filter ∋ p → filter ∋ q → filter ∋ (p ∩ q) open Filter record prime-filter { L : HOD } (P : Filter L) : Set (suc (suc n)) where field proper : ¬ (filter P ∋ od∅) prime : {p q : HOD } → filter P ∋ (p ∪ q) → ( filter P ∋ p ) ∨ ( filter P ∋ q ) record ultra-filter { L : HOD } (P : Filter L) : Set (suc (suc n)) where field proper : ¬ (filter P ∋ od∅) ultra : {p : HOD } → p ⊆ L → ( filter P ∋ p ) ∨ ( filter P ∋ ( L \ p) ) open _⊆_ ∈-filter : {L p : HOD} → (P : Filter L ) → filter P ∋ p → p ⊆ L ∈-filter {L} {p} P lt = power→⊆ L p ( incl (f⊆PL P) lt ) ∪-lemma1 : {L p q : HOD } → (p ∪ q) ⊆ L → p ⊆ L ∪-lemma1 {L} {p} {q} lt = record { incl = λ {x} p∋x → incl lt (case1 p∋x) } ∪-lemma2 : {L p q : HOD } → (p ∪ q) ⊆ L → q ⊆ L ∪-lemma2 {L} {p} {q} lt = record { incl = λ {x} p∋x → incl lt (case2 p∋x) } q∩q⊆q : {p q : HOD } → (q ∩ p) ⊆ q q∩q⊆q = record { incl = λ lt → proj1 lt } open HOD ----- -- -- ultra filter is prime -- filter-lemma1 : {L : HOD} → (P : Filter L) → ∀ {p q : HOD } → ultra-filter P → prime-filter P filter-lemma1 {L} P u = record { proper = ultra-filter.proper u ; prime = lemma3 } where lemma3 : {p q : HOD} → filter P ∋ (p ∪ q) → ( filter P ∋ p ) ∨ ( filter P ∋ q ) lemma3 {p} {q} lt with ultra-filter.ultra u (∪-lemma1 (∈-filter P lt) ) ... | case1 p∈P = case1 p∈P ... | case2 ¬p∈P = case2 (filter1 P {q ∩ (L \ p)} (∪-lemma2 (∈-filter P lt)) lemma7 lemma8) where lemma5 : ((p ∪ q ) ∩ (L \ p)) =h= (q ∩ (L \ p)) lemma5 = record { eq→ = λ {x} lt → ⟪ lemma4 x lt , proj2 lt ⟫ ; eq← = λ {x} lt → ⟪ case2 (proj1 lt) , proj2 lt ⟫ } where lemma4 : (x : Ordinal ) → odef ((p ∪ q) ∩ (L \ p)) x → odef q x lemma4 x lt with proj1 lt lemma4 x lt | case1 px = ⊥-elim ( proj2 (proj2 lt) px ) lemma4 x lt | case2 qx = qx lemma6 : filter P ∋ ((p ∪ q ) ∩ (L \ p)) lemma6 = filter2 P lt ¬p∈P lemma7 : filter P ∋ (q ∩ (L \ p)) lemma7 = subst (λ k → filter P ∋ k ) (==→o≡ lemma5 ) lemma6 lemma8 : (q ∩ (L \ p)) ⊆ q lemma8 = q∩q⊆q ----- -- -- if Filter contains L, prime filter is ultra -- filter-lemma2 : {L : HOD} → (P : Filter L) → filter P ∋ L → prime-filter P → ultra-filter P filter-lemma2 {L} P f∋L prime = record { proper = prime-filter.proper prime ; ultra = λ {p} p⊆L → prime-filter.prime prime (lemma p p⊆L) } where open _==_ p+1-p=1 : {p : HOD} → p ⊆ L → L =h= (p ∪ (L \ p)) eq→ (p+1-p=1 {p} p⊆L) {x} lt with ODC.decp O (odef p x) eq→ (p+1-p=1 {p} p⊆L) {x} lt | yes p∋x = case1 p∋x eq→ (p+1-p=1 {p} p⊆L) {x} lt | no ¬p = case2 ⟪ lt , ¬p ⟫ eq← (p+1-p=1 {p} p⊆L) {x} ( case1 p∋x ) = subst (λ k → odef L k ) &iso (incl p⊆L ( subst (λ k → odef p k) (sym &iso) p∋x )) eq← (p+1-p=1 {p} p⊆L) {x} ( case2 ¬p ) = proj1 ¬p lemma : (p : HOD) → p ⊆ L → filter P ∋ (p ∪ (L \ p)) lemma p p⊆L = subst (λ k → filter P ∋ k ) (==→o≡ (p+1-p=1 p⊆L)) f∋L record Dense (P : HOD ) : Set (suc n) where field dense : HOD d⊆P : dense ⊆ Power P dense-f : HOD → HOD dense-d : { p : HOD} → p ⊆ P → dense ∋ dense-f p dense-p : { p : HOD} → p ⊆ P → p ⊆ (dense-f p) record Ideal ( L : HOD ) : Set (suc n) where field ideal : HOD i⊆PL : ideal ⊆ Power L ideal1 : { p q : HOD } → q ⊆ L → ideal ∋ p → q ⊆ p → ideal ∋ q ideal2 : { p q : HOD } → ideal ∋ p → ideal ∋ q → ideal ∋ (p ∪ q) open Ideal proper-ideal : {L : HOD} → (P : Ideal L ) → {p : HOD} → Set n proper-ideal {L} P {p} = ideal P ∋ od∅ prime-ideal : {L : HOD} → Ideal L → ∀ {p q : HOD } → Set n prime-ideal {L} P {p} {q} = ideal P ∋ ( p ∩ q) → ( ideal P ∋ p ) ∨ ( ideal P ∋ q ) ---- -- -- Filter/Ideal without ZF -- L have to be a Latice -- record F-Filter {n : Level} (L : Set n) (PL : (L → Set n) → Set n) ( _⊆_ : L → L → Set n) (_∩_ : L → L → L ) : Set (suc n) where field filter : L → Set n f⊆P : PL filter filter1 : { p q : L } → PL (λ x → q ⊆ x ) → filter p → p ⊆ q → filter q filter2 : { p q : L } → filter p → filter q → filter (p ∩ q) Filter-is-F : {L : HOD} → (f : Filter L ) → F-Filter HOD (λ p → (x : HOD) → p x → x ⊆ L ) _⊆_ _∩_ Filter-is-F {L} f = record { filter = λ x → Lift (suc n) ((filter f) ∋ x) ; f⊆P = λ x f∋x → power→⊆ _ _ (incl ( f⊆PL f ) (lower f∋x )) ; filter1 = λ {p} {q} q⊆L f∋p p⊆q → lift ( filter1 f (q⊆L q refl-⊆) (lower f∋p) p⊆q) ; filter2 = λ {p} {q} f∋p f∋q → lift ( filter2 f (lower f∋p) (lower f∋q)) } record F-Dense {n : Level} (L : Set n) (PL : (L → Set n) → Set n) ( _⊆_ : L → L → Set n) (_∩_ : L → L → L ) : Set (suc n) where field dense : L → Set n d⊆P : PL dense dense-f : L → L dense-d : { p : L} → PL (λ x → p ⊆ x ) → dense ( dense-f p ) dense-p : { p : L} → PL (λ x → p ⊆ x ) → p ⊆ (dense-f p) Dense-is-F : {L : HOD} → (f : Dense L ) → F-Dense HOD (λ p → (x : HOD) → p x → x ⊆ L ) _⊆_ _∩_ Dense-is-F {L} f = record { dense = λ x → Lift (suc n) ((dense f) ∋ x) ; d⊆P = λ x f∋x → power→⊆ _ _ (incl ( d⊆P f ) (lower f∋x )) ; dense-f = λ x → dense-f f x ; dense-d = λ {p} d → lift ( dense-d f (d p refl-⊆ ) ) ; dense-p = λ {p} d → dense-p f (d p refl-⊆) } where open Dense record GenericFilter (P : HOD) : Set (suc n) where field genf : Filter P generic : (D : Dense P ) → ¬ ( (Dense.dense D ∩ Filter.filter genf ) ≡ od∅ ) record F-GenericFilter {n : Level} (L : Set n) (PL : (L → Set n) → Set n) ( _⊆_ : L → L → Set n) (_∩_ : L → L → L ) : Set (suc n) where field GFilter : F-Filter L PL _⊆_ _∩_ Intersection : (D : F-Dense L PL _⊆_ _∩_ ) → { x : L } → F-Dense.dense D x → L Generic : (D : F-Dense L PL _⊆_ _∩_ ) → { x : L } → ( y : F-Dense.dense D x) → F-Filter.filter GFilter (Intersection D y )
{ "alphanum_fraction": 0.492280547, "avg_line_length": 34.6989795918, "ext": "agda", "hexsha": "8aabd8a20db7f4452e11ef0b84bc210e6501b248", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/zf-in-agda", "max_forks_repo_path": "src/filter.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "shinji-kono/zf-in-agda", "max_issues_repo_path": "src/filter.agda", "max_line_length": 137, "max_stars_count": 5, "max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/zf-in-agda", "max_stars_repo_path": "src/filter.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z", "num_tokens": 2979, "size": 6801 }
module Solution where open import Data.Empty open import Data.List open import Data.Nat open import Data.Bool hiding (_≟_) open import Relation.Nullary open import Relation.Binary.PropositionalEquality data Subseq : List ℕ → List ℕ → Set where subseq-nil : Subseq [] [] subseq-take : ∀ a xs ys → Subseq xs ys → Subseq (a ∷ xs) (a ∷ ys) subseq-drop : ∀ a xs ys → Subseq xs ys → Subseq xs (a ∷ ys) _⊂_ : List ℕ → List ℕ → Set _⊂_ = Subseq subseq-match : (xs ys : List ℕ) → Bool subseq-match [] ys = true subseq-match (x ∷ xs) [] = false subseq-match (x ∷ xs) (y ∷ ys) with x ≟ y ... | yes _ = subseq-match xs ys ... | no _ = subseq-match (x ∷ xs) ys _⊂*_ : List ℕ → List ℕ → Bool _⊂*_ = subseq-match -- silly : ∀ (a : ℕ) (xs ys : List ℕ) → xs ⊂* ys ≡ (a ∷ xs) ⊂* (a ∷ ys) -- silly a xs ys = ? subseq-match⇒subseq : ∀ xs ys → xs ⊂* ys ≡ true → xs ⊂ ys subseq-match⇒subseq [] [] H = subseq-nil subseq-match⇒subseq [] (y ∷ ys) H = subseq-drop y [] ys (subseq-match⇒subseq [] ys H) subseq-match⇒subseq (x ∷ xs) (y ∷ ys) H with x ≟ y ... | yes P rewrite sym P = subseq-take x xs ys (subseq-match⇒subseq xs ys H) ... | no _ = subseq-drop y (x ∷ xs) ys (subseq-match⇒subseq (x ∷ xs) ys H) subseq⇒subseq-match : ∀ xs ys → xs ⊂ ys → xs ⊂* ys ≡ true subseq⇒subseq-match .[] .[] subseq-nil = refl subseq⇒subseq-match (x ∷ xs) .(a ∷ ys) (subseq-take a xs ys H) with x ≟ a ... | yes refl = subseq⇒subseq-match xs ys H ... | no absurd = ⊥-elim (absurd refl) subseq⇒subseq-match [] .(a ∷ ys) (subseq-drop a .[] ys H) = refl subseq⇒subseq-match (x ∷ xs) .(a ∷ ys) (subseq-drop a .(x ∷ xs) ys H) with x ≟ a ... | yes refl = {!!} ... | no _ = {!!}
{ "alphanum_fraction": 0.57771261, "avg_line_length": 36.2765957447, "ext": "agda", "hexsha": "e5ffae9a471b97f39e6bff7835271ab12038490e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z", "max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z", "max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Brethland/LEARNING-STUFF", "max_forks_repo_path": "Agda/Solution.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Brethland/LEARNING-STUFF", "max_issues_repo_path": "Agda/Solution.agda", "max_line_length": 91, "max_stars_count": 2, "max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Brethland/LEARNING-STUFF", "max_stars_repo_path": "Agda/Solution.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z", "max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z", "num_tokens": 671, "size": 1705 }
{-# OPTIONS --cubical --safe #-} open import Relation.Binary module Relation.Binary.Equivalence.Reasoning {a} {𝑆 : Set a} {b} (equivalence : Equivalence 𝑆 b) where open Equivalence equivalence open import Function import Path infixr 2 ≋˘⟨⟩-syntax _≋⟨⟩_ ≋⟨∙⟩-syntax ≡⟨∙⟩-syntax ≋˘⟨⟩-syntax : ∀ (x : 𝑆) {y z} → y ≋ z → y ≋ x → x ≋ z ≋˘⟨⟩-syntax _ y≋z y≋x = sym y≋x ⟨ trans ⟩ y≋z syntax ≋˘⟨⟩-syntax x y≋z y≋x = x ≋˘⟨ y≋x ⟩ y≋z ≋⟨∙⟩-syntax : ∀ (x : 𝑆) {y z} → y ≋ z → x ≋ y → x ≋ z ≋⟨∙⟩-syntax _ y≋z x≋y = x≋y ⟨ trans ⟩ y≋z syntax ≋⟨∙⟩-syntax x y≋z x≋y = x ≋⟨ x≋y ⟩ y≋z _≋⟨⟩_ : ∀ (x : 𝑆) {y} → x ≋ y → x ≋ y _ ≋⟨⟩ x≋y = x≋y ≡⟨∙⟩-syntax : ∀ (x : 𝑆) {y z} → y ≋ z → x Path.≡ y → x ≋ z ≡⟨∙⟩-syntax _ y≋z x≡y = Path.subst (_≋ _) (Path.sym x≡y) y≋z syntax ≡⟨∙⟩-syntax x y≋z x≡y = x ≡⟨ x≡y ⟩ y≋z infix 2.5 _∎ _∎ : ∀ x → x ≋ x x ∎ = refl
{ "alphanum_fraction": 0.5047619048, "avg_line_length": 24, "ext": "agda", "hexsha": "1ed307c4aef127d6b44ec6e283e925f65cd08886", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Relation/Binary/Equivalence/Reasoning.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Relation/Binary/Equivalence/Reasoning.agda", "max_line_length": 102, "max_stars_count": 6, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Relation/Binary/Equivalence/Reasoning.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 506, "size": 840 }
{-# OPTIONS --allow-unsolved-metas #-} open import Oscar.Prelude -- meta-class open import Oscar.Class -- classes open import Oscar.Class.Smap open import Oscar.Class.Symmetry -- individual instances open import Oscar.Class.Hmap.Transleftidentity open import Oscar.Class.Reflexivity.Function open import Oscar.Class.Transitivity.Function -- instance bundles open import Oscar.Property.Functor.SubstitunctionExtensionTerm open import Oscar.Data.Proposequality module Test.ProblemWithDerivation-2 where postulate A : Set B : Set _~A~_ : A → A → Set _~B~_ : B → B → Set s1 : A → B f1 : ∀ {x y} → x ~A~ y → s1 x ~B~ s1 y instance 𝓢urjectivity1 : Smap.class _~A~_ _~B~_ s1 s1 𝓢urjectivity1 .⋆ _ _ = f1 -- Oscar.Property.Setoid.Proposextensequality module _ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} where instance 𝓢ymmetryProposextensequality : Symmetry.class Proposextensequality⟦ 𝔓 ⟧ 𝓢ymmetryProposextensequality .⋆ f₁≡̇f₂ x rewrite f₁≡̇f₂ x = ∅ test : ∀ {x y} → x ~A~ y → s1 x ~B~ s1 y test {x} {y} = smap -- FIXME this works now. why?
{ "alphanum_fraction": 0.7001879699, "avg_line_length": 22.6382978723, "ext": "agda", "hexsha": "4fc608be0497d4c20c4103e8d23317744b89842b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Test/ProblemWithDerivation-2.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Test/ProblemWithDerivation-2.agda", "max_line_length": 75, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Test/ProblemWithDerivation-2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 390, "size": 1064 }
-- Records are allowed in mutual blocks. module RecordInMutual where mutual record A : Set where field x : B record B : Set where field x : A
{ "alphanum_fraction": 0.6751592357, "avg_line_length": 14.2727272727, "ext": "agda", "hexsha": "db211fb2e2e78dc9d38e41098782d8176bfe43f9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/agda-kanso", "max_forks_repo_path": "test/succeed/RecordInMutual.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/agda-kanso", "max_issues_repo_path": "test/succeed/RecordInMutual.agda", "max_line_length": 40, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/RecordInMutual.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 45, "size": 157 }
module Ag09 where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; cong-app) open Eq.≡-Reasoning open import Data.Nat using (ℕ; zero; suc; _+_) open import Data.Nat.Properties using (+-comm) _∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C) (g ∘ f) x = g (f x) infix 0 _≃_ record _≃_ (A B : Set) : Set where field to : A → B from : B → A from∘to : ∀ (x : A) → from (to x) ≡ x to∘from : ∀ (y : B) → to (from y) ≡ y open _≃_ infix 0 _≲_ record _≲_ (A B : Set) : Set where field to : A → B from : B → A from∘to : ∀ (x : A) → from (to x) ≡ x open _≲_ -- exercises ≃-implies-≲ : ∀ {A B : Set} → A ≃ B ----- → A ≲ B ≃-implies-≲ A≃B = record { to = to A≃B ; from = from A≃B ; from∘to = from∘to A≃B } record _⇔_ (A B : Set) : Set where field to : A → B from : B → A open _⇔_ ⇔-refl : ∀ {A : Set} → A ⇔ A ⇔-refl = record { to = λ{x → x} ; from = λ{y → y} } ⇔-sym : ∀ {A B : Set} → A ⇔ B → B ⇔ A ⇔-sym A⇔B = record { to = from A⇔B ; from = to A⇔B } ⇔-trans : ∀ {A B C : Set} → A ⇔ B → B ⇔ C → A ⇔ C ⇔-trans A⇔B B⇔C = record { to = to B⇔C ∘ to A⇔B ; from = from A⇔B ∘ from B⇔C } ≃-refl : ∀ {A : Set} ----- → A ≃ A ≃-refl = record { to = λ{x → x} ; from = λ{y → y} ; from∘to = λ{x → refl} ; to∘from = λ{y → refl} } ≃-sym : ∀ {A B : Set} → A ≃ B ----- → B ≃ A ≃-sym A≃B = record { to = from A≃B ; from = to A≃B ; from∘to = to∘from A≃B ; to∘from = from∘to A≃B } ≃-trans : ∀ {A B C : Set} → A ≃ B → B ≃ C ----- → A ≃ C ≃-trans A≃B B≃C = record { to = to B≃C ∘ to A≃B ; from = from A≃B ∘ from B≃C ; from∘to = λ{x → begin (from A≃B ∘ from B≃C) ((to B≃C ∘ to A≃B) x) ≡⟨⟩ from A≃B (from B≃C (to B≃C (to A≃B x))) ≡⟨ cong (from A≃B) (from∘to B≃C (to A≃B x)) ⟩ from A≃B (to A≃B x) ≡⟨ from∘to A≃B x ⟩ x ∎} ; to∘from = λ{y → begin (to B≃C ∘ to A≃B) ((from A≃B ∘ from B≃C) y) ≡⟨⟩ to B≃C (to A≃B (from A≃B (from B≃C y))) ≡⟨ cong (to B≃C) (to∘from A≃B (from B≃C y)) ⟩ to B≃C (from B≃C y) ≡⟨ to∘from B≃C y ⟩ y ∎} } module ≃-Reasoning where infix 1 ≃-begin_ infixr 2 _≃⟨_⟩_ infix 3 _≃-∎ ≃-begin_ : ∀ {A B : Set} → A ≃ B ----- → A ≃ B ≃-begin A≃B = A≃B _≃⟨_⟩_ : ∀ (A : Set) {B C : Set} → A ≃ B → B ≃ C ----- → A ≃ C A ≃⟨ A≃B ⟩ B≃C = ≃-trans A≃B B≃C _≃-∎ : ∀ (A : Set) ----- → A ≃ A A ≃-∎ = ≃-refl open ≃-Reasoning postulate extensionality : ∀ {A B : Set} {f g : A → B} → (∀ (x : A) → f x ≡ g x) ----------------------- → f ≡ g
{ "alphanum_fraction": 0.4003546099, "avg_line_length": 18.0769230769, "ext": "agda", "hexsha": "c2b5c0e6389d0dc8140e8edf7d83355a774c472d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z", "max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z", "max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Brethland/LEARNING-STUFF", "max_forks_repo_path": "Agda/Ag09.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Brethland/LEARNING-STUFF", "max_issues_repo_path": "Agda/Ag09.agda", "max_line_length": 53, "max_stars_count": 2, "max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Brethland/LEARNING-STUFF", "max_stars_repo_path": "Agda/Ag09.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z", "max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z", "num_tokens": 1424, "size": 2820 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Integers.Definition open import Semirings.Definition open import Groups.Abelian.Definition open import Groups.Definition open import Setoids.Setoids module Numbers.Integers.Addition where infix 15 _+Z_ _+Z_ : ℤ → ℤ → ℤ nonneg zero +Z b = b nonneg (succ x) +Z nonneg y = nonneg (succ x +N y) nonneg (succ x) +Z negSucc zero = nonneg x nonneg (succ x) +Z negSucc (succ y) = nonneg x +Z negSucc y negSucc x +Z nonneg zero = negSucc x negSucc zero +Z nonneg (succ y) = nonneg y negSucc (succ x) +Z nonneg (succ y) = negSucc x +Z nonneg y negSucc x +Z negSucc y = negSucc (succ x +N y) +Zinherits : (a b : ℕ) → nonneg (a +N b) ≡ (nonneg a) +Z (nonneg b) +Zinherits zero b = refl +Zinherits (succ a) b = refl +ZCommutative : (a b : ℤ) → a +Z b ≡ b +Z a +ZCommutative (nonneg zero) (nonneg zero) = refl +ZCommutative (nonneg zero) (nonneg (succ y)) = applyEquality (λ i → nonneg (succ i)) (Semiring.commutative ℕSemiring 0 y) +ZCommutative (nonneg (succ x)) (nonneg zero) = applyEquality (λ i → nonneg (succ i)) (Semiring.commutative ℕSemiring x 0) +ZCommutative (nonneg (succ x)) (nonneg (succ y)) = applyEquality (λ i → nonneg (succ i)) (transitivity (Semiring.commutative ℕSemiring x (succ y)) (transitivity (applyEquality succ (Semiring.commutative ℕSemiring y x)) (Semiring.commutative ℕSemiring (succ x) y))) +ZCommutative (nonneg zero) (negSucc y) = refl +ZCommutative (nonneg (succ x)) (negSucc zero) = refl +ZCommutative (nonneg (succ x)) (negSucc (succ y)) = +ZCommutative (nonneg x) (negSucc y) +ZCommutative (negSucc x) (nonneg zero) = refl +ZCommutative (negSucc zero) (nonneg (succ y)) = refl +ZCommutative (negSucc (succ x)) (nonneg (succ y)) = +ZCommutative (negSucc x) (nonneg y) +ZCommutative (negSucc x) (negSucc y) = applyEquality (λ i → negSucc (succ i)) (Semiring.commutative ℕSemiring x y) +ZAssociative : (a b c : ℤ) → a +Z (b +Z c) ≡ (a +Z b) +Z c +ZAssociative (nonneg zero) (nonneg b) (nonneg c) = refl +ZAssociative (nonneg (succ a)) (nonneg zero) (nonneg c) rewrite Semiring.commutative ℕSemiring a 0 = refl +ZAssociative (nonneg (succ a)) (nonneg (succ b)) (nonneg c) = applyEquality (λ i → nonneg (succ i)) (Semiring.+Associative ℕSemiring a (succ b) c) +ZAssociative (nonneg zero) (nonneg b) (negSucc c) = refl +ZAssociative (nonneg (succ a)) (nonneg zero) (negSucc c) rewrite Semiring.sumZeroRight ℕSemiring a = refl +ZAssociative (nonneg (succ a)) (nonneg (succ b)) (negSucc zero) = applyEquality nonneg (transitivity (applyEquality succ (Semiring.commutative ℕSemiring a b)) (Semiring.commutative ℕSemiring (succ b) a)) +ZAssociative (nonneg (succ a)) (nonneg (succ b)) (negSucc (succ c)) = transitivity (+ZAssociative (nonneg (succ a)) (nonneg b) (negSucc c)) (applyEquality (λ i → nonneg i +Z negSucc c) (transitivity (applyEquality succ (Semiring.commutative ℕSemiring a b)) (Semiring.commutative ℕSemiring (succ b) a))) +ZAssociative (nonneg zero) (negSucc b) c = refl +ZAssociative (nonneg (succ a)) (negSucc zero) (nonneg zero) = +ZCommutative (nonneg 0) (nonneg a) +ZAssociative (nonneg (succ a)) (negSucc zero) (nonneg (succ c)) = transitivity (applyEquality nonneg (transitivity (applyEquality succ (Semiring.commutative ℕSemiring a c)) (Semiring.commutative ℕSemiring (succ c) a))) (+Zinherits a (succ c)) +ZAssociative (nonneg (succ a)) (negSucc zero) (negSucc c) = refl +ZAssociative (nonneg (succ a)) (negSucc (succ b)) (nonneg zero) = +ZCommutative (nonneg 0) _ +ZAssociative (nonneg (succ a)) (negSucc (succ b)) (nonneg (succ c)) = transitivity (applyEquality (nonneg (succ a) +Z_) (+ZCommutative (negSucc b) (nonneg c))) (transitivity (+ZAssociative (nonneg (succ a)) (nonneg c) (negSucc b)) (transitivity (transitivity (transitivity (transitivity (applyEquality (λ i → nonneg (succ i) +Z negSucc b) (Semiring.commutative ℕSemiring a c)) (+ZCommutative (nonneg (succ (c +N a))) (negSucc b))) (applyEquality (negSucc b +Z_) (+ZCommutative (nonneg (succ c)) (nonneg a)))) (+ZAssociative (negSucc b) (nonneg a) (nonneg (succ c)))) (applyEquality (_+Z nonneg (succ c)) (+ZCommutative (negSucc b) (nonneg a))))) +ZAssociative (nonneg (succ a)) (negSucc (succ b)) (negSucc c) = +ZAssociative (nonneg a) (negSucc b) (negSucc c) +ZAssociative (negSucc a) (nonneg zero) c = refl +ZAssociative (negSucc zero) (nonneg (succ b)) (nonneg c) = +Zinherits b c +ZAssociative (negSucc zero) (nonneg (succ b)) (negSucc zero) = +ZCommutative (negSucc 0) (nonneg b) +ZAssociative (negSucc zero) (nonneg (succ b)) (negSucc (succ c)) = transitivity (+ZCommutative (negSucc 0) (nonneg b +Z negSucc c)) (transitivity (equalityCommutative (+ZAssociative (nonneg b) (negSucc c) (negSucc 0))) (applyEquality (λ i → nonneg b +Z negSucc (succ i)) (Semiring.sumZeroRight ℕSemiring c))) +ZAssociative (negSucc (succ a)) (nonneg (succ b)) (nonneg zero) = transitivity (applyEquality (λ i → negSucc a +Z (nonneg i)) (Semiring.sumZeroRight ℕSemiring b)) (+ZCommutative (nonneg 0) (negSucc a +Z nonneg b)) +ZAssociative (negSucc (succ a)) (nonneg (succ b)) (nonneg (succ c)) = transitivity (applyEquality (negSucc a +Z_) (+Zinherits b (succ c))) (+ZAssociative (negSucc a) (nonneg b) (nonneg (succ c))) +ZAssociative (negSucc (succ a)) (nonneg (succ b)) (negSucc zero) = transitivity (+ZCommutative (negSucc (succ a)) (nonneg b)) (transitivity (transitivity (applyEquality (λ i → nonneg b +Z negSucc (succ i)) (equalityCommutative (Semiring.sumZeroRight ℕSemiring a))) (+ZAssociative (nonneg b) (negSucc a) (negSucc 0))) (applyEquality (_+Z negSucc 0) (+ZCommutative (nonneg b) (negSucc a)))) +ZAssociative (negSucc (succ a)) (nonneg (succ b)) (negSucc (succ c)) = transitivity (+ZCommutative (negSucc (succ a)) (nonneg b +Z negSucc c)) (transitivity (transitivity (equalityCommutative (+ZAssociative (nonneg b) (negSucc c) (negSucc (succ a)))) (transitivity (applyEquality (λ i → nonneg b +Z negSucc i) (Semiring.commutative ℕSemiring (succ c) (succ a))) (+ZAssociative (nonneg b) (negSucc a) (negSucc (succ c))))) (applyEquality (_+Z negSucc (succ c)) (+ZCommutative (nonneg b) (negSucc a)))) +ZAssociative (negSucc a) (negSucc b) (nonneg zero) = refl +ZAssociative (negSucc a) (negSucc zero) (nonneg (succ c)) = applyEquality (λ i → negSucc i +Z nonneg c) (Semiring.commutative ℕSemiring 0 a) +ZAssociative (negSucc a) (negSucc (succ b)) (nonneg (succ c)) = transitivity (+ZAssociative (negSucc a) (negSucc b) (nonneg c)) (applyEquality (λ i → negSucc i +Z nonneg c) (transitivity (applyEquality succ (Semiring.commutative ℕSemiring a b)) (Semiring.commutative ℕSemiring (succ b) a))) +ZAssociative (negSucc a) (negSucc b) (negSucc c) = applyEquality (λ i → negSucc (succ i)) (transitivity (Semiring.+Associative ℕSemiring a (succ b) c) (applyEquality (_+N c) (transitivity (Semiring.commutative ℕSemiring a (succ b)) (applyEquality succ (Semiring.commutative ℕSemiring b a))))) additiveInverseExists : (a : ℕ) → (negSucc a +Z nonneg (succ a)) ≡ nonneg 0 additiveInverseExists zero = refl additiveInverseExists (succ a) = additiveInverseExists a additiveInverse : (a : ℤ) → ℤ additiveInverse (nonneg zero) = nonneg 0 additiveInverse (nonneg (succ x)) = negSucc x additiveInverse (negSucc x) = nonneg (succ x) ℤGroup : Group (reflSetoid ℤ) (_+Z_) Group.+WellDefined ℤGroup refl refl = refl Group.0G ℤGroup = nonneg 0 Group.inverse ℤGroup = additiveInverse Group.+Associative ℤGroup {a} {b} {c} = +ZAssociative a b c Group.identRight ℤGroup {nonneg zero} = refl Group.identRight ℤGroup {nonneg (succ x)} = applyEquality (λ i → nonneg (succ i)) (Semiring.commutative ℕSemiring x 0) Group.identRight ℤGroup {negSucc x} = refl Group.identLeft ℤGroup = refl Group.invLeft ℤGroup {nonneg zero} = refl Group.invLeft ℤGroup {nonneg (succ x)} = additiveInverseExists x Group.invLeft ℤGroup {negSucc x} = transitivity (+ZCommutative (nonneg (succ x)) (negSucc x)) (additiveInverseExists x) Group.invRight ℤGroup {nonneg zero} = refl Group.invRight ℤGroup {nonneg (succ x)} = transitivity (+ZCommutative (nonneg (succ x)) (negSucc x)) (additiveInverseExists x) Group.invRight ℤGroup {negSucc x} = additiveInverseExists x ℤAbGrp : AbelianGroup ℤGroup ℤAbGrp = record { commutative = λ {a} {b} → +ZCommutative a b }
{ "alphanum_fraction": 0.7196465319, "avg_line_length": 86.0520833333, "ext": "agda", "hexsha": "c4a657dd354b75501e5423540de599a78ebd66f3", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Numbers/Integers/Addition.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Numbers/Integers/Addition.agda", "max_line_length": 646, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Numbers/Integers/Addition.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 2936, "size": 8261 }
module Cats.Util.Monad where open import Category.Monad public open import Data.List using (List ; [] ; _∷_ ; map) open import Data.Unit using (⊤) open import Function using (_∘_) open import Level using (Lift ; lift) open RawMonad {{...}} public private _<*>_ = _⊛_ module _ {f} {M : Set f → Set f} {{_ : RawMonad M}} where sequence : ∀ {A} → List (M A) → M (List A) sequence [] = return [] sequence (mx ∷ mxs) = ⦇ mx ∷ sequence mxs ⦈ void : ∀ {A} → M A → M (Lift f ⊤) void m = m >>= λ _ → return _ mapM : ∀ {a} {A : Set a} {B} → (A → M B) → List A → M (List B) mapM f = sequence ∘ map f mapM′ : ∀ {a} {A : Set a} {B} → (A → M B) → List A → M (Lift f ⊤) mapM′ f = void ∘ mapM f
{ "alphanum_fraction": 0.5497896213, "avg_line_length": 20.9705882353, "ext": "agda", "hexsha": "6d2685e922e4cfe3f7188934ce6b55045a96e255", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "alessio-b-zak/cats", "max_forks_repo_path": "Cats/Util/Monad.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "alessio-b-zak/cats", "max_issues_repo_path": "Cats/Util/Monad.agda", "max_line_length": 67, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "alessio-b-zak/cats", "max_stars_repo_path": "Cats/Util/Monad.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 275, "size": 713 }
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Localization.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.PathSplitEquiv open isPathSplitEquiv open import Cubical.HITs.Localization.Base module _ {ℓα ℓs ℓt} {A : Type ℓα} {S : A → Type ℓs} {T : A → Type ℓt} where rec : ∀ {F : ∀ α → S α → T α} {ℓ ℓ'} {X : Type ℓ} {Y : Type ℓ'} → (lY : isLocal F Y) → (X → Y) → Localize F X → Y rec lY g ∣ x ∣ = g x rec lY g (ext α f t) = fst (sec (lY α)) (λ s → rec lY g (f s)) t rec lY g (isExt α f s i) = snd (sec (lY α)) (λ s → rec lY g (f s)) i s rec lY f (≡ext α g h p t i) = fst (secCong (lY α) (λ t → rec lY f (g t)) (λ t → rec lY f (h t))) (λ i s → rec lY f (p s i)) i t rec lY f (≡isExt α g h p t i j) = snd (secCong (lY α) (λ t → rec lY f (g t)) (λ t → rec lY f (h t))) (λ i s → rec lY f (p s i)) i j t
{ "alphanum_fraction": 0.5532900834, "avg_line_length": 44.9583333333, "ext": "agda", "hexsha": "c9be10f9338749a9ac7bd0d11799f382062af9c5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "borsiemir/cubical", "max_forks_repo_path": "Cubical/HITs/Localization/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "borsiemir/cubical", "max_issues_repo_path": "Cubical/HITs/Localization/Properties.agda", "max_line_length": 102, "max_stars_count": null, "max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "borsiemir/cubical", "max_stars_repo_path": "Cubical/HITs/Localization/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 420, "size": 1079 }
------------------------------------------------------------------------------ -- The alternating bit protocol (ABP) is correct ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- This module proves the correctness of the ABP following the -- formalization in Dybjer and Sander (1989). module FOTC.Program.ABP.CorrectnessProofI where open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.Bool open import FOTC.Data.Bool.PropertiesI open import FOTC.Data.Stream.Type open import FOTC.Data.Stream.Equality.PropertiesI open import FOTC.Program.ABP.ABP open import FOTC.Program.ABP.Lemma1I open import FOTC.Program.ABP.Lemma2I open import FOTC.Program.ABP.Fair.Type open import FOTC.Program.ABP.Terms open import FOTC.Relation.Binary.Bisimilarity.Type ------------------------------------------------------------------------------ -- Main theorem. abpCorrect : ∀ {b os₁ os₂ is} → Bit b → Fair os₁ → Fair os₂ → Stream is → is ≈ abpTransfer b os₁ os₂ is abpCorrect {b} {os₁} {os₂} {is} Bb Fos₁ Fos₂ Sis = ≈-coind B h₁ h₂ where h₁ : ∀ {ks ls} → B ks ls → ∃[ k' ] ∃[ ks' ] ∃[ ls' ] ks ≡ k' ∷ ks' ∧ ls ≡ k' ∷ ls' ∧ B ks' ls' h₁ {ks} {ls} (b , os₁ , os₂ , as , bs , cs , ds , Sks , Bb , Fos₁ , Fos₂ , h) with Stream-out Sks ... | (k' , ks' , ks≡k'∷ks' , Sks') = k' , ks' , ls' , ks≡k'∷ks' , ls≡k'∷ls' , Bks'ls' where S-helper : ks ≡ k' ∷ ks' → S b ks os₁ os₂ as bs cs ds ls → S b (k' ∷ ks') os₁ os₂ as bs cs ds ls S-helper h₁ h₂ = subst (λ t → S b t os₁ os₂ as bs cs ds ls) h₁ h₂ S'-lemma₁ : ∃[ os₁' ] ∃[ os₂' ] ∃[ as' ] ∃[ bs' ] ∃[ cs' ] ∃[ ds' ] ∃[ ls' ] Fair os₁' ∧ Fair os₂' ∧ S' b k' ks' os₁' os₂' as' bs' cs' ds' ls' ∧ ls ≡ k' ∷ ls' S'-lemma₁ = lemma₁ Bb Fos₁ Fos₂ (S-helper ks≡k'∷ks' h) -- Following Martin Escardo advice (see Agda mailing list, heap -- mistery) we use pattern matching instead of ∃ eliminators to -- project the elements of the existentials. -- 2011-08-25 update: It does not seems strictly necessary because -- the Agda issue 415 was fixed. ls' : D ls' with S'-lemma₁ ... | _ , _ , _ , _ , _ , _ , ls' , _ = ls' ls≡k'∷ls' : ls ≡ k' ∷ ls' ls≡k'∷ls' with S'-lemma₁ ... | _ , _ , _ , _ , _ , _ , _ , _ , _ , _ , prf = prf S-lemma₂ : ∃[ os₁'' ] ∃[ os₂'' ] ∃[ as'' ] ∃[ bs'' ] ∃[ cs'' ] ∃[ ds'' ] Fair os₁'' ∧ Fair os₂'' ∧ S (not b) ks' os₁'' os₂'' as'' bs'' cs'' ds'' ls' S-lemma₂ with S'-lemma₁ ... | _ , _ , _ , _ , _ , _ , _ , Fos₁' , Fos₂' , s' , _ = lemma₂ Bb Fos₁' Fos₂' s' Bks'ls' : B ks' ls' Bks'ls' with S-lemma₂ ... | os₁'' , os₂'' , as'' , bs'' , cs'' , ds'' , Fos₁'' , Fos₂'' , s = not b , os₁'' , os₂'' , as'' , bs'' , cs'' , ds'' , Sks' , not-Bool Bb , Fos₁'' , Fos₂'' , s h₂ : B is (abpTransfer b os₁ os₂ is) h₂ = b , os₁ , os₂ , has aux₁ aux₂ aux₃ aux₄ aux₅ is , hbs aux₁ aux₂ aux₃ aux₄ aux₅ is , hcs aux₁ aux₂ aux₃ aux₄ aux₅ is , hds aux₁ aux₂ aux₃ aux₄ aux₅ is , Sis , Bb , Fos₁ , Fos₂ , has-eq aux₁ aux₂ aux₃ aux₄ aux₅ is , hbs-eq aux₁ aux₂ aux₃ aux₄ aux₅ is , hcs-eq aux₁ aux₂ aux₃ aux₄ aux₅ is , hds-eq aux₁ aux₂ aux₃ aux₄ aux₅ is , trans (abpTransfer-eq b os₁ os₂ is) (transfer-eq aux₁ aux₂ aux₃ aux₄ aux₅ is) where aux₁ aux₂ aux₃ aux₄ aux₅ : D aux₁ = send b aux₂ = ack b aux₃ = out b aux₄ = corrupt os₁ aux₅ = corrupt os₂ ------------------------------------------------------------------------------ -- abpTransfer produces a Stream. abpTransfer-Stream : ∀ {b os₁ os₂ is} → Bit b → Fair os₁ → Fair os₂ → Stream is → Stream (abpTransfer b os₁ os₂ is) abpTransfer-Stream Bb Fos₁ Fos₂ Sis = ≈→Stream₂ (abpCorrect Bb Fos₁ Fos₂ Sis) ------------------------------------------------------------------------------ -- References -- -- Dybjer, Peter and Sander, Herbert P. (1989). A Functional -- Programming Approach to the Specification and Verification of -- Concurrent Systems. Formal Aspects of Computing 1, pp. 303–319.
{ "alphanum_fraction": 0.4914021164, "avg_line_length": 36.5806451613, "ext": "agda", "hexsha": "230fad8b185bb731c0f6f1e6b64bb9932aaf5594", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/ABP/CorrectnessProofI.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/ABP/CorrectnessProofI.agda", "max_line_length": 80, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/ABP/CorrectnessProofI.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 1568, "size": 4536 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Pointed.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Structure open import Cubical.Foundations.Structure using (typ) public open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence Pointed : (ℓ : Level) → Type (ℓ-suc ℓ) Pointed ℓ = TypeWithStr ℓ (λ x → x) pt : ∀ {ℓ} (A∙ : Pointed ℓ) → typ A∙ pt = str Pointed₀ = Pointed ℓ-zero {- Pointed functions -} _→∙_ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Type (ℓ-max ℓ ℓ') (A , a) →∙ (B , b) = Σ[ f ∈ (A → B) ] f a ≡ b _→∙_∙ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ') (A →∙ B ∙) .fst = A →∙ B (A →∙ B ∙) .snd .fst x = pt B (A →∙ B ∙) .snd .snd = refl idfun∙ : ∀ {ℓ} (A : Pointed ℓ) → A →∙ A idfun∙ A .fst x = x idfun∙ A .snd = refl {- HIT allowing for pattern matching on pointed types -} data Pointer {ℓ} (A : Pointed ℓ) : Type ℓ where pt₀ : Pointer A ⌊_⌋ : typ A → Pointer A id : ⌊ pt A ⌋ ≡ pt₀ IsoPointedPointer : ∀ {ℓ} {A : Pointed ℓ} → Iso (typ A) (Pointer A) Iso.fun IsoPointedPointer = ⌊_⌋ Iso.inv (IsoPointedPointer {A = A}) pt₀ = pt A Iso.inv IsoPointedPointer ⌊ x ⌋ = x Iso.inv (IsoPointedPointer {A = A}) (id i) = pt A Iso.rightInv IsoPointedPointer pt₀ = id Iso.rightInv IsoPointedPointer ⌊ x ⌋ = refl Iso.rightInv IsoPointedPointer (id i) j = id (i ∧ j) Iso.leftInv IsoPointedPointer x = refl Pointed≡Pointer : ∀ {ℓ} {A : Pointed ℓ} → typ A ≡ Pointer A Pointed≡Pointer = isoToPath IsoPointedPointer Pointer∙ : ∀ {ℓ} (A : Pointed ℓ) → Pointed ℓ Pointer∙ A .fst = Pointer A Pointer∙ A .snd = pt₀ Pointed≡∙Pointer : ∀ {ℓ} {A : Pointed ℓ} → A ≡ (Pointer A , pt₀) Pointed≡∙Pointer {A = A} i = (Pointed≡Pointer {A = A} i) , helper i where helper : PathP (λ i → Pointed≡Pointer {A = A} i) (pt A) pt₀ helper = ua-gluePath (isoToEquiv (IsoPointedPointer {A = A})) id pointerFun : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) → Pointer A → Pointer B pointerFun f pt₀ = pt₀ pointerFun f ⌊ x ⌋ = ⌊ fst f x ⌋ pointerFun f (id i) = (cong ⌊_⌋ (snd f) ∙ id) i pointerFun∙ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) → Pointer∙ A →∙ Pointer∙ B pointerFun∙ f .fst = pointerFun f pointerFun∙ f .snd = refl
{ "alphanum_fraction": 0.626156434, "avg_line_length": 32.5753424658, "ext": "agda", "hexsha": "9fdd3d5d963a09069f24f40ace1e00a8cdaca7f1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "L-TChen/cubical", "max_forks_repo_path": "Cubical/Foundations/Pointed/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "L-TChen/cubical", "max_issues_repo_path": "Cubical/Foundations/Pointed/Base.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "L-TChen/cubical", "max_stars_repo_path": "Cubical/Foundations/Pointed/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 992, "size": 2378 }
open import SOAS.Common open import SOAS.Families.Core import SOAS.Metatheory.MetaAlgebra -- Shorthands for de Bruijn indices module SOAS.Syntax.Shorthands {T : Set} {⅀F : Functor 𝔽amiliesₛ 𝔽amiliesₛ} (open SOAS.Metatheory.MetaAlgebra ⅀F) {𝒜 : Familyₛ → Familyₛ}(𝒜ᵃ : (𝔛 : Familyₛ) → MetaAlg 𝔛 (𝒜 𝔛)) where open import SOAS.Context open import SOAS.Families.Build open import SOAS.ContextMaps.Inductive open import SOAS.Variable open import Data.Nat open import Relation.Nullary.Decidable using (True; toWitness) private variable α β γ δ υ : T Γ Δ : Ctx module _ {𝔛 : Familyₛ} where open MetaAlg 𝔛 (𝒜ᵃ 𝔛) -- Refer to variables via de Bruijn numerals: e.g. ` 2 = 𝑣𝑎𝑟 (old (old new)) len : Ctx {T} → ℕ len ∅ = ℕ.zero len (α ∙ Γ) = suc (len Γ) ix : {Γ : Ctx} → {n : ℕ} → (p : n < len Γ) → T ix {(α ∙ _)} {zero} (s≤s z≤n) = α ix {(_ ∙ Γ)} {(suc n)} (s≤s p) = ix p deBruijn : ∀ {Γ} → {n : ℕ} → (p : n < len Γ) → ℐ (ix p) Γ deBruijn {_ ∙ _} {zero} (s≤s z≤n) = new deBruijn {_ ∙ Γ} {(suc n)} (s≤s p) = old (deBruijn p) ′ : {Γ : Ctx}(n : ℕ){n∈Γ : True (suc n ≤? len Γ)} → 𝒜 𝔛 (ix (toWitness n∈Γ)) Γ ′ n {n∈Γ} = 𝑣𝑎𝑟 (deBruijn (toWitness n∈Γ)) -- Explicit abbreviations for de Bruijn indices 0-4 x₀ : 𝒜 𝔛 α (α ∙ Γ) x₀ = 𝑣𝑎𝑟 new x₁ : 𝒜 𝔛 β (α ∙ β ∙ Γ) x₁ = 𝑣𝑎𝑟 (old new) x₂ : 𝒜 𝔛 γ (α ∙ β ∙ γ ∙ Γ) x₂ = 𝑣𝑎𝑟 (old (old new)) x₃ : 𝒜 𝔛 δ (α ∙ β ∙ γ ∙ δ ∙ Γ) x₃ = 𝑣𝑎𝑟 (old (old (old new))) x₄ : 𝒜 𝔛 υ (α ∙ β ∙ γ ∙ δ ∙ υ ∙ Γ) x₄ = 𝑣𝑎𝑟 (old (old (old (old new))))
{ "alphanum_fraction": 0.5631443299, "avg_line_length": 27.2280701754, "ext": "agda", "hexsha": "bd2e92acdcf3776020f02698a835733c85e3995c", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_path": "SOAS/Syntax/Shorthands.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_path": "SOAS/Syntax/Shorthands.agda", "max_line_length": 80, "max_stars_count": 39, "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_path": "SOAS/Syntax/Shorthands.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "num_tokens": 804, "size": 1552 }
import MJ.Classtable import MJ.Syntax as Syntax import MJ.Semantics.Values as Values import MJ.Classtable.Core as Core import MJ.Classtable.Code as Code -- -- Substitution-free interpretation of welltyped MJ -- module MJ.Semantics.Monadic {c} (Ct : Core.Classtable c)(ℂ : Code.Code Ct) where open import Prelude hiding (_^_) open import Data.Vec hiding (init; _>>=_) open import Data.Vec.All.Properties.Extra as Vec∀++ open import Data.List hiding (null) open import Data.List.Properties.Extra open import Data.List.All.Properties.Extra open import Data.List.Prefix open import Data.List.First open import Data.List.First.Properties open import Data.List.Relation.Unary.All as All open import Data.List.Relation.Unary.Any open import Data.List.Membership.Propositional open import Relation.Nullary.Decidable open import Data.Star hiding (return; _>>=_) open import Data.Sum using (_⊎_; inj₁; inj₂) open Values Ct open Syntax Ct open Code Ct open Core c open Classtable Ct open import MJ.Syntax.Program Ct open import MJ.Classtable.Membership Ct open import MJ.Types open import MJ.LexicalScope c open import MJ.Semantics.Environments Ct open import MJ.Semantics.Objects Ct open import MJ.Semantics.Objects.Flat Ct ℂ using (encoding) open import Common.Weakening {- Make the object encoding API available; -} open ObjEncoding encoding {- The monad in which we define evaluation. This encapsulates state, lexical environments, timeouts and exceptions. -} WSet = World c → Set data Exception : Set where nullderef : Exception other : Exception data Result (W : World c)(A : WSet) : Set where exception : ∀ {W'} → W' ⊒ W → Store W' → Exception → Result W A timeout : Result W A returns : ∀ {W'} → W' ⊒ W → Store W' → A W' → Result W A result-strengthen : ∀ {W W'}{A : WSet} → W ⊒ W' → Result W A → Result W' A result-strengthen ext (exception ext' μ e) = exception (ext ⊚ ext') μ e result-strengthen ext timeout = timeout result-strengthen ext (returns ext' μ v) = returns (ext ⊚ ext') μ v -- monad that threads a readonly environment, store and propagates -- semantic errors M : Ctx → World c → WSet → Set M Γ W A = Env Γ W → Store W → Result W A return : ∀ {Γ W}{A : WSet} → A W → M Γ W A return v _ μ = returns ⊑-refl μ v doTimeout : ∀ {Γ W}{A : WSet} → M Γ W A doTimeout _ _ = timeout raiseM : ∀ {Γ W}{A : WSet} → Exception → M Γ W A raiseM exc E μ = exception ⊑-refl μ exc sval-weaken : ∀ {W W' a} → W' ⊒ W → StoreVal W a → StoreVal W' a sval-weaken ext (val x) = val $ weaken-val ext x sval-weaken ext (obj cid x) = obj cid (weaken-obj cid ext x) instance storeval-weakenable : ∀ {a} → Weakenable (λ W → StoreVal W a) storeval-weakenable = record {wk = sval-weaken } infixl 10 _>>=_ _>>=_ : ∀ {Γ W}{A B : WSet} → M Γ W A → (∀ {W'} → A W' → M Γ W' B) → M Γ W B (k >>= f) E μ with k E μ ... | exception ext μ' e = exception ext μ' e ... | timeout = timeout ... | returns ext μ' v = result-strengthen ext $ f v (All.map (wk ext) E) μ' infixl 10 _^_ _^_ : ∀ {Σ Γ}{A B : WSet} ⦃ w : Weakenable B ⦄ → M Γ Σ A → B Σ → M Γ Σ (A ⊗ B) (f ^ x) E μ with (f E μ) ... | timeout = timeout ... | exception ext μ' e = exception ext μ' e ... | returns ext μ' v = returns ext μ' (v , wk ext x) _recoverWith_ : ∀ {Γ W}{A : WSet} → M Γ W A → (∀ {W'} → Exception → W' ⊒ W → M Γ W' A) → M Γ W A (k recoverWith f) E μ with k E μ ... | timeout = timeout ... | returns ext μ' x = returns ext μ' x ... | exception ext μ' e = result-strengthen ext $ f e ext (wk ext E) μ' store : ∀ {Γ W a} → StoreVal W a → M Γ W (λ W' → a ∈ W') store {Γ}{W}{a} sv E μ = let ext = ∷ʳ-⊒ a W μ' = (All.map (wk ext) μ) all-∷ʳ (wk ext sv) in returns ext μ' (∈-∷ʳ W a) update : ∀ {Γ W a} → a ∈ W → StoreVal W a → M Γ W (λ W' → ⊤) update ptr v E μ = returns ⊑-refl (μ All.[ ptr ]≔ v) tt deref : ∀ {Γ W a} → a ∈ W → M Γ W (flip StoreVal a) deref ptr E μ = returns ⊑-refl μ (∈-all ptr μ) getEnv : ∀ {Γ W}{A : WSet} → (Env Γ W → M Γ W A) → M Γ W A getEnv f E μ = f E E μ usingEnv : ∀ {Γ Γ' W}{A : WSet} → Env Γ' W → M Γ' W A → M Γ W A usingEnv E e = const $ e E store* : ∀ {Γ W as} → All (λ a → StoreVal W (vty a)) as → M Γ W (λ W' → All (λ a → (vty a) ∈ W') as) store* [] = return [] store* (v ∷ vs) = store v ^ vs >>= λ{ (r , vs) → store* vs ^ r >>= λ{ (rs , r) → return (r ∷ rs) }} {- Lifting of object getter/setter into the monad -} read-field : ∀ {Γ : Ctx}{C W f a} → IsMember C FIELD f a → Val W (ref C) → M Γ W (λ W → Val W a) read-field m null = raiseM nullderef read-field m (ref o C<:C') E μ with ∈-all o μ read-field m (ref o C<:C') E μ | obj cid O = returns ⊑-refl μ (getter _ O (inherit' C<:C' m)) write-field : ∀ {Γ C W f a} → IsMember C FIELD f a → Val W (ref C) → Val W a → M Γ W (flip Val (ref C)) write-field m null v = raiseM nullderef write-field m (ref o s) v E μ with ∈-all o μ write-field m (ref o s) v E μ | obj cid O = let vobj = obj cid (setter _ O (inherit' s m) v) μ' = μ All.[ o ]≔ vobj in returns ⊑-refl μ' (ref o s) -- Get the implementation of any method definition of a class mbody : ∀ {m ty} cid → AccMember cid METHOD m ty → InheritedMethod cid m ty mbody cid mb with toWitness mb ... | (pid , s , d∈decls) = pid , s , ∈-all (proj₁ (first⟶∈ d∈decls)) (Implementation.mbodies (ℂ pid)) {- Refinements of bind and return for the nested monad for command evaluation -} _>>=c_ : ∀ {I O O' : Ctx}{W : World c}{a} → M I W (λ W → Val W a ⊎ Env O W) → (∀ {W'} → Env O W' → M I W' (λ W → Val W a ⊎ Env O' W)) → M I W (λ W → Val W a ⊎ Env O' W) m >>=c f = m >>= λ{ (inj₁ v) → return (inj₁ v) ; (inj₂ E) → f E } continue : ∀ {Γ : Ctx}{W : World c}{a} → M Γ W (λ W → Val W a ⊎ Env Γ W) continue = getEnv λ E → return (inj₂ E) {- Fueled interpreter -} mutual {- Arguments are passed as mutable and thus have to be evaluated, after which we store the values in the store and we pass the references. -} eval-args : ∀ {Γ as W} → ℕ → All (Expr Γ) as → M Γ W (λ W' → All (λ a → (vty a) ∈ W') as) eval-args k args = evalₑ* k args >>= λ vs → store* (All.map val vs) {- Object initialization: Creates a default object; stores a mutable reference to it on the heap; calls the constructor on the resulting reference. -} constructM : ℕ → ∀ cid → ∀ {W} → M (Class.constr (Σ cid)) W (flip Val (ref cid)) constructM k cid with ℂ cid constructM k cid | (implementation construct mbodies) = store (obj _ (defaultObject cid)) >>= λ r → store (val (ref r ε)) ^ r >>= λ{ (r' , r) → getEnv λ E → usingEnv (E ⊕ r') (eval-constructor k ε r construct) ^ r >>= λ{ (_ , r) → return $ ref r ε }} {- Constructor interpretation: The difficult case being the one where we have a super call. -} eval-constructor : ∀ {cid' cid W} → ℕ → Σ ⊢ cid' <: cid → (obj cid') ∈ W → Constructor cid → M (constrctx cid) W (flip Val void) eval-constructor zero _ _ _ = doTimeout eval-constructor {_}{Object} (suc k) _ _ _ = return unit eval-constructor {_}{cls cid} (suc k) s o∈W (super args then b) = -- evaluate super call let s' = s ◅◅ super ◅ ε super-con = Implementation.construct (ℂ (Class.parent (Σ (cls cid)))) in eval-args k args ^ o∈W >>= λ{ (rvs , o∈W) → -- arguments getEnv λ{ (self ∷ _) → -- store a parent pointer for passing to super store (val (ref o∈W s')) ^ o∈W ^ rvs >>= λ{ ((sup , o∈W) , rvs) → usingEnv (sup ∷ rvs) (eval-constructor k s' o∈W super-con) >>= λ _ → -- evaluate own body eval-body k b >>= λ _ → return unit }}} eval-constructor {_}{cls id} (suc k) _ _ (body x) = eval-body k x >>= λ _ → return unit {- Method evaluation including super calls. The difficult case again being the one where we have a super call. -} eval-method : ∀ {cid m as b pid W Γ} → ℕ → Σ ⊢ cid <: pid → (obj cid) ∈ W → All (λ ty → vty ty ∈ W) as → InheritedMethod pid m (as , b) → M Γ W (flip Val b) eval-method zero _ _ _ _ = doTimeout eval-method (suc k) s o args (pid' , pid<:pid' , body b) = store (val (ref o (s ◅◅ pid<:pid'))) ^ args >>= λ{ (mutself , args) → usingEnv (mutself ∷ args) (eval-body k b) } eval-method {_}{m}{as}{b} (suc k) s o args (Object , _ , super x ⟨ _ ⟩then _) rewrite Σ-Object = -- calling a method on Object is improbable... ⊥-elim (∉Object {METHOD}{m}{(as , b)}(sound x)) eval-method (suc k) s o args (cls pid' , pid<:pid' , super x ⟨ supargs ⟩then b) = let super-met = mbody (Class.parent (Σ (cls pid'))) x in store (val (ref o (s ◅◅ pid<:pid'))) ^ (args , o) >>= λ{ (mutself , args , o) → -- eval super args in method context usingEnv (mutself ∷ args) (eval-args k supargs) ^ (args , o) >>= λ{ (rvs , args , o) → -- call super eval-method k (s ◅◅ pid<:pid' ◅◅ super ◅ ε) o rvs super-met ^ (args , o) >>= λ{ (retv , args , o) → -- store the super return value to be used as a mutable local store (val retv) ^ (args , o) >>= λ{ (mutret , args , o) → -- store the mutable "this" store (val (ref o (s ◅◅ pid<:pid'))) ^ (mutret , args) >>= λ{ (mutself' , mutret , args) → -- call body usingEnv (mutret ∷ mutself' ∷ args) (eval-body k b) }}}}} {- evaluation of expressions -} evalₑ : ∀ {Γ : Ctx}{a} → ℕ → Expr Γ a → ∀ {W} → M Γ W (flip Val a) evalₑ zero _ = doTimeout -- primitive values evalₑ (suc k) unit = return unit evalₑ (suc k) (num n) = return (num n) evalₑ (suc k) null = return null -- variable lookup evalₑ (suc k) (var x) = getEnv (λ E → return $ getvar x E) >>= λ v → deref v >>= λ{ (val w) → return w } evalₑ (suc k) (upcast ε e) = evalₑ k e evalₑ (suc k) (upcast s₁@(_ ◅ _) e) = evalₑ k e >>= λ{ (ref o s₂ ) → return $ ref o (s₂ ◅◅ s₁) ; null → return null } -- binary interger operations evalₑ (suc k) (iop f l r) = evalₑ k l >>= λ{ (num vₗ) → evalₑ k r >>= λ{ (num vᵣ) → return (num (f vₗ vᵣ)) }} -- method calls evalₑ (suc k) (call e _ {acc = mtd} args) = evalₑ k e >>= λ{ null → raiseM nullderef ; r@(ref {dyn-cid} o s₁) → -- evaluate the arguments eval-args k args ^ o >>= λ{ (rvs , o) → -- dynamic dispatch: dynamic lookup of the method on the runtime class of the reference -- and execution of the call (eval-method k ε o rvs (mbody dyn-cid (inherit _ s₁ mtd))) }} -- field lookup in the heap evalₑ (suc k) (get e _ {_}{fld}) = evalₑ k e >>= λ{ null → raiseM nullderef ; (ref o s) → deref o >>= λ{ (obj c O) → return (getter _ O $ inherit' s (sound fld)) }} -- object allocation evalₑ (suc k) (new C args) = eval-args k args >>= λ rvs → usingEnv rvs (constructM k C) {- Statement evaluation -} evalc : ∀ {I : Ctx}{O : Ctx}{W : World c}{a} → ℕ → Stmt I a O → M I W (λ W → Val W a ⊎ Env O W) evalc zero _ = doTimeout evalc (suc k) raise = raiseM other evalc (suc k) (block stmts) = eval-stmts k stmts >>=c λ _ → continue evalc (suc k) (try cs catch cs') = (evalc k cs >>=c λ _ → continue) recoverWith (λ e ext → evalc k cs' >>= λ _ → continue) -- new local variable evalc (suc k) (loc a) = store (val $ default a) >>= λ r → getEnv λ E → return (inj₂ (E ⊕ r)) -- assigning to a local evalc (suc k) (asgn x e) = evalₑ k e >>= λ v → getEnv (λ E → return $ getvar x E) ^ v >>= λ{ (addr , v) → update addr (val v) >>= λ _ → continue } -- setting a field evalc (suc k) (set r _ {_}{fld} e) = evalₑ k r >>= λ{ null → raiseM nullderef ; r'@(ref _ _) → evalₑ k e ^ r' >>= λ{ (v , r') → write-field (sound fld) r' v >>= λ _ → continue }} -- side-effectful expressions evalc (suc k) (run e) = evalₑ k e >>= λ _ → continue -- early returns evalc (suc k) (ret e) = evalₑ k e >>= λ v → return (inj₁ v) -- if-then-else blocks evalc (suc k) (if e then cs else ds) = evalₑ k e >>= λ{ (num zero) → evalc k cs ; (num (suc _)) → evalc k ds } -- while loops evalc (suc k) (while e run b) = evalₑ (suc k) e >>= λ{ (num zero) → evalc k b >>= λ _ → evalc k (while e run b) ; (num (suc _)) → continue } {- An helper for interpreting a sequence of statements -} eval-stmts : ∀ {Γ Γ' W a} → ℕ → Stmts Γ a Γ' → M Γ W (λ W → Val W a ⊎ Env Γ' W) eval-stmts k ε = continue eval-stmts k (x ◅ st) = evalc k x >>=c λ E' → usingEnv E' (eval-stmts k st) {- An helper for interpreting method bodies (i.e. sequence of Stmts optionally followed by a return). -} eval-body : ∀ {I : Ctx}{W : World c}{a} → ℕ → Body I a → M I W (λ W → Val W a) eval-body k (body ε re) = evalₑ k re eval-body k (body stmts@(_ ◅ _) e) = (eval-stmts k stmts) >>= λ{ (inj₁ v) → return v ; (inj₂ E) → usingEnv E (evalₑ k e) } {- An helper for interpreting a list of expressions in the same context. -} evalₑ* : ∀ {Γ W as} → ℕ → All (Expr Γ) as → M Γ W (λ W → All (Val W) as) evalₑ* k [] = return [] evalₑ* k (e ∷ es) = evalₑ k e >>= λ v → evalₑ* k es ^ v >>= λ{ (vs , v) → return (v ∷ vs) } eval : ∀ {a} → ℕ → Prog a → Result [] (flip Val a) eval k (lib , main) = eval-body k main [] [] {- a few predicates on program interpretation: ... saying it will terminate succesfully in a state where P holds -} _⇓⟨_⟩_ : ∀ {a} → Prog a → ℕ → (P : ∀ {W} → Val W a → Set) → Set p ⇓⟨ k ⟩ P with eval k p p ⇓⟨ k ⟩ P | exception _ _ _ = ⊥ p ⇓⟨ k ⟩ P | timeout = ⊥ p ⇓⟨ k ⟩ P | returns ext μ v = P v {- ...saying it will raise an exception in a state where P holds -} _⇓⟨_⟩!_ : ∀ {a} → Prog a → ℕ → (P : ∀ {W} → Store W → Exception → Set) → Set p ⇓⟨ k ⟩! P with eval k p p ⇓⟨ k ⟩! P | exception _ μ e = P μ e p ⇓⟨ k ⟩! P | timeout = ⊥ p ⇓⟨ k ⟩! P | returns ext μ v = ⊥
{ "alphanum_fraction": 0.5693639551, "avg_line_length": 32.0573394495, "ext": "agda", "hexsha": "aad01ad73e699c033668ed391f7804bc57f76739", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/MJ/Semantics/Monadic.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/MJ/Semantics/Monadic.agda", "max_line_length": 105, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/MJ/Semantics/Monadic.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 5104, "size": 13977 }
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} module Light.Implementation.Data.Natural where open import Light.Library.Data.Natural using (Library ; Dependencies) import Light.Implementation.Relation.Decidable import Light.Implementation.Relation.Binary.Equality.Propositional import Light.Package open import Light.Library.Relation.Decidable using (Decidable ; yes ; no ; if_then_else_) import Light.Implementation.Relation.Binary.Equality.Propositional.Decidable as DecidablePropositional open import Light.Library.Relation.Binary using (reflexivity ; congruence) open import Light.Library.Relation.Binary.Equality using (_≈_ ; wrap) open import Agda.Builtin.Equality using (refl) instance dependencies : Dependencies dependencies = record {} instance library : Library dependencies library = record { Implementation } where module Implementation where data ℕ : Set where zero : ℕ successor : ℕ → ℕ {-# COMPILE JS ℕ = (a, cons) => a === 0n ? cons.zero() : cons.successor(a - 1n) #-} {-# COMPILE JS zero = 0n #-} {-# COMPILE JS successor = a => a + 1n #-} postulate _+_ _∗_ _//_ _∸_ : ℕ → ℕ → ℕ {-# COMPILE JS _+_ = () => a => b => a + b #-} {-# COMPILE JS _∗_ = () => a => b => a * b #-} {-# COMPILE JS _//_ = () => a => b => a / b #-} {-# COMPILE JS _∸_ = () => a => b => a < b ? 0n : a - b #-} predecessor : _ predecessor a = a ∸ successor zero private _≈?_ : ∀ (a b : ℕ) → Decidable (a ≈ b) zero ≈? zero = yes reflexivity successor _ ≈? zero = no λ () zero ≈? successor _ = no λ () successor a ≈? successor b = if a ≈? b then (λ ⦃ a‐≡‐b ⦄ → yes (congruence a‐≡‐b)) else (λ ⦃ f ⦄ → no λ {refl → f reflexivity}) equals = record { equals = wrap (record { are = λ a b → a ≈? b }) } module EqualityProperties = DecidablePropositional.Main _≈?_
{ "alphanum_fraction": 0.5416479063, "avg_line_length": 41.1296296296, "ext": "agda", "hexsha": "be32d8c44df4b42e591f67d62c19a7ac08c42e48", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "Zambonifofex/lightlib", "max_forks_repo_path": "Light/Implementation/Data/Natural.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "Zambonifofex/lightlib", "max_issues_repo_path": "Light/Implementation/Data/Natural.agda", "max_line_length": 102, "max_stars_count": 1, "max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "zamfofex/lightlib", "max_stars_repo_path": "Light/Implementation/Data/Natural.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z", "num_tokens": 562, "size": 2221 }
module silly0 where record SingleSortedAlgebra : Set₁ where field Carrier : Set _⊕_ : Carrier → Carrier → Carrier {- One of my aims to introduce construct “fields-of”: record SingleSortedAlgebraWithConstant : Set₁ where fields-of SingleSortedAlgebra renaming (_⊕_ to _⟨$⟩_) field ε : Carrier Should have the same net result as: record SingleSortedAlgebraWithConstant : Set₁ where field Carrier : Set _⟨$⟩_ : Carrier → Carrier → Carrier ε : Carrier -}
{ "alphanum_fraction": 0.6385321101, "avg_line_length": 20.9615384615, "ext": "agda", "hexsha": "b1dad0a07922cbd8ea5515e417aa569956e17169", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "silly0.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "silly0.agda", "max_line_length": 60, "max_stars_count": null, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "silly0.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 144, "size": 545 }
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} module Light.Library.Data.Boolean where open import Light.Level using (Level ; Setω ; Lifted) open import Light.Variable.Sets open import Light.Library.Data.Unit as Unit using (Unit) open import Light.Library.Data.Empty as Empty using (Empty) open import Light.Package using (Package) open import Light.Library.Relation.Binary using (SelfTransitive ; SelfSymmetric ; Reflexive) open import Light.Library.Relation.Binary.Equality as ≈ using (_≈_) open import Light.Library.Relation.Binary.Equality.Decidable using (DecidableSelfEquality) import Light.Library.Relation.Decidable open import Light.Library.Relation using (False) record Dependencies : Setω where field ⦃ unit‐package ⦄ : Package record { Unit } ⦃ empty‐package ⦄ : Package record { Empty } record Library (dependencies : Dependencies) : Setω where field ℓ : Level Boolean : Set ℓ true false : Boolean if_then_else_ : Boolean → 𝕒 → 𝕒 → 𝕒 ¬_ : Boolean → Boolean _∧_ _∨_ _⇢_ : Boolean → Boolean → Boolean true‐is‐true : if true then Lifted (Empty.ℓ) Unit else Lifted (Unit.ℓ) Empty false‐is‐false : if false then Lifted (Unit.ℓ) Empty else Lifted (Empty.ℓ) Unit ⦃ equals ⦄ : DecidableSelfEquality Boolean ⦃ ≈‐transitive ⦄ : SelfTransitive (≈.self‐relation Boolean) ⦃ ≈‐symmetric ⦄ : SelfSymmetric (≈.self‐relation Boolean) ⦃ ≈‐reflexive ⦄ : Reflexive (≈.self‐relation Boolean) true‐≉‐false : False (true ≈ false) open Library ⦃ ... ⦄ public
{ "alphanum_fraction": 0.6638954869, "avg_line_length": 43.1794871795, "ext": "agda", "hexsha": "2bf512c43cf74ead1d17606051f8c70e7ed2310c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "Zambonifofex/lightlib", "max_forks_repo_path": "Light/Library/Data/Boolean.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "Zambonifofex/lightlib", "max_issues_repo_path": "Light/Library/Data/Boolean.agda", "max_line_length": 91, "max_stars_count": 1, "max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "zamfofex/lightlib", "max_stars_repo_path": "Light/Library/Data/Boolean.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z", "num_tokens": 454, "size": 1684 }
module Issue794 where open import Common.Prelude open import Common.MAlonzo postulate A : Set record R : Set where id : A → A id x = x
{ "alphanum_fraction": 0.7112676056, "avg_line_length": 12.9090909091, "ext": "agda", "hexsha": "1b06b8f4994a112dc1c9b0aedd89e5aa13332380", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue794.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue794.agda", "max_line_length": 26, "max_stars_count": 3, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue794.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 44, "size": 142 }
{-# OPTIONS --without-K #-} module LeqLemmas where open import Data.Nat using (ℕ; suc; _+_; _*_; _<_; _≤_; _≤?_; z≤n; s≤s; module ≤-Reasoning) open import Data.Nat.Properties.Simple using (+-comm) open import Data.Nat.Properties using (n≤m+n) open import Relation.Binary using (Decidable) ------------------------------------------------------------------------------ -- Proofs and definitions about ≤ on natural numbers _<?_ : Decidable _<_ i <? j = suc i ≤? j cong+r≤ : ∀ {i j} → i ≤ j → (k : ℕ) → i + k ≤ j + k cong+r≤ {0} {j} z≤n k = n≤m+n j k cong+r≤ {suc i} {0} () k -- absurd cong+r≤ {suc i} {suc j} (s≤s i≤j) k = s≤s (cong+r≤ {i} {j} i≤j k) cong+l≤ : ∀ {i j} → i ≤ j → (k : ℕ) → k + i ≤ k + j cong+l≤ {i} {j} i≤j k = begin (k + i ≡⟨ +-comm k i ⟩ i + k ≤⟨ cong+r≤ i≤j k ⟩ j + k ≡⟨ +-comm j k ⟩ k + j ∎) where open ≤-Reasoning cong*r≤ : ∀ {i j} → i ≤ j → (k : ℕ) → i * k ≤ j * k cong*r≤ {0} {j} z≤n k = z≤n cong*r≤ {suc i} {0} () k -- absurd cong*r≤ {suc i} {suc j} (s≤s i≤j) k = cong+l≤ (cong*r≤ i≤j k) k ------------------------------------------------------------------------------
{ "alphanum_fraction": 0.4060705496, "avg_line_length": 31.2564102564, "ext": "agda", "hexsha": "4eb9f8a8d8f39a9182a585a73d91359cb5ecfff9", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "Univalence/LeqLemmas.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "Univalence/LeqLemmas.agda", "max_line_length": 78, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "Univalence/LeqLemmas.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 496, "size": 1219 }
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use `Data.Vec.Functional` instead. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Table.Base where {-# WARNING_ON_IMPORT "Data.Table.Base was deprecated in v1.2. Use Data.Vec.Functional instead." #-} open import Data.Nat.Base open import Data.Fin.Base open import Data.Product using (_×_ ; _,_) open import Data.List.Base as List using (List) open import Data.Vec.Base as Vec using (Vec) open import Function using (_∘_; flip) open import Level using (Level) private variable a b : Level A : Set a B : Set b ------------------------------------------------------------------------ -- Definition record Table (A : Set a) n : Set a where constructor tabulate field lookup : Fin n → A open Table public ------------------------------------------------------------------------ -- Basic operations head : ∀ {n} → Table A (suc n) → A head t = lookup t zero tail : ∀ {n} → Table A (suc n) → Table A n tail t = tabulate (lookup t ∘ suc) uncons : ∀ {n} → Table A (suc n) → A × Table A n uncons t = head t , tail t remove : ∀ {n} → Fin (suc n) → Table A (suc n) → Table A n remove i t = tabulate (lookup t ∘ punchIn i) ------------------------------------------------------------------------ -- Operations for transforming tables rearrange : ∀ {m n} → (Fin m → Fin n) → Table A n → Table A m rearrange f t = tabulate (lookup t ∘ f) map : ∀ {n} → (A → B) → Table A n → Table B n map f t = tabulate (f ∘ lookup t) _⊛_ : ∀ {n} → Table (A → B) n → Table A n → Table B n fs ⊛ xs = tabulate λ i → lookup fs i (lookup xs i) ------------------------------------------------------------------------ -- Operations for reducing tables foldr : ∀ {n} → (A → B → B) → B → Table A n → B foldr {n = zero} f z t = z foldr {n = suc n} f z t = f (head t) (foldr f z (tail t)) foldl : ∀ {n} → (B → A → B) → B → Table A n → B foldl {n = zero} f z t = z foldl {n = suc n} f z t = foldl f (f z (head t)) (tail t) ------------------------------------------------------------------------ -- Operations for building tables replicate : ∀ {n} → A → Table A n replicate x = tabulate (λ _ → x) ------------------------------------------------------------------------ -- Operations for converting tables toList : ∀ {n} → Table A n → List A toList = List.tabulate ∘ lookup fromList : ∀ (xs : List A) → Table A (List.length xs) fromList = tabulate ∘ List.lookup fromVec : ∀ {n} → Vec A n → Table A n fromVec = tabulate ∘ Vec.lookup toVec : ∀ {n} → Table A n → Vec A n toVec = Vec.tabulate ∘ lookup
{ "alphanum_fraction": 0.4893225331, "avg_line_length": 28.2916666667, "ext": "agda", "hexsha": "a7b282bd3861884191be7f9434b1dd9fac10e4bd", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Data/Table/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/Table/Base.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/Table/Base.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 740, "size": 2716 }
{-# OPTIONS --cubical-compatible #-} -- Large indices are not allowed --cubical-compatible data Singleton {a} {A : Set a} : A → Set where [_] : ∀ x → Singleton x
{ "alphanum_fraction": 0.6424242424, "avg_line_length": 27.5, "ext": "agda", "hexsha": "fea25f3e482a4f20c70b98a05a56c31071779b51", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Fail/LargeIndicesWithoutK.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Fail/LargeIndicesWithoutK.agda", "max_line_length": 53, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Fail/LargeIndicesWithoutK.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 47, "size": 165 }
------------------------------------------------------------------------ -- Bounded vectors (inefficient, concrete implementation) ------------------------------------------------------------------------ -- Vectors of a specified maximum length. module Data.BoundedVec.Inefficient where open import Data.Nat open import Data.List ------------------------------------------------------------------------ -- The type infixr 5 _∷_ data BoundedVec (a : Set) : ℕ → Set where [] : ∀ {n} → BoundedVec a n _∷_ : ∀ {n} (x : a) (xs : BoundedVec a n) → BoundedVec a (suc n) ------------------------------------------------------------------------ -- Increasing the bound -- Note that this operation is linear in the length of the list. ↑ : ∀ {a n} → BoundedVec a n → BoundedVec a (suc n) ↑ [] = [] ↑ (x ∷ xs) = x ∷ ↑ xs ------------------------------------------------------------------------ -- Conversions fromList : ∀ {a} → (xs : List a) → BoundedVec a (length xs) fromList [] = [] fromList (x ∷ xs) = x ∷ fromList xs toList : ∀ {a n} → BoundedVec a n → List a toList [] = [] toList (x ∷ xs) = x ∷ toList xs
{ "alphanum_fraction": 0.4114537445, "avg_line_length": 28.375, "ext": "agda", "hexsha": "a73a6a2b662500c23e99d5b782db7eaa55ee36c9", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Data/BoundedVec/Inefficient.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Data/BoundedVec/Inefficient.agda", "max_line_length": 72, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Data/BoundedVec/Inefficient.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 275, "size": 1135 }
{-# OPTIONS --cubical --safe #-} module Control.Monad.Levels.Mult where open import Prelude open import Control.Monad.Levels.Definition open import Control.Monad.Levels.Eliminators open import Control.Monad.Levels.Zipping open import Data.Bag hiding (bind) open import Path.Reasoning open import Cubical.Foundations.HLevels using (isOfHLevelΠ) bind-alg : (A → Levels B) → Levels-ϕ[ A ] Levels B [ bind-alg f ]-set = trunc [ bind-alg f ] x ∷ _ ⟨ xs ⟩ = zip (⟦ levels-cmon ⟧ trunc f x) ([] ∷ xs) [ bind-alg f ][] = [] [ bind-alg f ]-trail = trail bind : Levels A → (A → Levels B) → Levels B bind xs f = bind-alg f ↓ xs
{ "alphanum_fraction": 0.691318328, "avg_line_length": 28.2727272727, "ext": "agda", "hexsha": "90c02d34ab3533691fe841159cc2f0e2258e313b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Control/Monad/Levels/Mult.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Control/Monad/Levels/Mult.agda", "max_line_length": 71, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Control/Monad/Levels/Mult.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 195, "size": 622 }
open import Level using () renaming (_⊔_ to _⊔ˡ_) open import Function using (_$_; flip) open import Function.Equivalence as FE using () open import Relation.Nullary using (yes; no) open import Relation.Nullary.Decidable using (map) open import Relation.Nullary.Negation using (contradiction) open import Relation.Binary using (Setoid; IsEquivalence; Decidable; DecSetoid; IsDecEquivalence; Tri) open import Relation.Binary.Definitions using (Recomputable) open import Relation.Binary.PropositionalEquality using (_≡_; _≢_) renaming (refl to ≡-refl; sym to ≡-sym; cong to ≡-cong; cong₂ to ≡-cong₂; setoid to ≡-setoid) open Tri open import Data.Empty.Irrelevant using (⊥-elim) open import Data.Maybe using (Maybe; nothing; just) open import Data.List using ([]; _∷_) open import Data.Product using (_,_; proj₁; proj₂) open import Data.Sum using (inj₁; inj₂) open import Algebra.Bundles using (CommutativeRing) open import AKS.Algebra.Bundles using (DecField; IntegralDomain) module AKS.Polynomial.Properties {c ℓ} (F : DecField c ℓ) where open import AKS.Nat using (ℕ; zero; suc; _<_; _≤_; lte; _≟_; _≟⁺_; _∸_; ℕ⁺; ℕ+; ⟅_⇓⟆; ⟅_⇑⟆; pred) renaming (_+_ to _+ℕ_) open import AKS.Nat using (<-cmp; <-≤-connex; m+[n∸m]≡n; ℕ→ℕ⁺→ℕ; ⟅⇓⟆-injective; m<n⇒n∸m≢0; ≢⇒¬≟; <⇒≤; +-suc) open import AKS.Nat using (0≤n; suc-mono-≤; ≤-reflexive; +-mono-<; module ≤-Reasoning) open import AKS.Nat using (_⊔_; ⊔-identityʳ; ⊔-identityˡ; +-distribˡ-⊔; ⊔-least-<; m≤n⇒m⊔n≡n) open import AKS.Nat using (Acc; acc; <-well-founded) import Data.Nat.Properties as Nat open import Polynomial.Simple.AlmostCommutativeRing using (AlmostCommutativeRing; fromCommutativeRing) open import Polynomial.Simple.Reflection using (solve; solveOver) open import Polynomial.Simple.AlmostCommutativeRing.Instances using (module Nat) open Nat.Reflection using (∀⟨_⟩) open DecField F using (0#; 1#; _+_; _*_; -_; _-_; _⁻¹; _/_) renaming (Carrier to C) open DecField F using (C/0; _*-nonzero_; _/-nonzero_; -1#-nonzero; 0#≉1#; 1#≉0#; *-cancelˡ) open DecField F using (_≈_; _≉_; _≈?_; setoid) open Setoid setoid using (refl; sym; trans) open import Relation.Binary.Reasoning.MultiSetoid open DecField F using (ring; commutativeRing; *-commutativeMonoid) open CommutativeRing commutativeRing using (+-assoc; +-comm; +-cong; +-congˡ; +-congʳ; +-identityˡ; +-identityʳ) open CommutativeRing commutativeRing using (*-assoc; *-comm; *-cong; *-congˡ; *-congʳ; *-identityˡ; *-identityʳ; zeroˡ; zeroʳ) open CommutativeRing commutativeRing using (distribˡ; distribʳ; -‿cong; -‿inverseˡ; -‿inverseʳ) open import Algebra.Properties.Ring ring using (-‿distribˡ-*) open import AKS.Exponentiation *-commutativeMonoid using (_^_; _^⁺_; ^-homo; ^-^⁺-homo; x^n≈x^⁺n) open import AKS.Polynomial.Base F using ( Polynomialⁱ; 0ⁱ; 1ⁱ; _+x∙_; _+ⁱ_; -ⁱ_; _∙ⁱ_; _*ⁱ_; x∙_; expand; expandˢ; simplify; +ⁱ-*ⁱ-rawRing ; _≈ⁱ_; _≉ⁱ_; 0≈0; 0≈+; +≈0; +≈+; ≈ⁱ-refl; ≈ⁱ-sym; ≈ⁱ-trans ; Spine; K; _+x^_∙_; Polynomial; 0ᵖ; x^_∙_; ⟦_⟧; ⟦_⟧ˢ; _+?_; 𝐾; 𝑋; _∙𝑋^_ ; 1ᵖ; _+ᵖ_; +ᵖ-spine; +ᵖ-spine-≡-K; +ᵖ-spine-≡; +ᵖ-spine-<; -ᵖ_; _-ᵖ_; _*ᵖ_; *ᵖ-spine; _∙ᵖ_; ∙ᵖ-spine; +ᵖ-*ᵖ-rawRing ; _≈ᵖ_; _≉ᵖ_; 0ᵖ≈; 0ᵖ≉; _≈ˢ_; K≈; +≈; ≈ᵖ-refl; ≈ᵖ-sym; ≈ᵖ-trans ; Degree; deg; degree; degreeˢ; _⊔ᵈ_; _+ᵈ_; _≤ᵈ_; -∞≤_; ≤ᵈ-refl; module ≤ᵈ-Reasoning; -∞; ⟨_⟩; degreeⁱ ) open import Algebra.Structures {A = Polynomialⁱ} _≈ⁱ_ using (IsCommutativeRing; IsRing; IsAbelianGroup; IsGroup; IsMonoid; IsSemigroup; IsMagma) open import Algebra.Definitions {A = Polynomialⁱ} _≈ⁱ_ using ( _DistributesOver_; _DistributesOverʳ_; _DistributesOverˡ_ ; RightIdentity; LeftIdentity; Identity; Associative; Commutative ; RightInverse; LeftInverse; Inverse ; LeftCongruent; RightCongruent; Congruent₂; Congruent₁ ) open import AKS.Algebra.Structures using (IsNonZeroCommutativeRing; IsIntegralDomain) open import Relation.Binary.Morphism.Structures using (IsRelHomomorphism) open import AKS.Algebra.Morphism.Structures using (IsRingHomomorphism; IsRingMonomorphism) open import AKS.Algebra.Morphism.Consequences using (module RingConsequences) +-*-almostCommutativeRing : AlmostCommutativeRing c ℓ +-*-almostCommutativeRing = fromCommutativeRing commutativeRing (λ _ → nothing) expand-cong : ∀ {p} {q} → p ≈ᵖ q → expand p ≈ⁱ expand q expand-cong 0ᵖ≈ = ≈ⁱ-refl expand-cong (0ᵖ≉ ≡-refl p≈ˢq) = expandˢ-cong p≈ˢq where expandˢ-cong : ∀ {n} {p} {q} → p ≈ˢ q → expandˢ n p ≈ⁱ expandˢ n q expandˢ-cong {zero} {K c₁} {K c₂} (K≈ c₁≈c₂) = +≈+ c₁≈c₂ 0≈0 expandˢ-cong {zero} {c₁ +x^ i ∙ p} {c₂ +x^ i ∙ q} (+≈ c₁≈c₂ ≡-refl p≈ˢq) = +≈+ c₁≈c₂ (expandˢ-cong p≈ˢq) expandˢ-cong {suc n} {p} {q} p≈ˢq = +≈+ refl (expandˢ-cong {n} p≈ˢq) 0≉expandˢ[≉0] : ∀ n p → 0ⁱ ≉ⁱ expandˢ n p 0≉expandˢ[≉0] zero (K c) (0≈+ c≈0 _) = contradiction c≈0 (proj₂ c) 0≉expandˢ[≉0] zero (c +x^ i ∙ p) (0≈+ c≈0 _) = contradiction c≈0 (proj₂ c) 0≉expandˢ[≉0] (suc n) p (0≈+ _ 0ⁱ≈expand) = 0≉expandˢ[≉0] n p 0ⁱ≈expand 0≉expand[≉0] : ∀ n p → 0ⁱ ≉ⁱ expand (x^ n ∙ p) 0≉expand[≉0] = 0≉expandˢ[≉0] expand-injective : ∀ {p q} → expand p ≈ⁱ expand q → p ≈ᵖ q expand-injective {0ᵖ} {0ᵖ} pf = ≈ᵖ-refl expand-injective {0ᵖ} {x^ o₂ ∙ q} pf = contradiction pf (0≉expand[≉0] o₂ q) expand-injective {x^ o₁ ∙ p} {0ᵖ} pf = contradiction (≈ⁱ-sym pf) (0≉expand[≉0] o₁ p) expand-injective {x^ o₁ ∙ p} {x^ o₂ ∙ q} pf = expandˢ-injective o₁ o₂ p q pf where expandˢ-injective : ∀ o₁ o₂ p q → expandˢ o₁ p ≈ⁱ expandˢ o₂ q → x^ o₁ ∙ p ≈ᵖ x^ o₂ ∙ q expandˢ-injective zero zero (K c₁) (K c₂) (+≈+ c₁≈c₂ pf) = 0ᵖ≉ ≡-refl (K≈ c₁≈c₂) expandˢ-injective zero zero (K c₁) (c₂ +x^ i₂ ∙ q) (+≈+ c₁≈c₂ pf) = contradiction pf (0≉expandˢ[≉0] _ _) expandˢ-injective zero zero (c₁ +x^ i₁ ∙ p) (K c₂) (+≈+ c₁≈c₂ pf) = contradiction (≈ⁱ-sym pf) (0≉expandˢ[≉0] _ _) expandˢ-injective zero zero (c₁ +x^ i₁ ∙ p) (c₂ +x^ i₂ ∙ q) (+≈+ c₁≈c₂ pf) with expandˢ-injective (pred ⟅ i₁ ⇓⟆) (pred ⟅ i₂ ⇓⟆) p q pf ... | 0ᵖ≉ i₁≡i₂ p≈ˢq = 0ᵖ≉ ≡-refl (+≈ c₁≈c₂ (⟅⇓⟆-injective i₁≡i₂) p≈ˢq) expandˢ-injective zero (suc o₂) (K c₁) q (+≈+ c₁≈c₂ pf) = contradiction pf (0≉expandˢ[≉0] _ _) expandˢ-injective zero (suc o₂) (c₁ +x^ i₁ ∙ p) (K c₂) (+≈+ c₁≈0 pf) = contradiction c₁≈0 (proj₂ c₁) expandˢ-injective zero (suc o₂) (c₁ +x^ i₁ ∙ p) (c₂ +x^ i₂ ∙ q) (+≈+ c₁≈0 pf) = contradiction c₁≈0 (proj₂ c₁) expandˢ-injective (suc o₁) zero p (K c₂) (+≈+ c₁≈c₂ pf) = contradiction (≈ⁱ-sym pf) (0≉expandˢ[≉0] _ _) expandˢ-injective (suc o₁) zero (K c₁) (c₂ +x^ i₂ ∙ q) (+≈+ 0≈c₂ pf) = contradiction (sym 0≈c₂) (proj₂ c₂) expandˢ-injective (suc o₁) zero (c₁ +x^ i₁ ∙ p) (c₂ +x^ i₂ ∙ q) (+≈+ 0≈c₂ pf) = contradiction (sym 0≈c₂) (proj₂ c₂) expandˢ-injective (suc o₁) (suc o₂) p q (+≈+ _ pf) with expandˢ-injective o₁ o₂ p q pf ... | 0ᵖ≉ ≡-refl p≈ˢq = 0ᵖ≉ ≡-refl p≈ˢq infix 4 _≈ˢ?_ _≈ˢ?_ : Decidable _≈ˢ_ (K c₁) ≈ˢ? (K c₂) with proj₁ c₁ ≈? proj₁ c₂ ... | no ¬c₁≈c₂ = no λ { (K≈ c₁≈c₂) → contradiction c₁≈c₂ ¬c₁≈c₂ } ... | yes c₁≈c₂ = yes (K≈ c₁≈c₂) (K c₁) ≈ˢ? (c₂ +x^ m ∙ q) = no λ () (c₁ +x^ n ∙ p) ≈ˢ? (K c₂) = no λ () (c₁ +x^ n ∙ p) ≈ˢ? (c₂ +x^ m ∙ q) with proj₁ c₁ ≈? proj₁ c₂ ... | no ¬c₁≈c₂ = no λ { (+≈ c₁≈c₂ _ _) → contradiction c₁≈c₂ ¬c₁≈c₂ } ... | yes c₁≈c₂ with n ≟⁺ m ... | no n≢m = no λ { (+≈ _ n≡m _) → contradiction n≡m n≢m } ... | yes n≡m with p ≈ˢ? q ... | no ¬p≈ˢq = no λ { (+≈ _ _ p≈ˢq) → contradiction p≈ˢq ¬p≈ˢq } ... | yes p≈ˢq = yes (+≈ c₁≈c₂ n≡m p≈ˢq) infix 4 _≈ᵖ?_ _≈ᵖ?_ : Decidable _≈ᵖ_ 0ᵖ ≈ᵖ? 0ᵖ = yes ≈ᵖ-refl 0ᵖ ≈ᵖ? (x^ m ∙ q) = no λ () (x^ n ∙ p) ≈ᵖ? 0ᵖ = no λ () (x^ n ∙ p) ≈ᵖ? (x^ m ∙ q) with n ≟ m ... | no n≢m = no λ { (0ᵖ≉ n≡m _) → contradiction n≡m n≢m } ... | yes n≡m with p ≈ˢ? q ... | no ¬p≈ˢq = no λ { (0ᵖ≉ _ p≈ˢq) → contradiction p≈ˢq ¬p≈ˢq } ... | yes p≈ˢq = yes (0ᵖ≉ n≡m p≈ˢq) ≈ᵖ-isEquivalence : IsEquivalence _≈ᵖ_ ≈ᵖ-isEquivalence = record { refl = ≈ᵖ-refl ; sym = ≈ᵖ-sym ; trans = ≈ᵖ-trans } ≈ᵖ-isDecEquivalence : IsDecEquivalence _≈ᵖ_ ≈ᵖ-isDecEquivalence = record { isEquivalence = ≈ᵖ-isEquivalence ; _≟_ = _≈ᵖ?_ } ≈ᵖ-setoid : Setoid (c ⊔ˡ ℓ) (c ⊔ˡ ℓ) ≈ᵖ-setoid = record { Carrier = Polynomial ; _≈_ = _≈ᵖ_ ; isEquivalence = ≈ᵖ-isEquivalence } ≈ᵖ-decSetoid : DecSetoid (c ⊔ˡ ℓ) (c ⊔ˡ ℓ) ≈ᵖ-decSetoid = record { Carrier = Polynomial ; _≈_ = _≈ᵖ_ ; isDecEquivalence = ≈ᵖ-isDecEquivalence } ≈ᵖ-recomputable : Recomputable _≈ᵖ_ ≈ᵖ-recomputable {p} {q} [p≈q]₁ with p ≈ᵖ? q ... | yes [p≈q]₂ = [p≈q]₂ ... | no ¬[p≈q] = ⊥-elim (¬[p≈q] [p≈q]₁) ⟦⟧-preserves-≈ᵖ→≈ : ∀ {p q} → p ≈ᵖ q → ∀ x → ⟦ p ⟧ x ≈ ⟦ q ⟧ x ⟦⟧-preserves-≈ᵖ→≈ {0ᵖ} {0ᵖ} 0ᵖ≈ x = refl ⟦⟧-preserves-≈ᵖ→≈ {x^ n ∙ p} {x^ n ∙ q} (0ᵖ≉ ≡-refl p≈ˢq) x = *-congˡ (⟦⟧-preserves-≈ᵖ→≈ˢ p q p≈ˢq x) where ⟦⟧-preserves-≈ᵖ→≈ˢ : ∀ p q → p ≈ˢ q → ∀ x → ⟦ p ⟧ˢ x ≈ ⟦ q ⟧ˢ x ⟦⟧-preserves-≈ᵖ→≈ˢ (K c₁) (K c₂) (K≈ c₁≈c₂) x = c₁≈c₂ ⟦⟧-preserves-≈ᵖ→≈ˢ (c₁ +x^ n ∙ p) (c₂ +x^ n ∙ q) (+≈ c₁≈c₂ ≡-refl p≈ˢq) x = begin⟨ setoid ⟩ proj₁ c₁ + x ^⁺ n * ⟦ p ⟧ˢ x ≈⟨ +-cong c₁≈c₂ (*-congˡ (⟦⟧-preserves-≈ᵖ→≈ˢ p q p≈ˢq x)) ⟩ proj₁ c₂ + x ^⁺ n * ⟦ q ⟧ˢ x ∎ _≈ⁱ?_ : Decidable _≈ⁱ_ 0ⁱ ≈ⁱ? 0ⁱ = yes 0≈0 0ⁱ ≈ⁱ? (c₂ +x∙ q) with c₂ ≈? 0# ... | no c₂≉0 = no λ { (0≈+ c₂≈0 _) → contradiction c₂≈0 c₂≉0 } ... | yes c₂≈0 with 0ⁱ ≈ⁱ? q ... | no 0≉q = no λ { (0≈+ _ 0≈q) → contradiction 0≈q 0≉q } ... | yes 0≈q = yes (0≈+ c₂≈0 0≈q) (c₁ +x∙ p) ≈ⁱ? 0ⁱ with c₁ ≈? 0# ... | no c₁≉0 = no λ { (+≈0 c₁≈0 _) → contradiction c₁≈0 c₁≉0 } ... | yes c₁≈0 with p ≈ⁱ? 0ⁱ ... | no p≉0 = no λ { (+≈0 _ 0≈p) → contradiction (≈ⁱ-sym 0≈p) p≉0 } ... | yes p≈0 = yes (+≈0 c₁≈0 (≈ⁱ-sym p≈0)) (c₁ +x∙ p) ≈ⁱ? (c₂ +x∙ q) with c₁ ≈? c₂ ... | no c₁≉c₂ = no λ { (+≈+ c₁≈c₂ _) → contradiction c₁≈c₂ c₁≉c₂} ... | yes c₁≈c₂ with p ≈ⁱ? q ... | no p≉q = no λ { (+≈+ _ p≈q) → contradiction p≈q p≉q} ... | yes p≈q = yes (+≈+ c₁≈c₂ p≈q) ≈ⁱ-isEquivalence : IsEquivalence _≈ⁱ_ ≈ⁱ-isEquivalence = record { refl = ≈ⁱ-refl ; sym = ≈ⁱ-sym ; trans = ≈ⁱ-trans } ≈ⁱ-isDecEquivalence : IsDecEquivalence _≈ⁱ_ ≈ⁱ-isDecEquivalence = record { isEquivalence = ≈ⁱ-isEquivalence ; _≟_ = _≈ⁱ?_ } ≈ⁱ-setoid : Setoid c (c ⊔ˡ ℓ) ≈ⁱ-setoid = record { Carrier = Polynomialⁱ ; _≈_ = _≈ⁱ_ ; isEquivalence = ≈ⁱ-isEquivalence } ≈ⁱ-decSetoid : DecSetoid c (c ⊔ˡ ℓ) ≈ⁱ-decSetoid = record { Carrier = Polynomialⁱ ; _≈_ = _≈ⁱ_ ; isDecEquivalence = ≈ⁱ-isDecEquivalence } ≈ⁱ-recomputable : Recomputable _≈ⁱ_ ≈ⁱ-recomputable {p} {q} [p≈q]₁ with p ≈ⁱ? q ... | yes [p≈q]₂ = [p≈q]₂ ... | no ¬[p≈q] = ⊥-elim (¬[p≈q] [p≈q]₁) +ⁱ-comm : Commutative _+ⁱ_ +ⁱ-comm 0ⁱ 0ⁱ = ≈ⁱ-refl +ⁱ-comm 0ⁱ (c₂ +x∙ q) = ≈ⁱ-refl +ⁱ-comm (c₁ +x∙ p) 0ⁱ = ≈ⁱ-refl +ⁱ-comm (c₁ +x∙ p) (c₂ +x∙ q) = +≈+ (+-comm c₁ c₂) (+ⁱ-comm p q) +ⁱ-identityˡ : LeftIdentity 0ⁱ _+ⁱ_ +ⁱ-identityˡ _ = ≈ⁱ-refl +ⁱ-identityʳ : RightIdentity 0ⁱ _+ⁱ_ +ⁱ-identityʳ 0ⁱ = ≈ⁱ-refl +ⁱ-identityʳ (c +x∙ p) = ≈ⁱ-refl +ⁱ-identity : Identity 0ⁱ _+ⁱ_ +ⁱ-identity = +ⁱ-identityˡ , +ⁱ-identityʳ +ⁱ-congˡ : LeftCongruent _+ⁱ_ +ⁱ-congˡ {0ⁱ} {p} {q} p≈q = p≈q +ⁱ-congˡ {c₁ +x∙ r} {0ⁱ} {0ⁱ} 0≈0 = ≈ⁱ-refl +ⁱ-congˡ {c₁ +x∙ r} {0ⁱ} {c₃ +x∙ q} (0≈+ c₃≈0 0≈q)= +≈+ (begin⟨ setoid ⟩ c₁ ≈⟨ sym (+-identityʳ c₁) ⟩ c₁ + 0# ≈⟨ +-congˡ (sym c₃≈0) ⟩ c₁ + c₃ ∎) (begin⟨ ≈ⁱ-setoid ⟩ r ≈⟨ ≈ⁱ-sym (+ⁱ-identityʳ r) ⟩ r +ⁱ 0ⁱ ≈⟨ +ⁱ-congˡ 0≈q ⟩ r +ⁱ q ∎) +ⁱ-congˡ {c₁ +x∙ r} {c₂ +x∙ p} {0ⁱ} (+≈0 c₂≈0 0≈p) = +≈+ (begin⟨ setoid ⟩ c₁ + c₂ ≈⟨ +-congˡ c₂≈0 ⟩ c₁ + 0# ≈⟨ +-identityʳ c₁ ⟩ c₁ ∎) (begin⟨ ≈ⁱ-setoid ⟩ r +ⁱ p ≈⟨ +ⁱ-congˡ (≈ⁱ-sym 0≈p) ⟩ r +ⁱ 0ⁱ ≈⟨ +ⁱ-identityʳ r ⟩ r ∎) +ⁱ-congˡ {c₁ +x∙ r} {c₂ +x∙ p} {c₃ +x∙ q} (+≈+ c₂≈c₃ p≈q) = +≈+ (+-congˡ c₂≈c₃) (+ⁱ-congˡ p≈q) +ⁱ-congʳ : RightCongruent _+ⁱ_ +ⁱ-congʳ {r} {p} {q} p≈q = begin⟨ ≈ⁱ-setoid ⟩ p +ⁱ r ≈⟨ +ⁱ-comm p r ⟩ r +ⁱ p ≈⟨ +ⁱ-congˡ p≈q ⟩ r +ⁱ q ≈⟨ +ⁱ-comm r q ⟩ q +ⁱ r ∎ +ⁱ-cong : Congruent₂ _+ⁱ_ +ⁱ-cong {p} {q} {r} {s} p≈q r≈s = begin⟨ ≈ⁱ-setoid ⟩ p +ⁱ r ≈⟨ +ⁱ-congˡ r≈s ⟩ p +ⁱ s ≈⟨ +ⁱ-congʳ p≈q ⟩ q +ⁱ s ∎ +ⁱ-isMagma : IsMagma _+ⁱ_ +ⁱ-isMagma = record { isEquivalence = ≈ⁱ-isEquivalence ; ∙-cong = +ⁱ-cong } +ⁱ-assoc : Associative _+ⁱ_ +ⁱ-assoc 0ⁱ q r = ≈ⁱ-refl +ⁱ-assoc (c₁ +x∙ p) 0ⁱ r = ≈ⁱ-refl +ⁱ-assoc (c₁ +x∙ p) (c₂ +x∙ q) 0ⁱ = ≈ⁱ-refl +ⁱ-assoc (c₁ +x∙ p) (c₂ +x∙ q) (c₃ +x∙ r) = +≈+ (+-assoc c₁ c₂ c₃) (+ⁱ-assoc p q r ) +ⁱ-isSemigroup : IsSemigroup _+ⁱ_ +ⁱ-isSemigroup = record { isMagma = +ⁱ-isMagma ; assoc = +ⁱ-assoc } open import Algebra.FunctionProperties.Consequences ≈ⁱ-setoid using (comm+idˡ⇒idʳ; comm+invˡ⇒invʳ; comm+distrˡ⇒distrʳ) +ⁱ-isMonoid : IsMonoid _+ⁱ_ 0ⁱ +ⁱ-isMonoid = record { isSemigroup = +ⁱ-isSemigroup ; identity = +ⁱ-identity } -ⁱ‿inverseˡ : LeftInverse 0ⁱ -ⁱ_ _+ⁱ_ -ⁱ‿inverseˡ 0ⁱ = ≈ⁱ-refl -ⁱ‿inverseˡ (c +x∙ p) = +≈0 (begin⟨ setoid ⟩ - 1# * c + c ≈⟨ +-congʳ (sym (-‿distribˡ-* 1# c)) ⟩ - (1# * c) + c ≈⟨ +-congʳ (-‿cong (*-identityˡ c)) ⟩ - c + c ≈⟨ -‿inverseˡ c ⟩ 0# ∎ ) (≈ⁱ-sym (-ⁱ‿inverseˡ p)) -ⁱ‿inverseʳ : RightInverse 0ⁱ -ⁱ_ _+ⁱ_ -ⁱ‿inverseʳ = comm+invˡ⇒invʳ +ⁱ-comm -ⁱ‿inverseˡ -ⁱ‿inverse : Inverse 0ⁱ -ⁱ_ _+ⁱ_ -ⁱ‿inverse = -ⁱ‿inverseˡ , -ⁱ‿inverseʳ ∙ⁱ-cong : ∀ {c₁ c₂} {p q} → c₁ ≈ c₂ → p ≈ⁱ q → c₁ ∙ⁱ p ≈ⁱ c₂ ∙ⁱ q ∙ⁱ-cong {c₁} {c₂} {0ⁱ} {0ⁱ} c₁≈c₂ 0≈0 = 0≈0 ∙ⁱ-cong {c₁} {c₂} {0ⁱ} {c₄ +x∙ q} c₁≈c₂ (0≈+ c₄≈0 0≈q) = 0≈+ (begin⟨ setoid ⟩ c₂ * c₄ ≈⟨ *-congˡ c₄≈0 ⟩ c₂ * 0# ≈⟨ zeroʳ c₂ ⟩ 0# ∎) (∙ⁱ-cong c₁≈c₂ 0≈q) ∙ⁱ-cong {c₁} {c₂} {c₃ +x∙ p} {0ⁱ} c₁≈c₂ (+≈0 c₃≈0 0≈p) = +≈0 (begin⟨ setoid ⟩ c₁ * c₃ ≈⟨ *-congˡ c₃≈0 ⟩ c₁ * 0# ≈⟨ zeroʳ c₁ ⟩ 0# ∎) (∙ⁱ-cong (sym c₁≈c₂) 0≈p) ∙ⁱ-cong {c₁} {c₂} {c₃ +x∙ p} {c₄ +x∙ q} c₁≈c₂ (+≈+ c₃≈c₄ p≈q) = +≈+ (*-cong c₁≈c₂ c₃≈c₄) (∙ⁱ-cong c₁≈c₂ p≈q) -ⁱ‿cong : Congruent₁ (-ⁱ_) -ⁱ‿cong = ∙ⁱ-cong refl +ⁱ-isGroup : IsGroup _+ⁱ_ 0ⁱ (-ⁱ_) +ⁱ-isGroup = record { isMonoid = +ⁱ-isMonoid ; inverse = -ⁱ‿inverse ; ⁻¹-cong = -ⁱ‿cong } +ⁱ-isAbelianGroup : IsAbelianGroup _+ⁱ_ 0ⁱ (-ⁱ_) +ⁱ-isAbelianGroup = record { isGroup = +ⁱ-isGroup ; comm = +ⁱ-comm } *ⁱ-comm : Commutative _*ⁱ_ *ⁱ-comm 0ⁱ 0ⁱ = ≈ⁱ-refl *ⁱ-comm 0ⁱ (c₂ +x∙ q) = ≈ⁱ-refl *ⁱ-comm (c₁ +x∙ p) 0ⁱ = ≈ⁱ-refl *ⁱ-comm (c₁ +x∙ p) (c₂ +x∙ q) = +≈+ (*-comm c₁ c₂) (+ⁱ-cong (+ⁱ-comm (c₁ ∙ⁱ q) (c₂ ∙ⁱ p)) (+≈+ refl (*ⁱ-comm p q))) 0≈0∙p : ∀ p → 0ⁱ ≈ⁱ 0# ∙ⁱ p 0≈0∙p 0ⁱ = 0≈0 0≈0∙p (c +x∙ p) = 0≈+ (zeroˡ c) (0≈0∙p p) *ⁱ-zeroʳ : ∀ r → r *ⁱ 0ⁱ ≈ⁱ 0ⁱ *ⁱ-zeroʳ 0ⁱ = ≈ⁱ-refl *ⁱ-zeroʳ (c +x∙ p) = ≈ⁱ-refl *ⁱ-congˡ : LeftCongruent _*ⁱ_ *ⁱ-congˡ {0ⁱ} {p} {q} p≈q = ≈ⁱ-refl *ⁱ-congˡ {c₁ +x∙ r} {0ⁱ} {0ⁱ} 0≈0 = ≈ⁱ-refl *ⁱ-congˡ {c₁ +x∙ r} {0ⁱ} {c₃ +x∙ q} (0≈+ c₃≈0 0≈q) = 0≈+ (begin⟨ setoid ⟩ c₁ * c₃ ≈⟨ *-congˡ c₃≈0 ⟩ c₁ * 0# ≈⟨ zeroʳ c₁ ⟩ 0# ∎) $ begin⟨ ≈ⁱ-setoid ⟩ c₁ ∙ⁱ 0ⁱ +ⁱ 0ⁱ +ⁱ 0ⁱ ≈⟨ +ⁱ-cong (+ⁱ-cong (∙ⁱ-cong (refl {c₁}) 0≈q) (0≈0∙p r)) (0≈+ refl (≈ⁱ-sym (*ⁱ-zeroʳ r))) ⟩ c₁ ∙ⁱ q +ⁱ 0# ∙ⁱ r +ⁱ x∙ (r *ⁱ 0ⁱ) ≈⟨ +ⁱ-cong (+ⁱ-congˡ {c₁ ∙ⁱ q} (∙ⁱ-cong (sym c₃≈0) ≈ⁱ-refl)) (+≈+ refl (*ⁱ-congˡ {r} 0≈q)) ⟩ c₁ ∙ⁱ q +ⁱ c₃ ∙ⁱ r +ⁱ x∙ (r *ⁱ q) ∎ *ⁱ-congˡ {c₁ +x∙ r} {c₂ +x∙ p} {0ⁱ} (+≈0 c₂≈0 0≈p) = +≈0 (begin⟨ setoid ⟩ c₁ * c₂ ≈⟨ *-congˡ c₂≈0 ⟩ c₁ * 0# ≈⟨ zeroʳ c₁ ⟩ 0# ∎) $ begin⟨ ≈ⁱ-setoid ⟩ c₁ ∙ⁱ 0ⁱ +ⁱ 0ⁱ +ⁱ 0ⁱ ≈⟨ +ⁱ-cong (+ⁱ-cong (∙ⁱ-cong (refl {c₁}) 0≈p) (0≈0∙p r)) (0≈+ refl (≈ⁱ-sym (*ⁱ-zeroʳ r))) ⟩ c₁ ∙ⁱ p +ⁱ 0# ∙ⁱ r +ⁱ x∙ (r *ⁱ 0ⁱ) ≈⟨ +ⁱ-cong (+ⁱ-congˡ {c₁ ∙ⁱ p} (∙ⁱ-cong (sym c₂≈0) ≈ⁱ-refl)) (+≈+ refl (*ⁱ-congˡ {r} 0≈p)) ⟩ c₁ ∙ⁱ p +ⁱ c₂ ∙ⁱ r +ⁱ x∙ (r *ⁱ p) ∎ *ⁱ-congˡ {c₁ +x∙ r} {c₂ +x∙ p} {c₃ +x∙ q} (+≈+ c₂≈c₃ p≈q) = +≈+ (*-congˡ c₂≈c₃) (+ⁱ-cong (+ⁱ-cong (∙ⁱ-cong refl p≈q) (∙ⁱ-cong c₂≈c₃ ≈ⁱ-refl)) (+≈+ refl (*ⁱ-congˡ p≈q))) *ⁱ-congʳ : RightCongruent _*ⁱ_ *ⁱ-congʳ {r} {p} {q} p≈q = begin⟨ ≈ⁱ-setoid ⟩ p *ⁱ r ≈⟨ *ⁱ-comm p r ⟩ r *ⁱ p ≈⟨ *ⁱ-congˡ p≈q ⟩ r *ⁱ q ≈⟨ *ⁱ-comm r q ⟩ q *ⁱ r ∎ *ⁱ-cong : Congruent₂ _*ⁱ_ *ⁱ-cong {p} {q} {r} {s} p≈q r≈s = begin⟨ ≈ⁱ-setoid ⟩ p *ⁱ r ≈⟨ *ⁱ-congˡ r≈s ⟩ p *ⁱ s ≈⟨ *ⁱ-congʳ p≈q ⟩ q *ⁱ s ∎ *ⁱ-isMagma : IsMagma _*ⁱ_ *ⁱ-isMagma = record { isEquivalence = ≈ⁱ-isEquivalence ; ∙-cong = *ⁱ-cong } ∙ⁱ-distrib-+ⁱ : ∀ c p q → c ∙ⁱ (p +ⁱ q) ≈ⁱ c ∙ⁱ p +ⁱ c ∙ⁱ q ∙ⁱ-distrib-+ⁱ c₁ 0ⁱ q = ≈ⁱ-refl ∙ⁱ-distrib-+ⁱ c₁ (c₂ +x∙ p) 0ⁱ = ≈ⁱ-refl ∙ⁱ-distrib-+ⁱ c₁ (c₂ +x∙ p) (c₃ +x∙ q) = +≈+ (distribˡ c₁ c₂ c₃) (∙ⁱ-distrib-+ⁱ c₁ p q) ∙ⁱ-distrib-* : ∀ c₁ c₂ p → (c₁ * c₂) ∙ⁱ p ≈ⁱ c₁ ∙ⁱ (c₂ ∙ⁱ p) ∙ⁱ-distrib-* c₁ c₂ 0ⁱ = ≈ⁱ-refl ∙ⁱ-distrib-* c₁ c₂ (c₃ +x∙ p) = +≈+ (*-assoc c₁ c₂ c₃) (∙ⁱ-distrib-* c₁ c₂ p) x∙-distrib-+ⁱ : ∀ p q → x∙ (p +ⁱ q) ≈ⁱ x∙ p +ⁱ x∙ q x∙-distrib-+ⁱ 0ⁱ q = +≈+ (sym (+-identityʳ 0#)) (+ⁱ-identityˡ q) x∙-distrib-+ⁱ (c₁ +x∙ p) 0ⁱ = +≈+ (sym (+-identityʳ 0#)) ≈ⁱ-refl x∙-distrib-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) = +≈+ (sym (+-identityʳ 0#)) ≈ⁱ-refl ∙ⁱ-distrib-+ : ∀ c₁ c₂ p → (c₁ + c₂) ∙ⁱ p ≈ⁱ c₁ ∙ⁱ p +ⁱ c₂ ∙ⁱ p ∙ⁱ-distrib-+ c₁ c₂ 0ⁱ = ≈ⁱ-refl ∙ⁱ-distrib-+ c₁ c₂ (c₃ +x∙ p) = +≈+ (distribʳ c₃ c₁ c₂) (∙ⁱ-distrib-+ c₁ c₂ p) *ⁱ-distribˡ-+ⁱ : _*ⁱ_ DistributesOverˡ _+ⁱ_ *ⁱ-distribˡ-+ⁱ 0ⁱ p q = ≈ⁱ-refl *ⁱ-distribˡ-+ⁱ (c₁ +x∙ r) 0ⁱ q = ≈ⁱ-refl *ⁱ-distribˡ-+ⁱ (c₁ +x∙ r) (c₂ +x∙ p) 0ⁱ = ≈ⁱ-refl *ⁱ-distribˡ-+ⁱ (c₁ +x∙ r) (c₂ +x∙ p) (c₃ +x∙ q) = +≈+ (distribˡ c₁ c₂ c₃) $ begin⟨ ≈ⁱ-setoid ⟩ c₁ ∙ⁱ (p +ⁱ q) +ⁱ (c₂ + c₃) ∙ⁱ r +ⁱ x∙ (r *ⁱ (p +ⁱ q)) ≈⟨ +ⁱ-cong (+ⁱ-cong (∙ⁱ-distrib-+ⁱ c₁ p q) (∙ⁱ-distrib-+ c₂ c₃ r)) (+≈+ refl (*ⁱ-distribˡ-+ⁱ r p q)) ⟩ (c₁ ∙ⁱ p +ⁱ c₁ ∙ⁱ q) +ⁱ (c₂ ∙ⁱ r +ⁱ c₃ ∙ⁱ r) +ⁱ x∙ (r *ⁱ p +ⁱ r *ⁱ q) ≈⟨ +ⁱ-cong (≈ⁱ-sym (+ⁱ-assoc (c₁ ∙ⁱ p +ⁱ c₁ ∙ⁱ q) _ _)) (x∙-distrib-+ⁱ (r *ⁱ p) (r *ⁱ q)) ⟩ ((c₁ ∙ⁱ p +ⁱ c₁ ∙ⁱ q) +ⁱ c₂ ∙ⁱ r) +ⁱ c₃ ∙ⁱ r +ⁱ (x∙ (r *ⁱ p) +ⁱ x∙ (r *ⁱ q)) ≈⟨ final (c₁ ∙ⁱ p) _ _ _ _ _ ⟩ c₁ ∙ⁱ p +ⁱ c₂ ∙ⁱ r +ⁱ x∙ (r *ⁱ p) +ⁱ (c₁ ∙ⁱ q +ⁱ c₃ ∙ⁱ r +ⁱ x∙ (r *ⁱ q)) ∎ where final : ∀ a b c d x y → ((a +ⁱ b) +ⁱ c) +ⁱ d +ⁱ (x +ⁱ y) ≈ⁱ a +ⁱ c +ⁱ x +ⁱ (b +ⁱ d +ⁱ y) final a b c d x y = begin⟨ ≈ⁱ-setoid ⟩ (((a +ⁱ b) +ⁱ c) +ⁱ d) +ⁱ (x +ⁱ y) ≈⟨ +ⁱ-congʳ (+ⁱ-congʳ (+ⁱ-assoc a b c)) ⟩ ((a +ⁱ (b +ⁱ c)) +ⁱ d) +ⁱ (x +ⁱ y) ≈⟨ +ⁱ-congʳ (+ⁱ-congʳ (+ⁱ-congˡ {a} (+ⁱ-comm b c))) ⟩ ((a +ⁱ (c +ⁱ b)) +ⁱ d) +ⁱ (x +ⁱ y) ≈⟨ +ⁱ-congʳ (+ⁱ-assoc a (c +ⁱ b) d) ⟩ (a +ⁱ ((c +ⁱ b) +ⁱ d)) +ⁱ (x +ⁱ y) ≈⟨ +ⁱ-congʳ (+ⁱ-congˡ {a} (+ⁱ-assoc c b d)) ⟩ (a +ⁱ (c +ⁱ (b +ⁱ d))) +ⁱ (x +ⁱ y) ≈⟨ +ⁱ-congʳ (≈ⁱ-sym (+ⁱ-assoc a c (b +ⁱ d))) ⟩ ((a +ⁱ c) +ⁱ (b +ⁱ d)) +ⁱ (x +ⁱ y) ≈⟨ +ⁱ-assoc (a +ⁱ c) (b +ⁱ d) (x +ⁱ y) ⟩ (a +ⁱ c) +ⁱ ((b +ⁱ d) +ⁱ (x +ⁱ y)) ≈⟨ +ⁱ-congˡ {a +ⁱ c} (≈ⁱ-sym (+ⁱ-assoc (b +ⁱ d) x y)) ⟩ (a +ⁱ c) +ⁱ (((b +ⁱ d) +ⁱ x) +ⁱ y) ≈⟨ +ⁱ-congˡ {a +ⁱ c} (+ⁱ-congʳ (+ⁱ-comm (b +ⁱ d) x)) ⟩ (a +ⁱ c) +ⁱ ((x +ⁱ (b +ⁱ d)) +ⁱ y) ≈⟨ +ⁱ-congˡ {a +ⁱ c} (+ⁱ-assoc x (b +ⁱ d) y) ⟩ (a +ⁱ c) +ⁱ (x +ⁱ ((b +ⁱ d) +ⁱ y)) ≈⟨ ≈ⁱ-sym (+ⁱ-assoc (a +ⁱ c) x (b +ⁱ d +ⁱ y)) ⟩ ((a +ⁱ c) +ⁱ x) +ⁱ ((b +ⁱ d) +ⁱ y) ∎ *ⁱ-distribʳ-+ⁱ : _*ⁱ_ DistributesOverʳ _+ⁱ_ *ⁱ-distribʳ-+ⁱ = comm+distrˡ⇒distrʳ +ⁱ-cong *ⁱ-comm *ⁱ-distribˡ-+ⁱ *ⁱ-distrib-+ⁱ : _*ⁱ_ DistributesOver _+ⁱ_ *ⁱ-distrib-+ⁱ = *ⁱ-distribˡ-+ⁱ , *ⁱ-distribʳ-+ⁱ open import AKS.Unsafe using (TODO) +x∙-distribʳ-*ⁱ : ∀ c p q → (c +x∙ p) *ⁱ q ≈ⁱ c ∙ⁱ q +ⁱ x∙ (p *ⁱ q) +x∙-distribʳ-*ⁱ c₁ p 0ⁱ = 0≈+ refl (≈ⁱ-sym (*ⁱ-zeroʳ p)) +x∙-distribʳ-*ⁱ c₁ p (c₂ +x∙ q) = +≈+ (sym (+-identityʳ (c₁ * c₂))) $ begin⟨ ≈ⁱ-setoid ⟩ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p) +ⁱ x∙ (p *ⁱ q) ≈⟨ +ⁱ-congˡ (+≈+ refl (*ⁱ-comm p q)) ⟩ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p) +ⁱ x∙ (q *ⁱ p) ≈⟨ +ⁱ-assoc (c₁ ∙ⁱ q) (c₂ ∙ⁱ p) (x∙ (q *ⁱ p)) ⟩ c₁ ∙ⁱ q +ⁱ (c₂ ∙ⁱ p +ⁱ x∙ (q *ⁱ p)) ≈⟨ +ⁱ-congˡ (≈ⁱ-sym (+x∙-distribʳ-*ⁱ c₂ q p)) ⟩ c₁ ∙ⁱ q +ⁱ (c₂ +x∙ q) *ⁱ p ≈⟨ +ⁱ-congˡ (*ⁱ-comm (c₂ +x∙ q) p) ⟩ c₁ ∙ⁱ q +ⁱ p *ⁱ (c₂ +x∙ q) ∎ +x∙-distribˡ-*ⁱ : ∀ c p q → p *ⁱ (c +x∙ q) ≈ⁱ c ∙ⁱ p +ⁱ x∙ (p *ⁱ q) +x∙-distribˡ-*ⁱ c p q = begin⟨ ≈ⁱ-setoid ⟩ p *ⁱ (c +x∙ q) ≈⟨ *ⁱ-comm p (c +x∙ q) ⟩ (c +x∙ q) *ⁱ p ≈⟨ +x∙-distribʳ-*ⁱ c q p ⟩ c ∙ⁱ p +ⁱ x∙ (q *ⁱ p) ≈⟨ +ⁱ-congˡ (+≈+ refl (*ⁱ-comm q p)) ⟩ c ∙ⁱ p +ⁱ x∙ (p *ⁱ q) ∎ x∙-distrib-*ⁱ : ∀ p q → x∙ (p *ⁱ q) ≈ⁱ p *ⁱ (x∙ q) x∙-distrib-*ⁱ 0ⁱ q = +≈0 refl ≈ⁱ-refl x∙-distrib-*ⁱ (c₁ +x∙ p) 0ⁱ = +≈+ (sym (zeroʳ c₁)) $ begin⟨ ≈ⁱ-setoid ⟩ 0ⁱ +ⁱ 0ⁱ ≈⟨ +ⁱ-cong (0≈0∙p p) (0≈+ refl (≈ⁱ-sym (*ⁱ-zeroʳ p))) ⟩ 0# ∙ⁱ p +ⁱ x∙ (p *ⁱ 0ⁱ) ∎ x∙-distrib-*ⁱ (c₁ +x∙ p) (c₂ +x∙ q) = +≈+ (sym (zeroʳ c₁)) $ begin⟨ ≈ⁱ-setoid ⟩ (c₁ * c₂) +x∙ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q)) ≈⟨ TODO ⟩ (c₁ * c₂) +x∙ (c₁ ∙ⁱ q +ⁱ (c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q))) ≈⟨ +≈+ refl (+ⁱ-congˡ (≈ⁱ-sym (+x∙-distribˡ-*ⁱ c₂ p q))) ⟩ (c₁ * c₂) +x∙ (c₁ ∙ⁱ q +ⁱ p *ⁱ (c₂ +x∙ q)) ≈⟨ TODO ⟩ ((c₁ * c₂) +x∙ (c₁ ∙ⁱ q)) +ⁱ 0# ∙ⁱ p +ⁱ x∙ (p *ⁱ (c₂ +x∙ q)) ∎ *ⁱ-assoc : Associative _*ⁱ_ *ⁱ-assoc 0ⁱ q r = ≈ⁱ-refl *ⁱ-assoc (c₁ +x∙ p) 0ⁱ r = ≈ⁱ-refl *ⁱ-assoc (c₁ +x∙ p) (c₂ +x∙ q) 0ⁱ = ≈ⁱ-refl *ⁱ-assoc (c₁ +x∙ p) (c₂ +x∙ q) (c₃ +x∙ r) = +≈+ (*-assoc c₁ c₂ c₃) $ begin⟨ ≈ⁱ-setoid ⟩ (c₁ * c₂) ∙ⁱ r +ⁱ c₃ ∙ⁱ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q)) +ⁱ x∙ ((c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q)) *ⁱ r) ≈⟨ TODO ⟩ c₁ ∙ⁱ (c₂ ∙ⁱ r) +ⁱ (c₃ ∙ⁱ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p) +ⁱ c₃ ∙ⁱ (x∙ (p *ⁱ q))) +ⁱ x∙ ((c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q)) *ⁱ r) ≈⟨ TODO ⟩ c₁ ∙ⁱ (c₂ ∙ⁱ r +ⁱ c₃ ∙ⁱ q +ⁱ x∙ (q *ⁱ r)) +ⁱ c₂ * c₃ ∙ⁱ p +ⁱ x∙ (p *ⁱ (c₂ ∙ⁱ r +ⁱ c₃ ∙ⁱ q +ⁱ x∙ (q *ⁱ r))) ∎ *ⁱ-isSemigroup : IsSemigroup _*ⁱ_ *ⁱ-isSemigroup = record { isMagma = *ⁱ-isMagma ; assoc = *ⁱ-assoc } ∙ⁱ-identity : ∀ p → 1# ∙ⁱ p ≈ⁱ p ∙ⁱ-identity 0ⁱ = ≈ⁱ-refl ∙ⁱ-identity (c +x∙ p) = +≈+ (*-identityˡ c) (∙ⁱ-identity p) *ⁱ-identityˡ : LeftIdentity 1ⁱ _*ⁱ_ *ⁱ-identityˡ 0ⁱ = ≈ⁱ-refl *ⁱ-identityˡ (c +x∙ p) = +≈+ (*-identityˡ c) $ begin⟨ ≈ⁱ-setoid ⟩ 1# ∙ⁱ p +ⁱ 0ⁱ +ⁱ (0# +x∙ 0ⁱ) ≈⟨ +ⁱ-cong (+ⁱ-congʳ (∙ⁱ-identity p)) (+≈0 refl 0≈0) ⟩ p +ⁱ 0ⁱ +ⁱ 0ⁱ ≈⟨ +ⁱ-identityʳ (p +ⁱ 0ⁱ) ⟩ p +ⁱ 0ⁱ ≈⟨ +ⁱ-identityʳ p ⟩ p ∎ *ⁱ-identityʳ : RightIdentity 1ⁱ _*ⁱ_ *ⁱ-identityʳ = comm+idˡ⇒idʳ *ⁱ-comm *ⁱ-identityˡ *ⁱ-identity : Identity 1ⁱ _*ⁱ_ *ⁱ-identity = *ⁱ-identityˡ , *ⁱ-identityʳ *ⁱ-1ⁱ-isMonoid : IsMonoid _*ⁱ_ 1ⁱ *ⁱ-1ⁱ-isMonoid = record { isSemigroup = *ⁱ-isSemigroup ; identity = *ⁱ-identity } +ⁱ-*ⁱ-isRing : IsRing _+ⁱ_ _*ⁱ_ -ⁱ_ 0ⁱ 1ⁱ +ⁱ-*ⁱ-isRing = record { +-isAbelianGroup = +ⁱ-isAbelianGroup ; *-isMonoid = *ⁱ-1ⁱ-isMonoid ; distrib = *ⁱ-distrib-+ⁱ } +ⁱ-*ⁱ-isCommutativeRing : IsCommutativeRing _+ⁱ_ _*ⁱ_ -ⁱ_ 0ⁱ 1ⁱ +ⁱ-*ⁱ-isCommutativeRing = record { isRing = +ⁱ-*ⁱ-isRing ; *-comm = *ⁱ-comm } +ⁱ-*ⁱ-commutativeRing : CommutativeRing c (c ⊔ˡ ℓ) +ⁱ-*ⁱ-commutativeRing = record { isCommutativeRing = +ⁱ-*ⁱ-isCommutativeRing } open CommutativeRing +ⁱ-*ⁱ-commutativeRing using () renaming (+-rawMonoid to +ⁱ-rawMonoid; zeroˡ to *ⁱ-zeroˡ) +ⁱ-*ⁱ-almostCommutativeRing : AlmostCommutativeRing c (c ⊔ˡ ℓ) +ⁱ-*ⁱ-almostCommutativeRing = fromCommutativeRing +ⁱ-*ⁱ-commutativeRing isZero where isZero : ∀ x → Maybe (0ⁱ ≈ⁱ x) isZero 0ⁱ = just ≈ⁱ-refl isZero (_ +x∙ _) = nothing 0ⁱ≉1ⁱ : 0ⁱ ≉ⁱ 1ⁱ 0ⁱ≉1ⁱ (0≈+ 1#≈0# _) = contradiction 1#≈0# 1#≉0# +ⁱ-*ⁱ-isNonZeroCommutativeRing : IsNonZeroCommutativeRing Polynomialⁱ _≈ⁱ_ _+ⁱ_ _*ⁱ_ -ⁱ_ 0ⁱ 1ⁱ +ⁱ-*ⁱ-isNonZeroCommutativeRing = record { isCommutativeRing = +ⁱ-*ⁱ-isCommutativeRing ; 0#≉1# = 0ⁱ≉1ⁱ } +≉0 : ∀ {c} {p} → c ≈ 0# → c +x∙ p ≉ⁱ 0ⁱ → p ≉ⁱ 0ⁱ +≉0 c≈0 c+x∙p≉0ⁱ p≈0 = contradiction (+≈0 c≈0 (≈ⁱ-sym p≈0)) c+x∙p≉0ⁱ *ⁱ-cancelˡ-lemma₁ : ∀ c₁ p c₂ q → c₁ ≈ 0# → 0ⁱ ≈ⁱ c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q) → p *ⁱ 0ⁱ ≈ⁱ p *ⁱ (c₂ +x∙ q) *ⁱ-cancelˡ-lemma₁ c₁ p c₂ q c₁≈0 pf = begin⟨ ≈ⁱ-setoid ⟩ p *ⁱ 0ⁱ ≈⟨ *ⁱ-zeroʳ p ⟩ 0ⁱ ≈⟨ pf ⟩ c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q) ≈⟨ +ⁱ-congʳ (+ⁱ-congʳ (∙ⁱ-cong c₁≈0 (≈ⁱ-refl {q}))) ⟩ 0# ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q) ≈⟨ +ⁱ-congʳ (+ⁱ-congʳ (≈ⁱ-sym (0≈0∙p q))) ⟩ 0ⁱ +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q) ≈⟨ ≈ⁱ-sym (+x∙-distribˡ-*ⁱ c₂ p q) ⟩ p *ⁱ (c₂ +x∙ q) ∎ *ⁱ-cancelˡ-lemma₂ : ∀ c₁ p c₂ q → c₂ ≈ 0# → 0ⁱ ≈ⁱ c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q) → (c₁ +x∙ p) *ⁱ 0ⁱ ≈ⁱ (c₁ +x∙ p) *ⁱ q *ⁱ-cancelˡ-lemma₂ c₁ p c₂ q c₂≈0 pf = begin⟨ ≈ⁱ-setoid ⟩ (c₁ +x∙ p) *ⁱ 0ⁱ ≈⟨ pf ⟩ c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q) ≈⟨ +ⁱ-congʳ (+ⁱ-congˡ {c₁ ∙ⁱ q} (∙ⁱ-cong c₂≈0 ≈ⁱ-refl)) ⟩ c₁ ∙ⁱ q +ⁱ 0# ∙ⁱ p +ⁱ x∙ (p *ⁱ q) ≈⟨ +ⁱ-congʳ (+ⁱ-congˡ {c₁ ∙ⁱ q} (≈ⁱ-sym (0≈0∙p p))) ⟩ c₁ ∙ⁱ q +ⁱ 0ⁱ +ⁱ x∙ (p *ⁱ q) ≈⟨ +ⁱ-congʳ (+ⁱ-identityʳ (c₁ ∙ⁱ q)) ⟩ c₁ ∙ⁱ q +ⁱ x∙ (p *ⁱ q) ≈⟨ ≈ⁱ-sym (+x∙-distribʳ-*ⁱ c₁ p q) ⟩ (c₁ +x∙ p) *ⁱ q ∎ *ⁱ-cancelˡ : ∀ p {q r} → p ≉ⁱ 0ⁱ → p *ⁱ q ≈ⁱ p *ⁱ r → q ≈ⁱ r *ⁱ-cancelˡ 0ⁱ {q} {r} p≉0 p*q≈p*r = contradiction ≈ⁱ-refl p≉0 *ⁱ-cancelˡ (c₁ +x∙ p) {0ⁱ} {0ⁱ} p≉0 p*q≈p*r = ≈ⁱ-refl *ⁱ-cancelˡ (c₁ +x∙ p) {0ⁱ} {c₃ +x∙ r} p≉0 (0≈+ c₁*c₃≈0 pf) with c₁ ≈? 0# ... | yes c₁≈0 = *ⁱ-cancelˡ p (+≉0 c₁≈0 p≉0) (*ⁱ-cancelˡ-lemma₁ c₁ p c₃ r c₁≈0 pf) ... | no c₁≉0 = 0≈+ c₃≈0 $ *ⁱ-cancelˡ (c₁ +x∙ p) p≉0 (*ⁱ-cancelˡ-lemma₂ c₁ p c₃ r c₃≈0 pf) where c₃≈0 = *-cancelˡ c₁ c₁≉0 $ begin⟨ setoid ⟩ c₁ * c₃ ≈⟨ c₁*c₃≈0 ⟩ 0# ≈⟨ sym (zeroʳ c₁) ⟩ c₁ * 0# ∎ *ⁱ-cancelˡ (c₁ +x∙ p) {c₂ +x∙ q} {0ⁱ} p≉0 (+≈0 c₁*c₂≈0 pf) with c₁ ≈? 0# ... | yes c₁≈0 = *ⁱ-cancelˡ p (+≉0 c₁≈0 p≉0) (≈ⁱ-sym (*ⁱ-cancelˡ-lemma₁ c₁ p c₂ q c₁≈0 pf) ) ... | no c₁≉0 = +≈0 c₂≈0 $ ≈ⁱ-sym (*ⁱ-cancelˡ (c₁ +x∙ p) {q} {0ⁱ} p≉0 (≈ⁱ-sym (*ⁱ-cancelˡ-lemma₂ c₁ p c₂ q c₂≈0 pf))) where c₂≈0 = *-cancelˡ c₁ c₁≉0 $ begin⟨ setoid ⟩ c₁ * c₂ ≈⟨ c₁*c₂≈0 ⟩ 0# ≈⟨ sym (zeroʳ c₁) ⟩ c₁ * 0# ∎ *ⁱ-cancelˡ (c₁ +x∙ p) {c₂ +x∙ q} {c₃ +x∙ r} p≉0 (+≈+ c₁*c₂≈c₁*c₃ pf) with c₁ ≈? 0# ... | yes c₁≈0 = *ⁱ-cancelˡ p (+≉0 c₁≈0 p≉0) $ begin⟨ ≈ⁱ-setoid ⟩ 0ⁱ +ⁱ p *ⁱ (c₂ +x∙ q) ≈⟨ +ⁱ-cong (0≈0∙p q) (+x∙-distribˡ-*ⁱ c₂ p q) ⟩ 0# ∙ⁱ q +ⁱ (c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q)) ≈⟨ +ⁱ-congʳ (∙ⁱ-cong (sym c₁≈0) (≈ⁱ-refl {q})) ⟩ c₁ ∙ⁱ q +ⁱ (c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q)) ≈⟨ ≈ⁱ-sym (+ⁱ-assoc (c₁ ∙ⁱ q) _ _) ⟩ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p) +ⁱ x∙ (p *ⁱ q) ≈⟨ pf ⟩ (c₁ ∙ⁱ r +ⁱ c₃ ∙ⁱ p) +ⁱ x∙ (p *ⁱ r) ≈⟨ +ⁱ-assoc (c₁ ∙ⁱ r) _ _ ⟩ c₁ ∙ⁱ r +ⁱ (c₃ ∙ⁱ p +ⁱ x∙ (p *ⁱ r)) ≈⟨ +ⁱ-congʳ (∙ⁱ-cong c₁≈0 (≈ⁱ-refl {r})) ⟩ 0# ∙ⁱ r +ⁱ (c₃ ∙ⁱ p +ⁱ x∙ (p *ⁱ r)) ≈⟨ +ⁱ-cong (≈ⁱ-sym (0≈0∙p r)) (≈ⁱ-sym (+x∙-distribˡ-*ⁱ c₃ p r)) ⟩ 0ⁱ +ⁱ p *ⁱ (c₃ +x∙ r) ∎ ... | no c₁≉0 = +≈+ c₂≈c₃ $ *ⁱ-cancelˡ (c₁ +x∙ p) p≉0 $ begin⟨ ≈ⁱ-setoid ⟩ 0ⁱ +ⁱ (c₁ +x∙ p) *ⁱ q ≈⟨ +ⁱ-cong (≈ⁱ-sym (-ⁱ‿inverseˡ (c₂ ∙ⁱ p))) (+x∙-distribʳ-*ⁱ c₁ p q) ⟩ (-ⁱ (c₂ ∙ⁱ p) +ⁱ c₂ ∙ⁱ p) +ⁱ (c₁ ∙ⁱ q +ⁱ x∙ (p *ⁱ q)) ≈⟨ lemma (-ⁱ (c₂ ∙ⁱ p)) (c₂ ∙ⁱ p) (c₁ ∙ⁱ q) (x∙ (p *ⁱ q)) ⟩ -ⁱ (c₂ ∙ⁱ p) +ⁱ ((c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p) +ⁱ x∙ (p *ⁱ q)) ≈⟨ +ⁱ-cong (-ⁱ‿cong (∙ⁱ-cong c₂≈c₃ (≈ⁱ-refl {p}))) pf ⟩ -ⁱ (c₃ ∙ⁱ p) +ⁱ ((c₁ ∙ⁱ r +ⁱ c₃ ∙ⁱ p) +ⁱ x∙ (p *ⁱ r)) ≈⟨ ≈ⁱ-sym (lemma (-ⁱ (c₃ ∙ⁱ p)) (c₃ ∙ⁱ p) (c₁ ∙ⁱ r) (x∙ (p *ⁱ r))) ⟩ (-ⁱ (c₃ ∙ⁱ p) +ⁱ c₃ ∙ⁱ p) +ⁱ (c₁ ∙ⁱ r +ⁱ x∙ (p *ⁱ r)) ≈⟨ +ⁱ-cong (-ⁱ‿inverseˡ (c₃ ∙ⁱ p)) (≈ⁱ-sym (+x∙-distribʳ-*ⁱ c₁ p r)) ⟩ 0ⁱ +ⁱ (c₁ +x∙ p) *ⁱ r ∎ where c₂≈c₃ = *-cancelˡ c₁ c₁≉0 c₁*c₂≈c₁*c₃ lemma : ∀ a b c d → (a +ⁱ b) +ⁱ (c +ⁱ d) ≈ⁱ a +ⁱ ((c +ⁱ b) +ⁱ d) lemma = solve +ⁱ-*ⁱ-almostCommutativeRing +ⁱ-*ⁱ-isIntegralDomain : IsIntegralDomain Polynomialⁱ _≈ⁱ_ _+ⁱ_ _*ⁱ_ -ⁱ_ 0ⁱ 1ⁱ +ⁱ-*ⁱ-isIntegralDomain = record { isNonZeroCommutativeRing = +ⁱ-*ⁱ-isNonZeroCommutativeRing ; *-cancelˡ = *ⁱ-cancelˡ } +ⁱ-*ⁱ-integralDomain : IntegralDomain c (c ⊔ˡ ℓ) +ⁱ-*ⁱ-integralDomain = record { isIntegralDomain = +ⁱ-*ⁱ-isIntegralDomain } expandˢ-+x^-lemma : ∀ o n c p → expandˢ o (c +x^ n ∙ p) ≈ⁱ expandˢ o (K c) +ⁱ expandˢ (o +ℕ ⟅ n ⇓⟆) p expandˢ-+x^-lemma zero (ℕ+ n) c₁ p = begin⟨ ≈ⁱ-setoid ⟩ proj₁ c₁ +x∙ expandˢ n p ≈⟨ +≈+ (sym (+-identityʳ (proj₁ c₁))) ≈ⁱ-refl ⟩ (proj₁ c₁ + 0#) +x∙ expandˢ n p ∎ expandˢ-+x^-lemma (suc o) n c₁ p = begin⟨ ≈ⁱ-setoid ⟩ expandˢ (suc o) (c₁ +x^ n ∙ p) ≈⟨ +≈+ (sym (+-identityʳ 0#)) (expandˢ-+x^-lemma o n c₁ p) ⟩ expandˢ (suc o) (K c₁) +ⁱ expandˢ (suc (o +ℕ ⟅ n ⇓⟆)) p ∎ expandˢ-≡-cong : ∀ {o₁ o₂} {p} → o₁ ≡ o₂ → expandˢ o₁ p ≈ⁱ expandˢ o₂ p expandˢ-≡-cong ≡-refl = ≈ⁱ-refl expandˢ-raise₁ : ∀ n o₁ p o₂ q → 0ⁱ ≈ⁱ expandˢ o₁ p +ⁱ expandˢ o₂ q → 0ⁱ ≈ⁱ expandˢ (n +ℕ o₁) p +ⁱ expandˢ (n +ℕ o₂) q expandˢ-raise₁ zero o₁ p o₂ q pf = pf expandˢ-raise₁ (suc n) o₁ p o₂ q pf = 0≈+ (+-identityʳ 0#) (expandˢ-raise₁ n o₁ p o₂ q pf) expandˢ-raise₂ : ∀ n o₁ r o₂ p o₃ q → expandˢ o₁ r ≈ⁱ expandˢ o₂ p +ⁱ expandˢ o₃ q → expandˢ (n +ℕ o₁) r ≈ⁱ expandˢ (n +ℕ o₂) p +ⁱ expandˢ (n +ℕ o₃) q expandˢ-raise₂ zero o₁ r o₂ p o₃ q pf = pf expandˢ-raise₂ (suc n) o₁ r o₂ p o₃ q pf = +≈+ (sym (+-identityʳ 0#)) (expandˢ-raise₂ n o₁ r o₂ p o₃ q pf) expandˢ-+ᵖ-spine-≡-K-homo-lemma₁ : ∀ o c₁ c₂ → proj₁ c₁ + proj₁ c₂ ≈ 0# → 0ⁱ ≈ⁱ expandˢ o (K c₁) +ⁱ expandˢ o (K c₂) expandˢ-+ᵖ-spine-≡-K-homo-lemma₁ zero c₁ c₂ c₁+c₂≈0 = 0≈+ c₁+c₂≈0 0≈0 expandˢ-+ᵖ-spine-≡-K-homo-lemma₁ (suc o) c₁ c₂ c₁+c₂≈0 = 0≈+ (+-identityʳ 0#) (expandˢ-+ᵖ-spine-≡-K-homo-lemma₁ o c₁ c₂ c₁+c₂≈0) expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ : ∀ o c₁ c₂ c₁+c₂≉0 → expandˢ o (K (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0)) ≈ⁱ expandˢ o (K c₁) +ⁱ expandˢ o (K c₂) expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ zero c₁ c₂ c₁+c₂≉0 = ≈ⁱ-refl expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ (suc o) c₁ c₂ c₁+c₂≉0 = +≈+ (sym (+-identityʳ 0#)) (expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ o c₁ c₂ c₁+c₂≉0) expand-+ᵖ-spine-≡-K-homo : ∀ o c p → expand (+ᵖ-spine-≡-K o c p) ≈ⁱ expandˢ o (K c) +ⁱ expandˢ o p expand-+ᵖ-spine-≡-K-homo o c₁ (K c₂) with proj₁ c₁ + proj₁ c₂ ≈? 0# ... | yes c₁+c₂≈0 = expandˢ-+ᵖ-spine-≡-K-homo-lemma₁ o c₁ c₂ c₁+c₂≈0 ... | no c₁+c₂≉0 = expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ o c₁ c₂ c₁+c₂≉0 expand-+ᵖ-spine-≡-K-homo o c₁ (c₂ +x^ n₂ ∙ p) with proj₁ c₁ + proj₁ c₂ ≈? 0# ... | yes c₁+c₂≈0 = begin⟨ ≈ⁱ-setoid ⟩ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p ≈⟨ ≈ⁱ-sym (+ⁱ-identityˡ (expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p)) ⟩ 0ⁱ +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p ≈⟨ +ⁱ-congʳ (expandˢ-+ᵖ-spine-≡-K-homo-lemma₁ o c₁ c₂ c₁+c₂≈0) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p ≈⟨ +ⁱ-assoc (expandˢ o (K c₁)) (expandˢ o (K c₂)) (expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p) ⟩ expandˢ o (K c₁) +ⁱ (expandˢ o (K c₂) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p) ≈⟨ +ⁱ-congˡ (≈ⁱ-sym (expandˢ-+x^-lemma o n₂ c₂ p)) ⟩ expandˢ o (K c₁) +ⁱ expandˢ o (c₂ +x^ n₂ ∙ p) ∎ ... | no c₁+c₂≉0 = begin⟨ ≈ⁱ-setoid ⟩ expandˢ o ((proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0) +x^ n₂ ∙ p) ≈⟨ expandˢ-+x^-lemma o n₂ (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0) p ⟩ expandˢ o (K (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0)) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p ≈⟨ +ⁱ-congʳ (expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ o c₁ c₂ c₁+c₂≉0) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p ≈⟨ +ⁱ-assoc (expandˢ o (K c₁)) (expandˢ o (K c₂)) (expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p) ⟩ expandˢ o (K c₁) +ⁱ (expandˢ o (K c₂) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) p) ≈⟨ +ⁱ-congˡ (≈ⁱ-sym (expandˢ-+x^-lemma o n₂ c₂ p)) ⟩ expandˢ o (K c₁) +ⁱ expandˢ o (c₂ +x^ n₂ ∙ p) ∎ expand-+ᵖ-spine-≡-homo : ∀ o p q → expand (+ᵖ-spine-≡ o p q) ≈ⁱ expandˢ o p +ⁱ expandˢ o q expand-+ᵖ-spine-<-homo : ∀ o₁ p o₂ q o₁<o₂ → expand (+ᵖ-spine-< o₁ p o₂ q o₁<o₂) ≈ⁱ expandˢ o₁ p +ⁱ expandˢ o₂ q expand-+ᵖ-spine-homo : ∀ o₁ p o₂ q → expand (+ᵖ-spine o₁ p o₂ q) ≈ⁱ expandˢ o₁ p +ⁱ expandˢ o₂ q expand-+ᵖ-spine-≡-homo-permute : ∀ a b x y → (a +ⁱ b) +ⁱ (x +ⁱ y) ≈ⁱ (a +ⁱ x) +ⁱ (b +ⁱ y) expand-+ᵖ-spine-≡-homo-permute = solve +ⁱ-*ⁱ-almostCommutativeRing expand-+ᵖ-spine-≡-homo o (K c₁) q = expand-+ᵖ-spine-≡-K-homo o c₁ q expand-+ᵖ-spine-≡-homo o (c₁ +x^ n₁ ∙ p) (K c₂) = begin⟨ ≈ⁱ-setoid ⟩ expand (+ᵖ-spine-≡-K o c₂ (c₁ +x^ n₁ ∙ p)) ≈⟨ expand-+ᵖ-spine-≡-K-homo o c₂ (c₁ +x^ n₁ ∙ p) ⟩ expandˢ o (K c₂) +ⁱ expandˢ o (c₁ +x^ n₁ ∙ p) ≈⟨ +ⁱ-comm (expandˢ o (K c₂)) (expandˢ o (c₁ +x^ n₁ ∙ p)) ⟩ expandˢ o (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o (K c₂) ∎ expand-+ᵖ-spine-≡-homo o (c₁ +x^ n₁ ∙ p) (c₂ +x^ n₂ ∙ q) with proj₁ c₁ + proj₁ c₂ ≈? 0# ... | yes c₁+c₂≈0 = begin⟨ ≈ⁱ-setoid ⟩ expand (+ᵖ-spine (o +ℕ ⟅ n₁ ⇓⟆) p (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ expand-+ᵖ-spine-homo (o +ℕ ⟅ n₁ ⇓⟆) p (o +ℕ ⟅ n₂ ⇓⟆) q ⟩ expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q ≈⟨ ≈ⁱ-sym (+ⁱ-identityˡ (expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q)) ⟩ 0ⁱ +ⁱ (expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ +ⁱ-congʳ (expandˢ-+ᵖ-spine-≡-K-homo-lemma₁ o c₁ c₂ c₁+c₂≈0) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ (expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ expand-+ᵖ-spine-≡-homo-permute (expandˢ o (K c₁)) (expandˢ o (K c₂)) _ _ ⟩ (expandˢ o (K c₁) +ⁱ expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p) +ⁱ (expandˢ o (K c₂) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ +ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o n₁ c₁ p)) (≈ⁱ-sym (expandˢ-+x^-lemma o n₂ c₂ q)) ⟩ expandˢ o (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o (c₂ +x^ n₂ ∙ q) ∎ where ... | no c₁+c₂≉0 with +ᵖ-spine ⟅ n₁ ⇓⟆ p ⟅ n₂ ⇓⟆ q | expand-+ᵖ-spine-homo ⟅ n₁ ⇓⟆ p ⟅ n₂ ⇓⟆ q ... | 0ᵖ | pf = begin⟨ ≈ⁱ-setoid ⟩ expandˢ o (K (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0)) ≈⟨ ≈ⁱ-sym (+ⁱ-identityʳ _) ⟩ expandˢ o (K (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0)) +ⁱ 0ⁱ ≈⟨ +ⁱ-cong (expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ o c₁ c₂ c₁+c₂≉0) (expandˢ-raise₁ o ⟅ n₁ ⇓⟆ p ⟅ n₂ ⇓⟆ q pf) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ (expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ expand-+ᵖ-spine-≡-homo-permute (expandˢ o (K c₁)) (expandˢ o (K c₂)) _ _ ⟩ (expandˢ o (K c₁) +ⁱ expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p) +ⁱ (expandˢ o (K c₂) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ +ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o n₁ c₁ p)) (≈ⁱ-sym (expandˢ-+x^-lemma o n₂ c₂ q)) ⟩ expandˢ o (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o (c₂ +x^ n₂ ∙ q) ∎ ... | x^ zero ∙ r | pf = begin⟨ ≈ⁱ-setoid ⟩ expand (+ᵖ-spine-≡-K o (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0) r) ≈⟨ expand-+ᵖ-spine-≡-K-homo o (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0) r ⟩ expandˢ o (K (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0)) +ⁱ expandˢ o r ≈⟨ +ⁱ-cong (expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ o c₁ c₂ c₁+c₂≉0) (expandˢ-≡-cong (≡-sym (Nat.+-identityʳ o))) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ expandˢ (o +ℕ 0) r ≈⟨ +ⁱ-congˡ (expandˢ-raise₂ o 0 r ⟅ n₁ ⇓⟆ p ⟅ n₂ ⇓⟆ q pf) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ (expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ expand-+ᵖ-spine-≡-homo-permute (expandˢ o (K c₁)) (expandˢ o (K c₂)) _ _ ⟩ (expandˢ o (K c₁) +ⁱ expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p) +ⁱ (expandˢ o (K c₂) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ +ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o n₁ c₁ p)) (≈ⁱ-sym (expandˢ-+x^-lemma o n₂ c₂ q)) ⟩ expandˢ o (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o (c₂ +x^ n₂ ∙ q) ∎ ... | x^ suc n₃ ∙ r | pf = begin⟨ ≈ⁱ-setoid ⟩ expandˢ o ((proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0) +x^ ⟅ suc n₃ ⇑⟆ ∙ r) ≈⟨ expandˢ-+x^-lemma o ⟅ suc n₃ ⇑⟆ (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0) r ⟩ expandˢ o (K (proj₁ c₁ + proj₁ c₂ , c₁+c₂≉0)) +ⁱ expandˢ (o +ℕ suc n₃) r ≈⟨ +ⁱ-congʳ (expandˢ-+ᵖ-spine-≡-K-homo-lemma₂ o c₁ c₂ c₁+c₂≉0) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ expandˢ (o +ℕ suc n₃) r ≈⟨ +ⁱ-congˡ (expandˢ-raise₂ o (suc n₃) r ⟅ n₁ ⇓⟆ p ⟅ n₂ ⇓⟆ q pf) ⟩ (expandˢ o (K c₁) +ⁱ expandˢ o (K c₂)) +ⁱ (expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ expand-+ᵖ-spine-≡-homo-permute (expandˢ o (K c₁)) (expandˢ o (K c₂)) _ _ ⟩ (expandˢ o (K c₁) +ⁱ expandˢ (o +ℕ ⟅ n₁ ⇓⟆) p) +ⁱ (expandˢ o (K c₂) +ⁱ expandˢ (o +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ +ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o n₁ c₁ p)) (≈ⁱ-sym (expandˢ-+x^-lemma o n₂ c₂ q)) ⟩ expandˢ o (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o (c₂ +x^ n₂ ∙ q) ∎ expand-+ᵖ-spine-<-homo o₁ (K c₁) o₂ q o₁<o₂ = begin⟨ ≈ⁱ-setoid ⟩ expandˢ o₁ (c₁ +x^ ⟅ o₂ ∸ o₁ ⇑⟆ ∙ q) ≈⟨ expandˢ-+x^-lemma o₁ ⟅ o₂ ∸ o₁ ⇑⟆ c₁ q ⟩ expandˢ o₁ (K c₁) +ⁱ expandˢ (o₁ +ℕ ⟅ ⟅ o₂ ∸ o₁ ⇑⟆ ⇓⟆) q ≈⟨ +ⁱ-congˡ (expandˢ-≡-cong lemma) ⟩ expandˢ o₁ (K c₁) +ⁱ expandˢ o₂ q ∎ where lemma : o₁ +ℕ ⟅ ⟅ o₂ ∸ o₁ ⇑⟆ ⇓⟆ ≡ o₂ lemma = begin⟨ ≡-setoid ℕ ⟩ o₁ +ℕ ⟅ ⟅ o₂ ∸ o₁ ⇑⟆ ⇓⟆ ≡⟨ ≡-cong (λ x → o₁ +ℕ x) (ℕ→ℕ⁺→ℕ (o₂ ∸ o₁) {≢⇒¬≟ (m<n⇒n∸m≢0 o₁<o₂)}) ⟩ o₁ +ℕ (o₂ ∸ o₁) ≡⟨ m+[n∸m]≡n {o₁} {o₂} (<⇒≤ o₁<o₂) ⟩ o₂ ∎ expand-+ᵖ-spine-<-homo o₁ (c₁ +x^ n₁ ∙ p) o₂ q o₁<o₂ with +ᵖ-spine ⟅ n₁ ⇓⟆ p (o₂ ∸ o₁) q | expand-+ᵖ-spine-homo ⟅ n₁ ⇓⟆ p (o₂ ∸ o₁) q ... | 0ᵖ | pf = begin⟨ ≈ⁱ-setoid ⟩ expandˢ o₁ (K c₁) ≈⟨ ≈ⁱ-sym (+ⁱ-identityʳ (expandˢ o₁ (K c₁))) ⟩ expandˢ o₁ (K c₁) +ⁱ 0ⁱ ≈⟨ +ⁱ-congˡ (expandˢ-raise₁ o₁ ⟅ n₁ ⇓⟆ p (o₂ ∸ o₁) q pf) ⟩ expandˢ o₁ (K c₁) +ⁱ (expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o₁ +ℕ (o₂ ∸ o₁)) q) ≈⟨ ≈ⁱ-sym (+ⁱ-assoc (expandˢ o₁ (K c₁)) _ _) ⟩ (expandˢ o₁ (K c₁) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p) +ⁱ expandˢ (o₁ +ℕ (o₂ ∸ o₁)) q ≈⟨ +ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o₁ n₁ c₁ p)) (expandˢ-≡-cong (m+[n∸m]≡n (<⇒≤ o₁<o₂))) ⟩ expandˢ o₁ (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o₂ q ∎ ... | x^ zero ∙ r | pf = begin⟨ ≈ⁱ-setoid ⟩ expand (+ᵖ-spine-≡-K o₁ c₁ r) ≈⟨ expand-+ᵖ-spine-≡-K-homo o₁ c₁ r ⟩ expandˢ o₁ (K c₁) +ⁱ expandˢ o₁ r ≈⟨ +ⁱ-congˡ (expandˢ-≡-cong (≡-sym (Nat.+-identityʳ o₁))) ⟩ expandˢ o₁ (K c₁) +ⁱ expandˢ (o₁ +ℕ 0) r ≈⟨ +ⁱ-congˡ (expandˢ-raise₂ o₁ 0 r ⟅ n₁ ⇓⟆ p (o₂ ∸ o₁) q pf) ⟩ expandˢ o₁ (K c₁) +ⁱ (expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o₁ +ℕ (o₂ ∸ o₁)) q) ≈⟨ ≈ⁱ-sym (+ⁱ-assoc (expandˢ o₁ (K c₁)) _ _) ⟩ (expandˢ o₁ (K c₁) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p) +ⁱ expandˢ (o₁ +ℕ (o₂ ∸ o₁)) q ≈⟨ +ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o₁ n₁ c₁ p)) (expandˢ-≡-cong (m+[n∸m]≡n (<⇒≤ o₁<o₂))) ⟩ expandˢ o₁ (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o₂ q ∎ ... | x^ suc o₃ ∙ r | pf = begin⟨ ≈ⁱ-setoid ⟩ expandˢ o₁ (c₁ +x^ ⟅ suc o₃ ⇑⟆ ∙ r) ≈⟨ expandˢ-+x^-lemma o₁ ⟅ suc o₃ ⇑⟆ c₁ r ⟩ expandˢ o₁ (K c₁) +ⁱ expandˢ (o₁ +ℕ suc o₃) r ≈⟨ +ⁱ-congˡ (expandˢ-raise₂ o₁ (suc o₃) r ⟅ n₁ ⇓⟆ p (o₂ ∸ o₁) q pf) ⟩ expandˢ o₁ (K c₁) +ⁱ (expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o₁ +ℕ (o₂ ∸ o₁)) q) ≈⟨ ≈ⁱ-sym (+ⁱ-assoc (expandˢ o₁ (K c₁)) _ _) ⟩ (expandˢ o₁ (K c₁) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p) +ⁱ expandˢ (o₁ +ℕ (o₂ ∸ o₁)) q ≈⟨ +ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o₁ n₁ c₁ p)) (expandˢ-≡-cong (m+[n∸m]≡n (<⇒≤ o₁<o₂))) ⟩ expandˢ o₁ (c₁ +x^ n₁ ∙ p) +ⁱ expandˢ o₂ q ∎ expand-+ᵖ-spine-homo o₁ p o₂ q with <-cmp o₁ o₂ ... | tri< o₁<o₂ _ _ = expand-+ᵖ-spine-<-homo o₁ p o₂ q o₁<o₂ ... | tri≈ _ ≡-refl _ = expand-+ᵖ-spine-≡-homo o₁ p q ... | tri> _ _ o₁>o₂ = begin⟨ ≈ⁱ-setoid ⟩ expand (+ᵖ-spine-< o₂ q o₁ p o₁>o₂) ≈⟨ expand-+ᵖ-spine-<-homo o₂ q o₁ p o₁>o₂ ⟩ expandˢ o₂ q +ⁱ expandˢ o₁ p ≈⟨ +ⁱ-comm (expandˢ o₂ q) (expandˢ o₁ p) ⟩ expandˢ o₁ p +ⁱ expandˢ o₂ q ∎ expand-+ᵖ-homo : ∀ p q → expand (p +ᵖ q) ≈ⁱ expand p +ⁱ expand q expand-+ᵖ-homo 0ᵖ q = ≈ⁱ-refl expand-+ᵖ-homo (x^ o₁ ∙ p) 0ᵖ = ≈ⁱ-sym (+ⁱ-identityʳ (expand (x^ o₁ ∙ p))) expand-+ᵖ-homo (x^ o₁ ∙ p) (x^ o₂ ∙ q) = expand-+ᵖ-spine-homo o₁ p o₂ q expandˢ-*ᵖ-K-lemma : ∀ o₁ o₂ c₁ c₂ → expandˢ (o₁ +ℕ o₂) (K (c₁ *-nonzero c₂)) ≈ⁱ expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (K c₂) expandˢ-*ᵖ-K-lemma zero zero c₁ c₂ = +≈+ refl (0≈+ refl 0≈0) expandˢ-*ᵖ-K-lemma zero (suc o₂) c₁ c₂ = +≈+ (sym (zeroʳ (proj₁ c₁))) $ begin⟨ ≈ⁱ-setoid ⟩ expandˢ o₂ (K (c₁ *-nonzero c₂)) ≈⟨ expandˢ-*ᵖ-K-lemma zero o₂ c₁ c₂ ⟩ (proj₁ c₁ +x∙ 0ⁱ) *ⁱ expandˢ o₂ (K c₂) ≈⟨ +x∙-distribʳ-*ⁱ (proj₁ c₁) 0ⁱ (expandˢ o₂ (K c₂)) ⟩ proj₁ c₁ ∙ⁱ expandˢ o₂ (K c₂) +ⁱ x∙ (0ⁱ *ⁱ expandˢ o₂ (K c₂)) ≈⟨ ≈ⁱ-refl ⟩ proj₁ c₁ ∙ⁱ expandˢ o₂ (K c₂) +ⁱ x∙ 0ⁱ ≈⟨ +ⁱ-congʳ (≈ⁱ-sym (+ⁱ-identityʳ (proj₁ c₁ ∙ⁱ expandˢ o₂ (K c₂)))) ⟩ proj₁ c₁ ∙ⁱ expandˢ o₂ (K c₂) +ⁱ 0ⁱ +ⁱ x∙ 0ⁱ ∎ expandˢ-*ᵖ-K-lemma (suc o₁) o₂ c₁ c₂ = begin⟨ ≈ⁱ-setoid ⟩ 0# +x∙ expandˢ (o₁ +ℕ o₂) (K (c₁ *-nonzero c₂)) ≈⟨ +≈+ refl (expandˢ-*ᵖ-K-lemma o₁ o₂ c₁ c₂) ⟩ 0# +x∙ (expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (K c₂)) ≈⟨ ≈ⁱ-refl ⟩ 0ⁱ +ⁱ x∙ (expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (K c₂)) ≈⟨ +ⁱ-congʳ (0≈0∙p (expandˢ o₂ (K c₂))) ⟩ 0# ∙ⁱ expandˢ o₂ (K c₂) +ⁱ x∙ (expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (K c₂)) ≈⟨ ≈ⁱ-sym (+x∙-distribʳ-*ⁱ 0# _ _) ⟩ (0# +x∙ expandˢ o₁ (K c₁)) *ⁱ expandˢ o₂ (K c₂) ∎ expandˢ-∙ᵖ-spine-homo : ∀ o₁ c o₂ p → expandˢ (o₁ +ℕ o₂) (∙ᵖ-spine c p) ≈ⁱ expandˢ o₁ (K c) *ⁱ expandˢ o₂ p expandˢ-∙ᵖ-spine-homo o₁ c₁ o₂ (K c₂) = expandˢ-*ᵖ-K-lemma o₁ o₂ c₁ c₂ expandˢ-∙ᵖ-spine-homo o₁ c₁ o₂ (c₂ +x^ n₂ ∙ q) = begin⟨ ≈ⁱ-setoid ⟩ expandˢ (o₁ +ℕ o₂) ((c₁ *-nonzero c₂) +x^ n₂ ∙ ∙ᵖ-spine c₁ q) ≈⟨ expandˢ-+x^-lemma (o₁ +ℕ o₂) n₂ (c₁ *-nonzero c₂) (∙ᵖ-spine c₁ q) ⟩ expandˢ (o₁ +ℕ o₂) (K (c₁ *-nonzero c₂)) +ⁱ expandˢ ((o₁ +ℕ o₂) +ℕ ⟅ n₂ ⇓⟆) (∙ᵖ-spine c₁ q) ≈⟨ +ⁱ-congˡ (expandˢ-≡-cong (Nat.+-assoc o₁ o₂ ⟅ n₂ ⇓⟆)) ⟩ expandˢ (o₁ +ℕ o₂) (K (c₁ *-nonzero c₂)) +ⁱ expandˢ (o₁ +ℕ (o₂ +ℕ ⟅ n₂ ⇓⟆)) (∙ᵖ-spine c₁ q) ≈⟨ +ⁱ-cong (expandˢ-*ᵖ-K-lemma o₁ o₂ c₁ c₂) (expandˢ-∙ᵖ-spine-homo o₁ c₁ (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ⟩ expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (K c₂) +ⁱ expandˢ o₁ (K c₁) *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q ≈⟨ ≈ⁱ-sym (*ⁱ-distribˡ-+ⁱ (expandˢ o₁ (K c₁)) (expandˢ o₂ (K c₂)) _) ⟩ expandˢ o₁ (K c₁) *ⁱ (expandˢ o₂ (K c₂) +ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ *ⁱ-congˡ (≈ⁱ-sym (expandˢ-+x^-lemma o₂ n₂ c₂ q)) ⟩ expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (c₂ +x^ n₂ ∙ q) ∎ expand-*ᵖ-spine-homo : ∀ o₁ p o₂ q → expand (*ᵖ-spine o₁ p o₂ q) ≈ⁱ expandˢ o₁ p *ⁱ expandˢ o₂ q expand-*ᵖ-spine-homo o₁ (K c₁) o₂ q = expandˢ-∙ᵖ-spine-homo o₁ c₁ o₂ q expand-*ᵖ-spine-homo o₁ (c₁ +x^ n₁ ∙ p) o₂ (K c₂) = begin⟨ ≈ⁱ-setoid ⟩ expandˢ (o₁ +ℕ o₂) (∙ᵖ-spine c₂ (c₁ +x^ n₁ ∙ p)) ≈⟨ expandˢ-≡-cong (Nat.+-comm o₁ o₂) ⟩ expandˢ (o₂ +ℕ o₁) (∙ᵖ-spine c₂ (c₁ +x^ n₁ ∙ p)) ≈⟨ expandˢ-∙ᵖ-spine-homo o₂ c₂ o₁ (c₁ +x^ n₁ ∙ p) ⟩ expandˢ o₂ (K c₂) *ⁱ expandˢ o₁ (c₁ +x^ n₁ ∙ p) ≈⟨ *ⁱ-comm _ _ ⟩ expandˢ o₁ (c₁ +x^ n₁ ∙ p) *ⁱ expandˢ o₂ (K c₂) ∎ expand-*ᵖ-spine-homo o₁ (c₁ +x^ n₁ ∙ p) o₂ (c₂ +x^ n₂ ∙ q) = begin⟨ ≈ⁱ-setoid ⟩ expand ( x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p +ᵖ *ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q ) ≈⟨ expand-+ᵖ-homo ( x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p ) (*ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ⟩ expand ( x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p ) +ⁱ expand ( *ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q ) ≈⟨ +ⁱ-cong (expand-+ᵖ-homo (x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q) (c₂ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p)) (expand-*ᵖ-spine-homo (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ⟩ expand ( x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q ) +ⁱ expandˢ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) (∙ᵖ-spine c₂ p) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q ≈⟨ +ⁱ-congʳ (+ⁱ-cong (expand-+ᵖ-homo (x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂)) (c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q)) (expandˢ-≡-cong (≡-cong (λ x → x +ℕ ⟅ n₁ ⇓⟆) (Nat.+-comm o₁ o₂)))) ⟩ expandˢ (o₁ +ℕ o₂) (K (c₁ *-nonzero c₂)) +ⁱ expandˢ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) (∙ᵖ-spine c₁ q) +ⁱ expandˢ (o₂ +ℕ o₁ +ℕ ⟅ n₁ ⇓⟆) (∙ᵖ-spine c₂ p) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q ≈⟨ +ⁱ-congʳ (+ⁱ-cong (+ⁱ-congˡ {expandˢ (o₁ +ℕ o₂) (K (c₁ *-nonzero c₂))} (expandˢ-≡-cong {p = ∙ᵖ-spine c₁ q} (Nat.+-assoc o₁ o₂ ⟅ n₂ ⇓⟆))) (expandˢ-≡-cong (Nat.+-assoc o₂ o₁ ⟅ n₁ ⇓⟆))) ⟩ expandˢ (o₁ +ℕ o₂) (K (c₁ *-nonzero c₂)) +ⁱ expandˢ (o₁ +ℕ (o₂ +ℕ ⟅ n₂ ⇓⟆)) (∙ᵖ-spine c₁ q) +ⁱ expandˢ (o₂ +ℕ (o₁ +ℕ ⟅ n₁ ⇓⟆)) (∙ᵖ-spine c₂ p) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q ≈⟨ +ⁱ-congʳ (+ⁱ-cong (+ⁱ-cong (expandˢ-*ᵖ-K-lemma o₁ o₂ c₁ c₂) (expandˢ-∙ᵖ-spine-homo o₁ c₁ (o₂ +ℕ ⟅ n₂ ⇓⟆) q)) (expandˢ-∙ᵖ-spine-homo o₂ c₂ (o₁ +ℕ ⟅ n₁ ⇓⟆) p)) ⟩ expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (K c₂) +ⁱ expandˢ o₁ (K c₁) *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q +ⁱ expandˢ o₂ (K c₂) *ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q ≈⟨ +ⁱ-congʳ {expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q} (+ⁱ-congˡ (*ⁱ-comm (expandˢ o₂ (K c₂)) (expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p) )) ⟩ expandˢ o₁ (K c₁) *ⁱ expandˢ o₂ (K c₂) +ⁱ expandˢ o₁ (K c₁) *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p *ⁱ expandˢ o₂ (K c₂) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p *ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q ≈⟨ ≈ⁱ-sym (foil (expandˢ o₁ (K c₁)) _ (expandˢ o₂ (K c₂)) _) ⟩ (expandˢ o₁ (K c₁) +ⁱ expandˢ (o₁ +ℕ ⟅ n₁ ⇓⟆) p) *ⁱ (expandˢ o₂ (K c₂) +ⁱ expandˢ (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ≈⟨ *ⁱ-cong (≈ⁱ-sym (expandˢ-+x^-lemma o₁ n₁ c₁ p)) (≈ⁱ-sym (expandˢ-+x^-lemma o₂ n₂ c₂ q)) ⟩ expandˢ o₁ (c₁ +x^ n₁ ∙ p) *ⁱ expandˢ o₂ (c₂ +x^ n₂ ∙ q) ∎ where foil : ∀ a b c d → (a +ⁱ b) *ⁱ (c +ⁱ d) ≈ⁱ a *ⁱ c +ⁱ a *ⁱ d +ⁱ b *ⁱ c +ⁱ b *ⁱ d foil = solve +ⁱ-*ⁱ-almostCommutativeRing expand-*ᵖ-homo : ∀ p q → expand (p *ᵖ q) ≈ⁱ expand p *ⁱ expand q expand-*ᵖ-homo 0ᵖ q = *ⁱ-zeroˡ (expand q) expand-*ᵖ-homo (x^ o₁ ∙ p) 0ᵖ = ≈ⁱ-sym (*ⁱ-zeroʳ (expand (x^ o₁ ∙ p))) expand-*ᵖ-homo (x^ o₁ ∙ p) (x^ o₂ ∙ q) = expand-*ᵖ-spine-homo o₁ p o₂ q expand-∙ᵖ-homo : ∀ c p → expand (c ∙ᵖ p) ≈ⁱ proj₁ c ∙ⁱ expand p expand-∙ᵖ-homo c₁ 0ᵖ = ≈ⁱ-refl expand-∙ᵖ-homo c₁ (x^ n ∙ p) = loop c₁ n p where loop : ∀ c n p → expandˢ n (∙ᵖ-spine c p) ≈ⁱ proj₁ c ∙ⁱ expandˢ n p loop c₁ zero (K c₂) = ≈ⁱ-refl loop c₁ zero (c₂ +x^ n₂ ∙ p) = +≈+ refl (loop c₁ (pred ⟅ n₂ ⇓⟆) p) loop c₁ (suc n) p = +≈+ (sym (zeroʳ (proj₁ c₁))) (loop c₁ n p) expand‿-ᵖ‿homo : ∀ p → expand (-ᵖ p) ≈ⁱ -ⁱ (expand p) expand‿-ᵖ‿homo = expand-∙ᵖ-homo -1#-nonzero ---- Witness me ---- expand-isRelHomomorphism : IsRelHomomorphism _≈ᵖ_ _≈ⁱ_ expand expand-isRelHomomorphism = record { cong = expand-cong } expand-isRingHomomorphism : IsRingHomomorphism +ᵖ-*ᵖ-rawRing +ⁱ-*ⁱ-rawRing expand expand-isRingHomomorphism = record { isRelHomomorphism = expand-isRelHomomorphism ; +-homo = expand-+ᵖ-homo ; *-homo = expand-*ᵖ-homo ; -‿homo = expand‿-ᵖ‿homo ; 0#-homo = ≈ⁱ-refl ; 1#-homo = ≈ⁱ-refl } expand-isRingMonomorphism : IsRingMonomorphism +ᵖ-*ᵖ-rawRing +ⁱ-*ⁱ-rawRing expand expand-isRingMonomorphism = record { isRingHomomorphism = expand-isRingHomomorphism ; injective = expand-injective } open RingConsequences expand-isRingMonomorphism using (R₂-isIntegralDomain→R₁-isIntegralDomain) +ᵖ-*ᵖ-isIntegralDomain : IsIntegralDomain Polynomial _≈ᵖ_ _+ᵖ_ _*ᵖ_ -ᵖ_ 0ᵖ 1ᵖ +ᵖ-*ᵖ-isIntegralDomain = R₂-isIntegralDomain→R₁-isIntegralDomain +ⁱ-*ⁱ-isIntegralDomain +ᵖ-*ᵖ-integralDomain : IntegralDomain (c ⊔ˡ ℓ) (c ⊔ˡ ℓ) +ᵖ-*ᵖ-integralDomain = record { isIntegralDomain = +ᵖ-*ᵖ-isIntegralDomain } open IntegralDomain +ᵖ-*ᵖ-integralDomain using () renaming (commutativeRing to +ᵖ-*ᵖ-commutativeRing) open CommutativeRing +ᵖ-*ᵖ-commutativeRing using () renaming (+-cong to +ᵖ-cong; +-congˡ to +ᵖ-congˡ; +-congʳ to +ᵖ-congʳ; +-identityʳ to +ᵖ-identityʳ; +-assoc to +ᵖ-assoc; +-comm to +ᵖ-comm) open CommutativeRing +ᵖ-*ᵖ-commutativeRing using () renaming (zeroʳ to *ᵖ-zeroʳ; -‿inverseˡ to -ᵖ‿inverseˡ; -‿inverseʳ to -ᵖ‿inverseʳ; *-comm to *ᵖ-comm; distribʳ to *ᵖ-distribʳ-+ᵖ; distribˡ to *ᵖ-distribˡ-+ᵖ) +ᵖ-*ᵖ-almostCommutativeRing : AlmostCommutativeRing (c ⊔ˡ ℓ) (c ⊔ˡ ℓ) +ᵖ-*ᵖ-almostCommutativeRing = fromCommutativeRing +ᵖ-*ᵖ-commutativeRing isZero where isZero : ∀ x → Maybe (0ᵖ ≈ᵖ x) isZero 0ᵖ = just ≈ᵖ-refl isZero (x^ _ ∙ _) = nothing degreeⁱ≡degreeˢ : ∀ n p → degreeⁱ (expandˢ n p) ≡ ⟨ n +ℕ degreeˢ p ⟩ degreeⁱ≡degreeˢ zero (K c) with proj₁ c ≈? 0# ... | yes c≈0 = contradiction c≈0 (proj₂ c) ... | no _ = ≡-refl degreeⁱ≡degreeˢ zero (c +x^ (ℕ+ i) ∙ p) rewrite degreeⁱ≡degreeˢ i p = ≡-refl degreeⁱ≡degreeˢ (suc n) p rewrite degreeⁱ≡degreeˢ n p = ≡-refl degreeⁱ≡degree : ∀ p → degreeⁱ (expand p) ≡ degree p degreeⁱ≡degree 0ᵖ = ≡-refl degreeⁱ≡degree (x^ n ∙ p) = degreeⁱ≡degreeˢ n p degreeˢ-cong : ∀ {p q} → p ≈ˢ q → degreeˢ p ≡ degreeˢ q degreeˢ-cong {K c₁} {K c₂} (K≈ c₁≈c₂) = ≡-refl degreeˢ-cong {c₁ +x^ n ∙ p} {c₂ +x^ n ∙ q} (+≈ c₁≈c₂ ≡-refl p≈q) rewrite degreeˢ-cong p≈q = ≡-refl degree-cong : ∀ {p q} → p ≈ᵖ q → degree p ≡ degree q degree-cong {0ᵖ} {0ᵖ} 0ᵖ≈ = ≡-refl degree-cong {x^ n ∙ p} {x^ n ∙ q} (0ᵖ≉ ≡-refl p≈q) rewrite degreeˢ-cong p≈q = ≡-refl degreeⁱ-cong : ∀ {p q} → p ≈ⁱ q → degreeⁱ p ≡ degreeⁱ q degreeⁱ-cong {0ⁱ} {0ⁱ} 0≈0 = ≡-refl degreeⁱ-cong {0ⁱ} {c₂ +x∙ q} (0≈+ c₂≈0 0≈q) with degreeⁱ q | degreeⁱ-cong 0≈q ... | ⟨ _ ⟩ | () ... | -∞ | ≡-refl with c₂ ≈? 0# ... | yes _ = ≡-refl ... | no c₂≉0 = contradiction c₂≈0 c₂≉0 degreeⁱ-cong {c₁ +x∙ p} {0ⁱ} (+≈0 c₁≈0 0≈p) with degreeⁱ p | degreeⁱ-cong 0≈p ... | ⟨ _ ⟩ | () ... | -∞ | ≡-refl with c₁ ≈? 0# ... | yes _ = ≡-refl ... | no c₁≉0 = contradiction c₁≈0 c₁≉0 degreeⁱ-cong {c₁ +x∙ p} {c₂ +x∙ q} (+≈+ c₁≈c₂ p≈q) with degreeⁱ p | degreeⁱ q | degreeⁱ-cong p≈q ... | ⟨ n ⟩ | ⟨ n ⟩ | ≡-refl = ≡-refl ... | -∞ | -∞ | ≡-refl with c₁ ≈? 0# | c₂ ≈? 0# ... | yes c₁≈0 | yes c₂≈0 = ≡-refl ... | yes c₁≈0 | no c₂≉0 = contradiction (begin⟨ setoid ⟩ c₂ ≈⟨ sym c₁≈c₂ ⟩ c₁ ≈⟨ c₁≈0 ⟩ 0# ∎) c₂≉0 ... | no c₁≉0 | yes c₂≈0 = contradiction (begin⟨ setoid ⟩ c₁ ≈⟨ c₁≈c₂ ⟩ c₂ ≈⟨ c₂≈0 ⟩ 0# ∎) c₁≉0 ... | no c₁≉0 | no c₂≉0 = ≡-refl module _ where open ≤-Reasoning using (begin_; _≤⟨_⟩_) renaming (_≡⟨_⟩_ to _≡≤⟨_⟩_; _∎ to _≤∎) degreeⁱ-+ⁱ : ∀ p q → degreeⁱ (p +ⁱ q) ≤ᵈ degreeⁱ p ⊔ᵈ degreeⁱ q degreeⁱ-+ⁱ 0ⁱ q = ≤ᵈ-refl degreeⁱ-+ⁱ (c₁ +x∙ p) 0ⁱ with degreeⁱ (c₁ +x∙ p) ... | -∞ = ≤ᵈ-refl ... | ⟨ _ ⟩ = ≤ᵈ-refl degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) with degreeⁱ (p +ⁱ q) | degreeⁱ p | degreeⁱ q | degreeⁱ-+ⁱ p q degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | n | m | (-∞≤ _) with c₁ + c₂ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | n | m | (-∞≤ _) | yes c₁+c₂≈0 = -∞≤ _ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | m | (-∞≤ _) | no c₁+c₂≉0 with c₁ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | yes c₁≈0 with c₂ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | yes c₁≈0 | yes c₂≈0 = contradiction (begin⟨ setoid ⟩ c₁ + c₂ ≈⟨ +-cong c₁≈0 c₂≈0 ⟩ 0# + 0# ≈⟨ +-identityʳ 0# ⟩ 0# ∎) c₁+c₂≉0 degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | yes c₁≈0 | no c₂≉0 = ≤ᵈ-refl degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | ⟨ m ⟩ | (-∞≤ _) | no c₁+c₂≉0 | yes c₁≈0 = ⟨ 0≤n ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | no c₁≉0 with c₂ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | no c₁≉0 | yes c₂≈0 = ≤ᵈ-refl degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | no c₁≉0 | no c₂≉0 = ⟨ ≤-reflexive (⊔-identityʳ (λ x → 0≤n) 0) ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | -∞ | ⟨ m ⟩ | (-∞≤ _) | no c₁+c₂≉0 | no c₁≉0 = ⟨ begin 0 ≤⟨ 0≤n ⟩ suc m ≡≤⟨ ≡-sym (⊔-identityʳ (λ x → 0≤n) (suc m)) ⟩ 0 ⊔ suc m ≤∎ ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | ⟨ n ⟩ | -∞ | (-∞≤ _) | no c₁+c₂≉0 with c₂ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | ⟨ n ⟩ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | yes c₂≈0 = ⟨ 0≤n ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | ⟨ n ⟩ | -∞ | (-∞≤ _) | no c₁+c₂≉0 | no c₂≉0 = ⟨ begin 0 ≤⟨ 0≤n ⟩ suc n ≡≤⟨ ≡-sym (⊔-identityˡ (λ x → 0≤n) (suc n)) ⟩ suc n ⊔ 0 ≤∎ ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | -∞ | ⟨ n ⟩ | ⟨ m ⟩ | (-∞≤ _) | no c₁+c₂≉0 = ⟨ 0≤n ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | m | _ with c₁ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | -∞ | _ | yes c₁≈0 with c₂ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | -∞ | () | yes c₁≈0 | yes c₂≈0 degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | -∞ | () | yes c₁≈0 | no c₂≉0 degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | ⟨ m ⟩ | ⟨ r≤m ⟩ | yes c₁≈0 = ⟨ suc-mono-≤ r≤m ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | -∞ | pf | no c₁≉0 with c₂ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | -∞ | () | no c₁≉0 | yes c₂≈0 degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | -∞ | () | no c₁≉0 | no c₂≉0 degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | -∞ | ⟨ m ⟩ | ⟨ r≤m ⟩ | no c₁≉0 = ⟨ begin suc r ≤⟨ suc-mono-≤ r≤m ⟩ suc m ≡≤⟨ ≡-sym (⊔-identityʳ (λ x → 0≤n) (suc m)) ⟩ 0 ⊔ suc m ≤∎ ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | ⟨ n ⟩ | -∞ | ⟨ r≤n ⟩ with c₂ ≈? 0# degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | ⟨ n ⟩ | -∞ | ⟨ r≤n ⟩ | yes c₂≈0 = ⟨ suc-mono-≤ r≤n ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | ⟨ n ⟩ | -∞ | ⟨ r≤n ⟩ | no c₂≉0 = ⟨ begin suc r ≤⟨ suc-mono-≤ r≤n ⟩ suc n ≡≤⟨ ≡-sym (⊔-identityˡ (λ x → 0≤n) (suc n)) ⟩ suc n ⊔ 0 ≤∎ ⟩ degreeⁱ-+ⁱ (c₁ +x∙ p) (c₂ +x∙ q) | ⟨ r ⟩ | ⟨ n ⟩ | ⟨ m ⟩ | ⟨ r≤n⊔m ⟩ = ⟨ begin suc r ≤⟨ suc-mono-≤ r≤n⊔m ⟩ suc (n ⊔ m) ≡≤⟨ +-distribˡ-⊔ 1 n m ⟩ suc n ⊔ suc m ≤∎ ⟩ -- degreeⁱ-*ⁱ : ∀ p q → degreeⁱ (p *ⁱ q) ≡ degreeⁱ p +ᵈ degreeⁱ q -- degreeⁱ-*ⁱ 0ⁱ q = ≡-refl -- degreeⁱ-*ⁱ (c₁ +x∙ p) 0ⁱ with degreeⁱ p -- ... | ⟨ n ⟩ = ≡-refl -- ... | -∞ with c₁ ≈? 0# -- ... | yes _ = ≡-refl -- ... | no _ = ≡-refl -- degreeⁱ-*ⁱ (c₁ +x∙ p) (c₂ +x∙ q) = {!!} -- -- lemma : degreeⁱ ((c₁ * c₂) +x∙ (c₁ ∙ⁱ q +ⁱ c₂ ∙ⁱ p +ⁱ x∙ (p *ⁱ q))) ≡ degreeⁱ (c₁ +x∙ p) +ᵈ degreeⁱ (c₂ +x∙ q) -- -- lemma = {!!} degreeᵖ-+ᵖ : ∀ p q → degree (p +ᵖ q) ≤ᵈ degree p ⊔ᵈ degree q degreeᵖ-+ᵖ p q = begin degree (p +ᵖ q) ≡ᵈ⟨ ≡-sym (degreeⁱ≡degree (p +ᵖ q)) ⟩ degreeⁱ (expand (p +ᵖ q)) ≡ᵈ⟨ degreeⁱ-cong (expand-+ᵖ-homo p q) ⟩ degreeⁱ (expand p +ⁱ expand q) ≤ᵈ⟨ degreeⁱ-+ⁱ (expand p) (expand q) ⟩ degreeⁱ (expand p) ⊔ᵈ degreeⁱ (expand q) ≡ᵈ⟨ ≡-cong₂ _⊔ᵈ_ (degreeⁱ≡degree p) (degreeⁱ≡degree q) ⟩ degree p ⊔ᵈ degree q ∎ᵈ where open ≤ᵈ-Reasoning ∙ᵖ-spine-degreeˢ : ∀ a p → degreeˢ (∙ᵖ-spine a p) ≡ degreeˢ p ∙ᵖ-spine-degreeˢ a (K c) = ≡-refl ∙ᵖ-spine-degreeˢ a (c +x^ n ∙ p) = ≡-cong (λ x → ⟅ n ⇓⟆ +ℕ x) (∙ᵖ-spine-degreeˢ a p) ∙ᵖ-degree : ∀ a p → degree (a ∙ᵖ p) ≡ degree p ∙ᵖ-degree a 0ᵖ = ≡-refl ∙ᵖ-degree a (x^ n ∙ p) = ≡-cong (λ x → ⟨ n +ℕ x ⟩) (∙ᵖ-spine-degreeˢ a p) open import Relation.Binary using (Antisymmetric) open import AKS.Nat using (≤-antisym; ≤-total) ≤ᵈ-antisym : Antisymmetric _≡_ _≤ᵈ_ ≤ᵈ-antisym (-∞≤ _) (-∞≤ _) = ≡-refl ≤ᵈ-antisym ⟨ x≤y ⟩ ⟨ y≤x ⟩ = ≡-cong ⟨_⟩ (≤-antisym x≤y y≤x) m≤ᵈn⇒m⊔ᵈn≡n : ∀ {m n} → m ≤ᵈ n → m ⊔ᵈ n ≡ n m≤ᵈn⇒m⊔ᵈn≡n { -∞} {n} m≤n = ≡-refl m≤ᵈn⇒m⊔ᵈn≡n {⟨ m ⟩} {⟨ n ⟩} ⟨ m≤n ⟩ with ≤-total n m ... | inj₁ n≤m = ≡-cong ⟨_⟩ (≤-antisym m≤n n≤m) ... | inj₂ _ = ≡-refl degreeⁱ[q]≤degreeⁱ[p+ⁱq] : ∀ p q → degreeⁱ p ≤ᵈ degreeⁱ q → degreeⁱ q ≤ᵈ degreeⁱ (p +ⁱ q) degreeⁱ[q]≤degreeⁱ[p+ⁱq] 0ⁱ q _ = ≤ᵈ-refl degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) 0ⁱ _ = -∞≤ _ degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ with degreeⁱ q degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ with c₂ ≈? 0# degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | yes c₂≈0 = -∞≤ _ degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 with degreeⁱ (p +ⁱ q) degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 | -∞ with c₁ + c₂ ≈? 0# degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 | -∞ | yes c₁+c₂≈0 with degreeⁱ p degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 | -∞ | yes c₁+c₂≈0 | -∞ with c₁ ≈? 0# degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 | -∞ | yes c₁+c₂≈0 | -∞ | yes c₁≈0 = contradiction TODO c₂≉0 degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 | -∞ | yes c₁+c₂≈0 | -∞ | no c₁≉0 = contradiction TODO c₂≉0 degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) ⟨ () ⟩ | -∞ | no c₂≉0 | -∞ | yes c₁+c₂≈0 | ⟨ n ⟩ degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 | -∞ | no c₁+c₂≉0 = ≤ᵈ-refl degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | -∞ | no c₂≉0 | ⟨ r ⟩ = ⟨ 0≤n ⟩ degreeⁱ[q]≤degreeⁱ[p+ⁱq] (c₁ +x∙ p) (c₂ +x∙ q) _ | ⟨ m ⟩ = TODO degree[q]≤degree[p+ᵖq] : ∀ p q → degree p ≤ᵈ degree q → degree q ≤ᵈ degree (p +ᵖ q) degree[q]≤degree[p+ᵖq] p q degree[p]≤degree[q] = begin degree q ≡ᵈ⟨ ≡-sym (degreeⁱ≡degree q) ⟩ degreeⁱ (expand q) ≤ᵈ⟨ degreeⁱ[q]≤degreeⁱ[p+ⁱq] (expand p) (expand q) degreeⁱ[p]≤degreeⁱ[q] ⟩ degreeⁱ (expand p +ⁱ expand q) ≡ᵈ⟨ ≡-sym (degreeⁱ-cong (expand-+ᵖ-homo p q)) ⟩ degreeⁱ (expand (p +ᵖ q)) ≡ᵈ⟨ degreeⁱ≡degree (p +ᵖ q) ⟩ degree (p +ᵖ q) ∎ᵈ where open ≤ᵈ-Reasoning degreeⁱ[p]≤degreeⁱ[q] : degreeⁱ (expand p) ≤ᵈ degreeⁱ (expand q) degreeⁱ[p]≤degreeⁱ[q] = begin degreeⁱ (expand p) ≡ᵈ⟨ degreeⁱ≡degree p ⟩ degree p ≤ᵈ⟨ degree[p]≤degree[q] ⟩ degree q ≡ᵈ⟨ ≡-sym (degreeⁱ≡degree q) ⟩ degreeⁱ (expand q) ∎ᵈ -- idea : ∀ o₁ p o₂ q → o₁ < o₂ → degree (x^ o₁ ∙ p +ᵖ x^ o₂ ∙ q) ≡ degree (x^ o₂ ∙ q) -- idea o₁ p o₂ q o₁<o₂ with <-cmp o₁ o₂ -- idea o₁ (K c₁) o₂ q o₁<o₂ | tri< _ _ _ = {!!} -- idea o₁ (c₁ +x^ n₁ ∙ p) o₂ q o₁<o₂ | tri< _ _ _ with +ᵖ-spine ⟅ n₁ ⇓⟆ p (o₂ ∸ o₁) q -- idea o₁ (c₁ +x^ n₁ ∙ p) o₂ q o₁<o₂ | tri< _ _ _ | 0ᵖ = {!!} -- idea o₁ (c₁ +x^ n₁ ∙ p) o₂ q o₁<o₂ | tri< _ _ _ | x^ zero ∙ r = {!!} -- idea o₁ (c₁ +x^ n₁ ∙ p) o₂ q o₁<o₂ | tri< _ _ _ | x^ suc n₃ ∙ r = {!!} -- idea o₁ p o₂ q o₁<o₂ | tri≈ o₁≮o₂ _ _ = contradiction o₁<o₂ o₁≮o₂ -- idea o₁ p o₂ q o₁<o₂ | tri> o₁≮o₂ _ _ = contradiction o₁<o₂ o₁≮o₂ *ᵖ-degree : ∀ p q → degree (p *ᵖ q) ≡ degree p +ᵈ degree q *ᵖ-degree 0ᵖ q = ≡-refl *ᵖ-degree (x^ o₁ ∙ p) 0ᵖ = ≡-refl *ᵖ-degree (x^ o₁ ∙ p) (x^ o₂ ∙ q) = *ᵖ-spine-degree o₁ p o₂ q where *ᵖ-spine-degree : ∀ o₁ p o₂ q → degree (*ᵖ-spine o₁ p o₂ q) ≡ ⟨ (o₁ +ℕ degreeˢ p) +ℕ (o₂ +ℕ degreeˢ q) ⟩ *ᵖ-spine-degree o₁ (K c₁) o₂ q = begin⟨ ≡-setoid Degree ⟩ ⟨ (o₁ +ℕ o₂) +ℕ degreeˢ (∙ᵖ-spine c₁ q) ⟩ ≡⟨ ≡-cong (λ t → ⟨ o₁ +ℕ o₂ +ℕ t ⟩) (∙ᵖ-spine-degreeˢ c₁ q) ⟩ ⟨ (o₁ +ℕ o₂) +ℕ degreeˢ q ⟩ ≡⟨ ≡-cong ⟨_⟩ (Nat.+-assoc o₁ o₂ (degreeˢ q)) ⟩ ⟨ o₁ +ℕ (o₂ +ℕ degreeˢ q) ⟩ ≡⟨ ≡-cong (λ t → ⟨ t +ℕ (o₂ +ℕ degreeˢ q) ⟩) (≡-sym (Nat.+-identityʳ o₁)) ⟩ ⟨ (o₁ +ℕ 0) +ℕ (o₂ +ℕ degreeˢ q) ⟩ ∎ *ᵖ-spine-degree o₁ (c₁ +x^ n₁ ∙ p) o₂ (K c₂) = begin⟨ ≡-setoid Degree ⟩ ⟨ o₁ +ℕ o₂ +ℕ (⟅ n₁ ⇓⟆ +ℕ degreeˢ (∙ᵖ-spine c₂ p)) ⟩ ≡⟨ ≡-cong (λ t → ⟨ o₁ +ℕ o₂ +ℕ (⟅ n₁ ⇓⟆ +ℕ t) ⟩) (∙ᵖ-spine-degreeˢ c₂ p) ⟩ ⟨ o₁ +ℕ o₂ +ℕ (⟅ n₁ ⇓⟆ +ℕ degreeˢ p) ⟩ ≡⟨ ≡-cong ⟨_⟩ (lemma o₁ o₂ ⟅ n₁ ⇓⟆ (degreeˢ p)) ⟩ ⟨ o₁ +ℕ (⟅ n₁ ⇓⟆ +ℕ degreeˢ p) +ℕ (o₂ +ℕ 0) ⟩ ∎ where lemma : ∀ x y n d → x +ℕ y +ℕ (n +ℕ d) ≡ x +ℕ (n +ℕ d) +ℕ (y +ℕ 0) lemma = solve Nat.ring *ᵖ-spine-degree o₁ (c₁ +x^ n₁ ∙ p) o₂ (c₂ +x^ n₂ ∙ q) = ≤ᵈ-antisym deg<deg+deg deg+deg<deg where open ≤ᵈ-Reasoning last-larger : degree (x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ (x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p)) ≤ᵈ degree (*ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) last-larger = TODO deg<deg+deg : degree (*ᵖ-spine o₁ (c₁ +x^ n₁ ∙ p) o₂ (c₂ +x^ n₂ ∙ q)) ≤ᵈ ⟨ (o₁ +ℕ degreeˢ (c₁ +x^ n₁ ∙ p)) +ℕ (o₂ +ℕ degreeˢ (c₂ +x^ n₂ ∙ q)) ⟩ deg<deg+deg = begin degree (x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ (x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p) +ᵖ *ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ≤ᵈ⟨ degreeᵖ-+ᵖ (x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ (x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p)) (*ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ⟩ degree (x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ (x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p)) ⊔ᵈ degree (*ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ≡ᵈ⟨ m≤ᵈn⇒m⊔ᵈn≡n last-larger ⟩ degree (*ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ≡ᵈ⟨ *ᵖ-spine-degree (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q ⟩ ⟨ ((o₁ +ℕ ⟅ n₁ ⇓⟆) +ℕ degreeˢ p) +ℕ ((o₂ +ℕ ⟅ n₂ ⇓⟆) +ℕ degreeˢ q) ⟩ ≡ᵈ⟨ ≡-cong₂ (λ x y → ⟨ x +ℕ y ⟩) (Nat.+-assoc o₁ ⟅ n₁ ⇓⟆ (degreeˢ p)) (Nat.+-assoc o₂ ⟅ n₂ ⇓⟆ (degreeˢ q)) ⟩ ⟨ o₁ +ℕ (⟅ n₁ ⇓⟆ +ℕ degreeˢ p) +ℕ (o₂ +ℕ (⟅ n₂ ⇓⟆ +ℕ degreeˢ q)) ⟩ ∎ᵈ deg+deg<deg : ⟨ o₁ +ℕ degreeˢ (c₁ +x^ n₁ ∙ p) +ℕ (o₂ +ℕ degreeˢ (c₂ +x^ n₂ ∙ q)) ⟩ ≤ᵈ degree (*ᵖ-spine o₁ (c₁ +x^ n₁ ∙ p) o₂ (c₂ +x^ n₂ ∙ q)) deg+deg<deg = begin ⟨ (o₁ +ℕ (⟅ n₁ ⇓⟆ +ℕ degreeˢ p)) +ℕ (o₂ +ℕ (⟅ n₂ ⇓⟆ +ℕ degreeˢ q)) ⟩ ≡ᵈ⟨ ≡-cong₂ (λ x y → ⟨ x +ℕ y ⟩) (≡-sym (Nat.+-assoc o₁ ⟅ n₁ ⇓⟆ (degreeˢ p))) (≡-sym (Nat.+-assoc o₂ ⟅ n₂ ⇓⟆ (degreeˢ q))) ⟩ ⟨ ((o₁ +ℕ ⟅ n₁ ⇓⟆) +ℕ degreeˢ p) +ℕ ((o₂ +ℕ ⟅ n₂ ⇓⟆) +ℕ degreeˢ q) ⟩ ≡ᵈ⟨ ≡-sym (*ᵖ-spine-degree (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ⟩ degree (*ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) ≤ᵈ⟨ degree[q]≤degree[p+ᵖq] (x^ (o₁ +ℕ o₂) ∙ K (c₁ *-nonzero c₂) +ᵖ c₁ ∙ᵖ x^ (o₁ +ℕ o₂ +ℕ ⟅ n₂ ⇓⟆) ∙ q +ᵖ c₂ ∙ᵖ (x^ (o₁ +ℕ o₂ +ℕ ⟅ n₁ ⇓⟆) ∙ p)) (*ᵖ-spine (o₁ +ℕ ⟅ n₁ ⇓⟆) p (o₂ +ℕ ⟅ n₂ ⇓⟆) q) last-larger ⟩ degree (*ᵖ-spine o₁ (c₁ +x^ n₁ ∙ p) o₂ (c₂ +x^ n₂ ∙ q)) ∎ᵈ -ᵖ-degree : ∀ p → degree (-ᵖ p) ≡ degree p -ᵖ-degree = ∙ᵖ-degree -1#-nonzero deg-+ᵖ : ∀ p q {p≉0} {q≉0} {p+q≉0} → deg (p +ᵖ q) {p+q≉0} ≤ deg p {p≉0} ⊔ deg q {q≉0} deg-+ᵖ 0ᵖ q {p≉0} {q≉0} {p+q≉0} = contradiction ≈ᵖ-refl p≉0 deg-+ᵖ (x^ o₁ ∙ p) 0ᵖ {p≉0} {q≉0} {p+q≉0} = contradiction ≈ᵖ-refl q≉0 deg-+ᵖ (x^ o₁ ∙ p) (x^ o₂ ∙ q) {p≉0} {q≉0} {p+q≉0} = helper (x^ o₁ ∙ p +ᵖ x^ o₂ ∙ q) {p+q≉0} (degreeᵖ-+ᵖ (x^ o₁ ∙ p) (x^ o₂ ∙ q)) where helper : ∀ d {d≉0} {x} → degree d ≤ᵈ ⟨ x ⟩ → deg d {d≉0} ≤ x helper 0ᵖ {d≉0} = contradiction ≈ᵖ-refl d≉0 helper (x^ o₃ ∙ d) {d≉0} ⟨ pf ⟩ = pf deg-cong : ∀ {p q} {p≉0} {q≉0} → p ≈ᵖ q → deg p {p≉0} ≡ deg q {q≉0} deg-cong {0ᵖ} {q} {p≉0} {q≉0} p≈q = contradiction ≈ᵖ-refl p≉0 deg-cong {x^ o₁ ∙ p} {0ᵖ} {p≉0} {q≉0} p≈q = contradiction ≈ᵖ-refl q≉0 deg-cong {x^ o₁ ∙ p} {x^ o₂ ∙ q} {p≉0} {q≉0} (0ᵖ≉ ≡-refl p≈q) rewrite degreeˢ-cong p≈q = ≡-refl data Coefficients : Set (c ⊔ˡ ℓ) where 0ᶜ : Coefficients _∙x^_+_ : C/0 → ℕ → Coefficients → Coefficients coefficientsˢ : ℕ → Spine → Coefficients → Coefficients coefficientsˢ o (K c) coeffs = c ∙x^ o + coeffs coefficientsˢ o (c +x^ n ∙ p) coeffs = coefficientsˢ (o +ℕ ⟅ n ⇓⟆) p (c ∙x^ o + coeffs) coefficients : Polynomial → Coefficients coefficients 0ᵖ = 0ᶜ coefficients (x^ o ∙ p) = coefficientsˢ o p 0ᶜ polynomial : Coefficients → Polynomial polynomial 0ᶜ = 0ᵖ polynomial (c ∙x^ n + p) = c ∙𝑋^ n +ᵖ polynomial p polynomial∘coefficients≡id : ∀ p → polynomial (coefficients p) ≈ᵖ p polynomial∘coefficients≡id 0ᵖ = ≈ᵖ-refl polynomial∘coefficients≡id (x^ o ∙ p) = loop o p 0ᶜ where lemma : ∀ o c n p → x^ o ∙ K c +ᵖ x^ (o +ℕ ⟅ n ⇓⟆) ∙ p ≈ᵖ x^ o ∙ (c +x^ n ∙ p) lemma o c n p = expand-injective $ begin⟨ ≈ⁱ-setoid ⟩ expand (x^ o ∙ K c +ᵖ x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) ≈⟨ expand-+ᵖ-homo (x^ o ∙ K c) (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) ⟩ expandˢ o (K c) +ⁱ expandˢ (o +ℕ ⟅ n ⇓⟆) p ≈⟨ ≈ⁱ-sym (expandˢ-+x^-lemma o n c p) ⟩ expandˢ o (c +x^ n ∙ p) ∎ loop : ∀ o p coeffs → polynomial (coefficientsˢ o p coeffs) ≈ᵖ x^ o ∙ p +ᵖ polynomial coeffs loop o (K c) coeffs = ≈ᵖ-refl loop o (c +x^ n ∙ p) coeffs = begin⟨ ≈ᵖ-setoid ⟩ polynomial (coefficientsˢ (o +ℕ ⟅ n ⇓⟆) p (c ∙x^ o + coeffs)) ≈⟨ loop (o +ℕ ⟅ n ⇓⟆) p (c ∙x^ o + coeffs) ⟩ x^ (o +ℕ ⟅ n ⇓⟆) ∙ p +ᵖ (x^ o ∙ K c +ᵖ polynomial coeffs) ≈⟨ ≈ᵖ-sym (+ᵖ-assoc (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) (x^ o ∙ K c) (polynomial coeffs)) ⟩ (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p +ᵖ x^ o ∙ K c) +ᵖ polynomial coeffs ≈⟨ +ᵖ-congʳ (+ᵖ-comm (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) (x^ o ∙ K c)) ⟩ (x^ o ∙ K c +ᵖ x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) +ᵖ polynomial coeffs ≈⟨ +ᵖ-congʳ {polynomial coeffs} {x^ o ∙ K c +ᵖ x^ (o +ℕ ⟅ n ⇓⟆) ∙ p} {x^ o ∙ (c +x^ n ∙ p)} (lemma _ _ _ _) ⟩ (x^ o ∙ (c +x^ n ∙ p)) +ᵖ polynomial coeffs ∎ coefficientsˢ≢0ᶜ : ∀ o p coeffs → coefficientsˢ o p coeffs ≢ 0ᶜ coefficientsˢ≢0ᶜ o (K c) coeffs = λ () coefficientsˢ≢0ᶜ o (c +x^ n ∙ p) coeffs = coefficientsˢ≢0ᶜ (o +ℕ ⟅ n ⇓⟆) p (c ∙x^ o + coeffs) coefficients≢0ᶜ : ∀ p {p≉0 : p ≉ᵖ 0ᵖ} → coefficients p ≢ 0ᶜ coefficients≢0ᶜ 0ᵖ {p≉0} = contradiction ≈ᵖ-refl p≉0 coefficients≢0ᶜ (x^ o ∙ p) {p≉0} = coefficientsˢ≢0ᶜ o p 0ᶜ degᶜ : ∀ c {c≉0 : c ≢ 0ᶜ} → ℕ degᶜ 0ᶜ {c≉0} = contradiction ≡-refl c≉0 degᶜ (_ ∙x^ n + _) = n degᶜ[coefficients] : ∀ p {p≉0} → degᶜ (coefficients p) {coefficients≢0ᶜ p {p≉0}} ≡ deg p {p≉0} degᶜ[coefficients] 0ᵖ {p≉0} = contradiction ≈ᵖ-refl p≉0 degᶜ[coefficients] (x^ o ∙ p) = loop o p 0ᶜ where loop : ∀ o p coeffs → degᶜ (coefficientsˢ o p coeffs) {coefficientsˢ≢0ᶜ o p coeffs} ≡ o +ℕ degreeˢ p loop o (K c) coeffs = ≡-sym (Nat.+-identityʳ o) loop o (c +x^ n ∙ p) coeffs = begin⟨ ≡-setoid ℕ ⟩ degᶜ (coefficientsˢ (o +ℕ ⟅ n ⇓⟆) p (c ∙x^ o + coeffs)) ≡⟨ loop (o +ℕ ⟅ n ⇓⟆) p (c ∙x^ o + coeffs) ⟩ (o +ℕ ⟅ n ⇓⟆) +ℕ degreeˢ p ≡⟨ Nat.+-assoc o ⟅ n ⇓⟆ (degreeˢ p) ⟩ o +ℕ (⟅ n ⇓⟆ +ℕ degreeˢ p) ∎ -- leading : ∀ p {p≉0 : p ≉ᵖ 0ᵖ} → Leading p {p≉0} -- leading p {p≉0} = helper (coefficients p) {coefficients≢0ᶜ p {p≉0}} (polynomial∘coefficients≡id p) (degᶜ[coefficients] p) -- where -- helper : ∀ coeffs {coeffs≢0} → polynomial coeffs ≈ᵖ p → degᶜ coeffs {coeffs≢0} ≡ deg p {p≉0} → Leading p {p≉0} -- helper 0ᶜ {coeffs≢0} = contradiction ≡-refl coeffs≢0 -- helper (leading-coefficient ∙x^ leading-degree + next-term) roundtrip leading-degree≡degree = -- Leading✓ leading-coefficient leading-degree leading-degree≡degree (polynomial next-term) {!!} roundtrip data Remainder (r : Polynomial) (m : Polynomial) {m≉0 : m ≉ᵖ 0ᵖ} : Set (c ⊔ˡ ℓ) where 0ᵖ≈ : (r≈0 : r ≈ᵖ 0ᵖ) → Remainder r m 0ᵖ≉ : (r≉0 : r ≉ᵖ 0ᵖ) → deg r {r≉0} < deg m {m≉0} → Remainder r m record Leading (p : Polynomial) {p≉0 : p ≉ᵖ 0ᵖ} : Set (c ⊔ˡ ℓ) where constructor Leading✓ field leading-coefficent : C/0 leading-degree : ℕ leading-degree≡degree : leading-degree ≡ deg p {p≉0} next-term : Polynomial next-term<p : Remainder next-term p {p≉0} proof : leading-coefficent ∙𝑋^ leading-degree +ᵖ next-term ≈ᵖ p leading : ∀ p {p≉0 : p ≉ᵖ 0ᵖ} → Leading p {p≉0} leading 0ᵖ {p≉0} = contradiction ≈ᵖ-refl p≉0 leading (x^ o ∙ p) {p≉0} = loop o p {p≉0} where open ≤-Reasoning using (begin-strict_; _<⟨_⟩_; _≤⟨_⟩_) renaming (_≡⟨_⟩_ to _≡≤⟨_⟩_; _∎ to _≤∎) degree-step : ∀ o n c p → deg (x^ o +ℕ ⟅ n ⇓⟆ ∙ p) {λ ()} ≡ deg (x^ o ∙ (c +x^ n ∙ p)) {λ ()} degree-step o n c p = Nat.+-assoc o ⟅ n ⇓⟆ (degreeˢ p) remainder-smaller : ∀ o n c p {r≉0} {r'≉0} → deg (x^ o ∙ K c) {r≉0} < deg (x^ o ∙ (c +x^ n ∙ p)) {r'≉0} remainder-smaller o (ℕ+ n) c p = lte (n +ℕ degreeˢ p) (lemma o n (degreeˢ p)) where lemma : ∀ x y z → suc (x +ℕ 0 +ℕ (y +ℕ z)) ≡ x +ℕ suc (y +ℕ z) lemma = solve Nat.ring remainder-base : ∀ next o n c p {r≉0} → next ≈ᵖ 0ᵖ → Remainder ((x^ o ∙ K c) +ᵖ next) (x^ o ∙ (c +x^ n ∙ p)) {r≉0} remainder-base next o n c p {r≉0} next≈0 = 0ᵖ≉ c∙𝑋^o+next≉0 smaller where c∙𝑋^o≈c∙𝑋^o+next : c ∙𝑋^ o ≈ᵖ c ∙𝑋^ o +ᵖ next c∙𝑋^o≈c∙𝑋^o+next = begin⟨ ≈ᵖ-setoid ⟩ c ∙𝑋^ o ≈⟨ ≈ᵖ-sym (+ᵖ-identityʳ _) ⟩ c ∙𝑋^ o +ᵖ 0ᵖ ≈⟨ +ᵖ-congˡ {c ∙𝑋^ o} (≈ᵖ-sym next≈0) ⟩ c ∙𝑋^ o +ᵖ next ∎ c∙𝑋^o+next≉0 : c ∙𝑋^ o +ᵖ next ≉ᵖ 0ᵖ c∙𝑋^o+next≉0 c∙𝑋^o+next≈0 = contradiction (begin⟨ ≈ᵖ-setoid ⟩ c ∙𝑋^ o ≈⟨ c∙𝑋^o≈c∙𝑋^o+next ⟩ c ∙𝑋^ o +ᵖ next ≈⟨ c∙𝑋^o+next≈0 ⟩ 0ᵖ ∎) (λ ()) smaller : deg ((x^ o ∙ K c) +ᵖ next) {c∙𝑋^o+next≉0} < deg (x^ o ∙ (c +x^ n ∙ p)) {r≉0} smaller = begin-strict deg (x^ o ∙ K c +ᵖ next) ≡≤⟨ deg-cong {p≉0 = c∙𝑋^o+next≉0} {q≉0 = λ ()} (≈ᵖ-sym (c∙𝑋^o≈c∙𝑋^o+next)) ⟩ deg (x^ o ∙ K c) {λ ()} <⟨ remainder-smaller o n c p {λ ()} {r≉0} ⟩ deg (x^ o ∙ (c +x^ n ∙ p)) {r≉0} ≤∎ remainder-step : ∀ next o n c p {r≉0} → Remainder next (x^ o +ℕ ⟅ n ⇓⟆ ∙ p) {λ ()} → Remainder ((x^ o ∙ K c) +ᵖ next) (x^ o ∙ (c +x^ n ∙ p)) {r≉0} remainder-step next o n c p {r≉0} (0ᵖ≈ next≈0) = remainder-base next o n c p next≈0 remainder-step next o n c p {r≉0} (0ᵖ≉ next≉0 next<r) with x^ o ∙ K c +ᵖ next ≈ᵖ? 0ᵖ ... | yes r'≈0 = 0ᵖ≈ r'≈0 ... | no r'≉0 = 0ᵖ≉ r'≉0 smaller where smaller : deg ((x^ o ∙ K c) +ᵖ next) {r'≉0} < deg (x^ o ∙ (c +x^ n ∙ p)) {r≉0} smaller rewrite degree-step o n c p = begin-strict deg ((x^ o ∙ K c) +ᵖ next) {r'≉0} ≤⟨ deg-+ᵖ (x^ o ∙ K c) next {p≉0 = λ ()} ⟩ deg (x^ o ∙ K c) {λ ()} ⊔ deg next {next≉0} <⟨ ⊔-least-< (deg (x^ o ∙ K c) {λ ()}) (deg next) (deg (x^ o ∙ (c +x^ n ∙ p)) {r≉0}) (remainder-smaller o n c p {λ ()} {r≉0}) next<r ⟩ deg (x^ o ∙ (c +x^ n ∙ p)) {r≉0} ≤∎ lemma : ∀ o c n p → x^ o ∙ K c +ᵖ x^ (o +ℕ ⟅ n ⇓⟆) ∙ p ≈ᵖ x^ o ∙ (c +x^ n ∙ p) lemma o c n p = expand-injective $ begin⟨ ≈ⁱ-setoid ⟩ expand (x^ o ∙ K c +ᵖ x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) ≈⟨ expand-+ᵖ-homo (x^ o ∙ K c) (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) ⟩ expandˢ o (K c) +ⁱ expandˢ (o +ℕ ⟅ n ⇓⟆) p ≈⟨ ≈ⁱ-sym (expandˢ-+x^-lemma o n c p) ⟩ expandˢ o (c +x^ n ∙ p) ∎ proof-step : ∀ lc o n c p next → lc ∙𝑋^ deg (x^ o +ℕ ⟅ n ⇓⟆ ∙ p) {λ ()} +ᵖ next ≈ᵖ x^ o +ℕ ⟅ n ⇓⟆ ∙ p → lc ∙𝑋^ deg (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) {λ ()} +ᵖ ((x^ o ∙ K c) +ᵖ next) ≈ᵖ x^ o ∙ (c +x^ n ∙ p) proof-step lc o n c p next pf = begin⟨ ≈ᵖ-setoid ⟩ lc ∙𝑋^ deg (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) {λ ()} +ᵖ (x^ o ∙ K c +ᵖ next) ≈⟨ +ᵖ-congˡ {lc ∙𝑋^ deg (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) {λ ()}} (+ᵖ-comm (x^ o ∙ K c) next) ⟩ lc ∙𝑋^ deg (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) {λ ()} +ᵖ (next +ᵖ x^ o ∙ K c) ≈⟨ ≈ᵖ-sym (+ᵖ-assoc (lc ∙𝑋^ deg (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) {λ ()}) next (x^ o ∙ K c)) ⟩ (lc ∙𝑋^ deg (x^ (o +ℕ ⟅ n ⇓⟆) ∙ p) {λ ()} +ᵖ next) +ᵖ x^ o ∙ K c ≈⟨ +ᵖ-congʳ {x^ o ∙ K c} pf ⟩ x^ o +ℕ ⟅ n ⇓⟆ ∙ p +ᵖ x^ o ∙ K c ≈⟨ +ᵖ-comm (x^ o +ℕ ⟅ n ⇓⟆ ∙ p) (x^ o ∙ K c) ⟩ x^ o ∙ K c +ᵖ x^ o +ℕ ⟅ n ⇓⟆ ∙ p ≈⟨ lemma o c n p ⟩ x^ o ∙ (c +x^ n ∙ p) ∎ loop : ∀ o p {p≉0 : x^ o ∙ p ≉ᵖ 0ᵖ} → Leading (x^ o ∙ p) {p≉0} loop o (K c) = Leading✓ c o (≡-sym (Nat.+-identityʳ o)) 0ᵖ (0ᵖ≈ ≈ᵖ-refl) (+ᵖ-identityʳ (c ∙𝑋^ o)) loop o (c +x^ n ∙ p) with loop (o +ℕ ⟅ n ⇓⟆) p {λ ()} ... | Leading✓ lc d ≡-refl next next<p pf = Leading✓ lc d (degree-step o n c p) (c ∙𝑋^ o +ᵖ next) (remainder-step next o n c p next<p) (proof-step lc o n c p next pf) record Euclidean (n : Polynomial) (m : Polynomial) {m≉0 : m ≉ᵖ 0ᵖ} : Set (c ⊔ˡ ℓ) where constructor Euclidean✓ field q : Polynomial r : Polynomial division : n ≈ᵖ m *ᵖ q +ᵖ r remainder : Remainder r m {m≉0} divMod-base₁ : ∀ n m → n ≈ᵖ 0ᵖ → n ≈ᵖ m *ᵖ 0ᵖ +ᵖ 0ᵖ divMod-base₁ n m n≈0 = begin⟨ ≈ᵖ-setoid ⟩ n ≈⟨ n≈0 ⟩ 0ᵖ ≈⟨ ≈ᵖ-sym (*ᵖ-zeroʳ m) ⟩ m *ᵖ 0ᵖ ≈⟨ ≈ᵖ-sym (+ᵖ-identityʳ _) ⟩ m *ᵖ 0ᵖ +ᵖ 0ᵖ ∎ -- open import Strict using (force) open import Agda.Builtin.Strict using (primForce; primForceLemma) force : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) → (∀ y → x ≡ y → B y) → B x force {B = B} x f = primForce ≡-refl (primForce {B = λ y → x ≡ y → B y} x f) force-≡ : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) (f : ∀ y → x ≡ y → B y) → force x f ≡ f x ≡-refl force-≡ {B = B} x f rewrite primForceLemma {B = λ y → x ≡ y → B y} x f = ≡-refl divMod : ∀ n m {m≉0} → Euclidean n m {m≉0} divMod n m {m≉0} with n ≈ᵖ? 0ᵖ ... | yes n≈0 = Euclidean✓ 0ᵖ 0ᵖ (divMod-base₁ n m n≈0) (0ᵖ≈ ≈ᵖ-refl) ... | no n≉0 = loop 0ᵖ n {n≉0} (solveOver (n ∷ m ∷ []) +ᵖ-*ᵖ-almostCommutativeRing) <-well-founded where open ≤-Reasoning using (begin-strict_; _<⟨_⟩_; _≤⟨_⟩_) renaming (_≡⟨_⟩_ to _≡≤⟨_⟩_; _∎ to _≤∎) term : ∀ r {r≉0} → Polynomial term r {r≉0} with leading r {r≉0} | leading m {m≉0} ... | Leading✓ lcʳ degʳ _ _ _ _ | Leading✓ lcᵐ degᵐ _ _ _ _ = (lcʳ /-nonzero lcᵐ) ∙𝑋^ (degʳ ∸ degᵐ) term-smaller : ∀ r {r≉0 : r ≉ᵖ 0ᵖ} {r'≉0 : r -ᵖ term r {r≉0} *ᵖ m ≉ᵖ 0ᵖ} → deg m {m≉0} ≤ deg r {r≉0} → deg (r -ᵖ term r {r≉0} *ᵖ m) {r'≉0} < deg r {r≉0} term-smaller r {r≉0} {r'≉0} m≤r with leading r {r≉0} | leading m {m≉0} ... | Leading✓ lcʳ degʳ degʳ-pf restʳ restʳ<r pfʳ | Leading✓ lcᵐ degᵐ ≡-refl degᵐ-pf restᵐ<m pfᵐ = begin-strict deg (r -ᵖ ((lcʳ /-nonzero lcᵐ) ∙𝑋^ (degʳ ∸ degᵐ)) *ᵖ m) {r'≉0} <⟨ {!!} ⟩ deg r {r≉0} ≤∎ -- restʳ -ᵖ (lcʳ /-nonzero lcᵐ) ∙𝑋^ (degʳ ∸ degᵐ) *ᵖ restᵐ) -- deg[r] ∸ deg[m] + deg[restᵐ] < deg[r] divMod-base₂ : ∀ q r {r≉0} → n ≈ᵖ m *ᵖ q +ᵖ r → r -ᵖ term r {r≉0} *ᵖ m ≈ᵖ 0ᵖ → n ≈ᵖ m *ᵖ (q +ᵖ term r {r≉0}) +ᵖ 0ᵖ divMod-base₂ q r {r≉0} n≈mq+r r-t*m≈0 = begin⟨ ≈ᵖ-setoid ⟩ n ≈⟨ n≈mq+r ⟩ m *ᵖ q +ᵖ r ≈⟨ ≈ᵖ-sym (+ᵖ-identityʳ _) ⟩ m *ᵖ q +ᵖ r +ᵖ 0ᵖ ≈⟨ +ᵖ-congˡ {m *ᵖ q +ᵖ r} (≈ᵖ-sym (-ᵖ‿inverseˡ (term r {r≉0} *ᵖ m))) ⟩ m *ᵖ q +ᵖ r +ᵖ ((-ᵖ (term r {r≉0} *ᵖ m)) +ᵖ term r {r≉0} *ᵖ m) ≈⟨ ≈ᵖ-sym (+ᵖ-assoc (m *ᵖ q +ᵖ r) (-ᵖ (term r *ᵖ m)) (term r *ᵖ m)) ⟩ ((m *ᵖ q +ᵖ r) -ᵖ term r {r≉0} *ᵖ m) +ᵖ term r {r≉0} *ᵖ m ≈⟨ +ᵖ-cong (+ᵖ-assoc (m *ᵖ q) r (-ᵖ (term r *ᵖ m))) (*ᵖ-comm (term r) m) ⟩ (m *ᵖ q +ᵖ (r -ᵖ term r {r≉0} *ᵖ m)) +ᵖ m *ᵖ term r {r≉0} ≈⟨ +ᵖ-congʳ {m *ᵖ term r} (+ᵖ-congˡ {m *ᵖ q} r-t*m≈0) ⟩ (m *ᵖ q +ᵖ 0ᵖ) +ᵖ m *ᵖ term r {r≉0} ≈⟨ +ᵖ-congʳ {m *ᵖ term r} (+ᵖ-identityʳ (m *ᵖ q)) ⟩ m *ᵖ q +ᵖ m *ᵖ term r {r≉0} ≈⟨ ≈ᵖ-sym (*ᵖ-distribˡ-+ᵖ m q (term r)) ⟩ m *ᵖ (q +ᵖ term r {r≉0}) ≈⟨ ≈ᵖ-sym (+ᵖ-identityʳ (m *ᵖ (q +ᵖ term r))) ⟩ m *ᵖ (q +ᵖ term r {r≉0}) +ᵖ 0ᵖ ∎ divMod-step : ∀ q r {r≉0} → n ≈ᵖ m *ᵖ q +ᵖ r → n ≈ᵖ m *ᵖ (q +ᵖ term r {r≉0}) +ᵖ (r -ᵖ term r {r≉0} *ᵖ m) divMod-step q r {r≉0} n≈mq+r = begin⟨ ≈ᵖ-setoid ⟩ n ≈⟨ n≈mq+r ⟩ m *ᵖ q +ᵖ r ≈⟨ ≈ᵖ-sym (+ᵖ-identityʳ _) ⟩ m *ᵖ q +ᵖ r +ᵖ 0ᵖ ≈⟨ +ᵖ-congˡ {m *ᵖ q +ᵖ r} (≈ᵖ-sym (-ᵖ‿inverseʳ (term r {r≉0} *ᵖ m))) ⟩ m *ᵖ q +ᵖ r +ᵖ (term r {r≉0} *ᵖ m -ᵖ term r {r≉0} *ᵖ m) ≈⟨ final m q r (term r) (-ᵖ (term r *ᵖ m)) ⟩ m *ᵖ (q +ᵖ term r {r≉0}) +ᵖ (r -ᵖ term r {r≉0} *ᵖ m) ∎ where final : ∀ m q r x y → m *ᵖ q +ᵖ r +ᵖ (x *ᵖ m +ᵖ y) ≈ᵖ m *ᵖ (q +ᵖ x) +ᵖ (r +ᵖ y) final = solve +ᵖ-*ᵖ-almostCommutativeRing loop : ∀ q r {r≉0} → n ≈ᵖ m *ᵖ q +ᵖ r → Acc _<_ (deg r {r≉0}) → Euclidean n m {m≉0} loop q r {r≉0} n≈mq+r (acc downward) with <-≤-connex (deg r {r≉0}) (deg m {m≉0}) ... | inj₁ r<m = Euclidean✓ q r n≈mq+r (0ᵖ≉ r≉0 r<m) ... | inj₂ r≥m with (r -ᵖ term r {r≉0} *ᵖ m) ≈ᵖ? 0ᵖ ... | yes r'≈0 = Euclidean✓ (q +ᵖ term r {r≉0}) 0ᵖ (divMod-base₂ q r {r≉0} n≈mq+r r'≈0) (0ᵖ≈ ≈ᵖ-refl) ... | no r'≉0 = force (q +ᵖ term r {r≉0}) λ { q' ≡-refl → loop q' (r -ᵖ term r {r≉0} *ᵖ m) {r'≉0} (divMod-step q r {r≉0} n≈mq+r) (downward _ (term-smaller r r≥m)) } -- factor : ∀ p a → ⟦ p ⟧ a ≈ 0# → (𝑋 -ᵖ 𝐾 a) ∣ p -- factor = TODO
{ "alphanum_fraction": 0.5009914078, "avg_line_length": 56.5396113602, "ext": "agda", "hexsha": "7687d89a403729595919cf835211a1092a227ec3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/thesis", "max_forks_repo_path": "proofs/AKS/Polynomial/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mckeankylej/thesis", "max_issues_repo_path": "proofs/AKS/Polynomial/Properties.agda", "max_line_length": 212, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/thesis", "max_stars_repo_path": "proofs/AKS/Polynomial/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z", "num_tokens": 46156, "size": 75650 }
open import Relation.Binary.PropositionalEquality using (sym) open import Data.Fin using (zero; suc) open import Data.Nat using (suc) open import Substitution using (rename-subst-commute; subst-commute) open import DeBruijn open import Beta infix 3 _—↠ˢ_ _—↠ˢ_ : ∀ {n m} → Subst n m → Subst n m → Set σ —↠ˢ σ′ = ∀ {x} → σ x —↠ σ′ x beta-rename : ∀ {n m} {ρ : Rename n m} {M M′ : Term n} → M —→ M′ ------------------------- → rename ρ M —→ rename ρ M′ beta-rename (—→-ƛ M—→M′) = —→-ƛ (beta-rename M—→M′) beta-rename (—→-ξₗ M—→M′) = —→-ξₗ (beta-rename M—→M′) beta-rename (—→-ξᵣ N—→N′) = —→-ξᵣ (beta-rename N—→N′) beta-rename {ρ = ρ} (—→-β {M = M}{N = N}) rewrite sym (rename-subst-commute {N = M}{M = N}{ρ = ρ}) = —→-β betas-rename : ∀ {n m} {ρ : Rename n m} {M M′ : Term n} → M —↠ M′ ------------------------- → rename ρ M —↠ rename ρ M′ betas-rename {ρ = ρ} (M ∎) = rename ρ M ∎ betas-rename {ρ = ρ} (M —→⟨ M—→L ⟩ L—↠M′) = rename ρ M —→⟨ beta-rename M—→L ⟩ betas-rename L—↠M′ betas-subst-exts : ∀ {n m} {σ σ′ : Subst n m} → σ —↠ˢ σ′ ------------------ → exts σ —↠ˢ exts σ′ betas-subst-exts σ—↠σ′ {zero} = # zero ∎ betas-subst-exts σ—↠σ′ {suc x} = betas-rename σ—↠σ′ subst-betas-sub : ∀ {n m} {M : Term n} {σ σ′ : Subst n m} → σ —↠ˢ σ′ ----------------------- → subst σ M —↠ subst σ′ M subst-betas-sub {M = # x} σ—↠σ′ = σ—↠σ′ subst-betas-sub {M = M · N} σ—↠σ′ = —↠-cong (subst-betas-sub {M = M} σ—↠σ′) (subst-betas-sub {M = N} σ—↠σ′) subst-betas-sub {M = ƛ M} σ—↠σ′ = —↠-cong-ƛ (subst-betas-sub {M = M} (λ {x} → betas-subst-exts σ—↠σ′ {x = x})) subst-beta-term : ∀ {n m} {M M′ : Term n} {σ : Subst n m} → M —→ M′ ----------------------- → subst σ M —→ subst σ M′ subst-beta-term (—→-ƛ M—→M′) = —→-ƛ (subst-beta-term M—→M′) subst-beta-term (—→-ξₗ M—→M′) = —→-ξₗ (subst-beta-term M—→M′) subst-beta-term (—→-ξᵣ N—→N′) = —→-ξᵣ (subst-beta-term N—→N′) subst-beta-term {σ = σ} (—→-β {M = M}{N = N}) rewrite sym (subst-commute {N = M}{M = N}{σ = σ}) = —→-β subst-betas : ∀ {n m} {σ σ′ : Subst n m} {M M′ : Term n} → σ —↠ˢ σ′ → M —↠ M′ ------------------------ → subst σ M —↠ subst σ′ M′ subst-betas σ—↠σ′ (M ∎) = subst-betas-sub {M = M} σ—↠σ′ subst-betas {σ = σ} σ—↠σ′ (M —→⟨ M—→L ⟩ L—↠M′) = subst σ M —→⟨ subst-beta-term M—→L ⟩ subst-betas σ—↠σ′ L—↠M′ betas-subst-zero : ∀ {n} {M M′ : Term n} → M —↠ M′ ------------------------------ → subst-zero M —↠ˢ subst-zero M′ betas-subst-zero M—↠M′ {zero} = M—↠M′ betas-subst-zero M—↠M′ {suc x} = # x ∎ sub-betas : ∀ {n} {M M′ : Term (suc n)} {N N′ : Term n} → M —↠ M′ → N —↠ N′ -------------------- → M [ N ] —↠ M′ [ N′ ] sub-betas M—↠M′ N—↠N′ = subst-betas (betas-subst-zero N—↠N′) M—↠M′
{ "alphanum_fraction": 0.4518595759, "avg_line_length": 32.3258426966, "ext": "agda", "hexsha": "d556ca363efa75ee4d8d3fd3ea2bbb72267c9cc2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "iwilare/church-rosser", "max_forks_repo_path": "BetaSubstitutivity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "iwilare/church-rosser", "max_issues_repo_path": "BetaSubstitutivity.agda", "max_line_length": 97, "max_stars_count": 5, "max_stars_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "iwilare/church-rosser", "max_stars_repo_path": "BetaSubstitutivity.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-22T01:43:09.000Z", "max_stars_repo_stars_event_min_datetime": "2020-06-02T07:27:54.000Z", "num_tokens": 1324, "size": 2877 }
open import Formalization.PredicateLogic.Signature module Formalization.PredicateLogic.Constructive.NaturalDeduction (𝔏 : Signature) where open Signature(𝔏) open import Data.ListSized import Lvl open import Formalization.PredicateLogic.Syntax(𝔏) open import Formalization.PredicateLogic.Syntax.Substitution(𝔏) open import Functional using (_∘_ ; _∘₂_ ; swap) open import Numeral.Finite open import Numeral.Natural open import Relator.Equals.Proofs.Equiv open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to · ; _≡_ to _≡ₛ_) open import Type private variable ℓ : Lvl.Level private variable args vars : ℕ private variable Γ : PredSet{ℓ}(Formula(vars)) data _⊢_ {ℓ} : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type{Lvl.𝐒(ℓₚ Lvl.⊔ ℓₒ Lvl.⊔ ℓ)} where direct : (Γ ⊆ (Γ ⊢_)) [⊤]-intro : (Γ ⊢ ⊤) [⊥]-elim : ∀{φ} → (Γ ⊢ ⊥) → (Γ ⊢ φ) [∧]-intro : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ ψ) → (Γ ⊢ (φ ∧ ψ)) [∧]-elimₗ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ φ) [∧]-elimᵣ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ ψ) [∨]-introₗ : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ∨ ψ)) [∨]-introᵣ : ∀{φ ψ} → (Γ ⊢ ψ) → (Γ ⊢ (φ ∨ ψ)) [∨]-elim : ∀{φ ψ χ} → ((Γ ∪ · φ) ⊢ χ) → ((Γ ∪ · ψ) ⊢ χ) → (Γ ⊢ (φ ∨ ψ)) → (Γ ⊢ χ) [⟶]-intro : ∀{φ ψ} → ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (φ ⟶ ψ)) [⟶]-elim : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ⟶ ψ)) → (Γ ⊢ ψ) [Ɐ]-intro : ∀{φ} → (∀{t} → (Γ ⊢ (substitute0 t φ))) → (Γ ⊢ (Ɐ φ)) [Ɐ]-elim : ∀{φ} → (Γ ⊢ (Ɐ φ)) → ∀{t} → (Γ ⊢ (substitute0 t φ)) [∃]-intro : ∀{φ}{t} → (Γ ⊢ (substitute0 t φ)) → (Γ ⊢ (∃ φ)) [∃]-elim : ∀{φ ψ} → (∀{t} → (Γ ∪ ·(substitute0 t φ)) ⊢ ψ) → (Γ ⊢ (∃ φ)) → (Γ ⊢ ψ)
{ "alphanum_fraction": 0.5093542547, "avg_line_length": 37.6590909091, "ext": "agda", "hexsha": "942b8b3ec915d8d5c65676aed5c420ddad66b8de", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Formalization/PredicateLogic/Constructive/NaturalDeduction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Formalization/PredicateLogic/Constructive/NaturalDeduction.agda", "max_line_length": 151, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Formalization/PredicateLogic/Constructive/NaturalDeduction.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 879, "size": 1657 }
open import Function open import Relation.Binary open import Relation.Binary.PropositionalEquality as P open ≡-Reasoning open import Data.Empty open import Data.Unit open import Data.Sum as Sum open import Data.Product as Prod record ℕ∞ : Set where coinductive field pred : ⊤ ⊎ ℕ∞ open ℕ∞ public data-~ℕ∞~ : ⊤ ⊎ ℕ∞ → ⊤ ⊎ ℕ∞ → Set record _~ℕ∞~_ (n m : ℕ∞) : Set where coinductive field pred~ : data-~ℕ∞~ (pred n) (pred m) open _~ℕ∞~_ public data-~ℕ∞~ (inj₁ tt) (inj₁ tt) = ⊤ data-~ℕ∞~ (inj₁ tt) (inj₂ m') = ⊥ data-~ℕ∞~ (inj₂ n') (inj₁ tt) = ⊥ data-~ℕ∞~ (inj₂ n') (inj₂ m') = n' ~ℕ∞~ m' refl-ℕ∞ : {n : ℕ∞} → n ~ℕ∞~ n pred~ (refl-ℕ∞ {n}) with pred n pred~ refl-ℕ∞ | inj₁ tt = tt pred~ refl-ℕ∞ | inj₂ n' = refl-ℕ∞ ∞ : ℕ∞ pred ∞ = inj₂ ∞ succ : ℕ∞ → ℕ∞ pred (succ n) = inj₂ n _+∞_ : ℕ∞ → ℕ∞ → ℕ∞ pred (n +∞ m) with pred n | pred m pred (n +∞ m) | inj₁ tt | inj₁ tt = inj₁ tt pred (n +∞ m) | inj₁ tt | inj₂ m' = inj₂ m' pred (n +∞ m) | inj₂ n' | inj₁ tt = inj₂ n' pred (n +∞ m) | inj₂ n' | inj₂ m' = inj₂ (record { pred = inj₂ (n' +∞ m') }) +∞-comm : (n m : ℕ∞) → (n +∞ m) ~ℕ∞~ (m +∞ n) pred~ (+∞-comm n m) with pred n | pred m pred~ (+∞-comm n m) | inj₁ tt | inj₁ tt = tt pred~ (+∞-comm n m) | inj₁ tt | inj₂ m' = refl-ℕ∞ pred~ (+∞-comm n m) | inj₂ n' | inj₁ tt = refl-ℕ∞ pred~ (+∞-comm n m) | inj₂ n' | inj₂ m' = record { pred~ = +∞-comm n' m' } 2×_ : ℕ∞ → ℕ∞ pred (2× n) with pred n pred (2× n) | inj₁ tt = inj₁ tt pred (2× n) | inj₂ n' = inj₂ (record { pred = inj₂ (2× n') }) StrData : Set → (ℕ∞ → Set) → ⊤ ⊎ ℕ∞ → Set StrData A F (inj₁ tt) = ⊤ StrData A F (inj₂ d') = A × F d' record Str (A : Set) (d : ℕ∞) : Set where coinductive field str-out : StrData A (Str A) (pred d) open Str public reidx-Str : ∀{n m A} → n ~ℕ∞~ m → Str A n → Str A m str-out (reidx-Str {n} {m} p s) with pred n | pred m | pred~ p | str-out s str-out (reidx-Str p s) | inj₁ tt | inj₁ tt | _ | _ = tt str-out (reidx-Str p s) | inj₁ tt | inj₂ m' | () | _ str-out (reidx-Str p s) | inj₂ n' | inj₁ tt | () | _ str-out (reidx-Str p s) | inj₂ n' | inj₂ m' | q | (a , s') = (a , reidx-Str q s') tl : ∀{d A} → Str A (succ d) → Str A d tl {d} s = proj₂ (str-out s) tl₂ : ∀{d A} → Str A (succ (succ d)) → Str A d tl₂ {d} s = proj₂ (str-out (proj₂ (str-out s))) even : ∀{d A} → Str A (2× d) → Str A d str-out (even {d} s) with pred d | str-out s str-out (even s) | inj₁ tt | tt = tt str-out (even s) | inj₂ d' | (a , s') with str-out s' str-out (even s) | inj₂ d' | (a , s') | (_ , s'') = (a , even s'') zip₂ : ∀{m n A} → Str A m → Str A n → Str A (m +∞ n) str-out (zip₂ {m} {n} s t) with pred m | pred n | str-out s | str-out t str-out (zip₂ s t) | inj₁ tt | inj₁ tt | tt | _ = tt str-out (zip₂ s t) | inj₁ tt | inj₂ n' | tt | u = u str-out (zip₂ s t) | inj₂ m' | inj₁ tt | (a , s') | tt = (a , s') str-out (zip₂ s t) | inj₂ m' | inj₂ n' | (a , s') | (b , t') = (a , record { str-out = (b , zip₂ s' t') }) 𝔹 : Set 𝔹 = ⊤ ⊎ ⊤ l r : 𝔹 l = inj₁ tt r = inj₂ tt L R : Str 𝔹 ∞ str-out L = (l , L) str-out R = (r , R) restr : ∀{A} → Str A ∞ → (d : ℕ∞) → Str A d str-out (restr s d) with pred d | str-out s str-out (restr s d) | inj₁ tt | _ = tt str-out (restr s d) | inj₂ d' | (a , s') = (a , restr s' d') foo : ∀{d} → Str 𝔹 d str-out (foo {d}) with pred d str-out foo | inj₁ tt = tt str-out foo | inj₂ d' = (l , even {!!})
{ "alphanum_fraction": 0.5234959593, "avg_line_length": 28.313559322, "ext": "agda", "hexsha": "4ab11587a268587da464b724ee5662fce3dc05ec", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "Streams/SizedStreams.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "Streams/SizedStreams.agda", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "Streams/SizedStreams.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1585, "size": 3341 }
module Structure.Operator.Vector.LinearMap.Category where import Data.Tuple as Tuple open import Functional open import Function.Proofs open import Function.Equals open import Function.Equals.Proofs open import Logic.Predicate open import Logic.Predicate.Equiv open import Logic.Propositional import Lvl open import Structure.Category open import Structure.Categorical.Properties open import Structure.Function open import Structure.Operator open import Structure.Function.Domain open import Structure.Function.Multi open import Structure.Operator.Properties open import Structure.Operator.Vector.LinearMap open import Structure.Operator.Vector.LinearMaps as LinearMaps using (_∘ˡⁱⁿᵉᵃʳᵐᵃᵖ_ ; idˡⁱⁿᵉᵃʳᵐᵃᵖ) open import Structure.Operator.Vector.Proofs open import Structure.Operator.Vector open import Structure.Relator.Equivalence open import Structure.Relator.Properties open import Structure.Setoid open import Syntax.Transitivity open import Type private variable ℓ ℓᵥ ℓᵥₗ ℓᵥᵣ ℓᵥ₁ ℓᵥ₂ ℓᵥ₃ ℓₛ ℓᵥₑ ℓᵥₑₗ ℓᵥₑᵣ ℓᵥₑ₁ ℓᵥₑ₂ ℓᵥₑ₃ ℓₛₑ : Lvl.Level private variable V Vₗ Vᵣ V₁ V₂ V₃ S : Type{ℓ} private variable _+ᵥ_ _+ᵥₗ_ _+ᵥᵣ_ _+ᵥ₁_ _+ᵥ₂_ _+ᵥ₃_ : V → V → V private variable _⋅ₛᵥ_ _⋅ₛᵥₗ_ _⋅ₛᵥᵣ_ _⋅ₛᵥ₁_ _⋅ₛᵥ₂_ _⋅ₛᵥ₃_ : S → V → V private variable _+ₛ_ _⋅ₛ_ : S → S → S private variable f g : Vₗ → Vᵣ open VectorSpace ⦃ … ⦄ open VectorSpaceVObject module _ ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄ {_+ₛ_ _⋅ₛ_ : S → S → S} where private variable A B : VectorSpaceVObject {ℓᵥ}{_}{ℓᵥₑ}{ℓₛₑ} ⦃ equiv-S ⦄ (_+ₛ_)(_⋅ₛ_) instance [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-reflexivity : Reflexivity(_↔ˡⁱⁿᵉᵃʳᵐᵃᵖ_ {ℓᵥₗ = ℓᵥₗ}{ℓᵥₑₗ = ℓᵥₑₗ}{_+ₛ_ = _+ₛ_}{_⋅ₛ_ = _⋅ₛ_}) ∃.witness (Reflexivity.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-reflexivity) = id Tuple.left (∃.proof (Reflexivity.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-reflexivity)) = {!!} Tuple.right (∃.proof (Reflexivity.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-reflexivity {V})) = LinearMaps.identity (VectorSpaceVObject.vectorSpace V) instance [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-symmetry : Symmetry(_↔ˡⁱⁿᵉᵃʳᵐᵃᵖ_ {ℓᵥₗ = ℓᵥₗ}{ℓᵥₑₗ = ℓᵥₑₗ}{_+ₛ_ = _+ₛ_}{_⋅ₛ_ = _⋅ₛ_}) ∃.witness (Symmetry.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-symmetry ([∃]-intro f ⦃ [∧]-intro p q ⦄)) = {!!} Tuple.left (∃.proof (Symmetry.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-symmetry x)) = {!!} Tuple.right (∃.proof (Symmetry.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-symmetry x)) = {!!} instance [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-transitivity : Transitivity(_↔ˡⁱⁿᵉᵃʳᵐᵃᵖ_ {ℓᵥₗ = ℓᵥₗ}{ℓᵥₑₗ = ℓᵥₑₗ}{_+ₛ_ = _+ₛ_}{_⋅ₛ_ = _⋅ₛ_}) ∃.witness (Transitivity.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-transitivity ([∃]-intro f) ([∃]-intro g)) = g ∘ f Tuple.left (∃.proof (Transitivity.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-transitivity p q)) = {!!} Tuple.right (∃.proof (Transitivity.proof [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-transitivity {V₁}{V₂}{V₃} ([∃]-intro _ ⦃ p ⦄) ([∃]-intro _ ⦃ q ⦄))) = LinearMaps.compose (VectorSpaceVObject.vectorSpace V₁)(VectorSpaceVObject.vectorSpace V₂)(VectorSpaceVObject.vectorSpace V₃) (Tuple.right q) (Tuple.right p) instance [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equivalence : Equivalence(_↔ˡⁱⁿᵉᵃʳᵐᵃᵖ_ {ℓᵥₗ = ℓᵥₗ}{ℓᵥₑₗ = ℓᵥₑₗ}{_+ₛ_ = _+ₛ_}{_⋅ₛ_ = _⋅ₛ_}) [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equivalence = intro instance VectorSpaceVObject-equiv : Equiv(VectorSpaceVObject{ℓᵥ = ℓᵥ}{ℓᵥₑ = ℓᵥₑ}(_+ₛ_)(_⋅ₛ_)) Equiv._≡_ VectorSpaceVObject-equiv = _↔ˡⁱⁿᵉᵃʳᵐᵃᵖ_ Equiv.equivalence VectorSpaceVObject-equiv = [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equivalence instance [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equiv : Equiv(A →ˡⁱⁿᵉᵃʳᵐᵃᵖ B) [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equiv {A = A} {B = B} = [≡∃]-equiv ⦃ [⊜]-equiv ⦃ Vector-equiv B ⦄ ⦄ -- Equiv._≡_ [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equiv ([∃]-intro f) ([∃]-intro g) = {!!} -- Equiv.equivalence [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equiv = {!!} linearMapCategory : Category(_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_ {ℓᵥₗ = ℓᵥₗ}{ℓᵥₑₗ = ℓᵥₑₗ}{_+ₛ_ = _+ₛ_}{_⋅ₛ_ = _⋅ₛ_}) ⦃ [_→ˡⁱⁿᵉᵃʳᵐᵃᵖ_]-equiv ⦄ Category._∘_ linearMapCategory = _∘ˡⁱⁿᵉᵃʳᵐᵃᵖ_ Category.id linearMapCategory = idˡⁱⁿᵉᵃʳᵐᵃᵖ BinaryOperator.congruence (Category.binaryOperator linearMapCategory) p q = [⊜][∘]-binaryOperator-raw p q Morphism.Associativity.proof (Category.associativity linearMapCategory) {X}{Y}{Z}{W} = intro(reflexivity(Equiv._≡_ (Vector-equiv(W)))) Morphism.Identityₗ.proof (Tuple.left (Category.identity linearMapCategory)) {X}{Y} = intro(reflexivity(Equiv._≡_ (Vector-equiv(Y)))) Morphism.Identityᵣ.proof (Tuple.right (Category.identity linearMapCategory)) {X}{Y} = intro(reflexivity(Equiv._≡_ (Vector-equiv(Y)))) -- _≡∃_ {Obj = {!!}} ⦃ {![⊜]-equiv ⦃ Vector-equiv Y ⦄!} ⦄ {Pred = {!f ↦ LinearMap(vectorSpace(X))(vectorSpace(Y)) (f)!}}
{ "alphanum_fraction": 0.7107664234, "avg_line_length": 51.5764705882, "ext": "agda", "hexsha": "9d12ccd6200aebc656395d0c905e6361ab77d495", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Structure/Operator/Vector/LinearMap/Category.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Structure/Operator/Vector/LinearMap/Category.agda", "max_line_length": 286, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Structure/Operator/Vector/LinearMap/Category.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 2495, "size": 4384 }
{-# OPTIONS --without-K #-} {- Now it only has specialized constructs and lemmas for π₀ (x ≡ y) Should be rewritten with something like Algebra.Groupoids -} open import Base module Homotopy.PathTruncation where open import HLevel open import HLevelBis open import Homotopy.Truncation _≡₀_ : ∀ {i} {A : Set i} → A → A → Set i _≡₀_ x y = π₀ (x ≡ y) infix 8 _∘₀_ -- \o\0 _∘₀_ : ∀ {i} {A : Set i} {x y z : A} → x ≡₀ y → y ≡₀ z → x ≡₀ z _∘₀_ = π₀-extend-nondep ⦃ →-is-set $ π₀-is-set _ ⦄ (λ p → π₀-extend-nondep ⦃ π₀-is-set _ ⦄ (λ q → proj $ p ∘ q)) !₀ : ∀ {i} {A : Set i} {x y : A} → x ≡₀ y → y ≡₀ x !₀ = π₀-extend-nondep ⦃ π₀-is-set _ ⦄ (proj ◯ !) refl₀ : ∀ {i} {A : Set i} {a : A} → a ≡₀ a refl₀ = proj refl ap₀ : ∀ {i j} {A : Set i} {B : Set j} {x y : A} (f : A → B) → x ≡₀ y → f x ≡₀ f y ap₀ f = π₀-extend-nondep ⦃ π₀-is-set _ ⦄ (proj ◯ ap f) module _ {i} {A : Set i} where refl₀-right-unit : ∀ {x y : A} (q : x ≡₀ y) → (q ∘₀ refl₀) ≡ q refl₀-right-unit {x = x} {y} = π₀-extend ⦃ λ _ → ≡-is-set $ π₀-is-set (x ≡ y) ⦄ (λ x → ap proj $ refl-right-unit x) refl₀-left-unit : ∀ {x y : A} (q : x ≡₀ y) → (refl₀ ∘₀ q) ≡ q refl₀-left-unit {x = x} {y} = π₀-extend ⦃ λ _ → ≡-is-set $ π₀-is-set (x ≡ y) ⦄ (λ _ → refl) concat₀-assoc : {x y z t : A} (p : x ≡₀ y) (q : y ≡₀ z) (r : z ≡₀ t) → (p ∘₀ q) ∘₀ r ≡ p ∘₀ (q ∘₀ r) concat₀-assoc = π₀-extend ⦃ λ _ → Π-is-set λ _ → Π-is-set λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ p → π₀-extend ⦃ λ _ → Π-is-set λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ q → π₀-extend ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ r → ap proj $ concat-assoc p q r))) concat₀-ap₀ : ∀ {j} {B : Set j} (f : A → B) {x y z : A} (p : x ≡₀ y) (q : y ≡₀ z) → ap₀ f p ∘₀ ap₀ f q ≡ ap₀ f (p ∘₀ q) concat₀-ap₀ f = π₀-extend ⦃ λ _ → Π-is-set λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ p → π₀-extend ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ q → ap proj $ concat-ap f p q)) ap₀-compose : ∀ {j k} {B : Set j} {C : Set k} (g : B → C) (f : A → B) {x y : A} (p : x ≡₀ y) → ap₀ (g ◯ f) p ≡ ap₀ g (ap₀ f p) ap₀-compose f g = π₀-extend ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ p → ap proj $ ap-compose f g p) module _ {i} {A : Set i} where trans-id≡₀cst : {a b c : A} (p : b ≡ c) (q : b ≡₀ a) → transport (λ x → x ≡₀ a) p q ≡ proj (! p) ∘₀ q trans-id≡₀cst refl q = ! $ refl₀-left-unit q trans-cst≡₀id : {a b c : A} (p : b ≡ c) (q : a ≡₀ b) → transport (λ x → a ≡₀ x) p q ≡ q ∘₀ proj p trans-cst≡₀id refl q = ! $ refl₀-right-unit q module _ {i} {A : Set i} where homotopy₀-naturality : ∀ {j} {B : Set j} (f g : A → B) (p : (x : A) → f x ≡₀ g x) {x y : A} (q : x ≡₀ y) → ap₀ f q ∘₀ p y ≡ p x ∘₀ ap₀ g q homotopy₀-naturality f g p {x} {y} q = π₀-extend ⦃ λ q → ≡-is-set {x = ap₀ f q ∘₀ p y} {y = p x ∘₀ ap₀ g q} $ π₀-is-set (f x ≡ g y) ⦄ (lemma {x} {y}) q where lemma : ∀ {x y : A} (q : x ≡ y) → ap₀ f (proj q) ∘₀ p y ≡ p x ∘₀ ap₀ g (proj q) lemma refl = refl₀ ∘₀ p _ ≡⟨ refl₀-left-unit (p _) ⟩ p _ ≡⟨ ! $ refl₀-right-unit _ ⟩∎ p _ ∘₀ refl₀ ∎ -- Loop space commutes with truncation in the sense that -- τ n (Ω X) = Ω (τ (S n) X) -- (actually, this is true more generally for paths spaces and we need this -- level of generality to prove it) module _ {i} {n : ℕ₋₂} {A : Set i} where private to : (x y : A) → (τ n (x ≡ y)) → ((proj {n = S n} x) ≡ (proj y)) to x y = τ-extend-nondep ⦃ τ-is-truncated (S n) A _ _ ⦄ (ap proj) -- [truncated-path-space (proj x) (proj y)] is [τ n (x ≡ y)] truncated-path-space : (u v : τ (S n) A) → Type≤ n i truncated-path-space = τ-extend-nondep ⦃ →-is-truncated (S n) (Type≤-is-truncated n _) ⦄ (λ x → τ-extend-nondep ⦃ Type≤-is-truncated n _ ⦄ (λ y → τ n (x ≡ y) , τ-is-truncated n _)) -- We now extend [to] to the truncation of [A], and this is why we needed to -- first extend the return type of [to] to' : (u v : τ (S n) A) → (π₁ (truncated-path-space u v) → u ≡ v) to' = τ-extend ⦃ λ x → Π-is-truncated (S n) (λ a → Π-is-truncated (S n) (λ b → ≡-is-truncated (S n) (τ-is-truncated (S n) A)))⦄ (λ x → τ-extend ⦃ λ t → Π-is-truncated (S n) (λ a → ≡-is-truncated (S n) (τ-is-truncated (S n) A))⦄ (λ y → to x y)) from'-refl : (u : τ (S n) A) → (π₁ (truncated-path-space u u)) from'-refl = τ-extend ⦃ λ x → truncated-is-truncated-S n (π₂ (truncated-path-space x x))⦄ (λ x → proj refl) from' : (u v : τ (S n) A) → (u ≡ v → π₁ (truncated-path-space u v)) from' u .u refl = from'-refl u from : (x y : A) → (proj {n = S n} x ≡ proj y → τ n (x ≡ y)) from x y p = from' (proj x) (proj y) p from-to : (x y : A) (p : τ n (x ≡ y)) → from x y (to x y p) ≡ p from-to x y = τ-extend ⦃ λ _ → ≡-is-truncated n (τ-is-truncated n _)⦄ (from-to' x y) where from-to' : (x y : A) (p : x ≡ y) → from x y (to x y (proj p)) ≡ proj p from-to' x .x refl = refl to'-from' : (u v : τ (S n) A) (p : u ≡ v) → to' u v (from' u v p) ≡ p to'-from' x .x refl = to'-from'-refl x where to'-from'-refl : (u : τ (S n) A) → to' u u (from' u u refl) ≡ refl to'-from'-refl = τ-extend ⦃ λ _ → ≡-is-truncated (S n) (≡-is-truncated (S n) (τ-is-truncated (S n) A))⦄ (λ _ → refl) to-from : (x y : A) (p : proj {n = S n} x ≡ proj y) → to x y (from x y p) ≡ p to-from x y p = to'-from' (proj x) (proj y) p τ-path-equiv-path-τ-S : {x y : A} → τ n (x ≡ y) ≃ (proj {n = S n} x ≡ proj y) τ-path-equiv-path-τ-S {x} {y} = (to x y , iso-is-eq _ (from x y) (to-from x y) (from-to x y)) module _ where open import Homotopy.Connected abstract connected-has-connected-paths : is-connected (S n) A → (p q : A) → is-connected n (p ≡ q) connected-has-connected-paths conn p q = equiv-types-truncated ⟨-2⟩ (τ-path-equiv-path-τ-S ⁻¹) (contr-is-prop conn (proj p) (proj q)) connected-has-all-τ-paths : is-connected (S n) A → (p q : A) → τ n (p ≡ q) connected-has-all-τ-paths conn p q = π₁ $ connected-has-connected-paths conn p q
{ "alphanum_fraction": 0.4709568939, "avg_line_length": 38.4823529412, "ext": "agda", "hexsha": "bd17cf8dec8506f5756c508c077d7e1f5ae8355c", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/Homotopy/PathTruncation.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/Homotopy/PathTruncation.agda", "max_line_length": 100, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "old/Homotopy/PathTruncation.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 2764, "size": 6542 }
{- A morphism of UARels is a function between the structures with an action on the relations that commutes with the equivalence to PathP. We can reindex a DUARel or SubstRel along one of these. -} {-# OPTIONS --safe #-} module Cubical.Displayed.Morphism where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Transport open import Cubical.Displayed.Base open import Cubical.Displayed.Subst private variable ℓ ℓA ℓA' ℓ≅A ℓB ℓB' ℓ≅B ℓC ℓ≅C : Level record UARelHom {A : Type ℓA} {B : Type ℓB} (𝒮-A : UARel A ℓ≅A) (𝒮-B : UARel B ℓ≅B) : Type (ℓ-max (ℓ-max ℓA ℓ≅A) (ℓ-max ℓB ℓ≅B)) where no-eta-equality constructor uarelhom field fun : A → B rel : ∀ {a a'} → UARel._≅_ 𝒮-A a a' → UARel._≅_ 𝒮-B (fun a) (fun a') ua : ∀ {a a'} (p : UARel._≅_ 𝒮-A a a') → cong fun (UARel.≅→≡ 𝒮-A p) ≡ UARel.≅→≡ 𝒮-B (rel p) open UARelHom 𝒮-id : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) → UARelHom 𝒮-A 𝒮-A 𝒮-id 𝒮-A .fun = idfun _ 𝒮-id 𝒮-A .rel = idfun _ 𝒮-id 𝒮-A .ua _ = refl 𝒮-∘ : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : Type ℓB} {𝒮-B : UARel B ℓ≅B} {C : Type ℓC} {𝒮-C : UARel C ℓ≅C} → UARelHom 𝒮-B 𝒮-C → UARelHom 𝒮-A 𝒮-B → UARelHom 𝒮-A 𝒮-C 𝒮-∘ g f .fun = g .fun ∘ f .fun 𝒮-∘ g f .rel = g .rel ∘ f .rel 𝒮-∘ {𝒮-A = 𝒮-A} {𝒮-B = 𝒮-B} {𝒮-C = 𝒮-C} g f .ua p = cong (cong (g .fun)) (f .ua p) ∙ g .ua (f .rel p) 𝒮ᴰ-reindex : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : Type ℓB} {𝒮-B : UARel B ℓ≅B} {C : B → Type ℓC} (f : UARelHom 𝒮-A 𝒮-B) → DUARel 𝒮-B C ℓ≅C → DUARel 𝒮-A (C ∘ fun f) ℓ≅C 𝒮ᴰ-reindex f 𝒮ᴰ-C .DUARel._≅ᴰ⟨_⟩_ c p c' = 𝒮ᴰ-C .DUARel._≅ᴰ⟨_⟩_ c (f .rel p) c' 𝒮ᴰ-reindex {C = C} f 𝒮ᴰ-C .DUARel.uaᴰ c p c' = compEquiv (𝒮ᴰ-C .DUARel.uaᴰ c (f .rel p) c') (substEquiv (λ q → PathP (λ i → C (q i)) c c') (sym (f .ua p))) 𝒮ˢ-reindex : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : Type ℓB} {𝒮-B : UARel B ℓ≅B} {C : B → Type ℓC} (f : UARelHom 𝒮-A 𝒮-B) → SubstRel 𝒮-B C → SubstRel 𝒮-A (C ∘ fun f) 𝒮ˢ-reindex f 𝒮ˢ-C .SubstRel.act p = 𝒮ˢ-C .SubstRel.act (f .rel p) 𝒮ˢ-reindex {C = C} f 𝒮ˢ-C .SubstRel.uaˢ p c = cong (λ q → subst C q c) (f .ua p) ∙ 𝒮ˢ-C .SubstRel.uaˢ (f .rel p) c
{ "alphanum_fraction": 0.5934309809, "avg_line_length": 33.1323529412, "ext": "agda", "hexsha": "94b463a36a56f6a3aa432078c6c86546a90f56f4", "lang": "Agda", "max_forks_count": 134, "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z", "max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "marcinjangrzybowski/cubical", "max_forks_repo_path": "Cubical/Displayed/Morphism.agda", "max_issues_count": 584, "max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "marcinjangrzybowski/cubical", "max_issues_repo_path": "Cubical/Displayed/Morphism.agda", "max_line_length": 98, "max_stars_count": 301, "max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "marcinjangrzybowski/cubical", "max_stars_repo_path": "Cubical/Displayed/Morphism.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z", "num_tokens": 1226, "size": 2253 }
{-# OPTIONS --copatterns #-} -- One-place functors (decorations) on Set module Control.Auto-Bug-in-Goal-2 where open import Function using (id) open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Control.Functor record IsDecoration (D : Set → Set) : Set₁ where field traverse : ∀ {F} {{ functor : IsFunctor F }} {A B} → (A → F B) → D A → F (D B) traverse-id : ∀ {A} → traverse {F = λ A → A} {A = A} id ≡ id isFunctor : IsFunctor D isFunctor = record { ops = record { map = traverse } ; laws = record { map-id = traverse-id ; map-∘ = {!!} } } open IsDecoration idIsDecoration : IsDecoration (λ A → A) traverse idIsDecoration f = f traverse-id idIsDecoration = {!!} compIsDecoration : ∀ {D E} → IsDecoration D → IsDecoration E → IsDecoration (λ A → D (E A)) traverse (compIsDecoration d e) f = traverse d (traverse e f) traverse-id (compIsDecoration d e) = {!!}
{ "alphanum_fraction": 0.6543478261, "avg_line_length": 27.8787878788, "ext": "agda", "hexsha": "bb8472baef35b512156b26575ea09ad48b64d563", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/cubical", "max_forks_repo_path": "src/Control/Auto-Bug-in-Goal-2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/cubical", "max_issues_repo_path": "src/Control/Auto-Bug-in-Goal-2.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/cubical", "max_stars_repo_path": "src/Control/Auto-Bug-in-Goal-2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 286, "size": 920 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import cohomology.Theory open import cw.CW module cw.cohomology.CohomologyGroupsTooHigh {i} (OT : OrdinaryTheory i) m {n} (n<m : n < m) (G : Group i) (⊙skel : ⊙Skeleton {i} n) (ac : ⊙has-cells-with-choice 0 ⊙skel i) where open OrdinaryTheory OT open import cw.cohomology.Descending OT open import groups.KernelImage {G = G} {H = Lift-group {j = i} Unit-group} {K = Lift-group {j = i} Unit-group} cst-hom cst-hom (snd (Lift-abgroup Unit-abgroup)) open import groups.KernelCstImageCst G (Lift-group {j = i} Unit-group) (Lift-group {j = i} Unit-group) (snd (Lift-abgroup Unit-abgroup)) C-cw-iso-ker/im : C (ℕ-to-ℤ m) ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker/Im C-cw-iso-ker/im = Ker-cst-quot-Im-cst ⁻¹ᴳ ∘eᴳ lift-iso ∘eᴳ trivial-iso-0ᴳ (C-cw-at-higher ⊙skel n<m ac)
{ "alphanum_fraction": 0.6686819831, "avg_line_length": 29.5357142857, "ext": "agda", "hexsha": "241056171c52ffae0ab9ddd4fa9ccff5b96b6e3f", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_path": "theorems/cw/cohomology/CohomologyGroupsTooHigh.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_path": "theorems/cw/cohomology/CohomologyGroupsTooHigh.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_path": "theorems/cw/cohomology/CohomologyGroupsTooHigh.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 333, "size": 827 }
{-# 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
{ "alphanum_fraction": 0.5210016801, "avg_line_length": 42.0841750842, "ext": "agda", "hexsha": "a009141f1fdee63453fe067d4d1394dd86a5b39f", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2018-06-25T15:05:21.000Z", "max_forks_repo_forks_event_min_datetime": "2018-02-22T19:58:46.000Z", "max_forks_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "glangmead/hott_cmu80818", "max_forks_repo_path": "Lecture5.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b", "max_issues_repo_issues_event_max_datetime": "2018-03-25T14:44:31.000Z", "max_issues_repo_issues_event_min_datetime": "2018-02-22T21:01:16.000Z", "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "glangmead/hott_cmu80818", "max_issues_repo_path": "Lecture5.agda", "max_line_length": 215, "max_stars_count": 4, "max_stars_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "glangmead/hott_cmu80818", "max_stars_repo_path": "Lecture5.agda", "max_stars_repo_stars_event_max_datetime": "2018-09-04T02:52:25.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-03T20:32:19.000Z", "num_tokens": 5761, "size": 12499 }
module Inductive.Examples.Sum where open import Inductive open import Tuple open import Data.Fin open import Data.Product open import Data.List open import Data.Vec _⊎_ : Set → Set → Set A ⊎ B = Inductive (((A ∷ []) , []) ∷ (((B ∷ []) , []) ∷ [])) inl : {A B : Set} → A → A ⊎ B inl a = construct zero (a ∷ []) [] inr : {A B : Set} → B → A ⊎ B inr b = construct (suc zero) (b ∷ []) [] case : {A B C : Set} → A ⊎ B → (A → C) → (B → C) → C case x f g = rec (f ∷ (g ∷ [])) x
{ "alphanum_fraction": 0.5303983229, "avg_line_length": 21.6818181818, "ext": "agda", "hexsha": "165d97e342bc4939b3f6abec53350627e9281252", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mr-ohman/general-induction", "max_forks_repo_path": "Inductive/Examples/Sum.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mr-ohman/general-induction", "max_issues_repo_path": "Inductive/Examples/Sum.agda", "max_line_length": 60, "max_stars_count": null, "max_stars_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mr-ohman/general-induction", "max_stars_repo_path": "Inductive/Examples/Sum.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 187, "size": 477 }
module Basic.BigStep where import Data.Bool as Bool using (not) open import Data.Bool hiding (not; if_then_else_) open import Data.Empty open import Data.Fin using (Fin; suc; zero; #_) open import Data.Nat open import Data.Nat.Properties.Simple open import Data.Vec open import Function open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Data.Product import Level as L open import Utils.Decidable open import Utils.NatOrdLemmas open import Basic.AST {- The big-step semantics of the while language. It's chapter 2.1 in the book. Note that we use a {n : ℕ} parameter to fix the size of the program state over our derivations. This is fine since we don't have any derivation rule that changes the size of the state. The definitions themselves should come as no surprise to readers of the book. I employ some syntactic shenanigans to make the definitions visually similar to the familiar sequent/natural calculus notation (I borrow the formatting style from Conor McBride). -} infixr 4 _,_ data ⟨_,_⟩⟱_ {n : ℕ} : St n → State n → State n → Set where {- "[ x ]≔ value" is just the standard library definition of vector update -} ass : ∀ {s x a} → ------------------------------------ ⟨ x := a , s ⟩⟱ (s [ x ]≔ ⟦ a ⟧ᵉ s) skip : ∀ {s} → ----------------- ⟨ skip , s ⟩⟱ s _,_ : ∀ {s₁ s₂ s₃ S₁ S₂} → ⟨ S₁ , s₁ ⟩⟱ s₂ → ⟨ S₂ , s₂ ⟩⟱ s₃ → ------------------------------------- ⟨ (S₁ , S₂ ) , s₁ ⟩⟱ s₃ {- The "T" in "T (⟦ b ⟧ᵉ s)" can be found in Data.Bool.Base. It's ⊤ on a true argument and ⊥ on a false argument, so it just lifts boolean values to proofs. "F" works the same way, except it's provable on a false argument -} if-true : ∀ {s s' S₁ S₂ b} → T (⟦ b ⟧ᵉ s) → ⟨ S₁ , s ⟩⟱ s' → ----------------------------------- ⟨ if b then S₁ else S₂ , s ⟩⟱ s' if-false : ∀ {s s' S₁ S₂ b} → F (⟦ b ⟧ᵉ s) → ⟨ S₂ , s ⟩⟱ s' → ----------------------------------- ⟨ if b then S₁ else S₂ , s ⟩⟱ s' while-true : ∀ {s s' s'' S b} → T (⟦ b ⟧ᵉ s) → ⟨ S , s ⟩⟱ s' → ⟨ while b do S , s' ⟩⟱ s'' → ---------------------------------------------------------------- ⟨ while b do S , s ⟩⟱ s'' while-false : ∀ {s S b} → F (⟦ b ⟧ᵉ s) → ------------------------ ⟨ while b do S , s ⟩⟱ s {- Example program and program derivation below. Note the magnificient de Bruijn variables. Program derivations are really slow to typecheck. Brave souls may want to uncomment it and give it a try. But other than that, we may should that the derivations look pretty clean and concise. There's lots of details that Agda's inference can fill in for us. -} private prog : St 3 prog = # 2 := lit 0 , while lte (var (# 1)) (var (# 0)) do ( # 2 := add (var (# 2)) (lit 1) , # 0 := sub (var (# 0)) (var (# 1)) ) -- -- uncomment if you dare -- prog-deriv : -- ∀ {z} → ⟨ prog , 17 ∷ 5 ∷ z ∷ [] ⟩⟱ (2 ∷ 5 ∷ 3 ∷ []) -- prog-deriv = -- ass , -- while-true tt (ass , ass) -- (while-true tt (ass , ass) -- (while-true tt (ass , ass) -- (while-false tt))) {- A program diverges on a state if there is no derivation starting from it Since this is big-step semantics, we can't distinguish this from being stuck -} _divergesOnₙ_ : ∀ {n} → St n → State n → Set prog divergesOnₙ s = ∀ {s'} → ¬ ⟨ prog , s ⟩⟱ s' {- A program is divergent if it diverges on all states -} Divergentₙ : ∀ {n} → St n → Set Divergentₙ prog = ∀ {s} → prog divergesOnₙ s {- The fun thing about the following proof of divergence is that we implicitly rely on the finiteness of Agda data. Since we have apparent infinite recursion in the proof, but all inductive Agda data are finite, this implies that no such derivation may exist in the first place. -} private inf-loopₙ : ∀ {n} → Divergentₙ {n} (while tt do skip) inf-loopₙ (while-true x skip p₁) = inf-loopₙ p₁ inf-loopₙ (while-false x) = x -- Semantic equivalence _⇔_ : ∀ {a b} → Set a → Set b → Set (a L.⊔ b) A ⇔ B = (A → B) × (B → A) SemanticEq : ∀ {n} → St n → St n → Set SemanticEq pa pb = ∀ {s s'} → ⟨ pa , s ⟩⟱ s' ⇔ ⟨ pb , s ⟩⟱ s' Semantic⇒ : ∀ {n} → St n → St n → Set Semantic⇒ pa pb = ∀ {s s'} → ⟨ pa , s ⟩⟱ s' → ⟨ pb , s ⟩⟱ s' private -- "while b do S" is equivalent to "if b then (S , while b do S) else skip" prog1 : ∀ {n} _ _ → St n prog1 b S = while b do S prog2 : ∀ {n} _ _ → St n prog2 b S = if b then (S , while b do S) else skip progeq : ∀ {n b S} → SemanticEq {n} (prog1 b S) (prog2 b S) progeq {n}{b}{S} = to , from where to : Semantic⇒ (prog1 b S) (prog2 b S) to (while-true x p1 p2) = if-true x (p1 , p2) to (while-false x) = if-false x skip from : Semantic⇒ (prog2 b S) (prog1 b S) from (if-true x (p1 , p2)) = while-true x p1 p2 from (if-false x skip) = while-false x -- The semantics is deterministic. Not much to comment on. deterministic : ∀ {n}{p : St n}{s s' s''} → ⟨ p , s ⟩⟱ s' → ⟨ p , s ⟩⟱ s'' → s' ≡ s'' deterministic = go where go : ∀ {p s s' s''} → ⟨ p , s ⟩⟱ s' → ⟨ p , s ⟩⟱ s'' → s' ≡ s'' go ass ass = refl go skip skip = refl go (p1 , p2) (p3 , p4) rewrite go p1 p3 | go p2 p4 = refl go (if-true x p1) (if-true x₁ p2) rewrite go p1 p2 = refl go (if-true x p1) (if-false x₁ p2) rewrite T→≡true x = ⊥-elim x₁ go (if-false x p1) (if-true x₁ p2) rewrite T→≡true x₁ = ⊥-elim x go (if-false x p1) (if-false x₁ p2) rewrite go p1 p2 = refl go (while-true x p1 p2) (while-true x₁ p3 p4) rewrite go p1 p3 | go p2 p4 = refl go (while-true x p1 p2) (while-false x₁) rewrite T→≡true x = ⊥-elim x₁ go (while-false x) (while-true x₁ p2 p3) rewrite T→≡true x₁ = ⊥-elim x go (while-false x) (while-false x₁) = refl {- Below is a proof that is not contained in the book. I did it to familiarize myself with the style of proving in this semantics. It proves that if we have a derivation for a loop, then we can construct a derivation for a loop that goes on for one more iteration, because it has a higher bound in the condition. However, if we start out with a loop index that is already greater then the loop bound, we get divergence. But just having a derivation as hypothesis rules out divergence! We can show this to Agda by proving the divergence in that case and getting a contradiction. -} private loop : St 2 loop = while not (eq (var (# 0)) (var (# 1))) do (# 0 := add (lit 1) (var (# 0))) once-more : ∀ { i₀ lim₀ i₁} → ⟨ loop , i₀ ∷ lim₀ ∷ [] ⟩⟱ (i₁ ∷ lim₀ ∷ []) → ⟨ loop , i₀ ∷ suc lim₀ ∷ [] ⟩⟱ (1 + i₁ ∷ suc lim₀ ∷ []) once-more {i₀}{lim₀} p with cmp i₀ lim₀ once-more (while-true x₁ ass p₁) | LT x = while-true (¬A→FalseA $ a<b⟶a≢sb _ _ x) ass (once-more p₁) once-more (while-false x₁) | LT x rewrite TrueA→A $ F-not-elim x₁ = ⊥-elim (a≮a _ x) once-more (while-true x p p₁) | EQ refl = ⊥-elim (FalseA→¬A x refl) once-more (while-false x) | EQ refl = while-true (¬A→FalseA $ a≢sa _) ass (while-false (F-not-add $ A→TrueA refl)) once-more p | GT x = ⊥-elim (diverges x p) where diverges : ∀ {i₀ lim₀} → lim₀ < i₀ → loop divergesOnₙ (i₀ ∷ lim₀ ∷ []) diverges p1 (while-true x ass p3) = diverges (<-weakenr1 _ _ p1) p3 diverges p1 (while-false x) rewrite TrueA→A $ F-not-elim x = a≮a _ p1 {- Correctness of a factorial program. This task made me ponder the nature of meta- and object languages a bit. Our job here is to prove that the factorial program computes a factorial. But in order to be able to state this property, we had to define the notion of factorial in Agda. But this Agda ⟦fac⟧ function is already executable! Luckily for us, Agda and Coq and co. already have computational meaning. So if our goal is to simply have a correct factorial program, then we should just write it in Agda or Coq (although neither supports software development in an acceptable manner, unfortunately). Some languages are just better as metalanguages, but if those metalanguages are also satisfactory as object languages then we might make do with just a single language, instead of multiple languages and multiple semantics. Turning back to the actual proof, note that unlike the manual factorial proof in Chapter 6.1 of the book, this one looks pretty neat and it's also concise. It's also structurally similar to the program itself. -} module Fac where ⟦fac⟧ : ℕ → ℕ ⟦fac⟧ zero = 1 ⟦fac⟧ (suc n) = suc n * ⟦fac⟧ n fac-loop : St 3 fac-loop = while lt (var (# 1)) (var (# 0)) do (# 1 := add (lit 1) (var (# 1)) , # 2 := mul (var (# 1)) (var (# 2)) ) fac : St 3 fac = # 1 := lit 0 , # 2 := lit 1 , fac-loop fac-loop-ok : ∀ d i → ⟨ fac-loop , d + i ∷ i ∷ ⟦fac⟧ i ∷ [] ⟩⟱ (d + i ∷ d + i ∷ ⟦fac⟧ (d + i) ∷ []) fac-loop-ok zero i = while-false (¬A→FalseA $ a≮a i ) fac-loop-ok (suc d) i with fac-loop-ok d (suc i) ... | next rewrite +-suc d i = while-true (A→TrueA $ a<sb+a i d) (ass , ass) next fac-ok : ∀ n {i acc} → ⟨ fac , n ∷ i ∷ acc ∷ [] ⟩⟱ (n ∷ n ∷ ⟦fac⟧ n ∷ []) fac-ok n with fac-loop-ok n 0 ... | loop-ok rewrite +-comm n 0 = ass , ass , loop-ok
{ "alphanum_fraction": 0.5792158113, "avg_line_length": 33.3723404255, "ext": "agda", "hexsha": "8ea7a6a70e52fb895104e438c6240ed10d8b4540", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_forks_repo_path": "Basic/BigStep.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_issues_repo_path": "Basic/BigStep.agda", "max_line_length": 92, "max_stars_count": 8, "max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_stars_repo_path": "Basic/BigStep.agda", "max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z", "max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z", "num_tokens": 3275, "size": 9411 }
postulate A : Set open import Agda.Builtin.Equality -- here the solution g := (\ (@0 x) (@0 y) → f y x) is not well-typed -- in a non-erased context, which is how `g` is declared. bar : (f : A → A → A) (g : @0 A → @0 A → A) → @0 _≡_ {A = @0 A → @0 A → A} g (\ (@0 x) (@0 y) → f y x) → @0 A → @0 A → A bar f g refl = g
{ "alphanum_fraction": 0.4954682779, "avg_line_length": 25.4615384615, "ext": "agda", "hexsha": "634b77a086e51a240abc5d651c8d6e1c01b9bafd", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue4986b.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue4986b.agda", "max_line_length": 69, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue4986b.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 140, "size": 331 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category open import Categories.Category.Monoidal module Categories.Category.Monoidal.Traced {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where open Category C open import Level open import Data.Product using (_,_) open import Categories.Category.Monoidal.Symmetric M private variable A B X Y : Obj f g : A ⇒ B ------------------------------------------------------------------------------ -- Def from http://ncatlab.org/nlab/show/traced+monoidal+category -- -- A symmetric monoidal category (C,⊗,1,b) (where b is the symmetry) is -- said to be traced if it is equipped with a natural family of functions -- -- TrXA,B:C(A⊗X,B⊗X)→C(A,B) -- satisfying three axioms: -- -- Vanishing: Tr1A,B(f)=f (for all f:A→B) and -- TrX⊗YA,B=TrXA,B(TrYA⊗X,B⊗X(f)) (for all f:A⊗X⊗Y→B⊗X⊗Y) -- -- Superposing: TrXC⊗A,C⊗B(idC⊗f)=idC⊗TrXA,B(f) (for all f:A⊗X→B⊗X) -- -- Yanking: TrXX,X(bX,X)=idX -- Traced monoidal category -- is a symmetric monoidal category with a trace operation -- -- note that the definition in this library is significantly easier than the previous one because -- we adopt a simpler definition of monoidal category to begin with. record Traced : Set (levelOfTerm M) where field symmetric : Symmetric open Symmetric symmetric public field trace : ∀ {X A B} → A ⊗₀ X ⇒ B ⊗₀ X → A ⇒ B vanishing₁ : trace {X = unit} (f ⊗₁ id) ≈ f vanishing₂ : trace {X = X} (trace {X = Y} (associator.to ∘ f ∘ associator.from)) ≈ trace {X = X ⊗₀ Y} f superposing : trace {X = X} (associator.to ∘ id {Y} ⊗₁ f ∘ associator.from) ≈ id {Y} ⊗₁ trace {X = X} f yanking : trace (braiding.⇒.η (X , X)) ≈ id
{ "alphanum_fraction": 0.6224549156, "avg_line_length": 30.6964285714, "ext": "agda", "hexsha": "4d953052f9e68997876641a0b65923b0f10e2f91", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Category/Monoidal/Traced.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Category/Monoidal/Traced.agda", "max_line_length": 107, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Category/Monoidal/Traced.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 583, "size": 1719 }
open import Structure.Category open import Type module Structure.Category.Monad.Category {ℓₒ ℓₘ ℓₑ} {cat : CategoryObject{ℓₒ}{ℓₘ}{ℓₑ}} where import Data.Tuple as Tuple import Function.Equals open Function.Equals.Dependent import Lvl open import Structure.Category.Functor open import Structure.Category.Monad{cat = cat} open import Structure.Category.Monad.ExtensionSystem{cat = cat} open import Structure.Categorical.Properties open import Structure.Function open import Structure.Operator open import Structure.Relator.Equivalence open import Structure.Setoid open import Syntax.Transitivity open CategoryObject(cat) open Category.ArrowNotation(category) open Category(category) private open module MorphismEquiv {x}{y} = Equivalence (Equiv-equivalence ⦃ morphism-equiv{x}{y} ⦄) using () module _ (T : Object → Object) ⦃ extSys : ExtensionSystem(T) ⦄ where open ExtensionSystem(extSys) open Functor(functor) open Monad ⦃ functor ⦄ (monad) using (μ-functor-[∘]-identityₗ) -- Also called: Kleisli category categoryₑₓₜ : Category(\x y → (x ⟶ T(y))) Category._∘_ categoryₑₓₜ = _∘ₑₓₜ_ Category.id categoryₑₓₜ = idₑₓₜ BinaryOperator.congruence (Category.binaryOperator categoryₑₓₜ {x}{y}{z}) {f₁}{f₂} {g₁}{g₂} f₁f₂ g₁g₂ = f₁ ∘ₑₓₜ g₁ 🝖[ _≡_ ]-[] ext f₁ ∘ g₁ 🝖[ _≡_ ]-[ congruence₂(_∘_) (congruence₁(ext) f₁f₂) g₁g₂ ] ext f₂ ∘ g₂ 🝖[ _≡_ ]-[] f₂ ∘ₑₓₜ g₂ 🝖-end Morphism.Associativity.proof (Category.associativity categoryₑₓₜ) {x} {y} {z} {w} {f} {g} {h} = (f ∘ₑₓₜ g) ∘ₑₓₜ h 🝖[ _≡_ ]-[] ext(ext(f) ∘ g) ∘ h 🝖[ _≡_ ]-[ congruence₂ₗ(_∘_)(_) ext-distribute ] (ext(f) ∘ ext(g)) ∘ h 🝖[ _≡_ ]-[ Morphism.associativity(_∘_) ] ext(f) ∘ (ext(g) ∘ h) 🝖[ _≡_ ]-[] f ∘ₑₓₜ (g ∘ₑₓₜ h) 🝖-end Morphism.Identityₗ.proof (Tuple.left (Category.identity categoryₑₓₜ)) {x} {y} {f} = idₑₓₜ ∘ₑₓₜ f 🝖[ _≡_ ]-[] ext(η(y)) ∘ f 🝖[ _≡_ ]-[ congruence₂ₗ(_∘_)(f) ext-inverse ] id ∘ f 🝖[ _≡_ ]-[ Morphism.identityₗ(_∘_)(id) ] f 🝖-end Morphism.Identityᵣ.proof (Tuple.right (Category.identity categoryₑₓₜ)) {x} {y} {f} = f ∘ₑₓₜ idₑₓₜ 🝖[ _≡_ ]-[] ext(f) ∘ η(x) 🝖[ _≡_ ]-[ ext-identity ] f 🝖-end module _ (T : Object → Object) ⦃ functor : Functor(category)(category)(T) ⦄ ⦃ monad : Monad(T) ⦄ where open Functor(functor) open Monad(monad) hiding (ext) open ExtensionSystem(monad-to-extensionSystem) hiding (η ; μ) -- Note: This is the supposed to be the same as categoryₑₓₜ but proven from a monad directly. monad-category : Category(\x y → (x ⟶ T(y))) Category._∘_ monad-category f g = ext(f) ∘ g Category.id monad-category {x} = η(x) BinaryOperator.congruence (Category.binaryOperator monad-category {x}{y}{z}) {f₁}{f₂} {g₁}{g₂} f₁f₂ g₁g₂ = ext(f₁) ∘ g₁ 🝖[ _≡_ ]-[] (μ(z) ∘ map f₁) ∘ g₁ 🝖-[ Morphism.associativity(_∘_) ] μ(z) ∘ (map f₁ ∘ g₁) 🝖-[ congruence₂ᵣ(_∘_)(μ(z)) (congruence₂(_∘_) (congruence₁(map) f₁f₂) g₁g₂) ] μ(z) ∘ (map f₂ ∘ g₂) 🝖-[ Morphism.associativity(_∘_) ]-sym (μ(z) ∘ map f₂) ∘ g₂ 🝖[ _≡_ ]-[] ext(f₂) ∘ g₂ 🝖-end Morphism.Associativity.proof (Category.associativity monad-category) {x} {y} {z} {w} {f} {g} {h} = ext(ext(f) ∘ g) ∘ h 🝖-[ congruence₂ₗ(_∘_)(_) (ext-distribute) ] (ext(f) ∘ ext(g)) ∘ h 🝖-[ Morphism.associativity(_∘_) ] ext(f) ∘ (ext(g) ∘ h) 🝖-end Morphism.Identityₗ.proof (Tuple.left (Category.identity monad-category)) {x} {y} {f} = ext(η(y)) ∘ f 🝖[ _≡_ ]-[] (μ(y) ∘ map(η(y))) ∘ f 🝖-[ congruence₂ₗ(_∘_)(f) (_⊜_.proof μ-functor-[∘]-identityₗ) ] id ∘ f 🝖-[ Morphism.identityₗ(_∘_)(id) ] f 🝖-end Morphism.Identityᵣ.proof (Tuple.right (Category.identity monad-category)) {x} {y} {f} = ext-identity
{ "alphanum_fraction": 0.608751942, "avg_line_length": 45.9761904762, "ext": "agda", "hexsha": "41f95bfc3af1b5cbac34979aa5f1089da0c47191", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Structure/Category/Monad/Category.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Structure/Category/Monad/Category.agda", "max_line_length": 108, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Structure/Category/Monad/Category.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 1598, "size": 3862 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Lexicographic ordering of lists ------------------------------------------------------------------------ -- The definitions of lexicographic orderings used here is suitable if -- the argument order is a (non-strict) partial order. {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Lex.NonStrict where open import Data.Empty using (⊥) open import Function open import Data.Unit.Base using (⊤; tt) open import Data.Product open import Data.List.Base open import Data.List.Relation.Binary.Pointwise using (Pointwise; []) import Data.List.Relation.Binary.Lex.Strict as Strict open import Level open import Relation.Nullary open import Relation.Binary import Relation.Binary.Construct.NonStrictToStrict as Conv ------------------------------------------------------------------------ -- Publically re-export definitions from Core open import Data.List.Relation.Binary.Lex.Core as Core public using (base; halt; this; next; ¬≤-this; ¬≤-next) ------------------------------------------------------------------------ -- Strict lexicographic ordering. module _ {a ℓ₁ ℓ₂} {A : Set a} where Lex-< : (_≈_ : Rel A ℓ₁) (_≼_ : Rel A ℓ₂) → Rel (List A) (a ⊔ ℓ₁ ⊔ ℓ₂) Lex-< _≈_ _≼_ = Core.Lex ⊥ _≈_ (Conv._<_ _≈_ _≼_) -- Properties module _ {_≈_ : Rel A ℓ₁} {_≼_ : Rel A ℓ₂} where private _≋_ = Pointwise _≈_ _<_ = Lex-< _≈_ _≼_ <-irreflexive : Irreflexive _≋_ _<_ <-irreflexive = Strict.<-irreflexive (Conv.<-irrefl _≈_ _≼_) <-asymmetric : IsEquivalence _≈_ → _≼_ Respects₂ _≈_ → Antisymmetric _≈_ _≼_ → Asymmetric _<_ <-asymmetric eq resp antisym = Strict.<-asymmetric sym (Conv.<-resp-≈ _ _ eq resp) (Conv.<-asym _≈_ _ antisym) where open IsEquivalence eq <-antisymmetric : Symmetric _≈_ → Antisymmetric _≈_ _≼_ → Antisymmetric _≋_ _<_ <-antisymmetric sym antisym = Core.antisymmetric sym (Conv.<-irrefl _≈_ _≼_) (Conv.<-asym _ _≼_ antisym) <-transitive : IsPartialOrder _≈_ _≼_ → Transitive _<_ <-transitive po = Core.transitive isEquivalence (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈) (Conv.<-trans _ _≼_ po) where open IsPartialOrder po <-resp₂ : IsEquivalence _≈_ → _≼_ Respects₂ _≈_ → _<_ Respects₂ _≋_ <-resp₂ eq resp = Core.respects₂ eq (Conv.<-resp-≈ _ _ eq resp) <-compare : Symmetric _≈_ → Decidable _≈_ → Antisymmetric _≈_ _≼_ → Total _≼_ → Trichotomous _≋_ _<_ <-compare sym _≟_ antisym tot = Strict.<-compare sym (Conv.<-trichotomous _ _ sym _≟_ antisym tot) <-decidable : Decidable _≈_ → Decidable _≼_ → Decidable _<_ <-decidable _≟_ _≼?_ = Core.decidable (no id) _≟_ (Conv.<-decidable _ _ _≟_ _≼?_) <-isStrictPartialOrder : IsPartialOrder _≈_ _≼_ → IsStrictPartialOrder _≋_ _<_ <-isStrictPartialOrder po = Strict.<-isStrictPartialOrder (Conv.<-isStrictPartialOrder _ _ po) <-isStrictTotalOrder : Decidable _≈_ → IsTotalOrder _≈_ _≼_ → IsStrictTotalOrder _≋_ _<_ <-isStrictTotalOrder dec tot = Strict.<-isStrictTotalOrder (Conv.<-isStrictTotalOrder₁ _ _ dec tot) <-strictPartialOrder : ∀ {a ℓ₁ ℓ₂} → Poset a ℓ₁ ℓ₂ → StrictPartialOrder _ _ _ <-strictPartialOrder po = record { isStrictPartialOrder = <-isStrictPartialOrder isPartialOrder } where open Poset po <-strictTotalOrder : ∀ {a ℓ₁ ℓ₂} → DecTotalOrder a ℓ₁ ℓ₂ → StrictTotalOrder _ _ _ <-strictTotalOrder dtot = record { isStrictTotalOrder = <-isStrictTotalOrder _≟_ isTotalOrder } where open DecTotalOrder dtot ------------------------------------------------------------------------ -- Non-strict lexicographic ordering. module _ {a ℓ₁ ℓ₂} {A : Set a} where Lex-≤ : (_≈_ : Rel A ℓ₁) (_≼_ : Rel A ℓ₂) → Rel (List A) (a ⊔ ℓ₁ ⊔ ℓ₂) Lex-≤ _≈_ _≼_ = Core.Lex ⊤ _≈_ (Conv._<_ _≈_ _≼_) ≤-reflexive : ∀ _≈_ _≼_ → Pointwise _≈_ ⇒ Lex-≤ _≈_ _≼_ ≤-reflexive _≈_ _≼_ = Strict.≤-reflexive _≈_ (Conv._<_ _≈_ _≼_) -- Properties module _ {_≈_ : Rel A ℓ₁} {_≼_ : Rel A ℓ₂} where private _≋_ = Pointwise _≈_ _≤_ = Lex-≤ _≈_ _≼_ ≤-antisymmetric : Symmetric _≈_ → Antisymmetric _≈_ _≼_ → Antisymmetric _≋_ _≤_ ≤-antisymmetric sym antisym = Core.antisymmetric sym (Conv.<-irrefl _≈_ _≼_) (Conv.<-asym _ _≼_ antisym) ≤-transitive : IsPartialOrder _≈_ _≼_ → Transitive _≤_ ≤-transitive po = Core.transitive isEquivalence (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈) (Conv.<-trans _ _≼_ po) where open IsPartialOrder po ≤-resp₂ : IsEquivalence _≈_ → _≼_ Respects₂ _≈_ → _≤_ Respects₂ _≋_ ≤-resp₂ eq resp = Core.respects₂ eq (Conv.<-resp-≈ _ _ eq resp) ≤-decidable : Decidable _≈_ → Decidable _≼_ → Decidable _≤_ ≤-decidable _≟_ _≼?_ = Core.decidable (yes tt) _≟_ (Conv.<-decidable _ _ _≟_ _≼?_) ≤-total : Symmetric _≈_ → Decidable _≈_ → Antisymmetric _≈_ _≼_ → Total _≼_ → Total _≤_ ≤-total sym dec-≈ antisym tot = Strict.≤-total sym (Conv.<-trichotomous _ _ sym dec-≈ antisym tot) ≤-isPreorder : IsPartialOrder _≈_ _≼_ → IsPreorder _≋_ _≤_ ≤-isPreorder po = Strict.≤-isPreorder isEquivalence (Conv.<-trans _ _ po) (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈) where open IsPartialOrder po ≤-isPartialOrder : IsPartialOrder _≈_ _≼_ → IsPartialOrder _≋_ _≤_ ≤-isPartialOrder po = Strict.≤-isPartialOrder (Conv.<-isStrictPartialOrder _ _ po) ≤-isTotalOrder : Decidable _≈_ → IsTotalOrder _≈_ _≼_ → IsTotalOrder _≋_ _≤_ ≤-isTotalOrder dec tot = Strict.≤-isTotalOrder (Conv.<-isStrictTotalOrder₁ _ _ dec tot) ≤-isDecTotalOrder : IsDecTotalOrder _≈_ _≼_ → IsDecTotalOrder _≋_ _≤_ ≤-isDecTotalOrder dtot = Strict.≤-isDecTotalOrder (Conv.<-isStrictTotalOrder₂ _ _ dtot) ≤-preorder : ∀ {a ℓ₁ ℓ₂} → Poset a ℓ₁ ℓ₂ → Preorder _ _ _ ≤-preorder po = record { isPreorder = ≤-isPreorder isPartialOrder } where open Poset po ≤-partialOrder : ∀ {a ℓ₁ ℓ₂} → Poset a ℓ₁ ℓ₂ → Poset _ _ _ ≤-partialOrder po = record { isPartialOrder = ≤-isPartialOrder isPartialOrder } where open Poset po ≤-decTotalOrder : ∀ {a ℓ₁ ℓ₂} → DecTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder _ _ _ ≤-decTotalOrder dtot = record { isDecTotalOrder = ≤-isDecTotalOrder isDecTotalOrder } where open DecTotalOrder dtot
{ "alphanum_fraction": 0.5906650761, "avg_line_length": 35.109947644, "ext": "agda", "hexsha": "8f75bbd7977666ad1a5f224ffd59f607ef3d2e94", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Lex/NonStrict.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Lex/NonStrict.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Lex/NonStrict.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 2312, "size": 6706 }
{-# OPTIONS --exact-split #-} module ExactSplitMin where data ℕ : Set where zero : ℕ suc : ℕ → ℕ min : ℕ → ℕ → ℕ min zero y = zero min x zero = zero min (suc x) (suc y) = suc (min x y)
{ "alphanum_fraction": 0.5355450237, "avg_line_length": 16.2307692308, "ext": "agda", "hexsha": "ee546fcc53dc90fbd147b5c057f5701751b6afce", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Fail/ExactSplitMin.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Fail/ExactSplitMin.agda", "max_line_length": 35, "max_stars_count": 3, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Fail/ExactSplitMin.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 73, "size": 211 }
------------------------------------------------------------------------------ -- Division program ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- This module define a division program using repeated subtraction -- (Dybjer 1985). -- Peter Dybjer. Program verification in a logical theory of -- constructions. In Jean-Pierre Jouannaud, editor. Functional -- Programming Languages and Computer Architecture, volume 201 of -- LNCS, 1985, pages 334-349. Appears in revised form as Programming -- Methodology Group Report 26, June 1986. module LTC-PCF.Program.Division.Division where open import LTC-PCF.Base open import LTC-PCF.Data.Nat open import LTC-PCF.Data.Nat.Inequalities ------------------------------------------------------------------------------ divh : D → D divh g = lam (λ i → lam (λ j → if (lt i j) then zero else (succ₁ (g · (i ∸ j) · j)))) div : D → D → D div i j = fix divh · i · j
{ "alphanum_fraction": 0.5191451469, "avg_line_length": 34.0303030303, "ext": "agda", "hexsha": "bfc9eab7ead6a047f2b52af78052003bfc2b1287", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/LTC-PCF/Program/Division/Division.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/LTC-PCF/Program/Division/Division.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/LTC-PCF/Program/Division/Division.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 247, "size": 1123 }
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.Vec.Relation.Binary.Equality.DecPropositional directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary open import Relation.Binary.PropositionalEquality module Data.Vec.Relation.Equality.DecPropositional {a} {A : Set a} (_≟_ : Decidable {A = A} _≡_) where open import Data.Vec.Relation.Binary.Equality.DecPropositional _≟_ public
{ "alphanum_fraction": 0.5664939551, "avg_line_length": 34.0588235294, "ext": "agda", "hexsha": "45486f3964565fa80d84d7dfb49447b028100c3f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Equality/DecPropositional.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Equality/DecPropositional.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Equality/DecPropositional.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 120, "size": 579 }
-- Andreas, 2016-05-19, issue 1986, after report from Nisse -- Andreas, 2016-06-02 fixed -- This has been reported before as issue 842 -- {-# OPTIONS -v tc.cover:20 #-} -- {-# OPTIONS -v tc.cc:20 -v reduce.compiled:100 #-} open import Common.Equality data Bool : Set where true false : Bool not : Bool → Bool not true = false not = λ _ → true not-true : not true ≡ false not-true = refl not-false : not false ≡ true not-false = refl
{ "alphanum_fraction": 0.6614349776, "avg_line_length": 20.2727272727, "ext": "agda", "hexsha": "81a8aac1692f1bdbced029c1ba5beaa0c9f49d67", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue1986.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue1986.agda", "max_line_length": 59, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1986.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 143, "size": 446 }
module Cats.Category.Constructions.Unique where open import Data.Unit using (⊤) open import Level open import Cats.Category.Base open import Cats.Util.Conv module Build {lo la l≈} (Cat : Category lo la l≈) where open Category Cat IsUniqueSuchThat : ∀ {lp A B} → (A ⇒ B → Set lp) → A ⇒ B → Set (la ⊔ l≈ ⊔ lp) IsUniqueSuchThat P f = ∀ {g} → P g → f ≈ g IsUnique : ∀ {A B} → A ⇒ B → Set (la ⊔ l≈) IsUnique {A} {B} = IsUniqueSuchThat {A = A} {B} (λ _ → ⊤) IsUniqueSuchThat→≈ : ∀ {lp A B} {P : A ⇒ B → Set lp} {f} → IsUniqueSuchThat P f → ∀ {g h} → P g → P h → g ≈ h IsUniqueSuchThat→≈ unique Pg Ph = ≈.trans (≈.sym (unique Pg)) (unique Ph) record ∃!′ {lp A B} (P : A ⇒ B → Set lp) : Set (la ⊔ l≈ ⊔ lp) where constructor ∃!-intro field arr : A ⇒ B prop : P arr unique : IsUniqueSuchThat P arr instance HasArrow-∃! : ∀ {lp A B} {P : A ⇒ B → Set lp} → HasArrow (∃!′ P) lo la l≈ HasArrow-∃! = record { Cat = Cat ; _⃗ = ∃!′.arr } syntax ∃!′ (λ f → P) = ∃![ f ] P ∃!″ : ∀ {lp A B} (P : A ⇒ B → Set lp) → Set (la ⊔ l≈ ⊔ lp) ∃!″ = ∃!′ syntax ∃!″ {A = A} {B} (λ f → P) = ∃![ f ∈ A ⇒ B ] P ∃! : (A B : Obj) → Set (la ⊔ l≈) ∃! A B = ∃![ f ∈ A ⇒ B ] ⊤ ∃!→≈ : ∀ {lp A B} {P : A ⇒ B → Set lp} → ∃!′ P → ∀ {g h} → P g → P h → g ≈ h ∃!→≈ (∃!-intro _ _ unique) = IsUniqueSuchThat→≈ unique
{ "alphanum_fraction": 0.4765291607, "avg_line_length": 21.303030303, "ext": "agda", "hexsha": "9f2d645257c7a64a4bdff21cce87df4da9557cf0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "alessio-b-zak/cats", "max_forks_repo_path": "Cats/Category/Constructions/Unique.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "alessio-b-zak/cats", "max_issues_repo_path": "Cats/Category/Constructions/Unique.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "alessio-b-zak/cats", "max_stars_repo_path": "Cats/Category/Constructions/Unique.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 620, "size": 1406 }
module Oscar.Category.Functor where open import Oscar.Category.Setoid open import Oscar.Category.Category open import Oscar.Category.Semifunctor open import Oscar.Level record Categories 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ : Set (lsuc (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂)) where constructor _,_ field category₁ : Category 𝔬₁ 𝔪₁ 𝔮₁ category₂ : Category 𝔬₂ 𝔪₂ 𝔮₂ module 𝔊₁ = Category category₁ module 𝔊₂ = Category category₂ semigroupoids : Semigroupoids _ _ _ _ _ _ Semigroupoids.semigroupoid₁ semigroupoids = 𝔊₁.semigroupoid Semigroupoids.semigroupoid₂ semigroupoids = 𝔊₂.semigroupoid module _ {𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂} (categories : Categories 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂) where open Categories categories record IsFunctor {μ : 𝔊₁.⋆ → 𝔊₂.⋆} (𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y) : Set (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂) where instance _ = 𝔊₁.IsSetoid↦ instance _ = 𝔊₂.IsSetoid↦ field ⦃ isSemifunctor ⦄ : IsSemifunctor semigroupoids 𝔣 field identity : (x : 𝔊₁.⋆) → 𝔣 (𝔊₁.ε {x = x}) ≋ 𝔊₂.ε open IsSemifunctor isSemifunctor public open IsFunctor ⦃ … ⦄ public open import Oscar.Category.Morphism record Functor 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ : Set (lsuc (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂)) where constructor _,_ field categories : Categories 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ open Categories categories public field {μ} : 𝔊₁.⋆ → 𝔊₂.⋆ 𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y ⦃ isFunctor ⦄ : IsFunctor categories 𝔣 open IsFunctor isFunctor public -- module _ -- {𝔬₁ 𝔪₁ 𝔮₁} (category₁ : Category 𝔬₁ 𝔪₁ 𝔮₁) -- {𝔬₂ 𝔪₂ 𝔮₂} (category₂ : Category 𝔬₂ 𝔪₂ 𝔮₂) -- where -- private module 𝔊₁ = Category category₁ -- private module 𝔊₂ = Category category₂ -- record IsFunctor -- (μ : 𝔊₁.⋆ → 𝔊₂.⋆) -- (𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y) -- : Set (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂) where -- field -- ⦃ isSemifunctor ⦄ : IsSemifunctor 𝔊₁.semigroupoid 𝔊₂.semigroupoid μ 𝔣 -- field -- identity : (x : 𝔊₁.⋆) → 𝔣 (𝔊₁.ε {x = x}) ≋ 𝔊₂.ε -- open IsFunctor ⦃ … ⦄ public -- record Functor 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ : Set (lsuc (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂)) where -- field -- category₁ : Category 𝔬₁ 𝔪₁ 𝔮₁ -- category₂ : Category 𝔬₂ 𝔪₂ 𝔮₂ -- module 𝔊₁ = Category category₁ -- module 𝔊₂ = Category category₂ -- field -- μ : 𝔊₁.⋆ → 𝔊₂.⋆ -- 𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y -- ⦃ isFunctor ⦄ : IsFunctor category₁ category₂ μ 𝔣
{ "alphanum_fraction": 0.6197417743, "avg_line_length": 27.9186046512, "ext": "agda", "hexsha": "a3523c1561da286b2b5527342fcaabbfc804118a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-2/Oscar/Category/Functor.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-2/Oscar/Category/Functor.agda", "max_line_length": 84, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-2/Oscar/Category/Functor.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1255, "size": 2401 }
module Impossible where {-# IMPOSSIBLE #-}
{ "alphanum_fraction": 0.7045454545, "avg_line_length": 11, "ext": "agda", "hexsha": "6c84f20c7f0775bde53a91fca6104a0f429bdb69", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Impossible.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Impossible.agda", "max_line_length": 23, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Impossible.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 10, "size": 44 }
module _ where open import Agda.Builtin.Equality open import Agda.Builtin.Bool open import Agda.Builtin.Unit open import Agda.Builtin.List open import Agda.Builtin.Nat open import Agda.Builtin.Reflection renaming (returnTC to return; bindTC to _>>=_) _>>_ : {A B : Set} → TC A → TC B → TC B m >> m' = m >>= λ _ → m' macro solve : Nat → Term → TC ⊤ solve blocker hole = do unify hole (lam visible (abs "x" (var 0 []))) meta x _ ← withNormalisation true (quoteTC blocker) where _ → return _ blockOnMeta x mutual blocker : Nat blocker = _ bug : Bool bug = (solve blocker) true unblock : blocker ≡ 0 unblock = refl
{ "alphanum_fraction": 0.6641104294, "avg_line_length": 21.0322580645, "ext": "agda", "hexsha": "faab34cd7ff66f8a3ab95934fe276b9571a72e01", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue3639.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue3639.agda", "max_line_length": 82, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue3639.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 205, "size": 652 }
open import Agda.Builtin.Nat data Sing : Nat → Set where i : (k : Nat) → Sing k toSing : (n : Nat) → Sing n toSing n = i n fun : (n : Nat) → Nat fun n with toSing n fun .n | i n with toSing n fun .(n + n) | i .n | i n = {!!}
{ "alphanum_fraction": 0.5400843882, "avg_line_length": 16.9285714286, "ext": "agda", "hexsha": "527a8dba4a5959d36dd305257d63926252050d77", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue142.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue142.agda", "max_line_length": 32, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue142.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 95, "size": 237 }
module PrintNat where import PreludeShow open PreludeShow mainS = showNat 42
{ "alphanum_fraction": 0.7738095238, "avg_line_length": 12, "ext": "agda", "hexsha": "f7dc747f327677389072e5fa651428cc48f9a0a3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "examples/outdated-and-incorrect/Alonzo/PrintNat.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/Alonzo/PrintNat.agda", "max_line_length": 21, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/outdated-and-incorrect/Alonzo/PrintNat.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 21, "size": 84 }
------------------------------------------------------------------------ -- The Agda standard library -- -- The sublist relation over propositional equality. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Subset.Propositional {a} {A : Set a} where import Data.List.Relation.Binary.Subset.Setoid as SetoidSubset open import Relation.Binary.PropositionalEquality using (setoid) ------------------------------------------------------------------------ -- Re-export parameterised definitions from setoid sublists open SetoidSubset (setoid A) public
{ "alphanum_fraction": 0.5123839009, "avg_line_length": 34, "ext": "agda", "hexsha": "dd3608a22d6a051febbf37d0840f172518edf135", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Subset/Propositional.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Subset/Propositional.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Subset/Propositional.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 106, "size": 646 }
open import Common.Prelude renaming (Nat to ℕ; _+_ to _+ℕ_) open import Common.Product open import Common.Equality postulate _≤ℕ_ : (n m : ℕ) → Set maxℕ : (n m : ℕ) → ℕ When : (b : Bool) (P : Set) → Set When true P = P When false P = ⊤ infix 30 _⊕_ infix 20 _+_ infix 10 _≤_ infix 10 _<_ infixr 4 _,_ mutual data Cxt : Set where ∘ : Cxt _,_ : (Δ : Cxt) (b : Size Δ) → Cxt data Var : (Δ : Cxt) → Set where vz : ∀{Δ b} → Var (Δ , b) vs : ∀{Δ b} (i : Var Δ) → Var (Δ , b) data Base (Δ : Cxt) : Set where zero : Base Δ ∞ : Base Δ var : Var Δ → Base Δ record Size (Δ : Cxt) : Set where inductive constructor _⊕_ field h : Base Δ n : ℕ ↑ : ∀{Δ} (a : Size Δ) → Size Δ ↑ (h ⊕ n) = h ⊕ suc n _+_ : ∀{Δ} (a : Size Δ) (m : ℕ) → Size Δ (h ⊕ n) + m = h ⊕ (n +ℕ m) _-_ : ∀{Δ} (a : Size Δ) (m : ℕ) → Size Δ (h ⊕ n) - m = h ⊕ (n ∸ m) ClosedSize = Size ∘ data _≤_ : (a b : ClosedSize) → Set where leZZ : ∀{n m} (p : n ≤ℕ m) → zero ⊕ n ≤ zero ⊕ m leZ∞ : ∀{n m} → zero ⊕ n ≤ ∞ ⊕ m le∞∞ : ∀{n m} (p : n ≤ℕ m) → ∞ ⊕ n ≤ ∞ ⊕ m _<_ : (a b : ClosedSize) → Set a < b = ↑ a ≤ b max : (a b : ClosedSize) → ClosedSize max (zero ⊕ n) (zero ⊕ n') = zero ⊕ maxℕ n n' max (zero ⊕ n) (∞ ⊕ n') = ∞ ⊕ n' max (zero ⊕ n) (var () ⊕ n') max (∞ ⊕ n) (zero ⊕ n') = ∞ ⊕ n max (∞ ⊕ n) (∞ ⊕ n') = ∞ ⊕ maxℕ n n' max (∞ ⊕ n) (var () ⊕ n') max (var () ⊕ n) -- Closed size valuation mutual data Val (chk : Bool) : (Δ : Cxt) → Set where ∘ : Val chk ∘ _,_<_∣_ : ∀{Δ} (ξ : Val chk Δ) (a : ClosedSize) b (p : When chk (a < eval ξ b)) → Val chk (Δ , b) lookup : ∀{Δ chk} (ξ : Val chk Δ) (x : Var Δ) → ClosedSize lookup (ξ , a < b ∣ p) vz = a lookup (ξ , a < b ∣ p) (vs x) = lookup ξ x evalBase : ∀{Δ chk} (ξ : Val chk Δ) (a : Base Δ) → ClosedSize evalBase ξ zero = zero ⊕ 0 evalBase ξ ∞ = ∞ ⊕ 0 evalBase ξ (var x) = lookup ξ x eval : ∀{Δ chk} (ξ : Val chk Δ) (a : Size Δ) → ClosedSize eval ξ (h ⊕ n) = evalBase ξ h + n UVal = Val false -- unsound valuation SVal = Val true -- sound valuation update : ∀{Δ} (ρ : UVal Δ) (x : Var Δ) (f : ClosedSize → ClosedSize) → UVal Δ update (ρ , a < b ∣ _) vz f = ρ , f a < b ∣ _ update (ρ , a < b ∣ _) (vs x) f = update ρ x f , a < b ∣ _ data _≤V_ {chk chk'} : ∀ {Δ} (ρ : Val chk Δ) (ξ : Val chk' Δ) → Set where ∘ : ∘ ≤V ∘ _,_ : ∀{Δ} {ρ : Val chk Δ} {ξ : Val chk' Δ} {a a' b p q} (r : ρ ≤V ξ) (s : a ≤ a') → (ρ , a < b ∣ p) ≤V (ξ , a' < b ∣ q) lemma-str : ∀ {Δ} (x : Var Δ) {n} {a} {ρ : UVal Δ} {ξ : SVal Δ} → (p : ρ ≤V ξ) → (q : a < lookup ξ x + n) → update ρ x (max (↑ a - n)) ≤V ξ lemma-str vz (p , s) q = {!q!} lemma-str (vs x) (p , s) q = {!q!}
{ "alphanum_fraction": 0.4634502924, "avg_line_length": 25.8113207547, "ext": "agda", "hexsha": "c8a7bb9e87aad3368e90ceef45b2c94871d7c2b1", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/interaction/Issue635b.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/interaction/Issue635b.agda", "max_line_length": 101, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue635b.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 1301, "size": 2736 }
open import Categories open import Functors open import RMonads module RMonads.RKleisli.Functors {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}} {J : Fun C D}(M : RMonad J) where open import Library open import RMonads.RKleisli M open import RAdjunctions open Cat open Fun open RMonad M RKlL : Fun C Kl RKlL = record{ OMap = id; HMap = λ f → comp D η (HMap J f); fid = proof comp D η (HMap J (iden C)) ≅⟨ cong (comp D η) (fid J) ⟩ comp D η (iden D) ≅⟨ idr D ⟩ η ∎; fcomp = λ{_ _ _ f g} → proof comp D η (HMap J (comp C f g)) ≅⟨ cong (comp D η) (fcomp J) ⟩ comp D η (comp D (HMap J f) (HMap J g)) ≅⟨ sym (ass D) ⟩ comp D (comp D η (HMap J f)) (HMap J g) ≅⟨ cong (λ f → comp D f (HMap J g)) (sym law2) ⟩ comp D (comp D (bind (comp D η (HMap J f))) η) (HMap J g) ≅⟨ ass D ⟩ comp D (bind (comp D η (HMap J f))) (comp D η (HMap J g)) ∎} RKlR : Fun Kl D RKlR = record{ OMap = T; HMap = bind; fid = law1; fcomp = law3}
{ "alphanum_fraction": 0.530651341, "avg_line_length": 22.6956521739, "ext": "agda", "hexsha": "e6fc7795dde21016518318e6bcf426d40caef5f5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_path": "RMonads/RKleisli/Functors.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_path": "RMonads/RKleisli/Functors.agda", "max_line_length": 74, "max_stars_count": 21, "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_path": "RMonads/RKleisli/Functors.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "num_tokens": 451, "size": 1044 }
postulate B : Set module M where record ⊤ : Set where module P (A : Set) where open M public module PB = P B
{ "alphanum_fraction": 0.6495726496, "avg_line_length": 10.6363636364, "ext": "agda", "hexsha": "cd8596949c7da9c7dd37b23a15f40fbc41ac5d74", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue1679.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue1679.agda", "max_line_length": 24, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue1679.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 39, "size": 117 }
{-# OPTIONS --experimental-irrelevance #-} {-# OPTIONS --sized-types #-} open import Agda.Primitive public using (lzero; lsuc) open import Agda.Builtin.Size public using (Size; ↑_) renaming (∞ to oo) open import Agda.Builtin.Nat public using (suc) renaming (Nat to ℕ) _+_ : Size → ℕ → Size s + 0 = s s + suc n = ↑ (s + n) data Nat : ..(i : Size) → Set where zero : ∀ .i → Nat (↑ i) suc : ∀ .i → Nat i → Nat (↑ i) caseof : ∀{a b} {A : Set a} (B : A → Set b) → (x : A) → ((x : A) → B x) → B x caseof B x f = f x syntax caseof B x f = case x return B of f fix : ∀{ℓ} (T : ..(i : Size) → Nat i → Set ℓ) (f : ∀ .j → ((x : Nat j) → T j x) → (x : Nat (↑ j)) → T (↑ j) x) .{i} (x : Nat i) → T i x fix T f (zero j) = f j (fix T f) (zero j) fix T f (suc j n) = f j (fix T f) (suc j n)
{ "alphanum_fraction": 0.5142857143, "avg_line_length": 23.6764705882, "ext": "agda", "hexsha": "b7b3633e72c4dba6c46d06546b2372c744ef4624", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "262b8a87db8ab58aa77f60a749eacb8c49c7471f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/Sit", "max_forks_repo_path": "test/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "262b8a87db8ab58aa77f60a749eacb8c49c7471f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/Sit", "max_issues_repo_path": "test/Base.agda", "max_line_length": 77, "max_stars_count": 6, "max_stars_repo_head_hexsha": "262b8a87db8ab58aa77f60a749eacb8c49c7471f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/S", "max_stars_repo_path": "test/Base.agda", "max_stars_repo_stars_event_max_datetime": "2021-04-07T19:52:52.000Z", "max_stars_repo_stars_event_min_datetime": "2017-05-16T02:28:36.000Z", "num_tokens": 332, "size": 805 }
import Oscar.Class.Reflexivity.Function import Oscar.Class.Transextensionality.Proposequality -- FIXME why not use the instance here? open import Oscar.Class open import Oscar.Class.Category open import Oscar.Class.HasEquivalence open import Oscar.Class.IsCategory open import Oscar.Class.IsPrecategory open import Oscar.Class.Precategory open import Oscar.Class.Reflexivity open import Oscar.Class.Transassociativity open import Oscar.Class.Transextensionality open import Oscar.Class.Transitivity open import Oscar.Class.Transleftidentity open import Oscar.Class.Transrightidentity open import Oscar.Class.[IsExtensionB] open import Oscar.Data.Proposequality open import Oscar.Prelude open import Oscar.Property.Category.Function open import Oscar.Property.Setoid.Proposextensequality open import Oscar.Property.Setoid.Proposequality module Oscar.Property.Category.Proposequality where module _ {a} {A : Ø a} where instance 𝓣ransassociativityProposequality : Transassociativity.class Proposequality⟦ A ⟧ Proposequality transitivity 𝓣ransassociativityProposequality .⋆ ∅ _ _ = ! {- module _ {a} {A : Ø a} where instance 𝓣ransextensionalityProposequality : Transextensionality.class Proposequality⟦ A ⟧ Proposequality transitivity 𝓣ransextensionalityProposequality .⋆ ∅ ∅ = ! -} module _ {a} {A : Ø a} where instance 𝓣ransleftidentityProposequality : Transleftidentity.class Proposequality⟦ A ⟧ Proposequality ε transitivity 𝓣ransleftidentityProposequality .⋆ {f = ∅} = ∅ module _ {a} {A : Ø a} where instance 𝓣ransrightidentityProposequality : Transrightidentity.class Proposequality⟦ A ⟧ Proposequality ε transitivity 𝓣ransrightidentityProposequality .⋆ = ∅ {- module _ {a} (A : Ø a) where instance HasEquivalenceExtension : ∀ {x y : A} ⦃ _ : [IsExtensionB] B ⦄ → HasEquivalence (Extension B x y) _ HasEquivalenceExtension = ∁ Proposextensequality -} module _ {a} {A : Ø a} where instance IsPrecategoryProposequality : IsPrecategory Proposequality⟦ A ⟧ Proposequality transitivity IsPrecategoryProposequality = ∁ IsCategoryProposequality : IsCategory Proposequality⟦ A ⟧ Proposequality ε transitivity IsCategoryProposequality = ∁ module _ {a} (A : Ø a) where PrecategoryProposequality : Precategory _ _ _ PrecategoryProposequality = ∁ Proposequality⟦ A ⟧ Proposequality transitivity CategoryProposequality : Category _ _ _ CategoryProposequality = ∁ Proposequality⟦ A ⟧ Proposequality ε transitivity
{ "alphanum_fraction": 0.7779097387, "avg_line_length": 27.7582417582, "ext": "agda", "hexsha": "028eff0eadaeafe93adc5dd8b3e1a552a6ce355d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Property/Category/Proposequality.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Property/Category/Proposequality.agda", "max_line_length": 113, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Property/Category/Proposequality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 710, "size": 2526 }
open import MLib.Algebra.PropertyCode open import MLib.Algebra.PropertyCode.Structures module MLib.Matrix.SemiTensor.Core {c ℓ} (struct : Struct bimonoidCode c ℓ) where open import MLib.Prelude open import MLib.Matrix.Core open import MLib.Matrix.Equality struct open import MLib.Matrix.Mul struct open import MLib.Matrix.Tensor struct open import MLib.Algebra.Operations struct open Nat using () renaming (_+_ to _+ℕ_; _*_ to _*ℕ_) open import MLib.Fin.Parts.Simple open import Data.Nat.LCM open import Data.Nat.Divisibility chunkVec : ∀ {m n} → Table S (m *ℕ n) → Table (Table S n) m chunkVec {m} {n} t .lookup i .lookup j = lookup t (fromParts (i , j)) -- Case 1 of semi-tensor inner product of vectors _⋉ᵥ₁_ : ∀ {n t} → Table S (t *ℕ n) → Table S t → Table S n (_⋉ᵥ₁_ {n} {t} X Y) .lookup i = ∑[ k < t ] (X′ .lookup k .lookup i *′ Y .lookup k) where X′ = chunkVec {t} X -- Case 2 of semi-tensor inner product of vector _⋉ᵥ₂_ : ∀ {n s} → Table S s → Table S (s *ℕ n) → Table S n (_⋉ᵥ₂_ {n} {s} X Y) .lookup i = ∑[ k < s ] (X .lookup k *′ Y′ .lookup k .lookup i) where Y′ = chunkVec {s} Y module Defn {n p t : ℕ} (lcm : LCM n p t) where -- Left semi-Tensor product n∣t = LCM.commonMultiple lcm .proj₁ p∣t = LCM.commonMultiple lcm .proj₂ t/n = quotient n∣t t/p = quotient p∣t Iₜₙ = 1● {t/n} Iₜₚ = 1● {t/p} module _ where open ≡.Reasoning abstract lem₁ : n *ℕ t/n ≡ t lem₁ = begin n *ℕ t/n ≡⟨ Nat.*-comm n _ ⟩ t/n *ℕ n ≡⟨ ≡.sym (_∣_.equality n∣t) ⟩ t ∎ lem₂ : p *ℕ t/p ≡ t lem₂ = begin p *ℕ t/p ≡⟨ Nat.*-comm p _ ⟩ t/p *ℕ p ≡⟨ ≡.sym (_∣_.equality p∣t) ⟩ t ∎ module _ {m q} (A : Matrix S m n) (B : Matrix S p q) where A′ = A ⊠ Iₜₙ B′ = B ⊠ Iₜₚ A′′ = ≡.subst (Matrix S (m *ℕ t/n)) {y = t} lem₁ A′ B′′ = ≡.subst (λ h → Matrix S h (q *ℕ t/p)) {y = t} lem₂ B′ stp : Matrix S (m *ℕ t/n) (q *ℕ t/p) stp = A′′ ⊗ B′′ infixl 7 _⋉_ _⋉_ : ∀ {m n p q} → Matrix S m n → Matrix S p q → Matrix S _ _ _⋉_ {m} {n} {p} {q} = Defn.stp {n} {p} (lcm n p .proj₂)
{ "alphanum_fraction": 0.5775862069, "avg_line_length": 27.1168831169, "ext": "agda", "hexsha": "199066435e481109ae3c061a1ec8325251fe7956", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bch29/agda-matrices", "max_forks_repo_path": "src/MLib/Matrix/SemiTensor/Core.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bch29/agda-matrices", "max_issues_repo_path": "src/MLib/Matrix/SemiTensor/Core.agda", "max_line_length": 82, "max_stars_count": null, "max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bch29/agda-matrices", "max_stars_repo_path": "src/MLib/Matrix/SemiTensor/Core.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 902, "size": 2088 }
{-# OPTIONS --safe #-} module Cubical.Data.Int.MoreInts.BiInvInt where open import Cubical.Data.Int.MoreInts.BiInvInt.Base public open import Cubical.Data.Int.MoreInts.BiInvInt.Properties public
{ "alphanum_fraction": 0.8020304569, "avg_line_length": 28.1428571429, "ext": "agda", "hexsha": "60adfd54dc78063c72957cfe176ccab9b084310f", "lang": "Agda", "max_forks_count": 134, "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z", "max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "marcinjangrzybowski/cubical", "max_forks_repo_path": "Cubical/Data/Int/MoreInts/BiInvInt.agda", "max_issues_count": 584, "max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "marcinjangrzybowski/cubical", "max_issues_repo_path": "Cubical/Data/Int/MoreInts/BiInvInt.agda", "max_line_length": 64, "max_stars_count": 301, "max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "marcinjangrzybowski/cubical", "max_stars_repo_path": "Cubical/Data/Int/MoreInts/BiInvInt.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z", "num_tokens": 51, "size": 197 }
{-# OPTIONS --sized-types --show-implicit #-} module WrongSizeAssignment2 where open import Common.Size renaming (↑_ to _^) data Empty : Set where data N : {_ : Size} -> Set where zero : N {∞} suc : forall {i} -> N {i ^} -> N {i} lift : forall {i} -> N {i} -> N {i ^} lift zero = zero lift (suc x) = suc (lift x) f : forall {i} -> N {i} -> Empty f x = f (suc (lift x))
{ "alphanum_fraction": 0.5613577023, "avg_line_length": 20.1578947368, "ext": "agda", "hexsha": "f46b1a45d12f12312b3367d55490781cf39f3cf8", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/WrongSizeAssignment2.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/WrongSizeAssignment2.agda", "max_line_length": 45, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/WrongSizeAssignment2.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 134, "size": 383 }
postulate U V : Set T : V → Set H : ∀ v → T v → Set f : U → V data D : Set where d : D foo : (u : U) (t : T (f u)) (h : H (f u) t) → H (f u) t foo u t h with f u | d ... | fu | x = h
{ "alphanum_fraction": 0.395, "avg_line_length": 15.3846153846, "ext": "agda", "hexsha": "bd7ee9fa9d8c721ae3cf94a2bf02ee9c99fe109d", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue745c.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue745c.agda", "max_line_length": 55, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue745c.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 98, "size": 200 }
module RandomAccessList.Standard.Properties where open import BuildingBlock open import BuildingBlock.BinaryLeafTree using (BinaryLeafTree; Node; Leaf) import BuildingBlock.BinaryLeafTree as BLT open import RandomAccessList.Standard open import RandomAccessList.Standard.Core open import RandomAccessList.Standard.Core.Properties open import Data.Nat open import Data.Nat.Etc open import Data.Nat.Properties.Simple open import Data.Product as Prod open import Data.Product hiding (map) open import Data.Empty using (⊥-elim) open import Function open import Relation.Nullary using (Dec; yes; no; ¬_) open import Relation.Nullary.Decidable using (False; True; fromWitnessFalse) open import Relation.Nullary.Negation using (contraposition) open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; _≢_; refl; cong; cong₂; trans; sym; inspect) open PropEq.≡-Reasoning tailₙ-suc : ∀ {n A} → (xs : 0-1-RAL A n) → (p : ⟦ xs ⟧ ≢ 0) → suc ⟦ tailₙ xs p ⟧ₙ ≡ ⟦ xs ⟧ₙ tailₙ-suc {n} {A} [] p = ⊥-elim (p (⟦[]⟧≡0 ([] {A} {n}) refl)) tailₙ-suc ( 0∷ xs) p = begin 2 + (2 * ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ) ≡⟨ sym (+-*-suc 2 ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ) ⟩ 2 * suc ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ ≡⟨ cong (_*_ 2) (tailₙ-suc xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p)) ⟩ 2 * ⟦ xs ⟧ₙ ∎ tailₙ-suc (x 1∷ xs) p = refl tail-suc : ∀ {A} → (xs : 0-1-RAL A 0) → (p : ⟦ xs ⟧ ≢ 0) → suc ⟦ tail xs p ⟧ ≡ ⟦ xs ⟧ tail-suc {A} [] p = ⊥-elim (p (⟦[]⟧≡0 ([] {A} {0}) refl)) tail-suc (0∷ xs) p = begin 2 + (2 * ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ + 0) ≡⟨ sym (+-assoc 2 (2 * ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ) 0) ⟩ 2 + 2 * ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ + 0 ≡⟨ cong (λ x → x + 0) (sym (+-*-suc 2 ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ)) ⟩ 2 * suc ⟦ tailₙ xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p) ⟧ₙ + 0 ≡⟨ cong (λ x → 2 * x + 0) (tailₙ-suc xs (⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p)) ⟩ 2 * ⟦ xs ⟧ₙ + 0 ∎ tail-suc (x 1∷ xs) p = refl headₙ-tailₙ-consₙ : ∀ {n A} → (xs : 0-1-RAL A n) → (p : ⟦ xs ⟧ ≢ 0) → consₙ (headₙ xs p) (tailₙ xs p) ≡ xs headₙ-tailₙ-consₙ {n} {A} [] p = ⊥-elim (p (⟦[]⟧≡0 ([] {A} {n}) refl)) headₙ-tailₙ-consₙ (0∷ xs) p = let p' = contraposition (trans (⟦0∷xs⟧≡⟦xs⟧ xs)) p in begin consₙ (headₙ (0∷ xs) p) (tailₙ (0∷ xs) p) ≡⟨ refl ⟩ consₙ (proj₁ (BLT.split (headₙ xs p'))) ((proj₂ (BLT.split (headₙ xs p'))) 1∷ tailₙ xs p') ≡⟨ refl ⟩ 0∷ (consₙ (Node ((proj₁ (BLT.split (headₙ xs p')))) ((proj₂ (BLT.split (headₙ xs p'))))) (tailₙ xs p')) ≡⟨ cong (λ x → 0∷ consₙ x (tailₙ xs p')) (BLT.split-merge (headₙ xs p')) ⟩ 0∷ consₙ (headₙ xs (p')) (tailₙ xs p') ≡⟨ cong 0∷_ (headₙ-tailₙ-consₙ xs p') ⟩ 0∷ xs ∎ headₙ-tailₙ-consₙ (x 1∷ xs) p = refl head-tail-cons : ∀ {A} → (xs : 0-1-RAL A 0) → (p : ⟦ xs ⟧ ≢ 0) → cons (head xs p) (tail xs p) ≡ xs head-tail-cons {A} [] p = ⊥-elim (p (⟦[]⟧≡0 ([] {A} {0}) refl)) head-tail-cons (0∷ xs) p = let p' = contraposition (trans (⟦0∷xs⟧≡⟦xs⟧ xs)) p in begin cons (head (0∷ xs) p) (tail (0∷ xs) p) ≡⟨ cong (λ x → consₙ x (proj₂ (BLT.split (headₙ xs p')) 1∷ tailₙ xs p')) (lemma (proj₁ (BLT.split (headₙ xs p')))) ⟩ 0∷ consₙ (Node (proj₁ (BLT.split (headₙ xs p'))) (proj₂ (BLT.split (headₙ xs p')))) (tailₙ xs p') ≡⟨ cong (λ x → 0∷ consₙ x (tailₙ xs p')) (BLT.split-merge (headₙ xs p')) ⟩ 0∷ consₙ (headₙ xs p') (tailₙ xs p') ≡⟨ cong 0∷_ (headₙ-tailₙ-consₙ xs p') ⟩ 0∷ xs ∎ where lemma : ∀ {A} → (xs : BinaryLeafTree A 0) → Leaf (BLT.head xs) ≡ xs lemma (Leaf x) = refl head-tail-cons (Leaf x 1∷ xs) p = refl {- begin {! !} ≡⟨ {! !} ⟩ {! !} ≡⟨ {! !} ⟩ {! !} ≡⟨ {! !} ⟩ {! !} ≡⟨ {! !} ⟩ {! !} ∎ -}
{ "alphanum_fraction": 0.5207313933, "avg_line_length": 37.6990291262, "ext": "agda", "hexsha": "823a5c1edfcc8123193023bd0d02022f8613bbb5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "banacorn/numeral", "max_forks_repo_path": "legacy/RandomAccessList/Standard/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "banacorn/numeral", "max_issues_repo_path": "legacy/RandomAccessList/Standard/Properties.agda", "max_line_length": 120, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "banacorn/numeral", "max_stars_repo_path": "legacy/RandomAccessList/Standard/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z", "num_tokens": 1919, "size": 3883 }
{-# OPTIONS --without-K #-} open import lib.Base module lib.types.List where data List {i} (A : Type i) : Type i where nil : List A _::_ : A → List A → List A data HList {i} : List (Type i) → Type (lsucc i) where nil : HList nil _::_ : {A : Type i} {L : List (Type i)} → A → HList L → HList (A :: L) hlist-curry-type : ∀ {i j} (L : List (Type i)) (B : HList L → Type (lmax i j)) → Type (lmax i j) hlist-curry-type nil B = B nil hlist-curry-type {j = j} (A :: L) B = (x : A) → hlist-curry-type {j = j} L (λ xs → B (x :: xs)) hlist-curry : ∀ {i j} {L : List (Type i)} {B : HList L → Type (lmax i j)} (f : Π (HList L) B) → hlist-curry-type {j = j} L B hlist-curry {L = nil} f = f nil hlist-curry {L = A :: _} f = λ x → hlist-curry (λ xs → f (x :: xs))
{ "alphanum_fraction": 0.5409622887, "avg_line_length": 30.76, "ext": "agda", "hexsha": "3e4a1fe2e79df26d813cbe3236fc5163566af763", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "lib/types/List.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "lib/types/List.agda", "max_line_length": 73, "max_stars_count": 1, "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_path": "lib/types/List.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "num_tokens": 312, "size": 769 }
open import Oscar.Prelude open import Oscar.Class open import Oscar.Class.Leftunit open import Oscar.Class.Reflexivity open import Oscar.Class.Transitivity module Oscar.Class.Transleftidentity where module Transleftidentity {𝔬} {𝔒 : Ø 𝔬} {𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯) {ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ) (ε : Reflexivity.type _∼_) (transitivity : Transitivity.type _∼_) = ℭLASS (_∼_ ,, (λ {x y} → _∼̇_ {x} {y}) ,, (λ {x} → ε {x}) ,, (λ {x y z} → transitivity {x} {y} {z})) (∀ {x y} {f : x ∼ y} → Leftunit.type _∼̇_ ε (flip transitivity) f) module _ {𝔬} {𝔒 : Ø 𝔬} {𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯} {ℓ} {_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ} {ε : Reflexivity.type _∼_} {transitivity : Transitivity.type _∼_} where transleftidentity = Transleftidentity.method _∼_ _∼̇_ ε transitivity module Transleftidentity! {𝔬} {𝔒 : Ø 𝔬} {𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯) {ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ) ⦃ _ : Reflexivity.class _∼_ ⦄ ⦃ _ : Transitivity.class _∼_ ⦄ = Transleftidentity (_∼_) (_∼̇_) reflexivity transitivity module _ {𝔬} {𝔒 : Ø 𝔬} {𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯} {ℓ} {_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ} ⦃ _ : Reflexivity.class _∼_ ⦄ ⦃ _ : Transitivity.class _∼_ ⦄ where transleftidentity! = Transleftidentity!.method _∼_ _∼̇_ module _ where transleftidentity[_] : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯} {ℓ} (_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ) ⦃ _ : Reflexivity.class _∼_ ⦄ ⦃ _ : Transitivity.class _∼_ ⦄ ⦃ _ : Transleftidentity!.class _∼_ _∼̇_ ⦄ → Transleftidentity!.type _∼_ _∼̇_ transleftidentity[ _ ] = transleftidentity module _ where open import Oscar.Data.Proposequality module ≡̇-Transleftidentity! {𝔬} {𝔒 : Ø 𝔬} {𝔣} (F : 𝔒 → Ø 𝔣) {𝔱} (T : {x : 𝔒} → F x → 𝔒 → Ø 𝔱) (let _∼_ : ∀ x y → Ø 𝔣 ∙̂ 𝔱 _∼_ = λ x y → (f : F x) → T f y) ⦃ _ : Reflexivity.class _∼_ ⦄ ⦃ _ : Transitivity.class _∼_ ⦄ = Transleftidentity (_∼_) _≡̇_
{ "alphanum_fraction": 0.5443877551, "avg_line_length": 28, "ext": "agda", "hexsha": "0ff3d1921fa7d2a5509720c2e917e951f50d0e76", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Transleftidentity.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Transleftidentity.agda", "max_line_length": 104, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Transleftidentity.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 977, "size": 1960 }
{-# OPTIONS --without-K --safe #-} module Categories.Bicategory.Construction.Spans.Properties where open import Level open import Data.Product using (_,_; _×_) open import Relation.Binary.Bundles using (Setoid) import Relation.Binary.Reasoning.Setoid as SR open import Function.Equality as SΠ renaming (id to ⟶-id) open import Categories.Category open import Categories.Category.Helper open import Categories.Category.Instance.Setoids open import Categories.Category.Instance.Properties.Setoids.Limits.Canonical open import Categories.Diagram.Pullback open import Categories.Bicategory open import Categories.Bicategory.Monad import Categories.Category.Diagram.Span as Span import Categories.Bicategory.Construction.Spans as Spans -------------------------------------------------------------------------------- -- Monads in the Bicategory of Spans are Categories module _ {o ℓ : Level} (T : Monad (Spans.Spans (pullback o ℓ))) where private module T = Monad T open Span (Setoids (o ⊔ ℓ) ℓ) open Spans (pullback o ℓ) open Span⇒ open Bicategory Spans open Setoid renaming (_≈_ to [_][_≈_]) -- We can view the roof of the span as a hom set! However, we need to partition -- this big set up into small chunks with known domains/codomains. record Hom (X Y : Carrier T.C) : Set (o ⊔ ℓ) where field hom : Carrier (Span.M T.T) dom-eq : [ T.C ][ Span.dom T.T ⟨$⟩ hom ≈ X ] cod-eq : [ T.C ][ Span.cod T.T ⟨$⟩ hom ≈ Y ] open Hom private ObjSetoid : Setoid (o ⊔ ℓ) ℓ ObjSetoid = T.C HomSetoid : Setoid (o ⊔ ℓ) ℓ HomSetoid = Span.M T.T module ObjSetoid = Setoid ObjSetoid module HomSetoid = Setoid HomSetoid id⇒ : (X : Carrier T.C) → Hom X X id⇒ X = record { hom = arr T.η ⟨$⟩ X ; dom-eq = commute-dom T.η (refl T.C) ; cod-eq = commute-cod T.η (refl T.C) } _×ₚ_ : ∀ {A B C} → (f : Hom B C) → (g : Hom A B) → FiberProduct (Span.cod T.T) (Span.dom T.T) _×ₚ_ {B = B} f g = record { elem₁ = hom g ; elem₂ = hom f ; commute = begin Span.cod T.T ⟨$⟩ hom g ≈⟨ cod-eq g ⟩ B ≈⟨ ObjSetoid.sym (dom-eq f) ⟩ Span.dom T.T ⟨$⟩ hom f ∎ } where open SR ObjSetoid _∘⇒_ : ∀ {A B C} (f : Hom B C) → (g : Hom A B) → Hom A C _∘⇒_ {A = A} {C = C} f g = record { hom = arr T.μ ⟨$⟩ (f ×ₚ g) ; dom-eq = begin Span.dom T.T ⟨$⟩ (arr T.μ ⟨$⟩ (f ×ₚ g)) ≈⟨ (commute-dom T.μ {f ×ₚ g} {f ×ₚ g} (HomSetoid.refl , HomSetoid.refl)) ⟩ Span.dom T.T ⟨$⟩ hom g ≈⟨ dom-eq g ⟩ A ∎ ; cod-eq = begin Span.cod T.T ⟨$⟩ (arr T.μ ⟨$⟩ (f ×ₚ g)) ≈⟨ commute-cod T.μ {f ×ₚ g} {f ×ₚ g} (HomSetoid.refl , HomSetoid.refl) ⟩ Span.cod T.T ⟨$⟩ hom f ≈⟨ cod-eq f ⟩ C ∎ } where open SR ObjSetoid SpanMonad⇒Category : Category (o ⊔ ℓ) (o ⊔ ℓ) ℓ SpanMonad⇒Category = categoryHelper record { Obj = Setoid.Carrier T.C ; _⇒_ = Hom ; _≈_ = λ f g → [ HomSetoid ][ hom f ≈ hom g ] ; id = λ {X} → id⇒ X ; _∘_ = _∘⇒_ ; assoc = λ {A} {B} {C} {D} {f} {g} {h} → let f×ₚ⟨g×ₚh⟩ = record { elem₁ = record { elem₁ = hom f ; elem₂ = hom g ; commute = FiberProduct.commute (g ×ₚ f) } ; elem₂ = hom h ; commute = FiberProduct.commute (h ×ₚ g) } in begin arr T.μ ⟨$⟩ ((h ∘⇒ g) ×ₚ f) ≈⟨ cong (arr T.μ) (HomSetoid.refl , cong (arr T.μ) (HomSetoid.refl , HomSetoid.refl)) ⟩ arr T.μ ⟨$⟩ _ ≈⟨ T.sym-assoc {f×ₚ⟨g×ₚh⟩} {f×ₚ⟨g×ₚh⟩} ((HomSetoid.refl , HomSetoid.refl) , HomSetoid.refl) ⟩ arr T.μ ⟨$⟩ _ ≈⟨ (cong (arr T.μ) (cong (arr T.μ) (HomSetoid.refl , HomSetoid.refl) , HomSetoid.refl)) ⟩ arr T.μ ⟨$⟩ (h ×ₚ (g ∘⇒ f)) ∎ ; identityˡ = λ {A} {B} {f} → begin arr T.μ ⟨$⟩ (id⇒ B ×ₚ f) ≈⟨ cong (arr T.μ) (HomSetoid.refl , cong (arr T.η) (ObjSetoid.sym (cod-eq f))) ⟩ arr T.μ ⟨$⟩ _ ≈⟨ T.identityʳ HomSetoid.refl ⟩ hom f ∎ ; identityʳ = λ {A} {B} {f} → begin arr T.μ ⟨$⟩ (f ×ₚ id⇒ A) ≈⟨ cong (arr T.μ) (cong (arr T.η) (ObjSetoid.sym (dom-eq f)) , HomSetoid.refl) ⟩ arr T.μ ⟨$⟩ _ ≈⟨ T.identityˡ HomSetoid.refl ⟩ hom f ∎ ; equiv = record { refl = HomSetoid.refl ; sym = HomSetoid.sym ; trans = HomSetoid.trans } ; ∘-resp-≈ = λ f≈h g≈i → cong (arr T.μ) (g≈i , f≈h) } where open SR HomSetoid
{ "alphanum_fraction": 0.5165704511, "avg_line_length": 34.9029850746, "ext": "agda", "hexsha": "bd73d1d92ac863f32b738a2e979cc83f56456d3a", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Bicategory/Construction/Spans/Properties.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Bicategory/Construction/Spans/Properties.agda", "max_line_length": 130, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Bicategory/Construction/Spans/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 1718, "size": 4677 }
{-# OPTIONS --rewriting --without-K #-} open import Agda.Primitive open import Prelude {- Syntax for the Type theory for globular sets -} module GSeTT.Syntax where data Pre-Ty : Set data Pre-Tm : Set data Pre-Ty where ∗ : Pre-Ty ⇒ : Pre-Ty → Pre-Tm → Pre-Tm → Pre-Ty data Pre-Tm where Var : ℕ → Pre-Tm Pre-Ctx : Set₁ Pre-Ctx = list (ℕ × Pre-Ty) Pre-Sub : Set₁ Pre-Sub = list (ℕ × Pre-Tm) ⇒= : ∀ {A B t t' u u'} → A == B → t == t' → u == u' → ⇒ A t u == ⇒ B t' u' ⇒= idp idp idp = idp =⇒ : ∀ {A B t t' u u'} → ⇒ A t u == ⇒ B t' u' → (A == B × t == t') × u == u' =⇒ idp = (idp , idp) , idp tgt= : ∀ {A B t t' u u'} → ⇒ A t u == ⇒ B t' u' → u == u' tgt= idp = idp Var= : ∀ {v w} → v == w → Var v == Var w Var= idp = idp =Var : ∀ {v w} → Var v == Var w → v == w =Var idp = idp {- Dimension of a type and aof a context -} -- Careful: dimension of ∗ should be -1 dim : Pre-Ty → ℕ dim ∗ = O dim (⇒ A t u) = S (dim A) -- Careful: dimension of the empty context should be -1 dimC : Pre-Ctx → ℕ dimC nil = O dimC (Γ :: (x , A)) = max (dimC Γ) (dim A) {- Action of substitutions on types and terms on a syntactical level -} _[_]Pre-Ty : Pre-Ty → Pre-Sub → Pre-Ty _[_]Pre-Tm : Pre-Tm → Pre-Sub → Pre-Tm ∗ [ γ ]Pre-Ty = ∗ ⇒ A t u [ γ ]Pre-Ty = ⇒ (A [ γ ]Pre-Ty) (t [ γ ]Pre-Tm) (u [ γ ]Pre-Tm) Var x [ nil ]Pre-Tm = Var x Var x [ γ :: (v , t) ]Pre-Tm = if x ≡ v then t else ((Var x) [ γ ]Pre-Tm) _∘_ : Pre-Sub → Pre-Sub → Pre-Sub nil ∘ γ = nil (γ :: (x , t)) ∘ δ = (γ ∘ δ) :: (x , (t [ δ ]Pre-Tm)) {- Identity and canonical projection -} Pre-id : ∀ (Γ : Pre-Ctx) → Pre-Sub Pre-id nil = nil Pre-id (Γ :: (x , A)) = (Pre-id Γ) :: (x , Var x) Pre-π : ∀ (Γ : Pre-Ctx) (x : ℕ) (A : Pre-Ty) → Pre-Sub Pre-π Γ x A = Pre-id Γ {- The pairing (x#A) ∈ Γ -} _#_∈_ : ℕ → Pre-Ty → Pre-Ctx → Set _ # _ ∈ nil = ⊥ x # A ∈ (Γ :: (y , B)) = (x # A ∈ Γ) + ((x == y) × (A == B)) _∈_ : ℕ → Pre-Ctx → Set _ ∈ nil = ⊥ x ∈ (Γ :: (y , _)) = (x ∈ Γ) + (x == y) eqdec-PreCtx : eqdec Pre-Ctx eqdec-PreTy : eqdec Pre-Ty eqdec-PreTm : eqdec Pre-Tm eqdec-PreCtx nil nil = inl idp eqdec-PreCtx nil (_ :: _) = inr λ() eqdec-PreCtx (_ :: _) nil = inr λ() eqdec-PreCtx (Γ :: (n , A)) (Δ :: (m , B)) with eqdec-PreCtx Γ Δ | eqdecℕ n m | eqdec-PreTy A B ... | inl idp | inl idp | inl idp = inl idp ... | inl idp | inl idp | inr A≠B = inr λ Γ,A=Γ,B → A≠B (snd (=, (snd (=:: Γ,A=Γ,B)))) ... | inl idp | inr n≠m | _ = inr λ Γ,A=Γ,B → n≠m (fst (=, (snd (=:: Γ,A=Γ,B)))) ... | inr Γ≠Δ | _ | _ = inr λ{idp → Γ≠Δ idp} eqdec-PreTy ∗ ∗ = inl idp eqdec-PreTy ∗ (⇒ _ _ _) = inr λ() eqdec-PreTy (⇒ _ _ _) ∗ = inr λ() eqdec-PreTy (⇒ A t u) (⇒ B v w) with eqdec-PreTy A B | eqdec-PreTm t v | eqdec-PreTm u w ... | inl idp | inl idp | inl idp = inl idp ... | inl idp | inl idp | inr u≠w = inr λ A=B → u≠w (snd (=⇒ A=B)) ... | inl idp | inr t≠v | _ = inr λ A=B → t≠v (snd (fst (=⇒ A=B))) ... | inr A≠B | _ | _ = inr λ{idp → A≠B idp} eqdec-PreTm (Var a) (Var b) with eqdecℕ a b ... | inl idp = inl idp ... | inr a≠b = inr λ{idp → a≠b idp}
{ "alphanum_fraction": 0.4849445325, "avg_line_length": 29.4859813084, "ext": "agda", "hexsha": "443ca79e9dfa9c4d3b3c8c005552a9526b025fd0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thibautbenjamin/catt-formalization", "max_forks_repo_path": "GSeTT/Syntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thibautbenjamin/catt-formalization", "max_issues_repo_path": "GSeTT/Syntax.agda", "max_line_length": 97, "max_stars_count": null, "max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thibautbenjamin/catt-formalization", "max_stars_repo_path": "GSeTT/Syntax.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1487, "size": 3155 }
open import Data.Product using ( _×_ ; _,_ ) open import Data.Sum using ( inj₁ ; inj₂ ) open import Relation.Binary.PropositionalEquality using ( refl ) open import Relation.Unary using ( _∈_ ; _∉_ ; _⊆_ ) open import Web.Semantic.DL.Concept.Model using ( _⟦_⟧₁ ; ⟦⟧₁-resp-≈ ; ⟦⟧₁-resp-≃; ⟦⟧₁-refl-≃ ) open import Web.Semantic.DL.Role.Model using ( _⟦_⟧₂ ; ⟦⟧₂-resp-≈ ; ⟦⟧₂-resp-≃ ; ⟦⟧₂-refl-≃ ) open import Web.Semantic.DL.Signature using ( Signature ) open import Web.Semantic.DL.TBox using ( TBox ; Axioms ; ε ; _,_ ;_⊑₁_ ; _⊑₂_ ; Dis ; Ref ; Irr ; Tra ) open import Web.Semantic.DL.TBox.Interp using ( Interp ) open import Web.Semantic.DL.TBox.Interp.Morphism using ( _≃_ ; ≃-sym ) open import Web.Semantic.Util using ( True ; tt ; _∘_ ) module Web.Semantic.DL.TBox.Model {Σ : Signature} where infixr 2 _⊨t_ _⊨t_ : Interp Σ → TBox Σ → Set I ⊨t ε = True I ⊨t (T , U) = (I ⊨t T) × (I ⊨t U) I ⊨t (C ⊑₁ D) = I ⟦ C ⟧₁ ⊆ I ⟦ D ⟧₁ I ⊨t (Q ⊑₂ R) = I ⟦ Q ⟧₂ ⊆ I ⟦ R ⟧₂ I ⊨t (Dis Q R) = ∀ {xy} → (xy ∈ I ⟦ Q ⟧₂) → (xy ∉ I ⟦ R ⟧₂) I ⊨t (Ref R) = ∀ x → ((x , x) ∈ I ⟦ R ⟧₂) I ⊨t (Irr R) = ∀ x → ((x , x) ∉ I ⟦ R ⟧₂) I ⊨t (Tra R) = ∀ {x y z} → ((x , y) ∈ I ⟦ R ⟧₂) → ((y , z) ∈ I ⟦ R ⟧₂) → ((x , z) ∈ I ⟦ R ⟧₂) Axioms✓ : ∀ I T {t} → (t ∈ Axioms T) → (I ⊨t T) → (I ⊨t t) Axioms✓ I ε () I⊨T Axioms✓ I (T , U) (inj₁ t∈T) (I⊨T , I⊨U) = Axioms✓ I T t∈T I⊨T Axioms✓ I (T , U) (inj₂ t∈U) (I⊨T , I⊨U) = Axioms✓ I U t∈U I⊨U Axioms✓ I (C ⊑₁ D) refl I⊨T = I⊨T Axioms✓ I (Q ⊑₂ R) refl I⊨T = I⊨T Axioms✓ I (Dis Q R) refl I⊨T = I⊨T Axioms✓ I (Ref R) refl I⊨T = I⊨T Axioms✓ I (Irr R) refl I⊨T = I⊨T Axioms✓ I (Tra R) refl I⊨T = I⊨T ⊨t-resp-≃ : ∀ {I J : Interp Σ} → (I ≃ J) → ∀ T → (I ⊨t T) → (J ⊨t T) ⊨t-resp-≃ {I} {J} I≃J ε _ = tt ⊨t-resp-≃ {I} {J} I≃J (T , U) (I⊨T , I⊨U) = (⊨t-resp-≃ I≃J T I⊨T , ⊨t-resp-≃ I≃J U I⊨U) ⊨t-resp-≃ {I} {J} I≃J (C ⊑₁ D) I⊨C⊑D = ⟦⟧₁-refl-≃ I≃J D ∘ I⊨C⊑D ∘ ⟦⟧₁-resp-≃ (≃-sym I≃J) C ⊨t-resp-≃ {I} {J} I≃J (Q ⊑₂ R) I⊨Q⊑R = ⟦⟧₂-refl-≃ I≃J R ∘ I⊨Q⊑R ∘ ⟦⟧₂-resp-≃ (≃-sym I≃J) Q ⊨t-resp-≃ {I} {J} I≃J (Dis Q R) I⊨DisQR = λ xy∈⟦Q⟧ xy∈⟦R⟧ → I⊨DisQR (⟦⟧₂-resp-≃ (≃-sym I≃J) Q xy∈⟦Q⟧) (⟦⟧₂-resp-≃ (≃-sym I≃J) R xy∈⟦R⟧) ⊨t-resp-≃ {I} {J} I≃J (Ref R) I⊨RefR = λ x → ⟦⟧₂-refl-≃ I≃J R (I⊨RefR _) ⊨t-resp-≃ {I} {J} I≃J (Irr R) I⊨IrrR = λ x xx∈⟦R⟧ → I⊨IrrR _ (⟦⟧₂-resp-≃ (≃-sym I≃J) R xx∈⟦R⟧) ⊨t-resp-≃ {I} {J} I≃J (Tra R) I⊨TraR = λ xy∈⟦R⟧ yz∈⟦R⟧ → ⟦⟧₂-refl-≃ I≃J R (I⊨TraR (⟦⟧₂-resp-≃ (≃-sym I≃J) R xy∈⟦R⟧) (⟦⟧₂-resp-≃ (≃-sym I≃J) R yz∈⟦R⟧))
{ "alphanum_fraction": 0.4741280184, "avg_line_length": 43.4833333333, "ext": "agda", "hexsha": "a1c09b122b71b3dda7a04be6ded3b367e6ccb894", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_path": "src/Web/Semantic/DL/TBox/Model.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_path": "src/Web/Semantic/DL/TBox/Model.agda", "max_line_length": 77, "max_stars_count": 9, "max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/agda-web-semantic", "max_stars_repo_path": "src/Web/Semantic/DL/TBox/Model.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z", "num_tokens": 1645, "size": 2609 }
-- Andreas, 2017-01-13, regression introduced by the fix of #1899 -- test case and report by Nisse -- {-# OPTIONS -v term:40 #-} open import Agda.Builtin.Size mutual D : Size → Set D i = D′ i record D′ (i : Size) : Set where coinductive field force : {j : Size< i} → D j test : D′ ω D′.force test = test -- Same without sizes (they are not used) mutual E = E' record E' : Set where coinductive field force : E testE : E' E'.force testE = testE -- Both should succeed, no termination errors.
{ "alphanum_fraction": 0.6228893058, "avg_line_length": 16.1515151515, "ext": "agda", "hexsha": "69905a7bc6672a45052a87438a148537e3c749c5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Blaisorblade/Agda", "max_forks_repo_path": "test/Succeed/Issue1899-coind.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "Blaisorblade/Agda", "max_issues_repo_path": "test/Succeed/Issue1899-coind.agda", "max_line_length": 65, "max_stars_count": 3, "max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "Blaisorblade/Agda", "max_stars_repo_path": "test/Succeed/Issue1899-coind.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 176, "size": 533 }
{-# OPTIONS --without-K #-} module PInj where open import Codata.Delay renaming (length to dlength ; map to dmap ) open import Codata.Thunk open import Relation.Binary.PropositionalEquality open import Size open import Level open import Data.Product -- A pair of partial functions that are supposed to form a partial bijection. record _⊢_⇔_ (i : Size) {ℓ : Level} (A : Set ℓ) (B : Set ℓ) : Set ℓ where constructor pre-pinj-i field forward : A -> Delay B i backward : B -> Delay A i open _⊢_⇔_
{ "alphanum_fraction": 0.6969111969, "avg_line_length": 22.5217391304, "ext": "agda", "hexsha": "4b66e6a146f0b3e77526345221a2f243f0175425", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "e2fb3a669e733a9020a51b24244d89abd8fcf725", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "kztk-m/sparcl-agda", "max_forks_repo_path": "PInj.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e2fb3a669e733a9020a51b24244d89abd8fcf725", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "kztk-m/sparcl-agda", "max_issues_repo_path": "PInj.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "e2fb3a669e733a9020a51b24244d89abd8fcf725", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "kztk-m/sparcl-agda", "max_stars_repo_path": "PInj.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 156, "size": 518 }
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-} module 10-number-theory where import 09-truncation-levels open 09-truncation-levels public two-ℕ : ℕ two-ℕ = succ-ℕ one-ℕ three-ℕ : ℕ three-ℕ = succ-ℕ two-ℕ four-ℕ : ℕ four-ℕ = succ-ℕ three-ℕ five-ℕ : ℕ five-ℕ = succ-ℕ four-ℕ six-ℕ : ℕ six-ℕ = succ-ℕ five-ℕ seven-ℕ : ℕ seven-ℕ = succ-ℕ six-ℕ eight-ℕ : ℕ eight-ℕ = succ-ℕ seven-ℕ nine-ℕ : ℕ nine-ℕ = succ-ℕ eight-ℕ ten-ℕ : ℕ ten-ℕ = succ-ℕ nine-ℕ -- Section 10.1 Decidability. {- Recall that a proposition P is decidable if P + (¬ P) holds. -} classical-Prop : (l : Level) → UU (lsuc l) classical-Prop l = Σ (UU-Prop l) (λ P → is-decidable (pr1 P)) is-decidable-Eq-ℕ : (m n : ℕ) → is-decidable (Eq-ℕ m n) is-decidable-Eq-ℕ zero-ℕ zero-ℕ = inl star is-decidable-Eq-ℕ zero-ℕ (succ-ℕ n) = inr id is-decidable-Eq-ℕ (succ-ℕ m) zero-ℕ = inr id is-decidable-Eq-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-Eq-ℕ m n is-decidable-leq-ℕ : (m n : ℕ) → is-decidable (leq-ℕ m n) is-decidable-leq-ℕ zero-ℕ zero-ℕ = inl star is-decidable-leq-ℕ zero-ℕ (succ-ℕ n) = inl star is-decidable-leq-ℕ (succ-ℕ m) zero-ℕ = inr id is-decidable-leq-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-leq-ℕ m n is-decidable-le-ℕ : (m n : ℕ) → is-decidable (le-ℕ m n) is-decidable-le-ℕ zero-ℕ zero-ℕ = inr id is-decidable-le-ℕ zero-ℕ (succ-ℕ n) = inl star is-decidable-le-ℕ (succ-ℕ m) zero-ℕ = inr id is-decidable-le-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-le-ℕ m n {- We say that a type has decidable equality if we can decide whether x = y holds for any x,y:A. -} has-decidable-equality : {l : Level} (A : UU l) → UU l has-decidable-equality A = (x y : A) → is-decidable (Id x y) {- The type ℕ is an example of a type with decidable equality. -} Eq-ℕ-eq : (x y : ℕ) → Id x y → Eq-ℕ x y Eq-ℕ-eq x .x refl = refl-Eq-ℕ x is-injective-succ-ℕ : (x y : ℕ) → Id (succ-ℕ x) (succ-ℕ y) → Id x y is-injective-succ-ℕ zero-ℕ zero-ℕ p = refl is-injective-succ-ℕ zero-ℕ (succ-ℕ y) p = ind-empty { P = λ t → Id zero-ℕ (succ-ℕ y)} ( Eq-ℕ-eq one-ℕ (succ-ℕ (succ-ℕ y)) p) is-injective-succ-ℕ (succ-ℕ x) zero-ℕ p = ind-empty { P = λ t → Id (succ-ℕ x) zero-ℕ} ( Eq-ℕ-eq (succ-ℕ (succ-ℕ x)) one-ℕ p) is-injective-succ-ℕ (succ-ℕ x) (succ-ℕ y) p = ap succ-ℕ (eq-Eq-ℕ x y (Eq-ℕ-eq (succ-ℕ (succ-ℕ x)) (succ-ℕ (succ-ℕ y)) p)) has-decidable-equality-ℕ : has-decidable-equality ℕ has-decidable-equality-ℕ zero-ℕ zero-ℕ = inl refl has-decidable-equality-ℕ zero-ℕ (succ-ℕ y) = inr (Eq-ℕ-eq zero-ℕ (succ-ℕ y)) has-decidable-equality-ℕ (succ-ℕ x) zero-ℕ = inr (Eq-ℕ-eq (succ-ℕ x) zero-ℕ) has-decidable-equality-ℕ (succ-ℕ x) (succ-ℕ y) = functor-coprod ( ap succ-ℕ) ( λ (f : ¬ (Id x y)) p → f (is-injective-succ-ℕ x y p)) ( has-decidable-equality-ℕ x y) {- Types with decidable equality are closed under coproducts. -} has-decidable-equality-coprod : {l1 l2 : Level} {A : UU l1} {B : UU l2} → has-decidable-equality A → has-decidable-equality B → has-decidable-equality (coprod A B) has-decidable-equality-coprod dec-A dec-B (inl x) (inl y) = functor-coprod ( ap inl) ( λ f p → f (inv-is-equiv (is-emb-inl _ _ x y) p)) ( dec-A x y) has-decidable-equality-coprod {A = A} {B = B} dec-A dec-B (inl x) (inr y) = inr ( λ p → inv-is-equiv ( is-equiv-map-raise _ empty) ( Eq-coprod-eq A B (inl x) (inr y) p)) has-decidable-equality-coprod {A = A} {B = B} dec-A dec-B (inr x) (inl y) = inr ( λ p → inv-is-equiv ( is-equiv-map-raise _ empty) ( Eq-coprod-eq A B (inr x) (inl y) p)) has-decidable-equality-coprod dec-A dec-B (inr x) (inr y) = functor-coprod ( ap inr) ( λ f p → f (inv-is-equiv (is-emb-inr _ _ x y) p)) ( dec-B x y) {- Decidable equality of Fin n. -} has-decidable-equality-empty : has-decidable-equality empty has-decidable-equality-empty () has-decidable-equality-unit : has-decidable-equality unit has-decidable-equality-unit star star = inl refl has-decidable-equality-Fin : (n : ℕ) → has-decidable-equality (Fin n) has-decidable-equality-Fin zero-ℕ = has-decidable-equality-empty has-decidable-equality-Fin (succ-ℕ n) = has-decidable-equality-coprod ( has-decidable-equality-Fin n) ( has-decidable-equality-unit) {- Decidable equality of ℤ. -} has-decidable-equality-ℤ : has-decidable-equality ℤ has-decidable-equality-ℤ = has-decidable-equality-coprod has-decidable-equality-ℕ ( has-decidable-equality-coprod has-decidable-equality-unit has-decidable-equality-ℕ) {- Next, we show that types with decidable equality are sets. To see this, we will construct a fiberwise equivalence with the binary relation R that is defined by R x y := unit if (x = y), and empty otherwise. In order to define this relation, we first define a type family over ((x = y) + ¬(x = y)) that returns unit on the left and empty on the right. -} splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) → is-decidable (Id x y) → UU lzero splitting-decidable-equality A x y (inl p) = unit splitting-decidable-equality A x y (inr f) = empty is-prop-splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) → (t : is-decidable (Id x y)) → is-prop (splitting-decidable-equality A x y t) is-prop-splitting-decidable-equality A x y (inl p) = is-prop-unit is-prop-splitting-decidable-equality A x y (inr f) = is-prop-empty reflexive-splitting-decidable-equality : {l : Level} (A : UU l) (x : A) → (t : is-decidable (Id x x)) → splitting-decidable-equality A x x t reflexive-splitting-decidable-equality A x (inl p) = star reflexive-splitting-decidable-equality A x (inr f) = ind-empty {P = λ t → splitting-decidable-equality A x x (inr f)} (f refl) eq-splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) → (t : is-decidable (Id x y)) → splitting-decidable-equality A x y t → Id x y eq-splitting-decidable-equality A x y (inl p) t = p eq-splitting-decidable-equality A x y (inr f) t = ind-empty {P = λ s → Id x y} t is-set-has-decidable-equality : {l : Level} (A : UU l) → has-decidable-equality A → is-set A is-set-has-decidable-equality A d = is-set-prop-in-id ( λ x y → splitting-decidable-equality A x y (d x y)) ( λ x y → is-prop-splitting-decidable-equality A x y (d x y)) ( λ x → reflexive-splitting-decidable-equality A x (d x x)) ( λ x y → eq-splitting-decidable-equality A x y (d x y)) {- Closure of decidable types under retracts and equivalences. -} is-decidable-retract-of : {l1 l2 : Level} {A : UU l1} {B : UU l2} → A retract-of B → is-decidable B → is-decidable A is-decidable-retract-of (pair i (pair r H)) (inl b) = inl (r b) is-decidable-retract-of (pair i (pair r H)) (inr f) = inr (f ∘ i) is-decidable-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} {f : A → B} (is-equiv-f : is-equiv f) → is-decidable B → is-decidable A is-decidable-is-equiv {f = f} (pair (pair g G) (pair h H)) = is-decidable-retract-of (pair f (pair h H)) is-decidable-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → is-decidable B → is-decidable A is-decidable-equiv e = is-decidable-is-equiv (is-equiv-map-equiv e) is-decidable-equiv' : {l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → is-decidable A → is-decidable B is-decidable-equiv' e = is-decidable-equiv (inv-equiv e) has-decidable-equality-retract-of : {l1 l2 : Level} {A : UU l1} {B : UU l2} → A retract-of B → has-decidable-equality B → has-decidable-equality A has-decidable-equality-retract-of (pair i (pair r H)) d x y = is-decidable-retract-of ( Id-retract-of-Id (pair i (pair r H)) x y) ( d (i x) (i y)) {- The well-ordering principle. -} is-minimal-element-ℕ : {l : Level} (P : ℕ → UU l) (n : ℕ) (p : P n) → UU l is-minimal-element-ℕ P n p = (m : ℕ) → P m → (leq-ℕ n m) minimal-element-ℕ : {l : Level} (P : ℕ → UU l) → UU l minimal-element-ℕ P = Σ ℕ (λ n → Σ (P n) (is-minimal-element-ℕ P n)) is-minimal-element-succ-ℕ : {l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) (m : ℕ) (pm : P (succ-ℕ m)) (is-min-m : is-minimal-element-ℕ (λ x → P (succ-ℕ x)) m pm) → ¬ (P zero-ℕ) → is-minimal-element-ℕ P (succ-ℕ m) pm is-minimal-element-succ-ℕ P d m pm is-min-m neg-p0 zero-ℕ p0 = ind-empty (neg-p0 p0) is-minimal-element-succ-ℕ P d zero-ℕ pm is-min-m neg-p0 (succ-ℕ n) psuccn = leq-zero-ℕ n is-minimal-element-succ-ℕ P d (succ-ℕ m) pm is-min-m neg-p0 (succ-ℕ n) psuccn = is-minimal-element-succ-ℕ (λ x → P (succ-ℕ x)) (λ x → d (succ-ℕ x)) m pm ( λ m → is-min-m (succ-ℕ m)) ( is-min-m zero-ℕ) ( n) ( psuccn) well-ordering-principle-succ-ℕ : {l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) (n : ℕ) (p : P (succ-ℕ n)) → is-decidable (P zero-ℕ) → minimal-element-ℕ (λ m → P (succ-ℕ m)) → minimal-element-ℕ P well-ordering-principle-succ-ℕ P d n p (inl p0) _ = pair zero-ℕ (pair p0 (λ m q → leq-zero-ℕ m)) well-ordering-principle-succ-ℕ P d n p (inr neg-p0) (pair m (pair pm is-min-m)) = pair ( succ-ℕ m) ( pair pm ( is-minimal-element-succ-ℕ P d m pm is-min-m neg-p0)) well-ordering-principle-ℕ : {l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) → Σ ℕ P → minimal-element-ℕ P well-ordering-principle-ℕ P d (pair zero-ℕ p) = pair zero-ℕ (pair p (λ m q → leq-zero-ℕ m)) well-ordering-principle-ℕ P d (pair (succ-ℕ n) p) = well-ordering-principle-succ-ℕ P d n p (d zero-ℕ) ( well-ordering-principle-ℕ ( λ m → P (succ-ℕ m)) ( λ m → d (succ-ℕ m)) ( pair n p)) {- The Pigeon hole principle. -} {- First we write a function that counts the number of elements in a decidable subset of a finite set. -} count-Fin-succ-ℕ : {l : Level} (n : ℕ) (P : Fin (succ-ℕ n) → classical-Prop l) → ℕ → is-decidable (pr1 (pr1 (P (inr star)))) → ℕ count-Fin-succ-ℕ n P m (inl x) = succ-ℕ m count-Fin-succ-ℕ n P m (inr x) = m count-Fin : (l : Level) (n : ℕ) (P : Fin n → classical-Prop l) → ℕ count-Fin l zero-ℕ P = zero-ℕ count-Fin l (succ-ℕ n) P = count-Fin-succ-ℕ n P ( count-Fin l n (P ∘ inl)) ( pr2 (P (inr star))) {- Next we prove the pigeonhole principle. -} decidable-Eq-Fin : (n : ℕ) (i j : Fin n) → classical-Prop lzero decidable-Eq-Fin n i j = pair ( pair (Id i j) (is-set-Fin n i j)) ( has-decidable-equality-Fin n i j) skip : (n : ℕ) → Fin (succ-ℕ n) → Fin n → Fin (succ-ℕ n) skip (succ-ℕ n) (inl i) (inl j) = inl (skip n i j) skip (succ-ℕ n) (inl i) (inr star) = inr star skip (succ-ℕ n) (inr star) j = inl j double : (n : ℕ) → Fin n → Fin (succ-ℕ n) → Fin n double (succ-ℕ n) (inl i) (inl j) = inl (double n i j) double (succ-ℕ n) (inl j) (inr star) = inr star double (succ-ℕ n) (inr star) (inl j) = j double (succ-ℕ n) (inr star) (inr star) = inr star {- skip-skip : (n : ℕ) (i : Fin (succ-ℕ (succ-ℕ n))) (j : Fin (succ-ℕ n)) → ( ( skip (succ-ℕ n) i) ∘ (skip n j)) ~ ( ( skip (succ-ℕ n) (skip (succ-ℕ n) i j)) ∘ ( skip n (double (succ-ℕ n) j i))) skip-skip zero-ℕ (inl x) (inl x₁) () skip-skip zero-ℕ (inl x) (inr x₁) () skip-skip zero-ℕ (inr x) (inl x₁) () skip-skip zero-ℕ (inr x) (inr x₁) () skip-skip (succ-ℕ n) (inl i) (inl j) (inl k) = {!!} skip-skip (succ-ℕ n) (inl x) (inl x₁) (inr x₂) = {!!} skip-skip (succ-ℕ n) (inl x) (inr x₁) (inl x₂) = {!!} skip-skip (succ-ℕ n) (inl x) (inr x₁) (inr x₂) = {!!} skip-skip (succ-ℕ n) (inr x) (inl x₁) (inl x₂) = {!!} skip-skip (succ-ℕ n) (inr x) (inl x₁) (inr x₂) = {!!} skip-skip (succ-ℕ n) (inr x) (inr x₁) (inl x₂) = {!!} skip-skip (succ-ℕ n) (inr x) (inr x₁) (inr x₂) = {!!} -} {- pigeonhole-principle : (m n : ℕ) (f : Fin n → Fin m) (H : le-ℕ m n) → Σ ( Fin m) (λ i → le-ℕ one-ℕ ( count-Fin lzero n ( λ j → decidable-Eq-Fin m (f j) i))) pigeonhole-principle zero-ℕ (succ-ℕ n) f H = {!!} pigeonhole-principle (succ-ℕ m) n f H = {!!} -} -- The greatest common divisor {- First we show that mul-ℕ n is an embedding whenever n > 0. In order to do this, we have to show that add-ℕ n is injective. -} is-injective-add-ℕ : (n : ℕ) → is-injective is-set-ℕ is-set-ℕ (add-ℕ n) is-injective-add-ℕ zero-ℕ k l p = p is-injective-add-ℕ (succ-ℕ n) k l p = is-injective-add-ℕ n k l (is-injective-succ-ℕ (add-ℕ n k) (add-ℕ n l) p) is-emb-add-ℕ : (n : ℕ) → is-emb (add-ℕ n) is-emb-add-ℕ n = is-emb-is-injective is-set-ℕ is-set-ℕ (add-ℕ n) (is-injective-add-ℕ n) leq-fib-add-ℕ : (m n : ℕ) → fib (add-ℕ m) n → (leq-ℕ m n) leq-fib-add-ℕ zero-ℕ n (pair k p) = leq-zero-ℕ n leq-fib-add-ℕ (succ-ℕ m) (succ-ℕ n) (pair k p) = leq-fib-add-ℕ m n (pair k (is-injective-succ-ℕ (add-ℕ m k) n p)) fib-add-leq-ℕ : (m n : ℕ) → (leq-ℕ m n) → fib (add-ℕ m) n fib-add-leq-ℕ zero-ℕ zero-ℕ H = pair zero-ℕ refl fib-add-leq-ℕ zero-ℕ (succ-ℕ n) H = pair (succ-ℕ n) refl fib-add-leq-ℕ (succ-ℕ m) (succ-ℕ n) H = pair ( pr1 (fib-add-leq-ℕ m n H)) ( ap succ-ℕ (pr2 (fib-add-leq-ℕ m n H))) is-prop-leq-ℕ : (m n : ℕ) → is-prop (leq-ℕ m n) is-prop-leq-ℕ zero-ℕ zero-ℕ = is-prop-unit is-prop-leq-ℕ zero-ℕ (succ-ℕ n) = is-prop-unit is-prop-leq-ℕ (succ-ℕ m) zero-ℕ = is-prop-empty is-prop-leq-ℕ (succ-ℕ m) (succ-ℕ n) = is-prop-leq-ℕ m n is-equiv-leq-fib-add-ℕ : (m n : ℕ) → is-equiv (leq-fib-add-ℕ m n) is-equiv-leq-fib-add-ℕ m n = is-equiv-is-prop ( is-prop-map-is-emb _ (is-emb-add-ℕ m) n) ( is-prop-leq-ℕ m n) ( fib-add-leq-ℕ m n) is-equiv-fib-add-leq-ℕ : (m n : ℕ) → is-equiv (fib-add-leq-ℕ m n) is-equiv-fib-add-leq-ℕ m n = is-equiv-is-prop ( is-prop-leq-ℕ m n) ( is-prop-map-is-emb _ (is-emb-add-ℕ m) n) ( leq-fib-add-ℕ m n) is-injective-add-ℕ' : (n : ℕ) → is-injective is-set-ℕ is-set-ℕ (λ m → add-ℕ m n) is-injective-add-ℕ' n k l p = is-injective-add-ℕ n k l (((commutative-add-ℕ n k) ∙ p) ∙ (commutative-add-ℕ l n)) is-injective-mul-ℕ : (n : ℕ) → (le-ℕ zero-ℕ n) → is-injective is-set-ℕ is-set-ℕ (mul-ℕ n) is-injective-mul-ℕ (succ-ℕ n) star zero-ℕ zero-ℕ p = refl is-injective-mul-ℕ (succ-ℕ n) star zero-ℕ (succ-ℕ l) p = ind-empty ( Eq-ℕ-eq ( zero-ℕ) ( succ-ℕ (add-ℕ (mul-ℕ n (succ-ℕ l)) l)) ( ( inv (right-zero-law-mul-ℕ n)) ∙ ( ( inv (right-unit-law-add-ℕ (mul-ℕ n zero-ℕ))) ∙ ( p ∙ (right-successor-law-add-ℕ (mul-ℕ n (succ-ℕ l)) l))))) is-injective-mul-ℕ (succ-ℕ n) star (succ-ℕ k) zero-ℕ p = ind-empty ( Eq-ℕ-eq ( succ-ℕ (add-ℕ (mul-ℕ n (succ-ℕ k)) k)) ( zero-ℕ) ( ( inv (right-successor-law-add-ℕ (mul-ℕ n (succ-ℕ k)) k)) ∙ ( p ∙ ( right-zero-law-mul-ℕ (succ-ℕ n))))) is-injective-mul-ℕ (succ-ℕ n) star (succ-ℕ k) (succ-ℕ l) p = ap succ-ℕ ( is-injective-mul-ℕ (succ-ℕ n) star k l ( is-injective-add-ℕ (succ-ℕ n) ( mul-ℕ (succ-ℕ n) k) ( mul-ℕ (succ-ℕ n) l) ( ( inv (right-successor-law-mul-ℕ (succ-ℕ n) k) ∙ p) ∙ ( right-successor-law-mul-ℕ (succ-ℕ n) l)))) is-emb-mul-ℕ : (n : ℕ) → (le-ℕ zero-ℕ n) → is-emb (mul-ℕ n) is-emb-mul-ℕ n le = is-emb-is-injective is-set-ℕ is-set-ℕ ( mul-ℕ n) ( is-injective-mul-ℕ n le) is-emb-mul-ℕ' : (n : ℕ) → (le-ℕ zero-ℕ n) → is-emb (λ m → mul-ℕ m n) is-emb-mul-ℕ' n t = is-emb-htpy' ( mul-ℕ n) ( λ m → mul-ℕ m n) ( commutative-mul-ℕ n) ( is-emb-mul-ℕ n t) {- We conclude that the division relation is a property. -} div-ℕ : ℕ → ℕ → UU lzero div-ℕ m n = Σ ℕ (λ k → Id (mul-ℕ k m) n) is-prop-div-ℕ : (m n : ℕ) → (le-ℕ zero-ℕ m) → is-prop (div-ℕ m n) is-prop-div-ℕ (succ-ℕ m) n star = is-prop-map-is-emb ( λ z → mul-ℕ z (succ-ℕ m)) ( is-emb-mul-ℕ' (succ-ℕ m) star) n {- We now construct the division with remainder. -} le-mul-ℕ : (d n k : ℕ) → UU lzero le-mul-ℕ d n k = le-ℕ n (mul-ℕ k d) is-decidable-le-mul-ℕ : (d n k : ℕ) → is-decidable (le-mul-ℕ d n k) is-decidable-le-mul-ℕ d n k = is-decidable-le-ℕ n (mul-ℕ k d) order-preserving-succ-ℕ : (n n' : ℕ) → (leq-ℕ n n') → (leq-ℕ (succ-ℕ n) (succ-ℕ n')) order-preserving-succ-ℕ n n' H = H leq-eq-left-ℕ : {m m' : ℕ} → Id m m' → (n : ℕ) → leq-ℕ m n → leq-ℕ m' n leq-eq-left-ℕ refl n = id leq-eq-right-ℕ : (m : ℕ) {n n' : ℕ} → Id n n' → leq-ℕ m n → leq-ℕ m n' leq-eq-right-ℕ m refl = id order-preserving-add-ℕ : (m n m' n' : ℕ) → (leq-ℕ m m') → (leq-ℕ n n') → (leq-ℕ (add-ℕ m n) (add-ℕ m' n')) order-preserving-add-ℕ zero-ℕ zero-ℕ m' n' Hm Hn = star order-preserving-add-ℕ zero-ℕ (succ-ℕ n) zero-ℕ (succ-ℕ n') Hm Hn = Hn order-preserving-add-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ m') (succ-ℕ n') Hm Hn = leq-eq-right-ℕ n ( inv (right-successor-law-add-ℕ m' n')) ( order-preserving-add-ℕ zero-ℕ n (succ-ℕ m') n' Hm Hn) order-preserving-add-ℕ (succ-ℕ m) n (succ-ℕ m') n' Hm Hn = order-preserving-add-ℕ m n m' n' Hm Hn le-eq-right-ℕ : (m : ℕ) {n n' : ℕ} → Id n n' → le-ℕ m n' → le-ℕ m n le-eq-right-ℕ m refl = id le-add-ℕ : (m n : ℕ) → (leq-ℕ one-ℕ n) → le-ℕ m (add-ℕ m n) le-add-ℕ zero-ℕ (succ-ℕ n) star = star le-add-ℕ (succ-ℕ m) (succ-ℕ n) star = le-add-ℕ m (succ-ℕ n) star le-mul-self-ℕ : (d n : ℕ) → (leq-ℕ one-ℕ d) → (leq-ℕ one-ℕ n) → le-mul-ℕ d n n le-mul-self-ℕ (succ-ℕ d) (succ-ℕ n) star star = le-eq-right-ℕ ( succ-ℕ n) ( right-successor-law-mul-ℕ (succ-ℕ n) d) ( le-add-ℕ (succ-ℕ n) (mul-ℕ (succ-ℕ n) d) {!leq-eq-right-ℕ !}) leq-multiple-ℕ : (n m : ℕ) → (leq-ℕ one-ℕ m) → leq-ℕ n (mul-ℕ n m) leq-multiple-ℕ n (succ-ℕ m) H = leq-eq-right-ℕ n ( inv (right-successor-law-mul-ℕ n m)) ( leq-fib-add-ℕ n (add-ℕ n (mul-ℕ n m)) (pair (mul-ℕ n m) refl)) least-factor-least-larger-multiple-ℕ : (d n : ℕ) → (leq-ℕ one-ℕ d) → minimal-element-ℕ (λ k → leq-ℕ n (mul-ℕ k d)) least-factor-least-larger-multiple-ℕ d n H = well-ordering-principle-ℕ ( λ k → leq-ℕ n (mul-ℕ k d)) ( λ k → is-decidable-leq-ℕ n (mul-ℕ k d)) ( pair n (leq-multiple-ℕ n d H)) factor-least-larger-multiple-ℕ : (d n : ℕ) → (leq-ℕ one-ℕ d) → ℕ factor-least-larger-multiple-ℕ d n H = pr1 (least-factor-least-larger-multiple-ℕ d n H) least-larger-multiple-ℕ : (d n : ℕ) → (leq-ℕ one-ℕ d) → ℕ least-larger-multiple-ℕ d n H = mul-ℕ (factor-least-larger-multiple-ℕ d n H) d leq-least-larger-multiple-ℕ : (d n : ℕ) (H : leq-ℕ one-ℕ d) → leq-ℕ n (least-larger-multiple-ℕ d n H) leq-least-larger-multiple-ℕ d n H = pr1 (pr2 (least-factor-least-larger-multiple-ℕ d n H)) is-minimal-least-larger-multiple-ℕ : (d n : ℕ) (H : leq-ℕ one-ℕ d) (k : ℕ) (K : leq-ℕ n (mul-ℕ k d)) → leq-ℕ (factor-least-larger-multiple-ℕ d n H) k is-minimal-least-larger-multiple-ℕ d n H = pr2 (pr2 (least-factor-least-larger-multiple-ℕ d n H)) is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ : (d n : ℕ) (H : leq-ℕ one-ℕ d) → is-decidable (Id (least-larger-multiple-ℕ d n H) n) → is-decidable (div-ℕ d n) is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ d n H (inl p) = inl (pair (factor-least-larger-multiple-ℕ d n H) p) is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ d n H (inr f) = inr (λ x → {!!}) is-decidable-div-ℕ' : (d n : ℕ) → (leq-ℕ one-ℕ d) → is-decidable (div-ℕ d n) is-decidable-div-ℕ' d n H = {!!} is-decidable-div-ℕ : (d n : ℕ) → is-decidable (div-ℕ d n) is-decidable-div-ℕ zero-ℕ zero-ℕ = inl (pair zero-ℕ refl) is-decidable-div-ℕ zero-ℕ (succ-ℕ n) = inr ( λ p → Eq-ℕ-eq zero-ℕ (succ-ℕ n) ((inv (right-zero-law-mul-ℕ (pr1 p))) ∙ (pr2 p))) is-decidable-div-ℕ (succ-ℕ d) n = is-decidable-div-ℕ' (succ-ℕ d) n (leq-zero-ℕ d) -- Operations on decidable bounded subsets of ℕ iterated-operation-ℕ : (strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) (base-value : ℕ) → ℕ iterated-operation-ℕ zero-ℕ μ e = e iterated-operation-ℕ (succ-ℕ b) μ e = μ (iterated-operation-ℕ b μ e) b iterated-sum-ℕ : (summand : ℕ → ℕ) (b : ℕ) → ℕ iterated-sum-ℕ f zero-ℕ = zero-ℕ iterated-sum-ℕ f (succ-ℕ b) = add-ℕ (iterated-sum-ℕ f b) (f (succ-ℕ b)) ranged-sum-ℕ : (summand : ℕ → ℕ) (l u : ℕ) → ℕ ranged-sum-ℕ f zero-ℕ u = iterated-sum-ℕ f u ranged-sum-ℕ f (succ-ℕ l) zero-ℕ = zero-ℕ ranged-sum-ℕ f (succ-ℕ l) (succ-ℕ u) = ranged-sum-ℕ (f ∘ succ-ℕ) l u succ-iterated-operation-fam-ℕ : { l : Level} ( P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) → ( predecessor-strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) → is-decidable (P predecessor-strict-upper-bound) → ℕ → ℕ succ-iterated-operation-fam-ℕ P is-decidable-P b μ (inl p) m = μ m b succ-iterated-operation-fam-ℕ P is-decidable-P b μ (inr f) m = m iterated-operation-fam-ℕ : { l : Level} (P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) → ( strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) (base-value : ℕ) → ℕ iterated-operation-fam-ℕ P d zero-ℕ μ e = e iterated-operation-fam-ℕ P d (succ-ℕ b) μ e = succ-iterated-operation-fam-ℕ P d b μ (d b) ( iterated-operation-fam-ℕ P d b μ e) Sum-fam-ℕ : { l : Level} (P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) → ( upper-bound : ℕ) ( summand : ℕ → ℕ) → ℕ Sum-fam-ℕ P d b f = iterated-operation-fam-ℕ P d (succ-ℕ b) (λ x y → add-ℕ x (f y)) zero-ℕ {- iterated-operation-fam-ℕ P is-decidable-P zero-ℕ is-bounded-P μ base-value = base-value iterated-operation-fam-ℕ P is-decidable-P (succ-ℕ b) is-bounded-P μ base-value = succ-iterated-operation-ℕ P is-decidable-P b is-bounded-P μ ( is-decidable-P b) ( iterated-operation-ℕ ( introduce-bound-on-fam-ℕ b P) ( is-decidable-introduce-bound-on-fam-ℕ b P is-decidable-P) ( b) ( is-bounded-introduce-bound-on-fam-ℕ b P) ( μ) ( base-value)) product-decidable-bounded-fam-ℕ : { l : Level} (P : ℕ → UU l) → ( is-decidable-P : (n : ℕ) → is-decidable (P n)) ( b : ℕ) ( is-bounded-P : is-bounded-fam-ℕ b P) → ℕ product-decidable-bounded-fam-ℕ P is-decidable-P b is-bounded-P = iterated-operation-ℕ P is-decidable-P b is-bounded-P mul-ℕ one-ℕ twenty-four-ℕ : ℕ twenty-four-ℕ = product-decidable-bounded-fam-ℕ ( λ x → le-ℕ x five-ℕ) ( λ x → is-decidable-le-ℕ x five-ℕ) ( five-ℕ) ( λ x → id) -} {- test-zero-twenty-four-ℕ : Id twenty-four-ℕ zero-ℕ test-zero-twenty-four-ℕ = refl test-twenty-four-ℕ : Id twenty-four-ℕ (factorial four-ℕ) test-twenty-four-ℕ = refl -} -- Exercises -- Exercise 10.? Eq-𝟚-eq : (x y : bool) → Id x y → Eq-𝟚 x y Eq-𝟚-eq x .x refl = reflexive-Eq-𝟚 x abstract has-decidable-equality-𝟚 : has-decidable-equality bool has-decidable-equality-𝟚 true true = inl refl has-decidable-equality-𝟚 true false = inr (Eq-𝟚-eq true false) has-decidable-equality-𝟚 false true = inr (Eq-𝟚-eq false true) has-decidable-equality-𝟚 false false = inl refl -- Exercise 10.? abstract has-decidable-equality-prod' : {l1 l2 : Level} {A : UU l1} {B : UU l2} → (x x' : A) (y y' : B) → is-decidable (Id x x') → is-decidable (Id y y') → is-decidable (Id (pair x y) (pair x' y')) has-decidable-equality-prod' x x' y y' (inl p) (inl q) = inl (eq-pair-triv (pair p q)) has-decidable-equality-prod' x x' y y' (inl p) (inr g) = inr (λ h → g (ap pr2 h)) has-decidable-equality-prod' x x' y y' (inr f) (inl q) = inr (λ h → f (ap pr1 h)) has-decidable-equality-prod' x x' y y' (inr f) (inr g) = inr (λ h → f (ap pr1 h)) abstract has-decidable-equality-prod : {l1 l2 : Level} {A : UU l1} {B : UU l2} → has-decidable-equality A → has-decidable-equality B → has-decidable-equality (A × B) has-decidable-equality-prod dec-A dec-B (pair x y) (pair x' y') = has-decidable-equality-prod' x x' y y' (dec-A x x') (dec-B y y') {- bounds-fam-ℕ : {l : Level} (P : ℕ → UU l) → UU l bounds-fam-ℕ P = Σ ℕ (λ n → is-bounded-fam-ℕ n P) is-minimal-ℕ : {l : Level} (P : ℕ → UU l) → Σ ℕ P → UU l is-minimal-ℕ P (pair n p) = (t : Σ ℕ P) → leq-ℕ n (pr1 t) eq-zero-leq-zero-ℕ : (n : ℕ) → leq-ℕ n zero-ℕ → Id n zero-ℕ eq-zero-leq-zero-ℕ zero-ℕ star = refl eq-zero-leq-zero-ℕ (succ-ℕ n) () fam-succ-ℕ : {l : Level} → (ℕ → UU l) → (ℕ → UU l) fam-succ-ℕ P n = P (succ-ℕ n) is-decidable-fam-succ-ℕ : {l : Level} (P : ℕ → UU l) → ((n : ℕ) → is-decidable (P n)) → ((n : ℕ) → is-decidable (P (succ-ℕ n))) is-decidable-fam-succ-ℕ P d n = d (succ-ℕ n) min-is-bounded-not-zero-ℕ : {l : Level} (P : ℕ → UU l) → ((n : ℕ) → is-decidable (P n)) → Σ ℕ (λ n → is-bounded-fam-ℕ n P) → ¬ (P zero-ℕ) → Σ (Σ ℕ (fam-succ-ℕ P)) (is-minimal-ℕ (fam-succ-ℕ P)) → Σ (Σ ℕ P) (is-minimal-ℕ P) min-is-bounded-not-zero-ℕ P d b np0 t = {!!} min-is-bounded-ℕ : {l : Level} (P : ℕ → UU l) → ((n : ℕ) → is-decidable (P n)) → Σ ℕ (λ n → is-bounded-fam-ℕ n P) → Σ ℕ P → Σ (Σ ℕ P) (is-minimal-ℕ P) min-is-bounded-ℕ P d (pair zero-ℕ b) t = pair ( pair ( zero-ℕ) ( tr P (eq-zero-leq-zero-ℕ (pr1 t) (b (pr1 t) (pr2 t))) (pr2 t))) ( λ p → leq-zero-ℕ (pr1 p)) min-is-bounded-ℕ P d (pair (succ-ℕ n) b) t = ind-coprod ( λ (t : is-decidable (P zero-ℕ)) → Σ (Σ ℕ P) (is-minimal-ℕ P)) ( λ p0 → pair (pair zero-ℕ p0) (λ p → leq-zero-ℕ (pr1 p))) ( λ y → min-is-bounded-not-zero-ℕ P d (pair (succ-ℕ n) b) y ( min-is-bounded-ℕ ( fam-succ-ℕ P) ( is-decidable-fam-succ-ℕ P d) {!!} {!!})) ( d zero-ℕ) {- We show that every non-empty decidable subset of ℕ has a least element. -} least-ℕ : {l : Level} (P : ℕ → UU l) → Σ ℕ P → UU l least-ℕ P (pair n p) = (m : ℕ) → P m → leq-ℕ n m least-element-non-empty-decidable-subset-ℕ : {l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) → Σ ℕ P → Σ (Σ ℕ P) (least-ℕ P) least-element-non-empty-decidable-subset-ℕ P d (pair zero-ℕ p) = pair (pair zero-ℕ p) {!!} least-element-non-empty-decidable-subset-ℕ P d (pair (succ-ℕ n) p) = {!!} -} zero-Fin : (n : ℕ) → Fin (succ-ℕ n) zero-Fin zero-ℕ = inr star zero-Fin (succ-ℕ n) = inl (zero-Fin n) succ-Fin : (n : ℕ) → Fin n → Fin n succ-Fin (succ-ℕ n) (inr star) = zero-Fin n succ-Fin (succ-ℕ (succ-ℕ n)) (inl (inl x)) = inl (succ-Fin (succ-ℕ n) (inl x)) succ-Fin (succ-ℕ (succ-ℕ n)) (inl (inr star)) = inr star iterated-succ-Fin : (k : ℕ) → (n : ℕ) → Fin n → Fin n iterated-succ-Fin zero-ℕ n = id iterated-succ-Fin (succ-ℕ k) n = (succ-Fin n) ∘ (iterated-succ-Fin k n) quotient-ℕ-Fin : (n : ℕ) → Fin (succ-ℕ n) quotient-ℕ-Fin n = iterated-succ-Fin n (succ-ℕ n) (zero-Fin n) pred-Fin : (n : ℕ) → Fin n → Fin n pred-Fin (succ-ℕ zero-ℕ) (inr star) = inr star pred-Fin (succ-ℕ (succ-ℕ n)) (inl x) = {!!} pred-Fin (succ-ℕ (succ-ℕ n)) (inr star) = inl (inr star) add-Fin : (n : ℕ) → Fin n → Fin n → Fin n add-Fin (succ-ℕ n) (inl x) j = {!!} add-Fin (succ-ℕ n) (inr x) j = {!!} idempotent-succ-Fin : (n : ℕ) (i : Fin n) → Id (iterated-succ-Fin n n i) i idempotent-succ-Fin (succ-ℕ zero-ℕ) (inr star) = refl idempotent-succ-Fin (succ-ℕ (succ-ℕ n)) (inl x) = {!!} idempotent-succ-Fin (succ-ℕ (succ-ℕ n)) (inr x) = {!!} in-nat-ℤ : ℕ → ℤ in-nat-ℤ zero-ℕ = zero-ℤ in-nat-ℤ (succ-ℕ n) = in-pos n div-ℤ : (k l : ℤ) → UU lzero div-ℤ k l = Σ ℤ (λ x → Id (mul-ℤ x k) l) _≡_mod_ : (k l : ℤ) (n : ℕ) → UU lzero k ≡ l mod n = div-ℤ (in-nat-ℤ n) (add-ℤ k (neg-ℤ l)) -- From before is-even-ℕ : ℕ → UU lzero is-even-ℕ n = div-ℕ two-ℕ n is-prime : ℕ → UU lzero is-prime n = (one-ℕ < n) × ((m : ℕ) → (one-ℕ < m) → (div-ℕ m n) → Id m n) {- The Goldbach conjecture asserts that every even number above 2 is the sum of two primes. -} Goldbach-conjecture : UU lzero Goldbach-conjecture = ( n : ℕ) → (two-ℕ < n) → (is-even-ℕ n) → Σ ℕ (λ p → (is-prime p) × (Σ ℕ (λ q → (is-prime q) × Id (add-ℕ p q) n))) is-twin-prime : ℕ → UU lzero is-twin-prime n = (is-prime n) × (is-prime (succ-ℕ (succ-ℕ n))) {- The twin prime conjecture asserts that there are infinitely many twin primes. We assert that there are infinitely twin primes by asserting that for every n : ℕ there is a twin prime that is larger than n. -} Twin-prime-conjecture : UU lzero Twin-prime-conjecture = (n : ℕ) → Σ ℕ (λ p → (is-twin-prime p) × (leq-ℕ n p))
{ "alphanum_fraction": 0.5954642303, "avg_line_length": 33.0047675805, "ext": "agda", "hexsha": "05232d9fa4161694e328570eb8228b0cff497529", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_path": "Agda/10-number-theory.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_path": "Agda/10-number-theory.agda", "max_line_length": 90, "max_stars_count": null, "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_path": "Agda/10-number-theory.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 12395, "size": 27691 }
-- We apply the theory of quasi equivalence relations (QERs) to finite multisets and association lists. {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Relation.ZigZag.Applications.MultiSet where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.Foundations.RelationalStructure open import Cubical.Foundations.Structure open import Cubical.Foundations.SIP open import Cubical.Foundations.Univalence open import Cubical.Data.Unit open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Nat open import Cubical.Data.List hiding ([_]) open import Cubical.Data.Sigma open import Cubical.HITs.SetQuotients open import Cubical.HITs.FiniteMultiset as FMS hiding ([_] ; _++_) open import Cubical.HITs.FiniteMultiset.CountExtensionality open import Cubical.HITs.PropositionalTruncation open import Cubical.Relation.Nullary open import Cubical.Relation.ZigZag.Base open import Cubical.Structures.MultiSet open import Cubical.Structures.Relational.Auto open import Cubical.Structures.Relational.Macro -- we define simple association lists without any higher constructors data AList {ℓ} (A : Type ℓ) : Type ℓ where ⟨⟩ : AList A ⟨_,_⟩∷_ : A → ℕ → AList A → AList A infixr 5 ⟨_,_⟩∷_ private variable ℓ : Level -- We have a CountStructure on List and AList and use these to get a QER between the two module Lists&ALists {A : Type ℓ} (discA : Discrete A) where multisetShape : Type ℓ → Type ℓ multisetShape X = X × (A → X → X) × (X → X → X) × (A → X → Const[ ℕ , isSetℕ ]) module S = RelMacro ℓ (autoRelDesc multisetShape) addIfEq : (a x : A) → ℕ → ℕ → ℕ addIfEq a x m n with discA a x ... | yes _ = m + n ... | no _ = n module _ {a x : A} {n : ℕ} where addIfEq≡ : {m : ℕ} → a ≡ x → addIfEq a x m n ≡ m + n addIfEq≡ a≡x with discA a x ... | yes _ = refl ... | no a≢x = ⊥.rec (a≢x a≡x) addIfEq≢ : {m : ℕ} → ¬ (a ≡ x) → addIfEq a x m n ≡ n addIfEq≢ a≢x with discA a x ... | yes a≡x = ⊥.rec (a≢x a≡x) ... | no _ = refl addIfEq0 : addIfEq a x 0 n ≡ n addIfEq0 with discA a x ... | yes _ = refl ... | no _ = refl addIfEq+ : {m : ℕ} (n' : ℕ) → addIfEq a x m (n + n') ≡ addIfEq a x m n + n' addIfEq+ n' with discA a x ... | yes _ = +-assoc _ n n' ... | no _ = refl module L where emp : List A emp = [] insert : A → List A → List A insert x xs = x ∷ xs union : List A → List A → List A union xs ys = xs ++ ys count : A → List A → ℕ count a [] = zero count a (x ∷ xs) = addIfEq a x 1 (count a xs) structure : S.structure (List A) structure = emp , insert , union , count countUnion : ∀ a xs ys → count a (union xs ys) ≡ count a xs + count a ys countUnion a [] ys = refl countUnion a (x ∷ xs) ys = cong (addIfEq a x 1) (countUnion a xs ys) ∙ addIfEq+ (count a ys) module AL where emp : AList A emp = ⟨⟩ insert* : ℕ → A → AList A → AList A insert* m a ⟨⟩ = ⟨ a , m ⟩∷ ⟨⟩ insert* m a (⟨ y , n ⟩∷ ys) with (discA a y) ... | yes _ = ⟨ y , m + n ⟩∷ ys ... | no _ = ⟨ y , n ⟩∷ insert* m a ys insert : A → AList A → AList A insert = insert* 1 union : AList A → AList A → AList A union ⟨⟩ ys = ys union (⟨ x , n ⟩∷ xs) ys = insert* n x (union xs ys) count : A → AList A → ℕ count a ⟨⟩ = zero count a (⟨ y , n ⟩∷ ys) = addIfEq a y n (count a ys) structure : S.structure (AList A) structure = emp , insert , union , count countInsert* : ∀ m a x ys → count a (insert* m x ys) ≡ addIfEq a x m (count a ys) countInsert* m a x ⟨⟩ = refl countInsert* m a x (⟨ y , n ⟩∷ ys) with discA a x | discA a y | discA x y ... | yes a≡x | yes a≡y | yes x≡y = addIfEq≡ a≡y ∙ sym (+-assoc m n _) ... | yes a≡x | yes a≡y | no x≢y = ⊥.rec (x≢y (sym a≡x ∙ a≡y)) ... | yes a≡x | no a≢y | yes x≡y = ⊥.rec (a≢y (a≡x ∙ x≡y)) ... | yes a≡x | no a≢y | no x≢y = addIfEq≢ a≢y ∙ countInsert* m a x ys ∙ addIfEq≡ a≡x ... | no a≢x | yes a≡y | yes x≡y = ⊥.rec (a≢x (a≡y ∙ sym x≡y)) ... | no a≢x | yes a≡y | no x≢y = addIfEq≡ a≡y ∙ cong (n +_) (countInsert* m a x ys ∙ addIfEq≢ a≢x) ... | no a≢x | no a≢y | yes x≡y = addIfEq≢ a≢y ... | no a≢x | no a≢y | no x≢y = addIfEq≢ a≢y ∙ countInsert* m a x ys ∙ addIfEq≢ a≢x countInsert = countInsert* 1 countUnion : ∀ a xs ys → count a (union xs ys) ≡ count a xs + count a ys countUnion a ⟨⟩ ys = refl countUnion a (⟨ x , n ⟩∷ xs) ys = countInsert* n a x (union xs ys) ∙ cong (addIfEq a x n) (countUnion a xs ys) ∙ addIfEq+ (count a ys) -- now for the QER between List and Alist R : List A → AList A → Type ℓ R xs ys = ∀ a → L.count a xs ≡ AL.count a ys φ : List A → AList A φ [] = ⟨⟩ φ (x ∷ xs) = AL.insert x (φ xs) ψ : AList A → List A ψ ⟨⟩ = [] ψ (⟨ x , zero ⟩∷ xs) = ψ xs ψ (⟨ x , suc n ⟩∷ xs) = x ∷ ψ (⟨ x , n ⟩∷ xs) η : ∀ xs → R xs (φ xs) η [] a = refl η (x ∷ xs) a = cong (addIfEq a x 1) (η xs a) ∙ sym (AL.countInsert a x (φ xs)) -- for the other direction we need a little helper function ε : ∀ y → R (ψ y) y ε' : (x : A) (n : ℕ) (xs : AList A) (a : A) → L.count a (ψ (⟨ x , n ⟩∷ xs)) ≡ AL.count a (⟨ x , n ⟩∷ xs) ε ⟨⟩ a = refl ε (⟨ x , n ⟩∷ xs) a = ε' x n xs a ε' x zero xs a = ε xs a ∙ sym addIfEq0 ε' x (suc n) xs a with discA a x ... | yes a≡x = cong suc (ε' x n xs a ∙ addIfEq≡ a≡x) ... | no a≢x = ε' x n xs a ∙ addIfEq≢ a≢x -- Induced quotients and equivalence open isQuasiEquivRel -- R is a QER QuasiR : QuasiEquivRel _ _ ℓ QuasiR .fst .fst = R QuasiR .fst .snd _ _ = isPropΠ λ _ → isSetℕ _ _ QuasiR .snd .zigzag r r' r'' a = (r a) ∙∙ sym (r' a) ∙∙ (r'' a) QuasiR .snd .fwd a = ∣ φ a , η a ∣ QuasiR .snd .bwd b = ∣ ψ b , ε b ∣ isStructuredInsert : (x : A) {xs : List A} {ys : AList A} → R xs ys → R (L.insert x xs) (AL.insert x ys) isStructuredInsert x {xs} {ys} r a = cong (addIfEq a x 1) (r a) ∙ sym (AL.countInsert a x ys) isStructuredUnion : {xs : List A} {ys : AList A} (r : R xs ys) {xs' : List A} {ys' : AList A} (r' : R xs' ys') → R (L.union xs xs') (AL.union ys ys') isStructuredUnion {xs} {ys} r {xs'} {ys'} r' a = L.countUnion a xs xs' ∙ cong₂ _+_ (r a) (r' a) ∙ sym (AL.countUnion a ys ys') -- R is structured isStructuredR : S.relation R L.structure AL.structure isStructuredR .fst a = refl isStructuredR .snd .fst = isStructuredInsert isStructuredR .snd .snd .fst {xs} {ys} = isStructuredUnion {xs} {ys} isStructuredR .snd .snd .snd a r = r a module E = QER→Equiv QuasiR open E renaming (Rᴸ to Rᴸ; Rᴿ to Rᴬᴸ) List/Rᴸ = (List A) / Rᴸ AList/Rᴬᴸ = (AList A) / Rᴬᴸ List/Rᴸ≃AList/Rᴬᴸ : List/Rᴸ ≃ AList/Rᴬᴸ List/Rᴸ≃AList/Rᴬᴸ = E.Thm main : QERDescends _ S.relation (List A , L.structure) (AList A , AL.structure) QuasiR main = structuredQER→structuredEquiv S.suitable _ _ QuasiR isStructuredR open QERDescends LQstructure : S.structure List/Rᴸ LQstructure = main .quoᴸ .fst ALQstructure : S.structure AList/Rᴬᴸ ALQstructure = main .quoᴿ .fst -- We get a path between structure over the equivalence from the fact that the QER is structured List/Rᴸ≡AList/Rᴬᴸ : Path (TypeWithStr ℓ S.structure) (List/Rᴸ , LQstructure) (AList/Rᴬᴸ , ALQstructure) List/Rᴸ≡AList/Rᴬᴸ = sip S.univalent _ _ (E.Thm , S.matches (List/Rᴸ , LQstructure) (AList/Rᴬᴸ , ALQstructure) E.Thm .fst (main .rel)) -- Deriving associativity of union for association list multisets LQunion = LQstructure .snd .snd .fst ALQunion = ALQstructure .snd .snd .fst hasAssociativeUnion : TypeWithStr ℓ S.structure → Type ℓ hasAssociativeUnion (_ , _ , _ , _⊔_ , _) = ∀ xs ys zs → (xs ⊔ ys) ⊔ zs ≡ xs ⊔ (ys ⊔ zs) LQassoc : hasAssociativeUnion (List/Rᴸ , LQstructure) LQassoc = elimProp3 (λ _ _ _ → squash/ _ _) (λ xs ys zs i → [ ++-assoc xs ys zs i ]) ALQassoc : hasAssociativeUnion (AList/Rᴬᴸ , ALQstructure) ALQassoc = subst hasAssociativeUnion List/Rᴸ≡AList/Rᴬᴸ LQassoc -- We now show that List/Rᴸ≃FMSet _∷/_ : A → List/Rᴸ → List/Rᴸ _∷/_ = LQstructure .snd .fst multisetShape' : Type ℓ → Type ℓ multisetShape' X = X × (A → X → X) × (A → X → Const[ ℕ , isSetℕ ]) FMSstructure : S.structure (FMSet A) FMSstructure = [] , _∷_ , FMS._++_ , FMScount discA infixr 5 _∷/_ FMSet→List/Rᴸ : FMSet A → List/Rᴸ FMSet→List/Rᴸ = FMS.Rec.f squash/ [ [] ] _∷/_ β where δ : ∀ c a b xs → L.count c (a ∷ b ∷ xs) ≡ L.count c (b ∷ a ∷ xs) δ c a b xs with discA c a | discA c b δ c a b xs | yes _ | yes _ = refl δ c a b xs | yes _ | no _ = refl δ c a b xs | no _ | yes _ = refl δ c a b xs | no _ | no _ = refl γ : ∀ a b xs → Rᴸ (a ∷ b ∷ xs) (b ∷ a ∷ xs) γ a b xs = ∣ φ (a ∷ b ∷ xs) , η (a ∷ b ∷ xs) , (λ c → δ c b a xs ∙ η (a ∷ b ∷ xs) c) ∣ β : ∀ a b [xs] → a ∷/ b ∷/ [xs] ≡ b ∷/ a ∷/ [xs] β a b = elimProp (λ _ → squash/ _ _) (λ xs → eq/ _ _ (γ a b xs)) -- The inverse is induced by the standard projection of lists into finite multisets, -- which is a morphism of CountStructures -- Moreover, we need 'count-extensionality' for finite multisets List→FMSet : List A → FMSet A List→FMSet [] = [] List→FMSet (x ∷ xs) = x ∷ List→FMSet xs List→FMSet-count : ∀ a xs → L.count a xs ≡ FMScount discA a (List→FMSet xs) List→FMSet-count a [] = refl List→FMSet-count a (x ∷ xs) with discA a x ... | yes _ = cong suc (List→FMSet-count a xs) ... | no _ = List→FMSet-count a xs List/Rᴸ→FMSet : List/Rᴸ → FMSet A List/Rᴸ→FMSet [ xs ] = List→FMSet xs List/Rᴸ→FMSet (eq/ xs ys r i) = path i where countsAgree : ∀ a → L.count a xs ≡ L.count a ys countsAgree a = cong (LQstructure .snd .snd .snd a) (eq/ xs ys r) θ : ∀ a → FMScount discA a (List→FMSet xs) ≡ FMScount discA a (List→FMSet ys) θ a = sym (List→FMSet-count a xs) ∙∙ countsAgree a ∙∙ List→FMSet-count a ys path : List→FMSet xs ≡ List→FMSet ys path = FMScountExt.Thm discA _ _ θ List/Rᴸ→FMSet (squash/ xs/ xs/' p q i j) = trunc (List/Rᴸ→FMSet xs/) (List/Rᴸ→FMSet xs/') (cong List/Rᴸ→FMSet p) (cong List/Rᴸ→FMSet q) i j List/Rᴸ→FMSet-insert : (x : A) (ys : List/Rᴸ) → List/Rᴸ→FMSet (x ∷/ ys) ≡ x ∷ List/Rᴸ→FMSet ys List/Rᴸ→FMSet-insert x = elimProp (λ _ → FMS.trunc _ _) λ xs → refl List→FMSet-union : (xs ys : List A) → List→FMSet (xs ++ ys) ≡ FMS._++_ (List→FMSet xs) (List→FMSet ys) List→FMSet-union [] ys = refl List→FMSet-union (x ∷ xs) ys = cong (x ∷_) (List→FMSet-union xs ys) List/Rᴸ≃FMSet : List/Rᴸ ≃ FMSet A List/Rᴸ≃FMSet = isoToEquiv (iso List/Rᴸ→FMSet FMSet→List/Rᴸ τ σ) where σ' : (xs : List A) → FMSet→List/Rᴸ (List/Rᴸ→FMSet [ xs ]) ≡ [ xs ] σ' [] = refl σ' (x ∷ xs) = cong (x ∷/_) (σ' xs) σ : section FMSet→List/Rᴸ List/Rᴸ→FMSet σ = elimProp (λ _ → squash/ _ _) σ' τ' : ∀ x {xs} → List/Rᴸ→FMSet (FMSet→List/Rᴸ xs) ≡ xs → List/Rᴸ→FMSet (FMSet→List/Rᴸ (x ∷ xs)) ≡ x ∷ xs τ' x {xs} p = List/Rᴸ→FMSet-insert x (FMSet→List/Rᴸ xs) ∙ cong (x ∷_) p τ : retract FMSet→List/Rᴸ List/Rᴸ→FMSet τ = FMS.ElimProp.f (FMS.trunc _ _) refl τ' List/Rᴸ≃FMSet-EquivStr : S.equiv (List/Rᴸ , LQstructure) (FMSet A , FMSstructure) List/Rᴸ≃FMSet List/Rᴸ≃FMSet-EquivStr .fst = refl List/Rᴸ≃FMSet-EquivStr .snd .fst a xs = List/Rᴸ→FMSet-insert a xs List/Rᴸ≃FMSet-EquivStr .snd .snd .fst = elimProp2 (λ _ _ → trunc _ _) List→FMSet-union List/Rᴸ≃FMSet-EquivStr .snd .snd .snd a = elimProp (λ _ → isSetℕ _ _) (List→FMSet-count a) {- Putting everything together we get: ≃ List/Rᴸ ------------> AList/Rᴬᴸ | |≃ | ∨ ≃ FMSet A ------------> AssocList A We thus get that AList/Rᴬᴸ≃AssocList. Constructing such an equivalence directly requires count extensionality for association lists, which should be even harder to prove than for finite multisets. This strategy should work for all implementations of multisets with HITs. We just have to show that: ∙ The HIT is equivalent to FMSet (like AssocList) ∙ There is a QER between lists and the basic data type of the HIT with the higher constructors removed (like AList) Then we get that this HIT is equivalent to the corresponding set quotient that identifies elements that give the same count on each a : A. TODO: Show that all the equivalences are indeed isomorphisms of multisets not only of CountStructures! -}
{ "alphanum_fraction": 0.595806962, "avg_line_length": 35.208913649, "ext": "agda", "hexsha": "f283d7f9d5aeb22baddf3861cd1289ee48c404db", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Relation/ZigZag/Applications/MultiSet.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Relation/ZigZag/Applications/MultiSet.agda", "max_line_length": 107, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Relation/ZigZag/Applications/MultiSet.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5131, "size": 12640 }